summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2018-03-28 00:30:41 -0400
committerDave Airlie <airlied@redhat.com>2018-03-28 00:30:41 -0400
commit2b4f44eec2be2688511c2b617d0e1b4f94c45ba4 (patch)
tree533c03602f4ae6d6404db6fa56c88e6f83e1bebe
parent33d009cd889490838c5db9b9339856c9e3d3facc (diff)
parent3eb2ce825ea1ad89d20f7a3b5780df850e4be274 (diff)
Backmerge tag 'v4.16-rc7' into drm-next
Linux 4.16-rc7 This was requested by Daniel, and things were getting a bit hard to reconcile, most of the conflicts were trivial though.
-rw-r--r--.gitignore4
-rw-r--r--Documentation/ABI/testing/sysfs-ata171
-rw-r--r--Documentation/ABI/testing/sysfs-block-device58
-rw-r--r--Documentation/ABI/testing/sysfs-class-scsi_host89
-rw-r--r--Documentation/ABI/testing/sysfs-devices-platform-dock39
-rw-r--r--Documentation/ABI/testing/sysfs-devices-system-cpu77
-rw-r--r--Documentation/ABI/testing/sysfs-platform-dptf40
-rw-r--r--Documentation/PCI/pci.txt4
-rw-r--r--Documentation/accelerators/ocxl.rst5
-rw-r--r--Documentation/atomic_bitops.txt7
-rw-r--r--Documentation/devicetree/bindings/auxdisplay/arm-charlcd.txt (renamed from Documentation/devicetree/bindings/misc/arm-charlcd.txt)0
-rw-r--r--Documentation/devicetree/bindings/display/exynos/exynos_hdmi.txt1
-rw-r--r--Documentation/devicetree/bindings/dma/mv-xor-v2.txt6
-rw-r--r--Documentation/devicetree/bindings/eeprom/at24.txt2
-rw-r--r--Documentation/devicetree/bindings/iio/adc/sigma-delta-modulator.txt4
-rw-r--r--Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt1
-rw-r--r--Documentation/devicetree/bindings/net/dsa/marvell.txt48
-rw-r--r--Documentation/devicetree/bindings/net/renesas,ravb.txt7
-rw-r--r--Documentation/devicetree/bindings/power/mti,mips-cpc.txt8
-rw-r--r--Documentation/devicetree/bindings/power/wakeup-source.txt2
-rw-r--r--Documentation/devicetree/bindings/thermal/imx-thermal.txt25
-rw-r--r--Documentation/devicetree/bindings/usb/dwc2.txt2
-rw-r--r--Documentation/devicetree/bindings/usb/renesas_usb3.txt1
-rw-r--r--Documentation/devicetree/bindings/usb/renesas_usbhs.txt1
-rw-r--r--Documentation/devicetree/bindings/usb/usb-xhci.txt1
-rw-r--r--Documentation/features/sched/membarrier-sync-core/arch-support.txt62
-rw-r--r--Documentation/gpu/tve200.rst2
-rw-r--r--Documentation/i2c/busses/i2c-i8012
-rw-r--r--Documentation/ia64/serial.txt2
-rw-r--r--Documentation/locking/mutex-design.txt49
-rw-r--r--Documentation/media/dmx.h.rst.exceptions14
-rw-r--r--Documentation/media/uapi/dvb/dmx-qbuf.rst7
-rw-r--r--Documentation/networking/segmentation-offloads.txt52
-rw-r--r--Documentation/sphinx/kerneldoc.py3
-rw-r--r--Documentation/virtual/kvm/api.txt40
-rw-r--r--Documentation/virtual/kvm/cpuid.txt4
-rw-r--r--Documentation/virtual/kvm/msr.txt3
-rw-r--r--Documentation/x86/intel_rdt_ui.txt2
-rw-r--r--Documentation/x86/topology.txt2
-rw-r--r--MAINTAINERS39
-rw-r--r--Makefile28
-rw-r--r--arch/alpha/include/asm/cmpxchg.h6
-rw-r--r--arch/alpha/include/asm/xchg.h38
-rw-r--r--arch/arc/Kconfig1
-rw-r--r--arch/arc/boot/dts/axs101.dts2
-rw-r--r--arch/arc/boot/dts/axs10x_mb.dtsi4
-rw-r--r--arch/arc/boot/dts/haps_hs_idu.dts2
-rw-r--r--arch/arc/boot/dts/nsim_700.dts2
-rw-r--r--arch/arc/boot/dts/nsim_hs.dts2
-rw-r--r--arch/arc/boot/dts/nsim_hs_idu.dts2
-rw-r--r--arch/arc/boot/dts/nsimosci.dts2
-rw-r--r--arch/arc/boot/dts/nsimosci_hs.dts2
-rw-r--r--arch/arc/boot/dts/nsimosci_hs_idu.dts2
-rw-r--r--arch/arc/include/asm/bug.h3
-rw-r--r--arch/arc/include/asm/entry-arcv2.h2
-rw-r--r--arch/arc/kernel/mcip.c74
-rw-r--r--arch/arc/kernel/setup.c4
-rw-r--r--arch/arc/kernel/smp.c50
-rw-r--r--arch/arc/kernel/unwind.c2
-rw-r--r--arch/arc/mm/cache.c5
-rw-r--r--arch/arm/boot/dts/bcm11351.dtsi2
-rw-r--r--arch/arm/boot/dts/bcm21664.dtsi2
-rw-r--r--arch/arm/boot/dts/bcm2835.dtsi6
-rw-r--r--arch/arm/boot/dts/bcm2836.dtsi12
-rw-r--r--arch/arm/boot/dts/bcm2837.dtsi2
-rw-r--r--arch/arm/boot/dts/bcm283x.dtsi2
-rw-r--r--arch/arm/boot/dts/bcm958625hr.dts2
-rw-r--r--arch/arm/boot/dts/gemini-dlink-dns-313.dts2
-rw-r--r--arch/arm/boot/dts/imx6dl-icore-rqs.dts2
-rw-r--r--arch/arm/boot/dts/logicpd-som-lv.dtsi9
-rw-r--r--arch/arm/boot/dts/logicpd-torpedo-som.dtsi8
-rw-r--r--arch/arm/boot/dts/omap5-uevm.dts2
-rw-r--r--arch/arm/boot/dts/rk3036.dtsi4
-rw-r--r--arch/arm/boot/dts/rk322x.dtsi6
-rw-r--r--arch/arm/boot/dts/rk3288-phycore-som.dtsi20
-rw-r--r--arch/arm/boot/dts/zx296702.dtsi20
-rw-r--r--arch/arm/configs/omap2plus_defconfig2
-rw-r--r--arch/arm/kernel/time.c2
-rw-r--r--arch/arm/kvm/hyp/Makefile5
-rw-r--r--arch/arm/kvm/hyp/banked-sr.c4
-rw-r--r--arch/arm/mach-clps711x/board-dt.c2
-rw-r--r--arch/arm/mach-davinci/board-dm355-evm.c2
-rw-r--r--arch/arm/mach-davinci/board-dm355-leopard.c2
-rw-r--r--arch/arm/mach-davinci/board-dm365-evm.c2
-rw-r--r--arch/arm/mach-mvebu/Kconfig4
-rw-r--r--arch/arm/mach-omap1/clock.c6
-rw-r--r--arch/arm/mach-omap2/omap-wakeupgen.c4
-rw-r--r--arch/arm/mach-omap2/omap_hwmod.c6
-rw-r--r--arch/arm/mach-omap2/pm.c4
-rw-r--r--arch/arm/mach-omap2/timer.c19
-rw-r--r--arch/arm/mach-orion5x/Kconfig3
-rw-r--r--arch/arm/mach-orion5x/dns323-setup.c53
-rw-r--r--arch/arm/mach-orion5x/tsx09-common.c49
-rw-r--r--arch/arm/mach-ux500/cpu-db8500.c35
-rw-r--r--arch/arm/plat-orion/common.c23
-rw-r--r--arch/arm64/boot/dts/amlogic/meson-axg.dtsi4
-rw-r--r--arch/arm64/boot/dts/amlogic/meson-gx.dtsi10
-rw-r--r--arch/arm64/boot/dts/amlogic/meson-gxl.dtsi1
-rw-r--r--arch/arm64/boot/dts/cavium/thunder2-99xx.dtsi3
-rw-r--r--arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts2
-rw-r--r--arch/arm64/boot/dts/mediatek/mt8173.dtsi2
-rw-r--r--arch/arm64/boot/dts/qcom/apq8096-db820c.dtsi6
-rw-r--r--arch/arm64/boot/dts/qcom/msm8996.dtsi6
-rw-r--r--arch/arm64/boot/dts/rockchip/rk3328-rock64.dts7
-rw-r--r--arch/arm64/boot/dts/rockchip/rk3328.dtsi6
-rw-r--r--arch/arm64/boot/dts/rockchip/rk3368.dtsi2
-rw-r--r--arch/arm64/boot/dts/rockchip/rk3399-sapphire.dtsi2
-rw-r--r--arch/arm64/boot/dts/rockchip/rk3399.dtsi4
-rw-r--r--arch/arm64/include/asm/cputype.h2
-rw-r--r--arch/arm64/include/asm/hugetlb.h2
-rw-r--r--arch/arm64/include/asm/kvm_mmu.h26
-rw-r--r--arch/arm64/include/asm/mmu_context.h4
-rw-r--r--arch/arm64/include/asm/pgalloc.h44
-rw-r--r--arch/arm64/include/asm/pgtable.h23
-rw-r--r--arch/arm64/include/asm/stacktrace.h2
-rw-r--r--arch/arm64/include/asm/uaccess.h12
-rw-r--r--arch/arm64/kernel/armv8_deprecated.c4
-rw-r--r--arch/arm64/kernel/cpu_errata.c13
-rw-r--r--arch/arm64/kernel/cpufeature.c6
-rw-r--r--arch/arm64/kernel/efi.c2
-rw-r--r--arch/arm64/kernel/hibernate.c148
-rw-r--r--arch/arm64/kernel/perf_event.c4
-rw-r--r--arch/arm64/kernel/process.c11
-rw-r--r--arch/arm64/kernel/ptrace.c2
-rw-r--r--arch/arm64/kernel/stacktrace.c5
-rw-r--r--arch/arm64/kernel/sys_compat.c2
-rw-r--r--arch/arm64/kernel/time.c2
-rw-r--r--arch/arm64/kernel/traps.c10
-rw-r--r--arch/arm64/kvm/guest.c3
-rw-r--r--arch/arm64/kvm/hyp/switch.c4
-rw-r--r--arch/arm64/mm/dump.c54
-rw-r--r--arch/arm64/mm/fault.c44
-rw-r--r--arch/arm64/mm/hugetlbpage.c94
-rw-r--r--arch/arm64/mm/kasan_init.c70
-rw-r--r--arch/arm64/mm/mmu.c310
-rw-r--r--arch/arm64/mm/pageattr.c32
-rw-r--r--arch/arm64/mm/proc.S14
-rw-r--r--arch/arm64/net/bpf_jit_comp.c5
-rw-r--r--arch/cris/include/arch-v10/arch/bug.h11
-rw-r--r--arch/h8300/include/asm/byteorder.h1
-rw-r--r--arch/ia64/include/asm/atomic.h69
-rw-r--r--arch/ia64/include/asm/bug.h6
-rw-r--r--arch/ia64/kernel/Makefile1
-rw-r--r--arch/ia64/kernel/err_inject.c4
-rw-r--r--arch/ia64/scripts/unwcheck.py16
-rw-r--r--arch/m68k/include/asm/bug.h3
-rw-r--r--arch/microblaze/Kconfig1
-rw-r--r--arch/microblaze/Kconfig.platform2
-rw-r--r--arch/microblaze/include/asm/setup.h1
-rw-r--r--arch/microblaze/lib/fastcopy.S4
-rw-r--r--arch/microblaze/mm/init.c64
-rw-r--r--arch/mips/ath25/board.c2
-rw-r--r--arch/mips/boot/Makefile1
-rw-r--r--arch/mips/cavium-octeon/octeon-irq.c2
-rw-r--r--arch/mips/include/asm/compat.h1
-rw-r--r--arch/mips/kernel/mips-cpc.c13
-rw-r--r--arch/mips/kernel/setup.c16
-rw-r--r--arch/mips/kernel/smp-bmips.c10
-rw-r--r--arch/mips/lantiq/Kconfig2
-rw-r--r--arch/mips/lantiq/xway/sysctrl.c6
-rw-r--r--arch/mips/loongson64/Kconfig6
-rw-r--r--arch/mips/ralink/mt7621.c42
-rw-r--r--arch/mips/ralink/reset.c7
-rw-r--r--arch/parisc/include/asm/cacheflush.h1
-rw-r--r--arch/parisc/include/asm/processor.h2
-rw-r--r--arch/parisc/kernel/cache.c88
-rw-r--r--arch/parisc/kernel/head.S18
-rw-r--r--arch/parisc/kernel/pacache.S22
-rw-r--r--arch/parisc/kernel/smp.c7
-rw-r--r--arch/parisc/kernel/time.c11
-rw-r--r--arch/parisc/mm/init.c7
-rw-r--r--arch/powerpc/boot/Makefile3
-rw-r--r--arch/powerpc/include/asm/book3s/32/pgtable.h1
-rw-r--r--arch/powerpc/include/asm/book3s/64/hash-4k.h3
-rw-r--r--arch/powerpc/include/asm/book3s/64/hash-64k.h16
-rw-r--r--arch/powerpc/include/asm/book3s/64/hash.h13
-rw-r--r--arch/powerpc/include/asm/book3s/64/pgalloc.h16
-rw-r--r--arch/powerpc/include/asm/book3s/64/pgtable.h4
-rw-r--r--arch/powerpc/include/asm/exception-64s.h2
-rw-r--r--arch/powerpc/include/asm/firmware.h2
-rw-r--r--arch/powerpc/include/asm/hw_irq.h12
-rw-r--r--arch/powerpc/include/asm/kexec.h6
-rw-r--r--arch/powerpc/include/asm/nohash/32/pgtable.h1
-rw-r--r--arch/powerpc/include/asm/nohash/64/pgtable.h1
-rw-r--r--arch/powerpc/include/asm/topology.h13
-rw-r--r--arch/powerpc/kernel/eeh_driver.c3
-rw-r--r--arch/powerpc/kernel/exceptions-64e.S2
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S6
-rw-r--r--arch/powerpc/kernel/prom_init.c1
-rw-r--r--arch/powerpc/kernel/sysfs.c6
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_radix.c69
-rw-r--r--arch/powerpc/kvm/book3s_hv.c17
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S10
-rw-r--r--arch/powerpc/kvm/book3s_xive.c2
-rw-r--r--arch/powerpc/kvm/powerpc.c4
-rw-r--r--arch/powerpc/mm/drmem.c14
-rw-r--r--arch/powerpc/mm/hash64_4k.c4
-rw-r--r--arch/powerpc/mm/hash64_64k.c8
-rw-r--r--arch/powerpc/mm/hash_utils_64.c1
-rw-r--r--arch/powerpc/mm/hugetlbpage-hash64.c10
-rw-r--r--arch/powerpc/mm/init-common.c4
-rw-r--r--arch/powerpc/mm/numa.c5
-rw-r--r--arch/powerpc/mm/pgtable-radix.c117
-rw-r--r--arch/powerpc/mm/pgtable_64.c4
-rw-r--r--arch/powerpc/mm/tlb_hash64.c9
-rw-r--r--arch/powerpc/net/bpf_jit_comp.c3
-rw-r--r--arch/powerpc/net/bpf_jit_comp64.c1
-rw-r--r--arch/powerpc/platforms/powernv/opal-imc.c6
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c2
-rw-r--r--arch/powerpc/platforms/powernv/setup.c4
-rw-r--r--arch/powerpc/platforms/powernv/vas-window.c16
-rw-r--r--arch/powerpc/platforms/pseries/hotplug-cpu.c4
-rw-r--r--arch/powerpc/platforms/pseries/ras.c31
-rw-r--r--arch/powerpc/platforms/pseries/setup.c3
-rw-r--r--arch/powerpc/sysdev/xive/spapr.c16
-rw-r--r--arch/riscv/Kconfig3
-rw-r--r--arch/riscv/include/asm/barrier.h6
-rw-r--r--arch/riscv/kernel/entry.S5
-rw-r--r--arch/riscv/kernel/head.S2
-rw-r--r--arch/riscv/kernel/setup.c2
-rw-r--r--arch/s390/include/asm/mmu_context.h1
-rw-r--r--arch/s390/kernel/entry.S10
-rw-r--r--arch/s390/kernel/nospec-branch.c4
-rw-r--r--arch/s390/kvm/intercept.c51
-rw-r--r--arch/s390/kvm/interrupt.c123
-rw-r--r--arch/s390/kvm/kvm-s390.c81
-rw-r--r--arch/s390/kvm/kvm-s390.h7
-rw-r--r--arch/s390/kvm/priv.c192
-rw-r--r--arch/s390/kvm/vsie.c20
-rw-r--r--arch/sh/boot/dts/Makefile4
-rw-r--r--arch/sparc/Kconfig2
-rw-r--r--arch/sparc/include/asm/bug.h6
-rw-r--r--arch/sparc/mm/tlb.c19
-rw-r--r--arch/x86/.gitignore1
-rw-r--r--arch/x86/Kconfig89
-rw-r--r--arch/x86/Kconfig.cpu17
-rw-r--r--arch/x86/Makefile16
-rw-r--r--arch/x86/boot/compressed/eboot.c4
-rw-r--r--arch/x86/boot/compressed/misc.c4
-rw-r--r--arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c10
-rw-r--r--arch/x86/entry/calling.h121
-rw-r--r--arch/x86/entry/entry_32.S3
-rw-r--r--arch/x86/entry/entry_64.S223
-rw-r--r--arch/x86/entry/entry_64_compat.S65
-rw-r--r--arch/x86/entry/syscalls/syscall_32.tbl38
-rw-r--r--arch/x86/entry/vdso/vdso32/vclock_gettime.c2
-rw-r--r--arch/x86/entry/vsyscall/vsyscall_64.c18
-rw-r--r--arch/x86/events/core.c3
-rw-r--r--arch/x86/events/intel/core.c16
-rw-r--r--arch/x86/events/intel/ds.c6
-rw-r--r--arch/x86/events/intel/lbr.c2
-rw-r--r--arch/x86/events/intel/p6.c2
-rw-r--r--arch/x86/events/intel/uncore_snbep.c34
-rw-r--r--arch/x86/events/perf_event.h6
-rw-r--r--arch/x86/ia32/sys_ia32.c74
-rw-r--r--arch/x86/include/asm/acpi.h2
-rw-r--r--arch/x86/include/asm/apm.h6
-rw-r--r--arch/x86/include/asm/asm-prototypes.h3
-rw-r--r--arch/x86/include/asm/barrier.h32
-rw-r--r--arch/x86/include/asm/bitops.h29
-rw-r--r--arch/x86/include/asm/bug.h19
-rw-r--r--arch/x86/include/asm/cpufeature.h79
-rw-r--r--arch/x86/include/asm/cpufeatures.h3
-rw-r--r--arch/x86/include/asm/efi.h17
-rw-r--r--arch/x86/include/asm/io.h15
-rw-r--r--arch/x86/include/asm/kvm_host.h6
-rw-r--r--arch/x86/include/asm/microcode.h10
-rw-r--r--arch/x86/include/asm/mmu_context.h1
-rw-r--r--arch/x86/include/asm/nospec-branch.h176
-rw-r--r--arch/x86/include/asm/page_64.h4
-rw-r--r--arch/x86/include/asm/paravirt.h21
-rw-r--r--arch/x86/include/asm/paravirt_types.h7
-rw-r--r--arch/x86/include/asm/percpu.h2
-rw-r--r--arch/x86/include/asm/pgtable.h8
-rw-r--r--arch/x86/include/asm/pgtable_32.h3
-rw-r--r--arch/x86/include/asm/pgtable_64.h1
-rw-r--r--arch/x86/include/asm/pgtable_types.h12
-rw-r--r--arch/x86/include/asm/processor.h8
-rw-r--r--arch/x86/include/asm/refcount.h6
-rw-r--r--arch/x86/include/asm/rmwcc.h16
-rw-r--r--arch/x86/include/asm/sections.h1
-rw-r--r--arch/x86/include/asm/smp.h1
-rw-r--r--arch/x86/include/asm/sys_ia32.h48
-rw-r--r--arch/x86/include/asm/tlbflush.h27
-rw-r--r--arch/x86/include/asm/vmx.h1
-rw-r--r--arch/x86/include/uapi/asm/hyperv.h18
-rw-r--r--arch/x86/include/uapi/asm/kvm_para.h1
-rw-r--r--arch/x86/include/uapi/asm/mce.h1
-rw-r--r--arch/x86/kernel/amd_nb.c2
-rw-r--r--arch/x86/kernel/apic/apic.c6
-rw-r--r--arch/x86/kernel/apic/io_apic.c2
-rw-r--r--arch/x86/kernel/apic/vector.c25
-rw-r--r--arch/x86/kernel/apic/x2apic_uv_x.c15
-rw-r--r--arch/x86/kernel/asm-offsets_32.c2
-rw-r--r--arch/x86/kernel/cpu/amd.c28
-rw-r--r--arch/x86/kernel/cpu/bugs.c46
-rw-r--r--arch/x86/kernel/cpu/centaur.c4
-rw-r--r--arch/x86/kernel/cpu/common.c40
-rw-r--r--arch/x86/kernel/cpu/cyrix.c2
-rw-r--r--arch/x86/kernel/cpu/intel.c41
-rw-r--r--arch/x86/kernel/cpu/intel_rdt.c2
-rw-r--r--arch/x86/kernel/cpu/intel_rdt_rdtgroup.c1
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce-internal.h15
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.c45
-rw-r--r--arch/x86/kernel/cpu/microcode/amd.c44
-rw-r--r--arch/x86/kernel/cpu/microcode/core.c181
-rw-r--r--arch/x86/kernel/cpu/microcode/intel.c68
-rw-r--r--arch/x86/kernel/cpu/mtrr/generic.c2
-rw-r--r--arch/x86/kernel/cpu/mtrr/main.c4
-rw-r--r--arch/x86/kernel/cpu/proc.c8
-rw-r--r--arch/x86/kernel/head_32.S4
-rw-r--r--arch/x86/kernel/head_64.S2
-rw-r--r--arch/x86/kernel/idt.c2
-rw-r--r--arch/x86/kernel/ioport.c2
-rw-r--r--arch/x86/kernel/kprobes/core.c10
-rw-r--r--arch/x86/kernel/kvm.c20
-rw-r--r--arch/x86/kernel/machine_kexec_64.c1
-rw-r--r--arch/x86/kernel/module.c1
-rw-r--r--arch/x86/kernel/mpparse.c2
-rw-r--r--arch/x86/kernel/paravirt.c6
-rw-r--r--arch/x86/kernel/pci-nommu.c19
-rw-r--r--arch/x86/kernel/setup.c17
-rw-r--r--arch/x86/kernel/setup_percpu.c17
-rw-r--r--arch/x86/kernel/signal_compat.c65
-rw-r--r--arch/x86/kernel/smpboot.c12
-rw-r--r--arch/x86/kernel/traps.c17
-rw-r--r--arch/x86/kernel/unwind_orc.c3
-rw-r--r--arch/x86/kernel/vm86_32.c3
-rw-r--r--arch/x86/kernel/vmlinux.lds.S2
-rw-r--r--arch/x86/kvm/cpuid.c3
-rw-r--r--arch/x86/kvm/lapic.c11
-rw-r--r--arch/x86/kvm/mmu.c16
-rw-r--r--arch/x86/kvm/svm.c90
-rw-r--r--arch/x86/kvm/vmx.c44
-rw-r--r--arch/x86/kvm/x86.c107
-rw-r--r--arch/x86/lib/Makefile1
-rw-r--r--arch/x86/lib/cpu.c2
-rw-r--r--arch/x86/lib/error-inject.c1
-rw-r--r--arch/x86/lib/retpoline.S56
-rw-r--r--arch/x86/mm/cpu_entry_area.c6
-rw-r--r--arch/x86/mm/fault.c10
-rw-r--r--arch/x86/mm/init_32.c15
-rw-r--r--arch/x86/mm/init_64.c66
-rw-r--r--arch/x86/mm/ioremap.c2
-rw-r--r--arch/x86/mm/kmmio.c2
-rw-r--r--arch/x86/mm/mem_encrypt_boot.S2
-rw-r--r--arch/x86/mm/pgtable.c48
-rw-r--r--arch/x86/mm/pgtable_32.c2
-rw-r--r--arch/x86/mm/pti.c2
-rw-r--r--arch/x86/mm/tlb.c6
-rw-r--r--arch/x86/net/bpf_jit_comp.c12
-rw-r--r--arch/x86/oprofile/nmi_int.c2
-rw-r--r--arch/x86/platform/efi/efi_64.c2
-rw-r--r--arch/x86/platform/intel-mid/intel-mid.c2
-rw-r--r--arch/x86/platform/uv/tlb_uv.c2
-rw-r--r--arch/x86/realmode/rm/trampoline_64.S2
-rw-r--r--arch/x86/tools/relocs.c3
-rw-r--r--arch/x86/um/asm/barrier.h4
-rw-r--r--arch/x86/xen/enlighten_pv.c6
-rw-r--r--arch/x86/xen/mmu_pv.c6
-rw-r--r--arch/x86/xen/smp.c2
-rw-r--r--arch/x86/xen/suspend.c16
-rw-r--r--arch/xtensa/kernel/pci-dma.c40
-rw-r--r--arch/xtensa/mm/init.c70
-rw-r--r--block/blk-cgroup.c11
-rw-r--r--block/blk-core.c2
-rw-r--r--block/blk-mq.c5
-rw-r--r--block/genhd.c48
-rw-r--r--block/ioctl.c2
-rw-r--r--block/kyber-iosched.c1
-rw-r--r--block/mq-deadline.c16
-rw-r--r--block/partition-generic.c6
-rw-r--r--block/sed-opal.c2
-rw-r--r--certs/blacklist_nohashes.c2
-rw-r--r--crypto/asymmetric_keys/pkcs7_trust.c1
-rw-r--r--crypto/asymmetric_keys/pkcs7_verify.c12
-rw-r--r--crypto/asymmetric_keys/public_key.c4
-rw-r--r--crypto/asymmetric_keys/restrict.c21
-rw-r--r--crypto/sha3_generic.c218
-rw-r--r--drivers/acpi/acpi_watchdog.c4
-rw-r--r--drivers/acpi/battery.c48
-rw-r--r--drivers/acpi/bus.c75
-rw-r--r--drivers/acpi/ec.c6
-rw-r--r--drivers/acpi/nfit/core.c10
-rw-r--r--drivers/acpi/numa.c10
-rw-r--r--drivers/acpi/property.c4
-rw-r--r--drivers/acpi/spcr.c1
-rw-r--r--drivers/android/binder.c29
-rw-r--r--drivers/ata/ahci.c4
-rw-r--r--drivers/ata/libahci.c10
-rw-r--r--drivers/ata/libahci_platform.c2
-rw-r--r--drivers/ata/libata-core.c26
-rw-r--r--drivers/ata/libata-eh.c3
-rw-r--r--drivers/ata/libata-scsi.c12
-rw-r--r--drivers/ata/sata_rcar.c62
-rw-r--r--drivers/auxdisplay/img-ascii-lcd.c6
-rw-r--r--drivers/auxdisplay/panel.c6
-rw-r--r--drivers/base/core.c3
-rw-r--r--drivers/base/power/wakeirq.c6
-rw-r--r--drivers/base/property.c5
-rw-r--r--drivers/block/amiflop.c2
-rw-r--r--drivers/block/ataflop.c2
-rw-r--r--drivers/block/brd.c2
-rw-r--r--drivers/block/floppy.c2
-rw-r--r--drivers/block/loop.c4
-rw-r--r--drivers/block/nbd.c2
-rw-r--r--drivers/block/pktcdvd.c2
-rw-r--r--drivers/block/swim.c2
-rw-r--r--drivers/block/xen-blkfront.c17
-rw-r--r--drivers/block/z2ram.c2
-rw-r--r--drivers/bluetooth/btusb.c27
-rw-r--r--drivers/bluetooth/hci_bcm.c20
-rw-r--r--drivers/bus/ti-sysc.c2
-rw-r--r--drivers/char/hw_random/via-rng.c2
-rw-r--r--drivers/char/tpm/st33zp24/st33zp24.c4
-rw-r--r--drivers/char/tpm/tpm-interface.c4
-rw-r--r--drivers/char/tpm/tpm2-cmd.c4
-rw-r--r--drivers/char/tpm/tpm_i2c_infineon.c5
-rw-r--r--drivers/char/tpm/tpm_i2c_nuvoton.c8
-rw-r--r--drivers/char/tpm/tpm_tis_core.c5
-rw-r--r--drivers/clk/bcm/clk-bcm2835.c12
-rw-r--r--drivers/clk/clk-aspeed.c28
-rw-r--r--drivers/clk/clk.c46
-rw-r--r--drivers/clk/hisilicon/clk-hi3660-stub.c2
-rw-r--r--drivers/clk/imx/clk-imx51-imx53.c20
-rw-r--r--drivers/clk/qcom/apcs-msm8916.c5
-rw-r--r--drivers/clk/sunxi-ng/ccu-sun6i-a31.c6
-rw-r--r--drivers/clk/ti/clk-33xx.c2
-rw-r--r--drivers/clk/ti/clk-43xx.c2
-rw-r--r--drivers/clk/ti/clkctrl.c2
-rw-r--r--drivers/clocksource/Kconfig1
-rw-r--r--drivers/clocksource/arc_timer.c11
-rw-r--r--drivers/clocksource/fsl_ftm_timer.c2
-rw-r--r--drivers/clocksource/mips-gic-timer.c6
-rw-r--r--drivers/clocksource/timer-sun5i.c2
-rw-r--r--drivers/cpufreq/Kconfig.arm6
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c2
-rw-r--r--drivers/cpufreq/longhaul.c6
-rw-r--r--drivers/cpufreq/p4-clockmod.c2
-rw-r--r--drivers/cpufreq/powernow-k7.c2
-rw-r--r--drivers/cpufreq/s3c24xx-cpufreq.c8
-rw-r--r--drivers/cpufreq/scpi-cpufreq.c16
-rw-r--r--drivers/cpufreq/speedstep-centrino.c4
-rw-r--r--drivers/cpufreq/speedstep-lib.c6
-rw-r--r--drivers/crypto/caam/ctrl.c8
-rw-r--r--drivers/crypto/ccp/psp-dev.c8
-rw-r--r--drivers/crypto/padlock-aes.c2
-rw-r--r--drivers/crypto/s5p-sss.c12
-rw-r--r--drivers/crypto/sunxi-ss/sun4i-ss-prng.c6
-rw-r--r--drivers/crypto/talitos.c4
-rw-r--r--drivers/dax/super.c6
-rw-r--r--drivers/dma/mv_xor_v2.c25
-rw-r--r--drivers/dma/sh/rcar-dmac.c2
-rw-r--r--drivers/dma/stm32-dmamux.c9
-rw-r--r--drivers/edac/amd64_edac.c2
-rw-r--r--drivers/edac/sb_edac.c2
-rw-r--r--drivers/extcon/extcon-axp288.c36
-rw-r--r--drivers/extcon/extcon-intel-int3496.c3
-rw-r--r--drivers/firmware/dcdbas.c2
-rw-r--r--drivers/firmware/efi/libstub/tpm.c4
-rw-r--r--drivers/gpio/gpio-rcar.c38
-rw-r--r--drivers/gpio/gpiolib-of.c15
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c58
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c2
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c2
-rw-r--r--drivers/gpu/drm/amd/display/dc/dce/dce_opp.c9
-rw-r--r--drivers/gpu/drm/ast/ast_tables.h4
-rw-r--r--drivers/gpu/drm/cirrus/cirrus_mode.c40
-rw-r--r--drivers/gpu/drm/drm_edid.c21
-rw-r--r--drivers/gpu/drm/drm_framebuffer.c11
-rw-r--r--drivers/gpu/drm/drm_mm.c21
-rw-r--r--drivers/gpu/drm/drm_probe_helper.c20
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_g2d.c12
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_rotator.h19
-rw-r--r--drivers/gpu/drm/exynos/exynos_hdmi.c7
-rw-r--r--drivers/gpu/drm/exynos/regs-fimc.h2
-rw-r--r--drivers/gpu/drm/exynos/regs-hdmi.h2
-rw-r--r--drivers/gpu/drm/i915/gvt/cmd_parser.c8
-rw-r--r--drivers/gpu/drm/i915/gvt/kvmgt.c51
-rw-r--r--drivers/gpu/drm/i915/gvt/mmio_context.c3
-rw-r--r--drivers/gpu/drm/i915/gvt/scheduler.c71
-rw-r--r--drivers/gpu/drm/i915/gvt/scheduler.h5
-rw-r--r--drivers/gpu/drm/i915/gvt/trace.h2
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c16
-rw-r--r--drivers/gpu/drm/i915/i915_sysfs.c10
-rw-r--r--drivers/gpu/drm/i915/intel_ddi.c7
-rw-r--r--drivers/gpu/drm/i915/intel_hangcheck.c4
-rw-r--r--drivers/gpu/drm/imx/ipuv3-crtc.c5
-rw-r--r--drivers/gpu/drm/imx/ipuv3-plane.c10
-rw-r--r--drivers/gpu/drm/meson/meson_crtc.c6
-rw-r--r--drivers/gpu/drm/meson/meson_drv.h3
-rw-r--r--drivers/gpu/drm/meson/meson_plane.c7
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_backlight.c14
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_connector.c18
-rw-r--r--drivers/gpu/drm/nouveau/nv50_display.c1
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c2
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c6
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c74
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_crtc.c4
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_dotclock.c5
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_drv.c3
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c6
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_rgb.c2
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_tcon.c95
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_tcon.h1
-rw-r--r--drivers/gpu/drm/tegra/dc.c16
-rw-r--r--drivers/gpu/drm/tegra/drm.c1
-rw-r--r--drivers/gpu/drm/tegra/dsi.c1
-rw-r--r--drivers/gpu/drm/tegra/plane.c9
-rw-r--r--drivers/gpu/drm/udl/udl_fb.c9
-rw-r--r--drivers/gpu/drm/virtio/virtgpu_ioctl.c17
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c13
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h1
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_kms.c38
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_kms.h13
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c5
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c5
-rw-r--r--drivers/gpu/ipu-v3/ipu-common.c4
-rw-r--r--drivers/gpu/ipu-v3/ipu-cpmem.c2
-rw-r--r--drivers/gpu/ipu-v3/ipu-csi.c2
-rw-r--r--drivers/gpu/ipu-v3/ipu-pre.c3
-rw-r--r--drivers/gpu/ipu-v3/ipu-prg.c15
-rw-r--r--drivers/hid/hid-ids.h3
-rw-r--r--drivers/hid/hid-quirks.c3
-rw-r--r--drivers/hv/ring_buffer.c52
-rw-r--r--drivers/hwmon/coretemp.c6
-rw-r--r--drivers/hwmon/hwmon-vid.c2
-rw-r--r--drivers/hwmon/k10temp.c7
-rw-r--r--drivers/hwmon/k8temp.c2
-rw-r--r--drivers/i2c/busses/Kconfig2
-rw-r--r--drivers/i2c/busses/i2c-bcm2835.c21
-rw-r--r--drivers/i2c/busses/i2c-designware-master.c4
-rw-r--r--drivers/i2c/busses/i2c-i801.c1
-rw-r--r--drivers/i2c/busses/i2c-octeon-core.c1
-rw-r--r--drivers/i2c/busses/i2c-octeon-core.h2
-rw-r--r--drivers/i2c/busses/i2c-sirf.c4
-rw-r--r--drivers/ide/ide-probe.c2
-rw-r--r--drivers/iio/accel/st_accel_core.c7
-rw-r--r--drivers/iio/adc/aspeed_adc.c7
-rw-r--r--drivers/iio/adc/meson_saradc.c4
-rw-r--r--drivers/iio/adc/stm32-adc.c7
-rw-r--r--drivers/iio/adc/stm32-dfsdm-adc.c39
-rw-r--r--drivers/iio/adc/stm32-dfsdm-core.c12
-rw-r--r--drivers/iio/chemical/ccs811.c3
-rw-r--r--drivers/iio/imu/adis_trigger.c7
-rw-r--r--drivers/iio/industrialio-buffer.c2
-rw-r--r--drivers/iio/pressure/st_pressure_core.c2
-rw-r--r--drivers/iio/proximity/Kconfig2
-rw-r--r--drivers/infiniband/core/addr.c15
-rw-r--r--drivers/infiniband/core/cma.c15
-rw-r--r--drivers/infiniband/core/core_priv.h7
-rw-r--r--drivers/infiniband/core/cq.c21
-rw-r--r--drivers/infiniband/core/device.c6
-rw-r--r--drivers/infiniband/core/rdma_core.c38
-rw-r--r--drivers/infiniband/core/restrack.c23
-rw-r--r--drivers/infiniband/core/sa_query.c7
-rw-r--r--drivers/infiniband/core/ucma.c42
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c50
-rw-r--r--drivers/infiniband/core/uverbs_ioctl.c3
-rw-r--r--drivers/infiniband/core/uverbs_ioctl_merge.c18
-rw-r--r--drivers/infiniband/core/uverbs_main.c29
-rw-r--r--drivers/infiniband/core/uverbs_std_types.c12
-rw-r--r--drivers/infiniband/core/verbs.c3
-rw-r--r--drivers/infiniband/hw/bnxt_re/bnxt_re.h6
-rw-r--r--drivers/infiniband/hw/bnxt_re/ib_verbs.c76
-rw-r--r--drivers/infiniband/hw/bnxt_re/ib_verbs.h5
-rw-r--r--drivers/infiniband/hw/bnxt_re/main.c24
-rw-r--r--drivers/infiniband/hw/bnxt_re/qplib_fp.c134
-rw-r--r--drivers/infiniband/hw/bnxt_re/qplib_fp.h16
-rw-r--r--drivers/infiniband/hw/bnxt_re/qplib_rcfw.c9
-rw-r--r--drivers/infiniband/hw/bnxt_re/qplib_rcfw.h1
-rw-r--r--drivers/infiniband/hw/bnxt_re/qplib_sp.c17
-rw-r--r--drivers/infiniband/hw/bnxt_re/roce_hsi.h25
-rw-r--r--drivers/infiniband/hw/mlx4/cq.c4
-rw-r--r--drivers/infiniband/hw/mlx4/main.c11
-rw-r--r--drivers/infiniband/hw/mlx5/cq.c10
-rw-r--r--drivers/infiniband/hw/mlx5/main.c42
-rw-r--r--drivers/infiniband/hw/mlx5/mlx5_ib.h3
-rw-r--r--drivers/infiniband/hw/mlx5/mr.c14
-rw-r--r--drivers/infiniband/hw/mlx5/qp.c34
-rw-r--r--drivers/infiniband/hw/mlx5/srq.c15
-rw-r--r--drivers/infiniband/hw/qedr/qedr_iw_cm.c19
-rw-r--r--drivers/infiniband/hw/qedr/verbs.c13
-rw-r--r--drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c4
-rw-r--r--drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c4
-rw-r--r--drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c4
-rw-r--r--drivers/infiniband/sw/rdmavt/mr.c10
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_fs.c2
-rw-r--r--drivers/input/keyboard/matrix_keypad.c4
-rw-r--r--drivers/input/mouse/synaptics.c1
-rw-r--r--drivers/input/touchscreen/mms114.c15
-rw-r--r--drivers/iommu/intel-svm.c2
-rw-r--r--drivers/irqchip/irq-bcm7038-l1.c3
-rw-r--r--drivers/irqchip/irq-bcm7120-l2.c3
-rw-r--r--drivers/irqchip/irq-brcmstb-l2.c3
-rw-r--r--drivers/irqchip/irq-gic-v2m.c46
-rw-r--r--drivers/irqchip/irq-gic-v3-its-pci-msi.c2
-rw-r--r--drivers/irqchip/irq-gic-v3-its-platform-msi.c2
-rw-r--r--drivers/irqchip/irq-gic-v3-its.c15
-rw-r--r--drivers/irqchip/irq-gic-v3.c4
-rw-r--r--drivers/irqchip/irq-imx-gpcv2.c14
-rw-r--r--drivers/irqchip/irq-mips-gic.c2
-rw-r--r--drivers/macintosh/macio_asic.c1
-rw-r--r--drivers/md/bcache/request.c2
-rw-r--r--drivers/md/bcache/super.c29
-rw-r--r--drivers/md/dm-bufio.c16
-rw-r--r--drivers/md/dm-mpath.c77
-rw-r--r--drivers/md/dm-raid.c7
-rw-r--r--drivers/md/dm-table.c16
-rw-r--r--drivers/md/dm.c38
-rw-r--r--drivers/md/md-multipath.c2
-rw-r--r--drivers/md/md.c53
-rw-r--r--drivers/md/md.h2
-rw-r--r--drivers/md/raid1.c13
-rw-r--r--drivers/md/raid1.h12
-rw-r--r--drivers/md/raid10.c18
-rw-r--r--drivers/md/raid10.h13
-rw-r--r--drivers/md/raid5-log.h3
-rw-r--r--drivers/md/raid5-ppl.c10
-rw-r--r--drivers/md/raid5.c19
-rw-r--r--drivers/md/raid5.h12
-rw-r--r--drivers/media/Kconfig4
-rw-r--r--drivers/media/common/videobuf2/Kconfig3
-rw-r--r--drivers/media/common/videobuf2/Makefile9
-rw-r--r--drivers/media/common/videobuf2/vb2-trace.c (renamed from drivers/media/v4l2-core/vb2-trace.c)0
-rw-r--r--drivers/media/dvb-core/Makefile2
-rw-r--r--drivers/media/dvb-core/dmxdev.c115
-rw-r--r--drivers/media/dvb-core/dvb_demux.c112
-rw-r--r--drivers/media/dvb-core/dvb_net.c5
-rw-r--r--drivers/media/dvb-core/dvb_vb2.c31
-rw-r--r--drivers/media/dvb-frontends/m88ds3103.c7
-rw-r--r--drivers/media/i2c/tvp5150.c88
-rw-r--r--drivers/media/pci/ttpci/av7110.c5
-rw-r--r--drivers/media/pci/ttpci/av7110_av.c6
-rw-r--r--drivers/media/platform/tegra-cec/tegra_cec.c17
-rw-r--r--drivers/media/usb/au0828/Kconfig2
-rw-r--r--drivers/media/usb/ttusb-dec/ttusb_dec.c10
-rw-r--r--drivers/media/v4l2-core/Kconfig1
-rw-r--r--drivers/media/v4l2-core/Makefile3
-rw-r--r--drivers/memory/brcmstb_dpfe.c74
-rw-r--r--drivers/message/fusion/mptctl.c2
-rw-r--r--drivers/misc/mei/bus.c6
-rw-r--r--drivers/misc/mei/client.c6
-rw-r--r--drivers/misc/mei/hw-me-regs.h5
-rw-r--r--drivers/misc/mei/pci-me.c5
-rw-r--r--drivers/misc/ocxl/file.c35
-rw-r--r--drivers/mmc/core/block.c19
-rw-r--r--drivers/mmc/core/card.h1
-rw-r--r--drivers/mmc/core/mmc_ops.c4
-rw-r--r--drivers/mmc/core/quirks.h6
-rw-r--r--drivers/mmc/host/bcm2835.c3
-rw-r--r--drivers/mmc/host/dw_mmc-exynos.c9
-rw-r--r--drivers/mmc/host/dw_mmc-k3.c4
-rw-r--r--drivers/mmc/host/dw_mmc-rockchip.c1
-rw-r--r--drivers/mmc/host/dw_mmc-zx.c1
-rw-r--r--drivers/mmc/host/dw_mmc.c99
-rw-r--r--drivers/mmc/host/dw_mmc.h2
-rw-r--r--drivers/mmc/host/meson-gx-mmc.c19
-rw-r--r--drivers/mmc/host/sdhci-acpi.c2
-rw-r--r--drivers/mmc/host/sdhci-pci-core.c35
-rw-r--r--drivers/mtd/mtdchar.c4
-rw-r--r--drivers/mtd/nand/Kconfig2
-rw-r--r--drivers/mtd/nand/fsl_ifc_nand.c32
-rw-r--r--drivers/mtd/nand/vf610_nfc.c6
-rw-r--r--drivers/net/can/cc770/cc770.c100
-rw-r--r--drivers/net/can/cc770/cc770.h2
-rw-r--r--drivers/net/can/ifi_canfd/ifi_canfd.c75
-rw-r--r--drivers/net/can/m_can/m_can.c7
-rw-r--r--drivers/net/can/peak_canfd/peak_canfd.c25
-rw-r--r--drivers/net/can/peak_canfd/peak_pciefd_main.c8
-rw-r--r--drivers/net/dsa/Makefile5
-rw-r--r--drivers/net/dsa/b53/b53_common.c4
-rw-r--r--drivers/net/ethernet/8390/Kconfig2
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-pci.c2
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_cfg.h2
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_nic.c22
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_nic.h1
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c29
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_ring.c7
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_ring.h2
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_vec.c11
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c66
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.h1
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/ver.h2
-rw-r--r--drivers/net/ethernet/arc/emac_rockchip.c6
-rw-r--r--drivers/net/ethernet/broadcom/bcmsysport.c33
-rw-r--r--drivers/net/ethernet/broadcom/bcmsysport.h2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.c180
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.h1
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c33
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c33
-rw-r--r--drivers/net/ethernet/broadcom/tg3.h5
-rw-r--r--drivers/net/ethernet/cavium/common/cavium_ptp.c2
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_main.c110
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_queues.c11
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_queues.h4
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c2
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c2
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c28
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/t4_hw.c10
-rw-r--r--drivers/net/ethernet/cortina/gemini.c1
-rw-r--r--drivers/net/ethernet/freescale/dpaa/dpaa_eth.c8
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c2
-rw-r--r--drivers/net/ethernet/freescale/fman/fman_dtsec.c2
-rw-r--r--drivers/net/ethernet/freescale/gianfar.c30
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c2
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c2
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c2
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_ethtool.c4
-rw-r--r--drivers/net/ethernet/ibm/ibmvnic.c59
-rw-r--r--drivers/net/ethernet/intel/e1000e/defines.h21
-rw-r--r--drivers/net/ethernet/intel/e1000e/ich8lan.c42
-rw-r--r--drivers/net/ethernet/intel/e1000e/mac.c25
-rw-r--r--drivers/net/ethernet/intel/e1000e/netdev.c37
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c8
-rw-r--r--drivers/net/ethernet/marvell/mvpp2.c11
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.c8
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_main.c14
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_rx.c49
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c3
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_tc.c3
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_tx.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/eswitch.c8
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/fs_core.c13
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/health.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c11
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h1
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h20
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.c111
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.h5
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c5
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c12
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c35
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c29
-rw-r--r--drivers/net/ethernet/natsemi/Kconfig6
-rw-r--r--drivers/net/ethernet/natsemi/Makefile2
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_cxt.c5
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_iwarp.c17
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_rdma.c1
-rw-r--r--drivers/net/ethernet/qlogic/qede/qede_main.c8
-rw-r--r--drivers/net/ethernet/qlogic/qede/qede_ptp.c2
-rw-r--r--drivers/net/ethernet/qualcomm/emac/emac-mac.c23
-rw-r--r--drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c68
-rw-r--r--drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c5
-rw-r--r--drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c2
-rw-r--r--drivers/net/ethernet/renesas/ravb_main.c6
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c29
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.h11
-rw-r--r--drivers/net/ethernet/smsc/Kconfig2
-rw-r--r--drivers/net/ethernet/smsc/smsc911x.c4
-rw-r--r--drivers/net/ethernet/socionext/sni_ave.c2
-rw-r--r--drivers/net/ethernet/sun/sunvnet.c2
-rw-r--r--drivers/net/ethernet/ti/cpsw.c3
-rw-r--r--drivers/net/hyperv/hyperv_net.h2
-rw-r--r--drivers/net/hyperv/netvsc.c85
-rw-r--r--drivers/net/hyperv/netvsc_drv.c343
-rw-r--r--drivers/net/hyperv/rndis_filter.c81
-rw-r--r--drivers/net/macsec.c5
-rw-r--r--drivers/net/macvlan.c4
-rw-r--r--drivers/net/phy/bcm-phy-lib.c4
-rw-r--r--drivers/net/phy/marvell.c4
-rw-r--r--drivers/net/phy/micrel.c27
-rw-r--r--drivers/net/phy/phy.c147
-rw-r--r--drivers/net/phy/phy_device.c52
-rw-r--r--drivers/net/phy/realtek.c2
-rw-r--r--drivers/net/ppp/ppp_generic.c35
-rw-r--r--drivers/net/team/team.c4
-rw-r--r--drivers/net/thunderbolt.c19
-rw-r--r--drivers/net/tun.c41
-rw-r--r--drivers/net/usb/cdc_ether.c6
-rw-r--r--drivers/net/usb/r8152.c2
-rw-r--r--drivers/net/usb/smsc75xx.c7
-rw-r--r--drivers/net/usb/usbnet.c10
-rw-r--r--drivers/net/virtio_net.c110
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c16
-rw-r--r--drivers/net/vmxnet3/vmxnet3_int.h7
-rw-r--r--drivers/net/wan/hdlc_ppp.c5
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_init.c1
-rw-r--r--drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h2
-rw-r--r--drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c10
-rw-r--r--drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.c3
-rw-r--r--drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c24
-rw-r--r--drivers/net/wireless/intel/iwlwifi/Kconfig1
-rw-r--r--drivers/net/wireless/intel/iwlwifi/fw/api/time-event.h4
-rw-r--r--drivers/net/wireless/intel/iwlwifi/fw/dbg.c13
-rw-r--r--drivers/net/wireless/intel/iwlwifi/fw/dbg.h3
-rw-r--r--drivers/net/wireless/intel/iwlwifi/fw/debugfs.h18
-rw-r--r--drivers/net/wireless/intel/iwlwifi/fw/init.c12
-rw-r--r--drivers/net/wireless/intel/iwlwifi/fw/runtime.h7
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/d3.c8
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c5
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c3
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c49
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/mvm.h2
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/ops.c10
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/rs.c28
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c39
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/sta.c33
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/time-event.c6
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/tx.c13
-rw-r--r--drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c2
-rw-r--r--drivers/net/wireless/intel/iwlwifi/pcie/tx.c2
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c3
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c3
-rw-r--r--drivers/net/xen-netfront.c7
-rw-r--r--drivers/nvdimm/blk.c3
-rw-r--r--drivers/nvdimm/btt.c3
-rw-r--r--drivers/nvdimm/pfn_devs.c2
-rw-r--r--drivers/nvdimm/pmem.c3
-rw-r--r--drivers/nvdimm/region_devs.c17
-rw-r--r--drivers/nvme/host/core.c59
-rw-r--r--drivers/nvme/host/fabrics.c7
-rw-r--r--drivers/nvme/host/fabrics.h9
-rw-r--r--drivers/nvme/host/fc.c184
-rw-r--r--drivers/nvme/host/multipath.c43
-rw-r--r--drivers/nvme/host/nvme.h11
-rw-r--r--drivers/nvme/host/pci.c59
-rw-r--r--drivers/nvme/host/rdma.c20
-rw-r--r--drivers/nvme/target/core.c9
-rw-r--r--drivers/nvme/target/io-cmd.c7
-rw-r--r--drivers/nvme/target/loop.c4
-rw-r--r--drivers/of/property.c4
-rw-r--r--drivers/opp/cpu.c2
-rw-r--r--drivers/pci/dwc/pcie-designware-host.c2
-rw-r--r--drivers/pci/quirks.c41
-rw-r--r--drivers/pci/setup-res.c4
-rw-r--r--drivers/perf/arm_pmu.c138
-rw-r--r--drivers/perf/arm_pmu_acpi.c61
-rw-r--r--drivers/perf/arm_pmu_platform.c37
-rw-r--r--drivers/phy/qualcomm/phy-qcom-ufs.c5
-rw-r--r--drivers/pinctrl/meson/pinctrl-meson-axg.c4
-rw-r--r--drivers/pinctrl/samsung/pinctrl-exynos-arm.c56
-rw-r--r--drivers/pinctrl/samsung/pinctrl-exynos-arm64.c14
-rw-r--r--drivers/pinctrl/samsung/pinctrl-s3c24xx.c28
-rw-r--r--drivers/pinctrl/samsung/pinctrl-s3c64xx.c7
-rw-r--r--drivers/pinctrl/samsung/pinctrl-samsung.c61
-rw-r--r--drivers/pinctrl/samsung/pinctrl-samsung.h40
-rw-r--r--drivers/pinctrl/sh-pfc/pfc-r8a7795.c1
-rw-r--r--drivers/platform/chrome/chromeos_laptop.c22
-rw-r--r--drivers/platform/x86/Kconfig28
-rw-r--r--drivers/platform/x86/Makefile5
-rw-r--r--drivers/platform/x86/dell-laptop.c20
-rw-r--r--drivers/platform/x86/dell-smbios-base.c (renamed from drivers/platform/x86/dell-smbios.c)31
-rw-r--r--drivers/platform/x86/dell-smbios-smm.c18
-rw-r--r--drivers/platform/x86/dell-smbios-wmi.c14
-rw-r--r--drivers/platform/x86/dell-smbios.h27
-rw-r--r--drivers/platform/x86/dell-wmi.c2
-rw-r--r--drivers/platform/x86/ideapad-laptop.c2
-rw-r--r--drivers/platform/x86/intel-hid.c1
-rw-r--r--drivers/platform/x86/intel-vbtn.c47
-rw-r--r--drivers/platform/x86/wmi.c8
-rw-r--r--drivers/regulator/core.c2
-rw-r--r--drivers/regulator/stm32-vrefbuf.c2
-rw-r--r--drivers/s390/block/dasd.c21
-rw-r--r--drivers/s390/cio/device_fsm.c7
-rw-r--r--drivers/s390/cio/device_ops.c72
-rw-r--r--drivers/s390/cio/io_sch.h1
-rw-r--r--drivers/s390/net/qeth_core_main.c50
-rw-r--r--drivers/s390/net/qeth_l2_main.c2
-rw-r--r--drivers/s390/net/qeth_l3.h34
-rw-r--r--drivers/s390/net/qeth_l3_main.c125
-rw-r--r--drivers/s390/virtio/virtio_ccw.c29
-rw-r--r--drivers/scsi/Makefile1
-rw-r--r--drivers/scsi/aacraid/linit.c4
-rw-r--r--drivers/scsi/aic7xxx/aiclib.c34
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_io.c1
-rw-r--r--drivers/scsi/csiostor/csio_lnode.c2
-rw-r--r--drivers/scsi/device_handler/scsi_dh_alua.c5
-rw-r--r--drivers/scsi/hosts.c3
-rw-r--r--drivers/scsi/ibmvscsi/ibmvfc.h2
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c33
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fusion.c42
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_base.c13
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_base.h3
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_scsih.c23
-rw-r--r--drivers/scsi/qedi/qedi_fw.c5
-rw-r--r--drivers/scsi/qedi/qedi_main.c55
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h5
-rw-r--r--drivers/scsi/qla2xxx/qla_gs.c5
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c75
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c7
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c6
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c75
-rw-r--r--drivers/scsi/qla2xxx/qla_target.c19
-rw-r--r--drivers/scsi/qla4xxx/ql4_def.h2
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c46
-rw-r--r--drivers/scsi/scsi_error.c5
-rw-r--r--drivers/scsi/scsi_lib.c4
-rw-r--r--drivers/scsi/sd.c3
-rw-r--r--drivers/scsi/sd_zbc.c35
-rw-r--r--drivers/scsi/storvsc_drv.c5
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.c2
-rw-r--r--drivers/scsi/ufs/ufshcd.c2
-rw-r--r--drivers/soc/fsl/qbman/qman.c28
-rw-r--r--drivers/soc/imx/gpc.c12
-rw-r--r--drivers/staging/android/ashmem.c32
-rw-r--r--drivers/staging/android/ion/ion_cma_heap.c17
-rw-r--r--drivers/staging/comedi/drivers.c3
-rw-r--r--drivers/staging/fsl-mc/bus/Kconfig2
-rw-r--r--drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c2
-rw-r--r--drivers/staging/iio/adc/ad7192.c27
-rw-r--r--drivers/staging/iio/impedance-analyzer/ad5933.c4
-rw-r--r--drivers/staging/ncpfs/ncplib_kernel.c4
-rw-r--r--drivers/tty/n_tty.c6
-rw-r--r--drivers/tty/serial/8250/8250_pci.c21
-rw-r--r--drivers/tty/serial/atmel_serial.c1
-rw-r--r--drivers/tty/serial/earlycon.c3
-rw-r--r--drivers/tty/serial/imx.c2
-rw-r--r--drivers/tty/serial/serial_core.c2
-rw-r--r--drivers/tty/serial/sh-sci.c2
-rw-r--r--drivers/tty/tty_io.c9
-rw-r--r--drivers/tty/vt/vt.c8
-rw-r--r--drivers/usb/Kconfig6
-rw-r--r--drivers/usb/class/cdc-acm.c9
-rw-r--r--drivers/usb/core/message.c4
-rw-r--r--drivers/usb/core/quirks.c6
-rw-r--r--drivers/usb/dwc2/gadget.c26
-rw-r--r--drivers/usb/dwc2/params.c6
-rw-r--r--drivers/usb/dwc3/core.c88
-rw-r--r--drivers/usb/dwc3/core.h21
-rw-r--r--drivers/usb/dwc3/dwc3-of-simple.c1
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c16
-rw-r--r--drivers/usb/dwc3/ep0.c7
-rw-r--r--drivers/usb/dwc3/gadget.c2
-rw-r--r--drivers/usb/gadget/function/f_fs.c45
-rw-r--r--drivers/usb/gadget/function/f_uac2.c2
-rw-r--r--drivers/usb/gadget/udc/Kconfig1
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc_pci.c1
-rw-r--r--drivers/usb/gadget/udc/core.c2
-rw-r--r--drivers/usb/gadget/udc/fsl_udc_core.c4
-rw-r--r--drivers/usb/gadget/udc/renesas_usb3.c2
-rw-r--r--drivers/usb/host/Kconfig8
-rw-r--r--drivers/usb/host/ehci-hub.c4
-rw-r--r--drivers/usb/host/ehci-q.c12
-rw-r--r--drivers/usb/host/ohci-hcd.c13
-rw-r--r--drivers/usb/host/ohci-hub.c4
-rw-r--r--drivers/usb/host/ohci-q.c17
-rw-r--r--drivers/usb/host/pci-quirks.c109
-rw-r--r--drivers/usb/host/pci-quirks.h5
-rw-r--r--drivers/usb/host/xhci-dbgcap.c20
-rw-r--r--drivers/usb/host/xhci-dbgtty.c20
-rw-r--r--drivers/usb/host/xhci-debugfs.c4
-rw-r--r--drivers/usb/host/xhci-hub.c25
-rw-r--r--drivers/usb/host/xhci-pci.c14
-rw-r--r--drivers/usb/host/xhci-plat.c11
-rw-r--r--drivers/usb/host/xhci-rcar.c4
-rw-r--r--drivers/usb/host/xhci.c13
-rw-r--r--drivers/usb/host/xhci.h25
-rw-r--r--drivers/usb/misc/ldusb.c6
-rw-r--r--drivers/usb/mon/mon_text.c126
-rw-r--r--drivers/usb/musb/musb_core.c7
-rw-r--r--drivers/usb/musb/musb_host.c8
-rw-r--r--drivers/usb/phy/phy-mxs-usb.c3
-rw-r--r--drivers/usb/renesas_usbhs/fifo.c5
-rw-r--r--drivers/usb/serial/option.c7
-rw-r--r--drivers/usb/storage/uas.c2
-rw-r--r--drivers/usb/storage/unusual_devs.h7
-rw-r--r--drivers/usb/typec/fusb302/fusb302.c3
-rw-r--r--drivers/usb/typec/tcpm.c163
-rw-r--r--drivers/usb/usbip/stub_dev.c3
-rw-r--r--drivers/usb/usbip/vhci_hcd.c2
-rw-r--r--drivers/usb/usbip/vudc_sysfs.c8
-rw-r--r--drivers/vfio/pci/vfio_pci.c3
-rw-r--r--drivers/vfio/vfio_iommu_type1.c18
-rw-r--r--drivers/vhost/net.c8
-rw-r--r--drivers/video/fbdev/geode/video_gx.c2
-rw-r--r--drivers/video/fbdev/sbuslib.c4
-rw-r--r--drivers/virtio/virtio_ring.c2
-rw-r--r--drivers/watchdog/Kconfig4
-rw-r--r--drivers/watchdog/f71808e_wdt.c3
-rw-r--r--drivers/watchdog/hpwdt.c501
-rw-r--r--drivers/watchdog/sbsa_gwdt.c3
-rw-r--r--drivers/watchdog/wdat_wdt.c2
-rw-r--r--drivers/xen/events/events_base.c4
-rw-r--r--drivers/xen/pvcalls-back.c2
-rw-r--r--drivers/xen/pvcalls-front.c208
-rw-r--r--drivers/xen/tmem.c4
-rw-r--r--drivers/xen/xenbus/xenbus.h1
-rw-r--r--drivers/xen/xenbus/xenbus_comms.c1
-rw-r--r--drivers/xen/xenbus/xenbus_probe.c5
-rw-r--r--drivers/xen/xenbus/xenbus_xs.c3
-rw-r--r--fs/aio.c44
-rw-r--r--fs/block_dev.c49
-rw-r--r--fs/btrfs/backref.c12
-rw-r--r--fs/btrfs/ctree.h7
-rw-r--r--fs/btrfs/delayed-ref.c3
-rw-r--r--fs/btrfs/extent-tree.c4
-rw-r--r--fs/btrfs/inode-item.c44
-rw-r--r--fs/btrfs/inode.c52
-rw-r--r--fs/btrfs/qgroup.c9
-rw-r--r--fs/btrfs/raid56.c1
-rw-r--r--fs/btrfs/relocation.c18
-rw-r--r--fs/btrfs/send.c3
-rw-r--r--fs/btrfs/super.c2
-rw-r--r--fs/btrfs/tree-log.c146
-rw-r--r--fs/btrfs/volumes.c12
-rw-r--r--fs/ceph/caps.c26
-rw-r--r--fs/ceph/dir.c28
-rw-r--r--fs/ceph/super.c27
-rw-r--r--fs/ceph/super.h2
-rw-r--r--fs/dcache.c21
-rw-r--r--fs/direct-io.c3
-rw-r--r--fs/efivarfs/file.c6
-rw-r--r--fs/gfs2/bmap.c40
-rw-r--r--fs/hugetlbfs/inode.c17
-rw-r--r--fs/namei.c5
-rw-r--r--fs/nfs/callback_proc.c14
-rw-r--r--fs/nfs/direct.c2
-rw-r--r--fs/nfs/nfs3proc.c2
-rw-r--r--fs/nfs/nfs4client.c6
-rw-r--r--fs/nfs/pnfs.c13
-rw-r--r--fs/nfs/super.c2
-rw-r--r--fs/nfs/write.c83
-rw-r--r--fs/nfsd/nfs4state.c62
-rw-r--r--fs/overlayfs/Kconfig14
-rw-r--r--fs/overlayfs/export.c216
-rw-r--r--fs/overlayfs/inode.c58
-rw-r--r--fs/overlayfs/namei.c6
-rw-r--r--fs/overlayfs/overlayfs.h1
-rw-r--r--fs/overlayfs/super.c1
-rw-r--r--fs/proc/kcore.c4
-rw-r--r--fs/signalfd.c15
-rw-r--r--fs/sysfs/symlink.c1
-rw-r--r--fs/xfs/scrub/agheader.c3
-rw-r--r--fs/xfs/xfs_iomap.c42
-rw-r--r--fs/xfs/xfs_refcount_item.c9
-rw-r--r--fs/xfs/xfs_rmap_item.c4
-rw-r--r--fs/xfs/xfs_super.c2
-rw-r--r--include/asm-generic/bitops/lock.h3
-rw-r--r--include/asm-generic/bug.h1
-rw-r--r--include/asm-generic/pgtable.h10
-rw-r--r--include/drm/drm_crtc_helper.h1
-rw-r--r--include/drm/drm_drv.h1
-rw-r--r--include/kvm/arm_vgic.h1
-rw-r--r--include/linux/acpi.h4
-rw-r--r--include/linux/bio.h4
-rw-r--r--include/linux/blkdev.h2
-rw-r--r--include/linux/cgroup-defs.h4
-rw-r--r--include/linux/compat.h30
-rw-r--r--include/linux/compiler-clang.h5
-rw-r--r--include/linux/compiler-gcc.h26
-rw-r--r--include/linux/compiler.h9
-rw-r--r--include/linux/cpuidle.h2
-rw-r--r--include/linux/cpumask.h2
-rw-r--r--include/linux/dma-mapping.h2
-rw-r--r--include/linux/fs.h3
-rw-r--r--include/linux/fsl_ifc.h6
-rw-r--r--include/linux/fwnode.h4
-rw-r--r--include/linux/genhd.h4
-rw-r--r--include/linux/if_tun.h4
-rw-r--r--include/linux/if_vlan.h66
-rw-r--r--include/linux/init.h8
-rw-r--r--include/linux/irqchip/arm-gic-v3.h1
-rw-r--r--include/linux/irqchip/arm-gic.h1
-rw-r--r--include/linux/jump_label.h3
-rw-r--r--include/linux/kconfig.h9
-rw-r--r--include/linux/kcore.h1
-rw-r--r--include/linux/kernel.h1
-rw-r--r--include/linux/kvm_host.h6
-rw-r--r--include/linux/memblock.h1
-rw-r--r--include/linux/memcontrol.h24
-rw-r--r--include/linux/mlx5/driver.h4
-rw-r--r--include/linux/mm_inline.h6
-rw-r--r--include/linux/mutex.h5
-rw-r--r--include/linux/net.h1
-rw-r--r--include/linux/netfilter/x_tables.h2
-rw-r--r--include/linux/nospec.h18
-rw-r--r--include/linux/of_pci.h17
-rw-r--r--include/linux/percpu-refcount.h18
-rw-r--r--include/linux/perf/arm_pmu.h26
-rw-r--r--include/linux/phy.h6
-rw-r--r--include/linux/property.h2
-rw-r--r--include/linux/ptr_ring.h2
-rw-r--r--include/linux/rhashtable.h4
-rw-r--r--include/linux/sched/mm.h13
-rw-r--r--include/linux/sched/user.h4
-rw-r--r--include/linux/semaphore.h2
-rw-r--r--include/linux/skbuff.h59
-rw-r--r--include/linux/swap.h2
-rw-r--r--include/linux/tty.h1
-rw-r--r--include/linux/u64_stats_sync.h22
-rw-r--r--include/linux/usb/quirks.h3
-rw-r--r--include/linux/workqueue.h2
-rw-r--r--include/media/demux.h21
-rw-r--r--include/media/dmxdev.h2
-rw-r--r--include/media/dvb_demux.h4
-rw-r--r--include/media/dvb_vb2.h20
-rw-r--r--include/net/devlink.h18
-rw-r--r--include/net/ip.h11
-rw-r--r--include/net/ip6_route.h3
-rw-r--r--include/net/ip_fib.h1
-rw-r--r--include/net/mac80211.h6
-rw-r--r--include/net/regulatory.h2
-rw-r--r--include/net/route.h6
-rw-r--r--include/net/sch_generic.h19
-rw-r--r--include/net/sock.h1
-rw-r--r--include/net/udplite.h1
-rw-r--r--include/rdma/ib_verbs.h4
-rw-r--r--include/rdma/restrack.h4
-rw-r--r--include/rdma/uverbs_ioctl.h43
-rw-r--r--include/scsi/scsi_cmnd.h3
-rw-r--r--include/scsi/scsi_host.h2
-rw-r--r--include/soc/arc/mcip.h5
-rw-r--r--include/sound/ac97/regs.h2
-rw-r--r--include/trace/events/mmc.h4
-rw-r--r--include/trace/events/xen.h2
-rw-r--r--include/uapi/asm-generic/siginfo.h4
-rw-r--r--include/uapi/drm/virtgpu_drm.h1
-rw-r--r--include/uapi/linux/blktrace_api.h2
-rw-r--r--include/uapi/linux/dvb/dmx.h35
-rw-r--r--include/uapi/linux/if_ether.h7
-rw-r--r--include/uapi/linux/kvm.h2
-rw-r--r--include/uapi/linux/libc-compat.h6
-rw-r--r--include/uapi/linux/lirc.h1
-rw-r--r--include/uapi/linux/psp-sev.h2
-rw-r--r--include/uapi/linux/ptrace.h4
-rw-r--r--include/uapi/linux/usb/audio.h4
-rw-r--r--include/uapi/misc/ocxl.h17
-rw-r--r--include/uapi/rdma/rdma_user_ioctl.h4
-rw-r--r--init/main.c2
-rw-r--r--ipc/mqueue.c74
-rw-r--r--kernel/bpf/arraymap.c33
-rw-r--r--kernel/bpf/core.c2
-rw-r--r--kernel/bpf/cpumap.c2
-rw-r--r--kernel/bpf/lpm_trie.c14
-rw-r--r--kernel/bpf/sockmap.c3
-rw-r--r--kernel/bpf/syscall.c2
-rw-r--r--kernel/bpf/verifier.c42
-rw-r--r--kernel/cgroup/cgroup.c10
-rw-r--r--kernel/compat.c19
-rw-r--r--kernel/events/core.c25
-rw-r--r--kernel/extable.c2
-rw-r--r--kernel/fail_function.c10
-rw-r--r--kernel/fork.c15
-rw-r--r--kernel/irq/irqdomain.c18
-rw-r--r--kernel/irq/matrix.c23
-rw-r--r--kernel/jump_label.c29
-rw-r--r--kernel/kprobes.c178
-rw-r--r--kernel/locking/mutex.c37
-rw-r--r--kernel/locking/qspinlock.c21
-rw-r--r--kernel/locking/rtmutex.c5
-rw-r--r--kernel/memremap.c16
-rw-r--r--kernel/module.c2
-rw-r--r--kernel/panic.c2
-rw-r--r--kernel/printk/printk.c3
-rw-r--r--kernel/relay.c2
-rw-r--r--kernel/sched/core.c42
-rw-r--r--kernel/sched/cpufreq_schedutil.c2
-rw-r--r--kernel/sched/deadline.c6
-rw-r--r--kernel/sched/debug.c29
-rw-r--r--kernel/sched/rt.c3
-rw-r--r--kernel/seccomp.c6
-rw-r--r--kernel/time/posix-timers.c11
-rw-r--r--kernel/time/timer.c6
-rw-r--r--kernel/trace/bpf_trace.c70
-rw-r--r--kernel/trace/trace_kprobe.c4
-rw-r--r--kernel/trace/trace_probe.c8
-rw-r--r--kernel/trace/trace_probe.h2
-rw-r--r--kernel/user.c3
-rw-r--r--kernel/workqueue.c26
-rw-r--r--lib/Kconfig.debug1
-rw-r--r--lib/btree.c10
-rw-r--r--lib/bug.c4
-rw-r--r--lib/dma-debug.c10
-rw-r--r--lib/dma-direct.c5
-rw-r--r--lib/idr.c15
-rw-r--r--lib/ioremap.c6
-rw-r--r--lib/percpu-refcount.c2
-rw-r--r--lib/radix-tree.c2
-rw-r--r--lib/rhashtable.c4
-rw-r--r--lib/test_bpf.c6
-rw-r--r--lib/test_kmod.c2
-rw-r--r--lib/test_rhashtable.c134
-rw-r--r--lib/vsprintf.c2
-rw-r--r--mm/gup.c7
-rw-r--r--mm/huge_memory.c9
-rw-r--r--mm/hugetlb.c9
-rw-r--r--mm/khugepaged.c15
-rw-r--r--mm/memblock.c28
-rw-r--r--mm/memory-failure.c2
-rw-r--r--mm/memory.c2
-rw-r--r--mm/mempolicy.c3
-rw-r--r--mm/mlock.c6
-rw-r--r--mm/page_alloc.c21
-rw-r--r--mm/percpu-km.c8
-rw-r--r--mm/percpu-vm.c18
-rw-r--r--mm/percpu.c67
-rw-r--r--mm/shmem.c31
-rw-r--r--mm/swap.c84
-rw-r--r--mm/vmalloc.c10
-rw-r--r--mm/vmscan.c90
-rw-r--r--mm/zpool.c2
-rw-r--r--mm/zswap.c6
-rw-r--r--net/8021q/vlan_core.c4
-rw-r--r--net/9p/trans_virtio.c3
-rw-r--r--net/batman-adv/bat_iv_ogm.c26
-rw-r--r--net/batman-adv/bat_v.c2
-rw-r--r--net/batman-adv/bridge_loop_avoidance.c22
-rw-r--r--net/batman-adv/distributed-arp-table.c2
-rw-r--r--net/batman-adv/fragmentation.c3
-rw-r--r--net/batman-adv/hard-interface.c9
-rw-r--r--net/batman-adv/icmp_socket.c1
-rw-r--r--net/batman-adv/log.c1
-rw-r--r--net/batman-adv/multicast.c4
-rw-r--r--net/batman-adv/originator.c4
-rw-r--r--net/batman-adv/originator.h4
-rw-r--r--net/batman-adv/routing.c25
-rw-r--r--net/batman-adv/soft-interface.c8
-rw-r--r--net/batman-adv/types.h11
-rw-r--r--net/bluetooth/smp.c8
-rw-r--r--net/bridge/br_netfilter_hooks.c4
-rw-r--r--net/bridge/br_sysfs_if.c3
-rw-r--r--net/bridge/br_vlan.c2
-rw-r--r--net/bridge/netfilter/ebt_among.c65
-rw-r--r--net/bridge/netfilter/ebt_limit.c4
-rw-r--r--net/bridge/netfilter/ebtables.c44
-rw-r--r--net/ceph/ceph_common.c7
-rw-r--r--net/core/dev.c47
-rw-r--r--net/core/dev_ioctl.c7
-rw-r--r--net/core/devlink.c62
-rw-r--r--net/core/ethtool.c5
-rw-r--r--net/core/filter.c66
-rw-r--r--net/core/gen_estimator.c1
-rw-r--r--net/core/skbuff.c59
-rw-r--r--net/core/sock.c21
-rw-r--r--net/core/sock_diag.c12
-rw-r--r--net/dccp/proto.c5
-rw-r--r--net/decnet/af_decnet.c62
-rw-r--r--net/dsa/legacy.c2
-rw-r--r--net/ieee802154/6lowpan/core.c12
-rw-r--r--net/ipv4/fib_semantics.c5
-rw-r--r--net/ipv4/inet_diag.c3
-rw-r--r--net/ipv4/inet_fragment.c3
-rw-r--r--net/ipv4/ip_forward.c2
-rw-r--r--net/ipv4/ip_gre.c5
-rw-r--r--net/ipv4/ip_output.c2
-rw-r--r--net/ipv4/ip_sockglue.c13
-rw-r--r--net/ipv4/ip_tunnel.c13
-rw-r--r--net/ipv4/netfilter/arp_tables.c4
-rw-r--r--net/ipv4/netfilter/ip_tables.c7
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c35
-rw-r--r--net/ipv4/netfilter/ipt_ECN.c12
-rw-r--r--net/ipv4/netfilter/ipt_REJECT.c4
-rw-r--r--net/ipv4/netfilter/ipt_rpfilter.c6
-rw-r--r--net/ipv4/netfilter/nf_flow_table_ipv4.c3
-rw-r--r--net/ipv4/route.c67
-rw-r--r--net/ipv4/tcp.c1
-rw-r--r--net/ipv4/tcp_illinois.c2
-rw-r--r--net/ipv4/tcp_input.c24
-rw-r--r--net/ipv4/tcp_output.c34
-rw-r--r--net/ipv4/tcp_timer.c1
-rw-r--r--net/ipv4/udp.c5
-rw-r--r--net/ipv4/xfrm4_mode_tunnel.c3
-rw-r--r--net/ipv4/xfrm4_output.c3
-rw-r--r--net/ipv4/xfrm4_policy.c5
-rw-r--r--net/ipv6/datagram.c21
-rw-r--r--net/ipv6/ip6_checksum.c5
-rw-r--r--net/ipv6/ip6_gre.c8
-rw-r--r--net/ipv6/ip6_output.c2
-rw-r--r--net/ipv6/ip6_tunnel.c12
-rw-r--r--net/ipv6/ipv6_sockglue.c10
-rw-r--r--net/ipv6/ndisc.c3
-rw-r--r--net/ipv6/netfilter.c9
-rw-r--r--net/ipv6/netfilter/ip6_tables.c4
-rw-r--r--net/ipv6/netfilter/ip6t_REJECT.c4
-rw-r--r--net/ipv6/netfilter/ip6t_rpfilter.c10
-rw-r--r--net/ipv6/netfilter/ip6t_srh.c6
-rw-r--r--net/ipv6/netfilter/nf_flow_table_ipv6.c2
-rw-r--r--net/ipv6/netfilter/nf_nat_l3proto_ipv6.c4
-rw-r--r--net/ipv6/netfilter/nft_fib_ipv6.c12
-rw-r--r--net/ipv6/route.c76
-rw-r--r--net/ipv6/seg6_iptunnel.c7
-rw-r--r--net/ipv6/sit.c9
-rw-r--r--net/ipv6/xfrm6_mode_tunnel.c3
-rw-r--r--net/ipv6/xfrm6_output.c2
-rw-r--r--net/ipv6/xfrm6_policy.c5
-rw-r--r--net/iucv/af_iucv.c4
-rw-r--r--net/kcm/kcmsock.c33
-rw-r--r--net/l2tp/l2tp_core.c188
-rw-r--r--net/l2tp/l2tp_core.h26
-rw-r--r--net/l2tp/l2tp_ip.c10
-rw-r--r--net/l2tp/l2tp_ip6.c8
-rw-r--r--net/l2tp/l2tp_ppp.c60
-rw-r--r--net/mac80211/agg-rx.c4
-rw-r--r--net/mac80211/cfg.c2
-rw-r--r--net/mac80211/debugfs.c1
-rw-r--r--net/mac80211/ieee80211_i.h2
-rw-r--r--net/mac80211/mesh.c17
-rw-r--r--net/mac80211/mlme.c3
-rw-r--r--net/mac80211/rx.c2
-rw-r--r--net/mac80211/spectmgmt.c7
-rw-r--r--net/mac80211/sta_info.c3
-rw-r--r--net/mac80211/tx.c8
-rw-r--r--net/mpls/af_mpls.c2
-rw-r--r--net/netfilter/ipvs/ip_vs_ftp.c2
-rw-r--r--net/netfilter/nf_nat_proto_common.c7
-rw-r--r--net/netfilter/nf_tables_api.c26
-rw-r--r--net/netfilter/nft_set_hash.c2
-rw-r--r--net/netfilter/x_tables.c104
-rw-r--r--net/netfilter/xt_AUDIT.c4
-rw-r--r--net/netfilter/xt_CHECKSUM.c8
-rw-r--r--net/netfilter/xt_CONNSECMARK.c10
-rw-r--r--net/netfilter/xt_CT.c25
-rw-r--r--net/netfilter/xt_DSCP.c4
-rw-r--r--net/netfilter/xt_HL.c13
-rw-r--r--net/netfilter/xt_HMARK.c27
-rw-r--r--net/netfilter/xt_IDLETIMER.c9
-rw-r--r--net/netfilter/xt_LED.c16
-rw-r--r--net/netfilter/xt_NFQUEUE.c8
-rw-r--r--net/netfilter/xt_SECMARK.c18
-rw-r--r--net/netfilter/xt_TCPMSS.c10
-rw-r--r--net/netfilter/xt_TPROXY.c6
-rw-r--r--net/netfilter/xt_addrtype.c33
-rw-r--r--net/netfilter/xt_bpf.c4
-rw-r--r--net/netfilter/xt_cgroup.c8
-rw-r--r--net/netfilter/xt_cluster.c8
-rw-r--r--net/netfilter/xt_connbytes.c4
-rw-r--r--net/netfilter/xt_connlabel.c7
-rw-r--r--net/netfilter/xt_connmark.c8
-rw-r--r--net/netfilter/xt_conntrack.c4
-rw-r--r--net/netfilter/xt_dscp.c4
-rw-r--r--net/netfilter/xt_ecn.c4
-rw-r--r--net/netfilter/xt_hashlimit.c42
-rw-r--r--net/netfilter/xt_helper.c4
-rw-r--r--net/netfilter/xt_ipcomp.c2
-rw-r--r--net/netfilter/xt_ipvs.c3
-rw-r--r--net/netfilter/xt_l2tp.c22
-rw-r--r--net/netfilter/xt_limit.c4
-rw-r--r--net/netfilter/xt_nat.c5
-rw-r--r--net/netfilter/xt_nfacct.c6
-rw-r--r--net/netfilter/xt_physdev.c4
-rw-r--r--net/netfilter/xt_policy.c23
-rw-r--r--net/netfilter/xt_recent.c20
-rw-r--r--net/netfilter/xt_set.c50
-rw-r--r--net/netfilter/xt_socket.c10
-rw-r--r--net/netfilter/xt_state.c4
-rw-r--r--net/netfilter/xt_time.c6
-rw-r--r--net/netlink/af_netlink.c4
-rw-r--r--net/netlink/genetlink.c2
-rw-r--r--net/nfc/llcp_commands.c4
-rw-r--r--net/nfc/netlink.c3
-rw-r--r--net/openvswitch/meter.c12
-rw-r--r--net/qrtr/smd.c1
-rw-r--r--net/rds/connection.c2
-rw-r--r--net/rds/tcp_listen.c14
-rw-r--r--net/rxrpc/output.c2
-rw-r--r--net/rxrpc/recvmsg.c5
-rw-r--r--net/sched/act_bpf.c2
-rw-r--r--net/sched/act_csum.c5
-rw-r--r--net/sched/act_ipt.c9
-rw-r--r--net/sched/act_pedit.c2
-rw-r--r--net/sched/act_police.c2
-rw-r--r--net/sched/act_sample.c3
-rw-r--r--net/sched/act_simple.c2
-rw-r--r--net/sched/act_skbmod.c5
-rw-r--r--net/sched/act_tunnel_key.c10
-rw-r--r--net/sched/act_vlan.c5
-rw-r--r--net/sched/cls_api.c33
-rw-r--r--net/sched/cls_u32.c24
-rw-r--r--net/sched/sch_generic.c22
-rw-r--r--net/sched/sch_netem.c2
-rw-r--r--net/sched/sch_tbf.c3
-rw-r--r--net/sctp/debug.c6
-rw-r--r--net/sctp/input.c13
-rw-r--r--net/sctp/inqueue.c2
-rw-r--r--net/sctp/offload.c2
-rw-r--r--net/sctp/stream.c2
-rw-r--r--net/sctp/stream_interleave.c16
-rw-r--r--net/smc/af_smc.c8
-rw-r--r--net/smc/smc_cdc.c2
-rw-r--r--net/smc/smc_close.c25
-rw-r--r--net/smc/smc_core.c3
-rw-r--r--net/smc/smc_llc.c2
-rw-r--r--net/socket.c5
-rw-r--r--net/tipc/bearer.c82
-rw-r--r--net/tipc/bearer.h4
-rw-r--r--net/tipc/group.c1
-rw-r--r--net/tipc/net.c15
-rw-r--r--net/tipc/net.h1
-rw-r--r--net/tipc/netlink_compat.c43
-rw-r--r--net/tipc/socket.c1
-rw-r--r--net/tls/tls_main.c59
-rw-r--r--net/unix/af_unix.c2
-rw-r--r--net/wireless/Kconfig13
-rw-r--r--net/wireless/mesh.c25
-rw-r--r--net/wireless/sme.c2
-rw-r--r--net/xfrm/xfrm_device.c2
-rw-r--r--net/xfrm/xfrm_ipcomp.c2
-rw-r--r--net/xfrm/xfrm_policy.c13
-rw-r--r--net/xfrm/xfrm_replay.c2
-rw-r--r--net/xfrm/xfrm_state.c5
-rw-r--r--net/xfrm/xfrm_user.c21
-rw-r--r--samples/seccomp/Makefile10
-rw-r--r--scripts/Makefile.build8
-rw-r--r--scripts/Makefile.lib8
-rw-r--r--scripts/basic/fixdep.c15
-rwxr-xr-xscripts/bloat-o-meter2
-rw-r--r--scripts/coccinelle/api/memdup.cocci4
-rw-r--r--scripts/kallsyms.c2
-rw-r--r--scripts/kconfig/confdata.c2
-rw-r--r--scripts/kconfig/kxgettext.c2
-rw-r--r--scripts/kconfig/lkc.h1
-rwxr-xr-xscripts/kconfig/lxdialog/check-lxdialog.sh3
-rw-r--r--scripts/kconfig/menu.c1
-rw-r--r--scripts/kconfig/symbol.c4
-rw-r--r--scripts/kconfig/util.c11
-rw-r--r--scripts/kconfig/zconf.l12
-rw-r--r--scripts/kconfig/zconf.y3
-rwxr-xr-xscripts/link-vmlinux.sh2
-rw-r--r--security/integrity/digsig.c1
-rw-r--r--security/keys/big_key.c110
-rw-r--r--sound/ac97/Kconfig1
-rw-r--r--sound/core/control.c2
-rw-r--r--sound/core/oss/pcm_oss.c10
-rw-r--r--sound/core/seq/seq_clientmgr.c30
-rw-r--r--sound/core/seq/seq_fifo.c2
-rw-r--r--sound/core/seq/seq_memory.c14
-rw-r--r--sound/core/seq/seq_memory.h3
-rw-r--r--sound/core/seq/seq_prioq.c28
-rw-r--r--sound/core/seq/seq_prioq.h6
-rw-r--r--sound/core/seq/seq_queue.c28
-rw-r--r--sound/drivers/aloop.c17
-rw-r--r--sound/pci/hda/hda_intel.c43
-rw-r--r--sound/pci/hda/patch_conexant.c2
-rw-r--r--sound/pci/hda/patch_realtek.c136
-rw-r--r--sound/soc/amd/acp-pcm-dma.c16
-rw-r--r--sound/soc/amd/acp.h2
-rw-r--r--sound/soc/codecs/hdmi-codec.c7
-rw-r--r--sound/soc/codecs/rt5651.c1
-rw-r--r--sound/soc/codecs/sgtl5000.c26
-rw-r--r--sound/soc/codecs/wm_adsp.c14
-rw-r--r--sound/soc/sunxi/sun4i-i2s.c2
-rw-r--r--sound/usb/mixer.c18
-rw-r--r--sound/usb/pcm.c9
-rw-r--r--sound/usb/quirks-table.h47
-rw-r--r--sound/usb/quirks.c7
-rw-r--r--sound/x86/intel_hdmi_audio.c37
-rw-r--r--tools/arch/powerpc/include/uapi/asm/kvm.h2
-rw-r--r--tools/arch/s390/include/uapi/asm/unistd.h412
-rw-r--r--tools/arch/x86/include/asm/cpufeatures.h2
-rw-r--r--tools/bpf/bpftool/common.c4
-rw-r--r--tools/bpf/bpftool/main.c2
-rw-r--r--tools/bpf/bpftool/prog.c3
-rw-r--r--tools/cgroup/Makefile1
-rw-r--r--tools/gpio/Makefile2
-rw-r--r--tools/hv/Makefile1
-rw-r--r--tools/iio/Makefile2
-rw-r--r--tools/include/uapi/drm/i915_drm.h77
-rw-r--r--tools/include/uapi/linux/if_link.h1
-rw-r--r--tools/include/uapi/linux/kvm.h92
-rwxr-xr-xtools/kvm/kvm_stat/kvm_stat503
-rw-r--r--tools/kvm/kvm_stat/kvm_stat.txt4
-rw-r--r--tools/laptop/freefall/Makefile1
-rw-r--r--tools/leds/Makefile1
-rw-r--r--tools/lib/bpf/libbpf.c5
-rw-r--r--tools/objtool/builtin-check.c6
-rw-r--r--tools/objtool/builtin-orc.c6
-rw-r--r--tools/objtool/builtin.h5
-rw-r--r--tools/objtool/check.c146
-rw-r--r--tools/objtool/check.h4
-rw-r--r--tools/perf/Documentation/perf-data.txt4
-rw-r--r--tools/perf/Documentation/perf-kallsyms.txt2
-rw-r--r--tools/perf/Makefile.perf6
-rw-r--r--tools/perf/arch/s390/Makefile10
-rwxr-xr-xtools/perf/arch/s390/entry/syscalls/mksyscalltbl18
-rw-r--r--tools/perf/arch/s390/entry/syscalls/syscall.tbl390
-rw-r--r--tools/perf/builtin-c2c.c4
-rw-r--r--tools/perf/builtin-record.c9
-rw-r--r--tools/perf/builtin-report.c3
-rw-r--r--tools/perf/builtin-stat.c2
-rw-r--r--tools/perf/builtin-top.c150
-rwxr-xr-xtools/perf/check-headers.sh1
-rw-r--r--tools/perf/perf.h1
-rw-r--r--tools/perf/pmu-events/arch/arm64/cortex-a53/branch.json27
-rw-r--r--tools/perf/pmu-events/arch/arm64/cortex-a53/bus.json22
-rw-r--r--tools/perf/pmu-events/arch/arm64/cortex-a53/cache.json27
-rw-r--r--tools/perf/pmu-events/arch/arm64/cortex-a53/memory.json22
-rw-r--r--tools/perf/pmu-events/arch/arm64/cortex-a53/other.json32
-rw-r--r--tools/perf/pmu-events/arch/arm64/cortex-a53/pipeline.json52
-rw-r--r--tools/perf/pmu-events/arch/arm64/mapfile.csv1
-rw-r--r--tools/perf/tests/backward-ring-buffer.c7
-rwxr-xr-xtools/perf/tests/shell/trace+probe_libc_inet_pton.sh23
-rw-r--r--tools/perf/ui/browsers/annotate.c25
-rw-r--r--tools/perf/ui/browsers/hists.c38
-rw-r--r--tools/perf/ui/browsers/hists.h3
-rw-r--r--tools/perf/util/auxtrace.c15
-rw-r--r--tools/perf/util/evlist.c17
-rw-r--r--tools/perf/util/evlist.h4
-rw-r--r--tools/perf/util/evsel.c12
-rw-r--r--tools/perf/util/evsel.h14
-rw-r--r--tools/perf/util/hist.h6
-rw-r--r--tools/perf/util/mmap.c141
-rw-r--r--tools/perf/util/mmap.h10
-rw-r--r--tools/perf/util/record.c8
-rw-r--r--tools/perf/util/trigger.h9
-rw-r--r--tools/perf/util/util.c24
-rw-r--r--tools/power/acpi/Makefile.config3
-rw-r--r--tools/scripts/Makefile.include18
-rw-r--r--tools/spi/Makefile2
-rw-r--r--tools/testing/radix-tree/idr-test.c52
-rw-r--r--tools/testing/radix-tree/linux.c11
-rw-r--r--tools/testing/radix-tree/linux/compiler_types.h0
-rw-r--r--tools/testing/radix-tree/linux/gfp.h1
-rw-r--r--tools/testing/radix-tree/linux/slab.h6
-rw-r--r--tools/testing/selftests/android/Makefile8
-rw-r--r--tools/testing/selftests/bpf/.gitignore1
-rw-r--r--tools/testing/selftests/bpf/test_maps.c2
-rw-r--r--tools/testing/selftests/bpf/test_tcpbpf_kern.c1
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c84
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc46
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc97
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc43
-rw-r--r--tools/testing/selftests/futex/Makefile6
-rw-r--r--tools/testing/selftests/memfd/Makefile1
-rw-r--r--tools/testing/selftests/memfd/config1
-rw-r--r--tools/testing/selftests/memory-hotplug/Makefile5
-rw-r--r--tools/testing/selftests/powerpc/alignment/alignment_handler.c2
-rw-r--r--tools/testing/selftests/powerpc/mm/subpage_prot.c14
-rw-r--r--tools/testing/selftests/powerpc/tm/Makefile2
-rw-r--r--tools/testing/selftests/powerpc/tm/tm-trap.c2
-rw-r--r--tools/testing/selftests/pstore/config1
-rw-r--r--tools/testing/selftests/seccomp/seccomp_bpf.c61
-rw-r--r--tools/testing/selftests/sync/Makefile2
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/skbmod.json2
-rw-r--r--tools/testing/selftests/vDSO/Makefile14
-rw-r--r--tools/testing/selftests/vm/.gitignore1
-rwxr-xr-xtools/testing/selftests/vm/run_vmtests25
-rw-r--r--tools/testing/selftests/x86/Makefile24
-rw-r--r--tools/testing/selftests/x86/entry_from_vm86.c32
-rw-r--r--tools/testing/selftests/x86/mpx-mini-test.c32
-rw-r--r--tools/testing/selftests/x86/protection_keys.c28
-rw-r--r--tools/testing/selftests/x86/ptrace_syscall.c8
-rw-r--r--tools/testing/selftests/x86/single_step_syscall.c5
-rw-r--r--tools/testing/selftests/x86/test_mremap_vdso.c4
-rw-r--r--tools/testing/selftests/x86/test_vdso.c55
-rw-r--r--tools/testing/selftests/x86/test_vsyscall.c22
-rw-r--r--tools/usb/Makefile1
-rw-r--r--tools/vm/Makefile1
-rw-r--r--tools/wmi/Makefile1
-rw-r--r--virt/kvm/arm/arch_timer.c122
-rw-r--r--virt/kvm/arm/arm.c9
-rw-r--r--virt/kvm/arm/hyp/vgic-v3-sr.c3
-rw-r--r--virt/kvm/arm/mmu.c6
-rw-r--r--virt/kvm/arm/vgic/vgic-mmio.c3
-rw-r--r--virt/kvm/arm/vgic/vgic-v2.c11
-rw-r--r--virt/kvm/arm/vgic/vgic-v3.c9
-rw-r--r--virt/kvm/arm/vgic/vgic.c87
-rw-r--r--virt/kvm/arm/vgic/vgic.h3
-rw-r--r--virt/kvm/kvm_main.c3
1554 files changed, 17357 insertions, 10527 deletions
diff --git a/.gitignore b/.gitignore
index 705e09913dc2..1be78fd8163b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -127,3 +127,7 @@ all.config
127 127
128# Kdevelop4 128# Kdevelop4
129*.kdev4 129*.kdev4
130
131#Automatically generated by ASN.1 compiler
132net/ipv4/netfilter/nf_nat_snmp_basic-asn1.c
133net/ipv4/netfilter/nf_nat_snmp_basic-asn1.h
diff --git a/Documentation/ABI/testing/sysfs-ata b/Documentation/ABI/testing/sysfs-ata
index aa4296498859..9ab0ef1dd1c7 100644
--- a/Documentation/ABI/testing/sysfs-ata
+++ b/Documentation/ABI/testing/sysfs-ata
@@ -1,110 +1,139 @@
1What: /sys/class/ata_... 1What: /sys/class/ata_...
2Date: August 2008
3Contact: Gwendal Grignou<gwendal@google.com>
4Description: 2Description:
5 3 Provide a place in sysfs for storing the ATA topology of the
6Provide a place in sysfs for storing the ATA topology of the system. This allows 4 system. This allows retrieving various information about ATA
7retrieving various information about ATA objects. 5 objects.
8 6
9Files under /sys/class/ata_port 7Files under /sys/class/ata_port
10------------------------------- 8-------------------------------
11 9
12 For each port, a directory ataX is created where X is the ata_port_id of 10For each port, a directory ataX is created where X is the ata_port_id of the
13 the port. The device parent is the ata host device. 11port. The device parent is the ata host device.
14 12
15idle_irq (read)
16 13
17 Number of IRQ received by the port while idle [some ata HBA only]. 14What: /sys/class/ata_port/ataX/nr_pmp_links
15What: /sys/class/ata_port/ataX/idle_irq
16Date: May, 2010
17KernelVersion: v2.6.37
18Contact: Gwendal Grignou <gwendal@chromium.org>
19Description:
20 nr_pmp_links: (RO) If a SATA Port Multiplier (PM) is
21 connected, the number of links behind it.
18 22
19nr_pmp_links (read) 23 idle_irq: (RO) Number of IRQ received by the port while
24 idle [some ata HBA only].
20 25
21 If a SATA Port Multiplier (PM) is connected, number of link behind it. 26
27What: /sys/class/ata_port/ataX/port_no
28Date: May, 2013
29KernelVersion: v3.11
30Contact: Gwendal Grignou <gwendal@chromium.org>
31Description:
32 (RO) Host local port number. While registering host controller,
33 port numbers are tracked based upon number of ports available on
34 the controller. This attribute is needed by udev for composing
35 persistent links in /dev/disk/by-path.
22 36
23Files under /sys/class/ata_link 37Files under /sys/class/ata_link
24------------------------------- 38-------------------------------
25 39
26 Behind each port, there is a ata_link. If there is a SATA PM in the 40Behind each port, there is a ata_link. If there is a SATA PM in the topology, 15
27 topology, 15 ata_link objects are created. 41ata_link objects are created.
28
29 If a link is behind a port, the directory name is linkX, where X is
30 ata_port_id of the port.
31 If a link is behind a PM, its name is linkX.Y where X is ata_port_id
32 of the parent port and Y the PM port.
33 42
34hw_sata_spd_limit 43If a link is behind a port, the directory name is linkX, where X is ata_port_id
44of the port. If a link is behind a PM, its name is linkX.Y where X is
45ata_port_id of the parent port and Y the PM port.
35 46
36 Maximum speed supported by the connected SATA device.
37 47
38sata_spd_limit 48What: /sys/class/ata_link/linkX[.Y]/hw_sata_spd_limit
49What: /sys/class/ata_link/linkX[.Y]/sata_spd_limit
50What: /sys/class/ata_link/linkX[.Y]/sata_spd
51Date: May, 2010
52KernelVersion: v2.6.37
53Contact: Gwendal Grignou <gwendal@chromium.org>
54Description:
55 hw_sata_spd_limit: (RO) Maximum speed supported by the
56 connected SATA device.
39 57
40 Maximum speed imposed by libata. 58 sata_spd_limit: (RO) Maximum speed imposed by libata.
41 59
42sata_spd 60 sata_spd: (RO) Current speed of the link
61 eg. 1.5, 3 Gbps etc.
43 62
44 Current speed of the link [1.5, 3Gps,...].
45 63
46Files under /sys/class/ata_device 64Files under /sys/class/ata_device
47--------------------------------- 65---------------------------------
48 66
49 Behind each link, up to two ata device are created. 67Behind each link, up to two ata devices are created.
50 The name of the directory is devX[.Y].Z where: 68The name of the directory is devX[.Y].Z where:
51 - X is ata_port_id of the port where the device is connected, 69- X is ata_port_id of the port where the device is connected,
52 - Y the port of the PM if any, and 70- Y the port of the PM if any, and
53 - Z the device id: for PATA, there is usually 2 devices [0,1], 71- Z the device id: for PATA, there is usually 2 devices [0,1], only 1 for SATA.
54 only 1 for SATA. 72
55 73
56class 74What: /sys/class/ata_device/devX[.Y].Z/spdn_cnt
57 Device class. Can be "ata" for disk, "atapi" for packet device, 75What: /sys/class/ata_device/devX[.Y].Z/gscr
58 "pmp" for PM, or "none" if no device was found behind the link. 76What: /sys/class/ata_device/devX[.Y].Z/ering
59 77What: /sys/class/ata_device/devX[.Y].Z/id
60dma_mode 78What: /sys/class/ata_device/devX[.Y].Z/pio_mode
79What: /sys/class/ata_device/devX[.Y].Z/xfer_mode
80What: /sys/class/ata_device/devX[.Y].Z/dma_mode
81What: /sys/class/ata_device/devX[.Y].Z/class
82Date: May, 2010
83KernelVersion: v2.6.37
84Contact: Gwendal Grignou <gwendal@chromium.org>
85Description:
86 spdn_cnt: (RO) Number of times libata decided to lower the
87 speed of link due to errors.
61 88
62 Transfer modes supported by the device when in DMA mode. 89 gscr: (RO) Cached result of the dump of PM GSCR
63 Mostly used by PATA device. 90 register. Valid registers are:
64 91
65pio_mode 92 0: SATA_PMP_GSCR_PROD_ID,
93 1: SATA_PMP_GSCR_REV,
94 2: SATA_PMP_GSCR_PORT_INFO,
95 32: SATA_PMP_GSCR_ERROR,
96 33: SATA_PMP_GSCR_ERROR_EN,
97 64: SATA_PMP_GSCR_FEAT,
98 96: SATA_PMP_GSCR_FEAT_EN,
99 130: SATA_PMP_GSCR_SII_GPIO
66 100
67 Transfer modes supported by the device when in PIO mode. 101 Only valid if the device is a PM.
68 Mostly used by PATA device.
69 102
70xfer_mode 103 ering: (RO) Formatted output of the error ring of the
104 device.
71 105
72 Current transfer mode. 106 id: (RO) Cached result of IDENTIFY command, as
107 described in ATA8 7.16 and 7.17. Only valid if
108 the device is not a PM.
73 109
74id 110 pio_mode: (RO) Transfer modes supported by the device when
111 in PIO mode. Mostly used by PATA device.
75 112
76 Cached result of IDENTIFY command, as described in ATA8 7.16 and 7.17. 113 xfer_mode: (RO) Current transfer mode
77 Only valid if the device is not a PM.
78 114
79gscr 115 dma_mode: (RO) Transfer modes supported by the device when
116 in DMA mode. Mostly used by PATA device.
80 117
81 Cached result of the dump of PM GSCR register. 118 class: (RO) Device class. Can be "ata" for disk,
82 Valid registers are: 119 "atapi" for packet device, "pmp" for PM, or
83 0: SATA_PMP_GSCR_PROD_ID, 120 "none" if no device was found behind the link.
84 1: SATA_PMP_GSCR_REV,
85 2: SATA_PMP_GSCR_PORT_INFO,
86 32: SATA_PMP_GSCR_ERROR,
87 33: SATA_PMP_GSCR_ERROR_EN,
88 64: SATA_PMP_GSCR_FEAT,
89 96: SATA_PMP_GSCR_FEAT_EN,
90 130: SATA_PMP_GSCR_SII_GPIO
91 Only valid if the device is a PM.
92 121
93trim
94 122
95 Shows the DSM TRIM mode currently used by the device. Valid 123What: /sys/class/ata_device/devX[.Y].Z/trim
96 values are: 124Date: May, 2015
97 unsupported: Drive does not support DSM TRIM 125KernelVersion: v4.10
98 unqueued: Drive supports unqueued DSM TRIM only 126Contact: Gwendal Grignou <gwendal@chromium.org>
99 queued: Drive supports queued DSM TRIM 127Description:
100 forced_unqueued: Drive's queued DSM support is known to be 128 (RO) Shows the DSM TRIM mode currently used by the device. Valid
101 buggy and only unqueued TRIM commands 129 values are:
102 are sent
103 130
104spdn_cnt 131 unsupported: Drive does not support DSM TRIM
105 132
106 Number of time libata decided to lower the speed of link due to errors. 133 unqueued: Drive supports unqueued DSM TRIM only
107 134
108ering 135 queued: Drive supports queued DSM TRIM
109 136
110 Formatted output of the error ring of the device. 137 forced_unqueued: Drive's queued DSM support is known to
138 be buggy and only unqueued TRIM commands
139 are sent
diff --git a/Documentation/ABI/testing/sysfs-block-device b/Documentation/ABI/testing/sysfs-block-device
new file mode 100644
index 000000000000..82ef6eab042d
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-block-device
@@ -0,0 +1,58 @@
1What: /sys/block/*/device/sw_activity
2Date: Jun, 2008
3KernelVersion: v2.6.27
4Contact: linux-ide@vger.kernel.org
5Description:
6 (RW) Used by drivers which support software controlled activity
7 LEDs.
8
9 It has the following valid values:
10
11 0 OFF - the LED is not activated on activity
12 1 BLINK_ON - the LED blinks on every 10ms when activity is
13 detected.
14 2 BLINK_OFF - the LED is on when idle, and blinks off
15 every 10ms when activity is detected.
16
17 Note that the user must turn sw_activity OFF it they wish to
18 control the activity LED via the em_message file.
19
20
21What: /sys/block/*/device/unload_heads
22Date: Sep, 2008
23KernelVersion: v2.6.28
24Contact: linux-ide@vger.kernel.org
25Description:
26 (RW) Hard disk shock protection
27
28 Writing an integer value to this file will take the heads of the
29 respective drive off the platter and block all I/O operations
30 for the specified number of milliseconds.
31
32 - If the device does not support the unload heads feature,
33 access is denied with -EOPNOTSUPP.
34 - The maximal value accepted for a timeout is 30000
35 milliseconds.
36 - A previously set timeout can be cancelled and disk can resume
37 normal operation immediately by specifying a timeout of 0.
38 - Some hard drives only comply with an earlier version of the
39 ATA standard, but support the unload feature nonetheless.
40 There is no safe way Linux can detect these devices, so this
41 is not enabled by default. If it is known that your device
42 does support the unload feature, then you can tell the kernel
43 to enable it by writing -1. It can be disabled again by
44 writing -2.
45 - Values below -2 are rejected with -EINVAL
46
47 For more information, see
48 Documentation/laptops/disk-shock-protection.txt
49
50
51What: /sys/block/*/device/ncq_prio_enable
52Date: Oct, 2016
53KernelVersion: v4.10
54Contact: linux-ide@vger.kernel.org
55Description:
56 (RW) Write to the file to turn on or off the SATA ncq (native
57 command queueing) support. By default this feature is turned
58 off.
diff --git a/Documentation/ABI/testing/sysfs-class-scsi_host b/Documentation/ABI/testing/sysfs-class-scsi_host
index 0eb255e7db12..bafc59fd7b69 100644
--- a/Documentation/ABI/testing/sysfs-class-scsi_host
+++ b/Documentation/ABI/testing/sysfs-class-scsi_host
@@ -27,3 +27,92 @@ Description: This file contains the current status of the "SSD Smart Path"
27 the direct i/o path to physical devices. This setting is 27 the direct i/o path to physical devices. This setting is
28 controller wide, affecting all configured logical drives on the 28 controller wide, affecting all configured logical drives on the
29 controller. This file is readable and writable. 29 controller. This file is readable and writable.
30
31What: /sys/class/scsi_host/hostX/link_power_management_policy
32Date: Oct, 2007
33KernelVersion: v2.6.24
34Contact: linux-ide@vger.kernel.org
35Description:
36 (RW) This parameter allows the user to read and set the link
37 (interface) power management.
38
39 There are four possible options:
40
41 min_power: Tell the controller to try to make the link use the
42 least possible power when possible. This may sacrifice some
43 performance due to increased latency when coming out of lower
44 power states.
45
46 max_performance: Generally, this means no power management.
47 Tell the controller to have performance be a priority over power
48 management.
49
50 medium_power: Tell the controller to enter a lower power state
51 when possible, but do not enter the lowest power state, thus
52 improving latency over min_power setting.
53
54 med_power_with_dipm: Identical to the existing medium_power
55 setting except that it enables dipm (device initiated power
56 management) on top, which makes it match the Windows IRST (Intel
57 Rapid Storage Technology) driver settings. This setting is also
58 close to min_power, except that:
59 a) It does not use host-initiated slumber mode, but it does
60 allow device-initiated slumber
61 b) It does not enable low power device sleep mode (DevSlp).
62
63What: /sys/class/scsi_host/hostX/em_message
64What: /sys/class/scsi_host/hostX/em_message_type
65Date: Jun, 2008
66KernelVersion: v2.6.27
67Contact: linux-ide@vger.kernel.org
68Description:
69 em_message: (RW) Enclosure management support. For the LED
70 protocol, writes and reads correspond to the LED message format
71 as defined in the AHCI spec.
72
73 The user must turn sw_activity (under /sys/block/*/device/) OFF
74 it they wish to control the activity LED via the em_message
75 file.
76
77 em_message_type: (RO) Displays the current enclosure management
78 protocol that is being used by the driver (for eg. LED, SAF-TE,
79 SES-2, SGPIO etc).
80
81What: /sys/class/scsi_host/hostX/ahci_port_cmd
82What: /sys/class/scsi_host/hostX/ahci_host_caps
83What: /sys/class/scsi_host/hostX/ahci_host_cap2
84Date: Mar, 2010
85KernelVersion: v2.6.35
86Contact: linux-ide@vger.kernel.org
87Description:
88 [to be documented]
89
90What: /sys/class/scsi_host/hostX/ahci_host_version
91Date: Mar, 2010
92KernelVersion: v2.6.35
93Contact: linux-ide@vger.kernel.org
94Description:
95 (RO) Display the version of the AHCI spec implemented by the
96 host.
97
98What: /sys/class/scsi_host/hostX/em_buffer
99Date: Apr, 2010
100KernelVersion: v2.6.35
101Contact: linux-ide@vger.kernel.org
102Description:
103 (RW) Allows access to AHCI EM (enclosure management) buffer
104 directly if the host supports EM.
105
106 For eg. the AHCI driver supports SGPIO EM messages but the
107 SATA/AHCI specs do not define the SGPIO message format of the EM
108 buffer. Different hardware(HW) vendors may have different
109 definitions. With the em_buffer attribute, this issue can be
110 solved by allowing HW vendors to provide userland drivers and
111 tools for their SGPIO initiators.
112
113What: /sys/class/scsi_host/hostX/em_message_supported
114Date: Oct, 2009
115KernelVersion: v2.6.39
116Contact: linux-ide@vger.kernel.org
117Description:
118 (RO) Displays supported enclosure management message types.
diff --git a/Documentation/ABI/testing/sysfs-devices-platform-dock b/Documentation/ABI/testing/sysfs-devices-platform-dock
new file mode 100644
index 000000000000..1d8c18f905c7
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-platform-dock
@@ -0,0 +1,39 @@
1What: /sys/devices/platform/dock.N/docked
2Date: Dec, 2006
3KernelVersion: 2.6.19
4Contact: linux-acpi@vger.kernel.org
5Description:
6 (RO) Value 1 or 0 indicates whether the software believes the
7 laptop is docked in a docking station.
8
9What: /sys/devices/platform/dock.N/undock
10Date: Dec, 2006
11KernelVersion: 2.6.19
12Contact: linux-acpi@vger.kernel.org
13Description:
14 (WO) Writing to this file causes the software to initiate an
15 undock request to the firmware.
16
17What: /sys/devices/platform/dock.N/uid
18Date: Feb, 2007
19KernelVersion: v2.6.21
20Contact: linux-acpi@vger.kernel.org
21Description:
22 (RO) Displays the docking station the laptop is docked to.
23
24What: /sys/devices/platform/dock.N/flags
25Date: May, 2007
26KernelVersion: v2.6.21
27Contact: linux-acpi@vger.kernel.org
28Description:
29 (RO) Show dock station flags, useful for checking if undock
30 request has been made by the user (from the immediate_undock
31 option).
32
33What: /sys/devices/platform/dock.N/type
34Date: Aug, 2008
35KernelVersion: v2.6.27
36Contact: linux-acpi@vger.kernel.org
37Description:
38 (RO) Display the dock station type- dock_station, ata_bay or
39 battery_bay.
diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index bfd29bc8d37a..4ed63b6cfb15 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -108,6 +108,8 @@ Description: CPU topology files that describe a logical CPU's relationship
108 108
109What: /sys/devices/system/cpu/cpuidle/current_driver 109What: /sys/devices/system/cpu/cpuidle/current_driver
110 /sys/devices/system/cpu/cpuidle/current_governer_ro 110 /sys/devices/system/cpu/cpuidle/current_governer_ro
111 /sys/devices/system/cpu/cpuidle/available_governors
112 /sys/devices/system/cpu/cpuidle/current_governor
111Date: September 2007 113Date: September 2007
112Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org> 114Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
113Description: Discover cpuidle policy and mechanism 115Description: Discover cpuidle policy and mechanism
@@ -119,13 +121,84 @@ Description: Discover cpuidle policy and mechanism
119 Idle policy (governor) is differentiated from idle mechanism 121 Idle policy (governor) is differentiated from idle mechanism
120 (driver) 122 (driver)
121 123
122 current_driver: displays current idle mechanism 124 current_driver: (RO) displays current idle mechanism
123 125
124 current_governor_ro: displays current idle policy 126 current_governor_ro: (RO) displays current idle policy
127
128 With the cpuidle_sysfs_switch boot option enabled (meant for
129 developer testing), the following three attributes are visible
130 instead:
131
132 current_driver: same as described above
133
134 available_governors: (RO) displays a space separated list of
135 available governors
136
137 current_governor: (RW) displays current idle policy. Users can
138 switch the governor at runtime by writing to this file.
125 139
126 See files in Documentation/cpuidle/ for more information. 140 See files in Documentation/cpuidle/ for more information.
127 141
128 142
143What: /sys/devices/system/cpu/cpuX/cpuidle/stateN/name
144 /sys/devices/system/cpu/cpuX/cpuidle/stateN/latency
145 /sys/devices/system/cpu/cpuX/cpuidle/stateN/power
146 /sys/devices/system/cpu/cpuX/cpuidle/stateN/time
147 /sys/devices/system/cpu/cpuX/cpuidle/stateN/usage
148Date: September 2007
149KernelVersion: v2.6.24
150Contact: Linux power management list <linux-pm@vger.kernel.org>
151Description:
152 The directory /sys/devices/system/cpu/cpuX/cpuidle contains per
153 logical CPU specific cpuidle information for each online cpu X.
154 The processor idle states which are available for use have the
155 following attributes:
156
157 name: (RO) Name of the idle state (string).
158
159 latency: (RO) The latency to exit out of this idle state (in
160 microseconds).
161
162 power: (RO) The power consumed while in this idle state (in
163 milliwatts).
164
165 time: (RO) The total time spent in this idle state (in microseconds).
166
167 usage: (RO) Number of times this state was entered (a count).
168
169
170What: /sys/devices/system/cpu/cpuX/cpuidle/stateN/desc
171Date: February 2008
172KernelVersion: v2.6.25
173Contact: Linux power management list <linux-pm@vger.kernel.org>
174Description:
175 (RO) A small description about the idle state (string).
176
177
178What: /sys/devices/system/cpu/cpuX/cpuidle/stateN/disable
179Date: March 2012
180KernelVersion: v3.10
181Contact: Linux power management list <linux-pm@vger.kernel.org>
182Description:
183 (RW) Option to disable this idle state (bool). The behavior and
184 the effect of the disable variable depends on the implementation
185 of a particular governor. In the ladder governor, for example,
186 it is not coherent, i.e. if one is disabling a light state, then
187 all deeper states are disabled as well, but the disable variable
188 does not reflect it. Likewise, if one enables a deep state but a
189 lighter state still is disabled, then this has no effect.
190
191
192What: /sys/devices/system/cpu/cpuX/cpuidle/stateN/residency
193Date: March 2014
194KernelVersion: v3.15
195Contact: Linux power management list <linux-pm@vger.kernel.org>
196Description:
197 (RO) Display the target residency i.e. the minimum amount of
198 time (in microseconds) this cpu should spend in this idle state
199 to make the transition worth the effort.
200
201
129What: /sys/devices/system/cpu/cpu#/cpufreq/* 202What: /sys/devices/system/cpu/cpu#/cpufreq/*
130Date: pre-git history 203Date: pre-git history
131Contact: linux-pm@vger.kernel.org 204Contact: linux-pm@vger.kernel.org
diff --git a/Documentation/ABI/testing/sysfs-platform-dptf b/Documentation/ABI/testing/sysfs-platform-dptf
new file mode 100644
index 000000000000..325dc0667dbb
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-dptf
@@ -0,0 +1,40 @@
1What: /sys/bus/platform/devices/INT3407:00/dptf_power/charger_type
2Date: Jul, 2016
3KernelVersion: v4.10
4Contact: linux-acpi@vger.kernel.org
5Description:
6 (RO) The charger type - Traditional, Hybrid or NVDC.
7
8What: /sys/bus/platform/devices/INT3407:00/dptf_power/adapter_rating_mw
9Date: Jul, 2016
10KernelVersion: v4.10
11Contact: linux-acpi@vger.kernel.org
12Description:
13 (RO) Adapter rating in milliwatts (the maximum Adapter power).
14 Must be 0 if no AC Adaptor is plugged in.
15
16What: /sys/bus/platform/devices/INT3407:00/dptf_power/max_platform_power_mw
17Date: Jul, 2016
18KernelVersion: v4.10
19Contact: linux-acpi@vger.kernel.org
20Description:
21 (RO) Maximum platform power that can be supported by the battery
22 in milliwatts.
23
24What: /sys/bus/platform/devices/INT3407:00/dptf_power/platform_power_source
25Date: Jul, 2016
26KernelVersion: v4.10
27Contact: linux-acpi@vger.kernel.org
28Description:
29 (RO) Display the platform power source
30 0x00 = DC
31 0x01 = AC
32 0x02 = USB
33 0x03 = Wireless Charger
34
35What: /sys/bus/platform/devices/INT3407:00/dptf_power/battery_steady_power
36Date: Jul, 2016
37KernelVersion: v4.10
38Contact: linux-acpi@vger.kernel.org
39Description:
40 (RO) The maximum sustained power for battery in milliwatts.
diff --git a/Documentation/PCI/pci.txt b/Documentation/PCI/pci.txt
index 611a75e4366e..badb26ac33dc 100644
--- a/Documentation/PCI/pci.txt
+++ b/Documentation/PCI/pci.txt
@@ -570,7 +570,9 @@ your driver if they're helpful, or just use plain hex constants.
570The device IDs are arbitrary hex numbers (vendor controlled) and normally used 570The device IDs are arbitrary hex numbers (vendor controlled) and normally used
571only in a single location, the pci_device_id table. 571only in a single location, the pci_device_id table.
572 572
573Please DO submit new vendor/device IDs to http://pciids.sourceforge.net/. 573Please DO submit new vendor/device IDs to http://pci-ids.ucw.cz/.
574There are mirrors of the pci.ids file at http://pciids.sourceforge.net/
575and https://github.com/pciutils/pciids.
574 576
575 577
576 578
diff --git a/Documentation/accelerators/ocxl.rst b/Documentation/accelerators/ocxl.rst
index 4f7af841d935..ddcc58d01cfb 100644
--- a/Documentation/accelerators/ocxl.rst
+++ b/Documentation/accelerators/ocxl.rst
@@ -152,6 +152,11 @@ OCXL_IOCTL_IRQ_SET_FD:
152 Associate an event fd to an AFU interrupt so that the user process 152 Associate an event fd to an AFU interrupt so that the user process
153 can be notified when the AFU sends an interrupt. 153 can be notified when the AFU sends an interrupt.
154 154
155OCXL_IOCTL_GET_METADATA:
156
157 Obtains configuration information from the card, such at the size of
158 MMIO areas, the AFU version, and the PASID for the current context.
159
155 160
156mmap 161mmap
157---- 162----
diff --git a/Documentation/atomic_bitops.txt b/Documentation/atomic_bitops.txt
index 5550bfdcce5f..be70b32c95d9 100644
--- a/Documentation/atomic_bitops.txt
+++ b/Documentation/atomic_bitops.txt
@@ -58,7 +58,12 @@ Like with atomic_t, the rule of thumb is:
58 58
59 - RMW operations that have a return value are fully ordered. 59 - RMW operations that have a return value are fully ordered.
60 60
61Except for test_and_set_bit_lock() which has ACQUIRE semantics and 61 - RMW operations that are conditional are unordered on FAILURE,
62 otherwise the above rules apply. In the case of test_and_{}_bit() operations,
63 if the bit in memory is unchanged by the operation then it is deemed to have
64 failed.
65
66Except for a successful test_and_set_bit_lock() which has ACQUIRE semantics and
62clear_bit_unlock() which has RELEASE semantics. 67clear_bit_unlock() which has RELEASE semantics.
63 68
64Since a platform only has a single means of achieving atomic operations 69Since a platform only has a single means of achieving atomic operations
diff --git a/Documentation/devicetree/bindings/misc/arm-charlcd.txt b/Documentation/devicetree/bindings/auxdisplay/arm-charlcd.txt
index e28e2aac47f1..e28e2aac47f1 100644
--- a/Documentation/devicetree/bindings/misc/arm-charlcd.txt
+++ b/Documentation/devicetree/bindings/auxdisplay/arm-charlcd.txt
diff --git a/Documentation/devicetree/bindings/display/exynos/exynos_hdmi.txt b/Documentation/devicetree/bindings/display/exynos/exynos_hdmi.txt
index 6394ea9e3b9e..58b12e25bbb1 100644
--- a/Documentation/devicetree/bindings/display/exynos/exynos_hdmi.txt
+++ b/Documentation/devicetree/bindings/display/exynos/exynos_hdmi.txt
@@ -16,6 +16,7 @@ Required properties:
16- ddc: phandle to the hdmi ddc node 16- ddc: phandle to the hdmi ddc node
17- phy: phandle to the hdmi phy node 17- phy: phandle to the hdmi phy node
18- samsung,syscon-phandle: phandle for system controller node for PMU. 18- samsung,syscon-phandle: phandle for system controller node for PMU.
19- #sound-dai-cells: should be 0.
19 20
20Required properties for Exynos 4210, 4212, 5420 and 5433: 21Required properties for Exynos 4210, 4212, 5420 and 5433:
21- clocks: list of clock IDs from SoC clock driver. 22- clocks: list of clock IDs from SoC clock driver.
diff --git a/Documentation/devicetree/bindings/dma/mv-xor-v2.txt b/Documentation/devicetree/bindings/dma/mv-xor-v2.txt
index 217a90eaabe7..9c38bbe7e6d7 100644
--- a/Documentation/devicetree/bindings/dma/mv-xor-v2.txt
+++ b/Documentation/devicetree/bindings/dma/mv-xor-v2.txt
@@ -11,7 +11,11 @@ Required properties:
11 interrupts. 11 interrupts.
12 12
13Optional properties: 13Optional properties:
14- clocks: Optional reference to the clock used by the XOR engine. 14- clocks: Optional reference to the clocks used by the XOR engine.
15- clock-names: mandatory if there is a second clock, in this case the
16 name must be "core" for the first clock and "reg" for the second
17 one
18
15 19
16Example: 20Example:
17 21
diff --git a/Documentation/devicetree/bindings/eeprom/at24.txt b/Documentation/devicetree/bindings/eeprom/at24.txt
index 1812c848e369..abfae1beca2b 100644
--- a/Documentation/devicetree/bindings/eeprom/at24.txt
+++ b/Documentation/devicetree/bindings/eeprom/at24.txt
@@ -38,9 +38,9 @@ Required properties:
38 38
39 "catalyst", 39 "catalyst",
40 "microchip", 40 "microchip",
41 "nxp",
41 "ramtron", 42 "ramtron",
42 "renesas", 43 "renesas",
43 "nxp",
44 "st", 44 "st",
45 45
46 Some vendors use different model names for chips which are just 46 Some vendors use different model names for chips which are just
diff --git a/Documentation/devicetree/bindings/iio/adc/sigma-delta-modulator.txt b/Documentation/devicetree/bindings/iio/adc/sigma-delta-modulator.txt
index e9ebb8a20e0d..ba24ca7ba95e 100644
--- a/Documentation/devicetree/bindings/iio/adc/sigma-delta-modulator.txt
+++ b/Documentation/devicetree/bindings/iio/adc/sigma-delta-modulator.txt
@@ -3,11 +3,11 @@ Device-Tree bindings for sigma delta modulator
3Required properties: 3Required properties:
4- compatible: should be "ads1201", "sd-modulator". "sd-modulator" can be use 4- compatible: should be "ads1201", "sd-modulator". "sd-modulator" can be use
5 as a generic SD modulator if modulator not specified in compatible list. 5 as a generic SD modulator if modulator not specified in compatible list.
6- #io-channel-cells = <1>: See the IIO bindings section "IIO consumers". 6- #io-channel-cells = <0>: See the IIO bindings section "IIO consumers".
7 7
8Example node: 8Example node:
9 9
10 ads1202: adc@0 { 10 ads1202: adc@0 {
11 compatible = "sd-modulator"; 11 compatible = "sd-modulator";
12 #io-channel-cells = <1>; 12 #io-channel-cells = <0>;
13 }; 13 };
diff --git a/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt b/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt
index 33c9a10fdc91..20f121daa910 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt
+++ b/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt
@@ -14,6 +14,7 @@ Required properties:
14 - "renesas,irqc-r8a7794" (R-Car E2) 14 - "renesas,irqc-r8a7794" (R-Car E2)
15 - "renesas,intc-ex-r8a7795" (R-Car H3) 15 - "renesas,intc-ex-r8a7795" (R-Car H3)
16 - "renesas,intc-ex-r8a7796" (R-Car M3-W) 16 - "renesas,intc-ex-r8a7796" (R-Car M3-W)
17 - "renesas,intc-ex-r8a77965" (R-Car M3-N)
17 - "renesas,intc-ex-r8a77970" (R-Car V3M) 18 - "renesas,intc-ex-r8a77970" (R-Car V3M)
18 - "renesas,intc-ex-r8a77995" (R-Car D3) 19 - "renesas,intc-ex-r8a77995" (R-Car D3)
19- #interrupt-cells: has to be <2>: an interrupt index and flags, as defined in 20- #interrupt-cells: has to be <2>: an interrupt index and flags, as defined in
diff --git a/Documentation/devicetree/bindings/net/dsa/marvell.txt b/Documentation/devicetree/bindings/net/dsa/marvell.txt
index 1d4d0f49c9d0..8c033d48e2ba 100644
--- a/Documentation/devicetree/bindings/net/dsa/marvell.txt
+++ b/Documentation/devicetree/bindings/net/dsa/marvell.txt
@@ -50,14 +50,15 @@ Example:
50 compatible = "marvell,mv88e6085"; 50 compatible = "marvell,mv88e6085";
51 reg = <0>; 51 reg = <0>;
52 reset-gpios = <&gpio5 1 GPIO_ACTIVE_LOW>; 52 reset-gpios = <&gpio5 1 GPIO_ACTIVE_LOW>;
53 }; 53
54 mdio { 54 mdio {
55 #address-cells = <1>; 55 #address-cells = <1>;
56 #size-cells = <0>; 56 #size-cells = <0>;
57 switch1phy0: switch1phy0@0 { 57 switch1phy0: switch1phy0@0 {
58 reg = <0>; 58 reg = <0>;
59 interrupt-parent = <&switch0>; 59 interrupt-parent = <&switch0>;
60 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 60 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
61 };
61 }; 62 };
62 }; 63 };
63 }; 64 };
@@ -74,23 +75,24 @@ Example:
74 compatible = "marvell,mv88e6390"; 75 compatible = "marvell,mv88e6390";
75 reg = <0>; 76 reg = <0>;
76 reset-gpios = <&gpio5 1 GPIO_ACTIVE_LOW>; 77 reset-gpios = <&gpio5 1 GPIO_ACTIVE_LOW>;
77 }; 78
78 mdio { 79 mdio {
79 #address-cells = <1>; 80 #address-cells = <1>;
80 #size-cells = <0>; 81 #size-cells = <0>;
81 switch1phy0: switch1phy0@0 { 82 switch1phy0: switch1phy0@0 {
82 reg = <0>; 83 reg = <0>;
83 interrupt-parent = <&switch0>; 84 interrupt-parent = <&switch0>;
84 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 85 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
86 };
85 }; 87 };
86 };
87 88
88 mdio1 { 89 mdio1 {
89 compatible = "marvell,mv88e6xxx-mdio-external"; 90 compatible = "marvell,mv88e6xxx-mdio-external";
90 #address-cells = <1>; 91 #address-cells = <1>;
91 #size-cells = <0>; 92 #size-cells = <0>;
92 switch1phy9: switch1phy0@9 { 93 switch1phy9: switch1phy0@9 {
93 reg = <9>; 94 reg = <9>;
95 };
94 }; 96 };
95 }; 97 };
96 }; 98 };
diff --git a/Documentation/devicetree/bindings/net/renesas,ravb.txt b/Documentation/devicetree/bindings/net/renesas,ravb.txt
index c902261893b9..b4dc455eb155 100644
--- a/Documentation/devicetree/bindings/net/renesas,ravb.txt
+++ b/Documentation/devicetree/bindings/net/renesas,ravb.txt
@@ -18,6 +18,7 @@ Required properties:
18 - "renesas,etheravb-r8a7795" for the R8A7795 SoC. 18 - "renesas,etheravb-r8a7795" for the R8A7795 SoC.
19 - "renesas,etheravb-r8a7796" for the R8A7796 SoC. 19 - "renesas,etheravb-r8a7796" for the R8A7796 SoC.
20 - "renesas,etheravb-r8a77970" for the R8A77970 SoC. 20 - "renesas,etheravb-r8a77970" for the R8A77970 SoC.
21 - "renesas,etheravb-r8a77980" for the R8A77980 SoC.
21 - "renesas,etheravb-r8a77995" for the R8A77995 SoC. 22 - "renesas,etheravb-r8a77995" for the R8A77995 SoC.
22 - "renesas,etheravb-rcar-gen3" as a fallback for the above 23 - "renesas,etheravb-rcar-gen3" as a fallback for the above
23 R-Car Gen3 devices. 24 R-Car Gen3 devices.
@@ -26,7 +27,11 @@ Required properties:
26 SoC-specific version corresponding to the platform first followed by 27 SoC-specific version corresponding to the platform first followed by
27 the generic version. 28 the generic version.
28 29
29- reg: offset and length of (1) the register block and (2) the stream buffer. 30- reg: Offset and length of (1) the register block and (2) the stream buffer.
31 The region for the register block is mandatory.
32 The region for the stream buffer is optional, as it is only present on
33 R-Car Gen2 and RZ/G1 SoCs, and on R-Car H3 (R8A7795), M3-W (R8A7796),
34 and M3-N (R8A77965).
30- interrupts: A list of interrupt-specifiers, one for each entry in 35- interrupts: A list of interrupt-specifiers, one for each entry in
31 interrupt-names. 36 interrupt-names.
32 If interrupt-names is not present, an interrupt specifier 37 If interrupt-names is not present, an interrupt specifier
diff --git a/Documentation/devicetree/bindings/power/mti,mips-cpc.txt b/Documentation/devicetree/bindings/power/mti,mips-cpc.txt
new file mode 100644
index 000000000000..c6b82511ae8a
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/mti,mips-cpc.txt
@@ -0,0 +1,8 @@
1Binding for MIPS Cluster Power Controller (CPC).
2
3This binding allows a system to specify where the CPC registers are
4located.
5
6Required properties:
7compatible : Should be "mti,mips-cpc".
8regs: Should describe the address & size of the CPC register region.
diff --git a/Documentation/devicetree/bindings/power/wakeup-source.txt b/Documentation/devicetree/bindings/power/wakeup-source.txt
index 3c81f78b5c27..5d254ab13ebf 100644
--- a/Documentation/devicetree/bindings/power/wakeup-source.txt
+++ b/Documentation/devicetree/bindings/power/wakeup-source.txt
@@ -60,7 +60,7 @@ Examples
60 #size-cells = <0>; 60 #size-cells = <0>;
61 61
62 button@1 { 62 button@1 {
63 debounce_interval = <50>; 63 debounce-interval = <50>;
64 wakeup-source; 64 wakeup-source;
65 linux,code = <116>; 65 linux,code = <116>;
66 label = "POWER"; 66 label = "POWER";
diff --git a/Documentation/devicetree/bindings/thermal/imx-thermal.txt b/Documentation/devicetree/bindings/thermal/imx-thermal.txt
index 28be51afdb6a..379eb763073e 100644
--- a/Documentation/devicetree/bindings/thermal/imx-thermal.txt
+++ b/Documentation/devicetree/bindings/thermal/imx-thermal.txt
@@ -22,7 +22,32 @@ Optional properties:
22- clocks : thermal sensor's clock source. 22- clocks : thermal sensor's clock source.
23 23
24Example: 24Example:
25ocotp: ocotp@21bc000 {
26 #address-cells = <1>;
27 #size-cells = <1>;
28 compatible = "fsl,imx6sx-ocotp", "syscon";
29 reg = <0x021bc000 0x4000>;
30 clocks = <&clks IMX6SX_CLK_OCOTP>;
25 31
32 tempmon_calib: calib@38 {
33 reg = <0x38 4>;
34 };
35
36 tempmon_temp_grade: temp-grade@20 {
37 reg = <0x20 4>;
38 };
39};
40
41tempmon: tempmon {
42 compatible = "fsl,imx6sx-tempmon", "fsl,imx6q-tempmon";
43 interrupts = <GIC_SPI 49 IRQ_TYPE_LEVEL_HIGH>;
44 fsl,tempmon = <&anatop>;
45 nvmem-cells = <&tempmon_calib>, <&tempmon_temp_grade>;
46 nvmem-cell-names = "calib", "temp_grade";
47 clocks = <&clks IMX6SX_CLK_PLL3_USB_OTG>;
48};
49
50Legacy method (Deprecated):
26tempmon { 51tempmon {
27 compatible = "fsl,imx6q-tempmon"; 52 compatible = "fsl,imx6q-tempmon";
28 fsl,tempmon = <&anatop>; 53 fsl,tempmon = <&anatop>;
diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt b/Documentation/devicetree/bindings/usb/dwc2.txt
index e64d903bcbe8..46da5f184460 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -19,7 +19,7 @@ Required properties:
19 configured in FS mode; 19 configured in FS mode;
20 - "st,stm32f4x9-hsotg": The DWC2 USB HS controller instance in STM32F4x9 SoCs 20 - "st,stm32f4x9-hsotg": The DWC2 USB HS controller instance in STM32F4x9 SoCs
21 configured in HS mode; 21 configured in HS mode;
22 - "st,stm32f7xx-hsotg": The DWC2 USB HS controller instance in STM32F7xx SoCs 22 - "st,stm32f7-hsotg": The DWC2 USB HS controller instance in STM32F7 SoCs
23 configured in HS mode; 23 configured in HS mode;
24- reg : Should contain 1 register range (address and length) 24- reg : Should contain 1 register range (address and length)
25- interrupts : Should contain 1 interrupt 25- interrupts : Should contain 1 interrupt
diff --git a/Documentation/devicetree/bindings/usb/renesas_usb3.txt b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
index 87a45e2f9b7f..2c071bb5801e 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
@@ -4,6 +4,7 @@ Required properties:
4 - compatible: Must contain one of the following: 4 - compatible: Must contain one of the following:
5 - "renesas,r8a7795-usb3-peri" 5 - "renesas,r8a7795-usb3-peri"
6 - "renesas,r8a7796-usb3-peri" 6 - "renesas,r8a7796-usb3-peri"
7 - "renesas,r8a77965-usb3-peri"
7 - "renesas,rcar-gen3-usb3-peri" for a generic R-Car Gen3 compatible 8 - "renesas,rcar-gen3-usb3-peri" for a generic R-Car Gen3 compatible
8 device 9 device
9 10
diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
index d060172f1529..43960faf5a88 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
@@ -12,6 +12,7 @@ Required properties:
12 - "renesas,usbhs-r8a7794" for r8a7794 (R-Car E2) compatible device 12 - "renesas,usbhs-r8a7794" for r8a7794 (R-Car E2) compatible device
13 - "renesas,usbhs-r8a7795" for r8a7795 (R-Car H3) compatible device 13 - "renesas,usbhs-r8a7795" for r8a7795 (R-Car H3) compatible device
14 - "renesas,usbhs-r8a7796" for r8a7796 (R-Car M3-W) compatible device 14 - "renesas,usbhs-r8a7796" for r8a7796 (R-Car M3-W) compatible device
15 - "renesas,usbhs-r8a77965" for r8a77965 (R-Car M3-N) compatible device
15 - "renesas,usbhs-r8a77995" for r8a77995 (R-Car D3) compatible device 16 - "renesas,usbhs-r8a77995" for r8a77995 (R-Car D3) compatible device
16 - "renesas,usbhs-r7s72100" for r7s72100 (RZ/A1) compatible device 17 - "renesas,usbhs-r7s72100" for r7s72100 (RZ/A1) compatible device
17 - "renesas,rcar-gen2-usbhs" for R-Car Gen2 or RZ/G1 compatible devices 18 - "renesas,rcar-gen2-usbhs" for R-Car Gen2 or RZ/G1 compatible devices
diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt b/Documentation/devicetree/bindings/usb/usb-xhci.txt
index e2ea59bbca93..1651483a7048 100644
--- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
@@ -13,6 +13,7 @@ Required properties:
13 - "renesas,xhci-r8a7793" for r8a7793 SoC 13 - "renesas,xhci-r8a7793" for r8a7793 SoC
14 - "renesas,xhci-r8a7795" for r8a7795 SoC 14 - "renesas,xhci-r8a7795" for r8a7795 SoC
15 - "renesas,xhci-r8a7796" for r8a7796 SoC 15 - "renesas,xhci-r8a7796" for r8a7796 SoC
16 - "renesas,xhci-r8a77965" for r8a77965 SoC
16 - "renesas,rcar-gen2-xhci" for a generic R-Car Gen2 or RZ/G1 compatible 17 - "renesas,rcar-gen2-xhci" for a generic R-Car Gen2 or RZ/G1 compatible
17 device 18 device
18 - "renesas,rcar-gen3-xhci" for a generic R-Car Gen3 compatible device 19 - "renesas,rcar-gen3-xhci" for a generic R-Car Gen3 compatible device
diff --git a/Documentation/features/sched/membarrier-sync-core/arch-support.txt b/Documentation/features/sched/membarrier-sync-core/arch-support.txt
new file mode 100644
index 000000000000..2c815a7f1ba7
--- /dev/null
+++ b/Documentation/features/sched/membarrier-sync-core/arch-support.txt
@@ -0,0 +1,62 @@
1#
2# Feature name: membarrier-sync-core
3# Kconfig: ARCH_HAS_MEMBARRIER_SYNC_CORE
4# description: arch supports core serializing membarrier
5#
6# Architecture requirements
7#
8# * arm64
9#
10# Rely on eret context synchronization when returning from IPI handler, and
11# when returning to user-space.
12#
13# * x86
14#
15# x86-32 uses IRET as return from interrupt, which takes care of the IPI.
16# However, it uses both IRET and SYSEXIT to go back to user-space. The IRET
17# instruction is core serializing, but not SYSEXIT.
18#
19# x86-64 uses IRET as return from interrupt, which takes care of the IPI.
20# However, it can return to user-space through either SYSRETL (compat code),
21# SYSRETQ, or IRET.
22#
23# Given that neither SYSRET{L,Q}, nor SYSEXIT, are core serializing, we rely
24# instead on write_cr3() performed by switch_mm() to provide core serialization
25# after changing the current mm, and deal with the special case of kthread ->
26# uthread (temporarily keeping current mm into active_mm) by issuing a
27# sync_core_before_usermode() in that specific case.
28#
29 -----------------------
30 | arch |status|
31 -----------------------
32 | alpha: | TODO |
33 | arc: | TODO |
34 | arm: | TODO |
35 | arm64: | ok |
36 | blackfin: | TODO |
37 | c6x: | TODO |
38 | cris: | TODO |
39 | frv: | TODO |
40 | h8300: | TODO |
41 | hexagon: | TODO |
42 | ia64: | TODO |
43 | m32r: | TODO |
44 | m68k: | TODO |
45 | metag: | TODO |
46 | microblaze: | TODO |
47 | mips: | TODO |
48 | mn10300: | TODO |
49 | nios2: | TODO |
50 | openrisc: | TODO |
51 | parisc: | TODO |
52 | powerpc: | TODO |
53 | s390: | TODO |
54 | score: | TODO |
55 | sh: | TODO |
56 | sparc: | TODO |
57 | tile: | TODO |
58 | um: | TODO |
59 | unicore32: | TODO |
60 | x86: | ok |
61 | xtensa: | TODO |
62 -----------------------
diff --git a/Documentation/gpu/tve200.rst b/Documentation/gpu/tve200.rst
index 69b17b324e12..152ea9398f7e 100644
--- a/Documentation/gpu/tve200.rst
+++ b/Documentation/gpu/tve200.rst
@@ -3,4 +3,4 @@
3================================== 3==================================
4 4
5.. kernel-doc:: drivers/gpu/drm/tve200/tve200_drv.c 5.. kernel-doc:: drivers/gpu/drm/tve200/tve200_drv.c
6 :doc: Faraday TV Encoder 200 6 :doc: Faraday TV Encoder TVE200 DRM Driver
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
index d47702456926..65514c251318 100644
--- a/Documentation/i2c/busses/i2c-i801
+++ b/Documentation/i2c/busses/i2c-i801
@@ -28,8 +28,10 @@ Supported adapters:
28 * Intel Wildcat Point (PCH) 28 * Intel Wildcat Point (PCH)
29 * Intel Wildcat Point-LP (PCH) 29 * Intel Wildcat Point-LP (PCH)
30 * Intel BayTrail (SOC) 30 * Intel BayTrail (SOC)
31 * Intel Braswell (SOC)
31 * Intel Sunrise Point-H (PCH) 32 * Intel Sunrise Point-H (PCH)
32 * Intel Sunrise Point-LP (PCH) 33 * Intel Sunrise Point-LP (PCH)
34 * Intel Kaby Lake-H (PCH)
33 * Intel DNV (SOC) 35 * Intel DNV (SOC)
34 * Intel Broxton (SOC) 36 * Intel Broxton (SOC)
35 * Intel Lewisburg (PCH) 37 * Intel Lewisburg (PCH)
diff --git a/Documentation/ia64/serial.txt b/Documentation/ia64/serial.txt
index 6869c73de4e2..a63d2c54329b 100644
--- a/Documentation/ia64/serial.txt
+++ b/Documentation/ia64/serial.txt
@@ -111,7 +111,7 @@ TROUBLESHOOTING SERIAL CONSOLE PROBLEMS
111 111
112 - If you don't have an HCDP, the kernel doesn't know where 112 - If you don't have an HCDP, the kernel doesn't know where
113 your console lives until the driver discovers serial 113 your console lives until the driver discovers serial
114 devices. Use "console=uart, io,0x3f8" (or appropriate 114 devices. Use "console=uart,io,0x3f8" (or appropriate
115 address for your machine). 115 address for your machine).
116 116
117 Kernel and init script output works fine, but no "login:" prompt: 117 Kernel and init script output works fine, but no "login:" prompt:
diff --git a/Documentation/locking/mutex-design.txt b/Documentation/locking/mutex-design.txt
index 60c482df1a38..818aca19612f 100644
--- a/Documentation/locking/mutex-design.txt
+++ b/Documentation/locking/mutex-design.txt
@@ -21,37 +21,23 @@ Implementation
21-------------- 21--------------
22 22
23Mutexes are represented by 'struct mutex', defined in include/linux/mutex.h 23Mutexes are represented by 'struct mutex', defined in include/linux/mutex.h
24and implemented in kernel/locking/mutex.c. These locks use a three 24and implemented in kernel/locking/mutex.c. These locks use an atomic variable
25state atomic counter (->count) to represent the different possible 25(->owner) to keep track of the lock state during its lifetime. Field owner
26transitions that can occur during the lifetime of a lock: 26actually contains 'struct task_struct *' to the current lock owner and it is
27 27therefore NULL if not currently owned. Since task_struct pointers are aligned
28 1: unlocked 28at at least L1_CACHE_BYTES, low bits (3) are used to store extra state (e.g.,
29 0: locked, no waiters 29if waiter list is non-empty). In its most basic form it also includes a
30 negative: locked, with potential waiters 30wait-queue and a spinlock that serializes access to it. Furthermore,
31 31CONFIG_MUTEX_SPIN_ON_OWNER=y systems use a spinner MCS lock (->osq), described
32In its most basic form it also includes a wait-queue and a spinlock 32below in (ii).
33that serializes access to it. CONFIG_SMP systems can also include
34a pointer to the lock task owner (->owner) as well as a spinner MCS
35lock (->osq), both described below in (ii).
36 33
37When acquiring a mutex, there are three possible paths that can be 34When acquiring a mutex, there are three possible paths that can be
38taken, depending on the state of the lock: 35taken, depending on the state of the lock:
39 36
40(i) fastpath: tries to atomically acquire the lock by decrementing the 37(i) fastpath: tries to atomically acquire the lock by cmpxchg()ing the owner with
41 counter. If it was already taken by another task it goes to the next 38 the current task. This only works in the uncontended case (cmpxchg() checks
42 possible path. This logic is architecture specific. On x86-64, the 39 against 0UL, so all 3 state bits above have to be 0). If the lock is
43 locking fastpath is 2 instructions: 40 contended it goes to the next possible path.
44
45 0000000000000e10 <mutex_lock>:
46 e21: f0 ff 0b lock decl (%rbx)
47 e24: 79 08 jns e2e <mutex_lock+0x1e>
48
49 the unlocking fastpath is equally tight:
50
51 0000000000000bc0 <mutex_unlock>:
52 bc8: f0 ff 07 lock incl (%rdi)
53 bcb: 7f 0a jg bd7 <mutex_unlock+0x17>
54
55 41
56(ii) midpath: aka optimistic spinning, tries to spin for acquisition 42(ii) midpath: aka optimistic spinning, tries to spin for acquisition
57 while the lock owner is running and there are no other tasks ready 43 while the lock owner is running and there are no other tasks ready
@@ -143,11 +129,10 @@ Test if the mutex is taken:
143Disadvantages 129Disadvantages
144------------- 130-------------
145 131
146Unlike its original design and purpose, 'struct mutex' is larger than 132Unlike its original design and purpose, 'struct mutex' is among the largest
147most locks in the kernel. E.g: on x86-64 it is 40 bytes, almost twice 133locks in the kernel. E.g: on x86-64 it is 32 bytes, where 'struct semaphore'
148as large as 'struct semaphore' (24 bytes) and tied, along with rwsems, 134is 24 bytes and rw_semaphore is 40 bytes. Larger structure sizes mean more CPU
149for the largest lock in the kernel. Larger structure sizes mean more 135cache and memory footprint.
150CPU cache and memory footprint.
151 136
152When to use mutexes 137When to use mutexes
153------------------- 138-------------------
diff --git a/Documentation/media/dmx.h.rst.exceptions b/Documentation/media/dmx.h.rst.exceptions
index 63f55a9ae2b1..a8c4239ed95b 100644
--- a/Documentation/media/dmx.h.rst.exceptions
+++ b/Documentation/media/dmx.h.rst.exceptions
@@ -50,9 +50,15 @@ replace typedef dmx_filter_t :c:type:`dmx_filter`
50replace typedef dmx_pes_type_t :c:type:`dmx_pes_type` 50replace typedef dmx_pes_type_t :c:type:`dmx_pes_type`
51replace typedef dmx_input_t :c:type:`dmx_input` 51replace typedef dmx_input_t :c:type:`dmx_input`
52 52
53ignore symbol DMX_OUT_DECODER 53replace symbol DMX_BUFFER_FLAG_HAD_CRC32_DISCARD :c:type:`dmx_buffer_flags`
54ignore symbol DMX_OUT_TAP 54replace symbol DMX_BUFFER_FLAG_TEI :c:type:`dmx_buffer_flags`
55ignore symbol DMX_OUT_TS_TAP 55replace symbol DMX_BUFFER_PKT_COUNTER_MISMATCH :c:type:`dmx_buffer_flags`
56ignore symbol DMX_OUT_TSDEMUX_TAP 56replace symbol DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED :c:type:`dmx_buffer_flags`
57replace symbol DMX_BUFFER_FLAG_DISCONTINUITY_INDICATOR :c:type:`dmx_buffer_flags`
58
59replace symbol DMX_OUT_DECODER :c:type:`dmx_output`
60replace symbol DMX_OUT_TAP :c:type:`dmx_output`
61replace symbol DMX_OUT_TS_TAP :c:type:`dmx_output`
62replace symbol DMX_OUT_TSDEMUX_TAP :c:type:`dmx_output`
57 63
58replace ioctl DMX_DQBUF dmx_qbuf 64replace ioctl DMX_DQBUF dmx_qbuf
diff --git a/Documentation/media/uapi/dvb/dmx-qbuf.rst b/Documentation/media/uapi/dvb/dmx-qbuf.rst
index b48c4931658e..be5a4c6f1904 100644
--- a/Documentation/media/uapi/dvb/dmx-qbuf.rst
+++ b/Documentation/media/uapi/dvb/dmx-qbuf.rst
@@ -51,9 +51,10 @@ out to disk. Buffers remain locked until dequeued, until the
51the device is closed. 51the device is closed.
52 52
53Applications call the ``DMX_DQBUF`` ioctl to dequeue a filled 53Applications call the ``DMX_DQBUF`` ioctl to dequeue a filled
54(capturing) buffer from the driver's outgoing queue. They just set the ``reserved`` field array to zero. When ``DMX_DQBUF`` is called with a 54(capturing) buffer from the driver's outgoing queue.
55pointer to this structure, the driver fills the remaining fields or 55They just set the ``index`` field withe the buffer ID to be queued.
56returns an error code. 56When ``DMX_DQBUF`` is called with a pointer to struct :c:type:`dmx_buffer`,
57the driver fills the remaining fields or returns an error code.
57 58
58By default ``DMX_DQBUF`` blocks when no buffer is in the outgoing 59By default ``DMX_DQBUF`` blocks when no buffer is in the outgoing
59queue. When the ``O_NONBLOCK`` flag was given to the 60queue. When the ``O_NONBLOCK`` flag was given to the
diff --git a/Documentation/networking/segmentation-offloads.txt b/Documentation/networking/segmentation-offloads.txt
index 2f09455a993a..aca542ec125c 100644
--- a/Documentation/networking/segmentation-offloads.txt
+++ b/Documentation/networking/segmentation-offloads.txt
@@ -13,14 +13,15 @@ The following technologies are described:
13 * Generic Segmentation Offload - GSO 13 * Generic Segmentation Offload - GSO
14 * Generic Receive Offload - GRO 14 * Generic Receive Offload - GRO
15 * Partial Generic Segmentation Offload - GSO_PARTIAL 15 * Partial Generic Segmentation Offload - GSO_PARTIAL
16 * SCTP accelleration with GSO - GSO_BY_FRAGS
16 17
17TCP Segmentation Offload 18TCP Segmentation Offload
18======================== 19========================
19 20
20TCP segmentation allows a device to segment a single frame into multiple 21TCP segmentation allows a device to segment a single frame into multiple
21frames with a data payload size specified in skb_shinfo()->gso_size. 22frames with a data payload size specified in skb_shinfo()->gso_size.
22When TCP segmentation requested the bit for either SKB_GSO_TCP or 23When TCP segmentation requested the bit for either SKB_GSO_TCPV4 or
23SKB_GSO_TCP6 should be set in skb_shinfo()->gso_type and 24SKB_GSO_TCPV6 should be set in skb_shinfo()->gso_type and
24skb_shinfo()->gso_size should be set to a non-zero value. 25skb_shinfo()->gso_size should be set to a non-zero value.
25 26
26TCP segmentation is dependent on support for the use of partial checksum 27TCP segmentation is dependent on support for the use of partial checksum
@@ -49,6 +50,10 @@ datagram into multiple IPv4 fragments. Many of the requirements for UDP
49fragmentation offload are the same as TSO. However the IPv4 ID for 50fragmentation offload are the same as TSO. However the IPv4 ID for
50fragments should not increment as a single IPv4 datagram is fragmented. 51fragments should not increment as a single IPv4 datagram is fragmented.
51 52
53UFO is deprecated: modern kernels will no longer generate UFO skbs, but can
54still receive them from tuntap and similar devices. Offload of UDP-based
55tunnel protocols is still supported.
56
52IPIP, SIT, GRE, UDP Tunnel, and Remote Checksum Offloads 57IPIP, SIT, GRE, UDP Tunnel, and Remote Checksum Offloads
53======================================================== 58========================================================
54 59
@@ -83,10 +88,10 @@ SKB_GSO_UDP_TUNNEL_CSUM. These two additional tunnel types reflect the
83fact that the outer header also requests to have a non-zero checksum 88fact that the outer header also requests to have a non-zero checksum
84included in the outer header. 89included in the outer header.
85 90
86Finally there is SKB_GSO_REMCSUM which indicates that a given tunnel header 91Finally there is SKB_GSO_TUNNEL_REMCSUM which indicates that a given tunnel
87has requested a remote checksum offload. In this case the inner headers 92header has requested a remote checksum offload. In this case the inner
88will be left with a partial checksum and only the outer header checksum 93headers will be left with a partial checksum and only the outer header
89will be computed. 94checksum will be computed.
90 95
91Generic Segmentation Offload 96Generic Segmentation Offload
92============================ 97============================
@@ -128,3 +133,38 @@ values for if the header was simply duplicated. The one exception to this
128is the outer IPv4 ID field. It is up to the device drivers to guarantee 133is the outer IPv4 ID field. It is up to the device drivers to guarantee
129that the IPv4 ID field is incremented in the case that a given header does 134that the IPv4 ID field is incremented in the case that a given header does
130not have the DF bit set. 135not have the DF bit set.
136
137SCTP accelleration with GSO
138===========================
139
140SCTP - despite the lack of hardware support - can still take advantage of
141GSO to pass one large packet through the network stack, rather than
142multiple small packets.
143
144This requires a different approach to other offloads, as SCTP packets
145cannot be just segmented to (P)MTU. Rather, the chunks must be contained in
146IP segments, padding respected. So unlike regular GSO, SCTP can't just
147generate a big skb, set gso_size to the fragmentation point and deliver it
148to IP layer.
149
150Instead, the SCTP protocol layer builds an skb with the segments correctly
151padded and stored as chained skbs, and skb_segment() splits based on those.
152To signal this, gso_size is set to the special value GSO_BY_FRAGS.
153
154Therefore, any code in the core networking stack must be aware of the
155possibility that gso_size will be GSO_BY_FRAGS and handle that case
156appropriately.
157
158There are some helpers to make this easier:
159
160 - skb_is_gso(skb) && skb_is_gso_sctp(skb) is the best way to see if
161 an skb is an SCTP GSO skb.
162
163 - For size checks, the skb_gso_validate_*_len family of helpers correctly
164 considers GSO_BY_FRAGS.
165
166 - For manipulating packets, skb_increase_gso_size and skb_decrease_gso_size
167 will check for GSO_BY_FRAGS and WARN if asked to manipulate these skbs.
168
169This also affects drivers with the NETIF_F_FRAGLIST & NETIF_F_GSO_SCTP bits
170set. Note also that NETIF_F_GSO_SCTP is included in NETIF_F_GSO_SOFTWARE.
diff --git a/Documentation/sphinx/kerneldoc.py b/Documentation/sphinx/kerneldoc.py
index 39aa9e8697cc..fbedcc39460b 100644
--- a/Documentation/sphinx/kerneldoc.py
+++ b/Documentation/sphinx/kerneldoc.py
@@ -36,8 +36,7 @@ import glob
36 36
37from docutils import nodes, statemachine 37from docutils import nodes, statemachine
38from docutils.statemachine import ViewList 38from docutils.statemachine import ViewList
39from docutils.parsers.rst import directives 39from docutils.parsers.rst import directives, Directive
40from sphinx.util.compat import Directive
41from sphinx.ext.autodoc import AutodocReporter 40from sphinx.ext.autodoc import AutodocReporter
42 41
43__version__ = '1.0' 42__version__ = '1.0'
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 792fa8717d13..d6b3ff51a14f 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -123,14 +123,15 @@ memory layout to fit in user mode), check KVM_CAP_MIPS_VZ and use the
123flag KVM_VM_MIPS_VZ. 123flag KVM_VM_MIPS_VZ.
124 124
125 125
1264.3 KVM_GET_MSR_INDEX_LIST 1264.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST
127 127
128Capability: basic 128Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST
129Architectures: x86 129Architectures: x86
130Type: system 130Type: system ioctl
131Parameters: struct kvm_msr_list (in/out) 131Parameters: struct kvm_msr_list (in/out)
132Returns: 0 on success; -1 on error 132Returns: 0 on success; -1 on error
133Errors: 133Errors:
134 EFAULT: the msr index list cannot be read from or written to
134 E2BIG: the msr index list is to be to fit in the array specified by 135 E2BIG: the msr index list is to be to fit in the array specified by
135 the user. 136 the user.
136 137
@@ -139,16 +140,23 @@ struct kvm_msr_list {
139 __u32 indices[0]; 140 __u32 indices[0];
140}; 141};
141 142
142This ioctl returns the guest msrs that are supported. The list varies 143The user fills in the size of the indices array in nmsrs, and in return
143by kvm version and host processor, but does not change otherwise. The 144kvm adjusts nmsrs to reflect the actual number of msrs and fills in the
144user fills in the size of the indices array in nmsrs, and in return 145indices array with their numbers.
145kvm adjusts nmsrs to reflect the actual number of msrs and fills in 146
146the indices array with their numbers. 147KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported. The list
148varies by kvm version and host processor, but does not change otherwise.
147 149
148Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are 150Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
149not returned in the MSR list, as different vcpus can have a different number 151not returned in the MSR list, as different vcpus can have a different number
150of banks, as set via the KVM_X86_SETUP_MCE ioctl. 152of banks, as set via the KVM_X86_SETUP_MCE ioctl.
151 153
154KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed
155to the KVM_GET_MSRS system ioctl. This lets userspace probe host capabilities
156and processor features that are exposed via MSRs (e.g., VMX capabilities).
157This list also varies by kvm version and host processor, but does not change
158otherwise.
159
152 160
1534.4 KVM_CHECK_EXTENSION 1614.4 KVM_CHECK_EXTENSION
154 162
@@ -475,14 +483,22 @@ Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
475 483
4764.18 KVM_GET_MSRS 4844.18 KVM_GET_MSRS
477 485
478Capability: basic 486Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system)
479Architectures: x86 487Architectures: x86
480Type: vcpu ioctl 488Type: system ioctl, vcpu ioctl
481Parameters: struct kvm_msrs (in/out) 489Parameters: struct kvm_msrs (in/out)
482Returns: 0 on success, -1 on error 490Returns: number of msrs successfully returned;
491 -1 on error
492
493When used as a system ioctl:
494Reads the values of MSR-based features that are available for the VM. This
495is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values.
496The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST
497in a system ioctl.
483 498
499When used as a vcpu ioctl:
484Reads model-specific registers from the vcpu. Supported msr indices can 500Reads model-specific registers from the vcpu. Supported msr indices can
485be obtained using KVM_GET_MSR_INDEX_LIST. 501be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl.
486 502
487struct kvm_msrs { 503struct kvm_msrs {
488 __u32 nmsrs; /* number of msrs in entries */ 504 __u32 nmsrs; /* number of msrs in entries */
diff --git a/Documentation/virtual/kvm/cpuid.txt b/Documentation/virtual/kvm/cpuid.txt
index dcab6dc11e3b..87a7506f31c2 100644
--- a/Documentation/virtual/kvm/cpuid.txt
+++ b/Documentation/virtual/kvm/cpuid.txt
@@ -58,6 +58,10 @@ KVM_FEATURE_PV_TLB_FLUSH || 9 || guest checks this feature bit
58 || || before enabling paravirtualized 58 || || before enabling paravirtualized
59 || || tlb flush. 59 || || tlb flush.
60------------------------------------------------------------------------------ 60------------------------------------------------------------------------------
61KVM_FEATURE_ASYNC_PF_VMEXIT || 10 || paravirtualized async PF VM exit
62 || || can be enabled by setting bit 2
63 || || when writing to msr 0x4b564d02
64------------------------------------------------------------------------------
61KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side 65KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side
62 || || per-cpu warps are expected in 66 || || per-cpu warps are expected in
63 || || kvmclock. 67 || || kvmclock.
diff --git a/Documentation/virtual/kvm/msr.txt b/Documentation/virtual/kvm/msr.txt
index 1ebecc115dc6..f3f0d57ced8e 100644
--- a/Documentation/virtual/kvm/msr.txt
+++ b/Documentation/virtual/kvm/msr.txt
@@ -170,7 +170,8 @@ MSR_KVM_ASYNC_PF_EN: 0x4b564d02
170 when asynchronous page faults are enabled on the vcpu 0 when 170 when asynchronous page faults are enabled on the vcpu 0 when
171 disabled. Bit 1 is 1 if asynchronous page faults can be injected 171 disabled. Bit 1 is 1 if asynchronous page faults can be injected
172 when vcpu is in cpl == 0. Bit 2 is 1 if asynchronous page faults 172 when vcpu is in cpl == 0. Bit 2 is 1 if asynchronous page faults
173 are delivered to L1 as #PF vmexits. 173 are delivered to L1 as #PF vmexits. Bit 2 can be set only if
174 KVM_FEATURE_ASYNC_PF_VMEXIT is present in CPUID.
174 175
175 First 4 byte of 64 byte memory location will be written to by 176 First 4 byte of 64 byte memory location will be written to by
176 the hypervisor at the time of asynchronous page fault (APF) 177 the hypervisor at the time of asynchronous page fault (APF)
diff --git a/Documentation/x86/intel_rdt_ui.txt b/Documentation/x86/intel_rdt_ui.txt
index 756fd76b78a6..71c30984e94d 100644
--- a/Documentation/x86/intel_rdt_ui.txt
+++ b/Documentation/x86/intel_rdt_ui.txt
@@ -671,7 +671,7 @@ occupancy of the real time threads on these cores.
671# mkdir p1 671# mkdir p1
672 672
673Move the cpus 4-7 over to p1 673Move the cpus 4-7 over to p1
674# echo f0 > p0/cpus 674# echo f0 > p1/cpus
675 675
676View the llc occupancy snapshot 676View the llc occupancy snapshot
677 677
diff --git a/Documentation/x86/topology.txt b/Documentation/x86/topology.txt
index f3e9d7e9ed6c..2953e3ec9a02 100644
--- a/Documentation/x86/topology.txt
+++ b/Documentation/x86/topology.txt
@@ -108,7 +108,7 @@ The topology of a system is described in the units of:
108 108
109 The number of online threads is also printed in /proc/cpuinfo "siblings." 109 The number of online threads is also printed in /proc/cpuinfo "siblings."
110 110
111 - topology_sibling_mask(): 111 - topology_sibling_cpumask():
112 112
113 The cpumask contains all online threads in the core to which a thread 113 The cpumask contains all online threads in the core to which a thread
114 belongs. 114 belongs.
diff --git a/MAINTAINERS b/MAINTAINERS
index dccae57985fe..004d2c14ee4b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1240,7 +1240,7 @@ F: drivers/clk/at91
1240 1240
1241ARM/ATMEL AT91RM9200, AT91SAM9 AND SAMA5 SOC SUPPORT 1241ARM/ATMEL AT91RM9200, AT91SAM9 AND SAMA5 SOC SUPPORT
1242M: Nicolas Ferre <nicolas.ferre@microchip.com> 1242M: Nicolas Ferre <nicolas.ferre@microchip.com>
1243M: Alexandre Belloni <alexandre.belloni@free-electrons.com> 1243M: Alexandre Belloni <alexandre.belloni@bootlin.com>
1244L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1244L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1245W: http://www.linux4sam.org 1245W: http://www.linux4sam.org
1246T: git git://git.kernel.org/pub/scm/linux/kernel/git/nferre/linux-at91.git 1246T: git git://git.kernel.org/pub/scm/linux/kernel/git/nferre/linux-at91.git
@@ -1592,7 +1592,7 @@ ARM/Marvell Dove/MV78xx0/Orion SOC support
1592M: Jason Cooper <jason@lakedaemon.net> 1592M: Jason Cooper <jason@lakedaemon.net>
1593M: Andrew Lunn <andrew@lunn.ch> 1593M: Andrew Lunn <andrew@lunn.ch>
1594M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> 1594M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
1595M: Gregory Clement <gregory.clement@free-electrons.com> 1595M: Gregory Clement <gregory.clement@bootlin.com>
1596L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1596L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1597S: Maintained 1597S: Maintained
1598F: Documentation/devicetree/bindings/soc/dove/ 1598F: Documentation/devicetree/bindings/soc/dove/
@@ -1606,7 +1606,7 @@ F: arch/arm/boot/dts/orion5x*
1606ARM/Marvell Kirkwood and Armada 370, 375, 38x, 39x, XP, 3700, 7K/8K SOC support 1606ARM/Marvell Kirkwood and Armada 370, 375, 38x, 39x, XP, 3700, 7K/8K SOC support
1607M: Jason Cooper <jason@lakedaemon.net> 1607M: Jason Cooper <jason@lakedaemon.net>
1608M: Andrew Lunn <andrew@lunn.ch> 1608M: Andrew Lunn <andrew@lunn.ch>
1609M: Gregory Clement <gregory.clement@free-electrons.com> 1609M: Gregory Clement <gregory.clement@bootlin.com>
1610M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> 1610M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
1611L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1611L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1612S: Maintained 1612S: Maintained
@@ -2001,8 +2001,10 @@ M: Maxime Coquelin <mcoquelin.stm32@gmail.com>
2001M: Alexandre Torgue <alexandre.torgue@st.com> 2001M: Alexandre Torgue <alexandre.torgue@st.com>
2002L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 2002L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
2003S: Maintained 2003S: Maintained
2004T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcoquelin/stm32.git 2004T: git git://git.kernel.org/pub/scm/linux/kernel/git/atorgue/stm32.git stm32-next
2005N: stm32 2005N: stm32
2006F: arch/arm/boot/dts/stm32*
2007F: arch/arm/mach-stm32/
2006F: drivers/clocksource/armv7m_systick.c 2008F: drivers/clocksource/armv7m_systick.c
2007 2009
2008ARM/TANGO ARCHITECTURE 2010ARM/TANGO ARCHITECTURE
@@ -7610,8 +7612,10 @@ F: mm/kasan/
7610F: scripts/Makefile.kasan 7612F: scripts/Makefile.kasan
7611 7613
7612KCONFIG 7614KCONFIG
7615M: Masahiro Yamada <yamada.masahiro@socionext.com>
7616T: git git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git kconfig
7613L: linux-kbuild@vger.kernel.org 7617L: linux-kbuild@vger.kernel.org
7614S: Orphan 7618S: Maintained
7615F: Documentation/kbuild/kconfig-language.txt 7619F: Documentation/kbuild/kconfig-language.txt
7616F: scripts/kconfig/ 7620F: scripts/kconfig/
7617 7621
@@ -7919,7 +7923,6 @@ S: Maintained
7919F: scripts/leaking_addresses.pl 7923F: scripts/leaking_addresses.pl
7920 7924
7921LED SUBSYSTEM 7925LED SUBSYSTEM
7922M: Richard Purdie <rpurdie@rpsys.net>
7923M: Jacek Anaszewski <jacek.anaszewski@gmail.com> 7926M: Jacek Anaszewski <jacek.anaszewski@gmail.com>
7924M: Pavel Machek <pavel@ucw.cz> 7927M: Pavel Machek <pavel@ucw.cz>
7925L: linux-leds@vger.kernel.org 7928L: linux-leds@vger.kernel.org
@@ -9216,6 +9219,7 @@ MIPS GENERIC PLATFORM
9216M: Paul Burton <paul.burton@mips.com> 9219M: Paul Burton <paul.burton@mips.com>
9217L: linux-mips@linux-mips.org 9220L: linux-mips@linux-mips.org
9218S: Supported 9221S: Supported
9222F: Documentation/devicetree/bindings/power/mti,mips-cpc.txt
9219F: arch/mips/generic/ 9223F: arch/mips/generic/
9220F: arch/mips/tools/generic-board-config.sh 9224F: arch/mips/tools/generic-board-config.sh
9221 9225
@@ -9931,6 +9935,13 @@ F: Documentation/ABI/stable/sysfs-bus-nvmem
9931F: include/linux/nvmem-consumer.h 9935F: include/linux/nvmem-consumer.h
9932F: include/linux/nvmem-provider.h 9936F: include/linux/nvmem-provider.h
9933 9937
9938NXP SGTL5000 DRIVER
9939M: Fabio Estevam <fabio.estevam@nxp.com>
9940L: alsa-devel@alsa-project.org (moderated for non-subscribers)
9941S: Maintained
9942F: Documentation/devicetree/bindings/sound/sgtl5000.txt
9943F: sound/soc/codecs/sgtl5000*
9944
9934NXP TDA998X DRM DRIVER 9945NXP TDA998X DRM DRIVER
9935M: Russell King <linux@armlinux.org.uk> 9946M: Russell King <linux@armlinux.org.uk>
9936S: Supported 9947S: Supported
@@ -9955,6 +9966,7 @@ F: drivers/nfc/nxp-nci
9955 9966
9956OBJTOOL 9967OBJTOOL
9957M: Josh Poimboeuf <jpoimboe@redhat.com> 9968M: Josh Poimboeuf <jpoimboe@redhat.com>
9969M: Peter Zijlstra <peterz@infradead.org>
9958S: Supported 9970S: Supported
9959F: tools/objtool/ 9971F: tools/objtool/
9960 9972
@@ -10332,7 +10344,7 @@ F: drivers/oprofile/
10332F: include/linux/oprofile.h 10344F: include/linux/oprofile.h
10333 10345
10334ORACLE CLUSTER FILESYSTEM 2 (OCFS2) 10346ORACLE CLUSTER FILESYSTEM 2 (OCFS2)
10335M: Mark Fasheh <mfasheh@versity.com> 10347M: Mark Fasheh <mark@fasheh.com>
10336M: Joel Becker <jlbec@evilplan.org> 10348M: Joel Becker <jlbec@evilplan.org>
10337L: ocfs2-devel@oss.oracle.com (moderated for non-subscribers) 10349L: ocfs2-devel@oss.oracle.com (moderated for non-subscribers)
10338W: http://ocfs2.wiki.kernel.org 10350W: http://ocfs2.wiki.kernel.org
@@ -10842,6 +10854,7 @@ F: drivers/platform/x86/peaq-wmi.c
10842PER-CPU MEMORY ALLOCATOR 10854PER-CPU MEMORY ALLOCATOR
10843M: Tejun Heo <tj@kernel.org> 10855M: Tejun Heo <tj@kernel.org>
10844M: Christoph Lameter <cl@linux.com> 10856M: Christoph Lameter <cl@linux.com>
10857M: Dennis Zhou <dennisszhou@gmail.com>
10845T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu.git 10858T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu.git
10846S: Maintained 10859S: Maintained
10847F: include/linux/percpu*.h 10860F: include/linux/percpu*.h
@@ -10935,6 +10948,17 @@ L: linux-gpio@vger.kernel.org
10935S: Supported 10948S: Supported
10936F: drivers/pinctrl/pinctrl-at91-pio4.* 10949F: drivers/pinctrl/pinctrl-at91-pio4.*
10937 10950
10951PIN CONTROLLER - FREESCALE
10952M: Dong Aisheng <aisheng.dong@nxp.com>
10953M: Fabio Estevam <festevam@gmail.com>
10954M: Shawn Guo <shawnguo@kernel.org>
10955M: Stefan Agner <stefan@agner.ch>
10956R: Pengutronix Kernel Team <kernel@pengutronix.de>
10957L: linux-gpio@vger.kernel.org
10958S: Maintained
10959F: drivers/pinctrl/freescale/
10960F: Documentation/devicetree/bindings/pinctrl/fsl,*
10961
10938PIN CONTROLLER - INTEL 10962PIN CONTROLLER - INTEL
10939M: Mika Westerberg <mika.westerberg@linux.intel.com> 10963M: Mika Westerberg <mika.westerberg@linux.intel.com>
10940M: Heikki Krogerus <heikki.krogerus@linux.intel.com> 10964M: Heikki Krogerus <heikki.krogerus@linux.intel.com>
@@ -12101,6 +12125,7 @@ M: Sylwester Nawrocki <s.nawrocki@samsung.com>
12101L: alsa-devel@alsa-project.org (moderated for non-subscribers) 12125L: alsa-devel@alsa-project.org (moderated for non-subscribers)
12102S: Supported 12126S: Supported
12103F: sound/soc/samsung/ 12127F: sound/soc/samsung/
12128F: Documentation/devicetree/bindings/sound/samsung*
12104 12129
12105SAMSUNG EXYNOS PSEUDO RANDOM NUMBER GENERATOR (RNG) DRIVER 12130SAMSUNG EXYNOS PSEUDO RANDOM NUMBER GENERATOR (RNG) DRIVER
12106M: Krzysztof Kozlowski <krzk@kernel.org> 12131M: Krzysztof Kozlowski <krzk@kernel.org>
diff --git a/Makefile b/Makefile
index 79ad2bfa24b6..7ba478ab8c82 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
2VERSION = 4 2VERSION = 4
3PATCHLEVEL = 16 3PATCHLEVEL = 16
4SUBLEVEL = 0 4SUBLEVEL = 0
5EXTRAVERSION = -rc1 5EXTRAVERSION = -rc7
6NAME = Fearless Coyote 6NAME = Fearless Coyote
7 7
8# *DOCUMENTATION* 8# *DOCUMENTATION*
@@ -388,7 +388,7 @@ PYTHON = python
388CHECK = sparse 388CHECK = sparse
389 389
390CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ 390CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
391 -Wbitwise -Wno-return-void $(CF) 391 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
392NOSTDINC_FLAGS = 392NOSTDINC_FLAGS =
393CFLAGS_MODULE = 393CFLAGS_MODULE =
394AFLAGS_MODULE = 394AFLAGS_MODULE =
@@ -489,6 +489,11 @@ KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
489KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) 489KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
490endif 490endif
491 491
492RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
493RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
494RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
495export RETPOLINE_CFLAGS
496
492ifeq ($(config-targets),1) 497ifeq ($(config-targets),1)
493# =========================================================================== 498# ===========================================================================
494# *config targets only - make sure prerequisites are updated, and descend 499# *config targets only - make sure prerequisites are updated, and descend
@@ -579,10 +584,9 @@ ifeq ($(KBUILD_EXTMOD),)
579# To avoid any implicit rule to kick in, define an empty command 584# To avoid any implicit rule to kick in, define an empty command
580$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ; 585$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
581 586
582# If .config is newer than include/config/auto.conf, someone tinkered 587# The actual configuration files used during the build are stored in
583# with it and forgot to run make oldconfig. 588# include/generated/ and include/config/. Update them if .config is newer than
584# if auto.conf.cmd is missing then we are probably in a cleaned tree so 589# include/config/auto.conf (which mirrors .config).
585# we execute the config step to be sure to catch updated Kconfig files
586include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd 590include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
587 $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig 591 $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
588else 592else
@@ -822,6 +826,15 @@ KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign)
822# disable invalid "can't wrap" optimizations for signed / pointers 826# disable invalid "can't wrap" optimizations for signed / pointers
823KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow) 827KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
824 828
829# clang sets -fmerge-all-constants by default as optimization, but this
830# is non-conforming behavior for C and in fact breaks the kernel, so we
831# need to disable it here generally.
832KBUILD_CFLAGS += $(call cc-option,-fno-merge-all-constants)
833
834# for gcc -fno-merge-all-constants disables everything, but it is fine
835# to have actual conforming behavior enabled.
836KBUILD_CFLAGS += $(call cc-option,-fmerge-constants)
837
825# Make sure -fstack-check isn't enabled (like gentoo apparently did) 838# Make sure -fstack-check isn't enabled (like gentoo apparently did)
826KBUILD_CFLAGS += $(call cc-option,-fno-stack-check,) 839KBUILD_CFLAGS += $(call cc-option,-fno-stack-check,)
827 840
@@ -857,8 +870,7 @@ KBUILD_AFLAGS += $(ARCH_AFLAGS) $(KAFLAGS)
857KBUILD_CFLAGS += $(ARCH_CFLAGS) $(KCFLAGS) 870KBUILD_CFLAGS += $(ARCH_CFLAGS) $(KCFLAGS)
858 871
859# Use --build-id when available. 872# Use --build-id when available.
860LDFLAGS_BUILD_ID := $(patsubst -Wl$(comma)%,%,\ 873LDFLAGS_BUILD_ID := $(call ld-option, --build-id)
861 $(call cc-ldoption, -Wl$(comma)--build-id,))
862KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID) 874KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
863LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID) 875LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
864 876
diff --git a/arch/alpha/include/asm/cmpxchg.h b/arch/alpha/include/asm/cmpxchg.h
index 46ebf14aed4e..8a2b331e43fe 100644
--- a/arch/alpha/include/asm/cmpxchg.h
+++ b/arch/alpha/include/asm/cmpxchg.h
@@ -6,7 +6,6 @@
6 * Atomic exchange routines. 6 * Atomic exchange routines.
7 */ 7 */
8 8
9#define __ASM__MB
10#define ____xchg(type, args...) __xchg ## type ## _local(args) 9#define ____xchg(type, args...) __xchg ## type ## _local(args)
11#define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args) 10#define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args)
12#include <asm/xchg.h> 11#include <asm/xchg.h>
@@ -33,10 +32,6 @@
33 cmpxchg_local((ptr), (o), (n)); \ 32 cmpxchg_local((ptr), (o), (n)); \
34}) 33})
35 34
36#ifdef CONFIG_SMP
37#undef __ASM__MB
38#define __ASM__MB "\tmb\n"
39#endif
40#undef ____xchg 35#undef ____xchg
41#undef ____cmpxchg 36#undef ____cmpxchg
42#define ____xchg(type, args...) __xchg ##type(args) 37#define ____xchg(type, args...) __xchg ##type(args)
@@ -64,7 +59,6 @@
64 cmpxchg((ptr), (o), (n)); \ 59 cmpxchg((ptr), (o), (n)); \
65}) 60})
66 61
67#undef __ASM__MB
68#undef ____cmpxchg 62#undef ____cmpxchg
69 63
70#endif /* _ALPHA_CMPXCHG_H */ 64#endif /* _ALPHA_CMPXCHG_H */
diff --git a/arch/alpha/include/asm/xchg.h b/arch/alpha/include/asm/xchg.h
index 68dfb3cb7145..e2b59fac5257 100644
--- a/arch/alpha/include/asm/xchg.h
+++ b/arch/alpha/include/asm/xchg.h
@@ -12,6 +12,10 @@
12 * Atomic exchange. 12 * Atomic exchange.
13 * Since it can be used to implement critical sections 13 * Since it can be used to implement critical sections
14 * it must clobber "memory" (also for interrupts in UP). 14 * it must clobber "memory" (also for interrupts in UP).
15 *
16 * The leading and the trailing memory barriers guarantee that these
17 * operations are fully ordered.
18 *
15 */ 19 */
16 20
17static inline unsigned long 21static inline unsigned long
@@ -19,6 +23,7 @@ ____xchg(_u8, volatile char *m, unsigned long val)
19{ 23{
20 unsigned long ret, tmp, addr64; 24 unsigned long ret, tmp, addr64;
21 25
26 smp_mb();
22 __asm__ __volatile__( 27 __asm__ __volatile__(
23 " andnot %4,7,%3\n" 28 " andnot %4,7,%3\n"
24 " insbl %1,%4,%1\n" 29 " insbl %1,%4,%1\n"
@@ -28,12 +33,12 @@ ____xchg(_u8, volatile char *m, unsigned long val)
28 " or %1,%2,%2\n" 33 " or %1,%2,%2\n"
29 " stq_c %2,0(%3)\n" 34 " stq_c %2,0(%3)\n"
30 " beq %2,2f\n" 35 " beq %2,2f\n"
31 __ASM__MB
32 ".subsection 2\n" 36 ".subsection 2\n"
33 "2: br 1b\n" 37 "2: br 1b\n"
34 ".previous" 38 ".previous"
35 : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64) 39 : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64)
36 : "r" ((long)m), "1" (val) : "memory"); 40 : "r" ((long)m), "1" (val) : "memory");
41 smp_mb();
37 42
38 return ret; 43 return ret;
39} 44}
@@ -43,6 +48,7 @@ ____xchg(_u16, volatile short *m, unsigned long val)
43{ 48{
44 unsigned long ret, tmp, addr64; 49 unsigned long ret, tmp, addr64;
45 50
51 smp_mb();
46 __asm__ __volatile__( 52 __asm__ __volatile__(
47 " andnot %4,7,%3\n" 53 " andnot %4,7,%3\n"
48 " inswl %1,%4,%1\n" 54 " inswl %1,%4,%1\n"
@@ -52,12 +58,12 @@ ____xchg(_u16, volatile short *m, unsigned long val)
52 " or %1,%2,%2\n" 58 " or %1,%2,%2\n"
53 " stq_c %2,0(%3)\n" 59 " stq_c %2,0(%3)\n"
54 " beq %2,2f\n" 60 " beq %2,2f\n"
55 __ASM__MB
56 ".subsection 2\n" 61 ".subsection 2\n"
57 "2: br 1b\n" 62 "2: br 1b\n"
58 ".previous" 63 ".previous"
59 : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64) 64 : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64)
60 : "r" ((long)m), "1" (val) : "memory"); 65 : "r" ((long)m), "1" (val) : "memory");
66 smp_mb();
61 67
62 return ret; 68 return ret;
63} 69}
@@ -67,17 +73,18 @@ ____xchg(_u32, volatile int *m, unsigned long val)
67{ 73{
68 unsigned long dummy; 74 unsigned long dummy;
69 75
76 smp_mb();
70 __asm__ __volatile__( 77 __asm__ __volatile__(
71 "1: ldl_l %0,%4\n" 78 "1: ldl_l %0,%4\n"
72 " bis $31,%3,%1\n" 79 " bis $31,%3,%1\n"
73 " stl_c %1,%2\n" 80 " stl_c %1,%2\n"
74 " beq %1,2f\n" 81 " beq %1,2f\n"
75 __ASM__MB
76 ".subsection 2\n" 82 ".subsection 2\n"
77 "2: br 1b\n" 83 "2: br 1b\n"
78 ".previous" 84 ".previous"
79 : "=&r" (val), "=&r" (dummy), "=m" (*m) 85 : "=&r" (val), "=&r" (dummy), "=m" (*m)
80 : "rI" (val), "m" (*m) : "memory"); 86 : "rI" (val), "m" (*m) : "memory");
87 smp_mb();
81 88
82 return val; 89 return val;
83} 90}
@@ -87,17 +94,18 @@ ____xchg(_u64, volatile long *m, unsigned long val)
87{ 94{
88 unsigned long dummy; 95 unsigned long dummy;
89 96
97 smp_mb();
90 __asm__ __volatile__( 98 __asm__ __volatile__(
91 "1: ldq_l %0,%4\n" 99 "1: ldq_l %0,%4\n"
92 " bis $31,%3,%1\n" 100 " bis $31,%3,%1\n"
93 " stq_c %1,%2\n" 101 " stq_c %1,%2\n"
94 " beq %1,2f\n" 102 " beq %1,2f\n"
95 __ASM__MB
96 ".subsection 2\n" 103 ".subsection 2\n"
97 "2: br 1b\n" 104 "2: br 1b\n"
98 ".previous" 105 ".previous"
99 : "=&r" (val), "=&r" (dummy), "=m" (*m) 106 : "=&r" (val), "=&r" (dummy), "=m" (*m)
100 : "rI" (val), "m" (*m) : "memory"); 107 : "rI" (val), "m" (*m) : "memory");
108 smp_mb();
101 109
102 return val; 110 return val;
103} 111}
@@ -128,10 +136,12 @@ ____xchg(, volatile void *ptr, unsigned long x, int size)
128 * store NEW in MEM. Return the initial value in MEM. Success is 136 * store NEW in MEM. Return the initial value in MEM. Success is
129 * indicated by comparing RETURN with OLD. 137 * indicated by comparing RETURN with OLD.
130 * 138 *
131 * The memory barrier should be placed in SMP only when we actually 139 * The leading and the trailing memory barriers guarantee that these
132 * make the change. If we don't change anything (so if the returned 140 * operations are fully ordered.
133 * prev is equal to old) then we aren't acquiring anything new and 141 *
134 * we don't need any memory barrier as far I can tell. 142 * The trailing memory barrier is placed in SMP unconditionally, in
143 * order to guarantee that dependency ordering is preserved when a
144 * dependency is headed by an unsuccessful operation.
135 */ 145 */
136 146
137static inline unsigned long 147static inline unsigned long
@@ -139,6 +149,7 @@ ____cmpxchg(_u8, volatile char *m, unsigned char old, unsigned char new)
139{ 149{
140 unsigned long prev, tmp, cmp, addr64; 150 unsigned long prev, tmp, cmp, addr64;
141 151
152 smp_mb();
142 __asm__ __volatile__( 153 __asm__ __volatile__(
143 " andnot %5,7,%4\n" 154 " andnot %5,7,%4\n"
144 " insbl %1,%5,%1\n" 155 " insbl %1,%5,%1\n"
@@ -150,13 +161,13 @@ ____cmpxchg(_u8, volatile char *m, unsigned char old, unsigned char new)
150 " or %1,%2,%2\n" 161 " or %1,%2,%2\n"
151 " stq_c %2,0(%4)\n" 162 " stq_c %2,0(%4)\n"
152 " beq %2,3f\n" 163 " beq %2,3f\n"
153 __ASM__MB
154 "2:\n" 164 "2:\n"
155 ".subsection 2\n" 165 ".subsection 2\n"
156 "3: br 1b\n" 166 "3: br 1b\n"
157 ".previous" 167 ".previous"
158 : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64) 168 : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64)
159 : "r" ((long)m), "Ir" (old), "1" (new) : "memory"); 169 : "r" ((long)m), "Ir" (old), "1" (new) : "memory");
170 smp_mb();
160 171
161 return prev; 172 return prev;
162} 173}
@@ -166,6 +177,7 @@ ____cmpxchg(_u16, volatile short *m, unsigned short old, unsigned short new)
166{ 177{
167 unsigned long prev, tmp, cmp, addr64; 178 unsigned long prev, tmp, cmp, addr64;
168 179
180 smp_mb();
169 __asm__ __volatile__( 181 __asm__ __volatile__(
170 " andnot %5,7,%4\n" 182 " andnot %5,7,%4\n"
171 " inswl %1,%5,%1\n" 183 " inswl %1,%5,%1\n"
@@ -177,13 +189,13 @@ ____cmpxchg(_u16, volatile short *m, unsigned short old, unsigned short new)
177 " or %1,%2,%2\n" 189 " or %1,%2,%2\n"
178 " stq_c %2,0(%4)\n" 190 " stq_c %2,0(%4)\n"
179 " beq %2,3f\n" 191 " beq %2,3f\n"
180 __ASM__MB
181 "2:\n" 192 "2:\n"
182 ".subsection 2\n" 193 ".subsection 2\n"
183 "3: br 1b\n" 194 "3: br 1b\n"
184 ".previous" 195 ".previous"
185 : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64) 196 : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64)
186 : "r" ((long)m), "Ir" (old), "1" (new) : "memory"); 197 : "r" ((long)m), "Ir" (old), "1" (new) : "memory");
198 smp_mb();
187 199
188 return prev; 200 return prev;
189} 201}
@@ -193,6 +205,7 @@ ____cmpxchg(_u32, volatile int *m, int old, int new)
193{ 205{
194 unsigned long prev, cmp; 206 unsigned long prev, cmp;
195 207
208 smp_mb();
196 __asm__ __volatile__( 209 __asm__ __volatile__(
197 "1: ldl_l %0,%5\n" 210 "1: ldl_l %0,%5\n"
198 " cmpeq %0,%3,%1\n" 211 " cmpeq %0,%3,%1\n"
@@ -200,13 +213,13 @@ ____cmpxchg(_u32, volatile int *m, int old, int new)
200 " mov %4,%1\n" 213 " mov %4,%1\n"
201 " stl_c %1,%2\n" 214 " stl_c %1,%2\n"
202 " beq %1,3f\n" 215 " beq %1,3f\n"
203 __ASM__MB
204 "2:\n" 216 "2:\n"
205 ".subsection 2\n" 217 ".subsection 2\n"
206 "3: br 1b\n" 218 "3: br 1b\n"
207 ".previous" 219 ".previous"
208 : "=&r"(prev), "=&r"(cmp), "=m"(*m) 220 : "=&r"(prev), "=&r"(cmp), "=m"(*m)
209 : "r"((long) old), "r"(new), "m"(*m) : "memory"); 221 : "r"((long) old), "r"(new), "m"(*m) : "memory");
222 smp_mb();
210 223
211 return prev; 224 return prev;
212} 225}
@@ -216,6 +229,7 @@ ____cmpxchg(_u64, volatile long *m, unsigned long old, unsigned long new)
216{ 229{
217 unsigned long prev, cmp; 230 unsigned long prev, cmp;
218 231
232 smp_mb();
219 __asm__ __volatile__( 233 __asm__ __volatile__(
220 "1: ldq_l %0,%5\n" 234 "1: ldq_l %0,%5\n"
221 " cmpeq %0,%3,%1\n" 235 " cmpeq %0,%3,%1\n"
@@ -223,13 +237,13 @@ ____cmpxchg(_u64, volatile long *m, unsigned long old, unsigned long new)
223 " mov %4,%1\n" 237 " mov %4,%1\n"
224 " stq_c %1,%2\n" 238 " stq_c %1,%2\n"
225 " beq %1,3f\n" 239 " beq %1,3f\n"
226 __ASM__MB
227 "2:\n" 240 "2:\n"
228 ".subsection 2\n" 241 ".subsection 2\n"
229 "3: br 1b\n" 242 "3: br 1b\n"
230 ".previous" 243 ".previous"
231 : "=&r"(prev), "=&r"(cmp), "=m"(*m) 244 : "=&r"(prev), "=&r"(cmp), "=m"(*m)
232 : "r"((long) old), "r"(new), "m"(*m) : "memory"); 245 : "r"((long) old), "r"(new), "m"(*m) : "memory");
246 smp_mb();
233 247
234 return prev; 248 return prev;
235} 249}
diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index f3a80cf164cc..d76bf4a83740 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -484,7 +484,6 @@ config ARC_CURR_IN_REG
484 484
485config ARC_EMUL_UNALIGNED 485config ARC_EMUL_UNALIGNED
486 bool "Emulate unaligned memory access (userspace only)" 486 bool "Emulate unaligned memory access (userspace only)"
487 default N
488 select SYSCTL_ARCH_UNALIGN_NO_WARN 487 select SYSCTL_ARCH_UNALIGN_NO_WARN
489 select SYSCTL_ARCH_UNALIGN_ALLOW 488 select SYSCTL_ARCH_UNALIGN_ALLOW
490 depends on ISA_ARCOMPACT 489 depends on ISA_ARCOMPACT
diff --git a/arch/arc/boot/dts/axs101.dts b/arch/arc/boot/dts/axs101.dts
index 70aec7d6ca60..626b694c7be7 100644
--- a/arch/arc/boot/dts/axs101.dts
+++ b/arch/arc/boot/dts/axs101.dts
@@ -17,6 +17,6 @@
17 compatible = "snps,axs101", "snps,arc-sdp"; 17 compatible = "snps,axs101", "snps,arc-sdp";
18 18
19 chosen { 19 chosen {
20 bootargs = "earlycon=uart8250,mmio32,0xe0022000,115200n8 console=tty0 console=ttyS3,115200n8 consoleblank=0 video=1280x720@60"; 20 bootargs = "earlycon=uart8250,mmio32,0xe0022000,115200n8 console=tty0 console=ttyS3,115200n8 consoleblank=0 video=1280x720@60 print-fatal-signals=1";
21 }; 21 };
22}; 22};
diff --git a/arch/arc/boot/dts/axs10x_mb.dtsi b/arch/arc/boot/dts/axs10x_mb.dtsi
index 74d070cd3c13..47b74fbc403c 100644
--- a/arch/arc/boot/dts/axs10x_mb.dtsi
+++ b/arch/arc/boot/dts/axs10x_mb.dtsi
@@ -214,13 +214,13 @@
214 }; 214 };
215 215
216 eeprom@0x54{ 216 eeprom@0x54{
217 compatible = "24c01"; 217 compatible = "atmel,24c01";
218 reg = <0x54>; 218 reg = <0x54>;
219 pagesize = <0x8>; 219 pagesize = <0x8>;
220 }; 220 };
221 221
222 eeprom@0x57{ 222 eeprom@0x57{
223 compatible = "24c04"; 223 compatible = "atmel,24c04";
224 reg = <0x57>; 224 reg = <0x57>;
225 pagesize = <0x8>; 225 pagesize = <0x8>;
226 }; 226 };
diff --git a/arch/arc/boot/dts/haps_hs_idu.dts b/arch/arc/boot/dts/haps_hs_idu.dts
index 215cddd0b63b..0c603308aeb3 100644
--- a/arch/arc/boot/dts/haps_hs_idu.dts
+++ b/arch/arc/boot/dts/haps_hs_idu.dts
@@ -22,7 +22,7 @@
22 }; 22 };
23 23
24 chosen { 24 chosen {
25 bootargs = "earlycon=uart8250,mmio32,0xf0000000,115200n8 console=ttyS0,115200n8 debug"; 25 bootargs = "earlycon=uart8250,mmio32,0xf0000000,115200n8 console=ttyS0,115200n8 debug print-fatal-signals=1";
26 }; 26 };
27 27
28 aliases { 28 aliases {
diff --git a/arch/arc/boot/dts/nsim_700.dts b/arch/arc/boot/dts/nsim_700.dts
index 5ee96b067c08..ff2f2c70c545 100644
--- a/arch/arc/boot/dts/nsim_700.dts
+++ b/arch/arc/boot/dts/nsim_700.dts
@@ -17,7 +17,7 @@
17 interrupt-parent = <&core_intc>; 17 interrupt-parent = <&core_intc>;
18 18
19 chosen { 19 chosen {
20 bootargs = "earlycon=arc_uart,mmio32,0xc0fc1000,115200n8 console=ttyARC0,115200n8"; 20 bootargs = "earlycon=arc_uart,mmio32,0xc0fc1000,115200n8 console=ttyARC0,115200n8 print-fatal-signals=1";
21 }; 21 };
22 22
23 aliases { 23 aliases {
diff --git a/arch/arc/boot/dts/nsim_hs.dts b/arch/arc/boot/dts/nsim_hs.dts
index 8d787b251f73..8e2489b16b0a 100644
--- a/arch/arc/boot/dts/nsim_hs.dts
+++ b/arch/arc/boot/dts/nsim_hs.dts
@@ -24,7 +24,7 @@
24 }; 24 };
25 25
26 chosen { 26 chosen {
27 bootargs = "earlycon=arc_uart,mmio32,0xc0fc1000,115200n8 console=ttyARC0,115200n8"; 27 bootargs = "earlycon=arc_uart,mmio32,0xc0fc1000,115200n8 console=ttyARC0,115200n8 print-fatal-signals=1";
28 }; 28 };
29 29
30 aliases { 30 aliases {
diff --git a/arch/arc/boot/dts/nsim_hs_idu.dts b/arch/arc/boot/dts/nsim_hs_idu.dts
index 4f98ebf71fd8..ed12f494721d 100644
--- a/arch/arc/boot/dts/nsim_hs_idu.dts
+++ b/arch/arc/boot/dts/nsim_hs_idu.dts
@@ -15,7 +15,7 @@
15 interrupt-parent = <&core_intc>; 15 interrupt-parent = <&core_intc>;
16 16
17 chosen { 17 chosen {
18 bootargs = "earlycon=arc_uart,mmio32,0xc0fc1000,115200n8 console=ttyARC0,115200n8"; 18 bootargs = "earlycon=arc_uart,mmio32,0xc0fc1000,115200n8 console=ttyARC0,115200n8 print-fatal-signals=1";
19 }; 19 };
20 20
21 aliases { 21 aliases {
diff --git a/arch/arc/boot/dts/nsimosci.dts b/arch/arc/boot/dts/nsimosci.dts
index 3c391ba565ed..7842e5eb4ab5 100644
--- a/arch/arc/boot/dts/nsimosci.dts
+++ b/arch/arc/boot/dts/nsimosci.dts
@@ -20,7 +20,7 @@
20 /* this is for console on PGU */ 20 /* this is for console on PGU */
21 /* bootargs = "console=tty0 consoleblank=0"; */ 21 /* bootargs = "console=tty0 consoleblank=0"; */
22 /* this is for console on serial */ 22 /* this is for console on serial */
23 bootargs = "earlycon=uart8250,mmio32,0xf0000000,115200n8 console=tty0 console=ttyS0,115200n8 consoleblank=0 debug video=640x480-24"; 23 bootargs = "earlycon=uart8250,mmio32,0xf0000000,115200n8 console=tty0 console=ttyS0,115200n8 consoleblank=0 debug video=640x480-24 print-fatal-signals=1";
24 }; 24 };
25 25
26 aliases { 26 aliases {
diff --git a/arch/arc/boot/dts/nsimosci_hs.dts b/arch/arc/boot/dts/nsimosci_hs.dts
index 14a727cbf4c9..b8838cf2b4ec 100644
--- a/arch/arc/boot/dts/nsimosci_hs.dts
+++ b/arch/arc/boot/dts/nsimosci_hs.dts
@@ -20,7 +20,7 @@
20 /* this is for console on PGU */ 20 /* this is for console on PGU */
21 /* bootargs = "console=tty0 consoleblank=0"; */ 21 /* bootargs = "console=tty0 consoleblank=0"; */
22 /* this is for console on serial */ 22 /* this is for console on serial */
23 bootargs = "earlycon=uart8250,mmio32,0xf0000000,115200n8 console=tty0 console=ttyS0,115200n8 consoleblank=0 debug video=640x480-24"; 23 bootargs = "earlycon=uart8250,mmio32,0xf0000000,115200n8 console=tty0 console=ttyS0,115200n8 consoleblank=0 debug video=640x480-24 print-fatal-signals=1";
24 }; 24 };
25 25
26 aliases { 26 aliases {
diff --git a/arch/arc/boot/dts/nsimosci_hs_idu.dts b/arch/arc/boot/dts/nsimosci_hs_idu.dts
index 5052917d4a99..72a2c723f1f7 100644
--- a/arch/arc/boot/dts/nsimosci_hs_idu.dts
+++ b/arch/arc/boot/dts/nsimosci_hs_idu.dts
@@ -18,7 +18,7 @@
18 18
19 chosen { 19 chosen {
20 /* this is for console on serial */ 20 /* this is for console on serial */
21 bootargs = "earlycon=uart8250,mmio32,0xf0000000,115200n8 console=tty0 console=ttyS0,115200n8 consoleblan=0 debug video=640x480-24"; 21 bootargs = "earlycon=uart8250,mmio32,0xf0000000,115200n8 console=tty0 console=ttyS0,115200n8 consoleblan=0 debug video=640x480-24 print-fatal-signals=1";
22 }; 22 };
23 23
24 aliases { 24 aliases {
diff --git a/arch/arc/include/asm/bug.h b/arch/arc/include/asm/bug.h
index ea022d47896c..21ec82466d62 100644
--- a/arch/arc/include/asm/bug.h
+++ b/arch/arc/include/asm/bug.h
@@ -23,7 +23,8 @@ void die(const char *str, struct pt_regs *regs, unsigned long address);
23 23
24#define BUG() do { \ 24#define BUG() do { \
25 pr_warn("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ 25 pr_warn("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
26 dump_stack(); \ 26 barrier_before_unreachable(); \
27 __builtin_trap(); \
27} while (0) 28} while (0)
28 29
29#define HAVE_ARCH_BUG 30#define HAVE_ARCH_BUG
diff --git a/arch/arc/include/asm/entry-arcv2.h b/arch/arc/include/asm/entry-arcv2.h
index 257a68f3c2fe..309f4e6721b3 100644
--- a/arch/arc/include/asm/entry-arcv2.h
+++ b/arch/arc/include/asm/entry-arcv2.h
@@ -184,7 +184,7 @@
184.macro FAKE_RET_FROM_EXCPN 184.macro FAKE_RET_FROM_EXCPN
185 lr r9, [status32] 185 lr r9, [status32]
186 bic r9, r9, (STATUS_U_MASK|STATUS_DE_MASK|STATUS_AE_MASK) 186 bic r9, r9, (STATUS_U_MASK|STATUS_DE_MASK|STATUS_AE_MASK)
187 or r9, r9, (STATUS_L_MASK|STATUS_IE_MASK) 187 or r9, r9, STATUS_IE_MASK
188 kflag r9 188 kflag r9
189.endm 189.endm
190 190
diff --git a/arch/arc/kernel/mcip.c b/arch/arc/kernel/mcip.c
index f61a52b01625..5fe84e481654 100644
--- a/arch/arc/kernel/mcip.c
+++ b/arch/arc/kernel/mcip.c
@@ -22,10 +22,79 @@ static DEFINE_RAW_SPINLOCK(mcip_lock);
22 22
23static char smp_cpuinfo_buf[128]; 23static char smp_cpuinfo_buf[128];
24 24
25/*
26 * Set mask to halt GFRC if any online core in SMP cluster is halted.
27 * Only works for ARC HS v3.0+, on earlier versions has no effect.
28 */
29static void mcip_update_gfrc_halt_mask(int cpu)
30{
31 struct bcr_generic gfrc;
32 unsigned long flags;
33 u32 gfrc_halt_mask;
34
35 READ_BCR(ARC_REG_GFRC_BUILD, gfrc);
36
37 /*
38 * CMD_GFRC_SET_CORE and CMD_GFRC_READ_CORE commands were added in
39 * GFRC 0x3 version.
40 */
41 if (gfrc.ver < 0x3)
42 return;
43
44 raw_spin_lock_irqsave(&mcip_lock, flags);
45
46 __mcip_cmd(CMD_GFRC_READ_CORE, 0);
47 gfrc_halt_mask = read_aux_reg(ARC_REG_MCIP_READBACK);
48 gfrc_halt_mask |= BIT(cpu);
49 __mcip_cmd_data(CMD_GFRC_SET_CORE, 0, gfrc_halt_mask);
50
51 raw_spin_unlock_irqrestore(&mcip_lock, flags);
52}
53
54static void mcip_update_debug_halt_mask(int cpu)
55{
56 u32 mcip_mask = 0;
57 unsigned long flags;
58
59 raw_spin_lock_irqsave(&mcip_lock, flags);
60
61 /*
62 * mcip_mask is same for CMD_DEBUG_SET_SELECT and CMD_DEBUG_SET_MASK
63 * commands. So read it once instead of reading both CMD_DEBUG_READ_MASK
64 * and CMD_DEBUG_READ_SELECT.
65 */
66 __mcip_cmd(CMD_DEBUG_READ_SELECT, 0);
67 mcip_mask = read_aux_reg(ARC_REG_MCIP_READBACK);
68
69 mcip_mask |= BIT(cpu);
70
71 __mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, mcip_mask);
72 /*
73 * Parameter specified halt cause:
74 * STATUS32[H]/actionpoint/breakpoint/self-halt
75 * We choose all of them (0xF).
76 */
77 __mcip_cmd_data(CMD_DEBUG_SET_MASK, 0xF, mcip_mask);
78
79 raw_spin_unlock_irqrestore(&mcip_lock, flags);
80}
81
25static void mcip_setup_per_cpu(int cpu) 82static void mcip_setup_per_cpu(int cpu)
26{ 83{
84 struct mcip_bcr mp;
85
86 READ_BCR(ARC_REG_MCIP_BCR, mp);
87
27 smp_ipi_irq_setup(cpu, IPI_IRQ); 88 smp_ipi_irq_setup(cpu, IPI_IRQ);
28 smp_ipi_irq_setup(cpu, SOFTIRQ_IRQ); 89 smp_ipi_irq_setup(cpu, SOFTIRQ_IRQ);
90
91 /* Update GFRC halt mask as new CPU came online */
92 if (mp.gfrc)
93 mcip_update_gfrc_halt_mask(cpu);
94
95 /* Update MCIP debug mask as new CPU came online */
96 if (mp.dbg)
97 mcip_update_debug_halt_mask(cpu);
29} 98}
30 99
31static void mcip_ipi_send(int cpu) 100static void mcip_ipi_send(int cpu)
@@ -101,11 +170,6 @@ static void mcip_probe_n_setup(void)
101 IS_AVAIL1(mp.gfrc, "GFRC")); 170 IS_AVAIL1(mp.gfrc, "GFRC"));
102 171
103 cpuinfo_arc700[0].extn.gfrc = mp.gfrc; 172 cpuinfo_arc700[0].extn.gfrc = mp.gfrc;
104
105 if (mp.dbg) {
106 __mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, 0xf);
107 __mcip_cmd_data(CMD_DEBUG_SET_MASK, 0xf, 0xf);
108 }
109} 173}
110 174
111struct plat_smp_ops plat_smp_ops = { 175struct plat_smp_ops plat_smp_ops = {
diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c
index 9d27331fe69a..b2cae79a25d7 100644
--- a/arch/arc/kernel/setup.c
+++ b/arch/arc/kernel/setup.c
@@ -51,7 +51,7 @@ static const struct id_to_str arc_cpu_rel[] = {
51 { 0x51, "R2.0" }, 51 { 0x51, "R2.0" },
52 { 0x52, "R2.1" }, 52 { 0x52, "R2.1" },
53 { 0x53, "R3.0" }, 53 { 0x53, "R3.0" },
54 { 0x54, "R4.0" }, 54 { 0x54, "R3.10a" },
55#endif 55#endif
56 { 0x00, NULL } 56 { 0x00, NULL }
57}; 57};
@@ -373,7 +373,7 @@ static void arc_chk_core_config(void)
373{ 373{
374 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()]; 374 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
375 int saved = 0, present = 0; 375 int saved = 0, present = 0;
376 char *opt_nm = NULL;; 376 char *opt_nm = NULL;
377 377
378 if (!cpu->extn.timer0) 378 if (!cpu->extn.timer0)
379 panic("Timer0 is not present!\n"); 379 panic("Timer0 is not present!\n");
diff --git a/arch/arc/kernel/smp.c b/arch/arc/kernel/smp.c
index efe8b4200a67..21d86c36692b 100644
--- a/arch/arc/kernel/smp.c
+++ b/arch/arc/kernel/smp.c
@@ -24,6 +24,7 @@
24#include <linux/reboot.h> 24#include <linux/reboot.h>
25#include <linux/irqdomain.h> 25#include <linux/irqdomain.h>
26#include <linux/export.h> 26#include <linux/export.h>
27#include <linux/of_fdt.h>
27 28
28#include <asm/processor.h> 29#include <asm/processor.h>
29#include <asm/setup.h> 30#include <asm/setup.h>
@@ -47,6 +48,42 @@ void __init smp_prepare_boot_cpu(void)
47{ 48{
48} 49}
49 50
51static int __init arc_get_cpu_map(const char *name, struct cpumask *cpumask)
52{
53 unsigned long dt_root = of_get_flat_dt_root();
54 const char *buf;
55
56 buf = of_get_flat_dt_prop(dt_root, name, NULL);
57 if (!buf)
58 return -EINVAL;
59
60 if (cpulist_parse(buf, cpumask))
61 return -EINVAL;
62
63 return 0;
64}
65
66/*
67 * Read from DeviceTree and setup cpu possible mask. If there is no
68 * "possible-cpus" property in DeviceTree pretend all [0..NR_CPUS-1] exist.
69 */
70static void __init arc_init_cpu_possible(void)
71{
72 struct cpumask cpumask;
73
74 if (arc_get_cpu_map("possible-cpus", &cpumask)) {
75 pr_warn("Failed to get possible-cpus from dtb, pretending all %u cpus exist\n",
76 NR_CPUS);
77
78 cpumask_setall(&cpumask);
79 }
80
81 if (!cpumask_test_cpu(0, &cpumask))
82 panic("Master cpu (cpu[0]) is missed in cpu possible mask!");
83
84 init_cpu_possible(&cpumask);
85}
86
50/* 87/*
51 * Called from setup_arch() before calling setup_processor() 88 * Called from setup_arch() before calling setup_processor()
52 * 89 *
@@ -58,10 +95,7 @@ void __init smp_prepare_boot_cpu(void)
58 */ 95 */
59void __init smp_init_cpus(void) 96void __init smp_init_cpus(void)
60{ 97{
61 unsigned int i; 98 arc_init_cpu_possible();
62
63 for (i = 0; i < NR_CPUS; i++)
64 set_cpu_possible(i, true);
65 99
66 if (plat_smp_ops.init_early_smp) 100 if (plat_smp_ops.init_early_smp)
67 plat_smp_ops.init_early_smp(); 101 plat_smp_ops.init_early_smp();
@@ -70,16 +104,12 @@ void __init smp_init_cpus(void)
70/* called from init ( ) => process 1 */ 104/* called from init ( ) => process 1 */
71void __init smp_prepare_cpus(unsigned int max_cpus) 105void __init smp_prepare_cpus(unsigned int max_cpus)
72{ 106{
73 int i;
74
75 /* 107 /*
76 * if platform didn't set the present map already, do it now 108 * if platform didn't set the present map already, do it now
77 * boot cpu is set to present already by init/main.c 109 * boot cpu is set to present already by init/main.c
78 */ 110 */
79 if (num_present_cpus() <= 1) { 111 if (num_present_cpus() <= 1)
80 for (i = 0; i < max_cpus; i++) 112 init_cpu_present(cpu_possible_mask);
81 set_cpu_present(i, true);
82 }
83} 113}
84 114
85void __init smp_cpus_done(unsigned int max_cpus) 115void __init smp_cpus_done(unsigned int max_cpus)
diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
index 333daab7def0..183391d4d33a 100644
--- a/arch/arc/kernel/unwind.c
+++ b/arch/arc/kernel/unwind.c
@@ -366,7 +366,7 @@ static void init_unwind_hdr(struct unwind_table *table,
366 return; 366 return;
367 367
368ret_err: 368ret_err:
369 panic("Attention !!! Dwarf FDE parsing errors\n");; 369 panic("Attention !!! Dwarf FDE parsing errors\n");
370} 370}
371 371
372#ifdef CONFIG_MODULES 372#ifdef CONFIG_MODULES
diff --git a/arch/arc/mm/cache.c b/arch/arc/mm/cache.c
index eee924dfffa6..2072f3451e9c 100644
--- a/arch/arc/mm/cache.c
+++ b/arch/arc/mm/cache.c
@@ -780,7 +780,10 @@ noinline static void slc_entire_op(const int op)
780 780
781 write_aux_reg(r, ctrl); 781 write_aux_reg(r, ctrl);
782 782
783 write_aux_reg(ARC_REG_SLC_INVALIDATE, 1); 783 if (op & OP_INV) /* Inv or flush-n-inv use same cmd reg */
784 write_aux_reg(ARC_REG_SLC_INVALIDATE, 0x1);
785 else
786 write_aux_reg(ARC_REG_SLC_FLUSH, 0x1);
784 787
785 /* Make sure "busy" bit reports correct stataus, see STAR 9001165532 */ 788 /* Make sure "busy" bit reports correct stataus, see STAR 9001165532 */
786 read_aux_reg(r); 789 read_aux_reg(r);
diff --git a/arch/arm/boot/dts/bcm11351.dtsi b/arch/arm/boot/dts/bcm11351.dtsi
index 18045c38bcf1..db7cded1b7ad 100644
--- a/arch/arm/boot/dts/bcm11351.dtsi
+++ b/arch/arm/boot/dts/bcm11351.dtsi
@@ -55,7 +55,7 @@
55 <0x3ff00100 0x100>; 55 <0x3ff00100 0x100>;
56 }; 56 };
57 57
58 smc@0x3404c000 { 58 smc@3404c000 {
59 compatible = "brcm,bcm11351-smc", "brcm,kona-smc"; 59 compatible = "brcm,bcm11351-smc", "brcm,kona-smc";
60 reg = <0x3404c000 0x400>; /* 1 KiB in SRAM */ 60 reg = <0x3404c000 0x400>; /* 1 KiB in SRAM */
61 }; 61 };
diff --git a/arch/arm/boot/dts/bcm21664.dtsi b/arch/arm/boot/dts/bcm21664.dtsi
index 6dde95f21cef..266f2611dc22 100644
--- a/arch/arm/boot/dts/bcm21664.dtsi
+++ b/arch/arm/boot/dts/bcm21664.dtsi
@@ -55,7 +55,7 @@
55 <0x3ff00100 0x100>; 55 <0x3ff00100 0x100>;
56 }; 56 };
57 57
58 smc@0x3404e000 { 58 smc@3404e000 {
59 compatible = "brcm,bcm21664-smc", "brcm,kona-smc"; 59 compatible = "brcm,bcm21664-smc", "brcm,kona-smc";
60 reg = <0x3404e000 0x400>; /* 1 KiB in SRAM */ 60 reg = <0x3404e000 0x400>; /* 1 KiB in SRAM */
61 }; 61 };
diff --git a/arch/arm/boot/dts/bcm2835.dtsi b/arch/arm/boot/dts/bcm2835.dtsi
index 0e3d2a5ff208..a5c3824c8056 100644
--- a/arch/arm/boot/dts/bcm2835.dtsi
+++ b/arch/arm/boot/dts/bcm2835.dtsi
@@ -18,10 +18,10 @@
18 soc { 18 soc {
19 ranges = <0x7e000000 0x20000000 0x02000000>; 19 ranges = <0x7e000000 0x20000000 0x02000000>;
20 dma-ranges = <0x40000000 0x00000000 0x20000000>; 20 dma-ranges = <0x40000000 0x00000000 0x20000000>;
21 };
21 22
22 arm-pmu { 23 arm-pmu {
23 compatible = "arm,arm1176-pmu"; 24 compatible = "arm,arm1176-pmu";
24 };
25 }; 25 };
26}; 26};
27 27
diff --git a/arch/arm/boot/dts/bcm2836.dtsi b/arch/arm/boot/dts/bcm2836.dtsi
index 1dfd76442777..c933e8413884 100644
--- a/arch/arm/boot/dts/bcm2836.dtsi
+++ b/arch/arm/boot/dts/bcm2836.dtsi
@@ -9,19 +9,19 @@
9 <0x40000000 0x40000000 0x00001000>; 9 <0x40000000 0x40000000 0x00001000>;
10 dma-ranges = <0xc0000000 0x00000000 0x3f000000>; 10 dma-ranges = <0xc0000000 0x00000000 0x3f000000>;
11 11
12 local_intc: local_intc { 12 local_intc: local_intc@40000000 {
13 compatible = "brcm,bcm2836-l1-intc"; 13 compatible = "brcm,bcm2836-l1-intc";
14 reg = <0x40000000 0x100>; 14 reg = <0x40000000 0x100>;
15 interrupt-controller; 15 interrupt-controller;
16 #interrupt-cells = <2>; 16 #interrupt-cells = <2>;
17 interrupt-parent = <&local_intc>; 17 interrupt-parent = <&local_intc>;
18 }; 18 };
19 };
19 20
20 arm-pmu { 21 arm-pmu {
21 compatible = "arm,cortex-a7-pmu"; 22 compatible = "arm,cortex-a7-pmu";
22 interrupt-parent = <&local_intc>; 23 interrupt-parent = <&local_intc>;
23 interrupts = <9 IRQ_TYPE_LEVEL_HIGH>; 24 interrupts = <9 IRQ_TYPE_LEVEL_HIGH>;
24 };
25 }; 25 };
26 26
27 timer { 27 timer {
diff --git a/arch/arm/boot/dts/bcm2837.dtsi b/arch/arm/boot/dts/bcm2837.dtsi
index efa7d3387ab2..7704bb029605 100644
--- a/arch/arm/boot/dts/bcm2837.dtsi
+++ b/arch/arm/boot/dts/bcm2837.dtsi
@@ -8,7 +8,7 @@
8 <0x40000000 0x40000000 0x00001000>; 8 <0x40000000 0x40000000 0x00001000>;
9 dma-ranges = <0xc0000000 0x00000000 0x3f000000>; 9 dma-ranges = <0xc0000000 0x00000000 0x3f000000>;
10 10
11 local_intc: local_intc { 11 local_intc: local_intc@40000000 {
12 compatible = "brcm,bcm2836-l1-intc"; 12 compatible = "brcm,bcm2836-l1-intc";
13 reg = <0x40000000 0x100>; 13 reg = <0x40000000 0x100>;
14 interrupt-controller; 14 interrupt-controller;
diff --git a/arch/arm/boot/dts/bcm283x.dtsi b/arch/arm/boot/dts/bcm283x.dtsi
index 18db25a5a66e..9d293decf8d3 100644
--- a/arch/arm/boot/dts/bcm283x.dtsi
+++ b/arch/arm/boot/dts/bcm283x.dtsi
@@ -465,7 +465,7 @@
465 status = "disabled"; 465 status = "disabled";
466 }; 466 };
467 467
468 aux: aux@0x7e215000 { 468 aux: aux@7e215000 {
469 compatible = "brcm,bcm2835-aux"; 469 compatible = "brcm,bcm2835-aux";
470 #clock-cells = <1>; 470 #clock-cells = <1>;
471 reg = <0x7e215000 0x8>; 471 reg = <0x7e215000 0x8>;
diff --git a/arch/arm/boot/dts/bcm958625hr.dts b/arch/arm/boot/dts/bcm958625hr.dts
index 6a44b8021702..f0e2008f7490 100644
--- a/arch/arm/boot/dts/bcm958625hr.dts
+++ b/arch/arm/boot/dts/bcm958625hr.dts
@@ -49,7 +49,7 @@
49 49
50 memory { 50 memory {
51 device_type = "memory"; 51 device_type = "memory";
52 reg = <0x60000000 0x80000000>; 52 reg = <0x60000000 0x20000000>;
53 }; 53 };
54 54
55 gpio-restart { 55 gpio-restart {
diff --git a/arch/arm/boot/dts/gemini-dlink-dns-313.dts b/arch/arm/boot/dts/gemini-dlink-dns-313.dts
index 08568ce24d06..da8bb9d60f99 100644
--- a/arch/arm/boot/dts/gemini-dlink-dns-313.dts
+++ b/arch/arm/boot/dts/gemini-dlink-dns-313.dts
@@ -269,7 +269,7 @@
269 269
270 sata: sata@46000000 { 270 sata: sata@46000000 {
271 /* The ROM uses this muxmode */ 271 /* The ROM uses this muxmode */
272 cortina,gemini-ata-muxmode = <3>; 272 cortina,gemini-ata-muxmode = <0>;
273 cortina,gemini-enable-sata-bridge; 273 cortina,gemini-enable-sata-bridge;
274 status = "okay"; 274 status = "okay";
275 }; 275 };
diff --git a/arch/arm/boot/dts/imx6dl-icore-rqs.dts b/arch/arm/boot/dts/imx6dl-icore-rqs.dts
index cf42c2f5cdc7..1281bc39b7ab 100644
--- a/arch/arm/boot/dts/imx6dl-icore-rqs.dts
+++ b/arch/arm/boot/dts/imx6dl-icore-rqs.dts
@@ -42,7 +42,7 @@
42 42
43/dts-v1/; 43/dts-v1/;
44 44
45#include "imx6q.dtsi" 45#include "imx6dl.dtsi"
46#include "imx6qdl-icore-rqs.dtsi" 46#include "imx6qdl-icore-rqs.dtsi"
47 47
48/ { 48/ {
diff --git a/arch/arm/boot/dts/logicpd-som-lv.dtsi b/arch/arm/boot/dts/logicpd-som-lv.dtsi
index c1aa7a4518fb..a30ee9fcb3ae 100644
--- a/arch/arm/boot/dts/logicpd-som-lv.dtsi
+++ b/arch/arm/boot/dts/logicpd-som-lv.dtsi
@@ -71,6 +71,8 @@
71}; 71};
72 72
73&i2c1 { 73&i2c1 {
74 pinctrl-names = "default";
75 pinctrl-0 = <&i2c1_pins>;
74 clock-frequency = <2600000>; 76 clock-frequency = <2600000>;
75 77
76 twl: twl@48 { 78 twl: twl@48 {
@@ -189,7 +191,12 @@
189 >; 191 >;
190 }; 192 };
191 193
192 194 i2c1_pins: pinmux_i2c1_pins {
195 pinctrl-single,pins = <
196 OMAP3_CORE1_IOPAD(0x21ba, PIN_INPUT | MUX_MODE0) /* i2c1_scl.i2c1_scl */
197 OMAP3_CORE1_IOPAD(0x21bc, PIN_INPUT | MUX_MODE0) /* i2c1_sda.i2c1_sda */
198 >;
199 };
193}; 200};
194 201
195&omap3_pmx_wkup { 202&omap3_pmx_wkup {
diff --git a/arch/arm/boot/dts/logicpd-torpedo-som.dtsi b/arch/arm/boot/dts/logicpd-torpedo-som.dtsi
index b50b796e15c7..47915447a826 100644
--- a/arch/arm/boot/dts/logicpd-torpedo-som.dtsi
+++ b/arch/arm/boot/dts/logicpd-torpedo-som.dtsi
@@ -66,6 +66,8 @@
66}; 66};
67 67
68&i2c1 { 68&i2c1 {
69 pinctrl-names = "default";
70 pinctrl-0 = <&i2c1_pins>;
69 clock-frequency = <2600000>; 71 clock-frequency = <2600000>;
70 72
71 twl: twl@48 { 73 twl: twl@48 {
@@ -136,6 +138,12 @@
136 OMAP3_CORE1_IOPAD(0x21b8, PIN_INPUT | MUX_MODE0) /* hsusb0_data7.hsusb0_data7 */ 138 OMAP3_CORE1_IOPAD(0x21b8, PIN_INPUT | MUX_MODE0) /* hsusb0_data7.hsusb0_data7 */
137 >; 139 >;
138 }; 140 };
141 i2c1_pins: pinmux_i2c1_pins {
142 pinctrl-single,pins = <
143 OMAP3_CORE1_IOPAD(0x21ba, PIN_INPUT | MUX_MODE0) /* i2c1_scl.i2c1_scl */
144 OMAP3_CORE1_IOPAD(0x21bc, PIN_INPUT | MUX_MODE0) /* i2c1_sda.i2c1_sda */
145 >;
146 };
139}; 147};
140 148
141&uart2 { 149&uart2 {
diff --git a/arch/arm/boot/dts/omap5-uevm.dts b/arch/arm/boot/dts/omap5-uevm.dts
index ec2c8baef62a..592e17fd4eeb 100644
--- a/arch/arm/boot/dts/omap5-uevm.dts
+++ b/arch/arm/boot/dts/omap5-uevm.dts
@@ -47,7 +47,7 @@
47 gpios = <&gpio3 19 GPIO_ACTIVE_LOW>; /* gpio3_83 */ 47 gpios = <&gpio3 19 GPIO_ACTIVE_LOW>; /* gpio3_83 */
48 wakeup-source; 48 wakeup-source;
49 autorepeat; 49 autorepeat;
50 debounce_interval = <50>; 50 debounce-interval = <50>;
51 }; 51 };
52 }; 52 };
53 53
diff --git a/arch/arm/boot/dts/rk3036.dtsi b/arch/arm/boot/dts/rk3036.dtsi
index 3b704cfed69a..a97458112ff6 100644
--- a/arch/arm/boot/dts/rk3036.dtsi
+++ b/arch/arm/boot/dts/rk3036.dtsi
@@ -280,7 +280,7 @@
280 max-frequency = <37500000>; 280 max-frequency = <37500000>;
281 clocks = <&cru HCLK_SDIO>, <&cru SCLK_SDIO>, 281 clocks = <&cru HCLK_SDIO>, <&cru SCLK_SDIO>,
282 <&cru SCLK_SDIO_DRV>, <&cru SCLK_SDIO_SAMPLE>; 282 <&cru SCLK_SDIO_DRV>, <&cru SCLK_SDIO_SAMPLE>;
283 clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; 283 clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
284 fifo-depth = <0x100>; 284 fifo-depth = <0x100>;
285 interrupts = <GIC_SPI 15 IRQ_TYPE_LEVEL_HIGH>; 285 interrupts = <GIC_SPI 15 IRQ_TYPE_LEVEL_HIGH>;
286 resets = <&cru SRST_SDIO>; 286 resets = <&cru SRST_SDIO>;
@@ -298,7 +298,7 @@
298 max-frequency = <37500000>; 298 max-frequency = <37500000>;
299 clocks = <&cru HCLK_EMMC>, <&cru SCLK_EMMC>, 299 clocks = <&cru HCLK_EMMC>, <&cru SCLK_EMMC>,
300 <&cru SCLK_EMMC_DRV>, <&cru SCLK_EMMC_SAMPLE>; 300 <&cru SCLK_EMMC_DRV>, <&cru SCLK_EMMC_SAMPLE>;
301 clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; 301 clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
302 default-sample-phase = <158>; 302 default-sample-phase = <158>;
303 disable-wp; 303 disable-wp;
304 dmas = <&pdma 12>; 304 dmas = <&pdma 12>;
diff --git a/arch/arm/boot/dts/rk322x.dtsi b/arch/arm/boot/dts/rk322x.dtsi
index 780ec3a99b21..341deaf62ff6 100644
--- a/arch/arm/boot/dts/rk322x.dtsi
+++ b/arch/arm/boot/dts/rk322x.dtsi
@@ -621,7 +621,7 @@
621 interrupts = <GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>; 621 interrupts = <GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>;
622 clocks = <&cru HCLK_SDMMC>, <&cru SCLK_SDMMC>, 622 clocks = <&cru HCLK_SDMMC>, <&cru SCLK_SDMMC>,
623 <&cru SCLK_SDMMC_DRV>, <&cru SCLK_SDMMC_SAMPLE>; 623 <&cru SCLK_SDMMC_DRV>, <&cru SCLK_SDMMC_SAMPLE>;
624 clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; 624 clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
625 fifo-depth = <0x100>; 625 fifo-depth = <0x100>;
626 pinctrl-names = "default"; 626 pinctrl-names = "default";
627 pinctrl-0 = <&sdmmc_clk &sdmmc_cmd &sdmmc_bus4>; 627 pinctrl-0 = <&sdmmc_clk &sdmmc_cmd &sdmmc_bus4>;
@@ -634,7 +634,7 @@
634 interrupts = <GIC_SPI 13 IRQ_TYPE_LEVEL_HIGH>; 634 interrupts = <GIC_SPI 13 IRQ_TYPE_LEVEL_HIGH>;
635 clocks = <&cru HCLK_SDIO>, <&cru SCLK_SDIO>, 635 clocks = <&cru HCLK_SDIO>, <&cru SCLK_SDIO>,
636 <&cru SCLK_SDIO_DRV>, <&cru SCLK_SDIO_SAMPLE>; 636 <&cru SCLK_SDIO_DRV>, <&cru SCLK_SDIO_SAMPLE>;
637 clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; 637 clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
638 fifo-depth = <0x100>; 638 fifo-depth = <0x100>;
639 pinctrl-names = "default"; 639 pinctrl-names = "default";
640 pinctrl-0 = <&sdio_clk &sdio_cmd &sdio_bus4>; 640 pinctrl-0 = <&sdio_clk &sdio_cmd &sdio_bus4>;
@@ -649,7 +649,7 @@
649 max-frequency = <37500000>; 649 max-frequency = <37500000>;
650 clocks = <&cru HCLK_EMMC>, <&cru SCLK_EMMC>, 650 clocks = <&cru HCLK_EMMC>, <&cru SCLK_EMMC>,
651 <&cru SCLK_EMMC_DRV>, <&cru SCLK_EMMC_SAMPLE>; 651 <&cru SCLK_EMMC_DRV>, <&cru SCLK_EMMC_SAMPLE>;
652 clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; 652 clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
653 bus-width = <8>; 653 bus-width = <8>;
654 default-sample-phase = <158>; 654 default-sample-phase = <158>;
655 fifo-depth = <0x100>; 655 fifo-depth = <0x100>;
diff --git a/arch/arm/boot/dts/rk3288-phycore-som.dtsi b/arch/arm/boot/dts/rk3288-phycore-som.dtsi
index 99cfae875e12..5eae4776ffde 100644
--- a/arch/arm/boot/dts/rk3288-phycore-som.dtsi
+++ b/arch/arm/boot/dts/rk3288-phycore-som.dtsi
@@ -110,26 +110,6 @@
110 }; 110 };
111}; 111};
112 112
113&cpu0 {
114 cpu0-supply = <&vdd_cpu>;
115 operating-points = <
116 /* KHz uV */
117 1800000 1400000
118 1608000 1350000
119 1512000 1300000
120 1416000 1200000
121 1200000 1100000
122 1008000 1050000
123 816000 1000000
124 696000 950000
125 600000 900000
126 408000 900000
127 312000 900000
128 216000 900000
129 126000 900000
130 >;
131};
132
133&emmc { 113&emmc {
134 status = "okay"; 114 status = "okay";
135 bus-width = <8>; 115 bus-width = <8>;
diff --git a/arch/arm/boot/dts/zx296702.dtsi b/arch/arm/boot/dts/zx296702.dtsi
index 8a74efdb6360..240e7a23d81f 100644
--- a/arch/arm/boot/dts/zx296702.dtsi
+++ b/arch/arm/boot/dts/zx296702.dtsi
@@ -56,7 +56,7 @@
56 clocks = <&topclk ZX296702_A9_PERIPHCLK>; 56 clocks = <&topclk ZX296702_A9_PERIPHCLK>;
57 }; 57 };
58 58
59 l2cc: l2-cache-controller@0x00c00000 { 59 l2cc: l2-cache-controller@c00000 {
60 compatible = "arm,pl310-cache"; 60 compatible = "arm,pl310-cache";
61 reg = <0x00c00000 0x1000>; 61 reg = <0x00c00000 0x1000>;
62 cache-unified; 62 cache-unified;
@@ -67,30 +67,30 @@
67 arm,double-linefill-incr = <0>; 67 arm,double-linefill-incr = <0>;
68 }; 68 };
69 69
70 pcu: pcu@0xa0008000 { 70 pcu: pcu@a0008000 {
71 compatible = "zte,zx296702-pcu"; 71 compatible = "zte,zx296702-pcu";
72 reg = <0xa0008000 0x1000>; 72 reg = <0xa0008000 0x1000>;
73 }; 73 };
74 74
75 topclk: topclk@0x09800000 { 75 topclk: topclk@9800000 {
76 compatible = "zte,zx296702-topcrm-clk"; 76 compatible = "zte,zx296702-topcrm-clk";
77 reg = <0x09800000 0x1000>; 77 reg = <0x09800000 0x1000>;
78 #clock-cells = <1>; 78 #clock-cells = <1>;
79 }; 79 };
80 80
81 lsp1clk: lsp1clk@0x09400000 { 81 lsp1clk: lsp1clk@9400000 {
82 compatible = "zte,zx296702-lsp1crpm-clk"; 82 compatible = "zte,zx296702-lsp1crpm-clk";
83 reg = <0x09400000 0x1000>; 83 reg = <0x09400000 0x1000>;
84 #clock-cells = <1>; 84 #clock-cells = <1>;
85 }; 85 };
86 86
87 lsp0clk: lsp0clk@0x0b000000 { 87 lsp0clk: lsp0clk@b000000 {
88 compatible = "zte,zx296702-lsp0crpm-clk"; 88 compatible = "zte,zx296702-lsp0crpm-clk";
89 reg = <0x0b000000 0x1000>; 89 reg = <0x0b000000 0x1000>;
90 #clock-cells = <1>; 90 #clock-cells = <1>;
91 }; 91 };
92 92
93 uart0: serial@0x09405000 { 93 uart0: serial@9405000 {
94 compatible = "zte,zx296702-uart"; 94 compatible = "zte,zx296702-uart";
95 reg = <0x09405000 0x1000>; 95 reg = <0x09405000 0x1000>;
96 interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; 96 interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;
@@ -98,7 +98,7 @@
98 status = "disabled"; 98 status = "disabled";
99 }; 99 };
100 100
101 uart1: serial@0x09406000 { 101 uart1: serial@9406000 {
102 compatible = "zte,zx296702-uart"; 102 compatible = "zte,zx296702-uart";
103 reg = <0x09406000 0x1000>; 103 reg = <0x09406000 0x1000>;
104 interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>; 104 interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
@@ -106,7 +106,7 @@
106 status = "disabled"; 106 status = "disabled";
107 }; 107 };
108 108
109 mmc0: mmc@0x09408000 { 109 mmc0: mmc@9408000 {
110 compatible = "snps,dw-mshc"; 110 compatible = "snps,dw-mshc";
111 #address-cells = <1>; 111 #address-cells = <1>;
112 #size-cells = <0>; 112 #size-cells = <0>;
@@ -119,7 +119,7 @@
119 status = "disabled"; 119 status = "disabled";
120 }; 120 };
121 121
122 mmc1: mmc@0x0b003000 { 122 mmc1: mmc@b003000 {
123 compatible = "snps,dw-mshc"; 123 compatible = "snps,dw-mshc";
124 #address-cells = <1>; 124 #address-cells = <1>;
125 #size-cells = <0>; 125 #size-cells = <0>;
@@ -132,7 +132,7 @@
132 status = "disabled"; 132 status = "disabled";
133 }; 133 };
134 134
135 sysctrl: sysctrl@0xa0007000 { 135 sysctrl: sysctrl@a0007000 {
136 compatible = "zte,sysctrl", "syscon"; 136 compatible = "zte,sysctrl", "syscon";
137 reg = <0xa0007000 0x1000>; 137 reg = <0xa0007000 0x1000>;
138 }; 138 };
diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index 2f145c4af93a..92674f247a12 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -319,7 +319,7 @@ CONFIG_MEDIA_CAMERA_SUPPORT=y
319CONFIG_RC_CORE=m 319CONFIG_RC_CORE=m
320CONFIG_MEDIA_CONTROLLER=y 320CONFIG_MEDIA_CONTROLLER=y
321CONFIG_VIDEO_V4L2_SUBDEV_API=y 321CONFIG_VIDEO_V4L2_SUBDEV_API=y
322CONFIG_LIRC=m 322CONFIG_LIRC=y
323CONFIG_RC_DEVICES=y 323CONFIG_RC_DEVICES=y
324CONFIG_IR_RX51=m 324CONFIG_IR_RX51=m
325CONFIG_V4L_PLATFORM_DRIVERS=y 325CONFIG_V4L_PLATFORM_DRIVERS=y
diff --git a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c
index 629f8e9981f1..cf2701cb0de8 100644
--- a/arch/arm/kernel/time.c
+++ b/arch/arm/kernel/time.c
@@ -83,7 +83,7 @@ static void dummy_clock_access(struct timespec64 *ts)
83} 83}
84 84
85static clock_access_fn __read_persistent_clock = dummy_clock_access; 85static clock_access_fn __read_persistent_clock = dummy_clock_access;
86static clock_access_fn __read_boot_clock = dummy_clock_access;; 86static clock_access_fn __read_boot_clock = dummy_clock_access;
87 87
88void read_persistent_clock64(struct timespec64 *ts) 88void read_persistent_clock64(struct timespec64 *ts)
89{ 89{
diff --git a/arch/arm/kvm/hyp/Makefile b/arch/arm/kvm/hyp/Makefile
index 5638ce0c9524..63d6b404d88e 100644
--- a/arch/arm/kvm/hyp/Makefile
+++ b/arch/arm/kvm/hyp/Makefile
@@ -7,6 +7,8 @@ ccflags-y += -fno-stack-protector -DDISABLE_BRANCH_PROFILING
7 7
8KVM=../../../../virt/kvm 8KVM=../../../../virt/kvm
9 9
10CFLAGS_ARMV7VE :=$(call cc-option, -march=armv7ve)
11
10obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v2-sr.o 12obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v2-sr.o
11obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v3-sr.o 13obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v3-sr.o
12obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/timer-sr.o 14obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/timer-sr.o
@@ -15,7 +17,10 @@ obj-$(CONFIG_KVM_ARM_HOST) += tlb.o
15obj-$(CONFIG_KVM_ARM_HOST) += cp15-sr.o 17obj-$(CONFIG_KVM_ARM_HOST) += cp15-sr.o
16obj-$(CONFIG_KVM_ARM_HOST) += vfp.o 18obj-$(CONFIG_KVM_ARM_HOST) += vfp.o
17obj-$(CONFIG_KVM_ARM_HOST) += banked-sr.o 19obj-$(CONFIG_KVM_ARM_HOST) += banked-sr.o
20CFLAGS_banked-sr.o += $(CFLAGS_ARMV7VE)
21
18obj-$(CONFIG_KVM_ARM_HOST) += entry.o 22obj-$(CONFIG_KVM_ARM_HOST) += entry.o
19obj-$(CONFIG_KVM_ARM_HOST) += hyp-entry.o 23obj-$(CONFIG_KVM_ARM_HOST) += hyp-entry.o
20obj-$(CONFIG_KVM_ARM_HOST) += switch.o 24obj-$(CONFIG_KVM_ARM_HOST) += switch.o
25CFLAGS_switch.o += $(CFLAGS_ARMV7VE)
21obj-$(CONFIG_KVM_ARM_HOST) += s2-setup.o 26obj-$(CONFIG_KVM_ARM_HOST) += s2-setup.o
diff --git a/arch/arm/kvm/hyp/banked-sr.c b/arch/arm/kvm/hyp/banked-sr.c
index 111bda8cdebd..be4b8b0a40ad 100644
--- a/arch/arm/kvm/hyp/banked-sr.c
+++ b/arch/arm/kvm/hyp/banked-sr.c
@@ -20,6 +20,10 @@
20 20
21#include <asm/kvm_hyp.h> 21#include <asm/kvm_hyp.h>
22 22
23/*
24 * gcc before 4.9 doesn't understand -march=armv7ve, so we have to
25 * trick the assembler.
26 */
23__asm__(".arch_extension virt"); 27__asm__(".arch_extension virt");
24 28
25void __hyp_text __banked_save_state(struct kvm_cpu_context *ctxt) 29void __hyp_text __banked_save_state(struct kvm_cpu_context *ctxt)
diff --git a/arch/arm/mach-clps711x/board-dt.c b/arch/arm/mach-clps711x/board-dt.c
index ee1f83b1a332..4c89a8e9a2e3 100644
--- a/arch/arm/mach-clps711x/board-dt.c
+++ b/arch/arm/mach-clps711x/board-dt.c
@@ -69,7 +69,7 @@ static void clps711x_restart(enum reboot_mode mode, const char *cmd)
69 soft_restart(0); 69 soft_restart(0);
70} 70}
71 71
72static const char *clps711x_compat[] __initconst = { 72static const char *const clps711x_compat[] __initconst = {
73 "cirrus,ep7209", 73 "cirrus,ep7209",
74 NULL 74 NULL
75}; 75};
diff --git a/arch/arm/mach-davinci/board-dm355-evm.c b/arch/arm/mach-davinci/board-dm355-evm.c
index e457f299cd44..d6b11907380c 100644
--- a/arch/arm/mach-davinci/board-dm355-evm.c
+++ b/arch/arm/mach-davinci/board-dm355-evm.c
@@ -368,7 +368,7 @@ static struct spi_eeprom at25640a = {
368 .flags = EE_ADDR2, 368 .flags = EE_ADDR2,
369}; 369};
370 370
371static struct spi_board_info dm355_evm_spi_info[] __initconst = { 371static const struct spi_board_info dm355_evm_spi_info[] __initconst = {
372 { 372 {
373 .modalias = "at25", 373 .modalias = "at25",
374 .platform_data = &at25640a, 374 .platform_data = &at25640a,
diff --git a/arch/arm/mach-davinci/board-dm355-leopard.c b/arch/arm/mach-davinci/board-dm355-leopard.c
index be997243447b..fad9a5611a5d 100644
--- a/arch/arm/mach-davinci/board-dm355-leopard.c
+++ b/arch/arm/mach-davinci/board-dm355-leopard.c
@@ -217,7 +217,7 @@ static struct spi_eeprom at25640a = {
217 .flags = EE_ADDR2, 217 .flags = EE_ADDR2,
218}; 218};
219 219
220static struct spi_board_info dm355_leopard_spi_info[] __initconst = { 220static const struct spi_board_info dm355_leopard_spi_info[] __initconst = {
221 { 221 {
222 .modalias = "at25", 222 .modalias = "at25",
223 .platform_data = &at25640a, 223 .platform_data = &at25640a,
diff --git a/arch/arm/mach-davinci/board-dm365-evm.c b/arch/arm/mach-davinci/board-dm365-evm.c
index e75741fb2c1d..e3780986d2a3 100644
--- a/arch/arm/mach-davinci/board-dm365-evm.c
+++ b/arch/arm/mach-davinci/board-dm365-evm.c
@@ -726,7 +726,7 @@ static struct spi_eeprom at25640 = {
726 .flags = EE_ADDR2, 726 .flags = EE_ADDR2,
727}; 727};
728 728
729static struct spi_board_info dm365_evm_spi_info[] __initconst = { 729static const struct spi_board_info dm365_evm_spi_info[] __initconst = {
730 { 730 {
731 .modalias = "at25", 731 .modalias = "at25",
732 .platform_data = &at25640, 732 .platform_data = &at25640,
diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index 6b32dc527edc..2c20599cc350 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -41,7 +41,7 @@ config MACH_ARMADA_375
41 depends on ARCH_MULTI_V7 41 depends on ARCH_MULTI_V7
42 select ARMADA_370_XP_IRQ 42 select ARMADA_370_XP_IRQ
43 select ARM_ERRATA_720789 43 select ARM_ERRATA_720789
44 select ARM_ERRATA_753970 44 select PL310_ERRATA_753970
45 select ARM_GIC 45 select ARM_GIC
46 select ARMADA_375_CLK 46 select ARMADA_375_CLK
47 select HAVE_ARM_SCU 47 select HAVE_ARM_SCU
@@ -57,7 +57,7 @@ config MACH_ARMADA_38X
57 bool "Marvell Armada 380/385 boards" 57 bool "Marvell Armada 380/385 boards"
58 depends on ARCH_MULTI_V7 58 depends on ARCH_MULTI_V7
59 select ARM_ERRATA_720789 59 select ARM_ERRATA_720789
60 select ARM_ERRATA_753970 60 select PL310_ERRATA_753970
61 select ARM_GIC 61 select ARM_GIC
62 select ARM_GLOBAL_TIMER 62 select ARM_GLOBAL_TIMER
63 select CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK 63 select CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK
diff --git a/arch/arm/mach-omap1/clock.c b/arch/arm/mach-omap1/clock.c
index 43e3e188f521..fa512413a471 100644
--- a/arch/arm/mach-omap1/clock.c
+++ b/arch/arm/mach-omap1/clock.c
@@ -1011,17 +1011,17 @@ static int clk_debugfs_register_one(struct clk *c)
1011 return -ENOMEM; 1011 return -ENOMEM;
1012 c->dent = d; 1012 c->dent = d;
1013 1013
1014 d = debugfs_create_u8("usecount", S_IRUGO, c->dent, (u8 *)&c->usecount); 1014 d = debugfs_create_u8("usecount", S_IRUGO, c->dent, &c->usecount);
1015 if (!d) { 1015 if (!d) {
1016 err = -ENOMEM; 1016 err = -ENOMEM;
1017 goto err_out; 1017 goto err_out;
1018 } 1018 }
1019 d = debugfs_create_u32("rate", S_IRUGO, c->dent, (u32 *)&c->rate); 1019 d = debugfs_create_ulong("rate", S_IRUGO, c->dent, &c->rate);
1020 if (!d) { 1020 if (!d) {
1021 err = -ENOMEM; 1021 err = -ENOMEM;
1022 goto err_out; 1022 goto err_out;
1023 } 1023 }
1024 d = debugfs_create_x32("flags", S_IRUGO, c->dent, (u32 *)&c->flags); 1024 d = debugfs_create_x8("flags", S_IRUGO, c->dent, &c->flags);
1025 if (!d) { 1025 if (!d) {
1026 err = -ENOMEM; 1026 err = -ENOMEM;
1027 goto err_out; 1027 goto err_out;
diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
index 4bb6751864a5..fc5fb776a710 100644
--- a/arch/arm/mach-omap2/omap-wakeupgen.c
+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
@@ -299,8 +299,6 @@ static void irq_save_context(void)
299 if (soc_is_dra7xx()) 299 if (soc_is_dra7xx())
300 return; 300 return;
301 301
302 if (!sar_base)
303 sar_base = omap4_get_sar_ram_base();
304 if (wakeupgen_ops && wakeupgen_ops->save_context) 302 if (wakeupgen_ops && wakeupgen_ops->save_context)
305 wakeupgen_ops->save_context(); 303 wakeupgen_ops->save_context();
306} 304}
@@ -598,6 +596,8 @@ static int __init wakeupgen_init(struct device_node *node,
598 irq_hotplug_init(); 596 irq_hotplug_init();
599 irq_pm_init(); 597 irq_pm_init();
600 598
599 sar_base = omap4_get_sar_ram_base();
600
601 return 0; 601 return 0;
602} 602}
603IRQCHIP_DECLARE(ti_wakeupgen, "ti,omap4-wugen-mpu", wakeupgen_init); 603IRQCHIP_DECLARE(ti_wakeupgen, "ti,omap4-wugen-mpu", wakeupgen_init);
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index 124f9af34a15..34156eca8e23 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -977,6 +977,9 @@ static int _enable_clocks(struct omap_hwmod *oh)
977 977
978 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name); 978 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
979 979
980 if (oh->flags & HWMOD_OPT_CLKS_NEEDED)
981 _enable_optional_clocks(oh);
982
980 if (oh->_clk) 983 if (oh->_clk)
981 clk_enable(oh->_clk); 984 clk_enable(oh->_clk);
982 985
@@ -985,9 +988,6 @@ static int _enable_clocks(struct omap_hwmod *oh)
985 clk_enable(os->_clk); 988 clk_enable(os->_clk);
986 } 989 }
987 990
988 if (oh->flags & HWMOD_OPT_CLKS_NEEDED)
989 _enable_optional_clocks(oh);
990
991 /* The opt clocks are controlled by the device driver. */ 991 /* The opt clocks are controlled by the device driver. */
992 992
993 return 0; 993 return 0;
diff --git a/arch/arm/mach-omap2/pm.c b/arch/arm/mach-omap2/pm.c
index 366158a54fcd..6f68576e5695 100644
--- a/arch/arm/mach-omap2/pm.c
+++ b/arch/arm/mach-omap2/pm.c
@@ -186,7 +186,7 @@ static void omap_pm_end(void)
186 cpu_idle_poll_ctrl(false); 186 cpu_idle_poll_ctrl(false);
187} 187}
188 188
189static void omap_pm_finish(void) 189static void omap_pm_wake(void)
190{ 190{
191 if (soc_is_omap34xx()) 191 if (soc_is_omap34xx())
192 omap_prcm_irq_complete(); 192 omap_prcm_irq_complete();
@@ -196,7 +196,7 @@ static const struct platform_suspend_ops omap_pm_ops = {
196 .begin = omap_pm_begin, 196 .begin = omap_pm_begin,
197 .end = omap_pm_end, 197 .end = omap_pm_end,
198 .enter = omap_pm_enter, 198 .enter = omap_pm_enter,
199 .finish = omap_pm_finish, 199 .wake = omap_pm_wake,
200 .valid = suspend_valid_only_mem, 200 .valid = suspend_valid_only_mem,
201}; 201};
202 202
diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c
index ece09c9461f7..d61fbd7a2840 100644
--- a/arch/arm/mach-omap2/timer.c
+++ b/arch/arm/mach-omap2/timer.c
@@ -156,12 +156,6 @@ static struct clock_event_device clockevent_gpt = {
156 .tick_resume = omap2_gp_timer_shutdown, 156 .tick_resume = omap2_gp_timer_shutdown,
157}; 157};
158 158
159static struct property device_disabled = {
160 .name = "status",
161 .length = sizeof("disabled"),
162 .value = "disabled",
163};
164
165static const struct of_device_id omap_timer_match[] __initconst = { 159static const struct of_device_id omap_timer_match[] __initconst = {
166 { .compatible = "ti,omap2420-timer", }, 160 { .compatible = "ti,omap2420-timer", },
167 { .compatible = "ti,omap3430-timer", }, 161 { .compatible = "ti,omap3430-timer", },
@@ -203,8 +197,17 @@ static struct device_node * __init omap_get_timer_dt(const struct of_device_id *
203 of_get_property(np, "ti,timer-secure", NULL))) 197 of_get_property(np, "ti,timer-secure", NULL)))
204 continue; 198 continue;
205 199
206 if (!of_device_is_compatible(np, "ti,omap-counter32k")) 200 if (!of_device_is_compatible(np, "ti,omap-counter32k")) {
207 of_add_property(np, &device_disabled); 201 struct property *prop;
202
203 prop = kzalloc(sizeof(*prop), GFP_KERNEL);
204 if (!prop)
205 return NULL;
206 prop->name = "status";
207 prop->value = "disabled";
208 prop->length = strlen(prop->value);
209 of_add_property(np, prop);
210 }
208 return np; 211 return np;
209 } 212 }
210 213
diff --git a/arch/arm/mach-orion5x/Kconfig b/arch/arm/mach-orion5x/Kconfig
index 2a7bb6ccdcb7..a810f4dd34b1 100644
--- a/arch/arm/mach-orion5x/Kconfig
+++ b/arch/arm/mach-orion5x/Kconfig
@@ -58,7 +58,6 @@ config MACH_KUROBOX_PRO
58 58
59config MACH_DNS323 59config MACH_DNS323
60 bool "D-Link DNS-323" 60 bool "D-Link DNS-323"
61 select GENERIC_NET_UTILS
62 select I2C_BOARDINFO if I2C 61 select I2C_BOARDINFO if I2C
63 help 62 help
64 Say 'Y' here if you want your kernel to support the 63 Say 'Y' here if you want your kernel to support the
@@ -66,7 +65,6 @@ config MACH_DNS323
66 65
67config MACH_TS209 66config MACH_TS209
68 bool "QNAP TS-109/TS-209" 67 bool "QNAP TS-109/TS-209"
69 select GENERIC_NET_UTILS
70 help 68 help
71 Say 'Y' here if you want your kernel to support the 69 Say 'Y' here if you want your kernel to support the
72 QNAP TS-109/TS-209 platform. 70 QNAP TS-109/TS-209 platform.
@@ -101,7 +99,6 @@ config MACH_LINKSTATION_LS_HGL
101 99
102config MACH_TS409 100config MACH_TS409
103 bool "QNAP TS-409" 101 bool "QNAP TS-409"
104 select GENERIC_NET_UTILS
105 help 102 help
106 Say 'Y' here if you want your kernel to support the 103 Say 'Y' here if you want your kernel to support the
107 QNAP TS-409 platform. 104 QNAP TS-409 platform.
diff --git a/arch/arm/mach-orion5x/dns323-setup.c b/arch/arm/mach-orion5x/dns323-setup.c
index cd483bfb5ca8..d13344b2ddcd 100644
--- a/arch/arm/mach-orion5x/dns323-setup.c
+++ b/arch/arm/mach-orion5x/dns323-setup.c
@@ -173,10 +173,42 @@ static struct mv643xx_eth_platform_data dns323_eth_data = {
173 .phy_addr = MV643XX_ETH_PHY_ADDR(8), 173 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
174}; 174};
175 175
176/* dns323_parse_hex_*() taken from tsx09-common.c; should a common copy of these
177 * functions be kept somewhere?
178 */
179static int __init dns323_parse_hex_nibble(char n)
180{
181 if (n >= '0' && n <= '9')
182 return n - '0';
183
184 if (n >= 'A' && n <= 'F')
185 return n - 'A' + 10;
186
187 if (n >= 'a' && n <= 'f')
188 return n - 'a' + 10;
189
190 return -1;
191}
192
193static int __init dns323_parse_hex_byte(const char *b)
194{
195 int hi;
196 int lo;
197
198 hi = dns323_parse_hex_nibble(b[0]);
199 lo = dns323_parse_hex_nibble(b[1]);
200
201 if (hi < 0 || lo < 0)
202 return -1;
203
204 return (hi << 4) | lo;
205}
206
176static int __init dns323_read_mac_addr(void) 207static int __init dns323_read_mac_addr(void)
177{ 208{
178 u_int8_t addr[6]; 209 u_int8_t addr[6];
179 void __iomem *mac_page; 210 int i;
211 char *mac_page;
180 212
181 /* MAC address is stored as a regular ol' string in /dev/mtdblock4 213 /* MAC address is stored as a regular ol' string in /dev/mtdblock4
182 * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80). 214 * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80).
@@ -185,8 +217,23 @@ static int __init dns323_read_mac_addr(void)
185 if (!mac_page) 217 if (!mac_page)
186 return -ENOMEM; 218 return -ENOMEM;
187 219
188 if (!mac_pton((__force const char *) mac_page, addr)) 220 /* Sanity check the string we're looking at */
189 goto error_fail; 221 for (i = 0; i < 5; i++) {
222 if (*(mac_page + (i * 3) + 2) != ':') {
223 goto error_fail;
224 }
225 }
226
227 for (i = 0; i < 6; i++) {
228 int byte;
229
230 byte = dns323_parse_hex_byte(mac_page + (i * 3));
231 if (byte < 0) {
232 goto error_fail;
233 }
234
235 addr[i] = byte;
236 }
190 237
191 iounmap(mac_page); 238 iounmap(mac_page);
192 printk("DNS-323: Found ethernet MAC address: %pM\n", addr); 239 printk("DNS-323: Found ethernet MAC address: %pM\n", addr);
diff --git a/arch/arm/mach-orion5x/tsx09-common.c b/arch/arm/mach-orion5x/tsx09-common.c
index 89774985d380..905d4f2dd0b8 100644
--- a/arch/arm/mach-orion5x/tsx09-common.c
+++ b/arch/arm/mach-orion5x/tsx09-common.c
@@ -53,12 +53,53 @@ struct mv643xx_eth_platform_data qnap_tsx09_eth_data = {
53 .phy_addr = MV643XX_ETH_PHY_ADDR(8), 53 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
54}; 54};
55 55
56static int __init qnap_tsx09_parse_hex_nibble(char n)
57{
58 if (n >= '0' && n <= '9')
59 return n - '0';
60
61 if (n >= 'A' && n <= 'F')
62 return n - 'A' + 10;
63
64 if (n >= 'a' && n <= 'f')
65 return n - 'a' + 10;
66
67 return -1;
68}
69
70static int __init qnap_tsx09_parse_hex_byte(const char *b)
71{
72 int hi;
73 int lo;
74
75 hi = qnap_tsx09_parse_hex_nibble(b[0]);
76 lo = qnap_tsx09_parse_hex_nibble(b[1]);
77
78 if (hi < 0 || lo < 0)
79 return -1;
80
81 return (hi << 4) | lo;
82}
83
56static int __init qnap_tsx09_check_mac_addr(const char *addr_str) 84static int __init qnap_tsx09_check_mac_addr(const char *addr_str)
57{ 85{
58 u_int8_t addr[6]; 86 u_int8_t addr[6];
87 int i;
59 88
60 if (!mac_pton(addr_str, addr)) 89 for (i = 0; i < 6; i++) {
61 return -1; 90 int byte;
91
92 /*
93 * Enforce "xx:xx:xx:xx:xx:xx\n" format.
94 */
95 if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
96 return -1;
97
98 byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3));
99 if (byte < 0)
100 return -1;
101 addr[i] = byte;
102 }
62 103
63 printk(KERN_INFO "tsx09: found ethernet mac address %pM\n", addr); 104 printk(KERN_INFO "tsx09: found ethernet mac address %pM\n", addr);
64 105
@@ -77,12 +118,12 @@ void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size)
77 unsigned long addr; 118 unsigned long addr;
78 119
79 for (addr = mem_base; addr < (mem_base + size); addr += 1024) { 120 for (addr = mem_base; addr < (mem_base + size); addr += 1024) {
80 void __iomem *nor_page; 121 char *nor_page;
81 int ret = 0; 122 int ret = 0;
82 123
83 nor_page = ioremap(addr, 1024); 124 nor_page = ioremap(addr, 1024);
84 if (nor_page != NULL) { 125 if (nor_page != NULL) {
85 ret = qnap_tsx09_check_mac_addr((__force const char *)nor_page); 126 ret = qnap_tsx09_check_mac_addr(nor_page);
86 iounmap(nor_page); 127 iounmap(nor_page);
87 } 128 }
88 129
diff --git a/arch/arm/mach-ux500/cpu-db8500.c b/arch/arm/mach-ux500/cpu-db8500.c
index 57058ac46f49..7e5d7a083707 100644
--- a/arch/arm/mach-ux500/cpu-db8500.c
+++ b/arch/arm/mach-ux500/cpu-db8500.c
@@ -23,7 +23,6 @@
23#include <linux/of.h> 23#include <linux/of.h>
24#include <linux/of_address.h> 24#include <linux/of_address.h>
25#include <linux/of_platform.h> 25#include <linux/of_platform.h>
26#include <linux/perf/arm_pmu.h>
27#include <linux/regulator/machine.h> 26#include <linux/regulator/machine.h>
28 27
29#include <asm/outercache.h> 28#include <asm/outercache.h>
@@ -112,37 +111,6 @@ static void ux500_restart(enum reboot_mode mode, const char *cmd)
112 prcmu_system_reset(0); 111 prcmu_system_reset(0);
113} 112}
114 113
115/*
116 * The PMU IRQ lines of two cores are wired together into a single interrupt.
117 * Bounce the interrupt to the other core if it's not ours.
118 */
119static irqreturn_t db8500_pmu_handler(int irq, void *dev, irq_handler_t handler)
120{
121 irqreturn_t ret = handler(irq, dev);
122 int other = !smp_processor_id();
123
124 if (ret == IRQ_NONE && cpu_online(other))
125 irq_set_affinity(irq, cpumask_of(other));
126
127 /*
128 * We should be able to get away with the amount of IRQ_NONEs we give,
129 * while still having the spurious IRQ detection code kick in if the
130 * interrupt really starts hitting spuriously.
131 */
132 return ret;
133}
134
135static struct arm_pmu_platdata db8500_pmu_platdata = {
136 .handle_irq = db8500_pmu_handler,
137 .irq_flags = IRQF_NOBALANCING | IRQF_NO_THREAD,
138};
139
140static struct of_dev_auxdata u8500_auxdata_lookup[] __initdata = {
141 /* Requires call-back bindings. */
142 OF_DEV_AUXDATA("arm,cortex-a9-pmu", 0, "arm-pmu", &db8500_pmu_platdata),
143 {},
144};
145
146static struct of_dev_auxdata u8540_auxdata_lookup[] __initdata = { 114static struct of_dev_auxdata u8540_auxdata_lookup[] __initdata = {
147 OF_DEV_AUXDATA("stericsson,db8500-prcmu", 0x80157000, "db8500-prcmu", NULL), 115 OF_DEV_AUXDATA("stericsson,db8500-prcmu", 0x80157000, "db8500-prcmu", NULL),
148 {}, 116 {},
@@ -165,9 +133,6 @@ static void __init u8500_init_machine(void)
165 if (of_machine_is_compatible("st-ericsson,u8540")) 133 if (of_machine_is_compatible("st-ericsson,u8540"))
166 of_platform_populate(NULL, u8500_local_bus_nodes, 134 of_platform_populate(NULL, u8500_local_bus_nodes,
167 u8540_auxdata_lookup, NULL); 135 u8540_auxdata_lookup, NULL);
168 else
169 of_platform_populate(NULL, u8500_local_bus_nodes,
170 u8500_auxdata_lookup, NULL);
171} 136}
172 137
173static const char * stericsson_dt_platform_compat[] = { 138static const char * stericsson_dt_platform_compat[] = {
diff --git a/arch/arm/plat-orion/common.c b/arch/arm/plat-orion/common.c
index aff6994950ba..a2399fd66e97 100644
--- a/arch/arm/plat-orion/common.c
+++ b/arch/arm/plat-orion/common.c
@@ -472,28 +472,27 @@ void __init orion_ge11_init(struct mv643xx_eth_platform_data *eth_data,
472/***************************************************************************** 472/*****************************************************************************
473 * Ethernet switch 473 * Ethernet switch
474 ****************************************************************************/ 474 ****************************************************************************/
475static __initconst const char *orion_ge00_mvmdio_bus_name = "orion-mii"; 475static __initdata struct mdio_board_info orion_ge00_switch_board_info = {
476static __initdata struct mdio_board_info 476 .bus_id = "orion-mii",
477 orion_ge00_switch_board_info; 477 .modalias = "mv88e6085",
478};
478 479
479void __init orion_ge00_switch_init(struct dsa_chip_data *d) 480void __init orion_ge00_switch_init(struct dsa_chip_data *d)
480{ 481{
481 struct mdio_board_info *bd;
482 unsigned int i; 482 unsigned int i;
483 483
484 if (!IS_BUILTIN(CONFIG_PHYLIB)) 484 if (!IS_BUILTIN(CONFIG_PHYLIB))
485 return; 485 return;
486 486
487 for (i = 0; i < ARRAY_SIZE(d->port_names); i++) 487 for (i = 0; i < ARRAY_SIZE(d->port_names); i++) {
488 if (!strcmp(d->port_names[i], "cpu")) 488 if (!strcmp(d->port_names[i], "cpu")) {
489 d->netdev[i] = &orion_ge00.dev;
489 break; 490 break;
491 }
492 }
490 493
491 bd = &orion_ge00_switch_board_info; 494 orion_ge00_switch_board_info.mdio_addr = d->sw_addr;
492 bd->bus_id = orion_ge00_mvmdio_bus_name; 495 orion_ge00_switch_board_info.platform_data = d;
493 bd->mdio_addr = d->sw_addr;
494 d->netdev[i] = &orion_ge00.dev;
495 strcpy(bd->modalias, "mv88e6085");
496 bd->platform_data = d;
497 496
498 mdiobus_register_board_info(&orion_ge00_switch_board_info, 1); 497 mdiobus_register_board_info(&orion_ge00_switch_board_info, 1);
499} 498}
diff --git a/arch/arm64/boot/dts/amlogic/meson-axg.dtsi b/arch/arm64/boot/dts/amlogic/meson-axg.dtsi
index a80632641b39..70c776ef7aa7 100644
--- a/arch/arm64/boot/dts/amlogic/meson-axg.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-axg.dtsi
@@ -165,14 +165,14 @@
165 165
166 uart_A: serial@24000 { 166 uart_A: serial@24000 {
167 compatible = "amlogic,meson-gx-uart", "amlogic,meson-uart"; 167 compatible = "amlogic,meson-gx-uart", "amlogic,meson-uart";
168 reg = <0x0 0x24000 0x0 0x14>; 168 reg = <0x0 0x24000 0x0 0x18>;
169 interrupts = <GIC_SPI 26 IRQ_TYPE_EDGE_RISING>; 169 interrupts = <GIC_SPI 26 IRQ_TYPE_EDGE_RISING>;
170 status = "disabled"; 170 status = "disabled";
171 }; 171 };
172 172
173 uart_B: serial@23000 { 173 uart_B: serial@23000 {
174 compatible = "amlogic,meson-gx-uart", "amlogic,meson-uart"; 174 compatible = "amlogic,meson-gx-uart", "amlogic,meson-uart";
175 reg = <0x0 0x23000 0x0 0x14>; 175 reg = <0x0 0x23000 0x0 0x18>;
176 interrupts = <GIC_SPI 75 IRQ_TYPE_EDGE_RISING>; 176 interrupts = <GIC_SPI 75 IRQ_TYPE_EDGE_RISING>;
177 status = "disabled"; 177 status = "disabled";
178 }; 178 };
diff --git a/arch/arm64/boot/dts/amlogic/meson-gx.dtsi b/arch/arm64/boot/dts/amlogic/meson-gx.dtsi
index 6cb3c2a52baf..4ee2e7951482 100644
--- a/arch/arm64/boot/dts/amlogic/meson-gx.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-gx.dtsi
@@ -235,14 +235,14 @@
235 235
236 uart_A: serial@84c0 { 236 uart_A: serial@84c0 {
237 compatible = "amlogic,meson-gx-uart"; 237 compatible = "amlogic,meson-gx-uart";
238 reg = <0x0 0x84c0 0x0 0x14>; 238 reg = <0x0 0x84c0 0x0 0x18>;
239 interrupts = <GIC_SPI 26 IRQ_TYPE_EDGE_RISING>; 239 interrupts = <GIC_SPI 26 IRQ_TYPE_EDGE_RISING>;
240 status = "disabled"; 240 status = "disabled";
241 }; 241 };
242 242
243 uart_B: serial@84dc { 243 uart_B: serial@84dc {
244 compatible = "amlogic,meson-gx-uart"; 244 compatible = "amlogic,meson-gx-uart";
245 reg = <0x0 0x84dc 0x0 0x14>; 245 reg = <0x0 0x84dc 0x0 0x18>;
246 interrupts = <GIC_SPI 75 IRQ_TYPE_EDGE_RISING>; 246 interrupts = <GIC_SPI 75 IRQ_TYPE_EDGE_RISING>;
247 status = "disabled"; 247 status = "disabled";
248 }; 248 };
@@ -287,7 +287,7 @@
287 287
288 uart_C: serial@8700 { 288 uart_C: serial@8700 {
289 compatible = "amlogic,meson-gx-uart"; 289 compatible = "amlogic,meson-gx-uart";
290 reg = <0x0 0x8700 0x0 0x14>; 290 reg = <0x0 0x8700 0x0 0x18>;
291 interrupts = <GIC_SPI 93 IRQ_TYPE_EDGE_RISING>; 291 interrupts = <GIC_SPI 93 IRQ_TYPE_EDGE_RISING>;
292 status = "disabled"; 292 status = "disabled";
293 }; 293 };
@@ -404,14 +404,14 @@
404 404
405 uart_AO: serial@4c0 { 405 uart_AO: serial@4c0 {
406 compatible = "amlogic,meson-gx-uart", "amlogic,meson-ao-uart"; 406 compatible = "amlogic,meson-gx-uart", "amlogic,meson-ao-uart";
407 reg = <0x0 0x004c0 0x0 0x14>; 407 reg = <0x0 0x004c0 0x0 0x18>;
408 interrupts = <GIC_SPI 193 IRQ_TYPE_EDGE_RISING>; 408 interrupts = <GIC_SPI 193 IRQ_TYPE_EDGE_RISING>;
409 status = "disabled"; 409 status = "disabled";
410 }; 410 };
411 411
412 uart_AO_B: serial@4e0 { 412 uart_AO_B: serial@4e0 {
413 compatible = "amlogic,meson-gx-uart", "amlogic,meson-ao-uart"; 413 compatible = "amlogic,meson-gx-uart", "amlogic,meson-ao-uart";
414 reg = <0x0 0x004e0 0x0 0x14>; 414 reg = <0x0 0x004e0 0x0 0x18>;
415 interrupts = <GIC_SPI 197 IRQ_TYPE_EDGE_RISING>; 415 interrupts = <GIC_SPI 197 IRQ_TYPE_EDGE_RISING>;
416 status = "disabled"; 416 status = "disabled";
417 }; 417 };
diff --git a/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi b/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi
index 4f355f17eed6..c8514110b9da 100644
--- a/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi
@@ -631,6 +631,7 @@
631 631
632 internal_phy: ethernet-phy@8 { 632 internal_phy: ethernet-phy@8 {
633 compatible = "ethernet-phy-id0181.4400", "ethernet-phy-ieee802.3-c22"; 633 compatible = "ethernet-phy-id0181.4400", "ethernet-phy-ieee802.3-c22";
634 interrupts = <GIC_SPI 9 IRQ_TYPE_LEVEL_HIGH>;
634 reg = <8>; 635 reg = <8>;
635 max-speed = <100>; 636 max-speed = <100>;
636 }; 637 };
diff --git a/arch/arm64/boot/dts/cavium/thunder2-99xx.dtsi b/arch/arm64/boot/dts/cavium/thunder2-99xx.dtsi
index 4220fbdcb24a..ff5c4c47b22b 100644
--- a/arch/arm64/boot/dts/cavium/thunder2-99xx.dtsi
+++ b/arch/arm64/boot/dts/cavium/thunder2-99xx.dtsi
@@ -98,7 +98,7 @@
98 clock-output-names = "clk125mhz"; 98 clock-output-names = "clk125mhz";
99 }; 99 };
100 100
101 pci { 101 pcie@30000000 {
102 compatible = "pci-host-ecam-generic"; 102 compatible = "pci-host-ecam-generic";
103 device_type = "pci"; 103 device_type = "pci";
104 #interrupt-cells = <1>; 104 #interrupt-cells = <1>;
@@ -118,6 +118,7 @@
118 ranges = 118 ranges =
119 <0x02000000 0 0x40000000 0 0x40000000 0 0x20000000 119 <0x02000000 0 0x40000000 0 0x40000000 0 0x20000000
120 0x43000000 0x40 0x00000000 0x40 0x00000000 0x20 0x00000000>; 120 0x43000000 0x40 0x00000000 0x40 0x00000000 0x20 0x00000000>;
121 bus-range = <0 0xff>;
121 interrupt-map-mask = <0 0 0 7>; 122 interrupt-map-mask = <0 0 0 7>;
122 interrupt-map = 123 interrupt-map =
123 /* addr pin ic icaddr icintr */ 124 /* addr pin ic icaddr icintr */
diff --git a/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts b/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
index e94fa1a53192..047641fe294c 100644
--- a/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
+++ b/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
@@ -51,7 +51,7 @@
51 #size-cells = <2>; 51 #size-cells = <2>;
52 ranges; 52 ranges;
53 53
54 ramoops@0x21f00000 { 54 ramoops@21f00000 {
55 compatible = "ramoops"; 55 compatible = "ramoops";
56 reg = <0x0 0x21f00000 0x0 0x00100000>; 56 reg = <0x0 0x21f00000 0x0 0x00100000>;
57 record-size = <0x00020000>; 57 record-size = <0x00020000>;
diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 9fbe4705ee88..94597e33c806 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -341,7 +341,7 @@
341 reg = <0 0x10005000 0 0x1000>; 341 reg = <0 0x10005000 0 0x1000>;
342 }; 342 };
343 343
344 pio: pinctrl@0x10005000 { 344 pio: pinctrl@10005000 {
345 compatible = "mediatek,mt8173-pinctrl"; 345 compatible = "mediatek,mt8173-pinctrl";
346 reg = <0 0x1000b000 0 0x1000>; 346 reg = <0 0x1000b000 0 0x1000>;
347 mediatek,pctl-regmap = <&syscfg_pctl_a>; 347 mediatek,pctl-regmap = <&syscfg_pctl_a>;
diff --git a/arch/arm64/boot/dts/qcom/apq8096-db820c.dtsi b/arch/arm64/boot/dts/qcom/apq8096-db820c.dtsi
index 492a011f14f6..1c8f1b86472d 100644
--- a/arch/arm64/boot/dts/qcom/apq8096-db820c.dtsi
+++ b/arch/arm64/boot/dts/qcom/apq8096-db820c.dtsi
@@ -140,16 +140,16 @@
140 }; 140 };
141 141
142 agnoc@0 { 142 agnoc@0 {
143 qcom,pcie@00600000 { 143 qcom,pcie@600000 {
144 perst-gpio = <&msmgpio 35 GPIO_ACTIVE_LOW>; 144 perst-gpio = <&msmgpio 35 GPIO_ACTIVE_LOW>;
145 }; 145 };
146 146
147 qcom,pcie@00608000 { 147 qcom,pcie@608000 {
148 status = "okay"; 148 status = "okay";
149 perst-gpio = <&msmgpio 130 GPIO_ACTIVE_LOW>; 149 perst-gpio = <&msmgpio 130 GPIO_ACTIVE_LOW>;
150 }; 150 };
151 151
152 qcom,pcie@00610000 { 152 qcom,pcie@610000 {
153 status = "okay"; 153 status = "okay";
154 perst-gpio = <&msmgpio 114 GPIO_ACTIVE_LOW>; 154 perst-gpio = <&msmgpio 114 GPIO_ACTIVE_LOW>;
155 }; 155 };
diff --git a/arch/arm64/boot/dts/qcom/msm8996.dtsi b/arch/arm64/boot/dts/qcom/msm8996.dtsi
index 4b2afcc4fdf4..0a6f7952bbb1 100644
--- a/arch/arm64/boot/dts/qcom/msm8996.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8996.dtsi
@@ -840,7 +840,7 @@
840 #size-cells = <1>; 840 #size-cells = <1>;
841 ranges; 841 ranges;
842 842
843 pcie0: qcom,pcie@00600000 { 843 pcie0: qcom,pcie@600000 {
844 compatible = "qcom,pcie-msm8996", "snps,dw-pcie"; 844 compatible = "qcom,pcie-msm8996", "snps,dw-pcie";
845 status = "disabled"; 845 status = "disabled";
846 power-domains = <&gcc PCIE0_GDSC>; 846 power-domains = <&gcc PCIE0_GDSC>;
@@ -893,7 +893,7 @@
893 893
894 }; 894 };
895 895
896 pcie1: qcom,pcie@00608000 { 896 pcie1: qcom,pcie@608000 {
897 compatible = "qcom,pcie-msm8996", "snps,dw-pcie"; 897 compatible = "qcom,pcie-msm8996", "snps,dw-pcie";
898 power-domains = <&gcc PCIE1_GDSC>; 898 power-domains = <&gcc PCIE1_GDSC>;
899 bus-range = <0x00 0xff>; 899 bus-range = <0x00 0xff>;
@@ -946,7 +946,7 @@
946 "bus_slave"; 946 "bus_slave";
947 }; 947 };
948 948
949 pcie2: qcom,pcie@00610000 { 949 pcie2: qcom,pcie@610000 {
950 compatible = "qcom,pcie-msm8996", "snps,dw-pcie"; 950 compatible = "qcom,pcie-msm8996", "snps,dw-pcie";
951 power-domains = <&gcc PCIE2_GDSC>; 951 power-domains = <&gcc PCIE2_GDSC>;
952 bus-range = <0x00 0xff>; 952 bus-range = <0x00 0xff>;
diff --git a/arch/arm64/boot/dts/rockchip/rk3328-rock64.dts b/arch/arm64/boot/dts/rockchip/rk3328-rock64.dts
index 3890468678ce..28257724a56e 100644
--- a/arch/arm64/boot/dts/rockchip/rk3328-rock64.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3328-rock64.dts
@@ -132,17 +132,16 @@
132 assigned-clocks = <&cru SCLK_MAC2IO>, <&cru SCLK_MAC2IO_EXT>; 132 assigned-clocks = <&cru SCLK_MAC2IO>, <&cru SCLK_MAC2IO_EXT>;
133 assigned-clock-parents = <&gmac_clkin>, <&gmac_clkin>; 133 assigned-clock-parents = <&gmac_clkin>, <&gmac_clkin>;
134 clock_in_out = "input"; 134 clock_in_out = "input";
135 /* shows instability at 1GBit right now */
136 max-speed = <100>;
137 phy-supply = <&vcc_io>; 135 phy-supply = <&vcc_io>;
138 phy-mode = "rgmii"; 136 phy-mode = "rgmii";
139 pinctrl-names = "default"; 137 pinctrl-names = "default";
140 pinctrl-0 = <&rgmiim1_pins>; 138 pinctrl-0 = <&rgmiim1_pins>;
139 snps,force_thresh_dma_mode;
141 snps,reset-gpio = <&gpio1 RK_PC2 GPIO_ACTIVE_LOW>; 140 snps,reset-gpio = <&gpio1 RK_PC2 GPIO_ACTIVE_LOW>;
142 snps,reset-active-low; 141 snps,reset-active-low;
143 snps,reset-delays-us = <0 10000 50000>; 142 snps,reset-delays-us = <0 10000 50000>;
144 tx_delay = <0x26>; 143 tx_delay = <0x24>;
145 rx_delay = <0x11>; 144 rx_delay = <0x18>;
146 status = "okay"; 145 status = "okay";
147}; 146};
148 147
diff --git a/arch/arm64/boot/dts/rockchip/rk3328.dtsi b/arch/arm64/boot/dts/rockchip/rk3328.dtsi
index a037ee56fead..cae341554486 100644
--- a/arch/arm64/boot/dts/rockchip/rk3328.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3328.dtsi
@@ -730,7 +730,7 @@
730 interrupts = <GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>; 730 interrupts = <GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>;
731 clocks = <&cru HCLK_SDMMC>, <&cru SCLK_SDMMC>, 731 clocks = <&cru HCLK_SDMMC>, <&cru SCLK_SDMMC>,
732 <&cru SCLK_SDMMC_DRV>, <&cru SCLK_SDMMC_SAMPLE>; 732 <&cru SCLK_SDMMC_DRV>, <&cru SCLK_SDMMC_SAMPLE>;
733 clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; 733 clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
734 fifo-depth = <0x100>; 734 fifo-depth = <0x100>;
735 status = "disabled"; 735 status = "disabled";
736 }; 736 };
@@ -741,7 +741,7 @@
741 interrupts = <GIC_SPI 13 IRQ_TYPE_LEVEL_HIGH>; 741 interrupts = <GIC_SPI 13 IRQ_TYPE_LEVEL_HIGH>;
742 clocks = <&cru HCLK_SDIO>, <&cru SCLK_SDIO>, 742 clocks = <&cru HCLK_SDIO>, <&cru SCLK_SDIO>,
743 <&cru SCLK_SDIO_DRV>, <&cru SCLK_SDIO_SAMPLE>; 743 <&cru SCLK_SDIO_DRV>, <&cru SCLK_SDIO_SAMPLE>;
744 clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; 744 clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
745 fifo-depth = <0x100>; 745 fifo-depth = <0x100>;
746 status = "disabled"; 746 status = "disabled";
747 }; 747 };
@@ -752,7 +752,7 @@
752 interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>; 752 interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>;
753 clocks = <&cru HCLK_EMMC>, <&cru SCLK_EMMC>, 753 clocks = <&cru HCLK_EMMC>, <&cru SCLK_EMMC>,
754 <&cru SCLK_EMMC_DRV>, <&cru SCLK_EMMC_SAMPLE>; 754 <&cru SCLK_EMMC_DRV>, <&cru SCLK_EMMC_SAMPLE>;
755 clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; 755 clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
756 fifo-depth = <0x100>; 756 fifo-depth = <0x100>;
757 status = "disabled"; 757 status = "disabled";
758 }; 758 };
diff --git a/arch/arm64/boot/dts/rockchip/rk3368.dtsi b/arch/arm64/boot/dts/rockchip/rk3368.dtsi
index aa4d07046a7b..03458ac44201 100644
--- a/arch/arm64/boot/dts/rockchip/rk3368.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3368.dtsi
@@ -257,7 +257,7 @@
257 max-frequency = <150000000>; 257 max-frequency = <150000000>;
258 clocks = <&cru HCLK_SDIO0>, <&cru SCLK_SDIO0>, 258 clocks = <&cru HCLK_SDIO0>, <&cru SCLK_SDIO0>,
259 <&cru SCLK_SDIO0_DRV>, <&cru SCLK_SDIO0_SAMPLE>; 259 <&cru SCLK_SDIO0_DRV>, <&cru SCLK_SDIO0_SAMPLE>;
260 clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; 260 clock-names = "biu", "ciu", "ciu-drive", "ciu-sample";
261 fifo-depth = <0x100>; 261 fifo-depth = <0x100>;
262 interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>; 262 interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
263 resets = <&cru SRST_SDIO0>; 263 resets = <&cru SRST_SDIO0>;
diff --git a/arch/arm64/boot/dts/rockchip/rk3399-sapphire.dtsi b/arch/arm64/boot/dts/rockchip/rk3399-sapphire.dtsi
index 0f873c897d0d..ce592a4c0c4c 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-sapphire.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399-sapphire.dtsi
@@ -457,7 +457,7 @@
457 assigned-clocks = <&cru SCLK_PCIEPHY_REF>; 457 assigned-clocks = <&cru SCLK_PCIEPHY_REF>;
458 assigned-clock-parents = <&cru SCLK_PCIEPHY_REF100M>; 458 assigned-clock-parents = <&cru SCLK_PCIEPHY_REF100M>;
459 assigned-clock-rates = <100000000>; 459 assigned-clock-rates = <100000000>;
460 ep-gpios = <&gpio3 RK_PB5 GPIO_ACTIVE_HIGH>; 460 ep-gpios = <&gpio2 RK_PA4 GPIO_ACTIVE_HIGH>;
461 num-lanes = <4>; 461 num-lanes = <4>;
462 pinctrl-names = "default"; 462 pinctrl-names = "default";
463 pinctrl-0 = <&pcie_clkreqn_cpm>; 463 pinctrl-0 = <&pcie_clkreqn_cpm>;
diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 7aa2144e0d47..2605118d4b4c 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1739,8 +1739,8 @@
1739 compatible = "rockchip,rk3399-edp"; 1739 compatible = "rockchip,rk3399-edp";
1740 reg = <0x0 0xff970000 0x0 0x8000>; 1740 reg = <0x0 0xff970000 0x0 0x8000>;
1741 interrupts = <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH 0>; 1741 interrupts = <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH 0>;
1742 clocks = <&cru PCLK_EDP>, <&cru PCLK_EDP_CTRL>; 1742 clocks = <&cru PCLK_EDP>, <&cru PCLK_EDP_CTRL>, <&cru PCLK_VIO_GRF>;
1743 clock-names = "dp", "pclk"; 1743 clock-names = "dp", "pclk", "grf";
1744 pinctrl-names = "default"; 1744 pinctrl-names = "default";
1745 pinctrl-0 = <&edp_hpd>; 1745 pinctrl-0 = <&edp_hpd>;
1746 power-domains = <&power RK3399_PD_EDP>; 1746 power-domains = <&power RK3399_PD_EDP>;
diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h
index be7bd19c87ec..350c76a1d15b 100644
--- a/arch/arm64/include/asm/cputype.h
+++ b/arch/arm64/include/asm/cputype.h
@@ -20,7 +20,7 @@
20 20
21#define MPIDR_UP_BITMASK (0x1 << 30) 21#define MPIDR_UP_BITMASK (0x1 << 30)
22#define MPIDR_MT_BITMASK (0x1 << 24) 22#define MPIDR_MT_BITMASK (0x1 << 24)
23#define MPIDR_HWID_BITMASK 0xff00ffffff 23#define MPIDR_HWID_BITMASK UL(0xff00ffffff)
24 24
25#define MPIDR_LEVEL_BITS_SHIFT 3 25#define MPIDR_LEVEL_BITS_SHIFT 3
26#define MPIDR_LEVEL_BITS (1 << MPIDR_LEVEL_BITS_SHIFT) 26#define MPIDR_LEVEL_BITS (1 << MPIDR_LEVEL_BITS_SHIFT)
diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h
index 1dca41bea16a..e73f68569624 100644
--- a/arch/arm64/include/asm/hugetlb.h
+++ b/arch/arm64/include/asm/hugetlb.h
@@ -22,7 +22,7 @@
22 22
23static inline pte_t huge_ptep_get(pte_t *ptep) 23static inline pte_t huge_ptep_get(pte_t *ptep)
24{ 24{
25 return *ptep; 25 return READ_ONCE(*ptep);
26} 26}
27 27
28 28
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 9679067a1574..7faed6e48b46 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -185,42 +185,42 @@ static inline pmd_t kvm_s2pmd_mkexec(pmd_t pmd)
185 return pmd; 185 return pmd;
186} 186}
187 187
188static inline void kvm_set_s2pte_readonly(pte_t *pte) 188static inline void kvm_set_s2pte_readonly(pte_t *ptep)
189{ 189{
190 pteval_t old_pteval, pteval; 190 pteval_t old_pteval, pteval;
191 191
192 pteval = READ_ONCE(pte_val(*pte)); 192 pteval = READ_ONCE(pte_val(*ptep));
193 do { 193 do {
194 old_pteval = pteval; 194 old_pteval = pteval;
195 pteval &= ~PTE_S2_RDWR; 195 pteval &= ~PTE_S2_RDWR;
196 pteval |= PTE_S2_RDONLY; 196 pteval |= PTE_S2_RDONLY;
197 pteval = cmpxchg_relaxed(&pte_val(*pte), old_pteval, pteval); 197 pteval = cmpxchg_relaxed(&pte_val(*ptep), old_pteval, pteval);
198 } while (pteval != old_pteval); 198 } while (pteval != old_pteval);
199} 199}
200 200
201static inline bool kvm_s2pte_readonly(pte_t *pte) 201static inline bool kvm_s2pte_readonly(pte_t *ptep)
202{ 202{
203 return (pte_val(*pte) & PTE_S2_RDWR) == PTE_S2_RDONLY; 203 return (READ_ONCE(pte_val(*ptep)) & PTE_S2_RDWR) == PTE_S2_RDONLY;
204} 204}
205 205
206static inline bool kvm_s2pte_exec(pte_t *pte) 206static inline bool kvm_s2pte_exec(pte_t *ptep)
207{ 207{
208 return !(pte_val(*pte) & PTE_S2_XN); 208 return !(READ_ONCE(pte_val(*ptep)) & PTE_S2_XN);
209} 209}
210 210
211static inline void kvm_set_s2pmd_readonly(pmd_t *pmd) 211static inline void kvm_set_s2pmd_readonly(pmd_t *pmdp)
212{ 212{
213 kvm_set_s2pte_readonly((pte_t *)pmd); 213 kvm_set_s2pte_readonly((pte_t *)pmdp);
214} 214}
215 215
216static inline bool kvm_s2pmd_readonly(pmd_t *pmd) 216static inline bool kvm_s2pmd_readonly(pmd_t *pmdp)
217{ 217{
218 return kvm_s2pte_readonly((pte_t *)pmd); 218 return kvm_s2pte_readonly((pte_t *)pmdp);
219} 219}
220 220
221static inline bool kvm_s2pmd_exec(pmd_t *pmd) 221static inline bool kvm_s2pmd_exec(pmd_t *pmdp)
222{ 222{
223 return !(pmd_val(*pmd) & PMD_S2_XN); 223 return !(READ_ONCE(pmd_val(*pmdp)) & PMD_S2_XN);
224} 224}
225 225
226static inline bool kvm_page_empty(void *ptr) 226static inline bool kvm_page_empty(void *ptr)
diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h
index 8d3331985d2e..39ec0b8a689e 100644
--- a/arch/arm64/include/asm/mmu_context.h
+++ b/arch/arm64/include/asm/mmu_context.h
@@ -141,13 +141,13 @@ static inline void cpu_install_idmap(void)
141 * Atomically replaces the active TTBR1_EL1 PGD with a new VA-compatible PGD, 141 * Atomically replaces the active TTBR1_EL1 PGD with a new VA-compatible PGD,
142 * avoiding the possibility of conflicting TLB entries being allocated. 142 * avoiding the possibility of conflicting TLB entries being allocated.
143 */ 143 */
144static inline void cpu_replace_ttbr1(pgd_t *pgd) 144static inline void cpu_replace_ttbr1(pgd_t *pgdp)
145{ 145{
146 typedef void (ttbr_replace_func)(phys_addr_t); 146 typedef void (ttbr_replace_func)(phys_addr_t);
147 extern ttbr_replace_func idmap_cpu_replace_ttbr1; 147 extern ttbr_replace_func idmap_cpu_replace_ttbr1;
148 ttbr_replace_func *replace_phys; 148 ttbr_replace_func *replace_phys;
149 149
150 phys_addr_t pgd_phys = virt_to_phys(pgd); 150 phys_addr_t pgd_phys = virt_to_phys(pgdp);
151 151
152 replace_phys = (void *)__pa_symbol(idmap_cpu_replace_ttbr1); 152 replace_phys = (void *)__pa_symbol(idmap_cpu_replace_ttbr1);
153 153
diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h
index e9d9f1b006ef..2e05bcd944c8 100644
--- a/arch/arm64/include/asm/pgalloc.h
+++ b/arch/arm64/include/asm/pgalloc.h
@@ -36,23 +36,23 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
36 return (pmd_t *)__get_free_page(PGALLOC_GFP); 36 return (pmd_t *)__get_free_page(PGALLOC_GFP);
37} 37}
38 38
39static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) 39static inline void pmd_free(struct mm_struct *mm, pmd_t *pmdp)
40{ 40{
41 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1)); 41 BUG_ON((unsigned long)pmdp & (PAGE_SIZE-1));
42 free_page((unsigned long)pmd); 42 free_page((unsigned long)pmdp);
43} 43}
44 44
45static inline void __pud_populate(pud_t *pud, phys_addr_t pmd, pudval_t prot) 45static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot)
46{ 46{
47 set_pud(pud, __pud(__phys_to_pud_val(pmd) | prot)); 47 set_pud(pudp, __pud(__phys_to_pud_val(pmdp) | prot));
48} 48}
49 49
50static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) 50static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp)
51{ 51{
52 __pud_populate(pud, __pa(pmd), PMD_TYPE_TABLE); 52 __pud_populate(pudp, __pa(pmdp), PMD_TYPE_TABLE);
53} 53}
54#else 54#else
55static inline void __pud_populate(pud_t *pud, phys_addr_t pmd, pudval_t prot) 55static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot)
56{ 56{
57 BUILD_BUG(); 57 BUILD_BUG();
58} 58}
@@ -65,30 +65,30 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
65 return (pud_t *)__get_free_page(PGALLOC_GFP); 65 return (pud_t *)__get_free_page(PGALLOC_GFP);
66} 66}
67 67
68static inline void pud_free(struct mm_struct *mm, pud_t *pud) 68static inline void pud_free(struct mm_struct *mm, pud_t *pudp)
69{ 69{
70 BUG_ON((unsigned long)pud & (PAGE_SIZE-1)); 70 BUG_ON((unsigned long)pudp & (PAGE_SIZE-1));
71 free_page((unsigned long)pud); 71 free_page((unsigned long)pudp);
72} 72}
73 73
74static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pud, pgdval_t prot) 74static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pudp, pgdval_t prot)
75{ 75{
76 set_pgd(pgdp, __pgd(__phys_to_pgd_val(pud) | prot)); 76 set_pgd(pgdp, __pgd(__phys_to_pgd_val(pudp) | prot));
77} 77}
78 78
79static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud) 79static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgdp, pud_t *pudp)
80{ 80{
81 __pgd_populate(pgd, __pa(pud), PUD_TYPE_TABLE); 81 __pgd_populate(pgdp, __pa(pudp), PUD_TYPE_TABLE);
82} 82}
83#else 83#else
84static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pud, pgdval_t prot) 84static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pudp, pgdval_t prot)
85{ 85{
86 BUILD_BUG(); 86 BUILD_BUG();
87} 87}
88#endif /* CONFIG_PGTABLE_LEVELS > 3 */ 88#endif /* CONFIG_PGTABLE_LEVELS > 3 */
89 89
90extern pgd_t *pgd_alloc(struct mm_struct *mm); 90extern pgd_t *pgd_alloc(struct mm_struct *mm);
91extern void pgd_free(struct mm_struct *mm, pgd_t *pgd); 91extern void pgd_free(struct mm_struct *mm, pgd_t *pgdp);
92 92
93static inline pte_t * 93static inline pte_t *
94pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr) 94pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
@@ -114,10 +114,10 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
114/* 114/*
115 * Free a PTE table. 115 * Free a PTE table.
116 */ 116 */
117static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) 117static inline void pte_free_kernel(struct mm_struct *mm, pte_t *ptep)
118{ 118{
119 if (pte) 119 if (ptep)
120 free_page((unsigned long)pte); 120 free_page((unsigned long)ptep);
121} 121}
122 122
123static inline void pte_free(struct mm_struct *mm, pgtable_t pte) 123static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
@@ -126,10 +126,10 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
126 __free_page(pte); 126 __free_page(pte);
127} 127}
128 128
129static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte, 129static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t ptep,
130 pmdval_t prot) 130 pmdval_t prot)
131{ 131{
132 set_pmd(pmdp, __pmd(__phys_to_pmd_val(pte) | prot)); 132 set_pmd(pmdp, __pmd(__phys_to_pmd_val(ptep) | prot));
133} 133}
134 134
135/* 135/*
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 094374c82db0..7e2c27e63cd8 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -218,7 +218,7 @@ static inline pmd_t pmd_mkcont(pmd_t pmd)
218 218
219static inline void set_pte(pte_t *ptep, pte_t pte) 219static inline void set_pte(pte_t *ptep, pte_t pte)
220{ 220{
221 *ptep = pte; 221 WRITE_ONCE(*ptep, pte);
222 222
223 /* 223 /*
224 * Only if the new pte is valid and kernel, otherwise TLB maintenance 224 * Only if the new pte is valid and kernel, otherwise TLB maintenance
@@ -250,6 +250,8 @@ extern void __sync_icache_dcache(pte_t pteval, unsigned long addr);
250static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, 250static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
251 pte_t *ptep, pte_t pte) 251 pte_t *ptep, pte_t pte)
252{ 252{
253 pte_t old_pte;
254
253 if (pte_present(pte) && pte_user_exec(pte) && !pte_special(pte)) 255 if (pte_present(pte) && pte_user_exec(pte) && !pte_special(pte))
254 __sync_icache_dcache(pte, addr); 256 __sync_icache_dcache(pte, addr);
255 257
@@ -258,14 +260,15 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
258 * hardware updates of the pte (ptep_set_access_flags safely changes 260 * hardware updates of the pte (ptep_set_access_flags safely changes
259 * valid ptes without going through an invalid entry). 261 * valid ptes without going through an invalid entry).
260 */ 262 */
261 if (IS_ENABLED(CONFIG_DEBUG_VM) && pte_valid(*ptep) && pte_valid(pte) && 263 old_pte = READ_ONCE(*ptep);
264 if (IS_ENABLED(CONFIG_DEBUG_VM) && pte_valid(old_pte) && pte_valid(pte) &&
262 (mm == current->active_mm || atomic_read(&mm->mm_users) > 1)) { 265 (mm == current->active_mm || atomic_read(&mm->mm_users) > 1)) {
263 VM_WARN_ONCE(!pte_young(pte), 266 VM_WARN_ONCE(!pte_young(pte),
264 "%s: racy access flag clearing: 0x%016llx -> 0x%016llx", 267 "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
265 __func__, pte_val(*ptep), pte_val(pte)); 268 __func__, pte_val(old_pte), pte_val(pte));
266 VM_WARN_ONCE(pte_write(*ptep) && !pte_dirty(pte), 269 VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
267 "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx", 270 "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
268 __func__, pte_val(*ptep), pte_val(pte)); 271 __func__, pte_val(old_pte), pte_val(pte));
269 } 272 }
270 273
271 set_pte(ptep, pte); 274 set_pte(ptep, pte);
@@ -431,7 +434,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
431 434
432static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) 435static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
433{ 436{
434 *pmdp = pmd; 437 WRITE_ONCE(*pmdp, pmd);
435 dsb(ishst); 438 dsb(ishst);
436 isb(); 439 isb();
437} 440}
@@ -482,7 +485,7 @@ static inline phys_addr_t pmd_page_paddr(pmd_t pmd)
482 485
483static inline void set_pud(pud_t *pudp, pud_t pud) 486static inline void set_pud(pud_t *pudp, pud_t pud)
484{ 487{
485 *pudp = pud; 488 WRITE_ONCE(*pudp, pud);
486 dsb(ishst); 489 dsb(ishst);
487 isb(); 490 isb();
488} 491}
@@ -500,7 +503,7 @@ static inline phys_addr_t pud_page_paddr(pud_t pud)
500/* Find an entry in the second-level page table. */ 503/* Find an entry in the second-level page table. */
501#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)) 504#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
502 505
503#define pmd_offset_phys(dir, addr) (pud_page_paddr(*(dir)) + pmd_index(addr) * sizeof(pmd_t)) 506#define pmd_offset_phys(dir, addr) (pud_page_paddr(READ_ONCE(*(dir))) + pmd_index(addr) * sizeof(pmd_t))
504#define pmd_offset(dir, addr) ((pmd_t *)__va(pmd_offset_phys((dir), (addr)))) 507#define pmd_offset(dir, addr) ((pmd_t *)__va(pmd_offset_phys((dir), (addr))))
505 508
506#define pmd_set_fixmap(addr) ((pmd_t *)set_fixmap_offset(FIX_PMD, addr)) 509#define pmd_set_fixmap(addr) ((pmd_t *)set_fixmap_offset(FIX_PMD, addr))
@@ -535,7 +538,7 @@ static inline phys_addr_t pud_page_paddr(pud_t pud)
535 538
536static inline void set_pgd(pgd_t *pgdp, pgd_t pgd) 539static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
537{ 540{
538 *pgdp = pgd; 541 WRITE_ONCE(*pgdp, pgd);
539 dsb(ishst); 542 dsb(ishst);
540} 543}
541 544
@@ -552,7 +555,7 @@ static inline phys_addr_t pgd_page_paddr(pgd_t pgd)
552/* Find an entry in the frst-level page table. */ 555/* Find an entry in the frst-level page table. */
553#define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1)) 556#define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
554 557
555#define pud_offset_phys(dir, addr) (pgd_page_paddr(*(dir)) + pud_index(addr) * sizeof(pud_t)) 558#define pud_offset_phys(dir, addr) (pgd_page_paddr(READ_ONCE(*(dir))) + pud_index(addr) * sizeof(pud_t))
556#define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr)))) 559#define pud_offset(dir, addr) ((pud_t *)__va(pud_offset_phys((dir), (addr))))
557 560
558#define pud_set_fixmap(addr) ((pud_t *)set_fixmap_offset(FIX_PUD, addr)) 561#define pud_set_fixmap(addr) ((pud_t *)set_fixmap_offset(FIX_PUD, addr))
diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h
index 472ef944e932..902f9edacbea 100644
--- a/arch/arm64/include/asm/stacktrace.h
+++ b/arch/arm64/include/asm/stacktrace.h
@@ -28,7 +28,7 @@ struct stackframe {
28 unsigned long fp; 28 unsigned long fp;
29 unsigned long pc; 29 unsigned long pc;
30#ifdef CONFIG_FUNCTION_GRAPH_TRACER 30#ifdef CONFIG_FUNCTION_GRAPH_TRACER
31 unsigned int graph; 31 int graph;
32#endif 32#endif
33}; 33};
34 34
diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
index 543e11f0f657..e66b0fca99c2 100644
--- a/arch/arm64/include/asm/uaccess.h
+++ b/arch/arm64/include/asm/uaccess.h
@@ -72,15 +72,15 @@ static inline void set_fs(mm_segment_t fs)
72 * This is equivalent to the following test: 72 * This is equivalent to the following test:
73 * (u65)addr + (u65)size <= (u65)current->addr_limit + 1 73 * (u65)addr + (u65)size <= (u65)current->addr_limit + 1
74 */ 74 */
75static inline unsigned long __range_ok(unsigned long addr, unsigned long size) 75static inline unsigned long __range_ok(const void __user *addr, unsigned long size)
76{ 76{
77 unsigned long limit = current_thread_info()->addr_limit; 77 unsigned long ret, limit = current_thread_info()->addr_limit;
78 78
79 __chk_user_ptr(addr); 79 __chk_user_ptr(addr);
80 asm volatile( 80 asm volatile(
81 // A + B <= C + 1 for all A,B,C, in four easy steps: 81 // A + B <= C + 1 for all A,B,C, in four easy steps:
82 // 1: X = A + B; X' = X % 2^64 82 // 1: X = A + B; X' = X % 2^64
83 " adds %0, %0, %2\n" 83 " adds %0, %3, %2\n"
84 // 2: Set C = 0 if X > 2^64, to guarantee X' > C in step 4 84 // 2: Set C = 0 if X > 2^64, to guarantee X' > C in step 4
85 " csel %1, xzr, %1, hi\n" 85 " csel %1, xzr, %1, hi\n"
86 // 3: Set X' = ~0 if X >= 2^64. For X == 2^64, this decrements X' 86 // 3: Set X' = ~0 if X >= 2^64. For X == 2^64, this decrements X'
@@ -92,9 +92,9 @@ static inline unsigned long __range_ok(unsigned long addr, unsigned long size)
92 // testing X' - C == 0, subject to the previous adjustments. 92 // testing X' - C == 0, subject to the previous adjustments.
93 " sbcs xzr, %0, %1\n" 93 " sbcs xzr, %0, %1\n"
94 " cset %0, ls\n" 94 " cset %0, ls\n"
95 : "+r" (addr), "+r" (limit) : "Ir" (size) : "cc"); 95 : "=&r" (ret), "+r" (limit) : "Ir" (size), "0" (addr) : "cc");
96 96
97 return addr; 97 return ret;
98} 98}
99 99
100/* 100/*
@@ -104,7 +104,7 @@ static inline unsigned long __range_ok(unsigned long addr, unsigned long size)
104 */ 104 */
105#define untagged_addr(addr) sign_extend64(addr, 55) 105#define untagged_addr(addr) sign_extend64(addr, 55)
106 106
107#define access_ok(type, addr, size) __range_ok((unsigned long)(addr), size) 107#define access_ok(type, addr, size) __range_ok(addr, size)
108#define user_addr_max get_fs 108#define user_addr_max get_fs
109 109
110#define _ASM_EXTABLE(from, to) \ 110#define _ASM_EXTABLE(from, to) \
diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
index c33b5e4010ab..68450e954d47 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -370,6 +370,7 @@ static unsigned int __kprobes aarch32_check_condition(u32 opcode, u32 psr)
370static int swp_handler(struct pt_regs *regs, u32 instr) 370static int swp_handler(struct pt_regs *regs, u32 instr)
371{ 371{
372 u32 destreg, data, type, address = 0; 372 u32 destreg, data, type, address = 0;
373 const void __user *user_ptr;
373 int rn, rt2, res = 0; 374 int rn, rt2, res = 0;
374 375
375 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, regs->pc); 376 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, regs->pc);
@@ -401,7 +402,8 @@ static int swp_handler(struct pt_regs *regs, u32 instr)
401 aarch32_insn_extract_reg_num(instr, A32_RT2_OFFSET), data); 402 aarch32_insn_extract_reg_num(instr, A32_RT2_OFFSET), data);
402 403
403 /* Check access in reasonable access range for both SWP and SWPB */ 404 /* Check access in reasonable access range for both SWP and SWPB */
404 if (!access_ok(VERIFY_WRITE, (address & ~3), 4)) { 405 user_ptr = (const void __user *)(unsigned long)(address & ~3);
406 if (!access_ok(VERIFY_WRITE, user_ptr, 4)) {
405 pr_debug("SWP{B} emulation: access to 0x%08x not allowed!\n", 407 pr_debug("SWP{B} emulation: access to 0x%08x not allowed!\n",
406 address); 408 address);
407 goto fault; 409 goto fault;
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
index 07823595b7f0..b5a28336c077 100644
--- a/arch/arm64/kernel/cpu_errata.c
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -178,7 +178,7 @@ static int enable_smccc_arch_workaround_1(void *data)
178 case PSCI_CONDUIT_HVC: 178 case PSCI_CONDUIT_HVC:
179 arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, 179 arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
180 ARM_SMCCC_ARCH_WORKAROUND_1, &res); 180 ARM_SMCCC_ARCH_WORKAROUND_1, &res);
181 if (res.a0) 181 if ((int)res.a0 < 0)
182 return 0; 182 return 0;
183 cb = call_hvc_arch_workaround_1; 183 cb = call_hvc_arch_workaround_1;
184 smccc_start = __smccc_workaround_1_hvc_start; 184 smccc_start = __smccc_workaround_1_hvc_start;
@@ -188,7 +188,7 @@ static int enable_smccc_arch_workaround_1(void *data)
188 case PSCI_CONDUIT_SMC: 188 case PSCI_CONDUIT_SMC:
189 arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, 189 arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
190 ARM_SMCCC_ARCH_WORKAROUND_1, &res); 190 ARM_SMCCC_ARCH_WORKAROUND_1, &res);
191 if (res.a0) 191 if ((int)res.a0 < 0)
192 return 0; 192 return 0;
193 cb = call_smc_arch_workaround_1; 193 cb = call_smc_arch_workaround_1;
194 smccc_start = __smccc_workaround_1_smc_start; 194 smccc_start = __smccc_workaround_1_smc_start;
@@ -408,6 +408,15 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
408 }, 408 },
409 { 409 {
410 .capability = ARM64_HARDEN_BRANCH_PREDICTOR, 410 .capability = ARM64_HARDEN_BRANCH_PREDICTOR,
411 MIDR_ALL_VERSIONS(MIDR_QCOM_FALKOR),
412 .enable = qcom_enable_link_stack_sanitization,
413 },
414 {
415 .capability = ARM64_HARDEN_BP_POST_GUEST_EXIT,
416 MIDR_ALL_VERSIONS(MIDR_QCOM_FALKOR),
417 },
418 {
419 .capability = ARM64_HARDEN_BRANCH_PREDICTOR,
411 MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), 420 MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN),
412 .enable = enable_smccc_arch_workaround_1, 421 .enable = enable_smccc_arch_workaround_1,
413 }, 422 },
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 29b1f873e337..2985a067fc13 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -199,9 +199,11 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr2[] = {
199}; 199};
200 200
201static const struct arm64_ftr_bits ftr_ctr[] = { 201static const struct arm64_ftr_bits ftr_ctr[] = {
202 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, 31, 1, 1), /* RAO */ 202 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, 31, 1, 1), /* RES1 */
203 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 29, 1, 1), /* DIC */
204 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 28, 1, 1), /* IDC */
203 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_HIGHER_SAFE, 24, 4, 0), /* CWG */ 205 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_HIGHER_SAFE, 24, 4, 0), /* CWG */
204 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 20, 4, 0), /* ERG */ 206 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_HIGHER_SAFE, 20, 4, 0), /* ERG */
205 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 16, 4, 1), /* DminLine */ 207 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 16, 4, 1), /* DminLine */
206 /* 208 /*
207 * Linux can handle differing I-cache policies. Userspace JITs will 209 * Linux can handle differing I-cache policies. Userspace JITs will
diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
index f85ac58d08a3..a8bf1c892b90 100644
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -90,7 +90,7 @@ static int __init set_permissions(pte_t *ptep, pgtable_t token,
90 unsigned long addr, void *data) 90 unsigned long addr, void *data)
91{ 91{
92 efi_memory_desc_t *md = data; 92 efi_memory_desc_t *md = data;
93 pte_t pte = *ptep; 93 pte_t pte = READ_ONCE(*ptep);
94 94
95 if (md->attribute & EFI_MEMORY_RO) 95 if (md->attribute & EFI_MEMORY_RO)
96 pte = set_pte_bit(pte, __pgprot(PTE_RDONLY)); 96 pte = set_pte_bit(pte, __pgprot(PTE_RDONLY));
diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
index f20cf7e99249..1ec5f28c39fc 100644
--- a/arch/arm64/kernel/hibernate.c
+++ b/arch/arm64/kernel/hibernate.c
@@ -202,10 +202,10 @@ static int create_safe_exec_page(void *src_start, size_t length,
202 gfp_t mask) 202 gfp_t mask)
203{ 203{
204 int rc = 0; 204 int rc = 0;
205 pgd_t *pgd; 205 pgd_t *pgdp;
206 pud_t *pud; 206 pud_t *pudp;
207 pmd_t *pmd; 207 pmd_t *pmdp;
208 pte_t *pte; 208 pte_t *ptep;
209 unsigned long dst = (unsigned long)allocator(mask); 209 unsigned long dst = (unsigned long)allocator(mask);
210 210
211 if (!dst) { 211 if (!dst) {
@@ -216,38 +216,38 @@ static int create_safe_exec_page(void *src_start, size_t length,
216 memcpy((void *)dst, src_start, length); 216 memcpy((void *)dst, src_start, length);
217 flush_icache_range(dst, dst + length); 217 flush_icache_range(dst, dst + length);
218 218
219 pgd = pgd_offset_raw(allocator(mask), dst_addr); 219 pgdp = pgd_offset_raw(allocator(mask), dst_addr);
220 if (pgd_none(*pgd)) { 220 if (pgd_none(READ_ONCE(*pgdp))) {
221 pud = allocator(mask); 221 pudp = allocator(mask);
222 if (!pud) { 222 if (!pudp) {
223 rc = -ENOMEM; 223 rc = -ENOMEM;
224 goto out; 224 goto out;
225 } 225 }
226 pgd_populate(&init_mm, pgd, pud); 226 pgd_populate(&init_mm, pgdp, pudp);
227 } 227 }
228 228
229 pud = pud_offset(pgd, dst_addr); 229 pudp = pud_offset(pgdp, dst_addr);
230 if (pud_none(*pud)) { 230 if (pud_none(READ_ONCE(*pudp))) {
231 pmd = allocator(mask); 231 pmdp = allocator(mask);
232 if (!pmd) { 232 if (!pmdp) {
233 rc = -ENOMEM; 233 rc = -ENOMEM;
234 goto out; 234 goto out;
235 } 235 }
236 pud_populate(&init_mm, pud, pmd); 236 pud_populate(&init_mm, pudp, pmdp);
237 } 237 }
238 238
239 pmd = pmd_offset(pud, dst_addr); 239 pmdp = pmd_offset(pudp, dst_addr);
240 if (pmd_none(*pmd)) { 240 if (pmd_none(READ_ONCE(*pmdp))) {
241 pte = allocator(mask); 241 ptep = allocator(mask);
242 if (!pte) { 242 if (!ptep) {
243 rc = -ENOMEM; 243 rc = -ENOMEM;
244 goto out; 244 goto out;
245 } 245 }
246 pmd_populate_kernel(&init_mm, pmd, pte); 246 pmd_populate_kernel(&init_mm, pmdp, ptep);
247 } 247 }
248 248
249 pte = pte_offset_kernel(pmd, dst_addr); 249 ptep = pte_offset_kernel(pmdp, dst_addr);
250 set_pte(pte, pfn_pte(virt_to_pfn(dst), PAGE_KERNEL_EXEC)); 250 set_pte(ptep, pfn_pte(virt_to_pfn(dst), PAGE_KERNEL_EXEC));
251 251
252 /* 252 /*
253 * Load our new page tables. A strict BBM approach requires that we 253 * Load our new page tables. A strict BBM approach requires that we
@@ -263,7 +263,7 @@ static int create_safe_exec_page(void *src_start, size_t length,
263 */ 263 */
264 cpu_set_reserved_ttbr0(); 264 cpu_set_reserved_ttbr0();
265 local_flush_tlb_all(); 265 local_flush_tlb_all();
266 write_sysreg(phys_to_ttbr(virt_to_phys(pgd)), ttbr0_el1); 266 write_sysreg(phys_to_ttbr(virt_to_phys(pgdp)), ttbr0_el1);
267 isb(); 267 isb();
268 268
269 *phys_dst_addr = virt_to_phys((void *)dst); 269 *phys_dst_addr = virt_to_phys((void *)dst);
@@ -320,9 +320,9 @@ int swsusp_arch_suspend(void)
320 return ret; 320 return ret;
321} 321}
322 322
323static void _copy_pte(pte_t *dst_pte, pte_t *src_pte, unsigned long addr) 323static void _copy_pte(pte_t *dst_ptep, pte_t *src_ptep, unsigned long addr)
324{ 324{
325 pte_t pte = *src_pte; 325 pte_t pte = READ_ONCE(*src_ptep);
326 326
327 if (pte_valid(pte)) { 327 if (pte_valid(pte)) {
328 /* 328 /*
@@ -330,7 +330,7 @@ static void _copy_pte(pte_t *dst_pte, pte_t *src_pte, unsigned long addr)
330 * read only (code, rodata). Clear the RDONLY bit from 330 * read only (code, rodata). Clear the RDONLY bit from
331 * the temporary mappings we use during restore. 331 * the temporary mappings we use during restore.
332 */ 332 */
333 set_pte(dst_pte, pte_mkwrite(pte)); 333 set_pte(dst_ptep, pte_mkwrite(pte));
334 } else if (debug_pagealloc_enabled() && !pte_none(pte)) { 334 } else if (debug_pagealloc_enabled() && !pte_none(pte)) {
335 /* 335 /*
336 * debug_pagealloc will removed the PTE_VALID bit if 336 * debug_pagealloc will removed the PTE_VALID bit if
@@ -343,112 +343,116 @@ static void _copy_pte(pte_t *dst_pte, pte_t *src_pte, unsigned long addr)
343 */ 343 */
344 BUG_ON(!pfn_valid(pte_pfn(pte))); 344 BUG_ON(!pfn_valid(pte_pfn(pte)));
345 345
346 set_pte(dst_pte, pte_mkpresent(pte_mkwrite(pte))); 346 set_pte(dst_ptep, pte_mkpresent(pte_mkwrite(pte)));
347 } 347 }
348} 348}
349 349
350static int copy_pte(pmd_t *dst_pmd, pmd_t *src_pmd, unsigned long start, 350static int copy_pte(pmd_t *dst_pmdp, pmd_t *src_pmdp, unsigned long start,
351 unsigned long end) 351 unsigned long end)
352{ 352{
353 pte_t *src_pte; 353 pte_t *src_ptep;
354 pte_t *dst_pte; 354 pte_t *dst_ptep;
355 unsigned long addr = start; 355 unsigned long addr = start;
356 356
357 dst_pte = (pte_t *)get_safe_page(GFP_ATOMIC); 357 dst_ptep = (pte_t *)get_safe_page(GFP_ATOMIC);
358 if (!dst_pte) 358 if (!dst_ptep)
359 return -ENOMEM; 359 return -ENOMEM;
360 pmd_populate_kernel(&init_mm, dst_pmd, dst_pte); 360 pmd_populate_kernel(&init_mm, dst_pmdp, dst_ptep);
361 dst_pte = pte_offset_kernel(dst_pmd, start); 361 dst_ptep = pte_offset_kernel(dst_pmdp, start);
362 362
363 src_pte = pte_offset_kernel(src_pmd, start); 363 src_ptep = pte_offset_kernel(src_pmdp, start);
364 do { 364 do {
365 _copy_pte(dst_pte, src_pte, addr); 365 _copy_pte(dst_ptep, src_ptep, addr);
366 } while (dst_pte++, src_pte++, addr += PAGE_SIZE, addr != end); 366 } while (dst_ptep++, src_ptep++, addr += PAGE_SIZE, addr != end);
367 367
368 return 0; 368 return 0;
369} 369}
370 370
371static int copy_pmd(pud_t *dst_pud, pud_t *src_pud, unsigned long start, 371static int copy_pmd(pud_t *dst_pudp, pud_t *src_pudp, unsigned long start,
372 unsigned long end) 372 unsigned long end)
373{ 373{
374 pmd_t *src_pmd; 374 pmd_t *src_pmdp;
375 pmd_t *dst_pmd; 375 pmd_t *dst_pmdp;
376 unsigned long next; 376 unsigned long next;
377 unsigned long addr = start; 377 unsigned long addr = start;
378 378
379 if (pud_none(*dst_pud)) { 379 if (pud_none(READ_ONCE(*dst_pudp))) {
380 dst_pmd = (pmd_t *)get_safe_page(GFP_ATOMIC); 380 dst_pmdp = (pmd_t *)get_safe_page(GFP_ATOMIC);
381 if (!dst_pmd) 381 if (!dst_pmdp)
382 return -ENOMEM; 382 return -ENOMEM;
383 pud_populate(&init_mm, dst_pud, dst_pmd); 383 pud_populate(&init_mm, dst_pudp, dst_pmdp);
384 } 384 }
385 dst_pmd = pmd_offset(dst_pud, start); 385 dst_pmdp = pmd_offset(dst_pudp, start);
386 386
387 src_pmd = pmd_offset(src_pud, start); 387 src_pmdp = pmd_offset(src_pudp, start);
388 do { 388 do {
389 pmd_t pmd = READ_ONCE(*src_pmdp);
390
389 next = pmd_addr_end(addr, end); 391 next = pmd_addr_end(addr, end);
390 if (pmd_none(*src_pmd)) 392 if (pmd_none(pmd))
391 continue; 393 continue;
392 if (pmd_table(*src_pmd)) { 394 if (pmd_table(pmd)) {
393 if (copy_pte(dst_pmd, src_pmd, addr, next)) 395 if (copy_pte(dst_pmdp, src_pmdp, addr, next))
394 return -ENOMEM; 396 return -ENOMEM;
395 } else { 397 } else {
396 set_pmd(dst_pmd, 398 set_pmd(dst_pmdp,
397 __pmd(pmd_val(*src_pmd) & ~PMD_SECT_RDONLY)); 399 __pmd(pmd_val(pmd) & ~PMD_SECT_RDONLY));
398 } 400 }
399 } while (dst_pmd++, src_pmd++, addr = next, addr != end); 401 } while (dst_pmdp++, src_pmdp++, addr = next, addr != end);
400 402
401 return 0; 403 return 0;
402} 404}
403 405
404static int copy_pud(pgd_t *dst_pgd, pgd_t *src_pgd, unsigned long start, 406static int copy_pud(pgd_t *dst_pgdp, pgd_t *src_pgdp, unsigned long start,
405 unsigned long end) 407 unsigned long end)
406{ 408{
407 pud_t *dst_pud; 409 pud_t *dst_pudp;
408 pud_t *src_pud; 410 pud_t *src_pudp;
409 unsigned long next; 411 unsigned long next;
410 unsigned long addr = start; 412 unsigned long addr = start;
411 413
412 if (pgd_none(*dst_pgd)) { 414 if (pgd_none(READ_ONCE(*dst_pgdp))) {
413 dst_pud = (pud_t *)get_safe_page(GFP_ATOMIC); 415 dst_pudp = (pud_t *)get_safe_page(GFP_ATOMIC);
414 if (!dst_pud) 416 if (!dst_pudp)
415 return -ENOMEM; 417 return -ENOMEM;
416 pgd_populate(&init_mm, dst_pgd, dst_pud); 418 pgd_populate(&init_mm, dst_pgdp, dst_pudp);
417 } 419 }
418 dst_pud = pud_offset(dst_pgd, start); 420 dst_pudp = pud_offset(dst_pgdp, start);
419 421
420 src_pud = pud_offset(src_pgd, start); 422 src_pudp = pud_offset(src_pgdp, start);
421 do { 423 do {
424 pud_t pud = READ_ONCE(*src_pudp);
425
422 next = pud_addr_end(addr, end); 426 next = pud_addr_end(addr, end);
423 if (pud_none(*src_pud)) 427 if (pud_none(pud))
424 continue; 428 continue;
425 if (pud_table(*(src_pud))) { 429 if (pud_table(pud)) {
426 if (copy_pmd(dst_pud, src_pud, addr, next)) 430 if (copy_pmd(dst_pudp, src_pudp, addr, next))
427 return -ENOMEM; 431 return -ENOMEM;
428 } else { 432 } else {
429 set_pud(dst_pud, 433 set_pud(dst_pudp,
430 __pud(pud_val(*src_pud) & ~PMD_SECT_RDONLY)); 434 __pud(pud_val(pud) & ~PMD_SECT_RDONLY));
431 } 435 }
432 } while (dst_pud++, src_pud++, addr = next, addr != end); 436 } while (dst_pudp++, src_pudp++, addr = next, addr != end);
433 437
434 return 0; 438 return 0;
435} 439}
436 440
437static int copy_page_tables(pgd_t *dst_pgd, unsigned long start, 441static int copy_page_tables(pgd_t *dst_pgdp, unsigned long start,
438 unsigned long end) 442 unsigned long end)
439{ 443{
440 unsigned long next; 444 unsigned long next;
441 unsigned long addr = start; 445 unsigned long addr = start;
442 pgd_t *src_pgd = pgd_offset_k(start); 446 pgd_t *src_pgdp = pgd_offset_k(start);
443 447
444 dst_pgd = pgd_offset_raw(dst_pgd, start); 448 dst_pgdp = pgd_offset_raw(dst_pgdp, start);
445 do { 449 do {
446 next = pgd_addr_end(addr, end); 450 next = pgd_addr_end(addr, end);
447 if (pgd_none(*src_pgd)) 451 if (pgd_none(READ_ONCE(*src_pgdp)))
448 continue; 452 continue;
449 if (copy_pud(dst_pgd, src_pgd, addr, next)) 453 if (copy_pud(dst_pgdp, src_pgdp, addr, next))
450 return -ENOMEM; 454 return -ENOMEM;
451 } while (dst_pgd++, src_pgd++, addr = next, addr != end); 455 } while (dst_pgdp++, src_pgdp++, addr = next, addr != end);
452 456
453 return 0; 457 return 0;
454} 458}
diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index 75b220ba73a3..85a251b6dfa8 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -908,9 +908,9 @@ static void __armv8pmu_probe_pmu(void *info)
908 int pmuver; 908 int pmuver;
909 909
910 dfr0 = read_sysreg(id_aa64dfr0_el1); 910 dfr0 = read_sysreg(id_aa64dfr0_el1);
911 pmuver = cpuid_feature_extract_signed_field(dfr0, 911 pmuver = cpuid_feature_extract_unsigned_field(dfr0,
912 ID_AA64DFR0_PMUVER_SHIFT); 912 ID_AA64DFR0_PMUVER_SHIFT);
913 if (pmuver < 1) 913 if (pmuver == 0xf || pmuver == 0)
914 return; 914 return;
915 915
916 probe->present = true; 916 probe->present = true;
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index ad8aeb098b31..c0da6efe5465 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -220,8 +220,15 @@ void __show_regs(struct pt_regs *regs)
220 220
221 show_regs_print_info(KERN_DEFAULT); 221 show_regs_print_info(KERN_DEFAULT);
222 print_pstate(regs); 222 print_pstate(regs);
223 printk("pc : %pS\n", (void *)regs->pc); 223
224 printk("lr : %pS\n", (void *)lr); 224 if (!user_mode(regs)) {
225 printk("pc : %pS\n", (void *)regs->pc);
226 printk("lr : %pS\n", (void *)lr);
227 } else {
228 printk("pc : %016llx\n", regs->pc);
229 printk("lr : %016llx\n", lr);
230 }
231
225 printk("sp : %016llx\n", sp); 232 printk("sp : %016llx\n", sp);
226 233
227 i = top_reg; 234 i = top_reg;
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index 6618036ae6d4..9ae31f7e2243 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -1419,7 +1419,7 @@ static int compat_ptrace_hbp_get(unsigned int note_type,
1419 u64 addr = 0; 1419 u64 addr = 0;
1420 u32 ctrl = 0; 1420 u32 ctrl = 0;
1421 1421
1422 int err, idx = compat_ptrace_hbp_num_to_idx(num);; 1422 int err, idx = compat_ptrace_hbp_num_to_idx(num);
1423 1423
1424 if (num & 1) { 1424 if (num & 1) {
1425 err = ptrace_hbp_get_addr(note_type, tsk, idx, &addr); 1425 err = ptrace_hbp_get_addr(note_type, tsk, idx, &addr);
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 76809ccd309c..d5718a060672 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -59,6 +59,11 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame)
59#ifdef CONFIG_FUNCTION_GRAPH_TRACER 59#ifdef CONFIG_FUNCTION_GRAPH_TRACER
60 if (tsk->ret_stack && 60 if (tsk->ret_stack &&
61 (frame->pc == (unsigned long)return_to_handler)) { 61 (frame->pc == (unsigned long)return_to_handler)) {
62 if (WARN_ON_ONCE(frame->graph == -1))
63 return -EINVAL;
64 if (frame->graph < -1)
65 frame->graph += FTRACE_NOTRACE_DEPTH;
66
62 /* 67 /*
63 * This is a case where function graph tracer has 68 * This is a case where function graph tracer has
64 * modified a return address (LR) in a stack frame 69 * modified a return address (LR) in a stack frame
diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
index 8b8bbd3eaa52..a382b2a1b84e 100644
--- a/arch/arm64/kernel/sys_compat.c
+++ b/arch/arm64/kernel/sys_compat.c
@@ -57,7 +57,7 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags)
57 if (end < start || flags) 57 if (end < start || flags)
58 return -EINVAL; 58 return -EINVAL;
59 59
60 if (!access_ok(VERIFY_READ, start, end - start)) 60 if (!access_ok(VERIFY_READ, (const void __user *)start, end - start))
61 return -EFAULT; 61 return -EFAULT;
62 62
63 return __do_compat_cache_op(start, end); 63 return __do_compat_cache_op(start, end);
diff --git a/arch/arm64/kernel/time.c b/arch/arm64/kernel/time.c
index a4391280fba9..f258636273c9 100644
--- a/arch/arm64/kernel/time.c
+++ b/arch/arm64/kernel/time.c
@@ -52,7 +52,7 @@ unsigned long profile_pc(struct pt_regs *regs)
52 frame.fp = regs->regs[29]; 52 frame.fp = regs->regs[29];
53 frame.pc = regs->pc; 53 frame.pc = regs->pc;
54#ifdef CONFIG_FUNCTION_GRAPH_TRACER 54#ifdef CONFIG_FUNCTION_GRAPH_TRACER
55 frame.graph = -1; /* no task info */ 55 frame.graph = current->curr_ret_stack;
56#endif 56#endif
57 do { 57 do {
58 int ret = unwind_frame(NULL, &frame); 58 int ret = unwind_frame(NULL, &frame);
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index bbb0fde2780e..eb2d15147e8d 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -57,7 +57,7 @@ static const char *handler[]= {
57 "Error" 57 "Error"
58}; 58};
59 59
60int show_unhandled_signals = 1; 60int show_unhandled_signals = 0;
61 61
62static void dump_backtrace_entry(unsigned long where) 62static void dump_backtrace_entry(unsigned long where)
63{ 63{
@@ -526,14 +526,6 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs)
526 } 526 }
527#endif 527#endif
528 528
529 if (show_unhandled_signals_ratelimited()) {
530 pr_info("%s[%d]: syscall %d\n", current->comm,
531 task_pid_nr(current), regs->syscallno);
532 dump_instr("", regs);
533 if (user_mode(regs))
534 __show_regs(regs);
535 }
536
537 return sys_ni_syscall(); 529 return sys_ni_syscall();
538} 530}
539 531
diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
index d7e3299a7734..959e50d2588c 100644
--- a/arch/arm64/kvm/guest.c
+++ b/arch/arm64/kvm/guest.c
@@ -363,8 +363,6 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
363{ 363{
364 int ret = 0; 364 int ret = 0;
365 365
366 vcpu_load(vcpu);
367
368 trace_kvm_set_guest_debug(vcpu, dbg->control); 366 trace_kvm_set_guest_debug(vcpu, dbg->control);
369 367
370 if (dbg->control & ~KVM_GUESTDBG_VALID_MASK) { 368 if (dbg->control & ~KVM_GUESTDBG_VALID_MASK) {
@@ -386,7 +384,6 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
386 } 384 }
387 385
388out: 386out:
389 vcpu_put(vcpu);
390 return ret; 387 return ret;
391} 388}
392 389
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index 116252a8d3a5..870f4b1587f9 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -407,8 +407,10 @@ again:
407 u32 midr = read_cpuid_id(); 407 u32 midr = read_cpuid_id();
408 408
409 /* Apply BTAC predictors mitigation to all Falkor chips */ 409 /* Apply BTAC predictors mitigation to all Falkor chips */
410 if ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1) 410 if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) ||
411 ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1)) {
411 __qcom_hyp_sanitize_btac_predictors(); 412 __qcom_hyp_sanitize_btac_predictors();
413 }
412 } 414 }
413 415
414 fp_enabled = __fpsimd_enabled(); 416 fp_enabled = __fpsimd_enabled();
diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c
index 7b60d62ac593..65dfc8571bf8 100644
--- a/arch/arm64/mm/dump.c
+++ b/arch/arm64/mm/dump.c
@@ -286,48 +286,52 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level,
286 286
287} 287}
288 288
289static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start) 289static void walk_pte(struct pg_state *st, pmd_t *pmdp, unsigned long start)
290{ 290{
291 pte_t *pte = pte_offset_kernel(pmd, 0UL); 291 pte_t *ptep = pte_offset_kernel(pmdp, 0UL);
292 unsigned long addr; 292 unsigned long addr;
293 unsigned i; 293 unsigned i;
294 294
295 for (i = 0; i < PTRS_PER_PTE; i++, pte++) { 295 for (i = 0; i < PTRS_PER_PTE; i++, ptep++) {
296 addr = start + i * PAGE_SIZE; 296 addr = start + i * PAGE_SIZE;
297 note_page(st, addr, 4, pte_val(*pte)); 297 note_page(st, addr, 4, READ_ONCE(pte_val(*ptep)));
298 } 298 }
299} 299}
300 300
301static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start) 301static void walk_pmd(struct pg_state *st, pud_t *pudp, unsigned long start)
302{ 302{
303 pmd_t *pmd = pmd_offset(pud, 0UL); 303 pmd_t *pmdp = pmd_offset(pudp, 0UL);
304 unsigned long addr; 304 unsigned long addr;
305 unsigned i; 305 unsigned i;
306 306
307 for (i = 0; i < PTRS_PER_PMD; i++, pmd++) { 307 for (i = 0; i < PTRS_PER_PMD; i++, pmdp++) {
308 pmd_t pmd = READ_ONCE(*pmdp);
309
308 addr = start + i * PMD_SIZE; 310 addr = start + i * PMD_SIZE;
309 if (pmd_none(*pmd) || pmd_sect(*pmd)) { 311 if (pmd_none(pmd) || pmd_sect(pmd)) {
310 note_page(st, addr, 3, pmd_val(*pmd)); 312 note_page(st, addr, 3, pmd_val(pmd));
311 } else { 313 } else {
312 BUG_ON(pmd_bad(*pmd)); 314 BUG_ON(pmd_bad(pmd));
313 walk_pte(st, pmd, addr); 315 walk_pte(st, pmdp, addr);
314 } 316 }
315 } 317 }
316} 318}
317 319
318static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start) 320static void walk_pud(struct pg_state *st, pgd_t *pgdp, unsigned long start)
319{ 321{
320 pud_t *pud = pud_offset(pgd, 0UL); 322 pud_t *pudp = pud_offset(pgdp, 0UL);
321 unsigned long addr; 323 unsigned long addr;
322 unsigned i; 324 unsigned i;
323 325
324 for (i = 0; i < PTRS_PER_PUD; i++, pud++) { 326 for (i = 0; i < PTRS_PER_PUD; i++, pudp++) {
327 pud_t pud = READ_ONCE(*pudp);
328
325 addr = start + i * PUD_SIZE; 329 addr = start + i * PUD_SIZE;
326 if (pud_none(*pud) || pud_sect(*pud)) { 330 if (pud_none(pud) || pud_sect(pud)) {
327 note_page(st, addr, 2, pud_val(*pud)); 331 note_page(st, addr, 2, pud_val(pud));
328 } else { 332 } else {
329 BUG_ON(pud_bad(*pud)); 333 BUG_ON(pud_bad(pud));
330 walk_pmd(st, pud, addr); 334 walk_pmd(st, pudp, addr);
331 } 335 }
332 } 336 }
333} 337}
@@ -335,17 +339,19 @@ static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start)
335static void walk_pgd(struct pg_state *st, struct mm_struct *mm, 339static void walk_pgd(struct pg_state *st, struct mm_struct *mm,
336 unsigned long start) 340 unsigned long start)
337{ 341{
338 pgd_t *pgd = pgd_offset(mm, 0UL); 342 pgd_t *pgdp = pgd_offset(mm, 0UL);
339 unsigned i; 343 unsigned i;
340 unsigned long addr; 344 unsigned long addr;
341 345
342 for (i = 0; i < PTRS_PER_PGD; i++, pgd++) { 346 for (i = 0; i < PTRS_PER_PGD; i++, pgdp++) {
347 pgd_t pgd = READ_ONCE(*pgdp);
348
343 addr = start + i * PGDIR_SIZE; 349 addr = start + i * PGDIR_SIZE;
344 if (pgd_none(*pgd)) { 350 if (pgd_none(pgd)) {
345 note_page(st, addr, 1, pgd_val(*pgd)); 351 note_page(st, addr, 1, pgd_val(pgd));
346 } else { 352 } else {
347 BUG_ON(pgd_bad(*pgd)); 353 BUG_ON(pgd_bad(pgd));
348 walk_pud(st, pgd, addr); 354 walk_pud(st, pgdp, addr);
349 } 355 }
350 } 356 }
351} 357}
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index f76bb2c3c943..bff11553eb05 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -130,7 +130,8 @@ static void mem_abort_decode(unsigned int esr)
130void show_pte(unsigned long addr) 130void show_pte(unsigned long addr)
131{ 131{
132 struct mm_struct *mm; 132 struct mm_struct *mm;
133 pgd_t *pgd; 133 pgd_t *pgdp;
134 pgd_t pgd;
134 135
135 if (addr < TASK_SIZE) { 136 if (addr < TASK_SIZE) {
136 /* TTBR0 */ 137 /* TTBR0 */
@@ -149,33 +150,37 @@ void show_pte(unsigned long addr)
149 return; 150 return;
150 } 151 }
151 152
152 pr_alert("%s pgtable: %luk pages, %u-bit VAs, pgd = %p\n", 153 pr_alert("%s pgtable: %luk pages, %u-bit VAs, pgdp = %p\n",
153 mm == &init_mm ? "swapper" : "user", PAGE_SIZE / SZ_1K, 154 mm == &init_mm ? "swapper" : "user", PAGE_SIZE / SZ_1K,
154 VA_BITS, mm->pgd); 155 VA_BITS, mm->pgd);
155 pgd = pgd_offset(mm, addr); 156 pgdp = pgd_offset(mm, addr);
156 pr_alert("[%016lx] *pgd=%016llx", addr, pgd_val(*pgd)); 157 pgd = READ_ONCE(*pgdp);
158 pr_alert("[%016lx] pgd=%016llx", addr, pgd_val(pgd));
157 159
158 do { 160 do {
159 pud_t *pud; 161 pud_t *pudp, pud;
160 pmd_t *pmd; 162 pmd_t *pmdp, pmd;
161 pte_t *pte; 163 pte_t *ptep, pte;
162 164
163 if (pgd_none(*pgd) || pgd_bad(*pgd)) 165 if (pgd_none(pgd) || pgd_bad(pgd))
164 break; 166 break;
165 167
166 pud = pud_offset(pgd, addr); 168 pudp = pud_offset(pgdp, addr);
167 pr_cont(", *pud=%016llx", pud_val(*pud)); 169 pud = READ_ONCE(*pudp);
168 if (pud_none(*pud) || pud_bad(*pud)) 170 pr_cont(", pud=%016llx", pud_val(pud));
171 if (pud_none(pud) || pud_bad(pud))
169 break; 172 break;
170 173
171 pmd = pmd_offset(pud, addr); 174 pmdp = pmd_offset(pudp, addr);
172 pr_cont(", *pmd=%016llx", pmd_val(*pmd)); 175 pmd = READ_ONCE(*pmdp);
173 if (pmd_none(*pmd) || pmd_bad(*pmd)) 176 pr_cont(", pmd=%016llx", pmd_val(pmd));
177 if (pmd_none(pmd) || pmd_bad(pmd))
174 break; 178 break;
175 179
176 pte = pte_offset_map(pmd, addr); 180 ptep = pte_offset_map(pmdp, addr);
177 pr_cont(", *pte=%016llx", pte_val(*pte)); 181 pte = READ_ONCE(*ptep);
178 pte_unmap(pte); 182 pr_cont(", pte=%016llx", pte_val(pte));
183 pte_unmap(ptep);
179 } while(0); 184 } while(0);
180 185
181 pr_cont("\n"); 186 pr_cont("\n");
@@ -196,8 +201,9 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
196 pte_t entry, int dirty) 201 pte_t entry, int dirty)
197{ 202{
198 pteval_t old_pteval, pteval; 203 pteval_t old_pteval, pteval;
204 pte_t pte = READ_ONCE(*ptep);
199 205
200 if (pte_same(*ptep, entry)) 206 if (pte_same(pte, entry))
201 return 0; 207 return 0;
202 208
203 /* only preserve the access flags and write permission */ 209 /* only preserve the access flags and write permission */
@@ -210,7 +216,7 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
210 * (calculated as: a & b == ~(~a | ~b)). 216 * (calculated as: a & b == ~(~a | ~b)).
211 */ 217 */
212 pte_val(entry) ^= PTE_RDONLY; 218 pte_val(entry) ^= PTE_RDONLY;
213 pteval = READ_ONCE(pte_val(*ptep)); 219 pteval = pte_val(pte);
214 do { 220 do {
215 old_pteval = pteval; 221 old_pteval = pteval;
216 pteval ^= PTE_RDONLY; 222 pteval ^= PTE_RDONLY;
diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index 6cb0fa92a651..ecc6818191df 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -54,14 +54,14 @@ static inline pgprot_t pte_pgprot(pte_t pte)
54static int find_num_contig(struct mm_struct *mm, unsigned long addr, 54static int find_num_contig(struct mm_struct *mm, unsigned long addr,
55 pte_t *ptep, size_t *pgsize) 55 pte_t *ptep, size_t *pgsize)
56{ 56{
57 pgd_t *pgd = pgd_offset(mm, addr); 57 pgd_t *pgdp = pgd_offset(mm, addr);
58 pud_t *pud; 58 pud_t *pudp;
59 pmd_t *pmd; 59 pmd_t *pmdp;
60 60
61 *pgsize = PAGE_SIZE; 61 *pgsize = PAGE_SIZE;
62 pud = pud_offset(pgd, addr); 62 pudp = pud_offset(pgdp, addr);
63 pmd = pmd_offset(pud, addr); 63 pmdp = pmd_offset(pudp, addr);
64 if ((pte_t *)pmd == ptep) { 64 if ((pte_t *)pmdp == ptep) {
65 *pgsize = PMD_SIZE; 65 *pgsize = PMD_SIZE;
66 return CONT_PMDS; 66 return CONT_PMDS;
67 } 67 }
@@ -181,11 +181,8 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
181 181
182 clear_flush(mm, addr, ptep, pgsize, ncontig); 182 clear_flush(mm, addr, ptep, pgsize, ncontig);
183 183
184 for (i = 0; i < ncontig; i++, ptep++, addr += pgsize, pfn += dpfn) { 184 for (i = 0; i < ncontig; i++, ptep++, addr += pgsize, pfn += dpfn)
185 pr_debug("%s: set pte %p to 0x%llx\n", __func__, ptep,
186 pte_val(pfn_pte(pfn, hugeprot)));
187 set_pte_at(mm, addr, ptep, pfn_pte(pfn, hugeprot)); 185 set_pte_at(mm, addr, ptep, pfn_pte(pfn, hugeprot));
188 }
189} 186}
190 187
191void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr, 188void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr,
@@ -203,20 +200,20 @@ void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr,
203pte_t *huge_pte_alloc(struct mm_struct *mm, 200pte_t *huge_pte_alloc(struct mm_struct *mm,
204 unsigned long addr, unsigned long sz) 201 unsigned long addr, unsigned long sz)
205{ 202{
206 pgd_t *pgd; 203 pgd_t *pgdp;
207 pud_t *pud; 204 pud_t *pudp;
208 pte_t *pte = NULL; 205 pmd_t *pmdp;
209 206 pte_t *ptep = NULL;
210 pr_debug("%s: addr:0x%lx sz:0x%lx\n", __func__, addr, sz); 207
211 pgd = pgd_offset(mm, addr); 208 pgdp = pgd_offset(mm, addr);
212 pud = pud_alloc(mm, pgd, addr); 209 pudp = pud_alloc(mm, pgdp, addr);
213 if (!pud) 210 if (!pudp)
214 return NULL; 211 return NULL;
215 212
216 if (sz == PUD_SIZE) { 213 if (sz == PUD_SIZE) {
217 pte = (pte_t *)pud; 214 ptep = (pte_t *)pudp;
218 } else if (sz == (PAGE_SIZE * CONT_PTES)) { 215 } else if (sz == (PAGE_SIZE * CONT_PTES)) {
219 pmd_t *pmd = pmd_alloc(mm, pud, addr); 216 pmdp = pmd_alloc(mm, pudp, addr);
220 217
221 WARN_ON(addr & (sz - 1)); 218 WARN_ON(addr & (sz - 1));
222 /* 219 /*
@@ -226,60 +223,55 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
226 * will be no pte_unmap() to correspond with this 223 * will be no pte_unmap() to correspond with this
227 * pte_alloc_map(). 224 * pte_alloc_map().
228 */ 225 */
229 pte = pte_alloc_map(mm, pmd, addr); 226 ptep = pte_alloc_map(mm, pmdp, addr);
230 } else if (sz == PMD_SIZE) { 227 } else if (sz == PMD_SIZE) {
231 if (IS_ENABLED(CONFIG_ARCH_WANT_HUGE_PMD_SHARE) && 228 if (IS_ENABLED(CONFIG_ARCH_WANT_HUGE_PMD_SHARE) &&
232 pud_none(*pud)) 229 pud_none(READ_ONCE(*pudp)))
233 pte = huge_pmd_share(mm, addr, pud); 230 ptep = huge_pmd_share(mm, addr, pudp);
234 else 231 else
235 pte = (pte_t *)pmd_alloc(mm, pud, addr); 232 ptep = (pte_t *)pmd_alloc(mm, pudp, addr);
236 } else if (sz == (PMD_SIZE * CONT_PMDS)) { 233 } else if (sz == (PMD_SIZE * CONT_PMDS)) {
237 pmd_t *pmd; 234 pmdp = pmd_alloc(mm, pudp, addr);
238
239 pmd = pmd_alloc(mm, pud, addr);
240 WARN_ON(addr & (sz - 1)); 235 WARN_ON(addr & (sz - 1));
241 return (pte_t *)pmd; 236 return (pte_t *)pmdp;
242 } 237 }
243 238
244 pr_debug("%s: addr:0x%lx sz:0x%lx ret pte=%p/0x%llx\n", __func__, addr, 239 return ptep;
245 sz, pte, pte_val(*pte));
246 return pte;
247} 240}
248 241
249pte_t *huge_pte_offset(struct mm_struct *mm, 242pte_t *huge_pte_offset(struct mm_struct *mm,
250 unsigned long addr, unsigned long sz) 243 unsigned long addr, unsigned long sz)
251{ 244{
252 pgd_t *pgd; 245 pgd_t *pgdp;
253 pud_t *pud; 246 pud_t *pudp, pud;
254 pmd_t *pmd; 247 pmd_t *pmdp, pmd;
255 248
256 pgd = pgd_offset(mm, addr); 249 pgdp = pgd_offset(mm, addr);
257 pr_debug("%s: addr:0x%lx pgd:%p\n", __func__, addr, pgd); 250 if (!pgd_present(READ_ONCE(*pgdp)))
258 if (!pgd_present(*pgd))
259 return NULL; 251 return NULL;
260 252
261 pud = pud_offset(pgd, addr); 253 pudp = pud_offset(pgdp, addr);
262 if (sz != PUD_SIZE && pud_none(*pud)) 254 pud = READ_ONCE(*pudp);
255 if (sz != PUD_SIZE && pud_none(pud))
263 return NULL; 256 return NULL;
264 /* hugepage or swap? */ 257 /* hugepage or swap? */
265 if (pud_huge(*pud) || !pud_present(*pud)) 258 if (pud_huge(pud) || !pud_present(pud))
266 return (pte_t *)pud; 259 return (pte_t *)pudp;
267 /* table; check the next level */ 260 /* table; check the next level */
268 261
269 if (sz == CONT_PMD_SIZE) 262 if (sz == CONT_PMD_SIZE)
270 addr &= CONT_PMD_MASK; 263 addr &= CONT_PMD_MASK;
271 264
272 pmd = pmd_offset(pud, addr); 265 pmdp = pmd_offset(pudp, addr);
266 pmd = READ_ONCE(*pmdp);
273 if (!(sz == PMD_SIZE || sz == CONT_PMD_SIZE) && 267 if (!(sz == PMD_SIZE || sz == CONT_PMD_SIZE) &&
274 pmd_none(*pmd)) 268 pmd_none(pmd))
275 return NULL; 269 return NULL;
276 if (pmd_huge(*pmd) || !pmd_present(*pmd)) 270 if (pmd_huge(pmd) || !pmd_present(pmd))
277 return (pte_t *)pmd; 271 return (pte_t *)pmdp;
278 272
279 if (sz == CONT_PTE_SIZE) { 273 if (sz == CONT_PTE_SIZE)
280 pte_t *pte = pte_offset_kernel(pmd, (addr & CONT_PTE_MASK)); 274 return pte_offset_kernel(pmdp, (addr & CONT_PTE_MASK));
281 return pte;
282 }
283 275
284 return NULL; 276 return NULL;
285} 277}
@@ -367,7 +359,7 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm,
367 size_t pgsize; 359 size_t pgsize;
368 pte_t pte; 360 pte_t pte;
369 361
370 if (!pte_cont(*ptep)) { 362 if (!pte_cont(READ_ONCE(*ptep))) {
371 ptep_set_wrprotect(mm, addr, ptep); 363 ptep_set_wrprotect(mm, addr, ptep);
372 return; 364 return;
373 } 365 }
@@ -391,7 +383,7 @@ void huge_ptep_clear_flush(struct vm_area_struct *vma,
391 size_t pgsize; 383 size_t pgsize;
392 int ncontig; 384 int ncontig;
393 385
394 if (!pte_cont(*ptep)) { 386 if (!pte_cont(READ_ONCE(*ptep))) {
395 ptep_clear_flush(vma, addr, ptep); 387 ptep_clear_flush(vma, addr, ptep);
396 return; 388 return;
397 } 389 }
diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c
index 6e02e6fb4c7b..dabfc1ecda3d 100644
--- a/arch/arm64/mm/kasan_init.c
+++ b/arch/arm64/mm/kasan_init.c
@@ -44,92 +44,92 @@ static phys_addr_t __init kasan_alloc_zeroed_page(int node)
44 return __pa(p); 44 return __pa(p);
45} 45}
46 46
47static pte_t *__init kasan_pte_offset(pmd_t *pmd, unsigned long addr, int node, 47static pte_t *__init kasan_pte_offset(pmd_t *pmdp, unsigned long addr, int node,
48 bool early) 48 bool early)
49{ 49{
50 if (pmd_none(*pmd)) { 50 if (pmd_none(READ_ONCE(*pmdp))) {
51 phys_addr_t pte_phys = early ? __pa_symbol(kasan_zero_pte) 51 phys_addr_t pte_phys = early ? __pa_symbol(kasan_zero_pte)
52 : kasan_alloc_zeroed_page(node); 52 : kasan_alloc_zeroed_page(node);
53 __pmd_populate(pmd, pte_phys, PMD_TYPE_TABLE); 53 __pmd_populate(pmdp, pte_phys, PMD_TYPE_TABLE);
54 } 54 }
55 55
56 return early ? pte_offset_kimg(pmd, addr) 56 return early ? pte_offset_kimg(pmdp, addr)
57 : pte_offset_kernel(pmd, addr); 57 : pte_offset_kernel(pmdp, addr);
58} 58}
59 59
60static pmd_t *__init kasan_pmd_offset(pud_t *pud, unsigned long addr, int node, 60static pmd_t *__init kasan_pmd_offset(pud_t *pudp, unsigned long addr, int node,
61 bool early) 61 bool early)
62{ 62{
63 if (pud_none(*pud)) { 63 if (pud_none(READ_ONCE(*pudp))) {
64 phys_addr_t pmd_phys = early ? __pa_symbol(kasan_zero_pmd) 64 phys_addr_t pmd_phys = early ? __pa_symbol(kasan_zero_pmd)
65 : kasan_alloc_zeroed_page(node); 65 : kasan_alloc_zeroed_page(node);
66 __pud_populate(pud, pmd_phys, PMD_TYPE_TABLE); 66 __pud_populate(pudp, pmd_phys, PMD_TYPE_TABLE);
67 } 67 }
68 68
69 return early ? pmd_offset_kimg(pud, addr) : pmd_offset(pud, addr); 69 return early ? pmd_offset_kimg(pudp, addr) : pmd_offset(pudp, addr);
70} 70}
71 71
72static pud_t *__init kasan_pud_offset(pgd_t *pgd, unsigned long addr, int node, 72static pud_t *__init kasan_pud_offset(pgd_t *pgdp, unsigned long addr, int node,
73 bool early) 73 bool early)
74{ 74{
75 if (pgd_none(*pgd)) { 75 if (pgd_none(READ_ONCE(*pgdp))) {
76 phys_addr_t pud_phys = early ? __pa_symbol(kasan_zero_pud) 76 phys_addr_t pud_phys = early ? __pa_symbol(kasan_zero_pud)
77 : kasan_alloc_zeroed_page(node); 77 : kasan_alloc_zeroed_page(node);
78 __pgd_populate(pgd, pud_phys, PMD_TYPE_TABLE); 78 __pgd_populate(pgdp, pud_phys, PMD_TYPE_TABLE);
79 } 79 }
80 80
81 return early ? pud_offset_kimg(pgd, addr) : pud_offset(pgd, addr); 81 return early ? pud_offset_kimg(pgdp, addr) : pud_offset(pgdp, addr);
82} 82}
83 83
84static void __init kasan_pte_populate(pmd_t *pmd, unsigned long addr, 84static void __init kasan_pte_populate(pmd_t *pmdp, unsigned long addr,
85 unsigned long end, int node, bool early) 85 unsigned long end, int node, bool early)
86{ 86{
87 unsigned long next; 87 unsigned long next;
88 pte_t *pte = kasan_pte_offset(pmd, addr, node, early); 88 pte_t *ptep = kasan_pte_offset(pmdp, addr, node, early);
89 89
90 do { 90 do {
91 phys_addr_t page_phys = early ? __pa_symbol(kasan_zero_page) 91 phys_addr_t page_phys = early ? __pa_symbol(kasan_zero_page)
92 : kasan_alloc_zeroed_page(node); 92 : kasan_alloc_zeroed_page(node);
93 next = addr + PAGE_SIZE; 93 next = addr + PAGE_SIZE;
94 set_pte(pte, pfn_pte(__phys_to_pfn(page_phys), PAGE_KERNEL)); 94 set_pte(ptep, pfn_pte(__phys_to_pfn(page_phys), PAGE_KERNEL));
95 } while (pte++, addr = next, addr != end && pte_none(*pte)); 95 } while (ptep++, addr = next, addr != end && pte_none(READ_ONCE(*ptep)));
96} 96}
97 97
98static void __init kasan_pmd_populate(pud_t *pud, unsigned long addr, 98static void __init kasan_pmd_populate(pud_t *pudp, unsigned long addr,
99 unsigned long end, int node, bool early) 99 unsigned long end, int node, bool early)
100{ 100{
101 unsigned long next; 101 unsigned long next;
102 pmd_t *pmd = kasan_pmd_offset(pud, addr, node, early); 102 pmd_t *pmdp = kasan_pmd_offset(pudp, addr, node, early);
103 103
104 do { 104 do {
105 next = pmd_addr_end(addr, end); 105 next = pmd_addr_end(addr, end);
106 kasan_pte_populate(pmd, addr, next, node, early); 106 kasan_pte_populate(pmdp, addr, next, node, early);
107 } while (pmd++, addr = next, addr != end && pmd_none(*pmd)); 107 } while (pmdp++, addr = next, addr != end && pmd_none(READ_ONCE(*pmdp)));
108} 108}
109 109
110static void __init kasan_pud_populate(pgd_t *pgd, unsigned long addr, 110static void __init kasan_pud_populate(pgd_t *pgdp, unsigned long addr,
111 unsigned long end, int node, bool early) 111 unsigned long end, int node, bool early)
112{ 112{
113 unsigned long next; 113 unsigned long next;
114 pud_t *pud = kasan_pud_offset(pgd, addr, node, early); 114 pud_t *pudp = kasan_pud_offset(pgdp, addr, node, early);
115 115
116 do { 116 do {
117 next = pud_addr_end(addr, end); 117 next = pud_addr_end(addr, end);
118 kasan_pmd_populate(pud, addr, next, node, early); 118 kasan_pmd_populate(pudp, addr, next, node, early);
119 } while (pud++, addr = next, addr != end && pud_none(*pud)); 119 } while (pudp++, addr = next, addr != end && pud_none(READ_ONCE(*pudp)));
120} 120}
121 121
122static void __init kasan_pgd_populate(unsigned long addr, unsigned long end, 122static void __init kasan_pgd_populate(unsigned long addr, unsigned long end,
123 int node, bool early) 123 int node, bool early)
124{ 124{
125 unsigned long next; 125 unsigned long next;
126 pgd_t *pgd; 126 pgd_t *pgdp;
127 127
128 pgd = pgd_offset_k(addr); 128 pgdp = pgd_offset_k(addr);
129 do { 129 do {
130 next = pgd_addr_end(addr, end); 130 next = pgd_addr_end(addr, end);
131 kasan_pud_populate(pgd, addr, next, node, early); 131 kasan_pud_populate(pgdp, addr, next, node, early);
132 } while (pgd++, addr = next, addr != end); 132 } while (pgdp++, addr = next, addr != end);
133} 133}
134 134
135/* The early shadow maps everything to a single page of zeroes */ 135/* The early shadow maps everything to a single page of zeroes */
@@ -155,14 +155,14 @@ static void __init kasan_map_populate(unsigned long start, unsigned long end,
155 */ 155 */
156void __init kasan_copy_shadow(pgd_t *pgdir) 156void __init kasan_copy_shadow(pgd_t *pgdir)
157{ 157{
158 pgd_t *pgd, *pgd_new, *pgd_end; 158 pgd_t *pgdp, *pgdp_new, *pgdp_end;
159 159
160 pgd = pgd_offset_k(KASAN_SHADOW_START); 160 pgdp = pgd_offset_k(KASAN_SHADOW_START);
161 pgd_end = pgd_offset_k(KASAN_SHADOW_END); 161 pgdp_end = pgd_offset_k(KASAN_SHADOW_END);
162 pgd_new = pgd_offset_raw(pgdir, KASAN_SHADOW_START); 162 pgdp_new = pgd_offset_raw(pgdir, KASAN_SHADOW_START);
163 do { 163 do {
164 set_pgd(pgd_new, *pgd); 164 set_pgd(pgdp_new, READ_ONCE(*pgdp));
165 } while (pgd++, pgd_new++, pgd != pgd_end); 165 } while (pgdp++, pgdp_new++, pgdp != pgdp_end);
166} 166}
167 167
168static void __init clear_pgds(unsigned long start, 168static void __init clear_pgds(unsigned long start,
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 4694cda823c9..2dbb2c9f1ec1 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -108,7 +108,7 @@ static bool pgattr_change_is_safe(u64 old, u64 new)
108 * The following mapping attributes may be updated in live 108 * The following mapping attributes may be updated in live
109 * kernel mappings without the need for break-before-make. 109 * kernel mappings without the need for break-before-make.
110 */ 110 */
111 static const pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE; 111 static const pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG;
112 112
113 /* creating or taking down mappings is always safe */ 113 /* creating or taking down mappings is always safe */
114 if (old == 0 || new == 0) 114 if (old == 0 || new == 0)
@@ -118,52 +118,55 @@ static bool pgattr_change_is_safe(u64 old, u64 new)
118 if ((old | new) & PTE_CONT) 118 if ((old | new) & PTE_CONT)
119 return false; 119 return false;
120 120
121 /* Transitioning from Global to Non-Global is safe */ 121 /* Transitioning from Non-Global to Global is unsafe */
122 if (((old ^ new) == PTE_NG) && (new & PTE_NG)) 122 if (old & ~new & PTE_NG)
123 return true; 123 return false;
124 124
125 return ((old ^ new) & ~mask) == 0; 125 return ((old ^ new) & ~mask) == 0;
126} 126}
127 127
128static void init_pte(pmd_t *pmd, unsigned long addr, unsigned long end, 128static void init_pte(pmd_t *pmdp, unsigned long addr, unsigned long end,
129 phys_addr_t phys, pgprot_t prot) 129 phys_addr_t phys, pgprot_t prot)
130{ 130{
131 pte_t *pte; 131 pte_t *ptep;
132 132
133 pte = pte_set_fixmap_offset(pmd, addr); 133 ptep = pte_set_fixmap_offset(pmdp, addr);
134 do { 134 do {
135 pte_t old_pte = *pte; 135 pte_t old_pte = READ_ONCE(*ptep);
136 136
137 set_pte(pte, pfn_pte(__phys_to_pfn(phys), prot)); 137 set_pte(ptep, pfn_pte(__phys_to_pfn(phys), prot));
138 138
139 /* 139 /*
140 * After the PTE entry has been populated once, we 140 * After the PTE entry has been populated once, we
141 * only allow updates to the permission attributes. 141 * only allow updates to the permission attributes.
142 */ 142 */
143 BUG_ON(!pgattr_change_is_safe(pte_val(old_pte), pte_val(*pte))); 143 BUG_ON(!pgattr_change_is_safe(pte_val(old_pte),
144 READ_ONCE(pte_val(*ptep))));
144 145
145 phys += PAGE_SIZE; 146 phys += PAGE_SIZE;
146 } while (pte++, addr += PAGE_SIZE, addr != end); 147 } while (ptep++, addr += PAGE_SIZE, addr != end);
147 148
148 pte_clear_fixmap(); 149 pte_clear_fixmap();
149} 150}
150 151
151static void alloc_init_cont_pte(pmd_t *pmd, unsigned long addr, 152static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr,
152 unsigned long end, phys_addr_t phys, 153 unsigned long end, phys_addr_t phys,
153 pgprot_t prot, 154 pgprot_t prot,
154 phys_addr_t (*pgtable_alloc)(void), 155 phys_addr_t (*pgtable_alloc)(void),
155 int flags) 156 int flags)
156{ 157{
157 unsigned long next; 158 unsigned long next;
159 pmd_t pmd = READ_ONCE(*pmdp);
158 160
159 BUG_ON(pmd_sect(*pmd)); 161 BUG_ON(pmd_sect(pmd));
160 if (pmd_none(*pmd)) { 162 if (pmd_none(pmd)) {
161 phys_addr_t pte_phys; 163 phys_addr_t pte_phys;
162 BUG_ON(!pgtable_alloc); 164 BUG_ON(!pgtable_alloc);
163 pte_phys = pgtable_alloc(); 165 pte_phys = pgtable_alloc();
164 __pmd_populate(pmd, pte_phys, PMD_TYPE_TABLE); 166 __pmd_populate(pmdp, pte_phys, PMD_TYPE_TABLE);
167 pmd = READ_ONCE(*pmdp);
165 } 168 }
166 BUG_ON(pmd_bad(*pmd)); 169 BUG_ON(pmd_bad(pmd));
167 170
168 do { 171 do {
169 pgprot_t __prot = prot; 172 pgprot_t __prot = prot;
@@ -175,67 +178,69 @@ static void alloc_init_cont_pte(pmd_t *pmd, unsigned long addr,
175 (flags & NO_CONT_MAPPINGS) == 0) 178 (flags & NO_CONT_MAPPINGS) == 0)
176 __prot = __pgprot(pgprot_val(prot) | PTE_CONT); 179 __prot = __pgprot(pgprot_val(prot) | PTE_CONT);
177 180
178 init_pte(pmd, addr, next, phys, __prot); 181 init_pte(pmdp, addr, next, phys, __prot);
179 182
180 phys += next - addr; 183 phys += next - addr;
181 } while (addr = next, addr != end); 184 } while (addr = next, addr != end);
182} 185}
183 186
184static void init_pmd(pud_t *pud, unsigned long addr, unsigned long end, 187static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end,
185 phys_addr_t phys, pgprot_t prot, 188 phys_addr_t phys, pgprot_t prot,
186 phys_addr_t (*pgtable_alloc)(void), int flags) 189 phys_addr_t (*pgtable_alloc)(void), int flags)
187{ 190{
188 unsigned long next; 191 unsigned long next;
189 pmd_t *pmd; 192 pmd_t *pmdp;
190 193
191 pmd = pmd_set_fixmap_offset(pud, addr); 194 pmdp = pmd_set_fixmap_offset(pudp, addr);
192 do { 195 do {
193 pmd_t old_pmd = *pmd; 196 pmd_t old_pmd = READ_ONCE(*pmdp);
194 197
195 next = pmd_addr_end(addr, end); 198 next = pmd_addr_end(addr, end);
196 199
197 /* try section mapping first */ 200 /* try section mapping first */
198 if (((addr | next | phys) & ~SECTION_MASK) == 0 && 201 if (((addr | next | phys) & ~SECTION_MASK) == 0 &&
199 (flags & NO_BLOCK_MAPPINGS) == 0) { 202 (flags & NO_BLOCK_MAPPINGS) == 0) {
200 pmd_set_huge(pmd, phys, prot); 203 pmd_set_huge(pmdp, phys, prot);
201 204
202 /* 205 /*
203 * After the PMD entry has been populated once, we 206 * After the PMD entry has been populated once, we
204 * only allow updates to the permission attributes. 207 * only allow updates to the permission attributes.
205 */ 208 */
206 BUG_ON(!pgattr_change_is_safe(pmd_val(old_pmd), 209 BUG_ON(!pgattr_change_is_safe(pmd_val(old_pmd),
207 pmd_val(*pmd))); 210 READ_ONCE(pmd_val(*pmdp))));
208 } else { 211 } else {
209 alloc_init_cont_pte(pmd, addr, next, phys, prot, 212 alloc_init_cont_pte(pmdp, addr, next, phys, prot,
210 pgtable_alloc, flags); 213 pgtable_alloc, flags);
211 214
212 BUG_ON(pmd_val(old_pmd) != 0 && 215 BUG_ON(pmd_val(old_pmd) != 0 &&
213 pmd_val(old_pmd) != pmd_val(*pmd)); 216 pmd_val(old_pmd) != READ_ONCE(pmd_val(*pmdp)));
214 } 217 }
215 phys += next - addr; 218 phys += next - addr;
216 } while (pmd++, addr = next, addr != end); 219 } while (pmdp++, addr = next, addr != end);
217 220
218 pmd_clear_fixmap(); 221 pmd_clear_fixmap();
219} 222}
220 223
221static void alloc_init_cont_pmd(pud_t *pud, unsigned long addr, 224static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr,
222 unsigned long end, phys_addr_t phys, 225 unsigned long end, phys_addr_t phys,
223 pgprot_t prot, 226 pgprot_t prot,
224 phys_addr_t (*pgtable_alloc)(void), int flags) 227 phys_addr_t (*pgtable_alloc)(void), int flags)
225{ 228{
226 unsigned long next; 229 unsigned long next;
230 pud_t pud = READ_ONCE(*pudp);
227 231
228 /* 232 /*
229 * Check for initial section mappings in the pgd/pud. 233 * Check for initial section mappings in the pgd/pud.
230 */ 234 */
231 BUG_ON(pud_sect(*pud)); 235 BUG_ON(pud_sect(pud));
232 if (pud_none(*pud)) { 236 if (pud_none(pud)) {
233 phys_addr_t pmd_phys; 237 phys_addr_t pmd_phys;
234 BUG_ON(!pgtable_alloc); 238 BUG_ON(!pgtable_alloc);
235 pmd_phys = pgtable_alloc(); 239 pmd_phys = pgtable_alloc();
236 __pud_populate(pud, pmd_phys, PUD_TYPE_TABLE); 240 __pud_populate(pudp, pmd_phys, PUD_TYPE_TABLE);
241 pud = READ_ONCE(*pudp);
237 } 242 }
238 BUG_ON(pud_bad(*pud)); 243 BUG_ON(pud_bad(pud));
239 244
240 do { 245 do {
241 pgprot_t __prot = prot; 246 pgprot_t __prot = prot;
@@ -247,7 +252,7 @@ static void alloc_init_cont_pmd(pud_t *pud, unsigned long addr,
247 (flags & NO_CONT_MAPPINGS) == 0) 252 (flags & NO_CONT_MAPPINGS) == 0)
248 __prot = __pgprot(pgprot_val(prot) | PTE_CONT); 253 __prot = __pgprot(pgprot_val(prot) | PTE_CONT);
249 254
250 init_pmd(pud, addr, next, phys, __prot, pgtable_alloc, flags); 255 init_pmd(pudp, addr, next, phys, __prot, pgtable_alloc, flags);
251 256
252 phys += next - addr; 257 phys += next - addr;
253 } while (addr = next, addr != end); 258 } while (addr = next, addr != end);
@@ -265,25 +270,27 @@ static inline bool use_1G_block(unsigned long addr, unsigned long next,
265 return true; 270 return true;
266} 271}
267 272
268static void alloc_init_pud(pgd_t *pgd, unsigned long addr, unsigned long end, 273static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end,
269 phys_addr_t phys, pgprot_t prot, 274 phys_addr_t phys, pgprot_t prot,
270 phys_addr_t (*pgtable_alloc)(void), 275 phys_addr_t (*pgtable_alloc)(void),
271 int flags) 276 int flags)
272{ 277{
273 pud_t *pud;
274 unsigned long next; 278 unsigned long next;
279 pud_t *pudp;
280 pgd_t pgd = READ_ONCE(*pgdp);
275 281
276 if (pgd_none(*pgd)) { 282 if (pgd_none(pgd)) {
277 phys_addr_t pud_phys; 283 phys_addr_t pud_phys;
278 BUG_ON(!pgtable_alloc); 284 BUG_ON(!pgtable_alloc);
279 pud_phys = pgtable_alloc(); 285 pud_phys = pgtable_alloc();
280 __pgd_populate(pgd, pud_phys, PUD_TYPE_TABLE); 286 __pgd_populate(pgdp, pud_phys, PUD_TYPE_TABLE);
287 pgd = READ_ONCE(*pgdp);
281 } 288 }
282 BUG_ON(pgd_bad(*pgd)); 289 BUG_ON(pgd_bad(pgd));
283 290
284 pud = pud_set_fixmap_offset(pgd, addr); 291 pudp = pud_set_fixmap_offset(pgdp, addr);
285 do { 292 do {
286 pud_t old_pud = *pud; 293 pud_t old_pud = READ_ONCE(*pudp);
287 294
288 next = pud_addr_end(addr, end); 295 next = pud_addr_end(addr, end);
289 296
@@ -292,23 +299,23 @@ static void alloc_init_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
292 */ 299 */
293 if (use_1G_block(addr, next, phys) && 300 if (use_1G_block(addr, next, phys) &&
294 (flags & NO_BLOCK_MAPPINGS) == 0) { 301 (flags & NO_BLOCK_MAPPINGS) == 0) {
295 pud_set_huge(pud, phys, prot); 302 pud_set_huge(pudp, phys, prot);
296 303
297 /* 304 /*
298 * After the PUD entry has been populated once, we 305 * After the PUD entry has been populated once, we
299 * only allow updates to the permission attributes. 306 * only allow updates to the permission attributes.
300 */ 307 */
301 BUG_ON(!pgattr_change_is_safe(pud_val(old_pud), 308 BUG_ON(!pgattr_change_is_safe(pud_val(old_pud),
302 pud_val(*pud))); 309 READ_ONCE(pud_val(*pudp))));
303 } else { 310 } else {
304 alloc_init_cont_pmd(pud, addr, next, phys, prot, 311 alloc_init_cont_pmd(pudp, addr, next, phys, prot,
305 pgtable_alloc, flags); 312 pgtable_alloc, flags);
306 313
307 BUG_ON(pud_val(old_pud) != 0 && 314 BUG_ON(pud_val(old_pud) != 0 &&
308 pud_val(old_pud) != pud_val(*pud)); 315 pud_val(old_pud) != READ_ONCE(pud_val(*pudp)));
309 } 316 }
310 phys += next - addr; 317 phys += next - addr;
311 } while (pud++, addr = next, addr != end); 318 } while (pudp++, addr = next, addr != end);
312 319
313 pud_clear_fixmap(); 320 pud_clear_fixmap();
314} 321}
@@ -320,7 +327,7 @@ static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys,
320 int flags) 327 int flags)
321{ 328{
322 unsigned long addr, length, end, next; 329 unsigned long addr, length, end, next;
323 pgd_t *pgd = pgd_offset_raw(pgdir, virt); 330 pgd_t *pgdp = pgd_offset_raw(pgdir, virt);
324 331
325 /* 332 /*
326 * If the virtual and physical address don't have the same offset 333 * If the virtual and physical address don't have the same offset
@@ -336,10 +343,10 @@ static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys,
336 end = addr + length; 343 end = addr + length;
337 do { 344 do {
338 next = pgd_addr_end(addr, end); 345 next = pgd_addr_end(addr, end);
339 alloc_init_pud(pgd, addr, next, phys, prot, pgtable_alloc, 346 alloc_init_pud(pgdp, addr, next, phys, prot, pgtable_alloc,
340 flags); 347 flags);
341 phys += next - addr; 348 phys += next - addr;
342 } while (pgd++, addr = next, addr != end); 349 } while (pgdp++, addr = next, addr != end);
343} 350}
344 351
345static phys_addr_t pgd_pgtable_alloc(void) 352static phys_addr_t pgd_pgtable_alloc(void)
@@ -401,10 +408,10 @@ static void update_mapping_prot(phys_addr_t phys, unsigned long virt,
401 flush_tlb_kernel_range(virt, virt + size); 408 flush_tlb_kernel_range(virt, virt + size);
402} 409}
403 410
404static void __init __map_memblock(pgd_t *pgd, phys_addr_t start, 411static void __init __map_memblock(pgd_t *pgdp, phys_addr_t start,
405 phys_addr_t end, pgprot_t prot, int flags) 412 phys_addr_t end, pgprot_t prot, int flags)
406{ 413{
407 __create_pgd_mapping(pgd, start, __phys_to_virt(start), end - start, 414 __create_pgd_mapping(pgdp, start, __phys_to_virt(start), end - start,
408 prot, early_pgtable_alloc, flags); 415 prot, early_pgtable_alloc, flags);
409} 416}
410 417
@@ -418,7 +425,7 @@ void __init mark_linear_text_alias_ro(void)
418 PAGE_KERNEL_RO); 425 PAGE_KERNEL_RO);
419} 426}
420 427
421static void __init map_mem(pgd_t *pgd) 428static void __init map_mem(pgd_t *pgdp)
422{ 429{
423 phys_addr_t kernel_start = __pa_symbol(_text); 430 phys_addr_t kernel_start = __pa_symbol(_text);
424 phys_addr_t kernel_end = __pa_symbol(__init_begin); 431 phys_addr_t kernel_end = __pa_symbol(__init_begin);
@@ -451,7 +458,7 @@ static void __init map_mem(pgd_t *pgd)
451 if (memblock_is_nomap(reg)) 458 if (memblock_is_nomap(reg))
452 continue; 459 continue;
453 460
454 __map_memblock(pgd, start, end, PAGE_KERNEL, flags); 461 __map_memblock(pgdp, start, end, PAGE_KERNEL, flags);
455 } 462 }
456 463
457 /* 464 /*
@@ -464,7 +471,7 @@ static void __init map_mem(pgd_t *pgd)
464 * Note that contiguous mappings cannot be remapped in this way, 471 * Note that contiguous mappings cannot be remapped in this way,
465 * so we should avoid them here. 472 * so we should avoid them here.
466 */ 473 */
467 __map_memblock(pgd, kernel_start, kernel_end, 474 __map_memblock(pgdp, kernel_start, kernel_end,
468 PAGE_KERNEL, NO_CONT_MAPPINGS); 475 PAGE_KERNEL, NO_CONT_MAPPINGS);
469 memblock_clear_nomap(kernel_start, kernel_end - kernel_start); 476 memblock_clear_nomap(kernel_start, kernel_end - kernel_start);
470 477
@@ -475,7 +482,7 @@ static void __init map_mem(pgd_t *pgd)
475 * through /sys/kernel/kexec_crash_size interface. 482 * through /sys/kernel/kexec_crash_size interface.
476 */ 483 */
477 if (crashk_res.end) { 484 if (crashk_res.end) {
478 __map_memblock(pgd, crashk_res.start, crashk_res.end + 1, 485 __map_memblock(pgdp, crashk_res.start, crashk_res.end + 1,
479 PAGE_KERNEL, 486 PAGE_KERNEL,
480 NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS); 487 NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS);
481 memblock_clear_nomap(crashk_res.start, 488 memblock_clear_nomap(crashk_res.start,
@@ -499,7 +506,7 @@ void mark_rodata_ro(void)
499 debug_checkwx(); 506 debug_checkwx();
500} 507}
501 508
502static void __init map_kernel_segment(pgd_t *pgd, void *va_start, void *va_end, 509static void __init map_kernel_segment(pgd_t *pgdp, void *va_start, void *va_end,
503 pgprot_t prot, struct vm_struct *vma, 510 pgprot_t prot, struct vm_struct *vma,
504 int flags, unsigned long vm_flags) 511 int flags, unsigned long vm_flags)
505{ 512{
@@ -509,7 +516,7 @@ static void __init map_kernel_segment(pgd_t *pgd, void *va_start, void *va_end,
509 BUG_ON(!PAGE_ALIGNED(pa_start)); 516 BUG_ON(!PAGE_ALIGNED(pa_start));
510 BUG_ON(!PAGE_ALIGNED(size)); 517 BUG_ON(!PAGE_ALIGNED(size));
511 518
512 __create_pgd_mapping(pgd, pa_start, (unsigned long)va_start, size, prot, 519 __create_pgd_mapping(pgdp, pa_start, (unsigned long)va_start, size, prot,
513 early_pgtable_alloc, flags); 520 early_pgtable_alloc, flags);
514 521
515 if (!(vm_flags & VM_NO_GUARD)) 522 if (!(vm_flags & VM_NO_GUARD))
@@ -562,7 +569,7 @@ core_initcall(map_entry_trampoline);
562/* 569/*
563 * Create fine-grained mappings for the kernel. 570 * Create fine-grained mappings for the kernel.
564 */ 571 */
565static void __init map_kernel(pgd_t *pgd) 572static void __init map_kernel(pgd_t *pgdp)
566{ 573{
567 static struct vm_struct vmlinux_text, vmlinux_rodata, vmlinux_inittext, 574 static struct vm_struct vmlinux_text, vmlinux_rodata, vmlinux_inittext,
568 vmlinux_initdata, vmlinux_data; 575 vmlinux_initdata, vmlinux_data;
@@ -578,24 +585,24 @@ static void __init map_kernel(pgd_t *pgd)
578 * Only rodata will be remapped with different permissions later on, 585 * Only rodata will be remapped with different permissions later on,
579 * all other segments are allowed to use contiguous mappings. 586 * all other segments are allowed to use contiguous mappings.
580 */ 587 */
581 map_kernel_segment(pgd, _text, _etext, text_prot, &vmlinux_text, 0, 588 map_kernel_segment(pgdp, _text, _etext, text_prot, &vmlinux_text, 0,
582 VM_NO_GUARD); 589 VM_NO_GUARD);
583 map_kernel_segment(pgd, __start_rodata, __inittext_begin, PAGE_KERNEL, 590 map_kernel_segment(pgdp, __start_rodata, __inittext_begin, PAGE_KERNEL,
584 &vmlinux_rodata, NO_CONT_MAPPINGS, VM_NO_GUARD); 591 &vmlinux_rodata, NO_CONT_MAPPINGS, VM_NO_GUARD);
585 map_kernel_segment(pgd, __inittext_begin, __inittext_end, text_prot, 592 map_kernel_segment(pgdp, __inittext_begin, __inittext_end, text_prot,
586 &vmlinux_inittext, 0, VM_NO_GUARD); 593 &vmlinux_inittext, 0, VM_NO_GUARD);
587 map_kernel_segment(pgd, __initdata_begin, __initdata_end, PAGE_KERNEL, 594 map_kernel_segment(pgdp, __initdata_begin, __initdata_end, PAGE_KERNEL,
588 &vmlinux_initdata, 0, VM_NO_GUARD); 595 &vmlinux_initdata, 0, VM_NO_GUARD);
589 map_kernel_segment(pgd, _data, _end, PAGE_KERNEL, &vmlinux_data, 0, 0); 596 map_kernel_segment(pgdp, _data, _end, PAGE_KERNEL, &vmlinux_data, 0, 0);
590 597
591 if (!pgd_val(*pgd_offset_raw(pgd, FIXADDR_START))) { 598 if (!READ_ONCE(pgd_val(*pgd_offset_raw(pgdp, FIXADDR_START)))) {
592 /* 599 /*
593 * The fixmap falls in a separate pgd to the kernel, and doesn't 600 * The fixmap falls in a separate pgd to the kernel, and doesn't
594 * live in the carveout for the swapper_pg_dir. We can simply 601 * live in the carveout for the swapper_pg_dir. We can simply
595 * re-use the existing dir for the fixmap. 602 * re-use the existing dir for the fixmap.
596 */ 603 */
597 set_pgd(pgd_offset_raw(pgd, FIXADDR_START), 604 set_pgd(pgd_offset_raw(pgdp, FIXADDR_START),
598 *pgd_offset_k(FIXADDR_START)); 605 READ_ONCE(*pgd_offset_k(FIXADDR_START)));
599 } else if (CONFIG_PGTABLE_LEVELS > 3) { 606 } else if (CONFIG_PGTABLE_LEVELS > 3) {
600 /* 607 /*
601 * The fixmap shares its top level pgd entry with the kernel 608 * The fixmap shares its top level pgd entry with the kernel
@@ -604,14 +611,15 @@ static void __init map_kernel(pgd_t *pgd)
604 * entry instead. 611 * entry instead.
605 */ 612 */
606 BUG_ON(!IS_ENABLED(CONFIG_ARM64_16K_PAGES)); 613 BUG_ON(!IS_ENABLED(CONFIG_ARM64_16K_PAGES));
607 pud_populate(&init_mm, pud_set_fixmap_offset(pgd, FIXADDR_START), 614 pud_populate(&init_mm,
615 pud_set_fixmap_offset(pgdp, FIXADDR_START),
608 lm_alias(bm_pmd)); 616 lm_alias(bm_pmd));
609 pud_clear_fixmap(); 617 pud_clear_fixmap();
610 } else { 618 } else {
611 BUG(); 619 BUG();
612 } 620 }
613 621
614 kasan_copy_shadow(pgd); 622 kasan_copy_shadow(pgdp);
615} 623}
616 624
617/* 625/*
@@ -621,10 +629,10 @@ static void __init map_kernel(pgd_t *pgd)
621void __init paging_init(void) 629void __init paging_init(void)
622{ 630{
623 phys_addr_t pgd_phys = early_pgtable_alloc(); 631 phys_addr_t pgd_phys = early_pgtable_alloc();
624 pgd_t *pgd = pgd_set_fixmap(pgd_phys); 632 pgd_t *pgdp = pgd_set_fixmap(pgd_phys);
625 633
626 map_kernel(pgd); 634 map_kernel(pgdp);
627 map_mem(pgd); 635 map_mem(pgdp);
628 636
629 /* 637 /*
630 * We want to reuse the original swapper_pg_dir so we don't have to 638 * We want to reuse the original swapper_pg_dir so we don't have to
@@ -635,7 +643,7 @@ void __init paging_init(void)
635 * To do this we need to go via a temporary pgd. 643 * To do this we need to go via a temporary pgd.
636 */ 644 */
637 cpu_replace_ttbr1(__va(pgd_phys)); 645 cpu_replace_ttbr1(__va(pgd_phys));
638 memcpy(swapper_pg_dir, pgd, PGD_SIZE); 646 memcpy(swapper_pg_dir, pgdp, PGD_SIZE);
639 cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); 647 cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
640 648
641 pgd_clear_fixmap(); 649 pgd_clear_fixmap();
@@ -655,37 +663,40 @@ void __init paging_init(void)
655 */ 663 */
656int kern_addr_valid(unsigned long addr) 664int kern_addr_valid(unsigned long addr)
657{ 665{
658 pgd_t *pgd; 666 pgd_t *pgdp;
659 pud_t *pud; 667 pud_t *pudp, pud;
660 pmd_t *pmd; 668 pmd_t *pmdp, pmd;
661 pte_t *pte; 669 pte_t *ptep, pte;
662 670
663 if ((((long)addr) >> VA_BITS) != -1UL) 671 if ((((long)addr) >> VA_BITS) != -1UL)
664 return 0; 672 return 0;
665 673
666 pgd = pgd_offset_k(addr); 674 pgdp = pgd_offset_k(addr);
667 if (pgd_none(*pgd)) 675 if (pgd_none(READ_ONCE(*pgdp)))
668 return 0; 676 return 0;
669 677
670 pud = pud_offset(pgd, addr); 678 pudp = pud_offset(pgdp, addr);
671 if (pud_none(*pud)) 679 pud = READ_ONCE(*pudp);
680 if (pud_none(pud))
672 return 0; 681 return 0;
673 682
674 if (pud_sect(*pud)) 683 if (pud_sect(pud))
675 return pfn_valid(pud_pfn(*pud)); 684 return pfn_valid(pud_pfn(pud));
676 685
677 pmd = pmd_offset(pud, addr); 686 pmdp = pmd_offset(pudp, addr);
678 if (pmd_none(*pmd)) 687 pmd = READ_ONCE(*pmdp);
688 if (pmd_none(pmd))
679 return 0; 689 return 0;
680 690
681 if (pmd_sect(*pmd)) 691 if (pmd_sect(pmd))
682 return pfn_valid(pmd_pfn(*pmd)); 692 return pfn_valid(pmd_pfn(pmd));
683 693
684 pte = pte_offset_kernel(pmd, addr); 694 ptep = pte_offset_kernel(pmdp, addr);
685 if (pte_none(*pte)) 695 pte = READ_ONCE(*ptep);
696 if (pte_none(pte))
686 return 0; 697 return 0;
687 698
688 return pfn_valid(pte_pfn(*pte)); 699 return pfn_valid(pte_pfn(pte));
689} 700}
690#ifdef CONFIG_SPARSEMEM_VMEMMAP 701#ifdef CONFIG_SPARSEMEM_VMEMMAP
691#if !ARM64_SWAPPER_USES_SECTION_MAPS 702#if !ARM64_SWAPPER_USES_SECTION_MAPS
@@ -700,32 +711,32 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
700{ 711{
701 unsigned long addr = start; 712 unsigned long addr = start;
702 unsigned long next; 713 unsigned long next;
703 pgd_t *pgd; 714 pgd_t *pgdp;
704 pud_t *pud; 715 pud_t *pudp;
705 pmd_t *pmd; 716 pmd_t *pmdp;
706 717
707 do { 718 do {
708 next = pmd_addr_end(addr, end); 719 next = pmd_addr_end(addr, end);
709 720
710 pgd = vmemmap_pgd_populate(addr, node); 721 pgdp = vmemmap_pgd_populate(addr, node);
711 if (!pgd) 722 if (!pgdp)
712 return -ENOMEM; 723 return -ENOMEM;
713 724
714 pud = vmemmap_pud_populate(pgd, addr, node); 725 pudp = vmemmap_pud_populate(pgdp, addr, node);
715 if (!pud) 726 if (!pudp)
716 return -ENOMEM; 727 return -ENOMEM;
717 728
718 pmd = pmd_offset(pud, addr); 729 pmdp = pmd_offset(pudp, addr);
719 if (pmd_none(*pmd)) { 730 if (pmd_none(READ_ONCE(*pmdp))) {
720 void *p = NULL; 731 void *p = NULL;
721 732
722 p = vmemmap_alloc_block_buf(PMD_SIZE, node); 733 p = vmemmap_alloc_block_buf(PMD_SIZE, node);
723 if (!p) 734 if (!p)
724 return -ENOMEM; 735 return -ENOMEM;
725 736
726 pmd_set_huge(pmd, __pa(p), __pgprot(PROT_SECT_NORMAL)); 737 pmd_set_huge(pmdp, __pa(p), __pgprot(PROT_SECT_NORMAL));
727 } else 738 } else
728 vmemmap_verify((pte_t *)pmd, node, addr, next); 739 vmemmap_verify((pte_t *)pmdp, node, addr, next);
729 } while (addr = next, addr != end); 740 } while (addr = next, addr != end);
730 741
731 return 0; 742 return 0;
@@ -739,20 +750,22 @@ void vmemmap_free(unsigned long start, unsigned long end,
739 750
740static inline pud_t * fixmap_pud(unsigned long addr) 751static inline pud_t * fixmap_pud(unsigned long addr)
741{ 752{
742 pgd_t *pgd = pgd_offset_k(addr); 753 pgd_t *pgdp = pgd_offset_k(addr);
754 pgd_t pgd = READ_ONCE(*pgdp);
743 755
744 BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd)); 756 BUG_ON(pgd_none(pgd) || pgd_bad(pgd));
745 757
746 return pud_offset_kimg(pgd, addr); 758 return pud_offset_kimg(pgdp, addr);
747} 759}
748 760
749static inline pmd_t * fixmap_pmd(unsigned long addr) 761static inline pmd_t * fixmap_pmd(unsigned long addr)
750{ 762{
751 pud_t *pud = fixmap_pud(addr); 763 pud_t *pudp = fixmap_pud(addr);
764 pud_t pud = READ_ONCE(*pudp);
752 765
753 BUG_ON(pud_none(*pud) || pud_bad(*pud)); 766 BUG_ON(pud_none(pud) || pud_bad(pud));
754 767
755 return pmd_offset_kimg(pud, addr); 768 return pmd_offset_kimg(pudp, addr);
756} 769}
757 770
758static inline pte_t * fixmap_pte(unsigned long addr) 771static inline pte_t * fixmap_pte(unsigned long addr)
@@ -768,30 +781,31 @@ static inline pte_t * fixmap_pte(unsigned long addr)
768 */ 781 */
769void __init early_fixmap_init(void) 782void __init early_fixmap_init(void)
770{ 783{
771 pgd_t *pgd; 784 pgd_t *pgdp, pgd;
772 pud_t *pud; 785 pud_t *pudp;
773 pmd_t *pmd; 786 pmd_t *pmdp;
774 unsigned long addr = FIXADDR_START; 787 unsigned long addr = FIXADDR_START;
775 788
776 pgd = pgd_offset_k(addr); 789 pgdp = pgd_offset_k(addr);
790 pgd = READ_ONCE(*pgdp);
777 if (CONFIG_PGTABLE_LEVELS > 3 && 791 if (CONFIG_PGTABLE_LEVELS > 3 &&
778 !(pgd_none(*pgd) || pgd_page_paddr(*pgd) == __pa_symbol(bm_pud))) { 792 !(pgd_none(pgd) || pgd_page_paddr(pgd) == __pa_symbol(bm_pud))) {
779 /* 793 /*
780 * We only end up here if the kernel mapping and the fixmap 794 * We only end up here if the kernel mapping and the fixmap
781 * share the top level pgd entry, which should only happen on 795 * share the top level pgd entry, which should only happen on
782 * 16k/4 levels configurations. 796 * 16k/4 levels configurations.
783 */ 797 */
784 BUG_ON(!IS_ENABLED(CONFIG_ARM64_16K_PAGES)); 798 BUG_ON(!IS_ENABLED(CONFIG_ARM64_16K_PAGES));
785 pud = pud_offset_kimg(pgd, addr); 799 pudp = pud_offset_kimg(pgdp, addr);
786 } else { 800 } else {
787 if (pgd_none(*pgd)) 801 if (pgd_none(pgd))
788 __pgd_populate(pgd, __pa_symbol(bm_pud), PUD_TYPE_TABLE); 802 __pgd_populate(pgdp, __pa_symbol(bm_pud), PUD_TYPE_TABLE);
789 pud = fixmap_pud(addr); 803 pudp = fixmap_pud(addr);
790 } 804 }
791 if (pud_none(*pud)) 805 if (pud_none(READ_ONCE(*pudp)))
792 __pud_populate(pud, __pa_symbol(bm_pmd), PMD_TYPE_TABLE); 806 __pud_populate(pudp, __pa_symbol(bm_pmd), PMD_TYPE_TABLE);
793 pmd = fixmap_pmd(addr); 807 pmdp = fixmap_pmd(addr);
794 __pmd_populate(pmd, __pa_symbol(bm_pte), PMD_TYPE_TABLE); 808 __pmd_populate(pmdp, __pa_symbol(bm_pte), PMD_TYPE_TABLE);
795 809
796 /* 810 /*
797 * The boot-ioremap range spans multiple pmds, for which 811 * The boot-ioremap range spans multiple pmds, for which
@@ -800,11 +814,11 @@ void __init early_fixmap_init(void)
800 BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT) 814 BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT)
801 != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT)); 815 != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));
802 816
803 if ((pmd != fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN))) 817 if ((pmdp != fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)))
804 || pmd != fixmap_pmd(fix_to_virt(FIX_BTMAP_END))) { 818 || pmdp != fixmap_pmd(fix_to_virt(FIX_BTMAP_END))) {
805 WARN_ON(1); 819 WARN_ON(1);
806 pr_warn("pmd %p != %p, %p\n", 820 pr_warn("pmdp %p != %p, %p\n",
807 pmd, fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)), 821 pmdp, fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)),
808 fixmap_pmd(fix_to_virt(FIX_BTMAP_END))); 822 fixmap_pmd(fix_to_virt(FIX_BTMAP_END)));
809 pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n", 823 pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
810 fix_to_virt(FIX_BTMAP_BEGIN)); 824 fix_to_virt(FIX_BTMAP_BEGIN));
@@ -824,16 +838,16 @@ void __set_fixmap(enum fixed_addresses idx,
824 phys_addr_t phys, pgprot_t flags) 838 phys_addr_t phys, pgprot_t flags)
825{ 839{
826 unsigned long addr = __fix_to_virt(idx); 840 unsigned long addr = __fix_to_virt(idx);
827 pte_t *pte; 841 pte_t *ptep;
828 842
829 BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses); 843 BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
830 844
831 pte = fixmap_pte(addr); 845 ptep = fixmap_pte(addr);
832 846
833 if (pgprot_val(flags)) { 847 if (pgprot_val(flags)) {
834 set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags)); 848 set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, flags));
835 } else { 849 } else {
836 pte_clear(&init_mm, addr, pte); 850 pte_clear(&init_mm, addr, ptep);
837 flush_tlb_kernel_range(addr, addr+PAGE_SIZE); 851 flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
838 } 852 }
839} 853}
@@ -915,36 +929,56 @@ int __init arch_ioremap_pmd_supported(void)
915 return 1; 929 return 1;
916} 930}
917 931
918int pud_set_huge(pud_t *pud, phys_addr_t phys, pgprot_t prot) 932int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
919{ 933{
920 pgprot_t sect_prot = __pgprot(PUD_TYPE_SECT | 934 pgprot_t sect_prot = __pgprot(PUD_TYPE_SECT |
921 pgprot_val(mk_sect_prot(prot))); 935 pgprot_val(mk_sect_prot(prot)));
936
937 /* ioremap_page_range doesn't honour BBM */
938 if (pud_present(READ_ONCE(*pudp)))
939 return 0;
940
922 BUG_ON(phys & ~PUD_MASK); 941 BUG_ON(phys & ~PUD_MASK);
923 set_pud(pud, pfn_pud(__phys_to_pfn(phys), sect_prot)); 942 set_pud(pudp, pfn_pud(__phys_to_pfn(phys), sect_prot));
924 return 1; 943 return 1;
925} 944}
926 945
927int pmd_set_huge(pmd_t *pmd, phys_addr_t phys, pgprot_t prot) 946int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot)
928{ 947{
929 pgprot_t sect_prot = __pgprot(PMD_TYPE_SECT | 948 pgprot_t sect_prot = __pgprot(PMD_TYPE_SECT |
930 pgprot_val(mk_sect_prot(prot))); 949 pgprot_val(mk_sect_prot(prot)));
950
951 /* ioremap_page_range doesn't honour BBM */
952 if (pmd_present(READ_ONCE(*pmdp)))
953 return 0;
954
931 BUG_ON(phys & ~PMD_MASK); 955 BUG_ON(phys & ~PMD_MASK);
932 set_pmd(pmd, pfn_pmd(__phys_to_pfn(phys), sect_prot)); 956 set_pmd(pmdp, pfn_pmd(__phys_to_pfn(phys), sect_prot));
933 return 1; 957 return 1;
934} 958}
935 959
936int pud_clear_huge(pud_t *pud) 960int pud_clear_huge(pud_t *pudp)
937{ 961{
938 if (!pud_sect(*pud)) 962 if (!pud_sect(READ_ONCE(*pudp)))
939 return 0; 963 return 0;
940 pud_clear(pud); 964 pud_clear(pudp);
941 return 1; 965 return 1;
942} 966}
943 967
944int pmd_clear_huge(pmd_t *pmd) 968int pmd_clear_huge(pmd_t *pmdp)
945{ 969{
946 if (!pmd_sect(*pmd)) 970 if (!pmd_sect(READ_ONCE(*pmdp)))
947 return 0; 971 return 0;
948 pmd_clear(pmd); 972 pmd_clear(pmdp);
949 return 1; 973 return 1;
950} 974}
975
976int pud_free_pmd_page(pud_t *pud)
977{
978 return pud_none(*pud);
979}
980
981int pmd_free_pte_page(pmd_t *pmd)
982{
983 return pmd_none(*pmd);
984}
diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index a682a0a2a0fa..a56359373d8b 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -29,7 +29,7 @@ static int change_page_range(pte_t *ptep, pgtable_t token, unsigned long addr,
29 void *data) 29 void *data)
30{ 30{
31 struct page_change_data *cdata = data; 31 struct page_change_data *cdata = data;
32 pte_t pte = *ptep; 32 pte_t pte = READ_ONCE(*ptep);
33 33
34 pte = clear_pte_bit(pte, cdata->clear_mask); 34 pte = clear_pte_bit(pte, cdata->clear_mask);
35 pte = set_pte_bit(pte, cdata->set_mask); 35 pte = set_pte_bit(pte, cdata->set_mask);
@@ -156,30 +156,32 @@ void __kernel_map_pages(struct page *page, int numpages, int enable)
156 */ 156 */
157bool kernel_page_present(struct page *page) 157bool kernel_page_present(struct page *page)
158{ 158{
159 pgd_t *pgd; 159 pgd_t *pgdp;
160 pud_t *pud; 160 pud_t *pudp, pud;
161 pmd_t *pmd; 161 pmd_t *pmdp, pmd;
162 pte_t *pte; 162 pte_t *ptep;
163 unsigned long addr = (unsigned long)page_address(page); 163 unsigned long addr = (unsigned long)page_address(page);
164 164
165 pgd = pgd_offset_k(addr); 165 pgdp = pgd_offset_k(addr);
166 if (pgd_none(*pgd)) 166 if (pgd_none(READ_ONCE(*pgdp)))
167 return false; 167 return false;
168 168
169 pud = pud_offset(pgd, addr); 169 pudp = pud_offset(pgdp, addr);
170 if (pud_none(*pud)) 170 pud = READ_ONCE(*pudp);
171 if (pud_none(pud))
171 return false; 172 return false;
172 if (pud_sect(*pud)) 173 if (pud_sect(pud))
173 return true; 174 return true;
174 175
175 pmd = pmd_offset(pud, addr); 176 pmdp = pmd_offset(pudp, addr);
176 if (pmd_none(*pmd)) 177 pmd = READ_ONCE(*pmdp);
178 if (pmd_none(pmd))
177 return false; 179 return false;
178 if (pmd_sect(*pmd)) 180 if (pmd_sect(pmd))
179 return true; 181 return true;
180 182
181 pte = pte_offset_kernel(pmd, addr); 183 ptep = pte_offset_kernel(pmdp, addr);
182 return pte_valid(*pte); 184 return pte_valid(READ_ONCE(*ptep));
183} 185}
184#endif /* CONFIG_HIBERNATION */ 186#endif /* CONFIG_HIBERNATION */
185#endif /* CONFIG_DEBUG_PAGEALLOC */ 187#endif /* CONFIG_DEBUG_PAGEALLOC */
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 71baed7e592a..c0af47617299 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -205,7 +205,8 @@ ENDPROC(idmap_cpu_replace_ttbr1)
205 dc cvac, cur_\()\type\()p // Ensure any existing dirty 205 dc cvac, cur_\()\type\()p // Ensure any existing dirty
206 dmb sy // lines are written back before 206 dmb sy // lines are written back before
207 ldr \type, [cur_\()\type\()p] // loading the entry 207 ldr \type, [cur_\()\type\()p] // loading the entry
208 tbz \type, #0, next_\()\type // Skip invalid entries 208 tbz \type, #0, skip_\()\type // Skip invalid and
209 tbnz \type, #11, skip_\()\type // non-global entries
209 .endm 210 .endm
210 211
211 .macro __idmap_kpti_put_pgtable_ent_ng, type 212 .macro __idmap_kpti_put_pgtable_ent_ng, type
@@ -265,8 +266,9 @@ ENTRY(idmap_kpti_install_ng_mappings)
265 add end_pgdp, cur_pgdp, #(PTRS_PER_PGD * 8) 266 add end_pgdp, cur_pgdp, #(PTRS_PER_PGD * 8)
266do_pgd: __idmap_kpti_get_pgtable_ent pgd 267do_pgd: __idmap_kpti_get_pgtable_ent pgd
267 tbnz pgd, #1, walk_puds 268 tbnz pgd, #1, walk_puds
268 __idmap_kpti_put_pgtable_ent_ng pgd
269next_pgd: 269next_pgd:
270 __idmap_kpti_put_pgtable_ent_ng pgd
271skip_pgd:
270 add cur_pgdp, cur_pgdp, #8 272 add cur_pgdp, cur_pgdp, #8
271 cmp cur_pgdp, end_pgdp 273 cmp cur_pgdp, end_pgdp
272 b.ne do_pgd 274 b.ne do_pgd
@@ -294,8 +296,9 @@ walk_puds:
294 add end_pudp, cur_pudp, #(PTRS_PER_PUD * 8) 296 add end_pudp, cur_pudp, #(PTRS_PER_PUD * 8)
295do_pud: __idmap_kpti_get_pgtable_ent pud 297do_pud: __idmap_kpti_get_pgtable_ent pud
296 tbnz pud, #1, walk_pmds 298 tbnz pud, #1, walk_pmds
297 __idmap_kpti_put_pgtable_ent_ng pud
298next_pud: 299next_pud:
300 __idmap_kpti_put_pgtable_ent_ng pud
301skip_pud:
299 add cur_pudp, cur_pudp, 8 302 add cur_pudp, cur_pudp, 8
300 cmp cur_pudp, end_pudp 303 cmp cur_pudp, end_pudp
301 b.ne do_pud 304 b.ne do_pud
@@ -314,8 +317,9 @@ walk_pmds:
314 add end_pmdp, cur_pmdp, #(PTRS_PER_PMD * 8) 317 add end_pmdp, cur_pmdp, #(PTRS_PER_PMD * 8)
315do_pmd: __idmap_kpti_get_pgtable_ent pmd 318do_pmd: __idmap_kpti_get_pgtable_ent pmd
316 tbnz pmd, #1, walk_ptes 319 tbnz pmd, #1, walk_ptes
317 __idmap_kpti_put_pgtable_ent_ng pmd
318next_pmd: 320next_pmd:
321 __idmap_kpti_put_pgtable_ent_ng pmd
322skip_pmd:
319 add cur_pmdp, cur_pmdp, #8 323 add cur_pmdp, cur_pmdp, #8
320 cmp cur_pmdp, end_pmdp 324 cmp cur_pmdp, end_pmdp
321 b.ne do_pmd 325 b.ne do_pmd
@@ -333,7 +337,7 @@ walk_ptes:
333 add end_ptep, cur_ptep, #(PTRS_PER_PTE * 8) 337 add end_ptep, cur_ptep, #(PTRS_PER_PTE * 8)
334do_pte: __idmap_kpti_get_pgtable_ent pte 338do_pte: __idmap_kpti_get_pgtable_ent pte
335 __idmap_kpti_put_pgtable_ent_ng pte 339 __idmap_kpti_put_pgtable_ent_ng pte
336next_pte: 340skip_pte:
337 add cur_ptep, cur_ptep, #8 341 add cur_ptep, cur_ptep, #8
338 cmp cur_ptep, end_ptep 342 cmp cur_ptep, end_ptep
339 b.ne do_pte 343 b.ne do_pte
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 1d4f1da7c58f..a93350451e8e 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -250,8 +250,9 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx)
250 off = offsetof(struct bpf_array, map.max_entries); 250 off = offsetof(struct bpf_array, map.max_entries);
251 emit_a64_mov_i64(tmp, off, ctx); 251 emit_a64_mov_i64(tmp, off, ctx);
252 emit(A64_LDR32(tmp, r2, tmp), ctx); 252 emit(A64_LDR32(tmp, r2, tmp), ctx);
253 emit(A64_MOV(0, r3, r3), ctx);
253 emit(A64_CMP(0, r3, tmp), ctx); 254 emit(A64_CMP(0, r3, tmp), ctx);
254 emit(A64_B_(A64_COND_GE, jmp_offset), ctx); 255 emit(A64_B_(A64_COND_CS, jmp_offset), ctx);
255 256
256 /* if (tail_call_cnt > MAX_TAIL_CALL_CNT) 257 /* if (tail_call_cnt > MAX_TAIL_CALL_CNT)
257 * goto out; 258 * goto out;
@@ -259,7 +260,7 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx)
259 */ 260 */
260 emit_a64_mov_i64(tmp, MAX_TAIL_CALL_CNT, ctx); 261 emit_a64_mov_i64(tmp, MAX_TAIL_CALL_CNT, ctx);
261 emit(A64_CMP(1, tcc, tmp), ctx); 262 emit(A64_CMP(1, tcc, tmp), ctx);
262 emit(A64_B_(A64_COND_GT, jmp_offset), ctx); 263 emit(A64_B_(A64_COND_HI, jmp_offset), ctx);
263 emit(A64_ADD_I(1, tcc, tcc, 1), ctx); 264 emit(A64_ADD_I(1, tcc, tcc, 1), ctx);
264 265
265 /* prog = array->ptrs[index]; 266 /* prog = array->ptrs[index];
diff --git a/arch/cris/include/arch-v10/arch/bug.h b/arch/cris/include/arch-v10/arch/bug.h
index 905afeacfedf..06da9d49152a 100644
--- a/arch/cris/include/arch-v10/arch/bug.h
+++ b/arch/cris/include/arch-v10/arch/bug.h
@@ -44,18 +44,25 @@ struct bug_frame {
44 * not be used like this with newer versions of gcc. 44 * not be used like this with newer versions of gcc.
45 */ 45 */
46#define BUG() \ 46#define BUG() \
47do { \
47 __asm__ __volatile__ ("clear.d [" __stringify(BUG_MAGIC) "]\n\t"\ 48 __asm__ __volatile__ ("clear.d [" __stringify(BUG_MAGIC) "]\n\t"\
48 "movu.w " __stringify(__LINE__) ",$r0\n\t"\ 49 "movu.w " __stringify(__LINE__) ",$r0\n\t"\
49 "jump 0f\n\t" \ 50 "jump 0f\n\t" \
50 ".section .rodata\n" \ 51 ".section .rodata\n" \
51 "0:\t.string \"" __FILE__ "\"\n\t" \ 52 "0:\t.string \"" __FILE__ "\"\n\t" \
52 ".previous") 53 ".previous"); \
54 unreachable(); \
55} while (0)
53#endif 56#endif
54 57
55#else 58#else
56 59
57/* This just causes an oops. */ 60/* This just causes an oops. */
58#define BUG() (*(int *)0 = 0) 61#define BUG() \
62do { \
63 barrier_before_unreachable(); \
64 __builtin_trap(); \
65} while (0)
59 66
60#endif 67#endif
61 68
diff --git a/arch/h8300/include/asm/byteorder.h b/arch/h8300/include/asm/byteorder.h
index ecff2d1ca5a3..6eaa7ad5fc2c 100644
--- a/arch/h8300/include/asm/byteorder.h
+++ b/arch/h8300/include/asm/byteorder.h
@@ -2,7 +2,6 @@
2#ifndef __H8300_BYTEORDER_H__ 2#ifndef __H8300_BYTEORDER_H__
3#define __H8300_BYTEORDER_H__ 3#define __H8300_BYTEORDER_H__
4 4
5#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
6#include <linux/byteorder/big_endian.h> 5#include <linux/byteorder/big_endian.h>
7 6
8#endif 7#endif
diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
index 762eeb0fcc1d..2524fb60fbc2 100644
--- a/arch/ia64/include/asm/atomic.h
+++ b/arch/ia64/include/asm/atomic.h
@@ -66,38 +66,35 @@ ATOMIC_OPS(add, +)
66ATOMIC_OPS(sub, -) 66ATOMIC_OPS(sub, -)
67 67
68#ifdef __OPTIMIZE__ 68#ifdef __OPTIMIZE__
69#define __ia64_atomic_const(i) __builtin_constant_p(i) ? \ 69#define __ia64_atomic_const(i) \
70 static const int __ia64_atomic_p = __builtin_constant_p(i) ? \
70 ((i) == 1 || (i) == 4 || (i) == 8 || (i) == 16 || \ 71 ((i) == 1 || (i) == 4 || (i) == 8 || (i) == 16 || \
71 (i) == -1 || (i) == -4 || (i) == -8 || (i) == -16) : 0 72 (i) == -1 || (i) == -4 || (i) == -8 || (i) == -16) : 0;\
73 __ia64_atomic_p
74#else
75#define __ia64_atomic_const(i) 0
76#endif
72 77
73#define atomic_add_return(i, v) \ 78#define atomic_add_return(i,v) \
74({ \ 79({ \
75 int __i = (i); \ 80 int __ia64_aar_i = (i); \
76 static const int __ia64_atomic_p = __ia64_atomic_const(i); \ 81 __ia64_atomic_const(i) \
77 __ia64_atomic_p ? ia64_fetch_and_add(__i, &(v)->counter) : \ 82 ? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
78 ia64_atomic_add(__i, v); \ 83 : ia64_atomic_add(__ia64_aar_i, v); \
79}) 84})
80 85
81#define atomic_sub_return(i, v) \ 86#define atomic_sub_return(i,v) \
82({ \ 87({ \
83 int __i = (i); \ 88 int __ia64_asr_i = (i); \
84 static const int __ia64_atomic_p = __ia64_atomic_const(i); \ 89 __ia64_atomic_const(i) \
85 __ia64_atomic_p ? ia64_fetch_and_add(-__i, &(v)->counter) : \ 90 ? ia64_fetch_and_add(-__ia64_asr_i, &(v)->counter) \
86 ia64_atomic_sub(__i, v); \ 91 : ia64_atomic_sub(__ia64_asr_i, v); \
87}) 92})
88#else
89#define atomic_add_return(i, v) ia64_atomic_add(i, v)
90#define atomic_sub_return(i, v) ia64_atomic_sub(i, v)
91#endif
92 93
93#define atomic_fetch_add(i,v) \ 94#define atomic_fetch_add(i,v) \
94({ \ 95({ \
95 int __ia64_aar_i = (i); \ 96 int __ia64_aar_i = (i); \
96 (__builtin_constant_p(i) \ 97 __ia64_atomic_const(i) \
97 && ( (__ia64_aar_i == 1) || (__ia64_aar_i == 4) \
98 || (__ia64_aar_i == 8) || (__ia64_aar_i == 16) \
99 || (__ia64_aar_i == -1) || (__ia64_aar_i == -4) \
100 || (__ia64_aar_i == -8) || (__ia64_aar_i == -16))) \
101 ? ia64_fetchadd(__ia64_aar_i, &(v)->counter, acq) \ 98 ? ia64_fetchadd(__ia64_aar_i, &(v)->counter, acq) \
102 : ia64_atomic_fetch_add(__ia64_aar_i, v); \ 99 : ia64_atomic_fetch_add(__ia64_aar_i, v); \
103}) 100})
@@ -105,11 +102,7 @@ ATOMIC_OPS(sub, -)
105#define atomic_fetch_sub(i,v) \ 102#define atomic_fetch_sub(i,v) \
106({ \ 103({ \
107 int __ia64_asr_i = (i); \ 104 int __ia64_asr_i = (i); \
108 (__builtin_constant_p(i) \ 105 __ia64_atomic_const(i) \
109 && ( (__ia64_asr_i == 1) || (__ia64_asr_i == 4) \
110 || (__ia64_asr_i == 8) || (__ia64_asr_i == 16) \
111 || (__ia64_asr_i == -1) || (__ia64_asr_i == -4) \
112 || (__ia64_asr_i == -8) || (__ia64_asr_i == -16))) \
113 ? ia64_fetchadd(-__ia64_asr_i, &(v)->counter, acq) \ 106 ? ia64_fetchadd(-__ia64_asr_i, &(v)->counter, acq) \
114 : ia64_atomic_fetch_sub(__ia64_asr_i, v); \ 107 : ia64_atomic_fetch_sub(__ia64_asr_i, v); \
115}) 108})
@@ -170,11 +163,7 @@ ATOMIC64_OPS(sub, -)
170#define atomic64_add_return(i,v) \ 163#define atomic64_add_return(i,v) \
171({ \ 164({ \
172 long __ia64_aar_i = (i); \ 165 long __ia64_aar_i = (i); \
173 (__builtin_constant_p(i) \ 166 __ia64_atomic_const(i) \
174 && ( (__ia64_aar_i == 1) || (__ia64_aar_i == 4) \
175 || (__ia64_aar_i == 8) || (__ia64_aar_i == 16) \
176 || (__ia64_aar_i == -1) || (__ia64_aar_i == -4) \
177 || (__ia64_aar_i == -8) || (__ia64_aar_i == -16))) \
178 ? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \ 167 ? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
179 : ia64_atomic64_add(__ia64_aar_i, v); \ 168 : ia64_atomic64_add(__ia64_aar_i, v); \
180}) 169})
@@ -182,11 +171,7 @@ ATOMIC64_OPS(sub, -)
182#define atomic64_sub_return(i,v) \ 171#define atomic64_sub_return(i,v) \
183({ \ 172({ \
184 long __ia64_asr_i = (i); \ 173 long __ia64_asr_i = (i); \
185 (__builtin_constant_p(i) \ 174 __ia64_atomic_const(i) \
186 && ( (__ia64_asr_i == 1) || (__ia64_asr_i == 4) \
187 || (__ia64_asr_i == 8) || (__ia64_asr_i == 16) \
188 || (__ia64_asr_i == -1) || (__ia64_asr_i == -4) \
189 || (__ia64_asr_i == -8) || (__ia64_asr_i == -16))) \
190 ? ia64_fetch_and_add(-__ia64_asr_i, &(v)->counter) \ 175 ? ia64_fetch_and_add(-__ia64_asr_i, &(v)->counter) \
191 : ia64_atomic64_sub(__ia64_asr_i, v); \ 176 : ia64_atomic64_sub(__ia64_asr_i, v); \
192}) 177})
@@ -194,11 +179,7 @@ ATOMIC64_OPS(sub, -)
194#define atomic64_fetch_add(i,v) \ 179#define atomic64_fetch_add(i,v) \
195({ \ 180({ \
196 long __ia64_aar_i = (i); \ 181 long __ia64_aar_i = (i); \
197 (__builtin_constant_p(i) \ 182 __ia64_atomic_const(i) \
198 && ( (__ia64_aar_i == 1) || (__ia64_aar_i == 4) \
199 || (__ia64_aar_i == 8) || (__ia64_aar_i == 16) \
200 || (__ia64_aar_i == -1) || (__ia64_aar_i == -4) \
201 || (__ia64_aar_i == -8) || (__ia64_aar_i == -16))) \
202 ? ia64_fetchadd(__ia64_aar_i, &(v)->counter, acq) \ 183 ? ia64_fetchadd(__ia64_aar_i, &(v)->counter, acq) \
203 : ia64_atomic64_fetch_add(__ia64_aar_i, v); \ 184 : ia64_atomic64_fetch_add(__ia64_aar_i, v); \
204}) 185})
@@ -206,11 +187,7 @@ ATOMIC64_OPS(sub, -)
206#define atomic64_fetch_sub(i,v) \ 187#define atomic64_fetch_sub(i,v) \
207({ \ 188({ \
208 long __ia64_asr_i = (i); \ 189 long __ia64_asr_i = (i); \
209 (__builtin_constant_p(i) \ 190 __ia64_atomic_const(i) \
210 && ( (__ia64_asr_i == 1) || (__ia64_asr_i == 4) \
211 || (__ia64_asr_i == 8) || (__ia64_asr_i == 16) \
212 || (__ia64_asr_i == -1) || (__ia64_asr_i == -4) \
213 || (__ia64_asr_i == -8) || (__ia64_asr_i == -16))) \
214 ? ia64_fetchadd(-__ia64_asr_i, &(v)->counter, acq) \ 191 ? ia64_fetchadd(-__ia64_asr_i, &(v)->counter, acq) \
215 : ia64_atomic64_fetch_sub(__ia64_asr_i, v); \ 192 : ia64_atomic64_fetch_sub(__ia64_asr_i, v); \
216}) 193})
diff --git a/arch/ia64/include/asm/bug.h b/arch/ia64/include/asm/bug.h
index bd3eeb8d1cfa..66b37a532765 100644
--- a/arch/ia64/include/asm/bug.h
+++ b/arch/ia64/include/asm/bug.h
@@ -4,7 +4,11 @@
4 4
5#ifdef CONFIG_BUG 5#ifdef CONFIG_BUG
6#define ia64_abort() __builtin_trap() 6#define ia64_abort() __builtin_trap()
7#define BUG() do { printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); ia64_abort(); } while (0) 7#define BUG() do { \
8 printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
9 barrier_before_unreachable(); \
10 ia64_abort(); \
11} while (0)
8 12
9/* should this BUG be made generic? */ 13/* should this BUG be made generic? */
10#define HAVE_ARCH_BUG 14#define HAVE_ARCH_BUG
diff --git a/arch/ia64/kernel/Makefile b/arch/ia64/kernel/Makefile
index 0b4c65a1af25..498f3da3f225 100644
--- a/arch/ia64/kernel/Makefile
+++ b/arch/ia64/kernel/Makefile
@@ -41,7 +41,6 @@ ifneq ($(CONFIG_IA64_ESI),)
41obj-y += esi_stub.o # must be in kernel proper 41obj-y += esi_stub.o # must be in kernel proper
42endif 42endif
43obj-$(CONFIG_INTEL_IOMMU) += pci-dma.o 43obj-$(CONFIG_INTEL_IOMMU) += pci-dma.o
44obj-$(CONFIG_SWIOTLB) += pci-swiotlb.o
45 44
46obj-$(CONFIG_BINFMT_ELF) += elfcore.o 45obj-$(CONFIG_BINFMT_ELF) += elfcore.o
47 46
diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
index 85bba43e7d5d..8b5b8e6bc9d9 100644
--- a/arch/ia64/kernel/err_inject.c
+++ b/arch/ia64/kernel/err_inject.c
@@ -117,7 +117,7 @@ store_call_start(struct device *dev, struct device_attribute *attr,
117 117
118#ifdef ERR_INJ_DEBUG 118#ifdef ERR_INJ_DEBUG
119 printk(KERN_DEBUG "Returns: status=%d,\n", (int)status[cpu]); 119 printk(KERN_DEBUG "Returns: status=%d,\n", (int)status[cpu]);
120 printk(KERN_DEBUG "capapbilities=%lx,\n", capabilities[cpu]); 120 printk(KERN_DEBUG "capabilities=%lx,\n", capabilities[cpu]);
121 printk(KERN_DEBUG "resources=%lx\n", resources[cpu]); 121 printk(KERN_DEBUG "resources=%lx\n", resources[cpu]);
122#endif 122#endif
123 return size; 123 return size;
@@ -142,7 +142,7 @@ store_virtual_to_phys(struct device *dev, struct device_attribute *attr,
142 u64 virt_addr=simple_strtoull(buf, NULL, 16); 142 u64 virt_addr=simple_strtoull(buf, NULL, 16);
143 int ret; 143 int ret;
144 144
145 ret = get_user_pages(virt_addr, 1, FOLL_WRITE, NULL, NULL); 145 ret = get_user_pages_fast(virt_addr, 1, FOLL_WRITE, NULL);
146 if (ret<=0) { 146 if (ret<=0) {
147#ifdef ERR_INJ_DEBUG 147#ifdef ERR_INJ_DEBUG
148 printk("Virtual address %lx is not existing.\n",virt_addr); 148 printk("Virtual address %lx is not existing.\n",virt_addr);
diff --git a/arch/ia64/scripts/unwcheck.py b/arch/ia64/scripts/unwcheck.py
index 89f3a1480a63..c55276e31b6b 100644
--- a/arch/ia64/scripts/unwcheck.py
+++ b/arch/ia64/scripts/unwcheck.py
@@ -16,7 +16,7 @@ import re
16import sys 16import sys
17 17
18if len(sys.argv) != 2: 18if len(sys.argv) != 2:
19 print "Usage: %s FILE" % sys.argv[0] 19 print("Usage: %s FILE" % sys.argv[0])
20 sys.exit(2) 20 sys.exit(2)
21 21
22readelf = os.getenv("READELF", "readelf") 22readelf = os.getenv("READELF", "readelf")
@@ -29,7 +29,7 @@ def check_func (func, slots, rlen_sum):
29 global num_errors 29 global num_errors
30 num_errors += 1 30 num_errors += 1
31 if not func: func = "[%#x-%#x]" % (start, end) 31 if not func: func = "[%#x-%#x]" % (start, end)
32 print "ERROR: %s: %lu slots, total region length = %lu" % (func, slots, rlen_sum) 32 print("ERROR: %s: %lu slots, total region length = %lu" % (func, slots, rlen_sum))
33 return 33 return
34 34
35num_funcs = 0 35num_funcs = 0
@@ -43,23 +43,23 @@ for line in os.popen("%s -u %s" % (readelf, sys.argv[1])):
43 check_func(func, slots, rlen_sum) 43 check_func(func, slots, rlen_sum)
44 44
45 func = m.group(1) 45 func = m.group(1)
46 start = long(m.group(2), 16) 46 start = int(m.group(2), 16)
47 end = long(m.group(3), 16) 47 end = int(m.group(3), 16)
48 slots = 3 * (end - start) / 16 48 slots = 3 * (end - start) / 16
49 rlen_sum = 0L 49 rlen_sum = 0
50 num_funcs += 1 50 num_funcs += 1
51 else: 51 else:
52 m = rlen_pattern.match(line) 52 m = rlen_pattern.match(line)
53 if m: 53 if m:
54 rlen_sum += long(m.group(1)) 54 rlen_sum += int(m.group(1))
55check_func(func, slots, rlen_sum) 55check_func(func, slots, rlen_sum)
56 56
57if num_errors == 0: 57if num_errors == 0:
58 print "No errors detected in %u functions." % num_funcs 58 print("No errors detected in %u functions." % num_funcs)
59else: 59else:
60 if num_errors > 1: 60 if num_errors > 1:
61 err="errors" 61 err="errors"
62 else: 62 else:
63 err="error" 63 err="error"
64 print "%u %s detected in %u functions." % (num_errors, err, num_funcs) 64 print("%u %s detected in %u functions." % (num_errors, err, num_funcs))
65 sys.exit(1) 65 sys.exit(1)
diff --git a/arch/m68k/include/asm/bug.h b/arch/m68k/include/asm/bug.h
index b7e2bf1ba4a6..275dca1435bf 100644
--- a/arch/m68k/include/asm/bug.h
+++ b/arch/m68k/include/asm/bug.h
@@ -8,16 +8,19 @@
8#ifndef CONFIG_SUN3 8#ifndef CONFIG_SUN3
9#define BUG() do { \ 9#define BUG() do { \
10 pr_crit("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \ 10 pr_crit("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
11 barrier_before_unreachable(); \
11 __builtin_trap(); \ 12 __builtin_trap(); \
12} while (0) 13} while (0)
13#else 14#else
14#define BUG() do { \ 15#define BUG() do { \
15 pr_crit("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \ 16 pr_crit("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
17 barrier_before_unreachable(); \
16 panic("BUG!"); \ 18 panic("BUG!"); \
17} while (0) 19} while (0)
18#endif 20#endif
19#else 21#else
20#define BUG() do { \ 22#define BUG() do { \
23 barrier_before_unreachable(); \
21 __builtin_trap(); \ 24 __builtin_trap(); \
22} while (0) 25} while (0)
23#endif 26#endif
diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig
index 4f798aa671dd..3817a3e2146c 100644
--- a/arch/microblaze/Kconfig
+++ b/arch/microblaze/Kconfig
@@ -24,6 +24,7 @@ config MICROBLAZE
24 select HAVE_FTRACE_MCOUNT_RECORD 24 select HAVE_FTRACE_MCOUNT_RECORD
25 select HAVE_FUNCTION_GRAPH_TRACER 25 select HAVE_FUNCTION_GRAPH_TRACER
26 select HAVE_FUNCTION_TRACER 26 select HAVE_FUNCTION_TRACER
27 select NO_BOOTMEM
27 select HAVE_MEMBLOCK 28 select HAVE_MEMBLOCK
28 select HAVE_MEMBLOCK_NODE_MAP 29 select HAVE_MEMBLOCK_NODE_MAP
29 select HAVE_OPROFILE 30 select HAVE_OPROFILE
diff --git a/arch/microblaze/Kconfig.platform b/arch/microblaze/Kconfig.platform
index 6996f397c16c..f7f1739c11b9 100644
--- a/arch/microblaze/Kconfig.platform
+++ b/arch/microblaze/Kconfig.platform
@@ -8,7 +8,6 @@ menu "Platform options"
8 8
9config OPT_LIB_FUNCTION 9config OPT_LIB_FUNCTION
10 bool "Optimalized lib function" 10 bool "Optimalized lib function"
11 depends on CPU_LITTLE_ENDIAN
12 default y 11 default y
13 help 12 help
14 Allows turn on optimalized library function (memcpy and memmove). 13 Allows turn on optimalized library function (memcpy and memmove).
@@ -21,6 +20,7 @@ config OPT_LIB_FUNCTION
21config OPT_LIB_ASM 20config OPT_LIB_ASM
22 bool "Optimalized lib function ASM" 21 bool "Optimalized lib function ASM"
23 depends on OPT_LIB_FUNCTION && (XILINX_MICROBLAZE0_USE_BARREL = 1) 22 depends on OPT_LIB_FUNCTION && (XILINX_MICROBLAZE0_USE_BARREL = 1)
23 depends on CPU_BIG_ENDIAN
24 default n 24 default n
25 help 25 help
26 Allows turn on optimalized library function (memcpy and memmove). 26 Allows turn on optimalized library function (memcpy and memmove).
diff --git a/arch/microblaze/include/asm/setup.h b/arch/microblaze/include/asm/setup.h
index be84a4d3917f..7c968c1d1729 100644
--- a/arch/microblaze/include/asm/setup.h
+++ b/arch/microblaze/include/asm/setup.h
@@ -44,7 +44,6 @@ void machine_shutdown(void);
44void machine_halt(void); 44void machine_halt(void);
45void machine_power_off(void); 45void machine_power_off(void);
46 46
47extern void *alloc_maybe_bootmem(size_t size, gfp_t mask);
48extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask); 47extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
49 48
50# endif /* __ASSEMBLY__ */ 49# endif /* __ASSEMBLY__ */
diff --git a/arch/microblaze/lib/fastcopy.S b/arch/microblaze/lib/fastcopy.S
index 62021d7e249e..fdc48bb065d8 100644
--- a/arch/microblaze/lib/fastcopy.S
+++ b/arch/microblaze/lib/fastcopy.S
@@ -29,10 +29,6 @@
29 * between mem locations with size of xfer spec'd in bytes 29 * between mem locations with size of xfer spec'd in bytes
30 */ 30 */
31 31
32#ifdef __MICROBLAZEEL__
33#error Microblaze LE not support ASM optimized lib func. Disable OPT_LIB_ASM.
34#endif
35
36#include <linux/linkage.h> 32#include <linux/linkage.h>
37 .text 33 .text
38 .globl memcpy 34 .globl memcpy
diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c
index 434639f9a3a6..df6de7ccdc2e 100644
--- a/arch/microblaze/mm/init.c
+++ b/arch/microblaze/mm/init.c
@@ -32,9 +32,6 @@ int mem_init_done;
32#ifndef CONFIG_MMU 32#ifndef CONFIG_MMU
33unsigned int __page_offset; 33unsigned int __page_offset;
34EXPORT_SYMBOL(__page_offset); 34EXPORT_SYMBOL(__page_offset);
35
36#else
37static int init_bootmem_done;
38#endif /* CONFIG_MMU */ 35#endif /* CONFIG_MMU */
39 36
40char *klimit = _end; 37char *klimit = _end;
@@ -117,7 +114,6 @@ static void __init paging_init(void)
117 114
118void __init setup_memory(void) 115void __init setup_memory(void)
119{ 116{
120 unsigned long map_size;
121 struct memblock_region *reg; 117 struct memblock_region *reg;
122 118
123#ifndef CONFIG_MMU 119#ifndef CONFIG_MMU
@@ -174,17 +170,6 @@ void __init setup_memory(void)
174 pr_info("%s: max_low_pfn: %#lx\n", __func__, max_low_pfn); 170 pr_info("%s: max_low_pfn: %#lx\n", __func__, max_low_pfn);
175 pr_info("%s: max_pfn: %#lx\n", __func__, max_pfn); 171 pr_info("%s: max_pfn: %#lx\n", __func__, max_pfn);
176 172
177 /*
178 * Find an area to use for the bootmem bitmap.
179 * We look for the first area which is at least
180 * 128kB in length (128kB is enough for a bitmap
181 * for 4GB of memory, using 4kB pages), plus 1 page
182 * (in case the address isn't page-aligned).
183 */
184 map_size = init_bootmem_node(NODE_DATA(0),
185 PFN_UP(TOPHYS((u32)klimit)), min_low_pfn, max_low_pfn);
186 memblock_reserve(PFN_UP(TOPHYS((u32)klimit)) << PAGE_SHIFT, map_size);
187
188 /* Add active regions with valid PFNs */ 173 /* Add active regions with valid PFNs */
189 for_each_memblock(memory, reg) { 174 for_each_memblock(memory, reg) {
190 unsigned long start_pfn, end_pfn; 175 unsigned long start_pfn, end_pfn;
@@ -196,32 +181,9 @@ void __init setup_memory(void)
196 &memblock.memory, 0); 181 &memblock.memory, 0);
197 } 182 }
198 183
199 /* free bootmem is whole main memory */
200 free_bootmem_with_active_regions(0, max_low_pfn);
201
202 /* reserve allocate blocks */
203 for_each_memblock(reserved, reg) {
204 unsigned long top = reg->base + reg->size - 1;
205
206 pr_debug("reserved - 0x%08x-0x%08x, %lx, %lx\n",
207 (u32) reg->base, (u32) reg->size, top,
208 memory_start + lowmem_size - 1);
209
210 if (top <= (memory_start + lowmem_size - 1)) {
211 reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
212 } else if (reg->base < (memory_start + lowmem_size - 1)) {
213 unsigned long trunc_size = memory_start + lowmem_size -
214 reg->base;
215 reserve_bootmem(reg->base, trunc_size, BOOTMEM_DEFAULT);
216 }
217 }
218
219 /* XXX need to clip this if using highmem? */ 184 /* XXX need to clip this if using highmem? */
220 sparse_memory_present_with_active_regions(0); 185 sparse_memory_present_with_active_regions(0);
221 186
222#ifdef CONFIG_MMU
223 init_bootmem_done = 1;
224#endif
225 paging_init(); 187 paging_init();
226} 188}
227 189
@@ -398,30 +360,16 @@ asmlinkage void __init mmu_init(void)
398/* This is only called until mem_init is done. */ 360/* This is only called until mem_init is done. */
399void __init *early_get_page(void) 361void __init *early_get_page(void)
400{ 362{
401 void *p; 363 /*
402 if (init_bootmem_done) { 364 * Mem start + kernel_tlb -> here is limit
403 p = alloc_bootmem_pages(PAGE_SIZE); 365 * because of mem mapping from head.S
404 } else { 366 */
405 /* 367 return __va(memblock_alloc_base(PAGE_SIZE, PAGE_SIZE,
406 * Mem start + kernel_tlb -> here is limit 368 memory_start + kernel_tlb));
407 * because of mem mapping from head.S
408 */
409 p = __va(memblock_alloc_base(PAGE_SIZE, PAGE_SIZE,
410 memory_start + kernel_tlb));
411 }
412 return p;
413} 369}
414 370
415#endif /* CONFIG_MMU */ 371#endif /* CONFIG_MMU */
416 372
417void * __ref alloc_maybe_bootmem(size_t size, gfp_t mask)
418{
419 if (mem_init_done)
420 return kmalloc(size, mask);
421 else
422 return alloc_bootmem(size);
423}
424
425void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask) 373void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask)
426{ 374{
427 void *p; 375 void *p;
diff --git a/arch/mips/ath25/board.c b/arch/mips/ath25/board.c
index 9ab48ff80c1c..6d11ae581ea7 100644
--- a/arch/mips/ath25/board.c
+++ b/arch/mips/ath25/board.c
@@ -135,6 +135,8 @@ int __init ath25_find_config(phys_addr_t base, unsigned long size)
135 } 135 }
136 136
137 board_data = kzalloc(BOARD_CONFIG_BUFSZ, GFP_KERNEL); 137 board_data = kzalloc(BOARD_CONFIG_BUFSZ, GFP_KERNEL);
138 if (!board_data)
139 goto error;
138 ath25_board.config = (struct ath25_boarddata *)board_data; 140 ath25_board.config = (struct ath25_boarddata *)board_data;
139 memcpy_fromio(board_data, bcfg, 0x100); 141 memcpy_fromio(board_data, bcfg, 0x100);
140 if (broken_boarddata) { 142 if (broken_boarddata) {
diff --git a/arch/mips/boot/Makefile b/arch/mips/boot/Makefile
index 1bd5c4f00d19..c22da16d67b8 100644
--- a/arch/mips/boot/Makefile
+++ b/arch/mips/boot/Makefile
@@ -126,6 +126,7 @@ $(obj)/vmlinux.its.S: $(addprefix $(srctree)/arch/mips/$(PLATFORM)/,$(ITS_INPUTS
126 126
127quiet_cmd_cpp_its_S = ITS $@ 127quiet_cmd_cpp_its_S = ITS $@
128 cmd_cpp_its_S = $(CPP) $(cpp_flags) -P -C -o $@ $< \ 128 cmd_cpp_its_S = $(CPP) $(cpp_flags) -P -C -o $@ $< \
129 -D__ASSEMBLY__ \
129 -DKERNEL_NAME="\"Linux $(KERNELRELEASE)\"" \ 130 -DKERNEL_NAME="\"Linux $(KERNELRELEASE)\"" \
130 -DVMLINUX_BINARY="\"$(3)\"" \ 131 -DVMLINUX_BINARY="\"$(3)\"" \
131 -DVMLINUX_COMPRESSION="\"$(2)\"" \ 132 -DVMLINUX_COMPRESSION="\"$(2)\"" \
diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon/octeon-irq.c
index 5b3a3f6a9ad3..d99f5242169e 100644
--- a/arch/mips/cavium-octeon/octeon-irq.c
+++ b/arch/mips/cavium-octeon/octeon-irq.c
@@ -2277,6 +2277,8 @@ static int __init octeon_irq_init_cib(struct device_node *ciu_node,
2277 } 2277 }
2278 2278
2279 host_data = kzalloc(sizeof(*host_data), GFP_KERNEL); 2279 host_data = kzalloc(sizeof(*host_data), GFP_KERNEL);
2280 if (!host_data)
2281 return -ENOMEM;
2280 raw_spin_lock_init(&host_data->lock); 2282 raw_spin_lock_init(&host_data->lock);
2281 2283
2282 addr = of_get_address(ciu_node, 0, NULL, NULL); 2284 addr = of_get_address(ciu_node, 0, NULL, NULL);
diff --git a/arch/mips/include/asm/compat.h b/arch/mips/include/asm/compat.h
index 946681db8dc3..9a0fa66b81ac 100644
--- a/arch/mips/include/asm/compat.h
+++ b/arch/mips/include/asm/compat.h
@@ -86,7 +86,6 @@ struct compat_flock {
86 compat_off_t l_len; 86 compat_off_t l_len;
87 s32 l_sysid; 87 s32 l_sysid;
88 compat_pid_t l_pid; 88 compat_pid_t l_pid;
89 short __unused;
90 s32 pad[4]; 89 s32 pad[4];
91}; 90};
92 91
diff --git a/arch/mips/kernel/mips-cpc.c b/arch/mips/kernel/mips-cpc.c
index 19c88d770054..fcf9af492d60 100644
--- a/arch/mips/kernel/mips-cpc.c
+++ b/arch/mips/kernel/mips-cpc.c
@@ -10,6 +10,8 @@
10 10
11#include <linux/errno.h> 11#include <linux/errno.h>
12#include <linux/percpu.h> 12#include <linux/percpu.h>
13#include <linux/of.h>
14#include <linux/of_address.h>
13#include <linux/spinlock.h> 15#include <linux/spinlock.h>
14 16
15#include <asm/mips-cps.h> 17#include <asm/mips-cps.h>
@@ -22,6 +24,17 @@ static DEFINE_PER_CPU_ALIGNED(unsigned long, cpc_core_lock_flags);
22 24
23phys_addr_t __weak mips_cpc_default_phys_base(void) 25phys_addr_t __weak mips_cpc_default_phys_base(void)
24{ 26{
27 struct device_node *cpc_node;
28 struct resource res;
29 int err;
30
31 cpc_node = of_find_compatible_node(of_root, NULL, "mti,mips-cpc");
32 if (cpc_node) {
33 err = of_address_to_resource(cpc_node, 0, &res);
34 if (!err)
35 return res.start;
36 }
37
25 return 0; 38 return 0;
26} 39}
27 40
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 85bc601e9a0d..5f8b0a9e30b3 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -375,6 +375,7 @@ static void __init bootmem_init(void)
375 unsigned long reserved_end; 375 unsigned long reserved_end;
376 unsigned long mapstart = ~0UL; 376 unsigned long mapstart = ~0UL;
377 unsigned long bootmap_size; 377 unsigned long bootmap_size;
378 phys_addr_t ramstart = (phys_addr_t)ULLONG_MAX;
378 bool bootmap_valid = false; 379 bool bootmap_valid = false;
379 int i; 380 int i;
380 381
@@ -395,7 +396,8 @@ static void __init bootmem_init(void)
395 max_low_pfn = 0; 396 max_low_pfn = 0;
396 397
397 /* 398 /*
398 * Find the highest page frame number we have available. 399 * Find the highest page frame number we have available
400 * and the lowest used RAM address
399 */ 401 */
400 for (i = 0; i < boot_mem_map.nr_map; i++) { 402 for (i = 0; i < boot_mem_map.nr_map; i++) {
401 unsigned long start, end; 403 unsigned long start, end;
@@ -407,6 +409,8 @@ static void __init bootmem_init(void)
407 end = PFN_DOWN(boot_mem_map.map[i].addr 409 end = PFN_DOWN(boot_mem_map.map[i].addr
408 + boot_mem_map.map[i].size); 410 + boot_mem_map.map[i].size);
409 411
412 ramstart = min(ramstart, boot_mem_map.map[i].addr);
413
410#ifndef CONFIG_HIGHMEM 414#ifndef CONFIG_HIGHMEM
411 /* 415 /*
412 * Skip highmem here so we get an accurate max_low_pfn if low 416 * Skip highmem here so we get an accurate max_low_pfn if low
@@ -436,6 +440,13 @@ static void __init bootmem_init(void)
436 mapstart = max(reserved_end, start); 440 mapstart = max(reserved_end, start);
437 } 441 }
438 442
443 /*
444 * Reserve any memory between the start of RAM and PHYS_OFFSET
445 */
446 if (ramstart > PHYS_OFFSET)
447 add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET,
448 BOOT_MEM_RESERVED);
449
439 if (min_low_pfn >= max_low_pfn) 450 if (min_low_pfn >= max_low_pfn)
440 panic("Incorrect memory mapping !!!"); 451 panic("Incorrect memory mapping !!!");
441 if (min_low_pfn > ARCH_PFN_OFFSET) { 452 if (min_low_pfn > ARCH_PFN_OFFSET) {
@@ -664,9 +675,6 @@ static int __init early_parse_mem(char *p)
664 675
665 add_memory_region(start, size, BOOT_MEM_RAM); 676 add_memory_region(start, size, BOOT_MEM_RAM);
666 677
667 if (start && start > PHYS_OFFSET)
668 add_memory_region(PHYS_OFFSET, start - PHYS_OFFSET,
669 BOOT_MEM_RESERVED);
670 return 0; 678 return 0;
671} 679}
672early_param("mem", early_parse_mem); 680early_param("mem", early_parse_mem);
diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
index 87dcac2447c8..159e83add4bb 100644
--- a/arch/mips/kernel/smp-bmips.c
+++ b/arch/mips/kernel/smp-bmips.c
@@ -168,11 +168,11 @@ static void bmips_prepare_cpus(unsigned int max_cpus)
168 return; 168 return;
169 } 169 }
170 170
171 if (request_irq(IPI0_IRQ, bmips_ipi_interrupt, IRQF_PERCPU, 171 if (request_irq(IPI0_IRQ, bmips_ipi_interrupt,
172 "smp_ipi0", NULL)) 172 IRQF_PERCPU | IRQF_NO_SUSPEND, "smp_ipi0", NULL))
173 panic("Can't request IPI0 interrupt"); 173 panic("Can't request IPI0 interrupt");
174 if (request_irq(IPI1_IRQ, bmips_ipi_interrupt, IRQF_PERCPU, 174 if (request_irq(IPI1_IRQ, bmips_ipi_interrupt,
175 "smp_ipi1", NULL)) 175 IRQF_PERCPU | IRQF_NO_SUSPEND, "smp_ipi1", NULL))
176 panic("Can't request IPI1 interrupt"); 176 panic("Can't request IPI1 interrupt");
177} 177}
178 178
@@ -572,7 +572,7 @@ asmlinkage void __weak plat_wired_tlb_setup(void)
572 */ 572 */
573} 573}
574 574
575void __init bmips_cpu_setup(void) 575void bmips_cpu_setup(void)
576{ 576{
577 void __iomem __maybe_unused *cbr = BMIPS_GET_CBR(); 577 void __iomem __maybe_unused *cbr = BMIPS_GET_CBR();
578 u32 __maybe_unused cfg; 578 u32 __maybe_unused cfg;
diff --git a/arch/mips/lantiq/Kconfig b/arch/mips/lantiq/Kconfig
index 692ae85a3e3d..8e3a1fc2bc39 100644
--- a/arch/mips/lantiq/Kconfig
+++ b/arch/mips/lantiq/Kconfig
@@ -13,6 +13,8 @@ choice
13config SOC_AMAZON_SE 13config SOC_AMAZON_SE
14 bool "Amazon SE" 14 bool "Amazon SE"
15 select SOC_TYPE_XWAY 15 select SOC_TYPE_XWAY
16 select MFD_SYSCON
17 select MFD_CORE
16 18
17config SOC_XWAY 19config SOC_XWAY
18 bool "XWAY" 20 bool "XWAY"
diff --git a/arch/mips/lantiq/xway/sysctrl.c b/arch/mips/lantiq/xway/sysctrl.c
index 52500d3b7004..e0af39b33e28 100644
--- a/arch/mips/lantiq/xway/sysctrl.c
+++ b/arch/mips/lantiq/xway/sysctrl.c
@@ -549,9 +549,9 @@ void __init ltq_soc_init(void)
549 clkdev_add_static(ltq_ar9_cpu_hz(), ltq_ar9_fpi_hz(), 549 clkdev_add_static(ltq_ar9_cpu_hz(), ltq_ar9_fpi_hz(),
550 ltq_ar9_fpi_hz(), CLOCK_250M); 550 ltq_ar9_fpi_hz(), CLOCK_250M);
551 clkdev_add_pmu("1f203018.usb2-phy", "phy", 1, 0, PMU_USB0_P); 551 clkdev_add_pmu("1f203018.usb2-phy", "phy", 1, 0, PMU_USB0_P);
552 clkdev_add_pmu("1e101000.usb", "otg", 1, 0, PMU_USB0); 552 clkdev_add_pmu("1e101000.usb", "otg", 1, 0, PMU_USB0 | PMU_AHBM);
553 clkdev_add_pmu("1f203034.usb2-phy", "phy", 1, 0, PMU_USB1_P); 553 clkdev_add_pmu("1f203034.usb2-phy", "phy", 1, 0, PMU_USB1_P);
554 clkdev_add_pmu("1e106000.usb", "otg", 1, 0, PMU_USB1); 554 clkdev_add_pmu("1e106000.usb", "otg", 1, 0, PMU_USB1 | PMU_AHBM);
555 clkdev_add_pmu("1e180000.etop", "switch", 1, 0, PMU_SWITCH); 555 clkdev_add_pmu("1e180000.etop", "switch", 1, 0, PMU_SWITCH);
556 clkdev_add_pmu("1e103000.sdio", NULL, 1, 0, PMU_SDIO); 556 clkdev_add_pmu("1e103000.sdio", NULL, 1, 0, PMU_SDIO);
557 clkdev_add_pmu("1e103100.deu", NULL, 1, 0, PMU_DEU); 557 clkdev_add_pmu("1e103100.deu", NULL, 1, 0, PMU_DEU);
@@ -560,7 +560,7 @@ void __init ltq_soc_init(void)
560 } else { 560 } else {
561 clkdev_add_static(ltq_danube_cpu_hz(), ltq_danube_fpi_hz(), 561 clkdev_add_static(ltq_danube_cpu_hz(), ltq_danube_fpi_hz(),
562 ltq_danube_fpi_hz(), ltq_danube_pp32_hz()); 562 ltq_danube_fpi_hz(), ltq_danube_pp32_hz());
563 clkdev_add_pmu("1f203018.usb2-phy", "ctrl", 1, 0, PMU_USB0); 563 clkdev_add_pmu("1e101000.usb", "otg", 1, 0, PMU_USB0 | PMU_AHBM);
564 clkdev_add_pmu("1f203018.usb2-phy", "phy", 1, 0, PMU_USB0_P); 564 clkdev_add_pmu("1f203018.usb2-phy", "phy", 1, 0, PMU_USB0_P);
565 clkdev_add_pmu("1e103000.sdio", NULL, 1, 0, PMU_SDIO); 565 clkdev_add_pmu("1e103000.sdio", NULL, 1, 0, PMU_SDIO);
566 clkdev_add_pmu("1e103100.deu", NULL, 1, 0, PMU_DEU); 566 clkdev_add_pmu("1e103100.deu", NULL, 1, 0, PMU_DEU);
diff --git a/arch/mips/loongson64/Kconfig b/arch/mips/loongson64/Kconfig
index bc2fdbfa8223..72af0c183969 100644
--- a/arch/mips/loongson64/Kconfig
+++ b/arch/mips/loongson64/Kconfig
@@ -7,6 +7,8 @@ choice
7config LEMOTE_FULOONG2E 7config LEMOTE_FULOONG2E
8 bool "Lemote Fuloong(2e) mini-PC" 8 bool "Lemote Fuloong(2e) mini-PC"
9 select ARCH_SPARSEMEM_ENABLE 9 select ARCH_SPARSEMEM_ENABLE
10 select ARCH_MIGHT_HAVE_PC_PARPORT
11 select ARCH_MIGHT_HAVE_PC_SERIO
10 select CEVT_R4K 12 select CEVT_R4K
11 select CSRC_R4K 13 select CSRC_R4K
12 select SYS_HAS_CPU_LOONGSON2E 14 select SYS_HAS_CPU_LOONGSON2E
@@ -33,6 +35,8 @@ config LEMOTE_FULOONG2E
33config LEMOTE_MACH2F 35config LEMOTE_MACH2F
34 bool "Lemote Loongson 2F family machines" 36 bool "Lemote Loongson 2F family machines"
35 select ARCH_SPARSEMEM_ENABLE 37 select ARCH_SPARSEMEM_ENABLE
38 select ARCH_MIGHT_HAVE_PC_PARPORT
39 select ARCH_MIGHT_HAVE_PC_SERIO
36 select BOARD_SCACHE 40 select BOARD_SCACHE
37 select BOOT_ELF32 41 select BOOT_ELF32
38 select CEVT_R4K if ! MIPS_EXTERNAL_TIMER 42 select CEVT_R4K if ! MIPS_EXTERNAL_TIMER
@@ -62,6 +66,8 @@ config LEMOTE_MACH2F
62config LOONGSON_MACH3X 66config LOONGSON_MACH3X
63 bool "Generic Loongson 3 family machines" 67 bool "Generic Loongson 3 family machines"
64 select ARCH_SPARSEMEM_ENABLE 68 select ARCH_SPARSEMEM_ENABLE
69 select ARCH_MIGHT_HAVE_PC_PARPORT
70 select ARCH_MIGHT_HAVE_PC_SERIO
65 select GENERIC_ISA_DMA_SUPPORT_BROKEN 71 select GENERIC_ISA_DMA_SUPPORT_BROKEN
66 select BOOT_ELF32 72 select BOOT_ELF32
67 select BOARD_SCACHE 73 select BOARD_SCACHE
diff --git a/arch/mips/ralink/mt7621.c b/arch/mips/ralink/mt7621.c
index 1b274742077d..d2718de60b9b 100644
--- a/arch/mips/ralink/mt7621.c
+++ b/arch/mips/ralink/mt7621.c
@@ -170,6 +170,28 @@ void prom_soc_init(struct ralink_soc_info *soc_info)
170 u32 n1; 170 u32 n1;
171 u32 rev; 171 u32 rev;
172 172
173 /* Early detection of CMP support */
174 mips_cm_probe();
175 mips_cpc_probe();
176
177 if (mips_cps_numiocu(0)) {
178 /*
179 * mips_cm_probe() wipes out bootloader
180 * config for CM regions and we have to configure them
181 * again. This SoC cannot talk to pamlbus devices
182 * witout proper iocu region set up.
183 *
184 * FIXME: it would be better to do this with values
185 * from DT, but we need this very early because
186 * without this we cannot talk to pretty much anything
187 * including serial.
188 */
189 write_gcr_reg0_base(MT7621_PALMBUS_BASE);
190 write_gcr_reg0_mask(~MT7621_PALMBUS_SIZE |
191 CM_GCR_REGn_MASK_CMTGT_IOCU0);
192 __sync();
193 }
194
173 n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0); 195 n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
174 n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1); 196 n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
175 197
@@ -194,26 +216,6 @@ void prom_soc_init(struct ralink_soc_info *soc_info)
194 216
195 rt2880_pinmux_data = mt7621_pinmux_data; 217 rt2880_pinmux_data = mt7621_pinmux_data;
196 218
197 /* Early detection of CMP support */
198 mips_cm_probe();
199 mips_cpc_probe();
200
201 if (mips_cps_numiocu(0)) {
202 /*
203 * mips_cm_probe() wipes out bootloader
204 * config for CM regions and we have to configure them
205 * again. This SoC cannot talk to pamlbus devices
206 * witout proper iocu region set up.
207 *
208 * FIXME: it would be better to do this with values
209 * from DT, but we need this very early because
210 * without this we cannot talk to pretty much anything
211 * including serial.
212 */
213 write_gcr_reg0_base(MT7621_PALMBUS_BASE);
214 write_gcr_reg0_mask(~MT7621_PALMBUS_SIZE |
215 CM_GCR_REGn_MASK_CMTGT_IOCU0);
216 }
217 219
218 if (!register_cps_smp_ops()) 220 if (!register_cps_smp_ops())
219 return; 221 return;
diff --git a/arch/mips/ralink/reset.c b/arch/mips/ralink/reset.c
index 64543d66e76b..e9531fea23a2 100644
--- a/arch/mips/ralink/reset.c
+++ b/arch/mips/ralink/reset.c
@@ -96,16 +96,9 @@ static void ralink_restart(char *command)
96 unreachable(); 96 unreachable();
97} 97}
98 98
99static void ralink_halt(void)
100{
101 local_irq_disable();
102 unreachable();
103}
104
105static int __init mips_reboot_setup(void) 99static int __init mips_reboot_setup(void)
106{ 100{
107 _machine_restart = ralink_restart; 101 _machine_restart = ralink_restart;
108 _machine_halt = ralink_halt;
109 102
110 return 0; 103 return 0;
111} 104}
diff --git a/arch/parisc/include/asm/cacheflush.h b/arch/parisc/include/asm/cacheflush.h
index 3742508cc534..bd5ce31936f5 100644
--- a/arch/parisc/include/asm/cacheflush.h
+++ b/arch/parisc/include/asm/cacheflush.h
@@ -26,6 +26,7 @@ void flush_user_icache_range_asm(unsigned long, unsigned long);
26void flush_kernel_icache_range_asm(unsigned long, unsigned long); 26void flush_kernel_icache_range_asm(unsigned long, unsigned long);
27void flush_user_dcache_range_asm(unsigned long, unsigned long); 27void flush_user_dcache_range_asm(unsigned long, unsigned long);
28void flush_kernel_dcache_range_asm(unsigned long, unsigned long); 28void flush_kernel_dcache_range_asm(unsigned long, unsigned long);
29void purge_kernel_dcache_range_asm(unsigned long, unsigned long);
29void flush_kernel_dcache_page_asm(void *); 30void flush_kernel_dcache_page_asm(void *);
30void flush_kernel_icache_page(void *); 31void flush_kernel_icache_page(void *);
31 32
diff --git a/arch/parisc/include/asm/processor.h b/arch/parisc/include/asm/processor.h
index 0e6ab6e4a4e9..2dbe5580a1a4 100644
--- a/arch/parisc/include/asm/processor.h
+++ b/arch/parisc/include/asm/processor.h
@@ -316,6 +316,8 @@ extern int _parisc_requires_coherency;
316#define parisc_requires_coherency() (0) 316#define parisc_requires_coherency() (0)
317#endif 317#endif
318 318
319extern int running_on_qemu;
320
319#endif /* __ASSEMBLY__ */ 321#endif /* __ASSEMBLY__ */
320 322
321#endif /* __ASM_PARISC_PROCESSOR_H */ 323#endif /* __ASM_PARISC_PROCESSOR_H */
diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
index 19c0c141bc3f..e3b45546d589 100644
--- a/arch/parisc/kernel/cache.c
+++ b/arch/parisc/kernel/cache.c
@@ -465,10 +465,10 @@ EXPORT_SYMBOL(copy_user_page);
465int __flush_tlb_range(unsigned long sid, unsigned long start, 465int __flush_tlb_range(unsigned long sid, unsigned long start,
466 unsigned long end) 466 unsigned long end)
467{ 467{
468 unsigned long flags, size; 468 unsigned long flags;
469 469
470 size = (end - start); 470 if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
471 if (size >= parisc_tlb_flush_threshold) { 471 end - start >= parisc_tlb_flush_threshold) {
472 flush_tlb_all(); 472 flush_tlb_all();
473 return 1; 473 return 1;
474 } 474 }
@@ -539,13 +539,12 @@ void flush_cache_mm(struct mm_struct *mm)
539 struct vm_area_struct *vma; 539 struct vm_area_struct *vma;
540 pgd_t *pgd; 540 pgd_t *pgd;
541 541
542 /* Flush the TLB to avoid speculation if coherency is required. */
543 if (parisc_requires_coherency())
544 flush_tlb_all();
545
546 /* Flushing the whole cache on each cpu takes forever on 542 /* Flushing the whole cache on each cpu takes forever on
547 rp3440, etc. So, avoid it if the mm isn't too big. */ 543 rp3440, etc. So, avoid it if the mm isn't too big. */
548 if (mm_total_size(mm) >= parisc_cache_flush_threshold) { 544 if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
545 mm_total_size(mm) >= parisc_cache_flush_threshold) {
546 if (mm->context)
547 flush_tlb_all();
549 flush_cache_all(); 548 flush_cache_all();
550 return; 549 return;
551 } 550 }
@@ -553,9 +552,9 @@ void flush_cache_mm(struct mm_struct *mm)
553 if (mm->context == mfsp(3)) { 552 if (mm->context == mfsp(3)) {
554 for (vma = mm->mmap; vma; vma = vma->vm_next) { 553 for (vma = mm->mmap; vma; vma = vma->vm_next) {
555 flush_user_dcache_range_asm(vma->vm_start, vma->vm_end); 554 flush_user_dcache_range_asm(vma->vm_start, vma->vm_end);
556 if ((vma->vm_flags & VM_EXEC) == 0) 555 if (vma->vm_flags & VM_EXEC)
557 continue; 556 flush_user_icache_range_asm(vma->vm_start, vma->vm_end);
558 flush_user_icache_range_asm(vma->vm_start, vma->vm_end); 557 flush_tlb_range(vma, vma->vm_start, vma->vm_end);
559 } 558 }
560 return; 559 return;
561 } 560 }
@@ -573,6 +572,8 @@ void flush_cache_mm(struct mm_struct *mm)
573 pfn = pte_pfn(*ptep); 572 pfn = pte_pfn(*ptep);
574 if (!pfn_valid(pfn)) 573 if (!pfn_valid(pfn))
575 continue; 574 continue;
575 if (unlikely(mm->context))
576 flush_tlb_page(vma, addr);
576 __flush_cache_page(vma, addr, PFN_PHYS(pfn)); 577 __flush_cache_page(vma, addr, PFN_PHYS(pfn));
577 } 578 }
578 } 579 }
@@ -581,30 +582,45 @@ void flush_cache_mm(struct mm_struct *mm)
581void flush_cache_range(struct vm_area_struct *vma, 582void flush_cache_range(struct vm_area_struct *vma,
582 unsigned long start, unsigned long end) 583 unsigned long start, unsigned long end)
583{ 584{
584 BUG_ON(!vma->vm_mm->context); 585 pgd_t *pgd;
585 586 unsigned long addr;
586 /* Flush the TLB to avoid speculation if coherency is required. */
587 if (parisc_requires_coherency())
588 flush_tlb_range(vma, start, end);
589 587
590 if ((end - start) >= parisc_cache_flush_threshold 588 if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
591 || vma->vm_mm->context != mfsp(3)) { 589 end - start >= parisc_cache_flush_threshold) {
590 if (vma->vm_mm->context)
591 flush_tlb_range(vma, start, end);
592 flush_cache_all(); 592 flush_cache_all();
593 return; 593 return;
594 } 594 }
595 595
596 flush_user_dcache_range_asm(start, end); 596 if (vma->vm_mm->context == mfsp(3)) {
597 if (vma->vm_flags & VM_EXEC) 597 flush_user_dcache_range_asm(start, end);
598 flush_user_icache_range_asm(start, end); 598 if (vma->vm_flags & VM_EXEC)
599 flush_user_icache_range_asm(start, end);
600 flush_tlb_range(vma, start, end);
601 return;
602 }
603
604 pgd = vma->vm_mm->pgd;
605 for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) {
606 unsigned long pfn;
607 pte_t *ptep = get_ptep(pgd, addr);
608 if (!ptep)
609 continue;
610 pfn = pte_pfn(*ptep);
611 if (pfn_valid(pfn)) {
612 if (unlikely(vma->vm_mm->context))
613 flush_tlb_page(vma, addr);
614 __flush_cache_page(vma, addr, PFN_PHYS(pfn));
615 }
616 }
599} 617}
600 618
601void 619void
602flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn) 620flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
603{ 621{
604 BUG_ON(!vma->vm_mm->context);
605
606 if (pfn_valid(pfn)) { 622 if (pfn_valid(pfn)) {
607 if (parisc_requires_coherency()) 623 if (likely(vma->vm_mm->context))
608 flush_tlb_page(vma, vmaddr); 624 flush_tlb_page(vma, vmaddr);
609 __flush_cache_page(vma, vmaddr, PFN_PHYS(pfn)); 625 __flush_cache_page(vma, vmaddr, PFN_PHYS(pfn));
610 } 626 }
@@ -613,21 +629,33 @@ flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long
613void flush_kernel_vmap_range(void *vaddr, int size) 629void flush_kernel_vmap_range(void *vaddr, int size)
614{ 630{
615 unsigned long start = (unsigned long)vaddr; 631 unsigned long start = (unsigned long)vaddr;
632 unsigned long end = start + size;
616 633
617 if ((unsigned long)size > parisc_cache_flush_threshold) 634 if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
635 (unsigned long)size >= parisc_cache_flush_threshold) {
636 flush_tlb_kernel_range(start, end);
618 flush_data_cache(); 637 flush_data_cache();
619 else 638 return;
620 flush_kernel_dcache_range_asm(start, start + size); 639 }
640
641 flush_kernel_dcache_range_asm(start, end);
642 flush_tlb_kernel_range(start, end);
621} 643}
622EXPORT_SYMBOL(flush_kernel_vmap_range); 644EXPORT_SYMBOL(flush_kernel_vmap_range);
623 645
624void invalidate_kernel_vmap_range(void *vaddr, int size) 646void invalidate_kernel_vmap_range(void *vaddr, int size)
625{ 647{
626 unsigned long start = (unsigned long)vaddr; 648 unsigned long start = (unsigned long)vaddr;
649 unsigned long end = start + size;
627 650
628 if ((unsigned long)size > parisc_cache_flush_threshold) 651 if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
652 (unsigned long)size >= parisc_cache_flush_threshold) {
653 flush_tlb_kernel_range(start, end);
629 flush_data_cache(); 654 flush_data_cache();
630 else 655 return;
631 flush_kernel_dcache_range_asm(start, start + size); 656 }
657
658 purge_kernel_dcache_range_asm(start, end);
659 flush_tlb_kernel_range(start, end);
632} 660}
633EXPORT_SYMBOL(invalidate_kernel_vmap_range); 661EXPORT_SYMBOL(invalidate_kernel_vmap_range);
diff --git a/arch/parisc/kernel/head.S b/arch/parisc/kernel/head.S
index bbbe360b458f..fbb4e43fda05 100644
--- a/arch/parisc/kernel/head.S
+++ b/arch/parisc/kernel/head.S
@@ -138,6 +138,16 @@ $pgt_fill_loop:
138 std %dp,0x18(%r10) 138 std %dp,0x18(%r10)
139#endif 139#endif
140 140
141#ifdef CONFIG_64BIT
142 /* Get PDCE_PROC for monarch CPU. */
143#define MEM_PDC_LO 0x388
144#define MEM_PDC_HI 0x35C
145 ldw MEM_PDC_LO(%r0),%r3
146 ldw MEM_PDC_HI(%r0),%r10
147 depd %r10, 31, 32, %r3 /* move to upper word */
148#endif
149
150
141#ifdef CONFIG_SMP 151#ifdef CONFIG_SMP
142 /* Set the smp rendezvous address into page zero. 152 /* Set the smp rendezvous address into page zero.
143 ** It would be safer to do this in init_smp_config() but 153 ** It would be safer to do this in init_smp_config() but
@@ -196,12 +206,6 @@ common_stext:
196 ** Someday, palo might not do this for the Monarch either. 206 ** Someday, palo might not do this for the Monarch either.
197 */ 207 */
1982: 2082:
199#define MEM_PDC_LO 0x388
200#define MEM_PDC_HI 0x35C
201 ldw MEM_PDC_LO(%r0),%r3
202 ldw MEM_PDC_HI(%r0),%r6
203 depd %r6, 31, 32, %r3 /* move to upper word */
204
205 mfctl %cr30,%r6 /* PCX-W2 firmware bug */ 209 mfctl %cr30,%r6 /* PCX-W2 firmware bug */
206 210
207 ldo PDC_PSW(%r0),%arg0 /* 21 */ 211 ldo PDC_PSW(%r0),%arg0 /* 21 */
@@ -268,6 +272,8 @@ $install_iva:
268aligned_rfi: 272aligned_rfi:
269 pcxt_ssm_bug 273 pcxt_ssm_bug
270 274
275 copy %r3, %arg0 /* PDCE_PROC for smp_callin() */
276
271 rsm PSW_SM_QUIET,%r0 /* off troublesome PSW bits */ 277 rsm PSW_SM_QUIET,%r0 /* off troublesome PSW bits */
272 /* Don't need NOPs, have 8 compliant insn before rfi */ 278 /* Don't need NOPs, have 8 compliant insn before rfi */
273 279
diff --git a/arch/parisc/kernel/pacache.S b/arch/parisc/kernel/pacache.S
index 2d40c4ff3f69..67b0f7532e83 100644
--- a/arch/parisc/kernel/pacache.S
+++ b/arch/parisc/kernel/pacache.S
@@ -1110,6 +1110,28 @@ ENTRY_CFI(flush_kernel_dcache_range_asm)
1110 .procend 1110 .procend
1111ENDPROC_CFI(flush_kernel_dcache_range_asm) 1111ENDPROC_CFI(flush_kernel_dcache_range_asm)
1112 1112
1113ENTRY_CFI(purge_kernel_dcache_range_asm)
1114 .proc
1115 .callinfo NO_CALLS
1116 .entry
1117
1118 ldil L%dcache_stride, %r1
1119 ldw R%dcache_stride(%r1), %r23
1120 ldo -1(%r23), %r21
1121 ANDCM %r26, %r21, %r26
1122
11231: cmpb,COND(<<),n %r26, %r25,1b
1124 pdc,m %r23(%r26)
1125
1126 sync
1127 syncdma
1128 bv %r0(%r2)
1129 nop
1130 .exit
1131
1132 .procend
1133ENDPROC_CFI(purge_kernel_dcache_range_asm)
1134
1113ENTRY_CFI(flush_user_icache_range_asm) 1135ENTRY_CFI(flush_user_icache_range_asm)
1114 .proc 1136 .proc
1115 .callinfo NO_CALLS 1137 .callinfo NO_CALLS
diff --git a/arch/parisc/kernel/smp.c b/arch/parisc/kernel/smp.c
index 30c28ab14540..4065b5e48c9d 100644
--- a/arch/parisc/kernel/smp.c
+++ b/arch/parisc/kernel/smp.c
@@ -292,10 +292,15 @@ smp_cpu_init(int cpunum)
292 * Slaves start using C here. Indirectly called from smp_slave_stext. 292 * Slaves start using C here. Indirectly called from smp_slave_stext.
293 * Do what start_kernel() and main() do for boot strap processor (aka monarch) 293 * Do what start_kernel() and main() do for boot strap processor (aka monarch)
294 */ 294 */
295void __init smp_callin(void) 295void __init smp_callin(unsigned long pdce_proc)
296{ 296{
297 int slave_id = cpu_now_booting; 297 int slave_id = cpu_now_booting;
298 298
299#ifdef CONFIG_64BIT
300 WARN_ON(((unsigned long)(PAGE0->mem_pdc_hi) << 32
301 | PAGE0->mem_pdc) != pdce_proc);
302#endif
303
299 smp_cpu_init(slave_id); 304 smp_cpu_init(slave_id);
300 preempt_disable(); 305 preempt_disable();
301 306
diff --git a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c
index 4b8fd6dc22da..f7e684560186 100644
--- a/arch/parisc/kernel/time.c
+++ b/arch/parisc/kernel/time.c
@@ -76,10 +76,10 @@ irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id)
76 next_tick = cpuinfo->it_value; 76 next_tick = cpuinfo->it_value;
77 77
78 /* Calculate how many ticks have elapsed. */ 78 /* Calculate how many ticks have elapsed. */
79 now = mfctl(16);
79 do { 80 do {
80 ++ticks_elapsed; 81 ++ticks_elapsed;
81 next_tick += cpt; 82 next_tick += cpt;
82 now = mfctl(16);
83 } while (next_tick - now > cpt); 83 } while (next_tick - now > cpt);
84 84
85 /* Store (in CR16 cycles) up to when we are accounting right now. */ 85 /* Store (in CR16 cycles) up to when we are accounting right now. */
@@ -103,16 +103,17 @@ irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id)
103 * if one or the other wrapped. If "now" is "bigger" we'll end up 103 * if one or the other wrapped. If "now" is "bigger" we'll end up
104 * with a very large unsigned number. 104 * with a very large unsigned number.
105 */ 105 */
106 while (next_tick - mfctl(16) > cpt) 106 now = mfctl(16);
107 while (next_tick - now > cpt)
107 next_tick += cpt; 108 next_tick += cpt;
108 109
109 /* Program the IT when to deliver the next interrupt. 110 /* Program the IT when to deliver the next interrupt.
110 * Only bottom 32-bits of next_tick are writable in CR16! 111 * Only bottom 32-bits of next_tick are writable in CR16!
111 * Timer interrupt will be delivered at least a few hundred cycles 112 * Timer interrupt will be delivered at least a few hundred cycles
112 * after the IT fires, so if we are too close (<= 500 cycles) to the 113 * after the IT fires, so if we are too close (<= 8000 cycles) to the
113 * next cycle, simply skip it. 114 * next cycle, simply skip it.
114 */ 115 */
115 if (next_tick - mfctl(16) <= 500) 116 if (next_tick - now <= 8000)
116 next_tick += cpt; 117 next_tick += cpt;
117 mtctl(next_tick, 16); 118 mtctl(next_tick, 16);
118 119
@@ -248,7 +249,7 @@ static int __init init_cr16_clocksource(void)
248 * different sockets, so mark them unstable and lower rating on 249 * different sockets, so mark them unstable and lower rating on
249 * multi-socket SMP systems. 250 * multi-socket SMP systems.
250 */ 251 */
251 if (num_online_cpus() > 1) { 252 if (num_online_cpus() > 1 && !running_on_qemu) {
252 int cpu; 253 int cpu;
253 unsigned long cpu0_loc; 254 unsigned long cpu0_loc;
254 cpu0_loc = per_cpu(cpu_data, 0).cpu_loc; 255 cpu0_loc = per_cpu(cpu_data, 0).cpu_loc;
diff --git a/arch/parisc/mm/init.c b/arch/parisc/mm/init.c
index 48f41399fc0b..cab32ee824d2 100644
--- a/arch/parisc/mm/init.c
+++ b/arch/parisc/mm/init.c
@@ -629,7 +629,12 @@ void __init mem_init(void)
629#endif 629#endif
630 630
631 mem_init_print_info(NULL); 631 mem_init_print_info(NULL);
632#ifdef CONFIG_DEBUG_KERNEL /* double-sanity-check paranoia */ 632
633#if 0
634 /*
635 * Do not expose the virtual kernel memory layout to userspace.
636 * But keep code for debugging purposes.
637 */
633 printk("virtual kernel memory layout:\n" 638 printk("virtual kernel memory layout:\n"
634 " vmalloc : 0x%px - 0x%px (%4ld MB)\n" 639 " vmalloc : 0x%px - 0x%px (%4ld MB)\n"
635 " memory : 0x%px - 0x%px (%4ld MB)\n" 640 " memory : 0x%px - 0x%px (%4ld MB)\n"
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index ef6549e57157..26d5d2a5b8e9 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -101,7 +101,8 @@ $(addprefix $(obj)/,$(zlib-y)): \
101libfdt := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c 101libfdt := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c
102libfdtheader := fdt.h libfdt.h libfdt_internal.h 102libfdtheader := fdt.h libfdt.h libfdt_internal.h
103 103
104$(addprefix $(obj)/,$(libfdt) libfdt-wrapper.o simpleboot.o epapr.o opal.o): \ 104$(addprefix $(obj)/,$(libfdt) libfdt-wrapper.o simpleboot.o epapr.o opal.o \
105 treeboot-akebono.o treeboot-currituck.o treeboot-iss4xx.o): \
105 $(addprefix $(obj)/,$(libfdtheader)) 106 $(addprefix $(obj)/,$(libfdtheader))
106 107
107src-wlib-y := string.S crt0.S stdio.c decompress.c main.c \ 108src-wlib-y := string.S crt0.S stdio.c decompress.c main.c \
diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h
index 30a155c0a6b0..c615abdce119 100644
--- a/arch/powerpc/include/asm/book3s/32/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
@@ -16,6 +16,7 @@
16#define PGD_INDEX_SIZE (32 - PGDIR_SHIFT) 16#define PGD_INDEX_SIZE (32 - PGDIR_SHIFT)
17 17
18#define PMD_CACHE_INDEX PMD_INDEX_SIZE 18#define PMD_CACHE_INDEX PMD_INDEX_SIZE
19#define PUD_CACHE_INDEX PUD_INDEX_SIZE
19 20
20#ifndef __ASSEMBLY__ 21#ifndef __ASSEMBLY__
21#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE) 22#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE)
diff --git a/arch/powerpc/include/asm/book3s/64/hash-4k.h b/arch/powerpc/include/asm/book3s/64/hash-4k.h
index 949d691094a4..67c5475311ee 100644
--- a/arch/powerpc/include/asm/book3s/64/hash-4k.h
+++ b/arch/powerpc/include/asm/book3s/64/hash-4k.h
@@ -63,7 +63,8 @@ static inline int hash__hugepd_ok(hugepd_t hpd)
63 * keeping the prototype consistent across the two formats. 63 * keeping the prototype consistent across the two formats.
64 */ 64 */
65static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte, 65static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte,
66 unsigned int subpg_index, unsigned long hidx) 66 unsigned int subpg_index, unsigned long hidx,
67 int offset)
67{ 68{
68 return (hidx << H_PAGE_F_GIX_SHIFT) & 69 return (hidx << H_PAGE_F_GIX_SHIFT) &
69 (H_PAGE_F_SECOND | H_PAGE_F_GIX); 70 (H_PAGE_F_SECOND | H_PAGE_F_GIX);
diff --git a/arch/powerpc/include/asm/book3s/64/hash-64k.h b/arch/powerpc/include/asm/book3s/64/hash-64k.h
index 338b7da468ce..3bcf269f8f55 100644
--- a/arch/powerpc/include/asm/book3s/64/hash-64k.h
+++ b/arch/powerpc/include/asm/book3s/64/hash-64k.h
@@ -45,7 +45,7 @@
45 * generic accessors and iterators here 45 * generic accessors and iterators here
46 */ 46 */
47#define __real_pte __real_pte 47#define __real_pte __real_pte
48static inline real_pte_t __real_pte(pte_t pte, pte_t *ptep) 48static inline real_pte_t __real_pte(pte_t pte, pte_t *ptep, int offset)
49{ 49{
50 real_pte_t rpte; 50 real_pte_t rpte;
51 unsigned long *hidxp; 51 unsigned long *hidxp;
@@ -59,7 +59,7 @@ static inline real_pte_t __real_pte(pte_t pte, pte_t *ptep)
59 */ 59 */
60 smp_rmb(); 60 smp_rmb();
61 61
62 hidxp = (unsigned long *)(ptep + PTRS_PER_PTE); 62 hidxp = (unsigned long *)(ptep + offset);
63 rpte.hidx = *hidxp; 63 rpte.hidx = *hidxp;
64 return rpte; 64 return rpte;
65} 65}
@@ -86,9 +86,10 @@ static inline unsigned long __rpte_to_hidx(real_pte_t rpte, unsigned long index)
86 * expected to modify the PTE bits accordingly and commit the PTE to memory. 86 * expected to modify the PTE bits accordingly and commit the PTE to memory.
87 */ 87 */
88static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte, 88static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte,
89 unsigned int subpg_index, unsigned long hidx) 89 unsigned int subpg_index,
90 unsigned long hidx, int offset)
90{ 91{
91 unsigned long *hidxp = (unsigned long *)(ptep + PTRS_PER_PTE); 92 unsigned long *hidxp = (unsigned long *)(ptep + offset);
92 93
93 rpte.hidx &= ~HIDX_BITS(0xfUL, subpg_index); 94 rpte.hidx &= ~HIDX_BITS(0xfUL, subpg_index);
94 *hidxp = rpte.hidx | HIDX_BITS(HIDX_SHIFT_BY_ONE(hidx), subpg_index); 95 *hidxp = rpte.hidx | HIDX_BITS(HIDX_SHIFT_BY_ONE(hidx), subpg_index);
@@ -140,13 +141,18 @@ static inline int hash__remap_4k_pfn(struct vm_area_struct *vma, unsigned long a
140} 141}
141 142
142#define H_PTE_TABLE_SIZE PTE_FRAG_SIZE 143#define H_PTE_TABLE_SIZE PTE_FRAG_SIZE
143#ifdef CONFIG_TRANSPARENT_HUGEPAGE 144#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined (CONFIG_HUGETLB_PAGE)
144#define H_PMD_TABLE_SIZE ((sizeof(pmd_t) << PMD_INDEX_SIZE) + \ 145#define H_PMD_TABLE_SIZE ((sizeof(pmd_t) << PMD_INDEX_SIZE) + \
145 (sizeof(unsigned long) << PMD_INDEX_SIZE)) 146 (sizeof(unsigned long) << PMD_INDEX_SIZE))
146#else 147#else
147#define H_PMD_TABLE_SIZE (sizeof(pmd_t) << PMD_INDEX_SIZE) 148#define H_PMD_TABLE_SIZE (sizeof(pmd_t) << PMD_INDEX_SIZE)
148#endif 149#endif
150#ifdef CONFIG_HUGETLB_PAGE
151#define H_PUD_TABLE_SIZE ((sizeof(pud_t) << PUD_INDEX_SIZE) + \
152 (sizeof(unsigned long) << PUD_INDEX_SIZE))
153#else
149#define H_PUD_TABLE_SIZE (sizeof(pud_t) << PUD_INDEX_SIZE) 154#define H_PUD_TABLE_SIZE (sizeof(pud_t) << PUD_INDEX_SIZE)
155#endif
150#define H_PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE) 156#define H_PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE)
151 157
152#ifdef CONFIG_TRANSPARENT_HUGEPAGE 158#ifdef CONFIG_TRANSPARENT_HUGEPAGE
diff --git a/arch/powerpc/include/asm/book3s/64/hash.h b/arch/powerpc/include/asm/book3s/64/hash.h
index 0920eff731b3..935adcd92a81 100644
--- a/arch/powerpc/include/asm/book3s/64/hash.h
+++ b/arch/powerpc/include/asm/book3s/64/hash.h
@@ -23,7 +23,8 @@
23 H_PUD_INDEX_SIZE + H_PGD_INDEX_SIZE + PAGE_SHIFT) 23 H_PUD_INDEX_SIZE + H_PGD_INDEX_SIZE + PAGE_SHIFT)
24#define H_PGTABLE_RANGE (ASM_CONST(1) << H_PGTABLE_EADDR_SIZE) 24#define H_PGTABLE_RANGE (ASM_CONST(1) << H_PGTABLE_EADDR_SIZE)
25 25
26#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && defined(CONFIG_PPC_64K_PAGES) 26#if (defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE)) && \
27 defined(CONFIG_PPC_64K_PAGES)
27/* 28/*
28 * only with hash 64k we need to use the second half of pmd page table 29 * only with hash 64k we need to use the second half of pmd page table
29 * to store pointer to deposited pgtable_t 30 * to store pointer to deposited pgtable_t
@@ -33,6 +34,16 @@
33#define H_PMD_CACHE_INDEX H_PMD_INDEX_SIZE 34#define H_PMD_CACHE_INDEX H_PMD_INDEX_SIZE
34#endif 35#endif
35/* 36/*
37 * We store the slot details in the second half of page table.
38 * Increase the pud level table so that hugetlb ptes can be stored
39 * at pud level.
40 */
41#if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_PPC_64K_PAGES)
42#define H_PUD_CACHE_INDEX (H_PUD_INDEX_SIZE + 1)
43#else
44#define H_PUD_CACHE_INDEX (H_PUD_INDEX_SIZE)
45#endif
46/*
36 * Define the address range of the kernel non-linear virtual area 47 * Define the address range of the kernel non-linear virtual area
37 */ 48 */
38#define H_KERN_VIRT_START ASM_CONST(0xD000000000000000) 49#define H_KERN_VIRT_START ASM_CONST(0xD000000000000000)
diff --git a/arch/powerpc/include/asm/book3s/64/pgalloc.h b/arch/powerpc/include/asm/book3s/64/pgalloc.h
index 1fcfa425cefa..4746bc68d446 100644
--- a/arch/powerpc/include/asm/book3s/64/pgalloc.h
+++ b/arch/powerpc/include/asm/book3s/64/pgalloc.h
@@ -73,10 +73,16 @@ static inline void radix__pgd_free(struct mm_struct *mm, pgd_t *pgd)
73 73
74static inline pgd_t *pgd_alloc(struct mm_struct *mm) 74static inline pgd_t *pgd_alloc(struct mm_struct *mm)
75{ 75{
76 pgd_t *pgd;
77
76 if (radix_enabled()) 78 if (radix_enabled())
77 return radix__pgd_alloc(mm); 79 return radix__pgd_alloc(mm);
78 return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), 80
79 pgtable_gfp_flags(mm, GFP_KERNEL)); 81 pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
82 pgtable_gfp_flags(mm, GFP_KERNEL));
83 memset(pgd, 0, PGD_TABLE_SIZE);
84
85 return pgd;
80} 86}
81 87
82static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) 88static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
@@ -93,13 +99,13 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
93 99
94static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) 100static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
95{ 101{
96 return kmem_cache_alloc(PGT_CACHE(PUD_INDEX_SIZE), 102 return kmem_cache_alloc(PGT_CACHE(PUD_CACHE_INDEX),
97 pgtable_gfp_flags(mm, GFP_KERNEL)); 103 pgtable_gfp_flags(mm, GFP_KERNEL));
98} 104}
99 105
100static inline void pud_free(struct mm_struct *mm, pud_t *pud) 106static inline void pud_free(struct mm_struct *mm, pud_t *pud)
101{ 107{
102 kmem_cache_free(PGT_CACHE(PUD_INDEX_SIZE), pud); 108 kmem_cache_free(PGT_CACHE(PUD_CACHE_INDEX), pud);
103} 109}
104 110
105static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) 111static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
@@ -115,7 +121,7 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
115 * ahead and flush the page walk cache 121 * ahead and flush the page walk cache
116 */ 122 */
117 flush_tlb_pgtable(tlb, address); 123 flush_tlb_pgtable(tlb, address);
118 pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE); 124 pgtable_free_tlb(tlb, pud, PUD_CACHE_INDEX);
119} 125}
120 126
121static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) 127static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 51017726d495..a6b9f1d74600 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -232,11 +232,13 @@ extern unsigned long __pmd_index_size;
232extern unsigned long __pud_index_size; 232extern unsigned long __pud_index_size;
233extern unsigned long __pgd_index_size; 233extern unsigned long __pgd_index_size;
234extern unsigned long __pmd_cache_index; 234extern unsigned long __pmd_cache_index;
235extern unsigned long __pud_cache_index;
235#define PTE_INDEX_SIZE __pte_index_size 236#define PTE_INDEX_SIZE __pte_index_size
236#define PMD_INDEX_SIZE __pmd_index_size 237#define PMD_INDEX_SIZE __pmd_index_size
237#define PUD_INDEX_SIZE __pud_index_size 238#define PUD_INDEX_SIZE __pud_index_size
238#define PGD_INDEX_SIZE __pgd_index_size 239#define PGD_INDEX_SIZE __pgd_index_size
239#define PMD_CACHE_INDEX __pmd_cache_index 240#define PMD_CACHE_INDEX __pmd_cache_index
241#define PUD_CACHE_INDEX __pud_cache_index
240/* 242/*
241 * Because of use of pte fragments and THP, size of page table 243 * Because of use of pte fragments and THP, size of page table
242 * are not always derived out of index size above. 244 * are not always derived out of index size above.
@@ -348,7 +350,7 @@ extern unsigned long pci_io_base;
348 */ 350 */
349#ifndef __real_pte 351#ifndef __real_pte
350 352
351#define __real_pte(e,p) ((real_pte_t){(e)}) 353#define __real_pte(e, p, o) ((real_pte_t){(e)})
352#define __rpte_to_pte(r) ((r).pte) 354#define __rpte_to_pte(r) ((r).pte)
353#define __rpte_to_hidx(r,index) (pte_val(__rpte_to_pte(r)) >> H_PAGE_F_GIX_SHIFT) 355#define __rpte_to_hidx(r,index) (pte_val(__rpte_to_pte(r)) >> H_PAGE_F_GIX_SHIFT)
354 356
diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index 176dfb73d42c..471b2274fbeb 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -645,7 +645,7 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
645 EXC_HV, SOFTEN_TEST_HV, bitmask) 645 EXC_HV, SOFTEN_TEST_HV, bitmask)
646 646
647#define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label, bitmask) \ 647#define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label, bitmask) \
648 MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_NOTEST_HV, vec, bitmask);\ 648 MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec, bitmask);\
649 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) 649 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV)
650 650
651/* 651/*
diff --git a/arch/powerpc/include/asm/firmware.h b/arch/powerpc/include/asm/firmware.h
index 511acfd7ab0d..535add3f7791 100644
--- a/arch/powerpc/include/asm/firmware.h
+++ b/arch/powerpc/include/asm/firmware.h
@@ -52,7 +52,7 @@
52#define FW_FEATURE_TYPE1_AFFINITY ASM_CONST(0x0000000100000000) 52#define FW_FEATURE_TYPE1_AFFINITY ASM_CONST(0x0000000100000000)
53#define FW_FEATURE_PRRN ASM_CONST(0x0000000200000000) 53#define FW_FEATURE_PRRN ASM_CONST(0x0000000200000000)
54#define FW_FEATURE_DRMEM_V2 ASM_CONST(0x0000000400000000) 54#define FW_FEATURE_DRMEM_V2 ASM_CONST(0x0000000400000000)
55#define FW_FEATURE_DRC_INFO ASM_CONST(0x0000000400000000) 55#define FW_FEATURE_DRC_INFO ASM_CONST(0x0000000800000000)
56 56
57#ifndef __ASSEMBLY__ 57#ifndef __ASSEMBLY__
58 58
diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h
index 88e5e8f17e98..855e17d158b1 100644
--- a/arch/powerpc/include/asm/hw_irq.h
+++ b/arch/powerpc/include/asm/hw_irq.h
@@ -30,6 +30,16 @@
30#define PACA_IRQ_PMI 0x40 30#define PACA_IRQ_PMI 0x40
31 31
32/* 32/*
33 * Some soft-masked interrupts must be hard masked until they are replayed
34 * (e.g., because the soft-masked handler does not clear the exception).
35 */
36#ifdef CONFIG_PPC_BOOK3S
37#define PACA_IRQ_MUST_HARD_MASK (PACA_IRQ_EE|PACA_IRQ_PMI)
38#else
39#define PACA_IRQ_MUST_HARD_MASK (PACA_IRQ_EE)
40#endif
41
42/*
33 * flags for paca->irq_soft_mask 43 * flags for paca->irq_soft_mask
34 */ 44 */
35#define IRQS_ENABLED 0 45#define IRQS_ENABLED 0
@@ -244,7 +254,7 @@ static inline bool lazy_irq_pending(void)
244static inline void may_hard_irq_enable(void) 254static inline void may_hard_irq_enable(void)
245{ 255{
246 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS; 256 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
247 if (!(get_paca()->irq_happened & PACA_IRQ_EE)) 257 if (!(get_paca()->irq_happened & PACA_IRQ_MUST_HARD_MASK))
248 __hard_irq_enable(); 258 __hard_irq_enable();
249} 259}
250 260
diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h
index 9dcbfa6bbb91..d8b1e8e7e035 100644
--- a/arch/powerpc/include/asm/kexec.h
+++ b/arch/powerpc/include/asm/kexec.h
@@ -140,6 +140,12 @@ static inline bool kdump_in_progress(void)
140 return false; 140 return false;
141} 141}
142 142
143static inline void crash_ipi_callback(struct pt_regs *regs) { }
144
145static inline void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
146{
147}
148
143#endif /* CONFIG_KEXEC_CORE */ 149#endif /* CONFIG_KEXEC_CORE */
144#endif /* ! __ASSEMBLY__ */ 150#endif /* ! __ASSEMBLY__ */
145#endif /* __KERNEL__ */ 151#endif /* __KERNEL__ */
diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h b/arch/powerpc/include/asm/nohash/32/pgtable.h
index 504a3c36ce5c..03bbd1149530 100644
--- a/arch/powerpc/include/asm/nohash/32/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/32/pgtable.h
@@ -24,6 +24,7 @@ extern int icache_44x_need_flush;
24#define PGD_INDEX_SIZE (32 - PGDIR_SHIFT) 24#define PGD_INDEX_SIZE (32 - PGDIR_SHIFT)
25 25
26#define PMD_CACHE_INDEX PMD_INDEX_SIZE 26#define PMD_CACHE_INDEX PMD_INDEX_SIZE
27#define PUD_CACHE_INDEX PUD_INDEX_SIZE
27 28
28#ifndef __ASSEMBLY__ 29#ifndef __ASSEMBLY__
29#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE) 30#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE)
diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h b/arch/powerpc/include/asm/nohash/64/pgtable.h
index abddf5830ad5..5c5f75d005ad 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -27,6 +27,7 @@
27#else 27#else
28#define PMD_CACHE_INDEX PMD_INDEX_SIZE 28#define PMD_CACHE_INDEX PMD_INDEX_SIZE
29#endif 29#endif
30#define PUD_CACHE_INDEX PUD_INDEX_SIZE
30 31
31/* 32/*
32 * Define the address range of the kernel non-linear virtual area 33 * Define the address range of the kernel non-linear virtual area
diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
index 88187c285c70..9f421641a35c 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -44,6 +44,11 @@ extern int sysfs_add_device_to_node(struct device *dev, int nid);
44extern void sysfs_remove_device_from_node(struct device *dev, int nid); 44extern void sysfs_remove_device_from_node(struct device *dev, int nid);
45extern int numa_update_cpu_topology(bool cpus_locked); 45extern int numa_update_cpu_topology(bool cpus_locked);
46 46
47static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node)
48{
49 numa_cpu_lookup_table[cpu] = node;
50}
51
47static inline int early_cpu_to_node(int cpu) 52static inline int early_cpu_to_node(int cpu)
48{ 53{
49 int nid; 54 int nid;
@@ -76,12 +81,16 @@ static inline int numa_update_cpu_topology(bool cpus_locked)
76{ 81{
77 return 0; 82 return 0;
78} 83}
84
85static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) {}
86
79#endif /* CONFIG_NUMA */ 87#endif /* CONFIG_NUMA */
80 88
81#if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR) 89#if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
82extern int start_topology_update(void); 90extern int start_topology_update(void);
83extern int stop_topology_update(void); 91extern int stop_topology_update(void);
84extern int prrn_is_enabled(void); 92extern int prrn_is_enabled(void);
93extern int find_and_online_cpu_nid(int cpu);
85#else 94#else
86static inline int start_topology_update(void) 95static inline int start_topology_update(void)
87{ 96{
@@ -95,6 +104,10 @@ static inline int prrn_is_enabled(void)
95{ 104{
96 return 0; 105 return 0;
97} 106}
107static inline int find_and_online_cpu_nid(int cpu)
108{
109 return 0;
110}
98#endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */ 111#endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */
99 112
100#if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_NEED_MULTIPLE_NODES) 113#if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_NEED_MULTIPLE_NODES)
diff --git a/arch/powerpc/kernel/eeh_driver.c b/arch/powerpc/kernel/eeh_driver.c
index beea2182d754..0c0b66fc5bfb 100644
--- a/arch/powerpc/kernel/eeh_driver.c
+++ b/arch/powerpc/kernel/eeh_driver.c
@@ -384,7 +384,8 @@ static void *eeh_report_resume(void *data, void *userdata)
384 eeh_pcid_put(dev); 384 eeh_pcid_put(dev);
385 pci_uevent_ers(dev, PCI_ERS_RESULT_RECOVERED); 385 pci_uevent_ers(dev, PCI_ERS_RESULT_RECOVERED);
386#ifdef CONFIG_PCI_IOV 386#ifdef CONFIG_PCI_IOV
387 eeh_ops->notify_resume(eeh_dev_to_pdn(edev)); 387 if (eeh_ops->notify_resume && eeh_dev_to_pdn(edev))
388 eeh_ops->notify_resume(eeh_dev_to_pdn(edev));
388#endif 389#endif
389 return NULL; 390 return NULL;
390} 391}
diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
index ee832d344a5a..9b6e653e501a 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -943,6 +943,8 @@ kernel_dbg_exc:
943/* 943/*
944 * An interrupt came in while soft-disabled; We mark paca->irq_happened 944 * An interrupt came in while soft-disabled; We mark paca->irq_happened
945 * accordingly and if the interrupt is level sensitive, we hard disable 945 * accordingly and if the interrupt is level sensitive, we hard disable
946 * hard disable (full_mask) corresponds to PACA_IRQ_MUST_HARD_MASK, so
947 * keep these in synch.
946 */ 948 */
947 949
948.macro masked_interrupt_book3e paca_irq full_mask 950.macro masked_interrupt_book3e paca_irq full_mask
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 243d072a225a..3ac87e53b3da 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1426,7 +1426,7 @@ EXC_COMMON_BEGIN(soft_nmi_common)
1426 * triggered and won't automatically refire. 1426 * triggered and won't automatically refire.
1427 * - If it was a HMI we return immediately since we handled it in realmode 1427 * - If it was a HMI we return immediately since we handled it in realmode
1428 * and it won't refire. 1428 * and it won't refire.
1429 * - else we hard disable and return. 1429 * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return.
1430 * This is called with r10 containing the value to OR to the paca field. 1430 * This is called with r10 containing the value to OR to the paca field.
1431 */ 1431 */
1432#define MASKED_INTERRUPT(_H) \ 1432#define MASKED_INTERRUPT(_H) \
@@ -1441,8 +1441,8 @@ masked_##_H##interrupt: \
1441 ori r10,r10,0xffff; \ 1441 ori r10,r10,0xffff; \
1442 mtspr SPRN_DEC,r10; \ 1442 mtspr SPRN_DEC,r10; \
1443 b MASKED_DEC_HANDLER_LABEL; \ 1443 b MASKED_DEC_HANDLER_LABEL; \
14441: andi. r10,r10,(PACA_IRQ_DBELL|PACA_IRQ_HMI); \ 14441: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK; \
1445 bne 2f; \ 1445 beq 2f; \
1446 mfspr r10,SPRN_##_H##SRR1; \ 1446 mfspr r10,SPRN_##_H##SRR1; \
1447 xori r10,r10,MSR_EE; /* clear MSR_EE */ \ 1447 xori r10,r10,MSR_EE; /* clear MSR_EE */ \
1448 mtspr SPRN_##_H##SRR1,r10; \ 1448 mtspr SPRN_##_H##SRR1,r10; \
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index adf044daafd7..acf4b2e0530c 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -874,7 +874,6 @@ struct ibm_arch_vec __cacheline_aligned ibm_architecture_vec = {
874 .mmu = 0, 874 .mmu = 0,
875 .hash_ext = 0, 875 .hash_ext = 0,
876 .radix_ext = 0, 876 .radix_ext = 0,
877 .byte22 = OV5_FEAT(OV5_DRC_INFO),
878 }, 877 },
879 878
880 /* option vector 6: IBM PAPR hints */ 879 /* option vector 6: IBM PAPR hints */
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index 5a8bfee6e187..04d0bbd7a1dd 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -788,7 +788,8 @@ static int register_cpu_online(unsigned int cpu)
788 if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2)) 788 if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2))
789 device_create_file(s, &dev_attr_pir); 789 device_create_file(s, &dev_attr_pir);
790 790
791 if (cpu_has_feature(CPU_FTR_ARCH_206)) 791 if (cpu_has_feature(CPU_FTR_ARCH_206) &&
792 !firmware_has_feature(FW_FEATURE_LPAR))
792 device_create_file(s, &dev_attr_tscr); 793 device_create_file(s, &dev_attr_tscr);
793#endif /* CONFIG_PPC64 */ 794#endif /* CONFIG_PPC64 */
794 795
@@ -873,7 +874,8 @@ static int unregister_cpu_online(unsigned int cpu)
873 if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2)) 874 if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2))
874 device_remove_file(s, &dev_attr_pir); 875 device_remove_file(s, &dev_attr_pir);
875 876
876 if (cpu_has_feature(CPU_FTR_ARCH_206)) 877 if (cpu_has_feature(CPU_FTR_ARCH_206) &&
878 !firmware_has_feature(FW_FEATURE_LPAR))
877 device_remove_file(s, &dev_attr_tscr); 879 device_remove_file(s, &dev_attr_tscr);
878#endif /* CONFIG_PPC64 */ 880#endif /* CONFIG_PPC64 */
879 881
diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c
index 0c854816e653..5cb4e4687107 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
@@ -195,6 +195,12 @@ static void kvmppc_pte_free(pte_t *ptep)
195 kmem_cache_free(kvm_pte_cache, ptep); 195 kmem_cache_free(kvm_pte_cache, ptep);
196} 196}
197 197
198/* Like pmd_huge() and pmd_large(), but works regardless of config options */
199static inline int pmd_is_leaf(pmd_t pmd)
200{
201 return !!(pmd_val(pmd) & _PAGE_PTE);
202}
203
198static int kvmppc_create_pte(struct kvm *kvm, pte_t pte, unsigned long gpa, 204static int kvmppc_create_pte(struct kvm *kvm, pte_t pte, unsigned long gpa,
199 unsigned int level, unsigned long mmu_seq) 205 unsigned int level, unsigned long mmu_seq)
200{ 206{
@@ -219,7 +225,7 @@ static int kvmppc_create_pte(struct kvm *kvm, pte_t pte, unsigned long gpa,
219 else 225 else
220 new_pmd = pmd_alloc_one(kvm->mm, gpa); 226 new_pmd = pmd_alloc_one(kvm->mm, gpa);
221 227
222 if (level == 0 && !(pmd && pmd_present(*pmd))) 228 if (level == 0 && !(pmd && pmd_present(*pmd) && !pmd_is_leaf(*pmd)))
223 new_ptep = kvmppc_pte_alloc(); 229 new_ptep = kvmppc_pte_alloc();
224 230
225 /* Check if we might have been invalidated; let the guest retry if so */ 231 /* Check if we might have been invalidated; let the guest retry if so */
@@ -244,12 +250,30 @@ static int kvmppc_create_pte(struct kvm *kvm, pte_t pte, unsigned long gpa,
244 new_pmd = NULL; 250 new_pmd = NULL;
245 } 251 }
246 pmd = pmd_offset(pud, gpa); 252 pmd = pmd_offset(pud, gpa);
247 if (pmd_large(*pmd)) { 253 if (pmd_is_leaf(*pmd)) {
248 /* Someone else has instantiated a large page here; retry */ 254 unsigned long lgpa = gpa & PMD_MASK;
249 ret = -EAGAIN; 255
250 goto out_unlock; 256 /*
251 } 257 * If we raced with another CPU which has just put
252 if (level == 1 && !pmd_none(*pmd)) { 258 * a 2MB pte in after we saw a pte page, try again.
259 */
260 if (level == 0 && !new_ptep) {
261 ret = -EAGAIN;
262 goto out_unlock;
263 }
264 /* Valid 2MB page here already, remove it */
265 old = kvmppc_radix_update_pte(kvm, pmdp_ptep(pmd),
266 ~0UL, 0, lgpa, PMD_SHIFT);
267 kvmppc_radix_tlbie_page(kvm, lgpa, PMD_SHIFT);
268 if (old & _PAGE_DIRTY) {
269 unsigned long gfn = lgpa >> PAGE_SHIFT;
270 struct kvm_memory_slot *memslot;
271 memslot = gfn_to_memslot(kvm, gfn);
272 if (memslot && memslot->dirty_bitmap)
273 kvmppc_update_dirty_map(memslot,
274 gfn, PMD_SIZE);
275 }
276 } else if (level == 1 && !pmd_none(*pmd)) {
253 /* 277 /*
254 * There's a page table page here, but we wanted 278 * There's a page table page here, but we wanted
255 * to install a large page. Tell the caller and let 279 * to install a large page. Tell the caller and let
@@ -412,28 +436,24 @@ int kvmppc_book3s_radix_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
412 } else { 436 } else {
413 page = pages[0]; 437 page = pages[0];
414 pfn = page_to_pfn(page); 438 pfn = page_to_pfn(page);
415 if (PageHuge(page)) { 439 if (PageCompound(page)) {
416 page = compound_head(page); 440 pte_size <<= compound_order(compound_head(page));
417 pte_size <<= compound_order(page);
418 /* See if we can insert a 2MB large-page PTE here */ 441 /* See if we can insert a 2MB large-page PTE here */
419 if (pte_size >= PMD_SIZE && 442 if (pte_size >= PMD_SIZE &&
420 (gpa & PMD_MASK & PAGE_MASK) == 443 (gpa & (PMD_SIZE - PAGE_SIZE)) ==
421 (hva & PMD_MASK & PAGE_MASK)) { 444 (hva & (PMD_SIZE - PAGE_SIZE))) {
422 level = 1; 445 level = 1;
423 pfn &= ~((PMD_SIZE >> PAGE_SHIFT) - 1); 446 pfn &= ~((PMD_SIZE >> PAGE_SHIFT) - 1);
424 } 447 }
425 } 448 }
426 /* See if we can provide write access */ 449 /* See if we can provide write access */
427 if (writing) { 450 if (writing) {
428 /*
429 * We assume gup_fast has set dirty on the host PTE.
430 */
431 pgflags |= _PAGE_WRITE; 451 pgflags |= _PAGE_WRITE;
432 } else { 452 } else {
433 local_irq_save(flags); 453 local_irq_save(flags);
434 ptep = find_current_mm_pte(current->mm->pgd, 454 ptep = find_current_mm_pte(current->mm->pgd,
435 hva, NULL, NULL); 455 hva, NULL, NULL);
436 if (ptep && pte_write(*ptep) && pte_dirty(*ptep)) 456 if (ptep && pte_write(*ptep))
437 pgflags |= _PAGE_WRITE; 457 pgflags |= _PAGE_WRITE;
438 local_irq_restore(flags); 458 local_irq_restore(flags);
439 } 459 }
@@ -459,18 +479,15 @@ int kvmppc_book3s_radix_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
459 pte = pfn_pte(pfn, __pgprot(pgflags)); 479 pte = pfn_pte(pfn, __pgprot(pgflags));
460 ret = kvmppc_create_pte(kvm, pte, gpa, level, mmu_seq); 480 ret = kvmppc_create_pte(kvm, pte, gpa, level, mmu_seq);
461 } 481 }
462 if (ret == 0 || ret == -EAGAIN)
463 ret = RESUME_GUEST;
464 482
465 if (page) { 483 if (page) {
466 /* 484 if (!ret && (pgflags & _PAGE_WRITE))
467 * We drop pages[0] here, not page because page might 485 set_page_dirty_lock(page);
468 * have been set to the head page of a compound, but 486 put_page(page);
469 * we have to drop the reference on the correct tail
470 * page to match the get inside gup()
471 */
472 put_page(pages[0]);
473 } 487 }
488
489 if (ret == 0 || ret == -EAGAIN)
490 ret = RESUME_GUEST;
474 return ret; 491 return ret;
475} 492}
476 493
@@ -644,7 +661,7 @@ void kvmppc_free_radix(struct kvm *kvm)
644 continue; 661 continue;
645 pmd = pmd_offset(pud, 0); 662 pmd = pmd_offset(pud, 0);
646 for (im = 0; im < PTRS_PER_PMD; ++im, ++pmd) { 663 for (im = 0; im < PTRS_PER_PMD; ++im, ++pmd) {
647 if (pmd_huge(*pmd)) { 664 if (pmd_is_leaf(*pmd)) {
648 pmd_clear(pmd); 665 pmd_clear(pmd);
649 continue; 666 continue;
650 } 667 }
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 89707354c2ef..9cb9448163c4 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2885,7 +2885,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2885 */ 2885 */
2886 trace_hardirqs_on(); 2886 trace_hardirqs_on();
2887 2887
2888 guest_enter(); 2888 guest_enter_irqoff();
2889 2889
2890 srcu_idx = srcu_read_lock(&vc->kvm->srcu); 2890 srcu_idx = srcu_read_lock(&vc->kvm->srcu);
2891 2891
@@ -2893,8 +2893,6 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2893 2893
2894 srcu_read_unlock(&vc->kvm->srcu, srcu_idx); 2894 srcu_read_unlock(&vc->kvm->srcu, srcu_idx);
2895 2895
2896 guest_exit();
2897
2898 trace_hardirqs_off(); 2896 trace_hardirqs_off();
2899 set_irq_happened(trap); 2897 set_irq_happened(trap);
2900 2898
@@ -2937,6 +2935,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2937 kvmppc_set_host_core(pcpu); 2935 kvmppc_set_host_core(pcpu);
2938 2936
2939 local_irq_enable(); 2937 local_irq_enable();
2938 guest_exit();
2940 2939
2941 /* Let secondaries go back to the offline loop */ 2940 /* Let secondaries go back to the offline loop */
2942 for (i = 0; i < controlled_threads; ++i) { 2941 for (i = 0; i < controlled_threads; ++i) {
@@ -3656,15 +3655,17 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
3656 goto up_out; 3655 goto up_out;
3657 3656
3658 psize = vma_kernel_pagesize(vma); 3657 psize = vma_kernel_pagesize(vma);
3659 porder = __ilog2(psize);
3660 3658
3661 up_read(&current->mm->mmap_sem); 3659 up_read(&current->mm->mmap_sem);
3662 3660
3663 /* We can handle 4k, 64k or 16M pages in the VRMA */ 3661 /* We can handle 4k, 64k or 16M pages in the VRMA */
3664 err = -EINVAL; 3662 if (psize >= 0x1000000)
3665 if (!(psize == 0x1000 || psize == 0x10000 || 3663 psize = 0x1000000;
3666 psize == 0x1000000)) 3664 else if (psize >= 0x10000)
3667 goto out_srcu; 3665 psize = 0x10000;
3666 else
3667 psize = 0x1000;
3668 porder = __ilog2(psize);
3668 3669
3669 senc = slb_pgsize_encoding(psize); 3670 senc = slb_pgsize_encoding(psize);
3670 kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T | 3671 kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T |
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index f31f357b8c5a..d33264697a31 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -320,7 +320,6 @@ kvm_novcpu_exit:
320 stw r12, STACK_SLOT_TRAP(r1) 320 stw r12, STACK_SLOT_TRAP(r1)
321 bl kvmhv_commence_exit 321 bl kvmhv_commence_exit
322 nop 322 nop
323 lwz r12, STACK_SLOT_TRAP(r1)
324 b kvmhv_switch_to_host 323 b kvmhv_switch_to_host
325 324
326/* 325/*
@@ -1220,6 +1219,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
1220 1219
1221secondary_too_late: 1220secondary_too_late:
1222 li r12, 0 1221 li r12, 0
1222 stw r12, STACK_SLOT_TRAP(r1)
1223 cmpdi r4, 0 1223 cmpdi r4, 0
1224 beq 11f 1224 beq 11f
1225 stw r12, VCPU_TRAP(r4) 1225 stw r12, VCPU_TRAP(r4)
@@ -1558,12 +1558,12 @@ mc_cont:
15583: stw r5,VCPU_SLB_MAX(r9) 15583: stw r5,VCPU_SLB_MAX(r9)
1559 1559
1560guest_bypass: 1560guest_bypass:
1561 stw r12, STACK_SLOT_TRAP(r1)
1561 mr r3, r12 1562 mr r3, r12
1562 /* Increment exit count, poke other threads to exit */ 1563 /* Increment exit count, poke other threads to exit */
1563 bl kvmhv_commence_exit 1564 bl kvmhv_commence_exit
1564 nop 1565 nop
1565 ld r9, HSTATE_KVM_VCPU(r13) 1566 ld r9, HSTATE_KVM_VCPU(r13)
1566 lwz r12, VCPU_TRAP(r9)
1567 1567
1568 /* Stop others sending VCPU interrupts to this physical CPU */ 1568 /* Stop others sending VCPU interrupts to this physical CPU */
1569 li r0, -1 1569 li r0, -1
@@ -1898,6 +1898,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_POWER9_DD1)
1898 * POWER7/POWER8 guest -> host partition switch code. 1898 * POWER7/POWER8 guest -> host partition switch code.
1899 * We don't have to lock against tlbies but we do 1899 * We don't have to lock against tlbies but we do
1900 * have to coordinate the hardware threads. 1900 * have to coordinate the hardware threads.
1901 * Here STACK_SLOT_TRAP(r1) contains the trap number.
1901 */ 1902 */
1902kvmhv_switch_to_host: 1903kvmhv_switch_to_host:
1903 /* Secondary threads wait for primary to do partition switch */ 1904 /* Secondary threads wait for primary to do partition switch */
@@ -1950,12 +1951,12 @@ BEGIN_FTR_SECTION
1950END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) 1951END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
1951 1952
1952 /* If HMI, call kvmppc_realmode_hmi_handler() */ 1953 /* If HMI, call kvmppc_realmode_hmi_handler() */
1954 lwz r12, STACK_SLOT_TRAP(r1)
1953 cmpwi r12, BOOK3S_INTERRUPT_HMI 1955 cmpwi r12, BOOK3S_INTERRUPT_HMI
1954 bne 27f 1956 bne 27f
1955 bl kvmppc_realmode_hmi_handler 1957 bl kvmppc_realmode_hmi_handler
1956 nop 1958 nop
1957 cmpdi r3, 0 1959 cmpdi r3, 0
1958 li r12, BOOK3S_INTERRUPT_HMI
1959 /* 1960 /*
1960 * At this point kvmppc_realmode_hmi_handler may have resync-ed 1961 * At this point kvmppc_realmode_hmi_handler may have resync-ed
1961 * the TB, and if it has, we must not subtract the guest timebase 1962 * the TB, and if it has, we must not subtract the guest timebase
@@ -2008,10 +2009,8 @@ BEGIN_FTR_SECTION
2008 lwz r8, KVM_SPLIT_DO_RESTORE(r3) 2009 lwz r8, KVM_SPLIT_DO_RESTORE(r3)
2009 cmpwi r8, 0 2010 cmpwi r8, 0
2010 beq 47f 2011 beq 47f
2011 stw r12, STACK_SLOT_TRAP(r1)
2012 bl kvmhv_p9_restore_lpcr 2012 bl kvmhv_p9_restore_lpcr
2013 nop 2013 nop
2014 lwz r12, STACK_SLOT_TRAP(r1)
2015 b 48f 2014 b 48f
201647: 201547:
2017END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) 2016END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
@@ -2049,6 +2048,7 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
2049 li r0, KVM_GUEST_MODE_NONE 2048 li r0, KVM_GUEST_MODE_NONE
2050 stb r0, HSTATE_IN_GUEST(r13) 2049 stb r0, HSTATE_IN_GUEST(r13)
2051 2050
2051 lwz r12, STACK_SLOT_TRAP(r1) /* return trap # in r12 */
2052 ld r0, SFS+PPC_LR_STKOFF(r1) 2052 ld r0, SFS+PPC_LR_STKOFF(r1)
2053 addi r1, r1, SFS 2053 addi r1, r1, SFS
2054 mtlr r0 2054 mtlr r0
diff --git a/arch/powerpc/kvm/book3s_xive.c b/arch/powerpc/kvm/book3s_xive.c
index f0f5cd4d2fe7..f9818d7d3381 100644
--- a/arch/powerpc/kvm/book3s_xive.c
+++ b/arch/powerpc/kvm/book3s_xive.c
@@ -188,7 +188,7 @@ static int xive_provision_queue(struct kvm_vcpu *vcpu, u8 prio)
188 if (!qpage) { 188 if (!qpage) {
189 pr_err("Failed to allocate queue %d for VCPU %d\n", 189 pr_err("Failed to allocate queue %d for VCPU %d\n",
190 prio, xc->server_num); 190 prio, xc->server_num);
191 return -ENOMEM;; 191 return -ENOMEM;
192 } 192 }
193 memset(qpage, 0, 1 << xive->q_order); 193 memset(qpage, 0, 1 << xive->q_order);
194 194
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 403e642c78f5..52c205373986 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -1345,7 +1345,7 @@ static int kvmppc_emulate_mmio_vsx_loadstore(struct kvm_vcpu *vcpu,
1345int kvmppc_handle_load128_by2x64(struct kvm_run *run, struct kvm_vcpu *vcpu, 1345int kvmppc_handle_load128_by2x64(struct kvm_run *run, struct kvm_vcpu *vcpu,
1346 unsigned int rt, int is_default_endian) 1346 unsigned int rt, int is_default_endian)
1347{ 1347{
1348 enum emulation_result emulated; 1348 enum emulation_result emulated = EMULATE_DONE;
1349 1349
1350 while (vcpu->arch.mmio_vmx_copy_nums) { 1350 while (vcpu->arch.mmio_vmx_copy_nums) {
1351 emulated = __kvmppc_handle_load(run, vcpu, rt, 8, 1351 emulated = __kvmppc_handle_load(run, vcpu, rt, 8,
@@ -1608,7 +1608,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
1608 1608
1609 kvm_sigset_deactivate(vcpu); 1609 kvm_sigset_deactivate(vcpu);
1610 1610
1611#ifdef CONFIG_ALTIVEC
1611out: 1612out:
1613#endif
1612 vcpu_put(vcpu); 1614 vcpu_put(vcpu);
1613 return r; 1615 return r;
1614} 1616}
diff --git a/arch/powerpc/mm/drmem.c b/arch/powerpc/mm/drmem.c
index 1604110c4238..3f1803672c9b 100644
--- a/arch/powerpc/mm/drmem.c
+++ b/arch/powerpc/mm/drmem.c
@@ -98,7 +98,7 @@ static void init_drconf_v2_cell(struct of_drconf_cell_v2 *dr_cell,
98 dr_cell->base_addr = cpu_to_be64(lmb->base_addr); 98 dr_cell->base_addr = cpu_to_be64(lmb->base_addr);
99 dr_cell->drc_index = cpu_to_be32(lmb->drc_index); 99 dr_cell->drc_index = cpu_to_be32(lmb->drc_index);
100 dr_cell->aa_index = cpu_to_be32(lmb->aa_index); 100 dr_cell->aa_index = cpu_to_be32(lmb->aa_index);
101 dr_cell->flags = cpu_to_be32(lmb->flags); 101 dr_cell->flags = cpu_to_be32(drmem_lmb_flags(lmb));
102} 102}
103 103
104static int drmem_update_dt_v2(struct device_node *memory, 104static int drmem_update_dt_v2(struct device_node *memory,
@@ -121,7 +121,7 @@ static int drmem_update_dt_v2(struct device_node *memory,
121 } 121 }
122 122
123 if (prev_lmb->aa_index != lmb->aa_index || 123 if (prev_lmb->aa_index != lmb->aa_index ||
124 prev_lmb->flags != lmb->flags) 124 drmem_lmb_flags(prev_lmb) != drmem_lmb_flags(lmb))
125 lmb_sets++; 125 lmb_sets++;
126 126
127 prev_lmb = lmb; 127 prev_lmb = lmb;
@@ -150,7 +150,7 @@ static int drmem_update_dt_v2(struct device_node *memory,
150 } 150 }
151 151
152 if (prev_lmb->aa_index != lmb->aa_index || 152 if (prev_lmb->aa_index != lmb->aa_index ||
153 prev_lmb->flags != lmb->flags) { 153 drmem_lmb_flags(prev_lmb) != drmem_lmb_flags(lmb)) {
154 /* end of one set, start of another */ 154 /* end of one set, start of another */
155 dr_cell->seq_lmbs = cpu_to_be32(seq_lmbs); 155 dr_cell->seq_lmbs = cpu_to_be32(seq_lmbs);
156 dr_cell++; 156 dr_cell++;
@@ -216,6 +216,8 @@ static void __init __walk_drmem_v1_lmbs(const __be32 *prop, const __be32 *usm,
216 u32 i, n_lmbs; 216 u32 i, n_lmbs;
217 217
218 n_lmbs = of_read_number(prop++, 1); 218 n_lmbs = of_read_number(prop++, 1);
219 if (n_lmbs == 0)
220 return;
219 221
220 for (i = 0; i < n_lmbs; i++) { 222 for (i = 0; i < n_lmbs; i++) {
221 read_drconf_v1_cell(&lmb, &prop); 223 read_drconf_v1_cell(&lmb, &prop);
@@ -245,6 +247,8 @@ static void __init __walk_drmem_v2_lmbs(const __be32 *prop, const __be32 *usm,
245 u32 i, j, lmb_sets; 247 u32 i, j, lmb_sets;
246 248
247 lmb_sets = of_read_number(prop++, 1); 249 lmb_sets = of_read_number(prop++, 1);
250 if (lmb_sets == 0)
251 return;
248 252
249 for (i = 0; i < lmb_sets; i++) { 253 for (i = 0; i < lmb_sets; i++) {
250 read_drconf_v2_cell(&dr_cell, &prop); 254 read_drconf_v2_cell(&dr_cell, &prop);
@@ -354,6 +358,8 @@ static void __init init_drmem_v1_lmbs(const __be32 *prop)
354 struct drmem_lmb *lmb; 358 struct drmem_lmb *lmb;
355 359
356 drmem_info->n_lmbs = of_read_number(prop++, 1); 360 drmem_info->n_lmbs = of_read_number(prop++, 1);
361 if (drmem_info->n_lmbs == 0)
362 return;
357 363
358 drmem_info->lmbs = kcalloc(drmem_info->n_lmbs, sizeof(*lmb), 364 drmem_info->lmbs = kcalloc(drmem_info->n_lmbs, sizeof(*lmb),
359 GFP_KERNEL); 365 GFP_KERNEL);
@@ -373,6 +379,8 @@ static void __init init_drmem_v2_lmbs(const __be32 *prop)
373 int lmb_index; 379 int lmb_index;
374 380
375 lmb_sets = of_read_number(prop++, 1); 381 lmb_sets = of_read_number(prop++, 1);
382 if (lmb_sets == 0)
383 return;
376 384
377 /* first pass, calculate the number of LMBs */ 385 /* first pass, calculate the number of LMBs */
378 p = prop; 386 p = prop;
diff --git a/arch/powerpc/mm/hash64_4k.c b/arch/powerpc/mm/hash64_4k.c
index 5a69b51d08a3..d573d7d07f25 100644
--- a/arch/powerpc/mm/hash64_4k.c
+++ b/arch/powerpc/mm/hash64_4k.c
@@ -55,7 +55,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
55 * need to add in 0x1 if it's a read-only user page 55 * need to add in 0x1 if it's a read-only user page
56 */ 56 */
57 rflags = htab_convert_pte_flags(new_pte); 57 rflags = htab_convert_pte_flags(new_pte);
58 rpte = __real_pte(__pte(old_pte), ptep); 58 rpte = __real_pte(__pte(old_pte), ptep, PTRS_PER_PTE);
59 59
60 if (cpu_has_feature(CPU_FTR_NOEXECUTE) && 60 if (cpu_has_feature(CPU_FTR_NOEXECUTE) &&
61 !cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) 61 !cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
@@ -117,7 +117,7 @@ repeat:
117 return -1; 117 return -1;
118 } 118 }
119 new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | H_PAGE_HASHPTE; 119 new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | H_PAGE_HASHPTE;
120 new_pte |= pte_set_hidx(ptep, rpte, 0, slot); 120 new_pte |= pte_set_hidx(ptep, rpte, 0, slot, PTRS_PER_PTE);
121 } 121 }
122 *ptep = __pte(new_pte & ~H_PAGE_BUSY); 122 *ptep = __pte(new_pte & ~H_PAGE_BUSY);
123 return 0; 123 return 0;
diff --git a/arch/powerpc/mm/hash64_64k.c b/arch/powerpc/mm/hash64_64k.c
index 2253bbc6a599..e601d95c3b20 100644
--- a/arch/powerpc/mm/hash64_64k.c
+++ b/arch/powerpc/mm/hash64_64k.c
@@ -86,7 +86,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
86 86
87 subpg_index = (ea & (PAGE_SIZE - 1)) >> shift; 87 subpg_index = (ea & (PAGE_SIZE - 1)) >> shift;
88 vpn = hpt_vpn(ea, vsid, ssize); 88 vpn = hpt_vpn(ea, vsid, ssize);
89 rpte = __real_pte(__pte(old_pte), ptep); 89 rpte = __real_pte(__pte(old_pte), ptep, PTRS_PER_PTE);
90 /* 90 /*
91 *None of the sub 4k page is hashed 91 *None of the sub 4k page is hashed
92 */ 92 */
@@ -214,7 +214,7 @@ repeat:
214 return -1; 214 return -1;
215 } 215 }
216 216
217 new_pte |= pte_set_hidx(ptep, rpte, subpg_index, slot); 217 new_pte |= pte_set_hidx(ptep, rpte, subpg_index, slot, PTRS_PER_PTE);
218 new_pte |= H_PAGE_HASHPTE; 218 new_pte |= H_PAGE_HASHPTE;
219 219
220 *ptep = __pte(new_pte & ~H_PAGE_BUSY); 220 *ptep = __pte(new_pte & ~H_PAGE_BUSY);
@@ -262,7 +262,7 @@ int __hash_page_64K(unsigned long ea, unsigned long access,
262 } while (!pte_xchg(ptep, __pte(old_pte), __pte(new_pte))); 262 } while (!pte_xchg(ptep, __pte(old_pte), __pte(new_pte)));
263 263
264 rflags = htab_convert_pte_flags(new_pte); 264 rflags = htab_convert_pte_flags(new_pte);
265 rpte = __real_pte(__pte(old_pte), ptep); 265 rpte = __real_pte(__pte(old_pte), ptep, PTRS_PER_PTE);
266 266
267 if (cpu_has_feature(CPU_FTR_NOEXECUTE) && 267 if (cpu_has_feature(CPU_FTR_NOEXECUTE) &&
268 !cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) 268 !cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
@@ -327,7 +327,7 @@ repeat:
327 } 327 }
328 328
329 new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | H_PAGE_HASHPTE; 329 new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | H_PAGE_HASHPTE;
330 new_pte |= pte_set_hidx(ptep, rpte, 0, slot); 330 new_pte |= pte_set_hidx(ptep, rpte, 0, slot, PTRS_PER_PTE);
331 } 331 }
332 *ptep = __pte(new_pte & ~H_PAGE_BUSY); 332 *ptep = __pte(new_pte & ~H_PAGE_BUSY);
333 return 0; 333 return 0;
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 7d07c7e17db6..cf290d415dcd 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -1008,6 +1008,7 @@ void __init hash__early_init_mmu(void)
1008 __pmd_index_size = H_PMD_INDEX_SIZE; 1008 __pmd_index_size = H_PMD_INDEX_SIZE;
1009 __pud_index_size = H_PUD_INDEX_SIZE; 1009 __pud_index_size = H_PUD_INDEX_SIZE;
1010 __pgd_index_size = H_PGD_INDEX_SIZE; 1010 __pgd_index_size = H_PGD_INDEX_SIZE;
1011 __pud_cache_index = H_PUD_CACHE_INDEX;
1011 __pmd_cache_index = H_PMD_CACHE_INDEX; 1012 __pmd_cache_index = H_PMD_CACHE_INDEX;
1012 __pte_table_size = H_PTE_TABLE_SIZE; 1013 __pte_table_size = H_PTE_TABLE_SIZE;
1013 __pmd_table_size = H_PMD_TABLE_SIZE; 1014 __pmd_table_size = H_PMD_TABLE_SIZE;
diff --git a/arch/powerpc/mm/hugetlbpage-hash64.c b/arch/powerpc/mm/hugetlbpage-hash64.c
index 12511f5a015f..b320f5097a06 100644
--- a/arch/powerpc/mm/hugetlbpage-hash64.c
+++ b/arch/powerpc/mm/hugetlbpage-hash64.c
@@ -27,7 +27,7 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
27 unsigned long vpn; 27 unsigned long vpn;
28 unsigned long old_pte, new_pte; 28 unsigned long old_pte, new_pte;
29 unsigned long rflags, pa, sz; 29 unsigned long rflags, pa, sz;
30 long slot; 30 long slot, offset;
31 31
32 BUG_ON(shift != mmu_psize_defs[mmu_psize].shift); 32 BUG_ON(shift != mmu_psize_defs[mmu_psize].shift);
33 33
@@ -63,7 +63,11 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
63 } while(!pte_xchg(ptep, __pte(old_pte), __pte(new_pte))); 63 } while(!pte_xchg(ptep, __pte(old_pte), __pte(new_pte)));
64 64
65 rflags = htab_convert_pte_flags(new_pte); 65 rflags = htab_convert_pte_flags(new_pte);
66 rpte = __real_pte(__pte(old_pte), ptep); 66 if (unlikely(mmu_psize == MMU_PAGE_16G))
67 offset = PTRS_PER_PUD;
68 else
69 offset = PTRS_PER_PMD;
70 rpte = __real_pte(__pte(old_pte), ptep, offset);
67 71
68 sz = ((1UL) << shift); 72 sz = ((1UL) << shift);
69 if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) 73 if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
@@ -104,7 +108,7 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
104 return -1; 108 return -1;
105 } 109 }
106 110
107 new_pte |= pte_set_hidx(ptep, rpte, 0, slot); 111 new_pte |= pte_set_hidx(ptep, rpte, 0, slot, offset);
108 } 112 }
109 113
110 /* 114 /*
diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index eb8c6c8c4851..2b656e67f2ea 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -100,6 +100,6 @@ void pgtable_cache_init(void)
100 * same size as either the pgd or pmd index except with THP enabled 100 * same size as either the pgd or pmd index except with THP enabled
101 * on book3s 64 101 * on book3s 64
102 */ 102 */
103 if (PUD_INDEX_SIZE && !PGT_CACHE(PUD_INDEX_SIZE)) 103 if (PUD_CACHE_INDEX && !PGT_CACHE(PUD_CACHE_INDEX))
104 pgtable_cache_add(PUD_INDEX_SIZE, pud_ctor); 104 pgtable_cache_add(PUD_CACHE_INDEX, pud_ctor);
105} 105}
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 314d19ab9385..edd8d0bc9364 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -143,11 +143,6 @@ static void reset_numa_cpu_lookup_table(void)
143 numa_cpu_lookup_table[cpu] = -1; 143 numa_cpu_lookup_table[cpu] = -1;
144} 144}
145 145
146static void update_numa_cpu_lookup_table(unsigned int cpu, int node)
147{
148 numa_cpu_lookup_table[cpu] = node;
149}
150
151static void map_cpu_to_node(int cpu, int node) 146static void map_cpu_to_node(int cpu, int node)
152{ 147{
153 update_numa_cpu_lookup_table(cpu, node); 148 update_numa_cpu_lookup_table(cpu, node);
diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index 573a9a2ee455..2e10a964e290 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -17,9 +17,11 @@
17#include <linux/of_fdt.h> 17#include <linux/of_fdt.h>
18#include <linux/mm.h> 18#include <linux/mm.h>
19#include <linux/string_helpers.h> 19#include <linux/string_helpers.h>
20#include <linux/stop_machine.h>
20 21
21#include <asm/pgtable.h> 22#include <asm/pgtable.h>
22#include <asm/pgalloc.h> 23#include <asm/pgalloc.h>
24#include <asm/mmu_context.h>
23#include <asm/dma.h> 25#include <asm/dma.h>
24#include <asm/machdep.h> 26#include <asm/machdep.h>
25#include <asm/mmu.h> 27#include <asm/mmu.h>
@@ -333,6 +335,22 @@ static void __init radix_init_pgtable(void)
333 "r" (TLBIEL_INVAL_SET_LPID), "r" (0)); 335 "r" (TLBIEL_INVAL_SET_LPID), "r" (0));
334 asm volatile("eieio; tlbsync; ptesync" : : : "memory"); 336 asm volatile("eieio; tlbsync; ptesync" : : : "memory");
335 trace_tlbie(0, 0, TLBIEL_INVAL_SET_LPID, 0, 2, 1, 1); 337 trace_tlbie(0, 0, TLBIEL_INVAL_SET_LPID, 0, 2, 1, 1);
338
339 /*
340 * The init_mm context is given the first available (non-zero) PID,
341 * which is the "guard PID" and contains no page table. PIDR should
342 * never be set to zero because that duplicates the kernel address
343 * space at the 0x0... offset (quadrant 0)!
344 *
345 * An arbitrary PID that may later be allocated by the PID allocator
346 * for userspace processes must not be used either, because that
347 * would cause stale user mappings for that PID on CPUs outside of
348 * the TLB invalidation scheme (because it won't be in mm_cpumask).
349 *
350 * So permanently carve out one PID for the purpose of a guard PID.
351 */
352 init_mm.context.id = mmu_base_pid;
353 mmu_base_pid++;
336} 354}
337 355
338static void __init radix_init_partition_table(void) 356static void __init radix_init_partition_table(void)
@@ -535,6 +553,7 @@ void __init radix__early_init_mmu(void)
535 __pmd_index_size = RADIX_PMD_INDEX_SIZE; 553 __pmd_index_size = RADIX_PMD_INDEX_SIZE;
536 __pud_index_size = RADIX_PUD_INDEX_SIZE; 554 __pud_index_size = RADIX_PUD_INDEX_SIZE;
537 __pgd_index_size = RADIX_PGD_INDEX_SIZE; 555 __pgd_index_size = RADIX_PGD_INDEX_SIZE;
556 __pud_cache_index = RADIX_PUD_INDEX_SIZE;
538 __pmd_cache_index = RADIX_PMD_INDEX_SIZE; 557 __pmd_cache_index = RADIX_PMD_INDEX_SIZE;
539 __pte_table_size = RADIX_PTE_TABLE_SIZE; 558 __pte_table_size = RADIX_PTE_TABLE_SIZE;
540 __pmd_table_size = RADIX_PMD_TABLE_SIZE; 559 __pmd_table_size = RADIX_PMD_TABLE_SIZE;
@@ -579,7 +598,8 @@ void __init radix__early_init_mmu(void)
579 598
580 radix_init_iamr(); 599 radix_init_iamr();
581 radix_init_pgtable(); 600 radix_init_pgtable();
582 601 /* Switch to the guard PID before turning on MMU */
602 radix__switch_mmu_context(NULL, &init_mm);
583 if (cpu_has_feature(CPU_FTR_HVMODE)) 603 if (cpu_has_feature(CPU_FTR_HVMODE))
584 tlbiel_all(); 604 tlbiel_all();
585} 605}
@@ -604,6 +624,7 @@ void radix__early_init_mmu_secondary(void)
604 } 624 }
605 radix_init_iamr(); 625 radix_init_iamr();
606 626
627 radix__switch_mmu_context(NULL, &init_mm);
607 if (cpu_has_feature(CPU_FTR_HVMODE)) 628 if (cpu_has_feature(CPU_FTR_HVMODE))
608 tlbiel_all(); 629 tlbiel_all();
609} 630}
@@ -666,6 +687,30 @@ static void free_pmd_table(pmd_t *pmd_start, pud_t *pud)
666 pud_clear(pud); 687 pud_clear(pud);
667} 688}
668 689
690struct change_mapping_params {
691 pte_t *pte;
692 unsigned long start;
693 unsigned long end;
694 unsigned long aligned_start;
695 unsigned long aligned_end;
696};
697
698static int stop_machine_change_mapping(void *data)
699{
700 struct change_mapping_params *params =
701 (struct change_mapping_params *)data;
702
703 if (!data)
704 return -1;
705
706 spin_unlock(&init_mm.page_table_lock);
707 pte_clear(&init_mm, params->aligned_start, params->pte);
708 create_physical_mapping(params->aligned_start, params->start);
709 create_physical_mapping(params->end, params->aligned_end);
710 spin_lock(&init_mm.page_table_lock);
711 return 0;
712}
713
669static void remove_pte_table(pte_t *pte_start, unsigned long addr, 714static void remove_pte_table(pte_t *pte_start, unsigned long addr,
670 unsigned long end) 715 unsigned long end)
671{ 716{
@@ -694,6 +739,52 @@ static void remove_pte_table(pte_t *pte_start, unsigned long addr,
694 } 739 }
695} 740}
696 741
742/*
743 * clear the pte and potentially split the mapping helper
744 */
745static void split_kernel_mapping(unsigned long addr, unsigned long end,
746 unsigned long size, pte_t *pte)
747{
748 unsigned long mask = ~(size - 1);
749 unsigned long aligned_start = addr & mask;
750 unsigned long aligned_end = addr + size;
751 struct change_mapping_params params;
752 bool split_region = false;
753
754 if ((end - addr) < size) {
755 /*
756 * We're going to clear the PTE, but not flushed
757 * the mapping, time to remap and flush. The
758 * effects if visible outside the processor or
759 * if we are running in code close to the
760 * mapping we cleared, we are in trouble.
761 */
762 if (overlaps_kernel_text(aligned_start, addr) ||
763 overlaps_kernel_text(end, aligned_end)) {
764 /*
765 * Hack, just return, don't pte_clear
766 */
767 WARN_ONCE(1, "Linear mapping %lx->%lx overlaps kernel "
768 "text, not splitting\n", addr, end);
769 return;
770 }
771 split_region = true;
772 }
773
774 if (split_region) {
775 params.pte = pte;
776 params.start = addr;
777 params.end = end;
778 params.aligned_start = addr & ~(size - 1);
779 params.aligned_end = min_t(unsigned long, aligned_end,
780 (unsigned long)__va(memblock_end_of_DRAM()));
781 stop_machine(stop_machine_change_mapping, &params, NULL);
782 return;
783 }
784
785 pte_clear(&init_mm, addr, pte);
786}
787
697static void remove_pmd_table(pmd_t *pmd_start, unsigned long addr, 788static void remove_pmd_table(pmd_t *pmd_start, unsigned long addr,
698 unsigned long end) 789 unsigned long end)
699{ 790{
@@ -709,13 +800,7 @@ static void remove_pmd_table(pmd_t *pmd_start, unsigned long addr,
709 continue; 800 continue;
710 801
711 if (pmd_huge(*pmd)) { 802 if (pmd_huge(*pmd)) {
712 if (!IS_ALIGNED(addr, PMD_SIZE) || 803 split_kernel_mapping(addr, end, PMD_SIZE, (pte_t *)pmd);
713 !IS_ALIGNED(next, PMD_SIZE)) {
714 WARN_ONCE(1, "%s: unaligned range\n", __func__);
715 continue;
716 }
717
718 pte_clear(&init_mm, addr, (pte_t *)pmd);
719 continue; 804 continue;
720 } 805 }
721 806
@@ -740,13 +825,7 @@ static void remove_pud_table(pud_t *pud_start, unsigned long addr,
740 continue; 825 continue;
741 826
742 if (pud_huge(*pud)) { 827 if (pud_huge(*pud)) {
743 if (!IS_ALIGNED(addr, PUD_SIZE) || 828 split_kernel_mapping(addr, end, PUD_SIZE, (pte_t *)pud);
744 !IS_ALIGNED(next, PUD_SIZE)) {
745 WARN_ONCE(1, "%s: unaligned range\n", __func__);
746 continue;
747 }
748
749 pte_clear(&init_mm, addr, (pte_t *)pud);
750 continue; 829 continue;
751 } 830 }
752 831
@@ -772,13 +851,7 @@ static void remove_pagetable(unsigned long start, unsigned long end)
772 continue; 851 continue;
773 852
774 if (pgd_huge(*pgd)) { 853 if (pgd_huge(*pgd)) {
775 if (!IS_ALIGNED(addr, PGDIR_SIZE) || 854 split_kernel_mapping(addr, end, PGDIR_SIZE, (pte_t *)pgd);
776 !IS_ALIGNED(next, PGDIR_SIZE)) {
777 WARN_ONCE(1, "%s: unaligned range\n", __func__);
778 continue;
779 }
780
781 pte_clear(&init_mm, addr, (pte_t *)pgd);
782 continue; 855 continue;
783 } 856 }
784 857
diff --git a/arch/powerpc/mm/pgtable_64.c b/arch/powerpc/mm/pgtable_64.c
index c9a623c2d8a2..28c980eb4422 100644
--- a/arch/powerpc/mm/pgtable_64.c
+++ b/arch/powerpc/mm/pgtable_64.c
@@ -82,6 +82,8 @@ unsigned long __pgd_index_size;
82EXPORT_SYMBOL(__pgd_index_size); 82EXPORT_SYMBOL(__pgd_index_size);
83unsigned long __pmd_cache_index; 83unsigned long __pmd_cache_index;
84EXPORT_SYMBOL(__pmd_cache_index); 84EXPORT_SYMBOL(__pmd_cache_index);
85unsigned long __pud_cache_index;
86EXPORT_SYMBOL(__pud_cache_index);
85unsigned long __pte_table_size; 87unsigned long __pte_table_size;
86EXPORT_SYMBOL(__pte_table_size); 88EXPORT_SYMBOL(__pte_table_size);
87unsigned long __pmd_table_size; 89unsigned long __pmd_table_size;
@@ -471,6 +473,8 @@ void mmu_partition_table_set_entry(unsigned int lpid, unsigned long dw0,
471 if (old & PATB_HR) { 473 if (old & PATB_HR) {
472 asm volatile(PPC_TLBIE_5(%0,%1,2,0,1) : : 474 asm volatile(PPC_TLBIE_5(%0,%1,2,0,1) : :
473 "r" (TLBIEL_INVAL_SET_LPID), "r" (lpid)); 475 "r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
476 asm volatile(PPC_TLBIE_5(%0,%1,2,1,1) : :
477 "r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
474 trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 1); 478 trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 1);
475 } else { 479 } else {
476 asm volatile(PPC_TLBIE_5(%0,%1,2,0,0) : : 480 asm volatile(PPC_TLBIE_5(%0,%1,2,0,0) : :
diff --git a/arch/powerpc/mm/tlb_hash64.c b/arch/powerpc/mm/tlb_hash64.c
index 881ebd53ffc2..9b23f12e863c 100644
--- a/arch/powerpc/mm/tlb_hash64.c
+++ b/arch/powerpc/mm/tlb_hash64.c
@@ -51,7 +51,7 @@ void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
51 unsigned int psize; 51 unsigned int psize;
52 int ssize; 52 int ssize;
53 real_pte_t rpte; 53 real_pte_t rpte;
54 int i; 54 int i, offset;
55 55
56 i = batch->index; 56 i = batch->index;
57 57
@@ -67,6 +67,10 @@ void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
67 psize = get_slice_psize(mm, addr); 67 psize = get_slice_psize(mm, addr);
68 /* Mask the address for the correct page size */ 68 /* Mask the address for the correct page size */
69 addr &= ~((1UL << mmu_psize_defs[psize].shift) - 1); 69 addr &= ~((1UL << mmu_psize_defs[psize].shift) - 1);
70 if (unlikely(psize == MMU_PAGE_16G))
71 offset = PTRS_PER_PUD;
72 else
73 offset = PTRS_PER_PMD;
70#else 74#else
71 BUG(); 75 BUG();
72 psize = pte_pagesize_index(mm, addr, pte); /* shutup gcc */ 76 psize = pte_pagesize_index(mm, addr, pte); /* shutup gcc */
@@ -78,6 +82,7 @@ void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
78 * support 64k pages, this might be different from the 82 * support 64k pages, this might be different from the
79 * hardware page size encoded in the slice table. */ 83 * hardware page size encoded in the slice table. */
80 addr &= PAGE_MASK; 84 addr &= PAGE_MASK;
85 offset = PTRS_PER_PTE;
81 } 86 }
82 87
83 88
@@ -91,7 +96,7 @@ void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
91 } 96 }
92 WARN_ON(vsid == 0); 97 WARN_ON(vsid == 0);
93 vpn = hpt_vpn(addr, vsid, ssize); 98 vpn = hpt_vpn(addr, vsid, ssize);
94 rpte = __real_pte(__pte(pte), ptep); 99 rpte = __real_pte(__pte(pte), ptep, offset);
95 100
96 /* 101 /*
97 * Check if we have an active batch on this CPU. If not, just 102 * Check if we have an active batch on this CPU. If not, just
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index 872d1f6dd11e..a9636d8cba15 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -327,6 +327,9 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
327 BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, len) != 4); 327 BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, len) != 4);
328 PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff, len)); 328 PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff, len));
329 break; 329 break;
330 case BPF_LDX | BPF_W | BPF_ABS: /* A = *((u32 *)(seccomp_data + K)); */
331 PPC_LWZ_OFFS(r_A, r_skb, K);
332 break;
330 case BPF_LDX | BPF_W | BPF_LEN: /* X = skb->len; */ 333 case BPF_LDX | BPF_W | BPF_LEN: /* X = skb->len; */
331 PPC_LWZ_OFFS(r_X, r_skb, offsetof(struct sk_buff, len)); 334 PPC_LWZ_OFFS(r_X, r_skb, offsetof(struct sk_buff, len));
332 break; 335 break;
diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c
index 0a34b0cec7b7..0ef3d9580e98 100644
--- a/arch/powerpc/net/bpf_jit_comp64.c
+++ b/arch/powerpc/net/bpf_jit_comp64.c
@@ -240,6 +240,7 @@ static void bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32
240 * goto out; 240 * goto out;
241 */ 241 */
242 PPC_LWZ(b2p[TMP_REG_1], b2p_bpf_array, offsetof(struct bpf_array, map.max_entries)); 242 PPC_LWZ(b2p[TMP_REG_1], b2p_bpf_array, offsetof(struct bpf_array, map.max_entries));
243 PPC_RLWINM(b2p_index, b2p_index, 0, 0, 31);
243 PPC_CMPLW(b2p_index, b2p[TMP_REG_1]); 244 PPC_CMPLW(b2p_index, b2p[TMP_REG_1]);
244 PPC_BCC(COND_GE, out); 245 PPC_BCC(COND_GE, out);
245 246
diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c
index dd4c9b8b8a81..f6f55ab4980e 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -199,9 +199,11 @@ static void disable_nest_pmu_counters(void)
199 const struct cpumask *l_cpumask; 199 const struct cpumask *l_cpumask;
200 200
201 get_online_cpus(); 201 get_online_cpus();
202 for_each_online_node(nid) { 202 for_each_node_with_cpus(nid) {
203 l_cpumask = cpumask_of_node(nid); 203 l_cpumask = cpumask_of_node(nid);
204 cpu = cpumask_first(l_cpumask); 204 cpu = cpumask_first_and(l_cpumask, cpu_online_mask);
205 if (cpu >= nr_cpu_ids)
206 continue;
205 opal_imc_counters_stop(OPAL_IMC_COUNTERS_NEST, 207 opal_imc_counters_stop(OPAL_IMC_COUNTERS_NEST,
206 get_hard_smp_processor_id(cpu)); 208 get_hard_smp_processor_id(cpu));
207 } 209 }
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 496e47696ed0..a6c92c78c9b2 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1854,7 +1854,7 @@ static int pnv_pci_ioda_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
1854 s64 rc; 1854 s64 rc;
1855 1855
1856 if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE)) 1856 if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE))
1857 return -ENODEV;; 1857 return -ENODEV;
1858 1858
1859 pe = &phb->ioda.pe_array[pdn->pe_number]; 1859 pe = &phb->ioda.pe_array[pdn->pe_number];
1860 if (pe->tce_bypass_enabled) { 1860 if (pe->tce_bypass_enabled) {
diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c
index 4fb21e17504a..092715b9674b 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -80,6 +80,10 @@ static void pnv_setup_rfi_flush(void)
80 if (np && of_property_read_bool(np, "disabled")) 80 if (np && of_property_read_bool(np, "disabled"))
81 enable--; 81 enable--;
82 82
83 np = of_get_child_by_name(fw_features, "speculation-policy-favor-security");
84 if (np && of_property_read_bool(np, "disabled"))
85 enable = 0;
86
83 of_node_put(np); 87 of_node_put(np);
84 of_node_put(fw_features); 88 of_node_put(fw_features);
85 } 89 }
diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
index 2b3eb01ab110..b7c53a51c31b 100644
--- a/arch/powerpc/platforms/powernv/vas-window.c
+++ b/arch/powerpc/platforms/powernv/vas-window.c
@@ -1063,16 +1063,16 @@ struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop,
1063 rc = PTR_ERR(txwin->paste_kaddr); 1063 rc = PTR_ERR(txwin->paste_kaddr);
1064 goto free_window; 1064 goto free_window;
1065 } 1065 }
1066 } else {
1067 /*
1068 * A user mapping must ensure that context switch issues
1069 * CP_ABORT for this thread.
1070 */
1071 rc = set_thread_uses_vas();
1072 if (rc)
1073 goto free_window;
1066 } 1074 }
1067 1075
1068 /*
1069 * Now that we have a send window, ensure context switch issues
1070 * CP_ABORT for this thread.
1071 */
1072 rc = -EINVAL;
1073 if (set_thread_uses_vas() < 0)
1074 goto free_window;
1075
1076 set_vinst_win(vinst, txwin); 1076 set_vinst_win(vinst, txwin);
1077 1077
1078 return txwin; 1078 return txwin;
diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index dceb51454d8d..652d3e96b812 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -36,6 +36,7 @@
36#include <asm/xics.h> 36#include <asm/xics.h>
37#include <asm/xive.h> 37#include <asm/xive.h>
38#include <asm/plpar_wrappers.h> 38#include <asm/plpar_wrappers.h>
39#include <asm/topology.h>
39 40
40#include "pseries.h" 41#include "pseries.h"
41#include "offline_states.h" 42#include "offline_states.h"
@@ -331,6 +332,7 @@ static void pseries_remove_processor(struct device_node *np)
331 BUG_ON(cpu_online(cpu)); 332 BUG_ON(cpu_online(cpu));
332 set_cpu_present(cpu, false); 333 set_cpu_present(cpu, false);
333 set_hard_smp_processor_id(cpu, -1); 334 set_hard_smp_processor_id(cpu, -1);
335 update_numa_cpu_lookup_table(cpu, -1);
334 break; 336 break;
335 } 337 }
336 if (cpu >= nr_cpu_ids) 338 if (cpu >= nr_cpu_ids)
@@ -340,8 +342,6 @@ static void pseries_remove_processor(struct device_node *np)
340 cpu_maps_update_done(); 342 cpu_maps_update_done();
341} 343}
342 344
343extern int find_and_online_cpu_nid(int cpu);
344
345static int dlpar_online_cpu(struct device_node *dn) 345static int dlpar_online_cpu(struct device_node *dn)
346{ 346{
347 int rc = 0; 347 int rc = 0;
diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index 81d8614e7379..5e1ef9150182 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -49,6 +49,28 @@ static irqreturn_t ras_error_interrupt(int irq, void *dev_id);
49 49
50 50
51/* 51/*
52 * Enable the hotplug interrupt late because processing them may touch other
53 * devices or systems (e.g. hugepages) that have not been initialized at the
54 * subsys stage.
55 */
56int __init init_ras_hotplug_IRQ(void)
57{
58 struct device_node *np;
59
60 /* Hotplug Events */
61 np = of_find_node_by_path("/event-sources/hot-plug-events");
62 if (np != NULL) {
63 if (dlpar_workqueue_init() == 0)
64 request_event_sources_irqs(np, ras_hotplug_interrupt,
65 "RAS_HOTPLUG");
66 of_node_put(np);
67 }
68
69 return 0;
70}
71machine_late_initcall(pseries, init_ras_hotplug_IRQ);
72
73/*
52 * Initialize handlers for the set of interrupts caused by hardware errors 74 * Initialize handlers for the set of interrupts caused by hardware errors
53 * and power system events. 75 * and power system events.
54 */ 76 */
@@ -66,15 +88,6 @@ static int __init init_ras_IRQ(void)
66 of_node_put(np); 88 of_node_put(np);
67 } 89 }
68 90
69 /* Hotplug Events */
70 np = of_find_node_by_path("/event-sources/hot-plug-events");
71 if (np != NULL) {
72 if (dlpar_workqueue_init() == 0)
73 request_event_sources_irqs(np, ras_hotplug_interrupt,
74 "RAS_HOTPLUG");
75 of_node_put(np);
76 }
77
78 /* EPOW Events */ 91 /* EPOW Events */
79 np = of_find_node_by_path("/event-sources/epow-events"); 92 np = of_find_node_by_path("/event-sources/epow-events");
80 if (np != NULL) { 93 if (np != NULL) {
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 372d7ada1a0c..1a527625acf7 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -482,7 +482,8 @@ static void pseries_setup_rfi_flush(void)
482 if (types == L1D_FLUSH_NONE) 482 if (types == L1D_FLUSH_NONE)
483 types = L1D_FLUSH_FALLBACK; 483 types = L1D_FLUSH_FALLBACK;
484 484
485 if (!(result.behaviour & H_CPU_BEHAV_L1D_FLUSH_PR)) 485 if ((!(result.behaviour & H_CPU_BEHAV_L1D_FLUSH_PR)) ||
486 (!(result.behaviour & H_CPU_BEHAV_FAVOUR_SECURITY)))
486 enable = false; 487 enable = false;
487 } else { 488 } else {
488 /* Default to fallback if case hcall is not available */ 489 /* Default to fallback if case hcall is not available */
diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
index d9c4c9366049..091f1d0d0af1 100644
--- a/arch/powerpc/sysdev/xive/spapr.c
+++ b/arch/powerpc/sysdev/xive/spapr.c
@@ -356,7 +356,8 @@ static int xive_spapr_configure_queue(u32 target, struct xive_q *q, u8 prio,
356 356
357 rc = plpar_int_get_queue_info(0, target, prio, &esn_page, &esn_size); 357 rc = plpar_int_get_queue_info(0, target, prio, &esn_page, &esn_size);
358 if (rc) { 358 if (rc) {
359 pr_err("Error %lld getting queue info prio %d\n", rc, prio); 359 pr_err("Error %lld getting queue info CPU %d prio %d\n", rc,
360 target, prio);
360 rc = -EIO; 361 rc = -EIO;
361 goto fail; 362 goto fail;
362 } 363 }
@@ -370,7 +371,8 @@ static int xive_spapr_configure_queue(u32 target, struct xive_q *q, u8 prio,
370 /* Configure and enable the queue in HW */ 371 /* Configure and enable the queue in HW */
371 rc = plpar_int_set_queue_config(flags, target, prio, qpage_phys, order); 372 rc = plpar_int_set_queue_config(flags, target, prio, qpage_phys, order);
372 if (rc) { 373 if (rc) {
373 pr_err("Error %lld setting queue for prio %d\n", rc, prio); 374 pr_err("Error %lld setting queue for CPU %d prio %d\n", rc,
375 target, prio);
374 rc = -EIO; 376 rc = -EIO;
375 } else { 377 } else {
376 q->qpage = qpage; 378 q->qpage = qpage;
@@ -389,8 +391,8 @@ static int xive_spapr_setup_queue(unsigned int cpu, struct xive_cpu *xc,
389 if (IS_ERR(qpage)) 391 if (IS_ERR(qpage))
390 return PTR_ERR(qpage); 392 return PTR_ERR(qpage);
391 393
392 return xive_spapr_configure_queue(cpu, q, prio, qpage, 394 return xive_spapr_configure_queue(get_hard_smp_processor_id(cpu),
393 xive_queue_shift); 395 q, prio, qpage, xive_queue_shift);
394} 396}
395 397
396static void xive_spapr_cleanup_queue(unsigned int cpu, struct xive_cpu *xc, 398static void xive_spapr_cleanup_queue(unsigned int cpu, struct xive_cpu *xc,
@@ -399,10 +401,12 @@ static void xive_spapr_cleanup_queue(unsigned int cpu, struct xive_cpu *xc,
399 struct xive_q *q = &xc->queue[prio]; 401 struct xive_q *q = &xc->queue[prio];
400 unsigned int alloc_order; 402 unsigned int alloc_order;
401 long rc; 403 long rc;
404 int hw_cpu = get_hard_smp_processor_id(cpu);
402 405
403 rc = plpar_int_set_queue_config(0, cpu, prio, 0, 0); 406 rc = plpar_int_set_queue_config(0, hw_cpu, prio, 0, 0);
404 if (rc) 407 if (rc)
405 pr_err("Error %ld setting queue for prio %d\n", rc, prio); 408 pr_err("Error %ld setting queue for CPU %d prio %d\n", rc,
409 hw_cpu, prio);
406 410
407 alloc_order = xive_alloc_order(xive_queue_shift); 411 alloc_order = xive_alloc_order(xive_queue_shift);
408 free_pages((unsigned long)q->qpage, alloc_order); 412 free_pages((unsigned long)q->qpage, alloc_order);
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index b6722c246d9c..04807c7f64cc 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -8,7 +8,6 @@ config RISCV
8 select OF 8 select OF
9 select OF_EARLY_FLATTREE 9 select OF_EARLY_FLATTREE
10 select OF_IRQ 10 select OF_IRQ
11 select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
12 select ARCH_WANT_FRAME_POINTERS 11 select ARCH_WANT_FRAME_POINTERS
13 select CLONE_BACKWARDS 12 select CLONE_BACKWARDS
14 select COMMON_CLK 13 select COMMON_CLK
@@ -20,7 +19,6 @@ config RISCV
20 select GENERIC_STRNLEN_USER 19 select GENERIC_STRNLEN_USER
21 select GENERIC_SMP_IDLE_THREAD 20 select GENERIC_SMP_IDLE_THREAD
22 select GENERIC_ATOMIC64 if !64BIT || !RISCV_ISA_A 21 select GENERIC_ATOMIC64 if !64BIT || !RISCV_ISA_A
23 select ARCH_WANT_OPTIONAL_GPIOLIB
24 select HAVE_MEMBLOCK 22 select HAVE_MEMBLOCK
25 select HAVE_MEMBLOCK_NODE_MAP 23 select HAVE_MEMBLOCK_NODE_MAP
26 select HAVE_DMA_API_DEBUG 24 select HAVE_DMA_API_DEBUG
@@ -34,7 +32,6 @@ config RISCV
34 select HAVE_ARCH_TRACEHOOK 32 select HAVE_ARCH_TRACEHOOK
35 select MODULES_USE_ELF_RELA if MODULES 33 select MODULES_USE_ELF_RELA if MODULES
36 select THREAD_INFO_IN_TASK 34 select THREAD_INFO_IN_TASK
37 select RISCV_IRQ_INTC
38 select RISCV_TIMER 35 select RISCV_TIMER
39 36
40config MMU 37config MMU
diff --git a/arch/riscv/include/asm/barrier.h b/arch/riscv/include/asm/barrier.h
index c0319cbf1eec..5510366d169a 100644
--- a/arch/riscv/include/asm/barrier.h
+++ b/arch/riscv/include/asm/barrier.h
@@ -34,9 +34,9 @@
34#define wmb() RISCV_FENCE(ow,ow) 34#define wmb() RISCV_FENCE(ow,ow)
35 35
36/* These barriers do not need to enforce ordering on devices, just memory. */ 36/* These barriers do not need to enforce ordering on devices, just memory. */
37#define smp_mb() RISCV_FENCE(rw,rw) 37#define __smp_mb() RISCV_FENCE(rw,rw)
38#define smp_rmb() RISCV_FENCE(r,r) 38#define __smp_rmb() RISCV_FENCE(r,r)
39#define smp_wmb() RISCV_FENCE(w,w) 39#define __smp_wmb() RISCV_FENCE(w,w)
40 40
41/* 41/*
42 * This is a very specific barrier: it's currently only used in two places in 42 * This is a very specific barrier: it's currently only used in two places in
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index 87fc045be51f..56fa592cfa34 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -172,6 +172,9 @@ ENTRY(handle_exception)
172 move a1, sp /* pt_regs */ 172 move a1, sp /* pt_regs */
173 tail do_IRQ 173 tail do_IRQ
1741: 1741:
175 /* Exceptions run with interrupts enabled */
176 csrs sstatus, SR_SIE
177
175 /* Handle syscalls */ 178 /* Handle syscalls */
176 li t0, EXC_SYSCALL 179 li t0, EXC_SYSCALL
177 beq s4, t0, handle_syscall 180 beq s4, t0, handle_syscall
@@ -198,8 +201,6 @@ handle_syscall:
198 */ 201 */
199 addi s2, s2, 0x4 202 addi s2, s2, 0x4
200 REG_S s2, PT_SEPC(sp) 203 REG_S s2, PT_SEPC(sp)
201 /* System calls run with interrupts enabled */
202 csrs sstatus, SR_SIE
203 /* Trace syscalls, but only if requested by the user. */ 204 /* Trace syscalls, but only if requested by the user. */
204 REG_L t0, TASK_TI_FLAGS(tp) 205 REG_L t0, TASK_TI_FLAGS(tp)
205 andi t0, t0, _TIF_SYSCALL_TRACE 206 andi t0, t0, _TIF_SYSCALL_TRACE
diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index 226eeb190f90..6e07ed37bbff 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -64,7 +64,7 @@ ENTRY(_start)
64 /* Start the kernel */ 64 /* Start the kernel */
65 mv a0, s0 65 mv a0, s0
66 mv a1, s1 66 mv a1, s1
67 call sbi_save 67 call parse_dtb
68 tail start_kernel 68 tail start_kernel
69 69
70relocate: 70relocate:
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 09f7064e898c..c11f40c1b2a8 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -144,7 +144,7 @@ asmlinkage void __init setup_vm(void)
144#endif 144#endif
145} 145}
146 146
147void __init sbi_save(unsigned int hartid, void *dtb) 147void __init parse_dtb(unsigned int hartid, void *dtb)
148{ 148{
149 early_init_dt_scan(__va(dtb)); 149 early_init_dt_scan(__va(dtb));
150} 150}
diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h
index 65154eaa3714..6c8ce15cde7b 100644
--- a/arch/s390/include/asm/mmu_context.h
+++ b/arch/s390/include/asm/mmu_context.h
@@ -63,6 +63,7 @@ static inline int init_new_context(struct task_struct *tsk,
63 _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT; 63 _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT;
64 /* pgd_alloc() did not account this pmd */ 64 /* pgd_alloc() did not account this pmd */
65 mm_inc_nr_pmds(mm); 65 mm_inc_nr_pmds(mm);
66 mm_inc_nr_puds(mm);
66 } 67 }
67 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm)); 68 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
68 return 0; 69 return 0;
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 13a133a6015c..a5621ea6d123 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -14,6 +14,7 @@
14#include <asm/processor.h> 14#include <asm/processor.h>
15#include <asm/cache.h> 15#include <asm/cache.h>
16#include <asm/ctl_reg.h> 16#include <asm/ctl_reg.h>
17#include <asm/dwarf.h>
17#include <asm/errno.h> 18#include <asm/errno.h>
18#include <asm/ptrace.h> 19#include <asm/ptrace.h>
19#include <asm/thread_info.h> 20#include <asm/thread_info.h>
@@ -230,7 +231,7 @@ _PIF_WORK = (_PIF_PER_TRAP | _PIF_SYSCALL_RESTART)
230 .hidden \name 231 .hidden \name
231 .type \name,@function 232 .type \name,@function
232\name: 233\name:
233 .cfi_startproc 234 CFI_STARTPROC
234#ifdef CONFIG_HAVE_MARCH_Z10_FEATURES 235#ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
235 exrl 0,0f 236 exrl 0,0f
236#else 237#else
@@ -239,7 +240,7 @@ _PIF_WORK = (_PIF_PER_TRAP | _PIF_SYSCALL_RESTART)
239#endif 240#endif
240 j . 241 j .
2410: br \reg 2420: br \reg
242 .cfi_endproc 243 CFI_ENDPROC
243 .endm 244 .endm
244 245
245 GEN_BR_THUNK __s390x_indirect_jump_r1use_r9,%r9,%r1 246 GEN_BR_THUNK __s390x_indirect_jump_r1use_r9,%r9,%r1
@@ -426,13 +427,13 @@ ENTRY(system_call)
426 UPDATE_VTIME %r8,%r9,__LC_SYNC_ENTER_TIMER 427 UPDATE_VTIME %r8,%r9,__LC_SYNC_ENTER_TIMER
427 BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP 428 BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
428 stmg %r0,%r7,__PT_R0(%r11) 429 stmg %r0,%r7,__PT_R0(%r11)
429 # clear user controlled register to prevent speculative use
430 xgr %r0,%r0
431 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC 430 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
432 mvc __PT_PSW(16,%r11),__LC_SVC_OLD_PSW 431 mvc __PT_PSW(16,%r11),__LC_SVC_OLD_PSW
433 mvc __PT_INT_CODE(4,%r11),__LC_SVC_ILC 432 mvc __PT_INT_CODE(4,%r11),__LC_SVC_ILC
434 stg %r14,__PT_FLAGS(%r11) 433 stg %r14,__PT_FLAGS(%r11)
435.Lsysc_do_svc: 434.Lsysc_do_svc:
435 # clear user controlled register to prevent speculative use
436 xgr %r0,%r0
436 # load address of system call table 437 # load address of system call table
437 lg %r10,__THREAD_sysc_table(%r13,%r12) 438 lg %r10,__THREAD_sysc_table(%r13,%r12)
438 llgh %r8,__PT_INT_CODE+2(%r11) 439 llgh %r8,__PT_INT_CODE+2(%r11)
@@ -1439,6 +1440,7 @@ cleanup_critical:
1439 stg %r15,__LC_SYSTEM_TIMER 1440 stg %r15,__LC_SYSTEM_TIMER
14400: # update accounting time stamp 14410: # update accounting time stamp
1441 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER 1442 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
1443 BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
1442 # set up saved register r11 1444 # set up saved register r11
1443 lg %r15,__LC_KERNEL_STACK 1445 lg %r15,__LC_KERNEL_STACK
1444 la %r9,STACK_FRAME_OVERHEAD(%r15) 1446 la %r9,STACK_FRAME_OVERHEAD(%r15)
diff --git a/arch/s390/kernel/nospec-branch.c b/arch/s390/kernel/nospec-branch.c
index 69d7fcf48158..9aff72d3abda 100644
--- a/arch/s390/kernel/nospec-branch.c
+++ b/arch/s390/kernel/nospec-branch.c
@@ -2,8 +2,8 @@
2#include <linux/module.h> 2#include <linux/module.h>
3#include <asm/nospec-branch.h> 3#include <asm/nospec-branch.h>
4 4
5int nospec_call_disable = IS_ENABLED(EXPOLINE_OFF); 5int nospec_call_disable = IS_ENABLED(CONFIG_EXPOLINE_OFF);
6int nospec_return_disable = !IS_ENABLED(EXPOLINE_FULL); 6int nospec_return_disable = !IS_ENABLED(CONFIG_EXPOLINE_FULL);
7 7
8static int __init nospectre_v2_setup_early(char *str) 8static int __init nospectre_v2_setup_early(char *str)
9{ 9{
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
index 9c7d70715862..07c6e81163bf 100644
--- a/arch/s390/kvm/intercept.c
+++ b/arch/s390/kvm/intercept.c
@@ -22,22 +22,6 @@
22#include "trace.h" 22#include "trace.h"
23#include "trace-s390.h" 23#include "trace-s390.h"
24 24
25
26static const intercept_handler_t instruction_handlers[256] = {
27 [0x01] = kvm_s390_handle_01,
28 [0x82] = kvm_s390_handle_lpsw,
29 [0x83] = kvm_s390_handle_diag,
30 [0xaa] = kvm_s390_handle_aa,
31 [0xae] = kvm_s390_handle_sigp,
32 [0xb2] = kvm_s390_handle_b2,
33 [0xb6] = kvm_s390_handle_stctl,
34 [0xb7] = kvm_s390_handle_lctl,
35 [0xb9] = kvm_s390_handle_b9,
36 [0xe3] = kvm_s390_handle_e3,
37 [0xe5] = kvm_s390_handle_e5,
38 [0xeb] = kvm_s390_handle_eb,
39};
40
41u8 kvm_s390_get_ilen(struct kvm_vcpu *vcpu) 25u8 kvm_s390_get_ilen(struct kvm_vcpu *vcpu)
42{ 26{
43 struct kvm_s390_sie_block *sie_block = vcpu->arch.sie_block; 27 struct kvm_s390_sie_block *sie_block = vcpu->arch.sie_block;
@@ -129,16 +113,39 @@ static int handle_validity(struct kvm_vcpu *vcpu)
129 113
130static int handle_instruction(struct kvm_vcpu *vcpu) 114static int handle_instruction(struct kvm_vcpu *vcpu)
131{ 115{
132 intercept_handler_t handler;
133
134 vcpu->stat.exit_instruction++; 116 vcpu->stat.exit_instruction++;
135 trace_kvm_s390_intercept_instruction(vcpu, 117 trace_kvm_s390_intercept_instruction(vcpu,
136 vcpu->arch.sie_block->ipa, 118 vcpu->arch.sie_block->ipa,
137 vcpu->arch.sie_block->ipb); 119 vcpu->arch.sie_block->ipb);
138 handler = instruction_handlers[vcpu->arch.sie_block->ipa >> 8]; 120
139 if (handler) 121 switch (vcpu->arch.sie_block->ipa >> 8) {
140 return handler(vcpu); 122 case 0x01:
141 return -EOPNOTSUPP; 123 return kvm_s390_handle_01(vcpu);
124 case 0x82:
125 return kvm_s390_handle_lpsw(vcpu);
126 case 0x83:
127 return kvm_s390_handle_diag(vcpu);
128 case 0xaa:
129 return kvm_s390_handle_aa(vcpu);
130 case 0xae:
131 return kvm_s390_handle_sigp(vcpu);
132 case 0xb2:
133 return kvm_s390_handle_b2(vcpu);
134 case 0xb6:
135 return kvm_s390_handle_stctl(vcpu);
136 case 0xb7:
137 return kvm_s390_handle_lctl(vcpu);
138 case 0xb9:
139 return kvm_s390_handle_b9(vcpu);
140 case 0xe3:
141 return kvm_s390_handle_e3(vcpu);
142 case 0xe5:
143 return kvm_s390_handle_e5(vcpu);
144 case 0xeb:
145 return kvm_s390_handle_eb(vcpu);
146 default:
147 return -EOPNOTSUPP;
148 }
142} 149}
143 150
144static int inject_prog_on_prog_intercept(struct kvm_vcpu *vcpu) 151static int inject_prog_on_prog_intercept(struct kvm_vcpu *vcpu)
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index aabf46f5f883..b04616b57a94 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -169,8 +169,15 @@ static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu)
169 169
170static int ckc_irq_pending(struct kvm_vcpu *vcpu) 170static int ckc_irq_pending(struct kvm_vcpu *vcpu)
171{ 171{
172 if (vcpu->arch.sie_block->ckc >= kvm_s390_get_tod_clock_fast(vcpu->kvm)) 172 const u64 now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
173 const u64 ckc = vcpu->arch.sie_block->ckc;
174
175 if (vcpu->arch.sie_block->gcr[0] & 0x0020000000000000ul) {
176 if ((s64)ckc >= (s64)now)
177 return 0;
178 } else if (ckc >= now) {
173 return 0; 179 return 0;
180 }
174 return ckc_interrupts_enabled(vcpu); 181 return ckc_interrupts_enabled(vcpu);
175} 182}
176 183
@@ -187,12 +194,6 @@ static int cpu_timer_irq_pending(struct kvm_vcpu *vcpu)
187 return kvm_s390_get_cpu_timer(vcpu) >> 63; 194 return kvm_s390_get_cpu_timer(vcpu) >> 63;
188} 195}
189 196
190static inline int is_ioirq(unsigned long irq_type)
191{
192 return ((irq_type >= IRQ_PEND_IO_ISC_7) &&
193 (irq_type <= IRQ_PEND_IO_ISC_0));
194}
195
196static uint64_t isc_to_isc_bits(int isc) 197static uint64_t isc_to_isc_bits(int isc)
197{ 198{
198 return (0x80 >> isc) << 24; 199 return (0x80 >> isc) << 24;
@@ -236,10 +237,15 @@ static inline int kvm_s390_gisa_tac_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gis
236 return test_and_clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa); 237 return test_and_clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa);
237} 238}
238 239
239static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu) 240static inline unsigned long pending_irqs_no_gisa(struct kvm_vcpu *vcpu)
240{ 241{
241 return vcpu->kvm->arch.float_int.pending_irqs | 242 return vcpu->kvm->arch.float_int.pending_irqs |
242 vcpu->arch.local_int.pending_irqs | 243 vcpu->arch.local_int.pending_irqs;
244}
245
246static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu)
247{
248 return pending_irqs_no_gisa(vcpu) |
243 kvm_s390_gisa_get_ipm(vcpu->kvm->arch.gisa) << IRQ_PEND_IO_ISC_7; 249 kvm_s390_gisa_get_ipm(vcpu->kvm->arch.gisa) << IRQ_PEND_IO_ISC_7;
244} 250}
245 251
@@ -337,7 +343,7 @@ static void __reset_intercept_indicators(struct kvm_vcpu *vcpu)
337 343
338static void set_intercept_indicators_io(struct kvm_vcpu *vcpu) 344static void set_intercept_indicators_io(struct kvm_vcpu *vcpu)
339{ 345{
340 if (!(pending_irqs(vcpu) & IRQ_PEND_IO_MASK)) 346 if (!(pending_irqs_no_gisa(vcpu) & IRQ_PEND_IO_MASK))
341 return; 347 return;
342 else if (psw_ioint_disabled(vcpu)) 348 else if (psw_ioint_disabled(vcpu))
343 kvm_s390_set_cpuflags(vcpu, CPUSTAT_IO_INT); 349 kvm_s390_set_cpuflags(vcpu, CPUSTAT_IO_INT);
@@ -1011,24 +1017,6 @@ out:
1011 return rc; 1017 return rc;
1012} 1018}
1013 1019
1014typedef int (*deliver_irq_t)(struct kvm_vcpu *vcpu);
1015
1016static const deliver_irq_t deliver_irq_funcs[] = {
1017 [IRQ_PEND_MCHK_EX] = __deliver_machine_check,
1018 [IRQ_PEND_MCHK_REP] = __deliver_machine_check,
1019 [IRQ_PEND_PROG] = __deliver_prog,
1020 [IRQ_PEND_EXT_EMERGENCY] = __deliver_emergency_signal,
1021 [IRQ_PEND_EXT_EXTERNAL] = __deliver_external_call,
1022 [IRQ_PEND_EXT_CLOCK_COMP] = __deliver_ckc,
1023 [IRQ_PEND_EXT_CPU_TIMER] = __deliver_cpu_timer,
1024 [IRQ_PEND_RESTART] = __deliver_restart,
1025 [IRQ_PEND_SET_PREFIX] = __deliver_set_prefix,
1026 [IRQ_PEND_PFAULT_INIT] = __deliver_pfault_init,
1027 [IRQ_PEND_EXT_SERVICE] = __deliver_service,
1028 [IRQ_PEND_PFAULT_DONE] = __deliver_pfault_done,
1029 [IRQ_PEND_VIRTIO] = __deliver_virtio,
1030};
1031
1032/* Check whether an external call is pending (deliverable or not) */ 1020/* Check whether an external call is pending (deliverable or not) */
1033int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu) 1021int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu)
1034{ 1022{
@@ -1066,13 +1054,19 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
1066 1054
1067static u64 __calculate_sltime(struct kvm_vcpu *vcpu) 1055static u64 __calculate_sltime(struct kvm_vcpu *vcpu)
1068{ 1056{
1069 u64 now, cputm, sltime = 0; 1057 const u64 now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
1058 const u64 ckc = vcpu->arch.sie_block->ckc;
1059 u64 cputm, sltime = 0;
1070 1060
1071 if (ckc_interrupts_enabled(vcpu)) { 1061 if (ckc_interrupts_enabled(vcpu)) {
1072 now = kvm_s390_get_tod_clock_fast(vcpu->kvm); 1062 if (vcpu->arch.sie_block->gcr[0] & 0x0020000000000000ul) {
1073 sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); 1063 if ((s64)now < (s64)ckc)
1074 /* already expired or overflow? */ 1064 sltime = tod_to_ns((s64)ckc - (s64)now);
1075 if (!sltime || vcpu->arch.sie_block->ckc <= now) 1065 } else if (now < ckc) {
1066 sltime = tod_to_ns(ckc - now);
1067 }
1068 /* already expired */
1069 if (!sltime)
1076 return 0; 1070 return 0;
1077 if (cpu_timer_interrupts_enabled(vcpu)) { 1071 if (cpu_timer_interrupts_enabled(vcpu)) {
1078 cputm = kvm_s390_get_cpu_timer(vcpu); 1072 cputm = kvm_s390_get_cpu_timer(vcpu);
@@ -1192,7 +1186,6 @@ void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu)
1192int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu) 1186int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
1193{ 1187{
1194 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; 1188 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
1195 deliver_irq_t func;
1196 int rc = 0; 1189 int rc = 0;
1197 unsigned long irq_type; 1190 unsigned long irq_type;
1198 unsigned long irqs; 1191 unsigned long irqs;
@@ -1212,16 +1205,57 @@ int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
1212 while ((irqs = deliverable_irqs(vcpu)) && !rc) { 1205 while ((irqs = deliverable_irqs(vcpu)) && !rc) {
1213 /* bits are in the reverse order of interrupt priority */ 1206 /* bits are in the reverse order of interrupt priority */
1214 irq_type = find_last_bit(&irqs, IRQ_PEND_COUNT); 1207 irq_type = find_last_bit(&irqs, IRQ_PEND_COUNT);
1215 if (is_ioirq(irq_type)) { 1208 switch (irq_type) {
1209 case IRQ_PEND_IO_ISC_0:
1210 case IRQ_PEND_IO_ISC_1:
1211 case IRQ_PEND_IO_ISC_2:
1212 case IRQ_PEND_IO_ISC_3:
1213 case IRQ_PEND_IO_ISC_4:
1214 case IRQ_PEND_IO_ISC_5:
1215 case IRQ_PEND_IO_ISC_6:
1216 case IRQ_PEND_IO_ISC_7:
1216 rc = __deliver_io(vcpu, irq_type); 1217 rc = __deliver_io(vcpu, irq_type);
1217 } else { 1218 break;
1218 func = deliver_irq_funcs[irq_type]; 1219 case IRQ_PEND_MCHK_EX:
1219 if (!func) { 1220 case IRQ_PEND_MCHK_REP:
1220 WARN_ON_ONCE(func == NULL); 1221 rc = __deliver_machine_check(vcpu);
1221 clear_bit(irq_type, &li->pending_irqs); 1222 break;
1222 continue; 1223 case IRQ_PEND_PROG:
1223 } 1224 rc = __deliver_prog(vcpu);
1224 rc = func(vcpu); 1225 break;
1226 case IRQ_PEND_EXT_EMERGENCY:
1227 rc = __deliver_emergency_signal(vcpu);
1228 break;
1229 case IRQ_PEND_EXT_EXTERNAL:
1230 rc = __deliver_external_call(vcpu);
1231 break;
1232 case IRQ_PEND_EXT_CLOCK_COMP:
1233 rc = __deliver_ckc(vcpu);
1234 break;
1235 case IRQ_PEND_EXT_CPU_TIMER:
1236 rc = __deliver_cpu_timer(vcpu);
1237 break;
1238 case IRQ_PEND_RESTART:
1239 rc = __deliver_restart(vcpu);
1240 break;
1241 case IRQ_PEND_SET_PREFIX:
1242 rc = __deliver_set_prefix(vcpu);
1243 break;
1244 case IRQ_PEND_PFAULT_INIT:
1245 rc = __deliver_pfault_init(vcpu);
1246 break;
1247 case IRQ_PEND_EXT_SERVICE:
1248 rc = __deliver_service(vcpu);
1249 break;
1250 case IRQ_PEND_PFAULT_DONE:
1251 rc = __deliver_pfault_done(vcpu);
1252 break;
1253 case IRQ_PEND_VIRTIO:
1254 rc = __deliver_virtio(vcpu);
1255 break;
1256 default:
1257 WARN_ONCE(1, "Unknown pending irq type %ld", irq_type);
1258 clear_bit(irq_type, &li->pending_irqs);
1225 } 1259 }
1226 } 1260 }
1227 1261
@@ -1701,7 +1735,8 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type)
1701 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_STOP_INT); 1735 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_STOP_INT);
1702 break; 1736 break;
1703 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: 1737 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
1704 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_IO_INT); 1738 if (!(type & KVM_S390_INT_IO_AI_MASK && kvm->arch.gisa))
1739 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_IO_INT);
1705 break; 1740 break;
1706 default: 1741 default:
1707 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_EXT_INT); 1742 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_EXT_INT);
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index ba4c7092335a..339ac0964590 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -86,6 +86,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
86 { "deliver_prefix_signal", VCPU_STAT(deliver_prefix_signal) }, 86 { "deliver_prefix_signal", VCPU_STAT(deliver_prefix_signal) },
87 { "deliver_restart_signal", VCPU_STAT(deliver_restart_signal) }, 87 { "deliver_restart_signal", VCPU_STAT(deliver_restart_signal) },
88 { "deliver_program_interruption", VCPU_STAT(deliver_program_int) }, 88 { "deliver_program_interruption", VCPU_STAT(deliver_program_int) },
89 { "deliver_io_interrupt", VCPU_STAT(deliver_io_int) },
89 { "exit_wait_state", VCPU_STAT(exit_wait_state) }, 90 { "exit_wait_state", VCPU_STAT(exit_wait_state) },
90 { "instruction_epsw", VCPU_STAT(instruction_epsw) }, 91 { "instruction_epsw", VCPU_STAT(instruction_epsw) },
91 { "instruction_gs", VCPU_STAT(instruction_gs) }, 92 { "instruction_gs", VCPU_STAT(instruction_gs) },
@@ -179,6 +180,28 @@ int kvm_arch_hardware_enable(void)
179static void kvm_gmap_notifier(struct gmap *gmap, unsigned long start, 180static void kvm_gmap_notifier(struct gmap *gmap, unsigned long start,
180 unsigned long end); 181 unsigned long end);
181 182
183static void kvm_clock_sync_scb(struct kvm_s390_sie_block *scb, u64 delta)
184{
185 u8 delta_idx = 0;
186
187 /*
188 * The TOD jumps by delta, we have to compensate this by adding
189 * -delta to the epoch.
190 */
191 delta = -delta;
192
193 /* sign-extension - we're adding to signed values below */
194 if ((s64)delta < 0)
195 delta_idx = -1;
196
197 scb->epoch += delta;
198 if (scb->ecd & ECD_MEF) {
199 scb->epdx += delta_idx;
200 if (scb->epoch < delta)
201 scb->epdx += 1;
202 }
203}
204
182/* 205/*
183 * This callback is executed during stop_machine(). All CPUs are therefore 206 * This callback is executed during stop_machine(). All CPUs are therefore
184 * temporarily stopped. In order not to change guest behavior, we have to 207 * temporarily stopped. In order not to change guest behavior, we have to
@@ -194,13 +217,17 @@ static int kvm_clock_sync(struct notifier_block *notifier, unsigned long val,
194 unsigned long long *delta = v; 217 unsigned long long *delta = v;
195 218
196 list_for_each_entry(kvm, &vm_list, vm_list) { 219 list_for_each_entry(kvm, &vm_list, vm_list) {
197 kvm->arch.epoch -= *delta;
198 kvm_for_each_vcpu(i, vcpu, kvm) { 220 kvm_for_each_vcpu(i, vcpu, kvm) {
199 vcpu->arch.sie_block->epoch -= *delta; 221 kvm_clock_sync_scb(vcpu->arch.sie_block, *delta);
222 if (i == 0) {
223 kvm->arch.epoch = vcpu->arch.sie_block->epoch;
224 kvm->arch.epdx = vcpu->arch.sie_block->epdx;
225 }
200 if (vcpu->arch.cputm_enabled) 226 if (vcpu->arch.cputm_enabled)
201 vcpu->arch.cputm_start += *delta; 227 vcpu->arch.cputm_start += *delta;
202 if (vcpu->arch.vsie_block) 228 if (vcpu->arch.vsie_block)
203 vcpu->arch.vsie_block->epoch -= *delta; 229 kvm_clock_sync_scb(vcpu->arch.vsie_block,
230 *delta);
204 } 231 }
205 } 232 }
206 return NOTIFY_OK; 233 return NOTIFY_OK;
@@ -902,12 +929,9 @@ static int kvm_s390_set_tod_ext(struct kvm *kvm, struct kvm_device_attr *attr)
902 if (copy_from_user(&gtod, (void __user *)attr->addr, sizeof(gtod))) 929 if (copy_from_user(&gtod, (void __user *)attr->addr, sizeof(gtod)))
903 return -EFAULT; 930 return -EFAULT;
904 931
905 if (test_kvm_facility(kvm, 139)) 932 if (!test_kvm_facility(kvm, 139) && gtod.epoch_idx)
906 kvm_s390_set_tod_clock_ext(kvm, &gtod);
907 else if (gtod.epoch_idx == 0)
908 kvm_s390_set_tod_clock(kvm, gtod.tod);
909 else
910 return -EINVAL; 933 return -EINVAL;
934 kvm_s390_set_tod_clock(kvm, &gtod);
911 935
912 VM_EVENT(kvm, 3, "SET: TOD extension: 0x%x, TOD base: 0x%llx", 936 VM_EVENT(kvm, 3, "SET: TOD extension: 0x%x, TOD base: 0x%llx",
913 gtod.epoch_idx, gtod.tod); 937 gtod.epoch_idx, gtod.tod);
@@ -932,13 +956,14 @@ static int kvm_s390_set_tod_high(struct kvm *kvm, struct kvm_device_attr *attr)
932 956
933static int kvm_s390_set_tod_low(struct kvm *kvm, struct kvm_device_attr *attr) 957static int kvm_s390_set_tod_low(struct kvm *kvm, struct kvm_device_attr *attr)
934{ 958{
935 u64 gtod; 959 struct kvm_s390_vm_tod_clock gtod = { 0 };
936 960
937 if (copy_from_user(&gtod, (void __user *)attr->addr, sizeof(gtod))) 961 if (copy_from_user(&gtod.tod, (void __user *)attr->addr,
962 sizeof(gtod.tod)))
938 return -EFAULT; 963 return -EFAULT;
939 964
940 kvm_s390_set_tod_clock(kvm, gtod); 965 kvm_s390_set_tod_clock(kvm, &gtod);
941 VM_EVENT(kvm, 3, "SET: TOD base: 0x%llx", gtod); 966 VM_EVENT(kvm, 3, "SET: TOD base: 0x%llx", gtod.tod);
942 return 0; 967 return 0;
943} 968}
944 969
@@ -2122,6 +2147,7 @@ static void sca_add_vcpu(struct kvm_vcpu *vcpu)
2122 /* we still need the basic sca for the ipte control */ 2147 /* we still need the basic sca for the ipte control */
2123 vcpu->arch.sie_block->scaoh = (__u32)(((__u64)sca) >> 32); 2148 vcpu->arch.sie_block->scaoh = (__u32)(((__u64)sca) >> 32);
2124 vcpu->arch.sie_block->scaol = (__u32)(__u64)sca; 2149 vcpu->arch.sie_block->scaol = (__u32)(__u64)sca;
2150 return;
2125 } 2151 }
2126 read_lock(&vcpu->kvm->arch.sca_lock); 2152 read_lock(&vcpu->kvm->arch.sca_lock);
2127 if (vcpu->kvm->arch.use_esca) { 2153 if (vcpu->kvm->arch.use_esca) {
@@ -2389,6 +2415,7 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
2389 mutex_lock(&vcpu->kvm->lock); 2415 mutex_lock(&vcpu->kvm->lock);
2390 preempt_disable(); 2416 preempt_disable();
2391 vcpu->arch.sie_block->epoch = vcpu->kvm->arch.epoch; 2417 vcpu->arch.sie_block->epoch = vcpu->kvm->arch.epoch;
2418 vcpu->arch.sie_block->epdx = vcpu->kvm->arch.epdx;
2392 preempt_enable(); 2419 preempt_enable();
2393 mutex_unlock(&vcpu->kvm->lock); 2420 mutex_unlock(&vcpu->kvm->lock);
2394 if (!kvm_is_ucontrol(vcpu->kvm)) { 2421 if (!kvm_is_ucontrol(vcpu->kvm)) {
@@ -3021,8 +3048,8 @@ retry:
3021 return 0; 3048 return 0;
3022} 3049}
3023 3050
3024void kvm_s390_set_tod_clock_ext(struct kvm *kvm, 3051void kvm_s390_set_tod_clock(struct kvm *kvm,
3025 const struct kvm_s390_vm_tod_clock *gtod) 3052 const struct kvm_s390_vm_tod_clock *gtod)
3026{ 3053{
3027 struct kvm_vcpu *vcpu; 3054 struct kvm_vcpu *vcpu;
3028 struct kvm_s390_tod_clock_ext htod; 3055 struct kvm_s390_tod_clock_ext htod;
@@ -3034,10 +3061,12 @@ void kvm_s390_set_tod_clock_ext(struct kvm *kvm,
3034 get_tod_clock_ext((char *)&htod); 3061 get_tod_clock_ext((char *)&htod);
3035 3062
3036 kvm->arch.epoch = gtod->tod - htod.tod; 3063 kvm->arch.epoch = gtod->tod - htod.tod;
3037 kvm->arch.epdx = gtod->epoch_idx - htod.epoch_idx; 3064 kvm->arch.epdx = 0;
3038 3065 if (test_kvm_facility(kvm, 139)) {
3039 if (kvm->arch.epoch > gtod->tod) 3066 kvm->arch.epdx = gtod->epoch_idx - htod.epoch_idx;
3040 kvm->arch.epdx -= 1; 3067 if (kvm->arch.epoch > gtod->tod)
3068 kvm->arch.epdx -= 1;
3069 }
3041 3070
3042 kvm_s390_vcpu_block_all(kvm); 3071 kvm_s390_vcpu_block_all(kvm);
3043 kvm_for_each_vcpu(i, vcpu, kvm) { 3072 kvm_for_each_vcpu(i, vcpu, kvm) {
@@ -3050,22 +3079,6 @@ void kvm_s390_set_tod_clock_ext(struct kvm *kvm,
3050 mutex_unlock(&kvm->lock); 3079 mutex_unlock(&kvm->lock);
3051} 3080}
3052 3081
3053void kvm_s390_set_tod_clock(struct kvm *kvm, u64 tod)
3054{
3055 struct kvm_vcpu *vcpu;
3056 int i;
3057
3058 mutex_lock(&kvm->lock);
3059 preempt_disable();
3060 kvm->arch.epoch = tod - get_tod_clock();
3061 kvm_s390_vcpu_block_all(kvm);
3062 kvm_for_each_vcpu(i, vcpu, kvm)
3063 vcpu->arch.sie_block->epoch = kvm->arch.epoch;
3064 kvm_s390_vcpu_unblock_all(kvm);
3065 preempt_enable();
3066 mutex_unlock(&kvm->lock);
3067}
3068
3069/** 3082/**
3070 * kvm_arch_fault_in_page - fault-in guest page if necessary 3083 * kvm_arch_fault_in_page - fault-in guest page if necessary
3071 * @vcpu: The corresponding virtual cpu 3084 * @vcpu: The corresponding virtual cpu
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index bd31b37b0e6f..f55ac0ef99ea 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -19,8 +19,6 @@
19#include <asm/processor.h> 19#include <asm/processor.h>
20#include <asm/sclp.h> 20#include <asm/sclp.h>
21 21
22typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu);
23
24/* Transactional Memory Execution related macros */ 22/* Transactional Memory Execution related macros */
25#define IS_TE_ENABLED(vcpu) ((vcpu->arch.sie_block->ecb & ECB_TE)) 23#define IS_TE_ENABLED(vcpu) ((vcpu->arch.sie_block->ecb & ECB_TE))
26#define TDB_FORMAT1 1 24#define TDB_FORMAT1 1
@@ -283,9 +281,8 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
283int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu); 281int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
284 282
285/* implemented in kvm-s390.c */ 283/* implemented in kvm-s390.c */
286void kvm_s390_set_tod_clock_ext(struct kvm *kvm, 284void kvm_s390_set_tod_clock(struct kvm *kvm,
287 const struct kvm_s390_vm_tod_clock *gtod); 285 const struct kvm_s390_vm_tod_clock *gtod);
288void kvm_s390_set_tod_clock(struct kvm *kvm, u64 tod);
289long kvm_arch_fault_in_page(struct kvm_vcpu *vcpu, gpa_t gpa, int writable); 286long kvm_arch_fault_in_page(struct kvm_vcpu *vcpu, gpa_t gpa, int writable);
290int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr); 287int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr);
291int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr); 288int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr);
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index c4c4e157c036..f0b4185158af 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -85,9 +85,10 @@ int kvm_s390_handle_e3(struct kvm_vcpu *vcpu)
85/* Handle SCK (SET CLOCK) interception */ 85/* Handle SCK (SET CLOCK) interception */
86static int handle_set_clock(struct kvm_vcpu *vcpu) 86static int handle_set_clock(struct kvm_vcpu *vcpu)
87{ 87{
88 struct kvm_s390_vm_tod_clock gtod = { 0 };
88 int rc; 89 int rc;
89 u8 ar; 90 u8 ar;
90 u64 op2, val; 91 u64 op2;
91 92
92 vcpu->stat.instruction_sck++; 93 vcpu->stat.instruction_sck++;
93 94
@@ -97,12 +98,12 @@ static int handle_set_clock(struct kvm_vcpu *vcpu)
97 op2 = kvm_s390_get_base_disp_s(vcpu, &ar); 98 op2 = kvm_s390_get_base_disp_s(vcpu, &ar);
98 if (op2 & 7) /* Operand must be on a doubleword boundary */ 99 if (op2 & 7) /* Operand must be on a doubleword boundary */
99 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); 100 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
100 rc = read_guest(vcpu, op2, ar, &val, sizeof(val)); 101 rc = read_guest(vcpu, op2, ar, &gtod.tod, sizeof(gtod.tod));
101 if (rc) 102 if (rc)
102 return kvm_s390_inject_prog_cond(vcpu, rc); 103 return kvm_s390_inject_prog_cond(vcpu, rc);
103 104
104 VCPU_EVENT(vcpu, 3, "SCK: setting guest TOD to 0x%llx", val); 105 VCPU_EVENT(vcpu, 3, "SCK: setting guest TOD to 0x%llx", gtod.tod);
105 kvm_s390_set_tod_clock(vcpu->kvm, val); 106 kvm_s390_set_tod_clock(vcpu->kvm, &gtod);
106 107
107 kvm_s390_set_psw_cc(vcpu, 0); 108 kvm_s390_set_psw_cc(vcpu, 0);
108 return 0; 109 return 0;
@@ -795,55 +796,60 @@ out:
795 return rc; 796 return rc;
796} 797}
797 798
798static const intercept_handler_t b2_handlers[256] = {
799 [0x02] = handle_stidp,
800 [0x04] = handle_set_clock,
801 [0x10] = handle_set_prefix,
802 [0x11] = handle_store_prefix,
803 [0x12] = handle_store_cpu_address,
804 [0x14] = kvm_s390_handle_vsie,
805 [0x21] = handle_ipte_interlock,
806 [0x29] = handle_iske,
807 [0x2a] = handle_rrbe,
808 [0x2b] = handle_sske,
809 [0x2c] = handle_test_block,
810 [0x30] = handle_io_inst,
811 [0x31] = handle_io_inst,
812 [0x32] = handle_io_inst,
813 [0x33] = handle_io_inst,
814 [0x34] = handle_io_inst,
815 [0x35] = handle_io_inst,
816 [0x36] = handle_io_inst,
817 [0x37] = handle_io_inst,
818 [0x38] = handle_io_inst,
819 [0x39] = handle_io_inst,
820 [0x3a] = handle_io_inst,
821 [0x3b] = handle_io_inst,
822 [0x3c] = handle_io_inst,
823 [0x50] = handle_ipte_interlock,
824 [0x56] = handle_sthyi,
825 [0x5f] = handle_io_inst,
826 [0x74] = handle_io_inst,
827 [0x76] = handle_io_inst,
828 [0x7d] = handle_stsi,
829 [0xb1] = handle_stfl,
830 [0xb2] = handle_lpswe,
831};
832
833int kvm_s390_handle_b2(struct kvm_vcpu *vcpu) 799int kvm_s390_handle_b2(struct kvm_vcpu *vcpu)
834{ 800{
835 intercept_handler_t handler; 801 switch (vcpu->arch.sie_block->ipa & 0x00ff) {
836 802 case 0x02:
837 /* 803 return handle_stidp(vcpu);
838 * A lot of B2 instructions are priviledged. Here we check for 804 case 0x04:
839 * the privileged ones, that we can handle in the kernel. 805 return handle_set_clock(vcpu);
840 * Anything else goes to userspace. 806 case 0x10:
841 */ 807 return handle_set_prefix(vcpu);
842 handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; 808 case 0x11:
843 if (handler) 809 return handle_store_prefix(vcpu);
844 return handler(vcpu); 810 case 0x12:
845 811 return handle_store_cpu_address(vcpu);
846 return -EOPNOTSUPP; 812 case 0x14:
813 return kvm_s390_handle_vsie(vcpu);
814 case 0x21:
815 case 0x50:
816 return handle_ipte_interlock(vcpu);
817 case 0x29:
818 return handle_iske(vcpu);
819 case 0x2a:
820 return handle_rrbe(vcpu);
821 case 0x2b:
822 return handle_sske(vcpu);
823 case 0x2c:
824 return handle_test_block(vcpu);
825 case 0x30:
826 case 0x31:
827 case 0x32:
828 case 0x33:
829 case 0x34:
830 case 0x35:
831 case 0x36:
832 case 0x37:
833 case 0x38:
834 case 0x39:
835 case 0x3a:
836 case 0x3b:
837 case 0x3c:
838 case 0x5f:
839 case 0x74:
840 case 0x76:
841 return handle_io_inst(vcpu);
842 case 0x56:
843 return handle_sthyi(vcpu);
844 case 0x7d:
845 return handle_stsi(vcpu);
846 case 0xb1:
847 return handle_stfl(vcpu);
848 case 0xb2:
849 return handle_lpswe(vcpu);
850 default:
851 return -EOPNOTSUPP;
852 }
847} 853}
848 854
849static int handle_epsw(struct kvm_vcpu *vcpu) 855static int handle_epsw(struct kvm_vcpu *vcpu)
@@ -1105,25 +1111,22 @@ static int handle_essa(struct kvm_vcpu *vcpu)
1105 return 0; 1111 return 0;
1106} 1112}
1107 1113
1108static const intercept_handler_t b9_handlers[256] = {
1109 [0x8a] = handle_ipte_interlock,
1110 [0x8d] = handle_epsw,
1111 [0x8e] = handle_ipte_interlock,
1112 [0x8f] = handle_ipte_interlock,
1113 [0xab] = handle_essa,
1114 [0xaf] = handle_pfmf,
1115};
1116
1117int kvm_s390_handle_b9(struct kvm_vcpu *vcpu) 1114int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
1118{ 1115{
1119 intercept_handler_t handler; 1116 switch (vcpu->arch.sie_block->ipa & 0x00ff) {
1120 1117 case 0x8a:
1121 /* This is handled just as for the B2 instructions. */ 1118 case 0x8e:
1122 handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; 1119 case 0x8f:
1123 if (handler) 1120 return handle_ipte_interlock(vcpu);
1124 return handler(vcpu); 1121 case 0x8d:
1125 1122 return handle_epsw(vcpu);
1126 return -EOPNOTSUPP; 1123 case 0xab:
1124 return handle_essa(vcpu);
1125 case 0xaf:
1126 return handle_pfmf(vcpu);
1127 default:
1128 return -EOPNOTSUPP;
1129 }
1127} 1130}
1128 1131
1129int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu) 1132int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu)
@@ -1271,22 +1274,20 @@ static int handle_stctg(struct kvm_vcpu *vcpu)
1271 return rc ? kvm_s390_inject_prog_cond(vcpu, rc) : 0; 1274 return rc ? kvm_s390_inject_prog_cond(vcpu, rc) : 0;
1272} 1275}
1273 1276
1274static const intercept_handler_t eb_handlers[256] = {
1275 [0x2f] = handle_lctlg,
1276 [0x25] = handle_stctg,
1277 [0x60] = handle_ri,
1278 [0x61] = handle_ri,
1279 [0x62] = handle_ri,
1280};
1281
1282int kvm_s390_handle_eb(struct kvm_vcpu *vcpu) 1277int kvm_s390_handle_eb(struct kvm_vcpu *vcpu)
1283{ 1278{
1284 intercept_handler_t handler; 1279 switch (vcpu->arch.sie_block->ipb & 0x000000ff) {
1285 1280 case 0x25:
1286 handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff]; 1281 return handle_stctg(vcpu);
1287 if (handler) 1282 case 0x2f:
1288 return handler(vcpu); 1283 return handle_lctlg(vcpu);
1289 return -EOPNOTSUPP; 1284 case 0x60:
1285 case 0x61:
1286 case 0x62:
1287 return handle_ri(vcpu);
1288 default:
1289 return -EOPNOTSUPP;
1290 }
1290} 1291}
1291 1292
1292static int handle_tprot(struct kvm_vcpu *vcpu) 1293static int handle_tprot(struct kvm_vcpu *vcpu)
@@ -1346,10 +1347,12 @@ out_unlock:
1346 1347
1347int kvm_s390_handle_e5(struct kvm_vcpu *vcpu) 1348int kvm_s390_handle_e5(struct kvm_vcpu *vcpu)
1348{ 1349{
1349 /* For e5xx... instructions we only handle TPROT */ 1350 switch (vcpu->arch.sie_block->ipa & 0x00ff) {
1350 if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01) 1351 case 0x01:
1351 return handle_tprot(vcpu); 1352 return handle_tprot(vcpu);
1352 return -EOPNOTSUPP; 1353 default:
1354 return -EOPNOTSUPP;
1355 }
1353} 1356}
1354 1357
1355static int handle_sckpf(struct kvm_vcpu *vcpu) 1358static int handle_sckpf(struct kvm_vcpu *vcpu)
@@ -1380,17 +1383,14 @@ static int handle_ptff(struct kvm_vcpu *vcpu)
1380 return 0; 1383 return 0;
1381} 1384}
1382 1385
1383static const intercept_handler_t x01_handlers[256] = {
1384 [0x04] = handle_ptff,
1385 [0x07] = handle_sckpf,
1386};
1387
1388int kvm_s390_handle_01(struct kvm_vcpu *vcpu) 1386int kvm_s390_handle_01(struct kvm_vcpu *vcpu)
1389{ 1387{
1390 intercept_handler_t handler; 1388 switch (vcpu->arch.sie_block->ipa & 0x00ff) {
1391 1389 case 0x04:
1392 handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; 1390 return handle_ptff(vcpu);
1393 if (handler) 1391 case 0x07:
1394 return handler(vcpu); 1392 return handle_sckpf(vcpu);
1395 return -EOPNOTSUPP; 1393 default:
1394 return -EOPNOTSUPP;
1395 }
1396} 1396}
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index ec772700ff96..8961e3970901 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -821,6 +821,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
821{ 821{
822 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; 822 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
823 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; 823 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
824 int guest_bp_isolation;
824 int rc; 825 int rc;
825 826
826 handle_last_fault(vcpu, vsie_page); 827 handle_last_fault(vcpu, vsie_page);
@@ -831,6 +832,20 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
831 s390_handle_mcck(); 832 s390_handle_mcck();
832 833
833 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); 834 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
835
836 /* save current guest state of bp isolation override */
837 guest_bp_isolation = test_thread_flag(TIF_ISOLATE_BP_GUEST);
838
839 /*
840 * The guest is running with BPBC, so we have to force it on for our
841 * nested guest. This is done by enabling BPBC globally, so the BPBC
842 * control in the SCB (which the nested guest can modify) is simply
843 * ignored.
844 */
845 if (test_kvm_facility(vcpu->kvm, 82) &&
846 vcpu->arch.sie_block->fpf & FPF_BPBC)
847 set_thread_flag(TIF_ISOLATE_BP_GUEST);
848
834 local_irq_disable(); 849 local_irq_disable();
835 guest_enter_irqoff(); 850 guest_enter_irqoff();
836 local_irq_enable(); 851 local_irq_enable();
@@ -840,6 +855,11 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
840 local_irq_disable(); 855 local_irq_disable();
841 guest_exit_irqoff(); 856 guest_exit_irqoff();
842 local_irq_enable(); 857 local_irq_enable();
858
859 /* restore guest state for bp isolation override */
860 if (!guest_bp_isolation)
861 clear_thread_flag(TIF_ISOLATE_BP_GUEST);
862
843 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 863 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
844 864
845 if (rc == -EINTR) { 865 if (rc == -EINTR) {
diff --git a/arch/sh/boot/dts/Makefile b/arch/sh/boot/dts/Makefile
index 715def00a436..01d0f7fb14cc 100644
--- a/arch/sh/boot/dts/Makefile
+++ b/arch/sh/boot/dts/Makefile
@@ -1 +1,3 @@
1obj-$(CONFIG_USE_BUILTIN_DTB) += $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_SOURCE)).dtb.o 1ifneq ($(CONFIG_BUILTIN_DTB_SOURCE),"")
2obj-y += $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_SOURCE)).dtb.o
3endif
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 6bf594ace663..8767e45f1b2b 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -430,6 +430,8 @@ config SPARC_LEON
430 depends on SPARC32 430 depends on SPARC32
431 select USB_EHCI_BIG_ENDIAN_MMIO 431 select USB_EHCI_BIG_ENDIAN_MMIO
432 select USB_EHCI_BIG_ENDIAN_DESC 432 select USB_EHCI_BIG_ENDIAN_DESC
433 select USB_UHCI_BIG_ENDIAN_MMIO
434 select USB_UHCI_BIG_ENDIAN_DESC
433 ---help--- 435 ---help---
434 If you say Y here if you are running on a SPARC-LEON processor. 436 If you say Y here if you are running on a SPARC-LEON processor.
435 The LEON processor is a synthesizable VHDL model of the 437 The LEON processor is a synthesizable VHDL model of the
diff --git a/arch/sparc/include/asm/bug.h b/arch/sparc/include/asm/bug.h
index 6f17528356b2..ea53e418f6c0 100644
--- a/arch/sparc/include/asm/bug.h
+++ b/arch/sparc/include/asm/bug.h
@@ -9,10 +9,14 @@
9void do_BUG(const char *file, int line); 9void do_BUG(const char *file, int line);
10#define BUG() do { \ 10#define BUG() do { \
11 do_BUG(__FILE__, __LINE__); \ 11 do_BUG(__FILE__, __LINE__); \
12 barrier_before_unreachable(); \
12 __builtin_trap(); \ 13 __builtin_trap(); \
13} while (0) 14} while (0)
14#else 15#else
15#define BUG() __builtin_trap() 16#define BUG() do { \
17 barrier_before_unreachable(); \
18 __builtin_trap(); \
19} while (0)
16#endif 20#endif
17 21
18#define HAVE_ARCH_BUG 22#define HAVE_ARCH_BUG
diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
index 847ddffbf38a..b5cfab711651 100644
--- a/arch/sparc/mm/tlb.c
+++ b/arch/sparc/mm/tlb.c
@@ -163,13 +163,10 @@ static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
163 pte_unmap(pte); 163 pte_unmap(pte);
164} 164}
165 165
166void set_pmd_at(struct mm_struct *mm, unsigned long addr,
167 pmd_t *pmdp, pmd_t pmd)
168{
169 pmd_t orig = *pmdp;
170
171 *pmdp = pmd;
172 166
167static void __set_pmd_acct(struct mm_struct *mm, unsigned long addr,
168 pmd_t orig, pmd_t pmd)
169{
173 if (mm == &init_mm) 170 if (mm == &init_mm)
174 return; 171 return;
175 172
@@ -219,6 +216,15 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,
219 } 216 }
220} 217}
221 218
219void set_pmd_at(struct mm_struct *mm, unsigned long addr,
220 pmd_t *pmdp, pmd_t pmd)
221{
222 pmd_t orig = *pmdp;
223
224 *pmdp = pmd;
225 __set_pmd_acct(mm, addr, orig, pmd);
226}
227
222static inline pmd_t pmdp_establish(struct vm_area_struct *vma, 228static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
223 unsigned long address, pmd_t *pmdp, pmd_t pmd) 229 unsigned long address, pmd_t *pmdp, pmd_t pmd)
224{ 230{
@@ -227,6 +233,7 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
227 do { 233 do {
228 old = *pmdp; 234 old = *pmdp;
229 } while (cmpxchg64(&pmdp->pmd, old.pmd, pmd.pmd) != old.pmd); 235 } while (cmpxchg64(&pmdp->pmd, old.pmd, pmd.pmd) != old.pmd);
236 __set_pmd_acct(vma->vm_mm, address, old, pmd);
230 237
231 return old; 238 return old;
232} 239}
diff --git a/arch/x86/.gitignore b/arch/x86/.gitignore
index aff152c87cf4..5a82bac5e0bc 100644
--- a/arch/x86/.gitignore
+++ b/arch/x86/.gitignore
@@ -1,6 +1,7 @@
1boot/compressed/vmlinux 1boot/compressed/vmlinux
2tools/test_get_len 2tools/test_get_len
3tools/insn_sanity 3tools/insn_sanity
4tools/insn_decoder_test
4purgatory/kexec-purgatory.c 5purgatory/kexec-purgatory.c
5purgatory/purgatory.ro 6purgatory/purgatory.ro
6 7
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 63bf349b2b24..0fa71a78ec99 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -423,12 +423,6 @@ config X86_MPPARSE
423 For old smp systems that do not have proper acpi support. Newer systems 423 For old smp systems that do not have proper acpi support. Newer systems
424 (esp with 64bit cpus) with acpi support, MADT and DSDT will override it 424 (esp with 64bit cpus) with acpi support, MADT and DSDT will override it
425 425
426config X86_BIGSMP
427 bool "Support for big SMP systems with more than 8 CPUs"
428 depends on X86_32 && SMP
429 ---help---
430 This option is needed for the systems that have more than 8 CPUs
431
432config GOLDFISH 426config GOLDFISH
433 def_bool y 427 def_bool y
434 depends on X86_GOLDFISH 428 depends on X86_GOLDFISH
@@ -436,6 +430,7 @@ config GOLDFISH
436config RETPOLINE 430config RETPOLINE
437 bool "Avoid speculative indirect branches in kernel" 431 bool "Avoid speculative indirect branches in kernel"
438 default y 432 default y
433 select STACK_VALIDATION if HAVE_STACK_VALIDATION
439 help 434 help
440 Compile kernel with the retpoline compiler options to guard against 435 Compile kernel with the retpoline compiler options to guard against
441 kernel-to-user data leaks by avoiding speculative indirect 436 kernel-to-user data leaks by avoiding speculative indirect
@@ -460,6 +455,12 @@ config INTEL_RDT
460 Say N if unsure. 455 Say N if unsure.
461 456
462if X86_32 457if X86_32
458config X86_BIGSMP
459 bool "Support for big SMP systems with more than 8 CPUs"
460 depends on SMP
461 ---help---
462 This option is needed for the systems that have more than 8 CPUs
463
463config X86_EXTENDED_PLATFORM 464config X86_EXTENDED_PLATFORM
464 bool "Support for extended (non-PC) x86 platforms" 465 bool "Support for extended (non-PC) x86 platforms"
465 default y 466 default y
@@ -949,25 +950,66 @@ config MAXSMP
949 Enable maximum number of CPUS and NUMA Nodes for this architecture. 950 Enable maximum number of CPUS and NUMA Nodes for this architecture.
950 If unsure, say N. 951 If unsure, say N.
951 952
953#
954# The maximum number of CPUs supported:
955#
956# The main config value is NR_CPUS, which defaults to NR_CPUS_DEFAULT,
957# and which can be configured interactively in the
958# [NR_CPUS_RANGE_BEGIN ... NR_CPUS_RANGE_END] range.
959#
960# The ranges are different on 32-bit and 64-bit kernels, depending on
961# hardware capabilities and scalability features of the kernel.
962#
963# ( If MAXSMP is enabled we just use the highest possible value and disable
964# interactive configuration. )
965#
966
967config NR_CPUS_RANGE_BEGIN
968 int
969 default NR_CPUS_RANGE_END if MAXSMP
970 default 1 if !SMP
971 default 2
972
973config NR_CPUS_RANGE_END
974 int
975 depends on X86_32
976 default 64 if SMP && X86_BIGSMP
977 default 8 if SMP && !X86_BIGSMP
978 default 1 if !SMP
979
980config NR_CPUS_RANGE_END
981 int
982 depends on X86_64
983 default 8192 if SMP && ( MAXSMP || CPUMASK_OFFSTACK)
984 default 512 if SMP && (!MAXSMP && !CPUMASK_OFFSTACK)
985 default 1 if !SMP
986
987config NR_CPUS_DEFAULT
988 int
989 depends on X86_32
990 default 32 if X86_BIGSMP
991 default 8 if SMP
992 default 1 if !SMP
993
994config NR_CPUS_DEFAULT
995 int
996 depends on X86_64
997 default 8192 if MAXSMP
998 default 64 if SMP
999 default 1 if !SMP
1000
952config NR_CPUS 1001config NR_CPUS
953 int "Maximum number of CPUs" if SMP && !MAXSMP 1002 int "Maximum number of CPUs" if SMP && !MAXSMP
954 range 2 8 if SMP && X86_32 && !X86_BIGSMP 1003 range NR_CPUS_RANGE_BEGIN NR_CPUS_RANGE_END
955 range 2 64 if SMP && X86_32 && X86_BIGSMP 1004 default NR_CPUS_DEFAULT
956 range 2 512 if SMP && !MAXSMP && !CPUMASK_OFFSTACK && X86_64
957 range 2 8192 if SMP && !MAXSMP && CPUMASK_OFFSTACK && X86_64
958 default "1" if !SMP
959 default "8192" if MAXSMP
960 default "32" if SMP && X86_BIGSMP
961 default "8" if SMP && X86_32
962 default "64" if SMP
963 ---help--- 1005 ---help---
964 This allows you to specify the maximum number of CPUs which this 1006 This allows you to specify the maximum number of CPUs which this
965 kernel will support. If CPUMASK_OFFSTACK is enabled, the maximum 1007 kernel will support. If CPUMASK_OFFSTACK is enabled, the maximum
966 supported value is 8192, otherwise the maximum value is 512. The 1008 supported value is 8192, otherwise the maximum value is 512. The
967 minimum value which makes sense is 2. 1009 minimum value which makes sense is 2.
968 1010
969 This is purely to save memory - each supported CPU adds 1011 This is purely to save memory: each supported CPU adds about 8KB
970 approximately eight kilobytes to the kernel image. 1012 to the kernel image.
971 1013
972config SCHED_SMT 1014config SCHED_SMT
973 bool "SMT (Hyperthreading) scheduler support" 1015 bool "SMT (Hyperthreading) scheduler support"
@@ -1363,7 +1405,7 @@ config HIGHMEM4G
1363 1405
1364config HIGHMEM64G 1406config HIGHMEM64G
1365 bool "64GB" 1407 bool "64GB"
1366 depends on !M486 1408 depends on !M486 && !M586 && !M586TSC && !M586MMX && !MGEODE_LX && !MGEODEGX1 && !MCYRIXIII && !MELAN && !MWINCHIPC6 && !WINCHIP3D && !MK6
1367 select X86_PAE 1409 select X86_PAE
1368 ---help--- 1410 ---help---
1369 Select this if you have a 32-bit processor and more than 4 1411 Select this if you have a 32-bit processor and more than 4
@@ -2265,7 +2307,7 @@ choice
2265 it can be used to assist security vulnerability exploitation. 2307 it can be used to assist security vulnerability exploitation.
2266 2308
2267 This setting can be changed at boot time via the kernel command 2309 This setting can be changed at boot time via the kernel command
2268 line parameter vsyscall=[native|emulate|none]. 2310 line parameter vsyscall=[emulate|none].
2269 2311
2270 On a system with recent enough glibc (2.14 or newer) and no 2312 On a system with recent enough glibc (2.14 or newer) and no
2271 static binaries, you can say None without a performance penalty 2313 static binaries, you can say None without a performance penalty
@@ -2273,15 +2315,6 @@ choice
2273 2315
2274 If unsure, select "Emulate". 2316 If unsure, select "Emulate".
2275 2317
2276 config LEGACY_VSYSCALL_NATIVE
2277 bool "Native"
2278 help
2279 Actual executable code is located in the fixed vsyscall
2280 address mapping, implementing time() efficiently. Since
2281 this makes the mapping executable, it can be used during
2282 security vulnerability exploitation (traditionally as
2283 ROP gadgets). This configuration is not recommended.
2284
2285 config LEGACY_VSYSCALL_EMULATE 2318 config LEGACY_VSYSCALL_EMULATE
2286 bool "Emulate" 2319 bool "Emulate"
2287 help 2320 help
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index 65a9a4716e34..638411f22267 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -315,19 +315,6 @@ config X86_L1_CACHE_SHIFT
315 default "4" if MELAN || M486 || MGEODEGX1 315 default "4" if MELAN || M486 || MGEODEGX1
316 default "5" if MWINCHIP3D || MWINCHIPC6 || MCRUSOE || MEFFICEON || MCYRIXIII || MK6 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || MVIAC3_2 || MGEODE_LX 316 default "5" if MWINCHIP3D || MWINCHIPC6 || MCRUSOE || MEFFICEON || MCYRIXIII || MK6 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || MVIAC3_2 || MGEODE_LX
317 317
318config X86_PPRO_FENCE
319 bool "PentiumPro memory ordering errata workaround"
320 depends on M686 || M586MMX || M586TSC || M586 || M486 || MGEODEGX1
321 ---help---
322 Old PentiumPro multiprocessor systems had errata that could cause
323 memory operations to violate the x86 ordering standard in rare cases.
324 Enabling this option will attempt to work around some (but not all)
325 occurrences of this problem, at the cost of much heavier spinlock and
326 memory barrier operations.
327
328 If unsure, say n here. Even distro kernels should think twice before
329 enabling this: there are few systems, and an unlikely bug.
330
331config X86_F00F_BUG 318config X86_F00F_BUG
332 def_bool y 319 def_bool y
333 depends on M586MMX || M586TSC || M586 || M486 320 depends on M586MMX || M586TSC || M586 || M486
@@ -374,7 +361,7 @@ config X86_TSC
374 361
375config X86_CMPXCHG64 362config X86_CMPXCHG64
376 def_bool y 363 def_bool y
377 depends on X86_PAE || X86_64 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MATOM 364 depends on X86_PAE || X86_64 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || M586TSC || M586MMX || MATOM || MGEODE_LX || MGEODEGX1 || MK6 || MK7 || MK8
378 365
379# this should be set for all -march=.. options where the compiler 366# this should be set for all -march=.. options where the compiler
380# generates cmov. 367# generates cmov.
@@ -385,7 +372,7 @@ config X86_CMOV
385config X86_MINIMUM_CPU_FAMILY 372config X86_MINIMUM_CPU_FAMILY
386 int 373 int
387 default "64" if X86_64 374 default "64" if X86_64
388 default "6" if X86_32 && X86_P6_NOP 375 default "6" if X86_32 && (MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MEFFICEON || MATOM || MCRUSOE || MCORE2 || MK7 || MK8)
389 default "5" if X86_32 && X86_CMPXCHG64 376 default "5" if X86_32 && X86_CMPXCHG64
390 default "4" 377 default "4"
391 378
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index fad55160dcb9..1c4d012550ec 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -223,6 +223,15 @@ KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr)
223 223
224LDFLAGS := -m elf_$(UTS_MACHINE) 224LDFLAGS := -m elf_$(UTS_MACHINE)
225 225
226#
227# The 64-bit kernel must be aligned to 2MB. Pass -z max-page-size=0x200000 to
228# the linker to force 2MB page size regardless of the default page size used
229# by the linker.
230#
231ifdef CONFIG_X86_64
232LDFLAGS += $(call ld-option, -z max-page-size=0x200000)
233endif
234
226# Speed up the build 235# Speed up the build
227KBUILD_CFLAGS += -pipe 236KBUILD_CFLAGS += -pipe
228# Workaround for a gcc prelease that unfortunately was shipped in a suse release 237# Workaround for a gcc prelease that unfortunately was shipped in a suse release
@@ -232,10 +241,9 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
232 241
233# Avoid indirect branches in kernel to deal with Spectre 242# Avoid indirect branches in kernel to deal with Spectre
234ifdef CONFIG_RETPOLINE 243ifdef CONFIG_RETPOLINE
235 RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) 244ifneq ($(RETPOLINE_CFLAGS),)
236 ifneq ($(RETPOLINE_CFLAGS),) 245 KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE
237 KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE 246endif
238 endif
239endif 247endif
240 248
241archscripts: scripts_basic 249archscripts: scripts_basic
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 353e20c3f114..886a9115af62 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -439,7 +439,7 @@ setup_uga32(void **uga_handle, unsigned long size, u32 *width, u32 *height)
439 struct efi_uga_draw_protocol *uga = NULL, *first_uga; 439 struct efi_uga_draw_protocol *uga = NULL, *first_uga;
440 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; 440 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
441 unsigned long nr_ugas; 441 unsigned long nr_ugas;
442 u32 *handles = (u32 *)uga_handle;; 442 u32 *handles = (u32 *)uga_handle;
443 efi_status_t status = EFI_INVALID_PARAMETER; 443 efi_status_t status = EFI_INVALID_PARAMETER;
444 int i; 444 int i;
445 445
@@ -484,7 +484,7 @@ setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height)
484 struct efi_uga_draw_protocol *uga = NULL, *first_uga; 484 struct efi_uga_draw_protocol *uga = NULL, *first_uga;
485 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; 485 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
486 unsigned long nr_ugas; 486 unsigned long nr_ugas;
487 u64 *handles = (u64 *)uga_handle;; 487 u64 *handles = (u64 *)uga_handle;
488 efi_status_t status = EFI_INVALID_PARAMETER; 488 efi_status_t status = EFI_INVALID_PARAMETER;
489 int i; 489 int i;
490 490
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 98761a1576ce..252fee320816 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -309,6 +309,10 @@ static void parse_elf(void *output)
309 309
310 switch (phdr->p_type) { 310 switch (phdr->p_type) {
311 case PT_LOAD: 311 case PT_LOAD:
312#ifdef CONFIG_X86_64
313 if ((phdr->p_align % 0x200000) != 0)
314 error("Alignment of LOAD segment isn't multiple of 2MB");
315#endif
312#ifdef CONFIG_RELOCATABLE 316#ifdef CONFIG_RELOCATABLE
313 dest = output; 317 dest = output;
314 dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR); 318 dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
diff --git a/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c b/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c
index 36870b26067a..d08805032f01 100644
--- a/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c
+++ b/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c
@@ -57,10 +57,12 @@ void sha512_mb_mgr_init_avx2(struct sha512_mb_mgr *state)
57{ 57{
58 unsigned int j; 58 unsigned int j;
59 59
60 state->lens[0] = 0; 60 /* initially all lanes are unused */
61 state->lens[1] = 1; 61 state->lens[0] = 0xFFFFFFFF00000000;
62 state->lens[2] = 2; 62 state->lens[1] = 0xFFFFFFFF00000001;
63 state->lens[3] = 3; 63 state->lens[2] = 0xFFFFFFFF00000002;
64 state->lens[3] = 0xFFFFFFFF00000003;
65
64 state->unused_lanes = 0xFF03020100; 66 state->unused_lanes = 0xFF03020100;
65 for (j = 0; j < 4; j++) 67 for (j = 0; j < 4; j++)
66 state->ldata[j].job_in_lane = NULL; 68 state->ldata[j].job_in_lane = NULL;
diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index 3f48f695d5e6..be63330c5511 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -97,80 +97,78 @@ For 32-bit we have the following conventions - kernel is built with
97 97
98#define SIZEOF_PTREGS 21*8 98#define SIZEOF_PTREGS 21*8
99 99
100 .macro ALLOC_PT_GPREGS_ON_STACK 100.macro PUSH_AND_CLEAR_REGS rdx=%rdx rax=%rax save_ret=0
101 addq $-(15*8), %rsp 101 /*
102 .endm 102 * Push registers and sanitize registers of values that a
103 103 * speculation attack might otherwise want to exploit. The
104 .macro SAVE_C_REGS_HELPER offset=0 rax=1 rcx=1 r8910=1 r11=1 104 * lower registers are likely clobbered well before they
105 .if \r11 105 * could be put to use in a speculative execution gadget.
106 movq %r11, 6*8+\offset(%rsp) 106 * Interleave XOR with PUSH for better uop scheduling:
107 .endif 107 */
108 .if \r8910 108 .if \save_ret
109 movq %r10, 7*8+\offset(%rsp) 109 pushq %rsi /* pt_regs->si */
110 movq %r9, 8*8+\offset(%rsp) 110 movq 8(%rsp), %rsi /* temporarily store the return address in %rsi */
111 movq %r8, 9*8+\offset(%rsp) 111 movq %rdi, 8(%rsp) /* pt_regs->di (overwriting original return address) */
112 .endif 112 .else
113 .if \rax 113 pushq %rdi /* pt_regs->di */
114 movq %rax, 10*8+\offset(%rsp) 114 pushq %rsi /* pt_regs->si */
115 .endif 115 .endif
116 .if \rcx 116 pushq \rdx /* pt_regs->dx */
117 movq %rcx, 11*8+\offset(%rsp) 117 pushq %rcx /* pt_regs->cx */
118 pushq \rax /* pt_regs->ax */
119 pushq %r8 /* pt_regs->r8 */
120 xorl %r8d, %r8d /* nospec r8 */
121 pushq %r9 /* pt_regs->r9 */
122 xorl %r9d, %r9d /* nospec r9 */
123 pushq %r10 /* pt_regs->r10 */
124 xorl %r10d, %r10d /* nospec r10 */
125 pushq %r11 /* pt_regs->r11 */
126 xorl %r11d, %r11d /* nospec r11*/
127 pushq %rbx /* pt_regs->rbx */
128 xorl %ebx, %ebx /* nospec rbx*/
129 pushq %rbp /* pt_regs->rbp */
130 xorl %ebp, %ebp /* nospec rbp*/
131 pushq %r12 /* pt_regs->r12 */
132 xorl %r12d, %r12d /* nospec r12*/
133 pushq %r13 /* pt_regs->r13 */
134 xorl %r13d, %r13d /* nospec r13*/
135 pushq %r14 /* pt_regs->r14 */
136 xorl %r14d, %r14d /* nospec r14*/
137 pushq %r15 /* pt_regs->r15 */
138 xorl %r15d, %r15d /* nospec r15*/
139 UNWIND_HINT_REGS
140 .if \save_ret
141 pushq %rsi /* return address on top of stack */
118 .endif 142 .endif
119 movq %rdx, 12*8+\offset(%rsp) 143.endm
120 movq %rsi, 13*8+\offset(%rsp) 144
121 movq %rdi, 14*8+\offset(%rsp) 145.macro POP_REGS pop_rdi=1 skip_r11rcx=0
122 UNWIND_HINT_REGS offset=\offset extra=0
123 .endm
124 .macro SAVE_C_REGS offset=0
125 SAVE_C_REGS_HELPER \offset, 1, 1, 1, 1
126 .endm
127 .macro SAVE_C_REGS_EXCEPT_RAX_RCX offset=0
128 SAVE_C_REGS_HELPER \offset, 0, 0, 1, 1
129 .endm
130 .macro SAVE_C_REGS_EXCEPT_R891011
131 SAVE_C_REGS_HELPER 0, 1, 1, 0, 0
132 .endm
133 .macro SAVE_C_REGS_EXCEPT_RCX_R891011
134 SAVE_C_REGS_HELPER 0, 1, 0, 0, 0
135 .endm
136 .macro SAVE_C_REGS_EXCEPT_RAX_RCX_R11
137 SAVE_C_REGS_HELPER 0, 0, 0, 1, 0
138 .endm
139
140 .macro SAVE_EXTRA_REGS offset=0
141 movq %r15, 0*8+\offset(%rsp)
142 movq %r14, 1*8+\offset(%rsp)
143 movq %r13, 2*8+\offset(%rsp)
144 movq %r12, 3*8+\offset(%rsp)
145 movq %rbp, 4*8+\offset(%rsp)
146 movq %rbx, 5*8+\offset(%rsp)
147 UNWIND_HINT_REGS offset=\offset
148 .endm
149
150 .macro POP_EXTRA_REGS
151 popq %r15 146 popq %r15
152 popq %r14 147 popq %r14
153 popq %r13 148 popq %r13
154 popq %r12 149 popq %r12
155 popq %rbp 150 popq %rbp
156 popq %rbx 151 popq %rbx
157 .endm 152 .if \skip_r11rcx
158 153 popq %rsi
159 .macro POP_C_REGS 154 .else
160 popq %r11 155 popq %r11
156 .endif
161 popq %r10 157 popq %r10
162 popq %r9 158 popq %r9
163 popq %r8 159 popq %r8
164 popq %rax 160 popq %rax
161 .if \skip_r11rcx
162 popq %rsi
163 .else
165 popq %rcx 164 popq %rcx
165 .endif
166 popq %rdx 166 popq %rdx
167 popq %rsi 167 popq %rsi
168 .if \pop_rdi
168 popq %rdi 169 popq %rdi
169 .endm 170 .endif
170 171.endm
171 .macro icebp
172 .byte 0xf1
173 .endm
174 172
175/* 173/*
176 * This is a sneaky trick to help the unwinder find pt_regs on the stack. The 174 * This is a sneaky trick to help the unwinder find pt_regs on the stack. The
@@ -178,17 +176,12 @@ For 32-bit we have the following conventions - kernel is built with
178 * is just setting the LSB, which makes it an invalid stack address and is also 176 * is just setting the LSB, which makes it an invalid stack address and is also
179 * a signal to the unwinder that it's a pt_regs pointer in disguise. 177 * a signal to the unwinder that it's a pt_regs pointer in disguise.
180 * 178 *
181 * NOTE: This macro must be used *after* SAVE_EXTRA_REGS because it corrupts 179 * NOTE: This macro must be used *after* PUSH_AND_CLEAR_REGS because it corrupts
182 * the original rbp. 180 * the original rbp.
183 */ 181 */
184.macro ENCODE_FRAME_POINTER ptregs_offset=0 182.macro ENCODE_FRAME_POINTER ptregs_offset=0
185#ifdef CONFIG_FRAME_POINTER 183#ifdef CONFIG_FRAME_POINTER
186 .if \ptregs_offset 184 leaq 1+\ptregs_offset(%rsp), %rbp
187 leaq \ptregs_offset(%rsp), %rbp
188 .else
189 mov %rsp, %rbp
190 .endif
191 orq $0x1, %rbp
192#endif 185#endif
193.endm 186.endm
194 187
diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S
index 16c2c022540d..6ad064c8cf35 100644
--- a/arch/x86/entry/entry_32.S
+++ b/arch/x86/entry/entry_32.S
@@ -252,8 +252,7 @@ ENTRY(__switch_to_asm)
252 * exist, overwrite the RSB with entries which capture 252 * exist, overwrite the RSB with entries which capture
253 * speculative execution to prevent attack. 253 * speculative execution to prevent attack.
254 */ 254 */
255 /* Clobbers %ebx */ 255 FILL_RETURN_BUFFER %ebx, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW
256 FILL_RETURN_BUFFER RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW
257#endif 256#endif
258 257
259 /* restore callee-saved registers */ 258 /* restore callee-saved registers */
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 30c8c5344c4a..18ed349b4f83 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -55,7 +55,7 @@ END(native_usergs_sysret64)
55 55
56.macro TRACE_IRQS_FLAGS flags:req 56.macro TRACE_IRQS_FLAGS flags:req
57#ifdef CONFIG_TRACE_IRQFLAGS 57#ifdef CONFIG_TRACE_IRQFLAGS
58 bt $9, \flags /* interrupts off? */ 58 btl $9, \flags /* interrupts off? */
59 jnc 1f 59 jnc 1f
60 TRACE_IRQS_ON 60 TRACE_IRQS_ON
611: 611:
@@ -213,7 +213,7 @@ ENTRY(entry_SYSCALL_64)
213 213
214 swapgs 214 swapgs
215 /* 215 /*
216 * This path is not taken when PAGE_TABLE_ISOLATION is disabled so it 216 * This path is only taken when PAGE_TABLE_ISOLATION is disabled so it
217 * is not required to switch CR3. 217 * is not required to switch CR3.
218 */ 218 */
219 movq %rsp, PER_CPU_VAR(rsp_scratch) 219 movq %rsp, PER_CPU_VAR(rsp_scratch)
@@ -227,22 +227,8 @@ ENTRY(entry_SYSCALL_64)
227 pushq %rcx /* pt_regs->ip */ 227 pushq %rcx /* pt_regs->ip */
228GLOBAL(entry_SYSCALL_64_after_hwframe) 228GLOBAL(entry_SYSCALL_64_after_hwframe)
229 pushq %rax /* pt_regs->orig_ax */ 229 pushq %rax /* pt_regs->orig_ax */
230 pushq %rdi /* pt_regs->di */ 230
231 pushq %rsi /* pt_regs->si */ 231 PUSH_AND_CLEAR_REGS rax=$-ENOSYS
232 pushq %rdx /* pt_regs->dx */
233 pushq %rcx /* pt_regs->cx */
234 pushq $-ENOSYS /* pt_regs->ax */
235 pushq %r8 /* pt_regs->r8 */
236 pushq %r9 /* pt_regs->r9 */
237 pushq %r10 /* pt_regs->r10 */
238 pushq %r11 /* pt_regs->r11 */
239 pushq %rbx /* pt_regs->rbx */
240 pushq %rbp /* pt_regs->rbp */
241 pushq %r12 /* pt_regs->r12 */
242 pushq %r13 /* pt_regs->r13 */
243 pushq %r14 /* pt_regs->r14 */
244 pushq %r15 /* pt_regs->r15 */
245 UNWIND_HINT_REGS
246 232
247 TRACE_IRQS_OFF 233 TRACE_IRQS_OFF
248 234
@@ -321,15 +307,7 @@ GLOBAL(entry_SYSCALL_64_after_hwframe)
321syscall_return_via_sysret: 307syscall_return_via_sysret:
322 /* rcx and r11 are already restored (see code above) */ 308 /* rcx and r11 are already restored (see code above) */
323 UNWIND_HINT_EMPTY 309 UNWIND_HINT_EMPTY
324 POP_EXTRA_REGS 310 POP_REGS pop_rdi=0 skip_r11rcx=1
325 popq %rsi /* skip r11 */
326 popq %r10
327 popq %r9
328 popq %r8
329 popq %rax
330 popq %rsi /* skip rcx */
331 popq %rdx
332 popq %rsi
333 311
334 /* 312 /*
335 * Now all regs are restored except RSP and RDI. 313 * Now all regs are restored except RSP and RDI.
@@ -386,8 +364,7 @@ ENTRY(__switch_to_asm)
386 * exist, overwrite the RSB with entries which capture 364 * exist, overwrite the RSB with entries which capture
387 * speculative execution to prevent attack. 365 * speculative execution to prevent attack.
388 */ 366 */
389 /* Clobbers %rbx */ 367 FILL_RETURN_BUFFER %r12, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW
390 FILL_RETURN_BUFFER RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW
391#endif 368#endif
392 369
393 /* restore callee-saved registers */ 370 /* restore callee-saved registers */
@@ -471,9 +448,19 @@ END(irq_entries_start)
471 * 448 *
472 * The invariant is that, if irq_count != -1, then the IRQ stack is in use. 449 * The invariant is that, if irq_count != -1, then the IRQ stack is in use.
473 */ 450 */
474.macro ENTER_IRQ_STACK regs=1 old_rsp 451.macro ENTER_IRQ_STACK regs=1 old_rsp save_ret=0
475 DEBUG_ENTRY_ASSERT_IRQS_OFF 452 DEBUG_ENTRY_ASSERT_IRQS_OFF
453
454 .if \save_ret
455 /*
456 * If save_ret is set, the original stack contains one additional
457 * entry -- the return address. Therefore, move the address one
458 * entry below %rsp to \old_rsp.
459 */
460 leaq 8(%rsp), \old_rsp
461 .else
476 movq %rsp, \old_rsp 462 movq %rsp, \old_rsp
463 .endif
477 464
478 .if \regs 465 .if \regs
479 UNWIND_HINT_REGS base=\old_rsp 466 UNWIND_HINT_REGS base=\old_rsp
@@ -519,6 +506,15 @@ END(irq_entries_start)
519 .if \regs 506 .if \regs
520 UNWIND_HINT_REGS indirect=1 507 UNWIND_HINT_REGS indirect=1
521 .endif 508 .endif
509
510 .if \save_ret
511 /*
512 * Push the return address to the stack. This return address can
513 * be found at the "real" original RSP, which was offset by 8 at
514 * the beginning of this macro.
515 */
516 pushq -8(\old_rsp)
517 .endif
522.endm 518.endm
523 519
524/* 520/*
@@ -542,29 +538,65 @@ END(irq_entries_start)
542.endm 538.endm
543 539
544/* 540/*
545 * Interrupt entry/exit. 541 * Interrupt entry helper function.
546 *
547 * Interrupt entry points save only callee clobbered registers in fast path.
548 * 542 *
549 * Entry runs with interrupts off. 543 * Entry runs with interrupts off. Stack layout at entry:
544 * +----------------------------------------------------+
545 * | regs->ss |
546 * | regs->rsp |
547 * | regs->eflags |
548 * | regs->cs |
549 * | regs->ip |
550 * +----------------------------------------------------+
551 * | regs->orig_ax = ~(interrupt number) |
552 * +----------------------------------------------------+
553 * | return address |
554 * +----------------------------------------------------+
550 */ 555 */
551 556ENTRY(interrupt_entry)
552/* 0(%rsp): ~(interrupt number) */ 557 UNWIND_HINT_FUNC
553 .macro interrupt func 558 ASM_CLAC
554 cld 559 cld
555 560
556 testb $3, CS-ORIG_RAX(%rsp) 561 testb $3, CS-ORIG_RAX+8(%rsp)
557 jz 1f 562 jz 1f
558 SWAPGS 563 SWAPGS
559 call switch_to_thread_stack 564
565 /*
566 * Switch to the thread stack. The IRET frame and orig_ax are
567 * on the stack, as well as the return address. RDI..R12 are
568 * not (yet) on the stack and space has not (yet) been
569 * allocated for them.
570 */
571 pushq %rdi
572
573 /* Need to switch before accessing the thread stack. */
574 SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi
575 movq %rsp, %rdi
576 movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
577
578 /*
579 * We have RDI, return address, and orig_ax on the stack on
580 * top of the IRET frame. That means offset=24
581 */
582 UNWIND_HINT_IRET_REGS base=%rdi offset=24
583
584 pushq 7*8(%rdi) /* regs->ss */
585 pushq 6*8(%rdi) /* regs->rsp */
586 pushq 5*8(%rdi) /* regs->eflags */
587 pushq 4*8(%rdi) /* regs->cs */
588 pushq 3*8(%rdi) /* regs->ip */
589 pushq 2*8(%rdi) /* regs->orig_ax */
590 pushq 8(%rdi) /* return address */
591 UNWIND_HINT_FUNC
592
593 movq (%rdi), %rdi
5601: 5941:
561 595
562 ALLOC_PT_GPREGS_ON_STACK 596 PUSH_AND_CLEAR_REGS save_ret=1
563 SAVE_C_REGS 597 ENCODE_FRAME_POINTER 8
564 SAVE_EXTRA_REGS
565 ENCODE_FRAME_POINTER
566 598
567 testb $3, CS(%rsp) 599 testb $3, CS+8(%rsp)
568 jz 1f 600 jz 1f
569 601
570 /* 602 /*
@@ -572,7 +604,7 @@ END(irq_entries_start)
572 * 604 *
573 * We need to tell lockdep that IRQs are off. We can't do this until 605 * We need to tell lockdep that IRQs are off. We can't do this until
574 * we fix gsbase, and we should do it before enter_from_user_mode 606 * we fix gsbase, and we should do it before enter_from_user_mode
575 * (which can take locks). Since TRACE_IRQS_OFF idempotent, 607 * (which can take locks). Since TRACE_IRQS_OFF is idempotent,
576 * the simplest way to handle it is to just call it twice if 608 * the simplest way to handle it is to just call it twice if
577 * we enter from user mode. There's no reason to optimize this since 609 * we enter from user mode. There's no reason to optimize this since
578 * TRACE_IRQS_OFF is a no-op if lockdep is off. 610 * TRACE_IRQS_OFF is a no-op if lockdep is off.
@@ -582,12 +614,15 @@ END(irq_entries_start)
582 CALL_enter_from_user_mode 614 CALL_enter_from_user_mode
583 615
5841: 6161:
585 ENTER_IRQ_STACK old_rsp=%rdi 617 ENTER_IRQ_STACK old_rsp=%rdi save_ret=1
586 /* We entered an interrupt context - irqs are off: */ 618 /* We entered an interrupt context - irqs are off: */
587 TRACE_IRQS_OFF 619 TRACE_IRQS_OFF
588 620
589 call \func /* rdi points to pt_regs */ 621 ret
590 .endm 622END(interrupt_entry)
623
624
625/* Interrupt entry/exit. */
591 626
592 /* 627 /*
593 * The interrupt stubs push (~vector+0x80) onto the stack and 628 * The interrupt stubs push (~vector+0x80) onto the stack and
@@ -595,9 +630,10 @@ END(irq_entries_start)
595 */ 630 */
596 .p2align CONFIG_X86_L1_CACHE_SHIFT 631 .p2align CONFIG_X86_L1_CACHE_SHIFT
597common_interrupt: 632common_interrupt:
598 ASM_CLAC
599 addq $-0x80, (%rsp) /* Adjust vector to [-256, -1] range */ 633 addq $-0x80, (%rsp) /* Adjust vector to [-256, -1] range */
600 interrupt do_IRQ 634 call interrupt_entry
635 UNWIND_HINT_REGS indirect=1
636 call do_IRQ /* rdi points to pt_regs */
601 /* 0(%rsp): old RSP */ 637 /* 0(%rsp): old RSP */
602ret_from_intr: 638ret_from_intr:
603 DISABLE_INTERRUPTS(CLBR_ANY) 639 DISABLE_INTERRUPTS(CLBR_ANY)
@@ -622,15 +658,7 @@ GLOBAL(swapgs_restore_regs_and_return_to_usermode)
622 ud2 658 ud2
6231: 6591:
624#endif 660#endif
625 POP_EXTRA_REGS 661 POP_REGS pop_rdi=0
626 popq %r11
627 popq %r10
628 popq %r9
629 popq %r8
630 popq %rax
631 popq %rcx
632 popq %rdx
633 popq %rsi
634 662
635 /* 663 /*
636 * The stack is now user RDI, orig_ax, RIP, CS, EFLAGS, RSP, SS. 664 * The stack is now user RDI, orig_ax, RIP, CS, EFLAGS, RSP, SS.
@@ -688,8 +716,7 @@ GLOBAL(restore_regs_and_return_to_kernel)
688 ud2 716 ud2
6891: 7171:
690#endif 718#endif
691 POP_EXTRA_REGS 719 POP_REGS
692 POP_C_REGS
693 addq $8, %rsp /* skip regs->orig_ax */ 720 addq $8, %rsp /* skip regs->orig_ax */
694 /* 721 /*
695 * ARCH_HAS_MEMBARRIER_SYNC_CORE rely on IRET core serialization 722 * ARCH_HAS_MEMBARRIER_SYNC_CORE rely on IRET core serialization
@@ -799,10 +826,11 @@ END(common_interrupt)
799.macro apicinterrupt3 num sym do_sym 826.macro apicinterrupt3 num sym do_sym
800ENTRY(\sym) 827ENTRY(\sym)
801 UNWIND_HINT_IRET_REGS 828 UNWIND_HINT_IRET_REGS
802 ASM_CLAC
803 pushq $~(\num) 829 pushq $~(\num)
804.Lcommon_\sym: 830.Lcommon_\sym:
805 interrupt \do_sym 831 call interrupt_entry
832 UNWIND_HINT_REGS indirect=1
833 call \do_sym /* rdi points to pt_regs */
806 jmp ret_from_intr 834 jmp ret_from_intr
807END(\sym) 835END(\sym)
808.endm 836.endm
@@ -865,34 +893,6 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt
865 */ 893 */
866#define CPU_TSS_IST(x) PER_CPU_VAR(cpu_tss_rw) + (TSS_ist + ((x) - 1) * 8) 894#define CPU_TSS_IST(x) PER_CPU_VAR(cpu_tss_rw) + (TSS_ist + ((x) - 1) * 8)
867 895
868/*
869 * Switch to the thread stack. This is called with the IRET frame and
870 * orig_ax on the stack. (That is, RDI..R12 are not on the stack and
871 * space has not been allocated for them.)
872 */
873ENTRY(switch_to_thread_stack)
874 UNWIND_HINT_FUNC
875
876 pushq %rdi
877 /* Need to switch before accessing the thread stack. */
878 SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi
879 movq %rsp, %rdi
880 movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
881 UNWIND_HINT sp_offset=16 sp_reg=ORC_REG_DI
882
883 pushq 7*8(%rdi) /* regs->ss */
884 pushq 6*8(%rdi) /* regs->rsp */
885 pushq 5*8(%rdi) /* regs->eflags */
886 pushq 4*8(%rdi) /* regs->cs */
887 pushq 3*8(%rdi) /* regs->ip */
888 pushq 2*8(%rdi) /* regs->orig_ax */
889 pushq 8(%rdi) /* return address */
890 UNWIND_HINT_FUNC
891
892 movq (%rdi), %rdi
893 ret
894END(switch_to_thread_stack)
895
896.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 896.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
897ENTRY(\sym) 897ENTRY(\sym)
898 UNWIND_HINT_IRET_REGS offset=\has_error_code*8 898 UNWIND_HINT_IRET_REGS offset=\has_error_code*8
@@ -908,10 +908,8 @@ ENTRY(\sym)
908 pushq $-1 /* ORIG_RAX: no syscall to restart */ 908 pushq $-1 /* ORIG_RAX: no syscall to restart */
909 .endif 909 .endif
910 910
911 ALLOC_PT_GPREGS_ON_STACK
912
913 .if \paranoid < 2 911 .if \paranoid < 2
914 testb $3, CS(%rsp) /* If coming from userspace, switch stacks */ 912 testb $3, CS-ORIG_RAX(%rsp) /* If coming from userspace, switch stacks */
915 jnz .Lfrom_usermode_switch_stack_\@ 913 jnz .Lfrom_usermode_switch_stack_\@
916 .endif 914 .endif
917 915
@@ -1121,9 +1119,7 @@ ENTRY(xen_failsafe_callback)
1121 addq $0x30, %rsp 1119 addq $0x30, %rsp
1122 UNWIND_HINT_IRET_REGS 1120 UNWIND_HINT_IRET_REGS
1123 pushq $-1 /* orig_ax = -1 => not a system call */ 1121 pushq $-1 /* orig_ax = -1 => not a system call */
1124 ALLOC_PT_GPREGS_ON_STACK 1122 PUSH_AND_CLEAR_REGS
1125 SAVE_C_REGS
1126 SAVE_EXTRA_REGS
1127 ENCODE_FRAME_POINTER 1123 ENCODE_FRAME_POINTER
1128 jmp error_exit 1124 jmp error_exit
1129END(xen_failsafe_callback) 1125END(xen_failsafe_callback)
@@ -1142,7 +1138,7 @@ apicinterrupt3 HYPERV_REENLIGHTENMENT_VECTOR \
1142#endif /* CONFIG_HYPERV */ 1138#endif /* CONFIG_HYPERV */
1143 1139
1144idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK 1140idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
1145idtentry int3 do_int3 has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK 1141idtentry int3 do_int3 has_error_code=0
1146idtentry stack_segment do_stack_segment has_error_code=1 1142idtentry stack_segment do_stack_segment has_error_code=1
1147 1143
1148#ifdef CONFIG_XEN 1144#ifdef CONFIG_XEN
@@ -1170,8 +1166,7 @@ idtentry machine_check do_mce has_error_code=0 paranoid=1
1170ENTRY(paranoid_entry) 1166ENTRY(paranoid_entry)
1171 UNWIND_HINT_FUNC 1167 UNWIND_HINT_FUNC
1172 cld 1168 cld
1173 SAVE_C_REGS 8 1169 PUSH_AND_CLEAR_REGS save_ret=1
1174 SAVE_EXTRA_REGS 8
1175 ENCODE_FRAME_POINTER 8 1170 ENCODE_FRAME_POINTER 8
1176 movl $1, %ebx 1171 movl $1, %ebx
1177 movl $MSR_GS_BASE, %ecx 1172 movl $MSR_GS_BASE, %ecx
@@ -1211,21 +1206,20 @@ ENTRY(paranoid_exit)
1211 jmp .Lparanoid_exit_restore 1206 jmp .Lparanoid_exit_restore
1212.Lparanoid_exit_no_swapgs: 1207.Lparanoid_exit_no_swapgs:
1213 TRACE_IRQS_IRETQ_DEBUG 1208 TRACE_IRQS_IRETQ_DEBUG
1209 RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
1214.Lparanoid_exit_restore: 1210.Lparanoid_exit_restore:
1215 jmp restore_regs_and_return_to_kernel 1211 jmp restore_regs_and_return_to_kernel
1216END(paranoid_exit) 1212END(paranoid_exit)
1217 1213
1218/* 1214/*
1219 * Save all registers in pt_regs, and switch gs if needed. 1215 * Save all registers in pt_regs, and switch GS if needed.
1220 * Return: EBX=0: came from user mode; EBX=1: otherwise 1216 * Return: EBX=0: came from user mode; EBX=1: otherwise
1221 */ 1217 */
1222ENTRY(error_entry) 1218ENTRY(error_entry)
1223 UNWIND_HINT_FUNC 1219 UNWIND_HINT_FUNC
1224 cld 1220 cld
1225 SAVE_C_REGS 8 1221 PUSH_AND_CLEAR_REGS save_ret=1
1226 SAVE_EXTRA_REGS 8
1227 ENCODE_FRAME_POINTER 8 1222 ENCODE_FRAME_POINTER 8
1228 xorl %ebx, %ebx
1229 testb $3, CS+8(%rsp) 1223 testb $3, CS+8(%rsp)
1230 jz .Lerror_kernelspace 1224 jz .Lerror_kernelspace
1231 1225
@@ -1406,22 +1400,7 @@ ENTRY(nmi)
1406 pushq 1*8(%rdx) /* pt_regs->rip */ 1400 pushq 1*8(%rdx) /* pt_regs->rip */
1407 UNWIND_HINT_IRET_REGS 1401 UNWIND_HINT_IRET_REGS
1408 pushq $-1 /* pt_regs->orig_ax */ 1402 pushq $-1 /* pt_regs->orig_ax */
1409 pushq %rdi /* pt_regs->di */ 1403 PUSH_AND_CLEAR_REGS rdx=(%rdx)
1410 pushq %rsi /* pt_regs->si */
1411 pushq (%rdx) /* pt_regs->dx */
1412 pushq %rcx /* pt_regs->cx */
1413 pushq %rax /* pt_regs->ax */
1414 pushq %r8 /* pt_regs->r8 */
1415 pushq %r9 /* pt_regs->r9 */
1416 pushq %r10 /* pt_regs->r10 */
1417 pushq %r11 /* pt_regs->r11 */
1418 pushq %rbx /* pt_regs->rbx */
1419 pushq %rbp /* pt_regs->rbp */
1420 pushq %r12 /* pt_regs->r12 */
1421 pushq %r13 /* pt_regs->r13 */
1422 pushq %r14 /* pt_regs->r14 */
1423 pushq %r15 /* pt_regs->r15 */
1424 UNWIND_HINT_REGS
1425 ENCODE_FRAME_POINTER 1404 ENCODE_FRAME_POINTER
1426 1405
1427 /* 1406 /*
@@ -1631,7 +1610,6 @@ end_repeat_nmi:
1631 * frame to point back to repeat_nmi. 1610 * frame to point back to repeat_nmi.
1632 */ 1611 */
1633 pushq $-1 /* ORIG_RAX: no syscall to restart */ 1612 pushq $-1 /* ORIG_RAX: no syscall to restart */
1634 ALLOC_PT_GPREGS_ON_STACK
1635 1613
1636 /* 1614 /*
1637 * Use paranoid_entry to handle SWAPGS, but no need to use paranoid_exit 1615 * Use paranoid_entry to handle SWAPGS, but no need to use paranoid_exit
@@ -1655,8 +1633,7 @@ end_repeat_nmi:
1655nmi_swapgs: 1633nmi_swapgs:
1656 SWAPGS_UNSAFE_STACK 1634 SWAPGS_UNSAFE_STACK
1657nmi_restore: 1635nmi_restore:
1658 POP_EXTRA_REGS 1636 POP_REGS
1659 POP_C_REGS
1660 1637
1661 /* 1638 /*
1662 * Skip orig_ax and the "outermost" frame to point RSP at the "iret" 1639 * Skip orig_ax and the "outermost" frame to point RSP at the "iret"
diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 98d5358e4041..08425c42f8b7 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -85,15 +85,25 @@ ENTRY(entry_SYSENTER_compat)
85 pushq %rcx /* pt_regs->cx */ 85 pushq %rcx /* pt_regs->cx */
86 pushq $-ENOSYS /* pt_regs->ax */ 86 pushq $-ENOSYS /* pt_regs->ax */
87 pushq $0 /* pt_regs->r8 = 0 */ 87 pushq $0 /* pt_regs->r8 = 0 */
88 xorl %r8d, %r8d /* nospec r8 */
88 pushq $0 /* pt_regs->r9 = 0 */ 89 pushq $0 /* pt_regs->r9 = 0 */
90 xorl %r9d, %r9d /* nospec r9 */
89 pushq $0 /* pt_regs->r10 = 0 */ 91 pushq $0 /* pt_regs->r10 = 0 */
92 xorl %r10d, %r10d /* nospec r10 */
90 pushq $0 /* pt_regs->r11 = 0 */ 93 pushq $0 /* pt_regs->r11 = 0 */
94 xorl %r11d, %r11d /* nospec r11 */
91 pushq %rbx /* pt_regs->rbx */ 95 pushq %rbx /* pt_regs->rbx */
96 xorl %ebx, %ebx /* nospec rbx */
92 pushq %rbp /* pt_regs->rbp (will be overwritten) */ 97 pushq %rbp /* pt_regs->rbp (will be overwritten) */
98 xorl %ebp, %ebp /* nospec rbp */
93 pushq $0 /* pt_regs->r12 = 0 */ 99 pushq $0 /* pt_regs->r12 = 0 */
100 xorl %r12d, %r12d /* nospec r12 */
94 pushq $0 /* pt_regs->r13 = 0 */ 101 pushq $0 /* pt_regs->r13 = 0 */
102 xorl %r13d, %r13d /* nospec r13 */
95 pushq $0 /* pt_regs->r14 = 0 */ 103 pushq $0 /* pt_regs->r14 = 0 */
104 xorl %r14d, %r14d /* nospec r14 */
96 pushq $0 /* pt_regs->r15 = 0 */ 105 pushq $0 /* pt_regs->r15 = 0 */
106 xorl %r15d, %r15d /* nospec r15 */
97 cld 107 cld
98 108
99 /* 109 /*
@@ -214,15 +224,25 @@ GLOBAL(entry_SYSCALL_compat_after_hwframe)
214 pushq %rbp /* pt_regs->cx (stashed in bp) */ 224 pushq %rbp /* pt_regs->cx (stashed in bp) */
215 pushq $-ENOSYS /* pt_regs->ax */ 225 pushq $-ENOSYS /* pt_regs->ax */
216 pushq $0 /* pt_regs->r8 = 0 */ 226 pushq $0 /* pt_regs->r8 = 0 */
227 xorl %r8d, %r8d /* nospec r8 */
217 pushq $0 /* pt_regs->r9 = 0 */ 228 pushq $0 /* pt_regs->r9 = 0 */
229 xorl %r9d, %r9d /* nospec r9 */
218 pushq $0 /* pt_regs->r10 = 0 */ 230 pushq $0 /* pt_regs->r10 = 0 */
231 xorl %r10d, %r10d /* nospec r10 */
219 pushq $0 /* pt_regs->r11 = 0 */ 232 pushq $0 /* pt_regs->r11 = 0 */
233 xorl %r11d, %r11d /* nospec r11 */
220 pushq %rbx /* pt_regs->rbx */ 234 pushq %rbx /* pt_regs->rbx */
235 xorl %ebx, %ebx /* nospec rbx */
221 pushq %rbp /* pt_regs->rbp (will be overwritten) */ 236 pushq %rbp /* pt_regs->rbp (will be overwritten) */
237 xorl %ebp, %ebp /* nospec rbp */
222 pushq $0 /* pt_regs->r12 = 0 */ 238 pushq $0 /* pt_regs->r12 = 0 */
239 xorl %r12d, %r12d /* nospec r12 */
223 pushq $0 /* pt_regs->r13 = 0 */ 240 pushq $0 /* pt_regs->r13 = 0 */
241 xorl %r13d, %r13d /* nospec r13 */
224 pushq $0 /* pt_regs->r14 = 0 */ 242 pushq $0 /* pt_regs->r14 = 0 */
243 xorl %r14d, %r14d /* nospec r14 */
225 pushq $0 /* pt_regs->r15 = 0 */ 244 pushq $0 /* pt_regs->r15 = 0 */
245 xorl %r15d, %r15d /* nospec r15 */
226 246
227 /* 247 /*
228 * User mode is traced as though IRQs are on, and SYSENTER 248 * User mode is traced as though IRQs are on, and SYSENTER
@@ -278,9 +298,9 @@ sysret32_from_system_call:
278 */ 298 */
279 SWITCH_TO_USER_CR3_NOSTACK scratch_reg=%r8 scratch_reg2=%r9 299 SWITCH_TO_USER_CR3_NOSTACK scratch_reg=%r8 scratch_reg2=%r9
280 300
281 xorq %r8, %r8 301 xorl %r8d, %r8d
282 xorq %r9, %r9 302 xorl %r9d, %r9d
283 xorq %r10, %r10 303 xorl %r10d, %r10d
284 swapgs 304 swapgs
285 sysretl 305 sysretl
286END(entry_SYSCALL_compat) 306END(entry_SYSCALL_compat)
@@ -327,26 +347,47 @@ ENTRY(entry_INT80_compat)
327 */ 347 */
328 movl %eax, %eax 348 movl %eax, %eax
329 349
350 /* switch to thread stack expects orig_ax and rdi to be pushed */
330 pushq %rax /* pt_regs->orig_ax */ 351 pushq %rax /* pt_regs->orig_ax */
352 pushq %rdi /* pt_regs->di */
331 353
332 /* switch to thread stack expects orig_ax to be pushed */ 354 /* Need to switch before accessing the thread stack. */
333 call switch_to_thread_stack 355 SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi
356 movq %rsp, %rdi
357 movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
334 358
335 pushq %rdi /* pt_regs->di */ 359 pushq 6*8(%rdi) /* regs->ss */
360 pushq 5*8(%rdi) /* regs->rsp */
361 pushq 4*8(%rdi) /* regs->eflags */
362 pushq 3*8(%rdi) /* regs->cs */
363 pushq 2*8(%rdi) /* regs->ip */
364 pushq 1*8(%rdi) /* regs->orig_ax */
365
366 pushq (%rdi) /* pt_regs->di */
336 pushq %rsi /* pt_regs->si */ 367 pushq %rsi /* pt_regs->si */
337 pushq %rdx /* pt_regs->dx */ 368 pushq %rdx /* pt_regs->dx */
338 pushq %rcx /* pt_regs->cx */ 369 pushq %rcx /* pt_regs->cx */
339 pushq $-ENOSYS /* pt_regs->ax */ 370 pushq $-ENOSYS /* pt_regs->ax */
340 pushq $0 /* pt_regs->r8 = 0 */ 371 pushq $0 /* pt_regs->r8 = 0 */
372 xorl %r8d, %r8d /* nospec r8 */
341 pushq $0 /* pt_regs->r9 = 0 */ 373 pushq $0 /* pt_regs->r9 = 0 */
374 xorl %r9d, %r9d /* nospec r9 */
342 pushq $0 /* pt_regs->r10 = 0 */ 375 pushq $0 /* pt_regs->r10 = 0 */
376 xorl %r10d, %r10d /* nospec r10 */
343 pushq $0 /* pt_regs->r11 = 0 */ 377 pushq $0 /* pt_regs->r11 = 0 */
378 xorl %r11d, %r11d /* nospec r11 */
344 pushq %rbx /* pt_regs->rbx */ 379 pushq %rbx /* pt_regs->rbx */
380 xorl %ebx, %ebx /* nospec rbx */
345 pushq %rbp /* pt_regs->rbp */ 381 pushq %rbp /* pt_regs->rbp */
382 xorl %ebp, %ebp /* nospec rbp */
346 pushq %r12 /* pt_regs->r12 */ 383 pushq %r12 /* pt_regs->r12 */
384 xorl %r12d, %r12d /* nospec r12 */
347 pushq %r13 /* pt_regs->r13 */ 385 pushq %r13 /* pt_regs->r13 */
386 xorl %r13d, %r13d /* nospec r13 */
348 pushq %r14 /* pt_regs->r14 */ 387 pushq %r14 /* pt_regs->r14 */
388 xorl %r14d, %r14d /* nospec r14 */
349 pushq %r15 /* pt_regs->r15 */ 389 pushq %r15 /* pt_regs->r15 */
390 xorl %r15d, %r15d /* nospec r15 */
350 cld 391 cld
351 392
352 /* 393 /*
@@ -363,15 +404,3 @@ ENTRY(entry_INT80_compat)
363 TRACE_IRQS_ON 404 TRACE_IRQS_ON
364 jmp swapgs_restore_regs_and_return_to_usermode 405 jmp swapgs_restore_regs_and_return_to_usermode
365END(entry_INT80_compat) 406END(entry_INT80_compat)
366
367ENTRY(stub32_clone)
368 /*
369 * The 32-bit clone ABI is: clone(..., int tls_val, int *child_tidptr).
370 * The 64-bit clone ABI is: clone(..., int *child_tidptr, int tls_val).
371 *
372 * The native 64-bit kernel's sys_clone() implements the latter,
373 * so we need to swap arguments here before calling it:
374 */
375 xchg %r8, %rcx
376 jmp sys_clone
377ENDPROC(stub32_clone)
diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
index 448ac2161112..2a5e99cff859 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -8,12 +8,12 @@
8# 8#
90 i386 restart_syscall sys_restart_syscall 90 i386 restart_syscall sys_restart_syscall
101 i386 exit sys_exit 101 i386 exit sys_exit
112 i386 fork sys_fork sys_fork 112 i386 fork sys_fork
123 i386 read sys_read 123 i386 read sys_read
134 i386 write sys_write 134 i386 write sys_write
145 i386 open sys_open compat_sys_open 145 i386 open sys_open compat_sys_open
156 i386 close sys_close 156 i386 close sys_close
167 i386 waitpid sys_waitpid sys32_waitpid 167 i386 waitpid sys_waitpid compat_sys_x86_waitpid
178 i386 creat sys_creat 178 i386 creat sys_creat
189 i386 link sys_link 189 i386 link sys_link
1910 i386 unlink sys_unlink 1910 i386 unlink sys_unlink
@@ -78,7 +78,7 @@
7869 i386 ssetmask sys_ssetmask 7869 i386 ssetmask sys_ssetmask
7970 i386 setreuid sys_setreuid16 7970 i386 setreuid sys_setreuid16
8071 i386 setregid sys_setregid16 8071 i386 setregid sys_setregid16
8172 i386 sigsuspend sys_sigsuspend sys_sigsuspend 8172 i386 sigsuspend sys_sigsuspend
8273 i386 sigpending sys_sigpending compat_sys_sigpending 8273 i386 sigpending sys_sigpending compat_sys_sigpending
8374 i386 sethostname sys_sethostname 8374 i386 sethostname sys_sethostname
8475 i386 setrlimit sys_setrlimit compat_sys_setrlimit 8475 i386 setrlimit sys_setrlimit compat_sys_setrlimit
@@ -96,7 +96,7 @@
9687 i386 swapon sys_swapon 9687 i386 swapon sys_swapon
9788 i386 reboot sys_reboot 9788 i386 reboot sys_reboot
9889 i386 readdir sys_old_readdir compat_sys_old_readdir 9889 i386 readdir sys_old_readdir compat_sys_old_readdir
9990 i386 mmap sys_old_mmap sys32_mmap 9990 i386 mmap sys_old_mmap compat_sys_x86_mmap
10091 i386 munmap sys_munmap 10091 i386 munmap sys_munmap
10192 i386 truncate sys_truncate compat_sys_truncate 10192 i386 truncate sys_truncate compat_sys_truncate
10293 i386 ftruncate sys_ftruncate compat_sys_ftruncate 10293 i386 ftruncate sys_ftruncate compat_sys_ftruncate
@@ -126,7 +126,7 @@
126117 i386 ipc sys_ipc compat_sys_ipc 126117 i386 ipc sys_ipc compat_sys_ipc
127118 i386 fsync sys_fsync 127118 i386 fsync sys_fsync
128119 i386 sigreturn sys_sigreturn sys32_sigreturn 128119 i386 sigreturn sys_sigreturn sys32_sigreturn
129120 i386 clone sys_clone stub32_clone 129120 i386 clone sys_clone compat_sys_x86_clone
130121 i386 setdomainname sys_setdomainname 130121 i386 setdomainname sys_setdomainname
131122 i386 uname sys_newuname 131122 i386 uname sys_newuname
132123 i386 modify_ldt sys_modify_ldt 132123 i386 modify_ldt sys_modify_ldt
@@ -186,8 +186,8 @@
186177 i386 rt_sigtimedwait sys_rt_sigtimedwait compat_sys_rt_sigtimedwait 186177 i386 rt_sigtimedwait sys_rt_sigtimedwait compat_sys_rt_sigtimedwait
187178 i386 rt_sigqueueinfo sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo 187178 i386 rt_sigqueueinfo sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo
188179 i386 rt_sigsuspend sys_rt_sigsuspend 188179 i386 rt_sigsuspend sys_rt_sigsuspend
189180 i386 pread64 sys_pread64 sys32_pread 189180 i386 pread64 sys_pread64 compat_sys_x86_pread
190181 i386 pwrite64 sys_pwrite64 sys32_pwrite 190181 i386 pwrite64 sys_pwrite64 compat_sys_x86_pwrite
191182 i386 chown sys_chown16 191182 i386 chown sys_chown16
192183 i386 getcwd sys_getcwd 192183 i386 getcwd sys_getcwd
193184 i386 capget sys_capget 193184 i386 capget sys_capget
@@ -196,14 +196,14 @@
196187 i386 sendfile sys_sendfile compat_sys_sendfile 196187 i386 sendfile sys_sendfile compat_sys_sendfile
197188 i386 getpmsg 197188 i386 getpmsg
198189 i386 putpmsg 198189 i386 putpmsg
199190 i386 vfork sys_vfork sys_vfork 199190 i386 vfork sys_vfork
200191 i386 ugetrlimit sys_getrlimit compat_sys_getrlimit 200191 i386 ugetrlimit sys_getrlimit compat_sys_getrlimit
201192 i386 mmap2 sys_mmap_pgoff 201192 i386 mmap2 sys_mmap_pgoff
202193 i386 truncate64 sys_truncate64 sys32_truncate64 202193 i386 truncate64 sys_truncate64 compat_sys_x86_truncate64
203194 i386 ftruncate64 sys_ftruncate64 sys32_ftruncate64 203194 i386 ftruncate64 sys_ftruncate64 compat_sys_x86_ftruncate64
204195 i386 stat64 sys_stat64 sys32_stat64 204195 i386 stat64 sys_stat64 compat_sys_x86_stat64
205196 i386 lstat64 sys_lstat64 sys32_lstat64 205196 i386 lstat64 sys_lstat64 compat_sys_x86_lstat64
206197 i386 fstat64 sys_fstat64 sys32_fstat64 206197 i386 fstat64 sys_fstat64 compat_sys_x86_fstat64
207198 i386 lchown32 sys_lchown 207198 i386 lchown32 sys_lchown
208199 i386 getuid32 sys_getuid 208199 i386 getuid32 sys_getuid
209200 i386 getgid32 sys_getgid 209200 i386 getgid32 sys_getgid
@@ -231,7 +231,7 @@
231# 222 is unused 231# 222 is unused
232# 223 is unused 232# 223 is unused
233224 i386 gettid sys_gettid 233224 i386 gettid sys_gettid
234225 i386 readahead sys_readahead sys32_readahead 234225 i386 readahead sys_readahead compat_sys_x86_readahead
235226 i386 setxattr sys_setxattr 235226 i386 setxattr sys_setxattr
236227 i386 lsetxattr sys_lsetxattr 236227 i386 lsetxattr sys_lsetxattr
237228 i386 fsetxattr sys_fsetxattr 237228 i386 fsetxattr sys_fsetxattr
@@ -256,7 +256,7 @@
256247 i386 io_getevents sys_io_getevents compat_sys_io_getevents 256247 i386 io_getevents sys_io_getevents compat_sys_io_getevents
257248 i386 io_submit sys_io_submit compat_sys_io_submit 257248 i386 io_submit sys_io_submit compat_sys_io_submit
258249 i386 io_cancel sys_io_cancel 258249 i386 io_cancel sys_io_cancel
259250 i386 fadvise64 sys_fadvise64 sys32_fadvise64 259250 i386 fadvise64 sys_fadvise64 compat_sys_x86_fadvise64
260# 251 is available for reuse (was briefly sys_set_zone_reclaim) 260# 251 is available for reuse (was briefly sys_set_zone_reclaim)
261252 i386 exit_group sys_exit_group 261252 i386 exit_group sys_exit_group
262253 i386 lookup_dcookie sys_lookup_dcookie compat_sys_lookup_dcookie 262253 i386 lookup_dcookie sys_lookup_dcookie compat_sys_lookup_dcookie
@@ -278,7 +278,7 @@
278269 i386 fstatfs64 sys_fstatfs64 compat_sys_fstatfs64 278269 i386 fstatfs64 sys_fstatfs64 compat_sys_fstatfs64
279270 i386 tgkill sys_tgkill 279270 i386 tgkill sys_tgkill
280271 i386 utimes sys_utimes compat_sys_utimes 280271 i386 utimes sys_utimes compat_sys_utimes
281272 i386 fadvise64_64 sys_fadvise64_64 sys32_fadvise64_64 281272 i386 fadvise64_64 sys_fadvise64_64 compat_sys_x86_fadvise64_64
282273 i386 vserver 282273 i386 vserver
283274 i386 mbind sys_mbind 283274 i386 mbind sys_mbind
284275 i386 get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy 284275 i386 get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy
@@ -306,7 +306,7 @@
306297 i386 mknodat sys_mknodat 306297 i386 mknodat sys_mknodat
307298 i386 fchownat sys_fchownat 307298 i386 fchownat sys_fchownat
308299 i386 futimesat sys_futimesat compat_sys_futimesat 308299 i386 futimesat sys_futimesat compat_sys_futimesat
309300 i386 fstatat64 sys_fstatat64 sys32_fstatat 309300 i386 fstatat64 sys_fstatat64 compat_sys_x86_fstatat
310301 i386 unlinkat sys_unlinkat 310301 i386 unlinkat sys_unlinkat
311302 i386 renameat sys_renameat 311302 i386 renameat sys_renameat
312303 i386 linkat sys_linkat 312303 i386 linkat sys_linkat
@@ -320,7 +320,7 @@
320311 i386 set_robust_list sys_set_robust_list compat_sys_set_robust_list 320311 i386 set_robust_list sys_set_robust_list compat_sys_set_robust_list
321312 i386 get_robust_list sys_get_robust_list compat_sys_get_robust_list 321312 i386 get_robust_list sys_get_robust_list compat_sys_get_robust_list
322313 i386 splice sys_splice 322313 i386 splice sys_splice
323314 i386 sync_file_range sys_sync_file_range sys32_sync_file_range 323314 i386 sync_file_range sys_sync_file_range compat_sys_x86_sync_file_range
324315 i386 tee sys_tee 324315 i386 tee sys_tee
325316 i386 vmsplice sys_vmsplice compat_sys_vmsplice 325316 i386 vmsplice sys_vmsplice compat_sys_vmsplice
326317 i386 move_pages sys_move_pages compat_sys_move_pages 326317 i386 move_pages sys_move_pages compat_sys_move_pages
@@ -330,7 +330,7 @@
330321 i386 signalfd sys_signalfd compat_sys_signalfd 330321 i386 signalfd sys_signalfd compat_sys_signalfd
331322 i386 timerfd_create sys_timerfd_create 331322 i386 timerfd_create sys_timerfd_create
332323 i386 eventfd sys_eventfd 332323 i386 eventfd sys_eventfd
333324 i386 fallocate sys_fallocate sys32_fallocate 333324 i386 fallocate sys_fallocate compat_sys_x86_fallocate
334325 i386 timerfd_settime sys_timerfd_settime compat_sys_timerfd_settime 334325 i386 timerfd_settime sys_timerfd_settime compat_sys_timerfd_settime
335326 i386 timerfd_gettime sys_timerfd_gettime compat_sys_timerfd_gettime 335326 i386 timerfd_gettime sys_timerfd_gettime compat_sys_timerfd_gettime
336327 i386 signalfd4 sys_signalfd4 compat_sys_signalfd4 336327 i386 signalfd4 sys_signalfd4 compat_sys_signalfd4
diff --git a/arch/x86/entry/vdso/vdso32/vclock_gettime.c b/arch/x86/entry/vdso/vdso32/vclock_gettime.c
index 7780bbfb06ef..9242b28418d5 100644
--- a/arch/x86/entry/vdso/vdso32/vclock_gettime.c
+++ b/arch/x86/entry/vdso/vdso32/vclock_gettime.c
@@ -5,8 +5,6 @@
5#undef CONFIG_OPTIMIZE_INLINING 5#undef CONFIG_OPTIMIZE_INLINING
6#endif 6#endif
7 7
8#undef CONFIG_X86_PPRO_FENCE
9
10#ifdef CONFIG_X86_64 8#ifdef CONFIG_X86_64
11 9
12/* 10/*
diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscall/vsyscall_64.c
index 577fa8adb785..317be365bce3 100644
--- a/arch/x86/entry/vsyscall/vsyscall_64.c
+++ b/arch/x86/entry/vsyscall/vsyscall_64.c
@@ -42,10 +42,8 @@
42#define CREATE_TRACE_POINTS 42#define CREATE_TRACE_POINTS
43#include "vsyscall_trace.h" 43#include "vsyscall_trace.h"
44 44
45static enum { EMULATE, NATIVE, NONE } vsyscall_mode = 45static enum { EMULATE, NONE } vsyscall_mode =
46#if defined(CONFIG_LEGACY_VSYSCALL_NATIVE) 46#ifdef CONFIG_LEGACY_VSYSCALL_NONE
47 NATIVE;
48#elif defined(CONFIG_LEGACY_VSYSCALL_NONE)
49 NONE; 47 NONE;
50#else 48#else
51 EMULATE; 49 EMULATE;
@@ -56,8 +54,6 @@ static int __init vsyscall_setup(char *str)
56 if (str) { 54 if (str) {
57 if (!strcmp("emulate", str)) 55 if (!strcmp("emulate", str))
58 vsyscall_mode = EMULATE; 56 vsyscall_mode = EMULATE;
59 else if (!strcmp("native", str))
60 vsyscall_mode = NATIVE;
61 else if (!strcmp("none", str)) 57 else if (!strcmp("none", str))
62 vsyscall_mode = NONE; 58 vsyscall_mode = NONE;
63 else 59 else
@@ -139,10 +135,6 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
139 135
140 WARN_ON_ONCE(address != regs->ip); 136 WARN_ON_ONCE(address != regs->ip);
141 137
142 /* This should be unreachable in NATIVE mode. */
143 if (WARN_ON(vsyscall_mode == NATIVE))
144 return false;
145
146 if (vsyscall_mode == NONE) { 138 if (vsyscall_mode == NONE) {
147 warn_bad_vsyscall(KERN_INFO, regs, 139 warn_bad_vsyscall(KERN_INFO, regs,
148 "vsyscall attempted with vsyscall=none"); 140 "vsyscall attempted with vsyscall=none");
@@ -355,7 +347,7 @@ void __init set_vsyscall_pgtable_user_bits(pgd_t *root)
355 set_pgd(pgd, __pgd(pgd_val(*pgd) | _PAGE_USER)); 347 set_pgd(pgd, __pgd(pgd_val(*pgd) | _PAGE_USER));
356 p4d = p4d_offset(pgd, VSYSCALL_ADDR); 348 p4d = p4d_offset(pgd, VSYSCALL_ADDR);
357#if CONFIG_PGTABLE_LEVELS >= 5 349#if CONFIG_PGTABLE_LEVELS >= 5
358 p4d->p4d |= _PAGE_USER; 350 set_p4d(p4d, __p4d(p4d_val(*p4d) | _PAGE_USER));
359#endif 351#endif
360 pud = pud_offset(p4d, VSYSCALL_ADDR); 352 pud = pud_offset(p4d, VSYSCALL_ADDR);
361 set_pud(pud, __pud(pud_val(*pud) | _PAGE_USER)); 353 set_pud(pud, __pud(pud_val(*pud) | _PAGE_USER));
@@ -370,9 +362,7 @@ void __init map_vsyscall(void)
370 362
371 if (vsyscall_mode != NONE) { 363 if (vsyscall_mode != NONE) {
372 __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, 364 __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
373 vsyscall_mode == NATIVE 365 PAGE_KERNEL_VVAR);
374 ? PAGE_KERNEL_VSYSCALL
375 : PAGE_KERNEL_VVAR);
376 set_vsyscall_pgtable_user_bits(swapper_pg_dir); 366 set_vsyscall_pgtable_user_bits(swapper_pg_dir);
377 } 367 }
378 368
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 140d33288e78..88797c80b3e0 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2118,7 +2118,8 @@ static int x86_pmu_event_init(struct perf_event *event)
2118 event->destroy(event); 2118 event->destroy(event);
2119 } 2119 }
2120 2120
2121 if (READ_ONCE(x86_pmu.attr_rdpmc)) 2121 if (READ_ONCE(x86_pmu.attr_rdpmc) &&
2122 !(event->hw.flags & PERF_X86_EVENT_LARGE_PEBS))
2122 event->hw.flags |= PERF_X86_EVENT_RDPMC_ALLOWED; 2123 event->hw.flags |= PERF_X86_EVENT_RDPMC_ALLOWED;
2123 2124
2124 return err; 2125 return err;
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 731153a4681e..1e41d7508d99 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -2952,9 +2952,9 @@ static void intel_pebs_aliases_skl(struct perf_event *event)
2952 return intel_pebs_aliases_precdist(event); 2952 return intel_pebs_aliases_precdist(event);
2953} 2953}
2954 2954
2955static unsigned long intel_pmu_free_running_flags(struct perf_event *event) 2955static unsigned long intel_pmu_large_pebs_flags(struct perf_event *event)
2956{ 2956{
2957 unsigned long flags = x86_pmu.free_running_flags; 2957 unsigned long flags = x86_pmu.large_pebs_flags;
2958 2958
2959 if (event->attr.use_clockid) 2959 if (event->attr.use_clockid)
2960 flags &= ~PERF_SAMPLE_TIME; 2960 flags &= ~PERF_SAMPLE_TIME;
@@ -2976,8 +2976,8 @@ static int intel_pmu_hw_config(struct perf_event *event)
2976 if (!event->attr.freq) { 2976 if (!event->attr.freq) {
2977 event->hw.flags |= PERF_X86_EVENT_AUTO_RELOAD; 2977 event->hw.flags |= PERF_X86_EVENT_AUTO_RELOAD;
2978 if (!(event->attr.sample_type & 2978 if (!(event->attr.sample_type &
2979 ~intel_pmu_free_running_flags(event))) 2979 ~intel_pmu_large_pebs_flags(event)))
2980 event->hw.flags |= PERF_X86_EVENT_FREERUNNING; 2980 event->hw.flags |= PERF_X86_EVENT_LARGE_PEBS;
2981 } 2981 }
2982 if (x86_pmu.pebs_aliases) 2982 if (x86_pmu.pebs_aliases)
2983 x86_pmu.pebs_aliases(event); 2983 x86_pmu.pebs_aliases(event);
@@ -3194,7 +3194,7 @@ static unsigned bdw_limit_period(struct perf_event *event, unsigned left)
3194 X86_CONFIG(.event=0xc0, .umask=0x01)) { 3194 X86_CONFIG(.event=0xc0, .umask=0x01)) {
3195 if (left < 128) 3195 if (left < 128)
3196 left = 128; 3196 left = 128;
3197 left &= ~0x3fu; 3197 left &= ~0x3fULL;
3198 } 3198 }
3199 return left; 3199 return left;
3200} 3200}
@@ -3460,7 +3460,7 @@ static __initconst const struct x86_pmu core_pmu = {
3460 .event_map = intel_pmu_event_map, 3460 .event_map = intel_pmu_event_map,
3461 .max_events = ARRAY_SIZE(intel_perfmon_event_map), 3461 .max_events = ARRAY_SIZE(intel_perfmon_event_map),
3462 .apic = 1, 3462 .apic = 1,
3463 .free_running_flags = PEBS_FREERUNNING_FLAGS, 3463 .large_pebs_flags = LARGE_PEBS_FLAGS,
3464 3464
3465 /* 3465 /*
3466 * Intel PMCs cannot be accessed sanely above 32-bit width, 3466 * Intel PMCs cannot be accessed sanely above 32-bit width,
@@ -3502,7 +3502,7 @@ static __initconst const struct x86_pmu intel_pmu = {
3502 .event_map = intel_pmu_event_map, 3502 .event_map = intel_pmu_event_map,
3503 .max_events = ARRAY_SIZE(intel_perfmon_event_map), 3503 .max_events = ARRAY_SIZE(intel_perfmon_event_map),
3504 .apic = 1, 3504 .apic = 1,
3505 .free_running_flags = PEBS_FREERUNNING_FLAGS, 3505 .large_pebs_flags = LARGE_PEBS_FLAGS,
3506 /* 3506 /*
3507 * Intel PMCs cannot be accessed sanely above 32 bit width, 3507 * Intel PMCs cannot be accessed sanely above 32 bit width,
3508 * so we install an artificial 1<<31 period regardless of 3508 * so we install an artificial 1<<31 period regardless of
@@ -3559,7 +3559,7 @@ static int intel_snb_pebs_broken(int cpu)
3559 break; 3559 break;
3560 3560
3561 case INTEL_FAM6_SANDYBRIDGE_X: 3561 case INTEL_FAM6_SANDYBRIDGE_X:
3562 switch (cpu_data(cpu).x86_mask) { 3562 switch (cpu_data(cpu).x86_stepping) {
3563 case 6: rev = 0x618; break; 3563 case 6: rev = 0x618; break;
3564 case 7: rev = 0x70c; break; 3564 case 7: rev = 0x70c; break;
3565 } 3565 }
diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
index 18c25ab28557..d8015235ba76 100644
--- a/arch/x86/events/intel/ds.c
+++ b/arch/x86/events/intel/ds.c
@@ -935,7 +935,7 @@ void intel_pmu_pebs_add(struct perf_event *event)
935 bool needed_cb = pebs_needs_sched_cb(cpuc); 935 bool needed_cb = pebs_needs_sched_cb(cpuc);
936 936
937 cpuc->n_pebs++; 937 cpuc->n_pebs++;
938 if (hwc->flags & PERF_X86_EVENT_FREERUNNING) 938 if (hwc->flags & PERF_X86_EVENT_LARGE_PEBS)
939 cpuc->n_large_pebs++; 939 cpuc->n_large_pebs++;
940 940
941 pebs_update_state(needed_cb, cpuc, event->ctx->pmu); 941 pebs_update_state(needed_cb, cpuc, event->ctx->pmu);
@@ -975,7 +975,7 @@ void intel_pmu_pebs_del(struct perf_event *event)
975 bool needed_cb = pebs_needs_sched_cb(cpuc); 975 bool needed_cb = pebs_needs_sched_cb(cpuc);
976 976
977 cpuc->n_pebs--; 977 cpuc->n_pebs--;
978 if (hwc->flags & PERF_X86_EVENT_FREERUNNING) 978 if (hwc->flags & PERF_X86_EVENT_LARGE_PEBS)
979 cpuc->n_large_pebs--; 979 cpuc->n_large_pebs--;
980 980
981 pebs_update_state(needed_cb, cpuc, event->ctx->pmu); 981 pebs_update_state(needed_cb, cpuc, event->ctx->pmu);
@@ -1530,7 +1530,7 @@ void __init intel_ds_init(void)
1530 x86_pmu.pebs_record_size = 1530 x86_pmu.pebs_record_size =
1531 sizeof(struct pebs_record_skl); 1531 sizeof(struct pebs_record_skl);
1532 x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm; 1532 x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm;
1533 x86_pmu.free_running_flags |= PERF_SAMPLE_TIME; 1533 x86_pmu.large_pebs_flags |= PERF_SAMPLE_TIME;
1534 break; 1534 break;
1535 1535
1536 default: 1536 default:
diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
index ae64d0b69729..cf372b90557e 100644
--- a/arch/x86/events/intel/lbr.c
+++ b/arch/x86/events/intel/lbr.c
@@ -1186,7 +1186,7 @@ void __init intel_pmu_lbr_init_atom(void)
1186 * on PMU interrupt 1186 * on PMU interrupt
1187 */ 1187 */
1188 if (boot_cpu_data.x86_model == 28 1188 if (boot_cpu_data.x86_model == 28
1189 && boot_cpu_data.x86_mask < 10) { 1189 && boot_cpu_data.x86_stepping < 10) {
1190 pr_cont("LBR disabled due to erratum"); 1190 pr_cont("LBR disabled due to erratum");
1191 return; 1191 return;
1192 } 1192 }
diff --git a/arch/x86/events/intel/p6.c b/arch/x86/events/intel/p6.c
index a5604c352930..408879b0c0d4 100644
--- a/arch/x86/events/intel/p6.c
+++ b/arch/x86/events/intel/p6.c
@@ -234,7 +234,7 @@ static __initconst const struct x86_pmu p6_pmu = {
234 234
235static __init void p6_pmu_rdpmc_quirk(void) 235static __init void p6_pmu_rdpmc_quirk(void)
236{ 236{
237 if (boot_cpu_data.x86_mask < 9) { 237 if (boot_cpu_data.x86_stepping < 9) {
238 /* 238 /*
239 * PPro erratum 26; fixed in stepping 9 and above. 239 * PPro erratum 26; fixed in stepping 9 and above.
240 */ 240 */
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 6d8044ab1060..c98b943e58b4 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -3343,6 +3343,7 @@ static struct extra_reg skx_uncore_cha_extra_regs[] = {
3343 SNBEP_CBO_EVENT_EXTRA_REG(0x9134, 0xffff, 0x4), 3343 SNBEP_CBO_EVENT_EXTRA_REG(0x9134, 0xffff, 0x4),
3344 SNBEP_CBO_EVENT_EXTRA_REG(0x35, 0xff, 0x8), 3344 SNBEP_CBO_EVENT_EXTRA_REG(0x35, 0xff, 0x8),
3345 SNBEP_CBO_EVENT_EXTRA_REG(0x36, 0xff, 0x8), 3345 SNBEP_CBO_EVENT_EXTRA_REG(0x36, 0xff, 0x8),
3346 SNBEP_CBO_EVENT_EXTRA_REG(0x38, 0xff, 0x3),
3346 EVENT_EXTRA_END 3347 EVENT_EXTRA_END
3347}; 3348};
3348 3349
@@ -3562,24 +3563,27 @@ static struct intel_uncore_type *skx_msr_uncores[] = {
3562 NULL, 3563 NULL,
3563}; 3564};
3564 3565
3566/*
3567 * To determine the number of CHAs, it should read bits 27:0 in the CAPID6
3568 * register which located at Device 30, Function 3, Offset 0x9C. PCI ID 0x2083.
3569 */
3570#define SKX_CAPID6 0x9c
3571#define SKX_CHA_BIT_MASK GENMASK(27, 0)
3572
3565static int skx_count_chabox(void) 3573static int skx_count_chabox(void)
3566{ 3574{
3567 struct pci_dev *chabox_dev = NULL; 3575 struct pci_dev *dev = NULL;
3568 int bus, count = 0; 3576 u32 val = 0;
3569 3577
3570 while (1) { 3578 dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2083, dev);
3571 chabox_dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x208d, chabox_dev); 3579 if (!dev)
3572 if (!chabox_dev) 3580 goto out;
3573 break;
3574 if (count == 0)
3575 bus = chabox_dev->bus->number;
3576 if (bus != chabox_dev->bus->number)
3577 break;
3578 count++;
3579 }
3580 3581
3581 pci_dev_put(chabox_dev); 3582 pci_read_config_dword(dev, SKX_CAPID6, &val);
3582 return count; 3583 val &= SKX_CHA_BIT_MASK;
3584out:
3585 pci_dev_put(dev);
3586 return hweight32(val);
3583} 3587}
3584 3588
3585void skx_uncore_cpu_init(void) 3589void skx_uncore_cpu_init(void)
@@ -3606,7 +3610,7 @@ static struct intel_uncore_type skx_uncore_imc = {
3606}; 3610};
3607 3611
3608static struct attribute *skx_upi_uncore_formats_attr[] = { 3612static struct attribute *skx_upi_uncore_formats_attr[] = {
3609 &format_attr_event_ext.attr, 3613 &format_attr_event.attr,
3610 &format_attr_umask_ext.attr, 3614 &format_attr_umask_ext.attr,
3611 &format_attr_edge.attr, 3615 &format_attr_edge.attr,
3612 &format_attr_inv.attr, 3616 &format_attr_inv.attr,
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 78f91ec1056e..39cd0615f04f 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -69,7 +69,7 @@ struct event_constraint {
69#define PERF_X86_EVENT_RDPMC_ALLOWED 0x0100 /* grant rdpmc permission */ 69#define PERF_X86_EVENT_RDPMC_ALLOWED 0x0100 /* grant rdpmc permission */
70#define PERF_X86_EVENT_EXCL_ACCT 0x0200 /* accounted EXCL event */ 70#define PERF_X86_EVENT_EXCL_ACCT 0x0200 /* accounted EXCL event */
71#define PERF_X86_EVENT_AUTO_RELOAD 0x0400 /* use PEBS auto-reload */ 71#define PERF_X86_EVENT_AUTO_RELOAD 0x0400 /* use PEBS auto-reload */
72#define PERF_X86_EVENT_FREERUNNING 0x0800 /* use freerunning PEBS */ 72#define PERF_X86_EVENT_LARGE_PEBS 0x0800 /* use large PEBS */
73 73
74 74
75struct amd_nb { 75struct amd_nb {
@@ -88,7 +88,7 @@ struct amd_nb {
88 * REGS_USER can be handled for events limited to ring 3. 88 * REGS_USER can be handled for events limited to ring 3.
89 * 89 *
90 */ 90 */
91#define PEBS_FREERUNNING_FLAGS \ 91#define LARGE_PEBS_FLAGS \
92 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_ADDR | \ 92 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_ADDR | \
93 PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_STREAM_ID | \ 93 PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_STREAM_ID | \
94 PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_IDENTIFIER | \ 94 PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_IDENTIFIER | \
@@ -608,7 +608,7 @@ struct x86_pmu {
608 struct event_constraint *pebs_constraints; 608 struct event_constraint *pebs_constraints;
609 void (*pebs_aliases)(struct perf_event *event); 609 void (*pebs_aliases)(struct perf_event *event);
610 int max_pebs_events; 610 int max_pebs_events;
611 unsigned long free_running_flags; 611 unsigned long large_pebs_flags;
612 612
613 /* 613 /*
614 * Intel LBR 614 * Intel LBR
diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
index 96cd33bbfc85..6512498bbef6 100644
--- a/arch/x86/ia32/sys_ia32.c
+++ b/arch/x86/ia32/sys_ia32.c
@@ -51,15 +51,14 @@
51#define AA(__x) ((unsigned long)(__x)) 51#define AA(__x) ((unsigned long)(__x))
52 52
53 53
54asmlinkage long sys32_truncate64(const char __user *filename, 54COMPAT_SYSCALL_DEFINE3(x86_truncate64, const char __user *, filename,
55 unsigned long offset_low, 55 unsigned long, offset_low, unsigned long, offset_high)
56 unsigned long offset_high)
57{ 56{
58 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low); 57 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
59} 58}
60 59
61asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low, 60COMPAT_SYSCALL_DEFINE3(x86_ftruncate64, unsigned int, fd,
62 unsigned long offset_high) 61 unsigned long, offset_low, unsigned long, offset_high)
63{ 62{
64 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low); 63 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
65} 64}
@@ -96,8 +95,8 @@ static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
96 return 0; 95 return 0;
97} 96}
98 97
99asmlinkage long sys32_stat64(const char __user *filename, 98COMPAT_SYSCALL_DEFINE2(x86_stat64, const char __user *, filename,
100 struct stat64 __user *statbuf) 99 struct stat64 __user *, statbuf)
101{ 100{
102 struct kstat stat; 101 struct kstat stat;
103 int ret = vfs_stat(filename, &stat); 102 int ret = vfs_stat(filename, &stat);
@@ -107,8 +106,8 @@ asmlinkage long sys32_stat64(const char __user *filename,
107 return ret; 106 return ret;
108} 107}
109 108
110asmlinkage long sys32_lstat64(const char __user *filename, 109COMPAT_SYSCALL_DEFINE2(x86_lstat64, const char __user *, filename,
111 struct stat64 __user *statbuf) 110 struct stat64 __user *, statbuf)
112{ 111{
113 struct kstat stat; 112 struct kstat stat;
114 int ret = vfs_lstat(filename, &stat); 113 int ret = vfs_lstat(filename, &stat);
@@ -117,7 +116,8 @@ asmlinkage long sys32_lstat64(const char __user *filename,
117 return ret; 116 return ret;
118} 117}
119 118
120asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf) 119COMPAT_SYSCALL_DEFINE2(x86_fstat64, unsigned int, fd,
120 struct stat64 __user *, statbuf)
121{ 121{
122 struct kstat stat; 122 struct kstat stat;
123 int ret = vfs_fstat(fd, &stat); 123 int ret = vfs_fstat(fd, &stat);
@@ -126,8 +126,9 @@ asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
126 return ret; 126 return ret;
127} 127}
128 128
129asmlinkage long sys32_fstatat(unsigned int dfd, const char __user *filename, 129COMPAT_SYSCALL_DEFINE4(x86_fstatat, unsigned int, dfd,
130 struct stat64 __user *statbuf, int flag) 130 const char __user *, filename,
131 struct stat64 __user *, statbuf, int, flag)
131{ 132{
132 struct kstat stat; 133 struct kstat stat;
133 int error; 134 int error;
@@ -153,7 +154,7 @@ struct mmap_arg_struct32 {
153 unsigned int offset; 154 unsigned int offset;
154}; 155};
155 156
156asmlinkage long sys32_mmap(struct mmap_arg_struct32 __user *arg) 157COMPAT_SYSCALL_DEFINE1(x86_mmap, struct mmap_arg_struct32 __user *, arg)
157{ 158{
158 struct mmap_arg_struct32 a; 159 struct mmap_arg_struct32 a;
159 160
@@ -167,22 +168,22 @@ asmlinkage long sys32_mmap(struct mmap_arg_struct32 __user *arg)
167 a.offset>>PAGE_SHIFT); 168 a.offset>>PAGE_SHIFT);
168} 169}
169 170
170asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr, 171COMPAT_SYSCALL_DEFINE3(x86_waitpid, compat_pid_t, pid, unsigned int __user *,
171 int options) 172 stat_addr, int, options)
172{ 173{
173 return compat_sys_wait4(pid, stat_addr, options, NULL); 174 return compat_sys_wait4(pid, stat_addr, options, NULL);
174} 175}
175 176
176/* warning: next two assume little endian */ 177/* warning: next two assume little endian */
177asmlinkage long sys32_pread(unsigned int fd, char __user *ubuf, u32 count, 178COMPAT_SYSCALL_DEFINE5(x86_pread, unsigned int, fd, char __user *, ubuf,
178 u32 poslo, u32 poshi) 179 u32, count, u32, poslo, u32, poshi)
179{ 180{
180 return sys_pread64(fd, ubuf, count, 181 return sys_pread64(fd, ubuf, count,
181 ((loff_t)AA(poshi) << 32) | AA(poslo)); 182 ((loff_t)AA(poshi) << 32) | AA(poslo));
182} 183}
183 184
184asmlinkage long sys32_pwrite(unsigned int fd, const char __user *ubuf, 185COMPAT_SYSCALL_DEFINE5(x86_pwrite, unsigned int, fd, const char __user *, ubuf,
185 u32 count, u32 poslo, u32 poshi) 186 u32, count, u32, poslo, u32, poshi)
186{ 187{
187 return sys_pwrite64(fd, ubuf, count, 188 return sys_pwrite64(fd, ubuf, count,
188 ((loff_t)AA(poshi) << 32) | AA(poslo)); 189 ((loff_t)AA(poshi) << 32) | AA(poslo));
@@ -193,8 +194,9 @@ asmlinkage long sys32_pwrite(unsigned int fd, const char __user *ubuf,
193 * Some system calls that need sign extended arguments. This could be 194 * Some system calls that need sign extended arguments. This could be
194 * done by a generic wrapper. 195 * done by a generic wrapper.
195 */ 196 */
196long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high, 197COMPAT_SYSCALL_DEFINE6(x86_fadvise64_64, int, fd, __u32, offset_low,
197 __u32 len_low, __u32 len_high, int advice) 198 __u32, offset_high, __u32, len_low, __u32, len_high,
199 int, advice)
198{ 200{
199 return sys_fadvise64_64(fd, 201 return sys_fadvise64_64(fd,
200 (((u64)offset_high)<<32) | offset_low, 202 (((u64)offset_high)<<32) | offset_low,
@@ -202,31 +204,43 @@ long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
202 advice); 204 advice);
203} 205}
204 206
205asmlinkage ssize_t sys32_readahead(int fd, unsigned off_lo, unsigned off_hi, 207COMPAT_SYSCALL_DEFINE4(x86_readahead, int, fd, unsigned int, off_lo,
206 size_t count) 208 unsigned int, off_hi, size_t, count)
207{ 209{
208 return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count); 210 return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
209} 211}
210 212
211asmlinkage long sys32_sync_file_range(int fd, unsigned off_low, unsigned off_hi, 213COMPAT_SYSCALL_DEFINE6(x86_sync_file_range, int, fd, unsigned int, off_low,
212 unsigned n_low, unsigned n_hi, int flags) 214 unsigned int, off_hi, unsigned int, n_low,
215 unsigned int, n_hi, int, flags)
213{ 216{
214 return sys_sync_file_range(fd, 217 return sys_sync_file_range(fd,
215 ((u64)off_hi << 32) | off_low, 218 ((u64)off_hi << 32) | off_low,
216 ((u64)n_hi << 32) | n_low, flags); 219 ((u64)n_hi << 32) | n_low, flags);
217} 220}
218 221
219asmlinkage long sys32_fadvise64(int fd, unsigned offset_lo, unsigned offset_hi, 222COMPAT_SYSCALL_DEFINE5(x86_fadvise64, int, fd, unsigned int, offset_lo,
220 size_t len, int advice) 223 unsigned int, offset_hi, size_t, len, int, advice)
221{ 224{
222 return sys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo, 225 return sys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
223 len, advice); 226 len, advice);
224} 227}
225 228
226asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_lo, 229COMPAT_SYSCALL_DEFINE6(x86_fallocate, int, fd, int, mode,
227 unsigned offset_hi, unsigned len_lo, 230 unsigned int, offset_lo, unsigned int, offset_hi,
228 unsigned len_hi) 231 unsigned int, len_lo, unsigned int, len_hi)
229{ 232{
230 return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo, 233 return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
231 ((u64)len_hi << 32) | len_lo); 234 ((u64)len_hi << 32) | len_lo);
232} 235}
236
237/*
238 * The 32-bit clone ABI is CONFIG_CLONE_BACKWARDS
239 */
240COMPAT_SYSCALL_DEFINE5(x86_clone, unsigned long, clone_flags,
241 unsigned long, newsp, int __user *, parent_tidptr,
242 unsigned long, tls_val, int __user *, child_tidptr)
243{
244 return sys_clone(clone_flags, newsp, parent_tidptr, child_tidptr,
245 tls_val);
246}
diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h
index 44f5d79d5105..11881726ed37 100644
--- a/arch/x86/include/asm/acpi.h
+++ b/arch/x86/include/asm/acpi.h
@@ -94,7 +94,7 @@ static inline unsigned int acpi_processor_cstate_check(unsigned int max_cstate)
94 if (boot_cpu_data.x86 == 0x0F && 94 if (boot_cpu_data.x86 == 0x0F &&
95 boot_cpu_data.x86_vendor == X86_VENDOR_AMD && 95 boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
96 boot_cpu_data.x86_model <= 0x05 && 96 boot_cpu_data.x86_model <= 0x05 &&
97 boot_cpu_data.x86_mask < 0x0A) 97 boot_cpu_data.x86_stepping < 0x0A)
98 return 1; 98 return 1;
99 else if (boot_cpu_has(X86_BUG_AMD_APIC_C1E)) 99 else if (boot_cpu_has(X86_BUG_AMD_APIC_C1E))
100 return 1; 100 return 1;
diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
index 4d4015ddcf26..c356098b6fb9 100644
--- a/arch/x86/include/asm/apm.h
+++ b/arch/x86/include/asm/apm.h
@@ -7,6 +7,8 @@
7#ifndef _ASM_X86_MACH_DEFAULT_APM_H 7#ifndef _ASM_X86_MACH_DEFAULT_APM_H
8#define _ASM_X86_MACH_DEFAULT_APM_H 8#define _ASM_X86_MACH_DEFAULT_APM_H
9 9
10#include <asm/nospec-branch.h>
11
10#ifdef APM_ZERO_SEGS 12#ifdef APM_ZERO_SEGS
11# define APM_DO_ZERO_SEGS \ 13# define APM_DO_ZERO_SEGS \
12 "pushl %%ds\n\t" \ 14 "pushl %%ds\n\t" \
@@ -32,6 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
32 * N.B. We do NOT need a cld after the BIOS call 34 * N.B. We do NOT need a cld after the BIOS call
33 * because we always save and restore the flags. 35 * because we always save and restore the flags.
34 */ 36 */
37 firmware_restrict_branch_speculation_start();
35 __asm__ __volatile__(APM_DO_ZERO_SEGS 38 __asm__ __volatile__(APM_DO_ZERO_SEGS
36 "pushl %%edi\n\t" 39 "pushl %%edi\n\t"
37 "pushl %%ebp\n\t" 40 "pushl %%ebp\n\t"
@@ -44,6 +47,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
44 "=S" (*esi) 47 "=S" (*esi)
45 : "a" (func), "b" (ebx_in), "c" (ecx_in) 48 : "a" (func), "b" (ebx_in), "c" (ecx_in)
46 : "memory", "cc"); 49 : "memory", "cc");
50 firmware_restrict_branch_speculation_end();
47} 51}
48 52
49static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in, 53static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in,
@@ -56,6 +60,7 @@ static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in,
56 * N.B. We do NOT need a cld after the BIOS call 60 * N.B. We do NOT need a cld after the BIOS call
57 * because we always save and restore the flags. 61 * because we always save and restore the flags.
58 */ 62 */
63 firmware_restrict_branch_speculation_start();
59 __asm__ __volatile__(APM_DO_ZERO_SEGS 64 __asm__ __volatile__(APM_DO_ZERO_SEGS
60 "pushl %%edi\n\t" 65 "pushl %%edi\n\t"
61 "pushl %%ebp\n\t" 66 "pushl %%ebp\n\t"
@@ -68,6 +73,7 @@ static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in,
68 "=S" (si) 73 "=S" (si)
69 : "a" (func), "b" (ebx_in), "c" (ecx_in) 74 : "a" (func), "b" (ebx_in), "c" (ecx_in)
70 : "memory", "cc"); 75 : "memory", "cc");
76 firmware_restrict_branch_speculation_end();
71 return error; 77 return error;
72} 78}
73 79
diff --git a/arch/x86/include/asm/asm-prototypes.h b/arch/x86/include/asm/asm-prototypes.h
index 4d111616524b..1908214b9125 100644
--- a/arch/x86/include/asm/asm-prototypes.h
+++ b/arch/x86/include/asm/asm-prototypes.h
@@ -38,7 +38,4 @@ INDIRECT_THUNK(dx)
38INDIRECT_THUNK(si) 38INDIRECT_THUNK(si)
39INDIRECT_THUNK(di) 39INDIRECT_THUNK(di)
40INDIRECT_THUNK(bp) 40INDIRECT_THUNK(bp)
41asmlinkage void __fill_rsb(void);
42asmlinkage void __clear_rsb(void);
43
44#endif /* CONFIG_RETPOLINE */ 41#endif /* CONFIG_RETPOLINE */
diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
index 30d406146016..042b5e892ed1 100644
--- a/arch/x86/include/asm/barrier.h
+++ b/arch/x86/include/asm/barrier.h
@@ -40,7 +40,7 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,
40 40
41 asm ("cmp %1,%2; sbb %0,%0;" 41 asm ("cmp %1,%2; sbb %0,%0;"
42 :"=r" (mask) 42 :"=r" (mask)
43 :"r"(size),"r" (index) 43 :"g"(size),"r" (index)
44 :"cc"); 44 :"cc");
45 return mask; 45 return mask;
46} 46}
@@ -52,11 +52,7 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,
52#define barrier_nospec() alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC, \ 52#define barrier_nospec() alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC, \
53 "lfence", X86_FEATURE_LFENCE_RDTSC) 53 "lfence", X86_FEATURE_LFENCE_RDTSC)
54 54
55#ifdef CONFIG_X86_PPRO_FENCE
56#define dma_rmb() rmb()
57#else
58#define dma_rmb() barrier() 55#define dma_rmb() barrier()
59#endif
60#define dma_wmb() barrier() 56#define dma_wmb() barrier()
61 57
62#ifdef CONFIG_X86_32 58#ifdef CONFIG_X86_32
@@ -68,30 +64,6 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,
68#define __smp_wmb() barrier() 64#define __smp_wmb() barrier()
69#define __smp_store_mb(var, value) do { (void)xchg(&var, value); } while (0) 65#define __smp_store_mb(var, value) do { (void)xchg(&var, value); } while (0)
70 66
71#if defined(CONFIG_X86_PPRO_FENCE)
72
73/*
74 * For this option x86 doesn't have a strong TSO memory
75 * model and we should fall back to full barriers.
76 */
77
78#define __smp_store_release(p, v) \
79do { \
80 compiletime_assert_atomic_type(*p); \
81 __smp_mb(); \
82 WRITE_ONCE(*p, v); \
83} while (0)
84
85#define __smp_load_acquire(p) \
86({ \
87 typeof(*p) ___p1 = READ_ONCE(*p); \
88 compiletime_assert_atomic_type(*p); \
89 __smp_mb(); \
90 ___p1; \
91})
92
93#else /* regular x86 TSO memory ordering */
94
95#define __smp_store_release(p, v) \ 67#define __smp_store_release(p, v) \
96do { \ 68do { \
97 compiletime_assert_atomic_type(*p); \ 69 compiletime_assert_atomic_type(*p); \
@@ -107,8 +79,6 @@ do { \
107 ___p1; \ 79 ___p1; \
108}) 80})
109 81
110#endif
111
112/* Atomic operations are already serializing on x86 */ 82/* Atomic operations are already serializing on x86 */
113#define __smp_mb__before_atomic() barrier() 83#define __smp_mb__before_atomic() barrier()
114#define __smp_mb__after_atomic() barrier() 84#define __smp_mb__after_atomic() barrier()
diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
index 3fa039855b8f..9f645ba57dbb 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -78,7 +78,7 @@ set_bit(long nr, volatile unsigned long *addr)
78 : "iq" ((u8)CONST_MASK(nr)) 78 : "iq" ((u8)CONST_MASK(nr))
79 : "memory"); 79 : "memory");
80 } else { 80 } else {
81 asm volatile(LOCK_PREFIX "bts %1,%0" 81 asm volatile(LOCK_PREFIX __ASM_SIZE(bts) " %1,%0"
82 : BITOP_ADDR(addr) : "Ir" (nr) : "memory"); 82 : BITOP_ADDR(addr) : "Ir" (nr) : "memory");
83 } 83 }
84} 84}
@@ -94,7 +94,7 @@ set_bit(long nr, volatile unsigned long *addr)
94 */ 94 */
95static __always_inline void __set_bit(long nr, volatile unsigned long *addr) 95static __always_inline void __set_bit(long nr, volatile unsigned long *addr)
96{ 96{
97 asm volatile("bts %1,%0" : ADDR : "Ir" (nr) : "memory"); 97 asm volatile(__ASM_SIZE(bts) " %1,%0" : ADDR : "Ir" (nr) : "memory");
98} 98}
99 99
100/** 100/**
@@ -115,7 +115,7 @@ clear_bit(long nr, volatile unsigned long *addr)
115 : CONST_MASK_ADDR(nr, addr) 115 : CONST_MASK_ADDR(nr, addr)
116 : "iq" ((u8)~CONST_MASK(nr))); 116 : "iq" ((u8)~CONST_MASK(nr)));
117 } else { 117 } else {
118 asm volatile(LOCK_PREFIX "btr %1,%0" 118 asm volatile(LOCK_PREFIX __ASM_SIZE(btr) " %1,%0"
119 : BITOP_ADDR(addr) 119 : BITOP_ADDR(addr)
120 : "Ir" (nr)); 120 : "Ir" (nr));
121 } 121 }
@@ -137,7 +137,7 @@ static __always_inline void clear_bit_unlock(long nr, volatile unsigned long *ad
137 137
138static __always_inline void __clear_bit(long nr, volatile unsigned long *addr) 138static __always_inline void __clear_bit(long nr, volatile unsigned long *addr)
139{ 139{
140 asm volatile("btr %1,%0" : ADDR : "Ir" (nr)); 140 asm volatile(__ASM_SIZE(btr) " %1,%0" : ADDR : "Ir" (nr));
141} 141}
142 142
143static __always_inline bool clear_bit_unlock_is_negative_byte(long nr, volatile unsigned long *addr) 143static __always_inline bool clear_bit_unlock_is_negative_byte(long nr, volatile unsigned long *addr)
@@ -182,7 +182,7 @@ static __always_inline void __clear_bit_unlock(long nr, volatile unsigned long *
182 */ 182 */
183static __always_inline void __change_bit(long nr, volatile unsigned long *addr) 183static __always_inline void __change_bit(long nr, volatile unsigned long *addr)
184{ 184{
185 asm volatile("btc %1,%0" : ADDR : "Ir" (nr)); 185 asm volatile(__ASM_SIZE(btc) " %1,%0" : ADDR : "Ir" (nr));
186} 186}
187 187
188/** 188/**
@@ -201,7 +201,7 @@ static __always_inline void change_bit(long nr, volatile unsigned long *addr)
201 : CONST_MASK_ADDR(nr, addr) 201 : CONST_MASK_ADDR(nr, addr)
202 : "iq" ((u8)CONST_MASK(nr))); 202 : "iq" ((u8)CONST_MASK(nr)));
203 } else { 203 } else {
204 asm volatile(LOCK_PREFIX "btc %1,%0" 204 asm volatile(LOCK_PREFIX __ASM_SIZE(btc) " %1,%0"
205 : BITOP_ADDR(addr) 205 : BITOP_ADDR(addr)
206 : "Ir" (nr)); 206 : "Ir" (nr));
207 } 207 }
@@ -217,7 +217,8 @@ static __always_inline void change_bit(long nr, volatile unsigned long *addr)
217 */ 217 */
218static __always_inline bool test_and_set_bit(long nr, volatile unsigned long *addr) 218static __always_inline bool test_and_set_bit(long nr, volatile unsigned long *addr)
219{ 219{
220 GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", c); 220 GEN_BINARY_RMWcc(LOCK_PREFIX __ASM_SIZE(bts),
221 *addr, "Ir", nr, "%0", c);
221} 222}
222 223
223/** 224/**
@@ -246,7 +247,7 @@ static __always_inline bool __test_and_set_bit(long nr, volatile unsigned long *
246{ 247{
247 bool oldbit; 248 bool oldbit;
248 249
249 asm("bts %2,%1" 250 asm(__ASM_SIZE(bts) " %2,%1"
250 CC_SET(c) 251 CC_SET(c)
251 : CC_OUT(c) (oldbit), ADDR 252 : CC_OUT(c) (oldbit), ADDR
252 : "Ir" (nr)); 253 : "Ir" (nr));
@@ -263,7 +264,8 @@ static __always_inline bool __test_and_set_bit(long nr, volatile unsigned long *
263 */ 264 */
264static __always_inline bool test_and_clear_bit(long nr, volatile unsigned long *addr) 265static __always_inline bool test_and_clear_bit(long nr, volatile unsigned long *addr)
265{ 266{
266 GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", c); 267 GEN_BINARY_RMWcc(LOCK_PREFIX __ASM_SIZE(btr),
268 *addr, "Ir", nr, "%0", c);
267} 269}
268 270
269/** 271/**
@@ -286,7 +288,7 @@ static __always_inline bool __test_and_clear_bit(long nr, volatile unsigned long
286{ 288{
287 bool oldbit; 289 bool oldbit;
288 290
289 asm volatile("btr %2,%1" 291 asm volatile(__ASM_SIZE(btr) " %2,%1"
290 CC_SET(c) 292 CC_SET(c)
291 : CC_OUT(c) (oldbit), ADDR 293 : CC_OUT(c) (oldbit), ADDR
292 : "Ir" (nr)); 294 : "Ir" (nr));
@@ -298,7 +300,7 @@ static __always_inline bool __test_and_change_bit(long nr, volatile unsigned lon
298{ 300{
299 bool oldbit; 301 bool oldbit;
300 302
301 asm volatile("btc %2,%1" 303 asm volatile(__ASM_SIZE(btc) " %2,%1"
302 CC_SET(c) 304 CC_SET(c)
303 : CC_OUT(c) (oldbit), ADDR 305 : CC_OUT(c) (oldbit), ADDR
304 : "Ir" (nr) : "memory"); 306 : "Ir" (nr) : "memory");
@@ -316,7 +318,8 @@ static __always_inline bool __test_and_change_bit(long nr, volatile unsigned lon
316 */ 318 */
317static __always_inline bool test_and_change_bit(long nr, volatile unsigned long *addr) 319static __always_inline bool test_and_change_bit(long nr, volatile unsigned long *addr)
318{ 320{
319 GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", c); 321 GEN_BINARY_RMWcc(LOCK_PREFIX __ASM_SIZE(btc),
322 *addr, "Ir", nr, "%0", c);
320} 323}
321 324
322static __always_inline bool constant_test_bit(long nr, const volatile unsigned long *addr) 325static __always_inline bool constant_test_bit(long nr, const volatile unsigned long *addr)
@@ -329,7 +332,7 @@ static __always_inline bool variable_test_bit(long nr, volatile const unsigned l
329{ 332{
330 bool oldbit; 333 bool oldbit;
331 334
332 asm volatile("bt %2,%1" 335 asm volatile(__ASM_SIZE(bt) " %2,%1"
333 CC_SET(c) 336 CC_SET(c)
334 : CC_OUT(c) (oldbit) 337 : CC_OUT(c) (oldbit)
335 : "m" (*(unsigned long *)addr), "Ir" (nr)); 338 : "m" (*(unsigned long *)addr), "Ir" (nr));
diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h
index 34d99af43994..6804d6642767 100644
--- a/arch/x86/include/asm/bug.h
+++ b/arch/x86/include/asm/bug.h
@@ -5,23 +5,20 @@
5#include <linux/stringify.h> 5#include <linux/stringify.h>
6 6
7/* 7/*
8 * Since some emulators terminate on UD2, we cannot use it for WARN. 8 * Despite that some emulators terminate on UD2, we use it for WARN().
9 * Since various instruction decoders disagree on the length of UD1,
10 * we cannot use it either. So use UD0 for WARN.
11 * 9 *
12 * (binutils knows about "ud1" but {en,de}codes it as 2 bytes, whereas 10 * Since various instruction decoders/specs disagree on the encoding of
13 * our kernel decoder thinks it takes a ModRM byte, which seems consistent 11 * UD0/UD1.
14 * with various things like the Intel SDM instruction encoding rules)
15 */ 12 */
16 13
17#define ASM_UD0 ".byte 0x0f, 0xff" 14#define ASM_UD0 ".byte 0x0f, 0xff" /* + ModRM (for Intel) */
18#define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */ 15#define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */
19#define ASM_UD2 ".byte 0x0f, 0x0b" 16#define ASM_UD2 ".byte 0x0f, 0x0b"
20 17
21#define INSN_UD0 0xff0f 18#define INSN_UD0 0xff0f
22#define INSN_UD2 0x0b0f 19#define INSN_UD2 0x0b0f
23 20
24#define LEN_UD0 2 21#define LEN_UD2 2
25 22
26#ifdef CONFIG_GENERIC_BUG 23#ifdef CONFIG_GENERIC_BUG
27 24
@@ -77,7 +74,11 @@ do { \
77 unreachable(); \ 74 unreachable(); \
78} while (0) 75} while (0)
79 76
80#define __WARN_FLAGS(flags) _BUG_FLAGS(ASM_UD0, BUGFLAG_WARNING|(flags)) 77#define __WARN_FLAGS(flags) \
78do { \
79 _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
80 annotate_reachable(); \
81} while (0)
81 82
82#include <asm-generic/bug.h> 83#include <asm-generic/bug.h>
83 84
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 70eddb3922ff..736771c9822e 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -148,45 +148,46 @@ extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
148 */ 148 */
149static __always_inline __pure bool _static_cpu_has(u16 bit) 149static __always_inline __pure bool _static_cpu_has(u16 bit)
150{ 150{
151 asm_volatile_goto("1: jmp 6f\n" 151 asm_volatile_goto("1: jmp 6f\n"
152 "2:\n" 152 "2:\n"
153 ".skip -(((5f-4f) - (2b-1b)) > 0) * " 153 ".skip -(((5f-4f) - (2b-1b)) > 0) * "
154 "((5f-4f) - (2b-1b)),0x90\n" 154 "((5f-4f) - (2b-1b)),0x90\n"
155 "3:\n" 155 "3:\n"
156 ".section .altinstructions,\"a\"\n" 156 ".section .altinstructions,\"a\"\n"
157 " .long 1b - .\n" /* src offset */ 157 " .long 1b - .\n" /* src offset */
158 " .long 4f - .\n" /* repl offset */ 158 " .long 4f - .\n" /* repl offset */
159 " .word %P1\n" /* always replace */ 159 " .word %P[always]\n" /* always replace */
160 " .byte 3b - 1b\n" /* src len */ 160 " .byte 3b - 1b\n" /* src len */
161 " .byte 5f - 4f\n" /* repl len */ 161 " .byte 5f - 4f\n" /* repl len */
162 " .byte 3b - 2b\n" /* pad len */ 162 " .byte 3b - 2b\n" /* pad len */
163 ".previous\n" 163 ".previous\n"
164 ".section .altinstr_replacement,\"ax\"\n" 164 ".section .altinstr_replacement,\"ax\"\n"
165 "4: jmp %l[t_no]\n" 165 "4: jmp %l[t_no]\n"
166 "5:\n" 166 "5:\n"
167 ".previous\n" 167 ".previous\n"
168 ".section .altinstructions,\"a\"\n" 168 ".section .altinstructions,\"a\"\n"
169 " .long 1b - .\n" /* src offset */ 169 " .long 1b - .\n" /* src offset */
170 " .long 0\n" /* no replacement */ 170 " .long 0\n" /* no replacement */
171 " .word %P0\n" /* feature bit */ 171 " .word %P[feature]\n" /* feature bit */
172 " .byte 3b - 1b\n" /* src len */ 172 " .byte 3b - 1b\n" /* src len */
173 " .byte 0\n" /* repl len */ 173 " .byte 0\n" /* repl len */
174 " .byte 0\n" /* pad len */ 174 " .byte 0\n" /* pad len */
175 ".previous\n" 175 ".previous\n"
176 ".section .altinstr_aux,\"ax\"\n" 176 ".section .altinstr_aux,\"ax\"\n"
177 "6:\n" 177 "6:\n"
178 " testb %[bitnum],%[cap_byte]\n" 178 " testb %[bitnum],%[cap_byte]\n"
179 " jnz %l[t_yes]\n" 179 " jnz %l[t_yes]\n"
180 " jmp %l[t_no]\n" 180 " jmp %l[t_no]\n"
181 ".previous\n" 181 ".previous\n"
182 : : "i" (bit), "i" (X86_FEATURE_ALWAYS), 182 : : [feature] "i" (bit),
183 [bitnum] "i" (1 << (bit & 7)), 183 [always] "i" (X86_FEATURE_ALWAYS),
184 [cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3]) 184 [bitnum] "i" (1 << (bit & 7)),
185 : : t_yes, t_no); 185 [cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
186 t_yes: 186 : : t_yes, t_no);
187 return true; 187t_yes:
188 t_no: 188 return true;
189 return false; 189t_no:
190 return false;
190} 191}
191 192
192#define static_cpu_has(bit) \ 193#define static_cpu_has(bit) \
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 0dfe4d3f74e2..d554c11e01ff 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -213,6 +213,7 @@
213#define X86_FEATURE_SEV ( 7*32+20) /* AMD Secure Encrypted Virtualization */ 213#define X86_FEATURE_SEV ( 7*32+20) /* AMD Secure Encrypted Virtualization */
214 214
215#define X86_FEATURE_USE_IBPB ( 7*32+21) /* "" Indirect Branch Prediction Barrier enabled */ 215#define X86_FEATURE_USE_IBPB ( 7*32+21) /* "" Indirect Branch Prediction Barrier enabled */
216#define X86_FEATURE_USE_IBRS_FW ( 7*32+22) /* "" Use IBRS during runtime firmware calls */
216 217
217/* Virtualization flags: Linux defined, word 8 */ 218/* Virtualization flags: Linux defined, word 8 */
218#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ 219#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */
@@ -315,6 +316,7 @@
315#define X86_FEATURE_VPCLMULQDQ (16*32+10) /* Carry-Less Multiplication Double Quadword */ 316#define X86_FEATURE_VPCLMULQDQ (16*32+10) /* Carry-Less Multiplication Double Quadword */
316#define X86_FEATURE_AVX512_VNNI (16*32+11) /* Vector Neural Network Instructions */ 317#define X86_FEATURE_AVX512_VNNI (16*32+11) /* Vector Neural Network Instructions */
317#define X86_FEATURE_AVX512_BITALG (16*32+12) /* Support for VPOPCNT[B,W] and VPSHUF-BITQMB instructions */ 318#define X86_FEATURE_AVX512_BITALG (16*32+12) /* Support for VPOPCNT[B,W] and VPSHUF-BITQMB instructions */
319#define X86_FEATURE_TME (16*32+13) /* Intel Total Memory Encryption */
318#define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors of DW/QW */ 320#define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors of DW/QW */
319#define X86_FEATURE_LA57 (16*32+16) /* 5-level page tables */ 321#define X86_FEATURE_LA57 (16*32+16) /* 5-level page tables */
320#define X86_FEATURE_RDPID (16*32+22) /* RDPID instruction */ 322#define X86_FEATURE_RDPID (16*32+22) /* RDPID instruction */
@@ -327,6 +329,7 @@
327/* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */ 329/* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */
328#define X86_FEATURE_AVX512_4VNNIW (18*32+ 2) /* AVX-512 Neural Network Instructions */ 330#define X86_FEATURE_AVX512_4VNNIW (18*32+ 2) /* AVX-512 Neural Network Instructions */
329#define X86_FEATURE_AVX512_4FMAPS (18*32+ 3) /* AVX-512 Multiply Accumulation Single precision */ 331#define X86_FEATURE_AVX512_4FMAPS (18*32+ 3) /* AVX-512 Multiply Accumulation Single precision */
332#define X86_FEATURE_PCONFIG (18*32+18) /* Intel PCONFIG */
330#define X86_FEATURE_SPEC_CTRL (18*32+26) /* "" Speculation Control (IBRS + IBPB) */ 333#define X86_FEATURE_SPEC_CTRL (18*32+26) /* "" Speculation Control (IBRS + IBPB) */
331#define X86_FEATURE_INTEL_STIBP (18*32+27) /* "" Single Thread Indirect Branch Predictors */ 334#define X86_FEATURE_INTEL_STIBP (18*32+27) /* "" Single Thread Indirect Branch Predictors */
332#define X86_FEATURE_ARCH_CAPABILITIES (18*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */ 335#define X86_FEATURE_ARCH_CAPABILITIES (18*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */
diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 85f6ccb80b91..a399c1ebf6f0 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -6,6 +6,7 @@
6#include <asm/pgtable.h> 6#include <asm/pgtable.h>
7#include <asm/processor-flags.h> 7#include <asm/processor-flags.h>
8#include <asm/tlb.h> 8#include <asm/tlb.h>
9#include <asm/nospec-branch.h>
9 10
10/* 11/*
11 * We map the EFI regions needed for runtime services non-contiguously, 12 * We map the EFI regions needed for runtime services non-contiguously,
@@ -36,8 +37,18 @@
36 37
37extern asmlinkage unsigned long efi_call_phys(void *, ...); 38extern asmlinkage unsigned long efi_call_phys(void *, ...);
38 39
39#define arch_efi_call_virt_setup() kernel_fpu_begin() 40#define arch_efi_call_virt_setup() \
40#define arch_efi_call_virt_teardown() kernel_fpu_end() 41({ \
42 kernel_fpu_begin(); \
43 firmware_restrict_branch_speculation_start(); \
44})
45
46#define arch_efi_call_virt_teardown() \
47({ \
48 firmware_restrict_branch_speculation_end(); \
49 kernel_fpu_end(); \
50})
51
41 52
42/* 53/*
43 * Wrap all the virtual calls in a way that forces the parameters on the stack. 54 * Wrap all the virtual calls in a way that forces the parameters on the stack.
@@ -73,6 +84,7 @@ struct efi_scratch {
73 efi_sync_low_kernel_mappings(); \ 84 efi_sync_low_kernel_mappings(); \
74 preempt_disable(); \ 85 preempt_disable(); \
75 __kernel_fpu_begin(); \ 86 __kernel_fpu_begin(); \
87 firmware_restrict_branch_speculation_start(); \
76 \ 88 \
77 if (efi_scratch.use_pgd) { \ 89 if (efi_scratch.use_pgd) { \
78 efi_scratch.prev_cr3 = __read_cr3(); \ 90 efi_scratch.prev_cr3 = __read_cr3(); \
@@ -91,6 +103,7 @@ struct efi_scratch {
91 __flush_tlb_all(); \ 103 __flush_tlb_all(); \
92 } \ 104 } \
93 \ 105 \
106 firmware_restrict_branch_speculation_end(); \
94 __kernel_fpu_end(); \ 107 __kernel_fpu_end(); \
95 preempt_enable(); \ 108 preempt_enable(); \
96}) 109})
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index 95e948627fd0..f6e5b9375d8c 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -232,21 +232,6 @@ extern void set_iounmap_nonlazy(void);
232 */ 232 */
233#define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET)) 233#define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
234 234
235/*
236 * Cache management
237 *
238 * This needed for two cases
239 * 1. Out of order aware processors
240 * 2. Accidentally out of order processors (PPro errata #51)
241 */
242
243static inline void flush_write_buffers(void)
244{
245#if defined(CONFIG_X86_PPRO_FENCE)
246 asm volatile("lock; addl $0,0(%%esp)": : :"memory");
247#endif
248}
249
250#endif /* __KERNEL__ */ 235#endif /* __KERNEL__ */
251 236
252extern void native_io_delay(void); 237extern void native_io_delay(void);
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index dd6f57a54a26..b605a5b6a30c 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -507,6 +507,7 @@ struct kvm_vcpu_arch {
507 u64 smi_count; 507 u64 smi_count;
508 bool tpr_access_reporting; 508 bool tpr_access_reporting;
509 u64 ia32_xss; 509 u64 ia32_xss;
510 u64 microcode_version;
510 511
511 /* 512 /*
512 * Paging state of the vcpu 513 * Paging state of the vcpu
@@ -1095,6 +1096,8 @@ struct kvm_x86_ops {
1095 int (*mem_enc_op)(struct kvm *kvm, void __user *argp); 1096 int (*mem_enc_op)(struct kvm *kvm, void __user *argp);
1096 int (*mem_enc_reg_region)(struct kvm *kvm, struct kvm_enc_region *argp); 1097 int (*mem_enc_reg_region)(struct kvm *kvm, struct kvm_enc_region *argp);
1097 int (*mem_enc_unreg_region)(struct kvm *kvm, struct kvm_enc_region *argp); 1098 int (*mem_enc_unreg_region)(struct kvm *kvm, struct kvm_enc_region *argp);
1099
1100 int (*get_msr_feature)(struct kvm_msr_entry *entry);
1098}; 1101};
1099 1102
1100struct kvm_arch_async_pf { 1103struct kvm_arch_async_pf {
@@ -1464,7 +1467,4 @@ static inline int kvm_cpu_get_apicid(int mps_cpu)
1464#define put_smstate(type, buf, offset, val) \ 1467#define put_smstate(type, buf, offset, val) \
1465 *(type *)((buf) + (offset) - 0x7e00) = val 1468 *(type *)((buf) + (offset) - 0x7e00) = val
1466 1469
1467void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
1468 unsigned long start, unsigned long end);
1469
1470#endif /* _ASM_X86_KVM_HOST_H */ 1470#endif /* _ASM_X86_KVM_HOST_H */
diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h
index 55520cec8b27..6cf0e4cb7b97 100644
--- a/arch/x86/include/asm/microcode.h
+++ b/arch/x86/include/asm/microcode.h
@@ -37,7 +37,13 @@ struct cpu_signature {
37 37
38struct device; 38struct device;
39 39
40enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND }; 40enum ucode_state {
41 UCODE_OK = 0,
42 UCODE_NEW,
43 UCODE_UPDATED,
44 UCODE_NFOUND,
45 UCODE_ERROR,
46};
41 47
42struct microcode_ops { 48struct microcode_ops {
43 enum ucode_state (*request_microcode_user) (int cpu, 49 enum ucode_state (*request_microcode_user) (int cpu,
@@ -54,7 +60,7 @@ struct microcode_ops {
54 * are being called. 60 * are being called.
55 * See also the "Synchronization" section in microcode_core.c. 61 * See also the "Synchronization" section in microcode_core.c.
56 */ 62 */
57 int (*apply_microcode) (int cpu); 63 enum ucode_state (*apply_microcode) (int cpu);
58 int (*collect_cpu_info) (int cpu, struct cpu_signature *csig); 64 int (*collect_cpu_info) (int cpu, struct cpu_signature *csig);
59}; 65};
60 66
diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
index c931b88982a0..1de72ce514cd 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -74,6 +74,7 @@ static inline void *ldt_slot_va(int slot)
74 return (void *)(LDT_BASE_ADDR + LDT_SLOT_STRIDE * slot); 74 return (void *)(LDT_BASE_ADDR + LDT_SLOT_STRIDE * slot);
75#else 75#else
76 BUG(); 76 BUG();
77 return (void *)fix_to_virt(FIX_HOLE);
77#endif 78#endif
78} 79}
79 80
diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 4d57894635f2..f928ad9b143f 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -6,6 +6,51 @@
6#include <asm/alternative.h> 6#include <asm/alternative.h>
7#include <asm/alternative-asm.h> 7#include <asm/alternative-asm.h>
8#include <asm/cpufeatures.h> 8#include <asm/cpufeatures.h>
9#include <asm/msr-index.h>
10
11/*
12 * Fill the CPU return stack buffer.
13 *
14 * Each entry in the RSB, if used for a speculative 'ret', contains an
15 * infinite 'pause; lfence; jmp' loop to capture speculative execution.
16 *
17 * This is required in various cases for retpoline and IBRS-based
18 * mitigations for the Spectre variant 2 vulnerability. Sometimes to
19 * eliminate potentially bogus entries from the RSB, and sometimes
20 * purely to ensure that it doesn't get empty, which on some CPUs would
21 * allow predictions from other (unwanted!) sources to be used.
22 *
23 * We define a CPP macro such that it can be used from both .S files and
24 * inline assembly. It's possible to do a .macro and then include that
25 * from C via asm(".include <asm/nospec-branch.h>") but let's not go there.
26 */
27
28#define RSB_CLEAR_LOOPS 32 /* To forcibly overwrite all entries */
29#define RSB_FILL_LOOPS 16 /* To avoid underflow */
30
31/*
32 * Google experimented with loop-unrolling and this turned out to be
33 * the optimal version — two calls, each with their own speculation
34 * trap should their return address end up getting used, in a loop.
35 */
36#define __FILL_RETURN_BUFFER(reg, nr, sp) \
37 mov $(nr/2), reg; \
38771: \
39 call 772f; \
40773: /* speculation trap */ \
41 pause; \
42 lfence; \
43 jmp 773b; \
44772: \
45 call 774f; \
46775: /* speculation trap */ \
47 pause; \
48 lfence; \
49 jmp 775b; \
50774: \
51 dec reg; \
52 jnz 771b; \
53 add $(BITS_PER_LONG/8) * nr, sp;
9 54
10#ifdef __ASSEMBLY__ 55#ifdef __ASSEMBLY__
11 56
@@ -23,6 +68,18 @@
23.endm 68.endm
24 69
25/* 70/*
71 * This should be used immediately before an indirect jump/call. It tells
72 * objtool the subsequent indirect jump/call is vouched safe for retpoline
73 * builds.
74 */
75.macro ANNOTATE_RETPOLINE_SAFE
76 .Lannotate_\@:
77 .pushsection .discard.retpoline_safe
78 _ASM_PTR .Lannotate_\@
79 .popsection
80.endm
81
82/*
26 * These are the bare retpoline primitives for indirect jmp and call. 83 * These are the bare retpoline primitives for indirect jmp and call.
27 * Do not use these directly; they only exist to make the ALTERNATIVE 84 * Do not use these directly; they only exist to make the ALTERNATIVE
28 * invocation below less ugly. 85 * invocation below less ugly.
@@ -58,9 +115,9 @@
58.macro JMP_NOSPEC reg:req 115.macro JMP_NOSPEC reg:req
59#ifdef CONFIG_RETPOLINE 116#ifdef CONFIG_RETPOLINE
60 ANNOTATE_NOSPEC_ALTERNATIVE 117 ANNOTATE_NOSPEC_ALTERNATIVE
61 ALTERNATIVE_2 __stringify(jmp *\reg), \ 118 ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *\reg), \
62 __stringify(RETPOLINE_JMP \reg), X86_FEATURE_RETPOLINE, \ 119 __stringify(RETPOLINE_JMP \reg), X86_FEATURE_RETPOLINE, \
63 __stringify(lfence; jmp *\reg), X86_FEATURE_RETPOLINE_AMD 120 __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *\reg), X86_FEATURE_RETPOLINE_AMD
64#else 121#else
65 jmp *\reg 122 jmp *\reg
66#endif 123#endif
@@ -69,18 +126,25 @@
69.macro CALL_NOSPEC reg:req 126.macro CALL_NOSPEC reg:req
70#ifdef CONFIG_RETPOLINE 127#ifdef CONFIG_RETPOLINE
71 ANNOTATE_NOSPEC_ALTERNATIVE 128 ANNOTATE_NOSPEC_ALTERNATIVE
72 ALTERNATIVE_2 __stringify(call *\reg), \ 129 ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; call *\reg), \
73 __stringify(RETPOLINE_CALL \reg), X86_FEATURE_RETPOLINE,\ 130 __stringify(RETPOLINE_CALL \reg), X86_FEATURE_RETPOLINE,\
74 __stringify(lfence; call *\reg), X86_FEATURE_RETPOLINE_AMD 131 __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *\reg), X86_FEATURE_RETPOLINE_AMD
75#else 132#else
76 call *\reg 133 call *\reg
77#endif 134#endif
78.endm 135.endm
79 136
80/* This clobbers the BX register */ 137 /*
81.macro FILL_RETURN_BUFFER nr:req ftr:req 138 * A simpler FILL_RETURN_BUFFER macro. Don't make people use the CPP
139 * monstrosity above, manually.
140 */
141.macro FILL_RETURN_BUFFER reg:req nr:req ftr:req
82#ifdef CONFIG_RETPOLINE 142#ifdef CONFIG_RETPOLINE
83 ALTERNATIVE "", "call __clear_rsb", \ftr 143 ANNOTATE_NOSPEC_ALTERNATIVE
144 ALTERNATIVE "jmp .Lskip_rsb_\@", \
145 __stringify(__FILL_RETURN_BUFFER(\reg,\nr,%_ASM_SP)) \
146 \ftr
147.Lskip_rsb_\@:
84#endif 148#endif
85.endm 149.endm
86 150
@@ -92,6 +156,12 @@
92 ".long 999b - .\n\t" \ 156 ".long 999b - .\n\t" \
93 ".popsection\n\t" 157 ".popsection\n\t"
94 158
159#define ANNOTATE_RETPOLINE_SAFE \
160 "999:\n\t" \
161 ".pushsection .discard.retpoline_safe\n\t" \
162 _ASM_PTR " 999b\n\t" \
163 ".popsection\n\t"
164
95#if defined(CONFIG_X86_64) && defined(RETPOLINE) 165#if defined(CONFIG_X86_64) && defined(RETPOLINE)
96 166
97/* 167/*
@@ -101,6 +171,7 @@
101# define CALL_NOSPEC \ 171# define CALL_NOSPEC \
102 ANNOTATE_NOSPEC_ALTERNATIVE \ 172 ANNOTATE_NOSPEC_ALTERNATIVE \
103 ALTERNATIVE( \ 173 ALTERNATIVE( \
174 ANNOTATE_RETPOLINE_SAFE \
104 "call *%[thunk_target]\n", \ 175 "call *%[thunk_target]\n", \
105 "call __x86_indirect_thunk_%V[thunk_target]\n", \ 176 "call __x86_indirect_thunk_%V[thunk_target]\n", \
106 X86_FEATURE_RETPOLINE) 177 X86_FEATURE_RETPOLINE)
@@ -112,7 +183,10 @@
112 * otherwise we'll run out of registers. We don't care about CET 183 * otherwise we'll run out of registers. We don't care about CET
113 * here, anyway. 184 * here, anyway.
114 */ 185 */
115# define CALL_NOSPEC ALTERNATIVE("call *%[thunk_target]\n", \ 186# define CALL_NOSPEC \
187 ALTERNATIVE( \
188 ANNOTATE_RETPOLINE_SAFE \
189 "call *%[thunk_target]\n", \
116 " jmp 904f;\n" \ 190 " jmp 904f;\n" \
117 " .align 16\n" \ 191 " .align 16\n" \
118 "901: call 903f;\n" \ 192 "901: call 903f;\n" \
@@ -155,20 +229,90 @@ extern char __indirect_thunk_end[];
155static inline void vmexit_fill_RSB(void) 229static inline void vmexit_fill_RSB(void)
156{ 230{
157#ifdef CONFIG_RETPOLINE 231#ifdef CONFIG_RETPOLINE
158 alternative_input("", 232 unsigned long loops;
159 "call __fill_rsb", 233
160 X86_FEATURE_RETPOLINE, 234 asm volatile (ANNOTATE_NOSPEC_ALTERNATIVE
161 ASM_NO_INPUT_CLOBBER(_ASM_BX, "memory")); 235 ALTERNATIVE("jmp 910f",
236 __stringify(__FILL_RETURN_BUFFER(%0, RSB_CLEAR_LOOPS, %1)),
237 X86_FEATURE_RETPOLINE)
238 "910:"
239 : "=r" (loops), ASM_CALL_CONSTRAINT
240 : : "memory" );
162#endif 241#endif
163} 242}
164 243
244#define alternative_msr_write(_msr, _val, _feature) \
245 asm volatile(ALTERNATIVE("", \
246 "movl %[msr], %%ecx\n\t" \
247 "movl %[val], %%eax\n\t" \
248 "movl $0, %%edx\n\t" \
249 "wrmsr", \
250 _feature) \
251 : : [msr] "i" (_msr), [val] "i" (_val) \
252 : "eax", "ecx", "edx", "memory")
253
165static inline void indirect_branch_prediction_barrier(void) 254static inline void indirect_branch_prediction_barrier(void)
166{ 255{
167 alternative_input("", 256 alternative_msr_write(MSR_IA32_PRED_CMD, PRED_CMD_IBPB,
168 "call __ibp_barrier", 257 X86_FEATURE_USE_IBPB);
169 X86_FEATURE_USE_IBPB,
170 ASM_NO_INPUT_CLOBBER("eax", "ecx", "edx", "memory"));
171} 258}
172 259
260/*
261 * With retpoline, we must use IBRS to restrict branch prediction
262 * before calling into firmware.
263 *
264 * (Implemented as CPP macros due to header hell.)
265 */
266#define firmware_restrict_branch_speculation_start() \
267do { \
268 preempt_disable(); \
269 alternative_msr_write(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS, \
270 X86_FEATURE_USE_IBRS_FW); \
271} while (0)
272
273#define firmware_restrict_branch_speculation_end() \
274do { \
275 alternative_msr_write(MSR_IA32_SPEC_CTRL, 0, \
276 X86_FEATURE_USE_IBRS_FW); \
277 preempt_enable(); \
278} while (0)
279
173#endif /* __ASSEMBLY__ */ 280#endif /* __ASSEMBLY__ */
281
282/*
283 * Below is used in the eBPF JIT compiler and emits the byte sequence
284 * for the following assembly:
285 *
286 * With retpolines configured:
287 *
288 * callq do_rop
289 * spec_trap:
290 * pause
291 * lfence
292 * jmp spec_trap
293 * do_rop:
294 * mov %rax,(%rsp)
295 * retq
296 *
297 * Without retpolines configured:
298 *
299 * jmp *%rax
300 */
301#ifdef CONFIG_RETPOLINE
302# define RETPOLINE_RAX_BPF_JIT_SIZE 17
303# define RETPOLINE_RAX_BPF_JIT() \
304 EMIT1_off32(0xE8, 7); /* callq do_rop */ \
305 /* spec_trap: */ \
306 EMIT2(0xF3, 0x90); /* pause */ \
307 EMIT3(0x0F, 0xAE, 0xE8); /* lfence */ \
308 EMIT2(0xEB, 0xF9); /* jmp spec_trap */ \
309 /* do_rop: */ \
310 EMIT4(0x48, 0x89, 0x04, 0x24); /* mov %rax,(%rsp) */ \
311 EMIT1(0xC3); /* retq */
312#else
313# define RETPOLINE_RAX_BPF_JIT_SIZE 2
314# define RETPOLINE_RAX_BPF_JIT() \
315 EMIT2(0xFF, 0xE0); /* jmp *%rax */
316#endif
317
174#endif /* _ASM_X86_NOSPEC_BRANCH_H_ */ 318#endif /* _ASM_X86_NOSPEC_BRANCH_H_ */
diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
index 4baa6bceb232..d652a3808065 100644
--- a/arch/x86/include/asm/page_64.h
+++ b/arch/x86/include/asm/page_64.h
@@ -52,10 +52,6 @@ static inline void clear_page(void *page)
52 52
53void copy_page(void *to, void *from); 53void copy_page(void *to, void *from);
54 54
55#ifdef CONFIG_X86_MCE
56#define arch_unmap_kpfn arch_unmap_kpfn
57#endif
58
59#endif /* !__ASSEMBLY__ */ 55#endif /* !__ASSEMBLY__ */
60 56
61#ifdef CONFIG_X86_VSYSCALL_EMULATION 57#ifdef CONFIG_X86_VSYSCALL_EMULATION
diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
index 892df375b615..c83a2f418cea 100644
--- a/arch/x86/include/asm/paravirt.h
+++ b/arch/x86/include/asm/paravirt.h
@@ -7,6 +7,7 @@
7#ifdef CONFIG_PARAVIRT 7#ifdef CONFIG_PARAVIRT
8#include <asm/pgtable_types.h> 8#include <asm/pgtable_types.h>
9#include <asm/asm.h> 9#include <asm/asm.h>
10#include <asm/nospec-branch.h>
10 11
11#include <asm/paravirt_types.h> 12#include <asm/paravirt_types.h>
12 13
@@ -297,9 +298,9 @@ static inline void __flush_tlb_global(void)
297{ 298{
298 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel); 299 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
299} 300}
300static inline void __flush_tlb_single(unsigned long addr) 301static inline void __flush_tlb_one_user(unsigned long addr)
301{ 302{
302 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr); 303 PVOP_VCALL1(pv_mmu_ops.flush_tlb_one_user, addr);
303} 304}
304 305
305static inline void flush_tlb_others(const struct cpumask *cpumask, 306static inline void flush_tlb_others(const struct cpumask *cpumask,
@@ -879,23 +880,27 @@ extern void default_banner(void);
879 880
880#define INTERRUPT_RETURN \ 881#define INTERRUPT_RETURN \
881 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \ 882 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
882 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret)) 883 ANNOTATE_RETPOLINE_SAFE; \
884 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret);)
883 885
884#define DISABLE_INTERRUPTS(clobbers) \ 886#define DISABLE_INTERRUPTS(clobbers) \
885 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \ 887 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
886 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \ 888 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
889 ANNOTATE_RETPOLINE_SAFE; \
887 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \ 890 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
888 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);) 891 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
889 892
890#define ENABLE_INTERRUPTS(clobbers) \ 893#define ENABLE_INTERRUPTS(clobbers) \
891 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \ 894 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
892 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \ 895 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
896 ANNOTATE_RETPOLINE_SAFE; \
893 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \ 897 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
894 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);) 898 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
895 899
896#ifdef CONFIG_X86_32 900#ifdef CONFIG_X86_32
897#define GET_CR0_INTO_EAX \ 901#define GET_CR0_INTO_EAX \
898 push %ecx; push %edx; \ 902 push %ecx; push %edx; \
903 ANNOTATE_RETPOLINE_SAFE; \
899 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \ 904 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
900 pop %edx; pop %ecx 905 pop %edx; pop %ecx
901#else /* !CONFIG_X86_32 */ 906#else /* !CONFIG_X86_32 */
@@ -917,21 +922,25 @@ extern void default_banner(void);
917 */ 922 */
918#define SWAPGS \ 923#define SWAPGS \
919 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \ 924 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
920 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \ 925 ANNOTATE_RETPOLINE_SAFE; \
926 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs); \
921 ) 927 )
922 928
923#define GET_CR2_INTO_RAX \ 929#define GET_CR2_INTO_RAX \
924 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2) 930 ANNOTATE_RETPOLINE_SAFE; \
931 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2);
925 932
926#define USERGS_SYSRET64 \ 933#define USERGS_SYSRET64 \
927 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \ 934 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
928 CLBR_NONE, \ 935 CLBR_NONE, \
929 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64)) 936 ANNOTATE_RETPOLINE_SAFE; \
937 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64);)
930 938
931#ifdef CONFIG_DEBUG_ENTRY 939#ifdef CONFIG_DEBUG_ENTRY
932#define SAVE_FLAGS(clobbers) \ 940#define SAVE_FLAGS(clobbers) \
933 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_save_fl), clobbers, \ 941 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_save_fl), clobbers, \
934 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \ 942 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
943 ANNOTATE_RETPOLINE_SAFE; \
935 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_save_fl); \ 944 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_save_fl); \
936 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);) 945 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
937#endif 946#endif
diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
index 6ec54d01972d..180bc0bff0fb 100644
--- a/arch/x86/include/asm/paravirt_types.h
+++ b/arch/x86/include/asm/paravirt_types.h
@@ -43,6 +43,7 @@
43#include <asm/desc_defs.h> 43#include <asm/desc_defs.h>
44#include <asm/kmap_types.h> 44#include <asm/kmap_types.h>
45#include <asm/pgtable_types.h> 45#include <asm/pgtable_types.h>
46#include <asm/nospec-branch.h>
46 47
47struct page; 48struct page;
48struct thread_struct; 49struct thread_struct;
@@ -217,7 +218,7 @@ struct pv_mmu_ops {
217 /* TLB operations */ 218 /* TLB operations */
218 void (*flush_tlb_user)(void); 219 void (*flush_tlb_user)(void);
219 void (*flush_tlb_kernel)(void); 220 void (*flush_tlb_kernel)(void);
220 void (*flush_tlb_single)(unsigned long addr); 221 void (*flush_tlb_one_user)(unsigned long addr);
221 void (*flush_tlb_others)(const struct cpumask *cpus, 222 void (*flush_tlb_others)(const struct cpumask *cpus,
222 const struct flush_tlb_info *info); 223 const struct flush_tlb_info *info);
223 224
@@ -392,7 +393,9 @@ int paravirt_disable_iospace(void);
392 * offset into the paravirt_patch_template structure, and can therefore be 393 * offset into the paravirt_patch_template structure, and can therefore be
393 * freely converted back into a structure offset. 394 * freely converted back into a structure offset.
394 */ 395 */
395#define PARAVIRT_CALL "call *%c[paravirt_opptr];" 396#define PARAVIRT_CALL \
397 ANNOTATE_RETPOLINE_SAFE \
398 "call *%c[paravirt_opptr];"
396 399
397/* 400/*
398 * These macros are intended to wrap calls through one of the paravirt 401 * These macros are intended to wrap calls through one of the paravirt
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index ba3c523aaf16..a06b07399d17 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -526,7 +526,7 @@ static inline bool x86_this_cpu_variable_test_bit(int nr,
526{ 526{
527 bool oldbit; 527 bool oldbit;
528 528
529 asm volatile("bt "__percpu_arg(2)",%1" 529 asm volatile("btl "__percpu_arg(2)",%1"
530 CC_SET(c) 530 CC_SET(c)
531 : CC_OUT(c) (oldbit) 531 : CC_OUT(c) (oldbit)
532 : "m" (*(unsigned long __percpu *)addr), "Ir" (nr)); 532 : "m" (*(unsigned long __percpu *)addr), "Ir" (nr));
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 63c2552b6b65..b444d83cfc95 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -350,14 +350,14 @@ static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set)
350{ 350{
351 pmdval_t v = native_pmd_val(pmd); 351 pmdval_t v = native_pmd_val(pmd);
352 352
353 return __pmd(v | set); 353 return native_make_pmd(v | set);
354} 354}
355 355
356static inline pmd_t pmd_clear_flags(pmd_t pmd, pmdval_t clear) 356static inline pmd_t pmd_clear_flags(pmd_t pmd, pmdval_t clear)
357{ 357{
358 pmdval_t v = native_pmd_val(pmd); 358 pmdval_t v = native_pmd_val(pmd);
359 359
360 return __pmd(v & ~clear); 360 return native_make_pmd(v & ~clear);
361} 361}
362 362
363static inline pmd_t pmd_mkold(pmd_t pmd) 363static inline pmd_t pmd_mkold(pmd_t pmd)
@@ -409,14 +409,14 @@ static inline pud_t pud_set_flags(pud_t pud, pudval_t set)
409{ 409{
410 pudval_t v = native_pud_val(pud); 410 pudval_t v = native_pud_val(pud);
411 411
412 return __pud(v | set); 412 return native_make_pud(v | set);
413} 413}
414 414
415static inline pud_t pud_clear_flags(pud_t pud, pudval_t clear) 415static inline pud_t pud_clear_flags(pud_t pud, pudval_t clear)
416{ 416{
417 pudval_t v = native_pud_val(pud); 417 pudval_t v = native_pud_val(pud);
418 418
419 return __pud(v & ~clear); 419 return native_make_pud(v & ~clear);
420} 420}
421 421
422static inline pud_t pud_mkold(pud_t pud) 422static inline pud_t pud_mkold(pud_t pud)
diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
index e67c0620aec2..b3ec519e3982 100644
--- a/arch/x86/include/asm/pgtable_32.h
+++ b/arch/x86/include/asm/pgtable_32.h
@@ -32,6 +32,7 @@ extern pmd_t initial_pg_pmd[];
32static inline void pgtable_cache_init(void) { } 32static inline void pgtable_cache_init(void) { }
33static inline void check_pgt_cache(void) { } 33static inline void check_pgt_cache(void) { }
34void paging_init(void); 34void paging_init(void);
35void sync_initial_page_table(void);
35 36
36/* 37/*
37 * Define this if things work differently on an i386 and an i486: 38 * Define this if things work differently on an i386 and an i486:
@@ -61,7 +62,7 @@ void paging_init(void);
61#define kpte_clear_flush(ptep, vaddr) \ 62#define kpte_clear_flush(ptep, vaddr) \
62do { \ 63do { \
63 pte_clear(&init_mm, (vaddr), (ptep)); \ 64 pte_clear(&init_mm, (vaddr), (ptep)); \
64 __flush_tlb_one((vaddr)); \ 65 __flush_tlb_one_kernel((vaddr)); \
65} while (0) 66} while (0)
66 67
67#endif /* !__ASSEMBLY__ */ 68#endif /* !__ASSEMBLY__ */
diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index 81462e9a34f6..1149d2112b2e 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -28,6 +28,7 @@ extern pgd_t init_top_pgt[];
28#define swapper_pg_dir init_top_pgt 28#define swapper_pg_dir init_top_pgt
29 29
30extern void paging_init(void); 30extern void paging_init(void);
31static inline void sync_initial_page_table(void) { }
31 32
32#define pte_ERROR(e) \ 33#define pte_ERROR(e) \
33 pr_err("%s:%d: bad pte %p(%016lx)\n", \ 34 pr_err("%s:%d: bad pte %p(%016lx)\n", \
diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
index 3696398a9475..acfe755562a6 100644
--- a/arch/x86/include/asm/pgtable_types.h
+++ b/arch/x86/include/asm/pgtable_types.h
@@ -174,7 +174,6 @@ enum page_cache_mode {
174#define __PAGE_KERNEL_RO (__PAGE_KERNEL & ~_PAGE_RW) 174#define __PAGE_KERNEL_RO (__PAGE_KERNEL & ~_PAGE_RW)
175#define __PAGE_KERNEL_RX (__PAGE_KERNEL_EXEC & ~_PAGE_RW) 175#define __PAGE_KERNEL_RX (__PAGE_KERNEL_EXEC & ~_PAGE_RW)
176#define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_NOCACHE) 176#define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_NOCACHE)
177#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
178#define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER) 177#define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
179#define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE) 178#define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
180#define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE) 179#define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
@@ -206,7 +205,6 @@ enum page_cache_mode {
206#define PAGE_KERNEL_NOCACHE __pgprot(__PAGE_KERNEL_NOCACHE | _PAGE_ENC) 205#define PAGE_KERNEL_NOCACHE __pgprot(__PAGE_KERNEL_NOCACHE | _PAGE_ENC)
207#define PAGE_KERNEL_LARGE __pgprot(__PAGE_KERNEL_LARGE | _PAGE_ENC) 206#define PAGE_KERNEL_LARGE __pgprot(__PAGE_KERNEL_LARGE | _PAGE_ENC)
208#define PAGE_KERNEL_LARGE_EXEC __pgprot(__PAGE_KERNEL_LARGE_EXEC | _PAGE_ENC) 207#define PAGE_KERNEL_LARGE_EXEC __pgprot(__PAGE_KERNEL_LARGE_EXEC | _PAGE_ENC)
209#define PAGE_KERNEL_VSYSCALL __pgprot(__PAGE_KERNEL_VSYSCALL | _PAGE_ENC)
210#define PAGE_KERNEL_VVAR __pgprot(__PAGE_KERNEL_VVAR | _PAGE_ENC) 208#define PAGE_KERNEL_VVAR __pgprot(__PAGE_KERNEL_VVAR | _PAGE_ENC)
211 209
212#define PAGE_KERNEL_IO __pgprot(__PAGE_KERNEL_IO) 210#define PAGE_KERNEL_IO __pgprot(__PAGE_KERNEL_IO)
@@ -323,6 +321,11 @@ static inline pudval_t native_pud_val(pud_t pud)
323#else 321#else
324#include <asm-generic/pgtable-nopud.h> 322#include <asm-generic/pgtable-nopud.h>
325 323
324static inline pud_t native_make_pud(pudval_t val)
325{
326 return (pud_t) { .p4d.pgd = native_make_pgd(val) };
327}
328
326static inline pudval_t native_pud_val(pud_t pud) 329static inline pudval_t native_pud_val(pud_t pud)
327{ 330{
328 return native_pgd_val(pud.p4d.pgd); 331 return native_pgd_val(pud.p4d.pgd);
@@ -344,6 +347,11 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
344#else 347#else
345#include <asm-generic/pgtable-nopmd.h> 348#include <asm-generic/pgtable-nopmd.h>
346 349
350static inline pmd_t native_make_pmd(pmdval_t val)
351{
352 return (pmd_t) { .pud.p4d.pgd = native_make_pgd(val) };
353}
354
347static inline pmdval_t native_pmd_val(pmd_t pmd) 355static inline pmdval_t native_pmd_val(pmd_t pmd)
348{ 356{
349 return native_pgd_val(pmd.pud.p4d.pgd); 357 return native_pgd_val(pmd.pud.p4d.pgd);
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 793bae7e7ce3..b0ccd4847a58 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -91,7 +91,7 @@ struct cpuinfo_x86 {
91 __u8 x86; /* CPU family */ 91 __u8 x86; /* CPU family */
92 __u8 x86_vendor; /* CPU vendor */ 92 __u8 x86_vendor; /* CPU vendor */
93 __u8 x86_model; 93 __u8 x86_model;
94 __u8 x86_mask; 94 __u8 x86_stepping;
95#ifdef CONFIG_X86_64 95#ifdef CONFIG_X86_64
96 /* Number of 4K pages in DTLB/ITLB combined(in pages): */ 96 /* Number of 4K pages in DTLB/ITLB combined(in pages): */
97 int x86_tlbsize; 97 int x86_tlbsize;
@@ -109,7 +109,7 @@ struct cpuinfo_x86 {
109 char x86_vendor_id[16]; 109 char x86_vendor_id[16];
110 char x86_model_id[64]; 110 char x86_model_id[64];
111 /* in KB - valid for CPUS which support this call: */ 111 /* in KB - valid for CPUS which support this call: */
112 int x86_cache_size; 112 unsigned int x86_cache_size;
113 int x86_cache_alignment; /* In bytes */ 113 int x86_cache_alignment; /* In bytes */
114 /* Cache QoS architectural values: */ 114 /* Cache QoS architectural values: */
115 int x86_cache_max_rmid; /* max index */ 115 int x86_cache_max_rmid; /* max index */
@@ -977,7 +977,5 @@ bool xen_set_default_idle(void);
977 977
978void stop_this_cpu(void *dummy); 978void stop_this_cpu(void *dummy);
979void df_debug(struct pt_regs *regs, long error_code); 979void df_debug(struct pt_regs *regs, long error_code);
980 980void microcode_check(void);
981void __ibp_barrier(void);
982
983#endif /* _ASM_X86_PROCESSOR_H */ 981#endif /* _ASM_X86_PROCESSOR_H */
diff --git a/arch/x86/include/asm/refcount.h b/arch/x86/include/asm/refcount.h
index 4e44250e7d0d..4cf11d88d3b3 100644
--- a/arch/x86/include/asm/refcount.h
+++ b/arch/x86/include/asm/refcount.h
@@ -17,7 +17,7 @@
17#define _REFCOUNT_EXCEPTION \ 17#define _REFCOUNT_EXCEPTION \
18 ".pushsection .text..refcount\n" \ 18 ".pushsection .text..refcount\n" \
19 "111:\tlea %[counter], %%" _ASM_CX "\n" \ 19 "111:\tlea %[counter], %%" _ASM_CX "\n" \
20 "112:\t" ASM_UD0 "\n" \ 20 "112:\t" ASM_UD2 "\n" \
21 ASM_UNREACHABLE \ 21 ASM_UNREACHABLE \
22 ".popsection\n" \ 22 ".popsection\n" \
23 "113:\n" \ 23 "113:\n" \
@@ -67,13 +67,13 @@ static __always_inline __must_check
67bool refcount_sub_and_test(unsigned int i, refcount_t *r) 67bool refcount_sub_and_test(unsigned int i, refcount_t *r)
68{ 68{
69 GEN_BINARY_SUFFIXED_RMWcc(LOCK_PREFIX "subl", REFCOUNT_CHECK_LT_ZERO, 69 GEN_BINARY_SUFFIXED_RMWcc(LOCK_PREFIX "subl", REFCOUNT_CHECK_LT_ZERO,
70 r->refs.counter, "er", i, "%0", e); 70 r->refs.counter, "er", i, "%0", e, "cx");
71} 71}
72 72
73static __always_inline __must_check bool refcount_dec_and_test(refcount_t *r) 73static __always_inline __must_check bool refcount_dec_and_test(refcount_t *r)
74{ 74{
75 GEN_UNARY_SUFFIXED_RMWcc(LOCK_PREFIX "decl", REFCOUNT_CHECK_LT_ZERO, 75 GEN_UNARY_SUFFIXED_RMWcc(LOCK_PREFIX "decl", REFCOUNT_CHECK_LT_ZERO,
76 r->refs.counter, "%0", e); 76 r->refs.counter, "%0", e, "cx");
77} 77}
78 78
79static __always_inline __must_check 79static __always_inline __must_check
diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
index f91c365e57c3..4914a3e7c803 100644
--- a/arch/x86/include/asm/rmwcc.h
+++ b/arch/x86/include/asm/rmwcc.h
@@ -2,8 +2,7 @@
2#ifndef _ASM_X86_RMWcc 2#ifndef _ASM_X86_RMWcc
3#define _ASM_X86_RMWcc 3#define _ASM_X86_RMWcc
4 4
5#define __CLOBBERS_MEM "memory" 5#define __CLOBBERS_MEM(clb...) "memory", ## clb
6#define __CLOBBERS_MEM_CC_CX "memory", "cc", "cx"
7 6
8#if !defined(__GCC_ASM_FLAG_OUTPUTS__) && defined(CC_HAVE_ASM_GOTO) 7#if !defined(__GCC_ASM_FLAG_OUTPUTS__) && defined(CC_HAVE_ASM_GOTO)
9 8
@@ -40,18 +39,19 @@ do { \
40#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */ 39#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
41 40
42#define GEN_UNARY_RMWcc(op, var, arg0, cc) \ 41#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
43 __GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM) 42 __GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM())
44 43
45#define GEN_UNARY_SUFFIXED_RMWcc(op, suffix, var, arg0, cc) \ 44#define GEN_UNARY_SUFFIXED_RMWcc(op, suffix, var, arg0, cc, clobbers...)\
46 __GEN_RMWcc(op " " arg0 "\n\t" suffix, var, cc, \ 45 __GEN_RMWcc(op " " arg0 "\n\t" suffix, var, cc, \
47 __CLOBBERS_MEM_CC_CX) 46 __CLOBBERS_MEM(clobbers))
48 47
49#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \ 48#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
50 __GEN_RMWcc(op __BINARY_RMWcc_ARG arg0, var, cc, \ 49 __GEN_RMWcc(op __BINARY_RMWcc_ARG arg0, var, cc, \
51 __CLOBBERS_MEM, vcon (val)) 50 __CLOBBERS_MEM(), vcon (val))
52 51
53#define GEN_BINARY_SUFFIXED_RMWcc(op, suffix, var, vcon, val, arg0, cc) \ 52#define GEN_BINARY_SUFFIXED_RMWcc(op, suffix, var, vcon, val, arg0, cc, \
53 clobbers...) \
54 __GEN_RMWcc(op __BINARY_RMWcc_ARG arg0 "\n\t" suffix, var, cc, \ 54 __GEN_RMWcc(op __BINARY_RMWcc_ARG arg0 "\n\t" suffix, var, cc, \
55 __CLOBBERS_MEM_CC_CX, vcon (val)) 55 __CLOBBERS_MEM(clobbers), vcon (val))
56 56
57#endif /* _ASM_X86_RMWcc */ 57#endif /* _ASM_X86_RMWcc */
diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
index d6baf23782bc..5c019d23d06b 100644
--- a/arch/x86/include/asm/sections.h
+++ b/arch/x86/include/asm/sections.h
@@ -10,6 +10,7 @@ extern struct exception_table_entry __stop___ex_table[];
10 10
11#if defined(CONFIG_X86_64) 11#if defined(CONFIG_X86_64)
12extern char __end_rodata_hpage_align[]; 12extern char __end_rodata_hpage_align[];
13extern char __entry_trampoline_start[], __entry_trampoline_end[];
13#endif 14#endif
14 15
15#endif /* _ASM_X86_SECTIONS_H */ 16#endif /* _ASM_X86_SECTIONS_H */
diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index 461f53d27708..a4189762b266 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -129,6 +129,7 @@ static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
129void cpu_disable_common(void); 129void cpu_disable_common(void);
130void native_smp_prepare_boot_cpu(void); 130void native_smp_prepare_boot_cpu(void);
131void native_smp_prepare_cpus(unsigned int max_cpus); 131void native_smp_prepare_cpus(unsigned int max_cpus);
132void calculate_max_logical_packages(void);
132void native_smp_cpus_done(unsigned int max_cpus); 133void native_smp_cpus_done(unsigned int max_cpus);
133void common_cpu_up(unsigned int cpunum, struct task_struct *tidle); 134void common_cpu_up(unsigned int cpunum, struct task_struct *tidle);
134int native_cpu_up(unsigned int cpunum, struct task_struct *tidle); 135int native_cpu_up(unsigned int cpunum, struct task_struct *tidle);
diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
index 82c34ee25a65..906794aa034e 100644
--- a/arch/x86/include/asm/sys_ia32.h
+++ b/arch/x86/include/asm/sys_ia32.h
@@ -20,31 +20,43 @@
20#include <asm/ia32.h> 20#include <asm/ia32.h>
21 21
22/* ia32/sys_ia32.c */ 22/* ia32/sys_ia32.c */
23asmlinkage long sys32_truncate64(const char __user *, unsigned long, unsigned long); 23asmlinkage long compat_sys_x86_truncate64(const char __user *, unsigned long,
24asmlinkage long sys32_ftruncate64(unsigned int, unsigned long, unsigned long); 24 unsigned long);
25asmlinkage long compat_sys_x86_ftruncate64(unsigned int, unsigned long,
26 unsigned long);
25 27
26asmlinkage long sys32_stat64(const char __user *, struct stat64 __user *); 28asmlinkage long compat_sys_x86_stat64(const char __user *,
27asmlinkage long sys32_lstat64(const char __user *, struct stat64 __user *); 29 struct stat64 __user *);
28asmlinkage long sys32_fstat64(unsigned int, struct stat64 __user *); 30asmlinkage long compat_sys_x86_lstat64(const char __user *,
29asmlinkage long sys32_fstatat(unsigned int, const char __user *, 31 struct stat64 __user *);
32asmlinkage long compat_sys_x86_fstat64(unsigned int, struct stat64 __user *);
33asmlinkage long compat_sys_x86_fstatat(unsigned int, const char __user *,
30 struct stat64 __user *, int); 34 struct stat64 __user *, int);
31struct mmap_arg_struct32; 35struct mmap_arg_struct32;
32asmlinkage long sys32_mmap(struct mmap_arg_struct32 __user *); 36asmlinkage long compat_sys_x86_mmap(struct mmap_arg_struct32 __user *);
33 37
34asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int); 38asmlinkage long compat_sys_x86_waitpid(compat_pid_t, unsigned int __user *,
39 int);
35 40
36asmlinkage long sys32_pread(unsigned int, char __user *, u32, u32, u32); 41asmlinkage long compat_sys_x86_pread(unsigned int, char __user *, u32, u32,
37asmlinkage long sys32_pwrite(unsigned int, const char __user *, u32, u32, u32); 42 u32);
43asmlinkage long compat_sys_x86_pwrite(unsigned int, const char __user *, u32,
44 u32, u32);
38 45
39long sys32_fadvise64_64(int, __u32, __u32, __u32, __u32, int); 46asmlinkage long compat_sys_x86_fadvise64_64(int, __u32, __u32, __u32, __u32,
40long sys32_vm86_warning(void); 47 int);
41 48
42asmlinkage ssize_t sys32_readahead(int, unsigned, unsigned, size_t); 49asmlinkage ssize_t compat_sys_x86_readahead(int, unsigned int, unsigned int,
43asmlinkage long sys32_sync_file_range(int, unsigned, unsigned, 50 size_t);
44 unsigned, unsigned, int); 51asmlinkage long compat_sys_x86_sync_file_range(int, unsigned int, unsigned int,
45asmlinkage long sys32_fadvise64(int, unsigned, unsigned, size_t, int); 52 unsigned int, unsigned int,
46asmlinkage long sys32_fallocate(int, int, unsigned, 53 int);
47 unsigned, unsigned, unsigned); 54asmlinkage long compat_sys_x86_fadvise64(int, unsigned int, unsigned int,
55 size_t, int);
56asmlinkage long compat_sys_x86_fallocate(int, int, unsigned int, unsigned int,
57 unsigned int, unsigned int);
58asmlinkage long compat_sys_x86_clone(unsigned long, unsigned long, int __user *,
59 unsigned long, int __user *);
48 60
49/* ia32/ia32_signal.c */ 61/* ia32/ia32_signal.c */
50asmlinkage long sys32_sigreturn(void); 62asmlinkage long sys32_sigreturn(void);
diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index 2b8f18ca5874..84137c22fdfa 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -140,7 +140,7 @@ static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid)
140#else 140#else
141#define __flush_tlb() __native_flush_tlb() 141#define __flush_tlb() __native_flush_tlb()
142#define __flush_tlb_global() __native_flush_tlb_global() 142#define __flush_tlb_global() __native_flush_tlb_global()
143#define __flush_tlb_single(addr) __native_flush_tlb_single(addr) 143#define __flush_tlb_one_user(addr) __native_flush_tlb_one_user(addr)
144#endif 144#endif
145 145
146static inline bool tlb_defer_switch_to_init_mm(void) 146static inline bool tlb_defer_switch_to_init_mm(void)
@@ -400,7 +400,7 @@ static inline void __native_flush_tlb_global(void)
400/* 400/*
401 * flush one page in the user mapping 401 * flush one page in the user mapping
402 */ 402 */
403static inline void __native_flush_tlb_single(unsigned long addr) 403static inline void __native_flush_tlb_one_user(unsigned long addr)
404{ 404{
405 u32 loaded_mm_asid = this_cpu_read(cpu_tlbstate.loaded_mm_asid); 405 u32 loaded_mm_asid = this_cpu_read(cpu_tlbstate.loaded_mm_asid);
406 406
@@ -437,18 +437,31 @@ static inline void __flush_tlb_all(void)
437/* 437/*
438 * flush one page in the kernel mapping 438 * flush one page in the kernel mapping
439 */ 439 */
440static inline void __flush_tlb_one(unsigned long addr) 440static inline void __flush_tlb_one_kernel(unsigned long addr)
441{ 441{
442 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ONE); 442 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ONE);
443 __flush_tlb_single(addr); 443
444 /*
445 * If PTI is off, then __flush_tlb_one_user() is just INVLPG or its
446 * paravirt equivalent. Even with PCID, this is sufficient: we only
447 * use PCID if we also use global PTEs for the kernel mapping, and
448 * INVLPG flushes global translations across all address spaces.
449 *
450 * If PTI is on, then the kernel is mapped with non-global PTEs, and
451 * __flush_tlb_one_user() will flush the given address for the current
452 * kernel address space and for its usermode counterpart, but it does
453 * not flush it for other address spaces.
454 */
455 __flush_tlb_one_user(addr);
444 456
445 if (!static_cpu_has(X86_FEATURE_PTI)) 457 if (!static_cpu_has(X86_FEATURE_PTI))
446 return; 458 return;
447 459
448 /* 460 /*
449 * __flush_tlb_single() will have cleared the TLB entry for this ASID, 461 * See above. We need to propagate the flush to all other address
450 * but since kernel space is replicated across all, we must also 462 * spaces. In principle, we only need to propagate it to kernelmode
451 * invalidate all others. 463 * address spaces, but the extra bookkeeping we would need is not
464 * worth it.
452 */ 465 */
453 invalidate_other_asid(); 466 invalidate_other_asid();
454} 467}
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 8b6780751132..5db8b0b10766 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -352,6 +352,7 @@ enum vmcs_field {
352#define INTR_TYPE_NMI_INTR (2 << 8) /* NMI */ 352#define INTR_TYPE_NMI_INTR (2 << 8) /* NMI */
353#define INTR_TYPE_HARD_EXCEPTION (3 << 8) /* processor exception */ 353#define INTR_TYPE_HARD_EXCEPTION (3 << 8) /* processor exception */
354#define INTR_TYPE_SOFT_INTR (4 << 8) /* software interrupt */ 354#define INTR_TYPE_SOFT_INTR (4 << 8) /* software interrupt */
355#define INTR_TYPE_PRIV_SW_EXCEPTION (5 << 8) /* ICE breakpoint - undocumented */
355#define INTR_TYPE_SOFT_EXCEPTION (6 << 8) /* software exception */ 356#define INTR_TYPE_SOFT_EXCEPTION (6 << 8) /* software exception */
356 357
357/* GUEST_INTERRUPTIBILITY_INFO flags. */ 358/* GUEST_INTERRUPTIBILITY_INFO flags. */
diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h
index 197c2e6c7376..099414345865 100644
--- a/arch/x86/include/uapi/asm/hyperv.h
+++ b/arch/x86/include/uapi/asm/hyperv.h
@@ -241,24 +241,24 @@
241#define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106 241#define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106
242 242
243struct hv_reenlightenment_control { 243struct hv_reenlightenment_control {
244 u64 vector:8; 244 __u64 vector:8;
245 u64 reserved1:8; 245 __u64 reserved1:8;
246 u64 enabled:1; 246 __u64 enabled:1;
247 u64 reserved2:15; 247 __u64 reserved2:15;
248 u64 target_vp:32; 248 __u64 target_vp:32;
249}; 249};
250 250
251#define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107 251#define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107
252#define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108 252#define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108
253 253
254struct hv_tsc_emulation_control { 254struct hv_tsc_emulation_control {
255 u64 enabled:1; 255 __u64 enabled:1;
256 u64 reserved:63; 256 __u64 reserved:63;
257}; 257};
258 258
259struct hv_tsc_emulation_status { 259struct hv_tsc_emulation_status {
260 u64 inprogress:1; 260 __u64 inprogress:1;
261 u64 reserved:63; 261 __u64 reserved:63;
262}; 262};
263 263
264#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001 264#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001
diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h
index 7a2ade4aa235..6cfa9c8cb7d6 100644
--- a/arch/x86/include/uapi/asm/kvm_para.h
+++ b/arch/x86/include/uapi/asm/kvm_para.h
@@ -26,6 +26,7 @@
26#define KVM_FEATURE_PV_EOI 6 26#define KVM_FEATURE_PV_EOI 6
27#define KVM_FEATURE_PV_UNHALT 7 27#define KVM_FEATURE_PV_UNHALT 7
28#define KVM_FEATURE_PV_TLB_FLUSH 9 28#define KVM_FEATURE_PV_TLB_FLUSH 9
29#define KVM_FEATURE_ASYNC_PF_VMEXIT 10
29 30
30/* The last 8 bits are used to indicate how to interpret the flags field 31/* The last 8 bits are used to indicate how to interpret the flags field
31 * in pvclock structure. If no bits are set, all flags are ignored. 32 * in pvclock structure. If no bits are set, all flags are ignored.
diff --git a/arch/x86/include/uapi/asm/mce.h b/arch/x86/include/uapi/asm/mce.h
index 91723461dc1f..435db58a7bad 100644
--- a/arch/x86/include/uapi/asm/mce.h
+++ b/arch/x86/include/uapi/asm/mce.h
@@ -30,6 +30,7 @@ struct mce {
30 __u64 synd; /* MCA_SYND MSR: only valid on SMCA systems */ 30 __u64 synd; /* MCA_SYND MSR: only valid on SMCA systems */
31 __u64 ipid; /* MCA_IPID MSR: only valid on SMCA systems */ 31 __u64 ipid; /* MCA_IPID MSR: only valid on SMCA systems */
32 __u64 ppin; /* Protected Processor Inventory Number */ 32 __u64 ppin; /* Protected Processor Inventory Number */
33 __u32 microcode;/* Microcode revision */
33}; 34};
34 35
35#define MCE_GET_RECORD_LEN _IOR('M', 1, int) 36#define MCE_GET_RECORD_LEN _IOR('M', 1, int)
diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index 6db28f17ff28..c88e0b127810 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -235,7 +235,7 @@ int amd_cache_northbridges(void)
235 if (boot_cpu_data.x86 == 0x10 && 235 if (boot_cpu_data.x86 == 0x10 &&
236 boot_cpu_data.x86_model >= 0x8 && 236 boot_cpu_data.x86_model >= 0x8 &&
237 (boot_cpu_data.x86_model > 0x9 || 237 (boot_cpu_data.x86_model > 0x9 ||
238 boot_cpu_data.x86_mask >= 0x1)) 238 boot_cpu_data.x86_stepping >= 0x1))
239 amd_northbridges.flags |= AMD_NB_L3_INDEX_DISABLE; 239 amd_northbridges.flags |= AMD_NB_L3_INDEX_DISABLE;
240 240
241 if (boot_cpu_data.x86 == 0x15) 241 if (boot_cpu_data.x86 == 0x15)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 25ddf02598d2..b203af0855b5 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -546,7 +546,7 @@ static DEFINE_PER_CPU(struct clock_event_device, lapic_events);
546 546
547static u32 hsx_deadline_rev(void) 547static u32 hsx_deadline_rev(void)
548{ 548{
549 switch (boot_cpu_data.x86_mask) { 549 switch (boot_cpu_data.x86_stepping) {
550 case 0x02: return 0x3a; /* EP */ 550 case 0x02: return 0x3a; /* EP */
551 case 0x04: return 0x0f; /* EX */ 551 case 0x04: return 0x0f; /* EX */
552 } 552 }
@@ -556,7 +556,7 @@ static u32 hsx_deadline_rev(void)
556 556
557static u32 bdx_deadline_rev(void) 557static u32 bdx_deadline_rev(void)
558{ 558{
559 switch (boot_cpu_data.x86_mask) { 559 switch (boot_cpu_data.x86_stepping) {
560 case 0x02: return 0x00000011; 560 case 0x02: return 0x00000011;
561 case 0x03: return 0x0700000e; 561 case 0x03: return 0x0700000e;
562 case 0x04: return 0x0f00000c; 562 case 0x04: return 0x0f00000c;
@@ -568,7 +568,7 @@ static u32 bdx_deadline_rev(void)
568 568
569static u32 skx_deadline_rev(void) 569static u32 skx_deadline_rev(void)
570{ 570{
571 switch (boot_cpu_data.x86_mask) { 571 switch (boot_cpu_data.x86_stepping) {
572 case 0x03: return 0x01000136; 572 case 0x03: return 0x01000136;
573 case 0x04: return 0x02000014; 573 case 0x04: return 0x02000014;
574 } 574 }
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 8ad2e410974f..7c5538769f7e 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -1603,7 +1603,7 @@ static void __init delay_with_tsc(void)
1603 do { 1603 do {
1604 rep_nop(); 1604 rep_nop();
1605 now = rdtsc(); 1605 now = rdtsc();
1606 } while ((now - start) < 40000000000UL / HZ && 1606 } while ((now - start) < 40000000000ULL / HZ &&
1607 time_before_eq(jiffies, end)); 1607 time_before_eq(jiffies, end));
1608} 1608}
1609 1609
diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c
index 3cc471beb50b..bb6f7a2148d7 100644
--- a/arch/x86/kernel/apic/vector.c
+++ b/arch/x86/kernel/apic/vector.c
@@ -134,21 +134,40 @@ static void apic_update_vector(struct irq_data *irqd, unsigned int newvec,
134{ 134{
135 struct apic_chip_data *apicd = apic_chip_data(irqd); 135 struct apic_chip_data *apicd = apic_chip_data(irqd);
136 struct irq_desc *desc = irq_data_to_desc(irqd); 136 struct irq_desc *desc = irq_data_to_desc(irqd);
137 bool managed = irqd_affinity_is_managed(irqd);
137 138
138 lockdep_assert_held(&vector_lock); 139 lockdep_assert_held(&vector_lock);
139 140
140 trace_vector_update(irqd->irq, newvec, newcpu, apicd->vector, 141 trace_vector_update(irqd->irq, newvec, newcpu, apicd->vector,
141 apicd->cpu); 142 apicd->cpu);
142 143
143 /* Setup the vector move, if required */ 144 /*
144 if (apicd->vector && cpu_online(apicd->cpu)) { 145 * If there is no vector associated or if the associated vector is
146 * the shutdown vector, which is associated to make PCI/MSI
147 * shutdown mode work, then there is nothing to release. Clear out
148 * prev_vector for this and the offlined target case.
149 */
150 apicd->prev_vector = 0;
151 if (!apicd->vector || apicd->vector == MANAGED_IRQ_SHUTDOWN_VECTOR)
152 goto setnew;
153 /*
154 * If the target CPU of the previous vector is online, then mark
155 * the vector as move in progress and store it for cleanup when the
156 * first interrupt on the new vector arrives. If the target CPU is
157 * offline then the regular release mechanism via the cleanup
158 * vector is not possible and the vector can be immediately freed
159 * in the underlying matrix allocator.
160 */
161 if (cpu_online(apicd->cpu)) {
145 apicd->move_in_progress = true; 162 apicd->move_in_progress = true;
146 apicd->prev_vector = apicd->vector; 163 apicd->prev_vector = apicd->vector;
147 apicd->prev_cpu = apicd->cpu; 164 apicd->prev_cpu = apicd->cpu;
148 } else { 165 } else {
149 apicd->prev_vector = 0; 166 irq_matrix_free(vector_matrix, apicd->cpu, apicd->vector,
167 managed);
150 } 168 }
151 169
170setnew:
152 apicd->vector = newvec; 171 apicd->vector = newvec;
153 apicd->cpu = newcpu; 172 apicd->cpu = newcpu;
154 BUG_ON(!IS_ERR_OR_NULL(per_cpu(vector_irq, newcpu)[newvec])); 173 BUG_ON(!IS_ERR_OR_NULL(per_cpu(vector_irq, newcpu)[newvec]));
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index 46b675aaf20b..f11910b44638 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -1176,16 +1176,25 @@ static void __init decode_gam_rng_tbl(unsigned long ptr)
1176 1176
1177 uv_gre_table = gre; 1177 uv_gre_table = gre;
1178 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) { 1178 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
1179 unsigned long size = ((unsigned long)(gre->limit - lgre)
1180 << UV_GAM_RANGE_SHFT);
1181 int order = 0;
1182 char suffix[] = " KMGTPE";
1183
1184 while (size > 9999 && order < sizeof(suffix)) {
1185 size /= 1024;
1186 order++;
1187 }
1188
1179 if (!index) { 1189 if (!index) {
1180 pr_info("UV: GAM Range Table...\n"); 1190 pr_info("UV: GAM Range Table...\n");
1181 pr_info("UV: # %20s %14s %5s %4s %5s %3s %2s\n", "Range", "", "Size", "Type", "NASID", "SID", "PN"); 1191 pr_info("UV: # %20s %14s %5s %4s %5s %3s %2s\n", "Range", "", "Size", "Type", "NASID", "SID", "PN");
1182 } 1192 }
1183 pr_info("UV: %2d: 0x%014lx-0x%014lx %5luG %3d %04x %02x %02x\n", 1193 pr_info("UV: %2d: 0x%014lx-0x%014lx %5lu%c %3d %04x %02x %02x\n",
1184 index++, 1194 index++,
1185 (unsigned long)lgre << UV_GAM_RANGE_SHFT, 1195 (unsigned long)lgre << UV_GAM_RANGE_SHFT,
1186 (unsigned long)gre->limit << UV_GAM_RANGE_SHFT, 1196 (unsigned long)gre->limit << UV_GAM_RANGE_SHFT,
1187 ((unsigned long)(gre->limit - lgre)) >> 1197 size, suffix[order],
1188 (30 - UV_GAM_RANGE_SHFT), /* 64M -> 1G */
1189 gre->type, gre->nasid, gre->sockid, gre->pnode); 1198 gre->type, gre->nasid, gre->sockid, gre->pnode);
1190 1199
1191 lgre = gre->limit; 1200 lgre = gre->limit;
diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
index fa1261eefa16..f91ba53e06c8 100644
--- a/arch/x86/kernel/asm-offsets_32.c
+++ b/arch/x86/kernel/asm-offsets_32.c
@@ -18,7 +18,7 @@ void foo(void)
18 OFFSET(CPUINFO_x86, cpuinfo_x86, x86); 18 OFFSET(CPUINFO_x86, cpuinfo_x86, x86);
19 OFFSET(CPUINFO_x86_vendor, cpuinfo_x86, x86_vendor); 19 OFFSET(CPUINFO_x86_vendor, cpuinfo_x86, x86_vendor);
20 OFFSET(CPUINFO_x86_model, cpuinfo_x86, x86_model); 20 OFFSET(CPUINFO_x86_model, cpuinfo_x86, x86_model);
21 OFFSET(CPUINFO_x86_mask, cpuinfo_x86, x86_mask); 21 OFFSET(CPUINFO_x86_stepping, cpuinfo_x86, x86_stepping);
22 OFFSET(CPUINFO_cpuid_level, cpuinfo_x86, cpuid_level); 22 OFFSET(CPUINFO_cpuid_level, cpuinfo_x86, cpuid_level);
23 OFFSET(CPUINFO_x86_capability, cpuinfo_x86, x86_capability); 23 OFFSET(CPUINFO_x86_capability, cpuinfo_x86, x86_capability);
24 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id); 24 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 5bddbdcbc4a3..f0e6456ca7d3 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -119,7 +119,7 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
119 return; 119 return;
120 } 120 }
121 121
122 if (c->x86_model == 6 && c->x86_mask == 1) { 122 if (c->x86_model == 6 && c->x86_stepping == 1) {
123 const int K6_BUG_LOOP = 1000000; 123 const int K6_BUG_LOOP = 1000000;
124 int n; 124 int n;
125 void (*f_vide)(void); 125 void (*f_vide)(void);
@@ -149,7 +149,7 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
149 149
150 /* K6 with old style WHCR */ 150 /* K6 with old style WHCR */
151 if (c->x86_model < 8 || 151 if (c->x86_model < 8 ||
152 (c->x86_model == 8 && c->x86_mask < 8)) { 152 (c->x86_model == 8 && c->x86_stepping < 8)) {
153 /* We can only write allocate on the low 508Mb */ 153 /* We can only write allocate on the low 508Mb */
154 if (mbytes > 508) 154 if (mbytes > 508)
155 mbytes = 508; 155 mbytes = 508;
@@ -168,7 +168,7 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
168 return; 168 return;
169 } 169 }
170 170
171 if ((c->x86_model == 8 && c->x86_mask > 7) || 171 if ((c->x86_model == 8 && c->x86_stepping > 7) ||
172 c->x86_model == 9 || c->x86_model == 13) { 172 c->x86_model == 9 || c->x86_model == 13) {
173 /* The more serious chips .. */ 173 /* The more serious chips .. */
174 174
@@ -221,7 +221,7 @@ static void init_amd_k7(struct cpuinfo_x86 *c)
221 * are more robust with CLK_CTL set to 200xxxxx instead of 600xxxxx 221 * are more robust with CLK_CTL set to 200xxxxx instead of 600xxxxx
222 * As per AMD technical note 27212 0.2 222 * As per AMD technical note 27212 0.2
223 */ 223 */
224 if ((c->x86_model == 8 && c->x86_mask >= 1) || (c->x86_model > 8)) { 224 if ((c->x86_model == 8 && c->x86_stepping >= 1) || (c->x86_model > 8)) {
225 rdmsr(MSR_K7_CLK_CTL, l, h); 225 rdmsr(MSR_K7_CLK_CTL, l, h);
226 if ((l & 0xfff00000) != 0x20000000) { 226 if ((l & 0xfff00000) != 0x20000000) {
227 pr_info("CPU: CLK_CTL MSR was %x. Reprogramming to %x\n", 227 pr_info("CPU: CLK_CTL MSR was %x. Reprogramming to %x\n",
@@ -241,12 +241,12 @@ static void init_amd_k7(struct cpuinfo_x86 *c)
241 * but they are not certified as MP capable. 241 * but they are not certified as MP capable.
242 */ 242 */
243 /* Athlon 660/661 is valid. */ 243 /* Athlon 660/661 is valid. */
244 if ((c->x86_model == 6) && ((c->x86_mask == 0) || 244 if ((c->x86_model == 6) && ((c->x86_stepping == 0) ||
245 (c->x86_mask == 1))) 245 (c->x86_stepping == 1)))
246 return; 246 return;
247 247
248 /* Duron 670 is valid */ 248 /* Duron 670 is valid */
249 if ((c->x86_model == 7) && (c->x86_mask == 0)) 249 if ((c->x86_model == 7) && (c->x86_stepping == 0))
250 return; 250 return;
251 251
252 /* 252 /*
@@ -256,8 +256,8 @@ static void init_amd_k7(struct cpuinfo_x86 *c)
256 * See http://www.heise.de/newsticker/data/jow-18.10.01-000 for 256 * See http://www.heise.de/newsticker/data/jow-18.10.01-000 for
257 * more. 257 * more.
258 */ 258 */
259 if (((c->x86_model == 6) && (c->x86_mask >= 2)) || 259 if (((c->x86_model == 6) && (c->x86_stepping >= 2)) ||
260 ((c->x86_model == 7) && (c->x86_mask >= 1)) || 260 ((c->x86_model == 7) && (c->x86_stepping >= 1)) ||
261 (c->x86_model > 7)) 261 (c->x86_model > 7))
262 if (cpu_has(c, X86_FEATURE_MP)) 262 if (cpu_has(c, X86_FEATURE_MP))
263 return; 263 return;
@@ -628,7 +628,7 @@ static void early_init_amd(struct cpuinfo_x86 *c)
628 /* Set MTRR capability flag if appropriate */ 628 /* Set MTRR capability flag if appropriate */
629 if (c->x86 == 5) 629 if (c->x86 == 5)
630 if (c->x86_model == 13 || c->x86_model == 9 || 630 if (c->x86_model == 13 || c->x86_model == 9 ||
631 (c->x86_model == 8 && c->x86_mask >= 8)) 631 (c->x86_model == 8 && c->x86_stepping >= 8))
632 set_cpu_cap(c, X86_FEATURE_K6_MTRR); 632 set_cpu_cap(c, X86_FEATURE_K6_MTRR);
633#endif 633#endif
634#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_PCI) 634#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_PCI)
@@ -795,7 +795,7 @@ static void init_amd_zn(struct cpuinfo_x86 *c)
795 * Fix erratum 1076: CPB feature bit not being set in CPUID. It affects 795 * Fix erratum 1076: CPB feature bit not being set in CPUID. It affects
796 * all up to and including B1. 796 * all up to and including B1.
797 */ 797 */
798 if (c->x86_model <= 1 && c->x86_mask <= 1) 798 if (c->x86_model <= 1 && c->x86_stepping <= 1)
799 set_cpu_cap(c, X86_FEATURE_CPB); 799 set_cpu_cap(c, X86_FEATURE_CPB);
800} 800}
801 801
@@ -906,11 +906,11 @@ static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
906 /* AMD errata T13 (order #21922) */ 906 /* AMD errata T13 (order #21922) */
907 if ((c->x86 == 6)) { 907 if ((c->x86 == 6)) {
908 /* Duron Rev A0 */ 908 /* Duron Rev A0 */
909 if (c->x86_model == 3 && c->x86_mask == 0) 909 if (c->x86_model == 3 && c->x86_stepping == 0)
910 size = 64; 910 size = 64;
911 /* Tbird rev A1/A2 */ 911 /* Tbird rev A1/A2 */
912 if (c->x86_model == 4 && 912 if (c->x86_model == 4 &&
913 (c->x86_mask == 0 || c->x86_mask == 1)) 913 (c->x86_stepping == 0 || c->x86_stepping == 1))
914 size = 256; 914 size = 256;
915 } 915 }
916 return size; 916 return size;
@@ -1047,7 +1047,7 @@ static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum)
1047 } 1047 }
1048 1048
1049 /* OSVW unavailable or ID unknown, match family-model-stepping range */ 1049 /* OSVW unavailable or ID unknown, match family-model-stepping range */
1050 ms = (cpu->x86_model << 4) | cpu->x86_mask; 1050 ms = (cpu->x86_model << 4) | cpu->x86_stepping;
1051 while ((range = *erratum++)) 1051 while ((range = *erratum++))
1052 if ((cpu->x86 == AMD_MODEL_RANGE_FAMILY(range)) && 1052 if ((cpu->x86 == AMD_MODEL_RANGE_FAMILY(range)) &&
1053 (ms >= AMD_MODEL_RANGE_START(range)) && 1053 (ms >= AMD_MODEL_RANGE_START(range)) &&
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 71949bf2de5a..bfca937bdcc3 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -162,8 +162,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
162 if (cmdline_find_option_bool(boot_command_line, "nospectre_v2")) 162 if (cmdline_find_option_bool(boot_command_line, "nospectre_v2"))
163 return SPECTRE_V2_CMD_NONE; 163 return SPECTRE_V2_CMD_NONE;
164 else { 164 else {
165 ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, 165 ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg));
166 sizeof(arg));
167 if (ret < 0) 166 if (ret < 0)
168 return SPECTRE_V2_CMD_AUTO; 167 return SPECTRE_V2_CMD_AUTO;
169 168
@@ -175,8 +174,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
175 } 174 }
176 175
177 if (i >= ARRAY_SIZE(mitigation_options)) { 176 if (i >= ARRAY_SIZE(mitigation_options)) {
178 pr_err("unknown option (%s). Switching to AUTO select\n", 177 pr_err("unknown option (%s). Switching to AUTO select\n", arg);
179 mitigation_options[i].option);
180 return SPECTRE_V2_CMD_AUTO; 178 return SPECTRE_V2_CMD_AUTO;
181 } 179 }
182 } 180 }
@@ -185,8 +183,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
185 cmd == SPECTRE_V2_CMD_RETPOLINE_AMD || 183 cmd == SPECTRE_V2_CMD_RETPOLINE_AMD ||
186 cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC) && 184 cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC) &&
187 !IS_ENABLED(CONFIG_RETPOLINE)) { 185 !IS_ENABLED(CONFIG_RETPOLINE)) {
188 pr_err("%s selected but not compiled in. Switching to AUTO select\n", 186 pr_err("%s selected but not compiled in. Switching to AUTO select\n", mitigation_options[i].option);
189 mitigation_options[i].option);
190 return SPECTRE_V2_CMD_AUTO; 187 return SPECTRE_V2_CMD_AUTO;
191 } 188 }
192 189
@@ -256,14 +253,14 @@ static void __init spectre_v2_select_mitigation(void)
256 goto retpoline_auto; 253 goto retpoline_auto;
257 break; 254 break;
258 } 255 }
259 pr_err("kernel not compiled with retpoline; no mitigation available!"); 256 pr_err("Spectre mitigation: kernel not compiled with retpoline; no mitigation available!");
260 return; 257 return;
261 258
262retpoline_auto: 259retpoline_auto:
263 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { 260 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
264 retpoline_amd: 261 retpoline_amd:
265 if (!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) { 262 if (!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
266 pr_err("LFENCE not serializing. Switching to generic retpoline\n"); 263 pr_err("Spectre mitigation: LFENCE not serializing, switching to generic retpoline\n");
267 goto retpoline_generic; 264 goto retpoline_generic;
268 } 265 }
269 mode = retp_compiler() ? SPECTRE_V2_RETPOLINE_AMD : 266 mode = retp_compiler() ? SPECTRE_V2_RETPOLINE_AMD :
@@ -281,7 +278,7 @@ retpoline_auto:
281 pr_info("%s\n", spectre_v2_strings[mode]); 278 pr_info("%s\n", spectre_v2_strings[mode]);
282 279
283 /* 280 /*
284 * If neither SMEP or KPTI are available, there is a risk of 281 * If neither SMEP nor PTI are available, there is a risk of
285 * hitting userspace addresses in the RSB after a context switch 282 * hitting userspace addresses in the RSB after a context switch
286 * from a shallow call stack to a deeper one. To prevent this fill 283 * from a shallow call stack to a deeper one. To prevent this fill
287 * the entire RSB, even when using IBRS. 284 * the entire RSB, even when using IBRS.
@@ -295,21 +292,29 @@ retpoline_auto:
295 if ((!boot_cpu_has(X86_FEATURE_PTI) && 292 if ((!boot_cpu_has(X86_FEATURE_PTI) &&
296 !boot_cpu_has(X86_FEATURE_SMEP)) || is_skylake_era()) { 293 !boot_cpu_has(X86_FEATURE_SMEP)) || is_skylake_era()) {
297 setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW); 294 setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
298 pr_info("Filling RSB on context switch\n"); 295 pr_info("Spectre v2 mitigation: Filling RSB on context switch\n");
299 } 296 }
300 297
301 /* Initialize Indirect Branch Prediction Barrier if supported */ 298 /* Initialize Indirect Branch Prediction Barrier if supported */
302 if (boot_cpu_has(X86_FEATURE_IBPB)) { 299 if (boot_cpu_has(X86_FEATURE_IBPB)) {
303 setup_force_cpu_cap(X86_FEATURE_USE_IBPB); 300 setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
304 pr_info("Enabling Indirect Branch Prediction Barrier\n"); 301 pr_info("Spectre v2 mitigation: Enabling Indirect Branch Prediction Barrier\n");
302 }
303
304 /*
305 * Retpoline means the kernel is safe because it has no indirect
306 * branches. But firmware isn't, so use IBRS to protect that.
307 */
308 if (boot_cpu_has(X86_FEATURE_IBRS)) {
309 setup_force_cpu_cap(X86_FEATURE_USE_IBRS_FW);
310 pr_info("Enabling Restricted Speculation for firmware calls\n");
305 } 311 }
306} 312}
307 313
308#undef pr_fmt 314#undef pr_fmt
309 315
310#ifdef CONFIG_SYSFS 316#ifdef CONFIG_SYSFS
311ssize_t cpu_show_meltdown(struct device *dev, 317ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf)
312 struct device_attribute *attr, char *buf)
313{ 318{
314 if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN)) 319 if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN))
315 return sprintf(buf, "Not affected\n"); 320 return sprintf(buf, "Not affected\n");
@@ -318,28 +323,21 @@ ssize_t cpu_show_meltdown(struct device *dev,
318 return sprintf(buf, "Vulnerable\n"); 323 return sprintf(buf, "Vulnerable\n");
319} 324}
320 325
321ssize_t cpu_show_spectre_v1(struct device *dev, 326ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf)
322 struct device_attribute *attr, char *buf)
323{ 327{
324 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1)) 328 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1))
325 return sprintf(buf, "Not affected\n"); 329 return sprintf(buf, "Not affected\n");
326 return sprintf(buf, "Mitigation: __user pointer sanitization\n"); 330 return sprintf(buf, "Mitigation: __user pointer sanitization\n");
327} 331}
328 332
329ssize_t cpu_show_spectre_v2(struct device *dev, 333ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf)
330 struct device_attribute *attr, char *buf)
331{ 334{
332 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) 335 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2))
333 return sprintf(buf, "Not affected\n"); 336 return sprintf(buf, "Not affected\n");
334 337
335 return sprintf(buf, "%s%s%s\n", spectre_v2_strings[spectre_v2_enabled], 338 return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
336 boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "", 339 boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
340 boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",
337 spectre_v2_module_string()); 341 spectre_v2_module_string());
338} 342}
339#endif 343#endif
340
341void __ibp_barrier(void)
342{
343 __wrmsr(MSR_IA32_PRED_CMD, PRED_CMD_IBPB, 0);
344}
345EXPORT_SYMBOL_GPL(__ibp_barrier);
diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index c578cd29c2d2..e5ec0f11c0de 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -140,7 +140,7 @@ static void init_centaur(struct cpuinfo_x86 *c)
140 clear_cpu_cap(c, X86_FEATURE_TSC); 140 clear_cpu_cap(c, X86_FEATURE_TSC);
141 break; 141 break;
142 case 8: 142 case 8:
143 switch (c->x86_mask) { 143 switch (c->x86_stepping) {
144 default: 144 default:
145 name = "2"; 145 name = "2";
146 break; 146 break;
@@ -215,7 +215,7 @@ centaur_size_cache(struct cpuinfo_x86 *c, unsigned int size)
215 * - Note, it seems this may only be in engineering samples. 215 * - Note, it seems this may only be in engineering samples.
216 */ 216 */
217 if ((c->x86 == 6) && (c->x86_model == 9) && 217 if ((c->x86 == 6) && (c->x86_model == 9) &&
218 (c->x86_mask == 1) && (size == 65)) 218 (c->x86_stepping == 1) && (size == 65))
219 size -= 1; 219 size -= 1;
220 return size; 220 return size;
221} 221}
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index d63f4b5706e4..348cf4821240 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -731,7 +731,7 @@ void cpu_detect(struct cpuinfo_x86 *c)
731 cpuid(0x00000001, &tfms, &misc, &junk, &cap0); 731 cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
732 c->x86 = x86_family(tfms); 732 c->x86 = x86_family(tfms);
733 c->x86_model = x86_model(tfms); 733 c->x86_model = x86_model(tfms);
734 c->x86_mask = x86_stepping(tfms); 734 c->x86_stepping = x86_stepping(tfms);
735 735
736 if (cap0 & (1<<19)) { 736 if (cap0 & (1<<19)) {
737 c->x86_clflush_size = ((misc >> 8) & 0xff) * 8; 737 c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
@@ -1184,9 +1184,9 @@ static void identify_cpu(struct cpuinfo_x86 *c)
1184 int i; 1184 int i;
1185 1185
1186 c->loops_per_jiffy = loops_per_jiffy; 1186 c->loops_per_jiffy = loops_per_jiffy;
1187 c->x86_cache_size = -1; 1187 c->x86_cache_size = 0;
1188 c->x86_vendor = X86_VENDOR_UNKNOWN; 1188 c->x86_vendor = X86_VENDOR_UNKNOWN;
1189 c->x86_model = c->x86_mask = 0; /* So far unknown... */ 1189 c->x86_model = c->x86_stepping = 0; /* So far unknown... */
1190 c->x86_vendor_id[0] = '\0'; /* Unset */ 1190 c->x86_vendor_id[0] = '\0'; /* Unset */
1191 c->x86_model_id[0] = '\0'; /* Unset */ 1191 c->x86_model_id[0] = '\0'; /* Unset */
1192 c->x86_max_cores = 1; 1192 c->x86_max_cores = 1;
@@ -1378,8 +1378,8 @@ void print_cpu_info(struct cpuinfo_x86 *c)
1378 1378
1379 pr_cont(" (family: 0x%x, model: 0x%x", c->x86, c->x86_model); 1379 pr_cont(" (family: 0x%x, model: 0x%x", c->x86, c->x86_model);
1380 1380
1381 if (c->x86_mask || c->cpuid_level >= 0) 1381 if (c->x86_stepping || c->cpuid_level >= 0)
1382 pr_cont(", stepping: 0x%x)\n", c->x86_mask); 1382 pr_cont(", stepping: 0x%x)\n", c->x86_stepping);
1383 else 1383 else
1384 pr_cont(")\n"); 1384 pr_cont(")\n");
1385} 1385}
@@ -1749,3 +1749,33 @@ static int __init init_cpu_syscore(void)
1749 return 0; 1749 return 0;
1750} 1750}
1751core_initcall(init_cpu_syscore); 1751core_initcall(init_cpu_syscore);
1752
1753/*
1754 * The microcode loader calls this upon late microcode load to recheck features,
1755 * only when microcode has been updated. Caller holds microcode_mutex and CPU
1756 * hotplug lock.
1757 */
1758void microcode_check(void)
1759{
1760 struct cpuinfo_x86 info;
1761
1762 perf_check_microcode();
1763
1764 /* Reload CPUID max function as it might've changed. */
1765 info.cpuid_level = cpuid_eax(0);
1766
1767 /*
1768 * Copy all capability leafs to pick up the synthetic ones so that
1769 * memcmp() below doesn't fail on that. The ones coming from CPUID will
1770 * get overwritten in get_cpu_cap().
1771 */
1772 memcpy(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability));
1773
1774 get_cpu_cap(&info);
1775
1776 if (!memcmp(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability)))
1777 return;
1778
1779 pr_warn("x86/CPU: CPU features have changed after loading microcode, but might not take effect.\n");
1780 pr_warn("x86/CPU: Please consider either early loading through initrd/built-in or a potential BIOS update.\n");
1781}
diff --git a/arch/x86/kernel/cpu/cyrix.c b/arch/x86/kernel/cpu/cyrix.c
index 6b4bb335641f..8949b7ae6d92 100644
--- a/arch/x86/kernel/cpu/cyrix.c
+++ b/arch/x86/kernel/cpu/cyrix.c
@@ -215,7 +215,7 @@ static void init_cyrix(struct cpuinfo_x86 *c)
215 215
216 /* common case step number/rev -- exceptions handled below */ 216 /* common case step number/rev -- exceptions handled below */
217 c->x86_model = (dir1 >> 4) + 1; 217 c->x86_model = (dir1 >> 4) + 1;
218 c->x86_mask = dir1 & 0xf; 218 c->x86_stepping = dir1 & 0xf;
219 219
220 /* Now cook; the original recipe is by Channing Corn, from Cyrix. 220 /* Now cook; the original recipe is by Channing Corn, from Cyrix.
221 * We do the same thing for each generation: we work out 221 * We do the same thing for each generation: we work out
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index 319bf989fad1..c3af167d0a70 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -105,7 +105,7 @@ static void probe_xeon_phi_r3mwait(struct cpuinfo_x86 *c)
105/* 105/*
106 * Early microcode releases for the Spectre v2 mitigation were broken. 106 * Early microcode releases for the Spectre v2 mitigation were broken.
107 * Information taken from; 107 * Information taken from;
108 * - https://newsroom.intel.com/wp-content/uploads/sites/11/2018/01/microcode-update-guidance.pdf 108 * - https://newsroom.intel.com/wp-content/uploads/sites/11/2018/03/microcode-update-guidance.pdf
109 * - https://kb.vmware.com/s/article/52345 109 * - https://kb.vmware.com/s/article/52345
110 * - Microcode revisions observed in the wild 110 * - Microcode revisions observed in the wild
111 * - Release note from 20180108 microcode release 111 * - Release note from 20180108 microcode release
@@ -116,15 +116,13 @@ struct sku_microcode {
116 u32 microcode; 116 u32 microcode;
117}; 117};
118static const struct sku_microcode spectre_bad_microcodes[] = { 118static const struct sku_microcode spectre_bad_microcodes[] = {
119 { INTEL_FAM6_KABYLAKE_DESKTOP, 0x0B, 0x84 }, 119 { INTEL_FAM6_KABYLAKE_DESKTOP, 0x0B, 0x80 },
120 { INTEL_FAM6_KABYLAKE_DESKTOP, 0x0A, 0x84 }, 120 { INTEL_FAM6_KABYLAKE_DESKTOP, 0x0A, 0x80 },
121 { INTEL_FAM6_KABYLAKE_DESKTOP, 0x09, 0x84 }, 121 { INTEL_FAM6_KABYLAKE_DESKTOP, 0x09, 0x80 },
122 { INTEL_FAM6_KABYLAKE_MOBILE, 0x0A, 0x84 }, 122 { INTEL_FAM6_KABYLAKE_MOBILE, 0x0A, 0x80 },
123 { INTEL_FAM6_KABYLAKE_MOBILE, 0x09, 0x84 }, 123 { INTEL_FAM6_KABYLAKE_MOBILE, 0x09, 0x80 },
124 { INTEL_FAM6_SKYLAKE_X, 0x03, 0x0100013e }, 124 { INTEL_FAM6_SKYLAKE_X, 0x03, 0x0100013e },
125 { INTEL_FAM6_SKYLAKE_X, 0x04, 0x0200003c }, 125 { INTEL_FAM6_SKYLAKE_X, 0x04, 0x0200003c },
126 { INTEL_FAM6_SKYLAKE_MOBILE, 0x03, 0xc2 },
127 { INTEL_FAM6_SKYLAKE_DESKTOP, 0x03, 0xc2 },
128 { INTEL_FAM6_BROADWELL_CORE, 0x04, 0x28 }, 126 { INTEL_FAM6_BROADWELL_CORE, 0x04, 0x28 },
129 { INTEL_FAM6_BROADWELL_GT3E, 0x01, 0x1b }, 127 { INTEL_FAM6_BROADWELL_GT3E, 0x01, 0x1b },
130 { INTEL_FAM6_BROADWELL_XEON_D, 0x02, 0x14 }, 128 { INTEL_FAM6_BROADWELL_XEON_D, 0x02, 0x14 },
@@ -136,8 +134,6 @@ static const struct sku_microcode spectre_bad_microcodes[] = {
136 { INTEL_FAM6_HASWELL_X, 0x02, 0x3b }, 134 { INTEL_FAM6_HASWELL_X, 0x02, 0x3b },
137 { INTEL_FAM6_HASWELL_X, 0x04, 0x10 }, 135 { INTEL_FAM6_HASWELL_X, 0x04, 0x10 },
138 { INTEL_FAM6_IVYBRIDGE_X, 0x04, 0x42a }, 136 { INTEL_FAM6_IVYBRIDGE_X, 0x04, 0x42a },
139 /* Updated in the 20180108 release; blacklist until we know otherwise */
140 { INTEL_FAM6_ATOM_GEMINI_LAKE, 0x01, 0x22 },
141 /* Observed in the wild */ 137 /* Observed in the wild */
142 { INTEL_FAM6_SANDYBRIDGE_X, 0x06, 0x61b }, 138 { INTEL_FAM6_SANDYBRIDGE_X, 0x06, 0x61b },
143 { INTEL_FAM6_SANDYBRIDGE_X, 0x07, 0x712 }, 139 { INTEL_FAM6_SANDYBRIDGE_X, 0x07, 0x712 },
@@ -147,9 +143,16 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
147{ 143{
148 int i; 144 int i;
149 145
146 /*
147 * We know that the hypervisor lie to us on the microcode version so
148 * we may as well hope that it is running the correct version.
149 */
150 if (cpu_has(c, X86_FEATURE_HYPERVISOR))
151 return false;
152
150 for (i = 0; i < ARRAY_SIZE(spectre_bad_microcodes); i++) { 153 for (i = 0; i < ARRAY_SIZE(spectre_bad_microcodes); i++) {
151 if (c->x86_model == spectre_bad_microcodes[i].model && 154 if (c->x86_model == spectre_bad_microcodes[i].model &&
152 c->x86_mask == spectre_bad_microcodes[i].stepping) 155 c->x86_stepping == spectre_bad_microcodes[i].stepping)
153 return (c->microcode <= spectre_bad_microcodes[i].microcode); 156 return (c->microcode <= spectre_bad_microcodes[i].microcode);
154 } 157 }
155 return false; 158 return false;
@@ -196,7 +199,7 @@ static void early_init_intel(struct cpuinfo_x86 *c)
196 * need the microcode to have already been loaded... so if it is 199 * need the microcode to have already been loaded... so if it is
197 * not, recommend a BIOS update and disable large pages. 200 * not, recommend a BIOS update and disable large pages.
198 */ 201 */
199 if (c->x86 == 6 && c->x86_model == 0x1c && c->x86_mask <= 2 && 202 if (c->x86 == 6 && c->x86_model == 0x1c && c->x86_stepping <= 2 &&
200 c->microcode < 0x20e) { 203 c->microcode < 0x20e) {
201 pr_warn("Atom PSE erratum detected, BIOS microcode update recommended\n"); 204 pr_warn("Atom PSE erratum detected, BIOS microcode update recommended\n");
202 clear_cpu_cap(c, X86_FEATURE_PSE); 205 clear_cpu_cap(c, X86_FEATURE_PSE);
@@ -212,7 +215,7 @@ static void early_init_intel(struct cpuinfo_x86 *c)
212 215
213 /* CPUID workaround for 0F33/0F34 CPU */ 216 /* CPUID workaround for 0F33/0F34 CPU */
214 if (c->x86 == 0xF && c->x86_model == 0x3 217 if (c->x86 == 0xF && c->x86_model == 0x3
215 && (c->x86_mask == 0x3 || c->x86_mask == 0x4)) 218 && (c->x86_stepping == 0x3 || c->x86_stepping == 0x4))
216 c->x86_phys_bits = 36; 219 c->x86_phys_bits = 36;
217 220
218 /* 221 /*
@@ -310,7 +313,7 @@ int ppro_with_ram_bug(void)
310 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && 313 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
311 boot_cpu_data.x86 == 6 && 314 boot_cpu_data.x86 == 6 &&
312 boot_cpu_data.x86_model == 1 && 315 boot_cpu_data.x86_model == 1 &&
313 boot_cpu_data.x86_mask < 8) { 316 boot_cpu_data.x86_stepping < 8) {
314 pr_info("Pentium Pro with Errata#50 detected. Taking evasive action.\n"); 317 pr_info("Pentium Pro with Errata#50 detected. Taking evasive action.\n");
315 return 1; 318 return 1;
316 } 319 }
@@ -327,7 +330,7 @@ static void intel_smp_check(struct cpuinfo_x86 *c)
327 * Mask B, Pentium, but not Pentium MMX 330 * Mask B, Pentium, but not Pentium MMX
328 */ 331 */
329 if (c->x86 == 5 && 332 if (c->x86 == 5 &&
330 c->x86_mask >= 1 && c->x86_mask <= 4 && 333 c->x86_stepping >= 1 && c->x86_stepping <= 4 &&
331 c->x86_model <= 3) { 334 c->x86_model <= 3) {
332 /* 335 /*
333 * Remember we have B step Pentia with bugs 336 * Remember we have B step Pentia with bugs
@@ -370,7 +373,7 @@ static void intel_workarounds(struct cpuinfo_x86 *c)
370 * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until 373 * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
371 * model 3 mask 3 374 * model 3 mask 3
372 */ 375 */
373 if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633) 376 if ((c->x86<<8 | c->x86_model<<4 | c->x86_stepping) < 0x633)
374 clear_cpu_cap(c, X86_FEATURE_SEP); 377 clear_cpu_cap(c, X86_FEATURE_SEP);
375 378
376 /* 379 /*
@@ -388,7 +391,7 @@ static void intel_workarounds(struct cpuinfo_x86 *c)
388 * P4 Xeon erratum 037 workaround. 391 * P4 Xeon erratum 037 workaround.
389 * Hardware prefetcher may cause stale data to be loaded into the cache. 392 * Hardware prefetcher may cause stale data to be loaded into the cache.
390 */ 393 */
391 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) { 394 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_stepping == 1)) {
392 if (msr_set_bit(MSR_IA32_MISC_ENABLE, 395 if (msr_set_bit(MSR_IA32_MISC_ENABLE,
393 MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT) > 0) { 396 MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT) > 0) {
394 pr_info("CPU: C0 stepping P4 Xeon detected.\n"); 397 pr_info("CPU: C0 stepping P4 Xeon detected.\n");
@@ -403,7 +406,7 @@ static void intel_workarounds(struct cpuinfo_x86 *c)
403 * Specification Update"). 406 * Specification Update").
404 */ 407 */
405 if (boot_cpu_has(X86_FEATURE_APIC) && (c->x86<<8 | c->x86_model<<4) == 0x520 && 408 if (boot_cpu_has(X86_FEATURE_APIC) && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
406 (c->x86_mask < 0x6 || c->x86_mask == 0xb)) 409 (c->x86_stepping < 0x6 || c->x86_stepping == 0xb))
407 set_cpu_bug(c, X86_BUG_11AP); 410 set_cpu_bug(c, X86_BUG_11AP);
408 411
409 412
@@ -650,7 +653,7 @@ static void init_intel(struct cpuinfo_x86 *c)
650 case 6: 653 case 6:
651 if (l2 == 128) 654 if (l2 == 128)
652 p = "Celeron (Mendocino)"; 655 p = "Celeron (Mendocino)";
653 else if (c->x86_mask == 0 || c->x86_mask == 5) 656 else if (c->x86_stepping == 0 || c->x86_stepping == 5)
654 p = "Celeron-A"; 657 p = "Celeron-A";
655 break; 658 break;
656 659
diff --git a/arch/x86/kernel/cpu/intel_rdt.c b/arch/x86/kernel/cpu/intel_rdt.c
index 410629f10ad3..589b948e6e01 100644
--- a/arch/x86/kernel/cpu/intel_rdt.c
+++ b/arch/x86/kernel/cpu/intel_rdt.c
@@ -819,7 +819,7 @@ static __init void rdt_quirks(void)
819 cache_alloc_hsw_probe(); 819 cache_alloc_hsw_probe();
820 break; 820 break;
821 case INTEL_FAM6_SKYLAKE_X: 821 case INTEL_FAM6_SKYLAKE_X:
822 if (boot_cpu_data.x86_mask <= 4) 822 if (boot_cpu_data.x86_stepping <= 4)
823 set_rdt_options("!cmt,!mbmtotal,!mbmlocal,!l3cat"); 823 set_rdt_options("!cmt,!mbmtotal,!mbmlocal,!l3cat");
824 } 824 }
825} 825}
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index bdab7d2f51af..fca759d272a1 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -1804,6 +1804,7 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
1804 goto out_common_fail; 1804 goto out_common_fail;
1805 } 1805 }
1806 closid = ret; 1806 closid = ret;
1807 ret = 0;
1807 1808
1808 rdtgrp->closid = closid; 1809 rdtgrp->closid = closid;
1809 list_add(&rdtgrp->rdtgroup_list, &rdt_all_groups); 1810 list_add(&rdtgrp->rdtgroup_list, &rdt_all_groups);
diff --git a/arch/x86/kernel/cpu/mcheck/mce-internal.h b/arch/x86/kernel/cpu/mcheck/mce-internal.h
index aa0d5df9dc60..e956eb267061 100644
--- a/arch/x86/kernel/cpu/mcheck/mce-internal.h
+++ b/arch/x86/kernel/cpu/mcheck/mce-internal.h
@@ -115,4 +115,19 @@ static inline void mce_unregister_injector_chain(struct notifier_block *nb) { }
115 115
116extern struct mca_config mca_cfg; 116extern struct mca_config mca_cfg;
117 117
118#ifndef CONFIG_X86_64
119/*
120 * On 32-bit systems it would be difficult to safely unmap a poison page
121 * from the kernel 1:1 map because there are no non-canonical addresses that
122 * we can use to refer to the address without risking a speculative access.
123 * However, this isn't much of an issue because:
124 * 1) Few unmappable pages are in the 1:1 map. Most are in HIGHMEM which
125 * are only mapped into the kernel as needed
126 * 2) Few people would run a 32-bit kernel on a machine that supports
127 * recoverable errors because they have too much memory to boot 32-bit.
128 */
129static inline void mce_unmap_kpfn(unsigned long pfn) {}
130#define mce_unmap_kpfn mce_unmap_kpfn
131#endif
132
118#endif /* __X86_MCE_INTERNAL_H__ */ 133#endif /* __X86_MCE_INTERNAL_H__ */
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 3a8e88a611eb..466f47301334 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -56,6 +56,9 @@
56 56
57static DEFINE_MUTEX(mce_log_mutex); 57static DEFINE_MUTEX(mce_log_mutex);
58 58
59/* sysfs synchronization */
60static DEFINE_MUTEX(mce_sysfs_mutex);
61
59#define CREATE_TRACE_POINTS 62#define CREATE_TRACE_POINTS
60#include <trace/events/mce.h> 63#include <trace/events/mce.h>
61 64
@@ -105,6 +108,10 @@ static struct irq_work mce_irq_work;
105 108
106static void (*quirk_no_way_out)(int bank, struct mce *m, struct pt_regs *regs); 109static void (*quirk_no_way_out)(int bank, struct mce *m, struct pt_regs *regs);
107 110
111#ifndef mce_unmap_kpfn
112static void mce_unmap_kpfn(unsigned long pfn);
113#endif
114
108/* 115/*
109 * CPU/chipset specific EDAC code can register a notifier call here to print 116 * CPU/chipset specific EDAC code can register a notifier call here to print
110 * MCE errors in a human-readable form. 117 * MCE errors in a human-readable form.
@@ -126,6 +133,8 @@ void mce_setup(struct mce *m)
126 133
127 if (this_cpu_has(X86_FEATURE_INTEL_PPIN)) 134 if (this_cpu_has(X86_FEATURE_INTEL_PPIN))
128 rdmsrl(MSR_PPIN, m->ppin); 135 rdmsrl(MSR_PPIN, m->ppin);
136
137 m->microcode = boot_cpu_data.microcode;
129} 138}
130 139
131DEFINE_PER_CPU(struct mce, injectm); 140DEFINE_PER_CPU(struct mce, injectm);
@@ -234,7 +243,7 @@ static void __print_mce(struct mce *m)
234 m->cs, m->ip); 243 m->cs, m->ip);
235 244
236 if (m->cs == __KERNEL_CS) 245 if (m->cs == __KERNEL_CS)
237 pr_cont("{%pS}", (void *)m->ip); 246 pr_cont("{%pS}", (void *)(unsigned long)m->ip);
238 pr_cont("\n"); 247 pr_cont("\n");
239 } 248 }
240 249
@@ -258,7 +267,7 @@ static void __print_mce(struct mce *m)
258 */ 267 */
259 pr_emerg(HW_ERR "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x microcode %x\n", 268 pr_emerg(HW_ERR "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x microcode %x\n",
260 m->cpuvendor, m->cpuid, m->time, m->socketid, m->apicid, 269 m->cpuvendor, m->cpuid, m->time, m->socketid, m->apicid,
261 cpu_data(m->extcpu).microcode); 270 m->microcode);
262} 271}
263 272
264static void print_mce(struct mce *m) 273static void print_mce(struct mce *m)
@@ -590,7 +599,8 @@ static int srao_decode_notifier(struct notifier_block *nb, unsigned long val,
590 599
591 if (mce_usable_address(mce) && (mce->severity == MCE_AO_SEVERITY)) { 600 if (mce_usable_address(mce) && (mce->severity == MCE_AO_SEVERITY)) {
592 pfn = mce->addr >> PAGE_SHIFT; 601 pfn = mce->addr >> PAGE_SHIFT;
593 memory_failure(pfn, 0); 602 if (!memory_failure(pfn, 0))
603 mce_unmap_kpfn(pfn);
594 } 604 }
595 605
596 return NOTIFY_OK; 606 return NOTIFY_OK;
@@ -1057,12 +1067,13 @@ static int do_memory_failure(struct mce *m)
1057 ret = memory_failure(m->addr >> PAGE_SHIFT, flags); 1067 ret = memory_failure(m->addr >> PAGE_SHIFT, flags);
1058 if (ret) 1068 if (ret)
1059 pr_err("Memory error not recovered"); 1069 pr_err("Memory error not recovered");
1070 else
1071 mce_unmap_kpfn(m->addr >> PAGE_SHIFT);
1060 return ret; 1072 return ret;
1061} 1073}
1062 1074
1063#if defined(arch_unmap_kpfn) && defined(CONFIG_MEMORY_FAILURE) 1075#ifndef mce_unmap_kpfn
1064 1076static void mce_unmap_kpfn(unsigned long pfn)
1065void arch_unmap_kpfn(unsigned long pfn)
1066{ 1077{
1067 unsigned long decoy_addr; 1078 unsigned long decoy_addr;
1068 1079
@@ -1073,7 +1084,7 @@ void arch_unmap_kpfn(unsigned long pfn)
1073 * We would like to just call: 1084 * We would like to just call:
1074 * set_memory_np((unsigned long)pfn_to_kaddr(pfn), 1); 1085 * set_memory_np((unsigned long)pfn_to_kaddr(pfn), 1);
1075 * but doing that would radically increase the odds of a 1086 * but doing that would radically increase the odds of a
1076 * speculative access to the posion page because we'd have 1087 * speculative access to the poison page because we'd have
1077 * the virtual address of the kernel 1:1 mapping sitting 1088 * the virtual address of the kernel 1:1 mapping sitting
1078 * around in registers. 1089 * around in registers.
1079 * Instead we get tricky. We create a non-canonical address 1090 * Instead we get tricky. We create a non-canonical address
@@ -1098,7 +1109,6 @@ void arch_unmap_kpfn(unsigned long pfn)
1098 1109
1099 if (set_memory_np(decoy_addr, 1)) 1110 if (set_memory_np(decoy_addr, 1))
1100 pr_warn("Could not invalidate pfn=0x%lx from 1:1 map\n", pfn); 1111 pr_warn("Could not invalidate pfn=0x%lx from 1:1 map\n", pfn);
1101
1102} 1112}
1103#endif 1113#endif
1104 1114
@@ -2081,6 +2091,7 @@ static ssize_t set_ignore_ce(struct device *s,
2081 if (kstrtou64(buf, 0, &new) < 0) 2091 if (kstrtou64(buf, 0, &new) < 0)
2082 return -EINVAL; 2092 return -EINVAL;
2083 2093
2094 mutex_lock(&mce_sysfs_mutex);
2084 if (mca_cfg.ignore_ce ^ !!new) { 2095 if (mca_cfg.ignore_ce ^ !!new) {
2085 if (new) { 2096 if (new) {
2086 /* disable ce features */ 2097 /* disable ce features */
@@ -2093,6 +2104,8 @@ static ssize_t set_ignore_ce(struct device *s,
2093 on_each_cpu(mce_enable_ce, (void *)1, 1); 2104 on_each_cpu(mce_enable_ce, (void *)1, 1);
2094 } 2105 }
2095 } 2106 }
2107 mutex_unlock(&mce_sysfs_mutex);
2108
2096 return size; 2109 return size;
2097} 2110}
2098 2111
@@ -2105,6 +2118,7 @@ static ssize_t set_cmci_disabled(struct device *s,
2105 if (kstrtou64(buf, 0, &new) < 0) 2118 if (kstrtou64(buf, 0, &new) < 0)
2106 return -EINVAL; 2119 return -EINVAL;
2107 2120
2121 mutex_lock(&mce_sysfs_mutex);
2108 if (mca_cfg.cmci_disabled ^ !!new) { 2122 if (mca_cfg.cmci_disabled ^ !!new) {
2109 if (new) { 2123 if (new) {
2110 /* disable cmci */ 2124 /* disable cmci */
@@ -2116,6 +2130,8 @@ static ssize_t set_cmci_disabled(struct device *s,
2116 on_each_cpu(mce_enable_ce, NULL, 1); 2130 on_each_cpu(mce_enable_ce, NULL, 1);
2117 } 2131 }
2118 } 2132 }
2133 mutex_unlock(&mce_sysfs_mutex);
2134
2119 return size; 2135 return size;
2120} 2136}
2121 2137
@@ -2123,8 +2139,19 @@ static ssize_t store_int_with_restart(struct device *s,
2123 struct device_attribute *attr, 2139 struct device_attribute *attr,
2124 const char *buf, size_t size) 2140 const char *buf, size_t size)
2125{ 2141{
2126 ssize_t ret = device_store_int(s, attr, buf, size); 2142 unsigned long old_check_interval = check_interval;
2143 ssize_t ret = device_store_ulong(s, attr, buf, size);
2144
2145 if (check_interval == old_check_interval)
2146 return ret;
2147
2148 if (check_interval < 1)
2149 check_interval = 1;
2150
2151 mutex_lock(&mce_sysfs_mutex);
2127 mce_restart(); 2152 mce_restart();
2153 mutex_unlock(&mce_sysfs_mutex);
2154
2128 return ret; 2155 return ret;
2129} 2156}
2130 2157
diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 330b8462d426..48179928ff38 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -339,7 +339,7 @@ int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax)
339 return -EINVAL; 339 return -EINVAL;
340 340
341 ret = load_microcode_amd(true, x86_family(cpuid_1_eax), desc.data, desc.size); 341 ret = load_microcode_amd(true, x86_family(cpuid_1_eax), desc.data, desc.size);
342 if (ret != UCODE_OK) 342 if (ret > UCODE_UPDATED)
343 return -EINVAL; 343 return -EINVAL;
344 344
345 return 0; 345 return 0;
@@ -498,7 +498,7 @@ static unsigned int verify_patch_size(u8 family, u32 patch_size,
498 return patch_size; 498 return patch_size;
499} 499}
500 500
501static int apply_microcode_amd(int cpu) 501static enum ucode_state apply_microcode_amd(int cpu)
502{ 502{
503 struct cpuinfo_x86 *c = &cpu_data(cpu); 503 struct cpuinfo_x86 *c = &cpu_data(cpu);
504 struct microcode_amd *mc_amd; 504 struct microcode_amd *mc_amd;
@@ -512,7 +512,7 @@ static int apply_microcode_amd(int cpu)
512 512
513 p = find_patch(cpu); 513 p = find_patch(cpu);
514 if (!p) 514 if (!p)
515 return 0; 515 return UCODE_NFOUND;
516 516
517 mc_amd = p->data; 517 mc_amd = p->data;
518 uci->mc = p->data; 518 uci->mc = p->data;
@@ -523,13 +523,13 @@ static int apply_microcode_amd(int cpu)
523 if (rev >= mc_amd->hdr.patch_id) { 523 if (rev >= mc_amd->hdr.patch_id) {
524 c->microcode = rev; 524 c->microcode = rev;
525 uci->cpu_sig.rev = rev; 525 uci->cpu_sig.rev = rev;
526 return 0; 526 return UCODE_OK;
527 } 527 }
528 528
529 if (__apply_microcode_amd(mc_amd)) { 529 if (__apply_microcode_amd(mc_amd)) {
530 pr_err("CPU%d: update failed for patch_level=0x%08x\n", 530 pr_err("CPU%d: update failed for patch_level=0x%08x\n",
531 cpu, mc_amd->hdr.patch_id); 531 cpu, mc_amd->hdr.patch_id);
532 return -1; 532 return UCODE_ERROR;
533 } 533 }
534 pr_info("CPU%d: new patch_level=0x%08x\n", cpu, 534 pr_info("CPU%d: new patch_level=0x%08x\n", cpu,
535 mc_amd->hdr.patch_id); 535 mc_amd->hdr.patch_id);
@@ -537,7 +537,7 @@ static int apply_microcode_amd(int cpu)
537 uci->cpu_sig.rev = mc_amd->hdr.patch_id; 537 uci->cpu_sig.rev = mc_amd->hdr.patch_id;
538 c->microcode = mc_amd->hdr.patch_id; 538 c->microcode = mc_amd->hdr.patch_id;
539 539
540 return 0; 540 return UCODE_UPDATED;
541} 541}
542 542
543static int install_equiv_cpu_table(const u8 *buf) 543static int install_equiv_cpu_table(const u8 *buf)
@@ -683,27 +683,35 @@ static enum ucode_state __load_microcode_amd(u8 family, const u8 *data,
683static enum ucode_state 683static enum ucode_state
684load_microcode_amd(bool save, u8 family, const u8 *data, size_t size) 684load_microcode_amd(bool save, u8 family, const u8 *data, size_t size)
685{ 685{
686 struct ucode_patch *p;
686 enum ucode_state ret; 687 enum ucode_state ret;
687 688
688 /* free old equiv table */ 689 /* free old equiv table */
689 free_equiv_cpu_table(); 690 free_equiv_cpu_table();
690 691
691 ret = __load_microcode_amd(family, data, size); 692 ret = __load_microcode_amd(family, data, size);
692 693 if (ret != UCODE_OK) {
693 if (ret != UCODE_OK)
694 cleanup(); 694 cleanup();
695 return ret;
696 }
695 697
696#ifdef CONFIG_X86_32 698 p = find_patch(0);
697 /* save BSP's matching patch for early load */ 699 if (!p) {
698 if (save) { 700 return ret;
699 struct ucode_patch *p = find_patch(0); 701 } else {
700 if (p) { 702 if (boot_cpu_data.microcode == p->patch_id)
701 memset(amd_ucode_patch, 0, PATCH_MAX_SIZE); 703 return ret;
702 memcpy(amd_ucode_patch, p->data, min_t(u32, ksize(p->data), 704
703 PATCH_MAX_SIZE)); 705 ret = UCODE_NEW;
704 }
705 } 706 }
706#endif 707
708 /* save BSP's matching patch for early load */
709 if (!save)
710 return ret;
711
712 memset(amd_ucode_patch, 0, PATCH_MAX_SIZE);
713 memcpy(amd_ucode_patch, p->data, min_t(u32, ksize(p->data), PATCH_MAX_SIZE));
714
707 return ret; 715 return ret;
708} 716}
709 717
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index 319dd65f98a2..10c4fc2c91f8 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -22,13 +22,16 @@
22#define pr_fmt(fmt) "microcode: " fmt 22#define pr_fmt(fmt) "microcode: " fmt
23 23
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/stop_machine.h>
25#include <linux/syscore_ops.h> 26#include <linux/syscore_ops.h>
26#include <linux/miscdevice.h> 27#include <linux/miscdevice.h>
27#include <linux/capability.h> 28#include <linux/capability.h>
28#include <linux/firmware.h> 29#include <linux/firmware.h>
29#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/delay.h>
30#include <linux/mutex.h> 32#include <linux/mutex.h>
31#include <linux/cpu.h> 33#include <linux/cpu.h>
34#include <linux/nmi.h>
32#include <linux/fs.h> 35#include <linux/fs.h>
33#include <linux/mm.h> 36#include <linux/mm.h>
34 37
@@ -64,6 +67,11 @@ LIST_HEAD(microcode_cache);
64 */ 67 */
65static DEFINE_MUTEX(microcode_mutex); 68static DEFINE_MUTEX(microcode_mutex);
66 69
70/*
71 * Serialize late loading so that CPUs get updated one-by-one.
72 */
73static DEFINE_SPINLOCK(update_lock);
74
67struct ucode_cpu_info ucode_cpu_info[NR_CPUS]; 75struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
68 76
69struct cpu_info_ctx { 77struct cpu_info_ctx {
@@ -373,26 +381,23 @@ static int collect_cpu_info(int cpu)
373 return ret; 381 return ret;
374} 382}
375 383
376struct apply_microcode_ctx {
377 int err;
378};
379
380static void apply_microcode_local(void *arg) 384static void apply_microcode_local(void *arg)
381{ 385{
382 struct apply_microcode_ctx *ctx = arg; 386 enum ucode_state *err = arg;
383 387
384 ctx->err = microcode_ops->apply_microcode(smp_processor_id()); 388 *err = microcode_ops->apply_microcode(smp_processor_id());
385} 389}
386 390
387static int apply_microcode_on_target(int cpu) 391static int apply_microcode_on_target(int cpu)
388{ 392{
389 struct apply_microcode_ctx ctx = { .err = 0 }; 393 enum ucode_state err;
390 int ret; 394 int ret;
391 395
392 ret = smp_call_function_single(cpu, apply_microcode_local, &ctx, 1); 396 ret = smp_call_function_single(cpu, apply_microcode_local, &err, 1);
393 if (!ret) 397 if (!ret) {
394 ret = ctx.err; 398 if (err == UCODE_ERROR)
395 399 ret = 1;
400 }
396 return ret; 401 return ret;
397} 402}
398 403
@@ -489,31 +494,124 @@ static void __exit microcode_dev_exit(void)
489/* fake device for request_firmware */ 494/* fake device for request_firmware */
490static struct platform_device *microcode_pdev; 495static struct platform_device *microcode_pdev;
491 496
492static int reload_for_cpu(int cpu) 497/*
498 * Late loading dance. Why the heavy-handed stomp_machine effort?
499 *
500 * - HT siblings must be idle and not execute other code while the other sibling
501 * is loading microcode in order to avoid any negative interactions caused by
502 * the loading.
503 *
504 * - In addition, microcode update on the cores must be serialized until this
505 * requirement can be relaxed in the future. Right now, this is conservative
506 * and good.
507 */
508#define SPINUNIT 100 /* 100 nsec */
509
510static int check_online_cpus(void)
493{ 511{
494 struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 512 if (num_online_cpus() == num_present_cpus())
495 enum ucode_state ustate; 513 return 0;
496 int err = 0;
497 514
498 if (!uci->valid) 515 pr_err("Not all CPUs online, aborting microcode update.\n");
499 return err;
500 516
501 ustate = microcode_ops->request_microcode_fw(cpu, &microcode_pdev->dev, true); 517 return -EINVAL;
502 if (ustate == UCODE_OK) 518}
503 apply_microcode_on_target(cpu); 519
504 else 520static atomic_t late_cpus_in;
505 if (ustate == UCODE_ERROR) 521static atomic_t late_cpus_out;
506 err = -EINVAL; 522
507 return err; 523static int __wait_for_cpus(atomic_t *t, long long timeout)
524{
525 int all_cpus = num_online_cpus();
526
527 atomic_inc(t);
528
529 while (atomic_read(t) < all_cpus) {
530 if (timeout < SPINUNIT) {
531 pr_err("Timeout while waiting for CPUs rendezvous, remaining: %d\n",
532 all_cpus - atomic_read(t));
533 return 1;
534 }
535
536 ndelay(SPINUNIT);
537 timeout -= SPINUNIT;
538
539 touch_nmi_watchdog();
540 }
541 return 0;
542}
543
544/*
545 * Returns:
546 * < 0 - on error
547 * 0 - no update done
548 * 1 - microcode was updated
549 */
550static int __reload_late(void *info)
551{
552 int cpu = smp_processor_id();
553 enum ucode_state err;
554 int ret = 0;
555
556 /*
557 * Wait for all CPUs to arrive. A load will not be attempted unless all
558 * CPUs show up.
559 * */
560 if (__wait_for_cpus(&late_cpus_in, NSEC_PER_SEC))
561 return -1;
562
563 spin_lock(&update_lock);
564 apply_microcode_local(&err);
565 spin_unlock(&update_lock);
566
567 if (err > UCODE_NFOUND) {
568 pr_warn("Error reloading microcode on CPU %d\n", cpu);
569 return -1;
570 /* siblings return UCODE_OK because their engine got updated already */
571 } else if (err == UCODE_UPDATED || err == UCODE_OK) {
572 ret = 1;
573 } else {
574 return ret;
575 }
576
577 /*
578 * Increase the wait timeout to a safe value here since we're
579 * serializing the microcode update and that could take a while on a
580 * large number of CPUs. And that is fine as the *actual* timeout will
581 * be determined by the last CPU finished updating and thus cut short.
582 */
583 if (__wait_for_cpus(&late_cpus_out, NSEC_PER_SEC * num_online_cpus()))
584 panic("Timeout during microcode update!\n");
585
586 return ret;
587}
588
589/*
590 * Reload microcode late on all CPUs. Wait for a sec until they
591 * all gather together.
592 */
593static int microcode_reload_late(void)
594{
595 int ret;
596
597 atomic_set(&late_cpus_in, 0);
598 atomic_set(&late_cpus_out, 0);
599
600 ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
601 if (ret > 0)
602 microcode_check();
603
604 return ret;
508} 605}
509 606
510static ssize_t reload_store(struct device *dev, 607static ssize_t reload_store(struct device *dev,
511 struct device_attribute *attr, 608 struct device_attribute *attr,
512 const char *buf, size_t size) 609 const char *buf, size_t size)
513{ 610{
611 enum ucode_state tmp_ret = UCODE_OK;
612 int bsp = boot_cpu_data.cpu_index;
514 unsigned long val; 613 unsigned long val;
515 int cpu; 614 ssize_t ret = 0;
516 ssize_t ret = 0, tmp_ret;
517 615
518 ret = kstrtoul(buf, 0, &val); 616 ret = kstrtoul(buf, 0, &val);
519 if (ret) 617 if (ret)
@@ -522,23 +620,24 @@ static ssize_t reload_store(struct device *dev,
522 if (val != 1) 620 if (val != 1)
523 return size; 621 return size;
524 622
623 tmp_ret = microcode_ops->request_microcode_fw(bsp, &microcode_pdev->dev, true);
624 if (tmp_ret != UCODE_NEW)
625 return size;
626
525 get_online_cpus(); 627 get_online_cpus();
526 mutex_lock(&microcode_mutex);
527 for_each_online_cpu(cpu) {
528 tmp_ret = reload_for_cpu(cpu);
529 if (tmp_ret != 0)
530 pr_warn("Error reloading microcode on CPU %d\n", cpu);
531 628
532 /* save retval of the first encountered reload error */ 629 ret = check_online_cpus();
533 if (!ret) 630 if (ret)
534 ret = tmp_ret; 631 goto put;
535 } 632
536 if (!ret) 633 mutex_lock(&microcode_mutex);
537 perf_check_microcode(); 634 ret = microcode_reload_late();
538 mutex_unlock(&microcode_mutex); 635 mutex_unlock(&microcode_mutex);
636
637put:
539 put_online_cpus(); 638 put_online_cpus();
540 639
541 if (!ret) 640 if (ret >= 0)
542 ret = size; 641 ret = size;
543 642
544 return ret; 643 return ret;
@@ -606,10 +705,8 @@ static enum ucode_state microcode_init_cpu(int cpu, bool refresh_fw)
606 if (system_state != SYSTEM_RUNNING) 705 if (system_state != SYSTEM_RUNNING)
607 return UCODE_NFOUND; 706 return UCODE_NFOUND;
608 707
609 ustate = microcode_ops->request_microcode_fw(cpu, &microcode_pdev->dev, 708 ustate = microcode_ops->request_microcode_fw(cpu, &microcode_pdev->dev, refresh_fw);
610 refresh_fw); 709 if (ustate == UCODE_NEW) {
611
612 if (ustate == UCODE_OK) {
613 pr_debug("CPU%d updated upon init\n", cpu); 710 pr_debug("CPU%d updated upon init\n", cpu);
614 apply_microcode_on_target(cpu); 711 apply_microcode_on_target(cpu);
615 } 712 }
diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
index f7c55b0e753a..32b8e5724f96 100644
--- a/arch/x86/kernel/cpu/microcode/intel.c
+++ b/arch/x86/kernel/cpu/microcode/intel.c
@@ -589,6 +589,23 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
589 if (!mc) 589 if (!mc)
590 return 0; 590 return 0;
591 591
592 /*
593 * Save us the MSR write below - which is a particular expensive
594 * operation - when the other hyperthread has updated the microcode
595 * already.
596 */
597 rev = intel_get_microcode_revision();
598 if (rev >= mc->hdr.rev) {
599 uci->cpu_sig.rev = rev;
600 return UCODE_OK;
601 }
602
603 /*
604 * Writeback and invalidate caches before updating microcode to avoid
605 * internal issues depending on what the microcode is updating.
606 */
607 native_wbinvd();
608
592 /* write microcode via MSR 0x79 */ 609 /* write microcode via MSR 0x79 */
593 native_wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc->bits); 610 native_wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc->bits);
594 611
@@ -772,27 +789,44 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig)
772 return 0; 789 return 0;
773} 790}
774 791
775static int apply_microcode_intel(int cpu) 792static enum ucode_state apply_microcode_intel(int cpu)
776{ 793{
794 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
795 struct cpuinfo_x86 *c = &cpu_data(cpu);
777 struct microcode_intel *mc; 796 struct microcode_intel *mc;
778 struct ucode_cpu_info *uci;
779 struct cpuinfo_x86 *c;
780 static int prev_rev; 797 static int prev_rev;
781 u32 rev; 798 u32 rev;
782 799
783 /* We should bind the task to the CPU */ 800 /* We should bind the task to the CPU */
784 if (WARN_ON(raw_smp_processor_id() != cpu)) 801 if (WARN_ON(raw_smp_processor_id() != cpu))
785 return -1; 802 return UCODE_ERROR;
786 803
787 uci = ucode_cpu_info + cpu; 804 /* Look for a newer patch in our cache: */
788 mc = uci->mc; 805 mc = find_patch(uci);
789 if (!mc) { 806 if (!mc) {
790 /* Look for a newer patch in our cache: */ 807 mc = uci->mc;
791 mc = find_patch(uci);
792 if (!mc) 808 if (!mc)
793 return 0; 809 return UCODE_NFOUND;
794 } 810 }
795 811
812 /*
813 * Save us the MSR write below - which is a particular expensive
814 * operation - when the other hyperthread has updated the microcode
815 * already.
816 */
817 rev = intel_get_microcode_revision();
818 if (rev >= mc->hdr.rev) {
819 uci->cpu_sig.rev = rev;
820 c->microcode = rev;
821 return UCODE_OK;
822 }
823
824 /*
825 * Writeback and invalidate caches before updating microcode to avoid
826 * internal issues depending on what the microcode is updating.
827 */
828 native_wbinvd();
829
796 /* write microcode via MSR 0x79 */ 830 /* write microcode via MSR 0x79 */
797 wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc->bits); 831 wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc->bits);
798 832
@@ -801,7 +835,7 @@ static int apply_microcode_intel(int cpu)
801 if (rev != mc->hdr.rev) { 835 if (rev != mc->hdr.rev) {
802 pr_err("CPU%d update to revision 0x%x failed\n", 836 pr_err("CPU%d update to revision 0x%x failed\n",
803 cpu, mc->hdr.rev); 837 cpu, mc->hdr.rev);
804 return -1; 838 return UCODE_ERROR;
805 } 839 }
806 840
807 if (rev != prev_rev) { 841 if (rev != prev_rev) {
@@ -813,12 +847,10 @@ static int apply_microcode_intel(int cpu)
813 prev_rev = rev; 847 prev_rev = rev;
814 } 848 }
815 849
816 c = &cpu_data(cpu);
817
818 uci->cpu_sig.rev = rev; 850 uci->cpu_sig.rev = rev;
819 c->microcode = rev; 851 c->microcode = rev;
820 852
821 return 0; 853 return UCODE_UPDATED;
822} 854}
823 855
824static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size, 856static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
@@ -830,6 +862,7 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
830 unsigned int leftover = size; 862 unsigned int leftover = size;
831 unsigned int curr_mc_size = 0, new_mc_size = 0; 863 unsigned int curr_mc_size = 0, new_mc_size = 0;
832 unsigned int csig, cpf; 864 unsigned int csig, cpf;
865 enum ucode_state ret = UCODE_OK;
833 866
834 while (leftover) { 867 while (leftover) {
835 struct microcode_header_intel mc_header; 868 struct microcode_header_intel mc_header;
@@ -871,6 +904,7 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
871 new_mc = mc; 904 new_mc = mc;
872 new_mc_size = mc_size; 905 new_mc_size = mc_size;
873 mc = NULL; /* trigger new vmalloc */ 906 mc = NULL; /* trigger new vmalloc */
907 ret = UCODE_NEW;
874 } 908 }
875 909
876 ucode_ptr += mc_size; 910 ucode_ptr += mc_size;
@@ -900,7 +934,7 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
900 pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n", 934 pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n",
901 cpu, new_rev, uci->cpu_sig.rev); 935 cpu, new_rev, uci->cpu_sig.rev);
902 936
903 return UCODE_OK; 937 return ret;
904} 938}
905 939
906static int get_ucode_fw(void *to, const void *from, size_t n) 940static int get_ucode_fw(void *to, const void *from, size_t n)
@@ -921,7 +955,7 @@ static bool is_blacklisted(unsigned int cpu)
921 */ 955 */
922 if (c->x86 == 6 && 956 if (c->x86 == 6 &&
923 c->x86_model == INTEL_FAM6_BROADWELL_X && 957 c->x86_model == INTEL_FAM6_BROADWELL_X &&
924 c->x86_mask == 0x01 && 958 c->x86_stepping == 0x01 &&
925 llc_size_per_core > 2621440 && 959 llc_size_per_core > 2621440 &&
926 c->microcode < 0x0b000021) { 960 c->microcode < 0x0b000021) {
927 pr_err_once("Erratum BDF90: late loading with revision < 0x0b000021 (0x%x) disabled.\n", c->microcode); 961 pr_err_once("Erratum BDF90: late loading with revision < 0x0b000021 (0x%x) disabled.\n", c->microcode);
@@ -944,7 +978,7 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
944 return UCODE_NFOUND; 978 return UCODE_NFOUND;
945 979
946 sprintf(name, "intel-ucode/%02x-%02x-%02x", 980 sprintf(name, "intel-ucode/%02x-%02x-%02x",
947 c->x86, c->x86_model, c->x86_mask); 981 c->x86, c->x86_model, c->x86_stepping);
948 982
949 if (request_firmware_direct(&firmware, name, device)) { 983 if (request_firmware_direct(&firmware, name, device)) {
950 pr_debug("data file %s load failed\n", name); 984 pr_debug("data file %s load failed\n", name);
@@ -982,7 +1016,7 @@ static struct microcode_ops microcode_intel_ops = {
982 1016
983static int __init calc_llc_size_per_core(struct cpuinfo_x86 *c) 1017static int __init calc_llc_size_per_core(struct cpuinfo_x86 *c)
984{ 1018{
985 u64 llc_size = c->x86_cache_size * 1024; 1019 u64 llc_size = c->x86_cache_size * 1024ULL;
986 1020
987 do_div(llc_size, c->x86_max_cores); 1021 do_div(llc_size, c->x86_max_cores);
988 1022
diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index fdc55215d44d..e12ee86906c6 100644
--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -859,7 +859,7 @@ int generic_validate_add_page(unsigned long base, unsigned long size,
859 */ 859 */
860 if (is_cpu(INTEL) && boot_cpu_data.x86 == 6 && 860 if (is_cpu(INTEL) && boot_cpu_data.x86 == 6 &&
861 boot_cpu_data.x86_model == 1 && 861 boot_cpu_data.x86_model == 1 &&
862 boot_cpu_data.x86_mask <= 7) { 862 boot_cpu_data.x86_stepping <= 7) {
863 if (base & ((1 << (22 - PAGE_SHIFT)) - 1)) { 863 if (base & ((1 << (22 - PAGE_SHIFT)) - 1)) {
864 pr_warn("mtrr: base(0x%lx000) is not 4 MiB aligned\n", base); 864 pr_warn("mtrr: base(0x%lx000) is not 4 MiB aligned\n", base);
865 return -EINVAL; 865 return -EINVAL;
diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
index 40d5a8a75212..7468de429087 100644
--- a/arch/x86/kernel/cpu/mtrr/main.c
+++ b/arch/x86/kernel/cpu/mtrr/main.c
@@ -711,8 +711,8 @@ void __init mtrr_bp_init(void)
711 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && 711 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
712 boot_cpu_data.x86 == 0xF && 712 boot_cpu_data.x86 == 0xF &&
713 boot_cpu_data.x86_model == 0x3 && 713 boot_cpu_data.x86_model == 0x3 &&
714 (boot_cpu_data.x86_mask == 0x3 || 714 (boot_cpu_data.x86_stepping == 0x3 ||
715 boot_cpu_data.x86_mask == 0x4)) 715 boot_cpu_data.x86_stepping == 0x4))
716 phys_addr = 36; 716 phys_addr = 36;
717 717
718 size_or_mask = SIZE_OR_MASK_BITS(phys_addr); 718 size_or_mask = SIZE_OR_MASK_BITS(phys_addr);
diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index e7ecedafa1c8..2c8522a39ed5 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -72,8 +72,8 @@ static int show_cpuinfo(struct seq_file *m, void *v)
72 c->x86_model, 72 c->x86_model,
73 c->x86_model_id[0] ? c->x86_model_id : "unknown"); 73 c->x86_model_id[0] ? c->x86_model_id : "unknown");
74 74
75 if (c->x86_mask || c->cpuid_level >= 0) 75 if (c->x86_stepping || c->cpuid_level >= 0)
76 seq_printf(m, "stepping\t: %d\n", c->x86_mask); 76 seq_printf(m, "stepping\t: %d\n", c->x86_stepping);
77 else 77 else
78 seq_puts(m, "stepping\t: unknown\n"); 78 seq_puts(m, "stepping\t: unknown\n");
79 if (c->microcode) 79 if (c->microcode)
@@ -91,8 +91,8 @@ static int show_cpuinfo(struct seq_file *m, void *v)
91 } 91 }
92 92
93 /* Cache size */ 93 /* Cache size */
94 if (c->x86_cache_size >= 0) 94 if (c->x86_cache_size)
95 seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size); 95 seq_printf(m, "cache size\t: %u KB\n", c->x86_cache_size);
96 96
97 show_cpuinfo_core(m, c, cpu); 97 show_cpuinfo_core(m, c, cpu);
98 show_cpuinfo_misc(m, c); 98 show_cpuinfo_misc(m, c);
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index c29020907886..b59e4fb40fd9 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -37,7 +37,7 @@
37#define X86 new_cpu_data+CPUINFO_x86 37#define X86 new_cpu_data+CPUINFO_x86
38#define X86_VENDOR new_cpu_data+CPUINFO_x86_vendor 38#define X86_VENDOR new_cpu_data+CPUINFO_x86_vendor
39#define X86_MODEL new_cpu_data+CPUINFO_x86_model 39#define X86_MODEL new_cpu_data+CPUINFO_x86_model
40#define X86_MASK new_cpu_data+CPUINFO_x86_mask 40#define X86_STEPPING new_cpu_data+CPUINFO_x86_stepping
41#define X86_HARD_MATH new_cpu_data+CPUINFO_hard_math 41#define X86_HARD_MATH new_cpu_data+CPUINFO_hard_math
42#define X86_CPUID new_cpu_data+CPUINFO_cpuid_level 42#define X86_CPUID new_cpu_data+CPUINFO_cpuid_level
43#define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability 43#define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability
@@ -332,7 +332,7 @@ ENTRY(startup_32_smp)
332 shrb $4,%al 332 shrb $4,%al
333 movb %al,X86_MODEL 333 movb %al,X86_MODEL
334 andb $0x0f,%cl # mask mask revision 334 andb $0x0f,%cl # mask mask revision
335 movb %cl,X86_MASK 335 movb %cl,X86_STEPPING
336 movl %edx,X86_CAPABILITY 336 movl %edx,X86_CAPABILITY
337 337
338.Lis486: 338.Lis486:
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 04a625f0fcda..0f545b3cf926 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -23,6 +23,7 @@
23#include <asm/nops.h> 23#include <asm/nops.h>
24#include "../entry/calling.h" 24#include "../entry/calling.h"
25#include <asm/export.h> 25#include <asm/export.h>
26#include <asm/nospec-branch.h>
26 27
27#ifdef CONFIG_PARAVIRT 28#ifdef CONFIG_PARAVIRT
28#include <asm/asm-offsets.h> 29#include <asm/asm-offsets.h>
@@ -134,6 +135,7 @@ ENTRY(secondary_startup_64)
134 135
135 /* Ensure I am executing from virtual addresses */ 136 /* Ensure I am executing from virtual addresses */
136 movq $1f, %rax 137 movq $1f, %rax
138 ANNOTATE_RETPOLINE_SAFE
137 jmp *%rax 139 jmp *%rax
1381: 1401:
139 UNWIND_HINT_EMPTY 141 UNWIND_HINT_EMPTY
diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c
index 56d99be3706a..50bee5fe1140 100644
--- a/arch/x86/kernel/idt.c
+++ b/arch/x86/kernel/idt.c
@@ -160,7 +160,6 @@ static const __initconst struct idt_data early_pf_idts[] = {
160 */ 160 */
161static const __initconst struct idt_data dbg_idts[] = { 161static const __initconst struct idt_data dbg_idts[] = {
162 INTG(X86_TRAP_DB, debug), 162 INTG(X86_TRAP_DB, debug),
163 INTG(X86_TRAP_BP, int3),
164}; 163};
165#endif 164#endif
166 165
@@ -183,7 +182,6 @@ gate_desc debug_idt_table[IDT_ENTRIES] __page_aligned_bss;
183static const __initconst struct idt_data ist_idts[] = { 182static const __initconst struct idt_data ist_idts[] = {
184 ISTG(X86_TRAP_DB, debug, DEBUG_STACK), 183 ISTG(X86_TRAP_DB, debug, DEBUG_STACK),
185 ISTG(X86_TRAP_NMI, nmi, NMI_STACK), 184 ISTG(X86_TRAP_NMI, nmi, NMI_STACK),
186 SISTG(X86_TRAP_BP, int3, DEBUG_STACK),
187 ISTG(X86_TRAP_DF, double_fault, DOUBLEFAULT_STACK), 185 ISTG(X86_TRAP_DF, double_fault, DOUBLEFAULT_STACK),
188#ifdef CONFIG_X86_MCE 186#ifdef CONFIG_X86_MCE
189 ISTG(X86_TRAP_MC, &machine_check, MCE_STACK), 187 ISTG(X86_TRAP_MC, &machine_check, MCE_STACK),
diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
index 2f723301eb58..38deafebb21b 100644
--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -23,7 +23,7 @@
23/* 23/*
24 * this changes the io permissions bitmap in the current task. 24 * this changes the io permissions bitmap in the current task.
25 */ 25 */
26asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on) 26SYSCALL_DEFINE3(ioperm, unsigned long, from, unsigned long, num, int, turn_on)
27{ 27{
28 struct thread_struct *t = &current->thread; 28 struct thread_struct *t = &current->thread;
29 struct tss_struct *tss; 29 struct tss_struct *tss;
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index bd36f3c33cd0..0715f827607c 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -1168,10 +1168,18 @@ NOKPROBE_SYMBOL(longjmp_break_handler);
1168 1168
1169bool arch_within_kprobe_blacklist(unsigned long addr) 1169bool arch_within_kprobe_blacklist(unsigned long addr)
1170{ 1170{
1171 bool is_in_entry_trampoline_section = false;
1172
1173#ifdef CONFIG_X86_64
1174 is_in_entry_trampoline_section =
1175 (addr >= (unsigned long)__entry_trampoline_start &&
1176 addr < (unsigned long)__entry_trampoline_end);
1177#endif
1171 return (addr >= (unsigned long)__kprobes_text_start && 1178 return (addr >= (unsigned long)__kprobes_text_start &&
1172 addr < (unsigned long)__kprobes_text_end) || 1179 addr < (unsigned long)__kprobes_text_end) ||
1173 (addr >= (unsigned long)__entry_text_start && 1180 (addr >= (unsigned long)__entry_text_start &&
1174 addr < (unsigned long)__entry_text_end); 1181 addr < (unsigned long)__entry_text_end) ||
1182 is_in_entry_trampoline_section;
1175} 1183}
1176 1184
1177int __init arch_init_kprobes(void) 1185int __init arch_init_kprobes(void)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 4e37d1a851a6..bc1a27280c4b 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -49,7 +49,7 @@
49 49
50static int kvmapf = 1; 50static int kvmapf = 1;
51 51
52static int parse_no_kvmapf(char *arg) 52static int __init parse_no_kvmapf(char *arg)
53{ 53{
54 kvmapf = 0; 54 kvmapf = 0;
55 return 0; 55 return 0;
@@ -58,7 +58,7 @@ static int parse_no_kvmapf(char *arg)
58early_param("no-kvmapf", parse_no_kvmapf); 58early_param("no-kvmapf", parse_no_kvmapf);
59 59
60static int steal_acc = 1; 60static int steal_acc = 1;
61static int parse_no_stealacc(char *arg) 61static int __init parse_no_stealacc(char *arg)
62{ 62{
63 steal_acc = 0; 63 steal_acc = 0;
64 return 0; 64 return 0;
@@ -67,7 +67,7 @@ static int parse_no_stealacc(char *arg)
67early_param("no-steal-acc", parse_no_stealacc); 67early_param("no-steal-acc", parse_no_stealacc);
68 68
69static int kvmclock_vsyscall = 1; 69static int kvmclock_vsyscall = 1;
70static int parse_no_kvmclock_vsyscall(char *arg) 70static int __init parse_no_kvmclock_vsyscall(char *arg)
71{ 71{
72 kvmclock_vsyscall = 0; 72 kvmclock_vsyscall = 0;
73 return 0; 73 return 0;
@@ -341,10 +341,10 @@ static void kvm_guest_cpu_init(void)
341#endif 341#endif
342 pa |= KVM_ASYNC_PF_ENABLED; 342 pa |= KVM_ASYNC_PF_ENABLED;
343 343
344 /* Async page fault support for L1 hypervisor is optional */ 344 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF_VMEXIT))
345 if (wrmsr_safe(MSR_KVM_ASYNC_PF_EN, 345 pa |= KVM_ASYNC_PF_DELIVERY_AS_PF_VMEXIT;
346 (pa | KVM_ASYNC_PF_DELIVERY_AS_PF_VMEXIT) & 0xffffffff, pa >> 32) < 0) 346
347 wrmsrl(MSR_KVM_ASYNC_PF_EN, pa); 347 wrmsrl(MSR_KVM_ASYNC_PF_EN, pa);
348 __this_cpu_write(apf_reason.enabled, 1); 348 __this_cpu_write(apf_reason.enabled, 1);
349 printk(KERN_INFO"KVM setup async PF for cpu %d\n", 349 printk(KERN_INFO"KVM setup async PF for cpu %d\n",
350 smp_processor_id()); 350 smp_processor_id());
@@ -545,7 +545,8 @@ static void __init kvm_guest_init(void)
545 pv_time_ops.steal_clock = kvm_steal_clock; 545 pv_time_ops.steal_clock = kvm_steal_clock;
546 } 546 }
547 547
548 if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH)) 548 if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
549 !kvm_para_has_feature(KVM_FEATURE_STEAL_TIME))
549 pv_mmu_ops.flush_tlb_others = kvm_flush_tlb_others; 550 pv_mmu_ops.flush_tlb_others = kvm_flush_tlb_others;
550 551
551 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) 552 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
@@ -633,7 +634,8 @@ static __init int kvm_setup_pv_tlb_flush(void)
633{ 634{
634 int cpu; 635 int cpu;
635 636
636 if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH)) { 637 if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
638 !kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
637 for_each_possible_cpu(cpu) { 639 for_each_possible_cpu(cpu) {
638 zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu), 640 zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
639 GFP_KERNEL, cpu_to_node(cpu)); 641 GFP_KERNEL, cpu_to_node(cpu));
diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c
index 1f790cf9d38f..3b7427aa7d85 100644
--- a/arch/x86/kernel/machine_kexec_64.c
+++ b/arch/x86/kernel/machine_kexec_64.c
@@ -542,6 +542,7 @@ int arch_kexec_apply_relocations_add(const Elf64_Ehdr *ehdr,
542 goto overflow; 542 goto overflow;
543 break; 543 break;
544 case R_X86_64_PC32: 544 case R_X86_64_PC32:
545 case R_X86_64_PLT32:
545 value -= (u64)address; 546 value -= (u64)address;
546 *(u32 *)location = value; 547 *(u32 *)location = value;
547 break; 548 break;
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index da0c160e5589..f58336af095c 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -191,6 +191,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
191 goto overflow; 191 goto overflow;
192 break; 192 break;
193 case R_X86_64_PC32: 193 case R_X86_64_PC32:
194 case R_X86_64_PLT32:
194 if (*(u32 *)loc != 0) 195 if (*(u32 *)loc != 0)
195 goto invalid_relocation; 196 goto invalid_relocation;
196 val -= (u64)loc; 197 val -= (u64)loc;
diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c
index 27d0a1712663..f1c5eb99d445 100644
--- a/arch/x86/kernel/mpparse.c
+++ b/arch/x86/kernel/mpparse.c
@@ -410,7 +410,7 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
410 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01; 410 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
411 processor.cpuflag = CPU_ENABLED; 411 processor.cpuflag = CPU_ENABLED;
412 processor.cpufeature = (boot_cpu_data.x86 << 8) | 412 processor.cpufeature = (boot_cpu_data.x86 << 8) |
413 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask; 413 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_stepping;
414 processor.featureflag = boot_cpu_data.x86_capability[CPUID_1_EDX]; 414 processor.featureflag = boot_cpu_data.x86_capability[CPUID_1_EDX];
415 processor.reserved[0] = 0; 415 processor.reserved[0] = 0;
416 processor.reserved[1] = 0; 416 processor.reserved[1] = 0;
diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
index 041096bdef86..99dc79e76bdc 100644
--- a/arch/x86/kernel/paravirt.c
+++ b/arch/x86/kernel/paravirt.c
@@ -200,9 +200,9 @@ static void native_flush_tlb_global(void)
200 __native_flush_tlb_global(); 200 __native_flush_tlb_global();
201} 201}
202 202
203static void native_flush_tlb_single(unsigned long addr) 203static void native_flush_tlb_one_user(unsigned long addr)
204{ 204{
205 __native_flush_tlb_single(addr); 205 __native_flush_tlb_one_user(addr);
206} 206}
207 207
208struct static_key paravirt_steal_enabled; 208struct static_key paravirt_steal_enabled;
@@ -401,7 +401,7 @@ struct pv_mmu_ops pv_mmu_ops __ro_after_init = {
401 401
402 .flush_tlb_user = native_flush_tlb, 402 .flush_tlb_user = native_flush_tlb,
403 .flush_tlb_kernel = native_flush_tlb_global, 403 .flush_tlb_kernel = native_flush_tlb_global,
404 .flush_tlb_single = native_flush_tlb_single, 404 .flush_tlb_one_user = native_flush_tlb_one_user,
405 .flush_tlb_others = native_flush_tlb_others, 405 .flush_tlb_others = native_flush_tlb_others,
406 406
407 .pgd_alloc = __paravirt_pgd_alloc, 407 .pgd_alloc = __paravirt_pgd_alloc,
diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c
index 618285e475c6..ac7ea3a8242f 100644
--- a/arch/x86/kernel/pci-nommu.c
+++ b/arch/x86/kernel/pci-nommu.c
@@ -37,7 +37,6 @@ static dma_addr_t nommu_map_page(struct device *dev, struct page *page,
37 WARN_ON(size == 0); 37 WARN_ON(size == 0);
38 if (!check_addr("map_single", dev, bus, size)) 38 if (!check_addr("map_single", dev, bus, size))
39 return NOMMU_MAPPING_ERROR; 39 return NOMMU_MAPPING_ERROR;
40 flush_write_buffers();
41 return bus; 40 return bus;
42} 41}
43 42
@@ -72,25 +71,9 @@ static int nommu_map_sg(struct device *hwdev, struct scatterlist *sg,
72 return 0; 71 return 0;
73 s->dma_length = s->length; 72 s->dma_length = s->length;
74 } 73 }
75 flush_write_buffers();
76 return nents; 74 return nents;
77} 75}
78 76
79static void nommu_sync_single_for_device(struct device *dev,
80 dma_addr_t addr, size_t size,
81 enum dma_data_direction dir)
82{
83 flush_write_buffers();
84}
85
86
87static void nommu_sync_sg_for_device(struct device *dev,
88 struct scatterlist *sg, int nelems,
89 enum dma_data_direction dir)
90{
91 flush_write_buffers();
92}
93
94static int nommu_mapping_error(struct device *dev, dma_addr_t dma_addr) 77static int nommu_mapping_error(struct device *dev, dma_addr_t dma_addr)
95{ 78{
96 return dma_addr == NOMMU_MAPPING_ERROR; 79 return dma_addr == NOMMU_MAPPING_ERROR;
@@ -101,8 +84,6 @@ const struct dma_map_ops nommu_dma_ops = {
101 .free = dma_generic_free_coherent, 84 .free = dma_generic_free_coherent,
102 .map_sg = nommu_map_sg, 85 .map_sg = nommu_map_sg,
103 .map_page = nommu_map_page, 86 .map_page = nommu_map_page,
104 .sync_single_for_device = nommu_sync_single_for_device,
105 .sync_sg_for_device = nommu_sync_sg_for_device,
106 .is_phys = 1, 87 .is_phys = 1,
107 .mapping_error = nommu_mapping_error, 88 .mapping_error = nommu_mapping_error,
108 .dma_supported = x86_dma_supported, 89 .dma_supported = x86_dma_supported,
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 1ae67e982af7..4c616be28506 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1204,20 +1204,13 @@ void __init setup_arch(char **cmdline_p)
1204 1204
1205 kasan_init(); 1205 kasan_init();
1206 1206
1207#ifdef CONFIG_X86_32
1208 /* sync back kernel address range */
1209 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
1210 swapper_pg_dir + KERNEL_PGD_BOUNDARY,
1211 KERNEL_PGD_PTRS);
1212
1213 /* 1207 /*
1214 * sync back low identity map too. It is used for example 1208 * Sync back kernel address range.
1215 * in the 32-bit EFI stub. 1209 *
1210 * FIXME: Can the later sync in setup_cpu_entry_areas() replace
1211 * this call?
1216 */ 1212 */
1217 clone_pgd_range(initial_page_table, 1213 sync_initial_page_table();
1218 swapper_pg_dir + KERNEL_PGD_BOUNDARY,
1219 min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
1220#endif
1221 1214
1222 tboot_probe(); 1215 tboot_probe();
1223 1216
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
index 497aa766fab3..ea554f812ee1 100644
--- a/arch/x86/kernel/setup_percpu.c
+++ b/arch/x86/kernel/setup_percpu.c
@@ -287,24 +287,15 @@ void __init setup_per_cpu_areas(void)
287 /* Setup cpu initialized, callin, callout masks */ 287 /* Setup cpu initialized, callin, callout masks */
288 setup_cpu_local_masks(); 288 setup_cpu_local_masks();
289 289
290#ifdef CONFIG_X86_32
291 /* 290 /*
292 * Sync back kernel address range again. We already did this in 291 * Sync back kernel address range again. We already did this in
293 * setup_arch(), but percpu data also needs to be available in 292 * setup_arch(), but percpu data also needs to be available in
294 * the smpboot asm. We can't reliably pick up percpu mappings 293 * the smpboot asm. We can't reliably pick up percpu mappings
295 * using vmalloc_fault(), because exception dispatch needs 294 * using vmalloc_fault(), because exception dispatch needs
296 * percpu data. 295 * percpu data.
296 *
297 * FIXME: Can the later sync in setup_cpu_entry_areas() replace
298 * this call?
297 */ 299 */
298 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY, 300 sync_initial_page_table();
299 swapper_pg_dir + KERNEL_PGD_BOUNDARY,
300 KERNEL_PGD_PTRS);
301
302 /*
303 * sync back low identity map too. It is used for example
304 * in the 32-bit EFI stub.
305 */
306 clone_pgd_range(initial_page_table,
307 swapper_pg_dir + KERNEL_PGD_BOUNDARY,
308 min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
309#endif
310} 301}
diff --git a/arch/x86/kernel/signal_compat.c b/arch/x86/kernel/signal_compat.c
index ac057f9b0763..0d930d8987cc 100644
--- a/arch/x86/kernel/signal_compat.c
+++ b/arch/x86/kernel/signal_compat.c
@@ -43,6 +43,13 @@ static inline void signal_compat_build_tests(void)
43 BUILD_BUG_ON(offsetof(compat_siginfo_t, _sifields) != 3 * sizeof(int)); 43 BUILD_BUG_ON(offsetof(compat_siginfo_t, _sifields) != 3 * sizeof(int));
44#define CHECK_CSI_OFFSET(name) BUILD_BUG_ON(_sifields_offset != offsetof(compat_siginfo_t, _sifields.name)) 44#define CHECK_CSI_OFFSET(name) BUILD_BUG_ON(_sifields_offset != offsetof(compat_siginfo_t, _sifields.name))
45 45
46 BUILD_BUG_ON(offsetof(siginfo_t, si_signo) != 0);
47 BUILD_BUG_ON(offsetof(siginfo_t, si_errno) != 4);
48 BUILD_BUG_ON(offsetof(siginfo_t, si_code) != 8);
49
50 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_signo) != 0);
51 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_errno) != 4);
52 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_code) != 8);
46 /* 53 /*
47 * Ensure that the size of each si_field never changes. 54 * Ensure that the size of each si_field never changes.
48 * If it does, it is a sign that the 55 * If it does, it is a sign that the
@@ -63,36 +70,94 @@ static inline void signal_compat_build_tests(void)
63 CHECK_CSI_SIZE (_kill, 2*sizeof(int)); 70 CHECK_CSI_SIZE (_kill, 2*sizeof(int));
64 CHECK_SI_SIZE (_kill, 2*sizeof(int)); 71 CHECK_SI_SIZE (_kill, 2*sizeof(int));
65 72
73 BUILD_BUG_ON(offsetof(siginfo_t, si_pid) != 0x10);
74 BUILD_BUG_ON(offsetof(siginfo_t, si_uid) != 0x14);
75 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pid) != 0xC);
76 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_uid) != 0x10);
77
66 CHECK_CSI_OFFSET(_timer); 78 CHECK_CSI_OFFSET(_timer);
67 CHECK_CSI_SIZE (_timer, 3*sizeof(int)); 79 CHECK_CSI_SIZE (_timer, 3*sizeof(int));
68 CHECK_SI_SIZE (_timer, 6*sizeof(int)); 80 CHECK_SI_SIZE (_timer, 6*sizeof(int));
69 81
82 BUILD_BUG_ON(offsetof(siginfo_t, si_tid) != 0x10);
83 BUILD_BUG_ON(offsetof(siginfo_t, si_overrun) != 0x14);
84 BUILD_BUG_ON(offsetof(siginfo_t, si_value) != 0x18);
85 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_tid) != 0x0C);
86 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_overrun) != 0x10);
87 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_value) != 0x14);
88
70 CHECK_CSI_OFFSET(_rt); 89 CHECK_CSI_OFFSET(_rt);
71 CHECK_CSI_SIZE (_rt, 3*sizeof(int)); 90 CHECK_CSI_SIZE (_rt, 3*sizeof(int));
72 CHECK_SI_SIZE (_rt, 4*sizeof(int)); 91 CHECK_SI_SIZE (_rt, 4*sizeof(int));
73 92
93 BUILD_BUG_ON(offsetof(siginfo_t, si_pid) != 0x10);
94 BUILD_BUG_ON(offsetof(siginfo_t, si_uid) != 0x14);
95 BUILD_BUG_ON(offsetof(siginfo_t, si_value) != 0x18);
96 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pid) != 0x0C);
97 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_uid) != 0x10);
98 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_value) != 0x14);
99
74 CHECK_CSI_OFFSET(_sigchld); 100 CHECK_CSI_OFFSET(_sigchld);
75 CHECK_CSI_SIZE (_sigchld, 5*sizeof(int)); 101 CHECK_CSI_SIZE (_sigchld, 5*sizeof(int));
76 CHECK_SI_SIZE (_sigchld, 8*sizeof(int)); 102 CHECK_SI_SIZE (_sigchld, 8*sizeof(int));
77 103
104 BUILD_BUG_ON(offsetof(siginfo_t, si_pid) != 0x10);
105 BUILD_BUG_ON(offsetof(siginfo_t, si_uid) != 0x14);
106 BUILD_BUG_ON(offsetof(siginfo_t, si_status) != 0x18);
107 BUILD_BUG_ON(offsetof(siginfo_t, si_utime) != 0x20);
108 BUILD_BUG_ON(offsetof(siginfo_t, si_stime) != 0x28);
109 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pid) != 0x0C);
110 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_uid) != 0x10);
111 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_status) != 0x14);
112 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_utime) != 0x18);
113 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_stime) != 0x1C);
114
78#ifdef CONFIG_X86_X32_ABI 115#ifdef CONFIG_X86_X32_ABI
79 CHECK_CSI_OFFSET(_sigchld_x32); 116 CHECK_CSI_OFFSET(_sigchld_x32);
80 CHECK_CSI_SIZE (_sigchld_x32, 7*sizeof(int)); 117 CHECK_CSI_SIZE (_sigchld_x32, 7*sizeof(int));
81 /* no _sigchld_x32 in the generic siginfo_t */ 118 /* no _sigchld_x32 in the generic siginfo_t */
119 BUILD_BUG_ON(offsetof(compat_siginfo_t, _sifields._sigchld_x32._utime) != 0x18);
120 BUILD_BUG_ON(offsetof(compat_siginfo_t, _sifields._sigchld_x32._stime) != 0x20);
82#endif 121#endif
83 122
84 CHECK_CSI_OFFSET(_sigfault); 123 CHECK_CSI_OFFSET(_sigfault);
85 CHECK_CSI_SIZE (_sigfault, 4*sizeof(int)); 124 CHECK_CSI_SIZE (_sigfault, 4*sizeof(int));
86 CHECK_SI_SIZE (_sigfault, 8*sizeof(int)); 125 CHECK_SI_SIZE (_sigfault, 8*sizeof(int));
87 126
127 BUILD_BUG_ON(offsetof(siginfo_t, si_addr) != 0x10);
128 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_addr) != 0x0C);
129
130 BUILD_BUG_ON(offsetof(siginfo_t, si_addr_lsb) != 0x18);
131 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_addr_lsb) != 0x10);
132
133 BUILD_BUG_ON(offsetof(siginfo_t, si_lower) != 0x20);
134 BUILD_BUG_ON(offsetof(siginfo_t, si_upper) != 0x28);
135 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_lower) != 0x14);
136 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_upper) != 0x18);
137
138 BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x20);
139 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pkey) != 0x14);
140
88 CHECK_CSI_OFFSET(_sigpoll); 141 CHECK_CSI_OFFSET(_sigpoll);
89 CHECK_CSI_SIZE (_sigpoll, 2*sizeof(int)); 142 CHECK_CSI_SIZE (_sigpoll, 2*sizeof(int));
90 CHECK_SI_SIZE (_sigpoll, 4*sizeof(int)); 143 CHECK_SI_SIZE (_sigpoll, 4*sizeof(int));
91 144
145 BUILD_BUG_ON(offsetof(siginfo_t, si_band) != 0x10);
146 BUILD_BUG_ON(offsetof(siginfo_t, si_fd) != 0x18);
147 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_band) != 0x0C);
148 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_fd) != 0x10);
149
92 CHECK_CSI_OFFSET(_sigsys); 150 CHECK_CSI_OFFSET(_sigsys);
93 CHECK_CSI_SIZE (_sigsys, 3*sizeof(int)); 151 CHECK_CSI_SIZE (_sigsys, 3*sizeof(int));
94 CHECK_SI_SIZE (_sigsys, 4*sizeof(int)); 152 CHECK_SI_SIZE (_sigsys, 4*sizeof(int));
95 153
154 BUILD_BUG_ON(offsetof(siginfo_t, si_call_addr) != 0x10);
155 BUILD_BUG_ON(offsetof(siginfo_t, si_syscall) != 0x18);
156 BUILD_BUG_ON(offsetof(siginfo_t, si_arch) != 0x1C);
157 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_call_addr) != 0x0C);
158 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_syscall) != 0x10);
159 BUILD_BUG_ON(offsetof(compat_siginfo_t, si_arch) != 0x14);
160
96 /* any new si_fields should be added here */ 161 /* any new si_fields should be added here */
97} 162}
98 163
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 6f27facbaa9b..ff99e2b6fc54 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1281,11 +1281,10 @@ void __init native_smp_prepare_boot_cpu(void)
1281 cpu_set_state_online(me); 1281 cpu_set_state_online(me);
1282} 1282}
1283 1283
1284void __init native_smp_cpus_done(unsigned int max_cpus) 1284void __init calculate_max_logical_packages(void)
1285{ 1285{
1286 int ncpus; 1286 int ncpus;
1287 1287
1288 pr_debug("Boot done\n");
1289 /* 1288 /*
1290 * Today neither Intel nor AMD support heterogenous systems so 1289 * Today neither Intel nor AMD support heterogenous systems so
1291 * extrapolate the boot cpu's data to all packages. 1290 * extrapolate the boot cpu's data to all packages.
@@ -1293,6 +1292,13 @@ void __init native_smp_cpus_done(unsigned int max_cpus)
1293 ncpus = cpu_data(0).booted_cores * topology_max_smt_threads(); 1292 ncpus = cpu_data(0).booted_cores * topology_max_smt_threads();
1294 __max_logical_packages = DIV_ROUND_UP(nr_cpu_ids, ncpus); 1293 __max_logical_packages = DIV_ROUND_UP(nr_cpu_ids, ncpus);
1295 pr_info("Max logical packages: %u\n", __max_logical_packages); 1294 pr_info("Max logical packages: %u\n", __max_logical_packages);
1295}
1296
1297void __init native_smp_cpus_done(unsigned int max_cpus)
1298{
1299 pr_debug("Boot done\n");
1300
1301 calculate_max_logical_packages();
1296 1302
1297 if (x86_has_numa_in_package) 1303 if (x86_has_numa_in_package)
1298 set_sched_topology(x86_numa_in_package_topology); 1304 set_sched_topology(x86_numa_in_package_topology);
@@ -1430,8 +1436,8 @@ static void remove_siblinginfo(int cpu)
1430 cpumask_clear(cpu_llc_shared_mask(cpu)); 1436 cpumask_clear(cpu_llc_shared_mask(cpu));
1431 cpumask_clear(topology_sibling_cpumask(cpu)); 1437 cpumask_clear(topology_sibling_cpumask(cpu));
1432 cpumask_clear(topology_core_cpumask(cpu)); 1438 cpumask_clear(topology_core_cpumask(cpu));
1433 c->phys_proc_id = 0;
1434 c->cpu_core_id = 0; 1439 c->cpu_core_id = 0;
1440 c->booted_cores = 0;
1435 cpumask_clear_cpu(cpu, cpu_sibling_setup_mask); 1441 cpumask_clear_cpu(cpu, cpu_sibling_setup_mask);
1436 recompute_smt_state(); 1442 recompute_smt_state();
1437} 1443}
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 446c9ef8cfc3..03f3d7695dac 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -181,7 +181,7 @@ int fixup_bug(struct pt_regs *regs, int trapnr)
181 break; 181 break;
182 182
183 case BUG_TRAP_TYPE_WARN: 183 case BUG_TRAP_TYPE_WARN:
184 regs->ip += LEN_UD0; 184 regs->ip += LEN_UD2;
185 return 1; 185 return 1;
186 } 186 }
187 187
@@ -577,7 +577,6 @@ do_general_protection(struct pt_regs *regs, long error_code)
577} 577}
578NOKPROBE_SYMBOL(do_general_protection); 578NOKPROBE_SYMBOL(do_general_protection);
579 579
580/* May run on IST stack. */
581dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code) 580dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
582{ 581{
583#ifdef CONFIG_DYNAMIC_FTRACE 582#ifdef CONFIG_DYNAMIC_FTRACE
@@ -592,6 +591,13 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
592 if (poke_int3_handler(regs)) 591 if (poke_int3_handler(regs))
593 return; 592 return;
594 593
594 /*
595 * Use ist_enter despite the fact that we don't use an IST stack.
596 * We can be called from a kprobe in non-CONTEXT_KERNEL kernel
597 * mode or even during context tracking state changes.
598 *
599 * This means that we can't schedule. That's okay.
600 */
595 ist_enter(regs); 601 ist_enter(regs);
596 RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU"); 602 RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU");
597#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP 603#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
@@ -609,15 +615,10 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
609 SIGTRAP) == NOTIFY_STOP) 615 SIGTRAP) == NOTIFY_STOP)
610 goto exit; 616 goto exit;
611 617
612 /*
613 * Let others (NMI) know that the debug stack is in use
614 * as we may switch to the interrupt stack.
615 */
616 debug_stack_usage_inc();
617 cond_local_irq_enable(regs); 618 cond_local_irq_enable(regs);
618 do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL); 619 do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
619 cond_local_irq_disable(regs); 620 cond_local_irq_disable(regs);
620 debug_stack_usage_dec(); 621
621exit: 622exit:
622 ist_exit(regs); 623 ist_exit(regs);
623} 624}
diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
index 1f9188f5357c..feb28fee6cea 100644
--- a/arch/x86/kernel/unwind_orc.c
+++ b/arch/x86/kernel/unwind_orc.c
@@ -5,7 +5,6 @@
5#include <asm/unwind.h> 5#include <asm/unwind.h>
6#include <asm/orc_types.h> 6#include <asm/orc_types.h>
7#include <asm/orc_lookup.h> 7#include <asm/orc_lookup.h>
8#include <asm/sections.h>
9 8
10#define orc_warn(fmt, ...) \ 9#define orc_warn(fmt, ...) \
11 printk_deferred_once(KERN_WARNING pr_fmt("WARNING: " fmt), ##__VA_ARGS__) 10 printk_deferred_once(KERN_WARNING pr_fmt("WARNING: " fmt), ##__VA_ARGS__)
@@ -148,7 +147,7 @@ static struct orc_entry *orc_find(unsigned long ip)
148 } 147 }
149 148
150 /* vmlinux .init slow lookup: */ 149 /* vmlinux .init slow lookup: */
151 if (ip >= (unsigned long)_sinittext && ip < (unsigned long)_einittext) 150 if (init_kernel_text(ip))
152 return __orc_find(__start_orc_unwind_ip, __start_orc_unwind, 151 return __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
153 __stop_orc_unwind_ip - __start_orc_unwind_ip, ip); 152 __stop_orc_unwind_ip - __start_orc_unwind_ip, ip);
154 153
diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
index 5edb27f1a2c4..9d0b5af7db91 100644
--- a/arch/x86/kernel/vm86_32.c
+++ b/arch/x86/kernel/vm86_32.c
@@ -727,7 +727,8 @@ void handle_vm86_fault(struct kernel_vm86_regs *regs, long error_code)
727 return; 727 return;
728 728
729check_vip: 729check_vip:
730 if (VEFLAGS & X86_EFLAGS_VIP) { 730 if ((VEFLAGS & (X86_EFLAGS_VIP | X86_EFLAGS_VIF)) ==
731 (X86_EFLAGS_VIP | X86_EFLAGS_VIF)) {
731 save_v86_state(regs, VM86_STI); 732 save_v86_state(regs, VM86_STI);
732 return; 733 return;
733 } 734 }
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 9b138a06c1a4..b854ebf5851b 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -118,9 +118,11 @@ SECTIONS
118 118
119#ifdef CONFIG_X86_64 119#ifdef CONFIG_X86_64
120 . = ALIGN(PAGE_SIZE); 120 . = ALIGN(PAGE_SIZE);
121 VMLINUX_SYMBOL(__entry_trampoline_start) = .;
121 _entry_trampoline = .; 122 _entry_trampoline = .;
122 *(.entry_trampoline) 123 *(.entry_trampoline)
123 . = ALIGN(PAGE_SIZE); 124 . = ALIGN(PAGE_SIZE);
125 VMLINUX_SYMBOL(__entry_trampoline_end) = .;
124 ASSERT(. - _entry_trampoline == PAGE_SIZE, "entry trampoline is too big"); 126 ASSERT(. - _entry_trampoline == PAGE_SIZE, "entry trampoline is too big");
125#endif 127#endif
126 128
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index a0c5a69bc7c4..b671fc2d0422 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -607,7 +607,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
607 (1 << KVM_FEATURE_PV_EOI) | 607 (1 << KVM_FEATURE_PV_EOI) |
608 (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT) | 608 (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT) |
609 (1 << KVM_FEATURE_PV_UNHALT) | 609 (1 << KVM_FEATURE_PV_UNHALT) |
610 (1 << KVM_FEATURE_PV_TLB_FLUSH); 610 (1 << KVM_FEATURE_PV_TLB_FLUSH) |
611 (1 << KVM_FEATURE_ASYNC_PF_VMEXIT);
611 612
612 if (sched_info_on()) 613 if (sched_info_on())
613 entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); 614 entry->eax |= (1 << KVM_FEATURE_STEAL_TIME);
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 924ac8ce9d50..391dda8d43b7 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -2002,14 +2002,13 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value)
2002 2002
2003void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event) 2003void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event)
2004{ 2004{
2005 struct kvm_lapic *apic; 2005 struct kvm_lapic *apic = vcpu->arch.apic;
2006 int i; 2006 int i;
2007 2007
2008 apic_debug("%s\n", __func__); 2008 if (!apic)
2009 return;
2009 2010
2010 ASSERT(vcpu); 2011 apic_debug("%s\n", __func__);
2011 apic = vcpu->arch.apic;
2012 ASSERT(apic != NULL);
2013 2012
2014 /* Stop the timer in case it's a reset to an active apic */ 2013 /* Stop the timer in case it's a reset to an active apic */
2015 hrtimer_cancel(&apic->lapic_timer.timer); 2014 hrtimer_cancel(&apic->lapic_timer.timer);
@@ -2165,7 +2164,6 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
2165 */ 2164 */
2166 vcpu->arch.apic_base = MSR_IA32_APICBASE_ENABLE; 2165 vcpu->arch.apic_base = MSR_IA32_APICBASE_ENABLE;
2167 static_key_slow_inc(&apic_sw_disabled.key); /* sw disabled at reset */ 2166 static_key_slow_inc(&apic_sw_disabled.key); /* sw disabled at reset */
2168 kvm_lapic_reset(vcpu, false);
2169 kvm_iodevice_init(&apic->dev, &apic_mmio_ops); 2167 kvm_iodevice_init(&apic->dev, &apic_mmio_ops);
2170 2168
2171 return 0; 2169 return 0;
@@ -2569,7 +2567,6 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
2569 2567
2570 pe = xchg(&apic->pending_events, 0); 2568 pe = xchg(&apic->pending_events, 0);
2571 if (test_bit(KVM_APIC_INIT, &pe)) { 2569 if (test_bit(KVM_APIC_INIT, &pe)) {
2572 kvm_lapic_reset(vcpu, true);
2573 kvm_vcpu_reset(vcpu, true); 2570 kvm_vcpu_reset(vcpu, true);
2574 if (kvm_vcpu_is_bsp(apic->vcpu)) 2571 if (kvm_vcpu_is_bsp(apic->vcpu))
2575 vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; 2572 vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 8eca1d04aeb8..763bb3bade63 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2770,8 +2770,10 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
2770 else 2770 else
2771 pte_access &= ~ACC_WRITE_MASK; 2771 pte_access &= ~ACC_WRITE_MASK;
2772 2772
2773 if (!kvm_is_mmio_pfn(pfn))
2774 spte |= shadow_me_mask;
2775
2773 spte |= (u64)pfn << PAGE_SHIFT; 2776 spte |= (u64)pfn << PAGE_SHIFT;
2774 spte |= shadow_me_mask;
2775 2777
2776 if (pte_access & ACC_WRITE_MASK) { 2778 if (pte_access & ACC_WRITE_MASK) {
2777 2779
@@ -3029,7 +3031,7 @@ static int kvm_handle_bad_page(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn)
3029 return RET_PF_RETRY; 3031 return RET_PF_RETRY;
3030 } 3032 }
3031 3033
3032 return -EFAULT; 3034 return RET_PF_EMULATE;
3033} 3035}
3034 3036
3035static void transparent_hugepage_adjust(struct kvm_vcpu *vcpu, 3037static void transparent_hugepage_adjust(struct kvm_vcpu *vcpu,
@@ -5080,7 +5082,7 @@ void kvm_mmu_uninit_vm(struct kvm *kvm)
5080typedef bool (*slot_level_handler) (struct kvm *kvm, struct kvm_rmap_head *rmap_head); 5082typedef bool (*slot_level_handler) (struct kvm *kvm, struct kvm_rmap_head *rmap_head);
5081 5083
5082/* The caller should hold mmu-lock before calling this function. */ 5084/* The caller should hold mmu-lock before calling this function. */
5083static bool 5085static __always_inline bool
5084slot_handle_level_range(struct kvm *kvm, struct kvm_memory_slot *memslot, 5086slot_handle_level_range(struct kvm *kvm, struct kvm_memory_slot *memslot,
5085 slot_level_handler fn, int start_level, int end_level, 5087 slot_level_handler fn, int start_level, int end_level,
5086 gfn_t start_gfn, gfn_t end_gfn, bool lock_flush_tlb) 5088 gfn_t start_gfn, gfn_t end_gfn, bool lock_flush_tlb)
@@ -5110,7 +5112,7 @@ slot_handle_level_range(struct kvm *kvm, struct kvm_memory_slot *memslot,
5110 return flush; 5112 return flush;
5111} 5113}
5112 5114
5113static bool 5115static __always_inline bool
5114slot_handle_level(struct kvm *kvm, struct kvm_memory_slot *memslot, 5116slot_handle_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5115 slot_level_handler fn, int start_level, int end_level, 5117 slot_level_handler fn, int start_level, int end_level,
5116 bool lock_flush_tlb) 5118 bool lock_flush_tlb)
@@ -5121,7 +5123,7 @@ slot_handle_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5121 lock_flush_tlb); 5123 lock_flush_tlb);
5122} 5124}
5123 5125
5124static bool 5126static __always_inline bool
5125slot_handle_all_level(struct kvm *kvm, struct kvm_memory_slot *memslot, 5127slot_handle_all_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5126 slot_level_handler fn, bool lock_flush_tlb) 5128 slot_level_handler fn, bool lock_flush_tlb)
5127{ 5129{
@@ -5129,7 +5131,7 @@ slot_handle_all_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5129 PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb); 5131 PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb);
5130} 5132}
5131 5133
5132static bool 5134static __always_inline bool
5133slot_handle_large_level(struct kvm *kvm, struct kvm_memory_slot *memslot, 5135slot_handle_large_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5134 slot_level_handler fn, bool lock_flush_tlb) 5136 slot_level_handler fn, bool lock_flush_tlb)
5135{ 5137{
@@ -5137,7 +5139,7 @@ slot_handle_large_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5137 PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb); 5139 PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb);
5138} 5140}
5139 5141
5140static bool 5142static __always_inline bool
5141slot_handle_leaf(struct kvm *kvm, struct kvm_memory_slot *memslot, 5143slot_handle_leaf(struct kvm *kvm, struct kvm_memory_slot *memslot,
5142 slot_level_handler fn, bool lock_flush_tlb) 5144 slot_level_handler fn, bool lock_flush_tlb)
5143{ 5145{
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index b3e488a74828..be9c839e2c89 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -49,6 +49,7 @@
49#include <asm/debugreg.h> 49#include <asm/debugreg.h>
50#include <asm/kvm_para.h> 50#include <asm/kvm_para.h>
51#include <asm/irq_remapping.h> 51#include <asm/irq_remapping.h>
52#include <asm/microcode.h>
52#include <asm/nospec-branch.h> 53#include <asm/nospec-branch.h>
53 54
54#include <asm/virtext.h> 55#include <asm/virtext.h>
@@ -178,6 +179,8 @@ struct vcpu_svm {
178 uint64_t sysenter_eip; 179 uint64_t sysenter_eip;
179 uint64_t tsc_aux; 180 uint64_t tsc_aux;
180 181
182 u64 msr_decfg;
183
181 u64 next_rip; 184 u64 next_rip;
182 185
183 u64 host_user_msrs[NR_HOST_SAVE_USER_MSRS]; 186 u64 host_user_msrs[NR_HOST_SAVE_USER_MSRS];
@@ -300,6 +303,8 @@ module_param(vgif, int, 0444);
300static int sev = IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT); 303static int sev = IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT);
301module_param(sev, int, 0444); 304module_param(sev, int, 0444);
302 305
306static u8 rsm_ins_bytes[] = "\x0f\xaa";
307
303static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0); 308static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
304static void svm_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa); 309static void svm_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa);
305static void svm_complete_interrupts(struct vcpu_svm *svm); 310static void svm_complete_interrupts(struct vcpu_svm *svm);
@@ -1383,6 +1388,7 @@ static void init_vmcb(struct vcpu_svm *svm)
1383 set_intercept(svm, INTERCEPT_SKINIT); 1388 set_intercept(svm, INTERCEPT_SKINIT);
1384 set_intercept(svm, INTERCEPT_WBINVD); 1389 set_intercept(svm, INTERCEPT_WBINVD);
1385 set_intercept(svm, INTERCEPT_XSETBV); 1390 set_intercept(svm, INTERCEPT_XSETBV);
1391 set_intercept(svm, INTERCEPT_RSM);
1386 1392
1387 if (!kvm_mwait_in_guest()) { 1393 if (!kvm_mwait_in_guest()) {
1388 set_intercept(svm, INTERCEPT_MONITOR); 1394 set_intercept(svm, INTERCEPT_MONITOR);
@@ -1902,6 +1908,7 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
1902 u32 dummy; 1908 u32 dummy;
1903 u32 eax = 1; 1909 u32 eax = 1;
1904 1910
1911 vcpu->arch.microcode_version = 0x01000065;
1905 svm->spec_ctrl = 0; 1912 svm->spec_ctrl = 0;
1906 1913
1907 if (!init_event) { 1914 if (!init_event) {
@@ -3699,6 +3706,12 @@ static int emulate_on_interception(struct vcpu_svm *svm)
3699 return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE; 3706 return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE;
3700} 3707}
3701 3708
3709static int rsm_interception(struct vcpu_svm *svm)
3710{
3711 return x86_emulate_instruction(&svm->vcpu, 0, 0,
3712 rsm_ins_bytes, 2) == EMULATE_DONE;
3713}
3714
3702static int rdpmc_interception(struct vcpu_svm *svm) 3715static int rdpmc_interception(struct vcpu_svm *svm)
3703{ 3716{
3704 int err; 3717 int err;
@@ -3860,6 +3873,22 @@ static int cr8_write_interception(struct vcpu_svm *svm)
3860 return 0; 3873 return 0;
3861} 3874}
3862 3875
3876static int svm_get_msr_feature(struct kvm_msr_entry *msr)
3877{
3878 msr->data = 0;
3879
3880 switch (msr->index) {
3881 case MSR_F10H_DECFG:
3882 if (boot_cpu_has(X86_FEATURE_LFENCE_RDTSC))
3883 msr->data |= MSR_F10H_DECFG_LFENCE_SERIALIZE;
3884 break;
3885 default:
3886 return 1;
3887 }
3888
3889 return 0;
3890}
3891
3863static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) 3892static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
3864{ 3893{
3865 struct vcpu_svm *svm = to_svm(vcpu); 3894 struct vcpu_svm *svm = to_svm(vcpu);
@@ -3935,9 +3964,6 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
3935 3964
3936 msr_info->data = svm->spec_ctrl; 3965 msr_info->data = svm->spec_ctrl;
3937 break; 3966 break;
3938 case MSR_IA32_UCODE_REV:
3939 msr_info->data = 0x01000065;
3940 break;
3941 case MSR_F15H_IC_CFG: { 3967 case MSR_F15H_IC_CFG: {
3942 3968
3943 int family, model; 3969 int family, model;
@@ -3955,6 +3981,9 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
3955 msr_info->data = 0x1E; 3981 msr_info->data = 0x1E;
3956 } 3982 }
3957 break; 3983 break;
3984 case MSR_F10H_DECFG:
3985 msr_info->data = svm->msr_decfg;
3986 break;
3958 default: 3987 default:
3959 return kvm_get_msr_common(vcpu, msr_info); 3988 return kvm_get_msr_common(vcpu, msr_info);
3960 } 3989 }
@@ -4133,6 +4162,24 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
4133 case MSR_VM_IGNNE: 4162 case MSR_VM_IGNNE:
4134 vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data); 4163 vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data);
4135 break; 4164 break;
4165 case MSR_F10H_DECFG: {
4166 struct kvm_msr_entry msr_entry;
4167
4168 msr_entry.index = msr->index;
4169 if (svm_get_msr_feature(&msr_entry))
4170 return 1;
4171
4172 /* Check the supported bits */
4173 if (data & ~msr_entry.data)
4174 return 1;
4175
4176 /* Don't allow the guest to change a bit, #GP */
4177 if (!msr->host_initiated && (data ^ msr_entry.data))
4178 return 1;
4179
4180 svm->msr_decfg = data;
4181 break;
4182 }
4136 case MSR_IA32_APICBASE: 4183 case MSR_IA32_APICBASE:
4137 if (kvm_vcpu_apicv_active(vcpu)) 4184 if (kvm_vcpu_apicv_active(vcpu))
4138 avic_update_vapic_bar(to_svm(vcpu), data); 4185 avic_update_vapic_bar(to_svm(vcpu), data);
@@ -4541,7 +4588,7 @@ static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = {
4541 [SVM_EXIT_MWAIT] = mwait_interception, 4588 [SVM_EXIT_MWAIT] = mwait_interception,
4542 [SVM_EXIT_XSETBV] = xsetbv_interception, 4589 [SVM_EXIT_XSETBV] = xsetbv_interception,
4543 [SVM_EXIT_NPF] = npf_interception, 4590 [SVM_EXIT_NPF] = npf_interception,
4544 [SVM_EXIT_RSM] = emulate_on_interception, 4591 [SVM_EXIT_RSM] = rsm_interception,
4545 [SVM_EXIT_AVIC_INCOMPLETE_IPI] = avic_incomplete_ipi_interception, 4592 [SVM_EXIT_AVIC_INCOMPLETE_IPI] = avic_incomplete_ipi_interception,
4546 [SVM_EXIT_AVIC_UNACCELERATED_ACCESS] = avic_unaccelerated_access_interception, 4593 [SVM_EXIT_AVIC_UNACCELERATED_ACCESS] = avic_unaccelerated_access_interception,
4547}; 4594};
@@ -5355,7 +5402,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
5355 * being speculatively taken. 5402 * being speculatively taken.
5356 */ 5403 */
5357 if (svm->spec_ctrl) 5404 if (svm->spec_ctrl)
5358 wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl); 5405 native_wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
5359 5406
5360 asm volatile ( 5407 asm volatile (
5361 "push %%" _ASM_BP "; \n\t" 5408 "push %%" _ASM_BP "; \n\t"
@@ -5464,11 +5511,11 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
5464 * If the L02 MSR bitmap does not intercept the MSR, then we need to 5511 * If the L02 MSR bitmap does not intercept the MSR, then we need to
5465 * save it. 5512 * save it.
5466 */ 5513 */
5467 if (!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)) 5514 if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))
5468 rdmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl); 5515 svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
5469 5516
5470 if (svm->spec_ctrl) 5517 if (svm->spec_ctrl)
5471 wrmsrl(MSR_IA32_SPEC_CTRL, 0); 5518 native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
5472 5519
5473 /* Eliminate branch target predictions from guest mode */ 5520 /* Eliminate branch target predictions from guest mode */
5474 vmexit_fill_RSB(); 5521 vmexit_fill_RSB();
@@ -6236,16 +6283,18 @@ e_free:
6236 6283
6237static int sev_launch_measure(struct kvm *kvm, struct kvm_sev_cmd *argp) 6284static int sev_launch_measure(struct kvm *kvm, struct kvm_sev_cmd *argp)
6238{ 6285{
6286 void __user *measure = (void __user *)(uintptr_t)argp->data;
6239 struct kvm_sev_info *sev = &kvm->arch.sev_info; 6287 struct kvm_sev_info *sev = &kvm->arch.sev_info;
6240 struct sev_data_launch_measure *data; 6288 struct sev_data_launch_measure *data;
6241 struct kvm_sev_launch_measure params; 6289 struct kvm_sev_launch_measure params;
6290 void __user *p = NULL;
6242 void *blob = NULL; 6291 void *blob = NULL;
6243 int ret; 6292 int ret;
6244 6293
6245 if (!sev_guest(kvm)) 6294 if (!sev_guest(kvm))
6246 return -ENOTTY; 6295 return -ENOTTY;
6247 6296
6248 if (copy_from_user(&params, (void __user *)(uintptr_t)argp->data, sizeof(params))) 6297 if (copy_from_user(&params, measure, sizeof(params)))
6249 return -EFAULT; 6298 return -EFAULT;
6250 6299
6251 data = kzalloc(sizeof(*data), GFP_KERNEL); 6300 data = kzalloc(sizeof(*data), GFP_KERNEL);
@@ -6256,17 +6305,13 @@ static int sev_launch_measure(struct kvm *kvm, struct kvm_sev_cmd *argp)
6256 if (!params.len) 6305 if (!params.len)
6257 goto cmd; 6306 goto cmd;
6258 6307
6259 if (params.uaddr) { 6308 p = (void __user *)(uintptr_t)params.uaddr;
6309 if (p) {
6260 if (params.len > SEV_FW_BLOB_MAX_SIZE) { 6310 if (params.len > SEV_FW_BLOB_MAX_SIZE) {
6261 ret = -EINVAL; 6311 ret = -EINVAL;
6262 goto e_free; 6312 goto e_free;
6263 } 6313 }
6264 6314
6265 if (!access_ok(VERIFY_WRITE, params.uaddr, params.len)) {
6266 ret = -EFAULT;
6267 goto e_free;
6268 }
6269
6270 ret = -ENOMEM; 6315 ret = -ENOMEM;
6271 blob = kmalloc(params.len, GFP_KERNEL); 6316 blob = kmalloc(params.len, GFP_KERNEL);
6272 if (!blob) 6317 if (!blob)
@@ -6290,13 +6335,13 @@ cmd:
6290 goto e_free_blob; 6335 goto e_free_blob;
6291 6336
6292 if (blob) { 6337 if (blob) {
6293 if (copy_to_user((void __user *)(uintptr_t)params.uaddr, blob, params.len)) 6338 if (copy_to_user(p, blob, params.len))
6294 ret = -EFAULT; 6339 ret = -EFAULT;
6295 } 6340 }
6296 6341
6297done: 6342done:
6298 params.len = data->len; 6343 params.len = data->len;
6299 if (copy_to_user((void __user *)(uintptr_t)argp->data, &params, sizeof(params))) 6344 if (copy_to_user(measure, &params, sizeof(params)))
6300 ret = -EFAULT; 6345 ret = -EFAULT;
6301e_free_blob: 6346e_free_blob:
6302 kfree(blob); 6347 kfree(blob);
@@ -6597,7 +6642,7 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp)
6597 struct page **pages; 6642 struct page **pages;
6598 void *blob, *hdr; 6643 void *blob, *hdr;
6599 unsigned long n; 6644 unsigned long n;
6600 int ret; 6645 int ret, offset;
6601 6646
6602 if (!sev_guest(kvm)) 6647 if (!sev_guest(kvm))
6603 return -ENOTTY; 6648 return -ENOTTY;
@@ -6623,6 +6668,10 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp)
6623 if (!data) 6668 if (!data)
6624 goto e_unpin_memory; 6669 goto e_unpin_memory;
6625 6670
6671 offset = params.guest_uaddr & (PAGE_SIZE - 1);
6672 data->guest_address = __sme_page_pa(pages[0]) + offset;
6673 data->guest_len = params.guest_len;
6674
6626 blob = psp_copy_user_blob(params.trans_uaddr, params.trans_len); 6675 blob = psp_copy_user_blob(params.trans_uaddr, params.trans_len);
6627 if (IS_ERR(blob)) { 6676 if (IS_ERR(blob)) {
6628 ret = PTR_ERR(blob); 6677 ret = PTR_ERR(blob);
@@ -6637,8 +6686,8 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp)
6637 ret = PTR_ERR(hdr); 6686 ret = PTR_ERR(hdr);
6638 goto e_free_blob; 6687 goto e_free_blob;
6639 } 6688 }
6640 data->trans_address = __psp_pa(blob); 6689 data->hdr_address = __psp_pa(hdr);
6641 data->trans_len = params.trans_len; 6690 data->hdr_len = params.hdr_len;
6642 6691
6643 data->handle = sev->handle; 6692 data->handle = sev->handle;
6644 ret = sev_issue_cmd(kvm, SEV_CMD_LAUNCH_UPDATE_SECRET, data, &argp->error); 6693 ret = sev_issue_cmd(kvm, SEV_CMD_LAUNCH_UPDATE_SECRET, data, &argp->error);
@@ -6821,6 +6870,7 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = {
6821 .vcpu_unblocking = svm_vcpu_unblocking, 6870 .vcpu_unblocking = svm_vcpu_unblocking,
6822 6871
6823 .update_bp_intercept = update_bp_intercept, 6872 .update_bp_intercept = update_bp_intercept,
6873 .get_msr_feature = svm_get_msr_feature,
6824 .get_msr = svm_get_msr, 6874 .get_msr = svm_get_msr,
6825 .set_msr = svm_set_msr, 6875 .set_msr = svm_set_msr,
6826 .get_segment_base = svm_get_segment_base, 6876 .get_segment_base = svm_get_segment_base,
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index f427723dc7db..2d87603f9179 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -51,6 +51,7 @@
51#include <asm/apic.h> 51#include <asm/apic.h>
52#include <asm/irq_remapping.h> 52#include <asm/irq_remapping.h>
53#include <asm/mmu_context.h> 53#include <asm/mmu_context.h>
54#include <asm/microcode.h>
54#include <asm/nospec-branch.h> 55#include <asm/nospec-branch.h>
55 56
56#include "trace.h" 57#include "trace.h"
@@ -1044,6 +1045,13 @@ static inline bool is_machine_check(u32 intr_info)
1044 (INTR_TYPE_HARD_EXCEPTION | MC_VECTOR | INTR_INFO_VALID_MASK); 1045 (INTR_TYPE_HARD_EXCEPTION | MC_VECTOR | INTR_INFO_VALID_MASK);
1045} 1046}
1046 1047
1048/* Undocumented: icebp/int1 */
1049static inline bool is_icebp(u32 intr_info)
1050{
1051 return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK))
1052 == (INTR_TYPE_PRIV_SW_EXCEPTION | INTR_INFO_VALID_MASK);
1053}
1054
1047static inline bool cpu_has_vmx_msr_bitmap(void) 1055static inline bool cpu_has_vmx_msr_bitmap(void)
1048{ 1056{
1049 return vmcs_config.cpu_based_exec_ctrl & CPU_BASED_USE_MSR_BITMAPS; 1057 return vmcs_config.cpu_based_exec_ctrl & CPU_BASED_USE_MSR_BITMAPS;
@@ -3226,6 +3234,11 @@ static inline bool vmx_feature_control_msr_valid(struct kvm_vcpu *vcpu,
3226 return !(val & ~valid_bits); 3234 return !(val & ~valid_bits);
3227} 3235}
3228 3236
3237static int vmx_get_msr_feature(struct kvm_msr_entry *msr)
3238{
3239 return 1;
3240}
3241
3229/* 3242/*
3230 * Reads an msr value (of 'msr_index') into 'pdata'. 3243 * Reads an msr value (of 'msr_index') into 'pdata'.
3231 * Returns 0 on success, non-0 otherwise. 3244 * Returns 0 on success, non-0 otherwise.
@@ -4485,7 +4498,8 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
4485 vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL, 4498 vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL,
4486 SECONDARY_EXEC_DESC); 4499 SECONDARY_EXEC_DESC);
4487 hw_cr4 &= ~X86_CR4_UMIP; 4500 hw_cr4 &= ~X86_CR4_UMIP;
4488 } else 4501 } else if (!is_guest_mode(vcpu) ||
4502 !nested_cpu_has2(get_vmcs12(vcpu), SECONDARY_EXEC_DESC))
4489 vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, 4503 vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL,
4490 SECONDARY_EXEC_DESC); 4504 SECONDARY_EXEC_DESC);
4491 4505
@@ -5765,6 +5779,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
5765 vmx->rmode.vm86_active = 0; 5779 vmx->rmode.vm86_active = 0;
5766 vmx->spec_ctrl = 0; 5780 vmx->spec_ctrl = 0;
5767 5781
5782 vcpu->arch.microcode_version = 0x100000000ULL;
5768 vmx->vcpu.arch.regs[VCPU_REGS_RDX] = get_rdx_init_val(); 5783 vmx->vcpu.arch.regs[VCPU_REGS_RDX] = get_rdx_init_val();
5769 kvm_set_cr8(vcpu, 0); 5784 kvm_set_cr8(vcpu, 0);
5770 5785
@@ -6171,7 +6186,7 @@ static int handle_exception(struct kvm_vcpu *vcpu)
6171 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))) { 6186 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))) {
6172 vcpu->arch.dr6 &= ~15; 6187 vcpu->arch.dr6 &= ~15;
6173 vcpu->arch.dr6 |= dr6 | DR6_RTM; 6188 vcpu->arch.dr6 |= dr6 | DR6_RTM;
6174 if (!(dr6 & ~DR6_RESERVED)) /* icebp */ 6189 if (is_icebp(intr_info))
6175 skip_emulated_instruction(vcpu); 6190 skip_emulated_instruction(vcpu);
6176 6191
6177 kvm_queue_exception(vcpu, DB_VECTOR); 6192 kvm_queue_exception(vcpu, DB_VECTOR);
@@ -9452,7 +9467,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
9452 * being speculatively taken. 9467 * being speculatively taken.
9453 */ 9468 */
9454 if (vmx->spec_ctrl) 9469 if (vmx->spec_ctrl)
9455 wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); 9470 native_wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
9456 9471
9457 vmx->__launched = vmx->loaded_vmcs->launched; 9472 vmx->__launched = vmx->loaded_vmcs->launched;
9458 asm( 9473 asm(
@@ -9587,11 +9602,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
9587 * If the L02 MSR bitmap does not intercept the MSR, then we need to 9602 * If the L02 MSR bitmap does not intercept the MSR, then we need to
9588 * save it. 9603 * save it.
9589 */ 9604 */
9590 if (!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)) 9605 if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))
9591 rdmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); 9606 vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
9592 9607
9593 if (vmx->spec_ctrl) 9608 if (vmx->spec_ctrl)
9594 wrmsrl(MSR_IA32_SPEC_CTRL, 0); 9609 native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
9595 9610
9596 /* Eliminate branch target predictions from guest mode */ 9611 /* Eliminate branch target predictions from guest mode */
9597 vmexit_fill_RSB(); 9612 vmexit_fill_RSB();
@@ -10136,7 +10151,10 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu,
10136 (unsigned long)(vmcs12->posted_intr_desc_addr & 10151 (unsigned long)(vmcs12->posted_intr_desc_addr &
10137 (PAGE_SIZE - 1))); 10152 (PAGE_SIZE - 1)));
10138 } 10153 }
10139 if (!nested_vmx_prepare_msr_bitmap(vcpu, vmcs12)) 10154 if (nested_vmx_prepare_msr_bitmap(vcpu, vmcs12))
10155 vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL,
10156 CPU_BASED_USE_MSR_BITMAPS);
10157 else
10140 vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL, 10158 vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL,
10141 CPU_BASED_USE_MSR_BITMAPS); 10159 CPU_BASED_USE_MSR_BITMAPS);
10142} 10160}
@@ -10224,8 +10242,8 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
10224 * updated to reflect this when L1 (or its L2s) actually write to 10242 * updated to reflect this when L1 (or its L2s) actually write to
10225 * the MSR. 10243 * the MSR.
10226 */ 10244 */
10227 bool pred_cmd = msr_write_intercepted_l01(vcpu, MSR_IA32_PRED_CMD); 10245 bool pred_cmd = !msr_write_intercepted_l01(vcpu, MSR_IA32_PRED_CMD);
10228 bool spec_ctrl = msr_write_intercepted_l01(vcpu, MSR_IA32_SPEC_CTRL); 10246 bool spec_ctrl = !msr_write_intercepted_l01(vcpu, MSR_IA32_SPEC_CTRL);
10229 10247
10230 /* Nothing to do if the MSR bitmap is not in use. */ 10248 /* Nothing to do if the MSR bitmap is not in use. */
10231 if (!cpu_has_vmx_msr_bitmap() || 10249 if (!cpu_has_vmx_msr_bitmap() ||
@@ -11196,7 +11214,12 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
11196 if (ret) 11214 if (ret)
11197 return ret; 11215 return ret;
11198 11216
11199 if (vmcs12->guest_activity_state == GUEST_ACTIVITY_HLT) 11217 /*
11218 * If we're entering a halted L2 vcpu and the L2 vcpu won't be woken
11219 * by event injection, halt vcpu.
11220 */
11221 if ((vmcs12->guest_activity_state == GUEST_ACTIVITY_HLT) &&
11222 !(vmcs12->vm_entry_intr_info_field & INTR_INFO_VALID_MASK))
11200 return kvm_vcpu_halt(vcpu); 11223 return kvm_vcpu_halt(vcpu);
11201 11224
11202 vmx->nested.nested_run_pending = 1; 11225 vmx->nested.nested_run_pending = 1;
@@ -12287,6 +12310,7 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = {
12287 .vcpu_put = vmx_vcpu_put, 12310 .vcpu_put = vmx_vcpu_put,
12288 12311
12289 .update_bp_intercept = update_exception_bitmap, 12312 .update_bp_intercept = update_exception_bitmap,
12313 .get_msr_feature = vmx_get_msr_feature,
12290 .get_msr = vmx_get_msr, 12314 .get_msr = vmx_get_msr,
12291 .set_msr = vmx_set_msr, 12315 .set_msr = vmx_set_msr,
12292 .get_segment_base = vmx_get_segment_base, 12316 .get_segment_base = vmx_get_segment_base,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c8a0b545ac20..18b5ca7a3197 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1049,6 +1049,45 @@ static u32 emulated_msrs[] = {
1049 1049
1050static unsigned num_emulated_msrs; 1050static unsigned num_emulated_msrs;
1051 1051
1052/*
1053 * List of msr numbers which are used to expose MSR-based features that
1054 * can be used by a hypervisor to validate requested CPU features.
1055 */
1056static u32 msr_based_features[] = {
1057 MSR_F10H_DECFG,
1058 MSR_IA32_UCODE_REV,
1059};
1060
1061static unsigned int num_msr_based_features;
1062
1063static int kvm_get_msr_feature(struct kvm_msr_entry *msr)
1064{
1065 switch (msr->index) {
1066 case MSR_IA32_UCODE_REV:
1067 rdmsrl(msr->index, msr->data);
1068 break;
1069 default:
1070 if (kvm_x86_ops->get_msr_feature(msr))
1071 return 1;
1072 }
1073 return 0;
1074}
1075
1076static int do_get_msr_feature(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
1077{
1078 struct kvm_msr_entry msr;
1079 int r;
1080
1081 msr.index = index;
1082 r = kvm_get_msr_feature(&msr);
1083 if (r)
1084 return r;
1085
1086 *data = msr.data;
1087
1088 return 0;
1089}
1090
1052bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer) 1091bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer)
1053{ 1092{
1054 if (efer & efer_reserved_bits) 1093 if (efer & efer_reserved_bits)
@@ -2222,7 +2261,6 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
2222 2261
2223 switch (msr) { 2262 switch (msr) {
2224 case MSR_AMD64_NB_CFG: 2263 case MSR_AMD64_NB_CFG:
2225 case MSR_IA32_UCODE_REV:
2226 case MSR_IA32_UCODE_WRITE: 2264 case MSR_IA32_UCODE_WRITE:
2227 case MSR_VM_HSAVE_PA: 2265 case MSR_VM_HSAVE_PA:
2228 case MSR_AMD64_PATCH_LOADER: 2266 case MSR_AMD64_PATCH_LOADER:
@@ -2230,6 +2268,10 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
2230 case MSR_AMD64_DC_CFG: 2268 case MSR_AMD64_DC_CFG:
2231 break; 2269 break;
2232 2270
2271 case MSR_IA32_UCODE_REV:
2272 if (msr_info->host_initiated)
2273 vcpu->arch.microcode_version = data;
2274 break;
2233 case MSR_EFER: 2275 case MSR_EFER:
2234 return set_efer(vcpu, data); 2276 return set_efer(vcpu, data);
2235 case MSR_K7_HWCR: 2277 case MSR_K7_HWCR:
@@ -2525,7 +2567,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
2525 msr_info->data = 0; 2567 msr_info->data = 0;
2526 break; 2568 break;
2527 case MSR_IA32_UCODE_REV: 2569 case MSR_IA32_UCODE_REV:
2528 msr_info->data = 0x100000000ULL; 2570 msr_info->data = vcpu->arch.microcode_version;
2529 break; 2571 break;
2530 case MSR_MTRRcap: 2572 case MSR_MTRRcap:
2531 case 0x200 ... 0x2ff: 2573 case 0x200 ... 0x2ff:
@@ -2680,13 +2722,11 @@ static int __msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs *msrs,
2680 int (*do_msr)(struct kvm_vcpu *vcpu, 2722 int (*do_msr)(struct kvm_vcpu *vcpu,
2681 unsigned index, u64 *data)) 2723 unsigned index, u64 *data))
2682{ 2724{
2683 int i, idx; 2725 int i;
2684 2726
2685 idx = srcu_read_lock(&vcpu->kvm->srcu);
2686 for (i = 0; i < msrs->nmsrs; ++i) 2727 for (i = 0; i < msrs->nmsrs; ++i)
2687 if (do_msr(vcpu, entries[i].index, &entries[i].data)) 2728 if (do_msr(vcpu, entries[i].index, &entries[i].data))
2688 break; 2729 break;
2689 srcu_read_unlock(&vcpu->kvm->srcu, idx);
2690 2730
2691 return i; 2731 return i;
2692} 2732}
@@ -2785,6 +2825,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
2785 case KVM_CAP_SET_BOOT_CPU_ID: 2825 case KVM_CAP_SET_BOOT_CPU_ID:
2786 case KVM_CAP_SPLIT_IRQCHIP: 2826 case KVM_CAP_SPLIT_IRQCHIP:
2787 case KVM_CAP_IMMEDIATE_EXIT: 2827 case KVM_CAP_IMMEDIATE_EXIT:
2828 case KVM_CAP_GET_MSR_FEATURES:
2788 r = 1; 2829 r = 1;
2789 break; 2830 break;
2790 case KVM_CAP_ADJUST_CLOCK: 2831 case KVM_CAP_ADJUST_CLOCK:
@@ -2899,6 +2940,31 @@ long kvm_arch_dev_ioctl(struct file *filp,
2899 goto out; 2940 goto out;
2900 r = 0; 2941 r = 0;
2901 break; 2942 break;
2943 case KVM_GET_MSR_FEATURE_INDEX_LIST: {
2944 struct kvm_msr_list __user *user_msr_list = argp;
2945 struct kvm_msr_list msr_list;
2946 unsigned int n;
2947
2948 r = -EFAULT;
2949 if (copy_from_user(&msr_list, user_msr_list, sizeof(msr_list)))
2950 goto out;
2951 n = msr_list.nmsrs;
2952 msr_list.nmsrs = num_msr_based_features;
2953 if (copy_to_user(user_msr_list, &msr_list, sizeof(msr_list)))
2954 goto out;
2955 r = -E2BIG;
2956 if (n < msr_list.nmsrs)
2957 goto out;
2958 r = -EFAULT;
2959 if (copy_to_user(user_msr_list->indices, &msr_based_features,
2960 num_msr_based_features * sizeof(u32)))
2961 goto out;
2962 r = 0;
2963 break;
2964 }
2965 case KVM_GET_MSRS:
2966 r = msr_io(NULL, argp, do_get_msr_feature, 1);
2967 break;
2902 } 2968 }
2903 default: 2969 default:
2904 r = -EINVAL; 2970 r = -EINVAL;
@@ -3636,12 +3702,18 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
3636 r = 0; 3702 r = 0;
3637 break; 3703 break;
3638 } 3704 }
3639 case KVM_GET_MSRS: 3705 case KVM_GET_MSRS: {
3706 int idx = srcu_read_lock(&vcpu->kvm->srcu);
3640 r = msr_io(vcpu, argp, do_get_msr, 1); 3707 r = msr_io(vcpu, argp, do_get_msr, 1);
3708 srcu_read_unlock(&vcpu->kvm->srcu, idx);
3641 break; 3709 break;
3642 case KVM_SET_MSRS: 3710 }
3711 case KVM_SET_MSRS: {
3712 int idx = srcu_read_lock(&vcpu->kvm->srcu);
3643 r = msr_io(vcpu, argp, do_set_msr, 0); 3713 r = msr_io(vcpu, argp, do_set_msr, 0);
3714 srcu_read_unlock(&vcpu->kvm->srcu, idx);
3644 break; 3715 break;
3716 }
3645 case KVM_TPR_ACCESS_REPORTING: { 3717 case KVM_TPR_ACCESS_REPORTING: {
3646 struct kvm_tpr_access_ctl tac; 3718 struct kvm_tpr_access_ctl tac;
3647 3719
@@ -4464,6 +4536,19 @@ static void kvm_init_msr_list(void)
4464 j++; 4536 j++;
4465 } 4537 }
4466 num_emulated_msrs = j; 4538 num_emulated_msrs = j;
4539
4540 for (i = j = 0; i < ARRAY_SIZE(msr_based_features); i++) {
4541 struct kvm_msr_entry msr;
4542
4543 msr.index = msr_based_features[i];
4544 if (kvm_get_msr_feature(&msr))
4545 continue;
4546
4547 if (j < i)
4548 msr_based_features[j] = msr_based_features[i];
4549 j++;
4550 }
4551 num_msr_based_features = j;
4467} 4552}
4468 4553
4469static int vcpu_mmio_write(struct kvm_vcpu *vcpu, gpa_t addr, int len, 4554static int vcpu_mmio_write(struct kvm_vcpu *vcpu, gpa_t addr, int len,
@@ -8017,6 +8102,8 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
8017 8102
8018void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) 8103void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
8019{ 8104{
8105 kvm_lapic_reset(vcpu, init_event);
8106
8020 vcpu->arch.hflags = 0; 8107 vcpu->arch.hflags = 0;
8021 8108
8022 vcpu->arch.smi_pending = 0; 8109 vcpu->arch.smi_pending = 0;
@@ -8460,10 +8547,8 @@ int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
8460 return r; 8547 return r;
8461 } 8548 }
8462 8549
8463 if (!size) { 8550 if (!size)
8464 r = vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE); 8551 vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
8465 WARN_ON(r < 0);
8466 }
8467 8552
8468 return 0; 8553 return 0;
8469} 8554}
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index 91e9700cc6dc..25a972c61b0a 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -28,7 +28,6 @@ lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o insn-eval.o
28lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o 28lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o
29lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o 29lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
30lib-$(CONFIG_RETPOLINE) += retpoline.o 30lib-$(CONFIG_RETPOLINE) += retpoline.o
31OBJECT_FILES_NON_STANDARD_retpoline.o :=y
32 31
33obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o 32obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o
34 33
diff --git a/arch/x86/lib/cpu.c b/arch/x86/lib/cpu.c
index d6f848d1211d..2dd1fe13a37b 100644
--- a/arch/x86/lib/cpu.c
+++ b/arch/x86/lib/cpu.c
@@ -18,7 +18,7 @@ unsigned int x86_model(unsigned int sig)
18{ 18{
19 unsigned int fam, model; 19 unsigned int fam, model;
20 20
21 fam = x86_family(sig); 21 fam = x86_family(sig);
22 22
23 model = (sig >> 4) & 0xf; 23 model = (sig >> 4) & 0xf;
24 24
diff --git a/arch/x86/lib/error-inject.c b/arch/x86/lib/error-inject.c
index 7b881d03d0dd..3cdf06128d13 100644
--- a/arch/x86/lib/error-inject.c
+++ b/arch/x86/lib/error-inject.c
@@ -7,6 +7,7 @@ asmlinkage void just_return_func(void);
7 7
8asm( 8asm(
9 ".type just_return_func, @function\n" 9 ".type just_return_func, @function\n"
10 ".globl just_return_func\n"
10 "just_return_func:\n" 11 "just_return_func:\n"
11 " ret\n" 12 " ret\n"
12 ".size just_return_func, .-just_return_func\n" 13 ".size just_return_func, .-just_return_func\n"
diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S
index 480edc3a5e03..c909961e678a 100644
--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -7,7 +7,6 @@
7#include <asm/alternative-asm.h> 7#include <asm/alternative-asm.h>
8#include <asm/export.h> 8#include <asm/export.h>
9#include <asm/nospec-branch.h> 9#include <asm/nospec-branch.h>
10#include <asm/bitsperlong.h>
11 10
12.macro THUNK reg 11.macro THUNK reg
13 .section .text.__x86.indirect_thunk 12 .section .text.__x86.indirect_thunk
@@ -47,58 +46,3 @@ GENERATE_THUNK(r13)
47GENERATE_THUNK(r14) 46GENERATE_THUNK(r14)
48GENERATE_THUNK(r15) 47GENERATE_THUNK(r15)
49#endif 48#endif
50
51/*
52 * Fill the CPU return stack buffer.
53 *
54 * Each entry in the RSB, if used for a speculative 'ret', contains an
55 * infinite 'pause; lfence; jmp' loop to capture speculative execution.
56 *
57 * This is required in various cases for retpoline and IBRS-based
58 * mitigations for the Spectre variant 2 vulnerability. Sometimes to
59 * eliminate potentially bogus entries from the RSB, and sometimes
60 * purely to ensure that it doesn't get empty, which on some CPUs would
61 * allow predictions from other (unwanted!) sources to be used.
62 *
63 * Google experimented with loop-unrolling and this turned out to be
64 * the optimal version - two calls, each with their own speculation
65 * trap should their return address end up getting used, in a loop.
66 */
67.macro STUFF_RSB nr:req sp:req
68 mov $(\nr / 2), %_ASM_BX
69 .align 16
70771:
71 call 772f
72773: /* speculation trap */
73 pause
74 lfence
75 jmp 773b
76 .align 16
77772:
78 call 774f
79775: /* speculation trap */
80 pause
81 lfence
82 jmp 775b
83 .align 16
84774:
85 dec %_ASM_BX
86 jnz 771b
87 add $((BITS_PER_LONG/8) * \nr), \sp
88.endm
89
90#define RSB_FILL_LOOPS 16 /* To avoid underflow */
91
92ENTRY(__fill_rsb)
93 STUFF_RSB RSB_FILL_LOOPS, %_ASM_SP
94 ret
95END(__fill_rsb)
96EXPORT_SYMBOL_GPL(__fill_rsb)
97
98#define RSB_CLEAR_LOOPS 32 /* To forcibly overwrite all entries */
99
100ENTRY(__clear_rsb)
101 STUFF_RSB RSB_CLEAR_LOOPS, %_ASM_SP
102 ret
103END(__clear_rsb)
104EXPORT_SYMBOL_GPL(__clear_rsb)
diff --git a/arch/x86/mm/cpu_entry_area.c b/arch/x86/mm/cpu_entry_area.c
index b9283cc27622..476d810639a8 100644
--- a/arch/x86/mm/cpu_entry_area.c
+++ b/arch/x86/mm/cpu_entry_area.c
@@ -163,4 +163,10 @@ void __init setup_cpu_entry_areas(void)
163 163
164 for_each_possible_cpu(cpu) 164 for_each_possible_cpu(cpu)
165 setup_cpu_entry_area(cpu); 165 setup_cpu_entry_area(cpu);
166
167 /*
168 * This is the last essential update to swapper_pgdir which needs
169 * to be synchronized to initial_page_table on 32bit.
170 */
171 sync_initial_page_table();
166} 172}
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 800de815519c..25a30b5d6582 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -330,7 +330,7 @@ static noinline int vmalloc_fault(unsigned long address)
330 if (!pmd_k) 330 if (!pmd_k)
331 return -1; 331 return -1;
332 332
333 if (pmd_huge(*pmd_k)) 333 if (pmd_large(*pmd_k))
334 return 0; 334 return 0;
335 335
336 pte_k = pte_offset_kernel(pmd_k, address); 336 pte_k = pte_offset_kernel(pmd_k, address);
@@ -475,7 +475,7 @@ static noinline int vmalloc_fault(unsigned long address)
475 if (pud_none(*pud) || pud_pfn(*pud) != pud_pfn(*pud_ref)) 475 if (pud_none(*pud) || pud_pfn(*pud) != pud_pfn(*pud_ref))
476 BUG(); 476 BUG();
477 477
478 if (pud_huge(*pud)) 478 if (pud_large(*pud))
479 return 0; 479 return 0;
480 480
481 pmd = pmd_offset(pud, address); 481 pmd = pmd_offset(pud, address);
@@ -486,7 +486,7 @@ static noinline int vmalloc_fault(unsigned long address)
486 if (pmd_none(*pmd) || pmd_pfn(*pmd) != pmd_pfn(*pmd_ref)) 486 if (pmd_none(*pmd) || pmd_pfn(*pmd) != pmd_pfn(*pmd_ref))
487 BUG(); 487 BUG();
488 488
489 if (pmd_huge(*pmd)) 489 if (pmd_large(*pmd))
490 return 0; 490 return 0;
491 491
492 pte_ref = pte_offset_kernel(pmd_ref, address); 492 pte_ref = pte_offset_kernel(pmd_ref, address);
@@ -1248,10 +1248,6 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
1248 tsk = current; 1248 tsk = current;
1249 mm = tsk->mm; 1249 mm = tsk->mm;
1250 1250
1251 /*
1252 * Detect and handle instructions that would cause a page fault for
1253 * both a tracked kernel page and a userspace page.
1254 */
1255 prefetchw(&mm->mmap_sem); 1251 prefetchw(&mm->mmap_sem);
1256 1252
1257 if (unlikely(kmmio_fault(regs, address))) 1253 if (unlikely(kmmio_fault(regs, address)))
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index 79cb066f40c0..396e1f0151ac 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -453,6 +453,21 @@ static inline void permanent_kmaps_init(pgd_t *pgd_base)
453} 453}
454#endif /* CONFIG_HIGHMEM */ 454#endif /* CONFIG_HIGHMEM */
455 455
456void __init sync_initial_page_table(void)
457{
458 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
459 swapper_pg_dir + KERNEL_PGD_BOUNDARY,
460 KERNEL_PGD_PTRS);
461
462 /*
463 * sync back low identity map too. It is used for example
464 * in the 32-bit EFI stub.
465 */
466 clone_pgd_range(initial_page_table,
467 swapper_pg_dir + KERNEL_PGD_BOUNDARY,
468 min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
469}
470
456void __init native_pagetable_init(void) 471void __init native_pagetable_init(void)
457{ 472{
458 unsigned long pfn, va; 473 unsigned long pfn, va;
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 1ab42c852069..af11a2890235 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -256,7 +256,7 @@ static void __set_pte_vaddr(pud_t *pud, unsigned long vaddr, pte_t new_pte)
256 * It's enough to flush this one mapping. 256 * It's enough to flush this one mapping.
257 * (PGE mappings get flushed as well) 257 * (PGE mappings get flushed as well)
258 */ 258 */
259 __flush_tlb_one(vaddr); 259 __flush_tlb_one_kernel(vaddr);
260} 260}
261 261
262void set_pte_vaddr_p4d(p4d_t *p4d_page, unsigned long vaddr, pte_t new_pte) 262void set_pte_vaddr_p4d(p4d_t *p4d_page, unsigned long vaddr, pte_t new_pte)
@@ -800,17 +800,11 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
800 800
801#define PAGE_INUSE 0xFD 801#define PAGE_INUSE 0xFD
802 802
803static void __meminit free_pagetable(struct page *page, int order, 803static void __meminit free_pagetable(struct page *page, int order)
804 struct vmem_altmap *altmap)
805{ 804{
806 unsigned long magic; 805 unsigned long magic;
807 unsigned int nr_pages = 1 << order; 806 unsigned int nr_pages = 1 << order;
808 807
809 if (altmap) {
810 vmem_altmap_free(altmap, nr_pages);
811 return;
812 }
813
814 /* bootmem page has reserved flag */ 808 /* bootmem page has reserved flag */
815 if (PageReserved(page)) { 809 if (PageReserved(page)) {
816 __ClearPageReserved(page); 810 __ClearPageReserved(page);
@@ -826,9 +820,17 @@ static void __meminit free_pagetable(struct page *page, int order,
826 free_pages((unsigned long)page_address(page), order); 820 free_pages((unsigned long)page_address(page), order);
827} 821}
828 822
829static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd, 823static void __meminit free_hugepage_table(struct page *page,
830 struct vmem_altmap *altmap) 824 struct vmem_altmap *altmap)
831{ 825{
826 if (altmap)
827 vmem_altmap_free(altmap, PMD_SIZE / PAGE_SIZE);
828 else
829 free_pagetable(page, get_order(PMD_SIZE));
830}
831
832static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd)
833{
832 pte_t *pte; 834 pte_t *pte;
833 int i; 835 int i;
834 836
@@ -839,14 +841,13 @@ static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd,
839 } 841 }
840 842
841 /* free a pte talbe */ 843 /* free a pte talbe */
842 free_pagetable(pmd_page(*pmd), 0, altmap); 844 free_pagetable(pmd_page(*pmd), 0);
843 spin_lock(&init_mm.page_table_lock); 845 spin_lock(&init_mm.page_table_lock);
844 pmd_clear(pmd); 846 pmd_clear(pmd);
845 spin_unlock(&init_mm.page_table_lock); 847 spin_unlock(&init_mm.page_table_lock);
846} 848}
847 849
848static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud, 850static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud)
849 struct vmem_altmap *altmap)
850{ 851{
851 pmd_t *pmd; 852 pmd_t *pmd;
852 int i; 853 int i;
@@ -858,14 +859,13 @@ static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud,
858 } 859 }
859 860
860 /* free a pmd talbe */ 861 /* free a pmd talbe */
861 free_pagetable(pud_page(*pud), 0, altmap); 862 free_pagetable(pud_page(*pud), 0);
862 spin_lock(&init_mm.page_table_lock); 863 spin_lock(&init_mm.page_table_lock);
863 pud_clear(pud); 864 pud_clear(pud);
864 spin_unlock(&init_mm.page_table_lock); 865 spin_unlock(&init_mm.page_table_lock);
865} 866}
866 867
867static void __meminit free_pud_table(pud_t *pud_start, p4d_t *p4d, 868static void __meminit free_pud_table(pud_t *pud_start, p4d_t *p4d)
868 struct vmem_altmap *altmap)
869{ 869{
870 pud_t *pud; 870 pud_t *pud;
871 int i; 871 int i;
@@ -877,7 +877,7 @@ static void __meminit free_pud_table(pud_t *pud_start, p4d_t *p4d,
877 } 877 }
878 878
879 /* free a pud talbe */ 879 /* free a pud talbe */
880 free_pagetable(p4d_page(*p4d), 0, altmap); 880 free_pagetable(p4d_page(*p4d), 0);
881 spin_lock(&init_mm.page_table_lock); 881 spin_lock(&init_mm.page_table_lock);
882 p4d_clear(p4d); 882 p4d_clear(p4d);
883 spin_unlock(&init_mm.page_table_lock); 883 spin_unlock(&init_mm.page_table_lock);
@@ -885,7 +885,7 @@ static void __meminit free_pud_table(pud_t *pud_start, p4d_t *p4d,
885 885
886static void __meminit 886static void __meminit
887remove_pte_table(pte_t *pte_start, unsigned long addr, unsigned long end, 887remove_pte_table(pte_t *pte_start, unsigned long addr, unsigned long end,
888 struct vmem_altmap *altmap, bool direct) 888 bool direct)
889{ 889{
890 unsigned long next, pages = 0; 890 unsigned long next, pages = 0;
891 pte_t *pte; 891 pte_t *pte;
@@ -916,7 +916,7 @@ remove_pte_table(pte_t *pte_start, unsigned long addr, unsigned long end,
916 * freed when offlining, or simplely not in use. 916 * freed when offlining, or simplely not in use.
917 */ 917 */
918 if (!direct) 918 if (!direct)
919 free_pagetable(pte_page(*pte), 0, altmap); 919 free_pagetable(pte_page(*pte), 0);
920 920
921 spin_lock(&init_mm.page_table_lock); 921 spin_lock(&init_mm.page_table_lock);
922 pte_clear(&init_mm, addr, pte); 922 pte_clear(&init_mm, addr, pte);
@@ -939,7 +939,7 @@ remove_pte_table(pte_t *pte_start, unsigned long addr, unsigned long end,
939 939
940 page_addr = page_address(pte_page(*pte)); 940 page_addr = page_address(pte_page(*pte));
941 if (!memchr_inv(page_addr, PAGE_INUSE, PAGE_SIZE)) { 941 if (!memchr_inv(page_addr, PAGE_INUSE, PAGE_SIZE)) {
942 free_pagetable(pte_page(*pte), 0, altmap); 942 free_pagetable(pte_page(*pte), 0);
943 943
944 spin_lock(&init_mm.page_table_lock); 944 spin_lock(&init_mm.page_table_lock);
945 pte_clear(&init_mm, addr, pte); 945 pte_clear(&init_mm, addr, pte);
@@ -974,9 +974,8 @@ remove_pmd_table(pmd_t *pmd_start, unsigned long addr, unsigned long end,
974 if (IS_ALIGNED(addr, PMD_SIZE) && 974 if (IS_ALIGNED(addr, PMD_SIZE) &&
975 IS_ALIGNED(next, PMD_SIZE)) { 975 IS_ALIGNED(next, PMD_SIZE)) {
976 if (!direct) 976 if (!direct)
977 free_pagetable(pmd_page(*pmd), 977 free_hugepage_table(pmd_page(*pmd),
978 get_order(PMD_SIZE), 978 altmap);
979 altmap);
980 979
981 spin_lock(&init_mm.page_table_lock); 980 spin_lock(&init_mm.page_table_lock);
982 pmd_clear(pmd); 981 pmd_clear(pmd);
@@ -989,9 +988,8 @@ remove_pmd_table(pmd_t *pmd_start, unsigned long addr, unsigned long end,
989 page_addr = page_address(pmd_page(*pmd)); 988 page_addr = page_address(pmd_page(*pmd));
990 if (!memchr_inv(page_addr, PAGE_INUSE, 989 if (!memchr_inv(page_addr, PAGE_INUSE,
991 PMD_SIZE)) { 990 PMD_SIZE)) {
992 free_pagetable(pmd_page(*pmd), 991 free_hugepage_table(pmd_page(*pmd),
993 get_order(PMD_SIZE), 992 altmap);
994 altmap);
995 993
996 spin_lock(&init_mm.page_table_lock); 994 spin_lock(&init_mm.page_table_lock);
997 pmd_clear(pmd); 995 pmd_clear(pmd);
@@ -1003,8 +1001,8 @@ remove_pmd_table(pmd_t *pmd_start, unsigned long addr, unsigned long end,
1003 } 1001 }
1004 1002
1005 pte_base = (pte_t *)pmd_page_vaddr(*pmd); 1003 pte_base = (pte_t *)pmd_page_vaddr(*pmd);
1006 remove_pte_table(pte_base, addr, next, altmap, direct); 1004 remove_pte_table(pte_base, addr, next, direct);
1007 free_pte_table(pte_base, pmd, altmap); 1005 free_pte_table(pte_base, pmd);
1008 } 1006 }
1009 1007
1010 /* Call free_pmd_table() in remove_pud_table(). */ 1008 /* Call free_pmd_table() in remove_pud_table(). */
@@ -1033,8 +1031,7 @@ remove_pud_table(pud_t *pud_start, unsigned long addr, unsigned long end,
1033 IS_ALIGNED(next, PUD_SIZE)) { 1031 IS_ALIGNED(next, PUD_SIZE)) {
1034 if (!direct) 1032 if (!direct)
1035 free_pagetable(pud_page(*pud), 1033 free_pagetable(pud_page(*pud),
1036 get_order(PUD_SIZE), 1034 get_order(PUD_SIZE));
1037 altmap);
1038 1035
1039 spin_lock(&init_mm.page_table_lock); 1036 spin_lock(&init_mm.page_table_lock);
1040 pud_clear(pud); 1037 pud_clear(pud);
@@ -1048,8 +1045,7 @@ remove_pud_table(pud_t *pud_start, unsigned long addr, unsigned long end,
1048 if (!memchr_inv(page_addr, PAGE_INUSE, 1045 if (!memchr_inv(page_addr, PAGE_INUSE,
1049 PUD_SIZE)) { 1046 PUD_SIZE)) {
1050 free_pagetable(pud_page(*pud), 1047 free_pagetable(pud_page(*pud),
1051 get_order(PUD_SIZE), 1048 get_order(PUD_SIZE));
1052 altmap);
1053 1049
1054 spin_lock(&init_mm.page_table_lock); 1050 spin_lock(&init_mm.page_table_lock);
1055 pud_clear(pud); 1051 pud_clear(pud);
@@ -1062,7 +1058,7 @@ remove_pud_table(pud_t *pud_start, unsigned long addr, unsigned long end,
1062 1058
1063 pmd_base = pmd_offset(pud, 0); 1059 pmd_base = pmd_offset(pud, 0);
1064 remove_pmd_table(pmd_base, addr, next, direct, altmap); 1060 remove_pmd_table(pmd_base, addr, next, direct, altmap);
1065 free_pmd_table(pmd_base, pud, altmap); 1061 free_pmd_table(pmd_base, pud);
1066 } 1062 }
1067 1063
1068 if (direct) 1064 if (direct)
@@ -1094,7 +1090,7 @@ remove_p4d_table(p4d_t *p4d_start, unsigned long addr, unsigned long end,
1094 * to adapt for boot-time switching between 4 and 5 level page tables. 1090 * to adapt for boot-time switching between 4 and 5 level page tables.
1095 */ 1091 */
1096 if (CONFIG_PGTABLE_LEVELS == 5) 1092 if (CONFIG_PGTABLE_LEVELS == 5)
1097 free_pud_table(pud_base, p4d, altmap); 1093 free_pud_table(pud_base, p4d);
1098 } 1094 }
1099 1095
1100 if (direct) 1096 if (direct)
@@ -1193,8 +1189,8 @@ void __init mem_init(void)
1193 register_page_bootmem_info(); 1189 register_page_bootmem_info();
1194 1190
1195 /* Register memory areas for /proc/kcore */ 1191 /* Register memory areas for /proc/kcore */
1196 kclist_add(&kcore_vsyscall, (void *)VSYSCALL_ADDR, 1192 if (get_gate_vma(&init_mm))
1197 PAGE_SIZE, KCORE_OTHER); 1193 kclist_add(&kcore_vsyscall, (void *)VSYSCALL_ADDR, PAGE_SIZE, KCORE_USER);
1198 1194
1199 mem_init_print_info(NULL); 1195 mem_init_print_info(NULL);
1200} 1196}
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index c45b6ec5357b..e2db83bebc3b 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -820,5 +820,5 @@ void __init __early_set_fixmap(enum fixed_addresses idx,
820 set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags)); 820 set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
821 else 821 else
822 pte_clear(&init_mm, addr, pte); 822 pte_clear(&init_mm, addr, pte);
823 __flush_tlb_one(addr); 823 __flush_tlb_one_kernel(addr);
824} 824}
diff --git a/arch/x86/mm/kmmio.c b/arch/x86/mm/kmmio.c
index 58477ec3d66d..7c8686709636 100644
--- a/arch/x86/mm/kmmio.c
+++ b/arch/x86/mm/kmmio.c
@@ -168,7 +168,7 @@ static int clear_page_presence(struct kmmio_fault_page *f, bool clear)
168 return -1; 168 return -1;
169 } 169 }
170 170
171 __flush_tlb_one(f->addr); 171 __flush_tlb_one_kernel(f->addr);
172 return 0; 172 return 0;
173} 173}
174 174
diff --git a/arch/x86/mm/mem_encrypt_boot.S b/arch/x86/mm/mem_encrypt_boot.S
index 01f682cf77a8..40a6085063d6 100644
--- a/arch/x86/mm/mem_encrypt_boot.S
+++ b/arch/x86/mm/mem_encrypt_boot.S
@@ -15,6 +15,7 @@
15#include <asm/page.h> 15#include <asm/page.h>
16#include <asm/processor-flags.h> 16#include <asm/processor-flags.h>
17#include <asm/msr-index.h> 17#include <asm/msr-index.h>
18#include <asm/nospec-branch.h>
18 19
19 .text 20 .text
20 .code64 21 .code64
@@ -59,6 +60,7 @@ ENTRY(sme_encrypt_execute)
59 movq %rax, %r8 /* Workarea encryption routine */ 60 movq %rax, %r8 /* Workarea encryption routine */
60 addq $PAGE_SIZE, %r8 /* Workarea intermediate copy buffer */ 61 addq $PAGE_SIZE, %r8 /* Workarea intermediate copy buffer */
61 62
63 ANNOTATE_RETPOLINE_SAFE
62 call *%rax /* Call the encryption routine */ 64 call *%rax /* Call the encryption routine */
63 65
64 pop %r12 66 pop %r12
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 004abf9ebf12..34cda7e0551b 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -702,4 +702,52 @@ int pmd_clear_huge(pmd_t *pmd)
702 702
703 return 0; 703 return 0;
704} 704}
705
706/**
707 * pud_free_pmd_page - Clear pud entry and free pmd page.
708 * @pud: Pointer to a PUD.
709 *
710 * Context: The pud range has been unmaped and TLB purged.
711 * Return: 1 if clearing the entry succeeded. 0 otherwise.
712 */
713int pud_free_pmd_page(pud_t *pud)
714{
715 pmd_t *pmd;
716 int i;
717
718 if (pud_none(*pud))
719 return 1;
720
721 pmd = (pmd_t *)pud_page_vaddr(*pud);
722
723 for (i = 0; i < PTRS_PER_PMD; i++)
724 if (!pmd_free_pte_page(&pmd[i]))
725 return 0;
726
727 pud_clear(pud);
728 free_page((unsigned long)pmd);
729
730 return 1;
731}
732
733/**
734 * pmd_free_pte_page - Clear pmd entry and free pte page.
735 * @pmd: Pointer to a PMD.
736 *
737 * Context: The pmd range has been unmaped and TLB purged.
738 * Return: 1 if clearing the entry succeeded. 0 otherwise.
739 */
740int pmd_free_pte_page(pmd_t *pmd)
741{
742 pte_t *pte;
743
744 if (pmd_none(*pmd))
745 return 1;
746
747 pte = (pte_t *)pmd_page_vaddr(*pmd);
748 pmd_clear(pmd);
749 free_page((unsigned long)pte);
750
751 return 1;
752}
705#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ 753#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
index c3c5274410a9..9bb7f0ab9fe6 100644
--- a/arch/x86/mm/pgtable_32.c
+++ b/arch/x86/mm/pgtable_32.c
@@ -63,7 +63,7 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
63 * It's enough to flush this one mapping. 63 * It's enough to flush this one mapping.
64 * (PGE mappings get flushed as well) 64 * (PGE mappings get flushed as well)
65 */ 65 */
66 __flush_tlb_one(vaddr); 66 __flush_tlb_one_kernel(vaddr);
67} 67}
68 68
69unsigned long __FIXADDR_TOP = 0xfffff000; 69unsigned long __FIXADDR_TOP = 0xfffff000;
diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index ce38f165489b..631507f0c198 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -332,7 +332,7 @@ static void __init pti_clone_user_shared(void)
332} 332}
333 333
334/* 334/*
335 * Clone the ESPFIX P4D into the user space visinble page table 335 * Clone the ESPFIX P4D into the user space visible page table
336 */ 336 */
337static void __init pti_setup_espfix64(void) 337static void __init pti_setup_espfix64(void)
338{ 338{
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index 8dcc0607f805..7f1a51399674 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -498,7 +498,7 @@ static void flush_tlb_func_common(const struct flush_tlb_info *f,
498 * flush that changes context.tlb_gen from 2 to 3. If they get 498 * flush that changes context.tlb_gen from 2 to 3. If they get
499 * processed on this CPU in reverse order, we'll see 499 * processed on this CPU in reverse order, we'll see
500 * local_tlb_gen == 1, mm_tlb_gen == 3, and end != TLB_FLUSH_ALL. 500 * local_tlb_gen == 1, mm_tlb_gen == 3, and end != TLB_FLUSH_ALL.
501 * If we were to use __flush_tlb_single() and set local_tlb_gen to 501 * If we were to use __flush_tlb_one_user() and set local_tlb_gen to
502 * 3, we'd be break the invariant: we'd update local_tlb_gen above 502 * 3, we'd be break the invariant: we'd update local_tlb_gen above
503 * 1 without the full flush that's needed for tlb_gen 2. 503 * 1 without the full flush that's needed for tlb_gen 2.
504 * 504 *
@@ -519,7 +519,7 @@ static void flush_tlb_func_common(const struct flush_tlb_info *f,
519 519
520 addr = f->start; 520 addr = f->start;
521 while (addr < f->end) { 521 while (addr < f->end) {
522 __flush_tlb_single(addr); 522 __flush_tlb_one_user(addr);
523 addr += PAGE_SIZE; 523 addr += PAGE_SIZE;
524 } 524 }
525 if (local) 525 if (local)
@@ -666,7 +666,7 @@ static void do_kernel_range_flush(void *info)
666 666
667 /* flush range by one by one 'invlpg' */ 667 /* flush range by one by one 'invlpg' */
668 for (addr = f->start; addr < f->end; addr += PAGE_SIZE) 668 for (addr = f->start; addr < f->end; addr += PAGE_SIZE)
669 __flush_tlb_one(addr); 669 __flush_tlb_one_kernel(addr);
670} 670}
671 671
672void flush_tlb_kernel_range(unsigned long start, unsigned long end) 672void flush_tlb_kernel_range(unsigned long start, unsigned long end)
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 4923d92f918d..ce5b2ebd5701 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -13,6 +13,7 @@
13#include <linux/if_vlan.h> 13#include <linux/if_vlan.h>
14#include <asm/cacheflush.h> 14#include <asm/cacheflush.h>
15#include <asm/set_memory.h> 15#include <asm/set_memory.h>
16#include <asm/nospec-branch.h>
16#include <linux/bpf.h> 17#include <linux/bpf.h>
17 18
18/* 19/*
@@ -290,7 +291,7 @@ static void emit_bpf_tail_call(u8 **pprog)
290 EMIT2(0x89, 0xD2); /* mov edx, edx */ 291 EMIT2(0x89, 0xD2); /* mov edx, edx */
291 EMIT3(0x39, 0x56, /* cmp dword ptr [rsi + 16], edx */ 292 EMIT3(0x39, 0x56, /* cmp dword ptr [rsi + 16], edx */
292 offsetof(struct bpf_array, map.max_entries)); 293 offsetof(struct bpf_array, map.max_entries));
293#define OFFSET1 43 /* number of bytes to jump */ 294#define OFFSET1 (41 + RETPOLINE_RAX_BPF_JIT_SIZE) /* number of bytes to jump */
294 EMIT2(X86_JBE, OFFSET1); /* jbe out */ 295 EMIT2(X86_JBE, OFFSET1); /* jbe out */
295 label1 = cnt; 296 label1 = cnt;
296 297
@@ -299,7 +300,7 @@ static void emit_bpf_tail_call(u8 **pprog)
299 */ 300 */
300 EMIT2_off32(0x8B, 0x85, 36); /* mov eax, dword ptr [rbp + 36] */ 301 EMIT2_off32(0x8B, 0x85, 36); /* mov eax, dword ptr [rbp + 36] */
301 EMIT3(0x83, 0xF8, MAX_TAIL_CALL_CNT); /* cmp eax, MAX_TAIL_CALL_CNT */ 302 EMIT3(0x83, 0xF8, MAX_TAIL_CALL_CNT); /* cmp eax, MAX_TAIL_CALL_CNT */
302#define OFFSET2 32 303#define OFFSET2 (30 + RETPOLINE_RAX_BPF_JIT_SIZE)
303 EMIT2(X86_JA, OFFSET2); /* ja out */ 304 EMIT2(X86_JA, OFFSET2); /* ja out */
304 label2 = cnt; 305 label2 = cnt;
305 EMIT3(0x83, 0xC0, 0x01); /* add eax, 1 */ 306 EMIT3(0x83, 0xC0, 0x01); /* add eax, 1 */
@@ -313,7 +314,7 @@ static void emit_bpf_tail_call(u8 **pprog)
313 * goto out; 314 * goto out;
314 */ 315 */
315 EMIT3(0x48, 0x85, 0xC0); /* test rax,rax */ 316 EMIT3(0x48, 0x85, 0xC0); /* test rax,rax */
316#define OFFSET3 10 317#define OFFSET3 (8 + RETPOLINE_RAX_BPF_JIT_SIZE)
317 EMIT2(X86_JE, OFFSET3); /* je out */ 318 EMIT2(X86_JE, OFFSET3); /* je out */
318 label3 = cnt; 319 label3 = cnt;
319 320
@@ -326,7 +327,7 @@ static void emit_bpf_tail_call(u8 **pprog)
326 * rdi == ctx (1st arg) 327 * rdi == ctx (1st arg)
327 * rax == prog->bpf_func + prologue_size 328 * rax == prog->bpf_func + prologue_size
328 */ 329 */
329 EMIT2(0xFF, 0xE0); /* jmp rax */ 330 RETPOLINE_RAX_BPF_JIT();
330 331
331 /* out: */ 332 /* out: */
332 BUILD_BUG_ON(cnt - label1 != OFFSET1); 333 BUILD_BUG_ON(cnt - label1 != OFFSET1);
@@ -1187,7 +1188,7 @@ skip_init_addrs:
1187 * may converge on the last pass. In such case do one more 1188 * may converge on the last pass. In such case do one more
1188 * pass to emit the final image 1189 * pass to emit the final image
1189 */ 1190 */
1190 for (pass = 0; pass < 10 || image; pass++) { 1191 for (pass = 0; pass < 20 || image; pass++) {
1191 proglen = do_jit(prog, addrs, image, oldproglen, &ctx); 1192 proglen = do_jit(prog, addrs, image, oldproglen, &ctx);
1192 if (proglen <= 0) { 1193 if (proglen <= 0) {
1193 image = NULL; 1194 image = NULL;
@@ -1214,6 +1215,7 @@ skip_init_addrs:
1214 } 1215 }
1215 } 1216 }
1216 oldproglen = proglen; 1217 oldproglen = proglen;
1218 cond_resched();
1217 } 1219 }
1218 1220
1219 if (bpf_jit_enable > 1) 1221 if (bpf_jit_enable > 1)
diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index 174c59774cc9..a7a7677265b6 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -460,7 +460,7 @@ static int nmi_setup(void)
460 goto fail; 460 goto fail;
461 461
462 for_each_possible_cpu(cpu) { 462 for_each_possible_cpu(cpu) {
463 if (!cpu) 463 if (!IS_ENABLED(CONFIG_SMP) || !cpu)
464 continue; 464 continue;
465 465
466 memcpy(per_cpu(cpu_msrs, cpu).counters, 466 memcpy(per_cpu(cpu_msrs, cpu).counters,
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index c310a8284358..f9cfbc0d1f33 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -227,7 +227,7 @@ int __init efi_alloc_page_tables(void)
227 if (!pud) { 227 if (!pud) {
228 if (CONFIG_PGTABLE_LEVELS > 4) 228 if (CONFIG_PGTABLE_LEVELS > 4)
229 free_page((unsigned long) pgd_page_vaddr(*pgd)); 229 free_page((unsigned long) pgd_page_vaddr(*pgd));
230 free_page((unsigned long)efi_pgd); 230 free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
231 return -ENOMEM; 231 return -ENOMEM;
232 } 232 }
233 233
diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
index 2c67bae6bb53..fb1df9488e98 100644
--- a/arch/x86/platform/intel-mid/intel-mid.c
+++ b/arch/x86/platform/intel-mid/intel-mid.c
@@ -79,7 +79,7 @@ static void intel_mid_power_off(void)
79 79
80static void intel_mid_reboot(void) 80static void intel_mid_reboot(void)
81{ 81{
82 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0); 82 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
83} 83}
84 84
85static unsigned long __init intel_mid_calibrate_tsc(void) 85static unsigned long __init intel_mid_calibrate_tsc(void)
diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
index c2e9285d1bf1..db77e087adaf 100644
--- a/arch/x86/platform/uv/tlb_uv.c
+++ b/arch/x86/platform/uv/tlb_uv.c
@@ -299,7 +299,7 @@ static void bau_process_message(struct msg_desc *mdp, struct bau_control *bcp,
299 local_flush_tlb(); 299 local_flush_tlb();
300 stat->d_alltlb++; 300 stat->d_alltlb++;
301 } else { 301 } else {
302 __flush_tlb_single(msg->address); 302 __flush_tlb_one_user(msg->address);
303 stat->d_onetlb++; 303 stat->d_onetlb++;
304 } 304 }
305 stat->d_requestee++; 305 stat->d_requestee++;
diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
index de53bd15df5a..24bb7598774e 100644
--- a/arch/x86/realmode/rm/trampoline_64.S
+++ b/arch/x86/realmode/rm/trampoline_64.S
@@ -102,7 +102,7 @@ ENTRY(startup_32)
102 * don't we'll eventually crash trying to execute encrypted 102 * don't we'll eventually crash trying to execute encrypted
103 * instructions. 103 * instructions.
104 */ 104 */
105 bt $TH_FLAGS_SME_ACTIVE_BIT, pa_tr_flags 105 btl $TH_FLAGS_SME_ACTIVE_BIT, pa_tr_flags
106 jnc .Ldone 106 jnc .Ldone
107 movl $MSR_K8_SYSCFG, %ecx 107 movl $MSR_K8_SYSCFG, %ecx
108 rdmsr 108 rdmsr
diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
index 5d73c443e778..220e97841e49 100644
--- a/arch/x86/tools/relocs.c
+++ b/arch/x86/tools/relocs.c
@@ -770,9 +770,12 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym,
770 break; 770 break;
771 771
772 case R_X86_64_PC32: 772 case R_X86_64_PC32:
773 case R_X86_64_PLT32:
773 /* 774 /*
774 * PC relative relocations don't need to be adjusted unless 775 * PC relative relocations don't need to be adjusted unless
775 * referencing a percpu symbol. 776 * referencing a percpu symbol.
777 *
778 * NB: R_X86_64_PLT32 can be treated as R_X86_64_PC32.
776 */ 779 */
777 if (is_percpu_sym(sym, symname)) 780 if (is_percpu_sym(sym, symname))
778 add_reloc(&relocs32neg, offset); 781 add_reloc(&relocs32neg, offset);
diff --git a/arch/x86/um/asm/barrier.h b/arch/x86/um/asm/barrier.h
index b7d73400ea29..f31e5d903161 100644
--- a/arch/x86/um/asm/barrier.h
+++ b/arch/x86/um/asm/barrier.h
@@ -30,11 +30,7 @@
30 30
31#endif /* CONFIG_X86_32 */ 31#endif /* CONFIG_X86_32 */
32 32
33#ifdef CONFIG_X86_PPRO_FENCE
34#define dma_rmb() rmb()
35#else /* CONFIG_X86_PPRO_FENCE */
36#define dma_rmb() barrier() 33#define dma_rmb() barrier()
37#endif /* CONFIG_X86_PPRO_FENCE */
38#define dma_wmb() barrier() 34#define dma_wmb() barrier()
39 35
40#include <asm-generic/barrier.h> 36#include <asm-generic/barrier.h>
diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
index c047f42552e1..3c2c2530737e 100644
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -1376,8 +1376,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
1376 1376
1377 if (!xen_initial_domain()) { 1377 if (!xen_initial_domain()) {
1378 add_preferred_console("xenboot", 0, NULL); 1378 add_preferred_console("xenboot", 0, NULL);
1379 add_preferred_console("tty", 0, NULL);
1380 add_preferred_console("hvc", 0, NULL);
1381 if (pci_xen) 1379 if (pci_xen)
1382 x86_init.pci.arch_init = pci_xen_init; 1380 x86_init.pci.arch_init = pci_xen_init;
1383 } else { 1381 } else {
@@ -1410,6 +1408,10 @@ asmlinkage __visible void __init xen_start_kernel(void)
1410 1408
1411 xen_boot_params_init_edd(); 1409 xen_boot_params_init_edd();
1412 } 1410 }
1411
1412 add_preferred_console("tty", 0, NULL);
1413 add_preferred_console("hvc", 0, NULL);
1414
1413#ifdef CONFIG_PCI 1415#ifdef CONFIG_PCI
1414 /* PCI BIOS service won't work from a PV guest. */ 1416 /* PCI BIOS service won't work from a PV guest. */
1415 pci_probe &= ~PCI_PROBE_BIOS; 1417 pci_probe &= ~PCI_PROBE_BIOS;
diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index d85076223a69..aae88fec9941 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -1300,12 +1300,12 @@ static void xen_flush_tlb(void)
1300 preempt_enable(); 1300 preempt_enable();
1301} 1301}
1302 1302
1303static void xen_flush_tlb_single(unsigned long addr) 1303static void xen_flush_tlb_one_user(unsigned long addr)
1304{ 1304{
1305 struct mmuext_op *op; 1305 struct mmuext_op *op;
1306 struct multicall_space mcs; 1306 struct multicall_space mcs;
1307 1307
1308 trace_xen_mmu_flush_tlb_single(addr); 1308 trace_xen_mmu_flush_tlb_one_user(addr);
1309 1309
1310 preempt_disable(); 1310 preempt_disable();
1311 1311
@@ -2370,7 +2370,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
2370 2370
2371 .flush_tlb_user = xen_flush_tlb, 2371 .flush_tlb_user = xen_flush_tlb,
2372 .flush_tlb_kernel = xen_flush_tlb, 2372 .flush_tlb_kernel = xen_flush_tlb,
2373 .flush_tlb_single = xen_flush_tlb_single, 2373 .flush_tlb_one_user = xen_flush_tlb_one_user,
2374 .flush_tlb_others = xen_flush_tlb_others, 2374 .flush_tlb_others = xen_flush_tlb_others,
2375 2375
2376 .pgd_alloc = xen_pgd_alloc, 2376 .pgd_alloc = xen_pgd_alloc,
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 77c959cf81e7..7a43b2ae19f1 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -122,6 +122,8 @@ void __init xen_smp_cpus_done(unsigned int max_cpus)
122 122
123 if (xen_hvm_domain()) 123 if (xen_hvm_domain())
124 native_smp_cpus_done(max_cpus); 124 native_smp_cpus_done(max_cpus);
125 else
126 calculate_max_logical_packages();
125 127
126 if (xen_have_vcpu_info_placement) 128 if (xen_have_vcpu_info_placement)
127 return; 129 return;
diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c
index d9f96cc5d743..1d83152c761b 100644
--- a/arch/x86/xen/suspend.c
+++ b/arch/x86/xen/suspend.c
@@ -1,12 +1,15 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2#include <linux/types.h> 2#include <linux/types.h>
3#include <linux/tick.h> 3#include <linux/tick.h>
4#include <linux/percpu-defs.h>
4 5
5#include <xen/xen.h> 6#include <xen/xen.h>
6#include <xen/interface/xen.h> 7#include <xen/interface/xen.h>
7#include <xen/grant_table.h> 8#include <xen/grant_table.h>
8#include <xen/events.h> 9#include <xen/events.h>
9 10
11#include <asm/cpufeatures.h>
12#include <asm/msr-index.h>
10#include <asm/xen/hypercall.h> 13#include <asm/xen/hypercall.h>
11#include <asm/xen/page.h> 14#include <asm/xen/page.h>
12#include <asm/fixmap.h> 15#include <asm/fixmap.h>
@@ -15,6 +18,8 @@
15#include "mmu.h" 18#include "mmu.h"
16#include "pmu.h" 19#include "pmu.h"
17 20
21static DEFINE_PER_CPU(u64, spec_ctrl);
22
18void xen_arch_pre_suspend(void) 23void xen_arch_pre_suspend(void)
19{ 24{
20 xen_save_time_memory_area(); 25 xen_save_time_memory_area();
@@ -35,6 +40,9 @@ void xen_arch_post_suspend(int cancelled)
35 40
36static void xen_vcpu_notify_restore(void *data) 41static void xen_vcpu_notify_restore(void *data)
37{ 42{
43 if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL))
44 wrmsrl(MSR_IA32_SPEC_CTRL, this_cpu_read(spec_ctrl));
45
38 /* Boot processor notified via generic timekeeping_resume() */ 46 /* Boot processor notified via generic timekeeping_resume() */
39 if (smp_processor_id() == 0) 47 if (smp_processor_id() == 0)
40 return; 48 return;
@@ -44,7 +52,15 @@ static void xen_vcpu_notify_restore(void *data)
44 52
45static void xen_vcpu_notify_suspend(void *data) 53static void xen_vcpu_notify_suspend(void *data)
46{ 54{
55 u64 tmp;
56
47 tick_suspend_local(); 57 tick_suspend_local();
58
59 if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
60 rdmsrl(MSR_IA32_SPEC_CTRL, tmp);
61 this_cpu_write(spec_ctrl, tmp);
62 wrmsrl(MSR_IA32_SPEC_CTRL, 0);
63 }
48} 64}
49 65
50void xen_arch_resume(void) 66void xen_arch_resume(void)
diff --git a/arch/xtensa/kernel/pci-dma.c b/arch/xtensa/kernel/pci-dma.c
index 623720a11143..732631ce250f 100644
--- a/arch/xtensa/kernel/pci-dma.c
+++ b/arch/xtensa/kernel/pci-dma.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/dma-contiguous.h> 18#include <linux/dma-contiguous.h>
19#include <linux/dma-direct.h>
19#include <linux/gfp.h> 20#include <linux/gfp.h>
20#include <linux/highmem.h> 21#include <linux/highmem.h>
21#include <linux/mm.h> 22#include <linux/mm.h>
@@ -123,7 +124,7 @@ static void *xtensa_dma_alloc(struct device *dev, size_t size,
123 unsigned long attrs) 124 unsigned long attrs)
124{ 125{
125 unsigned long ret; 126 unsigned long ret;
126 unsigned long uncached = 0; 127 unsigned long uncached;
127 unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; 128 unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
128 struct page *page = NULL; 129 struct page *page = NULL;
129 130
@@ -144,15 +145,27 @@ static void *xtensa_dma_alloc(struct device *dev, size_t size,
144 if (!page) 145 if (!page)
145 return NULL; 146 return NULL;
146 147
147 ret = (unsigned long)page_address(page); 148 *handle = phys_to_dma(dev, page_to_phys(page));
148 149
149 /* We currently don't support coherent memory outside KSEG */ 150#ifdef CONFIG_MMU
151 if (PageHighMem(page)) {
152 void *p;
150 153
154 p = dma_common_contiguous_remap(page, size, VM_MAP,
155 pgprot_noncached(PAGE_KERNEL),
156 __builtin_return_address(0));
157 if (!p) {
158 if (!dma_release_from_contiguous(dev, page, count))
159 __free_pages(page, get_order(size));
160 }
161 return p;
162 }
163#endif
164 ret = (unsigned long)page_address(page);
151 BUG_ON(ret < XCHAL_KSEG_CACHED_VADDR || 165 BUG_ON(ret < XCHAL_KSEG_CACHED_VADDR ||
152 ret > XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_SIZE - 1); 166 ret > XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_SIZE - 1);
153 167
154 uncached = ret + XCHAL_KSEG_BYPASS_VADDR - XCHAL_KSEG_CACHED_VADDR; 168 uncached = ret + XCHAL_KSEG_BYPASS_VADDR - XCHAL_KSEG_CACHED_VADDR;
155 *handle = virt_to_bus((void *)ret);
156 __invalidate_dcache_range(ret, size); 169 __invalidate_dcache_range(ret, size);
157 170
158 return (void *)uncached; 171 return (void *)uncached;
@@ -161,13 +174,20 @@ static void *xtensa_dma_alloc(struct device *dev, size_t size,
161static void xtensa_dma_free(struct device *dev, size_t size, void *vaddr, 174static void xtensa_dma_free(struct device *dev, size_t size, void *vaddr,
162 dma_addr_t dma_handle, unsigned long attrs) 175 dma_addr_t dma_handle, unsigned long attrs)
163{ 176{
164 unsigned long addr = (unsigned long)vaddr +
165 XCHAL_KSEG_CACHED_VADDR - XCHAL_KSEG_BYPASS_VADDR;
166 struct page *page = virt_to_page(addr);
167 unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; 177 unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
168 178 unsigned long addr = (unsigned long)vaddr;
169 BUG_ON(addr < XCHAL_KSEG_CACHED_VADDR || 179 struct page *page;
170 addr > XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_SIZE - 1); 180
181 if (addr >= XCHAL_KSEG_BYPASS_VADDR &&
182 addr - XCHAL_KSEG_BYPASS_VADDR < XCHAL_KSEG_SIZE) {
183 addr += XCHAL_KSEG_CACHED_VADDR - XCHAL_KSEG_BYPASS_VADDR;
184 page = virt_to_page(addr);
185 } else {
186#ifdef CONFIG_MMU
187 dma_common_free_remap(vaddr, size, VM_MAP);
188#endif
189 page = pfn_to_page(PHYS_PFN(dma_to_phys(dev, dma_handle)));
190 }
171 191
172 if (!dma_release_from_contiguous(dev, page, count)) 192 if (!dma_release_from_contiguous(dev, page, count))
173 __free_pages(page, get_order(size)); 193 __free_pages(page, get_order(size));
diff --git a/arch/xtensa/mm/init.c b/arch/xtensa/mm/init.c
index d776ec0d7b22..34aead7dcb48 100644
--- a/arch/xtensa/mm/init.c
+++ b/arch/xtensa/mm/init.c
@@ -79,19 +79,75 @@ void __init zones_init(void)
79 free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL); 79 free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL);
80} 80}
81 81
82#ifdef CONFIG_HIGHMEM
83static void __init free_area_high(unsigned long pfn, unsigned long end)
84{
85 for (; pfn < end; pfn++)
86 free_highmem_page(pfn_to_page(pfn));
87}
88
89static void __init free_highpages(void)
90{
91 unsigned long max_low = max_low_pfn;
92 struct memblock_region *mem, *res;
93
94 reset_all_zones_managed_pages();
95 /* set highmem page free */
96 for_each_memblock(memory, mem) {
97 unsigned long start = memblock_region_memory_base_pfn(mem);
98 unsigned long end = memblock_region_memory_end_pfn(mem);
99
100 /* Ignore complete lowmem entries */
101 if (end <= max_low)
102 continue;
103
104 if (memblock_is_nomap(mem))
105 continue;
106
107 /* Truncate partial highmem entries */
108 if (start < max_low)
109 start = max_low;
110
111 /* Find and exclude any reserved regions */
112 for_each_memblock(reserved, res) {
113 unsigned long res_start, res_end;
114
115 res_start = memblock_region_reserved_base_pfn(res);
116 res_end = memblock_region_reserved_end_pfn(res);
117
118 if (res_end < start)
119 continue;
120 if (res_start < start)
121 res_start = start;
122 if (res_start > end)
123 res_start = end;
124 if (res_end > end)
125 res_end = end;
126 if (res_start != start)
127 free_area_high(start, res_start);
128 start = res_end;
129 if (start == end)
130 break;
131 }
132
133 /* And now free anything which remains */
134 if (start < end)
135 free_area_high(start, end);
136 }
137}
138#else
139static void __init free_highpages(void)
140{
141}
142#endif
143
82/* 144/*
83 * Initialize memory pages. 145 * Initialize memory pages.
84 */ 146 */
85 147
86void __init mem_init(void) 148void __init mem_init(void)
87{ 149{
88#ifdef CONFIG_HIGHMEM 150 free_highpages();
89 unsigned long tmp;
90
91 reset_all_zones_managed_pages();
92 for (tmp = max_low_pfn; tmp < max_pfn; tmp++)
93 free_highmem_page(pfn_to_page(tmp));
94#endif
95 151
96 max_mapnr = max_pfn - ARCH_PFN_OFFSET; 152 max_mapnr = max_pfn - ARCH_PFN_OFFSET;
97 high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT); 153 high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT);
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 4117524ca45b..c2033a232a44 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -812,7 +812,6 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
812 struct gendisk *disk; 812 struct gendisk *disk;
813 struct request_queue *q; 813 struct request_queue *q;
814 struct blkcg_gq *blkg; 814 struct blkcg_gq *blkg;
815 struct module *owner;
816 unsigned int major, minor; 815 unsigned int major, minor;
817 int key_len, part, ret; 816 int key_len, part, ret;
818 char *body; 817 char *body;
@@ -904,9 +903,7 @@ fail_unlock:
904 spin_unlock_irq(q->queue_lock); 903 spin_unlock_irq(q->queue_lock);
905 rcu_read_unlock(); 904 rcu_read_unlock();
906fail: 905fail:
907 owner = disk->fops->owner; 906 put_disk_and_module(disk);
908 put_disk(disk);
909 module_put(owner);
910 /* 907 /*
911 * If queue was bypassing, we should retry. Do so after a 908 * If queue was bypassing, we should retry. Do so after a
912 * short msleep(). It isn't strictly necessary but queue 909 * short msleep(). It isn't strictly necessary but queue
@@ -931,13 +928,9 @@ EXPORT_SYMBOL_GPL(blkg_conf_prep);
931void blkg_conf_finish(struct blkg_conf_ctx *ctx) 928void blkg_conf_finish(struct blkg_conf_ctx *ctx)
932 __releases(ctx->disk->queue->queue_lock) __releases(rcu) 929 __releases(ctx->disk->queue->queue_lock) __releases(rcu)
933{ 930{
934 struct module *owner;
935
936 spin_unlock_irq(ctx->disk->queue->queue_lock); 931 spin_unlock_irq(ctx->disk->queue->queue_lock);
937 rcu_read_unlock(); 932 rcu_read_unlock();
938 owner = ctx->disk->fops->owner; 933 put_disk_and_module(ctx->disk);
939 put_disk(ctx->disk);
940 module_put(owner);
941} 934}
942EXPORT_SYMBOL_GPL(blkg_conf_finish); 935EXPORT_SYMBOL_GPL(blkg_conf_finish);
943 936
diff --git a/block/blk-core.c b/block/blk-core.c
index 2d1a7bbe0634..6d82c4f7fadd 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -2434,7 +2434,7 @@ blk_qc_t submit_bio(struct bio *bio)
2434 unsigned int count; 2434 unsigned int count;
2435 2435
2436 if (unlikely(bio_op(bio) == REQ_OP_WRITE_SAME)) 2436 if (unlikely(bio_op(bio) == REQ_OP_WRITE_SAME))
2437 count = queue_logical_block_size(bio->bi_disk->queue); 2437 count = queue_logical_block_size(bio->bi_disk->queue) >> 9;
2438 else 2438 else
2439 count = bio_sectors(bio); 2439 count = bio_sectors(bio);
2440 2440
diff --git a/block/blk-mq.c b/block/blk-mq.c
index df93102e2149..16e83e6df404 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -712,7 +712,6 @@ static void __blk_mq_requeue_request(struct request *rq)
712 712
713 trace_block_rq_requeue(q, rq); 713 trace_block_rq_requeue(q, rq);
714 wbt_requeue(q->rq_wb, &rq->issue_stat); 714 wbt_requeue(q->rq_wb, &rq->issue_stat);
715 blk_mq_sched_requeue_request(rq);
716 715
717 if (blk_mq_rq_state(rq) != MQ_RQ_IDLE) { 716 if (blk_mq_rq_state(rq) != MQ_RQ_IDLE) {
718 blk_mq_rq_update_state(rq, MQ_RQ_IDLE); 717 blk_mq_rq_update_state(rq, MQ_RQ_IDLE);
@@ -725,6 +724,9 @@ void blk_mq_requeue_request(struct request *rq, bool kick_requeue_list)
725{ 724{
726 __blk_mq_requeue_request(rq); 725 __blk_mq_requeue_request(rq);
727 726
727 /* this request will be re-inserted to io scheduler queue */
728 blk_mq_sched_requeue_request(rq);
729
728 BUG_ON(blk_queued_rq(rq)); 730 BUG_ON(blk_queued_rq(rq));
729 blk_mq_add_to_requeue_list(rq, true, kick_requeue_list); 731 blk_mq_add_to_requeue_list(rq, true, kick_requeue_list);
730} 732}
@@ -3164,6 +3166,7 @@ static bool __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq)
3164 cpu_relax(); 3166 cpu_relax();
3165 } 3167 }
3166 3168
3169 __set_current_state(TASK_RUNNING);
3167 return false; 3170 return false;
3168} 3171}
3169 3172
diff --git a/block/genhd.c b/block/genhd.c
index 88a53c188cb7..9656f9e9f99e 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -547,7 +547,7 @@ static int exact_lock(dev_t devt, void *data)
547{ 547{
548 struct gendisk *p = data; 548 struct gendisk *p = data;
549 549
550 if (!get_disk(p)) 550 if (!get_disk_and_module(p))
551 return -1; 551 return -1;
552 return 0; 552 return 0;
553} 553}
@@ -717,6 +717,11 @@ void del_gendisk(struct gendisk *disk)
717 blk_integrity_del(disk); 717 blk_integrity_del(disk);
718 disk_del_events(disk); 718 disk_del_events(disk);
719 719
720 /*
721 * Block lookups of the disk until all bdevs are unhashed and the
722 * disk is marked as dead (GENHD_FL_UP cleared).
723 */
724 down_write(&disk->lookup_sem);
720 /* invalidate stuff */ 725 /* invalidate stuff */
721 disk_part_iter_init(&piter, disk, 726 disk_part_iter_init(&piter, disk,
722 DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE); 727 DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
@@ -731,6 +736,7 @@ void del_gendisk(struct gendisk *disk)
731 bdev_unhash_inode(disk_devt(disk)); 736 bdev_unhash_inode(disk_devt(disk));
732 set_capacity(disk, 0); 737 set_capacity(disk, 0);
733 disk->flags &= ~GENHD_FL_UP; 738 disk->flags &= ~GENHD_FL_UP;
739 up_write(&disk->lookup_sem);
734 740
735 if (!(disk->flags & GENHD_FL_HIDDEN)) 741 if (!(disk->flags & GENHD_FL_HIDDEN))
736 sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi"); 742 sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi");
@@ -809,16 +815,28 @@ struct gendisk *get_gendisk(dev_t devt, int *partno)
809 815
810 spin_lock_bh(&ext_devt_lock); 816 spin_lock_bh(&ext_devt_lock);
811 part = idr_find(&ext_devt_idr, blk_mangle_minor(MINOR(devt))); 817 part = idr_find(&ext_devt_idr, blk_mangle_minor(MINOR(devt)));
812 if (part && get_disk(part_to_disk(part))) { 818 if (part && get_disk_and_module(part_to_disk(part))) {
813 *partno = part->partno; 819 *partno = part->partno;
814 disk = part_to_disk(part); 820 disk = part_to_disk(part);
815 } 821 }
816 spin_unlock_bh(&ext_devt_lock); 822 spin_unlock_bh(&ext_devt_lock);
817 } 823 }
818 824
819 if (disk && unlikely(disk->flags & GENHD_FL_HIDDEN)) { 825 if (!disk)
820 put_disk(disk); 826 return NULL;
827
828 /*
829 * Synchronize with del_gendisk() to not return disk that is being
830 * destroyed.
831 */
832 down_read(&disk->lookup_sem);
833 if (unlikely((disk->flags & GENHD_FL_HIDDEN) ||
834 !(disk->flags & GENHD_FL_UP))) {
835 up_read(&disk->lookup_sem);
836 put_disk_and_module(disk);
821 disk = NULL; 837 disk = NULL;
838 } else {
839 up_read(&disk->lookup_sem);
822 } 840 }
823 return disk; 841 return disk;
824} 842}
@@ -1418,6 +1436,7 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
1418 kfree(disk); 1436 kfree(disk);
1419 return NULL; 1437 return NULL;
1420 } 1438 }
1439 init_rwsem(&disk->lookup_sem);
1421 disk->node_id = node_id; 1440 disk->node_id = node_id;
1422 if (disk_expand_part_tbl(disk, 0)) { 1441 if (disk_expand_part_tbl(disk, 0)) {
1423 free_part_stats(&disk->part0); 1442 free_part_stats(&disk->part0);
@@ -1453,7 +1472,7 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
1453} 1472}
1454EXPORT_SYMBOL(__alloc_disk_node); 1473EXPORT_SYMBOL(__alloc_disk_node);
1455 1474
1456struct kobject *get_disk(struct gendisk *disk) 1475struct kobject *get_disk_and_module(struct gendisk *disk)
1457{ 1476{
1458 struct module *owner; 1477 struct module *owner;
1459 struct kobject *kobj; 1478 struct kobject *kobj;
@@ -1471,17 +1490,30 @@ struct kobject *get_disk(struct gendisk *disk)
1471 return kobj; 1490 return kobj;
1472 1491
1473} 1492}
1474 1493EXPORT_SYMBOL(get_disk_and_module);
1475EXPORT_SYMBOL(get_disk);
1476 1494
1477void put_disk(struct gendisk *disk) 1495void put_disk(struct gendisk *disk)
1478{ 1496{
1479 if (disk) 1497 if (disk)
1480 kobject_put(&disk_to_dev(disk)->kobj); 1498 kobject_put(&disk_to_dev(disk)->kobj);
1481} 1499}
1482
1483EXPORT_SYMBOL(put_disk); 1500EXPORT_SYMBOL(put_disk);
1484 1501
1502/*
1503 * This is a counterpart of get_disk_and_module() and thus also of
1504 * get_gendisk().
1505 */
1506void put_disk_and_module(struct gendisk *disk)
1507{
1508 if (disk) {
1509 struct module *owner = disk->fops->owner;
1510
1511 put_disk(disk);
1512 module_put(owner);
1513 }
1514}
1515EXPORT_SYMBOL(put_disk_and_module);
1516
1485static void set_disk_ro_uevent(struct gendisk *gd, int ro) 1517static void set_disk_ro_uevent(struct gendisk *gd, int ro)
1486{ 1518{
1487 char event[] = "DISK_RO=1"; 1519 char event[] = "DISK_RO=1";
diff --git a/block/ioctl.c b/block/ioctl.c
index 1668506d8ed8..3884d810efd2 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -225,7 +225,7 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
225 225
226 if (start + len > i_size_read(bdev->bd_inode)) 226 if (start + len > i_size_read(bdev->bd_inode))
227 return -EINVAL; 227 return -EINVAL;
228 truncate_inode_pages_range(mapping, start, start + len); 228 truncate_inode_pages_range(mapping, start, start + len - 1);
229 return blkdev_issue_discard(bdev, start >> 9, len >> 9, 229 return blkdev_issue_discard(bdev, start >> 9, len >> 9,
230 GFP_KERNEL, flags); 230 GFP_KERNEL, flags);
231} 231}
diff --git a/block/kyber-iosched.c b/block/kyber-iosched.c
index f95c60774ce8..0d6d25e32e1f 100644
--- a/block/kyber-iosched.c
+++ b/block/kyber-iosched.c
@@ -833,6 +833,7 @@ static struct elevator_type kyber_sched = {
833 .limit_depth = kyber_limit_depth, 833 .limit_depth = kyber_limit_depth,
834 .prepare_request = kyber_prepare_request, 834 .prepare_request = kyber_prepare_request,
835 .finish_request = kyber_finish_request, 835 .finish_request = kyber_finish_request,
836 .requeue_request = kyber_finish_request,
836 .completed_request = kyber_completed_request, 837 .completed_request = kyber_completed_request,
837 .dispatch_request = kyber_dispatch_request, 838 .dispatch_request = kyber_dispatch_request,
838 .has_work = kyber_has_work, 839 .has_work = kyber_has_work,
diff --git a/block/mq-deadline.c b/block/mq-deadline.c
index c56f211c8440..8ec0ba9f5386 100644
--- a/block/mq-deadline.c
+++ b/block/mq-deadline.c
@@ -536,12 +536,21 @@ static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
536} 536}
537 537
538/* 538/*
539 * Nothing to do here. This is defined only to ensure that .finish_request
540 * method is called upon request completion.
541 */
542static void dd_prepare_request(struct request *rq, struct bio *bio)
543{
544}
545
546/*
539 * For zoned block devices, write unlock the target zone of 547 * For zoned block devices, write unlock the target zone of
540 * completed write requests. Do this while holding the zone lock 548 * completed write requests. Do this while holding the zone lock
541 * spinlock so that the zone is never unlocked while deadline_fifo_request() 549 * spinlock so that the zone is never unlocked while deadline_fifo_request()
542 * while deadline_next_request() are executing. 550 * or deadline_next_request() are executing. This function is called for
551 * all requests, whether or not these requests complete successfully.
543 */ 552 */
544static void dd_completed_request(struct request *rq) 553static void dd_finish_request(struct request *rq)
545{ 554{
546 struct request_queue *q = rq->q; 555 struct request_queue *q = rq->q;
547 556
@@ -756,7 +765,8 @@ static struct elevator_type mq_deadline = {
756 .ops.mq = { 765 .ops.mq = {
757 .insert_requests = dd_insert_requests, 766 .insert_requests = dd_insert_requests,
758 .dispatch_request = dd_dispatch_request, 767 .dispatch_request = dd_dispatch_request,
759 .completed_request = dd_completed_request, 768 .prepare_request = dd_prepare_request,
769 .finish_request = dd_finish_request,
760 .next_request = elv_rb_latter_request, 770 .next_request = elv_rb_latter_request,
761 .former_request = elv_rb_former_request, 771 .former_request = elv_rb_former_request,
762 .bio_merge = dd_bio_merge, 772 .bio_merge = dd_bio_merge,
diff --git a/block/partition-generic.c b/block/partition-generic.c
index 91622db9aedf..08dabcd8b6ae 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -51,6 +51,12 @@ const char *bdevname(struct block_device *bdev, char *buf)
51 51
52EXPORT_SYMBOL(bdevname); 52EXPORT_SYMBOL(bdevname);
53 53
54const char *bio_devname(struct bio *bio, char *buf)
55{
56 return disk_name(bio->bi_disk, bio->bi_partno, buf);
57}
58EXPORT_SYMBOL(bio_devname);
59
54/* 60/*
55 * There's very little reason to use this, you should really 61 * There's very little reason to use this, you should really
56 * have a struct block_device just about everywhere and use 62 * have a struct block_device just about everywhere and use
diff --git a/block/sed-opal.c b/block/sed-opal.c
index 9ed51d0c6b1d..e4929eec547f 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -490,7 +490,7 @@ static int opal_discovery0_end(struct opal_dev *dev)
490 490
491 if (!found_com_id) { 491 if (!found_com_id) {
492 pr_debug("Could not find OPAL comid for device. Returning early\n"); 492 pr_debug("Could not find OPAL comid for device. Returning early\n");
493 return -EOPNOTSUPP;; 493 return -EOPNOTSUPP;
494 } 494 }
495 495
496 dev->comid = comid; 496 dev->comid = comid;
diff --git a/certs/blacklist_nohashes.c b/certs/blacklist_nohashes.c
index 73fd99098ad7..753b703ef0ef 100644
--- a/certs/blacklist_nohashes.c
+++ b/certs/blacklist_nohashes.c
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2#include "blacklist.h" 2#include "blacklist.h"
3 3
4const char __initdata *const blacklist_hashes[] = { 4const char __initconst *const blacklist_hashes[] = {
5 NULL 5 NULL
6}; 6};
diff --git a/crypto/asymmetric_keys/pkcs7_trust.c b/crypto/asymmetric_keys/pkcs7_trust.c
index 1f4e25f10049..598906b1e28d 100644
--- a/crypto/asymmetric_keys/pkcs7_trust.c
+++ b/crypto/asymmetric_keys/pkcs7_trust.c
@@ -106,6 +106,7 @@ static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7,
106 pr_devel("sinfo %u: Direct signer is key %x\n", 106 pr_devel("sinfo %u: Direct signer is key %x\n",
107 sinfo->index, key_serial(key)); 107 sinfo->index, key_serial(key));
108 x509 = NULL; 108 x509 = NULL;
109 sig = sinfo->sig;
109 goto matched; 110 goto matched;
110 } 111 }
111 if (PTR_ERR(key) != -ENOKEY) 112 if (PTR_ERR(key) != -ENOKEY)
diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c
index 39e6de0c2761..97c77f66b20d 100644
--- a/crypto/asymmetric_keys/pkcs7_verify.c
+++ b/crypto/asymmetric_keys/pkcs7_verify.c
@@ -270,7 +270,7 @@ static int pkcs7_verify_sig_chain(struct pkcs7_message *pkcs7,
270 sinfo->index); 270 sinfo->index);
271 return 0; 271 return 0;
272 } 272 }
273 ret = public_key_verify_signature(p->pub, p->sig); 273 ret = public_key_verify_signature(p->pub, x509->sig);
274 if (ret < 0) 274 if (ret < 0)
275 return ret; 275 return ret;
276 x509->signer = p; 276 x509->signer = p;
@@ -366,8 +366,7 @@ static int pkcs7_verify_one(struct pkcs7_message *pkcs7,
366 * 366 *
367 * (*) -EBADMSG if some part of the message was invalid, or: 367 * (*) -EBADMSG if some part of the message was invalid, or:
368 * 368 *
369 * (*) 0 if no signature chains were found to be blacklisted or to contain 369 * (*) 0 if a signature chain passed verification, or:
370 * unsupported crypto, or:
371 * 370 *
372 * (*) -EKEYREJECTED if a blacklisted key was encountered, or: 371 * (*) -EKEYREJECTED if a blacklisted key was encountered, or:
373 * 372 *
@@ -423,8 +422,11 @@ int pkcs7_verify(struct pkcs7_message *pkcs7,
423 422
424 for (sinfo = pkcs7->signed_infos; sinfo; sinfo = sinfo->next) { 423 for (sinfo = pkcs7->signed_infos; sinfo; sinfo = sinfo->next) {
425 ret = pkcs7_verify_one(pkcs7, sinfo); 424 ret = pkcs7_verify_one(pkcs7, sinfo);
426 if (sinfo->blacklisted && actual_ret == -ENOPKG) 425 if (sinfo->blacklisted) {
427 actual_ret = -EKEYREJECTED; 426 if (actual_ret == -ENOPKG)
427 actual_ret = -EKEYREJECTED;
428 continue;
429 }
428 if (ret < 0) { 430 if (ret < 0) {
429 if (ret == -ENOPKG) { 431 if (ret == -ENOPKG) {
430 sinfo->unsupported_crypto = true; 432 sinfo->unsupported_crypto = true;
diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index de996586762a..e929fe1e4106 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -79,9 +79,11 @@ int public_key_verify_signature(const struct public_key *pkey,
79 79
80 BUG_ON(!pkey); 80 BUG_ON(!pkey);
81 BUG_ON(!sig); 81 BUG_ON(!sig);
82 BUG_ON(!sig->digest);
83 BUG_ON(!sig->s); 82 BUG_ON(!sig->s);
84 83
84 if (!sig->digest)
85 return -ENOPKG;
86
85 alg_name = sig->pkey_algo; 87 alg_name = sig->pkey_algo;
86 if (strcmp(sig->pkey_algo, "rsa") == 0) { 88 if (strcmp(sig->pkey_algo, "rsa") == 0) {
87 /* The data wangled by the RSA algorithm is typically padded 89 /* The data wangled by the RSA algorithm is typically padded
diff --git a/crypto/asymmetric_keys/restrict.c b/crypto/asymmetric_keys/restrict.c
index 86fb68508952..7c93c7728454 100644
--- a/crypto/asymmetric_keys/restrict.c
+++ b/crypto/asymmetric_keys/restrict.c
@@ -67,8 +67,9 @@ __setup("ca_keys=", ca_keys_setup);
67 * 67 *
68 * Returns 0 if the new certificate was accepted, -ENOKEY if we couldn't find a 68 * Returns 0 if the new certificate was accepted, -ENOKEY if we couldn't find a
69 * matching parent certificate in the trusted list, -EKEYREJECTED if the 69 * matching parent certificate in the trusted list, -EKEYREJECTED if the
70 * signature check fails or the key is blacklisted and some other error if 70 * signature check fails or the key is blacklisted, -ENOPKG if the signature
71 * there is a matching certificate but the signature check cannot be performed. 71 * uses unsupported crypto, or some other error if there is a matching
72 * certificate but the signature check cannot be performed.
72 */ 73 */
73int restrict_link_by_signature(struct key *dest_keyring, 74int restrict_link_by_signature(struct key *dest_keyring,
74 const struct key_type *type, 75 const struct key_type *type,
@@ -88,6 +89,8 @@ int restrict_link_by_signature(struct key *dest_keyring,
88 return -EOPNOTSUPP; 89 return -EOPNOTSUPP;
89 90
90 sig = payload->data[asym_auth]; 91 sig = payload->data[asym_auth];
92 if (!sig)
93 return -ENOPKG;
91 if (!sig->auth_ids[0] && !sig->auth_ids[1]) 94 if (!sig->auth_ids[0] && !sig->auth_ids[1])
92 return -ENOKEY; 95 return -ENOKEY;
93 96
@@ -139,6 +142,8 @@ static int key_or_keyring_common(struct key *dest_keyring,
139 return -EOPNOTSUPP; 142 return -EOPNOTSUPP;
140 143
141 sig = payload->data[asym_auth]; 144 sig = payload->data[asym_auth];
145 if (!sig)
146 return -ENOPKG;
142 if (!sig->auth_ids[0] && !sig->auth_ids[1]) 147 if (!sig->auth_ids[0] && !sig->auth_ids[1])
143 return -ENOKEY; 148 return -ENOKEY;
144 149
@@ -222,9 +227,9 @@ static int key_or_keyring_common(struct key *dest_keyring,
222 * 227 *
223 * Returns 0 if the new certificate was accepted, -ENOKEY if we 228 * Returns 0 if the new certificate was accepted, -ENOKEY if we
224 * couldn't find a matching parent certificate in the trusted list, 229 * couldn't find a matching parent certificate in the trusted list,
225 * -EKEYREJECTED if the signature check fails, and some other error if 230 * -EKEYREJECTED if the signature check fails, -ENOPKG if the signature uses
226 * there is a matching certificate but the signature check cannot be 231 * unsupported crypto, or some other error if there is a matching certificate
227 * performed. 232 * but the signature check cannot be performed.
228 */ 233 */
229int restrict_link_by_key_or_keyring(struct key *dest_keyring, 234int restrict_link_by_key_or_keyring(struct key *dest_keyring,
230 const struct key_type *type, 235 const struct key_type *type,
@@ -249,9 +254,9 @@ int restrict_link_by_key_or_keyring(struct key *dest_keyring,
249 * 254 *
250 * Returns 0 if the new certificate was accepted, -ENOKEY if we 255 * Returns 0 if the new certificate was accepted, -ENOKEY if we
251 * couldn't find a matching parent certificate in the trusted list, 256 * couldn't find a matching parent certificate in the trusted list,
252 * -EKEYREJECTED if the signature check fails, and some other error if 257 * -EKEYREJECTED if the signature check fails, -ENOPKG if the signature uses
253 * there is a matching certificate but the signature check cannot be 258 * unsupported crypto, or some other error if there is a matching certificate
254 * performed. 259 * but the signature check cannot be performed.
255 */ 260 */
256int restrict_link_by_key_or_keyring_chain(struct key *dest_keyring, 261int restrict_link_by_key_or_keyring_chain(struct key *dest_keyring,
257 const struct key_type *type, 262 const struct key_type *type,
diff --git a/crypto/sha3_generic.c b/crypto/sha3_generic.c
index a965b9d80559..ded148783303 100644
--- a/crypto/sha3_generic.c
+++ b/crypto/sha3_generic.c
@@ -20,6 +20,20 @@
20#include <crypto/sha3.h> 20#include <crypto/sha3.h>
21#include <asm/unaligned.h> 21#include <asm/unaligned.h>
22 22
23/*
24 * On some 32-bit architectures (mn10300 and h8300), GCC ends up using
25 * over 1 KB of stack if we inline the round calculation into the loop
26 * in keccakf(). On the other hand, on 64-bit architectures with plenty
27 * of [64-bit wide] general purpose registers, not inlining it severely
28 * hurts performance. So let's use 64-bitness as a heuristic to decide
29 * whether to inline or not.
30 */
31#ifdef CONFIG_64BIT
32#define SHA3_INLINE inline
33#else
34#define SHA3_INLINE noinline
35#endif
36
23#define KECCAK_ROUNDS 24 37#define KECCAK_ROUNDS 24
24 38
25static const u64 keccakf_rndc[24] = { 39static const u64 keccakf_rndc[24] = {
@@ -35,111 +49,115 @@ static const u64 keccakf_rndc[24] = {
35 49
36/* update the state with given number of rounds */ 50/* update the state with given number of rounds */
37 51
38static void __attribute__((__optimize__("O3"))) keccakf(u64 st[25]) 52static SHA3_INLINE void keccakf_round(u64 st[25])
39{ 53{
40 u64 t[5], tt, bc[5]; 54 u64 t[5], tt, bc[5];
41 int round;
42 55
43 for (round = 0; round < KECCAK_ROUNDS; round++) { 56 /* Theta */
57 bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20];
58 bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21];
59 bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22];
60 bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23];
61 bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
62
63 t[0] = bc[4] ^ rol64(bc[1], 1);
64 t[1] = bc[0] ^ rol64(bc[2], 1);
65 t[2] = bc[1] ^ rol64(bc[3], 1);
66 t[3] = bc[2] ^ rol64(bc[4], 1);
67 t[4] = bc[3] ^ rol64(bc[0], 1);
68
69 st[0] ^= t[0];
70
71 /* Rho Pi */
72 tt = st[1];
73 st[ 1] = rol64(st[ 6] ^ t[1], 44);
74 st[ 6] = rol64(st[ 9] ^ t[4], 20);
75 st[ 9] = rol64(st[22] ^ t[2], 61);
76 st[22] = rol64(st[14] ^ t[4], 39);
77 st[14] = rol64(st[20] ^ t[0], 18);
78 st[20] = rol64(st[ 2] ^ t[2], 62);
79 st[ 2] = rol64(st[12] ^ t[2], 43);
80 st[12] = rol64(st[13] ^ t[3], 25);
81 st[13] = rol64(st[19] ^ t[4], 8);
82 st[19] = rol64(st[23] ^ t[3], 56);
83 st[23] = rol64(st[15] ^ t[0], 41);
84 st[15] = rol64(st[ 4] ^ t[4], 27);
85 st[ 4] = rol64(st[24] ^ t[4], 14);
86 st[24] = rol64(st[21] ^ t[1], 2);
87 st[21] = rol64(st[ 8] ^ t[3], 55);
88 st[ 8] = rol64(st[16] ^ t[1], 45);
89 st[16] = rol64(st[ 5] ^ t[0], 36);
90 st[ 5] = rol64(st[ 3] ^ t[3], 28);
91 st[ 3] = rol64(st[18] ^ t[3], 21);
92 st[18] = rol64(st[17] ^ t[2], 15);
93 st[17] = rol64(st[11] ^ t[1], 10);
94 st[11] = rol64(st[ 7] ^ t[2], 6);
95 st[ 7] = rol64(st[10] ^ t[0], 3);
96 st[10] = rol64( tt ^ t[1], 1);
97
98 /* Chi */
99 bc[ 0] = ~st[ 1] & st[ 2];
100 bc[ 1] = ~st[ 2] & st[ 3];
101 bc[ 2] = ~st[ 3] & st[ 4];
102 bc[ 3] = ~st[ 4] & st[ 0];
103 bc[ 4] = ~st[ 0] & st[ 1];
104 st[ 0] ^= bc[ 0];
105 st[ 1] ^= bc[ 1];
106 st[ 2] ^= bc[ 2];
107 st[ 3] ^= bc[ 3];
108 st[ 4] ^= bc[ 4];
109
110 bc[ 0] = ~st[ 6] & st[ 7];
111 bc[ 1] = ~st[ 7] & st[ 8];
112 bc[ 2] = ~st[ 8] & st[ 9];
113 bc[ 3] = ~st[ 9] & st[ 5];
114 bc[ 4] = ~st[ 5] & st[ 6];
115 st[ 5] ^= bc[ 0];
116 st[ 6] ^= bc[ 1];
117 st[ 7] ^= bc[ 2];
118 st[ 8] ^= bc[ 3];
119 st[ 9] ^= bc[ 4];
120
121 bc[ 0] = ~st[11] & st[12];
122 bc[ 1] = ~st[12] & st[13];
123 bc[ 2] = ~st[13] & st[14];
124 bc[ 3] = ~st[14] & st[10];
125 bc[ 4] = ~st[10] & st[11];
126 st[10] ^= bc[ 0];
127 st[11] ^= bc[ 1];
128 st[12] ^= bc[ 2];
129 st[13] ^= bc[ 3];
130 st[14] ^= bc[ 4];
131
132 bc[ 0] = ~st[16] & st[17];
133 bc[ 1] = ~st[17] & st[18];
134 bc[ 2] = ~st[18] & st[19];
135 bc[ 3] = ~st[19] & st[15];
136 bc[ 4] = ~st[15] & st[16];
137 st[15] ^= bc[ 0];
138 st[16] ^= bc[ 1];
139 st[17] ^= bc[ 2];
140 st[18] ^= bc[ 3];
141 st[19] ^= bc[ 4];
142
143 bc[ 0] = ~st[21] & st[22];
144 bc[ 1] = ~st[22] & st[23];
145 bc[ 2] = ~st[23] & st[24];
146 bc[ 3] = ~st[24] & st[20];
147 bc[ 4] = ~st[20] & st[21];
148 st[20] ^= bc[ 0];
149 st[21] ^= bc[ 1];
150 st[22] ^= bc[ 2];
151 st[23] ^= bc[ 3];
152 st[24] ^= bc[ 4];
153}
44 154
45 /* Theta */ 155static void __optimize("O3") keccakf(u64 st[25])
46 bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20]; 156{
47 bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21]; 157 int round;
48 bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22];
49 bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23];
50 bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
51
52 t[0] = bc[4] ^ rol64(bc[1], 1);
53 t[1] = bc[0] ^ rol64(bc[2], 1);
54 t[2] = bc[1] ^ rol64(bc[3], 1);
55 t[3] = bc[2] ^ rol64(bc[4], 1);
56 t[4] = bc[3] ^ rol64(bc[0], 1);
57
58 st[0] ^= t[0];
59
60 /* Rho Pi */
61 tt = st[1];
62 st[ 1] = rol64(st[ 6] ^ t[1], 44);
63 st[ 6] = rol64(st[ 9] ^ t[4], 20);
64 st[ 9] = rol64(st[22] ^ t[2], 61);
65 st[22] = rol64(st[14] ^ t[4], 39);
66 st[14] = rol64(st[20] ^ t[0], 18);
67 st[20] = rol64(st[ 2] ^ t[2], 62);
68 st[ 2] = rol64(st[12] ^ t[2], 43);
69 st[12] = rol64(st[13] ^ t[3], 25);
70 st[13] = rol64(st[19] ^ t[4], 8);
71 st[19] = rol64(st[23] ^ t[3], 56);
72 st[23] = rol64(st[15] ^ t[0], 41);
73 st[15] = rol64(st[ 4] ^ t[4], 27);
74 st[ 4] = rol64(st[24] ^ t[4], 14);
75 st[24] = rol64(st[21] ^ t[1], 2);
76 st[21] = rol64(st[ 8] ^ t[3], 55);
77 st[ 8] = rol64(st[16] ^ t[1], 45);
78 st[16] = rol64(st[ 5] ^ t[0], 36);
79 st[ 5] = rol64(st[ 3] ^ t[3], 28);
80 st[ 3] = rol64(st[18] ^ t[3], 21);
81 st[18] = rol64(st[17] ^ t[2], 15);
82 st[17] = rol64(st[11] ^ t[1], 10);
83 st[11] = rol64(st[ 7] ^ t[2], 6);
84 st[ 7] = rol64(st[10] ^ t[0], 3);
85 st[10] = rol64( tt ^ t[1], 1);
86
87 /* Chi */
88 bc[ 0] = ~st[ 1] & st[ 2];
89 bc[ 1] = ~st[ 2] & st[ 3];
90 bc[ 2] = ~st[ 3] & st[ 4];
91 bc[ 3] = ~st[ 4] & st[ 0];
92 bc[ 4] = ~st[ 0] & st[ 1];
93 st[ 0] ^= bc[ 0];
94 st[ 1] ^= bc[ 1];
95 st[ 2] ^= bc[ 2];
96 st[ 3] ^= bc[ 3];
97 st[ 4] ^= bc[ 4];
98
99 bc[ 0] = ~st[ 6] & st[ 7];
100 bc[ 1] = ~st[ 7] & st[ 8];
101 bc[ 2] = ~st[ 8] & st[ 9];
102 bc[ 3] = ~st[ 9] & st[ 5];
103 bc[ 4] = ~st[ 5] & st[ 6];
104 st[ 5] ^= bc[ 0];
105 st[ 6] ^= bc[ 1];
106 st[ 7] ^= bc[ 2];
107 st[ 8] ^= bc[ 3];
108 st[ 9] ^= bc[ 4];
109
110 bc[ 0] = ~st[11] & st[12];
111 bc[ 1] = ~st[12] & st[13];
112 bc[ 2] = ~st[13] & st[14];
113 bc[ 3] = ~st[14] & st[10];
114 bc[ 4] = ~st[10] & st[11];
115 st[10] ^= bc[ 0];
116 st[11] ^= bc[ 1];
117 st[12] ^= bc[ 2];
118 st[13] ^= bc[ 3];
119 st[14] ^= bc[ 4];
120
121 bc[ 0] = ~st[16] & st[17];
122 bc[ 1] = ~st[17] & st[18];
123 bc[ 2] = ~st[18] & st[19];
124 bc[ 3] = ~st[19] & st[15];
125 bc[ 4] = ~st[15] & st[16];
126 st[15] ^= bc[ 0];
127 st[16] ^= bc[ 1];
128 st[17] ^= bc[ 2];
129 st[18] ^= bc[ 3];
130 st[19] ^= bc[ 4];
131
132 bc[ 0] = ~st[21] & st[22];
133 bc[ 1] = ~st[22] & st[23];
134 bc[ 2] = ~st[23] & st[24];
135 bc[ 3] = ~st[24] & st[20];
136 bc[ 4] = ~st[20] & st[21];
137 st[20] ^= bc[ 0];
138 st[21] ^= bc[ 1];
139 st[22] ^= bc[ 2];
140 st[23] ^= bc[ 3];
141 st[24] ^= bc[ 4];
142 158
159 for (round = 0; round < KECCAK_ROUNDS; round++) {
160 keccakf_round(st);
143 /* Iota */ 161 /* Iota */
144 st[0] ^= keccakf_rndc[round]; 162 st[0] ^= keccakf_rndc[round];
145 } 163 }
diff --git a/drivers/acpi/acpi_watchdog.c b/drivers/acpi/acpi_watchdog.c
index 11b113f8e367..ebb626ffb5fa 100644
--- a/drivers/acpi/acpi_watchdog.c
+++ b/drivers/acpi/acpi_watchdog.c
@@ -74,10 +74,10 @@ void __init acpi_watchdog_init(void)
74 res.start = gas->address; 74 res.start = gas->address;
75 if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 75 if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
76 res.flags = IORESOURCE_MEM; 76 res.flags = IORESOURCE_MEM;
77 res.end = res.start + ALIGN(gas->access_width, 4); 77 res.end = res.start + ALIGN(gas->access_width, 4) - 1;
78 } else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { 78 } else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
79 res.flags = IORESOURCE_IO; 79 res.flags = IORESOURCE_IO;
80 res.end = res.start + gas->access_width; 80 res.end = res.start + gas->access_width - 1;
81 } else { 81 } else {
82 pr_warn("Unsupported address space: %u\n", 82 pr_warn("Unsupported address space: %u\n",
83 gas->space_id); 83 gas->space_id);
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 7128488a3a72..f2eb6c37ea0a 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -70,7 +70,6 @@ static async_cookie_t async_cookie;
70static bool battery_driver_registered; 70static bool battery_driver_registered;
71static int battery_bix_broken_package; 71static int battery_bix_broken_package;
72static int battery_notification_delay_ms; 72static int battery_notification_delay_ms;
73static int battery_full_discharging;
74static unsigned int cache_time = 1000; 73static unsigned int cache_time = 1000;
75module_param(cache_time, uint, 0644); 74module_param(cache_time, uint, 0644);
76MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); 75MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
@@ -215,12 +214,9 @@ static int acpi_battery_get_property(struct power_supply *psy,
215 return -ENODEV; 214 return -ENODEV;
216 switch (psp) { 215 switch (psp) {
217 case POWER_SUPPLY_PROP_STATUS: 216 case POWER_SUPPLY_PROP_STATUS:
218 if (battery->state & ACPI_BATTERY_STATE_DISCHARGING) { 217 if (battery->state & ACPI_BATTERY_STATE_DISCHARGING)
219 if (battery_full_discharging && battery->rate_now == 0) 218 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
220 val->intval = POWER_SUPPLY_STATUS_FULL; 219 else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
221 else
222 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
223 } else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
224 val->intval = POWER_SUPPLY_STATUS_CHARGING; 220 val->intval = POWER_SUPPLY_STATUS_CHARGING;
225 else if (acpi_battery_is_charged(battery)) 221 else if (acpi_battery_is_charged(battery))
226 val->intval = POWER_SUPPLY_STATUS_FULL; 222 val->intval = POWER_SUPPLY_STATUS_FULL;
@@ -1170,12 +1166,6 @@ battery_notification_delay_quirk(const struct dmi_system_id *d)
1170 return 0; 1166 return 0;
1171} 1167}
1172 1168
1173static int __init battery_full_discharging_quirk(const struct dmi_system_id *d)
1174{
1175 battery_full_discharging = 1;
1176 return 0;
1177}
1178
1179static const struct dmi_system_id bat_dmi_table[] __initconst = { 1169static const struct dmi_system_id bat_dmi_table[] __initconst = {
1180 { 1170 {
1181 .callback = battery_bix_broken_package_quirk, 1171 .callback = battery_bix_broken_package_quirk,
@@ -1193,38 +1183,6 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = {
1193 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"), 1183 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"),
1194 }, 1184 },
1195 }, 1185 },
1196 {
1197 .callback = battery_full_discharging_quirk,
1198 .ident = "ASUS GL502VSK",
1199 .matches = {
1200 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1201 DMI_MATCH(DMI_PRODUCT_NAME, "GL502VSK"),
1202 },
1203 },
1204 {
1205 .callback = battery_full_discharging_quirk,
1206 .ident = "ASUS UX305LA",
1207 .matches = {
1208 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1209 DMI_MATCH(DMI_PRODUCT_NAME, "UX305LA"),
1210 },
1211 },
1212 {
1213 .callback = battery_full_discharging_quirk,
1214 .ident = "ASUS UX360UA",
1215 .matches = {
1216 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1217 DMI_MATCH(DMI_PRODUCT_NAME, "UX360UA"),
1218 },
1219 },
1220 {
1221 .callback = battery_full_discharging_quirk,
1222 .ident = "ASUS UX410UAK",
1223 .matches = {
1224 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1225 DMI_MATCH(DMI_PRODUCT_NAME, "UX410UAK"),
1226 },
1227 },
1228 {}, 1186 {},
1229}; 1187};
1230 1188
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 676c9788e1c8..0dad0bd9327b 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -660,13 +660,15 @@ struct acpi_device *acpi_companion_match(const struct device *dev)
660 * acpi_of_match_device - Match device object using the "compatible" property. 660 * acpi_of_match_device - Match device object using the "compatible" property.
661 * @adev: ACPI device object to match. 661 * @adev: ACPI device object to match.
662 * @of_match_table: List of device IDs to match against. 662 * @of_match_table: List of device IDs to match against.
663 * @of_id: OF ID if matched
663 * 664 *
664 * If @dev has an ACPI companion which has ACPI_DT_NAMESPACE_HID in its list of 665 * If @dev has an ACPI companion which has ACPI_DT_NAMESPACE_HID in its list of
665 * identifiers and a _DSD object with the "compatible" property, use that 666 * identifiers and a _DSD object with the "compatible" property, use that
666 * property to match against the given list of identifiers. 667 * property to match against the given list of identifiers.
667 */ 668 */
668static bool acpi_of_match_device(struct acpi_device *adev, 669static bool acpi_of_match_device(struct acpi_device *adev,
669 const struct of_device_id *of_match_table) 670 const struct of_device_id *of_match_table,
671 const struct of_device_id **of_id)
670{ 672{
671 const union acpi_object *of_compatible, *obj; 673 const union acpi_object *of_compatible, *obj;
672 int i, nval; 674 int i, nval;
@@ -690,8 +692,11 @@ static bool acpi_of_match_device(struct acpi_device *adev,
690 const struct of_device_id *id; 692 const struct of_device_id *id;
691 693
692 for (id = of_match_table; id->compatible[0]; id++) 694 for (id = of_match_table; id->compatible[0]; id++)
693 if (!strcasecmp(obj->string.pointer, id->compatible)) 695 if (!strcasecmp(obj->string.pointer, id->compatible)) {
696 if (of_id)
697 *of_id = id;
694 return true; 698 return true;
699 }
695 } 700 }
696 701
697 return false; 702 return false;
@@ -762,10 +767,11 @@ static bool __acpi_match_device_cls(const struct acpi_device_id *id,
762 return true; 767 return true;
763} 768}
764 769
765static const struct acpi_device_id *__acpi_match_device( 770static bool __acpi_match_device(struct acpi_device *device,
766 struct acpi_device *device, 771 const struct acpi_device_id *acpi_ids,
767 const struct acpi_device_id *ids, 772 const struct of_device_id *of_ids,
768 const struct of_device_id *of_ids) 773 const struct acpi_device_id **acpi_id,
774 const struct of_device_id **of_id)
769{ 775{
770 const struct acpi_device_id *id; 776 const struct acpi_device_id *id;
771 struct acpi_hardware_id *hwid; 777 struct acpi_hardware_id *hwid;
@@ -775,30 +781,32 @@ static const struct acpi_device_id *__acpi_match_device(
775 * driver for it. 781 * driver for it.
776 */ 782 */
777 if (!device || !device->status.present) 783 if (!device || !device->status.present)
778 return NULL; 784 return false;
779 785
780 list_for_each_entry(hwid, &device->pnp.ids, list) { 786 list_for_each_entry(hwid, &device->pnp.ids, list) {
781 /* First, check the ACPI/PNP IDs provided by the caller. */ 787 /* First, check the ACPI/PNP IDs provided by the caller. */
782 for (id = ids; id->id[0] || id->cls; id++) { 788 if (acpi_ids) {
783 if (id->id[0] && !strcmp((char *) id->id, hwid->id)) 789 for (id = acpi_ids; id->id[0] || id->cls; id++) {
784 return id; 790 if (id->id[0] && !strcmp((char *)id->id, hwid->id))
785 else if (id->cls && __acpi_match_device_cls(id, hwid)) 791 goto out_acpi_match;
786 return id; 792 if (id->cls && __acpi_match_device_cls(id, hwid))
793 goto out_acpi_match;
794 }
787 } 795 }
788 796
789 /* 797 /*
790 * Next, check ACPI_DT_NAMESPACE_HID and try to match the 798 * Next, check ACPI_DT_NAMESPACE_HID and try to match the
791 * "compatible" property if found. 799 * "compatible" property if found.
792 *
793 * The id returned by the below is not valid, but the only
794 * caller passing non-NULL of_ids here is only interested in
795 * whether or not the return value is NULL.
796 */ 800 */
797 if (!strcmp(ACPI_DT_NAMESPACE_HID, hwid->id) 801 if (!strcmp(ACPI_DT_NAMESPACE_HID, hwid->id))
798 && acpi_of_match_device(device, of_ids)) 802 return acpi_of_match_device(device, of_ids, of_id);
799 return id;
800 } 803 }
801 return NULL; 804 return false;
805
806out_acpi_match:
807 if (acpi_id)
808 *acpi_id = id;
809 return true;
802} 810}
803 811
804/** 812/**
@@ -815,32 +823,29 @@ static const struct acpi_device_id *__acpi_match_device(
815const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids, 823const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
816 const struct device *dev) 824 const struct device *dev)
817{ 825{
818 return __acpi_match_device(acpi_companion_match(dev), ids, NULL); 826 const struct acpi_device_id *id = NULL;
827
828 __acpi_match_device(acpi_companion_match(dev), ids, NULL, &id, NULL);
829 return id;
819} 830}
820EXPORT_SYMBOL_GPL(acpi_match_device); 831EXPORT_SYMBOL_GPL(acpi_match_device);
821 832
822void *acpi_get_match_data(const struct device *dev) 833const void *acpi_device_get_match_data(const struct device *dev)
823{ 834{
824 const struct acpi_device_id *match; 835 const struct acpi_device_id *match;
825 836
826 if (!dev->driver)
827 return NULL;
828
829 if (!dev->driver->acpi_match_table)
830 return NULL;
831
832 match = acpi_match_device(dev->driver->acpi_match_table, dev); 837 match = acpi_match_device(dev->driver->acpi_match_table, dev);
833 if (!match) 838 if (!match)
834 return NULL; 839 return NULL;
835 840
836 return (void *)match->driver_data; 841 return (const void *)match->driver_data;
837} 842}
838EXPORT_SYMBOL_GPL(acpi_get_match_data); 843EXPORT_SYMBOL_GPL(acpi_device_get_match_data);
839 844
840int acpi_match_device_ids(struct acpi_device *device, 845int acpi_match_device_ids(struct acpi_device *device,
841 const struct acpi_device_id *ids) 846 const struct acpi_device_id *ids)
842{ 847{
843 return __acpi_match_device(device, ids, NULL) ? 0 : -ENOENT; 848 return __acpi_match_device(device, ids, NULL, NULL, NULL) ? 0 : -ENOENT;
844} 849}
845EXPORT_SYMBOL(acpi_match_device_ids); 850EXPORT_SYMBOL(acpi_match_device_ids);
846 851
@@ -849,10 +854,12 @@ bool acpi_driver_match_device(struct device *dev,
849{ 854{
850 if (!drv->acpi_match_table) 855 if (!drv->acpi_match_table)
851 return acpi_of_match_device(ACPI_COMPANION(dev), 856 return acpi_of_match_device(ACPI_COMPANION(dev),
852 drv->of_match_table); 857 drv->of_match_table,
858 NULL);
853 859
854 return !!__acpi_match_device(acpi_companion_match(dev), 860 return __acpi_match_device(acpi_companion_match(dev),
855 drv->acpi_match_table, drv->of_match_table); 861 drv->acpi_match_table, drv->of_match_table,
862 NULL, NULL);
856} 863}
857EXPORT_SYMBOL_GPL(acpi_driver_match_device); 864EXPORT_SYMBOL_GPL(acpi_driver_match_device);
858 865
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index d9f38c645e4a..30a572956557 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -1927,6 +1927,9 @@ static int acpi_ec_suspend_noirq(struct device *dev)
1927 ec->reference_count >= 1) 1927 ec->reference_count >= 1)
1928 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE); 1928 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
1929 1929
1930 if (acpi_sleep_no_ec_events())
1931 acpi_ec_enter_noirq(ec);
1932
1930 return 0; 1933 return 0;
1931} 1934}
1932 1935
@@ -1934,6 +1937,9 @@ static int acpi_ec_resume_noirq(struct device *dev)
1934{ 1937{
1935 struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev)); 1938 struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev));
1936 1939
1940 if (acpi_sleep_no_ec_events())
1941 acpi_ec_leave_noirq(ec);
1942
1937 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) && 1943 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) &&
1938 ec->reference_count >= 1) 1944 ec->reference_count >= 1)
1939 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE); 1945 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index bbe48ad20886..eb09ef55c38a 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -2675,10 +2675,14 @@ static int acpi_nfit_register_region(struct acpi_nfit_desc *acpi_desc,
2675 else 2675 else
2676 ndr_desc->numa_node = NUMA_NO_NODE; 2676 ndr_desc->numa_node = NUMA_NO_NODE;
2677 2677
2678 if(acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_CACHE_FLUSH) 2678 /*
2679 * Persistence domain bits are hierarchical, if
2680 * ACPI_NFIT_CAPABILITY_CACHE_FLUSH is set then
2681 * ACPI_NFIT_CAPABILITY_MEM_FLUSH is implied.
2682 */
2683 if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_CACHE_FLUSH)
2679 set_bit(ND_REGION_PERSIST_CACHE, &ndr_desc->flags); 2684 set_bit(ND_REGION_PERSIST_CACHE, &ndr_desc->flags);
2680 2685 else if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_MEM_FLUSH)
2681 if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_MEM_FLUSH)
2682 set_bit(ND_REGION_PERSIST_MEMCTRL, &ndr_desc->flags); 2686 set_bit(ND_REGION_PERSIST_MEMCTRL, &ndr_desc->flags);
2683 2687
2684 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { 2688 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 8ccaae3550d2..85167603b9c9 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -103,25 +103,27 @@ int acpi_map_pxm_to_node(int pxm)
103 */ 103 */
104int acpi_map_pxm_to_online_node(int pxm) 104int acpi_map_pxm_to_online_node(int pxm)
105{ 105{
106 int node, n, dist, min_dist; 106 int node, min_node;
107 107
108 node = acpi_map_pxm_to_node(pxm); 108 node = acpi_map_pxm_to_node(pxm);
109 109
110 if (node == NUMA_NO_NODE) 110 if (node == NUMA_NO_NODE)
111 node = 0; 111 node = 0;
112 112
113 min_node = node;
113 if (!node_online(node)) { 114 if (!node_online(node)) {
114 min_dist = INT_MAX; 115 int min_dist = INT_MAX, dist, n;
116
115 for_each_online_node(n) { 117 for_each_online_node(n) {
116 dist = node_distance(node, n); 118 dist = node_distance(node, n);
117 if (dist < min_dist) { 119 if (dist < min_dist) {
118 min_dist = dist; 120 min_dist = dist;
119 node = n; 121 min_node = n;
120 } 122 }
121 } 123 }
122 } 124 }
123 125
124 return node; 126 return min_node;
125} 127}
126EXPORT_SYMBOL(acpi_map_pxm_to_online_node); 128EXPORT_SYMBOL(acpi_map_pxm_to_online_node);
127 129
diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 466d1503aba0..5815356ea6ad 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1271,11 +1271,11 @@ static int acpi_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
1271 return 0; 1271 return 0;
1272} 1272}
1273 1273
1274static void * 1274static const void *
1275acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode, 1275acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
1276 const struct device *dev) 1276 const struct device *dev)
1277{ 1277{
1278 return acpi_get_match_data(dev); 1278 return acpi_device_get_match_data(dev);
1279} 1279}
1280 1280
1281#define DECLARE_ACPI_FWNODE_OPS(ops) \ 1281#define DECLARE_ACPI_FWNODE_OPS(ops) \
diff --git a/drivers/acpi/spcr.c b/drivers/acpi/spcr.c
index 89e97d21a89c..9d52743080a4 100644
--- a/drivers/acpi/spcr.c
+++ b/drivers/acpi/spcr.c
@@ -115,6 +115,7 @@ int __init acpi_parse_spcr(bool enable_earlycon, bool enable_console)
115 table->serial_port.access_width))) { 115 table->serial_port.access_width))) {
116 default: 116 default:
117 pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n"); 117 pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n");
118 /* fall through */
118 case 8: 119 case 8:
119 iotype = "mmio"; 120 iotype = "mmio";
120 break; 121 break;
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 15e3d3c2260d..764b63a5aade 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -1991,8 +1991,14 @@ static void binder_send_failed_reply(struct binder_transaction *t,
1991 &target_thread->reply_error.work); 1991 &target_thread->reply_error.work);
1992 wake_up_interruptible(&target_thread->wait); 1992 wake_up_interruptible(&target_thread->wait);
1993 } else { 1993 } else {
1994 WARN(1, "Unexpected reply error: %u\n", 1994 /*
1995 target_thread->reply_error.cmd); 1995 * Cannot get here for normal operation, but
1996 * we can if multiple synchronous transactions
1997 * are sent without blocking for responses.
1998 * Just ignore the 2nd error in this case.
1999 */
2000 pr_warn("Unexpected reply error: %u\n",
2001 target_thread->reply_error.cmd);
1996 } 2002 }
1997 binder_inner_proc_unlock(target_thread->proc); 2003 binder_inner_proc_unlock(target_thread->proc);
1998 binder_thread_dec_tmpref(target_thread); 2004 binder_thread_dec_tmpref(target_thread);
@@ -2193,7 +2199,7 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
2193 int debug_id = buffer->debug_id; 2199 int debug_id = buffer->debug_id;
2194 2200
2195 binder_debug(BINDER_DEBUG_TRANSACTION, 2201 binder_debug(BINDER_DEBUG_TRANSACTION,
2196 "%d buffer release %d, size %zd-%zd, failed at %p\n", 2202 "%d buffer release %d, size %zd-%zd, failed at %pK\n",
2197 proc->pid, buffer->debug_id, 2203 proc->pid, buffer->debug_id,
2198 buffer->data_size, buffer->offsets_size, failed_at); 2204 buffer->data_size, buffer->offsets_size, failed_at);
2199 2205
@@ -3705,7 +3711,7 @@ static int binder_thread_write(struct binder_proc *proc,
3705 } 3711 }
3706 } 3712 }
3707 binder_debug(BINDER_DEBUG_DEAD_BINDER, 3713 binder_debug(BINDER_DEBUG_DEAD_BINDER,
3708 "%d:%d BC_DEAD_BINDER_DONE %016llx found %p\n", 3714 "%d:%d BC_DEAD_BINDER_DONE %016llx found %pK\n",
3709 proc->pid, thread->pid, (u64)cookie, 3715 proc->pid, thread->pid, (u64)cookie,
3710 death); 3716 death);
3711 if (death == NULL) { 3717 if (death == NULL) {
@@ -4376,6 +4382,15 @@ static int binder_thread_release(struct binder_proc *proc,
4376 4382
4377 binder_inner_proc_unlock(thread->proc); 4383 binder_inner_proc_unlock(thread->proc);
4378 4384
4385 /*
4386 * This is needed to avoid races between wake_up_poll() above and
4387 * and ep_remove_waitqueue() called for other reasons (eg the epoll file
4388 * descriptor being closed); ep_remove_waitqueue() holds an RCU read
4389 * lock, so we can be sure it's done after calling synchronize_rcu().
4390 */
4391 if (thread->looper & BINDER_LOOPER_STATE_POLL)
4392 synchronize_rcu();
4393
4379 if (send_reply) 4394 if (send_reply)
4380 binder_send_failed_reply(send_reply, BR_DEAD_REPLY); 4395 binder_send_failed_reply(send_reply, BR_DEAD_REPLY);
4381 binder_release_work(proc, &thread->todo); 4396 binder_release_work(proc, &thread->todo);
@@ -4391,6 +4406,8 @@ static __poll_t binder_poll(struct file *filp,
4391 bool wait_for_proc_work; 4406 bool wait_for_proc_work;
4392 4407
4393 thread = binder_get_thread(proc); 4408 thread = binder_get_thread(proc);
4409 if (!thread)
4410 return POLLERR;
4394 4411
4395 binder_inner_proc_lock(thread->proc); 4412 binder_inner_proc_lock(thread->proc);
4396 thread->looper |= BINDER_LOOPER_STATE_POLL; 4413 thread->looper |= BINDER_LOOPER_STATE_POLL;
@@ -5034,7 +5051,7 @@ static void print_binder_transaction_ilocked(struct seq_file *m,
5034 spin_lock(&t->lock); 5051 spin_lock(&t->lock);
5035 to_proc = t->to_proc; 5052 to_proc = t->to_proc;
5036 seq_printf(m, 5053 seq_printf(m,
5037 "%s %d: %p from %d:%d to %d:%d code %x flags %x pri %ld r%d", 5054 "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld r%d",
5038 prefix, t->debug_id, t, 5055 prefix, t->debug_id, t,
5039 t->from ? t->from->proc->pid : 0, 5056 t->from ? t->from->proc->pid : 0,
5040 t->from ? t->from->pid : 0, 5057 t->from ? t->from->pid : 0,
@@ -5058,7 +5075,7 @@ static void print_binder_transaction_ilocked(struct seq_file *m,
5058 } 5075 }
5059 if (buffer->target_node) 5076 if (buffer->target_node)
5060 seq_printf(m, " node %d", buffer->target_node->debug_id); 5077 seq_printf(m, " node %d", buffer->target_node->debug_id);
5061 seq_printf(m, " size %zd:%zd data %p\n", 5078 seq_printf(m, " size %zd:%zd data %pK\n",
5062 buffer->data_size, buffer->offsets_size, 5079 buffer->data_size, buffer->offsets_size,
5063 buffer->data); 5080 buffer->data);
5064} 5081}
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 355a95a83a34..1ff17799769d 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -550,7 +550,9 @@ static const struct pci_device_id ahci_pci_tbl[] = {
550 .driver_data = board_ahci_yes_fbs }, 550 .driver_data = board_ahci_yes_fbs },
551 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9230), 551 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9230),
552 .driver_data = board_ahci_yes_fbs }, 552 .driver_data = board_ahci_yes_fbs },
553 { PCI_DEVICE(PCI_VENDOR_ID_TTI, 0x0642), 553 { PCI_DEVICE(PCI_VENDOR_ID_TTI, 0x0642), /* highpoint rocketraid 642L */
554 .driver_data = board_ahci_yes_fbs },
555 { PCI_DEVICE(PCI_VENDOR_ID_TTI, 0x0645), /* highpoint rocketraid 644L */
554 .driver_data = board_ahci_yes_fbs }, 556 .driver_data = board_ahci_yes_fbs },
555 557
556 /* Promise */ 558 /* Promise */
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index a0de7a38430c..7adcf3caabd0 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -665,6 +665,16 @@ int ahci_stop_engine(struct ata_port *ap)
665 if ((tmp & (PORT_CMD_START | PORT_CMD_LIST_ON)) == 0) 665 if ((tmp & (PORT_CMD_START | PORT_CMD_LIST_ON)) == 0)
666 return 0; 666 return 0;
667 667
668 /*
669 * Don't try to issue commands but return with ENODEV if the
670 * AHCI controller not available anymore (e.g. due to PCIe hot
671 * unplugging). Otherwise a 500ms delay for each port is added.
672 */
673 if (tmp == 0xffffffff) {
674 dev_err(ap->host->dev, "AHCI controller unavailable!\n");
675 return -ENODEV;
676 }
677
668 /* setting HBA to idle */ 678 /* setting HBA to idle */
669 tmp &= ~PORT_CMD_START; 679 tmp &= ~PORT_CMD_START;
670 writel(tmp, port_mmio + PORT_CMD); 680 writel(tmp, port_mmio + PORT_CMD);
diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
index 341d0ef82cbd..30cc8f1a31e1 100644
--- a/drivers/ata/libahci_platform.c
+++ b/drivers/ata/libahci_platform.c
@@ -340,7 +340,7 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port,
340 * 2) regulator for controlling the targets power (optional) 340 * 2) regulator for controlling the targets power (optional)
341 * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node, 341 * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
342 * or for non devicetree enabled platforms a single clock 342 * or for non devicetree enabled platforms a single clock
343 * 4) phys (optional) 343 * 4) phys (optional)
344 * 344 *
345 * RETURNS: 345 * RETURNS:
346 * The allocated ahci_host_priv on success, otherwise an ERR_PTR value 346 * The allocated ahci_host_priv on success, otherwise an ERR_PTR value
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 3c09122bf038..7431ccd03316 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4530,6 +4530,25 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4530 { "PIONEER DVD-RW DVR-212D", NULL, ATA_HORKAGE_NOSETXFER }, 4530 { "PIONEER DVD-RW DVR-212D", NULL, ATA_HORKAGE_NOSETXFER },
4531 { "PIONEER DVD-RW DVR-216D", NULL, ATA_HORKAGE_NOSETXFER }, 4531 { "PIONEER DVD-RW DVR-216D", NULL, ATA_HORKAGE_NOSETXFER },
4532 4532
4533 /* Crucial BX100 SSD 500GB has broken LPM support */
4534 { "CT500BX100SSD1", NULL, ATA_HORKAGE_NOLPM },
4535
4536 /* 512GB MX100 with MU01 firmware has both queued TRIM and LPM issues */
4537 { "Crucial_CT512MX100*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM |
4538 ATA_HORKAGE_ZERO_AFTER_TRIM |
4539 ATA_HORKAGE_NOLPM, },
4540 /* 512GB MX100 with newer firmware has only LPM issues */
4541 { "Crucial_CT512MX100*", NULL, ATA_HORKAGE_ZERO_AFTER_TRIM |
4542 ATA_HORKAGE_NOLPM, },
4543
4544 /* 480GB+ M500 SSDs have both queued TRIM and LPM issues */
4545 { "Crucial_CT480M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
4546 ATA_HORKAGE_ZERO_AFTER_TRIM |
4547 ATA_HORKAGE_NOLPM, },
4548 { "Crucial_CT960M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
4549 ATA_HORKAGE_ZERO_AFTER_TRIM |
4550 ATA_HORKAGE_NOLPM, },
4551
4533 /* devices that don't properly handle queued TRIM commands */ 4552 /* devices that don't properly handle queued TRIM commands */
4534 { "Micron_M500_*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | 4553 { "Micron_M500_*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
4535 ATA_HORKAGE_ZERO_AFTER_TRIM, }, 4554 ATA_HORKAGE_ZERO_AFTER_TRIM, },
@@ -4541,7 +4560,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4541 ATA_HORKAGE_ZERO_AFTER_TRIM, }, 4560 ATA_HORKAGE_ZERO_AFTER_TRIM, },
4542 { "Crucial_CT*MX100*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM | 4561 { "Crucial_CT*MX100*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM |
4543 ATA_HORKAGE_ZERO_AFTER_TRIM, }, 4562 ATA_HORKAGE_ZERO_AFTER_TRIM, },
4544 { "Samsung SSD 8*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | 4563 { "Samsung SSD 840*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
4564 ATA_HORKAGE_ZERO_AFTER_TRIM, },
4565 { "Samsung SSD 850*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
4545 ATA_HORKAGE_ZERO_AFTER_TRIM, }, 4566 ATA_HORKAGE_ZERO_AFTER_TRIM, },
4546 { "FCCT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | 4567 { "FCCT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
4547 ATA_HORKAGE_ZERO_AFTER_TRIM, }, 4568 ATA_HORKAGE_ZERO_AFTER_TRIM, },
@@ -5401,8 +5422,7 @@ void ata_qc_issue(struct ata_queued_cmd *qc)
5401 * We guarantee to LLDs that they will have at least one 5422 * We guarantee to LLDs that they will have at least one
5402 * non-zero sg if the command is a data command. 5423 * non-zero sg if the command is a data command.
5403 */ 5424 */
5404 if (WARN_ON_ONCE(ata_is_data(prot) && 5425 if (ata_is_data(prot) && (!qc->sg || !qc->n_elem || !qc->nbytes))
5405 (!qc->sg || !qc->n_elem || !qc->nbytes)))
5406 goto sys_err; 5426 goto sys_err;
5407 5427
5408 if (ata_is_dma(prot) || (ata_is_pio(prot) && 5428 if (ata_is_dma(prot) || (ata_is_pio(prot) &&
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 11c3137d7b0a..c016829a38fd 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -815,7 +815,8 @@ void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap)
815 815
816 if (ap->pflags & ATA_PFLAG_LOADING) 816 if (ap->pflags & ATA_PFLAG_LOADING)
817 ap->pflags &= ~ATA_PFLAG_LOADING; 817 ap->pflags &= ~ATA_PFLAG_LOADING;
818 else if (ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) 818 else if ((ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) &&
819 !(ap->flags & ATA_FLAG_SAS_HOST))
819 schedule_delayed_work(&ap->hotplug_task, 0); 820 schedule_delayed_work(&ap->hotplug_task, 0);
820 821
821 if (ap->pflags & ATA_PFLAG_RECOVERED) 822 if (ap->pflags & ATA_PFLAG_RECOVERED)
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 66be961c93a4..89a9d4a2efc8 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3316,6 +3316,12 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
3316 goto invalid_fld; 3316 goto invalid_fld;
3317 } 3317 }
3318 3318
3319 /* We may not issue NCQ commands to devices not supporting NCQ */
3320 if (ata_is_ncq(tf->protocol) && !ata_ncq_enabled(dev)) {
3321 fp = 1;
3322 goto invalid_fld;
3323 }
3324
3319 /* sanity check for pio multi commands */ 3325 /* sanity check for pio multi commands */
3320 if ((cdb[1] & 0xe0) && !is_multi_taskfile(tf)) { 3326 if ((cdb[1] & 0xe0) && !is_multi_taskfile(tf)) {
3321 fp = 1; 3327 fp = 1;
@@ -4282,7 +4288,7 @@ static inline void ata_scsi_dump_cdb(struct ata_port *ap,
4282#ifdef ATA_DEBUG 4288#ifdef ATA_DEBUG
4283 struct scsi_device *scsidev = cmd->device; 4289 struct scsi_device *scsidev = cmd->device;
4284 4290
4285 DPRINTK("CDB (%u:%d,%d,%d) %9ph\n", 4291 DPRINTK("CDB (%u:%d,%d,%lld) %9ph\n",
4286 ap->print_id, 4292 ap->print_id,
4287 scsidev->channel, scsidev->id, scsidev->lun, 4293 scsidev->channel, scsidev->id, scsidev->lun,
4288 cmd->cmnd); 4294 cmd->cmnd);
@@ -4309,7 +4315,9 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
4309 if (likely((scsi_op != ATA_16) || !atapi_passthru16)) { 4315 if (likely((scsi_op != ATA_16) || !atapi_passthru16)) {
4310 /* relay SCSI command to ATAPI device */ 4316 /* relay SCSI command to ATAPI device */
4311 int len = COMMAND_SIZE(scsi_op); 4317 int len = COMMAND_SIZE(scsi_op);
4312 if (unlikely(len > scmd->cmd_len || len > dev->cdb_len)) 4318 if (unlikely(len > scmd->cmd_len ||
4319 len > dev->cdb_len ||
4320 scmd->cmd_len > ATAPI_CDB_LEN))
4313 goto bad_cdb_len; 4321 goto bad_cdb_len;
4314 4322
4315 xlat_func = atapi_xlat; 4323 xlat_func = atapi_xlat;
diff --git a/drivers/ata/sata_rcar.c b/drivers/ata/sata_rcar.c
index 80ee2f2a50d0..6456e07db72a 100644
--- a/drivers/ata/sata_rcar.c
+++ b/drivers/ata/sata_rcar.c
@@ -146,6 +146,7 @@
146enum sata_rcar_type { 146enum sata_rcar_type {
147 RCAR_GEN1_SATA, 147 RCAR_GEN1_SATA,
148 RCAR_GEN2_SATA, 148 RCAR_GEN2_SATA,
149 RCAR_GEN3_SATA,
149 RCAR_R8A7790_ES1_SATA, 150 RCAR_R8A7790_ES1_SATA,
150}; 151};
151 152
@@ -784,26 +785,11 @@ static void sata_rcar_setup_port(struct ata_host *host)
784 ioaddr->command_addr = ioaddr->cmd_addr + (ATA_REG_CMD << 2); 785 ioaddr->command_addr = ioaddr->cmd_addr + (ATA_REG_CMD << 2);
785} 786}
786 787
787static void sata_rcar_init_controller(struct ata_host *host) 788static void sata_rcar_init_module(struct sata_rcar_priv *priv)
788{ 789{
789 struct sata_rcar_priv *priv = host->private_data;
790 void __iomem *base = priv->base; 790 void __iomem *base = priv->base;
791 u32 val; 791 u32 val;
792 792
793 /* reset and setup phy */
794 switch (priv->type) {
795 case RCAR_GEN1_SATA:
796 sata_rcar_gen1_phy_init(priv);
797 break;
798 case RCAR_GEN2_SATA:
799 case RCAR_R8A7790_ES1_SATA:
800 sata_rcar_gen2_phy_init(priv);
801 break;
802 default:
803 dev_warn(host->dev, "SATA phy is not initialized\n");
804 break;
805 }
806
807 /* SATA-IP reset state */ 793 /* SATA-IP reset state */
808 val = ioread32(base + ATAPI_CONTROL1_REG); 794 val = ioread32(base + ATAPI_CONTROL1_REG);
809 val |= ATAPI_CONTROL1_RESET; 795 val |= ATAPI_CONTROL1_RESET;
@@ -824,10 +810,33 @@ static void sata_rcar_init_controller(struct ata_host *host)
824 /* ack and mask */ 810 /* ack and mask */
825 iowrite32(0, base + SATAINTSTAT_REG); 811 iowrite32(0, base + SATAINTSTAT_REG);
826 iowrite32(0x7ff, base + SATAINTMASK_REG); 812 iowrite32(0x7ff, base + SATAINTMASK_REG);
813
827 /* enable interrupts */ 814 /* enable interrupts */
828 iowrite32(ATAPI_INT_ENABLE_SATAINT, base + ATAPI_INT_ENABLE_REG); 815 iowrite32(ATAPI_INT_ENABLE_SATAINT, base + ATAPI_INT_ENABLE_REG);
829} 816}
830 817
818static void sata_rcar_init_controller(struct ata_host *host)
819{
820 struct sata_rcar_priv *priv = host->private_data;
821
822 /* reset and setup phy */
823 switch (priv->type) {
824 case RCAR_GEN1_SATA:
825 sata_rcar_gen1_phy_init(priv);
826 break;
827 case RCAR_GEN2_SATA:
828 case RCAR_GEN3_SATA:
829 case RCAR_R8A7790_ES1_SATA:
830 sata_rcar_gen2_phy_init(priv);
831 break;
832 default:
833 dev_warn(host->dev, "SATA phy is not initialized\n");
834 break;
835 }
836
837 sata_rcar_init_module(priv);
838}
839
831static const struct of_device_id sata_rcar_match[] = { 840static const struct of_device_id sata_rcar_match[] = {
832 { 841 {
833 /* Deprecated by "renesas,sata-r8a7779" */ 842 /* Deprecated by "renesas,sata-r8a7779" */
@@ -856,7 +865,7 @@ static const struct of_device_id sata_rcar_match[] = {
856 }, 865 },
857 { 866 {
858 .compatible = "renesas,sata-r8a7795", 867 .compatible = "renesas,sata-r8a7795",
859 .data = (void *)RCAR_GEN2_SATA 868 .data = (void *)RCAR_GEN3_SATA
860 }, 869 },
861 { 870 {
862 .compatible = "renesas,rcar-gen2-sata", 871 .compatible = "renesas,rcar-gen2-sata",
@@ -864,7 +873,7 @@ static const struct of_device_id sata_rcar_match[] = {
864 }, 873 },
865 { 874 {
866 .compatible = "renesas,rcar-gen3-sata", 875 .compatible = "renesas,rcar-gen3-sata",
867 .data = (void *)RCAR_GEN2_SATA 876 .data = (void *)RCAR_GEN3_SATA
868 }, 877 },
869 { }, 878 { },
870}; 879};
@@ -982,11 +991,18 @@ static int sata_rcar_resume(struct device *dev)
982 if (ret) 991 if (ret)
983 return ret; 992 return ret;
984 993
985 /* ack and mask */ 994 if (priv->type == RCAR_GEN3_SATA) {
986 iowrite32(0, base + SATAINTSTAT_REG); 995 sata_rcar_gen2_phy_init(priv);
987 iowrite32(0x7ff, base + SATAINTMASK_REG); 996 sata_rcar_init_module(priv);
988 /* enable interrupts */ 997 } else {
989 iowrite32(ATAPI_INT_ENABLE_SATAINT, base + ATAPI_INT_ENABLE_REG); 998 /* ack and mask */
999 iowrite32(0, base + SATAINTSTAT_REG);
1000 iowrite32(0x7ff, base + SATAINTMASK_REG);
1001
1002 /* enable interrupts */
1003 iowrite32(ATAPI_INT_ENABLE_SATAINT,
1004 base + ATAPI_INT_ENABLE_REG);
1005 }
990 1006
991 ata_host_resume(host); 1007 ata_host_resume(host);
992 1008
diff --git a/drivers/auxdisplay/img-ascii-lcd.c b/drivers/auxdisplay/img-ascii-lcd.c
index 9180b9bd5821..834509506ef6 100644
--- a/drivers/auxdisplay/img-ascii-lcd.c
+++ b/drivers/auxdisplay/img-ascii-lcd.c
@@ -97,7 +97,7 @@ static struct img_ascii_lcd_config boston_config = {
97static void malta_update(struct img_ascii_lcd_ctx *ctx) 97static void malta_update(struct img_ascii_lcd_ctx *ctx)
98{ 98{
99 unsigned int i; 99 unsigned int i;
100 int err; 100 int err = 0;
101 101
102 for (i = 0; i < ctx->cfg->num_chars; i++) { 102 for (i = 0; i < ctx->cfg->num_chars; i++) {
103 err = regmap_write(ctx->regmap, 103 err = regmap_write(ctx->regmap,
@@ -180,7 +180,7 @@ static int sead3_wait_lcd_idle(struct img_ascii_lcd_ctx *ctx)
180static void sead3_update(struct img_ascii_lcd_ctx *ctx) 180static void sead3_update(struct img_ascii_lcd_ctx *ctx)
181{ 181{
182 unsigned int i; 182 unsigned int i;
183 int err; 183 int err = 0;
184 184
185 for (i = 0; i < ctx->cfg->num_chars; i++) { 185 for (i = 0; i < ctx->cfg->num_chars; i++) {
186 err = sead3_wait_lcd_idle(ctx); 186 err = sead3_wait_lcd_idle(ctx);
@@ -224,7 +224,7 @@ MODULE_DEVICE_TABLE(of, img_ascii_lcd_matches);
224 224
225/** 225/**
226 * img_ascii_lcd_scroll() - scroll the display by a character 226 * img_ascii_lcd_scroll() - scroll the display by a character
227 * @arg: really a pointer to the private data structure 227 * @t: really a pointer to the private data structure
228 * 228 *
229 * Scroll the current message along the LCD by one character, rearming the 229 * Scroll the current message along the LCD by one character, rearming the
230 * timer if required. 230 * timer if required.
diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c
index ea7869c0d7f9..ec5e8800f8ad 100644
--- a/drivers/auxdisplay/panel.c
+++ b/drivers/auxdisplay/panel.c
@@ -1372,7 +1372,7 @@ static void panel_process_inputs(void)
1372 break; 1372 break;
1373 input->rise_timer = 0; 1373 input->rise_timer = 0;
1374 input->state = INPUT_ST_RISING; 1374 input->state = INPUT_ST_RISING;
1375 /* no break here, fall through */ 1375 /* fall through */
1376 case INPUT_ST_RISING: 1376 case INPUT_ST_RISING:
1377 if ((phys_curr & input->mask) != input->value) { 1377 if ((phys_curr & input->mask) != input->value) {
1378 input->state = INPUT_ST_LOW; 1378 input->state = INPUT_ST_LOW;
@@ -1385,11 +1385,11 @@ static void panel_process_inputs(void)
1385 } 1385 }
1386 input->high_timer = 0; 1386 input->high_timer = 0;
1387 input->state = INPUT_ST_HIGH; 1387 input->state = INPUT_ST_HIGH;
1388 /* no break here, fall through */ 1388 /* fall through */
1389 case INPUT_ST_HIGH: 1389 case INPUT_ST_HIGH:
1390 if (input_state_high(input)) 1390 if (input_state_high(input))
1391 break; 1391 break;
1392 /* no break here, fall through */ 1392 /* fall through */
1393 case INPUT_ST_FALLING: 1393 case INPUT_ST_FALLING:
1394 input_state_falling(input); 1394 input_state_falling(input);
1395 } 1395 }
diff --git a/drivers/base/core.c b/drivers/base/core.c
index b2261f92f2f1..5847364f25d9 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -310,6 +310,9 @@ static void __device_link_del(struct device_link *link)
310 dev_info(link->consumer, "Dropping the link to %s\n", 310 dev_info(link->consumer, "Dropping the link to %s\n",
311 dev_name(link->supplier)); 311 dev_name(link->supplier));
312 312
313 if (link->flags & DL_FLAG_PM_RUNTIME)
314 pm_runtime_drop_link(link->consumer);
315
313 list_del(&link->s_node); 316 list_del(&link->s_node);
314 list_del(&link->c_node); 317 list_del(&link->c_node);
315 device_link_free(link); 318 device_link_free(link);
diff --git a/drivers/base/power/wakeirq.c b/drivers/base/power/wakeirq.c
index a8ac86e4d79e..6637fc319269 100644
--- a/drivers/base/power/wakeirq.c
+++ b/drivers/base/power/wakeirq.c
@@ -321,7 +321,8 @@ void dev_pm_arm_wake_irq(struct wake_irq *wirq)
321 return; 321 return;
322 322
323 if (device_may_wakeup(wirq->dev)) { 323 if (device_may_wakeup(wirq->dev)) {
324 if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED) 324 if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED &&
325 !pm_runtime_status_suspended(wirq->dev))
325 enable_irq(wirq->irq); 326 enable_irq(wirq->irq);
326 327
327 enable_irq_wake(wirq->irq); 328 enable_irq_wake(wirq->irq);
@@ -343,7 +344,8 @@ void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
343 if (device_may_wakeup(wirq->dev)) { 344 if (device_may_wakeup(wirq->dev)) {
344 disable_irq_wake(wirq->irq); 345 disable_irq_wake(wirq->irq);
345 346
346 if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED) 347 if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED &&
348 !pm_runtime_status_suspended(wirq->dev))
347 disable_irq_nosync(wirq->irq); 349 disable_irq_nosync(wirq->irq);
348 } 350 }
349} 351}
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 302236281d83..8f205f6461ed 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1410,9 +1410,8 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
1410} 1410}
1411EXPORT_SYMBOL(fwnode_graph_parse_endpoint); 1411EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
1412 1412
1413void *device_get_match_data(struct device *dev) 1413const void *device_get_match_data(struct device *dev)
1414{ 1414{
1415 return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, 1415 return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
1416 dev);
1417} 1416}
1418EXPORT_SYMBOL_GPL(device_get_match_data); 1417EXPORT_SYMBOL_GPL(device_get_match_data);
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index e5aa62fcf5a8..3aaf6af3ec23 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -1758,7 +1758,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data)
1758 if (unit[drive].type->code == FD_NODRIVE) 1758 if (unit[drive].type->code == FD_NODRIVE)
1759 return NULL; 1759 return NULL;
1760 *part = 0; 1760 *part = 0;
1761 return get_disk(unit[drive].gendisk); 1761 return get_disk_and_module(unit[drive].gendisk);
1762} 1762}
1763 1763
1764static int __init amiga_floppy_probe(struct platform_device *pdev) 1764static int __init amiga_floppy_probe(struct platform_device *pdev)
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 8bc3b9fd8dd2..dfb2c2622e5a 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1917,7 +1917,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data)
1917 if (drive >= FD_MAX_UNITS || type > NUM_DISK_MINORS) 1917 if (drive >= FD_MAX_UNITS || type > NUM_DISK_MINORS)
1918 return NULL; 1918 return NULL;
1919 *part = 0; 1919 *part = 0;
1920 return get_disk(unit[drive].disk); 1920 return get_disk_and_module(unit[drive].disk);
1921} 1921}
1922 1922
1923static int __init atari_floppy_init (void) 1923static int __init atari_floppy_init (void)
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 8028a3a7e7fd..deea78e485da 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -456,7 +456,7 @@ static struct kobject *brd_probe(dev_t dev, int *part, void *data)
456 456
457 mutex_lock(&brd_devices_mutex); 457 mutex_lock(&brd_devices_mutex);
458 brd = brd_init_one(MINOR(dev) / max_part, &new); 458 brd = brd_init_one(MINOR(dev) / max_part, &new);
459 kobj = brd ? get_disk(brd->brd_disk) : NULL; 459 kobj = brd ? get_disk_and_module(brd->brd_disk) : NULL;
460 mutex_unlock(&brd_devices_mutex); 460 mutex_unlock(&brd_devices_mutex);
461 461
462 if (new) 462 if (new)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index eae484acfbbc..8ec7235fc93b 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4505,7 +4505,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data)
4505 if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type)) 4505 if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type))
4506 return NULL; 4506 return NULL;
4507 *part = 0; 4507 *part = 0;
4508 return get_disk(disks[drive]); 4508 return get_disk_and_module(disks[drive]);
4509} 4509}
4510 4510
4511static int __init do_floppy_init(void) 4511static int __init do_floppy_init(void)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index d5fe720cf149..ee62d2d517bf 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -266,7 +266,7 @@ static int lo_write_bvec(struct file *file, struct bio_vec *bvec, loff_t *ppos)
266 struct iov_iter i; 266 struct iov_iter i;
267 ssize_t bw; 267 ssize_t bw;
268 268
269 iov_iter_bvec(&i, ITER_BVEC, bvec, 1, bvec->bv_len); 269 iov_iter_bvec(&i, ITER_BVEC | WRITE, bvec, 1, bvec->bv_len);
270 270
271 file_start_write(file); 271 file_start_write(file);
272 bw = vfs_iter_write(file, &i, ppos, 0); 272 bw = vfs_iter_write(file, &i, ppos, 0);
@@ -1922,7 +1922,7 @@ static struct kobject *loop_probe(dev_t dev, int *part, void *data)
1922 if (err < 0) 1922 if (err < 0)
1923 kobj = NULL; 1923 kobj = NULL;
1924 else 1924 else
1925 kobj = get_disk(lo->lo_disk); 1925 kobj = get_disk_and_module(lo->lo_disk);
1926 mutex_unlock(&loop_index_mutex); 1926 mutex_unlock(&loop_index_mutex);
1927 1927
1928 *part = 0; 1928 *part = 0;
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 5f2a4240a204..86258b00a1d4 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1591,7 +1591,7 @@ again:
1591 if (new_index < 0) { 1591 if (new_index < 0) {
1592 mutex_unlock(&nbd_index_mutex); 1592 mutex_unlock(&nbd_index_mutex);
1593 printk(KERN_ERR "nbd: failed to add new device\n"); 1593 printk(KERN_ERR "nbd: failed to add new device\n");
1594 return ret; 1594 return new_index;
1595 } 1595 }
1596 nbd = idr_find(&nbd_index_idr, new_index); 1596 nbd = idr_find(&nbd_index_idr, new_index);
1597 } 1597 }
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 531a0915066b..c61d20c9f3f8 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -1122,7 +1122,7 @@ static int pkt_start_recovery(struct packet_data *pkt)
1122 pkt->sector = new_sector; 1122 pkt->sector = new_sector;
1123 1123
1124 bio_reset(pkt->bio); 1124 bio_reset(pkt->bio);
1125 bio_set_set(pkt->bio, pd->bdev); 1125 bio_set_dev(pkt->bio, pd->bdev);
1126 bio_set_op_attrs(pkt->bio, REQ_OP_WRITE, 0); 1126 bio_set_op_attrs(pkt->bio, REQ_OP_WRITE, 0);
1127 pkt->bio->bi_iter.bi_sector = new_sector; 1127 pkt->bio->bi_iter.bi_sector = new_sector;
1128 pkt->bio->bi_iter.bi_size = pkt->frames * CD_FRAMESIZE; 1128 pkt->bio->bi_iter.bi_size = pkt->frames * CD_FRAMESIZE;
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 84434d3ea19b..64e066eba72e 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -799,7 +799,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data)
799 return NULL; 799 return NULL;
800 800
801 *part = 0; 801 *part = 0;
802 return get_disk(swd->unit[drive].disk); 802 return get_disk_and_module(swd->unit[drive].disk);
803} 803}
804 804
805static int swim_add_floppy(struct swim_priv *swd, enum drive_location location) 805static int swim_add_floppy(struct swim_priv *swd, enum drive_location location)
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index e126e4cac2ca..92ec1bbece51 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -262,6 +262,7 @@ static DEFINE_SPINLOCK(minor_lock);
262 262
263static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo); 263static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo);
264static void blkfront_gather_backend_features(struct blkfront_info *info); 264static void blkfront_gather_backend_features(struct blkfront_info *info);
265static int negotiate_mq(struct blkfront_info *info);
265 266
266static int get_id_from_freelist(struct blkfront_ring_info *rinfo) 267static int get_id_from_freelist(struct blkfront_ring_info *rinfo)
267{ 268{
@@ -1774,11 +1775,18 @@ static int talk_to_blkback(struct xenbus_device *dev,
1774 unsigned int i, max_page_order; 1775 unsigned int i, max_page_order;
1775 unsigned int ring_page_order; 1776 unsigned int ring_page_order;
1776 1777
1778 if (!info)
1779 return -ENODEV;
1780
1777 max_page_order = xenbus_read_unsigned(info->xbdev->otherend, 1781 max_page_order = xenbus_read_unsigned(info->xbdev->otherend,
1778 "max-ring-page-order", 0); 1782 "max-ring-page-order", 0);
1779 ring_page_order = min(xen_blkif_max_ring_order, max_page_order); 1783 ring_page_order = min(xen_blkif_max_ring_order, max_page_order);
1780 info->nr_ring_pages = 1 << ring_page_order; 1784 info->nr_ring_pages = 1 << ring_page_order;
1781 1785
1786 err = negotiate_mq(info);
1787 if (err)
1788 goto destroy_blkring;
1789
1782 for (i = 0; i < info->nr_rings; i++) { 1790 for (i = 0; i < info->nr_rings; i++) {
1783 struct blkfront_ring_info *rinfo = &info->rinfo[i]; 1791 struct blkfront_ring_info *rinfo = &info->rinfo[i];
1784 1792
@@ -1978,11 +1986,6 @@ static int blkfront_probe(struct xenbus_device *dev,
1978 } 1986 }
1979 1987
1980 info->xbdev = dev; 1988 info->xbdev = dev;
1981 err = negotiate_mq(info);
1982 if (err) {
1983 kfree(info);
1984 return err;
1985 }
1986 1989
1987 mutex_init(&info->mutex); 1990 mutex_init(&info->mutex);
1988 info->vdevice = vdevice; 1991 info->vdevice = vdevice;
@@ -2099,10 +2102,6 @@ static int blkfront_resume(struct xenbus_device *dev)
2099 2102
2100 blkif_free(info, info->connected == BLKIF_STATE_CONNECTED); 2103 blkif_free(info, info->connected == BLKIF_STATE_CONNECTED);
2101 2104
2102 err = negotiate_mq(info);
2103 if (err)
2104 return err;
2105
2106 err = talk_to_blkback(dev, info); 2105 err = talk_to_blkback(dev, info);
2107 if (!err) 2106 if (!err)
2108 blk_mq_update_nr_hw_queues(&info->tag_set, info->nr_rings); 2107 blk_mq_update_nr_hw_queues(&info->tag_set, info->nr_rings);
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index 41c95c9b2ab4..8f9130ab5887 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -332,7 +332,7 @@ static const struct block_device_operations z2_fops =
332static struct kobject *z2_find(dev_t dev, int *part, void *data) 332static struct kobject *z2_find(dev_t dev, int *part, void *data)
333{ 333{
334 *part = 0; 334 *part = 0;
335 return get_disk(z2ram_gendisk); 335 return get_disk_and_module(z2ram_gendisk);
336} 336}
337 337
338static struct request_queue *z2_queue; 338static struct request_queue *z2_queue;
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 2a55380ad730..366a49c7c08f 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -21,6 +21,7 @@
21 * 21 *
22 */ 22 */
23 23
24#include <linux/dmi.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/usb.h> 26#include <linux/usb.h>
26#include <linux/usb/quirks.h> 27#include <linux/usb/quirks.h>
@@ -230,7 +231,6 @@ static const struct usb_device_id blacklist_table[] = {
230 { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 }, 231 { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 },
231 { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 }, 232 { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 },
232 { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 }, 233 { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 },
233 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
234 { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 }, 234 { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
235 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 }, 235 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
236 { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 }, 236 { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 },
@@ -263,6 +263,7 @@ static const struct usb_device_id blacklist_table[] = {
263 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, 263 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
264 264
265 /* QCA ROME chipset */ 265 /* QCA ROME chipset */
266 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_QCA_ROME },
266 { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME }, 267 { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME },
267 { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME }, 268 { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME },
268 { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME }, 269 { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME },
@@ -379,6 +380,21 @@ static const struct usb_device_id blacklist_table[] = {
379 { } /* Terminating entry */ 380 { } /* Terminating entry */
380}; 381};
381 382
383/* The Bluetooth USB module build into some devices needs to be reset on resume,
384 * this is a problem with the platform (likely shutting off all power) not with
385 * the module itself. So we use a DMI list to match known broken platforms.
386 */
387static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
388 {
389 /* Dell OptiPlex 3060 (QCA ROME device 0cf3:e007) */
390 .matches = {
391 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
392 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 3060"),
393 },
394 },
395 {}
396};
397
382#define BTUSB_MAX_ISOC_FRAMES 10 398#define BTUSB_MAX_ISOC_FRAMES 10
383 399
384#define BTUSB_INTR_RUNNING 0 400#define BTUSB_INTR_RUNNING 0
@@ -2945,6 +2961,9 @@ static int btusb_probe(struct usb_interface *intf,
2945 hdev->send = btusb_send_frame; 2961 hdev->send = btusb_send_frame;
2946 hdev->notify = btusb_notify; 2962 hdev->notify = btusb_notify;
2947 2963
2964 if (dmi_check_system(btusb_needs_reset_resume_table))
2965 interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME;
2966
2948#ifdef CONFIG_PM 2967#ifdef CONFIG_PM
2949 err = btusb_config_oob_wake(hdev); 2968 err = btusb_config_oob_wake(hdev);
2950 if (err) 2969 if (err)
@@ -3031,12 +3050,6 @@ static int btusb_probe(struct usb_interface *intf,
3031 if (id->driver_info & BTUSB_QCA_ROME) { 3050 if (id->driver_info & BTUSB_QCA_ROME) {
3032 data->setup_on_usb = btusb_setup_qca; 3051 data->setup_on_usb = btusb_setup_qca;
3033 hdev->set_bdaddr = btusb_set_bdaddr_ath3012; 3052 hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
3034
3035 /* QCA Rome devices lose their updated firmware over suspend,
3036 * but the USB hub doesn't notice any status change.
3037 * explicitly request a device reset on resume.
3038 */
3039 interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME;
3040 } 3053 }
3041 3054
3042#ifdef CONFIG_BT_HCIBTUSB_RTL 3055#ifdef CONFIG_BT_HCIBTUSB_RTL
diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 0438a64b8185..40b9fb247010 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -244,7 +244,9 @@ static irqreturn_t bcm_host_wake(int irq, void *data)
244 244
245 bt_dev_dbg(bdev, "Host wake IRQ"); 245 bt_dev_dbg(bdev, "Host wake IRQ");
246 246
247 pm_request_resume(bdev->dev); 247 pm_runtime_get(bdev->dev);
248 pm_runtime_mark_last_busy(bdev->dev);
249 pm_runtime_put_autosuspend(bdev->dev);
248 250
249 return IRQ_HANDLED; 251 return IRQ_HANDLED;
250} 252}
@@ -301,7 +303,7 @@ static const struct bcm_set_sleep_mode default_sleep_params = {
301 .usb_auto_sleep = 0, 303 .usb_auto_sleep = 0,
302 .usb_resume_timeout = 0, 304 .usb_resume_timeout = 0,
303 .break_to_host = 0, 305 .break_to_host = 0,
304 .pulsed_host_wake = 0, 306 .pulsed_host_wake = 1,
305}; 307};
306 308
307static int bcm_setup_sleep(struct hci_uart *hu) 309static int bcm_setup_sleep(struct hci_uart *hu)
@@ -586,8 +588,11 @@ static int bcm_recv(struct hci_uart *hu, const void *data, int count)
586 } else if (!bcm->rx_skb) { 588 } else if (!bcm->rx_skb) {
587 /* Delay auto-suspend when receiving completed packet */ 589 /* Delay auto-suspend when receiving completed packet */
588 mutex_lock(&bcm_device_lock); 590 mutex_lock(&bcm_device_lock);
589 if (bcm->dev && bcm_device_exists(bcm->dev)) 591 if (bcm->dev && bcm_device_exists(bcm->dev)) {
590 pm_request_resume(bcm->dev->dev); 592 pm_runtime_get(bcm->dev->dev);
593 pm_runtime_mark_last_busy(bcm->dev->dev);
594 pm_runtime_put_autosuspend(bcm->dev->dev);
595 }
591 mutex_unlock(&bcm_device_lock); 596 mutex_unlock(&bcm_device_lock);
592 } 597 }
593 598
@@ -922,12 +927,13 @@ static int bcm_get_resources(struct bcm_device *dev)
922 927
923 dev->clk = devm_clk_get(dev->dev, NULL); 928 dev->clk = devm_clk_get(dev->dev, NULL);
924 929
925 dev->device_wakeup = devm_gpiod_get(dev->dev, "device-wakeup", 930 dev->device_wakeup = devm_gpiod_get_optional(dev->dev, "device-wakeup",
926 GPIOD_OUT_LOW); 931 GPIOD_OUT_LOW);
927 if (IS_ERR(dev->device_wakeup)) 932 if (IS_ERR(dev->device_wakeup))
928 return PTR_ERR(dev->device_wakeup); 933 return PTR_ERR(dev->device_wakeup);
929 934
930 dev->shutdown = devm_gpiod_get(dev->dev, "shutdown", GPIOD_OUT_LOW); 935 dev->shutdown = devm_gpiod_get_optional(dev->dev, "shutdown",
936 GPIOD_OUT_LOW);
931 if (IS_ERR(dev->shutdown)) 937 if (IS_ERR(dev->shutdown))
932 return PTR_ERR(dev->shutdown); 938 return PTR_ERR(dev->shutdown);
933 939
diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c
index 4d46003c46cf..cdaeeea7999c 100644
--- a/drivers/bus/ti-sysc.c
+++ b/drivers/bus/ti-sysc.c
@@ -630,7 +630,7 @@ static int sysc_init_dts_quirks(struct sysc *ddata)
630 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) { 630 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
631 prop = of_get_property(np, sysc_dts_quirks[i].name, &len); 631 prop = of_get_property(np, sysc_dts_quirks[i].name, &len);
632 if (!prop) 632 if (!prop)
633 break; 633 continue;
634 634
635 ddata->cfg.quirks |= sysc_dts_quirks[i].mask; 635 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
636 } 636 }
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index d1f5bb534e0e..6e9df558325b 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -162,7 +162,7 @@ static int via_rng_init(struct hwrng *rng)
162 /* Enable secondary noise source on CPUs where it is present. */ 162 /* Enable secondary noise source on CPUs where it is present. */
163 163
164 /* Nehemiah stepping 8 and higher */ 164 /* Nehemiah stepping 8 and higher */
165 if ((c->x86_model == 9) && (c->x86_mask > 7)) 165 if ((c->x86_model == 9) && (c->x86_stepping > 7))
166 lo |= VIA_NOISESRC2; 166 lo |= VIA_NOISESRC2;
167 167
168 /* Esther */ 168 /* Esther */
diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c
index 4d1dc8b46877..f95b9c75175b 100644
--- a/drivers/char/tpm/st33zp24/st33zp24.c
+++ b/drivers/char/tpm/st33zp24/st33zp24.c
@@ -457,7 +457,7 @@ static int st33zp24_recv(struct tpm_chip *chip, unsigned char *buf,
457 size_t count) 457 size_t count)
458{ 458{
459 int size = 0; 459 int size = 0;
460 int expected; 460 u32 expected;
461 461
462 if (!chip) 462 if (!chip)
463 return -EBUSY; 463 return -EBUSY;
@@ -474,7 +474,7 @@ static int st33zp24_recv(struct tpm_chip *chip, unsigned char *buf,
474 } 474 }
475 475
476 expected = be32_to_cpu(*(__be32 *)(buf + 2)); 476 expected = be32_to_cpu(*(__be32 *)(buf + 2));
477 if (expected > count) { 477 if (expected > count || expected < TPM_HEADER_SIZE) {
478 size = -EIO; 478 size = -EIO;
479 goto out; 479 goto out;
480 } 480 }
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 76df4fbcf089..9e80a953d693 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1190,6 +1190,10 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
1190 break; 1190 break;
1191 1191
1192 recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len); 1192 recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len);
1193 if (recd > num_bytes) {
1194 total = -EFAULT;
1195 break;
1196 }
1193 1197
1194 rlength = be32_to_cpu(tpm_cmd.header.out.length); 1198 rlength = be32_to_cpu(tpm_cmd.header.out.length);
1195 if (rlength < offsetof(struct tpm_getrandom_out, rng_data) + 1199 if (rlength < offsetof(struct tpm_getrandom_out, rng_data) +
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index c17e75348a99..a700f8f9ead7 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -683,6 +683,10 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
683 if (!rc) { 683 if (!rc) {
684 data_len = be16_to_cpup( 684 data_len = be16_to_cpup(
685 (__be16 *) &buf.data[TPM_HEADER_SIZE + 4]); 685 (__be16 *) &buf.data[TPM_HEADER_SIZE + 4]);
686 if (data_len < MIN_KEY_SIZE || data_len > MAX_KEY_SIZE + 1) {
687 rc = -EFAULT;
688 goto out;
689 }
686 690
687 rlength = be32_to_cpu(((struct tpm2_cmd *)&buf) 691 rlength = be32_to_cpu(((struct tpm2_cmd *)&buf)
688 ->header.out.length); 692 ->header.out.length);
diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c
index c1dd39eaaeeb..6116cd05e228 100644
--- a/drivers/char/tpm/tpm_i2c_infineon.c
+++ b/drivers/char/tpm/tpm_i2c_infineon.c
@@ -473,7 +473,8 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
473static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count) 473static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count)
474{ 474{
475 int size = 0; 475 int size = 0;
476 int expected, status; 476 int status;
477 u32 expected;
477 478
478 if (count < TPM_HEADER_SIZE) { 479 if (count < TPM_HEADER_SIZE) {
479 size = -EIO; 480 size = -EIO;
@@ -488,7 +489,7 @@ static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count)
488 } 489 }
489 490
490 expected = be32_to_cpu(*(__be32 *)(buf + 2)); 491 expected = be32_to_cpu(*(__be32 *)(buf + 2));
491 if ((size_t) expected > count) { 492 if (((size_t) expected > count) || (expected < TPM_HEADER_SIZE)) {
492 size = -EIO; 493 size = -EIO;
493 goto out; 494 goto out;
494 } 495 }
diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c
index c6428771841f..caa86b19c76d 100644
--- a/drivers/char/tpm/tpm_i2c_nuvoton.c
+++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
@@ -281,7 +281,11 @@ static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count)
281 struct device *dev = chip->dev.parent; 281 struct device *dev = chip->dev.parent;
282 struct i2c_client *client = to_i2c_client(dev); 282 struct i2c_client *client = to_i2c_client(dev);
283 s32 rc; 283 s32 rc;
284 int expected, status, burst_count, retries, size = 0; 284 int status;
285 int burst_count;
286 int retries;
287 int size = 0;
288 u32 expected;
285 289
286 if (count < TPM_HEADER_SIZE) { 290 if (count < TPM_HEADER_SIZE) {
287 i2c_nuvoton_ready(chip); /* return to idle */ 291 i2c_nuvoton_ready(chip); /* return to idle */
@@ -323,7 +327,7 @@ static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count)
323 * to machine native 327 * to machine native
324 */ 328 */
325 expected = be32_to_cpu(*(__be32 *) (buf + 2)); 329 expected = be32_to_cpu(*(__be32 *) (buf + 2));
326 if (expected > count) { 330 if (expected > count || expected < size) {
327 dev_err(dev, "%s() expected > count\n", __func__); 331 dev_err(dev, "%s() expected > count\n", __func__);
328 size = -EIO; 332 size = -EIO;
329 continue; 333 continue;
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 183a5f54d875..da074e3db19b 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -270,7 +270,8 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
270{ 270{
271 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); 271 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
272 int size = 0; 272 int size = 0;
273 int expected, status; 273 int status;
274 u32 expected;
274 275
275 if (count < TPM_HEADER_SIZE) { 276 if (count < TPM_HEADER_SIZE) {
276 size = -EIO; 277 size = -EIO;
@@ -285,7 +286,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
285 } 286 }
286 287
287 expected = be32_to_cpu(*(__be32 *) (buf + 2)); 288 expected = be32_to_cpu(*(__be32 *) (buf + 2));
288 if (expected > count) { 289 if (expected > count || expected < TPM_HEADER_SIZE) {
289 size = -EIO; 290 size = -EIO;
290 goto out; 291 goto out;
291 } 292 }
diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index 44301a3d9963..a07f6451694a 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -449,17 +449,17 @@ struct bcm2835_pll_ana_bits {
449static const struct bcm2835_pll_ana_bits bcm2835_ana_default = { 449static const struct bcm2835_pll_ana_bits bcm2835_ana_default = {
450 .mask0 = 0, 450 .mask0 = 0,
451 .set0 = 0, 451 .set0 = 0,
452 .mask1 = (u32)~(A2W_PLL_KI_MASK | A2W_PLL_KP_MASK), 452 .mask1 = A2W_PLL_KI_MASK | A2W_PLL_KP_MASK,
453 .set1 = (2 << A2W_PLL_KI_SHIFT) | (8 << A2W_PLL_KP_SHIFT), 453 .set1 = (2 << A2W_PLL_KI_SHIFT) | (8 << A2W_PLL_KP_SHIFT),
454 .mask3 = (u32)~A2W_PLL_KA_MASK, 454 .mask3 = A2W_PLL_KA_MASK,
455 .set3 = (2 << A2W_PLL_KA_SHIFT), 455 .set3 = (2 << A2W_PLL_KA_SHIFT),
456 .fb_prediv_mask = BIT(14), 456 .fb_prediv_mask = BIT(14),
457}; 457};
458 458
459static const struct bcm2835_pll_ana_bits bcm2835_ana_pllh = { 459static const struct bcm2835_pll_ana_bits bcm2835_ana_pllh = {
460 .mask0 = (u32)~(A2W_PLLH_KA_MASK | A2W_PLLH_KI_LOW_MASK), 460 .mask0 = A2W_PLLH_KA_MASK | A2W_PLLH_KI_LOW_MASK,
461 .set0 = (2 << A2W_PLLH_KA_SHIFT) | (2 << A2W_PLLH_KI_LOW_SHIFT), 461 .set0 = (2 << A2W_PLLH_KA_SHIFT) | (2 << A2W_PLLH_KI_LOW_SHIFT),
462 .mask1 = (u32)~(A2W_PLLH_KI_HIGH_MASK | A2W_PLLH_KP_MASK), 462 .mask1 = A2W_PLLH_KI_HIGH_MASK | A2W_PLLH_KP_MASK,
463 .set1 = (6 << A2W_PLLH_KP_SHIFT), 463 .set1 = (6 << A2W_PLLH_KP_SHIFT),
464 .mask3 = 0, 464 .mask3 = 0,
465 .set3 = 0, 465 .set3 = 0,
@@ -623,8 +623,10 @@ static int bcm2835_pll_on(struct clk_hw *hw)
623 ~A2W_PLL_CTRL_PWRDN); 623 ~A2W_PLL_CTRL_PWRDN);
624 624
625 /* Take the PLL out of reset. */ 625 /* Take the PLL out of reset. */
626 spin_lock(&cprman->regs_lock);
626 cprman_write(cprman, data->cm_ctrl_reg, 627 cprman_write(cprman, data->cm_ctrl_reg,
627 cprman_read(cprman, data->cm_ctrl_reg) & ~CM_PLL_ANARST); 628 cprman_read(cprman, data->cm_ctrl_reg) & ~CM_PLL_ANARST);
629 spin_unlock(&cprman->regs_lock);
628 630
629 /* Wait for the PLL to lock. */ 631 /* Wait for the PLL to lock. */
630 timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS); 632 timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
@@ -701,9 +703,11 @@ static int bcm2835_pll_set_rate(struct clk_hw *hw,
701 } 703 }
702 704
703 /* Unmask the reference clock from the oscillator. */ 705 /* Unmask the reference clock from the oscillator. */
706 spin_lock(&cprman->regs_lock);
704 cprman_write(cprman, A2W_XOSC_CTRL, 707 cprman_write(cprman, A2W_XOSC_CTRL,
705 cprman_read(cprman, A2W_XOSC_CTRL) | 708 cprman_read(cprman, A2W_XOSC_CTRL) |
706 data->reference_enable_mask); 709 data->reference_enable_mask);
710 spin_unlock(&cprman->regs_lock);
707 711
708 if (do_ana_setup_first) 712 if (do_ana_setup_first)
709 bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana); 713 bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana);
diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c
index 9f7f931d6b2f..5eb50c31e455 100644
--- a/drivers/clk/clk-aspeed.c
+++ b/drivers/clk/clk-aspeed.c
@@ -205,6 +205,18 @@ static const struct aspeed_clk_soc_data ast2400_data = {
205 .calc_pll = aspeed_ast2400_calc_pll, 205 .calc_pll = aspeed_ast2400_calc_pll,
206}; 206};
207 207
208static int aspeed_clk_is_enabled(struct clk_hw *hw)
209{
210 struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
211 u32 clk = BIT(gate->clock_idx);
212 u32 enval = (gate->flags & CLK_GATE_SET_TO_DISABLE) ? 0 : clk;
213 u32 reg;
214
215 regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
216
217 return ((reg & clk) == enval) ? 1 : 0;
218}
219
208static int aspeed_clk_enable(struct clk_hw *hw) 220static int aspeed_clk_enable(struct clk_hw *hw)
209{ 221{
210 struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw); 222 struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
@@ -215,6 +227,11 @@ static int aspeed_clk_enable(struct clk_hw *hw)
215 227
216 spin_lock_irqsave(gate->lock, flags); 228 spin_lock_irqsave(gate->lock, flags);
217 229
230 if (aspeed_clk_is_enabled(hw)) {
231 spin_unlock_irqrestore(gate->lock, flags);
232 return 0;
233 }
234
218 if (gate->reset_idx >= 0) { 235 if (gate->reset_idx >= 0) {
219 /* Put IP in reset */ 236 /* Put IP in reset */
220 regmap_update_bits(gate->map, ASPEED_RESET_CTRL, rst, rst); 237 regmap_update_bits(gate->map, ASPEED_RESET_CTRL, rst, rst);
@@ -255,17 +272,6 @@ static void aspeed_clk_disable(struct clk_hw *hw)
255 spin_unlock_irqrestore(gate->lock, flags); 272 spin_unlock_irqrestore(gate->lock, flags);
256} 273}
257 274
258static int aspeed_clk_is_enabled(struct clk_hw *hw)
259{
260 struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
261 u32 clk = BIT(gate->clock_idx);
262 u32 reg;
263
264 regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
265
266 return (reg & clk) ? 0 : 1;
267}
268
269static const struct clk_ops aspeed_clk_gate_ops = { 275static const struct clk_ops aspeed_clk_gate_ops = {
270 .enable = aspeed_clk_enable, 276 .enable = aspeed_clk_enable,
271 .disable = aspeed_clk_disable, 277 .disable = aspeed_clk_disable,
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 0f686a9dac3e..076d4244d672 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1125,8 +1125,10 @@ static int clk_core_round_rate_nolock(struct clk_core *core,
1125{ 1125{
1126 lockdep_assert_held(&prepare_lock); 1126 lockdep_assert_held(&prepare_lock);
1127 1127
1128 if (!core) 1128 if (!core) {
1129 req->rate = 0;
1129 return 0; 1130 return 0;
1131 }
1130 1132
1131 clk_core_init_rate_req(core, req); 1133 clk_core_init_rate_req(core, req);
1132 1134
@@ -2309,8 +2311,11 @@ static int clk_core_set_phase_nolock(struct clk_core *core, int degrees)
2309 2311
2310 trace_clk_set_phase(core, degrees); 2312 trace_clk_set_phase(core, degrees);
2311 2313
2312 if (core->ops->set_phase) 2314 if (core->ops->set_phase) {
2313 ret = core->ops->set_phase(core->hw, degrees); 2315 ret = core->ops->set_phase(core->hw, degrees);
2316 if (!ret)
2317 core->phase = degrees;
2318 }
2314 2319
2315 trace_clk_set_phase_complete(core, degrees); 2320 trace_clk_set_phase_complete(core, degrees);
2316 2321
@@ -2968,22 +2973,37 @@ static int __clk_core_init(struct clk_core *core)
2968 core->rate = core->req_rate = rate; 2973 core->rate = core->req_rate = rate;
2969 2974
2970 /* 2975 /*
2976 * Enable CLK_IS_CRITICAL clocks so newly added critical clocks
2977 * don't get accidentally disabled when walking the orphan tree and
2978 * reparenting clocks
2979 */
2980 if (core->flags & CLK_IS_CRITICAL) {
2981 unsigned long flags;
2982
2983 clk_core_prepare(core);
2984
2985 flags = clk_enable_lock();
2986 clk_core_enable(core);
2987 clk_enable_unlock(flags);
2988 }
2989
2990 /*
2971 * walk the list of orphan clocks and reparent any that newly finds a 2991 * walk the list of orphan clocks and reparent any that newly finds a
2972 * parent. 2992 * parent.
2973 */ 2993 */
2974 hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) { 2994 hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) {
2975 struct clk_core *parent = __clk_init_parent(orphan); 2995 struct clk_core *parent = __clk_init_parent(orphan);
2976 unsigned long flags;
2977 2996
2978 /* 2997 /*
2979 * we could call __clk_set_parent, but that would result in a 2998 * We need to use __clk_set_parent_before() and _after() to
2980 * redundant call to the .set_rate op, if it exists 2999 * to properly migrate any prepare/enable count of the orphan
3000 * clock. This is important for CLK_IS_CRITICAL clocks, which
3001 * are enabled during init but might not have a parent yet.
2981 */ 3002 */
2982 if (parent) { 3003 if (parent) {
2983 /* update the clk tree topology */ 3004 /* update the clk tree topology */
2984 flags = clk_enable_lock(); 3005 __clk_set_parent_before(orphan, parent);
2985 clk_reparent(orphan, parent); 3006 __clk_set_parent_after(orphan, parent, NULL);
2986 clk_enable_unlock(flags);
2987 __clk_recalc_accuracies(orphan); 3007 __clk_recalc_accuracies(orphan);
2988 __clk_recalc_rates(orphan, 0); 3008 __clk_recalc_rates(orphan, 0);
2989 } 3009 }
@@ -3000,16 +3020,6 @@ static int __clk_core_init(struct clk_core *core)
3000 if (core->ops->init) 3020 if (core->ops->init)
3001 core->ops->init(core->hw); 3021 core->ops->init(core->hw);
3002 3022
3003 if (core->flags & CLK_IS_CRITICAL) {
3004 unsigned long flags;
3005
3006 clk_core_prepare(core);
3007
3008 flags = clk_enable_lock();
3009 clk_core_enable(core);
3010 clk_enable_unlock(flags);
3011 }
3012
3013 kref_init(&core->ref); 3023 kref_init(&core->ref);
3014out: 3024out:
3015 clk_pm_runtime_put(core); 3025 clk_pm_runtime_put(core);
diff --git a/drivers/clk/hisilicon/clk-hi3660-stub.c b/drivers/clk/hisilicon/clk-hi3660-stub.c
index 9b6c72bbddf9..e8b2c43b1bb8 100644
--- a/drivers/clk/hisilicon/clk-hi3660-stub.c
+++ b/drivers/clk/hisilicon/clk-hi3660-stub.c
@@ -149,6 +149,8 @@ static int hi3660_stub_clk_probe(struct platform_device *pdev)
149 return PTR_ERR(stub_clk_chan.mbox); 149 return PTR_ERR(stub_clk_chan.mbox);
150 150
151 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 151 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
152 if (!res)
153 return -EINVAL;
152 freq_reg = devm_ioremap(dev, res->start, resource_size(res)); 154 freq_reg = devm_ioremap(dev, res->start, resource_size(res));
153 if (!freq_reg) 155 if (!freq_reg)
154 return -ENOMEM; 156 return -ENOMEM;
diff --git a/drivers/clk/imx/clk-imx51-imx53.c b/drivers/clk/imx/clk-imx51-imx53.c
index c864992e6983..caa8bd40692c 100644
--- a/drivers/clk/imx/clk-imx51-imx53.c
+++ b/drivers/clk/imx/clk-imx51-imx53.c
@@ -131,7 +131,17 @@ static const char *ieee1588_sels[] = { "pll3_sw", "pll4_sw", "dummy" /* usbphy2_
131static struct clk *clk[IMX5_CLK_END]; 131static struct clk *clk[IMX5_CLK_END];
132static struct clk_onecell_data clk_data; 132static struct clk_onecell_data clk_data;
133 133
134static struct clk ** const uart_clks[] __initconst = { 134static struct clk ** const uart_clks_mx51[] __initconst = {
135 &clk[IMX5_CLK_UART1_IPG_GATE],
136 &clk[IMX5_CLK_UART1_PER_GATE],
137 &clk[IMX5_CLK_UART2_IPG_GATE],
138 &clk[IMX5_CLK_UART2_PER_GATE],
139 &clk[IMX5_CLK_UART3_IPG_GATE],
140 &clk[IMX5_CLK_UART3_PER_GATE],
141 NULL
142};
143
144static struct clk ** const uart_clks_mx50_mx53[] __initconst = {
135 &clk[IMX5_CLK_UART1_IPG_GATE], 145 &clk[IMX5_CLK_UART1_IPG_GATE],
136 &clk[IMX5_CLK_UART1_PER_GATE], 146 &clk[IMX5_CLK_UART1_PER_GATE],
137 &clk[IMX5_CLK_UART2_IPG_GATE], 147 &clk[IMX5_CLK_UART2_IPG_GATE],
@@ -321,8 +331,6 @@ static void __init mx5_clocks_common_init(void __iomem *ccm_base)
321 clk_prepare_enable(clk[IMX5_CLK_TMAX1]); 331 clk_prepare_enable(clk[IMX5_CLK_TMAX1]);
322 clk_prepare_enable(clk[IMX5_CLK_TMAX2]); /* esdhc2, fec */ 332 clk_prepare_enable(clk[IMX5_CLK_TMAX2]); /* esdhc2, fec */
323 clk_prepare_enable(clk[IMX5_CLK_TMAX3]); /* esdhc1, esdhc4 */ 333 clk_prepare_enable(clk[IMX5_CLK_TMAX3]); /* esdhc1, esdhc4 */
324
325 imx_register_uart_clocks(uart_clks);
326} 334}
327 335
328static void __init mx50_clocks_init(struct device_node *np) 336static void __init mx50_clocks_init(struct device_node *np)
@@ -388,6 +396,8 @@ static void __init mx50_clocks_init(struct device_node *np)
388 396
389 r = clk_round_rate(clk[IMX5_CLK_USBOH3_PER_GATE], 54000000); 397 r = clk_round_rate(clk[IMX5_CLK_USBOH3_PER_GATE], 54000000);
390 clk_set_rate(clk[IMX5_CLK_USBOH3_PER_GATE], r); 398 clk_set_rate(clk[IMX5_CLK_USBOH3_PER_GATE], r);
399
400 imx_register_uart_clocks(uart_clks_mx50_mx53);
391} 401}
392CLK_OF_DECLARE(imx50_ccm, "fsl,imx50-ccm", mx50_clocks_init); 402CLK_OF_DECLARE(imx50_ccm, "fsl,imx50-ccm", mx50_clocks_init);
393 403
@@ -477,6 +487,8 @@ static void __init mx51_clocks_init(struct device_node *np)
477 val = readl(MXC_CCM_CLPCR); 487 val = readl(MXC_CCM_CLPCR);
478 val |= 1 << 23; 488 val |= 1 << 23;
479 writel(val, MXC_CCM_CLPCR); 489 writel(val, MXC_CCM_CLPCR);
490
491 imx_register_uart_clocks(uart_clks_mx51);
480} 492}
481CLK_OF_DECLARE(imx51_ccm, "fsl,imx51-ccm", mx51_clocks_init); 493CLK_OF_DECLARE(imx51_ccm, "fsl,imx51-ccm", mx51_clocks_init);
482 494
@@ -606,5 +618,7 @@ static void __init mx53_clocks_init(struct device_node *np)
606 618
607 r = clk_round_rate(clk[IMX5_CLK_USBOH3_PER_GATE], 54000000); 619 r = clk_round_rate(clk[IMX5_CLK_USBOH3_PER_GATE], 54000000);
608 clk_set_rate(clk[IMX5_CLK_USBOH3_PER_GATE], r); 620 clk_set_rate(clk[IMX5_CLK_USBOH3_PER_GATE], r);
621
622 imx_register_uart_clocks(uart_clks_mx50_mx53);
609} 623}
610CLK_OF_DECLARE(imx53_ccm, "fsl,imx53-ccm", mx53_clocks_init); 624CLK_OF_DECLARE(imx53_ccm, "fsl,imx53-ccm", mx53_clocks_init);
diff --git a/drivers/clk/qcom/apcs-msm8916.c b/drivers/clk/qcom/apcs-msm8916.c
index 246957f1a413..b1cc8dbcd327 100644
--- a/drivers/clk/qcom/apcs-msm8916.c
+++ b/drivers/clk/qcom/apcs-msm8916.c
@@ -49,11 +49,10 @@ static int qcom_apcs_msm8916_clk_probe(struct platform_device *pdev)
49 struct clk_regmap_mux_div *a53cc; 49 struct clk_regmap_mux_div *a53cc;
50 struct regmap *regmap; 50 struct regmap *regmap;
51 struct clk_init_data init = { }; 51 struct clk_init_data init = { };
52 int ret; 52 int ret = -ENODEV;
53 53
54 regmap = dev_get_regmap(parent, NULL); 54 regmap = dev_get_regmap(parent, NULL);
55 if (IS_ERR(regmap)) { 55 if (!regmap) {
56 ret = PTR_ERR(regmap);
57 dev_err(dev, "failed to get regmap: %d\n", ret); 56 dev_err(dev, "failed to get regmap: %d\n", ret);
58 return ret; 57 return ret;
59 } 58 }
diff --git a/drivers/clk/sunxi-ng/ccu-sun6i-a31.c b/drivers/clk/sunxi-ng/ccu-sun6i-a31.c
index 72b16ed1012b..3b97f60540ad 100644
--- a/drivers/clk/sunxi-ng/ccu-sun6i-a31.c
+++ b/drivers/clk/sunxi-ng/ccu-sun6i-a31.c
@@ -762,7 +762,7 @@ static struct ccu_mp out_a_clk = {
762 .features = CCU_FEATURE_FIXED_PREDIV, 762 .features = CCU_FEATURE_FIXED_PREDIV,
763 .hw.init = CLK_HW_INIT_PARENTS("out-a", 763 .hw.init = CLK_HW_INIT_PARENTS("out-a",
764 clk_out_parents, 764 clk_out_parents,
765 &ccu_div_ops, 765 &ccu_mp_ops,
766 0), 766 0),
767 }, 767 },
768}; 768};
@@ -783,7 +783,7 @@ static struct ccu_mp out_b_clk = {
783 .features = CCU_FEATURE_FIXED_PREDIV, 783 .features = CCU_FEATURE_FIXED_PREDIV,
784 .hw.init = CLK_HW_INIT_PARENTS("out-b", 784 .hw.init = CLK_HW_INIT_PARENTS("out-b",
785 clk_out_parents, 785 clk_out_parents,
786 &ccu_div_ops, 786 &ccu_mp_ops,
787 0), 787 0),
788 }, 788 },
789}; 789};
@@ -804,7 +804,7 @@ static struct ccu_mp out_c_clk = {
804 .features = CCU_FEATURE_FIXED_PREDIV, 804 .features = CCU_FEATURE_FIXED_PREDIV,
805 .hw.init = CLK_HW_INIT_PARENTS("out-c", 805 .hw.init = CLK_HW_INIT_PARENTS("out-c",
806 clk_out_parents, 806 clk_out_parents,
807 &ccu_div_ops, 807 &ccu_mp_ops,
808 0), 808 0),
809 }, 809 },
810}; 810};
diff --git a/drivers/clk/ti/clk-33xx.c b/drivers/clk/ti/clk-33xx.c
index 612491a26070..12e0a2d19911 100644
--- a/drivers/clk/ti/clk-33xx.c
+++ b/drivers/clk/ti/clk-33xx.c
@@ -45,7 +45,7 @@ static const struct omap_clkctrl_bit_data am3_gpio4_bit_data[] __initconst = {
45 45
46static const struct omap_clkctrl_reg_data am3_l4_per_clkctrl_regs[] __initconst = { 46static const struct omap_clkctrl_reg_data am3_l4_per_clkctrl_regs[] __initconst = {
47 { AM3_CPGMAC0_CLKCTRL, NULL, CLKF_SW_SUP, "cpsw_125mhz_gclk", "cpsw_125mhz_clkdm" }, 47 { AM3_CPGMAC0_CLKCTRL, NULL, CLKF_SW_SUP, "cpsw_125mhz_gclk", "cpsw_125mhz_clkdm" },
48 { AM3_LCDC_CLKCTRL, NULL, CLKF_SW_SUP, "lcd_gclk", "lcdc_clkdm" }, 48 { AM3_LCDC_CLKCTRL, NULL, CLKF_SW_SUP | CLKF_SET_RATE_PARENT, "lcd_gclk", "lcdc_clkdm" },
49 { AM3_USB_OTG_HS_CLKCTRL, NULL, CLKF_SW_SUP, "usbotg_fck", "l3s_clkdm" }, 49 { AM3_USB_OTG_HS_CLKCTRL, NULL, CLKF_SW_SUP, "usbotg_fck", "l3s_clkdm" },
50 { AM3_TPTC0_CLKCTRL, NULL, CLKF_SW_SUP, "l3_gclk", "l3_clkdm" }, 50 { AM3_TPTC0_CLKCTRL, NULL, CLKF_SW_SUP, "l3_gclk", "l3_clkdm" },
51 { AM3_EMIF_CLKCTRL, NULL, CLKF_SW_SUP, "dpll_ddr_m2_div2_ck", "l3_clkdm" }, 51 { AM3_EMIF_CLKCTRL, NULL, CLKF_SW_SUP, "dpll_ddr_m2_div2_ck", "l3_clkdm" },
diff --git a/drivers/clk/ti/clk-43xx.c b/drivers/clk/ti/clk-43xx.c
index 2b7c2e017665..63c5ddb50187 100644
--- a/drivers/clk/ti/clk-43xx.c
+++ b/drivers/clk/ti/clk-43xx.c
@@ -187,7 +187,7 @@ static const struct omap_clkctrl_reg_data am4_l4_per_clkctrl_regs[] __initconst
187 { AM4_OCP2SCP0_CLKCTRL, NULL, CLKF_SW_SUP, "l4ls_gclk" }, 187 { AM4_OCP2SCP0_CLKCTRL, NULL, CLKF_SW_SUP, "l4ls_gclk" },
188 { AM4_OCP2SCP1_CLKCTRL, NULL, CLKF_SW_SUP, "l4ls_gclk" }, 188 { AM4_OCP2SCP1_CLKCTRL, NULL, CLKF_SW_SUP, "l4ls_gclk" },
189 { AM4_EMIF_CLKCTRL, NULL, CLKF_SW_SUP, "dpll_ddr_m2_ck", "emif_clkdm" }, 189 { AM4_EMIF_CLKCTRL, NULL, CLKF_SW_SUP, "dpll_ddr_m2_ck", "emif_clkdm" },
190 { AM4_DSS_CORE_CLKCTRL, NULL, CLKF_SW_SUP, "disp_clk", "dss_clkdm" }, 190 { AM4_DSS_CORE_CLKCTRL, NULL, CLKF_SW_SUP | CLKF_SET_RATE_PARENT, "disp_clk", "dss_clkdm" },
191 { AM4_CPGMAC0_CLKCTRL, NULL, CLKF_SW_SUP, "cpsw_125mhz_gclk", "cpsw_125mhz_clkdm" }, 191 { AM4_CPGMAC0_CLKCTRL, NULL, CLKF_SW_SUP, "cpsw_125mhz_gclk", "cpsw_125mhz_clkdm" },
192 { 0 }, 192 { 0 },
193}; 193};
diff --git a/drivers/clk/ti/clkctrl.c b/drivers/clk/ti/clkctrl.c
index afa0d6bfc5c1..421b05392220 100644
--- a/drivers/clk/ti/clkctrl.c
+++ b/drivers/clk/ti/clkctrl.c
@@ -537,6 +537,8 @@ static void __init _ti_omap4_clkctrl_setup(struct device_node *node)
537 init.parent_names = &reg_data->parent; 537 init.parent_names = &reg_data->parent;
538 init.num_parents = 1; 538 init.num_parents = 1;
539 init.flags = 0; 539 init.flags = 0;
540 if (reg_data->flags & CLKF_SET_RATE_PARENT)
541 init.flags |= CLK_SET_RATE_PARENT;
540 init.name = kasprintf(GFP_KERNEL, "%s:%s:%04x:%d", 542 init.name = kasprintf(GFP_KERNEL, "%s:%s:%04x:%d",
541 node->parent->name, node->name, 543 node->parent->name, node->name,
542 reg_data->offset, 0); 544 reg_data->offset, 0);
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index b3b4ed9b6874..d2e5382821a4 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -386,6 +386,7 @@ config ATMEL_PIT
386 386
387config ATMEL_ST 387config ATMEL_ST
388 bool "Atmel ST timer support" if COMPILE_TEST 388 bool "Atmel ST timer support" if COMPILE_TEST
389 depends on HAS_IOMEM
389 select TIMER_OF 390 select TIMER_OF
390 select MFD_SYSCON 391 select MFD_SYSCON
391 help 392 help
diff --git a/drivers/clocksource/arc_timer.c b/drivers/clocksource/arc_timer.c
index 4927355f9cbe..471b428d8034 100644
--- a/drivers/clocksource/arc_timer.c
+++ b/drivers/clocksource/arc_timer.c
@@ -251,9 +251,14 @@ static irqreturn_t timer_irq_handler(int irq, void *dev_id)
251 int irq_reenable = clockevent_state_periodic(evt); 251 int irq_reenable = clockevent_state_periodic(evt);
252 252
253 /* 253 /*
254 * Any write to CTRL reg ACks the interrupt, we rewrite the 254 * 1. ACK the interrupt
255 * Count when [N]ot [H]alted bit. 255 * - For ARC700, any write to CTRL reg ACKs it, so just rewrite
256 * And re-arm it if perioid by [I]nterrupt [E]nable bit 256 * Count when [N]ot [H]alted bit.
257 * - For HS3x, it is a bit subtle. On taken count-down interrupt,
258 * IP bit [3] is set, which needs to be cleared for ACK'ing.
259 * The write below can only update the other two bits, hence
260 * explicitly clears IP bit
261 * 2. Re-arm interrupt if periodic by writing to IE bit [0]
257 */ 262 */
258 write_aux_reg(ARC_REG_TIMER0_CTRL, irq_reenable | TIMER_CTRL_NH); 263 write_aux_reg(ARC_REG_TIMER0_CTRL, irq_reenable | TIMER_CTRL_NH);
259 264
diff --git a/drivers/clocksource/fsl_ftm_timer.c b/drivers/clocksource/fsl_ftm_timer.c
index 3ee7e6fea621..846d18daf893 100644
--- a/drivers/clocksource/fsl_ftm_timer.c
+++ b/drivers/clocksource/fsl_ftm_timer.c
@@ -281,7 +281,7 @@ static int __init __ftm_clk_init(struct device_node *np, char *cnt_name,
281 281
282static unsigned long __init ftm_clk_init(struct device_node *np) 282static unsigned long __init ftm_clk_init(struct device_node *np)
283{ 283{
284 unsigned long freq; 284 long freq;
285 285
286 freq = __ftm_clk_init(np, "ftm-evt-counter-en", "ftm-evt"); 286 freq = __ftm_clk_init(np, "ftm-evt-counter-en", "ftm-evt");
287 if (freq <= 0) 287 if (freq <= 0)
diff --git a/drivers/clocksource/mips-gic-timer.c b/drivers/clocksource/mips-gic-timer.c
index a04808a21d4e..986b6796b631 100644
--- a/drivers/clocksource/mips-gic-timer.c
+++ b/drivers/clocksource/mips-gic-timer.c
@@ -166,7 +166,7 @@ static int __init __gic_clocksource_init(void)
166 166
167 /* Set clocksource mask. */ 167 /* Set clocksource mask. */
168 count_width = read_gic_config() & GIC_CONFIG_COUNTBITS; 168 count_width = read_gic_config() & GIC_CONFIG_COUNTBITS;
169 count_width >>= __fls(GIC_CONFIG_COUNTBITS); 169 count_width >>= __ffs(GIC_CONFIG_COUNTBITS);
170 count_width *= 4; 170 count_width *= 4;
171 count_width += 32; 171 count_width += 32;
172 gic_clocksource.mask = CLOCKSOURCE_MASK(count_width); 172 gic_clocksource.mask = CLOCKSOURCE_MASK(count_width);
@@ -205,12 +205,12 @@ static int __init gic_clocksource_of_init(struct device_node *node)
205 } else if (of_property_read_u32(node, "clock-frequency", 205 } else if (of_property_read_u32(node, "clock-frequency",
206 &gic_frequency)) { 206 &gic_frequency)) {
207 pr_err("GIC frequency not specified.\n"); 207 pr_err("GIC frequency not specified.\n");
208 return -EINVAL;; 208 return -EINVAL;
209 } 209 }
210 gic_timer_irq = irq_of_parse_and_map(node, 0); 210 gic_timer_irq = irq_of_parse_and_map(node, 0);
211 if (!gic_timer_irq) { 211 if (!gic_timer_irq) {
212 pr_err("GIC timer IRQ not specified.\n"); 212 pr_err("GIC timer IRQ not specified.\n");
213 return -EINVAL;; 213 return -EINVAL;
214 } 214 }
215 215
216 ret = __gic_clocksource_init(); 216 ret = __gic_clocksource_init();
diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c
index 2a3fe83ec337..3b56ea3f52af 100644
--- a/drivers/clocksource/timer-sun5i.c
+++ b/drivers/clocksource/timer-sun5i.c
@@ -334,7 +334,7 @@ static int __init sun5i_timer_init(struct device_node *node)
334 timer_base = of_io_request_and_map(node, 0, of_node_full_name(node)); 334 timer_base = of_io_request_and_map(node, 0, of_node_full_name(node));
335 if (IS_ERR(timer_base)) { 335 if (IS_ERR(timer_base)) {
336 pr_err("Can't map registers\n"); 336 pr_err("Can't map registers\n");
337 return PTR_ERR(timer_base);; 337 return PTR_ERR(timer_base);
338 } 338 }
339 339
340 irq = irq_of_parse_and_map(node, 0); 340 irq = irq_of_parse_and_map(node, 0);
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 3a88e33b0cfe..fb586e09682d 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -44,10 +44,10 @@ config ARM_DT_BL_CPUFREQ
44 44
45config ARM_SCPI_CPUFREQ 45config ARM_SCPI_CPUFREQ
46 tristate "SCPI based CPUfreq driver" 46 tristate "SCPI based CPUfreq driver"
47 depends on ARM_BIG_LITTLE_CPUFREQ && ARM_SCPI_PROTOCOL && COMMON_CLK_SCPI 47 depends on ARM_SCPI_PROTOCOL && COMMON_CLK_SCPI
48 help 48 help
49 This adds the CPUfreq driver support for ARM big.LITTLE platforms 49 This adds the CPUfreq driver support for ARM platforms using SCPI
50 using SCPI protocol for CPU power management. 50 protocol for CPU power management.
51 51
52 This driver uses SCPI Message Protocol driver to interact with the 52 This driver uses SCPI Message Protocol driver to interact with the
53 firmware providing the CPU DVFS functionality. 53 firmware providing the CPU DVFS functionality.
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 3a2ca0f79daf..d0c34df0529c 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -629,7 +629,7 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)
629 if (c->x86_vendor == X86_VENDOR_INTEL) { 629 if (c->x86_vendor == X86_VENDOR_INTEL) {
630 if ((c->x86 == 15) && 630 if ((c->x86 == 15) &&
631 (c->x86_model == 6) && 631 (c->x86_model == 6) &&
632 (c->x86_mask == 8)) { 632 (c->x86_stepping == 8)) {
633 pr_info("Intel(R) Xeon(R) 7100 Errata AL30, processors may lock up on frequency changes: disabling acpi-cpufreq\n"); 633 pr_info("Intel(R) Xeon(R) 7100 Errata AL30, processors may lock up on frequency changes: disabling acpi-cpufreq\n");
634 return -ENODEV; 634 return -ENODEV;
635 } 635 }
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index 942632a27b50..f730b6528c18 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -775,7 +775,7 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
775 break; 775 break;
776 776
777 case 7: 777 case 7:
778 switch (c->x86_mask) { 778 switch (c->x86_stepping) {
779 case 0: 779 case 0:
780 longhaul_version = TYPE_LONGHAUL_V1; 780 longhaul_version = TYPE_LONGHAUL_V1;
781 cpu_model = CPU_SAMUEL2; 781 cpu_model = CPU_SAMUEL2;
@@ -787,7 +787,7 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
787 break; 787 break;
788 case 1 ... 15: 788 case 1 ... 15:
789 longhaul_version = TYPE_LONGHAUL_V2; 789 longhaul_version = TYPE_LONGHAUL_V2;
790 if (c->x86_mask < 8) { 790 if (c->x86_stepping < 8) {
791 cpu_model = CPU_SAMUEL2; 791 cpu_model = CPU_SAMUEL2;
792 cpuname = "C3 'Samuel 2' [C5B]"; 792 cpuname = "C3 'Samuel 2' [C5B]";
793 } else { 793 } else {
@@ -814,7 +814,7 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
814 numscales = 32; 814 numscales = 32;
815 memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults)); 815 memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults));
816 memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr)); 816 memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr));
817 switch (c->x86_mask) { 817 switch (c->x86_stepping) {
818 case 0 ... 1: 818 case 0 ... 1:
819 cpu_model = CPU_NEHEMIAH; 819 cpu_model = CPU_NEHEMIAH;
820 cpuname = "C3 'Nehemiah A' [C5XLOE]"; 820 cpuname = "C3 'Nehemiah A' [C5XLOE]";
diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
index fd77812313f3..a25741b1281b 100644
--- a/drivers/cpufreq/p4-clockmod.c
+++ b/drivers/cpufreq/p4-clockmod.c
@@ -168,7 +168,7 @@ static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)
168#endif 168#endif
169 169
170 /* Errata workaround */ 170 /* Errata workaround */
171 cpuid = (c->x86 << 8) | (c->x86_model << 4) | c->x86_mask; 171 cpuid = (c->x86 << 8) | (c->x86_model << 4) | c->x86_stepping;
172 switch (cpuid) { 172 switch (cpuid) {
173 case 0x0f07: 173 case 0x0f07:
174 case 0x0f0a: 174 case 0x0f0a:
diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
index 80ac313e6c59..302e9ce793a0 100644
--- a/drivers/cpufreq/powernow-k7.c
+++ b/drivers/cpufreq/powernow-k7.c
@@ -131,7 +131,7 @@ static int check_powernow(void)
131 return 0; 131 return 0;
132 } 132 }
133 133
134 if ((c->x86_model == 6) && (c->x86_mask == 0)) { 134 if ((c->x86_model == 6) && (c->x86_stepping == 0)) {
135 pr_info("K7 660[A0] core detected, enabling errata workarounds\n"); 135 pr_info("K7 660[A0] core detected, enabling errata workarounds\n");
136 have_a0 = 1; 136 have_a0 = 1;
137 } 137 }
diff --git a/drivers/cpufreq/s3c24xx-cpufreq.c b/drivers/cpufreq/s3c24xx-cpufreq.c
index 7b596fa38ad2..6bebc1f9f55a 100644
--- a/drivers/cpufreq/s3c24xx-cpufreq.c
+++ b/drivers/cpufreq/s3c24xx-cpufreq.c
@@ -351,7 +351,13 @@ struct clk *s3c_cpufreq_clk_get(struct device *dev, const char *name)
351static int s3c_cpufreq_init(struct cpufreq_policy *policy) 351static int s3c_cpufreq_init(struct cpufreq_policy *policy)
352{ 352{
353 policy->clk = clk_arm; 353 policy->clk = clk_arm;
354 return cpufreq_generic_init(policy, ftab, cpu_cur.info->latency); 354
355 policy->cpuinfo.transition_latency = cpu_cur.info->latency;
356
357 if (ftab)
358 return cpufreq_table_validate_and_show(policy, ftab);
359
360 return 0;
355} 361}
356 362
357static int __init s3c_cpufreq_initclks(void) 363static int __init s3c_cpufreq_initclks(void)
diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c
index c32a833e1b00..d300a163945f 100644
--- a/drivers/cpufreq/scpi-cpufreq.c
+++ b/drivers/cpufreq/scpi-cpufreq.c
@@ -51,15 +51,23 @@ static unsigned int scpi_cpufreq_get_rate(unsigned int cpu)
51static int 51static int
52scpi_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int index) 52scpi_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int index)
53{ 53{
54 unsigned long freq = policy->freq_table[index].frequency;
54 struct scpi_data *priv = policy->driver_data; 55 struct scpi_data *priv = policy->driver_data;
55 u64 rate = policy->freq_table[index].frequency * 1000; 56 u64 rate = freq * 1000;
56 int ret; 57 int ret;
57 58
58 ret = clk_set_rate(priv->clk, rate); 59 ret = clk_set_rate(priv->clk, rate);
59 if (!ret && (clk_get_rate(priv->clk) != rate))
60 ret = -EIO;
61 60
62 return ret; 61 if (ret)
62 return ret;
63
64 if (clk_get_rate(priv->clk) != rate)
65 return -EIO;
66
67 arch_set_freq_scale(policy->related_cpus, freq,
68 policy->cpuinfo.max_freq);
69
70 return 0;
63} 71}
64 72
65static int 73static int
diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
index 41bc5397f4bb..4fa5adf16c70 100644
--- a/drivers/cpufreq/speedstep-centrino.c
+++ b/drivers/cpufreq/speedstep-centrino.c
@@ -37,7 +37,7 @@ struct cpu_id
37{ 37{
38 __u8 x86; /* CPU family */ 38 __u8 x86; /* CPU family */
39 __u8 x86_model; /* model */ 39 __u8 x86_model; /* model */
40 __u8 x86_mask; /* stepping */ 40 __u8 x86_stepping; /* stepping */
41}; 41};
42 42
43enum { 43enum {
@@ -277,7 +277,7 @@ static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c,
277{ 277{
278 if ((c->x86 == x->x86) && 278 if ((c->x86 == x->x86) &&
279 (c->x86_model == x->x86_model) && 279 (c->x86_model == x->x86_model) &&
280 (c->x86_mask == x->x86_mask)) 280 (c->x86_stepping == x->x86_stepping))
281 return 1; 281 return 1;
282 return 0; 282 return 0;
283} 283}
diff --git a/drivers/cpufreq/speedstep-lib.c b/drivers/cpufreq/speedstep-lib.c
index 8085ec9000d1..e3a9962ee410 100644
--- a/drivers/cpufreq/speedstep-lib.c
+++ b/drivers/cpufreq/speedstep-lib.c
@@ -272,9 +272,9 @@ unsigned int speedstep_detect_processor(void)
272 ebx = cpuid_ebx(0x00000001); 272 ebx = cpuid_ebx(0x00000001);
273 ebx &= 0x000000FF; 273 ebx &= 0x000000FF;
274 274
275 pr_debug("ebx value is %x, x86_mask is %x\n", ebx, c->x86_mask); 275 pr_debug("ebx value is %x, x86_stepping is %x\n", ebx, c->x86_stepping);
276 276
277 switch (c->x86_mask) { 277 switch (c->x86_stepping) {
278 case 4: 278 case 4:
279 /* 279 /*
280 * B-stepping [M-P4-M] 280 * B-stepping [M-P4-M]
@@ -361,7 +361,7 @@ unsigned int speedstep_detect_processor(void)
361 msr_lo, msr_hi); 361 msr_lo, msr_hi);
362 if ((msr_hi & (1<<18)) && 362 if ((msr_hi & (1<<18)) &&
363 (relaxed_check ? 1 : (msr_hi & (3<<24)))) { 363 (relaxed_check ? 1 : (msr_hi & (3<<24)))) {
364 if (c->x86_mask == 0x01) { 364 if (c->x86_stepping == 0x01) {
365 pr_debug("early PIII version\n"); 365 pr_debug("early PIII version\n");
366 return SPEEDSTEP_CPU_PIII_C_EARLY; 366 return SPEEDSTEP_CPU_PIII_C_EARLY;
367 } else 367 } else
diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 75d280cb2dc0..e843cf410373 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -228,12 +228,16 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask,
228 * without any error (HW optimizations for later 228 * without any error (HW optimizations for later
229 * CAAM eras), then try again. 229 * CAAM eras), then try again.
230 */ 230 */
231 if (ret)
232 break;
233
231 rdsta_val = rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_IFMASK; 234 rdsta_val = rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_IFMASK;
232 if ((status && status != JRSTA_SSRC_JUMP_HALT_CC) || 235 if ((status && status != JRSTA_SSRC_JUMP_HALT_CC) ||
233 !(rdsta_val & (1 << sh_idx))) 236 !(rdsta_val & (1 << sh_idx))) {
234 ret = -EAGAIN; 237 ret = -EAGAIN;
235 if (ret)
236 break; 238 break;
239 }
240
237 dev_info(ctrldev, "Instantiated RNG4 SH%d\n", sh_idx); 241 dev_info(ctrldev, "Instantiated RNG4 SH%d\n", sh_idx);
238 /* Clear the contents before recreating the descriptor */ 242 /* Clear the contents before recreating the descriptor */
239 memset(desc, 0x00, CAAM_CMD_SZ * 7); 243 memset(desc, 0x00, CAAM_CMD_SZ * 7);
diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index fcfa5b1eae61..b3afb6cc9d72 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -211,7 +211,7 @@ static int __sev_platform_shutdown_locked(int *error)
211{ 211{
212 int ret; 212 int ret;
213 213
214 ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, 0, error); 214 ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error);
215 if (ret) 215 if (ret)
216 return ret; 216 return ret;
217 217
@@ -271,7 +271,7 @@ static int sev_ioctl_do_reset(struct sev_issue_cmd *argp)
271 return rc; 271 return rc;
272 } 272 }
273 273
274 return __sev_do_cmd_locked(SEV_CMD_FACTORY_RESET, 0, &argp->error); 274 return __sev_do_cmd_locked(SEV_CMD_FACTORY_RESET, NULL, &argp->error);
275} 275}
276 276
277static int sev_ioctl_do_platform_status(struct sev_issue_cmd *argp) 277static int sev_ioctl_do_platform_status(struct sev_issue_cmd *argp)
@@ -299,7 +299,7 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp)
299 return rc; 299 return rc;
300 } 300 }
301 301
302 return __sev_do_cmd_locked(cmd, 0, &argp->error); 302 return __sev_do_cmd_locked(cmd, NULL, &argp->error);
303} 303}
304 304
305static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp) 305static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp)
@@ -624,7 +624,7 @@ EXPORT_SYMBOL_GPL(sev_guest_decommission);
624 624
625int sev_guest_df_flush(int *error) 625int sev_guest_df_flush(int *error)
626{ 626{
627 return sev_do_cmd(SEV_CMD_DF_FLUSH, 0, error); 627 return sev_do_cmd(SEV_CMD_DF_FLUSH, NULL, error);
628} 628}
629EXPORT_SYMBOL_GPL(sev_guest_df_flush); 629EXPORT_SYMBOL_GPL(sev_guest_df_flush);
630 630
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 4b6642a25df5..1c6cbda56afe 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -512,7 +512,7 @@ static int __init padlock_init(void)
512 512
513 printk(KERN_NOTICE PFX "Using VIA PadLock ACE for AES algorithm.\n"); 513 printk(KERN_NOTICE PFX "Using VIA PadLock ACE for AES algorithm.\n");
514 514
515 if (c->x86 == 6 && c->x86_model == 15 && c->x86_mask == 2) { 515 if (c->x86 == 6 && c->x86_model == 15 && c->x86_stepping == 2) {
516 ecb_fetch_blocks = MAX_ECB_FETCH_BLOCKS; 516 ecb_fetch_blocks = MAX_ECB_FETCH_BLOCKS;
517 cbc_fetch_blocks = MAX_CBC_FETCH_BLOCKS; 517 cbc_fetch_blocks = MAX_CBC_FETCH_BLOCKS;
518 printk(KERN_NOTICE PFX "VIA Nano stepping 2 detected: enabling workaround.\n"); 518 printk(KERN_NOTICE PFX "VIA Nano stepping 2 detected: enabling workaround.\n");
diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c
index 188f44b7eb27..5d64c08b7f47 100644
--- a/drivers/crypto/s5p-sss.c
+++ b/drivers/crypto/s5p-sss.c
@@ -1922,15 +1922,21 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode)
1922 uint32_t aes_control; 1922 uint32_t aes_control;
1923 unsigned long flags; 1923 unsigned long flags;
1924 int err; 1924 int err;
1925 u8 *iv;
1925 1926
1926 aes_control = SSS_AES_KEY_CHANGE_MODE; 1927 aes_control = SSS_AES_KEY_CHANGE_MODE;
1927 if (mode & FLAGS_AES_DECRYPT) 1928 if (mode & FLAGS_AES_DECRYPT)
1928 aes_control |= SSS_AES_MODE_DECRYPT; 1929 aes_control |= SSS_AES_MODE_DECRYPT;
1929 1930
1930 if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CBC) 1931 if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CBC) {
1931 aes_control |= SSS_AES_CHAIN_MODE_CBC; 1932 aes_control |= SSS_AES_CHAIN_MODE_CBC;
1932 else if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CTR) 1933 iv = req->info;
1934 } else if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CTR) {
1933 aes_control |= SSS_AES_CHAIN_MODE_CTR; 1935 aes_control |= SSS_AES_CHAIN_MODE_CTR;
1936 iv = req->info;
1937 } else {
1938 iv = NULL; /* AES_ECB */
1939 }
1934 1940
1935 if (dev->ctx->keylen == AES_KEYSIZE_192) 1941 if (dev->ctx->keylen == AES_KEYSIZE_192)
1936 aes_control |= SSS_AES_KEY_SIZE_192; 1942 aes_control |= SSS_AES_KEY_SIZE_192;
@@ -1961,7 +1967,7 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode)
1961 goto outdata_error; 1967 goto outdata_error;
1962 1968
1963 SSS_AES_WRITE(dev, AES_CONTROL, aes_control); 1969 SSS_AES_WRITE(dev, AES_CONTROL, aes_control);
1964 s5p_set_aes(dev, dev->ctx->aes_key, req->info, dev->ctx->keylen); 1970 s5p_set_aes(dev, dev->ctx->aes_key, iv, dev->ctx->keylen);
1965 1971
1966 s5p_set_dma_indata(dev, dev->sg_src); 1972 s5p_set_dma_indata(dev, dev->sg_src);
1967 s5p_set_dma_outdata(dev, dev->sg_dst); 1973 s5p_set_dma_outdata(dev, dev->sg_dst);
diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
index 0d01d1624252..63d636424161 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
+++ b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
@@ -28,7 +28,7 @@ int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
28 algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng); 28 algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
29 ss = algt->ss; 29 ss = algt->ss;
30 30
31 spin_lock(&ss->slock); 31 spin_lock_bh(&ss->slock);
32 32
33 writel(mode, ss->base + SS_CTL); 33 writel(mode, ss->base + SS_CTL);
34 34
@@ -51,6 +51,6 @@ int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
51 } 51 }
52 52
53 writel(0, ss->base + SS_CTL); 53 writel(0, ss->base + SS_CTL);
54 spin_unlock(&ss->slock); 54 spin_unlock_bh(&ss->slock);
55 return dlen; 55 return 0;
56} 56}
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 9c80e0cb1664..6882fa2f8bad 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1138,6 +1138,10 @@ static int talitos_sg_map(struct device *dev, struct scatterlist *src,
1138 struct talitos_private *priv = dev_get_drvdata(dev); 1138 struct talitos_private *priv = dev_get_drvdata(dev);
1139 bool is_sec1 = has_ftr_sec1(priv); 1139 bool is_sec1 = has_ftr_sec1(priv);
1140 1140
1141 if (!src) {
1142 to_talitos_ptr(ptr, 0, 0, is_sec1);
1143 return 1;
1144 }
1141 if (sg_count == 1) { 1145 if (sg_count == 1) {
1142 to_talitos_ptr(ptr, sg_dma_address(src) + offset, len, is_sec1); 1146 to_talitos_ptr(ptr, sg_dma_address(src) + offset, len, is_sec1);
1143 return sg_count; 1147 return sg_count;
diff --git a/drivers/dax/super.c b/drivers/dax/super.c
index 473af694ad1c..ecdc292aa4e4 100644
--- a/drivers/dax/super.c
+++ b/drivers/dax/super.c
@@ -246,12 +246,6 @@ long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
246{ 246{
247 long avail; 247 long avail;
248 248
249 /*
250 * The device driver is allowed to sleep, in order to make the
251 * memory directly accessible.
252 */
253 might_sleep();
254
255 if (!dax_dev) 249 if (!dax_dev)
256 return -EOPNOTSUPP; 250 return -EOPNOTSUPP;
257 251
diff --git a/drivers/dma/mv_xor_v2.c b/drivers/dma/mv_xor_v2.c
index f652a0e0f5a2..3548caa9e933 100644
--- a/drivers/dma/mv_xor_v2.c
+++ b/drivers/dma/mv_xor_v2.c
@@ -163,6 +163,7 @@ struct mv_xor_v2_device {
163 void __iomem *dma_base; 163 void __iomem *dma_base;
164 void __iomem *glob_base; 164 void __iomem *glob_base;
165 struct clk *clk; 165 struct clk *clk;
166 struct clk *reg_clk;
166 struct tasklet_struct irq_tasklet; 167 struct tasklet_struct irq_tasklet;
167 struct list_head free_sw_desc; 168 struct list_head free_sw_desc;
168 struct dma_device dmadev; 169 struct dma_device dmadev;
@@ -749,13 +750,26 @@ static int mv_xor_v2_probe(struct platform_device *pdev)
749 if (ret) 750 if (ret)
750 return ret; 751 return ret;
751 752
753 xor_dev->reg_clk = devm_clk_get(&pdev->dev, "reg");
754 if (PTR_ERR(xor_dev->reg_clk) != -ENOENT) {
755 if (!IS_ERR(xor_dev->reg_clk)) {
756 ret = clk_prepare_enable(xor_dev->reg_clk);
757 if (ret)
758 return ret;
759 } else {
760 return PTR_ERR(xor_dev->reg_clk);
761 }
762 }
763
752 xor_dev->clk = devm_clk_get(&pdev->dev, NULL); 764 xor_dev->clk = devm_clk_get(&pdev->dev, NULL);
753 if (IS_ERR(xor_dev->clk) && PTR_ERR(xor_dev->clk) == -EPROBE_DEFER) 765 if (IS_ERR(xor_dev->clk) && PTR_ERR(xor_dev->clk) == -EPROBE_DEFER) {
754 return -EPROBE_DEFER; 766 ret = EPROBE_DEFER;
767 goto disable_reg_clk;
768 }
755 if (!IS_ERR(xor_dev->clk)) { 769 if (!IS_ERR(xor_dev->clk)) {
756 ret = clk_prepare_enable(xor_dev->clk); 770 ret = clk_prepare_enable(xor_dev->clk);
757 if (ret) 771 if (ret)
758 return ret; 772 goto disable_reg_clk;
759 } 773 }
760 774
761 ret = platform_msi_domain_alloc_irqs(&pdev->dev, 1, 775 ret = platform_msi_domain_alloc_irqs(&pdev->dev, 1,
@@ -866,8 +880,9 @@ free_hw_desq:
866free_msi_irqs: 880free_msi_irqs:
867 platform_msi_domain_free_irqs(&pdev->dev); 881 platform_msi_domain_free_irqs(&pdev->dev);
868disable_clk: 882disable_clk:
869 if (!IS_ERR(xor_dev->clk)) 883 clk_disable_unprepare(xor_dev->clk);
870 clk_disable_unprepare(xor_dev->clk); 884disable_reg_clk:
885 clk_disable_unprepare(xor_dev->reg_clk);
871 return ret; 886 return ret;
872} 887}
873 888
diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
index e3ff162c03fc..d0cacdb0713e 100644
--- a/drivers/dma/sh/rcar-dmac.c
+++ b/drivers/dma/sh/rcar-dmac.c
@@ -917,7 +917,7 @@ rcar_dmac_chan_prep_sg(struct rcar_dmac_chan *chan, struct scatterlist *sgl,
917 917
918 rcar_dmac_chan_configure_desc(chan, desc); 918 rcar_dmac_chan_configure_desc(chan, desc);
919 919
920 max_chunk_size = (RCAR_DMATCR_MASK + 1) << desc->xfer_shift; 920 max_chunk_size = RCAR_DMATCR_MASK << desc->xfer_shift;
921 921
922 /* 922 /*
923 * Allocate and fill the transfer chunk descriptors. We own the only 923 * Allocate and fill the transfer chunk descriptors. We own the only
diff --git a/drivers/dma/stm32-dmamux.c b/drivers/dma/stm32-dmamux.c
index 4dbb30cf94ac..b922db90939a 100644
--- a/drivers/dma/stm32-dmamux.c
+++ b/drivers/dma/stm32-dmamux.c
@@ -118,14 +118,15 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
118 spin_lock_irqsave(&dmamux->lock, flags); 118 spin_lock_irqsave(&dmamux->lock, flags);
119 mux->chan_id = find_first_zero_bit(dmamux->dma_inuse, 119 mux->chan_id = find_first_zero_bit(dmamux->dma_inuse,
120 dmamux->dma_requests); 120 dmamux->dma_requests);
121 set_bit(mux->chan_id, dmamux->dma_inuse);
122 spin_unlock_irqrestore(&dmamux->lock, flags);
123 121
124 if (mux->chan_id == dmamux->dma_requests) { 122 if (mux->chan_id == dmamux->dma_requests) {
123 spin_unlock_irqrestore(&dmamux->lock, flags);
125 dev_err(&pdev->dev, "Run out of free DMA requests\n"); 124 dev_err(&pdev->dev, "Run out of free DMA requests\n");
126 ret = -ENOMEM; 125 ret = -ENOMEM;
127 goto error; 126 goto error_chan_id;
128 } 127 }
128 set_bit(mux->chan_id, dmamux->dma_inuse);
129 spin_unlock_irqrestore(&dmamux->lock, flags);
129 130
130 /* Look for DMA Master */ 131 /* Look for DMA Master */
131 for (i = 1, min = 0, max = dmamux->dma_reqs[i]; 132 for (i = 1, min = 0, max = dmamux->dma_reqs[i];
@@ -173,6 +174,8 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
173 174
174error: 175error:
175 clear_bit(mux->chan_id, dmamux->dma_inuse); 176 clear_bit(mux->chan_id, dmamux->dma_inuse);
177
178error_chan_id:
176 kfree(mux); 179 kfree(mux);
177 return ERR_PTR(ret); 180 return ERR_PTR(ret);
178} 181}
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 8b16ec595fa7..329cb96f886f 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -3147,7 +3147,7 @@ static struct amd64_family_type *per_family_init(struct amd64_pvt *pvt)
3147 struct amd64_family_type *fam_type = NULL; 3147 struct amd64_family_type *fam_type = NULL;
3148 3148
3149 pvt->ext_model = boot_cpu_data.x86_model >> 4; 3149 pvt->ext_model = boot_cpu_data.x86_model >> 4;
3150 pvt->stepping = boot_cpu_data.x86_mask; 3150 pvt->stepping = boot_cpu_data.x86_stepping;
3151 pvt->model = boot_cpu_data.x86_model; 3151 pvt->model = boot_cpu_data.x86_model;
3152 pvt->fam = boot_cpu_data.x86; 3152 pvt->fam = boot_cpu_data.x86;
3153 3153
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index f34430f99fd8..872100215ca0 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -279,7 +279,7 @@ static const u32 correrrthrsld[] = {
279 * sbridge structs 279 * sbridge structs
280 */ 280 */
281 281
282#define NUM_CHANNELS 4 /* Max channels per MC */ 282#define NUM_CHANNELS 6 /* Max channels per MC */
283#define MAX_DIMMS 3 /* Max DIMMS per channel */ 283#define MAX_DIMMS 3 /* Max DIMMS per channel */
284#define KNL_MAX_CHAS 38 /* KNL max num. of Cache Home Agents */ 284#define KNL_MAX_CHAS 38 /* KNL max num. of Cache Home Agents */
285#define KNL_MAX_CHANNELS 6 /* KNL max num. of PCI channels */ 285#define KNL_MAX_CHANNELS 6 /* KNL max num. of PCI channels */
diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 0a44d43802fe..3ec4c715e240 100644
--- a/drivers/extcon/extcon-axp288.c
+++ b/drivers/extcon/extcon-axp288.c
@@ -1,7 +1,6 @@
1/* 1/*
2 * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver 2 * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver
3 * 3 *
4 * Copyright (C) 2016-2017 Hans de Goede <hdegoede@redhat.com>
5 * Copyright (C) 2015 Intel Corporation 4 * Copyright (C) 2015 Intel Corporation
6 * Author: Ramakrishna Pallala <ramakrishna.pallala@intel.com> 5 * Author: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
7 * 6 *
@@ -98,15 +97,13 @@ struct axp288_extcon_info {
98 struct device *dev; 97 struct device *dev;
99 struct regmap *regmap; 98 struct regmap *regmap;
100 struct regmap_irq_chip_data *regmap_irqc; 99 struct regmap_irq_chip_data *regmap_irqc;
101 struct delayed_work det_work;
102 int irq[EXTCON_IRQ_END]; 100 int irq[EXTCON_IRQ_END];
103 struct extcon_dev *edev; 101 struct extcon_dev *edev;
104 unsigned int previous_cable; 102 unsigned int previous_cable;
105 bool first_detect_done;
106}; 103};
107 104
108/* Power up/down reason string array */ 105/* Power up/down reason string array */
109static char *axp288_pwr_up_down_info[] = { 106static const char * const axp288_pwr_up_down_info[] = {
110 "Last wake caused by user pressing the power button", 107 "Last wake caused by user pressing the power button",
111 "Last wake caused by a charger insertion", 108 "Last wake caused by a charger insertion",
112 "Last wake caused by a battery insertion", 109 "Last wake caused by a battery insertion",
@@ -124,7 +121,7 @@ static char *axp288_pwr_up_down_info[] = {
124 */ 121 */
125static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) 122static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
126{ 123{
127 char **rsi; 124 const char * const *rsi;
128 unsigned int val, i, clear_mask = 0; 125 unsigned int val, i, clear_mask = 0;
129 int ret; 126 int ret;
130 127
@@ -140,25 +137,6 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
140 regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask); 137 regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
141} 138}
142 139
143static void axp288_chrg_detect_complete(struct axp288_extcon_info *info)
144{
145 /*
146 * We depend on other drivers to do things like mux the data lines,
147 * enable/disable vbus based on the id-pin, etc. Sometimes the BIOS has
148 * not set these things up correctly resulting in the initial charger
149 * cable type detection giving a wrong result and we end up not charging
150 * or charging at only 0.5A.
151 *
152 * So we schedule a second cable type detection after 2 seconds to
153 * give the other drivers time to load and do their thing.
154 */
155 if (!info->first_detect_done) {
156 queue_delayed_work(system_wq, &info->det_work,
157 msecs_to_jiffies(2000));
158 info->first_detect_done = true;
159 }
160}
161
162static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) 140static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
163{ 141{
164 int ret, stat, cfg, pwr_stat; 142 int ret, stat, cfg, pwr_stat;
@@ -223,8 +201,6 @@ no_vbus:
223 info->previous_cable = cable; 201 info->previous_cable = cable;
224 } 202 }
225 203
226 axp288_chrg_detect_complete(info);
227
228 return 0; 204 return 0;
229 205
230dev_det_ret: 206dev_det_ret:
@@ -246,11 +222,8 @@ static irqreturn_t axp288_extcon_isr(int irq, void *data)
246 return IRQ_HANDLED; 222 return IRQ_HANDLED;
247} 223}
248 224
249static void axp288_extcon_det_work(struct work_struct *work) 225static void axp288_extcon_enable(struct axp288_extcon_info *info)
250{ 226{
251 struct axp288_extcon_info *info =
252 container_of(work, struct axp288_extcon_info, det_work.work);
253
254 regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG, 227 regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG,
255 BC_GLOBAL_RUN, 0); 228 BC_GLOBAL_RUN, 0);
256 /* Enable the charger detection logic */ 229 /* Enable the charger detection logic */
@@ -272,7 +245,6 @@ static int axp288_extcon_probe(struct platform_device *pdev)
272 info->regmap = axp20x->regmap; 245 info->regmap = axp20x->regmap;
273 info->regmap_irqc = axp20x->regmap_irqc; 246 info->regmap_irqc = axp20x->regmap_irqc;
274 info->previous_cable = EXTCON_NONE; 247 info->previous_cable = EXTCON_NONE;
275 INIT_DELAYED_WORK(&info->det_work, axp288_extcon_det_work);
276 248
277 platform_set_drvdata(pdev, info); 249 platform_set_drvdata(pdev, info);
278 250
@@ -318,7 +290,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
318 } 290 }
319 291
320 /* Start charger cable type detection */ 292 /* Start charger cable type detection */
321 queue_delayed_work(system_wq, &info->det_work, 0); 293 axp288_extcon_enable(info);
322 294
323 return 0; 295 return 0;
324} 296}
diff --git a/drivers/extcon/extcon-intel-int3496.c b/drivers/extcon/extcon-intel-int3496.c
index c8691b5a9cb0..191e99f06a9a 100644
--- a/drivers/extcon/extcon-intel-int3496.c
+++ b/drivers/extcon/extcon-intel-int3496.c
@@ -153,8 +153,9 @@ static int int3496_probe(struct platform_device *pdev)
153 return ret; 153 return ret;
154 } 154 }
155 155
156 /* queue initial processing of id-pin */ 156 /* process id-pin so that we start with the right status */
157 queue_delayed_work(system_wq, &data->work, 0); 157 queue_delayed_work(system_wq, &data->work, 0);
158 flush_delayed_work(&data->work);
158 159
159 platform_set_drvdata(pdev, data); 160 platform_set_drvdata(pdev, data);
160 161
diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c
index c16600f30611..0bdea60c65dd 100644
--- a/drivers/firmware/dcdbas.c
+++ b/drivers/firmware/dcdbas.c
@@ -639,7 +639,7 @@ static void __exit dcdbas_exit(void)
639 platform_driver_unregister(&dcdbas_driver); 639 platform_driver_unregister(&dcdbas_driver);
640} 640}
641 641
642module_init(dcdbas_init); 642subsys_initcall_sync(dcdbas_init);
643module_exit(dcdbas_exit); 643module_exit(dcdbas_exit);
644 644
645MODULE_DESCRIPTION(DRIVER_DESCRIPTION " (version " DRIVER_VERSION ")"); 645MODULE_DESCRIPTION(DRIVER_DESCRIPTION " (version " DRIVER_VERSION ")");
diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c
index da661bf8cb96..13c1edd37e96 100644
--- a/drivers/firmware/efi/libstub/tpm.c
+++ b/drivers/firmware/efi/libstub/tpm.c
@@ -68,11 +68,11 @@ void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg)
68 efi_guid_t linux_eventlog_guid = LINUX_EFI_TPM_EVENT_LOG_GUID; 68 efi_guid_t linux_eventlog_guid = LINUX_EFI_TPM_EVENT_LOG_GUID;
69 efi_status_t status; 69 efi_status_t status;
70 efi_physical_addr_t log_location, log_last_entry; 70 efi_physical_addr_t log_location, log_last_entry;
71 struct linux_efi_tpm_eventlog *log_tbl; 71 struct linux_efi_tpm_eventlog *log_tbl = NULL;
72 unsigned long first_entry_addr, last_entry_addr; 72 unsigned long first_entry_addr, last_entry_addr;
73 size_t log_size, last_entry_size; 73 size_t log_size, last_entry_size;
74 efi_bool_t truncated; 74 efi_bool_t truncated;
75 void *tcg2_protocol; 75 void *tcg2_protocol = NULL;
76 76
77 status = efi_call_early(locate_protocol, &tcg2_guid, NULL, 77 status = efi_call_early(locate_protocol, &tcg2_guid, NULL,
78 &tcg2_protocol); 78 &tcg2_protocol);
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index e76de57dd617..ebaea8b1594b 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -14,7 +14,6 @@
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 */ 15 */
16 16
17#include <linux/clk.h>
18#include <linux/err.h> 17#include <linux/err.h>
19#include <linux/gpio.h> 18#include <linux/gpio.h>
20#include <linux/init.h> 19#include <linux/init.h>
@@ -37,10 +36,9 @@ struct gpio_rcar_priv {
37 struct platform_device *pdev; 36 struct platform_device *pdev;
38 struct gpio_chip gpio_chip; 37 struct gpio_chip gpio_chip;
39 struct irq_chip irq_chip; 38 struct irq_chip irq_chip;
40 struct clk *clk;
41 unsigned int irq_parent; 39 unsigned int irq_parent;
40 atomic_t wakeup_path;
42 bool has_both_edge_trigger; 41 bool has_both_edge_trigger;
43 bool needs_clk;
44}; 42};
45 43
46#define IOINTSEL 0x00 /* General IO/Interrupt Switching Register */ 44#define IOINTSEL 0x00 /* General IO/Interrupt Switching Register */
@@ -186,13 +184,10 @@ static int gpio_rcar_irq_set_wake(struct irq_data *d, unsigned int on)
186 } 184 }
187 } 185 }
188 186
189 if (!p->clk)
190 return 0;
191
192 if (on) 187 if (on)
193 clk_enable(p->clk); 188 atomic_inc(&p->wakeup_path);
194 else 189 else
195 clk_disable(p->clk); 190 atomic_dec(&p->wakeup_path);
196 191
197 return 0; 192 return 0;
198} 193}
@@ -330,17 +325,14 @@ static int gpio_rcar_direction_output(struct gpio_chip *chip, unsigned offset,
330 325
331struct gpio_rcar_info { 326struct gpio_rcar_info {
332 bool has_both_edge_trigger; 327 bool has_both_edge_trigger;
333 bool needs_clk;
334}; 328};
335 329
336static const struct gpio_rcar_info gpio_rcar_info_gen1 = { 330static const struct gpio_rcar_info gpio_rcar_info_gen1 = {
337 .has_both_edge_trigger = false, 331 .has_both_edge_trigger = false,
338 .needs_clk = false,
339}; 332};
340 333
341static const struct gpio_rcar_info gpio_rcar_info_gen2 = { 334static const struct gpio_rcar_info gpio_rcar_info_gen2 = {
342 .has_both_edge_trigger = true, 335 .has_both_edge_trigger = true,
343 .needs_clk = true,
344}; 336};
345 337
346static const struct of_device_id gpio_rcar_of_table[] = { 338static const struct of_device_id gpio_rcar_of_table[] = {
@@ -403,7 +395,6 @@ static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins)
403 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &args); 395 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &args);
404 *npins = ret == 0 ? args.args[2] : RCAR_MAX_GPIO_PER_BANK; 396 *npins = ret == 0 ? args.args[2] : RCAR_MAX_GPIO_PER_BANK;
405 p->has_both_edge_trigger = info->has_both_edge_trigger; 397 p->has_both_edge_trigger = info->has_both_edge_trigger;
406 p->needs_clk = info->needs_clk;
407 398
408 if (*npins == 0 || *npins > RCAR_MAX_GPIO_PER_BANK) { 399 if (*npins == 0 || *npins > RCAR_MAX_GPIO_PER_BANK) {
409 dev_warn(&p->pdev->dev, 400 dev_warn(&p->pdev->dev,
@@ -440,16 +431,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
440 431
441 platform_set_drvdata(pdev, p); 432 platform_set_drvdata(pdev, p);
442 433
443 p->clk = devm_clk_get(dev, NULL);
444 if (IS_ERR(p->clk)) {
445 if (p->needs_clk) {
446 dev_err(dev, "unable to get clock\n");
447 ret = PTR_ERR(p->clk);
448 goto err0;
449 }
450 p->clk = NULL;
451 }
452
453 pm_runtime_enable(dev); 434 pm_runtime_enable(dev);
454 435
455 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 436 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -531,11 +512,24 @@ static int gpio_rcar_remove(struct platform_device *pdev)
531 return 0; 512 return 0;
532} 513}
533 514
515static int __maybe_unused gpio_rcar_suspend(struct device *dev)
516{
517 struct gpio_rcar_priv *p = dev_get_drvdata(dev);
518
519 if (atomic_read(&p->wakeup_path))
520 device_set_wakeup_path(dev);
521
522 return 0;
523}
524
525static SIMPLE_DEV_PM_OPS(gpio_rcar_pm_ops, gpio_rcar_suspend, NULL);
526
534static struct platform_driver gpio_rcar_device_driver = { 527static struct platform_driver gpio_rcar_device_driver = {
535 .probe = gpio_rcar_probe, 528 .probe = gpio_rcar_probe,
536 .remove = gpio_rcar_remove, 529 .remove = gpio_rcar_remove,
537 .driver = { 530 .driver = {
538 .name = "gpio_rcar", 531 .name = "gpio_rcar",
532 .pm = &gpio_rcar_pm_ops,
539 .of_match_table = of_match_ptr(gpio_rcar_of_table), 533 .of_match_table = of_match_ptr(gpio_rcar_of_table),
540 } 534 }
541}; 535};
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 564bb7a31da4..84e5a9df2344 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -241,6 +241,19 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
241 241
242 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, 242 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
243 &of_flags); 243 &of_flags);
244 /*
245 * -EPROBE_DEFER in our case means that we found a
246 * valid GPIO property, but no controller has been
247 * registered so far.
248 *
249 * This means we don't need to look any further for
250 * alternate name conventions, and we should really
251 * preserve the return code for our user to be able to
252 * retry probing later.
253 */
254 if (IS_ERR(desc) && PTR_ERR(desc) == -EPROBE_DEFER)
255 return desc;
256
244 if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) 257 if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
245 break; 258 break;
246 } 259 }
@@ -250,7 +263,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
250 desc = of_find_spi_gpio(dev, con_id, &of_flags); 263 desc = of_find_spi_gpio(dev, con_id, &of_flags);
251 264
252 /* Special handling for regulator GPIOs if used */ 265 /* Special handling for regulator GPIOs if used */
253 if (IS_ERR(desc)) 266 if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER)
254 desc = of_find_regulator_gpio(dev, con_id, &of_flags); 267 desc = of_find_regulator_gpio(dev, con_id, &of_flags);
255 268
256 if (IS_ERR(desc)) 269 if (IS_ERR(desc))
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
index 9da8d5802980..96501ff0e55b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -729,9 +729,11 @@ amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force)
729 enum drm_connector_status ret = connector_status_disconnected; 729 enum drm_connector_status ret = connector_status_disconnected;
730 int r; 730 int r;
731 731
732 r = pm_runtime_get_sync(connector->dev->dev); 732 if (!drm_kms_helper_is_poll_worker()) {
733 if (r < 0) 733 r = pm_runtime_get_sync(connector->dev->dev);
734 return connector_status_disconnected; 734 if (r < 0)
735 return connector_status_disconnected;
736 }
735 737
736 if (encoder) { 738 if (encoder) {
737 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 739 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
@@ -750,8 +752,12 @@ amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force)
750 /* check acpi lid status ??? */ 752 /* check acpi lid status ??? */
751 753
752 amdgpu_connector_update_scratch_regs(connector, ret); 754 amdgpu_connector_update_scratch_regs(connector, ret);
753 pm_runtime_mark_last_busy(connector->dev->dev); 755
754 pm_runtime_put_autosuspend(connector->dev->dev); 756 if (!drm_kms_helper_is_poll_worker()) {
757 pm_runtime_mark_last_busy(connector->dev->dev);
758 pm_runtime_put_autosuspend(connector->dev->dev);
759 }
760
755 return ret; 761 return ret;
756} 762}
757 763
@@ -861,9 +867,11 @@ amdgpu_connector_vga_detect(struct drm_connector *connector, bool force)
861 enum drm_connector_status ret = connector_status_disconnected; 867 enum drm_connector_status ret = connector_status_disconnected;
862 int r; 868 int r;
863 869
864 r = pm_runtime_get_sync(connector->dev->dev); 870 if (!drm_kms_helper_is_poll_worker()) {
865 if (r < 0) 871 r = pm_runtime_get_sync(connector->dev->dev);
866 return connector_status_disconnected; 872 if (r < 0)
873 return connector_status_disconnected;
874 }
867 875
868 encoder = amdgpu_connector_best_single_encoder(connector); 876 encoder = amdgpu_connector_best_single_encoder(connector);
869 if (!encoder) 877 if (!encoder)
@@ -917,8 +925,10 @@ amdgpu_connector_vga_detect(struct drm_connector *connector, bool force)
917 amdgpu_connector_update_scratch_regs(connector, ret); 925 amdgpu_connector_update_scratch_regs(connector, ret);
918 926
919out: 927out:
920 pm_runtime_mark_last_busy(connector->dev->dev); 928 if (!drm_kms_helper_is_poll_worker()) {
921 pm_runtime_put_autosuspend(connector->dev->dev); 929 pm_runtime_mark_last_busy(connector->dev->dev);
930 pm_runtime_put_autosuspend(connector->dev->dev);
931 }
922 932
923 return ret; 933 return ret;
924} 934}
@@ -981,9 +991,11 @@ amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force)
981 enum drm_connector_status ret = connector_status_disconnected; 991 enum drm_connector_status ret = connector_status_disconnected;
982 bool dret = false, broken_edid = false; 992 bool dret = false, broken_edid = false;
983 993
984 r = pm_runtime_get_sync(connector->dev->dev); 994 if (!drm_kms_helper_is_poll_worker()) {
985 if (r < 0) 995 r = pm_runtime_get_sync(connector->dev->dev);
986 return connector_status_disconnected; 996 if (r < 0)
997 return connector_status_disconnected;
998 }
987 999
988 if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) { 1000 if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) {
989 ret = connector->status; 1001 ret = connector->status;
@@ -1108,8 +1120,10 @@ out:
1108 amdgpu_connector_update_scratch_regs(connector, ret); 1120 amdgpu_connector_update_scratch_regs(connector, ret);
1109 1121
1110exit: 1122exit:
1111 pm_runtime_mark_last_busy(connector->dev->dev); 1123 if (!drm_kms_helper_is_poll_worker()) {
1112 pm_runtime_put_autosuspend(connector->dev->dev); 1124 pm_runtime_mark_last_busy(connector->dev->dev);
1125 pm_runtime_put_autosuspend(connector->dev->dev);
1126 }
1113 1127
1114 return ret; 1128 return ret;
1115} 1129}
@@ -1352,9 +1366,11 @@ amdgpu_connector_dp_detect(struct drm_connector *connector, bool force)
1352 struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector); 1366 struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
1353 int r; 1367 int r;
1354 1368
1355 r = pm_runtime_get_sync(connector->dev->dev); 1369 if (!drm_kms_helper_is_poll_worker()) {
1356 if (r < 0) 1370 r = pm_runtime_get_sync(connector->dev->dev);
1357 return connector_status_disconnected; 1371 if (r < 0)
1372 return connector_status_disconnected;
1373 }
1358 1374
1359 if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) { 1375 if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) {
1360 ret = connector->status; 1376 ret = connector->status;
@@ -1424,8 +1440,10 @@ amdgpu_connector_dp_detect(struct drm_connector *connector, bool force)
1424 1440
1425 amdgpu_connector_update_scratch_regs(connector, ret); 1441 amdgpu_connector_update_scratch_regs(connector, ret);
1426out: 1442out:
1427 pm_runtime_mark_last_busy(connector->dev->dev); 1443 if (!drm_kms_helper_is_poll_worker()) {
1428 pm_runtime_put_autosuspend(connector->dev->dev); 1444 pm_runtime_mark_last_busy(connector->dev->dev);
1445 pm_runtime_put_autosuspend(connector->dev->dev);
1446 }
1429 1447
1430 return ret; 1448 return ret;
1431} 1449}
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 13a5362d074e..e42a28e3adc5 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3172,8 +3172,6 @@ static int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
3172 3172
3173 switch (aplane->base.type) { 3173 switch (aplane->base.type) {
3174 case DRM_PLANE_TYPE_PRIMARY: 3174 case DRM_PLANE_TYPE_PRIMARY:
3175 aplane->base.format_default = true;
3176
3177 res = drm_universal_plane_init( 3175 res = drm_universal_plane_init(
3178 dm->adev->ddev, 3176 dm->adev->ddev,
3179 &aplane->base, 3177 &aplane->base,
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
index 9ab69b22b989..ca0b08bfa2cf 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
@@ -109,7 +109,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(
109 struct cea_sad *sad = &sads[i]; 109 struct cea_sad *sad = &sads[i];
110 110
111 edid_caps->audio_modes[i].format_code = sad->format; 111 edid_caps->audio_modes[i].format_code = sad->format;
112 edid_caps->audio_modes[i].channel_count = sad->channels; 112 edid_caps->audio_modes[i].channel_count = sad->channels + 1;
113 edid_caps->audio_modes[i].sample_rate = sad->freq; 113 edid_caps->audio_modes[i].sample_rate = sad->freq;
114 edid_caps->audio_modes[i].sample_size = sad->byte2; 114 edid_caps->audio_modes[i].sample_size = sad->byte2;
115 } 115 }
diff --git a/drivers/gpu/drm/amd/display/dc/dce/dce_opp.c b/drivers/gpu/drm/amd/display/dc/dce/dce_opp.c
index 3931412ab6d3..87093894ea9e 100644
--- a/drivers/gpu/drm/amd/display/dc/dce/dce_opp.c
+++ b/drivers/gpu/drm/amd/display/dc/dce/dce_opp.c
@@ -128,23 +128,22 @@ static void set_truncation(
128 return; 128 return;
129 } 129 }
130 /* on other format-to do */ 130 /* on other format-to do */
131 if (params->flags.TRUNCATE_ENABLED == 0 || 131 if (params->flags.TRUNCATE_ENABLED == 0)
132 params->flags.TRUNCATE_DEPTH == 2)
133 return; 132 return;
134 /*Set truncation depth and Enable truncation*/ 133 /*Set truncation depth and Enable truncation*/
135 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL, 134 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
136 FMT_TRUNCATE_EN, 1, 135 FMT_TRUNCATE_EN, 1,
137 FMT_TRUNCATE_DEPTH, 136 FMT_TRUNCATE_DEPTH,
138 params->flags.TRUNCATE_MODE, 137 params->flags.TRUNCATE_DEPTH,
139 FMT_TRUNCATE_MODE, 138 FMT_TRUNCATE_MODE,
140 params->flags.TRUNCATE_DEPTH); 139 params->flags.TRUNCATE_MODE);
141} 140}
142 141
143 142
144/** 143/**
145 * set_spatial_dither 144 * set_spatial_dither
146 * 1) set spatial dithering mode: pattern of seed 145 * 1) set spatial dithering mode: pattern of seed
147 * 2) set spatical dithering depth: 0 for 18bpp or 1 for 24bpp 146 * 2) set spatial dithering depth: 0 for 18bpp or 1 for 24bpp
148 * 3) set random seed 147 * 3) set random seed
149 * 4) set random mode 148 * 4) set random mode
150 * lfsr is reset every frame or not reset 149 * lfsr is reset every frame or not reset
diff --git a/drivers/gpu/drm/ast/ast_tables.h b/drivers/gpu/drm/ast/ast_tables.h
index 5f4c2e833a65..d665dd5af5dd 100644
--- a/drivers/gpu/drm/ast/ast_tables.h
+++ b/drivers/gpu/drm/ast/ast_tables.h
@@ -97,7 +97,7 @@ static const struct ast_vbios_dclk_info dclk_table[] = {
97 {0x67, 0x22, 0x00}, /* 0E: VCLK157_5 */ 97 {0x67, 0x22, 0x00}, /* 0E: VCLK157_5 */
98 {0x6A, 0x22, 0x00}, /* 0F: VCLK162 */ 98 {0x6A, 0x22, 0x00}, /* 0F: VCLK162 */
99 {0x4d, 0x4c, 0x80}, /* 10: VCLK154 */ 99 {0x4d, 0x4c, 0x80}, /* 10: VCLK154 */
100 {0xa7, 0x78, 0x80}, /* 11: VCLK83.5 */ 100 {0x68, 0x6f, 0x80}, /* 11: VCLK83.5 */
101 {0x28, 0x49, 0x80}, /* 12: VCLK106.5 */ 101 {0x28, 0x49, 0x80}, /* 12: VCLK106.5 */
102 {0x37, 0x49, 0x80}, /* 13: VCLK146.25 */ 102 {0x37, 0x49, 0x80}, /* 13: VCLK146.25 */
103 {0x1f, 0x45, 0x80}, /* 14: VCLK148.5 */ 103 {0x1f, 0x45, 0x80}, /* 14: VCLK148.5 */
@@ -127,7 +127,7 @@ static const struct ast_vbios_dclk_info dclk_table_ast2500[] = {
127 {0x67, 0x22, 0x00}, /* 0E: VCLK157_5 */ 127 {0x67, 0x22, 0x00}, /* 0E: VCLK157_5 */
128 {0x6A, 0x22, 0x00}, /* 0F: VCLK162 */ 128 {0x6A, 0x22, 0x00}, /* 0F: VCLK162 */
129 {0x4d, 0x4c, 0x80}, /* 10: VCLK154 */ 129 {0x4d, 0x4c, 0x80}, /* 10: VCLK154 */
130 {0xa7, 0x78, 0x80}, /* 11: VCLK83.5 */ 130 {0x68, 0x6f, 0x80}, /* 11: VCLK83.5 */
131 {0x28, 0x49, 0x80}, /* 12: VCLK106.5 */ 131 {0x28, 0x49, 0x80}, /* 12: VCLK106.5 */
132 {0x37, 0x49, 0x80}, /* 13: VCLK146.25 */ 132 {0x37, 0x49, 0x80}, /* 13: VCLK146.25 */
133 {0x1f, 0x45, 0x80}, /* 14: VCLK148.5 */ 133 {0x1f, 0x45, 0x80}, /* 14: VCLK148.5 */
diff --git a/drivers/gpu/drm/cirrus/cirrus_mode.c b/drivers/gpu/drm/cirrus/cirrus_mode.c
index cd23b1b28259..c91b9b054e3f 100644
--- a/drivers/gpu/drm/cirrus/cirrus_mode.c
+++ b/drivers/gpu/drm/cirrus/cirrus_mode.c
@@ -294,22 +294,7 @@ static void cirrus_crtc_prepare(struct drm_crtc *crtc)
294{ 294{
295} 295}
296 296
297/* 297static void cirrus_crtc_load_lut(struct drm_crtc *crtc)
298 * This is called after a mode is programmed. It should reverse anything done
299 * by the prepare function
300 */
301static void cirrus_crtc_commit(struct drm_crtc *crtc)
302{
303}
304
305/*
306 * The core can pass us a set of gamma values to program. We actually only
307 * use this for 8-bit mode so can't perform smooth fades on deeper modes,
308 * but it's a requirement that we provide the function
309 */
310static int cirrus_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
311 u16 *blue, uint32_t size,
312 struct drm_modeset_acquire_ctx *ctx)
313{ 298{
314 struct drm_device *dev = crtc->dev; 299 struct drm_device *dev = crtc->dev;
315 struct cirrus_device *cdev = dev->dev_private; 300 struct cirrus_device *cdev = dev->dev_private;
@@ -317,7 +302,7 @@ static int cirrus_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
317 int i; 302 int i;
318 303
319 if (!crtc->enabled) 304 if (!crtc->enabled)
320 return 0; 305 return;
321 306
322 r = crtc->gamma_store; 307 r = crtc->gamma_store;
323 g = r + crtc->gamma_size; 308 g = r + crtc->gamma_size;
@@ -330,6 +315,27 @@ static int cirrus_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
330 WREG8(PALETTE_DATA, *g++ >> 8); 315 WREG8(PALETTE_DATA, *g++ >> 8);
331 WREG8(PALETTE_DATA, *b++ >> 8); 316 WREG8(PALETTE_DATA, *b++ >> 8);
332 } 317 }
318}
319
320/*
321 * This is called after a mode is programmed. It should reverse anything done
322 * by the prepare function
323 */
324static void cirrus_crtc_commit(struct drm_crtc *crtc)
325{
326 cirrus_crtc_load_lut(crtc);
327}
328
329/*
330 * The core can pass us a set of gamma values to program. We actually only
331 * use this for 8-bit mode so can't perform smooth fades on deeper modes,
332 * but it's a requirement that we provide the function
333 */
334static int cirrus_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
335 u16 *blue, uint32_t size,
336 struct drm_modeset_acquire_ctx *ctx)
337{
338 cirrus_crtc_load_lut(crtc);
333 339
334 return 0; 340 return 0;
335} 341}
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 49147b2aa288..134069f36482 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -113,6 +113,9 @@ static const struct edid_quirk {
113 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */ 113 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
114 { "AEO", 0, EDID_QUIRK_FORCE_6BPC }, 114 { "AEO", 0, EDID_QUIRK_FORCE_6BPC },
115 115
116 /* CPT panel of Asus UX303LA reports 8 bpc, but is a 6 bpc panel */
117 { "CPT", 0x17df, EDID_QUIRK_FORCE_6BPC },
118
116 /* Belinea 10 15 55 */ 119 /* Belinea 10 15 55 */
117 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 }, 120 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
118 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 }, 121 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
@@ -162,6 +165,24 @@ static const struct edid_quirk {
162 165
163 /* HTC Vive VR Headset */ 166 /* HTC Vive VR Headset */
164 { "HVR", 0xaa01, EDID_QUIRK_NON_DESKTOP }, 167 { "HVR", 0xaa01, EDID_QUIRK_NON_DESKTOP },
168
169 /* Oculus Rift DK1, DK2, and CV1 VR Headsets */
170 { "OVR", 0x0001, EDID_QUIRK_NON_DESKTOP },
171 { "OVR", 0x0003, EDID_QUIRK_NON_DESKTOP },
172 { "OVR", 0x0004, EDID_QUIRK_NON_DESKTOP },
173
174 /* Windows Mixed Reality Headsets */
175 { "ACR", 0x7fce, EDID_QUIRK_NON_DESKTOP },
176 { "HPN", 0x3515, EDID_QUIRK_NON_DESKTOP },
177 { "LEN", 0x0408, EDID_QUIRK_NON_DESKTOP },
178 { "LEN", 0xb800, EDID_QUIRK_NON_DESKTOP },
179 { "FUJ", 0x1970, EDID_QUIRK_NON_DESKTOP },
180 { "DEL", 0x7fce, EDID_QUIRK_NON_DESKTOP },
181 { "SEC", 0x144a, EDID_QUIRK_NON_DESKTOP },
182 { "AUS", 0xc102, EDID_QUIRK_NON_DESKTOP },
183
184 /* Sony PlayStation VR Headset */
185 { "SNY", 0x0704, EDID_QUIRK_NON_DESKTOP },
165}; 186};
166 187
167/* 188/*
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index 0eebe8ba8a2c..ad67203de715 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -121,6 +121,10 @@ int drm_mode_addfb(struct drm_device *dev,
121 r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth); 121 r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth);
122 r.handles[0] = or->handle; 122 r.handles[0] = or->handle;
123 123
124 if (r.pixel_format == DRM_FORMAT_XRGB2101010 &&
125 dev->driver->driver_features & DRIVER_PREFER_XBGR_30BPP)
126 r.pixel_format = DRM_FORMAT_XBGR2101010;
127
124 ret = drm_mode_addfb2(dev, &r, file_priv); 128 ret = drm_mode_addfb2(dev, &r, file_priv);
125 if (ret) 129 if (ret)
126 return ret; 130 return ret;
@@ -458,6 +462,12 @@ int drm_mode_getfb(struct drm_device *dev,
458 if (!fb) 462 if (!fb)
459 return -ENOENT; 463 return -ENOENT;
460 464
465 /* Multi-planar framebuffers need getfb2. */
466 if (fb->format->num_planes > 1) {
467 ret = -EINVAL;
468 goto out;
469 }
470
461 r->height = fb->height; 471 r->height = fb->height;
462 r->width = fb->width; 472 r->width = fb->width;
463 r->depth = fb->format->depth; 473 r->depth = fb->format->depth;
@@ -481,6 +491,7 @@ int drm_mode_getfb(struct drm_device *dev,
481 ret = -ENODEV; 491 ret = -ENODEV;
482 } 492 }
483 493
494out:
484 drm_framebuffer_put(fb); 495 drm_framebuffer_put(fb);
485 496
486 return ret; 497 return ret;
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index a351bd888a61..3166026a1874 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -837,9 +837,24 @@ struct drm_mm_node *drm_mm_scan_color_evict(struct drm_mm_scan *scan)
837 if (!mm->color_adjust) 837 if (!mm->color_adjust)
838 return NULL; 838 return NULL;
839 839
840 hole = list_first_entry(&mm->hole_stack, typeof(*hole), hole_stack); 840 /*
841 hole_start = __drm_mm_hole_node_start(hole); 841 * The hole found during scanning should ideally be the first element
842 hole_end = hole_start + hole->hole_size; 842 * in the hole_stack list, but due to side-effects in the driver it
843 * may not be.
844 */
845 list_for_each_entry(hole, &mm->hole_stack, hole_stack) {
846 hole_start = __drm_mm_hole_node_start(hole);
847 hole_end = hole_start + hole->hole_size;
848
849 if (hole_start <= scan->hit_start &&
850 hole_end >= scan->hit_end)
851 break;
852 }
853
854 /* We should only be called after we found the hole previously */
855 DRM_MM_BUG_ON(&hole->hole_stack == &mm->hole_stack);
856 if (unlikely(&hole->hole_stack == &mm->hole_stack))
857 return NULL;
843 858
844 DRM_MM_BUG_ON(hole_start > scan->hit_start); 859 DRM_MM_BUG_ON(hole_start > scan->hit_start);
845 DRM_MM_BUG_ON(hole_end < scan->hit_end); 860 DRM_MM_BUG_ON(hole_end < scan->hit_end);
diff --git a/drivers/gpu/drm/drm_probe_helper.c b/drivers/gpu/drm/drm_probe_helper.c
index 2d1643bdae78..527743394150 100644
--- a/drivers/gpu/drm/drm_probe_helper.c
+++ b/drivers/gpu/drm/drm_probe_helper.c
@@ -654,6 +654,26 @@ out:
654} 654}
655 655
656/** 656/**
657 * drm_kms_helper_is_poll_worker - is %current task an output poll worker?
658 *
659 * Determine if %current task is an output poll worker. This can be used
660 * to select distinct code paths for output polling versus other contexts.
661 *
662 * One use case is to avoid a deadlock between the output poll worker and
663 * the autosuspend worker wherein the latter waits for polling to finish
664 * upon calling drm_kms_helper_poll_disable(), while the former waits for
665 * runtime suspend to finish upon calling pm_runtime_get_sync() in a
666 * connector ->detect hook.
667 */
668bool drm_kms_helper_is_poll_worker(void)
669{
670 struct work_struct *work = current_work();
671
672 return work && work->func == output_poll_execute;
673}
674EXPORT_SYMBOL(drm_kms_helper_is_poll_worker);
675
676/**
657 * drm_kms_helper_poll_disable - disable output polling 677 * drm_kms_helper_poll_disable - disable output polling
658 * @dev: drm_device 678 * @dev: drm_device
659 * 679 *
diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index 2b8bf2dd6387..f68ef1b3a28c 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -286,7 +286,6 @@ static int g2d_init_cmdlist(struct g2d_data *g2d)
286 286
287 node = kcalloc(G2D_CMDLIST_NUM, sizeof(*node), GFP_KERNEL); 287 node = kcalloc(G2D_CMDLIST_NUM, sizeof(*node), GFP_KERNEL);
288 if (!node) { 288 if (!node) {
289 dev_err(dev, "failed to allocate memory\n");
290 ret = -ENOMEM; 289 ret = -ENOMEM;
291 goto err; 290 goto err;
292 } 291 }
@@ -926,7 +925,7 @@ static void g2d_finish_event(struct g2d_data *g2d, u32 cmdlist_no)
926 struct drm_device *drm_dev = g2d->subdrv.drm_dev; 925 struct drm_device *drm_dev = g2d->subdrv.drm_dev;
927 struct g2d_runqueue_node *runqueue_node = g2d->runqueue_node; 926 struct g2d_runqueue_node *runqueue_node = g2d->runqueue_node;
928 struct drm_exynos_pending_g2d_event *e; 927 struct drm_exynos_pending_g2d_event *e;
929 struct timeval now; 928 struct timespec64 now;
930 929
931 if (list_empty(&runqueue_node->event_list)) 930 if (list_empty(&runqueue_node->event_list))
932 return; 931 return;
@@ -934,9 +933,9 @@ static void g2d_finish_event(struct g2d_data *g2d, u32 cmdlist_no)
934 e = list_first_entry(&runqueue_node->event_list, 933 e = list_first_entry(&runqueue_node->event_list,
935 struct drm_exynos_pending_g2d_event, base.link); 934 struct drm_exynos_pending_g2d_event, base.link);
936 935
937 do_gettimeofday(&now); 936 ktime_get_ts64(&now);
938 e->event.tv_sec = now.tv_sec; 937 e->event.tv_sec = now.tv_sec;
939 e->event.tv_usec = now.tv_usec; 938 e->event.tv_usec = now.tv_nsec / NSEC_PER_USEC;
940 e->event.cmdlist_no = cmdlist_no; 939 e->event.cmdlist_no = cmdlist_no;
941 940
942 drm_send_event(drm_dev, &e->base); 941 drm_send_event(drm_dev, &e->base);
@@ -1358,10 +1357,9 @@ int exynos_g2d_exec_ioctl(struct drm_device *drm_dev, void *data,
1358 return -EFAULT; 1357 return -EFAULT;
1359 1358
1360 runqueue_node = kmem_cache_alloc(g2d->runqueue_slab, GFP_KERNEL); 1359 runqueue_node = kmem_cache_alloc(g2d->runqueue_slab, GFP_KERNEL);
1361 if (!runqueue_node) { 1360 if (!runqueue_node)
1362 dev_err(dev, "failed to allocate memory\n");
1363 return -ENOMEM; 1361 return -ENOMEM;
1364 } 1362
1365 run_cmdlist = &runqueue_node->run_cmdlist; 1363 run_cmdlist = &runqueue_node->run_cmdlist;
1366 event_list = &runqueue_node->event_list; 1364 event_list = &runqueue_node->event_list;
1367 INIT_LIST_HEAD(run_cmdlist); 1365 INIT_LIST_HEAD(run_cmdlist);
diff --git a/drivers/gpu/drm/exynos/exynos_drm_rotator.h b/drivers/gpu/drm/exynos/exynos_drm_rotator.h
deleted file mode 100644
index 71a0b4c0c1e8..000000000000
--- a/drivers/gpu/drm/exynos/exynos_drm_rotator.h
+++ /dev/null
@@ -1,19 +0,0 @@
1/*
2 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 *
4 * Authors:
5 * YoungJun Cho <yj44.cho@samsung.com>
6 * Eunchul Kim <chulspro.kim@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#ifndef _EXYNOS_DRM_ROTATOR_H_
15#define _EXYNOS_DRM_ROTATOR_H_
16
17/* TODO */
18
19#endif
diff --git a/drivers/gpu/drm/exynos/exynos_hdmi.c b/drivers/gpu/drm/exynos/exynos_hdmi.c
index a4b75a46f946..abd84cbcf1c2 100644
--- a/drivers/gpu/drm/exynos/exynos_hdmi.c
+++ b/drivers/gpu/drm/exynos/exynos_hdmi.c
@@ -1068,10 +1068,13 @@ static void hdmi_audio_config(struct hdmi_context *hdata)
1068 /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */ 1068 /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
1069 hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5) 1069 hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
1070 | HDMI_I2S_SEL_LRCK(6)); 1070 | HDMI_I2S_SEL_LRCK(6));
1071 hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1) 1071
1072 | HDMI_I2S_SEL_SDATA2(4)); 1072 hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(3)
1073 | HDMI_I2S_SEL_SDATA0(4));
1074
1073 hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1) 1075 hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
1074 | HDMI_I2S_SEL_SDATA2(2)); 1076 | HDMI_I2S_SEL_SDATA2(2));
1077
1075 hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0)); 1078 hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
1076 1079
1077 /* I2S_CON_1 & 2 */ 1080 /* I2S_CON_1 & 2 */
diff --git a/drivers/gpu/drm/exynos/regs-fimc.h b/drivers/gpu/drm/exynos/regs-fimc.h
index 30496134a3d0..d7cbe53c4c01 100644
--- a/drivers/gpu/drm/exynos/regs-fimc.h
+++ b/drivers/gpu/drm/exynos/regs-fimc.h
@@ -569,7 +569,7 @@
569#define EXYNOS_CIIMGEFF_FIN_EMBOSSING (4 << 26) 569#define EXYNOS_CIIMGEFF_FIN_EMBOSSING (4 << 26)
570#define EXYNOS_CIIMGEFF_FIN_SILHOUETTE (5 << 26) 570#define EXYNOS_CIIMGEFF_FIN_SILHOUETTE (5 << 26)
571#define EXYNOS_CIIMGEFF_FIN_MASK (7 << 26) 571#define EXYNOS_CIIMGEFF_FIN_MASK (7 << 26)
572#define EXYNOS_CIIMGEFF_PAT_CBCR_MASK ((0xff < 13) | (0xff < 0)) 572#define EXYNOS_CIIMGEFF_PAT_CBCR_MASK ((0xff << 13) | (0xff << 0))
573 573
574/* Real input DMA size register */ 574/* Real input DMA size register */
575#define EXYNOS_CIREAL_ISIZE_AUTOLOAD_ENABLE (1 << 31) 575#define EXYNOS_CIREAL_ISIZE_AUTOLOAD_ENABLE (1 << 31)
diff --git a/drivers/gpu/drm/exynos/regs-hdmi.h b/drivers/gpu/drm/exynos/regs-hdmi.h
index 04be0f7e8193..4420c203ac85 100644
--- a/drivers/gpu/drm/exynos/regs-hdmi.h
+++ b/drivers/gpu/drm/exynos/regs-hdmi.h
@@ -464,7 +464,7 @@
464 464
465/* I2S_PIN_SEL_1 */ 465/* I2S_PIN_SEL_1 */
466#define HDMI_I2S_SEL_SDATA1(x) (((x) & 0x7) << 4) 466#define HDMI_I2S_SEL_SDATA1(x) (((x) & 0x7) << 4)
467#define HDMI_I2S_SEL_SDATA2(x) ((x) & 0x7) 467#define HDMI_I2S_SEL_SDATA0(x) ((x) & 0x7)
468 468
469/* I2S_PIN_SEL_2 */ 469/* I2S_PIN_SEL_2 */
470#define HDMI_I2S_SEL_SDATA3(x) (((x) & 0x7) << 4) 470#define HDMI_I2S_SEL_SDATA3(x) (((x) & 0x7) << 4)
diff --git a/drivers/gpu/drm/i915/gvt/cmd_parser.c b/drivers/gpu/drm/i915/gvt/cmd_parser.c
index c8454ac43fae..db6b94dda5df 100644
--- a/drivers/gpu/drm/i915/gvt/cmd_parser.c
+++ b/drivers/gpu/drm/i915/gvt/cmd_parser.c
@@ -471,6 +471,7 @@ struct parser_exec_state {
471 * used when ret from 2nd level batch buffer 471 * used when ret from 2nd level batch buffer
472 */ 472 */
473 int saved_buf_addr_type; 473 int saved_buf_addr_type;
474 bool is_ctx_wa;
474 475
475 struct cmd_info *info; 476 struct cmd_info *info;
476 477
@@ -1715,6 +1716,11 @@ static int perform_bb_shadow(struct parser_exec_state *s)
1715 bb->accessing = true; 1716 bb->accessing = true;
1716 bb->bb_start_cmd_va = s->ip_va; 1717 bb->bb_start_cmd_va = s->ip_va;
1717 1718
1719 if ((s->buf_type == BATCH_BUFFER_INSTRUCTION) && (!s->is_ctx_wa))
1720 bb->bb_offset = s->ip_va - s->rb_va;
1721 else
1722 bb->bb_offset = 0;
1723
1718 /* 1724 /*
1719 * ip_va saves the virtual address of the shadow batch buffer, while 1725 * ip_va saves the virtual address of the shadow batch buffer, while
1720 * ip_gma saves the graphics address of the original batch buffer. 1726 * ip_gma saves the graphics address of the original batch buffer.
@@ -2571,6 +2577,7 @@ static int scan_workload(struct intel_vgpu_workload *workload)
2571 s.ring_tail = gma_tail; 2577 s.ring_tail = gma_tail;
2572 s.rb_va = workload->shadow_ring_buffer_va; 2578 s.rb_va = workload->shadow_ring_buffer_va;
2573 s.workload = workload; 2579 s.workload = workload;
2580 s.is_ctx_wa = false;
2574 2581
2575 if ((bypass_scan_mask & (1 << workload->ring_id)) || 2582 if ((bypass_scan_mask & (1 << workload->ring_id)) ||
2576 gma_head == gma_tail) 2583 gma_head == gma_tail)
@@ -2624,6 +2631,7 @@ static int scan_wa_ctx(struct intel_shadow_wa_ctx *wa_ctx)
2624 s.ring_tail = gma_tail; 2631 s.ring_tail = gma_tail;
2625 s.rb_va = wa_ctx->indirect_ctx.shadow_va; 2632 s.rb_va = wa_ctx->indirect_ctx.shadow_va;
2626 s.workload = workload; 2633 s.workload = workload;
2634 s.is_ctx_wa = true;
2627 2635
2628 if (!intel_gvt_ggtt_validate_range(s.vgpu, s.ring_start, s.ring_size)) { 2636 if (!intel_gvt_ggtt_validate_range(s.vgpu, s.ring_start, s.ring_size)) {
2629 ret = -EINVAL; 2637 ret = -EINVAL;
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 520fe3d0a882..c16a492449d7 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -750,6 +750,25 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf,
750 return ret == 0 ? count : ret; 750 return ret == 0 ? count : ret;
751} 751}
752 752
753static bool gtt_entry(struct mdev_device *mdev, loff_t *ppos)
754{
755 struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
756 unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
757 struct intel_gvt *gvt = vgpu->gvt;
758 int offset;
759
760 /* Only allow MMIO GGTT entry access */
761 if (index != PCI_BASE_ADDRESS_0)
762 return false;
763
764 offset = (u64)(*ppos & VFIO_PCI_OFFSET_MASK) -
765 intel_vgpu_get_bar_gpa(vgpu, PCI_BASE_ADDRESS_0);
766
767 return (offset >= gvt->device_info.gtt_start_offset &&
768 offset < gvt->device_info.gtt_start_offset + gvt_ggtt_sz(gvt)) ?
769 true : false;
770}
771
753static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf, 772static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf,
754 size_t count, loff_t *ppos) 773 size_t count, loff_t *ppos)
755{ 774{
@@ -759,7 +778,21 @@ static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf,
759 while (count) { 778 while (count) {
760 size_t filled; 779 size_t filled;
761 780
762 if (count >= 4 && !(*ppos % 4)) { 781 /* Only support GGTT entry 8 bytes read */
782 if (count >= 8 && !(*ppos % 8) &&
783 gtt_entry(mdev, ppos)) {
784 u64 val;
785
786 ret = intel_vgpu_rw(mdev, (char *)&val, sizeof(val),
787 ppos, false);
788 if (ret <= 0)
789 goto read_err;
790
791 if (copy_to_user(buf, &val, sizeof(val)))
792 goto read_err;
793
794 filled = 8;
795 } else if (count >= 4 && !(*ppos % 4)) {
763 u32 val; 796 u32 val;
764 797
765 ret = intel_vgpu_rw(mdev, (char *)&val, sizeof(val), 798 ret = intel_vgpu_rw(mdev, (char *)&val, sizeof(val),
@@ -819,7 +852,21 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev,
819 while (count) { 852 while (count) {
820 size_t filled; 853 size_t filled;
821 854
822 if (count >= 4 && !(*ppos % 4)) { 855 /* Only support GGTT entry 8 bytes write */
856 if (count >= 8 && !(*ppos % 8) &&
857 gtt_entry(mdev, ppos)) {
858 u64 val;
859
860 if (copy_from_user(&val, buf, sizeof(val)))
861 goto write_err;
862
863 ret = intel_vgpu_rw(mdev, (char *)&val, sizeof(val),
864 ppos, true);
865 if (ret <= 0)
866 goto write_err;
867
868 filled = 8;
869 } else if (count >= 4 && !(*ppos % 4)) {
823 u32 val; 870 u32 val;
824 871
825 if (copy_from_user(&val, buf, sizeof(val))) 872 if (copy_from_user(&val, buf, sizeof(val)))
diff --git a/drivers/gpu/drm/i915/gvt/mmio_context.c b/drivers/gpu/drm/i915/gvt/mmio_context.c
index 74a9c7b5516e..a5bac83d53a9 100644
--- a/drivers/gpu/drm/i915/gvt/mmio_context.c
+++ b/drivers/gpu/drm/i915/gvt/mmio_context.c
@@ -120,6 +120,7 @@ static struct engine_mmio gen9_engine_mmio_list[] __cacheline_aligned = {
120 {RCS, HALF_SLICE_CHICKEN3, 0xffff, true}, /* 0xe184 */ 120 {RCS, HALF_SLICE_CHICKEN3, 0xffff, true}, /* 0xe184 */
121 {RCS, GEN9_HALF_SLICE_CHICKEN5, 0xffff, true}, /* 0xe188 */ 121 {RCS, GEN9_HALF_SLICE_CHICKEN5, 0xffff, true}, /* 0xe188 */
122 {RCS, GEN9_HALF_SLICE_CHICKEN7, 0xffff, true}, /* 0xe194 */ 122 {RCS, GEN9_HALF_SLICE_CHICKEN7, 0xffff, true}, /* 0xe194 */
123 {RCS, GEN8_ROW_CHICKEN, 0xffff, true}, /* 0xe4f0 */
123 {RCS, TRVATTL3PTRDW(0), 0, false}, /* 0x4de0 */ 124 {RCS, TRVATTL3PTRDW(0), 0, false}, /* 0x4de0 */
124 {RCS, TRVATTL3PTRDW(1), 0, false}, /* 0x4de4 */ 125 {RCS, TRVATTL3PTRDW(1), 0, false}, /* 0x4de4 */
125 {RCS, TRNULLDETCT, 0, false}, /* 0x4de8 */ 126 {RCS, TRNULLDETCT, 0, false}, /* 0x4de8 */
@@ -557,9 +558,11 @@ void intel_gvt_switch_mmio(struct intel_vgpu *pre,
557 * performace for batch mmio read/write, so we need 558 * performace for batch mmio read/write, so we need
558 * handle forcewake mannually. 559 * handle forcewake mannually.
559 */ 560 */
561 intel_runtime_pm_get(dev_priv);
560 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); 562 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
561 switch_mmio(pre, next, ring_id); 563 switch_mmio(pre, next, ring_id);
562 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); 564 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
565 intel_runtime_pm_put(dev_priv);
563} 566}
564 567
565/** 568/**
diff --git a/drivers/gpu/drm/i915/gvt/scheduler.c b/drivers/gpu/drm/i915/gvt/scheduler.c
index a55b4975c154..638abe84857c 100644
--- a/drivers/gpu/drm/i915/gvt/scheduler.c
+++ b/drivers/gpu/drm/i915/gvt/scheduler.c
@@ -75,6 +75,54 @@ static void update_shadow_pdps(struct intel_vgpu_workload *workload)
75 kunmap(page); 75 kunmap(page);
76} 76}
77 77
78/*
79 * when populating shadow ctx from guest, we should not overrride oa related
80 * registers, so that they will not be overlapped by guest oa configs. Thus
81 * made it possible to capture oa data from host for both host and guests.
82 */
83static void sr_oa_regs(struct intel_vgpu_workload *workload,
84 u32 *reg_state, bool save)
85{
86 struct drm_i915_private *dev_priv = workload->vgpu->gvt->dev_priv;
87 u32 ctx_oactxctrl = dev_priv->perf.oa.ctx_oactxctrl_offset;
88 u32 ctx_flexeu0 = dev_priv->perf.oa.ctx_flexeu0_offset;
89 int i = 0;
90 u32 flex_mmio[] = {
91 i915_mmio_reg_offset(EU_PERF_CNTL0),
92 i915_mmio_reg_offset(EU_PERF_CNTL1),
93 i915_mmio_reg_offset(EU_PERF_CNTL2),
94 i915_mmio_reg_offset(EU_PERF_CNTL3),
95 i915_mmio_reg_offset(EU_PERF_CNTL4),
96 i915_mmio_reg_offset(EU_PERF_CNTL5),
97 i915_mmio_reg_offset(EU_PERF_CNTL6),
98 };
99
100 if (!workload || !reg_state || workload->ring_id != RCS)
101 return;
102
103 if (save) {
104 workload->oactxctrl = reg_state[ctx_oactxctrl + 1];
105
106 for (i = 0; i < ARRAY_SIZE(workload->flex_mmio); i++) {
107 u32 state_offset = ctx_flexeu0 + i * 2;
108
109 workload->flex_mmio[i] = reg_state[state_offset + 1];
110 }
111 } else {
112 reg_state[ctx_oactxctrl] =
113 i915_mmio_reg_offset(GEN8_OACTXCONTROL);
114 reg_state[ctx_oactxctrl + 1] = workload->oactxctrl;
115
116 for (i = 0; i < ARRAY_SIZE(workload->flex_mmio); i++) {
117 u32 state_offset = ctx_flexeu0 + i * 2;
118 u32 mmio = flex_mmio[i];
119
120 reg_state[state_offset] = mmio;
121 reg_state[state_offset + 1] = workload->flex_mmio[i];
122 }
123 }
124}
125
78static int populate_shadow_context(struct intel_vgpu_workload *workload) 126static int populate_shadow_context(struct intel_vgpu_workload *workload)
79{ 127{
80 struct intel_vgpu *vgpu = workload->vgpu; 128 struct intel_vgpu *vgpu = workload->vgpu;
@@ -121,6 +169,7 @@ static int populate_shadow_context(struct intel_vgpu_workload *workload)
121 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN); 169 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
122 shadow_ring_context = kmap(page); 170 shadow_ring_context = kmap(page);
123 171
172 sr_oa_regs(workload, (u32 *)shadow_ring_context, true);
124#define COPY_REG(name) \ 173#define COPY_REG(name) \
125 intel_gvt_hypervisor_read_gpa(vgpu, workload->ring_context_gpa \ 174 intel_gvt_hypervisor_read_gpa(vgpu, workload->ring_context_gpa \
126 + RING_CTX_OFF(name.val), &shadow_ring_context->name.val, 4) 175 + RING_CTX_OFF(name.val), &shadow_ring_context->name.val, 4)
@@ -149,6 +198,7 @@ static int populate_shadow_context(struct intel_vgpu_workload *workload)
149 sizeof(*shadow_ring_context), 198 sizeof(*shadow_ring_context),
150 I915_GTT_PAGE_SIZE - sizeof(*shadow_ring_context)); 199 I915_GTT_PAGE_SIZE - sizeof(*shadow_ring_context));
151 200
201 sr_oa_regs(workload, (u32 *)shadow_ring_context, false);
152 kunmap(page); 202 kunmap(page);
153 return 0; 203 return 0;
154} 204}
@@ -408,6 +458,17 @@ static int prepare_shadow_batch_buffer(struct intel_vgpu_workload *workload)
408 goto err; 458 goto err;
409 } 459 }
410 460
461 /* For privilge batch buffer and not wa_ctx, the bb_start_cmd_va
462 * is only updated into ring_scan_buffer, not real ring address
463 * allocated in later copy_workload_to_ring_buffer. pls be noted
464 * shadow_ring_buffer_va is now pointed to real ring buffer va
465 * in copy_workload_to_ring_buffer.
466 */
467
468 if (bb->bb_offset)
469 bb->bb_start_cmd_va = workload->shadow_ring_buffer_va
470 + bb->bb_offset;
471
411 /* relocate shadow batch buffer */ 472 /* relocate shadow batch buffer */
412 bb->bb_start_cmd_va[1] = i915_ggtt_offset(bb->vma); 473 bb->bb_start_cmd_va[1] = i915_ggtt_offset(bb->vma);
413 if (gmadr_bytes == 8) 474 if (gmadr_bytes == 8)
@@ -1078,10 +1139,12 @@ int intel_vgpu_setup_submission(struct intel_vgpu *vgpu)
1078 1139
1079 bitmap_zero(s->shadow_ctx_desc_updated, I915_NUM_ENGINES); 1140 bitmap_zero(s->shadow_ctx_desc_updated, I915_NUM_ENGINES);
1080 1141
1081 s->workloads = kmem_cache_create("gvt-g_vgpu_workload", 1142 s->workloads = kmem_cache_create_usercopy("gvt-g_vgpu_workload",
1082 sizeof(struct intel_vgpu_workload), 0, 1143 sizeof(struct intel_vgpu_workload), 0,
1083 SLAB_HWCACHE_ALIGN, 1144 SLAB_HWCACHE_ALIGN,
1084 NULL); 1145 offsetof(struct intel_vgpu_workload, rb_tail),
1146 sizeof_field(struct intel_vgpu_workload, rb_tail),
1147 NULL);
1085 1148
1086 if (!s->workloads) { 1149 if (!s->workloads) {
1087 ret = -ENOMEM; 1150 ret = -ENOMEM;
diff --git a/drivers/gpu/drm/i915/gvt/scheduler.h b/drivers/gpu/drm/i915/gvt/scheduler.h
index bab4097aa6d7..486ed57a4ad1 100644
--- a/drivers/gpu/drm/i915/gvt/scheduler.h
+++ b/drivers/gpu/drm/i915/gvt/scheduler.h
@@ -110,6 +110,10 @@ struct intel_vgpu_workload {
110 /* shadow batch buffer */ 110 /* shadow batch buffer */
111 struct list_head shadow_bb; 111 struct list_head shadow_bb;
112 struct intel_shadow_wa_ctx wa_ctx; 112 struct intel_shadow_wa_ctx wa_ctx;
113
114 /* oa registers */
115 u32 oactxctrl;
116 u32 flex_mmio[7];
113}; 117};
114 118
115struct intel_vgpu_shadow_bb { 119struct intel_vgpu_shadow_bb {
@@ -120,6 +124,7 @@ struct intel_vgpu_shadow_bb {
120 u32 *bb_start_cmd_va; 124 u32 *bb_start_cmd_va;
121 unsigned int clflush; 125 unsigned int clflush;
122 bool accessing; 126 bool accessing;
127 unsigned long bb_offset;
123}; 128};
124 129
125#define workload_q_head(vgpu, ring_id) \ 130#define workload_q_head(vgpu, ring_id) \
diff --git a/drivers/gpu/drm/i915/gvt/trace.h b/drivers/gpu/drm/i915/gvt/trace.h
index fc7831a62121..82093f1e8612 100644
--- a/drivers/gpu/drm/i915/gvt/trace.h
+++ b/drivers/gpu/drm/i915/gvt/trace.h
@@ -333,7 +333,7 @@ TRACE_EVENT(render_mmio,
333 TP_PROTO(int old_id, int new_id, char *action, unsigned int reg, 333 TP_PROTO(int old_id, int new_id, char *action, unsigned int reg,
334 unsigned int old_val, unsigned int new_val), 334 unsigned int old_val, unsigned int new_val),
335 335
336 TP_ARGS(old_id, new_id, action, reg, new_val, old_val), 336 TP_ARGS(old_id, new_id, action, reg, old_val, new_val),
337 337
338 TP_STRUCT__entry( 338 TP_STRUCT__entry(
339 __field(int, old_id) 339 __field(int, old_id)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 0359d6f870b4..7b5a9d7c9593 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -433,20 +433,28 @@ i915_gem_object_wait_reservation(struct reservation_object *resv,
433 dma_fence_put(shared[i]); 433 dma_fence_put(shared[i]);
434 kfree(shared); 434 kfree(shared);
435 435
436 /*
437 * If both shared fences and an exclusive fence exist,
438 * then by construction the shared fences must be later
439 * than the exclusive fence. If we successfully wait for
440 * all the shared fences, we know that the exclusive fence
441 * must all be signaled. If all the shared fences are
442 * signaled, we can prune the array and recover the
443 * floating references on the fences/requests.
444 */
436 prune_fences = count && timeout >= 0; 445 prune_fences = count && timeout >= 0;
437 } else { 446 } else {
438 excl = reservation_object_get_excl_rcu(resv); 447 excl = reservation_object_get_excl_rcu(resv);
439 } 448 }
440 449
441 if (excl && timeout >= 0) { 450 if (excl && timeout >= 0)
442 timeout = i915_gem_object_wait_fence(excl, flags, timeout, 451 timeout = i915_gem_object_wait_fence(excl, flags, timeout,
443 rps_client); 452 rps_client);
444 prune_fences = timeout >= 0;
445 }
446 453
447 dma_fence_put(excl); 454 dma_fence_put(excl);
448 455
449 /* Oportunistically prune the fences iff we know they have *all* been 456 /*
457 * Opportunistically prune the fences iff we know they have *all* been
450 * signaled and that the reservation object has not been changed (i.e. 458 * signaled and that the reservation object has not been changed (i.e.
451 * no new fences have been added). 459 * no new fences have been added).
452 */ 460 */
diff --git a/drivers/gpu/drm/i915/i915_sysfs.c b/drivers/gpu/drm/i915/i915_sysfs.c
index b33d2158c234..e5e6f6bb2b05 100644
--- a/drivers/gpu/drm/i915/i915_sysfs.c
+++ b/drivers/gpu/drm/i915/i915_sysfs.c
@@ -304,8 +304,9 @@ static ssize_t gt_boost_freq_mhz_store(struct device *kdev,
304{ 304{
305 struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); 305 struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
306 struct intel_rps *rps = &dev_priv->gt_pm.rps; 306 struct intel_rps *rps = &dev_priv->gt_pm.rps;
307 u32 val; 307 bool boost = false;
308 ssize_t ret; 308 ssize_t ret;
309 u32 val;
309 310
310 ret = kstrtou32(buf, 0, &val); 311 ret = kstrtou32(buf, 0, &val);
311 if (ret) 312 if (ret)
@@ -317,8 +318,13 @@ static ssize_t gt_boost_freq_mhz_store(struct device *kdev,
317 return -EINVAL; 318 return -EINVAL;
318 319
319 mutex_lock(&dev_priv->pcu_lock); 320 mutex_lock(&dev_priv->pcu_lock);
320 rps->boost_freq = val; 321 if (val != rps->boost_freq) {
322 rps->boost_freq = val;
323 boost = atomic_read(&rps->num_waiters);
324 }
321 mutex_unlock(&dev_priv->pcu_lock); 325 mutex_unlock(&dev_priv->pcu_lock);
326 if (boost)
327 schedule_work(&rps->work);
322 328
323 return count; 329 return count;
324} 330}
diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index dbcf1a0586f9..8c2d778560f0 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -2205,8 +2205,7 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
2205 intel_prepare_dp_ddi_buffers(encoder, crtc_state); 2205 intel_prepare_dp_ddi_buffers(encoder, crtc_state);
2206 2206
2207 intel_ddi_init_dp_buf_reg(encoder); 2207 intel_ddi_init_dp_buf_reg(encoder);
2208 if (!is_mst) 2208 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2209 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2210 intel_dp_start_link_train(intel_dp); 2209 intel_dp_start_link_train(intel_dp);
2211 if (port != PORT_A || INTEL_GEN(dev_priv) >= 9) 2210 if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
2212 intel_dp_stop_link_train(intel_dp); 2211 intel_dp_stop_link_train(intel_dp);
@@ -2304,14 +2303,12 @@ static void intel_ddi_post_disable_dp(struct intel_encoder *encoder,
2304 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2303 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2305 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 2304 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
2306 struct intel_dp *intel_dp = &dig_port->dp; 2305 struct intel_dp *intel_dp = &dig_port->dp;
2307 bool is_mst = intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST);
2308 2306
2309 /* 2307 /*
2310 * Power down sink before disabling the port, otherwise we end 2308 * Power down sink before disabling the port, otherwise we end
2311 * up getting interrupts from the sink on detecting link loss. 2309 * up getting interrupts from the sink on detecting link loss.
2312 */ 2310 */
2313 if (!is_mst) 2311 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
2314 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
2315 2312
2316 intel_disable_ddi_buf(encoder); 2313 intel_disable_ddi_buf(encoder);
2317 2314
diff --git a/drivers/gpu/drm/i915/intel_hangcheck.c b/drivers/gpu/drm/i915/intel_hangcheck.c
index 42e45ae87393..c8ea510629fa 100644
--- a/drivers/gpu/drm/i915/intel_hangcheck.c
+++ b/drivers/gpu/drm/i915/intel_hangcheck.c
@@ -246,7 +246,7 @@ engine_stuck(struct intel_engine_cs *engine, u64 acthd)
246 */ 246 */
247 tmp = I915_READ_CTL(engine); 247 tmp = I915_READ_CTL(engine);
248 if (tmp & RING_WAIT) { 248 if (tmp & RING_WAIT) {
249 i915_handle_error(dev_priv, 0, 249 i915_handle_error(dev_priv, BIT(engine->id),
250 "Kicking stuck wait on %s", 250 "Kicking stuck wait on %s",
251 engine->name); 251 engine->name);
252 I915_WRITE_CTL(engine, tmp); 252 I915_WRITE_CTL(engine, tmp);
@@ -258,7 +258,7 @@ engine_stuck(struct intel_engine_cs *engine, u64 acthd)
258 default: 258 default:
259 return ENGINE_DEAD; 259 return ENGINE_DEAD;
260 case 1: 260 case 1:
261 i915_handle_error(dev_priv, 0, 261 i915_handle_error(dev_priv, ALL_ENGINES,
262 "Kicking stuck semaphore on %s", 262 "Kicking stuck semaphore on %s",
263 engine->name); 263 engine->name);
264 I915_WRITE_CTL(engine, tmp); 264 I915_WRITE_CTL(engine, tmp);
diff --git a/drivers/gpu/drm/imx/ipuv3-crtc.c b/drivers/gpu/drm/imx/ipuv3-crtc.c
index 9a9961802f5c..e83af0f2be86 100644
--- a/drivers/gpu/drm/imx/ipuv3-crtc.c
+++ b/drivers/gpu/drm/imx/ipuv3-crtc.c
@@ -225,7 +225,11 @@ static void ipu_crtc_atomic_begin(struct drm_crtc *crtc,
225 struct drm_crtc_state *old_crtc_state) 225 struct drm_crtc_state *old_crtc_state)
226{ 226{
227 drm_crtc_vblank_on(crtc); 227 drm_crtc_vblank_on(crtc);
228}
228 229
230static void ipu_crtc_atomic_flush(struct drm_crtc *crtc,
231 struct drm_crtc_state *old_crtc_state)
232{
229 spin_lock_irq(&crtc->dev->event_lock); 233 spin_lock_irq(&crtc->dev->event_lock);
230 if (crtc->state->event) { 234 if (crtc->state->event) {
231 WARN_ON(drm_crtc_vblank_get(crtc)); 235 WARN_ON(drm_crtc_vblank_get(crtc));
@@ -293,6 +297,7 @@ static const struct drm_crtc_helper_funcs ipu_helper_funcs = {
293 .mode_set_nofb = ipu_crtc_mode_set_nofb, 297 .mode_set_nofb = ipu_crtc_mode_set_nofb,
294 .atomic_check = ipu_crtc_atomic_check, 298 .atomic_check = ipu_crtc_atomic_check,
295 .atomic_begin = ipu_crtc_atomic_begin, 299 .atomic_begin = ipu_crtc_atomic_begin,
300 .atomic_flush = ipu_crtc_atomic_flush,
296 .atomic_disable = ipu_crtc_atomic_disable, 301 .atomic_disable = ipu_crtc_atomic_disable,
297 .atomic_enable = ipu_crtc_atomic_enable, 302 .atomic_enable = ipu_crtc_atomic_enable,
298}; 303};
diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c
index d7e3583e608e..203f247d4854 100644
--- a/drivers/gpu/drm/imx/ipuv3-plane.c
+++ b/drivers/gpu/drm/imx/ipuv3-plane.c
@@ -22,6 +22,7 @@
22#include <drm/drm_plane_helper.h> 22#include <drm/drm_plane_helper.h>
23 23
24#include "video/imx-ipu-v3.h" 24#include "video/imx-ipu-v3.h"
25#include "imx-drm.h"
25#include "ipuv3-plane.h" 26#include "ipuv3-plane.h"
26 27
27struct ipu_plane_state { 28struct ipu_plane_state {
@@ -272,7 +273,7 @@ static void ipu_plane_destroy(struct drm_plane *plane)
272 kfree(ipu_plane); 273 kfree(ipu_plane);
273} 274}
274 275
275void ipu_plane_state_reset(struct drm_plane *plane) 276static void ipu_plane_state_reset(struct drm_plane *plane)
276{ 277{
277 struct ipu_plane_state *ipu_state; 278 struct ipu_plane_state *ipu_state;
278 279
@@ -292,7 +293,8 @@ void ipu_plane_state_reset(struct drm_plane *plane)
292 plane->state = &ipu_state->base; 293 plane->state = &ipu_state->base;
293} 294}
294 295
295struct drm_plane_state *ipu_plane_duplicate_state(struct drm_plane *plane) 296static struct drm_plane_state *
297ipu_plane_duplicate_state(struct drm_plane *plane)
296{ 298{
297 struct ipu_plane_state *state; 299 struct ipu_plane_state *state;
298 300
@@ -306,8 +308,8 @@ struct drm_plane_state *ipu_plane_duplicate_state(struct drm_plane *plane)
306 return &state->base; 308 return &state->base;
307} 309}
308 310
309void ipu_plane_destroy_state(struct drm_plane *plane, 311static void ipu_plane_destroy_state(struct drm_plane *plane,
310 struct drm_plane_state *state) 312 struct drm_plane_state *state)
311{ 313{
312 struct ipu_plane_state *ipu_state = to_ipu_plane_state(state); 314 struct ipu_plane_state *ipu_state = to_ipu_plane_state(state);
313 315
diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
index 5155f0179b61..05520202c967 100644
--- a/drivers/gpu/drm/meson/meson_crtc.c
+++ b/drivers/gpu/drm/meson/meson_crtc.c
@@ -36,6 +36,7 @@
36#include "meson_venc.h" 36#include "meson_venc.h"
37#include "meson_vpp.h" 37#include "meson_vpp.h"
38#include "meson_viu.h" 38#include "meson_viu.h"
39#include "meson_canvas.h"
39#include "meson_registers.h" 40#include "meson_registers.h"
40 41
41/* CRTC definition */ 42/* CRTC definition */
@@ -192,6 +193,11 @@ void meson_crtc_irq(struct meson_drm *priv)
192 } else 193 } else
193 meson_vpp_disable_interlace_vscaler_osd1(priv); 194 meson_vpp_disable_interlace_vscaler_osd1(priv);
194 195
196 meson_canvas_setup(priv, MESON_CANVAS_ID_OSD1,
197 priv->viu.osd1_addr, priv->viu.osd1_stride,
198 priv->viu.osd1_height, MESON_CANVAS_WRAP_NONE,
199 MESON_CANVAS_BLKMODE_LINEAR);
200
195 /* Enable OSD1 */ 201 /* Enable OSD1 */
196 writel_bits_relaxed(VPP_OSD1_POSTBLEND, VPP_OSD1_POSTBLEND, 202 writel_bits_relaxed(VPP_OSD1_POSTBLEND, VPP_OSD1_POSTBLEND,
197 priv->io_base + _REG(VPP_MISC)); 203 priv->io_base + _REG(VPP_MISC));
diff --git a/drivers/gpu/drm/meson/meson_drv.h b/drivers/gpu/drm/meson/meson_drv.h
index 5e8b392b9d1f..8450d6ac8c9b 100644
--- a/drivers/gpu/drm/meson/meson_drv.h
+++ b/drivers/gpu/drm/meson/meson_drv.h
@@ -43,6 +43,9 @@ struct meson_drm {
43 bool osd1_commit; 43 bool osd1_commit;
44 uint32_t osd1_ctrl_stat; 44 uint32_t osd1_ctrl_stat;
45 uint32_t osd1_blk0_cfg[5]; 45 uint32_t osd1_blk0_cfg[5];
46 uint32_t osd1_addr;
47 uint32_t osd1_stride;
48 uint32_t osd1_height;
46 } viu; 49 } viu;
47 50
48 struct { 51 struct {
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index c78a3a59f58c..12c80dfcff59 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -160,10 +160,9 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
160 /* Update Canvas with buffer address */ 160 /* Update Canvas with buffer address */
161 gem = drm_fb_cma_get_gem_obj(fb, 0); 161 gem = drm_fb_cma_get_gem_obj(fb, 0);
162 162
163 meson_canvas_setup(priv, MESON_CANVAS_ID_OSD1, 163 priv->viu.osd1_addr = gem->paddr;
164 gem->paddr, fb->pitches[0], 164 priv->viu.osd1_stride = fb->pitches[0];
165 fb->height, MESON_CANVAS_WRAP_NONE, 165 priv->viu.osd1_height = fb->height;
166 MESON_CANVAS_BLKMODE_LINEAR);
167 166
168 spin_unlock_irqrestore(&priv->drm->event_lock, flags); 167 spin_unlock_irqrestore(&priv->drm->event_lock, flags);
169} 168}
diff --git a/drivers/gpu/drm/nouveau/nouveau_backlight.c b/drivers/gpu/drm/nouveau/nouveau_backlight.c
index 380f340204e8..debbbf0fd4bd 100644
--- a/drivers/gpu/drm/nouveau/nouveau_backlight.c
+++ b/drivers/gpu/drm/nouveau/nouveau_backlight.c
@@ -134,7 +134,7 @@ nv50_get_intensity(struct backlight_device *bd)
134 struct nouveau_encoder *nv_encoder = bl_get_data(bd); 134 struct nouveau_encoder *nv_encoder = bl_get_data(bd);
135 struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); 135 struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev);
136 struct nvif_object *device = &drm->client.device.object; 136 struct nvif_object *device = &drm->client.device.object;
137 int or = nv_encoder->or; 137 int or = ffs(nv_encoder->dcb->or) - 1;
138 u32 div = 1025; 138 u32 div = 1025;
139 u32 val; 139 u32 val;
140 140
@@ -149,7 +149,7 @@ nv50_set_intensity(struct backlight_device *bd)
149 struct nouveau_encoder *nv_encoder = bl_get_data(bd); 149 struct nouveau_encoder *nv_encoder = bl_get_data(bd);
150 struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); 150 struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev);
151 struct nvif_object *device = &drm->client.device.object; 151 struct nvif_object *device = &drm->client.device.object;
152 int or = nv_encoder->or; 152 int or = ffs(nv_encoder->dcb->or) - 1;
153 u32 div = 1025; 153 u32 div = 1025;
154 u32 val = (bd->props.brightness * div) / 100; 154 u32 val = (bd->props.brightness * div) / 100;
155 155
@@ -170,7 +170,7 @@ nva3_get_intensity(struct backlight_device *bd)
170 struct nouveau_encoder *nv_encoder = bl_get_data(bd); 170 struct nouveau_encoder *nv_encoder = bl_get_data(bd);
171 struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); 171 struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev);
172 struct nvif_object *device = &drm->client.device.object; 172 struct nvif_object *device = &drm->client.device.object;
173 int or = nv_encoder->or; 173 int or = ffs(nv_encoder->dcb->or) - 1;
174 u32 div, val; 174 u32 div, val;
175 175
176 div = nvif_rd32(device, NV50_PDISP_SOR_PWM_DIV(or)); 176 div = nvif_rd32(device, NV50_PDISP_SOR_PWM_DIV(or));
@@ -188,7 +188,7 @@ nva3_set_intensity(struct backlight_device *bd)
188 struct nouveau_encoder *nv_encoder = bl_get_data(bd); 188 struct nouveau_encoder *nv_encoder = bl_get_data(bd);
189 struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); 189 struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev);
190 struct nvif_object *device = &drm->client.device.object; 190 struct nvif_object *device = &drm->client.device.object;
191 int or = nv_encoder->or; 191 int or = ffs(nv_encoder->dcb->or) - 1;
192 u32 div, val; 192 u32 div, val;
193 193
194 div = nvif_rd32(device, NV50_PDISP_SOR_PWM_DIV(or)); 194 div = nvif_rd32(device, NV50_PDISP_SOR_PWM_DIV(or));
@@ -228,7 +228,7 @@ nv50_backlight_init(struct drm_connector *connector)
228 return -ENODEV; 228 return -ENODEV;
229 } 229 }
230 230
231 if (!nvif_rd32(device, NV50_PDISP_SOR_PWM_CTL(nv_encoder->or))) 231 if (!nvif_rd32(device, NV50_PDISP_SOR_PWM_CTL(ffs(nv_encoder->dcb->or) - 1)))
232 return 0; 232 return 0;
233 233
234 if (drm->client.device.info.chipset <= 0xa0 || 234 if (drm->client.device.info.chipset <= 0xa0 ||
@@ -268,13 +268,13 @@ nouveau_backlight_init(struct drm_device *dev)
268 struct nvif_device *device = &drm->client.device; 268 struct nvif_device *device = &drm->client.device;
269 struct drm_connector *connector; 269 struct drm_connector *connector;
270 270
271 INIT_LIST_HEAD(&drm->bl_connectors);
272
271 if (apple_gmux_present()) { 273 if (apple_gmux_present()) {
272 NV_INFO(drm, "Apple GMUX detected: not registering Nouveau backlight interface\n"); 274 NV_INFO(drm, "Apple GMUX detected: not registering Nouveau backlight interface\n");
273 return 0; 275 return 0;
274 } 276 }
275 277
276 INIT_LIST_HEAD(&drm->bl_connectors);
277
278 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 278 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
279 if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS && 279 if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS &&
280 connector->connector_type != DRM_MODE_CONNECTOR_eDP) 280 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index 69d6e61a01ec..6ed9cb053dfa 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -570,9 +570,15 @@ nouveau_connector_detect(struct drm_connector *connector, bool force)
570 nv_connector->edid = NULL; 570 nv_connector->edid = NULL;
571 } 571 }
572 572
573 ret = pm_runtime_get_sync(connector->dev->dev); 573 /* Outputs are only polled while runtime active, so acquiring a
574 if (ret < 0 && ret != -EACCES) 574 * runtime PM ref here is unnecessary (and would deadlock upon
575 return conn_status; 575 * runtime suspend because it waits for polling to finish).
576 */
577 if (!drm_kms_helper_is_poll_worker()) {
578 ret = pm_runtime_get_sync(connector->dev->dev);
579 if (ret < 0 && ret != -EACCES)
580 return conn_status;
581 }
576 582
577 nv_encoder = nouveau_connector_ddc_detect(connector); 583 nv_encoder = nouveau_connector_ddc_detect(connector);
578 if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) { 584 if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) {
@@ -647,8 +653,10 @@ detect_analog:
647 653
648 out: 654 out:
649 655
650 pm_runtime_mark_last_busy(connector->dev->dev); 656 if (!drm_kms_helper_is_poll_worker()) {
651 pm_runtime_put_autosuspend(connector->dev->dev); 657 pm_runtime_mark_last_busy(connector->dev->dev);
658 pm_runtime_put_autosuspend(connector->dev->dev);
659 }
652 660
653 return conn_status; 661 return conn_status;
654} 662}
diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
index 6af3bc483c84..8bd739cfd00d 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -4469,6 +4469,7 @@ nv50_display_create(struct drm_device *dev)
4469 nouveau_display(dev)->fini = nv50_display_fini; 4469 nouveau_display(dev)->fini = nv50_display_fini;
4470 disp->disp = &nouveau_display(dev)->disp; 4470 disp->disp = &nouveau_display(dev)->disp;
4471 dev->mode_config.funcs = &nv50_disp_func; 4471 dev->mode_config.funcs = &nv50_disp_func;
4472 dev->driver->driver_features |= DRIVER_PREFER_XBGR_30BPP;
4472 if (nouveau_atomic) 4473 if (nouveau_atomic)
4473 dev->driver->driver_features |= DRIVER_ATOMIC; 4474 dev->driver->driver_features |= DRIVER_ATOMIC;
4474 4475
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
index 93946dcee319..1c12e58f44c2 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
@@ -1354,7 +1354,7 @@ nvkm_vmm_get_locked(struct nvkm_vmm *vmm, bool getref, bool mapref, bool sparse,
1354 1354
1355 tail = this->addr + this->size; 1355 tail = this->addr + this->size;
1356 if (vmm->func->page_block && next && next->page != p) 1356 if (vmm->func->page_block && next && next->page != p)
1357 tail = ALIGN_DOWN(addr, vmm->func->page_block); 1357 tail = ALIGN_DOWN(tail, vmm->func->page_block);
1358 1358
1359 if (addr <= tail && tail - addr >= size) { 1359 if (addr <= tail && tail - addr >= size) {
1360 rb_erase(&this->tree, &vmm->free); 1360 rb_erase(&this->tree, &vmm->free);
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
index bf62303571b3..3695cde669f8 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
@@ -301,7 +301,7 @@ nvkm_therm_attr_set(struct nvkm_therm *therm,
301void 301void
302nvkm_therm_clkgate_enable(struct nvkm_therm *therm) 302nvkm_therm_clkgate_enable(struct nvkm_therm *therm)
303{ 303{
304 if (!therm->func->clkgate_enable || !therm->clkgating_enabled) 304 if (!therm || !therm->func->clkgate_enable || !therm->clkgating_enabled)
305 return; 305 return;
306 306
307 nvkm_debug(&therm->subdev, 307 nvkm_debug(&therm->subdev,
@@ -312,7 +312,7 @@ nvkm_therm_clkgate_enable(struct nvkm_therm *therm)
312void 312void
313nvkm_therm_clkgate_fini(struct nvkm_therm *therm, bool suspend) 313nvkm_therm_clkgate_fini(struct nvkm_therm *therm, bool suspend)
314{ 314{
315 if (!therm->func->clkgate_fini || !therm->clkgating_enabled) 315 if (!therm || !therm->func->clkgate_fini || !therm->clkgating_enabled)
316 return; 316 return;
317 317
318 nvkm_debug(&therm->subdev, 318 nvkm_debug(&therm->subdev,
@@ -395,7 +395,7 @@ void
395nvkm_therm_clkgate_init(struct nvkm_therm *therm, 395nvkm_therm_clkgate_init(struct nvkm_therm *therm,
396 const struct nvkm_therm_clkgate_pack *p) 396 const struct nvkm_therm_clkgate_pack *p)
397{ 397{
398 if (!therm->func->clkgate_init || !therm->clkgating_enabled) 398 if (!therm || !therm->func->clkgate_init || !therm->clkgating_enabled)
399 return; 399 return;
400 400
401 therm->func->clkgate_init(therm, p); 401 therm->func->clkgate_init(therm, p);
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index b108eaabb6df..df9469a8fdb1 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -892,9 +892,11 @@ radeon_lvds_detect(struct drm_connector *connector, bool force)
892 enum drm_connector_status ret = connector_status_disconnected; 892 enum drm_connector_status ret = connector_status_disconnected;
893 int r; 893 int r;
894 894
895 r = pm_runtime_get_sync(connector->dev->dev); 895 if (!drm_kms_helper_is_poll_worker()) {
896 if (r < 0) 896 r = pm_runtime_get_sync(connector->dev->dev);
897 return connector_status_disconnected; 897 if (r < 0)
898 return connector_status_disconnected;
899 }
898 900
899 if (encoder) { 901 if (encoder) {
900 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 902 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
@@ -917,8 +919,12 @@ radeon_lvds_detect(struct drm_connector *connector, bool force)
917 /* check acpi lid status ??? */ 919 /* check acpi lid status ??? */
918 920
919 radeon_connector_update_scratch_regs(connector, ret); 921 radeon_connector_update_scratch_regs(connector, ret);
920 pm_runtime_mark_last_busy(connector->dev->dev); 922
921 pm_runtime_put_autosuspend(connector->dev->dev); 923 if (!drm_kms_helper_is_poll_worker()) {
924 pm_runtime_mark_last_busy(connector->dev->dev);
925 pm_runtime_put_autosuspend(connector->dev->dev);
926 }
927
922 return ret; 928 return ret;
923} 929}
924 930
@@ -1032,9 +1038,11 @@ radeon_vga_detect(struct drm_connector *connector, bool force)
1032 enum drm_connector_status ret = connector_status_disconnected; 1038 enum drm_connector_status ret = connector_status_disconnected;
1033 int r; 1039 int r;
1034 1040
1035 r = pm_runtime_get_sync(connector->dev->dev); 1041 if (!drm_kms_helper_is_poll_worker()) {
1036 if (r < 0) 1042 r = pm_runtime_get_sync(connector->dev->dev);
1037 return connector_status_disconnected; 1043 if (r < 0)
1044 return connector_status_disconnected;
1045 }
1038 1046
1039 encoder = radeon_best_single_encoder(connector); 1047 encoder = radeon_best_single_encoder(connector);
1040 if (!encoder) 1048 if (!encoder)
@@ -1101,8 +1109,10 @@ radeon_vga_detect(struct drm_connector *connector, bool force)
1101 radeon_connector_update_scratch_regs(connector, ret); 1109 radeon_connector_update_scratch_regs(connector, ret);
1102 1110
1103out: 1111out:
1104 pm_runtime_mark_last_busy(connector->dev->dev); 1112 if (!drm_kms_helper_is_poll_worker()) {
1105 pm_runtime_put_autosuspend(connector->dev->dev); 1113 pm_runtime_mark_last_busy(connector->dev->dev);
1114 pm_runtime_put_autosuspend(connector->dev->dev);
1115 }
1106 1116
1107 return ret; 1117 return ret;
1108} 1118}
@@ -1166,9 +1176,11 @@ radeon_tv_detect(struct drm_connector *connector, bool force)
1166 if (!radeon_connector->dac_load_detect) 1176 if (!radeon_connector->dac_load_detect)
1167 return ret; 1177 return ret;
1168 1178
1169 r = pm_runtime_get_sync(connector->dev->dev); 1179 if (!drm_kms_helper_is_poll_worker()) {
1170 if (r < 0) 1180 r = pm_runtime_get_sync(connector->dev->dev);
1171 return connector_status_disconnected; 1181 if (r < 0)
1182 return connector_status_disconnected;
1183 }
1172 1184
1173 encoder = radeon_best_single_encoder(connector); 1185 encoder = radeon_best_single_encoder(connector);
1174 if (!encoder) 1186 if (!encoder)
@@ -1180,8 +1192,12 @@ radeon_tv_detect(struct drm_connector *connector, bool force)
1180 if (ret == connector_status_connected) 1192 if (ret == connector_status_connected)
1181 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false); 1193 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
1182 radeon_connector_update_scratch_regs(connector, ret); 1194 radeon_connector_update_scratch_regs(connector, ret);
1183 pm_runtime_mark_last_busy(connector->dev->dev); 1195
1184 pm_runtime_put_autosuspend(connector->dev->dev); 1196 if (!drm_kms_helper_is_poll_worker()) {
1197 pm_runtime_mark_last_busy(connector->dev->dev);
1198 pm_runtime_put_autosuspend(connector->dev->dev);
1199 }
1200
1185 return ret; 1201 return ret;
1186} 1202}
1187 1203
@@ -1244,9 +1260,11 @@ radeon_dvi_detect(struct drm_connector *connector, bool force)
1244 enum drm_connector_status ret = connector_status_disconnected; 1260 enum drm_connector_status ret = connector_status_disconnected;
1245 bool dret = false, broken_edid = false; 1261 bool dret = false, broken_edid = false;
1246 1262
1247 r = pm_runtime_get_sync(connector->dev->dev); 1263 if (!drm_kms_helper_is_poll_worker()) {
1248 if (r < 0) 1264 r = pm_runtime_get_sync(connector->dev->dev);
1249 return connector_status_disconnected; 1265 if (r < 0)
1266 return connector_status_disconnected;
1267 }
1250 1268
1251 if (radeon_connector->detected_hpd_without_ddc) { 1269 if (radeon_connector->detected_hpd_without_ddc) {
1252 force = true; 1270 force = true;
@@ -1429,8 +1447,10 @@ out:
1429 } 1447 }
1430 1448
1431exit: 1449exit:
1432 pm_runtime_mark_last_busy(connector->dev->dev); 1450 if (!drm_kms_helper_is_poll_worker()) {
1433 pm_runtime_put_autosuspend(connector->dev->dev); 1451 pm_runtime_mark_last_busy(connector->dev->dev);
1452 pm_runtime_put_autosuspend(connector->dev->dev);
1453 }
1434 1454
1435 return ret; 1455 return ret;
1436} 1456}
@@ -1681,9 +1701,11 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
1681 if (radeon_dig_connector->is_mst) 1701 if (radeon_dig_connector->is_mst)
1682 return connector_status_disconnected; 1702 return connector_status_disconnected;
1683 1703
1684 r = pm_runtime_get_sync(connector->dev->dev); 1704 if (!drm_kms_helper_is_poll_worker()) {
1685 if (r < 0) 1705 r = pm_runtime_get_sync(connector->dev->dev);
1686 return connector_status_disconnected; 1706 if (r < 0)
1707 return connector_status_disconnected;
1708 }
1687 1709
1688 if (!force && radeon_check_hpd_status_unchanged(connector)) { 1710 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1689 ret = connector->status; 1711 ret = connector->status;
@@ -1770,8 +1792,10 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
1770 } 1792 }
1771 1793
1772out: 1794out:
1773 pm_runtime_mark_last_busy(connector->dev->dev); 1795 if (!drm_kms_helper_is_poll_worker()) {
1774 pm_runtime_put_autosuspend(connector->dev->dev); 1796 pm_runtime_mark_last_busy(connector->dev->dev);
1797 pm_runtime_put_autosuspend(connector->dev->dev);
1798 }
1775 1799
1776 return ret; 1800 return ret;
1777} 1801}
diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c
index 3b2d11b675e8..2d7c57406715 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
@@ -111,6 +111,8 @@ static void sun4i_crtc_atomic_disable(struct drm_crtc *crtc,
111 111
112 DRM_DEBUG_DRIVER("Disabling the CRTC\n"); 112 DRM_DEBUG_DRIVER("Disabling the CRTC\n");
113 113
114 drm_crtc_vblank_off(crtc);
115
114 sun4i_tcon_set_status(scrtc->tcon, encoder, false); 116 sun4i_tcon_set_status(scrtc->tcon, encoder, false);
115 117
116 if (crtc->state->event && !crtc->state->active) { 118 if (crtc->state->event && !crtc->state->active) {
@@ -131,6 +133,8 @@ static void sun4i_crtc_atomic_enable(struct drm_crtc *crtc,
131 DRM_DEBUG_DRIVER("Enabling the CRTC\n"); 133 DRM_DEBUG_DRIVER("Enabling the CRTC\n");
132 134
133 sun4i_tcon_set_status(scrtc->tcon, encoder, true); 135 sun4i_tcon_set_status(scrtc->tcon, encoder, true);
136
137 drm_crtc_vblank_on(crtc);
134} 138}
135 139
136static void sun4i_crtc_mode_set_nofb(struct drm_crtc *crtc) 140static void sun4i_crtc_mode_set_nofb(struct drm_crtc *crtc)
diff --git a/drivers/gpu/drm/sun4i/sun4i_dotclock.c b/drivers/gpu/drm/sun4i/sun4i_dotclock.c
index 023f39bda633..e36004fbe453 100644
--- a/drivers/gpu/drm/sun4i/sun4i_dotclock.c
+++ b/drivers/gpu/drm/sun4i/sun4i_dotclock.c
@@ -132,10 +132,13 @@ static int sun4i_dclk_get_phase(struct clk_hw *hw)
132static int sun4i_dclk_set_phase(struct clk_hw *hw, int degrees) 132static int sun4i_dclk_set_phase(struct clk_hw *hw, int degrees)
133{ 133{
134 struct sun4i_dclk *dclk = hw_to_dclk(hw); 134 struct sun4i_dclk *dclk = hw_to_dclk(hw);
135 u32 val = degrees / 120;
136
137 val <<= 28;
135 138
136 regmap_update_bits(dclk->regmap, SUN4I_TCON0_IO_POL_REG, 139 regmap_update_bits(dclk->regmap, SUN4I_TCON0_IO_POL_REG,
137 GENMASK(29, 28), 140 GENMASK(29, 28),
138 degrees / 120); 141 val);
139 142
140 return 0; 143 return 0;
141} 144}
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c
index 7f0705ef9f4e..50d19605c38f 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.c
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.c
@@ -113,7 +113,7 @@ static int sun4i_drv_bind(struct device *dev)
113 /* drm_vblank_init calls kcalloc, which can fail */ 113 /* drm_vblank_init calls kcalloc, which can fail */
114 ret = drm_vblank_init(drm, drm->mode_config.num_crtc); 114 ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
115 if (ret) 115 if (ret)
116 goto free_mem_region; 116 goto cleanup_mode_config;
117 117
118 drm->irq_enabled = true; 118 drm->irq_enabled = true;
119 119
@@ -141,7 +141,6 @@ finish_poll:
141 sun4i_framebuffer_free(drm); 141 sun4i_framebuffer_free(drm);
142cleanup_mode_config: 142cleanup_mode_config:
143 drm_mode_config_cleanup(drm); 143 drm_mode_config_cleanup(drm);
144free_mem_region:
145 of_reserved_mem_device_release(dev); 144 of_reserved_mem_device_release(dev);
146free_drm: 145free_drm:
147 drm_dev_unref(drm); 146 drm_dev_unref(drm);
diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
index 500b6fb3e028..fa4bcd092eaf 100644
--- a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
@@ -538,7 +538,8 @@ static int sun4i_hdmi_bind(struct device *dev, struct device *master,
538 &sun4i_hdmi_regmap_config); 538 &sun4i_hdmi_regmap_config);
539 if (IS_ERR(hdmi->regmap)) { 539 if (IS_ERR(hdmi->regmap)) {
540 dev_err(dev, "Couldn't create HDMI encoder regmap\n"); 540 dev_err(dev, "Couldn't create HDMI encoder regmap\n");
541 return PTR_ERR(hdmi->regmap); 541 ret = PTR_ERR(hdmi->regmap);
542 goto err_disable_mod_clk;
542 } 543 }
543 544
544 ret = sun4i_tmds_create(hdmi); 545 ret = sun4i_tmds_create(hdmi);
@@ -551,7 +552,8 @@ static int sun4i_hdmi_bind(struct device *dev, struct device *master,
551 hdmi->ddc_parent_clk = devm_clk_get(dev, "ddc"); 552 hdmi->ddc_parent_clk = devm_clk_get(dev, "ddc");
552 if (IS_ERR(hdmi->ddc_parent_clk)) { 553 if (IS_ERR(hdmi->ddc_parent_clk)) {
553 dev_err(dev, "Couldn't get the HDMI DDC clock\n"); 554 dev_err(dev, "Couldn't get the HDMI DDC clock\n");
554 return PTR_ERR(hdmi->ddc_parent_clk); 555 ret = PTR_ERR(hdmi->ddc_parent_clk);
556 goto err_disable_mod_clk;
555 } 557 }
556 } else { 558 } else {
557 hdmi->ddc_parent_clk = hdmi->tmds_clk; 559 hdmi->ddc_parent_clk = hdmi->tmds_clk;
diff --git a/drivers/gpu/drm/sun4i/sun4i_rgb.c b/drivers/gpu/drm/sun4i/sun4i_rgb.c
index a2a697a099e6..f2fa1f210509 100644
--- a/drivers/gpu/drm/sun4i/sun4i_rgb.c
+++ b/drivers/gpu/drm/sun4i/sun4i_rgb.c
@@ -92,6 +92,8 @@ static enum drm_mode_status sun4i_rgb_mode_valid(struct drm_encoder *crtc,
92 92
93 DRM_DEBUG_DRIVER("Vertical parameters OK\n"); 93 DRM_DEBUG_DRIVER("Vertical parameters OK\n");
94 94
95 tcon->dclk_min_div = 6;
96 tcon->dclk_max_div = 127;
95 rounded_rate = clk_round_rate(tcon->dclk, rate); 97 rounded_rate = clk_round_rate(tcon->dclk, rate);
96 if (rounded_rate < rate) 98 if (rounded_rate < rate)
97 return MODE_CLOCK_LOW; 99 return MODE_CLOCK_LOW;
diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c
index 1a114e380f13..c3d92d537240 100644
--- a/drivers/gpu/drm/sun4i/sun4i_tcon.c
+++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c
@@ -103,10 +103,13 @@ static void sun4i_tcon_channel_set_status(struct sun4i_tcon *tcon, int channel,
103 return; 103 return;
104 } 104 }
105 105
106 if (enabled) 106 if (enabled) {
107 clk_prepare_enable(clk); 107 clk_prepare_enable(clk);
108 else 108 clk_rate_exclusive_get(clk);
109 } else {
110 clk_rate_exclusive_put(clk);
109 clk_disable_unprepare(clk); 111 clk_disable_unprepare(clk);
112 }
110} 113}
111 114
112static void sun4i_tcon_lvds_set_status(struct sun4i_tcon *tcon, 115static void sun4i_tcon_lvds_set_status(struct sun4i_tcon *tcon,
@@ -339,6 +342,9 @@ static void sun4i_tcon0_mode_set_lvds(struct sun4i_tcon *tcon,
339 regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, 342 regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
340 SUN4I_TCON_GCTL_IOMAP_MASK, 343 SUN4I_TCON_GCTL_IOMAP_MASK,
341 SUN4I_TCON_GCTL_IOMAP_TCON0); 344 SUN4I_TCON_GCTL_IOMAP_TCON0);
345
346 /* Enable the output on the pins */
347 regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0xe0000000);
342} 348}
343 349
344static void sun4i_tcon0_mode_set_rgb(struct sun4i_tcon *tcon, 350static void sun4i_tcon0_mode_set_rgb(struct sun4i_tcon *tcon,
@@ -921,52 +927,56 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master,
921 return ret; 927 return ret;
922 } 928 }
923 929
924 /* 930 if (tcon->quirks->supports_lvds) {
925 * This can only be made optional since we've had DT nodes 931 /*
926 * without the LVDS reset properties. 932 * This can only be made optional since we've had DT
927 * 933 * nodes without the LVDS reset properties.
928 * If the property is missing, just disable LVDS, and print a 934 *
929 * warning. 935 * If the property is missing, just disable LVDS, and
930 */ 936 * print a warning.
931 tcon->lvds_rst = devm_reset_control_get_optional(dev, "lvds"); 937 */
932 if (IS_ERR(tcon->lvds_rst)) { 938 tcon->lvds_rst = devm_reset_control_get_optional(dev, "lvds");
933 dev_err(dev, "Couldn't get our reset line\n"); 939 if (IS_ERR(tcon->lvds_rst)) {
934 return PTR_ERR(tcon->lvds_rst); 940 dev_err(dev, "Couldn't get our reset line\n");
935 } else if (tcon->lvds_rst) { 941 return PTR_ERR(tcon->lvds_rst);
936 has_lvds_rst = true; 942 } else if (tcon->lvds_rst) {
937 reset_control_reset(tcon->lvds_rst); 943 has_lvds_rst = true;
938 } else { 944 reset_control_reset(tcon->lvds_rst);
939 has_lvds_rst = false; 945 } else {
940 } 946 has_lvds_rst = false;
947 }
941 948
942 /* 949 /*
943 * This can only be made optional since we've had DT nodes 950 * This can only be made optional since we've had DT
944 * without the LVDS reset properties. 951 * nodes without the LVDS reset properties.
945 * 952 *
946 * If the property is missing, just disable LVDS, and print a 953 * If the property is missing, just disable LVDS, and
947 * warning. 954 * print a warning.
948 */ 955 */
949 if (tcon->quirks->has_lvds_alt) { 956 if (tcon->quirks->has_lvds_alt) {
950 tcon->lvds_pll = devm_clk_get(dev, "lvds-alt"); 957 tcon->lvds_pll = devm_clk_get(dev, "lvds-alt");
951 if (IS_ERR(tcon->lvds_pll)) { 958 if (IS_ERR(tcon->lvds_pll)) {
952 if (PTR_ERR(tcon->lvds_pll) == -ENOENT) { 959 if (PTR_ERR(tcon->lvds_pll) == -ENOENT) {
953 has_lvds_alt = false; 960 has_lvds_alt = false;
961 } else {
962 dev_err(dev, "Couldn't get the LVDS PLL\n");
963 return PTR_ERR(tcon->lvds_pll);
964 }
954 } else { 965 } else {
955 dev_err(dev, "Couldn't get the LVDS PLL\n"); 966 has_lvds_alt = true;
956 return PTR_ERR(tcon->lvds_pll);
957 } 967 }
958 } else {
959 has_lvds_alt = true;
960 } 968 }
961 }
962 969
963 if (!has_lvds_rst || (tcon->quirks->has_lvds_alt && !has_lvds_alt)) { 970 if (!has_lvds_rst ||
964 dev_warn(dev, 971 (tcon->quirks->has_lvds_alt && !has_lvds_alt)) {
965 "Missing LVDS properties, Please upgrade your DT\n"); 972 dev_warn(dev, "Missing LVDS properties, Please upgrade your DT\n");
966 dev_warn(dev, "LVDS output disabled\n"); 973 dev_warn(dev, "LVDS output disabled\n");
967 can_lvds = false; 974 can_lvds = false;
975 } else {
976 can_lvds = true;
977 }
968 } else { 978 } else {
969 can_lvds = true; 979 can_lvds = false;
970 } 980 }
971 981
972 ret = sun4i_tcon_init_clocks(dev, tcon); 982 ret = sun4i_tcon_init_clocks(dev, tcon);
@@ -1195,6 +1205,7 @@ static const struct sun4i_tcon_quirks sun8i_a33_quirks = {
1195}; 1205};
1196 1206
1197static const struct sun4i_tcon_quirks sun8i_a83t_lcd_quirks = { 1207static const struct sun4i_tcon_quirks sun8i_a83t_lcd_quirks = {
1208 .supports_lvds = true,
1198 .has_channel_0 = true, 1209 .has_channel_0 = true,
1199}; 1210};
1200 1211
diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.h b/drivers/gpu/drm/sun4i/sun4i_tcon.h
index d3a945b7bb60..161e09427124 100644
--- a/drivers/gpu/drm/sun4i/sun4i_tcon.h
+++ b/drivers/gpu/drm/sun4i/sun4i_tcon.h
@@ -177,6 +177,7 @@ struct sun4i_tcon_quirks {
177 bool has_lvds_alt; /* Does the LVDS clock have a parent other than the TCON clock? */ 177 bool has_lvds_alt; /* Does the LVDS clock have a parent other than the TCON clock? */
178 bool needs_de_be_mux; /* sun6i needs mux to select backend */ 178 bool needs_de_be_mux; /* sun6i needs mux to select backend */
179 bool needs_edp_reset; /* a80 edp reset needed for tcon0 access */ 179 bool needs_edp_reset; /* a80 edp reset needed for tcon0 access */
180 bool supports_lvds; /* Does the TCON support an LVDS output? */
180 181
181 /* callback to handle tcon muxing options */ 182 /* callback to handle tcon muxing options */
182 int (*set_mux)(struct sun4i_tcon *, const struct drm_encoder *); 183 int (*set_mux)(struct sun4i_tcon *, const struct drm_encoder *);
diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index 71152776b04c..616c9634585e 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -1916,8 +1916,12 @@ cleanup:
1916 if (!IS_ERR(primary)) 1916 if (!IS_ERR(primary))
1917 drm_plane_cleanup(primary); 1917 drm_plane_cleanup(primary);
1918 1918
1919 if (group && tegra->domain) { 1919 if (group && dc->domain) {
1920 iommu_detach_group(tegra->domain, group); 1920 if (group == tegra->group) {
1921 iommu_detach_group(dc->domain, group);
1922 tegra->group = NULL;
1923 }
1924
1921 dc->domain = NULL; 1925 dc->domain = NULL;
1922 } 1926 }
1923 1927
@@ -1926,8 +1930,10 @@ cleanup:
1926 1930
1927static int tegra_dc_exit(struct host1x_client *client) 1931static int tegra_dc_exit(struct host1x_client *client)
1928{ 1932{
1933 struct drm_device *drm = dev_get_drvdata(client->parent);
1929 struct iommu_group *group = iommu_group_get(client->dev); 1934 struct iommu_group *group = iommu_group_get(client->dev);
1930 struct tegra_dc *dc = host1x_client_to_dc(client); 1935 struct tegra_dc *dc = host1x_client_to_dc(client);
1936 struct tegra_drm *tegra = drm->dev_private;
1931 int err; 1937 int err;
1932 1938
1933 devm_free_irq(dc->dev, dc->irq, dc); 1939 devm_free_irq(dc->dev, dc->irq, dc);
@@ -1939,7 +1945,11 @@ static int tegra_dc_exit(struct host1x_client *client)
1939 } 1945 }
1940 1946
1941 if (group && dc->domain) { 1947 if (group && dc->domain) {
1942 iommu_detach_group(dc->domain, group); 1948 if (group == tegra->group) {
1949 iommu_detach_group(dc->domain, group);
1950 tegra->group = NULL;
1951 }
1952
1943 dc->domain = NULL; 1953 dc->domain = NULL;
1944 } 1954 }
1945 1955
diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
index e20e013151f0..7afe2f635f74 100644
--- a/drivers/gpu/drm/tegra/drm.c
+++ b/drivers/gpu/drm/tegra/drm.c
@@ -222,6 +222,7 @@ static void tegra_drm_unload(struct drm_device *drm)
222 222
223 drm_kms_helper_poll_fini(drm); 223 drm_kms_helper_poll_fini(drm);
224 tegra_drm_fb_exit(drm); 224 tegra_drm_fb_exit(drm);
225 drm_atomic_helper_shutdown(drm);
225 drm_mode_config_cleanup(drm); 226 drm_mode_config_cleanup(drm);
226 227
227 err = host1x_device_exit(device); 228 err = host1x_device_exit(device);
diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
index 4d2ed966f9e3..87c5d89bc9ba 100644
--- a/drivers/gpu/drm/tegra/dsi.c
+++ b/drivers/gpu/drm/tegra/dsi.c
@@ -1072,7 +1072,6 @@ static int tegra_dsi_exit(struct host1x_client *client)
1072 struct tegra_dsi *dsi = host1x_client_to_dsi(client); 1072 struct tegra_dsi *dsi = host1x_client_to_dsi(client);
1073 1073
1074 tegra_output_exit(&dsi->output); 1074 tegra_output_exit(&dsi->output);
1075 regulator_disable(dsi->vdd);
1076 1075
1077 return 0; 1076 return 0;
1078} 1077}
diff --git a/drivers/gpu/drm/tegra/plane.c b/drivers/gpu/drm/tegra/plane.c
index 6d6e2d0091eb..176ef46c615c 100644
--- a/drivers/gpu/drm/tegra/plane.c
+++ b/drivers/gpu/drm/tegra/plane.c
@@ -307,6 +307,10 @@ int tegra_plane_format_get_alpha(unsigned int opaque, unsigned int *alpha)
307 case WIN_COLOR_DEPTH_B8G8R8X8: 307 case WIN_COLOR_DEPTH_B8G8R8X8:
308 *alpha = WIN_COLOR_DEPTH_B8G8R8A8; 308 *alpha = WIN_COLOR_DEPTH_B8G8R8A8;
309 return 0; 309 return 0;
310
311 case WIN_COLOR_DEPTH_B5G6R5:
312 *alpha = opaque;
313 return 0;
310 } 314 }
311 315
312 return -EINVAL; 316 return -EINVAL;
@@ -340,9 +344,6 @@ void tegra_plane_check_dependent(struct tegra_plane *tegra,
340 unsigned int zpos[2]; 344 unsigned int zpos[2];
341 unsigned int i; 345 unsigned int i;
342 346
343 for (i = 0; i < 3; i++)
344 state->dependent[i] = false;
345
346 for (i = 0; i < 2; i++) 347 for (i = 0; i < 2; i++)
347 zpos[i] = 0; 348 zpos[i] = 0;
348 349
@@ -356,6 +357,8 @@ void tegra_plane_check_dependent(struct tegra_plane *tegra,
356 357
357 index = tegra_plane_get_overlap_index(tegra, p); 358 index = tegra_plane_get_overlap_index(tegra, p);
358 359
360 state->dependent[index] = false;
361
359 /* 362 /*
360 * If any of the other planes is on top of this plane and uses 363 * If any of the other planes is on top of this plane and uses
361 * a format with an alpha component, mark this plane as being 364 * a format with an alpha component, mark this plane as being
diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
index b5b335c9b2bb..2ebdc6d5a76e 100644
--- a/drivers/gpu/drm/udl/udl_fb.c
+++ b/drivers/gpu/drm/udl/udl_fb.c
@@ -159,10 +159,15 @@ static int udl_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
159{ 159{
160 unsigned long start = vma->vm_start; 160 unsigned long start = vma->vm_start;
161 unsigned long size = vma->vm_end - vma->vm_start; 161 unsigned long size = vma->vm_end - vma->vm_start;
162 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 162 unsigned long offset;
163 unsigned long page, pos; 163 unsigned long page, pos;
164 164
165 if (offset + size > info->fix.smem_len) 165 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
166 return -EINVAL;
167
168 offset = vma->vm_pgoff << PAGE_SHIFT;
169
170 if (offset > info->fix.smem_len || size > info->fix.smem_len - offset)
166 return -EINVAL; 171 return -EINVAL;
167 172
168 pos = (unsigned long)info->fix.smem_start + offset; 173 pos = (unsigned long)info->fix.smem_start + offset;
diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
index a14e8a2ec682..7bdf6f0e58a5 100644
--- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
+++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
@@ -198,6 +198,9 @@ static int virtio_gpu_getparam_ioctl(struct drm_device *dev, void *data,
198 case VIRTGPU_PARAM_3D_FEATURES: 198 case VIRTGPU_PARAM_3D_FEATURES:
199 value = vgdev->has_virgl_3d == true ? 1 : 0; 199 value = vgdev->has_virgl_3d == true ? 1 : 0;
200 break; 200 break;
201 case VIRTGPU_PARAM_CAPSET_QUERY_FIX:
202 value = 1;
203 break;
201 default: 204 default:
202 return -EINVAL; 205 return -EINVAL;
203 } 206 }
@@ -473,7 +476,7 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
473{ 476{
474 struct virtio_gpu_device *vgdev = dev->dev_private; 477 struct virtio_gpu_device *vgdev = dev->dev_private;
475 struct drm_virtgpu_get_caps *args = data; 478 struct drm_virtgpu_get_caps *args = data;
476 int size; 479 unsigned size, host_caps_size;
477 int i; 480 int i;
478 int found_valid = -1; 481 int found_valid = -1;
479 int ret; 482 int ret;
@@ -483,6 +486,10 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
483 if (vgdev->num_capsets == 0) 486 if (vgdev->num_capsets == 0)
484 return -ENOSYS; 487 return -ENOSYS;
485 488
489 /* don't allow userspace to pass 0 */
490 if (args->size == 0)
491 return -EINVAL;
492
486 spin_lock(&vgdev->display_info_lock); 493 spin_lock(&vgdev->display_info_lock);
487 for (i = 0; i < vgdev->num_capsets; i++) { 494 for (i = 0; i < vgdev->num_capsets; i++) {
488 if (vgdev->capsets[i].id == args->cap_set_id) { 495 if (vgdev->capsets[i].id == args->cap_set_id) {
@@ -498,11 +505,9 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
498 return -EINVAL; 505 return -EINVAL;
499 } 506 }
500 507
501 size = vgdev->capsets[found_valid].max_size; 508 host_caps_size = vgdev->capsets[found_valid].max_size;
502 if (args->size > size) { 509 /* only copy to user the minimum of the host caps size or the guest caps size */
503 spin_unlock(&vgdev->display_info_lock); 510 size = min(args->size, host_caps_size);
504 return -EINVAL;
505 }
506 511
507 list_for_each_entry(cache_ent, &vgdev->cap_cache, head) { 512 list_for_each_entry(cache_ent, &vgdev->cap_cache, head) {
508 if (cache_ent->id == args->cap_set_id && 513 if (cache_ent->id == args->cap_set_id &&
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 61a03ac90f8c..70e1a8820a7c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -1338,6 +1338,19 @@ static void __vmw_svga_disable(struct vmw_private *dev_priv)
1338 */ 1338 */
1339void vmw_svga_disable(struct vmw_private *dev_priv) 1339void vmw_svga_disable(struct vmw_private *dev_priv)
1340{ 1340{
1341 /*
1342 * Disabling SVGA will turn off device modesetting capabilities, so
1343 * notify KMS about that so that it doesn't cache atomic state that
1344 * isn't valid anymore, for example crtcs turned on.
1345 * Strictly we'd want to do this under the SVGA lock (or an SVGA mutex),
1346 * but vmw_kms_lost_device() takes the reservation sem and thus we'll
1347 * end up with lock order reversal. Thus, a master may actually perform
1348 * a new modeset just after we call vmw_kms_lost_device() and race with
1349 * vmw_svga_disable(), but that should at worst cause atomic KMS state
1350 * to be inconsistent with the device, causing modesetting problems.
1351 *
1352 */
1353 vmw_kms_lost_device(dev_priv->dev);
1341 ttm_write_lock(&dev_priv->reservation_sem, false); 1354 ttm_write_lock(&dev_priv->reservation_sem, false);
1342 spin_lock(&dev_priv->svga_lock); 1355 spin_lock(&dev_priv->svga_lock);
1343 if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) { 1356 if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 9e60de95b863..f34f368c1a2e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -949,6 +949,7 @@ int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
949void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv); 949void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
950int vmw_kms_suspend(struct drm_device *dev); 950int vmw_kms_suspend(struct drm_device *dev);
951int vmw_kms_resume(struct drm_device *dev); 951int vmw_kms_resume(struct drm_device *dev);
952void vmw_kms_lost_device(struct drm_device *dev);
952 953
953int vmw_dumb_create(struct drm_file *file_priv, 954int vmw_dumb_create(struct drm_file *file_priv,
954 struct drm_device *dev, 955 struct drm_device *dev,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 3628a9fe705f..f11601b6fd74 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -31,7 +31,6 @@
31#include <drm/drm_atomic_helper.h> 31#include <drm/drm_atomic_helper.h>
32#include <drm/drm_rect.h> 32#include <drm/drm_rect.h>
33 33
34
35/* Might need a hrtimer here? */ 34/* Might need a hrtimer here? */
36#define VMWGFX_PRESENT_RATE ((HZ / 60 > 0) ? HZ / 60 : 1) 35#define VMWGFX_PRESENT_RATE ((HZ / 60 > 0) ? HZ / 60 : 1)
37 36
@@ -2513,9 +2512,12 @@ void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
2513 * Helper to be used if an error forces the caller to undo the actions of 2512 * Helper to be used if an error forces the caller to undo the actions of
2514 * vmw_kms_helper_resource_prepare. 2513 * vmw_kms_helper_resource_prepare.
2515 */ 2514 */
2516void vmw_kms_helper_resource_revert(struct vmw_resource *res) 2515void vmw_kms_helper_resource_revert(struct vmw_validation_ctx *ctx)
2517{ 2516{
2518 vmw_kms_helper_buffer_revert(res->backup); 2517 struct vmw_resource *res = ctx->res;
2518
2519 vmw_kms_helper_buffer_revert(ctx->buf);
2520 vmw_dmabuf_unreference(&ctx->buf);
2519 vmw_resource_unreserve(res, false, NULL, 0); 2521 vmw_resource_unreserve(res, false, NULL, 0);
2520 mutex_unlock(&res->dev_priv->cmdbuf_mutex); 2522 mutex_unlock(&res->dev_priv->cmdbuf_mutex);
2521} 2523}
@@ -2532,10 +2534,14 @@ void vmw_kms_helper_resource_revert(struct vmw_resource *res)
2532 * interrupted by a signal. 2534 * interrupted by a signal.
2533 */ 2535 */
2534int vmw_kms_helper_resource_prepare(struct vmw_resource *res, 2536int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
2535 bool interruptible) 2537 bool interruptible,
2538 struct vmw_validation_ctx *ctx)
2536{ 2539{
2537 int ret = 0; 2540 int ret = 0;
2538 2541
2542 ctx->buf = NULL;
2543 ctx->res = res;
2544
2539 if (interruptible) 2545 if (interruptible)
2540 ret = mutex_lock_interruptible(&res->dev_priv->cmdbuf_mutex); 2546 ret = mutex_lock_interruptible(&res->dev_priv->cmdbuf_mutex);
2541 else 2547 else
@@ -2555,6 +2561,8 @@ int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
2555 false); 2561 false);
2556 if (ret) 2562 if (ret)
2557 goto out_unreserve; 2563 goto out_unreserve;
2564
2565 ctx->buf = vmw_dmabuf_reference(res->backup);
2558 } 2566 }
2559 ret = vmw_resource_validate(res); 2567 ret = vmw_resource_validate(res);
2560 if (ret) 2568 if (ret)
@@ -2562,7 +2570,7 @@ int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
2562 return 0; 2570 return 0;
2563 2571
2564out_revert: 2572out_revert:
2565 vmw_kms_helper_buffer_revert(res->backup); 2573 vmw_kms_helper_buffer_revert(ctx->buf);
2566out_unreserve: 2574out_unreserve:
2567 vmw_resource_unreserve(res, false, NULL, 0); 2575 vmw_resource_unreserve(res, false, NULL, 0);
2568out_unlock: 2576out_unlock:
@@ -2578,11 +2586,13 @@ out_unlock:
2578 * @out_fence: Optional pointer to a fence pointer. If non-NULL, a 2586 * @out_fence: Optional pointer to a fence pointer. If non-NULL, a
2579 * ref-counted fence pointer is returned here. 2587 * ref-counted fence pointer is returned here.
2580 */ 2588 */
2581void vmw_kms_helper_resource_finish(struct vmw_resource *res, 2589void vmw_kms_helper_resource_finish(struct vmw_validation_ctx *ctx,
2582 struct vmw_fence_obj **out_fence) 2590 struct vmw_fence_obj **out_fence)
2583{ 2591{
2584 if (res->backup || out_fence) 2592 struct vmw_resource *res = ctx->res;
2585 vmw_kms_helper_buffer_finish(res->dev_priv, NULL, res->backup, 2593
2594 if (ctx->buf || out_fence)
2595 vmw_kms_helper_buffer_finish(res->dev_priv, NULL, ctx->buf,
2586 out_fence, NULL); 2596 out_fence, NULL);
2587 2597
2588 vmw_resource_unreserve(res, false, NULL, 0); 2598 vmw_resource_unreserve(res, false, NULL, 0);
@@ -2896,3 +2906,13 @@ int vmw_kms_resume(struct drm_device *dev)
2896 2906
2897 return ret; 2907 return ret;
2898} 2908}
2909
2910/**
2911 * vmw_kms_lost_device - Notify kms that modesetting capabilities will be lost
2912 *
2913 * @dev: Pointer to the drm device
2914 */
2915void vmw_kms_lost_device(struct drm_device *dev)
2916{
2917 drm_atomic_helper_shutdown(dev);
2918}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
index 4e8749a8717e..6b7c012719f1 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
@@ -241,6 +241,11 @@ struct vmw_display_unit {
241 int set_gui_y; 241 int set_gui_y;
242}; 242};
243 243
244struct vmw_validation_ctx {
245 struct vmw_resource *res;
246 struct vmw_dma_buffer *buf;
247};
248
244#define vmw_crtc_to_du(x) \ 249#define vmw_crtc_to_du(x) \
245 container_of(x, struct vmw_display_unit, crtc) 250 container_of(x, struct vmw_display_unit, crtc)
246#define vmw_connector_to_du(x) \ 251#define vmw_connector_to_du(x) \
@@ -298,9 +303,10 @@ void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
298 struct drm_vmw_fence_rep __user * 303 struct drm_vmw_fence_rep __user *
299 user_fence_rep); 304 user_fence_rep);
300int vmw_kms_helper_resource_prepare(struct vmw_resource *res, 305int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
301 bool interruptible); 306 bool interruptible,
302void vmw_kms_helper_resource_revert(struct vmw_resource *res); 307 struct vmw_validation_ctx *ctx);
303void vmw_kms_helper_resource_finish(struct vmw_resource *res, 308void vmw_kms_helper_resource_revert(struct vmw_validation_ctx *ctx);
309void vmw_kms_helper_resource_finish(struct vmw_validation_ctx *ctx,
304 struct vmw_fence_obj **out_fence); 310 struct vmw_fence_obj **out_fence);
305int vmw_kms_readback(struct vmw_private *dev_priv, 311int vmw_kms_readback(struct vmw_private *dev_priv,
306 struct drm_file *file_priv, 312 struct drm_file *file_priv,
@@ -446,5 +452,4 @@ int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
446 452
447int vmw_kms_set_config(struct drm_mode_set *set, 453int vmw_kms_set_config(struct drm_mode_set *set,
448 struct drm_modeset_acquire_ctx *ctx); 454 struct drm_modeset_acquire_ctx *ctx);
449
450#endif 455#endif
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c b/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
index 419185f60278..648f8127f65a 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
@@ -938,12 +938,13 @@ int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
938 struct vmw_framebuffer_surface *vfbs = 938 struct vmw_framebuffer_surface *vfbs =
939 container_of(framebuffer, typeof(*vfbs), base); 939 container_of(framebuffer, typeof(*vfbs), base);
940 struct vmw_kms_sou_surface_dirty sdirty; 940 struct vmw_kms_sou_surface_dirty sdirty;
941 struct vmw_validation_ctx ctx;
941 int ret; 942 int ret;
942 943
943 if (!srf) 944 if (!srf)
944 srf = &vfbs->surface->res; 945 srf = &vfbs->surface->res;
945 946
946 ret = vmw_kms_helper_resource_prepare(srf, true); 947 ret = vmw_kms_helper_resource_prepare(srf, true, &ctx);
947 if (ret) 948 if (ret)
948 return ret; 949 return ret;
949 950
@@ -963,7 +964,7 @@ int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
963 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips, 964 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips,
964 dest_x, dest_y, num_clips, inc, 965 dest_x, dest_y, num_clips, inc,
965 &sdirty.base); 966 &sdirty.base);
966 vmw_kms_helper_resource_finish(srf, out_fence); 967 vmw_kms_helper_resource_finish(&ctx, out_fence);
967 968
968 return ret; 969 return ret;
969} 970}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
index 8eec88920851..67331f01ef32 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
@@ -916,12 +916,13 @@ int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
916 struct vmw_framebuffer_surface *vfbs = 916 struct vmw_framebuffer_surface *vfbs =
917 container_of(framebuffer, typeof(*vfbs), base); 917 container_of(framebuffer, typeof(*vfbs), base);
918 struct vmw_stdu_dirty sdirty; 918 struct vmw_stdu_dirty sdirty;
919 struct vmw_validation_ctx ctx;
919 int ret; 920 int ret;
920 921
921 if (!srf) 922 if (!srf)
922 srf = &vfbs->surface->res; 923 srf = &vfbs->surface->res;
923 924
924 ret = vmw_kms_helper_resource_prepare(srf, true); 925 ret = vmw_kms_helper_resource_prepare(srf, true, &ctx);
925 if (ret) 926 if (ret)
926 return ret; 927 return ret;
927 928
@@ -945,7 +946,7 @@ int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
945 dest_x, dest_y, num_clips, inc, 946 dest_x, dest_y, num_clips, inc,
946 &sdirty.base); 947 &sdirty.base);
947out_finish: 948out_finish:
948 vmw_kms_helper_resource_finish(srf, out_fence); 949 vmw_kms_helper_resource_finish(&ctx, out_fence);
949 950
950 return ret; 951 return ret;
951} 952}
diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 658fa2d3e40c..48685cddbad1 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -1089,7 +1089,7 @@ static void ipu_irq_handler(struct irq_desc *desc)
1089{ 1089{
1090 struct ipu_soc *ipu = irq_desc_get_handler_data(desc); 1090 struct ipu_soc *ipu = irq_desc_get_handler_data(desc);
1091 struct irq_chip *chip = irq_desc_get_chip(desc); 1091 struct irq_chip *chip = irq_desc_get_chip(desc);
1092 const int int_reg[] = { 0, 1, 2, 3, 10, 11, 12, 13, 14}; 1092 static const int int_reg[] = { 0, 1, 2, 3, 10, 11, 12, 13, 14};
1093 1093
1094 chained_irq_enter(chip, desc); 1094 chained_irq_enter(chip, desc);
1095 1095
@@ -1102,7 +1102,7 @@ static void ipu_err_irq_handler(struct irq_desc *desc)
1102{ 1102{
1103 struct ipu_soc *ipu = irq_desc_get_handler_data(desc); 1103 struct ipu_soc *ipu = irq_desc_get_handler_data(desc);
1104 struct irq_chip *chip = irq_desc_get_chip(desc); 1104 struct irq_chip *chip = irq_desc_get_chip(desc);
1105 const int int_reg[] = { 4, 5, 8, 9}; 1105 static const int int_reg[] = { 4, 5, 8, 9};
1106 1106
1107 chained_irq_enter(chip, desc); 1107 chained_irq_enter(chip, desc);
1108 1108
diff --git a/drivers/gpu/ipu-v3/ipu-cpmem.c b/drivers/gpu/ipu-v3/ipu-cpmem.c
index bb9c087e6c0d..9f2d9ec42add 100644
--- a/drivers/gpu/ipu-v3/ipu-cpmem.c
+++ b/drivers/gpu/ipu-v3/ipu-cpmem.c
@@ -788,12 +788,14 @@ int ipu_cpmem_set_image(struct ipuv3_channel *ch, struct ipu_image *image)
788 case V4L2_PIX_FMT_SGBRG8: 788 case V4L2_PIX_FMT_SGBRG8:
789 case V4L2_PIX_FMT_SGRBG8: 789 case V4L2_PIX_FMT_SGRBG8:
790 case V4L2_PIX_FMT_SRGGB8: 790 case V4L2_PIX_FMT_SRGGB8:
791 case V4L2_PIX_FMT_GREY:
791 offset = image->rect.left + image->rect.top * pix->bytesperline; 792 offset = image->rect.left + image->rect.top * pix->bytesperline;
792 break; 793 break;
793 case V4L2_PIX_FMT_SBGGR16: 794 case V4L2_PIX_FMT_SBGGR16:
794 case V4L2_PIX_FMT_SGBRG16: 795 case V4L2_PIX_FMT_SGBRG16:
795 case V4L2_PIX_FMT_SGRBG16: 796 case V4L2_PIX_FMT_SGRBG16:
796 case V4L2_PIX_FMT_SRGGB16: 797 case V4L2_PIX_FMT_SRGGB16:
798 case V4L2_PIX_FMT_Y16:
797 offset = image->rect.left * 2 + 799 offset = image->rect.left * 2 +
798 image->rect.top * pix->bytesperline; 800 image->rect.top * pix->bytesperline;
799 break; 801 break;
diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 24e12b87a0cb..caa05b0702e1 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -288,6 +288,7 @@ static int mbus_code_to_bus_cfg(struct ipu_csi_bus_config *cfg, u32 mbus_code)
288 case MEDIA_BUS_FMT_SGBRG10_1X10: 288 case MEDIA_BUS_FMT_SGBRG10_1X10:
289 case MEDIA_BUS_FMT_SGRBG10_1X10: 289 case MEDIA_BUS_FMT_SGRBG10_1X10:
290 case MEDIA_BUS_FMT_SRGGB10_1X10: 290 case MEDIA_BUS_FMT_SRGGB10_1X10:
291 case MEDIA_BUS_FMT_Y10_1X10:
291 cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_BAYER; 292 cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_BAYER;
292 cfg->mipi_dt = MIPI_DT_RAW10; 293 cfg->mipi_dt = MIPI_DT_RAW10;
293 cfg->data_width = IPU_CSI_DATA_WIDTH_10; 294 cfg->data_width = IPU_CSI_DATA_WIDTH_10;
@@ -296,6 +297,7 @@ static int mbus_code_to_bus_cfg(struct ipu_csi_bus_config *cfg, u32 mbus_code)
296 case MEDIA_BUS_FMT_SGBRG12_1X12: 297 case MEDIA_BUS_FMT_SGBRG12_1X12:
297 case MEDIA_BUS_FMT_SGRBG12_1X12: 298 case MEDIA_BUS_FMT_SGRBG12_1X12:
298 case MEDIA_BUS_FMT_SRGGB12_1X12: 299 case MEDIA_BUS_FMT_SRGGB12_1X12:
300 case MEDIA_BUS_FMT_Y12_1X12:
299 cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_BAYER; 301 cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_BAYER;
300 cfg->mipi_dt = MIPI_DT_RAW12; 302 cfg->mipi_dt = MIPI_DT_RAW12;
301 cfg->data_width = IPU_CSI_DATA_WIDTH_12; 303 cfg->data_width = IPU_CSI_DATA_WIDTH_12;
diff --git a/drivers/gpu/ipu-v3/ipu-pre.c b/drivers/gpu/ipu-v3/ipu-pre.c
index f1cec3d70498..0f70e8847540 100644
--- a/drivers/gpu/ipu-v3/ipu-pre.c
+++ b/drivers/gpu/ipu-v3/ipu-pre.c
@@ -129,11 +129,14 @@ ipu_pre_lookup_by_phandle(struct device *dev, const char *name, int index)
129 if (pre_node == pre->dev->of_node) { 129 if (pre_node == pre->dev->of_node) {
130 mutex_unlock(&ipu_pre_list_mutex); 130 mutex_unlock(&ipu_pre_list_mutex);
131 device_link_add(dev, pre->dev, DL_FLAG_AUTOREMOVE); 131 device_link_add(dev, pre->dev, DL_FLAG_AUTOREMOVE);
132 of_node_put(pre_node);
132 return pre; 133 return pre;
133 } 134 }
134 } 135 }
135 mutex_unlock(&ipu_pre_list_mutex); 136 mutex_unlock(&ipu_pre_list_mutex);
136 137
138 of_node_put(pre_node);
139
137 return NULL; 140 return NULL;
138} 141}
139 142
diff --git a/drivers/gpu/ipu-v3/ipu-prg.c b/drivers/gpu/ipu-v3/ipu-prg.c
index 067365c733c6..83f9dd934a5d 100644
--- a/drivers/gpu/ipu-v3/ipu-prg.c
+++ b/drivers/gpu/ipu-v3/ipu-prg.c
@@ -102,11 +102,14 @@ ipu_prg_lookup_by_phandle(struct device *dev, const char *name, int ipu_id)
102 mutex_unlock(&ipu_prg_list_mutex); 102 mutex_unlock(&ipu_prg_list_mutex);
103 device_link_add(dev, prg->dev, DL_FLAG_AUTOREMOVE); 103 device_link_add(dev, prg->dev, DL_FLAG_AUTOREMOVE);
104 prg->id = ipu_id; 104 prg->id = ipu_id;
105 of_node_put(prg_node);
105 return prg; 106 return prg;
106 } 107 }
107 } 108 }
108 mutex_unlock(&ipu_prg_list_mutex); 109 mutex_unlock(&ipu_prg_list_mutex);
109 110
111 of_node_put(prg_node);
112
110 return NULL; 113 return NULL;
111} 114}
112 115
@@ -247,10 +250,14 @@ void ipu_prg_channel_disable(struct ipuv3_channel *ipu_chan)
247{ 250{
248 int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num); 251 int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
249 struct ipu_prg *prg = ipu_chan->ipu->prg_priv; 252 struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
250 struct ipu_prg_channel *chan = &prg->chan[prg_chan]; 253 struct ipu_prg_channel *chan;
251 u32 val; 254 u32 val;
252 255
253 if (!chan->enabled || prg_chan < 0) 256 if (prg_chan < 0)
257 return;
258
259 chan = &prg->chan[prg_chan];
260 if (!chan->enabled)
254 return; 261 return;
255 262
256 pm_runtime_get_sync(prg->dev); 263 pm_runtime_get_sync(prg->dev);
@@ -277,13 +284,15 @@ int ipu_prg_channel_configure(struct ipuv3_channel *ipu_chan,
277{ 284{
278 int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num); 285 int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
279 struct ipu_prg *prg = ipu_chan->ipu->prg_priv; 286 struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
280 struct ipu_prg_channel *chan = &prg->chan[prg_chan]; 287 struct ipu_prg_channel *chan;
281 u32 val; 288 u32 val;
282 int ret; 289 int ret;
283 290
284 if (prg_chan < 0) 291 if (prg_chan < 0)
285 return prg_chan; 292 return prg_chan;
286 293
294 chan = &prg->chan[prg_chan];
295
287 if (chan->enabled) { 296 if (chan->enabled) {
288 ipu_pre_update(prg->pres[chan->used_pre], *eba); 297 ipu_pre_update(prg->pres[chan->used_pre], *eba);
289 return 0; 298 return 0;
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 43ddcdfbd0da..9454ac134ce2 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -645,6 +645,9 @@
645#define USB_DEVICE_ID_LD_MICROCASSYTIME 0x1033 645#define USB_DEVICE_ID_LD_MICROCASSYTIME 0x1033
646#define USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE 0x1035 646#define USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE 0x1035
647#define USB_DEVICE_ID_LD_MICROCASSYPH 0x1038 647#define USB_DEVICE_ID_LD_MICROCASSYPH 0x1038
648#define USB_DEVICE_ID_LD_POWERANALYSERCASSY 0x1040
649#define USB_DEVICE_ID_LD_CONVERTERCONTROLLERCASSY 0x1042
650#define USB_DEVICE_ID_LD_MACHINETESTCASSY 0x1043
648#define USB_DEVICE_ID_LD_JWM 0x1080 651#define USB_DEVICE_ID_LD_JWM 0x1080
649#define USB_DEVICE_ID_LD_DMMP 0x1081 652#define USB_DEVICE_ID_LD_DMMP 0x1081
650#define USB_DEVICE_ID_LD_UMIP 0x1090 653#define USB_DEVICE_ID_LD_UMIP 0x1090
diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index 5f6035a5ce36..e92b77fa574a 100644
--- a/drivers/hid/hid-quirks.c
+++ b/drivers/hid/hid-quirks.c
@@ -809,6 +809,9 @@ static const struct hid_device_id hid_ignore_list[] = {
809 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) }, 809 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
810 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) }, 810 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
811 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) }, 811 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
812 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERANALYSERCASSY) },
813 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CONVERTERCONTROLLERCASSY) },
814 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETESTCASSY) },
812 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, 815 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
813 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, 816 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
814 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) }, 817 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 50e071444a5c..8699bb969e7e 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -417,13 +417,24 @@ __hv_pkt_iter_next(struct vmbus_channel *channel,
417} 417}
418EXPORT_SYMBOL_GPL(__hv_pkt_iter_next); 418EXPORT_SYMBOL_GPL(__hv_pkt_iter_next);
419 419
420/* How many bytes were read in this iterator cycle */
421static u32 hv_pkt_iter_bytes_read(const struct hv_ring_buffer_info *rbi,
422 u32 start_read_index)
423{
424 if (rbi->priv_read_index >= start_read_index)
425 return rbi->priv_read_index - start_read_index;
426 else
427 return rbi->ring_datasize - start_read_index +
428 rbi->priv_read_index;
429}
430
420/* 431/*
421 * Update host ring buffer after iterating over packets. 432 * Update host ring buffer after iterating over packets.
422 */ 433 */
423void hv_pkt_iter_close(struct vmbus_channel *channel) 434void hv_pkt_iter_close(struct vmbus_channel *channel)
424{ 435{
425 struct hv_ring_buffer_info *rbi = &channel->inbound; 436 struct hv_ring_buffer_info *rbi = &channel->inbound;
426 u32 orig_write_sz = hv_get_bytes_to_write(rbi); 437 u32 curr_write_sz, pending_sz, bytes_read, start_read_index;
427 438
428 /* 439 /*
429 * Make sure all reads are done before we update the read index since 440 * Make sure all reads are done before we update the read index since
@@ -431,8 +442,12 @@ void hv_pkt_iter_close(struct vmbus_channel *channel)
431 * is updated. 442 * is updated.
432 */ 443 */
433 virt_rmb(); 444 virt_rmb();
445 start_read_index = rbi->ring_buffer->read_index;
434 rbi->ring_buffer->read_index = rbi->priv_read_index; 446 rbi->ring_buffer->read_index = rbi->priv_read_index;
435 447
448 if (!rbi->ring_buffer->feature_bits.feat_pending_send_sz)
449 return;
450
436 /* 451 /*
437 * Issue a full memory barrier before making the signaling decision. 452 * Issue a full memory barrier before making the signaling decision.
438 * Here is the reason for having this barrier: 453 * Here is the reason for having this barrier:
@@ -446,26 +461,29 @@ void hv_pkt_iter_close(struct vmbus_channel *channel)
446 */ 461 */
447 virt_mb(); 462 virt_mb();
448 463
449 /* If host has disabled notifications then skip */ 464 pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
450 if (rbi->ring_buffer->interrupt_mask) 465 if (!pending_sz)
451 return; 466 return;
452 467
453 if (rbi->ring_buffer->feature_bits.feat_pending_send_sz) { 468 /*
454 u32 pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz); 469 * Ensure the read of write_index in hv_get_bytes_to_write()
470 * happens after the read of pending_send_sz.
471 */
472 virt_rmb();
473 curr_write_sz = hv_get_bytes_to_write(rbi);
474 bytes_read = hv_pkt_iter_bytes_read(rbi, start_read_index);
455 475
456 /* 476 /*
457 * If there was space before we began iteration, 477 * If there was space before we began iteration,
458 * then host was not blocked. Also handles case where 478 * then host was not blocked.
459 * pending_sz is zero then host has nothing pending 479 */
460 * and does not need to be signaled.
461 */
462 if (orig_write_sz > pending_sz)
463 return;
464 480
465 /* If pending write will not fit, don't give false hope. */ 481 if (curr_write_sz - bytes_read > pending_sz)
466 if (hv_get_bytes_to_write(rbi) < pending_sz) 482 return;
467 return; 483
468 } 484 /* If pending write will not fit, don't give false hope. */
485 if (curr_write_sz <= pending_sz)
486 return;
469 487
470 vmbus_setevent(channel); 488 vmbus_setevent(channel);
471} 489}
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 4bdbf77f7197..72c338eb5fae 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -269,13 +269,13 @@ static int adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev)
269 for (i = 0; i < ARRAY_SIZE(tjmax_model_table); i++) { 269 for (i = 0; i < ARRAY_SIZE(tjmax_model_table); i++) {
270 const struct tjmax_model *tm = &tjmax_model_table[i]; 270 const struct tjmax_model *tm = &tjmax_model_table[i];
271 if (c->x86_model == tm->model && 271 if (c->x86_model == tm->model &&
272 (tm->mask == ANY || c->x86_mask == tm->mask)) 272 (tm->mask == ANY || c->x86_stepping == tm->mask))
273 return tm->tjmax; 273 return tm->tjmax;
274 } 274 }
275 275
276 /* Early chips have no MSR for TjMax */ 276 /* Early chips have no MSR for TjMax */
277 277
278 if (c->x86_model == 0xf && c->x86_mask < 4) 278 if (c->x86_model == 0xf && c->x86_stepping < 4)
279 usemsr_ee = 0; 279 usemsr_ee = 0;
280 280
281 if (c->x86_model > 0xe && usemsr_ee) { 281 if (c->x86_model > 0xe && usemsr_ee) {
@@ -426,7 +426,7 @@ static int chk_ucode_version(unsigned int cpu)
426 * Readings might stop update when processor visited too deep sleep, 426 * Readings might stop update when processor visited too deep sleep,
427 * fixed for stepping D0 (6EC). 427 * fixed for stepping D0 (6EC).
428 */ 428 */
429 if (c->x86_model == 0xe && c->x86_mask < 0xc && c->microcode < 0x39) { 429 if (c->x86_model == 0xe && c->x86_stepping < 0xc && c->microcode < 0x39) {
430 pr_err("Errata AE18 not fixed, update BIOS or microcode of the CPU!\n"); 430 pr_err("Errata AE18 not fixed, update BIOS or microcode of the CPU!\n");
431 return -ENODEV; 431 return -ENODEV;
432 } 432 }
diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
index ef91b8a67549..84e91286fc4f 100644
--- a/drivers/hwmon/hwmon-vid.c
+++ b/drivers/hwmon/hwmon-vid.c
@@ -293,7 +293,7 @@ u8 vid_which_vrm(void)
293 if (c->x86 < 6) /* Any CPU with family lower than 6 */ 293 if (c->x86 < 6) /* Any CPU with family lower than 6 */
294 return 0; /* doesn't have VID */ 294 return 0; /* doesn't have VID */
295 295
296 vrm_ret = find_vrm(c->x86, c->x86_model, c->x86_mask, c->x86_vendor); 296 vrm_ret = find_vrm(c->x86, c->x86_model, c->x86_stepping, c->x86_vendor);
297 if (vrm_ret == 134) 297 if (vrm_ret == 134)
298 vrm_ret = get_via_model_d_vrm(); 298 vrm_ret = get_via_model_d_vrm();
299 if (vrm_ret == 0) 299 if (vrm_ret == 0)
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
index 06b4e1c78bd8..051a72eecb24 100644
--- a/drivers/hwmon/k10temp.c
+++ b/drivers/hwmon/k10temp.c
@@ -129,7 +129,10 @@ static ssize_t temp1_input_show(struct device *dev,
129 129
130 data->read_tempreg(data->pdev, &regval); 130 data->read_tempreg(data->pdev, &regval);
131 temp = (regval >> 21) * 125; 131 temp = (regval >> 21) * 125;
132 temp -= data->temp_offset; 132 if (temp > data->temp_offset)
133 temp -= data->temp_offset;
134 else
135 temp = 0;
133 136
134 return sprintf(buf, "%u\n", temp); 137 return sprintf(buf, "%u\n", temp);
135} 138}
@@ -227,7 +230,7 @@ static bool has_erratum_319(struct pci_dev *pdev)
227 * and AM3 formats, but that's the best we can do. 230 * and AM3 formats, but that's the best we can do.
228 */ 231 */
229 return boot_cpu_data.x86_model < 4 || 232 return boot_cpu_data.x86_model < 4 ||
230 (boot_cpu_data.x86_model == 4 && boot_cpu_data.x86_mask <= 2); 233 (boot_cpu_data.x86_model == 4 && boot_cpu_data.x86_stepping <= 2);
231} 234}
232 235
233static int k10temp_probe(struct pci_dev *pdev, 236static int k10temp_probe(struct pci_dev *pdev,
diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c
index 5a632bcf869b..e59f9113fb93 100644
--- a/drivers/hwmon/k8temp.c
+++ b/drivers/hwmon/k8temp.c
@@ -187,7 +187,7 @@ static int k8temp_probe(struct pci_dev *pdev,
187 return -ENOMEM; 187 return -ENOMEM;
188 188
189 model = boot_cpu_data.x86_model; 189 model = boot_cpu_data.x86_model;
190 stepping = boot_cpu_data.x86_mask; 190 stepping = boot_cpu_data.x86_stepping;
191 191
192 /* feature available since SH-C0, exclude older revisions */ 192 /* feature available since SH-C0, exclude older revisions */
193 if ((model == 4 && stepping == 0) || 193 if ((model == 4 && stepping == 0) ||
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index a9805c7cb305..e2954fb86d65 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -123,8 +123,10 @@ config I2C_I801
123 Wildcat Point (PCH) 123 Wildcat Point (PCH)
124 Wildcat Point-LP (PCH) 124 Wildcat Point-LP (PCH)
125 BayTrail (SOC) 125 BayTrail (SOC)
126 Braswell (SOC)
126 Sunrise Point-H (PCH) 127 Sunrise Point-H (PCH)
127 Sunrise Point-LP (PCH) 128 Sunrise Point-LP (PCH)
129 Kaby Lake-H (PCH)
128 DNV (SOC) 130 DNV (SOC)
129 Broxton (SOC) 131 Broxton (SOC)
130 Lewisburg (PCH) 132 Lewisburg (PCH)
diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c
index cd07a69e2e93..44deae78913e 100644
--- a/drivers/i2c/busses/i2c-bcm2835.c
+++ b/drivers/i2c/busses/i2c-bcm2835.c
@@ -50,6 +50,9 @@
50#define BCM2835_I2C_S_CLKT BIT(9) 50#define BCM2835_I2C_S_CLKT BIT(9)
51#define BCM2835_I2C_S_LEN BIT(10) /* Fake bit for SW error reporting */ 51#define BCM2835_I2C_S_LEN BIT(10) /* Fake bit for SW error reporting */
52 52
53#define BCM2835_I2C_FEDL_SHIFT 16
54#define BCM2835_I2C_REDL_SHIFT 0
55
53#define BCM2835_I2C_CDIV_MIN 0x0002 56#define BCM2835_I2C_CDIV_MIN 0x0002
54#define BCM2835_I2C_CDIV_MAX 0xFFFE 57#define BCM2835_I2C_CDIV_MAX 0xFFFE
55 58
@@ -81,7 +84,7 @@ static inline u32 bcm2835_i2c_readl(struct bcm2835_i2c_dev *i2c_dev, u32 reg)
81 84
82static int bcm2835_i2c_set_divider(struct bcm2835_i2c_dev *i2c_dev) 85static int bcm2835_i2c_set_divider(struct bcm2835_i2c_dev *i2c_dev)
83{ 86{
84 u32 divider; 87 u32 divider, redl, fedl;
85 88
86 divider = DIV_ROUND_UP(clk_get_rate(i2c_dev->clk), 89 divider = DIV_ROUND_UP(clk_get_rate(i2c_dev->clk),
87 i2c_dev->bus_clk_rate); 90 i2c_dev->bus_clk_rate);
@@ -100,6 +103,22 @@ static int bcm2835_i2c_set_divider(struct bcm2835_i2c_dev *i2c_dev)
100 103
101 bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DIV, divider); 104 bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DIV, divider);
102 105
106 /*
107 * Number of core clocks to wait after falling edge before
108 * outputting the next data bit. Note that both FEDL and REDL
109 * can't be greater than CDIV/2.
110 */
111 fedl = max(divider / 16, 1u);
112
113 /*
114 * Number of core clocks to wait after rising edge before
115 * sampling the next incoming data bit.
116 */
117 redl = max(divider / 4, 1u);
118
119 bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DEL,
120 (fedl << BCM2835_I2C_FEDL_SHIFT) |
121 (redl << BCM2835_I2C_REDL_SHIFT));
103 return 0; 122 return 0;
104} 123}
105 124
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index ae691884d071..05732531829f 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -209,7 +209,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
209 i2c_dw_disable_int(dev); 209 i2c_dw_disable_int(dev);
210 210
211 /* Enable the adapter */ 211 /* Enable the adapter */
212 __i2c_dw_enable(dev, true); 212 __i2c_dw_enable_and_wait(dev, true);
213 213
214 /* Clear and enable interrupts */ 214 /* Clear and enable interrupts */
215 dw_readl(dev, DW_IC_CLR_INTR); 215 dw_readl(dev, DW_IC_CLR_INTR);
@@ -644,7 +644,7 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
644 gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH); 644 gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH);
645 if (IS_ERR(gpio)) { 645 if (IS_ERR(gpio)) {
646 r = PTR_ERR(gpio); 646 r = PTR_ERR(gpio);
647 if (r == -ENOENT) 647 if (r == -ENOENT || r == -ENOSYS)
648 return 0; 648 return 0;
649 return r; 649 return r;
650 } 650 }
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 8eac00efadc1..692b34125866 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -58,6 +58,7 @@
58 * Wildcat Point (PCH) 0x8ca2 32 hard yes yes yes 58 * Wildcat Point (PCH) 0x8ca2 32 hard yes yes yes
59 * Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes 59 * Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes
60 * BayTrail (SOC) 0x0f12 32 hard yes yes yes 60 * BayTrail (SOC) 0x0f12 32 hard yes yes yes
61 * Braswell (SOC) 0x2292 32 hard yes yes yes
61 * Sunrise Point-H (PCH) 0xa123 32 hard yes yes yes 62 * Sunrise Point-H (PCH) 0xa123 32 hard yes yes yes
62 * Sunrise Point-LP (PCH) 0x9d23 32 hard yes yes yes 63 * Sunrise Point-LP (PCH) 0x9d23 32 hard yes yes yes
63 * DNV (SOC) 0x19df 32 hard yes yes yes 64 * DNV (SOC) 0x19df 32 hard yes yes yes
diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-octeon-core.c
index 1d8775799056..d9607905dc2f 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -233,6 +233,7 @@ static int octeon_i2c_check_status(struct octeon_i2c *i2c, int final_read)
233 return -EOPNOTSUPP; 233 return -EOPNOTSUPP;
234 234
235 case STAT_TXDATA_NAK: 235 case STAT_TXDATA_NAK:
236 case STAT_BUS_ERROR:
236 return -EIO; 237 return -EIO;
237 case STAT_TXADDR_NAK: 238 case STAT_TXADDR_NAK:
238 case STAT_RXADDR_NAK: 239 case STAT_RXADDR_NAK:
diff --git a/drivers/i2c/busses/i2c-octeon-core.h b/drivers/i2c/busses/i2c-octeon-core.h
index a7ef19855bb8..9bb9f64fdda0 100644
--- a/drivers/i2c/busses/i2c-octeon-core.h
+++ b/drivers/i2c/busses/i2c-octeon-core.h
@@ -43,7 +43,7 @@
43#define TWSI_CTL_AAK 0x04 /* Assert ACK */ 43#define TWSI_CTL_AAK 0x04 /* Assert ACK */
44 44
45/* Status values */ 45/* Status values */
46#define STAT_ERROR 0x00 46#define STAT_BUS_ERROR 0x00
47#define STAT_START 0x08 47#define STAT_START 0x08
48#define STAT_REP_START 0x10 48#define STAT_REP_START 0x10
49#define STAT_TXADDR_ACK 0x18 49#define STAT_TXADDR_ACK 0x18
diff --git a/drivers/i2c/busses/i2c-sirf.c b/drivers/i2c/busses/i2c-sirf.c
index 2fd8b6d00391..87197ece0f90 100644
--- a/drivers/i2c/busses/i2c-sirf.c
+++ b/drivers/i2c/busses/i2c-sirf.c
@@ -341,7 +341,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
341 platform_set_drvdata(pdev, adap); 341 platform_set_drvdata(pdev, adap);
342 init_completion(&siic->done); 342 init_completion(&siic->done);
343 343
344 /* Controller Initalisation */ 344 /* Controller initialisation */
345 345
346 writel(SIRFSOC_I2C_RESET, siic->base + SIRFSOC_I2C_CTRL); 346 writel(SIRFSOC_I2C_RESET, siic->base + SIRFSOC_I2C_CTRL);
347 while (readl(siic->base + SIRFSOC_I2C_CTRL) & SIRFSOC_I2C_RESET) 347 while (readl(siic->base + SIRFSOC_I2C_CTRL) & SIRFSOC_I2C_RESET)
@@ -369,7 +369,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
369 * but they start to affect the speed when clock is set to faster 369 * but they start to affect the speed when clock is set to faster
370 * frequencies. 370 * frequencies.
371 * Through the actual tests, use the different user_div value(which 371 * Through the actual tests, use the different user_div value(which
372 * in the divider formular 'Fio / (Fi2c * user_div)') to adapt 372 * in the divider formula 'Fio / (Fi2c * user_div)') to adapt
373 * the different ranges of i2c bus clock frequency, to make the SCL 373 * the different ranges of i2c bus clock frequency, to make the SCL
374 * more accurate. 374 * more accurate.
375 */ 375 */
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 17fd55af4d92..caa20eb5f26b 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -928,7 +928,7 @@ static int exact_lock(dev_t dev, void *data)
928{ 928{
929 struct gendisk *p = data; 929 struct gendisk *p = data;
930 930
931 if (!get_disk(p)) 931 if (!get_disk_and_module(p))
932 return -1; 932 return -1;
933 return 0; 933 return 0;
934} 934}
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 6fe995cf16a6..3e6fd5a8ac5b 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -920,6 +920,8 @@ static const struct iio_trigger_ops st_accel_trigger_ops = {
920int st_accel_common_probe(struct iio_dev *indio_dev) 920int st_accel_common_probe(struct iio_dev *indio_dev)
921{ 921{
922 struct st_sensor_data *adata = iio_priv(indio_dev); 922 struct st_sensor_data *adata = iio_priv(indio_dev);
923 struct st_sensors_platform_data *pdata =
924 (struct st_sensors_platform_data *)adata->dev->platform_data;
923 int irq = adata->get_irq_data_ready(indio_dev); 925 int irq = adata->get_irq_data_ready(indio_dev);
924 int err; 926 int err;
925 927
@@ -946,7 +948,10 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
946 &adata->sensor_settings->fs.fs_avl[0]; 948 &adata->sensor_settings->fs.fs_avl[0];
947 adata->odr = adata->sensor_settings->odr.odr_avl[0].hz; 949 adata->odr = adata->sensor_settings->odr.odr_avl[0].hz;
948 950
949 err = st_sensors_init_sensor(indio_dev, adata->dev->platform_data); 951 if (!pdata)
952 pdata = (struct st_sensors_platform_data *)&default_accel_pdata;
953
954 err = st_sensors_init_sensor(indio_dev, pdata);
950 if (err < 0) 955 if (err < 0)
951 goto st_accel_power_off; 956 goto st_accel_power_off;
952 957
diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c
index 327a49ba1991..9515ca165dfd 100644
--- a/drivers/iio/adc/aspeed_adc.c
+++ b/drivers/iio/adc/aspeed_adc.c
@@ -243,7 +243,7 @@ static int aspeed_adc_probe(struct platform_device *pdev)
243 ASPEED_ADC_INIT_POLLING_TIME, 243 ASPEED_ADC_INIT_POLLING_TIME,
244 ASPEED_ADC_INIT_TIMEOUT); 244 ASPEED_ADC_INIT_TIMEOUT);
245 if (ret) 245 if (ret)
246 goto scaler_error; 246 goto poll_timeout_error;
247 } 247 }
248 248
249 /* Start all channels in normal mode. */ 249 /* Start all channels in normal mode. */
@@ -274,9 +274,10 @@ iio_register_error:
274 writel(ASPEED_OPERATION_MODE_POWER_DOWN, 274 writel(ASPEED_OPERATION_MODE_POWER_DOWN,
275 data->base + ASPEED_REG_ENGINE_CONTROL); 275 data->base + ASPEED_REG_ENGINE_CONTROL);
276 clk_disable_unprepare(data->clk_scaler->clk); 276 clk_disable_unprepare(data->clk_scaler->clk);
277reset_error:
278 reset_control_assert(data->rst);
279clk_enable_error: 277clk_enable_error:
278poll_timeout_error:
279 reset_control_assert(data->rst);
280reset_error:
280 clk_hw_unregister_divider(data->clk_scaler); 281 clk_hw_unregister_divider(data->clk_scaler);
281scaler_error: 282scaler_error:
282 clk_hw_unregister_divider(data->clk_prescaler); 283 clk_hw_unregister_divider(data->clk_prescaler);
diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 29fa7736d80c..ede955d9b2a4 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -462,8 +462,10 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev)
462 regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val); 462 regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val);
463 } while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--); 463 } while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--);
464 464
465 if (timeout < 0) 465 if (timeout < 0) {
466 mutex_unlock(&indio_dev->mlock);
466 return -ETIMEDOUT; 467 return -ETIMEDOUT;
468 }
467 } 469 }
468 470
469 return 0; 471 return 0;
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index 7f5def465340..9a2583caedaa 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -722,8 +722,6 @@ static int stm32h7_adc_enable(struct stm32_adc *adc)
722 int ret; 722 int ret;
723 u32 val; 723 u32 val;
724 724
725 /* Clear ADRDY by writing one, then enable ADC */
726 stm32_adc_set_bits(adc, STM32H7_ADC_ISR, STM32H7_ADRDY);
727 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADEN); 725 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADEN);
728 726
729 /* Poll for ADRDY to be set (after adc startup time) */ 727 /* Poll for ADRDY to be set (after adc startup time) */
@@ -731,8 +729,11 @@ static int stm32h7_adc_enable(struct stm32_adc *adc)
731 val & STM32H7_ADRDY, 729 val & STM32H7_ADRDY,
732 100, STM32_ADC_TIMEOUT_US); 730 100, STM32_ADC_TIMEOUT_US);
733 if (ret) { 731 if (ret) {
734 stm32_adc_clr_bits(adc, STM32H7_ADC_CR, STM32H7_ADEN); 732 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADDIS);
735 dev_err(&indio_dev->dev, "Failed to enable ADC\n"); 733 dev_err(&indio_dev->dev, "Failed to enable ADC\n");
734 } else {
735 /* Clear ADRDY by writing one */
736 stm32_adc_set_bits(adc, STM32H7_ADC_ISR, STM32H7_ADRDY);
736 } 737 }
737 738
738 return ret; 739 return ret;
diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c
index daa026d6a94f..01422d11753c 100644
--- a/drivers/iio/adc/stm32-dfsdm-adc.c
+++ b/drivers/iio/adc/stm32-dfsdm-adc.c
@@ -54,7 +54,6 @@ struct stm32_dfsdm_adc {
54 struct stm32_dfsdm *dfsdm; 54 struct stm32_dfsdm *dfsdm;
55 const struct stm32_dfsdm_dev_data *dev_data; 55 const struct stm32_dfsdm_dev_data *dev_data;
56 unsigned int fl_id; 56 unsigned int fl_id;
57 unsigned int ch_id;
58 57
59 /* ADC specific */ 58 /* ADC specific */
60 unsigned int oversamp; 59 unsigned int oversamp;
@@ -384,7 +383,7 @@ static ssize_t dfsdm_adc_audio_set_spiclk(struct iio_dev *indio_dev,
384{ 383{
385 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); 384 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
386 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id]; 385 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
387 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[adc->ch_id]; 386 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel];
388 unsigned int sample_freq = adc->sample_freq; 387 unsigned int sample_freq = adc->sample_freq;
389 unsigned int spi_freq; 388 unsigned int spi_freq;
390 int ret; 389 int ret;
@@ -419,18 +418,20 @@ static ssize_t dfsdm_adc_audio_set_spiclk(struct iio_dev *indio_dev,
419 return len; 418 return len;
420} 419}
421 420
422static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc, bool dma) 421static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc,
422 const struct iio_chan_spec *chan,
423 bool dma)
423{ 424{
424 struct regmap *regmap = adc->dfsdm->regmap; 425 struct regmap *regmap = adc->dfsdm->regmap;
425 int ret; 426 int ret;
426 unsigned int dma_en = 0, cont_en = 0; 427 unsigned int dma_en = 0, cont_en = 0;
427 428
428 ret = stm32_dfsdm_start_channel(adc->dfsdm, adc->ch_id); 429 ret = stm32_dfsdm_start_channel(adc->dfsdm, chan->channel);
429 if (ret < 0) 430 if (ret < 0)
430 return ret; 431 return ret;
431 432
432 ret = stm32_dfsdm_filter_configure(adc->dfsdm, adc->fl_id, 433 ret = stm32_dfsdm_filter_configure(adc->dfsdm, adc->fl_id,
433 adc->ch_id); 434 chan->channel);
434 if (ret < 0) 435 if (ret < 0)
435 goto stop_channels; 436 goto stop_channels;
436 437
@@ -464,12 +465,13 @@ stop_channels:
464 465
465 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), 466 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
466 DFSDM_CR1_RCONT_MASK, 0); 467 DFSDM_CR1_RCONT_MASK, 0);
467 stm32_dfsdm_stop_channel(adc->dfsdm, adc->fl_id); 468 stm32_dfsdm_stop_channel(adc->dfsdm, chan->channel);
468 469
469 return ret; 470 return ret;
470} 471}
471 472
472static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc) 473static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc,
474 const struct iio_chan_spec *chan)
473{ 475{
474 struct regmap *regmap = adc->dfsdm->regmap; 476 struct regmap *regmap = adc->dfsdm->regmap;
475 477
@@ -482,7 +484,7 @@ static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc)
482 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), 484 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
483 DFSDM_CR1_RCONT_MASK, 0); 485 DFSDM_CR1_RCONT_MASK, 0);
484 486
485 stm32_dfsdm_stop_channel(adc->dfsdm, adc->ch_id); 487 stm32_dfsdm_stop_channel(adc->dfsdm, chan->channel);
486} 488}
487 489
488static int stm32_dfsdm_set_watermark(struct iio_dev *indio_dev, 490static int stm32_dfsdm_set_watermark(struct iio_dev *indio_dev,
@@ -609,6 +611,7 @@ static int stm32_dfsdm_adc_dma_start(struct iio_dev *indio_dev)
609static int stm32_dfsdm_postenable(struct iio_dev *indio_dev) 611static int stm32_dfsdm_postenable(struct iio_dev *indio_dev)
610{ 612{
611 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); 613 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
614 const struct iio_chan_spec *chan = &indio_dev->channels[0];
612 int ret; 615 int ret;
613 616
614 /* Reset adc buffer index */ 617 /* Reset adc buffer index */
@@ -618,7 +621,7 @@ static int stm32_dfsdm_postenable(struct iio_dev *indio_dev)
618 if (ret < 0) 621 if (ret < 0)
619 return ret; 622 return ret;
620 623
621 ret = stm32_dfsdm_start_conv(adc, true); 624 ret = stm32_dfsdm_start_conv(adc, chan, true);
622 if (ret) { 625 if (ret) {
623 dev_err(&indio_dev->dev, "Can't start conversion\n"); 626 dev_err(&indio_dev->dev, "Can't start conversion\n");
624 goto stop_dfsdm; 627 goto stop_dfsdm;
@@ -635,7 +638,7 @@ static int stm32_dfsdm_postenable(struct iio_dev *indio_dev)
635 return 0; 638 return 0;
636 639
637err_stop_conv: 640err_stop_conv:
638 stm32_dfsdm_stop_conv(adc); 641 stm32_dfsdm_stop_conv(adc, chan);
639stop_dfsdm: 642stop_dfsdm:
640 stm32_dfsdm_stop_dfsdm(adc->dfsdm); 643 stm32_dfsdm_stop_dfsdm(adc->dfsdm);
641 644
@@ -645,11 +648,12 @@ stop_dfsdm:
645static int stm32_dfsdm_predisable(struct iio_dev *indio_dev) 648static int stm32_dfsdm_predisable(struct iio_dev *indio_dev)
646{ 649{
647 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); 650 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
651 const struct iio_chan_spec *chan = &indio_dev->channels[0];
648 652
649 if (adc->dma_chan) 653 if (adc->dma_chan)
650 dmaengine_terminate_all(adc->dma_chan); 654 dmaengine_terminate_all(adc->dma_chan);
651 655
652 stm32_dfsdm_stop_conv(adc); 656 stm32_dfsdm_stop_conv(adc, chan);
653 657
654 stm32_dfsdm_stop_dfsdm(adc->dfsdm); 658 stm32_dfsdm_stop_dfsdm(adc->dfsdm);
655 659
@@ -730,7 +734,7 @@ static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev,
730 if (ret < 0) 734 if (ret < 0)
731 goto stop_dfsdm; 735 goto stop_dfsdm;
732 736
733 ret = stm32_dfsdm_start_conv(adc, false); 737 ret = stm32_dfsdm_start_conv(adc, chan, false);
734 if (ret < 0) { 738 if (ret < 0) {
735 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id), 739 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id),
736 DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(0)); 740 DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(0));
@@ -751,7 +755,7 @@ static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev,
751 else 755 else
752 ret = IIO_VAL_INT; 756 ret = IIO_VAL_INT;
753 757
754 stm32_dfsdm_stop_conv(adc); 758 stm32_dfsdm_stop_conv(adc, chan);
755 759
756stop_dfsdm: 760stop_dfsdm:
757 stm32_dfsdm_stop_dfsdm(adc->dfsdm); 761 stm32_dfsdm_stop_dfsdm(adc->dfsdm);
@@ -765,7 +769,7 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
765{ 769{
766 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); 770 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
767 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id]; 771 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
768 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[adc->ch_id]; 772 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel];
769 unsigned int spi_freq = adc->spi_freq; 773 unsigned int spi_freq = adc->spi_freq;
770 int ret = -EINVAL; 774 int ret = -EINVAL;
771 775
@@ -972,7 +976,6 @@ static int stm32_dfsdm_adc_chan_init_one(struct iio_dev *indio_dev,
972 } 976 }
973 ch->scan_type.realbits = 24; 977 ch->scan_type.realbits = 24;
974 ch->scan_type.storagebits = 32; 978 ch->scan_type.storagebits = 32;
975 adc->ch_id = ch->channel;
976 979
977 return stm32_dfsdm_chan_configure(adc->dfsdm, 980 return stm32_dfsdm_chan_configure(adc->dfsdm,
978 &adc->dfsdm->ch_list[ch->channel]); 981 &adc->dfsdm->ch_list[ch->channel]);
@@ -1001,7 +1004,7 @@ static int stm32_dfsdm_audio_init(struct iio_dev *indio_dev)
1001 } 1004 }
1002 ch->info_mask_separate = BIT(IIO_CHAN_INFO_SAMP_FREQ); 1005 ch->info_mask_separate = BIT(IIO_CHAN_INFO_SAMP_FREQ);
1003 1006
1004 d_ch = &adc->dfsdm->ch_list[adc->ch_id]; 1007 d_ch = &adc->dfsdm->ch_list[ch->channel];
1005 if (d_ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL) 1008 if (d_ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL)
1006 adc->spi_freq = adc->dfsdm->spi_master_freq; 1009 adc->spi_freq = adc->dfsdm->spi_master_freq;
1007 1010
@@ -1042,8 +1045,8 @@ static int stm32_dfsdm_adc_init(struct iio_dev *indio_dev)
1042 return -ENOMEM; 1045 return -ENOMEM;
1043 1046
1044 for (chan_idx = 0; chan_idx < num_ch; chan_idx++) { 1047 for (chan_idx = 0; chan_idx < num_ch; chan_idx++) {
1045 ch->scan_index = chan_idx; 1048 ch[chan_idx].scan_index = chan_idx;
1046 ret = stm32_dfsdm_adc_chan_init_one(indio_dev, ch); 1049 ret = stm32_dfsdm_adc_chan_init_one(indio_dev, &ch[chan_idx]);
1047 if (ret < 0) { 1050 if (ret < 0) {
1048 dev_err(&indio_dev->dev, "Channels init failed\n"); 1051 dev_err(&indio_dev->dev, "Channels init failed\n");
1049 return ret; 1052 return ret;
diff --git a/drivers/iio/adc/stm32-dfsdm-core.c b/drivers/iio/adc/stm32-dfsdm-core.c
index 6290332cfd3f..e50efdcc41ff 100644
--- a/drivers/iio/adc/stm32-dfsdm-core.c
+++ b/drivers/iio/adc/stm32-dfsdm-core.c
@@ -83,7 +83,7 @@ int stm32_dfsdm_start_dfsdm(struct stm32_dfsdm *dfsdm)
83{ 83{
84 struct dfsdm_priv *priv = container_of(dfsdm, struct dfsdm_priv, dfsdm); 84 struct dfsdm_priv *priv = container_of(dfsdm, struct dfsdm_priv, dfsdm);
85 struct device *dev = &priv->pdev->dev; 85 struct device *dev = &priv->pdev->dev;
86 unsigned int clk_div = priv->spi_clk_out_div; 86 unsigned int clk_div = priv->spi_clk_out_div, clk_src;
87 int ret; 87 int ret;
88 88
89 if (atomic_inc_return(&priv->n_active_ch) == 1) { 89 if (atomic_inc_return(&priv->n_active_ch) == 1) {
@@ -100,6 +100,14 @@ int stm32_dfsdm_start_dfsdm(struct stm32_dfsdm *dfsdm)
100 } 100 }
101 } 101 }
102 102
103 /* select clock source, e.g. 0 for "dfsdm" or 1 for "audio" */
104 clk_src = priv->aclk ? 1 : 0;
105 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0),
106 DFSDM_CHCFGR1_CKOUTSRC_MASK,
107 DFSDM_CHCFGR1_CKOUTSRC(clk_src));
108 if (ret < 0)
109 goto disable_aclk;
110
103 /* Output the SPI CLKOUT (if clk_div == 0 clock if OFF) */ 111 /* Output the SPI CLKOUT (if clk_div == 0 clock if OFF) */
104 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), 112 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0),
105 DFSDM_CHCFGR1_CKOUTDIV_MASK, 113 DFSDM_CHCFGR1_CKOUTDIV_MASK,
@@ -274,7 +282,7 @@ static int stm32_dfsdm_probe(struct platform_device *pdev)
274 282
275 dfsdm->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "dfsdm", 283 dfsdm->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "dfsdm",
276 dfsdm->base, 284 dfsdm->base,
277 &stm32h7_dfsdm_regmap_cfg); 285 dev_data->regmap_cfg);
278 if (IS_ERR(dfsdm->regmap)) { 286 if (IS_ERR(dfsdm->regmap)) {
279 ret = PTR_ERR(dfsdm->regmap); 287 ret = PTR_ERR(dfsdm->regmap);
280 dev_err(&pdev->dev, "%s: Failed to allocate regmap: %d\n", 288 dev_err(&pdev->dev, "%s: Failed to allocate regmap: %d\n",
diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
index fbe2431f5b81..1ea9f5513b02 100644
--- a/drivers/iio/chemical/ccs811.c
+++ b/drivers/iio/chemical/ccs811.c
@@ -133,6 +133,9 @@ static int ccs811_start_sensor_application(struct i2c_client *client)
133 if (ret < 0) 133 if (ret < 0)
134 return ret; 134 return ret;
135 135
136 if ((ret & CCS811_STATUS_FW_MODE_APPLICATION))
137 return 0;
138
136 if ((ret & CCS811_STATUS_APP_VALID_MASK) != 139 if ((ret & CCS811_STATUS_APP_VALID_MASK) !=
137 CCS811_STATUS_APP_VALID_LOADED) 140 CCS811_STATUS_APP_VALID_LOADED)
138 return -EIO; 141 return -EIO;
diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c
index 0dd5a381be64..457372f36791 100644
--- a/drivers/iio/imu/adis_trigger.c
+++ b/drivers/iio/imu/adis_trigger.c
@@ -46,6 +46,10 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
46 if (adis->trig == NULL) 46 if (adis->trig == NULL)
47 return -ENOMEM; 47 return -ENOMEM;
48 48
49 adis->trig->dev.parent = &adis->spi->dev;
50 adis->trig->ops = &adis_trigger_ops;
51 iio_trigger_set_drvdata(adis->trig, adis);
52
49 ret = request_irq(adis->spi->irq, 53 ret = request_irq(adis->spi->irq,
50 &iio_trigger_generic_data_rdy_poll, 54 &iio_trigger_generic_data_rdy_poll,
51 IRQF_TRIGGER_RISING, 55 IRQF_TRIGGER_RISING,
@@ -54,9 +58,6 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
54 if (ret) 58 if (ret)
55 goto error_free_trig; 59 goto error_free_trig;
56 60
57 adis->trig->dev.parent = &adis->spi->dev;
58 adis->trig->ops = &adis_trigger_ops;
59 iio_trigger_set_drvdata(adis->trig, adis);
60 ret = iio_trigger_register(adis->trig); 61 ret = iio_trigger_register(adis->trig);
61 62
62 indio_dev->trig = iio_trigger_get(adis->trig); 63 indio_dev->trig = iio_trigger_get(adis->trig);
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 79abf70a126d..cd5bfe39591b 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -175,7 +175,7 @@ __poll_t iio_buffer_poll(struct file *filp,
175 struct iio_dev *indio_dev = filp->private_data; 175 struct iio_dev *indio_dev = filp->private_data;
176 struct iio_buffer *rb = indio_dev->buffer; 176 struct iio_buffer *rb = indio_dev->buffer;
177 177
178 if (!indio_dev->info) 178 if (!indio_dev->info || rb == NULL)
179 return 0; 179 return 0;
180 180
181 poll_wait(filp, &rb->pollq, wait); 181 poll_wait(filp, &rb->pollq, wait);
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 349e5c713c03..4ddb6cf7d401 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -640,7 +640,7 @@ int st_press_common_probe(struct iio_dev *indio_dev)
640 press_data->sensor_settings->drdy_irq.int2.addr)) 640 press_data->sensor_settings->drdy_irq.int2.addr))
641 pdata = (struct st_sensors_platform_data *)&default_press_pdata; 641 pdata = (struct st_sensors_platform_data *)&default_press_pdata;
642 642
643 err = st_sensors_init_sensor(indio_dev, press_data->dev->platform_data); 643 err = st_sensors_init_sensor(indio_dev, pdata);
644 if (err < 0) 644 if (err < 0)
645 goto st_press_power_off; 645 goto st_press_power_off;
646 646
diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index fcb1c4ba5e41..f726f9427602 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -68,6 +68,8 @@ config SX9500
68 68
69config SRF08 69config SRF08
70 tristate "Devantech SRF02/SRF08/SRF10 ultrasonic ranger sensor" 70 tristate "Devantech SRF02/SRF08/SRF10 ultrasonic ranger sensor"
71 select IIO_BUFFER
72 select IIO_TRIGGERED_BUFFER
71 depends on I2C 73 depends on I2C
72 help 74 help
73 Say Y here to build a driver for Devantech SRF02/SRF08/SRF10 75 Say Y here to build a driver for Devantech SRF02/SRF08/SRF10
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index a5b4cf030c11..9183d148d644 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -550,18 +550,13 @@ static int addr_resolve(struct sockaddr *src_in,
550 dst_release(dst); 550 dst_release(dst);
551 } 551 }
552 552
553 if (ndev->flags & IFF_LOOPBACK) { 553 if (ndev) {
554 ret = rdma_translate_ip(dst_in, addr); 554 if (ndev->flags & IFF_LOOPBACK)
555 /* 555 ret = rdma_translate_ip(dst_in, addr);
556 * Put the loopback device and get the translated 556 else
557 * device instead. 557 addr->bound_dev_if = ndev->ifindex;
558 */
559 dev_put(ndev); 558 dev_put(ndev);
560 ndev = dev_get_by_index(addr->net, addr->bound_dev_if);
561 } else {
562 addr->bound_dev_if = ndev->ifindex;
563 } 559 }
564 dev_put(ndev);
565 560
566 return ret; 561 return ret;
567} 562}
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index e66963ca58bd..a5367c5efbe7 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -3069,7 +3069,8 @@ static int cma_port_is_unique(struct rdma_bind_list *bind_list,
3069 continue; 3069 continue;
3070 3070
3071 /* different dest port -> unique */ 3071 /* different dest port -> unique */
3072 if (!cma_any_port(cur_daddr) && 3072 if (!cma_any_port(daddr) &&
3073 !cma_any_port(cur_daddr) &&
3073 (dport != cur_dport)) 3074 (dport != cur_dport))
3074 continue; 3075 continue;
3075 3076
@@ -3080,7 +3081,8 @@ static int cma_port_is_unique(struct rdma_bind_list *bind_list,
3080 continue; 3081 continue;
3081 3082
3082 /* different dst address -> unique */ 3083 /* different dst address -> unique */
3083 if (!cma_any_addr(cur_daddr) && 3084 if (!cma_any_addr(daddr) &&
3085 !cma_any_addr(cur_daddr) &&
3084 cma_addr_cmp(daddr, cur_daddr)) 3086 cma_addr_cmp(daddr, cur_daddr))
3085 continue; 3087 continue;
3086 3088
@@ -3378,13 +3380,13 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr)
3378 } 3380 }
3379#endif 3381#endif
3380 } 3382 }
3383 daddr = cma_dst_addr(id_priv);
3384 daddr->sa_family = addr->sa_family;
3385
3381 ret = cma_get_port(id_priv); 3386 ret = cma_get_port(id_priv);
3382 if (ret) 3387 if (ret)
3383 goto err2; 3388 goto err2;
3384 3389
3385 daddr = cma_dst_addr(id_priv);
3386 daddr->sa_family = addr->sa_family;
3387
3388 return 0; 3390 return 0;
3389err2: 3391err2:
3390 if (id_priv->cma_dev) 3392 if (id_priv->cma_dev)
@@ -4173,6 +4175,9 @@ int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
4173 struct cma_multicast *mc; 4175 struct cma_multicast *mc;
4174 int ret; 4176 int ret;
4175 4177
4178 if (!id->device)
4179 return -EINVAL;
4180
4176 id_priv = container_of(id, struct rdma_id_private, id); 4181 id_priv = container_of(id, struct rdma_id_private, id);
4177 if (!cma_comp(id_priv, RDMA_CM_ADDR_BOUND) && 4182 if (!cma_comp(id_priv, RDMA_CM_ADDR_BOUND) &&
4178 !cma_comp(id_priv, RDMA_CM_ADDR_RESOLVED)) 4183 !cma_comp(id_priv, RDMA_CM_ADDR_RESOLVED))
diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h
index c4560d84dfae..25bb178f6074 100644
--- a/drivers/infiniband/core/core_priv.h
+++ b/drivers/infiniband/core/core_priv.h
@@ -305,16 +305,21 @@ void nldev_exit(void);
305static inline struct ib_qp *_ib_create_qp(struct ib_device *dev, 305static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
306 struct ib_pd *pd, 306 struct ib_pd *pd,
307 struct ib_qp_init_attr *attr, 307 struct ib_qp_init_attr *attr,
308 struct ib_udata *udata) 308 struct ib_udata *udata,
309 struct ib_uobject *uobj)
309{ 310{
310 struct ib_qp *qp; 311 struct ib_qp *qp;
311 312
313 if (!dev->create_qp)
314 return ERR_PTR(-EOPNOTSUPP);
315
312 qp = dev->create_qp(pd, attr, udata); 316 qp = dev->create_qp(pd, attr, udata);
313 if (IS_ERR(qp)) 317 if (IS_ERR(qp))
314 return qp; 318 return qp;
315 319
316 qp->device = dev; 320 qp->device = dev;
317 qp->pd = pd; 321 qp->pd = pd;
322 qp->uobject = uobj;
318 /* 323 /*
319 * We don't track XRC QPs for now, because they don't have PD 324 * We don't track XRC QPs for now, because they don't have PD
320 * and more importantly they are created internaly by driver, 325 * and more importantly they are created internaly by driver,
diff --git a/drivers/infiniband/core/cq.c b/drivers/infiniband/core/cq.c
index bc79ca8215d7..af5ad6a56ae4 100644
--- a/drivers/infiniband/core/cq.c
+++ b/drivers/infiniband/core/cq.c
@@ -17,6 +17,7 @@
17 17
18/* # of WCs to poll for with a single call to ib_poll_cq */ 18/* # of WCs to poll for with a single call to ib_poll_cq */
19#define IB_POLL_BATCH 16 19#define IB_POLL_BATCH 16
20#define IB_POLL_BATCH_DIRECT 8
20 21
21/* # of WCs to iterate over before yielding */ 22/* # of WCs to iterate over before yielding */
22#define IB_POLL_BUDGET_IRQ 256 23#define IB_POLL_BUDGET_IRQ 256
@@ -25,18 +26,18 @@
25#define IB_POLL_FLAGS \ 26#define IB_POLL_FLAGS \
26 (IB_CQ_NEXT_COMP | IB_CQ_REPORT_MISSED_EVENTS) 27 (IB_CQ_NEXT_COMP | IB_CQ_REPORT_MISSED_EVENTS)
27 28
28static int __ib_process_cq(struct ib_cq *cq, int budget, struct ib_wc *poll_wc) 29static int __ib_process_cq(struct ib_cq *cq, int budget, struct ib_wc *wcs,
30 int batch)
29{ 31{
30 int i, n, completed = 0; 32 int i, n, completed = 0;
31 struct ib_wc *wcs = poll_wc ? : cq->wc;
32 33
33 /* 34 /*
34 * budget might be (-1) if the caller does not 35 * budget might be (-1) if the caller does not
35 * want to bound this call, thus we need unsigned 36 * want to bound this call, thus we need unsigned
36 * minimum here. 37 * minimum here.
37 */ 38 */
38 while ((n = ib_poll_cq(cq, min_t(u32, IB_POLL_BATCH, 39 while ((n = ib_poll_cq(cq, min_t(u32, batch,
39 budget - completed), wcs)) > 0) { 40 budget - completed), wcs)) > 0) {
40 for (i = 0; i < n; i++) { 41 for (i = 0; i < n; i++) {
41 struct ib_wc *wc = &wcs[i]; 42 struct ib_wc *wc = &wcs[i];
42 43
@@ -48,8 +49,7 @@ static int __ib_process_cq(struct ib_cq *cq, int budget, struct ib_wc *poll_wc)
48 49
49 completed += n; 50 completed += n;
50 51
51 if (n != IB_POLL_BATCH || 52 if (n != batch || (budget != -1 && completed >= budget))
52 (budget != -1 && completed >= budget))
53 break; 53 break;
54 } 54 }
55 55
@@ -72,9 +72,9 @@ static int __ib_process_cq(struct ib_cq *cq, int budget, struct ib_wc *poll_wc)
72 */ 72 */
73int ib_process_cq_direct(struct ib_cq *cq, int budget) 73int ib_process_cq_direct(struct ib_cq *cq, int budget)
74{ 74{
75 struct ib_wc wcs[IB_POLL_BATCH]; 75 struct ib_wc wcs[IB_POLL_BATCH_DIRECT];
76 76
77 return __ib_process_cq(cq, budget, wcs); 77 return __ib_process_cq(cq, budget, wcs, IB_POLL_BATCH_DIRECT);
78} 78}
79EXPORT_SYMBOL(ib_process_cq_direct); 79EXPORT_SYMBOL(ib_process_cq_direct);
80 80
@@ -88,7 +88,7 @@ static int ib_poll_handler(struct irq_poll *iop, int budget)
88 struct ib_cq *cq = container_of(iop, struct ib_cq, iop); 88 struct ib_cq *cq = container_of(iop, struct ib_cq, iop);
89 int completed; 89 int completed;
90 90
91 completed = __ib_process_cq(cq, budget, NULL); 91 completed = __ib_process_cq(cq, budget, cq->wc, IB_POLL_BATCH);
92 if (completed < budget) { 92 if (completed < budget) {
93 irq_poll_complete(&cq->iop); 93 irq_poll_complete(&cq->iop);
94 if (ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) 94 if (ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0)
@@ -108,7 +108,8 @@ static void ib_cq_poll_work(struct work_struct *work)
108 struct ib_cq *cq = container_of(work, struct ib_cq, work); 108 struct ib_cq *cq = container_of(work, struct ib_cq, work);
109 int completed; 109 int completed;
110 110
111 completed = __ib_process_cq(cq, IB_POLL_BUDGET_WORKQUEUE, NULL); 111 completed = __ib_process_cq(cq, IB_POLL_BUDGET_WORKQUEUE, cq->wc,
112 IB_POLL_BATCH);
112 if (completed >= IB_POLL_BUDGET_WORKQUEUE || 113 if (completed >= IB_POLL_BUDGET_WORKQUEUE ||
113 ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) 114 ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0)
114 queue_work(ib_comp_wq, &cq->work); 115 queue_work(ib_comp_wq, &cq->work);
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index e8010e73a1cf..bb065c9449be 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -536,14 +536,14 @@ int ib_register_device(struct ib_device *device,
536 ret = device->query_device(device, &device->attrs, &uhw); 536 ret = device->query_device(device, &device->attrs, &uhw);
537 if (ret) { 537 if (ret) {
538 pr_warn("Couldn't query the device attributes\n"); 538 pr_warn("Couldn't query the device attributes\n");
539 goto cache_cleanup; 539 goto cg_cleanup;
540 } 540 }
541 541
542 ret = ib_device_register_sysfs(device, port_callback); 542 ret = ib_device_register_sysfs(device, port_callback);
543 if (ret) { 543 if (ret) {
544 pr_warn("Couldn't register device %s with driver model\n", 544 pr_warn("Couldn't register device %s with driver model\n",
545 device->name); 545 device->name);
546 goto cache_cleanup; 546 goto cg_cleanup;
547 } 547 }
548 548
549 device->reg_state = IB_DEV_REGISTERED; 549 device->reg_state = IB_DEV_REGISTERED;
@@ -559,6 +559,8 @@ int ib_register_device(struct ib_device *device,
559 mutex_unlock(&device_mutex); 559 mutex_unlock(&device_mutex);
560 return 0; 560 return 0;
561 561
562cg_cleanup:
563 ib_device_unregister_rdmacg(device);
562cache_cleanup: 564cache_cleanup:
563 ib_cache_cleanup_one(device); 565 ib_cache_cleanup_one(device);
564 ib_cache_release_one(device); 566 ib_cache_release_one(device);
diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c
index 85b5ee4defa4..d8eead5d106d 100644
--- a/drivers/infiniband/core/rdma_core.c
+++ b/drivers/infiniband/core/rdma_core.c
@@ -141,7 +141,12 @@ static struct ib_uobject *alloc_uobj(struct ib_ucontext *context,
141 */ 141 */
142 uobj->context = context; 142 uobj->context = context;
143 uobj->type = type; 143 uobj->type = type;
144 atomic_set(&uobj->usecnt, 0); 144 /*
145 * Allocated objects start out as write locked to deny any other
146 * syscalls from accessing them until they are committed. See
147 * rdma_alloc_commit_uobject
148 */
149 atomic_set(&uobj->usecnt, -1);
145 kref_init(&uobj->ref); 150 kref_init(&uobj->ref);
146 151
147 return uobj; 152 return uobj;
@@ -196,7 +201,15 @@ static struct ib_uobject *lookup_get_idr_uobject(const struct uverbs_obj_type *t
196 goto free; 201 goto free;
197 } 202 }
198 203
199 uverbs_uobject_get(uobj); 204 /*
205 * The idr_find is guaranteed to return a pointer to something that
206 * isn't freed yet, or NULL, as the free after idr_remove goes through
207 * kfree_rcu(). However the object may still have been released and
208 * kfree() could be called at any time.
209 */
210 if (!kref_get_unless_zero(&uobj->ref))
211 uobj = ERR_PTR(-ENOENT);
212
200free: 213free:
201 rcu_read_unlock(); 214 rcu_read_unlock();
202 return uobj; 215 return uobj;
@@ -399,13 +412,13 @@ static int __must_check remove_commit_fd_uobject(struct ib_uobject *uobj,
399 return ret; 412 return ret;
400} 413}
401 414
402static void lockdep_check(struct ib_uobject *uobj, bool exclusive) 415static void assert_uverbs_usecnt(struct ib_uobject *uobj, bool exclusive)
403{ 416{
404#ifdef CONFIG_LOCKDEP 417#ifdef CONFIG_LOCKDEP
405 if (exclusive) 418 if (exclusive)
406 WARN_ON(atomic_read(&uobj->usecnt) > 0); 419 WARN_ON(atomic_read(&uobj->usecnt) != -1);
407 else 420 else
408 WARN_ON(atomic_read(&uobj->usecnt) == -1); 421 WARN_ON(atomic_read(&uobj->usecnt) <= 0);
409#endif 422#endif
410} 423}
411 424
@@ -444,7 +457,7 @@ int __must_check rdma_remove_commit_uobject(struct ib_uobject *uobj)
444 WARN(true, "ib_uverbs: Cleanup is running while removing an uobject\n"); 457 WARN(true, "ib_uverbs: Cleanup is running while removing an uobject\n");
445 return 0; 458 return 0;
446 } 459 }
447 lockdep_check(uobj, true); 460 assert_uverbs_usecnt(uobj, true);
448 ret = _rdma_remove_commit_uobject(uobj, RDMA_REMOVE_DESTROY); 461 ret = _rdma_remove_commit_uobject(uobj, RDMA_REMOVE_DESTROY);
449 462
450 up_read(&ucontext->cleanup_rwsem); 463 up_read(&ucontext->cleanup_rwsem);
@@ -474,16 +487,17 @@ int rdma_explicit_destroy(struct ib_uobject *uobject)
474 WARN(true, "ib_uverbs: Cleanup is running while removing an uobject\n"); 487 WARN(true, "ib_uverbs: Cleanup is running while removing an uobject\n");
475 return 0; 488 return 0;
476 } 489 }
477 lockdep_check(uobject, true); 490 assert_uverbs_usecnt(uobject, true);
478 ret = uobject->type->type_class->remove_commit(uobject, 491 ret = uobject->type->type_class->remove_commit(uobject,
479 RDMA_REMOVE_DESTROY); 492 RDMA_REMOVE_DESTROY);
480 if (ret) 493 if (ret)
481 return ret; 494 goto out;
482 495
483 uobject->type = &null_obj_type; 496 uobject->type = &null_obj_type;
484 497
498out:
485 up_read(&ucontext->cleanup_rwsem); 499 up_read(&ucontext->cleanup_rwsem);
486 return 0; 500 return ret;
487} 501}
488 502
489static void alloc_commit_idr_uobject(struct ib_uobject *uobj) 503static void alloc_commit_idr_uobject(struct ib_uobject *uobj)
@@ -527,6 +541,10 @@ int rdma_alloc_commit_uobject(struct ib_uobject *uobj)
527 return ret; 541 return ret;
528 } 542 }
529 543
544 /* matches atomic_set(-1) in alloc_uobj */
545 assert_uverbs_usecnt(uobj, true);
546 atomic_set(&uobj->usecnt, 0);
547
530 uobj->type->type_class->alloc_commit(uobj); 548 uobj->type->type_class->alloc_commit(uobj);
531 up_read(&uobj->context->cleanup_rwsem); 549 up_read(&uobj->context->cleanup_rwsem);
532 550
@@ -561,7 +579,7 @@ static void lookup_put_fd_uobject(struct ib_uobject *uobj, bool exclusive)
561 579
562void rdma_lookup_put_uobject(struct ib_uobject *uobj, bool exclusive) 580void rdma_lookup_put_uobject(struct ib_uobject *uobj, bool exclusive)
563{ 581{
564 lockdep_check(uobj, exclusive); 582 assert_uverbs_usecnt(uobj, exclusive);
565 uobj->type->type_class->lookup_put(uobj, exclusive); 583 uobj->type->type_class->lookup_put(uobj, exclusive);
566 /* 584 /*
567 * In order to unlock an object, either decrease its usecnt for 585 * In order to unlock an object, either decrease its usecnt for
diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c
index 857637bf46da..3dbc4e4cca41 100644
--- a/drivers/infiniband/core/restrack.c
+++ b/drivers/infiniband/core/restrack.c
@@ -7,7 +7,6 @@
7#include <rdma/restrack.h> 7#include <rdma/restrack.h>
8#include <linux/mutex.h> 8#include <linux/mutex.h>
9#include <linux/sched/task.h> 9#include <linux/sched/task.h>
10#include <linux/uaccess.h>
11#include <linux/pid_namespace.h> 10#include <linux/pid_namespace.h>
12 11
13void rdma_restrack_init(struct rdma_restrack_root *res) 12void rdma_restrack_init(struct rdma_restrack_root *res)
@@ -63,7 +62,6 @@ static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
63{ 62{
64 enum rdma_restrack_type type = res->type; 63 enum rdma_restrack_type type = res->type;
65 struct ib_device *dev; 64 struct ib_device *dev;
66 struct ib_xrcd *xrcd;
67 struct ib_pd *pd; 65 struct ib_pd *pd;
68 struct ib_cq *cq; 66 struct ib_cq *cq;
69 struct ib_qp *qp; 67 struct ib_qp *qp;
@@ -81,10 +79,6 @@ static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
81 qp = container_of(res, struct ib_qp, res); 79 qp = container_of(res, struct ib_qp, res);
82 dev = qp->device; 80 dev = qp->device;
83 break; 81 break;
84 case RDMA_RESTRACK_XRCD:
85 xrcd = container_of(res, struct ib_xrcd, res);
86 dev = xrcd->device;
87 break;
88 default: 82 default:
89 WARN_ONCE(true, "Wrong resource tracking type %u\n", type); 83 WARN_ONCE(true, "Wrong resource tracking type %u\n", type);
90 return NULL; 84 return NULL;
@@ -93,6 +87,21 @@ static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
93 return dev; 87 return dev;
94} 88}
95 89
90static bool res_is_user(struct rdma_restrack_entry *res)
91{
92 switch (res->type) {
93 case RDMA_RESTRACK_PD:
94 return container_of(res, struct ib_pd, res)->uobject;
95 case RDMA_RESTRACK_CQ:
96 return container_of(res, struct ib_cq, res)->uobject;
97 case RDMA_RESTRACK_QP:
98 return container_of(res, struct ib_qp, res)->uobject;
99 default:
100 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type);
101 return false;
102 }
103}
104
96void rdma_restrack_add(struct rdma_restrack_entry *res) 105void rdma_restrack_add(struct rdma_restrack_entry *res)
97{ 106{
98 struct ib_device *dev = res_to_dev(res); 107 struct ib_device *dev = res_to_dev(res);
@@ -100,7 +109,7 @@ void rdma_restrack_add(struct rdma_restrack_entry *res)
100 if (!dev) 109 if (!dev)
101 return; 110 return;
102 111
103 if (!uaccess_kernel()) { 112 if (res_is_user(res)) {
104 get_task_struct(current); 113 get_task_struct(current);
105 res->task = current; 114 res->task = current;
106 res->kern_name = NULL; 115 res->kern_name = NULL;
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 8cf15d4a8ac4..9f029a1ca5ea 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -1291,10 +1291,9 @@ int ib_init_ah_attr_from_path(struct ib_device *device, u8 port_num,
1291 1291
1292 resolved_dev = dev_get_by_index(dev_addr.net, 1292 resolved_dev = dev_get_by_index(dev_addr.net,
1293 dev_addr.bound_dev_if); 1293 dev_addr.bound_dev_if);
1294 if (resolved_dev->flags & IFF_LOOPBACK) { 1294 if (!resolved_dev) {
1295 dev_put(resolved_dev); 1295 dev_put(idev);
1296 resolved_dev = idev; 1296 return -ENODEV;
1297 dev_hold(resolved_dev);
1298 } 1297 }
1299 ndev = ib_get_ndev_from_path(rec); 1298 ndev = ib_get_ndev_from_path(rec);
1300 rcu_read_lock(); 1299 rcu_read_lock();
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index f015f1bf88c9..e5a1e7d81326 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -132,7 +132,7 @@ static inline struct ucma_context *_ucma_find_context(int id,
132 ctx = idr_find(&ctx_idr, id); 132 ctx = idr_find(&ctx_idr, id);
133 if (!ctx) 133 if (!ctx)
134 ctx = ERR_PTR(-ENOENT); 134 ctx = ERR_PTR(-ENOENT);
135 else if (ctx->file != file) 135 else if (ctx->file != file || !ctx->cm_id)
136 ctx = ERR_PTR(-EINVAL); 136 ctx = ERR_PTR(-EINVAL);
137 return ctx; 137 return ctx;
138} 138}
@@ -456,6 +456,7 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
456 struct rdma_ucm_create_id cmd; 456 struct rdma_ucm_create_id cmd;
457 struct rdma_ucm_create_id_resp resp; 457 struct rdma_ucm_create_id_resp resp;
458 struct ucma_context *ctx; 458 struct ucma_context *ctx;
459 struct rdma_cm_id *cm_id;
459 enum ib_qp_type qp_type; 460 enum ib_qp_type qp_type;
460 int ret; 461 int ret;
461 462
@@ -476,10 +477,10 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
476 return -ENOMEM; 477 return -ENOMEM;
477 478
478 ctx->uid = cmd.uid; 479 ctx->uid = cmd.uid;
479 ctx->cm_id = rdma_create_id(current->nsproxy->net_ns, 480 cm_id = rdma_create_id(current->nsproxy->net_ns,
480 ucma_event_handler, ctx, cmd.ps, qp_type); 481 ucma_event_handler, ctx, cmd.ps, qp_type);
481 if (IS_ERR(ctx->cm_id)) { 482 if (IS_ERR(cm_id)) {
482 ret = PTR_ERR(ctx->cm_id); 483 ret = PTR_ERR(cm_id);
483 goto err1; 484 goto err1;
484 } 485 }
485 486
@@ -489,14 +490,19 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
489 ret = -EFAULT; 490 ret = -EFAULT;
490 goto err2; 491 goto err2;
491 } 492 }
493
494 ctx->cm_id = cm_id;
492 return 0; 495 return 0;
493 496
494err2: 497err2:
495 rdma_destroy_id(ctx->cm_id); 498 rdma_destroy_id(cm_id);
496err1: 499err1:
497 mutex_lock(&mut); 500 mutex_lock(&mut);
498 idr_remove(&ctx_idr, ctx->id); 501 idr_remove(&ctx_idr, ctx->id);
499 mutex_unlock(&mut); 502 mutex_unlock(&mut);
503 mutex_lock(&file->mut);
504 list_del(&ctx->list);
505 mutex_unlock(&file->mut);
500 kfree(ctx); 506 kfree(ctx);
501 return ret; 507 return ret;
502} 508}
@@ -664,19 +670,23 @@ static ssize_t ucma_resolve_ip(struct ucma_file *file,
664 int in_len, int out_len) 670 int in_len, int out_len)
665{ 671{
666 struct rdma_ucm_resolve_ip cmd; 672 struct rdma_ucm_resolve_ip cmd;
673 struct sockaddr *src, *dst;
667 struct ucma_context *ctx; 674 struct ucma_context *ctx;
668 int ret; 675 int ret;
669 676
670 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 677 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
671 return -EFAULT; 678 return -EFAULT;
672 679
680 src = (struct sockaddr *) &cmd.src_addr;
681 dst = (struct sockaddr *) &cmd.dst_addr;
682 if (!rdma_addr_size(src) || !rdma_addr_size(dst))
683 return -EINVAL;
684
673 ctx = ucma_get_ctx(file, cmd.id); 685 ctx = ucma_get_ctx(file, cmd.id);
674 if (IS_ERR(ctx)) 686 if (IS_ERR(ctx))
675 return PTR_ERR(ctx); 687 return PTR_ERR(ctx);
676 688
677 ret = rdma_resolve_addr(ctx->cm_id, (struct sockaddr *) &cmd.src_addr, 689 ret = rdma_resolve_addr(ctx->cm_id, src, dst, cmd.timeout_ms);
678 (struct sockaddr *) &cmd.dst_addr,
679 cmd.timeout_ms);
680 ucma_put_ctx(ctx); 690 ucma_put_ctx(ctx);
681 return ret; 691 return ret;
682} 692}
@@ -1149,6 +1159,9 @@ static ssize_t ucma_init_qp_attr(struct ucma_file *file,
1149 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 1159 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1150 return -EFAULT; 1160 return -EFAULT;
1151 1161
1162 if (cmd.qp_state > IB_QPS_ERR)
1163 return -EINVAL;
1164
1152 ctx = ucma_get_ctx(file, cmd.id); 1165 ctx = ucma_get_ctx(file, cmd.id);
1153 if (IS_ERR(ctx)) 1166 if (IS_ERR(ctx))
1154 return PTR_ERR(ctx); 1167 return PTR_ERR(ctx);
@@ -1294,6 +1307,9 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf,
1294 if (IS_ERR(ctx)) 1307 if (IS_ERR(ctx))
1295 return PTR_ERR(ctx); 1308 return PTR_ERR(ctx);
1296 1309
1310 if (unlikely(cmd.optval > KMALLOC_MAX_SIZE))
1311 return -EINVAL;
1312
1297 optval = memdup_user((void __user *) (unsigned long) cmd.optval, 1313 optval = memdup_user((void __user *) (unsigned long) cmd.optval,
1298 cmd.optlen); 1314 cmd.optlen);
1299 if (IS_ERR(optval)) { 1315 if (IS_ERR(optval)) {
@@ -1343,7 +1359,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
1343 return -ENOSPC; 1359 return -ENOSPC;
1344 1360
1345 addr = (struct sockaddr *) &cmd->addr; 1361 addr = (struct sockaddr *) &cmd->addr;
1346 if (!cmd->addr_size || (cmd->addr_size != rdma_addr_size(addr))) 1362 if (cmd->addr_size != rdma_addr_size(addr))
1347 return -EINVAL; 1363 return -EINVAL;
1348 1364
1349 if (cmd->join_flags == RDMA_MC_JOIN_FLAG_FULLMEMBER) 1365 if (cmd->join_flags == RDMA_MC_JOIN_FLAG_FULLMEMBER)
@@ -1411,6 +1427,9 @@ static ssize_t ucma_join_ip_multicast(struct ucma_file *file,
1411 join_cmd.uid = cmd.uid; 1427 join_cmd.uid = cmd.uid;
1412 join_cmd.id = cmd.id; 1428 join_cmd.id = cmd.id;
1413 join_cmd.addr_size = rdma_addr_size((struct sockaddr *) &cmd.addr); 1429 join_cmd.addr_size = rdma_addr_size((struct sockaddr *) &cmd.addr);
1430 if (!join_cmd.addr_size)
1431 return -EINVAL;
1432
1414 join_cmd.join_flags = RDMA_MC_JOIN_FLAG_FULLMEMBER; 1433 join_cmd.join_flags = RDMA_MC_JOIN_FLAG_FULLMEMBER;
1415 memcpy(&join_cmd.addr, &cmd.addr, join_cmd.addr_size); 1434 memcpy(&join_cmd.addr, &cmd.addr, join_cmd.addr_size);
1416 1435
@@ -1426,6 +1445,9 @@ static ssize_t ucma_join_multicast(struct ucma_file *file,
1426 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 1445 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1427 return -EFAULT; 1446 return -EFAULT;
1428 1447
1448 if (!rdma_addr_size((struct sockaddr *)&cmd.addr))
1449 return -EINVAL;
1450
1429 return ucma_process_join(file, &cmd, out_len); 1451 return ucma_process_join(file, &cmd, out_len);
1430} 1452}
1431 1453
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 256934d1f64f..a148de35df8d 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -562,9 +562,10 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
562 if (f.file) 562 if (f.file)
563 fdput(f); 563 fdput(f);
564 564
565 mutex_unlock(&file->device->xrcd_tree_mutex);
566
565 uobj_alloc_commit(&obj->uobject); 567 uobj_alloc_commit(&obj->uobject);
566 568
567 mutex_unlock(&file->device->xrcd_tree_mutex);
568 return in_len; 569 return in_len;
569 570
570err_copy: 571err_copy:
@@ -603,10 +604,8 @@ ssize_t ib_uverbs_close_xrcd(struct ib_uverbs_file *file,
603 604
604 uobj = uobj_get_write(uobj_get_type(xrcd), cmd.xrcd_handle, 605 uobj = uobj_get_write(uobj_get_type(xrcd), cmd.xrcd_handle,
605 file->ucontext); 606 file->ucontext);
606 if (IS_ERR(uobj)) { 607 if (IS_ERR(uobj))
607 mutex_unlock(&file->device->xrcd_tree_mutex);
608 return PTR_ERR(uobj); 608 return PTR_ERR(uobj);
609 }
610 609
611 ret = uobj_remove_commit(uobj); 610 ret = uobj_remove_commit(uobj);
612 return ret ?: in_len; 611 return ret ?: in_len;
@@ -979,6 +978,9 @@ static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file,
979 struct ib_uverbs_ex_create_cq_resp resp; 978 struct ib_uverbs_ex_create_cq_resp resp;
980 struct ib_cq_init_attr attr = {}; 979 struct ib_cq_init_attr attr = {};
981 980
981 if (!ib_dev->create_cq)
982 return ERR_PTR(-EOPNOTSUPP);
983
982 if (cmd->comp_vector >= file->device->num_comp_vectors) 984 if (cmd->comp_vector >= file->device->num_comp_vectors)
983 return ERR_PTR(-EINVAL); 985 return ERR_PTR(-EINVAL);
984 986
@@ -1030,14 +1032,14 @@ static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file,
1030 resp.response_length = offsetof(typeof(resp), response_length) + 1032 resp.response_length = offsetof(typeof(resp), response_length) +
1031 sizeof(resp.response_length); 1033 sizeof(resp.response_length);
1032 1034
1035 cq->res.type = RDMA_RESTRACK_CQ;
1036 rdma_restrack_add(&cq->res);
1037
1033 ret = cb(file, obj, &resp, ucore, context); 1038 ret = cb(file, obj, &resp, ucore, context);
1034 if (ret) 1039 if (ret)
1035 goto err_cb; 1040 goto err_cb;
1036 1041
1037 uobj_alloc_commit(&obj->uobject); 1042 uobj_alloc_commit(&obj->uobject);
1038 cq->res.type = RDMA_RESTRACK_CQ;
1039 rdma_restrack_add(&cq->res);
1040
1041 return obj; 1043 return obj;
1042 1044
1043err_cb: 1045err_cb:
@@ -1518,7 +1520,8 @@ static int create_qp(struct ib_uverbs_file *file,
1518 if (cmd->qp_type == IB_QPT_XRC_TGT) 1520 if (cmd->qp_type == IB_QPT_XRC_TGT)
1519 qp = ib_create_qp(pd, &attr); 1521 qp = ib_create_qp(pd, &attr);
1520 else 1522 else
1521 qp = _ib_create_qp(device, pd, &attr, uhw); 1523 qp = _ib_create_qp(device, pd, &attr, uhw,
1524 &obj->uevent.uobject);
1522 1525
1523 if (IS_ERR(qp)) { 1526 if (IS_ERR(qp)) {
1524 ret = PTR_ERR(qp); 1527 ret = PTR_ERR(qp);
@@ -1550,8 +1553,10 @@ static int create_qp(struct ib_uverbs_file *file,
1550 atomic_inc(&attr.srq->usecnt); 1553 atomic_inc(&attr.srq->usecnt);
1551 if (ind_tbl) 1554 if (ind_tbl)
1552 atomic_inc(&ind_tbl->usecnt); 1555 atomic_inc(&ind_tbl->usecnt);
1556 } else {
1557 /* It is done in _ib_create_qp for other QP types */
1558 qp->uobject = &obj->uevent.uobject;
1553 } 1559 }
1554 qp->uobject = &obj->uevent.uobject;
1555 1560
1556 obj->uevent.uobject.object = qp; 1561 obj->uevent.uobject.object = qp;
1557 1562
@@ -1971,8 +1976,15 @@ static int modify_qp(struct ib_uverbs_file *file,
1971 goto release_qp; 1976 goto release_qp;
1972 } 1977 }
1973 1978
1979 if ((cmd->base.attr_mask & IB_QP_AV) &&
1980 !rdma_is_port_valid(qp->device, cmd->base.dest.port_num)) {
1981 ret = -EINVAL;
1982 goto release_qp;
1983 }
1984
1974 if ((cmd->base.attr_mask & IB_QP_ALT_PATH) && 1985 if ((cmd->base.attr_mask & IB_QP_ALT_PATH) &&
1975 !rdma_is_port_valid(qp->device, cmd->base.alt_port_num)) { 1986 (!rdma_is_port_valid(qp->device, cmd->base.alt_port_num) ||
1987 !rdma_is_port_valid(qp->device, cmd->base.alt_dest.port_num))) {
1976 ret = -EINVAL; 1988 ret = -EINVAL;
1977 goto release_qp; 1989 goto release_qp;
1978 } 1990 }
@@ -2941,6 +2953,11 @@ int ib_uverbs_ex_create_wq(struct ib_uverbs_file *file,
2941 wq_init_attr.create_flags = cmd.create_flags; 2953 wq_init_attr.create_flags = cmd.create_flags;
2942 obj->uevent.events_reported = 0; 2954 obj->uevent.events_reported = 0;
2943 INIT_LIST_HEAD(&obj->uevent.event_list); 2955 INIT_LIST_HEAD(&obj->uevent.event_list);
2956
2957 if (!pd->device->create_wq) {
2958 err = -EOPNOTSUPP;
2959 goto err_put_cq;
2960 }
2944 wq = pd->device->create_wq(pd, &wq_init_attr, uhw); 2961 wq = pd->device->create_wq(pd, &wq_init_attr, uhw);
2945 if (IS_ERR(wq)) { 2962 if (IS_ERR(wq)) {
2946 err = PTR_ERR(wq); 2963 err = PTR_ERR(wq);
@@ -3084,7 +3101,12 @@ int ib_uverbs_ex_modify_wq(struct ib_uverbs_file *file,
3084 wq_attr.flags = cmd.flags; 3101 wq_attr.flags = cmd.flags;
3085 wq_attr.flags_mask = cmd.flags_mask; 3102 wq_attr.flags_mask = cmd.flags_mask;
3086 } 3103 }
3104 if (!wq->device->modify_wq) {
3105 ret = -EOPNOTSUPP;
3106 goto out;
3107 }
3087 ret = wq->device->modify_wq(wq, &wq_attr, cmd.attr_mask, uhw); 3108 ret = wq->device->modify_wq(wq, &wq_attr, cmd.attr_mask, uhw);
3109out:
3088 uobj_put_obj_read(wq); 3110 uobj_put_obj_read(wq);
3089 return ret; 3111 return ret;
3090} 3112}
@@ -3181,6 +3203,11 @@ int ib_uverbs_ex_create_rwq_ind_table(struct ib_uverbs_file *file,
3181 3203
3182 init_attr.log_ind_tbl_size = cmd.log_ind_tbl_size; 3204 init_attr.log_ind_tbl_size = cmd.log_ind_tbl_size;
3183 init_attr.ind_tbl = wqs; 3205 init_attr.ind_tbl = wqs;
3206
3207 if (!ib_dev->create_rwq_ind_table) {
3208 err = -EOPNOTSUPP;
3209 goto err_uobj;
3210 }
3184 rwq_ind_tbl = ib_dev->create_rwq_ind_table(ib_dev, &init_attr, uhw); 3211 rwq_ind_tbl = ib_dev->create_rwq_ind_table(ib_dev, &init_attr, uhw);
3185 3212
3186 if (IS_ERR(rwq_ind_tbl)) { 3213 if (IS_ERR(rwq_ind_tbl)) {
@@ -3770,6 +3797,9 @@ int ib_uverbs_ex_query_device(struct ib_uverbs_file *file,
3770 struct ib_device_attr attr = {0}; 3797 struct ib_device_attr attr = {0};
3771 int err; 3798 int err;
3772 3799
3800 if (!ib_dev->query_device)
3801 return -EOPNOTSUPP;
3802
3773 if (ucore->inlen < sizeof(cmd)) 3803 if (ucore->inlen < sizeof(cmd))
3774 return -EINVAL; 3804 return -EINVAL;
3775 3805
diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c
index d96dc1d17be1..339b85145044 100644
--- a/drivers/infiniband/core/uverbs_ioctl.c
+++ b/drivers/infiniband/core/uverbs_ioctl.c
@@ -59,6 +59,9 @@ static int uverbs_process_attr(struct ib_device *ibdev,
59 return 0; 59 return 0;
60 } 60 }
61 61
62 if (test_bit(attr_id, attr_bundle_h->valid_bitmap))
63 return -EINVAL;
64
62 spec = &attr_spec_bucket->attrs[attr_id]; 65 spec = &attr_spec_bucket->attrs[attr_id];
63 e = &elements[attr_id]; 66 e = &elements[attr_id];
64 e->uattr = uattr_ptr; 67 e->uattr = uattr_ptr;
diff --git a/drivers/infiniband/core/uverbs_ioctl_merge.c b/drivers/infiniband/core/uverbs_ioctl_merge.c
index 062485f9300d..62e1eb1d2a28 100644
--- a/drivers/infiniband/core/uverbs_ioctl_merge.c
+++ b/drivers/infiniband/core/uverbs_ioctl_merge.c
@@ -114,6 +114,7 @@ static size_t get_elements_above_id(const void **iters,
114 short min = SHRT_MAX; 114 short min = SHRT_MAX;
115 const void *elem; 115 const void *elem;
116 int i, j, last_stored = -1; 116 int i, j, last_stored = -1;
117 unsigned int equal_min = 0;
117 118
118 for_each_element(elem, i, j, elements, num_elements, num_offset, 119 for_each_element(elem, i, j, elements, num_elements, num_offset,
119 data_offset) { 120 data_offset) {
@@ -136,6 +137,10 @@ static size_t get_elements_above_id(const void **iters,
136 */ 137 */
137 iters[last_stored == i ? num_iters - 1 : num_iters++] = elem; 138 iters[last_stored == i ? num_iters - 1 : num_iters++] = elem;
138 last_stored = i; 139 last_stored = i;
140 if (min == GET_ID(id))
141 equal_min++;
142 else
143 equal_min = 1;
139 min = GET_ID(id); 144 min = GET_ID(id);
140 } 145 }
141 146
@@ -146,15 +151,10 @@ static size_t get_elements_above_id(const void **iters,
146 * Therefore, we need to clean the beginning of the array to make sure 151 * Therefore, we need to clean the beginning of the array to make sure
147 * all ids of final elements are equal to min. 152 * all ids of final elements are equal to min.
148 */ 153 */
149 for (i = num_iters - 1; i >= 0 && 154 memmove(iters, iters + num_iters - equal_min, sizeof(*iters) * equal_min);
150 GET_ID(*(u16 *)(iters[i] + id_offset)) == min; i--)
151 ;
152
153 num_iters -= i + 1;
154 memmove(iters, iters + i + 1, sizeof(*iters) * num_iters);
155 155
156 *min_id = min; 156 *min_id = min;
157 return num_iters; 157 return equal_min;
158} 158}
159 159
160#define find_max_element_entry_id(num_elements, elements, num_objects_fld, \ 160#define find_max_element_entry_id(num_elements, elements, num_objects_fld, \
@@ -322,7 +322,7 @@ static struct uverbs_method_spec *build_method_with_attrs(const struct uverbs_me
322 hash = kzalloc(sizeof(*hash) + 322 hash = kzalloc(sizeof(*hash) +
323 ALIGN(sizeof(*hash->attrs) * (attr_max_bucket + 1), 323 ALIGN(sizeof(*hash->attrs) * (attr_max_bucket + 1),
324 sizeof(long)) + 324 sizeof(long)) +
325 BITS_TO_LONGS(attr_max_bucket) * sizeof(long), 325 BITS_TO_LONGS(attr_max_bucket + 1) * sizeof(long),
326 GFP_KERNEL); 326 GFP_KERNEL);
327 if (!hash) { 327 if (!hash) {
328 res = -ENOMEM; 328 res = -ENOMEM;
@@ -509,7 +509,7 @@ static struct uverbs_object_spec *build_object_with_methods(const struct uverbs_
509 * first handler which != NULL. This also defines the 509 * first handler which != NULL. This also defines the
510 * set of flags used for this handler. 510 * set of flags used for this handler.
511 */ 511 */
512 for (i = num_object_defs - 1; 512 for (i = num_method_defs - 1;
513 i >= 0 && !method_defs[i]->handler; i--) 513 i >= 0 && !method_defs[i]->handler; i--)
514 ; 514 ;
515 hash->methods[min_id++] = method; 515 hash->methods[min_id++] = method;
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 395a3b091229..b1ca223aa380 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -650,12 +650,21 @@ static int verify_command_mask(struct ib_device *ib_dev, __u32 command)
650 return -1; 650 return -1;
651} 651}
652 652
653static bool verify_command_idx(u32 command, bool extended)
654{
655 if (extended)
656 return command < ARRAY_SIZE(uverbs_ex_cmd_table);
657
658 return command < ARRAY_SIZE(uverbs_cmd_table);
659}
660
653static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, 661static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
654 size_t count, loff_t *pos) 662 size_t count, loff_t *pos)
655{ 663{
656 struct ib_uverbs_file *file = filp->private_data; 664 struct ib_uverbs_file *file = filp->private_data;
657 struct ib_device *ib_dev; 665 struct ib_device *ib_dev;
658 struct ib_uverbs_cmd_hdr hdr; 666 struct ib_uverbs_cmd_hdr hdr;
667 bool extended_command;
659 __u32 command; 668 __u32 command;
660 __u32 flags; 669 __u32 flags;
661 int srcu_key; 670 int srcu_key;
@@ -688,6 +697,15 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
688 } 697 }
689 698
690 command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK; 699 command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK;
700 flags = (hdr.command &
701 IB_USER_VERBS_CMD_FLAGS_MASK) >> IB_USER_VERBS_CMD_FLAGS_SHIFT;
702
703 extended_command = flags & IB_USER_VERBS_CMD_FLAG_EXTENDED;
704 if (!verify_command_idx(command, extended_command)) {
705 ret = -EINVAL;
706 goto out;
707 }
708
691 if (verify_command_mask(ib_dev, command)) { 709 if (verify_command_mask(ib_dev, command)) {
692 ret = -EOPNOTSUPP; 710 ret = -EOPNOTSUPP;
693 goto out; 711 goto out;
@@ -699,12 +717,8 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
699 goto out; 717 goto out;
700 } 718 }
701 719
702 flags = (hdr.command &
703 IB_USER_VERBS_CMD_FLAGS_MASK) >> IB_USER_VERBS_CMD_FLAGS_SHIFT;
704
705 if (!flags) { 720 if (!flags) {
706 if (command >= ARRAY_SIZE(uverbs_cmd_table) || 721 if (!uverbs_cmd_table[command]) {
707 !uverbs_cmd_table[command]) {
708 ret = -EINVAL; 722 ret = -EINVAL;
709 goto out; 723 goto out;
710 } 724 }
@@ -725,8 +739,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
725 struct ib_udata uhw; 739 struct ib_udata uhw;
726 size_t written_count = count; 740 size_t written_count = count;
727 741
728 if (command >= ARRAY_SIZE(uverbs_ex_cmd_table) || 742 if (!uverbs_ex_cmd_table[command]) {
729 !uverbs_ex_cmd_table[command]) {
730 ret = -ENOSYS; 743 ret = -ENOSYS;
731 goto out; 744 goto out;
732 } 745 }
@@ -942,6 +955,7 @@ static const struct file_operations uverbs_fops = {
942 .llseek = no_llseek, 955 .llseek = no_llseek,
943#if IS_ENABLED(CONFIG_INFINIBAND_EXP_USER_ACCESS) 956#if IS_ENABLED(CONFIG_INFINIBAND_EXP_USER_ACCESS)
944 .unlocked_ioctl = ib_uverbs_ioctl, 957 .unlocked_ioctl = ib_uverbs_ioctl,
958 .compat_ioctl = ib_uverbs_ioctl,
945#endif 959#endif
946}; 960};
947 961
@@ -954,6 +968,7 @@ static const struct file_operations uverbs_mmap_fops = {
954 .llseek = no_llseek, 968 .llseek = no_llseek,
955#if IS_ENABLED(CONFIG_INFINIBAND_EXP_USER_ACCESS) 969#if IS_ENABLED(CONFIG_INFINIBAND_EXP_USER_ACCESS)
956 .unlocked_ioctl = ib_uverbs_ioctl, 970 .unlocked_ioctl = ib_uverbs_ioctl,
971 .compat_ioctl = ib_uverbs_ioctl,
957#endif 972#endif
958}; 973};
959 974
diff --git a/drivers/infiniband/core/uverbs_std_types.c b/drivers/infiniband/core/uverbs_std_types.c
index cab0ac3556eb..df1360e6774f 100644
--- a/drivers/infiniband/core/uverbs_std_types.c
+++ b/drivers/infiniband/core/uverbs_std_types.c
@@ -234,15 +234,18 @@ static void create_udata(struct uverbs_attr_bundle *ctx,
234 uverbs_attr_get(ctx, UVERBS_UHW_OUT); 234 uverbs_attr_get(ctx, UVERBS_UHW_OUT);
235 235
236 if (!IS_ERR(uhw_in)) { 236 if (!IS_ERR(uhw_in)) {
237 udata->inbuf = uhw_in->ptr_attr.ptr;
238 udata->inlen = uhw_in->ptr_attr.len; 237 udata->inlen = uhw_in->ptr_attr.len;
238 if (uverbs_attr_ptr_is_inline(uhw_in))
239 udata->inbuf = &uhw_in->uattr->data;
240 else
241 udata->inbuf = u64_to_user_ptr(uhw_in->ptr_attr.data);
239 } else { 242 } else {
240 udata->inbuf = NULL; 243 udata->inbuf = NULL;
241 udata->inlen = 0; 244 udata->inlen = 0;
242 } 245 }
243 246
244 if (!IS_ERR(uhw_out)) { 247 if (!IS_ERR(uhw_out)) {
245 udata->outbuf = uhw_out->ptr_attr.ptr; 248 udata->outbuf = u64_to_user_ptr(uhw_out->ptr_attr.data);
246 udata->outlen = uhw_out->ptr_attr.len; 249 udata->outlen = uhw_out->ptr_attr.len;
247 } else { 250 } else {
248 udata->outbuf = NULL; 251 udata->outbuf = NULL;
@@ -323,7 +326,8 @@ static int uverbs_create_cq_handler(struct ib_device *ib_dev,
323 cq->res.type = RDMA_RESTRACK_CQ; 326 cq->res.type = RDMA_RESTRACK_CQ;
324 rdma_restrack_add(&cq->res); 327 rdma_restrack_add(&cq->res);
325 328
326 ret = uverbs_copy_to(attrs, CREATE_CQ_RESP_CQE, &cq->cqe); 329 ret = uverbs_copy_to(attrs, CREATE_CQ_RESP_CQE, &cq->cqe,
330 sizeof(cq->cqe));
327 if (ret) 331 if (ret)
328 goto err_cq; 332 goto err_cq;
329 333
@@ -375,7 +379,7 @@ static int uverbs_destroy_cq_handler(struct ib_device *ib_dev,
375 resp.comp_events_reported = obj->comp_events_reported; 379 resp.comp_events_reported = obj->comp_events_reported;
376 resp.async_events_reported = obj->async_events_reported; 380 resp.async_events_reported = obj->async_events_reported;
377 381
378 return uverbs_copy_to(attrs, DESTROY_CQ_RESP, &resp); 382 return uverbs_copy_to(attrs, DESTROY_CQ_RESP, &resp, sizeof(resp));
379} 383}
380 384
381static DECLARE_UVERBS_METHOD( 385static DECLARE_UVERBS_METHOD(
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 16ebc6372c31..93025d2009b8 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -887,7 +887,7 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
887 if (qp_init_attr->cap.max_rdma_ctxs) 887 if (qp_init_attr->cap.max_rdma_ctxs)
888 rdma_rw_init_qp(device, qp_init_attr); 888 rdma_rw_init_qp(device, qp_init_attr);
889 889
890 qp = _ib_create_qp(device, pd, qp_init_attr, NULL); 890 qp = _ib_create_qp(device, pd, qp_init_attr, NULL, NULL);
891 if (IS_ERR(qp)) 891 if (IS_ERR(qp))
892 return qp; 892 return qp;
893 893
@@ -898,7 +898,6 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
898 } 898 }
899 899
900 qp->real_qp = qp; 900 qp->real_qp = qp;
901 qp->uobject = NULL;
902 qp->qp_type = qp_init_attr->qp_type; 901 qp->qp_type = qp_init_attr->qp_type;
903 qp->rwq_ind_tbl = qp_init_attr->rwq_ind_tbl; 902 qp->rwq_ind_tbl = qp_init_attr->rwq_ind_tbl;
904 903
diff --git a/drivers/infiniband/hw/bnxt_re/bnxt_re.h b/drivers/infiniband/hw/bnxt_re/bnxt_re.h
index ca32057e886f..96f76896488d 100644
--- a/drivers/infiniband/hw/bnxt_re/bnxt_re.h
+++ b/drivers/infiniband/hw/bnxt_re/bnxt_re.h
@@ -57,8 +57,8 @@
57#define BNXT_RE_PAGE_SIZE_8M BIT(BNXT_RE_PAGE_SHIFT_8M) 57#define BNXT_RE_PAGE_SIZE_8M BIT(BNXT_RE_PAGE_SHIFT_8M)
58#define BNXT_RE_PAGE_SIZE_1G BIT(BNXT_RE_PAGE_SHIFT_1G) 58#define BNXT_RE_PAGE_SIZE_1G BIT(BNXT_RE_PAGE_SHIFT_1G)
59 59
60#define BNXT_RE_MAX_MR_SIZE_LOW BIT(BNXT_RE_PAGE_SHIFT_1G) 60#define BNXT_RE_MAX_MR_SIZE_LOW BIT_ULL(BNXT_RE_PAGE_SHIFT_1G)
61#define BNXT_RE_MAX_MR_SIZE_HIGH BIT(39) 61#define BNXT_RE_MAX_MR_SIZE_HIGH BIT_ULL(39)
62#define BNXT_RE_MAX_MR_SIZE BNXT_RE_MAX_MR_SIZE_HIGH 62#define BNXT_RE_MAX_MR_SIZE BNXT_RE_MAX_MR_SIZE_HIGH
63 63
64#define BNXT_RE_MAX_QPC_COUNT (64 * 1024) 64#define BNXT_RE_MAX_QPC_COUNT (64 * 1024)
@@ -120,7 +120,6 @@ struct bnxt_re_dev {
120#define BNXT_RE_FLAG_HAVE_L2_REF 3 120#define BNXT_RE_FLAG_HAVE_L2_REF 3
121#define BNXT_RE_FLAG_RCFW_CHANNEL_EN 4 121#define BNXT_RE_FLAG_RCFW_CHANNEL_EN 4
122#define BNXT_RE_FLAG_QOS_WORK_REG 5 122#define BNXT_RE_FLAG_QOS_WORK_REG 5
123#define BNXT_RE_FLAG_TASK_IN_PROG 6
124#define BNXT_RE_FLAG_ISSUE_ROCE_STATS 29 123#define BNXT_RE_FLAG_ISSUE_ROCE_STATS 29
125 struct net_device *netdev; 124 struct net_device *netdev;
126 unsigned int version, major, minor; 125 unsigned int version, major, minor;
@@ -158,6 +157,7 @@ struct bnxt_re_dev {
158 atomic_t srq_count; 157 atomic_t srq_count;
159 atomic_t mr_count; 158 atomic_t mr_count;
160 atomic_t mw_count; 159 atomic_t mw_count;
160 atomic_t sched_count;
161 /* Max of 2 lossless traffic class supported per port */ 161 /* Max of 2 lossless traffic class supported per port */
162 u16 cosq[2]; 162 u16 cosq[2];
163 163
diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.c b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
index ae9e9ff54826..8301d7e5fa8c 100644
--- a/drivers/infiniband/hw/bnxt_re/ib_verbs.c
+++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
@@ -174,10 +174,8 @@ int bnxt_re_query_device(struct ib_device *ibdev,
174 ib_attr->max_pd = dev_attr->max_pd; 174 ib_attr->max_pd = dev_attr->max_pd;
175 ib_attr->max_qp_rd_atom = dev_attr->max_qp_rd_atom; 175 ib_attr->max_qp_rd_atom = dev_attr->max_qp_rd_atom;
176 ib_attr->max_qp_init_rd_atom = dev_attr->max_qp_init_rd_atom; 176 ib_attr->max_qp_init_rd_atom = dev_attr->max_qp_init_rd_atom;
177 if (dev_attr->is_atomic) { 177 ib_attr->atomic_cap = IB_ATOMIC_NONE;
178 ib_attr->atomic_cap = IB_ATOMIC_HCA; 178 ib_attr->masked_atomic_cap = IB_ATOMIC_NONE;
179 ib_attr->masked_atomic_cap = IB_ATOMIC_HCA;
180 }
181 179
182 ib_attr->max_ee_rd_atom = 0; 180 ib_attr->max_ee_rd_atom = 0;
183 ib_attr->max_res_rd_atom = 0; 181 ib_attr->max_res_rd_atom = 0;
@@ -787,20 +785,51 @@ int bnxt_re_query_ah(struct ib_ah *ib_ah, struct rdma_ah_attr *ah_attr)
787 return 0; 785 return 0;
788} 786}
789 787
788unsigned long bnxt_re_lock_cqs(struct bnxt_re_qp *qp)
789 __acquires(&qp->scq->cq_lock) __acquires(&qp->rcq->cq_lock)
790{
791 unsigned long flags;
792
793 spin_lock_irqsave(&qp->scq->cq_lock, flags);
794 if (qp->rcq != qp->scq)
795 spin_lock(&qp->rcq->cq_lock);
796 else
797 __acquire(&qp->rcq->cq_lock);
798
799 return flags;
800}
801
802void bnxt_re_unlock_cqs(struct bnxt_re_qp *qp,
803 unsigned long flags)
804 __releases(&qp->scq->cq_lock) __releases(&qp->rcq->cq_lock)
805{
806 if (qp->rcq != qp->scq)
807 spin_unlock(&qp->rcq->cq_lock);
808 else
809 __release(&qp->rcq->cq_lock);
810 spin_unlock_irqrestore(&qp->scq->cq_lock, flags);
811}
812
790/* Queue Pairs */ 813/* Queue Pairs */
791int bnxt_re_destroy_qp(struct ib_qp *ib_qp) 814int bnxt_re_destroy_qp(struct ib_qp *ib_qp)
792{ 815{
793 struct bnxt_re_qp *qp = container_of(ib_qp, struct bnxt_re_qp, ib_qp); 816 struct bnxt_re_qp *qp = container_of(ib_qp, struct bnxt_re_qp, ib_qp);
794 struct bnxt_re_dev *rdev = qp->rdev; 817 struct bnxt_re_dev *rdev = qp->rdev;
795 int rc; 818 int rc;
819 unsigned int flags;
796 820
797 bnxt_qplib_flush_cqn_wq(&qp->qplib_qp); 821 bnxt_qplib_flush_cqn_wq(&qp->qplib_qp);
798 bnxt_qplib_del_flush_qp(&qp->qplib_qp);
799 rc = bnxt_qplib_destroy_qp(&rdev->qplib_res, &qp->qplib_qp); 822 rc = bnxt_qplib_destroy_qp(&rdev->qplib_res, &qp->qplib_qp);
800 if (rc) { 823 if (rc) {
801 dev_err(rdev_to_dev(rdev), "Failed to destroy HW QP"); 824 dev_err(rdev_to_dev(rdev), "Failed to destroy HW QP");
802 return rc; 825 return rc;
803 } 826 }
827
828 flags = bnxt_re_lock_cqs(qp);
829 bnxt_qplib_clean_qp(&qp->qplib_qp);
830 bnxt_re_unlock_cqs(qp, flags);
831 bnxt_qplib_free_qp_res(&rdev->qplib_res, &qp->qplib_qp);
832
804 if (ib_qp->qp_type == IB_QPT_GSI && rdev->qp1_sqp) { 833 if (ib_qp->qp_type == IB_QPT_GSI && rdev->qp1_sqp) {
805 rc = bnxt_qplib_destroy_ah(&rdev->qplib_res, 834 rc = bnxt_qplib_destroy_ah(&rdev->qplib_res,
806 &rdev->sqp_ah->qplib_ah); 835 &rdev->sqp_ah->qplib_ah);
@@ -810,7 +839,7 @@ int bnxt_re_destroy_qp(struct ib_qp *ib_qp)
810 return rc; 839 return rc;
811 } 840 }
812 841
813 bnxt_qplib_del_flush_qp(&qp->qplib_qp); 842 bnxt_qplib_clean_qp(&qp->qplib_qp);
814 rc = bnxt_qplib_destroy_qp(&rdev->qplib_res, 843 rc = bnxt_qplib_destroy_qp(&rdev->qplib_res,
815 &rdev->qp1_sqp->qplib_qp); 844 &rdev->qp1_sqp->qplib_qp);
816 if (rc) { 845 if (rc) {
@@ -1069,6 +1098,7 @@ struct ib_qp *bnxt_re_create_qp(struct ib_pd *ib_pd,
1069 goto fail; 1098 goto fail;
1070 } 1099 }
1071 qp->qplib_qp.scq = &cq->qplib_cq; 1100 qp->qplib_qp.scq = &cq->qplib_cq;
1101 qp->scq = cq;
1072 } 1102 }
1073 1103
1074 if (qp_init_attr->recv_cq) { 1104 if (qp_init_attr->recv_cq) {
@@ -1080,6 +1110,7 @@ struct ib_qp *bnxt_re_create_qp(struct ib_pd *ib_pd,
1080 goto fail; 1110 goto fail;
1081 } 1111 }
1082 qp->qplib_qp.rcq = &cq->qplib_cq; 1112 qp->qplib_qp.rcq = &cq->qplib_cq;
1113 qp->rcq = cq;
1083 } 1114 }
1084 1115
1085 if (qp_init_attr->srq) { 1116 if (qp_init_attr->srq) {
@@ -1185,7 +1216,7 @@ struct ib_qp *bnxt_re_create_qp(struct ib_pd *ib_pd,
1185 rc = bnxt_qplib_create_qp(&rdev->qplib_res, &qp->qplib_qp); 1216 rc = bnxt_qplib_create_qp(&rdev->qplib_res, &qp->qplib_qp);
1186 if (rc) { 1217 if (rc) {
1187 dev_err(rdev_to_dev(rdev), "Failed to create HW QP"); 1218 dev_err(rdev_to_dev(rdev), "Failed to create HW QP");
1188 goto fail; 1219 goto free_umem;
1189 } 1220 }
1190 } 1221 }
1191 1222
@@ -1213,6 +1244,13 @@ struct ib_qp *bnxt_re_create_qp(struct ib_pd *ib_pd,
1213 return &qp->ib_qp; 1244 return &qp->ib_qp;
1214qp_destroy: 1245qp_destroy:
1215 bnxt_qplib_destroy_qp(&rdev->qplib_res, &qp->qplib_qp); 1246 bnxt_qplib_destroy_qp(&rdev->qplib_res, &qp->qplib_qp);
1247free_umem:
1248 if (udata) {
1249 if (qp->rumem)
1250 ib_umem_release(qp->rumem);
1251 if (qp->sumem)
1252 ib_umem_release(qp->sumem);
1253 }
1216fail: 1254fail:
1217 kfree(qp); 1255 kfree(qp);
1218 return ERR_PTR(rc); 1256 return ERR_PTR(rc);
@@ -1568,6 +1606,7 @@ int bnxt_re_modify_qp(struct ib_qp *ib_qp, struct ib_qp_attr *qp_attr,
1568 int status; 1606 int status;
1569 union ib_gid sgid; 1607 union ib_gid sgid;
1570 struct ib_gid_attr sgid_attr; 1608 struct ib_gid_attr sgid_attr;
1609 unsigned int flags;
1571 u8 nw_type; 1610 u8 nw_type;
1572 1611
1573 qp->qplib_qp.modify_flags = 0; 1612 qp->qplib_qp.modify_flags = 0;
@@ -1596,14 +1635,18 @@ int bnxt_re_modify_qp(struct ib_qp *ib_qp, struct ib_qp_attr *qp_attr,
1596 dev_dbg(rdev_to_dev(rdev), 1635 dev_dbg(rdev_to_dev(rdev),
1597 "Move QP = %p to flush list\n", 1636 "Move QP = %p to flush list\n",
1598 qp); 1637 qp);
1638 flags = bnxt_re_lock_cqs(qp);
1599 bnxt_qplib_add_flush_qp(&qp->qplib_qp); 1639 bnxt_qplib_add_flush_qp(&qp->qplib_qp);
1640 bnxt_re_unlock_cqs(qp, flags);
1600 } 1641 }
1601 if (!qp->sumem && 1642 if (!qp->sumem &&
1602 qp->qplib_qp.state == CMDQ_MODIFY_QP_NEW_STATE_RESET) { 1643 qp->qplib_qp.state == CMDQ_MODIFY_QP_NEW_STATE_RESET) {
1603 dev_dbg(rdev_to_dev(rdev), 1644 dev_dbg(rdev_to_dev(rdev),
1604 "Move QP = %p out of flush list\n", 1645 "Move QP = %p out of flush list\n",
1605 qp); 1646 qp);
1606 bnxt_qplib_del_flush_qp(&qp->qplib_qp); 1647 flags = bnxt_re_lock_cqs(qp);
1648 bnxt_qplib_clean_qp(&qp->qplib_qp);
1649 bnxt_re_unlock_cqs(qp, flags);
1607 } 1650 }
1608 } 1651 }
1609 if (qp_attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY) { 1652 if (qp_attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY) {
@@ -2189,10 +2232,13 @@ static int bnxt_re_build_inv_wqe(struct ib_send_wr *wr,
2189 wqe->type = BNXT_QPLIB_SWQE_TYPE_LOCAL_INV; 2232 wqe->type = BNXT_QPLIB_SWQE_TYPE_LOCAL_INV;
2190 wqe->local_inv.inv_l_key = wr->ex.invalidate_rkey; 2233 wqe->local_inv.inv_l_key = wr->ex.invalidate_rkey;
2191 2234
2235 /* Need unconditional fence for local invalidate
2236 * opcode to work as expected.
2237 */
2238 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE;
2239
2192 if (wr->send_flags & IB_SEND_SIGNALED) 2240 if (wr->send_flags & IB_SEND_SIGNALED)
2193 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP; 2241 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP;
2194 if (wr->send_flags & IB_SEND_FENCE)
2195 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE;
2196 if (wr->send_flags & IB_SEND_SOLICITED) 2242 if (wr->send_flags & IB_SEND_SOLICITED)
2197 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_SOLICIT_EVENT; 2243 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_SOLICIT_EVENT;
2198 2244
@@ -2213,8 +2259,12 @@ static int bnxt_re_build_reg_wqe(struct ib_reg_wr *wr,
2213 wqe->frmr.levels = qplib_frpl->hwq.level + 1; 2259 wqe->frmr.levels = qplib_frpl->hwq.level + 1;
2214 wqe->type = BNXT_QPLIB_SWQE_TYPE_REG_MR; 2260 wqe->type = BNXT_QPLIB_SWQE_TYPE_REG_MR;
2215 2261
2216 if (wr->wr.send_flags & IB_SEND_FENCE) 2262 /* Need unconditional fence for reg_mr
2217 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE; 2263 * opcode to function as expected.
2264 */
2265
2266 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE;
2267
2218 if (wr->wr.send_flags & IB_SEND_SIGNALED) 2268 if (wr->wr.send_flags & IB_SEND_SIGNALED)
2219 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP; 2269 wqe->flags |= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP;
2220 2270
@@ -3548,7 +3598,7 @@ struct ib_mr *bnxt_re_reg_user_mr(struct ib_pd *ib_pd, u64 start, u64 length,
3548 int umem_pgs, page_shift, rc; 3598 int umem_pgs, page_shift, rc;
3549 3599
3550 if (length > BNXT_RE_MAX_MR_SIZE) { 3600 if (length > BNXT_RE_MAX_MR_SIZE) {
3551 dev_err(rdev_to_dev(rdev), "MR Size: %lld > Max supported:%ld\n", 3601 dev_err(rdev_to_dev(rdev), "MR Size: %lld > Max supported:%lld\n",
3552 length, BNXT_RE_MAX_MR_SIZE); 3602 length, BNXT_RE_MAX_MR_SIZE);
3553 return ERR_PTR(-ENOMEM); 3603 return ERR_PTR(-ENOMEM);
3554 } 3604 }
diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.h b/drivers/infiniband/hw/bnxt_re/ib_verbs.h
index 423ebe012f95..e62b7c2c7da6 100644
--- a/drivers/infiniband/hw/bnxt_re/ib_verbs.h
+++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.h
@@ -89,6 +89,8 @@ struct bnxt_re_qp {
89 /* QP1 */ 89 /* QP1 */
90 u32 send_psn; 90 u32 send_psn;
91 struct ib_ud_header qp1_hdr; 91 struct ib_ud_header qp1_hdr;
92 struct bnxt_re_cq *scq;
93 struct bnxt_re_cq *rcq;
92}; 94};
93 95
94struct bnxt_re_cq { 96struct bnxt_re_cq {
@@ -220,4 +222,7 @@ struct ib_ucontext *bnxt_re_alloc_ucontext(struct ib_device *ibdev,
220 struct ib_udata *udata); 222 struct ib_udata *udata);
221int bnxt_re_dealloc_ucontext(struct ib_ucontext *context); 223int bnxt_re_dealloc_ucontext(struct ib_ucontext *context);
222int bnxt_re_mmap(struct ib_ucontext *context, struct vm_area_struct *vma); 224int bnxt_re_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
225
226unsigned long bnxt_re_lock_cqs(struct bnxt_re_qp *qp);
227void bnxt_re_unlock_cqs(struct bnxt_re_qp *qp, unsigned long flags);
223#endif /* __BNXT_RE_IB_VERBS_H__ */ 228#endif /* __BNXT_RE_IB_VERBS_H__ */
diff --git a/drivers/infiniband/hw/bnxt_re/main.c b/drivers/infiniband/hw/bnxt_re/main.c
index 508d00a5a106..f6e361750466 100644
--- a/drivers/infiniband/hw/bnxt_re/main.c
+++ b/drivers/infiniband/hw/bnxt_re/main.c
@@ -656,7 +656,6 @@ static void bnxt_re_dev_remove(struct bnxt_re_dev *rdev)
656 mutex_unlock(&bnxt_re_dev_lock); 656 mutex_unlock(&bnxt_re_dev_lock);
657 657
658 synchronize_rcu(); 658 synchronize_rcu();
659 flush_workqueue(bnxt_re_wq);
660 659
661 ib_dealloc_device(&rdev->ibdev); 660 ib_dealloc_device(&rdev->ibdev);
662 /* rdev is gone */ 661 /* rdev is gone */
@@ -731,6 +730,13 @@ static int bnxt_re_handle_qp_async_event(struct creq_qp_event *qp_event,
731 struct bnxt_re_qp *qp) 730 struct bnxt_re_qp *qp)
732{ 731{
733 struct ib_event event; 732 struct ib_event event;
733 unsigned int flags;
734
735 if (qp->qplib_qp.state == CMDQ_MODIFY_QP_NEW_STATE_ERR) {
736 flags = bnxt_re_lock_cqs(qp);
737 bnxt_qplib_add_flush_qp(&qp->qplib_qp);
738 bnxt_re_unlock_cqs(qp, flags);
739 }
734 740
735 memset(&event, 0, sizeof(event)); 741 memset(&event, 0, sizeof(event));
736 if (qp->qplib_qp.srq) { 742 if (qp->qplib_qp.srq) {
@@ -1417,9 +1423,12 @@ static void bnxt_re_task(struct work_struct *work)
1417 switch (re_work->event) { 1423 switch (re_work->event) {
1418 case NETDEV_REGISTER: 1424 case NETDEV_REGISTER:
1419 rc = bnxt_re_ib_reg(rdev); 1425 rc = bnxt_re_ib_reg(rdev);
1420 if (rc) 1426 if (rc) {
1421 dev_err(rdev_to_dev(rdev), 1427 dev_err(rdev_to_dev(rdev),
1422 "Failed to register with IB: %#x", rc); 1428 "Failed to register with IB: %#x", rc);
1429 bnxt_re_remove_one(rdev);
1430 bnxt_re_dev_unreg(rdev);
1431 }
1423 break; 1432 break;
1424 case NETDEV_UP: 1433 case NETDEV_UP:
1425 bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, 1434 bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1,
@@ -1441,7 +1450,7 @@ static void bnxt_re_task(struct work_struct *work)
1441 break; 1450 break;
1442 } 1451 }
1443 smp_mb__before_atomic(); 1452 smp_mb__before_atomic();
1444 clear_bit(BNXT_RE_FLAG_TASK_IN_PROG, &rdev->flags); 1453 atomic_dec(&rdev->sched_count);
1445 kfree(re_work); 1454 kfree(re_work);
1446} 1455}
1447 1456
@@ -1503,7 +1512,7 @@ static int bnxt_re_netdev_event(struct notifier_block *notifier,
1503 /* netdev notifier will call NETDEV_UNREGISTER again later since 1512 /* netdev notifier will call NETDEV_UNREGISTER again later since
1504 * we are still holding the reference to the netdev 1513 * we are still holding the reference to the netdev
1505 */ 1514 */
1506 if (test_bit(BNXT_RE_FLAG_TASK_IN_PROG, &rdev->flags)) 1515 if (atomic_read(&rdev->sched_count) > 0)
1507 goto exit; 1516 goto exit;
1508 bnxt_re_ib_unreg(rdev, false); 1517 bnxt_re_ib_unreg(rdev, false);
1509 bnxt_re_remove_one(rdev); 1518 bnxt_re_remove_one(rdev);
@@ -1523,7 +1532,7 @@ static int bnxt_re_netdev_event(struct notifier_block *notifier,
1523 re_work->vlan_dev = (real_dev == netdev ? 1532 re_work->vlan_dev = (real_dev == netdev ?
1524 NULL : netdev); 1533 NULL : netdev);
1525 INIT_WORK(&re_work->work, bnxt_re_task); 1534 INIT_WORK(&re_work->work, bnxt_re_task);
1526 set_bit(BNXT_RE_FLAG_TASK_IN_PROG, &rdev->flags); 1535 atomic_inc(&rdev->sched_count);
1527 queue_work(bnxt_re_wq, &re_work->work); 1536 queue_work(bnxt_re_wq, &re_work->work);
1528 } 1537 }
1529 } 1538 }
@@ -1578,6 +1587,11 @@ static void __exit bnxt_re_mod_exit(void)
1578 */ 1587 */
1579 list_for_each_entry_safe_reverse(rdev, next, &to_be_deleted, list) { 1588 list_for_each_entry_safe_reverse(rdev, next, &to_be_deleted, list) {
1580 dev_info(rdev_to_dev(rdev), "Unregistering Device"); 1589 dev_info(rdev_to_dev(rdev), "Unregistering Device");
1590 /*
1591 * Flush out any scheduled tasks before destroying the
1592 * resources
1593 */
1594 flush_workqueue(bnxt_re_wq);
1581 bnxt_re_dev_stop(rdev); 1595 bnxt_re_dev_stop(rdev);
1582 bnxt_re_ib_unreg(rdev, true); 1596 bnxt_re_ib_unreg(rdev, true);
1583 bnxt_re_remove_one(rdev); 1597 bnxt_re_remove_one(rdev);
diff --git a/drivers/infiniband/hw/bnxt_re/qplib_fp.c b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
index 1b0e94697fe3..3a78faba8d91 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_fp.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
@@ -88,75 +88,35 @@ static void __bnxt_qplib_add_flush_qp(struct bnxt_qplib_qp *qp)
88 } 88 }
89} 89}
90 90
91void bnxt_qplib_acquire_cq_locks(struct bnxt_qplib_qp *qp, 91static void bnxt_qplib_acquire_cq_flush_locks(struct bnxt_qplib_qp *qp,
92 unsigned long *flags) 92 unsigned long *flags)
93 __acquires(&qp->scq->hwq.lock) __acquires(&qp->rcq->hwq.lock) 93 __acquires(&qp->scq->flush_lock) __acquires(&qp->rcq->flush_lock)
94{ 94{
95 spin_lock_irqsave(&qp->scq->hwq.lock, *flags); 95 spin_lock_irqsave(&qp->scq->flush_lock, *flags);
96 if (qp->scq == qp->rcq) 96 if (qp->scq == qp->rcq)
97 __acquire(&qp->rcq->hwq.lock); 97 __acquire(&qp->rcq->flush_lock);
98 else 98 else
99 spin_lock(&qp->rcq->hwq.lock); 99 spin_lock(&qp->rcq->flush_lock);
100} 100}
101 101
102void bnxt_qplib_release_cq_locks(struct bnxt_qplib_qp *qp, 102static void bnxt_qplib_release_cq_flush_locks(struct bnxt_qplib_qp *qp,
103 unsigned long *flags) 103 unsigned long *flags)
104 __releases(&qp->scq->hwq.lock) __releases(&qp->rcq->hwq.lock) 104 __releases(&qp->scq->flush_lock) __releases(&qp->rcq->flush_lock)
105{ 105{
106 if (qp->scq == qp->rcq) 106 if (qp->scq == qp->rcq)
107 __release(&qp->rcq->hwq.lock); 107 __release(&qp->rcq->flush_lock);
108 else 108 else
109 spin_unlock(&qp->rcq->hwq.lock); 109 spin_unlock(&qp->rcq->flush_lock);
110 spin_unlock_irqrestore(&qp->scq->hwq.lock, *flags); 110 spin_unlock_irqrestore(&qp->scq->flush_lock, *flags);
111}
112
113static struct bnxt_qplib_cq *bnxt_qplib_find_buddy_cq(struct bnxt_qplib_qp *qp,
114 struct bnxt_qplib_cq *cq)
115{
116 struct bnxt_qplib_cq *buddy_cq = NULL;
117
118 if (qp->scq == qp->rcq)
119 buddy_cq = NULL;
120 else if (qp->scq == cq)
121 buddy_cq = qp->rcq;
122 else
123 buddy_cq = qp->scq;
124 return buddy_cq;
125}
126
127static void bnxt_qplib_lock_buddy_cq(struct bnxt_qplib_qp *qp,
128 struct bnxt_qplib_cq *cq)
129 __acquires(&buddy_cq->hwq.lock)
130{
131 struct bnxt_qplib_cq *buddy_cq = NULL;
132
133 buddy_cq = bnxt_qplib_find_buddy_cq(qp, cq);
134 if (!buddy_cq)
135 __acquire(&cq->hwq.lock);
136 else
137 spin_lock(&buddy_cq->hwq.lock);
138}
139
140static void bnxt_qplib_unlock_buddy_cq(struct bnxt_qplib_qp *qp,
141 struct bnxt_qplib_cq *cq)
142 __releases(&buddy_cq->hwq.lock)
143{
144 struct bnxt_qplib_cq *buddy_cq = NULL;
145
146 buddy_cq = bnxt_qplib_find_buddy_cq(qp, cq);
147 if (!buddy_cq)
148 __release(&cq->hwq.lock);
149 else
150 spin_unlock(&buddy_cq->hwq.lock);
151} 111}
152 112
153void bnxt_qplib_add_flush_qp(struct bnxt_qplib_qp *qp) 113void bnxt_qplib_add_flush_qp(struct bnxt_qplib_qp *qp)
154{ 114{
155 unsigned long flags; 115 unsigned long flags;
156 116
157 bnxt_qplib_acquire_cq_locks(qp, &flags); 117 bnxt_qplib_acquire_cq_flush_locks(qp, &flags);
158 __bnxt_qplib_add_flush_qp(qp); 118 __bnxt_qplib_add_flush_qp(qp);
159 bnxt_qplib_release_cq_locks(qp, &flags); 119 bnxt_qplib_release_cq_flush_locks(qp, &flags);
160} 120}
161 121
162static void __bnxt_qplib_del_flush_qp(struct bnxt_qplib_qp *qp) 122static void __bnxt_qplib_del_flush_qp(struct bnxt_qplib_qp *qp)
@@ -173,11 +133,11 @@ static void __bnxt_qplib_del_flush_qp(struct bnxt_qplib_qp *qp)
173 } 133 }
174} 134}
175 135
176void bnxt_qplib_del_flush_qp(struct bnxt_qplib_qp *qp) 136void bnxt_qplib_clean_qp(struct bnxt_qplib_qp *qp)
177{ 137{
178 unsigned long flags; 138 unsigned long flags;
179 139
180 bnxt_qplib_acquire_cq_locks(qp, &flags); 140 bnxt_qplib_acquire_cq_flush_locks(qp, &flags);
181 __clean_cq(qp->scq, (u64)(unsigned long)qp); 141 __clean_cq(qp->scq, (u64)(unsigned long)qp);
182 qp->sq.hwq.prod = 0; 142 qp->sq.hwq.prod = 0;
183 qp->sq.hwq.cons = 0; 143 qp->sq.hwq.cons = 0;
@@ -186,7 +146,7 @@ void bnxt_qplib_del_flush_qp(struct bnxt_qplib_qp *qp)
186 qp->rq.hwq.cons = 0; 146 qp->rq.hwq.cons = 0;
187 147
188 __bnxt_qplib_del_flush_qp(qp); 148 __bnxt_qplib_del_flush_qp(qp);
189 bnxt_qplib_release_cq_locks(qp, &flags); 149 bnxt_qplib_release_cq_flush_locks(qp, &flags);
190} 150}
191 151
192static void bnxt_qpn_cqn_sched_task(struct work_struct *work) 152static void bnxt_qpn_cqn_sched_task(struct work_struct *work)
@@ -283,7 +243,7 @@ static void bnxt_qplib_service_nq(unsigned long data)
283 u32 sw_cons, raw_cons; 243 u32 sw_cons, raw_cons;
284 u16 type; 244 u16 type;
285 int budget = nq->budget; 245 int budget = nq->budget;
286 u64 q_handle; 246 uintptr_t q_handle;
287 247
288 /* Service the NQ until empty */ 248 /* Service the NQ until empty */
289 raw_cons = hwq->cons; 249 raw_cons = hwq->cons;
@@ -566,7 +526,7 @@ int bnxt_qplib_create_srq(struct bnxt_qplib_res *res,
566 526
567 /* Configure the request */ 527 /* Configure the request */
568 req.dpi = cpu_to_le32(srq->dpi->dpi); 528 req.dpi = cpu_to_le32(srq->dpi->dpi);
569 req.srq_handle = cpu_to_le64(srq); 529 req.srq_handle = cpu_to_le64((uintptr_t)srq);
570 530
571 req.srq_size = cpu_to_le16((u16)srq->hwq.max_elements); 531 req.srq_size = cpu_to_le16((u16)srq->hwq.max_elements);
572 pbl = &srq->hwq.pbl[PBL_LVL_0]; 532 pbl = &srq->hwq.pbl[PBL_LVL_0];
@@ -1419,7 +1379,6 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
1419 struct bnxt_qplib_rcfw *rcfw = res->rcfw; 1379 struct bnxt_qplib_rcfw *rcfw = res->rcfw;
1420 struct cmdq_destroy_qp req; 1380 struct cmdq_destroy_qp req;
1421 struct creq_destroy_qp_resp resp; 1381 struct creq_destroy_qp_resp resp;
1422 unsigned long flags;
1423 u16 cmd_flags = 0; 1382 u16 cmd_flags = 0;
1424 int rc; 1383 int rc;
1425 1384
@@ -1437,19 +1396,12 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
1437 return rc; 1396 return rc;
1438 } 1397 }
1439 1398
1440 /* Must walk the associated CQs to nullified the QP ptr */ 1399 return 0;
1441 spin_lock_irqsave(&qp->scq->hwq.lock, flags); 1400}
1442
1443 __clean_cq(qp->scq, (u64)(unsigned long)qp);
1444
1445 if (qp->rcq && qp->rcq != qp->scq) {
1446 spin_lock(&qp->rcq->hwq.lock);
1447 __clean_cq(qp->rcq, (u64)(unsigned long)qp);
1448 spin_unlock(&qp->rcq->hwq.lock);
1449 }
1450
1451 spin_unlock_irqrestore(&qp->scq->hwq.lock, flags);
1452 1401
1402void bnxt_qplib_free_qp_res(struct bnxt_qplib_res *res,
1403 struct bnxt_qplib_qp *qp)
1404{
1453 bnxt_qplib_free_qp_hdr_buf(res, qp); 1405 bnxt_qplib_free_qp_hdr_buf(res, qp);
1454 bnxt_qplib_free_hwq(res->pdev, &qp->sq.hwq); 1406 bnxt_qplib_free_hwq(res->pdev, &qp->sq.hwq);
1455 kfree(qp->sq.swq); 1407 kfree(qp->sq.swq);
@@ -1462,7 +1414,6 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
1462 if (qp->orrq.max_elements) 1414 if (qp->orrq.max_elements)
1463 bnxt_qplib_free_hwq(res->pdev, &qp->orrq); 1415 bnxt_qplib_free_hwq(res->pdev, &qp->orrq);
1464 1416
1465 return 0;
1466} 1417}
1467 1418
1468void *bnxt_qplib_get_qp1_sq_buf(struct bnxt_qplib_qp *qp, 1419void *bnxt_qplib_get_qp1_sq_buf(struct bnxt_qplib_qp *qp,
@@ -2116,9 +2067,6 @@ void bnxt_qplib_mark_qp_error(void *qp_handle)
2116 /* Must block new posting of SQ and RQ */ 2067 /* Must block new posting of SQ and RQ */
2117 qp->state = CMDQ_MODIFY_QP_NEW_STATE_ERR; 2068 qp->state = CMDQ_MODIFY_QP_NEW_STATE_ERR;
2118 bnxt_qplib_cancel_phantom_processing(qp); 2069 bnxt_qplib_cancel_phantom_processing(qp);
2119
2120 /* Add qp to flush list of the CQ */
2121 __bnxt_qplib_add_flush_qp(qp);
2122} 2070}
2123 2071
2124/* Note: SQE is valid from sw_sq_cons up to cqe_sq_cons (exclusive) 2072/* Note: SQE is valid from sw_sq_cons up to cqe_sq_cons (exclusive)
@@ -2294,9 +2242,9 @@ static int bnxt_qplib_cq_process_req(struct bnxt_qplib_cq *cq,
2294 sw_sq_cons, cqe->wr_id, cqe->status); 2242 sw_sq_cons, cqe->wr_id, cqe->status);
2295 cqe++; 2243 cqe++;
2296 (*budget)--; 2244 (*budget)--;
2297 bnxt_qplib_lock_buddy_cq(qp, cq);
2298 bnxt_qplib_mark_qp_error(qp); 2245 bnxt_qplib_mark_qp_error(qp);
2299 bnxt_qplib_unlock_buddy_cq(qp, cq); 2246 /* Add qp to flush list of the CQ */
2247 bnxt_qplib_add_flush_qp(qp);
2300 } else { 2248 } else {
2301 if (swq->flags & SQ_SEND_FLAGS_SIGNAL_COMP) { 2249 if (swq->flags & SQ_SEND_FLAGS_SIGNAL_COMP) {
2302 /* Before we complete, do WA 9060 */ 2250 /* Before we complete, do WA 9060 */
@@ -2412,9 +2360,7 @@ static int bnxt_qplib_cq_process_res_rc(struct bnxt_qplib_cq *cq,
2412 if (hwcqe->status != CQ_RES_RC_STATUS_OK) { 2360 if (hwcqe->status != CQ_RES_RC_STATUS_OK) {
2413 qp->state = CMDQ_MODIFY_QP_NEW_STATE_ERR; 2361 qp->state = CMDQ_MODIFY_QP_NEW_STATE_ERR;
2414 /* Add qp to flush list of the CQ */ 2362 /* Add qp to flush list of the CQ */
2415 bnxt_qplib_lock_buddy_cq(qp, cq); 2363 bnxt_qplib_add_flush_qp(qp);
2416 __bnxt_qplib_add_flush_qp(qp);
2417 bnxt_qplib_unlock_buddy_cq(qp, cq);
2418 } 2364 }
2419 } 2365 }
2420 2366
@@ -2498,9 +2444,7 @@ static int bnxt_qplib_cq_process_res_ud(struct bnxt_qplib_cq *cq,
2498 if (hwcqe->status != CQ_RES_RC_STATUS_OK) { 2444 if (hwcqe->status != CQ_RES_RC_STATUS_OK) {
2499 qp->state = CMDQ_MODIFY_QP_NEW_STATE_ERR; 2445 qp->state = CMDQ_MODIFY_QP_NEW_STATE_ERR;
2500 /* Add qp to flush list of the CQ */ 2446 /* Add qp to flush list of the CQ */
2501 bnxt_qplib_lock_buddy_cq(qp, cq); 2447 bnxt_qplib_add_flush_qp(qp);
2502 __bnxt_qplib_add_flush_qp(qp);
2503 bnxt_qplib_unlock_buddy_cq(qp, cq);
2504 } 2448 }
2505 } 2449 }
2506done: 2450done:
@@ -2510,11 +2454,9 @@ done:
2510bool bnxt_qplib_is_cq_empty(struct bnxt_qplib_cq *cq) 2454bool bnxt_qplib_is_cq_empty(struct bnxt_qplib_cq *cq)
2511{ 2455{
2512 struct cq_base *hw_cqe, **hw_cqe_ptr; 2456 struct cq_base *hw_cqe, **hw_cqe_ptr;
2513 unsigned long flags;
2514 u32 sw_cons, raw_cons; 2457 u32 sw_cons, raw_cons;
2515 bool rc = true; 2458 bool rc = true;
2516 2459
2517 spin_lock_irqsave(&cq->hwq.lock, flags);
2518 raw_cons = cq->hwq.cons; 2460 raw_cons = cq->hwq.cons;
2519 sw_cons = HWQ_CMP(raw_cons, &cq->hwq); 2461 sw_cons = HWQ_CMP(raw_cons, &cq->hwq);
2520 hw_cqe_ptr = (struct cq_base **)cq->hwq.pbl_ptr; 2462 hw_cqe_ptr = (struct cq_base **)cq->hwq.pbl_ptr;
@@ -2522,7 +2464,6 @@ bool bnxt_qplib_is_cq_empty(struct bnxt_qplib_cq *cq)
2522 2464
2523 /* Check for Valid bit. If the CQE is valid, return false */ 2465 /* Check for Valid bit. If the CQE is valid, return false */
2524 rc = !CQE_CMP_VALID(hw_cqe, raw_cons, cq->hwq.max_elements); 2466 rc = !CQE_CMP_VALID(hw_cqe, raw_cons, cq->hwq.max_elements);
2525 spin_unlock_irqrestore(&cq->hwq.lock, flags);
2526 return rc; 2467 return rc;
2527} 2468}
2528 2469
@@ -2611,9 +2552,7 @@ static int bnxt_qplib_cq_process_res_raweth_qp1(struct bnxt_qplib_cq *cq,
2611 if (hwcqe->status != CQ_RES_RC_STATUS_OK) { 2552 if (hwcqe->status != CQ_RES_RC_STATUS_OK) {
2612 qp->state = CMDQ_MODIFY_QP_NEW_STATE_ERR; 2553 qp->state = CMDQ_MODIFY_QP_NEW_STATE_ERR;
2613 /* Add qp to flush list of the CQ */ 2554 /* Add qp to flush list of the CQ */
2614 bnxt_qplib_lock_buddy_cq(qp, cq); 2555 bnxt_qplib_add_flush_qp(qp);
2615 __bnxt_qplib_add_flush_qp(qp);
2616 bnxt_qplib_unlock_buddy_cq(qp, cq);
2617 } 2556 }
2618 } 2557 }
2619 2558
@@ -2728,9 +2667,7 @@ do_rq:
2728 */ 2667 */
2729 2668
2730 /* Add qp to flush list of the CQ */ 2669 /* Add qp to flush list of the CQ */
2731 bnxt_qplib_lock_buddy_cq(qp, cq); 2670 bnxt_qplib_add_flush_qp(qp);
2732 __bnxt_qplib_add_flush_qp(qp);
2733 bnxt_qplib_unlock_buddy_cq(qp, cq);
2734done: 2671done:
2735 return rc; 2672 return rc;
2736} 2673}
@@ -2759,7 +2696,7 @@ int bnxt_qplib_process_flush_list(struct bnxt_qplib_cq *cq,
2759 u32 budget = num_cqes; 2696 u32 budget = num_cqes;
2760 unsigned long flags; 2697 unsigned long flags;
2761 2698
2762 spin_lock_irqsave(&cq->hwq.lock, flags); 2699 spin_lock_irqsave(&cq->flush_lock, flags);
2763 list_for_each_entry(qp, &cq->sqf_head, sq_flush) { 2700 list_for_each_entry(qp, &cq->sqf_head, sq_flush) {
2764 dev_dbg(&cq->hwq.pdev->dev, 2701 dev_dbg(&cq->hwq.pdev->dev,
2765 "QPLIB: FP: Flushing SQ QP= %p", 2702 "QPLIB: FP: Flushing SQ QP= %p",
@@ -2773,7 +2710,7 @@ int bnxt_qplib_process_flush_list(struct bnxt_qplib_cq *cq,
2773 qp); 2710 qp);
2774 __flush_rq(&qp->rq, qp, &cqe, &budget); 2711 __flush_rq(&qp->rq, qp, &cqe, &budget);
2775 } 2712 }
2776 spin_unlock_irqrestore(&cq->hwq.lock, flags); 2713 spin_unlock_irqrestore(&cq->flush_lock, flags);
2777 2714
2778 return num_cqes - budget; 2715 return num_cqes - budget;
2779} 2716}
@@ -2782,11 +2719,9 @@ int bnxt_qplib_poll_cq(struct bnxt_qplib_cq *cq, struct bnxt_qplib_cqe *cqe,
2782 int num_cqes, struct bnxt_qplib_qp **lib_qp) 2719 int num_cqes, struct bnxt_qplib_qp **lib_qp)
2783{ 2720{
2784 struct cq_base *hw_cqe, **hw_cqe_ptr; 2721 struct cq_base *hw_cqe, **hw_cqe_ptr;
2785 unsigned long flags;
2786 u32 sw_cons, raw_cons; 2722 u32 sw_cons, raw_cons;
2787 int budget, rc = 0; 2723 int budget, rc = 0;
2788 2724
2789 spin_lock_irqsave(&cq->hwq.lock, flags);
2790 raw_cons = cq->hwq.cons; 2725 raw_cons = cq->hwq.cons;
2791 budget = num_cqes; 2726 budget = num_cqes;
2792 2727
@@ -2862,20 +2797,15 @@ int bnxt_qplib_poll_cq(struct bnxt_qplib_cq *cq, struct bnxt_qplib_cqe *cqe,
2862 bnxt_qplib_arm_cq(cq, DBR_DBR_TYPE_CQ); 2797 bnxt_qplib_arm_cq(cq, DBR_DBR_TYPE_CQ);
2863 } 2798 }
2864exit: 2799exit:
2865 spin_unlock_irqrestore(&cq->hwq.lock, flags);
2866 return num_cqes - budget; 2800 return num_cqes - budget;
2867} 2801}
2868 2802
2869void bnxt_qplib_req_notify_cq(struct bnxt_qplib_cq *cq, u32 arm_type) 2803void bnxt_qplib_req_notify_cq(struct bnxt_qplib_cq *cq, u32 arm_type)
2870{ 2804{
2871 unsigned long flags;
2872
2873 spin_lock_irqsave(&cq->hwq.lock, flags);
2874 if (arm_type) 2805 if (arm_type)
2875 bnxt_qplib_arm_cq(cq, arm_type); 2806 bnxt_qplib_arm_cq(cq, arm_type);
2876 /* Using cq->arm_state variable to track whether to issue cq handler */ 2807 /* Using cq->arm_state variable to track whether to issue cq handler */
2877 atomic_set(&cq->arm_state, 1); 2808 atomic_set(&cq->arm_state, 1);
2878 spin_unlock_irqrestore(&cq->hwq.lock, flags);
2879} 2809}
2880 2810
2881void bnxt_qplib_flush_cqn_wq(struct bnxt_qplib_qp *qp) 2811void bnxt_qplib_flush_cqn_wq(struct bnxt_qplib_qp *qp)
diff --git a/drivers/infiniband/hw/bnxt_re/qplib_fp.h b/drivers/infiniband/hw/bnxt_re/qplib_fp.h
index 211b27a8f9e2..ade9f13c0fd1 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_fp.h
+++ b/drivers/infiniband/hw/bnxt_re/qplib_fp.h
@@ -389,6 +389,18 @@ struct bnxt_qplib_cq {
389 struct list_head sqf_head, rqf_head; 389 struct list_head sqf_head, rqf_head;
390 atomic_t arm_state; 390 atomic_t arm_state;
391 spinlock_t compl_lock; /* synch CQ handlers */ 391 spinlock_t compl_lock; /* synch CQ handlers */
392/* Locking Notes:
393 * QP can move to error state from modify_qp, async error event or error
394 * CQE as part of poll_cq. When QP is moved to error state, it gets added
395 * to two flush lists, one each for SQ and RQ.
396 * Each flush list is protected by qplib_cq->flush_lock. Both scq and rcq
397 * flush_locks should be acquired when QP is moved to error. The control path
398 * operations(modify_qp and async error events) are synchronized with poll_cq
399 * using upper level CQ locks (bnxt_re_cq->cq_lock) of both SCQ and RCQ.
400 * The qplib_cq->flush_lock is required to synchronize two instances of poll_cq
401 * of the same QP while manipulating the flush list.
402 */
403 spinlock_t flush_lock; /* QP flush management */
392}; 404};
393 405
394#define BNXT_QPLIB_MAX_IRRQE_ENTRY_SIZE sizeof(struct xrrq_irrq) 406#define BNXT_QPLIB_MAX_IRRQE_ENTRY_SIZE sizeof(struct xrrq_irrq)
@@ -478,6 +490,9 @@ int bnxt_qplib_create_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
478int bnxt_qplib_modify_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp); 490int bnxt_qplib_modify_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
479int bnxt_qplib_query_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp); 491int bnxt_qplib_query_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
480int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp); 492int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
493void bnxt_qplib_clean_qp(struct bnxt_qplib_qp *qp);
494void bnxt_qplib_free_qp_res(struct bnxt_qplib_res *res,
495 struct bnxt_qplib_qp *qp);
481void *bnxt_qplib_get_qp1_sq_buf(struct bnxt_qplib_qp *qp, 496void *bnxt_qplib_get_qp1_sq_buf(struct bnxt_qplib_qp *qp,
482 struct bnxt_qplib_sge *sge); 497 struct bnxt_qplib_sge *sge);
483void *bnxt_qplib_get_qp1_rq_buf(struct bnxt_qplib_qp *qp, 498void *bnxt_qplib_get_qp1_rq_buf(struct bnxt_qplib_qp *qp,
@@ -500,7 +515,6 @@ void bnxt_qplib_req_notify_cq(struct bnxt_qplib_cq *cq, u32 arm_type);
500void bnxt_qplib_free_nq(struct bnxt_qplib_nq *nq); 515void bnxt_qplib_free_nq(struct bnxt_qplib_nq *nq);
501int bnxt_qplib_alloc_nq(struct pci_dev *pdev, struct bnxt_qplib_nq *nq); 516int bnxt_qplib_alloc_nq(struct pci_dev *pdev, struct bnxt_qplib_nq *nq);
502void bnxt_qplib_add_flush_qp(struct bnxt_qplib_qp *qp); 517void bnxt_qplib_add_flush_qp(struct bnxt_qplib_qp *qp);
503void bnxt_qplib_del_flush_qp(struct bnxt_qplib_qp *qp);
504void bnxt_qplib_acquire_cq_locks(struct bnxt_qplib_qp *qp, 518void bnxt_qplib_acquire_cq_locks(struct bnxt_qplib_qp *qp,
505 unsigned long *flags); 519 unsigned long *flags);
506void bnxt_qplib_release_cq_locks(struct bnxt_qplib_qp *qp, 520void bnxt_qplib_release_cq_locks(struct bnxt_qplib_qp *qp,
diff --git a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
index 8329ec6a7946..80027a494730 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
@@ -305,9 +305,8 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw,
305 err_event->res_err_state_reason); 305 err_event->res_err_state_reason);
306 if (!qp) 306 if (!qp)
307 break; 307 break;
308 bnxt_qplib_acquire_cq_locks(qp, &flags);
309 bnxt_qplib_mark_qp_error(qp); 308 bnxt_qplib_mark_qp_error(qp);
310 bnxt_qplib_release_cq_locks(qp, &flags); 309 rcfw->aeq_handler(rcfw, qp_event, qp);
311 break; 310 break;
312 default: 311 default:
313 /* Command Response */ 312 /* Command Response */
@@ -460,7 +459,11 @@ int bnxt_qplib_init_rcfw(struct bnxt_qplib_rcfw *rcfw,
460 int rc; 459 int rc;
461 460
462 RCFW_CMD_PREP(req, INITIALIZE_FW, cmd_flags); 461 RCFW_CMD_PREP(req, INITIALIZE_FW, cmd_flags);
463 462 /* Supply (log-base-2-of-host-page-size - base-page-shift)
463 * to bono to adjust the doorbell page sizes.
464 */
465 req.log2_dbr_pg_size = cpu_to_le16(PAGE_SHIFT -
466 RCFW_DBR_BASE_PAGE_SHIFT);
464 /* 467 /*
465 * VFs need not setup the HW context area, PF 468 * VFs need not setup the HW context area, PF
466 * shall setup this area for VF. Skipping the 469 * shall setup this area for VF. Skipping the
diff --git a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.h b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.h
index 6bee6e3636ea..c7cce2e4185e 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.h
+++ b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.h
@@ -49,6 +49,7 @@
49#define RCFW_COMM_SIZE 0x104 49#define RCFW_COMM_SIZE 0x104
50 50
51#define RCFW_DBR_PCI_BAR_REGION 2 51#define RCFW_DBR_PCI_BAR_REGION 2
52#define RCFW_DBR_BASE_PAGE_SHIFT 12
52 53
53#define RCFW_CMD_PREP(req, CMD, cmd_flags) \ 54#define RCFW_CMD_PREP(req, CMD, cmd_flags) \
54 do { \ 55 do { \
diff --git a/drivers/infiniband/hw/bnxt_re/qplib_sp.c b/drivers/infiniband/hw/bnxt_re/qplib_sp.c
index c015c1861351..ee98e5efef84 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_sp.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_sp.c
@@ -52,18 +52,6 @@ const struct bnxt_qplib_gid bnxt_qplib_gid_zero = {{ 0, 0, 0, 0, 0, 0, 0, 0,
52 52
53/* Device */ 53/* Device */
54 54
55static bool bnxt_qplib_is_atomic_cap(struct bnxt_qplib_rcfw *rcfw)
56{
57 int rc;
58 u16 pcie_ctl2;
59
60 rc = pcie_capability_read_word(rcfw->pdev, PCI_EXP_DEVCTL2,
61 &pcie_ctl2);
62 if (rc)
63 return false;
64 return !!(pcie_ctl2 & PCI_EXP_DEVCTL2_ATOMIC_REQ);
65}
66
67static void bnxt_qplib_query_version(struct bnxt_qplib_rcfw *rcfw, 55static void bnxt_qplib_query_version(struct bnxt_qplib_rcfw *rcfw,
68 char *fw_ver) 56 char *fw_ver)
69{ 57{
@@ -151,7 +139,8 @@ int bnxt_qplib_get_dev_attr(struct bnxt_qplib_rcfw *rcfw,
151 attr->max_pkey = le32_to_cpu(sb->max_pkeys); 139 attr->max_pkey = le32_to_cpu(sb->max_pkeys);
152 140
153 attr->max_inline_data = le32_to_cpu(sb->max_inline_data); 141 attr->max_inline_data = le32_to_cpu(sb->max_inline_data);
154 attr->l2_db_size = (sb->l2_db_space_size + 1) * PAGE_SIZE; 142 attr->l2_db_size = (sb->l2_db_space_size + 1) *
143 (0x01 << RCFW_DBR_BASE_PAGE_SHIFT);
155 attr->max_sgid = le32_to_cpu(sb->max_gid); 144 attr->max_sgid = le32_to_cpu(sb->max_gid);
156 145
157 bnxt_qplib_query_version(rcfw, attr->fw_ver); 146 bnxt_qplib_query_version(rcfw, attr->fw_ver);
@@ -165,7 +154,7 @@ int bnxt_qplib_get_dev_attr(struct bnxt_qplib_rcfw *rcfw,
165 attr->tqm_alloc_reqs[i * 4 + 3] = *(++tqm_alloc); 154 attr->tqm_alloc_reqs[i * 4 + 3] = *(++tqm_alloc);
166 } 155 }
167 156
168 attr->is_atomic = bnxt_qplib_is_atomic_cap(rcfw); 157 attr->is_atomic = 0;
169bail: 158bail:
170 bnxt_qplib_rcfw_free_sbuf(rcfw, sbuf); 159 bnxt_qplib_rcfw_free_sbuf(rcfw, sbuf);
171 return rc; 160 return rc;
diff --git a/drivers/infiniband/hw/bnxt_re/roce_hsi.h b/drivers/infiniband/hw/bnxt_re/roce_hsi.h
index 2d7ea096a247..3e5a4f760d0e 100644
--- a/drivers/infiniband/hw/bnxt_re/roce_hsi.h
+++ b/drivers/infiniband/hw/bnxt_re/roce_hsi.h
@@ -1761,7 +1761,30 @@ struct cmdq_initialize_fw {
1761 #define CMDQ_INITIALIZE_FW_TIM_PG_SIZE_PG_2M (0x3UL << 4) 1761 #define CMDQ_INITIALIZE_FW_TIM_PG_SIZE_PG_2M (0x3UL << 4)
1762 #define CMDQ_INITIALIZE_FW_TIM_PG_SIZE_PG_8M (0x4UL << 4) 1762 #define CMDQ_INITIALIZE_FW_TIM_PG_SIZE_PG_8M (0x4UL << 4)
1763 #define CMDQ_INITIALIZE_FW_TIM_PG_SIZE_PG_1G (0x5UL << 4) 1763 #define CMDQ_INITIALIZE_FW_TIM_PG_SIZE_PG_1G (0x5UL << 4)
1764 __le16 reserved16; 1764 /* This value is (log-base-2-of-DBR-page-size - 12).
1765 * 0 for 4KB. HW supported values are enumerated below.
1766 */
1767 __le16 log2_dbr_pg_size;
1768 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_MASK 0xfUL
1769 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_SFT 0
1770 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_4K 0x0UL
1771 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_8K 0x1UL
1772 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_16K 0x2UL
1773 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_32K 0x3UL
1774 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_64K 0x4UL
1775 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_128K 0x5UL
1776 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_256K 0x6UL
1777 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_512K 0x7UL
1778 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_1M 0x8UL
1779 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_2M 0x9UL
1780 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_4M 0xaUL
1781 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_8M 0xbUL
1782 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_16M 0xcUL
1783 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_32M 0xdUL
1784 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_64M 0xeUL
1785 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_128M 0xfUL
1786 #define CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_LAST \
1787 CMDQ_INITIALIZE_FW_LOG2_DBR_PG_SIZE_PG_128M
1765 __le64 qpc_page_dir; 1788 __le64 qpc_page_dir;
1766 __le64 mrw_page_dir; 1789 __le64 mrw_page_dir;
1767 __le64 srq_page_dir; 1790 __le64 srq_page_dir;
diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c
index 9a566ee3ceff..82adc0d1d30e 100644
--- a/drivers/infiniband/hw/mlx4/cq.c
+++ b/drivers/infiniband/hw/mlx4/cq.c
@@ -601,6 +601,7 @@ static void use_tunnel_data(struct mlx4_ib_qp *qp, struct mlx4_ib_cq *cq, struct
601 wc->dlid_path_bits = 0; 601 wc->dlid_path_bits = 0;
602 602
603 if (is_eth) { 603 if (is_eth) {
604 wc->slid = 0;
604 wc->vlan_id = be16_to_cpu(hdr->tun.sl_vid); 605 wc->vlan_id = be16_to_cpu(hdr->tun.sl_vid);
605 memcpy(&(wc->smac[0]), (char *)&hdr->tun.mac_31_0, 4); 606 memcpy(&(wc->smac[0]), (char *)&hdr->tun.mac_31_0, 4);
606 memcpy(&(wc->smac[4]), (char *)&hdr->tun.slid_mac_47_32, 2); 607 memcpy(&(wc->smac[4]), (char *)&hdr->tun.slid_mac_47_32, 2);
@@ -851,7 +852,6 @@ repoll:
851 } 852 }
852 } 853 }
853 854
854 wc->slid = be16_to_cpu(cqe->rlid);
855 g_mlpath_rqpn = be32_to_cpu(cqe->g_mlpath_rqpn); 855 g_mlpath_rqpn = be32_to_cpu(cqe->g_mlpath_rqpn);
856 wc->src_qp = g_mlpath_rqpn & 0xffffff; 856 wc->src_qp = g_mlpath_rqpn & 0xffffff;
857 wc->dlid_path_bits = (g_mlpath_rqpn >> 24) & 0x7f; 857 wc->dlid_path_bits = (g_mlpath_rqpn >> 24) & 0x7f;
@@ -860,6 +860,7 @@ repoll:
860 wc->wc_flags |= mlx4_ib_ipoib_csum_ok(cqe->status, 860 wc->wc_flags |= mlx4_ib_ipoib_csum_ok(cqe->status,
861 cqe->checksum) ? IB_WC_IP_CSUM_OK : 0; 861 cqe->checksum) ? IB_WC_IP_CSUM_OK : 0;
862 if (is_eth) { 862 if (is_eth) {
863 wc->slid = 0;
863 wc->sl = be16_to_cpu(cqe->sl_vid) >> 13; 864 wc->sl = be16_to_cpu(cqe->sl_vid) >> 13;
864 if (be32_to_cpu(cqe->vlan_my_qpn) & 865 if (be32_to_cpu(cqe->vlan_my_qpn) &
865 MLX4_CQE_CVLAN_PRESENT_MASK) { 866 MLX4_CQE_CVLAN_PRESENT_MASK) {
@@ -871,6 +872,7 @@ repoll:
871 memcpy(wc->smac, cqe->smac, ETH_ALEN); 872 memcpy(wc->smac, cqe->smac, ETH_ALEN);
872 wc->wc_flags |= (IB_WC_WITH_VLAN | IB_WC_WITH_SMAC); 873 wc->wc_flags |= (IB_WC_WITH_VLAN | IB_WC_WITH_SMAC);
873 } else { 874 } else {
875 wc->slid = be16_to_cpu(cqe->rlid);
874 wc->sl = be16_to_cpu(cqe->sl_vid) >> 12; 876 wc->sl = be16_to_cpu(cqe->sl_vid) >> 12;
875 wc->vlan_id = 0xffff; 877 wc->vlan_id = 0xffff;
876 } 878 }
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 8d2ee9322f2e..5a0e4fc4785a 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -219,8 +219,6 @@ static int mlx4_ib_update_gids_v1_v2(struct gid_entry *gids,
219 gid_tbl[i].version = 2; 219 gid_tbl[i].version = 2;
220 if (!ipv6_addr_v4mapped((struct in6_addr *)&gids[i].gid)) 220 if (!ipv6_addr_v4mapped((struct in6_addr *)&gids[i].gid))
221 gid_tbl[i].type = 1; 221 gid_tbl[i].type = 1;
222 else
223 memset(&gid_tbl[i].gid, 0, 12);
224 } 222 }
225 } 223 }
226 224
@@ -366,8 +364,13 @@ static int mlx4_ib_del_gid(struct ib_device *device,
366 if (!gids) { 364 if (!gids) {
367 ret = -ENOMEM; 365 ret = -ENOMEM;
368 } else { 366 } else {
369 for (i = 0; i < MLX4_MAX_PORT_GIDS; i++) 367 for (i = 0; i < MLX4_MAX_PORT_GIDS; i++) {
370 memcpy(&gids[i].gid, &port_gid_table->gids[i].gid, sizeof(union ib_gid)); 368 memcpy(&gids[i].gid,
369 &port_gid_table->gids[i].gid,
370 sizeof(union ib_gid));
371 gids[i].gid_type =
372 port_gid_table->gids[i].gid_type;
373 }
371 } 374 }
372 } 375 }
373 spin_unlock_bh(&iboe->lock); 376 spin_unlock_bh(&iboe->lock);
diff --git a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c
index 5b974fb97611..15457c9569a7 100644
--- a/drivers/infiniband/hw/mlx5/cq.c
+++ b/drivers/infiniband/hw/mlx5/cq.c
@@ -226,7 +226,6 @@ static void handle_responder(struct ib_wc *wc, struct mlx5_cqe64 *cqe,
226 wc->ex.invalidate_rkey = be32_to_cpu(cqe->imm_inval_pkey); 226 wc->ex.invalidate_rkey = be32_to_cpu(cqe->imm_inval_pkey);
227 break; 227 break;
228 } 228 }
229 wc->slid = be16_to_cpu(cqe->slid);
230 wc->src_qp = be32_to_cpu(cqe->flags_rqpn) & 0xffffff; 229 wc->src_qp = be32_to_cpu(cqe->flags_rqpn) & 0xffffff;
231 wc->dlid_path_bits = cqe->ml_path; 230 wc->dlid_path_bits = cqe->ml_path;
232 g = (be32_to_cpu(cqe->flags_rqpn) >> 28) & 3; 231 g = (be32_to_cpu(cqe->flags_rqpn) >> 28) & 3;
@@ -241,10 +240,12 @@ static void handle_responder(struct ib_wc *wc, struct mlx5_cqe64 *cqe,
241 } 240 }
242 241
243 if (ll != IB_LINK_LAYER_ETHERNET) { 242 if (ll != IB_LINK_LAYER_ETHERNET) {
243 wc->slid = be16_to_cpu(cqe->slid);
244 wc->sl = (be32_to_cpu(cqe->flags_rqpn) >> 24) & 0xf; 244 wc->sl = (be32_to_cpu(cqe->flags_rqpn) >> 24) & 0xf;
245 return; 245 return;
246 } 246 }
247 247
248 wc->slid = 0;
248 vlan_present = cqe->l4_l3_hdr_type & 0x1; 249 vlan_present = cqe->l4_l3_hdr_type & 0x1;
249 roce_packet_type = (be32_to_cpu(cqe->flags_rqpn) >> 24) & 0x3; 250 roce_packet_type = (be32_to_cpu(cqe->flags_rqpn) >> 24) & 0x3;
250 if (vlan_present) { 251 if (vlan_present) {
@@ -1177,7 +1178,12 @@ static int resize_user(struct mlx5_ib_dev *dev, struct mlx5_ib_cq *cq,
1177 if (ucmd.reserved0 || ucmd.reserved1) 1178 if (ucmd.reserved0 || ucmd.reserved1)
1178 return -EINVAL; 1179 return -EINVAL;
1179 1180
1180 umem = ib_umem_get(context, ucmd.buf_addr, entries * ucmd.cqe_size, 1181 /* check multiplication overflow */
1182 if (ucmd.cqe_size && SIZE_MAX / ucmd.cqe_size <= entries - 1)
1183 return -EINVAL;
1184
1185 umem = ib_umem_get(context, ucmd.buf_addr,
1186 (size_t)ucmd.cqe_size * entries,
1181 IB_ACCESS_LOCAL_WRITE, 1); 1187 IB_ACCESS_LOCAL_WRITE, 1);
1182 if (IS_ERR(umem)) { 1188 if (IS_ERR(umem)) {
1183 err = PTR_ERR(umem); 1189 err = PTR_ERR(umem);
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 4236c8086820..da091de4e69d 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -245,12 +245,16 @@ struct mlx5_core_dev *mlx5_ib_get_native_port_mdev(struct mlx5_ib_dev *ibdev,
245 struct mlx5_ib_multiport_info *mpi; 245 struct mlx5_ib_multiport_info *mpi;
246 struct mlx5_ib_port *port; 246 struct mlx5_ib_port *port;
247 247
248 if (!mlx5_core_mp_enabled(ibdev->mdev) ||
249 ll != IB_LINK_LAYER_ETHERNET) {
250 if (native_port_num)
251 *native_port_num = ib_port_num;
252 return ibdev->mdev;
253 }
254
248 if (native_port_num) 255 if (native_port_num)
249 *native_port_num = 1; 256 *native_port_num = 1;
250 257
251 if (!mlx5_core_mp_enabled(ibdev->mdev) || ll != IB_LINK_LAYER_ETHERNET)
252 return ibdev->mdev;
253
254 port = &ibdev->port[ib_port_num - 1]; 258 port = &ibdev->port[ib_port_num - 1];
255 if (!port) 259 if (!port)
256 return NULL; 260 return NULL;
@@ -3263,7 +3267,7 @@ static void mlx5_ib_handle_event(struct work_struct *_work)
3263 struct mlx5_ib_dev *ibdev; 3267 struct mlx5_ib_dev *ibdev;
3264 struct ib_event ibev; 3268 struct ib_event ibev;
3265 bool fatal = false; 3269 bool fatal = false;
3266 u8 port = 0; 3270 u8 port = (u8)work->param;
3267 3271
3268 if (mlx5_core_is_mp_slave(work->dev)) { 3272 if (mlx5_core_is_mp_slave(work->dev)) {
3269 ibdev = mlx5_ib_get_ibdev_from_mpi(work->context); 3273 ibdev = mlx5_ib_get_ibdev_from_mpi(work->context);
@@ -3283,8 +3287,6 @@ static void mlx5_ib_handle_event(struct work_struct *_work)
3283 case MLX5_DEV_EVENT_PORT_UP: 3287 case MLX5_DEV_EVENT_PORT_UP:
3284 case MLX5_DEV_EVENT_PORT_DOWN: 3288 case MLX5_DEV_EVENT_PORT_DOWN:
3285 case MLX5_DEV_EVENT_PORT_INITIALIZED: 3289 case MLX5_DEV_EVENT_PORT_INITIALIZED:
3286 port = (u8)work->param;
3287
3288 /* In RoCE, port up/down events are handled in 3290 /* In RoCE, port up/down events are handled in
3289 * mlx5_netdev_event(). 3291 * mlx5_netdev_event().
3290 */ 3292 */
@@ -3298,24 +3300,19 @@ static void mlx5_ib_handle_event(struct work_struct *_work)
3298 3300
3299 case MLX5_DEV_EVENT_LID_CHANGE: 3301 case MLX5_DEV_EVENT_LID_CHANGE:
3300 ibev.event = IB_EVENT_LID_CHANGE; 3302 ibev.event = IB_EVENT_LID_CHANGE;
3301 port = (u8)work->param;
3302 break; 3303 break;
3303 3304
3304 case MLX5_DEV_EVENT_PKEY_CHANGE: 3305 case MLX5_DEV_EVENT_PKEY_CHANGE:
3305 ibev.event = IB_EVENT_PKEY_CHANGE; 3306 ibev.event = IB_EVENT_PKEY_CHANGE;
3306 port = (u8)work->param;
3307
3308 schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work); 3307 schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work);
3309 break; 3308 break;
3310 3309
3311 case MLX5_DEV_EVENT_GUID_CHANGE: 3310 case MLX5_DEV_EVENT_GUID_CHANGE:
3312 ibev.event = IB_EVENT_GID_CHANGE; 3311 ibev.event = IB_EVENT_GID_CHANGE;
3313 port = (u8)work->param;
3314 break; 3312 break;
3315 3313
3316 case MLX5_DEV_EVENT_CLIENT_REREG: 3314 case MLX5_DEV_EVENT_CLIENT_REREG:
3317 ibev.event = IB_EVENT_CLIENT_REREGISTER; 3315 ibev.event = IB_EVENT_CLIENT_REREGISTER;
3318 port = (u8)work->param;
3319 break; 3316 break;
3320 case MLX5_DEV_EVENT_DELAY_DROP_TIMEOUT: 3317 case MLX5_DEV_EVENT_DELAY_DROP_TIMEOUT:
3321 schedule_work(&ibdev->delay_drop.delay_drop_work); 3318 schedule_work(&ibdev->delay_drop.delay_drop_work);
@@ -3327,7 +3324,7 @@ static void mlx5_ib_handle_event(struct work_struct *_work)
3327 ibev.device = &ibdev->ib_dev; 3324 ibev.device = &ibdev->ib_dev;
3328 ibev.element.port_num = port; 3325 ibev.element.port_num = port;
3329 3326
3330 if (port < 1 || port > ibdev->num_ports) { 3327 if (!rdma_is_port_valid(&ibdev->ib_dev, port)) {
3331 mlx5_ib_warn(ibdev, "warning: event on port %d\n", port); 3328 mlx5_ib_warn(ibdev, "warning: event on port %d\n", port);
3332 goto out; 3329 goto out;
3333 } 3330 }
@@ -4863,19 +4860,19 @@ static int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev)
4863 return ib_register_device(&dev->ib_dev, NULL); 4860 return ib_register_device(&dev->ib_dev, NULL);
4864} 4861}
4865 4862
4866static void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev) 4863static void mlx5_ib_stage_pre_ib_reg_umr_cleanup(struct mlx5_ib_dev *dev)
4867{ 4864{
4868 ib_unregister_device(&dev->ib_dev); 4865 destroy_umrc_res(dev);
4869} 4866}
4870 4867
4871static int mlx5_ib_stage_umr_res_init(struct mlx5_ib_dev *dev) 4868static void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev)
4872{ 4869{
4873 return create_umr_res(dev); 4870 ib_unregister_device(&dev->ib_dev);
4874} 4871}
4875 4872
4876static void mlx5_ib_stage_umr_res_cleanup(struct mlx5_ib_dev *dev) 4873static int mlx5_ib_stage_post_ib_reg_umr_init(struct mlx5_ib_dev *dev)
4877{ 4874{
4878 destroy_umrc_res(dev); 4875 return create_umr_res(dev);
4879} 4876}
4880 4877
4881static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev) 4878static int mlx5_ib_stage_delay_drop_init(struct mlx5_ib_dev *dev)
@@ -4985,12 +4982,15 @@ static const struct mlx5_ib_profile pf_profile = {
4985 STAGE_CREATE(MLX5_IB_STAGE_BFREG, 4982 STAGE_CREATE(MLX5_IB_STAGE_BFREG,
4986 mlx5_ib_stage_bfrag_init, 4983 mlx5_ib_stage_bfrag_init,
4987 mlx5_ib_stage_bfrag_cleanup), 4984 mlx5_ib_stage_bfrag_cleanup),
4985 STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR,
4986 NULL,
4987 mlx5_ib_stage_pre_ib_reg_umr_cleanup),
4988 STAGE_CREATE(MLX5_IB_STAGE_IB_REG, 4988 STAGE_CREATE(MLX5_IB_STAGE_IB_REG,
4989 mlx5_ib_stage_ib_reg_init, 4989 mlx5_ib_stage_ib_reg_init,
4990 mlx5_ib_stage_ib_reg_cleanup), 4990 mlx5_ib_stage_ib_reg_cleanup),
4991 STAGE_CREATE(MLX5_IB_STAGE_UMR_RESOURCES, 4991 STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR,
4992 mlx5_ib_stage_umr_res_init, 4992 mlx5_ib_stage_post_ib_reg_umr_init,
4993 mlx5_ib_stage_umr_res_cleanup), 4993 NULL),
4994 STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP, 4994 STAGE_CREATE(MLX5_IB_STAGE_DELAY_DROP,
4995 mlx5_ib_stage_delay_drop_init, 4995 mlx5_ib_stage_delay_drop_init,
4996 mlx5_ib_stage_delay_drop_cleanup), 4996 mlx5_ib_stage_delay_drop_cleanup),
diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h
index 139385129973..a5272499b600 100644
--- a/drivers/infiniband/hw/mlx5/mlx5_ib.h
+++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h
@@ -739,8 +739,9 @@ enum mlx5_ib_stages {
739 MLX5_IB_STAGE_CONG_DEBUGFS, 739 MLX5_IB_STAGE_CONG_DEBUGFS,
740 MLX5_IB_STAGE_UAR, 740 MLX5_IB_STAGE_UAR,
741 MLX5_IB_STAGE_BFREG, 741 MLX5_IB_STAGE_BFREG,
742 MLX5_IB_STAGE_PRE_IB_REG_UMR,
742 MLX5_IB_STAGE_IB_REG, 743 MLX5_IB_STAGE_IB_REG,
743 MLX5_IB_STAGE_UMR_RESOURCES, 744 MLX5_IB_STAGE_POST_IB_REG_UMR,
744 MLX5_IB_STAGE_DELAY_DROP, 745 MLX5_IB_STAGE_DELAY_DROP,
745 MLX5_IB_STAGE_CLASS_ATTR, 746 MLX5_IB_STAGE_CLASS_ATTR,
746 MLX5_IB_STAGE_MAX, 747 MLX5_IB_STAGE_MAX,
diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index 556e015678de..c51c602f06d6 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -838,7 +838,8 @@ static int mr_umem_get(struct ib_pd *pd, u64 start, u64 length,
838 *umem = ib_umem_get(pd->uobject->context, start, length, 838 *umem = ib_umem_get(pd->uobject->context, start, length,
839 access_flags, 0); 839 access_flags, 0);
840 err = PTR_ERR_OR_ZERO(*umem); 840 err = PTR_ERR_OR_ZERO(*umem);
841 if (err < 0) { 841 if (err) {
842 *umem = NULL;
842 mlx5_ib_err(dev, "umem get failed (%d)\n", err); 843 mlx5_ib_err(dev, "umem get failed (%d)\n", err);
843 return err; 844 return err;
844 } 845 }
@@ -1415,6 +1416,7 @@ int mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,
1415 if (err) { 1416 if (err) {
1416 mlx5_ib_warn(dev, "Failed to rereg UMR\n"); 1417 mlx5_ib_warn(dev, "Failed to rereg UMR\n");
1417 ib_umem_release(mr->umem); 1418 ib_umem_release(mr->umem);
1419 mr->umem = NULL;
1418 clean_mr(dev, mr); 1420 clean_mr(dev, mr);
1419 return err; 1421 return err;
1420 } 1422 }
@@ -1498,14 +1500,11 @@ static int clean_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
1498 u32 key = mr->mmkey.key; 1500 u32 key = mr->mmkey.key;
1499 1501
1500 err = destroy_mkey(dev, mr); 1502 err = destroy_mkey(dev, mr);
1501 kfree(mr);
1502 if (err) { 1503 if (err) {
1503 mlx5_ib_warn(dev, "failed to destroy mkey 0x%x (%d)\n", 1504 mlx5_ib_warn(dev, "failed to destroy mkey 0x%x (%d)\n",
1504 key, err); 1505 key, err);
1505 return err; 1506 return err;
1506 } 1507 }
1507 } else {
1508 mlx5_mr_cache_free(dev, mr);
1509 } 1508 }
1510 1509
1511 return 0; 1510 return 0;
@@ -1548,6 +1547,11 @@ static int dereg_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
1548 atomic_sub(npages, &dev->mdev->priv.reg_pages); 1547 atomic_sub(npages, &dev->mdev->priv.reg_pages);
1549 } 1548 }
1550 1549
1550 if (!mr->allocated_from_cache)
1551 kfree(mr);
1552 else
1553 mlx5_mr_cache_free(dev, mr);
1554
1551 return 0; 1555 return 0;
1552} 1556}
1553 1557
@@ -1816,7 +1820,6 @@ mlx5_ib_sg_to_klms(struct mlx5_ib_mr *mr,
1816 1820
1817 mr->ibmr.iova = sg_dma_address(sg) + sg_offset; 1821 mr->ibmr.iova = sg_dma_address(sg) + sg_offset;
1818 mr->ibmr.length = 0; 1822 mr->ibmr.length = 0;
1819 mr->ndescs = sg_nents;
1820 1823
1821 for_each_sg(sgl, sg, sg_nents, i) { 1824 for_each_sg(sgl, sg, sg_nents, i) {
1822 if (unlikely(i >= mr->max_descs)) 1825 if (unlikely(i >= mr->max_descs))
@@ -1828,6 +1831,7 @@ mlx5_ib_sg_to_klms(struct mlx5_ib_mr *mr,
1828 1831
1829 sg_offset = 0; 1832 sg_offset = 0;
1830 } 1833 }
1834 mr->ndescs = i;
1831 1835
1832 if (sg_offset_p) 1836 if (sg_offset_p)
1833 *sg_offset_p = sg_offset; 1837 *sg_offset_p = sg_offset;
diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
index 39d24bf694a8..a2e1aa86e133 100644
--- a/drivers/infiniband/hw/mlx5/qp.c
+++ b/drivers/infiniband/hw/mlx5/qp.c
@@ -1161,7 +1161,7 @@ static void destroy_raw_packet_qp_sq(struct mlx5_ib_dev *dev,
1161 ib_umem_release(sq->ubuffer.umem); 1161 ib_umem_release(sq->ubuffer.umem);
1162} 1162}
1163 1163
1164static int get_rq_pas_size(void *qpc) 1164static size_t get_rq_pas_size(void *qpc)
1165{ 1165{
1166 u32 log_page_size = MLX5_GET(qpc, qpc, log_page_size) + 12; 1166 u32 log_page_size = MLX5_GET(qpc, qpc, log_page_size) + 12;
1167 u32 log_rq_stride = MLX5_GET(qpc, qpc, log_rq_stride); 1167 u32 log_rq_stride = MLX5_GET(qpc, qpc, log_rq_stride);
@@ -1177,7 +1177,8 @@ static int get_rq_pas_size(void *qpc)
1177} 1177}
1178 1178
1179static int create_raw_packet_qp_rq(struct mlx5_ib_dev *dev, 1179static int create_raw_packet_qp_rq(struct mlx5_ib_dev *dev,
1180 struct mlx5_ib_rq *rq, void *qpin) 1180 struct mlx5_ib_rq *rq, void *qpin,
1181 size_t qpinlen)
1181{ 1182{
1182 struct mlx5_ib_qp *mqp = rq->base.container_mibqp; 1183 struct mlx5_ib_qp *mqp = rq->base.container_mibqp;
1183 __be64 *pas; 1184 __be64 *pas;
@@ -1186,9 +1187,12 @@ static int create_raw_packet_qp_rq(struct mlx5_ib_dev *dev,
1186 void *rqc; 1187 void *rqc;
1187 void *wq; 1188 void *wq;
1188 void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc); 1189 void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc);
1189 int inlen; 1190 size_t rq_pas_size = get_rq_pas_size(qpc);
1191 size_t inlen;
1190 int err; 1192 int err;
1191 u32 rq_pas_size = get_rq_pas_size(qpc); 1193
1194 if (qpinlen < rq_pas_size + MLX5_BYTE_OFF(create_qp_in, pas))
1195 return -EINVAL;
1192 1196
1193 inlen = MLX5_ST_SZ_BYTES(create_rq_in) + rq_pas_size; 1197 inlen = MLX5_ST_SZ_BYTES(create_rq_in) + rq_pas_size;
1194 in = kvzalloc(inlen, GFP_KERNEL); 1198 in = kvzalloc(inlen, GFP_KERNEL);
@@ -1277,7 +1281,7 @@ static void destroy_raw_packet_qp_tir(struct mlx5_ib_dev *dev,
1277} 1281}
1278 1282
1279static int create_raw_packet_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, 1283static int create_raw_packet_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp,
1280 u32 *in, 1284 u32 *in, size_t inlen,
1281 struct ib_pd *pd) 1285 struct ib_pd *pd)
1282{ 1286{
1283 struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; 1287 struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp;
@@ -1309,7 +1313,7 @@ static int create_raw_packet_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp,
1309 rq->flags |= MLX5_IB_RQ_CVLAN_STRIPPING; 1313 rq->flags |= MLX5_IB_RQ_CVLAN_STRIPPING;
1310 if (qp->flags & MLX5_IB_QP_PCI_WRITE_END_PADDING) 1314 if (qp->flags & MLX5_IB_QP_PCI_WRITE_END_PADDING)
1311 rq->flags |= MLX5_IB_RQ_PCI_WRITE_END_PADDING; 1315 rq->flags |= MLX5_IB_RQ_PCI_WRITE_END_PADDING;
1312 err = create_raw_packet_qp_rq(dev, rq, in); 1316 err = create_raw_packet_qp_rq(dev, rq, in, inlen);
1313 if (err) 1317 if (err)
1314 goto err_destroy_sq; 1318 goto err_destroy_sq;
1315 1319
@@ -1584,6 +1588,7 @@ static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd,
1584 u32 uidx = MLX5_IB_DEFAULT_UIDX; 1588 u32 uidx = MLX5_IB_DEFAULT_UIDX;
1585 struct mlx5_ib_create_qp ucmd; 1589 struct mlx5_ib_create_qp ucmd;
1586 struct mlx5_ib_qp_base *base; 1590 struct mlx5_ib_qp_base *base;
1591 int mlx5_st;
1587 void *qpc; 1592 void *qpc;
1588 u32 *in; 1593 u32 *in;
1589 int err; 1594 int err;
@@ -1592,6 +1597,10 @@ static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd,
1592 spin_lock_init(&qp->sq.lock); 1597 spin_lock_init(&qp->sq.lock);
1593 spin_lock_init(&qp->rq.lock); 1598 spin_lock_init(&qp->rq.lock);
1594 1599
1600 mlx5_st = to_mlx5_st(init_attr->qp_type);
1601 if (mlx5_st < 0)
1602 return -EINVAL;
1603
1595 if (init_attr->rwq_ind_tbl) { 1604 if (init_attr->rwq_ind_tbl) {
1596 if (!udata) 1605 if (!udata)
1597 return -ENOSYS; 1606 return -ENOSYS;
@@ -1753,7 +1762,7 @@ static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd,
1753 1762
1754 qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); 1763 qpc = MLX5_ADDR_OF(create_qp_in, in, qpc);
1755 1764
1756 MLX5_SET(qpc, qpc, st, to_mlx5_st(init_attr->qp_type)); 1765 MLX5_SET(qpc, qpc, st, mlx5_st);
1757 MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); 1766 MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED);
1758 1767
1759 if (init_attr->qp_type != MLX5_IB_QPT_REG_UMR) 1768 if (init_attr->qp_type != MLX5_IB_QPT_REG_UMR)
@@ -1867,11 +1876,16 @@ static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd,
1867 } 1876 }
1868 } 1877 }
1869 1878
1879 if (inlen < 0) {
1880 err = -EINVAL;
1881 goto err;
1882 }
1883
1870 if (init_attr->qp_type == IB_QPT_RAW_PACKET || 1884 if (init_attr->qp_type == IB_QPT_RAW_PACKET ||
1871 qp->flags & MLX5_IB_QP_UNDERLAY) { 1885 qp->flags & MLX5_IB_QP_UNDERLAY) {
1872 qp->raw_packet_qp.sq.ubuffer.buf_addr = ucmd.sq_buf_addr; 1886 qp->raw_packet_qp.sq.ubuffer.buf_addr = ucmd.sq_buf_addr;
1873 raw_packet_qp_copy_info(qp, &qp->raw_packet_qp); 1887 raw_packet_qp_copy_info(qp, &qp->raw_packet_qp);
1874 err = create_raw_packet_qp(dev, qp, in, pd); 1888 err = create_raw_packet_qp(dev, qp, in, inlen, pd);
1875 } else { 1889 } else {
1876 err = mlx5_core_create_qp(dev->mdev, &base->mqp, in, inlen); 1890 err = mlx5_core_create_qp(dev->mdev, &base->mqp, in, inlen);
1877 } 1891 }
@@ -3095,8 +3109,10 @@ static int __mlx5_ib_modify_qp(struct ib_qp *ibqp,
3095 goto out; 3109 goto out;
3096 3110
3097 if (mlx5_cur >= MLX5_QP_NUM_STATE || mlx5_new >= MLX5_QP_NUM_STATE || 3111 if (mlx5_cur >= MLX5_QP_NUM_STATE || mlx5_new >= MLX5_QP_NUM_STATE ||
3098 !optab[mlx5_cur][mlx5_new]) 3112 !optab[mlx5_cur][mlx5_new]) {
3113 err = -EINVAL;
3099 goto out; 3114 goto out;
3115 }
3100 3116
3101 op = optab[mlx5_cur][mlx5_new]; 3117 op = optab[mlx5_cur][mlx5_new];
3102 optpar = ib_mask_to_mlx5_opt(attr_mask); 3118 optpar = ib_mask_to_mlx5_opt(attr_mask);
diff --git a/drivers/infiniband/hw/mlx5/srq.c b/drivers/infiniband/hw/mlx5/srq.c
index 6d5fadad9090..3c7522d025f2 100644
--- a/drivers/infiniband/hw/mlx5/srq.c
+++ b/drivers/infiniband/hw/mlx5/srq.c
@@ -241,8 +241,8 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
241{ 241{
242 struct mlx5_ib_dev *dev = to_mdev(pd->device); 242 struct mlx5_ib_dev *dev = to_mdev(pd->device);
243 struct mlx5_ib_srq *srq; 243 struct mlx5_ib_srq *srq;
244 int desc_size; 244 size_t desc_size;
245 int buf_size; 245 size_t buf_size;
246 int err; 246 int err;
247 struct mlx5_srq_attr in = {0}; 247 struct mlx5_srq_attr in = {0};
248 __u32 max_srq_wqes = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz); 248 __u32 max_srq_wqes = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz);
@@ -266,15 +266,18 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
266 266
267 desc_size = sizeof(struct mlx5_wqe_srq_next_seg) + 267 desc_size = sizeof(struct mlx5_wqe_srq_next_seg) +
268 srq->msrq.max_gs * sizeof(struct mlx5_wqe_data_seg); 268 srq->msrq.max_gs * sizeof(struct mlx5_wqe_data_seg);
269 if (desc_size == 0 || srq->msrq.max_gs > desc_size)
270 return ERR_PTR(-EINVAL);
269 desc_size = roundup_pow_of_two(desc_size); 271 desc_size = roundup_pow_of_two(desc_size);
270 desc_size = max_t(int, 32, desc_size); 272 desc_size = max_t(size_t, 32, desc_size);
273 if (desc_size < sizeof(struct mlx5_wqe_srq_next_seg))
274 return ERR_PTR(-EINVAL);
271 srq->msrq.max_avail_gather = (desc_size - sizeof(struct mlx5_wqe_srq_next_seg)) / 275 srq->msrq.max_avail_gather = (desc_size - sizeof(struct mlx5_wqe_srq_next_seg)) /
272 sizeof(struct mlx5_wqe_data_seg); 276 sizeof(struct mlx5_wqe_data_seg);
273 srq->msrq.wqe_shift = ilog2(desc_size); 277 srq->msrq.wqe_shift = ilog2(desc_size);
274 buf_size = srq->msrq.max * desc_size; 278 buf_size = srq->msrq.max * desc_size;
275 mlx5_ib_dbg(dev, "desc_size 0x%x, req wr 0x%x, srq size 0x%x, max_gs 0x%x, max_avail_gather 0x%x\n", 279 if (buf_size < desc_size)
276 desc_size, init_attr->attr.max_wr, srq->msrq.max, srq->msrq.max_gs, 280 return ERR_PTR(-EINVAL);
277 srq->msrq.max_avail_gather);
278 in.type = init_attr->srq_type; 281 in.type = init_attr->srq_type;
279 282
280 if (pd->uobject) 283 if (pd->uobject)
diff --git a/drivers/infiniband/hw/qedr/qedr_iw_cm.c b/drivers/infiniband/hw/qedr/qedr_iw_cm.c
index 478b7317b80a..26dc374787f7 100644
--- a/drivers/infiniband/hw/qedr/qedr_iw_cm.c
+++ b/drivers/infiniband/hw/qedr/qedr_iw_cm.c
@@ -458,8 +458,7 @@ qedr_addr6_resolve(struct qedr_dev *dev,
458 } 458 }
459 return -EINVAL; 459 return -EINVAL;
460 } 460 }
461 neigh = dst_neigh_lookup(dst, &dst_in); 461 neigh = dst_neigh_lookup(dst, &fl6.daddr);
462
463 if (neigh) { 462 if (neigh) {
464 rcu_read_lock(); 463 rcu_read_lock();
465 if (neigh->nud_state & NUD_VALID) { 464 if (neigh->nud_state & NUD_VALID) {
@@ -494,10 +493,14 @@ int qedr_iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
494 493
495 qp = idr_find(&dev->qpidr, conn_param->qpn); 494 qp = idr_find(&dev->qpidr, conn_param->qpn);
496 495
497 laddr = (struct sockaddr_in *)&cm_id->local_addr; 496 laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
498 raddr = (struct sockaddr_in *)&cm_id->remote_addr; 497 raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
499 laddr6 = (struct sockaddr_in6 *)&cm_id->local_addr; 498 laddr6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
500 raddr6 = (struct sockaddr_in6 *)&cm_id->remote_addr; 499 raddr6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
500
501 DP_DEBUG(dev, QEDR_MSG_IWARP, "MAPPED %d %d\n",
502 ntohs(((struct sockaddr_in *)&cm_id->remote_addr)->sin_port),
503 ntohs(raddr->sin_port));
501 504
502 DP_DEBUG(dev, QEDR_MSG_IWARP, 505 DP_DEBUG(dev, QEDR_MSG_IWARP,
503 "Connect source address: %pISpc, remote address: %pISpc\n", 506 "Connect source address: %pISpc, remote address: %pISpc\n",
@@ -599,8 +602,8 @@ int qedr_iw_create_listen(struct iw_cm_id *cm_id, int backlog)
599 int rc; 602 int rc;
600 int i; 603 int i;
601 604
602 laddr = (struct sockaddr_in *)&cm_id->local_addr; 605 laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
603 laddr6 = (struct sockaddr_in6 *)&cm_id->local_addr; 606 laddr6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
604 607
605 DP_DEBUG(dev, QEDR_MSG_IWARP, 608 DP_DEBUG(dev, QEDR_MSG_IWARP,
606 "Create Listener address: %pISpc\n", &cm_id->local_addr); 609 "Create Listener address: %pISpc\n", &cm_id->local_addr);
diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c
index 53f00dbf313f..875b17272d65 100644
--- a/drivers/infiniband/hw/qedr/verbs.c
+++ b/drivers/infiniband/hw/qedr/verbs.c
@@ -3034,6 +3034,11 @@ static int __qedr_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
3034 3034
3035 switch (wr->opcode) { 3035 switch (wr->opcode) {
3036 case IB_WR_SEND_WITH_IMM: 3036 case IB_WR_SEND_WITH_IMM:
3037 if (unlikely(rdma_protocol_iwarp(&dev->ibdev, 1))) {
3038 rc = -EINVAL;
3039 *bad_wr = wr;
3040 break;
3041 }
3037 wqe->req_type = RDMA_SQ_REQ_TYPE_SEND_WITH_IMM; 3042 wqe->req_type = RDMA_SQ_REQ_TYPE_SEND_WITH_IMM;
3038 swqe = (struct rdma_sq_send_wqe_1st *)wqe; 3043 swqe = (struct rdma_sq_send_wqe_1st *)wqe;
3039 swqe->wqe_size = 2; 3044 swqe->wqe_size = 2;
@@ -3075,6 +3080,11 @@ static int __qedr_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
3075 break; 3080 break;
3076 3081
3077 case IB_WR_RDMA_WRITE_WITH_IMM: 3082 case IB_WR_RDMA_WRITE_WITH_IMM:
3083 if (unlikely(rdma_protocol_iwarp(&dev->ibdev, 1))) {
3084 rc = -EINVAL;
3085 *bad_wr = wr;
3086 break;
3087 }
3078 wqe->req_type = RDMA_SQ_REQ_TYPE_RDMA_WR_WITH_IMM; 3088 wqe->req_type = RDMA_SQ_REQ_TYPE_RDMA_WR_WITH_IMM;
3079 rwqe = (struct rdma_sq_rdma_wqe_1st *)wqe; 3089 rwqe = (struct rdma_sq_rdma_wqe_1st *)wqe;
3080 3090
@@ -3724,7 +3734,7 @@ int qedr_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)
3724{ 3734{
3725 struct qedr_dev *dev = get_qedr_dev(ibcq->device); 3735 struct qedr_dev *dev = get_qedr_dev(ibcq->device);
3726 struct qedr_cq *cq = get_qedr_cq(ibcq); 3736 struct qedr_cq *cq = get_qedr_cq(ibcq);
3727 union rdma_cqe *cqe = cq->latest_cqe; 3737 union rdma_cqe *cqe;
3728 u32 old_cons, new_cons; 3738 u32 old_cons, new_cons;
3729 unsigned long flags; 3739 unsigned long flags;
3730 int update = 0; 3740 int update = 0;
@@ -3741,6 +3751,7 @@ int qedr_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)
3741 return qedr_gsi_poll_cq(ibcq, num_entries, wc); 3751 return qedr_gsi_poll_cq(ibcq, num_entries, wc);
3742 3752
3743 spin_lock_irqsave(&cq->cq_lock, flags); 3753 spin_lock_irqsave(&cq->cq_lock, flags);
3754 cqe = cq->latest_cqe;
3744 old_cons = qed_chain_get_cons_idx_u32(&cq->pbl); 3755 old_cons = qed_chain_get_cons_idx_u32(&cq->pbl);
3745 while (num_entries && is_valid_cqe(cq, cqe)) { 3756 while (num_entries && is_valid_cqe(cq, cqe)) {
3746 struct qedr_qp *qp; 3757 struct qedr_qp *qp;
diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c
index faa9478c14a6..f95b97646c25 100644
--- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c
+++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c
@@ -114,6 +114,7 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
114 union pvrdma_cmd_resp rsp; 114 union pvrdma_cmd_resp rsp;
115 struct pvrdma_cmd_create_cq *cmd = &req.create_cq; 115 struct pvrdma_cmd_create_cq *cmd = &req.create_cq;
116 struct pvrdma_cmd_create_cq_resp *resp = &rsp.create_cq_resp; 116 struct pvrdma_cmd_create_cq_resp *resp = &rsp.create_cq_resp;
117 struct pvrdma_create_cq_resp cq_resp = {0};
117 struct pvrdma_create_cq ucmd; 118 struct pvrdma_create_cq ucmd;
118 119
119 BUILD_BUG_ON(sizeof(struct pvrdma_cqe) != 64); 120 BUILD_BUG_ON(sizeof(struct pvrdma_cqe) != 64);
@@ -197,6 +198,7 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
197 198
198 cq->ibcq.cqe = resp->cqe; 199 cq->ibcq.cqe = resp->cqe;
199 cq->cq_handle = resp->cq_handle; 200 cq->cq_handle = resp->cq_handle;
201 cq_resp.cqn = resp->cq_handle;
200 spin_lock_irqsave(&dev->cq_tbl_lock, flags); 202 spin_lock_irqsave(&dev->cq_tbl_lock, flags);
201 dev->cq_tbl[cq->cq_handle % dev->dsr->caps.max_cq] = cq; 203 dev->cq_tbl[cq->cq_handle % dev->dsr->caps.max_cq] = cq;
202 spin_unlock_irqrestore(&dev->cq_tbl_lock, flags); 204 spin_unlock_irqrestore(&dev->cq_tbl_lock, flags);
@@ -205,7 +207,7 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
205 cq->uar = &(to_vucontext(context)->uar); 207 cq->uar = &(to_vucontext(context)->uar);
206 208
207 /* Copy udata back. */ 209 /* Copy udata back. */
208 if (ib_copy_to_udata(udata, &cq->cq_handle, sizeof(__u32))) { 210 if (ib_copy_to_udata(udata, &cq_resp, sizeof(cq_resp))) {
209 dev_warn(&dev->pdev->dev, 211 dev_warn(&dev->pdev->dev,
210 "failed to copy back udata\n"); 212 "failed to copy back udata\n");
211 pvrdma_destroy_cq(&cq->ibcq); 213 pvrdma_destroy_cq(&cq->ibcq);
diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c
index 5acebb1ef631..af235967a9c2 100644
--- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c
+++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c
@@ -113,6 +113,7 @@ struct ib_srq *pvrdma_create_srq(struct ib_pd *pd,
113 union pvrdma_cmd_resp rsp; 113 union pvrdma_cmd_resp rsp;
114 struct pvrdma_cmd_create_srq *cmd = &req.create_srq; 114 struct pvrdma_cmd_create_srq *cmd = &req.create_srq;
115 struct pvrdma_cmd_create_srq_resp *resp = &rsp.create_srq_resp; 115 struct pvrdma_cmd_create_srq_resp *resp = &rsp.create_srq_resp;
116 struct pvrdma_create_srq_resp srq_resp = {0};
116 struct pvrdma_create_srq ucmd; 117 struct pvrdma_create_srq ucmd;
117 unsigned long flags; 118 unsigned long flags;
118 int ret; 119 int ret;
@@ -204,12 +205,13 @@ struct ib_srq *pvrdma_create_srq(struct ib_pd *pd,
204 } 205 }
205 206
206 srq->srq_handle = resp->srqn; 207 srq->srq_handle = resp->srqn;
208 srq_resp.srqn = resp->srqn;
207 spin_lock_irqsave(&dev->srq_tbl_lock, flags); 209 spin_lock_irqsave(&dev->srq_tbl_lock, flags);
208 dev->srq_tbl[srq->srq_handle % dev->dsr->caps.max_srq] = srq; 210 dev->srq_tbl[srq->srq_handle % dev->dsr->caps.max_srq] = srq;
209 spin_unlock_irqrestore(&dev->srq_tbl_lock, flags); 211 spin_unlock_irqrestore(&dev->srq_tbl_lock, flags);
210 212
211 /* Copy udata back. */ 213 /* Copy udata back. */
212 if (ib_copy_to_udata(udata, &srq->srq_handle, sizeof(__u32))) { 214 if (ib_copy_to_udata(udata, &srq_resp, sizeof(srq_resp))) {
213 dev_warn(&dev->pdev->dev, "failed to copy back udata\n"); 215 dev_warn(&dev->pdev->dev, "failed to copy back udata\n");
214 pvrdma_destroy_srq(&srq->ibsrq); 216 pvrdma_destroy_srq(&srq->ibsrq);
215 return ERR_PTR(-EINVAL); 217 return ERR_PTR(-EINVAL);
diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c
index 16b96616ef7e..a51463cd2f37 100644
--- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c
+++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c
@@ -447,6 +447,7 @@ struct ib_pd *pvrdma_alloc_pd(struct ib_device *ibdev,
447 union pvrdma_cmd_resp rsp; 447 union pvrdma_cmd_resp rsp;
448 struct pvrdma_cmd_create_pd *cmd = &req.create_pd; 448 struct pvrdma_cmd_create_pd *cmd = &req.create_pd;
449 struct pvrdma_cmd_create_pd_resp *resp = &rsp.create_pd_resp; 449 struct pvrdma_cmd_create_pd_resp *resp = &rsp.create_pd_resp;
450 struct pvrdma_alloc_pd_resp pd_resp = {0};
450 int ret; 451 int ret;
451 void *ptr; 452 void *ptr;
452 453
@@ -475,9 +476,10 @@ struct ib_pd *pvrdma_alloc_pd(struct ib_device *ibdev,
475 pd->privileged = !context; 476 pd->privileged = !context;
476 pd->pd_handle = resp->pd_handle; 477 pd->pd_handle = resp->pd_handle;
477 pd->pdn = resp->pd_handle; 478 pd->pdn = resp->pd_handle;
479 pd_resp.pdn = resp->pd_handle;
478 480
479 if (context) { 481 if (context) {
480 if (ib_copy_to_udata(udata, &pd->pdn, sizeof(__u32))) { 482 if (ib_copy_to_udata(udata, &pd_resp, sizeof(pd_resp))) {
481 dev_warn(&dev->pdev->dev, 483 dev_warn(&dev->pdev->dev,
482 "failed to copy back protection domain\n"); 484 "failed to copy back protection domain\n");
483 pvrdma_dealloc_pd(&pd->ibpd); 485 pvrdma_dealloc_pd(&pd->ibpd);
diff --git a/drivers/infiniband/sw/rdmavt/mr.c b/drivers/infiniband/sw/rdmavt/mr.c
index 1b2e5362a3ff..cc429b567d0a 100644
--- a/drivers/infiniband/sw/rdmavt/mr.c
+++ b/drivers/infiniband/sw/rdmavt/mr.c
@@ -489,11 +489,13 @@ static int rvt_check_refs(struct rvt_mregion *mr, const char *t)
489 unsigned long timeout; 489 unsigned long timeout;
490 struct rvt_dev_info *rdi = ib_to_rvt(mr->pd->device); 490 struct rvt_dev_info *rdi = ib_to_rvt(mr->pd->device);
491 491
492 if (percpu_ref_is_zero(&mr->refcount)) 492 if (mr->lkey) {
493 return 0; 493 /* avoid dma mr */
494 /* avoid dma mr */
495 if (mr->lkey)
496 rvt_dereg_clean_qps(mr); 494 rvt_dereg_clean_qps(mr);
495 /* @mr was indexed on rcu protected @lkey_table */
496 synchronize_rcu();
497 }
498
497 timeout = wait_for_completion_timeout(&mr->comp, 5 * HZ); 499 timeout = wait_for_completion_timeout(&mr->comp, 5 * HZ);
498 if (!timeout) { 500 if (!timeout) {
499 rvt_pr_err(rdi, 501 rvt_pr_err(rdi,
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_fs.c b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
index 11f74cbe6660..ea302b054601 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_fs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
@@ -281,8 +281,6 @@ void ipoib_delete_debug_files(struct net_device *dev)
281{ 281{
282 struct ipoib_dev_priv *priv = ipoib_priv(dev); 282 struct ipoib_dev_priv *priv = ipoib_priv(dev);
283 283
284 WARN_ONCE(!priv->mcg_dentry, "null mcg debug file\n");
285 WARN_ONCE(!priv->path_dentry, "null path debug file\n");
286 debugfs_remove(priv->mcg_dentry); 284 debugfs_remove(priv->mcg_dentry);
287 debugfs_remove(priv->path_dentry); 285 debugfs_remove(priv->path_dentry);
288 priv->mcg_dentry = priv->path_dentry = NULL; 286 priv->mcg_dentry = priv->path_dentry = NULL;
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index 1f316d66e6f7..41614c185918 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -218,8 +218,10 @@ static void matrix_keypad_stop(struct input_dev *dev)
218{ 218{
219 struct matrix_keypad *keypad = input_get_drvdata(dev); 219 struct matrix_keypad *keypad = input_get_drvdata(dev);
220 220
221 spin_lock_irq(&keypad->lock);
221 keypad->stopped = true; 222 keypad->stopped = true;
222 mb(); 223 spin_unlock_irq(&keypad->lock);
224
223 flush_work(&keypad->work.work); 225 flush_work(&keypad->work.work);
224 /* 226 /*
225 * matrix_keypad_scan() will leave IRQs enabled; 227 * matrix_keypad_scan() will leave IRQs enabled;
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 3d2e23a0ae39..a246fc686bb7 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -173,7 +173,6 @@ static const char * const smbus_pnp_ids[] = {
173 "LEN0046", /* X250 */ 173 "LEN0046", /* X250 */
174 "LEN004a", /* W541 */ 174 "LEN004a", /* W541 */
175 "LEN200f", /* T450s */ 175 "LEN200f", /* T450s */
176 "LEN2018", /* T460p */
177 NULL 176 NULL
178}; 177};
179 178
diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c
index db4f6bb502e3..a5ab774da4cc 100644
--- a/drivers/input/touchscreen/mms114.c
+++ b/drivers/input/touchscreen/mms114.c
@@ -1,11 +1,8 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012 Samsung Electronics Co.Ltd 2// Melfas MMS114/MMS152 touchscreen device driver
3 * Author: Joonyoung Shim <jy0922.shim@samsung.com> 3//
4 * 4// Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * This program is free software; you can redistribute it and/or modify 5// Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9 6
10#include <linux/module.h> 7#include <linux/module.h>
11#include <linux/delay.h> 8#include <linux/delay.h>
@@ -624,4 +621,4 @@ module_i2c_driver(mms114_driver);
624/* Module information */ 621/* Module information */
625MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); 622MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
626MODULE_DESCRIPTION("MELFAS mms114 Touchscreen driver"); 623MODULE_DESCRIPTION("MELFAS mms114 Touchscreen driver");
627MODULE_LICENSE("GPL"); 624MODULE_LICENSE("GPL v2");
diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c
index 35a408d0ae4f..99bc9bd64b9e 100644
--- a/drivers/iommu/intel-svm.c
+++ b/drivers/iommu/intel-svm.c
@@ -205,7 +205,7 @@ static void intel_flush_svm_range_dev (struct intel_svm *svm, struct intel_svm_d
205 * for example, an "address" value of 0x12345f000 will 205 * for example, an "address" value of 0x12345f000 will
206 * flush from 0x123440000 to 0x12347ffff (256KiB). */ 206 * flush from 0x123440000 to 0x12347ffff (256KiB). */
207 unsigned long last = address + ((unsigned long)(pages - 1) << VTD_PAGE_SHIFT); 207 unsigned long last = address + ((unsigned long)(pages - 1) << VTD_PAGE_SHIFT);
208 unsigned long mask = __rounddown_pow_of_two(address ^ last);; 208 unsigned long mask = __rounddown_pow_of_two(address ^ last);
209 209
210 desc.high = QI_DEV_EIOTLB_ADDR((address & ~mask) | (mask - 1)) | QI_DEV_EIOTLB_SIZE; 210 desc.high = QI_DEV_EIOTLB_ADDR((address & ~mask) | (mask - 1)) | QI_DEV_EIOTLB_SIZE;
211 } else { 211 } else {
diff --git a/drivers/irqchip/irq-bcm7038-l1.c b/drivers/irqchip/irq-bcm7038-l1.c
index 55cfb986225b..faf734ff4cf3 100644
--- a/drivers/irqchip/irq-bcm7038-l1.c
+++ b/drivers/irqchip/irq-bcm7038-l1.c
@@ -339,9 +339,6 @@ int __init bcm7038_l1_of_init(struct device_node *dn,
339 goto out_unmap; 339 goto out_unmap;
340 } 340 }
341 341
342 pr_info("registered BCM7038 L1 intc (mem: 0x%p, IRQs: %d)\n",
343 intc->cpus[0]->map_base, IRQS_PER_WORD * intc->n_words);
344
345 return 0; 342 return 0;
346 343
347out_unmap: 344out_unmap:
diff --git a/drivers/irqchip/irq-bcm7120-l2.c b/drivers/irqchip/irq-bcm7120-l2.c
index 983640eba418..8968e5e93fcb 100644
--- a/drivers/irqchip/irq-bcm7120-l2.c
+++ b/drivers/irqchip/irq-bcm7120-l2.c
@@ -318,9 +318,6 @@ static int __init bcm7120_l2_intc_probe(struct device_node *dn,
318 } 318 }
319 } 319 }
320 320
321 pr_info("registered %s intc (mem: 0x%p, parent IRQ(s): %d)\n",
322 intc_name, data->map_base[0], data->num_parent_irqs);
323
324 return 0; 321 return 0;
325 322
326out_free_domain: 323out_free_domain:
diff --git a/drivers/irqchip/irq-brcmstb-l2.c b/drivers/irqchip/irq-brcmstb-l2.c
index 691d20eb0bec..0e65f609352e 100644
--- a/drivers/irqchip/irq-brcmstb-l2.c
+++ b/drivers/irqchip/irq-brcmstb-l2.c
@@ -262,9 +262,6 @@ static int __init brcmstb_l2_intc_of_init(struct device_node *np,
262 ct->chip.irq_set_wake = irq_gc_set_wake; 262 ct->chip.irq_set_wake = irq_gc_set_wake;
263 } 263 }
264 264
265 pr_info("registered L2 intc (mem: 0x%p, parent irq: %d)\n",
266 base, parent_irq);
267
268 return 0; 265 return 0;
269 266
270out_free_domain: 267out_free_domain:
diff --git a/drivers/irqchip/irq-gic-v2m.c b/drivers/irqchip/irq-gic-v2m.c
index 993a8426a453..1ff38aff9f29 100644
--- a/drivers/irqchip/irq-gic-v2m.c
+++ b/drivers/irqchip/irq-gic-v2m.c
@@ -94,7 +94,7 @@ static struct irq_chip gicv2m_msi_irq_chip = {
94 94
95static struct msi_domain_info gicv2m_msi_domain_info = { 95static struct msi_domain_info gicv2m_msi_domain_info = {
96 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | 96 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
97 MSI_FLAG_PCI_MSIX), 97 MSI_FLAG_PCI_MSIX | MSI_FLAG_MULTI_PCI_MSI),
98 .chip = &gicv2m_msi_irq_chip, 98 .chip = &gicv2m_msi_irq_chip,
99}; 99};
100 100
@@ -155,18 +155,12 @@ static int gicv2m_irq_gic_domain_alloc(struct irq_domain *domain,
155 return 0; 155 return 0;
156} 156}
157 157
158static void gicv2m_unalloc_msi(struct v2m_data *v2m, unsigned int hwirq) 158static void gicv2m_unalloc_msi(struct v2m_data *v2m, unsigned int hwirq,
159 int nr_irqs)
159{ 160{
160 int pos;
161
162 pos = hwirq - v2m->spi_start;
163 if (pos < 0 || pos >= v2m->nr_spis) {
164 pr_err("Failed to teardown msi. Invalid hwirq %d\n", hwirq);
165 return;
166 }
167
168 spin_lock(&v2m_lock); 161 spin_lock(&v2m_lock);
169 __clear_bit(pos, v2m->bm); 162 bitmap_release_region(v2m->bm, hwirq - v2m->spi_start,
163 get_count_order(nr_irqs));
170 spin_unlock(&v2m_lock); 164 spin_unlock(&v2m_lock);
171} 165}
172 166
@@ -174,13 +168,13 @@ static int gicv2m_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
174 unsigned int nr_irqs, void *args) 168 unsigned int nr_irqs, void *args)
175{ 169{
176 struct v2m_data *v2m = NULL, *tmp; 170 struct v2m_data *v2m = NULL, *tmp;
177 int hwirq, offset, err = 0; 171 int hwirq, offset, i, err = 0;
178 172
179 spin_lock(&v2m_lock); 173 spin_lock(&v2m_lock);
180 list_for_each_entry(tmp, &v2m_nodes, entry) { 174 list_for_each_entry(tmp, &v2m_nodes, entry) {
181 offset = find_first_zero_bit(tmp->bm, tmp->nr_spis); 175 offset = bitmap_find_free_region(tmp->bm, tmp->nr_spis,
182 if (offset < tmp->nr_spis) { 176 get_count_order(nr_irqs));
183 __set_bit(offset, tmp->bm); 177 if (offset >= 0) {
184 v2m = tmp; 178 v2m = tmp;
185 break; 179 break;
186 } 180 }
@@ -192,16 +186,21 @@ static int gicv2m_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
192 186
193 hwirq = v2m->spi_start + offset; 187 hwirq = v2m->spi_start + offset;
194 188
195 err = gicv2m_irq_gic_domain_alloc(domain, virq, hwirq); 189 for (i = 0; i < nr_irqs; i++) {
196 if (err) { 190 err = gicv2m_irq_gic_domain_alloc(domain, virq + i, hwirq + i);
197 gicv2m_unalloc_msi(v2m, hwirq); 191 if (err)
198 return err; 192 goto fail;
199 }
200 193
201 irq_domain_set_hwirq_and_chip(domain, virq, hwirq, 194 irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
202 &gicv2m_irq_chip, v2m); 195 &gicv2m_irq_chip, v2m);
196 }
203 197
204 return 0; 198 return 0;
199
200fail:
201 irq_domain_free_irqs_parent(domain, virq, nr_irqs);
202 gicv2m_unalloc_msi(v2m, hwirq, get_count_order(nr_irqs));
203 return err;
205} 204}
206 205
207static void gicv2m_irq_domain_free(struct irq_domain *domain, 206static void gicv2m_irq_domain_free(struct irq_domain *domain,
@@ -210,8 +209,7 @@ static void gicv2m_irq_domain_free(struct irq_domain *domain,
210 struct irq_data *d = irq_domain_get_irq_data(domain, virq); 209 struct irq_data *d = irq_domain_get_irq_data(domain, virq);
211 struct v2m_data *v2m = irq_data_get_irq_chip_data(d); 210 struct v2m_data *v2m = irq_data_get_irq_chip_data(d);
212 211
213 BUG_ON(nr_irqs != 1); 212 gicv2m_unalloc_msi(v2m, d->hwirq, nr_irqs);
214 gicv2m_unalloc_msi(v2m, d->hwirq);
215 irq_domain_free_irqs_parent(domain, virq, nr_irqs); 213 irq_domain_free_irqs_parent(domain, virq, nr_irqs);
216} 214}
217 215
diff --git a/drivers/irqchip/irq-gic-v3-its-pci-msi.c b/drivers/irqchip/irq-gic-v3-its-pci-msi.c
index 14a8c0a7e095..25a98de5cfb2 100644
--- a/drivers/irqchip/irq-gic-v3-its-pci-msi.c
+++ b/drivers/irqchip/irq-gic-v3-its-pci-msi.c
@@ -132,6 +132,8 @@ static int __init its_pci_of_msi_init(void)
132 132
133 for (np = of_find_matching_node(NULL, its_device_id); np; 133 for (np = of_find_matching_node(NULL, its_device_id); np;
134 np = of_find_matching_node(np, its_device_id)) { 134 np = of_find_matching_node(np, its_device_id)) {
135 if (!of_device_is_available(np))
136 continue;
135 if (!of_property_read_bool(np, "msi-controller")) 137 if (!of_property_read_bool(np, "msi-controller"))
136 continue; 138 continue;
137 139
diff --git a/drivers/irqchip/irq-gic-v3-its-platform-msi.c b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
index 833a90fe33ae..8881a053c173 100644
--- a/drivers/irqchip/irq-gic-v3-its-platform-msi.c
+++ b/drivers/irqchip/irq-gic-v3-its-platform-msi.c
@@ -154,6 +154,8 @@ static void __init its_pmsi_of_init(void)
154 154
155 for (np = of_find_matching_node(NULL, its_device_id); np; 155 for (np = of_find_matching_node(NULL, its_device_id); np;
156 np = of_find_matching_node(np, its_device_id)) { 156 np = of_find_matching_node(np, its_device_id)) {
157 if (!of_device_is_available(np))
158 continue;
157 if (!of_property_read_bool(np, "msi-controller")) 159 if (!of_property_read_bool(np, "msi-controller"))
158 continue; 160 continue;
159 161
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 06f025fd5726..2cbb19cddbf8 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1412,7 +1412,7 @@ static struct irq_chip its_irq_chip = {
1412 * This gives us (((1UL << id_bits) - 8192) >> 5) possible allocations. 1412 * This gives us (((1UL << id_bits) - 8192) >> 5) possible allocations.
1413 */ 1413 */
1414#define IRQS_PER_CHUNK_SHIFT 5 1414#define IRQS_PER_CHUNK_SHIFT 5
1415#define IRQS_PER_CHUNK (1 << IRQS_PER_CHUNK_SHIFT) 1415#define IRQS_PER_CHUNK (1UL << IRQS_PER_CHUNK_SHIFT)
1416#define ITS_MAX_LPI_NRBITS 16 /* 64K LPIs */ 1416#define ITS_MAX_LPI_NRBITS 16 /* 64K LPIs */
1417 1417
1418static unsigned long *lpi_bitmap; 1418static unsigned long *lpi_bitmap;
@@ -2119,11 +2119,10 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,
2119 2119
2120 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 2120 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2121 /* 2121 /*
2122 * At least one bit of EventID is being used, hence a minimum 2122 * We allocate at least one chunk worth of LPIs bet device,
2123 * of two entries. No, the architecture doesn't let you 2123 * and thus that many ITEs. The device may require less though.
2124 * express an ITT with a single entry.
2125 */ 2124 */
2126 nr_ites = max(2UL, roundup_pow_of_two(nvecs)); 2125 nr_ites = max(IRQS_PER_CHUNK, roundup_pow_of_two(nvecs));
2127 sz = nr_ites * its->ite_size; 2126 sz = nr_ites * its->ite_size;
2128 sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1; 2127 sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1;
2129 itt = kzalloc(sz, GFP_KERNEL); 2128 itt = kzalloc(sz, GFP_KERNEL);
@@ -2495,7 +2494,7 @@ static int its_vpe_set_affinity(struct irq_data *d,
2495 2494
2496static void its_vpe_schedule(struct its_vpe *vpe) 2495static void its_vpe_schedule(struct its_vpe *vpe)
2497{ 2496{
2498 void * __iomem vlpi_base = gic_data_rdist_vlpi_base(); 2497 void __iomem *vlpi_base = gic_data_rdist_vlpi_base();
2499 u64 val; 2498 u64 val;
2500 2499
2501 /* Schedule the VPE */ 2500 /* Schedule the VPE */
@@ -2527,7 +2526,7 @@ static void its_vpe_schedule(struct its_vpe *vpe)
2527 2526
2528static void its_vpe_deschedule(struct its_vpe *vpe) 2527static void its_vpe_deschedule(struct its_vpe *vpe)
2529{ 2528{
2530 void * __iomem vlpi_base = gic_data_rdist_vlpi_base(); 2529 void __iomem *vlpi_base = gic_data_rdist_vlpi_base();
2531 u32 count = 1000000; /* 1s! */ 2530 u32 count = 1000000; /* 1s! */
2532 bool clean; 2531 bool clean;
2533 u64 val; 2532 u64 val;
@@ -3314,6 +3313,8 @@ static int __init its_of_probe(struct device_node *node)
3314 3313
3315 for (np = of_find_matching_node(node, its_device_id); np; 3314 for (np = of_find_matching_node(node, its_device_id); np;
3316 np = of_find_matching_node(np, its_device_id)) { 3315 np = of_find_matching_node(np, its_device_id)) {
3316 if (!of_device_is_available(np))
3317 continue;
3317 if (!of_property_read_bool(np, "msi-controller")) { 3318 if (!of_property_read_bool(np, "msi-controller")) {
3318 pr_warn("%pOF: no msi-controller property, ITS ignored\n", 3319 pr_warn("%pOF: no msi-controller property, ITS ignored\n",
3319 np); 3320 np);
diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c
index a57c0fbbd34a..d99cc07903ec 100644
--- a/drivers/irqchip/irq-gic-v3.c
+++ b/drivers/irqchip/irq-gic-v3.c
@@ -673,7 +673,7 @@ static void gic_send_sgi(u64 cluster_id, u16 tlist, unsigned int irq)
673 MPIDR_TO_SGI_RS(cluster_id) | 673 MPIDR_TO_SGI_RS(cluster_id) |
674 tlist << ICC_SGI1R_TARGET_LIST_SHIFT); 674 tlist << ICC_SGI1R_TARGET_LIST_SHIFT);
675 675
676 pr_debug("CPU%d: ICC_SGI1R_EL1 %llx\n", smp_processor_id(), val); 676 pr_devel("CPU%d: ICC_SGI1R_EL1 %llx\n", smp_processor_id(), val);
677 gic_write_sgi1r(val); 677 gic_write_sgi1r(val);
678} 678}
679 679
@@ -688,7 +688,7 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
688 * Ensure that stores to Normal memory are visible to the 688 * Ensure that stores to Normal memory are visible to the
689 * other CPUs before issuing the IPI. 689 * other CPUs before issuing the IPI.
690 */ 690 */
691 smp_wmb(); 691 wmb();
692 692
693 for_each_cpu(cpu, mask) { 693 for_each_cpu(cpu, mask) {
694 u64 cluster_id = MPIDR_TO_SGI_CLUSTER_ID(cpu_logical_map(cpu)); 694 u64 cluster_id = MPIDR_TO_SGI_CLUSTER_ID(cpu_logical_map(cpu));
diff --git a/drivers/irqchip/irq-imx-gpcv2.c b/drivers/irqchip/irq-imx-gpcv2.c
index 675eda5ff2b8..4760307ab43f 100644
--- a/drivers/irqchip/irq-imx-gpcv2.c
+++ b/drivers/irqchip/irq-imx-gpcv2.c
@@ -28,20 +28,6 @@ struct gpcv2_irqchip_data {
28 28
29static struct gpcv2_irqchip_data *imx_gpcv2_instance; 29static struct gpcv2_irqchip_data *imx_gpcv2_instance;
30 30
31/*
32 * Interface for the low level wakeup code.
33 */
34u32 imx_gpcv2_get_wakeup_source(u32 **sources)
35{
36 if (!imx_gpcv2_instance)
37 return 0;
38
39 if (sources)
40 *sources = imx_gpcv2_instance->wakeup_sources;
41
42 return IMR_NUM;
43}
44
45static int gpcv2_wakeup_source_save(void) 31static int gpcv2_wakeup_source_save(void)
46{ 32{
47 struct gpcv2_irqchip_data *cd; 33 struct gpcv2_irqchip_data *cd;
diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index ef92a4d2038e..d32268cc1174 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -424,8 +424,6 @@ static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq,
424 spin_lock_irqsave(&gic_lock, flags); 424 spin_lock_irqsave(&gic_lock, flags);
425 write_gic_map_pin(intr, GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin); 425 write_gic_map_pin(intr, GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin);
426 write_gic_map_vp(intr, BIT(mips_cm_vp_id(cpu))); 426 write_gic_map_vp(intr, BIT(mips_cm_vp_id(cpu)));
427 gic_clear_pcpu_masks(intr);
428 set_bit(intr, per_cpu_ptr(pcpu_masks, cpu));
429 irq_data_update_effective_affinity(data, cpumask_of(cpu)); 427 irq_data_update_effective_affinity(data, cpumask_of(cpu));
430 spin_unlock_irqrestore(&gic_lock, flags); 428 spin_unlock_irqrestore(&gic_lock, flags);
431 429
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 62f541f968f6..07074820a167 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -375,6 +375,7 @@ static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
375 dev->ofdev.dev.of_node = np; 375 dev->ofdev.dev.of_node = np;
376 dev->ofdev.archdata.dma_mask = 0xffffffffUL; 376 dev->ofdev.archdata.dma_mask = 0xffffffffUL;
377 dev->ofdev.dev.dma_mask = &dev->ofdev.archdata.dma_mask; 377 dev->ofdev.dev.dma_mask = &dev->ofdev.archdata.dma_mask;
378 dev->ofdev.dev.coherent_dma_mask = dev->ofdev.archdata.dma_mask;
378 dev->ofdev.dev.parent = parent; 379 dev->ofdev.dev.parent = parent;
379 dev->ofdev.dev.bus = &macio_bus_type; 380 dev->ofdev.dev.bus = &macio_bus_type;
380 dev->ofdev.dev.release = macio_release_dev; 381 dev->ofdev.dev.release = macio_release_dev;
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index 1a46b41dac70..6422846b546e 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -659,11 +659,11 @@ static void do_bio_hook(struct search *s, struct bio *orig_bio)
659static void search_free(struct closure *cl) 659static void search_free(struct closure *cl)
660{ 660{
661 struct search *s = container_of(cl, struct search, cl); 661 struct search *s = container_of(cl, struct search, cl);
662 bio_complete(s);
663 662
664 if (s->iop.bio) 663 if (s->iop.bio)
665 bio_put(s->iop.bio); 664 bio_put(s->iop.bio);
666 665
666 bio_complete(s);
667 closure_debug_destroy(cl); 667 closure_debug_destroy(cl);
668 mempool_free(s, s->d->c->search); 668 mempool_free(s, s->d->c->search);
669} 669}
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 312895788036..f2273143b3cb 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -963,6 +963,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,
963 uint32_t rtime = cpu_to_le32(get_seconds()); 963 uint32_t rtime = cpu_to_le32(get_seconds());
964 struct uuid_entry *u; 964 struct uuid_entry *u;
965 char buf[BDEVNAME_SIZE]; 965 char buf[BDEVNAME_SIZE];
966 struct cached_dev *exist_dc, *t;
966 967
967 bdevname(dc->bdev, buf); 968 bdevname(dc->bdev, buf);
968 969
@@ -987,6 +988,16 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,
987 return -EINVAL; 988 return -EINVAL;
988 } 989 }
989 990
991 /* Check whether already attached */
992 list_for_each_entry_safe(exist_dc, t, &c->cached_devs, list) {
993 if (!memcmp(dc->sb.uuid, exist_dc->sb.uuid, 16)) {
994 pr_err("Tried to attach %s but duplicate UUID already attached",
995 buf);
996
997 return -EINVAL;
998 }
999 }
1000
990 u = uuid_find(c, dc->sb.uuid); 1001 u = uuid_find(c, dc->sb.uuid);
991 1002
992 if (u && 1003 if (u &&
@@ -1204,7 +1215,7 @@ static void register_bdev(struct cache_sb *sb, struct page *sb_page,
1204 1215
1205 return; 1216 return;
1206err: 1217err:
1207 pr_notice("error opening %s: %s", bdevname(bdev, name), err); 1218 pr_notice("error %s: %s", bdevname(bdev, name), err);
1208 bcache_device_stop(&dc->disk); 1219 bcache_device_stop(&dc->disk);
1209} 1220}
1210 1221
@@ -1274,7 +1285,7 @@ static int flash_devs_run(struct cache_set *c)
1274 struct uuid_entry *u; 1285 struct uuid_entry *u;
1275 1286
1276 for (u = c->uuids; 1287 for (u = c->uuids;
1277 u < c->uuids + c->devices_max_used && !ret; 1288 u < c->uuids + c->nr_uuids && !ret;
1278 u++) 1289 u++)
1279 if (UUID_FLASH_ONLY(u)) 1290 if (UUID_FLASH_ONLY(u))
1280 ret = flash_dev_run(c, u); 1291 ret = flash_dev_run(c, u);
@@ -1883,6 +1894,8 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
1883 const char *err = NULL; /* must be set for any error case */ 1894 const char *err = NULL; /* must be set for any error case */
1884 int ret = 0; 1895 int ret = 0;
1885 1896
1897 bdevname(bdev, name);
1898
1886 memcpy(&ca->sb, sb, sizeof(struct cache_sb)); 1899 memcpy(&ca->sb, sb, sizeof(struct cache_sb));
1887 ca->bdev = bdev; 1900 ca->bdev = bdev;
1888 ca->bdev->bd_holder = ca; 1901 ca->bdev->bd_holder = ca;
@@ -1891,11 +1904,12 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
1891 bio_first_bvec_all(&ca->sb_bio)->bv_page = sb_page; 1904 bio_first_bvec_all(&ca->sb_bio)->bv_page = sb_page;
1892 get_page(sb_page); 1905 get_page(sb_page);
1893 1906
1894 if (blk_queue_discard(bdev_get_queue(ca->bdev))) 1907 if (blk_queue_discard(bdev_get_queue(bdev)))
1895 ca->discard = CACHE_DISCARD(&ca->sb); 1908 ca->discard = CACHE_DISCARD(&ca->sb);
1896 1909
1897 ret = cache_alloc(ca); 1910 ret = cache_alloc(ca);
1898 if (ret != 0) { 1911 if (ret != 0) {
1912 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1899 if (ret == -ENOMEM) 1913 if (ret == -ENOMEM)
1900 err = "cache_alloc(): -ENOMEM"; 1914 err = "cache_alloc(): -ENOMEM";
1901 else 1915 else
@@ -1918,14 +1932,14 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
1918 goto out; 1932 goto out;
1919 } 1933 }
1920 1934
1921 pr_info("registered cache device %s", bdevname(bdev, name)); 1935 pr_info("registered cache device %s", name);
1922 1936
1923out: 1937out:
1924 kobject_put(&ca->kobj); 1938 kobject_put(&ca->kobj);
1925 1939
1926err: 1940err:
1927 if (err) 1941 if (err)
1928 pr_notice("error opening %s: %s", bdevname(bdev, name), err); 1942 pr_notice("error %s: %s", name, err);
1929 1943
1930 return ret; 1944 return ret;
1931} 1945}
@@ -2014,6 +2028,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
2014 if (err) 2028 if (err)
2015 goto err_close; 2029 goto err_close;
2016 2030
2031 err = "failed to register device";
2017 if (SB_IS_BDEV(sb)) { 2032 if (SB_IS_BDEV(sb)) {
2018 struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL); 2033 struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
2019 if (!dc) 2034 if (!dc)
@@ -2028,7 +2043,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
2028 goto err_close; 2043 goto err_close;
2029 2044
2030 if (register_cache(sb, sb_page, bdev, ca) != 0) 2045 if (register_cache(sb, sb_page, bdev, ca) != 0)
2031 goto err_close; 2046 goto err;
2032 } 2047 }
2033out: 2048out:
2034 if (sb_page) 2049 if (sb_page)
@@ -2041,7 +2056,7 @@ out:
2041err_close: 2056err_close:
2042 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); 2057 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
2043err: 2058err:
2044 pr_info("error opening %s: %s", path, err); 2059 pr_info("error %s: %s", path, err);
2045 ret = -EINVAL; 2060 ret = -EINVAL;
2046 goto out; 2061 goto out;
2047} 2062}
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 414c9af54ded..aa2032fa80d4 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -386,9 +386,6 @@ static void __cache_size_refresh(void)
386static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask, 386static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask,
387 enum data_mode *data_mode) 387 enum data_mode *data_mode)
388{ 388{
389 unsigned noio_flag;
390 void *ptr;
391
392 if (c->block_size <= DM_BUFIO_BLOCK_SIZE_SLAB_LIMIT) { 389 if (c->block_size <= DM_BUFIO_BLOCK_SIZE_SLAB_LIMIT) {
393 *data_mode = DATA_MODE_SLAB; 390 *data_mode = DATA_MODE_SLAB;
394 return kmem_cache_alloc(DM_BUFIO_CACHE(c), gfp_mask); 391 return kmem_cache_alloc(DM_BUFIO_CACHE(c), gfp_mask);
@@ -412,16 +409,15 @@ static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask,
412 * all allocations done by this process (including pagetables) are done 409 * all allocations done by this process (including pagetables) are done
413 * as if GFP_NOIO was specified. 410 * as if GFP_NOIO was specified.
414 */ 411 */
412 if (gfp_mask & __GFP_NORETRY) {
413 unsigned noio_flag = memalloc_noio_save();
414 void *ptr = __vmalloc(c->block_size, gfp_mask, PAGE_KERNEL);
415 415
416 if (gfp_mask & __GFP_NORETRY)
417 noio_flag = memalloc_noio_save();
418
419 ptr = __vmalloc(c->block_size, gfp_mask, PAGE_KERNEL);
420
421 if (gfp_mask & __GFP_NORETRY)
422 memalloc_noio_restore(noio_flag); 416 memalloc_noio_restore(noio_flag);
417 return ptr;
418 }
423 419
424 return ptr; 420 return __vmalloc(c->block_size, gfp_mask, PAGE_KERNEL);
425} 421}
426 422
427/* 423/*
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 7d3e572072f5..a05a560d3cba 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -211,29 +211,27 @@ static int alloc_multipath_stage2(struct dm_target *ti, struct multipath *m)
211 else 211 else
212 m->queue_mode = DM_TYPE_REQUEST_BASED; 212 m->queue_mode = DM_TYPE_REQUEST_BASED;
213 213
214 } else if (m->queue_mode == DM_TYPE_BIO_BASED || 214 } else if (m->queue_mode == DM_TYPE_BIO_BASED) {
215 m->queue_mode == DM_TYPE_NVME_BIO_BASED) {
216 INIT_WORK(&m->process_queued_bios, process_queued_bios); 215 INIT_WORK(&m->process_queued_bios, process_queued_bios);
217 216 /*
218 if (m->queue_mode == DM_TYPE_BIO_BASED) { 217 * bio-based doesn't support any direct scsi_dh management;
219 /* 218 * it just discovers if a scsi_dh is attached.
220 * bio-based doesn't support any direct scsi_dh management; 219 */
221 * it just discovers if a scsi_dh is attached. 220 set_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, &m->flags);
222 */
223 set_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, &m->flags);
224 }
225 }
226
227 if (m->queue_mode != DM_TYPE_NVME_BIO_BASED) {
228 set_bit(MPATHF_QUEUE_IO, &m->flags);
229 atomic_set(&m->pg_init_in_progress, 0);
230 atomic_set(&m->pg_init_count, 0);
231 m->pg_init_delay_msecs = DM_PG_INIT_DELAY_DEFAULT;
232 init_waitqueue_head(&m->pg_init_wait);
233 } 221 }
234 222
235 dm_table_set_type(ti->table, m->queue_mode); 223 dm_table_set_type(ti->table, m->queue_mode);
236 224
225 /*
226 * Init fields that are only used when a scsi_dh is attached
227 * - must do this unconditionally (really doesn't hurt non-SCSI uses)
228 */
229 set_bit(MPATHF_QUEUE_IO, &m->flags);
230 atomic_set(&m->pg_init_in_progress, 0);
231 atomic_set(&m->pg_init_count, 0);
232 m->pg_init_delay_msecs = DM_PG_INIT_DELAY_DEFAULT;
233 init_waitqueue_head(&m->pg_init_wait);
234
237 return 0; 235 return 0;
238} 236}
239 237
@@ -337,9 +335,6 @@ static void __switch_pg(struct multipath *m, struct priority_group *pg)
337{ 335{
338 m->current_pg = pg; 336 m->current_pg = pg;
339 337
340 if (m->queue_mode == DM_TYPE_NVME_BIO_BASED)
341 return;
342
343 /* Must we initialise the PG first, and queue I/O till it's ready? */ 338 /* Must we initialise the PG first, and queue I/O till it's ready? */
344 if (m->hw_handler_name) { 339 if (m->hw_handler_name) {
345 set_bit(MPATHF_PG_INIT_REQUIRED, &m->flags); 340 set_bit(MPATHF_PG_INIT_REQUIRED, &m->flags);
@@ -385,8 +380,7 @@ static struct pgpath *choose_pgpath(struct multipath *m, size_t nr_bytes)
385 unsigned bypassed = 1; 380 unsigned bypassed = 1;
386 381
387 if (!atomic_read(&m->nr_valid_paths)) { 382 if (!atomic_read(&m->nr_valid_paths)) {
388 if (m->queue_mode != DM_TYPE_NVME_BIO_BASED) 383 clear_bit(MPATHF_QUEUE_IO, &m->flags);
389 clear_bit(MPATHF_QUEUE_IO, &m->flags);
390 goto failed; 384 goto failed;
391 } 385 }
392 386
@@ -599,7 +593,7 @@ static struct pgpath *__map_bio(struct multipath *m, struct bio *bio)
599 return pgpath; 593 return pgpath;
600} 594}
601 595
602static struct pgpath *__map_bio_nvme(struct multipath *m, struct bio *bio) 596static struct pgpath *__map_bio_fast(struct multipath *m, struct bio *bio)
603{ 597{
604 struct pgpath *pgpath; 598 struct pgpath *pgpath;
605 unsigned long flags; 599 unsigned long flags;
@@ -634,8 +628,8 @@ static int __multipath_map_bio(struct multipath *m, struct bio *bio,
634{ 628{
635 struct pgpath *pgpath; 629 struct pgpath *pgpath;
636 630
637 if (m->queue_mode == DM_TYPE_NVME_BIO_BASED) 631 if (!m->hw_handler_name)
638 pgpath = __map_bio_nvme(m, bio); 632 pgpath = __map_bio_fast(m, bio);
639 else 633 else
640 pgpath = __map_bio(m, bio); 634 pgpath = __map_bio(m, bio);
641 635
@@ -675,8 +669,7 @@ static void process_queued_io_list(struct multipath *m)
675{ 669{
676 if (m->queue_mode == DM_TYPE_MQ_REQUEST_BASED) 670 if (m->queue_mode == DM_TYPE_MQ_REQUEST_BASED)
677 dm_mq_kick_requeue_list(dm_table_get_md(m->ti->table)); 671 dm_mq_kick_requeue_list(dm_table_get_md(m->ti->table));
678 else if (m->queue_mode == DM_TYPE_BIO_BASED || 672 else if (m->queue_mode == DM_TYPE_BIO_BASED)
679 m->queue_mode == DM_TYPE_NVME_BIO_BASED)
680 queue_work(kmultipathd, &m->process_queued_bios); 673 queue_work(kmultipathd, &m->process_queued_bios);
681} 674}
682 675
@@ -811,15 +804,14 @@ static int parse_path_selector(struct dm_arg_set *as, struct priority_group *pg,
811 return 0; 804 return 0;
812} 805}
813 806
814static int setup_scsi_dh(struct block_device *bdev, struct multipath *m, char **error) 807static int setup_scsi_dh(struct block_device *bdev, struct multipath *m,
808 const char *attached_handler_name, char **error)
815{ 809{
816 struct request_queue *q = bdev_get_queue(bdev); 810 struct request_queue *q = bdev_get_queue(bdev);
817 const char *attached_handler_name;
818 int r; 811 int r;
819 812
820 if (test_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, &m->flags)) { 813 if (test_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, &m->flags)) {
821retain: 814retain:
822 attached_handler_name = scsi_dh_attached_handler_name(q, GFP_KERNEL);
823 if (attached_handler_name) { 815 if (attached_handler_name) {
824 /* 816 /*
825 * Clear any hw_handler_params associated with a 817 * Clear any hw_handler_params associated with a
@@ -873,6 +865,8 @@ static struct pgpath *parse_path(struct dm_arg_set *as, struct path_selector *ps
873 int r; 865 int r;
874 struct pgpath *p; 866 struct pgpath *p;
875 struct multipath *m = ti->private; 867 struct multipath *m = ti->private;
868 struct request_queue *q;
869 const char *attached_handler_name;
876 870
877 /* we need at least a path arg */ 871 /* we need at least a path arg */
878 if (as->argc < 1) { 872 if (as->argc < 1) {
@@ -891,9 +885,11 @@ static struct pgpath *parse_path(struct dm_arg_set *as, struct path_selector *ps
891 goto bad; 885 goto bad;
892 } 886 }
893 887
894 if (m->queue_mode != DM_TYPE_NVME_BIO_BASED) { 888 q = bdev_get_queue(p->path.dev->bdev);
889 attached_handler_name = scsi_dh_attached_handler_name(q, GFP_KERNEL);
890 if (attached_handler_name) {
895 INIT_DELAYED_WORK(&p->activate_path, activate_path_work); 891 INIT_DELAYED_WORK(&p->activate_path, activate_path_work);
896 r = setup_scsi_dh(p->path.dev->bdev, m, &ti->error); 892 r = setup_scsi_dh(p->path.dev->bdev, m, attached_handler_name, &ti->error);
897 if (r) { 893 if (r) {
898 dm_put_device(ti, p->path.dev); 894 dm_put_device(ti, p->path.dev);
899 goto bad; 895 goto bad;
@@ -1001,8 +997,7 @@ static int parse_hw_handler(struct dm_arg_set *as, struct multipath *m)
1001 if (!hw_argc) 997 if (!hw_argc)
1002 return 0; 998 return 0;
1003 999
1004 if (m->queue_mode == DM_TYPE_BIO_BASED || 1000 if (m->queue_mode == DM_TYPE_BIO_BASED) {
1005 m->queue_mode == DM_TYPE_NVME_BIO_BASED) {
1006 dm_consume_args(as, hw_argc); 1001 dm_consume_args(as, hw_argc);
1007 DMERR("bio-based multipath doesn't allow hardware handler args"); 1002 DMERR("bio-based multipath doesn't allow hardware handler args");
1008 return 0; 1003 return 0;
@@ -1091,8 +1086,6 @@ static int parse_features(struct dm_arg_set *as, struct multipath *m)
1091 1086
1092 if (!strcasecmp(queue_mode_name, "bio")) 1087 if (!strcasecmp(queue_mode_name, "bio"))
1093 m->queue_mode = DM_TYPE_BIO_BASED; 1088 m->queue_mode = DM_TYPE_BIO_BASED;
1094 else if (!strcasecmp(queue_mode_name, "nvme"))
1095 m->queue_mode = DM_TYPE_NVME_BIO_BASED;
1096 else if (!strcasecmp(queue_mode_name, "rq")) 1089 else if (!strcasecmp(queue_mode_name, "rq"))
1097 m->queue_mode = DM_TYPE_REQUEST_BASED; 1090 m->queue_mode = DM_TYPE_REQUEST_BASED;
1098 else if (!strcasecmp(queue_mode_name, "mq")) 1091 else if (!strcasecmp(queue_mode_name, "mq"))
@@ -1193,7 +1186,7 @@ static int multipath_ctr(struct dm_target *ti, unsigned argc, char **argv)
1193 ti->num_discard_bios = 1; 1186 ti->num_discard_bios = 1;
1194 ti->num_write_same_bios = 1; 1187 ti->num_write_same_bios = 1;
1195 ti->num_write_zeroes_bios = 1; 1188 ti->num_write_zeroes_bios = 1;
1196 if (m->queue_mode == DM_TYPE_BIO_BASED || m->queue_mode == DM_TYPE_NVME_BIO_BASED) 1189 if (m->queue_mode == DM_TYPE_BIO_BASED)
1197 ti->per_io_data_size = multipath_per_bio_data_size(); 1190 ti->per_io_data_size = multipath_per_bio_data_size();
1198 else 1191 else
1199 ti->per_io_data_size = sizeof(struct dm_mpath_io); 1192 ti->per_io_data_size = sizeof(struct dm_mpath_io);
@@ -1730,9 +1723,6 @@ static void multipath_status(struct dm_target *ti, status_type_t type,
1730 case DM_TYPE_BIO_BASED: 1723 case DM_TYPE_BIO_BASED:
1731 DMEMIT("queue_mode bio "); 1724 DMEMIT("queue_mode bio ");
1732 break; 1725 break;
1733 case DM_TYPE_NVME_BIO_BASED:
1734 DMEMIT("queue_mode nvme ");
1735 break;
1736 case DM_TYPE_MQ_REQUEST_BASED: 1726 case DM_TYPE_MQ_REQUEST_BASED:
1737 DMEMIT("queue_mode mq "); 1727 DMEMIT("queue_mode mq ");
1738 break; 1728 break;
@@ -2030,8 +2020,9 @@ static int multipath_busy(struct dm_target *ti)
2030 *---------------------------------------------------------------*/ 2020 *---------------------------------------------------------------*/
2031static struct target_type multipath_target = { 2021static struct target_type multipath_target = {
2032 .name = "multipath", 2022 .name = "multipath",
2033 .version = {1, 12, 0}, 2023 .version = {1, 13, 0},
2034 .features = DM_TARGET_SINGLETON | DM_TARGET_IMMUTABLE, 2024 .features = DM_TARGET_SINGLETON | DM_TARGET_IMMUTABLE |
2025 DM_TARGET_PASSES_INTEGRITY,
2035 .module = THIS_MODULE, 2026 .module = THIS_MODULE,
2036 .ctr = multipath_ctr, 2027 .ctr = multipath_ctr,
2037 .dtr = multipath_dtr, 2028 .dtr = multipath_dtr,
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 7ef469e902c6..c1d1034ff7b7 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -3408,9 +3408,10 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,
3408 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); 3408 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags);
3409 3409
3410 } else { 3410 } else {
3411 if (test_bit(MD_RECOVERY_NEEDED, &recovery) || 3411 if (!test_bit(MD_RECOVERY_INTR, &recovery) &&
3412 test_bit(MD_RECOVERY_RESHAPE, &recovery) || 3412 (test_bit(MD_RECOVERY_NEEDED, &recovery) ||
3413 test_bit(MD_RECOVERY_RUNNING, &recovery)) 3413 test_bit(MD_RECOVERY_RESHAPE, &recovery) ||
3414 test_bit(MD_RECOVERY_RUNNING, &recovery)))
3414 r = mddev->curr_resync_completed; 3415 r = mddev->curr_resync_completed;
3415 else 3416 else
3416 r = mddev->recovery_cp; 3417 r = mddev->recovery_cp;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 5fe7ec356c33..7eb3e2a3c07d 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -942,17 +942,12 @@ static int dm_table_determine_type(struct dm_table *t)
942 942
943 if (t->type != DM_TYPE_NONE) { 943 if (t->type != DM_TYPE_NONE) {
944 /* target already set the table's type */ 944 /* target already set the table's type */
945 if (t->type == DM_TYPE_BIO_BASED) 945 if (t->type == DM_TYPE_BIO_BASED) {
946 return 0; 946 /* possibly upgrade to a variant of bio-based */
947 else if (t->type == DM_TYPE_NVME_BIO_BASED) { 947 goto verify_bio_based;
948 if (!dm_table_does_not_support_partial_completion(t)) {
949 DMERR("nvme bio-based is only possible with devices"
950 " that don't support partial completion");
951 return -EINVAL;
952 }
953 /* Fallthru, also verify all devices are blk-mq */
954 } 948 }
955 BUG_ON(t->type == DM_TYPE_DAX_BIO_BASED); 949 BUG_ON(t->type == DM_TYPE_DAX_BIO_BASED);
950 BUG_ON(t->type == DM_TYPE_NVME_BIO_BASED);
956 goto verify_rq_based; 951 goto verify_rq_based;
957 } 952 }
958 953
@@ -985,6 +980,7 @@ static int dm_table_determine_type(struct dm_table *t)
985 } 980 }
986 981
987 if (bio_based) { 982 if (bio_based) {
983verify_bio_based:
988 /* We must use this table as bio-based */ 984 /* We must use this table as bio-based */
989 t->type = DM_TYPE_BIO_BASED; 985 t->type = DM_TYPE_BIO_BASED;
990 if (dm_table_supports_dax(t) || 986 if (dm_table_supports_dax(t) ||
@@ -1755,7 +1751,7 @@ static int device_no_partial_completion(struct dm_target *ti, struct dm_dev *dev
1755 char b[BDEVNAME_SIZE]; 1751 char b[BDEVNAME_SIZE];
1756 1752
1757 /* For now, NVMe devices are the only devices of this class */ 1753 /* For now, NVMe devices are the only devices of this class */
1758 return (strncmp(bdevname(dev->bdev, b), "nvme", 3) == 0); 1754 return (strncmp(bdevname(dev->bdev, b), "nvme", 4) == 0);
1759} 1755}
1760 1756
1761static bool dm_table_does_not_support_partial_completion(struct dm_table *t) 1757static bool dm_table_does_not_support_partial_completion(struct dm_table *t)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index d6de00f367ef..45328d8b2859 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -458,9 +458,11 @@ static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
458 return dm_get_geometry(md, geo); 458 return dm_get_geometry(md, geo);
459} 459}
460 460
461static int dm_grab_bdev_for_ioctl(struct mapped_device *md, 461static char *_dm_claim_ptr = "I belong to device-mapper";
462 struct block_device **bdev, 462
463 fmode_t *mode) 463static int dm_get_bdev_for_ioctl(struct mapped_device *md,
464 struct block_device **bdev,
465 fmode_t *mode)
464{ 466{
465 struct dm_target *tgt; 467 struct dm_target *tgt;
466 struct dm_table *map; 468 struct dm_table *map;
@@ -490,6 +492,10 @@ retry:
490 goto out; 492 goto out;
491 493
492 bdgrab(*bdev); 494 bdgrab(*bdev);
495 r = blkdev_get(*bdev, *mode, _dm_claim_ptr);
496 if (r < 0)
497 goto out;
498
493 dm_put_live_table(md, srcu_idx); 499 dm_put_live_table(md, srcu_idx);
494 return r; 500 return r;
495 501
@@ -508,7 +514,7 @@ static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
508 struct mapped_device *md = bdev->bd_disk->private_data; 514 struct mapped_device *md = bdev->bd_disk->private_data;
509 int r; 515 int r;
510 516
511 r = dm_grab_bdev_for_ioctl(md, &bdev, &mode); 517 r = dm_get_bdev_for_ioctl(md, &bdev, &mode);
512 if (r < 0) 518 if (r < 0)
513 return r; 519 return r;
514 520
@@ -528,7 +534,7 @@ static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
528 534
529 r = __blkdev_driver_ioctl(bdev, mode, cmd, arg); 535 r = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
530out: 536out:
531 bdput(bdev); 537 blkdev_put(bdev, mode);
532 return r; 538 return r;
533} 539}
534 540
@@ -708,14 +714,13 @@ static void dm_put_live_table_fast(struct mapped_device *md) __releases(RCU)
708static int open_table_device(struct table_device *td, dev_t dev, 714static int open_table_device(struct table_device *td, dev_t dev,
709 struct mapped_device *md) 715 struct mapped_device *md)
710{ 716{
711 static char *_claim_ptr = "I belong to device-mapper";
712 struct block_device *bdev; 717 struct block_device *bdev;
713 718
714 int r; 719 int r;
715 720
716 BUG_ON(td->dm_dev.bdev); 721 BUG_ON(td->dm_dev.bdev);
717 722
718 bdev = blkdev_get_by_dev(dev, td->dm_dev.mode | FMODE_EXCL, _claim_ptr); 723 bdev = blkdev_get_by_dev(dev, td->dm_dev.mode | FMODE_EXCL, _dm_claim_ptr);
719 if (IS_ERR(bdev)) 724 if (IS_ERR(bdev))
720 return PTR_ERR(bdev); 725 return PTR_ERR(bdev);
721 726
@@ -903,7 +908,8 @@ static void dec_pending(struct dm_io *io, blk_status_t error)
903 queue_io(md, bio); 908 queue_io(md, bio);
904 } else { 909 } else {
905 /* done with normal IO or empty flush */ 910 /* done with normal IO or empty flush */
906 bio->bi_status = io_error; 911 if (io_error)
912 bio->bi_status = io_error;
907 bio_endio(bio); 913 bio_endio(bio);
908 } 914 }
909 } 915 }
@@ -3010,7 +3016,7 @@ static int dm_pr_reserve(struct block_device *bdev, u64 key, enum pr_type type,
3010 fmode_t mode; 3016 fmode_t mode;
3011 int r; 3017 int r;
3012 3018
3013 r = dm_grab_bdev_for_ioctl(md, &bdev, &mode); 3019 r = dm_get_bdev_for_ioctl(md, &bdev, &mode);
3014 if (r < 0) 3020 if (r < 0)
3015 return r; 3021 return r;
3016 3022
@@ -3020,7 +3026,7 @@ static int dm_pr_reserve(struct block_device *bdev, u64 key, enum pr_type type,
3020 else 3026 else
3021 r = -EOPNOTSUPP; 3027 r = -EOPNOTSUPP;
3022 3028
3023 bdput(bdev); 3029 blkdev_put(bdev, mode);
3024 return r; 3030 return r;
3025} 3031}
3026 3032
@@ -3031,7 +3037,7 @@ static int dm_pr_release(struct block_device *bdev, u64 key, enum pr_type type)
3031 fmode_t mode; 3037 fmode_t mode;
3032 int r; 3038 int r;
3033 3039
3034 r = dm_grab_bdev_for_ioctl(md, &bdev, &mode); 3040 r = dm_get_bdev_for_ioctl(md, &bdev, &mode);
3035 if (r < 0) 3041 if (r < 0)
3036 return r; 3042 return r;
3037 3043
@@ -3041,7 +3047,7 @@ static int dm_pr_release(struct block_device *bdev, u64 key, enum pr_type type)
3041 else 3047 else
3042 r = -EOPNOTSUPP; 3048 r = -EOPNOTSUPP;
3043 3049
3044 bdput(bdev); 3050 blkdev_put(bdev, mode);
3045 return r; 3051 return r;
3046} 3052}
3047 3053
@@ -3053,7 +3059,7 @@ static int dm_pr_preempt(struct block_device *bdev, u64 old_key, u64 new_key,
3053 fmode_t mode; 3059 fmode_t mode;
3054 int r; 3060 int r;
3055 3061
3056 r = dm_grab_bdev_for_ioctl(md, &bdev, &mode); 3062 r = dm_get_bdev_for_ioctl(md, &bdev, &mode);
3057 if (r < 0) 3063 if (r < 0)
3058 return r; 3064 return r;
3059 3065
@@ -3063,7 +3069,7 @@ static int dm_pr_preempt(struct block_device *bdev, u64 old_key, u64 new_key,
3063 else 3069 else
3064 r = -EOPNOTSUPP; 3070 r = -EOPNOTSUPP;
3065 3071
3066 bdput(bdev); 3072 blkdev_put(bdev, mode);
3067 return r; 3073 return r;
3068} 3074}
3069 3075
@@ -3074,7 +3080,7 @@ static int dm_pr_clear(struct block_device *bdev, u64 key)
3074 fmode_t mode; 3080 fmode_t mode;
3075 int r; 3081 int r;
3076 3082
3077 r = dm_grab_bdev_for_ioctl(md, &bdev, &mode); 3083 r = dm_get_bdev_for_ioctl(md, &bdev, &mode);
3078 if (r < 0) 3084 if (r < 0)
3079 return r; 3085 return r;
3080 3086
@@ -3084,7 +3090,7 @@ static int dm_pr_clear(struct block_device *bdev, u64 key)
3084 else 3090 else
3085 r = -EOPNOTSUPP; 3091 r = -EOPNOTSUPP;
3086 3092
3087 bdput(bdev); 3093 blkdev_put(bdev, mode);
3088 return r; 3094 return r;
3089} 3095}
3090 3096
diff --git a/drivers/md/md-multipath.c b/drivers/md/md-multipath.c
index e40065bdbfc8..0a7e99d62c69 100644
--- a/drivers/md/md-multipath.c
+++ b/drivers/md/md-multipath.c
@@ -157,7 +157,7 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev)
157 seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); 157 seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
158 } 158 }
159 rcu_read_unlock(); 159 rcu_read_unlock();
160 seq_printf (seq, "]"); 160 seq_putc(seq, ']');
161} 161}
162 162
163static int multipath_congested(struct mddev *mddev, int bits) 163static int multipath_congested(struct mddev *mddev, int bits)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index bc67ab6844f0..254e44e44668 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -801,6 +801,9 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
801 struct bio *bio; 801 struct bio *bio;
802 int ff = 0; 802 int ff = 0;
803 803
804 if (!page)
805 return;
806
804 if (test_bit(Faulty, &rdev->flags)) 807 if (test_bit(Faulty, &rdev->flags))
805 return; 808 return;
806 809
@@ -5452,6 +5455,7 @@ int md_run(struct mddev *mddev)
5452 * the only valid external interface is through the md 5455 * the only valid external interface is through the md
5453 * device. 5456 * device.
5454 */ 5457 */
5458 mddev->has_superblocks = false;
5455 rdev_for_each(rdev, mddev) { 5459 rdev_for_each(rdev, mddev) {
5456 if (test_bit(Faulty, &rdev->flags)) 5460 if (test_bit(Faulty, &rdev->flags))
5457 continue; 5461 continue;
@@ -5465,6 +5469,9 @@ int md_run(struct mddev *mddev)
5465 set_disk_ro(mddev->gendisk, 1); 5469 set_disk_ro(mddev->gendisk, 1);
5466 } 5470 }
5467 5471
5472 if (rdev->sb_page)
5473 mddev->has_superblocks = true;
5474
5468 /* perform some consistency tests on the device. 5475 /* perform some consistency tests on the device.
5469 * We don't want the data to overlap the metadata, 5476 * We don't want the data to overlap the metadata,
5470 * Internal Bitmap issues have been handled elsewhere. 5477 * Internal Bitmap issues have been handled elsewhere.
@@ -5497,8 +5504,10 @@ int md_run(struct mddev *mddev)
5497 } 5504 }
5498 if (mddev->sync_set == NULL) { 5505 if (mddev->sync_set == NULL) {
5499 mddev->sync_set = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS); 5506 mddev->sync_set = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
5500 if (!mddev->sync_set) 5507 if (!mddev->sync_set) {
5501 return -ENOMEM; 5508 err = -ENOMEM;
5509 goto abort;
5510 }
5502 } 5511 }
5503 5512
5504 spin_lock(&pers_lock); 5513 spin_lock(&pers_lock);
@@ -5511,7 +5520,8 @@ int md_run(struct mddev *mddev)
5511 else 5520 else
5512 pr_warn("md: personality for level %s is not loaded!\n", 5521 pr_warn("md: personality for level %s is not loaded!\n",
5513 mddev->clevel); 5522 mddev->clevel);
5514 return -EINVAL; 5523 err = -EINVAL;
5524 goto abort;
5515 } 5525 }
5516 spin_unlock(&pers_lock); 5526 spin_unlock(&pers_lock);
5517 if (mddev->level != pers->level) { 5527 if (mddev->level != pers->level) {
@@ -5524,7 +5534,8 @@ int md_run(struct mddev *mddev)
5524 pers->start_reshape == NULL) { 5534 pers->start_reshape == NULL) {
5525 /* This personality cannot handle reshaping... */ 5535 /* This personality cannot handle reshaping... */
5526 module_put(pers->owner); 5536 module_put(pers->owner);
5527 return -EINVAL; 5537 err = -EINVAL;
5538 goto abort;
5528 } 5539 }
5529 5540
5530 if (pers->sync_request) { 5541 if (pers->sync_request) {
@@ -5593,7 +5604,7 @@ int md_run(struct mddev *mddev)
5593 mddev->private = NULL; 5604 mddev->private = NULL;
5594 module_put(pers->owner); 5605 module_put(pers->owner);
5595 bitmap_destroy(mddev); 5606 bitmap_destroy(mddev);
5596 return err; 5607 goto abort;
5597 } 5608 }
5598 if (mddev->queue) { 5609 if (mddev->queue) {
5599 bool nonrot = true; 5610 bool nonrot = true;
@@ -5655,6 +5666,18 @@ int md_run(struct mddev *mddev)
5655 sysfs_notify_dirent_safe(mddev->sysfs_action); 5666 sysfs_notify_dirent_safe(mddev->sysfs_action);
5656 sysfs_notify(&mddev->kobj, NULL, "degraded"); 5667 sysfs_notify(&mddev->kobj, NULL, "degraded");
5657 return 0; 5668 return 0;
5669
5670abort:
5671 if (mddev->bio_set) {
5672 bioset_free(mddev->bio_set);
5673 mddev->bio_set = NULL;
5674 }
5675 if (mddev->sync_set) {
5676 bioset_free(mddev->sync_set);
5677 mddev->sync_set = NULL;
5678 }
5679
5680 return err;
5658} 5681}
5659EXPORT_SYMBOL_GPL(md_run); 5682EXPORT_SYMBOL_GPL(md_run);
5660 5683
@@ -8049,6 +8072,7 @@ EXPORT_SYMBOL(md_done_sync);
8049bool md_write_start(struct mddev *mddev, struct bio *bi) 8072bool md_write_start(struct mddev *mddev, struct bio *bi)
8050{ 8073{
8051 int did_change = 0; 8074 int did_change = 0;
8075
8052 if (bio_data_dir(bi) != WRITE) 8076 if (bio_data_dir(bi) != WRITE)
8053 return true; 8077 return true;
8054 8078
@@ -8081,6 +8105,8 @@ bool md_write_start(struct mddev *mddev, struct bio *bi)
8081 rcu_read_unlock(); 8105 rcu_read_unlock();
8082 if (did_change) 8106 if (did_change)
8083 sysfs_notify_dirent_safe(mddev->sysfs_state); 8107 sysfs_notify_dirent_safe(mddev->sysfs_state);
8108 if (!mddev->has_superblocks)
8109 return true;
8084 wait_event(mddev->sb_wait, 8110 wait_event(mddev->sb_wait,
8085 !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags) || 8111 !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags) ||
8086 mddev->suspended); 8112 mddev->suspended);
@@ -8543,6 +8569,19 @@ void md_do_sync(struct md_thread *thread)
8543 set_mask_bits(&mddev->sb_flags, 0, 8569 set_mask_bits(&mddev->sb_flags, 0,
8544 BIT(MD_SB_CHANGE_PENDING) | BIT(MD_SB_CHANGE_DEVS)); 8570 BIT(MD_SB_CHANGE_PENDING) | BIT(MD_SB_CHANGE_DEVS));
8545 8571
8572 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
8573 !test_bit(MD_RECOVERY_INTR, &mddev->recovery) &&
8574 mddev->delta_disks > 0 &&
8575 mddev->pers->finish_reshape &&
8576 mddev->pers->size &&
8577 mddev->queue) {
8578 mddev_lock_nointr(mddev);
8579 md_set_array_sectors(mddev, mddev->pers->size(mddev, 0, 0));
8580 mddev_unlock(mddev);
8581 set_capacity(mddev->gendisk, mddev->array_sectors);
8582 revalidate_disk(mddev->gendisk);
8583 }
8584
8546 spin_lock(&mddev->lock); 8585 spin_lock(&mddev->lock);
8547 if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { 8586 if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
8548 /* We completed so min/max setting can be forgotten if used. */ 8587 /* We completed so min/max setting can be forgotten if used. */
@@ -8569,6 +8608,10 @@ static int remove_and_add_spares(struct mddev *mddev,
8569 int removed = 0; 8608 int removed = 0;
8570 bool remove_some = false; 8609 bool remove_some = false;
8571 8610
8611 if (this && test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
8612 /* Mustn't remove devices when resync thread is running */
8613 return 0;
8614
8572 rdev_for_each(rdev, mddev) { 8615 rdev_for_each(rdev, mddev) {
8573 if ((this == NULL || rdev == this) && 8616 if ((this == NULL || rdev == this) &&
8574 rdev->raid_disk >= 0 && 8617 rdev->raid_disk >= 0 &&
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 58cd20a5e85e..fbc925cce810 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -468,6 +468,8 @@ struct mddev {
468 void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev); 468 void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev);
469 struct md_cluster_info *cluster_info; 469 struct md_cluster_info *cluster_info;
470 unsigned int good_device_nr; /* good device num within cluster raid */ 470 unsigned int good_device_nr; /* good device num within cluster raid */
471
472 bool has_superblocks:1;
471}; 473};
472 474
473enum recovery_flags { 475enum recovery_flags {
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index b2eae332e1a2..fe872dc6712e 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1108,7 +1108,7 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio,
1108 1108
1109 bio_copy_data(behind_bio, bio); 1109 bio_copy_data(behind_bio, bio);
1110skip_copy: 1110skip_copy:
1111 r1_bio->behind_master_bio = behind_bio;; 1111 r1_bio->behind_master_bio = behind_bio;
1112 set_bit(R1BIO_BehindIO, &r1_bio->state); 1112 set_bit(R1BIO_BehindIO, &r1_bio->state);
1113 1113
1114 return; 1114 return;
@@ -1809,6 +1809,17 @@ static int raid1_remove_disk(struct mddev *mddev, struct md_rdev *rdev)
1809 struct md_rdev *repl = 1809 struct md_rdev *repl =
1810 conf->mirrors[conf->raid_disks + number].rdev; 1810 conf->mirrors[conf->raid_disks + number].rdev;
1811 freeze_array(conf, 0); 1811 freeze_array(conf, 0);
1812 if (atomic_read(&repl->nr_pending)) {
1813 /* It means that some queued IO of retry_list
1814 * hold repl. Thus, we cannot set replacement
1815 * as NULL, avoiding rdev NULL pointer
1816 * dereference in sync_request_write and
1817 * handle_write_finished.
1818 */
1819 err = -EBUSY;
1820 unfreeze_array(conf);
1821 goto abort;
1822 }
1812 clear_bit(Replacement, &repl->flags); 1823 clear_bit(Replacement, &repl->flags);
1813 p->rdev = repl; 1824 p->rdev = repl;
1814 conf->mirrors[conf->raid_disks + number].rdev = NULL; 1825 conf->mirrors[conf->raid_disks + number].rdev = NULL;
diff --git a/drivers/md/raid1.h b/drivers/md/raid1.h
index c7294e7557e0..eb84bc68e2fd 100644
--- a/drivers/md/raid1.h
+++ b/drivers/md/raid1.h
@@ -26,6 +26,18 @@
26#define BARRIER_BUCKETS_NR_BITS (PAGE_SHIFT - ilog2(sizeof(atomic_t))) 26#define BARRIER_BUCKETS_NR_BITS (PAGE_SHIFT - ilog2(sizeof(atomic_t)))
27#define BARRIER_BUCKETS_NR (1<<BARRIER_BUCKETS_NR_BITS) 27#define BARRIER_BUCKETS_NR (1<<BARRIER_BUCKETS_NR_BITS)
28 28
29/* Note: raid1_info.rdev can be set to NULL asynchronously by raid1_remove_disk.
30 * There are three safe ways to access raid1_info.rdev.
31 * 1/ when holding mddev->reconfig_mutex
32 * 2/ when resync/recovery is known to be happening - i.e. in code that is
33 * called as part of performing resync/recovery.
34 * 3/ while holding rcu_read_lock(), use rcu_dereference to get the pointer
35 * and if it is non-NULL, increment rdev->nr_pending before dropping the
36 * RCU lock.
37 * When .rdev is set to NULL, the nr_pending count checked again and if it has
38 * been incremented, the pointer is put back in .rdev.
39 */
40
29struct raid1_info { 41struct raid1_info {
30 struct md_rdev *rdev; 42 struct md_rdev *rdev;
31 sector_t head_position; 43 sector_t head_position;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 99c9207899a7..c5e6c60fc0d4 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -141,7 +141,7 @@ static void r10bio_pool_free(void *r10_bio, void *data)
141#define RESYNC_WINDOW (1024*1024) 141#define RESYNC_WINDOW (1024*1024)
142/* maximum number of concurrent requests, memory permitting */ 142/* maximum number of concurrent requests, memory permitting */
143#define RESYNC_DEPTH (32*1024*1024/RESYNC_BLOCK_SIZE) 143#define RESYNC_DEPTH (32*1024*1024/RESYNC_BLOCK_SIZE)
144#define CLUSTER_RESYNC_WINDOW (16 * RESYNC_WINDOW) 144#define CLUSTER_RESYNC_WINDOW (32 * RESYNC_WINDOW)
145#define CLUSTER_RESYNC_WINDOW_SECTORS (CLUSTER_RESYNC_WINDOW >> 9) 145#define CLUSTER_RESYNC_WINDOW_SECTORS (CLUSTER_RESYNC_WINDOW >> 9)
146 146
147/* 147/*
@@ -2655,7 +2655,8 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
2655 for (m = 0; m < conf->copies; m++) { 2655 for (m = 0; m < conf->copies; m++) {
2656 int dev = r10_bio->devs[m].devnum; 2656 int dev = r10_bio->devs[m].devnum;
2657 rdev = conf->mirrors[dev].rdev; 2657 rdev = conf->mirrors[dev].rdev;
2658 if (r10_bio->devs[m].bio == NULL) 2658 if (r10_bio->devs[m].bio == NULL ||
2659 r10_bio->devs[m].bio->bi_end_io == NULL)
2659 continue; 2660 continue;
2660 if (!r10_bio->devs[m].bio->bi_status) { 2661 if (!r10_bio->devs[m].bio->bi_status) {
2661 rdev_clear_badblocks( 2662 rdev_clear_badblocks(
@@ -2670,7 +2671,8 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
2670 md_error(conf->mddev, rdev); 2671 md_error(conf->mddev, rdev);
2671 } 2672 }
2672 rdev = conf->mirrors[dev].replacement; 2673 rdev = conf->mirrors[dev].replacement;
2673 if (r10_bio->devs[m].repl_bio == NULL) 2674 if (r10_bio->devs[m].repl_bio == NULL ||
2675 r10_bio->devs[m].repl_bio->bi_end_io == NULL)
2674 continue; 2676 continue;
2675 2677
2676 if (!r10_bio->devs[m].repl_bio->bi_status) { 2678 if (!r10_bio->devs[m].repl_bio->bi_status) {
@@ -3782,7 +3784,7 @@ static int raid10_run(struct mddev *mddev)
3782 if (fc > 1 || fo > 0) { 3784 if (fc > 1 || fo > 0) {
3783 pr_err("only near layout is supported by clustered" 3785 pr_err("only near layout is supported by clustered"
3784 " raid10\n"); 3786 " raid10\n");
3785 goto out; 3787 goto out_free_conf;
3786 } 3788 }
3787 } 3789 }
3788 3790
@@ -4830,17 +4832,11 @@ static void raid10_finish_reshape(struct mddev *mddev)
4830 return; 4832 return;
4831 4833
4832 if (mddev->delta_disks > 0) { 4834 if (mddev->delta_disks > 0) {
4833 sector_t size = raid10_size(mddev, 0, 0);
4834 md_set_array_sectors(mddev, size);
4835 if (mddev->recovery_cp > mddev->resync_max_sectors) { 4835 if (mddev->recovery_cp > mddev->resync_max_sectors) {
4836 mddev->recovery_cp = mddev->resync_max_sectors; 4836 mddev->recovery_cp = mddev->resync_max_sectors;
4837 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 4837 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
4838 } 4838 }
4839 mddev->resync_max_sectors = size; 4839 mddev->resync_max_sectors = mddev->array_sectors;
4840 if (mddev->queue) {
4841 set_capacity(mddev->gendisk, mddev->array_sectors);
4842 revalidate_disk(mddev->gendisk);
4843 }
4844 } else { 4840 } else {
4845 int d; 4841 int d;
4846 rcu_read_lock(); 4842 rcu_read_lock();
diff --git a/drivers/md/raid10.h b/drivers/md/raid10.h
index db2ac22ac1b4..e2e8840de9bf 100644
--- a/drivers/md/raid10.h
+++ b/drivers/md/raid10.h
@@ -2,6 +2,19 @@
2#ifndef _RAID10_H 2#ifndef _RAID10_H
3#define _RAID10_H 3#define _RAID10_H
4 4
5/* Note: raid10_info.rdev can be set to NULL asynchronously by
6 * raid10_remove_disk.
7 * There are three safe ways to access raid10_info.rdev.
8 * 1/ when holding mddev->reconfig_mutex
9 * 2/ when resync/recovery/reshape is known to be happening - i.e. in code
10 * that is called as part of performing resync/recovery/reshape.
11 * 3/ while holding rcu_read_lock(), use rcu_dereference to get the pointer
12 * and if it is non-NULL, increment rdev->nr_pending before dropping the
13 * RCU lock.
14 * When .rdev is set to NULL, the nr_pending count checked again and if it has
15 * been incremented, the pointer is put back in .rdev.
16 */
17
5struct raid10_info { 18struct raid10_info {
6 struct md_rdev *rdev, *replacement; 19 struct md_rdev *rdev, *replacement;
7 sector_t head_position; 20 sector_t head_position;
diff --git a/drivers/md/raid5-log.h b/drivers/md/raid5-log.h
index 0c76bcedfc1c..a001808a2b77 100644
--- a/drivers/md/raid5-log.h
+++ b/drivers/md/raid5-log.h
@@ -44,6 +44,7 @@ extern void ppl_write_stripe_run(struct r5conf *conf);
44extern void ppl_stripe_write_finished(struct stripe_head *sh); 44extern void ppl_stripe_write_finished(struct stripe_head *sh);
45extern int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add); 45extern int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add);
46extern void ppl_quiesce(struct r5conf *conf, int quiesce); 46extern void ppl_quiesce(struct r5conf *conf, int quiesce);
47extern int ppl_handle_flush_request(struct r5l_log *log, struct bio *bio);
47 48
48static inline bool raid5_has_ppl(struct r5conf *conf) 49static inline bool raid5_has_ppl(struct r5conf *conf)
49{ 50{
@@ -104,7 +105,7 @@ static inline int log_handle_flush_request(struct r5conf *conf, struct bio *bio)
104 if (conf->log) 105 if (conf->log)
105 ret = r5l_handle_flush_request(conf->log, bio); 106 ret = r5l_handle_flush_request(conf->log, bio);
106 else if (raid5_has_ppl(conf)) 107 else if (raid5_has_ppl(conf))
107 ret = 0; 108 ret = ppl_handle_flush_request(conf->log, bio);
108 109
109 return ret; 110 return ret;
110} 111}
diff --git a/drivers/md/raid5-ppl.c b/drivers/md/raid5-ppl.c
index 2764c2290062..42890a08375b 100644
--- a/drivers/md/raid5-ppl.c
+++ b/drivers/md/raid5-ppl.c
@@ -693,6 +693,16 @@ void ppl_quiesce(struct r5conf *conf, int quiesce)
693 } 693 }
694} 694}
695 695
696int ppl_handle_flush_request(struct r5l_log *log, struct bio *bio)
697{
698 if (bio->bi_iter.bi_size == 0) {
699 bio_endio(bio);
700 return 0;
701 }
702 bio->bi_opf &= ~REQ_PREFLUSH;
703 return -EAGAIN;
704}
705
696void ppl_stripe_write_finished(struct stripe_head *sh) 706void ppl_stripe_write_finished(struct stripe_head *sh)
697{ 707{
698 struct ppl_io_unit *io; 708 struct ppl_io_unit *io;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 50d01144b805..b5d2601483e3 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2196,15 +2196,16 @@ static int grow_one_stripe(struct r5conf *conf, gfp_t gfp)
2196static int grow_stripes(struct r5conf *conf, int num) 2196static int grow_stripes(struct r5conf *conf, int num)
2197{ 2197{
2198 struct kmem_cache *sc; 2198 struct kmem_cache *sc;
2199 size_t namelen = sizeof(conf->cache_name[0]);
2199 int devs = max(conf->raid_disks, conf->previous_raid_disks); 2200 int devs = max(conf->raid_disks, conf->previous_raid_disks);
2200 2201
2201 if (conf->mddev->gendisk) 2202 if (conf->mddev->gendisk)
2202 sprintf(conf->cache_name[0], 2203 snprintf(conf->cache_name[0], namelen,
2203 "raid%d-%s", conf->level, mdname(conf->mddev)); 2204 "raid%d-%s", conf->level, mdname(conf->mddev));
2204 else 2205 else
2205 sprintf(conf->cache_name[0], 2206 snprintf(conf->cache_name[0], namelen,
2206 "raid%d-%p", conf->level, conf->mddev); 2207 "raid%d-%p", conf->level, conf->mddev);
2207 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]); 2208 snprintf(conf->cache_name[1], namelen, "%.27s-alt", conf->cache_name[0]);
2208 2209
2209 conf->active_name = 0; 2210 conf->active_name = 0;
2210 sc = kmem_cache_create(conf->cache_name[conf->active_name], 2211 sc = kmem_cache_create(conf->cache_name[conf->active_name],
@@ -6764,9 +6765,7 @@ static void free_conf(struct r5conf *conf)
6764 6765
6765 log_exit(conf); 6766 log_exit(conf);
6766 6767
6767 if (conf->shrinker.nr_deferred) 6768 unregister_shrinker(&conf->shrinker);
6768 unregister_shrinker(&conf->shrinker);
6769
6770 free_thread_groups(conf); 6769 free_thread_groups(conf);
6771 shrink_stripes(conf); 6770 shrink_stripes(conf);
6772 raid5_free_percpu(conf); 6771 raid5_free_percpu(conf);
@@ -8001,13 +8000,7 @@ static void raid5_finish_reshape(struct mddev *mddev)
8001 8000
8002 if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { 8001 if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
8003 8002
8004 if (mddev->delta_disks > 0) { 8003 if (mddev->delta_disks <= 0) {
8005 md_set_array_sectors(mddev, raid5_size(mddev, 0, 0));
8006 if (mddev->queue) {
8007 set_capacity(mddev->gendisk, mddev->array_sectors);
8008 revalidate_disk(mddev->gendisk);
8009 }
8010 } else {
8011 int d; 8004 int d;
8012 spin_lock_irq(&conf->device_lock); 8005 spin_lock_irq(&conf->device_lock);
8013 mddev->degraded = raid5_calc_degraded(conf); 8006 mddev->degraded = raid5_calc_degraded(conf);
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index 2e6123825095..3f8da26032ac 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -450,6 +450,18 @@ enum {
450 * HANDLE gets cleared if stripe_handle leaves nothing locked. 450 * HANDLE gets cleared if stripe_handle leaves nothing locked.
451 */ 451 */
452 452
453/* Note: disk_info.rdev can be set to NULL asynchronously by raid5_remove_disk.
454 * There are three safe ways to access disk_info.rdev.
455 * 1/ when holding mddev->reconfig_mutex
456 * 2/ when resync/recovery/reshape is known to be happening - i.e. in code that
457 * is called as part of performing resync/recovery/reshape.
458 * 3/ while holding rcu_read_lock(), use rcu_dereference to get the pointer
459 * and if it is non-NULL, increment rdev->nr_pending before dropping the RCU
460 * lock.
461 * When .rdev is set to NULL, the nr_pending count checked again and if
462 * it has been incremented, the pointer is put back in .rdev.
463 */
464
453struct disk_info { 465struct disk_info {
454 struct md_rdev *rdev, *replacement; 466 struct md_rdev *rdev, *replacement;
455 struct page *extra_page; /* extra page to use in prexor */ 467 struct page *extra_page; /* extra page to use in prexor */
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 145e12bfb819..86c1a190d946 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -147,9 +147,11 @@ config DVB_CORE
147config DVB_MMAP 147config DVB_MMAP
148 bool "Enable DVB memory-mapped API (EXPERIMENTAL)" 148 bool "Enable DVB memory-mapped API (EXPERIMENTAL)"
149 depends on DVB_CORE 149 depends on DVB_CORE
150 depends on VIDEO_V4L2=y || VIDEO_V4L2=DVB_CORE
151 select VIDEOBUF2_VMALLOC
150 default n 152 default n
151 help 153 help
152 This option enables DVB experimental memory-mapped API, with 154 This option enables DVB experimental memory-mapped API, which
153 reduces the number of context switches to read DVB buffers, as 155 reduces the number of context switches to read DVB buffers, as
154 the buffers can use mmap() syscalls. 156 the buffers can use mmap() syscalls.
155 157
diff --git a/drivers/media/common/videobuf2/Kconfig b/drivers/media/common/videobuf2/Kconfig
index 5df05250de94..17c32ea58395 100644
--- a/drivers/media/common/videobuf2/Kconfig
+++ b/drivers/media/common/videobuf2/Kconfig
@@ -3,6 +3,9 @@ config VIDEOBUF2_CORE
3 select DMA_SHARED_BUFFER 3 select DMA_SHARED_BUFFER
4 tristate 4 tristate
5 5
6config VIDEOBUF2_V4L2
7 tristate
8
6config VIDEOBUF2_MEMOPS 9config VIDEOBUF2_MEMOPS
7 tristate 10 tristate
8 select FRAME_VECTOR 11 select FRAME_VECTOR
diff --git a/drivers/media/common/videobuf2/Makefile b/drivers/media/common/videobuf2/Makefile
index 19de5ccda20b..77bebe8b202f 100644
--- a/drivers/media/common/videobuf2/Makefile
+++ b/drivers/media/common/videobuf2/Makefile
@@ -1,5 +1,12 @@
1# SPDX-License-Identifier: GPL-2.0
2videobuf2-common-objs := videobuf2-core.o
1 3
2obj-$(CONFIG_VIDEOBUF2_CORE) += videobuf2-core.o videobuf2-v4l2.o 4ifeq ($(CONFIG_TRACEPOINTS),y)
5 videobuf2-common-objs += vb2-trace.o
6endif
7
8obj-$(CONFIG_VIDEOBUF2_CORE) += videobuf2-common.o
9obj-$(CONFIG_VIDEOBUF2_V4L2) += videobuf2-v4l2.o
3obj-$(CONFIG_VIDEOBUF2_MEMOPS) += videobuf2-memops.o 10obj-$(CONFIG_VIDEOBUF2_MEMOPS) += videobuf2-memops.o
4obj-$(CONFIG_VIDEOBUF2_VMALLOC) += videobuf2-vmalloc.o 11obj-$(CONFIG_VIDEOBUF2_VMALLOC) += videobuf2-vmalloc.o
5obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o 12obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o
diff --git a/drivers/media/v4l2-core/vb2-trace.c b/drivers/media/common/videobuf2/vb2-trace.c
index 4c0f39d271f0..4c0f39d271f0 100644
--- a/drivers/media/v4l2-core/vb2-trace.c
+++ b/drivers/media/common/videobuf2/vb2-trace.c
diff --git a/drivers/media/dvb-core/Makefile b/drivers/media/dvb-core/Makefile
index 3a105d82019a..62b028ded9f7 100644
--- a/drivers/media/dvb-core/Makefile
+++ b/drivers/media/dvb-core/Makefile
@@ -4,7 +4,7 @@
4# 4#
5 5
6dvb-net-$(CONFIG_DVB_NET) := dvb_net.o 6dvb-net-$(CONFIG_DVB_NET) := dvb_net.o
7dvb-vb2-$(CONFIG_DVB_MMSP) := dvb_vb2.o 7dvb-vb2-$(CONFIG_DVB_MMAP) := dvb_vb2.o
8 8
9dvb-core-objs := dvbdev.o dmxdev.o dvb_demux.o \ 9dvb-core-objs := dvbdev.o dmxdev.o dvb_demux.o \
10 dvb_ca_en50221.o dvb_frontend.o \ 10 dvb_ca_en50221.o dvb_frontend.o \
diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index 6d53af00190e..61a750fae465 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -128,11 +128,7 @@ static int dvb_dvr_open(struct inode *inode, struct file *file)
128 struct dvb_device *dvbdev = file->private_data; 128 struct dvb_device *dvbdev = file->private_data;
129 struct dmxdev *dmxdev = dvbdev->priv; 129 struct dmxdev *dmxdev = dvbdev->priv;
130 struct dmx_frontend *front; 130 struct dmx_frontend *front;
131#ifndef DVB_MMAP
132 bool need_ringbuffer = false; 131 bool need_ringbuffer = false;
133#else
134 const bool need_ringbuffer = true;
135#endif
136 132
137 dprintk("%s\n", __func__); 133 dprintk("%s\n", __func__);
138 134
@@ -144,17 +140,31 @@ static int dvb_dvr_open(struct inode *inode, struct file *file)
144 return -ENODEV; 140 return -ENODEV;
145 } 141 }
146 142
147#ifndef DVB_MMAP 143 dmxdev->may_do_mmap = 0;
144
145 /*
146 * The logic here is a little tricky due to the ifdef.
147 *
148 * The ringbuffer is used for both read and mmap.
149 *
150 * It is not needed, however, on two situations:
151 * - Write devices (access with O_WRONLY);
152 * - For duplex device nodes, opened with O_RDWR.
153 */
154
148 if ((file->f_flags & O_ACCMODE) == O_RDONLY) 155 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
149 need_ringbuffer = true; 156 need_ringbuffer = true;
150#else 157 else if ((file->f_flags & O_ACCMODE) == O_RDWR) {
151 if ((file->f_flags & O_ACCMODE) == O_RDWR) {
152 if (!(dmxdev->capabilities & DMXDEV_CAP_DUPLEX)) { 158 if (!(dmxdev->capabilities & DMXDEV_CAP_DUPLEX)) {
159#ifdef CONFIG_DVB_MMAP
160 dmxdev->may_do_mmap = 1;
161 need_ringbuffer = true;
162#else
153 mutex_unlock(&dmxdev->mutex); 163 mutex_unlock(&dmxdev->mutex);
154 return -EOPNOTSUPP; 164 return -EOPNOTSUPP;
165#endif
155 } 166 }
156 } 167 }
157#endif
158 168
159 if (need_ringbuffer) { 169 if (need_ringbuffer) {
160 void *mem; 170 void *mem;
@@ -169,8 +179,9 @@ static int dvb_dvr_open(struct inode *inode, struct file *file)
169 return -ENOMEM; 179 return -ENOMEM;
170 } 180 }
171 dvb_ringbuffer_init(&dmxdev->dvr_buffer, mem, DVR_BUFFER_SIZE); 181 dvb_ringbuffer_init(&dmxdev->dvr_buffer, mem, DVR_BUFFER_SIZE);
172 dvb_vb2_init(&dmxdev->dvr_vb2_ctx, "dvr", 182 if (dmxdev->may_do_mmap)
173 file->f_flags & O_NONBLOCK); 183 dvb_vb2_init(&dmxdev->dvr_vb2_ctx, "dvr",
184 file->f_flags & O_NONBLOCK);
174 dvbdev->readers--; 185 dvbdev->readers--;
175 } 186 }
176 187
@@ -200,11 +211,6 @@ static int dvb_dvr_release(struct inode *inode, struct file *file)
200{ 211{
201 struct dvb_device *dvbdev = file->private_data; 212 struct dvb_device *dvbdev = file->private_data;
202 struct dmxdev *dmxdev = dvbdev->priv; 213 struct dmxdev *dmxdev = dvbdev->priv;
203#ifndef DVB_MMAP
204 bool need_ringbuffer = false;
205#else
206 const bool need_ringbuffer = true;
207#endif
208 214
209 mutex_lock(&dmxdev->mutex); 215 mutex_lock(&dmxdev->mutex);
210 216
@@ -213,15 +219,14 @@ static int dvb_dvr_release(struct inode *inode, struct file *file)
213 dmxdev->demux->connect_frontend(dmxdev->demux, 219 dmxdev->demux->connect_frontend(dmxdev->demux,
214 dmxdev->dvr_orig_fe); 220 dmxdev->dvr_orig_fe);
215 } 221 }
216#ifndef DVB_MMAP
217 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
218 need_ringbuffer = true;
219#endif
220 222
221 if (need_ringbuffer) { 223 if (((file->f_flags & O_ACCMODE) == O_RDONLY) ||
222 if (dvb_vb2_is_streaming(&dmxdev->dvr_vb2_ctx)) 224 dmxdev->may_do_mmap) {
223 dvb_vb2_stream_off(&dmxdev->dvr_vb2_ctx); 225 if (dmxdev->may_do_mmap) {
224 dvb_vb2_release(&dmxdev->dvr_vb2_ctx); 226 if (dvb_vb2_is_streaming(&dmxdev->dvr_vb2_ctx))
227 dvb_vb2_stream_off(&dmxdev->dvr_vb2_ctx);
228 dvb_vb2_release(&dmxdev->dvr_vb2_ctx);
229 }
225 dvbdev->readers++; 230 dvbdev->readers++;
226 if (dmxdev->dvr_buffer.data) { 231 if (dmxdev->dvr_buffer.data) {
227 void *mem = dmxdev->dvr_buffer.data; 232 void *mem = dmxdev->dvr_buffer.data;
@@ -380,7 +385,8 @@ static void dvb_dmxdev_filter_timer(struct dmxdev_filter *dmxdevfilter)
380 385
381static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len, 386static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
382 const u8 *buffer2, size_t buffer2_len, 387 const u8 *buffer2, size_t buffer2_len,
383 struct dmx_section_filter *filter) 388 struct dmx_section_filter *filter,
389 u32 *buffer_flags)
384{ 390{
385 struct dmxdev_filter *dmxdevfilter = filter->priv; 391 struct dmxdev_filter *dmxdevfilter = filter->priv;
386 int ret; 392 int ret;
@@ -399,10 +405,12 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
399 dprintk("section callback %*ph\n", 6, buffer1); 405 dprintk("section callback %*ph\n", 6, buffer1);
400 if (dvb_vb2_is_streaming(&dmxdevfilter->vb2_ctx)) { 406 if (dvb_vb2_is_streaming(&dmxdevfilter->vb2_ctx)) {
401 ret = dvb_vb2_fill_buffer(&dmxdevfilter->vb2_ctx, 407 ret = dvb_vb2_fill_buffer(&dmxdevfilter->vb2_ctx,
402 buffer1, buffer1_len); 408 buffer1, buffer1_len,
409 buffer_flags);
403 if (ret == buffer1_len) 410 if (ret == buffer1_len)
404 ret = dvb_vb2_fill_buffer(&dmxdevfilter->vb2_ctx, 411 ret = dvb_vb2_fill_buffer(&dmxdevfilter->vb2_ctx,
405 buffer2, buffer2_len); 412 buffer2, buffer2_len,
413 buffer_flags);
406 } else { 414 } else {
407 ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, 415 ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer,
408 buffer1, buffer1_len); 416 buffer1, buffer1_len);
@@ -422,11 +430,12 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
422 430
423static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len, 431static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len,
424 const u8 *buffer2, size_t buffer2_len, 432 const u8 *buffer2, size_t buffer2_len,
425 struct dmx_ts_feed *feed) 433 struct dmx_ts_feed *feed,
434 u32 *buffer_flags)
426{ 435{
427 struct dmxdev_filter *dmxdevfilter = feed->priv; 436 struct dmxdev_filter *dmxdevfilter = feed->priv;
428 struct dvb_ringbuffer *buffer; 437 struct dvb_ringbuffer *buffer;
429#ifdef DVB_MMAP 438#ifdef CONFIG_DVB_MMAP
430 struct dvb_vb2_ctx *ctx; 439 struct dvb_vb2_ctx *ctx;
431#endif 440#endif
432 int ret; 441 int ret;
@@ -440,20 +449,22 @@ static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len,
440 if (dmxdevfilter->params.pes.output == DMX_OUT_TAP || 449 if (dmxdevfilter->params.pes.output == DMX_OUT_TAP ||
441 dmxdevfilter->params.pes.output == DMX_OUT_TSDEMUX_TAP) { 450 dmxdevfilter->params.pes.output == DMX_OUT_TSDEMUX_TAP) {
442 buffer = &dmxdevfilter->buffer; 451 buffer = &dmxdevfilter->buffer;
443#ifdef DVB_MMAP 452#ifdef CONFIG_DVB_MMAP
444 ctx = &dmxdevfilter->vb2_ctx; 453 ctx = &dmxdevfilter->vb2_ctx;
445#endif 454#endif
446 } else { 455 } else {
447 buffer = &dmxdevfilter->dev->dvr_buffer; 456 buffer = &dmxdevfilter->dev->dvr_buffer;
448#ifdef DVB_MMAP 457#ifdef CONFIG_DVB_MMAP
449 ctx = &dmxdevfilter->dev->dvr_vb2_ctx; 458 ctx = &dmxdevfilter->dev->dvr_vb2_ctx;
450#endif 459#endif
451 } 460 }
452 461
453 if (dvb_vb2_is_streaming(ctx)) { 462 if (dvb_vb2_is_streaming(ctx)) {
454 ret = dvb_vb2_fill_buffer(ctx, buffer1, buffer1_len); 463 ret = dvb_vb2_fill_buffer(ctx, buffer1, buffer1_len,
464 buffer_flags);
455 if (ret == buffer1_len) 465 if (ret == buffer1_len)
456 ret = dvb_vb2_fill_buffer(ctx, buffer2, buffer2_len); 466 ret = dvb_vb2_fill_buffer(ctx, buffer2, buffer2_len,
467 buffer_flags);
457 } else { 468 } else {
458 if (buffer->error) { 469 if (buffer->error) {
459 spin_unlock(&dmxdevfilter->dev->lock); 470 spin_unlock(&dmxdevfilter->dev->lock);
@@ -802,6 +813,12 @@ static int dvb_demux_open(struct inode *inode, struct file *file)
802 mutex_init(&dmxdevfilter->mutex); 813 mutex_init(&dmxdevfilter->mutex);
803 file->private_data = dmxdevfilter; 814 file->private_data = dmxdevfilter;
804 815
816#ifdef CONFIG_DVB_MMAP
817 dmxdev->may_do_mmap = 1;
818#else
819 dmxdev->may_do_mmap = 0;
820#endif
821
805 dvb_ringbuffer_init(&dmxdevfilter->buffer, NULL, 8192); 822 dvb_ringbuffer_init(&dmxdevfilter->buffer, NULL, 8192);
806 dvb_vb2_init(&dmxdevfilter->vb2_ctx, "demux_filter", 823 dvb_vb2_init(&dmxdevfilter->vb2_ctx, "demux_filter",
807 file->f_flags & O_NONBLOCK); 824 file->f_flags & O_NONBLOCK);
@@ -1111,7 +1128,7 @@ static int dvb_demux_do_ioctl(struct file *file,
1111 mutex_unlock(&dmxdevfilter->mutex); 1128 mutex_unlock(&dmxdevfilter->mutex);
1112 break; 1129 break;
1113 1130
1114#ifdef DVB_MMAP 1131#ifdef CONFIG_DVB_MMAP
1115 case DMX_REQBUFS: 1132 case DMX_REQBUFS:
1116 if (mutex_lock_interruptible(&dmxdevfilter->mutex)) { 1133 if (mutex_lock_interruptible(&dmxdevfilter->mutex)) {
1117 mutex_unlock(&dmxdev->mutex); 1134 mutex_unlock(&dmxdev->mutex);
@@ -1160,7 +1177,7 @@ static int dvb_demux_do_ioctl(struct file *file,
1160 break; 1177 break;
1161#endif 1178#endif
1162 default: 1179 default:
1163 ret = -EINVAL; 1180 ret = -ENOTTY;
1164 break; 1181 break;
1165 } 1182 }
1166 mutex_unlock(&dmxdev->mutex); 1183 mutex_unlock(&dmxdev->mutex);
@@ -1199,13 +1216,16 @@ static __poll_t dvb_demux_poll(struct file *file, poll_table *wait)
1199 return mask; 1216 return mask;
1200} 1217}
1201 1218
1202#ifdef DVB_MMAP 1219#ifdef CONFIG_DVB_MMAP
1203static int dvb_demux_mmap(struct file *file, struct vm_area_struct *vma) 1220static int dvb_demux_mmap(struct file *file, struct vm_area_struct *vma)
1204{ 1221{
1205 struct dmxdev_filter *dmxdevfilter = file->private_data; 1222 struct dmxdev_filter *dmxdevfilter = file->private_data;
1206 struct dmxdev *dmxdev = dmxdevfilter->dev; 1223 struct dmxdev *dmxdev = dmxdevfilter->dev;
1207 int ret; 1224 int ret;
1208 1225
1226 if (!dmxdev->may_do_mmap)
1227 return -ENOTTY;
1228
1209 if (mutex_lock_interruptible(&dmxdev->mutex)) 1229 if (mutex_lock_interruptible(&dmxdev->mutex))
1210 return -ERESTARTSYS; 1230 return -ERESTARTSYS;
1211 1231
@@ -1249,7 +1269,7 @@ static const struct file_operations dvb_demux_fops = {
1249 .release = dvb_demux_release, 1269 .release = dvb_demux_release,
1250 .poll = dvb_demux_poll, 1270 .poll = dvb_demux_poll,
1251 .llseek = default_llseek, 1271 .llseek = default_llseek,
1252#ifdef DVB_MMAP 1272#ifdef CONFIG_DVB_MMAP
1253 .mmap = dvb_demux_mmap, 1273 .mmap = dvb_demux_mmap,
1254#endif 1274#endif
1255}; 1275};
@@ -1280,7 +1300,7 @@ static int dvb_dvr_do_ioctl(struct file *file,
1280 ret = dvb_dvr_set_buffer_size(dmxdev, arg); 1300 ret = dvb_dvr_set_buffer_size(dmxdev, arg);
1281 break; 1301 break;
1282 1302
1283#ifdef DVB_MMAP 1303#ifdef CONFIG_DVB_MMAP
1284 case DMX_REQBUFS: 1304 case DMX_REQBUFS:
1285 ret = dvb_vb2_reqbufs(&dmxdev->dvr_vb2_ctx, parg); 1305 ret = dvb_vb2_reqbufs(&dmxdev->dvr_vb2_ctx, parg);
1286 break; 1306 break;
@@ -1304,7 +1324,7 @@ static int dvb_dvr_do_ioctl(struct file *file,
1304 break; 1324 break;
1305#endif 1325#endif
1306 default: 1326 default:
1307 ret = -EINVAL; 1327 ret = -ENOTTY;
1308 break; 1328 break;
1309 } 1329 }
1310 mutex_unlock(&dmxdev->mutex); 1330 mutex_unlock(&dmxdev->mutex);
@@ -1322,11 +1342,6 @@ static __poll_t dvb_dvr_poll(struct file *file, poll_table *wait)
1322 struct dvb_device *dvbdev = file->private_data; 1342 struct dvb_device *dvbdev = file->private_data;
1323 struct dmxdev *dmxdev = dvbdev->priv; 1343 struct dmxdev *dmxdev = dvbdev->priv;
1324 __poll_t mask = 0; 1344 __poll_t mask = 0;
1325#ifndef DVB_MMAP
1326 bool need_ringbuffer = false;
1327#else
1328 const bool need_ringbuffer = true;
1329#endif
1330 1345
1331 dprintk("%s\n", __func__); 1346 dprintk("%s\n", __func__);
1332 1347
@@ -1337,11 +1352,8 @@ static __poll_t dvb_dvr_poll(struct file *file, poll_table *wait)
1337 1352
1338 poll_wait(file, &dmxdev->dvr_buffer.queue, wait); 1353 poll_wait(file, &dmxdev->dvr_buffer.queue, wait);
1339 1354
1340#ifndef DVB_MMAP 1355 if (((file->f_flags & O_ACCMODE) == O_RDONLY) ||
1341 if ((file->f_flags & O_ACCMODE) == O_RDONLY) 1356 dmxdev->may_do_mmap) {
1342 need_ringbuffer = true;
1343#endif
1344 if (need_ringbuffer) {
1345 if (dmxdev->dvr_buffer.error) 1357 if (dmxdev->dvr_buffer.error)
1346 mask |= (EPOLLIN | EPOLLRDNORM | EPOLLPRI | EPOLLERR); 1358 mask |= (EPOLLIN | EPOLLRDNORM | EPOLLPRI | EPOLLERR);
1347 1359
@@ -1353,13 +1365,16 @@ static __poll_t dvb_dvr_poll(struct file *file, poll_table *wait)
1353 return mask; 1365 return mask;
1354} 1366}
1355 1367
1356#ifdef DVB_MMAP 1368#ifdef CONFIG_DVB_MMAP
1357static int dvb_dvr_mmap(struct file *file, struct vm_area_struct *vma) 1369static int dvb_dvr_mmap(struct file *file, struct vm_area_struct *vma)
1358{ 1370{
1359 struct dvb_device *dvbdev = file->private_data; 1371 struct dvb_device *dvbdev = file->private_data;
1360 struct dmxdev *dmxdev = dvbdev->priv; 1372 struct dmxdev *dmxdev = dvbdev->priv;
1361 int ret; 1373 int ret;
1362 1374
1375 if (!dmxdev->may_do_mmap)
1376 return -ENOTTY;
1377
1363 if (dmxdev->exit) 1378 if (dmxdev->exit)
1364 return -ENODEV; 1379 return -ENODEV;
1365 1380
@@ -1381,7 +1396,7 @@ static const struct file_operations dvb_dvr_fops = {
1381 .release = dvb_dvr_release, 1396 .release = dvb_dvr_release,
1382 .poll = dvb_dvr_poll, 1397 .poll = dvb_dvr_poll,
1383 .llseek = default_llseek, 1398 .llseek = default_llseek,
1384#ifdef DVB_MMAP 1399#ifdef CONFIG_DVB_MMAP
1385 .mmap = dvb_dvr_mmap, 1400 .mmap = dvb_dvr_mmap,
1386#endif 1401#endif
1387}; 1402};
diff --git a/drivers/media/dvb-core/dvb_demux.c b/drivers/media/dvb-core/dvb_demux.c
index 210eed0269b0..f45091246bdc 100644
--- a/drivers/media/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb-core/dvb_demux.c
@@ -55,6 +55,17 @@ MODULE_PARM_DESC(dvb_demux_feed_err_pkts,
55 dprintk(x); \ 55 dprintk(x); \
56} while (0) 56} while (0)
57 57
58#ifdef CONFIG_DVB_DEMUX_SECTION_LOSS_LOG
59# define dprintk_sect_loss(x...) dprintk(x)
60#else
61# define dprintk_sect_loss(x...)
62#endif
63
64#define set_buf_flags(__feed, __flag) \
65 do { \
66 (__feed)->buffer_flags |= (__flag); \
67 } while (0)
68
58/****************************************************************************** 69/******************************************************************************
59 * static inlined helper functions 70 * static inlined helper functions
60 ******************************************************************************/ 71 ******************************************************************************/
@@ -104,31 +115,30 @@ static inline int dvb_dmx_swfilter_payload(struct dvb_demux_feed *feed,
104{ 115{
105 int count = payload(buf); 116 int count = payload(buf);
106 int p; 117 int p;
107#ifdef CONFIG_DVB_DEMUX_SECTION_LOSS_LOG
108 int ccok; 118 int ccok;
109 u8 cc; 119 u8 cc;
110#endif
111 120
112 if (count == 0) 121 if (count == 0)
113 return -1; 122 return -1;
114 123
115 p = 188 - count; 124 p = 188 - count;
116 125
117#ifdef CONFIG_DVB_DEMUX_SECTION_LOSS_LOG
118 cc = buf[3] & 0x0f; 126 cc = buf[3] & 0x0f;
119 ccok = ((feed->cc + 1) & 0x0f) == cc; 127 ccok = ((feed->cc + 1) & 0x0f) == cc;
120 feed->cc = cc; 128 feed->cc = cc;
121 if (!ccok) 129 if (!ccok) {
122 dprintk("missed packet: %d instead of %d!\n", 130 set_buf_flags(feed, DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED);
123 cc, (feed->cc + 1) & 0x0f); 131 dprintk_sect_loss("missed packet: %d instead of %d!\n",
124#endif 132 cc, (feed->cc + 1) & 0x0f);
133 }
125 134
126 if (buf[1] & 0x40) // PUSI ? 135 if (buf[1] & 0x40) // PUSI ?
127 feed->peslen = 0xfffa; 136 feed->peslen = 0xfffa;
128 137
129 feed->peslen += count; 138 feed->peslen += count;
130 139
131 return feed->cb.ts(&buf[p], count, NULL, 0, &feed->feed.ts); 140 return feed->cb.ts(&buf[p], count, NULL, 0, &feed->feed.ts,
141 &feed->buffer_flags);
132} 142}
133 143
134static int dvb_dmx_swfilter_sectionfilter(struct dvb_demux_feed *feed, 144static int dvb_dmx_swfilter_sectionfilter(struct dvb_demux_feed *feed,
@@ -150,7 +160,7 @@ static int dvb_dmx_swfilter_sectionfilter(struct dvb_demux_feed *feed,
150 return 0; 160 return 0;
151 161
152 return feed->cb.sec(feed->feed.sec.secbuf, feed->feed.sec.seclen, 162 return feed->cb.sec(feed->feed.sec.secbuf, feed->feed.sec.seclen,
153 NULL, 0, &f->filter); 163 NULL, 0, &f->filter, &feed->buffer_flags);
154} 164}
155 165
156static inline int dvb_dmx_swfilter_section_feed(struct dvb_demux_feed *feed) 166static inline int dvb_dmx_swfilter_section_feed(struct dvb_demux_feed *feed)
@@ -169,8 +179,10 @@ static inline int dvb_dmx_swfilter_section_feed(struct dvb_demux_feed *feed)
169 if (sec->check_crc) { 179 if (sec->check_crc) {
170 section_syntax_indicator = ((sec->secbuf[1] & 0x80) != 0); 180 section_syntax_indicator = ((sec->secbuf[1] & 0x80) != 0);
171 if (section_syntax_indicator && 181 if (section_syntax_indicator &&
172 demux->check_crc32(feed, sec->secbuf, sec->seclen)) 182 demux->check_crc32(feed, sec->secbuf, sec->seclen)) {
183 set_buf_flags(feed, DMX_BUFFER_FLAG_HAD_CRC32_DISCARD);
173 return -1; 184 return -1;
185 }
174 } 186 }
175 187
176 do { 188 do {
@@ -187,7 +199,6 @@ static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed)
187{ 199{
188 struct dmx_section_feed *sec = &feed->feed.sec; 200 struct dmx_section_feed *sec = &feed->feed.sec;
189 201
190#ifdef CONFIG_DVB_DEMUX_SECTION_LOSS_LOG
191 if (sec->secbufp < sec->tsfeedp) { 202 if (sec->secbufp < sec->tsfeedp) {
192 int n = sec->tsfeedp - sec->secbufp; 203 int n = sec->tsfeedp - sec->secbufp;
193 204
@@ -197,12 +208,13 @@ static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed)
197 * but just first and last. 208 * but just first and last.
198 */ 209 */
199 if (sec->secbuf[0] != 0xff || sec->secbuf[n - 1] != 0xff) { 210 if (sec->secbuf[0] != 0xff || sec->secbuf[n - 1] != 0xff) {
200 dprintk("section ts padding loss: %d/%d\n", 211 set_buf_flags(feed,
201 n, sec->tsfeedp); 212 DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED);
202 dprintk("pad data: %*ph\n", n, sec->secbuf); 213 dprintk_sect_loss("section ts padding loss: %d/%d\n",
214 n, sec->tsfeedp);
215 dprintk_sect_loss("pad data: %*ph\n", n, sec->secbuf);
203 } 216 }
204 } 217 }
205#endif
206 218
207 sec->tsfeedp = sec->secbufp = sec->seclen = 0; 219 sec->tsfeedp = sec->secbufp = sec->seclen = 0;
208 sec->secbuf = sec->secbuf_base; 220 sec->secbuf = sec->secbuf_base;
@@ -237,11 +249,10 @@ static int dvb_dmx_swfilter_section_copy_dump(struct dvb_demux_feed *feed,
237 return 0; 249 return 0;
238 250
239 if (sec->tsfeedp + len > DMX_MAX_SECFEED_SIZE) { 251 if (sec->tsfeedp + len > DMX_MAX_SECFEED_SIZE) {
240#ifdef CONFIG_DVB_DEMUX_SECTION_LOSS_LOG 252 set_buf_flags(feed, DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED);
241 dprintk("section buffer full loss: %d/%d\n", 253 dprintk_sect_loss("section buffer full loss: %d/%d\n",
242 sec->tsfeedp + len - DMX_MAX_SECFEED_SIZE, 254 sec->tsfeedp + len - DMX_MAX_SECFEED_SIZE,
243 DMX_MAX_SECFEED_SIZE); 255 DMX_MAX_SECFEED_SIZE);
244#endif
245 len = DMX_MAX_SECFEED_SIZE - sec->tsfeedp; 256 len = DMX_MAX_SECFEED_SIZE - sec->tsfeedp;
246 } 257 }
247 258
@@ -269,12 +280,13 @@ static int dvb_dmx_swfilter_section_copy_dump(struct dvb_demux_feed *feed,
269 sec->seclen = seclen; 280 sec->seclen = seclen;
270 sec->crc_val = ~0; 281 sec->crc_val = ~0;
271 /* dump [secbuf .. secbuf+seclen) */ 282 /* dump [secbuf .. secbuf+seclen) */
272 if (feed->pusi_seen) 283 if (feed->pusi_seen) {
273 dvb_dmx_swfilter_section_feed(feed); 284 dvb_dmx_swfilter_section_feed(feed);
274#ifdef CONFIG_DVB_DEMUX_SECTION_LOSS_LOG 285 } else {
275 else 286 set_buf_flags(feed,
276 dprintk("pusi not seen, discarding section data\n"); 287 DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED);
277#endif 288 dprintk_sect_loss("pusi not seen, discarding section data\n");
289 }
278 sec->secbufp += seclen; /* secbufp and secbuf moving together is */ 290 sec->secbufp += seclen; /* secbufp and secbuf moving together is */
279 sec->secbuf += seclen; /* redundant but saves pointer arithmetic */ 291 sec->secbuf += seclen; /* redundant but saves pointer arithmetic */
280 } 292 }
@@ -307,18 +319,22 @@ static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed,
307 } 319 }
308 320
309 if (!ccok || dc_i) { 321 if (!ccok || dc_i) {
310#ifdef CONFIG_DVB_DEMUX_SECTION_LOSS_LOG 322 if (dc_i) {
311 if (dc_i) 323 set_buf_flags(feed,
312 dprintk("%d frame with disconnect indicator\n", 324 DMX_BUFFER_FLAG_DISCONTINUITY_INDICATOR);
325 dprintk_sect_loss("%d frame with disconnect indicator\n",
313 cc); 326 cc);
314 else 327 } else {
315 dprintk("discontinuity: %d instead of %d. %d bytes lost\n", 328 set_buf_flags(feed,
329 DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED);
330 dprintk_sect_loss("discontinuity: %d instead of %d. %d bytes lost\n",
316 cc, (feed->cc + 1) & 0x0f, count + 4); 331 cc, (feed->cc + 1) & 0x0f, count + 4);
332 }
317 /* 333 /*
318 * those bytes under sume circumstances will again be reported 334 * those bytes under some circumstances will again be reported
319 * in the following dvb_dmx_swfilter_section_new 335 * in the following dvb_dmx_swfilter_section_new
320 */ 336 */
321#endif 337
322 /* 338 /*
323 * Discontinuity detected. Reset pusi_seen to 339 * Discontinuity detected. Reset pusi_seen to
324 * stop feeding of suspicious data until next PUSI=1 arrives 340 * stop feeding of suspicious data until next PUSI=1 arrives
@@ -326,6 +342,7 @@ static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed,
326 * FIXME: does it make sense if the MPEG-TS is the one 342 * FIXME: does it make sense if the MPEG-TS is the one
327 * reporting discontinuity? 343 * reporting discontinuity?
328 */ 344 */
345
329 feed->pusi_seen = false; 346 feed->pusi_seen = false;
330 dvb_dmx_swfilter_section_new(feed); 347 dvb_dmx_swfilter_section_new(feed);
331 } 348 }
@@ -345,11 +362,11 @@ static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed,
345 dvb_dmx_swfilter_section_new(feed); 362 dvb_dmx_swfilter_section_new(feed);
346 dvb_dmx_swfilter_section_copy_dump(feed, after, 363 dvb_dmx_swfilter_section_copy_dump(feed, after,
347 after_len); 364 after_len);
365 } else if (count > 0) {
366 set_buf_flags(feed,
367 DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED);
368 dprintk_sect_loss("PUSI=1 but %d bytes lost\n", count);
348 } 369 }
349#ifdef CONFIG_DVB_DEMUX_SECTION_LOSS_LOG
350 else if (count > 0)
351 dprintk("PUSI=1 but %d bytes lost\n", count);
352#endif
353 } else { 370 } else {
354 /* PUSI=0 (is not set), no section boundary */ 371 /* PUSI=0 (is not set), no section boundary */
355 dvb_dmx_swfilter_section_copy_dump(feed, &buf[p], count); 372 dvb_dmx_swfilter_section_copy_dump(feed, &buf[p], count);
@@ -369,7 +386,8 @@ static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed,
369 if (feed->ts_type & TS_PAYLOAD_ONLY) 386 if (feed->ts_type & TS_PAYLOAD_ONLY)
370 dvb_dmx_swfilter_payload(feed, buf); 387 dvb_dmx_swfilter_payload(feed, buf);
371 else 388 else
372 feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts); 389 feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts,
390 &feed->buffer_flags);
373 } 391 }
374 /* Used only on full-featured devices */ 392 /* Used only on full-featured devices */
375 if (feed->ts_type & TS_DECODER) 393 if (feed->ts_type & TS_DECODER)
@@ -430,6 +448,11 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
430 } 448 }
431 449
432 if (buf[1] & 0x80) { 450 if (buf[1] & 0x80) {
451 list_for_each_entry(feed, &demux->feed_list, list_head) {
452 if ((feed->pid != pid) && (feed->pid != 0x2000))
453 continue;
454 set_buf_flags(feed, DMX_BUFFER_FLAG_TEI);
455 }
433 dprintk_tscheck("TEI detected. PID=0x%x data1=0x%x\n", 456 dprintk_tscheck("TEI detected. PID=0x%x data1=0x%x\n",
434 pid, buf[1]); 457 pid, buf[1]);
435 /* data in this packet can't be trusted - drop it unless 458 /* data in this packet can't be trusted - drop it unless
@@ -445,6 +468,13 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
445 (demux->cnt_storage[pid] + 1) & 0xf; 468 (demux->cnt_storage[pid] + 1) & 0xf;
446 469
447 if ((buf[3] & 0xf) != demux->cnt_storage[pid]) { 470 if ((buf[3] & 0xf) != demux->cnt_storage[pid]) {
471 list_for_each_entry(feed, &demux->feed_list, list_head) {
472 if ((feed->pid != pid) && (feed->pid != 0x2000))
473 continue;
474 set_buf_flags(feed,
475 DMX_BUFFER_PKT_COUNTER_MISMATCH);
476 }
477
448 dprintk_tscheck("TS packet counter mismatch. PID=0x%x expected 0x%x got 0x%x\n", 478 dprintk_tscheck("TS packet counter mismatch. PID=0x%x expected 0x%x got 0x%x\n",
449 pid, demux->cnt_storage[pid], 479 pid, demux->cnt_storage[pid],
450 buf[3] & 0xf); 480 buf[3] & 0xf);
@@ -466,7 +496,8 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
466 if (feed->pid == pid) 496 if (feed->pid == pid)
467 dvb_dmx_swfilter_packet_type(feed, buf); 497 dvb_dmx_swfilter_packet_type(feed, buf);
468 else if (feed->pid == 0x2000) 498 else if (feed->pid == 0x2000)
469 feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts); 499 feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts,
500 &feed->buffer_flags);
470 } 501 }
471} 502}
472 503
@@ -585,7 +616,8 @@ void dvb_dmx_swfilter_raw(struct dvb_demux *demux, const u8 *buf, size_t count)
585 616
586 spin_lock_irqsave(&demux->lock, flags); 617 spin_lock_irqsave(&demux->lock, flags);
587 618
588 demux->feed->cb.ts(buf, count, NULL, 0, &demux->feed->feed.ts); 619 demux->feed->cb.ts(buf, count, NULL, 0, &demux->feed->feed.ts,
620 &demux->feed->buffer_flags);
589 621
590 spin_unlock_irqrestore(&demux->lock, flags); 622 spin_unlock_irqrestore(&demux->lock, flags);
591} 623}
@@ -785,6 +817,7 @@ static int dvbdmx_allocate_ts_feed(struct dmx_demux *dmx,
785 feed->demux = demux; 817 feed->demux = demux;
786 feed->pid = 0xffff; 818 feed->pid = 0xffff;
787 feed->peslen = 0xfffa; 819 feed->peslen = 0xfffa;
820 feed->buffer_flags = 0;
788 821
789 (*ts_feed) = &feed->feed.ts; 822 (*ts_feed) = &feed->feed.ts;
790 (*ts_feed)->parent = dmx; 823 (*ts_feed)->parent = dmx;
@@ -1042,6 +1075,7 @@ static int dvbdmx_allocate_section_feed(struct dmx_demux *demux,
1042 dvbdmxfeed->cb.sec = callback; 1075 dvbdmxfeed->cb.sec = callback;
1043 dvbdmxfeed->demux = dvbdmx; 1076 dvbdmxfeed->demux = dvbdmx;
1044 dvbdmxfeed->pid = 0xffff; 1077 dvbdmxfeed->pid = 0xffff;
1078 dvbdmxfeed->buffer_flags = 0;
1045 dvbdmxfeed->feed.sec.secbuf = dvbdmxfeed->feed.sec.secbuf_base; 1079 dvbdmxfeed->feed.sec.secbuf = dvbdmxfeed->feed.sec.secbuf_base;
1046 dvbdmxfeed->feed.sec.secbufp = dvbdmxfeed->feed.sec.seclen = 0; 1080 dvbdmxfeed->feed.sec.secbufp = dvbdmxfeed->feed.sec.seclen = 0;
1047 dvbdmxfeed->feed.sec.tsfeedp = 0; 1081 dvbdmxfeed->feed.sec.tsfeedp = 0;
diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index b6c7eec863b9..ba39f9942e1d 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -883,7 +883,8 @@ static void dvb_net_ule(struct net_device *dev, const u8 *buf, size_t buf_len)
883 883
884static int dvb_net_ts_callback(const u8 *buffer1, size_t buffer1_len, 884static int dvb_net_ts_callback(const u8 *buffer1, size_t buffer1_len,
885 const u8 *buffer2, size_t buffer2_len, 885 const u8 *buffer2, size_t buffer2_len,
886 struct dmx_ts_feed *feed) 886 struct dmx_ts_feed *feed,
887 u32 *buffer_flags)
887{ 888{
888 struct net_device *dev = feed->priv; 889 struct net_device *dev = feed->priv;
889 890
@@ -992,7 +993,7 @@ static void dvb_net_sec(struct net_device *dev,
992 993
993static int dvb_net_sec_callback(const u8 *buffer1, size_t buffer1_len, 994static int dvb_net_sec_callback(const u8 *buffer1, size_t buffer1_len,
994 const u8 *buffer2, size_t buffer2_len, 995 const u8 *buffer2, size_t buffer2_len,
995 struct dmx_section_filter *filter) 996 struct dmx_section_filter *filter, u32 *buffer_flags)
996{ 997{
997 struct net_device *dev = filter->priv; 998 struct net_device *dev = filter->priv;
998 999
diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c
index 763145d74e83..b811adf88afa 100644
--- a/drivers/media/dvb-core/dvb_vb2.c
+++ b/drivers/media/dvb-core/dvb_vb2.c
@@ -256,7 +256,8 @@ int dvb_vb2_is_streaming(struct dvb_vb2_ctx *ctx)
256} 256}
257 257
258int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ctx, 258int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ctx,
259 const unsigned char *src, int len) 259 const unsigned char *src, int len,
260 enum dmx_buffer_flags *buffer_flags)
260{ 261{
261 unsigned long flags = 0; 262 unsigned long flags = 0;
262 void *vbuf = NULL; 263 void *vbuf = NULL;
@@ -264,15 +265,17 @@ int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ctx,
264 unsigned char *psrc = (unsigned char *)src; 265 unsigned char *psrc = (unsigned char *)src;
265 int ll = 0; 266 int ll = 0;
266 267
267 dprintk(3, "[%s] %d bytes are rcvd\n", ctx->name, len); 268 /*
268 if (!src) { 269 * normal case: This func is called twice from demux driver
269 dprintk(3, "[%s]:NULL pointer src\n", ctx->name); 270 * one with valid src pointer, second time with NULL pointer
270 /**normal case: This func is called twice from demux driver 271 */
271 * once with valid src pointer, second time with NULL pointer 272 if (!src || !len)
272 */
273 return 0; 273 return 0;
274 }
275 spin_lock_irqsave(&ctx->slock, flags); 274 spin_lock_irqsave(&ctx->slock, flags);
275 if (buffer_flags && *buffer_flags) {
276 ctx->flags |= *buffer_flags;
277 *buffer_flags = 0;
278 }
276 while (todo) { 279 while (todo) {
277 if (!ctx->buf) { 280 if (!ctx->buf) {
278 if (list_empty(&ctx->dvb_q)) { 281 if (list_empty(&ctx->dvb_q)) {
@@ -395,6 +398,7 @@ int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b)
395 398
396int dvb_vb2_dqbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) 399int dvb_vb2_dqbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b)
397{ 400{
401 unsigned long flags;
398 int ret; 402 int ret;
399 403
400 ret = vb2_core_dqbuf(&ctx->vb_q, &b->index, b, ctx->nonblocking); 404 ret = vb2_core_dqbuf(&ctx->vb_q, &b->index, b, ctx->nonblocking);
@@ -402,7 +406,16 @@ int dvb_vb2_dqbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b)
402 dprintk(1, "[%s] errno=%d\n", ctx->name, ret); 406 dprintk(1, "[%s] errno=%d\n", ctx->name, ret);
403 return ret; 407 return ret;
404 } 408 }
405 dprintk(5, "[%s] index=%d\n", ctx->name, b->index); 409
410 spin_lock_irqsave(&ctx->slock, flags);
411 b->count = ctx->count++;
412 b->flags = ctx->flags;
413 ctx->flags = 0;
414 spin_unlock_irqrestore(&ctx->slock, flags);
415
416 dprintk(5, "[%s] index=%d, count=%d, flags=%d\n",
417 ctx->name, b->index, ctx->count, b->flags);
418
406 419
407 return 0; 420 return 0;
408} 421}
diff --git a/drivers/media/dvb-frontends/m88ds3103.c b/drivers/media/dvb-frontends/m88ds3103.c
index 50bce68ffd66..65d157fe76d1 100644
--- a/drivers/media/dvb-frontends/m88ds3103.c
+++ b/drivers/media/dvb-frontends/m88ds3103.c
@@ -1262,11 +1262,12 @@ static int m88ds3103_select(struct i2c_mux_core *muxc, u32 chan)
1262 * New users must use I2C client binding directly! 1262 * New users must use I2C client binding directly!
1263 */ 1263 */
1264struct dvb_frontend *m88ds3103_attach(const struct m88ds3103_config *cfg, 1264struct dvb_frontend *m88ds3103_attach(const struct m88ds3103_config *cfg,
1265 struct i2c_adapter *i2c, struct i2c_adapter **tuner_i2c_adapter) 1265 struct i2c_adapter *i2c,
1266 struct i2c_adapter **tuner_i2c_adapter)
1266{ 1267{
1267 struct i2c_client *client; 1268 struct i2c_client *client;
1268 struct i2c_board_info board_info; 1269 struct i2c_board_info board_info;
1269 struct m88ds3103_platform_data pdata; 1270 struct m88ds3103_platform_data pdata = {};
1270 1271
1271 pdata.clk = cfg->clock; 1272 pdata.clk = cfg->clock;
1272 pdata.i2c_wr_max = cfg->i2c_wr_max; 1273 pdata.i2c_wr_max = cfg->i2c_wr_max;
@@ -1409,6 +1410,8 @@ static int m88ds3103_probe(struct i2c_client *client,
1409 case M88DS3103_CHIP_ID: 1410 case M88DS3103_CHIP_ID:
1410 break; 1411 break;
1411 default: 1412 default:
1413 ret = -ENODEV;
1414 dev_err(&client->dev, "Unknown device. Chip_id=%02x\n", dev->chip_id);
1412 goto err_kfree; 1415 goto err_kfree;
1413 } 1416 }
1414 1417
diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index 3c1851984b90..2476d812f669 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -505,80 +505,77 @@ static struct i2c_vbi_ram_value vbi_ram_default[] =
505 /* FIXME: Current api doesn't handle all VBI types, those not 505 /* FIXME: Current api doesn't handle all VBI types, those not
506 yet supported are placed under #if 0 */ 506 yet supported are placed under #if 0 */
507#if 0 507#if 0
508 {0x010, /* Teletext, SECAM, WST System A */ 508 [0] = {0x010, /* Teletext, SECAM, WST System A */
509 {V4L2_SLICED_TELETEXT_SECAM,6,23,1}, 509 {V4L2_SLICED_TELETEXT_SECAM,6,23,1},
510 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26, 510 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
511 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 } 511 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
512 }, 512 },
513#endif 513#endif
514 {0x030, /* Teletext, PAL, WST System B */ 514 [1] = {0x030, /* Teletext, PAL, WST System B */
515 {V4L2_SLICED_TELETEXT_B,6,22,1}, 515 {V4L2_SLICED_TELETEXT_B,6,22,1},
516 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b, 516 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
517 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 } 517 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
518 }, 518 },
519#if 0 519#if 0
520 {0x050, /* Teletext, PAL, WST System C */ 520 [2] = {0x050, /* Teletext, PAL, WST System C */
521 {V4L2_SLICED_TELETEXT_PAL_C,6,22,1}, 521 {V4L2_SLICED_TELETEXT_PAL_C,6,22,1},
522 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22, 522 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
523 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } 523 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
524 }, 524 },
525 {0x070, /* Teletext, NTSC, WST System B */ 525 [3] = {0x070, /* Teletext, NTSC, WST System B */
526 {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1}, 526 {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1},
527 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23, 527 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
528 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } 528 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
529 }, 529 },
530 {0x090, /* Tetetext, NTSC NABTS System C */ 530 [4] = {0x090, /* Tetetext, NTSC NABTS System C */
531 {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1}, 531 {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1},
532 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22, 532 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
533 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 } 533 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
534 }, 534 },
535 {0x0b0, /* Teletext, NTSC-J, NABTS System D */ 535 [5] = {0x0b0, /* Teletext, NTSC-J, NABTS System D */
536 {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1}, 536 {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1},
537 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23, 537 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
538 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } 538 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
539 }, 539 },
540 {0x0d0, /* Closed Caption, PAL/SECAM */ 540 [6] = {0x0d0, /* Closed Caption, PAL/SECAM */
541 {V4L2_SLICED_CAPTION_625,22,22,1}, 541 {V4L2_SLICED_CAPTION_625,22,22,1},
542 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, 542 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
543 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 } 543 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
544 }, 544 },
545#endif 545#endif
546 {0x0f0, /* Closed Caption, NTSC */ 546 [7] = {0x0f0, /* Closed Caption, NTSC */
547 {V4L2_SLICED_CAPTION_525,21,21,1}, 547 {V4L2_SLICED_CAPTION_525,21,21,1},
548 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, 548 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
549 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 } 549 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
550 }, 550 },
551 {0x110, /* Wide Screen Signal, PAL/SECAM */ 551 [8] = {0x110, /* Wide Screen Signal, PAL/SECAM */
552 {V4L2_SLICED_WSS_625,23,23,1}, 552 {V4L2_SLICED_WSS_625,23,23,1},
553 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42, 553 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
554 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 } 554 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
555 }, 555 },
556#if 0 556#if 0
557 {0x130, /* Wide Screen Signal, NTSC C */ 557 [9] = {0x130, /* Wide Screen Signal, NTSC C */
558 {V4L2_SLICED_WSS_525,20,20,1}, 558 {V4L2_SLICED_WSS_525,20,20,1},
559 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43, 559 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
560 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 } 560 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
561 }, 561 },
562 {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */ 562 [10] = {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
563 {V4l2_SLICED_VITC_625,6,22,0}, 563 {V4l2_SLICED_VITC_625,6,22,0},
564 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49, 564 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
565 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 } 565 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
566 }, 566 },
567 {0x170, /* Vertical Interval Timecode (VITC), NTSC */ 567 [11] = {0x170, /* Vertical Interval Timecode (VITC), NTSC */
568 {V4l2_SLICED_VITC_525,10,20,0}, 568 {V4l2_SLICED_VITC_525,10,20,0},
569 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49, 569 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
570 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 } 570 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
571 }, 571 },
572#endif 572#endif
573 {0x190, /* Video Program System (VPS), PAL */ 573 [12] = {0x190, /* Video Program System (VPS), PAL */
574 {V4L2_SLICED_VPS,16,16,0}, 574 {V4L2_SLICED_VPS,16,16,0},
575 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d, 575 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
576 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 } 576 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
577 }, 577 },
578 /* 0x1d0 User programmable */ 578 /* 0x1d0 User programmable */
579
580 /* End of struct */
581 { (u16)-1 }
582}; 579};
583 580
584static int tvp5150_write_inittab(struct v4l2_subdev *sd, 581static int tvp5150_write_inittab(struct v4l2_subdev *sd,
@@ -591,10 +588,10 @@ static int tvp5150_write_inittab(struct v4l2_subdev *sd,
591 return 0; 588 return 0;
592} 589}
593 590
594static int tvp5150_vdp_init(struct v4l2_subdev *sd, 591static int tvp5150_vdp_init(struct v4l2_subdev *sd)
595 const struct i2c_vbi_ram_value *regs)
596{ 592{
597 unsigned int i; 593 unsigned int i;
594 int j;
598 595
599 /* Disable Full Field */ 596 /* Disable Full Field */
600 tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0); 597 tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
@@ -604,14 +601,17 @@ static int tvp5150_vdp_init(struct v4l2_subdev *sd,
604 tvp5150_write(sd, i, 0xff); 601 tvp5150_write(sd, i, 0xff);
605 602
606 /* Load Ram Table */ 603 /* Load Ram Table */
607 while (regs->reg != (u16)-1) { 604 for (j = 0; j < ARRAY_SIZE(vbi_ram_default); j++) {
605 const struct i2c_vbi_ram_value *regs = &vbi_ram_default[j];
606
607 if (!regs->type.vbi_type)
608 continue;
609
608 tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8); 610 tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8);
609 tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_LOW, regs->reg); 611 tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_LOW, regs->reg);
610 612
611 for (i = 0; i < 16; i++) 613 for (i = 0; i < 16; i++)
612 tvp5150_write(sd, TVP5150_VDP_CONF_RAM_DATA, regs->values[i]); 614 tvp5150_write(sd, TVP5150_VDP_CONF_RAM_DATA, regs->values[i]);
613
614 regs++;
615 } 615 }
616 return 0; 616 return 0;
617} 617}
@@ -620,19 +620,23 @@ static int tvp5150_vdp_init(struct v4l2_subdev *sd,
620static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd, 620static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
621 struct v4l2_sliced_vbi_cap *cap) 621 struct v4l2_sliced_vbi_cap *cap)
622{ 622{
623 const struct i2c_vbi_ram_value *regs = vbi_ram_default; 623 int line, i;
624 int line;
625 624
626 dev_dbg_lvl(sd->dev, 1, debug, "g_sliced_vbi_cap\n"); 625 dev_dbg_lvl(sd->dev, 1, debug, "g_sliced_vbi_cap\n");
627 memset(cap, 0, sizeof *cap); 626 memset(cap, 0, sizeof *cap);
628 627
629 while (regs->reg != (u16)-1 ) { 628 for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) {
630 for (line=regs->type.ini_line;line<=regs->type.end_line;line++) { 629 const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i];
630
631 if (!regs->type.vbi_type)
632 continue;
633
634 for (line = regs->type.ini_line;
635 line <= regs->type.end_line;
636 line++) {
631 cap->service_lines[0][line] |= regs->type.vbi_type; 637 cap->service_lines[0][line] |= regs->type.vbi_type;
632 } 638 }
633 cap->service_set |= regs->type.vbi_type; 639 cap->service_set |= regs->type.vbi_type;
634
635 regs++;
636 } 640 }
637 return 0; 641 return 0;
638} 642}
@@ -651,14 +655,13 @@ static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
651 * MSB = field2 655 * MSB = field2
652 */ 656 */
653static int tvp5150_set_vbi(struct v4l2_subdev *sd, 657static int tvp5150_set_vbi(struct v4l2_subdev *sd,
654 const struct i2c_vbi_ram_value *regs,
655 unsigned int type,u8 flags, int line, 658 unsigned int type,u8 flags, int line,
656 const int fields) 659 const int fields)
657{ 660{
658 struct tvp5150 *decoder = to_tvp5150(sd); 661 struct tvp5150 *decoder = to_tvp5150(sd);
659 v4l2_std_id std = decoder->norm; 662 v4l2_std_id std = decoder->norm;
660 u8 reg; 663 u8 reg;
661 int pos = 0; 664 int i, pos = 0;
662 665
663 if (std == V4L2_STD_ALL) { 666 if (std == V4L2_STD_ALL) {
664 dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n"); 667 dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n");
@@ -671,19 +674,19 @@ static int tvp5150_set_vbi(struct v4l2_subdev *sd,
671 if (line < 6 || line > 27) 674 if (line < 6 || line > 27)
672 return 0; 675 return 0;
673 676
674 while (regs->reg != (u16)-1) { 677 for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) {
678 const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i];
679
680 if (!regs->type.vbi_type)
681 continue;
682
675 if ((type & regs->type.vbi_type) && 683 if ((type & regs->type.vbi_type) &&
676 (line >= regs->type.ini_line) && 684 (line >= regs->type.ini_line) &&
677 (line <= regs->type.end_line)) 685 (line <= regs->type.end_line))
678 break; 686 break;
679
680 regs++;
681 pos++; 687 pos++;
682 } 688 }
683 689
684 if (regs->reg == (u16)-1)
685 return 0;
686
687 type = pos | (flags & 0xf0); 690 type = pos | (flags & 0xf0);
688 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI; 691 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
689 692
@@ -696,8 +699,7 @@ static int tvp5150_set_vbi(struct v4l2_subdev *sd,
696 return type; 699 return type;
697} 700}
698 701
699static int tvp5150_get_vbi(struct v4l2_subdev *sd, 702static int tvp5150_get_vbi(struct v4l2_subdev *sd, int line)
700 const struct i2c_vbi_ram_value *regs, int line)
701{ 703{
702 struct tvp5150 *decoder = to_tvp5150(sd); 704 struct tvp5150 *decoder = to_tvp5150(sd);
703 v4l2_std_id std = decoder->norm; 705 v4l2_std_id std = decoder->norm;
@@ -726,8 +728,8 @@ static int tvp5150_get_vbi(struct v4l2_subdev *sd,
726 return 0; 728 return 0;
727 } 729 }
728 pos = ret & 0x0f; 730 pos = ret & 0x0f;
729 if (pos < 0x0f) 731 if (pos < ARRAY_SIZE(vbi_ram_default))
730 type |= regs[pos].type.vbi_type; 732 type |= vbi_ram_default[pos].type.vbi_type;
731 } 733 }
732 734
733 return type; 735 return type;
@@ -788,7 +790,7 @@ static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
788 tvp5150_write_inittab(sd, tvp5150_init_default); 790 tvp5150_write_inittab(sd, tvp5150_init_default);
789 791
790 /* Initializes VDP registers */ 792 /* Initializes VDP registers */
791 tvp5150_vdp_init(sd, vbi_ram_default); 793 tvp5150_vdp_init(sd);
792 794
793 /* Selects decoder input */ 795 /* Selects decoder input */
794 tvp5150_selmux(sd); 796 tvp5150_selmux(sd);
@@ -1121,8 +1123,8 @@ static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_f
1121 for (i = 0; i <= 23; i++) { 1123 for (i = 0; i <= 23; i++) {
1122 svbi->service_lines[1][i] = 0; 1124 svbi->service_lines[1][i] = 0;
1123 svbi->service_lines[0][i] = 1125 svbi->service_lines[0][i] =
1124 tvp5150_set_vbi(sd, vbi_ram_default, 1126 tvp5150_set_vbi(sd, svbi->service_lines[0][i],
1125 svbi->service_lines[0][i], 0xf0, i, 3); 1127 0xf0, i, 3);
1126 } 1128 }
1127 /* Enables FIFO */ 1129 /* Enables FIFO */
1128 tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 1); 1130 tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 1);
@@ -1148,7 +1150,7 @@ static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_f
1148 1150
1149 for (i = 0; i <= 23; i++) { 1151 for (i = 0; i <= 23; i++) {
1150 svbi->service_lines[0][i] = 1152 svbi->service_lines[0][i] =
1151 tvp5150_get_vbi(sd, vbi_ram_default, i); 1153 tvp5150_get_vbi(sd, i);
1152 mask |= svbi->service_lines[0][i]; 1154 mask |= svbi->service_lines[0][i];
1153 } 1155 }
1154 svbi->service_set = mask; 1156 svbi->service_set = mask;
diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c
index dc8e577b2f74..d6816effb878 100644
--- a/drivers/media/pci/ttpci/av7110.c
+++ b/drivers/media/pci/ttpci/av7110.c
@@ -324,14 +324,15 @@ static int DvbDmxFilterCallback(u8 *buffer1, size_t buffer1_len,
324 } 324 }
325 return dvbdmxfilter->feed->cb.sec(buffer1, buffer1_len, 325 return dvbdmxfilter->feed->cb.sec(buffer1, buffer1_len,
326 buffer2, buffer2_len, 326 buffer2, buffer2_len,
327 &dvbdmxfilter->filter); 327 &dvbdmxfilter->filter, NULL);
328 case DMX_TYPE_TS: 328 case DMX_TYPE_TS:
329 if (!(dvbdmxfilter->feed->ts_type & TS_PACKET)) 329 if (!(dvbdmxfilter->feed->ts_type & TS_PACKET))
330 return 0; 330 return 0;
331 if (dvbdmxfilter->feed->ts_type & TS_PAYLOAD_ONLY) 331 if (dvbdmxfilter->feed->ts_type & TS_PAYLOAD_ONLY)
332 return dvbdmxfilter->feed->cb.ts(buffer1, buffer1_len, 332 return dvbdmxfilter->feed->cb.ts(buffer1, buffer1_len,
333 buffer2, buffer2_len, 333 buffer2, buffer2_len,
334 &dvbdmxfilter->feed->feed.ts); 334 &dvbdmxfilter->feed->feed.ts,
335 NULL);
335 else 336 else
336 av7110_p2t_write(buffer1, buffer1_len, 337 av7110_p2t_write(buffer1, buffer1_len,
337 dvbdmxfilter->feed->pid, 338 dvbdmxfilter->feed->pid,
diff --git a/drivers/media/pci/ttpci/av7110_av.c b/drivers/media/pci/ttpci/av7110_av.c
index 4daba76ec240..ef1bc17cdc4d 100644
--- a/drivers/media/pci/ttpci/av7110_av.c
+++ b/drivers/media/pci/ttpci/av7110_av.c
@@ -99,7 +99,7 @@ int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len)
99 buf[4] = buf[5] = 0; 99 buf[4] = buf[5] = 0;
100 if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY) 100 if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
101 return dvbdmxfeed->cb.ts(buf, len, NULL, 0, 101 return dvbdmxfeed->cb.ts(buf, len, NULL, 0,
102 &dvbdmxfeed->feed.ts); 102 &dvbdmxfeed->feed.ts, NULL);
103 else 103 else
104 return dvb_filter_pes2ts(p2t, buf, len, 1); 104 return dvb_filter_pes2ts(p2t, buf, len, 1);
105} 105}
@@ -109,7 +109,7 @@ static int dvb_filter_pes2ts_cb(void *priv, unsigned char *data)
109 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) priv; 109 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) priv;
110 110
111 dvbdmxfeed->cb.ts(data, 188, NULL, 0, 111 dvbdmxfeed->cb.ts(data, 188, NULL, 0,
112 &dvbdmxfeed->feed.ts); 112 &dvbdmxfeed->feed.ts, NULL);
113 return 0; 113 return 0;
114} 114}
115 115
@@ -814,7 +814,7 @@ static void p_to_t(u8 const *buf, long int length, u16 pid, u8 *counter,
814 memcpy(obuf + l, buf + c, TS_SIZE - l); 814 memcpy(obuf + l, buf + c, TS_SIZE - l);
815 c = length; 815 c = length;
816 } 816 }
817 feed->cb.ts(obuf, 188, NULL, 0, &feed->feed.ts); 817 feed->cb.ts(obuf, 188, NULL, 0, &feed->feed.ts, NULL);
818 pes_start = 0; 818 pes_start = 0;
819 } 819 }
820} 820}
diff --git a/drivers/media/platform/tegra-cec/tegra_cec.c b/drivers/media/platform/tegra-cec/tegra_cec.c
index 92f93a880015..aba488cd0e64 100644
--- a/drivers/media/platform/tegra-cec/tegra_cec.c
+++ b/drivers/media/platform/tegra-cec/tegra_cec.c
@@ -172,16 +172,13 @@ static irqreturn_t tegra_cec_irq_handler(int irq, void *data)
172 } 172 }
173 } 173 }
174 174
175 if (status & (TEGRA_CEC_INT_STAT_RX_REGISTER_OVERRUN | 175 if (status & TEGRA_CEC_INT_STAT_RX_START_BIT_DETECTED) {
176 TEGRA_CEC_INT_STAT_RX_BUS_ANOMALY_DETECTED |
177 TEGRA_CEC_INT_STAT_RX_START_BIT_DETECTED |
178 TEGRA_CEC_INT_STAT_RX_BUS_ERROR_DETECTED)) {
179 cec_write(cec, TEGRA_CEC_INT_STAT, 176 cec_write(cec, TEGRA_CEC_INT_STAT,
180 (TEGRA_CEC_INT_STAT_RX_REGISTER_OVERRUN | 177 TEGRA_CEC_INT_STAT_RX_START_BIT_DETECTED);
181 TEGRA_CEC_INT_STAT_RX_BUS_ANOMALY_DETECTED | 178 cec->rx_done = false;
182 TEGRA_CEC_INT_STAT_RX_START_BIT_DETECTED | 179 cec->rx_buf_cnt = 0;
183 TEGRA_CEC_INT_STAT_RX_BUS_ERROR_DETECTED)); 180 }
184 } else if (status & TEGRA_CEC_INT_STAT_RX_REGISTER_FULL) { 181 if (status & TEGRA_CEC_INT_STAT_RX_REGISTER_FULL) {
185 u32 v; 182 u32 v;
186 183
187 cec_write(cec, TEGRA_CEC_INT_STAT, 184 cec_write(cec, TEGRA_CEC_INT_STAT,
@@ -255,7 +252,7 @@ static int tegra_cec_adap_enable(struct cec_adapter *adap, bool enable)
255 TEGRA_CEC_INT_MASK_TX_BUS_ANOMALY_DETECTED | 252 TEGRA_CEC_INT_MASK_TX_BUS_ANOMALY_DETECTED |
256 TEGRA_CEC_INT_MASK_TX_FRAME_TRANSMITTED | 253 TEGRA_CEC_INT_MASK_TX_FRAME_TRANSMITTED |
257 TEGRA_CEC_INT_MASK_RX_REGISTER_FULL | 254 TEGRA_CEC_INT_MASK_RX_REGISTER_FULL |
258 TEGRA_CEC_INT_MASK_RX_REGISTER_OVERRUN); 255 TEGRA_CEC_INT_MASK_RX_START_BIT_DETECTED);
259 256
260 cec_write(cec, TEGRA_CEC_HW_CONTROL, TEGRA_CEC_HWCTRL_TX_RX_MODE); 257 cec_write(cec, TEGRA_CEC_HW_CONTROL, TEGRA_CEC_HWCTRL_TX_RX_MODE);
261 return 0; 258 return 0;
diff --git a/drivers/media/usb/au0828/Kconfig b/drivers/media/usb/au0828/Kconfig
index 70521e0b4c53..bfaa806633df 100644
--- a/drivers/media/usb/au0828/Kconfig
+++ b/drivers/media/usb/au0828/Kconfig
@@ -1,7 +1,7 @@
1 1
2config VIDEO_AU0828 2config VIDEO_AU0828
3 tristate "Auvitek AU0828 support" 3 tristate "Auvitek AU0828 support"
4 depends on I2C && INPUT && DVB_CORE && USB 4 depends on I2C && INPUT && DVB_CORE && USB && VIDEO_V4L2
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
7 select VIDEOBUF2_VMALLOC 7 select VIDEOBUF2_VMALLOC
diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index a8900f5571f7..44ca66cb9b8f 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -428,7 +428,7 @@ static int ttusb_dec_audio_pes2ts_cb(void *priv, unsigned char *data)
428 struct ttusb_dec *dec = priv; 428 struct ttusb_dec *dec = priv;
429 429
430 dec->audio_filter->feed->cb.ts(data, 188, NULL, 0, 430 dec->audio_filter->feed->cb.ts(data, 188, NULL, 0,
431 &dec->audio_filter->feed->feed.ts); 431 &dec->audio_filter->feed->feed.ts, NULL);
432 432
433 return 0; 433 return 0;
434} 434}
@@ -438,7 +438,7 @@ static int ttusb_dec_video_pes2ts_cb(void *priv, unsigned char *data)
438 struct ttusb_dec *dec = priv; 438 struct ttusb_dec *dec = priv;
439 439
440 dec->video_filter->feed->cb.ts(data, 188, NULL, 0, 440 dec->video_filter->feed->cb.ts(data, 188, NULL, 0,
441 &dec->video_filter->feed->feed.ts); 441 &dec->video_filter->feed->feed.ts, NULL);
442 442
443 return 0; 443 return 0;
444} 444}
@@ -490,7 +490,7 @@ static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length)
490 490
491 if (output_pva) { 491 if (output_pva) {
492 dec->video_filter->feed->cb.ts(pva, length, NULL, 0, 492 dec->video_filter->feed->cb.ts(pva, length, NULL, 0,
493 &dec->video_filter->feed->feed.ts); 493 &dec->video_filter->feed->feed.ts, NULL);
494 return; 494 return;
495 } 495 }
496 496
@@ -551,7 +551,7 @@ static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length)
551 case 0x02: /* MainAudioStream */ 551 case 0x02: /* MainAudioStream */
552 if (output_pva) { 552 if (output_pva) {
553 dec->audio_filter->feed->cb.ts(pva, length, NULL, 0, 553 dec->audio_filter->feed->cb.ts(pva, length, NULL, 0,
554 &dec->audio_filter->feed->feed.ts); 554 &dec->audio_filter->feed->feed.ts, NULL);
555 return; 555 return;
556 } 556 }
557 557
@@ -589,7 +589,7 @@ static void ttusb_dec_process_filter(struct ttusb_dec *dec, u8 *packet,
589 589
590 if (filter) 590 if (filter)
591 filter->feed->cb.sec(&packet[2], length - 2, NULL, 0, 591 filter->feed->cb.sec(&packet[2], length - 2, NULL, 0,
592 &filter->filter); 592 &filter->filter, NULL);
593} 593}
594 594
595static void ttusb_dec_process_packet(struct ttusb_dec *dec) 595static void ttusb_dec_process_packet(struct ttusb_dec *dec)
diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig
index bf52fbd07aed..8e37e7c5e0f7 100644
--- a/drivers/media/v4l2-core/Kconfig
+++ b/drivers/media/v4l2-core/Kconfig
@@ -7,6 +7,7 @@ config VIDEO_V4L2
7 tristate 7 tristate
8 depends on (I2C || I2C=n) && VIDEO_DEV 8 depends on (I2C || I2C=n) && VIDEO_DEV
9 select RATIONAL 9 select RATIONAL
10 select VIDEOBUF2_V4L2 if VIDEOBUF2_CORE
10 default (I2C || I2C=n) && VIDEO_DEV 11 default (I2C || I2C=n) && VIDEO_DEV
11 12
12config VIDEO_ADV_DEBUG 13config VIDEO_ADV_DEBUG
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index 80de2cb9c476..7df54582e956 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -13,7 +13,7 @@ ifeq ($(CONFIG_COMPAT),y)
13endif 13endif
14obj-$(CONFIG_V4L2_FWNODE) += v4l2-fwnode.o 14obj-$(CONFIG_V4L2_FWNODE) += v4l2-fwnode.o
15ifeq ($(CONFIG_TRACEPOINTS),y) 15ifeq ($(CONFIG_TRACEPOINTS),y)
16 videodev-objs += vb2-trace.o v4l2-trace.o 16 videodev-objs += v4l2-trace.o
17endif 17endif
18videodev-$(CONFIG_MEDIA_CONTROLLER) += v4l2-mc.o 18videodev-$(CONFIG_MEDIA_CONTROLLER) += v4l2-mc.o
19 19
@@ -35,4 +35,3 @@ obj-$(CONFIG_VIDEOBUF_DVB) += videobuf-dvb.o
35 35
36ccflags-y += -I$(srctree)/drivers/media/dvb-frontends 36ccflags-y += -I$(srctree)/drivers/media/dvb-frontends
37ccflags-y += -I$(srctree)/drivers/media/tuners 37ccflags-y += -I$(srctree)/drivers/media/tuners
38
diff --git a/drivers/memory/brcmstb_dpfe.c b/drivers/memory/brcmstb_dpfe.c
index 0a7bdbed3a6f..e9c1485c32b9 100644
--- a/drivers/memory/brcmstb_dpfe.c
+++ b/drivers/memory/brcmstb_dpfe.c
@@ -45,8 +45,16 @@
45#define REG_TO_DCPU_MBOX 0x10 45#define REG_TO_DCPU_MBOX 0x10
46#define REG_TO_HOST_MBOX 0x14 46#define REG_TO_HOST_MBOX 0x14
47 47
48/* Macros to process offsets returned by the DCPU */
49#define DRAM_MSG_ADDR_OFFSET 0x0
50#define DRAM_MSG_TYPE_OFFSET 0x1c
51#define DRAM_MSG_ADDR_MASK ((1UL << DRAM_MSG_TYPE_OFFSET) - 1)
52#define DRAM_MSG_TYPE_MASK ((1UL << \
53 (BITS_PER_LONG - DRAM_MSG_TYPE_OFFSET)) - 1)
54
48/* Message RAM */ 55/* Message RAM */
49#define DCPU_MSG_RAM(x) (0x100 + (x) * sizeof(u32)) 56#define DCPU_MSG_RAM_START 0x100
57#define DCPU_MSG_RAM(x) (DCPU_MSG_RAM_START + (x) * sizeof(u32))
50 58
51/* DRAM Info Offsets & Masks */ 59/* DRAM Info Offsets & Masks */
52#define DRAM_INFO_INTERVAL 0x0 60#define DRAM_INFO_INTERVAL 0x0
@@ -255,6 +263,40 @@ static unsigned int get_msg_chksum(const u32 msg[])
255 return sum; 263 return sum;
256} 264}
257 265
266static void __iomem *get_msg_ptr(struct private_data *priv, u32 response,
267 char *buf, ssize_t *size)
268{
269 unsigned int msg_type;
270 unsigned int offset;
271 void __iomem *ptr = NULL;
272
273 msg_type = (response >> DRAM_MSG_TYPE_OFFSET) & DRAM_MSG_TYPE_MASK;
274 offset = (response >> DRAM_MSG_ADDR_OFFSET) & DRAM_MSG_ADDR_MASK;
275
276 /*
277 * msg_type == 1: the offset is relative to the message RAM
278 * msg_type == 0: the offset is relative to the data RAM (this is the
279 * previous way of passing data)
280 * msg_type is anything else: there's critical hardware problem
281 */
282 switch (msg_type) {
283 case 1:
284 ptr = priv->regs + DCPU_MSG_RAM_START + offset;
285 break;
286 case 0:
287 ptr = priv->dmem + offset;
288 break;
289 default:
290 dev_emerg(priv->dev, "invalid message reply from DCPU: %#x\n",
291 response);
292 if (buf && size)
293 *size = sprintf(buf,
294 "FATAL: communication error with DCPU\n");
295 }
296
297 return ptr;
298}
299
258static int __send_command(struct private_data *priv, unsigned int cmd, 300static int __send_command(struct private_data *priv, unsigned int cmd,
259 u32 result[]) 301 u32 result[])
260{ 302{
@@ -507,7 +549,7 @@ static ssize_t show_info(struct device *dev, struct device_attribute *devattr,
507{ 549{
508 u32 response[MSG_FIELD_MAX]; 550 u32 response[MSG_FIELD_MAX];
509 unsigned int info; 551 unsigned int info;
510 int ret; 552 ssize_t ret;
511 553
512 ret = generic_show(DPFE_CMD_GET_INFO, response, dev, buf); 554 ret = generic_show(DPFE_CMD_GET_INFO, response, dev, buf);
513 if (ret) 555 if (ret)
@@ -528,18 +570,19 @@ static ssize_t show_refresh(struct device *dev,
528 u32 response[MSG_FIELD_MAX]; 570 u32 response[MSG_FIELD_MAX];
529 void __iomem *info; 571 void __iomem *info;
530 struct private_data *priv; 572 struct private_data *priv;
531 unsigned int offset;
532 u8 refresh, sr_abort, ppre, thermal_offs, tuf; 573 u8 refresh, sr_abort, ppre, thermal_offs, tuf;
533 u32 mr4; 574 u32 mr4;
534 int ret; 575 ssize_t ret;
535 576
536 ret = generic_show(DPFE_CMD_GET_REFRESH, response, dev, buf); 577 ret = generic_show(DPFE_CMD_GET_REFRESH, response, dev, buf);
537 if (ret) 578 if (ret)
538 return ret; 579 return ret;
539 580
540 priv = dev_get_drvdata(dev); 581 priv = dev_get_drvdata(dev);
541 offset = response[MSG_ARG0]; 582
542 info = priv->dmem + offset; 583 info = get_msg_ptr(priv, response[MSG_ARG0], buf, &ret);
584 if (!info)
585 return ret;
543 586
544 mr4 = readl_relaxed(info + DRAM_INFO_MR4) & DRAM_INFO_MR4_MASK; 587 mr4 = readl_relaxed(info + DRAM_INFO_MR4) & DRAM_INFO_MR4_MASK;
545 588
@@ -561,7 +604,6 @@ static ssize_t store_refresh(struct device *dev, struct device_attribute *attr,
561 u32 response[MSG_FIELD_MAX]; 604 u32 response[MSG_FIELD_MAX];
562 struct private_data *priv; 605 struct private_data *priv;
563 void __iomem *info; 606 void __iomem *info;
564 unsigned int offset;
565 unsigned long val; 607 unsigned long val;
566 int ret; 608 int ret;
567 609
@@ -574,8 +616,10 @@ static ssize_t store_refresh(struct device *dev, struct device_attribute *attr,
574 if (ret) 616 if (ret)
575 return ret; 617 return ret;
576 618
577 offset = response[MSG_ARG0]; 619 info = get_msg_ptr(priv, response[MSG_ARG0], NULL, NULL);
578 info = priv->dmem + offset; 620 if (!info)
621 return -EIO;
622
579 writel_relaxed(val, info + DRAM_INFO_INTERVAL); 623 writel_relaxed(val, info + DRAM_INFO_INTERVAL);
580 624
581 return count; 625 return count;
@@ -587,23 +631,25 @@ static ssize_t show_vendor(struct device *dev, struct device_attribute *devattr,
587 u32 response[MSG_FIELD_MAX]; 631 u32 response[MSG_FIELD_MAX];
588 struct private_data *priv; 632 struct private_data *priv;
589 void __iomem *info; 633 void __iomem *info;
590 unsigned int offset; 634 ssize_t ret;
591 int ret;
592 635
593 ret = generic_show(DPFE_CMD_GET_VENDOR, response, dev, buf); 636 ret = generic_show(DPFE_CMD_GET_VENDOR, response, dev, buf);
594 if (ret) 637 if (ret)
595 return ret; 638 return ret;
596 639
597 offset = response[MSG_ARG0];
598 priv = dev_get_drvdata(dev); 640 priv = dev_get_drvdata(dev);
599 info = priv->dmem + offset; 641
642 info = get_msg_ptr(priv, response[MSG_ARG0], buf, &ret);
643 if (!info)
644 return ret;
600 645
601 return sprintf(buf, "%#x %#x %#x %#x %#x\n", 646 return sprintf(buf, "%#x %#x %#x %#x %#x\n",
602 readl_relaxed(info + DRAM_VENDOR_MR5) & DRAM_VENDOR_MASK, 647 readl_relaxed(info + DRAM_VENDOR_MR5) & DRAM_VENDOR_MASK,
603 readl_relaxed(info + DRAM_VENDOR_MR6) & DRAM_VENDOR_MASK, 648 readl_relaxed(info + DRAM_VENDOR_MR6) & DRAM_VENDOR_MASK,
604 readl_relaxed(info + DRAM_VENDOR_MR7) & DRAM_VENDOR_MASK, 649 readl_relaxed(info + DRAM_VENDOR_MR7) & DRAM_VENDOR_MASK,
605 readl_relaxed(info + DRAM_VENDOR_MR8) & DRAM_VENDOR_MASK, 650 readl_relaxed(info + DRAM_VENDOR_MR8) & DRAM_VENDOR_MASK,
606 readl_relaxed(info + DRAM_VENDOR_ERROR)); 651 readl_relaxed(info + DRAM_VENDOR_ERROR) &
652 DRAM_VENDOR_MASK);
607} 653}
608 654
609static int brcmstb_dpfe_resume(struct platform_device *pdev) 655static int brcmstb_dpfe_resume(struct platform_device *pdev)
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 8d12017b9893..4470630dd545 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -2687,6 +2687,8 @@ mptctl_hp_targetinfo(unsigned long arg)
2687 __FILE__, __LINE__, iocnum); 2687 __FILE__, __LINE__, iocnum);
2688 return -ENODEV; 2688 return -ENODEV;
2689 } 2689 }
2690 if (karg.hdr.id >= MPT_MAX_FC_DEVICES)
2691 return -EINVAL;
2690 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n", 2692 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n",
2691 ioc->name)); 2693 ioc->name));
2692 2694
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index 3e5eabdae8d9..772d02922529 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -548,12 +548,6 @@ int mei_cldev_disable(struct mei_cl_device *cldev)
548 goto out; 548 goto out;
549 } 549 }
550 550
551 if (bus->dev_state == MEI_DEV_POWER_DOWN) {
552 dev_dbg(bus->dev, "Device is powering down, don't bother with disconnection\n");
553 err = 0;
554 goto out;
555 }
556
557 err = mei_cl_disconnect(cl); 551 err = mei_cl_disconnect(cl);
558 if (err < 0) 552 if (err < 0)
559 dev_err(bus->dev, "Could not disconnect from the ME client\n"); 553 dev_err(bus->dev, "Could not disconnect from the ME client\n");
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index be64969d986a..7e60c1817c31 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -945,6 +945,12 @@ int mei_cl_disconnect(struct mei_cl *cl)
945 return 0; 945 return 0;
946 } 946 }
947 947
948 if (dev->dev_state == MEI_DEV_POWER_DOWN) {
949 cl_dbg(dev, cl, "Device is powering down, don't bother with disconnection\n");
950 mei_cl_set_disconnected(cl);
951 return 0;
952 }
953
948 rets = pm_runtime_get(dev->dev); 954 rets = pm_runtime_get(dev->dev);
949 if (rets < 0 && rets != -EINPROGRESS) { 955 if (rets < 0 && rets != -EINPROGRESS) {
950 pm_runtime_put_noidle(dev->dev); 956 pm_runtime_put_noidle(dev->dev);
diff --git a/drivers/misc/mei/hw-me-regs.h b/drivers/misc/mei/hw-me-regs.h
index 0ccccbaf530d..e4b10b2d1a08 100644
--- a/drivers/misc/mei/hw-me-regs.h
+++ b/drivers/misc/mei/hw-me-regs.h
@@ -132,6 +132,11 @@
132#define MEI_DEV_ID_KBP 0xA2BA /* Kaby Point */ 132#define MEI_DEV_ID_KBP 0xA2BA /* Kaby Point */
133#define MEI_DEV_ID_KBP_2 0xA2BB /* Kaby Point 2 */ 133#define MEI_DEV_ID_KBP_2 0xA2BB /* Kaby Point 2 */
134 134
135#define MEI_DEV_ID_CNP_LP 0x9DE0 /* Cannon Point LP */
136#define MEI_DEV_ID_CNP_LP_4 0x9DE4 /* Cannon Point LP 4 (iTouch) */
137#define MEI_DEV_ID_CNP_H 0xA360 /* Cannon Point H */
138#define MEI_DEV_ID_CNP_H_4 0xA364 /* Cannon Point H 4 (iTouch) */
139
135/* 140/*
136 * MEI HW Section 141 * MEI HW Section
137 */ 142 */
diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c
index 4a0ccda4d04b..ea4e152270a3 100644
--- a/drivers/misc/mei/pci-me.c
+++ b/drivers/misc/mei/pci-me.c
@@ -98,6 +98,11 @@ static const struct pci_device_id mei_me_pci_tbl[] = {
98 {MEI_PCI_DEVICE(MEI_DEV_ID_KBP, MEI_ME_PCH8_CFG)}, 98 {MEI_PCI_DEVICE(MEI_DEV_ID_KBP, MEI_ME_PCH8_CFG)},
99 {MEI_PCI_DEVICE(MEI_DEV_ID_KBP_2, MEI_ME_PCH8_CFG)}, 99 {MEI_PCI_DEVICE(MEI_DEV_ID_KBP_2, MEI_ME_PCH8_CFG)},
100 100
101 {MEI_PCI_DEVICE(MEI_DEV_ID_CNP_LP, MEI_ME_PCH8_CFG)},
102 {MEI_PCI_DEVICE(MEI_DEV_ID_CNP_LP_4, MEI_ME_PCH8_CFG)},
103 {MEI_PCI_DEVICE(MEI_DEV_ID_CNP_H, MEI_ME_PCH8_CFG)},
104 {MEI_PCI_DEVICE(MEI_DEV_ID_CNP_H_4, MEI_ME_PCH8_CFG)},
105
101 /* required last entry */ 106 /* required last entry */
102 {0, } 107 {0, }
103}; 108};
diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c
index d9aa407db06a..038509e5d031 100644
--- a/drivers/misc/ocxl/file.c
+++ b/drivers/misc/ocxl/file.c
@@ -102,10 +102,32 @@ static long afu_ioctl_attach(struct ocxl_context *ctx,
102 return rc; 102 return rc;
103} 103}
104 104
105static long afu_ioctl_get_metadata(struct ocxl_context *ctx,
106 struct ocxl_ioctl_metadata __user *uarg)
107{
108 struct ocxl_ioctl_metadata arg;
109
110 memset(&arg, 0, sizeof(arg));
111
112 arg.version = 0;
113
114 arg.afu_version_major = ctx->afu->config.version_major;
115 arg.afu_version_minor = ctx->afu->config.version_minor;
116 arg.pasid = ctx->pasid;
117 arg.pp_mmio_size = ctx->afu->config.pp_mmio_stride;
118 arg.global_mmio_size = ctx->afu->config.global_mmio_size;
119
120 if (copy_to_user(uarg, &arg, sizeof(arg)))
121 return -EFAULT;
122
123 return 0;
124}
125
105#define CMD_STR(x) (x == OCXL_IOCTL_ATTACH ? "ATTACH" : \ 126#define CMD_STR(x) (x == OCXL_IOCTL_ATTACH ? "ATTACH" : \
106 x == OCXL_IOCTL_IRQ_ALLOC ? "IRQ_ALLOC" : \ 127 x == OCXL_IOCTL_IRQ_ALLOC ? "IRQ_ALLOC" : \
107 x == OCXL_IOCTL_IRQ_FREE ? "IRQ_FREE" : \ 128 x == OCXL_IOCTL_IRQ_FREE ? "IRQ_FREE" : \
108 x == OCXL_IOCTL_IRQ_SET_FD ? "IRQ_SET_FD" : \ 129 x == OCXL_IOCTL_IRQ_SET_FD ? "IRQ_SET_FD" : \
130 x == OCXL_IOCTL_GET_METADATA ? "GET_METADATA" : \
109 "UNKNOWN") 131 "UNKNOWN")
110 132
111static long afu_ioctl(struct file *file, unsigned int cmd, 133static long afu_ioctl(struct file *file, unsigned int cmd,
@@ -133,8 +155,10 @@ static long afu_ioctl(struct file *file, unsigned int cmd,
133 if (!rc) { 155 if (!rc) {
134 rc = copy_to_user((u64 __user *) args, &irq_offset, 156 rc = copy_to_user((u64 __user *) args, &irq_offset,
135 sizeof(irq_offset)); 157 sizeof(irq_offset));
136 if (rc) 158 if (rc) {
137 ocxl_afu_irq_free(ctx, irq_offset); 159 ocxl_afu_irq_free(ctx, irq_offset);
160 return -EFAULT;
161 }
138 } 162 }
139 break; 163 break;
140 164
@@ -157,6 +181,11 @@ static long afu_ioctl(struct file *file, unsigned int cmd,
157 irq_fd.eventfd); 181 irq_fd.eventfd);
158 break; 182 break;
159 183
184 case OCXL_IOCTL_GET_METADATA:
185 rc = afu_ioctl_get_metadata(ctx,
186 (struct ocxl_ioctl_metadata __user *) args);
187 break;
188
160 default: 189 default:
161 rc = -EINVAL; 190 rc = -EINVAL;
162 } 191 }
@@ -277,7 +306,7 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,
277 struct ocxl_context *ctx = file->private_data; 306 struct ocxl_context *ctx = file->private_data;
278 struct ocxl_kernel_event_header header; 307 struct ocxl_kernel_event_header header;
279 ssize_t rc; 308 ssize_t rc;
280 size_t used = 0; 309 ssize_t used = 0;
281 DEFINE_WAIT(event_wait); 310 DEFINE_WAIT(event_wait);
282 311
283 memset(&header, 0, sizeof(header)); 312 memset(&header, 0, sizeof(header));
@@ -329,7 +358,7 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,
329 358
330 used += sizeof(header); 359 used += sizeof(header);
331 360
332 rc = (ssize_t) used; 361 rc = used;
333 return rc; 362 return rc;
334} 363}
335 364
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 20135a5de748..2cfb963d9f37 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -72,6 +72,7 @@ MODULE_ALIAS("mmc:block");
72#define MMC_BLK_TIMEOUT_MS (10 * 1000) 72#define MMC_BLK_TIMEOUT_MS (10 * 1000)
73#define MMC_SANITIZE_REQ_TIMEOUT 240000 73#define MMC_SANITIZE_REQ_TIMEOUT 240000
74#define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16) 74#define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16)
75#define MMC_EXTRACT_VALUE_FROM_ARG(x) ((x & 0x0000FF00) >> 8)
75 76
76#define mmc_req_rel_wr(req) ((req->cmd_flags & REQ_FUA) && \ 77#define mmc_req_rel_wr(req) ((req->cmd_flags & REQ_FUA) && \
77 (rq_data_dir(req) == WRITE)) 78 (rq_data_dir(req) == WRITE))
@@ -587,6 +588,24 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
587 } 588 }
588 589
589 /* 590 /*
591 * Make sure the cache of the PARTITION_CONFIG register and
592 * PARTITION_ACCESS bits is updated in case the ioctl ext_csd write
593 * changed it successfully.
594 */
595 if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_PART_CONFIG) &&
596 (cmd.opcode == MMC_SWITCH)) {
597 struct mmc_blk_data *main_md = dev_get_drvdata(&card->dev);
598 u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd.arg);
599
600 /*
601 * Update cache so the next mmc_blk_part_switch call operates
602 * on up-to-date data.
603 */
604 card->ext_csd.part_config = value;
605 main_md->part_curr = value & EXT_CSD_PART_CONFIG_ACC_MASK;
606 }
607
608 /*
590 * According to the SD specs, some commands require a delay after 609 * According to the SD specs, some commands require a delay after
591 * issuing the command. 610 * issuing the command.
592 */ 611 */
diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h
index 79a5b985ccf5..9c821eedd156 100644
--- a/drivers/mmc/core/card.h
+++ b/drivers/mmc/core/card.h
@@ -82,6 +82,7 @@ struct mmc_fixup {
82#define CID_MANFID_APACER 0x27 82#define CID_MANFID_APACER 0x27
83#define CID_MANFID_KINGSTON 0x70 83#define CID_MANFID_KINGSTON 0x70
84#define CID_MANFID_HYNIX 0x90 84#define CID_MANFID_HYNIX 0x90
85#define CID_MANFID_NUMONYX 0xFE
85 86
86#define END_FIXUP { NULL } 87#define END_FIXUP { NULL }
87 88
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 908e4db03535..42d6aa89a48a 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -848,7 +848,6 @@ int mmc_interrupt_hpi(struct mmc_card *card)
848 return 1; 848 return 1;
849 } 849 }
850 850
851 mmc_claim_host(card->host);
852 err = mmc_send_status(card, &status); 851 err = mmc_send_status(card, &status);
853 if (err) { 852 if (err) {
854 pr_err("%s: Get card status fail\n", mmc_hostname(card->host)); 853 pr_err("%s: Get card status fail\n", mmc_hostname(card->host));
@@ -890,7 +889,6 @@ int mmc_interrupt_hpi(struct mmc_card *card)
890 } while (!err); 889 } while (!err);
891 890
892out: 891out:
893 mmc_release_host(card->host);
894 return err; 892 return err;
895} 893}
896 894
@@ -932,9 +930,7 @@ static int mmc_read_bkops_status(struct mmc_card *card)
932 int err; 930 int err;
933 u8 *ext_csd; 931 u8 *ext_csd;
934 932
935 mmc_claim_host(card->host);
936 err = mmc_get_ext_csd(card, &ext_csd); 933 err = mmc_get_ext_csd(card, &ext_csd);
937 mmc_release_host(card->host);
938 if (err) 934 if (err)
939 return err; 935 return err;
940 936
diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h
index 75d317623852..5153577754f0 100644
--- a/drivers/mmc/core/quirks.h
+++ b/drivers/mmc/core/quirks.h
@@ -109,6 +109,12 @@ static const struct mmc_fixup mmc_ext_csd_fixups[] = {
109 */ 109 */
110 MMC_FIXUP_EXT_CSD_REV(CID_NAME_ANY, CID_MANFID_HYNIX, 110 MMC_FIXUP_EXT_CSD_REV(CID_NAME_ANY, CID_MANFID_HYNIX,
111 0x014a, add_quirk, MMC_QUIRK_BROKEN_HPI, 5), 111 0x014a, add_quirk, MMC_QUIRK_BROKEN_HPI, 5),
112 /*
113 * Certain Micron (Numonyx) eMMC 4.5 cards might get broken when HPI
114 * feature is used so disable the HPI feature for such buggy cards.
115 */
116 MMC_FIXUP_EXT_CSD_REV(CID_NAME_ANY, CID_MANFID_NUMONYX,
117 0x014e, add_quirk, MMC_QUIRK_BROKEN_HPI, 6),
112 118
113 END_FIXUP 119 END_FIXUP
114}; 120};
diff --git a/drivers/mmc/host/bcm2835.c b/drivers/mmc/host/bcm2835.c
index 229dc18f0581..768972af8b85 100644
--- a/drivers/mmc/host/bcm2835.c
+++ b/drivers/mmc/host/bcm2835.c
@@ -1265,7 +1265,8 @@ static int bcm2835_add_host(struct bcm2835_host *host)
1265 char pio_limit_string[20]; 1265 char pio_limit_string[20];
1266 int ret; 1266 int ret;
1267 1267
1268 mmc->f_max = host->max_clk; 1268 if (!mmc->f_max || mmc->f_max > host->max_clk)
1269 mmc->f_max = host->max_clk;
1269 mmc->f_min = host->max_clk / SDCDIV_MAX_CDIV; 1270 mmc->f_min = host->max_clk / SDCDIV_MAX_CDIV;
1270 1271
1271 mmc->max_busy_timeout = ~0 / (mmc->f_max / 1000); 1272 mmc->max_busy_timeout = ~0 / (mmc->f_max / 1000);
diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
index 35026795be28..a84aa3f1ae85 100644
--- a/drivers/mmc/host/dw_mmc-exynos.c
+++ b/drivers/mmc/host/dw_mmc-exynos.c
@@ -165,9 +165,15 @@ static void dw_mci_exynos_set_clksel_timing(struct dw_mci *host, u32 timing)
165static int dw_mci_exynos_runtime_resume(struct device *dev) 165static int dw_mci_exynos_runtime_resume(struct device *dev)
166{ 166{
167 struct dw_mci *host = dev_get_drvdata(dev); 167 struct dw_mci *host = dev_get_drvdata(dev);
168 int ret;
169
170 ret = dw_mci_runtime_resume(dev);
171 if (ret)
172 return ret;
168 173
169 dw_mci_exynos_config_smu(host); 174 dw_mci_exynos_config_smu(host);
170 return dw_mci_runtime_resume(dev); 175
176 return ret;
171} 177}
172 178
173/** 179/**
@@ -487,6 +493,7 @@ static unsigned long exynos_dwmmc_caps[4] = {
487 493
488static const struct dw_mci_drv_data exynos_drv_data = { 494static const struct dw_mci_drv_data exynos_drv_data = {
489 .caps = exynos_dwmmc_caps, 495 .caps = exynos_dwmmc_caps,
496 .num_caps = ARRAY_SIZE(exynos_dwmmc_caps),
490 .init = dw_mci_exynos_priv_init, 497 .init = dw_mci_exynos_priv_init,
491 .set_ios = dw_mci_exynos_set_ios, 498 .set_ios = dw_mci_exynos_set_ios,
492 .parse_dt = dw_mci_exynos_parse_dt, 499 .parse_dt = dw_mci_exynos_parse_dt,
diff --git a/drivers/mmc/host/dw_mmc-k3.c b/drivers/mmc/host/dw_mmc-k3.c
index 73fd75c3c824..89cdb3d533bb 100644
--- a/drivers/mmc/host/dw_mmc-k3.c
+++ b/drivers/mmc/host/dw_mmc-k3.c
@@ -135,6 +135,9 @@ static int dw_mci_hi6220_parse_dt(struct dw_mci *host)
135 if (priv->ctrl_id < 0) 135 if (priv->ctrl_id < 0)
136 priv->ctrl_id = 0; 136 priv->ctrl_id = 0;
137 137
138 if (priv->ctrl_id >= TIMING_MODE)
139 return -EINVAL;
140
138 host->priv = priv; 141 host->priv = priv;
139 return 0; 142 return 0;
140} 143}
@@ -207,6 +210,7 @@ static int dw_mci_hi6220_execute_tuning(struct dw_mci_slot *slot, u32 opcode)
207 210
208static const struct dw_mci_drv_data hi6220_data = { 211static const struct dw_mci_drv_data hi6220_data = {
209 .caps = dw_mci_hi6220_caps, 212 .caps = dw_mci_hi6220_caps,
213 .num_caps = ARRAY_SIZE(dw_mci_hi6220_caps),
210 .switch_voltage = dw_mci_hi6220_switch_voltage, 214 .switch_voltage = dw_mci_hi6220_switch_voltage,
211 .set_ios = dw_mci_hi6220_set_ios, 215 .set_ios = dw_mci_hi6220_set_ios,
212 .parse_dt = dw_mci_hi6220_parse_dt, 216 .parse_dt = dw_mci_hi6220_parse_dt,
diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c
index a3f1c2b30145..339295212935 100644
--- a/drivers/mmc/host/dw_mmc-rockchip.c
+++ b/drivers/mmc/host/dw_mmc-rockchip.c
@@ -319,6 +319,7 @@ static const struct dw_mci_drv_data rk2928_drv_data = {
319 319
320static const struct dw_mci_drv_data rk3288_drv_data = { 320static const struct dw_mci_drv_data rk3288_drv_data = {
321 .caps = dw_mci_rk3288_dwmmc_caps, 321 .caps = dw_mci_rk3288_dwmmc_caps,
322 .num_caps = ARRAY_SIZE(dw_mci_rk3288_dwmmc_caps),
322 .set_ios = dw_mci_rk3288_set_ios, 323 .set_ios = dw_mci_rk3288_set_ios,
323 .execute_tuning = dw_mci_rk3288_execute_tuning, 324 .execute_tuning = dw_mci_rk3288_execute_tuning,
324 .parse_dt = dw_mci_rk3288_parse_dt, 325 .parse_dt = dw_mci_rk3288_parse_dt,
diff --git a/drivers/mmc/host/dw_mmc-zx.c b/drivers/mmc/host/dw_mmc-zx.c
index d38e94ae2b85..c06b5393312f 100644
--- a/drivers/mmc/host/dw_mmc-zx.c
+++ b/drivers/mmc/host/dw_mmc-zx.c
@@ -195,6 +195,7 @@ static unsigned long zx_dwmmc_caps[3] = {
195 195
196static const struct dw_mci_drv_data zx_drv_data = { 196static const struct dw_mci_drv_data zx_drv_data = {
197 .caps = zx_dwmmc_caps, 197 .caps = zx_dwmmc_caps,
198 .num_caps = ARRAY_SIZE(zx_dwmmc_caps),
198 .execute_tuning = dw_mci_zx_execute_tuning, 199 .execute_tuning = dw_mci_zx_execute_tuning,
199 .prepare_hs400_tuning = dw_mci_zx_prepare_hs400_tuning, 200 .prepare_hs400_tuning = dw_mci_zx_prepare_hs400_tuning,
200 .parse_dt = dw_mci_zx_parse_dt, 201 .parse_dt = dw_mci_zx_parse_dt,
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 0aa39975f33b..06d47414d0c1 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -165,6 +165,8 @@ static int dw_mci_regs_show(struct seq_file *s, void *v)
165{ 165{
166 struct dw_mci *host = s->private; 166 struct dw_mci *host = s->private;
167 167
168 pm_runtime_get_sync(host->dev);
169
168 seq_printf(s, "STATUS:\t0x%08x\n", mci_readl(host, STATUS)); 170 seq_printf(s, "STATUS:\t0x%08x\n", mci_readl(host, STATUS));
169 seq_printf(s, "RINTSTS:\t0x%08x\n", mci_readl(host, RINTSTS)); 171 seq_printf(s, "RINTSTS:\t0x%08x\n", mci_readl(host, RINTSTS));
170 seq_printf(s, "CMD:\t0x%08x\n", mci_readl(host, CMD)); 172 seq_printf(s, "CMD:\t0x%08x\n", mci_readl(host, CMD));
@@ -172,6 +174,8 @@ static int dw_mci_regs_show(struct seq_file *s, void *v)
172 seq_printf(s, "INTMASK:\t0x%08x\n", mci_readl(host, INTMASK)); 174 seq_printf(s, "INTMASK:\t0x%08x\n", mci_readl(host, INTMASK));
173 seq_printf(s, "CLKENA:\t0x%08x\n", mci_readl(host, CLKENA)); 175 seq_printf(s, "CLKENA:\t0x%08x\n", mci_readl(host, CLKENA));
174 176
177 pm_runtime_put_autosuspend(host->dev);
178
175 return 0; 179 return 0;
176} 180}
177 181
@@ -409,7 +413,9 @@ static inline void dw_mci_set_cto(struct dw_mci *host)
409 cto_div = (mci_readl(host, CLKDIV) & 0xff) * 2; 413 cto_div = (mci_readl(host, CLKDIV) & 0xff) * 2;
410 if (cto_div == 0) 414 if (cto_div == 0)
411 cto_div = 1; 415 cto_div = 1;
412 cto_ms = DIV_ROUND_UP(MSEC_PER_SEC * cto_clks * cto_div, host->bus_hz); 416
417 cto_ms = DIV_ROUND_UP_ULL((u64)MSEC_PER_SEC * cto_clks * cto_div,
418 host->bus_hz);
413 419
414 /* add a bit spare time */ 420 /* add a bit spare time */
415 cto_ms += 10; 421 cto_ms += 10;
@@ -558,6 +564,7 @@ static int dw_mci_idmac_init(struct dw_mci *host)
558 (sizeof(struct idmac_desc_64addr) * 564 (sizeof(struct idmac_desc_64addr) *
559 (i + 1))) >> 32; 565 (i + 1))) >> 32;
560 /* Initialize reserved and buffer size fields to "0" */ 566 /* Initialize reserved and buffer size fields to "0" */
567 p->des0 = 0;
561 p->des1 = 0; 568 p->des1 = 0;
562 p->des2 = 0; 569 p->des2 = 0;
563 p->des3 = 0; 570 p->des3 = 0;
@@ -580,6 +587,7 @@ static int dw_mci_idmac_init(struct dw_mci *host)
580 i++, p++) { 587 i++, p++) {
581 p->des3 = cpu_to_le32(host->sg_dma + 588 p->des3 = cpu_to_le32(host->sg_dma +
582 (sizeof(struct idmac_desc) * (i + 1))); 589 (sizeof(struct idmac_desc) * (i + 1)));
590 p->des0 = 0;
583 p->des1 = 0; 591 p->des1 = 0;
584 } 592 }
585 593
@@ -1795,8 +1803,8 @@ static bool dw_mci_reset(struct dw_mci *host)
1795 } 1803 }
1796 1804
1797 if (host->use_dma == TRANS_MODE_IDMAC) 1805 if (host->use_dma == TRANS_MODE_IDMAC)
1798 /* It is also recommended that we reset and reprogram idmac */ 1806 /* It is also required that we reinit idmac */
1799 dw_mci_idmac_reset(host); 1807 dw_mci_idmac_init(host);
1800 1808
1801 ret = true; 1809 ret = true;
1802 1810
@@ -1944,8 +1952,9 @@ static void dw_mci_set_drto(struct dw_mci *host)
1944 drto_div = (mci_readl(host, CLKDIV) & 0xff) * 2; 1952 drto_div = (mci_readl(host, CLKDIV) & 0xff) * 2;
1945 if (drto_div == 0) 1953 if (drto_div == 0)
1946 drto_div = 1; 1954 drto_div = 1;
1947 drto_ms = DIV_ROUND_UP(MSEC_PER_SEC * drto_clks * drto_div, 1955
1948 host->bus_hz); 1956 drto_ms = DIV_ROUND_UP_ULL((u64)MSEC_PER_SEC * drto_clks * drto_div,
1957 host->bus_hz);
1949 1958
1950 /* add a bit spare time */ 1959 /* add a bit spare time */
1951 drto_ms += 10; 1960 drto_ms += 10;
@@ -2778,12 +2787,57 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
2778 return IRQ_HANDLED; 2787 return IRQ_HANDLED;
2779} 2788}
2780 2789
2790static int dw_mci_init_slot_caps(struct dw_mci_slot *slot)
2791{
2792 struct dw_mci *host = slot->host;
2793 const struct dw_mci_drv_data *drv_data = host->drv_data;
2794 struct mmc_host *mmc = slot->mmc;
2795 int ctrl_id;
2796
2797 if (host->pdata->caps)
2798 mmc->caps = host->pdata->caps;
2799
2800 /*
2801 * Support MMC_CAP_ERASE by default.
2802 * It needs to use trim/discard/erase commands.
2803 */
2804 mmc->caps |= MMC_CAP_ERASE;
2805
2806 if (host->pdata->pm_caps)
2807 mmc->pm_caps = host->pdata->pm_caps;
2808
2809 if (host->dev->of_node) {
2810 ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
2811 if (ctrl_id < 0)
2812 ctrl_id = 0;
2813 } else {
2814 ctrl_id = to_platform_device(host->dev)->id;
2815 }
2816
2817 if (drv_data && drv_data->caps) {
2818 if (ctrl_id >= drv_data->num_caps) {
2819 dev_err(host->dev, "invalid controller id %d\n",
2820 ctrl_id);
2821 return -EINVAL;
2822 }
2823 mmc->caps |= drv_data->caps[ctrl_id];
2824 }
2825
2826 if (host->pdata->caps2)
2827 mmc->caps2 = host->pdata->caps2;
2828
2829 /* Process SDIO IRQs through the sdio_irq_work. */
2830 if (mmc->caps & MMC_CAP_SDIO_IRQ)
2831 mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD;
2832
2833 return 0;
2834}
2835
2781static int dw_mci_init_slot(struct dw_mci *host) 2836static int dw_mci_init_slot(struct dw_mci *host)
2782{ 2837{
2783 struct mmc_host *mmc; 2838 struct mmc_host *mmc;
2784 struct dw_mci_slot *slot; 2839 struct dw_mci_slot *slot;
2785 const struct dw_mci_drv_data *drv_data = host->drv_data; 2840 int ret;
2786 int ctrl_id, ret;
2787 u32 freq[2]; 2841 u32 freq[2];
2788 2842
2789 mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev); 2843 mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev);
@@ -2817,38 +2871,13 @@ static int dw_mci_init_slot(struct dw_mci *host)
2817 if (!mmc->ocr_avail) 2871 if (!mmc->ocr_avail)
2818 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 2872 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
2819 2873
2820 if (host->pdata->caps)
2821 mmc->caps = host->pdata->caps;
2822
2823 /*
2824 * Support MMC_CAP_ERASE by default.
2825 * It needs to use trim/discard/erase commands.
2826 */
2827 mmc->caps |= MMC_CAP_ERASE;
2828
2829 if (host->pdata->pm_caps)
2830 mmc->pm_caps = host->pdata->pm_caps;
2831
2832 if (host->dev->of_node) {
2833 ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
2834 if (ctrl_id < 0)
2835 ctrl_id = 0;
2836 } else {
2837 ctrl_id = to_platform_device(host->dev)->id;
2838 }
2839 if (drv_data && drv_data->caps)
2840 mmc->caps |= drv_data->caps[ctrl_id];
2841
2842 if (host->pdata->caps2)
2843 mmc->caps2 = host->pdata->caps2;
2844
2845 ret = mmc_of_parse(mmc); 2874 ret = mmc_of_parse(mmc);
2846 if (ret) 2875 if (ret)
2847 goto err_host_allocated; 2876 goto err_host_allocated;
2848 2877
2849 /* Process SDIO IRQs through the sdio_irq_work. */ 2878 ret = dw_mci_init_slot_caps(slot);
2850 if (mmc->caps & MMC_CAP_SDIO_IRQ) 2879 if (ret)
2851 mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD; 2880 goto err_host_allocated;
2852 2881
2853 /* Useful defaults if platform data is unset. */ 2882 /* Useful defaults if platform data is unset. */
2854 if (host->use_dma == TRANS_MODE_IDMAC) { 2883 if (host->use_dma == TRANS_MODE_IDMAC) {
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index e3124f06a47e..1424bd490dd1 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -543,6 +543,7 @@ struct dw_mci_slot {
543/** 543/**
544 * dw_mci driver data - dw-mshc implementation specific driver data. 544 * dw_mci driver data - dw-mshc implementation specific driver data.
545 * @caps: mmc subsystem specified capabilities of the controller(s). 545 * @caps: mmc subsystem specified capabilities of the controller(s).
546 * @num_caps: number of capabilities specified by @caps.
546 * @init: early implementation specific initialization. 547 * @init: early implementation specific initialization.
547 * @set_ios: handle bus specific extensions. 548 * @set_ios: handle bus specific extensions.
548 * @parse_dt: parse implementation specific device tree properties. 549 * @parse_dt: parse implementation specific device tree properties.
@@ -554,6 +555,7 @@ struct dw_mci_slot {
554 */ 555 */
555struct dw_mci_drv_data { 556struct dw_mci_drv_data {
556 unsigned long *caps; 557 unsigned long *caps;
558 u32 num_caps;
557 int (*init)(struct dw_mci *host); 559 int (*init)(struct dw_mci *host);
558 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios); 560 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
559 int (*parse_dt)(struct dw_mci *host); 561 int (*parse_dt)(struct dw_mci *host);
diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c
index 22438ebfe4e6..4f972b879fe6 100644
--- a/drivers/mmc/host/meson-gx-mmc.c
+++ b/drivers/mmc/host/meson-gx-mmc.c
@@ -717,22 +717,6 @@ static int meson_mmc_clk_phase_tuning(struct mmc_host *mmc, u32 opcode,
717static int meson_mmc_execute_tuning(struct mmc_host *mmc, u32 opcode) 717static int meson_mmc_execute_tuning(struct mmc_host *mmc, u32 opcode)
718{ 718{
719 struct meson_host *host = mmc_priv(mmc); 719 struct meson_host *host = mmc_priv(mmc);
720 int ret;
721
722 /*
723 * If this is the initial tuning, try to get a sane Rx starting
724 * phase before doing the actual tuning.
725 */
726 if (!mmc->doing_retune) {
727 ret = meson_mmc_clk_phase_tuning(mmc, opcode, host->rx_clk);
728
729 if (ret)
730 return ret;
731 }
732
733 ret = meson_mmc_clk_phase_tuning(mmc, opcode, host->tx_clk);
734 if (ret)
735 return ret;
736 720
737 return meson_mmc_clk_phase_tuning(mmc, opcode, host->rx_clk); 721 return meson_mmc_clk_phase_tuning(mmc, opcode, host->rx_clk);
738} 722}
@@ -763,9 +747,8 @@ static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
763 if (!IS_ERR(mmc->supply.vmmc)) 747 if (!IS_ERR(mmc->supply.vmmc))
764 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd); 748 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
765 749
766 /* Reset phases */ 750 /* Reset rx phase */
767 clk_set_phase(host->rx_clk, 0); 751 clk_set_phase(host->rx_clk, 0);
768 clk_set_phase(host->tx_clk, 270);
769 752
770 break; 753 break;
771 754
diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
index 4065da58789d..32321bd596d8 100644
--- a/drivers/mmc/host/sdhci-acpi.c
+++ b/drivers/mmc/host/sdhci-acpi.c
@@ -680,7 +680,7 @@ static int sdhci_acpi_probe(struct platform_device *pdev)
680 host->hw_name = "ACPI"; 680 host->hw_name = "ACPI";
681 host->ops = &sdhci_acpi_ops_dflt; 681 host->ops = &sdhci_acpi_ops_dflt;
682 host->irq = platform_get_irq(pdev, 0); 682 host->irq = platform_get_irq(pdev, 0);
683 if (host->irq <= 0) { 683 if (host->irq < 0) {
684 err = -EINVAL; 684 err = -EINVAL;
685 goto err_free; 685 goto err_free;
686 } 686 }
diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
index 6d1a983e6227..82c4f05f91d8 100644
--- a/drivers/mmc/host/sdhci-pci-core.c
+++ b/drivers/mmc/host/sdhci-pci-core.c
@@ -654,9 +654,36 @@ static void byt_read_dsm(struct sdhci_pci_slot *slot)
654 slot->chip->rpm_retune = intel_host->d3_retune; 654 slot->chip->rpm_retune = intel_host->d3_retune;
655} 655}
656 656
657static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot) 657static int intel_execute_tuning(struct mmc_host *mmc, u32 opcode)
658{
659 int err = sdhci_execute_tuning(mmc, opcode);
660 struct sdhci_host *host = mmc_priv(mmc);
661
662 if (err)
663 return err;
664
665 /*
666 * Tuning can leave the IP in an active state (Buffer Read Enable bit
667 * set) which prevents the entry to low power states (i.e. S0i3). Data
668 * reset will clear it.
669 */
670 sdhci_reset(host, SDHCI_RESET_DATA);
671
672 return 0;
673}
674
675static void byt_probe_slot(struct sdhci_pci_slot *slot)
658{ 676{
677 struct mmc_host_ops *ops = &slot->host->mmc_host_ops;
678
659 byt_read_dsm(slot); 679 byt_read_dsm(slot);
680
681 ops->execute_tuning = intel_execute_tuning;
682}
683
684static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
685{
686 byt_probe_slot(slot);
660 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | 687 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
661 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR | 688 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR |
662 MMC_CAP_CMD_DURING_TFR | 689 MMC_CAP_CMD_DURING_TFR |
@@ -779,7 +806,7 @@ static int ni_byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
779{ 806{
780 int err; 807 int err;
781 808
782 byt_read_dsm(slot); 809 byt_probe_slot(slot);
783 810
784 err = ni_set_max_freq(slot); 811 err = ni_set_max_freq(slot);
785 if (err) 812 if (err)
@@ -792,7 +819,7 @@ static int ni_byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
792 819
793static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot) 820static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
794{ 821{
795 byt_read_dsm(slot); 822 byt_probe_slot(slot);
796 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE | 823 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE |
797 MMC_CAP_WAIT_WHILE_BUSY; 824 MMC_CAP_WAIT_WHILE_BUSY;
798 return 0; 825 return 0;
@@ -800,7 +827,7 @@ static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
800 827
801static int byt_sd_probe_slot(struct sdhci_pci_slot *slot) 828static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
802{ 829{
803 byt_read_dsm(slot); 830 byt_probe_slot(slot);
804 slot->host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY | 831 slot->host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY |
805 MMC_CAP_AGGRESSIVE_PM | MMC_CAP_CD_WAKE; 832 MMC_CAP_AGGRESSIVE_PM | MMC_CAP_CD_WAKE;
806 slot->cd_idx = 0; 833 slot->cd_idx = 0;
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index de8c902059b8..7d80a8bb96fe 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -479,7 +479,7 @@ static int shrink_ecclayout(struct mtd_info *mtd,
479 for (i = 0; i < MTD_MAX_ECCPOS_ENTRIES;) { 479 for (i = 0; i < MTD_MAX_ECCPOS_ENTRIES;) {
480 u32 eccpos; 480 u32 eccpos;
481 481
482 ret = mtd_ooblayout_ecc(mtd, section, &oobregion); 482 ret = mtd_ooblayout_ecc(mtd, section++, &oobregion);
483 if (ret < 0) { 483 if (ret < 0) {
484 if (ret != -ERANGE) 484 if (ret != -ERANGE)
485 return ret; 485 return ret;
@@ -526,7 +526,7 @@ static int get_oobinfo(struct mtd_info *mtd, struct nand_oobinfo *to)
526 for (i = 0; i < ARRAY_SIZE(to->eccpos);) { 526 for (i = 0; i < ARRAY_SIZE(to->eccpos);) {
527 u32 eccpos; 527 u32 eccpos;
528 528
529 ret = mtd_ooblayout_ecc(mtd, section, &oobregion); 529 ret = mtd_ooblayout_ecc(mtd, section++, &oobregion);
530 if (ret < 0) { 530 if (ret < 0) {
531 if (ret != -ERANGE) 531 if (ret != -ERANGE)
532 return ret; 532 return ret;
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index e6b8c59f2c0d..736ac887303c 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -328,7 +328,7 @@ config MTD_NAND_MARVELL
328 tristate "NAND controller support on Marvell boards" 328 tristate "NAND controller support on Marvell boards"
329 depends on PXA3xx || ARCH_MMP || PLAT_ORION || ARCH_MVEBU || \ 329 depends on PXA3xx || ARCH_MMP || PLAT_ORION || ARCH_MVEBU || \
330 COMPILE_TEST 330 COMPILE_TEST
331 depends on HAS_IOMEM 331 depends on HAS_IOMEM && HAS_DMA
332 help 332 help
333 This enables the NAND flash controller driver for Marvell boards, 333 This enables the NAND flash controller driver for Marvell boards,
334 including: 334 including:
diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c
index 4872a7ba6503..5a9c2f0020c2 100644
--- a/drivers/mtd/nand/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/fsl_ifc_nand.c
@@ -173,14 +173,9 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob)
173 173
174/* returns nonzero if entire page is blank */ 174/* returns nonzero if entire page is blank */
175static int check_read_ecc(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl, 175static int check_read_ecc(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl,
176 u32 *eccstat, unsigned int bufnum) 176 u32 eccstat, unsigned int bufnum)
177{ 177{
178 u32 reg = eccstat[bufnum / 4]; 178 return (eccstat >> ((3 - bufnum % 4) * 8)) & 15;
179 int errors;
180
181 errors = (reg >> ((3 - bufnum % 4) * 8)) & 15;
182
183 return errors;
184} 179}
185 180
186/* 181/*
@@ -193,7 +188,7 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
193 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 188 struct fsl_ifc_ctrl *ctrl = priv->ctrl;
194 struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl; 189 struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl;
195 struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; 190 struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
196 u32 eccstat[4]; 191 u32 eccstat;
197 int i; 192 int i;
198 193
199 /* set the chip select for NAND Transaction */ 194 /* set the chip select for NAND Transaction */
@@ -228,19 +223,17 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
228 if (nctrl->eccread) { 223 if (nctrl->eccread) {
229 int errors; 224 int errors;
230 int bufnum = nctrl->page & priv->bufnum_mask; 225 int bufnum = nctrl->page & priv->bufnum_mask;
231 int sector = bufnum * chip->ecc.steps; 226 int sector_start = bufnum * chip->ecc.steps;
232 int sector_end = sector + chip->ecc.steps - 1; 227 int sector_end = sector_start + chip->ecc.steps - 1;
233 __be32 *eccstat_regs; 228 __be32 *eccstat_regs;
234 229
235 if (ctrl->version >= FSL_IFC_VERSION_2_0_0) 230 eccstat_regs = ifc->ifc_nand.nand_eccstat;
236 eccstat_regs = ifc->ifc_nand.v2_nand_eccstat; 231 eccstat = ifc_in32(&eccstat_regs[sector_start / 4]);
237 else
238 eccstat_regs = ifc->ifc_nand.v1_nand_eccstat;
239 232
240 for (i = sector / 4; i <= sector_end / 4; i++) 233 for (i = sector_start; i <= sector_end; i++) {
241 eccstat[i] = ifc_in32(&eccstat_regs[i]); 234 if (i != sector_start && !(i % 4))
235 eccstat = ifc_in32(&eccstat_regs[i / 4]);
242 236
243 for (i = sector; i <= sector_end; i++) {
244 errors = check_read_ecc(mtd, ctrl, eccstat, i); 237 errors = check_read_ecc(mtd, ctrl, eccstat, i);
245 238
246 if (errors == 15) { 239 if (errors == 15) {
@@ -626,6 +619,7 @@ static int fsl_ifc_wait(struct mtd_info *mtd, struct nand_chip *chip)
626 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 619 struct fsl_ifc_ctrl *ctrl = priv->ctrl;
627 struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; 620 struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
628 u32 nand_fsr; 621 u32 nand_fsr;
622 int status;
629 623
630 /* Use READ_STATUS command, but wait for the device to be ready */ 624 /* Use READ_STATUS command, but wait for the device to be ready */
631 ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) | 625 ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
@@ -640,12 +634,12 @@ static int fsl_ifc_wait(struct mtd_info *mtd, struct nand_chip *chip)
640 fsl_ifc_run_command(mtd); 634 fsl_ifc_run_command(mtd);
641 635
642 nand_fsr = ifc_in32(&ifc->ifc_nand.nand_fsr); 636 nand_fsr = ifc_in32(&ifc->ifc_nand.nand_fsr);
643 637 status = nand_fsr >> 24;
644 /* 638 /*
645 * The chip always seems to report that it is 639 * The chip always seems to report that it is
646 * write-protected, even when it is not. 640 * write-protected, even when it is not.
647 */ 641 */
648 return nand_fsr | NAND_STATUS_WP; 642 return status | NAND_STATUS_WP;
649} 643}
650 644
651/* 645/*
diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 80d31a58e558..f367144f3c6f 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -752,10 +752,8 @@ static int vf610_nfc_probe(struct platform_device *pdev)
752 if (mtd->oobsize > 64) 752 if (mtd->oobsize > 64)
753 mtd->oobsize = 64; 753 mtd->oobsize = 64;
754 754
755 /* 755 /* Use default large page ECC layout defined in NAND core */
756 * mtd->ecclayout is not specified here because we're using the 756 mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
757 * default large page ECC layout defined in NAND core.
758 */
759 if (chip->ecc.strength == 32) { 757 if (chip->ecc.strength == 32) {
760 nfc->ecc_mode = ECC_60_BYTE; 758 nfc->ecc_mode = ECC_60_BYTE;
761 chip->ecc.bytes = 60; 759 chip->ecc.bytes = 60;
diff --git a/drivers/net/can/cc770/cc770.c b/drivers/net/can/cc770/cc770.c
index 1e37313054f3..6da69af103e6 100644
--- a/drivers/net/can/cc770/cc770.c
+++ b/drivers/net/can/cc770/cc770.c
@@ -390,37 +390,23 @@ static int cc770_get_berr_counter(const struct net_device *dev,
390 return 0; 390 return 0;
391} 391}
392 392
393static netdev_tx_t cc770_start_xmit(struct sk_buff *skb, struct net_device *dev) 393static void cc770_tx(struct net_device *dev, int mo)
394{ 394{
395 struct cc770_priv *priv = netdev_priv(dev); 395 struct cc770_priv *priv = netdev_priv(dev);
396 struct net_device_stats *stats = &dev->stats; 396 struct can_frame *cf = (struct can_frame *)priv->tx_skb->data;
397 struct can_frame *cf = (struct can_frame *)skb->data;
398 unsigned int mo = obj2msgobj(CC770_OBJ_TX);
399 u8 dlc, rtr; 397 u8 dlc, rtr;
400 u32 id; 398 u32 id;
401 int i; 399 int i;
402 400
403 if (can_dropped_invalid_skb(dev, skb))
404 return NETDEV_TX_OK;
405
406 if ((cc770_read_reg(priv,
407 msgobj[mo].ctrl1) & TXRQST_UNC) == TXRQST_SET) {
408 netdev_err(dev, "TX register is still occupied!\n");
409 return NETDEV_TX_BUSY;
410 }
411
412 netif_stop_queue(dev);
413
414 dlc = cf->can_dlc; 401 dlc = cf->can_dlc;
415 id = cf->can_id; 402 id = cf->can_id;
416 if (cf->can_id & CAN_RTR_FLAG) 403 rtr = cf->can_id & CAN_RTR_FLAG ? 0 : MSGCFG_DIR;
417 rtr = 0; 404
418 else 405 cc770_write_reg(priv, msgobj[mo].ctrl0,
419 rtr = MSGCFG_DIR; 406 MSGVAL_RES | TXIE_RES | RXIE_RES | INTPND_RES);
420 cc770_write_reg(priv, msgobj[mo].ctrl1, 407 cc770_write_reg(priv, msgobj[mo].ctrl1,
421 RMTPND_RES | TXRQST_RES | CPUUPD_SET | NEWDAT_RES); 408 RMTPND_RES | TXRQST_RES | CPUUPD_SET | NEWDAT_RES);
422 cc770_write_reg(priv, msgobj[mo].ctrl0, 409
423 MSGVAL_SET | TXIE_SET | RXIE_RES | INTPND_RES);
424 if (id & CAN_EFF_FLAG) { 410 if (id & CAN_EFF_FLAG) {
425 id &= CAN_EFF_MASK; 411 id &= CAN_EFF_MASK;
426 cc770_write_reg(priv, msgobj[mo].config, 412 cc770_write_reg(priv, msgobj[mo].config,
@@ -439,22 +425,30 @@ static netdev_tx_t cc770_start_xmit(struct sk_buff *skb, struct net_device *dev)
439 for (i = 0; i < dlc; i++) 425 for (i = 0; i < dlc; i++)
440 cc770_write_reg(priv, msgobj[mo].data[i], cf->data[i]); 426 cc770_write_reg(priv, msgobj[mo].data[i], cf->data[i]);
441 427
442 /* Store echo skb before starting the transfer */
443 can_put_echo_skb(skb, dev, 0);
444
445 cc770_write_reg(priv, msgobj[mo].ctrl1, 428 cc770_write_reg(priv, msgobj[mo].ctrl1,
446 RMTPND_RES | TXRQST_SET | CPUUPD_RES | NEWDAT_UNC); 429 RMTPND_UNC | TXRQST_SET | CPUUPD_RES | NEWDAT_UNC);
430 cc770_write_reg(priv, msgobj[mo].ctrl0,
431 MSGVAL_SET | TXIE_SET | RXIE_SET | INTPND_UNC);
432}
447 433
448 stats->tx_bytes += dlc; 434static netdev_tx_t cc770_start_xmit(struct sk_buff *skb, struct net_device *dev)
435{
436 struct cc770_priv *priv = netdev_priv(dev);
437 unsigned int mo = obj2msgobj(CC770_OBJ_TX);
449 438
439 if (can_dropped_invalid_skb(dev, skb))
440 return NETDEV_TX_OK;
450 441
451 /* 442 netif_stop_queue(dev);
452 * HM: We had some cases of repeated IRQs so make sure the 443
453 * INT is acknowledged I know it's already further up, but 444 if ((cc770_read_reg(priv,
454 * doing again fixed the issue 445 msgobj[mo].ctrl1) & TXRQST_UNC) == TXRQST_SET) {
455 */ 446 netdev_err(dev, "TX register is still occupied!\n");
456 cc770_write_reg(priv, msgobj[mo].ctrl0, 447 return NETDEV_TX_BUSY;
457 MSGVAL_UNC | TXIE_UNC | RXIE_UNC | INTPND_RES); 448 }
449
450 priv->tx_skb = skb;
451 cc770_tx(dev, mo);
458 452
459 return NETDEV_TX_OK; 453 return NETDEV_TX_OK;
460} 454}
@@ -680,19 +674,46 @@ static void cc770_tx_interrupt(struct net_device *dev, unsigned int o)
680 struct cc770_priv *priv = netdev_priv(dev); 674 struct cc770_priv *priv = netdev_priv(dev);
681 struct net_device_stats *stats = &dev->stats; 675 struct net_device_stats *stats = &dev->stats;
682 unsigned int mo = obj2msgobj(o); 676 unsigned int mo = obj2msgobj(o);
677 struct can_frame *cf;
678 u8 ctrl1;
679
680 ctrl1 = cc770_read_reg(priv, msgobj[mo].ctrl1);
683 681
684 /* Nothing more to send, switch off interrupts */
685 cc770_write_reg(priv, msgobj[mo].ctrl0, 682 cc770_write_reg(priv, msgobj[mo].ctrl0,
686 MSGVAL_RES | TXIE_RES | RXIE_RES | INTPND_RES); 683 MSGVAL_RES | TXIE_RES | RXIE_RES | INTPND_RES);
687 /* 684 cc770_write_reg(priv, msgobj[mo].ctrl1,
688 * We had some cases of repeated IRQ so make sure the 685 RMTPND_RES | TXRQST_RES | MSGLST_RES | NEWDAT_RES);
689 * INT is acknowledged 686
687 if (unlikely(!priv->tx_skb)) {
688 netdev_err(dev, "missing tx skb in tx interrupt\n");
689 return;
690 }
691
692 if (unlikely(ctrl1 & MSGLST_SET)) {
693 stats->rx_over_errors++;
694 stats->rx_errors++;
695 }
696
697 /* When the CC770 is sending an RTR message and it receives a regular
698 * message that matches the id of the RTR message, it will overwrite the
699 * outgoing message in the TX register. When this happens we must
700 * process the received message and try to transmit the outgoing skb
701 * again.
690 */ 702 */
691 cc770_write_reg(priv, msgobj[mo].ctrl0, 703 if (unlikely(ctrl1 & NEWDAT_SET)) {
692 MSGVAL_UNC | TXIE_UNC | RXIE_UNC | INTPND_RES); 704 cc770_rx(dev, mo, ctrl1);
705 cc770_tx(dev, mo);
706 return;
707 }
693 708
709 cf = (struct can_frame *)priv->tx_skb->data;
710 stats->tx_bytes += cf->can_dlc;
694 stats->tx_packets++; 711 stats->tx_packets++;
712
713 can_put_echo_skb(priv->tx_skb, dev, 0);
695 can_get_echo_skb(dev, 0); 714 can_get_echo_skb(dev, 0);
715 priv->tx_skb = NULL;
716
696 netif_wake_queue(dev); 717 netif_wake_queue(dev);
697} 718}
698 719
@@ -804,6 +825,7 @@ struct net_device *alloc_cc770dev(int sizeof_priv)
804 priv->can.do_set_bittiming = cc770_set_bittiming; 825 priv->can.do_set_bittiming = cc770_set_bittiming;
805 priv->can.do_set_mode = cc770_set_mode; 826 priv->can.do_set_mode = cc770_set_mode;
806 priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES; 827 priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES;
828 priv->tx_skb = NULL;
807 829
808 memcpy(priv->obj_flags, cc770_obj_flags, sizeof(cc770_obj_flags)); 830 memcpy(priv->obj_flags, cc770_obj_flags, sizeof(cc770_obj_flags));
809 831
diff --git a/drivers/net/can/cc770/cc770.h b/drivers/net/can/cc770/cc770.h
index a1739db98d91..95752e1d1283 100644
--- a/drivers/net/can/cc770/cc770.h
+++ b/drivers/net/can/cc770/cc770.h
@@ -193,6 +193,8 @@ struct cc770_priv {
193 u8 cpu_interface; /* CPU interface register */ 193 u8 cpu_interface; /* CPU interface register */
194 u8 clkout; /* Clock out register */ 194 u8 clkout; /* Clock out register */
195 u8 bus_config; /* Bus conffiguration register */ 195 u8 bus_config; /* Bus conffiguration register */
196
197 struct sk_buff *tx_skb;
196}; 198};
197 199
198struct net_device *alloc_cc770dev(int sizeof_priv); 200struct net_device *alloc_cc770dev(int sizeof_priv);
diff --git a/drivers/net/can/ifi_canfd/ifi_canfd.c b/drivers/net/can/ifi_canfd/ifi_canfd.c
index 2772d05ff11c..fedd927ba6ed 100644
--- a/drivers/net/can/ifi_canfd/ifi_canfd.c
+++ b/drivers/net/can/ifi_canfd/ifi_canfd.c
@@ -30,6 +30,7 @@
30#define IFI_CANFD_STCMD_ERROR_ACTIVE BIT(2) 30#define IFI_CANFD_STCMD_ERROR_ACTIVE BIT(2)
31#define IFI_CANFD_STCMD_ERROR_PASSIVE BIT(3) 31#define IFI_CANFD_STCMD_ERROR_PASSIVE BIT(3)
32#define IFI_CANFD_STCMD_BUSOFF BIT(4) 32#define IFI_CANFD_STCMD_BUSOFF BIT(4)
33#define IFI_CANFD_STCMD_ERROR_WARNING BIT(5)
33#define IFI_CANFD_STCMD_BUSMONITOR BIT(16) 34#define IFI_CANFD_STCMD_BUSMONITOR BIT(16)
34#define IFI_CANFD_STCMD_LOOPBACK BIT(18) 35#define IFI_CANFD_STCMD_LOOPBACK BIT(18)
35#define IFI_CANFD_STCMD_DISABLE_CANFD BIT(24) 36#define IFI_CANFD_STCMD_DISABLE_CANFD BIT(24)
@@ -52,7 +53,10 @@
52#define IFI_CANFD_TXSTCMD_OVERFLOW BIT(13) 53#define IFI_CANFD_TXSTCMD_OVERFLOW BIT(13)
53 54
54#define IFI_CANFD_INTERRUPT 0xc 55#define IFI_CANFD_INTERRUPT 0xc
56#define IFI_CANFD_INTERRUPT_ERROR_BUSOFF BIT(0)
55#define IFI_CANFD_INTERRUPT_ERROR_WARNING BIT(1) 57#define IFI_CANFD_INTERRUPT_ERROR_WARNING BIT(1)
58#define IFI_CANFD_INTERRUPT_ERROR_STATE_CHG BIT(2)
59#define IFI_CANFD_INTERRUPT_ERROR_REC_TEC_INC BIT(3)
56#define IFI_CANFD_INTERRUPT_ERROR_COUNTER BIT(10) 60#define IFI_CANFD_INTERRUPT_ERROR_COUNTER BIT(10)
57#define IFI_CANFD_INTERRUPT_TXFIFO_EMPTY BIT(16) 61#define IFI_CANFD_INTERRUPT_TXFIFO_EMPTY BIT(16)
58#define IFI_CANFD_INTERRUPT_TXFIFO_REMOVE BIT(22) 62#define IFI_CANFD_INTERRUPT_TXFIFO_REMOVE BIT(22)
@@ -61,6 +65,10 @@
61#define IFI_CANFD_INTERRUPT_SET_IRQ ((u32)BIT(31)) 65#define IFI_CANFD_INTERRUPT_SET_IRQ ((u32)BIT(31))
62 66
63#define IFI_CANFD_IRQMASK 0x10 67#define IFI_CANFD_IRQMASK 0x10
68#define IFI_CANFD_IRQMASK_ERROR_BUSOFF BIT(0)
69#define IFI_CANFD_IRQMASK_ERROR_WARNING BIT(1)
70#define IFI_CANFD_IRQMASK_ERROR_STATE_CHG BIT(2)
71#define IFI_CANFD_IRQMASK_ERROR_REC_TEC_INC BIT(3)
64#define IFI_CANFD_IRQMASK_SET_ERR BIT(7) 72#define IFI_CANFD_IRQMASK_SET_ERR BIT(7)
65#define IFI_CANFD_IRQMASK_SET_TS BIT(15) 73#define IFI_CANFD_IRQMASK_SET_TS BIT(15)
66#define IFI_CANFD_IRQMASK_TXFIFO_EMPTY BIT(16) 74#define IFI_CANFD_IRQMASK_TXFIFO_EMPTY BIT(16)
@@ -136,6 +144,8 @@
136#define IFI_CANFD_SYSCLOCK 0x50 144#define IFI_CANFD_SYSCLOCK 0x50
137 145
138#define IFI_CANFD_VER 0x54 146#define IFI_CANFD_VER 0x54
147#define IFI_CANFD_VER_REV_MASK 0xff
148#define IFI_CANFD_VER_REV_MIN_SUPPORTED 0x15
139 149
140#define IFI_CANFD_IP_ID 0x58 150#define IFI_CANFD_IP_ID 0x58
141#define IFI_CANFD_IP_ID_VALUE 0xD073CAFD 151#define IFI_CANFD_IP_ID_VALUE 0xD073CAFD
@@ -220,7 +230,10 @@ static void ifi_canfd_irq_enable(struct net_device *ndev, bool enable)
220 230
221 if (enable) { 231 if (enable) {
222 enirq = IFI_CANFD_IRQMASK_TXFIFO_EMPTY | 232 enirq = IFI_CANFD_IRQMASK_TXFIFO_EMPTY |
223 IFI_CANFD_IRQMASK_RXFIFO_NEMPTY; 233 IFI_CANFD_IRQMASK_RXFIFO_NEMPTY |
234 IFI_CANFD_IRQMASK_ERROR_STATE_CHG |
235 IFI_CANFD_IRQMASK_ERROR_WARNING |
236 IFI_CANFD_IRQMASK_ERROR_BUSOFF;
224 if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) 237 if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
225 enirq |= IFI_CANFD_INTERRUPT_ERROR_COUNTER; 238 enirq |= IFI_CANFD_INTERRUPT_ERROR_COUNTER;
226 } 239 }
@@ -361,12 +374,13 @@ static int ifi_canfd_handle_lost_msg(struct net_device *ndev)
361 return 1; 374 return 1;
362} 375}
363 376
364static int ifi_canfd_handle_lec_err(struct net_device *ndev, const u32 errctr) 377static int ifi_canfd_handle_lec_err(struct net_device *ndev)
365{ 378{
366 struct ifi_canfd_priv *priv = netdev_priv(ndev); 379 struct ifi_canfd_priv *priv = netdev_priv(ndev);
367 struct net_device_stats *stats = &ndev->stats; 380 struct net_device_stats *stats = &ndev->stats;
368 struct can_frame *cf; 381 struct can_frame *cf;
369 struct sk_buff *skb; 382 struct sk_buff *skb;
383 u32 errctr = readl(priv->base + IFI_CANFD_ERROR_CTR);
370 const u32 errmask = IFI_CANFD_ERROR_CTR_OVERLOAD_FIRST | 384 const u32 errmask = IFI_CANFD_ERROR_CTR_OVERLOAD_FIRST |
371 IFI_CANFD_ERROR_CTR_ACK_ERROR_FIRST | 385 IFI_CANFD_ERROR_CTR_ACK_ERROR_FIRST |
372 IFI_CANFD_ERROR_CTR_BIT0_ERROR_FIRST | 386 IFI_CANFD_ERROR_CTR_BIT0_ERROR_FIRST |
@@ -449,6 +463,11 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,
449 463
450 switch (new_state) { 464 switch (new_state) {
451 case CAN_STATE_ERROR_ACTIVE: 465 case CAN_STATE_ERROR_ACTIVE:
466 /* error active state */
467 priv->can.can_stats.error_warning++;
468 priv->can.state = CAN_STATE_ERROR_ACTIVE;
469 break;
470 case CAN_STATE_ERROR_WARNING:
452 /* error warning state */ 471 /* error warning state */
453 priv->can.can_stats.error_warning++; 472 priv->can.can_stats.error_warning++;
454 priv->can.state = CAN_STATE_ERROR_WARNING; 473 priv->can.state = CAN_STATE_ERROR_WARNING;
@@ -477,7 +496,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,
477 ifi_canfd_get_berr_counter(ndev, &bec); 496 ifi_canfd_get_berr_counter(ndev, &bec);
478 497
479 switch (new_state) { 498 switch (new_state) {
480 case CAN_STATE_ERROR_ACTIVE: 499 case CAN_STATE_ERROR_WARNING:
481 /* error warning state */ 500 /* error warning state */
482 cf->can_id |= CAN_ERR_CRTL; 501 cf->can_id |= CAN_ERR_CRTL;
483 cf->data[1] = (bec.txerr > bec.rxerr) ? 502 cf->data[1] = (bec.txerr > bec.rxerr) ?
@@ -510,22 +529,21 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,
510 return 1; 529 return 1;
511} 530}
512 531
513static int ifi_canfd_handle_state_errors(struct net_device *ndev, u32 stcmd) 532static int ifi_canfd_handle_state_errors(struct net_device *ndev)
514{ 533{
515 struct ifi_canfd_priv *priv = netdev_priv(ndev); 534 struct ifi_canfd_priv *priv = netdev_priv(ndev);
535 u32 stcmd = readl(priv->base + IFI_CANFD_STCMD);
516 int work_done = 0; 536 int work_done = 0;
517 u32 isr;
518 537
519 /* 538 if ((stcmd & IFI_CANFD_STCMD_ERROR_ACTIVE) &&
520 * The ErrWarn condition is a little special, since the bit is 539 (priv->can.state != CAN_STATE_ERROR_ACTIVE)) {
521 * located in the INTERRUPT register instead of STCMD register. 540 netdev_dbg(ndev, "Error, entered active state\n");
522 */ 541 work_done += ifi_canfd_handle_state_change(ndev,
523 isr = readl(priv->base + IFI_CANFD_INTERRUPT); 542 CAN_STATE_ERROR_ACTIVE);
524 if ((isr & IFI_CANFD_INTERRUPT_ERROR_WARNING) && 543 }
544
545 if ((stcmd & IFI_CANFD_STCMD_ERROR_WARNING) &&
525 (priv->can.state != CAN_STATE_ERROR_WARNING)) { 546 (priv->can.state != CAN_STATE_ERROR_WARNING)) {
526 /* Clear the interrupt */
527 writel(IFI_CANFD_INTERRUPT_ERROR_WARNING,
528 priv->base + IFI_CANFD_INTERRUPT);
529 netdev_dbg(ndev, "Error, entered warning state\n"); 547 netdev_dbg(ndev, "Error, entered warning state\n");
530 work_done += ifi_canfd_handle_state_change(ndev, 548 work_done += ifi_canfd_handle_state_change(ndev,
531 CAN_STATE_ERROR_WARNING); 549 CAN_STATE_ERROR_WARNING);
@@ -552,18 +570,11 @@ static int ifi_canfd_poll(struct napi_struct *napi, int quota)
552{ 570{
553 struct net_device *ndev = napi->dev; 571 struct net_device *ndev = napi->dev;
554 struct ifi_canfd_priv *priv = netdev_priv(ndev); 572 struct ifi_canfd_priv *priv = netdev_priv(ndev);
555 const u32 stcmd_state_mask = IFI_CANFD_STCMD_ERROR_PASSIVE |
556 IFI_CANFD_STCMD_BUSOFF;
557 int work_done = 0;
558
559 u32 stcmd = readl(priv->base + IFI_CANFD_STCMD);
560 u32 rxstcmd = readl(priv->base + IFI_CANFD_RXSTCMD); 573 u32 rxstcmd = readl(priv->base + IFI_CANFD_RXSTCMD);
561 u32 errctr = readl(priv->base + IFI_CANFD_ERROR_CTR); 574 int work_done = 0;
562 575
563 /* Handle bus state changes */ 576 /* Handle bus state changes */
564 if ((stcmd & stcmd_state_mask) || 577 work_done += ifi_canfd_handle_state_errors(ndev);
565 ((stcmd & IFI_CANFD_STCMD_ERROR_ACTIVE) == 0))
566 work_done += ifi_canfd_handle_state_errors(ndev, stcmd);
567 578
568 /* Handle lost messages on RX */ 579 /* Handle lost messages on RX */
569 if (rxstcmd & IFI_CANFD_RXSTCMD_OVERFLOW) 580 if (rxstcmd & IFI_CANFD_RXSTCMD_OVERFLOW)
@@ -571,7 +582,7 @@ static int ifi_canfd_poll(struct napi_struct *napi, int quota)
571 582
572 /* Handle lec errors on the bus */ 583 /* Handle lec errors on the bus */
573 if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) 584 if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
574 work_done += ifi_canfd_handle_lec_err(ndev, errctr); 585 work_done += ifi_canfd_handle_lec_err(ndev);
575 586
576 /* Handle normal messages on RX */ 587 /* Handle normal messages on RX */
577 if (!(rxstcmd & IFI_CANFD_RXSTCMD_EMPTY)) 588 if (!(rxstcmd & IFI_CANFD_RXSTCMD_EMPTY))
@@ -592,12 +603,13 @@ static irqreturn_t ifi_canfd_isr(int irq, void *dev_id)
592 struct net_device_stats *stats = &ndev->stats; 603 struct net_device_stats *stats = &ndev->stats;
593 const u32 rx_irq_mask = IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY | 604 const u32 rx_irq_mask = IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY |
594 IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY_PER | 605 IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY_PER |
606 IFI_CANFD_INTERRUPT_ERROR_COUNTER |
607 IFI_CANFD_INTERRUPT_ERROR_STATE_CHG |
595 IFI_CANFD_INTERRUPT_ERROR_WARNING | 608 IFI_CANFD_INTERRUPT_ERROR_WARNING |
596 IFI_CANFD_INTERRUPT_ERROR_COUNTER; 609 IFI_CANFD_INTERRUPT_ERROR_BUSOFF;
597 const u32 tx_irq_mask = IFI_CANFD_INTERRUPT_TXFIFO_EMPTY | 610 const u32 tx_irq_mask = IFI_CANFD_INTERRUPT_TXFIFO_EMPTY |
598 IFI_CANFD_INTERRUPT_TXFIFO_REMOVE; 611 IFI_CANFD_INTERRUPT_TXFIFO_REMOVE;
599 const u32 clr_irq_mask = ~((u32)(IFI_CANFD_INTERRUPT_SET_IRQ | 612 const u32 clr_irq_mask = ~((u32)IFI_CANFD_INTERRUPT_SET_IRQ);
600 IFI_CANFD_INTERRUPT_ERROR_WARNING));
601 u32 isr; 613 u32 isr;
602 614
603 isr = readl(priv->base + IFI_CANFD_INTERRUPT); 615 isr = readl(priv->base + IFI_CANFD_INTERRUPT);
@@ -933,7 +945,7 @@ static int ifi_canfd_plat_probe(struct platform_device *pdev)
933 struct resource *res; 945 struct resource *res;
934 void __iomem *addr; 946 void __iomem *addr;
935 int irq, ret; 947 int irq, ret;
936 u32 id; 948 u32 id, rev;
937 949
938 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 950 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
939 addr = devm_ioremap_resource(dev, res); 951 addr = devm_ioremap_resource(dev, res);
@@ -947,6 +959,13 @@ static int ifi_canfd_plat_probe(struct platform_device *pdev)
947 return -EINVAL; 959 return -EINVAL;
948 } 960 }
949 961
962 rev = readl(addr + IFI_CANFD_VER) & IFI_CANFD_VER_REV_MASK;
963 if (rev < IFI_CANFD_VER_REV_MIN_SUPPORTED) {
964 dev_err(dev, "This block is too old (rev %i), minimum supported is rev %i\n",
965 rev, IFI_CANFD_VER_REV_MIN_SUPPORTED);
966 return -EINVAL;
967 }
968
950 ndev = alloc_candev(sizeof(*priv), 1); 969 ndev = alloc_candev(sizeof(*priv), 1);
951 if (!ndev) 970 if (!ndev)
952 return -ENOMEM; 971 return -ENOMEM;
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 2594f7779c6f..b397a33f3d32 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -26,6 +26,7 @@
26#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
27#include <linux/iopoll.h> 27#include <linux/iopoll.h>
28#include <linux/can/dev.h> 28#include <linux/can/dev.h>
29#include <linux/pinctrl/consumer.h>
29 30
30/* napi related */ 31/* napi related */
31#define M_CAN_NAPI_WEIGHT 64 32#define M_CAN_NAPI_WEIGHT 64
@@ -253,7 +254,7 @@ enum m_can_mram_cfg {
253 254
254/* Rx FIFO 0/1 Configuration (RXF0C/RXF1C) */ 255/* Rx FIFO 0/1 Configuration (RXF0C/RXF1C) */
255#define RXFC_FWM_SHIFT 24 256#define RXFC_FWM_SHIFT 24
256#define RXFC_FWM_MASK (0x7f < RXFC_FWM_SHIFT) 257#define RXFC_FWM_MASK (0x7f << RXFC_FWM_SHIFT)
257#define RXFC_FS_SHIFT 16 258#define RXFC_FS_SHIFT 16
258#define RXFC_FS_MASK (0x7f << RXFC_FS_SHIFT) 259#define RXFC_FS_MASK (0x7f << RXFC_FS_SHIFT)
259 260
@@ -1700,6 +1701,8 @@ static __maybe_unused int m_can_suspend(struct device *dev)
1700 m_can_clk_stop(priv); 1701 m_can_clk_stop(priv);
1701 } 1702 }
1702 1703
1704 pinctrl_pm_select_sleep_state(dev);
1705
1703 priv->can.state = CAN_STATE_SLEEPING; 1706 priv->can.state = CAN_STATE_SLEEPING;
1704 1707
1705 return 0; 1708 return 0;
@@ -1710,6 +1713,8 @@ static __maybe_unused int m_can_resume(struct device *dev)
1710 struct net_device *ndev = dev_get_drvdata(dev); 1713 struct net_device *ndev = dev_get_drvdata(dev);
1711 struct m_can_priv *priv = netdev_priv(ndev); 1714 struct m_can_priv *priv = netdev_priv(ndev);
1712 1715
1716 pinctrl_pm_select_default_state(dev);
1717
1713 m_can_init_ram(priv); 1718 m_can_init_ram(priv);
1714 1719
1715 priv->can.state = CAN_STATE_ERROR_ACTIVE; 1720 priv->can.state = CAN_STATE_ERROR_ACTIVE;
diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c
index 55513411a82e..ed8561d4a90f 100644
--- a/drivers/net/can/peak_canfd/peak_canfd.c
+++ b/drivers/net/can/peak_canfd/peak_canfd.c
@@ -262,7 +262,6 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
262 262
263 spin_lock_irqsave(&priv->echo_lock, flags); 263 spin_lock_irqsave(&priv->echo_lock, flags);
264 can_get_echo_skb(priv->ndev, msg->client); 264 can_get_echo_skb(priv->ndev, msg->client);
265 spin_unlock_irqrestore(&priv->echo_lock, flags);
266 265
267 /* count bytes of the echo instead of skb */ 266 /* count bytes of the echo instead of skb */
268 stats->tx_bytes += cf_len; 267 stats->tx_bytes += cf_len;
@@ -271,6 +270,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
271 /* restart tx queue (a slot is free) */ 270 /* restart tx queue (a slot is free) */
272 netif_wake_queue(priv->ndev); 271 netif_wake_queue(priv->ndev);
273 272
273 spin_unlock_irqrestore(&priv->echo_lock, flags);
274 return 0; 274 return 0;
275 } 275 }
276 276
@@ -333,7 +333,6 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
333 333
334 /* this STATUS is the CNF of the RX_BARRIER: Tx path can be setup */ 334 /* this STATUS is the CNF of the RX_BARRIER: Tx path can be setup */
335 if (pucan_status_is_rx_barrier(msg)) { 335 if (pucan_status_is_rx_barrier(msg)) {
336 unsigned long flags;
337 336
338 if (priv->enable_tx_path) { 337 if (priv->enable_tx_path) {
339 int err = priv->enable_tx_path(priv); 338 int err = priv->enable_tx_path(priv);
@@ -342,16 +341,8 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
342 return err; 341 return err;
343 } 342 }
344 343
345 /* restart network queue only if echo skb array is free */ 344 /* start network queue (echo_skb array is empty) */
346 spin_lock_irqsave(&priv->echo_lock, flags); 345 netif_start_queue(ndev);
347
348 if (!priv->can.echo_skb[priv->echo_idx]) {
349 spin_unlock_irqrestore(&priv->echo_lock, flags);
350
351 netif_wake_queue(ndev);
352 } else {
353 spin_unlock_irqrestore(&priv->echo_lock, flags);
354 }
355 346
356 return 0; 347 return 0;
357 } 348 }
@@ -726,11 +717,6 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff *skb,
726 */ 717 */
727 should_stop_tx_queue = !!(priv->can.echo_skb[priv->echo_idx]); 718 should_stop_tx_queue = !!(priv->can.echo_skb[priv->echo_idx]);
728 719
729 spin_unlock_irqrestore(&priv->echo_lock, flags);
730
731 /* write the skb on the interface */
732 priv->write_tx_msg(priv, msg);
733
734 /* stop network tx queue if not enough room to save one more msg too */ 720 /* stop network tx queue if not enough room to save one more msg too */
735 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) 721 if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
736 should_stop_tx_queue |= (room_left < 722 should_stop_tx_queue |= (room_left <
@@ -742,6 +728,11 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff *skb,
742 if (should_stop_tx_queue) 728 if (should_stop_tx_queue)
743 netif_stop_queue(ndev); 729 netif_stop_queue(ndev);
744 730
731 spin_unlock_irqrestore(&priv->echo_lock, flags);
732
733 /* write the skb on the interface */
734 priv->write_tx_msg(priv, msg);
735
745 return NETDEV_TX_OK; 736 return NETDEV_TX_OK;
746} 737}
747 738
diff --git a/drivers/net/can/peak_canfd/peak_pciefd_main.c b/drivers/net/can/peak_canfd/peak_pciefd_main.c
index 788c3464a3b0..3c51a884db87 100644
--- a/drivers/net/can/peak_canfd/peak_pciefd_main.c
+++ b/drivers/net/can/peak_canfd/peak_pciefd_main.c
@@ -349,8 +349,12 @@ static irqreturn_t pciefd_irq_handler(int irq, void *arg)
349 priv->tx_pages_free++; 349 priv->tx_pages_free++;
350 spin_unlock_irqrestore(&priv->tx_lock, flags); 350 spin_unlock_irqrestore(&priv->tx_lock, flags);
351 351
352 /* wake producer up */ 352 /* wake producer up (only if enough room in echo_skb array) */
353 netif_wake_queue(priv->ucan.ndev); 353 spin_lock_irqsave(&priv->ucan.echo_lock, flags);
354 if (!priv->ucan.can.echo_skb[priv->ucan.echo_idx])
355 netif_wake_queue(priv->ucan.ndev);
356
357 spin_unlock_irqrestore(&priv->ucan.echo_lock, flags);
354 } 358 }
355 359
356 /* re-enable Rx DMA transfer for this CAN */ 360 /* re-enable Rx DMA transfer for this CAN */
diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile
index d040aeb45172..15c2a831edf1 100644
--- a/drivers/net/dsa/Makefile
+++ b/drivers/net/dsa/Makefile
@@ -1,7 +1,10 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2obj-$(CONFIG_NET_DSA_BCM_SF2) += bcm-sf2.o 2obj-$(CONFIG_NET_DSA_BCM_SF2) += bcm-sf2.o
3bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o 3bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o
4obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o dsa_loop_bdinfo.o 4obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o
5ifdef CONFIG_NET_DSA_LOOP
6obj-$(CONFIG_FIXED_PHY) += dsa_loop_bdinfo.o
7endif
5obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o 8obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o
6obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o 9obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o
7obj-$(CONFIG_NET_DSA_QCA8K) += qca8k.o 10obj-$(CONFIG_NET_DSA_QCA8K) += qca8k.o
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index db830a1141d9..63e02a54d537 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -814,8 +814,8 @@ void b53_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
814 unsigned int i; 814 unsigned int i;
815 815
816 for (i = 0; i < mib_size; i++) 816 for (i = 0; i < mib_size; i++)
817 memcpy(data + i * ETH_GSTRING_LEN, 817 strlcpy(data + i * ETH_GSTRING_LEN,
818 mibs[i].name, ETH_GSTRING_LEN); 818 mibs[i].name, ETH_GSTRING_LEN);
819} 819}
820EXPORT_SYMBOL(b53_get_strings); 820EXPORT_SYMBOL(b53_get_strings);
821 821
diff --git a/drivers/net/ethernet/8390/Kconfig b/drivers/net/ethernet/8390/Kconfig
index 29c3075bfb05..fdc673484add 100644
--- a/drivers/net/ethernet/8390/Kconfig
+++ b/drivers/net/ethernet/8390/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4 4
5config NET_VENDOR_8390 5config NET_VENDOR_8390
6 bool "National Semi-conductor 8390 devices" 6 bool "National Semiconductor 8390 devices"
7 default y 7 default y
8 depends on NET_VENDOR_NATSEMI 8 depends on NET_VENDOR_NATSEMI
9 ---help--- 9 ---help---
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c
index 3e5833cf1fab..eb23f9ba1a9a 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c
@@ -426,6 +426,8 @@ static int xgbe_pci_resume(struct pci_dev *pdev)
426 struct net_device *netdev = pdata->netdev; 426 struct net_device *netdev = pdata->netdev;
427 int ret = 0; 427 int ret = 0;
428 428
429 XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff);
430
429 pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER; 431 pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER;
430 XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl); 432 XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
431 433
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_cfg.h b/drivers/net/ethernet/aquantia/atlantic/aq_cfg.h
index 0b49f1aeebd3..fc7383106946 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_cfg.h
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_cfg.h
@@ -36,6 +36,8 @@
36#define AQ_CFG_TX_FRAME_MAX (16U * 1024U) 36#define AQ_CFG_TX_FRAME_MAX (16U * 1024U)
37#define AQ_CFG_RX_FRAME_MAX (4U * 1024U) 37#define AQ_CFG_RX_FRAME_MAX (4U * 1024U)
38 38
39#define AQ_CFG_TX_CLEAN_BUDGET 256U
40
39/* LRO */ 41/* LRO */
40#define AQ_CFG_IS_LRO_DEF 1U 42#define AQ_CFG_IS_LRO_DEF 1U
41 43
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c
index ebbaf63eaf47..c96a92118b8b 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c
@@ -247,6 +247,8 @@ void aq_nic_ndev_init(struct aq_nic_s *self)
247 self->ndev->hw_features |= aq_hw_caps->hw_features; 247 self->ndev->hw_features |= aq_hw_caps->hw_features;
248 self->ndev->features = aq_hw_caps->hw_features; 248 self->ndev->features = aq_hw_caps->hw_features;
249 self->ndev->priv_flags = aq_hw_caps->hw_priv_flags; 249 self->ndev->priv_flags = aq_hw_caps->hw_priv_flags;
250 self->ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
251
250 self->ndev->mtu = aq_nic_cfg->mtu - ETH_HLEN; 252 self->ndev->mtu = aq_nic_cfg->mtu - ETH_HLEN;
251 self->ndev->max_mtu = aq_hw_caps->mtu - ETH_FCS_LEN - ETH_HLEN; 253 self->ndev->max_mtu = aq_hw_caps->mtu - ETH_FCS_LEN - ETH_HLEN;
252 254
@@ -937,3 +939,23 @@ err_exit:
937out: 939out:
938 return err; 940 return err;
939} 941}
942
943void aq_nic_shutdown(struct aq_nic_s *self)
944{
945 int err = 0;
946
947 if (!self->ndev)
948 return;
949
950 rtnl_lock();
951
952 netif_device_detach(self->ndev);
953
954 err = aq_nic_stop(self);
955 if (err < 0)
956 goto err_exit;
957 aq_nic_deinit(self);
958
959err_exit:
960 rtnl_unlock();
961} \ No newline at end of file
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.h b/drivers/net/ethernet/aquantia/atlantic/aq_nic.h
index d16b0f1a95aa..219b550d1665 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.h
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.h
@@ -118,5 +118,6 @@ struct aq_nic_cfg_s *aq_nic_get_cfg(struct aq_nic_s *self);
118u32 aq_nic_get_fw_version(struct aq_nic_s *self); 118u32 aq_nic_get_fw_version(struct aq_nic_s *self);
119int aq_nic_change_pm_state(struct aq_nic_s *self, pm_message_t *pm_msg); 119int aq_nic_change_pm_state(struct aq_nic_s *self, pm_message_t *pm_msg);
120int aq_nic_update_interrupt_moderation_settings(struct aq_nic_s *self); 120int aq_nic_update_interrupt_moderation_settings(struct aq_nic_s *self);
121void aq_nic_shutdown(struct aq_nic_s *self);
121 122
122#endif /* AQ_NIC_H */ 123#endif /* AQ_NIC_H */
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c
index 22889fc158f2..ecc6306f940f 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c
@@ -226,6 +226,10 @@ static int aq_pci_probe(struct pci_dev *pdev,
226 goto err_ioremap; 226 goto err_ioremap;
227 227
228 self->aq_hw = kzalloc(sizeof(*self->aq_hw), GFP_KERNEL); 228 self->aq_hw = kzalloc(sizeof(*self->aq_hw), GFP_KERNEL);
229 if (!self->aq_hw) {
230 err = -ENOMEM;
231 goto err_ioremap;
232 }
229 self->aq_hw->aq_nic_cfg = aq_nic_get_cfg(self); 233 self->aq_hw->aq_nic_cfg = aq_nic_get_cfg(self);
230 234
231 for (bar = 0; bar < 4; ++bar) { 235 for (bar = 0; bar < 4; ++bar) {
@@ -235,19 +239,19 @@ static int aq_pci_probe(struct pci_dev *pdev,
235 mmio_pa = pci_resource_start(pdev, bar); 239 mmio_pa = pci_resource_start(pdev, bar);
236 if (mmio_pa == 0U) { 240 if (mmio_pa == 0U) {
237 err = -EIO; 241 err = -EIO;
238 goto err_ioremap; 242 goto err_free_aq_hw;
239 } 243 }
240 244
241 reg_sz = pci_resource_len(pdev, bar); 245 reg_sz = pci_resource_len(pdev, bar);
242 if ((reg_sz <= 24 /*ATL_REGS_SIZE*/)) { 246 if ((reg_sz <= 24 /*ATL_REGS_SIZE*/)) {
243 err = -EIO; 247 err = -EIO;
244 goto err_ioremap; 248 goto err_free_aq_hw;
245 } 249 }
246 250
247 self->aq_hw->mmio = ioremap_nocache(mmio_pa, reg_sz); 251 self->aq_hw->mmio = ioremap_nocache(mmio_pa, reg_sz);
248 if (!self->aq_hw->mmio) { 252 if (!self->aq_hw->mmio) {
249 err = -EIO; 253 err = -EIO;
250 goto err_ioremap; 254 goto err_free_aq_hw;
251 } 255 }
252 break; 256 break;
253 } 257 }
@@ -255,7 +259,7 @@ static int aq_pci_probe(struct pci_dev *pdev,
255 259
256 if (bar == 4) { 260 if (bar == 4) {
257 err = -EIO; 261 err = -EIO;
258 goto err_ioremap; 262 goto err_free_aq_hw;
259 } 263 }
260 264
261 numvecs = min((u8)AQ_CFG_VECS_DEF, 265 numvecs = min((u8)AQ_CFG_VECS_DEF,
@@ -290,6 +294,8 @@ err_register:
290 aq_pci_free_irq_vectors(self); 294 aq_pci_free_irq_vectors(self);
291err_hwinit: 295err_hwinit:
292 iounmap(self->aq_hw->mmio); 296 iounmap(self->aq_hw->mmio);
297err_free_aq_hw:
298 kfree(self->aq_hw);
293err_ioremap: 299err_ioremap:
294 free_netdev(ndev); 300 free_netdev(ndev);
295err_pci_func: 301err_pci_func:
@@ -317,6 +323,20 @@ static void aq_pci_remove(struct pci_dev *pdev)
317 pci_disable_device(pdev); 323 pci_disable_device(pdev);
318} 324}
319 325
326static void aq_pci_shutdown(struct pci_dev *pdev)
327{
328 struct aq_nic_s *self = pci_get_drvdata(pdev);
329
330 aq_nic_shutdown(self);
331
332 pci_disable_device(pdev);
333
334 if (system_state == SYSTEM_POWER_OFF) {
335 pci_wake_from_d3(pdev, false);
336 pci_set_power_state(pdev, PCI_D3hot);
337 }
338}
339
320static int aq_pci_suspend(struct pci_dev *pdev, pm_message_t pm_msg) 340static int aq_pci_suspend(struct pci_dev *pdev, pm_message_t pm_msg)
321{ 341{
322 struct aq_nic_s *self = pci_get_drvdata(pdev); 342 struct aq_nic_s *self = pci_get_drvdata(pdev);
@@ -339,6 +359,7 @@ static struct pci_driver aq_pci_ops = {
339 .remove = aq_pci_remove, 359 .remove = aq_pci_remove,
340 .suspend = aq_pci_suspend, 360 .suspend = aq_pci_suspend,
341 .resume = aq_pci_resume, 361 .resume = aq_pci_resume,
362 .shutdown = aq_pci_shutdown,
342}; 363};
343 364
344module_pci_driver(aq_pci_ops); 365module_pci_driver(aq_pci_ops);
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
index 0be6a11370bb..b5f1f62e8e25 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
@@ -136,11 +136,12 @@ void aq_ring_queue_stop(struct aq_ring_s *ring)
136 netif_stop_subqueue(ndev, ring->idx); 136 netif_stop_subqueue(ndev, ring->idx);
137} 137}
138 138
139void aq_ring_tx_clean(struct aq_ring_s *self) 139bool aq_ring_tx_clean(struct aq_ring_s *self)
140{ 140{
141 struct device *dev = aq_nic_get_dev(self->aq_nic); 141 struct device *dev = aq_nic_get_dev(self->aq_nic);
142 unsigned int budget = AQ_CFG_TX_CLEAN_BUDGET;
142 143
143 for (; self->sw_head != self->hw_head; 144 for (; self->sw_head != self->hw_head && budget--;
144 self->sw_head = aq_ring_next_dx(self, self->sw_head)) { 145 self->sw_head = aq_ring_next_dx(self, self->sw_head)) {
145 struct aq_ring_buff_s *buff = &self->buff_ring[self->sw_head]; 146 struct aq_ring_buff_s *buff = &self->buff_ring[self->sw_head];
146 147
@@ -167,6 +168,8 @@ void aq_ring_tx_clean(struct aq_ring_s *self)
167 buff->pa = 0U; 168 buff->pa = 0U;
168 buff->eop_index = 0xffffU; 169 buff->eop_index = 0xffffU;
169 } 170 }
171
172 return !!budget;
170} 173}
171 174
172#define AQ_SKB_ALIGN SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) 175#define AQ_SKB_ALIGN SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.h b/drivers/net/ethernet/aquantia/atlantic/aq_ring.h
index 965fae0fb6e0..ac1329f4051d 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.h
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.h
@@ -153,7 +153,7 @@ void aq_ring_free(struct aq_ring_s *self);
153void aq_ring_update_queue_state(struct aq_ring_s *ring); 153void aq_ring_update_queue_state(struct aq_ring_s *ring);
154void aq_ring_queue_wake(struct aq_ring_s *ring); 154void aq_ring_queue_wake(struct aq_ring_s *ring);
155void aq_ring_queue_stop(struct aq_ring_s *ring); 155void aq_ring_queue_stop(struct aq_ring_s *ring);
156void aq_ring_tx_clean(struct aq_ring_s *self); 156bool aq_ring_tx_clean(struct aq_ring_s *self);
157int aq_ring_rx_clean(struct aq_ring_s *self, 157int aq_ring_rx_clean(struct aq_ring_s *self,
158 struct napi_struct *napi, 158 struct napi_struct *napi,
159 int *work_done, 159 int *work_done,
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_vec.c b/drivers/net/ethernet/aquantia/atlantic/aq_vec.c
index f890b8a5a862..d335c334fa56 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_vec.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_vec.c
@@ -35,12 +35,12 @@ struct aq_vec_s {
35static int aq_vec_poll(struct napi_struct *napi, int budget) 35static int aq_vec_poll(struct napi_struct *napi, int budget)
36{ 36{
37 struct aq_vec_s *self = container_of(napi, struct aq_vec_s, napi); 37 struct aq_vec_s *self = container_of(napi, struct aq_vec_s, napi);
38 unsigned int sw_tail_old = 0U;
38 struct aq_ring_s *ring = NULL; 39 struct aq_ring_s *ring = NULL;
40 bool was_tx_cleaned = true;
41 unsigned int i = 0U;
39 int work_done = 0; 42 int work_done = 0;
40 int err = 0; 43 int err = 0;
41 unsigned int i = 0U;
42 unsigned int sw_tail_old = 0U;
43 bool was_tx_cleaned = false;
44 44
45 if (!self) { 45 if (!self) {
46 err = -EINVAL; 46 err = -EINVAL;
@@ -57,9 +57,8 @@ static int aq_vec_poll(struct napi_struct *napi, int budget)
57 57
58 if (ring[AQ_VEC_TX_ID].sw_head != 58 if (ring[AQ_VEC_TX_ID].sw_head !=
59 ring[AQ_VEC_TX_ID].hw_head) { 59 ring[AQ_VEC_TX_ID].hw_head) {
60 aq_ring_tx_clean(&ring[AQ_VEC_TX_ID]); 60 was_tx_cleaned = aq_ring_tx_clean(&ring[AQ_VEC_TX_ID]);
61 aq_ring_update_queue_state(&ring[AQ_VEC_TX_ID]); 61 aq_ring_update_queue_state(&ring[AQ_VEC_TX_ID]);
62 was_tx_cleaned = true;
63 } 62 }
64 63
65 err = self->aq_hw_ops->hw_ring_rx_receive(self->aq_hw, 64 err = self->aq_hw_ops->hw_ring_rx_receive(self->aq_hw,
@@ -90,7 +89,7 @@ static int aq_vec_poll(struct napi_struct *napi, int budget)
90 } 89 }
91 } 90 }
92 91
93 if (was_tx_cleaned) 92 if (!was_tx_cleaned)
94 work_done = budget; 93 work_done = budget;
95 94
96 if (work_done < budget) { 95 if (work_done < budget) {
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
index 967f0fd07fcf..d3b847ec7465 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
@@ -21,6 +21,10 @@
21 21
22#define HW_ATL_UCP_0X370_REG 0x0370U 22#define HW_ATL_UCP_0X370_REG 0x0370U
23 23
24#define HW_ATL_MIF_CMD 0x0200U
25#define HW_ATL_MIF_ADDR 0x0208U
26#define HW_ATL_MIF_VAL 0x020CU
27
24#define HW_ATL_FW_SM_RAM 0x2U 28#define HW_ATL_FW_SM_RAM 0x2U
25#define HW_ATL_MPI_FW_VERSION 0x18 29#define HW_ATL_MPI_FW_VERSION 0x18
26#define HW_ATL_MPI_CONTROL_ADR 0x0368U 30#define HW_ATL_MPI_CONTROL_ADR 0x0368U
@@ -79,16 +83,15 @@ int hw_atl_utils_initfw(struct aq_hw_s *self, const struct aq_fw_ops **fw_ops)
79 83
80static int hw_atl_utils_soft_reset_flb(struct aq_hw_s *self) 84static int hw_atl_utils_soft_reset_flb(struct aq_hw_s *self)
81{ 85{
86 u32 gsr, val;
82 int k = 0; 87 int k = 0;
83 u32 gsr;
84 88
85 aq_hw_write_reg(self, 0x404, 0x40e1); 89 aq_hw_write_reg(self, 0x404, 0x40e1);
86 AQ_HW_SLEEP(50); 90 AQ_HW_SLEEP(50);
87 91
88 /* Cleanup SPI */ 92 /* Cleanup SPI */
89 aq_hw_write_reg(self, 0x534, 0xA0); 93 val = aq_hw_read_reg(self, 0x53C);
90 aq_hw_write_reg(self, 0x100, 0x9F); 94 aq_hw_write_reg(self, 0x53C, val | 0x10);
91 aq_hw_write_reg(self, 0x100, 0x809F);
92 95
93 gsr = aq_hw_read_reg(self, HW_ATL_GLB_SOFT_RES_ADR); 96 gsr = aq_hw_read_reg(self, HW_ATL_GLB_SOFT_RES_ADR);
94 aq_hw_write_reg(self, HW_ATL_GLB_SOFT_RES_ADR, (gsr & 0xBFFF) | 0x8000); 97 aq_hw_write_reg(self, HW_ATL_GLB_SOFT_RES_ADR, (gsr & 0xBFFF) | 0x8000);
@@ -97,7 +100,14 @@ static int hw_atl_utils_soft_reset_flb(struct aq_hw_s *self)
97 aq_hw_write_reg(self, 0x404, 0x80e0); 100 aq_hw_write_reg(self, 0x404, 0x80e0);
98 aq_hw_write_reg(self, 0x32a8, 0x0); 101 aq_hw_write_reg(self, 0x32a8, 0x0);
99 aq_hw_write_reg(self, 0x520, 0x1); 102 aq_hw_write_reg(self, 0x520, 0x1);
103
104 /* Reset SPI again because of possible interrupted SPI burst */
105 val = aq_hw_read_reg(self, 0x53C);
106 aq_hw_write_reg(self, 0x53C, val | 0x10);
100 AQ_HW_SLEEP(10); 107 AQ_HW_SLEEP(10);
108 /* Clear SPI reset state */
109 aq_hw_write_reg(self, 0x53C, val & ~0x10);
110
101 aq_hw_write_reg(self, 0x404, 0x180e0); 111 aq_hw_write_reg(self, 0x404, 0x180e0);
102 112
103 for (k = 0; k < 1000; k++) { 113 for (k = 0; k < 1000; k++) {
@@ -141,13 +151,15 @@ static int hw_atl_utils_soft_reset_flb(struct aq_hw_s *self)
141 aq_pr_err("FW kickstart failed\n"); 151 aq_pr_err("FW kickstart failed\n");
142 return -EIO; 152 return -EIO;
143 } 153 }
154 /* Old FW requires fixed delay after init */
155 AQ_HW_SLEEP(15);
144 156
145 return 0; 157 return 0;
146} 158}
147 159
148static int hw_atl_utils_soft_reset_rbl(struct aq_hw_s *self) 160static int hw_atl_utils_soft_reset_rbl(struct aq_hw_s *self)
149{ 161{
150 u32 gsr, rbl_status; 162 u32 gsr, val, rbl_status;
151 int k; 163 int k;
152 164
153 aq_hw_write_reg(self, 0x404, 0x40e1); 165 aq_hw_write_reg(self, 0x404, 0x40e1);
@@ -157,6 +169,10 @@ static int hw_atl_utils_soft_reset_rbl(struct aq_hw_s *self)
157 /* Alter RBL status */ 169 /* Alter RBL status */
158 aq_hw_write_reg(self, 0x388, 0xDEAD); 170 aq_hw_write_reg(self, 0x388, 0xDEAD);
159 171
172 /* Cleanup SPI */
173 val = aq_hw_read_reg(self, 0x53C);
174 aq_hw_write_reg(self, 0x53C, val | 0x10);
175
160 /* Global software reset*/ 176 /* Global software reset*/
161 hw_atl_rx_rx_reg_res_dis_set(self, 0U); 177 hw_atl_rx_rx_reg_res_dis_set(self, 0U);
162 hw_atl_tx_tx_reg_res_dis_set(self, 0U); 178 hw_atl_tx_tx_reg_res_dis_set(self, 0U);
@@ -204,6 +220,8 @@ static int hw_atl_utils_soft_reset_rbl(struct aq_hw_s *self)
204 aq_pr_err("FW kickstart failed\n"); 220 aq_pr_err("FW kickstart failed\n");
205 return -EIO; 221 return -EIO;
206 } 222 }
223 /* Old FW requires fixed delay after init */
224 AQ_HW_SLEEP(15);
207 225
208 return 0; 226 return 0;
209} 227}
@@ -255,18 +273,22 @@ int hw_atl_utils_fw_downld_dwords(struct aq_hw_s *self, u32 a,
255 } 273 }
256 } 274 }
257 275
258 aq_hw_write_reg(self, 0x00000208U, a); 276 aq_hw_write_reg(self, HW_ATL_MIF_ADDR, a);
259
260 for (++cnt; --cnt;) {
261 u32 i = 0U;
262 277
263 aq_hw_write_reg(self, 0x00000200U, 0x00008000U); 278 for (++cnt; --cnt && !err;) {
279 aq_hw_write_reg(self, HW_ATL_MIF_CMD, 0x00008000U);
264 280
265 for (i = 1024U; 281 if (IS_CHIP_FEATURE(REVISION_B1))
266 (0x100U & aq_hw_read_reg(self, 0x00000200U)) && --i;) { 282 AQ_HW_WAIT_FOR(a != aq_hw_read_reg(self,
267 } 283 HW_ATL_MIF_ADDR),
284 1, 1000U);
285 else
286 AQ_HW_WAIT_FOR(!(0x100 & aq_hw_read_reg(self,
287 HW_ATL_MIF_CMD)),
288 1, 1000U);
268 289
269 *(p++) = aq_hw_read_reg(self, 0x0000020CU); 290 *(p++) = aq_hw_read_reg(self, HW_ATL_MIF_VAL);
291 a += 4;
270 } 292 }
271 293
272 hw_atl_reg_glb_cpu_sem_set(self, 1U, HW_ATL_FW_SM_RAM); 294 hw_atl_reg_glb_cpu_sem_set(self, 1U, HW_ATL_FW_SM_RAM);
@@ -662,14 +684,18 @@ void hw_atl_utils_hw_chip_features_init(struct aq_hw_s *self, u32 *p)
662 u32 val = hw_atl_reg_glb_mif_id_get(self); 684 u32 val = hw_atl_reg_glb_mif_id_get(self);
663 u32 mif_rev = val & 0xFFU; 685 u32 mif_rev = val & 0xFFU;
664 686
665 if ((3U & mif_rev) == 1U) { 687 if ((0xFU & mif_rev) == 1U) {
666 chip_features |= 688 chip_features |= HAL_ATLANTIC_UTILS_CHIP_REVISION_A0 |
667 HAL_ATLANTIC_UTILS_CHIP_REVISION_A0 |
668 HAL_ATLANTIC_UTILS_CHIP_MPI_AQ | 689 HAL_ATLANTIC_UTILS_CHIP_MPI_AQ |
669 HAL_ATLANTIC_UTILS_CHIP_MIPS; 690 HAL_ATLANTIC_UTILS_CHIP_MIPS;
670 } else if ((3U & mif_rev) == 2U) { 691 } else if ((0xFU & mif_rev) == 2U) {
671 chip_features |= 692 chip_features |= HAL_ATLANTIC_UTILS_CHIP_REVISION_B0 |
672 HAL_ATLANTIC_UTILS_CHIP_REVISION_B0 | 693 HAL_ATLANTIC_UTILS_CHIP_MPI_AQ |
694 HAL_ATLANTIC_UTILS_CHIP_MIPS |
695 HAL_ATLANTIC_UTILS_CHIP_TPO2 |
696 HAL_ATLANTIC_UTILS_CHIP_RPF2;
697 } else if ((0xFU & mif_rev) == 0xAU) {
698 chip_features |= HAL_ATLANTIC_UTILS_CHIP_REVISION_B1 |
673 HAL_ATLANTIC_UTILS_CHIP_MPI_AQ | 699 HAL_ATLANTIC_UTILS_CHIP_MPI_AQ |
674 HAL_ATLANTIC_UTILS_CHIP_MIPS | 700 HAL_ATLANTIC_UTILS_CHIP_MIPS |
675 HAL_ATLANTIC_UTILS_CHIP_TPO2 | 701 HAL_ATLANTIC_UTILS_CHIP_TPO2 |
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.h b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.h
index 2c690947910a..cd8f18f39c61 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.h
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.h
@@ -161,6 +161,7 @@ struct __packed hw_aq_atl_utils_mbox {
161#define HAL_ATLANTIC_UTILS_CHIP_MPI_AQ 0x00000010U 161#define HAL_ATLANTIC_UTILS_CHIP_MPI_AQ 0x00000010U
162#define HAL_ATLANTIC_UTILS_CHIP_REVISION_A0 0x01000000U 162#define HAL_ATLANTIC_UTILS_CHIP_REVISION_A0 0x01000000U
163#define HAL_ATLANTIC_UTILS_CHIP_REVISION_B0 0x02000000U 163#define HAL_ATLANTIC_UTILS_CHIP_REVISION_B0 0x02000000U
164#define HAL_ATLANTIC_UTILS_CHIP_REVISION_B1 0x04000000U
164 165
165#define IS_CHIP_FEATURE(_F_) (HAL_ATLANTIC_UTILS_CHIP_##_F_ & \ 166#define IS_CHIP_FEATURE(_F_) (HAL_ATLANTIC_UTILS_CHIP_##_F_ & \
166 self->chip_features) 167 self->chip_features)
diff --git a/drivers/net/ethernet/aquantia/atlantic/ver.h b/drivers/net/ethernet/aquantia/atlantic/ver.h
index 5265b937677b..a445de6837a6 100644
--- a/drivers/net/ethernet/aquantia/atlantic/ver.h
+++ b/drivers/net/ethernet/aquantia/atlantic/ver.h
@@ -13,7 +13,7 @@
13#define NIC_MAJOR_DRIVER_VERSION 2 13#define NIC_MAJOR_DRIVER_VERSION 2
14#define NIC_MINOR_DRIVER_VERSION 0 14#define NIC_MINOR_DRIVER_VERSION 0
15#define NIC_BUILD_DRIVER_VERSION 2 15#define NIC_BUILD_DRIVER_VERSION 2
16#define NIC_REVISION_DRIVER_VERSION 0 16#define NIC_REVISION_DRIVER_VERSION 1
17 17
18#define AQ_CFG_DRV_VERSION_SUFFIX "-kern" 18#define AQ_CFG_DRV_VERSION_SUFFIX "-kern"
19 19
diff --git a/drivers/net/ethernet/arc/emac_rockchip.c b/drivers/net/ethernet/arc/emac_rockchip.c
index 16f9bee992fe..0f6576802607 100644
--- a/drivers/net/ethernet/arc/emac_rockchip.c
+++ b/drivers/net/ethernet/arc/emac_rockchip.c
@@ -169,8 +169,10 @@ static int emac_rockchip_probe(struct platform_device *pdev)
169 /* Optional regulator for PHY */ 169 /* Optional regulator for PHY */
170 priv->regulator = devm_regulator_get_optional(dev, "phy"); 170 priv->regulator = devm_regulator_get_optional(dev, "phy");
171 if (IS_ERR(priv->regulator)) { 171 if (IS_ERR(priv->regulator)) {
172 if (PTR_ERR(priv->regulator) == -EPROBE_DEFER) 172 if (PTR_ERR(priv->regulator) == -EPROBE_DEFER) {
173 return -EPROBE_DEFER; 173 err = -EPROBE_DEFER;
174 goto out_clk_disable;
175 }
174 dev_err(dev, "no regulator found\n"); 176 dev_err(dev, "no regulator found\n");
175 priv->regulator = NULL; 177 priv->regulator = NULL;
176 } 178 }
diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c
index f15a8fc6dfc9..3fc549b88c43 100644
--- a/drivers/net/ethernet/broadcom/bcmsysport.c
+++ b/drivers/net/ethernet/broadcom/bcmsysport.c
@@ -855,10 +855,12 @@ static void bcm_sysport_tx_reclaim_one(struct bcm_sysport_tx_ring *ring,
855static unsigned int __bcm_sysport_tx_reclaim(struct bcm_sysport_priv *priv, 855static unsigned int __bcm_sysport_tx_reclaim(struct bcm_sysport_priv *priv,
856 struct bcm_sysport_tx_ring *ring) 856 struct bcm_sysport_tx_ring *ring)
857{ 857{
858 unsigned int c_index, last_c_index, last_tx_cn, num_tx_cbs;
859 unsigned int pkts_compl = 0, bytes_compl = 0; 858 unsigned int pkts_compl = 0, bytes_compl = 0;
860 struct net_device *ndev = priv->netdev; 859 struct net_device *ndev = priv->netdev;
860 unsigned int txbds_processed = 0;
861 struct bcm_sysport_cb *cb; 861 struct bcm_sysport_cb *cb;
862 unsigned int txbds_ready;
863 unsigned int c_index;
862 u32 hw_ind; 864 u32 hw_ind;
863 865
864 /* Clear status before servicing to reduce spurious interrupts */ 866 /* Clear status before servicing to reduce spurious interrupts */
@@ -871,29 +873,23 @@ static unsigned int __bcm_sysport_tx_reclaim(struct bcm_sysport_priv *priv,
871 /* Compute how many descriptors have been processed since last call */ 873 /* Compute how many descriptors have been processed since last call */
872 hw_ind = tdma_readl(priv, TDMA_DESC_RING_PROD_CONS_INDEX(ring->index)); 874 hw_ind = tdma_readl(priv, TDMA_DESC_RING_PROD_CONS_INDEX(ring->index));
873 c_index = (hw_ind >> RING_CONS_INDEX_SHIFT) & RING_CONS_INDEX_MASK; 875 c_index = (hw_ind >> RING_CONS_INDEX_SHIFT) & RING_CONS_INDEX_MASK;
874 ring->p_index = (hw_ind & RING_PROD_INDEX_MASK); 876 txbds_ready = (c_index - ring->c_index) & RING_CONS_INDEX_MASK;
875
876 last_c_index = ring->c_index;
877 num_tx_cbs = ring->size;
878
879 c_index &= (num_tx_cbs - 1);
880
881 if (c_index >= last_c_index)
882 last_tx_cn = c_index - last_c_index;
883 else
884 last_tx_cn = num_tx_cbs - last_c_index + c_index;
885 877
886 netif_dbg(priv, tx_done, ndev, 878 netif_dbg(priv, tx_done, ndev,
887 "ring=%d c_index=%d last_tx_cn=%d last_c_index=%d\n", 879 "ring=%d old_c_index=%u c_index=%u txbds_ready=%u\n",
888 ring->index, c_index, last_tx_cn, last_c_index); 880 ring->index, ring->c_index, c_index, txbds_ready);
889 881
890 while (last_tx_cn-- > 0) { 882 while (txbds_processed < txbds_ready) {
891 cb = ring->cbs + last_c_index; 883 cb = &ring->cbs[ring->clean_index];
892 bcm_sysport_tx_reclaim_one(ring, cb, &bytes_compl, &pkts_compl); 884 bcm_sysport_tx_reclaim_one(ring, cb, &bytes_compl, &pkts_compl);
893 885
894 ring->desc_count++; 886 ring->desc_count++;
895 last_c_index++; 887 txbds_processed++;
896 last_c_index &= (num_tx_cbs - 1); 888
889 if (likely(ring->clean_index < ring->size - 1))
890 ring->clean_index++;
891 else
892 ring->clean_index = 0;
897 } 893 }
898 894
899 u64_stats_update_begin(&priv->syncp); 895 u64_stats_update_begin(&priv->syncp);
@@ -1394,6 +1390,7 @@ static int bcm_sysport_init_tx_ring(struct bcm_sysport_priv *priv,
1394 netif_tx_napi_add(priv->netdev, &ring->napi, bcm_sysport_tx_poll, 64); 1390 netif_tx_napi_add(priv->netdev, &ring->napi, bcm_sysport_tx_poll, 64);
1395 ring->index = index; 1391 ring->index = index;
1396 ring->size = size; 1392 ring->size = size;
1393 ring->clean_index = 0;
1397 ring->alloc_size = ring->size; 1394 ring->alloc_size = ring->size;
1398 ring->desc_cpu = p; 1395 ring->desc_cpu = p;
1399 ring->desc_count = ring->size; 1396 ring->desc_count = ring->size;
diff --git a/drivers/net/ethernet/broadcom/bcmsysport.h b/drivers/net/ethernet/broadcom/bcmsysport.h
index f5a984c1c986..19c91c76e327 100644
--- a/drivers/net/ethernet/broadcom/bcmsysport.h
+++ b/drivers/net/ethernet/broadcom/bcmsysport.h
@@ -706,7 +706,7 @@ struct bcm_sysport_tx_ring {
706 unsigned int desc_count; /* Number of descriptors */ 706 unsigned int desc_count; /* Number of descriptors */
707 unsigned int curr_desc; /* Current descriptor */ 707 unsigned int curr_desc; /* Current descriptor */
708 unsigned int c_index; /* Last consumer index */ 708 unsigned int c_index; /* Last consumer index */
709 unsigned int p_index; /* Current producer index */ 709 unsigned int clean_index; /* Current clean index */
710 struct bcm_sysport_cb *cbs; /* Transmit control blocks */ 710 struct bcm_sysport_cb *cbs; /* Transmit control blocks */
711 struct dma_desc *desc_cpu; /* CPU view of the descriptor */ 711 struct dma_desc *desc_cpu; /* CPU view of the descriptor */
712 struct bcm_sysport_priv *priv; /* private context backpointer */ 712 struct bcm_sysport_priv *priv; /* private context backpointer */
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 74fc9af4aadb..b8388e93520a 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13913,7 +13913,7 @@ static void bnx2x_register_phc(struct bnx2x *bp)
13913 bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev); 13913 bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
13914 if (IS_ERR(bp->ptp_clock)) { 13914 if (IS_ERR(bp->ptp_clock)) {
13915 bp->ptp_clock = NULL; 13915 bp->ptp_clock = NULL;
13916 BNX2X_ERR("PTP clock registeration failed\n"); 13916 BNX2X_ERR("PTP clock registration failed\n");
13917 } 13917 }
13918} 13918}
13919 13919
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 1500243b9886..c7e5e6f09647 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -1439,7 +1439,7 @@ static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
1439 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { 1439 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1440 u16 vlan_proto = tpa_info->metadata >> 1440 u16 vlan_proto = tpa_info->metadata >>
1441 RX_CMP_FLAGS2_METADATA_TPID_SFT; 1441 RX_CMP_FLAGS2_METADATA_TPID_SFT;
1442 u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_VID_MASK; 1442 u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_TCI_MASK;
1443 1443
1444 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); 1444 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
1445 } 1445 }
@@ -1623,7 +1623,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
1623 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) && 1623 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
1624 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { 1624 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
1625 u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data); 1625 u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data);
1626 u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_VID_MASK; 1626 u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_TCI_MASK;
1627 u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT; 1627 u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT;
1628 1628
1629 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); 1629 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
@@ -3847,6 +3847,9 @@ static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
3847 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; 3847 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3848 struct hwrm_vnic_tpa_cfg_input req = {0}; 3848 struct hwrm_vnic_tpa_cfg_input req = {0};
3849 3849
3850 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
3851 return 0;
3852
3850 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1); 3853 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1);
3851 3854
3852 if (tpa_flags) { 3855 if (tpa_flags) {
@@ -4558,18 +4561,17 @@ int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
4558 return rc; 4561 return rc;
4559} 4562}
4560 4563
4561static int 4564static void
4562bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings, 4565__bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, struct hwrm_func_cfg_input *req,
4563 int ring_grps, int cp_rings, int vnics) 4566 int tx_rings, int rx_rings, int ring_grps,
4567 int cp_rings, int vnics)
4564{ 4568{
4565 struct hwrm_func_cfg_input req = {0};
4566 u32 enables = 0; 4569 u32 enables = 0;
4567 int rc;
4568 4570
4569 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 4571 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_CFG, -1, -1);
4570 req.fid = cpu_to_le16(0xffff); 4572 req->fid = cpu_to_le16(0xffff);
4571 enables |= tx_rings ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0; 4573 enables |= tx_rings ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
4572 req.num_tx_rings = cpu_to_le16(tx_rings); 4574 req->num_tx_rings = cpu_to_le16(tx_rings);
4573 if (bp->flags & BNXT_FLAG_NEW_RM) { 4575 if (bp->flags & BNXT_FLAG_NEW_RM) {
4574 enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0; 4576 enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4575 enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS | 4577 enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
@@ -4578,16 +4580,53 @@ bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4578 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0; 4580 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4579 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0; 4581 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4580 4582
4581 req.num_rx_rings = cpu_to_le16(rx_rings); 4583 req->num_rx_rings = cpu_to_le16(rx_rings);
4582 req.num_hw_ring_grps = cpu_to_le16(ring_grps); 4584 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4583 req.num_cmpl_rings = cpu_to_le16(cp_rings); 4585 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4584 req.num_stat_ctxs = req.num_cmpl_rings; 4586 req->num_stat_ctxs = req->num_cmpl_rings;
4585 req.num_vnics = cpu_to_le16(vnics); 4587 req->num_vnics = cpu_to_le16(vnics);
4586 } 4588 }
4587 if (!enables) 4589 req->enables = cpu_to_le32(enables);
4590}
4591
4592static void
4593__bnxt_hwrm_reserve_vf_rings(struct bnxt *bp,
4594 struct hwrm_func_vf_cfg_input *req, int tx_rings,
4595 int rx_rings, int ring_grps, int cp_rings,
4596 int vnics)
4597{
4598 u32 enables = 0;
4599
4600 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_VF_CFG, -1, -1);
4601 enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
4602 enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4603 enables |= cp_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4604 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4605 enables |= ring_grps ? FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4606 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4607
4608 req->num_tx_rings = cpu_to_le16(tx_rings);
4609 req->num_rx_rings = cpu_to_le16(rx_rings);
4610 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4611 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4612 req->num_stat_ctxs = req->num_cmpl_rings;
4613 req->num_vnics = cpu_to_le16(vnics);
4614
4615 req->enables = cpu_to_le32(enables);
4616}
4617
4618static int
4619bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4620 int ring_grps, int cp_rings, int vnics)
4621{
4622 struct hwrm_func_cfg_input req = {0};
4623 int rc;
4624
4625 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4626 cp_rings, vnics);
4627 if (!req.enables)
4588 return 0; 4628 return 0;
4589 4629
4590 req.enables = cpu_to_le32(enables);
4591 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 4630 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4592 if (rc) 4631 if (rc)
4593 return -ENOMEM; 4632 return -ENOMEM;
@@ -4604,7 +4643,6 @@ bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4604 int ring_grps, int cp_rings, int vnics) 4643 int ring_grps, int cp_rings, int vnics)
4605{ 4644{
4606 struct hwrm_func_vf_cfg_input req = {0}; 4645 struct hwrm_func_vf_cfg_input req = {0};
4607 u32 enables = 0;
4608 int rc; 4646 int rc;
4609 4647
4610 if (!(bp->flags & BNXT_FLAG_NEW_RM)) { 4648 if (!(bp->flags & BNXT_FLAG_NEW_RM)) {
@@ -4612,22 +4650,8 @@ bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4612 return 0; 4650 return 0;
4613 } 4651 }
4614 4652
4615 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1); 4653 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4616 enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0; 4654 cp_rings, vnics);
4617 enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4618 enables |= cp_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4619 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4620 enables |= ring_grps ? FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4621 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4622
4623 req.num_tx_rings = cpu_to_le16(tx_rings);
4624 req.num_rx_rings = cpu_to_le16(rx_rings);
4625 req.num_hw_ring_grps = cpu_to_le16(ring_grps);
4626 req.num_cmpl_rings = cpu_to_le16(cp_rings);
4627 req.num_stat_ctxs = req.num_cmpl_rings;
4628 req.num_vnics = cpu_to_le16(vnics);
4629
4630 req.enables = cpu_to_le32(enables);
4631 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 4655 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4632 if (rc) 4656 if (rc)
4633 return -ENOMEM; 4657 return -ENOMEM;
@@ -4743,39 +4767,25 @@ static bool bnxt_need_reserve_rings(struct bnxt *bp)
4743} 4767}
4744 4768
4745static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings, 4769static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4746 int ring_grps, int cp_rings) 4770 int ring_grps, int cp_rings, int vnics)
4747{ 4771{
4748 struct hwrm_func_vf_cfg_input req = {0}; 4772 struct hwrm_func_vf_cfg_input req = {0};
4749 u32 flags, enables; 4773 u32 flags;
4750 int rc; 4774 int rc;
4751 4775
4752 if (!(bp->flags & BNXT_FLAG_NEW_RM)) 4776 if (!(bp->flags & BNXT_FLAG_NEW_RM))
4753 return 0; 4777 return 0;
4754 4778
4755 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1); 4779 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4780 cp_rings, vnics);
4756 flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST | 4781 flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST |
4757 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST | 4782 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4758 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST | 4783 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4759 FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST | 4784 FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4760 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST | 4785 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4761 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST; 4786 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
4762 enables = FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS |
4763 FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS |
4764 FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4765 FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS |
4766 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS |
4767 FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS;
4768 4787
4769 req.flags = cpu_to_le32(flags); 4788 req.flags = cpu_to_le32(flags);
4770 req.enables = cpu_to_le32(enables);
4771 req.num_tx_rings = cpu_to_le16(tx_rings);
4772 req.num_rx_rings = cpu_to_le16(rx_rings);
4773 req.num_cmpl_rings = cpu_to_le16(cp_rings);
4774 req.num_hw_ring_grps = cpu_to_le16(ring_grps);
4775 req.num_stat_ctxs = cpu_to_le16(cp_rings);
4776 req.num_vnics = cpu_to_le16(1);
4777 if (bp->flags & BNXT_FLAG_RFS)
4778 req.num_vnics = cpu_to_le16(rx_rings + 1);
4779 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 4789 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4780 if (rc) 4790 if (rc)
4781 return -ENOMEM; 4791 return -ENOMEM;
@@ -4783,38 +4793,23 @@ static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4783} 4793}
4784 4794
4785static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings, 4795static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4786 int ring_grps, int cp_rings) 4796 int ring_grps, int cp_rings, int vnics)
4787{ 4797{
4788 struct hwrm_func_cfg_input req = {0}; 4798 struct hwrm_func_cfg_input req = {0};
4789 u32 flags, enables; 4799 u32 flags;
4790 int rc; 4800 int rc;
4791 4801
4792 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 4802 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4793 req.fid = cpu_to_le16(0xffff); 4803 cp_rings, vnics);
4794 flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST; 4804 flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST;
4795 enables = FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS; 4805 if (bp->flags & BNXT_FLAG_NEW_RM)
4796 req.num_tx_rings = cpu_to_le16(tx_rings);
4797 if (bp->flags & BNXT_FLAG_NEW_RM) {
4798 flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST | 4806 flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4799 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST | 4807 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4800 FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST | 4808 FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4801 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST | 4809 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4802 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST; 4810 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
4803 enables |= FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS | 4811
4804 FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4805 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS |
4806 FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS |
4807 FUNC_CFG_REQ_ENABLES_NUM_VNICS;
4808 req.num_rx_rings = cpu_to_le16(rx_rings);
4809 req.num_cmpl_rings = cpu_to_le16(cp_rings);
4810 req.num_hw_ring_grps = cpu_to_le16(ring_grps);
4811 req.num_stat_ctxs = cpu_to_le16(cp_rings);
4812 req.num_vnics = cpu_to_le16(1);
4813 if (bp->flags & BNXT_FLAG_RFS)
4814 req.num_vnics = cpu_to_le16(rx_rings + 1);
4815 }
4816 req.flags = cpu_to_le32(flags); 4812 req.flags = cpu_to_le32(flags);
4817 req.enables = cpu_to_le32(enables);
4818 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 4813 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4819 if (rc) 4814 if (rc)
4820 return -ENOMEM; 4815 return -ENOMEM;
@@ -4822,17 +4817,17 @@ static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4822} 4817}
4823 4818
4824static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings, 4819static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4825 int ring_grps, int cp_rings) 4820 int ring_grps, int cp_rings, int vnics)
4826{ 4821{
4827 if (bp->hwrm_spec_code < 0x10801) 4822 if (bp->hwrm_spec_code < 0x10801)
4828 return 0; 4823 return 0;
4829 4824
4830 if (BNXT_PF(bp)) 4825 if (BNXT_PF(bp))
4831 return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings, 4826 return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings,
4832 ring_grps, cp_rings); 4827 ring_grps, cp_rings, vnics);
4833 4828
4834 return bnxt_hwrm_check_vf_rings(bp, tx_rings, rx_rings, ring_grps, 4829 return bnxt_hwrm_check_vf_rings(bp, tx_rings, rx_rings, ring_grps,
4835 cp_rings); 4830 cp_rings, vnics);
4836} 4831}
4837 4832
4838static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal, 4833static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
@@ -5865,7 +5860,6 @@ static int bnxt_init_msix(struct bnxt *bp)
5865 if (rc) 5860 if (rc)
5866 goto msix_setup_exit; 5861 goto msix_setup_exit;
5867 5862
5868 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
5869 bp->cp_nr_rings = (min == 1) ? 5863 bp->cp_nr_rings = (min == 1) ?
5870 max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 5864 max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
5871 bp->tx_nr_rings + bp->rx_nr_rings; 5865 bp->tx_nr_rings + bp->rx_nr_rings;
@@ -5897,7 +5891,6 @@ static int bnxt_init_inta(struct bnxt *bp)
5897 bp->rx_nr_rings = 1; 5891 bp->rx_nr_rings = 1;
5898 bp->tx_nr_rings = 1; 5892 bp->tx_nr_rings = 1;
5899 bp->cp_nr_rings = 1; 5893 bp->cp_nr_rings = 1;
5900 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
5901 bp->flags |= BNXT_FLAG_SHARED_RINGS; 5894 bp->flags |= BNXT_FLAG_SHARED_RINGS;
5902 bp->irq_tbl[0].vector = bp->pdev->irq; 5895 bp->irq_tbl[0].vector = bp->pdev->irq;
5903 return 0; 5896 return 0;
@@ -7531,7 +7524,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
7531 int max_rx, max_tx, tx_sets = 1; 7524 int max_rx, max_tx, tx_sets = 1;
7532 int tx_rings_needed; 7525 int tx_rings_needed;
7533 int rx_rings = rx; 7526 int rx_rings = rx;
7534 int cp, rc; 7527 int cp, vnics, rc;
7535 7528
7536 if (tcs) 7529 if (tcs)
7537 tx_sets = tcs; 7530 tx_sets = tcs;
@@ -7547,10 +7540,15 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
7547 if (max_tx < tx_rings_needed) 7540 if (max_tx < tx_rings_needed)
7548 return -ENOMEM; 7541 return -ENOMEM;
7549 7542
7543 vnics = 1;
7544 if (bp->flags & BNXT_FLAG_RFS)
7545 vnics += rx_rings;
7546
7550 if (bp->flags & BNXT_FLAG_AGG_RINGS) 7547 if (bp->flags & BNXT_FLAG_AGG_RINGS)
7551 rx_rings <<= 1; 7548 rx_rings <<= 1;
7552 cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx; 7549 cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx;
7553 return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp); 7550 return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp,
7551 vnics);
7554} 7552}
7555 7553
7556static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev) 7554static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
@@ -8437,13 +8435,20 @@ int bnxt_restore_pf_fw_resources(struct bnxt *bp)
8437 return 0; 8435 return 0;
8438 8436
8439 bnxt_hwrm_func_qcaps(bp); 8437 bnxt_hwrm_func_qcaps(bp);
8440 __bnxt_close_nic(bp, true, false); 8438
8439 if (netif_running(bp->dev))
8440 __bnxt_close_nic(bp, true, false);
8441
8441 bnxt_clear_int_mode(bp); 8442 bnxt_clear_int_mode(bp);
8442 rc = bnxt_init_int_mode(bp); 8443 rc = bnxt_init_int_mode(bp);
8443 if (rc) 8444
8444 dev_close(bp->dev); 8445 if (netif_running(bp->dev)) {
8445 else 8446 if (rc)
8446 rc = bnxt_open_nic(bp, true, false); 8447 dev_close(bp->dev);
8448 else
8449 rc = bnxt_open_nic(bp, true, false);
8450 }
8451
8447 return rc; 8452 return rc;
8448} 8453}
8449 8454
@@ -8664,6 +8669,11 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
8664 if (rc) 8669 if (rc)
8665 goto init_err_pci_clean; 8670 goto init_err_pci_clean;
8666 8671
8672 /* No TC has been set yet and rings may have been trimmed due to
8673 * limited MSIX, so we re-initialize the TX rings per TC.
8674 */
8675 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8676
8667 bnxt_get_wol_settings(bp); 8677 bnxt_get_wol_settings(bp);
8668 if (bp->flags & BNXT_FLAG_WOL_CAP) 8678 if (bp->flags & BNXT_FLAG_WOL_CAP)
8669 device_set_wakeup_enable(&pdev->dev, bp->wol); 8679 device_set_wakeup_enable(&pdev->dev, bp->wol);
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
index 1989c470172c..5e3d62189cab 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -189,6 +189,7 @@ struct rx_cmp_ext {
189 #define RX_CMP_FLAGS2_T_L4_CS_CALC (0x1 << 3) 189 #define RX_CMP_FLAGS2_T_L4_CS_CALC (0x1 << 3)
190 #define RX_CMP_FLAGS2_META_FORMAT_VLAN (0x1 << 4) 190 #define RX_CMP_FLAGS2_META_FORMAT_VLAN (0x1 << 4)
191 __le32 rx_cmp_meta_data; 191 __le32 rx_cmp_meta_data;
192 #define RX_CMP_FLAGS2_METADATA_TCI_MASK 0xffff
192 #define RX_CMP_FLAGS2_METADATA_VID_MASK 0xfff 193 #define RX_CMP_FLAGS2_METADATA_VID_MASK 0xfff
193 #define RX_CMP_FLAGS2_METADATA_TPID_MASK 0xffff0000 194 #define RX_CMP_FLAGS2_METADATA_TPID_MASK 0xffff0000
194 #define RX_CMP_FLAGS2_METADATA_TPID_SFT 16 195 #define RX_CMP_FLAGS2_METADATA_TPID_SFT 16
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
index fbe6e208e17b..65c2cee35766 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
@@ -349,6 +349,9 @@ static int bnxt_hwrm_cfa_flow_free(struct bnxt *bp, __le16 flow_handle)
349 if (rc) 349 if (rc)
350 netdev_info(bp->dev, "Error: %s: flow_handle=0x%x rc=%d", 350 netdev_info(bp->dev, "Error: %s: flow_handle=0x%x rc=%d",
351 __func__, flow_handle, rc); 351 __func__, flow_handle, rc);
352
353 if (rc)
354 rc = -EIO;
352 return rc; 355 return rc;
353} 356}
354 357
@@ -484,13 +487,15 @@ static int bnxt_hwrm_cfa_flow_alloc(struct bnxt *bp, struct bnxt_tc_flow *flow,
484 req.action_flags = cpu_to_le16(action_flags); 487 req.action_flags = cpu_to_le16(action_flags);
485 488
486 mutex_lock(&bp->hwrm_cmd_lock); 489 mutex_lock(&bp->hwrm_cmd_lock);
487
488 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 490 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
489 if (!rc) 491 if (!rc)
490 *flow_handle = resp->flow_handle; 492 *flow_handle = resp->flow_handle;
491
492 mutex_unlock(&bp->hwrm_cmd_lock); 493 mutex_unlock(&bp->hwrm_cmd_lock);
493 494
495 if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR)
496 rc = -ENOSPC;
497 else if (rc)
498 rc = -EIO;
494 return rc; 499 return rc;
495} 500}
496 501
@@ -561,6 +566,8 @@ static int hwrm_cfa_decap_filter_alloc(struct bnxt *bp,
561 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc); 566 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc);
562 mutex_unlock(&bp->hwrm_cmd_lock); 567 mutex_unlock(&bp->hwrm_cmd_lock);
563 568
569 if (rc)
570 rc = -EIO;
564 return rc; 571 return rc;
565} 572}
566 573
@@ -576,6 +583,9 @@ static int hwrm_cfa_decap_filter_free(struct bnxt *bp,
576 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 583 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
577 if (rc) 584 if (rc)
578 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc); 585 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc);
586
587 if (rc)
588 rc = -EIO;
579 return rc; 589 return rc;
580} 590}
581 591
@@ -624,6 +634,8 @@ static int hwrm_cfa_encap_record_alloc(struct bnxt *bp,
624 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc); 634 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc);
625 mutex_unlock(&bp->hwrm_cmd_lock); 635 mutex_unlock(&bp->hwrm_cmd_lock);
626 636
637 if (rc)
638 rc = -EIO;
627 return rc; 639 return rc;
628} 640}
629 641
@@ -639,6 +651,9 @@ static int hwrm_cfa_encap_record_free(struct bnxt *bp,
639 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 651 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
640 if (rc) 652 if (rc)
641 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc); 653 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc);
654
655 if (rc)
656 rc = -EIO;
642 return rc; 657 return rc;
643} 658}
644 659
@@ -1269,11 +1284,8 @@ static int bnxt_tc_del_flow(struct bnxt *bp,
1269 flow_node = rhashtable_lookup_fast(&tc_info->flow_table, 1284 flow_node = rhashtable_lookup_fast(&tc_info->flow_table,
1270 &tc_flow_cmd->cookie, 1285 &tc_flow_cmd->cookie,
1271 tc_info->flow_ht_params); 1286 tc_info->flow_ht_params);
1272 if (!flow_node) { 1287 if (!flow_node)
1273 netdev_info(bp->dev, "ERROR: no flow_node for cookie %lx",
1274 tc_flow_cmd->cookie);
1275 return -EINVAL; 1288 return -EINVAL;
1276 }
1277 1289
1278 return __bnxt_tc_del_flow(bp, flow_node); 1290 return __bnxt_tc_del_flow(bp, flow_node);
1279} 1291}
@@ -1290,11 +1302,8 @@ static int bnxt_tc_get_flow_stats(struct bnxt *bp,
1290 flow_node = rhashtable_lookup_fast(&tc_info->flow_table, 1302 flow_node = rhashtable_lookup_fast(&tc_info->flow_table,
1291 &tc_flow_cmd->cookie, 1303 &tc_flow_cmd->cookie,
1292 tc_info->flow_ht_params); 1304 tc_info->flow_ht_params);
1293 if (!flow_node) { 1305 if (!flow_node)
1294 netdev_info(bp->dev, "Error: no flow_node for cookie %lx",
1295 tc_flow_cmd->cookie);
1296 return -1; 1306 return -1;
1297 }
1298 1307
1299 flow = &flow_node->flow; 1308 flow = &flow_node->flow;
1300 curr_stats = &flow->stats; 1309 curr_stats = &flow->stats;
@@ -1344,8 +1353,10 @@ bnxt_hwrm_cfa_flow_stats_get(struct bnxt *bp, int num_flows,
1344 } else { 1353 } else {
1345 netdev_info(bp->dev, "error rc=%d", rc); 1354 netdev_info(bp->dev, "error rc=%d", rc);
1346 } 1355 }
1347
1348 mutex_unlock(&bp->hwrm_cmd_lock); 1356 mutex_unlock(&bp->hwrm_cmd_lock);
1357
1358 if (rc)
1359 rc = -EIO;
1349 return rc; 1360 return rc;
1350} 1361}
1351 1362
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index a77ee2f8fb8d..f2593978ae75 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -922,8 +922,8 @@ static int tg3_ape_send_event(struct tg3 *tp, u32 event)
922 if (!(apedata & APE_FW_STATUS_READY)) 922 if (!(apedata & APE_FW_STATUS_READY))
923 return -EAGAIN; 923 return -EAGAIN;
924 924
925 /* Wait for up to 1 millisecond for APE to service previous event. */ 925 /* Wait for up to 20 millisecond for APE to service previous event. */
926 err = tg3_ape_event_lock(tp, 1000); 926 err = tg3_ape_event_lock(tp, 20000);
927 if (err) 927 if (err)
928 return err; 928 return err;
929 929
@@ -946,6 +946,7 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
946 946
947 switch (kind) { 947 switch (kind) {
948 case RESET_KIND_INIT: 948 case RESET_KIND_INIT:
949 tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_COUNT, tp->ape_hb++);
949 tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 950 tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG,
950 APE_HOST_SEG_SIG_MAGIC); 951 APE_HOST_SEG_SIG_MAGIC);
951 tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, 952 tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN,
@@ -962,13 +963,6 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
962 event = APE_EVENT_STATUS_STATE_START; 963 event = APE_EVENT_STATUS_STATE_START;
963 break; 964 break;
964 case RESET_KIND_SHUTDOWN: 965 case RESET_KIND_SHUTDOWN:
965 /* With the interface we are currently using,
966 * APE does not track driver state. Wiping
967 * out the HOST SEGMENT SIGNATURE forces
968 * the APE to assume OS absent status.
969 */
970 tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0);
971
972 if (device_may_wakeup(&tp->pdev->dev) && 966 if (device_may_wakeup(&tp->pdev->dev) &&
973 tg3_flag(tp, WOL_ENABLE)) { 967 tg3_flag(tp, WOL_ENABLE)) {
974 tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, 968 tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED,
@@ -990,6 +984,18 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
990 tg3_ape_send_event(tp, event); 984 tg3_ape_send_event(tp, event);
991} 985}
992 986
987static void tg3_send_ape_heartbeat(struct tg3 *tp,
988 unsigned long interval)
989{
990 /* Check if hb interval has exceeded */
991 if (!tg3_flag(tp, ENABLE_APE) ||
992 time_before(jiffies, tp->ape_hb_jiffies + interval))
993 return;
994
995 tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_COUNT, tp->ape_hb++);
996 tp->ape_hb_jiffies = jiffies;
997}
998
993static void tg3_disable_ints(struct tg3 *tp) 999static void tg3_disable_ints(struct tg3 *tp)
994{ 1000{
995 int i; 1001 int i;
@@ -7262,6 +7268,7 @@ static int tg3_poll_msix(struct napi_struct *napi, int budget)
7262 } 7268 }
7263 } 7269 }
7264 7270
7271 tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1);
7265 return work_done; 7272 return work_done;
7266 7273
7267tx_recovery: 7274tx_recovery:
@@ -7344,6 +7351,7 @@ static int tg3_poll(struct napi_struct *napi, int budget)
7344 } 7351 }
7345 } 7352 }
7346 7353
7354 tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1);
7347 return work_done; 7355 return work_done;
7348 7356
7349tx_recovery: 7357tx_recovery:
@@ -10732,7 +10740,7 @@ static int tg3_reset_hw(struct tg3 *tp, bool reset_phy)
10732 if (tg3_flag(tp, ENABLE_APE)) 10740 if (tg3_flag(tp, ENABLE_APE))
10733 /* Write our heartbeat update interval to APE. */ 10741 /* Write our heartbeat update interval to APE. */
10734 tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, 10742 tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS,
10735 APE_HOST_HEARTBEAT_INT_DISABLE); 10743 APE_HOST_HEARTBEAT_INT_5SEC);
10736 10744
10737 tg3_write_sig_post_reset(tp, RESET_KIND_INIT); 10745 tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
10738 10746
@@ -11077,6 +11085,9 @@ static void tg3_timer(struct timer_list *t)
11077 tp->asf_counter = tp->asf_multiplier; 11085 tp->asf_counter = tp->asf_multiplier;
11078 } 11086 }
11079 11087
11088 /* Update the APE heartbeat every 5 seconds.*/
11089 tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL);
11090
11080 spin_unlock(&tp->lock); 11091 spin_unlock(&tp->lock);
11081 11092
11082restart_timer: 11093restart_timer:
@@ -16653,6 +16664,8 @@ static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent)
16653 pci_state_reg); 16664 pci_state_reg);
16654 16665
16655 tg3_ape_lock_init(tp); 16666 tg3_ape_lock_init(tp);
16667 tp->ape_hb_interval =
16668 msecs_to_jiffies(APE_HOST_HEARTBEAT_INT_5SEC);
16656 } 16669 }
16657 16670
16658 /* Set up tp->grc_local_ctrl before calling 16671 /* Set up tp->grc_local_ctrl before calling
diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
index 47f51cc0566d..1d61aa3efda1 100644
--- a/drivers/net/ethernet/broadcom/tg3.h
+++ b/drivers/net/ethernet/broadcom/tg3.h
@@ -2508,6 +2508,7 @@
2508#define TG3_APE_LOCK_PHY3 5 2508#define TG3_APE_LOCK_PHY3 5
2509#define TG3_APE_LOCK_GPIO 7 2509#define TG3_APE_LOCK_GPIO 7
2510 2510
2511#define TG3_APE_HB_INTERVAL (tp->ape_hb_interval)
2511#define TG3_EEPROM_SB_F1R2_MBA_OFF 0x10 2512#define TG3_EEPROM_SB_F1R2_MBA_OFF 0x10
2512 2513
2513 2514
@@ -3423,6 +3424,10 @@ struct tg3 {
3423 struct device *hwmon_dev; 3424 struct device *hwmon_dev;
3424 bool link_up; 3425 bool link_up;
3425 bool pcierr_recovery; 3426 bool pcierr_recovery;
3427
3428 u32 ape_hb;
3429 unsigned long ape_hb_interval;
3430 unsigned long ape_hb_jiffies;
3426}; 3431};
3427 3432
3428/* Accessor macros for chip and asic attributes 3433/* Accessor macros for chip and asic attributes
diff --git a/drivers/net/ethernet/cavium/common/cavium_ptp.c b/drivers/net/ethernet/cavium/common/cavium_ptp.c
index c87c9c684a33..d59497a7bdce 100644
--- a/drivers/net/ethernet/cavium/common/cavium_ptp.c
+++ b/drivers/net/ethernet/cavium/common/cavium_ptp.c
@@ -75,6 +75,8 @@ EXPORT_SYMBOL(cavium_ptp_get);
75 75
76void cavium_ptp_put(struct cavium_ptp *ptp) 76void cavium_ptp_put(struct cavium_ptp *ptp)
77{ 77{
78 if (!ptp)
79 return;
78 pci_dev_put(ptp->pdev); 80 pci_dev_put(ptp->pdev);
79} 81}
80EXPORT_SYMBOL(cavium_ptp_put); 82EXPORT_SYMBOL(cavium_ptp_put);
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
index b68cde9f17d2..7d9c5ffbd041 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
@@ -67,11 +67,6 @@ module_param(cpi_alg, int, S_IRUGO);
67MODULE_PARM_DESC(cpi_alg, 67MODULE_PARM_DESC(cpi_alg,
68 "PFC algorithm (0=none, 1=VLAN, 2=VLAN16, 3=IP Diffserv)"); 68 "PFC algorithm (0=none, 1=VLAN, 2=VLAN16, 3=IP Diffserv)");
69 69
70struct nicvf_xdp_tx {
71 u64 dma_addr;
72 u8 qidx;
73};
74
75static inline u8 nicvf_netdev_qidx(struct nicvf *nic, u8 qidx) 70static inline u8 nicvf_netdev_qidx(struct nicvf *nic, u8 qidx)
76{ 71{
77 if (nic->sqs_mode) 72 if (nic->sqs_mode)
@@ -507,29 +502,14 @@ static int nicvf_init_resources(struct nicvf *nic)
507 return 0; 502 return 0;
508} 503}
509 504
510static void nicvf_unmap_page(struct nicvf *nic, struct page *page, u64 dma_addr)
511{
512 /* Check if it's a recycled page, if not unmap the DMA mapping.
513 * Recycled page holds an extra reference.
514 */
515 if (page_ref_count(page) == 1) {
516 dma_addr &= PAGE_MASK;
517 dma_unmap_page_attrs(&nic->pdev->dev, dma_addr,
518 RCV_FRAG_LEN + XDP_HEADROOM,
519 DMA_FROM_DEVICE,
520 DMA_ATTR_SKIP_CPU_SYNC);
521 }
522}
523
524static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog, 505static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog,
525 struct cqe_rx_t *cqe_rx, struct snd_queue *sq, 506 struct cqe_rx_t *cqe_rx, struct snd_queue *sq,
526 struct rcv_queue *rq, struct sk_buff **skb) 507 struct rcv_queue *rq, struct sk_buff **skb)
527{ 508{
528 struct xdp_buff xdp; 509 struct xdp_buff xdp;
529 struct page *page; 510 struct page *page;
530 struct nicvf_xdp_tx *xdp_tx = NULL;
531 u32 action; 511 u32 action;
532 u16 len, err, offset = 0; 512 u16 len, offset = 0;
533 u64 dma_addr, cpu_addr; 513 u64 dma_addr, cpu_addr;
534 void *orig_data; 514 void *orig_data;
535 515
@@ -543,7 +523,7 @@ static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog,
543 cpu_addr = (u64)phys_to_virt(cpu_addr); 523 cpu_addr = (u64)phys_to_virt(cpu_addr);
544 page = virt_to_page((void *)cpu_addr); 524 page = virt_to_page((void *)cpu_addr);
545 525
546 xdp.data_hard_start = page_address(page) + RCV_BUF_HEADROOM; 526 xdp.data_hard_start = page_address(page);
547 xdp.data = (void *)cpu_addr; 527 xdp.data = (void *)cpu_addr;
548 xdp_set_data_meta_invalid(&xdp); 528 xdp_set_data_meta_invalid(&xdp);
549 xdp.data_end = xdp.data + len; 529 xdp.data_end = xdp.data + len;
@@ -563,7 +543,18 @@ static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog,
563 543
564 switch (action) { 544 switch (action) {
565 case XDP_PASS: 545 case XDP_PASS:
566 nicvf_unmap_page(nic, page, dma_addr); 546 /* Check if it's a recycled page, if not
547 * unmap the DMA mapping.
548 *
549 * Recycled page holds an extra reference.
550 */
551 if (page_ref_count(page) == 1) {
552 dma_addr &= PAGE_MASK;
553 dma_unmap_page_attrs(&nic->pdev->dev, dma_addr,
554 RCV_FRAG_LEN + XDP_PACKET_HEADROOM,
555 DMA_FROM_DEVICE,
556 DMA_ATTR_SKIP_CPU_SYNC);
557 }
567 558
568 /* Build SKB and pass on packet to network stack */ 559 /* Build SKB and pass on packet to network stack */
569 *skb = build_skb(xdp.data, 560 *skb = build_skb(xdp.data,
@@ -576,20 +567,6 @@ static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog,
576 case XDP_TX: 567 case XDP_TX:
577 nicvf_xdp_sq_append_pkt(nic, sq, (u64)xdp.data, dma_addr, len); 568 nicvf_xdp_sq_append_pkt(nic, sq, (u64)xdp.data, dma_addr, len);
578 return true; 569 return true;
579 case XDP_REDIRECT:
580 /* Save DMA address for use while transmitting */
581 xdp_tx = (struct nicvf_xdp_tx *)page_address(page);
582 xdp_tx->dma_addr = dma_addr;
583 xdp_tx->qidx = nicvf_netdev_qidx(nic, cqe_rx->rq_idx);
584
585 err = xdp_do_redirect(nic->pnicvf->netdev, &xdp, prog);
586 if (!err)
587 return true;
588
589 /* Free the page on error */
590 nicvf_unmap_page(nic, page, dma_addr);
591 put_page(page);
592 break;
593 default: 570 default:
594 bpf_warn_invalid_xdp_action(action); 571 bpf_warn_invalid_xdp_action(action);
595 /* fall through */ 572 /* fall through */
@@ -597,7 +574,18 @@ static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog,
597 trace_xdp_exception(nic->netdev, prog, action); 574 trace_xdp_exception(nic->netdev, prog, action);
598 /* fall through */ 575 /* fall through */
599 case XDP_DROP: 576 case XDP_DROP:
600 nicvf_unmap_page(nic, page, dma_addr); 577 /* Check if it's a recycled page, if not
578 * unmap the DMA mapping.
579 *
580 * Recycled page holds an extra reference.
581 */
582 if (page_ref_count(page) == 1) {
583 dma_addr &= PAGE_MASK;
584 dma_unmap_page_attrs(&nic->pdev->dev, dma_addr,
585 RCV_FRAG_LEN + XDP_PACKET_HEADROOM,
586 DMA_FROM_DEVICE,
587 DMA_ATTR_SKIP_CPU_SYNC);
588 }
601 put_page(page); 589 put_page(page);
602 return true; 590 return true;
603 } 591 }
@@ -1864,50 +1852,6 @@ static int nicvf_xdp(struct net_device *netdev, struct netdev_bpf *xdp)
1864 } 1852 }
1865} 1853}
1866 1854
1867static int nicvf_xdp_xmit(struct net_device *netdev, struct xdp_buff *xdp)
1868{
1869 struct nicvf *nic = netdev_priv(netdev);
1870 struct nicvf *snic = nic;
1871 struct nicvf_xdp_tx *xdp_tx;
1872 struct snd_queue *sq;
1873 struct page *page;
1874 int err, qidx;
1875
1876 if (!netif_running(netdev) || !nic->xdp_prog)
1877 return -EINVAL;
1878
1879 page = virt_to_page(xdp->data);
1880 xdp_tx = (struct nicvf_xdp_tx *)page_address(page);
1881 qidx = xdp_tx->qidx;
1882
1883 if (xdp_tx->qidx >= nic->xdp_tx_queues)
1884 return -EINVAL;
1885
1886 /* Get secondary Qset's info */
1887 if (xdp_tx->qidx >= MAX_SND_QUEUES_PER_QS) {
1888 qidx = xdp_tx->qidx / MAX_SND_QUEUES_PER_QS;
1889 snic = (struct nicvf *)nic->snicvf[qidx - 1];
1890 if (!snic)
1891 return -EINVAL;
1892 qidx = xdp_tx->qidx % MAX_SND_QUEUES_PER_QS;
1893 }
1894
1895 sq = &snic->qs->sq[qidx];
1896 err = nicvf_xdp_sq_append_pkt(snic, sq, (u64)xdp->data,
1897 xdp_tx->dma_addr,
1898 xdp->data_end - xdp->data);
1899 if (err)
1900 return -ENOMEM;
1901
1902 nicvf_xdp_sq_doorbell(snic, sq, qidx);
1903 return 0;
1904}
1905
1906static void nicvf_xdp_flush(struct net_device *dev)
1907{
1908 return;
1909}
1910
1911static int nicvf_config_hwtstamp(struct net_device *netdev, struct ifreq *ifr) 1855static int nicvf_config_hwtstamp(struct net_device *netdev, struct ifreq *ifr)
1912{ 1856{
1913 struct hwtstamp_config config; 1857 struct hwtstamp_config config;
@@ -1986,8 +1930,6 @@ static const struct net_device_ops nicvf_netdev_ops = {
1986 .ndo_fix_features = nicvf_fix_features, 1930 .ndo_fix_features = nicvf_fix_features,
1987 .ndo_set_features = nicvf_set_features, 1931 .ndo_set_features = nicvf_set_features,
1988 .ndo_bpf = nicvf_xdp, 1932 .ndo_bpf = nicvf_xdp,
1989 .ndo_xdp_xmit = nicvf_xdp_xmit,
1990 .ndo_xdp_flush = nicvf_xdp_flush,
1991 .ndo_do_ioctl = nicvf_ioctl, 1933 .ndo_do_ioctl = nicvf_ioctl,
1992}; 1934};
1993 1935
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
index 3eae9ff9b53a..d42704d07484 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
@@ -204,7 +204,7 @@ static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, struct rbdr *rbdr,
204 204
205 /* Reserve space for header modifications by BPF program */ 205 /* Reserve space for header modifications by BPF program */
206 if (rbdr->is_xdp) 206 if (rbdr->is_xdp)
207 buf_len += XDP_HEADROOM; 207 buf_len += XDP_PACKET_HEADROOM;
208 208
209 /* Check if it's recycled */ 209 /* Check if it's recycled */
210 if (pgcache) 210 if (pgcache)
@@ -224,9 +224,8 @@ ret:
224 nic->rb_page = NULL; 224 nic->rb_page = NULL;
225 return -ENOMEM; 225 return -ENOMEM;
226 } 226 }
227
228 if (pgcache) 227 if (pgcache)
229 pgcache->dma_addr = *rbuf + XDP_HEADROOM; 228 pgcache->dma_addr = *rbuf + XDP_PACKET_HEADROOM;
230 nic->rb_page_offset += buf_len; 229 nic->rb_page_offset += buf_len;
231 } 230 }
232 231
@@ -1244,7 +1243,7 @@ int nicvf_xdp_sq_append_pkt(struct nicvf *nic, struct snd_queue *sq,
1244 int qentry; 1243 int qentry;
1245 1244
1246 if (subdesc_cnt > sq->xdp_free_cnt) 1245 if (subdesc_cnt > sq->xdp_free_cnt)
1247 return -1; 1246 return 0;
1248 1247
1249 qentry = nicvf_get_sq_desc(sq, subdesc_cnt); 1248 qentry = nicvf_get_sq_desc(sq, subdesc_cnt);
1250 1249
@@ -1255,7 +1254,7 @@ int nicvf_xdp_sq_append_pkt(struct nicvf *nic, struct snd_queue *sq,
1255 1254
1256 sq->xdp_desc_cnt += subdesc_cnt; 1255 sq->xdp_desc_cnt += subdesc_cnt;
1257 1256
1258 return 0; 1257 return 1;
1259} 1258}
1260 1259
1261/* Calculate no of SQ subdescriptors needed to transmit all 1260/* Calculate no of SQ subdescriptors needed to transmit all
@@ -1656,7 +1655,7 @@ static void nicvf_unmap_rcv_buffer(struct nicvf *nic, u64 dma_addr,
1656 if (page_ref_count(page) != 1) 1655 if (page_ref_count(page) != 1)
1657 return; 1656 return;
1658 1657
1659 len += XDP_HEADROOM; 1658 len += XDP_PACKET_HEADROOM;
1660 /* Receive buffers in XDP mode are mapped from page start */ 1659 /* Receive buffers in XDP mode are mapped from page start */
1661 dma_addr &= PAGE_MASK; 1660 dma_addr &= PAGE_MASK;
1662 } 1661 }
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.h b/drivers/net/ethernet/cavium/thunder/nicvf_queues.h
index ce1eed7a6d63..5e9a03cf1b4d 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.h
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.h
@@ -11,7 +11,6 @@
11 11
12#include <linux/netdevice.h> 12#include <linux/netdevice.h>
13#include <linux/iommu.h> 13#include <linux/iommu.h>
14#include <linux/bpf.h>
15#include <net/xdp.h> 14#include <net/xdp.h>
16#include "q_struct.h" 15#include "q_struct.h"
17 16
@@ -94,9 +93,6 @@
94#define RCV_FRAG_LEN (SKB_DATA_ALIGN(DMA_BUFFER_LEN + NET_SKB_PAD) + \ 93#define RCV_FRAG_LEN (SKB_DATA_ALIGN(DMA_BUFFER_LEN + NET_SKB_PAD) + \
95 SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) 94 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
96 95
97#define RCV_BUF_HEADROOM 128 /* To store dma address for XDP redirect */
98#define XDP_HEADROOM (XDP_PACKET_HEADROOM + RCV_BUF_HEADROOM)
99
100#define MAX_CQES_FOR_TX ((SND_QUEUE_LEN / MIN_SQ_DESC_PER_PKT_XMIT) * \ 96#define MAX_CQES_FOR_TX ((SND_QUEUE_LEN / MIN_SQ_DESC_PER_PKT_XMIT) * \
101 MAX_CQE_PER_PKT_XMIT) 97 MAX_CQE_PER_PKT_XMIT)
102 98
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
index 557fd8bfd54e..00a1d2d13169 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
@@ -472,7 +472,7 @@ int cudbg_collect_cim_la(struct cudbg_init *pdbg_init,
472 472
473 if (is_t6(padap->params.chip)) { 473 if (is_t6(padap->params.chip)) {
474 size = padap->params.cim_la_size / 10 + 1; 474 size = padap->params.cim_la_size / 10 + 1;
475 size *= 11 * sizeof(u32); 475 size *= 10 * sizeof(u32);
476 } else { 476 } else {
477 size = padap->params.cim_la_size / 8; 477 size = padap->params.cim_la_size / 8;
478 size *= 8 * sizeof(u32); 478 size *= 8 * sizeof(u32);
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c
index 30485f9a598f..143686c60234 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c
@@ -102,7 +102,7 @@ static u32 cxgb4_get_entity_length(struct adapter *adap, u32 entity)
102 case CUDBG_CIM_LA: 102 case CUDBG_CIM_LA:
103 if (is_t6(adap->params.chip)) { 103 if (is_t6(adap->params.chip)) {
104 len = adap->params.cim_la_size / 10 + 1; 104 len = adap->params.cim_la_size / 10 + 1;
105 len *= 11 * sizeof(u32); 105 len *= 10 * sizeof(u32);
106 } else { 106 } else {
107 len = adap->params.cim_la_size / 8; 107 len = adap->params.cim_la_size / 8;
108 len *= 8 * sizeof(u32); 108 len *= 8 * sizeof(u32);
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 56bc626ef006..61022b5f6743 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -4970,7 +4970,6 @@ static void cxgb4_mgmt_setup(struct net_device *dev)
4970 /* Initialize the device structure. */ 4970 /* Initialize the device structure. */
4971 dev->netdev_ops = &cxgb4_mgmt_netdev_ops; 4971 dev->netdev_ops = &cxgb4_mgmt_netdev_ops;
4972 dev->ethtool_ops = &cxgb4_mgmt_ethtool_ops; 4972 dev->ethtool_ops = &cxgb4_mgmt_ethtool_ops;
4973 dev->needs_free_netdev = true;
4974} 4973}
4975 4974
4976static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs) 4975static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
@@ -4982,9 +4981,10 @@ static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
4982 4981
4983 pcie_fw = readl(adap->regs + PCIE_FW_A); 4982 pcie_fw = readl(adap->regs + PCIE_FW_A);
4984 /* Check if cxgb4 is the MASTER and fw is initialized */ 4983 /* Check if cxgb4 is the MASTER and fw is initialized */
4985 if (!(pcie_fw & PCIE_FW_INIT_F) || 4984 if (num_vfs &&
4985 (!(pcie_fw & PCIE_FW_INIT_F) ||
4986 !(pcie_fw & PCIE_FW_MASTER_VLD_F) || 4986 !(pcie_fw & PCIE_FW_MASTER_VLD_F) ||
4987 PCIE_FW_MASTER_G(pcie_fw) != CXGB4_UNIFIED_PF) { 4987 PCIE_FW_MASTER_G(pcie_fw) != CXGB4_UNIFIED_PF)) {
4988 dev_warn(&pdev->dev, 4988 dev_warn(&pdev->dev,
4989 "cxgb4 driver needs to be MASTER to support SRIOV\n"); 4989 "cxgb4 driver needs to be MASTER to support SRIOV\n");
4990 return -EOPNOTSUPP; 4990 return -EOPNOTSUPP;
@@ -5180,6 +5180,8 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
5180 adapter->name = pci_name(pdev); 5180 adapter->name = pci_name(pdev);
5181 adapter->mbox = func; 5181 adapter->mbox = func;
5182 adapter->pf = func; 5182 adapter->pf = func;
5183 adapter->params.chip = chip;
5184 adapter->adap_idx = adap_idx;
5183 adapter->msg_enable = DFLT_MSG_ENABLE; 5185 adapter->msg_enable = DFLT_MSG_ENABLE;
5184 adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) + 5186 adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
5185 (sizeof(struct mbox_cmd) * 5187 (sizeof(struct mbox_cmd) *
@@ -5599,24 +5601,24 @@ static void remove_one(struct pci_dev *pdev)
5599#if IS_ENABLED(CONFIG_IPV6) 5601#if IS_ENABLED(CONFIG_IPV6)
5600 t4_cleanup_clip_tbl(adapter); 5602 t4_cleanup_clip_tbl(adapter);
5601#endif 5603#endif
5602 iounmap(adapter->regs);
5603 if (!is_t4(adapter->params.chip)) 5604 if (!is_t4(adapter->params.chip))
5604 iounmap(adapter->bar2); 5605 iounmap(adapter->bar2);
5605 pci_disable_pcie_error_reporting(pdev);
5606 if ((adapter->flags & DEV_ENABLED)) {
5607 pci_disable_device(pdev);
5608 adapter->flags &= ~DEV_ENABLED;
5609 }
5610 pci_release_regions(pdev);
5611 kfree(adapter->mbox_log);
5612 synchronize_rcu();
5613 kfree(adapter);
5614 } 5606 }
5615#ifdef CONFIG_PCI_IOV 5607#ifdef CONFIG_PCI_IOV
5616 else { 5608 else {
5617 cxgb4_iov_configure(adapter->pdev, 0); 5609 cxgb4_iov_configure(adapter->pdev, 0);
5618 } 5610 }
5619#endif 5611#endif
5612 iounmap(adapter->regs);
5613 pci_disable_pcie_error_reporting(pdev);
5614 if ((adapter->flags & DEV_ENABLED)) {
5615 pci_disable_device(pdev);
5616 adapter->flags &= ~DEV_ENABLED;
5617 }
5618 pci_release_regions(pdev);
5619 kfree(adapter->mbox_log);
5620 synchronize_rcu();
5621 kfree(adapter);
5620} 5622}
5621 5623
5622/* "Shutdown" quiesces the device, stopping Ingress Packet and Interrupt 5624/* "Shutdown" quiesces the device, stopping Ingress Packet and Interrupt
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
index 047609ef0515..920bccd6bc40 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
@@ -2637,7 +2637,6 @@ void t4_get_regs(struct adapter *adap, void *buf, size_t buf_size)
2637} 2637}
2638 2638
2639#define EEPROM_STAT_ADDR 0x7bfc 2639#define EEPROM_STAT_ADDR 0x7bfc
2640#define VPD_SIZE 0x800
2641#define VPD_BASE 0x400 2640#define VPD_BASE 0x400
2642#define VPD_BASE_OLD 0 2641#define VPD_BASE_OLD 0
2643#define VPD_LEN 1024 2642#define VPD_LEN 1024
@@ -2704,15 +2703,6 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)
2704 if (!vpd) 2703 if (!vpd)
2705 return -ENOMEM; 2704 return -ENOMEM;
2706 2705
2707 /* We have two VPD data structures stored in the adapter VPD area.
2708 * By default, Linux calculates the size of the VPD area by traversing
2709 * the first VPD area at offset 0x0, so we need to tell the OS what
2710 * our real VPD size is.
2711 */
2712 ret = pci_set_vpd_size(adapter->pdev, VPD_SIZE);
2713 if (ret < 0)
2714 goto out;
2715
2716 /* Card information normally starts at VPD_BASE but early cards had 2706 /* Card information normally starts at VPD_BASE but early cards had
2717 * it at 0. 2707 * it at 0.
2718 */ 2708 */
diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 5eb999af2c40..bd3f6e4d1341 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -540,6 +540,7 @@ static int gmac_setup_txqs(struct net_device *netdev)
540 540
541 if (port->txq_dma_base & ~DMA_Q_BASE_MASK) { 541 if (port->txq_dma_base & ~DMA_Q_BASE_MASK) {
542 dev_warn(geth->dev, "TX queue base it not aligned\n"); 542 dev_warn(geth->dev, "TX queue base it not aligned\n");
543 kfree(skb_tab);
543 return -ENOMEM; 544 return -ENOMEM;
544 } 545 }
545 546
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 7caa8da48421..e4ec32a9ca15 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -2008,7 +2008,6 @@ static inline int dpaa_xmit(struct dpaa_priv *priv,
2008 } 2008 }
2009 2009
2010 if (unlikely(err < 0)) { 2010 if (unlikely(err < 0)) {
2011 percpu_stats->tx_errors++;
2012 percpu_stats->tx_fifo_errors++; 2011 percpu_stats->tx_fifo_errors++;
2013 return err; 2012 return err;
2014 } 2013 }
@@ -2278,7 +2277,6 @@ static enum qman_cb_dqrr_result rx_default_dqrr(struct qman_portal *portal,
2278 vaddr = phys_to_virt(addr); 2277 vaddr = phys_to_virt(addr);
2279 prefetch(vaddr + qm_fd_get_offset(fd)); 2278 prefetch(vaddr + qm_fd_get_offset(fd));
2280 2279
2281 fd_format = qm_fd_get_format(fd);
2282 /* The only FD types that we may receive are contig and S/G */ 2280 /* The only FD types that we may receive are contig and S/G */
2283 WARN_ON((fd_format != qm_fd_contig) && (fd_format != qm_fd_sg)); 2281 WARN_ON((fd_format != qm_fd_contig) && (fd_format != qm_fd_sg));
2284 2282
@@ -2311,8 +2309,10 @@ static enum qman_cb_dqrr_result rx_default_dqrr(struct qman_portal *portal,
2311 2309
2312 skb_len = skb->len; 2310 skb_len = skb->len;
2313 2311
2314 if (unlikely(netif_receive_skb(skb) == NET_RX_DROP)) 2312 if (unlikely(netif_receive_skb(skb) == NET_RX_DROP)) {
2313 percpu_stats->rx_dropped++;
2315 return qman_cb_dqrr_consume; 2314 return qman_cb_dqrr_consume;
2315 }
2316 2316
2317 percpu_stats->rx_packets++; 2317 percpu_stats->rx_packets++;
2318 percpu_stats->rx_bytes += skb_len; 2318 percpu_stats->rx_bytes += skb_len;
@@ -2860,7 +2860,7 @@ static int dpaa_remove(struct platform_device *pdev)
2860 struct device *dev; 2860 struct device *dev;
2861 int err; 2861 int err;
2862 2862
2863 dev = &pdev->dev; 2863 dev = pdev->dev.parent;
2864 net_dev = dev_get_drvdata(dev); 2864 net_dev = dev_get_drvdata(dev);
2865 2865
2866 priv = netdev_priv(net_dev); 2866 priv = netdev_priv(net_dev);
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 7a7f3a42b2aa..d4604bc8eb5b 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -3600,6 +3600,8 @@ fec_drv_remove(struct platform_device *pdev)
3600 fec_enet_mii_remove(fep); 3600 fec_enet_mii_remove(fep);
3601 if (fep->reg_phy) 3601 if (fep->reg_phy)
3602 regulator_disable(fep->reg_phy); 3602 regulator_disable(fep->reg_phy);
3603 pm_runtime_put(&pdev->dev);
3604 pm_runtime_disable(&pdev->dev);
3603 if (of_phy_is_fixed_link(np)) 3605 if (of_phy_is_fixed_link(np))
3604 of_phy_deregister_fixed_link(np); 3606 of_phy_deregister_fixed_link(np);
3605 of_node_put(fep->phy_node); 3607 of_node_put(fep->phy_node);
diff --git a/drivers/net/ethernet/freescale/fman/fman_dtsec.c b/drivers/net/ethernet/freescale/fman/fman_dtsec.c
index ea43b4974149..7af31ddd093f 100644
--- a/drivers/net/ethernet/freescale/fman/fman_dtsec.c
+++ b/drivers/net/ethernet/freescale/fman/fman_dtsec.c
@@ -1100,7 +1100,7 @@ int dtsec_add_hash_mac_address(struct fman_mac *dtsec, enet_addr_t *eth_addr)
1100 set_bucket(dtsec->regs, bucket, true); 1100 set_bucket(dtsec->regs, bucket, true);
1101 1101
1102 /* Create element to be added to the driver hash table */ 1102 /* Create element to be added to the driver hash table */
1103 hash_entry = kmalloc(sizeof(*hash_entry), GFP_KERNEL); 1103 hash_entry = kmalloc(sizeof(*hash_entry), GFP_ATOMIC);
1104 if (!hash_entry) 1104 if (!hash_entry)
1105 return -ENOMEM; 1105 return -ENOMEM;
1106 hash_entry->addr = addr; 1106 hash_entry->addr = addr;
diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
index 3bdeb295514b..f27f9bae1a4a 100644
--- a/drivers/net/ethernet/freescale/gianfar.c
+++ b/drivers/net/ethernet/freescale/gianfar.c
@@ -2934,29 +2934,17 @@ static bool gfar_add_rx_frag(struct gfar_rx_buff *rxb, u32 lstatus,
2934{ 2934{
2935 int size = lstatus & BD_LENGTH_MASK; 2935 int size = lstatus & BD_LENGTH_MASK;
2936 struct page *page = rxb->page; 2936 struct page *page = rxb->page;
2937 bool last = !!(lstatus & BD_LFLAG(RXBD_LAST));
2938
2939 /* Remove the FCS from the packet length */
2940 if (last)
2941 size -= ETH_FCS_LEN;
2942 2937
2943 if (likely(first)) { 2938 if (likely(first)) {
2944 skb_put(skb, size); 2939 skb_put(skb, size);
2945 } else { 2940 } else {
2946 /* the last fragments' length contains the full frame length */ 2941 /* the last fragments' length contains the full frame length */
2947 if (last) 2942 if (lstatus & BD_LFLAG(RXBD_LAST))
2948 size -= skb->len; 2943 size -= skb->len;
2949 2944
2950 /* Add the last fragment if it contains something other than 2945 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
2951 * the FCS, otherwise drop it and trim off any part of the FCS 2946 rxb->page_offset + RXBUF_ALIGNMENT,
2952 * that was already received. 2947 size, GFAR_RXB_TRUESIZE);
2953 */
2954 if (size > 0)
2955 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
2956 rxb->page_offset + RXBUF_ALIGNMENT,
2957 size, GFAR_RXB_TRUESIZE);
2958 else if (size < 0)
2959 pskb_trim(skb, skb->len + size);
2960 } 2948 }
2961 2949
2962 /* try reuse page */ 2950 /* try reuse page */
@@ -3069,12 +3057,12 @@ static void gfar_process_frame(struct net_device *ndev, struct sk_buff *skb)
3069 if (priv->padding) 3057 if (priv->padding)
3070 skb_pull(skb, priv->padding); 3058 skb_pull(skb, priv->padding);
3071 3059
3060 /* Trim off the FCS */
3061 pskb_trim(skb, skb->len - ETH_FCS_LEN);
3062
3072 if (ndev->features & NETIF_F_RXCSUM) 3063 if (ndev->features & NETIF_F_RXCSUM)
3073 gfar_rx_checksum(skb, fcb); 3064 gfar_rx_checksum(skb, fcb);
3074 3065
3075 /* Tell the skb what kind of packet this is */
3076 skb->protocol = eth_type_trans(skb, ndev);
3077
3078 /* There's need to check for NETIF_F_HW_VLAN_CTAG_RX here. 3066 /* There's need to check for NETIF_F_HW_VLAN_CTAG_RX here.
3079 * Even if vlan rx accel is disabled, on some chips 3067 * Even if vlan rx accel is disabled, on some chips
3080 * RXFCB_VLN is pseudo randomly set. 3068 * RXFCB_VLN is pseudo randomly set.
@@ -3145,13 +3133,15 @@ int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit)
3145 continue; 3133 continue;
3146 } 3134 }
3147 3135
3136 gfar_process_frame(ndev, skb);
3137
3148 /* Increment the number of packets */ 3138 /* Increment the number of packets */
3149 total_pkts++; 3139 total_pkts++;
3150 total_bytes += skb->len; 3140 total_bytes += skb->len;
3151 3141
3152 skb_record_rx_queue(skb, rx_queue->qindex); 3142 skb_record_rx_queue(skb, rx_queue->qindex);
3153 3143
3154 gfar_process_frame(ndev, skb); 3144 skb->protocol = eth_type_trans(skb, ndev);
3155 3145
3156 /* Send the packet up the stack */ 3146 /* Send the packet up the stack */
3157 napi_gro_receive(&rx_queue->grp->napi_rx, skb); 3147 napi_gro_receive(&rx_queue->grp->napi_rx, skb);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
index 86944bc3b273..74bd260ca02a 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
@@ -666,7 +666,7 @@ static void hns_gmac_get_strings(u32 stringset, u8 *data)
666 666
667static int hns_gmac_get_sset_count(int stringset) 667static int hns_gmac_get_sset_count(int stringset)
668{ 668{
669 if (stringset == ETH_SS_STATS || stringset == ETH_SS_PRIV_FLAGS) 669 if (stringset == ETH_SS_STATS)
670 return ARRAY_SIZE(g_gmac_stats_string); 670 return ARRAY_SIZE(g_gmac_stats_string);
671 671
672 return 0; 672 return 0;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c
index b62816c1574e..93e71e27401b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c
@@ -422,7 +422,7 @@ void hns_ppe_update_stats(struct hns_ppe_cb *ppe_cb)
422 422
423int hns_ppe_get_sset_count(int stringset) 423int hns_ppe_get_sset_count(int stringset)
424{ 424{
425 if (stringset == ETH_SS_STATS || stringset == ETH_SS_PRIV_FLAGS) 425 if (stringset == ETH_SS_STATS)
426 return ETH_PPE_STATIC_NUM; 426 return ETH_PPE_STATIC_NUM;
427 return 0; 427 return 0;
428} 428}
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
index 6f3570cfb501..e2e28532e4dc 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
@@ -876,7 +876,7 @@ void hns_rcb_get_stats(struct hnae_queue *queue, u64 *data)
876 */ 876 */
877int hns_rcb_get_ring_sset_count(int stringset) 877int hns_rcb_get_ring_sset_count(int stringset)
878{ 878{
879 if (stringset == ETH_SS_STATS || stringset == ETH_SS_PRIV_FLAGS) 879 if (stringset == ETH_SS_STATS)
880 return HNS_RING_STATIC_REG_NUM; 880 return HNS_RING_STATIC_REG_NUM;
881 881
882 return 0; 882 return 0;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 7ea7f8a4aa2a..2e14a3ae1d8b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -993,8 +993,10 @@ int hns_get_sset_count(struct net_device *netdev, int stringset)
993 cnt--; 993 cnt--;
994 994
995 return cnt; 995 return cnt;
996 } else { 996 } else if (stringset == ETH_SS_STATS) {
997 return (HNS_NET_STATS_CNT + ops->get_sset_count(h, stringset)); 997 return (HNS_NET_STATS_CNT + ops->get_sset_count(h, stringset));
998 } else {
999 return -EOPNOTSUPP;
998 } 1000 }
999} 1001}
1000 1002
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 27447260215d..1b3cc8bb0705 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -791,6 +791,18 @@ static int ibmvnic_login(struct net_device *netdev)
791 return 0; 791 return 0;
792} 792}
793 793
794static void release_login_buffer(struct ibmvnic_adapter *adapter)
795{
796 kfree(adapter->login_buf);
797 adapter->login_buf = NULL;
798}
799
800static void release_login_rsp_buffer(struct ibmvnic_adapter *adapter)
801{
802 kfree(adapter->login_rsp_buf);
803 adapter->login_rsp_buf = NULL;
804}
805
794static void release_resources(struct ibmvnic_adapter *adapter) 806static void release_resources(struct ibmvnic_adapter *adapter)
795{ 807{
796 int i; 808 int i;
@@ -813,6 +825,10 @@ static void release_resources(struct ibmvnic_adapter *adapter)
813 } 825 }
814 } 826 }
815 } 827 }
828 kfree(adapter->napi);
829 adapter->napi = NULL;
830
831 release_login_rsp_buffer(adapter);
816} 832}
817 833
818static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state) 834static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state)
@@ -1057,6 +1073,35 @@ static int ibmvnic_open(struct net_device *netdev)
1057 return rc; 1073 return rc;
1058} 1074}
1059 1075
1076static void clean_rx_pools(struct ibmvnic_adapter *adapter)
1077{
1078 struct ibmvnic_rx_pool *rx_pool;
1079 u64 rx_entries;
1080 int rx_scrqs;
1081 int i, j;
1082
1083 if (!adapter->rx_pool)
1084 return;
1085
1086 rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
1087 rx_entries = adapter->req_rx_add_entries_per_subcrq;
1088
1089 /* Free any remaining skbs in the rx buffer pools */
1090 for (i = 0; i < rx_scrqs; i++) {
1091 rx_pool = &adapter->rx_pool[i];
1092 if (!rx_pool)
1093 continue;
1094
1095 netdev_dbg(adapter->netdev, "Cleaning rx_pool[%d]\n", i);
1096 for (j = 0; j < rx_entries; j++) {
1097 if (rx_pool->rx_buff[j].skb) {
1098 dev_kfree_skb_any(rx_pool->rx_buff[j].skb);
1099 rx_pool->rx_buff[j].skb = NULL;
1100 }
1101 }
1102 }
1103}
1104
1060static void clean_tx_pools(struct ibmvnic_adapter *adapter) 1105static void clean_tx_pools(struct ibmvnic_adapter *adapter)
1061{ 1106{
1062 struct ibmvnic_tx_pool *tx_pool; 1107 struct ibmvnic_tx_pool *tx_pool;
@@ -1134,7 +1179,7 @@ static int __ibmvnic_close(struct net_device *netdev)
1134 } 1179 }
1135 } 1180 }
1136 } 1181 }
1137 1182 clean_rx_pools(adapter);
1138 clean_tx_pools(adapter); 1183 clean_tx_pools(adapter);
1139 adapter->state = VNIC_CLOSED; 1184 adapter->state = VNIC_CLOSED;
1140 return rc; 1185 return rc;
@@ -1670,8 +1715,6 @@ static int do_reset(struct ibmvnic_adapter *adapter,
1670 return 0; 1715 return 0;
1671 } 1716 }
1672 1717
1673 netif_carrier_on(netdev);
1674
1675 /* kick napi */ 1718 /* kick napi */
1676 for (i = 0; i < adapter->req_rx_queues; i++) 1719 for (i = 0; i < adapter->req_rx_queues; i++)
1677 napi_schedule(&adapter->napi[i]); 1720 napi_schedule(&adapter->napi[i]);
@@ -1679,6 +1722,8 @@ static int do_reset(struct ibmvnic_adapter *adapter,
1679 if (adapter->reset_reason != VNIC_RESET_FAILOVER) 1722 if (adapter->reset_reason != VNIC_RESET_FAILOVER)
1680 netdev_notify_peers(netdev); 1723 netdev_notify_peers(netdev);
1681 1724
1725 netif_carrier_on(netdev);
1726
1682 return 0; 1727 return 0;
1683} 1728}
1684 1729
@@ -1853,6 +1898,12 @@ restart_poll:
1853 be16_to_cpu(next->rx_comp.rc)); 1898 be16_to_cpu(next->rx_comp.rc));
1854 /* free the entry */ 1899 /* free the entry */
1855 next->rx_comp.first = 0; 1900 next->rx_comp.first = 0;
1901 dev_kfree_skb_any(rx_buff->skb);
1902 remove_buff_from_pool(adapter, rx_buff);
1903 continue;
1904 } else if (!rx_buff->skb) {
1905 /* free the entry */
1906 next->rx_comp.first = 0;
1856 remove_buff_from_pool(adapter, rx_buff); 1907 remove_buff_from_pool(adapter, rx_buff);
1857 continue; 1908 continue;
1858 } 1909 }
@@ -3013,6 +3064,7 @@ static void send_login(struct ibmvnic_adapter *adapter)
3013 struct vnic_login_client_data *vlcd; 3064 struct vnic_login_client_data *vlcd;
3014 int i; 3065 int i;
3015 3066
3067 release_login_rsp_buffer(adapter);
3016 client_data_len = vnic_client_data_len(adapter); 3068 client_data_len = vnic_client_data_len(adapter);
3017 3069
3018 buffer_size = 3070 buffer_size =
@@ -3738,6 +3790,7 @@ static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
3738 ibmvnic_remove(adapter->vdev); 3790 ibmvnic_remove(adapter->vdev);
3739 return -EIO; 3791 return -EIO;
3740 } 3792 }
3793 release_login_buffer(adapter);
3741 complete(&adapter->init_done); 3794 complete(&adapter->init_done);
3742 3795
3743 return 0; 3796 return 0;
diff --git a/drivers/net/ethernet/intel/e1000e/defines.h b/drivers/net/ethernet/intel/e1000e/defines.h
index afb7ebe20b24..824fd44e25f0 100644
--- a/drivers/net/ethernet/intel/e1000e/defines.h
+++ b/drivers/net/ethernet/intel/e1000e/defines.h
@@ -400,6 +400,10 @@
400#define E1000_ICR_RXDMT0 0x00000010 /* Rx desc min. threshold (0) */ 400#define E1000_ICR_RXDMT0 0x00000010 /* Rx desc min. threshold (0) */
401#define E1000_ICR_RXO 0x00000040 /* Receiver Overrun */ 401#define E1000_ICR_RXO 0x00000040 /* Receiver Overrun */
402#define E1000_ICR_RXT0 0x00000080 /* Rx timer intr (ring 0) */ 402#define E1000_ICR_RXT0 0x00000080 /* Rx timer intr (ring 0) */
403#define E1000_ICR_MDAC 0x00000200 /* MDIO Access Complete */
404#define E1000_ICR_SRPD 0x00010000 /* Small Receive Packet Detected */
405#define E1000_ICR_ACK 0x00020000 /* Receive ACK Frame Detected */
406#define E1000_ICR_MNG 0x00040000 /* Manageability Event Detected */
403#define E1000_ICR_ECCER 0x00400000 /* Uncorrectable ECC Error */ 407#define E1000_ICR_ECCER 0x00400000 /* Uncorrectable ECC Error */
404/* If this bit asserted, the driver should claim the interrupt */ 408/* If this bit asserted, the driver should claim the interrupt */
405#define E1000_ICR_INT_ASSERTED 0x80000000 409#define E1000_ICR_INT_ASSERTED 0x80000000
@@ -407,7 +411,7 @@
407#define E1000_ICR_RXQ1 0x00200000 /* Rx Queue 1 Interrupt */ 411#define E1000_ICR_RXQ1 0x00200000 /* Rx Queue 1 Interrupt */
408#define E1000_ICR_TXQ0 0x00400000 /* Tx Queue 0 Interrupt */ 412#define E1000_ICR_TXQ0 0x00400000 /* Tx Queue 0 Interrupt */
409#define E1000_ICR_TXQ1 0x00800000 /* Tx Queue 1 Interrupt */ 413#define E1000_ICR_TXQ1 0x00800000 /* Tx Queue 1 Interrupt */
410#define E1000_ICR_OTHER 0x01000000 /* Other Interrupts */ 414#define E1000_ICR_OTHER 0x01000000 /* Other Interrupt */
411 415
412/* PBA ECC Register */ 416/* PBA ECC Register */
413#define E1000_PBA_ECC_COUNTER_MASK 0xFFF00000 /* ECC counter mask */ 417#define E1000_PBA_ECC_COUNTER_MASK 0xFFF00000 /* ECC counter mask */
@@ -431,12 +435,27 @@
431 E1000_IMS_RXSEQ | \ 435 E1000_IMS_RXSEQ | \
432 E1000_IMS_LSC) 436 E1000_IMS_LSC)
433 437
438/* These are all of the events related to the OTHER interrupt.
439 */
440#define IMS_OTHER_MASK ( \
441 E1000_IMS_LSC | \
442 E1000_IMS_RXO | \
443 E1000_IMS_MDAC | \
444 E1000_IMS_SRPD | \
445 E1000_IMS_ACK | \
446 E1000_IMS_MNG)
447
434/* Interrupt Mask Set */ 448/* Interrupt Mask Set */
435#define E1000_IMS_TXDW E1000_ICR_TXDW /* Transmit desc written back */ 449#define E1000_IMS_TXDW E1000_ICR_TXDW /* Transmit desc written back */
436#define E1000_IMS_LSC E1000_ICR_LSC /* Link Status Change */ 450#define E1000_IMS_LSC E1000_ICR_LSC /* Link Status Change */
437#define E1000_IMS_RXSEQ E1000_ICR_RXSEQ /* Rx sequence error */ 451#define E1000_IMS_RXSEQ E1000_ICR_RXSEQ /* Rx sequence error */
438#define E1000_IMS_RXDMT0 E1000_ICR_RXDMT0 /* Rx desc min. threshold */ 452#define E1000_IMS_RXDMT0 E1000_ICR_RXDMT0 /* Rx desc min. threshold */
453#define E1000_IMS_RXO E1000_ICR_RXO /* Receiver Overrun */
439#define E1000_IMS_RXT0 E1000_ICR_RXT0 /* Rx timer intr */ 454#define E1000_IMS_RXT0 E1000_ICR_RXT0 /* Rx timer intr */
455#define E1000_IMS_MDAC E1000_ICR_MDAC /* MDIO Access Complete */
456#define E1000_IMS_SRPD E1000_ICR_SRPD /* Small Receive Packet */
457#define E1000_IMS_ACK E1000_ICR_ACK /* Receive ACK Frame Detected */
458#define E1000_IMS_MNG E1000_ICR_MNG /* Manageability Event */
440#define E1000_IMS_ECCER E1000_ICR_ECCER /* Uncorrectable ECC Error */ 459#define E1000_IMS_ECCER E1000_ICR_ECCER /* Uncorrectable ECC Error */
441#define E1000_IMS_RXQ0 E1000_ICR_RXQ0 /* Rx Queue 0 Interrupt */ 460#define E1000_IMS_RXQ0 E1000_ICR_RXQ0 /* Rx Queue 0 Interrupt */
442#define E1000_IMS_RXQ1 E1000_ICR_RXQ1 /* Rx Queue 1 Interrupt */ 461#define E1000_IMS_RXQ1 E1000_ICR_RXQ1 /* Rx Queue 1 Interrupt */
diff --git a/drivers/net/ethernet/intel/e1000e/ich8lan.c b/drivers/net/ethernet/intel/e1000e/ich8lan.c
index 31277d3bb7dc..1dddfb7b2de6 100644
--- a/drivers/net/ethernet/intel/e1000e/ich8lan.c
+++ b/drivers/net/ethernet/intel/e1000e/ich8lan.c
@@ -1367,9 +1367,6 @@ out:
1367 * Checks to see of the link status of the hardware has changed. If a 1367 * Checks to see of the link status of the hardware has changed. If a
1368 * change in link status has been detected, then we read the PHY registers 1368 * change in link status has been detected, then we read the PHY registers
1369 * to get the current speed/duplex if link exists. 1369 * to get the current speed/duplex if link exists.
1370 *
1371 * Returns a negative error code (-E1000_ERR_*) or 0 (link down) or 1 (link
1372 * up).
1373 **/ 1370 **/
1374static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw) 1371static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1375{ 1372{
@@ -1385,7 +1382,8 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1385 * Change or Rx Sequence Error interrupt. 1382 * Change or Rx Sequence Error interrupt.
1386 */ 1383 */
1387 if (!mac->get_link_status) 1384 if (!mac->get_link_status)
1388 return 1; 1385 return 0;
1386 mac->get_link_status = false;
1389 1387
1390 /* First we want to see if the MII Status Register reports 1388 /* First we want to see if the MII Status Register reports
1391 * link. If so, then we want to get the current speed/duplex 1389 * link. If so, then we want to get the current speed/duplex
@@ -1393,12 +1391,12 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1393 */ 1391 */
1394 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link); 1392 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1395 if (ret_val) 1393 if (ret_val)
1396 return ret_val; 1394 goto out;
1397 1395
1398 if (hw->mac.type == e1000_pchlan) { 1396 if (hw->mac.type == e1000_pchlan) {
1399 ret_val = e1000_k1_gig_workaround_hv(hw, link); 1397 ret_val = e1000_k1_gig_workaround_hv(hw, link);
1400 if (ret_val) 1398 if (ret_val)
1401 return ret_val; 1399 goto out;
1402 } 1400 }
1403 1401
1404 /* When connected at 10Mbps half-duplex, some parts are excessively 1402 /* When connected at 10Mbps half-duplex, some parts are excessively
@@ -1431,7 +1429,7 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1431 1429
1432 ret_val = hw->phy.ops.acquire(hw); 1430 ret_val = hw->phy.ops.acquire(hw);
1433 if (ret_val) 1431 if (ret_val)
1434 return ret_val; 1432 goto out;
1435 1433
1436 if (hw->mac.type == e1000_pch2lan) 1434 if (hw->mac.type == e1000_pch2lan)
1437 emi_addr = I82579_RX_CONFIG; 1435 emi_addr = I82579_RX_CONFIG;
@@ -1453,7 +1451,7 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1453 hw->phy.ops.release(hw); 1451 hw->phy.ops.release(hw);
1454 1452
1455 if (ret_val) 1453 if (ret_val)
1456 return ret_val; 1454 goto out;
1457 1455
1458 if (hw->mac.type >= e1000_pch_spt) { 1456 if (hw->mac.type >= e1000_pch_spt) {
1459 u16 data; 1457 u16 data;
@@ -1462,14 +1460,14 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1462 if (speed == SPEED_1000) { 1460 if (speed == SPEED_1000) {
1463 ret_val = hw->phy.ops.acquire(hw); 1461 ret_val = hw->phy.ops.acquire(hw);
1464 if (ret_val) 1462 if (ret_val)
1465 return ret_val; 1463 goto out;
1466 1464
1467 ret_val = e1e_rphy_locked(hw, 1465 ret_val = e1e_rphy_locked(hw,
1468 PHY_REG(776, 20), 1466 PHY_REG(776, 20),
1469 &data); 1467 &data);
1470 if (ret_val) { 1468 if (ret_val) {
1471 hw->phy.ops.release(hw); 1469 hw->phy.ops.release(hw);
1472 return ret_val; 1470 goto out;
1473 } 1471 }
1474 1472
1475 ptr_gap = (data & (0x3FF << 2)) >> 2; 1473 ptr_gap = (data & (0x3FF << 2)) >> 2;
@@ -1483,18 +1481,18 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1483 } 1481 }
1484 hw->phy.ops.release(hw); 1482 hw->phy.ops.release(hw);
1485 if (ret_val) 1483 if (ret_val)
1486 return ret_val; 1484 goto out;
1487 } else { 1485 } else {
1488 ret_val = hw->phy.ops.acquire(hw); 1486 ret_val = hw->phy.ops.acquire(hw);
1489 if (ret_val) 1487 if (ret_val)
1490 return ret_val; 1488 goto out;
1491 1489
1492 ret_val = e1e_wphy_locked(hw, 1490 ret_val = e1e_wphy_locked(hw,
1493 PHY_REG(776, 20), 1491 PHY_REG(776, 20),
1494 0xC023); 1492 0xC023);
1495 hw->phy.ops.release(hw); 1493 hw->phy.ops.release(hw);
1496 if (ret_val) 1494 if (ret_val)
1497 return ret_val; 1495 goto out;
1498 1496
1499 } 1497 }
1500 } 1498 }
@@ -1521,7 +1519,7 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1521 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) { 1519 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) {
1522 ret_val = e1000_k1_workaround_lpt_lp(hw, link); 1520 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
1523 if (ret_val) 1521 if (ret_val)
1524 return ret_val; 1522 goto out;
1525 } 1523 }
1526 if (hw->mac.type >= e1000_pch_lpt) { 1524 if (hw->mac.type >= e1000_pch_lpt) {
1527 /* Set platform power management values for 1525 /* Set platform power management values for
@@ -1529,7 +1527,7 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1529 */ 1527 */
1530 ret_val = e1000_platform_pm_pch_lpt(hw, link); 1528 ret_val = e1000_platform_pm_pch_lpt(hw, link);
1531 if (ret_val) 1529 if (ret_val)
1532 return ret_val; 1530 goto out;
1533 } 1531 }
1534 1532
1535 /* Clear link partner's EEE ability */ 1533 /* Clear link partner's EEE ability */
@@ -1552,9 +1550,7 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1552 } 1550 }
1553 1551
1554 if (!link) 1552 if (!link)
1555 return 0; /* No link detected */ 1553 goto out;
1556
1557 mac->get_link_status = false;
1558 1554
1559 switch (hw->mac.type) { 1555 switch (hw->mac.type) {
1560 case e1000_pch2lan: 1556 case e1000_pch2lan:
@@ -1616,12 +1612,14 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1616 * different link partner. 1612 * different link partner.
1617 */ 1613 */
1618 ret_val = e1000e_config_fc_after_link_up(hw); 1614 ret_val = e1000e_config_fc_after_link_up(hw);
1619 if (ret_val) { 1615 if (ret_val)
1620 e_dbg("Error configuring flow control\n"); 1616 e_dbg("Error configuring flow control\n");
1621 return ret_val;
1622 }
1623 1617
1624 return 1; 1618 return ret_val;
1619
1620out:
1621 mac->get_link_status = true;
1622 return ret_val;
1625} 1623}
1626 1624
1627static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter) 1625static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
diff --git a/drivers/net/ethernet/intel/e1000e/mac.c b/drivers/net/ethernet/intel/e1000e/mac.c
index f457c5703d0c..5bdc3a2d4fd7 100644
--- a/drivers/net/ethernet/intel/e1000e/mac.c
+++ b/drivers/net/ethernet/intel/e1000e/mac.c
@@ -410,9 +410,6 @@ void e1000e_clear_hw_cntrs_base(struct e1000_hw *hw)
410 * Checks to see of the link status of the hardware has changed. If a 410 * Checks to see of the link status of the hardware has changed. If a
411 * change in link status has been detected, then we read the PHY registers 411 * change in link status has been detected, then we read the PHY registers
412 * to get the current speed/duplex if link exists. 412 * to get the current speed/duplex if link exists.
413 *
414 * Returns a negative error code (-E1000_ERR_*) or 0 (link down) or 1 (link
415 * up).
416 **/ 413 **/
417s32 e1000e_check_for_copper_link(struct e1000_hw *hw) 414s32 e1000e_check_for_copper_link(struct e1000_hw *hw)
418{ 415{
@@ -426,20 +423,16 @@ s32 e1000e_check_for_copper_link(struct e1000_hw *hw)
426 * Change or Rx Sequence Error interrupt. 423 * Change or Rx Sequence Error interrupt.
427 */ 424 */
428 if (!mac->get_link_status) 425 if (!mac->get_link_status)
429 return 1; 426 return 0;
427 mac->get_link_status = false;
430 428
431 /* First we want to see if the MII Status Register reports 429 /* First we want to see if the MII Status Register reports
432 * link. If so, then we want to get the current speed/duplex 430 * link. If so, then we want to get the current speed/duplex
433 * of the PHY. 431 * of the PHY.
434 */ 432 */
435 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link); 433 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
436 if (ret_val) 434 if (ret_val || !link)
437 return ret_val; 435 goto out;
438
439 if (!link)
440 return 0; /* No link detected */
441
442 mac->get_link_status = false;
443 436
444 /* Check if there was DownShift, must be checked 437 /* Check if there was DownShift, must be checked
445 * immediately after link-up 438 * immediately after link-up
@@ -464,12 +457,14 @@ s32 e1000e_check_for_copper_link(struct e1000_hw *hw)
464 * different link partner. 457 * different link partner.
465 */ 458 */
466 ret_val = e1000e_config_fc_after_link_up(hw); 459 ret_val = e1000e_config_fc_after_link_up(hw);
467 if (ret_val) { 460 if (ret_val)
468 e_dbg("Error configuring flow control\n"); 461 e_dbg("Error configuring flow control\n");
469 return ret_val;
470 }
471 462
472 return 1; 463 return ret_val;
464
465out:
466 mac->get_link_status = true;
467 return ret_val;
473} 468}
474 469
475/** 470/**
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
index 1298b69f990b..dc853b0863af 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -1914,30 +1914,20 @@ static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
1914 struct net_device *netdev = data; 1914 struct net_device *netdev = data;
1915 struct e1000_adapter *adapter = netdev_priv(netdev); 1915 struct e1000_adapter *adapter = netdev_priv(netdev);
1916 struct e1000_hw *hw = &adapter->hw; 1916 struct e1000_hw *hw = &adapter->hw;
1917 u32 icr; 1917 u32 icr = er32(ICR);
1918 bool enable = true; 1918
1919 1919 if (icr & adapter->eiac_mask)
1920 icr = er32(ICR); 1920 ew32(ICS, (icr & adapter->eiac_mask));
1921 if (icr & E1000_ICR_RXO) { 1921
1922 ew32(ICR, E1000_ICR_RXO);
1923 enable = false;
1924 /* napi poll will re-enable Other, make sure it runs */
1925 if (napi_schedule_prep(&adapter->napi)) {
1926 adapter->total_rx_bytes = 0;
1927 adapter->total_rx_packets = 0;
1928 __napi_schedule(&adapter->napi);
1929 }
1930 }
1931 if (icr & E1000_ICR_LSC) { 1922 if (icr & E1000_ICR_LSC) {
1932 ew32(ICR, E1000_ICR_LSC);
1933 hw->mac.get_link_status = true; 1923 hw->mac.get_link_status = true;
1934 /* guard against interrupt when we're going down */ 1924 /* guard against interrupt when we're going down */
1935 if (!test_bit(__E1000_DOWN, &adapter->state)) 1925 if (!test_bit(__E1000_DOWN, &adapter->state))
1936 mod_timer(&adapter->watchdog_timer, jiffies + 1); 1926 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1937 } 1927 }
1938 1928
1939 if (enable && !test_bit(__E1000_DOWN, &adapter->state)) 1929 if (!test_bit(__E1000_DOWN, &adapter->state))
1940 ew32(IMS, E1000_IMS_OTHER); 1930 ew32(IMS, E1000_IMS_OTHER | IMS_OTHER_MASK);
1941 1931
1942 return IRQ_HANDLED; 1932 return IRQ_HANDLED;
1943} 1933}
@@ -2040,7 +2030,6 @@ static void e1000_configure_msix(struct e1000_adapter *adapter)
2040 hw->hw_addr + E1000_EITR_82574(vector)); 2030 hw->hw_addr + E1000_EITR_82574(vector));
2041 else 2031 else
2042 writel(1, hw->hw_addr + E1000_EITR_82574(vector)); 2032 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2043 adapter->eiac_mask |= E1000_IMS_OTHER;
2044 2033
2045 /* Cause Tx interrupts on every write back */ 2034 /* Cause Tx interrupts on every write back */
2046 ivar |= BIT(31); 2035 ivar |= BIT(31);
@@ -2265,7 +2254,8 @@ static void e1000_irq_enable(struct e1000_adapter *adapter)
2265 2254
2266 if (adapter->msix_entries) { 2255 if (adapter->msix_entries) {
2267 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); 2256 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2268 ew32(IMS, adapter->eiac_mask | E1000_IMS_LSC); 2257 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER |
2258 IMS_OTHER_MASK);
2269 } else if (hw->mac.type >= e1000_pch_lpt) { 2259 } else if (hw->mac.type >= e1000_pch_lpt) {
2270 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER); 2260 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
2271 } else { 2261 } else {
@@ -2333,8 +2323,8 @@ static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2333{ 2323{
2334 struct pci_dev *pdev = adapter->pdev; 2324 struct pci_dev *pdev = adapter->pdev;
2335 2325
2336 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, 2326 ring->desc = dma_zalloc_coherent(&pdev->dev, ring->size, &ring->dma,
2337 GFP_KERNEL); 2327 GFP_KERNEL);
2338 if (!ring->desc) 2328 if (!ring->desc)
2339 return -ENOMEM; 2329 return -ENOMEM;
2340 2330
@@ -2707,8 +2697,7 @@ static int e1000e_poll(struct napi_struct *napi, int weight)
2707 napi_complete_done(napi, work_done); 2697 napi_complete_done(napi, work_done);
2708 if (!test_bit(__E1000_DOWN, &adapter->state)) { 2698 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2709 if (adapter->msix_entries) 2699 if (adapter->msix_entries)
2710 ew32(IMS, adapter->rx_ring->ims_val | 2700 ew32(IMS, adapter->rx_ring->ims_val);
2711 E1000_IMS_OTHER);
2712 else 2701 else
2713 e1000_irq_enable(adapter); 2702 e1000_irq_enable(adapter);
2714 } 2703 }
@@ -5101,7 +5090,7 @@ static bool e1000e_has_link(struct e1000_adapter *adapter)
5101 case e1000_media_type_copper: 5090 case e1000_media_type_copper:
5102 if (hw->mac.get_link_status) { 5091 if (hw->mac.get_link_status) {
5103 ret_val = hw->mac.ops.check_for_link(hw); 5092 ret_val = hw->mac.ops.check_for_link(hw);
5104 link_active = ret_val > 0; 5093 link_active = !hw->mac.get_link_status;
5105 } else { 5094 } else {
5106 link_active = true; 5095 link_active = true;
5107 } 5096 }
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 0da5aa2c8aba..9fc063af233c 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -1888,6 +1888,14 @@ static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1888 ixgbe_rx_pg_size(rx_ring), 1888 ixgbe_rx_pg_size(rx_ring),
1889 DMA_FROM_DEVICE, 1889 DMA_FROM_DEVICE,
1890 IXGBE_RX_DMA_ATTR); 1890 IXGBE_RX_DMA_ATTR);
1891 } else if (ring_uses_build_skb(rx_ring)) {
1892 unsigned long offset = (unsigned long)(skb->data) & ~PAGE_MASK;
1893
1894 dma_sync_single_range_for_cpu(rx_ring->dev,
1895 IXGBE_CB(skb)->dma,
1896 offset,
1897 skb_headlen(skb),
1898 DMA_FROM_DEVICE);
1891 } else { 1899 } else {
1892 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; 1900 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1893 1901
diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index a1d7b88cf083..5a1668cdb461 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -7137,6 +7137,7 @@ static void mvpp2_set_rx_mode(struct net_device *dev)
7137 int id = port->id; 7137 int id = port->id;
7138 bool allmulti = dev->flags & IFF_ALLMULTI; 7138 bool allmulti = dev->flags & IFF_ALLMULTI;
7139 7139
7140retry:
7140 mvpp2_prs_mac_promisc_set(priv, id, dev->flags & IFF_PROMISC); 7141 mvpp2_prs_mac_promisc_set(priv, id, dev->flags & IFF_PROMISC);
7141 mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_ALL, allmulti); 7142 mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_ALL, allmulti);
7142 mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_IP6, allmulti); 7143 mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_IP6, allmulti);
@@ -7144,9 +7145,13 @@ static void mvpp2_set_rx_mode(struct net_device *dev)
7144 /* Remove all port->id's mcast enries */ 7145 /* Remove all port->id's mcast enries */
7145 mvpp2_prs_mcast_del_all(priv, id); 7146 mvpp2_prs_mcast_del_all(priv, id);
7146 7147
7147 if (allmulti && !netdev_mc_empty(dev)) { 7148 if (!allmulti) {
7148 netdev_for_each_mc_addr(ha, dev) 7149 netdev_for_each_mc_addr(ha, dev) {
7149 mvpp2_prs_mac_da_accept(priv, id, ha->addr, true); 7150 if (mvpp2_prs_mac_da_accept(priv, id, ha->addr, true)) {
7151 allmulti = true;
7152 goto retry;
7153 }
7154 }
7150 } 7155 }
7151} 7156}
7152 7157
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.c b/drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.c
index 0be4575b58a2..fd509160c8f6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.c
@@ -96,10 +96,10 @@ static void print_lyr_2_4_hdrs(struct trace_seq *p,
96 "%pI4"); 96 "%pI4");
97 } else if (ethertype.v == ETH_P_IPV6) { 97 } else if (ethertype.v == ETH_P_IPV6) {
98 static const struct in6_addr full_ones = { 98 static const struct in6_addr full_ones = {
99 .in6_u.u6_addr32 = {htonl(0xffffffff), 99 .in6_u.u6_addr32 = {__constant_htonl(0xffffffff),
100 htonl(0xffffffff), 100 __constant_htonl(0xffffffff),
101 htonl(0xffffffff), 101 __constant_htonl(0xffffffff),
102 htonl(0xffffffff)}, 102 __constant_htonl(0xffffffff)},
103 }; 103 };
104 DECLARE_MASK_VAL(struct in6_addr, src_ipv6); 104 DECLARE_MASK_VAL(struct in6_addr, src_ipv6);
105 DECLARE_MASK_VAL(struct in6_addr, dst_ipv6); 105 DECLARE_MASK_VAL(struct in6_addr, dst_ipv6);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 47bab842c5ee..da94c8cba5ee 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -1768,13 +1768,16 @@ static void mlx5e_build_rq_param(struct mlx5e_priv *priv,
1768 param->wq.linear = 1; 1768 param->wq.linear = 1;
1769} 1769}
1770 1770
1771static void mlx5e_build_drop_rq_param(struct mlx5e_rq_param *param) 1771static void mlx5e_build_drop_rq_param(struct mlx5_core_dev *mdev,
1772 struct mlx5e_rq_param *param)
1772{ 1773{
1773 void *rqc = param->rqc; 1774 void *rqc = param->rqc;
1774 void *wq = MLX5_ADDR_OF(rqc, rqc, wq); 1775 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1775 1776
1776 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST); 1777 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1777 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe))); 1778 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1779
1780 param->wq.buf_numa_node = dev_to_node(&mdev->pdev->dev);
1778} 1781}
1779 1782
1780static void mlx5e_build_sq_param_common(struct mlx5e_priv *priv, 1783static void mlx5e_build_sq_param_common(struct mlx5e_priv *priv,
@@ -2634,6 +2637,9 @@ static int mlx5e_alloc_drop_cq(struct mlx5_core_dev *mdev,
2634 struct mlx5e_cq *cq, 2637 struct mlx5e_cq *cq,
2635 struct mlx5e_cq_param *param) 2638 struct mlx5e_cq_param *param)
2636{ 2639{
2640 param->wq.buf_numa_node = dev_to_node(&mdev->pdev->dev);
2641 param->wq.db_numa_node = dev_to_node(&mdev->pdev->dev);
2642
2637 return mlx5e_alloc_cq_common(mdev, param, cq); 2643 return mlx5e_alloc_cq_common(mdev, param, cq);
2638} 2644}
2639 2645
@@ -2645,7 +2651,7 @@ static int mlx5e_open_drop_rq(struct mlx5_core_dev *mdev,
2645 struct mlx5e_cq *cq = &drop_rq->cq; 2651 struct mlx5e_cq *cq = &drop_rq->cq;
2646 int err; 2652 int err;
2647 2653
2648 mlx5e_build_drop_rq_param(&rq_param); 2654 mlx5e_build_drop_rq_param(mdev, &rq_param);
2649 2655
2650 err = mlx5e_alloc_drop_cq(mdev, cq, &cq_param); 2656 err = mlx5e_alloc_drop_cq(mdev, cq, &cq_param);
2651 if (err) 2657 if (err)
@@ -2994,8 +3000,8 @@ static int mlx5e_setup_tc_block(struct net_device *dev,
2994} 3000}
2995#endif 3001#endif
2996 3002
2997int mlx5e_setup_tc(struct net_device *dev, enum tc_setup_type type, 3003static int mlx5e_setup_tc(struct net_device *dev, enum tc_setup_type type,
2998 void *type_data) 3004 void *type_data)
2999{ 3005{
3000 switch (type) { 3006 switch (type) {
3001#ifdef CONFIG_MLX5_ESWITCH 3007#ifdef CONFIG_MLX5_ESWITCH
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index 0d4bb0688faa..e5c3ab46a24a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -36,6 +36,7 @@
36#include <linux/tcp.h> 36#include <linux/tcp.h>
37#include <linux/bpf_trace.h> 37#include <linux/bpf_trace.h>
38#include <net/busy_poll.h> 38#include <net/busy_poll.h>
39#include <net/ip6_checksum.h>
39#include "en.h" 40#include "en.h"
40#include "en_tc.h" 41#include "en_tc.h"
41#include "eswitch.h" 42#include "eswitch.h"
@@ -546,20 +547,33 @@ bool mlx5e_post_rx_mpwqes(struct mlx5e_rq *rq)
546 return true; 547 return true;
547} 548}
548 549
550static void mlx5e_lro_update_tcp_hdr(struct mlx5_cqe64 *cqe, struct tcphdr *tcp)
551{
552 u8 l4_hdr_type = get_cqe_l4_hdr_type(cqe);
553 u8 tcp_ack = (l4_hdr_type == CQE_L4_HDR_TYPE_TCP_ACK_NO_DATA) ||
554 (l4_hdr_type == CQE_L4_HDR_TYPE_TCP_ACK_AND_DATA);
555
556 tcp->check = 0;
557 tcp->psh = get_cqe_lro_tcppsh(cqe);
558
559 if (tcp_ack) {
560 tcp->ack = 1;
561 tcp->ack_seq = cqe->lro_ack_seq_num;
562 tcp->window = cqe->lro_tcp_win;
563 }
564}
565
549static void mlx5e_lro_update_hdr(struct sk_buff *skb, struct mlx5_cqe64 *cqe, 566static void mlx5e_lro_update_hdr(struct sk_buff *skb, struct mlx5_cqe64 *cqe,
550 u32 cqe_bcnt) 567 u32 cqe_bcnt)
551{ 568{
552 struct ethhdr *eth = (struct ethhdr *)(skb->data); 569 struct ethhdr *eth = (struct ethhdr *)(skb->data);
553 struct tcphdr *tcp; 570 struct tcphdr *tcp;
554 int network_depth = 0; 571 int network_depth = 0;
572 __wsum check;
555 __be16 proto; 573 __be16 proto;
556 u16 tot_len; 574 u16 tot_len;
557 void *ip_p; 575 void *ip_p;
558 576
559 u8 l4_hdr_type = get_cqe_l4_hdr_type(cqe);
560 u8 tcp_ack = (l4_hdr_type == CQE_L4_HDR_TYPE_TCP_ACK_NO_DATA) ||
561 (l4_hdr_type == CQE_L4_HDR_TYPE_TCP_ACK_AND_DATA);
562
563 proto = __vlan_get_protocol(skb, eth->h_proto, &network_depth); 577 proto = __vlan_get_protocol(skb, eth->h_proto, &network_depth);
564 578
565 tot_len = cqe_bcnt - network_depth; 579 tot_len = cqe_bcnt - network_depth;
@@ -576,23 +590,30 @@ static void mlx5e_lro_update_hdr(struct sk_buff *skb, struct mlx5_cqe64 *cqe,
576 ipv4->check = 0; 590 ipv4->check = 0;
577 ipv4->check = ip_fast_csum((unsigned char *)ipv4, 591 ipv4->check = ip_fast_csum((unsigned char *)ipv4,
578 ipv4->ihl); 592 ipv4->ihl);
593
594 mlx5e_lro_update_tcp_hdr(cqe, tcp);
595 check = csum_partial(tcp, tcp->doff * 4,
596 csum_unfold((__force __sum16)cqe->check_sum));
597 /* Almost done, don't forget the pseudo header */
598 tcp->check = csum_tcpudp_magic(ipv4->saddr, ipv4->daddr,
599 tot_len - sizeof(struct iphdr),
600 IPPROTO_TCP, check);
579 } else { 601 } else {
602 u16 payload_len = tot_len - sizeof(struct ipv6hdr);
580 struct ipv6hdr *ipv6 = ip_p; 603 struct ipv6hdr *ipv6 = ip_p;
581 604
582 tcp = ip_p + sizeof(struct ipv6hdr); 605 tcp = ip_p + sizeof(struct ipv6hdr);
583 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; 606 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
584 607
585 ipv6->hop_limit = cqe->lro_min_ttl; 608 ipv6->hop_limit = cqe->lro_min_ttl;
586 ipv6->payload_len = cpu_to_be16(tot_len - 609 ipv6->payload_len = cpu_to_be16(payload_len);
587 sizeof(struct ipv6hdr)); 610
588 } 611 mlx5e_lro_update_tcp_hdr(cqe, tcp);
589 612 check = csum_partial(tcp, tcp->doff * 4,
590 tcp->psh = get_cqe_lro_tcppsh(cqe); 613 csum_unfold((__force __sum16)cqe->check_sum));
591 614 /* Almost done, don't forget the pseudo header */
592 if (tcp_ack) { 615 tcp->check = csum_ipv6_magic(&ipv6->saddr, &ipv6->daddr, payload_len,
593 tcp->ack = 1; 616 IPPROTO_TCP, check);
594 tcp->ack_seq = cqe->lro_ack_seq_num;
595 tcp->window = cqe->lro_tcp_win;
596 } 617 }
597} 618}
598 619
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c b/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c
index 5a4608281f38..707976482c09 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c
@@ -216,7 +216,8 @@ mlx5e_test_loopback_validate(struct sk_buff *skb,
216 if (iph->protocol != IPPROTO_UDP) 216 if (iph->protocol != IPPROTO_UDP)
217 goto out; 217 goto out;
218 218
219 udph = udp_hdr(skb); 219 /* Don't assume skb_transport_header() was set */
220 udph = (struct udphdr *)((u8 *)iph + 4 * iph->ihl);
220 if (udph->dest != htons(9)) 221 if (udph->dest != htons(9))
221 goto out; 222 goto out;
222 223
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index fd98b0dc610f..fa86a1466718 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -2529,7 +2529,8 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
2529 if (tcf_vlan_action(a) == TCA_VLAN_ACT_POP) { 2529 if (tcf_vlan_action(a) == TCA_VLAN_ACT_POP) {
2530 attr->action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_POP; 2530 attr->action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_POP;
2531 } else if (tcf_vlan_action(a) == TCA_VLAN_ACT_PUSH) { 2531 } else if (tcf_vlan_action(a) == TCA_VLAN_ACT_PUSH) {
2532 if (tcf_vlan_push_proto(a) != htons(ETH_P_8021Q)) 2532 if (tcf_vlan_push_proto(a) != htons(ETH_P_8021Q) ||
2533 tcf_vlan_push_prio(a))
2533 return -EOPNOTSUPP; 2534 return -EOPNOTSUPP;
2534 2535
2535 attr->action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH; 2536 attr->action |= MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
index 569b42a01026..11b4f1089d1c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
@@ -176,7 +176,7 @@ static inline u16 mlx5e_calc_min_inline(enum mlx5_inline_modes mode,
176 default: 176 default:
177 hlen = mlx5e_skb_l2_header_offset(skb); 177 hlen = mlx5e_skb_l2_header_offset(skb);
178 } 178 }
179 return min_t(u16, hlen, skb->len); 179 return min_t(u16, hlen, skb_headlen(skb));
180} 180}
181 181
182static inline void mlx5e_tx_skb_pull_inline(unsigned char **skb_data, 182static inline void mlx5e_tx_skb_pull_inline(unsigned char **skb_data,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 5ecf2cddc16d..c2b1d7d351fc 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -1529,6 +1529,10 @@ static void esw_enable_vport(struct mlx5_eswitch *esw, int vport_num,
1529 1529
1530 esw_debug(esw->dev, "Enabling VPORT(%d)\n", vport_num); 1530 esw_debug(esw->dev, "Enabling VPORT(%d)\n", vport_num);
1531 1531
1532 /* Create steering drop counters for ingress and egress ACLs */
1533 if (vport_num && esw->mode == SRIOV_LEGACY)
1534 esw_vport_create_drop_counters(vport);
1535
1532 /* Restore old vport configuration */ 1536 /* Restore old vport configuration */
1533 esw_apply_vport_conf(esw, vport); 1537 esw_apply_vport_conf(esw, vport);
1534 1538
@@ -1545,10 +1549,6 @@ static void esw_enable_vport(struct mlx5_eswitch *esw, int vport_num,
1545 if (!vport_num) 1549 if (!vport_num)
1546 vport->info.trusted = true; 1550 vport->info.trusted = true;
1547 1551
1548 /* create steering drop counters for ingress and egress ACLs */
1549 if (vport_num && esw->mode == SRIOV_LEGACY)
1550 esw_vport_create_drop_counters(vport);
1551
1552 esw_vport_change_handle_locked(vport); 1552 esw_vport_change_handle_locked(vport);
1553 1553
1554 esw->enabled_vports++; 1554 esw->enabled_vports++;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
index c025c98700e4..31fc2cfac3b3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
@@ -1429,7 +1429,8 @@ static bool check_conflicting_actions(u32 action1, u32 action2)
1429 1429
1430 if (xored_actions & (MLX5_FLOW_CONTEXT_ACTION_DROP | 1430 if (xored_actions & (MLX5_FLOW_CONTEXT_ACTION_DROP |
1431 MLX5_FLOW_CONTEXT_ACTION_ENCAP | 1431 MLX5_FLOW_CONTEXT_ACTION_ENCAP |
1432 MLX5_FLOW_CONTEXT_ACTION_DECAP)) 1432 MLX5_FLOW_CONTEXT_ACTION_DECAP |
1433 MLX5_FLOW_CONTEXT_ACTION_MOD_HDR))
1433 return true; 1434 return true;
1434 1435
1435 return false; 1436 return false;
@@ -1758,8 +1759,11 @@ search_again_locked:
1758 1759
1759 /* Collect all fgs which has a matching match_criteria */ 1760 /* Collect all fgs which has a matching match_criteria */
1760 err = build_match_list(&match_head, ft, spec); 1761 err = build_match_list(&match_head, ft, spec);
1761 if (err) 1762 if (err) {
1763 if (take_write)
1764 up_write_ref_node(&ft->node);
1762 return ERR_PTR(err); 1765 return ERR_PTR(err);
1766 }
1763 1767
1764 if (!take_write) 1768 if (!take_write)
1765 up_read_ref_node(&ft->node); 1769 up_read_ref_node(&ft->node);
@@ -1768,8 +1772,11 @@ search_again_locked:
1768 dest_num, version); 1772 dest_num, version);
1769 free_match_list(&match_head); 1773 free_match_list(&match_head);
1770 if (!IS_ERR(rule) || 1774 if (!IS_ERR(rule) ||
1771 (PTR_ERR(rule) != -ENOENT && PTR_ERR(rule) != -EAGAIN)) 1775 (PTR_ERR(rule) != -ENOENT && PTR_ERR(rule) != -EAGAIN)) {
1776 if (take_write)
1777 up_write_ref_node(&ft->node);
1772 return rule; 1778 return rule;
1779 }
1773 1780
1774 if (!take_write) { 1781 if (!take_write) {
1775 nested_down_write_ref_node(&ft->node, FS_LOCK_GRANDPARENT); 1782 nested_down_write_ref_node(&ft->node, FS_LOCK_GRANDPARENT);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c b/drivers/net/ethernet/mellanox/mlx5/core/health.c
index 21d29f7936f6..d39b0b7011b2 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
@@ -124,7 +124,7 @@ void mlx5_enter_error_state(struct mlx5_core_dev *dev, bool force)
124 trigger_cmd_completions(dev); 124 trigger_cmd_completions(dev);
125 } 125 }
126 126
127 mlx5_core_event(dev, MLX5_DEV_EVENT_SYS_ERROR, 0); 127 mlx5_core_event(dev, MLX5_DEV_EVENT_SYS_ERROR, 1);
128 mlx5_core_err(dev, "end\n"); 128 mlx5_core_err(dev, "end\n");
129 129
130unlock: 130unlock:
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
index e159243e0fcf..857035583ccd 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
@@ -34,6 +34,7 @@
34#include <linux/highmem.h> 34#include <linux/highmem.h>
35#include <rdma/mlx5-abi.h> 35#include <rdma/mlx5-abi.h>
36#include "en.h" 36#include "en.h"
37#include "clock.h"
37 38
38enum { 39enum {
39 MLX5_CYCLES_SHIFT = 23 40 MLX5_CYCLES_SHIFT = 23
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index 2ef641c91c26..ae391e4b7070 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -551,7 +551,7 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
551 MLX5_SET(cmd_hca_cap, 551 MLX5_SET(cmd_hca_cap,
552 set_hca_cap, 552 set_hca_cap,
553 cache_line_128byte, 553 cache_line_128byte,
554 cache_line_size() == 128 ? 1 : 0); 554 cache_line_size() >= 128 ? 1 : 0);
555 555
556 if (MLX5_CAP_GEN_MAX(dev, dct)) 556 if (MLX5_CAP_GEN_MAX(dev, dct))
557 MLX5_SET(cmd_hca_cap, set_hca_cap, dct, 1); 557 MLX5_SET(cmd_hca_cap, set_hca_cap, dct, 1);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
index b698fb481b2e..996dc099cd58 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
@@ -443,6 +443,17 @@ int mlxsw_afa_block_jump(struct mlxsw_afa_block *block, u16 group_id)
443} 443}
444EXPORT_SYMBOL(mlxsw_afa_block_jump); 444EXPORT_SYMBOL(mlxsw_afa_block_jump);
445 445
446int mlxsw_afa_block_terminate(struct mlxsw_afa_block *block)
447{
448 if (block->finished)
449 return -EINVAL;
450 mlxsw_afa_set_goto_set(block->cur_set,
451 MLXSW_AFA_SET_GOTO_BINDING_CMD_TERM, 0);
452 block->finished = true;
453 return 0;
454}
455EXPORT_SYMBOL(mlxsw_afa_block_terminate);
456
446static struct mlxsw_afa_fwd_entry * 457static struct mlxsw_afa_fwd_entry *
447mlxsw_afa_fwd_entry_create(struct mlxsw_afa *mlxsw_afa, u8 local_port) 458mlxsw_afa_fwd_entry_create(struct mlxsw_afa *mlxsw_afa, u8 local_port)
448{ 459{
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h
index 43132293475c..b91f2b0829b0 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h
@@ -65,6 +65,7 @@ char *mlxsw_afa_block_first_set(struct mlxsw_afa_block *block);
65u32 mlxsw_afa_block_first_set_kvdl_index(struct mlxsw_afa_block *block); 65u32 mlxsw_afa_block_first_set_kvdl_index(struct mlxsw_afa_block *block);
66int mlxsw_afa_block_continue(struct mlxsw_afa_block *block); 66int mlxsw_afa_block_continue(struct mlxsw_afa_block *block);
67int mlxsw_afa_block_jump(struct mlxsw_afa_block *block, u16 group_id); 67int mlxsw_afa_block_jump(struct mlxsw_afa_block *block, u16 group_id);
68int mlxsw_afa_block_terminate(struct mlxsw_afa_block *block);
68int mlxsw_afa_block_append_drop(struct mlxsw_afa_block *block); 69int mlxsw_afa_block_append_drop(struct mlxsw_afa_block *block);
69int mlxsw_afa_block_append_trap(struct mlxsw_afa_block *block, u16 trap_id); 70int mlxsw_afa_block_append_trap(struct mlxsw_afa_block *block, u16 trap_id);
70int mlxsw_afa_block_append_trap_and_forward(struct mlxsw_afa_block *block, 71int mlxsw_afa_block_append_trap_and_forward(struct mlxsw_afa_block *block,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h
index f6963b0b4a55..122506daa586 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h
@@ -107,20 +107,20 @@ static const struct mlxsw_afk_element_info mlxsw_afk_element_infos[] = {
107 MLXSW_AFK_ELEMENT_INFO_U32(VID, 0x10, 8, 12), 107 MLXSW_AFK_ELEMENT_INFO_U32(VID, 0x10, 8, 12),
108 MLXSW_AFK_ELEMENT_INFO_U32(PCP, 0x10, 20, 3), 108 MLXSW_AFK_ELEMENT_INFO_U32(PCP, 0x10, 20, 3),
109 MLXSW_AFK_ELEMENT_INFO_U32(TCP_FLAGS, 0x10, 23, 9), 109 MLXSW_AFK_ELEMENT_INFO_U32(TCP_FLAGS, 0x10, 23, 9),
110 MLXSW_AFK_ELEMENT_INFO_U32(IP_TTL_, 0x14, 0, 8),
111 MLXSW_AFK_ELEMENT_INFO_U32(IP_ECN, 0x14, 9, 2),
112 MLXSW_AFK_ELEMENT_INFO_U32(IP_DSCP, 0x14, 11, 6),
113 MLXSW_AFK_ELEMENT_INFO_U32(SRC_IP4, 0x18, 0, 32),
114 MLXSW_AFK_ELEMENT_INFO_U32(DST_IP4, 0x1C, 0, 32),
115 MLXSW_AFK_ELEMENT_INFO_BUF(SRC_IP6_HI, 0x18, 8),
116 MLXSW_AFK_ELEMENT_INFO_BUF(SRC_IP6_LO, 0x20, 8),
117 MLXSW_AFK_ELEMENT_INFO_BUF(DST_IP6_HI, 0x28, 8),
118 MLXSW_AFK_ELEMENT_INFO_BUF(DST_IP6_LO, 0x30, 8),
119 MLXSW_AFK_ELEMENT_INFO_U32(DST_L4_PORT, 0x14, 0, 16), 110 MLXSW_AFK_ELEMENT_INFO_U32(DST_L4_PORT, 0x14, 0, 16),
120 MLXSW_AFK_ELEMENT_INFO_U32(SRC_L4_PORT, 0x14, 16, 16), 111 MLXSW_AFK_ELEMENT_INFO_U32(SRC_L4_PORT, 0x14, 16, 16),
112 MLXSW_AFK_ELEMENT_INFO_U32(IP_TTL_, 0x18, 0, 8),
113 MLXSW_AFK_ELEMENT_INFO_U32(IP_ECN, 0x18, 9, 2),
114 MLXSW_AFK_ELEMENT_INFO_U32(IP_DSCP, 0x18, 11, 6),
115 MLXSW_AFK_ELEMENT_INFO_U32(SRC_IP4, 0x20, 0, 32),
116 MLXSW_AFK_ELEMENT_INFO_U32(DST_IP4, 0x24, 0, 32),
117 MLXSW_AFK_ELEMENT_INFO_BUF(SRC_IP6_HI, 0x20, 8),
118 MLXSW_AFK_ELEMENT_INFO_BUF(SRC_IP6_LO, 0x28, 8),
119 MLXSW_AFK_ELEMENT_INFO_BUF(DST_IP6_HI, 0x30, 8),
120 MLXSW_AFK_ELEMENT_INFO_BUF(DST_IP6_LO, 0x38, 8),
121}; 121};
122 122
123#define MLXSW_AFK_ELEMENT_STORAGE_SIZE 0x38 123#define MLXSW_AFK_ELEMENT_STORAGE_SIZE 0x40
124 124
125struct mlxsw_afk_element_inst { /* element instance in actual block */ 125struct mlxsw_afk_element_inst { /* element instance in actual block */
126 const struct mlxsw_afk_element_info *info; 126 const struct mlxsw_afk_element_info *info;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 3dcc58d61506..bf400c75fcc8 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -655,13 +655,17 @@ static int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu)
655} 655}
656 656
657static struct mlxsw_sp_span_inspected_port * 657static struct mlxsw_sp_span_inspected_port *
658mlxsw_sp_span_entry_bound_port_find(struct mlxsw_sp_port *port, 658mlxsw_sp_span_entry_bound_port_find(struct mlxsw_sp_span_entry *span_entry,
659 struct mlxsw_sp_span_entry *span_entry) 659 enum mlxsw_sp_span_type type,
660 struct mlxsw_sp_port *port,
661 bool bind)
660{ 662{
661 struct mlxsw_sp_span_inspected_port *p; 663 struct mlxsw_sp_span_inspected_port *p;
662 664
663 list_for_each_entry(p, &span_entry->bound_ports_list, list) 665 list_for_each_entry(p, &span_entry->bound_ports_list, list)
664 if (port->local_port == p->local_port) 666 if (type == p->type &&
667 port->local_port == p->local_port &&
668 bind == p->bound)
665 return p; 669 return p;
666 return NULL; 670 return NULL;
667} 671}
@@ -691,8 +695,22 @@ mlxsw_sp_span_inspected_port_add(struct mlxsw_sp_port *port,
691 struct mlxsw_sp_span_inspected_port *inspected_port; 695 struct mlxsw_sp_span_inspected_port *inspected_port;
692 struct mlxsw_sp *mlxsw_sp = port->mlxsw_sp; 696 struct mlxsw_sp *mlxsw_sp = port->mlxsw_sp;
693 char sbib_pl[MLXSW_REG_SBIB_LEN]; 697 char sbib_pl[MLXSW_REG_SBIB_LEN];
698 int i;
694 int err; 699 int err;
695 700
701 /* A given (source port, direction) can only be bound to one analyzer,
702 * so if a binding is requested, check for conflicts.
703 */
704 if (bind)
705 for (i = 0; i < mlxsw_sp->span.entries_count; i++) {
706 struct mlxsw_sp_span_entry *curr =
707 &mlxsw_sp->span.entries[i];
708
709 if (mlxsw_sp_span_entry_bound_port_find(curr, type,
710 port, bind))
711 return -EEXIST;
712 }
713
696 /* if it is an egress SPAN, bind a shared buffer to it */ 714 /* if it is an egress SPAN, bind a shared buffer to it */
697 if (type == MLXSW_SP_SPAN_EGRESS) { 715 if (type == MLXSW_SP_SPAN_EGRESS) {
698 u32 buffsize = mlxsw_sp_span_mtu_to_buffsize(mlxsw_sp, 716 u32 buffsize = mlxsw_sp_span_mtu_to_buffsize(mlxsw_sp,
@@ -720,6 +738,7 @@ mlxsw_sp_span_inspected_port_add(struct mlxsw_sp_port *port,
720 } 738 }
721 inspected_port->local_port = port->local_port; 739 inspected_port->local_port = port->local_port;
722 inspected_port->type = type; 740 inspected_port->type = type;
741 inspected_port->bound = bind;
723 list_add_tail(&inspected_port->list, &span_entry->bound_ports_list); 742 list_add_tail(&inspected_port->list, &span_entry->bound_ports_list);
724 743
725 return 0; 744 return 0;
@@ -746,7 +765,8 @@ mlxsw_sp_span_inspected_port_del(struct mlxsw_sp_port *port,
746 struct mlxsw_sp *mlxsw_sp = port->mlxsw_sp; 765 struct mlxsw_sp *mlxsw_sp = port->mlxsw_sp;
747 char sbib_pl[MLXSW_REG_SBIB_LEN]; 766 char sbib_pl[MLXSW_REG_SBIB_LEN];
748 767
749 inspected_port = mlxsw_sp_span_entry_bound_port_find(port, span_entry); 768 inspected_port = mlxsw_sp_span_entry_bound_port_find(span_entry, type,
769 port, bind);
750 if (!inspected_port) 770 if (!inspected_port)
751 return; 771 return;
752 772
@@ -1459,6 +1479,7 @@ mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid)
1459 } 1479 }
1460 1480
1461 mlxsw_sp_port_vlan->mlxsw_sp_port = mlxsw_sp_port; 1481 mlxsw_sp_port_vlan->mlxsw_sp_port = mlxsw_sp_port;
1482 mlxsw_sp_port_vlan->ref_count = 1;
1462 mlxsw_sp_port_vlan->vid = vid; 1483 mlxsw_sp_port_vlan->vid = vid;
1463 list_add(&mlxsw_sp_port_vlan->list, &mlxsw_sp_port->vlans_list); 1484 list_add(&mlxsw_sp_port_vlan->list, &mlxsw_sp_port->vlans_list);
1464 1485
@@ -1486,8 +1507,10 @@ mlxsw_sp_port_vlan_get(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid)
1486 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan; 1507 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1487 1508
1488 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid); 1509 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
1489 if (mlxsw_sp_port_vlan) 1510 if (mlxsw_sp_port_vlan) {
1511 mlxsw_sp_port_vlan->ref_count++;
1490 return mlxsw_sp_port_vlan; 1512 return mlxsw_sp_port_vlan;
1513 }
1491 1514
1492 return mlxsw_sp_port_vlan_create(mlxsw_sp_port, vid); 1515 return mlxsw_sp_port_vlan_create(mlxsw_sp_port, vid);
1493} 1516}
@@ -1496,6 +1519,9 @@ void mlxsw_sp_port_vlan_put(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan)
1496{ 1519{
1497 struct mlxsw_sp_fid *fid = mlxsw_sp_port_vlan->fid; 1520 struct mlxsw_sp_fid *fid = mlxsw_sp_port_vlan->fid;
1498 1521
1522 if (--mlxsw_sp_port_vlan->ref_count != 0)
1523 return;
1524
1499 if (mlxsw_sp_port_vlan->bridge_port) 1525 if (mlxsw_sp_port_vlan->bridge_port)
1500 mlxsw_sp_port_vlan_bridge_leave(mlxsw_sp_port_vlan); 1526 mlxsw_sp_port_vlan_bridge_leave(mlxsw_sp_port_vlan);
1501 else if (fid) 1527 else if (fid)
@@ -4207,13 +4233,12 @@ static struct devlink_resource_ops mlxsw_sp_resource_kvd_hash_double_ops = {
4207 .size_validate = mlxsw_sp_resource_kvd_hash_double_size_validate, 4233 .size_validate = mlxsw_sp_resource_kvd_hash_double_size_validate,
4208}; 4234};
4209 4235
4210static struct devlink_resource_size_params mlxsw_sp_kvd_size_params;
4211static struct devlink_resource_size_params mlxsw_sp_linear_size_params;
4212static struct devlink_resource_size_params mlxsw_sp_hash_single_size_params;
4213static struct devlink_resource_size_params mlxsw_sp_hash_double_size_params;
4214
4215static void 4236static void
4216mlxsw_sp_resource_size_params_prepare(struct mlxsw_core *mlxsw_core) 4237mlxsw_sp_resource_size_params_prepare(struct mlxsw_core *mlxsw_core,
4238 struct devlink_resource_size_params *kvd_size_params,
4239 struct devlink_resource_size_params *linear_size_params,
4240 struct devlink_resource_size_params *hash_double_size_params,
4241 struct devlink_resource_size_params *hash_single_size_params)
4217{ 4242{
4218 u32 single_size_min = MLXSW_CORE_RES_GET(mlxsw_core, 4243 u32 single_size_min = MLXSW_CORE_RES_GET(mlxsw_core,
4219 KVD_SINGLE_MIN_SIZE); 4244 KVD_SINGLE_MIN_SIZE);
@@ -4222,37 +4247,35 @@ mlxsw_sp_resource_size_params_prepare(struct mlxsw_core *mlxsw_core)
4222 u32 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE); 4247 u32 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
4223 u32 linear_size_min = 0; 4248 u32 linear_size_min = 0;
4224 4249
4225 /* KVD top resource */ 4250 devlink_resource_size_params_init(kvd_size_params, kvd_size, kvd_size,
4226 mlxsw_sp_kvd_size_params.size_min = kvd_size; 4251 MLXSW_SP_KVD_GRANULARITY,
4227 mlxsw_sp_kvd_size_params.size_max = kvd_size; 4252 DEVLINK_RESOURCE_UNIT_ENTRY);
4228 mlxsw_sp_kvd_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY; 4253 devlink_resource_size_params_init(linear_size_params, linear_size_min,
4229 mlxsw_sp_kvd_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY; 4254 kvd_size - single_size_min -
4230 4255 double_size_min,
4231 /* Linear part init */ 4256 MLXSW_SP_KVD_GRANULARITY,
4232 mlxsw_sp_linear_size_params.size_min = linear_size_min; 4257 DEVLINK_RESOURCE_UNIT_ENTRY);
4233 mlxsw_sp_linear_size_params.size_max = kvd_size - single_size_min - 4258 devlink_resource_size_params_init(hash_double_size_params,
4234 double_size_min; 4259 double_size_min,
4235 mlxsw_sp_linear_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY; 4260 kvd_size - single_size_min -
4236 mlxsw_sp_linear_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY; 4261 linear_size_min,
4237 4262 MLXSW_SP_KVD_GRANULARITY,
4238 /* Hash double part init */ 4263 DEVLINK_RESOURCE_UNIT_ENTRY);
4239 mlxsw_sp_hash_double_size_params.size_min = double_size_min; 4264 devlink_resource_size_params_init(hash_single_size_params,
4240 mlxsw_sp_hash_double_size_params.size_max = kvd_size - single_size_min - 4265 single_size_min,
4241 linear_size_min; 4266 kvd_size - double_size_min -
4242 mlxsw_sp_hash_double_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY; 4267 linear_size_min,
4243 mlxsw_sp_hash_double_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY; 4268 MLXSW_SP_KVD_GRANULARITY,
4244 4269 DEVLINK_RESOURCE_UNIT_ENTRY);
4245 /* Hash single part init */
4246 mlxsw_sp_hash_single_size_params.size_min = single_size_min;
4247 mlxsw_sp_hash_single_size_params.size_max = kvd_size - double_size_min -
4248 linear_size_min;
4249 mlxsw_sp_hash_single_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY;
4250 mlxsw_sp_hash_single_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY;
4251} 4270}
4252 4271
4253static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core) 4272static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
4254{ 4273{
4255 struct devlink *devlink = priv_to_devlink(mlxsw_core); 4274 struct devlink *devlink = priv_to_devlink(mlxsw_core);
4275 struct devlink_resource_size_params hash_single_size_params;
4276 struct devlink_resource_size_params hash_double_size_params;
4277 struct devlink_resource_size_params linear_size_params;
4278 struct devlink_resource_size_params kvd_size_params;
4256 u32 kvd_size, single_size, double_size, linear_size; 4279 u32 kvd_size, single_size, double_size, linear_size;
4257 const struct mlxsw_config_profile *profile; 4280 const struct mlxsw_config_profile *profile;
4258 int err; 4281 int err;
@@ -4261,13 +4284,17 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
4261 if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SIZE)) 4284 if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SIZE))
4262 return -EIO; 4285 return -EIO;
4263 4286
4264 mlxsw_sp_resource_size_params_prepare(mlxsw_core); 4287 mlxsw_sp_resource_size_params_prepare(mlxsw_core, &kvd_size_params,
4288 &linear_size_params,
4289 &hash_double_size_params,
4290 &hash_single_size_params);
4291
4265 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE); 4292 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
4266 err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD, 4293 err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD,
4267 true, kvd_size, 4294 true, kvd_size,
4268 MLXSW_SP_RESOURCE_KVD, 4295 MLXSW_SP_RESOURCE_KVD,
4269 DEVLINK_RESOURCE_ID_PARENT_TOP, 4296 DEVLINK_RESOURCE_ID_PARENT_TOP,
4270 &mlxsw_sp_kvd_size_params, 4297 &kvd_size_params,
4271 &mlxsw_sp_resource_kvd_ops); 4298 &mlxsw_sp_resource_kvd_ops);
4272 if (err) 4299 if (err)
4273 return err; 4300 return err;
@@ -4277,7 +4304,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
4277 false, linear_size, 4304 false, linear_size,
4278 MLXSW_SP_RESOURCE_KVD_LINEAR, 4305 MLXSW_SP_RESOURCE_KVD_LINEAR,
4279 MLXSW_SP_RESOURCE_KVD, 4306 MLXSW_SP_RESOURCE_KVD,
4280 &mlxsw_sp_linear_size_params, 4307 &linear_size_params,
4281 &mlxsw_sp_resource_kvd_linear_ops); 4308 &mlxsw_sp_resource_kvd_linear_ops);
4282 if (err) 4309 if (err)
4283 return err; 4310 return err;
@@ -4291,7 +4318,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
4291 false, double_size, 4318 false, double_size,
4292 MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE, 4319 MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
4293 MLXSW_SP_RESOURCE_KVD, 4320 MLXSW_SP_RESOURCE_KVD,
4294 &mlxsw_sp_hash_double_size_params, 4321 &hash_double_size_params,
4295 &mlxsw_sp_resource_kvd_hash_double_ops); 4322 &mlxsw_sp_resource_kvd_hash_double_ops);
4296 if (err) 4323 if (err)
4297 return err; 4324 return err;
@@ -4301,7 +4328,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
4301 false, single_size, 4328 false, single_size,
4302 MLXSW_SP_RESOURCE_KVD_HASH_SINGLE, 4329 MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
4303 MLXSW_SP_RESOURCE_KVD, 4330 MLXSW_SP_RESOURCE_KVD,
4304 &mlxsw_sp_hash_single_size_params, 4331 &hash_single_size_params,
4305 &mlxsw_sp_resource_kvd_hash_single_ops); 4332 &mlxsw_sp_resource_kvd_hash_single_ops);
4306 if (err) 4333 if (err)
4307 return err; 4334 return err;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index bdd8f94a452c..92064db2ae44 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -120,6 +120,9 @@ struct mlxsw_sp_span_inspected_port {
120 struct list_head list; 120 struct list_head list;
121 enum mlxsw_sp_span_type type; 121 enum mlxsw_sp_span_type type;
122 u8 local_port; 122 u8 local_port;
123
124 /* Whether this is a directly bound mirror (port-to-port) or an ACL. */
125 bool bound;
123}; 126};
124 127
125struct mlxsw_sp_span_entry { 128struct mlxsw_sp_span_entry {
@@ -211,6 +214,7 @@ struct mlxsw_sp_port_vlan {
211 struct list_head list; 214 struct list_head list;
212 struct mlxsw_sp_port *mlxsw_sp_port; 215 struct mlxsw_sp_port *mlxsw_sp_port;
213 struct mlxsw_sp_fid *fid; 216 struct mlxsw_sp_fid *fid;
217 unsigned int ref_count;
214 u16 vid; 218 u16 vid;
215 struct mlxsw_sp_bridge_port *bridge_port; 219 struct mlxsw_sp_bridge_port *bridge_port;
216 struct list_head bridge_vlan_node; 220 struct list_head bridge_vlan_node;
@@ -552,6 +556,7 @@ void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
552int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei); 556int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
553int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei, 557int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
554 u16 group_id); 558 u16 group_id);
559int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
555int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei); 560int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
556int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei); 561int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
557int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp, 562int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
index 0897a5435cc2..92d90ed7207e 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
@@ -528,6 +528,11 @@ int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
528 return mlxsw_afa_block_jump(rulei->act_block, group_id); 528 return mlxsw_afa_block_jump(rulei->act_block, group_id);
529} 529}
530 530
531int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei)
532{
533 return mlxsw_afa_block_terminate(rulei->act_block);
534}
535
531int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei) 536int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei)
532{ 537{
533 return mlxsw_afa_block_append_drop(rulei->act_block); 538 return mlxsw_afa_block_append_drop(rulei->act_block);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
index 93728c694e6d..0a9adc5962fb 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
@@ -385,13 +385,13 @@ static const struct mlxsw_sp_sb_cm mlxsw_sp_sb_cms_egress[] = {
385 385
386static const struct mlxsw_sp_sb_cm mlxsw_sp_cpu_port_sb_cms[] = { 386static const struct mlxsw_sp_sb_cm mlxsw_sp_cpu_port_sb_cms[] = {
387 MLXSW_SP_CPU_PORT_SB_CM, 387 MLXSW_SP_CPU_PORT_SB_CM,
388 MLXSW_SP_SB_CM(MLXSW_PORT_MAX_MTU, 0, 0),
389 MLXSW_SP_SB_CM(MLXSW_PORT_MAX_MTU, 0, 0),
390 MLXSW_SP_SB_CM(MLXSW_PORT_MAX_MTU, 0, 0),
391 MLXSW_SP_SB_CM(MLXSW_PORT_MAX_MTU, 0, 0),
392 MLXSW_SP_SB_CM(MLXSW_PORT_MAX_MTU, 0, 0),
388 MLXSW_SP_CPU_PORT_SB_CM, 393 MLXSW_SP_CPU_PORT_SB_CM,
389 MLXSW_SP_CPU_PORT_SB_CM, 394 MLXSW_SP_SB_CM(MLXSW_PORT_MAX_MTU, 0, 0),
390 MLXSW_SP_CPU_PORT_SB_CM,
391 MLXSW_SP_CPU_PORT_SB_CM,
392 MLXSW_SP_CPU_PORT_SB_CM,
393 MLXSW_SP_CPU_PORT_SB_CM,
394 MLXSW_SP_SB_CM(10000, 0, 0),
395 MLXSW_SP_CPU_PORT_SB_CM, 395 MLXSW_SP_CPU_PORT_SB_CM,
396 MLXSW_SP_CPU_PORT_SB_CM, 396 MLXSW_SP_CPU_PORT_SB_CM,
397 MLXSW_SP_CPU_PORT_SB_CM, 397 MLXSW_SP_CPU_PORT_SB_CM,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c
index bbd238e50f05..54262af4e98f 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c
@@ -112,11 +112,11 @@ static const int mlxsw_sp_sfgc_bc_packet_types[MLXSW_REG_SFGC_TYPE_MAX] = {
112 [MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP] = 1, 112 [MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP] = 1,
113 [MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL] = 1, 113 [MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL] = 1,
114 [MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST] = 1, 114 [MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST] = 1,
115 [MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6] = 1,
115}; 116};
116 117
117static const int mlxsw_sp_sfgc_mc_packet_types[MLXSW_REG_SFGC_TYPE_MAX] = { 118static const int mlxsw_sp_sfgc_mc_packet_types[MLXSW_REG_SFGC_TYPE_MAX] = {
118 [MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4] = 1, 119 [MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4] = 1,
119 [MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6] = 1,
120}; 120};
121 121
122static const int *mlxsw_sp_packet_type_sfgc_types[] = { 122static const int *mlxsw_sp_packet_type_sfgc_types[] = {
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
index 6ce00e28d4ea..89dbf569dff5 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
@@ -65,7 +65,7 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
65 tcf_exts_to_list(exts, &actions); 65 tcf_exts_to_list(exts, &actions);
66 list_for_each_entry(a, &actions, list) { 66 list_for_each_entry(a, &actions, list) {
67 if (is_tcf_gact_ok(a)) { 67 if (is_tcf_gact_ok(a)) {
68 err = mlxsw_sp_acl_rulei_act_continue(rulei); 68 err = mlxsw_sp_acl_rulei_act_terminate(rulei);
69 if (err) 69 if (err)
70 return err; 70 return err;
71 } else if (is_tcf_gact_shot(a)) { 71 } else if (is_tcf_gact_shot(a)) {
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index f0b25baba09a..f7948e983637 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -788,6 +788,9 @@ static struct mlxsw_sp_vr *mlxsw_sp_vr_create(struct mlxsw_sp *mlxsw_sp,
788 u32 tb_id, 788 u32 tb_id,
789 struct netlink_ext_ack *extack) 789 struct netlink_ext_ack *extack)
790{ 790{
791 struct mlxsw_sp_mr_table *mr4_table;
792 struct mlxsw_sp_fib *fib4;
793 struct mlxsw_sp_fib *fib6;
791 struct mlxsw_sp_vr *vr; 794 struct mlxsw_sp_vr *vr;
792 int err; 795 int err;
793 796
@@ -796,29 +799,30 @@ static struct mlxsw_sp_vr *mlxsw_sp_vr_create(struct mlxsw_sp *mlxsw_sp,
796 NL_SET_ERR_MSG(extack, "spectrum: Exceeded number of supported virtual routers"); 799 NL_SET_ERR_MSG(extack, "spectrum: Exceeded number of supported virtual routers");
797 return ERR_PTR(-EBUSY); 800 return ERR_PTR(-EBUSY);
798 } 801 }
799 vr->fib4 = mlxsw_sp_fib_create(mlxsw_sp, vr, MLXSW_SP_L3_PROTO_IPV4); 802 fib4 = mlxsw_sp_fib_create(mlxsw_sp, vr, MLXSW_SP_L3_PROTO_IPV4);
800 if (IS_ERR(vr->fib4)) 803 if (IS_ERR(fib4))
801 return ERR_CAST(vr->fib4); 804 return ERR_CAST(fib4);
802 vr->fib6 = mlxsw_sp_fib_create(mlxsw_sp, vr, MLXSW_SP_L3_PROTO_IPV6); 805 fib6 = mlxsw_sp_fib_create(mlxsw_sp, vr, MLXSW_SP_L3_PROTO_IPV6);
803 if (IS_ERR(vr->fib6)) { 806 if (IS_ERR(fib6)) {
804 err = PTR_ERR(vr->fib6); 807 err = PTR_ERR(fib6);
805 goto err_fib6_create; 808 goto err_fib6_create;
806 } 809 }
807 vr->mr4_table = mlxsw_sp_mr_table_create(mlxsw_sp, vr->id, 810 mr4_table = mlxsw_sp_mr_table_create(mlxsw_sp, vr->id,
808 MLXSW_SP_L3_PROTO_IPV4); 811 MLXSW_SP_L3_PROTO_IPV4);
809 if (IS_ERR(vr->mr4_table)) { 812 if (IS_ERR(mr4_table)) {
810 err = PTR_ERR(vr->mr4_table); 813 err = PTR_ERR(mr4_table);
811 goto err_mr_table_create; 814 goto err_mr_table_create;
812 } 815 }
816 vr->fib4 = fib4;
817 vr->fib6 = fib6;
818 vr->mr4_table = mr4_table;
813 vr->tb_id = tb_id; 819 vr->tb_id = tb_id;
814 return vr; 820 return vr;
815 821
816err_mr_table_create: 822err_mr_table_create:
817 mlxsw_sp_fib_destroy(mlxsw_sp, vr->fib6); 823 mlxsw_sp_fib_destroy(mlxsw_sp, fib6);
818 vr->fib6 = NULL;
819err_fib6_create: 824err_fib6_create:
820 mlxsw_sp_fib_destroy(mlxsw_sp, vr->fib4); 825 mlxsw_sp_fib_destroy(mlxsw_sp, fib4);
821 vr->fib4 = NULL;
822 return ERR_PTR(err); 826 return ERR_PTR(err);
823} 827}
824 828
@@ -3790,6 +3794,9 @@ mlxsw_sp_fib4_entry_offload_unset(struct mlxsw_sp_fib_entry *fib_entry)
3790 struct mlxsw_sp_nexthop_group *nh_grp = fib_entry->nh_group; 3794 struct mlxsw_sp_nexthop_group *nh_grp = fib_entry->nh_group;
3791 int i; 3795 int i;
3792 3796
3797 if (!list_is_singular(&nh_grp->fib_list))
3798 return;
3799
3793 for (i = 0; i < nh_grp->count; i++) { 3800 for (i = 0; i < nh_grp->count; i++) {
3794 struct mlxsw_sp_nexthop *nh = &nh_grp->nexthops[i]; 3801 struct mlxsw_sp_nexthop *nh = &nh_grp->nexthops[i];
3795 3802
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 593ad31be749..161bcdc012f0 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1203,6 +1203,7 @@ static int __mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
1203 bool dynamic) 1203 bool dynamic)
1204{ 1204{
1205 char *sfd_pl; 1205 char *sfd_pl;
1206 u8 num_rec;
1206 int err; 1207 int err;
1207 1208
1208 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL); 1209 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
@@ -1212,9 +1213,16 @@ static int __mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
1212 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0); 1213 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
1213 mlxsw_reg_sfd_uc_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic), 1214 mlxsw_reg_sfd_uc_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
1214 mac, fid, action, local_port); 1215 mac, fid, action, local_port);
1216 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1215 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl); 1217 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1216 kfree(sfd_pl); 1218 if (err)
1219 goto out;
1220
1221 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1222 err = -EBUSY;
1217 1223
1224out:
1225 kfree(sfd_pl);
1218 return err; 1226 return err;
1219} 1227}
1220 1228
@@ -1239,6 +1247,7 @@ static int mlxsw_sp_port_fdb_uc_lag_op(struct mlxsw_sp *mlxsw_sp, u16 lag_id,
1239 bool adding, bool dynamic) 1247 bool adding, bool dynamic)
1240{ 1248{
1241 char *sfd_pl; 1249 char *sfd_pl;
1250 u8 num_rec;
1242 int err; 1251 int err;
1243 1252
1244 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL); 1253 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
@@ -1249,9 +1258,16 @@ static int mlxsw_sp_port_fdb_uc_lag_op(struct mlxsw_sp *mlxsw_sp, u16 lag_id,
1249 mlxsw_reg_sfd_uc_lag_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic), 1258 mlxsw_reg_sfd_uc_lag_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
1250 mac, fid, MLXSW_REG_SFD_REC_ACTION_NOP, 1259 mac, fid, MLXSW_REG_SFD_REC_ACTION_NOP,
1251 lag_vid, lag_id); 1260 lag_vid, lag_id);
1261 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1252 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl); 1262 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1253 kfree(sfd_pl); 1263 if (err)
1264 goto out;
1265
1266 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1267 err = -EBUSY;
1254 1268
1269out:
1270 kfree(sfd_pl);
1255 return err; 1271 return err;
1256} 1272}
1257 1273
@@ -1296,6 +1312,7 @@ static int mlxsw_sp_port_mdb_op(struct mlxsw_sp *mlxsw_sp, const char *addr,
1296 u16 fid, u16 mid_idx, bool adding) 1312 u16 fid, u16 mid_idx, bool adding)
1297{ 1313{
1298 char *sfd_pl; 1314 char *sfd_pl;
1315 u8 num_rec;
1299 int err; 1316 int err;
1300 1317
1301 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL); 1318 sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
@@ -1305,7 +1322,15 @@ static int mlxsw_sp_port_mdb_op(struct mlxsw_sp *mlxsw_sp, const char *addr,
1305 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0); 1322 mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
1306 mlxsw_reg_sfd_mc_pack(sfd_pl, 0, addr, fid, 1323 mlxsw_reg_sfd_mc_pack(sfd_pl, 0, addr, fid,
1307 MLXSW_REG_SFD_REC_ACTION_NOP, mid_idx); 1324 MLXSW_REG_SFD_REC_ACTION_NOP, mid_idx);
1325 num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
1308 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl); 1326 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
1327 if (err)
1328 goto out;
1329
1330 if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
1331 err = -EBUSY;
1332
1333out:
1309 kfree(sfd_pl); 1334 kfree(sfd_pl);
1310 return err; 1335 return err;
1311} 1336}
diff --git a/drivers/net/ethernet/natsemi/Kconfig b/drivers/net/ethernet/natsemi/Kconfig
index a10ef50e4f12..017fb2322589 100644
--- a/drivers/net/ethernet/natsemi/Kconfig
+++ b/drivers/net/ethernet/natsemi/Kconfig
@@ -1,16 +1,16 @@
1# 1#
2# National Semi-conductor device configuration 2# National Semiconductor device configuration
3# 3#
4 4
5config NET_VENDOR_NATSEMI 5config NET_VENDOR_NATSEMI
6 bool "National Semi-conductor devices" 6 bool "National Semiconductor devices"
7 default y 7 default y
8 ---help--- 8 ---help---
9 If you have a network (Ethernet) card belonging to this class, say Y. 9 If you have a network (Ethernet) card belonging to this class, say Y.
10 10
11 Note that the answer to this question doesn't directly affect the 11 Note that the answer to this question doesn't directly affect the
12 kernel: saying N will just cause the configurator to skip all 12 kernel: saying N will just cause the configurator to skip all
13 the questions about National Semi-conductor devices. If you say Y, 13 the questions about National Semiconductor devices. If you say Y,
14 you will be asked for your specific card in the following questions. 14 you will be asked for your specific card in the following questions.
15 15
16if NET_VENDOR_NATSEMI 16if NET_VENDOR_NATSEMI
diff --git a/drivers/net/ethernet/natsemi/Makefile b/drivers/net/ethernet/natsemi/Makefile
index cc664977596e..a759aa09ef59 100644
--- a/drivers/net/ethernet/natsemi/Makefile
+++ b/drivers/net/ethernet/natsemi/Makefile
@@ -1,6 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2# 2#
3# Makefile for the National Semi-conductor Sonic devices. 3# Makefile for the National Semiconductor Sonic devices.
4# 4#
5 5
6obj-$(CONFIG_MACSONIC) += macsonic.o 6obj-$(CONFIG_MACSONIC) += macsonic.o
diff --git a/drivers/net/ethernet/qlogic/qed/qed_cxt.c b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
index 6f546e869d8d..00f41c145d4d 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_cxt.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
@@ -2480,7 +2480,10 @@ int qed_cxt_free_proto_ilt(struct qed_hwfn *p_hwfn, enum protocol_type proto)
2480 if (rc) 2480 if (rc)
2481 return rc; 2481 return rc;
2482 2482
2483 /* Free Task CXT */ 2483 /* Free Task CXT ( Intentionally RoCE as task-id is shared between
2484 * RoCE and iWARP )
2485 */
2486 proto = PROTOCOLID_ROCE;
2484 rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_TASK, 0, 2487 rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_TASK, 0,
2485 qed_cxt_get_proto_tid_count(p_hwfn, proto)); 2488 qed_cxt_get_proto_tid_count(p_hwfn, proto));
2486 if (rc) 2489 if (rc)
diff --git a/drivers/net/ethernet/qlogic/qed/qed_iwarp.c b/drivers/net/ethernet/qlogic/qed/qed_iwarp.c
index ca4a81dc1ace..d5d02be72947 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_iwarp.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_iwarp.c
@@ -1703,6 +1703,13 @@ qed_iwarp_parse_rx_pkt(struct qed_hwfn *p_hwfn,
1703 iph = (struct iphdr *)((u8 *)(ethh) + eth_hlen); 1703 iph = (struct iphdr *)((u8 *)(ethh) + eth_hlen);
1704 1704
1705 if (eth_type == ETH_P_IP) { 1705 if (eth_type == ETH_P_IP) {
1706 if (iph->protocol != IPPROTO_TCP) {
1707 DP_NOTICE(p_hwfn,
1708 "Unexpected ip protocol on ll2 %x\n",
1709 iph->protocol);
1710 return -EINVAL;
1711 }
1712
1706 cm_info->local_ip[0] = ntohl(iph->daddr); 1713 cm_info->local_ip[0] = ntohl(iph->daddr);
1707 cm_info->remote_ip[0] = ntohl(iph->saddr); 1714 cm_info->remote_ip[0] = ntohl(iph->saddr);
1708 cm_info->ip_version = TCP_IPV4; 1715 cm_info->ip_version = TCP_IPV4;
@@ -1711,6 +1718,14 @@ qed_iwarp_parse_rx_pkt(struct qed_hwfn *p_hwfn,
1711 *payload_len = ntohs(iph->tot_len) - ip_hlen; 1718 *payload_len = ntohs(iph->tot_len) - ip_hlen;
1712 } else if (eth_type == ETH_P_IPV6) { 1719 } else if (eth_type == ETH_P_IPV6) {
1713 ip6h = (struct ipv6hdr *)iph; 1720 ip6h = (struct ipv6hdr *)iph;
1721
1722 if (ip6h->nexthdr != IPPROTO_TCP) {
1723 DP_NOTICE(p_hwfn,
1724 "Unexpected ip protocol on ll2 %x\n",
1725 iph->protocol);
1726 return -EINVAL;
1727 }
1728
1714 for (i = 0; i < 4; i++) { 1729 for (i = 0; i < 4; i++) {
1715 cm_info->local_ip[i] = 1730 cm_info->local_ip[i] =
1716 ntohl(ip6h->daddr.in6_u.u6_addr32[i]); 1731 ntohl(ip6h->daddr.in6_u.u6_addr32[i]);
@@ -1928,8 +1943,8 @@ qed_iwarp_update_fpdu_length(struct qed_hwfn *p_hwfn,
1928 /* Missing lower byte is now available */ 1943 /* Missing lower byte is now available */
1929 mpa_len = fpdu->fpdu_length | *mpa_data; 1944 mpa_len = fpdu->fpdu_length | *mpa_data;
1930 fpdu->fpdu_length = QED_IWARP_FPDU_LEN_WITH_PAD(mpa_len); 1945 fpdu->fpdu_length = QED_IWARP_FPDU_LEN_WITH_PAD(mpa_len);
1931 fpdu->mpa_frag_len = fpdu->fpdu_length;
1932 /* one byte of hdr */ 1946 /* one byte of hdr */
1947 fpdu->mpa_frag_len = 1;
1933 fpdu->incomplete_bytes = fpdu->fpdu_length - 1; 1948 fpdu->incomplete_bytes = fpdu->fpdu_length - 1;
1934 DP_VERBOSE(p_hwfn, 1949 DP_VERBOSE(p_hwfn,
1935 QED_MSG_RDMA, 1950 QED_MSG_RDMA,
diff --git a/drivers/net/ethernet/qlogic/qed/qed_rdma.c b/drivers/net/ethernet/qlogic/qed/qed_rdma.c
index 5d040b873137..a411f9c702a1 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_rdma.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_rdma.c
@@ -379,6 +379,7 @@ static void qed_rdma_free(struct qed_hwfn *p_hwfn)
379 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Freeing RDMA\n"); 379 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Freeing RDMA\n");
380 380
381 qed_rdma_free_reserved_lkey(p_hwfn); 381 qed_rdma_free_reserved_lkey(p_hwfn);
382 qed_cxt_free_proto_ilt(p_hwfn, p_hwfn->p_rdma_info->proto);
382 qed_rdma_resc_free(p_hwfn); 383 qed_rdma_resc_free(p_hwfn);
383} 384}
384 385
diff --git a/drivers/net/ethernet/qlogic/qede/qede_main.c b/drivers/net/ethernet/qlogic/qede/qede_main.c
index 2db70eabddfe..a01e7d6e5442 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_main.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_main.c
@@ -288,7 +288,7 @@ int __init qede_init(void)
288 } 288 }
289 289
290 /* Must register notifier before pci ops, since we might miss 290 /* Must register notifier before pci ops, since we might miss
291 * interface rename after pci probe and netdev registeration. 291 * interface rename after pci probe and netdev registration.
292 */ 292 */
293 ret = register_netdevice_notifier(&qede_netdev_notifier); 293 ret = register_netdevice_notifier(&qede_netdev_notifier);
294 if (ret) { 294 if (ret) {
@@ -988,7 +988,7 @@ static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level,
988 if (rc) 988 if (rc)
989 goto err3; 989 goto err3;
990 990
991 /* Prepare the lock prior to the registeration of the netdev, 991 /* Prepare the lock prior to the registration of the netdev,
992 * as once it's registered we might reach flows requiring it 992 * as once it's registered we might reach flows requiring it
993 * [it's even possible to reach a flow needing it directly 993 * [it's even possible to reach a flow needing it directly
994 * from there, although it's unlikely]. 994 * from there, although it's unlikely].
@@ -2067,8 +2067,6 @@ static int qede_load(struct qede_dev *edev, enum qede_load_mode mode,
2067 link_params.link_up = true; 2067 link_params.link_up = true;
2068 edev->ops->common->set_link(edev->cdev, &link_params); 2068 edev->ops->common->set_link(edev->cdev, &link_params);
2069 2069
2070 qede_rdma_dev_event_open(edev);
2071
2072 edev->state = QEDE_STATE_OPEN; 2070 edev->state = QEDE_STATE_OPEN;
2073 2071
2074 DP_INFO(edev, "Ending successfully qede load\n"); 2072 DP_INFO(edev, "Ending successfully qede load\n");
@@ -2169,12 +2167,14 @@ static void qede_link_update(void *dev, struct qed_link_output *link)
2169 DP_NOTICE(edev, "Link is up\n"); 2167 DP_NOTICE(edev, "Link is up\n");
2170 netif_tx_start_all_queues(edev->ndev); 2168 netif_tx_start_all_queues(edev->ndev);
2171 netif_carrier_on(edev->ndev); 2169 netif_carrier_on(edev->ndev);
2170 qede_rdma_dev_event_open(edev);
2172 } 2171 }
2173 } else { 2172 } else {
2174 if (netif_carrier_ok(edev->ndev)) { 2173 if (netif_carrier_ok(edev->ndev)) {
2175 DP_NOTICE(edev, "Link is down\n"); 2174 DP_NOTICE(edev, "Link is down\n");
2176 netif_tx_disable(edev->ndev); 2175 netif_tx_disable(edev->ndev);
2177 netif_carrier_off(edev->ndev); 2176 netif_carrier_off(edev->ndev);
2177 qede_rdma_dev_event_close(edev);
2178 } 2178 }
2179 } 2179 }
2180} 2180}
diff --git a/drivers/net/ethernet/qlogic/qede/qede_ptp.c b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
index 9b2280badaf7..02adb513f475 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ptp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
@@ -485,7 +485,7 @@ int qede_ptp_enable(struct qede_dev *edev, bool init_tc)
485 ptp->clock = ptp_clock_register(&ptp->clock_info, &edev->pdev->dev); 485 ptp->clock = ptp_clock_register(&ptp->clock_info, &edev->pdev->dev);
486 if (IS_ERR(ptp->clock)) { 486 if (IS_ERR(ptp->clock)) {
487 rc = -EINVAL; 487 rc = -EINVAL;
488 DP_ERR(edev, "PTP clock registeration failed\n"); 488 DP_ERR(edev, "PTP clock registration failed\n");
489 goto err2; 489 goto err2;
490 } 490 }
491 491
diff --git a/drivers/net/ethernet/qualcomm/emac/emac-mac.c b/drivers/net/ethernet/qualcomm/emac/emac-mac.c
index 9cbb27263742..d5a32b7c7dc5 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac-mac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac-mac.c
@@ -1194,9 +1194,9 @@ void emac_mac_tx_process(struct emac_adapter *adpt, struct emac_tx_queue *tx_q)
1194 while (tx_q->tpd.consume_idx != hw_consume_idx) { 1194 while (tx_q->tpd.consume_idx != hw_consume_idx) {
1195 tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.consume_idx); 1195 tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.consume_idx);
1196 if (tpbuf->dma_addr) { 1196 if (tpbuf->dma_addr) {
1197 dma_unmap_single(adpt->netdev->dev.parent, 1197 dma_unmap_page(adpt->netdev->dev.parent,
1198 tpbuf->dma_addr, tpbuf->length, 1198 tpbuf->dma_addr, tpbuf->length,
1199 DMA_TO_DEVICE); 1199 DMA_TO_DEVICE);
1200 tpbuf->dma_addr = 0; 1200 tpbuf->dma_addr = 0;
1201 } 1201 }
1202 1202
@@ -1353,9 +1353,11 @@ static void emac_tx_fill_tpd(struct emac_adapter *adpt,
1353 1353
1354 tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx); 1354 tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
1355 tpbuf->length = mapped_len; 1355 tpbuf->length = mapped_len;
1356 tpbuf->dma_addr = dma_map_single(adpt->netdev->dev.parent, 1356 tpbuf->dma_addr = dma_map_page(adpt->netdev->dev.parent,
1357 skb->data, tpbuf->length, 1357 virt_to_page(skb->data),
1358 DMA_TO_DEVICE); 1358 offset_in_page(skb->data),
1359 tpbuf->length,
1360 DMA_TO_DEVICE);
1359 ret = dma_mapping_error(adpt->netdev->dev.parent, 1361 ret = dma_mapping_error(adpt->netdev->dev.parent,
1360 tpbuf->dma_addr); 1362 tpbuf->dma_addr);
1361 if (ret) 1363 if (ret)
@@ -1371,9 +1373,12 @@ static void emac_tx_fill_tpd(struct emac_adapter *adpt,
1371 if (mapped_len < len) { 1373 if (mapped_len < len) {
1372 tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx); 1374 tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
1373 tpbuf->length = len - mapped_len; 1375 tpbuf->length = len - mapped_len;
1374 tpbuf->dma_addr = dma_map_single(adpt->netdev->dev.parent, 1376 tpbuf->dma_addr = dma_map_page(adpt->netdev->dev.parent,
1375 skb->data + mapped_len, 1377 virt_to_page(skb->data +
1376 tpbuf->length, DMA_TO_DEVICE); 1378 mapped_len),
1379 offset_in_page(skb->data +
1380 mapped_len),
1381 tpbuf->length, DMA_TO_DEVICE);
1377 ret = dma_mapping_error(adpt->netdev->dev.parent, 1382 ret = dma_mapping_error(adpt->netdev->dev.parent,
1378 tpbuf->dma_addr); 1383 tpbuf->dma_addr);
1379 if (ret) 1384 if (ret)
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
index 7e7704daf5f1..c4949183eef3 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
@@ -43,12 +43,6 @@
43 43
44/* Local Definitions and Declarations */ 44/* Local Definitions and Declarations */
45 45
46struct rmnet_walk_data {
47 struct net_device *real_dev;
48 struct list_head *head;
49 struct rmnet_port *port;
50};
51
52static int rmnet_is_real_dev_registered(const struct net_device *real_dev) 46static int rmnet_is_real_dev_registered(const struct net_device *real_dev)
53{ 47{
54 return rcu_access_pointer(real_dev->rx_handler) == rmnet_rx_handler; 48 return rcu_access_pointer(real_dev->rx_handler) == rmnet_rx_handler;
@@ -112,17 +106,14 @@ static int rmnet_register_real_device(struct net_device *real_dev)
112static void rmnet_unregister_bridge(struct net_device *dev, 106static void rmnet_unregister_bridge(struct net_device *dev,
113 struct rmnet_port *port) 107 struct rmnet_port *port)
114{ 108{
115 struct net_device *rmnet_dev, *bridge_dev;
116 struct rmnet_port *bridge_port; 109 struct rmnet_port *bridge_port;
110 struct net_device *bridge_dev;
117 111
118 if (port->rmnet_mode != RMNET_EPMODE_BRIDGE) 112 if (port->rmnet_mode != RMNET_EPMODE_BRIDGE)
119 return; 113 return;
120 114
121 /* bridge slave handling */ 115 /* bridge slave handling */
122 if (!port->nr_rmnet_devs) { 116 if (!port->nr_rmnet_devs) {
123 rmnet_dev = netdev_master_upper_dev_get_rcu(dev);
124 netdev_upper_dev_unlink(dev, rmnet_dev);
125
126 bridge_dev = port->bridge_ep; 117 bridge_dev = port->bridge_ep;
127 118
128 bridge_port = rmnet_get_port_rtnl(bridge_dev); 119 bridge_port = rmnet_get_port_rtnl(bridge_dev);
@@ -132,9 +123,6 @@ static void rmnet_unregister_bridge(struct net_device *dev,
132 bridge_dev = port->bridge_ep; 123 bridge_dev = port->bridge_ep;
133 124
134 bridge_port = rmnet_get_port_rtnl(bridge_dev); 125 bridge_port = rmnet_get_port_rtnl(bridge_dev);
135 rmnet_dev = netdev_master_upper_dev_get_rcu(bridge_dev);
136 netdev_upper_dev_unlink(bridge_dev, rmnet_dev);
137
138 rmnet_unregister_real_device(bridge_dev, bridge_port); 126 rmnet_unregister_real_device(bridge_dev, bridge_port);
139 } 127 }
140} 128}
@@ -173,10 +161,6 @@ static int rmnet_newlink(struct net *src_net, struct net_device *dev,
173 if (err) 161 if (err)
174 goto err1; 162 goto err1;
175 163
176 err = netdev_master_upper_dev_link(dev, real_dev, NULL, NULL, extack);
177 if (err)
178 goto err2;
179
180 port->rmnet_mode = mode; 164 port->rmnet_mode = mode;
181 165
182 hlist_add_head_rcu(&ep->hlnode, &port->muxed_ep[mux_id]); 166 hlist_add_head_rcu(&ep->hlnode, &port->muxed_ep[mux_id]);
@@ -193,8 +177,6 @@ static int rmnet_newlink(struct net *src_net, struct net_device *dev,
193 177
194 return 0; 178 return 0;
195 179
196err2:
197 rmnet_vnd_dellink(mux_id, port, ep);
198err1: 180err1:
199 rmnet_unregister_real_device(real_dev, port); 181 rmnet_unregister_real_device(real_dev, port);
200err0: 182err0:
@@ -204,14 +186,13 @@ err0:
204 186
205static void rmnet_dellink(struct net_device *dev, struct list_head *head) 187static void rmnet_dellink(struct net_device *dev, struct list_head *head)
206{ 188{
189 struct rmnet_priv *priv = netdev_priv(dev);
207 struct net_device *real_dev; 190 struct net_device *real_dev;
208 struct rmnet_endpoint *ep; 191 struct rmnet_endpoint *ep;
209 struct rmnet_port *port; 192 struct rmnet_port *port;
210 u8 mux_id; 193 u8 mux_id;
211 194
212 rcu_read_lock(); 195 real_dev = priv->real_dev;
213 real_dev = netdev_master_upper_dev_get_rcu(dev);
214 rcu_read_unlock();
215 196
216 if (!real_dev || !rmnet_is_real_dev_registered(real_dev)) 197 if (!real_dev || !rmnet_is_real_dev_registered(real_dev))
217 return; 198 return;
@@ -219,7 +200,6 @@ static void rmnet_dellink(struct net_device *dev, struct list_head *head)
219 port = rmnet_get_port_rtnl(real_dev); 200 port = rmnet_get_port_rtnl(real_dev);
220 201
221 mux_id = rmnet_vnd_get_mux(dev); 202 mux_id = rmnet_vnd_get_mux(dev);
222 netdev_upper_dev_unlink(dev, real_dev);
223 203
224 ep = rmnet_get_endpoint(port, mux_id); 204 ep = rmnet_get_endpoint(port, mux_id);
225 if (ep) { 205 if (ep) {
@@ -233,30 +213,13 @@ static void rmnet_dellink(struct net_device *dev, struct list_head *head)
233 unregister_netdevice_queue(dev, head); 213 unregister_netdevice_queue(dev, head);
234} 214}
235 215
236static int rmnet_dev_walk_unreg(struct net_device *rmnet_dev, void *data)
237{
238 struct rmnet_walk_data *d = data;
239 struct rmnet_endpoint *ep;
240 u8 mux_id;
241
242 mux_id = rmnet_vnd_get_mux(rmnet_dev);
243 ep = rmnet_get_endpoint(d->port, mux_id);
244 if (ep) {
245 hlist_del_init_rcu(&ep->hlnode);
246 rmnet_vnd_dellink(mux_id, d->port, ep);
247 kfree(ep);
248 }
249 netdev_upper_dev_unlink(rmnet_dev, d->real_dev);
250 unregister_netdevice_queue(rmnet_dev, d->head);
251
252 return 0;
253}
254
255static void rmnet_force_unassociate_device(struct net_device *dev) 216static void rmnet_force_unassociate_device(struct net_device *dev)
256{ 217{
257 struct net_device *real_dev = dev; 218 struct net_device *real_dev = dev;
258 struct rmnet_walk_data d; 219 struct hlist_node *tmp_ep;
220 struct rmnet_endpoint *ep;
259 struct rmnet_port *port; 221 struct rmnet_port *port;
222 unsigned long bkt_ep;
260 LIST_HEAD(list); 223 LIST_HEAD(list);
261 224
262 if (!rmnet_is_real_dev_registered(real_dev)) 225 if (!rmnet_is_real_dev_registered(real_dev))
@@ -264,16 +227,19 @@ static void rmnet_force_unassociate_device(struct net_device *dev)
264 227
265 ASSERT_RTNL(); 228 ASSERT_RTNL();
266 229
267 d.real_dev = real_dev;
268 d.head = &list;
269
270 port = rmnet_get_port_rtnl(dev); 230 port = rmnet_get_port_rtnl(dev);
271 d.port = port;
272 231
273 rcu_read_lock(); 232 rcu_read_lock();
274 rmnet_unregister_bridge(dev, port); 233 rmnet_unregister_bridge(dev, port);
275 234
276 netdev_walk_all_lower_dev_rcu(real_dev, rmnet_dev_walk_unreg, &d); 235 hash_for_each_safe(port->muxed_ep, bkt_ep, tmp_ep, ep, hlnode) {
236 unregister_netdevice_queue(ep->egress_dev, &list);
237 rmnet_vnd_dellink(ep->mux_id, port, ep);
238
239 hlist_del_init_rcu(&ep->hlnode);
240 kfree(ep);
241 }
242
277 rcu_read_unlock(); 243 rcu_read_unlock();
278 unregister_netdevice_many(&list); 244 unregister_netdevice_many(&list);
279 245
@@ -422,11 +388,6 @@ int rmnet_add_bridge(struct net_device *rmnet_dev,
422 if (err) 388 if (err)
423 return -EBUSY; 389 return -EBUSY;
424 390
425 err = netdev_master_upper_dev_link(slave_dev, rmnet_dev, NULL, NULL,
426 extack);
427 if (err)
428 return -EINVAL;
429
430 slave_port = rmnet_get_port(slave_dev); 391 slave_port = rmnet_get_port(slave_dev);
431 slave_port->rmnet_mode = RMNET_EPMODE_BRIDGE; 392 slave_port->rmnet_mode = RMNET_EPMODE_BRIDGE;
432 slave_port->bridge_ep = real_dev; 393 slave_port->bridge_ep = real_dev;
@@ -449,7 +410,6 @@ int rmnet_del_bridge(struct net_device *rmnet_dev,
449 port->rmnet_mode = RMNET_EPMODE_VND; 410 port->rmnet_mode = RMNET_EPMODE_VND;
450 port->bridge_ep = NULL; 411 port->bridge_ep = NULL;
451 412
452 netdev_upper_dev_unlink(slave_dev, rmnet_dev);
453 slave_port = rmnet_get_port(slave_dev); 413 slave_port = rmnet_get_port(slave_dev);
454 rmnet_unregister_real_device(slave_dev, slave_port); 414 rmnet_unregister_real_device(slave_dev, slave_port);
455 415
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c
index 6bc328fb88e1..b0dbca070c00 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c
@@ -38,6 +38,11 @@ static u8 rmnet_map_do_flow_control(struct sk_buff *skb,
38 } 38 }
39 39
40 ep = rmnet_get_endpoint(port, mux_id); 40 ep = rmnet_get_endpoint(port, mux_id);
41 if (!ep) {
42 kfree_skb(skb);
43 return RX_HANDLER_CONSUMED;
44 }
45
41 vnd = ep->egress_dev; 46 vnd = ep->egress_dev;
42 47
43 ip_family = cmd->flow_control.ip_family; 48 ip_family = cmd->flow_control.ip_family;
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
index 570a227acdd8..346d310914df 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
@@ -121,7 +121,7 @@ static void rmnet_get_stats64(struct net_device *dev,
121 memset(&total_stats, 0, sizeof(struct rmnet_vnd_stats)); 121 memset(&total_stats, 0, sizeof(struct rmnet_vnd_stats));
122 122
123 for_each_possible_cpu(cpu) { 123 for_each_possible_cpu(cpu) {
124 pcpu_ptr = this_cpu_ptr(priv->pcpu_stats); 124 pcpu_ptr = per_cpu_ptr(priv->pcpu_stats, cpu);
125 125
126 do { 126 do {
127 start = u64_stats_fetch_begin_irq(&pcpu_ptr->syncp); 127 start = u64_stats_fetch_begin_irq(&pcpu_ptr->syncp);
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index c87f57ca4437..a95fbd5510d9 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -2255,9 +2255,6 @@ static int ravb_wol_setup(struct net_device *ndev)
2255 /* Enable MagicPacket */ 2255 /* Enable MagicPacket */
2256 ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE); 2256 ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE);
2257 2257
2258 /* Increased clock usage so device won't be suspended */
2259 clk_enable(priv->clk);
2260
2261 return enable_irq_wake(priv->emac_irq); 2258 return enable_irq_wake(priv->emac_irq);
2262} 2259}
2263 2260
@@ -2276,9 +2273,6 @@ static int ravb_wol_restore(struct net_device *ndev)
2276 if (ret < 0) 2273 if (ret < 0)
2277 return ret; 2274 return ret;
2278 2275
2279 /* Restore clock usage count */
2280 clk_disable(priv->clk);
2281
2282 return disable_irq_wake(priv->emac_irq); 2276 return disable_irq_wake(priv->emac_irq);
2283} 2277}
2284 2278
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index a197e11f3a56..14c839bb09e7 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -40,7 +40,6 @@
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/ethtool.h> 41#include <linux/ethtool.h>
42#include <linux/if_vlan.h> 42#include <linux/if_vlan.h>
43#include <linux/clk.h>
44#include <linux/sh_eth.h> 43#include <linux/sh_eth.h>
45#include <linux/of_mdio.h> 44#include <linux/of_mdio.h>
46 45
@@ -440,6 +439,17 @@ static void sh_eth_modify(struct net_device *ndev, int enum_index, u32 clear,
440 enum_index); 439 enum_index);
441} 440}
442 441
442static void sh_eth_tsu_write(struct sh_eth_private *mdp, u32 data,
443 int enum_index)
444{
445 iowrite32(data, mdp->tsu_addr + mdp->reg_offset[enum_index]);
446}
447
448static u32 sh_eth_tsu_read(struct sh_eth_private *mdp, int enum_index)
449{
450 return ioread32(mdp->tsu_addr + mdp->reg_offset[enum_index]);
451}
452
443static bool sh_eth_is_gether(struct sh_eth_private *mdp) 453static bool sh_eth_is_gether(struct sh_eth_private *mdp)
444{ 454{
445 return mdp->reg_offset == sh_eth_offset_gigabit; 455 return mdp->reg_offset == sh_eth_offset_gigabit;
@@ -2304,7 +2314,7 @@ static void sh_eth_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
2304 wol->supported = 0; 2314 wol->supported = 0;
2305 wol->wolopts = 0; 2315 wol->wolopts = 0;
2306 2316
2307 if (mdp->cd->magic && mdp->clk) { 2317 if (mdp->cd->magic) {
2308 wol->supported = WAKE_MAGIC; 2318 wol->supported = WAKE_MAGIC;
2309 wol->wolopts = mdp->wol_enabled ? WAKE_MAGIC : 0; 2319 wol->wolopts = mdp->wol_enabled ? WAKE_MAGIC : 0;
2310 } 2320 }
@@ -2314,7 +2324,7 @@ static int sh_eth_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
2314{ 2324{
2315 struct sh_eth_private *mdp = netdev_priv(ndev); 2325 struct sh_eth_private *mdp = netdev_priv(ndev);
2316 2326
2317 if (!mdp->cd->magic || !mdp->clk || wol->wolopts & ~WAKE_MAGIC) 2327 if (!mdp->cd->magic || wol->wolopts & ~WAKE_MAGIC)
2318 return -EOPNOTSUPP; 2328 return -EOPNOTSUPP;
2319 2329
2320 mdp->wol_enabled = !!(wol->wolopts & WAKE_MAGIC); 2330 mdp->wol_enabled = !!(wol->wolopts & WAKE_MAGIC);
@@ -3153,11 +3163,6 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
3153 goto out_release; 3163 goto out_release;
3154 } 3164 }
3155 3165
3156 /* Get clock, if not found that's OK but Wake-On-Lan is unavailable */
3157 mdp->clk = devm_clk_get(&pdev->dev, NULL);
3158 if (IS_ERR(mdp->clk))
3159 mdp->clk = NULL;
3160
3161 ndev->base_addr = res->start; 3166 ndev->base_addr = res->start;
3162 3167
3163 spin_lock_init(&mdp->lock); 3168 spin_lock_init(&mdp->lock);
@@ -3278,7 +3283,7 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
3278 if (ret) 3283 if (ret)
3279 goto out_napi_del; 3284 goto out_napi_del;
3280 3285
3281 if (mdp->cd->magic && mdp->clk) 3286 if (mdp->cd->magic)
3282 device_set_wakeup_capable(&pdev->dev, 1); 3287 device_set_wakeup_capable(&pdev->dev, 1);
3283 3288
3284 /* print device information */ 3289 /* print device information */
@@ -3331,9 +3336,6 @@ static int sh_eth_wol_setup(struct net_device *ndev)
3331 /* Enable MagicPacket */ 3336 /* Enable MagicPacket */
3332 sh_eth_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE); 3337 sh_eth_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE);
3333 3338
3334 /* Increased clock usage so device won't be suspended */
3335 clk_enable(mdp->clk);
3336
3337 return enable_irq_wake(ndev->irq); 3339 return enable_irq_wake(ndev->irq);
3338} 3340}
3339 3341
@@ -3359,9 +3361,6 @@ static int sh_eth_wol_restore(struct net_device *ndev)
3359 if (ret < 0) 3361 if (ret < 0)
3360 return ret; 3362 return ret;
3361 3363
3362 /* Restore clock usage count */
3363 clk_disable(mdp->clk);
3364
3365 return disable_irq_wake(ndev->irq); 3364 return disable_irq_wake(ndev->irq);
3366} 3365}
3367 3366
diff --git a/drivers/net/ethernet/renesas/sh_eth.h b/drivers/net/ethernet/renesas/sh_eth.h
index a6753ccba711..e5fe70134690 100644
--- a/drivers/net/ethernet/renesas/sh_eth.h
+++ b/drivers/net/ethernet/renesas/sh_eth.h
@@ -567,15 +567,4 @@ static inline void *sh_eth_tsu_get_offset(struct sh_eth_private *mdp,
567 return mdp->tsu_addr + mdp->reg_offset[enum_index]; 567 return mdp->tsu_addr + mdp->reg_offset[enum_index];
568} 568}
569 569
570static inline void sh_eth_tsu_write(struct sh_eth_private *mdp, u32 data,
571 int enum_index)
572{
573 iowrite32(data, mdp->tsu_addr + mdp->reg_offset[enum_index]);
574}
575
576static inline u32 sh_eth_tsu_read(struct sh_eth_private *mdp, int enum_index)
577{
578 return ioread32(mdp->tsu_addr + mdp->reg_offset[enum_index]);
579}
580
581#endif /* #ifndef __SH_ETH_H__ */ 570#endif /* #ifndef __SH_ETH_H__ */
diff --git a/drivers/net/ethernet/smsc/Kconfig b/drivers/net/ethernet/smsc/Kconfig
index 63aca9f847e1..4c2f612e4414 100644
--- a/drivers/net/ethernet/smsc/Kconfig
+++ b/drivers/net/ethernet/smsc/Kconfig
@@ -20,7 +20,7 @@ if NET_VENDOR_SMSC
20 20
21config SMC9194 21config SMC9194
22 tristate "SMC 9194 support" 22 tristate "SMC 9194 support"
23 depends on (ISA || MAC && BROKEN) 23 depends on ISA
24 select CRC32 24 select CRC32
25 ---help--- 25 ---help---
26 This is support for the SMC9xxx based Ethernet cards. Choose this 26 This is support for the SMC9xxx based Ethernet cards. Choose this
diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index 012fb66eed8d..f0afb88d7bc2 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -2335,14 +2335,14 @@ static int smsc911x_drv_remove(struct platform_device *pdev)
2335 pdata = netdev_priv(dev); 2335 pdata = netdev_priv(dev);
2336 BUG_ON(!pdata); 2336 BUG_ON(!pdata);
2337 BUG_ON(!pdata->ioaddr); 2337 BUG_ON(!pdata->ioaddr);
2338 WARN_ON(dev->phydev);
2339 2338
2340 SMSC_TRACE(pdata, ifdown, "Stopping driver"); 2339 SMSC_TRACE(pdata, ifdown, "Stopping driver");
2341 2340
2341 unregister_netdev(dev);
2342
2342 mdiobus_unregister(pdata->mii_bus); 2343 mdiobus_unregister(pdata->mii_bus);
2343 mdiobus_free(pdata->mii_bus); 2344 mdiobus_free(pdata->mii_bus);
2344 2345
2345 unregister_netdev(dev);
2346 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 2346 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2347 "smsc911x-memory"); 2347 "smsc911x-memory");
2348 if (!res) 2348 if (!res)
diff --git a/drivers/net/ethernet/socionext/sni_ave.c b/drivers/net/ethernet/socionext/sni_ave.c
index 111e7ca9df56..f5c5984afefb 100644
--- a/drivers/net/ethernet/socionext/sni_ave.c
+++ b/drivers/net/ethernet/socionext/sni_ave.c
@@ -1295,7 +1295,7 @@ static int ave_open(struct net_device *ndev)
1295 val |= AVE_IIRQC_EN0 | (AVE_INTM_COUNT << 16); 1295 val |= AVE_IIRQC_EN0 | (AVE_INTM_COUNT << 16);
1296 writel(val, priv->base + AVE_IIRQC); 1296 writel(val, priv->base + AVE_IIRQC);
1297 1297
1298 val = AVE_GI_RXIINT | AVE_GI_RXOVF | AVE_GI_TX; 1298 val = AVE_GI_RXIINT | AVE_GI_RXOVF | AVE_GI_TX | AVE_GI_RXDROP;
1299 ave_irq_restore(ndev, val); 1299 ave_irq_restore(ndev, val);
1300 1300
1301 napi_enable(&priv->napi_rx); 1301 napi_enable(&priv->napi_rx);
diff --git a/drivers/net/ethernet/sun/sunvnet.c b/drivers/net/ethernet/sun/sunvnet.c
index 63d3d6b215f3..a94f50442613 100644
--- a/drivers/net/ethernet/sun/sunvnet.c
+++ b/drivers/net/ethernet/sun/sunvnet.c
@@ -312,7 +312,7 @@ static struct vnet *vnet_new(const u64 *local_mac,
312 dev->ethtool_ops = &vnet_ethtool_ops; 312 dev->ethtool_ops = &vnet_ethtool_ops;
313 dev->watchdog_timeo = VNET_TX_TIMEOUT; 313 dev->watchdog_timeo = VNET_TX_TIMEOUT;
314 314
315 dev->hw_features = NETIF_F_TSO | NETIF_F_GSO | NETIF_F_GSO_SOFTWARE | 315 dev->hw_features = NETIF_F_TSO | NETIF_F_GSO | NETIF_F_ALL_TSO |
316 NETIF_F_HW_CSUM | NETIF_F_SG; 316 NETIF_F_HW_CSUM | NETIF_F_SG;
317 dev->features = dev->hw_features; 317 dev->features = dev->hw_features;
318 318
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 1b1b78fdc138..b2b30c9df037 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -1014,7 +1014,8 @@ static void _cpsw_adjust_link(struct cpsw_slave *slave,
1014 /* set speed_in input in case RMII mode is used in 100Mbps */ 1014 /* set speed_in input in case RMII mode is used in 100Mbps */
1015 if (phy->speed == 100) 1015 if (phy->speed == 100)
1016 mac_control |= BIT(15); 1016 mac_control |= BIT(15);
1017 else if (phy->speed == 10) 1017 /* in band mode only works in 10Mbps RGMII mode */
1018 else if ((phy->speed == 10) && phy_interface_is_rgmii(phy))
1018 mac_control |= BIT(18); /* In Band mode */ 1019 mac_control |= BIT(18); /* In Band mode */
1019 1020
1020 if (priv->rx_pause) 1021 if (priv->rx_pause)
diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 0db3bd1ea06f..32861036c3fc 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -173,6 +173,7 @@ struct rndis_device {
173 struct list_head req_list; 173 struct list_head req_list;
174 174
175 struct work_struct mcast_work; 175 struct work_struct mcast_work;
176 u32 filter;
176 177
177 bool link_state; /* 0 - link up, 1 - link down */ 178 bool link_state; /* 0 - link up, 1 - link down */
178 179
@@ -211,7 +212,6 @@ void netvsc_channel_cb(void *context);
211int netvsc_poll(struct napi_struct *napi, int budget); 212int netvsc_poll(struct napi_struct *napi, int budget);
212 213
213void rndis_set_subchannel(struct work_struct *w); 214void rndis_set_subchannel(struct work_struct *w);
214bool rndis_filter_opened(const struct netvsc_device *nvdev);
215int rndis_filter_open(struct netvsc_device *nvdev); 215int rndis_filter_open(struct netvsc_device *nvdev);
216int rndis_filter_close(struct netvsc_device *nvdev); 216int rndis_filter_close(struct netvsc_device *nvdev);
217struct netvsc_device *rndis_filter_device_add(struct hv_device *dev, 217struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 17e529af79dc..7472172823f3 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -90,6 +90,11 @@ static void free_netvsc_device(struct rcu_head *head)
90 = container_of(head, struct netvsc_device, rcu); 90 = container_of(head, struct netvsc_device, rcu);
91 int i; 91 int i;
92 92
93 kfree(nvdev->extension);
94 vfree(nvdev->recv_buf);
95 vfree(nvdev->send_buf);
96 kfree(nvdev->send_section_map);
97
93 for (i = 0; i < VRSS_CHANNEL_MAX; i++) 98 for (i = 0; i < VRSS_CHANNEL_MAX; i++)
94 vfree(nvdev->chan_table[i].mrc.slots); 99 vfree(nvdev->chan_table[i].mrc.slots);
95 100
@@ -211,12 +216,6 @@ static void netvsc_teardown_gpadl(struct hv_device *device,
211 net_device->recv_buf_gpadl_handle = 0; 216 net_device->recv_buf_gpadl_handle = 0;
212 } 217 }
213 218
214 if (net_device->recv_buf) {
215 /* Free up the receive buffer */
216 vfree(net_device->recv_buf);
217 net_device->recv_buf = NULL;
218 }
219
220 if (net_device->send_buf_gpadl_handle) { 219 if (net_device->send_buf_gpadl_handle) {
221 ret = vmbus_teardown_gpadl(device->channel, 220 ret = vmbus_teardown_gpadl(device->channel,
222 net_device->send_buf_gpadl_handle); 221 net_device->send_buf_gpadl_handle);
@@ -231,12 +230,6 @@ static void netvsc_teardown_gpadl(struct hv_device *device,
231 } 230 }
232 net_device->send_buf_gpadl_handle = 0; 231 net_device->send_buf_gpadl_handle = 0;
233 } 232 }
234 if (net_device->send_buf) {
235 /* Free up the send buffer */
236 vfree(net_device->send_buf);
237 net_device->send_buf = NULL;
238 }
239 kfree(net_device->send_section_map);
240} 233}
241 234
242int netvsc_alloc_recv_comp_ring(struct netvsc_device *net_device, u32 q_idx) 235int netvsc_alloc_recv_comp_ring(struct netvsc_device *net_device, u32 q_idx)
@@ -562,26 +555,29 @@ void netvsc_device_remove(struct hv_device *device)
562 = rtnl_dereference(net_device_ctx->nvdev); 555 = rtnl_dereference(net_device_ctx->nvdev);
563 int i; 556 int i;
564 557
565 cancel_work_sync(&net_device->subchan_work);
566
567 netvsc_revoke_buf(device, net_device); 558 netvsc_revoke_buf(device, net_device);
568 559
569 RCU_INIT_POINTER(net_device_ctx->nvdev, NULL); 560 RCU_INIT_POINTER(net_device_ctx->nvdev, NULL);
570 561
562 /* And disassociate NAPI context from device */
563 for (i = 0; i < net_device->num_chn; i++)
564 netif_napi_del(&net_device->chan_table[i].napi);
565
571 /* 566 /*
572 * At this point, no one should be accessing net_device 567 * At this point, no one should be accessing net_device
573 * except in here 568 * except in here
574 */ 569 */
575 netdev_dbg(ndev, "net device safe to remove\n"); 570 netdev_dbg(ndev, "net device safe to remove\n");
576 571
572 /* older versions require that buffer be revoked before close */
573 if (net_device->nvsp_version < NVSP_PROTOCOL_VERSION_4)
574 netvsc_teardown_gpadl(device, net_device);
575
577 /* Now, we can close the channel safely */ 576 /* Now, we can close the channel safely */
578 vmbus_close(device->channel); 577 vmbus_close(device->channel);
579 578
580 netvsc_teardown_gpadl(device, net_device); 579 if (net_device->nvsp_version >= NVSP_PROTOCOL_VERSION_4)
581 580 netvsc_teardown_gpadl(device, net_device);
582 /* And dissassociate NAPI context from device */
583 for (i = 0; i < net_device->num_chn; i++)
584 netif_napi_del(&net_device->chan_table[i].napi);
585 581
586 /* Release all resources */ 582 /* Release all resources */
587 free_netvsc_device_rcu(net_device); 583 free_netvsc_device_rcu(net_device);
@@ -645,14 +641,18 @@ static void netvsc_send_tx_complete(struct netvsc_device *net_device,
645 queue_sends = 641 queue_sends =
646 atomic_dec_return(&net_device->chan_table[q_idx].queue_sends); 642 atomic_dec_return(&net_device->chan_table[q_idx].queue_sends);
647 643
648 if (net_device->destroy && queue_sends == 0) 644 if (unlikely(net_device->destroy)) {
649 wake_up(&net_device->wait_drain); 645 if (queue_sends == 0)
646 wake_up(&net_device->wait_drain);
647 } else {
648 struct netdev_queue *txq = netdev_get_tx_queue(ndev, q_idx);
650 649
651 if (netif_tx_queue_stopped(netdev_get_tx_queue(ndev, q_idx)) && 650 if (netif_tx_queue_stopped(txq) &&
652 (hv_ringbuf_avail_percent(&channel->outbound) > RING_AVAIL_PERCENT_HIWATER || 651 (hv_ringbuf_avail_percent(&channel->outbound) > RING_AVAIL_PERCENT_HIWATER ||
653 queue_sends < 1)) { 652 queue_sends < 1)) {
654 netif_tx_wake_queue(netdev_get_tx_queue(ndev, q_idx)); 653 netif_tx_wake_queue(txq);
655 ndev_ctx->eth_stats.wake_queue++; 654 ndev_ctx->eth_stats.wake_queue++;
655 }
656 } 656 }
657} 657}
658 658
@@ -852,13 +852,6 @@ int netvsc_send(struct net_device *ndev,
852 if (unlikely(!net_device || net_device->destroy)) 852 if (unlikely(!net_device || net_device->destroy))
853 return -ENODEV; 853 return -ENODEV;
854 854
855 /* We may race with netvsc_connect_vsp()/netvsc_init_buf() and get
856 * here before the negotiation with the host is finished and
857 * send_section_map may not be allocated yet.
858 */
859 if (unlikely(!net_device->send_section_map))
860 return -EAGAIN;
861
862 nvchan = &net_device->chan_table[packet->q_idx]; 855 nvchan = &net_device->chan_table[packet->q_idx];
863 packet->send_buf_index = NETVSC_INVALID_INDEX; 856 packet->send_buf_index = NETVSC_INVALID_INDEX;
864 packet->cp_partial = false; 857 packet->cp_partial = false;
@@ -866,10 +859,8 @@ int netvsc_send(struct net_device *ndev,
866 /* Send control message directly without accessing msd (Multi-Send 859 /* Send control message directly without accessing msd (Multi-Send
867 * Data) field which may be changed during data packet processing. 860 * Data) field which may be changed during data packet processing.
868 */ 861 */
869 if (!skb) { 862 if (!skb)
870 cur_send = packet; 863 return netvsc_send_pkt(device, packet, net_device, pb, skb);
871 goto send_now;
872 }
873 864
874 /* batch packets in send buffer if possible */ 865 /* batch packets in send buffer if possible */
875 msdp = &nvchan->msd; 866 msdp = &nvchan->msd;
@@ -953,7 +944,6 @@ int netvsc_send(struct net_device *ndev,
953 } 944 }
954 } 945 }
955 946
956send_now:
957 if (cur_send) 947 if (cur_send)
958 ret = netvsc_send_pkt(device, cur_send, net_device, pb, skb); 948 ret = netvsc_send_pkt(device, cur_send, net_device, pb, skb);
959 949
@@ -1217,9 +1207,10 @@ int netvsc_poll(struct napi_struct *napi, int budget)
1217 if (send_recv_completions(ndev, net_device, nvchan) == 0 && 1207 if (send_recv_completions(ndev, net_device, nvchan) == 0 &&
1218 work_done < budget && 1208 work_done < budget &&
1219 napi_complete_done(napi, work_done) && 1209 napi_complete_done(napi, work_done) &&
1220 hv_end_read(&channel->inbound)) { 1210 hv_end_read(&channel->inbound) &&
1211 napi_schedule_prep(napi)) {
1221 hv_begin_read(&channel->inbound); 1212 hv_begin_read(&channel->inbound);
1222 napi_reschedule(napi); 1213 __napi_schedule(napi);
1223 } 1214 }
1224 1215
1225 /* Driver may overshoot since multiple packets per descriptor */ 1216 /* Driver may overshoot since multiple packets per descriptor */
@@ -1242,7 +1233,7 @@ void netvsc_channel_cb(void *context)
1242 /* disable interupts from host */ 1233 /* disable interupts from host */
1243 hv_begin_read(rbi); 1234 hv_begin_read(rbi);
1244 1235
1245 __napi_schedule(&nvchan->napi); 1236 __napi_schedule_irqoff(&nvchan->napi);
1246 } 1237 }
1247} 1238}
1248 1239
@@ -1296,7 +1287,6 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,
1296 netvsc_channel_cb, net_device->chan_table); 1287 netvsc_channel_cb, net_device->chan_table);
1297 1288
1298 if (ret != 0) { 1289 if (ret != 0) {
1299 netif_napi_del(&net_device->chan_table[0].napi);
1300 netdev_err(ndev, "unable to open channel: %d\n", ret); 1290 netdev_err(ndev, "unable to open channel: %d\n", ret);
1301 goto cleanup; 1291 goto cleanup;
1302 } 1292 }
@@ -1306,11 +1296,6 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,
1306 1296
1307 napi_enable(&net_device->chan_table[0].napi); 1297 napi_enable(&net_device->chan_table[0].napi);
1308 1298
1309 /* Writing nvdev pointer unlocks netvsc_send(), make sure chn_table is
1310 * populated.
1311 */
1312 rcu_assign_pointer(net_device_ctx->nvdev, net_device);
1313
1314 /* Connect with the NetVsp */ 1299 /* Connect with the NetVsp */
1315 ret = netvsc_connect_vsp(device, net_device, device_info); 1300 ret = netvsc_connect_vsp(device, net_device, device_info);
1316 if (ret != 0) { 1301 if (ret != 0) {
@@ -1319,6 +1304,11 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,
1319 goto close; 1304 goto close;
1320 } 1305 }
1321 1306
1307 /* Writing nvdev pointer unlocks netvsc_send(), make sure chn_table is
1308 * populated.
1309 */
1310 rcu_assign_pointer(net_device_ctx->nvdev, net_device);
1311
1322 return net_device; 1312 return net_device;
1323 1313
1324close: 1314close:
@@ -1329,6 +1319,7 @@ close:
1329 vmbus_close(device->channel); 1319 vmbus_close(device->channel);
1330 1320
1331cleanup: 1321cleanup:
1322 netif_napi_del(&net_device->chan_table[0].napi);
1332 free_netvsc_device(&net_device->rcu); 1323 free_netvsc_device(&net_device->rcu);
1333 1324
1334 return ERR_PTR(ret); 1325 return ERR_PTR(ret);
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index c5584c2d440e..f28c85d212ce 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -46,7 +46,10 @@
46 46
47#include "hyperv_net.h" 47#include "hyperv_net.h"
48 48
49#define RING_SIZE_MIN 64 49#define RING_SIZE_MIN 64
50#define RETRY_US_LO 5000
51#define RETRY_US_HI 10000
52#define RETRY_MAX 2000 /* >10 sec */
50 53
51#define LINKCHANGE_INT (2 * HZ) 54#define LINKCHANGE_INT (2 * HZ)
52#define VF_TAKEOVER_INT (HZ / 10) 55#define VF_TAKEOVER_INT (HZ / 10)
@@ -66,12 +69,43 @@ static int debug = -1;
66module_param(debug, int, S_IRUGO); 69module_param(debug, int, S_IRUGO);
67MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 70MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
68 71
69static void netvsc_set_multicast_list(struct net_device *net) 72static void netvsc_change_rx_flags(struct net_device *net, int change)
70{ 73{
71 struct net_device_context *net_device_ctx = netdev_priv(net); 74 struct net_device_context *ndev_ctx = netdev_priv(net);
72 struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev); 75 struct net_device *vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
76 int inc;
77
78 if (!vf_netdev)
79 return;
80
81 if (change & IFF_PROMISC) {
82 inc = (net->flags & IFF_PROMISC) ? 1 : -1;
83 dev_set_promiscuity(vf_netdev, inc);
84 }
85
86 if (change & IFF_ALLMULTI) {
87 inc = (net->flags & IFF_ALLMULTI) ? 1 : -1;
88 dev_set_allmulti(vf_netdev, inc);
89 }
90}
73 91
74 rndis_filter_update(nvdev); 92static void netvsc_set_rx_mode(struct net_device *net)
93{
94 struct net_device_context *ndev_ctx = netdev_priv(net);
95 struct net_device *vf_netdev;
96 struct netvsc_device *nvdev;
97
98 rcu_read_lock();
99 vf_netdev = rcu_dereference(ndev_ctx->vf_netdev);
100 if (vf_netdev) {
101 dev_uc_sync(vf_netdev, net);
102 dev_mc_sync(vf_netdev, net);
103 }
104
105 nvdev = rcu_dereference(ndev_ctx->nvdev);
106 if (nvdev)
107 rndis_filter_update(nvdev);
108 rcu_read_unlock();
75} 109}
76 110
77static int netvsc_open(struct net_device *net) 111static int netvsc_open(struct net_device *net)
@@ -91,10 +125,7 @@ static int netvsc_open(struct net_device *net)
91 return ret; 125 return ret;
92 } 126 }
93 127
94 netif_tx_wake_all_queues(net);
95
96 rdev = nvdev->extension; 128 rdev = nvdev->extension;
97
98 if (!rdev->link_state) 129 if (!rdev->link_state)
99 netif_carrier_on(net); 130 netif_carrier_on(net);
100 131
@@ -112,36 +143,25 @@ static int netvsc_open(struct net_device *net)
112 return 0; 143 return 0;
113} 144}
114 145
115static int netvsc_close(struct net_device *net) 146static int netvsc_wait_until_empty(struct netvsc_device *nvdev)
116{ 147{
117 struct net_device_context *net_device_ctx = netdev_priv(net); 148 unsigned int retry = 0;
118 struct net_device *vf_netdev 149 int i;
119 = rtnl_dereference(net_device_ctx->vf_netdev);
120 struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev);
121 int ret = 0;
122 u32 aread, i, msec = 10, retry = 0, retry_max = 20;
123 struct vmbus_channel *chn;
124
125 netif_tx_disable(net);
126
127 /* No need to close rndis filter if it is removed already */
128 if (!nvdev)
129 goto out;
130
131 ret = rndis_filter_close(nvdev);
132 if (ret != 0) {
133 netdev_err(net, "unable to close device (ret %d).\n", ret);
134 return ret;
135 }
136 150
137 /* Ensure pending bytes in ring are read */ 151 /* Ensure pending bytes in ring are read */
138 while (true) { 152 for (;;) {
139 aread = 0; 153 u32 aread = 0;
154
140 for (i = 0; i < nvdev->num_chn; i++) { 155 for (i = 0; i < nvdev->num_chn; i++) {
141 chn = nvdev->chan_table[i].channel; 156 struct vmbus_channel *chn
157 = nvdev->chan_table[i].channel;
158
142 if (!chn) 159 if (!chn)
143 continue; 160 continue;
144 161
162 /* make sure receive not running now */
163 napi_synchronize(&nvdev->chan_table[i].napi);
164
145 aread = hv_get_bytes_to_read(&chn->inbound); 165 aread = hv_get_bytes_to_read(&chn->inbound);
146 if (aread) 166 if (aread)
147 break; 167 break;
@@ -151,22 +171,40 @@ static int netvsc_close(struct net_device *net)
151 break; 171 break;
152 } 172 }
153 173
154 retry++; 174 if (aread == 0)
155 if (retry > retry_max || aread == 0) 175 return 0;
156 break;
157 176
158 msleep(msec); 177 if (++retry > RETRY_MAX)
178 return -ETIMEDOUT;
159 179
160 if (msec < 1000) 180 usleep_range(RETRY_US_LO, RETRY_US_HI);
161 msec *= 2;
162 } 181 }
182}
163 183
164 if (aread) { 184static int netvsc_close(struct net_device *net)
165 netdev_err(net, "Ring buffer not empty after closing rndis\n"); 185{
166 ret = -ETIMEDOUT; 186 struct net_device_context *net_device_ctx = netdev_priv(net);
187 struct net_device *vf_netdev
188 = rtnl_dereference(net_device_ctx->vf_netdev);
189 struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev);
190 int ret;
191
192 netif_tx_disable(net);
193
194 /* No need to close rndis filter if it is removed already */
195 if (!nvdev)
196 return 0;
197
198 ret = rndis_filter_close(nvdev);
199 if (ret != 0) {
200 netdev_err(net, "unable to close device (ret %d).\n", ret);
201 return ret;
167 } 202 }
168 203
169out: 204 ret = netvsc_wait_until_empty(nvdev);
205 if (ret)
206 netdev_err(net, "Ring buffer not empty after closing rndis\n");
207
170 if (vf_netdev) 208 if (vf_netdev)
171 dev_close(vf_netdev); 209 dev_close(vf_netdev);
172 210
@@ -299,8 +337,19 @@ static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,
299 rcu_read_lock(); 337 rcu_read_lock();
300 vf_netdev = rcu_dereference(ndc->vf_netdev); 338 vf_netdev = rcu_dereference(ndc->vf_netdev);
301 if (vf_netdev) { 339 if (vf_netdev) {
302 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : 0; 340 const struct net_device_ops *vf_ops = vf_netdev->netdev_ops;
303 qdisc_skb_cb(skb)->slave_dev_queue_mapping = skb->queue_mapping; 341
342 if (vf_ops->ndo_select_queue)
343 txq = vf_ops->ndo_select_queue(vf_netdev, skb,
344 accel_priv, fallback);
345 else
346 txq = fallback(vf_netdev, skb);
347
348 /* Record the queue selected by VF so that it can be
349 * used for common case where VF has more queues than
350 * the synthetic device.
351 */
352 qdisc_skb_cb(skb)->slave_dev_queue_mapping = txq;
304 } else { 353 } else {
305 txq = netvsc_pick_tx(ndev, skb); 354 txq = netvsc_pick_tx(ndev, skb);
306 } 355 }
@@ -804,16 +853,81 @@ static void netvsc_get_channels(struct net_device *net,
804 } 853 }
805} 854}
806 855
856static int netvsc_detach(struct net_device *ndev,
857 struct netvsc_device *nvdev)
858{
859 struct net_device_context *ndev_ctx = netdev_priv(ndev);
860 struct hv_device *hdev = ndev_ctx->device_ctx;
861 int ret;
862
863 /* Don't try continuing to try and setup sub channels */
864 if (cancel_work_sync(&nvdev->subchan_work))
865 nvdev->num_chn = 1;
866
867 /* If device was up (receiving) then shutdown */
868 if (netif_running(ndev)) {
869 netif_tx_disable(ndev);
870
871 ret = rndis_filter_close(nvdev);
872 if (ret) {
873 netdev_err(ndev,
874 "unable to close device (ret %d).\n", ret);
875 return ret;
876 }
877
878 ret = netvsc_wait_until_empty(nvdev);
879 if (ret) {
880 netdev_err(ndev,
881 "Ring buffer not empty after closing rndis\n");
882 return ret;
883 }
884 }
885
886 netif_device_detach(ndev);
887
888 rndis_filter_device_remove(hdev, nvdev);
889
890 return 0;
891}
892
893static int netvsc_attach(struct net_device *ndev,
894 struct netvsc_device_info *dev_info)
895{
896 struct net_device_context *ndev_ctx = netdev_priv(ndev);
897 struct hv_device *hdev = ndev_ctx->device_ctx;
898 struct netvsc_device *nvdev;
899 struct rndis_device *rdev;
900 int ret;
901
902 nvdev = rndis_filter_device_add(hdev, dev_info);
903 if (IS_ERR(nvdev))
904 return PTR_ERR(nvdev);
905
906 /* Note: enable and attach happen when sub-channels setup */
907
908 netif_carrier_off(ndev);
909
910 if (netif_running(ndev)) {
911 ret = rndis_filter_open(nvdev);
912 if (ret)
913 return ret;
914
915 rdev = nvdev->extension;
916 if (!rdev->link_state)
917 netif_carrier_on(ndev);
918 }
919
920 return 0;
921}
922
807static int netvsc_set_channels(struct net_device *net, 923static int netvsc_set_channels(struct net_device *net,
808 struct ethtool_channels *channels) 924 struct ethtool_channels *channels)
809{ 925{
810 struct net_device_context *net_device_ctx = netdev_priv(net); 926 struct net_device_context *net_device_ctx = netdev_priv(net);
811 struct hv_device *dev = net_device_ctx->device_ctx;
812 struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev); 927 struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev);
813 unsigned int orig, count = channels->combined_count; 928 unsigned int orig, count = channels->combined_count;
814 struct netvsc_device_info device_info; 929 struct netvsc_device_info device_info;
815 bool was_opened; 930 int ret;
816 int ret = 0;
817 931
818 /* We do not support separate count for rx, tx, or other */ 932 /* We do not support separate count for rx, tx, or other */
819 if (count == 0 || 933 if (count == 0 ||
@@ -830,9 +944,6 @@ static int netvsc_set_channels(struct net_device *net,
830 return -EINVAL; 944 return -EINVAL;
831 945
832 orig = nvdev->num_chn; 946 orig = nvdev->num_chn;
833 was_opened = rndis_filter_opened(nvdev);
834 if (was_opened)
835 rndis_filter_close(nvdev);
836 947
837 memset(&device_info, 0, sizeof(device_info)); 948 memset(&device_info, 0, sizeof(device_info));
838 device_info.num_chn = count; 949 device_info.num_chn = count;
@@ -841,28 +952,17 @@ static int netvsc_set_channels(struct net_device *net,
841 device_info.recv_sections = nvdev->recv_section_cnt; 952 device_info.recv_sections = nvdev->recv_section_cnt;
842 device_info.recv_section_size = nvdev->recv_section_size; 953 device_info.recv_section_size = nvdev->recv_section_size;
843 954
844 rndis_filter_device_remove(dev, nvdev); 955 ret = netvsc_detach(net, nvdev);
956 if (ret)
957 return ret;
845 958
846 nvdev = rndis_filter_device_add(dev, &device_info); 959 ret = netvsc_attach(net, &device_info);
847 if (IS_ERR(nvdev)) { 960 if (ret) {
848 ret = PTR_ERR(nvdev);
849 device_info.num_chn = orig; 961 device_info.num_chn = orig;
850 nvdev = rndis_filter_device_add(dev, &device_info); 962 if (netvsc_attach(net, &device_info))
851 963 netdev_err(net, "restoring channel setting failed\n");
852 if (IS_ERR(nvdev)) {
853 netdev_err(net, "restoring channel setting failed: %ld\n",
854 PTR_ERR(nvdev));
855 return ret;
856 }
857 } 964 }
858 965
859 if (was_opened)
860 rndis_filter_open(nvdev);
861
862 /* We may have missed link change notifications */
863 net_device_ctx->last_reconfig = 0;
864 schedule_delayed_work(&net_device_ctx->dwork, 0);
865
866 return ret; 966 return ret;
867} 967}
868 968
@@ -928,10 +1028,8 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
928 struct net_device_context *ndevctx = netdev_priv(ndev); 1028 struct net_device_context *ndevctx = netdev_priv(ndev);
929 struct net_device *vf_netdev = rtnl_dereference(ndevctx->vf_netdev); 1029 struct net_device *vf_netdev = rtnl_dereference(ndevctx->vf_netdev);
930 struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev); 1030 struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
931 struct hv_device *hdev = ndevctx->device_ctx;
932 int orig_mtu = ndev->mtu; 1031 int orig_mtu = ndev->mtu;
933 struct netvsc_device_info device_info; 1032 struct netvsc_device_info device_info;
934 bool was_opened;
935 int ret = 0; 1033 int ret = 0;
936 1034
937 if (!nvdev || nvdev->destroy) 1035 if (!nvdev || nvdev->destroy)
@@ -944,11 +1042,6 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
944 return ret; 1042 return ret;
945 } 1043 }
946 1044
947 netif_device_detach(ndev);
948 was_opened = rndis_filter_opened(nvdev);
949 if (was_opened)
950 rndis_filter_close(nvdev);
951
952 memset(&device_info, 0, sizeof(device_info)); 1045 memset(&device_info, 0, sizeof(device_info));
953 device_info.num_chn = nvdev->num_chn; 1046 device_info.num_chn = nvdev->num_chn;
954 device_info.send_sections = nvdev->send_section_cnt; 1047 device_info.send_sections = nvdev->send_section_cnt;
@@ -956,35 +1049,27 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
956 device_info.recv_sections = nvdev->recv_section_cnt; 1049 device_info.recv_sections = nvdev->recv_section_cnt;
957 device_info.recv_section_size = nvdev->recv_section_size; 1050 device_info.recv_section_size = nvdev->recv_section_size;
958 1051
959 rndis_filter_device_remove(hdev, nvdev); 1052 ret = netvsc_detach(ndev, nvdev);
1053 if (ret)
1054 goto rollback_vf;
960 1055
961 ndev->mtu = mtu; 1056 ndev->mtu = mtu;
962 1057
963 nvdev = rndis_filter_device_add(hdev, &device_info); 1058 ret = netvsc_attach(ndev, &device_info);
964 if (IS_ERR(nvdev)) { 1059 if (ret)
965 ret = PTR_ERR(nvdev); 1060 goto rollback;
966
967 /* Attempt rollback to original MTU */
968 ndev->mtu = orig_mtu;
969 nvdev = rndis_filter_device_add(hdev, &device_info);
970
971 if (vf_netdev)
972 dev_set_mtu(vf_netdev, orig_mtu);
973
974 if (IS_ERR(nvdev)) {
975 netdev_err(ndev, "restoring mtu failed: %ld\n",
976 PTR_ERR(nvdev));
977 return ret;
978 }
979 }
980 1061
981 if (was_opened) 1062 return 0;
982 rndis_filter_open(nvdev);
983 1063
984 netif_device_attach(ndev); 1064rollback:
1065 /* Attempt rollback to original MTU */
1066 ndev->mtu = orig_mtu;
985 1067
986 /* We may have missed link change notifications */ 1068 if (netvsc_attach(ndev, &device_info))
987 schedule_delayed_work(&ndevctx->dwork, 0); 1069 netdev_err(ndev, "restoring mtu failed\n");
1070rollback_vf:
1071 if (vf_netdev)
1072 dev_set_mtu(vf_netdev, orig_mtu);
988 1073
989 return ret; 1074 return ret;
990} 1075}
@@ -1490,11 +1575,9 @@ static int netvsc_set_ringparam(struct net_device *ndev,
1490{ 1575{
1491 struct net_device_context *ndevctx = netdev_priv(ndev); 1576 struct net_device_context *ndevctx = netdev_priv(ndev);
1492 struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev); 1577 struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
1493 struct hv_device *hdev = ndevctx->device_ctx;
1494 struct netvsc_device_info device_info; 1578 struct netvsc_device_info device_info;
1495 struct ethtool_ringparam orig; 1579 struct ethtool_ringparam orig;
1496 u32 new_tx, new_rx; 1580 u32 new_tx, new_rx;
1497 bool was_opened;
1498 int ret = 0; 1581 int ret = 0;
1499 1582
1500 if (!nvdev || nvdev->destroy) 1583 if (!nvdev || nvdev->destroy)
@@ -1519,34 +1602,18 @@ static int netvsc_set_ringparam(struct net_device *ndev,
1519 device_info.recv_sections = new_rx; 1602 device_info.recv_sections = new_rx;
1520 device_info.recv_section_size = nvdev->recv_section_size; 1603 device_info.recv_section_size = nvdev->recv_section_size;
1521 1604
1522 netif_device_detach(ndev); 1605 ret = netvsc_detach(ndev, nvdev);
1523 was_opened = rndis_filter_opened(nvdev); 1606 if (ret)
1524 if (was_opened) 1607 return ret;
1525 rndis_filter_close(nvdev);
1526
1527 rndis_filter_device_remove(hdev, nvdev);
1528
1529 nvdev = rndis_filter_device_add(hdev, &device_info);
1530 if (IS_ERR(nvdev)) {
1531 ret = PTR_ERR(nvdev);
1532 1608
1609 ret = netvsc_attach(ndev, &device_info);
1610 if (ret) {
1533 device_info.send_sections = orig.tx_pending; 1611 device_info.send_sections = orig.tx_pending;
1534 device_info.recv_sections = orig.rx_pending; 1612 device_info.recv_sections = orig.rx_pending;
1535 nvdev = rndis_filter_device_add(hdev, &device_info);
1536 if (IS_ERR(nvdev)) {
1537 netdev_err(ndev, "restoring ringparam failed: %ld\n",
1538 PTR_ERR(nvdev));
1539 return ret;
1540 }
1541 }
1542 1613
1543 if (was_opened) 1614 if (netvsc_attach(ndev, &device_info))
1544 rndis_filter_open(nvdev); 1615 netdev_err(ndev, "restoring ringparam failed");
1545 netif_device_attach(ndev); 1616 }
1546
1547 /* We may have missed link change notifications */
1548 ndevctx->last_reconfig = 0;
1549 schedule_delayed_work(&ndevctx->dwork, 0);
1550 1617
1551 return ret; 1618 return ret;
1552} 1619}
@@ -1576,7 +1643,8 @@ static const struct net_device_ops device_ops = {
1576 .ndo_open = netvsc_open, 1643 .ndo_open = netvsc_open,
1577 .ndo_stop = netvsc_close, 1644 .ndo_stop = netvsc_close,
1578 .ndo_start_xmit = netvsc_start_xmit, 1645 .ndo_start_xmit = netvsc_start_xmit,
1579 .ndo_set_rx_mode = netvsc_set_multicast_list, 1646 .ndo_change_rx_flags = netvsc_change_rx_flags,
1647 .ndo_set_rx_mode = netvsc_set_rx_mode,
1580 .ndo_change_mtu = netvsc_change_mtu, 1648 .ndo_change_mtu = netvsc_change_mtu,
1581 .ndo_validate_addr = eth_validate_addr, 1649 .ndo_validate_addr = eth_validate_addr,
1582 .ndo_set_mac_address = netvsc_set_mac_addr, 1650 .ndo_set_mac_address = netvsc_set_mac_addr,
@@ -1807,6 +1875,15 @@ static void __netvsc_vf_setup(struct net_device *ndev,
1807 netdev_warn(vf_netdev, 1875 netdev_warn(vf_netdev,
1808 "unable to change mtu to %u\n", ndev->mtu); 1876 "unable to change mtu to %u\n", ndev->mtu);
1809 1877
1878 /* set multicast etc flags on VF */
1879 dev_change_flags(vf_netdev, ndev->flags | IFF_SLAVE);
1880
1881 /* sync address list from ndev to VF */
1882 netif_addr_lock_bh(ndev);
1883 dev_uc_sync(vf_netdev, ndev);
1884 dev_mc_sync(vf_netdev, ndev);
1885 netif_addr_unlock_bh(ndev);
1886
1810 if (netif_running(ndev)) { 1887 if (netif_running(ndev)) {
1811 ret = dev_open(vf_netdev); 1888 ret = dev_open(vf_netdev);
1812 if (ret) 1889 if (ret)
@@ -2021,8 +2098,8 @@ no_net:
2021static int netvsc_remove(struct hv_device *dev) 2098static int netvsc_remove(struct hv_device *dev)
2022{ 2099{
2023 struct net_device_context *ndev_ctx; 2100 struct net_device_context *ndev_ctx;
2024 struct net_device *vf_netdev; 2101 struct net_device *vf_netdev, *net;
2025 struct net_device *net; 2102 struct netvsc_device *nvdev;
2026 2103
2027 net = hv_get_drvdata(dev); 2104 net = hv_get_drvdata(dev);
2028 if (net == NULL) { 2105 if (net == NULL) {
@@ -2032,10 +2109,14 @@ static int netvsc_remove(struct hv_device *dev)
2032 2109
2033 ndev_ctx = netdev_priv(net); 2110 ndev_ctx = netdev_priv(net);
2034 2111
2035 netif_device_detach(net);
2036
2037 cancel_delayed_work_sync(&ndev_ctx->dwork); 2112 cancel_delayed_work_sync(&ndev_ctx->dwork);
2038 2113
2114 rcu_read_lock();
2115 nvdev = rcu_dereference(ndev_ctx->nvdev);
2116
2117 if (nvdev)
2118 cancel_work_sync(&nvdev->subchan_work);
2119
2039 /* 2120 /*
2040 * Call to the vsc driver to let it know that the device is being 2121 * Call to the vsc driver to let it know that the device is being
2041 * removed. Also blocks mtu and channel changes. 2122 * removed. Also blocks mtu and channel changes.
@@ -2045,11 +2126,13 @@ static int netvsc_remove(struct hv_device *dev)
2045 if (vf_netdev) 2126 if (vf_netdev)
2046 netvsc_unregister_vf(vf_netdev); 2127 netvsc_unregister_vf(vf_netdev);
2047 2128
2129 if (nvdev)
2130 rndis_filter_device_remove(dev, nvdev);
2131
2048 unregister_netdevice(net); 2132 unregister_netdevice(net);
2049 2133
2050 rndis_filter_device_remove(dev,
2051 rtnl_dereference(ndev_ctx->nvdev));
2052 rtnl_unlock(); 2134 rtnl_unlock();
2135 rcu_read_unlock();
2053 2136
2054 hv_set_drvdata(dev, NULL); 2137 hv_set_drvdata(dev, NULL);
2055 2138
diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index c3ca191fea7f..a6ec41c399d6 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -264,13 +264,23 @@ static void rndis_set_link_state(struct rndis_device *rdev,
264 } 264 }
265} 265}
266 266
267static void rndis_filter_receive_response(struct rndis_device *dev, 267static void rndis_filter_receive_response(struct net_device *ndev,
268 struct rndis_message *resp) 268 struct netvsc_device *nvdev,
269 const struct rndis_message *resp)
269{ 270{
271 struct rndis_device *dev = nvdev->extension;
270 struct rndis_request *request = NULL; 272 struct rndis_request *request = NULL;
271 bool found = false; 273 bool found = false;
272 unsigned long flags; 274 unsigned long flags;
273 struct net_device *ndev = dev->ndev; 275
276 /* This should never happen, it means control message
277 * response received after device removed.
278 */
279 if (dev->state == RNDIS_DEV_UNINITIALIZED) {
280 netdev_err(ndev,
281 "got rndis message uninitialized\n");
282 return;
283 }
274 284
275 spin_lock_irqsave(&dev->request_lock, flags); 285 spin_lock_irqsave(&dev->request_lock, flags);
276 list_for_each_entry(request, &dev->req_list, list_ent) { 286 list_for_each_entry(request, &dev->req_list, list_ent) {
@@ -352,7 +362,6 @@ static inline void *rndis_get_ppi(struct rndis_packet *rpkt, u32 type)
352 362
353static int rndis_filter_receive_data(struct net_device *ndev, 363static int rndis_filter_receive_data(struct net_device *ndev,
354 struct netvsc_device *nvdev, 364 struct netvsc_device *nvdev,
355 struct rndis_device *dev,
356 struct rndis_message *msg, 365 struct rndis_message *msg,
357 struct vmbus_channel *channel, 366 struct vmbus_channel *channel,
358 void *data, u32 data_buflen) 367 void *data, u32 data_buflen)
@@ -372,7 +381,7 @@ static int rndis_filter_receive_data(struct net_device *ndev,
372 * should be the data packet size plus the trailer padding size 381 * should be the data packet size plus the trailer padding size
373 */ 382 */
374 if (unlikely(data_buflen < rndis_pkt->data_len)) { 383 if (unlikely(data_buflen < rndis_pkt->data_len)) {
375 netdev_err(dev->ndev, "rndis message buffer " 384 netdev_err(ndev, "rndis message buffer "
376 "overflow detected (got %u, min %u)" 385 "overflow detected (got %u, min %u)"
377 "...dropping this message!\n", 386 "...dropping this message!\n",
378 data_buflen, rndis_pkt->data_len); 387 data_buflen, rndis_pkt->data_len);
@@ -400,35 +409,20 @@ int rndis_filter_receive(struct net_device *ndev,
400 void *data, u32 buflen) 409 void *data, u32 buflen)
401{ 410{
402 struct net_device_context *net_device_ctx = netdev_priv(ndev); 411 struct net_device_context *net_device_ctx = netdev_priv(ndev);
403 struct rndis_device *rndis_dev = net_dev->extension;
404 struct rndis_message *rndis_msg = data; 412 struct rndis_message *rndis_msg = data;
405 413
406 /* Make sure the rndis device state is initialized */
407 if (unlikely(!rndis_dev)) {
408 netif_dbg(net_device_ctx, rx_err, ndev,
409 "got rndis message but no rndis device!\n");
410 return NVSP_STAT_FAIL;
411 }
412
413 if (unlikely(rndis_dev->state == RNDIS_DEV_UNINITIALIZED)) {
414 netif_dbg(net_device_ctx, rx_err, ndev,
415 "got rndis message uninitialized\n");
416 return NVSP_STAT_FAIL;
417 }
418
419 if (netif_msg_rx_status(net_device_ctx)) 414 if (netif_msg_rx_status(net_device_ctx))
420 dump_rndis_message(ndev, rndis_msg); 415 dump_rndis_message(ndev, rndis_msg);
421 416
422 switch (rndis_msg->ndis_msg_type) { 417 switch (rndis_msg->ndis_msg_type) {
423 case RNDIS_MSG_PACKET: 418 case RNDIS_MSG_PACKET:
424 return rndis_filter_receive_data(ndev, net_dev, 419 return rndis_filter_receive_data(ndev, net_dev, rndis_msg,
425 rndis_dev, rndis_msg,
426 channel, data, buflen); 420 channel, data, buflen);
427 case RNDIS_MSG_INIT_C: 421 case RNDIS_MSG_INIT_C:
428 case RNDIS_MSG_QUERY_C: 422 case RNDIS_MSG_QUERY_C:
429 case RNDIS_MSG_SET_C: 423 case RNDIS_MSG_SET_C:
430 /* completion msgs */ 424 /* completion msgs */
431 rndis_filter_receive_response(rndis_dev, rndis_msg); 425 rndis_filter_receive_response(ndev, net_dev, rndis_msg);
432 break; 426 break;
433 427
434 case RNDIS_MSG_INDICATE: 428 case RNDIS_MSG_INDICATE:
@@ -825,13 +819,15 @@ static int rndis_filter_set_packet_filter(struct rndis_device *dev,
825 struct rndis_set_request *set; 819 struct rndis_set_request *set;
826 int ret; 820 int ret;
827 821
822 if (dev->filter == new_filter)
823 return 0;
824
828 request = get_rndis_request(dev, RNDIS_MSG_SET, 825 request = get_rndis_request(dev, RNDIS_MSG_SET,
829 RNDIS_MESSAGE_SIZE(struct rndis_set_request) + 826 RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
830 sizeof(u32)); 827 sizeof(u32));
831 if (!request) 828 if (!request)
832 return -ENOMEM; 829 return -ENOMEM;
833 830
834
835 /* Setup the rndis set */ 831 /* Setup the rndis set */
836 set = &request->request_msg.msg.set_req; 832 set = &request->request_msg.msg.set_req;
837 set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER; 833 set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER;
@@ -842,8 +838,10 @@ static int rndis_filter_set_packet_filter(struct rndis_device *dev,
842 &new_filter, sizeof(u32)); 838 &new_filter, sizeof(u32));
843 839
844 ret = rndis_filter_send_request(dev, request); 840 ret = rndis_filter_send_request(dev, request);
845 if (ret == 0) 841 if (ret == 0) {
846 wait_for_completion(&request->wait_event); 842 wait_for_completion(&request->wait_event);
843 dev->filter = new_filter;
844 }
847 845
848 put_rndis_request(dev, request); 846 put_rndis_request(dev, request);
849 847
@@ -854,15 +852,19 @@ static void rndis_set_multicast(struct work_struct *w)
854{ 852{
855 struct rndis_device *rdev 853 struct rndis_device *rdev
856 = container_of(w, struct rndis_device, mcast_work); 854 = container_of(w, struct rndis_device, mcast_work);
855 u32 filter = NDIS_PACKET_TYPE_DIRECTED;
856 unsigned int flags = rdev->ndev->flags;
857 857
858 if (rdev->ndev->flags & IFF_PROMISC) 858 if (flags & IFF_PROMISC) {
859 rndis_filter_set_packet_filter(rdev, 859 filter = NDIS_PACKET_TYPE_PROMISCUOUS;
860 NDIS_PACKET_TYPE_PROMISCUOUS); 860 } else {
861 else 861 if (flags & IFF_ALLMULTI)
862 rndis_filter_set_packet_filter(rdev, 862 filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
863 NDIS_PACKET_TYPE_BROADCAST | 863 if (flags & IFF_BROADCAST)
864 NDIS_PACKET_TYPE_ALL_MULTICAST | 864 filter |= NDIS_PACKET_TYPE_BROADCAST;
865 NDIS_PACKET_TYPE_DIRECTED); 865 }
866
867 rndis_filter_set_packet_filter(rdev, filter);
866} 868}
867 869
868void rndis_filter_update(struct netvsc_device *nvdev) 870void rndis_filter_update(struct netvsc_device *nvdev)
@@ -1116,6 +1118,7 @@ void rndis_set_subchannel(struct work_struct *w)
1116 for (i = 0; i < VRSS_SEND_TAB_SIZE; i++) 1118 for (i = 0; i < VRSS_SEND_TAB_SIZE; i++)
1117 ndev_ctx->tx_table[i] = i % nvdev->num_chn; 1119 ndev_ctx->tx_table[i] = i % nvdev->num_chn;
1118 1120
1121 netif_device_attach(ndev);
1119 rtnl_unlock(); 1122 rtnl_unlock();
1120 return; 1123 return;
1121 1124
@@ -1126,6 +1129,8 @@ failed:
1126 1129
1127 nvdev->max_chn = 1; 1130 nvdev->max_chn = 1;
1128 nvdev->num_chn = 1; 1131 nvdev->num_chn = 1;
1132
1133 netif_device_attach(ndev);
1129unlock: 1134unlock:
1130 rtnl_unlock(); 1135 rtnl_unlock();
1131} 1136}
@@ -1328,6 +1333,10 @@ out:
1328 net_device->num_chn = 1; 1333 net_device->num_chn = 1;
1329 } 1334 }
1330 1335
1336 /* No sub channels, device is ready */
1337 if (net_device->num_chn == 1)
1338 netif_device_attach(net);
1339
1331 return net_device; 1340 return net_device;
1332 1341
1333err_dev_remv: 1342err_dev_remv:
@@ -1346,7 +1355,6 @@ void rndis_filter_device_remove(struct hv_device *dev,
1346 net_dev->extension = NULL; 1355 net_dev->extension = NULL;
1347 1356
1348 netvsc_device_remove(dev); 1357 netvsc_device_remove(dev);
1349 kfree(rndis_dev);
1350} 1358}
1351 1359
1352int rndis_filter_open(struct netvsc_device *nvdev) 1360int rndis_filter_open(struct netvsc_device *nvdev)
@@ -1364,10 +1372,3 @@ int rndis_filter_close(struct netvsc_device *nvdev)
1364 1372
1365 return rndis_filter_close_device(nvdev->extension); 1373 return rndis_filter_close_device(nvdev->extension);
1366} 1374}
1367
1368bool rndis_filter_opened(const struct netvsc_device *nvdev)
1369{
1370 const struct rndis_device *dev = nvdev->extension;
1371
1372 return dev->state == RNDIS_DEV_DATAINITIALIZED;
1373}
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 7de88b33d5b9..9cbb0c8a896a 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -3277,7 +3277,7 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
3277 3277
3278 err = netdev_upper_dev_link(real_dev, dev, extack); 3278 err = netdev_upper_dev_link(real_dev, dev, extack);
3279 if (err < 0) 3279 if (err < 0)
3280 goto unregister; 3280 goto put_dev;
3281 3281
3282 /* need to be already registered so that ->init has run and 3282 /* need to be already registered so that ->init has run and
3283 * the MAC addr is set 3283 * the MAC addr is set
@@ -3316,7 +3316,8 @@ del_dev:
3316 macsec_del_dev(macsec); 3316 macsec_del_dev(macsec);
3317unlink: 3317unlink:
3318 netdev_upper_dev_unlink(real_dev, dev); 3318 netdev_upper_dev_unlink(real_dev, dev);
3319unregister: 3319put_dev:
3320 dev_put(real_dev);
3320 unregister_netdevice(dev); 3321 unregister_netdevice(dev);
3321 return err; 3322 return err;
3322} 3323}
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index a0f2be81d52e..725f4b4afc6d 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -1036,7 +1036,7 @@ static netdev_features_t macvlan_fix_features(struct net_device *dev,
1036 lowerdev_features &= (features | ~NETIF_F_LRO); 1036 lowerdev_features &= (features | ~NETIF_F_LRO);
1037 features = netdev_increment_features(lowerdev_features, features, mask); 1037 features = netdev_increment_features(lowerdev_features, features, mask);
1038 features |= ALWAYS_ON_FEATURES; 1038 features |= ALWAYS_ON_FEATURES;
1039 features &= ~NETIF_F_NETNS_LOCAL; 1039 features &= (ALWAYS_ON_FEATURES | MACVLAN_FEATURES);
1040 1040
1041 return features; 1041 return features;
1042} 1042}
@@ -1451,7 +1451,7 @@ destroy_macvlan_port:
1451 /* the macvlan port may be freed by macvlan_uninit when fail to register. 1451 /* the macvlan port may be freed by macvlan_uninit when fail to register.
1452 * so we destroy the macvlan port only when it's valid. 1452 * so we destroy the macvlan port only when it's valid.
1453 */ 1453 */
1454 if (create && macvlan_port_get_rtnl(dev)) 1454 if (create && macvlan_port_get_rtnl(lowerdev))
1455 macvlan_port_destroy(port->dev); 1455 macvlan_port_destroy(port->dev);
1456 return err; 1456 return err;
1457} 1457}
diff --git a/drivers/net/phy/bcm-phy-lib.c b/drivers/net/phy/bcm-phy-lib.c
index 171010eb4d9c..5ad130c3da43 100644
--- a/drivers/net/phy/bcm-phy-lib.c
+++ b/drivers/net/phy/bcm-phy-lib.c
@@ -341,8 +341,8 @@ void bcm_phy_get_strings(struct phy_device *phydev, u8 *data)
341 unsigned int i; 341 unsigned int i;
342 342
343 for (i = 0; i < ARRAY_SIZE(bcm_phy_hw_stats); i++) 343 for (i = 0; i < ARRAY_SIZE(bcm_phy_hw_stats); i++)
344 memcpy(data + i * ETH_GSTRING_LEN, 344 strlcpy(data + i * ETH_GSTRING_LEN,
345 bcm_phy_hw_stats[i].string, ETH_GSTRING_LEN); 345 bcm_phy_hw_stats[i].string, ETH_GSTRING_LEN);
346} 346}
347EXPORT_SYMBOL_GPL(bcm_phy_get_strings); 347EXPORT_SYMBOL_GPL(bcm_phy_get_strings);
348 348
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 22d9bc9c33a4..0e0978d8a0eb 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -1452,8 +1452,8 @@ static void marvell_get_strings(struct phy_device *phydev, u8 *data)
1452 int i; 1452 int i;
1453 1453
1454 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) { 1454 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) {
1455 memcpy(data + i * ETH_GSTRING_LEN, 1455 strlcpy(data + i * ETH_GSTRING_LEN,
1456 marvell_hw_stats[i].string, ETH_GSTRING_LEN); 1456 marvell_hw_stats[i].string, ETH_GSTRING_LEN);
1457 } 1457 }
1458} 1458}
1459 1459
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 0f45310300f6..f41b224a9cdb 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -635,25 +635,6 @@ static int ksz8873mll_config_aneg(struct phy_device *phydev)
635 return 0; 635 return 0;
636} 636}
637 637
638/* This routine returns -1 as an indication to the caller that the
639 * Micrel ksz9021 10/100/1000 PHY does not support standard IEEE
640 * MMD extended PHY registers.
641 */
642static int
643ksz9021_rd_mmd_phyreg(struct phy_device *phydev, int devad, u16 regnum)
644{
645 return -1;
646}
647
648/* This routine does nothing since the Micrel ksz9021 does not support
649 * standard IEEE MMD extended PHY registers.
650 */
651static int
652ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int devad, u16 regnum, u16 val)
653{
654 return -1;
655}
656
657static int kszphy_get_sset_count(struct phy_device *phydev) 638static int kszphy_get_sset_count(struct phy_device *phydev)
658{ 639{
659 return ARRAY_SIZE(kszphy_hw_stats); 640 return ARRAY_SIZE(kszphy_hw_stats);
@@ -664,8 +645,8 @@ static void kszphy_get_strings(struct phy_device *phydev, u8 *data)
664 int i; 645 int i;
665 646
666 for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) { 647 for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) {
667 memcpy(data + i * ETH_GSTRING_LEN, 648 strlcpy(data + i * ETH_GSTRING_LEN,
668 kszphy_hw_stats[i].string, ETH_GSTRING_LEN); 649 kszphy_hw_stats[i].string, ETH_GSTRING_LEN);
669 } 650 }
670} 651}
671 652
@@ -946,8 +927,8 @@ static struct phy_driver ksphy_driver[] = {
946 .get_stats = kszphy_get_stats, 927 .get_stats = kszphy_get_stats,
947 .suspend = genphy_suspend, 928 .suspend = genphy_suspend,
948 .resume = genphy_resume, 929 .resume = genphy_resume,
949 .read_mmd = ksz9021_rd_mmd_phyreg, 930 .read_mmd = genphy_read_mmd_unsupported,
950 .write_mmd = ksz9021_wr_mmd_phyreg, 931 .write_mmd = genphy_write_mmd_unsupported,
951}, { 932}, {
952 .phy_id = PHY_ID_KSZ9031, 933 .phy_id = PHY_ID_KSZ9031,
953 .phy_id_mask = MICREL_PHY_ID_MASK, 934 .phy_id_mask = MICREL_PHY_ID_MASK,
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e3e29c2b028b..9aabfa1a455a 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -618,6 +618,77 @@ static void phy_error(struct phy_device *phydev)
618} 618}
619 619
620/** 620/**
621 * phy_disable_interrupts - Disable the PHY interrupts from the PHY side
622 * @phydev: target phy_device struct
623 */
624static int phy_disable_interrupts(struct phy_device *phydev)
625{
626 int err;
627
628 /* Disable PHY interrupts */
629 err = phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED);
630 if (err)
631 goto phy_err;
632
633 /* Clear the interrupt */
634 err = phy_clear_interrupt(phydev);
635 if (err)
636 goto phy_err;
637
638 return 0;
639
640phy_err:
641 phy_error(phydev);
642
643 return err;
644}
645
646/**
647 * phy_change - Called by the phy_interrupt to handle PHY changes
648 * @phydev: phy_device struct that interrupted
649 */
650static irqreturn_t phy_change(struct phy_device *phydev)
651{
652 if (phy_interrupt_is_valid(phydev)) {
653 if (phydev->drv->did_interrupt &&
654 !phydev->drv->did_interrupt(phydev))
655 return IRQ_NONE;
656
657 if (phydev->state == PHY_HALTED)
658 if (phy_disable_interrupts(phydev))
659 goto phy_err;
660 }
661
662 mutex_lock(&phydev->lock);
663 if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state))
664 phydev->state = PHY_CHANGELINK;
665 mutex_unlock(&phydev->lock);
666
667 /* reschedule state queue work to run as soon as possible */
668 phy_trigger_machine(phydev, true);
669
670 if (phy_interrupt_is_valid(phydev) && phy_clear_interrupt(phydev))
671 goto phy_err;
672 return IRQ_HANDLED;
673
674phy_err:
675 phy_error(phydev);
676 return IRQ_NONE;
677}
678
679/**
680 * phy_change_work - Scheduled by the phy_mac_interrupt to handle PHY changes
681 * @work: work_struct that describes the work to be done
682 */
683void phy_change_work(struct work_struct *work)
684{
685 struct phy_device *phydev =
686 container_of(work, struct phy_device, phy_queue);
687
688 phy_change(phydev);
689}
690
691/**
621 * phy_interrupt - PHY interrupt handler 692 * phy_interrupt - PHY interrupt handler
622 * @irq: interrupt line 693 * @irq: interrupt line
623 * @phy_dat: phy_device pointer 694 * @phy_dat: phy_device pointer
@@ -632,9 +703,7 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
632 if (PHY_HALTED == phydev->state) 703 if (PHY_HALTED == phydev->state)
633 return IRQ_NONE; /* It can't be ours. */ 704 return IRQ_NONE; /* It can't be ours. */
634 705
635 phy_change(phydev); 706 return phy_change(phydev);
636
637 return IRQ_HANDLED;
638} 707}
639 708
640/** 709/**
@@ -652,32 +721,6 @@ static int phy_enable_interrupts(struct phy_device *phydev)
652} 721}
653 722
654/** 723/**
655 * phy_disable_interrupts - Disable the PHY interrupts from the PHY side
656 * @phydev: target phy_device struct
657 */
658static int phy_disable_interrupts(struct phy_device *phydev)
659{
660 int err;
661
662 /* Disable PHY interrupts */
663 err = phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED);
664 if (err)
665 goto phy_err;
666
667 /* Clear the interrupt */
668 err = phy_clear_interrupt(phydev);
669 if (err)
670 goto phy_err;
671
672 return 0;
673
674phy_err:
675 phy_error(phydev);
676
677 return err;
678}
679
680/**
681 * phy_start_interrupts - request and enable interrupts for a PHY device 724 * phy_start_interrupts - request and enable interrupts for a PHY device
682 * @phydev: target phy_device struct 725 * @phydev: target phy_device struct
683 * 726 *
@@ -720,50 +763,6 @@ int phy_stop_interrupts(struct phy_device *phydev)
720EXPORT_SYMBOL(phy_stop_interrupts); 763EXPORT_SYMBOL(phy_stop_interrupts);
721 764
722/** 765/**
723 * phy_change - Called by the phy_interrupt to handle PHY changes
724 * @phydev: phy_device struct that interrupted
725 */
726void phy_change(struct phy_device *phydev)
727{
728 if (phy_interrupt_is_valid(phydev)) {
729 if (phydev->drv->did_interrupt &&
730 !phydev->drv->did_interrupt(phydev))
731 return;
732
733 if (phydev->state == PHY_HALTED)
734 if (phy_disable_interrupts(phydev))
735 goto phy_err;
736 }
737
738 mutex_lock(&phydev->lock);
739 if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state))
740 phydev->state = PHY_CHANGELINK;
741 mutex_unlock(&phydev->lock);
742
743 /* reschedule state queue work to run as soon as possible */
744 phy_trigger_machine(phydev, true);
745
746 if (phy_interrupt_is_valid(phydev) && phy_clear_interrupt(phydev))
747 goto phy_err;
748 return;
749
750phy_err:
751 phy_error(phydev);
752}
753
754/**
755 * phy_change_work - Scheduled by the phy_mac_interrupt to handle PHY changes
756 * @work: work_struct that describes the work to be done
757 */
758void phy_change_work(struct work_struct *work)
759{
760 struct phy_device *phydev =
761 container_of(work, struct phy_device, phy_queue);
762
763 phy_change(phydev);
764}
765
766/**
767 * phy_stop - Bring down the PHY link, and stop checking the status 766 * phy_stop - Bring down the PHY link, and stop checking the status
768 * @phydev: target phy_device struct 767 * @phydev: target phy_device struct
769 */ 768 */
@@ -819,7 +818,7 @@ void phy_start(struct phy_device *phydev)
819 break; 818 break;
820 case PHY_HALTED: 819 case PHY_HALTED:
821 /* if phy was suspended, bring the physical link up again */ 820 /* if phy was suspended, bring the physical link up again */
822 phy_resume(phydev); 821 __phy_resume(phydev);
823 822
824 /* make sure interrupts are re-enabled for the PHY */ 823 /* make sure interrupts are re-enabled for the PHY */
825 if (phy_interrupt_is_valid(phydev)) { 824 if (phy_interrupt_is_valid(phydev)) {
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index b13eed21c87d..74664a6c0cdc 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -135,9 +135,7 @@ static int mdio_bus_phy_resume(struct device *dev)
135 if (!mdio_bus_phy_may_suspend(phydev)) 135 if (!mdio_bus_phy_may_suspend(phydev))
136 goto no_resume; 136 goto no_resume;
137 137
138 mutex_lock(&phydev->lock);
139 ret = phy_resume(phydev); 138 ret = phy_resume(phydev);
140 mutex_unlock(&phydev->lock);
141 if (ret < 0) 139 if (ret < 0)
142 return ret; 140 return ret;
143 141
@@ -1014,10 +1012,17 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
1014 err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj, 1012 err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj,
1015 "attached_dev"); 1013 "attached_dev");
1016 if (!err) { 1014 if (!err) {
1017 err = sysfs_create_link(&dev->dev.kobj, &phydev->mdio.dev.kobj, 1015 err = sysfs_create_link_nowarn(&dev->dev.kobj,
1018 "phydev"); 1016 &phydev->mdio.dev.kobj,
1019 if (err) 1017 "phydev");
1020 goto error; 1018 if (err) {
1019 dev_err(&dev->dev, "could not add device link to %s err %d\n",
1020 kobject_name(&phydev->mdio.dev.kobj),
1021 err);
1022 /* non-fatal - some net drivers can use one netdevice
1023 * with more then one phy
1024 */
1025 }
1021 1026
1022 phydev->sysfs_links = true; 1027 phydev->sysfs_links = true;
1023 } 1028 }
@@ -1041,9 +1046,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
1041 if (err) 1046 if (err)
1042 goto error; 1047 goto error;
1043 1048
1044 mutex_lock(&phydev->lock);
1045 phy_resume(phydev); 1049 phy_resume(phydev);
1046 mutex_unlock(&phydev->lock);
1047 phy_led_triggers_register(phydev); 1050 phy_led_triggers_register(phydev);
1048 1051
1049 return err; 1052 return err;
@@ -1172,7 +1175,7 @@ int phy_suspend(struct phy_device *phydev)
1172} 1175}
1173EXPORT_SYMBOL(phy_suspend); 1176EXPORT_SYMBOL(phy_suspend);
1174 1177
1175int phy_resume(struct phy_device *phydev) 1178int __phy_resume(struct phy_device *phydev)
1176{ 1179{
1177 struct phy_driver *phydrv = to_phy_driver(phydev->mdio.dev.driver); 1180 struct phy_driver *phydrv = to_phy_driver(phydev->mdio.dev.driver);
1178 int ret = 0; 1181 int ret = 0;
@@ -1189,6 +1192,18 @@ int phy_resume(struct phy_device *phydev)
1189 1192
1190 return ret; 1193 return ret;
1191} 1194}
1195EXPORT_SYMBOL(__phy_resume);
1196
1197int phy_resume(struct phy_device *phydev)
1198{
1199 int ret;
1200
1201 mutex_lock(&phydev->lock);
1202 ret = __phy_resume(phydev);
1203 mutex_unlock(&phydev->lock);
1204
1205 return ret;
1206}
1192EXPORT_SYMBOL(phy_resume); 1207EXPORT_SYMBOL(phy_resume);
1193 1208
1194int phy_loopback(struct phy_device *phydev, bool enable) 1209int phy_loopback(struct phy_device *phydev, bool enable)
@@ -1382,7 +1397,7 @@ int genphy_setup_forced(struct phy_device *phydev)
1382 ctl |= BMCR_FULLDPLX; 1397 ctl |= BMCR_FULLDPLX;
1383 1398
1384 return phy_modify(phydev, MII_BMCR, 1399 return phy_modify(phydev, MII_BMCR,
1385 BMCR_LOOPBACK | BMCR_ISOLATE | BMCR_PDOWN, ctl); 1400 ~(BMCR_LOOPBACK | BMCR_ISOLATE | BMCR_PDOWN), ctl);
1386} 1401}
1387EXPORT_SYMBOL(genphy_setup_forced); 1402EXPORT_SYMBOL(genphy_setup_forced);
1388 1403
@@ -1658,6 +1673,23 @@ int genphy_config_init(struct phy_device *phydev)
1658} 1673}
1659EXPORT_SYMBOL(genphy_config_init); 1674EXPORT_SYMBOL(genphy_config_init);
1660 1675
1676/* This is used for the phy device which doesn't support the MMD extended
1677 * register access, but it does have side effect when we are trying to access
1678 * the MMD register via indirect method.
1679 */
1680int genphy_read_mmd_unsupported(struct phy_device *phdev, int devad, u16 regnum)
1681{
1682 return -EOPNOTSUPP;
1683}
1684EXPORT_SYMBOL(genphy_read_mmd_unsupported);
1685
1686int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum,
1687 u16 regnum, u16 val)
1688{
1689 return -EOPNOTSUPP;
1690}
1691EXPORT_SYMBOL(genphy_write_mmd_unsupported);
1692
1661int genphy_suspend(struct phy_device *phydev) 1693int genphy_suspend(struct phy_device *phydev)
1662{ 1694{
1663 return phy_set_bits(phydev, MII_BMCR, BMCR_PDOWN); 1695 return phy_set_bits(phydev, MII_BMCR, BMCR_PDOWN);
diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index ee3ca4a2f12b..9f48ecf9c627 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -172,6 +172,8 @@ static struct phy_driver realtek_drvs[] = {
172 .flags = PHY_HAS_INTERRUPT, 172 .flags = PHY_HAS_INTERRUPT,
173 .ack_interrupt = &rtl821x_ack_interrupt, 173 .ack_interrupt = &rtl821x_ack_interrupt,
174 .config_intr = &rtl8211b_config_intr, 174 .config_intr = &rtl8211b_config_intr,
175 .read_mmd = &genphy_read_mmd_unsupported,
176 .write_mmd = &genphy_write_mmd_unsupported,
175 }, { 177 }, {
176 .phy_id = 0x001cc914, 178 .phy_id = 0x001cc914,
177 .name = "RTL8211DN Gigabit Ethernet", 179 .name = "RTL8211DN Gigabit Ethernet",
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index 255a5def56e9..da1937832c99 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -257,7 +257,7 @@ struct ppp_net {
257/* Prototypes. */ 257/* Prototypes. */
258static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf, 258static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf,
259 struct file *file, unsigned int cmd, unsigned long arg); 259 struct file *file, unsigned int cmd, unsigned long arg);
260static void ppp_xmit_process(struct ppp *ppp); 260static void ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb);
261static void ppp_send_frame(struct ppp *ppp, struct sk_buff *skb); 261static void ppp_send_frame(struct ppp *ppp, struct sk_buff *skb);
262static void ppp_push(struct ppp *ppp); 262static void ppp_push(struct ppp *ppp);
263static void ppp_channel_push(struct channel *pch); 263static void ppp_channel_push(struct channel *pch);
@@ -513,13 +513,12 @@ static ssize_t ppp_write(struct file *file, const char __user *buf,
513 goto out; 513 goto out;
514 } 514 }
515 515
516 skb_queue_tail(&pf->xq, skb);
517
518 switch (pf->kind) { 516 switch (pf->kind) {
519 case INTERFACE: 517 case INTERFACE:
520 ppp_xmit_process(PF_TO_PPP(pf)); 518 ppp_xmit_process(PF_TO_PPP(pf), skb);
521 break; 519 break;
522 case CHANNEL: 520 case CHANNEL:
521 skb_queue_tail(&pf->xq, skb);
523 ppp_channel_push(PF_TO_CHANNEL(pf)); 522 ppp_channel_push(PF_TO_CHANNEL(pf));
524 break; 523 break;
525 } 524 }
@@ -1267,8 +1266,8 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
1267 put_unaligned_be16(proto, pp); 1266 put_unaligned_be16(proto, pp);
1268 1267
1269 skb_scrub_packet(skb, !net_eq(ppp->ppp_net, dev_net(dev))); 1268 skb_scrub_packet(skb, !net_eq(ppp->ppp_net, dev_net(dev)));
1270 skb_queue_tail(&ppp->file.xq, skb); 1269 ppp_xmit_process(ppp, skb);
1271 ppp_xmit_process(ppp); 1270
1272 return NETDEV_TX_OK; 1271 return NETDEV_TX_OK;
1273 1272
1274 outf: 1273 outf:
@@ -1420,13 +1419,14 @@ static void ppp_setup(struct net_device *dev)
1420 */ 1419 */
1421 1420
1422/* Called to do any work queued up on the transmit side that can now be done */ 1421/* Called to do any work queued up on the transmit side that can now be done */
1423static void __ppp_xmit_process(struct ppp *ppp) 1422static void __ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb)
1424{ 1423{
1425 struct sk_buff *skb;
1426
1427 ppp_xmit_lock(ppp); 1424 ppp_xmit_lock(ppp);
1428 if (!ppp->closing) { 1425 if (!ppp->closing) {
1429 ppp_push(ppp); 1426 ppp_push(ppp);
1427
1428 if (skb)
1429 skb_queue_tail(&ppp->file.xq, skb);
1430 while (!ppp->xmit_pending && 1430 while (!ppp->xmit_pending &&
1431 (skb = skb_dequeue(&ppp->file.xq))) 1431 (skb = skb_dequeue(&ppp->file.xq)))
1432 ppp_send_frame(ppp, skb); 1432 ppp_send_frame(ppp, skb);
@@ -1440,7 +1440,7 @@ static void __ppp_xmit_process(struct ppp *ppp)
1440 ppp_xmit_unlock(ppp); 1440 ppp_xmit_unlock(ppp);
1441} 1441}
1442 1442
1443static void ppp_xmit_process(struct ppp *ppp) 1443static void ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb)
1444{ 1444{
1445 local_bh_disable(); 1445 local_bh_disable();
1446 1446
@@ -1448,7 +1448,7 @@ static void ppp_xmit_process(struct ppp *ppp)
1448 goto err; 1448 goto err;
1449 1449
1450 (*this_cpu_ptr(ppp->xmit_recursion))++; 1450 (*this_cpu_ptr(ppp->xmit_recursion))++;
1451 __ppp_xmit_process(ppp); 1451 __ppp_xmit_process(ppp, skb);
1452 (*this_cpu_ptr(ppp->xmit_recursion))--; 1452 (*this_cpu_ptr(ppp->xmit_recursion))--;
1453 1453
1454 local_bh_enable(); 1454 local_bh_enable();
@@ -1458,6 +1458,8 @@ static void ppp_xmit_process(struct ppp *ppp)
1458err: 1458err:
1459 local_bh_enable(); 1459 local_bh_enable();
1460 1460
1461 kfree_skb(skb);
1462
1461 if (net_ratelimit()) 1463 if (net_ratelimit())
1462 netdev_err(ppp->dev, "recursion detected\n"); 1464 netdev_err(ppp->dev, "recursion detected\n");
1463} 1465}
@@ -1942,7 +1944,7 @@ static void __ppp_channel_push(struct channel *pch)
1942 if (skb_queue_empty(&pch->file.xq)) { 1944 if (skb_queue_empty(&pch->file.xq)) {
1943 ppp = pch->ppp; 1945 ppp = pch->ppp;
1944 if (ppp) 1946 if (ppp)
1945 __ppp_xmit_process(ppp); 1947 __ppp_xmit_process(ppp, NULL);
1946 } 1948 }
1947} 1949}
1948 1950
@@ -3161,6 +3163,15 @@ ppp_connect_channel(struct channel *pch, int unit)
3161 goto outl; 3163 goto outl;
3162 3164
3163 ppp_lock(ppp); 3165 ppp_lock(ppp);
3166 spin_lock_bh(&pch->downl);
3167 if (!pch->chan) {
3168 /* Don't connect unregistered channels */
3169 spin_unlock_bh(&pch->downl);
3170 ppp_unlock(ppp);
3171 ret = -ENOTCONN;
3172 goto outl;
3173 }
3174 spin_unlock_bh(&pch->downl);
3164 if (pch->file.hdrlen > ppp->file.hdrlen) 3175 if (pch->file.hdrlen > ppp->file.hdrlen)
3165 ppp->file.hdrlen = pch->file.hdrlen; 3176 ppp->file.hdrlen = pch->file.hdrlen;
3166 hdrlen = pch->file.hdrlen + 2; /* for protocol bytes */ 3177 hdrlen = pch->file.hdrlen + 2; /* for protocol bytes */
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index a468439969df..56c701b73c12 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -2395,7 +2395,7 @@ send_done:
2395 if (!nlh) { 2395 if (!nlh) {
2396 err = __send_and_alloc_skb(&skb, team, portid, send_func); 2396 err = __send_and_alloc_skb(&skb, team, portid, send_func);
2397 if (err) 2397 if (err)
2398 goto errout; 2398 return err;
2399 goto send_done; 2399 goto send_done;
2400 } 2400 }
2401 2401
@@ -2681,7 +2681,7 @@ send_done:
2681 if (!nlh) { 2681 if (!nlh) {
2682 err = __send_and_alloc_skb(&skb, team, portid, send_func); 2682 err = __send_and_alloc_skb(&skb, team, portid, send_func);
2683 if (err) 2683 if (err)
2684 goto errout; 2684 return err;
2685 goto send_done; 2685 goto send_done;
2686 } 2686 }
2687 2687
diff --git a/drivers/net/thunderbolt.c b/drivers/net/thunderbolt.c
index ca5e375de27c..e0d6760f3219 100644
--- a/drivers/net/thunderbolt.c
+++ b/drivers/net/thunderbolt.c
@@ -166,6 +166,8 @@ struct tbnet_ring {
166 * @connected_work: Worker that finalizes the ThunderboltIP connection 166 * @connected_work: Worker that finalizes the ThunderboltIP connection
167 * setup and enables DMA paths for high speed data 167 * setup and enables DMA paths for high speed data
168 * transfers 168 * transfers
169 * @disconnect_work: Worker that handles tearing down the ThunderboltIP
170 * connection
169 * @rx_hdr: Copy of the currently processed Rx frame. Used when a 171 * @rx_hdr: Copy of the currently processed Rx frame. Used when a
170 * network packet consists of multiple Thunderbolt frames. 172 * network packet consists of multiple Thunderbolt frames.
171 * In host byte order. 173 * In host byte order.
@@ -190,6 +192,7 @@ struct tbnet {
190 int login_retries; 192 int login_retries;
191 struct delayed_work login_work; 193 struct delayed_work login_work;
192 struct work_struct connected_work; 194 struct work_struct connected_work;
195 struct work_struct disconnect_work;
193 struct thunderbolt_ip_frame_header rx_hdr; 196 struct thunderbolt_ip_frame_header rx_hdr;
194 struct tbnet_ring rx_ring; 197 struct tbnet_ring rx_ring;
195 atomic_t frame_id; 198 atomic_t frame_id;
@@ -445,7 +448,7 @@ static int tbnet_handle_packet(const void *buf, size_t size, void *data)
445 case TBIP_LOGOUT: 448 case TBIP_LOGOUT:
446 ret = tbnet_logout_response(net, route, sequence, command_id); 449 ret = tbnet_logout_response(net, route, sequence, command_id);
447 if (!ret) 450 if (!ret)
448 tbnet_tear_down(net, false); 451 queue_work(system_long_wq, &net->disconnect_work);
449 break; 452 break;
450 453
451 default: 454 default:
@@ -659,6 +662,13 @@ static void tbnet_login_work(struct work_struct *work)
659 } 662 }
660} 663}
661 664
665static void tbnet_disconnect_work(struct work_struct *work)
666{
667 struct tbnet *net = container_of(work, typeof(*net), disconnect_work);
668
669 tbnet_tear_down(net, false);
670}
671
662static bool tbnet_check_frame(struct tbnet *net, const struct tbnet_frame *tf, 672static bool tbnet_check_frame(struct tbnet *net, const struct tbnet_frame *tf,
663 const struct thunderbolt_ip_frame_header *hdr) 673 const struct thunderbolt_ip_frame_header *hdr)
664{ 674{
@@ -881,6 +891,7 @@ static int tbnet_stop(struct net_device *dev)
881 891
882 napi_disable(&net->napi); 892 napi_disable(&net->napi);
883 893
894 cancel_work_sync(&net->disconnect_work);
884 tbnet_tear_down(net, true); 895 tbnet_tear_down(net, true);
885 896
886 tb_ring_free(net->rx_ring.ring); 897 tb_ring_free(net->rx_ring.ring);
@@ -1195,6 +1206,7 @@ static int tbnet_probe(struct tb_service *svc, const struct tb_service_id *id)
1195 net = netdev_priv(dev); 1206 net = netdev_priv(dev);
1196 INIT_DELAYED_WORK(&net->login_work, tbnet_login_work); 1207 INIT_DELAYED_WORK(&net->login_work, tbnet_login_work);
1197 INIT_WORK(&net->connected_work, tbnet_connected_work); 1208 INIT_WORK(&net->connected_work, tbnet_connected_work);
1209 INIT_WORK(&net->disconnect_work, tbnet_disconnect_work);
1198 mutex_init(&net->connection_lock); 1210 mutex_init(&net->connection_lock);
1199 atomic_set(&net->command_id, 0); 1211 atomic_set(&net->command_id, 0);
1200 atomic_set(&net->frame_id, 0); 1212 atomic_set(&net->frame_id, 0);
@@ -1270,10 +1282,7 @@ static int __maybe_unused tbnet_suspend(struct device *dev)
1270 stop_login(net); 1282 stop_login(net);
1271 if (netif_running(net->dev)) { 1283 if (netif_running(net->dev)) {
1272 netif_device_detach(net->dev); 1284 netif_device_detach(net->dev);
1273 tb_ring_stop(net->rx_ring.ring); 1285 tbnet_tear_down(net, true);
1274 tb_ring_stop(net->tx_ring.ring);
1275 tbnet_free_buffers(&net->rx_ring);
1276 tbnet_free_buffers(&net->tx_ring);
1277 } 1286 }
1278 1287
1279 return 0; 1288 return 0;
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 81e6cc951e7f..28cfa642e39a 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -181,7 +181,6 @@ struct tun_file {
181 struct tun_struct *detached; 181 struct tun_struct *detached;
182 struct ptr_ring tx_ring; 182 struct ptr_ring tx_ring;
183 struct xdp_rxq_info xdp_rxq; 183 struct xdp_rxq_info xdp_rxq;
184 int xdp_pending_pkts;
185}; 184};
186 185
187struct tun_flow_entry { 186struct tun_flow_entry {
@@ -656,7 +655,7 @@ static struct tun_struct *tun_enable_queue(struct tun_file *tfile)
656 return tun; 655 return tun;
657} 656}
658 657
659static void tun_ptr_free(void *ptr) 658void tun_ptr_free(void *ptr)
660{ 659{
661 if (!ptr) 660 if (!ptr)
662 return; 661 return;
@@ -668,6 +667,7 @@ static void tun_ptr_free(void *ptr)
668 __skb_array_destroy_skb(ptr); 667 __skb_array_destroy_skb(ptr);
669 } 668 }
670} 669}
670EXPORT_SYMBOL_GPL(tun_ptr_free);
671 671
672static void tun_queue_purge(struct tun_file *tfile) 672static void tun_queue_purge(struct tun_file *tfile)
673{ 673{
@@ -1489,27 +1489,23 @@ static struct sk_buff *tun_napi_alloc_frags(struct tun_file *tfile,
1489 skb->truesize += skb->data_len; 1489 skb->truesize += skb->data_len;
1490 1490
1491 for (i = 1; i < it->nr_segs; i++) { 1491 for (i = 1; i < it->nr_segs; i++) {
1492 struct page_frag *pfrag = &current->task_frag;
1492 size_t fragsz = it->iov[i].iov_len; 1493 size_t fragsz = it->iov[i].iov_len;
1493 unsigned long offset;
1494 struct page *page;
1495 void *data;
1496 1494
1497 if (fragsz == 0 || fragsz > PAGE_SIZE) { 1495 if (fragsz == 0 || fragsz > PAGE_SIZE) {
1498 err = -EINVAL; 1496 err = -EINVAL;
1499 goto free; 1497 goto free;
1500 } 1498 }
1501 1499
1502 local_bh_disable(); 1500 if (!skb_page_frag_refill(fragsz, pfrag, GFP_KERNEL)) {
1503 data = napi_alloc_frag(fragsz);
1504 local_bh_enable();
1505 if (!data) {
1506 err = -ENOMEM; 1501 err = -ENOMEM;
1507 goto free; 1502 goto free;
1508 } 1503 }
1509 1504
1510 page = virt_to_head_page(data); 1505 skb_fill_page_desc(skb, i - 1, pfrag->page,
1511 offset = data - page_address(page); 1506 pfrag->offset, fragsz);
1512 skb_fill_page_desc(skb, i - 1, page, offset, fragsz); 1507 page_ref_inc(pfrag->page);
1508 pfrag->offset += fragsz;
1513 } 1509 }
1514 1510
1515 return skb; 1511 return skb;
@@ -1647,6 +1643,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
1647 else 1643 else
1648 *skb_xdp = 0; 1644 *skb_xdp = 0;
1649 1645
1646 preempt_disable();
1650 rcu_read_lock(); 1647 rcu_read_lock();
1651 xdp_prog = rcu_dereference(tun->xdp_prog); 1648 xdp_prog = rcu_dereference(tun->xdp_prog);
1652 if (xdp_prog && !*skb_xdp) { 1649 if (xdp_prog && !*skb_xdp) {
@@ -1666,11 +1663,12 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
1666 case XDP_REDIRECT: 1663 case XDP_REDIRECT:
1667 get_page(alloc_frag->page); 1664 get_page(alloc_frag->page);
1668 alloc_frag->offset += buflen; 1665 alloc_frag->offset += buflen;
1669 ++tfile->xdp_pending_pkts;
1670 err = xdp_do_redirect(tun->dev, &xdp, xdp_prog); 1666 err = xdp_do_redirect(tun->dev, &xdp, xdp_prog);
1667 xdp_do_flush_map();
1671 if (err) 1668 if (err)
1672 goto err_redirect; 1669 goto err_redirect;
1673 rcu_read_unlock(); 1670 rcu_read_unlock();
1671 preempt_enable();
1674 return NULL; 1672 return NULL;
1675 case XDP_TX: 1673 case XDP_TX:
1676 xdp_xmit = true; 1674 xdp_xmit = true;
@@ -1692,6 +1690,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
1692 skb = build_skb(buf, buflen); 1690 skb = build_skb(buf, buflen);
1693 if (!skb) { 1691 if (!skb) {
1694 rcu_read_unlock(); 1692 rcu_read_unlock();
1693 preempt_enable();
1695 return ERR_PTR(-ENOMEM); 1694 return ERR_PTR(-ENOMEM);
1696 } 1695 }
1697 1696
@@ -1704,10 +1703,12 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
1704 skb->dev = tun->dev; 1703 skb->dev = tun->dev;
1705 generic_xdp_tx(skb, xdp_prog); 1704 generic_xdp_tx(skb, xdp_prog);
1706 rcu_read_unlock(); 1705 rcu_read_unlock();
1706 preempt_enable();
1707 return NULL; 1707 return NULL;
1708 } 1708 }
1709 1709
1710 rcu_read_unlock(); 1710 rcu_read_unlock();
1711 preempt_enable();
1711 1712
1712 return skb; 1713 return skb;
1713 1714
@@ -1715,6 +1716,7 @@ err_redirect:
1715 put_page(alloc_frag->page); 1716 put_page(alloc_frag->page);
1716err_xdp: 1717err_xdp:
1717 rcu_read_unlock(); 1718 rcu_read_unlock();
1719 preempt_enable();
1718 this_cpu_inc(tun->pcpu_stats->rx_dropped); 1720 this_cpu_inc(tun->pcpu_stats->rx_dropped);
1719 return NULL; 1721 return NULL;
1720} 1722}
@@ -1988,11 +1990,6 @@ static ssize_t tun_chr_write_iter(struct kiocb *iocb, struct iov_iter *from)
1988 result = tun_get_user(tun, tfile, NULL, from, 1990 result = tun_get_user(tun, tfile, NULL, from,
1989 file->f_flags & O_NONBLOCK, false); 1991 file->f_flags & O_NONBLOCK, false);
1990 1992
1991 if (tfile->xdp_pending_pkts) {
1992 tfile->xdp_pending_pkts = 0;
1993 xdp_do_flush_map();
1994 }
1995
1996 tun_put(tun); 1993 tun_put(tun);
1997 return result; 1994 return result;
1998} 1995}
@@ -2329,13 +2326,6 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
2329 ret = tun_get_user(tun, tfile, m->msg_control, &m->msg_iter, 2326 ret = tun_get_user(tun, tfile, m->msg_control, &m->msg_iter,
2330 m->msg_flags & MSG_DONTWAIT, 2327 m->msg_flags & MSG_DONTWAIT,
2331 m->msg_flags & MSG_MORE); 2328 m->msg_flags & MSG_MORE);
2332
2333 if (tfile->xdp_pending_pkts >= NAPI_POLL_WEIGHT ||
2334 !(m->msg_flags & MSG_MORE)) {
2335 tfile->xdp_pending_pkts = 0;
2336 xdp_do_flush_map();
2337 }
2338
2339 tun_put(tun); 2329 tun_put(tun);
2340 return ret; 2330 return ret;
2341} 2331}
@@ -3167,7 +3157,6 @@ static int tun_chr_open(struct inode *inode, struct file * file)
3167 sock_set_flag(&tfile->sk, SOCK_ZEROCOPY); 3157 sock_set_flag(&tfile->sk, SOCK_ZEROCOPY);
3168 3158
3169 memset(&tfile->tx_ring, 0, sizeof(tfile->tx_ring)); 3159 memset(&tfile->tx_ring, 0, sizeof(tfile->tx_ring));
3170 tfile->xdp_pending_pkts = 0;
3171 3160
3172 return 0; 3161 return 0;
3173} 3162}
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 05dca3e5c93d..fff4b13eece2 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -896,6 +896,12 @@ static const struct usb_device_id products[] = {
896 USB_CDC_PROTO_NONE), 896 USB_CDC_PROTO_NONE),
897 .driver_info = (unsigned long)&wwan_info, 897 .driver_info = (unsigned long)&wwan_info,
898}, { 898}, {
899 /* Cinterion PLS8 modem by GEMALTO */
900 USB_DEVICE_AND_INTERFACE_INFO(0x1e2d, 0x0061, USB_CLASS_COMM,
901 USB_CDC_SUBCLASS_ETHERNET,
902 USB_CDC_PROTO_NONE),
903 .driver_info = (unsigned long)&wwan_info,
904}, {
899 USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET, 905 USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
900 USB_CDC_PROTO_NONE), 906 USB_CDC_PROTO_NONE),
901 .driver_info = (unsigned long) &cdc_info, 907 .driver_info = (unsigned long) &cdc_info,
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 958b2e8b90f6..86f7196f9d91 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1794,7 +1794,7 @@ static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
1794 1794
1795 tx_data += len; 1795 tx_data += len;
1796 agg->skb_len += len; 1796 agg->skb_len += len;
1797 agg->skb_num++; 1797 agg->skb_num += skb_shinfo(skb)->gso_segs ?: 1;
1798 1798
1799 dev_kfree_skb_any(skb); 1799 dev_kfree_skb_any(skb);
1800 1800
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index d0a113743195..7a6a1fe79309 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -954,10 +954,11 @@ static int smsc75xx_set_features(struct net_device *netdev,
954 /* it's racing here! */ 954 /* it's racing here! */
955 955
956 ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl); 956 ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
957 if (ret < 0) 957 if (ret < 0) {
958 netdev_warn(dev->net, "Error writing RFE_CTL\n"); 958 netdev_warn(dev->net, "Error writing RFE_CTL\n");
959 959 return ret;
960 return ret; 960 }
961 return 0;
961} 962}
962 963
963static int smsc75xx_wait_ready(struct usbnet *dev, int in_pm) 964static int smsc75xx_wait_ready(struct usbnet *dev, int in_pm)
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 8a22ff67b026..d9eea8cfe6cb 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -315,6 +315,7 @@ static void __usbnet_status_stop_force(struct usbnet *dev)
315void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb) 315void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)
316{ 316{
317 struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->stats64); 317 struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->stats64);
318 unsigned long flags;
318 int status; 319 int status;
319 320
320 if (test_bit(EVENT_RX_PAUSED, &dev->flags)) { 321 if (test_bit(EVENT_RX_PAUSED, &dev->flags)) {
@@ -326,10 +327,10 @@ void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)
326 if (skb->protocol == 0) 327 if (skb->protocol == 0)
327 skb->protocol = eth_type_trans (skb, dev->net); 328 skb->protocol = eth_type_trans (skb, dev->net);
328 329
329 u64_stats_update_begin(&stats64->syncp); 330 flags = u64_stats_update_begin_irqsave(&stats64->syncp);
330 stats64->rx_packets++; 331 stats64->rx_packets++;
331 stats64->rx_bytes += skb->len; 332 stats64->rx_bytes += skb->len;
332 u64_stats_update_end(&stats64->syncp); 333 u64_stats_update_end_irqrestore(&stats64->syncp, flags);
333 334
334 netif_dbg(dev, rx_status, dev->net, "< rx, len %zu, type 0x%x\n", 335 netif_dbg(dev, rx_status, dev->net, "< rx, len %zu, type 0x%x\n",
335 skb->len + sizeof (struct ethhdr), skb->protocol); 336 skb->len + sizeof (struct ethhdr), skb->protocol);
@@ -1248,11 +1249,12 @@ static void tx_complete (struct urb *urb)
1248 1249
1249 if (urb->status == 0) { 1250 if (urb->status == 0) {
1250 struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->stats64); 1251 struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->stats64);
1252 unsigned long flags;
1251 1253
1252 u64_stats_update_begin(&stats64->syncp); 1254 flags = u64_stats_update_begin_irqsave(&stats64->syncp);
1253 stats64->tx_packets += entry->packets; 1255 stats64->tx_packets += entry->packets;
1254 stats64->tx_bytes += entry->length; 1256 stats64->tx_bytes += entry->length;
1255 u64_stats_update_end(&stats64->syncp); 1257 u64_stats_update_end_irqrestore(&stats64->syncp, flags);
1256 } else { 1258 } else {
1257 dev->net->stats.tx_errors++; 1259 dev->net->stats.tx_errors++;
1258 1260
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 626c27352ae2..23374603e4d9 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -443,12 +443,8 @@ static bool __virtnet_xdp_xmit(struct virtnet_info *vi,
443 sg_init_one(sq->sg, xdp->data, xdp->data_end - xdp->data); 443 sg_init_one(sq->sg, xdp->data, xdp->data_end - xdp->data);
444 444
445 err = virtqueue_add_outbuf(sq->vq, sq->sg, 1, xdp->data, GFP_ATOMIC); 445 err = virtqueue_add_outbuf(sq->vq, sq->sg, 1, xdp->data, GFP_ATOMIC);
446 if (unlikely(err)) { 446 if (unlikely(err))
447 struct page *page = virt_to_head_page(xdp->data); 447 return false; /* Caller handle free/refcnt */
448
449 put_page(page);
450 return false;
451 }
452 448
453 return true; 449 return true;
454} 450}
@@ -456,8 +452,18 @@ static bool __virtnet_xdp_xmit(struct virtnet_info *vi,
456static int virtnet_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp) 452static int virtnet_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp)
457{ 453{
458 struct virtnet_info *vi = netdev_priv(dev); 454 struct virtnet_info *vi = netdev_priv(dev);
459 bool sent = __virtnet_xdp_xmit(vi, xdp); 455 struct receive_queue *rq = vi->rq;
456 struct bpf_prog *xdp_prog;
457 bool sent;
458
459 /* Only allow ndo_xdp_xmit if XDP is loaded on dev, as this
460 * indicate XDP resources have been successfully allocated.
461 */
462 xdp_prog = rcu_dereference(rq->xdp_prog);
463 if (!xdp_prog)
464 return -ENXIO;
460 465
466 sent = __virtnet_xdp_xmit(vi, xdp);
461 if (!sent) 467 if (!sent)
462 return -ENOSPC; 468 return -ENOSPC;
463 return 0; 469 return 0;
@@ -498,6 +504,7 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
498 page_off += *len; 504 page_off += *len;
499 505
500 while (--*num_buf) { 506 while (--*num_buf) {
507 int tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
501 unsigned int buflen; 508 unsigned int buflen;
502 void *buf; 509 void *buf;
503 int off; 510 int off;
@@ -512,7 +519,7 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
512 /* guard against a misconfigured or uncooperative backend that 519 /* guard against a misconfigured or uncooperative backend that
513 * is sending packet larger than the MTU. 520 * is sending packet larger than the MTU.
514 */ 521 */
515 if ((page_off + buflen) > PAGE_SIZE) { 522 if ((page_off + buflen + tailroom) > PAGE_SIZE) {
516 put_page(p); 523 put_page(p);
517 goto err_buf; 524 goto err_buf;
518 } 525 }
@@ -546,8 +553,11 @@ static struct sk_buff *receive_small(struct net_device *dev,
546 unsigned int buflen = SKB_DATA_ALIGN(GOOD_PACKET_LEN + headroom) + 553 unsigned int buflen = SKB_DATA_ALIGN(GOOD_PACKET_LEN + headroom) +
547 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); 554 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
548 struct page *page = virt_to_head_page(buf); 555 struct page *page = virt_to_head_page(buf);
549 unsigned int delta = 0, err; 556 unsigned int delta = 0;
550 struct page *xdp_page; 557 struct page *xdp_page;
558 bool sent;
559 int err;
560
551 len -= vi->hdr_len; 561 len -= vi->hdr_len;
552 562
553 rcu_read_lock(); 563 rcu_read_lock();
@@ -558,7 +568,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
558 void *orig_data; 568 void *orig_data;
559 u32 act; 569 u32 act;
560 570
561 if (unlikely(hdr->hdr.gso_type || hdr->hdr.flags)) 571 if (unlikely(hdr->hdr.gso_type))
562 goto err_xdp; 572 goto err_xdp;
563 573
564 if (unlikely(xdp_headroom < virtnet_get_headroom(vi))) { 574 if (unlikely(xdp_headroom < virtnet_get_headroom(vi))) {
@@ -596,16 +606,19 @@ static struct sk_buff *receive_small(struct net_device *dev,
596 delta = orig_data - xdp.data; 606 delta = orig_data - xdp.data;
597 break; 607 break;
598 case XDP_TX: 608 case XDP_TX:
599 if (unlikely(!__virtnet_xdp_xmit(vi, &xdp))) 609 sent = __virtnet_xdp_xmit(vi, &xdp);
610 if (unlikely(!sent)) {
600 trace_xdp_exception(vi->dev, xdp_prog, act); 611 trace_xdp_exception(vi->dev, xdp_prog, act);
601 else 612 goto err_xdp;
602 *xdp_xmit = true; 613 }
614 *xdp_xmit = true;
603 rcu_read_unlock(); 615 rcu_read_unlock();
604 goto xdp_xmit; 616 goto xdp_xmit;
605 case XDP_REDIRECT: 617 case XDP_REDIRECT:
606 err = xdp_do_redirect(dev, &xdp, xdp_prog); 618 err = xdp_do_redirect(dev, &xdp, xdp_prog);
607 if (!err) 619 if (err)
608 *xdp_xmit = true; 620 goto err_xdp;
621 *xdp_xmit = true;
609 rcu_read_unlock(); 622 rcu_read_unlock();
610 goto xdp_xmit; 623 goto xdp_xmit;
611 default: 624 default:
@@ -677,6 +690,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
677 struct bpf_prog *xdp_prog; 690 struct bpf_prog *xdp_prog;
678 unsigned int truesize; 691 unsigned int truesize;
679 unsigned int headroom = mergeable_ctx_to_headroom(ctx); 692 unsigned int headroom = mergeable_ctx_to_headroom(ctx);
693 bool sent;
680 int err; 694 int err;
681 695
682 head_skb = NULL; 696 head_skb = NULL;
@@ -689,7 +703,12 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
689 void *data; 703 void *data;
690 u32 act; 704 u32 act;
691 705
692 /* This happens when rx buffer size is underestimated */ 706 /* This happens when rx buffer size is underestimated
707 * or headroom is not enough because of the buffer
708 * was refilled before XDP is set. This should only
709 * happen for the first several packets, so we don't
710 * care much about its performance.
711 */
693 if (unlikely(num_buf > 1 || 712 if (unlikely(num_buf > 1 ||
694 headroom < virtnet_get_headroom(vi))) { 713 headroom < virtnet_get_headroom(vi))) {
695 /* linearize data for XDP */ 714 /* linearize data for XDP */
@@ -724,9 +743,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
724 743
725 act = bpf_prog_run_xdp(xdp_prog, &xdp); 744 act = bpf_prog_run_xdp(xdp_prog, &xdp);
726 745
727 if (act != XDP_PASS)
728 ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
729
730 switch (act) { 746 switch (act) {
731 case XDP_PASS: 747 case XDP_PASS:
732 /* recalculate offset to account for any header 748 /* recalculate offset to account for any header
@@ -746,18 +762,28 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
746 } 762 }
747 break; 763 break;
748 case XDP_TX: 764 case XDP_TX:
749 if (unlikely(!__virtnet_xdp_xmit(vi, &xdp))) 765 sent = __virtnet_xdp_xmit(vi, &xdp);
766 if (unlikely(!sent)) {
750 trace_xdp_exception(vi->dev, xdp_prog, act); 767 trace_xdp_exception(vi->dev, xdp_prog, act);
751 else 768 if (unlikely(xdp_page != page))
752 *xdp_xmit = true; 769 put_page(xdp_page);
770 goto err_xdp;
771 }
772 *xdp_xmit = true;
753 if (unlikely(xdp_page != page)) 773 if (unlikely(xdp_page != page))
754 goto err_xdp; 774 goto err_xdp;
755 rcu_read_unlock(); 775 rcu_read_unlock();
756 goto xdp_xmit; 776 goto xdp_xmit;
757 case XDP_REDIRECT: 777 case XDP_REDIRECT:
758 err = xdp_do_redirect(dev, &xdp, xdp_prog); 778 err = xdp_do_redirect(dev, &xdp, xdp_prog);
759 if (!err) 779 if (err) {
760 *xdp_xmit = true; 780 if (unlikely(xdp_page != page))
781 put_page(xdp_page);
782 goto err_xdp;
783 }
784 *xdp_xmit = true;
785 if (unlikely(xdp_page != page))
786 goto err_xdp;
761 rcu_read_unlock(); 787 rcu_read_unlock();
762 goto xdp_xmit; 788 goto xdp_xmit;
763 default: 789 default:
@@ -1003,13 +1029,18 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,
1003} 1029}
1004 1030
1005static unsigned int get_mergeable_buf_len(struct receive_queue *rq, 1031static unsigned int get_mergeable_buf_len(struct receive_queue *rq,
1006 struct ewma_pkt_len *avg_pkt_len) 1032 struct ewma_pkt_len *avg_pkt_len,
1033 unsigned int room)
1007{ 1034{
1008 const size_t hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf); 1035 const size_t hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf);
1009 unsigned int len; 1036 unsigned int len;
1010 1037
1011 len = hdr_len + clamp_t(unsigned int, ewma_pkt_len_read(avg_pkt_len), 1038 if (room)
1039 return PAGE_SIZE - room;
1040
1041 len = hdr_len + clamp_t(unsigned int, ewma_pkt_len_read(avg_pkt_len),
1012 rq->min_buf_len, PAGE_SIZE - hdr_len); 1042 rq->min_buf_len, PAGE_SIZE - hdr_len);
1043
1013 return ALIGN(len, L1_CACHE_BYTES); 1044 return ALIGN(len, L1_CACHE_BYTES);
1014} 1045}
1015 1046
@@ -1018,21 +1049,27 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
1018{ 1049{
1019 struct page_frag *alloc_frag = &rq->alloc_frag; 1050 struct page_frag *alloc_frag = &rq->alloc_frag;
1020 unsigned int headroom = virtnet_get_headroom(vi); 1051 unsigned int headroom = virtnet_get_headroom(vi);
1052 unsigned int tailroom = headroom ? sizeof(struct skb_shared_info) : 0;
1053 unsigned int room = SKB_DATA_ALIGN(headroom + tailroom);
1021 char *buf; 1054 char *buf;
1022 void *ctx; 1055 void *ctx;
1023 int err; 1056 int err;
1024 unsigned int len, hole; 1057 unsigned int len, hole;
1025 1058
1026 len = get_mergeable_buf_len(rq, &rq->mrg_avg_pkt_len); 1059 /* Extra tailroom is needed to satisfy XDP's assumption. This
1027 if (unlikely(!skb_page_frag_refill(len + headroom, alloc_frag, gfp))) 1060 * means rx frags coalescing won't work, but consider we've
1061 * disabled GSO for XDP, it won't be a big issue.
1062 */
1063 len = get_mergeable_buf_len(rq, &rq->mrg_avg_pkt_len, room);
1064 if (unlikely(!skb_page_frag_refill(len + room, alloc_frag, gfp)))
1028 return -ENOMEM; 1065 return -ENOMEM;
1029 1066
1030 buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset; 1067 buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset;
1031 buf += headroom; /* advance address leaving hole at front of pkt */ 1068 buf += headroom; /* advance address leaving hole at front of pkt */
1032 get_page(alloc_frag->page); 1069 get_page(alloc_frag->page);
1033 alloc_frag->offset += len + headroom; 1070 alloc_frag->offset += len + room;
1034 hole = alloc_frag->size - alloc_frag->offset; 1071 hole = alloc_frag->size - alloc_frag->offset;
1035 if (hole < len + headroom) { 1072 if (hole < len + room) {
1036 /* To avoid internal fragmentation, if there is very likely not 1073 /* To avoid internal fragmentation, if there is very likely not
1037 * enough space for another buffer, add the remaining space to 1074 * enough space for another buffer, add the remaining space to
1038 * the current buffer. 1075 * the current buffer.
@@ -2175,8 +2212,9 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
2175 } 2212 }
2176 2213
2177 /* Make sure NAPI is not using any XDP TX queues for RX. */ 2214 /* Make sure NAPI is not using any XDP TX queues for RX. */
2178 for (i = 0; i < vi->max_queue_pairs; i++) 2215 if (netif_running(dev))
2179 napi_disable(&vi->rq[i].napi); 2216 for (i = 0; i < vi->max_queue_pairs; i++)
2217 napi_disable(&vi->rq[i].napi);
2180 2218
2181 netif_set_real_num_rx_queues(dev, curr_qp + xdp_qp); 2219 netif_set_real_num_rx_queues(dev, curr_qp + xdp_qp);
2182 err = _virtnet_set_queues(vi, curr_qp + xdp_qp); 2220 err = _virtnet_set_queues(vi, curr_qp + xdp_qp);
@@ -2195,7 +2233,8 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
2195 } 2233 }
2196 if (old_prog) 2234 if (old_prog)
2197 bpf_prog_put(old_prog); 2235 bpf_prog_put(old_prog);
2198 virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); 2236 if (netif_running(dev))
2237 virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi);
2199 } 2238 }
2200 2239
2201 return 0; 2240 return 0;
@@ -2566,12 +2605,15 @@ static ssize_t mergeable_rx_buffer_size_show(struct netdev_rx_queue *queue,
2566{ 2605{
2567 struct virtnet_info *vi = netdev_priv(queue->dev); 2606 struct virtnet_info *vi = netdev_priv(queue->dev);
2568 unsigned int queue_index = get_netdev_rx_queue_index(queue); 2607 unsigned int queue_index = get_netdev_rx_queue_index(queue);
2608 unsigned int headroom = virtnet_get_headroom(vi);
2609 unsigned int tailroom = headroom ? sizeof(struct skb_shared_info) : 0;
2569 struct ewma_pkt_len *avg; 2610 struct ewma_pkt_len *avg;
2570 2611
2571 BUG_ON(queue_index >= vi->max_queue_pairs); 2612 BUG_ON(queue_index >= vi->max_queue_pairs);
2572 avg = &vi->rq[queue_index].mrg_avg_pkt_len; 2613 avg = &vi->rq[queue_index].mrg_avg_pkt_len;
2573 return sprintf(buf, "%u\n", 2614 return sprintf(buf, "%u\n",
2574 get_mergeable_buf_len(&vi->rq[queue_index], avg)); 2615 get_mergeable_buf_len(&vi->rq[queue_index], avg,
2616 SKB_DATA_ALIGN(headroom + tailroom)));
2575} 2617}
2576 2618
2577static struct rx_queue_attribute mergeable_rx_buffer_size_attribute = 2619static struct rx_queue_attribute mergeable_rx_buffer_size_attribute =
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index 8b39c160743d..e04937f44f33 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -977,6 +977,8 @@ vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
977{ 977{
978 int ret; 978 int ret;
979 u32 count; 979 u32 count;
980 int num_pkts;
981 int tx_num_deferred;
980 unsigned long flags; 982 unsigned long flags;
981 struct vmxnet3_tx_ctx ctx; 983 struct vmxnet3_tx_ctx ctx;
982 union Vmxnet3_GenericDesc *gdesc; 984 union Vmxnet3_GenericDesc *gdesc;
@@ -1075,12 +1077,12 @@ vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
1075#else 1077#else
1076 gdesc = ctx.sop_txd; 1078 gdesc = ctx.sop_txd;
1077#endif 1079#endif
1080 tx_num_deferred = le32_to_cpu(tq->shared->txNumDeferred);
1078 if (ctx.mss) { 1081 if (ctx.mss) {
1079 gdesc->txd.hlen = ctx.eth_ip_hdr_size + ctx.l4_hdr_size; 1082 gdesc->txd.hlen = ctx.eth_ip_hdr_size + ctx.l4_hdr_size;
1080 gdesc->txd.om = VMXNET3_OM_TSO; 1083 gdesc->txd.om = VMXNET3_OM_TSO;
1081 gdesc->txd.msscof = ctx.mss; 1084 gdesc->txd.msscof = ctx.mss;
1082 le32_add_cpu(&tq->shared->txNumDeferred, (skb->len - 1085 num_pkts = (skb->len - gdesc->txd.hlen + ctx.mss - 1) / ctx.mss;
1083 gdesc->txd.hlen + ctx.mss - 1) / ctx.mss);
1084 } else { 1086 } else {
1085 if (skb->ip_summed == CHECKSUM_PARTIAL) { 1087 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1086 gdesc->txd.hlen = ctx.eth_ip_hdr_size; 1088 gdesc->txd.hlen = ctx.eth_ip_hdr_size;
@@ -1091,8 +1093,10 @@ vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
1091 gdesc->txd.om = 0; 1093 gdesc->txd.om = 0;
1092 gdesc->txd.msscof = 0; 1094 gdesc->txd.msscof = 0;
1093 } 1095 }
1094 le32_add_cpu(&tq->shared->txNumDeferred, 1); 1096 num_pkts = 1;
1095 } 1097 }
1098 le32_add_cpu(&tq->shared->txNumDeferred, num_pkts);
1099 tx_num_deferred += num_pkts;
1096 1100
1097 if (skb_vlan_tag_present(skb)) { 1101 if (skb_vlan_tag_present(skb)) {
1098 gdesc->txd.ti = 1; 1102 gdesc->txd.ti = 1;
@@ -1118,8 +1122,7 @@ vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
1118 1122
1119 spin_unlock_irqrestore(&tq->tx_lock, flags); 1123 spin_unlock_irqrestore(&tq->tx_lock, flags);
1120 1124
1121 if (le32_to_cpu(tq->shared->txNumDeferred) >= 1125 if (tx_num_deferred >= le32_to_cpu(tq->shared->txThreshold)) {
1122 le32_to_cpu(tq->shared->txThreshold)) {
1123 tq->shared->txNumDeferred = 0; 1126 tq->shared->txNumDeferred = 0;
1124 VMXNET3_WRITE_BAR0_REG(adapter, 1127 VMXNET3_WRITE_BAR0_REG(adapter,
1125 VMXNET3_REG_TXPROD + tq->qid * 8, 1128 VMXNET3_REG_TXPROD + tq->qid * 8,
@@ -1470,7 +1473,8 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,
1470 vmxnet3_rx_csum(adapter, skb, 1473 vmxnet3_rx_csum(adapter, skb,
1471 (union Vmxnet3_GenericDesc *)rcd); 1474 (union Vmxnet3_GenericDesc *)rcd);
1472 skb->protocol = eth_type_trans(skb, adapter->netdev); 1475 skb->protocol = eth_type_trans(skb, adapter->netdev);
1473 if (!rcd->tcp || !adapter->lro) 1476 if (!rcd->tcp ||
1477 !(adapter->netdev->features & NETIF_F_LRO))
1474 goto not_lro; 1478 goto not_lro;
1475 1479
1476 if (segCnt != 0 && mss != 0) { 1480 if (segCnt != 0 && mss != 0) {
diff --git a/drivers/net/vmxnet3/vmxnet3_int.h b/drivers/net/vmxnet3/vmxnet3_int.h
index 5ba222920e80..59ec34052a65 100644
--- a/drivers/net/vmxnet3/vmxnet3_int.h
+++ b/drivers/net/vmxnet3/vmxnet3_int.h
@@ -69,10 +69,10 @@
69/* 69/*
70 * Version numbers 70 * Version numbers
71 */ 71 */
72#define VMXNET3_DRIVER_VERSION_STRING "1.4.11.0-k" 72#define VMXNET3_DRIVER_VERSION_STRING "1.4.13.0-k"
73 73
74/* a 32-bit int, each byte encode a verion number in VMXNET3_DRIVER_VERSION */ 74/* a 32-bit int, each byte encode a verion number in VMXNET3_DRIVER_VERSION */
75#define VMXNET3_DRIVER_VERSION_NUM 0x01040b00 75#define VMXNET3_DRIVER_VERSION_NUM 0x01040d00
76 76
77#if defined(CONFIG_PCI_MSI) 77#if defined(CONFIG_PCI_MSI)
78 /* RSS only makes sense if MSI-X is supported. */ 78 /* RSS only makes sense if MSI-X is supported. */
@@ -342,9 +342,6 @@ struct vmxnet3_adapter {
342 u8 __iomem *hw_addr1; /* for BAR 1 */ 342 u8 __iomem *hw_addr1; /* for BAR 1 */
343 u8 version; 343 u8 version;
344 344
345 bool rxcsum;
346 bool lro;
347
348#ifdef VMXNET3_RSS 345#ifdef VMXNET3_RSS
349 struct UPT1_RSSConf *rss_conf; 346 struct UPT1_RSSConf *rss_conf;
350 bool rss; 347 bool rss;
diff --git a/drivers/net/wan/hdlc_ppp.c b/drivers/net/wan/hdlc_ppp.c
index afeca6bcdade..ab8b3cbbb205 100644
--- a/drivers/net/wan/hdlc_ppp.c
+++ b/drivers/net/wan/hdlc_ppp.c
@@ -574,7 +574,10 @@ static void ppp_timer(struct timer_list *t)
574 ppp_cp_event(proto->dev, proto->pid, TO_GOOD, 0, 0, 574 ppp_cp_event(proto->dev, proto->pid, TO_GOOD, 0, 0,
575 0, NULL); 575 0, NULL);
576 proto->restart_counter--; 576 proto->restart_counter--;
577 } else 577 } else if (netif_carrier_ok(proto->dev))
578 ppp_cp_event(proto->dev, proto->pid, TO_GOOD, 0, 0,
579 0, NULL);
580 else
578 ppp_cp_event(proto->dev, proto->pid, TO_BAD, 0, 0, 581 ppp_cp_event(proto->dev, proto->pid, TO_BAD, 0, 0,
579 0, NULL); 582 0, NULL);
580 break; 583 break;
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_init.c b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
index e89e5ef2c2a4..f246e9ed4a81 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
@@ -729,6 +729,7 @@ static void ath9k_set_hw_capab(struct ath9k_htc_priv *priv,
729 ieee80211_hw_set(hw, SPECTRUM_MGMT); 729 ieee80211_hw_set(hw, SPECTRUM_MGMT);
730 ieee80211_hw_set(hw, SIGNAL_DBM); 730 ieee80211_hw_set(hw, SIGNAL_DBM);
731 ieee80211_hw_set(hw, AMPDU_AGGREGATION); 731 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
732 ieee80211_hw_set(hw, DOESNT_SUPPORT_QOS_NDP);
732 733
733 if (ath9k_ps_enable) 734 if (ath9k_ps_enable)
734 ieee80211_hw_set(hw, SUPPORTS_PS); 735 ieee80211_hw_set(hw, SUPPORTS_PS);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
index df8a1ecb9924..232dcbb83311 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h
@@ -181,6 +181,7 @@ enum brcmf_netif_stop_reason {
181 * @netif_stop_lock: spinlock for update netif_stop from multiple sources. 181 * @netif_stop_lock: spinlock for update netif_stop from multiple sources.
182 * @pend_8021x_cnt: tracks outstanding number of 802.1x frames. 182 * @pend_8021x_cnt: tracks outstanding number of 802.1x frames.
183 * @pend_8021x_wait: used for signalling change in count. 183 * @pend_8021x_wait: used for signalling change in count.
184 * @fwil_fwerr: flag indicating fwil layer should return firmware error codes.
184 */ 185 */
185struct brcmf_if { 186struct brcmf_if {
186 struct brcmf_pub *drvr; 187 struct brcmf_pub *drvr;
@@ -198,6 +199,7 @@ struct brcmf_if {
198 wait_queue_head_t pend_8021x_wait; 199 wait_queue_head_t pend_8021x_wait;
199 struct in6_addr ipv6_addr_tbl[NDOL_MAX_ENTRIES]; 200 struct in6_addr ipv6_addr_tbl[NDOL_MAX_ENTRIES];
200 u8 ipv6addr_idx; 201 u8 ipv6addr_idx;
202 bool fwil_fwerr;
201}; 203};
202 204
203int brcmf_netdev_wait_pend8021x(struct brcmf_if *ifp); 205int brcmf_netdev_wait_pend8021x(struct brcmf_if *ifp);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
index 47de35a33853..bede7b7fd996 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
@@ -104,6 +104,9 @@ static void brcmf_feat_iovar_int_get(struct brcmf_if *ifp,
104 u32 data; 104 u32 data;
105 int err; 105 int err;
106 106
107 /* we need to know firmware error */
108 ifp->fwil_fwerr = true;
109
107 err = brcmf_fil_iovar_int_get(ifp, name, &data); 110 err = brcmf_fil_iovar_int_get(ifp, name, &data);
108 if (err == 0) { 111 if (err == 0) {
109 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]); 112 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]);
@@ -112,6 +115,8 @@ static void brcmf_feat_iovar_int_get(struct brcmf_if *ifp,
112 brcmf_dbg(TRACE, "%s feature check failed: %d\n", 115 brcmf_dbg(TRACE, "%s feature check failed: %d\n",
113 brcmf_feat_names[id], err); 116 brcmf_feat_names[id], err);
114 } 117 }
118
119 ifp->fwil_fwerr = false;
115} 120}
116 121
117static void brcmf_feat_iovar_data_set(struct brcmf_if *ifp, 122static void brcmf_feat_iovar_data_set(struct brcmf_if *ifp,
@@ -120,6 +125,9 @@ static void brcmf_feat_iovar_data_set(struct brcmf_if *ifp,
120{ 125{
121 int err; 126 int err;
122 127
128 /* we need to know firmware error */
129 ifp->fwil_fwerr = true;
130
123 err = brcmf_fil_iovar_data_set(ifp, name, data, len); 131 err = brcmf_fil_iovar_data_set(ifp, name, data, len);
124 if (err != -BRCMF_FW_UNSUPPORTED) { 132 if (err != -BRCMF_FW_UNSUPPORTED) {
125 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]); 133 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]);
@@ -128,6 +136,8 @@ static void brcmf_feat_iovar_data_set(struct brcmf_if *ifp,
128 brcmf_dbg(TRACE, "%s feature check failed: %d\n", 136 brcmf_dbg(TRACE, "%s feature check failed: %d\n",
129 brcmf_feat_names[id], err); 137 brcmf_feat_names[id], err);
130 } 138 }
139
140 ifp->fwil_fwerr = false;
131} 141}
132 142
133#define MAX_CAPS_BUFFER_SIZE 512 143#define MAX_CAPS_BUFFER_SIZE 512
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.c
index f2cfdd3b2bf1..fc5751116d99 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.c
@@ -131,6 +131,9 @@ brcmf_fil_cmd_data(struct brcmf_if *ifp, u32 cmd, void *data, u32 len, bool set)
131 brcmf_fil_get_errstr((u32)(-fwerr)), fwerr); 131 brcmf_fil_get_errstr((u32)(-fwerr)), fwerr);
132 err = -EBADE; 132 err = -EBADE;
133 } 133 }
134 if (ifp->fwil_fwerr)
135 return fwerr;
136
134 return err; 137 return err;
135} 138}
136 139
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c
index 2ee54133efa1..82064e909784 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c
@@ -462,25 +462,23 @@ static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
462 * @dev_addr: optional device address. 462 * @dev_addr: optional device address.
463 * 463 *
464 * P2P needs mac addresses for P2P device and interface. If no device 464 * P2P needs mac addresses for P2P device and interface. If no device
465 * address it specified, these are derived from the primary net device, ie. 465 * address it specified, these are derived from a random ethernet
466 * the permanent ethernet address of the device. 466 * address.
467 */ 467 */
468static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p, u8 *dev_addr) 468static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p, u8 *dev_addr)
469{ 469{
470 struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; 470 bool random_addr = false;
471 bool local_admin = false;
472 471
473 if (!dev_addr || is_zero_ether_addr(dev_addr)) { 472 if (!dev_addr || is_zero_ether_addr(dev_addr))
474 dev_addr = pri_ifp->mac_addr; 473 random_addr = true;
475 local_admin = true;
476 }
477 474
478 /* Generate the P2P Device Address. This consists of the device's 475 /* Generate the P2P Device Address obtaining a random ethernet
479 * primary MAC address with the locally administered bit set. 476 * address with the locally administered bit set.
480 */ 477 */
481 memcpy(p2p->dev_addr, dev_addr, ETH_ALEN); 478 if (random_addr)
482 if (local_admin) 479 eth_random_addr(p2p->dev_addr);
483 p2p->dev_addr[0] |= 0x02; 480 else
481 memcpy(p2p->dev_addr, dev_addr, ETH_ALEN);
484 482
485 /* Generate the P2P Interface Address. If the discovery and connection 483 /* Generate the P2P Interface Address. If the discovery and connection
486 * BSSCFGs need to simultaneously co-exist, then this address must be 484 * BSSCFGs need to simultaneously co-exist, then this address must be
diff --git a/drivers/net/wireless/intel/iwlwifi/Kconfig b/drivers/net/wireless/intel/iwlwifi/Kconfig
index c5f2ddf9b0fe..e5a2fc738ac3 100644
--- a/drivers/net/wireless/intel/iwlwifi/Kconfig
+++ b/drivers/net/wireless/intel/iwlwifi/Kconfig
@@ -91,7 +91,6 @@ config IWLWIFI_BCAST_FILTERING
91config IWLWIFI_PCIE_RTPM 91config IWLWIFI_PCIE_RTPM
92 bool "Enable runtime power management mode for PCIe devices" 92 bool "Enable runtime power management mode for PCIe devices"
93 depends on IWLMVM && PM && EXPERT 93 depends on IWLMVM && PM && EXPERT
94 default false
95 help 94 help
96 Say Y here to enable runtime power management for PCIe 95 Say Y here to enable runtime power management for PCIe
97 devices. If enabled, the device will go into low power mode 96 devices. If enabled, the device will go into low power mode
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/time-event.h b/drivers/net/wireless/intel/iwlwifi/fw/api/time-event.h
index 3721a3ed358b..f824bebceb06 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/api/time-event.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/api/time-event.h
@@ -211,7 +211,7 @@ enum {
211 * @TE_V2_NOTIF_HOST_FRAG_END:request/receive notification on frag end 211 * @TE_V2_NOTIF_HOST_FRAG_END:request/receive notification on frag end
212 * @TE_V2_NOTIF_INTERNAL_FRAG_START: internal FW use. 212 * @TE_V2_NOTIF_INTERNAL_FRAG_START: internal FW use.
213 * @TE_V2_NOTIF_INTERNAL_FRAG_END: internal FW use. 213 * @TE_V2_NOTIF_INTERNAL_FRAG_END: internal FW use.
214 * @T2_V2_START_IMMEDIATELY: start time event immediately 214 * @TE_V2_START_IMMEDIATELY: start time event immediately
215 * @TE_V2_DEP_OTHER: depends on another time event 215 * @TE_V2_DEP_OTHER: depends on another time event
216 * @TE_V2_DEP_TSF: depends on a specific time 216 * @TE_V2_DEP_TSF: depends on a specific time
217 * @TE_V2_EVENT_SOCIOPATHIC: can't co-exist with other events of tha same MAC 217 * @TE_V2_EVENT_SOCIOPATHIC: can't co-exist with other events of tha same MAC
@@ -230,7 +230,7 @@ enum iwl_time_event_policy {
230 TE_V2_NOTIF_HOST_FRAG_END = BIT(5), 230 TE_V2_NOTIF_HOST_FRAG_END = BIT(5),
231 TE_V2_NOTIF_INTERNAL_FRAG_START = BIT(6), 231 TE_V2_NOTIF_INTERNAL_FRAG_START = BIT(6),
232 TE_V2_NOTIF_INTERNAL_FRAG_END = BIT(7), 232 TE_V2_NOTIF_INTERNAL_FRAG_END = BIT(7),
233 T2_V2_START_IMMEDIATELY = BIT(11), 233 TE_V2_START_IMMEDIATELY = BIT(11),
234 234
235 /* placement characteristics */ 235 /* placement characteristics */
236 TE_V2_DEP_OTHER = BIT(TE_V2_PLACEMENT_POS), 236 TE_V2_DEP_OTHER = BIT(TE_V2_PLACEMENT_POS),
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
index 67aefc8fc9ac..7bd704a3e640 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
+++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
@@ -8,6 +8,7 @@
8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH 10 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
11 * 12 *
12 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 14 * it under the terms of version 2 of the GNU General Public License as
@@ -33,6 +34,7 @@
33 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. 34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
34 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
35 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH 36 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
37 * Copyright(c) 2018 Intel Corporation
36 * All rights reserved. 38 * All rights reserved.
37 * 39 *
38 * Redistribution and use in source and binary forms, with or without 40 * Redistribution and use in source and binary forms, with or without
@@ -942,7 +944,6 @@ dump_trans_data:
942 944
943out: 945out:
944 iwl_fw_free_dump_desc(fwrt); 946 iwl_fw_free_dump_desc(fwrt);
945 fwrt->dump.trig = NULL;
946 clear_bit(IWL_FWRT_STATUS_DUMPING, &fwrt->status); 947 clear_bit(IWL_FWRT_STATUS_DUMPING, &fwrt->status);
947 IWL_DEBUG_INFO(fwrt, "WRT dump done\n"); 948 IWL_DEBUG_INFO(fwrt, "WRT dump done\n");
948} 949}
@@ -1112,6 +1113,14 @@ void iwl_fw_error_dump_wk(struct work_struct *work)
1112 fwrt->ops->dump_start(fwrt->ops_ctx)) 1113 fwrt->ops->dump_start(fwrt->ops_ctx))
1113 return; 1114 return;
1114 1115
1116 if (fwrt->ops && fwrt->ops->fw_running &&
1117 !fwrt->ops->fw_running(fwrt->ops_ctx)) {
1118 IWL_ERR(fwrt, "Firmware not running - cannot dump error\n");
1119 iwl_fw_free_dump_desc(fwrt);
1120 clear_bit(IWL_FWRT_STATUS_DUMPING, &fwrt->status);
1121 goto out;
1122 }
1123
1115 if (fwrt->trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) { 1124 if (fwrt->trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
1116 /* stop recording */ 1125 /* stop recording */
1117 iwl_fw_dbg_stop_recording(fwrt); 1126 iwl_fw_dbg_stop_recording(fwrt);
@@ -1145,7 +1154,7 @@ void iwl_fw_error_dump_wk(struct work_struct *work)
1145 iwl_write_prph(fwrt->trans, DBGC_OUT_CTRL, out_ctrl); 1154 iwl_write_prph(fwrt->trans, DBGC_OUT_CTRL, out_ctrl);
1146 } 1155 }
1147 } 1156 }
1148 1157out:
1149 if (fwrt->ops && fwrt->ops->dump_end) 1158 if (fwrt->ops && fwrt->ops->dump_end)
1150 fwrt->ops->dump_end(fwrt->ops_ctx); 1159 fwrt->ops->dump_end(fwrt->ops_ctx);
1151} 1160}
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
index 223fb77a3aa9..72259bff9922 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
@@ -8,6 +8,7 @@
8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH 10 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
11 * 12 *
12 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 14 * it under the terms of version 2 of the GNU General Public License as
@@ -33,6 +34,7 @@
33 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. 34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
34 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
35 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH 36 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
37 * Copyright(c) 2018 Intel Corporation
36 * All rights reserved. 38 * All rights reserved.
37 * 39 *
38 * Redistribution and use in source and binary forms, with or without 40 * Redistribution and use in source and binary forms, with or without
@@ -91,6 +93,7 @@ static inline void iwl_fw_free_dump_desc(struct iwl_fw_runtime *fwrt)
91 if (fwrt->dump.desc != &iwl_dump_desc_assert) 93 if (fwrt->dump.desc != &iwl_dump_desc_assert)
92 kfree(fwrt->dump.desc); 94 kfree(fwrt->dump.desc);
93 fwrt->dump.desc = NULL; 95 fwrt->dump.desc = NULL;
96 fwrt->dump.trig = NULL;
94} 97}
95 98
96void iwl_fw_error_dump(struct iwl_fw_runtime *fwrt); 99void iwl_fw_error_dump(struct iwl_fw_runtime *fwrt);
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/debugfs.h b/drivers/net/wireless/intel/iwlwifi/fw/debugfs.h
index e57ff92a68ae..3da468d2cc92 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/debugfs.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/debugfs.h
@@ -75,6 +75,20 @@ static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt)
75 cancel_delayed_work_sync(&fwrt->timestamp.wk); 75 cancel_delayed_work_sync(&fwrt->timestamp.wk);
76} 76}
77 77
78static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt)
79{
80 cancel_delayed_work_sync(&fwrt->timestamp.wk);
81}
82
83static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt)
84{
85 if (!fwrt->timestamp.delay)
86 return;
87
88 schedule_delayed_work(&fwrt->timestamp.wk,
89 round_jiffies_relative(fwrt->timestamp.delay));
90}
91
78#else 92#else
79static inline int iwl_fwrt_dbgfs_register(struct iwl_fw_runtime *fwrt, 93static inline int iwl_fwrt_dbgfs_register(struct iwl_fw_runtime *fwrt,
80 struct dentry *dbgfs_dir) 94 struct dentry *dbgfs_dir)
@@ -84,4 +98,8 @@ static inline int iwl_fwrt_dbgfs_register(struct iwl_fw_runtime *fwrt,
84 98
85static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt) {} 99static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt) {}
86 100
101static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt) {}
102
103static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt) {}
104
87#endif /* CONFIG_IWLWIFI_DEBUGFS */ 105#endif /* CONFIG_IWLWIFI_DEBUGFS */
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/init.c b/drivers/net/wireless/intel/iwlwifi/fw/init.c
index c39fe84bb4c4..2efac307909e 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/init.c
+++ b/drivers/net/wireless/intel/iwlwifi/fw/init.c
@@ -77,8 +77,14 @@ void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans,
77} 77}
78IWL_EXPORT_SYMBOL(iwl_fw_runtime_init); 78IWL_EXPORT_SYMBOL(iwl_fw_runtime_init);
79 79
80void iwl_fw_runtime_exit(struct iwl_fw_runtime *fwrt) 80void iwl_fw_runtime_suspend(struct iwl_fw_runtime *fwrt)
81{ 81{
82 iwl_fw_cancel_timestamp(fwrt); 82 iwl_fw_suspend_timestamp(fwrt);
83} 83}
84IWL_EXPORT_SYMBOL(iwl_fw_runtime_exit); 84IWL_EXPORT_SYMBOL(iwl_fw_runtime_suspend);
85
86void iwl_fw_runtime_resume(struct iwl_fw_runtime *fwrt)
87{
88 iwl_fw_resume_timestamp(fwrt);
89}
90IWL_EXPORT_SYMBOL(iwl_fw_runtime_resume);
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h
index e25c049f980f..3fb940ebd74a 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h
@@ -6,6 +6,7 @@
6 * GPL LICENSE SUMMARY 6 * GPL LICENSE SUMMARY
7 * 7 *
8 * Copyright(c) 2017 Intel Deutschland GmbH 8 * Copyright(c) 2017 Intel Deutschland GmbH
9 * Copyright(c) 2018 Intel Corporation
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
@@ -26,6 +27,7 @@
26 * BSD LICENSE 27 * BSD LICENSE
27 * 28 *
28 * Copyright(c) 2017 Intel Deutschland GmbH 29 * Copyright(c) 2017 Intel Deutschland GmbH
30 * Copyright(c) 2018 Intel Corporation
29 * All rights reserved. 31 * All rights reserved.
30 * 32 *
31 * Redistribution and use in source and binary forms, with or without 33 * Redistribution and use in source and binary forms, with or without
@@ -68,6 +70,7 @@
68struct iwl_fw_runtime_ops { 70struct iwl_fw_runtime_ops {
69 int (*dump_start)(void *ctx); 71 int (*dump_start)(void *ctx);
70 void (*dump_end)(void *ctx); 72 void (*dump_end)(void *ctx);
73 bool (*fw_running)(void *ctx);
71}; 74};
72 75
73#define MAX_NUM_LMAC 2 76#define MAX_NUM_LMAC 2
@@ -150,6 +153,10 @@ void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans,
150 153
151void iwl_fw_runtime_exit(struct iwl_fw_runtime *fwrt); 154void iwl_fw_runtime_exit(struct iwl_fw_runtime *fwrt);
152 155
156void iwl_fw_runtime_suspend(struct iwl_fw_runtime *fwrt);
157
158void iwl_fw_runtime_resume(struct iwl_fw_runtime *fwrt);
159
153static inline void iwl_fw_set_current_image(struct iwl_fw_runtime *fwrt, 160static inline void iwl_fw_set_current_image(struct iwl_fw_runtime *fwrt,
154 enum iwl_ucode_type cur_fw_img) 161 enum iwl_ucode_type cur_fw_img)
155{ 162{
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
index 0e6cf39285f4..2efe9b099556 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
@@ -1098,6 +1098,8 @@ int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
1098 /* make sure the d0i3 exit work is not pending */ 1098 /* make sure the d0i3 exit work is not pending */
1099 flush_work(&mvm->d0i3_exit_work); 1099 flush_work(&mvm->d0i3_exit_work);
1100 1100
1101 iwl_fw_runtime_suspend(&mvm->fwrt);
1102
1101 ret = iwl_trans_suspend(trans); 1103 ret = iwl_trans_suspend(trans);
1102 if (ret) 1104 if (ret)
1103 return ret; 1105 return ret;
@@ -2012,6 +2014,8 @@ int iwl_mvm_resume(struct ieee80211_hw *hw)
2012 2014
2013 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED; 2015 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
2014 2016
2017 iwl_fw_runtime_resume(&mvm->fwrt);
2018
2015 return ret; 2019 return ret;
2016} 2020}
2017 2021
@@ -2038,6 +2042,8 @@ static int iwl_mvm_d3_test_open(struct inode *inode, struct file *file)
2038 2042
2039 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_D3; 2043 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_D3;
2040 2044
2045 iwl_fw_runtime_suspend(&mvm->fwrt);
2046
2041 /* start pseudo D3 */ 2047 /* start pseudo D3 */
2042 rtnl_lock(); 2048 rtnl_lock();
2043 err = __iwl_mvm_suspend(mvm->hw, mvm->hw->wiphy->wowlan_config, true); 2049 err = __iwl_mvm_suspend(mvm->hw, mvm->hw->wiphy->wowlan_config, true);
@@ -2098,6 +2104,8 @@ static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file)
2098 __iwl_mvm_resume(mvm, true); 2104 __iwl_mvm_resume(mvm, true);
2099 rtnl_unlock(); 2105 rtnl_unlock();
2100 2106
2107 iwl_fw_runtime_resume(&mvm->fwrt);
2108
2101 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED; 2109 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
2102 2110
2103 iwl_abort_notification_waits(&mvm->notif_wait); 2111 iwl_abort_notification_waits(&mvm->notif_wait);
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
index a7892c1254a2..9c436d8d001d 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
@@ -8,6 +8,7 @@
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
11 * 12 *
12 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 14 * it under the terms of version 2 of the GNU General Public License as
@@ -35,6 +36,7 @@
35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 36 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 37 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
37 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 38 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
39 * Copyright(c) 2018 Intel Corporation
38 * All rights reserved. 40 * All rights reserved.
39 * 41 *
40 * Redistribution and use in source and binary forms, with or without 42 * Redistribution and use in source and binary forms, with or without
@@ -1281,9 +1283,6 @@ static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1281{ 1283{
1282 int ret; 1284 int ret;
1283 1285
1284 if (!iwl_mvm_firmware_running(mvm))
1285 return -EIO;
1286
1287 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE); 1286 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1288 if (ret) 1287 if (ret)
1289 return ret; 1288 return ret;
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c
index 2f22e14e00fe..8ba16fc24e3a 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c
@@ -438,7 +438,8 @@ int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
438 } 438 }
439 439
440 /* Allocate the CAB queue for softAP and GO interfaces */ 440 /* Allocate the CAB queue for softAP and GO interfaces */
441 if (vif->type == NL80211_IFTYPE_AP) { 441 if (vif->type == NL80211_IFTYPE_AP ||
442 vif->type == NL80211_IFTYPE_ADHOC) {
442 /* 443 /*
443 * For TVQM this will be overwritten later with the FW assigned 444 * For TVQM this will be overwritten later with the FW assigned
444 * queue value (when queue is enabled). 445 * queue value (when queue is enabled).
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c
index 8aed40a8bc38..ebf511150f4d 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c
@@ -8,6 +8,7 @@
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
11 * 12 *
12 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 14 * it under the terms of version 2 of the GNU General Public License as
@@ -2106,15 +2107,40 @@ static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2106 if (ret) 2107 if (ret)
2107 goto out_remove; 2108 goto out_remove;
2108 2109
2109 ret = iwl_mvm_add_mcast_sta(mvm, vif); 2110 /*
2110 if (ret) 2111 * This is not very nice, but the simplest:
2111 goto out_unbind; 2112 * For older FWs adding the mcast sta before the bcast station may
2112 2113 * cause assert 0x2b00.
2113 /* Send the bcast station. At this stage the TBTT and DTIM time events 2114 * This is fixed in later FW so make the order of removal depend on
2114 * are added and applied to the scheduler */ 2115 * the TLV
2115 ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 2116 */
2116 if (ret) 2117 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2117 goto out_rm_mcast; 2118 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2119 if (ret)
2120 goto out_unbind;
2121 /*
2122 * Send the bcast station. At this stage the TBTT and DTIM time
2123 * events are added and applied to the scheduler
2124 */
2125 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2126 if (ret) {
2127 iwl_mvm_rm_mcast_sta(mvm, vif);
2128 goto out_unbind;
2129 }
2130 } else {
2131 /*
2132 * Send the bcast station. At this stage the TBTT and DTIM time
2133 * events are added and applied to the scheduler
2134 */
2135 iwl_mvm_send_add_bcast_sta(mvm, vif);
2136 if (ret)
2137 goto out_unbind;
2138 iwl_mvm_add_mcast_sta(mvm, vif);
2139 if (ret) {
2140 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2141 goto out_unbind;
2142 }
2143 }
2118 2144
2119 /* must be set before quota calculations */ 2145 /* must be set before quota calculations */
2120 mvmvif->ap_ibss_active = true; 2146 mvmvif->ap_ibss_active = true;
@@ -2144,7 +2170,6 @@ out_quota_failed:
2144 iwl_mvm_power_update_mac(mvm); 2170 iwl_mvm_power_update_mac(mvm);
2145 mvmvif->ap_ibss_active = false; 2171 mvmvif->ap_ibss_active = false;
2146 iwl_mvm_send_rm_bcast_sta(mvm, vif); 2172 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2147out_rm_mcast:
2148 iwl_mvm_rm_mcast_sta(mvm, vif); 2173 iwl_mvm_rm_mcast_sta(mvm, vif);
2149out_unbind: 2174out_unbind:
2150 iwl_mvm_binding_remove_vif(mvm, vif); 2175 iwl_mvm_binding_remove_vif(mvm, vif);
@@ -2682,6 +2707,10 @@ static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2682 2707
2683 /* enable beacon filtering */ 2708 /* enable beacon filtering */
2684 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 2709 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2710
2711 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2712 false);
2713
2685 ret = 0; 2714 ret = 0;
2686 } else if (old_state == IEEE80211_STA_AUTHORIZED && 2715 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2687 new_state == IEEE80211_STA_ASSOC) { 2716 new_state == IEEE80211_STA_ASSOC) {
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
index 2d28e0804218..89ff02d7c876 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
@@ -90,6 +90,7 @@
90#include "fw/runtime.h" 90#include "fw/runtime.h"
91#include "fw/dbg.h" 91#include "fw/dbg.h"
92#include "fw/acpi.h" 92#include "fw/acpi.h"
93#include "fw/debugfs.h"
93 94
94#define IWL_MVM_MAX_ADDRESSES 5 95#define IWL_MVM_MAX_ADDRESSES 5
95/* RSSI offset for WkP */ 96/* RSSI offset for WkP */
@@ -1783,6 +1784,7 @@ static inline u32 iwl_mvm_flushable_queues(struct iwl_mvm *mvm)
1783 1784
1784static inline void iwl_mvm_stop_device(struct iwl_mvm *mvm) 1785static inline void iwl_mvm_stop_device(struct iwl_mvm *mvm)
1785{ 1786{
1787 iwl_fw_cancel_timestamp(&mvm->fwrt);
1786 iwl_free_fw_paging(&mvm->fwrt); 1788 iwl_free_fw_paging(&mvm->fwrt);
1787 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 1789 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1788 iwl_fw_dump_conf_clear(&mvm->fwrt); 1790 iwl_fw_dump_conf_clear(&mvm->fwrt);
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
index 5d525a0023dc..ab7fb5aad984 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
@@ -8,6 +8,7 @@
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
11 * 12 *
12 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as 14 * it under the terms of version 2 of the GNU General Public License as
@@ -35,6 +36,7 @@
35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 36 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 37 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
37 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 38 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
39 * Copyright(c) 2018 Intel Corporation
38 * All rights reserved. 40 * All rights reserved.
39 * 41 *
40 * Redistribution and use in source and binary forms, with or without 42 * Redistribution and use in source and binary forms, with or without
@@ -552,9 +554,15 @@ static void iwl_mvm_fwrt_dump_end(void *ctx)
552 iwl_mvm_unref(mvm, IWL_MVM_REF_FW_DBG_COLLECT); 554 iwl_mvm_unref(mvm, IWL_MVM_REF_FW_DBG_COLLECT);
553} 555}
554 556
557static bool iwl_mvm_fwrt_fw_running(void *ctx)
558{
559 return iwl_mvm_firmware_running(ctx);
560}
561
555static const struct iwl_fw_runtime_ops iwl_mvm_fwrt_ops = { 562static const struct iwl_fw_runtime_ops iwl_mvm_fwrt_ops = {
556 .dump_start = iwl_mvm_fwrt_dump_start, 563 .dump_start = iwl_mvm_fwrt_dump_start,
557 .dump_end = iwl_mvm_fwrt_dump_end, 564 .dump_end = iwl_mvm_fwrt_dump_end,
565 .fw_running = iwl_mvm_fwrt_fw_running,
558}; 566};
559 567
560static struct iwl_op_mode * 568static struct iwl_op_mode *
@@ -802,7 +810,6 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
802 iwl_mvm_leds_exit(mvm); 810 iwl_mvm_leds_exit(mvm);
803 iwl_mvm_thermal_exit(mvm); 811 iwl_mvm_thermal_exit(mvm);
804 out_free: 812 out_free:
805 iwl_fw_runtime_exit(&mvm->fwrt);
806 iwl_fw_flush_dump(&mvm->fwrt); 813 iwl_fw_flush_dump(&mvm->fwrt);
807 814
808 if (iwlmvm_mod_params.init_dbg) 815 if (iwlmvm_mod_params.init_dbg)
@@ -843,7 +850,6 @@ static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
843#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_IWLWIFI_DEBUGFS) 850#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_IWLWIFI_DEBUGFS)
844 kfree(mvm->d3_resume_sram); 851 kfree(mvm->d3_resume_sram);
845#endif 852#endif
846 iwl_fw_runtime_exit(&mvm->fwrt);
847 iwl_trans_op_mode_leave(mvm->trans); 853 iwl_trans_op_mode_leave(mvm->trans);
848 854
849 iwl_phy_db_free(mvm->phy_db); 855 iwl_phy_db_free(mvm->phy_db);
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rs.c b/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
index 60abb0084ee5..47f4c7a1d80d 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
@@ -2684,7 +2684,8 @@ static void rs_get_initial_rate(struct iwl_mvm *mvm,
2684 struct ieee80211_sta *sta, 2684 struct ieee80211_sta *sta,
2685 struct iwl_lq_sta *lq_sta, 2685 struct iwl_lq_sta *lq_sta,
2686 enum nl80211_band band, 2686 enum nl80211_band band,
2687 struct rs_rate *rate) 2687 struct rs_rate *rate,
2688 bool init)
2688{ 2689{
2689 int i, nentries; 2690 int i, nentries;
2690 unsigned long active_rate; 2691 unsigned long active_rate;
@@ -2738,14 +2739,25 @@ static void rs_get_initial_rate(struct iwl_mvm *mvm,
2738 */ 2739 */
2739 if (sta->vht_cap.vht_supported && 2740 if (sta->vht_cap.vht_supported &&
2740 best_rssi > IWL_RS_LOW_RSSI_THRESHOLD) { 2741 best_rssi > IWL_RS_LOW_RSSI_THRESHOLD) {
2741 switch (sta->bandwidth) { 2742 /*
2742 case IEEE80211_STA_RX_BW_160: 2743 * In AP mode, when a new station associates, rs is initialized
2743 case IEEE80211_STA_RX_BW_80: 2744 * immediately upon association completion, before the phy
2744 case IEEE80211_STA_RX_BW_40: 2745 * context is updated with the association parameters, so the
2746 * sta bandwidth might be wider than the phy context allows.
2747 * To avoid this issue, always initialize rs with 20mhz
2748 * bandwidth rate, and after authorization, when the phy context
2749 * is already up-to-date, re-init rs with the correct bw.
2750 */
2751 u32 bw = init ? RATE_MCS_CHAN_WIDTH_20 : rs_bw_from_sta_bw(sta);
2752
2753 switch (bw) {
2754 case RATE_MCS_CHAN_WIDTH_40:
2755 case RATE_MCS_CHAN_WIDTH_80:
2756 case RATE_MCS_CHAN_WIDTH_160:
2745 initial_rates = rs_optimal_rates_vht; 2757 initial_rates = rs_optimal_rates_vht;
2746 nentries = ARRAY_SIZE(rs_optimal_rates_vht); 2758 nentries = ARRAY_SIZE(rs_optimal_rates_vht);
2747 break; 2759 break;
2748 case IEEE80211_STA_RX_BW_20: 2760 case RATE_MCS_CHAN_WIDTH_20:
2749 initial_rates = rs_optimal_rates_vht_20mhz; 2761 initial_rates = rs_optimal_rates_vht_20mhz;
2750 nentries = ARRAY_SIZE(rs_optimal_rates_vht_20mhz); 2762 nentries = ARRAY_SIZE(rs_optimal_rates_vht_20mhz);
2751 break; 2763 break;
@@ -2756,7 +2768,7 @@ static void rs_get_initial_rate(struct iwl_mvm *mvm,
2756 2768
2757 active_rate = lq_sta->active_siso_rate; 2769 active_rate = lq_sta->active_siso_rate;
2758 rate->type = LQ_VHT_SISO; 2770 rate->type = LQ_VHT_SISO;
2759 rate->bw = rs_bw_from_sta_bw(sta); 2771 rate->bw = bw;
2760 } else if (sta->ht_cap.ht_supported && 2772 } else if (sta->ht_cap.ht_supported &&
2761 best_rssi > IWL_RS_LOW_RSSI_THRESHOLD) { 2773 best_rssi > IWL_RS_LOW_RSSI_THRESHOLD) {
2762 initial_rates = rs_optimal_rates_ht; 2774 initial_rates = rs_optimal_rates_ht;
@@ -2839,7 +2851,7 @@ static void rs_initialize_lq(struct iwl_mvm *mvm,
2839 tbl = &(lq_sta->lq_info[active_tbl]); 2851 tbl = &(lq_sta->lq_info[active_tbl]);
2840 rate = &tbl->rate; 2852 rate = &tbl->rate;
2841 2853
2842 rs_get_initial_rate(mvm, sta, lq_sta, band, rate); 2854 rs_get_initial_rate(mvm, sta, lq_sta, band, rate, init);
2843 rs_init_optimal_rate(mvm, sta, lq_sta); 2855 rs_init_optimal_rate(mvm, sta, lq_sta);
2844 2856
2845 WARN_ONCE(rate->ant != ANT_A && rate->ant != ANT_B, 2857 WARN_ONCE(rate->ant != ANT_A && rate->ant != ANT_B,
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
index a3f7c1bf3cc8..580de5851fc7 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
@@ -71,6 +71,7 @@ static inline int iwl_mvm_check_pn(struct iwl_mvm *mvm, struct sk_buff *skb,
71 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 71 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
72 struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb); 72 struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb);
73 struct iwl_mvm_key_pn *ptk_pn; 73 struct iwl_mvm_key_pn *ptk_pn;
74 int res;
74 u8 tid, keyidx; 75 u8 tid, keyidx;
75 u8 pn[IEEE80211_CCMP_PN_LEN]; 76 u8 pn[IEEE80211_CCMP_PN_LEN];
76 u8 *extiv; 77 u8 *extiv;
@@ -127,12 +128,13 @@ static inline int iwl_mvm_check_pn(struct iwl_mvm *mvm, struct sk_buff *skb,
127 pn[4] = extiv[1]; 128 pn[4] = extiv[1];
128 pn[5] = extiv[0]; 129 pn[5] = extiv[0];
129 130
130 if (memcmp(pn, ptk_pn->q[queue].pn[tid], 131 res = memcmp(pn, ptk_pn->q[queue].pn[tid], IEEE80211_CCMP_PN_LEN);
131 IEEE80211_CCMP_PN_LEN) <= 0) 132 if (res < 0)
133 return -1;
134 if (!res && !(stats->flag & RX_FLAG_ALLOW_SAME_PN))
132 return -1; 135 return -1;
133 136
134 if (!(stats->flag & RX_FLAG_AMSDU_MORE)) 137 memcpy(ptk_pn->q[queue].pn[tid], pn, IEEE80211_CCMP_PN_LEN);
135 memcpy(ptk_pn->q[queue].pn[tid], pn, IEEE80211_CCMP_PN_LEN);
136 stats->flag |= RX_FLAG_PN_VALIDATED; 138 stats->flag |= RX_FLAG_PN_VALIDATED;
137 139
138 return 0; 140 return 0;
@@ -314,28 +316,21 @@ static void iwl_mvm_rx_csum(struct ieee80211_sta *sta,
314} 316}
315 317
316/* 318/*
317 * returns true if a packet outside BA session is a duplicate and 319 * returns true if a packet is a duplicate and should be dropped.
318 * should be dropped 320 * Updates AMSDU PN tracking info
319 */ 321 */
320static bool iwl_mvm_is_nonagg_dup(struct ieee80211_sta *sta, int queue, 322static bool iwl_mvm_is_dup(struct ieee80211_sta *sta, int queue,
321 struct ieee80211_rx_status *rx_status, 323 struct ieee80211_rx_status *rx_status,
322 struct ieee80211_hdr *hdr, 324 struct ieee80211_hdr *hdr,
323 struct iwl_rx_mpdu_desc *desc) 325 struct iwl_rx_mpdu_desc *desc)
324{ 326{
325 struct iwl_mvm_sta *mvm_sta; 327 struct iwl_mvm_sta *mvm_sta;
326 struct iwl_mvm_rxq_dup_data *dup_data; 328 struct iwl_mvm_rxq_dup_data *dup_data;
327 u8 baid, tid, sub_frame_idx; 329 u8 tid, sub_frame_idx;
328 330
329 if (WARN_ON(IS_ERR_OR_NULL(sta))) 331 if (WARN_ON(IS_ERR_OR_NULL(sta)))
330 return false; 332 return false;
331 333
332 baid = (le32_to_cpu(desc->reorder_data) &
333 IWL_RX_MPDU_REORDER_BAID_MASK) >>
334 IWL_RX_MPDU_REORDER_BAID_SHIFT;
335
336 if (baid != IWL_RX_REORDER_DATA_INVALID_BAID)
337 return false;
338
339 mvm_sta = iwl_mvm_sta_from_mac80211(sta); 334 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
340 dup_data = &mvm_sta->dup_data[queue]; 335 dup_data = &mvm_sta->dup_data[queue];
341 336
@@ -365,6 +360,12 @@ static bool iwl_mvm_is_nonagg_dup(struct ieee80211_sta *sta, int queue,
365 dup_data->last_sub_frame[tid] >= sub_frame_idx)) 360 dup_data->last_sub_frame[tid] >= sub_frame_idx))
366 return true; 361 return true;
367 362
363 /* Allow same PN as the first subframe for following sub frames */
364 if (dup_data->last_seq[tid] == hdr->seq_ctrl &&
365 sub_frame_idx > dup_data->last_sub_frame[tid] &&
366 desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU)
367 rx_status->flag |= RX_FLAG_ALLOW_SAME_PN;
368
368 dup_data->last_seq[tid] = hdr->seq_ctrl; 369 dup_data->last_seq[tid] = hdr->seq_ctrl;
369 dup_data->last_sub_frame[tid] = sub_frame_idx; 370 dup_data->last_sub_frame[tid] = sub_frame_idx;
370 371
@@ -971,7 +972,7 @@ void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
971 if (ieee80211_is_data(hdr->frame_control)) 972 if (ieee80211_is_data(hdr->frame_control))
972 iwl_mvm_rx_csum(sta, skb, desc); 973 iwl_mvm_rx_csum(sta, skb, desc);
973 974
974 if (iwl_mvm_is_nonagg_dup(sta, queue, rx_status, hdr, desc)) { 975 if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) {
975 kfree_skb(skb); 976 kfree_skb(skb);
976 goto out; 977 goto out;
977 } 978 }
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c
index 6b2674e02606..630e23cb0ffb 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c
@@ -2039,7 +2039,7 @@ int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2039 struct iwl_trans_txq_scd_cfg cfg = { 2039 struct iwl_trans_txq_scd_cfg cfg = {
2040 .fifo = IWL_MVM_TX_FIFO_MCAST, 2040 .fifo = IWL_MVM_TX_FIFO_MCAST,
2041 .sta_id = msta->sta_id, 2041 .sta_id = msta->sta_id,
2042 .tid = IWL_MAX_TID_COUNT, 2042 .tid = 0,
2043 .aggregate = false, 2043 .aggregate = false,
2044 .frame_limit = IWL_FRAME_LIMIT, 2044 .frame_limit = IWL_FRAME_LIMIT,
2045 }; 2045 };
@@ -2053,6 +2053,17 @@ int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2053 return -ENOTSUPP; 2053 return -ENOTSUPP;
2054 2054
2055 /* 2055 /*
2056 * In IBSS, ieee80211_check_queues() sets the cab_queue to be
2057 * invalid, so make sure we use the queue we want.
2058 * Note that this is done here as we want to avoid making DQA
2059 * changes in mac80211 layer.
2060 */
2061 if (vif->type == NL80211_IFTYPE_ADHOC) {
2062 vif->cab_queue = IWL_MVM_DQA_GCAST_QUEUE;
2063 mvmvif->cab_queue = vif->cab_queue;
2064 }
2065
2066 /*
2056 * While in previous FWs we had to exclude cab queue from TFD queue 2067 * While in previous FWs we had to exclude cab queue from TFD queue
2057 * mask, now it is needed as any other queue. 2068 * mask, now it is needed as any other queue.
2058 */ 2069 */
@@ -2079,24 +2090,13 @@ int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2079 if (iwl_mvm_has_new_tx_api(mvm)) { 2090 if (iwl_mvm_has_new_tx_api(mvm)) {
2080 int queue = iwl_mvm_tvqm_enable_txq(mvm, vif->cab_queue, 2091 int queue = iwl_mvm_tvqm_enable_txq(mvm, vif->cab_queue,
2081 msta->sta_id, 2092 msta->sta_id,
2082 IWL_MAX_TID_COUNT, 2093 0,
2083 timeout); 2094 timeout);
2084 mvmvif->cab_queue = queue; 2095 mvmvif->cab_queue = queue;
2085 } else if (!fw_has_api(&mvm->fw->ucode_capa, 2096 } else if (!fw_has_api(&mvm->fw->ucode_capa,
2086 IWL_UCODE_TLV_API_STA_TYPE)) { 2097 IWL_UCODE_TLV_API_STA_TYPE))
2087 /*
2088 * In IBSS, ieee80211_check_queues() sets the cab_queue to be
2089 * invalid, so make sure we use the queue we want.
2090 * Note that this is done here as we want to avoid making DQA
2091 * changes in mac80211 layer.
2092 */
2093 if (vif->type == NL80211_IFTYPE_ADHOC) {
2094 vif->cab_queue = IWL_MVM_DQA_GCAST_QUEUE;
2095 mvmvif->cab_queue = vif->cab_queue;
2096 }
2097 iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0, 2098 iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0,
2098 &cfg, timeout); 2099 &cfg, timeout);
2099 }
2100 2100
2101 return 0; 2101 return 0;
2102} 2102}
@@ -2115,7 +2115,7 @@ int iwl_mvm_rm_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2115 iwl_mvm_flush_sta(mvm, &mvmvif->mcast_sta, true, 0); 2115 iwl_mvm_flush_sta(mvm, &mvmvif->mcast_sta, true, 0);
2116 2116
2117 iwl_mvm_disable_txq(mvm, mvmvif->cab_queue, vif->cab_queue, 2117 iwl_mvm_disable_txq(mvm, mvmvif->cab_queue, vif->cab_queue,
2118 IWL_MAX_TID_COUNT, 0); 2118 0, 0);
2119 2119
2120 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->mcast_sta.sta_id); 2120 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->mcast_sta.sta_id);
2121 if (ret) 2121 if (ret)
@@ -3170,8 +3170,9 @@ static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
3170 int ret, size; 3170 int ret, size;
3171 u32 status; 3171 u32 status;
3172 3172
3173 /* This is a valid situation for GTK removal */
3173 if (sta_id == IWL_MVM_INVALID_STA) 3174 if (sta_id == IWL_MVM_INVALID_STA)
3174 return -EINVAL; 3175 return 0;
3175 3176
3176 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & 3177 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
3177 STA_KEY_FLG_KEYID_MSK); 3178 STA_KEY_FLG_KEYID_MSK);
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c b/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c
index 200ab50ec86b..acb217e666db 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/time-event.c
@@ -616,7 +616,7 @@ void iwl_mvm_protect_session(struct iwl_mvm *mvm,
616 time_cmd.repeat = 1; 616 time_cmd.repeat = 1;
617 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START | 617 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
618 TE_V2_NOTIF_HOST_EVENT_END | 618 TE_V2_NOTIF_HOST_EVENT_END |
619 T2_V2_START_IMMEDIATELY); 619 TE_V2_START_IMMEDIATELY);
620 620
621 if (!wait_for_notif) { 621 if (!wait_for_notif) {
622 iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd); 622 iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
@@ -803,7 +803,7 @@ int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
803 time_cmd.repeat = 1; 803 time_cmd.repeat = 1;
804 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START | 804 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
805 TE_V2_NOTIF_HOST_EVENT_END | 805 TE_V2_NOTIF_HOST_EVENT_END |
806 T2_V2_START_IMMEDIATELY); 806 TE_V2_START_IMMEDIATELY);
807 807
808 return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd); 808 return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
809} 809}
@@ -913,6 +913,8 @@ int iwl_mvm_schedule_csa_period(struct iwl_mvm *mvm,
913 time_cmd.interval = cpu_to_le32(1); 913 time_cmd.interval = cpu_to_le32(1);
914 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START | 914 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
915 TE_V2_ABSENCE); 915 TE_V2_ABSENCE);
916 if (!apply_time)
917 time_cmd.policy |= cpu_to_le16(TE_V2_START_IMMEDIATELY);
916 918
917 return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd); 919 return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
918} 920}
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
index dda77b327c98..af6dfceab6b8 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
@@ -419,11 +419,11 @@ static void iwl_mvm_set_tx_cmd_crypto(struct iwl_mvm *mvm,
419{ 419{
420 struct ieee80211_key_conf *keyconf = info->control.hw_key; 420 struct ieee80211_key_conf *keyconf = info->control.hw_key;
421 u8 *crypto_hdr = skb_frag->data + hdrlen; 421 u8 *crypto_hdr = skb_frag->data + hdrlen;
422 enum iwl_tx_cmd_sec_ctrl type = TX_CMD_SEC_CCM;
422 u64 pn; 423 u64 pn;
423 424
424 switch (keyconf->cipher) { 425 switch (keyconf->cipher) {
425 case WLAN_CIPHER_SUITE_CCMP: 426 case WLAN_CIPHER_SUITE_CCMP:
426 case WLAN_CIPHER_SUITE_CCMP_256:
427 iwl_mvm_set_tx_cmd_ccmp(info, tx_cmd); 427 iwl_mvm_set_tx_cmd_ccmp(info, tx_cmd);
428 iwl_mvm_set_tx_cmd_pn(info, crypto_hdr); 428 iwl_mvm_set_tx_cmd_pn(info, crypto_hdr);
429 break; 429 break;
@@ -447,13 +447,16 @@ static void iwl_mvm_set_tx_cmd_crypto(struct iwl_mvm *mvm,
447 break; 447 break;
448 case WLAN_CIPHER_SUITE_GCMP: 448 case WLAN_CIPHER_SUITE_GCMP:
449 case WLAN_CIPHER_SUITE_GCMP_256: 449 case WLAN_CIPHER_SUITE_GCMP_256:
450 type = TX_CMD_SEC_GCMP;
451 /* Fall through */
452 case WLAN_CIPHER_SUITE_CCMP_256:
450 /* TODO: Taking the key from the table might introduce a race 453 /* TODO: Taking the key from the table might introduce a race
451 * when PTK rekeying is done, having an old packets with a PN 454 * when PTK rekeying is done, having an old packets with a PN
452 * based on the old key but the message encrypted with a new 455 * based on the old key but the message encrypted with a new
453 * one. 456 * one.
454 * Need to handle this. 457 * Need to handle this.
455 */ 458 */
456 tx_cmd->sec_ctl |= TX_CMD_SEC_GCMP | TX_CMD_SEC_KEY_FROM_TABLE; 459 tx_cmd->sec_ctl |= type | TX_CMD_SEC_KEY_FROM_TABLE;
457 tx_cmd->key[0] = keyconf->hw_key_idx; 460 tx_cmd->key[0] = keyconf->hw_key_idx;
458 iwl_mvm_set_tx_cmd_pn(info, crypto_hdr); 461 iwl_mvm_set_tx_cmd_pn(info, crypto_hdr);
459 break; 462 break;
@@ -645,7 +648,11 @@ int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb)
645 if (info.control.vif->type == NL80211_IFTYPE_P2P_DEVICE || 648 if (info.control.vif->type == NL80211_IFTYPE_P2P_DEVICE ||
646 info.control.vif->type == NL80211_IFTYPE_AP || 649 info.control.vif->type == NL80211_IFTYPE_AP ||
647 info.control.vif->type == NL80211_IFTYPE_ADHOC) { 650 info.control.vif->type == NL80211_IFTYPE_ADHOC) {
648 sta_id = mvmvif->bcast_sta.sta_id; 651 if (info.control.vif->type == NL80211_IFTYPE_P2P_DEVICE)
652 sta_id = mvmvif->bcast_sta.sta_id;
653 else
654 sta_id = mvmvif->mcast_sta.sta_id;
655
649 queue = iwl_mvm_get_ctrl_vif_queue(mvm, &info, 656 queue = iwl_mvm_get_ctrl_vif_queue(mvm, &info,
650 hdr->frame_control); 657 hdr->frame_control);
651 if (queue < 0) 658 if (queue < 0)
diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c
index 6d0a907d5ba5..fabae0f60683 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c
@@ -147,7 +147,7 @@ static void iwl_pcie_gen2_tfd_unmap(struct iwl_trans *trans,
147 /* Sanity check on number of chunks */ 147 /* Sanity check on number of chunks */
148 num_tbs = iwl_pcie_gen2_get_num_tbs(trans, tfd); 148 num_tbs = iwl_pcie_gen2_get_num_tbs(trans, tfd);
149 149
150 if (num_tbs >= trans_pcie->max_tbs) { 150 if (num_tbs > trans_pcie->max_tbs) {
151 IWL_ERR(trans, "Too many chunks: %i\n", num_tbs); 151 IWL_ERR(trans, "Too many chunks: %i\n", num_tbs);
152 return; 152 return;
153 } 153 }
diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
index 3f85713c41dc..1a566287993d 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
@@ -378,7 +378,7 @@ static void iwl_pcie_tfd_unmap(struct iwl_trans *trans,
378 /* Sanity check on number of chunks */ 378 /* Sanity check on number of chunks */
379 num_tbs = iwl_pcie_tfd_get_num_tbs(trans, tfd); 379 num_tbs = iwl_pcie_tfd_get_num_tbs(trans, tfd);
380 380
381 if (num_tbs >= trans_pcie->max_tbs) { 381 if (num_tbs > trans_pcie->max_tbs) {
382 IWL_ERR(trans, "Too many chunks: %i\n", num_tbs); 382 IWL_ERR(trans, "Too many chunks: %i\n", num_tbs);
383 /* @todo issue fatal error, it is quite serious situation */ 383 /* @todo issue fatal error, it is quite serious situation */
384 return; 384 return;
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 1cf22e62e3dd..35b21f8152bb 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -2727,6 +2727,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
2727 mutex_init(&data->mutex); 2727 mutex_init(&data->mutex);
2728 2728
2729 data->netgroup = hwsim_net_get_netgroup(net); 2729 data->netgroup = hwsim_net_get_netgroup(net);
2730 data->wmediumd = hwsim_net_get_wmediumd(net);
2730 2731
2731 /* Enable frame retransmissions for lossy channels */ 2732 /* Enable frame retransmissions for lossy channels */
2732 hw->max_rates = 4; 2733 hw->max_rates = 4;
@@ -3516,7 +3517,7 @@ static int __init init_mac80211_hwsim(void)
3516 3517
3517 spin_lock_init(&hwsim_radio_lock); 3518 spin_lock_init(&hwsim_radio_lock);
3518 3519
3519 hwsim_wq = alloc_workqueue("hwsim_wq",WQ_MEM_RECLAIM,0); 3520 hwsim_wq = alloc_workqueue("hwsim_wq", 0, 0);
3520 if (!hwsim_wq) 3521 if (!hwsim_wq)
3521 return -ENOMEM; 3522 return -ENOMEM;
3522 rhashtable_init(&hwsim_radios_rht, &hwsim_rht_params); 3523 rhashtable_init(&hwsim_radios_rht, &hwsim_rht_params);
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c
index f9ccd13c79f9..e7bbbc95cdb1 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c
@@ -1125,7 +1125,8 @@ static void _rtl8723be_enable_aspm_back_door(struct ieee80211_hw *hw)
1125 1125
1126 /* Configuration Space offset 0x70f BIT7 is used to control L0S */ 1126 /* Configuration Space offset 0x70f BIT7 is used to control L0S */
1127 tmp8 = _rtl8723be_dbi_read(rtlpriv, 0x70f); 1127 tmp8 = _rtl8723be_dbi_read(rtlpriv, 0x70f);
1128 _rtl8723be_dbi_write(rtlpriv, 0x70f, tmp8 | BIT(7)); 1128 _rtl8723be_dbi_write(rtlpriv, 0x70f, tmp8 | BIT(7) |
1129 ASPM_L1_LATENCY << 3);
1129 1130
1130 /* Configuration Space offset 0x719 Bit3 is for L1 1131 /* Configuration Space offset 0x719 Bit3 is for L1
1131 * BIT4 is for clock request 1132 * BIT4 is for clock request
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 8328d395e332..3127bc8633ca 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -2005,7 +2005,10 @@ static void netback_changed(struct xenbus_device *dev,
2005 case XenbusStateInitialised: 2005 case XenbusStateInitialised:
2006 case XenbusStateReconfiguring: 2006 case XenbusStateReconfiguring:
2007 case XenbusStateReconfigured: 2007 case XenbusStateReconfigured:
2008 break;
2009
2008 case XenbusStateUnknown: 2010 case XenbusStateUnknown:
2011 wake_up_all(&module_unload_q);
2009 break; 2012 break;
2010 2013
2011 case XenbusStateInitWait: 2014 case XenbusStateInitWait:
@@ -2136,7 +2139,9 @@ static int xennet_remove(struct xenbus_device *dev)
2136 xenbus_switch_state(dev, XenbusStateClosing); 2139 xenbus_switch_state(dev, XenbusStateClosing);
2137 wait_event(module_unload_q, 2140 wait_event(module_unload_q,
2138 xenbus_read_driver_state(dev->otherend) == 2141 xenbus_read_driver_state(dev->otherend) ==
2139 XenbusStateClosing); 2142 XenbusStateClosing ||
2143 xenbus_read_driver_state(dev->otherend) ==
2144 XenbusStateUnknown);
2140 2145
2141 xenbus_switch_state(dev, XenbusStateClosed); 2146 xenbus_switch_state(dev, XenbusStateClosed);
2142 wait_event(module_unload_q, 2147 wait_event(module_unload_q,
diff --git a/drivers/nvdimm/blk.c b/drivers/nvdimm/blk.c
index 345acca576b3..1bd7b3734751 100644
--- a/drivers/nvdimm/blk.c
+++ b/drivers/nvdimm/blk.c
@@ -278,8 +278,6 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)
278 disk->queue = q; 278 disk->queue = q;
279 disk->flags = GENHD_FL_EXT_DEVT; 279 disk->flags = GENHD_FL_EXT_DEVT;
280 nvdimm_namespace_disk_name(&nsblk->common, disk->disk_name); 280 nvdimm_namespace_disk_name(&nsblk->common, disk->disk_name);
281 set_capacity(disk, 0);
282 device_add_disk(dev, disk);
283 281
284 if (devm_add_action_or_reset(dev, nd_blk_release_disk, disk)) 282 if (devm_add_action_or_reset(dev, nd_blk_release_disk, disk))
285 return -ENOMEM; 283 return -ENOMEM;
@@ -292,6 +290,7 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)
292 } 290 }
293 291
294 set_capacity(disk, available_disk_size >> SECTOR_SHIFT); 292 set_capacity(disk, available_disk_size >> SECTOR_SHIFT);
293 device_add_disk(dev, disk);
295 revalidate_disk(disk); 294 revalidate_disk(disk);
296 return 0; 295 return 0;
297} 296}
diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
index 2ef544f10ec8..4b95ac513de2 100644
--- a/drivers/nvdimm/btt.c
+++ b/drivers/nvdimm/btt.c
@@ -1545,8 +1545,6 @@ static int btt_blk_init(struct btt *btt)
1545 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, btt->btt_queue); 1545 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, btt->btt_queue);
1546 btt->btt_queue->queuedata = btt; 1546 btt->btt_queue->queuedata = btt;
1547 1547
1548 set_capacity(btt->btt_disk, 0);
1549 device_add_disk(&btt->nd_btt->dev, btt->btt_disk);
1550 if (btt_meta_size(btt)) { 1548 if (btt_meta_size(btt)) {
1551 int rc = nd_integrity_init(btt->btt_disk, btt_meta_size(btt)); 1549 int rc = nd_integrity_init(btt->btt_disk, btt_meta_size(btt));
1552 1550
@@ -1558,6 +1556,7 @@ static int btt_blk_init(struct btt *btt)
1558 } 1556 }
1559 } 1557 }
1560 set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9); 1558 set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9);
1559 device_add_disk(&btt->nd_btt->dev, btt->btt_disk);
1561 btt->nd_btt->size = btt->nlba * (u64)btt->sector_size; 1560 btt->nd_btt->size = btt->nlba * (u64)btt->sector_size;
1562 revalidate_disk(btt->btt_disk); 1561 revalidate_disk(btt->btt_disk);
1563 1562
diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c
index f5c4e8c6e29d..2f4d18752c97 100644
--- a/drivers/nvdimm/pfn_devs.c
+++ b/drivers/nvdimm/pfn_devs.c
@@ -304,7 +304,7 @@ static const struct attribute_group *nd_pfn_attribute_groups[] = {
304struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn, 304struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
305 struct nd_namespace_common *ndns) 305 struct nd_namespace_common *ndns)
306{ 306{
307 struct device *dev = &nd_pfn->dev; 307 struct device *dev;
308 308
309 if (!nd_pfn) 309 if (!nd_pfn)
310 return NULL; 310 return NULL;
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 10041ac4032c..06f8dcc52ca6 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -335,8 +335,7 @@ static int pmem_attach_disk(struct device *dev,
335 dev_warn(dev, "unable to guarantee persistence of writes\n"); 335 dev_warn(dev, "unable to guarantee persistence of writes\n");
336 fua = 0; 336 fua = 0;
337 } 337 }
338 wbc = nvdimm_has_cache(nd_region) && 338 wbc = nvdimm_has_cache(nd_region);
339 !test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags);
340 339
341 if (!devm_request_mem_region(dev, res->start, resource_size(res), 340 if (!devm_request_mem_region(dev, res->start, resource_size(res),
342 dev_name(&ndns->dev))) { 341 dev_name(&ndns->dev))) {
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index e6d01911e092..1593e1806b16 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -532,11 +532,13 @@ static ssize_t persistence_domain_show(struct device *dev,
532 struct device_attribute *attr, char *buf) 532 struct device_attribute *attr, char *buf)
533{ 533{
534 struct nd_region *nd_region = to_nd_region(dev); 534 struct nd_region *nd_region = to_nd_region(dev);
535 unsigned long flags = nd_region->flags;
536 535
537 return sprintf(buf, "%s%s\n", 536 if (test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags))
538 flags & BIT(ND_REGION_PERSIST_CACHE) ? "cpu_cache " : "", 537 return sprintf(buf, "cpu_cache\n");
539 flags & BIT(ND_REGION_PERSIST_MEMCTRL) ? "memory_controller " : ""); 538 else if (test_bit(ND_REGION_PERSIST_MEMCTRL, &nd_region->flags))
539 return sprintf(buf, "memory_controller\n");
540 else
541 return sprintf(buf, "\n");
540} 542}
541static DEVICE_ATTR_RO(persistence_domain); 543static DEVICE_ATTR_RO(persistence_domain);
542 544
@@ -593,6 +595,13 @@ static umode_t region_visible(struct kobject *kobj, struct attribute *a, int n)
593 return 0; 595 return 0;
594 } 596 }
595 597
598 if (a == &dev_attr_persistence_domain.attr) {
599 if ((nd_region->flags & (BIT(ND_REGION_PERSIST_CACHE)
600 | BIT(ND_REGION_PERSIST_MEMCTRL))) == 0)
601 return 0;
602 return a->mode;
603 }
604
596 if (a != &dev_attr_set_cookie.attr 605 if (a != &dev_attr_set_cookie.attr
597 && a != &dev_attr_available_size.attr) 606 && a != &dev_attr_available_size.attr)
598 return a->mode; 607 return a->mode;
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f431c32774f3..7aeca5db7916 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -120,8 +120,12 @@ int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl)
120 int ret; 120 int ret;
121 121
122 ret = nvme_reset_ctrl(ctrl); 122 ret = nvme_reset_ctrl(ctrl);
123 if (!ret) 123 if (!ret) {
124 flush_work(&ctrl->reset_work); 124 flush_work(&ctrl->reset_work);
125 if (ctrl->state != NVME_CTRL_LIVE)
126 ret = -ENETRESET;
127 }
128
125 return ret; 129 return ret;
126} 130}
127EXPORT_SYMBOL_GPL(nvme_reset_ctrl_sync); 131EXPORT_SYMBOL_GPL(nvme_reset_ctrl_sync);
@@ -265,7 +269,7 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
265 switch (new_state) { 269 switch (new_state) {
266 case NVME_CTRL_ADMIN_ONLY: 270 case NVME_CTRL_ADMIN_ONLY:
267 switch (old_state) { 271 switch (old_state) {
268 case NVME_CTRL_RECONNECTING: 272 case NVME_CTRL_CONNECTING:
269 changed = true; 273 changed = true;
270 /* FALLTHRU */ 274 /* FALLTHRU */
271 default: 275 default:
@@ -276,7 +280,7 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
276 switch (old_state) { 280 switch (old_state) {
277 case NVME_CTRL_NEW: 281 case NVME_CTRL_NEW:
278 case NVME_CTRL_RESETTING: 282 case NVME_CTRL_RESETTING:
279 case NVME_CTRL_RECONNECTING: 283 case NVME_CTRL_CONNECTING:
280 changed = true; 284 changed = true;
281 /* FALLTHRU */ 285 /* FALLTHRU */
282 default: 286 default:
@@ -294,9 +298,9 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
294 break; 298 break;
295 } 299 }
296 break; 300 break;
297 case NVME_CTRL_RECONNECTING: 301 case NVME_CTRL_CONNECTING:
298 switch (old_state) { 302 switch (old_state) {
299 case NVME_CTRL_LIVE: 303 case NVME_CTRL_NEW:
300 case NVME_CTRL_RESETTING: 304 case NVME_CTRL_RESETTING:
301 changed = true; 305 changed = true;
302 /* FALLTHRU */ 306 /* FALLTHRU */
@@ -309,7 +313,7 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
309 case NVME_CTRL_LIVE: 313 case NVME_CTRL_LIVE:
310 case NVME_CTRL_ADMIN_ONLY: 314 case NVME_CTRL_ADMIN_ONLY:
311 case NVME_CTRL_RESETTING: 315 case NVME_CTRL_RESETTING:
312 case NVME_CTRL_RECONNECTING: 316 case NVME_CTRL_CONNECTING:
313 changed = true; 317 changed = true;
314 /* FALLTHRU */ 318 /* FALLTHRU */
315 default: 319 default:
@@ -518,9 +522,11 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
518 u64 slba = nvme_block_nr(ns, bio->bi_iter.bi_sector); 522 u64 slba = nvme_block_nr(ns, bio->bi_iter.bi_sector);
519 u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift; 523 u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift;
520 524
521 range[n].cattr = cpu_to_le32(0); 525 if (n < segments) {
522 range[n].nlb = cpu_to_le32(nlb); 526 range[n].cattr = cpu_to_le32(0);
523 range[n].slba = cpu_to_le64(slba); 527 range[n].nlb = cpu_to_le32(nlb);
528 range[n].slba = cpu_to_le64(slba);
529 }
524 n++; 530 n++;
525 } 531 }
526 532
@@ -794,13 +800,9 @@ static void nvme_keep_alive_end_io(struct request *rq, blk_status_t status)
794 800
795static int nvme_keep_alive(struct nvme_ctrl *ctrl) 801static int nvme_keep_alive(struct nvme_ctrl *ctrl)
796{ 802{
797 struct nvme_command c;
798 struct request *rq; 803 struct request *rq;
799 804
800 memset(&c, 0, sizeof(c)); 805 rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd, BLK_MQ_REQ_RESERVED,
801 c.common.opcode = nvme_admin_keep_alive;
802
803 rq = nvme_alloc_request(ctrl->admin_q, &c, BLK_MQ_REQ_RESERVED,
804 NVME_QID_ANY); 806 NVME_QID_ANY);
805 if (IS_ERR(rq)) 807 if (IS_ERR(rq))
806 return PTR_ERR(rq); 808 return PTR_ERR(rq);
@@ -832,6 +834,8 @@ void nvme_start_keep_alive(struct nvme_ctrl *ctrl)
832 return; 834 return;
833 835
834 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); 836 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work);
837 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd));
838 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive;
835 schedule_delayed_work(&ctrl->ka_work, ctrl->kato * HZ); 839 schedule_delayed_work(&ctrl->ka_work, ctrl->kato * HZ);
836} 840}
837EXPORT_SYMBOL_GPL(nvme_start_keep_alive); 841EXPORT_SYMBOL_GPL(nvme_start_keep_alive);
@@ -1117,14 +1121,19 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
1117 1121
1118static void nvme_update_formats(struct nvme_ctrl *ctrl) 1122static void nvme_update_formats(struct nvme_ctrl *ctrl)
1119{ 1123{
1120 struct nvme_ns *ns; 1124 struct nvme_ns *ns, *next;
1125 LIST_HEAD(rm_list);
1121 1126
1122 mutex_lock(&ctrl->namespaces_mutex); 1127 mutex_lock(&ctrl->namespaces_mutex);
1123 list_for_each_entry(ns, &ctrl->namespaces, list) { 1128 list_for_each_entry(ns, &ctrl->namespaces, list) {
1124 if (ns->disk && nvme_revalidate_disk(ns->disk)) 1129 if (ns->disk && nvme_revalidate_disk(ns->disk)) {
1125 nvme_ns_remove(ns); 1130 list_move_tail(&ns->list, &rm_list);
1131 }
1126 } 1132 }
1127 mutex_unlock(&ctrl->namespaces_mutex); 1133 mutex_unlock(&ctrl->namespaces_mutex);
1134
1135 list_for_each_entry_safe(ns, next, &rm_list, list)
1136 nvme_ns_remove(ns);
1128} 1137}
1129 1138
1130static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects) 1139static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
@@ -2687,7 +2696,7 @@ static ssize_t nvme_sysfs_show_state(struct device *dev,
2687 [NVME_CTRL_LIVE] = "live", 2696 [NVME_CTRL_LIVE] = "live",
2688 [NVME_CTRL_ADMIN_ONLY] = "only-admin", 2697 [NVME_CTRL_ADMIN_ONLY] = "only-admin",
2689 [NVME_CTRL_RESETTING] = "resetting", 2698 [NVME_CTRL_RESETTING] = "resetting",
2690 [NVME_CTRL_RECONNECTING]= "reconnecting", 2699 [NVME_CTRL_CONNECTING] = "connecting",
2691 [NVME_CTRL_DELETING] = "deleting", 2700 [NVME_CTRL_DELETING] = "deleting",
2692 [NVME_CTRL_DEAD] = "dead", 2701 [NVME_CTRL_DEAD] = "dead",
2693 }; 2702 };
@@ -2835,7 +2844,7 @@ out:
2835} 2844}
2836 2845
2837static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, 2846static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
2838 struct nvme_id_ns *id, bool *new) 2847 struct nvme_id_ns *id)
2839{ 2848{
2840 struct nvme_ctrl *ctrl = ns->ctrl; 2849 struct nvme_ctrl *ctrl = ns->ctrl;
2841 bool is_shared = id->nmic & (1 << 0); 2850 bool is_shared = id->nmic & (1 << 0);
@@ -2851,8 +2860,6 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
2851 ret = PTR_ERR(head); 2860 ret = PTR_ERR(head);
2852 goto out_unlock; 2861 goto out_unlock;
2853 } 2862 }
2854
2855 *new = true;
2856 } else { 2863 } else {
2857 struct nvme_ns_ids ids; 2864 struct nvme_ns_ids ids;
2858 2865
@@ -2864,8 +2871,6 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
2864 ret = -EINVAL; 2871 ret = -EINVAL;
2865 goto out_unlock; 2872 goto out_unlock;
2866 } 2873 }
2867
2868 *new = false;
2869 } 2874 }
2870 2875
2871 list_add_tail(&ns->siblings, &head->list); 2876 list_add_tail(&ns->siblings, &head->list);
@@ -2936,7 +2941,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
2936 struct nvme_id_ns *id; 2941 struct nvme_id_ns *id;
2937 char disk_name[DISK_NAME_LEN]; 2942 char disk_name[DISK_NAME_LEN];
2938 int node = dev_to_node(ctrl->dev), flags = GENHD_FL_EXT_DEVT; 2943 int node = dev_to_node(ctrl->dev), flags = GENHD_FL_EXT_DEVT;
2939 bool new = true;
2940 2944
2941 ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node); 2945 ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node);
2942 if (!ns) 2946 if (!ns)
@@ -2962,7 +2966,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
2962 if (id->ncap == 0) 2966 if (id->ncap == 0)
2963 goto out_free_id; 2967 goto out_free_id;
2964 2968
2965 if (nvme_init_ns_head(ns, nsid, id, &new)) 2969 if (nvme_init_ns_head(ns, nsid, id))
2966 goto out_free_id; 2970 goto out_free_id;
2967 nvme_setup_streams_ns(ctrl, ns); 2971 nvme_setup_streams_ns(ctrl, ns);
2968 2972
@@ -3028,9 +3032,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
3028 pr_warn("%s: failed to register lightnvm sysfs group for identification\n", 3032 pr_warn("%s: failed to register lightnvm sysfs group for identification\n",
3029 ns->disk->disk_name); 3033 ns->disk->disk_name);
3030 3034
3031 if (new) 3035 nvme_mpath_add_disk(ns->head);
3032 nvme_mpath_add_disk(ns->head);
3033 nvme_mpath_add_disk_links(ns);
3034 return; 3036 return;
3035 out_unlink_ns: 3037 out_unlink_ns:
3036 mutex_lock(&ctrl->subsys->lock); 3038 mutex_lock(&ctrl->subsys->lock);
@@ -3050,7 +3052,6 @@ static void nvme_ns_remove(struct nvme_ns *ns)
3050 return; 3052 return;
3051 3053
3052 if (ns->disk && ns->disk->flags & GENHD_FL_UP) { 3054 if (ns->disk && ns->disk->flags & GENHD_FL_UP) {
3053 nvme_mpath_remove_disk_links(ns);
3054 sysfs_remove_group(&disk_to_dev(ns->disk)->kobj, 3055 sysfs_remove_group(&disk_to_dev(ns->disk)->kobj,
3055 &nvme_ns_id_attr_group); 3056 &nvme_ns_id_attr_group);
3056 if (ns->ndev) 3057 if (ns->ndev)
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index 5dd4ceefed8f..8f0f34d06d46 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -493,7 +493,7 @@ EXPORT_SYMBOL_GPL(nvmf_should_reconnect);
493 */ 493 */
494int nvmf_register_transport(struct nvmf_transport_ops *ops) 494int nvmf_register_transport(struct nvmf_transport_ops *ops)
495{ 495{
496 if (!ops->create_ctrl || !ops->module) 496 if (!ops->create_ctrl)
497 return -EINVAL; 497 return -EINVAL;
498 498
499 down_write(&nvmf_transports_rwsem); 499 down_write(&nvmf_transports_rwsem);
@@ -650,6 +650,11 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
650 ret = -EINVAL; 650 ret = -EINVAL;
651 goto out; 651 goto out;
652 } 652 }
653 if (opts->discovery_nqn) {
654 pr_debug("Ignoring nr_io_queues value for discovery controller\n");
655 break;
656 }
657
653 opts->nr_io_queues = min_t(unsigned int, 658 opts->nr_io_queues = min_t(unsigned int,
654 num_online_cpus(), token); 659 num_online_cpus(), token);
655 break; 660 break;
diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
index 25b19f722f5b..a3145d90c1d2 100644
--- a/drivers/nvme/host/fabrics.h
+++ b/drivers/nvme/host/fabrics.h
@@ -171,13 +171,14 @@ static inline blk_status_t nvmf_check_init_req(struct nvme_ctrl *ctrl,
171 cmd->common.opcode != nvme_fabrics_command || 171 cmd->common.opcode != nvme_fabrics_command ||
172 cmd->fabrics.fctype != nvme_fabrics_type_connect) { 172 cmd->fabrics.fctype != nvme_fabrics_type_connect) {
173 /* 173 /*
174 * Reconnecting state means transport disruption, which can take 174 * Connecting state means transport disruption or initial
175 * a long time and even might fail permanently, fail fast to 175 * establishment, which can take a long time and even might
176 * give upper layers a chance to failover. 176 * fail permanently, fail fast to give upper layers a chance
177 * to failover.
177 * Deleting state means that the ctrl will never accept commands 178 * Deleting state means that the ctrl will never accept commands
178 * again, fail it permanently. 179 * again, fail it permanently.
179 */ 180 */
180 if (ctrl->state == NVME_CTRL_RECONNECTING || 181 if (ctrl->state == NVME_CTRL_CONNECTING ||
181 ctrl->state == NVME_CTRL_DELETING) { 182 ctrl->state == NVME_CTRL_DELETING) {
182 nvme_req(rq)->status = NVME_SC_ABORT_REQ; 183 nvme_req(rq)->status = NVME_SC_ABORT_REQ;
183 return BLK_STS_IOERR; 184 return BLK_STS_IOERR;
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index b856d7c919d2..1dc1387b7134 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -55,9 +55,7 @@ struct nvme_fc_queue {
55 55
56enum nvme_fcop_flags { 56enum nvme_fcop_flags {
57 FCOP_FLAGS_TERMIO = (1 << 0), 57 FCOP_FLAGS_TERMIO = (1 << 0),
58 FCOP_FLAGS_RELEASED = (1 << 1), 58 FCOP_FLAGS_AEN = (1 << 1),
59 FCOP_FLAGS_COMPLETE = (1 << 2),
60 FCOP_FLAGS_AEN = (1 << 3),
61}; 59};
62 60
63struct nvmefc_ls_req_op { 61struct nvmefc_ls_req_op {
@@ -532,7 +530,7 @@ nvme_fc_resume_controller(struct nvme_fc_ctrl *ctrl)
532{ 530{
533 switch (ctrl->ctrl.state) { 531 switch (ctrl->ctrl.state) {
534 case NVME_CTRL_NEW: 532 case NVME_CTRL_NEW:
535 case NVME_CTRL_RECONNECTING: 533 case NVME_CTRL_CONNECTING:
536 /* 534 /*
537 * As all reconnects were suppressed, schedule a 535 * As all reconnects were suppressed, schedule a
538 * connect. 536 * connect.
@@ -777,7 +775,7 @@ nvme_fc_ctrl_connectivity_loss(struct nvme_fc_ctrl *ctrl)
777 } 775 }
778 break; 776 break;
779 777
780 case NVME_CTRL_RECONNECTING: 778 case NVME_CTRL_CONNECTING:
781 /* 779 /*
782 * The association has already been terminated and the 780 * The association has already been terminated and the
783 * controller is attempting reconnects. No need to do anything 781 * controller is attempting reconnects. No need to do anything
@@ -1208,7 +1206,7 @@ nvme_fc_connect_admin_queue(struct nvme_fc_ctrl *ctrl,
1208 sizeof(struct fcnvme_lsdesc_cr_assoc_cmd)); 1206 sizeof(struct fcnvme_lsdesc_cr_assoc_cmd));
1209 1207
1210 assoc_rqst->assoc_cmd.ersp_ratio = cpu_to_be16(ersp_ratio); 1208 assoc_rqst->assoc_cmd.ersp_ratio = cpu_to_be16(ersp_ratio);
1211 assoc_rqst->assoc_cmd.sqsize = cpu_to_be16(qsize); 1209 assoc_rqst->assoc_cmd.sqsize = cpu_to_be16(qsize - 1);
1212 /* Linux supports only Dynamic controllers */ 1210 /* Linux supports only Dynamic controllers */
1213 assoc_rqst->assoc_cmd.cntlid = cpu_to_be16(0xffff); 1211 assoc_rqst->assoc_cmd.cntlid = cpu_to_be16(0xffff);
1214 uuid_copy(&assoc_rqst->assoc_cmd.hostid, &ctrl->ctrl.opts->host->id); 1212 uuid_copy(&assoc_rqst->assoc_cmd.hostid, &ctrl->ctrl.opts->host->id);
@@ -1323,7 +1321,7 @@ nvme_fc_connect_queue(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
1323 sizeof(struct fcnvme_lsdesc_cr_conn_cmd)); 1321 sizeof(struct fcnvme_lsdesc_cr_conn_cmd));
1324 conn_rqst->connect_cmd.ersp_ratio = cpu_to_be16(ersp_ratio); 1322 conn_rqst->connect_cmd.ersp_ratio = cpu_to_be16(ersp_ratio);
1325 conn_rqst->connect_cmd.qid = cpu_to_be16(queue->qnum); 1323 conn_rqst->connect_cmd.qid = cpu_to_be16(queue->qnum);
1326 conn_rqst->connect_cmd.sqsize = cpu_to_be16(qsize); 1324 conn_rqst->connect_cmd.sqsize = cpu_to_be16(qsize - 1);
1327 1325
1328 lsop->queue = queue; 1326 lsop->queue = queue;
1329 lsreq->rqstaddr = conn_rqst; 1327 lsreq->rqstaddr = conn_rqst;
@@ -1470,7 +1468,6 @@ nvme_fc_xmt_disconnect_assoc(struct nvme_fc_ctrl *ctrl)
1470 1468
1471/* *********************** NVME Ctrl Routines **************************** */ 1469/* *********************** NVME Ctrl Routines **************************** */
1472 1470
1473static void __nvme_fc_final_op_cleanup(struct request *rq);
1474static void nvme_fc_error_recovery(struct nvme_fc_ctrl *ctrl, char *errmsg); 1471static void nvme_fc_error_recovery(struct nvme_fc_ctrl *ctrl, char *errmsg);
1475 1472
1476static int 1473static int
@@ -1512,13 +1509,19 @@ nvme_fc_exit_request(struct blk_mq_tag_set *set, struct request *rq,
1512static int 1509static int
1513__nvme_fc_abort_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_fcp_op *op) 1510__nvme_fc_abort_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_fcp_op *op)
1514{ 1511{
1515 int state; 1512 unsigned long flags;
1513 int opstate;
1514
1515 spin_lock_irqsave(&ctrl->lock, flags);
1516 opstate = atomic_xchg(&op->state, FCPOP_STATE_ABORTED);
1517 if (opstate != FCPOP_STATE_ACTIVE)
1518 atomic_set(&op->state, opstate);
1519 else if (ctrl->flags & FCCTRL_TERMIO)
1520 ctrl->iocnt++;
1521 spin_unlock_irqrestore(&ctrl->lock, flags);
1516 1522
1517 state = atomic_xchg(&op->state, FCPOP_STATE_ABORTED); 1523 if (opstate != FCPOP_STATE_ACTIVE)
1518 if (state != FCPOP_STATE_ACTIVE) {
1519 atomic_set(&op->state, state);
1520 return -ECANCELED; 1524 return -ECANCELED;
1521 }
1522 1525
1523 ctrl->lport->ops->fcp_abort(&ctrl->lport->localport, 1526 ctrl->lport->ops->fcp_abort(&ctrl->lport->localport,
1524 &ctrl->rport->remoteport, 1527 &ctrl->rport->remoteport,
@@ -1532,60 +1535,26 @@ static void
1532nvme_fc_abort_aen_ops(struct nvme_fc_ctrl *ctrl) 1535nvme_fc_abort_aen_ops(struct nvme_fc_ctrl *ctrl)
1533{ 1536{
1534 struct nvme_fc_fcp_op *aen_op = ctrl->aen_ops; 1537 struct nvme_fc_fcp_op *aen_op = ctrl->aen_ops;
1535 unsigned long flags; 1538 int i;
1536 int i, ret;
1537
1538 for (i = 0; i < NVME_NR_AEN_COMMANDS; i++, aen_op++) {
1539 if (atomic_read(&aen_op->state) != FCPOP_STATE_ACTIVE)
1540 continue;
1541
1542 spin_lock_irqsave(&ctrl->lock, flags);
1543 if (ctrl->flags & FCCTRL_TERMIO) {
1544 ctrl->iocnt++;
1545 aen_op->flags |= FCOP_FLAGS_TERMIO;
1546 }
1547 spin_unlock_irqrestore(&ctrl->lock, flags);
1548
1549 ret = __nvme_fc_abort_op(ctrl, aen_op);
1550 if (ret) {
1551 /*
1552 * if __nvme_fc_abort_op failed the io wasn't
1553 * active. Thus this call path is running in
1554 * parallel to the io complete. Treat as non-error.
1555 */
1556 1539
1557 /* back out the flags/counters */ 1540 for (i = 0; i < NVME_NR_AEN_COMMANDS; i++, aen_op++)
1558 spin_lock_irqsave(&ctrl->lock, flags); 1541 __nvme_fc_abort_op(ctrl, aen_op);
1559 if (ctrl->flags & FCCTRL_TERMIO)
1560 ctrl->iocnt--;
1561 aen_op->flags &= ~FCOP_FLAGS_TERMIO;
1562 spin_unlock_irqrestore(&ctrl->lock, flags);
1563 return;
1564 }
1565 }
1566} 1542}
1567 1543
1568static inline int 1544static inline void
1569__nvme_fc_fcpop_chk_teardowns(struct nvme_fc_ctrl *ctrl, 1545__nvme_fc_fcpop_chk_teardowns(struct nvme_fc_ctrl *ctrl,
1570 struct nvme_fc_fcp_op *op) 1546 struct nvme_fc_fcp_op *op, int opstate)
1571{ 1547{
1572 unsigned long flags; 1548 unsigned long flags;
1573 bool complete_rq = false;
1574 1549
1575 spin_lock_irqsave(&ctrl->lock, flags); 1550 if (opstate == FCPOP_STATE_ABORTED) {
1576 if (unlikely(op->flags & FCOP_FLAGS_TERMIO)) { 1551 spin_lock_irqsave(&ctrl->lock, flags);
1577 if (ctrl->flags & FCCTRL_TERMIO) { 1552 if (ctrl->flags & FCCTRL_TERMIO) {
1578 if (!--ctrl->iocnt) 1553 if (!--ctrl->iocnt)
1579 wake_up(&ctrl->ioabort_wait); 1554 wake_up(&ctrl->ioabort_wait);
1580 } 1555 }
1556 spin_unlock_irqrestore(&ctrl->lock, flags);
1581 } 1557 }
1582 if (op->flags & FCOP_FLAGS_RELEASED)
1583 complete_rq = true;
1584 else
1585 op->flags |= FCOP_FLAGS_COMPLETE;
1586 spin_unlock_irqrestore(&ctrl->lock, flags);
1587
1588 return complete_rq;
1589} 1558}
1590 1559
1591static void 1560static void
@@ -1601,6 +1570,7 @@ nvme_fc_fcpio_done(struct nvmefc_fcp_req *req)
1601 __le16 status = cpu_to_le16(NVME_SC_SUCCESS << 1); 1570 __le16 status = cpu_to_le16(NVME_SC_SUCCESS << 1);
1602 union nvme_result result; 1571 union nvme_result result;
1603 bool terminate_assoc = true; 1572 bool terminate_assoc = true;
1573 int opstate;
1604 1574
1605 /* 1575 /*
1606 * WARNING: 1576 * WARNING:
@@ -1639,11 +1609,12 @@ nvme_fc_fcpio_done(struct nvmefc_fcp_req *req)
1639 * association to be terminated. 1609 * association to be terminated.
1640 */ 1610 */
1641 1611
1612 opstate = atomic_xchg(&op->state, FCPOP_STATE_COMPLETE);
1613
1642 fc_dma_sync_single_for_cpu(ctrl->lport->dev, op->fcp_req.rspdma, 1614 fc_dma_sync_single_for_cpu(ctrl->lport->dev, op->fcp_req.rspdma,
1643 sizeof(op->rsp_iu), DMA_FROM_DEVICE); 1615 sizeof(op->rsp_iu), DMA_FROM_DEVICE);
1644 1616
1645 if (atomic_read(&op->state) == FCPOP_STATE_ABORTED || 1617 if (opstate == FCPOP_STATE_ABORTED)
1646 op->flags & FCOP_FLAGS_TERMIO)
1647 status = cpu_to_le16(NVME_SC_ABORT_REQ << 1); 1618 status = cpu_to_le16(NVME_SC_ABORT_REQ << 1);
1648 else if (freq->status) 1619 else if (freq->status)
1649 status = cpu_to_le16(NVME_SC_INTERNAL << 1); 1620 status = cpu_to_le16(NVME_SC_INTERNAL << 1);
@@ -1708,7 +1679,7 @@ nvme_fc_fcpio_done(struct nvmefc_fcp_req *req)
1708done: 1679done:
1709 if (op->flags & FCOP_FLAGS_AEN) { 1680 if (op->flags & FCOP_FLAGS_AEN) {
1710 nvme_complete_async_event(&queue->ctrl->ctrl, status, &result); 1681 nvme_complete_async_event(&queue->ctrl->ctrl, status, &result);
1711 __nvme_fc_fcpop_chk_teardowns(ctrl, op); 1682 __nvme_fc_fcpop_chk_teardowns(ctrl, op, opstate);
1712 atomic_set(&op->state, FCPOP_STATE_IDLE); 1683 atomic_set(&op->state, FCPOP_STATE_IDLE);
1713 op->flags = FCOP_FLAGS_AEN; /* clear other flags */ 1684 op->flags = FCOP_FLAGS_AEN; /* clear other flags */
1714 nvme_fc_ctrl_put(ctrl); 1685 nvme_fc_ctrl_put(ctrl);
@@ -1722,13 +1693,11 @@ done:
1722 if (status && 1693 if (status &&
1723 (blk_queue_dying(rq->q) || 1694 (blk_queue_dying(rq->q) ||
1724 ctrl->ctrl.state == NVME_CTRL_NEW || 1695 ctrl->ctrl.state == NVME_CTRL_NEW ||
1725 ctrl->ctrl.state == NVME_CTRL_RECONNECTING)) 1696 ctrl->ctrl.state == NVME_CTRL_CONNECTING))
1726 status |= cpu_to_le16(NVME_SC_DNR << 1); 1697 status |= cpu_to_le16(NVME_SC_DNR << 1);
1727 1698
1728 if (__nvme_fc_fcpop_chk_teardowns(ctrl, op)) 1699 __nvme_fc_fcpop_chk_teardowns(ctrl, op, opstate);
1729 __nvme_fc_final_op_cleanup(rq); 1700 nvme_end_request(rq, status, result);
1730 else
1731 nvme_end_request(rq, status, result);
1732 1701
1733check_error: 1702check_error:
1734 if (terminate_assoc) 1703 if (terminate_assoc)
@@ -2415,46 +2384,16 @@ nvme_fc_submit_async_event(struct nvme_ctrl *arg)
2415} 2384}
2416 2385
2417static void 2386static void
2418__nvme_fc_final_op_cleanup(struct request *rq) 2387nvme_fc_complete_rq(struct request *rq)
2419{ 2388{
2420 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq); 2389 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
2421 struct nvme_fc_ctrl *ctrl = op->ctrl; 2390 struct nvme_fc_ctrl *ctrl = op->ctrl;
2422 2391
2423 atomic_set(&op->state, FCPOP_STATE_IDLE); 2392 atomic_set(&op->state, FCPOP_STATE_IDLE);
2424 op->flags &= ~(FCOP_FLAGS_TERMIO | FCOP_FLAGS_RELEASED |
2425 FCOP_FLAGS_COMPLETE);
2426 2393
2427 nvme_fc_unmap_data(ctrl, rq, op); 2394 nvme_fc_unmap_data(ctrl, rq, op);
2428 nvme_complete_rq(rq); 2395 nvme_complete_rq(rq);
2429 nvme_fc_ctrl_put(ctrl); 2396 nvme_fc_ctrl_put(ctrl);
2430
2431}
2432
2433static void
2434nvme_fc_complete_rq(struct request *rq)
2435{
2436 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
2437 struct nvme_fc_ctrl *ctrl = op->ctrl;
2438 unsigned long flags;
2439 bool completed = false;
2440
2441 /*
2442 * the core layer, on controller resets after calling
2443 * nvme_shutdown_ctrl(), calls complete_rq without our
2444 * calling blk_mq_complete_request(), thus there may still
2445 * be live i/o outstanding with the LLDD. Means transport has
2446 * to track complete calls vs fcpio_done calls to know what
2447 * path to take on completes and dones.
2448 */
2449 spin_lock_irqsave(&ctrl->lock, flags);
2450 if (op->flags & FCOP_FLAGS_COMPLETE)
2451 completed = true;
2452 else
2453 op->flags |= FCOP_FLAGS_RELEASED;
2454 spin_unlock_irqrestore(&ctrl->lock, flags);
2455
2456 if (completed)
2457 __nvme_fc_final_op_cleanup(rq);
2458} 2397}
2459 2398
2460/* 2399/*
@@ -2476,35 +2415,11 @@ nvme_fc_terminate_exchange(struct request *req, void *data, bool reserved)
2476 struct nvme_ctrl *nctrl = data; 2415 struct nvme_ctrl *nctrl = data;
2477 struct nvme_fc_ctrl *ctrl = to_fc_ctrl(nctrl); 2416 struct nvme_fc_ctrl *ctrl = to_fc_ctrl(nctrl);
2478 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(req); 2417 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(req);
2479 unsigned long flags;
2480 int status;
2481 2418
2482 if (!blk_mq_request_started(req)) 2419 if (!blk_mq_request_started(req))
2483 return; 2420 return;
2484 2421
2485 spin_lock_irqsave(&ctrl->lock, flags); 2422 __nvme_fc_abort_op(ctrl, op);
2486 if (ctrl->flags & FCCTRL_TERMIO) {
2487 ctrl->iocnt++;
2488 op->flags |= FCOP_FLAGS_TERMIO;
2489 }
2490 spin_unlock_irqrestore(&ctrl->lock, flags);
2491
2492 status = __nvme_fc_abort_op(ctrl, op);
2493 if (status) {
2494 /*
2495 * if __nvme_fc_abort_op failed the io wasn't
2496 * active. Thus this call path is running in
2497 * parallel to the io complete. Treat as non-error.
2498 */
2499
2500 /* back out the flags/counters */
2501 spin_lock_irqsave(&ctrl->lock, flags);
2502 if (ctrl->flags & FCCTRL_TERMIO)
2503 ctrl->iocnt--;
2504 op->flags &= ~FCOP_FLAGS_TERMIO;
2505 spin_unlock_irqrestore(&ctrl->lock, flags);
2506 return;
2507 }
2508} 2423}
2509 2424
2510 2425
@@ -2566,11 +2481,11 @@ nvme_fc_create_io_queues(struct nvme_fc_ctrl *ctrl)
2566 goto out_free_tag_set; 2481 goto out_free_tag_set;
2567 } 2482 }
2568 2483
2569 ret = nvme_fc_create_hw_io_queues(ctrl, ctrl->ctrl.opts->queue_size); 2484 ret = nvme_fc_create_hw_io_queues(ctrl, ctrl->ctrl.sqsize + 1);
2570 if (ret) 2485 if (ret)
2571 goto out_cleanup_blk_queue; 2486 goto out_cleanup_blk_queue;
2572 2487
2573 ret = nvme_fc_connect_io_queues(ctrl, ctrl->ctrl.opts->queue_size); 2488 ret = nvme_fc_connect_io_queues(ctrl, ctrl->ctrl.sqsize + 1);
2574 if (ret) 2489 if (ret)
2575 goto out_delete_hw_queues; 2490 goto out_delete_hw_queues;
2576 2491
@@ -2617,11 +2532,11 @@ nvme_fc_reinit_io_queues(struct nvme_fc_ctrl *ctrl)
2617 if (ret) 2532 if (ret)
2618 goto out_free_io_queues; 2533 goto out_free_io_queues;
2619 2534
2620 ret = nvme_fc_create_hw_io_queues(ctrl, ctrl->ctrl.opts->queue_size); 2535 ret = nvme_fc_create_hw_io_queues(ctrl, ctrl->ctrl.sqsize + 1);
2621 if (ret) 2536 if (ret)
2622 goto out_free_io_queues; 2537 goto out_free_io_queues;
2623 2538
2624 ret = nvme_fc_connect_io_queues(ctrl, ctrl->ctrl.opts->queue_size); 2539 ret = nvme_fc_connect_io_queues(ctrl, ctrl->ctrl.sqsize + 1);
2625 if (ret) 2540 if (ret)
2626 goto out_delete_hw_queues; 2541 goto out_delete_hw_queues;
2627 2542
@@ -2717,13 +2632,12 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
2717 nvme_fc_init_queue(ctrl, 0); 2632 nvme_fc_init_queue(ctrl, 0);
2718 2633
2719 ret = __nvme_fc_create_hw_queue(ctrl, &ctrl->queues[0], 0, 2634 ret = __nvme_fc_create_hw_queue(ctrl, &ctrl->queues[0], 0,
2720 NVME_AQ_BLK_MQ_DEPTH); 2635 NVME_AQ_DEPTH);
2721 if (ret) 2636 if (ret)
2722 goto out_free_queue; 2637 goto out_free_queue;
2723 2638
2724 ret = nvme_fc_connect_admin_queue(ctrl, &ctrl->queues[0], 2639 ret = nvme_fc_connect_admin_queue(ctrl, &ctrl->queues[0],
2725 NVME_AQ_BLK_MQ_DEPTH, 2640 NVME_AQ_DEPTH, (NVME_AQ_DEPTH / 4));
2726 (NVME_AQ_BLK_MQ_DEPTH / 4));
2727 if (ret) 2641 if (ret)
2728 goto out_delete_hw_queue; 2642 goto out_delete_hw_queue;
2729 2643
@@ -2751,7 +2665,7 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
2751 } 2665 }
2752 2666
2753 ctrl->ctrl.sqsize = 2667 ctrl->ctrl.sqsize =
2754 min_t(int, NVME_CAP_MQES(ctrl->ctrl.cap) + 1, ctrl->ctrl.sqsize); 2668 min_t(int, NVME_CAP_MQES(ctrl->ctrl.cap), ctrl->ctrl.sqsize);
2755 2669
2756 ret = nvme_enable_ctrl(&ctrl->ctrl, ctrl->ctrl.cap); 2670 ret = nvme_enable_ctrl(&ctrl->ctrl, ctrl->ctrl.cap);
2757 if (ret) 2671 if (ret)
@@ -2784,6 +2698,14 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
2784 opts->queue_size = ctrl->ctrl.maxcmd; 2698 opts->queue_size = ctrl->ctrl.maxcmd;
2785 } 2699 }
2786 2700
2701 if (opts->queue_size > ctrl->ctrl.sqsize + 1) {
2702 /* warn if sqsize is lower than queue_size */
2703 dev_warn(ctrl->ctrl.device,
2704 "queue_size %zu > ctrl sqsize %u, clamping down\n",
2705 opts->queue_size, ctrl->ctrl.sqsize + 1);
2706 opts->queue_size = ctrl->ctrl.sqsize + 1;
2707 }
2708
2787 ret = nvme_fc_init_aen_ops(ctrl); 2709 ret = nvme_fc_init_aen_ops(ctrl);
2788 if (ret) 2710 if (ret)
2789 goto out_term_aen_ops; 2711 goto out_term_aen_ops;
@@ -2943,7 +2865,7 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)
2943 unsigned long recon_delay = ctrl->ctrl.opts->reconnect_delay * HZ; 2865 unsigned long recon_delay = ctrl->ctrl.opts->reconnect_delay * HZ;
2944 bool recon = true; 2866 bool recon = true;
2945 2867
2946 if (ctrl->ctrl.state != NVME_CTRL_RECONNECTING) 2868 if (ctrl->ctrl.state != NVME_CTRL_CONNECTING)
2947 return; 2869 return;
2948 2870
2949 if (portptr->port_state == FC_OBJSTATE_ONLINE) 2871 if (portptr->port_state == FC_OBJSTATE_ONLINE)
@@ -2991,10 +2913,10 @@ nvme_fc_reset_ctrl_work(struct work_struct *work)
2991 /* will block will waiting for io to terminate */ 2913 /* will block will waiting for io to terminate */
2992 nvme_fc_delete_association(ctrl); 2914 nvme_fc_delete_association(ctrl);
2993 2915
2994 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RECONNECTING)) { 2916 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) {
2995 dev_err(ctrl->ctrl.device, 2917 dev_err(ctrl->ctrl.device,
2996 "NVME-FC{%d}: error_recovery: Couldn't change state " 2918 "NVME-FC{%d}: error_recovery: Couldn't change state "
2997 "to RECONNECTING\n", ctrl->cnum); 2919 "to CONNECTING\n", ctrl->cnum);
2998 return; 2920 return;
2999 } 2921 }
3000 2922
@@ -3195,7 +3117,7 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
3195 * transport errors (frame drop, LS failure) inherently must kill 3117 * transport errors (frame drop, LS failure) inherently must kill
3196 * the association. The transport is coded so that any command used 3118 * the association. The transport is coded so that any command used
3197 * to create the association (prior to a LIVE state transition 3119 * to create the association (prior to a LIVE state transition
3198 * while NEW or RECONNECTING) will fail if it completes in error or 3120 * while NEW or CONNECTING) will fail if it completes in error or
3199 * times out. 3121 * times out.
3200 * 3122 *
3201 * As such: as the connect request was mostly likely due to a 3123 * As such: as the connect request was mostly likely due to a
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 3b211d9e58b8..060f69e03427 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -198,30 +198,16 @@ void nvme_mpath_add_disk(struct nvme_ns_head *head)
198{ 198{
199 if (!head->disk) 199 if (!head->disk)
200 return; 200 return;
201 device_add_disk(&head->subsys->dev, head->disk);
202 if (sysfs_create_group(&disk_to_dev(head->disk)->kobj,
203 &nvme_ns_id_attr_group))
204 pr_warn("%s: failed to create sysfs group for identification\n",
205 head->disk->disk_name);
206}
207
208void nvme_mpath_add_disk_links(struct nvme_ns *ns)
209{
210 struct kobject *slave_disk_kobj, *holder_disk_kobj;
211
212 if (!ns->head->disk)
213 return;
214
215 slave_disk_kobj = &disk_to_dev(ns->disk)->kobj;
216 if (sysfs_create_link(ns->head->disk->slave_dir, slave_disk_kobj,
217 kobject_name(slave_disk_kobj)))
218 return;
219 201
220 holder_disk_kobj = &disk_to_dev(ns->head->disk)->kobj; 202 mutex_lock(&head->subsys->lock);
221 if (sysfs_create_link(ns->disk->part0.holder_dir, holder_disk_kobj, 203 if (!(head->disk->flags & GENHD_FL_UP)) {
222 kobject_name(holder_disk_kobj))) 204 device_add_disk(&head->subsys->dev, head->disk);
223 sysfs_remove_link(ns->head->disk->slave_dir, 205 if (sysfs_create_group(&disk_to_dev(head->disk)->kobj,
224 kobject_name(slave_disk_kobj)); 206 &nvme_ns_id_attr_group))
207 pr_warn("%s: failed to create sysfs group for identification\n",
208 head->disk->disk_name);
209 }
210 mutex_unlock(&head->subsys->lock);
225} 211}
226 212
227void nvme_mpath_remove_disk(struct nvme_ns_head *head) 213void nvme_mpath_remove_disk(struct nvme_ns_head *head)
@@ -238,14 +224,3 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
238 blk_cleanup_queue(head->disk->queue); 224 blk_cleanup_queue(head->disk->queue);
239 put_disk(head->disk); 225 put_disk(head->disk);
240} 226}
241
242void nvme_mpath_remove_disk_links(struct nvme_ns *ns)
243{
244 if (!ns->head->disk)
245 return;
246
247 sysfs_remove_link(ns->disk->part0.holder_dir,
248 kobject_name(&disk_to_dev(ns->head->disk)->kobj));
249 sysfs_remove_link(ns->head->disk->slave_dir,
250 kobject_name(&disk_to_dev(ns->disk)->kobj));
251}
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 8e4550fa08f8..d733b14ede9d 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -123,7 +123,7 @@ enum nvme_ctrl_state {
123 NVME_CTRL_LIVE, 123 NVME_CTRL_LIVE,
124 NVME_CTRL_ADMIN_ONLY, /* Only admin queue live */ 124 NVME_CTRL_ADMIN_ONLY, /* Only admin queue live */
125 NVME_CTRL_RESETTING, 125 NVME_CTRL_RESETTING,
126 NVME_CTRL_RECONNECTING, 126 NVME_CTRL_CONNECTING,
127 NVME_CTRL_DELETING, 127 NVME_CTRL_DELETING,
128 NVME_CTRL_DEAD, 128 NVME_CTRL_DEAD,
129}; 129};
@@ -183,6 +183,7 @@ struct nvme_ctrl {
183 struct work_struct scan_work; 183 struct work_struct scan_work;
184 struct work_struct async_event_work; 184 struct work_struct async_event_work;
185 struct delayed_work ka_work; 185 struct delayed_work ka_work;
186 struct nvme_command ka_cmd;
186 struct work_struct fw_act_work; 187 struct work_struct fw_act_work;
187 188
188 /* Power saving configuration */ 189 /* Power saving configuration */
@@ -409,9 +410,7 @@ bool nvme_req_needs_failover(struct request *req, blk_status_t error);
409void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl); 410void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);
410int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head); 411int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head);
411void nvme_mpath_add_disk(struct nvme_ns_head *head); 412void nvme_mpath_add_disk(struct nvme_ns_head *head);
412void nvme_mpath_add_disk_links(struct nvme_ns *ns);
413void nvme_mpath_remove_disk(struct nvme_ns_head *head); 413void nvme_mpath_remove_disk(struct nvme_ns_head *head);
414void nvme_mpath_remove_disk_links(struct nvme_ns *ns);
415 414
416static inline void nvme_mpath_clear_current_path(struct nvme_ns *ns) 415static inline void nvme_mpath_clear_current_path(struct nvme_ns *ns)
417{ 416{
@@ -453,12 +452,6 @@ static inline void nvme_mpath_add_disk(struct nvme_ns_head *head)
453static inline void nvme_mpath_remove_disk(struct nvme_ns_head *head) 452static inline void nvme_mpath_remove_disk(struct nvme_ns_head *head)
454{ 453{
455} 454}
456static inline void nvme_mpath_add_disk_links(struct nvme_ns *ns)
457{
458}
459static inline void nvme_mpath_remove_disk_links(struct nvme_ns *ns)
460{
461}
462static inline void nvme_mpath_clear_current_path(struct nvme_ns *ns) 455static inline void nvme_mpath_clear_current_path(struct nvme_ns *ns)
463{ 456{
464} 457}
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 6fe7af00a1f4..b6f43b738f03 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1141,7 +1141,7 @@ static bool nvme_should_reset(struct nvme_dev *dev, u32 csts)
1141 /* If there is a reset/reinit ongoing, we shouldn't reset again. */ 1141 /* If there is a reset/reinit ongoing, we shouldn't reset again. */
1142 switch (dev->ctrl.state) { 1142 switch (dev->ctrl.state) {
1143 case NVME_CTRL_RESETTING: 1143 case NVME_CTRL_RESETTING:
1144 case NVME_CTRL_RECONNECTING: 1144 case NVME_CTRL_CONNECTING:
1145 return false; 1145 return false;
1146 default: 1146 default:
1147 break; 1147 break;
@@ -1153,12 +1153,6 @@ static bool nvme_should_reset(struct nvme_dev *dev, u32 csts)
1153 if (!(csts & NVME_CSTS_CFS) && !nssro) 1153 if (!(csts & NVME_CSTS_CFS) && !nssro)
1154 return false; 1154 return false;
1155 1155
1156 /* If PCI error recovery process is happening, we cannot reset or
1157 * the recovery mechanism will surely fail.
1158 */
1159 if (pci_channel_offline(to_pci_dev(dev->dev)))
1160 return false;
1161
1162 return true; 1156 return true;
1163} 1157}
1164 1158
@@ -1189,6 +1183,13 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
1189 struct nvme_command cmd; 1183 struct nvme_command cmd;
1190 u32 csts = readl(dev->bar + NVME_REG_CSTS); 1184 u32 csts = readl(dev->bar + NVME_REG_CSTS);
1191 1185
1186 /* If PCI error recovery process is happening, we cannot reset or
1187 * the recovery mechanism will surely fail.
1188 */
1189 mb();
1190 if (pci_channel_offline(to_pci_dev(dev->dev)))
1191 return BLK_EH_RESET_TIMER;
1192
1192 /* 1193 /*
1193 * Reset immediately if the controller is failed 1194 * Reset immediately if the controller is failed
1194 */ 1195 */
@@ -1215,13 +1216,17 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
1215 * cancellation error. All outstanding requests are completed on 1216 * cancellation error. All outstanding requests are completed on
1216 * shutdown, so we return BLK_EH_HANDLED. 1217 * shutdown, so we return BLK_EH_HANDLED.
1217 */ 1218 */
1218 if (dev->ctrl.state == NVME_CTRL_RESETTING) { 1219 switch (dev->ctrl.state) {
1220 case NVME_CTRL_CONNECTING:
1221 case NVME_CTRL_RESETTING:
1219 dev_warn(dev->ctrl.device, 1222 dev_warn(dev->ctrl.device,
1220 "I/O %d QID %d timeout, disable controller\n", 1223 "I/O %d QID %d timeout, disable controller\n",
1221 req->tag, nvmeq->qid); 1224 req->tag, nvmeq->qid);
1222 nvme_dev_disable(dev, false); 1225 nvme_dev_disable(dev, false);
1223 nvme_req(req)->flags |= NVME_REQ_CANCELLED; 1226 nvme_req(req)->flags |= NVME_REQ_CANCELLED;
1224 return BLK_EH_HANDLED; 1227 return BLK_EH_HANDLED;
1228 default:
1229 break;
1225 } 1230 }
1226 1231
1227 /* 1232 /*
@@ -1364,18 +1369,14 @@ static int nvme_cmb_qdepth(struct nvme_dev *dev, int nr_io_queues,
1364static int nvme_alloc_sq_cmds(struct nvme_dev *dev, struct nvme_queue *nvmeq, 1369static int nvme_alloc_sq_cmds(struct nvme_dev *dev, struct nvme_queue *nvmeq,
1365 int qid, int depth) 1370 int qid, int depth)
1366{ 1371{
1367 if (qid && dev->cmb && use_cmb_sqes && (dev->cmbsz & NVME_CMBSZ_SQS)) { 1372 /* CMB SQEs will be mapped before creation */
1368 unsigned offset = (qid - 1) * roundup(SQ_SIZE(depth), 1373 if (qid && dev->cmb && use_cmb_sqes && (dev->cmbsz & NVME_CMBSZ_SQS))
1369 dev->ctrl.page_size); 1374 return 0;
1370 nvmeq->sq_dma_addr = dev->cmb_bus_addr + offset;
1371 nvmeq->sq_cmds_io = dev->cmb + offset;
1372 } else {
1373 nvmeq->sq_cmds = dma_alloc_coherent(dev->dev, SQ_SIZE(depth),
1374 &nvmeq->sq_dma_addr, GFP_KERNEL);
1375 if (!nvmeq->sq_cmds)
1376 return -ENOMEM;
1377 }
1378 1375
1376 nvmeq->sq_cmds = dma_alloc_coherent(dev->dev, SQ_SIZE(depth),
1377 &nvmeq->sq_dma_addr, GFP_KERNEL);
1378 if (!nvmeq->sq_cmds)
1379 return -ENOMEM;
1379 return 0; 1380 return 0;
1380} 1381}
1381 1382
@@ -1449,10 +1450,17 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
1449 struct nvme_dev *dev = nvmeq->dev; 1450 struct nvme_dev *dev = nvmeq->dev;
1450 int result; 1451 int result;
1451 1452
1453 if (dev->cmb && use_cmb_sqes && (dev->cmbsz & NVME_CMBSZ_SQS)) {
1454 unsigned offset = (qid - 1) * roundup(SQ_SIZE(nvmeq->q_depth),
1455 dev->ctrl.page_size);
1456 nvmeq->sq_dma_addr = dev->cmb_bus_addr + offset;
1457 nvmeq->sq_cmds_io = dev->cmb + offset;
1458 }
1459
1452 nvmeq->cq_vector = qid - 1; 1460 nvmeq->cq_vector = qid - 1;
1453 result = adapter_alloc_cq(dev, qid, nvmeq); 1461 result = adapter_alloc_cq(dev, qid, nvmeq);
1454 if (result < 0) 1462 if (result < 0)
1455 return result; 1463 goto release_vector;
1456 1464
1457 result = adapter_alloc_sq(dev, qid, nvmeq); 1465 result = adapter_alloc_sq(dev, qid, nvmeq);
1458 if (result < 0) 1466 if (result < 0)
@@ -1466,9 +1474,12 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
1466 return result; 1474 return result;
1467 1475
1468 release_sq: 1476 release_sq:
1477 dev->online_queues--;
1469 adapter_delete_sq(dev, qid); 1478 adapter_delete_sq(dev, qid);
1470 release_cq: 1479 release_cq:
1471 adapter_delete_cq(dev, qid); 1480 adapter_delete_cq(dev, qid);
1481 release_vector:
1482 nvmeq->cq_vector = -1;
1472 return result; 1483 return result;
1473} 1484}
1474 1485
@@ -1903,7 +1914,7 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
1903 int result, nr_io_queues; 1914 int result, nr_io_queues;
1904 unsigned long size; 1915 unsigned long size;
1905 1916
1906 nr_io_queues = num_present_cpus(); 1917 nr_io_queues = num_possible_cpus();
1907 result = nvme_set_queue_count(&dev->ctrl, &nr_io_queues); 1918 result = nvme_set_queue_count(&dev->ctrl, &nr_io_queues);
1908 if (result < 0) 1919 if (result < 0)
1909 return result; 1920 return result;
@@ -2288,12 +2299,12 @@ static void nvme_reset_work(struct work_struct *work)
2288 nvme_dev_disable(dev, false); 2299 nvme_dev_disable(dev, false);
2289 2300
2290 /* 2301 /*
2291 * Introduce RECONNECTING state from nvme-fc/rdma transports to mark the 2302 * Introduce CONNECTING state from nvme-fc/rdma transports to mark the
2292 * initializing procedure here. 2303 * initializing procedure here.
2293 */ 2304 */
2294 if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RECONNECTING)) { 2305 if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_CONNECTING)) {
2295 dev_warn(dev->ctrl.device, 2306 dev_warn(dev->ctrl.device,
2296 "failed to mark controller RECONNECTING\n"); 2307 "failed to mark controller CONNECTING\n");
2297 goto out; 2308 goto out;
2298 } 2309 }
2299 2310
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 2bc059f7d73c..4d84a73ee12d 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -887,7 +887,7 @@ free_ctrl:
887static void nvme_rdma_reconnect_or_remove(struct nvme_rdma_ctrl *ctrl) 887static void nvme_rdma_reconnect_or_remove(struct nvme_rdma_ctrl *ctrl)
888{ 888{
889 /* If we are resetting/deleting then do nothing */ 889 /* If we are resetting/deleting then do nothing */
890 if (ctrl->ctrl.state != NVME_CTRL_RECONNECTING) { 890 if (ctrl->ctrl.state != NVME_CTRL_CONNECTING) {
891 WARN_ON_ONCE(ctrl->ctrl.state == NVME_CTRL_NEW || 891 WARN_ON_ONCE(ctrl->ctrl.state == NVME_CTRL_NEW ||
892 ctrl->ctrl.state == NVME_CTRL_LIVE); 892 ctrl->ctrl.state == NVME_CTRL_LIVE);
893 return; 893 return;
@@ -973,7 +973,7 @@ static void nvme_rdma_error_recovery_work(struct work_struct *work)
973 blk_mq_unquiesce_queue(ctrl->ctrl.admin_q); 973 blk_mq_unquiesce_queue(ctrl->ctrl.admin_q);
974 nvme_start_queues(&ctrl->ctrl); 974 nvme_start_queues(&ctrl->ctrl);
975 975
976 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RECONNECTING)) { 976 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) {
977 /* state change failure should never happen */ 977 /* state change failure should never happen */
978 WARN_ON_ONCE(1); 978 WARN_ON_ONCE(1);
979 return; 979 return;
@@ -1051,7 +1051,7 @@ static void nvme_rdma_unmap_data(struct nvme_rdma_queue *queue,
1051 struct nvme_rdma_device *dev = queue->device; 1051 struct nvme_rdma_device *dev = queue->device;
1052 struct ib_device *ibdev = dev->dev; 1052 struct ib_device *ibdev = dev->dev;
1053 1053
1054 if (!blk_rq_bytes(rq)) 1054 if (!blk_rq_payload_bytes(rq))
1055 return; 1055 return;
1056 1056
1057 if (req->mr) { 1057 if (req->mr) {
@@ -1166,7 +1166,7 @@ static int nvme_rdma_map_data(struct nvme_rdma_queue *queue,
1166 1166
1167 c->common.flags |= NVME_CMD_SGL_METABUF; 1167 c->common.flags |= NVME_CMD_SGL_METABUF;
1168 1168
1169 if (!blk_rq_bytes(rq)) 1169 if (!blk_rq_payload_bytes(rq))
1170 return nvme_rdma_set_sg_null(c); 1170 return nvme_rdma_set_sg_null(c);
1171 1171
1172 req->sg_table.sgl = req->first_sgl; 1172 req->sg_table.sgl = req->first_sgl;
@@ -1756,7 +1756,7 @@ static void nvme_rdma_reset_ctrl_work(struct work_struct *work)
1756 nvme_stop_ctrl(&ctrl->ctrl); 1756 nvme_stop_ctrl(&ctrl->ctrl);
1757 nvme_rdma_shutdown_ctrl(ctrl, false); 1757 nvme_rdma_shutdown_ctrl(ctrl, false);
1758 1758
1759 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RECONNECTING)) { 1759 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) {
1760 /* state change failure should never happen */ 1760 /* state change failure should never happen */
1761 WARN_ON_ONCE(1); 1761 WARN_ON_ONCE(1);
1762 return; 1762 return;
@@ -1784,11 +1784,8 @@ static void nvme_rdma_reset_ctrl_work(struct work_struct *work)
1784 return; 1784 return;
1785 1785
1786out_fail: 1786out_fail:
1787 dev_warn(ctrl->ctrl.device, "Removing after reset failure\n"); 1787 ++ctrl->ctrl.nr_reconnects;
1788 nvme_remove_namespaces(&ctrl->ctrl); 1788 nvme_rdma_reconnect_or_remove(ctrl);
1789 nvme_rdma_shutdown_ctrl(ctrl, true);
1790 nvme_uninit_ctrl(&ctrl->ctrl);
1791 nvme_put_ctrl(&ctrl->ctrl);
1792} 1789}
1793 1790
1794static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = { 1791static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = {
@@ -1942,6 +1939,9 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
1942 if (!ctrl->queues) 1939 if (!ctrl->queues)
1943 goto out_uninit_ctrl; 1940 goto out_uninit_ctrl;
1944 1941
1942 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING);
1943 WARN_ON_ONCE(!changed);
1944
1945 ret = nvme_rdma_configure_admin_queue(ctrl, true); 1945 ret = nvme_rdma_configure_admin_queue(ctrl, true);
1946 if (ret) 1946 if (ret)
1947 goto out_kfree_queues; 1947 goto out_kfree_queues;
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 0bd737117a80..a78029e4e5f4 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -520,9 +520,12 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
520 goto fail; 520 goto fail;
521 } 521 }
522 522
523 /* either variant of SGLs is fine, as we don't support metadata */ 523 /*
524 if (unlikely((flags & NVME_CMD_SGL_ALL) != NVME_CMD_SGL_METABUF && 524 * For fabrics, PSDT field shall describe metadata pointer (MPTR) that
525 (flags & NVME_CMD_SGL_ALL) != NVME_CMD_SGL_METASEG)) { 525 * contains an address of a single contiguous physical buffer that is
526 * byte aligned.
527 */
528 if (unlikely((flags & NVME_CMD_SGL_ALL) != NVME_CMD_SGL_METABUF)) {
526 status = NVME_SC_INVALID_FIELD | NVME_SC_DNR; 529 status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
527 goto fail; 530 goto fail;
528 } 531 }
diff --git a/drivers/nvme/target/io-cmd.c b/drivers/nvme/target/io-cmd.c
index 0a4372a016f2..28bbdff4a88b 100644
--- a/drivers/nvme/target/io-cmd.c
+++ b/drivers/nvme/target/io-cmd.c
@@ -105,10 +105,13 @@ static void nvmet_execute_flush(struct nvmet_req *req)
105static u16 nvmet_discard_range(struct nvmet_ns *ns, 105static u16 nvmet_discard_range(struct nvmet_ns *ns,
106 struct nvme_dsm_range *range, struct bio **bio) 106 struct nvme_dsm_range *range, struct bio **bio)
107{ 107{
108 if (__blkdev_issue_discard(ns->bdev, 108 int ret;
109
110 ret = __blkdev_issue_discard(ns->bdev,
109 le64_to_cpu(range->slba) << (ns->blksize_shift - 9), 111 le64_to_cpu(range->slba) << (ns->blksize_shift - 9),
110 le32_to_cpu(range->nlb) << (ns->blksize_shift - 9), 112 le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
111 GFP_KERNEL, 0, bio)) 113 GFP_KERNEL, 0, bio);
114 if (ret && ret != -EOPNOTSUPP)
112 return NVME_SC_INTERNAL | NVME_SC_DNR; 115 return NVME_SC_INTERNAL | NVME_SC_DNR;
113 return 0; 116 return 0;
114} 117}
diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c
index 7991ec3a17db..861d1509b22b 100644
--- a/drivers/nvme/target/loop.c
+++ b/drivers/nvme/target/loop.c
@@ -184,7 +184,7 @@ static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
184 return BLK_STS_OK; 184 return BLK_STS_OK;
185 } 185 }
186 186
187 if (blk_rq_bytes(req)) { 187 if (blk_rq_payload_bytes(req)) {
188 iod->sg_table.sgl = iod->first_sgl; 188 iod->sg_table.sgl = iod->first_sgl;
189 if (sg_alloc_table_chained(&iod->sg_table, 189 if (sg_alloc_table_chained(&iod->sg_table,
190 blk_rq_nr_phys_segments(req), 190 blk_rq_nr_phys_segments(req),
@@ -193,7 +193,7 @@ static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
193 193
194 iod->req.sg = iod->sg_table.sgl; 194 iod->req.sg = iod->sg_table.sgl;
195 iod->req.sg_cnt = blk_rq_map_sg(req->q, req, iod->sg_table.sgl); 195 iod->req.sg_cnt = blk_rq_map_sg(req->q, req, iod->sg_table.sgl);
196 iod->req.transfer_len = blk_rq_bytes(req); 196 iod->req.transfer_len = blk_rq_payload_bytes(req);
197 } 197 }
198 198
199 blk_mq_start_request(req); 199 blk_mq_start_request(req);
diff --git a/drivers/of/property.c b/drivers/of/property.c
index 36ed84e26d9c..f46828e3b082 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -977,11 +977,11 @@ static int of_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
977 return 0; 977 return 0;
978} 978}
979 979
980static void * 980static const void *
981of_fwnode_device_get_match_data(const struct fwnode_handle *fwnode, 981of_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
982 const struct device *dev) 982 const struct device *dev)
983{ 983{
984 return (void *)of_device_get_match_data(dev); 984 return of_device_get_match_data(dev);
985} 985}
986 986
987const struct fwnode_operations of_fwnode_ops = { 987const struct fwnode_operations of_fwnode_ops = {
diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c
index 2d87bc1adf38..0c0910709435 100644
--- a/drivers/opp/cpu.c
+++ b/drivers/opp/cpu.c
@@ -55,7 +55,7 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev,
55 if (max_opps <= 0) 55 if (max_opps <= 0)
56 return max_opps ? max_opps : -ENODATA; 56 return max_opps ? max_opps : -ENODATA;
57 57
58 freq_table = kcalloc((max_opps + 1), sizeof(*freq_table), GFP_ATOMIC); 58 freq_table = kcalloc((max_opps + 1), sizeof(*freq_table), GFP_KERNEL);
59 if (!freq_table) 59 if (!freq_table)
60 return -ENOMEM; 60 return -ENOMEM;
61 61
diff --git a/drivers/pci/dwc/pcie-designware-host.c b/drivers/pci/dwc/pcie-designware-host.c
index 8de2d5c69b1d..dc9303abda42 100644
--- a/drivers/pci/dwc/pcie-designware-host.c
+++ b/drivers/pci/dwc/pcie-designware-host.c
@@ -613,7 +613,7 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
613 /* setup bus numbers */ 613 /* setup bus numbers */
614 val = dw_pcie_readl_dbi(pci, PCI_PRIMARY_BUS); 614 val = dw_pcie_readl_dbi(pci, PCI_PRIMARY_BUS);
615 val &= 0xff000000; 615 val &= 0xff000000;
616 val |= 0x00010100; 616 val |= 0x00ff0100;
617 dw_pcie_writel_dbi(pci, PCI_PRIMARY_BUS, val); 617 dw_pcie_writel_dbi(pci, PCI_PRIMARY_BUS, val);
618 618
619 /* setup command register */ 619 /* setup command register */
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index ec582d37c189..c3ba14f6444e 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -3420,22 +3420,29 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PORT_RIDGE,
3420 3420
3421static void quirk_chelsio_extend_vpd(struct pci_dev *dev) 3421static void quirk_chelsio_extend_vpd(struct pci_dev *dev)
3422{ 3422{
3423 pci_set_vpd_size(dev, 8192); 3423 int chip = (dev->device & 0xf000) >> 12;
3424} 3424 int func = (dev->device & 0x0f00) >> 8;
3425 3425 int prod = (dev->device & 0x00ff) >> 0;
3426DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x20, quirk_chelsio_extend_vpd); 3426
3427DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x21, quirk_chelsio_extend_vpd); 3427 /*
3428DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x22, quirk_chelsio_extend_vpd); 3428 * If this is a T3-based adapter, there's a 1KB VPD area at offset
3429DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x23, quirk_chelsio_extend_vpd); 3429 * 0xc00 which contains the preferred VPD values. If this is a T4 or
3430DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x24, quirk_chelsio_extend_vpd); 3430 * later based adapter, the special VPD is at offset 0x400 for the
3431DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x25, quirk_chelsio_extend_vpd); 3431 * Physical Functions (the SR-IOV Virtual Functions have no VPD
3432DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x26, quirk_chelsio_extend_vpd); 3432 * Capabilities). The PCI VPD Access core routines will normally
3433DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x30, quirk_chelsio_extend_vpd); 3433 * compute the size of the VPD by parsing the VPD Data Structure at
3434DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x31, quirk_chelsio_extend_vpd); 3434 * offset 0x000. This will result in silent failures when attempting
3435DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x32, quirk_chelsio_extend_vpd); 3435 * to accesses these other VPD areas which are beyond those computed
3436DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x35, quirk_chelsio_extend_vpd); 3436 * limits.
3437DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x36, quirk_chelsio_extend_vpd); 3437 */
3438DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x37, quirk_chelsio_extend_vpd); 3438 if (chip == 0x0 && prod >= 0x20)
3439 pci_set_vpd_size(dev, 8192);
3440 else if (chip >= 0x4 && func < 0x8)
3441 pci_set_vpd_size(dev, 2048);
3442}
3443
3444DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID,
3445 quirk_chelsio_extend_vpd);
3439 3446
3440#ifdef CONFIG_ACPI 3447#ifdef CONFIG_ACPI
3441/* 3448/*
@@ -3902,6 +3909,8 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9230,
3902 quirk_dma_func1_alias); 3909 quirk_dma_func1_alias);
3903DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TTI, 0x0642, 3910DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TTI, 0x0642,
3904 quirk_dma_func1_alias); 3911 quirk_dma_func1_alias);
3912DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TTI, 0x0645,
3913 quirk_dma_func1_alias);
3905/* https://bugs.gentoo.org/show_bug.cgi?id=497630 */ 3914/* https://bugs.gentoo.org/show_bug.cgi?id=497630 */
3906DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_JMICRON, 3915DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_JMICRON,
3907 PCI_DEVICE_ID_JMICRON_JMB388_ESD, 3916 PCI_DEVICE_ID_JMICRON_JMB388_ESD,
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 369d48d6c6f1..365447240d95 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -401,6 +401,10 @@ void pci_release_resource(struct pci_dev *dev, int resno)
401 struct resource *res = dev->resource + resno; 401 struct resource *res = dev->resource + resno;
402 402
403 pci_info(dev, "BAR %d: releasing %pR\n", resno, res); 403 pci_info(dev, "BAR %d: releasing %pR\n", resno, res);
404
405 if (!res->parent)
406 return;
407
404 release_resource(res); 408 release_resource(res);
405 res->end = resource_size(res) - 1; 409 res->end = resource_size(res) - 1;
406 res->start = 0; 410 res->start = 0;
diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
index 7bc5eee96b31..f63db346c219 100644
--- a/drivers/perf/arm_pmu.c
+++ b/drivers/perf/arm_pmu.c
@@ -17,7 +17,6 @@
17#include <linux/export.h> 17#include <linux/export.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/perf/arm_pmu.h> 19#include <linux/perf/arm_pmu.h>
20#include <linux/platform_device.h>
21#include <linux/slab.h> 20#include <linux/slab.h>
22#include <linux/sched/clock.h> 21#include <linux/sched/clock.h>
23#include <linux/spinlock.h> 22#include <linux/spinlock.h>
@@ -26,6 +25,9 @@
26 25
27#include <asm/irq_regs.h> 26#include <asm/irq_regs.h>
28 27
28static DEFINE_PER_CPU(struct arm_pmu *, cpu_armpmu);
29static DEFINE_PER_CPU(int, cpu_irq);
30
29static int 31static int
30armpmu_map_cache_event(const unsigned (*cache_map) 32armpmu_map_cache_event(const unsigned (*cache_map)
31 [PERF_COUNT_HW_CACHE_MAX] 33 [PERF_COUNT_HW_CACHE_MAX]
@@ -320,17 +322,9 @@ validate_group(struct perf_event *event)
320 return 0; 322 return 0;
321} 323}
322 324
323static struct arm_pmu_platdata *armpmu_get_platdata(struct arm_pmu *armpmu)
324{
325 struct platform_device *pdev = armpmu->plat_device;
326
327 return pdev ? dev_get_platdata(&pdev->dev) : NULL;
328}
329
330static irqreturn_t armpmu_dispatch_irq(int irq, void *dev) 325static irqreturn_t armpmu_dispatch_irq(int irq, void *dev)
331{ 326{
332 struct arm_pmu *armpmu; 327 struct arm_pmu *armpmu;
333 struct arm_pmu_platdata *plat;
334 int ret; 328 int ret;
335 u64 start_clock, finish_clock; 329 u64 start_clock, finish_clock;
336 330
@@ -341,14 +335,11 @@ static irqreturn_t armpmu_dispatch_irq(int irq, void *dev)
341 * dereference. 335 * dereference.
342 */ 336 */
343 armpmu = *(void **)dev; 337 armpmu = *(void **)dev;
344 338 if (WARN_ON_ONCE(!armpmu))
345 plat = armpmu_get_platdata(armpmu); 339 return IRQ_NONE;
346 340
347 start_clock = sched_clock(); 341 start_clock = sched_clock();
348 if (plat && plat->handle_irq) 342 ret = armpmu->handle_irq(irq, armpmu);
349 ret = plat->handle_irq(irq, armpmu, armpmu->handle_irq);
350 else
351 ret = armpmu->handle_irq(irq, armpmu);
352 finish_clock = sched_clock(); 343 finish_clock = sched_clock();
353 344
354 perf_sample_event_took(finish_clock - start_clock); 345 perf_sample_event_took(finish_clock - start_clock);
@@ -531,54 +522,41 @@ int perf_num_counters(void)
531} 522}
532EXPORT_SYMBOL_GPL(perf_num_counters); 523EXPORT_SYMBOL_GPL(perf_num_counters);
533 524
534void armpmu_free_irq(struct arm_pmu *armpmu, int cpu) 525static int armpmu_count_irq_users(const int irq)
535{ 526{
536 struct pmu_hw_events __percpu *hw_events = armpmu->hw_events; 527 int cpu, count = 0;
537 int irq = per_cpu(hw_events->irq, cpu);
538 528
539 if (!cpumask_test_and_clear_cpu(cpu, &armpmu->active_irqs)) 529 for_each_possible_cpu(cpu) {
540 return; 530 if (per_cpu(cpu_irq, cpu) == irq)
541 531 count++;
542 if (irq_is_percpu_devid(irq)) {
543 free_percpu_irq(irq, &hw_events->percpu_pmu);
544 cpumask_clear(&armpmu->active_irqs);
545 return;
546 } 532 }
547 533
548 free_irq(irq, per_cpu_ptr(&hw_events->percpu_pmu, cpu)); 534 return count;
549} 535}
550 536
551void armpmu_free_irqs(struct arm_pmu *armpmu) 537void armpmu_free_irq(int irq, int cpu)
552{ 538{
553 int cpu; 539 if (per_cpu(cpu_irq, cpu) == 0)
540 return;
541 if (WARN_ON(irq != per_cpu(cpu_irq, cpu)))
542 return;
543
544 if (!irq_is_percpu_devid(irq))
545 free_irq(irq, per_cpu_ptr(&cpu_armpmu, cpu));
546 else if (armpmu_count_irq_users(irq) == 1)
547 free_percpu_irq(irq, &cpu_armpmu);
554 548
555 for_each_cpu(cpu, &armpmu->supported_cpus) 549 per_cpu(cpu_irq, cpu) = 0;
556 armpmu_free_irq(armpmu, cpu);
557} 550}
558 551
559int armpmu_request_irq(struct arm_pmu *armpmu, int cpu) 552int armpmu_request_irq(int irq, int cpu)
560{ 553{
561 int err = 0; 554 int err = 0;
562 struct pmu_hw_events __percpu *hw_events = armpmu->hw_events;
563 const irq_handler_t handler = armpmu_dispatch_irq; 555 const irq_handler_t handler = armpmu_dispatch_irq;
564 int irq = per_cpu(hw_events->irq, cpu);
565 if (!irq) 556 if (!irq)
566 return 0; 557 return 0;
567 558
568 if (irq_is_percpu_devid(irq) && cpumask_empty(&armpmu->active_irqs)) { 559 if (!irq_is_percpu_devid(irq)) {
569 err = request_percpu_irq(irq, handler, "arm-pmu",
570 &hw_events->percpu_pmu);
571 } else if (irq_is_percpu_devid(irq)) {
572 int other_cpu = cpumask_first(&armpmu->active_irqs);
573 int other_irq = per_cpu(hw_events->irq, other_cpu);
574
575 if (irq != other_irq) {
576 pr_warn("mismatched PPIs detected.\n");
577 err = -EINVAL;
578 goto err_out;
579 }
580 } else {
581 struct arm_pmu_platdata *platdata = armpmu_get_platdata(armpmu);
582 unsigned long irq_flags; 560 unsigned long irq_flags;
583 561
584 err = irq_force_affinity(irq, cpumask_of(cpu)); 562 err = irq_force_affinity(irq, cpumask_of(cpu));
@@ -589,22 +567,22 @@ int armpmu_request_irq(struct arm_pmu *armpmu, int cpu)
589 goto err_out; 567 goto err_out;
590 } 568 }
591 569
592 if (platdata && platdata->irq_flags) { 570 irq_flags = IRQF_PERCPU |
593 irq_flags = platdata->irq_flags; 571 IRQF_NOBALANCING |
594 } else { 572 IRQF_NO_THREAD;
595 irq_flags = IRQF_PERCPU |
596 IRQF_NOBALANCING |
597 IRQF_NO_THREAD;
598 }
599 573
574 irq_set_status_flags(irq, IRQ_NOAUTOEN);
600 err = request_irq(irq, handler, irq_flags, "arm-pmu", 575 err = request_irq(irq, handler, irq_flags, "arm-pmu",
601 per_cpu_ptr(&hw_events->percpu_pmu, cpu)); 576 per_cpu_ptr(&cpu_armpmu, cpu));
577 } else if (armpmu_count_irq_users(irq) == 0) {
578 err = request_percpu_irq(irq, handler, "arm-pmu",
579 &cpu_armpmu);
602 } 580 }
603 581
604 if (err) 582 if (err)
605 goto err_out; 583 goto err_out;
606 584
607 cpumask_set_cpu(cpu, &armpmu->active_irqs); 585 per_cpu(cpu_irq, cpu) = irq;
608 return 0; 586 return 0;
609 587
610err_out: 588err_out:
@@ -612,19 +590,6 @@ err_out:
612 return err; 590 return err;
613} 591}
614 592
615int armpmu_request_irqs(struct arm_pmu *armpmu)
616{
617 int cpu, err;
618
619 for_each_cpu(cpu, &armpmu->supported_cpus) {
620 err = armpmu_request_irq(armpmu, cpu);
621 if (err)
622 break;
623 }
624
625 return err;
626}
627
628static int armpmu_get_cpu_irq(struct arm_pmu *pmu, int cpu) 593static int armpmu_get_cpu_irq(struct arm_pmu *pmu, int cpu)
629{ 594{
630 struct pmu_hw_events __percpu *hw_events = pmu->hw_events; 595 struct pmu_hw_events __percpu *hw_events = pmu->hw_events;
@@ -647,12 +612,14 @@ static int arm_perf_starting_cpu(unsigned int cpu, struct hlist_node *node)
647 if (pmu->reset) 612 if (pmu->reset)
648 pmu->reset(pmu); 613 pmu->reset(pmu);
649 614
615 per_cpu(cpu_armpmu, cpu) = pmu;
616
650 irq = armpmu_get_cpu_irq(pmu, cpu); 617 irq = armpmu_get_cpu_irq(pmu, cpu);
651 if (irq) { 618 if (irq) {
652 if (irq_is_percpu_devid(irq)) { 619 if (irq_is_percpu_devid(irq))
653 enable_percpu_irq(irq, IRQ_TYPE_NONE); 620 enable_percpu_irq(irq, IRQ_TYPE_NONE);
654 return 0; 621 else
655 } 622 enable_irq(irq);
656 } 623 }
657 624
658 return 0; 625 return 0;
@@ -667,8 +634,14 @@ static int arm_perf_teardown_cpu(unsigned int cpu, struct hlist_node *node)
667 return 0; 634 return 0;
668 635
669 irq = armpmu_get_cpu_irq(pmu, cpu); 636 irq = armpmu_get_cpu_irq(pmu, cpu);
670 if (irq && irq_is_percpu_devid(irq)) 637 if (irq) {
671 disable_percpu_irq(irq); 638 if (irq_is_percpu_devid(irq))
639 disable_percpu_irq(irq);
640 else
641 disable_irq_nosync(irq);
642 }
643
644 per_cpu(cpu_armpmu, cpu) = NULL;
672 645
673 return 0; 646 return 0;
674} 647}
@@ -800,18 +773,18 @@ static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu)
800 &cpu_pmu->node); 773 &cpu_pmu->node);
801} 774}
802 775
803struct arm_pmu *armpmu_alloc(void) 776static struct arm_pmu *__armpmu_alloc(gfp_t flags)
804{ 777{
805 struct arm_pmu *pmu; 778 struct arm_pmu *pmu;
806 int cpu; 779 int cpu;
807 780
808 pmu = kzalloc(sizeof(*pmu), GFP_KERNEL); 781 pmu = kzalloc(sizeof(*pmu), flags);
809 if (!pmu) { 782 if (!pmu) {
810 pr_info("failed to allocate PMU device!\n"); 783 pr_info("failed to allocate PMU device!\n");
811 goto out; 784 goto out;
812 } 785 }
813 786
814 pmu->hw_events = alloc_percpu(struct pmu_hw_events); 787 pmu->hw_events = alloc_percpu_gfp(struct pmu_hw_events, flags);
815 if (!pmu->hw_events) { 788 if (!pmu->hw_events) {
816 pr_info("failed to allocate per-cpu PMU data.\n"); 789 pr_info("failed to allocate per-cpu PMU data.\n");
817 goto out_free_pmu; 790 goto out_free_pmu;
@@ -857,6 +830,17 @@ out:
857 return NULL; 830 return NULL;
858} 831}
859 832
833struct arm_pmu *armpmu_alloc(void)
834{
835 return __armpmu_alloc(GFP_KERNEL);
836}
837
838struct arm_pmu *armpmu_alloc_atomic(void)
839{
840 return __armpmu_alloc(GFP_ATOMIC);
841}
842
843
860void armpmu_free(struct arm_pmu *pmu) 844void armpmu_free(struct arm_pmu *pmu)
861{ 845{
862 free_percpu(pmu->hw_events); 846 free_percpu(pmu->hw_events);
diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c
index 705f1a390e31..0f197516d708 100644
--- a/drivers/perf/arm_pmu_acpi.c
+++ b/drivers/perf/arm_pmu_acpi.c
@@ -11,6 +11,8 @@
11#include <linux/acpi.h> 11#include <linux/acpi.h>
12#include <linux/cpumask.h> 12#include <linux/cpumask.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/irq.h>
15#include <linux/irqdesc.h>
14#include <linux/percpu.h> 16#include <linux/percpu.h>
15#include <linux/perf/arm_pmu.h> 17#include <linux/perf/arm_pmu.h>
16 18
@@ -87,7 +89,13 @@ static int arm_pmu_acpi_parse_irqs(void)
87 pr_warn("No ACPI PMU IRQ for CPU%d\n", cpu); 89 pr_warn("No ACPI PMU IRQ for CPU%d\n", cpu);
88 } 90 }
89 91
92 /*
93 * Log and request the IRQ so the core arm_pmu code can manage
94 * it. We'll have to sanity-check IRQs later when we associate
95 * them with their PMUs.
96 */
90 per_cpu(pmu_irqs, cpu) = irq; 97 per_cpu(pmu_irqs, cpu) = irq;
98 armpmu_request_irq(irq, cpu);
91 } 99 }
92 100
93 return 0; 101 return 0;
@@ -127,7 +135,7 @@ static struct arm_pmu *arm_pmu_acpi_find_alloc_pmu(void)
127 return pmu; 135 return pmu;
128 } 136 }
129 137
130 pmu = armpmu_alloc(); 138 pmu = armpmu_alloc_atomic();
131 if (!pmu) { 139 if (!pmu) {
132 pr_warn("Unable to allocate PMU for CPU%d\n", 140 pr_warn("Unable to allocate PMU for CPU%d\n",
133 smp_processor_id()); 141 smp_processor_id());
@@ -140,6 +148,35 @@ static struct arm_pmu *arm_pmu_acpi_find_alloc_pmu(void)
140} 148}
141 149
142/* 150/*
151 * Check whether the new IRQ is compatible with those already associated with
152 * the PMU (e.g. we don't have mismatched PPIs).
153 */
154static bool pmu_irq_matches(struct arm_pmu *pmu, int irq)
155{
156 struct pmu_hw_events __percpu *hw_events = pmu->hw_events;
157 int cpu;
158
159 if (!irq)
160 return true;
161
162 for_each_cpu(cpu, &pmu->supported_cpus) {
163 int other_irq = per_cpu(hw_events->irq, cpu);
164 if (!other_irq)
165 continue;
166
167 if (irq == other_irq)
168 continue;
169 if (!irq_is_percpu_devid(irq) && !irq_is_percpu_devid(other_irq))
170 continue;
171
172 pr_warn("mismatched PPIs detected\n");
173 return false;
174 }
175
176 return true;
177}
178
179/*
143 * This must run before the common arm_pmu hotplug logic, so that we can 180 * This must run before the common arm_pmu hotplug logic, so that we can
144 * associate a CPU and its interrupt before the common code tries to manage the 181 * associate a CPU and its interrupt before the common code tries to manage the
145 * affinity and so on. 182 * affinity and so on.
@@ -164,19 +201,14 @@ static int arm_pmu_acpi_cpu_starting(unsigned int cpu)
164 if (!pmu) 201 if (!pmu)
165 return -ENOMEM; 202 return -ENOMEM;
166 203
167 cpumask_set_cpu(cpu, &pmu->supported_cpus);
168
169 per_cpu(probed_pmus, cpu) = pmu; 204 per_cpu(probed_pmus, cpu) = pmu;
170 205
171 /* 206 if (pmu_irq_matches(pmu, irq)) {
172 * Log and request the IRQ so the core arm_pmu code can manage it. In 207 hw_events = pmu->hw_events;
173 * some situations (e.g. mismatched PPIs), we may fail to request the 208 per_cpu(hw_events->irq, cpu) = irq;
174 * IRQ. However, it may be too late for us to do anything about it. 209 }
175 * The common ARM PMU code will log a warning in this case. 210
176 */ 211 cpumask_set_cpu(cpu, &pmu->supported_cpus);
177 hw_events = pmu->hw_events;
178 per_cpu(hw_events->irq, cpu) = irq;
179 armpmu_request_irq(pmu, cpu);
180 212
181 /* 213 /*
182 * Ideally, we'd probe the PMU here when we find the first matching 214 * Ideally, we'd probe the PMU here when we find the first matching
@@ -247,11 +279,6 @@ static int arm_pmu_acpi_init(void)
247 if (acpi_disabled) 279 if (acpi_disabled)
248 return 0; 280 return 0;
249 281
250 /*
251 * We can't request IRQs yet, since we don't know the cookie value
252 * until we know which CPUs share the same logical PMU. We'll handle
253 * that in arm_pmu_acpi_cpu_starting().
254 */
255 ret = arm_pmu_acpi_parse_irqs(); 282 ret = arm_pmu_acpi_parse_irqs();
256 if (ret) 283 if (ret)
257 return ret; 284 return ret;
diff --git a/drivers/perf/arm_pmu_platform.c b/drivers/perf/arm_pmu_platform.c
index 46501cc79fd7..7729eda5909d 100644
--- a/drivers/perf/arm_pmu_platform.c
+++ b/drivers/perf/arm_pmu_platform.c
@@ -127,13 +127,6 @@ static int pmu_parse_irqs(struct arm_pmu *pmu)
127 pdev->dev.of_node); 127 pdev->dev.of_node);
128 } 128 }
129 129
130 /*
131 * Some platforms have all PMU IRQs OR'd into a single IRQ, with a
132 * special platdata function that attempts to demux them.
133 */
134 if (dev_get_platdata(&pdev->dev))
135 cpumask_setall(&pmu->supported_cpus);
136
137 for (i = 0; i < num_irqs; i++) { 130 for (i = 0; i < num_irqs; i++) {
138 int cpu, irq; 131 int cpu, irq;
139 132
@@ -164,6 +157,36 @@ static int pmu_parse_irqs(struct arm_pmu *pmu)
164 return 0; 157 return 0;
165} 158}
166 159
160static int armpmu_request_irqs(struct arm_pmu *armpmu)
161{
162 struct pmu_hw_events __percpu *hw_events = armpmu->hw_events;
163 int cpu, err;
164
165 for_each_cpu(cpu, &armpmu->supported_cpus) {
166 int irq = per_cpu(hw_events->irq, cpu);
167 if (!irq)
168 continue;
169
170 err = armpmu_request_irq(irq, cpu);
171 if (err)
172 break;
173 }
174
175 return err;
176}
177
178static void armpmu_free_irqs(struct arm_pmu *armpmu)
179{
180 int cpu;
181 struct pmu_hw_events __percpu *hw_events = armpmu->hw_events;
182
183 for_each_cpu(cpu, &armpmu->supported_cpus) {
184 int irq = per_cpu(hw_events->irq, cpu);
185
186 armpmu_free_irq(irq, cpu);
187 }
188}
189
167int arm_pmu_device_probe(struct platform_device *pdev, 190int arm_pmu_device_probe(struct platform_device *pdev,
168 const struct of_device_id *of_table, 191 const struct of_device_id *of_table,
169 const struct pmu_probe_info *probe_table) 192 const struct pmu_probe_info *probe_table)
diff --git a/drivers/phy/qualcomm/phy-qcom-ufs.c b/drivers/phy/qualcomm/phy-qcom-ufs.c
index c5ff4525edef..c5493ea51282 100644
--- a/drivers/phy/qualcomm/phy-qcom-ufs.c
+++ b/drivers/phy/qualcomm/phy-qcom-ufs.c
@@ -675,3 +675,8 @@ int ufs_qcom_phy_power_off(struct phy *generic_phy)
675 return 0; 675 return 0;
676} 676}
677EXPORT_SYMBOL_GPL(ufs_qcom_phy_power_off); 677EXPORT_SYMBOL_GPL(ufs_qcom_phy_power_off);
678
679MODULE_AUTHOR("Yaniv Gardi <ygardi@codeaurora.org>");
680MODULE_AUTHOR("Vivek Gautam <vivek.gautam@codeaurora.org>");
681MODULE_DESCRIPTION("Universal Flash Storage (UFS) QCOM PHY");
682MODULE_LICENSE("GPL v2");
diff --git a/drivers/pinctrl/meson/pinctrl-meson-axg.c b/drivers/pinctrl/meson/pinctrl-meson-axg.c
index 1fda9d6c7ea3..4b91ff74779b 100644
--- a/drivers/pinctrl/meson/pinctrl-meson-axg.c
+++ b/drivers/pinctrl/meson/pinctrl-meson-axg.c
@@ -716,7 +716,7 @@ static const char * const uart_b_groups[] = {
716 "uart_tx_b_x", "uart_rx_b_x", "uart_cts_b_x", "uart_rts_b_x", 716 "uart_tx_b_x", "uart_rx_b_x", "uart_cts_b_x", "uart_rts_b_x",
717}; 717};
718 718
719static const char * const uart_ao_b_gpioz_groups[] = { 719static const char * const uart_ao_b_z_groups[] = {
720 "uart_ao_tx_b_z", "uart_ao_rx_b_z", 720 "uart_ao_tx_b_z", "uart_ao_rx_b_z",
721 "uart_ao_cts_b_z", "uart_ao_rts_b_z", 721 "uart_ao_cts_b_z", "uart_ao_rts_b_z",
722}; 722};
@@ -855,7 +855,7 @@ static struct meson_pmx_func meson_axg_periphs_functions[] = {
855 FUNCTION(nand), 855 FUNCTION(nand),
856 FUNCTION(uart_a), 856 FUNCTION(uart_a),
857 FUNCTION(uart_b), 857 FUNCTION(uart_b),
858 FUNCTION(uart_ao_b_gpioz), 858 FUNCTION(uart_ao_b_z),
859 FUNCTION(i2c0), 859 FUNCTION(i2c0),
860 FUNCTION(i2c1), 860 FUNCTION(i2c1),
861 FUNCTION(i2c2), 861 FUNCTION(i2c2),
diff --git a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
index c32399faff57..90c274490181 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
+++ b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c
@@ -124,7 +124,7 @@ static const struct samsung_pin_bank_data s5pv210_pin_bank[] __initconst = {
124 EXYNOS_PIN_BANK_EINTW(8, 0xc60, "gph3", 0x0c), 124 EXYNOS_PIN_BANK_EINTW(8, 0xc60, "gph3", 0x0c),
125}; 125};
126 126
127const struct samsung_pin_ctrl s5pv210_pin_ctrl[] __initconst = { 127static const struct samsung_pin_ctrl s5pv210_pin_ctrl[] __initconst = {
128 { 128 {
129 /* pin-controller instance 0 data */ 129 /* pin-controller instance 0 data */
130 .pin_banks = s5pv210_pin_bank, 130 .pin_banks = s5pv210_pin_bank,
@@ -137,6 +137,11 @@ const struct samsung_pin_ctrl s5pv210_pin_ctrl[] __initconst = {
137 }, 137 },
138}; 138};
139 139
140const struct samsung_pinctrl_of_match_data s5pv210_of_data __initconst = {
141 .ctrl = s5pv210_pin_ctrl,
142 .num_ctrl = ARRAY_SIZE(s5pv210_pin_ctrl),
143};
144
140/* Pad retention control code for accessing PMU regmap */ 145/* Pad retention control code for accessing PMU regmap */
141static atomic_t exynos_shared_retention_refcnt; 146static atomic_t exynos_shared_retention_refcnt;
142 147
@@ -199,7 +204,7 @@ static const struct samsung_retention_data exynos3250_retention_data __initconst
199 * Samsung pinctrl driver data for Exynos3250 SoC. Exynos3250 SoC includes 204 * Samsung pinctrl driver data for Exynos3250 SoC. Exynos3250 SoC includes
200 * two gpio/pin-mux/pinconfig controllers. 205 * two gpio/pin-mux/pinconfig controllers.
201 */ 206 */
202const struct samsung_pin_ctrl exynos3250_pin_ctrl[] __initconst = { 207static const struct samsung_pin_ctrl exynos3250_pin_ctrl[] __initconst = {
203 { 208 {
204 /* pin-controller instance 0 data */ 209 /* pin-controller instance 0 data */
205 .pin_banks = exynos3250_pin_banks0, 210 .pin_banks = exynos3250_pin_banks0,
@@ -220,6 +225,11 @@ const struct samsung_pin_ctrl exynos3250_pin_ctrl[] __initconst = {
220 }, 225 },
221}; 226};
222 227
228const struct samsung_pinctrl_of_match_data exynos3250_of_data __initconst = {
229 .ctrl = exynos3250_pin_ctrl,
230 .num_ctrl = ARRAY_SIZE(exynos3250_pin_ctrl),
231};
232
223/* pin banks of exynos4210 pin-controller 0 */ 233/* pin banks of exynos4210 pin-controller 0 */
224static const struct samsung_pin_bank_data exynos4210_pin_banks0[] __initconst = { 234static const struct samsung_pin_bank_data exynos4210_pin_banks0[] __initconst = {
225 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00), 235 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00),
@@ -303,7 +313,7 @@ static const struct samsung_retention_data exynos4_audio_retention_data __initco
303 * Samsung pinctrl driver data for Exynos4210 SoC. Exynos4210 SoC includes 313 * Samsung pinctrl driver data for Exynos4210 SoC. Exynos4210 SoC includes
304 * three gpio/pin-mux/pinconfig controllers. 314 * three gpio/pin-mux/pinconfig controllers.
305 */ 315 */
306const struct samsung_pin_ctrl exynos4210_pin_ctrl[] __initconst = { 316static const struct samsung_pin_ctrl exynos4210_pin_ctrl[] __initconst = {
307 { 317 {
308 /* pin-controller instance 0 data */ 318 /* pin-controller instance 0 data */
309 .pin_banks = exynos4210_pin_banks0, 319 .pin_banks = exynos4210_pin_banks0,
@@ -329,6 +339,11 @@ const struct samsung_pin_ctrl exynos4210_pin_ctrl[] __initconst = {
329 }, 339 },
330}; 340};
331 341
342const struct samsung_pinctrl_of_match_data exynos4210_of_data __initconst = {
343 .ctrl = exynos4210_pin_ctrl,
344 .num_ctrl = ARRAY_SIZE(exynos4210_pin_ctrl),
345};
346
332/* pin banks of exynos4x12 pin-controller 0 */ 347/* pin banks of exynos4x12 pin-controller 0 */
333static const struct samsung_pin_bank_data exynos4x12_pin_banks0[] __initconst = { 348static const struct samsung_pin_bank_data exynos4x12_pin_banks0[] __initconst = {
334 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00), 349 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00),
@@ -391,7 +406,7 @@ static const struct samsung_pin_bank_data exynos4x12_pin_banks3[] __initconst =
391 * Samsung pinctrl driver data for Exynos4x12 SoC. Exynos4x12 SoC includes 406 * Samsung pinctrl driver data for Exynos4x12 SoC. Exynos4x12 SoC includes
392 * four gpio/pin-mux/pinconfig controllers. 407 * four gpio/pin-mux/pinconfig controllers.
393 */ 408 */
394const struct samsung_pin_ctrl exynos4x12_pin_ctrl[] __initconst = { 409static const struct samsung_pin_ctrl exynos4x12_pin_ctrl[] __initconst = {
395 { 410 {
396 /* pin-controller instance 0 data */ 411 /* pin-controller instance 0 data */
397 .pin_banks = exynos4x12_pin_banks0, 412 .pin_banks = exynos4x12_pin_banks0,
@@ -427,6 +442,11 @@ const struct samsung_pin_ctrl exynos4x12_pin_ctrl[] __initconst = {
427 }, 442 },
428}; 443};
429 444
445const struct samsung_pinctrl_of_match_data exynos4x12_of_data __initconst = {
446 .ctrl = exynos4x12_pin_ctrl,
447 .num_ctrl = ARRAY_SIZE(exynos4x12_pin_ctrl),
448};
449
430/* pin banks of exynos5250 pin-controller 0 */ 450/* pin banks of exynos5250 pin-controller 0 */
431static const struct samsung_pin_bank_data exynos5250_pin_banks0[] __initconst = { 451static const struct samsung_pin_bank_data exynos5250_pin_banks0[] __initconst = {
432 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00), 452 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00),
@@ -487,7 +507,7 @@ static const struct samsung_pin_bank_data exynos5250_pin_banks3[] __initconst =
487 * Samsung pinctrl driver data for Exynos5250 SoC. Exynos5250 SoC includes 507 * Samsung pinctrl driver data for Exynos5250 SoC. Exynos5250 SoC includes
488 * four gpio/pin-mux/pinconfig controllers. 508 * four gpio/pin-mux/pinconfig controllers.
489 */ 509 */
490const struct samsung_pin_ctrl exynos5250_pin_ctrl[] __initconst = { 510static const struct samsung_pin_ctrl exynos5250_pin_ctrl[] __initconst = {
491 { 511 {
492 /* pin-controller instance 0 data */ 512 /* pin-controller instance 0 data */
493 .pin_banks = exynos5250_pin_banks0, 513 .pin_banks = exynos5250_pin_banks0,
@@ -523,6 +543,11 @@ const struct samsung_pin_ctrl exynos5250_pin_ctrl[] __initconst = {
523 }, 543 },
524}; 544};
525 545
546const struct samsung_pinctrl_of_match_data exynos5250_of_data __initconst = {
547 .ctrl = exynos5250_pin_ctrl,
548 .num_ctrl = ARRAY_SIZE(exynos5250_pin_ctrl),
549};
550
526/* pin banks of exynos5260 pin-controller 0 */ 551/* pin banks of exynos5260 pin-controller 0 */
527static const struct samsung_pin_bank_data exynos5260_pin_banks0[] __initconst = { 552static const struct samsung_pin_bank_data exynos5260_pin_banks0[] __initconst = {
528 EXYNOS_PIN_BANK_EINTG(4, 0x000, "gpa0", 0x00), 553 EXYNOS_PIN_BANK_EINTG(4, 0x000, "gpa0", 0x00),
@@ -567,7 +592,7 @@ static const struct samsung_pin_bank_data exynos5260_pin_banks2[] __initconst =
567 * Samsung pinctrl driver data for Exynos5260 SoC. Exynos5260 SoC includes 592 * Samsung pinctrl driver data for Exynos5260 SoC. Exynos5260 SoC includes
568 * three gpio/pin-mux/pinconfig controllers. 593 * three gpio/pin-mux/pinconfig controllers.
569 */ 594 */
570const struct samsung_pin_ctrl exynos5260_pin_ctrl[] __initconst = { 595static const struct samsung_pin_ctrl exynos5260_pin_ctrl[] __initconst = {
571 { 596 {
572 /* pin-controller instance 0 data */ 597 /* pin-controller instance 0 data */
573 .pin_banks = exynos5260_pin_banks0, 598 .pin_banks = exynos5260_pin_banks0,
@@ -587,6 +612,11 @@ const struct samsung_pin_ctrl exynos5260_pin_ctrl[] __initconst = {
587 }, 612 },
588}; 613};
589 614
615const struct samsung_pinctrl_of_match_data exynos5260_of_data __initconst = {
616 .ctrl = exynos5260_pin_ctrl,
617 .num_ctrl = ARRAY_SIZE(exynos5260_pin_ctrl),
618};
619
590/* pin banks of exynos5410 pin-controller 0 */ 620/* pin banks of exynos5410 pin-controller 0 */
591static const struct samsung_pin_bank_data exynos5410_pin_banks0[] __initconst = { 621static const struct samsung_pin_bank_data exynos5410_pin_banks0[] __initconst = {
592 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00), 622 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00),
@@ -657,7 +687,7 @@ static const struct samsung_pin_bank_data exynos5410_pin_banks3[] __initconst =
657 * Samsung pinctrl driver data for Exynos5410 SoC. Exynos5410 SoC includes 687 * Samsung pinctrl driver data for Exynos5410 SoC. Exynos5410 SoC includes
658 * four gpio/pin-mux/pinconfig controllers. 688 * four gpio/pin-mux/pinconfig controllers.
659 */ 689 */
660const struct samsung_pin_ctrl exynos5410_pin_ctrl[] __initconst = { 690static const struct samsung_pin_ctrl exynos5410_pin_ctrl[] __initconst = {
661 { 691 {
662 /* pin-controller instance 0 data */ 692 /* pin-controller instance 0 data */
663 .pin_banks = exynos5410_pin_banks0, 693 .pin_banks = exynos5410_pin_banks0,
@@ -690,6 +720,11 @@ const struct samsung_pin_ctrl exynos5410_pin_ctrl[] __initconst = {
690 }, 720 },
691}; 721};
692 722
723const struct samsung_pinctrl_of_match_data exynos5410_of_data __initconst = {
724 .ctrl = exynos5410_pin_ctrl,
725 .num_ctrl = ARRAY_SIZE(exynos5410_pin_ctrl),
726};
727
693/* pin banks of exynos5420 pin-controller 0 */ 728/* pin banks of exynos5420 pin-controller 0 */
694static const struct samsung_pin_bank_data exynos5420_pin_banks0[] __initconst = { 729static const struct samsung_pin_bank_data exynos5420_pin_banks0[] __initconst = {
695 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpy7", 0x00), 730 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpy7", 0x00),
@@ -774,7 +809,7 @@ static const struct samsung_retention_data exynos5420_retention_data __initconst
774 * Samsung pinctrl driver data for Exynos5420 SoC. Exynos5420 SoC includes 809 * Samsung pinctrl driver data for Exynos5420 SoC. Exynos5420 SoC includes
775 * four gpio/pin-mux/pinconfig controllers. 810 * four gpio/pin-mux/pinconfig controllers.
776 */ 811 */
777const struct samsung_pin_ctrl exynos5420_pin_ctrl[] __initconst = { 812static const struct samsung_pin_ctrl exynos5420_pin_ctrl[] __initconst = {
778 { 813 {
779 /* pin-controller instance 0 data */ 814 /* pin-controller instance 0 data */
780 .pin_banks = exynos5420_pin_banks0, 815 .pin_banks = exynos5420_pin_banks0,
@@ -808,3 +843,8 @@ const struct samsung_pin_ctrl exynos5420_pin_ctrl[] __initconst = {
808 .retention_data = &exynos4_audio_retention_data, 843 .retention_data = &exynos4_audio_retention_data,
809 }, 844 },
810}; 845};
846
847const struct samsung_pinctrl_of_match_data exynos5420_of_data __initconst = {
848 .ctrl = exynos5420_pin_ctrl,
849 .num_ctrl = ARRAY_SIZE(exynos5420_pin_ctrl),
850};
diff --git a/drivers/pinctrl/samsung/pinctrl-exynos-arm64.c b/drivers/pinctrl/samsung/pinctrl-exynos-arm64.c
index fc8f7833bec0..71c9d1d9f345 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos-arm64.c
+++ b/drivers/pinctrl/samsung/pinctrl-exynos-arm64.c
@@ -175,7 +175,7 @@ static const struct samsung_retention_data exynos5433_fsys_retention_data __init
175 * Samsung pinctrl driver data for Exynos5433 SoC. Exynos5433 SoC includes 175 * Samsung pinctrl driver data for Exynos5433 SoC. Exynos5433 SoC includes
176 * ten gpio/pin-mux/pinconfig controllers. 176 * ten gpio/pin-mux/pinconfig controllers.
177 */ 177 */
178const struct samsung_pin_ctrl exynos5433_pin_ctrl[] __initconst = { 178static const struct samsung_pin_ctrl exynos5433_pin_ctrl[] __initconst = {
179 { 179 {
180 /* pin-controller instance 0 data */ 180 /* pin-controller instance 0 data */
181 .pin_banks = exynos5433_pin_banks0, 181 .pin_banks = exynos5433_pin_banks0,
@@ -260,6 +260,11 @@ const struct samsung_pin_ctrl exynos5433_pin_ctrl[] __initconst = {
260 }, 260 },
261}; 261};
262 262
263const struct samsung_pinctrl_of_match_data exynos5433_of_data __initconst = {
264 .ctrl = exynos5433_pin_ctrl,
265 .num_ctrl = ARRAY_SIZE(exynos5433_pin_ctrl),
266};
267
263/* pin banks of exynos7 pin-controller - ALIVE */ 268/* pin banks of exynos7 pin-controller - ALIVE */
264static const struct samsung_pin_bank_data exynos7_pin_banks0[] __initconst = { 269static const struct samsung_pin_bank_data exynos7_pin_banks0[] __initconst = {
265 EXYNOS_PIN_BANK_EINTW(8, 0x000, "gpa0", 0x00), 270 EXYNOS_PIN_BANK_EINTW(8, 0x000, "gpa0", 0x00),
@@ -339,7 +344,7 @@ static const struct samsung_pin_bank_data exynos7_pin_banks9[] __initconst = {
339 EXYNOS_PIN_BANK_EINTG(4, 0x020, "gpz1", 0x04), 344 EXYNOS_PIN_BANK_EINTG(4, 0x020, "gpz1", 0x04),
340}; 345};
341 346
342const struct samsung_pin_ctrl exynos7_pin_ctrl[] __initconst = { 347static const struct samsung_pin_ctrl exynos7_pin_ctrl[] __initconst = {
343 { 348 {
344 /* pin-controller instance 0 Alive data */ 349 /* pin-controller instance 0 Alive data */
345 .pin_banks = exynos7_pin_banks0, 350 .pin_banks = exynos7_pin_banks0,
@@ -392,3 +397,8 @@ const struct samsung_pin_ctrl exynos7_pin_ctrl[] __initconst = {
392 .eint_gpio_init = exynos_eint_gpio_init, 397 .eint_gpio_init = exynos_eint_gpio_init,
393 }, 398 },
394}; 399};
400
401const struct samsung_pinctrl_of_match_data exynos7_of_data __initconst = {
402 .ctrl = exynos7_pin_ctrl,
403 .num_ctrl = ARRAY_SIZE(exynos7_pin_ctrl),
404};
diff --git a/drivers/pinctrl/samsung/pinctrl-s3c24xx.c b/drivers/pinctrl/samsung/pinctrl-s3c24xx.c
index 10187cb0e9b9..7e824e4d20f4 100644
--- a/drivers/pinctrl/samsung/pinctrl-s3c24xx.c
+++ b/drivers/pinctrl/samsung/pinctrl-s3c24xx.c
@@ -565,7 +565,7 @@ static const struct samsung_pin_bank_data s3c2412_pin_banks[] __initconst = {
565 PIN_BANK_2BIT(13, 0x080, "gpj"), 565 PIN_BANK_2BIT(13, 0x080, "gpj"),
566}; 566};
567 567
568const struct samsung_pin_ctrl s3c2412_pin_ctrl[] __initconst = { 568static const struct samsung_pin_ctrl s3c2412_pin_ctrl[] __initconst = {
569 { 569 {
570 .pin_banks = s3c2412_pin_banks, 570 .pin_banks = s3c2412_pin_banks,
571 .nr_banks = ARRAY_SIZE(s3c2412_pin_banks), 571 .nr_banks = ARRAY_SIZE(s3c2412_pin_banks),
@@ -573,6 +573,11 @@ const struct samsung_pin_ctrl s3c2412_pin_ctrl[] __initconst = {
573 }, 573 },
574}; 574};
575 575
576const struct samsung_pinctrl_of_match_data s3c2412_of_data __initconst = {
577 .ctrl = s3c2412_pin_ctrl,
578 .num_ctrl = ARRAY_SIZE(s3c2412_pin_ctrl),
579};
580
576static const struct samsung_pin_bank_data s3c2416_pin_banks[] __initconst = { 581static const struct samsung_pin_bank_data s3c2416_pin_banks[] __initconst = {
577 PIN_BANK_A(27, 0x000, "gpa"), 582 PIN_BANK_A(27, 0x000, "gpa"),
578 PIN_BANK_2BIT(11, 0x010, "gpb"), 583 PIN_BANK_2BIT(11, 0x010, "gpb"),
@@ -587,7 +592,7 @@ static const struct samsung_pin_bank_data s3c2416_pin_banks[] __initconst = {
587 PIN_BANK_2BIT(2, 0x100, "gpm"), 592 PIN_BANK_2BIT(2, 0x100, "gpm"),
588}; 593};
589 594
590const struct samsung_pin_ctrl s3c2416_pin_ctrl[] __initconst = { 595static const struct samsung_pin_ctrl s3c2416_pin_ctrl[] __initconst = {
591 { 596 {
592 .pin_banks = s3c2416_pin_banks, 597 .pin_banks = s3c2416_pin_banks,
593 .nr_banks = ARRAY_SIZE(s3c2416_pin_banks), 598 .nr_banks = ARRAY_SIZE(s3c2416_pin_banks),
@@ -595,6 +600,11 @@ const struct samsung_pin_ctrl s3c2416_pin_ctrl[] __initconst = {
595 }, 600 },
596}; 601};
597 602
603const struct samsung_pinctrl_of_match_data s3c2416_of_data __initconst = {
604 .ctrl = s3c2416_pin_ctrl,
605 .num_ctrl = ARRAY_SIZE(s3c2416_pin_ctrl),
606};
607
598static const struct samsung_pin_bank_data s3c2440_pin_banks[] __initconst = { 608static const struct samsung_pin_bank_data s3c2440_pin_banks[] __initconst = {
599 PIN_BANK_A(25, 0x000, "gpa"), 609 PIN_BANK_A(25, 0x000, "gpa"),
600 PIN_BANK_2BIT(11, 0x010, "gpb"), 610 PIN_BANK_2BIT(11, 0x010, "gpb"),
@@ -607,7 +617,7 @@ static const struct samsung_pin_bank_data s3c2440_pin_banks[] __initconst = {
607 PIN_BANK_2BIT(13, 0x0d0, "gpj"), 617 PIN_BANK_2BIT(13, 0x0d0, "gpj"),
608}; 618};
609 619
610const struct samsung_pin_ctrl s3c2440_pin_ctrl[] __initconst = { 620static const struct samsung_pin_ctrl s3c2440_pin_ctrl[] __initconst = {
611 { 621 {
612 .pin_banks = s3c2440_pin_banks, 622 .pin_banks = s3c2440_pin_banks,
613 .nr_banks = ARRAY_SIZE(s3c2440_pin_banks), 623 .nr_banks = ARRAY_SIZE(s3c2440_pin_banks),
@@ -615,6 +625,11 @@ const struct samsung_pin_ctrl s3c2440_pin_ctrl[] __initconst = {
615 }, 625 },
616}; 626};
617 627
628const struct samsung_pinctrl_of_match_data s3c2440_of_data __initconst = {
629 .ctrl = s3c2440_pin_ctrl,
630 .num_ctrl = ARRAY_SIZE(s3c2440_pin_ctrl),
631};
632
618static const struct samsung_pin_bank_data s3c2450_pin_banks[] __initconst = { 633static const struct samsung_pin_bank_data s3c2450_pin_banks[] __initconst = {
619 PIN_BANK_A(28, 0x000, "gpa"), 634 PIN_BANK_A(28, 0x000, "gpa"),
620 PIN_BANK_2BIT(11, 0x010, "gpb"), 635 PIN_BANK_2BIT(11, 0x010, "gpb"),
@@ -630,10 +645,15 @@ static const struct samsung_pin_bank_data s3c2450_pin_banks[] __initconst = {
630 PIN_BANK_2BIT(2, 0x100, "gpm"), 645 PIN_BANK_2BIT(2, 0x100, "gpm"),
631}; 646};
632 647
633const struct samsung_pin_ctrl s3c2450_pin_ctrl[] __initconst = { 648static const struct samsung_pin_ctrl s3c2450_pin_ctrl[] __initconst = {
634 { 649 {
635 .pin_banks = s3c2450_pin_banks, 650 .pin_banks = s3c2450_pin_banks,
636 .nr_banks = ARRAY_SIZE(s3c2450_pin_banks), 651 .nr_banks = ARRAY_SIZE(s3c2450_pin_banks),
637 .eint_wkup_init = s3c24xx_eint_init, 652 .eint_wkup_init = s3c24xx_eint_init,
638 }, 653 },
639}; 654};
655
656const struct samsung_pinctrl_of_match_data s3c2450_of_data __initconst = {
657 .ctrl = s3c2450_pin_ctrl,
658 .num_ctrl = ARRAY_SIZE(s3c2450_pin_ctrl),
659};
diff --git a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
index 679628ac4b31..288e6567ceb1 100644
--- a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
+++ b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
@@ -789,7 +789,7 @@ static const struct samsung_pin_bank_data s3c64xx_pin_banks0[] __initconst = {
789 * Samsung pinctrl driver data for S3C64xx SoC. S3C64xx SoC includes 789 * Samsung pinctrl driver data for S3C64xx SoC. S3C64xx SoC includes
790 * one gpio/pin-mux/pinconfig controller. 790 * one gpio/pin-mux/pinconfig controller.
791 */ 791 */
792const struct samsung_pin_ctrl s3c64xx_pin_ctrl[] __initconst = { 792static const struct samsung_pin_ctrl s3c64xx_pin_ctrl[] __initconst = {
793 { 793 {
794 /* pin-controller instance 1 data */ 794 /* pin-controller instance 1 data */
795 .pin_banks = s3c64xx_pin_banks0, 795 .pin_banks = s3c64xx_pin_banks0,
@@ -798,3 +798,8 @@ const struct samsung_pin_ctrl s3c64xx_pin_ctrl[] __initconst = {
798 .eint_wkup_init = s3c64xx_eint_eint0_init, 798 .eint_wkup_init = s3c64xx_eint_eint0_init,
799 }, 799 },
800}; 800};
801
802const struct samsung_pinctrl_of_match_data s3c64xx_of_data __initconst = {
803 .ctrl = s3c64xx_pin_ctrl,
804 .num_ctrl = ARRAY_SIZE(s3c64xx_pin_ctrl),
805};
diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index da58e4554137..336e88d7bdb9 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -942,12 +942,33 @@ static int samsung_gpiolib_register(struct platform_device *pdev,
942 return 0; 942 return 0;
943} 943}
944 944
945static const struct samsung_pin_ctrl *
946samsung_pinctrl_get_soc_data_for_of_alias(struct platform_device *pdev)
947{
948 struct device_node *node = pdev->dev.of_node;
949 const struct samsung_pinctrl_of_match_data *of_data;
950 int id;
951
952 id = of_alias_get_id(node, "pinctrl");
953 if (id < 0) {
954 dev_err(&pdev->dev, "failed to get alias id\n");
955 return NULL;
956 }
957
958 of_data = of_device_get_match_data(&pdev->dev);
959 if (id >= of_data->num_ctrl) {
960 dev_err(&pdev->dev, "invalid alias id %d\n", id);
961 return NULL;
962 }
963
964 return &(of_data->ctrl[id]);
965}
966
945/* retrieve the soc specific data */ 967/* retrieve the soc specific data */
946static const struct samsung_pin_ctrl * 968static const struct samsung_pin_ctrl *
947samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d, 969samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
948 struct platform_device *pdev) 970 struct platform_device *pdev)
949{ 971{
950 int id;
951 struct device_node *node = pdev->dev.of_node; 972 struct device_node *node = pdev->dev.of_node;
952 struct device_node *np; 973 struct device_node *np;
953 const struct samsung_pin_bank_data *bdata; 974 const struct samsung_pin_bank_data *bdata;
@@ -957,13 +978,9 @@ samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
957 void __iomem *virt_base[SAMSUNG_PINCTRL_NUM_RESOURCES]; 978 void __iomem *virt_base[SAMSUNG_PINCTRL_NUM_RESOURCES];
958 unsigned int i; 979 unsigned int i;
959 980
960 id = of_alias_get_id(node, "pinctrl"); 981 ctrl = samsung_pinctrl_get_soc_data_for_of_alias(pdev);
961 if (id < 0) { 982 if (!ctrl)
962 dev_err(&pdev->dev, "failed to get alias id\n");
963 return ERR_PTR(-ENOENT); 983 return ERR_PTR(-ENOENT);
964 }
965 ctrl = of_device_get_match_data(&pdev->dev);
966 ctrl += id;
967 984
968 d->suspend = ctrl->suspend; 985 d->suspend = ctrl->suspend;
969 d->resume = ctrl->resume; 986 d->resume = ctrl->resume;
@@ -1188,41 +1205,41 @@ static int __maybe_unused samsung_pinctrl_resume(struct device *dev)
1188static const struct of_device_id samsung_pinctrl_dt_match[] = { 1205static const struct of_device_id samsung_pinctrl_dt_match[] = {
1189#ifdef CONFIG_PINCTRL_EXYNOS_ARM 1206#ifdef CONFIG_PINCTRL_EXYNOS_ARM
1190 { .compatible = "samsung,exynos3250-pinctrl", 1207 { .compatible = "samsung,exynos3250-pinctrl",
1191 .data = exynos3250_pin_ctrl }, 1208 .data = &exynos3250_of_data },
1192 { .compatible = "samsung,exynos4210-pinctrl", 1209 { .compatible = "samsung,exynos4210-pinctrl",
1193 .data = exynos4210_pin_ctrl }, 1210 .data = &exynos4210_of_data },
1194 { .compatible = "samsung,exynos4x12-pinctrl", 1211 { .compatible = "samsung,exynos4x12-pinctrl",
1195 .data = exynos4x12_pin_ctrl }, 1212 .data = &exynos4x12_of_data },
1196 { .compatible = "samsung,exynos5250-pinctrl", 1213 { .compatible = "samsung,exynos5250-pinctrl",
1197 .data = exynos5250_pin_ctrl }, 1214 .data = &exynos5250_of_data },
1198 { .compatible = "samsung,exynos5260-pinctrl", 1215 { .compatible = "samsung,exynos5260-pinctrl",
1199 .data = exynos5260_pin_ctrl }, 1216 .data = &exynos5260_of_data },
1200 { .compatible = "samsung,exynos5410-pinctrl", 1217 { .compatible = "samsung,exynos5410-pinctrl",
1201 .data = exynos5410_pin_ctrl }, 1218 .data = &exynos5410_of_data },
1202 { .compatible = "samsung,exynos5420-pinctrl", 1219 { .compatible = "samsung,exynos5420-pinctrl",
1203 .data = exynos5420_pin_ctrl }, 1220 .data = &exynos5420_of_data },
1204 { .compatible = "samsung,s5pv210-pinctrl", 1221 { .compatible = "samsung,s5pv210-pinctrl",
1205 .data = s5pv210_pin_ctrl }, 1222 .data = &s5pv210_of_data },
1206#endif 1223#endif
1207#ifdef CONFIG_PINCTRL_EXYNOS_ARM64 1224#ifdef CONFIG_PINCTRL_EXYNOS_ARM64
1208 { .compatible = "samsung,exynos5433-pinctrl", 1225 { .compatible = "samsung,exynos5433-pinctrl",
1209 .data = exynos5433_pin_ctrl }, 1226 .data = &exynos5433_of_data },
1210 { .compatible = "samsung,exynos7-pinctrl", 1227 { .compatible = "samsung,exynos7-pinctrl",
1211 .data = exynos7_pin_ctrl }, 1228 .data = &exynos7_of_data },
1212#endif 1229#endif
1213#ifdef CONFIG_PINCTRL_S3C64XX 1230#ifdef CONFIG_PINCTRL_S3C64XX
1214 { .compatible = "samsung,s3c64xx-pinctrl", 1231 { .compatible = "samsung,s3c64xx-pinctrl",
1215 .data = s3c64xx_pin_ctrl }, 1232 .data = &s3c64xx_of_data },
1216#endif 1233#endif
1217#ifdef CONFIG_PINCTRL_S3C24XX 1234#ifdef CONFIG_PINCTRL_S3C24XX
1218 { .compatible = "samsung,s3c2412-pinctrl", 1235 { .compatible = "samsung,s3c2412-pinctrl",
1219 .data = s3c2412_pin_ctrl }, 1236 .data = &s3c2412_of_data },
1220 { .compatible = "samsung,s3c2416-pinctrl", 1237 { .compatible = "samsung,s3c2416-pinctrl",
1221 .data = s3c2416_pin_ctrl }, 1238 .data = &s3c2416_of_data },
1222 { .compatible = "samsung,s3c2440-pinctrl", 1239 { .compatible = "samsung,s3c2440-pinctrl",
1223 .data = s3c2440_pin_ctrl }, 1240 .data = &s3c2440_of_data },
1224 { .compatible = "samsung,s3c2450-pinctrl", 1241 { .compatible = "samsung,s3c2450-pinctrl",
1225 .data = s3c2450_pin_ctrl }, 1242 .data = &s3c2450_of_data },
1226#endif 1243#endif
1227 {}, 1244 {},
1228}; 1245};
diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.h b/drivers/pinctrl/samsung/pinctrl-samsung.h
index e204f609823b..f0cda9424dfe 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.h
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.h
@@ -282,6 +282,16 @@ struct samsung_pinctrl_drv_data {
282}; 282};
283 283
284/** 284/**
285 * struct samsung_pinctrl_of_match_data: OF match device specific configuration data.
286 * @ctrl: array of pin controller data.
287 * @num_ctrl: size of array @ctrl.
288 */
289struct samsung_pinctrl_of_match_data {
290 const struct samsung_pin_ctrl *ctrl;
291 unsigned int num_ctrl;
292};
293
294/**
285 * struct samsung_pin_group: represent group of pins of a pinmux function. 295 * struct samsung_pin_group: represent group of pins of a pinmux function.
286 * @name: name of the pin group, used to lookup the group. 296 * @name: name of the pin group, used to lookup the group.
287 * @pins: the pins included in this group. 297 * @pins: the pins included in this group.
@@ -309,20 +319,20 @@ struct samsung_pmx_func {
309}; 319};
310 320
311/* list of all exported SoC specific data */ 321/* list of all exported SoC specific data */
312extern const struct samsung_pin_ctrl exynos3250_pin_ctrl[]; 322extern const struct samsung_pinctrl_of_match_data exynos3250_of_data;
313extern const struct samsung_pin_ctrl exynos4210_pin_ctrl[]; 323extern const struct samsung_pinctrl_of_match_data exynos4210_of_data;
314extern const struct samsung_pin_ctrl exynos4x12_pin_ctrl[]; 324extern const struct samsung_pinctrl_of_match_data exynos4x12_of_data;
315extern const struct samsung_pin_ctrl exynos5250_pin_ctrl[]; 325extern const struct samsung_pinctrl_of_match_data exynos5250_of_data;
316extern const struct samsung_pin_ctrl exynos5260_pin_ctrl[]; 326extern const struct samsung_pinctrl_of_match_data exynos5260_of_data;
317extern const struct samsung_pin_ctrl exynos5410_pin_ctrl[]; 327extern const struct samsung_pinctrl_of_match_data exynos5410_of_data;
318extern const struct samsung_pin_ctrl exynos5420_pin_ctrl[]; 328extern const struct samsung_pinctrl_of_match_data exynos5420_of_data;
319extern const struct samsung_pin_ctrl exynos5433_pin_ctrl[]; 329extern const struct samsung_pinctrl_of_match_data exynos5433_of_data;
320extern const struct samsung_pin_ctrl exynos7_pin_ctrl[]; 330extern const struct samsung_pinctrl_of_match_data exynos7_of_data;
321extern const struct samsung_pin_ctrl s3c64xx_pin_ctrl[]; 331extern const struct samsung_pinctrl_of_match_data s3c64xx_of_data;
322extern const struct samsung_pin_ctrl s3c2412_pin_ctrl[]; 332extern const struct samsung_pinctrl_of_match_data s3c2412_of_data;
323extern const struct samsung_pin_ctrl s3c2416_pin_ctrl[]; 333extern const struct samsung_pinctrl_of_match_data s3c2416_of_data;
324extern const struct samsung_pin_ctrl s3c2440_pin_ctrl[]; 334extern const struct samsung_pinctrl_of_match_data s3c2440_of_data;
325extern const struct samsung_pin_ctrl s3c2450_pin_ctrl[]; 335extern const struct samsung_pinctrl_of_match_data s3c2450_of_data;
326extern const struct samsung_pin_ctrl s5pv210_pin_ctrl[]; 336extern const struct samsung_pinctrl_of_match_data s5pv210_of_data;
327 337
328#endif /* __PINCTRL_SAMSUNG_H */ 338#endif /* __PINCTRL_SAMSUNG_H */
diff --git a/drivers/pinctrl/sh-pfc/pfc-r8a7795.c b/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
index 18aeee592fdc..35951e7b89d2 100644
--- a/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
+++ b/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
@@ -1538,7 +1538,6 @@ static const struct sh_pfc_pin pinmux_pins[] = {
1538 SH_PFC_PIN_NAMED_CFG('B', 18, AVB_TD1, CFG_FLAGS), 1538 SH_PFC_PIN_NAMED_CFG('B', 18, AVB_TD1, CFG_FLAGS),
1539 SH_PFC_PIN_NAMED_CFG('B', 19, AVB_RXC, CFG_FLAGS), 1539 SH_PFC_PIN_NAMED_CFG('B', 19, AVB_RXC, CFG_FLAGS),
1540 SH_PFC_PIN_NAMED_CFG('C', 1, PRESETOUT#, CFG_FLAGS), 1540 SH_PFC_PIN_NAMED_CFG('C', 1, PRESETOUT#, CFG_FLAGS),
1541 SH_PFC_PIN_NAMED_CFG('F', 1, CLKOUT, CFG_FLAGS),
1542 SH_PFC_PIN_NAMED_CFG('H', 37, MLB_REF, CFG_FLAGS), 1541 SH_PFC_PIN_NAMED_CFG('H', 37, MLB_REF, CFG_FLAGS),
1543 SH_PFC_PIN_NAMED_CFG('V', 3, QSPI1_SPCLK, CFG_FLAGS), 1542 SH_PFC_PIN_NAMED_CFG('V', 3, QSPI1_SPCLK, CFG_FLAGS),
1544 SH_PFC_PIN_NAMED_CFG('V', 5, QSPI1_SSL, CFG_FLAGS), 1543 SH_PFC_PIN_NAMED_CFG('V', 5, QSPI1_SSL, CFG_FLAGS),
diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
index 6dec6ab13300..d8599736a41a 100644
--- a/drivers/platform/chrome/chromeos_laptop.c
+++ b/drivers/platform/chrome/chromeos_laptop.c
@@ -423,7 +423,7 @@ static int chromeos_laptop_probe(struct platform_device *pdev)
423 return ret; 423 return ret;
424} 424}
425 425
426static const struct chromeos_laptop samsung_series_5_550 = { 426static struct chromeos_laptop samsung_series_5_550 = {
427 .i2c_peripherals = { 427 .i2c_peripherals = {
428 /* Touchpad. */ 428 /* Touchpad. */
429 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, 429 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
@@ -432,14 +432,14 @@ static const struct chromeos_laptop samsung_series_5_550 = {
432 }, 432 },
433}; 433};
434 434
435static const struct chromeos_laptop samsung_series_5 = { 435static struct chromeos_laptop samsung_series_5 = {
436 .i2c_peripherals = { 436 .i2c_peripherals = {
437 /* Light Sensor. */ 437 /* Light Sensor. */
438 { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS }, 438 { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS },
439 }, 439 },
440}; 440};
441 441
442static const struct chromeos_laptop chromebook_pixel = { 442static struct chromeos_laptop chromebook_pixel = {
443 .i2c_peripherals = { 443 .i2c_peripherals = {
444 /* Touch Screen. */ 444 /* Touch Screen. */
445 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL }, 445 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL },
@@ -450,14 +450,14 @@ static const struct chromeos_laptop chromebook_pixel = {
450 }, 450 },
451}; 451};
452 452
453static const struct chromeos_laptop hp_chromebook_14 = { 453static struct chromeos_laptop hp_chromebook_14 = {
454 .i2c_peripherals = { 454 .i2c_peripherals = {
455 /* Touchpad. */ 455 /* Touchpad. */
456 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, 456 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
457 }, 457 },
458}; 458};
459 459
460static const struct chromeos_laptop dell_chromebook_11 = { 460static struct chromeos_laptop dell_chromebook_11 = {
461 .i2c_peripherals = { 461 .i2c_peripherals = {
462 /* Touchpad. */ 462 /* Touchpad. */
463 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, 463 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
@@ -466,28 +466,28 @@ static const struct chromeos_laptop dell_chromebook_11 = {
466 }, 466 },
467}; 467};
468 468
469static const struct chromeos_laptop toshiba_cb35 = { 469static struct chromeos_laptop toshiba_cb35 = {
470 .i2c_peripherals = { 470 .i2c_peripherals = {
471 /* Touchpad. */ 471 /* Touchpad. */
472 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, 472 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
473 }, 473 },
474}; 474};
475 475
476static const struct chromeos_laptop acer_c7_chromebook = { 476static struct chromeos_laptop acer_c7_chromebook = {
477 .i2c_peripherals = { 477 .i2c_peripherals = {
478 /* Touchpad. */ 478 /* Touchpad. */
479 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, 479 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
480 }, 480 },
481}; 481};
482 482
483static const struct chromeos_laptop acer_ac700 = { 483static struct chromeos_laptop acer_ac700 = {
484 .i2c_peripherals = { 484 .i2c_peripherals = {
485 /* Light Sensor. */ 485 /* Light Sensor. */
486 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS }, 486 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
487 }, 487 },
488}; 488};
489 489
490static const struct chromeos_laptop acer_c720 = { 490static struct chromeos_laptop acer_c720 = {
491 .i2c_peripherals = { 491 .i2c_peripherals = {
492 /* Touchscreen. */ 492 /* Touchscreen. */
493 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_DESIGNWARE_1 }, 493 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_DESIGNWARE_1 },
@@ -500,14 +500,14 @@ static const struct chromeos_laptop acer_c720 = {
500 }, 500 },
501}; 501};
502 502
503static const struct chromeos_laptop hp_pavilion_14_chromebook = { 503static struct chromeos_laptop hp_pavilion_14_chromebook = {
504 .i2c_peripherals = { 504 .i2c_peripherals = {
505 /* Touchpad. */ 505 /* Touchpad. */
506 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, 506 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
507 }, 507 },
508}; 508};
509 509
510static const struct chromeos_laptop cr48 = { 510static struct chromeos_laptop cr48 = {
511 .i2c_peripherals = { 511 .i2c_peripherals = {
512 /* Light Sensor. */ 512 /* Light Sensor. */
513 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS }, 513 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 9a8f96465cdc..51ebc5a6053f 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -105,31 +105,45 @@ config ASUS_LAPTOP
105 105
106 If you have an ACPI-compatible ASUS laptop, say Y or M here. 106 If you have an ACPI-compatible ASUS laptop, say Y or M here.
107 107
108#
109# The DELL_SMBIOS driver depends on ACPI_WMI and/or DCDBAS if those
110# backends are selected. The "depends" line prevents a configuration
111# where DELL_SMBIOS=y while either of those dependencies =m.
112#
108config DELL_SMBIOS 113config DELL_SMBIOS
109 tristate 114 tristate "Dell SMBIOS driver"
115 depends on DCDBAS || DCDBAS=n
116 depends on ACPI_WMI || ACPI_WMI=n
117 ---help---
118 This provides support for the Dell SMBIOS calling interface.
119 If you have a Dell computer you should enable this option.
120
121 Be sure to select at least one backend for it to work properly.
110 122
111config DELL_SMBIOS_WMI 123config DELL_SMBIOS_WMI
112 tristate "Dell SMBIOS calling interface (WMI implementation)" 124 bool "Dell SMBIOS driver WMI backend"
125 default y
113 depends on ACPI_WMI 126 depends on ACPI_WMI
114 select DELL_WMI_DESCRIPTOR 127 select DELL_WMI_DESCRIPTOR
115 select DELL_SMBIOS 128 depends on DELL_SMBIOS
116 ---help--- 129 ---help---
117 This provides an implementation for the Dell SMBIOS calling interface 130 This provides an implementation for the Dell SMBIOS calling interface
118 communicated over ACPI-WMI. 131 communicated over ACPI-WMI.
119 132
120 If you have a Dell computer from >2007 you should say Y or M here. 133 If you have a Dell computer from >2007 you should say Y here.
121 If you aren't sure and this module doesn't work for your computer 134 If you aren't sure and this module doesn't work for your computer
122 it just won't load. 135 it just won't load.
123 136
124config DELL_SMBIOS_SMM 137config DELL_SMBIOS_SMM
125 tristate "Dell SMBIOS calling interface (SMM implementation)" 138 bool "Dell SMBIOS driver SMM backend"
139 default y
126 depends on DCDBAS 140 depends on DCDBAS
127 select DELL_SMBIOS 141 depends on DELL_SMBIOS
128 ---help--- 142 ---help---
129 This provides an implementation for the Dell SMBIOS calling interface 143 This provides an implementation for the Dell SMBIOS calling interface
130 communicated over SMI/SMM. 144 communicated over SMI/SMM.
131 145
132 If you have a Dell computer from <=2017 you should say Y or M here. 146 If you have a Dell computer from <=2017 you should say Y here.
133 If you aren't sure and this module doesn't work for your computer 147 If you aren't sure and this module doesn't work for your computer
134 it just won't load. 148 it just won't load.
135 149
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index c388608ad2a3..2ba6cb795338 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -13,8 +13,9 @@ obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o
13obj-$(CONFIG_ACPI_CMPC) += classmate-laptop.o 13obj-$(CONFIG_ACPI_CMPC) += classmate-laptop.o
14obj-$(CONFIG_COMPAL_LAPTOP) += compal-laptop.o 14obj-$(CONFIG_COMPAL_LAPTOP) += compal-laptop.o
15obj-$(CONFIG_DELL_SMBIOS) += dell-smbios.o 15obj-$(CONFIG_DELL_SMBIOS) += dell-smbios.o
16obj-$(CONFIG_DELL_SMBIOS_WMI) += dell-smbios-wmi.o 16dell-smbios-objs := dell-smbios-base.o
17obj-$(CONFIG_DELL_SMBIOS_SMM) += dell-smbios-smm.o 17dell-smbios-$(CONFIG_DELL_SMBIOS_WMI) += dell-smbios-wmi.o
18dell-smbios-$(CONFIG_DELL_SMBIOS_SMM) += dell-smbios-smm.o
18obj-$(CONFIG_DELL_LAPTOP) += dell-laptop.o 19obj-$(CONFIG_DELL_LAPTOP) += dell-laptop.o
19obj-$(CONFIG_DELL_WMI) += dell-wmi.o 20obj-$(CONFIG_DELL_WMI) += dell-wmi.o
20obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o 21obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o
diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index 2a68f59d2228..c52c6723374b 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -127,24 +127,6 @@ static const struct dmi_system_id dell_device_table[] __initconst = {
127 }, 127 },
128 }, 128 },
129 { 129 {
130 .matches = {
131 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
132 DMI_MATCH(DMI_CHASSIS_TYPE, "30"), /*Tablet*/
133 },
134 },
135 {
136 .matches = {
137 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
138 DMI_MATCH(DMI_CHASSIS_TYPE, "31"), /*Convertible*/
139 },
140 },
141 {
142 .matches = {
143 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
144 DMI_MATCH(DMI_CHASSIS_TYPE, "32"), /*Detachable*/
145 },
146 },
147 {
148 .ident = "Dell Computer Corporation", 130 .ident = "Dell Computer Corporation",
149 .matches = { 131 .matches = {
150 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 132 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
@@ -1279,7 +1261,7 @@ static int kbd_get_state(struct kbd_state *state)
1279 struct calling_interface_buffer buffer; 1261 struct calling_interface_buffer buffer;
1280 int ret; 1262 int ret;
1281 1263
1282 dell_fill_request(&buffer, 0, 0, 0, 0); 1264 dell_fill_request(&buffer, 0x1, 0, 0, 0);
1283 ret = dell_send_request(&buffer, 1265 ret = dell_send_request(&buffer,
1284 CLASS_KBD_BACKLIGHT, SELECT_KBD_BACKLIGHT); 1266 CLASS_KBD_BACKLIGHT, SELECT_KBD_BACKLIGHT);
1285 if (ret) 1267 if (ret)
diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell-smbios-base.c
index 8541cde4cb7d..2485c80a9fdd 100644
--- a/drivers/platform/x86/dell-smbios.c
+++ b/drivers/platform/x86/dell-smbios-base.c
@@ -36,7 +36,7 @@ static DEFINE_MUTEX(smbios_mutex);
36struct smbios_device { 36struct smbios_device {
37 struct list_head list; 37 struct list_head list;
38 struct device *device; 38 struct device *device;
39 int (*call_fn)(struct calling_interface_buffer *); 39 int (*call_fn)(struct calling_interface_buffer *arg);
40}; 40};
41 41
42struct smbios_call { 42struct smbios_call {
@@ -352,8 +352,10 @@ static void __init parse_da_table(const struct dmi_header *dm)
352 struct calling_interface_structure *table = 352 struct calling_interface_structure *table =
353 container_of(dm, struct calling_interface_structure, header); 353 container_of(dm, struct calling_interface_structure, header);
354 354
355 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least 355 /*
356 6 bytes of entry */ 356 * 4 bytes of table header, plus 7 bytes of Dell header
357 * plus at least 6 bytes of entry
358 */
357 359
358 if (dm->length < 17) 360 if (dm->length < 17)
359 return; 361 return;
@@ -554,7 +556,7 @@ static void free_group(struct platform_device *pdev)
554static int __init dell_smbios_init(void) 556static int __init dell_smbios_init(void)
555{ 557{
556 const struct dmi_device *valid; 558 const struct dmi_device *valid;
557 int ret; 559 int ret, wmi, smm;
558 560
559 valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, "Dell System", NULL); 561 valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, "Dell System", NULL);
560 if (!valid) { 562 if (!valid) {
@@ -589,8 +591,24 @@ static int __init dell_smbios_init(void)
589 if (ret) 591 if (ret)
590 goto fail_create_group; 592 goto fail_create_group;
591 593
594 /* register backends */
595 wmi = init_dell_smbios_wmi();
596 if (wmi)
597 pr_debug("Failed to initialize WMI backend: %d\n", wmi);
598 smm = init_dell_smbios_smm();
599 if (smm)
600 pr_debug("Failed to initialize SMM backend: %d\n", smm);
601 if (wmi && smm) {
602 pr_err("No SMBIOS backends available (wmi: %d, smm: %d)\n",
603 wmi, smm);
604 goto fail_sysfs;
605 }
606
592 return 0; 607 return 0;
593 608
609fail_sysfs:
610 free_group(platform_device);
611
594fail_create_group: 612fail_create_group:
595 platform_device_del(platform_device); 613 platform_device_del(platform_device);
596 614
@@ -607,6 +625,8 @@ fail_platform_driver:
607 625
608static void __exit dell_smbios_exit(void) 626static void __exit dell_smbios_exit(void)
609{ 627{
628 exit_dell_smbios_wmi();
629 exit_dell_smbios_smm();
610 mutex_lock(&smbios_mutex); 630 mutex_lock(&smbios_mutex);
611 if (platform_device) { 631 if (platform_device) {
612 free_group(platform_device); 632 free_group(platform_device);
@@ -617,11 +637,12 @@ static void __exit dell_smbios_exit(void)
617 mutex_unlock(&smbios_mutex); 637 mutex_unlock(&smbios_mutex);
618} 638}
619 639
620subsys_initcall(dell_smbios_init); 640module_init(dell_smbios_init);
621module_exit(dell_smbios_exit); 641module_exit(dell_smbios_exit);
622 642
623MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); 643MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
624MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>"); 644MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
625MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); 645MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
646MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
626MODULE_DESCRIPTION("Common functions for kernel modules using Dell SMBIOS"); 647MODULE_DESCRIPTION("Common functions for kernel modules using Dell SMBIOS");
627MODULE_LICENSE("GPL"); 648MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/dell-smbios-smm.c b/drivers/platform/x86/dell-smbios-smm.c
index 89f65c4651a0..e9e9da556318 100644
--- a/drivers/platform/x86/dell-smbios-smm.c
+++ b/drivers/platform/x86/dell-smbios-smm.c
@@ -58,7 +58,7 @@ static const struct dmi_system_id dell_device_table[] __initconst = {
58}; 58};
59MODULE_DEVICE_TABLE(dmi, dell_device_table); 59MODULE_DEVICE_TABLE(dmi, dell_device_table);
60 60
61static void __init parse_da_table(const struct dmi_header *dm) 61static void parse_da_table(const struct dmi_header *dm)
62{ 62{
63 struct calling_interface_structure *table = 63 struct calling_interface_structure *table =
64 container_of(dm, struct calling_interface_structure, header); 64 container_of(dm, struct calling_interface_structure, header);
@@ -73,7 +73,7 @@ static void __init parse_da_table(const struct dmi_header *dm)
73 da_command_code = table->cmdIOCode; 73 da_command_code = table->cmdIOCode;
74} 74}
75 75
76static void __init find_cmd_address(const struct dmi_header *dm, void *dummy) 76static void find_cmd_address(const struct dmi_header *dm, void *dummy)
77{ 77{
78 switch (dm->type) { 78 switch (dm->type) {
79 case 0xda: /* Calling interface */ 79 case 0xda: /* Calling interface */
@@ -128,7 +128,7 @@ static bool test_wsmt_enabled(void)
128 return false; 128 return false;
129} 129}
130 130
131static int __init dell_smbios_smm_init(void) 131int init_dell_smbios_smm(void)
132{ 132{
133 int ret; 133 int ret;
134 /* 134 /*
@@ -176,7 +176,7 @@ fail_platform_device_alloc:
176 return ret; 176 return ret;
177} 177}
178 178
179static void __exit dell_smbios_smm_exit(void) 179void exit_dell_smbios_smm(void)
180{ 180{
181 if (platform_device) { 181 if (platform_device) {
182 dell_smbios_unregister_device(&platform_device->dev); 182 dell_smbios_unregister_device(&platform_device->dev);
@@ -184,13 +184,3 @@ static void __exit dell_smbios_smm_exit(void)
184 free_page((unsigned long)buffer); 184 free_page((unsigned long)buffer);
185 } 185 }
186} 186}
187
188subsys_initcall(dell_smbios_smm_init);
189module_exit(dell_smbios_smm_exit);
190
191MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
192MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
193MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
194MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
195MODULE_DESCRIPTION("Dell SMBIOS communications over SMI");
196MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/dell-smbios-wmi.c b/drivers/platform/x86/dell-smbios-wmi.c
index 609557aa5868..fbefedb1c172 100644
--- a/drivers/platform/x86/dell-smbios-wmi.c
+++ b/drivers/platform/x86/dell-smbios-wmi.c
@@ -228,7 +228,7 @@ static const struct wmi_device_id dell_smbios_wmi_id_table[] = {
228 { }, 228 { },
229}; 229};
230 230
231static void __init parse_b1_table(const struct dmi_header *dm) 231static void parse_b1_table(const struct dmi_header *dm)
232{ 232{
233 struct misc_bios_flags_structure *flags = 233 struct misc_bios_flags_structure *flags =
234 container_of(dm, struct misc_bios_flags_structure, header); 234 container_of(dm, struct misc_bios_flags_structure, header);
@@ -242,7 +242,7 @@ static void __init parse_b1_table(const struct dmi_header *dm)
242 wmi_supported = 1; 242 wmi_supported = 1;
243} 243}
244 244
245static void __init find_b1(const struct dmi_header *dm, void *dummy) 245static void find_b1(const struct dmi_header *dm, void *dummy)
246{ 246{
247 switch (dm->type) { 247 switch (dm->type) {
248 case 0xb1: /* misc bios flags */ 248 case 0xb1: /* misc bios flags */
@@ -261,7 +261,7 @@ static struct wmi_driver dell_smbios_wmi_driver = {
261 .filter_callback = dell_smbios_wmi_filter, 261 .filter_callback = dell_smbios_wmi_filter,
262}; 262};
263 263
264static int __init init_dell_smbios_wmi(void) 264int init_dell_smbios_wmi(void)
265{ 265{
266 dmi_walk(find_b1, NULL); 266 dmi_walk(find_b1, NULL);
267 267
@@ -271,15 +271,9 @@ static int __init init_dell_smbios_wmi(void)
271 return wmi_driver_register(&dell_smbios_wmi_driver); 271 return wmi_driver_register(&dell_smbios_wmi_driver);
272} 272}
273 273
274static void __exit exit_dell_smbios_wmi(void) 274void exit_dell_smbios_wmi(void)
275{ 275{
276 wmi_driver_unregister(&dell_smbios_wmi_driver); 276 wmi_driver_unregister(&dell_smbios_wmi_driver);
277} 277}
278 278
279module_init(init_dell_smbios_wmi);
280module_exit(exit_dell_smbios_wmi);
281
282MODULE_ALIAS("wmi:" DELL_WMI_SMBIOS_GUID); 279MODULE_ALIAS("wmi:" DELL_WMI_SMBIOS_GUID);
283MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
284MODULE_DESCRIPTION("Dell SMBIOS communications over WMI");
285MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/dell-smbios.h b/drivers/platform/x86/dell-smbios.h
index 138d478d9adc..d8adaf959740 100644
--- a/drivers/platform/x86/dell-smbios.h
+++ b/drivers/platform/x86/dell-smbios.h
@@ -75,4 +75,29 @@ int dell_laptop_register_notifier(struct notifier_block *nb);
75int dell_laptop_unregister_notifier(struct notifier_block *nb); 75int dell_laptop_unregister_notifier(struct notifier_block *nb);
76void dell_laptop_call_notifier(unsigned long action, void *data); 76void dell_laptop_call_notifier(unsigned long action, void *data);
77 77
78#endif 78/* for the supported backends */
79#ifdef CONFIG_DELL_SMBIOS_WMI
80int init_dell_smbios_wmi(void);
81void exit_dell_smbios_wmi(void);
82#else /* CONFIG_DELL_SMBIOS_WMI */
83static inline int init_dell_smbios_wmi(void)
84{
85 return -ENODEV;
86}
87static inline void exit_dell_smbios_wmi(void)
88{}
89#endif /* CONFIG_DELL_SMBIOS_WMI */
90
91#ifdef CONFIG_DELL_SMBIOS_SMM
92int init_dell_smbios_smm(void);
93void exit_dell_smbios_smm(void);
94#else /* CONFIG_DELL_SMBIOS_SMM */
95static inline int init_dell_smbios_smm(void)
96{
97 return -ENODEV;
98}
99static inline void exit_dell_smbios_smm(void)
100{}
101#endif /* CONFIG_DELL_SMBIOS_SMM */
102
103#endif /* _DELL_SMBIOS_H_ */
diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell-wmi.c
index 2c9927430d85..8d102195a392 100644
--- a/drivers/platform/x86/dell-wmi.c
+++ b/drivers/platform/x86/dell-wmi.c
@@ -714,7 +714,7 @@ static int __init dell_wmi_init(void)
714 714
715 return wmi_driver_register(&dell_wmi_driver); 715 return wmi_driver_register(&dell_wmi_driver);
716} 716}
717module_init(dell_wmi_init); 717late_initcall(dell_wmi_init);
718 718
719static void __exit dell_wmi_exit(void) 719static void __exit dell_wmi_exit(void)
720{ 720{
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index 5b6f18b18801..535199c9e6bc 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -113,7 +113,7 @@ MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
113/* 113/*
114 * ACPI Helpers 114 * ACPI Helpers
115 */ 115 */
116#define IDEAPAD_EC_TIMEOUT (100) /* in ms */ 116#define IDEAPAD_EC_TIMEOUT (200) /* in ms */
117 117
118static int read_method_int(acpi_handle handle, const char *method, int *val) 118static int read_method_int(acpi_handle handle, const char *method, int *val)
119{ 119{
diff --git a/drivers/platform/x86/intel-hid.c b/drivers/platform/x86/intel-hid.c
index d1a01311c1a2..5e3df194723e 100644
--- a/drivers/platform/x86/intel-hid.c
+++ b/drivers/platform/x86/intel-hid.c
@@ -376,6 +376,7 @@ static int intel_hid_remove(struct platform_device *device)
376{ 376{
377 acpi_handle handle = ACPI_HANDLE(&device->dev); 377 acpi_handle handle = ACPI_HANDLE(&device->dev);
378 378
379 device_init_wakeup(&device->dev, false);
379 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); 380 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler);
380 intel_hid_set_enable(&device->dev, false); 381 intel_hid_set_enable(&device->dev, false);
381 intel_button_array_enable(&device->dev, false); 382 intel_button_array_enable(&device->dev, false);
diff --git a/drivers/platform/x86/intel-vbtn.c b/drivers/platform/x86/intel-vbtn.c
index b703d6f5b099..c13780b8dabb 100644
--- a/drivers/platform/x86/intel-vbtn.c
+++ b/drivers/platform/x86/intel-vbtn.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/acpi.h> 9#include <linux/acpi.h>
10#include <linux/dmi.h>
10#include <linux/input.h> 11#include <linux/input.h>
11#include <linux/input/sparse-keymap.h> 12#include <linux/input/sparse-keymap.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
@@ -97,9 +98,35 @@ out_unknown:
97 dev_dbg(&device->dev, "unknown event index 0x%x\n", event); 98 dev_dbg(&device->dev, "unknown event index 0x%x\n", event);
98} 99}
99 100
100static int intel_vbtn_probe(struct platform_device *device) 101static void detect_tablet_mode(struct platform_device *device)
101{ 102{
103 const char *chassis_type = dmi_get_system_info(DMI_CHASSIS_TYPE);
104 struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev);
105 acpi_handle handle = ACPI_HANDLE(&device->dev);
102 struct acpi_buffer vgbs_output = { ACPI_ALLOCATE_BUFFER, NULL }; 106 struct acpi_buffer vgbs_output = { ACPI_ALLOCATE_BUFFER, NULL };
107 union acpi_object *obj;
108 acpi_status status;
109 int m;
110
111 if (!(chassis_type && strcmp(chassis_type, "31") == 0))
112 goto out;
113
114 status = acpi_evaluate_object(handle, "VGBS", NULL, &vgbs_output);
115 if (ACPI_FAILURE(status))
116 goto out;
117
118 obj = vgbs_output.pointer;
119 if (!(obj && obj->type == ACPI_TYPE_INTEGER))
120 goto out;
121
122 m = !(obj->integer.value & TABLET_MODE_FLAG);
123 input_report_switch(priv->input_dev, SW_TABLET_MODE, m);
124out:
125 kfree(vgbs_output.pointer);
126}
127
128static int intel_vbtn_probe(struct platform_device *device)
129{
103 acpi_handle handle = ACPI_HANDLE(&device->dev); 130 acpi_handle handle = ACPI_HANDLE(&device->dev);
104 struct intel_vbtn_priv *priv; 131 struct intel_vbtn_priv *priv;
105 acpi_status status; 132 acpi_status status;
@@ -122,22 +149,7 @@ static int intel_vbtn_probe(struct platform_device *device)
122 return err; 149 return err;
123 } 150 }
124 151
125 /* 152 detect_tablet_mode(device);
126 * VGBS being present and returning something means we have
127 * a tablet mode switch.
128 */
129 status = acpi_evaluate_object(handle, "VGBS", NULL, &vgbs_output);
130 if (ACPI_SUCCESS(status)) {
131 union acpi_object *obj = vgbs_output.pointer;
132
133 if (obj && obj->type == ACPI_TYPE_INTEGER) {
134 int m = !(obj->integer.value & TABLET_MODE_FLAG);
135
136 input_report_switch(priv->input_dev, SW_TABLET_MODE, m);
137 }
138 }
139
140 kfree(vgbs_output.pointer);
141 153
142 status = acpi_install_notify_handler(handle, 154 status = acpi_install_notify_handler(handle,
143 ACPI_DEVICE_NOTIFY, 155 ACPI_DEVICE_NOTIFY,
@@ -154,6 +166,7 @@ static int intel_vbtn_remove(struct platform_device *device)
154{ 166{
155 acpi_handle handle = ACPI_HANDLE(&device->dev); 167 acpi_handle handle = ACPI_HANDLE(&device->dev);
156 168
169 device_init_wakeup(&device->dev, false);
157 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); 170 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler);
158 171
159 /* 172 /*
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index daa68acbc900..8796211ef24a 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -933,7 +933,7 @@ static int wmi_dev_probe(struct device *dev)
933 goto probe_failure; 933 goto probe_failure;
934 } 934 }
935 935
936 buf = kmalloc(strlen(wdriver->driver.name) + 4, GFP_KERNEL); 936 buf = kmalloc(strlen(wdriver->driver.name) + 5, GFP_KERNEL);
937 if (!buf) { 937 if (!buf) {
938 ret = -ENOMEM; 938 ret = -ENOMEM;
939 goto probe_string_failure; 939 goto probe_string_failure;
@@ -945,7 +945,7 @@ static int wmi_dev_probe(struct device *dev)
945 wblock->char_dev.mode = 0444; 945 wblock->char_dev.mode = 0444;
946 ret = misc_register(&wblock->char_dev); 946 ret = misc_register(&wblock->char_dev);
947 if (ret) { 947 if (ret) {
948 dev_warn(dev, "failed to register char dev: %d", ret); 948 dev_warn(dev, "failed to register char dev: %d\n", ret);
949 ret = -ENOMEM; 949 ret = -ENOMEM;
950 goto probe_misc_failure; 950 goto probe_misc_failure;
951 } 951 }
@@ -1048,7 +1048,7 @@ static int wmi_create_device(struct device *wmi_bus_dev,
1048 1048
1049 if (result) { 1049 if (result) {
1050 dev_warn(wmi_bus_dev, 1050 dev_warn(wmi_bus_dev,
1051 "%s data block query control method not found", 1051 "%s data block query control method not found\n",
1052 method); 1052 method);
1053 return result; 1053 return result;
1054 } 1054 }
@@ -1198,7 +1198,7 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
1198 1198
1199 retval = device_add(&wblock->dev.dev); 1199 retval = device_add(&wblock->dev.dev);
1200 if (retval) { 1200 if (retval) {
1201 dev_err(wmi_bus_dev, "failed to register %pULL\n", 1201 dev_err(wmi_bus_dev, "failed to register %pUL\n",
1202 wblock->gblock.guid); 1202 wblock->gblock.guid);
1203 if (debug_event) 1203 if (debug_event)
1204 wmi_method_enable(wblock, 0); 1204 wmi_method_enable(wblock, 0);
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index dd4708c58480..1fc0c0811da4 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -4310,7 +4310,7 @@ static int _regulator_resume_early(struct device *dev, void *data)
4310 4310
4311 rstate = regulator_get_suspend_state(rdev, *state); 4311 rstate = regulator_get_suspend_state(rdev, *state);
4312 if (rstate == NULL) 4312 if (rstate == NULL)
4313 return -EINVAL; 4313 return 0;
4314 4314
4315 mutex_lock(&rdev->mutex); 4315 mutex_lock(&rdev->mutex);
4316 4316
diff --git a/drivers/regulator/stm32-vrefbuf.c b/drivers/regulator/stm32-vrefbuf.c
index 72c8b3e1022b..e0a9c445ed67 100644
--- a/drivers/regulator/stm32-vrefbuf.c
+++ b/drivers/regulator/stm32-vrefbuf.c
@@ -51,7 +51,7 @@ static int stm32_vrefbuf_enable(struct regulator_dev *rdev)
51 * arbitrary timeout. 51 * arbitrary timeout.
52 */ 52 */
53 ret = readl_poll_timeout(priv->base + STM32_VREFBUF_CSR, val, 53 ret = readl_poll_timeout(priv->base + STM32_VREFBUF_CSR, val,
54 !(val & STM32_VRR), 650, 10000); 54 val & STM32_VRR, 650, 10000);
55 if (ret) { 55 if (ret) {
56 dev_err(&rdev->dev, "stm32 vrefbuf timed out!\n"); 56 dev_err(&rdev->dev, "stm32 vrefbuf timed out!\n");
57 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); 57 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index a7c15f0085e2..ecef8e73d40b 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -2581,8 +2581,6 @@ int dasd_cancel_req(struct dasd_ccw_req *cqr)
2581 case DASD_CQR_QUEUED: 2581 case DASD_CQR_QUEUED:
2582 /* request was not started - just set to cleared */ 2582 /* request was not started - just set to cleared */
2583 cqr->status = DASD_CQR_CLEARED; 2583 cqr->status = DASD_CQR_CLEARED;
2584 if (cqr->callback_data == DASD_SLEEPON_START_TAG)
2585 cqr->callback_data = DASD_SLEEPON_END_TAG;
2586 break; 2584 break;
2587 case DASD_CQR_IN_IO: 2585 case DASD_CQR_IN_IO:
2588 /* request in IO - terminate IO and release again */ 2586 /* request in IO - terminate IO and release again */
@@ -3902,9 +3900,12 @@ static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3902 wait_event(dasd_flush_wq, 3900 wait_event(dasd_flush_wq,
3903 (cqr->status != DASD_CQR_CLEAR_PENDING)); 3901 (cqr->status != DASD_CQR_CLEAR_PENDING));
3904 3902
3905 /* mark sleepon requests as ended */ 3903 /*
3906 if (cqr->callback_data == DASD_SLEEPON_START_TAG) 3904 * requeue requests to blocklayer will only work
3907 cqr->callback_data = DASD_SLEEPON_END_TAG; 3905 * for block device requests
3906 */
3907 if (_dasd_requeue_request(cqr))
3908 continue;
3908 3909
3909 /* remove requests from device and block queue */ 3910 /* remove requests from device and block queue */
3910 list_del_init(&cqr->devlist); 3911 list_del_init(&cqr->devlist);
@@ -3917,13 +3918,6 @@ static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3917 cqr = refers; 3918 cqr = refers;
3918 } 3919 }
3919 3920
3920 /*
3921 * requeue requests to blocklayer will only work
3922 * for block device requests
3923 */
3924 if (_dasd_requeue_request(cqr))
3925 continue;
3926
3927 if (cqr->block) 3921 if (cqr->block)
3928 list_del_init(&cqr->blocklist); 3922 list_del_init(&cqr->blocklist);
3929 cqr->block->base->discipline->free_cp( 3923 cqr->block->base->discipline->free_cp(
@@ -3940,8 +3934,7 @@ static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3940 list_splice_tail(&requeue_queue, &device->ccw_queue); 3934 list_splice_tail(&requeue_queue, &device->ccw_queue);
3941 spin_unlock_irq(get_ccwdev_lock(device->cdev)); 3935 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3942 } 3936 }
3943 /* wake up generic waitqueue for eventually ended sleepon requests */ 3937 dasd_schedule_device_bh(device);
3944 wake_up(&generic_waitq);
3945 return rc; 3938 return rc;
3946} 3939}
3947 3940
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index 1319122e9d12..9169af7dbb43 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -795,6 +795,7 @@ ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
795 795
796 ccw_device_set_timeout(cdev, 0); 796 ccw_device_set_timeout(cdev, 0);
797 cdev->private->iretry = 255; 797 cdev->private->iretry = 255;
798 cdev->private->async_kill_io_rc = -ETIMEDOUT;
798 ret = ccw_device_cancel_halt_clear(cdev); 799 ret = ccw_device_cancel_halt_clear(cdev);
799 if (ret == -EBUSY) { 800 if (ret == -EBUSY) {
800 ccw_device_set_timeout(cdev, 3*HZ); 801 ccw_device_set_timeout(cdev, 3*HZ);
@@ -871,7 +872,7 @@ ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
871 /* OK, i/o is dead now. Call interrupt handler. */ 872 /* OK, i/o is dead now. Call interrupt handler. */
872 if (cdev->handler) 873 if (cdev->handler)
873 cdev->handler(cdev, cdev->private->intparm, 874 cdev->handler(cdev, cdev->private->intparm,
874 ERR_PTR(-EIO)); 875 ERR_PTR(cdev->private->async_kill_io_rc));
875} 876}
876 877
877static void 878static void
@@ -888,14 +889,16 @@ ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
888 ccw_device_online_verify(cdev, 0); 889 ccw_device_online_verify(cdev, 0);
889 if (cdev->handler) 890 if (cdev->handler)
890 cdev->handler(cdev, cdev->private->intparm, 891 cdev->handler(cdev, cdev->private->intparm,
891 ERR_PTR(-EIO)); 892 ERR_PTR(cdev->private->async_kill_io_rc));
892} 893}
893 894
894void ccw_device_kill_io(struct ccw_device *cdev) 895void ccw_device_kill_io(struct ccw_device *cdev)
895{ 896{
896 int ret; 897 int ret;
897 898
899 ccw_device_set_timeout(cdev, 0);
898 cdev->private->iretry = 255; 900 cdev->private->iretry = 255;
901 cdev->private->async_kill_io_rc = -EIO;
899 ret = ccw_device_cancel_halt_clear(cdev); 902 ret = ccw_device_cancel_halt_clear(cdev);
900 if (ret == -EBUSY) { 903 if (ret == -EBUSY) {
901 ccw_device_set_timeout(cdev, 3*HZ); 904 ccw_device_set_timeout(cdev, 3*HZ);
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index 1caf6a398760..75ce12a24dc2 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -159,7 +159,7 @@ int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
159} 159}
160 160
161/** 161/**
162 * ccw_device_start_key() - start a s390 channel program with key 162 * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key
163 * @cdev: target ccw device 163 * @cdev: target ccw device
164 * @cpa: logical start address of channel program 164 * @cpa: logical start address of channel program
165 * @intparm: user specific interruption parameter; will be presented back to 165 * @intparm: user specific interruption parameter; will be presented back to
@@ -170,10 +170,15 @@ int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
170 * @key: storage key to be used for the I/O 170 * @key: storage key to be used for the I/O
171 * @flags: additional flags; defines the action to be performed for I/O 171 * @flags: additional flags; defines the action to be performed for I/O
172 * processing. 172 * processing.
173 * @expires: timeout value in jiffies
173 * 174 *
174 * Start a S/390 channel program. When the interrupt arrives, the 175 * Start a S/390 channel program. When the interrupt arrives, the
175 * IRQ handler is called, either immediately, delayed (dev-end missing, 176 * IRQ handler is called, either immediately, delayed (dev-end missing,
176 * or sense required) or never (no IRQ handler registered). 177 * or sense required) or never (no IRQ handler registered).
178 * This function notifies the device driver if the channel program has not
179 * completed during the time specified by @expires. If a timeout occurs, the
180 * channel program is terminated via xsch, hsch or csch, and the device's
181 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
177 * Returns: 182 * Returns:
178 * %0, if the operation was successful; 183 * %0, if the operation was successful;
179 * -%EBUSY, if the device is busy, or status pending; 184 * -%EBUSY, if the device is busy, or status pending;
@@ -182,9 +187,9 @@ int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
182 * Context: 187 * Context:
183 * Interrupts disabled, ccw device lock held 188 * Interrupts disabled, ccw device lock held
184 */ 189 */
185int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa, 190int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,
186 unsigned long intparm, __u8 lpm, __u8 key, 191 unsigned long intparm, __u8 lpm, __u8 key,
187 unsigned long flags) 192 unsigned long flags, int expires)
188{ 193{
189 struct subchannel *sch; 194 struct subchannel *sch;
190 int ret; 195 int ret;
@@ -224,6 +229,8 @@ int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
224 switch (ret) { 229 switch (ret) {
225 case 0: 230 case 0:
226 cdev->private->intparm = intparm; 231 cdev->private->intparm = intparm;
232 if (expires)
233 ccw_device_set_timeout(cdev, expires);
227 break; 234 break;
228 case -EACCES: 235 case -EACCES:
229 case -ENODEV: 236 case -ENODEV:
@@ -234,7 +241,7 @@ int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
234} 241}
235 242
236/** 243/**
237 * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key 244 * ccw_device_start_key() - start a s390 channel program with key
238 * @cdev: target ccw device 245 * @cdev: target ccw device
239 * @cpa: logical start address of channel program 246 * @cpa: logical start address of channel program
240 * @intparm: user specific interruption parameter; will be presented back to 247 * @intparm: user specific interruption parameter; will be presented back to
@@ -245,15 +252,10 @@ int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
245 * @key: storage key to be used for the I/O 252 * @key: storage key to be used for the I/O
246 * @flags: additional flags; defines the action to be performed for I/O 253 * @flags: additional flags; defines the action to be performed for I/O
247 * processing. 254 * processing.
248 * @expires: timeout value in jiffies
249 * 255 *
250 * Start a S/390 channel program. When the interrupt arrives, the 256 * Start a S/390 channel program. When the interrupt arrives, the
251 * IRQ handler is called, either immediately, delayed (dev-end missing, 257 * IRQ handler is called, either immediately, delayed (dev-end missing,
252 * or sense required) or never (no IRQ handler registered). 258 * or sense required) or never (no IRQ handler registered).
253 * This function notifies the device driver if the channel program has not
254 * completed during the time specified by @expires. If a timeout occurs, the
255 * channel program is terminated via xsch, hsch or csch, and the device's
256 * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT).
257 * Returns: 259 * Returns:
258 * %0, if the operation was successful; 260 * %0, if the operation was successful;
259 * -%EBUSY, if the device is busy, or status pending; 261 * -%EBUSY, if the device is busy, or status pending;
@@ -262,19 +264,12 @@ int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
262 * Context: 264 * Context:
263 * Interrupts disabled, ccw device lock held 265 * Interrupts disabled, ccw device lock held
264 */ 266 */
265int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa, 267int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
266 unsigned long intparm, __u8 lpm, __u8 key, 268 unsigned long intparm, __u8 lpm, __u8 key,
267 unsigned long flags, int expires) 269 unsigned long flags)
268{ 270{
269 int ret; 271 return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm, key,
270 272 flags, 0);
271 if (!cdev)
272 return -ENODEV;
273 ccw_device_set_timeout(cdev, expires);
274 ret = ccw_device_start_key(cdev, cpa, intparm, lpm, key, flags);
275 if (ret != 0)
276 ccw_device_set_timeout(cdev, 0);
277 return ret;
278} 273}
279 274
280/** 275/**
@@ -489,18 +484,20 @@ void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
489EXPORT_SYMBOL(ccw_device_get_id); 484EXPORT_SYMBOL(ccw_device_get_id);
490 485
491/** 486/**
492 * ccw_device_tm_start_key() - perform start function 487 * ccw_device_tm_start_timeout_key() - perform start function
493 * @cdev: ccw device on which to perform the start function 488 * @cdev: ccw device on which to perform the start function
494 * @tcw: transport-command word to be started 489 * @tcw: transport-command word to be started
495 * @intparm: user defined parameter to be passed to the interrupt handler 490 * @intparm: user defined parameter to be passed to the interrupt handler
496 * @lpm: mask of paths to use 491 * @lpm: mask of paths to use
497 * @key: storage key to use for storage access 492 * @key: storage key to use for storage access
493 * @expires: time span in jiffies after which to abort request
498 * 494 *
499 * Start the tcw on the given ccw device. Return zero on success, non-zero 495 * Start the tcw on the given ccw device. Return zero on success, non-zero
500 * otherwise. 496 * otherwise.
501 */ 497 */
502int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw, 498int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
503 unsigned long intparm, u8 lpm, u8 key) 499 unsigned long intparm, u8 lpm, u8 key,
500 int expires)
504{ 501{
505 struct subchannel *sch; 502 struct subchannel *sch;
506 int rc; 503 int rc;
@@ -527,37 +524,32 @@ int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
527 return -EACCES; 524 return -EACCES;
528 } 525 }
529 rc = cio_tm_start_key(sch, tcw, lpm, key); 526 rc = cio_tm_start_key(sch, tcw, lpm, key);
530 if (rc == 0) 527 if (rc == 0) {
531 cdev->private->intparm = intparm; 528 cdev->private->intparm = intparm;
529 if (expires)
530 ccw_device_set_timeout(cdev, expires);
531 }
532 return rc; 532 return rc;
533} 533}
534EXPORT_SYMBOL(ccw_device_tm_start_key); 534EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
535 535
536/** 536/**
537 * ccw_device_tm_start_timeout_key() - perform start function 537 * ccw_device_tm_start_key() - perform start function
538 * @cdev: ccw device on which to perform the start function 538 * @cdev: ccw device on which to perform the start function
539 * @tcw: transport-command word to be started 539 * @tcw: transport-command word to be started
540 * @intparm: user defined parameter to be passed to the interrupt handler 540 * @intparm: user defined parameter to be passed to the interrupt handler
541 * @lpm: mask of paths to use 541 * @lpm: mask of paths to use
542 * @key: storage key to use for storage access 542 * @key: storage key to use for storage access
543 * @expires: time span in jiffies after which to abort request
544 * 543 *
545 * Start the tcw on the given ccw device. Return zero on success, non-zero 544 * Start the tcw on the given ccw device. Return zero on success, non-zero
546 * otherwise. 545 * otherwise.
547 */ 546 */
548int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw, 547int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
549 unsigned long intparm, u8 lpm, u8 key, 548 unsigned long intparm, u8 lpm, u8 key)
550 int expires)
551{ 549{
552 int ret; 550 return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm, key, 0);
553
554 ccw_device_set_timeout(cdev, expires);
555 ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
556 if (ret != 0)
557 ccw_device_set_timeout(cdev, 0);
558 return ret;
559} 551}
560EXPORT_SYMBOL(ccw_device_tm_start_timeout_key); 552EXPORT_SYMBOL(ccw_device_tm_start_key);
561 553
562/** 554/**
563 * ccw_device_tm_start() - perform start function 555 * ccw_device_tm_start() - perform start function
diff --git a/drivers/s390/cio/io_sch.h b/drivers/s390/cio/io_sch.h
index af571d8d6925..90e4e3a7841b 100644
--- a/drivers/s390/cio/io_sch.h
+++ b/drivers/s390/cio/io_sch.h
@@ -157,6 +157,7 @@ struct ccw_device_private {
157 unsigned long intparm; /* user interruption parameter */ 157 unsigned long intparm; /* user interruption parameter */
158 struct qdio_irq *qdio_data; 158 struct qdio_irq *qdio_data;
159 struct irb irb; /* device status */ 159 struct irb irb; /* device status */
160 int async_kill_io_rc;
160 struct senseid senseid; /* SenseID info */ 161 struct senseid senseid; /* SenseID info */
161 struct pgid pgid[8]; /* path group IDs per chpid*/ 162 struct pgid pgid[8]; /* path group IDs per chpid*/
162 struct ccw1 iccws[2]; /* ccws for SNID/SID/SPGID commands */ 163 struct ccw1 iccws[2]; /* ccws for SNID/SID/SPGID commands */
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index ca72f3311004..3653bea38470 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -527,8 +527,7 @@ static inline int qeth_is_cq(struct qeth_card *card, unsigned int queue)
527 queue == card->qdio.no_in_queues - 1; 527 queue == card->qdio.no_in_queues - 1;
528} 528}
529 529
530 530static int __qeth_issue_next_read(struct qeth_card *card)
531static int qeth_issue_next_read(struct qeth_card *card)
532{ 531{
533 int rc; 532 int rc;
534 struct qeth_cmd_buffer *iob; 533 struct qeth_cmd_buffer *iob;
@@ -559,6 +558,17 @@ static int qeth_issue_next_read(struct qeth_card *card)
559 return rc; 558 return rc;
560} 559}
561 560
561static int qeth_issue_next_read(struct qeth_card *card)
562{
563 int ret;
564
565 spin_lock_irq(get_ccwdev_lock(CARD_RDEV(card)));
566 ret = __qeth_issue_next_read(card);
567 spin_unlock_irq(get_ccwdev_lock(CARD_RDEV(card)));
568
569 return ret;
570}
571
562static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card) 572static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card)
563{ 573{
564 struct qeth_reply *reply; 574 struct qeth_reply *reply;
@@ -960,7 +970,7 @@ void qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
960 spin_lock_irqsave(&card->thread_mask_lock, flags); 970 spin_lock_irqsave(&card->thread_mask_lock, flags);
961 card->thread_running_mask &= ~thread; 971 card->thread_running_mask &= ~thread;
962 spin_unlock_irqrestore(&card->thread_mask_lock, flags); 972 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
963 wake_up(&card->wait_q); 973 wake_up_all(&card->wait_q);
964} 974}
965EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit); 975EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit);
966 976
@@ -1164,6 +1174,7 @@ static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
1164 } 1174 }
1165 rc = qeth_get_problem(cdev, irb); 1175 rc = qeth_get_problem(cdev, irb);
1166 if (rc) { 1176 if (rc) {
1177 card->read_or_write_problem = 1;
1167 qeth_clear_ipacmd_list(card); 1178 qeth_clear_ipacmd_list(card);
1168 qeth_schedule_recovery(card); 1179 qeth_schedule_recovery(card);
1169 goto out; 1180 goto out;
@@ -1182,7 +1193,7 @@ static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
1182 return; 1193 return;
1183 if (channel == &card->read && 1194 if (channel == &card->read &&
1184 channel->state == CH_STATE_UP) 1195 channel->state == CH_STATE_UP)
1185 qeth_issue_next_read(card); 1196 __qeth_issue_next_read(card);
1186 1197
1187 iob = channel->iob; 1198 iob = channel->iob;
1188 index = channel->buf_no; 1199 index = channel->buf_no;
@@ -2134,24 +2145,25 @@ int qeth_send_control_data(struct qeth_card *card, int len,
2134 } 2145 }
2135 reply->callback = reply_cb; 2146 reply->callback = reply_cb;
2136 reply->param = reply_param; 2147 reply->param = reply_param;
2137 if (card->state == CARD_STATE_DOWN) 2148
2138 reply->seqno = QETH_IDX_COMMAND_SEQNO;
2139 else
2140 reply->seqno = card->seqno.ipa++;
2141 init_waitqueue_head(&reply->wait_q); 2149 init_waitqueue_head(&reply->wait_q);
2142 spin_lock_irqsave(&card->lock, flags);
2143 list_add_tail(&reply->list, &card->cmd_waiter_list);
2144 spin_unlock_irqrestore(&card->lock, flags);
2145 2150
2146 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ; 2151 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
2147 qeth_prepare_control_data(card, len, iob);
2148 2152
2149 if (IS_IPA(iob->data)) { 2153 if (IS_IPA(iob->data)) {
2150 cmd = __ipa_cmd(iob); 2154 cmd = __ipa_cmd(iob);
2155 cmd->hdr.seqno = card->seqno.ipa++;
2156 reply->seqno = cmd->hdr.seqno;
2151 event_timeout = QETH_IPA_TIMEOUT; 2157 event_timeout = QETH_IPA_TIMEOUT;
2152 } else { 2158 } else {
2159 reply->seqno = QETH_IDX_COMMAND_SEQNO;
2153 event_timeout = QETH_TIMEOUT; 2160 event_timeout = QETH_TIMEOUT;
2154 } 2161 }
2162 qeth_prepare_control_data(card, len, iob);
2163
2164 spin_lock_irqsave(&card->lock, flags);
2165 list_add_tail(&reply->list, &card->cmd_waiter_list);
2166 spin_unlock_irqrestore(&card->lock, flags);
2155 2167
2156 timeout = jiffies + event_timeout; 2168 timeout = jiffies + event_timeout;
2157 2169
@@ -2933,7 +2945,7 @@ static void qeth_fill_ipacmd_header(struct qeth_card *card,
2933 memset(cmd, 0, sizeof(struct qeth_ipa_cmd)); 2945 memset(cmd, 0, sizeof(struct qeth_ipa_cmd));
2934 cmd->hdr.command = command; 2946 cmd->hdr.command = command;
2935 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST; 2947 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
2936 cmd->hdr.seqno = card->seqno.ipa; 2948 /* cmd->hdr.seqno is set by qeth_send_control_data() */
2937 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type); 2949 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
2938 cmd->hdr.rel_adapter_no = (__u8) card->info.portno; 2950 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
2939 if (card->options.layer2) 2951 if (card->options.layer2)
@@ -3898,10 +3910,12 @@ EXPORT_SYMBOL_GPL(qeth_get_elements_for_frags);
3898int qeth_get_elements_no(struct qeth_card *card, 3910int qeth_get_elements_no(struct qeth_card *card,
3899 struct sk_buff *skb, int extra_elems, int data_offset) 3911 struct sk_buff *skb, int extra_elems, int data_offset)
3900{ 3912{
3901 int elements = qeth_get_elements_for_range( 3913 addr_t end = (addr_t)skb->data + skb_headlen(skb);
3902 (addr_t)skb->data + data_offset, 3914 int elements = qeth_get_elements_for_frags(skb);
3903 (addr_t)skb->data + skb_headlen(skb)) + 3915 addr_t start = (addr_t)skb->data + data_offset;
3904 qeth_get_elements_for_frags(skb); 3916
3917 if (start != end)
3918 elements += qeth_get_elements_for_range(start, end);
3905 3919
3906 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) { 3920 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
3907 QETH_DBF_MESSAGE(2, "Invalid size of IP packet " 3921 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
@@ -5084,8 +5098,6 @@ static void qeth_core_free_card(struct qeth_card *card)
5084 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); 5098 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
5085 qeth_clean_channel(&card->read); 5099 qeth_clean_channel(&card->read);
5086 qeth_clean_channel(&card->write); 5100 qeth_clean_channel(&card->write);
5087 if (card->dev)
5088 free_netdev(card->dev);
5089 qeth_free_qdio_buffers(card); 5101 qeth_free_qdio_buffers(card);
5090 unregister_service_level(&card->qeth_service_level); 5102 unregister_service_level(&card->qeth_service_level);
5091 kfree(card); 5103 kfree(card);
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 7f236440483f..5ef4c978ad19 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -915,8 +915,8 @@ static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
915 qeth_l2_set_offline(cgdev); 915 qeth_l2_set_offline(cgdev);
916 916
917 if (card->dev) { 917 if (card->dev) {
918 netif_napi_del(&card->napi);
919 unregister_netdev(card->dev); 918 unregister_netdev(card->dev);
919 free_netdev(card->dev);
920 card->dev = NULL; 920 card->dev = NULL;
921 } 921 }
922 return; 922 return;
diff --git a/drivers/s390/net/qeth_l3.h b/drivers/s390/net/qeth_l3.h
index bdd45f4dcace..498fe9af2cdb 100644
--- a/drivers/s390/net/qeth_l3.h
+++ b/drivers/s390/net/qeth_l3.h
@@ -40,8 +40,40 @@ struct qeth_ipaddr {
40 unsigned int pfxlen; 40 unsigned int pfxlen;
41 } a6; 41 } a6;
42 } u; 42 } u;
43
44}; 43};
44
45static inline bool qeth_l3_addr_match_ip(struct qeth_ipaddr *a1,
46 struct qeth_ipaddr *a2)
47{
48 if (a1->proto != a2->proto)
49 return false;
50 if (a1->proto == QETH_PROT_IPV6)
51 return ipv6_addr_equal(&a1->u.a6.addr, &a2->u.a6.addr);
52 return a1->u.a4.addr == a2->u.a4.addr;
53}
54
55static inline bool qeth_l3_addr_match_all(struct qeth_ipaddr *a1,
56 struct qeth_ipaddr *a2)
57{
58 /* Assumes that the pair was obtained via qeth_l3_addr_find_by_ip(),
59 * so 'proto' and 'addr' match for sure.
60 *
61 * For ucast:
62 * - 'mac' is always 0.
63 * - 'mask'/'pfxlen' for RXIP/VIPA is always 0. For NORMAL, matching
64 * values are required to avoid mixups in takeover eligibility.
65 *
66 * For mcast,
67 * - 'mac' is mapped from the IP, and thus always matches.
68 * - 'mask'/'pfxlen' is always 0.
69 */
70 if (a1->type != a2->type)
71 return false;
72 if (a1->proto == QETH_PROT_IPV6)
73 return a1->u.a6.pfxlen == a2->u.a6.pfxlen;
74 return a1->u.a4.mask == a2->u.a4.mask;
75}
76
45static inline u64 qeth_l3_ipaddr_hash(struct qeth_ipaddr *addr) 77static inline u64 qeth_l3_ipaddr_hash(struct qeth_ipaddr *addr)
46{ 78{
47 u64 ret = 0; 79 u64 ret = 0;
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index b0c888e86cd4..b6b12220da71 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -67,6 +67,24 @@ void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
67 qeth_l3_ipaddr6_to_string(addr, buf); 67 qeth_l3_ipaddr6_to_string(addr, buf);
68} 68}
69 69
70static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,
71 struct qeth_ipaddr *query)
72{
73 u64 key = qeth_l3_ipaddr_hash(query);
74 struct qeth_ipaddr *addr;
75
76 if (query->is_multicast) {
77 hash_for_each_possible(card->ip_mc_htable, addr, hnode, key)
78 if (qeth_l3_addr_match_ip(addr, query))
79 return addr;
80 } else {
81 hash_for_each_possible(card->ip_htable, addr, hnode, key)
82 if (qeth_l3_addr_match_ip(addr, query))
83 return addr;
84 }
85 return NULL;
86}
87
70static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len) 88static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
71{ 89{
72 int i, j; 90 int i, j;
@@ -120,34 +138,6 @@ static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
120 return rc; 138 return rc;
121} 139}
122 140
123inline int
124qeth_l3_ipaddrs_is_equal(struct qeth_ipaddr *addr1, struct qeth_ipaddr *addr2)
125{
126 return addr1->proto == addr2->proto &&
127 !memcmp(&addr1->u, &addr2->u, sizeof(addr1->u)) &&
128 ether_addr_equal_64bits(addr1->mac, addr2->mac);
129}
130
131static struct qeth_ipaddr *
132qeth_l3_ip_from_hash(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
133{
134 struct qeth_ipaddr *addr;
135
136 if (tmp_addr->is_multicast) {
137 hash_for_each_possible(card->ip_mc_htable, addr,
138 hnode, qeth_l3_ipaddr_hash(tmp_addr))
139 if (qeth_l3_ipaddrs_is_equal(tmp_addr, addr))
140 return addr;
141 } else {
142 hash_for_each_possible(card->ip_htable, addr,
143 hnode, qeth_l3_ipaddr_hash(tmp_addr))
144 if (qeth_l3_ipaddrs_is_equal(tmp_addr, addr))
145 return addr;
146 }
147
148 return NULL;
149}
150
151int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr) 141int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
152{ 142{
153 int rc = 0; 143 int rc = 0;
@@ -162,23 +152,18 @@ int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
162 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8); 152 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
163 } 153 }
164 154
165 addr = qeth_l3_ip_from_hash(card, tmp_addr); 155 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
166 if (!addr) 156 if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr))
167 return -ENOENT; 157 return -ENOENT;
168 158
169 addr->ref_counter--; 159 addr->ref_counter--;
170 if (addr->ref_counter > 0 && (addr->type == QETH_IP_TYPE_NORMAL || 160 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
171 addr->type == QETH_IP_TYPE_RXIP))
172 return rc; 161 return rc;
173 if (addr->in_progress) 162 if (addr->in_progress)
174 return -EINPROGRESS; 163 return -EINPROGRESS;
175 164
176 if (!qeth_card_hw_is_reachable(card)) { 165 if (qeth_card_hw_is_reachable(card))
177 addr->disp_flag = QETH_DISP_ADDR_DELETE; 166 rc = qeth_l3_deregister_addr_entry(card, addr);
178 return 0;
179 }
180
181 rc = qeth_l3_deregister_addr_entry(card, addr);
182 167
183 hash_del(&addr->hnode); 168 hash_del(&addr->hnode);
184 kfree(addr); 169 kfree(addr);
@@ -190,6 +175,7 @@ int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
190{ 175{
191 int rc = 0; 176 int rc = 0;
192 struct qeth_ipaddr *addr; 177 struct qeth_ipaddr *addr;
178 char buf[40];
193 179
194 QETH_CARD_TEXT(card, 4, "addip"); 180 QETH_CARD_TEXT(card, 4, "addip");
195 181
@@ -200,8 +186,20 @@ int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
200 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8); 186 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
201 } 187 }
202 188
203 addr = qeth_l3_ip_from_hash(card, tmp_addr); 189 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
204 if (!addr) { 190 if (addr) {
191 if (tmp_addr->type != QETH_IP_TYPE_NORMAL)
192 return -EADDRINUSE;
193 if (qeth_l3_addr_match_all(addr, tmp_addr)) {
194 addr->ref_counter++;
195 return 0;
196 }
197 qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u,
198 buf);
199 dev_warn(&card->gdev->dev,
200 "Registering IP address %s failed\n", buf);
201 return -EADDRINUSE;
202 } else {
205 addr = qeth_l3_get_addr_buffer(tmp_addr->proto); 203 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
206 if (!addr) 204 if (!addr)
207 return -ENOMEM; 205 return -ENOMEM;
@@ -241,19 +239,15 @@ int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
241 (rc == IPA_RC_LAN_OFFLINE)) { 239 (rc == IPA_RC_LAN_OFFLINE)) {
242 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 240 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
243 if (addr->ref_counter < 1) { 241 if (addr->ref_counter < 1) {
244 qeth_l3_delete_ip(card, addr); 242 qeth_l3_deregister_addr_entry(card, addr);
243 hash_del(&addr->hnode);
245 kfree(addr); 244 kfree(addr);
246 } 245 }
247 } else { 246 } else {
248 hash_del(&addr->hnode); 247 hash_del(&addr->hnode);
249 kfree(addr); 248 kfree(addr);
250 } 249 }
251 } else {
252 if (addr->type == QETH_IP_TYPE_NORMAL ||
253 addr->type == QETH_IP_TYPE_RXIP)
254 addr->ref_counter++;
255 } 250 }
256
257 return rc; 251 return rc;
258} 252}
259 253
@@ -321,11 +315,7 @@ static void qeth_l3_recover_ip(struct qeth_card *card)
321 spin_lock_bh(&card->ip_lock); 315 spin_lock_bh(&card->ip_lock);
322 316
323 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) { 317 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
324 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) { 318 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
325 qeth_l3_deregister_addr_entry(card, addr);
326 hash_del(&addr->hnode);
327 kfree(addr);
328 } else if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
329 if (addr->proto == QETH_PROT_IPV4) { 319 if (addr->proto == QETH_PROT_IPV4) {
330 addr->in_progress = 1; 320 addr->in_progress = 1;
331 spin_unlock_bh(&card->ip_lock); 321 spin_unlock_bh(&card->ip_lock);
@@ -643,12 +633,7 @@ int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
643 return -ENOMEM; 633 return -ENOMEM;
644 634
645 spin_lock_bh(&card->ip_lock); 635 spin_lock_bh(&card->ip_lock);
646 636 rc = qeth_l3_add_ip(card, ipaddr);
647 if (qeth_l3_ip_from_hash(card, ipaddr))
648 rc = -EEXIST;
649 else
650 rc = qeth_l3_add_ip(card, ipaddr);
651
652 spin_unlock_bh(&card->ip_lock); 637 spin_unlock_bh(&card->ip_lock);
653 638
654 kfree(ipaddr); 639 kfree(ipaddr);
@@ -713,12 +698,7 @@ int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
713 return -ENOMEM; 698 return -ENOMEM;
714 699
715 spin_lock_bh(&card->ip_lock); 700 spin_lock_bh(&card->ip_lock);
716 701 rc = qeth_l3_add_ip(card, ipaddr);
717 if (qeth_l3_ip_from_hash(card, ipaddr))
718 rc = -EEXIST;
719 else
720 rc = qeth_l3_add_ip(card, ipaddr);
721
722 spin_unlock_bh(&card->ip_lock); 702 spin_unlock_bh(&card->ip_lock);
723 703
724 kfree(ipaddr); 704 kfree(ipaddr);
@@ -1239,8 +1219,9 @@ qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1239 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr); 1219 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr);
1240 tmp->is_multicast = 1; 1220 tmp->is_multicast = 1;
1241 1221
1242 ipm = qeth_l3_ip_from_hash(card, tmp); 1222 ipm = qeth_l3_find_addr_by_ip(card, tmp);
1243 if (ipm) { 1223 if (ipm) {
1224 /* for mcast, by-IP match means full match */
1244 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 1225 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1245 } else { 1226 } else {
1246 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4); 1227 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
@@ -1319,8 +1300,9 @@ static void qeth_l3_add_mc6_to_hash(struct qeth_card *card,
1319 sizeof(struct in6_addr)); 1300 sizeof(struct in6_addr));
1320 tmp->is_multicast = 1; 1301 tmp->is_multicast = 1;
1321 1302
1322 ipm = qeth_l3_ip_from_hash(card, tmp); 1303 ipm = qeth_l3_find_addr_by_ip(card, tmp);
1323 if (ipm) { 1304 if (ipm) {
1305 /* for mcast, by-IP match means full match */
1324 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 1306 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1325 continue; 1307 continue;
1326 } 1308 }
@@ -2450,11 +2432,12 @@ static void qeth_tso_fill_header(struct qeth_card *card,
2450static int qeth_l3_get_elements_no_tso(struct qeth_card *card, 2432static int qeth_l3_get_elements_no_tso(struct qeth_card *card,
2451 struct sk_buff *skb, int extra_elems) 2433 struct sk_buff *skb, int extra_elems)
2452{ 2434{
2453 addr_t tcpdptr = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb); 2435 addr_t start = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb);
2454 int elements = qeth_get_elements_for_range( 2436 addr_t end = (addr_t)skb->data + skb_headlen(skb);
2455 tcpdptr, 2437 int elements = qeth_get_elements_for_frags(skb);
2456 (addr_t)skb->data + skb_headlen(skb)) + 2438
2457 qeth_get_elements_for_frags(skb); 2439 if (start != end)
2440 elements += qeth_get_elements_for_range(start, end);
2458 2441
2459 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) { 2442 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
2460 QETH_DBF_MESSAGE(2, 2443 QETH_DBF_MESSAGE(2,
@@ -2882,8 +2865,8 @@ static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
2882 qeth_l3_set_offline(cgdev); 2865 qeth_l3_set_offline(cgdev);
2883 2866
2884 if (card->dev) { 2867 if (card->dev) {
2885 netif_napi_del(&card->napi);
2886 unregister_netdev(card->dev); 2868 unregister_netdev(card->dev);
2869 free_netdev(card->dev);
2887 card->dev = NULL; 2870 card->dev = NULL;
2888 } 2871 }
2889 2872
diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c
index ba2e0856d22c..8f5c1d7f751a 100644
--- a/drivers/s390/virtio/virtio_ccw.c
+++ b/drivers/s390/virtio/virtio_ccw.c
@@ -1297,6 +1297,9 @@ static int virtio_ccw_cio_notify(struct ccw_device *cdev, int event)
1297 vcdev->device_lost = true; 1297 vcdev->device_lost = true;
1298 rc = NOTIFY_DONE; 1298 rc = NOTIFY_DONE;
1299 break; 1299 break;
1300 case CIO_OPER:
1301 rc = NOTIFY_OK;
1302 break;
1300 default: 1303 default:
1301 rc = NOTIFY_DONE; 1304 rc = NOTIFY_DONE;
1302 break; 1305 break;
@@ -1309,6 +1312,27 @@ static struct ccw_device_id virtio_ids[] = {
1309 {}, 1312 {},
1310}; 1313};
1311 1314
1315#ifdef CONFIG_PM_SLEEP
1316static int virtio_ccw_freeze(struct ccw_device *cdev)
1317{
1318 struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
1319
1320 return virtio_device_freeze(&vcdev->vdev);
1321}
1322
1323static int virtio_ccw_restore(struct ccw_device *cdev)
1324{
1325 struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
1326 int ret;
1327
1328 ret = virtio_ccw_set_transport_rev(vcdev);
1329 if (ret)
1330 return ret;
1331
1332 return virtio_device_restore(&vcdev->vdev);
1333}
1334#endif
1335
1312static struct ccw_driver virtio_ccw_driver = { 1336static struct ccw_driver virtio_ccw_driver = {
1313 .driver = { 1337 .driver = {
1314 .owner = THIS_MODULE, 1338 .owner = THIS_MODULE,
@@ -1321,6 +1345,11 @@ static struct ccw_driver virtio_ccw_driver = {
1321 .set_online = virtio_ccw_online, 1345 .set_online = virtio_ccw_online,
1322 .notify = virtio_ccw_cio_notify, 1346 .notify = virtio_ccw_cio_notify,
1323 .int_class = IRQIO_VIR, 1347 .int_class = IRQIO_VIR,
1348#ifdef CONFIG_PM_SLEEP
1349 .freeze = virtio_ccw_freeze,
1350 .thaw = virtio_ccw_restore,
1351 .restore = virtio_ccw_restore,
1352#endif
1324}; 1353};
1325 1354
1326static int __init pure_hex(char **cp, unsigned int *val, int min_digit, 1355static int __init pure_hex(char **cp, unsigned int *val, int min_digit,
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index fcfd28d2884c..de1b3fce936d 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -185,7 +185,6 @@ ncr53c8xx-flags-$(CONFIG_SCSI_ZALON) \
185CFLAGS_ncr53c8xx.o := $(ncr53c8xx-flags-y) $(ncr53c8xx-flags-m) 185CFLAGS_ncr53c8xx.o := $(ncr53c8xx-flags-y) $(ncr53c8xx-flags-m)
186zalon7xx-objs := zalon.o ncr53c8xx.o 186zalon7xx-objs := zalon.o ncr53c8xx.o
187NCR_Q720_mod-objs := NCR_Q720.o ncr53c8xx.o 187NCR_Q720_mod-objs := NCR_Q720.o ncr53c8xx.o
188oktagon_esp_mod-objs := oktagon_esp.o oktagon_io.o
189 188
190# Files generated that shall be removed upon make clean 189# Files generated that shall be removed upon make clean
191clean-files := 53c700_d.h 53c700_u.h 190clean-files := 53c700_d.h 53c700_u.h
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index b3b931ab77eb..2664ea0df35f 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1693,8 +1693,10 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1693 * Map in the registers from the adapter. 1693 * Map in the registers from the adapter.
1694 */ 1694 */
1695 aac->base_size = AAC_MIN_FOOTPRINT_SIZE; 1695 aac->base_size = AAC_MIN_FOOTPRINT_SIZE;
1696 if ((*aac_drivers[index].init)(aac)) 1696 if ((*aac_drivers[index].init)(aac)) {
1697 error = -ENODEV;
1697 goto out_unmap; 1698 goto out_unmap;
1699 }
1698 1700
1699 if (aac->sync_mode) { 1701 if (aac->sync_mode) {
1700 if (aac_sync_mode) 1702 if (aac_sync_mode)
diff --git a/drivers/scsi/aic7xxx/aiclib.c b/drivers/scsi/aic7xxx/aiclib.c
deleted file mode 100644
index 828ae3d9a510..000000000000
--- a/drivers/scsi/aic7xxx/aiclib.c
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * Implementation of Utility functions for all SCSI device types.
3 *
4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998 Kenneth D. Merry.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: src/sys/cam/scsi/scsi_all.c,v 1.38 2002/09/23 04:56:35 mjacob Exp $
30 * $Id$
31 */
32
33#include "aiclib.h"
34
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 8e2f767147cb..5a645b8b9af1 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -1889,6 +1889,7 @@ void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd *io_req,
1889 /* we will not receive ABTS response for this IO */ 1889 /* we will not receive ABTS response for this IO */
1890 BNX2FC_IO_DBG(io_req, "Timer context finished processing " 1890 BNX2FC_IO_DBG(io_req, "Timer context finished processing "
1891 "this scsi cmd\n"); 1891 "this scsi cmd\n");
1892 return;
1892 } 1893 }
1893 1894
1894 /* Cancel the timeout_work, as we received IO completion */ 1895 /* Cancel the timeout_work, as we received IO completion */
diff --git a/drivers/scsi/csiostor/csio_lnode.c b/drivers/scsi/csiostor/csio_lnode.c
index be5ee2d37815..7dbbbb81a1e7 100644
--- a/drivers/scsi/csiostor/csio_lnode.c
+++ b/drivers/scsi/csiostor/csio_lnode.c
@@ -114,7 +114,7 @@ static enum csio_ln_ev fwevt_to_lnevt[] = {
114static struct csio_lnode * 114static struct csio_lnode *
115csio_ln_lookup_by_portid(struct csio_hw *hw, uint8_t portid) 115csio_ln_lookup_by_portid(struct csio_hw *hw, uint8_t portid)
116{ 116{
117 struct csio_lnode *ln = hw->rln; 117 struct csio_lnode *ln;
118 struct list_head *tmp; 118 struct list_head *tmp;
119 119
120 /* Match siblings lnode with portid */ 120 /* Match siblings lnode with portid */
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 022e421c2185..4b44325d1a82 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -876,6 +876,11 @@ static void alua_rtpg_work(struct work_struct *work)
876 876
877/** 877/**
878 * alua_rtpg_queue() - cause RTPG to be submitted asynchronously 878 * alua_rtpg_queue() - cause RTPG to be submitted asynchronously
879 * @pg: ALUA port group associated with @sdev.
880 * @sdev: SCSI device for which to submit an RTPG.
881 * @qdata: Information about the callback to invoke after the RTPG.
882 * @force: Whether or not to submit an RTPG if a work item that will submit an
883 * RTPG already has been scheduled.
879 * 884 *
880 * Returns true if and only if alua_rtpg_work() will be called asynchronously. 885 * Returns true if and only if alua_rtpg_work() will be called asynchronously.
881 * That function is responsible for calling @qdata->fn(). 886 * That function is responsible for calling @qdata->fn().
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 57bf43e34863..dd9464920456 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -328,8 +328,6 @@ static void scsi_host_dev_release(struct device *dev)
328 if (shost->work_q) 328 if (shost->work_q)
329 destroy_workqueue(shost->work_q); 329 destroy_workqueue(shost->work_q);
330 330
331 destroy_rcu_head(&shost->rcu);
332
333 if (shost->shost_state == SHOST_CREATED) { 331 if (shost->shost_state == SHOST_CREATED) {
334 /* 332 /*
335 * Free the shost_dev device name here if scsi_host_alloc() 333 * Free the shost_dev device name here if scsi_host_alloc()
@@ -404,7 +402,6 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
404 INIT_LIST_HEAD(&shost->starved_list); 402 INIT_LIST_HEAD(&shost->starved_list);
405 init_waitqueue_head(&shost->host_wait); 403 init_waitqueue_head(&shost->host_wait);
406 mutex_init(&shost->scan_mutex); 404 mutex_init(&shost->scan_mutex);
407 init_rcu_head(&shost->rcu);
408 405
409 index = ida_simple_get(&host_index_ida, 0, 0, GFP_KERNEL); 406 index = ida_simple_get(&host_index_ida, 0, 0, GFP_KERNEL);
410 if (index < 0) 407 if (index < 0)
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.h b/drivers/scsi/ibmvscsi/ibmvfc.h
index 9a0696f68f37..b81a53c4a9a8 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.h
+++ b/drivers/scsi/ibmvscsi/ibmvfc.h
@@ -367,7 +367,7 @@ enum ibmvfc_fcp_rsp_info_codes {
367}; 367};
368 368
369struct ibmvfc_fcp_rsp_info { 369struct ibmvfc_fcp_rsp_info {
370 __be16 reserved; 370 u8 reserved[3];
371 u8 rsp_code; 371 u8 rsp_code;
372 u8 reserved2[4]; 372 u8 reserved2[4];
373}__attribute__((packed, aligned (2))); 373}__attribute__((packed, aligned (2)));
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 6de9681ace82..ceab5e5c41c2 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -223,6 +223,7 @@ out_done:
223static void sas_eh_finish_cmd(struct scsi_cmnd *cmd) 223static void sas_eh_finish_cmd(struct scsi_cmnd *cmd)
224{ 224{
225 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(cmd->device->host); 225 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(cmd->device->host);
226 struct domain_device *dev = cmd_to_domain_dev(cmd);
226 struct sas_task *task = TO_SAS_TASK(cmd); 227 struct sas_task *task = TO_SAS_TASK(cmd);
227 228
228 /* At this point, we only get called following an actual abort 229 /* At this point, we only get called following an actual abort
@@ -231,6 +232,14 @@ static void sas_eh_finish_cmd(struct scsi_cmnd *cmd)
231 */ 232 */
232 sas_end_task(cmd, task); 233 sas_end_task(cmd, task);
233 234
235 if (dev_is_sata(dev)) {
236 /* defer commands to libata so that libata EH can
237 * handle ata qcs correctly
238 */
239 list_move_tail(&cmd->eh_entry, &sas_ha->eh_ata_q);
240 return;
241 }
242
234 /* now finish the command and move it on to the error 243 /* now finish the command and move it on to the error
235 * handler done list, this also takes it off the 244 * handler done list, this also takes it off the
236 * error handler pending list. 245 * error handler pending list.
@@ -238,22 +247,6 @@ static void sas_eh_finish_cmd(struct scsi_cmnd *cmd)
238 scsi_eh_finish_cmd(cmd, &sas_ha->eh_done_q); 247 scsi_eh_finish_cmd(cmd, &sas_ha->eh_done_q);
239} 248}
240 249
241static void sas_eh_defer_cmd(struct scsi_cmnd *cmd)
242{
243 struct domain_device *dev = cmd_to_domain_dev(cmd);
244 struct sas_ha_struct *ha = dev->port->ha;
245 struct sas_task *task = TO_SAS_TASK(cmd);
246
247 if (!dev_is_sata(dev)) {
248 sas_eh_finish_cmd(cmd);
249 return;
250 }
251
252 /* report the timeout to libata */
253 sas_end_task(cmd, task);
254 list_move_tail(&cmd->eh_entry, &ha->eh_ata_q);
255}
256
257static void sas_scsi_clear_queue_lu(struct list_head *error_q, struct scsi_cmnd *my_cmd) 250static void sas_scsi_clear_queue_lu(struct list_head *error_q, struct scsi_cmnd *my_cmd)
258{ 251{
259 struct scsi_cmnd *cmd, *n; 252 struct scsi_cmnd *cmd, *n;
@@ -261,7 +254,7 @@ static void sas_scsi_clear_queue_lu(struct list_head *error_q, struct scsi_cmnd
261 list_for_each_entry_safe(cmd, n, error_q, eh_entry) { 254 list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
262 if (cmd->device->sdev_target == my_cmd->device->sdev_target && 255 if (cmd->device->sdev_target == my_cmd->device->sdev_target &&
263 cmd->device->lun == my_cmd->device->lun) 256 cmd->device->lun == my_cmd->device->lun)
264 sas_eh_defer_cmd(cmd); 257 sas_eh_finish_cmd(cmd);
265 } 258 }
266} 259}
267 260
@@ -631,12 +624,12 @@ static void sas_eh_handle_sas_errors(struct Scsi_Host *shost, struct list_head *
631 case TASK_IS_DONE: 624 case TASK_IS_DONE:
632 SAS_DPRINTK("%s: task 0x%p is done\n", __func__, 625 SAS_DPRINTK("%s: task 0x%p is done\n", __func__,
633 task); 626 task);
634 sas_eh_defer_cmd(cmd); 627 sas_eh_finish_cmd(cmd);
635 continue; 628 continue;
636 case TASK_IS_ABORTED: 629 case TASK_IS_ABORTED:
637 SAS_DPRINTK("%s: task 0x%p is aborted\n", 630 SAS_DPRINTK("%s: task 0x%p is aborted\n",
638 __func__, task); 631 __func__, task);
639 sas_eh_defer_cmd(cmd); 632 sas_eh_finish_cmd(cmd);
640 continue; 633 continue;
641 case TASK_IS_AT_LU: 634 case TASK_IS_AT_LU:
642 SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task); 635 SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task);
@@ -647,7 +640,7 @@ static void sas_eh_handle_sas_errors(struct Scsi_Host *shost, struct list_head *
647 "recovered\n", 640 "recovered\n",
648 SAS_ADDR(task->dev), 641 SAS_ADDR(task->dev),
649 cmd->device->lun); 642 cmd->device->lun);
650 sas_eh_defer_cmd(cmd); 643 sas_eh_finish_cmd(cmd);
651 sas_scsi_clear_queue_lu(work_q, cmd); 644 sas_scsi_clear_queue_lu(work_q, cmd);
652 goto Again; 645 goto Again;
653 } 646 }
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 073ced07e662..dc8e850fbfd2 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -216,36 +216,30 @@ inline void megasas_return_cmd_fusion(struct megasas_instance *instance,
216/** 216/**
217 * megasas_fire_cmd_fusion - Sends command to the FW 217 * megasas_fire_cmd_fusion - Sends command to the FW
218 * @instance: Adapter soft state 218 * @instance: Adapter soft state
219 * @req_desc: 32bit or 64bit Request descriptor 219 * @req_desc: 64bit Request descriptor
220 * 220 *
221 * Perform PCI Write. Ventura supports 32 bit Descriptor. 221 * Perform PCI Write.
222 * Prior to Ventura (12G) MR controller supports 64 bit Descriptor.
223 */ 222 */
224 223
225static void 224static void
226megasas_fire_cmd_fusion(struct megasas_instance *instance, 225megasas_fire_cmd_fusion(struct megasas_instance *instance,
227 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc) 226 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc)
228{ 227{
229 if (instance->adapter_type == VENTURA_SERIES)
230 writel(le32_to_cpu(req_desc->u.low),
231 &instance->reg_set->inbound_single_queue_port);
232 else {
233#if defined(writeq) && defined(CONFIG_64BIT) 228#if defined(writeq) && defined(CONFIG_64BIT)
234 u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) | 229 u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) |
235 le32_to_cpu(req_desc->u.low)); 230 le32_to_cpu(req_desc->u.low));
236 231
237 writeq(req_data, &instance->reg_set->inbound_low_queue_port); 232 writeq(req_data, &instance->reg_set->inbound_low_queue_port);
238#else 233#else
239 unsigned long flags; 234 unsigned long flags;
240 spin_lock_irqsave(&instance->hba_lock, flags); 235 spin_lock_irqsave(&instance->hba_lock, flags);
241 writel(le32_to_cpu(req_desc->u.low), 236 writel(le32_to_cpu(req_desc->u.low),
242 &instance->reg_set->inbound_low_queue_port); 237 &instance->reg_set->inbound_low_queue_port);
243 writel(le32_to_cpu(req_desc->u.high), 238 writel(le32_to_cpu(req_desc->u.high),
244 &instance->reg_set->inbound_high_queue_port); 239 &instance->reg_set->inbound_high_queue_port);
245 mmiowb(); 240 mmiowb();
246 spin_unlock_irqrestore(&instance->hba_lock, flags); 241 spin_unlock_irqrestore(&instance->hba_lock, flags);
247#endif 242#endif
248 }
249} 243}
250 244
251/** 245/**
@@ -982,7 +976,6 @@ megasas_ioc_init_fusion(struct megasas_instance *instance)
982 const char *sys_info; 976 const char *sys_info;
983 MFI_CAPABILITIES *drv_ops; 977 MFI_CAPABILITIES *drv_ops;
984 u32 scratch_pad_2; 978 u32 scratch_pad_2;
985 unsigned long flags;
986 ktime_t time; 979 ktime_t time;
987 bool cur_fw_64bit_dma_capable; 980 bool cur_fw_64bit_dma_capable;
988 981
@@ -1121,14 +1114,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance)
1121 break; 1114 break;
1122 } 1115 }
1123 1116
1124 /* For Ventura also IOC INIT required 64 bit Descriptor write. */ 1117 megasas_fire_cmd_fusion(instance, &req_desc);
1125 spin_lock_irqsave(&instance->hba_lock, flags);
1126 writel(le32_to_cpu(req_desc.u.low),
1127 &instance->reg_set->inbound_low_queue_port);
1128 writel(le32_to_cpu(req_desc.u.high),
1129 &instance->reg_set->inbound_high_queue_port);
1130 mmiowb();
1131 spin_unlock_irqrestore(&instance->hba_lock, flags);
1132 1118
1133 wait_and_poll(instance, cmd, MFI_POLL_TIMEOUT_SECS); 1119 wait_and_poll(instance, cmd, MFI_POLL_TIMEOUT_SECS);
1134 1120
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 13d6e4ec3022..0aafbfd1b746 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -2410,8 +2410,11 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
2410 continue; 2410 continue;
2411 } 2411 }
2412 2412
2413 for_each_cpu(cpu, mask) 2413 for_each_cpu_and(cpu, mask, cpu_online_mask) {
2414 if (cpu >= ioc->cpu_msix_table_sz)
2415 break;
2414 ioc->cpu_msix_table[cpu] = reply_q->msix_index; 2416 ioc->cpu_msix_table[cpu] = reply_q->msix_index;
2417 }
2415 } 2418 }
2416 return; 2419 return;
2417 } 2420 }
@@ -6294,14 +6297,14 @@ _base_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
6294} 6297}
6295 6298
6296/** 6299/**
6297 * _wait_for_commands_to_complete - reset controller 6300 * mpt3sas_wait_for_commands_to_complete - reset controller
6298 * @ioc: Pointer to MPT_ADAPTER structure 6301 * @ioc: Pointer to MPT_ADAPTER structure
6299 * 6302 *
6300 * This function is waiting 10s for all pending commands to complete 6303 * This function is waiting 10s for all pending commands to complete
6301 * prior to putting controller in reset. 6304 * prior to putting controller in reset.
6302 */ 6305 */
6303static void 6306void
6304_wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc) 6307mpt3sas_wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc)
6305{ 6308{
6306 u32 ioc_state; 6309 u32 ioc_state;
6307 6310
@@ -6374,7 +6377,7 @@ mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER *ioc,
6374 is_fault = 1; 6377 is_fault = 1;
6375 } 6378 }
6376 _base_reset_handler(ioc, MPT3_IOC_PRE_RESET); 6379 _base_reset_handler(ioc, MPT3_IOC_PRE_RESET);
6377 _wait_for_commands_to_complete(ioc); 6380 mpt3sas_wait_for_commands_to_complete(ioc);
6378 _base_mask_interrupts(ioc); 6381 _base_mask_interrupts(ioc);
6379 r = _base_make_ioc_ready(ioc, type); 6382 r = _base_make_ioc_ready(ioc, type);
6380 if (r) 6383 if (r)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 789bc421424b..99ccf83b8c51 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -1433,6 +1433,9 @@ void mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER *ioc,
1433 1433
1434int mpt3sas_port_enable(struct MPT3SAS_ADAPTER *ioc); 1434int mpt3sas_port_enable(struct MPT3SAS_ADAPTER *ioc);
1435 1435
1436void
1437mpt3sas_wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc);
1438
1436 1439
1437/* scsih shared API */ 1440/* scsih shared API */
1438struct scsi_cmnd *mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, 1441struct scsi_cmnd *mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc,
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 74fca184dba9..a1cb0236c550 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -2835,7 +2835,8 @@ scsih_abort(struct scsi_cmnd *scmd)
2835 _scsih_tm_display_info(ioc, scmd); 2835 _scsih_tm_display_info(ioc, scmd);
2836 2836
2837 sas_device_priv_data = scmd->device->hostdata; 2837 sas_device_priv_data = scmd->device->hostdata;
2838 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { 2838 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2839 ioc->remove_host) {
2839 sdev_printk(KERN_INFO, scmd->device, 2840 sdev_printk(KERN_INFO, scmd->device,
2840 "device been deleted! scmd(%p)\n", scmd); 2841 "device been deleted! scmd(%p)\n", scmd);
2841 scmd->result = DID_NO_CONNECT << 16; 2842 scmd->result = DID_NO_CONNECT << 16;
@@ -2898,7 +2899,8 @@ scsih_dev_reset(struct scsi_cmnd *scmd)
2898 _scsih_tm_display_info(ioc, scmd); 2899 _scsih_tm_display_info(ioc, scmd);
2899 2900
2900 sas_device_priv_data = scmd->device->hostdata; 2901 sas_device_priv_data = scmd->device->hostdata;
2901 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { 2902 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2903 ioc->remove_host) {
2902 sdev_printk(KERN_INFO, scmd->device, 2904 sdev_printk(KERN_INFO, scmd->device,
2903 "device been deleted! scmd(%p)\n", scmd); 2905 "device been deleted! scmd(%p)\n", scmd);
2904 scmd->result = DID_NO_CONNECT << 16; 2906 scmd->result = DID_NO_CONNECT << 16;
@@ -2961,7 +2963,8 @@ scsih_target_reset(struct scsi_cmnd *scmd)
2961 _scsih_tm_display_info(ioc, scmd); 2963 _scsih_tm_display_info(ioc, scmd);
2962 2964
2963 sas_device_priv_data = scmd->device->hostdata; 2965 sas_device_priv_data = scmd->device->hostdata;
2964 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { 2966 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2967 ioc->remove_host) {
2965 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", 2968 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2966 scmd); 2969 scmd);
2967 scmd->result = DID_NO_CONNECT << 16; 2970 scmd->result = DID_NO_CONNECT << 16;
@@ -3019,7 +3022,7 @@ scsih_host_reset(struct scsi_cmnd *scmd)
3019 ioc->name, scmd); 3022 ioc->name, scmd);
3020 scsi_print_command(scmd); 3023 scsi_print_command(scmd);
3021 3024
3022 if (ioc->is_driver_loading) { 3025 if (ioc->is_driver_loading || ioc->remove_host) {
3023 pr_info(MPT3SAS_FMT "Blocking the host reset\n", 3026 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
3024 ioc->name); 3027 ioc->name);
3025 r = FAILED; 3028 r = FAILED;
@@ -4453,7 +4456,7 @@ _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
4453 st = scsi_cmd_priv(scmd); 4456 st = scsi_cmd_priv(scmd);
4454 mpt3sas_base_clear_st(ioc, st); 4457 mpt3sas_base_clear_st(ioc, st);
4455 scsi_dma_unmap(scmd); 4458 scsi_dma_unmap(scmd);
4456 if (ioc->pci_error_recovery) 4459 if (ioc->pci_error_recovery || ioc->remove_host)
4457 scmd->result = DID_NO_CONNECT << 16; 4460 scmd->result = DID_NO_CONNECT << 16;
4458 else 4461 else
4459 scmd->result = DID_RESET << 16; 4462 scmd->result = DID_RESET << 16;
@@ -9739,6 +9742,10 @@ static void scsih_remove(struct pci_dev *pdev)
9739 unsigned long flags; 9742 unsigned long flags;
9740 9743
9741 ioc->remove_host = 1; 9744 ioc->remove_host = 1;
9745
9746 mpt3sas_wait_for_commands_to_complete(ioc);
9747 _scsih_flush_running_cmds(ioc);
9748
9742 _scsih_fw_event_cleanup_queue(ioc); 9749 _scsih_fw_event_cleanup_queue(ioc);
9743 9750
9744 spin_lock_irqsave(&ioc->fw_event_lock, flags); 9751 spin_lock_irqsave(&ioc->fw_event_lock, flags);
@@ -9815,6 +9822,10 @@ scsih_shutdown(struct pci_dev *pdev)
9815 unsigned long flags; 9822 unsigned long flags;
9816 9823
9817 ioc->remove_host = 1; 9824 ioc->remove_host = 1;
9825
9826 mpt3sas_wait_for_commands_to_complete(ioc);
9827 _scsih_flush_running_cmds(ioc);
9828
9818 _scsih_fw_event_cleanup_queue(ioc); 9829 _scsih_fw_event_cleanup_queue(ioc);
9819 9830
9820 spin_lock_irqsave(&ioc->fw_event_lock, flags); 9831 spin_lock_irqsave(&ioc->fw_event_lock, flags);
@@ -10547,7 +10558,7 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
10547 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), 10558 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
10548 "fw_event_%s%d", ioc->driver_name, ioc->id); 10559 "fw_event_%s%d", ioc->driver_name, ioc->id);
10549 ioc->firmware_event_thread = alloc_ordered_workqueue( 10560 ioc->firmware_event_thread = alloc_ordered_workqueue(
10550 ioc->firmware_event_name, WQ_MEM_RECLAIM); 10561 ioc->firmware_event_name, 0);
10551 if (!ioc->firmware_event_thread) { 10562 if (!ioc->firmware_event_thread) {
10552 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", 10563 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
10553 ioc->name, __FILE__, __LINE__, __func__); 10564 ioc->name, __FILE__, __LINE__, __func__);
diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c
index 667d7697ba01..d09afe1b567d 100644
--- a/drivers/scsi/qedi/qedi_fw.c
+++ b/drivers/scsi/qedi/qedi_fw.c
@@ -762,6 +762,11 @@ static void qedi_process_cmd_cleanup_resp(struct qedi_ctx *qedi,
762 762
763 iscsi_cid = cqe->conn_id; 763 iscsi_cid = cqe->conn_id;
764 qedi_conn = qedi->cid_que.conn_cid_tbl[iscsi_cid]; 764 qedi_conn = qedi->cid_que.conn_cid_tbl[iscsi_cid];
765 if (!qedi_conn) {
766 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
767 "icid not found 0x%x\n", cqe->conn_id);
768 return;
769 }
765 770
766 /* Based on this itt get the corresponding qedi_cmd */ 771 /* Based on this itt get the corresponding qedi_cmd */
767 spin_lock_bh(&qedi_conn->tmf_work_lock); 772 spin_lock_bh(&qedi_conn->tmf_work_lock);
diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
index 029e2e69b29f..f57a94b4f0d9 100644
--- a/drivers/scsi/qedi/qedi_main.c
+++ b/drivers/scsi/qedi/qedi_main.c
@@ -1724,7 +1724,6 @@ static ssize_t qedi_show_boot_eth_info(void *data, int type, char *buf)
1724{ 1724{
1725 struct qedi_ctx *qedi = data; 1725 struct qedi_ctx *qedi = data;
1726 struct nvm_iscsi_initiator *initiator; 1726 struct nvm_iscsi_initiator *initiator;
1727 char *str = buf;
1728 int rc = 1; 1727 int rc = 1;
1729 u32 ipv6_en, dhcp_en, ip_len; 1728 u32 ipv6_en, dhcp_en, ip_len;
1730 struct nvm_iscsi_block *block; 1729 struct nvm_iscsi_block *block;
@@ -1758,32 +1757,32 @@ static ssize_t qedi_show_boot_eth_info(void *data, int type, char *buf)
1758 1757
1759 switch (type) { 1758 switch (type) {
1760 case ISCSI_BOOT_ETH_IP_ADDR: 1759 case ISCSI_BOOT_ETH_IP_ADDR:
1761 rc = snprintf(str, ip_len, fmt, ip); 1760 rc = snprintf(buf, ip_len, fmt, ip);
1762 break; 1761 break;
1763 case ISCSI_BOOT_ETH_SUBNET_MASK: 1762 case ISCSI_BOOT_ETH_SUBNET_MASK:
1764 rc = snprintf(str, ip_len, fmt, sub); 1763 rc = snprintf(buf, ip_len, fmt, sub);
1765 break; 1764 break;
1766 case ISCSI_BOOT_ETH_GATEWAY: 1765 case ISCSI_BOOT_ETH_GATEWAY:
1767 rc = snprintf(str, ip_len, fmt, gw); 1766 rc = snprintf(buf, ip_len, fmt, gw);
1768 break; 1767 break;
1769 case ISCSI_BOOT_ETH_FLAGS: 1768 case ISCSI_BOOT_ETH_FLAGS:
1770 rc = snprintf(str, 3, "%hhd\n", 1769 rc = snprintf(buf, 3, "%hhd\n",
1771 SYSFS_FLAG_FW_SEL_BOOT); 1770 SYSFS_FLAG_FW_SEL_BOOT);
1772 break; 1771 break;
1773 case ISCSI_BOOT_ETH_INDEX: 1772 case ISCSI_BOOT_ETH_INDEX:
1774 rc = snprintf(str, 3, "0\n"); 1773 rc = snprintf(buf, 3, "0\n");
1775 break; 1774 break;
1776 case ISCSI_BOOT_ETH_MAC: 1775 case ISCSI_BOOT_ETH_MAC:
1777 rc = sysfs_format_mac(str, qedi->mac, ETH_ALEN); 1776 rc = sysfs_format_mac(buf, qedi->mac, ETH_ALEN);
1778 break; 1777 break;
1779 case ISCSI_BOOT_ETH_VLAN: 1778 case ISCSI_BOOT_ETH_VLAN:
1780 rc = snprintf(str, 12, "%d\n", 1779 rc = snprintf(buf, 12, "%d\n",
1781 GET_FIELD2(initiator->generic_cont0, 1780 GET_FIELD2(initiator->generic_cont0,
1782 NVM_ISCSI_CFG_INITIATOR_VLAN)); 1781 NVM_ISCSI_CFG_INITIATOR_VLAN));
1783 break; 1782 break;
1784 case ISCSI_BOOT_ETH_ORIGIN: 1783 case ISCSI_BOOT_ETH_ORIGIN:
1785 if (dhcp_en) 1784 if (dhcp_en)
1786 rc = snprintf(str, 3, "3\n"); 1785 rc = snprintf(buf, 3, "3\n");
1787 break; 1786 break;
1788 default: 1787 default:
1789 rc = 0; 1788 rc = 0;
@@ -1819,7 +1818,6 @@ static ssize_t qedi_show_boot_ini_info(void *data, int type, char *buf)
1819{ 1818{
1820 struct qedi_ctx *qedi = data; 1819 struct qedi_ctx *qedi = data;
1821 struct nvm_iscsi_initiator *initiator; 1820 struct nvm_iscsi_initiator *initiator;
1822 char *str = buf;
1823 int rc; 1821 int rc;
1824 struct nvm_iscsi_block *block; 1822 struct nvm_iscsi_block *block;
1825 1823
@@ -1831,8 +1829,8 @@ static ssize_t qedi_show_boot_ini_info(void *data, int type, char *buf)
1831 1829
1832 switch (type) { 1830 switch (type) {
1833 case ISCSI_BOOT_INI_INITIATOR_NAME: 1831 case ISCSI_BOOT_INI_INITIATOR_NAME:
1834 rc = snprintf(str, NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, "%s\n", 1832 rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN,
1835 initiator->initiator_name.byte); 1833 initiator->initiator_name.byte);
1836 break; 1834 break;
1837 default: 1835 default:
1838 rc = 0; 1836 rc = 0;
@@ -1860,7 +1858,6 @@ static ssize_t
1860qedi_show_boot_tgt_info(struct qedi_ctx *qedi, int type, 1858qedi_show_boot_tgt_info(struct qedi_ctx *qedi, int type,
1861 char *buf, enum qedi_nvm_tgts idx) 1859 char *buf, enum qedi_nvm_tgts idx)
1862{ 1860{
1863 char *str = buf;
1864 int rc = 1; 1861 int rc = 1;
1865 u32 ctrl_flags, ipv6_en, chap_en, mchap_en, ip_len; 1862 u32 ctrl_flags, ipv6_en, chap_en, mchap_en, ip_len;
1866 struct nvm_iscsi_block *block; 1863 struct nvm_iscsi_block *block;
@@ -1899,48 +1896,48 @@ qedi_show_boot_tgt_info(struct qedi_ctx *qedi, int type,
1899 1896
1900 switch (type) { 1897 switch (type) {
1901 case ISCSI_BOOT_TGT_NAME: 1898 case ISCSI_BOOT_TGT_NAME:
1902 rc = snprintf(str, NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN, "%s\n", 1899 rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_ISCSI_NAME_MAX_LEN,
1903 block->target[idx].target_name.byte); 1900 block->target[idx].target_name.byte);
1904 break; 1901 break;
1905 case ISCSI_BOOT_TGT_IP_ADDR: 1902 case ISCSI_BOOT_TGT_IP_ADDR:
1906 if (ipv6_en) 1903 if (ipv6_en)
1907 rc = snprintf(str, ip_len, "%pI6\n", 1904 rc = snprintf(buf, ip_len, "%pI6\n",
1908 block->target[idx].ipv6_addr.byte); 1905 block->target[idx].ipv6_addr.byte);
1909 else 1906 else
1910 rc = snprintf(str, ip_len, "%pI4\n", 1907 rc = snprintf(buf, ip_len, "%pI4\n",
1911 block->target[idx].ipv4_addr.byte); 1908 block->target[idx].ipv4_addr.byte);
1912 break; 1909 break;
1913 case ISCSI_BOOT_TGT_PORT: 1910 case ISCSI_BOOT_TGT_PORT:
1914 rc = snprintf(str, 12, "%d\n", 1911 rc = snprintf(buf, 12, "%d\n",
1915 GET_FIELD2(block->target[idx].generic_cont0, 1912 GET_FIELD2(block->target[idx].generic_cont0,
1916 NVM_ISCSI_CFG_TARGET_TCP_PORT)); 1913 NVM_ISCSI_CFG_TARGET_TCP_PORT));
1917 break; 1914 break;
1918 case ISCSI_BOOT_TGT_LUN: 1915 case ISCSI_BOOT_TGT_LUN:
1919 rc = snprintf(str, 22, "%.*d\n", 1916 rc = snprintf(buf, 22, "%.*d\n",
1920 block->target[idx].lun.value[1], 1917 block->target[idx].lun.value[1],
1921 block->target[idx].lun.value[0]); 1918 block->target[idx].lun.value[0]);
1922 break; 1919 break;
1923 case ISCSI_BOOT_TGT_CHAP_NAME: 1920 case ISCSI_BOOT_TGT_CHAP_NAME:
1924 rc = snprintf(str, NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, "%s\n", 1921 rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN,
1925 chap_name); 1922 chap_name);
1926 break; 1923 break;
1927 case ISCSI_BOOT_TGT_CHAP_SECRET: 1924 case ISCSI_BOOT_TGT_CHAP_SECRET:
1928 rc = snprintf(str, NVM_ISCSI_CFG_CHAP_PWD_MAX_LEN, "%s\n", 1925 rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN,
1929 chap_secret); 1926 chap_secret);
1930 break; 1927 break;
1931 case ISCSI_BOOT_TGT_REV_CHAP_NAME: 1928 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
1932 rc = snprintf(str, NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN, "%s\n", 1929 rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN,
1933 mchap_name); 1930 mchap_name);
1934 break; 1931 break;
1935 case ISCSI_BOOT_TGT_REV_CHAP_SECRET: 1932 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
1936 rc = snprintf(str, NVM_ISCSI_CFG_CHAP_PWD_MAX_LEN, "%s\n", 1933 rc = sprintf(buf, "%.*s\n", NVM_ISCSI_CFG_CHAP_NAME_MAX_LEN,
1937 mchap_secret); 1934 mchap_secret);
1938 break; 1935 break;
1939 case ISCSI_BOOT_TGT_FLAGS: 1936 case ISCSI_BOOT_TGT_FLAGS:
1940 rc = snprintf(str, 3, "%hhd\n", SYSFS_FLAG_FW_SEL_BOOT); 1937 rc = snprintf(buf, 3, "%hhd\n", SYSFS_FLAG_FW_SEL_BOOT);
1941 break; 1938 break;
1942 case ISCSI_BOOT_TGT_NIC_ASSOC: 1939 case ISCSI_BOOT_TGT_NIC_ASSOC:
1943 rc = snprintf(str, 3, "0\n"); 1940 rc = snprintf(buf, 3, "0\n");
1944 break; 1941 break;
1945 default: 1942 default:
1946 rc = 0; 1943 rc = 0;
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index be7d6824581a..c9689f97c307 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -261,9 +261,9 @@
261struct name_list_extended { 261struct name_list_extended {
262 struct get_name_list_extended *l; 262 struct get_name_list_extended *l;
263 dma_addr_t ldma; 263 dma_addr_t ldma;
264 struct list_head fcports; /* protect by sess_list */ 264 struct list_head fcports;
265 spinlock_t fcports_lock;
265 u32 size; 266 u32 size;
266 u8 sent;
267}; 267};
268/* 268/*
269 * Timeout timer counts in seconds 269 * Timeout timer counts in seconds
@@ -2217,6 +2217,7 @@ typedef struct {
2217 2217
2218/* FCP-4 types */ 2218/* FCP-4 types */
2219#define FC4_TYPE_FCP_SCSI 0x08 2219#define FC4_TYPE_FCP_SCSI 0x08
2220#define FC4_TYPE_NVME 0x28
2220#define FC4_TYPE_OTHER 0x0 2221#define FC4_TYPE_OTHER 0x0
2221#define FC4_TYPE_UNKNOWN 0xff 2222#define FC4_TYPE_UNKNOWN 0xff
2222 2223
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index 5bf9a59432f6..403fa096f8c8 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -3179,6 +3179,7 @@ done_free_sp:
3179 sp->free(sp); 3179 sp->free(sp);
3180 fcport->flags &= ~FCF_ASYNC_SENT; 3180 fcport->flags &= ~FCF_ASYNC_SENT;
3181done: 3181done:
3182 fcport->flags &= ~FCF_ASYNC_ACTIVE;
3182 return rval; 3183 return rval;
3183} 3184}
3184 3185
@@ -3370,6 +3371,7 @@ done_free_sp:
3370 sp->free(sp); 3371 sp->free(sp);
3371 fcport->flags &= ~FCF_ASYNC_SENT; 3372 fcport->flags &= ~FCF_ASYNC_SENT;
3372done: 3373done:
3374 fcport->flags &= ~FCF_ASYNC_ACTIVE;
3373 return rval; 3375 return rval;
3374} 3376}
3375 3377
@@ -3971,6 +3973,9 @@ out:
3971 spin_lock_irqsave(&vha->work_lock, flags); 3973 spin_lock_irqsave(&vha->work_lock, flags);
3972 vha->scan.scan_flags &= ~SF_SCANNING; 3974 vha->scan.scan_flags &= ~SF_SCANNING;
3973 spin_unlock_irqrestore(&vha->work_lock, flags); 3975 spin_unlock_irqrestore(&vha->work_lock, flags);
3976
3977 if ((fc4type == FC4_TYPE_FCP_SCSI) && vha->flags.nvme_enabled)
3978 qla24xx_async_gpnft(vha, FC4_TYPE_NVME);
3974} 3979}
3975 3980
3976static void qla2x00_async_gpnft_gnnft_sp_done(void *s, int res) 3981static void qla2x00_async_gpnft_gnnft_sp_done(void *s, int res)
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index aececf664654..8d7fab3cd01d 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -59,8 +59,6 @@ qla2x00_sp_timeout(struct timer_list *t)
59 req->outstanding_cmds[sp->handle] = NULL; 59 req->outstanding_cmds[sp->handle] = NULL;
60 iocb = &sp->u.iocb_cmd; 60 iocb = &sp->u.iocb_cmd;
61 iocb->timeout(sp); 61 iocb->timeout(sp);
62 if (sp->type != SRB_ELS_DCMD)
63 sp->free(sp);
64 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); 62 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
65} 63}
66 64
@@ -102,7 +100,6 @@ qla2x00_async_iocb_timeout(void *data)
102 srb_t *sp = data; 100 srb_t *sp = data;
103 fc_port_t *fcport = sp->fcport; 101 fc_port_t *fcport = sp->fcport;
104 struct srb_iocb *lio = &sp->u.iocb_cmd; 102 struct srb_iocb *lio = &sp->u.iocb_cmd;
105 struct event_arg ea;
106 103
107 if (fcport) { 104 if (fcport) {
108 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, 105 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
@@ -117,25 +114,13 @@ qla2x00_async_iocb_timeout(void *data)
117 114
118 switch (sp->type) { 115 switch (sp->type) {
119 case SRB_LOGIN_CMD: 116 case SRB_LOGIN_CMD:
120 if (!fcport)
121 break;
122 /* Retry as needed. */ 117 /* Retry as needed. */
123 lio->u.logio.data[0] = MBS_COMMAND_ERROR; 118 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
124 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? 119 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
125 QLA_LOGIO_LOGIN_RETRIED : 0; 120 QLA_LOGIO_LOGIN_RETRIED : 0;
126 memset(&ea, 0, sizeof(ea)); 121 sp->done(sp, QLA_FUNCTION_TIMEOUT);
127 ea.event = FCME_PLOGI_DONE;
128 ea.fcport = sp->fcport;
129 ea.data[0] = lio->u.logio.data[0];
130 ea.data[1] = lio->u.logio.data[1];
131 ea.sp = sp;
132 qla24xx_handle_plogi_done_event(fcport->vha, &ea);
133 break; 122 break;
134 case SRB_LOGOUT_CMD: 123 case SRB_LOGOUT_CMD:
135 if (!fcport)
136 break;
137 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
138 break;
139 case SRB_CT_PTHRU_CMD: 124 case SRB_CT_PTHRU_CMD:
140 case SRB_MB_IOCB: 125 case SRB_MB_IOCB:
141 case SRB_NACK_PLOGI: 126 case SRB_NACK_PLOGI:
@@ -228,6 +213,7 @@ done_free_sp:
228 sp->free(sp); 213 sp->free(sp);
229 fcport->flags &= ~FCF_ASYNC_SENT; 214 fcport->flags &= ~FCF_ASYNC_SENT;
230done: 215done:
216 fcport->flags &= ~FCF_ASYNC_ACTIVE;
231 return rval; 217 return rval;
232} 218}
233 219
@@ -235,12 +221,10 @@ static void
235qla2x00_async_logout_sp_done(void *ptr, int res) 221qla2x00_async_logout_sp_done(void *ptr, int res)
236{ 222{
237 srb_t *sp = ptr; 223 srb_t *sp = ptr;
238 struct srb_iocb *lio = &sp->u.iocb_cmd;
239 224
240 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 225 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
241 if (!test_bit(UNLOADING, &sp->vha->dpc_flags)) 226 sp->fcport->login_gen++;
242 qla2x00_post_async_logout_done_work(sp->vha, sp->fcport, 227 qlt_logo_completion_handler(sp->fcport, res);
243 lio->u.logio.data);
244 sp->free(sp); 228 sp->free(sp);
245} 229}
246 230
@@ -280,7 +264,7 @@ qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
280done_free_sp: 264done_free_sp:
281 sp->free(sp); 265 sp->free(sp);
282done: 266done:
283 fcport->flags &= ~FCF_ASYNC_SENT; 267 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
284 return rval; 268 return rval;
285} 269}
286 270
@@ -288,6 +272,7 @@ void
288qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport, 272qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
289 uint16_t *data) 273 uint16_t *data)
290{ 274{
275 fcport->flags &= ~FCF_ASYNC_ACTIVE;
291 /* Don't re-login in target mode */ 276 /* Don't re-login in target mode */
292 if (!fcport->tgt_session) 277 if (!fcport->tgt_session)
293 qla2x00_mark_device_lost(vha, fcport, 1, 0); 278 qla2x00_mark_device_lost(vha, fcport, 1, 0);
@@ -301,6 +286,7 @@ qla2x00_async_prlo_sp_done(void *s, int res)
301 struct srb_iocb *lio = &sp->u.iocb_cmd; 286 struct srb_iocb *lio = &sp->u.iocb_cmd;
302 struct scsi_qla_host *vha = sp->vha; 287 struct scsi_qla_host *vha = sp->vha;
303 288
289 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
304 if (!test_bit(UNLOADING, &vha->dpc_flags)) 290 if (!test_bit(UNLOADING, &vha->dpc_flags))
305 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport, 291 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
306 lio->u.logio.data); 292 lio->u.logio.data);
@@ -339,6 +325,7 @@ qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
339done_free_sp: 325done_free_sp:
340 sp->free(sp); 326 sp->free(sp);
341done: 327done:
328 fcport->flags &= ~FCF_ASYNC_ACTIVE;
342 return rval; 329 return rval;
343} 330}
344 331
@@ -392,6 +379,8 @@ qla2x00_async_adisc_sp_done(void *ptr, int res)
392 "Async done-%s res %x %8phC\n", 379 "Async done-%s res %x %8phC\n",
393 sp->name, res, sp->fcport->port_name); 380 sp->name, res, sp->fcport->port_name);
394 381
382 sp->fcport->flags &= ~FCF_ASYNC_SENT;
383
395 memset(&ea, 0, sizeof(ea)); 384 memset(&ea, 0, sizeof(ea));
396 ea.event = FCME_ADISC_DONE; 385 ea.event = FCME_ADISC_DONE;
397 ea.rc = res; 386 ea.rc = res;
@@ -442,7 +431,7 @@ qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
442done_free_sp: 431done_free_sp:
443 sp->free(sp); 432 sp->free(sp);
444done: 433done:
445 fcport->flags &= ~FCF_ASYNC_SENT; 434 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
446 qla2x00_post_async_adisc_work(vha, fcport, data); 435 qla2x00_post_async_adisc_work(vha, fcport, data);
447 return rval; 436 return rval;
448} 437}
@@ -660,8 +649,7 @@ qla24xx_async_gnl_sp_done(void *s, int res)
660 (loop_id & 0x7fff)); 649 (loop_id & 0x7fff));
661 } 650 }
662 651
663 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 652 spin_lock_irqsave(&vha->gnl.fcports_lock, flags);
664 vha->gnl.sent = 0;
665 653
666 INIT_LIST_HEAD(&h); 654 INIT_LIST_HEAD(&h);
667 fcport = tf = NULL; 655 fcport = tf = NULL;
@@ -670,12 +658,16 @@ qla24xx_async_gnl_sp_done(void *s, int res)
670 658
671 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) { 659 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
672 list_del_init(&fcport->gnl_entry); 660 list_del_init(&fcport->gnl_entry);
661 spin_lock(&vha->hw->tgt.sess_lock);
673 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); 662 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
663 spin_unlock(&vha->hw->tgt.sess_lock);
674 ea.fcport = fcport; 664 ea.fcport = fcport;
675 665
676 qla2x00_fcport_event_handler(vha, &ea); 666 qla2x00_fcport_event_handler(vha, &ea);
677 } 667 }
668 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
678 669
670 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
679 /* create new fcport if fw has knowledge of new sessions */ 671 /* create new fcport if fw has knowledge of new sessions */
680 for (i = 0; i < n; i++) { 672 for (i = 0; i < n; i++) {
681 port_id_t id; 673 port_id_t id;
@@ -727,18 +719,21 @@ int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
727 ql_dbg(ql_dbg_disc, vha, 0x20d9, 719 ql_dbg(ql_dbg_disc, vha, 0x20d9,
728 "Async-gnlist WWPN %8phC \n", fcport->port_name); 720 "Async-gnlist WWPN %8phC \n", fcport->port_name);
729 721
730 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 722 spin_lock_irqsave(&vha->gnl.fcports_lock, flags);
723 if (!list_empty(&fcport->gnl_entry)) {
724 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
725 rval = QLA_SUCCESS;
726 goto done;
727 }
728
729 spin_lock(&vha->hw->tgt.sess_lock);
731 fcport->disc_state = DSC_GNL; 730 fcport->disc_state = DSC_GNL;
732 fcport->last_rscn_gen = fcport->rscn_gen; 731 fcport->last_rscn_gen = fcport->rscn_gen;
733 fcport->last_login_gen = fcport->login_gen; 732 fcport->last_login_gen = fcport->login_gen;
733 spin_unlock(&vha->hw->tgt.sess_lock);
734 734
735 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports); 735 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
736 if (vha->gnl.sent) { 736 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
737 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
738 return QLA_SUCCESS;
739 }
740 vha->gnl.sent = 1;
741 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
742 737
743 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); 738 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
744 if (!sp) 739 if (!sp)
@@ -1066,6 +1061,7 @@ void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1066 fc_port_t *fcport = ea->fcport; 1061 fc_port_t *fcport = ea->fcport;
1067 struct port_database_24xx *pd; 1062 struct port_database_24xx *pd;
1068 struct srb *sp = ea->sp; 1063 struct srb *sp = ea->sp;
1064 uint8_t ls;
1069 1065
1070 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in; 1066 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1071 1067
@@ -1078,7 +1074,12 @@ void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1078 if (fcport->disc_state == DSC_DELETE_PEND) 1074 if (fcport->disc_state == DSC_DELETE_PEND)
1079 return; 1075 return;
1080 1076
1081 switch (pd->current_login_state) { 1077 if (fcport->fc4f_nvme)
1078 ls = pd->current_login_state >> 4;
1079 else
1080 ls = pd->current_login_state & 0xf;
1081
1082 switch (ls) {
1082 case PDS_PRLI_COMPLETE: 1083 case PDS_PRLI_COMPLETE:
1083 __qla24xx_parse_gpdb(vha, fcport, pd); 1084 __qla24xx_parse_gpdb(vha, fcport, pd);
1084 break; 1085 break;
@@ -1168,8 +1169,9 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1168 if (fcport->scan_state != QLA_FCPORT_FOUND) 1169 if (fcport->scan_state != QLA_FCPORT_FOUND)
1169 return 0; 1170 return 0;
1170 1171
1171 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || 1172 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1172 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) 1173 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1174 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1173 return 0; 1175 return 0;
1174 1176
1175 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { 1177 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
@@ -1544,6 +1546,7 @@ qla24xx_abort_sp_done(void *ptr, int res)
1544 srb_t *sp = ptr; 1546 srb_t *sp = ptr;
1545 struct srb_iocb *abt = &sp->u.iocb_cmd; 1547 struct srb_iocb *abt = &sp->u.iocb_cmd;
1546 1548
1549 del_timer(&sp->u.iocb_cmd.timer);
1547 complete(&abt->u.abt.comp); 1550 complete(&abt->u.abt.comp);
1548} 1551}
1549 1552
@@ -1716,7 +1719,6 @@ qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1716 1719
1717 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); 1720 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1718 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 1721 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1719 ea->fcport->loop_id = FC_NO_LOOP_ID;
1720 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; 1722 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1721 ea->fcport->logout_on_delete = 1; 1723 ea->fcport->logout_on_delete = 1;
1722 ea->fcport->send_els_logo = 0; 1724 ea->fcport->send_els_logo = 0;
@@ -1808,6 +1810,7 @@ qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1808 qla2x00_mark_device_lost(vha, fcport, 1, 0); 1810 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1809 qlt_logo_completion_handler(fcport, data[0]); 1811 qlt_logo_completion_handler(fcport, data[0]);
1810 fcport->login_gen++; 1812 fcport->login_gen++;
1813 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1811 return; 1814 return;
1812} 1815}
1813 1816
@@ -1815,6 +1818,7 @@ void
1815qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, 1818qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1816 uint16_t *data) 1819 uint16_t *data)
1817{ 1820{
1821 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1818 if (data[0] == MBS_COMMAND_COMPLETE) { 1822 if (data[0] == MBS_COMMAND_COMPLETE) {
1819 qla2x00_update_fcport(vha, fcport); 1823 qla2x00_update_fcport(vha, fcport);
1820 1824
@@ -1822,7 +1826,6 @@ qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1822 } 1826 }
1823 1827
1824 /* Retry login. */ 1828 /* Retry login. */
1825 fcport->flags &= ~FCF_ASYNC_SENT;
1826 if (data[1] & QLA_LOGIO_LOGIN_RETRIED) 1829 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1827 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 1830 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1828 else 1831 else
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index 1b62e943ec49..8d00d559bd26 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -3275,12 +3275,11 @@ qla24xx_abort_iocb(srb_t *sp, struct abort_entry_24xx *abt_iocb)
3275 memset(abt_iocb, 0, sizeof(struct abort_entry_24xx)); 3275 memset(abt_iocb, 0, sizeof(struct abort_entry_24xx));
3276 abt_iocb->entry_type = ABORT_IOCB_TYPE; 3276 abt_iocb->entry_type = ABORT_IOCB_TYPE;
3277 abt_iocb->entry_count = 1; 3277 abt_iocb->entry_count = 1;
3278 abt_iocb->handle = 3278 abt_iocb->handle = cpu_to_le32(MAKE_HANDLE(req->id, sp->handle));
3279 cpu_to_le32(MAKE_HANDLE(aio->u.abt.req_que_no,
3280 aio->u.abt.cmd_hndl));
3281 abt_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id); 3279 abt_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
3282 abt_iocb->handle_to_abort = 3280 abt_iocb->handle_to_abort =
3283 cpu_to_le32(MAKE_HANDLE(req->id, aio->u.abt.cmd_hndl)); 3281 cpu_to_le32(MAKE_HANDLE(aio->u.abt.req_que_no,
3282 aio->u.abt.cmd_hndl));
3284 abt_iocb->port_id[0] = sp->fcport->d_id.b.al_pa; 3283 abt_iocb->port_id[0] = sp->fcport->d_id.b.al_pa;
3285 abt_iocb->port_id[1] = sp->fcport->d_id.b.area; 3284 abt_iocb->port_id[1] = sp->fcport->d_id.b.area;
3286 abt_iocb->port_id[2] = sp->fcport->d_id.b.domain; 3285 abt_iocb->port_id[2] = sp->fcport->d_id.b.domain;
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 14109d86c3f6..89f93ebd819d 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -272,7 +272,8 @@ qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
272 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 272 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
273 273
274 /* Read all mbox registers? */ 274 /* Read all mbox registers? */
275 mboxes = (1 << ha->mbx_count) - 1; 275 WARN_ON_ONCE(ha->mbx_count > 32);
276 mboxes = (1ULL << ha->mbx_count) - 1;
276 if (!ha->mcp) 277 if (!ha->mcp)
277 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n"); 278 ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n");
278 else 279 else
@@ -2880,7 +2881,8 @@ qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
2880 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; 2881 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2881 2882
2882 /* Read all mbox registers? */ 2883 /* Read all mbox registers? */
2883 mboxes = (1 << ha->mbx_count) - 1; 2884 WARN_ON_ONCE(ha->mbx_count > 32);
2885 mboxes = (1ULL << ha->mbx_count) - 1;
2884 if (!ha->mcp) 2886 if (!ha->mcp)
2885 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n"); 2887 ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n");
2886 else 2888 else
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 12ee6e02d146..5c5dcca4d1da 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -454,7 +454,7 @@ static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
454 ha->req_q_map[0] = req; 454 ha->req_q_map[0] = req;
455 set_bit(0, ha->rsp_qid_map); 455 set_bit(0, ha->rsp_qid_map);
456 set_bit(0, ha->req_qid_map); 456 set_bit(0, ha->req_qid_map);
457 return 1; 457 return 0;
458 458
459fail_qpair_map: 459fail_qpair_map:
460 kfree(ha->base_qpair); 460 kfree(ha->base_qpair);
@@ -471,6 +471,9 @@ fail_req_map:
471 471
472static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req) 472static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
473{ 473{
474 if (!ha->req_q_map)
475 return;
476
474 if (IS_QLAFX00(ha)) { 477 if (IS_QLAFX00(ha)) {
475 if (req && req->ring_fx00) 478 if (req && req->ring_fx00)
476 dma_free_coherent(&ha->pdev->dev, 479 dma_free_coherent(&ha->pdev->dev,
@@ -481,14 +484,17 @@ static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
481 (req->length + 1) * sizeof(request_t), 484 (req->length + 1) * sizeof(request_t),
482 req->ring, req->dma); 485 req->ring, req->dma);
483 486
484 if (req) 487 if (req) {
485 kfree(req->outstanding_cmds); 488 kfree(req->outstanding_cmds);
486 489 kfree(req);
487 kfree(req); 490 }
488} 491}
489 492
490static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp) 493static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
491{ 494{
495 if (!ha->rsp_q_map)
496 return;
497
492 if (IS_QLAFX00(ha)) { 498 if (IS_QLAFX00(ha)) {
493 if (rsp && rsp->ring) 499 if (rsp && rsp->ring)
494 dma_free_coherent(&ha->pdev->dev, 500 dma_free_coherent(&ha->pdev->dev,
@@ -499,7 +505,8 @@ static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
499 (rsp->length + 1) * sizeof(response_t), 505 (rsp->length + 1) * sizeof(response_t),
500 rsp->ring, rsp->dma); 506 rsp->ring, rsp->dma);
501 } 507 }
502 kfree(rsp); 508 if (rsp)
509 kfree(rsp);
503} 510}
504 511
505static void qla2x00_free_queues(struct qla_hw_data *ha) 512static void qla2x00_free_queues(struct qla_hw_data *ha)
@@ -1723,6 +1730,8 @@ __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
1723 struct qla_tgt_cmd *cmd; 1730 struct qla_tgt_cmd *cmd;
1724 uint8_t trace = 0; 1731 uint8_t trace = 0;
1725 1732
1733 if (!ha->req_q_map)
1734 return;
1726 spin_lock_irqsave(qp->qp_lock_ptr, flags); 1735 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1727 req = qp->req; 1736 req = qp->req;
1728 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) { 1737 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
@@ -3095,14 +3104,14 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
3095 /* Set up the irqs */ 3104 /* Set up the irqs */
3096 ret = qla2x00_request_irqs(ha, rsp); 3105 ret = qla2x00_request_irqs(ha, rsp);
3097 if (ret) 3106 if (ret)
3098 goto probe_hw_failed; 3107 goto probe_failed;
3099 3108
3100 /* Alloc arrays of request and response ring ptrs */ 3109 /* Alloc arrays of request and response ring ptrs */
3101 if (!qla2x00_alloc_queues(ha, req, rsp)) { 3110 if (qla2x00_alloc_queues(ha, req, rsp)) {
3102 ql_log(ql_log_fatal, base_vha, 0x003d, 3111 ql_log(ql_log_fatal, base_vha, 0x003d,
3103 "Failed to allocate memory for queue pointers..." 3112 "Failed to allocate memory for queue pointers..."
3104 "aborting.\n"); 3113 "aborting.\n");
3105 goto probe_init_failed; 3114 goto probe_failed;
3106 } 3115 }
3107 3116
3108 if (ha->mqenable && shost_use_blk_mq(host)) { 3117 if (ha->mqenable && shost_use_blk_mq(host)) {
@@ -3387,15 +3396,6 @@ skip_dpc:
3387 3396
3388 return 0; 3397 return 0;
3389 3398
3390probe_init_failed:
3391 qla2x00_free_req_que(ha, req);
3392 ha->req_q_map[0] = NULL;
3393 clear_bit(0, ha->req_qid_map);
3394 qla2x00_free_rsp_que(ha, rsp);
3395 ha->rsp_q_map[0] = NULL;
3396 clear_bit(0, ha->rsp_qid_map);
3397 ha->max_req_queues = ha->max_rsp_queues = 0;
3398
3399probe_failed: 3399probe_failed:
3400 if (base_vha->timer_active) 3400 if (base_vha->timer_active)
3401 qla2x00_stop_timer(base_vha); 3401 qla2x00_stop_timer(base_vha);
@@ -3625,6 +3625,8 @@ qla2x00_remove_one(struct pci_dev *pdev)
3625 } 3625 }
3626 qla2x00_wait_for_hba_ready(base_vha); 3626 qla2x00_wait_for_hba_ready(base_vha);
3627 3627
3628 qla2x00_wait_for_sess_deletion(base_vha);
3629
3628 /* 3630 /*
3629 * if UNLOAD flag is already set, then continue unload, 3631 * if UNLOAD flag is already set, then continue unload,
3630 * where it was set first. 3632 * where it was set first.
@@ -4506,11 +4508,17 @@ qla2x00_mem_free(struct qla_hw_data *ha)
4506 if (ha->init_cb) 4508 if (ha->init_cb)
4507 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, 4509 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
4508 ha->init_cb, ha->init_cb_dma); 4510 ha->init_cb, ha->init_cb_dma);
4509 vfree(ha->optrom_buffer); 4511
4510 kfree(ha->nvram); 4512 if (ha->optrom_buffer)
4511 kfree(ha->npiv_info); 4513 vfree(ha->optrom_buffer);
4512 kfree(ha->swl); 4514 if (ha->nvram)
4513 kfree(ha->loop_id_map); 4515 kfree(ha->nvram);
4516 if (ha->npiv_info)
4517 kfree(ha->npiv_info);
4518 if (ha->swl)
4519 kfree(ha->swl);
4520 if (ha->loop_id_map)
4521 kfree(ha->loop_id_map);
4514 4522
4515 ha->srb_mempool = NULL; 4523 ha->srb_mempool = NULL;
4516 ha->ctx_mempool = NULL; 4524 ha->ctx_mempool = NULL;
@@ -4526,6 +4534,15 @@ qla2x00_mem_free(struct qla_hw_data *ha)
4526 ha->ex_init_cb_dma = 0; 4534 ha->ex_init_cb_dma = 0;
4527 ha->async_pd = NULL; 4535 ha->async_pd = NULL;
4528 ha->async_pd_dma = 0; 4536 ha->async_pd_dma = 0;
4537 ha->loop_id_map = NULL;
4538 ha->npiv_info = NULL;
4539 ha->optrom_buffer = NULL;
4540 ha->swl = NULL;
4541 ha->nvram = NULL;
4542 ha->mctp_dump = NULL;
4543 ha->dcbx_tlv = NULL;
4544 ha->xgmac_data = NULL;
4545 ha->sfp_data = NULL;
4529 4546
4530 ha->s_dma_pool = NULL; 4547 ha->s_dma_pool = NULL;
4531 ha->dl_dma_pool = NULL; 4548 ha->dl_dma_pool = NULL;
@@ -4575,6 +4592,7 @@ struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4575 4592
4576 spin_lock_init(&vha->work_lock); 4593 spin_lock_init(&vha->work_lock);
4577 spin_lock_init(&vha->cmd_list_lock); 4594 spin_lock_init(&vha->cmd_list_lock);
4595 spin_lock_init(&vha->gnl.fcports_lock);
4578 init_waitqueue_head(&vha->fcport_waitQ); 4596 init_waitqueue_head(&vha->fcport_waitQ);
4579 init_waitqueue_head(&vha->vref_waitq); 4597 init_waitqueue_head(&vha->vref_waitq);
4580 4598
@@ -4804,9 +4822,12 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4804 fcport->d_id = e->u.new_sess.id; 4822 fcport->d_id = e->u.new_sess.id;
4805 fcport->flags |= FCF_FABRIC_DEVICE; 4823 fcport->flags |= FCF_FABRIC_DEVICE;
4806 fcport->fw_login_state = DSC_LS_PLOGI_PEND; 4824 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4807 if (e->u.new_sess.fc4_type == FC4_TYPE_FCP_SCSI) 4825 if (e->u.new_sess.fc4_type == FC4_TYPE_FCP_SCSI) {
4808 fcport->fc4_type = FC4_TYPE_FCP_SCSI; 4826 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
4809 4827 } else if (e->u.new_sess.fc4_type == FC4_TYPE_NVME) {
4828 fcport->fc4_type = FC4_TYPE_OTHER;
4829 fcport->fc4f_nvme = FC4_TYPE_NVME;
4830 }
4810 memcpy(fcport->port_name, e->u.new_sess.port_name, 4831 memcpy(fcport->port_name, e->u.new_sess.port_name,
4811 WWN_SIZE); 4832 WWN_SIZE);
4812 } else { 4833 } else {
@@ -4875,6 +4896,8 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4875 } 4896 }
4876 qlt_plogi_ack_unref(vha, pla); 4897 qlt_plogi_ack_unref(vha, pla);
4877 } else { 4898 } else {
4899 fc_port_t *dfcp = NULL;
4900
4878 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 4901 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4879 tfcp = qla2x00_find_fcport_by_nportid(vha, 4902 tfcp = qla2x00_find_fcport_by_nportid(vha,
4880 &e->u.new_sess.id, 1); 4903 &e->u.new_sess.id, 1);
@@ -4897,11 +4920,13 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4897 default: 4920 default:
4898 fcport->login_pause = 1; 4921 fcport->login_pause = 1;
4899 tfcp->conflict = fcport; 4922 tfcp->conflict = fcport;
4900 qlt_schedule_sess_for_deletion(tfcp); 4923 dfcp = tfcp;
4901 break; 4924 break;
4902 } 4925 }
4903 } 4926 }
4904 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 4927 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4928 if (dfcp)
4929 qlt_schedule_sess_for_deletion(tfcp);
4905 4930
4906 wwn = wwn_to_u64(fcport->node_name); 4931 wwn = wwn_to_u64(fcport->node_name);
4907 4932
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index fc89af8fe256..b49ac85f3de2 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -1224,10 +1224,10 @@ static void qla24xx_chk_fcp_state(struct fc_port *sess)
1224 } 1224 }
1225} 1225}
1226 1226
1227/* ha->tgt.sess_lock supposed to be held on entry */
1228void qlt_schedule_sess_for_deletion(struct fc_port *sess) 1227void qlt_schedule_sess_for_deletion(struct fc_port *sess)
1229{ 1228{
1230 struct qla_tgt *tgt = sess->tgt; 1229 struct qla_tgt *tgt = sess->tgt;
1230 struct qla_hw_data *ha = sess->vha->hw;
1231 unsigned long flags; 1231 unsigned long flags;
1232 1232
1233 if (sess->disc_state == DSC_DELETE_PEND) 1233 if (sess->disc_state == DSC_DELETE_PEND)
@@ -1244,16 +1244,16 @@ void qlt_schedule_sess_for_deletion(struct fc_port *sess)
1244 return; 1244 return;
1245 } 1245 }
1246 1246
1247 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1247 if (sess->deleted == QLA_SESS_DELETED) 1248 if (sess->deleted == QLA_SESS_DELETED)
1248 sess->logout_on_delete = 0; 1249 sess->logout_on_delete = 0;
1249 1250
1250 spin_lock_irqsave(&sess->vha->work_lock, flags);
1251 if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { 1251 if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) {
1252 spin_unlock_irqrestore(&sess->vha->work_lock, flags); 1252 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1253 return; 1253 return;
1254 } 1254 }
1255 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; 1255 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1256 spin_unlock_irqrestore(&sess->vha->work_lock, flags); 1256 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1257 1257
1258 sess->disc_state = DSC_DELETE_PEND; 1258 sess->disc_state = DSC_DELETE_PEND;
1259 1259
@@ -1262,13 +1262,10 @@ void qlt_schedule_sess_for_deletion(struct fc_port *sess)
1262 ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, 1262 ql_dbg(ql_dbg_tgt, sess->vha, 0xe001,
1263 "Scheduling sess %p for deletion\n", sess); 1263 "Scheduling sess %p for deletion\n", sess);
1264 1264
1265 /* use cancel to push work element through before re-queue */
1266 cancel_work_sync(&sess->del_work);
1267 INIT_WORK(&sess->del_work, qla24xx_delete_sess_fn); 1265 INIT_WORK(&sess->del_work, qla24xx_delete_sess_fn);
1268 queue_work(sess->vha->hw->wq, &sess->del_work); 1266 WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work));
1269} 1267}
1270 1268
1271/* ha->tgt.sess_lock supposed to be held on entry */
1272static void qlt_clear_tgt_db(struct qla_tgt *tgt) 1269static void qlt_clear_tgt_db(struct qla_tgt *tgt)
1273{ 1270{
1274 struct fc_port *sess; 1271 struct fc_port *sess;
@@ -1451,8 +1448,8 @@ qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport, int max_gen)
1451 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); 1448 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess);
1452 1449
1453 sess->local = 1; 1450 sess->local = 1;
1454 qlt_schedule_sess_for_deletion(sess);
1455 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 1451 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1452 qlt_schedule_sess_for_deletion(sess);
1456} 1453}
1457 1454
1458static inline int test_tgt_sess_count(struct qla_tgt *tgt) 1455static inline int test_tgt_sess_count(struct qla_tgt *tgt)
@@ -1512,10 +1509,8 @@ int qlt_stop_phase1(struct qla_tgt *tgt)
1512 * Lock is needed, because we still can get an incoming packet. 1509 * Lock is needed, because we still can get an incoming packet.
1513 */ 1510 */
1514 mutex_lock(&vha->vha_tgt.tgt_mutex); 1511 mutex_lock(&vha->vha_tgt.tgt_mutex);
1515 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1516 tgt->tgt_stop = 1; 1512 tgt->tgt_stop = 1;
1517 qlt_clear_tgt_db(tgt); 1513 qlt_clear_tgt_db(tgt);
1518 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1519 mutex_unlock(&vha->vha_tgt.tgt_mutex); 1514 mutex_unlock(&vha->vha_tgt.tgt_mutex);
1520 mutex_unlock(&qla_tgt_mutex); 1515 mutex_unlock(&qla_tgt_mutex);
1521 1516
@@ -4871,8 +4866,6 @@ static int qlt_24xx_handle_els(struct scsi_qla_host *vha,
4871 sess); 4866 sess);
4872 qlt_send_term_imm_notif(vha, iocb, 1); 4867 qlt_send_term_imm_notif(vha, iocb, 1);
4873 res = 0; 4868 res = 0;
4874 spin_lock_irqsave(&tgt->ha->tgt.sess_lock,
4875 flags);
4876 break; 4869 break;
4877 } 4870 }
4878 4871
diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
index fc233717355f..817f312023a9 100644
--- a/drivers/scsi/qla4xxx/ql4_def.h
+++ b/drivers/scsi/qla4xxx/ql4_def.h
@@ -168,6 +168,8 @@
168#define DEV_DB_NON_PERSISTENT 0 168#define DEV_DB_NON_PERSISTENT 0
169#define DEV_DB_PERSISTENT 1 169#define DEV_DB_PERSISTENT 1
170 170
171#define QL4_ISP_REG_DISCONNECT 0xffffffffU
172
171#define COPY_ISID(dst_isid, src_isid) { \ 173#define COPY_ISID(dst_isid, src_isid) { \
172 int i, j; \ 174 int i, j; \
173 for (i = 0, j = ISID_SIZE - 1; i < ISID_SIZE;) \ 175 for (i = 0, j = ISID_SIZE - 1; i < ISID_SIZE;) \
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 82e889bbe0ed..fc2c97d9a0d6 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -262,6 +262,24 @@ static struct iscsi_transport qla4xxx_iscsi_transport = {
262 262
263static struct scsi_transport_template *qla4xxx_scsi_transport; 263static struct scsi_transport_template *qla4xxx_scsi_transport;
264 264
265static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha)
266{
267 u32 reg_val = 0;
268 int rval = QLA_SUCCESS;
269
270 if (is_qla8022(ha))
271 reg_val = readl(&ha->qla4_82xx_reg->host_status);
272 else if (is_qla8032(ha) || is_qla8042(ha))
273 reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
274 else
275 reg_val = readw(&ha->reg->ctrl_status);
276
277 if (reg_val == QL4_ISP_REG_DISCONNECT)
278 rval = QLA_ERROR;
279
280 return rval;
281}
282
265static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num, 283static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
266 uint32_t iface_type, uint32_t payload_size, 284 uint32_t iface_type, uint32_t payload_size,
267 uint32_t pid, struct sockaddr *dst_addr) 285 uint32_t pid, struct sockaddr *dst_addr)
@@ -9186,10 +9204,17 @@ static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9186 struct srb *srb = NULL; 9204 struct srb *srb = NULL;
9187 int ret = SUCCESS; 9205 int ret = SUCCESS;
9188 int wait = 0; 9206 int wait = 0;
9207 int rval;
9189 9208
9190 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n", 9209 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9191 ha->host_no, id, lun, cmd, cmd->cmnd[0]); 9210 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9192 9211
9212 rval = qla4xxx_isp_check_reg(ha);
9213 if (rval != QLA_SUCCESS) {
9214 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9215 return FAILED;
9216 }
9217
9193 spin_lock_irqsave(&ha->hardware_lock, flags); 9218 spin_lock_irqsave(&ha->hardware_lock, flags);
9194 srb = (struct srb *) CMD_SP(cmd); 9219 srb = (struct srb *) CMD_SP(cmd);
9195 if (!srb) { 9220 if (!srb) {
@@ -9241,6 +9266,7 @@ static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9241 struct scsi_qla_host *ha = to_qla_host(cmd->device->host); 9266 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9242 struct ddb_entry *ddb_entry = cmd->device->hostdata; 9267 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9243 int ret = FAILED, stat; 9268 int ret = FAILED, stat;
9269 int rval;
9244 9270
9245 if (!ddb_entry) 9271 if (!ddb_entry)
9246 return ret; 9272 return ret;
@@ -9260,6 +9286,12 @@ static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9260 cmd, jiffies, cmd->request->timeout / HZ, 9286 cmd, jiffies, cmd->request->timeout / HZ,
9261 ha->dpc_flags, cmd->result, cmd->allowed)); 9287 ha->dpc_flags, cmd->result, cmd->allowed));
9262 9288
9289 rval = qla4xxx_isp_check_reg(ha);
9290 if (rval != QLA_SUCCESS) {
9291 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9292 return FAILED;
9293 }
9294
9263 /* FIXME: wait for hba to go online */ 9295 /* FIXME: wait for hba to go online */
9264 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun); 9296 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9265 if (stat != QLA_SUCCESS) { 9297 if (stat != QLA_SUCCESS) {
@@ -9303,6 +9335,7 @@ static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9303 struct scsi_qla_host *ha = to_qla_host(cmd->device->host); 9335 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9304 struct ddb_entry *ddb_entry = cmd->device->hostdata; 9336 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9305 int stat, ret; 9337 int stat, ret;
9338 int rval;
9306 9339
9307 if (!ddb_entry) 9340 if (!ddb_entry)
9308 return FAILED; 9341 return FAILED;
@@ -9320,6 +9353,12 @@ static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9320 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, 9353 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
9321 ha->dpc_flags, cmd->result, cmd->allowed)); 9354 ha->dpc_flags, cmd->result, cmd->allowed));
9322 9355
9356 rval = qla4xxx_isp_check_reg(ha);
9357 if (rval != QLA_SUCCESS) {
9358 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9359 return FAILED;
9360 }
9361
9323 stat = qla4xxx_reset_target(ha, ddb_entry); 9362 stat = qla4xxx_reset_target(ha, ddb_entry);
9324 if (stat != QLA_SUCCESS) { 9363 if (stat != QLA_SUCCESS) {
9325 starget_printk(KERN_INFO, scsi_target(cmd->device), 9364 starget_printk(KERN_INFO, scsi_target(cmd->device),
@@ -9374,9 +9413,16 @@ static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9374{ 9413{
9375 int return_status = FAILED; 9414 int return_status = FAILED;
9376 struct scsi_qla_host *ha; 9415 struct scsi_qla_host *ha;
9416 int rval;
9377 9417
9378 ha = to_qla_host(cmd->device->host); 9418 ha = to_qla_host(cmd->device->host);
9379 9419
9420 rval = qla4xxx_isp_check_reg(ha);
9421 if (rval != QLA_SUCCESS) {
9422 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9423 return FAILED;
9424 }
9425
9380 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba) 9426 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9381 qla4_83xx_set_idc_dontreset(ha); 9427 qla4_83xx_set_idc_dontreset(ha);
9382 9428
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index d042915ce895..ca53a5f785ee 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -223,7 +223,8 @@ static void scsi_eh_reset(struct scsi_cmnd *scmd)
223 223
224static void scsi_eh_inc_host_failed(struct rcu_head *head) 224static void scsi_eh_inc_host_failed(struct rcu_head *head)
225{ 225{
226 struct Scsi_Host *shost = container_of(head, typeof(*shost), rcu); 226 struct scsi_cmnd *scmd = container_of(head, typeof(*scmd), rcu);
227 struct Scsi_Host *shost = scmd->device->host;
227 unsigned long flags; 228 unsigned long flags;
228 229
229 spin_lock_irqsave(shost->host_lock, flags); 230 spin_lock_irqsave(shost->host_lock, flags);
@@ -259,7 +260,7 @@ void scsi_eh_scmd_add(struct scsi_cmnd *scmd)
259 * Ensure that all tasks observe the host state change before the 260 * Ensure that all tasks observe the host state change before the
260 * host_failed change. 261 * host_failed change.
261 */ 262 */
262 call_rcu(&shost->rcu, scsi_eh_inc_host_failed); 263 call_rcu(&scmd->rcu, scsi_eh_inc_host_failed);
263} 264}
264 265
265/** 266/**
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index a86df9ca7d1c..c84f931388f2 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -671,6 +671,7 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
671 if (!blk_rq_is_scsi(req)) { 671 if (!blk_rq_is_scsi(req)) {
672 WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED)); 672 WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED));
673 cmd->flags &= ~SCMD_INITIALIZED; 673 cmd->flags &= ~SCMD_INITIALIZED;
674 destroy_rcu_head(&cmd->rcu);
674 } 675 }
675 676
676 if (req->mq_ctx) { 677 if (req->mq_ctx) {
@@ -720,6 +721,8 @@ static blk_status_t __scsi_error_from_host_byte(struct scsi_cmnd *cmd,
720 int result) 721 int result)
721{ 722{
722 switch (host_byte(result)) { 723 switch (host_byte(result)) {
724 case DID_OK:
725 return BLK_STS_OK;
723 case DID_TRANSPORT_FAILFAST: 726 case DID_TRANSPORT_FAILFAST:
724 return BLK_STS_TRANSPORT; 727 return BLK_STS_TRANSPORT;
725 case DID_TARGET_FAILURE: 728 case DID_TARGET_FAILURE:
@@ -1151,6 +1154,7 @@ static void scsi_initialize_rq(struct request *rq)
1151 struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); 1154 struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
1152 1155
1153 scsi_req_init(&cmd->req); 1156 scsi_req_init(&cmd->req);
1157 init_rcu_head(&cmd->rcu);
1154 cmd->jiffies_at_alloc = jiffies; 1158 cmd->jiffies_at_alloc = jiffies;
1155 cmd->retries = 0; 1159 cmd->retries = 0;
1156} 1160}
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index bff21e636ddd..3541caf3fceb 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2595,6 +2595,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
2595 int res; 2595 int res;
2596 struct scsi_device *sdp = sdkp->device; 2596 struct scsi_device *sdp = sdkp->device;
2597 struct scsi_mode_data data; 2597 struct scsi_mode_data data;
2598 int disk_ro = get_disk_ro(sdkp->disk);
2598 int old_wp = sdkp->write_prot; 2599 int old_wp = sdkp->write_prot;
2599 2600
2600 set_disk_ro(sdkp->disk, 0); 2601 set_disk_ro(sdkp->disk, 0);
@@ -2635,7 +2636,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
2635 "Test WP failed, assume Write Enabled\n"); 2636 "Test WP failed, assume Write Enabled\n");
2636 } else { 2637 } else {
2637 sdkp->write_prot = ((data.device_specific & 0x80) != 0); 2638 sdkp->write_prot = ((data.device_specific & 0x80) != 0);
2638 set_disk_ro(sdkp->disk, sdkp->write_prot); 2639 set_disk_ro(sdkp->disk, sdkp->write_prot || disk_ro);
2639 if (sdkp->first_scan || old_wp != sdkp->write_prot) { 2640 if (sdkp->first_scan || old_wp != sdkp->write_prot) {
2640 sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n", 2641 sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n",
2641 sdkp->write_prot ? "on" : "off"); 2642 sdkp->write_prot ? "on" : "off");
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index 6c348a211ebb..89cf4498f535 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -403,7 +403,7 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf)
403 */ 403 */
404static int sd_zbc_check_zone_size(struct scsi_disk *sdkp) 404static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
405{ 405{
406 u64 zone_blocks; 406 u64 zone_blocks = 0;
407 sector_t block = 0; 407 sector_t block = 0;
408 unsigned char *buf; 408 unsigned char *buf;
409 unsigned char *rec; 409 unsigned char *rec;
@@ -421,10 +421,8 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
421 421
422 /* Do a report zone to get the same field */ 422 /* Do a report zone to get the same field */
423 ret = sd_zbc_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0); 423 ret = sd_zbc_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0);
424 if (ret) { 424 if (ret)
425 zone_blocks = 0; 425 goto out_free;
426 goto out;
427 }
428 426
429 same = buf[4] & 0x0f; 427 same = buf[4] & 0x0f;
430 if (same > 0) { 428 if (same > 0) {
@@ -464,7 +462,7 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
464 ret = sd_zbc_report_zones(sdkp, buf, 462 ret = sd_zbc_report_zones(sdkp, buf,
465 SD_ZBC_BUF_SIZE, block); 463 SD_ZBC_BUF_SIZE, block);
466 if (ret) 464 if (ret)
467 return ret; 465 goto out_free;
468 } 466 }
469 467
470 } while (block < sdkp->capacity); 468 } while (block < sdkp->capacity);
@@ -472,35 +470,32 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
472 zone_blocks = sdkp->zone_blocks; 470 zone_blocks = sdkp->zone_blocks;
473 471
474out: 472out:
475 kfree(buf);
476
477 if (!zone_blocks) { 473 if (!zone_blocks) {
478 if (sdkp->first_scan) 474 if (sdkp->first_scan)
479 sd_printk(KERN_NOTICE, sdkp, 475 sd_printk(KERN_NOTICE, sdkp,
480 "Devices with non constant zone " 476 "Devices with non constant zone "
481 "size are not supported\n"); 477 "size are not supported\n");
482 return -ENODEV; 478 ret = -ENODEV;
483 } 479 } else if (!is_power_of_2(zone_blocks)) {
484
485 if (!is_power_of_2(zone_blocks)) {
486 if (sdkp->first_scan) 480 if (sdkp->first_scan)
487 sd_printk(KERN_NOTICE, sdkp, 481 sd_printk(KERN_NOTICE, sdkp,
488 "Devices with non power of 2 zone " 482 "Devices with non power of 2 zone "
489 "size are not supported\n"); 483 "size are not supported\n");
490 return -ENODEV; 484 ret = -ENODEV;
491 } 485 } else if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) {
492
493 if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) {
494 if (sdkp->first_scan) 486 if (sdkp->first_scan)
495 sd_printk(KERN_NOTICE, sdkp, 487 sd_printk(KERN_NOTICE, sdkp,
496 "Zone size too large\n"); 488 "Zone size too large\n");
497 return -ENODEV; 489 ret = -ENODEV;
490 } else {
491 sdkp->zone_blocks = zone_blocks;
492 sdkp->zone_shift = ilog2(zone_blocks);
498 } 493 }
499 494
500 sdkp->zone_blocks = zone_blocks; 495out_free:
501 sdkp->zone_shift = ilog2(zone_blocks); 496 kfree(buf);
502 497
503 return 0; 498 return ret;
504} 499}
505 500
506/** 501/**
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 40fc7a590e81..8c51d628b52e 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1311,7 +1311,8 @@ static int storvsc_do_io(struct hv_device *device,
1311 */ 1311 */
1312 cpumask_and(&alloced_mask, &stor_device->alloced_cpus, 1312 cpumask_and(&alloced_mask, &stor_device->alloced_cpus,
1313 cpumask_of_node(cpu_to_node(q_num))); 1313 cpumask_of_node(cpu_to_node(q_num)));
1314 for_each_cpu(tgt_cpu, &alloced_mask) { 1314 for_each_cpu_wrap(tgt_cpu, &alloced_mask,
1315 outgoing_channel->target_cpu + 1) {
1315 if (tgt_cpu != outgoing_channel->target_cpu) { 1316 if (tgt_cpu != outgoing_channel->target_cpu) {
1316 outgoing_channel = 1317 outgoing_channel =
1317 stor_device->stor_chns[tgt_cpu]; 1318 stor_device->stor_chns[tgt_cpu];
@@ -1657,7 +1658,7 @@ static struct scsi_host_template scsi_driver = {
1657 .eh_timed_out = storvsc_eh_timed_out, 1658 .eh_timed_out = storvsc_eh_timed_out,
1658 .slave_alloc = storvsc_device_alloc, 1659 .slave_alloc = storvsc_device_alloc,
1659 .slave_configure = storvsc_device_configure, 1660 .slave_configure = storvsc_device_configure,
1660 .cmd_per_lun = 255, 1661 .cmd_per_lun = 2048,
1661 .this_id = -1, 1662 .this_id = -1,
1662 .use_clustering = ENABLE_CLUSTERING, 1663 .use_clustering = ENABLE_CLUSTERING,
1663 /* Make sure we dont get a sg segment crosses a page boundary */ 1664 /* Make sure we dont get a sg segment crosses a page boundary */
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.c b/drivers/scsi/sym53c8xx_2/sym_hipd.c
index ca360daa6a25..378af306fda1 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.c
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.c
@@ -536,7 +536,7 @@ sym_getsync(struct sym_hcb *np, u_char dt, u_char sfac, u_char *divp, u_char *fa
536 * Look for the greatest clock divisor that allows an 536 * Look for the greatest clock divisor that allows an
537 * input speed faster than the period. 537 * input speed faster than the period.
538 */ 538 */
539 while (div-- > 0) 539 while (--div > 0)
540 if (kpc >= (div_10M[div] << 2)) break; 540 if (kpc >= (div_10M[div] << 2)) break;
541 541
542 /* 542 /*
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index a355d989b414..c7da2c185990 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -4352,6 +4352,8 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev)
4352 /* REPORT SUPPORTED OPERATION CODES is not supported */ 4352 /* REPORT SUPPORTED OPERATION CODES is not supported */
4353 sdev->no_report_opcodes = 1; 4353 sdev->no_report_opcodes = 1;
4354 4354
4355 /* WRITE_SAME command is not supported */
4356 sdev->no_write_same = 1;
4355 4357
4356 ufshcd_set_queue_depth(sdev); 4358 ufshcd_set_queue_depth(sdev);
4357 4359
diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c
index e4f5bb056fd2..ba3cfa8e279b 100644
--- a/drivers/soc/fsl/qbman/qman.c
+++ b/drivers/soc/fsl/qbman/qman.c
@@ -2443,39 +2443,21 @@ struct cgr_comp {
2443 struct completion completion; 2443 struct completion completion;
2444}; 2444};
2445 2445
2446static int qman_delete_cgr_thread(void *p) 2446static void qman_delete_cgr_smp_call(void *p)
2447{ 2447{
2448 struct cgr_comp *cgr_comp = (struct cgr_comp *)p; 2448 qman_delete_cgr((struct qman_cgr *)p);
2449 int ret;
2450
2451 ret = qman_delete_cgr(cgr_comp->cgr);
2452 complete(&cgr_comp->completion);
2453
2454 return ret;
2455} 2449}
2456 2450
2457void qman_delete_cgr_safe(struct qman_cgr *cgr) 2451void qman_delete_cgr_safe(struct qman_cgr *cgr)
2458{ 2452{
2459 struct task_struct *thread;
2460 struct cgr_comp cgr_comp;
2461
2462 preempt_disable(); 2453 preempt_disable();
2463 if (qman_cgr_cpus[cgr->cgrid] != smp_processor_id()) { 2454 if (qman_cgr_cpus[cgr->cgrid] != smp_processor_id()) {
2464 init_completion(&cgr_comp.completion); 2455 smp_call_function_single(qman_cgr_cpus[cgr->cgrid],
2465 cgr_comp.cgr = cgr; 2456 qman_delete_cgr_smp_call, cgr, true);
2466 thread = kthread_create(qman_delete_cgr_thread, &cgr_comp,
2467 "cgr_del");
2468
2469 if (IS_ERR(thread))
2470 goto out;
2471
2472 kthread_bind(thread, qman_cgr_cpus[cgr->cgrid]);
2473 wake_up_process(thread);
2474 wait_for_completion(&cgr_comp.completion);
2475 preempt_enable(); 2457 preempt_enable();
2476 return; 2458 return;
2477 } 2459 }
2478out: 2460
2479 qman_delete_cgr(cgr); 2461 qman_delete_cgr(cgr);
2480 preempt_enable(); 2462 preempt_enable();
2481} 2463}
diff --git a/drivers/soc/imx/gpc.c b/drivers/soc/imx/gpc.c
index 53f7275d6cbd..750f93197411 100644
--- a/drivers/soc/imx/gpc.c
+++ b/drivers/soc/imx/gpc.c
@@ -348,7 +348,7 @@ static int imx_gpc_old_dt_init(struct device *dev, struct regmap *regmap,
348 if (i == 1) { 348 if (i == 1) {
349 domain->supply = devm_regulator_get(dev, "pu"); 349 domain->supply = devm_regulator_get(dev, "pu");
350 if (IS_ERR(domain->supply)) 350 if (IS_ERR(domain->supply))
351 return PTR_ERR(domain->supply);; 351 return PTR_ERR(domain->supply);
352 352
353 ret = imx_pgc_get_clocks(dev, domain); 353 ret = imx_pgc_get_clocks(dev, domain);
354 if (ret) 354 if (ret)
@@ -470,13 +470,21 @@ static int imx_gpc_probe(struct platform_device *pdev)
470 470
471static int imx_gpc_remove(struct platform_device *pdev) 471static int imx_gpc_remove(struct platform_device *pdev)
472{ 472{
473 struct device_node *pgc_node;
473 int ret; 474 int ret;
474 475
476 pgc_node = of_get_child_by_name(pdev->dev.of_node, "pgc");
477
478 /* bail out if DT too old and doesn't provide the necessary info */
479 if (!of_property_read_bool(pdev->dev.of_node, "#power-domain-cells") &&
480 !pgc_node)
481 return 0;
482
475 /* 483 /*
476 * If the old DT binding is used the toplevel driver needs to 484 * If the old DT binding is used the toplevel driver needs to
477 * de-register the power domains 485 * de-register the power domains
478 */ 486 */
479 if (!of_get_child_by_name(pdev->dev.of_node, "pgc")) { 487 if (!pgc_node) {
480 of_genpd_del_provider(pdev->dev.of_node); 488 of_genpd_del_provider(pdev->dev.of_node);
481 489
482 ret = pm_genpd_remove(&imx_gpc_domains[GPC_PGC_DOMAIN_PU].base); 490 ret = pm_genpd_remove(&imx_gpc_domains[GPC_PGC_DOMAIN_PU].base);
diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index bbdc53b686dd..86580b6df33d 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -326,24 +326,23 @@ static loff_t ashmem_llseek(struct file *file, loff_t offset, int origin)
326 mutex_lock(&ashmem_mutex); 326 mutex_lock(&ashmem_mutex);
327 327
328 if (asma->size == 0) { 328 if (asma->size == 0) {
329 ret = -EINVAL; 329 mutex_unlock(&ashmem_mutex);
330 goto out; 330 return -EINVAL;
331 } 331 }
332 332
333 if (!asma->file) { 333 if (!asma->file) {
334 ret = -EBADF; 334 mutex_unlock(&ashmem_mutex);
335 goto out; 335 return -EBADF;
336 } 336 }
337 337
338 mutex_unlock(&ashmem_mutex);
339
338 ret = vfs_llseek(asma->file, offset, origin); 340 ret = vfs_llseek(asma->file, offset, origin);
339 if (ret < 0) 341 if (ret < 0)
340 goto out; 342 return ret;
341 343
342 /** Copy f_pos from backing file, since f_ops->llseek() sets it */ 344 /** Copy f_pos from backing file, since f_ops->llseek() sets it */
343 file->f_pos = asma->file->f_pos; 345 file->f_pos = asma->file->f_pos;
344
345out:
346 mutex_unlock(&ashmem_mutex);
347 return ret; 346 return ret;
348} 347}
349 348
@@ -702,30 +701,30 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
702 size_t pgstart, pgend; 701 size_t pgstart, pgend;
703 int ret = -EINVAL; 702 int ret = -EINVAL;
704 703
705 if (unlikely(!asma->file))
706 return -EINVAL;
707
708 if (unlikely(copy_from_user(&pin, p, sizeof(pin)))) 704 if (unlikely(copy_from_user(&pin, p, sizeof(pin))))
709 return -EFAULT; 705 return -EFAULT;
710 706
707 mutex_lock(&ashmem_mutex);
708
709 if (unlikely(!asma->file))
710 goto out_unlock;
711
711 /* per custom, you can pass zero for len to mean "everything onward" */ 712 /* per custom, you can pass zero for len to mean "everything onward" */
712 if (!pin.len) 713 if (!pin.len)
713 pin.len = PAGE_ALIGN(asma->size) - pin.offset; 714 pin.len = PAGE_ALIGN(asma->size) - pin.offset;
714 715
715 if (unlikely((pin.offset | pin.len) & ~PAGE_MASK)) 716 if (unlikely((pin.offset | pin.len) & ~PAGE_MASK))
716 return -EINVAL; 717 goto out_unlock;
717 718
718 if (unlikely(((__u32)-1) - pin.offset < pin.len)) 719 if (unlikely(((__u32)-1) - pin.offset < pin.len))
719 return -EINVAL; 720 goto out_unlock;
720 721
721 if (unlikely(PAGE_ALIGN(asma->size) < pin.offset + pin.len)) 722 if (unlikely(PAGE_ALIGN(asma->size) < pin.offset + pin.len))
722 return -EINVAL; 723 goto out_unlock;
723 724
724 pgstart = pin.offset / PAGE_SIZE; 725 pgstart = pin.offset / PAGE_SIZE;
725 pgend = pgstart + (pin.len / PAGE_SIZE) - 1; 726 pgend = pgstart + (pin.len / PAGE_SIZE) - 1;
726 727
727 mutex_lock(&ashmem_mutex);
728
729 switch (cmd) { 728 switch (cmd) {
730 case ASHMEM_PIN: 729 case ASHMEM_PIN:
731 ret = ashmem_pin(asma, pgstart, pgend); 730 ret = ashmem_pin(asma, pgstart, pgend);
@@ -738,6 +737,7 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
738 break; 737 break;
739 } 738 }
740 739
740out_unlock:
741 mutex_unlock(&ashmem_mutex); 741 mutex_unlock(&ashmem_mutex);
742 742
743 return ret; 743 return ret;
diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
index 94e06925c712..49718c96bf9e 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -12,6 +12,7 @@
12#include <linux/err.h> 12#include <linux/err.h>
13#include <linux/cma.h> 13#include <linux/cma.h>
14#include <linux/scatterlist.h> 14#include <linux/scatterlist.h>
15#include <linux/highmem.h>
15 16
16#include "ion.h" 17#include "ion.h"
17 18
@@ -42,6 +43,22 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
42 if (!pages) 43 if (!pages)
43 return -ENOMEM; 44 return -ENOMEM;
44 45
46 if (PageHighMem(pages)) {
47 unsigned long nr_clear_pages = nr_pages;
48 struct page *page = pages;
49
50 while (nr_clear_pages > 0) {
51 void *vaddr = kmap_atomic(page);
52
53 memset(vaddr, 0, PAGE_SIZE);
54 kunmap_atomic(vaddr);
55 page++;
56 nr_clear_pages--;
57 }
58 } else {
59 memset(page_address(pages), 0, size);
60 }
61
45 table = kmalloc(sizeof(*table), GFP_KERNEL); 62 table = kmalloc(sizeof(*table), GFP_KERNEL);
46 if (!table) 63 if (!table)
47 goto err; 64 goto err;
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index e618a87521a3..9d733471ca2e 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -475,8 +475,7 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
475 struct comedi_cmd *cmd = &async->cmd; 475 struct comedi_cmd *cmd = &async->cmd;
476 476
477 if (cmd->stop_src == TRIG_COUNT) { 477 if (cmd->stop_src == TRIG_COUNT) {
478 unsigned int nscans = nsamples / cmd->scan_end_arg; 478 unsigned int scans_left = __comedi_nscans_left(s, cmd->stop_arg);
479 unsigned int scans_left = __comedi_nscans_left(s, nscans);
480 unsigned int scan_pos = 479 unsigned int scan_pos =
481 comedi_bytes_to_samples(s, async->scan_progress); 480 comedi_bytes_to_samples(s, async->scan_progress);
482 unsigned long long samples_left = 0; 481 unsigned long long samples_left = 0;
diff --git a/drivers/staging/fsl-mc/bus/Kconfig b/drivers/staging/fsl-mc/bus/Kconfig
index 1f9100049176..b35ef7ee6901 100644
--- a/drivers/staging/fsl-mc/bus/Kconfig
+++ b/drivers/staging/fsl-mc/bus/Kconfig
@@ -7,7 +7,7 @@
7 7
8config FSL_MC_BUS 8config FSL_MC_BUS
9 bool "QorIQ DPAA2 fsl-mc bus driver" 9 bool "QorIQ DPAA2 fsl-mc bus driver"
10 depends on OF && (ARCH_LAYERSCAPE || (COMPILE_TEST && (ARM || ARM64 || X86 || PPC))) 10 depends on OF && (ARCH_LAYERSCAPE || (COMPILE_TEST && (ARM || ARM64 || X86_LOCAL_APIC || PPC)))
11 select GENERIC_MSI_IRQ_DOMAIN 11 select GENERIC_MSI_IRQ_DOMAIN
12 help 12 help
13 Driver to enable the bus infrastructure for the QorIQ DPAA2 13 Driver to enable the bus infrastructure for the QorIQ DPAA2
diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
index 5064d5ddf581..fc2013aade51 100644
--- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
+++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
@@ -73,6 +73,8 @@ static int __init its_fsl_mc_msi_init(void)
73 73
74 for (np = of_find_matching_node(NULL, its_device_id); np; 74 for (np = of_find_matching_node(NULL, its_device_id); np;
75 np = of_find_matching_node(np, its_device_id)) { 75 np = of_find_matching_node(np, its_device_id)) {
76 if (!of_device_is_available(np))
77 continue;
76 if (!of_property_read_bool(np, "msi-controller")) 78 if (!of_property_read_bool(np, "msi-controller"))
77 continue; 79 continue;
78 80
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index f01595593ce2..425e8b82533b 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -141,6 +141,8 @@
141#define AD7192_GPOCON_P1DAT BIT(1) /* P1 state */ 141#define AD7192_GPOCON_P1DAT BIT(1) /* P1 state */
142#define AD7192_GPOCON_P0DAT BIT(0) /* P0 state */ 142#define AD7192_GPOCON_P0DAT BIT(0) /* P0 state */
143 143
144#define AD7192_EXT_FREQ_MHZ_MIN 2457600
145#define AD7192_EXT_FREQ_MHZ_MAX 5120000
144#define AD7192_INT_FREQ_MHZ 4915200 146#define AD7192_INT_FREQ_MHZ 4915200
145 147
146/* NOTE: 148/* NOTE:
@@ -218,6 +220,12 @@ static int ad7192_calibrate_all(struct ad7192_state *st)
218 ARRAY_SIZE(ad7192_calib_arr)); 220 ARRAY_SIZE(ad7192_calib_arr));
219} 221}
220 222
223static inline bool ad7192_valid_external_frequency(u32 freq)
224{
225 return (freq >= AD7192_EXT_FREQ_MHZ_MIN &&
226 freq <= AD7192_EXT_FREQ_MHZ_MAX);
227}
228
221static int ad7192_setup(struct ad7192_state *st, 229static int ad7192_setup(struct ad7192_state *st,
222 const struct ad7192_platform_data *pdata) 230 const struct ad7192_platform_data *pdata)
223{ 231{
@@ -243,17 +251,20 @@ static int ad7192_setup(struct ad7192_state *st,
243 id); 251 id);
244 252
245 switch (pdata->clock_source_sel) { 253 switch (pdata->clock_source_sel) {
246 case AD7192_CLK_EXT_MCLK1_2:
247 case AD7192_CLK_EXT_MCLK2:
248 st->mclk = AD7192_INT_FREQ_MHZ;
249 break;
250 case AD7192_CLK_INT: 254 case AD7192_CLK_INT:
251 case AD7192_CLK_INT_CO: 255 case AD7192_CLK_INT_CO:
252 if (pdata->ext_clk_hz) 256 st->mclk = AD7192_INT_FREQ_MHZ;
253 st->mclk = pdata->ext_clk_hz;
254 else
255 st->mclk = AD7192_INT_FREQ_MHZ;
256 break; 257 break;
258 case AD7192_CLK_EXT_MCLK1_2:
259 case AD7192_CLK_EXT_MCLK2:
260 if (ad7192_valid_external_frequency(pdata->ext_clk_hz)) {
261 st->mclk = pdata->ext_clk_hz;
262 break;
263 }
264 dev_err(&st->sd.spi->dev, "Invalid frequency setting %u\n",
265 pdata->ext_clk_hz);
266 ret = -EINVAL;
267 goto out;
257 default: 268 default:
258 ret = -EINVAL; 269 ret = -EINVAL;
259 goto out; 270 goto out;
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 2b28fb9c0048..3bcf49466361 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -648,8 +648,6 @@ static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
648 /* Ring buffer functions - here trigger setup related */ 648 /* Ring buffer functions - here trigger setup related */
649 indio_dev->setup_ops = &ad5933_ring_setup_ops; 649 indio_dev->setup_ops = &ad5933_ring_setup_ops;
650 650
651 indio_dev->modes |= INDIO_BUFFER_HARDWARE;
652
653 return 0; 651 return 0;
654} 652}
655 653
@@ -762,7 +760,7 @@ static int ad5933_probe(struct i2c_client *client,
762 indio_dev->dev.parent = &client->dev; 760 indio_dev->dev.parent = &client->dev;
763 indio_dev->info = &ad5933_info; 761 indio_dev->info = &ad5933_info;
764 indio_dev->name = id->name; 762 indio_dev->name = id->name;
765 indio_dev->modes = INDIO_DIRECT_MODE; 763 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
766 indio_dev->channels = ad5933_channels; 764 indio_dev->channels = ad5933_channels;
767 indio_dev->num_channels = ARRAY_SIZE(ad5933_channels); 765 indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
768 766
diff --git a/drivers/staging/ncpfs/ncplib_kernel.c b/drivers/staging/ncpfs/ncplib_kernel.c
index 804adfebba2f..3e047eb4cc7c 100644
--- a/drivers/staging/ncpfs/ncplib_kernel.c
+++ b/drivers/staging/ncpfs/ncplib_kernel.c
@@ -981,6 +981,10 @@ ncp_read_kernel(struct ncp_server *server, const char *file_id,
981 goto out; 981 goto out;
982 } 982 }
983 *bytes_read = ncp_reply_be16(server, 0); 983 *bytes_read = ncp_reply_be16(server, 0);
984 if (*bytes_read > to_read) {
985 result = -EINVAL;
986 goto out;
987 }
984 source = ncp_reply_data(server, 2 + (offset & 1)); 988 source = ncp_reply_data(server, 2 + (offset & 1));
985 989
986 memcpy(target, source, *bytes_read); 990 memcpy(target, source, *bytes_read);
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 5c0e59e8fe46..cbe98bc2b998 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2180,6 +2180,12 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
2180 } 2180 }
2181 if (tty_hung_up_p(file)) 2181 if (tty_hung_up_p(file))
2182 break; 2182 break;
2183 /*
2184 * Abort readers for ttys which never actually
2185 * get hung up. See __tty_hangup().
2186 */
2187 if (test_bit(TTY_HUPPING, &tty->flags))
2188 break;
2183 if (!timeout) 2189 if (!timeout)
2184 break; 2190 break;
2185 if (file->f_flags & O_NONBLOCK) { 2191 if (file->f_flags & O_NONBLOCK) {
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 54adf8d56350..a93f77ab3da0 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -3387,11 +3387,9 @@ static int serial_pci_is_class_communication(struct pci_dev *dev)
3387 /* 3387 /*
3388 * If it is not a communications device or the programming 3388 * If it is not a communications device or the programming
3389 * interface is greater than 6, give up. 3389 * interface is greater than 6, give up.
3390 *
3391 * (Should we try to make guesses for multiport serial devices
3392 * later?)
3393 */ 3390 */
3394 if ((((dev->class >> 8) != PCI_CLASS_COMMUNICATION_SERIAL) && 3391 if ((((dev->class >> 8) != PCI_CLASS_COMMUNICATION_SERIAL) &&
3392 ((dev->class >> 8) != PCI_CLASS_COMMUNICATION_MULTISERIAL) &&
3395 ((dev->class >> 8) != PCI_CLASS_COMMUNICATION_MODEM)) || 3393 ((dev->class >> 8) != PCI_CLASS_COMMUNICATION_MODEM)) ||
3396 (dev->class & 0xff) > 6) 3394 (dev->class & 0xff) > 6)
3397 return -ENODEV; 3395 return -ENODEV;
@@ -3428,6 +3426,12 @@ serial_pci_guess_board(struct pci_dev *dev, struct pciserial_board *board)
3428{ 3426{
3429 int num_iomem, num_port, first_port = -1, i; 3427 int num_iomem, num_port, first_port = -1, i;
3430 3428
3429 /*
3430 * Should we try to make guesses for multiport serial devices later?
3431 */
3432 if ((dev->class >> 8) == PCI_CLASS_COMMUNICATION_MULTISERIAL)
3433 return -ENODEV;
3434
3431 num_iomem = num_port = 0; 3435 num_iomem = num_port = 0;
3432 for (i = 0; i < PCI_NUM_BAR_RESOURCES; i++) { 3436 for (i = 0; i < PCI_NUM_BAR_RESOURCES; i++) {
3433 if (pci_resource_flags(dev, i) & IORESOURCE_IO) { 3437 if (pci_resource_flags(dev, i) & IORESOURCE_IO) {
@@ -4699,6 +4703,17 @@ static const struct pci_device_id serial_pci_tbl[] = {
4699 PCI_ANY_ID, PCI_ANY_ID, 0, 0, /* 135a.0dc0 */ 4703 PCI_ANY_ID, PCI_ANY_ID, 0, 0, /* 135a.0dc0 */
4700 pbn_b2_4_115200 }, 4704 pbn_b2_4_115200 },
4701 /* 4705 /*
4706 * BrainBoxes UC-260
4707 */
4708 { PCI_VENDOR_ID_INTASHIELD, 0x0D21,
4709 PCI_ANY_ID, PCI_ANY_ID,
4710 PCI_CLASS_COMMUNICATION_MULTISERIAL << 8, 0xffff00,
4711 pbn_b2_4_115200 },
4712 { PCI_VENDOR_ID_INTASHIELD, 0x0E34,
4713 PCI_ANY_ID, PCI_ANY_ID,
4714 PCI_CLASS_COMMUNICATION_MULTISERIAL << 8, 0xffff00,
4715 pbn_b2_4_115200 },
4716 /*
4702 * Perle PCI-RAS cards 4717 * Perle PCI-RAS cards
4703 */ 4718 */
4704 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, 4719 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index df46a9e88c34..e287fe8f10fc 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -1734,6 +1734,7 @@ static void atmel_get_ip_name(struct uart_port *port)
1734 switch (version) { 1734 switch (version) {
1735 case 0x302: 1735 case 0x302:
1736 case 0x10213: 1736 case 0x10213:
1737 case 0x10302:
1737 dev_dbg(port->dev, "This version is usart\n"); 1738 dev_dbg(port->dev, "This version is usart\n");
1738 atmel_port->has_frac_baudrate = true; 1739 atmel_port->has_frac_baudrate = true;
1739 atmel_port->has_hw_timer = true; 1740 atmel_port->has_hw_timer = true;
diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index 870e84fb6e39..a24278380fec 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -245,11 +245,12 @@ int __init of_setup_earlycon(const struct earlycon_id *match,
245 } 245 }
246 port->mapbase = addr; 246 port->mapbase = addr;
247 port->uartclk = BASE_BAUD * 16; 247 port->uartclk = BASE_BAUD * 16;
248 port->membase = earlycon_map(port->mapbase, SZ_4K);
249 248
250 val = of_get_flat_dt_prop(node, "reg-offset", NULL); 249 val = of_get_flat_dt_prop(node, "reg-offset", NULL);
251 if (val) 250 if (val)
252 port->mapbase += be32_to_cpu(*val); 251 port->mapbase += be32_to_cpu(*val);
252 port->membase = earlycon_map(port->mapbase, SZ_4K);
253
253 val = of_get_flat_dt_prop(node, "reg-shift", NULL); 254 val = of_get_flat_dt_prop(node, "reg-shift", NULL);
254 if (val) 255 if (val)
255 port->regshift = be32_to_cpu(*val); 256 port->regshift = be32_to_cpu(*val);
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 1d7ca382bc12..a33c685af990 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2093,7 +2093,7 @@ static int serial_imx_probe(struct platform_device *pdev)
2093 uart_get_rs485_mode(&pdev->dev, &sport->port.rs485); 2093 uart_get_rs485_mode(&pdev->dev, &sport->port.rs485);
2094 2094
2095 if (sport->port.rs485.flags & SER_RS485_ENABLED && 2095 if (sport->port.rs485.flags & SER_RS485_ENABLED &&
2096 (!sport->have_rtscts || !sport->have_rtsgpio)) 2096 (!sport->have_rtscts && !sport->have_rtsgpio))
2097 dev_err(&pdev->dev, "no RTS control, disabling rs485\n"); 2097 dev_err(&pdev->dev, "no RTS control, disabling rs485\n");
2098 2098
2099 imx_rs485_config(&sport->port, &sport->port.rs485); 2099 imx_rs485_config(&sport->port, &sport->port.rs485);
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index c8dde56b532b..35b9201db3b4 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1144,6 +1144,8 @@ static int uart_do_autoconfig(struct tty_struct *tty,struct uart_state *state)
1144 uport->ops->config_port(uport, flags); 1144 uport->ops->config_port(uport, flags);
1145 1145
1146 ret = uart_startup(tty, state, 1); 1146 ret = uart_startup(tty, state, 1);
1147 if (ret == 0)
1148 tty_port_set_initialized(port, true);
1147 if (ret > 0) 1149 if (ret > 0)
1148 ret = 0; 1150 ret = 0;
1149 } 1151 }
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 7257c078e155..44adf9db38f8 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -885,6 +885,8 @@ static void sci_receive_chars(struct uart_port *port)
885 /* Tell the rest of the system the news. New characters! */ 885 /* Tell the rest of the system the news. New characters! */
886 tty_flip_buffer_push(tport); 886 tty_flip_buffer_push(tport);
887 } else { 887 } else {
888 /* TTY buffers full; read from RX reg to prevent lockup */
889 serial_port_in(port, SCxRDR);
888 serial_port_in(port, SCxSR); /* dummy read */ 890 serial_port_in(port, SCxSR); /* dummy read */
889 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port)); 891 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port));
890 } 892 }
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index eb9133b472f4..63114ea35ec1 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -586,6 +586,14 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
586 return; 586 return;
587 } 587 }
588 588
589 /*
590 * Some console devices aren't actually hung up for technical and
591 * historical reasons, which can lead to indefinite interruptible
592 * sleep in n_tty_read(). The following explicitly tells
593 * n_tty_read() to abort readers.
594 */
595 set_bit(TTY_HUPPING, &tty->flags);
596
589 /* inuse_filps is protected by the single tty lock, 597 /* inuse_filps is protected by the single tty lock,
590 this really needs to change if we want to flush the 598 this really needs to change if we want to flush the
591 workqueue with the lock held */ 599 workqueue with the lock held */
@@ -640,6 +648,7 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
640 * from the ldisc side, which is now guaranteed. 648 * from the ldisc side, which is now guaranteed.
641 */ 649 */
642 set_bit(TTY_HUPPED, &tty->flags); 650 set_bit(TTY_HUPPED, &tty->flags);
651 clear_bit(TTY_HUPPING, &tty->flags);
643 tty_unlock(tty); 652 tty_unlock(tty);
644 653
645 if (f) 654 if (f)
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 88b902c525d7..b4e57c5a8bba 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -1727,7 +1727,7 @@ static void reset_terminal(struct vc_data *vc, int do_clear)
1727 default_attr(vc); 1727 default_attr(vc);
1728 update_attr(vc); 1728 update_attr(vc);
1729 1729
1730 vc->vc_tab_stop[0] = 0x01010100; 1730 vc->vc_tab_stop[0] =
1731 vc->vc_tab_stop[1] = 1731 vc->vc_tab_stop[1] =
1732 vc->vc_tab_stop[2] = 1732 vc->vc_tab_stop[2] =
1733 vc->vc_tab_stop[3] = 1733 vc->vc_tab_stop[3] =
@@ -1771,7 +1771,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
1771 vc->vc_pos -= (vc->vc_x << 1); 1771 vc->vc_pos -= (vc->vc_x << 1);
1772 while (vc->vc_x < vc->vc_cols - 1) { 1772 while (vc->vc_x < vc->vc_cols - 1) {
1773 vc->vc_x++; 1773 vc->vc_x++;
1774 if (vc->vc_tab_stop[vc->vc_x >> 5] & (1 << (vc->vc_x & 31))) 1774 if (vc->vc_tab_stop[7 & (vc->vc_x >> 5)] & (1 << (vc->vc_x & 31)))
1775 break; 1775 break;
1776 } 1776 }
1777 vc->vc_pos += (vc->vc_x << 1); 1777 vc->vc_pos += (vc->vc_x << 1);
@@ -1831,7 +1831,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
1831 lf(vc); 1831 lf(vc);
1832 return; 1832 return;
1833 case 'H': 1833 case 'H':
1834 vc->vc_tab_stop[vc->vc_x >> 5] |= (1 << (vc->vc_x & 31)); 1834 vc->vc_tab_stop[7 & (vc->vc_x >> 5)] |= (1 << (vc->vc_x & 31));
1835 return; 1835 return;
1836 case 'Z': 1836 case 'Z':
1837 respond_ID(tty); 1837 respond_ID(tty);
@@ -2024,7 +2024,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
2024 return; 2024 return;
2025 case 'g': 2025 case 'g':
2026 if (!vc->vc_par[0]) 2026 if (!vc->vc_par[0])
2027 vc->vc_tab_stop[vc->vc_x >> 5] &= ~(1 << (vc->vc_x & 31)); 2027 vc->vc_tab_stop[7 & (vc->vc_x >> 5)] &= ~(1 << (vc->vc_x & 31));
2028 else if (vc->vc_par[0] == 3) { 2028 else if (vc->vc_par[0] == 3) {
2029 vc->vc_tab_stop[0] = 2029 vc->vc_tab_stop[0] =
2030 vc->vc_tab_stop[1] = 2030 vc->vc_tab_stop[1] =
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index f699abab1787..148f3ee70286 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -19,6 +19,12 @@ config USB_EHCI_BIG_ENDIAN_MMIO
19config USB_EHCI_BIG_ENDIAN_DESC 19config USB_EHCI_BIG_ENDIAN_DESC
20 bool 20 bool
21 21
22config USB_UHCI_BIG_ENDIAN_MMIO
23 bool
24
25config USB_UHCI_BIG_ENDIAN_DESC
26 bool
27
22menuconfig USB_SUPPORT 28menuconfig USB_SUPPORT
23 bool "USB support" 29 bool "USB support"
24 depends on HAS_IOMEM 30 depends on HAS_IOMEM
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 06b3b54a0e68..7b366a6c0b49 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -174,6 +174,7 @@ static int acm_wb_alloc(struct acm *acm)
174 wb = &acm->wb[wbn]; 174 wb = &acm->wb[wbn];
175 if (!wb->use) { 175 if (!wb->use) {
176 wb->use = 1; 176 wb->use = 1;
177 wb->len = 0;
177 return wbn; 178 return wbn;
178 } 179 }
179 wbn = (wbn + 1) % ACM_NW; 180 wbn = (wbn + 1) % ACM_NW;
@@ -805,16 +806,18 @@ static int acm_tty_write(struct tty_struct *tty,
805static void acm_tty_flush_chars(struct tty_struct *tty) 806static void acm_tty_flush_chars(struct tty_struct *tty)
806{ 807{
807 struct acm *acm = tty->driver_data; 808 struct acm *acm = tty->driver_data;
808 struct acm_wb *cur = acm->putbuffer; 809 struct acm_wb *cur;
809 int err; 810 int err;
810 unsigned long flags; 811 unsigned long flags;
811 812
813 spin_lock_irqsave(&acm->write_lock, flags);
814
815 cur = acm->putbuffer;
812 if (!cur) /* nothing to do */ 816 if (!cur) /* nothing to do */
813 return; 817 goto out;
814 818
815 acm->putbuffer = NULL; 819 acm->putbuffer = NULL;
816 err = usb_autopm_get_interface_async(acm->control); 820 err = usb_autopm_get_interface_async(acm->control);
817 spin_lock_irqsave(&acm->write_lock, flags);
818 if (err < 0) { 821 if (err < 0) {
819 cur->use = 0; 822 cur->use = 0;
820 acm->putbuffer = cur; 823 acm->putbuffer = cur;
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index c64cf6c4a83d..0c11d40a12bc 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -151,6 +151,10 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
151 151
152 ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout); 152 ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
153 153
154 /* Linger a bit, prior to the next control message. */
155 if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG)
156 msleep(200);
157
154 kfree(dr); 158 kfree(dr);
155 159
156 return ret; 160 return ret;
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 4024926c1d68..54b019e267c5 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -226,8 +226,12 @@ static const struct usb_device_id usb_quirk_list[] = {
226 { USB_DEVICE(0x1a0a, 0x0200), .driver_info = 226 { USB_DEVICE(0x1a0a, 0x0200), .driver_info =
227 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL }, 227 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL },
228 228
229 /* Corsair K70 RGB */
230 { USB_DEVICE(0x1b1c, 0x1b13), .driver_info = USB_QUIRK_DELAY_INIT },
231
229 /* Corsair Strafe RGB */ 232 /* Corsair Strafe RGB */
230 { USB_DEVICE(0x1b1c, 0x1b20), .driver_info = USB_QUIRK_DELAY_INIT }, 233 { USB_DEVICE(0x1b1c, 0x1b20), .driver_info = USB_QUIRK_DELAY_INIT |
234 USB_QUIRK_DELAY_CTRL_MSG },
231 235
232 /* Corsair K70 LUX */ 236 /* Corsair K70 LUX */
233 { USB_DEVICE(0x1b1c, 0x1b36), .driver_info = USB_QUIRK_DELAY_INIT }, 237 { USB_DEVICE(0x1b1c, 0x1b36), .driver_info = USB_QUIRK_DELAY_INIT },
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index e4c3ce0de5de..5bcad1d869b5 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -1917,7 +1917,9 @@ static void dwc2_hsotg_program_zlp(struct dwc2_hsotg *hsotg,
1917 /* Not specific buffer needed for ep0 ZLP */ 1917 /* Not specific buffer needed for ep0 ZLP */
1918 dma_addr_t dma = hs_ep->desc_list_dma; 1918 dma_addr_t dma = hs_ep->desc_list_dma;
1919 1919
1920 dwc2_gadget_set_ep0_desc_chain(hsotg, hs_ep); 1920 if (!index)
1921 dwc2_gadget_set_ep0_desc_chain(hsotg, hs_ep);
1922
1921 dwc2_gadget_config_nonisoc_xfer_ddma(hs_ep, dma, 0); 1923 dwc2_gadget_config_nonisoc_xfer_ddma(hs_ep, dma, 0);
1922 } else { 1924 } else {
1923 dwc2_writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | 1925 dwc2_writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) |
@@ -2974,9 +2976,13 @@ static void dwc2_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx,
2974 if (ints & DXEPINT_STSPHSERCVD) { 2976 if (ints & DXEPINT_STSPHSERCVD) {
2975 dev_dbg(hsotg->dev, "%s: StsPhseRcvd\n", __func__); 2977 dev_dbg(hsotg->dev, "%s: StsPhseRcvd\n", __func__);
2976 2978
2977 /* Move to STATUS IN for DDMA */ 2979 /* Safety check EP0 state when STSPHSERCVD asserted */
2978 if (using_desc_dma(hsotg)) 2980 if (hsotg->ep0_state == DWC2_EP0_DATA_OUT) {
2979 dwc2_hsotg_ep0_zlp(hsotg, true); 2981 /* Move to STATUS IN for DDMA */
2982 if (using_desc_dma(hsotg))
2983 dwc2_hsotg_ep0_zlp(hsotg, true);
2984 }
2985
2980 } 2986 }
2981 2987
2982 if (ints & DXEPINT_BACK2BACKSETUP) 2988 if (ints & DXEPINT_BACK2BACKSETUP)
@@ -3375,12 +3381,6 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
3375 dwc2_writel(dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | 3381 dwc2_writel(dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) |
3376 DXEPCTL_USBACTEP, hsotg->regs + DIEPCTL0); 3382 DXEPCTL_USBACTEP, hsotg->regs + DIEPCTL0);
3377 3383
3378 dwc2_hsotg_enqueue_setup(hsotg);
3379
3380 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
3381 dwc2_readl(hsotg->regs + DIEPCTL0),
3382 dwc2_readl(hsotg->regs + DOEPCTL0));
3383
3384 /* clear global NAKs */ 3384 /* clear global NAKs */
3385 val = DCTL_CGOUTNAK | DCTL_CGNPINNAK; 3385 val = DCTL_CGOUTNAK | DCTL_CGNPINNAK;
3386 if (!is_usb_reset) 3386 if (!is_usb_reset)
@@ -3391,6 +3391,12 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
3391 mdelay(3); 3391 mdelay(3);
3392 3392
3393 hsotg->lx_state = DWC2_L0; 3393 hsotg->lx_state = DWC2_L0;
3394
3395 dwc2_hsotg_enqueue_setup(hsotg);
3396
3397 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
3398 dwc2_readl(hsotg->regs + DIEPCTL0),
3399 dwc2_readl(hsotg->regs + DOEPCTL0));
3394} 3400}
3395 3401
3396static void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) 3402static void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg)
diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index 03fd20f0b496..c4a47496d2fb 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -137,7 +137,7 @@ static void dwc2_set_stm32f4x9_fsotg_params(struct dwc2_hsotg *hsotg)
137 p->activate_stm_fs_transceiver = true; 137 p->activate_stm_fs_transceiver = true;
138} 138}
139 139
140static void dwc2_set_stm32f7xx_hsotg_params(struct dwc2_hsotg *hsotg) 140static void dwc2_set_stm32f7_hsotg_params(struct dwc2_hsotg *hsotg)
141{ 141{
142 struct dwc2_core_params *p = &hsotg->params; 142 struct dwc2_core_params *p = &hsotg->params;
143 143
@@ -164,8 +164,8 @@ const struct of_device_id dwc2_of_match_table[] = {
164 { .compatible = "st,stm32f4x9-fsotg", 164 { .compatible = "st,stm32f4x9-fsotg",
165 .data = dwc2_set_stm32f4x9_fsotg_params }, 165 .data = dwc2_set_stm32f4x9_fsotg_params },
166 { .compatible = "st,stm32f4x9-hsotg" }, 166 { .compatible = "st,stm32f4x9-hsotg" },
167 { .compatible = "st,stm32f7xx-hsotg", 167 { .compatible = "st,stm32f7-hsotg",
168 .data = dwc2_set_stm32f7xx_hsotg_params }, 168 .data = dwc2_set_stm32f7_hsotg_params },
169 {}, 169 {},
170}; 170};
171MODULE_DEVICE_TABLE(of, dwc2_of_match_table); 171MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index ade2ab00d37a..e94bf91cc58a 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -100,6 +100,8 @@ static void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
100 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG)); 100 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
101 reg |= DWC3_GCTL_PRTCAPDIR(mode); 101 reg |= DWC3_GCTL_PRTCAPDIR(mode);
102 dwc3_writel(dwc->regs, DWC3_GCTL, reg); 102 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
103
104 dwc->current_dr_role = mode;
103} 105}
104 106
105static void __dwc3_set_mode(struct work_struct *work) 107static void __dwc3_set_mode(struct work_struct *work)
@@ -133,8 +135,6 @@ static void __dwc3_set_mode(struct work_struct *work)
133 135
134 dwc3_set_prtcap(dwc, dwc->desired_dr_role); 136 dwc3_set_prtcap(dwc, dwc->desired_dr_role);
135 137
136 dwc->current_dr_role = dwc->desired_dr_role;
137
138 spin_unlock_irqrestore(&dwc->lock, flags); 138 spin_unlock_irqrestore(&dwc->lock, flags);
139 139
140 switch (dwc->desired_dr_role) { 140 switch (dwc->desired_dr_role) {
@@ -175,7 +175,7 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
175 dwc->desired_dr_role = mode; 175 dwc->desired_dr_role = mode;
176 spin_unlock_irqrestore(&dwc->lock, flags); 176 spin_unlock_irqrestore(&dwc->lock, flags);
177 177
178 queue_work(system_power_efficient_wq, &dwc->drd_work); 178 queue_work(system_freezable_wq, &dwc->drd_work);
179} 179}
180 180
181u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type) 181u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
@@ -219,7 +219,7 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
219 * XHCI driver will reset the host block. If dwc3 was configured for 219 * XHCI driver will reset the host block. If dwc3 was configured for
220 * host-only mode, then we can return early. 220 * host-only mode, then we can return early.
221 */ 221 */
222 if (dwc->dr_mode == USB_DR_MODE_HOST) 222 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST)
223 return 0; 223 return 0;
224 224
225 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 225 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
@@ -234,6 +234,9 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
234 udelay(1); 234 udelay(1);
235 } while (--retries); 235 } while (--retries);
236 236
237 phy_exit(dwc->usb3_generic_phy);
238 phy_exit(dwc->usb2_generic_phy);
239
237 return -ETIMEDOUT; 240 return -ETIMEDOUT;
238} 241}
239 242
@@ -483,6 +486,22 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc)
483 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); 486 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
484} 487}
485 488
489static int dwc3_core_ulpi_init(struct dwc3 *dwc)
490{
491 int intf;
492 int ret = 0;
493
494 intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3);
495
496 if (intf == DWC3_GHWPARAMS3_HSPHY_IFC_ULPI ||
497 (intf == DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI &&
498 dwc->hsphy_interface &&
499 !strncmp(dwc->hsphy_interface, "ulpi", 4)))
500 ret = dwc3_ulpi_init(dwc);
501
502 return ret;
503}
504
486/** 505/**
487 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core 506 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
488 * @dwc: Pointer to our controller context structure 507 * @dwc: Pointer to our controller context structure
@@ -494,7 +513,6 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc)
494static int dwc3_phy_setup(struct dwc3 *dwc) 513static int dwc3_phy_setup(struct dwc3 *dwc)
495{ 514{
496 u32 reg; 515 u32 reg;
497 int ret;
498 516
499 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); 517 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
500 518
@@ -565,9 +583,6 @@ static int dwc3_phy_setup(struct dwc3 *dwc)
565 } 583 }
566 /* FALLTHROUGH */ 584 /* FALLTHROUGH */
567 case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI: 585 case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
568 ret = dwc3_ulpi_init(dwc);
569 if (ret)
570 return ret;
571 /* FALLTHROUGH */ 586 /* FALLTHROUGH */
572 default: 587 default:
573 break; 588 break;
@@ -724,6 +739,7 @@ static void dwc3_core_setup_global_control(struct dwc3 *dwc)
724} 739}
725 740
726static int dwc3_core_get_phy(struct dwc3 *dwc); 741static int dwc3_core_get_phy(struct dwc3 *dwc);
742static int dwc3_core_ulpi_init(struct dwc3 *dwc);
727 743
728/** 744/**
729 * dwc3_core_init - Low-level initialization of DWC3 Core 745 * dwc3_core_init - Low-level initialization of DWC3 Core
@@ -755,17 +771,27 @@ static int dwc3_core_init(struct dwc3 *dwc)
755 dwc->maximum_speed = USB_SPEED_HIGH; 771 dwc->maximum_speed = USB_SPEED_HIGH;
756 } 772 }
757 773
758 ret = dwc3_core_get_phy(dwc); 774 ret = dwc3_phy_setup(dwc);
759 if (ret) 775 if (ret)
760 goto err0; 776 goto err0;
761 777
762 ret = dwc3_core_soft_reset(dwc); 778 if (!dwc->ulpi_ready) {
763 if (ret) 779 ret = dwc3_core_ulpi_init(dwc);
764 goto err0; 780 if (ret)
781 goto err0;
782 dwc->ulpi_ready = true;
783 }
765 784
766 ret = dwc3_phy_setup(dwc); 785 if (!dwc->phys_ready) {
786 ret = dwc3_core_get_phy(dwc);
787 if (ret)
788 goto err0a;
789 dwc->phys_ready = true;
790 }
791
792 ret = dwc3_core_soft_reset(dwc);
767 if (ret) 793 if (ret)
768 goto err0; 794 goto err0a;
769 795
770 dwc3_core_setup_global_control(dwc); 796 dwc3_core_setup_global_control(dwc);
771 dwc3_core_num_eps(dwc); 797 dwc3_core_num_eps(dwc);
@@ -838,6 +864,9 @@ err1:
838 phy_exit(dwc->usb2_generic_phy); 864 phy_exit(dwc->usb2_generic_phy);
839 phy_exit(dwc->usb3_generic_phy); 865 phy_exit(dwc->usb3_generic_phy);
840 866
867err0a:
868 dwc3_ulpi_exit(dwc);
869
841err0: 870err0:
842 return ret; 871 return ret;
843} 872}
@@ -916,7 +945,6 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
916 945
917 switch (dwc->dr_mode) { 946 switch (dwc->dr_mode) {
918 case USB_DR_MODE_PERIPHERAL: 947 case USB_DR_MODE_PERIPHERAL:
919 dwc->current_dr_role = DWC3_GCTL_PRTCAP_DEVICE;
920 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); 948 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
921 949
922 if (dwc->usb2_phy) 950 if (dwc->usb2_phy)
@@ -932,7 +960,6 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
932 } 960 }
933 break; 961 break;
934 case USB_DR_MODE_HOST: 962 case USB_DR_MODE_HOST:
935 dwc->current_dr_role = DWC3_GCTL_PRTCAP_HOST;
936 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); 963 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
937 964
938 if (dwc->usb2_phy) 965 if (dwc->usb2_phy)
@@ -1234,7 +1261,6 @@ err4:
1234 1261
1235err3: 1262err3:
1236 dwc3_free_event_buffers(dwc); 1263 dwc3_free_event_buffers(dwc);
1237 dwc3_ulpi_exit(dwc);
1238 1264
1239err2: 1265err2:
1240 pm_runtime_allow(&pdev->dev); 1266 pm_runtime_allow(&pdev->dev);
@@ -1284,7 +1310,7 @@ static int dwc3_remove(struct platform_device *pdev)
1284} 1310}
1285 1311
1286#ifdef CONFIG_PM 1312#ifdef CONFIG_PM
1287static int dwc3_suspend_common(struct dwc3 *dwc) 1313static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
1288{ 1314{
1289 unsigned long flags; 1315 unsigned long flags;
1290 1316
@@ -1296,6 +1322,10 @@ static int dwc3_suspend_common(struct dwc3 *dwc)
1296 dwc3_core_exit(dwc); 1322 dwc3_core_exit(dwc);
1297 break; 1323 break;
1298 case DWC3_GCTL_PRTCAP_HOST: 1324 case DWC3_GCTL_PRTCAP_HOST:
1325 /* do nothing during host runtime_suspend */
1326 if (!PMSG_IS_AUTO(msg))
1327 dwc3_core_exit(dwc);
1328 break;
1299 default: 1329 default:
1300 /* do nothing */ 1330 /* do nothing */
1301 break; 1331 break;
@@ -1304,7 +1334,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc)
1304 return 0; 1334 return 0;
1305} 1335}
1306 1336
1307static int dwc3_resume_common(struct dwc3 *dwc) 1337static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
1308{ 1338{
1309 unsigned long flags; 1339 unsigned long flags;
1310 int ret; 1340 int ret;
@@ -1320,6 +1350,13 @@ static int dwc3_resume_common(struct dwc3 *dwc)
1320 spin_unlock_irqrestore(&dwc->lock, flags); 1350 spin_unlock_irqrestore(&dwc->lock, flags);
1321 break; 1351 break;
1322 case DWC3_GCTL_PRTCAP_HOST: 1352 case DWC3_GCTL_PRTCAP_HOST:
1353 /* nothing to do on host runtime_resume */
1354 if (!PMSG_IS_AUTO(msg)) {
1355 ret = dwc3_core_init(dwc);
1356 if (ret)
1357 return ret;
1358 }
1359 break;
1323 default: 1360 default:
1324 /* do nothing */ 1361 /* do nothing */
1325 break; 1362 break;
@@ -1331,12 +1368,11 @@ static int dwc3_resume_common(struct dwc3 *dwc)
1331static int dwc3_runtime_checks(struct dwc3 *dwc) 1368static int dwc3_runtime_checks(struct dwc3 *dwc)
1332{ 1369{
1333 switch (dwc->current_dr_role) { 1370 switch (dwc->current_dr_role) {
1334 case USB_DR_MODE_PERIPHERAL: 1371 case DWC3_GCTL_PRTCAP_DEVICE:
1335 case USB_DR_MODE_OTG:
1336 if (dwc->connected) 1372 if (dwc->connected)
1337 return -EBUSY; 1373 return -EBUSY;
1338 break; 1374 break;
1339 case USB_DR_MODE_HOST: 1375 case DWC3_GCTL_PRTCAP_HOST:
1340 default: 1376 default:
1341 /* do nothing */ 1377 /* do nothing */
1342 break; 1378 break;
@@ -1353,7 +1389,7 @@ static int dwc3_runtime_suspend(struct device *dev)
1353 if (dwc3_runtime_checks(dwc)) 1389 if (dwc3_runtime_checks(dwc))
1354 return -EBUSY; 1390 return -EBUSY;
1355 1391
1356 ret = dwc3_suspend_common(dwc); 1392 ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND);
1357 if (ret) 1393 if (ret)
1358 return ret; 1394 return ret;
1359 1395
@@ -1369,7 +1405,7 @@ static int dwc3_runtime_resume(struct device *dev)
1369 1405
1370 device_init_wakeup(dev, false); 1406 device_init_wakeup(dev, false);
1371 1407
1372 ret = dwc3_resume_common(dwc); 1408 ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME);
1373 if (ret) 1409 if (ret)
1374 return ret; 1410 return ret;
1375 1411
@@ -1416,7 +1452,7 @@ static int dwc3_suspend(struct device *dev)
1416 struct dwc3 *dwc = dev_get_drvdata(dev); 1452 struct dwc3 *dwc = dev_get_drvdata(dev);
1417 int ret; 1453 int ret;
1418 1454
1419 ret = dwc3_suspend_common(dwc); 1455 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND);
1420 if (ret) 1456 if (ret)
1421 return ret; 1457 return ret;
1422 1458
@@ -1432,7 +1468,7 @@ static int dwc3_resume(struct device *dev)
1432 1468
1433 pinctrl_pm_select_default_state(dev); 1469 pinctrl_pm_select_default_state(dev);
1434 1470
1435 ret = dwc3_resume_common(dwc); 1471 ret = dwc3_resume_common(dwc, PMSG_RESUME);
1436 if (ret) 1472 if (ret)
1437 return ret; 1473 return ret;
1438 1474
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 03c7aaaac926..860d2bc184d1 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -158,13 +158,15 @@
158#define DWC3_GDBGFIFOSPACE_TYPE(n) (((n) << 5) & 0x1e0) 158#define DWC3_GDBGFIFOSPACE_TYPE(n) (((n) << 5) & 0x1e0)
159#define DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(n) (((n) >> 16) & 0xffff) 159#define DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(n) (((n) >> 16) & 0xffff)
160 160
161#define DWC3_TXFIFOQ 1 161#define DWC3_TXFIFOQ 0
162#define DWC3_RXFIFOQ 3 162#define DWC3_RXFIFOQ 1
163#define DWC3_TXREQQ 5 163#define DWC3_TXREQQ 2
164#define DWC3_RXREQQ 7 164#define DWC3_RXREQQ 3
165#define DWC3_RXINFOQ 9 165#define DWC3_RXINFOQ 4
166#define DWC3_DESCFETCHQ 13 166#define DWC3_PSTATQ 5
167#define DWC3_EVENTQ 15 167#define DWC3_DESCFETCHQ 6
168#define DWC3_EVENTQ 7
169#define DWC3_AUXEVENTQ 8
168 170
169/* Global RX Threshold Configuration Register */ 171/* Global RX Threshold Configuration Register */
170#define DWC3_GRXTHRCFG_MAXRXBURSTSIZE(n) (((n) & 0x1f) << 19) 172#define DWC3_GRXTHRCFG_MAXRXBURSTSIZE(n) (((n) & 0x1f) << 19)
@@ -795,7 +797,9 @@ struct dwc3_scratchpad_array {
795 * @usb3_phy: pointer to USB3 PHY 797 * @usb3_phy: pointer to USB3 PHY
796 * @usb2_generic_phy: pointer to USB2 PHY 798 * @usb2_generic_phy: pointer to USB2 PHY
797 * @usb3_generic_phy: pointer to USB3 PHY 799 * @usb3_generic_phy: pointer to USB3 PHY
800 * @phys_ready: flag to indicate that PHYs are ready
798 * @ulpi: pointer to ulpi interface 801 * @ulpi: pointer to ulpi interface
802 * @ulpi_ready: flag to indicate that ULPI is initialized
799 * @u2sel: parameter from Set SEL request. 803 * @u2sel: parameter from Set SEL request.
800 * @u2pel: parameter from Set SEL request. 804 * @u2pel: parameter from Set SEL request.
801 * @u1sel: parameter from Set SEL request. 805 * @u1sel: parameter from Set SEL request.
@@ -893,7 +897,10 @@ struct dwc3 {
893 struct phy *usb2_generic_phy; 897 struct phy *usb2_generic_phy;
894 struct phy *usb3_generic_phy; 898 struct phy *usb3_generic_phy;
895 899
900 bool phys_ready;
901
896 struct ulpi *ulpi; 902 struct ulpi *ulpi;
903 bool ulpi_ready;
897 904
898 void __iomem *regs; 905 void __iomem *regs;
899 size_t regs_size; 906 size_t regs_size;
diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c
index 7ae0eefc7cc7..e54c3622eb28 100644
--- a/drivers/usb/dwc3/dwc3-of-simple.c
+++ b/drivers/usb/dwc3/dwc3-of-simple.c
@@ -143,6 +143,7 @@ static int dwc3_of_simple_remove(struct platform_device *pdev)
143 clk_disable_unprepare(simple->clks[i]); 143 clk_disable_unprepare(simple->clks[i]);
144 clk_put(simple->clks[i]); 144 clk_put(simple->clks[i]);
145 } 145 }
146 simple->num_clocks = 0;
146 147
147 reset_control_assert(simple->resets); 148 reset_control_assert(simple->resets);
148 reset_control_put(simple->resets); 149 reset_control_put(simple->resets);
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index a4719e853b85..ed8b86517675 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -582,9 +582,25 @@ static int dwc3_omap_resume(struct device *dev)
582 return 0; 582 return 0;
583} 583}
584 584
585static void dwc3_omap_complete(struct device *dev)
586{
587 struct dwc3_omap *omap = dev_get_drvdata(dev);
588
589 if (extcon_get_state(omap->edev, EXTCON_USB))
590 dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
591 else
592 dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF);
593
594 if (extcon_get_state(omap->edev, EXTCON_USB_HOST))
595 dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
596 else
597 dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT);
598}
599
585static const struct dev_pm_ops dwc3_omap_dev_pm_ops = { 600static const struct dev_pm_ops dwc3_omap_dev_pm_ops = {
586 601
587 SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume) 602 SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume)
603 .complete = dwc3_omap_complete,
588}; 604};
589 605
590#define DEV_PM_OPS (&dwc3_omap_dev_pm_ops) 606#define DEV_PM_OPS (&dwc3_omap_dev_pm_ops)
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 9c2e4a17918e..18be31d5743a 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -854,7 +854,12 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
854 trb++; 854 trb++;
855 trb->ctrl &= ~DWC3_TRB_CTRL_HWO; 855 trb->ctrl &= ~DWC3_TRB_CTRL_HWO;
856 trace_dwc3_complete_trb(ep0, trb); 856 trace_dwc3_complete_trb(ep0, trb);
857 ep0->trb_enqueue = 0; 857
858 if (r->direction)
859 dwc->eps[1]->trb_enqueue = 0;
860 else
861 dwc->eps[0]->trb_enqueue = 0;
862
858 dwc->ep0_bounced = false; 863 dwc->ep0_bounced = false;
859 } 864 }
860 865
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 616ef49ccb49..2bda4eb1e9ac 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2745,6 +2745,8 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
2745 break; 2745 break;
2746 } 2746 }
2747 2747
2748 dwc->eps[1]->endpoint.maxpacket = dwc->gadget.ep0->maxpacket;
2749
2748 /* Enable USB2 LPM Capability */ 2750 /* Enable USB2 LPM Capability */
2749 2751
2750 if ((dwc->revision > DWC3_REVISION_194A) && 2752 if ((dwc->revision > DWC3_REVISION_194A) &&
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 8f2cf3baa19c..d2428a9e8900 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -1538,7 +1538,6 @@ ffs_fs_kill_sb(struct super_block *sb)
1538 if (sb->s_fs_info) { 1538 if (sb->s_fs_info) {
1539 ffs_release_dev(sb->s_fs_info); 1539 ffs_release_dev(sb->s_fs_info);
1540 ffs_data_closed(sb->s_fs_info); 1540 ffs_data_closed(sb->s_fs_info);
1541 ffs_data_put(sb->s_fs_info);
1542 } 1541 }
1543} 1542}
1544 1543
@@ -1855,44 +1854,20 @@ static int ffs_func_eps_enable(struct ffs_function *func)
1855 1854
1856 spin_lock_irqsave(&func->ffs->eps_lock, flags); 1855 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1857 while(count--) { 1856 while(count--) {
1858 struct usb_endpoint_descriptor *ds;
1859 struct usb_ss_ep_comp_descriptor *comp_desc = NULL;
1860 int needs_comp_desc = false;
1861 int desc_idx;
1862
1863 if (ffs->gadget->speed == USB_SPEED_SUPER) {
1864 desc_idx = 2;
1865 needs_comp_desc = true;
1866 } else if (ffs->gadget->speed == USB_SPEED_HIGH)
1867 desc_idx = 1;
1868 else
1869 desc_idx = 0;
1870
1871 /* fall-back to lower speed if desc missing for current speed */
1872 do {
1873 ds = ep->descs[desc_idx];
1874 } while (!ds && --desc_idx >= 0);
1875
1876 if (!ds) {
1877 ret = -EINVAL;
1878 break;
1879 }
1880
1881 ep->ep->driver_data = ep; 1857 ep->ep->driver_data = ep;
1882 ep->ep->desc = ds;
1883 1858
1884 if (needs_comp_desc) { 1859 ret = config_ep_by_speed(func->gadget, &func->function, ep->ep);
1885 comp_desc = (struct usb_ss_ep_comp_descriptor *)(ds + 1860 if (ret) {
1886 USB_DT_ENDPOINT_SIZE); 1861 pr_err("%s: config_ep_by_speed(%s) returned %d\n",
1887 ep->ep->maxburst = comp_desc->bMaxBurst + 1; 1862 __func__, ep->ep->name, ret);
1888 ep->ep->comp_desc = comp_desc; 1863 break;
1889 } 1864 }
1890 1865
1891 ret = usb_ep_enable(ep->ep); 1866 ret = usb_ep_enable(ep->ep);
1892 if (likely(!ret)) { 1867 if (likely(!ret)) {
1893 epfile->ep = ep; 1868 epfile->ep = ep;
1894 epfile->in = usb_endpoint_dir_in(ds); 1869 epfile->in = usb_endpoint_dir_in(ep->ep->desc);
1895 epfile->isoc = usb_endpoint_xfer_isoc(ds); 1870 epfile->isoc = usb_endpoint_xfer_isoc(ep->ep->desc);
1896 } else { 1871 } else {
1897 break; 1872 break;
1898 } 1873 }
@@ -2979,10 +2954,8 @@ static int _ffs_func_bind(struct usb_configuration *c,
2979 struct ffs_data *ffs = func->ffs; 2954 struct ffs_data *ffs = func->ffs;
2980 2955
2981 const int full = !!func->ffs->fs_descs_count; 2956 const int full = !!func->ffs->fs_descs_count;
2982 const int high = gadget_is_dualspeed(func->gadget) && 2957 const int high = !!func->ffs->hs_descs_count;
2983 func->ffs->hs_descs_count; 2958 const int super = !!func->ffs->ss_descs_count;
2984 const int super = gadget_is_superspeed(func->gadget) &&
2985 func->ffs->ss_descs_count;
2986 2959
2987 int fs_len, hs_len, ss_len, ret, i; 2960 int fs_len, hs_len, ss_len, ret, i;
2988 struct ffs_ep *eps_ptr; 2961 struct ffs_ep *eps_ptr;
diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index 11fe788b4308..d2dc1f00180b 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -524,6 +524,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
524 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 524 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
525 return ret; 525 return ret;
526 } 526 }
527 iad_desc.bFirstInterface = ret;
528
527 std_ac_if_desc.bInterfaceNumber = ret; 529 std_ac_if_desc.bInterfaceNumber = ret;
528 uac2->ac_intf = ret; 530 uac2->ac_intf = ret;
529 uac2->ac_alt = 0; 531 uac2->ac_alt = 0;
diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 1e9567091d86..0875d38476ee 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -274,7 +274,6 @@ config USB_SNP_UDC_PLAT
274 tristate "Synopsys USB 2.0 Device controller" 274 tristate "Synopsys USB 2.0 Device controller"
275 depends on USB_GADGET && OF && HAS_DMA 275 depends on USB_GADGET && OF && HAS_DMA
276 depends on EXTCON || EXTCON=n 276 depends on EXTCON || EXTCON=n
277 select USB_GADGET_DUALSPEED
278 select USB_SNP_CORE 277 select USB_SNP_CORE
279 default ARCH_BCM_IPROC 278 default ARCH_BCM_IPROC
280 help 279 help
diff --git a/drivers/usb/gadget/udc/bdc/bdc_pci.c b/drivers/usb/gadget/udc/bdc/bdc_pci.c
index 1e940f054cb8..6dbc489513cd 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_pci.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_pci.c
@@ -77,6 +77,7 @@ static int bdc_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
77 if (ret) { 77 if (ret) {
78 dev_err(&pci->dev, 78 dev_err(&pci->dev,
79 "couldn't add resources to bdc device\n"); 79 "couldn't add resources to bdc device\n");
80 platform_device_put(bdc);
80 return ret; 81 return ret;
81 } 82 }
82 83
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 859d5b11ba4c..1f8b19d9cf97 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -180,8 +180,8 @@ EXPORT_SYMBOL_GPL(usb_ep_alloc_request);
180void usb_ep_free_request(struct usb_ep *ep, 180void usb_ep_free_request(struct usb_ep *ep,
181 struct usb_request *req) 181 struct usb_request *req)
182{ 182{
183 ep->ops->free_request(ep, req);
184 trace_usb_ep_free_request(ep, req, 0); 183 trace_usb_ep_free_request(ep, req, 0);
184 ep->ops->free_request(ep, req);
185} 185}
186EXPORT_SYMBOL_GPL(usb_ep_free_request); 186EXPORT_SYMBOL_GPL(usb_ep_free_request);
187 187
diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c b/drivers/usb/gadget/udc/fsl_udc_core.c
index e5b4ee96c4bf..56b517a38865 100644
--- a/drivers/usb/gadget/udc/fsl_udc_core.c
+++ b/drivers/usb/gadget/udc/fsl_udc_core.c
@@ -1305,7 +1305,7 @@ static void udc_reset_ep_queue(struct fsl_udc *udc, u8 pipe)
1305{ 1305{
1306 struct fsl_ep *ep = get_ep_by_pipe(udc, pipe); 1306 struct fsl_ep *ep = get_ep_by_pipe(udc, pipe);
1307 1307
1308 if (ep->name) 1308 if (ep->ep.name)
1309 nuke(ep, -ESHUTDOWN); 1309 nuke(ep, -ESHUTDOWN);
1310} 1310}
1311 1311
@@ -1693,7 +1693,7 @@ static void dtd_complete_irq(struct fsl_udc *udc)
1693 curr_ep = get_ep_by_pipe(udc, i); 1693 curr_ep = get_ep_by_pipe(udc, i);
1694 1694
1695 /* If the ep is configured */ 1695 /* If the ep is configured */
1696 if (curr_ep->name == NULL) { 1696 if (!curr_ep->ep.name) {
1697 WARNING("Invalid EP?"); 1697 WARNING("Invalid EP?");
1698 continue; 1698 continue;
1699 } 1699 }
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c
index 6e87af248367..409cde4e6a51 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -2410,7 +2410,7 @@ static int renesas_usb3_remove(struct platform_device *pdev)
2410 __renesas_usb3_ep_free_request(usb3->ep0_req); 2410 __renesas_usb3_ep_free_request(usb3->ep0_req);
2411 if (usb3->phy) 2411 if (usb3->phy)
2412 phy_put(usb3->phy); 2412 phy_put(usb3->phy);
2413 pm_runtime_disable(usb3_to_dev(usb3)); 2413 pm_runtime_disable(&pdev->dev);
2414 2414
2415 return 0; 2415 return 0;
2416} 2416}
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 6150bed7cfa8..4fcfb3084b36 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -633,14 +633,6 @@ config USB_UHCI_ASPEED
633 bool 633 bool
634 default y if ARCH_ASPEED 634 default y if ARCH_ASPEED
635 635
636config USB_UHCI_BIG_ENDIAN_MMIO
637 bool
638 default y if SPARC_LEON
639
640config USB_UHCI_BIG_ENDIAN_DESC
641 bool
642 default y if SPARC_LEON
643
644config USB_FHCI_HCD 636config USB_FHCI_HCD
645 tristate "Freescale QE USB Host Controller support" 637 tristate "Freescale QE USB Host Controller support"
646 depends on OF_GPIO && QE_GPIO && QUICC_ENGINE 638 depends on OF_GPIO && QE_GPIO && QUICC_ENGINE
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index facafdf8fb95..d7641cbdee43 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -774,12 +774,12 @@ static struct urb *request_single_step_set_feature_urb(
774 atomic_inc(&urb->use_count); 774 atomic_inc(&urb->use_count);
775 atomic_inc(&urb->dev->urbnum); 775 atomic_inc(&urb->dev->urbnum);
776 urb->setup_dma = dma_map_single( 776 urb->setup_dma = dma_map_single(
777 hcd->self.controller, 777 hcd->self.sysdev,
778 urb->setup_packet, 778 urb->setup_packet,
779 sizeof(struct usb_ctrlrequest), 779 sizeof(struct usb_ctrlrequest),
780 DMA_TO_DEVICE); 780 DMA_TO_DEVICE);
781 urb->transfer_dma = dma_map_single( 781 urb->transfer_dma = dma_map_single(
782 hcd->self.controller, 782 hcd->self.sysdev,
783 urb->transfer_buffer, 783 urb->transfer_buffer,
784 urb->transfer_buffer_length, 784 urb->transfer_buffer_length,
785 DMA_FROM_DEVICE); 785 DMA_FROM_DEVICE);
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 88158324dcae..327630405695 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1188,10 +1188,10 @@ static int submit_single_step_set_feature(
1188 * 15 secs after the setup 1188 * 15 secs after the setup
1189 */ 1189 */
1190 if (is_setup) { 1190 if (is_setup) {
1191 /* SETUP pid */ 1191 /* SETUP pid, and interrupt after SETUP completion */
1192 qtd_fill(ehci, qtd, urb->setup_dma, 1192 qtd_fill(ehci, qtd, urb->setup_dma,
1193 sizeof(struct usb_ctrlrequest), 1193 sizeof(struct usb_ctrlrequest),
1194 token | (2 /* "setup" */ << 8), 8); 1194 QTD_IOC | token | (2 /* "setup" */ << 8), 8);
1195 1195
1196 submit_async(ehci, urb, &qtd_list, GFP_ATOMIC); 1196 submit_async(ehci, urb, &qtd_list, GFP_ATOMIC);
1197 return 0; /*Return now; we shall come back after 15 seconds*/ 1197 return 0; /*Return now; we shall come back after 15 seconds*/
@@ -1228,12 +1228,8 @@ static int submit_single_step_set_feature(
1228 qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma); 1228 qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma);
1229 list_add_tail(&qtd->qtd_list, head); 1229 list_add_tail(&qtd->qtd_list, head);
1230 1230
1231 /* dont fill any data in such packets */ 1231 /* Interrupt after STATUS completion */
1232 qtd_fill(ehci, qtd, 0, 0, token, 0); 1232 qtd_fill(ehci, qtd, 0, 0, token | QTD_IOC, 0);
1233
1234 /* by default, enable interrupt on urb completion */
1235 if (likely(!(urb->transfer_flags & URB_NO_INTERRUPT)))
1236 qtd->hw_token |= cpu_to_hc32(ehci, QTD_IOC);
1237 1233
1238 submit_async(ehci, urb, &qtd_list, GFP_KERNEL); 1234 submit_async(ehci, urb, &qtd_list, GFP_KERNEL);
1239 1235
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index ee9676349333..d088c340e4d0 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -74,6 +74,7 @@ static const char hcd_name [] = "ohci_hcd";
74 74
75#define STATECHANGE_DELAY msecs_to_jiffies(300) 75#define STATECHANGE_DELAY msecs_to_jiffies(300)
76#define IO_WATCHDOG_DELAY msecs_to_jiffies(275) 76#define IO_WATCHDOG_DELAY msecs_to_jiffies(275)
77#define IO_WATCHDOG_OFF 0xffffff00
77 78
78#include "ohci.h" 79#include "ohci.h"
79#include "pci-quirks.h" 80#include "pci-quirks.h"
@@ -231,7 +232,7 @@ static int ohci_urb_enqueue (
231 } 232 }
232 233
233 /* Start up the I/O watchdog timer, if it's not running */ 234 /* Start up the I/O watchdog timer, if it's not running */
234 if (!timer_pending(&ohci->io_watchdog) && 235 if (ohci->prev_frame_no == IO_WATCHDOG_OFF &&
235 list_empty(&ohci->eds_in_use) && 236 list_empty(&ohci->eds_in_use) &&
236 !(ohci->flags & OHCI_QUIRK_QEMU)) { 237 !(ohci->flags & OHCI_QUIRK_QEMU)) {
237 ohci->prev_frame_no = ohci_frame_no(ohci); 238 ohci->prev_frame_no = ohci_frame_no(ohci);
@@ -446,7 +447,8 @@ static int ohci_init (struct ohci_hcd *ohci)
446 struct usb_hcd *hcd = ohci_to_hcd(ohci); 447 struct usb_hcd *hcd = ohci_to_hcd(ohci);
447 448
448 /* Accept arbitrarily long scatter-gather lists */ 449 /* Accept arbitrarily long scatter-gather lists */
449 hcd->self.sg_tablesize = ~0; 450 if (!(hcd->driver->flags & HCD_LOCAL_MEM))
451 hcd->self.sg_tablesize = ~0;
450 452
451 if (distrust_firmware) 453 if (distrust_firmware)
452 ohci->flags |= OHCI_QUIRK_HUB_POWER; 454 ohci->flags |= OHCI_QUIRK_HUB_POWER;
@@ -501,6 +503,7 @@ static int ohci_init (struct ohci_hcd *ohci)
501 return 0; 503 return 0;
502 504
503 timer_setup(&ohci->io_watchdog, io_watchdog_func, 0); 505 timer_setup(&ohci->io_watchdog, io_watchdog_func, 0);
506 ohci->prev_frame_no = IO_WATCHDOG_OFF;
504 507
505 ohci->hcca = dma_alloc_coherent (hcd->self.controller, 508 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
506 sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL); 509 sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL);
@@ -730,7 +733,7 @@ static void io_watchdog_func(struct timer_list *t)
730 u32 head; 733 u32 head;
731 struct ed *ed; 734 struct ed *ed;
732 struct td *td, *td_start, *td_next; 735 struct td *td, *td_start, *td_next;
733 unsigned frame_no; 736 unsigned frame_no, prev_frame_no = IO_WATCHDOG_OFF;
734 unsigned long flags; 737 unsigned long flags;
735 738
736 spin_lock_irqsave(&ohci->lock, flags); 739 spin_lock_irqsave(&ohci->lock, flags);
@@ -835,7 +838,7 @@ static void io_watchdog_func(struct timer_list *t)
835 } 838 }
836 } 839 }
837 if (!list_empty(&ohci->eds_in_use)) { 840 if (!list_empty(&ohci->eds_in_use)) {
838 ohci->prev_frame_no = frame_no; 841 prev_frame_no = frame_no;
839 ohci->prev_wdh_cnt = ohci->wdh_cnt; 842 ohci->prev_wdh_cnt = ohci->wdh_cnt;
840 ohci->prev_donehead = ohci_readl(ohci, 843 ohci->prev_donehead = ohci_readl(ohci,
841 &ohci->regs->donehead); 844 &ohci->regs->donehead);
@@ -845,6 +848,7 @@ static void io_watchdog_func(struct timer_list *t)
845 } 848 }
846 849
847 done: 850 done:
851 ohci->prev_frame_no = prev_frame_no;
848 spin_unlock_irqrestore(&ohci->lock, flags); 852 spin_unlock_irqrestore(&ohci->lock, flags);
849} 853}
850 854
@@ -973,6 +977,7 @@ static void ohci_stop (struct usb_hcd *hcd)
973 if (quirk_nec(ohci)) 977 if (quirk_nec(ohci))
974 flush_work(&ohci->nec_work); 978 flush_work(&ohci->nec_work);
975 del_timer_sync(&ohci->io_watchdog); 979 del_timer_sync(&ohci->io_watchdog);
980 ohci->prev_frame_no = IO_WATCHDOG_OFF;
976 981
977 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 982 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
978 ohci_usb_reset(ohci); 983 ohci_usb_reset(ohci);
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index fb7aaa3b9d06..634f3c7bf774 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -311,8 +311,10 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
311 rc = ohci_rh_suspend (ohci, 0); 311 rc = ohci_rh_suspend (ohci, 0);
312 spin_unlock_irq (&ohci->lock); 312 spin_unlock_irq (&ohci->lock);
313 313
314 if (rc == 0) 314 if (rc == 0) {
315 del_timer_sync(&ohci->io_watchdog); 315 del_timer_sync(&ohci->io_watchdog);
316 ohci->prev_frame_no = IO_WATCHDOG_OFF;
317 }
316 return rc; 318 return rc;
317} 319}
318 320
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index b2ec8c399363..4ccb85a67bb3 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -1019,6 +1019,8 @@ skip_ed:
1019 * have modified this list. normally it's just prepending 1019 * have modified this list. normally it's just prepending
1020 * entries (which we'd ignore), but paranoia won't hurt. 1020 * entries (which we'd ignore), but paranoia won't hurt.
1021 */ 1021 */
1022 *last = ed->ed_next;
1023 ed->ed_next = NULL;
1022 modified = 0; 1024 modified = 0;
1023 1025
1024 /* unlink urbs as requested, but rescan the list after 1026 /* unlink urbs as requested, but rescan the list after
@@ -1077,21 +1079,22 @@ rescan_this:
1077 goto rescan_this; 1079 goto rescan_this;
1078 1080
1079 /* 1081 /*
1080 * If no TDs are queued, take ED off the ed_rm_list. 1082 * If no TDs are queued, ED is now idle.
1081 * Otherwise, if the HC is running, reschedule. 1083 * Otherwise, if the HC is running, reschedule.
1082 * If not, leave it on the list for further dequeues. 1084 * If the HC isn't running, add ED back to the
1085 * start of the list for later processing.
1083 */ 1086 */
1084 if (list_empty(&ed->td_list)) { 1087 if (list_empty(&ed->td_list)) {
1085 *last = ed->ed_next;
1086 ed->ed_next = NULL;
1087 ed->state = ED_IDLE; 1088 ed->state = ED_IDLE;
1088 list_del(&ed->in_use_list); 1089 list_del(&ed->in_use_list);
1089 } else if (ohci->rh_state == OHCI_RH_RUNNING) { 1090 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
1090 *last = ed->ed_next;
1091 ed->ed_next = NULL;
1092 ed_schedule(ohci, ed); 1091 ed_schedule(ohci, ed);
1093 } else { 1092 } else {
1094 last = &ed->ed_next; 1093 ed->ed_next = ohci->ed_rm_list;
1094 ohci->ed_rm_list = ed;
1095 /* Don't loop on the same ED */
1096 if (last == &ohci->ed_rm_list)
1097 last = &ed->ed_next;
1095 } 1098 }
1096 1099
1097 if (modified) 1100 if (modified)
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 161536717025..67ad4bb6919a 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -66,6 +66,23 @@
66#define AX_INDXC 0x30 66#define AX_INDXC 0x30
67#define AX_DATAC 0x34 67#define AX_DATAC 0x34
68 68
69#define PT_ADDR_INDX 0xE8
70#define PT_READ_INDX 0xE4
71#define PT_SIG_1_ADDR 0xA520
72#define PT_SIG_2_ADDR 0xA521
73#define PT_SIG_3_ADDR 0xA522
74#define PT_SIG_4_ADDR 0xA523
75#define PT_SIG_1_DATA 0x78
76#define PT_SIG_2_DATA 0x56
77#define PT_SIG_3_DATA 0x34
78#define PT_SIG_4_DATA 0x12
79#define PT4_P1_REG 0xB521
80#define PT4_P2_REG 0xB522
81#define PT2_P1_REG 0xD520
82#define PT2_P2_REG 0xD521
83#define PT1_P1_REG 0xD522
84#define PT1_P2_REG 0xD523
85
69#define NB_PCIE_INDX_ADDR 0xe0 86#define NB_PCIE_INDX_ADDR 0xe0
70#define NB_PCIE_INDX_DATA 0xe4 87#define NB_PCIE_INDX_DATA 0xe4
71#define PCIE_P_CNTL 0x10040 88#define PCIE_P_CNTL 0x10040
@@ -513,6 +530,98 @@ void usb_amd_dev_put(void)
513EXPORT_SYMBOL_GPL(usb_amd_dev_put); 530EXPORT_SYMBOL_GPL(usb_amd_dev_put);
514 531
515/* 532/*
533 * Check if port is disabled in BIOS on AMD Promontory host.
534 * BIOS Disabled ports may wake on connect/disconnect and need
535 * driver workaround to keep them disabled.
536 * Returns true if port is marked disabled.
537 */
538bool usb_amd_pt_check_port(struct device *device, int port)
539{
540 unsigned char value, port_shift;
541 struct pci_dev *pdev;
542 u16 reg;
543
544 pdev = to_pci_dev(device);
545 pci_write_config_word(pdev, PT_ADDR_INDX, PT_SIG_1_ADDR);
546
547 pci_read_config_byte(pdev, PT_READ_INDX, &value);
548 if (value != PT_SIG_1_DATA)
549 return false;
550
551 pci_write_config_word(pdev, PT_ADDR_INDX, PT_SIG_2_ADDR);
552
553 pci_read_config_byte(pdev, PT_READ_INDX, &value);
554 if (value != PT_SIG_2_DATA)
555 return false;
556
557 pci_write_config_word(pdev, PT_ADDR_INDX, PT_SIG_3_ADDR);
558
559 pci_read_config_byte(pdev, PT_READ_INDX, &value);
560 if (value != PT_SIG_3_DATA)
561 return false;
562
563 pci_write_config_word(pdev, PT_ADDR_INDX, PT_SIG_4_ADDR);
564
565 pci_read_config_byte(pdev, PT_READ_INDX, &value);
566 if (value != PT_SIG_4_DATA)
567 return false;
568
569 /* Check disabled port setting, if bit is set port is enabled */
570 switch (pdev->device) {
571 case 0x43b9:
572 case 0x43ba:
573 /*
574 * device is AMD_PROMONTORYA_4(0x43b9) or PROMONTORYA_3(0x43ba)
575 * PT4_P1_REG bits[7..1] represents USB2.0 ports 6 to 0
576 * PT4_P2_REG bits[6..0] represents ports 13 to 7
577 */
578 if (port > 6) {
579 reg = PT4_P2_REG;
580 port_shift = port - 7;
581 } else {
582 reg = PT4_P1_REG;
583 port_shift = port + 1;
584 }
585 break;
586 case 0x43bb:
587 /*
588 * device is AMD_PROMONTORYA_2(0x43bb)
589 * PT2_P1_REG bits[7..5] represents USB2.0 ports 2 to 0
590 * PT2_P2_REG bits[5..0] represents ports 9 to 3
591 */
592 if (port > 2) {
593 reg = PT2_P2_REG;
594 port_shift = port - 3;
595 } else {
596 reg = PT2_P1_REG;
597 port_shift = port + 5;
598 }
599 break;
600 case 0x43bc:
601 /*
602 * device is AMD_PROMONTORYA_1(0x43bc)
603 * PT1_P1_REG[7..4] represents USB2.0 ports 3 to 0
604 * PT1_P2_REG[5..0] represents ports 9 to 4
605 */
606 if (port > 3) {
607 reg = PT1_P2_REG;
608 port_shift = port - 4;
609 } else {
610 reg = PT1_P1_REG;
611 port_shift = port + 4;
612 }
613 break;
614 default:
615 return false;
616 }
617 pci_write_config_word(pdev, PT_ADDR_INDX, reg);
618 pci_read_config_byte(pdev, PT_READ_INDX, &value);
619
620 return !(value & BIT(port_shift));
621}
622EXPORT_SYMBOL_GPL(usb_amd_pt_check_port);
623
624/*
516 * Make sure the controller is completely inactive, unable to 625 * Make sure the controller is completely inactive, unable to
517 * generate interrupts or do DMA. 626 * generate interrupts or do DMA.
518 */ 627 */
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h
index b68dcb5dd0fd..4ca0d9b7e463 100644
--- a/drivers/usb/host/pci-quirks.h
+++ b/drivers/usb/host/pci-quirks.h
@@ -17,6 +17,7 @@ void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev);
17void usb_disable_xhci_ports(struct pci_dev *xhci_pdev); 17void usb_disable_xhci_ports(struct pci_dev *xhci_pdev);
18void sb800_prefetch(struct device *dev, int on); 18void sb800_prefetch(struct device *dev, int on);
19bool usb_xhci_needs_pci_reset(struct pci_dev *pdev); 19bool usb_xhci_needs_pci_reset(struct pci_dev *pdev);
20bool usb_amd_pt_check_port(struct device *device, int port);
20#else 21#else
21struct pci_dev; 22struct pci_dev;
22static inline void usb_amd_quirk_pll_disable(void) {} 23static inline void usb_amd_quirk_pll_disable(void) {}
@@ -25,6 +26,10 @@ static inline void usb_asmedia_modifyflowcontrol(struct pci_dev *pdev) {}
25static inline void usb_amd_dev_put(void) {} 26static inline void usb_amd_dev_put(void) {}
26static inline void usb_disable_xhci_ports(struct pci_dev *xhci_pdev) {} 27static inline void usb_disable_xhci_ports(struct pci_dev *xhci_pdev) {}
27static inline void sb800_prefetch(struct device *dev, int on) {} 28static inline void sb800_prefetch(struct device *dev, int on) {}
29static inline bool usb_amd_pt_check_port(struct device *device, int port)
30{
31 return false;
32}
28#endif /* CONFIG_USB_PCI */ 33#endif /* CONFIG_USB_PCI */
29 34
30#endif /* __LINUX_USB_PCI_QUIRKS_H */ 35#endif /* __LINUX_USB_PCI_QUIRKS_H */
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index a1ab8acf39ba..c359bae7b754 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -328,13 +328,14 @@ dbc_ep_do_queue(struct dbc_ep *dep, struct dbc_request *req)
328int dbc_ep_queue(struct dbc_ep *dep, struct dbc_request *req, 328int dbc_ep_queue(struct dbc_ep *dep, struct dbc_request *req,
329 gfp_t gfp_flags) 329 gfp_t gfp_flags)
330{ 330{
331 unsigned long flags;
331 struct xhci_dbc *dbc = dep->dbc; 332 struct xhci_dbc *dbc = dep->dbc;
332 int ret = -ESHUTDOWN; 333 int ret = -ESHUTDOWN;
333 334
334 spin_lock(&dbc->lock); 335 spin_lock_irqsave(&dbc->lock, flags);
335 if (dbc->state == DS_CONFIGURED) 336 if (dbc->state == DS_CONFIGURED)
336 ret = dbc_ep_do_queue(dep, req); 337 ret = dbc_ep_do_queue(dep, req);
337 spin_unlock(&dbc->lock); 338 spin_unlock_irqrestore(&dbc->lock, flags);
338 339
339 mod_delayed_work(system_wq, &dbc->event_work, 0); 340 mod_delayed_work(system_wq, &dbc->event_work, 0);
340 341
@@ -521,15 +522,16 @@ static void xhci_do_dbc_stop(struct xhci_hcd *xhci)
521static int xhci_dbc_start(struct xhci_hcd *xhci) 522static int xhci_dbc_start(struct xhci_hcd *xhci)
522{ 523{
523 int ret; 524 int ret;
525 unsigned long flags;
524 struct xhci_dbc *dbc = xhci->dbc; 526 struct xhci_dbc *dbc = xhci->dbc;
525 527
526 WARN_ON(!dbc); 528 WARN_ON(!dbc);
527 529
528 pm_runtime_get_sync(xhci_to_hcd(xhci)->self.controller); 530 pm_runtime_get_sync(xhci_to_hcd(xhci)->self.controller);
529 531
530 spin_lock(&dbc->lock); 532 spin_lock_irqsave(&dbc->lock, flags);
531 ret = xhci_do_dbc_start(xhci); 533 ret = xhci_do_dbc_start(xhci);
532 spin_unlock(&dbc->lock); 534 spin_unlock_irqrestore(&dbc->lock, flags);
533 535
534 if (ret) { 536 if (ret) {
535 pm_runtime_put(xhci_to_hcd(xhci)->self.controller); 537 pm_runtime_put(xhci_to_hcd(xhci)->self.controller);
@@ -541,6 +543,7 @@ static int xhci_dbc_start(struct xhci_hcd *xhci)
541 543
542static void xhci_dbc_stop(struct xhci_hcd *xhci) 544static void xhci_dbc_stop(struct xhci_hcd *xhci)
543{ 545{
546 unsigned long flags;
544 struct xhci_dbc *dbc = xhci->dbc; 547 struct xhci_dbc *dbc = xhci->dbc;
545 struct dbc_port *port = &dbc->port; 548 struct dbc_port *port = &dbc->port;
546 549
@@ -551,9 +554,9 @@ static void xhci_dbc_stop(struct xhci_hcd *xhci)
551 if (port->registered) 554 if (port->registered)
552 xhci_dbc_tty_unregister_device(xhci); 555 xhci_dbc_tty_unregister_device(xhci);
553 556
554 spin_lock(&dbc->lock); 557 spin_lock_irqsave(&dbc->lock, flags);
555 xhci_do_dbc_stop(xhci); 558 xhci_do_dbc_stop(xhci);
556 spin_unlock(&dbc->lock); 559 spin_unlock_irqrestore(&dbc->lock, flags);
557 560
558 pm_runtime_put_sync(xhci_to_hcd(xhci)->self.controller); 561 pm_runtime_put_sync(xhci_to_hcd(xhci)->self.controller);
559} 562}
@@ -779,14 +782,15 @@ static void xhci_dbc_handle_events(struct work_struct *work)
779 int ret; 782 int ret;
780 enum evtreturn evtr; 783 enum evtreturn evtr;
781 struct xhci_dbc *dbc; 784 struct xhci_dbc *dbc;
785 unsigned long flags;
782 struct xhci_hcd *xhci; 786 struct xhci_hcd *xhci;
783 787
784 dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work); 788 dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work);
785 xhci = dbc->xhci; 789 xhci = dbc->xhci;
786 790
787 spin_lock(&dbc->lock); 791 spin_lock_irqsave(&dbc->lock, flags);
788 evtr = xhci_dbc_do_handle_events(dbc); 792 evtr = xhci_dbc_do_handle_events(dbc);
789 spin_unlock(&dbc->lock); 793 spin_unlock_irqrestore(&dbc->lock, flags);
790 794
791 switch (evtr) { 795 switch (evtr) {
792 case EVT_GSER: 796 case EVT_GSER:
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 8d47b6fbf973..75f0b92694ba 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -92,21 +92,23 @@ static void dbc_start_rx(struct dbc_port *port)
92static void 92static void
93dbc_read_complete(struct xhci_hcd *xhci, struct dbc_request *req) 93dbc_read_complete(struct xhci_hcd *xhci, struct dbc_request *req)
94{ 94{
95 unsigned long flags;
95 struct xhci_dbc *dbc = xhci->dbc; 96 struct xhci_dbc *dbc = xhci->dbc;
96 struct dbc_port *port = &dbc->port; 97 struct dbc_port *port = &dbc->port;
97 98
98 spin_lock(&port->port_lock); 99 spin_lock_irqsave(&port->port_lock, flags);
99 list_add_tail(&req->list_pool, &port->read_queue); 100 list_add_tail(&req->list_pool, &port->read_queue);
100 tasklet_schedule(&port->push); 101 tasklet_schedule(&port->push);
101 spin_unlock(&port->port_lock); 102 spin_unlock_irqrestore(&port->port_lock, flags);
102} 103}
103 104
104static void dbc_write_complete(struct xhci_hcd *xhci, struct dbc_request *req) 105static void dbc_write_complete(struct xhci_hcd *xhci, struct dbc_request *req)
105{ 106{
107 unsigned long flags;
106 struct xhci_dbc *dbc = xhci->dbc; 108 struct xhci_dbc *dbc = xhci->dbc;
107 struct dbc_port *port = &dbc->port; 109 struct dbc_port *port = &dbc->port;
108 110
109 spin_lock(&port->port_lock); 111 spin_lock_irqsave(&port->port_lock, flags);
110 list_add(&req->list_pool, &port->write_pool); 112 list_add(&req->list_pool, &port->write_pool);
111 switch (req->status) { 113 switch (req->status) {
112 case 0: 114 case 0:
@@ -119,7 +121,7 @@ static void dbc_write_complete(struct xhci_hcd *xhci, struct dbc_request *req)
119 req->status); 121 req->status);
120 break; 122 break;
121 } 123 }
122 spin_unlock(&port->port_lock); 124 spin_unlock_irqrestore(&port->port_lock, flags);
123} 125}
124 126
125static void xhci_dbc_free_req(struct dbc_ep *dep, struct dbc_request *req) 127static void xhci_dbc_free_req(struct dbc_ep *dep, struct dbc_request *req)
@@ -327,12 +329,13 @@ static void dbc_rx_push(unsigned long _port)
327{ 329{
328 struct dbc_request *req; 330 struct dbc_request *req;
329 struct tty_struct *tty; 331 struct tty_struct *tty;
332 unsigned long flags;
330 bool do_push = false; 333 bool do_push = false;
331 bool disconnect = false; 334 bool disconnect = false;
332 struct dbc_port *port = (void *)_port; 335 struct dbc_port *port = (void *)_port;
333 struct list_head *queue = &port->read_queue; 336 struct list_head *queue = &port->read_queue;
334 337
335 spin_lock_irq(&port->port_lock); 338 spin_lock_irqsave(&port->port_lock, flags);
336 tty = port->port.tty; 339 tty = port->port.tty;
337 while (!list_empty(queue)) { 340 while (!list_empty(queue)) {
338 req = list_first_entry(queue, struct dbc_request, list_pool); 341 req = list_first_entry(queue, struct dbc_request, list_pool);
@@ -392,16 +395,17 @@ static void dbc_rx_push(unsigned long _port)
392 if (!disconnect) 395 if (!disconnect)
393 dbc_start_rx(port); 396 dbc_start_rx(port);
394 397
395 spin_unlock_irq(&port->port_lock); 398 spin_unlock_irqrestore(&port->port_lock, flags);
396} 399}
397 400
398static int dbc_port_activate(struct tty_port *_port, struct tty_struct *tty) 401static int dbc_port_activate(struct tty_port *_port, struct tty_struct *tty)
399{ 402{
403 unsigned long flags;
400 struct dbc_port *port = container_of(_port, struct dbc_port, port); 404 struct dbc_port *port = container_of(_port, struct dbc_port, port);
401 405
402 spin_lock_irq(&port->port_lock); 406 spin_lock_irqsave(&port->port_lock, flags);
403 dbc_start_rx(port); 407 dbc_start_rx(port);
404 spin_unlock_irq(&port->port_lock); 408 spin_unlock_irqrestore(&port->port_lock, flags);
405 409
406 return 0; 410 return 0;
407} 411}
diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
index e26e685d8a57..5851052d4668 100644
--- a/drivers/usb/host/xhci-debugfs.c
+++ b/drivers/usb/host/xhci-debugfs.c
@@ -211,7 +211,7 @@ static void xhci_ring_dump_segment(struct seq_file *s,
211static int xhci_ring_trb_show(struct seq_file *s, void *unused) 211static int xhci_ring_trb_show(struct seq_file *s, void *unused)
212{ 212{
213 int i; 213 int i;
214 struct xhci_ring *ring = s->private; 214 struct xhci_ring *ring = *(struct xhci_ring **)s->private;
215 struct xhci_segment *seg = ring->first_seg; 215 struct xhci_segment *seg = ring->first_seg;
216 216
217 for (i = 0; i < ring->num_segs; i++) { 217 for (i = 0; i < ring->num_segs; i++) {
@@ -387,7 +387,7 @@ void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci,
387 387
388 snprintf(epriv->name, sizeof(epriv->name), "ep%02d", ep_index); 388 snprintf(epriv->name, sizeof(epriv->name), "ep%02d", ep_index);
389 epriv->root = xhci_debugfs_create_ring_dir(xhci, 389 epriv->root = xhci_debugfs_create_ring_dir(xhci,
390 &dev->eps[ep_index].new_ring, 390 &dev->eps[ep_index].ring,
391 epriv->name, 391 epriv->name,
392 spriv->root); 392 spriv->root);
393 spriv->eps[ep_index] = epriv; 393 spriv->eps[ep_index] = epriv;
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 46d5e08f05f1..72ebbc908e19 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1224,17 +1224,17 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1224 temp = readl(port_array[wIndex]); 1224 temp = readl(port_array[wIndex]);
1225 break; 1225 break;
1226 } 1226 }
1227 1227 /* Port must be enabled */
1228 /* Software should not attempt to set 1228 if (!(temp & PORT_PE)) {
1229 * port link state above '3' (U3) and the port 1229 retval = -ENODEV;
1230 * must be enabled. 1230 break;
1231 */ 1231 }
1232 if ((temp & PORT_PE) == 0 || 1232 /* Can't set port link state above '3' (U3) */
1233 (link_state > USB_SS_PORT_LS_U3)) { 1233 if (link_state > USB_SS_PORT_LS_U3) {
1234 xhci_warn(xhci, "Cannot set link state.\n"); 1234 xhci_warn(xhci, "Cannot set port %d link state %d\n",
1235 wIndex, link_state);
1235 goto error; 1236 goto error;
1236 } 1237 }
1237
1238 if (link_state == USB_SS_PORT_LS_U3) { 1238 if (link_state == USB_SS_PORT_LS_U3) {
1239 slot_id = xhci_find_slot_id_by_port(hcd, xhci, 1239 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1240 wIndex + 1); 1240 wIndex + 1);
@@ -1522,6 +1522,13 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
1522 t2 |= PORT_WKOC_E | PORT_WKCONN_E; 1522 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
1523 t2 &= ~PORT_WKDISC_E; 1523 t2 &= ~PORT_WKDISC_E;
1524 } 1524 }
1525
1526 if ((xhci->quirks & XHCI_U2_DISABLE_WAKE) &&
1527 (hcd->speed < HCD_USB3)) {
1528 if (usb_amd_pt_check_port(hcd->self.controller,
1529 port_index))
1530 t2 &= ~PORT_WAKE_BITS;
1531 }
1525 } else 1532 } else
1526 t2 &= ~PORT_WAKE_BITS; 1533 t2 &= ~PORT_WAKE_BITS;
1527 1534
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 6c79037876db..d9f831b67e57 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -42,6 +42,10 @@
42#define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8 42#define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8
43#define PCI_DEVICE_ID_INTEL_DNV_XHCI 0x19d0 43#define PCI_DEVICE_ID_INTEL_DNV_XHCI 0x19d0
44 44
45#define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9
46#define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba
47#define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb
48#define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc
45#define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142 49#define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142
46 50
47static const char hcd_name[] = "xhci_hcd"; 51static const char hcd_name[] = "xhci_hcd";
@@ -122,9 +126,19 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
122 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info()) 126 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
123 xhci->quirks |= XHCI_AMD_PLL_FIX; 127 xhci->quirks |= XHCI_AMD_PLL_FIX;
124 128
129 if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x43bb)
130 xhci->quirks |= XHCI_SUSPEND_DELAY;
131
125 if (pdev->vendor == PCI_VENDOR_ID_AMD) 132 if (pdev->vendor == PCI_VENDOR_ID_AMD)
126 xhci->quirks |= XHCI_TRUST_TX_LENGTH; 133 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
127 134
135 if ((pdev->vendor == PCI_VENDOR_ID_AMD) &&
136 ((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) ||
137 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) ||
138 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2) ||
139 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_1)))
140 xhci->quirks |= XHCI_U2_DISABLE_WAKE;
141
128 if (pdev->vendor == PCI_VENDOR_ID_INTEL) { 142 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
129 xhci->quirks |= XHCI_LPM_SUPPORT; 143 xhci->quirks |= XHCI_LPM_SUPPORT;
130 xhci->quirks |= XHCI_INTEL_HOST; 144 xhci->quirks |= XHCI_INTEL_HOST;
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 6f038306c14d..6652e2d5bd2e 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -360,7 +360,6 @@ static int __maybe_unused xhci_plat_suspend(struct device *dev)
360{ 360{
361 struct usb_hcd *hcd = dev_get_drvdata(dev); 361 struct usb_hcd *hcd = dev_get_drvdata(dev);
362 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 362 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
363 int ret;
364 363
365 /* 364 /*
366 * xhci_suspend() needs `do_wakeup` to know whether host is allowed 365 * xhci_suspend() needs `do_wakeup` to know whether host is allowed
@@ -370,12 +369,7 @@ static int __maybe_unused xhci_plat_suspend(struct device *dev)
370 * reconsider this when xhci_plat_suspend enlarges its scope, e.g., 369 * reconsider this when xhci_plat_suspend enlarges its scope, e.g.,
371 * also applies to runtime suspend. 370 * also applies to runtime suspend.
372 */ 371 */
373 ret = xhci_suspend(xhci, device_may_wakeup(dev)); 372 return xhci_suspend(xhci, device_may_wakeup(dev));
374
375 if (!device_may_wakeup(dev) && !IS_ERR(xhci->clk))
376 clk_disable_unprepare(xhci->clk);
377
378 return ret;
379} 373}
380 374
381static int __maybe_unused xhci_plat_resume(struct device *dev) 375static int __maybe_unused xhci_plat_resume(struct device *dev)
@@ -384,9 +378,6 @@ static int __maybe_unused xhci_plat_resume(struct device *dev)
384 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 378 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
385 int ret; 379 int ret;
386 380
387 if (!device_may_wakeup(dev) && !IS_ERR(xhci->clk))
388 clk_prepare_enable(xhci->clk);
389
390 ret = xhci_priv_resume_quirk(hcd); 381 ret = xhci_priv_resume_quirk(hcd);
391 if (ret) 382 if (ret)
392 return ret; 383 return ret;
diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
index f0b559660007..f33ffc2bc4ed 100644
--- a/drivers/usb/host/xhci-rcar.c
+++ b/drivers/usb/host/xhci-rcar.c
@@ -83,6 +83,10 @@ static const struct soc_device_attribute rcar_quirks_match[] = {
83 .soc_id = "r8a7796", 83 .soc_id = "r8a7796",
84 .data = (void *)RCAR_XHCI_FIRMWARE_V3, 84 .data = (void *)RCAR_XHCI_FIRMWARE_V3,
85 }, 85 },
86 {
87 .soc_id = "r8a77965",
88 .data = (void *)RCAR_XHCI_FIRMWARE_V3,
89 },
86 { /* sentinel */ }, 90 { /* sentinel */ },
87}; 91};
88 92
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 1eeb3396300f..5d37700ae4b0 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -646,8 +646,6 @@ static void xhci_stop(struct usb_hcd *hcd)
646 return; 646 return;
647 } 647 }
648 648
649 xhci_debugfs_exit(xhci);
650
651 xhci_dbc_exit(xhci); 649 xhci_dbc_exit(xhci);
652 650
653 spin_lock_irq(&xhci->lock); 651 spin_lock_irq(&xhci->lock);
@@ -680,6 +678,7 @@ static void xhci_stop(struct usb_hcd *hcd)
680 678
681 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory"); 679 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory");
682 xhci_mem_cleanup(xhci); 680 xhci_mem_cleanup(xhci);
681 xhci_debugfs_exit(xhci);
683 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 682 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
684 "xhci_stop completed - status = %x", 683 "xhci_stop completed - status = %x",
685 readl(&xhci->op_regs->status)); 684 readl(&xhci->op_regs->status));
@@ -878,6 +877,9 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
878 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); 877 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);
879 del_timer_sync(&xhci->shared_hcd->rh_timer); 878 del_timer_sync(&xhci->shared_hcd->rh_timer);
880 879
880 if (xhci->quirks & XHCI_SUSPEND_DELAY)
881 usleep_range(1000, 1500);
882
881 spin_lock_irq(&xhci->lock); 883 spin_lock_irq(&xhci->lock);
882 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 884 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
883 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); 885 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
@@ -1014,6 +1016,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
1014 1016
1015 xhci_dbg(xhci, "cleaning up memory\n"); 1017 xhci_dbg(xhci, "cleaning up memory\n");
1016 xhci_mem_cleanup(xhci); 1018 xhci_mem_cleanup(xhci);
1019 xhci_debugfs_exit(xhci);
1017 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", 1020 xhci_dbg(xhci, "xhci_stop completed - status = %x\n",
1018 readl(&xhci->op_regs->status)); 1021 readl(&xhci->op_regs->status));
1019 1022
@@ -3544,12 +3547,10 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
3544 virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING; 3547 virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING;
3545 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); 3548 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer);
3546 } 3549 }
3547 3550 xhci_debugfs_remove_slot(xhci, udev->slot_id);
3548 ret = xhci_disable_slot(xhci, udev->slot_id); 3551 ret = xhci_disable_slot(xhci, udev->slot_id);
3549 if (ret) { 3552 if (ret)
3550 xhci_debugfs_remove_slot(xhci, udev->slot_id);
3551 xhci_free_virt_device(xhci, udev->slot_id); 3553 xhci_free_virt_device(xhci, udev->slot_id);
3552 }
3553} 3554}
3554 3555
3555int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id) 3556int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 96099a245c69..866e141d4972 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -718,11 +718,12 @@ struct xhci_ep_ctx {
718/* bits 10:14 are Max Primary Streams */ 718/* bits 10:14 are Max Primary Streams */
719/* bit 15 is Linear Stream Array */ 719/* bit 15 is Linear Stream Array */
720/* Interval - period between requests to an endpoint - 125u increments. */ 720/* Interval - period between requests to an endpoint - 125u increments. */
721#define EP_INTERVAL(p) (((p) & 0xff) << 16) 721#define EP_INTERVAL(p) (((p) & 0xff) << 16)
722#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff)) 722#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
723#define CTX_TO_EP_INTERVAL(p) (((p) >> 16) & 0xff) 723#define CTX_TO_EP_INTERVAL(p) (((p) >> 16) & 0xff)
724#define EP_MAXPSTREAMS_MASK (0x1f << 10) 724#define EP_MAXPSTREAMS_MASK (0x1f << 10)
725#define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK) 725#define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK)
726#define CTX_TO_EP_MAXPSTREAMS(p) (((p) & EP_MAXPSTREAMS_MASK) >> 10)
726/* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */ 727/* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */
727#define EP_HAS_LSA (1 << 15) 728#define EP_HAS_LSA (1 << 15)
728/* hosts with LEC=1 use bits 31:24 as ESIT high bits. */ 729/* hosts with LEC=1 use bits 31:24 as ESIT high bits. */
@@ -1822,9 +1823,10 @@ struct xhci_hcd {
1822/* For controller with a broken Port Disable implementation */ 1823/* For controller with a broken Port Disable implementation */
1823#define XHCI_BROKEN_PORT_PED (1 << 25) 1824#define XHCI_BROKEN_PORT_PED (1 << 25)
1824#define XHCI_LIMIT_ENDPOINT_INTERVAL_7 (1 << 26) 1825#define XHCI_LIMIT_ENDPOINT_INTERVAL_7 (1 << 26)
1825/* Reserved. It was XHCI_U2_DISABLE_WAKE */ 1826#define XHCI_U2_DISABLE_WAKE (1 << 27)
1826#define XHCI_ASMEDIA_MODIFY_FLOWCONTROL (1 << 28) 1827#define XHCI_ASMEDIA_MODIFY_FLOWCONTROL (1 << 28)
1827#define XHCI_HW_LPM_DISABLE (1 << 29) 1828#define XHCI_HW_LPM_DISABLE (1 << 29)
1829#define XHCI_SUSPEND_DELAY (1 << 30)
1828 1830
1829 unsigned int num_active_eps; 1831 unsigned int num_active_eps;
1830 unsigned int limit_active_eps; 1832 unsigned int limit_active_eps;
@@ -2549,21 +2551,22 @@ static inline const char *xhci_decode_ep_context(u32 info, u32 info2, u64 deq,
2549 u8 burst; 2551 u8 burst;
2550 u8 cerr; 2552 u8 cerr;
2551 u8 mult; 2553 u8 mult;
2552 u8 lsa; 2554
2553 u8 hid; 2555 bool lsa;
2556 bool hid;
2554 2557
2555 esit = CTX_TO_MAX_ESIT_PAYLOAD_HI(info) << 16 | 2558 esit = CTX_TO_MAX_ESIT_PAYLOAD_HI(info) << 16 |
2556 CTX_TO_MAX_ESIT_PAYLOAD(tx_info); 2559 CTX_TO_MAX_ESIT_PAYLOAD(tx_info);
2557 2560
2558 ep_state = info & EP_STATE_MASK; 2561 ep_state = info & EP_STATE_MASK;
2559 max_pstr = info & EP_MAXPSTREAMS_MASK; 2562 max_pstr = CTX_TO_EP_MAXPSTREAMS(info);
2560 interval = CTX_TO_EP_INTERVAL(info); 2563 interval = CTX_TO_EP_INTERVAL(info);
2561 mult = CTX_TO_EP_MULT(info) + 1; 2564 mult = CTX_TO_EP_MULT(info) + 1;
2562 lsa = info & EP_HAS_LSA; 2565 lsa = !!(info & EP_HAS_LSA);
2563 2566
2564 cerr = (info2 & (3 << 1)) >> 1; 2567 cerr = (info2 & (3 << 1)) >> 1;
2565 ep_type = CTX_TO_EP_TYPE(info2); 2568 ep_type = CTX_TO_EP_TYPE(info2);
2566 hid = info2 & (1 << 7); 2569 hid = !!(info2 & (1 << 7));
2567 burst = CTX_TO_MAX_BURST(info2); 2570 burst = CTX_TO_MAX_BURST(info2);
2568 maxp = MAX_PACKET_DECODED(info2); 2571 maxp = MAX_PACKET_DECODED(info2);
2569 2572
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index 63b9e85dc0e9..236a60f53099 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -42,6 +42,9 @@
42#define USB_DEVICE_ID_LD_MICROCASSYTIME 0x1033 /* USB Product ID of Micro-CASSY Time (reserved) */ 42#define USB_DEVICE_ID_LD_MICROCASSYTIME 0x1033 /* USB Product ID of Micro-CASSY Time (reserved) */
43#define USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE 0x1035 /* USB Product ID of Micro-CASSY Temperature */ 43#define USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE 0x1035 /* USB Product ID of Micro-CASSY Temperature */
44#define USB_DEVICE_ID_LD_MICROCASSYPH 0x1038 /* USB Product ID of Micro-CASSY pH */ 44#define USB_DEVICE_ID_LD_MICROCASSYPH 0x1038 /* USB Product ID of Micro-CASSY pH */
45#define USB_DEVICE_ID_LD_POWERANALYSERCASSY 0x1040 /* USB Product ID of Power Analyser CASSY */
46#define USB_DEVICE_ID_LD_CONVERTERCONTROLLERCASSY 0x1042 /* USB Product ID of Converter Controller CASSY */
47#define USB_DEVICE_ID_LD_MACHINETESTCASSY 0x1043 /* USB Product ID of Machine Test CASSY */
45#define USB_DEVICE_ID_LD_JWM 0x1080 /* USB Product ID of Joule and Wattmeter */ 48#define USB_DEVICE_ID_LD_JWM 0x1080 /* USB Product ID of Joule and Wattmeter */
46#define USB_DEVICE_ID_LD_DMMP 0x1081 /* USB Product ID of Digital Multimeter P (reserved) */ 49#define USB_DEVICE_ID_LD_DMMP 0x1081 /* USB Product ID of Digital Multimeter P (reserved) */
47#define USB_DEVICE_ID_LD_UMIP 0x1090 /* USB Product ID of UMI P */ 50#define USB_DEVICE_ID_LD_UMIP 0x1090 /* USB Product ID of UMI P */
@@ -84,6 +87,9 @@ static const struct usb_device_id ld_usb_table[] = {
84 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) }, 87 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
85 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) }, 88 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
86 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) }, 89 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
90 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERANALYSERCASSY) },
91 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CONVERTERCONTROLLERCASSY) },
92 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETESTCASSY) },
87 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, 93 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
88 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, 94 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
89 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) }, 95 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index f5e1bb5e5217..984f7e12a6a5 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -85,6 +85,8 @@ struct mon_reader_text {
85 85
86 wait_queue_head_t wait; 86 wait_queue_head_t wait;
87 int printf_size; 87 int printf_size;
88 size_t printf_offset;
89 size_t printf_togo;
88 char *printf_buf; 90 char *printf_buf;
89 struct mutex printf_lock; 91 struct mutex printf_lock;
90 92
@@ -376,75 +378,103 @@ err_alloc:
376 return rc; 378 return rc;
377} 379}
378 380
379/* 381static ssize_t mon_text_copy_to_user(struct mon_reader_text *rp,
380 * For simplicity, we read one record in one system call and throw out 382 char __user * const buf, const size_t nbytes)
381 * what does not fit. This means that the following does not work: 383{
382 * dd if=/dbg/usbmon/0t bs=10 384 const size_t togo = min(nbytes, rp->printf_togo);
383 * Also, we do not allow seeks and do not bother advancing the offset. 385
384 */ 386 if (copy_to_user(buf, &rp->printf_buf[rp->printf_offset], togo))
387 return -EFAULT;
388 rp->printf_togo -= togo;
389 rp->printf_offset += togo;
390 return togo;
391}
392
393/* ppos is not advanced since the llseek operation is not permitted. */
385static ssize_t mon_text_read_t(struct file *file, char __user *buf, 394static ssize_t mon_text_read_t(struct file *file, char __user *buf,
386 size_t nbytes, loff_t *ppos) 395 size_t nbytes, loff_t *ppos)
387{ 396{
388 struct mon_reader_text *rp = file->private_data; 397 struct mon_reader_text *rp = file->private_data;
389 struct mon_event_text *ep; 398 struct mon_event_text *ep;
390 struct mon_text_ptr ptr; 399 struct mon_text_ptr ptr;
400 ssize_t ret;
391 401
392 ep = mon_text_read_wait(rp, file);
393 if (IS_ERR(ep))
394 return PTR_ERR(ep);
395 mutex_lock(&rp->printf_lock); 402 mutex_lock(&rp->printf_lock);
396 ptr.cnt = 0; 403
397 ptr.pbuf = rp->printf_buf; 404 if (rp->printf_togo == 0) {
398 ptr.limit = rp->printf_size; 405
399 406 ep = mon_text_read_wait(rp, file);
400 mon_text_read_head_t(rp, &ptr, ep); 407 if (IS_ERR(ep)) {
401 mon_text_read_statset(rp, &ptr, ep); 408 mutex_unlock(&rp->printf_lock);
402 ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt, 409 return PTR_ERR(ep);
403 " %d", ep->length); 410 }
404 mon_text_read_data(rp, &ptr, ep); 411 ptr.cnt = 0;
405 412 ptr.pbuf = rp->printf_buf;
406 if (copy_to_user(buf, rp->printf_buf, ptr.cnt)) 413 ptr.limit = rp->printf_size;
407 ptr.cnt = -EFAULT; 414
415 mon_text_read_head_t(rp, &ptr, ep);
416 mon_text_read_statset(rp, &ptr, ep);
417 ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt,
418 " %d", ep->length);
419 mon_text_read_data(rp, &ptr, ep);
420
421 rp->printf_togo = ptr.cnt;
422 rp->printf_offset = 0;
423
424 kmem_cache_free(rp->e_slab, ep);
425 }
426
427 ret = mon_text_copy_to_user(rp, buf, nbytes);
408 mutex_unlock(&rp->printf_lock); 428 mutex_unlock(&rp->printf_lock);
409 kmem_cache_free(rp->e_slab, ep); 429 return ret;
410 return ptr.cnt;
411} 430}
412 431
432/* ppos is not advanced since the llseek operation is not permitted. */
413static ssize_t mon_text_read_u(struct file *file, char __user *buf, 433static ssize_t mon_text_read_u(struct file *file, char __user *buf,
414 size_t nbytes, loff_t *ppos) 434 size_t nbytes, loff_t *ppos)
415{ 435{
416 struct mon_reader_text *rp = file->private_data; 436 struct mon_reader_text *rp = file->private_data;
417 struct mon_event_text *ep; 437 struct mon_event_text *ep;
418 struct mon_text_ptr ptr; 438 struct mon_text_ptr ptr;
439 ssize_t ret;
419 440
420 ep = mon_text_read_wait(rp, file);
421 if (IS_ERR(ep))
422 return PTR_ERR(ep);
423 mutex_lock(&rp->printf_lock); 441 mutex_lock(&rp->printf_lock);
424 ptr.cnt = 0;
425 ptr.pbuf = rp->printf_buf;
426 ptr.limit = rp->printf_size;
427 442
428 mon_text_read_head_u(rp, &ptr, ep); 443 if (rp->printf_togo == 0) {
429 if (ep->type == 'E') { 444
430 mon_text_read_statset(rp, &ptr, ep); 445 ep = mon_text_read_wait(rp, file);
431 } else if (ep->xfertype == USB_ENDPOINT_XFER_ISOC) { 446 if (IS_ERR(ep)) {
432 mon_text_read_isostat(rp, &ptr, ep); 447 mutex_unlock(&rp->printf_lock);
433 mon_text_read_isodesc(rp, &ptr, ep); 448 return PTR_ERR(ep);
434 } else if (ep->xfertype == USB_ENDPOINT_XFER_INT) { 449 }
435 mon_text_read_intstat(rp, &ptr, ep); 450 ptr.cnt = 0;
436 } else { 451 ptr.pbuf = rp->printf_buf;
437 mon_text_read_statset(rp, &ptr, ep); 452 ptr.limit = rp->printf_size;
453
454 mon_text_read_head_u(rp, &ptr, ep);
455 if (ep->type == 'E') {
456 mon_text_read_statset(rp, &ptr, ep);
457 } else if (ep->xfertype == USB_ENDPOINT_XFER_ISOC) {
458 mon_text_read_isostat(rp, &ptr, ep);
459 mon_text_read_isodesc(rp, &ptr, ep);
460 } else if (ep->xfertype == USB_ENDPOINT_XFER_INT) {
461 mon_text_read_intstat(rp, &ptr, ep);
462 } else {
463 mon_text_read_statset(rp, &ptr, ep);
464 }
465 ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt,
466 " %d", ep->length);
467 mon_text_read_data(rp, &ptr, ep);
468
469 rp->printf_togo = ptr.cnt;
470 rp->printf_offset = 0;
471
472 kmem_cache_free(rp->e_slab, ep);
438 } 473 }
439 ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt,
440 " %d", ep->length);
441 mon_text_read_data(rp, &ptr, ep);
442 474
443 if (copy_to_user(buf, rp->printf_buf, ptr.cnt)) 475 ret = mon_text_copy_to_user(rp, buf, nbytes);
444 ptr.cnt = -EFAULT;
445 mutex_unlock(&rp->printf_lock); 476 mutex_unlock(&rp->printf_lock);
446 kmem_cache_free(rp->e_slab, ep); 477 return ret;
447 return ptr.cnt;
448} 478}
449 479
450static struct mon_event_text *mon_text_read_wait(struct mon_reader_text *rp, 480static struct mon_event_text *mon_text_read_wait(struct mon_reader_text *rp,
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 968bf1e8b0fe..4d723077be2b 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1756,6 +1756,7 @@ vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
1756 int vbus; 1756 int vbus;
1757 u8 devctl; 1757 u8 devctl;
1758 1758
1759 pm_runtime_get_sync(dev);
1759 spin_lock_irqsave(&musb->lock, flags); 1760 spin_lock_irqsave(&musb->lock, flags);
1760 val = musb->a_wait_bcon; 1761 val = musb->a_wait_bcon;
1761 vbus = musb_platform_get_vbus_status(musb); 1762 vbus = musb_platform_get_vbus_status(musb);
@@ -1769,6 +1770,7 @@ vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
1769 vbus = 0; 1770 vbus = 0;
1770 } 1771 }
1771 spin_unlock_irqrestore(&musb->lock, flags); 1772 spin_unlock_irqrestore(&musb->lock, flags);
1773 pm_runtime_put_sync(dev);
1772 1774
1773 return sprintf(buf, "Vbus %s, timeout %lu msec\n", 1775 return sprintf(buf, "Vbus %s, timeout %lu msec\n",
1774 vbus ? "on" : "off", val); 1776 vbus ? "on" : "off", val);
@@ -2471,11 +2473,11 @@ static int musb_remove(struct platform_device *pdev)
2471 musb_disable_interrupts(musb); 2473 musb_disable_interrupts(musb);
2472 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 2474 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
2473 spin_unlock_irqrestore(&musb->lock, flags); 2475 spin_unlock_irqrestore(&musb->lock, flags);
2476 musb_platform_exit(musb);
2474 2477
2475 pm_runtime_dont_use_autosuspend(musb->controller); 2478 pm_runtime_dont_use_autosuspend(musb->controller);
2476 pm_runtime_put_sync(musb->controller); 2479 pm_runtime_put_sync(musb->controller);
2477 pm_runtime_disable(musb->controller); 2480 pm_runtime_disable(musb->controller);
2478 musb_platform_exit(musb);
2479 musb_phy_callback = NULL; 2481 musb_phy_callback = NULL;
2480 if (musb->dma_controller) 2482 if (musb->dma_controller)
2481 musb_dma_controller_destroy(musb->dma_controller); 2483 musb_dma_controller_destroy(musb->dma_controller);
@@ -2708,7 +2710,8 @@ static int musb_resume(struct device *dev)
2708 if ((devctl & mask) != (musb->context.devctl & mask)) 2710 if ((devctl & mask) != (musb->context.devctl & mask))
2709 musb->port1_status = 0; 2711 musb->port1_status = 0;
2710 2712
2711 musb_start(musb); 2713 musb_enable_interrupts(musb);
2714 musb_platform_enable(musb);
2712 2715
2713 spin_lock_irqsave(&musb->lock, flags); 2716 spin_lock_irqsave(&musb->lock, flags);
2714 error = musb_run_resume_work(musb); 2717 error = musb_run_resume_work(musb);
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 394b4ac86161..45ed32c2cba9 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -391,13 +391,7 @@ static void musb_advance_schedule(struct musb *musb, struct urb *urb,
391 } 391 }
392 } 392 }
393 393
394 /* 394 if (qh != NULL && qh->is_ready) {
395 * The pipe must be broken if current urb->status is set, so don't
396 * start next urb.
397 * TODO: to minimize the risk of regression, only check urb->status
398 * for RX, until we have a test case to understand the behavior of TX.
399 */
400 if ((!status || !is_in) && qh && qh->is_ready) {
401 musb_dbg(musb, "... next ep%d %cX urb %p", 395 musb_dbg(musb, "... next ep%d %cX urb %p",
402 hw_ep->epnum, is_in ? 'R' : 'T', next_urb(qh)); 396 hw_ep->epnum, is_in ? 'R' : 'T', next_urb(qh));
403 musb_start_urb(musb, is_in, qh); 397 musb_start_urb(musb, is_in, qh);
diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c
index da031c45395a..fbec863350f6 100644
--- a/drivers/usb/phy/phy-mxs-usb.c
+++ b/drivers/usb/phy/phy-mxs-usb.c
@@ -602,6 +602,9 @@ static enum usb_charger_type mxs_phy_charger_detect(struct usb_phy *phy)
602 void __iomem *base = phy->io_priv; 602 void __iomem *base = phy->io_priv;
603 enum usb_charger_type chgr_type = UNKNOWN_TYPE; 603 enum usb_charger_type chgr_type = UNKNOWN_TYPE;
604 604
605 if (!regmap)
606 return UNKNOWN_TYPE;
607
605 if (mxs_charger_data_contact_detect(mxs_phy)) 608 if (mxs_charger_data_contact_detect(mxs_phy))
606 return chgr_type; 609 return chgr_type;
607 610
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index 5925d111bd47..39fa2fc1b8b7 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -982,6 +982,10 @@ static int usbhsf_dma_prepare_pop_with_usb_dmac(struct usbhs_pkt *pkt,
982 if ((uintptr_t)pkt->buf & (USBHS_USB_DMAC_XFER_SIZE - 1)) 982 if ((uintptr_t)pkt->buf & (USBHS_USB_DMAC_XFER_SIZE - 1))
983 goto usbhsf_pio_prepare_pop; 983 goto usbhsf_pio_prepare_pop;
984 984
985 /* return at this time if the pipe is running */
986 if (usbhs_pipe_is_running(pipe))
987 return 0;
988
985 usbhs_pipe_config_change_bfre(pipe, 1); 989 usbhs_pipe_config_change_bfre(pipe, 1);
986 990
987 ret = usbhsf_fifo_select(pipe, fifo, 0); 991 ret = usbhsf_fifo_select(pipe, fifo, 0);
@@ -1172,6 +1176,7 @@ static int usbhsf_dma_pop_done_with_usb_dmac(struct usbhs_pkt *pkt,
1172 usbhsf_fifo_clear(pipe, fifo); 1176 usbhsf_fifo_clear(pipe, fifo);
1173 pkt->actual = usbhs_dma_calc_received_size(pkt, chan, rcv_len); 1177 pkt->actual = usbhs_dma_calc_received_size(pkt, chan, rcv_len);
1174 1178
1179 usbhs_pipe_running(pipe, 0);
1175 usbhsf_dma_stop(pipe, fifo); 1180 usbhsf_dma_stop(pipe, fifo);
1176 usbhsf_dma_unmap(pkt); 1181 usbhsf_dma_unmap(pkt);
1177 usbhsf_fifo_unselect(pipe, pipe->fifo); 1182 usbhsf_fifo_unselect(pipe, pipe->fifo);
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 5db8ed517e0e..2d8d9150da0c 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -241,6 +241,7 @@ static void option_instat_callback(struct urb *urb);
241#define QUECTEL_PRODUCT_EC21 0x0121 241#define QUECTEL_PRODUCT_EC21 0x0121
242#define QUECTEL_PRODUCT_EC25 0x0125 242#define QUECTEL_PRODUCT_EC25 0x0125
243#define QUECTEL_PRODUCT_BG96 0x0296 243#define QUECTEL_PRODUCT_BG96 0x0296
244#define QUECTEL_PRODUCT_EP06 0x0306
244 245
245#define CMOTECH_VENDOR_ID 0x16d8 246#define CMOTECH_VENDOR_ID 0x16d8
246#define CMOTECH_PRODUCT_6001 0x6001 247#define CMOTECH_PRODUCT_6001 0x6001
@@ -689,6 +690,10 @@ static const struct option_blacklist_info yuga_clm920_nc5_blacklist = {
689 .reserved = BIT(1) | BIT(4), 690 .reserved = BIT(1) | BIT(4),
690}; 691};
691 692
693static const struct option_blacklist_info quectel_ep06_blacklist = {
694 .reserved = BIT(4) | BIT(5),
695};
696
692static const struct usb_device_id option_ids[] = { 697static const struct usb_device_id option_ids[] = {
693 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) }, 698 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
694 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) }, 699 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
@@ -1203,6 +1208,8 @@ static const struct usb_device_id option_ids[] = {
1203 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 1208 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1204 { USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_BG96), 1209 { USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_BG96),
1205 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 1210 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1211 { USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06),
1212 .driver_info = (kernel_ulong_t)&quectel_ep06_blacklist },
1206 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6001) }, 1213 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6001) },
1207 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_CMU_300) }, 1214 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_CMU_300) },
1208 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6003), 1215 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6003),
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 3b1b9695177a..6034c39b67d1 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -1076,7 +1076,7 @@ static int uas_post_reset(struct usb_interface *intf)
1076 return 0; 1076 return 0;
1077 1077
1078 err = uas_configure_endpoints(devinfo); 1078 err = uas_configure_endpoints(devinfo);
1079 if (err && err != ENODEV) 1079 if (err && err != -ENODEV)
1080 shost_printk(KERN_ERR, shost, 1080 shost_printk(KERN_ERR, shost,
1081 "%s: alloc streams error %d after reset", 1081 "%s: alloc streams error %d after reset",
1082 __func__, err); 1082 __func__, err);
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 264af199aec8..747d3a9596d9 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -2118,6 +2118,13 @@ UNUSUAL_DEV( 0x152d, 0x2566, 0x0114, 0x0114,
2118 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 2118 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
2119 US_FL_BROKEN_FUA ), 2119 US_FL_BROKEN_FUA ),
2120 2120
2121/* Reported by Teijo Kinnunen <teijo.kinnunen@code-q.fi> */
2122UNUSUAL_DEV( 0x152d, 0x2567, 0x0117, 0x0117,
2123 "JMicron",
2124 "USB to ATA/ATAPI Bridge",
2125 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
2126 US_FL_BROKEN_FUA ),
2127
2121/* Reported-by George Cherian <george.cherian@cavium.com> */ 2128/* Reported-by George Cherian <george.cherian@cavium.com> */
2122UNUSUAL_DEV(0x152d, 0x9561, 0x0000, 0x9999, 2129UNUSUAL_DEV(0x152d, 0x9561, 0x0000, 0x9999,
2123 "JMicron", 2130 "JMicron",
diff --git a/drivers/usb/typec/fusb302/fusb302.c b/drivers/usb/typec/fusb302/fusb302.c
index 9ce4756adad6..dcd8ef085b30 100644
--- a/drivers/usb/typec/fusb302/fusb302.c
+++ b/drivers/usb/typec/fusb302/fusb302.c
@@ -1857,7 +1857,8 @@ static int fusb302_probe(struct i2c_client *client,
1857 chip->tcpm_port = tcpm_register_port(&client->dev, &chip->tcpc_dev); 1857 chip->tcpm_port = tcpm_register_port(&client->dev, &chip->tcpc_dev);
1858 if (IS_ERR(chip->tcpm_port)) { 1858 if (IS_ERR(chip->tcpm_port)) {
1859 ret = PTR_ERR(chip->tcpm_port); 1859 ret = PTR_ERR(chip->tcpm_port);
1860 dev_err(dev, "cannot register tcpm port, ret=%d", ret); 1860 if (ret != -EPROBE_DEFER)
1861 dev_err(dev, "cannot register tcpm port, ret=%d", ret);
1861 goto destroy_workqueue; 1862 goto destroy_workqueue;
1862 } 1863 }
1863 1864
diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
index f4d563ee7690..8b637a4b474b 100644
--- a/drivers/usb/typec/tcpm.c
+++ b/drivers/usb/typec/tcpm.c
@@ -252,9 +252,6 @@ struct tcpm_port {
252 unsigned int nr_src_pdo; 252 unsigned int nr_src_pdo;
253 u32 snk_pdo[PDO_MAX_OBJECTS]; 253 u32 snk_pdo[PDO_MAX_OBJECTS];
254 unsigned int nr_snk_pdo; 254 unsigned int nr_snk_pdo;
255 unsigned int nr_fixed; /* number of fixed sink PDOs */
256 unsigned int nr_var; /* number of variable sink PDOs */
257 unsigned int nr_batt; /* number of battery sink PDOs */
258 u32 snk_vdo[VDO_MAX_OBJECTS]; 255 u32 snk_vdo[VDO_MAX_OBJECTS];
259 unsigned int nr_snk_vdo; 256 unsigned int nr_snk_vdo;
260 257
@@ -1770,90 +1767,39 @@ static int tcpm_pd_check_request(struct tcpm_port *port)
1770 return 0; 1767 return 0;
1771} 1768}
1772 1769
1773#define min_power(x, y) min(pdo_max_power(x), pdo_max_power(y)) 1770static int tcpm_pd_select_pdo(struct tcpm_port *port)
1774#define min_current(x, y) min(pdo_max_current(x), pdo_max_current(y))
1775
1776static int tcpm_pd_select_pdo(struct tcpm_port *port, int *sink_pdo,
1777 int *src_pdo)
1778{ 1771{
1779 unsigned int i, j, max_mw = 0, max_mv = 0, mw = 0, mv = 0, ma = 0; 1772 unsigned int i, max_mw = 0, max_mv = 0;
1780 int ret = -EINVAL; 1773 int ret = -EINVAL;
1781 1774
1782 /* 1775 /*
1783 * Select the source PDO providing the most power which has a 1776 * Select the source PDO providing the most power while staying within
1784 * matchig sink cap. 1777 * the board's voltage limits. Prefer PDO providing exp
1785 */ 1778 */
1786 for (i = 0; i < port->nr_source_caps; i++) { 1779 for (i = 0; i < port->nr_source_caps; i++) {
1787 u32 pdo = port->source_caps[i]; 1780 u32 pdo = port->source_caps[i];
1788 enum pd_pdo_type type = pdo_type(pdo); 1781 enum pd_pdo_type type = pdo_type(pdo);
1782 unsigned int mv, ma, mw;
1789 1783
1790 if (type == PDO_TYPE_FIXED) { 1784 if (type == PDO_TYPE_FIXED)
1791 for (j = 0; j < port->nr_fixed; j++) { 1785 mv = pdo_fixed_voltage(pdo);
1792 if (pdo_fixed_voltage(pdo) == 1786 else
1793 pdo_fixed_voltage(port->snk_pdo[j])) { 1787 mv = pdo_min_voltage(pdo);
1794 ma = min_current(pdo, port->snk_pdo[j]); 1788
1795 mv = pdo_fixed_voltage(pdo); 1789 if (type == PDO_TYPE_BATT) {
1796 mw = ma * mv / 1000; 1790 mw = pdo_max_power(pdo);
1797 if (mw > max_mw || 1791 } else {
1798 (mw == max_mw && mv > max_mv)) { 1792 ma = min(pdo_max_current(pdo),
1799 ret = 0; 1793 port->max_snk_ma);
1800 *src_pdo = i; 1794 mw = ma * mv / 1000;
1801 *sink_pdo = j; 1795 }
1802 max_mw = mw; 1796
1803 max_mv = mv; 1797 /* Perfer higher voltages if available */
1804 } 1798 if ((mw > max_mw || (mw == max_mw && mv > max_mv)) &&
1805 /* There could only be one fixed pdo 1799 mv <= port->max_snk_mv) {
1806 * at a specific voltage level. 1800 ret = i;
1807 * So breaking here. 1801 max_mw = mw;
1808 */ 1802 max_mv = mv;
1809 break;
1810 }
1811 }
1812 } else if (type == PDO_TYPE_BATT) {
1813 for (j = port->nr_fixed;
1814 j < port->nr_fixed +
1815 port->nr_batt;
1816 j++) {
1817 if (pdo_min_voltage(pdo) >=
1818 pdo_min_voltage(port->snk_pdo[j]) &&
1819 pdo_max_voltage(pdo) <=
1820 pdo_max_voltage(port->snk_pdo[j])) {
1821 mw = min_power(pdo, port->snk_pdo[j]);
1822 mv = pdo_min_voltage(pdo);
1823 if (mw > max_mw ||
1824 (mw == max_mw && mv > max_mv)) {
1825 ret = 0;
1826 *src_pdo = i;
1827 *sink_pdo = j;
1828 max_mw = mw;
1829 max_mv = mv;
1830 }
1831 }
1832 }
1833 } else if (type == PDO_TYPE_VAR) {
1834 for (j = port->nr_fixed +
1835 port->nr_batt;
1836 j < port->nr_fixed +
1837 port->nr_batt +
1838 port->nr_var;
1839 j++) {
1840 if (pdo_min_voltage(pdo) >=
1841 pdo_min_voltage(port->snk_pdo[j]) &&
1842 pdo_max_voltage(pdo) <=
1843 pdo_max_voltage(port->snk_pdo[j])) {
1844 ma = min_current(pdo, port->snk_pdo[j]);
1845 mv = pdo_min_voltage(pdo);
1846 mw = ma * mv / 1000;
1847 if (mw > max_mw ||
1848 (mw == max_mw && mv > max_mv)) {
1849 ret = 0;
1850 *src_pdo = i;
1851 *sink_pdo = j;
1852 max_mw = mw;
1853 max_mv = mv;
1854 }
1855 }
1856 }
1857 } 1803 }
1858 } 1804 }
1859 1805
@@ -1865,14 +1811,13 @@ static int tcpm_pd_build_request(struct tcpm_port *port, u32 *rdo)
1865 unsigned int mv, ma, mw, flags; 1811 unsigned int mv, ma, mw, flags;
1866 unsigned int max_ma, max_mw; 1812 unsigned int max_ma, max_mw;
1867 enum pd_pdo_type type; 1813 enum pd_pdo_type type;
1868 int src_pdo_index, snk_pdo_index; 1814 int index;
1869 u32 pdo, matching_snk_pdo; 1815 u32 pdo;
1870 1816
1871 if (tcpm_pd_select_pdo(port, &snk_pdo_index, &src_pdo_index) < 0) 1817 index = tcpm_pd_select_pdo(port);
1818 if (index < 0)
1872 return -EINVAL; 1819 return -EINVAL;
1873 1820 pdo = port->source_caps[index];
1874 pdo = port->source_caps[src_pdo_index];
1875 matching_snk_pdo = port->snk_pdo[snk_pdo_index];
1876 type = pdo_type(pdo); 1821 type = pdo_type(pdo);
1877 1822
1878 if (type == PDO_TYPE_FIXED) 1823 if (type == PDO_TYPE_FIXED)
@@ -1880,28 +1825,26 @@ static int tcpm_pd_build_request(struct tcpm_port *port, u32 *rdo)
1880 else 1825 else
1881 mv = pdo_min_voltage(pdo); 1826 mv = pdo_min_voltage(pdo);
1882 1827
1883 /* Select maximum available current within the sink pdo's limit */ 1828 /* Select maximum available current within the board's power limit */
1884 if (type == PDO_TYPE_BATT) { 1829 if (type == PDO_TYPE_BATT) {
1885 mw = min_power(pdo, matching_snk_pdo); 1830 mw = pdo_max_power(pdo);
1886 ma = 1000 * mw / mv; 1831 ma = 1000 * min(mw, port->max_snk_mw) / mv;
1887 } else { 1832 } else {
1888 ma = min_current(pdo, matching_snk_pdo); 1833 ma = min(pdo_max_current(pdo),
1889 mw = ma * mv / 1000; 1834 1000 * port->max_snk_mw / mv);
1890 } 1835 }
1836 ma = min(ma, port->max_snk_ma);
1891 1837
1892 flags = RDO_USB_COMM | RDO_NO_SUSPEND; 1838 flags = RDO_USB_COMM | RDO_NO_SUSPEND;
1893 1839
1894 /* Set mismatch bit if offered power is less than operating power */ 1840 /* Set mismatch bit if offered power is less than operating power */
1841 mw = ma * mv / 1000;
1895 max_ma = ma; 1842 max_ma = ma;
1896 max_mw = mw; 1843 max_mw = mw;
1897 if (mw < port->operating_snk_mw) { 1844 if (mw < port->operating_snk_mw) {
1898 flags |= RDO_CAP_MISMATCH; 1845 flags |= RDO_CAP_MISMATCH;
1899 if (type == PDO_TYPE_BATT && 1846 max_mw = port->operating_snk_mw;
1900 (pdo_max_power(matching_snk_pdo) > pdo_max_power(pdo))) 1847 max_ma = max_mw * 1000 / mv;
1901 max_mw = pdo_max_power(matching_snk_pdo);
1902 else if (pdo_max_current(matching_snk_pdo) >
1903 pdo_max_current(pdo))
1904 max_ma = pdo_max_current(matching_snk_pdo);
1905 } 1848 }
1906 1849
1907 tcpm_log(port, "cc=%d cc1=%d cc2=%d vbus=%d vconn=%s polarity=%d", 1850 tcpm_log(port, "cc=%d cc1=%d cc2=%d vbus=%d vconn=%s polarity=%d",
@@ -1910,16 +1853,16 @@ static int tcpm_pd_build_request(struct tcpm_port *port, u32 *rdo)
1910 port->polarity); 1853 port->polarity);
1911 1854
1912 if (type == PDO_TYPE_BATT) { 1855 if (type == PDO_TYPE_BATT) {
1913 *rdo = RDO_BATT(src_pdo_index + 1, mw, max_mw, flags); 1856 *rdo = RDO_BATT(index + 1, mw, max_mw, flags);
1914 1857
1915 tcpm_log(port, "Requesting PDO %d: %u mV, %u mW%s", 1858 tcpm_log(port, "Requesting PDO %d: %u mV, %u mW%s",
1916 src_pdo_index, mv, mw, 1859 index, mv, mw,
1917 flags & RDO_CAP_MISMATCH ? " [mismatch]" : ""); 1860 flags & RDO_CAP_MISMATCH ? " [mismatch]" : "");
1918 } else { 1861 } else {
1919 *rdo = RDO_FIXED(src_pdo_index + 1, ma, max_ma, flags); 1862 *rdo = RDO_FIXED(index + 1, ma, max_ma, flags);
1920 1863
1921 tcpm_log(port, "Requesting PDO %d: %u mV, %u mA%s", 1864 tcpm_log(port, "Requesting PDO %d: %u mV, %u mA%s",
1922 src_pdo_index, mv, ma, 1865 index, mv, ma,
1923 flags & RDO_CAP_MISMATCH ? " [mismatch]" : ""); 1866 flags & RDO_CAP_MISMATCH ? " [mismatch]" : "");
1924 } 1867 }
1925 1868
@@ -3650,19 +3593,6 @@ int tcpm_update_sink_capabilities(struct tcpm_port *port, const u32 *pdo,
3650} 3593}
3651EXPORT_SYMBOL_GPL(tcpm_update_sink_capabilities); 3594EXPORT_SYMBOL_GPL(tcpm_update_sink_capabilities);
3652 3595
3653static int nr_type_pdos(const u32 *pdo, unsigned int nr_pdo,
3654 enum pd_pdo_type type)
3655{
3656 int count = 0;
3657 int i;
3658
3659 for (i = 0; i < nr_pdo; i++) {
3660 if (pdo_type(pdo[i]) == type)
3661 count++;
3662 }
3663 return count;
3664}
3665
3666struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) 3596struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
3667{ 3597{
3668 struct tcpm_port *port; 3598 struct tcpm_port *port;
@@ -3708,15 +3638,6 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
3708 tcpc->config->nr_src_pdo); 3638 tcpc->config->nr_src_pdo);
3709 port->nr_snk_pdo = tcpm_copy_pdos(port->snk_pdo, tcpc->config->snk_pdo, 3639 port->nr_snk_pdo = tcpm_copy_pdos(port->snk_pdo, tcpc->config->snk_pdo,
3710 tcpc->config->nr_snk_pdo); 3640 tcpc->config->nr_snk_pdo);
3711 port->nr_fixed = nr_type_pdos(port->snk_pdo,
3712 port->nr_snk_pdo,
3713 PDO_TYPE_FIXED);
3714 port->nr_var = nr_type_pdos(port->snk_pdo,
3715 port->nr_snk_pdo,
3716 PDO_TYPE_VAR);
3717 port->nr_batt = nr_type_pdos(port->snk_pdo,
3718 port->nr_snk_pdo,
3719 PDO_TYPE_BATT);
3720 port->nr_snk_vdo = tcpm_copy_vdos(port->snk_vdo, tcpc->config->snk_vdo, 3641 port->nr_snk_vdo = tcpm_copy_vdos(port->snk_vdo, tcpc->config->snk_vdo,
3721 tcpc->config->nr_snk_vdo); 3642 tcpc->config->nr_snk_vdo);
3722 3643
diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
index 49e552472c3f..dd8ef36ab10e 100644
--- a/drivers/usb/usbip/stub_dev.c
+++ b/drivers/usb/usbip/stub_dev.c
@@ -73,6 +73,7 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
73 goto err; 73 goto err;
74 74
75 sdev->ud.tcp_socket = socket; 75 sdev->ud.tcp_socket = socket;
76 sdev->ud.sockfd = sockfd;
76 77
77 spin_unlock_irq(&sdev->ud.lock); 78 spin_unlock_irq(&sdev->ud.lock);
78 79
@@ -172,6 +173,7 @@ static void stub_shutdown_connection(struct usbip_device *ud)
172 if (ud->tcp_socket) { 173 if (ud->tcp_socket) {
173 sockfd_put(ud->tcp_socket); 174 sockfd_put(ud->tcp_socket);
174 ud->tcp_socket = NULL; 175 ud->tcp_socket = NULL;
176 ud->sockfd = -1;
175 } 177 }
176 178
177 /* 3. free used data */ 179 /* 3. free used data */
@@ -266,6 +268,7 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev)
266 sdev->ud.status = SDEV_ST_AVAILABLE; 268 sdev->ud.status = SDEV_ST_AVAILABLE;
267 spin_lock_init(&sdev->ud.lock); 269 spin_lock_init(&sdev->ud.lock);
268 sdev->ud.tcp_socket = NULL; 270 sdev->ud.tcp_socket = NULL;
271 sdev->ud.sockfd = -1;
269 272
270 INIT_LIST_HEAD(&sdev->priv_init); 273 INIT_LIST_HEAD(&sdev->priv_init);
271 INIT_LIST_HEAD(&sdev->priv_tx); 274 INIT_LIST_HEAD(&sdev->priv_tx);
diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index c3e1008aa491..20e3d4609583 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -984,6 +984,7 @@ static void vhci_shutdown_connection(struct usbip_device *ud)
984 if (vdev->ud.tcp_socket) { 984 if (vdev->ud.tcp_socket) {
985 sockfd_put(vdev->ud.tcp_socket); 985 sockfd_put(vdev->ud.tcp_socket);
986 vdev->ud.tcp_socket = NULL; 986 vdev->ud.tcp_socket = NULL;
987 vdev->ud.sockfd = -1;
987 } 988 }
988 pr_info("release socket\n"); 989 pr_info("release socket\n");
989 990
@@ -1030,6 +1031,7 @@ static void vhci_device_reset(struct usbip_device *ud)
1030 if (ud->tcp_socket) { 1031 if (ud->tcp_socket) {
1031 sockfd_put(ud->tcp_socket); 1032 sockfd_put(ud->tcp_socket);
1032 ud->tcp_socket = NULL; 1033 ud->tcp_socket = NULL;
1034 ud->sockfd = -1;
1033 } 1035 }
1034 ud->status = VDEV_ST_NULL; 1036 ud->status = VDEV_ST_NULL;
1035 1037
diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
index d86f72bbbb91..6dcd3ff655c3 100644
--- a/drivers/usb/usbip/vudc_sysfs.c
+++ b/drivers/usb/usbip/vudc_sysfs.c
@@ -105,10 +105,14 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
105 if (rv != 0) 105 if (rv != 0)
106 return -EINVAL; 106 return -EINVAL;
107 107
108 if (!udc) {
109 dev_err(dev, "no device");
110 return -ENODEV;
111 }
108 spin_lock_irqsave(&udc->lock, flags); 112 spin_lock_irqsave(&udc->lock, flags);
109 /* Don't export what we don't have */ 113 /* Don't export what we don't have */
110 if (!udc || !udc->driver || !udc->pullup) { 114 if (!udc->driver || !udc->pullup) {
111 dev_err(dev, "no device or gadget not bound"); 115 dev_err(dev, "gadget not bound");
112 ret = -ENODEV; 116 ret = -ENODEV;
113 goto unlock; 117 goto unlock;
114 } 118 }
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index b0f759476900..8a1508a8e481 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -207,9 +207,6 @@ static bool vfio_pci_nointx(struct pci_dev *pdev)
207 } 207 }
208 } 208 }
209 209
210 if (!pdev->irq)
211 return true;
212
213 return false; 210 return false;
214} 211}
215 212
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index e30e29ae4819..45657e2b1ff7 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -338,11 +338,12 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
338{ 338{
339 struct page *page[1]; 339 struct page *page[1];
340 struct vm_area_struct *vma; 340 struct vm_area_struct *vma;
341 struct vm_area_struct *vmas[1];
341 int ret; 342 int ret;
342 343
343 if (mm == current->mm) { 344 if (mm == current->mm) {
344 ret = get_user_pages_fast(vaddr, 1, !!(prot & IOMMU_WRITE), 345 ret = get_user_pages_longterm(vaddr, 1, !!(prot & IOMMU_WRITE),
345 page); 346 page, vmas);
346 } else { 347 } else {
347 unsigned int flags = 0; 348 unsigned int flags = 0;
348 349
@@ -351,7 +352,18 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
351 352
352 down_read(&mm->mmap_sem); 353 down_read(&mm->mmap_sem);
353 ret = get_user_pages_remote(NULL, mm, vaddr, 1, flags, page, 354 ret = get_user_pages_remote(NULL, mm, vaddr, 1, flags, page,
354 NULL, NULL); 355 vmas, NULL);
356 /*
357 * The lifetime of a vaddr_get_pfn() page pin is
358 * userspace-controlled. In the fs-dax case this could
359 * lead to indefinite stalls in filesystem operations.
360 * Disallow attempts to pin fs-dax pages via this
361 * interface.
362 */
363 if (ret > 0 && vma_is_fsdax(vmas[0])) {
364 ret = -EOPNOTSUPP;
365 put_page(page[0]);
366 }
355 up_read(&mm->mmap_sem); 367 up_read(&mm->mmap_sem);
356 } 368 }
357 369
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 610cba276d47..8139bc70ad7d 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -170,7 +170,7 @@ static void vhost_net_buf_unproduce(struct vhost_net_virtqueue *nvq)
170 if (nvq->rx_ring && !vhost_net_buf_is_empty(rxq)) { 170 if (nvq->rx_ring && !vhost_net_buf_is_empty(rxq)) {
171 ptr_ring_unconsume(nvq->rx_ring, rxq->queue + rxq->head, 171 ptr_ring_unconsume(nvq->rx_ring, rxq->queue + rxq->head,
172 vhost_net_buf_get_size(rxq), 172 vhost_net_buf_get_size(rxq),
173 __skb_array_destroy_skb); 173 tun_ptr_free);
174 rxq->head = rxq->tail = 0; 174 rxq->head = rxq->tail = 0;
175 } 175 }
176} 176}
@@ -948,6 +948,7 @@ static int vhost_net_open(struct inode *inode, struct file *f)
948 n->vqs[i].done_idx = 0; 948 n->vqs[i].done_idx = 0;
949 n->vqs[i].vhost_hlen = 0; 949 n->vqs[i].vhost_hlen = 0;
950 n->vqs[i].sock_hlen = 0; 950 n->vqs[i].sock_hlen = 0;
951 n->vqs[i].rx_ring = NULL;
951 vhost_net_buf_init(&n->vqs[i].rxq); 952 vhost_net_buf_init(&n->vqs[i].rxq);
952 } 953 }
953 vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX); 954 vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX);
@@ -972,6 +973,7 @@ static struct socket *vhost_net_stop_vq(struct vhost_net *n,
972 vhost_net_disable_vq(n, vq); 973 vhost_net_disable_vq(n, vq);
973 vq->private_data = NULL; 974 vq->private_data = NULL;
974 vhost_net_buf_unproduce(nvq); 975 vhost_net_buf_unproduce(nvq);
976 nvq->rx_ring = NULL;
975 mutex_unlock(&vq->mutex); 977 mutex_unlock(&vq->mutex);
976 return sock; 978 return sock;
977} 979}
@@ -1161,14 +1163,14 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
1161 vhost_net_disable_vq(n, vq); 1163 vhost_net_disable_vq(n, vq);
1162 vq->private_data = sock; 1164 vq->private_data = sock;
1163 vhost_net_buf_unproduce(nvq); 1165 vhost_net_buf_unproduce(nvq);
1164 if (index == VHOST_NET_VQ_RX)
1165 nvq->rx_ring = get_tap_ptr_ring(fd);
1166 r = vhost_vq_init_access(vq); 1166 r = vhost_vq_init_access(vq);
1167 if (r) 1167 if (r)
1168 goto err_used; 1168 goto err_used;
1169 r = vhost_net_enable_vq(n, vq); 1169 r = vhost_net_enable_vq(n, vq);
1170 if (r) 1170 if (r)
1171 goto err_used; 1171 goto err_used;
1172 if (index == VHOST_NET_VQ_RX)
1173 nvq->rx_ring = get_tap_ptr_ring(fd);
1172 1174
1173 oldubufs = nvq->ubufs; 1175 oldubufs = nvq->ubufs;
1174 nvq->ubufs = ubufs; 1176 nvq->ubufs = ubufs;
diff --git a/drivers/video/fbdev/geode/video_gx.c b/drivers/video/fbdev/geode/video_gx.c
index 6082f653c68a..67773e8bbb95 100644
--- a/drivers/video/fbdev/geode/video_gx.c
+++ b/drivers/video/fbdev/geode/video_gx.c
@@ -127,7 +127,7 @@ void gx_set_dclk_frequency(struct fb_info *info)
127 int timeout = 1000; 127 int timeout = 1000;
128 128
129 /* Rev. 1 Geode GXs use a 14 MHz reference clock instead of 48 MHz. */ 129 /* Rev. 1 Geode GXs use a 14 MHz reference clock instead of 48 MHz. */
130 if (cpu_data(0).x86_mask == 1) { 130 if (cpu_data(0).x86_stepping == 1) {
131 pll_table = gx_pll_table_14MHz; 131 pll_table = gx_pll_table_14MHz;
132 pll_table_len = ARRAY_SIZE(gx_pll_table_14MHz); 132 pll_table_len = ARRAY_SIZE(gx_pll_table_14MHz);
133 } else { 133 } else {
diff --git a/drivers/video/fbdev/sbuslib.c b/drivers/video/fbdev/sbuslib.c
index af6fc97f4ba4..a436d44f1b7f 100644
--- a/drivers/video/fbdev/sbuslib.c
+++ b/drivers/video/fbdev/sbuslib.c
@@ -122,7 +122,7 @@ int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg,
122 unsigned char __user *ured; 122 unsigned char __user *ured;
123 unsigned char __user *ugreen; 123 unsigned char __user *ugreen;
124 unsigned char __user *ublue; 124 unsigned char __user *ublue;
125 int index, count, i; 125 unsigned int index, count, i;
126 126
127 if (get_user(index, &c->index) || 127 if (get_user(index, &c->index) ||
128 __get_user(count, &c->count) || 128 __get_user(count, &c->count) ||
@@ -161,7 +161,7 @@ int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg,
161 unsigned char __user *ugreen; 161 unsigned char __user *ugreen;
162 unsigned char __user *ublue; 162 unsigned char __user *ublue;
163 struct fb_cmap *cmap = &info->cmap; 163 struct fb_cmap *cmap = &info->cmap;
164 int index, count, i; 164 unsigned int index, count, i;
165 u8 red, green, blue; 165 u8 red, green, blue;
166 166
167 if (get_user(index, &c->index) || 167 if (get_user(index, &c->index) ||
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index eb30f3e09a47..71458f493cf8 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -428,8 +428,6 @@ unmap_release:
428 i = virtio16_to_cpu(_vq->vdev, vq->vring.desc[i].next); 428 i = virtio16_to_cpu(_vq->vdev, vq->vring.desc[i].next);
429 } 429 }
430 430
431 vq->vq.num_free += total_sg;
432
433 if (indirect) 431 if (indirect)
434 kfree(desc); 432 kfree(desc);
435 433
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index aff773bcebdb..37460cd6cabb 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -226,6 +226,7 @@ config ZIIRAVE_WATCHDOG
226config RAVE_SP_WATCHDOG 226config RAVE_SP_WATCHDOG
227 tristate "RAVE SP Watchdog timer" 227 tristate "RAVE SP Watchdog timer"
228 depends on RAVE_SP_CORE 228 depends on RAVE_SP_CORE
229 depends on NVMEM || !NVMEM
229 select WATCHDOG_CORE 230 select WATCHDOG_CORE
230 help 231 help
231 Support for the watchdog on RAVE SP device. 232 Support for the watchdog on RAVE SP device.
@@ -903,6 +904,7 @@ config F71808E_WDT
903config SP5100_TCO 904config SP5100_TCO
904 tristate "AMD/ATI SP5100 TCO Timer/Watchdog" 905 tristate "AMD/ATI SP5100 TCO Timer/Watchdog"
905 depends on X86 && PCI 906 depends on X86 && PCI
907 select WATCHDOG_CORE
906 ---help--- 908 ---help---
907 Hardware watchdog driver for the AMD/ATI SP5100 chipset. The TCO 909 Hardware watchdog driver for the AMD/ATI SP5100 chipset. The TCO
908 (Total Cost of Ownership) timer is a watchdog timer that will reboot 910 (Total Cost of Ownership) timer is a watchdog timer that will reboot
@@ -1008,6 +1010,7 @@ config WAFER_WDT
1008config I6300ESB_WDT 1010config I6300ESB_WDT
1009 tristate "Intel 6300ESB Timer/Watchdog" 1011 tristate "Intel 6300ESB Timer/Watchdog"
1010 depends on PCI 1012 depends on PCI
1013 select WATCHDOG_CORE
1011 ---help--- 1014 ---help---
1012 Hardware driver for the watchdog timer built into the Intel 1015 Hardware driver for the watchdog timer built into the Intel
1013 6300ESB controller hub. 1016 6300ESB controller hub.
@@ -1837,6 +1840,7 @@ config WATCHDOG_SUN4V
1837config XEN_WDT 1840config XEN_WDT
1838 tristate "Xen Watchdog support" 1841 tristate "Xen Watchdog support"
1839 depends on XEN 1842 depends on XEN
1843 select WATCHDOG_CORE
1840 help 1844 help
1841 Say Y here to support the hypervisor watchdog capability provided 1845 Say Y here to support the hypervisor watchdog capability provided
1842 by Xen 4.0 and newer. The watchdog timeout period is normally one 1846 by Xen 4.0 and newer. The watchdog timeout period is normally one
diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c
index e0678c14480f..3a33c5344bd5 100644
--- a/drivers/watchdog/f71808e_wdt.c
+++ b/drivers/watchdog/f71808e_wdt.c
@@ -566,7 +566,8 @@ static ssize_t watchdog_write(struct file *file, const char __user *buf,
566 char c; 566 char c;
567 if (get_user(c, buf + i)) 567 if (get_user(c, buf + i))
568 return -EFAULT; 568 return -EFAULT;
569 expect_close = (c == 'V'); 569 if (c == 'V')
570 expect_close = true;
570 } 571 }
571 572
572 /* Properly order writes across fork()ed processes */ 573 /* Properly order writes across fork()ed processes */
diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c
index f1f00dfc0e68..b0a158073abd 100644
--- a/drivers/watchdog/hpwdt.c
+++ b/drivers/watchdog/hpwdt.c
@@ -28,16 +28,7 @@
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/uaccess.h> 29#include <linux/uaccess.h>
30#include <linux/watchdog.h> 30#include <linux/watchdog.h>
31#ifdef CONFIG_HPWDT_NMI_DECODING
32#include <linux/dmi.h>
33#include <linux/spinlock.h>
34#include <linux/nmi.h>
35#include <linux/kdebug.h>
36#include <linux/notifier.h>
37#include <asm/set_memory.h>
38#endif /* CONFIG_HPWDT_NMI_DECODING */
39#include <asm/nmi.h> 31#include <asm/nmi.h>
40#include <asm/frame.h>
41 32
42#define HPWDT_VERSION "1.4.0" 33#define HPWDT_VERSION "1.4.0"
43#define SECS_TO_TICKS(secs) ((secs) * 1000 / 128) 34#define SECS_TO_TICKS(secs) ((secs) * 1000 / 128)
@@ -48,6 +39,9 @@
48static unsigned int soft_margin = DEFAULT_MARGIN; /* in seconds */ 39static unsigned int soft_margin = DEFAULT_MARGIN; /* in seconds */
49static unsigned int reload; /* the computed soft_margin */ 40static unsigned int reload; /* the computed soft_margin */
50static bool nowayout = WATCHDOG_NOWAYOUT; 41static bool nowayout = WATCHDOG_NOWAYOUT;
42#ifdef CONFIG_HPWDT_NMI_DECODING
43static unsigned int allow_kdump = 1;
44#endif
51static char expect_release; 45static char expect_release;
52static unsigned long hpwdt_is_open; 46static unsigned long hpwdt_is_open;
53 47
@@ -63,373 +57,6 @@ static const struct pci_device_id hpwdt_devices[] = {
63}; 57};
64MODULE_DEVICE_TABLE(pci, hpwdt_devices); 58MODULE_DEVICE_TABLE(pci, hpwdt_devices);
65 59
66#ifdef CONFIG_HPWDT_NMI_DECODING
67#define PCI_BIOS32_SD_VALUE 0x5F32335F /* "_32_" */
68#define CRU_BIOS_SIGNATURE_VALUE 0x55524324
69#define PCI_BIOS32_PARAGRAPH_LEN 16
70#define PCI_ROM_BASE1 0x000F0000
71#define ROM_SIZE 0x10000
72
73struct bios32_service_dir {
74 u32 signature;
75 u32 entry_point;
76 u8 revision;
77 u8 length;
78 u8 checksum;
79 u8 reserved[5];
80};
81
82/* type 212 */
83struct smbios_cru64_info {
84 u8 type;
85 u8 byte_length;
86 u16 handle;
87 u32 signature;
88 u64 physical_address;
89 u32 double_length;
90 u32 double_offset;
91};
92#define SMBIOS_CRU64_INFORMATION 212
93
94/* type 219 */
95struct smbios_proliant_info {
96 u8 type;
97 u8 byte_length;
98 u16 handle;
99 u32 power_features;
100 u32 omega_features;
101 u32 reserved;
102 u32 misc_features;
103};
104#define SMBIOS_ICRU_INFORMATION 219
105
106
107struct cmn_registers {
108 union {
109 struct {
110 u8 ral;
111 u8 rah;
112 u16 rea2;
113 };
114 u32 reax;
115 } u1;
116 union {
117 struct {
118 u8 rbl;
119 u8 rbh;
120 u8 reb2l;
121 u8 reb2h;
122 };
123 u32 rebx;
124 } u2;
125 union {
126 struct {
127 u8 rcl;
128 u8 rch;
129 u16 rec2;
130 };
131 u32 recx;
132 } u3;
133 union {
134 struct {
135 u8 rdl;
136 u8 rdh;
137 u16 red2;
138 };
139 u32 redx;
140 } u4;
141
142 u32 resi;
143 u32 redi;
144 u16 rds;
145 u16 res;
146 u32 reflags;
147} __attribute__((packed));
148
149static unsigned int hpwdt_nmi_decoding;
150static unsigned int allow_kdump = 1;
151static unsigned int is_icru;
152static unsigned int is_uefi;
153static DEFINE_SPINLOCK(rom_lock);
154static void *cru_rom_addr;
155static struct cmn_registers cmn_regs;
156
157extern asmlinkage void asminline_call(struct cmn_registers *pi86Regs,
158 unsigned long *pRomEntry);
159
160#ifdef CONFIG_X86_32
161/* --32 Bit Bios------------------------------------------------------------ */
162
163#define HPWDT_ARCH 32
164
165asm(".text \n\t"
166 ".align 4 \n\t"
167 ".globl asminline_call \n"
168 "asminline_call: \n\t"
169 "pushl %ebp \n\t"
170 "movl %esp, %ebp \n\t"
171 "pusha \n\t"
172 "pushf \n\t"
173 "push %es \n\t"
174 "push %ds \n\t"
175 "pop %es \n\t"
176 "movl 8(%ebp),%eax \n\t"
177 "movl 4(%eax),%ebx \n\t"
178 "movl 8(%eax),%ecx \n\t"
179 "movl 12(%eax),%edx \n\t"
180 "movl 16(%eax),%esi \n\t"
181 "movl 20(%eax),%edi \n\t"
182 "movl (%eax),%eax \n\t"
183 "push %cs \n\t"
184 "call *12(%ebp) \n\t"
185 "pushf \n\t"
186 "pushl %eax \n\t"
187 "movl 8(%ebp),%eax \n\t"
188 "movl %ebx,4(%eax) \n\t"
189 "movl %ecx,8(%eax) \n\t"
190 "movl %edx,12(%eax) \n\t"
191 "movl %esi,16(%eax) \n\t"
192 "movl %edi,20(%eax) \n\t"
193 "movw %ds,24(%eax) \n\t"
194 "movw %es,26(%eax) \n\t"
195 "popl %ebx \n\t"
196 "movl %ebx,(%eax) \n\t"
197 "popl %ebx \n\t"
198 "movl %ebx,28(%eax) \n\t"
199 "pop %es \n\t"
200 "popf \n\t"
201 "popa \n\t"
202 "leave \n\t"
203 "ret \n\t"
204 ".previous");
205
206
207/*
208 * cru_detect
209 *
210 * Routine Description:
211 * This function uses the 32-bit BIOS Service Directory record to
212 * search for a $CRU record.
213 *
214 * Return Value:
215 * 0 : SUCCESS
216 * <0 : FAILURE
217 */
218static int cru_detect(unsigned long map_entry,
219 unsigned long map_offset)
220{
221 void *bios32_map;
222 unsigned long *bios32_entrypoint;
223 unsigned long cru_physical_address;
224 unsigned long cru_length;
225 unsigned long physical_bios_base = 0;
226 unsigned long physical_bios_offset = 0;
227 int retval = -ENODEV;
228
229 bios32_map = ioremap(map_entry, (2 * PAGE_SIZE));
230
231 if (bios32_map == NULL)
232 return -ENODEV;
233
234 bios32_entrypoint = bios32_map + map_offset;
235
236 cmn_regs.u1.reax = CRU_BIOS_SIGNATURE_VALUE;
237
238 set_memory_x((unsigned long)bios32_map, 2);
239 asminline_call(&cmn_regs, bios32_entrypoint);
240
241 if (cmn_regs.u1.ral != 0) {
242 pr_warn("Call succeeded but with an error: 0x%x\n",
243 cmn_regs.u1.ral);
244 } else {
245 physical_bios_base = cmn_regs.u2.rebx;
246 physical_bios_offset = cmn_regs.u4.redx;
247 cru_length = cmn_regs.u3.recx;
248 cru_physical_address =
249 physical_bios_base + physical_bios_offset;
250
251 /* If the values look OK, then map it in. */
252 if ((physical_bios_base + physical_bios_offset)) {
253 cru_rom_addr =
254 ioremap(cru_physical_address, cru_length);
255 if (cru_rom_addr) {
256 set_memory_x((unsigned long)cru_rom_addr & PAGE_MASK,
257 (cru_length + PAGE_SIZE - 1) >> PAGE_SHIFT);
258 retval = 0;
259 }
260 }
261
262 pr_debug("CRU Base Address: 0x%lx\n", physical_bios_base);
263 pr_debug("CRU Offset Address: 0x%lx\n", physical_bios_offset);
264 pr_debug("CRU Length: 0x%lx\n", cru_length);
265 pr_debug("CRU Mapped Address: %p\n", &cru_rom_addr);
266 }
267 iounmap(bios32_map);
268 return retval;
269}
270
271/*
272 * bios_checksum
273 */
274static int bios_checksum(const char __iomem *ptr, int len)
275{
276 char sum = 0;
277 int i;
278
279 /*
280 * calculate checksum of size bytes. This should add up
281 * to zero if we have a valid header.
282 */
283 for (i = 0; i < len; i++)
284 sum += ptr[i];
285
286 return ((sum == 0) && (len > 0));
287}
288
289/*
290 * bios32_present
291 *
292 * Routine Description:
293 * This function finds the 32-bit BIOS Service Directory
294 *
295 * Return Value:
296 * 0 : SUCCESS
297 * <0 : FAILURE
298 */
299static int bios32_present(const char __iomem *p)
300{
301 struct bios32_service_dir *bios_32_ptr;
302 int length;
303 unsigned long map_entry, map_offset;
304
305 bios_32_ptr = (struct bios32_service_dir *) p;
306
307 /*
308 * Search for signature by checking equal to the swizzled value
309 * instead of calling another routine to perform a strcmp.
310 */
311 if (bios_32_ptr->signature == PCI_BIOS32_SD_VALUE) {
312 length = bios_32_ptr->length * PCI_BIOS32_PARAGRAPH_LEN;
313 if (bios_checksum(p, length)) {
314 /*
315 * According to the spec, we're looking for the
316 * first 4KB-aligned address below the entrypoint
317 * listed in the header. The Service Directory code
318 * is guaranteed to occupy no more than 2 4KB pages.
319 */
320 map_entry = bios_32_ptr->entry_point & ~(PAGE_SIZE - 1);
321 map_offset = bios_32_ptr->entry_point - map_entry;
322
323 return cru_detect(map_entry, map_offset);
324 }
325 }
326 return -ENODEV;
327}
328
329static int detect_cru_service(void)
330{
331 char __iomem *p, *q;
332 int rc = -1;
333
334 /*
335 * Search from 0x0f0000 through 0x0fffff, inclusive.
336 */
337 p = ioremap(PCI_ROM_BASE1, ROM_SIZE);
338 if (p == NULL)
339 return -ENOMEM;
340
341 for (q = p; q < p + ROM_SIZE; q += 16) {
342 rc = bios32_present(q);
343 if (!rc)
344 break;
345 }
346 iounmap(p);
347 return rc;
348}
349/* ------------------------------------------------------------------------- */
350#endif /* CONFIG_X86_32 */
351#ifdef CONFIG_X86_64
352/* --64 Bit Bios------------------------------------------------------------ */
353
354#define HPWDT_ARCH 64
355
356asm(".text \n\t"
357 ".align 4 \n\t"
358 ".globl asminline_call \n\t"
359 ".type asminline_call, @function \n\t"
360 "asminline_call: \n\t"
361 FRAME_BEGIN
362 "pushq %rax \n\t"
363 "pushq %rbx \n\t"
364 "pushq %rdx \n\t"
365 "pushq %r12 \n\t"
366 "pushq %r9 \n\t"
367 "movq %rsi, %r12 \n\t"
368 "movq %rdi, %r9 \n\t"
369 "movl 4(%r9),%ebx \n\t"
370 "movl 8(%r9),%ecx \n\t"
371 "movl 12(%r9),%edx \n\t"
372 "movl 16(%r9),%esi \n\t"
373 "movl 20(%r9),%edi \n\t"
374 "movl (%r9),%eax \n\t"
375 "call *%r12 \n\t"
376 "pushfq \n\t"
377 "popq %r12 \n\t"
378 "movl %eax, (%r9) \n\t"
379 "movl %ebx, 4(%r9) \n\t"
380 "movl %ecx, 8(%r9) \n\t"
381 "movl %edx, 12(%r9) \n\t"
382 "movl %esi, 16(%r9) \n\t"
383 "movl %edi, 20(%r9) \n\t"
384 "movq %r12, %rax \n\t"
385 "movl %eax, 28(%r9) \n\t"
386 "popq %r9 \n\t"
387 "popq %r12 \n\t"
388 "popq %rdx \n\t"
389 "popq %rbx \n\t"
390 "popq %rax \n\t"
391 FRAME_END
392 "ret \n\t"
393 ".previous");
394
395/*
396 * dmi_find_cru
397 *
398 * Routine Description:
399 * This function checks whether or not a SMBIOS/DMI record is
400 * the 64bit CRU info or not
401 */
402static void dmi_find_cru(const struct dmi_header *dm, void *dummy)
403{
404 struct smbios_cru64_info *smbios_cru64_ptr;
405 unsigned long cru_physical_address;
406
407 if (dm->type == SMBIOS_CRU64_INFORMATION) {
408 smbios_cru64_ptr = (struct smbios_cru64_info *) dm;
409 if (smbios_cru64_ptr->signature == CRU_BIOS_SIGNATURE_VALUE) {
410 cru_physical_address =
411 smbios_cru64_ptr->physical_address +
412 smbios_cru64_ptr->double_offset;
413 cru_rom_addr = ioremap(cru_physical_address,
414 smbios_cru64_ptr->double_length);
415 set_memory_x((unsigned long)cru_rom_addr & PAGE_MASK,
416 smbios_cru64_ptr->double_length >> PAGE_SHIFT);
417 }
418 }
419}
420
421static int detect_cru_service(void)
422{
423 cru_rom_addr = NULL;
424
425 dmi_walk(dmi_find_cru, NULL);
426
427 /* if cru_rom_addr has been set then we found a CRU service */
428 return ((cru_rom_addr != NULL) ? 0 : -ENODEV);
429}
430/* ------------------------------------------------------------------------- */
431#endif /* CONFIG_X86_64 */
432#endif /* CONFIG_HPWDT_NMI_DECODING */
433 60
434/* 61/*
435 * Watchdog operations 62 * Watchdog operations
@@ -486,30 +113,12 @@ static int hpwdt_my_nmi(void)
486 */ 113 */
487static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs) 114static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs)
488{ 115{
489 unsigned long rom_pl;
490 static int die_nmi_called;
491
492 if (!hpwdt_nmi_decoding)
493 return NMI_DONE;
494
495 if ((ulReason == NMI_UNKNOWN) && !hpwdt_my_nmi()) 116 if ((ulReason == NMI_UNKNOWN) && !hpwdt_my_nmi())
496 return NMI_DONE; 117 return NMI_DONE;
497 118
498 spin_lock_irqsave(&rom_lock, rom_pl);
499 if (!die_nmi_called && !is_icru && !is_uefi)
500 asminline_call(&cmn_regs, cru_rom_addr);
501 die_nmi_called = 1;
502 spin_unlock_irqrestore(&rom_lock, rom_pl);
503
504 if (allow_kdump) 119 if (allow_kdump)
505 hpwdt_stop(); 120 hpwdt_stop();
506 121
507 if (!is_icru && !is_uefi) {
508 if (cmn_regs.u1.ral == 0) {
509 nmi_panic(regs, "An NMI occurred, but unable to determine source.\n");
510 return NMI_HANDLED;
511 }
512 }
513 nmi_panic(regs, "An NMI occurred. Depending on your system the reason " 122 nmi_panic(regs, "An NMI occurred. Depending on your system the reason "
514 "for the NMI is logged in any one of the following " 123 "for the NMI is logged in any one of the following "
515 "resources:\n" 124 "resources:\n"
@@ -675,84 +284,11 @@ static struct miscdevice hpwdt_miscdev = {
675 * Init & Exit 284 * Init & Exit
676 */ 285 */
677 286
678#ifdef CONFIG_HPWDT_NMI_DECODING
679#ifdef CONFIG_X86_LOCAL_APIC
680static void hpwdt_check_nmi_decoding(struct pci_dev *dev)
681{
682 /*
683 * If nmi_watchdog is turned off then we can turn on
684 * our nmi decoding capability.
685 */
686 hpwdt_nmi_decoding = 1;
687}
688#else
689static void hpwdt_check_nmi_decoding(struct pci_dev *dev)
690{
691 dev_warn(&dev->dev, "NMI decoding is disabled. "
692 "Your kernel does not support a NMI Watchdog.\n");
693}
694#endif /* CONFIG_X86_LOCAL_APIC */
695
696/*
697 * dmi_find_icru
698 *
699 * Routine Description:
700 * This function checks whether or not we are on an iCRU-based server.
701 * This check is independent of architecture and needs to be made for
702 * any ProLiant system.
703 */
704static void dmi_find_icru(const struct dmi_header *dm, void *dummy)
705{
706 struct smbios_proliant_info *smbios_proliant_ptr;
707
708 if (dm->type == SMBIOS_ICRU_INFORMATION) {
709 smbios_proliant_ptr = (struct smbios_proliant_info *) dm;
710 if (smbios_proliant_ptr->misc_features & 0x01)
711 is_icru = 1;
712 if (smbios_proliant_ptr->misc_features & 0x1400)
713 is_uefi = 1;
714 }
715}
716 287
717static int hpwdt_init_nmi_decoding(struct pci_dev *dev) 288static int hpwdt_init_nmi_decoding(struct pci_dev *dev)
718{ 289{
290#ifdef CONFIG_HPWDT_NMI_DECODING
719 int retval; 291 int retval;
720
721 /*
722 * On typical CRU-based systems we need to map that service in
723 * the BIOS. For 32 bit Operating Systems we need to go through
724 * the 32 Bit BIOS Service Directory. For 64 bit Operating
725 * Systems we get that service through SMBIOS.
726 *
727 * On systems that support the new iCRU service all we need to
728 * do is call dmi_walk to get the supported flag value and skip
729 * the old cru detect code.
730 */
731 dmi_walk(dmi_find_icru, NULL);
732 if (!is_icru && !is_uefi) {
733
734 /*
735 * We need to map the ROM to get the CRU service.
736 * For 32 bit Operating Systems we need to go through the 32 Bit
737 * BIOS Service Directory
738 * For 64 bit Operating Systems we get that service through SMBIOS.
739 */
740 retval = detect_cru_service();
741 if (retval < 0) {
742 dev_warn(&dev->dev,
743 "Unable to detect the %d Bit CRU Service.\n",
744 HPWDT_ARCH);
745 return retval;
746 }
747
748 /*
749 * We know this is the only CRU call we need to make so lets keep as
750 * few instructions as possible once the NMI comes in.
751 */
752 cmn_regs.u1.rah = 0x0D;
753 cmn_regs.u1.ral = 0x02;
754 }
755
756 /* 292 /*
757 * Only one function can register for NMI_UNKNOWN 293 * Only one function can register for NMI_UNKNOWN
758 */ 294 */
@@ -780,45 +316,26 @@ error:
780 dev_warn(&dev->dev, 316 dev_warn(&dev->dev,
781 "Unable to register a die notifier (err=%d).\n", 317 "Unable to register a die notifier (err=%d).\n",
782 retval); 318 retval);
783 if (cru_rom_addr)
784 iounmap(cru_rom_addr);
785 return retval; 319 return retval;
320#endif /* CONFIG_HPWDT_NMI_DECODING */
321 return 0;
786} 322}
787 323
788static void hpwdt_exit_nmi_decoding(void) 324static void hpwdt_exit_nmi_decoding(void)
789{ 325{
326#ifdef CONFIG_HPWDT_NMI_DECODING
790 unregister_nmi_handler(NMI_UNKNOWN, "hpwdt"); 327 unregister_nmi_handler(NMI_UNKNOWN, "hpwdt");
791 unregister_nmi_handler(NMI_SERR, "hpwdt"); 328 unregister_nmi_handler(NMI_SERR, "hpwdt");
792 unregister_nmi_handler(NMI_IO_CHECK, "hpwdt"); 329 unregister_nmi_handler(NMI_IO_CHECK, "hpwdt");
793 if (cru_rom_addr) 330#endif
794 iounmap(cru_rom_addr);
795}
796#else /* !CONFIG_HPWDT_NMI_DECODING */
797static void hpwdt_check_nmi_decoding(struct pci_dev *dev)
798{
799}
800
801static int hpwdt_init_nmi_decoding(struct pci_dev *dev)
802{
803 return 0;
804} 331}
805 332
806static void hpwdt_exit_nmi_decoding(void)
807{
808}
809#endif /* CONFIG_HPWDT_NMI_DECODING */
810
811static int hpwdt_init_one(struct pci_dev *dev, 333static int hpwdt_init_one(struct pci_dev *dev,
812 const struct pci_device_id *ent) 334 const struct pci_device_id *ent)
813{ 335{
814 int retval; 336 int retval;
815 337
816 /* 338 /*
817 * Check if we can do NMI decoding or not
818 */
819 hpwdt_check_nmi_decoding(dev);
820
821 /*
822 * First let's find out if we are on an iLO2+ server. We will 339 * First let's find out if we are on an iLO2+ server. We will
823 * not run on a legacy ASM box. 340 * not run on a legacy ASM box.
824 * So we only support the G5 ProLiant servers and higher. 341 * So we only support the G5 ProLiant servers and higher.
@@ -922,6 +439,6 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
922#ifdef CONFIG_HPWDT_NMI_DECODING 439#ifdef CONFIG_HPWDT_NMI_DECODING
923module_param(allow_kdump, int, 0); 440module_param(allow_kdump, int, 0);
924MODULE_PARM_DESC(allow_kdump, "Start a kernel dump after NMI occurs"); 441MODULE_PARM_DESC(allow_kdump, "Start a kernel dump after NMI occurs");
925#endif /* !CONFIG_HPWDT_NMI_DECODING */ 442#endif /* CONFIG_HPWDT_NMI_DECODING */
926 443
927module_pci_driver(hpwdt_driver); 444module_pci_driver(hpwdt_driver);
diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
index 316c2eb122d2..e8bd9887c566 100644
--- a/drivers/watchdog/sbsa_gwdt.c
+++ b/drivers/watchdog/sbsa_gwdt.c
@@ -50,6 +50,7 @@
50 */ 50 */
51 51
52#include <linux/io.h> 52#include <linux/io.h>
53#include <linux/io-64-nonatomic-lo-hi.h>
53#include <linux/interrupt.h> 54#include <linux/interrupt.h>
54#include <linux/module.h> 55#include <linux/module.h>
55#include <linux/moduleparam.h> 56#include <linux/moduleparam.h>
@@ -159,7 +160,7 @@ static unsigned int sbsa_gwdt_get_timeleft(struct watchdog_device *wdd)
159 !(readl(gwdt->control_base + SBSA_GWDT_WCS) & SBSA_GWDT_WCS_WS0)) 160 !(readl(gwdt->control_base + SBSA_GWDT_WCS) & SBSA_GWDT_WCS_WS0))
160 timeleft += readl(gwdt->control_base + SBSA_GWDT_WOR); 161 timeleft += readl(gwdt->control_base + SBSA_GWDT_WOR);
161 162
162 timeleft += readq(gwdt->control_base + SBSA_GWDT_WCV) - 163 timeleft += lo_hi_readq(gwdt->control_base + SBSA_GWDT_WCV) -
163 arch_counter_get_cntvct(); 164 arch_counter_get_cntvct();
164 165
165 do_div(timeleft, gwdt->clk); 166 do_div(timeleft, gwdt->clk);
diff --git a/drivers/watchdog/wdat_wdt.c b/drivers/watchdog/wdat_wdt.c
index 6d1fbda0f461..0da9943d405f 100644
--- a/drivers/watchdog/wdat_wdt.c
+++ b/drivers/watchdog/wdat_wdt.c
@@ -392,7 +392,7 @@ static int wdat_wdt_probe(struct platform_device *pdev)
392 392
393 memset(&r, 0, sizeof(r)); 393 memset(&r, 0, sizeof(r));
394 r.start = gas->address; 394 r.start = gas->address;
395 r.end = r.start + gas->access_width; 395 r.end = r.start + gas->access_width - 1;
396 if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 396 if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
397 r.flags = IORESOURCE_MEM; 397 r.flags = IORESOURCE_MEM;
398 } else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { 398 } else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 1ab4bd11f5f3..762378f1811c 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -755,8 +755,8 @@ out:
755 mutex_unlock(&irq_mapping_update_lock); 755 mutex_unlock(&irq_mapping_update_lock);
756 return irq; 756 return irq;
757error_irq: 757error_irq:
758 for (; i >= 0; i--) 758 while (nvec--)
759 __unbind_from_irq(irq + i); 759 __unbind_from_irq(irq + nvec);
760 mutex_unlock(&irq_mapping_update_lock); 760 mutex_unlock(&irq_mapping_update_lock);
761 return ret; 761 return ret;
762} 762}
diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c
index 156e5aea36db..b1092fbefa63 100644
--- a/drivers/xen/pvcalls-back.c
+++ b/drivers/xen/pvcalls-back.c
@@ -416,7 +416,7 @@ static int pvcalls_back_connect(struct xenbus_device *dev,
416 sock); 416 sock);
417 if (!map) { 417 if (!map) {
418 ret = -EFAULT; 418 ret = -EFAULT;
419 sock_release(map->sock); 419 sock_release(sock);
420 } 420 }
421 421
422out: 422out:
diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 753d9cb437d0..2f11ca72a281 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -60,6 +60,7 @@ struct sock_mapping {
60 bool active_socket; 60 bool active_socket;
61 struct list_head list; 61 struct list_head list;
62 struct socket *sock; 62 struct socket *sock;
63 atomic_t refcount;
63 union { 64 union {
64 struct { 65 struct {
65 int irq; 66 int irq;
@@ -72,20 +73,25 @@ struct sock_mapping {
72 wait_queue_head_t inflight_conn_req; 73 wait_queue_head_t inflight_conn_req;
73 } active; 74 } active;
74 struct { 75 struct {
75 /* Socket status */ 76 /*
77 * Socket status, needs to be 64-bit aligned due to the
78 * test_and_* functions which have this requirement on arm64.
79 */
76#define PVCALLS_STATUS_UNINITALIZED 0 80#define PVCALLS_STATUS_UNINITALIZED 0
77#define PVCALLS_STATUS_BIND 1 81#define PVCALLS_STATUS_BIND 1
78#define PVCALLS_STATUS_LISTEN 2 82#define PVCALLS_STATUS_LISTEN 2
79 uint8_t status; 83 uint8_t status __attribute__((aligned(8)));
80 /* 84 /*
81 * Internal state-machine flags. 85 * Internal state-machine flags.
82 * Only one accept operation can be inflight for a socket. 86 * Only one accept operation can be inflight for a socket.
83 * Only one poll operation can be inflight for a given socket. 87 * Only one poll operation can be inflight for a given socket.
88 * flags needs to be 64-bit aligned due to the test_and_*
89 * functions which have this requirement on arm64.
84 */ 90 */
85#define PVCALLS_FLAG_ACCEPT_INFLIGHT 0 91#define PVCALLS_FLAG_ACCEPT_INFLIGHT 0
86#define PVCALLS_FLAG_POLL_INFLIGHT 1 92#define PVCALLS_FLAG_POLL_INFLIGHT 1
87#define PVCALLS_FLAG_POLL_RET 2 93#define PVCALLS_FLAG_POLL_RET 2
88 uint8_t flags; 94 uint8_t flags __attribute__((aligned(8)));
89 uint32_t inflight_req_id; 95 uint32_t inflight_req_id;
90 struct sock_mapping *accept_map; 96 struct sock_mapping *accept_map;
91 wait_queue_head_t inflight_accept_req; 97 wait_queue_head_t inflight_accept_req;
@@ -93,6 +99,32 @@ struct sock_mapping {
93 }; 99 };
94}; 100};
95 101
102static inline struct sock_mapping *pvcalls_enter_sock(struct socket *sock)
103{
104 struct sock_mapping *map;
105
106 if (!pvcalls_front_dev ||
107 dev_get_drvdata(&pvcalls_front_dev->dev) == NULL)
108 return ERR_PTR(-ENOTCONN);
109
110 map = (struct sock_mapping *)sock->sk->sk_send_head;
111 if (map == NULL)
112 return ERR_PTR(-ENOTSOCK);
113
114 pvcalls_enter();
115 atomic_inc(&map->refcount);
116 return map;
117}
118
119static inline void pvcalls_exit_sock(struct socket *sock)
120{
121 struct sock_mapping *map;
122
123 map = (struct sock_mapping *)sock->sk->sk_send_head;
124 atomic_dec(&map->refcount);
125 pvcalls_exit();
126}
127
96static inline int get_request(struct pvcalls_bedata *bedata, int *req_id) 128static inline int get_request(struct pvcalls_bedata *bedata, int *req_id)
97{ 129{
98 *req_id = bedata->ring.req_prod_pvt & (RING_SIZE(&bedata->ring) - 1); 130 *req_id = bedata->ring.req_prod_pvt & (RING_SIZE(&bedata->ring) - 1);
@@ -369,31 +401,23 @@ int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr,
369 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) 401 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM)
370 return -EOPNOTSUPP; 402 return -EOPNOTSUPP;
371 403
372 pvcalls_enter(); 404 map = pvcalls_enter_sock(sock);
373 if (!pvcalls_front_dev) { 405 if (IS_ERR(map))
374 pvcalls_exit(); 406 return PTR_ERR(map);
375 return -ENOTCONN;
376 }
377 407
378 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); 408 bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
379 409
380 map = (struct sock_mapping *)sock->sk->sk_send_head;
381 if (!map) {
382 pvcalls_exit();
383 return -ENOTSOCK;
384 }
385
386 spin_lock(&bedata->socket_lock); 410 spin_lock(&bedata->socket_lock);
387 ret = get_request(bedata, &req_id); 411 ret = get_request(bedata, &req_id);
388 if (ret < 0) { 412 if (ret < 0) {
389 spin_unlock(&bedata->socket_lock); 413 spin_unlock(&bedata->socket_lock);
390 pvcalls_exit(); 414 pvcalls_exit_sock(sock);
391 return ret; 415 return ret;
392 } 416 }
393 ret = create_active(map, &evtchn); 417 ret = create_active(map, &evtchn);
394 if (ret < 0) { 418 if (ret < 0) {
395 spin_unlock(&bedata->socket_lock); 419 spin_unlock(&bedata->socket_lock);
396 pvcalls_exit(); 420 pvcalls_exit_sock(sock);
397 return ret; 421 return ret;
398 } 422 }
399 423
@@ -423,7 +447,7 @@ int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr,
423 smp_rmb(); 447 smp_rmb();
424 ret = bedata->rsp[req_id].ret; 448 ret = bedata->rsp[req_id].ret;
425 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; 449 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID;
426 pvcalls_exit(); 450 pvcalls_exit_sock(sock);
427 return ret; 451 return ret;
428} 452}
429 453
@@ -488,23 +512,15 @@ int pvcalls_front_sendmsg(struct socket *sock, struct msghdr *msg,
488 if (flags & (MSG_CONFIRM|MSG_DONTROUTE|MSG_EOR|MSG_OOB)) 512 if (flags & (MSG_CONFIRM|MSG_DONTROUTE|MSG_EOR|MSG_OOB))
489 return -EOPNOTSUPP; 513 return -EOPNOTSUPP;
490 514
491 pvcalls_enter(); 515 map = pvcalls_enter_sock(sock);
492 if (!pvcalls_front_dev) { 516 if (IS_ERR(map))
493 pvcalls_exit(); 517 return PTR_ERR(map);
494 return -ENOTCONN;
495 }
496 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); 518 bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
497 519
498 map = (struct sock_mapping *) sock->sk->sk_send_head;
499 if (!map) {
500 pvcalls_exit();
501 return -ENOTSOCK;
502 }
503
504 mutex_lock(&map->active.out_mutex); 520 mutex_lock(&map->active.out_mutex);
505 if ((flags & MSG_DONTWAIT) && !pvcalls_front_write_todo(map)) { 521 if ((flags & MSG_DONTWAIT) && !pvcalls_front_write_todo(map)) {
506 mutex_unlock(&map->active.out_mutex); 522 mutex_unlock(&map->active.out_mutex);
507 pvcalls_exit(); 523 pvcalls_exit_sock(sock);
508 return -EAGAIN; 524 return -EAGAIN;
509 } 525 }
510 if (len > INT_MAX) 526 if (len > INT_MAX)
@@ -526,7 +542,7 @@ again:
526 tot_sent = sent; 542 tot_sent = sent;
527 543
528 mutex_unlock(&map->active.out_mutex); 544 mutex_unlock(&map->active.out_mutex);
529 pvcalls_exit(); 545 pvcalls_exit_sock(sock);
530 return tot_sent; 546 return tot_sent;
531} 547}
532 548
@@ -591,19 +607,11 @@ int pvcalls_front_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
591 if (flags & (MSG_CMSG_CLOEXEC|MSG_ERRQUEUE|MSG_OOB|MSG_TRUNC)) 607 if (flags & (MSG_CMSG_CLOEXEC|MSG_ERRQUEUE|MSG_OOB|MSG_TRUNC))
592 return -EOPNOTSUPP; 608 return -EOPNOTSUPP;
593 609
594 pvcalls_enter(); 610 map = pvcalls_enter_sock(sock);
595 if (!pvcalls_front_dev) { 611 if (IS_ERR(map))
596 pvcalls_exit(); 612 return PTR_ERR(map);
597 return -ENOTCONN;
598 }
599 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); 613 bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
600 614
601 map = (struct sock_mapping *) sock->sk->sk_send_head;
602 if (!map) {
603 pvcalls_exit();
604 return -ENOTSOCK;
605 }
606
607 mutex_lock(&map->active.in_mutex); 615 mutex_lock(&map->active.in_mutex);
608 if (len > XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER)) 616 if (len > XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER))
609 len = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER); 617 len = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
@@ -623,7 +631,7 @@ int pvcalls_front_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
623 ret = 0; 631 ret = 0;
624 632
625 mutex_unlock(&map->active.in_mutex); 633 mutex_unlock(&map->active.in_mutex);
626 pvcalls_exit(); 634 pvcalls_exit_sock(sock);
627 return ret; 635 return ret;
628} 636}
629 637
@@ -637,24 +645,16 @@ int pvcalls_front_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
637 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) 645 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM)
638 return -EOPNOTSUPP; 646 return -EOPNOTSUPP;
639 647
640 pvcalls_enter(); 648 map = pvcalls_enter_sock(sock);
641 if (!pvcalls_front_dev) { 649 if (IS_ERR(map))
642 pvcalls_exit(); 650 return PTR_ERR(map);
643 return -ENOTCONN;
644 }
645 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); 651 bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
646 652
647 map = (struct sock_mapping *) sock->sk->sk_send_head;
648 if (map == NULL) {
649 pvcalls_exit();
650 return -ENOTSOCK;
651 }
652
653 spin_lock(&bedata->socket_lock); 653 spin_lock(&bedata->socket_lock);
654 ret = get_request(bedata, &req_id); 654 ret = get_request(bedata, &req_id);
655 if (ret < 0) { 655 if (ret < 0) {
656 spin_unlock(&bedata->socket_lock); 656 spin_unlock(&bedata->socket_lock);
657 pvcalls_exit(); 657 pvcalls_exit_sock(sock);
658 return ret; 658 return ret;
659 } 659 }
660 req = RING_GET_REQUEST(&bedata->ring, req_id); 660 req = RING_GET_REQUEST(&bedata->ring, req_id);
@@ -684,7 +684,7 @@ int pvcalls_front_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
684 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; 684 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID;
685 685
686 map->passive.status = PVCALLS_STATUS_BIND; 686 map->passive.status = PVCALLS_STATUS_BIND;
687 pvcalls_exit(); 687 pvcalls_exit_sock(sock);
688 return 0; 688 return 0;
689} 689}
690 690
@@ -695,21 +695,13 @@ int pvcalls_front_listen(struct socket *sock, int backlog)
695 struct xen_pvcalls_request *req; 695 struct xen_pvcalls_request *req;
696 int notify, req_id, ret; 696 int notify, req_id, ret;
697 697
698 pvcalls_enter(); 698 map = pvcalls_enter_sock(sock);
699 if (!pvcalls_front_dev) { 699 if (IS_ERR(map))
700 pvcalls_exit(); 700 return PTR_ERR(map);
701 return -ENOTCONN;
702 }
703 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); 701 bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
704 702
705 map = (struct sock_mapping *) sock->sk->sk_send_head;
706 if (!map) {
707 pvcalls_exit();
708 return -ENOTSOCK;
709 }
710
711 if (map->passive.status != PVCALLS_STATUS_BIND) { 703 if (map->passive.status != PVCALLS_STATUS_BIND) {
712 pvcalls_exit(); 704 pvcalls_exit_sock(sock);
713 return -EOPNOTSUPP; 705 return -EOPNOTSUPP;
714 } 706 }
715 707
@@ -717,7 +709,7 @@ int pvcalls_front_listen(struct socket *sock, int backlog)
717 ret = get_request(bedata, &req_id); 709 ret = get_request(bedata, &req_id);
718 if (ret < 0) { 710 if (ret < 0) {
719 spin_unlock(&bedata->socket_lock); 711 spin_unlock(&bedata->socket_lock);
720 pvcalls_exit(); 712 pvcalls_exit_sock(sock);
721 return ret; 713 return ret;
722 } 714 }
723 req = RING_GET_REQUEST(&bedata->ring, req_id); 715 req = RING_GET_REQUEST(&bedata->ring, req_id);
@@ -741,7 +733,7 @@ int pvcalls_front_listen(struct socket *sock, int backlog)
741 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; 733 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID;
742 734
743 map->passive.status = PVCALLS_STATUS_LISTEN; 735 map->passive.status = PVCALLS_STATUS_LISTEN;
744 pvcalls_exit(); 736 pvcalls_exit_sock(sock);
745 return ret; 737 return ret;
746} 738}
747 739
@@ -753,21 +745,13 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int flags)
753 struct xen_pvcalls_request *req; 745 struct xen_pvcalls_request *req;
754 int notify, req_id, ret, evtchn, nonblock; 746 int notify, req_id, ret, evtchn, nonblock;
755 747
756 pvcalls_enter(); 748 map = pvcalls_enter_sock(sock);
757 if (!pvcalls_front_dev) { 749 if (IS_ERR(map))
758 pvcalls_exit(); 750 return PTR_ERR(map);
759 return -ENOTCONN;
760 }
761 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); 751 bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
762 752
763 map = (struct sock_mapping *) sock->sk->sk_send_head;
764 if (!map) {
765 pvcalls_exit();
766 return -ENOTSOCK;
767 }
768
769 if (map->passive.status != PVCALLS_STATUS_LISTEN) { 753 if (map->passive.status != PVCALLS_STATUS_LISTEN) {
770 pvcalls_exit(); 754 pvcalls_exit_sock(sock);
771 return -EINVAL; 755 return -EINVAL;
772 } 756 }
773 757
@@ -785,13 +769,13 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int flags)
785 goto received; 769 goto received;
786 } 770 }
787 if (nonblock) { 771 if (nonblock) {
788 pvcalls_exit(); 772 pvcalls_exit_sock(sock);
789 return -EAGAIN; 773 return -EAGAIN;
790 } 774 }
791 if (wait_event_interruptible(map->passive.inflight_accept_req, 775 if (wait_event_interruptible(map->passive.inflight_accept_req,
792 !test_and_set_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 776 !test_and_set_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
793 (void *)&map->passive.flags))) { 777 (void *)&map->passive.flags))) {
794 pvcalls_exit(); 778 pvcalls_exit_sock(sock);
795 return -EINTR; 779 return -EINTR;
796 } 780 }
797 } 781 }
@@ -802,7 +786,7 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int flags)
802 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 786 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
803 (void *)&map->passive.flags); 787 (void *)&map->passive.flags);
804 spin_unlock(&bedata->socket_lock); 788 spin_unlock(&bedata->socket_lock);
805 pvcalls_exit(); 789 pvcalls_exit_sock(sock);
806 return ret; 790 return ret;
807 } 791 }
808 map2 = kzalloc(sizeof(*map2), GFP_ATOMIC); 792 map2 = kzalloc(sizeof(*map2), GFP_ATOMIC);
@@ -810,7 +794,7 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int flags)
810 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 794 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
811 (void *)&map->passive.flags); 795 (void *)&map->passive.flags);
812 spin_unlock(&bedata->socket_lock); 796 spin_unlock(&bedata->socket_lock);
813 pvcalls_exit(); 797 pvcalls_exit_sock(sock);
814 return -ENOMEM; 798 return -ENOMEM;
815 } 799 }
816 ret = create_active(map2, &evtchn); 800 ret = create_active(map2, &evtchn);
@@ -819,7 +803,7 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int flags)
819 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 803 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
820 (void *)&map->passive.flags); 804 (void *)&map->passive.flags);
821 spin_unlock(&bedata->socket_lock); 805 spin_unlock(&bedata->socket_lock);
822 pvcalls_exit(); 806 pvcalls_exit_sock(sock);
823 return ret; 807 return ret;
824 } 808 }
825 list_add_tail(&map2->list, &bedata->socket_mappings); 809 list_add_tail(&map2->list, &bedata->socket_mappings);
@@ -841,13 +825,13 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int flags)
841 /* We could check if we have received a response before returning. */ 825 /* We could check if we have received a response before returning. */
842 if (nonblock) { 826 if (nonblock) {
843 WRITE_ONCE(map->passive.inflight_req_id, req_id); 827 WRITE_ONCE(map->passive.inflight_req_id, req_id);
844 pvcalls_exit(); 828 pvcalls_exit_sock(sock);
845 return -EAGAIN; 829 return -EAGAIN;
846 } 830 }
847 831
848 if (wait_event_interruptible(bedata->inflight_req, 832 if (wait_event_interruptible(bedata->inflight_req,
849 READ_ONCE(bedata->rsp[req_id].req_id) == req_id)) { 833 READ_ONCE(bedata->rsp[req_id].req_id) == req_id)) {
850 pvcalls_exit(); 834 pvcalls_exit_sock(sock);
851 return -EINTR; 835 return -EINTR;
852 } 836 }
853 /* read req_id, then the content */ 837 /* read req_id, then the content */
@@ -862,7 +846,7 @@ received:
862 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, 846 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
863 (void *)&map->passive.flags); 847 (void *)&map->passive.flags);
864 pvcalls_front_free_map(bedata, map2); 848 pvcalls_front_free_map(bedata, map2);
865 pvcalls_exit(); 849 pvcalls_exit_sock(sock);
866 return -ENOMEM; 850 return -ENOMEM;
867 } 851 }
868 newsock->sk->sk_send_head = (void *)map2; 852 newsock->sk->sk_send_head = (void *)map2;
@@ -874,7 +858,7 @@ received:
874 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, (void *)&map->passive.flags); 858 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, (void *)&map->passive.flags);
875 wake_up(&map->passive.inflight_accept_req); 859 wake_up(&map->passive.inflight_accept_req);
876 860
877 pvcalls_exit(); 861 pvcalls_exit_sock(sock);
878 return ret; 862 return ret;
879} 863}
880 864
@@ -965,23 +949,16 @@ __poll_t pvcalls_front_poll(struct file *file, struct socket *sock,
965 struct sock_mapping *map; 949 struct sock_mapping *map;
966 __poll_t ret; 950 __poll_t ret;
967 951
968 pvcalls_enter(); 952 map = pvcalls_enter_sock(sock);
969 if (!pvcalls_front_dev) { 953 if (IS_ERR(map))
970 pvcalls_exit();
971 return EPOLLNVAL; 954 return EPOLLNVAL;
972 }
973 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); 955 bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
974 956
975 map = (struct sock_mapping *) sock->sk->sk_send_head;
976 if (!map) {
977 pvcalls_exit();
978 return EPOLLNVAL;
979 }
980 if (map->active_socket) 957 if (map->active_socket)
981 ret = pvcalls_front_poll_active(file, bedata, map, wait); 958 ret = pvcalls_front_poll_active(file, bedata, map, wait);
982 else 959 else
983 ret = pvcalls_front_poll_passive(file, bedata, map, wait); 960 ret = pvcalls_front_poll_passive(file, bedata, map, wait);
984 pvcalls_exit(); 961 pvcalls_exit_sock(sock);
985 return ret; 962 return ret;
986} 963}
987 964
@@ -995,25 +972,20 @@ int pvcalls_front_release(struct socket *sock)
995 if (sock->sk == NULL) 972 if (sock->sk == NULL)
996 return 0; 973 return 0;
997 974
998 pvcalls_enter(); 975 map = pvcalls_enter_sock(sock);
999 if (!pvcalls_front_dev) { 976 if (IS_ERR(map)) {
1000 pvcalls_exit(); 977 if (PTR_ERR(map) == -ENOTCONN)
1001 return -EIO; 978 return -EIO;
979 else
980 return 0;
1002 } 981 }
1003
1004 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); 982 bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
1005 983
1006 map = (struct sock_mapping *) sock->sk->sk_send_head;
1007 if (map == NULL) {
1008 pvcalls_exit();
1009 return 0;
1010 }
1011
1012 spin_lock(&bedata->socket_lock); 984 spin_lock(&bedata->socket_lock);
1013 ret = get_request(bedata, &req_id); 985 ret = get_request(bedata, &req_id);
1014 if (ret < 0) { 986 if (ret < 0) {
1015 spin_unlock(&bedata->socket_lock); 987 spin_unlock(&bedata->socket_lock);
1016 pvcalls_exit(); 988 pvcalls_exit_sock(sock);
1017 return ret; 989 return ret;
1018 } 990 }
1019 sock->sk->sk_send_head = NULL; 991 sock->sk->sk_send_head = NULL;
@@ -1043,14 +1015,20 @@ int pvcalls_front_release(struct socket *sock)
1043 /* 1015 /*
1044 * We need to make sure that sendmsg/recvmsg on this socket have 1016 * We need to make sure that sendmsg/recvmsg on this socket have
1045 * not started before we've cleared sk_send_head here. The 1017 * not started before we've cleared sk_send_head here. The
1046 * easiest (though not optimal) way to guarantee this is to see 1018 * easiest way to guarantee this is to see that no pvcalls
1047 * that no pvcall (other than us) is in progress. 1019 * (other than us) is in progress on this socket.
1048 */ 1020 */
1049 while (atomic_read(&pvcalls_refcount) > 1) 1021 while (atomic_read(&map->refcount) > 1)
1050 cpu_relax(); 1022 cpu_relax();
1051 1023
1052 pvcalls_front_free_map(bedata, map); 1024 pvcalls_front_free_map(bedata, map);
1053 } else { 1025 } else {
1026 wake_up(&bedata->inflight_req);
1027 wake_up(&map->passive.inflight_accept_req);
1028
1029 while (atomic_read(&map->refcount) > 1)
1030 cpu_relax();
1031
1054 spin_lock(&bedata->socket_lock); 1032 spin_lock(&bedata->socket_lock);
1055 list_del(&map->list); 1033 list_del(&map->list);
1056 spin_unlock(&bedata->socket_lock); 1034 spin_unlock(&bedata->socket_lock);
diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c
index bf13d1ec51f3..04e7b3b29bac 100644
--- a/drivers/xen/tmem.c
+++ b/drivers/xen/tmem.c
@@ -284,6 +284,10 @@ static int tmem_frontswap_store(unsigned type, pgoff_t offset,
284 int pool = tmem_frontswap_poolid; 284 int pool = tmem_frontswap_poolid;
285 int ret; 285 int ret;
286 286
287 /* THP isn't supported */
288 if (PageTransHuge(page))
289 return -1;
290
287 if (pool < 0) 291 if (pool < 0)
288 return -1; 292 return -1;
289 if (ind64 != ind) 293 if (ind64 != ind)
diff --git a/drivers/xen/xenbus/xenbus.h b/drivers/xen/xenbus/xenbus.h
index 149c5e7efc89..092981171df1 100644
--- a/drivers/xen/xenbus/xenbus.h
+++ b/drivers/xen/xenbus/xenbus.h
@@ -76,6 +76,7 @@ struct xb_req_data {
76 struct list_head list; 76 struct list_head list;
77 wait_queue_head_t wq; 77 wait_queue_head_t wq;
78 struct xsd_sockmsg msg; 78 struct xsd_sockmsg msg;
79 uint32_t caller_req_id;
79 enum xsd_sockmsg_type type; 80 enum xsd_sockmsg_type type;
80 char *body; 81 char *body;
81 const struct kvec *vec; 82 const struct kvec *vec;
diff --git a/drivers/xen/xenbus/xenbus_comms.c b/drivers/xen/xenbus/xenbus_comms.c
index 5b081a01779d..d239fc3c5e3d 100644
--- a/drivers/xen/xenbus/xenbus_comms.c
+++ b/drivers/xen/xenbus/xenbus_comms.c
@@ -309,6 +309,7 @@ static int process_msg(void)
309 goto out; 309 goto out;
310 310
311 if (req->state == xb_req_state_wait_reply) { 311 if (req->state == xb_req_state_wait_reply) {
312 req->msg.req_id = req->caller_req_id;
312 req->msg.type = state.msg.type; 313 req->msg.type = state.msg.type;
313 req->msg.len = state.msg.len; 314 req->msg.len = state.msg.len;
314 req->body = state.body; 315 req->body = state.body;
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 74888cacd0b0..ec9eb4fba59c 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -466,8 +466,11 @@ int xenbus_probe_node(struct xen_bus_type *bus,
466 466
467 /* Register with generic device framework. */ 467 /* Register with generic device framework. */
468 err = device_register(&xendev->dev); 468 err = device_register(&xendev->dev);
469 if (err) 469 if (err) {
470 put_device(&xendev->dev);
471 xendev = NULL;
470 goto fail; 472 goto fail;
473 }
471 474
472 return 0; 475 return 0;
473fail: 476fail:
diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c
index 3e59590c7254..3f3b29398ab8 100644
--- a/drivers/xen/xenbus/xenbus_xs.c
+++ b/drivers/xen/xenbus/xenbus_xs.c
@@ -227,6 +227,8 @@ static void xs_send(struct xb_req_data *req, struct xsd_sockmsg *msg)
227 req->state = xb_req_state_queued; 227 req->state = xb_req_state_queued;
228 init_waitqueue_head(&req->wq); 228 init_waitqueue_head(&req->wq);
229 229
230 /* Save the caller req_id and restore it later in the reply */
231 req->caller_req_id = req->msg.req_id;
230 req->msg.req_id = xs_request_enter(req); 232 req->msg.req_id = xs_request_enter(req);
231 233
232 mutex_lock(&xb_write_mutex); 234 mutex_lock(&xb_write_mutex);
@@ -310,6 +312,7 @@ static void *xs_talkv(struct xenbus_transaction t,
310 req->num_vecs = num_vecs; 312 req->num_vecs = num_vecs;
311 req->cb = xs_wake_up; 313 req->cb = xs_wake_up;
312 314
315 msg.req_id = 0;
313 msg.tx_id = t.id; 316 msg.tx_id = t.id;
314 msg.type = type; 317 msg.type = type;
315 msg.len = 0; 318 msg.len = 0;
diff --git a/fs/aio.c b/fs/aio.c
index a062d75109cb..6bcd3fb5265a 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -68,9 +68,9 @@ struct aio_ring {
68#define AIO_RING_PAGES 8 68#define AIO_RING_PAGES 8
69 69
70struct kioctx_table { 70struct kioctx_table {
71 struct rcu_head rcu; 71 struct rcu_head rcu;
72 unsigned nr; 72 unsigned nr;
73 struct kioctx *table[]; 73 struct kioctx __rcu *table[];
74}; 74};
75 75
76struct kioctx_cpu { 76struct kioctx_cpu {
@@ -115,7 +115,8 @@ struct kioctx {
115 struct page **ring_pages; 115 struct page **ring_pages;
116 long nr_pages; 116 long nr_pages;
117 117
118 struct work_struct free_work; 118 struct rcu_head free_rcu;
119 struct work_struct free_work; /* see free_ioctx() */
119 120
120 /* 121 /*
121 * signals when all in-flight requests are done 122 * signals when all in-flight requests are done
@@ -329,7 +330,7 @@ static int aio_ring_mremap(struct vm_area_struct *vma)
329 for (i = 0; i < table->nr; i++) { 330 for (i = 0; i < table->nr; i++) {
330 struct kioctx *ctx; 331 struct kioctx *ctx;
331 332
332 ctx = table->table[i]; 333 ctx = rcu_dereference(table->table[i]);
333 if (ctx && ctx->aio_ring_file == file) { 334 if (ctx && ctx->aio_ring_file == file) {
334 if (!atomic_read(&ctx->dead)) { 335 if (!atomic_read(&ctx->dead)) {
335 ctx->user_id = ctx->mmap_base = vma->vm_start; 336 ctx->user_id = ctx->mmap_base = vma->vm_start;
@@ -588,6 +589,12 @@ static int kiocb_cancel(struct aio_kiocb *kiocb)
588 return cancel(&kiocb->common); 589 return cancel(&kiocb->common);
589} 590}
590 591
592/*
593 * free_ioctx() should be RCU delayed to synchronize against the RCU
594 * protected lookup_ioctx() and also needs process context to call
595 * aio_free_ring(), so the double bouncing through kioctx->free_rcu and
596 * ->free_work.
597 */
591static void free_ioctx(struct work_struct *work) 598static void free_ioctx(struct work_struct *work)
592{ 599{
593 struct kioctx *ctx = container_of(work, struct kioctx, free_work); 600 struct kioctx *ctx = container_of(work, struct kioctx, free_work);
@@ -601,6 +608,14 @@ static void free_ioctx(struct work_struct *work)
601 kmem_cache_free(kioctx_cachep, ctx); 608 kmem_cache_free(kioctx_cachep, ctx);
602} 609}
603 610
611static void free_ioctx_rcufn(struct rcu_head *head)
612{
613 struct kioctx *ctx = container_of(head, struct kioctx, free_rcu);
614
615 INIT_WORK(&ctx->free_work, free_ioctx);
616 schedule_work(&ctx->free_work);
617}
618
604static void free_ioctx_reqs(struct percpu_ref *ref) 619static void free_ioctx_reqs(struct percpu_ref *ref)
605{ 620{
606 struct kioctx *ctx = container_of(ref, struct kioctx, reqs); 621 struct kioctx *ctx = container_of(ref, struct kioctx, reqs);
@@ -609,8 +624,8 @@ static void free_ioctx_reqs(struct percpu_ref *ref)
609 if (ctx->rq_wait && atomic_dec_and_test(&ctx->rq_wait->count)) 624 if (ctx->rq_wait && atomic_dec_and_test(&ctx->rq_wait->count))
610 complete(&ctx->rq_wait->comp); 625 complete(&ctx->rq_wait->comp);
611 626
612 INIT_WORK(&ctx->free_work, free_ioctx); 627 /* Synchronize against RCU protected table->table[] dereferences */
613 schedule_work(&ctx->free_work); 628 call_rcu(&ctx->free_rcu, free_ioctx_rcufn);
614} 629}
615 630
616/* 631/*
@@ -651,9 +666,9 @@ static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm)
651 while (1) { 666 while (1) {
652 if (table) 667 if (table)
653 for (i = 0; i < table->nr; i++) 668 for (i = 0; i < table->nr; i++)
654 if (!table->table[i]) { 669 if (!rcu_access_pointer(table->table[i])) {
655 ctx->id = i; 670 ctx->id = i;
656 table->table[i] = ctx; 671 rcu_assign_pointer(table->table[i], ctx);
657 spin_unlock(&mm->ioctx_lock); 672 spin_unlock(&mm->ioctx_lock);
658 673
659 /* While kioctx setup is in progress, 674 /* While kioctx setup is in progress,
@@ -834,11 +849,11 @@ static int kill_ioctx(struct mm_struct *mm, struct kioctx *ctx,
834 } 849 }
835 850
836 table = rcu_dereference_raw(mm->ioctx_table); 851 table = rcu_dereference_raw(mm->ioctx_table);
837 WARN_ON(ctx != table->table[ctx->id]); 852 WARN_ON(ctx != rcu_access_pointer(table->table[ctx->id]));
838 table->table[ctx->id] = NULL; 853 RCU_INIT_POINTER(table->table[ctx->id], NULL);
839 spin_unlock(&mm->ioctx_lock); 854 spin_unlock(&mm->ioctx_lock);
840 855
841 /* percpu_ref_kill() will do the necessary call_rcu() */ 856 /* free_ioctx_reqs() will do the necessary RCU synchronization */
842 wake_up_all(&ctx->wait); 857 wake_up_all(&ctx->wait);
843 858
844 /* 859 /*
@@ -880,7 +895,8 @@ void exit_aio(struct mm_struct *mm)
880 895
881 skipped = 0; 896 skipped = 0;
882 for (i = 0; i < table->nr; ++i) { 897 for (i = 0; i < table->nr; ++i) {
883 struct kioctx *ctx = table->table[i]; 898 struct kioctx *ctx =
899 rcu_dereference_protected(table->table[i], true);
884 900
885 if (!ctx) { 901 if (!ctx) {
886 skipped++; 902 skipped++;
@@ -1069,7 +1085,7 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id)
1069 if (!table || id >= table->nr) 1085 if (!table || id >= table->nr)
1070 goto out; 1086 goto out;
1071 1087
1072 ctx = table->table[id]; 1088 ctx = rcu_dereference(table->table[id]);
1073 if (ctx && ctx->user_id == ctx_id) { 1089 if (ctx && ctx->user_id == ctx_id) {
1074 percpu_ref_get(&ctx->users); 1090 percpu_ref_get(&ctx->users);
1075 ret = ctx; 1091 ret = ctx;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 4a181fcb5175..fe09ef9c21f3 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1058,6 +1058,27 @@ retry:
1058 return 0; 1058 return 0;
1059} 1059}
1060 1060
1061static struct gendisk *bdev_get_gendisk(struct block_device *bdev, int *partno)
1062{
1063 struct gendisk *disk = get_gendisk(bdev->bd_dev, partno);
1064
1065 if (!disk)
1066 return NULL;
1067 /*
1068 * Now that we hold gendisk reference we make sure bdev we looked up is
1069 * not stale. If it is, it means device got removed and created before
1070 * we looked up gendisk and we fail open in such case. Associating
1071 * unhashed bdev with newly created gendisk could lead to two bdevs
1072 * (and thus two independent caches) being associated with one device
1073 * which is bad.
1074 */
1075 if (inode_unhashed(bdev->bd_inode)) {
1076 put_disk_and_module(disk);
1077 return NULL;
1078 }
1079 return disk;
1080}
1081
1061/** 1082/**
1062 * bd_start_claiming - start claiming a block device 1083 * bd_start_claiming - start claiming a block device
1063 * @bdev: block device of interest 1084 * @bdev: block device of interest
@@ -1094,7 +1115,7 @@ static struct block_device *bd_start_claiming(struct block_device *bdev,
1094 * @bdev might not have been initialized properly yet, look up 1115 * @bdev might not have been initialized properly yet, look up
1095 * and grab the outer block device the hard way. 1116 * and grab the outer block device the hard way.
1096 */ 1117 */
1097 disk = get_gendisk(bdev->bd_dev, &partno); 1118 disk = bdev_get_gendisk(bdev, &partno);
1098 if (!disk) 1119 if (!disk)
1099 return ERR_PTR(-ENXIO); 1120 return ERR_PTR(-ENXIO);
1100 1121
@@ -1111,8 +1132,7 @@ static struct block_device *bd_start_claiming(struct block_device *bdev,
1111 else 1132 else
1112 whole = bdgrab(bdev); 1133 whole = bdgrab(bdev);
1113 1134
1114 module_put(disk->fops->owner); 1135 put_disk_and_module(disk);
1115 put_disk(disk);
1116 if (!whole) 1136 if (!whole)
1117 return ERR_PTR(-ENOMEM); 1137 return ERR_PTR(-ENOMEM);
1118 1138
@@ -1407,10 +1427,10 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
1407static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) 1427static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1408{ 1428{
1409 struct gendisk *disk; 1429 struct gendisk *disk;
1410 struct module *owner;
1411 int ret; 1430 int ret;
1412 int partno; 1431 int partno;
1413 int perm = 0; 1432 int perm = 0;
1433 bool first_open = false;
1414 1434
1415 if (mode & FMODE_READ) 1435 if (mode & FMODE_READ)
1416 perm |= MAY_READ; 1436 perm |= MAY_READ;
@@ -1430,14 +1450,14 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1430 restart: 1450 restart:
1431 1451
1432 ret = -ENXIO; 1452 ret = -ENXIO;
1433 disk = get_gendisk(bdev->bd_dev, &partno); 1453 disk = bdev_get_gendisk(bdev, &partno);
1434 if (!disk) 1454 if (!disk)
1435 goto out; 1455 goto out;
1436 owner = disk->fops->owner;
1437 1456
1438 disk_block_events(disk); 1457 disk_block_events(disk);
1439 mutex_lock_nested(&bdev->bd_mutex, for_part); 1458 mutex_lock_nested(&bdev->bd_mutex, for_part);
1440 if (!bdev->bd_openers) { 1459 if (!bdev->bd_openers) {
1460 first_open = true;
1441 bdev->bd_disk = disk; 1461 bdev->bd_disk = disk;
1442 bdev->bd_queue = disk->queue; 1462 bdev->bd_queue = disk->queue;
1443 bdev->bd_contains = bdev; 1463 bdev->bd_contains = bdev;
@@ -1463,8 +1483,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1463 bdev->bd_queue = NULL; 1483 bdev->bd_queue = NULL;
1464 mutex_unlock(&bdev->bd_mutex); 1484 mutex_unlock(&bdev->bd_mutex);
1465 disk_unblock_events(disk); 1485 disk_unblock_events(disk);
1466 put_disk(disk); 1486 put_disk_and_module(disk);
1467 module_put(owner);
1468 goto restart; 1487 goto restart;
1469 } 1488 }
1470 } 1489 }
@@ -1524,15 +1543,15 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1524 if (ret) 1543 if (ret)
1525 goto out_unlock_bdev; 1544 goto out_unlock_bdev;
1526 } 1545 }
1527 /* only one opener holds refs to the module and disk */
1528 put_disk(disk);
1529 module_put(owner);
1530 } 1546 }
1531 bdev->bd_openers++; 1547 bdev->bd_openers++;
1532 if (for_part) 1548 if (for_part)
1533 bdev->bd_part_count++; 1549 bdev->bd_part_count++;
1534 mutex_unlock(&bdev->bd_mutex); 1550 mutex_unlock(&bdev->bd_mutex);
1535 disk_unblock_events(disk); 1551 disk_unblock_events(disk);
1552 /* only one opener holds refs to the module and disk */
1553 if (!first_open)
1554 put_disk_and_module(disk);
1536 return 0; 1555 return 0;
1537 1556
1538 out_clear: 1557 out_clear:
@@ -1546,8 +1565,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1546 out_unlock_bdev: 1565 out_unlock_bdev:
1547 mutex_unlock(&bdev->bd_mutex); 1566 mutex_unlock(&bdev->bd_mutex);
1548 disk_unblock_events(disk); 1567 disk_unblock_events(disk);
1549 put_disk(disk); 1568 put_disk_and_module(disk);
1550 module_put(owner);
1551 out: 1569 out:
1552 bdput(bdev); 1570 bdput(bdev);
1553 1571
@@ -1770,8 +1788,6 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
1770 disk->fops->release(disk, mode); 1788 disk->fops->release(disk, mode);
1771 } 1789 }
1772 if (!bdev->bd_openers) { 1790 if (!bdev->bd_openers) {
1773 struct module *owner = disk->fops->owner;
1774
1775 disk_put_part(bdev->bd_part); 1791 disk_put_part(bdev->bd_part);
1776 bdev->bd_part = NULL; 1792 bdev->bd_part = NULL;
1777 bdev->bd_disk = NULL; 1793 bdev->bd_disk = NULL;
@@ -1779,8 +1795,7 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
1779 victim = bdev->bd_contains; 1795 victim = bdev->bd_contains;
1780 bdev->bd_contains = NULL; 1796 bdev->bd_contains = NULL;
1781 1797
1782 put_disk(disk); 1798 put_disk_and_module(disk);
1783 module_put(owner);
1784 } 1799 }
1785 mutex_unlock(&bdev->bd_mutex); 1800 mutex_unlock(&bdev->bd_mutex);
1786 bdput(bdev); 1801 bdput(bdev);
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index e4054e533f6d..26484648d090 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -1264,7 +1264,16 @@ again:
1264 while (node) { 1264 while (node) {
1265 ref = rb_entry(node, struct prelim_ref, rbnode); 1265 ref = rb_entry(node, struct prelim_ref, rbnode);
1266 node = rb_next(&ref->rbnode); 1266 node = rb_next(&ref->rbnode);
1267 WARN_ON(ref->count < 0); 1267 /*
1268 * ref->count < 0 can happen here if there are delayed
1269 * refs with a node->action of BTRFS_DROP_DELAYED_REF.
1270 * prelim_ref_insert() relies on this when merging
1271 * identical refs to keep the overall count correct.
1272 * prelim_ref_insert() will merge only those refs
1273 * which compare identically. Any refs having
1274 * e.g. different offsets would not be merged,
1275 * and would retain their original ref->count < 0.
1276 */
1268 if (roots && ref->count && ref->root_id && ref->parent == 0) { 1277 if (roots && ref->count && ref->root_id && ref->parent == 0) {
1269 if (sc && sc->root_objectid && 1278 if (sc && sc->root_objectid &&
1270 ref->root_id != sc->root_objectid) { 1279 ref->root_id != sc->root_objectid) {
@@ -1510,6 +1519,7 @@ int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr)
1510 if (!node) 1519 if (!node)
1511 break; 1520 break;
1512 bytenr = node->val; 1521 bytenr = node->val;
1522 shared.share_count = 0;
1513 cond_resched(); 1523 cond_resched();
1514 } 1524 }
1515 1525
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 1a462ab85c49..da308774b8a4 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2974,7 +2974,7 @@ static inline void free_fs_info(struct btrfs_fs_info *fs_info)
2974 kfree(fs_info->super_copy); 2974 kfree(fs_info->super_copy);
2975 kfree(fs_info->super_for_commit); 2975 kfree(fs_info->super_for_commit);
2976 security_free_mnt_opts(&fs_info->security_opts); 2976 security_free_mnt_opts(&fs_info->security_opts);
2977 kfree(fs_info); 2977 kvfree(fs_info);
2978} 2978}
2979 2979
2980/* tree mod log functions from ctree.c */ 2980/* tree mod log functions from ctree.c */
@@ -3095,7 +3095,10 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
3095 u64 inode_objectid, u64 ref_objectid, int ins_len, 3095 u64 inode_objectid, u64 ref_objectid, int ins_len,
3096 int cow); 3096 int cow);
3097 3097
3098int btrfs_find_name_in_ext_backref(struct btrfs_path *path, 3098int btrfs_find_name_in_backref(struct extent_buffer *leaf, int slot,
3099 const char *name,
3100 int name_len, struct btrfs_inode_ref **ref_ret);
3101int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
3099 u64 ref_objectid, const char *name, 3102 u64 ref_objectid, const char *name,
3100 int name_len, 3103 int name_len,
3101 struct btrfs_inode_extref **extref_ret); 3104 struct btrfs_inode_extref **extref_ret);
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index a1a40cf382e3..7ab5e0128f0c 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -821,7 +821,8 @@ int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
821 spin_unlock(&delayed_refs->lock); 821 spin_unlock(&delayed_refs->lock);
822 822
823 if (qrecord_inserted) 823 if (qrecord_inserted)
824 return btrfs_qgroup_trace_extent_post(fs_info, record); 824 btrfs_qgroup_trace_extent_post(fs_info, record);
825
825 return 0; 826 return 0;
826 827
827free_head_ref: 828free_head_ref:
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 05751a677da4..c1618ab9fecf 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2147,6 +2147,10 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,
2147 u64 bytes; 2147 u64 bytes;
2148 struct request_queue *req_q; 2148 struct request_queue *req_q;
2149 2149
2150 if (!stripe->dev->bdev) {
2151 ASSERT(btrfs_test_opt(fs_info, DEGRADED));
2152 continue;
2153 }
2150 req_q = bdev_get_queue(stripe->dev->bdev); 2154 req_q = bdev_get_queue(stripe->dev->bdev);
2151 if (!blk_queue_discard(req_q)) 2155 if (!blk_queue_discard(req_q))
2152 continue; 2156 continue;
diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c
index 39c968f80157..65e1a76bf755 100644
--- a/fs/btrfs/inode-item.c
+++ b/fs/btrfs/inode-item.c
@@ -22,10 +22,10 @@
22#include "transaction.h" 22#include "transaction.h"
23#include "print-tree.h" 23#include "print-tree.h"
24 24
25static int find_name_in_backref(struct btrfs_path *path, const char *name, 25int btrfs_find_name_in_backref(struct extent_buffer *leaf, int slot,
26 int name_len, struct btrfs_inode_ref **ref_ret) 26 const char *name,
27 int name_len, struct btrfs_inode_ref **ref_ret)
27{ 28{
28 struct extent_buffer *leaf;
29 struct btrfs_inode_ref *ref; 29 struct btrfs_inode_ref *ref;
30 unsigned long ptr; 30 unsigned long ptr;
31 unsigned long name_ptr; 31 unsigned long name_ptr;
@@ -33,9 +33,8 @@ static int find_name_in_backref(struct btrfs_path *path, const char *name,
33 u32 cur_offset = 0; 33 u32 cur_offset = 0;
34 int len; 34 int len;
35 35
36 leaf = path->nodes[0]; 36 item_size = btrfs_item_size_nr(leaf, slot);
37 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 37 ptr = btrfs_item_ptr_offset(leaf, slot);
38 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]);
39 while (cur_offset < item_size) { 38 while (cur_offset < item_size) {
40 ref = (struct btrfs_inode_ref *)(ptr + cur_offset); 39 ref = (struct btrfs_inode_ref *)(ptr + cur_offset);
41 len = btrfs_inode_ref_name_len(leaf, ref); 40 len = btrfs_inode_ref_name_len(leaf, ref);
@@ -44,18 +43,19 @@ static int find_name_in_backref(struct btrfs_path *path, const char *name,
44 if (len != name_len) 43 if (len != name_len)
45 continue; 44 continue;
46 if (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0) { 45 if (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0) {
47 *ref_ret = ref; 46 if (ref_ret)
47 *ref_ret = ref;
48 return 1; 48 return 1;
49 } 49 }
50 } 50 }
51 return 0; 51 return 0;
52} 52}
53 53
54int btrfs_find_name_in_ext_backref(struct btrfs_path *path, u64 ref_objectid, 54int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
55 u64 ref_objectid,
55 const char *name, int name_len, 56 const char *name, int name_len,
56 struct btrfs_inode_extref **extref_ret) 57 struct btrfs_inode_extref **extref_ret)
57{ 58{
58 struct extent_buffer *leaf;
59 struct btrfs_inode_extref *extref; 59 struct btrfs_inode_extref *extref;
60 unsigned long ptr; 60 unsigned long ptr;
61 unsigned long name_ptr; 61 unsigned long name_ptr;
@@ -63,9 +63,8 @@ int btrfs_find_name_in_ext_backref(struct btrfs_path *path, u64 ref_objectid,
63 u32 cur_offset = 0; 63 u32 cur_offset = 0;
64 int ref_name_len; 64 int ref_name_len;
65 65
66 leaf = path->nodes[0]; 66 item_size = btrfs_item_size_nr(leaf, slot);
67 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 67 ptr = btrfs_item_ptr_offset(leaf, slot);
68 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]);
69 68
70 /* 69 /*
71 * Search all extended backrefs in this item. We're only 70 * Search all extended backrefs in this item. We're only
@@ -113,7 +112,9 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
113 return ERR_PTR(ret); 112 return ERR_PTR(ret);
114 if (ret > 0) 113 if (ret > 0)
115 return NULL; 114 return NULL;
116 if (!btrfs_find_name_in_ext_backref(path, ref_objectid, name, name_len, &extref)) 115 if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
116 ref_objectid, name, name_len,
117 &extref))
117 return NULL; 118 return NULL;
118 return extref; 119 return extref;
119} 120}
@@ -155,7 +156,8 @@ static int btrfs_del_inode_extref(struct btrfs_trans_handle *trans,
155 * This should always succeed so error here will make the FS 156 * This should always succeed so error here will make the FS
156 * readonly. 157 * readonly.
157 */ 158 */
158 if (!btrfs_find_name_in_ext_backref(path, ref_objectid, 159 if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
160 ref_objectid,
159 name, name_len, &extref)) { 161 name, name_len, &extref)) {
160 btrfs_handle_fs_error(root->fs_info, -ENOENT, NULL); 162 btrfs_handle_fs_error(root->fs_info, -ENOENT, NULL);
161 ret = -EROFS; 163 ret = -EROFS;
@@ -225,7 +227,8 @@ int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
225 } else if (ret < 0) { 227 } else if (ret < 0) {
226 goto out; 228 goto out;
227 } 229 }
228 if (!find_name_in_backref(path, name, name_len, &ref)) { 230 if (!btrfs_find_name_in_backref(path->nodes[0], path->slots[0],
231 name, name_len, &ref)) {
229 ret = -ENOENT; 232 ret = -ENOENT;
230 search_ext_refs = 1; 233 search_ext_refs = 1;
231 goto out; 234 goto out;
@@ -293,7 +296,9 @@ static int btrfs_insert_inode_extref(struct btrfs_trans_handle *trans,
293 ret = btrfs_insert_empty_item(trans, root, path, &key, 296 ret = btrfs_insert_empty_item(trans, root, path, &key,
294 ins_len); 297 ins_len);
295 if (ret == -EEXIST) { 298 if (ret == -EEXIST) {
296 if (btrfs_find_name_in_ext_backref(path, ref_objectid, 299 if (btrfs_find_name_in_ext_backref(path->nodes[0],
300 path->slots[0],
301 ref_objectid,
297 name, name_len, NULL)) 302 name, name_len, NULL))
298 goto out; 303 goto out;
299 304
@@ -351,7 +356,8 @@ int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
351 if (ret == -EEXIST) { 356 if (ret == -EEXIST) {
352 u32 old_size; 357 u32 old_size;
353 358
354 if (find_name_in_backref(path, name, name_len, &ref)) 359 if (btrfs_find_name_in_backref(path->nodes[0], path->slots[0],
360 name, name_len, &ref))
355 goto out; 361 goto out;
356 362
357 old_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]); 363 old_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]);
@@ -365,7 +371,9 @@ int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
365 ret = 0; 371 ret = 0;
366 } else if (ret < 0) { 372 } else if (ret < 0) {
367 if (ret == -EOVERFLOW) { 373 if (ret == -EOVERFLOW) {
368 if (find_name_in_backref(path, name, name_len, &ref)) 374 if (btrfs_find_name_in_backref(path->nodes[0],
375 path->slots[0],
376 name, name_len, &ref))
369 ret = -EEXIST; 377 ret = -EEXIST;
370 else 378 else
371 ret = -EMLINK; 379 ret = -EMLINK;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 53ca025655fc..f53470112670 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1335,8 +1335,11 @@ next_slot:
1335 leaf = path->nodes[0]; 1335 leaf = path->nodes[0];
1336 if (path->slots[0] >= btrfs_header_nritems(leaf)) { 1336 if (path->slots[0] >= btrfs_header_nritems(leaf)) {
1337 ret = btrfs_next_leaf(root, path); 1337 ret = btrfs_next_leaf(root, path);
1338 if (ret < 0) 1338 if (ret < 0) {
1339 if (cow_start != (u64)-1)
1340 cur_offset = cow_start;
1339 goto error; 1341 goto error;
1342 }
1340 if (ret > 0) 1343 if (ret > 0)
1341 break; 1344 break;
1342 leaf = path->nodes[0]; 1345 leaf = path->nodes[0];
@@ -2040,12 +2043,15 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
2040 struct inode *inode, struct list_head *list) 2043 struct inode *inode, struct list_head *list)
2041{ 2044{
2042 struct btrfs_ordered_sum *sum; 2045 struct btrfs_ordered_sum *sum;
2046 int ret;
2043 2047
2044 list_for_each_entry(sum, list, list) { 2048 list_for_each_entry(sum, list, list) {
2045 trans->adding_csums = true; 2049 trans->adding_csums = true;
2046 btrfs_csum_file_blocks(trans, 2050 ret = btrfs_csum_file_blocks(trans,
2047 BTRFS_I(inode)->root->fs_info->csum_root, sum); 2051 BTRFS_I(inode)->root->fs_info->csum_root, sum);
2048 trans->adding_csums = false; 2052 trans->adding_csums = false;
2053 if (ret)
2054 return ret;
2049 } 2055 }
2050 return 0; 2056 return 0;
2051} 2057}
@@ -3059,7 +3065,11 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
3059 goto out; 3065 goto out;
3060 } 3066 }
3061 3067
3062 add_pending_csums(trans, inode, &ordered_extent->list); 3068 ret = add_pending_csums(trans, inode, &ordered_extent->list);
3069 if (ret) {
3070 btrfs_abort_transaction(trans, ret);
3071 goto out;
3072 }
3063 3073
3064 btrfs_ordered_update_i_size(inode, 0, ordered_extent); 3074 btrfs_ordered_update_i_size(inode, 0, ordered_extent);
3065 ret = btrfs_update_inode_fallback(trans, root, inode); 3075 ret = btrfs_update_inode_fallback(trans, root, inode);
@@ -3385,6 +3395,11 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans,
3385 ret = btrfs_orphan_reserve_metadata(trans, inode); 3395 ret = btrfs_orphan_reserve_metadata(trans, inode);
3386 ASSERT(!ret); 3396 ASSERT(!ret);
3387 if (ret) { 3397 if (ret) {
3398 /*
3399 * dec doesn't need spin_lock as ->orphan_block_rsv
3400 * would be released only if ->orphan_inodes is
3401 * zero.
3402 */
3388 atomic_dec(&root->orphan_inodes); 3403 atomic_dec(&root->orphan_inodes);
3389 clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, 3404 clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
3390 &inode->runtime_flags); 3405 &inode->runtime_flags);
@@ -3399,12 +3414,17 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans,
3399 if (insert >= 1) { 3414 if (insert >= 1) {
3400 ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); 3415 ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode));
3401 if (ret) { 3416 if (ret) {
3402 atomic_dec(&root->orphan_inodes);
3403 if (reserve) { 3417 if (reserve) {
3404 clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, 3418 clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
3405 &inode->runtime_flags); 3419 &inode->runtime_flags);
3406 btrfs_orphan_release_metadata(inode); 3420 btrfs_orphan_release_metadata(inode);
3407 } 3421 }
3422 /*
3423 * btrfs_orphan_commit_root may race with us and set
3424 * ->orphan_block_rsv to zero, in order to avoid that,
3425 * decrease ->orphan_inodes after everything is done.
3426 */
3427 atomic_dec(&root->orphan_inodes);
3408 if (ret != -EEXIST) { 3428 if (ret != -EEXIST) {
3409 clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 3429 clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
3410 &inode->runtime_flags); 3430 &inode->runtime_flags);
@@ -3436,28 +3456,26 @@ static int btrfs_orphan_del(struct btrfs_trans_handle *trans,
3436{ 3456{
3437 struct btrfs_root *root = inode->root; 3457 struct btrfs_root *root = inode->root;
3438 int delete_item = 0; 3458 int delete_item = 0;
3439 int release_rsv = 0;
3440 int ret = 0; 3459 int ret = 0;
3441 3460
3442 spin_lock(&root->orphan_lock);
3443 if (test_and_clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 3461 if (test_and_clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
3444 &inode->runtime_flags)) 3462 &inode->runtime_flags))
3445 delete_item = 1; 3463 delete_item = 1;
3446 3464
3465 if (delete_item && trans)
3466 ret = btrfs_del_orphan_item(trans, root, btrfs_ino(inode));
3467
3447 if (test_and_clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, 3468 if (test_and_clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
3448 &inode->runtime_flags)) 3469 &inode->runtime_flags))
3449 release_rsv = 1; 3470 btrfs_orphan_release_metadata(inode);
3450 spin_unlock(&root->orphan_lock);
3451 3471
3452 if (delete_item) { 3472 /*
3473 * btrfs_orphan_commit_root may race with us and set ->orphan_block_rsv
3474 * to zero, in order to avoid that, decrease ->orphan_inodes after
3475 * everything is done.
3476 */
3477 if (delete_item)
3453 atomic_dec(&root->orphan_inodes); 3478 atomic_dec(&root->orphan_inodes);
3454 if (trans)
3455 ret = btrfs_del_orphan_item(trans, root,
3456 btrfs_ino(inode));
3457 }
3458
3459 if (release_rsv)
3460 btrfs_orphan_release_metadata(inode);
3461 3479
3462 return ret; 3480 return ret;
3463} 3481}
@@ -5281,7 +5299,7 @@ void btrfs_evict_inode(struct inode *inode)
5281 trace_btrfs_inode_evict(inode); 5299 trace_btrfs_inode_evict(inode);
5282 5300
5283 if (!root) { 5301 if (!root) {
5284 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); 5302 clear_inode(inode);
5285 return; 5303 return;
5286 } 5304 }
5287 5305
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 9e61dd624f7b..aa259d6986e1 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1442,8 +1442,13 @@ int btrfs_qgroup_trace_extent_post(struct btrfs_fs_info *fs_info,
1442 int ret; 1442 int ret;
1443 1443
1444 ret = btrfs_find_all_roots(NULL, fs_info, bytenr, 0, &old_root, false); 1444 ret = btrfs_find_all_roots(NULL, fs_info, bytenr, 0, &old_root, false);
1445 if (ret < 0) 1445 if (ret < 0) {
1446 return ret; 1446 fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
1447 btrfs_warn(fs_info,
1448"error accounting new delayed refs extent (err code: %d), quota inconsistent",
1449 ret);
1450 return 0;
1451 }
1447 1452
1448 /* 1453 /*
1449 * Here we don't need to get the lock of 1454 * Here we don't need to get the lock of
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index dec0907dfb8a..fcfc20de2df3 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1370,6 +1370,7 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio,
1370 stripe_start = stripe->physical; 1370 stripe_start = stripe->physical;
1371 if (physical >= stripe_start && 1371 if (physical >= stripe_start &&
1372 physical < stripe_start + rbio->stripe_len && 1372 physical < stripe_start + rbio->stripe_len &&
1373 stripe->dev->bdev &&
1373 bio->bi_disk == stripe->dev->bdev->bd_disk && 1374 bio->bi_disk == stripe->dev->bdev->bd_disk &&
1374 bio->bi_partno == stripe->dev->bdev->bd_partno) { 1375 bio->bi_partno == stripe->dev->bdev->bd_partno) {
1375 return i; 1376 return i;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index f0c3f00e97cb..cd2298d185dd 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3268,8 +3268,22 @@ static int relocate_file_extent_cluster(struct inode *inode,
3268 nr++; 3268 nr++;
3269 } 3269 }
3270 3270
3271 btrfs_set_extent_delalloc(inode, page_start, page_end, 0, NULL, 3271 ret = btrfs_set_extent_delalloc(inode, page_start, page_end, 0,
3272 0); 3272 NULL, 0);
3273 if (ret) {
3274 unlock_page(page);
3275 put_page(page);
3276 btrfs_delalloc_release_metadata(BTRFS_I(inode),
3277 PAGE_SIZE);
3278 btrfs_delalloc_release_extents(BTRFS_I(inode),
3279 PAGE_SIZE);
3280
3281 clear_extent_bits(&BTRFS_I(inode)->io_tree,
3282 page_start, page_end,
3283 EXTENT_LOCKED | EXTENT_BOUNDARY);
3284 goto out;
3285
3286 }
3273 set_page_dirty(page); 3287 set_page_dirty(page);
3274 3288
3275 unlock_extent(&BTRFS_I(inode)->io_tree, 3289 unlock_extent(&BTRFS_I(inode)->io_tree,
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index f306c608dc28..484e2af793de 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -5005,6 +5005,9 @@ static int send_hole(struct send_ctx *sctx, u64 end)
5005 u64 len; 5005 u64 len;
5006 int ret = 0; 5006 int ret = 0;
5007 5007
5008 if (sctx->flags & BTRFS_SEND_FLAG_NO_FILE_DATA)
5009 return send_update_extent(sctx, offset, end - offset);
5010
5008 p = fs_path_alloc(); 5011 p = fs_path_alloc();
5009 if (!p) 5012 if (!p)
5010 return -ENOMEM; 5013 return -ENOMEM;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 6e71a2a78363..4b817947e00f 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1545,7 +1545,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
1545 * it for searching for existing supers, so this lets us do that and 1545 * it for searching for existing supers, so this lets us do that and
1546 * then open_ctree will properly initialize everything later. 1546 * then open_ctree will properly initialize everything later.
1547 */ 1547 */
1548 fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL); 1548 fs_info = kvzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL);
1549 if (!fs_info) { 1549 if (!fs_info) {
1550 error = -ENOMEM; 1550 error = -ENOMEM;
1551 goto error_sec_opts; 1551 goto error_sec_opts;
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index afadaadab18e..434457794c27 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -29,6 +29,7 @@
29#include "hash.h" 29#include "hash.h"
30#include "compression.h" 30#include "compression.h"
31#include "qgroup.h" 31#include "qgroup.h"
32#include "inode-map.h"
32 33
33/* magic values for the inode_only field in btrfs_log_inode: 34/* magic values for the inode_only field in btrfs_log_inode:
34 * 35 *
@@ -966,7 +967,9 @@ static noinline int backref_in_log(struct btrfs_root *log,
966 ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]); 967 ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]);
967 968
968 if (key->type == BTRFS_INODE_EXTREF_KEY) { 969 if (key->type == BTRFS_INODE_EXTREF_KEY) {
969 if (btrfs_find_name_in_ext_backref(path, ref_objectid, 970 if (btrfs_find_name_in_ext_backref(path->nodes[0],
971 path->slots[0],
972 ref_objectid,
970 name, namelen, NULL)) 973 name, namelen, NULL))
971 match = 1; 974 match = 1;
972 975
@@ -1190,7 +1193,8 @@ static int extref_get_fields(struct extent_buffer *eb, unsigned long ref_ptr,
1190 read_extent_buffer(eb, *name, (unsigned long)&extref->name, 1193 read_extent_buffer(eb, *name, (unsigned long)&extref->name,
1191 *namelen); 1194 *namelen);
1192 1195
1193 *index = btrfs_inode_extref_index(eb, extref); 1196 if (index)
1197 *index = btrfs_inode_extref_index(eb, extref);
1194 if (parent_objectid) 1198 if (parent_objectid)
1195 *parent_objectid = btrfs_inode_extref_parent(eb, extref); 1199 *parent_objectid = btrfs_inode_extref_parent(eb, extref);
1196 1200
@@ -1211,12 +1215,102 @@ static int ref_get_fields(struct extent_buffer *eb, unsigned long ref_ptr,
1211 1215
1212 read_extent_buffer(eb, *name, (unsigned long)(ref + 1), *namelen); 1216 read_extent_buffer(eb, *name, (unsigned long)(ref + 1), *namelen);
1213 1217
1214 *index = btrfs_inode_ref_index(eb, ref); 1218 if (index)
1219 *index = btrfs_inode_ref_index(eb, ref);
1215 1220
1216 return 0; 1221 return 0;
1217} 1222}
1218 1223
1219/* 1224/*
1225 * Take an inode reference item from the log tree and iterate all names from the
1226 * inode reference item in the subvolume tree with the same key (if it exists).
1227 * For any name that is not in the inode reference item from the log tree, do a
1228 * proper unlink of that name (that is, remove its entry from the inode
1229 * reference item and both dir index keys).
1230 */
1231static int unlink_old_inode_refs(struct btrfs_trans_handle *trans,
1232 struct btrfs_root *root,
1233 struct btrfs_path *path,
1234 struct btrfs_inode *inode,
1235 struct extent_buffer *log_eb,
1236 int log_slot,
1237 struct btrfs_key *key)
1238{
1239 int ret;
1240 unsigned long ref_ptr;
1241 unsigned long ref_end;
1242 struct extent_buffer *eb;
1243
1244again:
1245 btrfs_release_path(path);
1246 ret = btrfs_search_slot(NULL, root, key, path, 0, 0);
1247 if (ret > 0) {
1248 ret = 0;
1249 goto out;
1250 }
1251 if (ret < 0)
1252 goto out;
1253
1254 eb = path->nodes[0];
1255 ref_ptr = btrfs_item_ptr_offset(eb, path->slots[0]);
1256 ref_end = ref_ptr + btrfs_item_size_nr(eb, path->slots[0]);
1257 while (ref_ptr < ref_end) {
1258 char *name = NULL;
1259 int namelen;
1260 u64 parent_id;
1261
1262 if (key->type == BTRFS_INODE_EXTREF_KEY) {
1263 ret = extref_get_fields(eb, ref_ptr, &namelen, &name,
1264 NULL, &parent_id);
1265 } else {
1266 parent_id = key->offset;
1267 ret = ref_get_fields(eb, ref_ptr, &namelen, &name,
1268 NULL);
1269 }
1270 if (ret)
1271 goto out;
1272
1273 if (key->type == BTRFS_INODE_EXTREF_KEY)
1274 ret = btrfs_find_name_in_ext_backref(log_eb, log_slot,
1275 parent_id, name,
1276 namelen, NULL);
1277 else
1278 ret = btrfs_find_name_in_backref(log_eb, log_slot, name,
1279 namelen, NULL);
1280
1281 if (!ret) {
1282 struct inode *dir;
1283
1284 btrfs_release_path(path);
1285 dir = read_one_inode(root, parent_id);
1286 if (!dir) {
1287 ret = -ENOENT;
1288 kfree(name);
1289 goto out;
1290 }
1291 ret = btrfs_unlink_inode(trans, root, BTRFS_I(dir),
1292 inode, name, namelen);
1293 kfree(name);
1294 iput(dir);
1295 if (ret)
1296 goto out;
1297 goto again;
1298 }
1299
1300 kfree(name);
1301 ref_ptr += namelen;
1302 if (key->type == BTRFS_INODE_EXTREF_KEY)
1303 ref_ptr += sizeof(struct btrfs_inode_extref);
1304 else
1305 ref_ptr += sizeof(struct btrfs_inode_ref);
1306 }
1307 ret = 0;
1308 out:
1309 btrfs_release_path(path);
1310 return ret;
1311}
1312
1313/*
1220 * replay one inode back reference item found in the log tree. 1314 * replay one inode back reference item found in the log tree.
1221 * eb, slot and key refer to the buffer and key found in the log tree. 1315 * eb, slot and key refer to the buffer and key found in the log tree.
1222 * root is the destination we are replaying into, and path is for temp 1316 * root is the destination we are replaying into, and path is for temp
@@ -1344,6 +1438,19 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
1344 } 1438 }
1345 } 1439 }
1346 1440
1441 /*
1442 * Before we overwrite the inode reference item in the subvolume tree
1443 * with the item from the log tree, we must unlink all names from the
1444 * parent directory that are in the subvolume's tree inode reference
1445 * item, otherwise we end up with an inconsistent subvolume tree where
1446 * dir index entries exist for a name but there is no inode reference
1447 * item with the same name.
1448 */
1449 ret = unlink_old_inode_refs(trans, root, path, BTRFS_I(inode), eb, slot,
1450 key);
1451 if (ret)
1452 goto out;
1453
1347 /* finally write the back reference in the inode */ 1454 /* finally write the back reference in the inode */
1348 ret = overwrite_item(trans, root, path, eb, slot, key); 1455 ret = overwrite_item(trans, root, path, eb, slot, key);
1349out: 1456out:
@@ -2472,6 +2579,9 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
2472 clean_tree_block(fs_info, next); 2579 clean_tree_block(fs_info, next);
2473 btrfs_wait_tree_block_writeback(next); 2580 btrfs_wait_tree_block_writeback(next);
2474 btrfs_tree_unlock(next); 2581 btrfs_tree_unlock(next);
2582 } else {
2583 if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags))
2584 clear_extent_buffer_dirty(next);
2475 } 2585 }
2476 2586
2477 WARN_ON(root_owner != 2587 WARN_ON(root_owner !=
@@ -2552,6 +2662,9 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans,
2552 clean_tree_block(fs_info, next); 2662 clean_tree_block(fs_info, next);
2553 btrfs_wait_tree_block_writeback(next); 2663 btrfs_wait_tree_block_writeback(next);
2554 btrfs_tree_unlock(next); 2664 btrfs_tree_unlock(next);
2665 } else {
2666 if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags))
2667 clear_extent_buffer_dirty(next);
2555 } 2668 }
2556 2669
2557 WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID); 2670 WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID);
@@ -2630,6 +2743,9 @@ static int walk_log_tree(struct btrfs_trans_handle *trans,
2630 clean_tree_block(fs_info, next); 2743 clean_tree_block(fs_info, next);
2631 btrfs_wait_tree_block_writeback(next); 2744 btrfs_wait_tree_block_writeback(next);
2632 btrfs_tree_unlock(next); 2745 btrfs_tree_unlock(next);
2746 } else {
2747 if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags))
2748 clear_extent_buffer_dirty(next);
2633 } 2749 }
2634 2750
2635 WARN_ON(log->root_key.objectid != 2751 WARN_ON(log->root_key.objectid !=
@@ -3018,13 +3134,14 @@ static void free_log_tree(struct btrfs_trans_handle *trans,
3018 3134
3019 while (1) { 3135 while (1) {
3020 ret = find_first_extent_bit(&log->dirty_log_pages, 3136 ret = find_first_extent_bit(&log->dirty_log_pages,
3021 0, &start, &end, EXTENT_DIRTY | EXTENT_NEW, 3137 0, &start, &end,
3138 EXTENT_DIRTY | EXTENT_NEW | EXTENT_NEED_WAIT,
3022 NULL); 3139 NULL);
3023 if (ret) 3140 if (ret)
3024 break; 3141 break;
3025 3142
3026 clear_extent_bits(&log->dirty_log_pages, start, end, 3143 clear_extent_bits(&log->dirty_log_pages, start, end,
3027 EXTENT_DIRTY | EXTENT_NEW); 3144 EXTENT_DIRTY | EXTENT_NEW | EXTENT_NEED_WAIT);
3028 } 3145 }
3029 3146
3030 /* 3147 /*
@@ -5677,6 +5794,23 @@ again:
5677 path); 5794 path);
5678 } 5795 }
5679 5796
5797 if (!ret && wc.stage == LOG_WALK_REPLAY_ALL) {
5798 struct btrfs_root *root = wc.replay_dest;
5799
5800 btrfs_release_path(path);
5801
5802 /*
5803 * We have just replayed everything, and the highest
5804 * objectid of fs roots probably has changed in case
5805 * some inode_item's got replayed.
5806 *
5807 * root->objectid_mutex is not acquired as log replay
5808 * could only happen during mount.
5809 */
5810 ret = btrfs_find_highest_objectid(root,
5811 &root->highest_objectid);
5812 }
5813
5680 key.offset = found_key.offset - 1; 5814 key.offset = found_key.offset - 1;
5681 wc.replay_dest->log_root = NULL; 5815 wc.replay_dest->log_root = NULL;
5682 free_extent_buffer(log->node); 5816 free_extent_buffer(log->node);
@@ -5825,7 +5959,7 @@ int btrfs_log_new_name(struct btrfs_trans_handle *trans,
5825 * this will force the logging code to walk the dentry chain 5959 * this will force the logging code to walk the dentry chain
5826 * up for the file 5960 * up for the file
5827 */ 5961 */
5828 if (S_ISREG(inode->vfs_inode.i_mode)) 5962 if (!S_ISDIR(inode->vfs_inode.i_mode))
5829 inode->last_unlink_trans = trans->transid; 5963 inode->last_unlink_trans = trans->transid;
5830 5964
5831 /* 5965 /*
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b5036bd69e6a..b2d05c6b1c56 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -645,6 +645,7 @@ static void btrfs_free_stale_devices(const char *path,
645 btrfs_sysfs_remove_fsid(fs_devs); 645 btrfs_sysfs_remove_fsid(fs_devs);
646 list_del(&fs_devs->list); 646 list_del(&fs_devs->list);
647 free_fs_devices(fs_devs); 647 free_fs_devices(fs_devs);
648 break;
648 } else { 649 } else {
649 fs_devs->num_devices--; 650 fs_devs->num_devices--;
650 list_del(&dev->dev_list); 651 list_del(&dev->dev_list);
@@ -4828,10 +4829,13 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
4828 ndevs = min(ndevs, devs_max); 4829 ndevs = min(ndevs, devs_max);
4829 4830
4830 /* 4831 /*
4831 * the primary goal is to maximize the number of stripes, so use as many 4832 * The primary goal is to maximize the number of stripes, so use as
4832 * devices as possible, even if the stripes are not maximum sized. 4833 * many devices as possible, even if the stripes are not maximum sized.
4834 *
4835 * The DUP profile stores more than one stripe per device, the
4836 * max_avail is the total size so we have to adjust.
4833 */ 4837 */
4834 stripe_size = devices_info[ndevs-1].max_avail; 4838 stripe_size = div_u64(devices_info[ndevs - 1].max_avail, dev_stripes);
4835 num_stripes = ndevs * dev_stripes; 4839 num_stripes = ndevs * dev_stripes;
4836 4840
4837 /* 4841 /*
@@ -4866,8 +4870,6 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
4866 stripe_size = devices_info[ndevs-1].max_avail; 4870 stripe_size = devices_info[ndevs-1].max_avail;
4867 } 4871 }
4868 4872
4869 stripe_size = div_u64(stripe_size, dev_stripes);
4870
4871 /* align to BTRFS_STRIPE_LEN */ 4873 /* align to BTRFS_STRIPE_LEN */
4872 stripe_size = round_down(stripe_size, BTRFS_STRIPE_LEN); 4874 stripe_size = round_down(stripe_size, BTRFS_STRIPE_LEN);
4873 4875
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 6582c4507e6c..0e5bd3e3344e 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -3965,6 +3965,32 @@ void ceph_put_fmode(struct ceph_inode_info *ci, int fmode)
3965} 3965}
3966 3966
3967/* 3967/*
3968 * For a soon-to-be unlinked file, drop the AUTH_RDCACHE caps. If it
3969 * looks like the link count will hit 0, drop any other caps (other
3970 * than PIN) we don't specifically want (due to the file still being
3971 * open).
3972 */
3973int ceph_drop_caps_for_unlink(struct inode *inode)
3974{
3975 struct ceph_inode_info *ci = ceph_inode(inode);
3976 int drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
3977
3978 spin_lock(&ci->i_ceph_lock);
3979 if (inode->i_nlink == 1) {
3980 drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN);
3981
3982 ci->i_ceph_flags |= CEPH_I_NODELAY;
3983 if (__ceph_caps_dirty(ci)) {
3984 struct ceph_mds_client *mdsc =
3985 ceph_inode_to_client(inode)->mdsc;
3986 __cap_delay_requeue_front(mdsc, ci);
3987 }
3988 }
3989 spin_unlock(&ci->i_ceph_lock);
3990 return drop;
3991}
3992
3993/*
3968 * Helpers for embedding cap and dentry lease releases into mds 3994 * Helpers for embedding cap and dentry lease releases into mds
3969 * requests. 3995 * requests.
3970 * 3996 *
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 0c4346806e17..f1d9c6cc0491 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -1003,26 +1003,6 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir,
1003} 1003}
1004 1004
1005/* 1005/*
1006 * For a soon-to-be unlinked file, drop the AUTH_RDCACHE caps. If it
1007 * looks like the link count will hit 0, drop any other caps (other
1008 * than PIN) we don't specifically want (due to the file still being
1009 * open).
1010 */
1011static int drop_caps_for_unlink(struct inode *inode)
1012{
1013 struct ceph_inode_info *ci = ceph_inode(inode);
1014 int drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
1015
1016 spin_lock(&ci->i_ceph_lock);
1017 if (inode->i_nlink == 1) {
1018 drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN);
1019 ci->i_ceph_flags |= CEPH_I_NODELAY;
1020 }
1021 spin_unlock(&ci->i_ceph_lock);
1022 return drop;
1023}
1024
1025/*
1026 * rmdir and unlink are differ only by the metadata op code 1006 * rmdir and unlink are differ only by the metadata op code
1027 */ 1007 */
1028static int ceph_unlink(struct inode *dir, struct dentry *dentry) 1008static int ceph_unlink(struct inode *dir, struct dentry *dentry)
@@ -1056,7 +1036,7 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry)
1056 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); 1036 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
1057 req->r_dentry_drop = CEPH_CAP_FILE_SHARED; 1037 req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
1058 req->r_dentry_unless = CEPH_CAP_FILE_EXCL; 1038 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
1059 req->r_inode_drop = drop_caps_for_unlink(inode); 1039 req->r_inode_drop = ceph_drop_caps_for_unlink(inode);
1060 err = ceph_mdsc_do_request(mdsc, dir, req); 1040 err = ceph_mdsc_do_request(mdsc, dir, req);
1061 if (!err && !req->r_reply_info.head->is_dentry) 1041 if (!err && !req->r_reply_info.head->is_dentry)
1062 d_delete(dentry); 1042 d_delete(dentry);
@@ -1104,8 +1084,10 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,
1104 req->r_dentry_unless = CEPH_CAP_FILE_EXCL; 1084 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
1105 /* release LINK_RDCACHE on source inode (mds will lock it) */ 1085 /* release LINK_RDCACHE on source inode (mds will lock it) */
1106 req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL; 1086 req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
1107 if (d_really_is_positive(new_dentry)) 1087 if (d_really_is_positive(new_dentry)) {
1108 req->r_inode_drop = drop_caps_for_unlink(d_inode(new_dentry)); 1088 req->r_inode_drop =
1089 ceph_drop_caps_for_unlink(d_inode(new_dentry));
1090 }
1109 err = ceph_mdsc_do_request(mdsc, old_dir, req); 1091 err = ceph_mdsc_do_request(mdsc, old_dir, req);
1110 if (!err && !req->r_reply_info.head->is_dentry) { 1092 if (!err && !req->r_reply_info.head->is_dentry) {
1111 /* 1093 /*
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index a62d2a9841dc..fb2bc9c15a23 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -225,6 +225,7 @@ static int parse_fsopt_token(char *c, void *private)
225 return -ENOMEM; 225 return -ENOMEM;
226 break; 226 break;
227 case Opt_mds_namespace: 227 case Opt_mds_namespace:
228 kfree(fsopt->mds_namespace);
228 fsopt->mds_namespace = kstrndup(argstr[0].from, 229 fsopt->mds_namespace = kstrndup(argstr[0].from,
229 argstr[0].to-argstr[0].from, 230 argstr[0].to-argstr[0].from,
230 GFP_KERNEL); 231 GFP_KERNEL);
@@ -232,6 +233,7 @@ static int parse_fsopt_token(char *c, void *private)
232 return -ENOMEM; 233 return -ENOMEM;
233 break; 234 break;
234 case Opt_fscache_uniq: 235 case Opt_fscache_uniq:
236 kfree(fsopt->fscache_uniq);
235 fsopt->fscache_uniq = kstrndup(argstr[0].from, 237 fsopt->fscache_uniq = kstrndup(argstr[0].from,
236 argstr[0].to-argstr[0].from, 238 argstr[0].to-argstr[0].from,
237 GFP_KERNEL); 239 GFP_KERNEL);
@@ -711,14 +713,17 @@ static int __init init_caches(void)
711 goto bad_dentry; 713 goto bad_dentry;
712 714
713 ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD); 715 ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
714
715 if (!ceph_file_cachep) 716 if (!ceph_file_cachep)
716 goto bad_file; 717 goto bad_file;
717 718
718 if ((error = ceph_fscache_register())) 719 error = ceph_fscache_register();
719 goto bad_file; 720 if (error)
721 goto bad_fscache;
720 722
721 return 0; 723 return 0;
724
725bad_fscache:
726 kmem_cache_destroy(ceph_file_cachep);
722bad_file: 727bad_file:
723 kmem_cache_destroy(ceph_dentry_cachep); 728 kmem_cache_destroy(ceph_dentry_cachep);
724bad_dentry: 729bad_dentry:
@@ -836,7 +841,6 @@ static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc)
836 int err; 841 int err;
837 unsigned long started = jiffies; /* note the start time */ 842 unsigned long started = jiffies; /* note the start time */
838 struct dentry *root; 843 struct dentry *root;
839 int first = 0; /* first vfsmount for this super_block */
840 844
841 dout("mount start %p\n", fsc); 845 dout("mount start %p\n", fsc);
842 mutex_lock(&fsc->client->mount_mutex); 846 mutex_lock(&fsc->client->mount_mutex);
@@ -861,17 +865,17 @@ static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc)
861 path = fsc->mount_options->server_path + 1; 865 path = fsc->mount_options->server_path + 1;
862 dout("mount opening path %s\n", path); 866 dout("mount opening path %s\n", path);
863 } 867 }
868
869 err = ceph_fs_debugfs_init(fsc);
870 if (err < 0)
871 goto out;
872
864 root = open_root_dentry(fsc, path, started); 873 root = open_root_dentry(fsc, path, started);
865 if (IS_ERR(root)) { 874 if (IS_ERR(root)) {
866 err = PTR_ERR(root); 875 err = PTR_ERR(root);
867 goto out; 876 goto out;
868 } 877 }
869 fsc->sb->s_root = dget(root); 878 fsc->sb->s_root = dget(root);
870 first = 1;
871
872 err = ceph_fs_debugfs_init(fsc);
873 if (err < 0)
874 goto fail;
875 } else { 879 } else {
876 root = dget(fsc->sb->s_root); 880 root = dget(fsc->sb->s_root);
877 } 881 }
@@ -881,11 +885,6 @@ static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc)
881 mutex_unlock(&fsc->client->mount_mutex); 885 mutex_unlock(&fsc->client->mount_mutex);
882 return root; 886 return root;
883 887
884fail:
885 if (first) {
886 dput(fsc->sb->s_root);
887 fsc->sb->s_root = NULL;
888 }
889out: 888out:
890 mutex_unlock(&fsc->client->mount_mutex); 889 mutex_unlock(&fsc->client->mount_mutex);
891 return ERR_PTR(err); 890 return ERR_PTR(err);
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 21b2e5b004eb..1c2086e0fec2 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -987,7 +987,7 @@ extern void ceph_check_caps(struct ceph_inode_info *ci, int flags,
987 struct ceph_mds_session *session); 987 struct ceph_mds_session *session);
988extern void ceph_check_delayed_caps(struct ceph_mds_client *mdsc); 988extern void ceph_check_delayed_caps(struct ceph_mds_client *mdsc);
989extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc); 989extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc);
990 990extern int ceph_drop_caps_for_unlink(struct inode *inode);
991extern int ceph_encode_inode_release(void **p, struct inode *inode, 991extern int ceph_encode_inode_release(void **p, struct inode *inode,
992 int mds, int drop, int unless, int force); 992 int mds, int drop, int unless, int force);
993extern int ceph_encode_dentry_release(void **p, struct dentry *dn, 993extern int ceph_encode_dentry_release(void **p, struct dentry *dn,
diff --git a/fs/dcache.c b/fs/dcache.c
index 7c38f39958bc..8945e6cabd93 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -647,11 +647,16 @@ again:
647 spin_unlock(&parent->d_lock); 647 spin_unlock(&parent->d_lock);
648 goto again; 648 goto again;
649 } 649 }
650 rcu_read_unlock(); 650 if (parent != dentry) {
651 if (parent != dentry)
652 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); 651 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
653 else 652 if (unlikely(dentry->d_lockref.count < 0)) {
653 spin_unlock(&parent->d_lock);
654 parent = NULL;
655 }
656 } else {
654 parent = NULL; 657 parent = NULL;
658 }
659 rcu_read_unlock();
655 return parent; 660 return parent;
656} 661}
657 662
@@ -2474,7 +2479,7 @@ struct dentry *d_alloc_parallel(struct dentry *parent,
2474 2479
2475retry: 2480retry:
2476 rcu_read_lock(); 2481 rcu_read_lock();
2477 seq = smp_load_acquire(&parent->d_inode->i_dir_seq) & ~1; 2482 seq = smp_load_acquire(&parent->d_inode->i_dir_seq);
2478 r_seq = read_seqbegin(&rename_lock); 2483 r_seq = read_seqbegin(&rename_lock);
2479 dentry = __d_lookup_rcu(parent, name, &d_seq); 2484 dentry = __d_lookup_rcu(parent, name, &d_seq);
2480 if (unlikely(dentry)) { 2485 if (unlikely(dentry)) {
@@ -2495,8 +2500,14 @@ retry:
2495 rcu_read_unlock(); 2500 rcu_read_unlock();
2496 goto retry; 2501 goto retry;
2497 } 2502 }
2503
2504 if (unlikely(seq & 1)) {
2505 rcu_read_unlock();
2506 goto retry;
2507 }
2508
2498 hlist_bl_lock(b); 2509 hlist_bl_lock(b);
2499 if (unlikely(parent->d_inode->i_dir_seq != seq)) { 2510 if (unlikely(READ_ONCE(parent->d_inode->i_dir_seq) != seq)) {
2500 hlist_bl_unlock(b); 2511 hlist_bl_unlock(b);
2501 rcu_read_unlock(); 2512 rcu_read_unlock();
2502 goto retry; 2513 goto retry;
diff --git a/fs/direct-io.c b/fs/direct-io.c
index a0ca9e48e993..1357ef563893 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -1274,8 +1274,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
1274 */ 1274 */
1275 if (dio->is_async && iov_iter_rw(iter) == WRITE) { 1275 if (dio->is_async && iov_iter_rw(iter) == WRITE) {
1276 retval = 0; 1276 retval = 0;
1277 if ((iocb->ki_filp->f_flags & O_DSYNC) || 1277 if (iocb->ki_flags & IOCB_DSYNC)
1278 IS_SYNC(iocb->ki_filp->f_mapping->host))
1279 retval = dio_set_defer_completion(dio); 1278 retval = dio_set_defer_completion(dio);
1280 else if (!dio->inode->i_sb->s_dio_done_wq) { 1279 else if (!dio->inode->i_sb->s_dio_done_wq) {
1281 /* 1280 /*
diff --git a/fs/efivarfs/file.c b/fs/efivarfs/file.c
index 5f22e74bbade..8e568428c88b 100644
--- a/fs/efivarfs/file.c
+++ b/fs/efivarfs/file.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/efi.h> 10#include <linux/efi.h>
11#include <linux/delay.h>
11#include <linux/fs.h> 12#include <linux/fs.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13#include <linux/mount.h> 14#include <linux/mount.h>
@@ -74,6 +75,11 @@ static ssize_t efivarfs_file_read(struct file *file, char __user *userbuf,
74 ssize_t size = 0; 75 ssize_t size = 0;
75 int err; 76 int err;
76 77
78 while (!__ratelimit(&file->f_cred->user->ratelimit)) {
79 if (!msleep_interruptible(50))
80 return -EINTR;
81 }
82
77 err = efivar_entry_size(var, &datasize); 83 err = efivar_entry_size(var, &datasize);
78 84
79 /* 85 /*
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 86863792f36a..51f940e76c5e 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -716,7 +716,7 @@ int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
716 __be64 *ptr; 716 __be64 *ptr;
717 sector_t lblock; 717 sector_t lblock;
718 sector_t lend; 718 sector_t lend;
719 int ret; 719 int ret = 0;
720 int eob; 720 int eob;
721 unsigned int len; 721 unsigned int len;
722 struct buffer_head *bh; 722 struct buffer_head *bh;
@@ -728,12 +728,14 @@ int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
728 goto out; 728 goto out;
729 } 729 }
730 730
731 if ((flags & IOMAP_REPORT) && gfs2_is_stuffed(ip)) { 731 if (gfs2_is_stuffed(ip)) {
732 gfs2_stuffed_iomap(inode, iomap); 732 if (flags & IOMAP_REPORT) {
733 if (pos >= iomap->length) 733 gfs2_stuffed_iomap(inode, iomap);
734 return -ENOENT; 734 if (pos >= iomap->length)
735 ret = 0; 735 ret = -ENOENT;
736 goto out; 736 goto out;
737 }
738 BUG_ON(!(flags & IOMAP_WRITE));
737 } 739 }
738 740
739 lblock = pos >> inode->i_blkbits; 741 lblock = pos >> inode->i_blkbits;
@@ -744,7 +746,7 @@ int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
744 iomap->type = IOMAP_HOLE; 746 iomap->type = IOMAP_HOLE;
745 iomap->length = (u64)(lend - lblock) << inode->i_blkbits; 747 iomap->length = (u64)(lend - lblock) << inode->i_blkbits;
746 iomap->flags = IOMAP_F_MERGED; 748 iomap->flags = IOMAP_F_MERGED;
747 bmap_lock(ip, 0); 749 bmap_lock(ip, flags & IOMAP_WRITE);
748 750
749 /* 751 /*
750 * Directory data blocks have a struct gfs2_meta_header header, so the 752 * Directory data blocks have a struct gfs2_meta_header header, so the
@@ -787,27 +789,25 @@ int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
787 iomap->flags |= IOMAP_F_BOUNDARY; 789 iomap->flags |= IOMAP_F_BOUNDARY;
788 iomap->length = (u64)len << inode->i_blkbits; 790 iomap->length = (u64)len << inode->i_blkbits;
789 791
790 ret = 0;
791
792out_release: 792out_release:
793 release_metapath(&mp); 793 release_metapath(&mp);
794 bmap_unlock(ip, 0); 794 bmap_unlock(ip, flags & IOMAP_WRITE);
795out: 795out:
796 trace_gfs2_iomap_end(ip, iomap, ret); 796 trace_gfs2_iomap_end(ip, iomap, ret);
797 return ret; 797 return ret;
798 798
799do_alloc: 799do_alloc:
800 if (!(flags & IOMAP_WRITE)) { 800 if (flags & IOMAP_WRITE) {
801 if (pos >= i_size_read(inode)) { 801 ret = gfs2_iomap_alloc(inode, iomap, flags, &mp);
802 } else if (flags & IOMAP_REPORT) {
803 loff_t size = i_size_read(inode);
804 if (pos >= size)
802 ret = -ENOENT; 805 ret = -ENOENT;
803 goto out_release; 806 else if (height <= ip->i_height)
804 } 807 iomap->length = hole_size(inode, lblock, &mp);
805 ret = 0; 808 else
806 iomap->length = hole_size(inode, lblock, &mp); 809 iomap->length = size - pos;
807 goto out_release;
808 } 810 }
809
810 ret = gfs2_iomap_alloc(inode, iomap, flags, &mp);
811 goto out_release; 811 goto out_release;
812} 812}
813 813
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 8fe1b0aa2896..b9a254dcc0e7 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -108,6 +108,16 @@ static void huge_pagevec_release(struct pagevec *pvec)
108 pagevec_reinit(pvec); 108 pagevec_reinit(pvec);
109} 109}
110 110
111/*
112 * Mask used when checking the page offset value passed in via system
113 * calls. This value will be converted to a loff_t which is signed.
114 * Therefore, we want to check the upper PAGE_SHIFT + 1 bits of the
115 * value. The extra bit (- 1 in the shift value) is to take the sign
116 * bit into account.
117 */
118#define PGOFF_LOFFT_MAX \
119 (((1UL << (PAGE_SHIFT + 1)) - 1) << (BITS_PER_LONG - (PAGE_SHIFT + 1)))
120
111static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) 121static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
112{ 122{
113 struct inode *inode = file_inode(file); 123 struct inode *inode = file_inode(file);
@@ -127,12 +137,13 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
127 vma->vm_ops = &hugetlb_vm_ops; 137 vma->vm_ops = &hugetlb_vm_ops;
128 138
129 /* 139 /*
130 * Offset passed to mmap (before page shift) could have been 140 * page based offset in vm_pgoff could be sufficiently large to
131 * negative when represented as a (l)off_t. 141 * overflow a (l)off_t when converted to byte offset.
132 */ 142 */
133 if (((loff_t)vma->vm_pgoff << PAGE_SHIFT) < 0) 143 if (vma->vm_pgoff & PGOFF_LOFFT_MAX)
134 return -EINVAL; 144 return -EINVAL;
135 145
146 /* must be huge page aligned */
136 if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT)) 147 if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
137 return -EINVAL; 148 return -EINVAL;
138 149
diff --git a/fs/namei.c b/fs/namei.c
index 921ae32dbc80..cafa365eeb70 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -559,9 +559,10 @@ static int __nd_alloc_stack(struct nameidata *nd)
559static bool path_connected(const struct path *path) 559static bool path_connected(const struct path *path)
560{ 560{
561 struct vfsmount *mnt = path->mnt; 561 struct vfsmount *mnt = path->mnt;
562 struct super_block *sb = mnt->mnt_sb;
562 563
563 /* Only bind mounts can have disconnected paths */ 564 /* Bind mounts and multi-root filesystems can have disconnected paths */
564 if (mnt->mnt_root == mnt->mnt_sb->s_root) 565 if (!(sb->s_iflags & SB_I_MULTIROOT) && (mnt->mnt_root == sb->s_root))
565 return true; 566 return true;
566 567
567 return is_subdir(path->dentry, mnt->mnt_root); 568 return is_subdir(path->dentry, mnt->mnt_root);
diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
index 2435af56b87e..a50d7813e3ea 100644
--- a/fs/nfs/callback_proc.c
+++ b/fs/nfs/callback_proc.c
@@ -572,7 +572,7 @@ out:
572} 572}
573 573
574static bool 574static bool
575validate_bitmap_values(unsigned long mask) 575validate_bitmap_values(unsigned int mask)
576{ 576{
577 return (mask & ~RCA4_TYPE_MASK_ALL) == 0; 577 return (mask & ~RCA4_TYPE_MASK_ALL) == 0;
578} 578}
@@ -596,17 +596,15 @@ __be32 nfs4_callback_recallany(void *argp, void *resp,
596 goto out; 596 goto out;
597 597
598 status = cpu_to_be32(NFS4_OK); 598 status = cpu_to_be32(NFS4_OK);
599 if (test_bit(RCA4_TYPE_MASK_RDATA_DLG, (const unsigned long *) 599 if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_RDATA_DLG))
600 &args->craa_type_mask))
601 flags = FMODE_READ; 600 flags = FMODE_READ;
602 if (test_bit(RCA4_TYPE_MASK_WDATA_DLG, (const unsigned long *) 601 if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_WDATA_DLG))
603 &args->craa_type_mask))
604 flags |= FMODE_WRITE; 602 flags |= FMODE_WRITE;
605 if (test_bit(RCA4_TYPE_MASK_FILE_LAYOUT, (const unsigned long *)
606 &args->craa_type_mask))
607 pnfs_recall_all_layouts(cps->clp);
608 if (flags) 603 if (flags)
609 nfs_expire_unused_delegation_types(cps->clp, flags); 604 nfs_expire_unused_delegation_types(cps->clp, flags);
605
606 if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_FILE_LAYOUT))
607 pnfs_recall_all_layouts(cps->clp);
610out: 608out:
611 dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); 609 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
612 return status; 610 return status;
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 8c10b0562e75..621c517b325c 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -86,10 +86,10 @@ struct nfs_direct_req {
86 struct nfs_direct_mirror mirrors[NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX]; 86 struct nfs_direct_mirror mirrors[NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX];
87 int mirror_count; 87 int mirror_count;
88 88
89 loff_t io_start; /* Start offset for I/O */
89 ssize_t count, /* bytes actually processed */ 90 ssize_t count, /* bytes actually processed */
90 max_count, /* max expected count */ 91 max_count, /* max expected count */
91 bytes_left, /* bytes left to be sent */ 92 bytes_left, /* bytes left to be sent */
92 io_start, /* start of IO */
93 error; /* any reported error */ 93 error; /* any reported error */
94 struct completion completion; /* wait for i/o completion */ 94 struct completion completion; /* wait for i/o completion */
95 95
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index 49f848fd1f04..7327930ad970 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -873,7 +873,7 @@ static void nfs3_nlm_release_call(void *data)
873 } 873 }
874} 874}
875 875
876const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = { 876static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = {
877 .nlmclnt_alloc_call = nfs3_nlm_alloc_call, 877 .nlmclnt_alloc_call = nfs3_nlm_alloc_call,
878 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare, 878 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare,
879 .nlmclnt_release_call = nfs3_nlm_release_call, 879 .nlmclnt_release_call = nfs3_nlm_release_call,
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
index 04612c24d394..979631411a0e 100644
--- a/fs/nfs/nfs4client.c
+++ b/fs/nfs/nfs4client.c
@@ -868,8 +868,10 @@ static int nfs4_set_client(struct nfs_server *server,
868 if (IS_ERR(clp)) 868 if (IS_ERR(clp))
869 return PTR_ERR(clp); 869 return PTR_ERR(clp);
870 870
871 if (server->nfs_client == clp) 871 if (server->nfs_client == clp) {
872 nfs_put_client(clp);
872 return -ELOOP; 873 return -ELOOP;
874 }
873 875
874 /* 876 /*
875 * Query for the lease time on clientid setup or renewal 877 * Query for the lease time on clientid setup or renewal
@@ -1244,11 +1246,11 @@ int nfs4_update_server(struct nfs_server *server, const char *hostname,
1244 clp->cl_proto, clnt->cl_timeout, 1246 clp->cl_proto, clnt->cl_timeout,
1245 clp->cl_minorversion, net); 1247 clp->cl_minorversion, net);
1246 clear_bit(NFS_MIG_TSM_POSSIBLE, &server->mig_status); 1248 clear_bit(NFS_MIG_TSM_POSSIBLE, &server->mig_status);
1247 nfs_put_client(clp);
1248 if (error != 0) { 1249 if (error != 0) {
1249 nfs_server_insert_lists(server); 1250 nfs_server_insert_lists(server);
1250 return error; 1251 return error;
1251 } 1252 }
1253 nfs_put_client(clp);
1252 1254
1253 if (server->nfs_client->cl_hostname == NULL) 1255 if (server->nfs_client->cl_hostname == NULL)
1254 server->nfs_client->cl_hostname = kstrdup(hostname, GFP_KERNEL); 1256 server->nfs_client->cl_hostname = kstrdup(hostname, GFP_KERNEL);
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index c13e826614b5..ee723aa153a3 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -292,8 +292,11 @@ pnfs_detach_layout_hdr(struct pnfs_layout_hdr *lo)
292void 292void
293pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo) 293pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo)
294{ 294{
295 struct inode *inode = lo->plh_inode; 295 struct inode *inode;
296 296
297 if (!lo)
298 return;
299 inode = lo->plh_inode;
297 pnfs_layoutreturn_before_put_layout_hdr(lo); 300 pnfs_layoutreturn_before_put_layout_hdr(lo);
298 301
299 if (refcount_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) { 302 if (refcount_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) {
@@ -1241,10 +1244,12 @@ retry:
1241 spin_lock(&ino->i_lock); 1244 spin_lock(&ino->i_lock);
1242 lo = nfsi->layout; 1245 lo = nfsi->layout;
1243 if (!lo || !pnfs_layout_is_valid(lo) || 1246 if (!lo || !pnfs_layout_is_valid(lo) ||
1244 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) 1247 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
1248 lo = NULL;
1245 goto out_noroc; 1249 goto out_noroc;
1250 }
1251 pnfs_get_layout_hdr(lo);
1246 if (test_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags)) { 1252 if (test_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags)) {
1247 pnfs_get_layout_hdr(lo);
1248 spin_unlock(&ino->i_lock); 1253 spin_unlock(&ino->i_lock);
1249 wait_on_bit(&lo->plh_flags, NFS_LAYOUT_RETURN, 1254 wait_on_bit(&lo->plh_flags, NFS_LAYOUT_RETURN,
1250 TASK_UNINTERRUPTIBLE); 1255 TASK_UNINTERRUPTIBLE);
@@ -1312,10 +1317,12 @@ out_noroc:
1312 struct pnfs_layoutdriver_type *ld = NFS_SERVER(ino)->pnfs_curr_ld; 1317 struct pnfs_layoutdriver_type *ld = NFS_SERVER(ino)->pnfs_curr_ld;
1313 if (ld->prepare_layoutreturn) 1318 if (ld->prepare_layoutreturn)
1314 ld->prepare_layoutreturn(args); 1319 ld->prepare_layoutreturn(args);
1320 pnfs_put_layout_hdr(lo);
1315 return true; 1321 return true;
1316 } 1322 }
1317 if (layoutreturn) 1323 if (layoutreturn)
1318 pnfs_send_layoutreturn(lo, &stateid, iomode, true); 1324 pnfs_send_layoutreturn(lo, &stateid, iomode, true);
1325 pnfs_put_layout_hdr(lo);
1319 return false; 1326 return false;
1320} 1327}
1321 1328
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 29bacdc56f6a..5e470e233c83 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -2631,6 +2631,8 @@ struct dentry *nfs_fs_mount_common(struct nfs_server *server,
2631 /* initial superblock/root creation */ 2631 /* initial superblock/root creation */
2632 mount_info->fill_super(s, mount_info); 2632 mount_info->fill_super(s, mount_info);
2633 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned); 2633 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
2634 if (!(server->flags & NFS_MOUNT_UNSHARED))
2635 s->s_iflags |= SB_I_MULTIROOT;
2634 } 2636 }
2635 2637
2636 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name); 2638 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 7428a669d7a7..e7d8ceae8f26 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -1876,40 +1876,43 @@ int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
1876 return status; 1876 return status;
1877} 1877}
1878 1878
1879int nfs_commit_inode(struct inode *inode, int how) 1879static int __nfs_commit_inode(struct inode *inode, int how,
1880 struct writeback_control *wbc)
1880{ 1881{
1881 LIST_HEAD(head); 1882 LIST_HEAD(head);
1882 struct nfs_commit_info cinfo; 1883 struct nfs_commit_info cinfo;
1883 int may_wait = how & FLUSH_SYNC; 1884 int may_wait = how & FLUSH_SYNC;
1884 int error = 0; 1885 int ret, nscan;
1885 int res;
1886 1886
1887 nfs_init_cinfo_from_inode(&cinfo, inode); 1887 nfs_init_cinfo_from_inode(&cinfo, inode);
1888 nfs_commit_begin(cinfo.mds); 1888 nfs_commit_begin(cinfo.mds);
1889 res = nfs_scan_commit(inode, &head, &cinfo); 1889 for (;;) {
1890 if (res) 1890 ret = nscan = nfs_scan_commit(inode, &head, &cinfo);
1891 error = nfs_generic_commit_list(inode, &head, how, &cinfo); 1891 if (ret <= 0)
1892 break;
1893 ret = nfs_generic_commit_list(inode, &head, how, &cinfo);
1894 if (ret < 0)
1895 break;
1896 ret = 0;
1897 if (wbc && wbc->sync_mode == WB_SYNC_NONE) {
1898 if (nscan < wbc->nr_to_write)
1899 wbc->nr_to_write -= nscan;
1900 else
1901 wbc->nr_to_write = 0;
1902 }
1903 if (nscan < INT_MAX)
1904 break;
1905 cond_resched();
1906 }
1892 nfs_commit_end(cinfo.mds); 1907 nfs_commit_end(cinfo.mds);
1893 if (res == 0) 1908 if (ret || !may_wait)
1894 return res; 1909 return ret;
1895 if (error < 0) 1910 return wait_on_commit(cinfo.mds);
1896 goto out_error; 1911}
1897 if (!may_wait) 1912
1898 goto out_mark_dirty; 1913int nfs_commit_inode(struct inode *inode, int how)
1899 error = wait_on_commit(cinfo.mds); 1914{
1900 if (error < 0) 1915 return __nfs_commit_inode(inode, how, NULL);
1901 return error;
1902 return res;
1903out_error:
1904 res = error;
1905 /* Note: If we exit without ensuring that the commit is complete,
1906 * we must mark the inode as dirty. Otherwise, future calls to
1907 * sync_inode() with the WB_SYNC_ALL flag set will fail to ensure
1908 * that the data is on the disk.
1909 */
1910out_mark_dirty:
1911 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1912 return res;
1913} 1916}
1914EXPORT_SYMBOL_GPL(nfs_commit_inode); 1917EXPORT_SYMBOL_GPL(nfs_commit_inode);
1915 1918
@@ -1919,11 +1922,11 @@ int nfs_write_inode(struct inode *inode, struct writeback_control *wbc)
1919 int flags = FLUSH_SYNC; 1922 int flags = FLUSH_SYNC;
1920 int ret = 0; 1923 int ret = 0;
1921 1924
1922 /* no commits means nothing needs to be done */
1923 if (!atomic_long_read(&nfsi->commit_info.ncommit))
1924 return ret;
1925
1926 if (wbc->sync_mode == WB_SYNC_NONE) { 1925 if (wbc->sync_mode == WB_SYNC_NONE) {
1926 /* no commits means nothing needs to be done */
1927 if (!atomic_long_read(&nfsi->commit_info.ncommit))
1928 goto check_requests_outstanding;
1929
1927 /* Don't commit yet if this is a non-blocking flush and there 1930 /* Don't commit yet if this is a non-blocking flush and there
1928 * are a lot of outstanding writes for this mapping. 1931 * are a lot of outstanding writes for this mapping.
1929 */ 1932 */
@@ -1934,16 +1937,16 @@ int nfs_write_inode(struct inode *inode, struct writeback_control *wbc)
1934 flags = 0; 1937 flags = 0;
1935 } 1938 }
1936 1939
1937 ret = nfs_commit_inode(inode, flags); 1940 ret = __nfs_commit_inode(inode, flags, wbc);
1938 if (ret >= 0) { 1941 if (!ret) {
1939 if (wbc->sync_mode == WB_SYNC_NONE) { 1942 if (flags & FLUSH_SYNC)
1940 if (ret < wbc->nr_to_write) 1943 return 0;
1941 wbc->nr_to_write -= ret; 1944 } else if (atomic_long_read(&nfsi->commit_info.ncommit))
1942 else 1945 goto out_mark_dirty;
1943 wbc->nr_to_write = 0; 1946
1944 } 1947check_requests_outstanding:
1945 return 0; 1948 if (!atomic_read(&nfsi->commit_info.rpcs_out))
1946 } 1949 return ret;
1947out_mark_dirty: 1950out_mark_dirty:
1948 __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 1951 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1949 return ret; 1952 return ret;
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 150521c9671b..61b770e39809 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -268,6 +268,35 @@ free_blocked_lock(struct nfsd4_blocked_lock *nbl)
268 kfree(nbl); 268 kfree(nbl);
269} 269}
270 270
271static void
272remove_blocked_locks(struct nfs4_lockowner *lo)
273{
274 struct nfs4_client *clp = lo->lo_owner.so_client;
275 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
276 struct nfsd4_blocked_lock *nbl;
277 LIST_HEAD(reaplist);
278
279 /* Dequeue all blocked locks */
280 spin_lock(&nn->blocked_locks_lock);
281 while (!list_empty(&lo->lo_blocked)) {
282 nbl = list_first_entry(&lo->lo_blocked,
283 struct nfsd4_blocked_lock,
284 nbl_list);
285 list_del_init(&nbl->nbl_list);
286 list_move(&nbl->nbl_lru, &reaplist);
287 }
288 spin_unlock(&nn->blocked_locks_lock);
289
290 /* Now free them */
291 while (!list_empty(&reaplist)) {
292 nbl = list_first_entry(&reaplist, struct nfsd4_blocked_lock,
293 nbl_lru);
294 list_del_init(&nbl->nbl_lru);
295 posix_unblock_lock(&nbl->nbl_lock);
296 free_blocked_lock(nbl);
297 }
298}
299
271static int 300static int
272nfsd4_cb_notify_lock_done(struct nfsd4_callback *cb, struct rpc_task *task) 301nfsd4_cb_notify_lock_done(struct nfsd4_callback *cb, struct rpc_task *task)
273{ 302{
@@ -1866,6 +1895,7 @@ static __be32 mark_client_expired_locked(struct nfs4_client *clp)
1866static void 1895static void
1867__destroy_client(struct nfs4_client *clp) 1896__destroy_client(struct nfs4_client *clp)
1868{ 1897{
1898 int i;
1869 struct nfs4_openowner *oo; 1899 struct nfs4_openowner *oo;
1870 struct nfs4_delegation *dp; 1900 struct nfs4_delegation *dp;
1871 struct list_head reaplist; 1901 struct list_head reaplist;
@@ -1895,6 +1925,16 @@ __destroy_client(struct nfs4_client *clp)
1895 nfs4_get_stateowner(&oo->oo_owner); 1925 nfs4_get_stateowner(&oo->oo_owner);
1896 release_openowner(oo); 1926 release_openowner(oo);
1897 } 1927 }
1928 for (i = 0; i < OWNER_HASH_SIZE; i++) {
1929 struct nfs4_stateowner *so, *tmp;
1930
1931 list_for_each_entry_safe(so, tmp, &clp->cl_ownerstr_hashtbl[i],
1932 so_strhash) {
1933 /* Should be no openowners at this point */
1934 WARN_ON_ONCE(so->so_is_open_owner);
1935 remove_blocked_locks(lockowner(so));
1936 }
1937 }
1898 nfsd4_return_all_client_layouts(clp); 1938 nfsd4_return_all_client_layouts(clp);
1899 nfsd4_shutdown_callback(clp); 1939 nfsd4_shutdown_callback(clp);
1900 if (clp->cl_cb_conn.cb_xprt) 1940 if (clp->cl_cb_conn.cb_xprt)
@@ -6355,6 +6395,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
6355 } 6395 }
6356 spin_unlock(&clp->cl_lock); 6396 spin_unlock(&clp->cl_lock);
6357 free_ol_stateid_reaplist(&reaplist); 6397 free_ol_stateid_reaplist(&reaplist);
6398 remove_blocked_locks(lo);
6358 nfs4_put_stateowner(&lo->lo_owner); 6399 nfs4_put_stateowner(&lo->lo_owner);
6359 6400
6360 return status; 6401 return status;
@@ -7140,6 +7181,8 @@ nfs4_state_destroy_net(struct net *net)
7140 } 7181 }
7141 } 7182 }
7142 7183
7184 WARN_ON(!list_empty(&nn->blocked_locks_lru));
7185
7143 for (i = 0; i < CLIENT_HASH_SIZE; i++) { 7186 for (i = 0; i < CLIENT_HASH_SIZE; i++) {
7144 while (!list_empty(&nn->unconf_id_hashtbl[i])) { 7187 while (!list_empty(&nn->unconf_id_hashtbl[i])) {
7145 clp = list_entry(nn->unconf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); 7188 clp = list_entry(nn->unconf_id_hashtbl[i].next, struct nfs4_client, cl_idhash);
@@ -7206,7 +7249,6 @@ nfs4_state_shutdown_net(struct net *net)
7206 struct nfs4_delegation *dp = NULL; 7249 struct nfs4_delegation *dp = NULL;
7207 struct list_head *pos, *next, reaplist; 7250 struct list_head *pos, *next, reaplist;
7208 struct nfsd_net *nn = net_generic(net, nfsd_net_id); 7251 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
7209 struct nfsd4_blocked_lock *nbl;
7210 7252
7211 cancel_delayed_work_sync(&nn->laundromat_work); 7253 cancel_delayed_work_sync(&nn->laundromat_work);
7212 locks_end_grace(&nn->nfsd4_manager); 7254 locks_end_grace(&nn->nfsd4_manager);
@@ -7227,24 +7269,6 @@ nfs4_state_shutdown_net(struct net *net)
7227 nfs4_put_stid(&dp->dl_stid); 7269 nfs4_put_stid(&dp->dl_stid);
7228 } 7270 }
7229 7271
7230 BUG_ON(!list_empty(&reaplist));
7231 spin_lock(&nn->blocked_locks_lock);
7232 while (!list_empty(&nn->blocked_locks_lru)) {
7233 nbl = list_first_entry(&nn->blocked_locks_lru,
7234 struct nfsd4_blocked_lock, nbl_lru);
7235 list_move(&nbl->nbl_lru, &reaplist);
7236 list_del_init(&nbl->nbl_list);
7237 }
7238 spin_unlock(&nn->blocked_locks_lock);
7239
7240 while (!list_empty(&reaplist)) {
7241 nbl = list_first_entry(&reaplist,
7242 struct nfsd4_blocked_lock, nbl_lru);
7243 list_del_init(&nbl->nbl_lru);
7244 posix_unblock_lock(&nbl->nbl_lock);
7245 free_blocked_lock(nbl);
7246 }
7247
7248 nfsd4_client_tracking_exit(net); 7272 nfsd4_client_tracking_exit(net);
7249 nfs4_state_destroy_net(net); 7273 nfs4_state_destroy_net(net);
7250} 7274}
diff --git a/fs/overlayfs/Kconfig b/fs/overlayfs/Kconfig
index 406e72de88f6..ce6ff5a0a6e4 100644
--- a/fs/overlayfs/Kconfig
+++ b/fs/overlayfs/Kconfig
@@ -24,6 +24,8 @@ config OVERLAY_FS_REDIRECT_DIR
24 an overlay which has redirects on a kernel that doesn't support this 24 an overlay which has redirects on a kernel that doesn't support this
25 feature will have unexpected results. 25 feature will have unexpected results.
26 26
27 If unsure, say N.
28
27config OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW 29config OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW
28 bool "Overlayfs: follow redirects even if redirects are turned off" 30 bool "Overlayfs: follow redirects even if redirects are turned off"
29 default y 31 default y
@@ -32,8 +34,13 @@ config OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW
32 Disable this to get a possibly more secure configuration, but that 34 Disable this to get a possibly more secure configuration, but that
33 might not be backward compatible with previous kernels. 35 might not be backward compatible with previous kernels.
34 36
37 If backward compatibility is not an issue, then it is safe and
38 recommended to say N here.
39
35 For more information, see Documentation/filesystems/overlayfs.txt 40 For more information, see Documentation/filesystems/overlayfs.txt
36 41
42 If unsure, say Y.
43
37config OVERLAY_FS_INDEX 44config OVERLAY_FS_INDEX
38 bool "Overlayfs: turn on inodes index feature by default" 45 bool "Overlayfs: turn on inodes index feature by default"
39 depends on OVERLAY_FS 46 depends on OVERLAY_FS
@@ -51,6 +58,8 @@ config OVERLAY_FS_INDEX
51 That is, mounting an overlay which has an inodes index on a kernel 58 That is, mounting an overlay which has an inodes index on a kernel
52 that doesn't support this feature will have unexpected results. 59 that doesn't support this feature will have unexpected results.
53 60
61 If unsure, say N.
62
54config OVERLAY_FS_NFS_EXPORT 63config OVERLAY_FS_NFS_EXPORT
55 bool "Overlayfs: turn on NFS export feature by default" 64 bool "Overlayfs: turn on NFS export feature by default"
56 depends on OVERLAY_FS 65 depends on OVERLAY_FS
@@ -72,3 +81,8 @@ config OVERLAY_FS_NFS_EXPORT
72 Note, that the NFS export feature is not backward compatible. 81 Note, that the NFS export feature is not backward compatible.
73 That is, mounting an overlay which has a full index on a kernel 82 That is, mounting an overlay which has a full index on a kernel
74 that doesn't support this feature will have unexpected results. 83 that doesn't support this feature will have unexpected results.
84
85 Most users should say N here and enable this feature on a case-by-
86 case basis with the "nfs_export=on" mount option.
87
88 Say N unless you fully understand the consequences.
diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c
index bb94ce9da5c8..87bd4148f4fb 100644
--- a/fs/overlayfs/export.c
+++ b/fs/overlayfs/export.c
@@ -19,6 +19,142 @@
19#include <linux/ratelimit.h> 19#include <linux/ratelimit.h>
20#include "overlayfs.h" 20#include "overlayfs.h"
21 21
22static int ovl_encode_maybe_copy_up(struct dentry *dentry)
23{
24 int err;
25
26 if (ovl_dentry_upper(dentry))
27 return 0;
28
29 err = ovl_want_write(dentry);
30 if (!err) {
31 err = ovl_copy_up(dentry);
32 ovl_drop_write(dentry);
33 }
34
35 if (err) {
36 pr_warn_ratelimited("overlayfs: failed to copy up on encode (%pd2, err=%i)\n",
37 dentry, err);
38 }
39
40 return err;
41}
42
43/*
44 * Before encoding a non-upper directory file handle from real layer N, we need
45 * to check if it will be possible to reconnect an overlay dentry from the real
46 * lower decoded dentry. This is done by following the overlay ancestry up to a
47 * "layer N connected" ancestor and verifying that all parents along the way are
48 * "layer N connectable". If an ancestor that is NOT "layer N connectable" is
49 * found, we need to copy up an ancestor, which is "layer N connectable", thus
50 * making that ancestor "layer N connected". For example:
51 *
52 * layer 1: /a
53 * layer 2: /a/b/c
54 *
55 * The overlay dentry /a is NOT "layer 2 connectable", because if dir /a is
56 * copied up and renamed, upper dir /a will be indexed by lower dir /a from
57 * layer 1. The dir /a from layer 2 will never be indexed, so the algorithm (*)
58 * in ovl_lookup_real_ancestor() will not be able to lookup a connected overlay
59 * dentry from the connected lower dentry /a/b/c.
60 *
61 * To avoid this problem on decode time, we need to copy up an ancestor of
62 * /a/b/c, which is "layer 2 connectable", on encode time. That ancestor is
63 * /a/b. After copy up (and index) of /a/b, it will become "layer 2 connected"
64 * and when the time comes to decode the file handle from lower dentry /a/b/c,
65 * ovl_lookup_real_ancestor() will find the indexed ancestor /a/b and decoding
66 * a connected overlay dentry will be accomplished.
67 *
68 * (*) the algorithm in ovl_lookup_real_ancestor() can be improved to lookup an
69 * entry /a in the lower layers above layer N and find the indexed dir /a from
70 * layer 1. If that improvement is made, then the check for "layer N connected"
71 * will need to verify there are no redirects in lower layers above N. In the
72 * example above, /a will be "layer 2 connectable". However, if layer 2 dir /a
73 * is a target of a layer 1 redirect, then /a will NOT be "layer 2 connectable":
74 *
75 * layer 1: /A (redirect = /a)
76 * layer 2: /a/b/c
77 */
78
79/* Return the lowest layer for encoding a connectable file handle */
80static int ovl_connectable_layer(struct dentry *dentry)
81{
82 struct ovl_entry *oe = OVL_E(dentry);
83
84 /* We can get overlay root from root of any layer */
85 if (dentry == dentry->d_sb->s_root)
86 return oe->numlower;
87
88 /*
89 * If it's an unindexed merge dir, then it's not connectable with any
90 * lower layer
91 */
92 if (ovl_dentry_upper(dentry) &&
93 !ovl_test_flag(OVL_INDEX, d_inode(dentry)))
94 return 0;
95
96 /* We can get upper/overlay path from indexed/lower dentry */
97 return oe->lowerstack[0].layer->idx;
98}
99
100/*
101 * @dentry is "connected" if all ancestors up to root or a "connected" ancestor
102 * have the same uppermost lower layer as the origin's layer. We may need to
103 * copy up a "connectable" ancestor to make it "connected". A "connected" dentry
104 * cannot become non "connected", so cache positive result in dentry flags.
105 *
106 * Return the connected origin layer or < 0 on error.
107 */
108static int ovl_connect_layer(struct dentry *dentry)
109{
110 struct dentry *next, *parent = NULL;
111 int origin_layer;
112 int err = 0;
113
114 if (WARN_ON(dentry == dentry->d_sb->s_root) ||
115 WARN_ON(!ovl_dentry_lower(dentry)))
116 return -EIO;
117
118 origin_layer = OVL_E(dentry)->lowerstack[0].layer->idx;
119 if (ovl_dentry_test_flag(OVL_E_CONNECTED, dentry))
120 return origin_layer;
121
122 /* Find the topmost origin layer connectable ancestor of @dentry */
123 next = dget(dentry);
124 for (;;) {
125 parent = dget_parent(next);
126 if (WARN_ON(parent == next)) {
127 err = -EIO;
128 break;
129 }
130
131 /*
132 * If @parent is not origin layer connectable, then copy up
133 * @next which is origin layer connectable and we are done.
134 */
135 if (ovl_connectable_layer(parent) < origin_layer) {
136 err = ovl_encode_maybe_copy_up(next);
137 break;
138 }
139
140 /* If @parent is connected or indexed we are done */
141 if (ovl_dentry_test_flag(OVL_E_CONNECTED, parent) ||
142 ovl_test_flag(OVL_INDEX, d_inode(parent)))
143 break;
144
145 dput(next);
146 next = parent;
147 }
148
149 dput(parent);
150 dput(next);
151
152 if (!err)
153 ovl_dentry_set_flag(OVL_E_CONNECTED, dentry);
154
155 return err ?: origin_layer;
156}
157
22/* 158/*
23 * We only need to encode origin if there is a chance that the same object was 159 * We only need to encode origin if there is a chance that the same object was
24 * encoded pre copy up and then we need to stay consistent with the same 160 * encoded pre copy up and then we need to stay consistent with the same
@@ -41,73 +177,59 @@
41 * L = lower file handle 177 * L = lower file handle
42 * 178 *
43 * (*) Connecting an overlay dir from real lower dentry is not always 179 * (*) Connecting an overlay dir from real lower dentry is not always
44 * possible when there are redirects in lower layers. To mitigate this case, 180 * possible when there are redirects in lower layers and non-indexed merge dirs.
45 * we copy up the lower dir first and then encode an upper dir file handle. 181 * To mitigate those case, we may copy up the lower dir ancestor before encode
182 * a lower dir file handle.
183 *
184 * Return 0 for upper file handle, > 0 for lower file handle or < 0 on error.
46 */ 185 */
47static bool ovl_should_encode_origin(struct dentry *dentry) 186static int ovl_check_encode_origin(struct dentry *dentry)
48{ 187{
49 struct ovl_fs *ofs = dentry->d_sb->s_fs_info; 188 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
50 189
190 /* Upper file handle for pure upper */
51 if (!ovl_dentry_lower(dentry)) 191 if (!ovl_dentry_lower(dentry))
52 return false; 192 return 0;
53 193
54 /* 194 /*
55 * Decoding a merge dir, whose origin's parent is under a redirected 195 * Upper file handle for non-indexed upper.
56 * lower dir is not always possible. As a simple aproximation, we do
57 * not encode lower dir file handles when overlay has multiple lower
58 * layers and origin is below the topmost lower layer.
59 * 196 *
60 * TODO: copy up only the parent that is under redirected lower. 197 * Root is never indexed, so if there's an upper layer, encode upper for
198 * root.
61 */ 199 */
62 if (d_is_dir(dentry) && ofs->upper_mnt &&
63 OVL_E(dentry)->lowerstack[0].layer->idx > 1)
64 return false;
65
66 /* Decoding a non-indexed upper from origin is not implemented */
67 if (ovl_dentry_upper(dentry) && 200 if (ovl_dentry_upper(dentry) &&
68 !ovl_test_flag(OVL_INDEX, d_inode(dentry))) 201 !ovl_test_flag(OVL_INDEX, d_inode(dentry)))
69 return false;
70
71 return true;
72}
73
74static int ovl_encode_maybe_copy_up(struct dentry *dentry)
75{
76 int err;
77
78 if (ovl_dentry_upper(dentry))
79 return 0; 202 return 0;
80 203
81 err = ovl_want_write(dentry); 204 /*
82 if (err) 205 * Decoding a merge dir, whose origin's ancestor is under a redirected
83 return err; 206 * lower dir or under a non-indexed upper is not always possible.
84 207 * ovl_connect_layer() will try to make origin's layer "connected" by
85 err = ovl_copy_up(dentry); 208 * copying up a "connectable" ancestor.
209 */
210 if (d_is_dir(dentry) && ofs->upper_mnt)
211 return ovl_connect_layer(dentry);
86 212
87 ovl_drop_write(dentry); 213 /* Lower file handle for indexed and non-upper dir/non-dir */
88 return err; 214 return 1;
89} 215}
90 216
91static int ovl_d_to_fh(struct dentry *dentry, char *buf, int buflen) 217static int ovl_d_to_fh(struct dentry *dentry, char *buf, int buflen)
92{ 218{
93 struct dentry *origin = ovl_dentry_lower(dentry);
94 struct ovl_fh *fh = NULL; 219 struct ovl_fh *fh = NULL;
95 int err; 220 int err, enc_lower;
96 221
97 /* 222 /*
98 * If we should not encode a lower dir file handle, copy up and encode 223 * Check if we should encode a lower or upper file handle and maybe
99 * an upper dir file handle. 224 * copy up an ancestor to make lower file handle connectable.
100 */ 225 */
101 if (!ovl_should_encode_origin(dentry)) { 226 err = enc_lower = ovl_check_encode_origin(dentry);
102 err = ovl_encode_maybe_copy_up(dentry); 227 if (enc_lower < 0)
103 if (err) 228 goto fail;
104 goto fail;
105
106 origin = NULL;
107 }
108 229
109 /* Encode an upper or origin file handle */ 230 /* Encode an upper or lower file handle */
110 fh = ovl_encode_fh(origin ?: ovl_dentry_upper(dentry), !origin); 231 fh = ovl_encode_fh(enc_lower ? ovl_dentry_lower(dentry) :
232 ovl_dentry_upper(dentry), !enc_lower);
111 err = PTR_ERR(fh); 233 err = PTR_ERR(fh);
112 if (IS_ERR(fh)) 234 if (IS_ERR(fh))
113 goto fail; 235 goto fail;
@@ -355,8 +477,8 @@ static struct dentry *ovl_lookup_real_inode(struct super_block *sb,
355 dput(upper); 477 dput(upper);
356 } 478 }
357 479
358 if (!this) 480 if (IS_ERR_OR_NULL(this))
359 return NULL; 481 return this;
360 482
361 if (WARN_ON(ovl_dentry_real_at(this, layer->idx) != real)) { 483 if (WARN_ON(ovl_dentry_real_at(this, layer->idx) != real)) {
362 dput(this); 484 dput(this);
@@ -498,7 +620,7 @@ static struct dentry *ovl_lookup_real(struct super_block *sb,
498 if (err == -ECHILD) { 620 if (err == -ECHILD) {
499 this = ovl_lookup_real_ancestor(sb, real, 621 this = ovl_lookup_real_ancestor(sb, real,
500 layer); 622 layer);
501 err = IS_ERR(this) ? PTR_ERR(this) : 0; 623 err = PTR_ERR_OR_ZERO(this);
502 } 624 }
503 if (!err) { 625 if (!err) {
504 dput(connected); 626 dput(connected);
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index fcd97b783fa1..3b1bd469accd 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -669,38 +669,59 @@ struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
669 return inode; 669 return inode;
670} 670}
671 671
672/*
673 * Does overlay inode need to be hashed by lower inode?
674 */
675static bool ovl_hash_bylower(struct super_block *sb, struct dentry *upper,
676 struct dentry *lower, struct dentry *index)
677{
678 struct ovl_fs *ofs = sb->s_fs_info;
679
680 /* No, if pure upper */
681 if (!lower)
682 return false;
683
684 /* Yes, if already indexed */
685 if (index)
686 return true;
687
688 /* Yes, if won't be copied up */
689 if (!ofs->upper_mnt)
690 return true;
691
692 /* No, if lower hardlink is or will be broken on copy up */
693 if ((upper || !ovl_indexdir(sb)) &&
694 !d_is_dir(lower) && d_inode(lower)->i_nlink > 1)
695 return false;
696
697 /* No, if non-indexed upper with NFS export */
698 if (sb->s_export_op && upper)
699 return false;
700
701 /* Otherwise, hash by lower inode for fsnotify */
702 return true;
703}
704
672struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry, 705struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry,
673 struct dentry *lowerdentry, struct dentry *index, 706 struct dentry *lowerdentry, struct dentry *index,
674 unsigned int numlower) 707 unsigned int numlower)
675{ 708{
676 struct ovl_fs *ofs = sb->s_fs_info;
677 struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL; 709 struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL;
678 struct inode *inode; 710 struct inode *inode;
679 /* Already indexed or could be indexed on copy up? */ 711 bool bylower = ovl_hash_bylower(sb, upperdentry, lowerdentry, index);
680 bool indexed = (index || (ovl_indexdir(sb) && !upperdentry));
681 struct dentry *origin = indexed ? lowerdentry : NULL;
682 bool is_dir; 712 bool is_dir;
683 713
684 if (WARN_ON(upperdentry && indexed && !lowerdentry))
685 return ERR_PTR(-EIO);
686
687 if (!realinode) 714 if (!realinode)
688 realinode = d_inode(lowerdentry); 715 realinode = d_inode(lowerdentry);
689 716
690 /* 717 /*
691 * Copy up origin (lower) may exist for non-indexed non-dir upper, but 718 * Copy up origin (lower) may exist for non-indexed upper, but we must
692 * we must not use lower as hash key in that case. 719 * not use lower as hash key if this is a broken hardlink.
693 * Hash non-dir that is or could be indexed by origin inode.
694 * Hash dir that is or could be merged by origin inode.
695 * Hash pure upper and non-indexed non-dir by upper inode.
696 * Hash non-indexed dir by upper inode for NFS export.
697 */ 720 */
698 is_dir = S_ISDIR(realinode->i_mode); 721 is_dir = S_ISDIR(realinode->i_mode);
699 if (is_dir && (indexed || !sb->s_export_op || !ofs->upper_mnt)) 722 if (upperdentry || bylower) {
700 origin = lowerdentry; 723 struct inode *key = d_inode(bylower ? lowerdentry :
701 724 upperdentry);
702 if (upperdentry || origin) {
703 struct inode *key = d_inode(origin ?: upperdentry);
704 unsigned int nlink = is_dir ? 1 : realinode->i_nlink; 725 unsigned int nlink = is_dir ? 1 : realinode->i_nlink;
705 726
706 inode = iget5_locked(sb, (unsigned long) key, 727 inode = iget5_locked(sb, (unsigned long) key,
@@ -728,6 +749,7 @@ struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry,
728 nlink = ovl_get_nlink(lowerdentry, upperdentry, nlink); 749 nlink = ovl_get_nlink(lowerdentry, upperdentry, nlink);
729 set_nlink(inode, nlink); 750 set_nlink(inode, nlink);
730 } else { 751 } else {
752 /* Lower hardlink that will be broken on copy up */
731 inode = new_inode(sb); 753 inode = new_inode(sb);
732 if (!inode) 754 if (!inode)
733 goto out_nomem; 755 goto out_nomem;
diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
index de3e6da1d5a5..70fcfcc684cc 100644
--- a/fs/overlayfs/namei.c
+++ b/fs/overlayfs/namei.c
@@ -913,9 +913,6 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
913 stack[ctr].layer = lower.layer; 913 stack[ctr].layer = lower.layer;
914 ctr++; 914 ctr++;
915 915
916 if (d.stop)
917 break;
918
919 /* 916 /*
920 * Following redirects can have security consequences: it's like 917 * Following redirects can have security consequences: it's like
921 * a symlink into the lower layer without the permission checks. 918 * a symlink into the lower layer without the permission checks.
@@ -933,6 +930,9 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
933 goto out_put; 930 goto out_put;
934 } 931 }
935 932
933 if (d.stop)
934 break;
935
936 if (d.redirect && d.redirect[0] == '/' && poe != roe) { 936 if (d.redirect && d.redirect[0] == '/' && poe != roe) {
937 poe = roe; 937 poe = roe;
938 /* Find the current layer on the root dentry */ 938 /* Find the current layer on the root dentry */
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 0df25a9c94bd..225ff1171147 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -40,6 +40,7 @@ enum ovl_inode_flag {
40enum ovl_entry_flag { 40enum ovl_entry_flag {
41 OVL_E_UPPER_ALIAS, 41 OVL_E_UPPER_ALIAS,
42 OVL_E_OPAQUE, 42 OVL_E_OPAQUE,
43 OVL_E_CONNECTED,
43}; 44};
44 45
45/* 46/*
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 9ee37c76091d..7c24619ae7fc 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -1359,6 +1359,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
1359 1359
1360 /* Root is always merge -> can have whiteouts */ 1360 /* Root is always merge -> can have whiteouts */
1361 ovl_set_flag(OVL_WHITEOUTS, d_inode(root_dentry)); 1361 ovl_set_flag(OVL_WHITEOUTS, d_inode(root_dentry));
1362 ovl_dentry_set_flag(OVL_E_CONNECTED, root_dentry);
1362 ovl_inode_init(d_inode(root_dentry), upperpath.dentry, 1363 ovl_inode_init(d_inode(root_dentry), upperpath.dentry,
1363 ovl_dentry_lower(root_dentry)); 1364 ovl_dentry_lower(root_dentry));
1364 1365
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index e8a93bc8285d..d1e82761de81 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -510,6 +510,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
510 /* we have to zero-fill user buffer even if no read */ 510 /* we have to zero-fill user buffer even if no read */
511 if (copy_to_user(buffer, buf, tsz)) 511 if (copy_to_user(buffer, buf, tsz))
512 return -EFAULT; 512 return -EFAULT;
513 } else if (m->type == KCORE_USER) {
514 /* User page is handled prior to normal kernel page: */
515 if (copy_to_user(buffer, (char *)start, tsz))
516 return -EFAULT;
513 } else { 517 } else {
514 if (kern_addr_valid(start)) { 518 if (kern_addr_valid(start)) {
515 /* 519 /*
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 9990957264e3..76bf9cc62074 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -118,13 +118,22 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
118 err |= __put_user(kinfo->si_trapno, &uinfo->ssi_trapno); 118 err |= __put_user(kinfo->si_trapno, &uinfo->ssi_trapno);
119#endif 119#endif
120#ifdef BUS_MCEERR_AO 120#ifdef BUS_MCEERR_AO
121 /* 121 /*
122 * Other callers might not initialize the si_lsb field,
123 * so check explicitly for the right codes here.
124 */
125 if (kinfo->si_signo == SIGBUS &&
126 kinfo->si_code == BUS_MCEERR_AO)
127 err |= __put_user((short) kinfo->si_addr_lsb,
128 &uinfo->ssi_addr_lsb);
129#endif
130#ifdef BUS_MCEERR_AR
131 /*
122 * Other callers might not initialize the si_lsb field, 132 * Other callers might not initialize the si_lsb field,
123 * so check explicitly for the right codes here. 133 * so check explicitly for the right codes here.
124 */ 134 */
125 if (kinfo->si_signo == SIGBUS && 135 if (kinfo->si_signo == SIGBUS &&
126 (kinfo->si_code == BUS_MCEERR_AR || 136 kinfo->si_code == BUS_MCEERR_AR)
127 kinfo->si_code == BUS_MCEERR_AO))
128 err |= __put_user((short) kinfo->si_addr_lsb, 137 err |= __put_user((short) kinfo->si_addr_lsb,
129 &uinfo->ssi_addr_lsb); 138 &uinfo->ssi_addr_lsb);
130#endif 139#endif
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 8664db25a9a6..215c225b2ca1 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -106,6 +106,7 @@ int sysfs_create_link_nowarn(struct kobject *kobj, struct kobject *target,
106{ 106{
107 return sysfs_do_create_link(kobj, target, name, 0); 107 return sysfs_do_create_link(kobj, target, name, 0);
108} 108}
109EXPORT_SYMBOL_GPL(sysfs_create_link_nowarn);
109 110
110/** 111/**
111 * sysfs_delete_link - remove symlink in object's directory. 112 * sysfs_delete_link - remove symlink in object's directory.
diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
index fd975524f460..05c66e05ae20 100644
--- a/fs/xfs/scrub/agheader.c
+++ b/fs/xfs/scrub/agheader.c
@@ -767,7 +767,7 @@ int
767xfs_scrub_agfl( 767xfs_scrub_agfl(
768 struct xfs_scrub_context *sc) 768 struct xfs_scrub_context *sc)
769{ 769{
770 struct xfs_scrub_agfl_info sai = { 0 }; 770 struct xfs_scrub_agfl_info sai;
771 struct xfs_agf *agf; 771 struct xfs_agf *agf;
772 xfs_agnumber_t agno; 772 xfs_agnumber_t agno;
773 unsigned int agflcount; 773 unsigned int agflcount;
@@ -795,6 +795,7 @@ xfs_scrub_agfl(
795 xfs_scrub_block_set_corrupt(sc, sc->sa.agf_bp); 795 xfs_scrub_block_set_corrupt(sc, sc->sa.agf_bp);
796 goto out; 796 goto out;
797 } 797 }
798 memset(&sai, 0, sizeof(sai));
798 sai.sz_entries = agflcount; 799 sai.sz_entries = agflcount;
799 sai.entries = kmem_zalloc(sizeof(xfs_agblock_t) * agflcount, KM_NOFS); 800 sai.entries = kmem_zalloc(sizeof(xfs_agblock_t) * agflcount, KM_NOFS);
800 if (!sai.entries) { 801 if (!sai.entries) {
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 66e1edbfb2b2..046469fcc1b8 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -955,15 +955,29 @@ static inline bool imap_needs_alloc(struct inode *inode,
955 (IS_DAX(inode) && imap->br_state == XFS_EXT_UNWRITTEN); 955 (IS_DAX(inode) && imap->br_state == XFS_EXT_UNWRITTEN);
956} 956}
957 957
958static inline bool needs_cow_for_zeroing(struct xfs_bmbt_irec *imap, int nimaps)
959{
960 return nimaps &&
961 imap->br_startblock != HOLESTARTBLOCK &&
962 imap->br_state != XFS_EXT_UNWRITTEN;
963}
964
958static inline bool need_excl_ilock(struct xfs_inode *ip, unsigned flags) 965static inline bool need_excl_ilock(struct xfs_inode *ip, unsigned flags)
959{ 966{
960 /* 967 /*
961 * COW writes will allocate delalloc space, so we need to make sure 968 * COW writes may allocate delalloc space or convert unwritten COW
962 * to take the lock exclusively here. 969 * extents, so we need to make sure to take the lock exclusively here.
963 */ 970 */
964 if (xfs_is_reflink_inode(ip) && (flags & (IOMAP_WRITE | IOMAP_ZERO))) 971 if (xfs_is_reflink_inode(ip) && (flags & (IOMAP_WRITE | IOMAP_ZERO)))
965 return true; 972 return true;
966 if ((flags & IOMAP_DIRECT) && (flags & IOMAP_WRITE)) 973
974 /*
975 * Extents not yet cached requires exclusive access, don't block.
976 * This is an opencoded xfs_ilock_data_map_shared() to cater for the
977 * non-blocking behaviour.
978 */
979 if (ip->i_d.di_format == XFS_DINODE_FMT_BTREE &&
980 !(ip->i_df.if_flags & XFS_IFEXTENTS))
967 return true; 981 return true;
968 return false; 982 return false;
969} 983}
@@ -993,16 +1007,18 @@ xfs_file_iomap_begin(
993 return xfs_file_iomap_begin_delay(inode, offset, length, iomap); 1007 return xfs_file_iomap_begin_delay(inode, offset, length, iomap);
994 } 1008 }
995 1009
996 if (need_excl_ilock(ip, flags)) { 1010 if (need_excl_ilock(ip, flags))
997 lockmode = XFS_ILOCK_EXCL; 1011 lockmode = XFS_ILOCK_EXCL;
998 xfs_ilock(ip, XFS_ILOCK_EXCL); 1012 else
999 } else { 1013 lockmode = XFS_ILOCK_SHARED;
1000 lockmode = xfs_ilock_data_map_shared(ip);
1001 }
1002 1014
1003 if ((flags & IOMAP_NOWAIT) && !(ip->i_df.if_flags & XFS_IFEXTENTS)) { 1015 if (flags & IOMAP_NOWAIT) {
1004 error = -EAGAIN; 1016 if (!(ip->i_df.if_flags & XFS_IFEXTENTS))
1005 goto out_unlock; 1017 return -EAGAIN;
1018 if (!xfs_ilock_nowait(ip, lockmode))
1019 return -EAGAIN;
1020 } else {
1021 xfs_ilock(ip, lockmode);
1006 } 1022 }
1007 1023
1008 ASSERT(offset <= mp->m_super->s_maxbytes); 1024 ASSERT(offset <= mp->m_super->s_maxbytes);
@@ -1024,7 +1040,9 @@ xfs_file_iomap_begin(
1024 goto out_unlock; 1040 goto out_unlock;
1025 } 1041 }
1026 1042
1027 if ((flags & (IOMAP_WRITE | IOMAP_ZERO)) && xfs_is_reflink_inode(ip)) { 1043 if (xfs_is_reflink_inode(ip) &&
1044 ((flags & IOMAP_WRITE) ||
1045 ((flags & IOMAP_ZERO) && needs_cow_for_zeroing(&imap, nimaps)))) {
1028 if (flags & IOMAP_DIRECT) { 1046 if (flags & IOMAP_DIRECT) {
1029 /* 1047 /*
1030 * A reflinked inode will result in CoW alloc. 1048 * A reflinked inode will result in CoW alloc.
diff --git a/fs/xfs/xfs_refcount_item.c b/fs/xfs/xfs_refcount_item.c
index 3a55d6fc271b..7a39f40645f7 100644
--- a/fs/xfs/xfs_refcount_item.c
+++ b/fs/xfs/xfs_refcount_item.c
@@ -23,6 +23,7 @@
23#include "xfs_log_format.h" 23#include "xfs_log_format.h"
24#include "xfs_trans_resv.h" 24#include "xfs_trans_resv.h"
25#include "xfs_bit.h" 25#include "xfs_bit.h"
26#include "xfs_shared.h"
26#include "xfs_mount.h" 27#include "xfs_mount.h"
27#include "xfs_defer.h" 28#include "xfs_defer.h"
28#include "xfs_trans.h" 29#include "xfs_trans.h"
@@ -456,10 +457,12 @@ xfs_cui_recover(
456 * transaction. Normally, any work that needs to be deferred 457 * transaction. Normally, any work that needs to be deferred
457 * gets attached to the same defer_ops that scheduled the 458 * gets attached to the same defer_ops that scheduled the
458 * refcount update. However, we're in log recovery here, so we 459 * refcount update. However, we're in log recovery here, so we
459 * we create our own defer_ops and use that to finish up any 460 * we use the passed in defer_ops and to finish up any work that
460 * work that doesn't fit. 461 * doesn't fit. We need to reserve enough blocks to handle a
462 * full btree split on either end of the refcount range.
461 */ 463 */
462 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); 464 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
465 mp->m_refc_maxlevels * 2, 0, XFS_TRANS_RESERVE, &tp);
463 if (error) 466 if (error)
464 return error; 467 return error;
465 cudp = xfs_trans_get_cud(tp, cuip); 468 cudp = xfs_trans_get_cud(tp, cuip);
diff --git a/fs/xfs/xfs_rmap_item.c b/fs/xfs/xfs_rmap_item.c
index f3b139c9aa16..49d3124863a8 100644
--- a/fs/xfs/xfs_rmap_item.c
+++ b/fs/xfs/xfs_rmap_item.c
@@ -23,6 +23,7 @@
23#include "xfs_log_format.h" 23#include "xfs_log_format.h"
24#include "xfs_trans_resv.h" 24#include "xfs_trans_resv.h"
25#include "xfs_bit.h" 25#include "xfs_bit.h"
26#include "xfs_shared.h"
26#include "xfs_mount.h" 27#include "xfs_mount.h"
27#include "xfs_defer.h" 28#include "xfs_defer.h"
28#include "xfs_trans.h" 29#include "xfs_trans.h"
@@ -470,7 +471,8 @@ xfs_rui_recover(
470 } 471 }
471 } 472 }
472 473
473 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); 474 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
475 mp->m_rmap_maxlevels, 0, XFS_TRANS_RESERVE, &tp);
474 if (error) 476 if (error)
475 return error; 477 return error;
476 rudp = xfs_trans_get_rud(tp, ruip); 478 rudp = xfs_trans_get_rud(tp, ruip);
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 7aba628dc527..93588ea3d3d2 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -250,6 +250,7 @@ xfs_parseargs(
250 return -EINVAL; 250 return -EINVAL;
251 break; 251 break;
252 case Opt_logdev: 252 case Opt_logdev:
253 kfree(mp->m_logname);
253 mp->m_logname = match_strdup(args); 254 mp->m_logname = match_strdup(args);
254 if (!mp->m_logname) 255 if (!mp->m_logname)
255 return -ENOMEM; 256 return -ENOMEM;
@@ -258,6 +259,7 @@ xfs_parseargs(
258 xfs_warn(mp, "%s option not allowed on this system", p); 259 xfs_warn(mp, "%s option not allowed on this system", p);
259 return -EINVAL; 260 return -EINVAL;
260 case Opt_rtdev: 261 case Opt_rtdev:
262 kfree(mp->m_rtname);
261 mp->m_rtname = match_strdup(args); 263 mp->m_rtname = match_strdup(args);
262 if (!mp->m_rtname) 264 if (!mp->m_rtname)
263 return -ENOMEM; 265 return -ENOMEM;
diff --git a/include/asm-generic/bitops/lock.h b/include/asm-generic/bitops/lock.h
index bc397573c43a..67ab280ad134 100644
--- a/include/asm-generic/bitops/lock.h
+++ b/include/asm-generic/bitops/lock.h
@@ -7,7 +7,8 @@
7 * @nr: Bit to set 7 * @nr: Bit to set
8 * @addr: Address to count from 8 * @addr: Address to count from
9 * 9 *
10 * This operation is atomic and provides acquire barrier semantics. 10 * This operation is atomic and provides acquire barrier semantics if
11 * the returned value is 0.
11 * It can be used to implement bit locks. 12 * It can be used to implement bit locks.
12 */ 13 */
13#define test_and_set_bit_lock(nr, addr) test_and_set_bit(nr, addr) 14#define test_and_set_bit_lock(nr, addr) test_and_set_bit(nr, addr)
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 963b755d19b0..a7613e1b0c87 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -52,6 +52,7 @@ struct bug_entry {
52#ifndef HAVE_ARCH_BUG 52#ifndef HAVE_ARCH_BUG
53#define BUG() do { \ 53#define BUG() do { \
54 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ 54 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
55 barrier_before_unreachable(); \
55 panic("BUG!"); \ 56 panic("BUG!"); \
56} while (0) 57} while (0)
57#endif 58#endif
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 2cfa3075d148..bfbb44a5ad38 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -983,6 +983,8 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot);
983int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); 983int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot);
984int pud_clear_huge(pud_t *pud); 984int pud_clear_huge(pud_t *pud);
985int pmd_clear_huge(pmd_t *pmd); 985int pmd_clear_huge(pmd_t *pmd);
986int pud_free_pmd_page(pud_t *pud);
987int pmd_free_pte_page(pmd_t *pmd);
986#else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ 988#else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */
987static inline int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot) 989static inline int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot)
988{ 990{
@@ -1008,6 +1010,14 @@ static inline int pmd_clear_huge(pmd_t *pmd)
1008{ 1010{
1009 return 0; 1011 return 0;
1010} 1012}
1013static inline int pud_free_pmd_page(pud_t *pud)
1014{
1015 return 0;
1016}
1017static inline int pmd_free_pte_page(pmd_t *pmd)
1018{
1019 return 0;
1020}
1011#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ 1021#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
1012 1022
1013#ifndef __HAVE_ARCH_FLUSH_PMD_TLB_RANGE 1023#ifndef __HAVE_ARCH_FLUSH_PMD_TLB_RANGE
diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
index 76e237bd989b..6914633037a5 100644
--- a/include/drm/drm_crtc_helper.h
+++ b/include/drm/drm_crtc_helper.h
@@ -77,5 +77,6 @@ void drm_kms_helper_hotplug_event(struct drm_device *dev);
77 77
78void drm_kms_helper_poll_disable(struct drm_device *dev); 78void drm_kms_helper_poll_disable(struct drm_device *dev);
79void drm_kms_helper_poll_enable(struct drm_device *dev); 79void drm_kms_helper_poll_enable(struct drm_device *dev);
80bool drm_kms_helper_is_poll_worker(void);
80 81
81#endif 82#endif
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index d32b688eb346..d23dcdd1bd95 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -56,6 +56,7 @@ struct drm_printer;
56#define DRIVER_ATOMIC 0x10000 56#define DRIVER_ATOMIC 0x10000
57#define DRIVER_KMS_LEGACY_CONTEXT 0x20000 57#define DRIVER_KMS_LEGACY_CONTEXT 0x20000
58#define DRIVER_SYNCOBJ 0x40000 58#define DRIVER_SYNCOBJ 0x40000
59#define DRIVER_PREFER_XBGR_30BPP 0x80000
59 60
60/** 61/**
61 * struct drm_driver - DRM driver structure 62 * struct drm_driver - DRM driver structure
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index cdbd142ca7f2..02924ae2527e 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -360,6 +360,7 @@ void kvm_vgic_put(struct kvm_vcpu *vcpu);
360bool kvm_vcpu_has_pending_irqs(struct kvm_vcpu *vcpu); 360bool kvm_vcpu_has_pending_irqs(struct kvm_vcpu *vcpu);
361void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu); 361void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu);
362void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu); 362void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu);
363void kvm_vgic_reset_mapped_irq(struct kvm_vcpu *vcpu, u32 vintid);
363 364
364void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg); 365void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg);
365 366
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 64e10746f282..968173ec2726 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -587,7 +587,7 @@ extern int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *),
587const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids, 587const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
588 const struct device *dev); 588 const struct device *dev);
589 589
590void *acpi_get_match_data(const struct device *dev); 590const void *acpi_device_get_match_data(const struct device *dev);
591extern bool acpi_driver_match_device(struct device *dev, 591extern bool acpi_driver_match_device(struct device *dev,
592 const struct device_driver *drv); 592 const struct device_driver *drv);
593int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *); 593int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *);
@@ -766,7 +766,7 @@ static inline const struct acpi_device_id *acpi_match_device(
766 return NULL; 766 return NULL;
767} 767}
768 768
769static inline void *acpi_get_match_data(const struct device *dev) 769static inline const void *acpi_device_get_match_data(const struct device *dev)
770{ 770{
771 return NULL; 771 return NULL;
772} 772}
diff --git a/include/linux/bio.h b/include/linux/bio.h
index d0eb659fa733..ce547a25e8ae 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -511,6 +511,7 @@ void zero_fill_bio(struct bio *bio);
511extern struct bio_vec *bvec_alloc(gfp_t, int, unsigned long *, mempool_t *); 511extern struct bio_vec *bvec_alloc(gfp_t, int, unsigned long *, mempool_t *);
512extern void bvec_free(mempool_t *, struct bio_vec *, unsigned int); 512extern void bvec_free(mempool_t *, struct bio_vec *, unsigned int);
513extern unsigned int bvec_nr_vecs(unsigned short idx); 513extern unsigned int bvec_nr_vecs(unsigned short idx);
514extern const char *bio_devname(struct bio *bio, char *buffer);
514 515
515#define bio_set_dev(bio, bdev) \ 516#define bio_set_dev(bio, bdev) \
516do { \ 517do { \
@@ -529,9 +530,6 @@ do { \
529#define bio_dev(bio) \ 530#define bio_dev(bio) \
530 disk_devt((bio)->bi_disk) 531 disk_devt((bio)->bi_disk)
531 532
532#define bio_devname(bio, buf) \
533 __bdevname(bio_dev(bio), (buf))
534
535#ifdef CONFIG_BLK_CGROUP 533#ifdef CONFIG_BLK_CGROUP
536int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css); 534int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css);
537void bio_disassociate_task(struct bio *bio); 535void bio_disassociate_task(struct bio *bio);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 4f3df807cf8f..ed63f3b69c12 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -49,7 +49,7 @@ struct blk_stat_callback;
49#define BLKDEV_MIN_RQ 4 49#define BLKDEV_MIN_RQ 4
50#define BLKDEV_MAX_RQ 128 /* Default maximum */ 50#define BLKDEV_MAX_RQ 128 /* Default maximum */
51 51
52/* Must be consisitent with blk_mq_poll_stats_bkt() */ 52/* Must be consistent with blk_mq_poll_stats_bkt() */
53#define BLK_MQ_POLL_STATS_BKTS 16 53#define BLK_MQ_POLL_STATS_BKTS 16
54 54
55/* 55/*
diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index 9f242b876fde..f8e76d01a5ad 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -755,13 +755,13 @@ struct sock_cgroup_data {
755 * updaters and return part of the previous pointer as the prioidx or 755 * updaters and return part of the previous pointer as the prioidx or
756 * classid. Such races are short-lived and the result isn't critical. 756 * classid. Such races are short-lived and the result isn't critical.
757 */ 757 */
758static inline u16 sock_cgroup_prioidx(struct sock_cgroup_data *skcd) 758static inline u16 sock_cgroup_prioidx(const struct sock_cgroup_data *skcd)
759{ 759{
760 /* fallback to 1 which is always the ID of the root cgroup */ 760 /* fallback to 1 which is always the ID of the root cgroup */
761 return (skcd->is_data & 1) ? skcd->prioidx : 1; 761 return (skcd->is_data & 1) ? skcd->prioidx : 1;
762} 762}
763 763
764static inline u32 sock_cgroup_classid(struct sock_cgroup_data *skcd) 764static inline u32 sock_cgroup_classid(const struct sock_cgroup_data *skcd)
765{ 765{
766 /* fallback to 0 which is the unconfigured default classid */ 766 /* fallback to 0 which is the unconfigured default classid */
767 return (skcd->is_data & 1) ? skcd->classid : 0; 767 return (skcd->is_data & 1) ? skcd->classid : 0;
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 8a9643857c4a..16c3027074a2 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -17,6 +17,7 @@
17#include <linux/if.h> 17#include <linux/if.h>
18#include <linux/fs.h> 18#include <linux/fs.h>
19#include <linux/aio_abi.h> /* for aio_context_t */ 19#include <linux/aio_abi.h> /* for aio_context_t */
20#include <linux/uaccess.h>
20#include <linux/unistd.h> 21#include <linux/unistd.h>
21 22
22#include <asm/compat.h> 23#include <asm/compat.h>
@@ -229,13 +230,13 @@ typedef struct compat_siginfo {
229 short int _addr_lsb; /* Valid LSB of the reported address. */ 230 short int _addr_lsb; /* Valid LSB of the reported address. */
230 /* used when si_code=SEGV_BNDERR */ 231 /* used when si_code=SEGV_BNDERR */
231 struct { 232 struct {
232 short _dummy_bnd; 233 compat_uptr_t _dummy_bnd;
233 compat_uptr_t _lower; 234 compat_uptr_t _lower;
234 compat_uptr_t _upper; 235 compat_uptr_t _upper;
235 } _addr_bnd; 236 } _addr_bnd;
236 /* used when si_code=SEGV_PKUERR */ 237 /* used when si_code=SEGV_PKUERR */
237 struct { 238 struct {
238 short _dummy_pkey; 239 compat_uptr_t _dummy_pkey;
239 u32 _pkey; 240 u32 _pkey;
240 } _addr_pkey; 241 } _addr_pkey;
241 }; 242 };
@@ -550,8 +551,29 @@ asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
550asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp); 551asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
551 552
552extern int get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat); 553extern int get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat);
553extern int put_compat_sigset(compat_sigset_t __user *compat, 554
554 const sigset_t *set, unsigned int size); 555/*
556 * Defined inline such that size can be compile time constant, which avoids
557 * CONFIG_HARDENED_USERCOPY complaining about copies from task_struct
558 */
559static inline int
560put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
561 unsigned int size)
562{
563 /* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
564#ifdef __BIG_ENDIAN
565 compat_sigset_t v;
566 switch (_NSIG_WORDS) {
567 case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
568 case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
569 case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
570 case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0];
571 }
572 return copy_to_user(compat, &v, size) ? -EFAULT : 0;
573#else
574 return copy_to_user(compat, set, size) ? -EFAULT : 0;
575#endif
576}
555 577
556asmlinkage long compat_sys_migrate_pages(compat_pid_t pid, 578asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
557 compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes, 579 compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,
diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index d02a4df3f473..d3f264a5b04d 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -27,3 +27,8 @@
27#if __has_feature(address_sanitizer) 27#if __has_feature(address_sanitizer)
28#define __SANITIZE_ADDRESS__ 28#define __SANITIZE_ADDRESS__
29#endif 29#endif
30
31/* Clang doesn't have a way to turn it off per-function, yet. */
32#ifdef __noretpoline
33#undef __noretpoline
34#endif
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 631354acfa72..e2c7f4369eff 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -93,6 +93,10 @@
93#define __weak __attribute__((weak)) 93#define __weak __attribute__((weak))
94#define __alias(symbol) __attribute__((alias(#symbol))) 94#define __alias(symbol) __attribute__((alias(#symbol)))
95 95
96#ifdef RETPOLINE
97#define __noretpoline __attribute__((indirect_branch("keep")))
98#endif
99
96/* 100/*
97 * it doesn't make sense on ARM (currently the only user of __naked) 101 * it doesn't make sense on ARM (currently the only user of __naked)
98 * to trace naked functions because then mcount is called without 102 * to trace naked functions because then mcount is called without
@@ -167,8 +171,6 @@
167 171
168#if GCC_VERSION >= 40100 172#if GCC_VERSION >= 40100
169# define __compiletime_object_size(obj) __builtin_object_size(obj, 0) 173# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
170
171#define __nostackprotector __attribute__((__optimize__("no-stack-protector")))
172#endif 174#endif
173 175
174#if GCC_VERSION >= 40300 176#if GCC_VERSION >= 40300
@@ -196,6 +198,11 @@
196#endif /* __CHECKER__ */ 198#endif /* __CHECKER__ */
197#endif /* GCC_VERSION >= 40300 */ 199#endif /* GCC_VERSION >= 40300 */
198 200
201#if GCC_VERSION >= 40400
202#define __optimize(level) __attribute__((__optimize__(level)))
203#define __nostackprotector __optimize("no-stack-protector")
204#endif /* GCC_VERSION >= 40400 */
205
199#if GCC_VERSION >= 40500 206#if GCC_VERSION >= 40500
200 207
201#ifndef __CHECKER__ 208#ifndef __CHECKER__
@@ -205,6 +212,15 @@
205#endif 212#endif
206 213
207/* 214/*
215 * calling noreturn functions, __builtin_unreachable() and __builtin_trap()
216 * confuse the stack allocation in gcc, leading to overly large stack
217 * frames, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365
218 *
219 * Adding an empty inline assembly before it works around the problem
220 */
221#define barrier_before_unreachable() asm volatile("")
222
223/*
208 * Mark a position in code as unreachable. This can be used to 224 * Mark a position in code as unreachable. This can be used to
209 * suppress control flow warnings after asm blocks that transfer 225 * suppress control flow warnings after asm blocks that transfer
210 * control elsewhere. 226 * control elsewhere.
@@ -214,7 +230,11 @@
214 * unreleased. Really, we need to have autoconf for the kernel. 230 * unreleased. Really, we need to have autoconf for the kernel.
215 */ 231 */
216#define unreachable() \ 232#define unreachable() \
217 do { annotate_unreachable(); __builtin_unreachable(); } while (0) 233 do { \
234 annotate_unreachable(); \
235 barrier_before_unreachable(); \
236 __builtin_unreachable(); \
237 } while (0)
218 238
219/* Mark a function definition as prohibited from being cloned. */ 239/* Mark a function definition as prohibited from being cloned. */
220#define __noclone __attribute__((__noclone__, __optimize__("no-tracer"))) 240#define __noclone __attribute__((__noclone__, __optimize__("no-tracer")))
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index c2cc57a2f508..ab4711c63601 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -86,6 +86,11 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
86# define barrier_data(ptr) barrier() 86# define barrier_data(ptr) barrier()
87#endif 87#endif
88 88
89/* workaround for GCC PR82365 if needed */
90#ifndef barrier_before_unreachable
91# define barrier_before_unreachable() do { } while (0)
92#endif
93
89/* Unreachable code */ 94/* Unreachable code */
90#ifdef CONFIG_STACK_VALIDATION 95#ifdef CONFIG_STACK_VALIDATION
91/* 96/*
@@ -277,6 +282,10 @@ unsigned long read_word_at_a_time(const void *addr)
277 282
278#endif /* __ASSEMBLY__ */ 283#endif /* __ASSEMBLY__ */
279 284
285#ifndef __optimize
286# define __optimize(level)
287#endif
288
280/* Compile time object size, -1 for unknown */ 289/* Compile time object size, -1 for unknown */
281#ifndef __compiletime_object_size 290#ifndef __compiletime_object_size
282# define __compiletime_object_size(obj) -1 291# define __compiletime_object_size(obj) -1
diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
index 871f9e21810c..0b3fc229086c 100644
--- a/include/linux/cpuidle.h
+++ b/include/linux/cpuidle.h
@@ -225,7 +225,7 @@ static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev,
225} 225}
226#endif 226#endif
227 227
228#ifdef CONFIG_ARCH_HAS_CPU_RELAX 228#if defined(CONFIG_CPU_IDLE) && defined(CONFIG_ARCH_HAS_CPU_RELAX)
229void cpuidle_poll_state_init(struct cpuidle_driver *drv); 229void cpuidle_poll_state_init(struct cpuidle_driver *drv);
230#else 230#else
231static inline void cpuidle_poll_state_init(struct cpuidle_driver *drv) {} 231static inline void cpuidle_poll_state_init(struct cpuidle_driver *drv) {}
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index d4a2a7dcd72d..bf53d893ad02 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -170,6 +170,8 @@ static inline unsigned int cpumask_local_spread(unsigned int i, int node)
170 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask) 170 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
171#define for_each_cpu_not(cpu, mask) \ 171#define for_each_cpu_not(cpu, mask) \
172 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask) 172 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
173#define for_each_cpu_wrap(cpu, mask, start) \
174 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)(start))
173#define for_each_cpu_and(cpu, mask, and) \ 175#define for_each_cpu_and(cpu, mask, and) \
174 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and) 176 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and)
175#else 177#else
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 34fe8463d10e..eb9eab4ecd6d 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -578,7 +578,7 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
578 578
579/* 579/*
580 * This is a hack for the legacy x86 forbid_dac and iommu_sac_force. Please 580 * This is a hack for the legacy x86 forbid_dac and iommu_sac_force. Please
581 * don't use this is new code. 581 * don't use this in new code.
582 */ 582 */
583#ifndef arch_dma_supported 583#ifndef arch_dma_supported
584#define arch_dma_supported(dev, mask) (1) 584#define arch_dma_supported(dev, mask) (1)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 2a815560fda0..c6baf767619e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1317,6 +1317,7 @@ extern int send_sigurg(struct fown_struct *fown);
1317#define SB_I_CGROUPWB 0x00000001 /* cgroup-aware writeback enabled */ 1317#define SB_I_CGROUPWB 0x00000001 /* cgroup-aware writeback enabled */
1318#define SB_I_NOEXEC 0x00000002 /* Ignore executables on this fs */ 1318#define SB_I_NOEXEC 0x00000002 /* Ignore executables on this fs */
1319#define SB_I_NODEV 0x00000004 /* Ignore devices on this fs */ 1319#define SB_I_NODEV 0x00000004 /* Ignore devices on this fs */
1320#define SB_I_MULTIROOT 0x00000008 /* Multiple roots to the dentry tree */
1320 1321
1321/* sb->s_iflags to limit user namespace mounts */ 1322/* sb->s_iflags to limit user namespace mounts */
1322#define SB_I_USERNS_VISIBLE 0x00000010 /* fstype already mounted */ 1323#define SB_I_USERNS_VISIBLE 0x00000010 /* fstype already mounted */
@@ -3198,7 +3199,7 @@ static inline bool vma_is_fsdax(struct vm_area_struct *vma)
3198 if (!vma_is_dax(vma)) 3199 if (!vma_is_dax(vma))
3199 return false; 3200 return false;
3200 inode = file_inode(vma->vm_file); 3201 inode = file_inode(vma->vm_file);
3201 if (inode->i_mode == S_IFCHR) 3202 if (S_ISCHR(inode->i_mode))
3202 return false; /* device-dax */ 3203 return false; /* device-dax */
3203 return true; 3204 return true;
3204} 3205}
diff --git a/include/linux/fsl_ifc.h b/include/linux/fsl_ifc.h
index c332f0a45607..3fdfede2f0f3 100644
--- a/include/linux/fsl_ifc.h
+++ b/include/linux/fsl_ifc.h
@@ -734,11 +734,7 @@ struct fsl_ifc_nand {
734 u32 res19[0x10]; 734 u32 res19[0x10];
735 __be32 nand_fsr; 735 __be32 nand_fsr;
736 u32 res20; 736 u32 res20;
737 /* The V1 nand_eccstat is actually 4 words that overlaps the 737 __be32 nand_eccstat[8];
738 * V2 nand_eccstat.
739 */
740 __be32 v1_nand_eccstat[2];
741 __be32 v2_nand_eccstat[6];
742 u32 res21[0x1c]; 738 u32 res21[0x1c];
743 __be32 nanndcr; 739 __be32 nanndcr;
744 u32 res22[0x2]; 740 u32 res22[0x2];
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index 4fa1a489efe4..4fe8f289b3f6 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -73,8 +73,8 @@ struct fwnode_operations {
73 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); 73 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
74 void (*put)(struct fwnode_handle *fwnode); 74 void (*put)(struct fwnode_handle *fwnode);
75 bool (*device_is_available)(const struct fwnode_handle *fwnode); 75 bool (*device_is_available)(const struct fwnode_handle *fwnode);
76 void *(*device_get_match_data)(const struct fwnode_handle *fwnode, 76 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
77 const struct device *dev); 77 const struct device *dev);
78 bool (*property_present)(const struct fwnode_handle *fwnode, 78 bool (*property_present)(const struct fwnode_handle *fwnode,
79 const char *propname); 79 const char *propname);
80 int (*property_read_int_array)(const struct fwnode_handle *fwnode, 80 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 5e3531027b51..c826b0b5232a 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -198,6 +198,7 @@ struct gendisk {
198 void *private_data; 198 void *private_data;
199 199
200 int flags; 200 int flags;
201 struct rw_semaphore lookup_sem;
201 struct kobject *slave_dir; 202 struct kobject *slave_dir;
202 203
203 struct timer_rand_state *random; 204 struct timer_rand_state *random;
@@ -600,8 +601,9 @@ extern void delete_partition(struct gendisk *, int);
600extern void printk_all_partitions(void); 601extern void printk_all_partitions(void);
601 602
602extern struct gendisk *__alloc_disk_node(int minors, int node_id); 603extern struct gendisk *__alloc_disk_node(int minors, int node_id);
603extern struct kobject *get_disk(struct gendisk *disk); 604extern struct kobject *get_disk_and_module(struct gendisk *disk);
604extern void put_disk(struct gendisk *disk); 605extern void put_disk(struct gendisk *disk);
606extern void put_disk_and_module(struct gendisk *disk);
605extern void blk_register_region(dev_t devt, unsigned long range, 607extern void blk_register_region(dev_t devt, unsigned long range,
606 struct module *module, 608 struct module *module,
607 struct kobject *(*probe)(dev_t, int *, void *), 609 struct kobject *(*probe)(dev_t, int *, void *),
diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h
index c5b0a75a7812..fd00170b494f 100644
--- a/include/linux/if_tun.h
+++ b/include/linux/if_tun.h
@@ -25,6 +25,7 @@ struct ptr_ring *tun_get_tx_ring(struct file *file);
25bool tun_is_xdp_buff(void *ptr); 25bool tun_is_xdp_buff(void *ptr);
26void *tun_xdp_to_ptr(void *ptr); 26void *tun_xdp_to_ptr(void *ptr);
27void *tun_ptr_to_xdp(void *ptr); 27void *tun_ptr_to_xdp(void *ptr);
28void tun_ptr_free(void *ptr);
28#else 29#else
29#include <linux/err.h> 30#include <linux/err.h>
30#include <linux/errno.h> 31#include <linux/errno.h>
@@ -50,5 +51,8 @@ static inline void *tun_ptr_to_xdp(void *ptr)
50{ 51{
51 return NULL; 52 return NULL;
52} 53}
54static inline void tun_ptr_free(void *ptr)
55{
56}
53#endif /* CONFIG_TUN */ 57#endif /* CONFIG_TUN */
54#endif /* __IF_TUN_H */ 58#endif /* __IF_TUN_H */
diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h
index 5e6a2d4dc366..c4a1cff9c768 100644
--- a/include/linux/if_vlan.h
+++ b/include/linux/if_vlan.h
@@ -300,30 +300,34 @@ static inline bool vlan_hw_offload_capable(netdev_features_t features,
300} 300}
301 301
302/** 302/**
303 * __vlan_insert_tag - regular VLAN tag inserting 303 * __vlan_insert_inner_tag - inner VLAN tag inserting
304 * @skb: skbuff to tag 304 * @skb: skbuff to tag
305 * @vlan_proto: VLAN encapsulation protocol 305 * @vlan_proto: VLAN encapsulation protocol
306 * @vlan_tci: VLAN TCI to insert 306 * @vlan_tci: VLAN TCI to insert
307 * @mac_len: MAC header length including outer vlan headers
307 * 308 *
308 * Inserts the VLAN tag into @skb as part of the payload 309 * Inserts the VLAN tag into @skb as part of the payload at offset mac_len
309 * Returns error if skb_cow_head failes. 310 * Returns error if skb_cow_head failes.
310 * 311 *
311 * Does not change skb->protocol so this function can be used during receive. 312 * Does not change skb->protocol so this function can be used during receive.
312 */ 313 */
313static inline int __vlan_insert_tag(struct sk_buff *skb, 314static inline int __vlan_insert_inner_tag(struct sk_buff *skb,
314 __be16 vlan_proto, u16 vlan_tci) 315 __be16 vlan_proto, u16 vlan_tci,
316 unsigned int mac_len)
315{ 317{
316 struct vlan_ethhdr *veth; 318 struct vlan_ethhdr *veth;
317 319
318 if (skb_cow_head(skb, VLAN_HLEN) < 0) 320 if (skb_cow_head(skb, VLAN_HLEN) < 0)
319 return -ENOMEM; 321 return -ENOMEM;
320 322
321 veth = skb_push(skb, VLAN_HLEN); 323 skb_push(skb, VLAN_HLEN);
322 324
323 /* Move the mac addresses to the beginning of the new header. */ 325 /* Move the mac header sans proto to the beginning of the new header. */
324 memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN); 326 memmove(skb->data, skb->data + VLAN_HLEN, mac_len - ETH_TLEN);
325 skb->mac_header -= VLAN_HLEN; 327 skb->mac_header -= VLAN_HLEN;
326 328
329 veth = (struct vlan_ethhdr *)(skb->data + mac_len - ETH_HLEN);
330
327 /* first, the ethernet type */ 331 /* first, the ethernet type */
328 veth->h_vlan_proto = vlan_proto; 332 veth->h_vlan_proto = vlan_proto;
329 333
@@ -334,12 +338,30 @@ static inline int __vlan_insert_tag(struct sk_buff *skb,
334} 338}
335 339
336/** 340/**
337 * vlan_insert_tag - regular VLAN tag inserting 341 * __vlan_insert_tag - regular VLAN tag inserting
338 * @skb: skbuff to tag 342 * @skb: skbuff to tag
339 * @vlan_proto: VLAN encapsulation protocol 343 * @vlan_proto: VLAN encapsulation protocol
340 * @vlan_tci: VLAN TCI to insert 344 * @vlan_tci: VLAN TCI to insert
341 * 345 *
342 * Inserts the VLAN tag into @skb as part of the payload 346 * Inserts the VLAN tag into @skb as part of the payload
347 * Returns error if skb_cow_head failes.
348 *
349 * Does not change skb->protocol so this function can be used during receive.
350 */
351static inline int __vlan_insert_tag(struct sk_buff *skb,
352 __be16 vlan_proto, u16 vlan_tci)
353{
354 return __vlan_insert_inner_tag(skb, vlan_proto, vlan_tci, ETH_HLEN);
355}
356
357/**
358 * vlan_insert_inner_tag - inner VLAN tag inserting
359 * @skb: skbuff to tag
360 * @vlan_proto: VLAN encapsulation protocol
361 * @vlan_tci: VLAN TCI to insert
362 * @mac_len: MAC header length including outer vlan headers
363 *
364 * Inserts the VLAN tag into @skb as part of the payload at offset mac_len
343 * Returns a VLAN tagged skb. If a new skb is created, @skb is freed. 365 * Returns a VLAN tagged skb. If a new skb is created, @skb is freed.
344 * 366 *
345 * Following the skb_unshare() example, in case of error, the calling function 367 * Following the skb_unshare() example, in case of error, the calling function
@@ -347,12 +369,14 @@ static inline int __vlan_insert_tag(struct sk_buff *skb,
347 * 369 *
348 * Does not change skb->protocol so this function can be used during receive. 370 * Does not change skb->protocol so this function can be used during receive.
349 */ 371 */
350static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb, 372static inline struct sk_buff *vlan_insert_inner_tag(struct sk_buff *skb,
351 __be16 vlan_proto, u16 vlan_tci) 373 __be16 vlan_proto,
374 u16 vlan_tci,
375 unsigned int mac_len)
352{ 376{
353 int err; 377 int err;
354 378
355 err = __vlan_insert_tag(skb, vlan_proto, vlan_tci); 379 err = __vlan_insert_inner_tag(skb, vlan_proto, vlan_tci, mac_len);
356 if (err) { 380 if (err) {
357 dev_kfree_skb_any(skb); 381 dev_kfree_skb_any(skb);
358 return NULL; 382 return NULL;
@@ -361,6 +385,26 @@ static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb,
361} 385}
362 386
363/** 387/**
388 * vlan_insert_tag - regular VLAN tag inserting
389 * @skb: skbuff to tag
390 * @vlan_proto: VLAN encapsulation protocol
391 * @vlan_tci: VLAN TCI to insert
392 *
393 * Inserts the VLAN tag into @skb as part of the payload
394 * Returns a VLAN tagged skb. If a new skb is created, @skb is freed.
395 *
396 * Following the skb_unshare() example, in case of error, the calling function
397 * doesn't have to worry about freeing the original skb.
398 *
399 * Does not change skb->protocol so this function can be used during receive.
400 */
401static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb,
402 __be16 vlan_proto, u16 vlan_tci)
403{
404 return vlan_insert_inner_tag(skb, vlan_proto, vlan_tci, ETH_HLEN);
405}
406
407/**
364 * vlan_insert_tag_set_proto - regular VLAN tag inserting 408 * vlan_insert_tag_set_proto - regular VLAN tag inserting
365 * @skb: skbuff to tag 409 * @skb: skbuff to tag
366 * @vlan_proto: VLAN encapsulation protocol 410 * @vlan_proto: VLAN encapsulation protocol
diff --git a/include/linux/init.h b/include/linux/init.h
index 506a98151131..bc27cf03c41e 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -6,10 +6,10 @@
6#include <linux/types.h> 6#include <linux/types.h>
7 7
8/* Built-in __init functions needn't be compiled with retpoline */ 8/* Built-in __init functions needn't be compiled with retpoline */
9#if defined(RETPOLINE) && !defined(MODULE) 9#if defined(__noretpoline) && !defined(MODULE)
10#define __noretpoline __attribute__((indirect_branch("keep"))) 10#define __noinitretpoline __noretpoline
11#else 11#else
12#define __noretpoline 12#define __noinitretpoline
13#endif 13#endif
14 14
15/* These macros are used to mark some functions or 15/* These macros are used to mark some functions or
@@ -47,7 +47,7 @@
47 47
48/* These are for everybody (although not all archs will actually 48/* These are for everybody (although not all archs will actually
49 discard it in modules) */ 49 discard it in modules) */
50#define __init __section(.init.text) __cold __latent_entropy __noretpoline 50#define __init __section(.init.text) __cold __latent_entropy __noinitretpoline
51#define __initdata __section(.init.data) 51#define __initdata __section(.init.data)
52#define __initconst __section(.init.rodata) 52#define __initconst __section(.init.rodata)
53#define __exitdata __section(.exit.data) 53#define __exitdata __section(.exit.data)
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
index c00c4c33e432..b26eccc78fb1 100644
--- a/include/linux/irqchip/arm-gic-v3.h
+++ b/include/linux/irqchip/arm-gic-v3.h
@@ -503,6 +503,7 @@
503 503
504#define ICH_HCR_EN (1 << 0) 504#define ICH_HCR_EN (1 << 0)
505#define ICH_HCR_UIE (1 << 1) 505#define ICH_HCR_UIE (1 << 1)
506#define ICH_HCR_NPIE (1 << 3)
506#define ICH_HCR_TC (1 << 10) 507#define ICH_HCR_TC (1 << 10)
507#define ICH_HCR_TALL0 (1 << 11) 508#define ICH_HCR_TALL0 (1 << 11)
508#define ICH_HCR_TALL1 (1 << 12) 509#define ICH_HCR_TALL1 (1 << 12)
diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
index d3453ee072fc..68d8b1f73682 100644
--- a/include/linux/irqchip/arm-gic.h
+++ b/include/linux/irqchip/arm-gic.h
@@ -84,6 +84,7 @@
84 84
85#define GICH_HCR_EN (1 << 0) 85#define GICH_HCR_EN (1 << 0)
86#define GICH_HCR_UIE (1 << 1) 86#define GICH_HCR_UIE (1 << 1)
87#define GICH_HCR_NPIE (1 << 3)
87 88
88#define GICH_LR_VIRTUALID (0x3ff << 0) 89#define GICH_LR_VIRTUALID (0x3ff << 0)
89#define GICH_LR_PHYSID_CPUID_SHIFT (10) 90#define GICH_LR_PHYSID_CPUID_SHIFT (10)
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index b6a29c126cc4..b46b541c67c4 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -151,6 +151,7 @@ extern struct jump_entry __start___jump_table[];
151extern struct jump_entry __stop___jump_table[]; 151extern struct jump_entry __stop___jump_table[];
152 152
153extern void jump_label_init(void); 153extern void jump_label_init(void);
154extern void jump_label_invalidate_initmem(void);
154extern void jump_label_lock(void); 155extern void jump_label_lock(void);
155extern void jump_label_unlock(void); 156extern void jump_label_unlock(void);
156extern void arch_jump_label_transform(struct jump_entry *entry, 157extern void arch_jump_label_transform(struct jump_entry *entry,
@@ -198,6 +199,8 @@ static __always_inline void jump_label_init(void)
198 static_key_initialized = true; 199 static_key_initialized = true;
199} 200}
200 201
202static inline void jump_label_invalidate_initmem(void) {}
203
201static __always_inline bool static_key_false(struct static_key *key) 204static __always_inline bool static_key_false(struct static_key *key)
202{ 205{
203 if (unlikely(static_key_count(key) > 0)) 206 if (unlikely(static_key_count(key) > 0))
diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index fec5076eda91..dcde9471897d 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -4,6 +4,12 @@
4 4
5#include <generated/autoconf.h> 5#include <generated/autoconf.h>
6 6
7#ifdef CONFIG_CPU_BIG_ENDIAN
8#define __BIG_ENDIAN 4321
9#else
10#define __LITTLE_ENDIAN 1234
11#endif
12
7#define __ARG_PLACEHOLDER_1 0, 13#define __ARG_PLACEHOLDER_1 0,
8#define __take_second_arg(__ignored, val, ...) val 14#define __take_second_arg(__ignored, val, ...) val
9 15
@@ -64,4 +70,7 @@
64 */ 70 */
65#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option)) 71#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
66 72
73/* Make sure we always have all types and struct attributes defined. */
74#include <linux/compiler_types.h>
75
67#endif /* __LINUX_KCONFIG_H */ 76#endif /* __LINUX_KCONFIG_H */
diff --git a/include/linux/kcore.h b/include/linux/kcore.h
index 7ff25a808fef..80db19d3a505 100644
--- a/include/linux/kcore.h
+++ b/include/linux/kcore.h
@@ -10,6 +10,7 @@ enum kcore_type {
10 KCORE_VMALLOC, 10 KCORE_VMALLOC,
11 KCORE_RAM, 11 KCORE_RAM,
12 KCORE_VMEMMAP, 12 KCORE_VMEMMAP,
13 KCORE_USER,
13 KCORE_OTHER, 14 KCORE_OTHER,
14}; 15};
15 16
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index ce51455e2adf..3fd291503576 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -472,6 +472,7 @@ extern bool parse_option_str(const char *str, const char *option);
472extern char *next_arg(char *args, char **param, char **val); 472extern char *next_arg(char *args, char **param, char **val);
473 473
474extern int core_kernel_text(unsigned long addr); 474extern int core_kernel_text(unsigned long addr);
475extern int init_kernel_text(unsigned long addr);
475extern int core_kernel_data(unsigned long addr); 476extern int core_kernel_data(unsigned long addr);
476extern int __kernel_text_address(unsigned long addr); 477extern int __kernel_text_address(unsigned long addr);
477extern int kernel_text_address(unsigned long addr); 478extern int kernel_text_address(unsigned long addr);
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ac0062b74aed..6930c63126c7 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1105,7 +1105,6 @@ static inline void kvm_irq_routing_update(struct kvm *kvm)
1105{ 1105{
1106} 1106}
1107#endif 1107#endif
1108void kvm_arch_irq_routing_update(struct kvm *kvm);
1109 1108
1110static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) 1109static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
1111{ 1110{
@@ -1114,6 +1113,8 @@ static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
1114 1113
1115#endif /* CONFIG_HAVE_KVM_EVENTFD */ 1114#endif /* CONFIG_HAVE_KVM_EVENTFD */
1116 1115
1116void kvm_arch_irq_routing_update(struct kvm *kvm);
1117
1117static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu) 1118static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)
1118{ 1119{
1119 /* 1120 /*
@@ -1272,4 +1273,7 @@ static inline long kvm_arch_vcpu_async_ioctl(struct file *filp,
1272} 1273}
1273#endif /* CONFIG_HAVE_KVM_VCPU_ASYNC_IOCTL */ 1274#endif /* CONFIG_HAVE_KVM_VCPU_ASYNC_IOCTL */
1274 1275
1276void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
1277 unsigned long start, unsigned long end);
1278
1275#endif 1279#endif
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 8be5077efb5f..f92ea7783652 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -187,7 +187,6 @@ int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn,
187 unsigned long *end_pfn); 187 unsigned long *end_pfn);
188void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, 188void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
189 unsigned long *out_end_pfn, int *out_nid); 189 unsigned long *out_end_pfn, int *out_nid);
190unsigned long memblock_next_valid_pfn(unsigned long pfn, unsigned long max_pfn);
191 190
192/** 191/**
193 * for_each_mem_pfn_range - early memory pfn range iterator 192 * for_each_mem_pfn_range - early memory pfn range iterator
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 882046863581..c46016bb25eb 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -523,9 +523,11 @@ static inline void __mod_memcg_state(struct mem_cgroup *memcg,
523static inline void mod_memcg_state(struct mem_cgroup *memcg, 523static inline void mod_memcg_state(struct mem_cgroup *memcg,
524 int idx, int val) 524 int idx, int val)
525{ 525{
526 preempt_disable(); 526 unsigned long flags;
527
528 local_irq_save(flags);
527 __mod_memcg_state(memcg, idx, val); 529 __mod_memcg_state(memcg, idx, val);
528 preempt_enable(); 530 local_irq_restore(flags);
529} 531}
530 532
531/** 533/**
@@ -606,9 +608,11 @@ static inline void __mod_lruvec_state(struct lruvec *lruvec,
606static inline void mod_lruvec_state(struct lruvec *lruvec, 608static inline void mod_lruvec_state(struct lruvec *lruvec,
607 enum node_stat_item idx, int val) 609 enum node_stat_item idx, int val)
608{ 610{
609 preempt_disable(); 611 unsigned long flags;
612
613 local_irq_save(flags);
610 __mod_lruvec_state(lruvec, idx, val); 614 __mod_lruvec_state(lruvec, idx, val);
611 preempt_enable(); 615 local_irq_restore(flags);
612} 616}
613 617
614static inline void __mod_lruvec_page_state(struct page *page, 618static inline void __mod_lruvec_page_state(struct page *page,
@@ -630,9 +634,11 @@ static inline void __mod_lruvec_page_state(struct page *page,
630static inline void mod_lruvec_page_state(struct page *page, 634static inline void mod_lruvec_page_state(struct page *page,
631 enum node_stat_item idx, int val) 635 enum node_stat_item idx, int val)
632{ 636{
633 preempt_disable(); 637 unsigned long flags;
638
639 local_irq_save(flags);
634 __mod_lruvec_page_state(page, idx, val); 640 __mod_lruvec_page_state(page, idx, val);
635 preempt_enable(); 641 local_irq_restore(flags);
636} 642}
637 643
638unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, 644unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
@@ -659,9 +665,11 @@ static inline void __count_memcg_events(struct mem_cgroup *memcg,
659static inline void count_memcg_events(struct mem_cgroup *memcg, 665static inline void count_memcg_events(struct mem_cgroup *memcg,
660 int idx, unsigned long count) 666 int idx, unsigned long count)
661{ 667{
662 preempt_disable(); 668 unsigned long flags;
669
670 local_irq_save(flags);
663 __count_memcg_events(memcg, idx, count); 671 __count_memcg_events(memcg, idx, count);
664 preempt_enable(); 672 local_irq_restore(flags);
665} 673}
666 674
667/* idx can be of type enum memcg_event_item or vm_event_item */ 675/* idx can be of type enum memcg_event_item or vm_event_item */
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 6ed79a8a8318..9d3a03364e6e 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -453,8 +453,8 @@ struct mlx5_core_srq {
453 struct mlx5_core_rsc_common common; /* must be first */ 453 struct mlx5_core_rsc_common common; /* must be first */
454 u32 srqn; 454 u32 srqn;
455 int max; 455 int max;
456 int max_gs; 456 size_t max_gs;
457 int max_avail_gather; 457 size_t max_avail_gather;
458 int wqe_shift; 458 int wqe_shift;
459 void (*event) (struct mlx5_core_srq *, enum mlx5_event); 459 void (*event) (struct mlx5_core_srq *, enum mlx5_event);
460 460
diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
index c30b32e3c862..10191c28fc04 100644
--- a/include/linux/mm_inline.h
+++ b/include/linux/mm_inline.h
@@ -127,10 +127,4 @@ static __always_inline enum lru_list page_lru(struct page *page)
127 127
128#define lru_to_page(head) (list_entry((head)->prev, struct page, lru)) 128#define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
129 129
130#ifdef arch_unmap_kpfn
131extern void arch_unmap_kpfn(unsigned long pfn);
132#else
133static __always_inline void arch_unmap_kpfn(unsigned long pfn) { }
134#endif
135
136#endif 130#endif
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index f25c13423bd4..cb3bbed4e633 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -66,6 +66,11 @@ struct mutex {
66#endif 66#endif
67}; 67};
68 68
69/*
70 * Internal helper function; C doesn't allow us to hide it :/
71 *
72 * DO NOT USE (outside of mutex code).
73 */
69static inline struct task_struct *__mutex_owner(struct mutex *lock) 74static inline struct task_struct *__mutex_owner(struct mutex *lock)
70{ 75{
71 return (struct task_struct *)(atomic_long_read(&lock->owner) & ~0x07); 76 return (struct task_struct *)(atomic_long_read(&lock->owner) & ~0x07);
diff --git a/include/linux/net.h b/include/linux/net.h
index 91216b16feb7..2a0391eea05c 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -222,6 +222,7 @@ enum {
222int sock_wake_async(struct socket_wq *sk_wq, int how, int band); 222int sock_wake_async(struct socket_wq *sk_wq, int how, int band);
223int sock_register(const struct net_proto_family *fam); 223int sock_register(const struct net_proto_family *fam);
224void sock_unregister(int family); 224void sock_unregister(int family);
225bool sock_is_registered(int family);
225int __sock_create(struct net *net, int family, int type, int proto, 226int __sock_create(struct net *net, int family, int type, int proto,
226 struct socket **res, int kern); 227 struct socket **res, int kern);
227int sock_create(int family, int type, int proto, struct socket **res); 228int sock_create(int family, int type, int proto, struct socket **res);
diff --git a/include/linux/netfilter/x_tables.h b/include/linux/netfilter/x_tables.h
index 1313b35c3ab7..14529511c4b8 100644
--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -285,6 +285,8 @@ unsigned int *xt_alloc_entry_offsets(unsigned int size);
285bool xt_find_jump_offset(const unsigned int *offsets, 285bool xt_find_jump_offset(const unsigned int *offsets,
286 unsigned int target, unsigned int size); 286 unsigned int target, unsigned int size);
287 287
288int xt_check_proc_name(const char *name, unsigned int size);
289
288int xt_check_match(struct xt_mtchk_param *, unsigned int size, u_int8_t proto, 290int xt_check_match(struct xt_mtchk_param *, unsigned int size, u_int8_t proto,
289 bool inv_proto); 291 bool inv_proto);
290int xt_check_target(struct xt_tgchk_param *, unsigned int size, u_int8_t proto, 292int xt_check_target(struct xt_tgchk_param *, unsigned int size, u_int8_t proto,
diff --git a/include/linux/nospec.h b/include/linux/nospec.h
index b99bced39ac2..e791ebc65c9c 100644
--- a/include/linux/nospec.h
+++ b/include/linux/nospec.h
@@ -5,6 +5,7 @@
5 5
6#ifndef _LINUX_NOSPEC_H 6#ifndef _LINUX_NOSPEC_H
7#define _LINUX_NOSPEC_H 7#define _LINUX_NOSPEC_H
8#include <asm/barrier.h>
8 9
9/** 10/**
10 * array_index_mask_nospec() - generate a ~0 mask when index < size, 0 otherwise 11 * array_index_mask_nospec() - generate a ~0 mask when index < size, 0 otherwise
@@ -20,20 +21,6 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,
20 unsigned long size) 21 unsigned long size)
21{ 22{
22 /* 23 /*
23 * Warn developers about inappropriate array_index_nospec() usage.
24 *
25 * Even if the CPU speculates past the WARN_ONCE branch, the
26 * sign bit of @index is taken into account when generating the
27 * mask.
28 *
29 * This warning is compiled out when the compiler can infer that
30 * @index and @size are less than LONG_MAX.
31 */
32 if (WARN_ONCE(index > LONG_MAX || size > LONG_MAX,
33 "array_index_nospec() limited to range of [0, LONG_MAX]\n"))
34 return 0;
35
36 /*
37 * Always calculate and emit the mask even if the compiler 24 * Always calculate and emit the mask even if the compiler
38 * thinks the mask is not needed. The compiler does not take 25 * thinks the mask is not needed. The compiler does not take
39 * into account the value of @index under speculation. 26 * into account the value of @index under speculation.
@@ -66,7 +53,6 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,
66 BUILD_BUG_ON(sizeof(_i) > sizeof(long)); \ 53 BUILD_BUG_ON(sizeof(_i) > sizeof(long)); \
67 BUILD_BUG_ON(sizeof(_s) > sizeof(long)); \ 54 BUILD_BUG_ON(sizeof(_s) > sizeof(long)); \
68 \ 55 \
69 _i &= _mask; \ 56 (typeof(_i)) (_i & _mask); \
70 _i; \
71}) 57})
72#endif /* _LINUX_NOSPEC_H */ 58#endif /* _LINUX_NOSPEC_H */
diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h
index 88865e0ebf4d..091033a6b836 100644
--- a/include/linux/of_pci.h
+++ b/include/linux/of_pci.h
@@ -13,7 +13,6 @@ struct device_node;
13struct device_node *of_pci_find_child_device(struct device_node *parent, 13struct device_node *of_pci_find_child_device(struct device_node *parent,
14 unsigned int devfn); 14 unsigned int devfn);
15int of_pci_get_devfn(struct device_node *np); 15int of_pci_get_devfn(struct device_node *np);
16int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin);
17int of_pci_parse_bus_range(struct device_node *node, struct resource *res); 16int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
18int of_get_pci_domain_nr(struct device_node *node); 17int of_get_pci_domain_nr(struct device_node *node);
19int of_pci_get_max_link_speed(struct device_node *node); 18int of_pci_get_max_link_speed(struct device_node *node);
@@ -34,12 +33,6 @@ static inline int of_pci_get_devfn(struct device_node *np)
34} 33}
35 34
36static inline int 35static inline int
37of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
38{
39 return 0;
40}
41
42static inline int
43of_pci_parse_bus_range(struct device_node *node, struct resource *res) 36of_pci_parse_bus_range(struct device_node *node, struct resource *res)
44{ 37{
45 return -EINVAL; 38 return -EINVAL;
@@ -67,6 +60,16 @@ of_pci_get_max_link_speed(struct device_node *node)
67static inline void of_pci_check_probe_only(void) { } 60static inline void of_pci_check_probe_only(void) { }
68#endif 61#endif
69 62
63#if IS_ENABLED(CONFIG_OF_IRQ)
64int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin);
65#else
66static inline int
67of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
68{
69 return 0;
70}
71#endif
72
70#if defined(CONFIG_OF_ADDRESS) 73#if defined(CONFIG_OF_ADDRESS)
71int of_pci_get_host_bridge_resources(struct device_node *dev, 74int of_pci_get_host_bridge_resources(struct device_node *dev,
72 unsigned char busno, unsigned char bus_max, 75 unsigned char busno, unsigned char bus_max,
diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index 864d167a1073..009cdf3d65b6 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -30,10 +30,14 @@
30 * calls io_destroy() or the process exits. 30 * calls io_destroy() or the process exits.
31 * 31 *
32 * In the aio code, kill_ioctx() is called when we wish to destroy a kioctx; it 32 * In the aio code, kill_ioctx() is called when we wish to destroy a kioctx; it
33 * calls percpu_ref_kill(), then hlist_del_rcu() and synchronize_rcu() to remove 33 * removes the kioctx from the proccess's table of kioctxs and kills percpu_ref.
34 * the kioctx from the proccess's list of kioctxs - after that, there can't be 34 * After that, there can't be any new users of the kioctx (from lookup_ioctx())
35 * any new users of the kioctx (from lookup_ioctx()) and it's then safe to drop 35 * and it's then safe to drop the initial ref with percpu_ref_put().
36 * the initial ref with percpu_ref_put(). 36 *
37 * Note that the free path, free_ioctx(), needs to go through explicit call_rcu()
38 * to synchronize with RCU protected lookup_ioctx(). percpu_ref operations don't
39 * imply RCU grace periods of any kind and if a user wants to combine percpu_ref
40 * with RCU protection, it must be done explicitly.
37 * 41 *
38 * Code that does a two stage shutdown like this often needs some kind of 42 * Code that does a two stage shutdown like this often needs some kind of
39 * explicit synchronization to ensure the initial refcount can only be dropped 43 * explicit synchronization to ensure the initial refcount can only be dropped
@@ -113,8 +117,10 @@ void percpu_ref_reinit(struct percpu_ref *ref);
113 * Must be used to drop the initial ref on a percpu refcount; must be called 117 * Must be used to drop the initial ref on a percpu refcount; must be called
114 * precisely once before shutdown. 118 * precisely once before shutdown.
115 * 119 *
116 * Puts @ref in non percpu mode, then does a call_rcu() before gathering up the 120 * Switches @ref into atomic mode before gathering up the percpu counters
117 * percpu counters and dropping the initial ref. 121 * and dropping the initial ref.
122 *
123 * There are no implied RCU grace periods between kill and release.
118 */ 124 */
119static inline void percpu_ref_kill(struct percpu_ref *ref) 125static inline void percpu_ref_kill(struct percpu_ref *ref)
120{ 126{
diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
index af0f44effd44..40036a57d072 100644
--- a/include/linux/perf/arm_pmu.h
+++ b/include/linux/perf/arm_pmu.h
@@ -14,26 +14,10 @@
14 14
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/perf_event.h> 16#include <linux/perf_event.h>
17#include <linux/platform_device.h>
17#include <linux/sysfs.h> 18#include <linux/sysfs.h>
18#include <asm/cputype.h> 19#include <asm/cputype.h>
19 20
20/*
21 * struct arm_pmu_platdata - ARM PMU platform data
22 *
23 * @handle_irq: an optional handler which will be called from the
24 * interrupt and passed the address of the low level handler,
25 * and can be used to implement any platform specific handling
26 * before or after calling it.
27 *
28 * @irq_flags: if non-zero, these flags will be passed to request_irq
29 * when requesting interrupts for this PMU device.
30 */
31struct arm_pmu_platdata {
32 irqreturn_t (*handle_irq)(int irq, void *dev,
33 irq_handler_t pmu_handler);
34 unsigned long irq_flags;
35};
36
37#ifdef CONFIG_ARM_PMU 21#ifdef CONFIG_ARM_PMU
38 22
39/* 23/*
@@ -92,7 +76,6 @@ enum armpmu_attr_groups {
92 76
93struct arm_pmu { 77struct arm_pmu {
94 struct pmu pmu; 78 struct pmu pmu;
95 cpumask_t active_irqs;
96 cpumask_t supported_cpus; 79 cpumask_t supported_cpus;
97 char *name; 80 char *name;
98 irqreturn_t (*handle_irq)(int irq_num, void *dev); 81 irqreturn_t (*handle_irq)(int irq_num, void *dev);
@@ -174,12 +157,11 @@ static inline int arm_pmu_acpi_probe(armpmu_init_fn init_fn) { return 0; }
174 157
175/* Internal functions only for core arm_pmu code */ 158/* Internal functions only for core arm_pmu code */
176struct arm_pmu *armpmu_alloc(void); 159struct arm_pmu *armpmu_alloc(void);
160struct arm_pmu *armpmu_alloc_atomic(void);
177void armpmu_free(struct arm_pmu *pmu); 161void armpmu_free(struct arm_pmu *pmu);
178int armpmu_register(struct arm_pmu *pmu); 162int armpmu_register(struct arm_pmu *pmu);
179int armpmu_request_irqs(struct arm_pmu *armpmu); 163int armpmu_request_irq(int irq, int cpu);
180void armpmu_free_irqs(struct arm_pmu *armpmu); 164void armpmu_free_irq(int irq, int cpu);
181int armpmu_request_irq(struct arm_pmu *armpmu, int cpu);
182void armpmu_free_irq(struct arm_pmu *armpmu, int cpu);
183 165
184#define ARMV8_PMU_PDEV_NAME "armv8-pmu" 166#define ARMV8_PMU_PDEV_NAME "armv8-pmu"
185 167
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 5a0c3e53e7c2..7c4c2379e010 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -924,6 +924,7 @@ void phy_device_remove(struct phy_device *phydev);
924int phy_init_hw(struct phy_device *phydev); 924int phy_init_hw(struct phy_device *phydev);
925int phy_suspend(struct phy_device *phydev); 925int phy_suspend(struct phy_device *phydev);
926int phy_resume(struct phy_device *phydev); 926int phy_resume(struct phy_device *phydev);
927int __phy_resume(struct phy_device *phydev);
927int phy_loopback(struct phy_device *phydev, bool enable); 928int phy_loopback(struct phy_device *phydev, bool enable);
928struct phy_device *phy_attach(struct net_device *dev, const char *bus_id, 929struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
929 phy_interface_t interface); 930 phy_interface_t interface);
@@ -983,6 +984,10 @@ static inline int genphy_no_soft_reset(struct phy_device *phydev)
983{ 984{
984 return 0; 985 return 0;
985} 986}
987int genphy_read_mmd_unsupported(struct phy_device *phdev, int devad,
988 u16 regnum);
989int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum,
990 u16 regnum, u16 val);
986 991
987/* Clause 45 PHY */ 992/* Clause 45 PHY */
988int genphy_c45_restart_aneg(struct phy_device *phydev); 993int genphy_c45_restart_aneg(struct phy_device *phydev);
@@ -1011,7 +1016,6 @@ int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
1011int phy_drivers_register(struct phy_driver *new_driver, int n, 1016int phy_drivers_register(struct phy_driver *new_driver, int n,
1012 struct module *owner); 1017 struct module *owner);
1013void phy_state_machine(struct work_struct *work); 1018void phy_state_machine(struct work_struct *work);
1014void phy_change(struct phy_device *phydev);
1015void phy_change_work(struct work_struct *work); 1019void phy_change_work(struct work_struct *work);
1016void phy_mac_interrupt(struct phy_device *phydev); 1020void phy_mac_interrupt(struct phy_device *phydev);
1017void phy_start_machine(struct phy_device *phydev); 1021void phy_start_machine(struct phy_device *phydev);
diff --git a/include/linux/property.h b/include/linux/property.h
index 769d372c1edf..2eea4b310fc2 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -283,7 +283,7 @@ bool device_dma_supported(struct device *dev);
283 283
284enum dev_dma_attr device_get_dma_attr(struct device *dev); 284enum dev_dma_attr device_get_dma_attr(struct device *dev);
285 285
286void *device_get_match_data(struct device *dev); 286const void *device_get_match_data(struct device *dev);
287 287
288int device_get_phy_mode(struct device *dev); 288int device_get_phy_mode(struct device *dev);
289 289
diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
index b884b7794187..e6335227b844 100644
--- a/include/linux/ptr_ring.h
+++ b/include/linux/ptr_ring.h
@@ -469,7 +469,7 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,
469 */ 469 */
470static inline void **__ptr_ring_init_queue_alloc(unsigned int size, gfp_t gfp) 470static inline void **__ptr_ring_init_queue_alloc(unsigned int size, gfp_t gfp)
471{ 471{
472 if (size * sizeof(void *) > KMALLOC_MAX_SIZE) 472 if (size > KMALLOC_MAX_SIZE / sizeof(void *))
473 return NULL; 473 return NULL;
474 return kvmalloc_array(size, sizeof(void *), gfp | __GFP_ZERO); 474 return kvmalloc_array(size, sizeof(void *), gfp | __GFP_ZERO);
475} 475}
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index c9df2527e0cd..668a21f04b09 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -766,8 +766,10 @@ slow_path:
766 if (!key || 766 if (!key ||
767 (params.obj_cmpfn ? 767 (params.obj_cmpfn ?
768 params.obj_cmpfn(&arg, rht_obj(ht, head)) : 768 params.obj_cmpfn(&arg, rht_obj(ht, head)) :
769 rhashtable_compare(&arg, rht_obj(ht, head)))) 769 rhashtable_compare(&arg, rht_obj(ht, head)))) {
770 pprev = &head->next;
770 continue; 771 continue;
772 }
771 773
772 data = rht_obj(ht, head); 774 data = rht_obj(ht, head);
773 775
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index 1149533aa2fa..9806184bb3d5 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -36,7 +36,18 @@ static inline void mmgrab(struct mm_struct *mm)
36 atomic_inc(&mm->mm_count); 36 atomic_inc(&mm->mm_count);
37} 37}
38 38
39extern void mmdrop(struct mm_struct *mm); 39extern void __mmdrop(struct mm_struct *mm);
40
41static inline void mmdrop(struct mm_struct *mm)
42{
43 /*
44 * The implicit full barrier implied by atomic_dec_and_test() is
45 * required by the membarrier system call before returning to
46 * user-space, after storing to rq->curr.
47 */
48 if (unlikely(atomic_dec_and_test(&mm->mm_count)))
49 __mmdrop(mm);
50}
40 51
41/** 52/**
42 * mmget() - Pin the address space associated with a &struct mm_struct. 53 * mmget() - Pin the address space associated with a &struct mm_struct.
diff --git a/include/linux/sched/user.h b/include/linux/sched/user.h
index 0dcf4e480ef7..96fe289c4c6e 100644
--- a/include/linux/sched/user.h
+++ b/include/linux/sched/user.h
@@ -4,6 +4,7 @@
4 4
5#include <linux/uidgid.h> 5#include <linux/uidgid.h>
6#include <linux/atomic.h> 6#include <linux/atomic.h>
7#include <linux/ratelimit.h>
7 8
8struct key; 9struct key;
9 10
@@ -41,6 +42,9 @@ struct user_struct {
41 defined(CONFIG_NET) 42 defined(CONFIG_NET)
42 atomic_long_t locked_vm; 43 atomic_long_t locked_vm;
43#endif 44#endif
45
46 /* Miscellaneous per-user rate limit */
47 struct ratelimit_state ratelimit;
44}; 48};
45 49
46extern int uids_sysfs_init(void); 50extern int uids_sysfs_init(void);
diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
index dc368b8ce215..11c86fbfeb98 100644
--- a/include/linux/semaphore.h
+++ b/include/linux/semaphore.h
@@ -4,7 +4,7 @@
4 * 4 *
5 * Distributed under the terms of the GNU GPL, version 2 5 * Distributed under the terms of the GNU GPL, version 2
6 * 6 *
7 * Please see kernel/semaphore.c for documentation of these functions 7 * Please see kernel/locking/semaphore.c for documentation of these functions
8 */ 8 */
9#ifndef __LINUX_SEMAPHORE_H 9#ifndef __LINUX_SEMAPHORE_H
10#define __LINUX_SEMAPHORE_H 10#define __LINUX_SEMAPHORE_H
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 5ebc0f869720..99df17109e1b 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3285,8 +3285,7 @@ int skb_zerocopy(struct sk_buff *to, struct sk_buff *from,
3285void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len); 3285void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len);
3286int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen); 3286int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen);
3287void skb_scrub_packet(struct sk_buff *skb, bool xnet); 3287void skb_scrub_packet(struct sk_buff *skb, bool xnet);
3288unsigned int skb_gso_transport_seglen(const struct sk_buff *skb); 3288bool skb_gso_validate_network_len(const struct sk_buff *skb, unsigned int mtu);
3289bool skb_gso_validate_mtu(const struct sk_buff *skb, unsigned int mtu);
3290bool skb_gso_validate_mac_len(const struct sk_buff *skb, unsigned int len); 3289bool skb_gso_validate_mac_len(const struct sk_buff *skb, unsigned int len);
3291struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features); 3290struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features);
3292struct sk_buff *skb_vlan_untag(struct sk_buff *skb); 3291struct sk_buff *skb_vlan_untag(struct sk_buff *skb);
@@ -3646,7 +3645,7 @@ static inline bool __skb_checksum_validate_needed(struct sk_buff *skb,
3646 return true; 3645 return true;
3647} 3646}
3648 3647
3649/* For small packets <= CHECKSUM_BREAK peform checksum complete directly 3648/* For small packets <= CHECKSUM_BREAK perform checksum complete directly
3650 * in checksum_init. 3649 * in checksum_init.
3651 */ 3650 */
3652#define CHECKSUM_BREAK 76 3651#define CHECKSUM_BREAK 76
@@ -4038,6 +4037,12 @@ static inline bool skb_is_gso_v6(const struct sk_buff *skb)
4038 return skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6; 4037 return skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6;
4039} 4038}
4040 4039
4040/* Note: Should be called only if skb_is_gso(skb) is true */
4041static inline bool skb_is_gso_sctp(const struct sk_buff *skb)
4042{
4043 return skb_shinfo(skb)->gso_type & SKB_GSO_SCTP;
4044}
4045
4041static inline void skb_gso_reset(struct sk_buff *skb) 4046static inline void skb_gso_reset(struct sk_buff *skb)
4042{ 4047{
4043 skb_shinfo(skb)->gso_size = 0; 4048 skb_shinfo(skb)->gso_size = 0;
@@ -4045,6 +4050,22 @@ static inline void skb_gso_reset(struct sk_buff *skb)
4045 skb_shinfo(skb)->gso_type = 0; 4050 skb_shinfo(skb)->gso_type = 0;
4046} 4051}
4047 4052
4053static inline void skb_increase_gso_size(struct skb_shared_info *shinfo,
4054 u16 increment)
4055{
4056 if (WARN_ON_ONCE(shinfo->gso_size == GSO_BY_FRAGS))
4057 return;
4058 shinfo->gso_size += increment;
4059}
4060
4061static inline void skb_decrease_gso_size(struct skb_shared_info *shinfo,
4062 u16 decrement)
4063{
4064 if (WARN_ON_ONCE(shinfo->gso_size == GSO_BY_FRAGS))
4065 return;
4066 shinfo->gso_size -= decrement;
4067}
4068
4048void __skb_warn_lro_forwarding(const struct sk_buff *skb); 4069void __skb_warn_lro_forwarding(const struct sk_buff *skb);
4049 4070
4050static inline bool skb_warn_if_lro(const struct sk_buff *skb) 4071static inline bool skb_warn_if_lro(const struct sk_buff *skb)
@@ -4104,38 +4125,6 @@ static inline bool skb_head_is_locked(const struct sk_buff *skb)
4104 return !skb->head_frag || skb_cloned(skb); 4125 return !skb->head_frag || skb_cloned(skb);
4105} 4126}
4106 4127
4107/**
4108 * skb_gso_network_seglen - Return length of individual segments of a gso packet
4109 *
4110 * @skb: GSO skb
4111 *
4112 * skb_gso_network_seglen is used to determine the real size of the
4113 * individual segments, including Layer3 (IP, IPv6) and L4 headers (TCP/UDP).
4114 *
4115 * The MAC/L2 header is not accounted for.
4116 */
4117static inline unsigned int skb_gso_network_seglen(const struct sk_buff *skb)
4118{
4119 unsigned int hdr_len = skb_transport_header(skb) -
4120 skb_network_header(skb);
4121 return hdr_len + skb_gso_transport_seglen(skb);
4122}
4123
4124/**
4125 * skb_gso_mac_seglen - Return length of individual segments of a gso packet
4126 *
4127 * @skb: GSO skb
4128 *
4129 * skb_gso_mac_seglen is used to determine the real size of the
4130 * individual segments, including MAC/L2, Layer3 (IP, IPv6) and L4
4131 * headers (TCP/UDP).
4132 */
4133static inline unsigned int skb_gso_mac_seglen(const struct sk_buff *skb)
4134{
4135 unsigned int hdr_len = skb_transport_header(skb) - skb_mac_header(skb);
4136 return hdr_len + skb_gso_transport_seglen(skb);
4137}
4138
4139/* Local Checksum Offload. 4128/* Local Checksum Offload.
4140 * Compute outer checksum based on the assumption that the 4129 * Compute outer checksum based on the assumption that the
4141 * inner checksum will be offloaded later. 4130 * inner checksum will be offloaded later.
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 7b6a59f722a3..a1a3f4ed94ce 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -337,8 +337,6 @@ extern void deactivate_file_page(struct page *page);
337extern void mark_page_lazyfree(struct page *page); 337extern void mark_page_lazyfree(struct page *page);
338extern void swap_setup(void); 338extern void swap_setup(void);
339 339
340extern void add_page_to_unevictable_list(struct page *page);
341
342extern void lru_cache_add_active_or_unevictable(struct page *page, 340extern void lru_cache_add_active_or_unevictable(struct page *page,
343 struct vm_area_struct *vma); 341 struct vm_area_struct *vma);
344 342
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 0a6c71e0ad01..47f8af22f216 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -364,6 +364,7 @@ struct tty_file_private {
364#define TTY_PTY_LOCK 16 /* pty private */ 364#define TTY_PTY_LOCK 16 /* pty private */
365#define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */ 365#define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */
366#define TTY_HUPPED 18 /* Post driver->hangup() */ 366#define TTY_HUPPED 18 /* Post driver->hangup() */
367#define TTY_HUPPING 19 /* Hangup in progress */
367#define TTY_LDISC_HALTED 22 /* Line discipline is halted */ 368#define TTY_LDISC_HALTED 22 /* Line discipline is halted */
368 369
369/* Values for tty->flow_change */ 370/* Values for tty->flow_change */
diff --git a/include/linux/u64_stats_sync.h b/include/linux/u64_stats_sync.h
index 5bdbd9f49395..07ee0f84a46c 100644
--- a/include/linux/u64_stats_sync.h
+++ b/include/linux/u64_stats_sync.h
@@ -90,6 +90,28 @@ static inline void u64_stats_update_end(struct u64_stats_sync *syncp)
90#endif 90#endif
91} 91}
92 92
93static inline unsigned long
94u64_stats_update_begin_irqsave(struct u64_stats_sync *syncp)
95{
96 unsigned long flags = 0;
97
98#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
99 local_irq_save(flags);
100 write_seqcount_begin(&syncp->seq);
101#endif
102 return flags;
103}
104
105static inline void
106u64_stats_update_end_irqrestore(struct u64_stats_sync *syncp,
107 unsigned long flags)
108{
109#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
110 write_seqcount_end(&syncp->seq);
111 local_irq_restore(flags);
112#endif
113}
114
93static inline void u64_stats_update_begin_raw(struct u64_stats_sync *syncp) 115static inline void u64_stats_update_begin_raw(struct u64_stats_sync *syncp)
94{ 116{
95#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 117#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
diff --git a/include/linux/usb/quirks.h b/include/linux/usb/quirks.h
index f1fcec2fd5f8..b7a99ce56bc9 100644
--- a/include/linux/usb/quirks.h
+++ b/include/linux/usb/quirks.h
@@ -63,4 +63,7 @@
63 */ 63 */
64#define USB_QUIRK_DISCONNECT_SUSPEND BIT(12) 64#define USB_QUIRK_DISCONNECT_SUSPEND BIT(12)
65 65
66/* Device needs a pause after every control message. */
67#define USB_QUIRK_DELAY_CTRL_MSG BIT(13)
68
66#endif /* __LINUX_USB_QUIRKS_H */ 69#endif /* __LINUX_USB_QUIRKS_H */
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 4a54ef96aff5..0c3301421c57 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -456,7 +456,6 @@ extern int schedule_on_each_cpu(work_func_t func);
456int execute_in_process_context(work_func_t fn, struct execute_work *); 456int execute_in_process_context(work_func_t fn, struct execute_work *);
457 457
458extern bool flush_work(struct work_struct *work); 458extern bool flush_work(struct work_struct *work);
459extern bool cancel_work(struct work_struct *work);
460extern bool cancel_work_sync(struct work_struct *work); 459extern bool cancel_work_sync(struct work_struct *work);
461 460
462extern bool flush_delayed_work(struct delayed_work *dwork); 461extern bool flush_delayed_work(struct delayed_work *dwork);
@@ -465,6 +464,7 @@ extern bool cancel_delayed_work_sync(struct delayed_work *dwork);
465 464
466extern void workqueue_set_max_active(struct workqueue_struct *wq, 465extern void workqueue_set_max_active(struct workqueue_struct *wq,
467 int max_active); 466 int max_active);
467extern struct work_struct *current_work(void);
468extern bool current_is_workqueue_rescuer(void); 468extern bool current_is_workqueue_rescuer(void);
469extern bool workqueue_congested(int cpu, struct workqueue_struct *wq); 469extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);
470extern unsigned int work_busy(struct work_struct *work); 470extern unsigned int work_busy(struct work_struct *work);
diff --git a/include/media/demux.h b/include/media/demux.h
index c4df6cee48e6..bf00a5a41a90 100644
--- a/include/media/demux.h
+++ b/include/media/demux.h
@@ -117,7 +117,7 @@ struct dmx_ts_feed {
117 * specified by @filter_value that will be used on the filter 117 * specified by @filter_value that will be used on the filter
118 * match logic. 118 * match logic.
119 * @filter_mode: Contains a 16 bytes (128 bits) filter mode. 119 * @filter_mode: Contains a 16 bytes (128 bits) filter mode.
120 * @parent: Pointer to struct dmx_section_feed. 120 * @parent: Back-pointer to struct dmx_section_feed.
121 * @priv: Pointer to private data of the API client. 121 * @priv: Pointer to private data of the API client.
122 * 122 *
123 * 123 *
@@ -130,8 +130,9 @@ struct dmx_section_filter {
130 u8 filter_value[DMX_MAX_FILTER_SIZE]; 130 u8 filter_value[DMX_MAX_FILTER_SIZE];
131 u8 filter_mask[DMX_MAX_FILTER_SIZE]; 131 u8 filter_mask[DMX_MAX_FILTER_SIZE];
132 u8 filter_mode[DMX_MAX_FILTER_SIZE]; 132 u8 filter_mode[DMX_MAX_FILTER_SIZE];
133 struct dmx_section_feed *parent; /* Back-pointer */ 133 struct dmx_section_feed *parent;
134 void *priv; /* Pointer to private data of the API client */ 134
135 void *priv;
135}; 136};
136 137
137/** 138/**
@@ -193,6 +194,10 @@ struct dmx_section_feed {
193 * @buffer2: Pointer to the tail of the filtered TS packets, or NULL. 194 * @buffer2: Pointer to the tail of the filtered TS packets, or NULL.
194 * @buffer2_length: Length of the TS data in buffer2. 195 * @buffer2_length: Length of the TS data in buffer2.
195 * @source: Indicates which TS feed is the source of the callback. 196 * @source: Indicates which TS feed is the source of the callback.
197 * @buffer_flags: Address where buffer flags are stored. Those are
198 * used to report discontinuity users via DVB
199 * memory mapped API, as defined by
200 * &enum dmx_buffer_flags.
196 * 201 *
197 * This function callback prototype, provided by the client of the demux API, 202 * This function callback prototype, provided by the client of the demux API,
198 * is called from the demux code. The function is only called when filtering 203 * is called from the demux code. The function is only called when filtering
@@ -245,7 +250,8 @@ typedef int (*dmx_ts_cb)(const u8 *buffer1,
245 size_t buffer1_length, 250 size_t buffer1_length,
246 const u8 *buffer2, 251 const u8 *buffer2,
247 size_t buffer2_length, 252 size_t buffer2_length,
248 struct dmx_ts_feed *source); 253 struct dmx_ts_feed *source,
254 u32 *buffer_flags);
249 255
250/** 256/**
251 * typedef dmx_section_cb - DVB demux TS filter callback function prototype 257 * typedef dmx_section_cb - DVB demux TS filter callback function prototype
@@ -261,6 +267,10 @@ typedef int (*dmx_ts_cb)(const u8 *buffer1,
261 * including headers and CRC. 267 * including headers and CRC.
262 * @source: Indicates which section feed is the source of the 268 * @source: Indicates which section feed is the source of the
263 * callback. 269 * callback.
270 * @buffer_flags: Address where buffer flags are stored. Those are
271 * used to report discontinuity users via DVB
272 * memory mapped API, as defined by
273 * &enum dmx_buffer_flags.
264 * 274 *
265 * This function callback prototype, provided by the client of the demux API, 275 * This function callback prototype, provided by the client of the demux API,
266 * is called from the demux code. The function is only called when 276 * is called from the demux code. The function is only called when
@@ -286,7 +296,8 @@ typedef int (*dmx_section_cb)(const u8 *buffer1,
286 size_t buffer1_len, 296 size_t buffer1_len,
287 const u8 *buffer2, 297 const u8 *buffer2,
288 size_t buffer2_len, 298 size_t buffer2_len,
289 struct dmx_section_filter *source); 299 struct dmx_section_filter *source,
300 u32 *buffer_flags);
290 301
291/* 302/*
292 * DVB Front-End 303 * DVB Front-End
diff --git a/include/media/dmxdev.h b/include/media/dmxdev.h
index 2f5cb2c7b6a7..baafa3b8aca4 100644
--- a/include/media/dmxdev.h
+++ b/include/media/dmxdev.h
@@ -163,6 +163,7 @@ struct dmxdev_filter {
163 * @demux: pointer to &struct dmx_demux. 163 * @demux: pointer to &struct dmx_demux.
164 * @filternum: number of filters. 164 * @filternum: number of filters.
165 * @capabilities: demux capabilities as defined by &enum dmx_demux_caps. 165 * @capabilities: demux capabilities as defined by &enum dmx_demux_caps.
166 * @may_do_mmap: flag used to indicate if the device may do mmap.
166 * @exit: flag to indicate that the demux is being released. 167 * @exit: flag to indicate that the demux is being released.
167 * @dvr_orig_fe: pointer to &struct dmx_frontend. 168 * @dvr_orig_fe: pointer to &struct dmx_frontend.
168 * @dvr_buffer: embedded &struct dvb_ringbuffer for DVB output. 169 * @dvr_buffer: embedded &struct dvb_ringbuffer for DVB output.
@@ -180,6 +181,7 @@ struct dmxdev {
180 int filternum; 181 int filternum;
181 int capabilities; 182 int capabilities;
182 183
184 unsigned int may_do_mmap:1;
183 unsigned int exit:1; 185 unsigned int exit:1;
184#define DMXDEV_CAP_DUPLEX 1 186#define DMXDEV_CAP_DUPLEX 1
185 struct dmx_frontend *dvr_orig_fe; 187 struct dmx_frontend *dvr_orig_fe;
diff --git a/include/media/dvb_demux.h b/include/media/dvb_demux.h
index b07092038f4b..3b6aeca7a49e 100644
--- a/include/media/dvb_demux.h
+++ b/include/media/dvb_demux.h
@@ -115,6 +115,8 @@ struct dvb_demux_filter {
115 * @pid: PID to be filtered. 115 * @pid: PID to be filtered.
116 * @timeout: feed timeout. 116 * @timeout: feed timeout.
117 * @filter: pointer to &struct dvb_demux_filter. 117 * @filter: pointer to &struct dvb_demux_filter.
118 * @buffer_flags: Buffer flags used to report discontinuity users via DVB
119 * memory mapped API, as defined by &enum dmx_buffer_flags.
118 * @ts_type: type of TS, as defined by &enum ts_filter_type. 120 * @ts_type: type of TS, as defined by &enum ts_filter_type.
119 * @pes_type: type of PES, as defined by &enum dmx_ts_pes. 121 * @pes_type: type of PES, as defined by &enum dmx_ts_pes.
120 * @cc: MPEG-TS packet continuity counter 122 * @cc: MPEG-TS packet continuity counter
@@ -145,6 +147,8 @@ struct dvb_demux_feed {
145 ktime_t timeout; 147 ktime_t timeout;
146 struct dvb_demux_filter *filter; 148 struct dvb_demux_filter *filter;
147 149
150 u32 buffer_flags;
151
148 enum ts_filter_type ts_type; 152 enum ts_filter_type ts_type;
149 enum dmx_ts_pes pes_type; 153 enum dmx_ts_pes pes_type;
150 154
diff --git a/include/media/dvb_vb2.h b/include/media/dvb_vb2.h
index 01d1202d1a55..8cb88452cd6c 100644
--- a/include/media/dvb_vb2.h
+++ b/include/media/dvb_vb2.h
@@ -85,6 +85,12 @@ struct dvb_buffer {
85 * @nonblocking: 85 * @nonblocking:
86 * If different than zero, device is operating on non-blocking 86 * If different than zero, device is operating on non-blocking
87 * mode. 87 * mode.
88 * @flags: buffer flags as defined by &enum dmx_buffer_flags.
89 * Filled only at &DMX_DQBUF. &DMX_QBUF should zero this field.
90 * @count: monotonic counter for filled buffers. Helps to identify
91 * data stream loses. Filled only at &DMX_DQBUF. &DMX_QBUF should
92 * zero this field.
93 *
88 * @name: name of the device type. Currently, it can either be 94 * @name: name of the device type. Currently, it can either be
89 * "dvr" or "demux_filter". 95 * "dvr" or "demux_filter".
90 */ 96 */
@@ -100,10 +106,14 @@ struct dvb_vb2_ctx {
100 int buf_siz; 106 int buf_siz;
101 int buf_cnt; 107 int buf_cnt;
102 int nonblocking; 108 int nonblocking;
109
110 enum dmx_buffer_flags flags;
111 u32 count;
112
103 char name[DVB_VB2_NAME_MAX + 1]; 113 char name[DVB_VB2_NAME_MAX + 1];
104}; 114};
105 115
106#ifndef DVB_MMAP 116#ifndef CONFIG_DVB_MMAP
107static inline int dvb_vb2_init(struct dvb_vb2_ctx *ctx, 117static inline int dvb_vb2_init(struct dvb_vb2_ctx *ctx,
108 const char *name, int non_blocking) 118 const char *name, int non_blocking)
109{ 119{
@@ -114,7 +124,7 @@ static inline int dvb_vb2_release(struct dvb_vb2_ctx *ctx)
114 return 0; 124 return 0;
115}; 125};
116#define dvb_vb2_is_streaming(ctx) (0) 126#define dvb_vb2_is_streaming(ctx) (0)
117#define dvb_vb2_fill_buffer(ctx, file, wait) (0) 127#define dvb_vb2_fill_buffer(ctx, file, wait, flags) (0)
118 128
119static inline __poll_t dvb_vb2_poll(struct dvb_vb2_ctx *ctx, 129static inline __poll_t dvb_vb2_poll(struct dvb_vb2_ctx *ctx,
120 struct file *file, 130 struct file *file,
@@ -153,9 +163,13 @@ int dvb_vb2_is_streaming(struct dvb_vb2_ctx *ctx);
153 * @ctx: control struct for VB2 handler 163 * @ctx: control struct for VB2 handler
154 * @src: place where the data is stored 164 * @src: place where the data is stored
155 * @len: number of bytes to be copied from @src 165 * @len: number of bytes to be copied from @src
166 * @buffer_flags:
167 * pointer to buffer flags as defined by &enum dmx_buffer_flags.
168 * can be NULL.
156 */ 169 */
157int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ctx, 170int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ctx,
158 const unsigned char *src, int len); 171 const unsigned char *src, int len,
172 enum dmx_buffer_flags *buffer_flags);
159 173
160/** 174/**
161 * dvb_vb2_poll - Wrapper to vb2_core_streamon() for Digital TV 175 * dvb_vb2_poll - Wrapper to vb2_core_streamon() for Digital TV
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 6545b03e97f7..4de35ed12bcc 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -257,6 +257,18 @@ struct devlink_resource_size_params {
257 enum devlink_resource_unit unit; 257 enum devlink_resource_unit unit;
258}; 258};
259 259
260static inline void
261devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
262 u64 size_min, u64 size_max,
263 u64 size_granularity,
264 enum devlink_resource_unit unit)
265{
266 size_params->size_min = size_min;
267 size_params->size_max = size_max;
268 size_params->size_granularity = size_granularity;
269 size_params->unit = unit;
270}
271
260/** 272/**
261 * struct devlink_resource - devlink resource 273 * struct devlink_resource - devlink resource
262 * @name: name of the resource 274 * @name: name of the resource
@@ -278,7 +290,7 @@ struct devlink_resource {
278 u64 size_new; 290 u64 size_new;
279 bool size_valid; 291 bool size_valid;
280 struct devlink_resource *parent; 292 struct devlink_resource *parent;
281 struct devlink_resource_size_params *size_params; 293 struct devlink_resource_size_params size_params;
282 struct list_head list; 294 struct list_head list;
283 struct list_head resource_list; 295 struct list_head resource_list;
284 const struct devlink_resource_ops *resource_ops; 296 const struct devlink_resource_ops *resource_ops;
@@ -402,7 +414,7 @@ int devlink_resource_register(struct devlink *devlink,
402 u64 resource_size, 414 u64 resource_size,
403 u64 resource_id, 415 u64 resource_id,
404 u64 parent_resource_id, 416 u64 parent_resource_id,
405 struct devlink_resource_size_params *size_params, 417 const struct devlink_resource_size_params *size_params,
406 const struct devlink_resource_ops *resource_ops); 418 const struct devlink_resource_ops *resource_ops);
407void devlink_resources_unregister(struct devlink *devlink, 419void devlink_resources_unregister(struct devlink *devlink,
408 struct devlink_resource *resource); 420 struct devlink_resource *resource);
@@ -556,7 +568,7 @@ devlink_resource_register(struct devlink *devlink,
556 u64 resource_size, 568 u64 resource_size,
557 u64 resource_id, 569 u64 resource_id,
558 u64 parent_resource_id, 570 u64 parent_resource_id,
559 struct devlink_resource_size_params *size_params, 571 const struct devlink_resource_size_params *size_params,
560 const struct devlink_resource_ops *resource_ops) 572 const struct devlink_resource_ops *resource_ops)
561{ 573{
562 return 0; 574 return 0;
diff --git a/include/net/ip.h b/include/net/ip.h
index 746abff9ce51..f49b3a576bec 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -328,6 +328,13 @@ int ip_decrease_ttl(struct iphdr *iph)
328 return --iph->ttl; 328 return --iph->ttl;
329} 329}
330 330
331static inline int ip_mtu_locked(const struct dst_entry *dst)
332{
333 const struct rtable *rt = (const struct rtable *)dst;
334
335 return rt->rt_mtu_locked || dst_metric_locked(dst, RTAX_MTU);
336}
337
331static inline 338static inline
332int ip_dont_fragment(const struct sock *sk, const struct dst_entry *dst) 339int ip_dont_fragment(const struct sock *sk, const struct dst_entry *dst)
333{ 340{
@@ -335,7 +342,7 @@ int ip_dont_fragment(const struct sock *sk, const struct dst_entry *dst)
335 342
336 return pmtudisc == IP_PMTUDISC_DO || 343 return pmtudisc == IP_PMTUDISC_DO ||
337 (pmtudisc == IP_PMTUDISC_WANT && 344 (pmtudisc == IP_PMTUDISC_WANT &&
338 !(dst_metric_locked(dst, RTAX_MTU))); 345 !ip_mtu_locked(dst));
339} 346}
340 347
341static inline bool ip_sk_accept_pmtu(const struct sock *sk) 348static inline bool ip_sk_accept_pmtu(const struct sock *sk)
@@ -361,7 +368,7 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
361 struct net *net = dev_net(dst->dev); 368 struct net *net = dev_net(dst->dev);
362 369
363 if (net->ipv4.sysctl_ip_fwd_use_pmtu || 370 if (net->ipv4.sysctl_ip_fwd_use_pmtu ||
364 dst_metric_locked(dst, RTAX_MTU) || 371 ip_mtu_locked(dst) ||
365 !forwarding) 372 !forwarding)
366 return dst_mtu(dst); 373 return dst_mtu(dst);
367 374
diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 27d23a65f3cd..ac0866bb9e93 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -179,6 +179,9 @@ void rt6_disable_ip(struct net_device *dev, unsigned long event);
179void rt6_sync_down_dev(struct net_device *dev, unsigned long event); 179void rt6_sync_down_dev(struct net_device *dev, unsigned long event);
180void rt6_multipath_rebalance(struct rt6_info *rt); 180void rt6_multipath_rebalance(struct rt6_info *rt);
181 181
182void rt6_uncached_list_add(struct rt6_info *rt);
183void rt6_uncached_list_del(struct rt6_info *rt);
184
182static inline const struct rt6_info *skb_rt6_info(const struct sk_buff *skb) 185static inline const struct rt6_info *skb_rt6_info(const struct sk_buff *skb)
183{ 186{
184 const struct dst_entry *dst = skb_dst(skb); 187 const struct dst_entry *dst = skb_dst(skb);
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index f80524396c06..77d0a78cf7d2 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -59,6 +59,7 @@ struct fib_nh_exception {
59 int fnhe_genid; 59 int fnhe_genid;
60 __be32 fnhe_daddr; 60 __be32 fnhe_daddr;
61 u32 fnhe_pmtu; 61 u32 fnhe_pmtu;
62 bool fnhe_mtu_locked;
62 __be32 fnhe_gw; 63 __be32 fnhe_gw;
63 unsigned long fnhe_expires; 64 unsigned long fnhe_expires;
64 struct rtable __rcu *fnhe_rth_input; 65 struct rtable __rcu *fnhe_rth_input;
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 906e90223066..2b581bd93812 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -2063,6 +2063,9 @@ struct ieee80211_txq {
2063 * @IEEE80211_HW_SUPPORTS_TDLS_BUFFER_STA: Hardware supports buffer STA on 2063 * @IEEE80211_HW_SUPPORTS_TDLS_BUFFER_STA: Hardware supports buffer STA on
2064 * TDLS links. 2064 * TDLS links.
2065 * 2065 *
2066 * @IEEE80211_HW_DOESNT_SUPPORT_QOS_NDP: The driver (or firmware) doesn't
2067 * support QoS NDP for AP probing - that's most likely a driver bug.
2068 *
2066 * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays 2069 * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
2067 */ 2070 */
2068enum ieee80211_hw_flags { 2071enum ieee80211_hw_flags {
@@ -2106,6 +2109,7 @@ enum ieee80211_hw_flags {
2106 IEEE80211_HW_REPORTS_LOW_ACK, 2109 IEEE80211_HW_REPORTS_LOW_ACK,
2107 IEEE80211_HW_SUPPORTS_TX_FRAG, 2110 IEEE80211_HW_SUPPORTS_TX_FRAG,
2108 IEEE80211_HW_SUPPORTS_TDLS_BUFFER_STA, 2111 IEEE80211_HW_SUPPORTS_TDLS_BUFFER_STA,
2112 IEEE80211_HW_DOESNT_SUPPORT_QOS_NDP,
2109 2113
2110 /* keep last, obviously */ 2114 /* keep last, obviously */
2111 NUM_IEEE80211_HW_FLAGS 2115 NUM_IEEE80211_HW_FLAGS
@@ -4149,7 +4153,7 @@ void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *sta, u8 tid);
4149 * The TX headroom reserved by mac80211 for its own tx_status functions. 4153 * The TX headroom reserved by mac80211 for its own tx_status functions.
4150 * This is enough for the radiotap header. 4154 * This is enough for the radiotap header.
4151 */ 4155 */
4152#define IEEE80211_TX_STATUS_HEADROOM 14 4156#define IEEE80211_TX_STATUS_HEADROOM ALIGN(14, 4)
4153 4157
4154/** 4158/**
4155 * ieee80211_sta_set_buffered - inform mac80211 about driver-buffered frames 4159 * ieee80211_sta_set_buffered - inform mac80211 about driver-buffered frames
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index ebc5a2ed8631..f83cacce3308 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -78,7 +78,7 @@ struct regulatory_request {
78 int wiphy_idx; 78 int wiphy_idx;
79 enum nl80211_reg_initiator initiator; 79 enum nl80211_reg_initiator initiator;
80 enum nl80211_user_reg_hint_type user_reg_hint_type; 80 enum nl80211_user_reg_hint_type user_reg_hint_type;
81 char alpha2[2]; 81 char alpha2[3];
82 enum nl80211_dfs_regions dfs_region; 82 enum nl80211_dfs_regions dfs_region;
83 bool intersect; 83 bool intersect;
84 bool processed; 84 bool processed;
diff --git a/include/net/route.h b/include/net/route.h
index 1eb9ce470e25..20a92ca9e115 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -63,7 +63,8 @@ struct rtable {
63 __be32 rt_gateway; 63 __be32 rt_gateway;
64 64
65 /* Miscellaneous cached information */ 65 /* Miscellaneous cached information */
66 u32 rt_pmtu; 66 u32 rt_mtu_locked:1,
67 rt_pmtu:31;
67 68
68 u32 rt_table_id; 69 u32 rt_table_id;
69 70
@@ -227,6 +228,9 @@ struct in_ifaddr;
227void fib_add_ifaddr(struct in_ifaddr *); 228void fib_add_ifaddr(struct in_ifaddr *);
228void fib_del_ifaddr(struct in_ifaddr *, struct in_ifaddr *); 229void fib_del_ifaddr(struct in_ifaddr *, struct in_ifaddr *);
229 230
231void rt_add_uncached_list(struct rtable *rt);
232void rt_del_uncached_list(struct rtable *rt);
233
230static inline void ip_rt_put(struct rtable *rt) 234static inline void ip_rt_put(struct rtable *rt)
231{ 235{
232 /* dst_release() accepts a NULL parameter. 236 /* dst_release() accepts a NULL parameter.
diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
index e2ab13687fb9..2092d33194dd 100644
--- a/include/net/sch_generic.h
+++ b/include/net/sch_generic.h
@@ -824,6 +824,16 @@ static inline void __qdisc_drop(struct sk_buff *skb, struct sk_buff **to_free)
824 *to_free = skb; 824 *to_free = skb;
825} 825}
826 826
827static inline void __qdisc_drop_all(struct sk_buff *skb,
828 struct sk_buff **to_free)
829{
830 if (skb->prev)
831 skb->prev->next = *to_free;
832 else
833 skb->next = *to_free;
834 *to_free = skb;
835}
836
827static inline unsigned int __qdisc_queue_drop_head(struct Qdisc *sch, 837static inline unsigned int __qdisc_queue_drop_head(struct Qdisc *sch,
828 struct qdisc_skb_head *qh, 838 struct qdisc_skb_head *qh,
829 struct sk_buff **to_free) 839 struct sk_buff **to_free)
@@ -956,6 +966,15 @@ static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch,
956 return NET_XMIT_DROP; 966 return NET_XMIT_DROP;
957} 967}
958 968
969static inline int qdisc_drop_all(struct sk_buff *skb, struct Qdisc *sch,
970 struct sk_buff **to_free)
971{
972 __qdisc_drop_all(skb, to_free);
973 qdisc_qstats_drop(sch);
974
975 return NET_XMIT_DROP;
976}
977
959/* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how 978/* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how
960 long it will take to send a packet given its size. 979 long it will take to send a packet given its size.
961 */ 980 */
diff --git a/include/net/sock.h b/include/net/sock.h
index 169c92afcafa..ae23f3b389ca 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1137,6 +1137,7 @@ struct proto {
1137 1137
1138int proto_register(struct proto *prot, int alloc_slab); 1138int proto_register(struct proto *prot, int alloc_slab);
1139void proto_unregister(struct proto *prot); 1139void proto_unregister(struct proto *prot);
1140int sock_load_diag_module(int family, int protocol);
1140 1141
1141#ifdef SOCK_REFCNT_DEBUG 1142#ifdef SOCK_REFCNT_DEBUG
1142static inline void sk_refcnt_debug_inc(struct sock *sk) 1143static inline void sk_refcnt_debug_inc(struct sock *sk)
diff --git a/include/net/udplite.h b/include/net/udplite.h
index 81bdbf97319b..9185e45b997f 100644
--- a/include/net/udplite.h
+++ b/include/net/udplite.h
@@ -64,6 +64,7 @@ static inline int udplite_checksum_init(struct sk_buff *skb, struct udphdr *uh)
64 UDP_SKB_CB(skb)->cscov = cscov; 64 UDP_SKB_CB(skb)->cscov = cscov;
65 if (skb->ip_summed == CHECKSUM_COMPLETE) 65 if (skb->ip_summed == CHECKSUM_COMPLETE)
66 skb->ip_summed = CHECKSUM_NONE; 66 skb->ip_summed = CHECKSUM_NONE;
67 skb->csum_valid = 0;
67 } 68 }
68 69
69 return 0; 70 return 0;
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 73b2387e3f74..ff3ed435701f 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -1537,10 +1537,6 @@ struct ib_xrcd {
1537 1537
1538 struct mutex tgt_qp_mutex; 1538 struct mutex tgt_qp_mutex;
1539 struct list_head tgt_qp_list; 1539 struct list_head tgt_qp_list;
1540 /*
1541 * Implementation details of the RDMA core, don't use in drivers:
1542 */
1543 struct rdma_restrack_entry res;
1544}; 1540};
1545 1541
1546struct ib_ah { 1542struct ib_ah {
diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h
index c2d81167c858..2cdf8dcf4bdc 100644
--- a/include/rdma/restrack.h
+++ b/include/rdma/restrack.h
@@ -29,10 +29,6 @@ enum rdma_restrack_type {
29 */ 29 */
30 RDMA_RESTRACK_QP, 30 RDMA_RESTRACK_QP,
31 /** 31 /**
32 * @RDMA_RESTRACK_XRCD: XRC domain (XRCD)
33 */
34 RDMA_RESTRACK_XRCD,
35 /**
36 * @RDMA_RESTRACK_MAX: Last entry, used for array dclarations 32 * @RDMA_RESTRACK_MAX: Last entry, used for array dclarations
37 */ 33 */
38 RDMA_RESTRACK_MAX 34 RDMA_RESTRACK_MAX
diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
index 6da44079aa58..38287d9d23a1 100644
--- a/include/rdma/uverbs_ioctl.h
+++ b/include/rdma/uverbs_ioctl.h
@@ -276,10 +276,7 @@ struct uverbs_object_tree_def {
276 */ 276 */
277 277
278struct uverbs_ptr_attr { 278struct uverbs_ptr_attr {
279 union { 279 u64 data;
280 u64 data;
281 void __user *ptr;
282 };
283 u16 len; 280 u16 len;
284 /* Combination of bits from enum UVERBS_ATTR_F_XXXX */ 281 /* Combination of bits from enum UVERBS_ATTR_F_XXXX */
285 u16 flags; 282 u16 flags;
@@ -351,38 +348,60 @@ static inline const struct uverbs_attr *uverbs_attr_get(const struct uverbs_attr
351} 348}
352 349
353static inline int uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle, 350static inline int uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle,
354 size_t idx, const void *from) 351 size_t idx, const void *from, size_t size)
355{ 352{
356 const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx); 353 const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx);
357 u16 flags; 354 u16 flags;
355 size_t min_size;
358 356
359 if (IS_ERR(attr)) 357 if (IS_ERR(attr))
360 return PTR_ERR(attr); 358 return PTR_ERR(attr);
361 359
360 min_size = min_t(size_t, attr->ptr_attr.len, size);
361 if (copy_to_user(u64_to_user_ptr(attr->ptr_attr.data), from, min_size))
362 return -EFAULT;
363
362 flags = attr->ptr_attr.flags | UVERBS_ATTR_F_VALID_OUTPUT; 364 flags = attr->ptr_attr.flags | UVERBS_ATTR_F_VALID_OUTPUT;
363 return (!copy_to_user(attr->ptr_attr.ptr, from, attr->ptr_attr.len) && 365 if (put_user(flags, &attr->uattr->flags))
364 !put_user(flags, &attr->uattr->flags)) ? 0 : -EFAULT; 366 return -EFAULT;
367
368 return 0;
365} 369}
366 370
367static inline int _uverbs_copy_from(void *to, size_t to_size, 371static inline bool uverbs_attr_ptr_is_inline(const struct uverbs_attr *attr)
372{
373 return attr->ptr_attr.len <= sizeof(attr->ptr_attr.data);
374}
375
376static inline int _uverbs_copy_from(void *to,
368 const struct uverbs_attr_bundle *attrs_bundle, 377 const struct uverbs_attr_bundle *attrs_bundle,
369 size_t idx) 378 size_t idx,
379 size_t size)
370{ 380{
371 const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx); 381 const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx);
372 382
373 if (IS_ERR(attr)) 383 if (IS_ERR(attr))
374 return PTR_ERR(attr); 384 return PTR_ERR(attr);
375 385
376 if (to_size <= sizeof(((struct ib_uverbs_attr *)0)->data)) 386 /*
387 * Validation ensures attr->ptr_attr.len >= size. If the caller is
388 * using UVERBS_ATTR_SPEC_F_MIN_SZ then it must call copy_from with
389 * the right size.
390 */
391 if (unlikely(size < attr->ptr_attr.len))
392 return -EINVAL;
393
394 if (uverbs_attr_ptr_is_inline(attr))
377 memcpy(to, &attr->ptr_attr.data, attr->ptr_attr.len); 395 memcpy(to, &attr->ptr_attr.data, attr->ptr_attr.len);
378 else if (copy_from_user(to, attr->ptr_attr.ptr, attr->ptr_attr.len)) 396 else if (copy_from_user(to, u64_to_user_ptr(attr->ptr_attr.data),
397 attr->ptr_attr.len))
379 return -EFAULT; 398 return -EFAULT;
380 399
381 return 0; 400 return 0;
382} 401}
383 402
384#define uverbs_copy_from(to, attrs_bundle, idx) \ 403#define uverbs_copy_from(to, attrs_bundle, idx) \
385 _uverbs_copy_from(to, sizeof(*(to)), attrs_bundle, idx) 404 _uverbs_copy_from(to, attrs_bundle, idx, sizeof(*to))
386 405
387/* ================================================= 406/* =================================================
388 * Definitions -> Specs infrastructure 407 * Definitions -> Specs infrastructure
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index d8d4a902a88d..2280b2351739 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -68,6 +68,9 @@ struct scsi_cmnd {
68 struct list_head list; /* scsi_cmnd participates in queue lists */ 68 struct list_head list; /* scsi_cmnd participates in queue lists */
69 struct list_head eh_entry; /* entry for the host eh_cmd_q */ 69 struct list_head eh_entry; /* entry for the host eh_cmd_q */
70 struct delayed_work abort_work; 70 struct delayed_work abort_work;
71
72 struct rcu_head rcu;
73
71 int eh_eflags; /* Used by error handlr */ 74 int eh_eflags; /* Used by error handlr */
72 75
73 /* 76 /*
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 1a1df0d21ee3..a8b7bf879ced 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -571,8 +571,6 @@ struct Scsi_Host {
571 struct blk_mq_tag_set tag_set; 571 struct blk_mq_tag_set tag_set;
572 }; 572 };
573 573
574 struct rcu_head rcu;
575
576 atomic_t host_busy; /* commands actually active on low-level */ 574 atomic_t host_busy; /* commands actually active on low-level */
577 atomic_t host_blocked; 575 atomic_t host_blocked;
578 576
diff --git a/include/soc/arc/mcip.h b/include/soc/arc/mcip.h
index c2d1b15da136..a91f25151a5b 100644
--- a/include/soc/arc/mcip.h
+++ b/include/soc/arc/mcip.h
@@ -15,6 +15,7 @@
15 15
16#define ARC_REG_MCIP_BCR 0x0d0 16#define ARC_REG_MCIP_BCR 0x0d0
17#define ARC_REG_MCIP_IDU_BCR 0x0D5 17#define ARC_REG_MCIP_IDU_BCR 0x0D5
18#define ARC_REG_GFRC_BUILD 0x0D6
18#define ARC_REG_MCIP_CMD 0x600 19#define ARC_REG_MCIP_CMD 0x600
19#define ARC_REG_MCIP_WDATA 0x601 20#define ARC_REG_MCIP_WDATA 0x601
20#define ARC_REG_MCIP_READBACK 0x602 21#define ARC_REG_MCIP_READBACK 0x602
@@ -36,10 +37,14 @@ struct mcip_cmd {
36#define CMD_SEMA_RELEASE 0x12 37#define CMD_SEMA_RELEASE 0x12
37 38
38#define CMD_DEBUG_SET_MASK 0x34 39#define CMD_DEBUG_SET_MASK 0x34
40#define CMD_DEBUG_READ_MASK 0x35
39#define CMD_DEBUG_SET_SELECT 0x36 41#define CMD_DEBUG_SET_SELECT 0x36
42#define CMD_DEBUG_READ_SELECT 0x37
40 43
41#define CMD_GFRC_READ_LO 0x42 44#define CMD_GFRC_READ_LO 0x42
42#define CMD_GFRC_READ_HI 0x43 45#define CMD_GFRC_READ_HI 0x43
46#define CMD_GFRC_SET_CORE 0x47
47#define CMD_GFRC_READ_CORE 0x48
43 48
44#define CMD_IDU_ENABLE 0x71 49#define CMD_IDU_ENABLE 0x71
45#define CMD_IDU_DISABLE 0x72 50#define CMD_IDU_DISABLE 0x72
diff --git a/include/sound/ac97/regs.h b/include/sound/ac97/regs.h
index 4bb86d379bd5..9a4fa0c3264a 100644
--- a/include/sound/ac97/regs.h
+++ b/include/sound/ac97/regs.h
@@ -31,7 +31,7 @@
31#define AC97_HEADPHONE 0x04 /* Headphone Volume (optional) */ 31#define AC97_HEADPHONE 0x04 /* Headphone Volume (optional) */
32#define AC97_MASTER_MONO 0x06 /* Master Volume Mono (optional) */ 32#define AC97_MASTER_MONO 0x06 /* Master Volume Mono (optional) */
33#define AC97_MASTER_TONE 0x08 /* Master Tone (Bass & Treble) (optional) */ 33#define AC97_MASTER_TONE 0x08 /* Master Tone (Bass & Treble) (optional) */
34#define AC97_PC_BEEP 0x0a /* PC Beep Volume (optinal) */ 34#define AC97_PC_BEEP 0x0a /* PC Beep Volume (optional) */
35#define AC97_PHONE 0x0c /* Phone Volume (optional) */ 35#define AC97_PHONE 0x0c /* Phone Volume (optional) */
36#define AC97_MIC 0x0e /* MIC Volume */ 36#define AC97_MIC 0x0e /* MIC Volume */
37#define AC97_LINE 0x10 /* Line In Volume */ 37#define AC97_LINE 0x10 /* Line In Volume */
diff --git a/include/trace/events/mmc.h b/include/trace/events/mmc.h
index 200f731be557..7b706ff21335 100644
--- a/include/trace/events/mmc.h
+++ b/include/trace/events/mmc.h
@@ -86,8 +86,8 @@ TRACE_EVENT(mmc_request_start,
86 __entry->stop_flags, __entry->stop_retries, 86 __entry->stop_flags, __entry->stop_retries,
87 __entry->sbc_opcode, __entry->sbc_arg, 87 __entry->sbc_opcode, __entry->sbc_arg,
88 __entry->sbc_flags, __entry->sbc_retries, 88 __entry->sbc_flags, __entry->sbc_retries,
89 __entry->blocks, __entry->blk_addr, 89 __entry->blocks, __entry->blksz,
90 __entry->blksz, __entry->data_flags, __entry->tag, 90 __entry->blk_addr, __entry->data_flags, __entry->tag,
91 __entry->can_retune, __entry->doing_retune, 91 __entry->can_retune, __entry->doing_retune,
92 __entry->retune_now, __entry->need_retune, 92 __entry->retune_now, __entry->need_retune,
93 __entry->hold_retune, __entry->retune_period) 93 __entry->hold_retune, __entry->retune_period)
diff --git a/include/trace/events/xen.h b/include/trace/events/xen.h
index b8adf05c534e..7dd8f34c37df 100644
--- a/include/trace/events/xen.h
+++ b/include/trace/events/xen.h
@@ -368,7 +368,7 @@ TRACE_EVENT(xen_mmu_flush_tlb,
368 TP_printk("%s", "") 368 TP_printk("%s", "")
369 ); 369 );
370 370
371TRACE_EVENT(xen_mmu_flush_tlb_single, 371TRACE_EVENT(xen_mmu_flush_tlb_one_user,
372 TP_PROTO(unsigned long addr), 372 TP_PROTO(unsigned long addr),
373 TP_ARGS(addr), 373 TP_ARGS(addr),
374 TP_STRUCT__entry( 374 TP_STRUCT__entry(
diff --git a/include/uapi/asm-generic/siginfo.h b/include/uapi/asm-generic/siginfo.h
index 85dc965afd89..99c902e460c2 100644
--- a/include/uapi/asm-generic/siginfo.h
+++ b/include/uapi/asm-generic/siginfo.h
@@ -102,13 +102,13 @@ typedef struct siginfo {
102 short _addr_lsb; /* LSB of the reported address */ 102 short _addr_lsb; /* LSB of the reported address */
103 /* used when si_code=SEGV_BNDERR */ 103 /* used when si_code=SEGV_BNDERR */
104 struct { 104 struct {
105 short _dummy_bnd; 105 void *_dummy_bnd;
106 void __user *_lower; 106 void __user *_lower;
107 void __user *_upper; 107 void __user *_upper;
108 } _addr_bnd; 108 } _addr_bnd;
109 /* used when si_code=SEGV_PKUERR */ 109 /* used when si_code=SEGV_PKUERR */
110 struct { 110 struct {
111 short _dummy_pkey; 111 void *_dummy_pkey;
112 __u32 _pkey; 112 __u32 _pkey;
113 } _addr_pkey; 113 } _addr_pkey;
114 }; 114 };
diff --git a/include/uapi/drm/virtgpu_drm.h b/include/uapi/drm/virtgpu_drm.h
index 91a31ffed828..9a781f0611df 100644
--- a/include/uapi/drm/virtgpu_drm.h
+++ b/include/uapi/drm/virtgpu_drm.h
@@ -63,6 +63,7 @@ struct drm_virtgpu_execbuffer {
63}; 63};
64 64
65#define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */ 65#define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */
66#define VIRTGPU_PARAM_CAPSET_QUERY_FIX 2 /* do we have the capset fix */
66 67
67struct drm_virtgpu_getparam { 68struct drm_virtgpu_getparam {
68 __u64 param; 69 __u64 param;
diff --git a/include/uapi/linux/blktrace_api.h b/include/uapi/linux/blktrace_api.h
index 20d1490d6377..3c50e07ee833 100644
--- a/include/uapi/linux/blktrace_api.h
+++ b/include/uapi/linux/blktrace_api.h
@@ -131,7 +131,7 @@ enum {
131#define BLKTRACE_BDEV_SIZE 32 131#define BLKTRACE_BDEV_SIZE 32
132 132
133/* 133/*
134 * User setup structure passed with BLKTRACESTART 134 * User setup structure passed with BLKTRACESETUP
135 */ 135 */
136struct blk_user_trace_setup { 136struct blk_user_trace_setup {
137 char name[BLKTRACE_BDEV_SIZE]; /* output */ 137 char name[BLKTRACE_BDEV_SIZE]; /* output */
diff --git a/include/uapi/linux/dvb/dmx.h b/include/uapi/linux/dvb/dmx.h
index 5f3c5a918f00..b4112f0b6dd3 100644
--- a/include/uapi/linux/dvb/dmx.h
+++ b/include/uapi/linux/dvb/dmx.h
@@ -212,6 +212,32 @@ struct dmx_stc {
212}; 212};
213 213
214/** 214/**
215 * enum dmx_buffer_flags - DMX memory-mapped buffer flags
216 *
217 * @DMX_BUFFER_FLAG_HAD_CRC32_DISCARD:
218 * Indicates that the Kernel discarded one or more frames due to wrong
219 * CRC32 checksum.
220 * @DMX_BUFFER_FLAG_TEI:
221 * Indicates that the Kernel has detected a Transport Error indicator
222 * (TEI) on a filtered pid.
223 * @DMX_BUFFER_PKT_COUNTER_MISMATCH:
224 * Indicates that the Kernel has detected a packet counter mismatch
225 * on a filtered pid.
226 * @DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED:
227 * Indicates that the Kernel has detected one or more frame discontinuity.
228 * @DMX_BUFFER_FLAG_DISCONTINUITY_INDICATOR:
229 * Received at least one packet with a frame discontinuity indicator.
230 */
231
232enum dmx_buffer_flags {
233 DMX_BUFFER_FLAG_HAD_CRC32_DISCARD = 1 << 0,
234 DMX_BUFFER_FLAG_TEI = 1 << 1,
235 DMX_BUFFER_PKT_COUNTER_MISMATCH = 1 << 2,
236 DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED = 1 << 3,
237 DMX_BUFFER_FLAG_DISCONTINUITY_INDICATOR = 1 << 4,
238};
239
240/**
215 * struct dmx_buffer - dmx buffer info 241 * struct dmx_buffer - dmx buffer info
216 * 242 *
217 * @index: id number of the buffer 243 * @index: id number of the buffer
@@ -220,15 +246,24 @@ struct dmx_stc {
220 * offset from the start of the device memory for this plane, 246 * offset from the start of the device memory for this plane,
221 * (or a "cookie" that should be passed to mmap() as offset) 247 * (or a "cookie" that should be passed to mmap() as offset)
222 * @length: size in bytes of the buffer 248 * @length: size in bytes of the buffer
249 * @flags: bit array of buffer flags as defined by &enum dmx_buffer_flags.
250 * Filled only at &DMX_DQBUF.
251 * @count: monotonic counter for filled buffers. Helps to identify
252 * data stream loses. Filled only at &DMX_DQBUF.
223 * 253 *
224 * Contains data exchanged by application and driver using one of the streaming 254 * Contains data exchanged by application and driver using one of the streaming
225 * I/O methods. 255 * I/O methods.
256 *
257 * Please notice that, for &DMX_QBUF, only @index should be filled.
258 * On &DMX_DQBUF calls, all fields will be filled by the Kernel.
226 */ 259 */
227struct dmx_buffer { 260struct dmx_buffer {
228 __u32 index; 261 __u32 index;
229 __u32 bytesused; 262 __u32 bytesused;
230 __u32 offset; 263 __u32 offset;
231 __u32 length; 264 __u32 length;
265 __u32 flags;
266 __u32 count;
232}; 267};
233 268
234/** 269/**
diff --git a/include/uapi/linux/if_ether.h b/include/uapi/linux/if_ether.h
index f8cb5760ea4f..820de5d222d2 100644
--- a/include/uapi/linux/if_ether.h
+++ b/include/uapi/linux/if_ether.h
@@ -23,7 +23,6 @@
23#define _UAPI_LINUX_IF_ETHER_H 23#define _UAPI_LINUX_IF_ETHER_H
24 24
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/libc-compat.h>
27 26
28/* 27/*
29 * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble 28 * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble
@@ -31,6 +30,7 @@
31 */ 30 */
32 31
33#define ETH_ALEN 6 /* Octets in one ethernet addr */ 32#define ETH_ALEN 6 /* Octets in one ethernet addr */
33#define ETH_TLEN 2 /* Octets in ethernet type field */
34#define ETH_HLEN 14 /* Total octets in header. */ 34#define ETH_HLEN 14 /* Total octets in header. */
35#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */ 35#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
36#define ETH_DATA_LEN 1500 /* Max. octets in payload */ 36#define ETH_DATA_LEN 1500 /* Max. octets in payload */
@@ -151,6 +151,11 @@
151 * This is an Ethernet frame header. 151 * This is an Ethernet frame header.
152 */ 152 */
153 153
154/* allow libcs like musl to deactivate this, glibc does not implement this. */
155#ifndef __UAPI_DEF_ETHHDR
156#define __UAPI_DEF_ETHHDR 1
157#endif
158
154#if __UAPI_DEF_ETHHDR 159#if __UAPI_DEF_ETHHDR
155struct ethhdr { 160struct ethhdr {
156 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ 161 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 0fb5ef939732..7b26d4b0b052 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -761,6 +761,7 @@ struct kvm_ppc_resize_hpt {
761#define KVM_TRACE_PAUSE __KVM_DEPRECATED_MAIN_0x07 761#define KVM_TRACE_PAUSE __KVM_DEPRECATED_MAIN_0x07
762#define KVM_TRACE_DISABLE __KVM_DEPRECATED_MAIN_0x08 762#define KVM_TRACE_DISABLE __KVM_DEPRECATED_MAIN_0x08
763#define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2) 763#define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2)
764#define KVM_GET_MSR_FEATURE_INDEX_LIST _IOWR(KVMIO, 0x0a, struct kvm_msr_list)
764 765
765/* 766/*
766 * Extension capability list. 767 * Extension capability list.
@@ -934,6 +935,7 @@ struct kvm_ppc_resize_hpt {
934#define KVM_CAP_S390_AIS_MIGRATION 150 935#define KVM_CAP_S390_AIS_MIGRATION 150
935#define KVM_CAP_PPC_GET_CPU_CHAR 151 936#define KVM_CAP_PPC_GET_CPU_CHAR 151
936#define KVM_CAP_S390_BPB 152 937#define KVM_CAP_S390_BPB 152
938#define KVM_CAP_GET_MSR_FEATURES 153
937 939
938#ifdef KVM_CAP_IRQ_ROUTING 940#ifdef KVM_CAP_IRQ_ROUTING
939 941
diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
index fc29efaa918c..8254c937c9f4 100644
--- a/include/uapi/linux/libc-compat.h
+++ b/include/uapi/linux/libc-compat.h
@@ -264,10 +264,4 @@
264 264
265#endif /* __GLIBC__ */ 265#endif /* __GLIBC__ */
266 266
267/* Definitions for if_ether.h */
268/* allow libcs like musl to deactivate this, glibc does not implement this. */
269#ifndef __UAPI_DEF_ETHHDR
270#define __UAPI_DEF_ETHHDR 1
271#endif
272
273#endif /* _UAPI_LIBC_COMPAT_H */ 267#endif /* _UAPI_LIBC_COMPAT_H */
diff --git a/include/uapi/linux/lirc.h b/include/uapi/linux/lirc.h
index 4fe580d36e41..f5bf06ecd87d 100644
--- a/include/uapi/linux/lirc.h
+++ b/include/uapi/linux/lirc.h
@@ -54,7 +54,6 @@
54#define LIRC_CAN_SEND_RAW LIRC_MODE2SEND(LIRC_MODE_RAW) 54#define LIRC_CAN_SEND_RAW LIRC_MODE2SEND(LIRC_MODE_RAW)
55#define LIRC_CAN_SEND_PULSE LIRC_MODE2SEND(LIRC_MODE_PULSE) 55#define LIRC_CAN_SEND_PULSE LIRC_MODE2SEND(LIRC_MODE_PULSE)
56#define LIRC_CAN_SEND_MODE2 LIRC_MODE2SEND(LIRC_MODE_MODE2) 56#define LIRC_CAN_SEND_MODE2 LIRC_MODE2SEND(LIRC_MODE_MODE2)
57#define LIRC_CAN_SEND_SCANCODE LIRC_MODE2SEND(LIRC_MODE_SCANCODE)
58#define LIRC_CAN_SEND_LIRCCODE LIRC_MODE2SEND(LIRC_MODE_LIRCCODE) 57#define LIRC_CAN_SEND_LIRCCODE LIRC_MODE2SEND(LIRC_MODE_LIRCCODE)
59 58
60#define LIRC_CAN_SEND_MASK 0x0000003f 59#define LIRC_CAN_SEND_MASK 0x0000003f
diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h
index 3d77fe91239a..9008f31c7eb6 100644
--- a/include/uapi/linux/psp-sev.h
+++ b/include/uapi/linux/psp-sev.h
@@ -42,7 +42,7 @@ typedef enum {
42 SEV_RET_INVALID_PLATFORM_STATE, 42 SEV_RET_INVALID_PLATFORM_STATE,
43 SEV_RET_INVALID_GUEST_STATE, 43 SEV_RET_INVALID_GUEST_STATE,
44 SEV_RET_INAVLID_CONFIG, 44 SEV_RET_INAVLID_CONFIG,
45 SEV_RET_INVALID_len, 45 SEV_RET_INVALID_LEN,
46 SEV_RET_ALREADY_OWNED, 46 SEV_RET_ALREADY_OWNED,
47 SEV_RET_INVALID_CERTIFICATE, 47 SEV_RET_INVALID_CERTIFICATE,
48 SEV_RET_POLICY_FAILURE, 48 SEV_RET_POLICY_FAILURE,
diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h
index e46d82b91166..d5a1b8a492b9 100644
--- a/include/uapi/linux/ptrace.h
+++ b/include/uapi/linux/ptrace.h
@@ -69,8 +69,8 @@ struct ptrace_peeksiginfo_args {
69#define PTRACE_SECCOMP_GET_METADATA 0x420d 69#define PTRACE_SECCOMP_GET_METADATA 0x420d
70 70
71struct seccomp_metadata { 71struct seccomp_metadata {
72 unsigned long filter_off; /* Input: which filter */ 72 __u64 filter_off; /* Input: which filter */
73 unsigned int flags; /* Output: filter's flags */ 73 __u64 flags; /* Output: filter's flags */
74}; 74};
75 75
76/* Read signals from a shared (process wide) queue */ 76/* Read signals from a shared (process wide) queue */
diff --git a/include/uapi/linux/usb/audio.h b/include/uapi/linux/usb/audio.h
index 17a022c5b414..da3315ed1bcd 100644
--- a/include/uapi/linux/usb/audio.h
+++ b/include/uapi/linux/usb/audio.h
@@ -370,7 +370,7 @@ static inline __u8 uac_processing_unit_bControlSize(struct uac_processing_unit_d
370{ 370{
371 return (protocol == UAC_VERSION_1) ? 371 return (protocol == UAC_VERSION_1) ?
372 desc->baSourceID[desc->bNrInPins + 4] : 372 desc->baSourceID[desc->bNrInPins + 4] :
373 desc->baSourceID[desc->bNrInPins + 6]; 373 2; /* in UAC2, this value is constant */
374} 374}
375 375
376static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc, 376static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc,
@@ -378,7 +378,7 @@ static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_de
378{ 378{
379 return (protocol == UAC_VERSION_1) ? 379 return (protocol == UAC_VERSION_1) ?
380 &desc->baSourceID[desc->bNrInPins + 5] : 380 &desc->baSourceID[desc->bNrInPins + 5] :
381 &desc->baSourceID[desc->bNrInPins + 7]; 381 &desc->baSourceID[desc->bNrInPins + 6];
382} 382}
383 383
384static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc, 384static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc,
diff --git a/include/uapi/misc/ocxl.h b/include/uapi/misc/ocxl.h
index 4b0b0b756f3e..0af83d80fb3e 100644
--- a/include/uapi/misc/ocxl.h
+++ b/include/uapi/misc/ocxl.h
@@ -32,6 +32,22 @@ struct ocxl_ioctl_attach {
32 __u64 reserved3; 32 __u64 reserved3;
33}; 33};
34 34
35struct ocxl_ioctl_metadata {
36 __u16 version; // struct version, always backwards compatible
37
38 // Version 0 fields
39 __u8 afu_version_major;
40 __u8 afu_version_minor;
41 __u32 pasid; // PASID assigned to the current context
42
43 __u64 pp_mmio_size; // Per PASID MMIO size
44 __u64 global_mmio_size;
45
46 // End version 0 fields
47
48 __u64 reserved[13]; // Total of 16*u64
49};
50
35struct ocxl_ioctl_irq_fd { 51struct ocxl_ioctl_irq_fd {
36 __u64 irq_offset; 52 __u64 irq_offset;
37 __s32 eventfd; 53 __s32 eventfd;
@@ -45,5 +61,6 @@ struct ocxl_ioctl_irq_fd {
45#define OCXL_IOCTL_IRQ_ALLOC _IOR(OCXL_MAGIC, 0x11, __u64) 61#define OCXL_IOCTL_IRQ_ALLOC _IOR(OCXL_MAGIC, 0x11, __u64)
46#define OCXL_IOCTL_IRQ_FREE _IOW(OCXL_MAGIC, 0x12, __u64) 62#define OCXL_IOCTL_IRQ_FREE _IOW(OCXL_MAGIC, 0x12, __u64)
47#define OCXL_IOCTL_IRQ_SET_FD _IOW(OCXL_MAGIC, 0x13, struct ocxl_ioctl_irq_fd) 63#define OCXL_IOCTL_IRQ_SET_FD _IOW(OCXL_MAGIC, 0x13, struct ocxl_ioctl_irq_fd)
64#define OCXL_IOCTL_GET_METADATA _IOR(OCXL_MAGIC, 0x14, struct ocxl_ioctl_metadata)
48 65
49#endif /* _UAPI_MISC_OCXL_H */ 66#endif /* _UAPI_MISC_OCXL_H */
diff --git a/include/uapi/rdma/rdma_user_ioctl.h b/include/uapi/rdma/rdma_user_ioctl.h
index 03557b5f9aa6..46de0885e800 100644
--- a/include/uapi/rdma/rdma_user_ioctl.h
+++ b/include/uapi/rdma/rdma_user_ioctl.h
@@ -65,7 +65,7 @@ struct ib_uverbs_attr {
65 __u16 len; /* only for pointers */ 65 __u16 len; /* only for pointers */
66 __u16 flags; /* combination of UVERBS_ATTR_F_XXXX */ 66 __u16 flags; /* combination of UVERBS_ATTR_F_XXXX */
67 __u16 reserved; 67 __u16 reserved;
68 __u64 data; /* ptr to command, inline data or idr/fd */ 68 __aligned_u64 data; /* ptr to command, inline data or idr/fd */
69}; 69};
70 70
71struct ib_uverbs_ioctl_hdr { 71struct ib_uverbs_ioctl_hdr {
@@ -73,7 +73,7 @@ struct ib_uverbs_ioctl_hdr {
73 __u16 object_id; 73 __u16 object_id;
74 __u16 method_id; 74 __u16 method_id;
75 __u16 num_attrs; 75 __u16 num_attrs;
76 __u64 reserved; 76 __aligned_u64 reserved;
77 struct ib_uverbs_attr attrs[0]; 77 struct ib_uverbs_attr attrs[0];
78}; 78};
79 79
diff --git a/init/main.c b/init/main.c
index a8100b954839..21efbf6ace93 100644
--- a/init/main.c
+++ b/init/main.c
@@ -89,6 +89,7 @@
89#include <linux/io.h> 89#include <linux/io.h>
90#include <linux/cache.h> 90#include <linux/cache.h>
91#include <linux/rodata_test.h> 91#include <linux/rodata_test.h>
92#include <linux/jump_label.h>
92 93
93#include <asm/io.h> 94#include <asm/io.h>
94#include <asm/bugs.h> 95#include <asm/bugs.h>
@@ -1000,6 +1001,7 @@ static int __ref kernel_init(void *unused)
1000 /* need to finish all async __init code before freeing the memory */ 1001 /* need to finish all async __init code before freeing the memory */
1001 async_synchronize_full(); 1002 async_synchronize_full();
1002 ftrace_free_init_mem(); 1003 ftrace_free_init_mem();
1004 jump_label_invalidate_initmem();
1003 free_initmem(); 1005 free_initmem();
1004 mark_readonly(); 1006 mark_readonly();
1005 system_state = SYSTEM_RUNNING; 1007 system_state = SYSTEM_RUNNING;
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index d7f309f74dec..a808f29d4c5a 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -325,9 +325,8 @@ err:
325static int mqueue_fill_super(struct super_block *sb, void *data, int silent) 325static int mqueue_fill_super(struct super_block *sb, void *data, int silent)
326{ 326{
327 struct inode *inode; 327 struct inode *inode;
328 struct ipc_namespace *ns = data; 328 struct ipc_namespace *ns = sb->s_fs_info;
329 329
330 sb->s_fs_info = ns;
331 sb->s_iflags |= SB_I_NOEXEC | SB_I_NODEV; 330 sb->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
332 sb->s_blocksize = PAGE_SIZE; 331 sb->s_blocksize = PAGE_SIZE;
333 sb->s_blocksize_bits = PAGE_SHIFT; 332 sb->s_blocksize_bits = PAGE_SHIFT;
@@ -344,44 +343,18 @@ static int mqueue_fill_super(struct super_block *sb, void *data, int silent)
344 return 0; 343 return 0;
345} 344}
346 345
347static struct file_system_type mqueue_fs_type;
348/*
349 * Return value is pinned only by reference in ->mq_mnt; it will
350 * live until ipcns dies. Caller does not need to drop it.
351 */
352static struct vfsmount *mq_internal_mount(void)
353{
354 struct ipc_namespace *ns = current->nsproxy->ipc_ns;
355 struct vfsmount *m = ns->mq_mnt;
356 if (m)
357 return m;
358 m = kern_mount_data(&mqueue_fs_type, ns);
359 spin_lock(&mq_lock);
360 if (unlikely(ns->mq_mnt)) {
361 spin_unlock(&mq_lock);
362 if (!IS_ERR(m))
363 kern_unmount(m);
364 return ns->mq_mnt;
365 }
366 if (!IS_ERR(m))
367 ns->mq_mnt = m;
368 spin_unlock(&mq_lock);
369 return m;
370}
371
372static struct dentry *mqueue_mount(struct file_system_type *fs_type, 346static struct dentry *mqueue_mount(struct file_system_type *fs_type,
373 int flags, const char *dev_name, 347 int flags, const char *dev_name,
374 void *data) 348 void *data)
375{ 349{
376 struct vfsmount *m; 350 struct ipc_namespace *ns;
377 if (flags & SB_KERNMOUNT) 351 if (flags & SB_KERNMOUNT) {
378 return mount_nodev(fs_type, flags, data, mqueue_fill_super); 352 ns = data;
379 m = mq_internal_mount(); 353 data = NULL;
380 if (IS_ERR(m)) 354 } else {
381 return ERR_CAST(m); 355 ns = current->nsproxy->ipc_ns;
382 atomic_inc(&m->mnt_sb->s_active); 356 }
383 down_write(&m->mnt_sb->s_umount); 357 return mount_ns(fs_type, flags, data, ns, ns->user_ns, mqueue_fill_super);
384 return dget(m->mnt_root);
385} 358}
386 359
387static void init_once(void *foo) 360static void init_once(void *foo)
@@ -771,16 +744,13 @@ static int prepare_open(struct dentry *dentry, int oflag, int ro,
771static int do_mq_open(const char __user *u_name, int oflag, umode_t mode, 744static int do_mq_open(const char __user *u_name, int oflag, umode_t mode,
772 struct mq_attr *attr) 745 struct mq_attr *attr)
773{ 746{
774 struct vfsmount *mnt = mq_internal_mount(); 747 struct vfsmount *mnt = current->nsproxy->ipc_ns->mq_mnt;
775 struct dentry *root; 748 struct dentry *root = mnt->mnt_root;
776 struct filename *name; 749 struct filename *name;
777 struct path path; 750 struct path path;
778 int fd, error; 751 int fd, error;
779 int ro; 752 int ro;
780 753
781 if (IS_ERR(mnt))
782 return PTR_ERR(mnt);
783
784 audit_mq_open(oflag, mode, attr); 754 audit_mq_open(oflag, mode, attr);
785 755
786 if (IS_ERR(name = getname(u_name))) 756 if (IS_ERR(name = getname(u_name)))
@@ -791,7 +761,6 @@ static int do_mq_open(const char __user *u_name, int oflag, umode_t mode,
791 goto out_putname; 761 goto out_putname;
792 762
793 ro = mnt_want_write(mnt); /* we'll drop it in any case */ 763 ro = mnt_want_write(mnt); /* we'll drop it in any case */
794 root = mnt->mnt_root;
795 inode_lock(d_inode(root)); 764 inode_lock(d_inode(root));
796 path.dentry = lookup_one_len(name->name, root, strlen(name->name)); 765 path.dentry = lookup_one_len(name->name, root, strlen(name->name));
797 if (IS_ERR(path.dentry)) { 766 if (IS_ERR(path.dentry)) {
@@ -840,9 +809,6 @@ SYSCALL_DEFINE1(mq_unlink, const char __user *, u_name)
840 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns; 809 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
841 struct vfsmount *mnt = ipc_ns->mq_mnt; 810 struct vfsmount *mnt = ipc_ns->mq_mnt;
842 811
843 if (!mnt)
844 return -ENOENT;
845
846 name = getname(u_name); 812 name = getname(u_name);
847 if (IS_ERR(name)) 813 if (IS_ERR(name))
848 return PTR_ERR(name); 814 return PTR_ERR(name);
@@ -1569,26 +1535,28 @@ int mq_init_ns(struct ipc_namespace *ns)
1569 ns->mq_msgsize_max = DFLT_MSGSIZEMAX; 1535 ns->mq_msgsize_max = DFLT_MSGSIZEMAX;
1570 ns->mq_msg_default = DFLT_MSG; 1536 ns->mq_msg_default = DFLT_MSG;
1571 ns->mq_msgsize_default = DFLT_MSGSIZE; 1537 ns->mq_msgsize_default = DFLT_MSGSIZE;
1572 ns->mq_mnt = NULL;
1573 1538
1539 ns->mq_mnt = kern_mount_data(&mqueue_fs_type, ns);
1540 if (IS_ERR(ns->mq_mnt)) {
1541 int err = PTR_ERR(ns->mq_mnt);
1542 ns->mq_mnt = NULL;
1543 return err;
1544 }
1574 return 0; 1545 return 0;
1575} 1546}
1576 1547
1577void mq_clear_sbinfo(struct ipc_namespace *ns) 1548void mq_clear_sbinfo(struct ipc_namespace *ns)
1578{ 1549{
1579 if (ns->mq_mnt) 1550 ns->mq_mnt->mnt_sb->s_fs_info = NULL;
1580 ns->mq_mnt->mnt_sb->s_fs_info = NULL;
1581} 1551}
1582 1552
1583void mq_put_mnt(struct ipc_namespace *ns) 1553void mq_put_mnt(struct ipc_namespace *ns)
1584{ 1554{
1585 if (ns->mq_mnt) 1555 kern_unmount(ns->mq_mnt);
1586 kern_unmount(ns->mq_mnt);
1587} 1556}
1588 1557
1589static int __init init_mqueue_fs(void) 1558static int __init init_mqueue_fs(void)
1590{ 1559{
1591 struct vfsmount *m;
1592 int error; 1560 int error;
1593 1561
1594 mqueue_inode_cachep = kmem_cache_create("mqueue_inode_cache", 1562 mqueue_inode_cachep = kmem_cache_create("mqueue_inode_cache",
@@ -1610,10 +1578,6 @@ static int __init init_mqueue_fs(void)
1610 if (error) 1578 if (error)
1611 goto out_filesystem; 1579 goto out_filesystem;
1612 1580
1613 m = kern_mount_data(&mqueue_fs_type, &init_ipc_ns);
1614 if (IS_ERR(m))
1615 goto out_filesystem;
1616 init_ipc_ns.mq_mnt = m;
1617 return 0; 1581 return 0;
1618 1582
1619out_filesystem: 1583out_filesystem:
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index b1f66480135b..14750e7c5ee4 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -26,8 +26,10 @@ static void bpf_array_free_percpu(struct bpf_array *array)
26{ 26{
27 int i; 27 int i;
28 28
29 for (i = 0; i < array->map.max_entries; i++) 29 for (i = 0; i < array->map.max_entries; i++) {
30 free_percpu(array->pptrs[i]); 30 free_percpu(array->pptrs[i]);
31 cond_resched();
32 }
31} 33}
32 34
33static int bpf_array_alloc_percpu(struct bpf_array *array) 35static int bpf_array_alloc_percpu(struct bpf_array *array)
@@ -43,6 +45,7 @@ static int bpf_array_alloc_percpu(struct bpf_array *array)
43 return -ENOMEM; 45 return -ENOMEM;
44 } 46 }
45 array->pptrs[i] = ptr; 47 array->pptrs[i] = ptr;
48 cond_resched();
46 } 49 }
47 50
48 return 0; 51 return 0;
@@ -73,11 +76,11 @@ static int array_map_alloc_check(union bpf_attr *attr)
73static struct bpf_map *array_map_alloc(union bpf_attr *attr) 76static struct bpf_map *array_map_alloc(union bpf_attr *attr)
74{ 77{
75 bool percpu = attr->map_type == BPF_MAP_TYPE_PERCPU_ARRAY; 78 bool percpu = attr->map_type == BPF_MAP_TYPE_PERCPU_ARRAY;
76 int numa_node = bpf_map_attr_numa_node(attr); 79 int ret, numa_node = bpf_map_attr_numa_node(attr);
77 u32 elem_size, index_mask, max_entries; 80 u32 elem_size, index_mask, max_entries;
78 bool unpriv = !capable(CAP_SYS_ADMIN); 81 bool unpriv = !capable(CAP_SYS_ADMIN);
82 u64 cost, array_size, mask64;
79 struct bpf_array *array; 83 struct bpf_array *array;
80 u64 array_size, mask64;
81 84
82 elem_size = round_up(attr->value_size, 8); 85 elem_size = round_up(attr->value_size, 8);
83 86
@@ -109,8 +112,19 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)
109 array_size += (u64) max_entries * elem_size; 112 array_size += (u64) max_entries * elem_size;
110 113
111 /* make sure there is no u32 overflow later in round_up() */ 114 /* make sure there is no u32 overflow later in round_up() */
112 if (array_size >= U32_MAX - PAGE_SIZE) 115 cost = array_size;
116 if (cost >= U32_MAX - PAGE_SIZE)
113 return ERR_PTR(-ENOMEM); 117 return ERR_PTR(-ENOMEM);
118 if (percpu) {
119 cost += (u64)attr->max_entries * elem_size * num_possible_cpus();
120 if (cost >= U32_MAX - PAGE_SIZE)
121 return ERR_PTR(-ENOMEM);
122 }
123 cost = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT;
124
125 ret = bpf_map_precharge_memlock(cost);
126 if (ret < 0)
127 return ERR_PTR(ret);
114 128
115 /* allocate all map elements and zero-initialize them */ 129 /* allocate all map elements and zero-initialize them */
116 array = bpf_map_area_alloc(array_size, numa_node); 130 array = bpf_map_area_alloc(array_size, numa_node);
@@ -121,20 +135,13 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)
121 135
122 /* copy mandatory map attributes */ 136 /* copy mandatory map attributes */
123 bpf_map_init_from_attr(&array->map, attr); 137 bpf_map_init_from_attr(&array->map, attr);
138 array->map.pages = cost;
124 array->elem_size = elem_size; 139 array->elem_size = elem_size;
125 140
126 if (!percpu) 141 if (percpu && bpf_array_alloc_percpu(array)) {
127 goto out;
128
129 array_size += (u64) attr->max_entries * elem_size * num_possible_cpus();
130
131 if (array_size >= U32_MAX - PAGE_SIZE ||
132 bpf_array_alloc_percpu(array)) {
133 bpf_map_area_free(array); 142 bpf_map_area_free(array);
134 return ERR_PTR(-ENOMEM); 143 return ERR_PTR(-ENOMEM);
135 } 144 }
136out:
137 array->map.pages = round_up(array_size, PAGE_SIZE) >> PAGE_SHIFT;
138 145
139 return &array->map; 146 return &array->map;
140} 147}
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 29ca9208dcfa..d315b393abdd 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1590,7 +1590,7 @@ int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
1590 * so always copy 'cnt' prog_ids to the user. 1590 * so always copy 'cnt' prog_ids to the user.
1591 * In a rare race the user will see zero prog_ids 1591 * In a rare race the user will see zero prog_ids
1592 */ 1592 */
1593 ids = kcalloc(cnt, sizeof(u32), GFP_USER); 1593 ids = kcalloc(cnt, sizeof(u32), GFP_USER | __GFP_NOWARN);
1594 if (!ids) 1594 if (!ids)
1595 return -ENOMEM; 1595 return -ENOMEM;
1596 rcu_read_lock(); 1596 rcu_read_lock();
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index fbfdada6caee..a4bb0b34375a 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -334,7 +334,7 @@ static int cpu_map_kthread_run(void *data)
334static struct bpf_cpu_map_entry *__cpu_map_entry_alloc(u32 qsize, u32 cpu, 334static struct bpf_cpu_map_entry *__cpu_map_entry_alloc(u32 qsize, u32 cpu,
335 int map_id) 335 int map_id)
336{ 336{
337 gfp_t gfp = GFP_ATOMIC|__GFP_NOWARN; 337 gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
338 struct bpf_cpu_map_entry *rcpu; 338 struct bpf_cpu_map_entry *rcpu;
339 int numa, err; 339 int numa, err;
340 340
diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c
index 7b469d10d0e9..b4b5b81e7251 100644
--- a/kernel/bpf/lpm_trie.c
+++ b/kernel/bpf/lpm_trie.c
@@ -555,7 +555,10 @@ static void trie_free(struct bpf_map *map)
555 struct lpm_trie_node __rcu **slot; 555 struct lpm_trie_node __rcu **slot;
556 struct lpm_trie_node *node; 556 struct lpm_trie_node *node;
557 557
558 raw_spin_lock(&trie->lock); 558 /* Wait for outstanding programs to complete
559 * update/lookup/delete/get_next_key and free the trie.
560 */
561 synchronize_rcu();
559 562
560 /* Always start at the root and walk down to a node that has no 563 /* Always start at the root and walk down to a node that has no
561 * children. Then free that node, nullify its reference in the parent 564 * children. Then free that node, nullify its reference in the parent
@@ -566,10 +569,9 @@ static void trie_free(struct bpf_map *map)
566 slot = &trie->root; 569 slot = &trie->root;
567 570
568 for (;;) { 571 for (;;) {
569 node = rcu_dereference_protected(*slot, 572 node = rcu_dereference_protected(*slot, 1);
570 lockdep_is_held(&trie->lock));
571 if (!node) 573 if (!node)
572 goto unlock; 574 goto out;
573 575
574 if (rcu_access_pointer(node->child[0])) { 576 if (rcu_access_pointer(node->child[0])) {
575 slot = &node->child[0]; 577 slot = &node->child[0];
@@ -587,8 +589,8 @@ static void trie_free(struct bpf_map *map)
587 } 589 }
588 } 590 }
589 591
590unlock: 592out:
591 raw_spin_unlock(&trie->lock); 593 kfree(trie);
592} 594}
593 595
594static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key) 596static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key)
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index 48c33417d13c..a927e89dad6e 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -521,8 +521,8 @@ static struct smap_psock *smap_init_psock(struct sock *sock,
521static struct bpf_map *sock_map_alloc(union bpf_attr *attr) 521static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
522{ 522{
523 struct bpf_stab *stab; 523 struct bpf_stab *stab;
524 int err = -EINVAL;
525 u64 cost; 524 u64 cost;
525 int err;
526 526
527 if (!capable(CAP_NET_ADMIN)) 527 if (!capable(CAP_NET_ADMIN))
528 return ERR_PTR(-EPERM); 528 return ERR_PTR(-EPERM);
@@ -547,6 +547,7 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
547 547
548 /* make sure page count doesn't overflow */ 548 /* make sure page count doesn't overflow */
549 cost = (u64) stab->map.max_entries * sizeof(struct sock *); 549 cost = (u64) stab->map.max_entries * sizeof(struct sock *);
550 err = -EINVAL;
550 if (cost >= U32_MAX - PAGE_SIZE) 551 if (cost >= U32_MAX - PAGE_SIZE)
551 goto free_stab; 552 goto free_stab;
552 553
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index e24aa3241387..43f95d190eea 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1845,7 +1845,7 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
1845 union bpf_attr attr = {}; 1845 union bpf_attr attr = {};
1846 int err; 1846 int err;
1847 1847
1848 if (!capable(CAP_SYS_ADMIN) && sysctl_unprivileged_bpf_disabled) 1848 if (sysctl_unprivileged_bpf_disabled && !capable(CAP_SYS_ADMIN))
1849 return -EPERM; 1849 return -EPERM;
1850 1850
1851 err = check_uarg_tail_zero(uattr, sizeof(attr), size); 1851 err = check_uarg_tail_zero(uattr, sizeof(attr), size);
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5fb69a85d967..c6eff108aa99 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1356,6 +1356,13 @@ static bool is_ctx_reg(struct bpf_verifier_env *env, int regno)
1356 return reg->type == PTR_TO_CTX; 1356 return reg->type == PTR_TO_CTX;
1357} 1357}
1358 1358
1359static bool is_pkt_reg(struct bpf_verifier_env *env, int regno)
1360{
1361 const struct bpf_reg_state *reg = cur_regs(env) + regno;
1362
1363 return type_is_pkt_pointer(reg->type);
1364}
1365
1359static int check_pkt_ptr_alignment(struct bpf_verifier_env *env, 1366static int check_pkt_ptr_alignment(struct bpf_verifier_env *env,
1360 const struct bpf_reg_state *reg, 1367 const struct bpf_reg_state *reg,
1361 int off, int size, bool strict) 1368 int off, int size, bool strict)
@@ -1416,10 +1423,10 @@ static int check_generic_ptr_alignment(struct bpf_verifier_env *env,
1416} 1423}
1417 1424
1418static int check_ptr_alignment(struct bpf_verifier_env *env, 1425static int check_ptr_alignment(struct bpf_verifier_env *env,
1419 const struct bpf_reg_state *reg, 1426 const struct bpf_reg_state *reg, int off,
1420 int off, int size) 1427 int size, bool strict_alignment_once)
1421{ 1428{
1422 bool strict = env->strict_alignment; 1429 bool strict = env->strict_alignment || strict_alignment_once;
1423 const char *pointer_desc = ""; 1430 const char *pointer_desc = "";
1424 1431
1425 switch (reg->type) { 1432 switch (reg->type) {
@@ -1576,9 +1583,9 @@ static void coerce_reg_to_size(struct bpf_reg_state *reg, int size)
1576 * if t==write && value_regno==-1, some unknown value is stored into memory 1583 * if t==write && value_regno==-1, some unknown value is stored into memory
1577 * if t==read && value_regno==-1, don't care what we read from memory 1584 * if t==read && value_regno==-1, don't care what we read from memory
1578 */ 1585 */
1579static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regno, int off, 1586static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regno,
1580 int bpf_size, enum bpf_access_type t, 1587 int off, int bpf_size, enum bpf_access_type t,
1581 int value_regno) 1588 int value_regno, bool strict_alignment_once)
1582{ 1589{
1583 struct bpf_reg_state *regs = cur_regs(env); 1590 struct bpf_reg_state *regs = cur_regs(env);
1584 struct bpf_reg_state *reg = regs + regno; 1591 struct bpf_reg_state *reg = regs + regno;
@@ -1590,7 +1597,7 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regn
1590 return size; 1597 return size;
1591 1598
1592 /* alignment checks will add in reg->off themselves */ 1599 /* alignment checks will add in reg->off themselves */
1593 err = check_ptr_alignment(env, reg, off, size); 1600 err = check_ptr_alignment(env, reg, off, size, strict_alignment_once);
1594 if (err) 1601 if (err)
1595 return err; 1602 return err;
1596 1603
@@ -1735,21 +1742,23 @@ static int check_xadd(struct bpf_verifier_env *env, int insn_idx, struct bpf_ins
1735 return -EACCES; 1742 return -EACCES;
1736 } 1743 }
1737 1744
1738 if (is_ctx_reg(env, insn->dst_reg)) { 1745 if (is_ctx_reg(env, insn->dst_reg) ||
1739 verbose(env, "BPF_XADD stores into R%d context is not allowed\n", 1746 is_pkt_reg(env, insn->dst_reg)) {
1740 insn->dst_reg); 1747 verbose(env, "BPF_XADD stores into R%d %s is not allowed\n",
1748 insn->dst_reg, is_ctx_reg(env, insn->dst_reg) ?
1749 "context" : "packet");
1741 return -EACCES; 1750 return -EACCES;
1742 } 1751 }
1743 1752
1744 /* check whether atomic_add can read the memory */ 1753 /* check whether atomic_add can read the memory */
1745 err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, 1754 err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off,
1746 BPF_SIZE(insn->code), BPF_READ, -1); 1755 BPF_SIZE(insn->code), BPF_READ, -1, true);
1747 if (err) 1756 if (err)
1748 return err; 1757 return err;
1749 1758
1750 /* check whether atomic_add can write into the same memory */ 1759 /* check whether atomic_add can write into the same memory */
1751 return check_mem_access(env, insn_idx, insn->dst_reg, insn->off, 1760 return check_mem_access(env, insn_idx, insn->dst_reg, insn->off,
1752 BPF_SIZE(insn->code), BPF_WRITE, -1); 1761 BPF_SIZE(insn->code), BPF_WRITE, -1, true);
1753} 1762}
1754 1763
1755/* when register 'regno' is passed into function that will read 'access_size' 1764/* when register 'regno' is passed into function that will read 'access_size'
@@ -2388,7 +2397,8 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn
2388 * is inferred from register state. 2397 * is inferred from register state.
2389 */ 2398 */
2390 for (i = 0; i < meta.access_size; i++) { 2399 for (i = 0; i < meta.access_size; i++) {
2391 err = check_mem_access(env, insn_idx, meta.regno, i, BPF_B, BPF_WRITE, -1); 2400 err = check_mem_access(env, insn_idx, meta.regno, i, BPF_B,
2401 BPF_WRITE, -1, false);
2392 if (err) 2402 if (err)
2393 return err; 2403 return err;
2394 } 2404 }
@@ -4632,7 +4642,7 @@ static int do_check(struct bpf_verifier_env *env)
4632 */ 4642 */
4633 err = check_mem_access(env, insn_idx, insn->src_reg, insn->off, 4643 err = check_mem_access(env, insn_idx, insn->src_reg, insn->off,
4634 BPF_SIZE(insn->code), BPF_READ, 4644 BPF_SIZE(insn->code), BPF_READ,
4635 insn->dst_reg); 4645 insn->dst_reg, false);
4636 if (err) 4646 if (err)
4637 return err; 4647 return err;
4638 4648
@@ -4684,7 +4694,7 @@ static int do_check(struct bpf_verifier_env *env)
4684 /* check that memory (dst_reg + off) is writeable */ 4694 /* check that memory (dst_reg + off) is writeable */
4685 err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, 4695 err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off,
4686 BPF_SIZE(insn->code), BPF_WRITE, 4696 BPF_SIZE(insn->code), BPF_WRITE,
4687 insn->src_reg); 4697 insn->src_reg, false);
4688 if (err) 4698 if (err)
4689 return err; 4699 return err;
4690 4700
@@ -4719,7 +4729,7 @@ static int do_check(struct bpf_verifier_env *env)
4719 /* check that memory (dst_reg + off) is writeable */ 4729 /* check that memory (dst_reg + off) is writeable */
4720 err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, 4730 err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off,
4721 BPF_SIZE(insn->code), BPF_WRITE, 4731 BPF_SIZE(insn->code), BPF_WRITE,
4722 -1); 4732 -1, false);
4723 if (err) 4733 if (err)
4724 return err; 4734 return err;
4725 4735
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 8cda3bc3ae22..4bfb2908ec15 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -3183,6 +3183,16 @@ static int cgroup_enable_threaded(struct cgroup *cgrp)
3183 if (cgroup_is_threaded(cgrp)) 3183 if (cgroup_is_threaded(cgrp))
3184 return 0; 3184 return 0;
3185 3185
3186 /*
3187 * If @cgroup is populated or has domain controllers enabled, it
3188 * can't be switched. While the below cgroup_can_be_thread_root()
3189 * test can catch the same conditions, that's only when @parent is
3190 * not mixable, so let's check it explicitly.
3191 */
3192 if (cgroup_is_populated(cgrp) ||
3193 cgrp->subtree_control & ~cgrp_dfl_threaded_ss_mask)
3194 return -EOPNOTSUPP;
3195
3186 /* we're joining the parent's domain, ensure its validity */ 3196 /* we're joining the parent's domain, ensure its validity */
3187 if (!cgroup_is_valid_domain(dom_cgrp) || 3197 if (!cgroup_is_valid_domain(dom_cgrp) ||
3188 !cgroup_can_be_thread_root(dom_cgrp)) 3198 !cgroup_can_be_thread_root(dom_cgrp))
diff --git a/kernel/compat.c b/kernel/compat.c
index 3247fe761f60..3f5fa8902e7d 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -488,25 +488,6 @@ get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat)
488} 488}
489EXPORT_SYMBOL_GPL(get_compat_sigset); 489EXPORT_SYMBOL_GPL(get_compat_sigset);
490 490
491int
492put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
493 unsigned int size)
494{
495 /* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
496#ifdef __BIG_ENDIAN
497 compat_sigset_t v;
498 switch (_NSIG_WORDS) {
499 case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
500 case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
501 case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
502 case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0];
503 }
504 return copy_to_user(compat, &v, size) ? -EFAULT : 0;
505#else
506 return copy_to_user(compat, set, size) ? -EFAULT : 0;
507#endif
508}
509
510#ifdef CONFIG_NUMA 491#ifdef CONFIG_NUMA
511COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages, 492COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages,
512 compat_uptr_t __user *, pages32, 493 compat_uptr_t __user *, pages32,
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 96db9ae5d5af..709a55b9ad97 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -724,9 +724,15 @@ static inline void __update_cgrp_time(struct perf_cgroup *cgrp)
724 724
725static inline void update_cgrp_time_from_cpuctx(struct perf_cpu_context *cpuctx) 725static inline void update_cgrp_time_from_cpuctx(struct perf_cpu_context *cpuctx)
726{ 726{
727 struct perf_cgroup *cgrp_out = cpuctx->cgrp; 727 struct perf_cgroup *cgrp = cpuctx->cgrp;
728 if (cgrp_out) 728 struct cgroup_subsys_state *css;
729 __update_cgrp_time(cgrp_out); 729
730 if (cgrp) {
731 for (css = &cgrp->css; css; css = css->parent) {
732 cgrp = container_of(css, struct perf_cgroup, css);
733 __update_cgrp_time(cgrp);
734 }
735 }
730} 736}
731 737
732static inline void update_cgrp_time_from_event(struct perf_event *event) 738static inline void update_cgrp_time_from_event(struct perf_event *event)
@@ -754,6 +760,7 @@ perf_cgroup_set_timestamp(struct task_struct *task,
754{ 760{
755 struct perf_cgroup *cgrp; 761 struct perf_cgroup *cgrp;
756 struct perf_cgroup_info *info; 762 struct perf_cgroup_info *info;
763 struct cgroup_subsys_state *css;
757 764
758 /* 765 /*
759 * ctx->lock held by caller 766 * ctx->lock held by caller
@@ -764,8 +771,12 @@ perf_cgroup_set_timestamp(struct task_struct *task,
764 return; 771 return;
765 772
766 cgrp = perf_cgroup_from_task(task, ctx); 773 cgrp = perf_cgroup_from_task(task, ctx);
767 info = this_cpu_ptr(cgrp->info); 774
768 info->timestamp = ctx->timestamp; 775 for (css = &cgrp->css; css; css = css->parent) {
776 cgrp = container_of(css, struct perf_cgroup, css);
777 info = this_cpu_ptr(cgrp->info);
778 info->timestamp = ctx->timestamp;
779 }
769} 780}
770 781
771static DEFINE_PER_CPU(struct list_head, cgrp_cpuctx_list); 782static DEFINE_PER_CPU(struct list_head, cgrp_cpuctx_list);
@@ -2246,7 +2257,7 @@ static void ctx_resched(struct perf_cpu_context *cpuctx,
2246 struct perf_event_context *task_ctx, 2257 struct perf_event_context *task_ctx,
2247 enum event_type_t event_type) 2258 enum event_type_t event_type)
2248{ 2259{
2249 enum event_type_t ctx_event_type = event_type & EVENT_ALL; 2260 enum event_type_t ctx_event_type;
2250 bool cpu_event = !!(event_type & EVENT_CPU); 2261 bool cpu_event = !!(event_type & EVENT_CPU);
2251 2262
2252 /* 2263 /*
@@ -2256,6 +2267,8 @@ static void ctx_resched(struct perf_cpu_context *cpuctx,
2256 if (event_type & EVENT_PINNED) 2267 if (event_type & EVENT_PINNED)
2257 event_type |= EVENT_FLEXIBLE; 2268 event_type |= EVENT_FLEXIBLE;
2258 2269
2270 ctx_event_type = event_type & EVENT_ALL;
2271
2259 perf_pmu_disable(cpuctx->ctx.pmu); 2272 perf_pmu_disable(cpuctx->ctx.pmu);
2260 if (task_ctx) 2273 if (task_ctx)
2261 task_ctx_sched_out(cpuctx, task_ctx, event_type); 2274 task_ctx_sched_out(cpuctx, task_ctx, event_type);
diff --git a/kernel/extable.c b/kernel/extable.c
index a17fdb63dc3e..6a5b61ebc66c 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -64,7 +64,7 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr)
64 return e; 64 return e;
65} 65}
66 66
67static inline int init_kernel_text(unsigned long addr) 67int init_kernel_text(unsigned long addr)
68{ 68{
69 if (addr >= (unsigned long)_sinittext && 69 if (addr >= (unsigned long)_sinittext &&
70 addr < (unsigned long)_einittext) 70 addr < (unsigned long)_einittext)
diff --git a/kernel/fail_function.c b/kernel/fail_function.c
index 21b0122cb39c..1d5632d8bbcc 100644
--- a/kernel/fail_function.c
+++ b/kernel/fail_function.c
@@ -14,6 +14,15 @@
14 14
15static int fei_kprobe_handler(struct kprobe *kp, struct pt_regs *regs); 15static int fei_kprobe_handler(struct kprobe *kp, struct pt_regs *regs);
16 16
17static void fei_post_handler(struct kprobe *kp, struct pt_regs *regs,
18 unsigned long flags)
19{
20 /*
21 * A dummy post handler is required to prohibit optimizing, because
22 * jump optimization does not support execution path overriding.
23 */
24}
25
17struct fei_attr { 26struct fei_attr {
18 struct list_head list; 27 struct list_head list;
19 struct kprobe kp; 28 struct kprobe kp;
@@ -56,6 +65,7 @@ static struct fei_attr *fei_attr_new(const char *sym, unsigned long addr)
56 return NULL; 65 return NULL;
57 } 66 }
58 attr->kp.pre_handler = fei_kprobe_handler; 67 attr->kp.pre_handler = fei_kprobe_handler;
68 attr->kp.post_handler = fei_post_handler;
59 attr->retval = adjust_error_retval(addr, 0); 69 attr->retval = adjust_error_retval(addr, 0);
60 INIT_LIST_HEAD(&attr->list); 70 INIT_LIST_HEAD(&attr->list);
61 } 71 }
diff --git a/kernel/fork.c b/kernel/fork.c
index be8aa5b98666..e5d9d405ae4e 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -592,7 +592,7 @@ static void check_mm(struct mm_struct *mm)
592 * is dropped: either by a lazy thread or by 592 * is dropped: either by a lazy thread or by
593 * mmput. Free the page directory and the mm. 593 * mmput. Free the page directory and the mm.
594 */ 594 */
595static void __mmdrop(struct mm_struct *mm) 595void __mmdrop(struct mm_struct *mm)
596{ 596{
597 BUG_ON(mm == &init_mm); 597 BUG_ON(mm == &init_mm);
598 mm_free_pgd(mm); 598 mm_free_pgd(mm);
@@ -603,18 +603,7 @@ static void __mmdrop(struct mm_struct *mm)
603 put_user_ns(mm->user_ns); 603 put_user_ns(mm->user_ns);
604 free_mm(mm); 604 free_mm(mm);
605} 605}
606 606EXPORT_SYMBOL_GPL(__mmdrop);
607void mmdrop(struct mm_struct *mm)
608{
609 /*
610 * The implicit full barrier implied by atomic_dec_and_test() is
611 * required by the membarrier system call before returning to
612 * user-space, after storing to rq->curr.
613 */
614 if (unlikely(atomic_dec_and_test(&mm->mm_count)))
615 __mmdrop(mm);
616}
617EXPORT_SYMBOL_GPL(mmdrop);
618 607
619static void mmdrop_async_fn(struct work_struct *work) 608static void mmdrop_async_fn(struct work_struct *work)
620{ 609{
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index e6a9c36470ee..82b8b18ee1eb 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -1726,25 +1726,14 @@ static int irq_domain_debug_show(struct seq_file *m, void *p)
1726 irq_domain_debug_show_one(m, d, 0); 1726 irq_domain_debug_show_one(m, d, 0);
1727 return 0; 1727 return 0;
1728} 1728}
1729 1729DEFINE_SHOW_ATTRIBUTE(irq_domain_debug);
1730static int irq_domain_debug_open(struct inode *inode, struct file *file)
1731{
1732 return single_open(file, irq_domain_debug_show, inode->i_private);
1733}
1734
1735static const struct file_operations dfs_domain_ops = {
1736 .open = irq_domain_debug_open,
1737 .read = seq_read,
1738 .llseek = seq_lseek,
1739 .release = single_release,
1740};
1741 1730
1742static void debugfs_add_domain_dir(struct irq_domain *d) 1731static void debugfs_add_domain_dir(struct irq_domain *d)
1743{ 1732{
1744 if (!d->name || !domain_dir || d->debugfs_file) 1733 if (!d->name || !domain_dir || d->debugfs_file)
1745 return; 1734 return;
1746 d->debugfs_file = debugfs_create_file(d->name, 0444, domain_dir, d, 1735 d->debugfs_file = debugfs_create_file(d->name, 0444, domain_dir, d,
1747 &dfs_domain_ops); 1736 &irq_domain_debug_fops);
1748} 1737}
1749 1738
1750static void debugfs_remove_domain_dir(struct irq_domain *d) 1739static void debugfs_remove_domain_dir(struct irq_domain *d)
@@ -1760,7 +1749,8 @@ void __init irq_domain_debugfs_init(struct dentry *root)
1760 if (!domain_dir) 1749 if (!domain_dir)
1761 return; 1750 return;
1762 1751
1763 debugfs_create_file("default", 0444, domain_dir, NULL, &dfs_domain_ops); 1752 debugfs_create_file("default", 0444, domain_dir, NULL,
1753 &irq_domain_debug_fops);
1764 mutex_lock(&irq_domain_mutex); 1754 mutex_lock(&irq_domain_mutex);
1765 list_for_each_entry(d, &irq_domain_list, link) 1755 list_for_each_entry(d, &irq_domain_list, link)
1766 debugfs_add_domain_dir(d); 1756 debugfs_add_domain_dir(d);
diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c
index 5187dfe809ac..4c5770407031 100644
--- a/kernel/irq/matrix.c
+++ b/kernel/irq/matrix.c
@@ -16,6 +16,7 @@ struct cpumap {
16 unsigned int available; 16 unsigned int available;
17 unsigned int allocated; 17 unsigned int allocated;
18 unsigned int managed; 18 unsigned int managed;
19 bool initialized;
19 bool online; 20 bool online;
20 unsigned long alloc_map[IRQ_MATRIX_SIZE]; 21 unsigned long alloc_map[IRQ_MATRIX_SIZE];
21 unsigned long managed_map[IRQ_MATRIX_SIZE]; 22 unsigned long managed_map[IRQ_MATRIX_SIZE];
@@ -81,9 +82,11 @@ void irq_matrix_online(struct irq_matrix *m)
81 82
82 BUG_ON(cm->online); 83 BUG_ON(cm->online);
83 84
84 bitmap_zero(cm->alloc_map, m->matrix_bits); 85 if (!cm->initialized) {
85 cm->available = m->alloc_size - (cm->managed + m->systembits_inalloc); 86 cm->available = m->alloc_size;
86 cm->allocated = 0; 87 cm->available -= cm->managed + m->systembits_inalloc;
88 cm->initialized = true;
89 }
87 m->global_available += cm->available; 90 m->global_available += cm->available;
88 cm->online = true; 91 cm->online = true;
89 m->online_maps++; 92 m->online_maps++;
@@ -370,14 +373,16 @@ void irq_matrix_free(struct irq_matrix *m, unsigned int cpu,
370 if (WARN_ON_ONCE(bit < m->alloc_start || bit >= m->alloc_end)) 373 if (WARN_ON_ONCE(bit < m->alloc_start || bit >= m->alloc_end))
371 return; 374 return;
372 375
373 if (cm->online) { 376 clear_bit(bit, cm->alloc_map);
374 clear_bit(bit, cm->alloc_map); 377 cm->allocated--;
375 cm->allocated--; 378
379 if (cm->online)
376 m->total_allocated--; 380 m->total_allocated--;
377 if (!managed) { 381
378 cm->available++; 382 if (!managed) {
383 cm->available++;
384 if (cm->online)
379 m->global_available++; 385 m->global_available++;
380 }
381 } 386 }
382 trace_irq_matrix_free(bit, cpu, m, cm); 387 trace_irq_matrix_free(bit, cpu, m, cm);
383} 388}
diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index b4517095db6a..01ebdf1f9f40 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -16,6 +16,7 @@
16#include <linux/jump_label_ratelimit.h> 16#include <linux/jump_label_ratelimit.h>
17#include <linux/bug.h> 17#include <linux/bug.h>
18#include <linux/cpu.h> 18#include <linux/cpu.h>
19#include <asm/sections.h>
19 20
20#ifdef HAVE_JUMP_LABEL 21#ifdef HAVE_JUMP_LABEL
21 22
@@ -366,12 +367,16 @@ static void __jump_label_update(struct static_key *key,
366{ 367{
367 for (; (entry < stop) && (jump_entry_key(entry) == key); entry++) { 368 for (; (entry < stop) && (jump_entry_key(entry) == key); entry++) {
368 /* 369 /*
369 * entry->code set to 0 invalidates module init text sections 370 * An entry->code of 0 indicates an entry which has been
370 * kernel_text_address() verifies we are not in core kernel 371 * disabled because it was in an init text area.
371 * init code, see jump_label_invalidate_module_init().
372 */ 372 */
373 if (entry->code && kernel_text_address(entry->code)) 373 if (entry->code) {
374 arch_jump_label_transform(entry, jump_label_type(entry)); 374 if (kernel_text_address(entry->code))
375 arch_jump_label_transform(entry, jump_label_type(entry));
376 else
377 WARN_ONCE(1, "can't patch jump_label at %pS",
378 (void *)(unsigned long)entry->code);
379 }
375 } 380 }
376} 381}
377 382
@@ -417,6 +422,19 @@ void __init jump_label_init(void)
417 cpus_read_unlock(); 422 cpus_read_unlock();
418} 423}
419 424
425/* Disable any jump label entries in __init/__exit code */
426void __init jump_label_invalidate_initmem(void)
427{
428 struct jump_entry *iter_start = __start___jump_table;
429 struct jump_entry *iter_stop = __stop___jump_table;
430 struct jump_entry *iter;
431
432 for (iter = iter_start; iter < iter_stop; iter++) {
433 if (init_section_contains((void *)(unsigned long)iter->code, 1))
434 iter->code = 0;
435 }
436}
437
420#ifdef CONFIG_MODULES 438#ifdef CONFIG_MODULES
421 439
422static enum jump_label_type jump_label_init_type(struct jump_entry *entry) 440static enum jump_label_type jump_label_init_type(struct jump_entry *entry)
@@ -633,6 +651,7 @@ static void jump_label_del_module(struct module *mod)
633 } 651 }
634} 652}
635 653
654/* Disable any jump label entries in module init code */
636static void jump_label_invalidate_module_init(struct module *mod) 655static void jump_label_invalidate_module_init(struct module *mod)
637{ 656{
638 struct jump_entry *iter_start = mod->jump_entries; 657 struct jump_entry *iter_start = mod->jump_entries;
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index da2ccf142358..102160ff5c66 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -978,67 +978,90 @@ static int prepare_kprobe(struct kprobe *p)
978} 978}
979 979
980/* Caller must lock kprobe_mutex */ 980/* Caller must lock kprobe_mutex */
981static void arm_kprobe_ftrace(struct kprobe *p) 981static int arm_kprobe_ftrace(struct kprobe *p)
982{ 982{
983 int ret; 983 int ret = 0;
984 984
985 ret = ftrace_set_filter_ip(&kprobe_ftrace_ops, 985 ret = ftrace_set_filter_ip(&kprobe_ftrace_ops,
986 (unsigned long)p->addr, 0, 0); 986 (unsigned long)p->addr, 0, 0);
987 WARN(ret < 0, "Failed to arm kprobe-ftrace at %p (%d)\n", p->addr, ret); 987 if (ret) {
988 kprobe_ftrace_enabled++; 988 pr_debug("Failed to arm kprobe-ftrace at %p (%d)\n", p->addr, ret);
989 if (kprobe_ftrace_enabled == 1) { 989 return ret;
990 }
991
992 if (kprobe_ftrace_enabled == 0) {
990 ret = register_ftrace_function(&kprobe_ftrace_ops); 993 ret = register_ftrace_function(&kprobe_ftrace_ops);
991 WARN(ret < 0, "Failed to init kprobe-ftrace (%d)\n", ret); 994 if (ret) {
995 pr_debug("Failed to init kprobe-ftrace (%d)\n", ret);
996 goto err_ftrace;
997 }
992 } 998 }
999
1000 kprobe_ftrace_enabled++;
1001 return ret;
1002
1003err_ftrace:
1004 /*
1005 * Note: Since kprobe_ftrace_ops has IPMODIFY set, and ftrace requires a
1006 * non-empty filter_hash for IPMODIFY ops, we're safe from an accidental
1007 * empty filter_hash which would undesirably trace all functions.
1008 */
1009 ftrace_set_filter_ip(&kprobe_ftrace_ops, (unsigned long)p->addr, 1, 0);
1010 return ret;
993} 1011}
994 1012
995/* Caller must lock kprobe_mutex */ 1013/* Caller must lock kprobe_mutex */
996static void disarm_kprobe_ftrace(struct kprobe *p) 1014static int disarm_kprobe_ftrace(struct kprobe *p)
997{ 1015{
998 int ret; 1016 int ret = 0;
999 1017
1000 kprobe_ftrace_enabled--; 1018 if (kprobe_ftrace_enabled == 1) {
1001 if (kprobe_ftrace_enabled == 0) {
1002 ret = unregister_ftrace_function(&kprobe_ftrace_ops); 1019 ret = unregister_ftrace_function(&kprobe_ftrace_ops);
1003 WARN(ret < 0, "Failed to init kprobe-ftrace (%d)\n", ret); 1020 if (WARN(ret < 0, "Failed to unregister kprobe-ftrace (%d)\n", ret))
1021 return ret;
1004 } 1022 }
1023
1024 kprobe_ftrace_enabled--;
1025
1005 ret = ftrace_set_filter_ip(&kprobe_ftrace_ops, 1026 ret = ftrace_set_filter_ip(&kprobe_ftrace_ops,
1006 (unsigned long)p->addr, 1, 0); 1027 (unsigned long)p->addr, 1, 0);
1007 WARN(ret < 0, "Failed to disarm kprobe-ftrace at %p (%d)\n", p->addr, ret); 1028 WARN(ret < 0, "Failed to disarm kprobe-ftrace at %p (%d)\n", p->addr, ret);
1029 return ret;
1008} 1030}
1009#else /* !CONFIG_KPROBES_ON_FTRACE */ 1031#else /* !CONFIG_KPROBES_ON_FTRACE */
1010#define prepare_kprobe(p) arch_prepare_kprobe(p) 1032#define prepare_kprobe(p) arch_prepare_kprobe(p)
1011#define arm_kprobe_ftrace(p) do {} while (0) 1033#define arm_kprobe_ftrace(p) (-ENODEV)
1012#define disarm_kprobe_ftrace(p) do {} while (0) 1034#define disarm_kprobe_ftrace(p) (-ENODEV)
1013#endif 1035#endif
1014 1036
1015/* Arm a kprobe with text_mutex */ 1037/* Arm a kprobe with text_mutex */
1016static void arm_kprobe(struct kprobe *kp) 1038static int arm_kprobe(struct kprobe *kp)
1017{ 1039{
1018 if (unlikely(kprobe_ftrace(kp))) { 1040 if (unlikely(kprobe_ftrace(kp)))
1019 arm_kprobe_ftrace(kp); 1041 return arm_kprobe_ftrace(kp);
1020 return; 1042
1021 }
1022 cpus_read_lock(); 1043 cpus_read_lock();
1023 mutex_lock(&text_mutex); 1044 mutex_lock(&text_mutex);
1024 __arm_kprobe(kp); 1045 __arm_kprobe(kp);
1025 mutex_unlock(&text_mutex); 1046 mutex_unlock(&text_mutex);
1026 cpus_read_unlock(); 1047 cpus_read_unlock();
1048
1049 return 0;
1027} 1050}
1028 1051
1029/* Disarm a kprobe with text_mutex */ 1052/* Disarm a kprobe with text_mutex */
1030static void disarm_kprobe(struct kprobe *kp, bool reopt) 1053static int disarm_kprobe(struct kprobe *kp, bool reopt)
1031{ 1054{
1032 if (unlikely(kprobe_ftrace(kp))) { 1055 if (unlikely(kprobe_ftrace(kp)))
1033 disarm_kprobe_ftrace(kp); 1056 return disarm_kprobe_ftrace(kp);
1034 return;
1035 }
1036 1057
1037 cpus_read_lock(); 1058 cpus_read_lock();
1038 mutex_lock(&text_mutex); 1059 mutex_lock(&text_mutex);
1039 __disarm_kprobe(kp, reopt); 1060 __disarm_kprobe(kp, reopt);
1040 mutex_unlock(&text_mutex); 1061 mutex_unlock(&text_mutex);
1041 cpus_read_unlock(); 1062 cpus_read_unlock();
1063
1064 return 0;
1042} 1065}
1043 1066
1044/* 1067/*
@@ -1362,9 +1385,15 @@ out:
1362 1385
1363 if (ret == 0 && kprobe_disabled(ap) && !kprobe_disabled(p)) { 1386 if (ret == 0 && kprobe_disabled(ap) && !kprobe_disabled(p)) {
1364 ap->flags &= ~KPROBE_FLAG_DISABLED; 1387 ap->flags &= ~KPROBE_FLAG_DISABLED;
1365 if (!kprobes_all_disarmed) 1388 if (!kprobes_all_disarmed) {
1366 /* Arm the breakpoint again. */ 1389 /* Arm the breakpoint again. */
1367 arm_kprobe(ap); 1390 ret = arm_kprobe(ap);
1391 if (ret) {
1392 ap->flags |= KPROBE_FLAG_DISABLED;
1393 list_del_rcu(&p->list);
1394 synchronize_sched();
1395 }
1396 }
1368 } 1397 }
1369 return ret; 1398 return ret;
1370} 1399}
@@ -1573,8 +1602,14 @@ int register_kprobe(struct kprobe *p)
1573 hlist_add_head_rcu(&p->hlist, 1602 hlist_add_head_rcu(&p->hlist,
1574 &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); 1603 &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]);
1575 1604
1576 if (!kprobes_all_disarmed && !kprobe_disabled(p)) 1605 if (!kprobes_all_disarmed && !kprobe_disabled(p)) {
1577 arm_kprobe(p); 1606 ret = arm_kprobe(p);
1607 if (ret) {
1608 hlist_del_rcu(&p->hlist);
1609 synchronize_sched();
1610 goto out;
1611 }
1612 }
1578 1613
1579 /* Try to optimize kprobe */ 1614 /* Try to optimize kprobe */
1580 try_to_optimize_kprobe(p); 1615 try_to_optimize_kprobe(p);
@@ -1608,11 +1643,12 @@ static int aggr_kprobe_disabled(struct kprobe *ap)
1608static struct kprobe *__disable_kprobe(struct kprobe *p) 1643static struct kprobe *__disable_kprobe(struct kprobe *p)
1609{ 1644{
1610 struct kprobe *orig_p; 1645 struct kprobe *orig_p;
1646 int ret;
1611 1647
1612 /* Get an original kprobe for return */ 1648 /* Get an original kprobe for return */
1613 orig_p = __get_valid_kprobe(p); 1649 orig_p = __get_valid_kprobe(p);
1614 if (unlikely(orig_p == NULL)) 1650 if (unlikely(orig_p == NULL))
1615 return NULL; 1651 return ERR_PTR(-EINVAL);
1616 1652
1617 if (!kprobe_disabled(p)) { 1653 if (!kprobe_disabled(p)) {
1618 /* Disable probe if it is a child probe */ 1654 /* Disable probe if it is a child probe */
@@ -1626,8 +1662,13 @@ static struct kprobe *__disable_kprobe(struct kprobe *p)
1626 * should have already been disarmed, so 1662 * should have already been disarmed, so
1627 * skip unneed disarming process. 1663 * skip unneed disarming process.
1628 */ 1664 */
1629 if (!kprobes_all_disarmed) 1665 if (!kprobes_all_disarmed) {
1630 disarm_kprobe(orig_p, true); 1666 ret = disarm_kprobe(orig_p, true);
1667 if (ret) {
1668 p->flags &= ~KPROBE_FLAG_DISABLED;
1669 return ERR_PTR(ret);
1670 }
1671 }
1631 orig_p->flags |= KPROBE_FLAG_DISABLED; 1672 orig_p->flags |= KPROBE_FLAG_DISABLED;
1632 } 1673 }
1633 } 1674 }
@@ -1644,8 +1685,8 @@ static int __unregister_kprobe_top(struct kprobe *p)
1644 1685
1645 /* Disable kprobe. This will disarm it if needed. */ 1686 /* Disable kprobe. This will disarm it if needed. */
1646 ap = __disable_kprobe(p); 1687 ap = __disable_kprobe(p);
1647 if (ap == NULL) 1688 if (IS_ERR(ap))
1648 return -EINVAL; 1689 return PTR_ERR(ap);
1649 1690
1650 if (ap == p) 1691 if (ap == p)
1651 /* 1692 /*
@@ -2078,12 +2119,14 @@ static void kill_kprobe(struct kprobe *p)
2078int disable_kprobe(struct kprobe *kp) 2119int disable_kprobe(struct kprobe *kp)
2079{ 2120{
2080 int ret = 0; 2121 int ret = 0;
2122 struct kprobe *p;
2081 2123
2082 mutex_lock(&kprobe_mutex); 2124 mutex_lock(&kprobe_mutex);
2083 2125
2084 /* Disable this kprobe */ 2126 /* Disable this kprobe */
2085 if (__disable_kprobe(kp) == NULL) 2127 p = __disable_kprobe(kp);
2086 ret = -EINVAL; 2128 if (IS_ERR(p))
2129 ret = PTR_ERR(p);
2087 2130
2088 mutex_unlock(&kprobe_mutex); 2131 mutex_unlock(&kprobe_mutex);
2089 return ret; 2132 return ret;
@@ -2116,7 +2159,9 @@ int enable_kprobe(struct kprobe *kp)
2116 2159
2117 if (!kprobes_all_disarmed && kprobe_disabled(p)) { 2160 if (!kprobes_all_disarmed && kprobe_disabled(p)) {
2118 p->flags &= ~KPROBE_FLAG_DISABLED; 2161 p->flags &= ~KPROBE_FLAG_DISABLED;
2119 arm_kprobe(p); 2162 ret = arm_kprobe(p);
2163 if (ret)
2164 p->flags |= KPROBE_FLAG_DISABLED;
2120 } 2165 }
2121out: 2166out:
2122 mutex_unlock(&kprobe_mutex); 2167 mutex_unlock(&kprobe_mutex);
@@ -2407,11 +2452,12 @@ static const struct file_operations debugfs_kprobe_blacklist_ops = {
2407 .release = seq_release, 2452 .release = seq_release,
2408}; 2453};
2409 2454
2410static void arm_all_kprobes(void) 2455static int arm_all_kprobes(void)
2411{ 2456{
2412 struct hlist_head *head; 2457 struct hlist_head *head;
2413 struct kprobe *p; 2458 struct kprobe *p;
2414 unsigned int i; 2459 unsigned int i, total = 0, errors = 0;
2460 int err, ret = 0;
2415 2461
2416 mutex_lock(&kprobe_mutex); 2462 mutex_lock(&kprobe_mutex);
2417 2463
@@ -2428,46 +2474,74 @@ static void arm_all_kprobes(void)
2428 /* Arming kprobes doesn't optimize kprobe itself */ 2474 /* Arming kprobes doesn't optimize kprobe itself */
2429 for (i = 0; i < KPROBE_TABLE_SIZE; i++) { 2475 for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
2430 head = &kprobe_table[i]; 2476 head = &kprobe_table[i];
2431 hlist_for_each_entry_rcu(p, head, hlist) 2477 /* Arm all kprobes on a best-effort basis */
2432 if (!kprobe_disabled(p)) 2478 hlist_for_each_entry_rcu(p, head, hlist) {
2433 arm_kprobe(p); 2479 if (!kprobe_disabled(p)) {
2480 err = arm_kprobe(p);
2481 if (err) {
2482 errors++;
2483 ret = err;
2484 }
2485 total++;
2486 }
2487 }
2434 } 2488 }
2435 2489
2436 printk(KERN_INFO "Kprobes globally enabled\n"); 2490 if (errors)
2491 pr_warn("Kprobes globally enabled, but failed to arm %d out of %d probes\n",
2492 errors, total);
2493 else
2494 pr_info("Kprobes globally enabled\n");
2437 2495
2438already_enabled: 2496already_enabled:
2439 mutex_unlock(&kprobe_mutex); 2497 mutex_unlock(&kprobe_mutex);
2440 return; 2498 return ret;
2441} 2499}
2442 2500
2443static void disarm_all_kprobes(void) 2501static int disarm_all_kprobes(void)
2444{ 2502{
2445 struct hlist_head *head; 2503 struct hlist_head *head;
2446 struct kprobe *p; 2504 struct kprobe *p;
2447 unsigned int i; 2505 unsigned int i, total = 0, errors = 0;
2506 int err, ret = 0;
2448 2507
2449 mutex_lock(&kprobe_mutex); 2508 mutex_lock(&kprobe_mutex);
2450 2509
2451 /* If kprobes are already disarmed, just return */ 2510 /* If kprobes are already disarmed, just return */
2452 if (kprobes_all_disarmed) { 2511 if (kprobes_all_disarmed) {
2453 mutex_unlock(&kprobe_mutex); 2512 mutex_unlock(&kprobe_mutex);
2454 return; 2513 return 0;
2455 } 2514 }
2456 2515
2457 kprobes_all_disarmed = true; 2516 kprobes_all_disarmed = true;
2458 printk(KERN_INFO "Kprobes globally disabled\n");
2459 2517
2460 for (i = 0; i < KPROBE_TABLE_SIZE; i++) { 2518 for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
2461 head = &kprobe_table[i]; 2519 head = &kprobe_table[i];
2520 /* Disarm all kprobes on a best-effort basis */
2462 hlist_for_each_entry_rcu(p, head, hlist) { 2521 hlist_for_each_entry_rcu(p, head, hlist) {
2463 if (!arch_trampoline_kprobe(p) && !kprobe_disabled(p)) 2522 if (!arch_trampoline_kprobe(p) && !kprobe_disabled(p)) {
2464 disarm_kprobe(p, false); 2523 err = disarm_kprobe(p, false);
2524 if (err) {
2525 errors++;
2526 ret = err;
2527 }
2528 total++;
2529 }
2465 } 2530 }
2466 } 2531 }
2532
2533 if (errors)
2534 pr_warn("Kprobes globally disabled, but failed to disarm %d out of %d probes\n",
2535 errors, total);
2536 else
2537 pr_info("Kprobes globally disabled\n");
2538
2467 mutex_unlock(&kprobe_mutex); 2539 mutex_unlock(&kprobe_mutex);
2468 2540
2469 /* Wait for disarming all kprobes by optimizer */ 2541 /* Wait for disarming all kprobes by optimizer */
2470 wait_for_kprobe_optimizer(); 2542 wait_for_kprobe_optimizer();
2543
2544 return ret;
2471} 2545}
2472 2546
2473/* 2547/*
@@ -2494,6 +2568,7 @@ static ssize_t write_enabled_file_bool(struct file *file,
2494{ 2568{
2495 char buf[32]; 2569 char buf[32];
2496 size_t buf_size; 2570 size_t buf_size;
2571 int ret = 0;
2497 2572
2498 buf_size = min(count, (sizeof(buf)-1)); 2573 buf_size = min(count, (sizeof(buf)-1));
2499 if (copy_from_user(buf, user_buf, buf_size)) 2574 if (copy_from_user(buf, user_buf, buf_size))
@@ -2504,17 +2579,20 @@ static ssize_t write_enabled_file_bool(struct file *file,
2504 case 'y': 2579 case 'y':
2505 case 'Y': 2580 case 'Y':
2506 case '1': 2581 case '1':
2507 arm_all_kprobes(); 2582 ret = arm_all_kprobes();
2508 break; 2583 break;
2509 case 'n': 2584 case 'n':
2510 case 'N': 2585 case 'N':
2511 case '0': 2586 case '0':
2512 disarm_all_kprobes(); 2587 ret = disarm_all_kprobes();
2513 break; 2588 break;
2514 default: 2589 default:
2515 return -EINVAL; 2590 return -EINVAL;
2516 } 2591 }
2517 2592
2593 if (ret)
2594 return ret;
2595
2518 return count; 2596 return count;
2519} 2597}
2520 2598
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index 858a07590e39..2048359f33d2 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -1082,15 +1082,16 @@ static noinline int __sched
1082__mutex_lock_interruptible_slowpath(struct mutex *lock); 1082__mutex_lock_interruptible_slowpath(struct mutex *lock);
1083 1083
1084/** 1084/**
1085 * mutex_lock_interruptible - acquire the mutex, interruptible 1085 * mutex_lock_interruptible() - Acquire the mutex, interruptible by signals.
1086 * @lock: the mutex to be acquired 1086 * @lock: The mutex to be acquired.
1087 * 1087 *
1088 * Lock the mutex like mutex_lock(), and return 0 if the mutex has 1088 * Lock the mutex like mutex_lock(). If a signal is delivered while the
1089 * been acquired or sleep until the mutex becomes available. If a 1089 * process is sleeping, this function will return without acquiring the
1090 * signal arrives while waiting for the lock then this function 1090 * mutex.
1091 * returns -EINTR.
1092 * 1091 *
1093 * This function is similar to (but not equivalent to) down_interruptible(). 1092 * Context: Process context.
1093 * Return: 0 if the lock was successfully acquired or %-EINTR if a
1094 * signal arrived.
1094 */ 1095 */
1095int __sched mutex_lock_interruptible(struct mutex *lock) 1096int __sched mutex_lock_interruptible(struct mutex *lock)
1096{ 1097{
@@ -1104,6 +1105,18 @@ int __sched mutex_lock_interruptible(struct mutex *lock)
1104 1105
1105EXPORT_SYMBOL(mutex_lock_interruptible); 1106EXPORT_SYMBOL(mutex_lock_interruptible);
1106 1107
1108/**
1109 * mutex_lock_killable() - Acquire the mutex, interruptible by fatal signals.
1110 * @lock: The mutex to be acquired.
1111 *
1112 * Lock the mutex like mutex_lock(). If a signal which will be fatal to
1113 * the current process is delivered while the process is sleeping, this
1114 * function will return without acquiring the mutex.
1115 *
1116 * Context: Process context.
1117 * Return: 0 if the lock was successfully acquired or %-EINTR if a
1118 * fatal signal arrived.
1119 */
1107int __sched mutex_lock_killable(struct mutex *lock) 1120int __sched mutex_lock_killable(struct mutex *lock)
1108{ 1121{
1109 might_sleep(); 1122 might_sleep();
@@ -1115,6 +1128,16 @@ int __sched mutex_lock_killable(struct mutex *lock)
1115} 1128}
1116EXPORT_SYMBOL(mutex_lock_killable); 1129EXPORT_SYMBOL(mutex_lock_killable);
1117 1130
1131/**
1132 * mutex_lock_io() - Acquire the mutex and mark the process as waiting for I/O
1133 * @lock: The mutex to be acquired.
1134 *
1135 * Lock the mutex like mutex_lock(). While the task is waiting for this
1136 * mutex, it will be accounted as being in the IO wait state by the
1137 * scheduler.
1138 *
1139 * Context: Process context.
1140 */
1118void __sched mutex_lock_io(struct mutex *lock) 1141void __sched mutex_lock_io(struct mutex *lock)
1119{ 1142{
1120 int token; 1143 int token;
diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
index 38ece035039e..d880296245c5 100644
--- a/kernel/locking/qspinlock.c
+++ b/kernel/locking/qspinlock.c
@@ -379,6 +379,14 @@ queue:
379 tail = encode_tail(smp_processor_id(), idx); 379 tail = encode_tail(smp_processor_id(), idx);
380 380
381 node += idx; 381 node += idx;
382
383 /*
384 * Ensure that we increment the head node->count before initialising
385 * the actual node. If the compiler is kind enough to reorder these
386 * stores, then an IRQ could overwrite our assignments.
387 */
388 barrier();
389
382 node->locked = 0; 390 node->locked = 0;
383 node->next = NULL; 391 node->next = NULL;
384 pv_init_node(node); 392 pv_init_node(node);
@@ -408,14 +416,15 @@ queue:
408 */ 416 */
409 if (old & _Q_TAIL_MASK) { 417 if (old & _Q_TAIL_MASK) {
410 prev = decode_tail(old); 418 prev = decode_tail(old);
419
411 /* 420 /*
412 * The above xchg_tail() is also a load of @lock which 421 * We must ensure that the stores to @node are observed before
413 * generates, through decode_tail(), a pointer. The address 422 * the write to prev->next. The address dependency from
414 * dependency matches the RELEASE of xchg_tail() such that 423 * xchg_tail is not sufficient to ensure this because the read
415 * the subsequent access to @prev happens after. 424 * component of xchg_tail is unordered with respect to the
425 * initialisation of @node.
416 */ 426 */
417 427 smp_store_release(&prev->next, node);
418 WRITE_ONCE(prev->next, node);
419 428
420 pv_wait_node(node, prev); 429 pv_wait_node(node, prev);
421 arch_mcs_spin_lock_contended(&node->locked); 430 arch_mcs_spin_lock_contended(&node->locked);
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 65cc0cb984e6..940633c63254 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1616,11 +1616,12 @@ bool __sched __rt_mutex_futex_unlock(struct rt_mutex *lock,
1616void __sched rt_mutex_futex_unlock(struct rt_mutex *lock) 1616void __sched rt_mutex_futex_unlock(struct rt_mutex *lock)
1617{ 1617{
1618 DEFINE_WAKE_Q(wake_q); 1618 DEFINE_WAKE_Q(wake_q);
1619 unsigned long flags;
1619 bool postunlock; 1620 bool postunlock;
1620 1621
1621 raw_spin_lock_irq(&lock->wait_lock); 1622 raw_spin_lock_irqsave(&lock->wait_lock, flags);
1622 postunlock = __rt_mutex_futex_unlock(lock, &wake_q); 1623 postunlock = __rt_mutex_futex_unlock(lock, &wake_q);
1623 raw_spin_unlock_irq(&lock->wait_lock); 1624 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
1624 1625
1625 if (postunlock) 1626 if (postunlock)
1626 rt_mutex_postunlock(&wake_q); 1627 rt_mutex_postunlock(&wake_q);
diff --git a/kernel/memremap.c b/kernel/memremap.c
index 4849be5f9b3c..895e6b76b25e 100644
--- a/kernel/memremap.c
+++ b/kernel/memremap.c
@@ -275,8 +275,15 @@ static unsigned long pfn_end(struct dev_pagemap *pgmap)
275 return (res->start + resource_size(res)) >> PAGE_SHIFT; 275 return (res->start + resource_size(res)) >> PAGE_SHIFT;
276} 276}
277 277
278static unsigned long pfn_next(unsigned long pfn)
279{
280 if (pfn % 1024 == 0)
281 cond_resched();
282 return pfn + 1;
283}
284
278#define for_each_device_pfn(pfn, map) \ 285#define for_each_device_pfn(pfn, map) \
279 for (pfn = pfn_first(map); pfn < pfn_end(map); pfn++) 286 for (pfn = pfn_first(map); pfn < pfn_end(map); pfn = pfn_next(pfn))
280 287
281static void devm_memremap_pages_release(void *data) 288static void devm_memremap_pages_release(void *data)
282{ 289{
@@ -337,10 +344,10 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
337 resource_size_t align_start, align_size, align_end; 344 resource_size_t align_start, align_size, align_end;
338 struct vmem_altmap *altmap = pgmap->altmap_valid ? 345 struct vmem_altmap *altmap = pgmap->altmap_valid ?
339 &pgmap->altmap : NULL; 346 &pgmap->altmap : NULL;
347 struct resource *res = &pgmap->res;
340 unsigned long pfn, pgoff, order; 348 unsigned long pfn, pgoff, order;
341 pgprot_t pgprot = PAGE_KERNEL; 349 pgprot_t pgprot = PAGE_KERNEL;
342 int error, nid, is_ram, i = 0; 350 int error, nid, is_ram;
343 struct resource *res = &pgmap->res;
344 351
345 align_start = res->start & ~(SECTION_SIZE - 1); 352 align_start = res->start & ~(SECTION_SIZE - 1);
346 align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE) 353 align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE)
@@ -409,8 +416,6 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
409 list_del(&page->lru); 416 list_del(&page->lru);
410 page->pgmap = pgmap; 417 page->pgmap = pgmap;
411 percpu_ref_get(pgmap->ref); 418 percpu_ref_get(pgmap->ref);
412 if (!(++i % 1024))
413 cond_resched();
414 } 419 }
415 420
416 devm_add_action(dev, devm_memremap_pages_release, pgmap); 421 devm_add_action(dev, devm_memremap_pages_release, pgmap);
@@ -422,7 +427,6 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
422 err_pfn_remap: 427 err_pfn_remap:
423 err_radix: 428 err_radix:
424 pgmap_radix_release(res, pgoff); 429 pgmap_radix_release(res, pgoff);
425 devres_free(pgmap);
426 return ERR_PTR(error); 430 return ERR_PTR(error);
427} 431}
428EXPORT_SYMBOL(devm_memremap_pages); 432EXPORT_SYMBOL(devm_memremap_pages);
diff --git a/kernel/module.c b/kernel/module.c
index ad2d420024f6..e42764acedb4 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -4228,7 +4228,7 @@ static int modules_open(struct inode *inode, struct file *file)
4228 m->private = kallsyms_show_value() ? NULL : (void *)8ul; 4228 m->private = kallsyms_show_value() ? NULL : (void *)8ul;
4229 } 4229 }
4230 4230
4231 return 0; 4231 return err;
4232} 4232}
4233 4233
4234static const struct file_operations proc_modules_operations = { 4234static const struct file_operations proc_modules_operations = {
diff --git a/kernel/panic.c b/kernel/panic.c
index 2cfef408fec9..4b794f1d8561 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -640,7 +640,7 @@ device_initcall(register_warn_debugfs);
640 */ 640 */
641__visible void __stack_chk_fail(void) 641__visible void __stack_chk_fail(void)
642{ 642{
643 panic("stack-protector: Kernel stack is corrupted in: %p\n", 643 panic("stack-protector: Kernel stack is corrupted in: %pB\n",
644 __builtin_return_address(0)); 644 __builtin_return_address(0));
645} 645}
646EXPORT_SYMBOL(__stack_chk_fail); 646EXPORT_SYMBOL(__stack_chk_fail);
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fc1123583fa6..f274fbef821d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2397,7 +2397,7 @@ skip:
2397 2397
2398 if (console_lock_spinning_disable_and_check()) { 2398 if (console_lock_spinning_disable_and_check()) {
2399 printk_safe_exit_irqrestore(flags); 2399 printk_safe_exit_irqrestore(flags);
2400 return; 2400 goto out;
2401 } 2401 }
2402 2402
2403 printk_safe_exit_irqrestore(flags); 2403 printk_safe_exit_irqrestore(flags);
@@ -2430,6 +2430,7 @@ skip:
2430 if (retry && console_trylock()) 2430 if (retry && console_trylock())
2431 goto again; 2431 goto again;
2432 2432
2433out:
2433 if (wake_klogd) 2434 if (wake_klogd)
2434 wake_up_klogd(); 2435 wake_up_klogd();
2435} 2436}
diff --git a/kernel/relay.c b/kernel/relay.c
index c3029402f15c..c955b10c973c 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -163,7 +163,7 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan)
163{ 163{
164 struct rchan_buf *buf; 164 struct rchan_buf *buf;
165 165
166 if (chan->n_subbufs > UINT_MAX / sizeof(size_t *)) 166 if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t *))
167 return NULL; 167 return NULL;
168 168
169 buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL); 169 buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index bf724c1952ea..c94895bc5a2c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2601,19 +2601,31 @@ static inline void finish_task(struct task_struct *prev)
2601#endif 2601#endif
2602} 2602}
2603 2603
2604static inline void finish_lock_switch(struct rq *rq) 2604static inline void
2605prepare_lock_switch(struct rq *rq, struct task_struct *next, struct rq_flags *rf)
2605{ 2606{
2607 /*
2608 * Since the runqueue lock will be released by the next
2609 * task (which is an invalid locking op but in the case
2610 * of the scheduler it's an obvious special-case), so we
2611 * do an early lockdep release here:
2612 */
2613 rq_unpin_lock(rq, rf);
2614 spin_release(&rq->lock.dep_map, 1, _THIS_IP_);
2606#ifdef CONFIG_DEBUG_SPINLOCK 2615#ifdef CONFIG_DEBUG_SPINLOCK
2607 /* this is a valid case when another task releases the spinlock */ 2616 /* this is a valid case when another task releases the spinlock */
2608 rq->lock.owner = current; 2617 rq->lock.owner = next;
2609#endif 2618#endif
2619}
2620
2621static inline void finish_lock_switch(struct rq *rq)
2622{
2610 /* 2623 /*
2611 * If we are tracking spinlock dependencies then we have to 2624 * If we are tracking spinlock dependencies then we have to
2612 * fix up the runqueue lock - which gets 'carried over' from 2625 * fix up the runqueue lock - which gets 'carried over' from
2613 * prev into current: 2626 * prev into current:
2614 */ 2627 */
2615 spin_acquire(&rq->lock.dep_map, 0, 0, _THIS_IP_); 2628 spin_acquire(&rq->lock.dep_map, 0, 0, _THIS_IP_);
2616
2617 raw_spin_unlock_irq(&rq->lock); 2629 raw_spin_unlock_irq(&rq->lock);
2618} 2630}
2619 2631
@@ -2844,14 +2856,7 @@ context_switch(struct rq *rq, struct task_struct *prev,
2844 2856
2845 rq->clock_update_flags &= ~(RQCF_ACT_SKIP|RQCF_REQ_SKIP); 2857 rq->clock_update_flags &= ~(RQCF_ACT_SKIP|RQCF_REQ_SKIP);
2846 2858
2847 /* 2859 prepare_lock_switch(rq, next, rf);
2848 * Since the runqueue lock will be released by the next
2849 * task (which is an invalid locking op but in the case
2850 * of the scheduler it's an obvious special-case), so we
2851 * do an early lockdep release here:
2852 */
2853 rq_unpin_lock(rq, rf);
2854 spin_release(&rq->lock.dep_map, 1, _THIS_IP_);
2855 2860
2856 /* Here we just switch the register state and the stack. */ 2861 /* Here we just switch the register state and the stack. */
2857 switch_to(prev, next, prev); 2862 switch_to(prev, next, prev);
@@ -6678,13 +6683,18 @@ static int tg_cfs_schedulable_down(struct task_group *tg, void *data)
6678 parent_quota = parent_b->hierarchical_quota; 6683 parent_quota = parent_b->hierarchical_quota;
6679 6684
6680 /* 6685 /*
6681 * Ensure max(child_quota) <= parent_quota, inherit when no 6686 * Ensure max(child_quota) <= parent_quota. On cgroup2,
6687 * always take the min. On cgroup1, only inherit when no
6682 * limit is set: 6688 * limit is set:
6683 */ 6689 */
6684 if (quota == RUNTIME_INF) 6690 if (cgroup_subsys_on_dfl(cpu_cgrp_subsys)) {
6685 quota = parent_quota; 6691 quota = min(quota, parent_quota);
6686 else if (parent_quota != RUNTIME_INF && quota > parent_quota) 6692 } else {
6687 return -EINVAL; 6693 if (quota == RUNTIME_INF)
6694 quota = parent_quota;
6695 else if (parent_quota != RUNTIME_INF && quota > parent_quota)
6696 return -EINVAL;
6697 }
6688 } 6698 }
6689 cfs_b->hierarchical_quota = quota; 6699 cfs_b->hierarchical_quota = quota;
6690 6700
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index dd062a1c8cf0..7936f548e071 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -19,8 +19,6 @@
19 19
20#include "sched.h" 20#include "sched.h"
21 21
22#define SUGOV_KTHREAD_PRIORITY 50
23
24struct sugov_tunables { 22struct sugov_tunables {
25 struct gov_attr_set attr_set; 23 struct gov_attr_set attr_set;
26 unsigned int rate_limit_us; 24 unsigned int rate_limit_us;
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 9bb0e0c412ec..9df09782025c 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1153,6 +1153,7 @@ static void update_curr_dl(struct rq *rq)
1153 struct sched_dl_entity *dl_se = &curr->dl; 1153 struct sched_dl_entity *dl_se = &curr->dl;
1154 u64 delta_exec, scaled_delta_exec; 1154 u64 delta_exec, scaled_delta_exec;
1155 int cpu = cpu_of(rq); 1155 int cpu = cpu_of(rq);
1156 u64 now;
1156 1157
1157 if (!dl_task(curr) || !on_dl_rq(dl_se)) 1158 if (!dl_task(curr) || !on_dl_rq(dl_se))
1158 return; 1159 return;
@@ -1165,7 +1166,8 @@ static void update_curr_dl(struct rq *rq)
1165 * natural solution, but the full ramifications of this 1166 * natural solution, but the full ramifications of this
1166 * approach need further study. 1167 * approach need further study.
1167 */ 1168 */
1168 delta_exec = rq_clock_task(rq) - curr->se.exec_start; 1169 now = rq_clock_task(rq);
1170 delta_exec = now - curr->se.exec_start;
1169 if (unlikely((s64)delta_exec <= 0)) { 1171 if (unlikely((s64)delta_exec <= 0)) {
1170 if (unlikely(dl_se->dl_yielded)) 1172 if (unlikely(dl_se->dl_yielded))
1171 goto throttle; 1173 goto throttle;
@@ -1178,7 +1180,7 @@ static void update_curr_dl(struct rq *rq)
1178 curr->se.sum_exec_runtime += delta_exec; 1180 curr->se.sum_exec_runtime += delta_exec;
1179 account_group_exec_runtime(curr, delta_exec); 1181 account_group_exec_runtime(curr, delta_exec);
1180 1182
1181 curr->se.exec_start = rq_clock_task(rq); 1183 curr->se.exec_start = now;
1182 cgroup_account_cputime(curr, delta_exec); 1184 cgroup_account_cputime(curr, delta_exec);
1183 1185
1184 sched_rt_avg_update(rq, delta_exec); 1186 sched_rt_avg_update(rq, delta_exec);
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 1ca0130ed4f9..72c401b3b15c 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -32,7 +32,7 @@ static DEFINE_SPINLOCK(sched_debug_lock);
32 if (m) \ 32 if (m) \
33 seq_printf(m, x); \ 33 seq_printf(m, x); \
34 else \ 34 else \
35 printk(x); \ 35 pr_cont(x); \
36 } while (0) 36 } while (0)
37 37
38/* 38/*
@@ -501,12 +501,12 @@ static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
501{ 501{
502 struct task_struct *g, *p; 502 struct task_struct *g, *p;
503 503
504 SEQ_printf(m, 504 SEQ_printf(m, "\n");
505 "\nrunnable tasks:\n" 505 SEQ_printf(m, "runnable tasks:\n");
506 " S task PID tree-key switches prio" 506 SEQ_printf(m, " S task PID tree-key switches prio"
507 " wait-time sum-exec sum-sleep\n" 507 " wait-time sum-exec sum-sleep\n");
508 "-------------------------------------------------------" 508 SEQ_printf(m, "-------------------------------------------------------"
509 "----------------------------------------------------\n"); 509 "----------------------------------------------------\n");
510 510
511 rcu_read_lock(); 511 rcu_read_lock();
512 for_each_process_thread(g, p) { 512 for_each_process_thread(g, p) {
@@ -527,9 +527,11 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
527 unsigned long flags; 527 unsigned long flags;
528 528
529#ifdef CONFIG_FAIR_GROUP_SCHED 529#ifdef CONFIG_FAIR_GROUP_SCHED
530 SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg)); 530 SEQ_printf(m, "\n");
531 SEQ_printf(m, "cfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
531#else 532#else
532 SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu); 533 SEQ_printf(m, "\n");
534 SEQ_printf(m, "cfs_rq[%d]:\n", cpu);
533#endif 535#endif
534 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock", 536 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock",
535 SPLIT_NS(cfs_rq->exec_clock)); 537 SPLIT_NS(cfs_rq->exec_clock));
@@ -595,9 +597,11 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
595void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq) 597void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
596{ 598{
597#ifdef CONFIG_RT_GROUP_SCHED 599#ifdef CONFIG_RT_GROUP_SCHED
598 SEQ_printf(m, "\nrt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg)); 600 SEQ_printf(m, "\n");
601 SEQ_printf(m, "rt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg));
599#else 602#else
600 SEQ_printf(m, "\nrt_rq[%d]:\n", cpu); 603 SEQ_printf(m, "\n");
604 SEQ_printf(m, "rt_rq[%d]:\n", cpu);
601#endif 605#endif
602 606
603#define P(x) \ 607#define P(x) \
@@ -624,7 +628,8 @@ void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq)
624{ 628{
625 struct dl_bw *dl_bw; 629 struct dl_bw *dl_bw;
626 630
627 SEQ_printf(m, "\ndl_rq[%d]:\n", cpu); 631 SEQ_printf(m, "\n");
632 SEQ_printf(m, "dl_rq[%d]:\n", cpu);
628 633
629#define PU(x) \ 634#define PU(x) \
630 SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(dl_rq->x)) 635 SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(dl_rq->x))
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 663b2355a3aa..aad49451584e 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -950,12 +950,13 @@ static void update_curr_rt(struct rq *rq)
950{ 950{
951 struct task_struct *curr = rq->curr; 951 struct task_struct *curr = rq->curr;
952 struct sched_rt_entity *rt_se = &curr->rt; 952 struct sched_rt_entity *rt_se = &curr->rt;
953 u64 now = rq_clock_task(rq);
954 u64 delta_exec; 953 u64 delta_exec;
954 u64 now;
955 955
956 if (curr->sched_class != &rt_sched_class) 956 if (curr->sched_class != &rt_sched_class)
957 return; 957 return;
958 958
959 now = rq_clock_task(rq);
959 delta_exec = now - curr->se.exec_start; 960 delta_exec = now - curr->se.exec_start;
960 if (unlikely((s64)delta_exec <= 0)) 961 if (unlikely((s64)delta_exec <= 0))
961 return; 962 return;
diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 940fa408a288..dc77548167ef 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -1076,14 +1076,16 @@ long seccomp_get_metadata(struct task_struct *task,
1076 1076
1077 size = min_t(unsigned long, size, sizeof(kmd)); 1077 size = min_t(unsigned long, size, sizeof(kmd));
1078 1078
1079 if (copy_from_user(&kmd, data, size)) 1079 if (size < sizeof(kmd.filter_off))
1080 return -EINVAL;
1081
1082 if (copy_from_user(&kmd.filter_off, data, sizeof(kmd.filter_off)))
1080 return -EFAULT; 1083 return -EFAULT;
1081 1084
1082 filter = get_nth_filter(task, kmd.filter_off); 1085 filter = get_nth_filter(task, kmd.filter_off);
1083 if (IS_ERR(filter)) 1086 if (IS_ERR(filter))
1084 return PTR_ERR(filter); 1087 return PTR_ERR(filter);
1085 1088
1086 memset(&kmd, 0, sizeof(kmd));
1087 if (filter->log) 1089 if (filter->log)
1088 kmd.flags |= SECCOMP_FILTER_FLAG_LOG; 1090 kmd.flags |= SECCOMP_FILTER_FLAG_LOG;
1089 1091
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 75043046914e..10b7186d0638 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -50,6 +50,7 @@
50#include <linux/export.h> 50#include <linux/export.h>
51#include <linux/hashtable.h> 51#include <linux/hashtable.h>
52#include <linux/compat.h> 52#include <linux/compat.h>
53#include <linux/nospec.h>
53 54
54#include "timekeeping.h" 55#include "timekeeping.h"
55#include "posix-timers.h" 56#include "posix-timers.h"
@@ -1346,11 +1347,15 @@ static const struct k_clock * const posix_clocks[] = {
1346 1347
1347static const struct k_clock *clockid_to_kclock(const clockid_t id) 1348static const struct k_clock *clockid_to_kclock(const clockid_t id)
1348{ 1349{
1349 if (id < 0) 1350 clockid_t idx = id;
1351
1352 if (id < 0) {
1350 return (id & CLOCKFD_MASK) == CLOCKFD ? 1353 return (id & CLOCKFD_MASK) == CLOCKFD ?
1351 &clock_posix_dynamic : &clock_posix_cpu; 1354 &clock_posix_dynamic : &clock_posix_cpu;
1355 }
1352 1356
1353 if (id >= ARRAY_SIZE(posix_clocks) || !posix_clocks[id]) 1357 if (id >= ARRAY_SIZE(posix_clocks))
1354 return NULL; 1358 return NULL;
1355 return posix_clocks[id]; 1359
1360 return posix_clocks[array_index_nospec(idx, ARRAY_SIZE(posix_clocks))];
1356} 1361}
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 48150ab42de9..4a4fd567fb26 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1894,6 +1894,12 @@ int timers_dead_cpu(unsigned int cpu)
1894 raw_spin_lock_irq(&new_base->lock); 1894 raw_spin_lock_irq(&new_base->lock);
1895 raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); 1895 raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
1896 1896
1897 /*
1898 * The current CPUs base clock might be stale. Update it
1899 * before moving the timers over.
1900 */
1901 forward_timer_base(new_base);
1902
1897 BUG_ON(old_base->running_timer); 1903 BUG_ON(old_base->running_timer);
1898 1904
1899 for (i = 0; i < WHEEL_SIZE; i++) 1905 for (i = 0; i < WHEEL_SIZE; i++)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index fc2838ac8b78..01e6b3a38871 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -661,7 +661,41 @@ static const struct bpf_func_proto bpf_get_stackid_proto_tp = {
661 .arg3_type = ARG_ANYTHING, 661 .arg3_type = ARG_ANYTHING,
662}; 662};
663 663
664BPF_CALL_3(bpf_perf_prog_read_value_tp, struct bpf_perf_event_data_kern *, ctx, 664static const struct bpf_func_proto *tp_prog_func_proto(enum bpf_func_id func_id)
665{
666 switch (func_id) {
667 case BPF_FUNC_perf_event_output:
668 return &bpf_perf_event_output_proto_tp;
669 case BPF_FUNC_get_stackid:
670 return &bpf_get_stackid_proto_tp;
671 default:
672 return tracing_func_proto(func_id);
673 }
674}
675
676static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type,
677 struct bpf_insn_access_aux *info)
678{
679 if (off < sizeof(void *) || off >= PERF_MAX_TRACE_SIZE)
680 return false;
681 if (type != BPF_READ)
682 return false;
683 if (off % size != 0)
684 return false;
685
686 BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(__u64));
687 return true;
688}
689
690const struct bpf_verifier_ops tracepoint_verifier_ops = {
691 .get_func_proto = tp_prog_func_proto,
692 .is_valid_access = tp_prog_is_valid_access,
693};
694
695const struct bpf_prog_ops tracepoint_prog_ops = {
696};
697
698BPF_CALL_3(bpf_perf_prog_read_value, struct bpf_perf_event_data_kern *, ctx,
665 struct bpf_perf_event_value *, buf, u32, size) 699 struct bpf_perf_event_value *, buf, u32, size)
666{ 700{
667 int err = -EINVAL; 701 int err = -EINVAL;
@@ -678,8 +712,8 @@ clear:
678 return err; 712 return err;
679} 713}
680 714
681static const struct bpf_func_proto bpf_perf_prog_read_value_proto_tp = { 715static const struct bpf_func_proto bpf_perf_prog_read_value_proto = {
682 .func = bpf_perf_prog_read_value_tp, 716 .func = bpf_perf_prog_read_value,
683 .gpl_only = true, 717 .gpl_only = true,
684 .ret_type = RET_INTEGER, 718 .ret_type = RET_INTEGER,
685 .arg1_type = ARG_PTR_TO_CTX, 719 .arg1_type = ARG_PTR_TO_CTX,
@@ -687,7 +721,7 @@ static const struct bpf_func_proto bpf_perf_prog_read_value_proto_tp = {
687 .arg3_type = ARG_CONST_SIZE, 721 .arg3_type = ARG_CONST_SIZE,
688}; 722};
689 723
690static const struct bpf_func_proto *tp_prog_func_proto(enum bpf_func_id func_id) 724static const struct bpf_func_proto *pe_prog_func_proto(enum bpf_func_id func_id)
691{ 725{
692 switch (func_id) { 726 switch (func_id) {
693 case BPF_FUNC_perf_event_output: 727 case BPF_FUNC_perf_event_output:
@@ -695,34 +729,12 @@ static const struct bpf_func_proto *tp_prog_func_proto(enum bpf_func_id func_id)
695 case BPF_FUNC_get_stackid: 729 case BPF_FUNC_get_stackid:
696 return &bpf_get_stackid_proto_tp; 730 return &bpf_get_stackid_proto_tp;
697 case BPF_FUNC_perf_prog_read_value: 731 case BPF_FUNC_perf_prog_read_value:
698 return &bpf_perf_prog_read_value_proto_tp; 732 return &bpf_perf_prog_read_value_proto;
699 default: 733 default:
700 return tracing_func_proto(func_id); 734 return tracing_func_proto(func_id);
701 } 735 }
702} 736}
703 737
704static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type,
705 struct bpf_insn_access_aux *info)
706{
707 if (off < sizeof(void *) || off >= PERF_MAX_TRACE_SIZE)
708 return false;
709 if (type != BPF_READ)
710 return false;
711 if (off % size != 0)
712 return false;
713
714 BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(__u64));
715 return true;
716}
717
718const struct bpf_verifier_ops tracepoint_verifier_ops = {
719 .get_func_proto = tp_prog_func_proto,
720 .is_valid_access = tp_prog_is_valid_access,
721};
722
723const struct bpf_prog_ops tracepoint_prog_ops = {
724};
725
726static bool pe_prog_is_valid_access(int off, int size, enum bpf_access_type type, 738static bool pe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
727 struct bpf_insn_access_aux *info) 739 struct bpf_insn_access_aux *info)
728{ 740{
@@ -779,7 +791,7 @@ static u32 pe_prog_convert_ctx_access(enum bpf_access_type type,
779} 791}
780 792
781const struct bpf_verifier_ops perf_event_verifier_ops = { 793const struct bpf_verifier_ops perf_event_verifier_ops = {
782 .get_func_proto = tp_prog_func_proto, 794 .get_func_proto = pe_prog_func_proto,
783 .is_valid_access = pe_prog_is_valid_access, 795 .is_valid_access = pe_prog_is_valid_access,
784 .convert_ctx_access = pe_prog_convert_ctx_access, 796 .convert_ctx_access = pe_prog_convert_ctx_access,
785}; 797};
@@ -872,6 +884,8 @@ int perf_event_query_prog_array(struct perf_event *event, void __user *info)
872 return -EINVAL; 884 return -EINVAL;
873 if (copy_from_user(&query, uquery, sizeof(query))) 885 if (copy_from_user(&query, uquery, sizeof(query)))
874 return -EFAULT; 886 return -EFAULT;
887 if (query.ids_len > BPF_TRACE_MAX_PROGS)
888 return -E2BIG;
875 889
876 mutex_lock(&bpf_event_mutex); 890 mutex_lock(&bpf_event_mutex);
877 ret = bpf_prog_array_copy_info(event->tp_event->prog_array, 891 ret = bpf_prog_array_copy_info(event->tp_event->prog_array,
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 1fad24acd444..ae4147eaebd4 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -659,7 +659,7 @@ static int create_trace_kprobe(int argc, char **argv)
659 char *symbol = NULL, *event = NULL, *group = NULL; 659 char *symbol = NULL, *event = NULL, *group = NULL;
660 int maxactive = 0; 660 int maxactive = 0;
661 char *arg; 661 char *arg;
662 unsigned long offset = 0; 662 long offset = 0;
663 void *addr = NULL; 663 void *addr = NULL;
664 char buf[MAX_EVENT_NAME_LEN]; 664 char buf[MAX_EVENT_NAME_LEN];
665 665
@@ -747,7 +747,7 @@ static int create_trace_kprobe(int argc, char **argv)
747 symbol = argv[1]; 747 symbol = argv[1];
748 /* TODO: support .init module functions */ 748 /* TODO: support .init module functions */
749 ret = traceprobe_split_symbol_offset(symbol, &offset); 749 ret = traceprobe_split_symbol_offset(symbol, &offset);
750 if (ret) { 750 if (ret || offset < 0 || offset > UINT_MAX) {
751 pr_info("Failed to parse either an address or a symbol.\n"); 751 pr_info("Failed to parse either an address or a symbol.\n");
752 return ret; 752 return ret;
753 } 753 }
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index d59357308677..daf54bda4dc8 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -320,7 +320,7 @@ static fetch_func_t get_fetch_size_function(const struct fetch_type *type,
320} 320}
321 321
322/* Split symbol and offset. */ 322/* Split symbol and offset. */
323int traceprobe_split_symbol_offset(char *symbol, unsigned long *offset) 323int traceprobe_split_symbol_offset(char *symbol, long *offset)
324{ 324{
325 char *tmp; 325 char *tmp;
326 int ret; 326 int ret;
@@ -328,13 +328,11 @@ int traceprobe_split_symbol_offset(char *symbol, unsigned long *offset)
328 if (!offset) 328 if (!offset)
329 return -EINVAL; 329 return -EINVAL;
330 330
331 tmp = strchr(symbol, '+'); 331 tmp = strpbrk(symbol, "+-");
332 if (tmp) { 332 if (tmp) {
333 /* skip sign because kstrtoul doesn't accept '+' */ 333 ret = kstrtol(tmp, 0, offset);
334 ret = kstrtoul(tmp + 1, 0, offset);
335 if (ret) 334 if (ret)
336 return ret; 335 return ret;
337
338 *tmp = '\0'; 336 *tmp = '\0';
339 } else 337 } else
340 *offset = 0; 338 *offset = 0;
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index e101c5bb9eda..6a4d3fa94042 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -365,7 +365,7 @@ extern int traceprobe_conflict_field_name(const char *name,
365extern void traceprobe_update_arg(struct probe_arg *arg); 365extern void traceprobe_update_arg(struct probe_arg *arg);
366extern void traceprobe_free_probe_arg(struct probe_arg *arg); 366extern void traceprobe_free_probe_arg(struct probe_arg *arg);
367 367
368extern int traceprobe_split_symbol_offset(char *symbol, unsigned long *offset); 368extern int traceprobe_split_symbol_offset(char *symbol, long *offset);
369 369
370/* Sum up total data length for dynamic arraies (strings) */ 370/* Sum up total data length for dynamic arraies (strings) */
371static nokprobe_inline int 371static nokprobe_inline int
diff --git a/kernel/user.c b/kernel/user.c
index 9a20acce460d..36288d840675 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -101,6 +101,7 @@ struct user_struct root_user = {
101 .sigpending = ATOMIC_INIT(0), 101 .sigpending = ATOMIC_INIT(0),
102 .locked_shm = 0, 102 .locked_shm = 0,
103 .uid = GLOBAL_ROOT_UID, 103 .uid = GLOBAL_ROOT_UID,
104 .ratelimit = RATELIMIT_STATE_INIT(root_user.ratelimit, 0, 0),
104}; 105};
105 106
106/* 107/*
@@ -191,6 +192,8 @@ struct user_struct *alloc_uid(kuid_t uid)
191 192
192 new->uid = uid; 193 new->uid = uid;
193 atomic_set(&new->__count, 1); 194 atomic_set(&new->__count, 1);
195 ratelimit_state_init(&new->ratelimit, HZ, 100);
196 ratelimit_set_flags(&new->ratelimit, RATELIMIT_MSG_ON_RELEASE);
194 197
195 /* 198 /*
196 * Before adding this, check whether we raced 199 * Before adding this, check whether we raced
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 017044c26233..6ec6ba65127b 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3018,14 +3018,6 @@ static bool __cancel_work(struct work_struct *work, bool is_dwork)
3018 return ret; 3018 return ret;
3019} 3019}
3020 3020
3021/*
3022 * See cancel_delayed_work()
3023 */
3024bool cancel_work(struct work_struct *work)
3025{
3026 return __cancel_work(work, false);
3027}
3028
3029/** 3021/**
3030 * cancel_delayed_work - cancel a delayed work 3022 * cancel_delayed_work - cancel a delayed work
3031 * @dwork: delayed_work to cancel 3023 * @dwork: delayed_work to cancel
@@ -4180,6 +4172,22 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
4180EXPORT_SYMBOL_GPL(workqueue_set_max_active); 4172EXPORT_SYMBOL_GPL(workqueue_set_max_active);
4181 4173
4182/** 4174/**
4175 * current_work - retrieve %current task's work struct
4176 *
4177 * Determine if %current task is a workqueue worker and what it's working on.
4178 * Useful to find out the context that the %current task is running in.
4179 *
4180 * Return: work struct if %current task is a workqueue worker, %NULL otherwise.
4181 */
4182struct work_struct *current_work(void)
4183{
4184 struct worker *worker = current_wq_worker();
4185
4186 return worker ? worker->current_work : NULL;
4187}
4188EXPORT_SYMBOL(current_work);
4189
4190/**
4183 * current_is_workqueue_rescuer - is %current workqueue rescuer? 4191 * current_is_workqueue_rescuer - is %current workqueue rescuer?
4184 * 4192 *
4185 * Determine whether %current is a workqueue rescuer. Can be used from 4193 * Determine whether %current is a workqueue rescuer. Can be used from
@@ -5321,7 +5329,7 @@ int workqueue_sysfs_register(struct workqueue_struct *wq)
5321 5329
5322 ret = device_register(&wq_dev->dev); 5330 ret = device_register(&wq_dev->dev);
5323 if (ret) { 5331 if (ret) {
5324 kfree(wq_dev); 5332 put_device(&wq_dev->dev);
5325 wq->wq_dev = NULL; 5333 wq->wq_dev = NULL;
5326 return ret; 5334 return ret;
5327 } 5335 }
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 6088408ef26c..64155e310a9f 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1642,6 +1642,7 @@ config DMA_API_DEBUG
1642 1642
1643menuconfig RUNTIME_TESTING_MENU 1643menuconfig RUNTIME_TESTING_MENU
1644 bool "Runtime Testing" 1644 bool "Runtime Testing"
1645 def_bool y
1645 1646
1646if RUNTIME_TESTING_MENU 1647if RUNTIME_TESTING_MENU
1647 1648
diff --git a/lib/btree.c b/lib/btree.c
index f93a945274af..590facba2c50 100644
--- a/lib/btree.c
+++ b/lib/btree.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * As should be obvious for Linux kernel code, license is GPLv2 4 * As should be obvious for Linux kernel code, license is GPLv2
5 * 5 *
6 * Copyright (c) 2007-2008 Joern Engel <joern@logfs.org> 6 * Copyright (c) 2007-2008 Joern Engel <joern@purestorage.com>
7 * Bits and pieces stolen from Peter Zijlstra's code, which is 7 * Bits and pieces stolen from Peter Zijlstra's code, which is
8 * Copyright 2007, Red Hat Inc. Peter Zijlstra 8 * Copyright 2007, Red Hat Inc. Peter Zijlstra
9 * GPLv2 9 * GPLv2
@@ -76,6 +76,8 @@ struct btree_geo btree_geo128 = {
76}; 76};
77EXPORT_SYMBOL_GPL(btree_geo128); 77EXPORT_SYMBOL_GPL(btree_geo128);
78 78
79#define MAX_KEYLEN (2 * LONG_PER_U64)
80
79static struct kmem_cache *btree_cachep; 81static struct kmem_cache *btree_cachep;
80 82
81void *btree_alloc(gfp_t gfp_mask, void *pool_data) 83void *btree_alloc(gfp_t gfp_mask, void *pool_data)
@@ -313,7 +315,7 @@ void *btree_get_prev(struct btree_head *head, struct btree_geo *geo,
313{ 315{
314 int i, height; 316 int i, height;
315 unsigned long *node, *oldnode; 317 unsigned long *node, *oldnode;
316 unsigned long *retry_key = NULL, key[geo->keylen]; 318 unsigned long *retry_key = NULL, key[MAX_KEYLEN];
317 319
318 if (keyzero(geo, __key)) 320 if (keyzero(geo, __key))
319 return NULL; 321 return NULL;
@@ -639,8 +641,8 @@ EXPORT_SYMBOL_GPL(btree_remove);
639int btree_merge(struct btree_head *target, struct btree_head *victim, 641int btree_merge(struct btree_head *target, struct btree_head *victim,
640 struct btree_geo *geo, gfp_t gfp) 642 struct btree_geo *geo, gfp_t gfp)
641{ 643{
642 unsigned long key[geo->keylen]; 644 unsigned long key[MAX_KEYLEN];
643 unsigned long dup[geo->keylen]; 645 unsigned long dup[MAX_KEYLEN];
644 void *val; 646 void *val;
645 int err; 647 int err;
646 648
diff --git a/lib/bug.c b/lib/bug.c
index c1b0fad31b10..1077366f496b 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -150,6 +150,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
150 return BUG_TRAP_TYPE_NONE; 150 return BUG_TRAP_TYPE_NONE;
151 151
152 bug = find_bug(bugaddr); 152 bug = find_bug(bugaddr);
153 if (!bug)
154 return BUG_TRAP_TYPE_NONE;
153 155
154 file = NULL; 156 file = NULL;
155 line = 0; 157 line = 0;
@@ -191,7 +193,7 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
191 if (file) 193 if (file)
192 pr_crit("kernel BUG at %s:%u!\n", file, line); 194 pr_crit("kernel BUG at %s:%u!\n", file, line);
193 else 195 else
194 pr_crit("Kernel BUG at %p [verbose debug info unavailable]\n", 196 pr_crit("Kernel BUG at %pB [verbose debug info unavailable]\n",
195 (void *)bugaddr); 197 (void *)bugaddr);
196 198
197 return BUG_TRAP_TYPE_BUG; 199 return BUG_TRAP_TYPE_BUG;
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 1b34d210452c..7f5cdc1e6b29 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -1491,12 +1491,12 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size,
1491 if (unlikely(virt == NULL)) 1491 if (unlikely(virt == NULL))
1492 return; 1492 return;
1493 1493
1494 entry = dma_entry_alloc(); 1494 /* handle vmalloc and linear addresses */
1495 if (!entry) 1495 if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
1496 return; 1496 return;
1497 1497
1498 /* handle vmalloc and linear addresses */ 1498 entry = dma_entry_alloc();
1499 if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) 1499 if (!entry)
1500 return; 1500 return;
1501 1501
1502 entry->type = dma_debug_coherent; 1502 entry->type = dma_debug_coherent;
@@ -1528,7 +1528,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size,
1528 }; 1528 };
1529 1529
1530 /* handle vmalloc and linear addresses */ 1530 /* handle vmalloc and linear addresses */
1531 if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) 1531 if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
1532 return; 1532 return;
1533 1533
1534 if (is_vmalloc_addr(virt)) 1534 if (is_vmalloc_addr(virt))
diff --git a/lib/dma-direct.c b/lib/dma-direct.c
index 40b1f92f2214..c9e8e21cb334 100644
--- a/lib/dma-direct.c
+++ b/lib/dma-direct.c
@@ -84,6 +84,10 @@ again:
84 return page_address(page); 84 return page_address(page);
85} 85}
86 86
87/*
88 * NOTE: this function must never look at the dma_addr argument, because we want
89 * to be able to use it as a helper for iommu implementations as well.
90 */
87void dma_direct_free(struct device *dev, size_t size, void *cpu_addr, 91void dma_direct_free(struct device *dev, size_t size, void *cpu_addr,
88 dma_addr_t dma_addr, unsigned long attrs) 92 dma_addr_t dma_addr, unsigned long attrs)
89{ 93{
@@ -152,5 +156,6 @@ const struct dma_map_ops dma_direct_ops = {
152 .map_sg = dma_direct_map_sg, 156 .map_sg = dma_direct_map_sg,
153 .dma_supported = dma_direct_supported, 157 .dma_supported = dma_direct_supported,
154 .mapping_error = dma_direct_mapping_error, 158 .mapping_error = dma_direct_mapping_error,
159 .is_phys = 1,
155}; 160};
156EXPORT_SYMBOL(dma_direct_ops); 161EXPORT_SYMBOL(dma_direct_ops);
diff --git a/lib/idr.c b/lib/idr.c
index c98d77fcf393..823b813f08f8 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -36,8 +36,8 @@ int idr_alloc_u32(struct idr *idr, void *ptr, u32 *nextid,
36{ 36{
37 struct radix_tree_iter iter; 37 struct radix_tree_iter iter;
38 void __rcu **slot; 38 void __rcu **slot;
39 int base = idr->idr_base; 39 unsigned int base = idr->idr_base;
40 int id = *nextid; 40 unsigned int id = *nextid;
41 41
42 if (WARN_ON_ONCE(radix_tree_is_internal_node(ptr))) 42 if (WARN_ON_ONCE(radix_tree_is_internal_node(ptr)))
43 return -EINVAL; 43 return -EINVAL;
@@ -204,10 +204,11 @@ int idr_for_each(const struct idr *idr,
204 204
205 radix_tree_for_each_slot(slot, &idr->idr_rt, &iter, 0) { 205 radix_tree_for_each_slot(slot, &idr->idr_rt, &iter, 0) {
206 int ret; 206 int ret;
207 unsigned long id = iter.index + base;
207 208
208 if (WARN_ON_ONCE(iter.index > INT_MAX)) 209 if (WARN_ON_ONCE(id > INT_MAX))
209 break; 210 break;
210 ret = fn(iter.index + base, rcu_dereference_raw(*slot), data); 211 ret = fn(id, rcu_dereference_raw(*slot), data);
211 if (ret) 212 if (ret)
212 return ret; 213 return ret;
213 } 214 }
@@ -230,8 +231,8 @@ void *idr_get_next(struct idr *idr, int *nextid)
230{ 231{
231 struct radix_tree_iter iter; 232 struct radix_tree_iter iter;
232 void __rcu **slot; 233 void __rcu **slot;
233 int base = idr->idr_base; 234 unsigned long base = idr->idr_base;
234 int id = *nextid; 235 unsigned long id = *nextid;
235 236
236 id = (id < base) ? 0 : id - base; 237 id = (id < base) ? 0 : id - base;
237 slot = radix_tree_iter_find(&idr->idr_rt, &iter, id); 238 slot = radix_tree_iter_find(&idr->idr_rt, &iter, id);
@@ -431,7 +432,6 @@ int ida_get_new_above(struct ida *ida, int start, int *id)
431 bitmap = this_cpu_xchg(ida_bitmap, NULL); 432 bitmap = this_cpu_xchg(ida_bitmap, NULL);
432 if (!bitmap) 433 if (!bitmap)
433 return -EAGAIN; 434 return -EAGAIN;
434 memset(bitmap, 0, sizeof(*bitmap));
435 bitmap->bitmap[0] = tmp >> RADIX_TREE_EXCEPTIONAL_SHIFT; 435 bitmap->bitmap[0] = tmp >> RADIX_TREE_EXCEPTIONAL_SHIFT;
436 rcu_assign_pointer(*slot, bitmap); 436 rcu_assign_pointer(*slot, bitmap);
437 } 437 }
@@ -464,7 +464,6 @@ int ida_get_new_above(struct ida *ida, int start, int *id)
464 bitmap = this_cpu_xchg(ida_bitmap, NULL); 464 bitmap = this_cpu_xchg(ida_bitmap, NULL);
465 if (!bitmap) 465 if (!bitmap)
466 return -EAGAIN; 466 return -EAGAIN;
467 memset(bitmap, 0, sizeof(*bitmap));
468 __set_bit(bit, bitmap->bitmap); 467 __set_bit(bit, bitmap->bitmap);
469 radix_tree_iter_replace(root, &iter, slot, bitmap); 468 radix_tree_iter_replace(root, &iter, slot, bitmap);
470 } 469 }
diff --git a/lib/ioremap.c b/lib/ioremap.c
index b808a390e4c3..54e5bbaa3200 100644
--- a/lib/ioremap.c
+++ b/lib/ioremap.c
@@ -91,7 +91,8 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91 91
92 if (ioremap_pmd_enabled() && 92 if (ioremap_pmd_enabled() &&
93 ((next - addr) == PMD_SIZE) && 93 ((next - addr) == PMD_SIZE) &&
94 IS_ALIGNED(phys_addr + addr, PMD_SIZE)) { 94 IS_ALIGNED(phys_addr + addr, PMD_SIZE) &&
95 pmd_free_pte_page(pmd)) {
95 if (pmd_set_huge(pmd, phys_addr + addr, prot)) 96 if (pmd_set_huge(pmd, phys_addr + addr, prot))
96 continue; 97 continue;
97 } 98 }
@@ -117,7 +118,8 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr,
117 118
118 if (ioremap_pud_enabled() && 119 if (ioremap_pud_enabled() &&
119 ((next - addr) == PUD_SIZE) && 120 ((next - addr) == PUD_SIZE) &&
120 IS_ALIGNED(phys_addr + addr, PUD_SIZE)) { 121 IS_ALIGNED(phys_addr + addr, PUD_SIZE) &&
122 pud_free_pmd_page(pud)) {
121 if (pud_set_huge(pud, phys_addr + addr, prot)) 123 if (pud_set_huge(pud, phys_addr + addr, prot))
122 continue; 124 continue;
123 } 125 }
diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index 30e7dd88148b..9f96fa7bc000 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -322,6 +322,8 @@ EXPORT_SYMBOL_GPL(percpu_ref_switch_to_percpu);
322 * This function normally doesn't block and can be called from any context 322 * This function normally doesn't block and can be called from any context
323 * but it may block if @confirm_kill is specified and @ref is in the 323 * but it may block if @confirm_kill is specified and @ref is in the
324 * process of switching to atomic mode by percpu_ref_switch_to_atomic(). 324 * process of switching to atomic mode by percpu_ref_switch_to_atomic().
325 *
326 * There are no implied RCU grace periods between kill and release.
325 */ 327 */
326void percpu_ref_kill_and_confirm(struct percpu_ref *ref, 328void percpu_ref_kill_and_confirm(struct percpu_ref *ref,
327 percpu_ref_func_t *confirm_kill) 329 percpu_ref_func_t *confirm_kill)
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 0a7ae3288a24..8e00138d593f 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -2125,7 +2125,7 @@ int ida_pre_get(struct ida *ida, gfp_t gfp)
2125 preempt_enable(); 2125 preempt_enable();
2126 2126
2127 if (!this_cpu_read(ida_bitmap)) { 2127 if (!this_cpu_read(ida_bitmap)) {
2128 struct ida_bitmap *bitmap = kmalloc(sizeof(*bitmap), gfp); 2128 struct ida_bitmap *bitmap = kzalloc(sizeof(*bitmap), gfp);
2129 if (!bitmap) 2129 if (!bitmap)
2130 return 0; 2130 return 0;
2131 if (this_cpu_cmpxchg(ida_bitmap, NULL, bitmap)) 2131 if (this_cpu_cmpxchg(ida_bitmap, NULL, bitmap))
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 3825c30aaa36..47de025b6245 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -506,8 +506,10 @@ static void *rhashtable_lookup_one(struct rhashtable *ht,
506 if (!key || 506 if (!key ||
507 (ht->p.obj_cmpfn ? 507 (ht->p.obj_cmpfn ?
508 ht->p.obj_cmpfn(&arg, rht_obj(ht, head)) : 508 ht->p.obj_cmpfn(&arg, rht_obj(ht, head)) :
509 rhashtable_compare(&arg, rht_obj(ht, head)))) 509 rhashtable_compare(&arg, rht_obj(ht, head)))) {
510 pprev = &head->next;
510 continue; 511 continue;
512 }
511 513
512 if (!ht->rhlist) 514 if (!ht->rhlist)
513 return rht_obj(ht, head); 515 return rht_obj(ht, head);
diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index b4e22345963f..3e9335493fe4 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -24,10 +24,11 @@
24#include <linux/if_vlan.h> 24#include <linux/if_vlan.h>
25#include <linux/random.h> 25#include <linux/random.h>
26#include <linux/highmem.h> 26#include <linux/highmem.h>
27#include <linux/sched.h>
27 28
28/* General test specific settings */ 29/* General test specific settings */
29#define MAX_SUBTESTS 3 30#define MAX_SUBTESTS 3
30#define MAX_TESTRUNS 10000 31#define MAX_TESTRUNS 1000
31#define MAX_DATA 128 32#define MAX_DATA 128
32#define MAX_INSNS 512 33#define MAX_INSNS 512
33#define MAX_K 0xffffFFFF 34#define MAX_K 0xffffFFFF
@@ -5466,7 +5467,7 @@ static struct bpf_test tests[] = {
5466 { 5467 {
5467 "BPF_MAXINSNS: Jump, gap, jump, ...", 5468 "BPF_MAXINSNS: Jump, gap, jump, ...",
5468 { }, 5469 { },
5469#ifdef CONFIG_BPF_JIT_ALWAYS_ON 5470#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_X86)
5470 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 5471 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5471#else 5472#else
5472 CLASSIC | FLAG_NO_DATA, 5473 CLASSIC | FLAG_NO_DATA,
@@ -6582,6 +6583,7 @@ static __init int test_bpf(void)
6582 struct bpf_prog *fp; 6583 struct bpf_prog *fp;
6583 int err; 6584 int err;
6584 6585
6586 cond_resched();
6585 if (exclude_test(i)) 6587 if (exclude_test(i))
6586 continue; 6588 continue;
6587 6589
diff --git a/lib/test_kmod.c b/lib/test_kmod.c
index e372b97eee13..0e5b7a61460b 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -1141,7 +1141,7 @@ static struct kmod_test_device *register_test_dev_kmod(void)
1141 mutex_lock(&reg_dev_mutex); 1141 mutex_lock(&reg_dev_mutex);
1142 1142
1143 /* int should suffice for number of devices, test for wrap */ 1143 /* int should suffice for number of devices, test for wrap */
1144 if (unlikely(num_test_devs + 1) < 0) { 1144 if (num_test_devs + 1 == INT_MAX) {
1145 pr_err("reached limit of number of test devices\n"); 1145 pr_err("reached limit of number of test devices\n");
1146 goto out; 1146 goto out;
1147 } 1147 }
diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c
index 76d3667fdea2..f4000c137dbe 100644
--- a/lib/test_rhashtable.c
+++ b/lib/test_rhashtable.c
@@ -79,6 +79,21 @@ struct thread_data {
79 struct test_obj *objs; 79 struct test_obj *objs;
80}; 80};
81 81
82static u32 my_hashfn(const void *data, u32 len, u32 seed)
83{
84 const struct test_obj_rhl *obj = data;
85
86 return (obj->value.id % 10) << RHT_HASH_RESERVED_SPACE;
87}
88
89static int my_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
90{
91 const struct test_obj_rhl *test_obj = obj;
92 const struct test_obj_val *val = arg->key;
93
94 return test_obj->value.id - val->id;
95}
96
82static struct rhashtable_params test_rht_params = { 97static struct rhashtable_params test_rht_params = {
83 .head_offset = offsetof(struct test_obj, node), 98 .head_offset = offsetof(struct test_obj, node),
84 .key_offset = offsetof(struct test_obj, value), 99 .key_offset = offsetof(struct test_obj, value),
@@ -87,6 +102,17 @@ static struct rhashtable_params test_rht_params = {
87 .nulls_base = (3U << RHT_BASE_SHIFT), 102 .nulls_base = (3U << RHT_BASE_SHIFT),
88}; 103};
89 104
105static struct rhashtable_params test_rht_params_dup = {
106 .head_offset = offsetof(struct test_obj_rhl, list_node),
107 .key_offset = offsetof(struct test_obj_rhl, value),
108 .key_len = sizeof(struct test_obj_val),
109 .hashfn = jhash,
110 .obj_hashfn = my_hashfn,
111 .obj_cmpfn = my_cmpfn,
112 .nelem_hint = 128,
113 .automatic_shrinking = false,
114};
115
90static struct semaphore prestart_sem; 116static struct semaphore prestart_sem;
91static struct semaphore startup_sem = __SEMAPHORE_INITIALIZER(startup_sem, 0); 117static struct semaphore startup_sem = __SEMAPHORE_INITIALIZER(startup_sem, 0);
92 118
@@ -465,6 +491,112 @@ static int __init test_rhashtable_max(struct test_obj *array,
465 return err; 491 return err;
466} 492}
467 493
494static unsigned int __init print_ht(struct rhltable *rhlt)
495{
496 struct rhashtable *ht;
497 const struct bucket_table *tbl;
498 char buff[512] = "";
499 unsigned int i, cnt = 0;
500
501 ht = &rhlt->ht;
502 tbl = rht_dereference(ht->tbl, ht);
503 for (i = 0; i < tbl->size; i++) {
504 struct rhash_head *pos, *next;
505 struct test_obj_rhl *p;
506
507 pos = rht_dereference(tbl->buckets[i], ht);
508 next = !rht_is_a_nulls(pos) ? rht_dereference(pos->next, ht) : NULL;
509
510 if (!rht_is_a_nulls(pos)) {
511 sprintf(buff, "%s\nbucket[%d] -> ", buff, i);
512 }
513
514 while (!rht_is_a_nulls(pos)) {
515 struct rhlist_head *list = container_of(pos, struct rhlist_head, rhead);
516 sprintf(buff, "%s[[", buff);
517 do {
518 pos = &list->rhead;
519 list = rht_dereference(list->next, ht);
520 p = rht_obj(ht, pos);
521
522 sprintf(buff, "%s val %d (tid=%d)%s", buff, p->value.id, p->value.tid,
523 list? ", " : " ");
524 cnt++;
525 } while (list);
526
527 pos = next,
528 next = !rht_is_a_nulls(pos) ?
529 rht_dereference(pos->next, ht) : NULL;
530
531 sprintf(buff, "%s]]%s", buff, !rht_is_a_nulls(pos) ? " -> " : "");
532 }
533 }
534 printk(KERN_ERR "\n---- ht: ----%s\n-------------\n", buff);
535
536 return cnt;
537}
538
539static int __init test_insert_dup(struct test_obj_rhl *rhl_test_objects,
540 int cnt, bool slow)
541{
542 struct rhltable rhlt;
543 unsigned int i, ret;
544 const char *key;
545 int err = 0;
546
547 err = rhltable_init(&rhlt, &test_rht_params_dup);
548 if (WARN_ON(err))
549 return err;
550
551 for (i = 0; i < cnt; i++) {
552 rhl_test_objects[i].value.tid = i;
553 key = rht_obj(&rhlt.ht, &rhl_test_objects[i].list_node.rhead);
554 key += test_rht_params_dup.key_offset;
555
556 if (slow) {
557 err = PTR_ERR(rhashtable_insert_slow(&rhlt.ht, key,
558 &rhl_test_objects[i].list_node.rhead));
559 if (err == -EAGAIN)
560 err = 0;
561 } else
562 err = rhltable_insert(&rhlt,
563 &rhl_test_objects[i].list_node,
564 test_rht_params_dup);
565 if (WARN(err, "error %d on element %d/%d (%s)\n", err, i, cnt, slow? "slow" : "fast"))
566 goto skip_print;
567 }
568
569 ret = print_ht(&rhlt);
570 WARN(ret != cnt, "missing rhltable elements (%d != %d, %s)\n", ret, cnt, slow? "slow" : "fast");
571
572skip_print:
573 rhltable_destroy(&rhlt);
574
575 return 0;
576}
577
578static int __init test_insert_duplicates_run(void)
579{
580 struct test_obj_rhl rhl_test_objects[3] = {};
581
582 pr_info("test inserting duplicates\n");
583
584 /* two different values that map to same bucket */
585 rhl_test_objects[0].value.id = 1;
586 rhl_test_objects[1].value.id = 21;
587
588 /* and another duplicate with same as [0] value
589 * which will be second on the bucket list */
590 rhl_test_objects[2].value.id = rhl_test_objects[0].value.id;
591
592 test_insert_dup(rhl_test_objects, 2, false);
593 test_insert_dup(rhl_test_objects, 3, false);
594 test_insert_dup(rhl_test_objects, 2, true);
595 test_insert_dup(rhl_test_objects, 3, true);
596
597 return 0;
598}
599
468static int thread_lookup_test(struct thread_data *tdata) 600static int thread_lookup_test(struct thread_data *tdata)
469{ 601{
470 unsigned int entries = tdata->entries; 602 unsigned int entries = tdata->entries;
@@ -613,6 +745,8 @@ static int __init test_rht_init(void)
613 do_div(total_time, runs); 745 do_div(total_time, runs);
614 pr_info("Average test time: %llu\n", total_time); 746 pr_info("Average test time: %llu\n", total_time);
615 747
748 test_insert_duplicates_run();
749
616 if (!tcount) 750 if (!tcount)
617 return 0; 751 return 0;
618 752
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 77ee6ced11b1..d7a708f82559 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1849,7 +1849,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1849{ 1849{
1850 const int default_width = 2 * sizeof(void *); 1850 const int default_width = 2 * sizeof(void *);
1851 1851
1852 if (!ptr && *fmt != 'K') { 1852 if (!ptr && *fmt != 'K' && *fmt != 'x') {
1853 /* 1853 /*
1854 * Print (null) with the same width as a pointer so it makes 1854 * Print (null) with the same width as a pointer so it makes
1855 * tabular output look nice. 1855 * tabular output look nice.
diff --git a/mm/gup.c b/mm/gup.c
index 1b46e6e74881..6afae32571ca 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -516,7 +516,7 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
516 } 516 }
517 517
518 if (ret & VM_FAULT_RETRY) { 518 if (ret & VM_FAULT_RETRY) {
519 if (nonblocking) 519 if (nonblocking && !(fault_flags & FAULT_FLAG_RETRY_NOWAIT))
520 *nonblocking = 0; 520 *nonblocking = 0;
521 return -EBUSY; 521 return -EBUSY;
522 } 522 }
@@ -890,7 +890,10 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
890 break; 890 break;
891 } 891 }
892 if (*locked) { 892 if (*locked) {
893 /* VM_FAULT_RETRY didn't trigger */ 893 /*
894 * VM_FAULT_RETRY didn't trigger or it was a
895 * FOLL_NOWAIT.
896 */
894 if (!pages_done) 897 if (!pages_done)
895 pages_done = ret; 898 pages_done = ret;
896 break; 899 break;
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 87ab9b8f56b5..5a68730eebd6 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -555,7 +555,8 @@ static int __do_huge_pmd_anonymous_page(struct vm_fault *vmf, struct page *page,
555 555
556 VM_BUG_ON_PAGE(!PageCompound(page), page); 556 VM_BUG_ON_PAGE(!PageCompound(page), page);
557 557
558 if (mem_cgroup_try_charge(page, vma->vm_mm, gfp, &memcg, true)) { 558 if (mem_cgroup_try_charge(page, vma->vm_mm, gfp | __GFP_NORETRY, &memcg,
559 true)) {
559 put_page(page); 560 put_page(page);
560 count_vm_event(THP_FAULT_FALLBACK); 561 count_vm_event(THP_FAULT_FALLBACK);
561 return VM_FAULT_FALLBACK; 562 return VM_FAULT_FALLBACK;
@@ -1316,7 +1317,7 @@ alloc:
1316 } 1317 }
1317 1318
1318 if (unlikely(mem_cgroup_try_charge(new_page, vma->vm_mm, 1319 if (unlikely(mem_cgroup_try_charge(new_page, vma->vm_mm,
1319 huge_gfp, &memcg, true))) { 1320 huge_gfp | __GFP_NORETRY, &memcg, true))) {
1320 put_page(new_page); 1321 put_page(new_page);
1321 split_huge_pmd(vma, vmf->pmd, vmf->address); 1322 split_huge_pmd(vma, vmf->pmd, vmf->address);
1322 if (page) 1323 if (page)
@@ -2783,11 +2784,13 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,
2783 2784
2784 list_for_each_safe(pos, next, &list) { 2785 list_for_each_safe(pos, next, &list) {
2785 page = list_entry((void *)pos, struct page, mapping); 2786 page = list_entry((void *)pos, struct page, mapping);
2786 lock_page(page); 2787 if (!trylock_page(page))
2788 goto next;
2787 /* split_huge_page() removes page from list on success */ 2789 /* split_huge_page() removes page from list on success */
2788 if (!split_huge_page(page)) 2790 if (!split_huge_page(page))
2789 split++; 2791 split++;
2790 unlock_page(page); 2792 unlock_page(page);
2793next:
2791 put_page(page); 2794 put_page(page);
2792 } 2795 }
2793 2796
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 7c204e3d132b..976bbc5646fe 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -18,6 +18,7 @@
18#include <linux/bootmem.h> 18#include <linux/bootmem.h>
19#include <linux/sysfs.h> 19#include <linux/sysfs.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/mmdebug.h>
21#include <linux/sched/signal.h> 22#include <linux/sched/signal.h>
22#include <linux/rmap.h> 23#include <linux/rmap.h>
23#include <linux/string_helpers.h> 24#include <linux/string_helpers.h>
@@ -1583,7 +1584,7 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask,
1583 page = NULL; 1584 page = NULL;
1584 } else { 1585 } else {
1585 h->surplus_huge_pages++; 1586 h->surplus_huge_pages++;
1586 h->nr_huge_pages_node[page_to_nid(page)]++; 1587 h->surplus_huge_pages_node[page_to_nid(page)]++;
1587 } 1588 }
1588 1589
1589out_unlock: 1590out_unlock:
@@ -4374,6 +4375,12 @@ int hugetlb_reserve_pages(struct inode *inode,
4374 struct resv_map *resv_map; 4375 struct resv_map *resv_map;
4375 long gbl_reserve; 4376 long gbl_reserve;
4376 4377
4378 /* This should never happen */
4379 if (from > to) {
4380 VM_WARN(1, "%s called with a negative range\n", __func__);
4381 return -EINVAL;
4382 }
4383
4377 /* 4384 /*
4378 * Only apply hugepage reservation if asked. At fault time, an 4385 * Only apply hugepage reservation if asked. At fault time, an
4379 * attempt will be made for VM_NORESERVE to allocate a page 4386 * attempt will be made for VM_NORESERVE to allocate a page
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b7e2268dfc9a..e42568284e06 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -530,7 +530,12 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
530 goto out; 530 goto out;
531 } 531 }
532 532
533 VM_BUG_ON_PAGE(PageCompound(page), page); 533 /* TODO: teach khugepaged to collapse THP mapped with pte */
534 if (PageCompound(page)) {
535 result = SCAN_PAGE_COMPOUND;
536 goto out;
537 }
538
534 VM_BUG_ON_PAGE(!PageAnon(page), page); 539 VM_BUG_ON_PAGE(!PageAnon(page), page);
535 540
536 /* 541 /*
@@ -960,7 +965,9 @@ static void collapse_huge_page(struct mm_struct *mm,
960 goto out_nolock; 965 goto out_nolock;
961 } 966 }
962 967
963 if (unlikely(mem_cgroup_try_charge(new_page, mm, gfp, &memcg, true))) { 968 /* Do not oom kill for khugepaged charges */
969 if (unlikely(mem_cgroup_try_charge(new_page, mm, gfp | __GFP_NORETRY,
970 &memcg, true))) {
964 result = SCAN_CGROUP_CHARGE_FAIL; 971 result = SCAN_CGROUP_CHARGE_FAIL;
965 goto out_nolock; 972 goto out_nolock;
966 } 973 }
@@ -1319,7 +1326,9 @@ static void collapse_shmem(struct mm_struct *mm,
1319 goto out; 1326 goto out;
1320 } 1327 }
1321 1328
1322 if (unlikely(mem_cgroup_try_charge(new_page, mm, gfp, &memcg, true))) { 1329 /* Do not oom kill for khugepaged charges */
1330 if (unlikely(mem_cgroup_try_charge(new_page, mm, gfp | __GFP_NORETRY,
1331 &memcg, true))) {
1323 result = SCAN_CGROUP_CHARGE_FAIL; 1332 result = SCAN_CGROUP_CHARGE_FAIL;
1324 goto out; 1333 goto out;
1325 } 1334 }
diff --git a/mm/memblock.c b/mm/memblock.c
index 5a9ca2a1751b..48376bd33274 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1101,34 +1101,6 @@ void __init_memblock __next_mem_pfn_range(int *idx, int nid,
1101 *out_nid = r->nid; 1101 *out_nid = r->nid;
1102} 1102}
1103 1103
1104unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn,
1105 unsigned long max_pfn)
1106{
1107 struct memblock_type *type = &memblock.memory;
1108 unsigned int right = type->cnt;
1109 unsigned int mid, left = 0;
1110 phys_addr_t addr = PFN_PHYS(pfn + 1);
1111
1112 do {
1113 mid = (right + left) / 2;
1114
1115 if (addr < type->regions[mid].base)
1116 right = mid;
1117 else if (addr >= (type->regions[mid].base +
1118 type->regions[mid].size))
1119 left = mid + 1;
1120 else {
1121 /* addr is within the region, so pfn + 1 is valid */
1122 return min(pfn + 1, max_pfn);
1123 }
1124 } while (left < right);
1125
1126 if (right == type->cnt)
1127 return max_pfn;
1128 else
1129 return min(PHYS_PFN(type->regions[right].base), max_pfn);
1130}
1131
1132/** 1104/**
1133 * memblock_set_node - set node ID on memblock regions 1105 * memblock_set_node - set node ID on memblock regions
1134 * @base: base of area to set node ID for 1106 * @base: base of area to set node ID for
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 4b80ccee4535..8291b75f42c8 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1139,8 +1139,6 @@ int memory_failure(unsigned long pfn, int flags)
1139 return 0; 1139 return 0;
1140 } 1140 }
1141 1141
1142 arch_unmap_kpfn(pfn);
1143
1144 orig_head = hpage = compound_head(p); 1142 orig_head = hpage = compound_head(p);
1145 num_poisoned_pages_inc(); 1143 num_poisoned_pages_inc();
1146 1144
diff --git a/mm/memory.c b/mm/memory.c
index dd8de96f5547..5fcfc24904d1 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -80,7 +80,7 @@
80 80
81#include "internal.h" 81#include "internal.h"
82 82
83#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS 83#if defined(LAST_CPUPID_NOT_IN_PAGE_FLAGS) && !defined(CONFIG_COMPILE_TEST)
84#warning Unfortunate NUMA and NUMA Balancing config, growing page-frame for last_cpupid. 84#warning Unfortunate NUMA and NUMA Balancing config, growing page-frame for last_cpupid.
85#endif 85#endif
86 86
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index d879f1d8a44a..32cba0332787 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2124,6 +2124,9 @@ bool __mpol_equal(struct mempolicy *a, struct mempolicy *b)
2124 case MPOL_INTERLEAVE: 2124 case MPOL_INTERLEAVE:
2125 return !!nodes_equal(a->v.nodes, b->v.nodes); 2125 return !!nodes_equal(a->v.nodes, b->v.nodes);
2126 case MPOL_PREFERRED: 2126 case MPOL_PREFERRED:
2127 /* a's ->flags is the same as b's */
2128 if (a->flags & MPOL_F_LOCAL)
2129 return true;
2127 return a->v.preferred_node == b->v.preferred_node; 2130 return a->v.preferred_node == b->v.preferred_node;
2128 default: 2131 default:
2129 BUG(); 2132 BUG();
diff --git a/mm/mlock.c b/mm/mlock.c
index 79398200e423..74e5a6547c3d 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -64,6 +64,12 @@ void clear_page_mlock(struct page *page)
64 mod_zone_page_state(page_zone(page), NR_MLOCK, 64 mod_zone_page_state(page_zone(page), NR_MLOCK,
65 -hpage_nr_pages(page)); 65 -hpage_nr_pages(page));
66 count_vm_event(UNEVICTABLE_PGCLEARED); 66 count_vm_event(UNEVICTABLE_PGCLEARED);
67 /*
68 * The previous TestClearPageMlocked() corresponds to the smp_mb()
69 * in __pagevec_lru_add_fn().
70 *
71 * See __pagevec_lru_add_fn for more explanation.
72 */
67 if (!isolate_lru_page(page)) { 73 if (!isolate_lru_page(page)) {
68 putback_lru_page(page); 74 putback_lru_page(page);
69 } else { 75 } else {
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 81e18ceef579..1741dd23e7c1 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -46,6 +46,7 @@
46#include <linux/stop_machine.h> 46#include <linux/stop_machine.h>
47#include <linux/sort.h> 47#include <linux/sort.h>
48#include <linux/pfn.h> 48#include <linux/pfn.h>
49#include <xen/xen.h>
49#include <linux/backing-dev.h> 50#include <linux/backing-dev.h>
50#include <linux/fault-inject.h> 51#include <linux/fault-inject.h>
51#include <linux/page-isolation.h> 52#include <linux/page-isolation.h>
@@ -347,6 +348,9 @@ static inline bool update_defer_init(pg_data_t *pgdat,
347 /* Always populate low zones for address-constrained allocations */ 348 /* Always populate low zones for address-constrained allocations */
348 if (zone_end < pgdat_end_pfn(pgdat)) 349 if (zone_end < pgdat_end_pfn(pgdat))
349 return true; 350 return true;
351 /* Xen PV domains need page structures early */
352 if (xen_pv_domain())
353 return true;
350 (*nr_initialised)++; 354 (*nr_initialised)++;
351 if ((*nr_initialised > pgdat->static_init_pgcnt) && 355 if ((*nr_initialised > pgdat->static_init_pgcnt) &&
352 (pfn & (PAGES_PER_SECTION - 1)) == 0) { 356 (pfn & (PAGES_PER_SECTION - 1)) == 0) {
@@ -1906,7 +1910,9 @@ static int move_freepages(struct zone *zone,
1906 * Remove at a later date when no bug reports exist related to 1910 * Remove at a later date when no bug reports exist related to
1907 * grouping pages by mobility 1911 * grouping pages by mobility
1908 */ 1912 */
1909 VM_BUG_ON(page_zone(start_page) != page_zone(end_page)); 1913 VM_BUG_ON(pfn_valid(page_to_pfn(start_page)) &&
1914 pfn_valid(page_to_pfn(end_page)) &&
1915 page_zone(start_page) != page_zone(end_page));
1910#endif 1916#endif
1911 1917
1912 if (num_movable) 1918 if (num_movable)
@@ -3590,7 +3596,7 @@ static bool __need_fs_reclaim(gfp_t gfp_mask)
3590 return false; 3596 return false;
3591 3597
3592 /* this guy won't enter reclaim */ 3598 /* this guy won't enter reclaim */
3593 if ((current->flags & PF_MEMALLOC) && !(gfp_mask & __GFP_NOMEMALLOC)) 3599 if (current->flags & PF_MEMALLOC)
3594 return false; 3600 return false;
3595 3601
3596 /* We're only interested __GFP_FS allocations for now */ 3602 /* We're only interested __GFP_FS allocations for now */
@@ -5350,17 +5356,8 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone,
5350 if (context != MEMMAP_EARLY) 5356 if (context != MEMMAP_EARLY)
5351 goto not_early; 5357 goto not_early;
5352 5358
5353 if (!early_pfn_valid(pfn)) { 5359 if (!early_pfn_valid(pfn))
5354#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
5355 /*
5356 * Skip to the pfn preceding the next valid one (or
5357 * end_pfn), such that we hit a valid pfn (or end_pfn)
5358 * on our next iteration of the loop.
5359 */
5360 pfn = memblock_next_valid_pfn(pfn, end_pfn) - 1;
5361#endif
5362 continue; 5360 continue;
5363 }
5364 if (!early_pfn_in_nid(pfn, nid)) 5361 if (!early_pfn_in_nid(pfn, nid))
5365 continue; 5362 continue;
5366 if (!update_defer_init(pgdat, pfn, end_pfn, &nr_initialised)) 5363 if (!update_defer_init(pgdat, pfn, end_pfn, &nr_initialised))
diff --git a/mm/percpu-km.c b/mm/percpu-km.c
index d2a76642c4ae..38de70ab1a0d 100644
--- a/mm/percpu-km.c
+++ b/mm/percpu-km.c
@@ -34,7 +34,7 @@
34#include <linux/log2.h> 34#include <linux/log2.h>
35 35
36static int pcpu_populate_chunk(struct pcpu_chunk *chunk, 36static int pcpu_populate_chunk(struct pcpu_chunk *chunk,
37 int page_start, int page_end) 37 int page_start, int page_end, gfp_t gfp)
38{ 38{
39 return 0; 39 return 0;
40} 40}
@@ -45,18 +45,18 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk,
45 /* nada */ 45 /* nada */
46} 46}
47 47
48static struct pcpu_chunk *pcpu_create_chunk(void) 48static struct pcpu_chunk *pcpu_create_chunk(gfp_t gfp)
49{ 49{
50 const int nr_pages = pcpu_group_sizes[0] >> PAGE_SHIFT; 50 const int nr_pages = pcpu_group_sizes[0] >> PAGE_SHIFT;
51 struct pcpu_chunk *chunk; 51 struct pcpu_chunk *chunk;
52 struct page *pages; 52 struct page *pages;
53 int i; 53 int i;
54 54
55 chunk = pcpu_alloc_chunk(); 55 chunk = pcpu_alloc_chunk(gfp);
56 if (!chunk) 56 if (!chunk)
57 return NULL; 57 return NULL;
58 58
59 pages = alloc_pages(GFP_KERNEL, order_base_2(nr_pages)); 59 pages = alloc_pages(gfp, order_base_2(nr_pages));
60 if (!pages) { 60 if (!pages) {
61 pcpu_free_chunk(chunk); 61 pcpu_free_chunk(chunk);
62 return NULL; 62 return NULL;
diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c
index 9158e5a81391..d8078de912de 100644
--- a/mm/percpu-vm.c
+++ b/mm/percpu-vm.c
@@ -37,7 +37,7 @@ static struct page **pcpu_get_pages(void)
37 lockdep_assert_held(&pcpu_alloc_mutex); 37 lockdep_assert_held(&pcpu_alloc_mutex);
38 38
39 if (!pages) 39 if (!pages)
40 pages = pcpu_mem_zalloc(pages_size); 40 pages = pcpu_mem_zalloc(pages_size, GFP_KERNEL);
41 return pages; 41 return pages;
42} 42}
43 43
@@ -73,18 +73,21 @@ static void pcpu_free_pages(struct pcpu_chunk *chunk,
73 * @pages: array to put the allocated pages into, indexed by pcpu_page_idx() 73 * @pages: array to put the allocated pages into, indexed by pcpu_page_idx()
74 * @page_start: page index of the first page to be allocated 74 * @page_start: page index of the first page to be allocated
75 * @page_end: page index of the last page to be allocated + 1 75 * @page_end: page index of the last page to be allocated + 1
76 * @gfp: allocation flags passed to the underlying allocator
76 * 77 *
77 * Allocate pages [@page_start,@page_end) into @pages for all units. 78 * Allocate pages [@page_start,@page_end) into @pages for all units.
78 * The allocation is for @chunk. Percpu core doesn't care about the 79 * The allocation is for @chunk. Percpu core doesn't care about the
79 * content of @pages and will pass it verbatim to pcpu_map_pages(). 80 * content of @pages and will pass it verbatim to pcpu_map_pages().
80 */ 81 */
81static int pcpu_alloc_pages(struct pcpu_chunk *chunk, 82static int pcpu_alloc_pages(struct pcpu_chunk *chunk,
82 struct page **pages, int page_start, int page_end) 83 struct page **pages, int page_start, int page_end,
84 gfp_t gfp)
83{ 85{
84 const gfp_t gfp = GFP_KERNEL | __GFP_HIGHMEM;
85 unsigned int cpu, tcpu; 86 unsigned int cpu, tcpu;
86 int i; 87 int i;
87 88
89 gfp |= __GFP_HIGHMEM;
90
88 for_each_possible_cpu(cpu) { 91 for_each_possible_cpu(cpu) {
89 for (i = page_start; i < page_end; i++) { 92 for (i = page_start; i < page_end; i++) {
90 struct page **pagep = &pages[pcpu_page_idx(cpu, i)]; 93 struct page **pagep = &pages[pcpu_page_idx(cpu, i)];
@@ -262,6 +265,7 @@ static void pcpu_post_map_flush(struct pcpu_chunk *chunk,
262 * @chunk: chunk of interest 265 * @chunk: chunk of interest
263 * @page_start: the start page 266 * @page_start: the start page
264 * @page_end: the end page 267 * @page_end: the end page
268 * @gfp: allocation flags passed to the underlying memory allocator
265 * 269 *
266 * For each cpu, populate and map pages [@page_start,@page_end) into 270 * For each cpu, populate and map pages [@page_start,@page_end) into
267 * @chunk. 271 * @chunk.
@@ -270,7 +274,7 @@ static void pcpu_post_map_flush(struct pcpu_chunk *chunk,
270 * pcpu_alloc_mutex, does GFP_KERNEL allocation. 274 * pcpu_alloc_mutex, does GFP_KERNEL allocation.
271 */ 275 */
272static int pcpu_populate_chunk(struct pcpu_chunk *chunk, 276static int pcpu_populate_chunk(struct pcpu_chunk *chunk,
273 int page_start, int page_end) 277 int page_start, int page_end, gfp_t gfp)
274{ 278{
275 struct page **pages; 279 struct page **pages;
276 280
@@ -278,7 +282,7 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk,
278 if (!pages) 282 if (!pages)
279 return -ENOMEM; 283 return -ENOMEM;
280 284
281 if (pcpu_alloc_pages(chunk, pages, page_start, page_end)) 285 if (pcpu_alloc_pages(chunk, pages, page_start, page_end, gfp))
282 return -ENOMEM; 286 return -ENOMEM;
283 287
284 if (pcpu_map_pages(chunk, pages, page_start, page_end)) { 288 if (pcpu_map_pages(chunk, pages, page_start, page_end)) {
@@ -325,12 +329,12 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk,
325 pcpu_free_pages(chunk, pages, page_start, page_end); 329 pcpu_free_pages(chunk, pages, page_start, page_end);
326} 330}
327 331
328static struct pcpu_chunk *pcpu_create_chunk(void) 332static struct pcpu_chunk *pcpu_create_chunk(gfp_t gfp)
329{ 333{
330 struct pcpu_chunk *chunk; 334 struct pcpu_chunk *chunk;
331 struct vm_struct **vms; 335 struct vm_struct **vms;
332 336
333 chunk = pcpu_alloc_chunk(); 337 chunk = pcpu_alloc_chunk(gfp);
334 if (!chunk) 338 if (!chunk)
335 return NULL; 339 return NULL;
336 340
diff --git a/mm/percpu.c b/mm/percpu.c
index 50e7fdf84055..9297098519a6 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -80,6 +80,7 @@
80#include <linux/vmalloc.h> 80#include <linux/vmalloc.h>
81#include <linux/workqueue.h> 81#include <linux/workqueue.h>
82#include <linux/kmemleak.h> 82#include <linux/kmemleak.h>
83#include <linux/sched.h>
83 84
84#include <asm/cacheflush.h> 85#include <asm/cacheflush.h>
85#include <asm/sections.h> 86#include <asm/sections.h>
@@ -447,26 +448,25 @@ static void pcpu_next_fit_region(struct pcpu_chunk *chunk, int alloc_bits,
447/** 448/**
448 * pcpu_mem_zalloc - allocate memory 449 * pcpu_mem_zalloc - allocate memory
449 * @size: bytes to allocate 450 * @size: bytes to allocate
451 * @gfp: allocation flags
450 * 452 *
451 * Allocate @size bytes. If @size is smaller than PAGE_SIZE, 453 * Allocate @size bytes. If @size is smaller than PAGE_SIZE,
452 * kzalloc() is used; otherwise, vzalloc() is used. The returned 454 * kzalloc() is used; otherwise, the equivalent of vzalloc() is used.
453 * memory is always zeroed. 455 * This is to facilitate passing through whitelisted flags. The
454 * 456 * returned memory is always zeroed.
455 * CONTEXT:
456 * Does GFP_KERNEL allocation.
457 * 457 *
458 * RETURNS: 458 * RETURNS:
459 * Pointer to the allocated area on success, NULL on failure. 459 * Pointer to the allocated area on success, NULL on failure.
460 */ 460 */
461static void *pcpu_mem_zalloc(size_t size) 461static void *pcpu_mem_zalloc(size_t size, gfp_t gfp)
462{ 462{
463 if (WARN_ON_ONCE(!slab_is_available())) 463 if (WARN_ON_ONCE(!slab_is_available()))
464 return NULL; 464 return NULL;
465 465
466 if (size <= PAGE_SIZE) 466 if (size <= PAGE_SIZE)
467 return kzalloc(size, GFP_KERNEL); 467 return kzalloc(size, gfp);
468 else 468 else
469 return vzalloc(size); 469 return __vmalloc(size, gfp | __GFP_ZERO, PAGE_KERNEL);
470} 470}
471 471
472/** 472/**
@@ -1154,12 +1154,12 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr,
1154 return chunk; 1154 return chunk;
1155} 1155}
1156 1156
1157static struct pcpu_chunk *pcpu_alloc_chunk(void) 1157static struct pcpu_chunk *pcpu_alloc_chunk(gfp_t gfp)
1158{ 1158{
1159 struct pcpu_chunk *chunk; 1159 struct pcpu_chunk *chunk;
1160 int region_bits; 1160 int region_bits;
1161 1161
1162 chunk = pcpu_mem_zalloc(pcpu_chunk_struct_size); 1162 chunk = pcpu_mem_zalloc(pcpu_chunk_struct_size, gfp);
1163 if (!chunk) 1163 if (!chunk)
1164 return NULL; 1164 return NULL;
1165 1165
@@ -1168,17 +1168,17 @@ static struct pcpu_chunk *pcpu_alloc_chunk(void)
1168 region_bits = pcpu_chunk_map_bits(chunk); 1168 region_bits = pcpu_chunk_map_bits(chunk);
1169 1169
1170 chunk->alloc_map = pcpu_mem_zalloc(BITS_TO_LONGS(region_bits) * 1170 chunk->alloc_map = pcpu_mem_zalloc(BITS_TO_LONGS(region_bits) *
1171 sizeof(chunk->alloc_map[0])); 1171 sizeof(chunk->alloc_map[0]), gfp);
1172 if (!chunk->alloc_map) 1172 if (!chunk->alloc_map)
1173 goto alloc_map_fail; 1173 goto alloc_map_fail;
1174 1174
1175 chunk->bound_map = pcpu_mem_zalloc(BITS_TO_LONGS(region_bits + 1) * 1175 chunk->bound_map = pcpu_mem_zalloc(BITS_TO_LONGS(region_bits + 1) *
1176 sizeof(chunk->bound_map[0])); 1176 sizeof(chunk->bound_map[0]), gfp);
1177 if (!chunk->bound_map) 1177 if (!chunk->bound_map)
1178 goto bound_map_fail; 1178 goto bound_map_fail;
1179 1179
1180 chunk->md_blocks = pcpu_mem_zalloc(pcpu_chunk_nr_blocks(chunk) * 1180 chunk->md_blocks = pcpu_mem_zalloc(pcpu_chunk_nr_blocks(chunk) *
1181 sizeof(chunk->md_blocks[0])); 1181 sizeof(chunk->md_blocks[0]), gfp);
1182 if (!chunk->md_blocks) 1182 if (!chunk->md_blocks)
1183 goto md_blocks_fail; 1183 goto md_blocks_fail;
1184 1184
@@ -1277,9 +1277,11 @@ static void pcpu_chunk_depopulated(struct pcpu_chunk *chunk,
1277 * pcpu_addr_to_page - translate address to physical address 1277 * pcpu_addr_to_page - translate address to physical address
1278 * pcpu_verify_alloc_info - check alloc_info is acceptable during init 1278 * pcpu_verify_alloc_info - check alloc_info is acceptable during init
1279 */ 1279 */
1280static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size); 1280static int pcpu_populate_chunk(struct pcpu_chunk *chunk,
1281static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size); 1281 int page_start, int page_end, gfp_t gfp);
1282static struct pcpu_chunk *pcpu_create_chunk(void); 1282static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk,
1283 int page_start, int page_end);
1284static struct pcpu_chunk *pcpu_create_chunk(gfp_t gfp);
1283static void pcpu_destroy_chunk(struct pcpu_chunk *chunk); 1285static void pcpu_destroy_chunk(struct pcpu_chunk *chunk);
1284static struct page *pcpu_addr_to_page(void *addr); 1286static struct page *pcpu_addr_to_page(void *addr);
1285static int __init pcpu_verify_alloc_info(const struct pcpu_alloc_info *ai); 1287static int __init pcpu_verify_alloc_info(const struct pcpu_alloc_info *ai);
@@ -1339,6 +1341,8 @@ static struct pcpu_chunk *pcpu_chunk_addr_search(void *addr)
1339static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, 1341static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved,
1340 gfp_t gfp) 1342 gfp_t gfp)
1341{ 1343{
1344 /* whitelisted flags that can be passed to the backing allocators */
1345 gfp_t pcpu_gfp = gfp & (GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
1342 bool is_atomic = (gfp & GFP_KERNEL) != GFP_KERNEL; 1346 bool is_atomic = (gfp & GFP_KERNEL) != GFP_KERNEL;
1343 bool do_warn = !(gfp & __GFP_NOWARN); 1347 bool do_warn = !(gfp & __GFP_NOWARN);
1344 static int warn_limit = 10; 1348 static int warn_limit = 10;
@@ -1369,8 +1373,17 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved,
1369 return NULL; 1373 return NULL;
1370 } 1374 }
1371 1375
1372 if (!is_atomic) 1376 if (!is_atomic) {
1373 mutex_lock(&pcpu_alloc_mutex); 1377 /*
1378 * pcpu_balance_workfn() allocates memory under this mutex,
1379 * and it may wait for memory reclaim. Allow current task
1380 * to become OOM victim, in case of memory pressure.
1381 */
1382 if (gfp & __GFP_NOFAIL)
1383 mutex_lock(&pcpu_alloc_mutex);
1384 else if (mutex_lock_killable(&pcpu_alloc_mutex))
1385 return NULL;
1386 }
1374 1387
1375 spin_lock_irqsave(&pcpu_lock, flags); 1388 spin_lock_irqsave(&pcpu_lock, flags);
1376 1389
@@ -1421,7 +1434,7 @@ restart:
1421 } 1434 }
1422 1435
1423 if (list_empty(&pcpu_slot[pcpu_nr_slots - 1])) { 1436 if (list_empty(&pcpu_slot[pcpu_nr_slots - 1])) {
1424 chunk = pcpu_create_chunk(); 1437 chunk = pcpu_create_chunk(pcpu_gfp);
1425 if (!chunk) { 1438 if (!chunk) {
1426 err = "failed to allocate new chunk"; 1439 err = "failed to allocate new chunk";
1427 goto fail; 1440 goto fail;
@@ -1450,7 +1463,7 @@ area_found:
1450 page_start, page_end) { 1463 page_start, page_end) {
1451 WARN_ON(chunk->immutable); 1464 WARN_ON(chunk->immutable);
1452 1465
1453 ret = pcpu_populate_chunk(chunk, rs, re); 1466 ret = pcpu_populate_chunk(chunk, rs, re, pcpu_gfp);
1454 1467
1455 spin_lock_irqsave(&pcpu_lock, flags); 1468 spin_lock_irqsave(&pcpu_lock, flags);
1456 if (ret) { 1469 if (ret) {
@@ -1561,10 +1574,17 @@ void __percpu *__alloc_reserved_percpu(size_t size, size_t align)
1561 * pcpu_balance_workfn - manage the amount of free chunks and populated pages 1574 * pcpu_balance_workfn - manage the amount of free chunks and populated pages
1562 * @work: unused 1575 * @work: unused
1563 * 1576 *
1564 * Reclaim all fully free chunks except for the first one. 1577 * Reclaim all fully free chunks except for the first one. This is also
1578 * responsible for maintaining the pool of empty populated pages. However,
1579 * it is possible that this is called when physical memory is scarce causing
1580 * OOM killer to be triggered. We should avoid doing so until an actual
1581 * allocation causes the failure as it is possible that requests can be
1582 * serviced from already backed regions.
1565 */ 1583 */
1566static void pcpu_balance_workfn(struct work_struct *work) 1584static void pcpu_balance_workfn(struct work_struct *work)
1567{ 1585{
1586 /* gfp flags passed to underlying allocators */
1587 const gfp_t gfp = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
1568 LIST_HEAD(to_free); 1588 LIST_HEAD(to_free);
1569 struct list_head *free_head = &pcpu_slot[pcpu_nr_slots - 1]; 1589 struct list_head *free_head = &pcpu_slot[pcpu_nr_slots - 1];
1570 struct pcpu_chunk *chunk, *next; 1590 struct pcpu_chunk *chunk, *next;
@@ -1600,6 +1620,7 @@ static void pcpu_balance_workfn(struct work_struct *work)
1600 spin_unlock_irq(&pcpu_lock); 1620 spin_unlock_irq(&pcpu_lock);
1601 } 1621 }
1602 pcpu_destroy_chunk(chunk); 1622 pcpu_destroy_chunk(chunk);
1623 cond_resched();
1603 } 1624 }
1604 1625
1605 /* 1626 /*
@@ -1645,7 +1666,7 @@ retry_pop:
1645 chunk->nr_pages) { 1666 chunk->nr_pages) {
1646 int nr = min(re - rs, nr_to_pop); 1667 int nr = min(re - rs, nr_to_pop);
1647 1668
1648 ret = pcpu_populate_chunk(chunk, rs, rs + nr); 1669 ret = pcpu_populate_chunk(chunk, rs, rs + nr, gfp);
1649 if (!ret) { 1670 if (!ret) {
1650 nr_to_pop -= nr; 1671 nr_to_pop -= nr;
1651 spin_lock_irq(&pcpu_lock); 1672 spin_lock_irq(&pcpu_lock);
@@ -1662,7 +1683,7 @@ retry_pop:
1662 1683
1663 if (nr_to_pop) { 1684 if (nr_to_pop) {
1664 /* ran out of chunks to populate, create a new one and retry */ 1685 /* ran out of chunks to populate, create a new one and retry */
1665 chunk = pcpu_create_chunk(); 1686 chunk = pcpu_create_chunk(gfp);
1666 if (chunk) { 1687 if (chunk) {
1667 spin_lock_irq(&pcpu_lock); 1688 spin_lock_irq(&pcpu_lock);
1668 pcpu_chunk_relocate(chunk, -1); 1689 pcpu_chunk_relocate(chunk, -1);
diff --git a/mm/shmem.c b/mm/shmem.c
index 1907688b75ee..b85919243399 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -493,36 +493,45 @@ next:
493 info = list_entry(pos, struct shmem_inode_info, shrinklist); 493 info = list_entry(pos, struct shmem_inode_info, shrinklist);
494 inode = &info->vfs_inode; 494 inode = &info->vfs_inode;
495 495
496 if (nr_to_split && split >= nr_to_split) { 496 if (nr_to_split && split >= nr_to_split)
497 iput(inode); 497 goto leave;
498 continue;
499 }
500 498
501 page = find_lock_page(inode->i_mapping, 499 page = find_get_page(inode->i_mapping,
502 (inode->i_size & HPAGE_PMD_MASK) >> PAGE_SHIFT); 500 (inode->i_size & HPAGE_PMD_MASK) >> PAGE_SHIFT);
503 if (!page) 501 if (!page)
504 goto drop; 502 goto drop;
505 503
504 /* No huge page at the end of the file: nothing to split */
506 if (!PageTransHuge(page)) { 505 if (!PageTransHuge(page)) {
507 unlock_page(page);
508 put_page(page); 506 put_page(page);
509 goto drop; 507 goto drop;
510 } 508 }
511 509
510 /*
511 * Leave the inode on the list if we failed to lock
512 * the page at this time.
513 *
514 * Waiting for the lock may lead to deadlock in the
515 * reclaim path.
516 */
517 if (!trylock_page(page)) {
518 put_page(page);
519 goto leave;
520 }
521
512 ret = split_huge_page(page); 522 ret = split_huge_page(page);
513 unlock_page(page); 523 unlock_page(page);
514 put_page(page); 524 put_page(page);
515 525
516 if (ret) { 526 /* If split failed leave the inode on the list */
517 /* split failed: leave it on the list */ 527 if (ret)
518 iput(inode); 528 goto leave;
519 continue;
520 }
521 529
522 split++; 530 split++;
523drop: 531drop:
524 list_del_init(&info->shrinklist); 532 list_del_init(&info->shrinklist);
525 removed++; 533 removed++;
534leave:
526 iput(inode); 535 iput(inode);
527 } 536 }
528 537
diff --git a/mm/swap.c b/mm/swap.c
index 567a7b96e41d..0f17330dd0e5 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -446,30 +446,6 @@ void lru_cache_add(struct page *page)
446} 446}
447 447
448/** 448/**
449 * add_page_to_unevictable_list - add a page to the unevictable list
450 * @page: the page to be added to the unevictable list
451 *
452 * Add page directly to its zone's unevictable list. To avoid races with
453 * tasks that might be making the page evictable, through eg. munlock,
454 * munmap or exit, while it's not on the lru, we want to add the page
455 * while it's locked or otherwise "invisible" to other tasks. This is
456 * difficult to do when using the pagevec cache, so bypass that.
457 */
458void add_page_to_unevictable_list(struct page *page)
459{
460 struct pglist_data *pgdat = page_pgdat(page);
461 struct lruvec *lruvec;
462
463 spin_lock_irq(&pgdat->lru_lock);
464 lruvec = mem_cgroup_page_lruvec(page, pgdat);
465 ClearPageActive(page);
466 SetPageUnevictable(page);
467 SetPageLRU(page);
468 add_page_to_lru_list(page, lruvec, LRU_UNEVICTABLE);
469 spin_unlock_irq(&pgdat->lru_lock);
470}
471
472/**
473 * lru_cache_add_active_or_unevictable 449 * lru_cache_add_active_or_unevictable
474 * @page: the page to be added to LRU 450 * @page: the page to be added to LRU
475 * @vma: vma in which page is mapped for determining reclaimability 451 * @vma: vma in which page is mapped for determining reclaimability
@@ -484,13 +460,9 @@ void lru_cache_add_active_or_unevictable(struct page *page,
484{ 460{
485 VM_BUG_ON_PAGE(PageLRU(page), page); 461 VM_BUG_ON_PAGE(PageLRU(page), page);
486 462
487 if (likely((vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) != VM_LOCKED)) { 463 if (likely((vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) != VM_LOCKED))
488 SetPageActive(page); 464 SetPageActive(page);
489 lru_cache_add(page); 465 else if (!TestSetPageMlocked(page)) {
490 return;
491 }
492
493 if (!TestSetPageMlocked(page)) {
494 /* 466 /*
495 * We use the irq-unsafe __mod_zone_page_stat because this 467 * We use the irq-unsafe __mod_zone_page_stat because this
496 * counter is not modified from interrupt context, and the pte 468 * counter is not modified from interrupt context, and the pte
@@ -500,7 +472,7 @@ void lru_cache_add_active_or_unevictable(struct page *page,
500 hpage_nr_pages(page)); 472 hpage_nr_pages(page));
501 count_vm_event(UNEVICTABLE_PGMLOCKED); 473 count_vm_event(UNEVICTABLE_PGMLOCKED);
502 } 474 }
503 add_page_to_unevictable_list(page); 475 lru_cache_add(page);
504} 476}
505 477
506/* 478/*
@@ -886,15 +858,55 @@ void lru_add_page_tail(struct page *page, struct page *page_tail,
886static void __pagevec_lru_add_fn(struct page *page, struct lruvec *lruvec, 858static void __pagevec_lru_add_fn(struct page *page, struct lruvec *lruvec,
887 void *arg) 859 void *arg)
888{ 860{
889 int file = page_is_file_cache(page); 861 enum lru_list lru;
890 int active = PageActive(page); 862 int was_unevictable = TestClearPageUnevictable(page);
891 enum lru_list lru = page_lru(page);
892 863
893 VM_BUG_ON_PAGE(PageLRU(page), page); 864 VM_BUG_ON_PAGE(PageLRU(page), page);
894 865
895 SetPageLRU(page); 866 SetPageLRU(page);
867 /*
868 * Page becomes evictable in two ways:
869 * 1) Within LRU lock [munlock_vma_pages() and __munlock_pagevec()].
870 * 2) Before acquiring LRU lock to put the page to correct LRU and then
871 * a) do PageLRU check with lock [check_move_unevictable_pages]
872 * b) do PageLRU check before lock [clear_page_mlock]
873 *
874 * (1) & (2a) are ok as LRU lock will serialize them. For (2b), we need
875 * following strict ordering:
876 *
877 * #0: __pagevec_lru_add_fn #1: clear_page_mlock
878 *
879 * SetPageLRU() TestClearPageMlocked()
880 * smp_mb() // explicit ordering // above provides strict
881 * // ordering
882 * PageMlocked() PageLRU()
883 *
884 *
885 * if '#1' does not observe setting of PG_lru by '#0' and fails
886 * isolation, the explicit barrier will make sure that page_evictable
887 * check will put the page in correct LRU. Without smp_mb(), SetPageLRU
888 * can be reordered after PageMlocked check and can make '#1' to fail
889 * the isolation of the page whose Mlocked bit is cleared (#0 is also
890 * looking at the same page) and the evictable page will be stranded
891 * in an unevictable LRU.
892 */
893 smp_mb();
894
895 if (page_evictable(page)) {
896 lru = page_lru(page);
897 update_page_reclaim_stat(lruvec, page_is_file_cache(page),
898 PageActive(page));
899 if (was_unevictable)
900 count_vm_event(UNEVICTABLE_PGRESCUED);
901 } else {
902 lru = LRU_UNEVICTABLE;
903 ClearPageActive(page);
904 SetPageUnevictable(page);
905 if (!was_unevictable)
906 count_vm_event(UNEVICTABLE_PGCULLED);
907 }
908
896 add_page_to_lru_list(page, lruvec, lru); 909 add_page_to_lru_list(page, lruvec, lru);
897 update_page_reclaim_stat(lruvec, file, active);
898 trace_mm_lru_insertion(page, lru); 910 trace_mm_lru_insertion(page, lru);
899} 911}
900 912
@@ -913,7 +925,7 @@ EXPORT_SYMBOL(__pagevec_lru_add);
913 * @pvec: Where the resulting entries are placed 925 * @pvec: Where the resulting entries are placed
914 * @mapping: The address_space to search 926 * @mapping: The address_space to search
915 * @start: The starting entry index 927 * @start: The starting entry index
916 * @nr_pages: The maximum number of pages 928 * @nr_entries: The maximum number of pages
917 * @indices: The cache indices corresponding to the entries in @pvec 929 * @indices: The cache indices corresponding to the entries in @pvec
918 * 930 *
919 * pagevec_lookup_entries() will search for and return a group of up 931 * pagevec_lookup_entries() will search for and return a group of up
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 673942094328..ebff729cc956 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1943,11 +1943,15 @@ void *vmalloc_exec(unsigned long size)
1943} 1943}
1944 1944
1945#if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32) 1945#if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32)
1946#define GFP_VMALLOC32 GFP_DMA32 | GFP_KERNEL 1946#define GFP_VMALLOC32 (GFP_DMA32 | GFP_KERNEL)
1947#elif defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA) 1947#elif defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA)
1948#define GFP_VMALLOC32 GFP_DMA | GFP_KERNEL 1948#define GFP_VMALLOC32 (GFP_DMA | GFP_KERNEL)
1949#else 1949#else
1950#define GFP_VMALLOC32 GFP_KERNEL 1950/*
1951 * 64b systems should always have either DMA or DMA32 zones. For others
1952 * GFP_DMA32 should do the right thing and use the normal zone.
1953 */
1954#define GFP_VMALLOC32 GFP_DMA32 | GFP_KERNEL
1951#endif 1955#endif
1952 1956
1953/** 1957/**
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 444749669187..cd5dc3faaa57 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -769,64 +769,7 @@ int remove_mapping(struct address_space *mapping, struct page *page)
769 */ 769 */
770void putback_lru_page(struct page *page) 770void putback_lru_page(struct page *page)
771{ 771{
772 bool is_unevictable; 772 lru_cache_add(page);
773 int was_unevictable = PageUnevictable(page);
774
775 VM_BUG_ON_PAGE(PageLRU(page), page);
776
777redo:
778 ClearPageUnevictable(page);
779
780 if (page_evictable(page)) {
781 /*
782 * For evictable pages, we can use the cache.
783 * In event of a race, worst case is we end up with an
784 * unevictable page on [in]active list.
785 * We know how to handle that.
786 */
787 is_unevictable = false;
788 lru_cache_add(page);
789 } else {
790 /*
791 * Put unevictable pages directly on zone's unevictable
792 * list.
793 */
794 is_unevictable = true;
795 add_page_to_unevictable_list(page);
796 /*
797 * When racing with an mlock or AS_UNEVICTABLE clearing
798 * (page is unlocked) make sure that if the other thread
799 * does not observe our setting of PG_lru and fails
800 * isolation/check_move_unevictable_pages,
801 * we see PG_mlocked/AS_UNEVICTABLE cleared below and move
802 * the page back to the evictable list.
803 *
804 * The other side is TestClearPageMlocked() or shmem_lock().
805 */
806 smp_mb();
807 }
808
809 /*
810 * page's status can change while we move it among lru. If an evictable
811 * page is on unevictable list, it never be freed. To avoid that,
812 * check after we added it to the list, again.
813 */
814 if (is_unevictable && page_evictable(page)) {
815 if (!isolate_lru_page(page)) {
816 put_page(page);
817 goto redo;
818 }
819 /* This means someone else dropped this page from LRU
820 * So, it will be freed or putback to LRU again. There is
821 * nothing to do here.
822 */
823 }
824
825 if (was_unevictable && !is_unevictable)
826 count_vm_event(UNEVICTABLE_PGRESCUED);
827 else if (!was_unevictable && is_unevictable)
828 count_vm_event(UNEVICTABLE_PGCULLED);
829
830 put_page(page); /* drop ref from isolate */ 773 put_page(page); /* drop ref from isolate */
831} 774}
832 775
@@ -1837,6 +1780,20 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
1837 set_bit(PGDAT_WRITEBACK, &pgdat->flags); 1780 set_bit(PGDAT_WRITEBACK, &pgdat->flags);
1838 1781
1839 /* 1782 /*
1783 * If dirty pages are scanned that are not queued for IO, it
1784 * implies that flushers are not doing their job. This can
1785 * happen when memory pressure pushes dirty pages to the end of
1786 * the LRU before the dirty limits are breached and the dirty
1787 * data has expired. It can also happen when the proportion of
1788 * dirty pages grows not through writes but through memory
1789 * pressure reclaiming all the clean cache. And in some cases,
1790 * the flushers simply cannot keep up with the allocation
1791 * rate. Nudge the flusher threads in case they are asleep.
1792 */
1793 if (stat.nr_unqueued_dirty == nr_taken)
1794 wakeup_flusher_threads(WB_REASON_VMSCAN);
1795
1796 /*
1840 * Legacy memcg will stall in page writeback so avoid forcibly 1797 * Legacy memcg will stall in page writeback so avoid forcibly
1841 * stalling here. 1798 * stalling here.
1842 */ 1799 */
@@ -1848,22 +1805,9 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
1848 if (stat.nr_dirty && stat.nr_dirty == stat.nr_congested) 1805 if (stat.nr_dirty && stat.nr_dirty == stat.nr_congested)
1849 set_bit(PGDAT_CONGESTED, &pgdat->flags); 1806 set_bit(PGDAT_CONGESTED, &pgdat->flags);
1850 1807
1851 /* 1808 /* Allow kswapd to start writing pages during reclaim. */
1852 * If dirty pages are scanned that are not queued for IO, it 1809 if (stat.nr_unqueued_dirty == nr_taken)
1853 * implies that flushers are not doing their job. This can
1854 * happen when memory pressure pushes dirty pages to the end of
1855 * the LRU before the dirty limits are breached and the dirty
1856 * data has expired. It can also happen when the proportion of
1857 * dirty pages grows not through writes but through memory
1858 * pressure reclaiming all the clean cache. And in some cases,
1859 * the flushers simply cannot keep up with the allocation
1860 * rate. Nudge the flusher threads in case they are asleep, but
1861 * also allow kswapd to start writing pages during reclaim.
1862 */
1863 if (stat.nr_unqueued_dirty == nr_taken) {
1864 wakeup_flusher_threads(WB_REASON_VMSCAN);
1865 set_bit(PGDAT_DIRTY, &pgdat->flags); 1810 set_bit(PGDAT_DIRTY, &pgdat->flags);
1866 }
1867 1811
1868 /* 1812 /*
1869 * If kswapd scans pages marked marked for immediate 1813 * If kswapd scans pages marked marked for immediate
diff --git a/mm/zpool.c b/mm/zpool.c
index f8cb83e7699b..01a771e304fa 100644
--- a/mm/zpool.c
+++ b/mm/zpool.c
@@ -360,7 +360,7 @@ u64 zpool_get_total_size(struct zpool *zpool)
360 360
361/** 361/**
362 * zpool_evictable() - Test if zpool is potentially evictable 362 * zpool_evictable() - Test if zpool is potentially evictable
363 * @pool The zpool to test 363 * @zpool: The zpool to test
364 * 364 *
365 * Zpool is only potentially evictable when it's created with struct 365 * Zpool is only potentially evictable when it's created with struct
366 * zpool_ops.evict and its driver implements struct zpool_driver.shrink. 366 * zpool_ops.evict and its driver implements struct zpool_driver.shrink.
diff --git a/mm/zswap.c b/mm/zswap.c
index c004aa4fd3f4..61a5c41972db 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1007,6 +1007,12 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
1007 u8 *src, *dst; 1007 u8 *src, *dst;
1008 struct zswap_header zhdr = { .swpentry = swp_entry(type, offset) }; 1008 struct zswap_header zhdr = { .swpentry = swp_entry(type, offset) };
1009 1009
1010 /* THP isn't supported */
1011 if (PageTransHuge(page)) {
1012 ret = -EINVAL;
1013 goto reject;
1014 }
1015
1010 if (!zswap_enabled || !tree) { 1016 if (!zswap_enabled || !tree) {
1011 ret = -ENODEV; 1017 ret = -ENODEV;
1012 goto reject; 1018 goto reject;
diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c
index 64aa9f755e1d..45c9bf5ff3a0 100644
--- a/net/8021q/vlan_core.c
+++ b/net/8021q/vlan_core.c
@@ -48,8 +48,8 @@ bool vlan_do_receive(struct sk_buff **skbp)
48 * original position later 48 * original position later
49 */ 49 */
50 skb_push(skb, offset); 50 skb_push(skb, offset);
51 skb = *skbp = vlan_insert_tag(skb, skb->vlan_proto, 51 skb = *skbp = vlan_insert_inner_tag(skb, skb->vlan_proto,
52 skb->vlan_tci); 52 skb->vlan_tci, skb->mac_len);
53 if (!skb) 53 if (!skb)
54 return false; 54 return false;
55 skb_pull(skb, offset + VLAN_HLEN); 55 skb_pull(skb, offset + VLAN_HLEN);
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index f3a4efcf1456..3aa5a93ad107 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -160,7 +160,8 @@ static void req_done(struct virtqueue *vq)
160 spin_unlock_irqrestore(&chan->lock, flags); 160 spin_unlock_irqrestore(&chan->lock, flags);
161 /* Wakeup if anyone waiting for VirtIO ring space. */ 161 /* Wakeup if anyone waiting for VirtIO ring space. */
162 wake_up(chan->vc_wq); 162 wake_up(chan->vc_wq);
163 p9_client_cb(chan->client, req, REQ_STATUS_RCVD); 163 if (len)
164 p9_client_cb(chan->client, req, REQ_STATUS_RCVD);
164 } 165 }
165} 166}
166 167
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 79e326383726..99abeadf416e 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -157,7 +157,7 @@ static void batadv_iv_ogm_orig_free(struct batadv_orig_node *orig_node)
157 * Return: 0 on success, a negative error code otherwise. 157 * Return: 0 on success, a negative error code otherwise.
158 */ 158 */
159static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node, 159static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node,
160 int max_if_num) 160 unsigned int max_if_num)
161{ 161{
162 void *data_ptr; 162 void *data_ptr;
163 size_t old_size; 163 size_t old_size;
@@ -201,7 +201,8 @@ unlock:
201 */ 201 */
202static void 202static void
203batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node, 203batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node,
204 int max_if_num, int del_if_num) 204 unsigned int max_if_num,
205 unsigned int del_if_num)
205{ 206{
206 size_t chunk_size; 207 size_t chunk_size;
207 size_t if_offset; 208 size_t if_offset;
@@ -239,7 +240,8 @@ batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node,
239 */ 240 */
240static void 241static void
241batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node, 242batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node,
242 int max_if_num, int del_if_num) 243 unsigned int max_if_num,
244 unsigned int del_if_num)
243{ 245{
244 size_t if_offset; 246 size_t if_offset;
245 void *data_ptr; 247 void *data_ptr;
@@ -276,7 +278,8 @@ batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node,
276 * Return: 0 on success, a negative error code otherwise. 278 * Return: 0 on success, a negative error code otherwise.
277 */ 279 */
278static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node, 280static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node,
279 int max_if_num, int del_if_num) 281 unsigned int max_if_num,
282 unsigned int del_if_num)
280{ 283{
281 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); 284 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
282 285
@@ -311,7 +314,8 @@ static struct batadv_orig_node *
311batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr) 314batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)
312{ 315{
313 struct batadv_orig_node *orig_node; 316 struct batadv_orig_node *orig_node;
314 int size, hash_added; 317 int hash_added;
318 size_t size;
315 319
316 orig_node = batadv_orig_hash_find(bat_priv, addr); 320 orig_node = batadv_orig_hash_find(bat_priv, addr);
317 if (orig_node) 321 if (orig_node)
@@ -893,7 +897,7 @@ batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)
893 u32 i; 897 u32 i;
894 size_t word_index; 898 size_t word_index;
895 u8 *w; 899 u8 *w;
896 int if_num; 900 unsigned int if_num;
897 901
898 for (i = 0; i < hash->size; i++) { 902 for (i = 0; i < hash->size; i++) {
899 head = &hash->table[i]; 903 head = &hash->table[i];
@@ -1023,7 +1027,7 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
1023 struct batadv_neigh_node *tmp_neigh_node = NULL; 1027 struct batadv_neigh_node *tmp_neigh_node = NULL;
1024 struct batadv_neigh_node *router = NULL; 1028 struct batadv_neigh_node *router = NULL;
1025 struct batadv_orig_node *orig_node_tmp; 1029 struct batadv_orig_node *orig_node_tmp;
1026 int if_num; 1030 unsigned int if_num;
1027 u8 sum_orig, sum_neigh; 1031 u8 sum_orig, sum_neigh;
1028 u8 *neigh_addr; 1032 u8 *neigh_addr;
1029 u8 tq_avg; 1033 u8 tq_avg;
@@ -1182,7 +1186,7 @@ static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
1182 u8 total_count; 1186 u8 total_count;
1183 u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own; 1187 u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
1184 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube; 1188 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
1185 int if_num; 1189 unsigned int if_num;
1186 unsigned int tq_asym_penalty, inv_asym_penalty; 1190 unsigned int tq_asym_penalty, inv_asym_penalty;
1187 unsigned int combined_tq; 1191 unsigned int combined_tq;
1188 unsigned int tq_iface_penalty; 1192 unsigned int tq_iface_penalty;
@@ -1702,9 +1706,9 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
1702 1706
1703 if (is_my_orig) { 1707 if (is_my_orig) {
1704 unsigned long *word; 1708 unsigned long *word;
1705 int offset; 1709 size_t offset;
1706 s32 bit_pos; 1710 s32 bit_pos;
1707 s16 if_num; 1711 unsigned int if_num;
1708 u8 *weight; 1712 u8 *weight;
1709 1713
1710 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv, 1714 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
@@ -2729,7 +2733,7 @@ static int batadv_iv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
2729 struct batadv_neigh_ifinfo *router_ifinfo = NULL; 2733 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
2730 struct batadv_neigh_node *router; 2734 struct batadv_neigh_node *router;
2731 struct batadv_gw_node *curr_gw; 2735 struct batadv_gw_node *curr_gw;
2732 int ret = -EINVAL; 2736 int ret = 0;
2733 void *hdr; 2737 void *hdr;
2734 2738
2735 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); 2739 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT);
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
index 27e165ac9302..c74f81341dab 100644
--- a/net/batman-adv/bat_v.c
+++ b/net/batman-adv/bat_v.c
@@ -928,7 +928,7 @@ static int batadv_v_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
928 struct batadv_neigh_ifinfo *router_ifinfo = NULL; 928 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
929 struct batadv_neigh_node *router; 929 struct batadv_neigh_node *router;
930 struct batadv_gw_node *curr_gw; 930 struct batadv_gw_node *curr_gw;
931 int ret = -EINVAL; 931 int ret = 0;
932 void *hdr; 932 void *hdr;
933 933
934 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); 934 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT);
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index fad47853ad3c..b1a08374088b 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -2161,22 +2161,25 @@ batadv_bla_claim_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
2161{ 2161{
2162 struct batadv_bla_claim *claim; 2162 struct batadv_bla_claim *claim;
2163 int idx = 0; 2163 int idx = 0;
2164 int ret = 0;
2164 2165
2165 rcu_read_lock(); 2166 rcu_read_lock();
2166 hlist_for_each_entry_rcu(claim, head, hash_entry) { 2167 hlist_for_each_entry_rcu(claim, head, hash_entry) {
2167 if (idx++ < *idx_skip) 2168 if (idx++ < *idx_skip)
2168 continue; 2169 continue;
2169 if (batadv_bla_claim_dump_entry(msg, portid, seq, 2170
2170 primary_if, claim)) { 2171 ret = batadv_bla_claim_dump_entry(msg, portid, seq,
2172 primary_if, claim);
2173 if (ret) {
2171 *idx_skip = idx - 1; 2174 *idx_skip = idx - 1;
2172 goto unlock; 2175 goto unlock;
2173 } 2176 }
2174 } 2177 }
2175 2178
2176 *idx_skip = idx; 2179 *idx_skip = 0;
2177unlock: 2180unlock:
2178 rcu_read_unlock(); 2181 rcu_read_unlock();
2179 return 0; 2182 return ret;
2180} 2183}
2181 2184
2182/** 2185/**
@@ -2391,22 +2394,25 @@ batadv_bla_backbone_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
2391{ 2394{
2392 struct batadv_bla_backbone_gw *backbone_gw; 2395 struct batadv_bla_backbone_gw *backbone_gw;
2393 int idx = 0; 2396 int idx = 0;
2397 int ret = 0;
2394 2398
2395 rcu_read_lock(); 2399 rcu_read_lock();
2396 hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) { 2400 hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
2397 if (idx++ < *idx_skip) 2401 if (idx++ < *idx_skip)
2398 continue; 2402 continue;
2399 if (batadv_bla_backbone_dump_entry(msg, portid, seq, 2403
2400 primary_if, backbone_gw)) { 2404 ret = batadv_bla_backbone_dump_entry(msg, portid, seq,
2405 primary_if, backbone_gw);
2406 if (ret) {
2401 *idx_skip = idx - 1; 2407 *idx_skip = idx - 1;
2402 goto unlock; 2408 goto unlock;
2403 } 2409 }
2404 } 2410 }
2405 2411
2406 *idx_skip = idx; 2412 *idx_skip = 0;
2407unlock: 2413unlock:
2408 rcu_read_unlock(); 2414 rcu_read_unlock();
2409 return 0; 2415 return ret;
2410} 2416}
2411 2417
2412/** 2418/**
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 9703c791ffc5..87cd962d28d5 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -393,7 +393,7 @@ static void batadv_dbg_arp(struct batadv_priv *bat_priv, struct sk_buff *skb,
393 batadv_arp_hw_src(skb, hdr_size), &ip_src, 393 batadv_arp_hw_src(skb, hdr_size), &ip_src,
394 batadv_arp_hw_dst(skb, hdr_size), &ip_dst); 394 batadv_arp_hw_dst(skb, hdr_size), &ip_dst);
395 395
396 if (hdr_size == 0) 396 if (hdr_size < sizeof(struct batadv_unicast_packet))
397 return; 397 return;
398 398
399 unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data; 399 unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data;
diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
index 22dde42fd80e..5afe641ee4b0 100644
--- a/net/batman-adv/fragmentation.c
+++ b/net/batman-adv/fragmentation.c
@@ -288,7 +288,8 @@ batadv_frag_merge_packets(struct hlist_head *chain)
288 /* Move the existing MAC header to just before the payload. (Override 288 /* Move the existing MAC header to just before the payload. (Override
289 * the fragment header.) 289 * the fragment header.)
290 */ 290 */
291 skb_pull_rcsum(skb_out, hdr_size); 291 skb_pull(skb_out, hdr_size);
292 skb_out->ip_summed = CHECKSUM_NONE;
292 memmove(skb_out->data - ETH_HLEN, skb_mac_header(skb_out), ETH_HLEN); 293 memmove(skb_out->data - ETH_HLEN, skb_mac_header(skb_out), ETH_HLEN);
293 skb_set_mac_header(skb_out, -ETH_HLEN); 294 skb_set_mac_header(skb_out, -ETH_HLEN);
294 skb_reset_network_header(skb_out); 295 skb_reset_network_header(skb_out);
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 5f186bff284a..68b54a39c51d 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -763,6 +763,11 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
763 hard_iface->soft_iface = soft_iface; 763 hard_iface->soft_iface = soft_iface;
764 bat_priv = netdev_priv(hard_iface->soft_iface); 764 bat_priv = netdev_priv(hard_iface->soft_iface);
765 765
766 if (bat_priv->num_ifaces >= UINT_MAX) {
767 ret = -ENOSPC;
768 goto err_dev;
769 }
770
766 ret = netdev_master_upper_dev_link(hard_iface->net_dev, 771 ret = netdev_master_upper_dev_link(hard_iface->net_dev,
767 soft_iface, NULL, NULL, NULL); 772 soft_iface, NULL, NULL, NULL);
768 if (ret) 773 if (ret)
@@ -876,7 +881,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
876 batadv_hardif_recalc_extra_skbroom(hard_iface->soft_iface); 881 batadv_hardif_recalc_extra_skbroom(hard_iface->soft_iface);
877 882
878 /* nobody uses this interface anymore */ 883 /* nobody uses this interface anymore */
879 if (!bat_priv->num_ifaces) { 884 if (bat_priv->num_ifaces == 0) {
880 batadv_gw_check_client_stop(bat_priv); 885 batadv_gw_check_client_stop(bat_priv);
881 886
882 if (autodel == BATADV_IF_CLEANUP_AUTO) 887 if (autodel == BATADV_IF_CLEANUP_AUTO)
@@ -912,7 +917,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
912 if (ret) 917 if (ret)
913 goto free_if; 918 goto free_if;
914 919
915 hard_iface->if_num = -1; 920 hard_iface->if_num = 0;
916 hard_iface->net_dev = net_dev; 921 hard_iface->net_dev = net_dev;
917 hard_iface->soft_iface = NULL; 922 hard_iface->soft_iface = NULL;
918 hard_iface->if_status = BATADV_IF_NOT_IN_USE; 923 hard_iface->if_status = BATADV_IF_NOT_IN_USE;
diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c
index e91f29c7c638..5daa3d50da17 100644
--- a/net/batman-adv/icmp_socket.c
+++ b/net/batman-adv/icmp_socket.c
@@ -24,6 +24,7 @@
24#include <linux/debugfs.h> 24#include <linux/debugfs.h>
25#include <linux/errno.h> 25#include <linux/errno.h>
26#include <linux/etherdevice.h> 26#include <linux/etherdevice.h>
27#include <linux/eventpoll.h>
27#include <linux/export.h> 28#include <linux/export.h>
28#include <linux/fcntl.h> 29#include <linux/fcntl.h>
29#include <linux/fs.h> 30#include <linux/fs.h>
diff --git a/net/batman-adv/log.c b/net/batman-adv/log.c
index dc9fa37ddd14..cdbe0e5e208b 100644
--- a/net/batman-adv/log.c
+++ b/net/batman-adv/log.c
@@ -22,6 +22,7 @@
22#include <linux/compiler.h> 22#include <linux/compiler.h>
23#include <linux/debugfs.h> 23#include <linux/debugfs.h>
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/eventpoll.h>
25#include <linux/export.h> 26#include <linux/export.h>
26#include <linux/fcntl.h> 27#include <linux/fcntl.h>
27#include <linux/fs.h> 28#include <linux/fs.h>
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index cbdeb47ec3f6..d70640135e3a 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -543,8 +543,8 @@ update:
543 bat_priv->mcast.enabled = true; 543 bat_priv->mcast.enabled = true;
544 } 544 }
545 545
546 return !(mcast_data.flags & 546 return !(mcast_data.flags & BATADV_MCAST_WANT_ALL_IPV4 &&
547 (BATADV_MCAST_WANT_ALL_IPV4 | BATADV_MCAST_WANT_ALL_IPV6)); 547 mcast_data.flags & BATADV_MCAST_WANT_ALL_IPV6);
548} 548}
549 549
550/** 550/**
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 58a7d9274435..74782426bb77 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -1569,7 +1569,7 @@ int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb)
1569 * Return: 0 on success or negative error number in case of failure 1569 * Return: 0 on success or negative error number in case of failure
1570 */ 1570 */
1571int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface, 1571int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
1572 int max_if_num) 1572 unsigned int max_if_num)
1573{ 1573{
1574 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 1574 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
1575 struct batadv_algo_ops *bao = bat_priv->algo_ops; 1575 struct batadv_algo_ops *bao = bat_priv->algo_ops;
@@ -1611,7 +1611,7 @@ err:
1611 * Return: 0 on success or negative error number in case of failure 1611 * Return: 0 on success or negative error number in case of failure
1612 */ 1612 */
1613int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface, 1613int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
1614 int max_if_num) 1614 unsigned int max_if_num)
1615{ 1615{
1616 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 1616 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
1617 struct batadv_hashtable *hash = bat_priv->orig_hash; 1617 struct batadv_hashtable *hash = bat_priv->orig_hash;
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index 8e543a3cdc6c..15d896b2de6f 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -73,9 +73,9 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset);
73int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb); 73int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb);
74int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset); 74int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset);
75int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface, 75int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
76 int max_if_num); 76 unsigned int max_if_num);
77int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface, 77int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
78 int max_if_num); 78 unsigned int max_if_num);
79struct batadv_orig_node_vlan * 79struct batadv_orig_node_vlan *
80batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node, 80batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
81 unsigned short vid); 81 unsigned short vid);
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index b6891e8b741c..e61dc1293bb5 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -759,6 +759,7 @@ free_skb:
759/** 759/**
760 * batadv_reroute_unicast_packet() - update the unicast header for re-routing 760 * batadv_reroute_unicast_packet() - update the unicast header for re-routing
761 * @bat_priv: the bat priv with all the soft interface information 761 * @bat_priv: the bat priv with all the soft interface information
762 * @skb: unicast packet to process
762 * @unicast_packet: the unicast header to be updated 763 * @unicast_packet: the unicast header to be updated
763 * @dst_addr: the payload destination 764 * @dst_addr: the payload destination
764 * @vid: VLAN identifier 765 * @vid: VLAN identifier
@@ -770,7 +771,7 @@ free_skb:
770 * Return: true if the packet header has been updated, false otherwise 771 * Return: true if the packet header has been updated, false otherwise
771 */ 772 */
772static bool 773static bool
773batadv_reroute_unicast_packet(struct batadv_priv *bat_priv, 774batadv_reroute_unicast_packet(struct batadv_priv *bat_priv, struct sk_buff *skb,
774 struct batadv_unicast_packet *unicast_packet, 775 struct batadv_unicast_packet *unicast_packet,
775 u8 *dst_addr, unsigned short vid) 776 u8 *dst_addr, unsigned short vid)
776{ 777{
@@ -799,8 +800,10 @@ batadv_reroute_unicast_packet(struct batadv_priv *bat_priv,
799 } 800 }
800 801
801 /* update the packet header */ 802 /* update the packet header */
803 skb_postpull_rcsum(skb, unicast_packet, sizeof(*unicast_packet));
802 ether_addr_copy(unicast_packet->dest, orig_addr); 804 ether_addr_copy(unicast_packet->dest, orig_addr);
803 unicast_packet->ttvn = orig_ttvn; 805 unicast_packet->ttvn = orig_ttvn;
806 skb_postpush_rcsum(skb, unicast_packet, sizeof(*unicast_packet));
804 807
805 ret = true; 808 ret = true;
806out: 809out:
@@ -841,7 +844,7 @@ static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
841 * the packet to 844 * the packet to
842 */ 845 */
843 if (batadv_tt_local_client_is_roaming(bat_priv, ethhdr->h_dest, vid)) { 846 if (batadv_tt_local_client_is_roaming(bat_priv, ethhdr->h_dest, vid)) {
844 if (batadv_reroute_unicast_packet(bat_priv, unicast_packet, 847 if (batadv_reroute_unicast_packet(bat_priv, skb, unicast_packet,
845 ethhdr->h_dest, vid)) 848 ethhdr->h_dest, vid))
846 batadv_dbg_ratelimited(BATADV_DBG_TT, 849 batadv_dbg_ratelimited(BATADV_DBG_TT,
847 bat_priv, 850 bat_priv,
@@ -887,7 +890,7 @@ static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
887 * destination can possibly be updated and forwarded towards the new 890 * destination can possibly be updated and forwarded towards the new
888 * target host 891 * target host
889 */ 892 */
890 if (batadv_reroute_unicast_packet(bat_priv, unicast_packet, 893 if (batadv_reroute_unicast_packet(bat_priv, skb, unicast_packet,
891 ethhdr->h_dest, vid)) { 894 ethhdr->h_dest, vid)) {
892 batadv_dbg_ratelimited(BATADV_DBG_TT, bat_priv, 895 batadv_dbg_ratelimited(BATADV_DBG_TT, bat_priv,
893 "Rerouting unicast packet to %pM (dst=%pM): TTVN mismatch old_ttvn=%u new_ttvn=%u\n", 896 "Rerouting unicast packet to %pM (dst=%pM): TTVN mismatch old_ttvn=%u new_ttvn=%u\n",
@@ -910,12 +913,14 @@ static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
910 if (!primary_if) 913 if (!primary_if)
911 return false; 914 return false;
912 915
916 /* update the packet header */
917 skb_postpull_rcsum(skb, unicast_packet, sizeof(*unicast_packet));
913 ether_addr_copy(unicast_packet->dest, primary_if->net_dev->dev_addr); 918 ether_addr_copy(unicast_packet->dest, primary_if->net_dev->dev_addr);
919 unicast_packet->ttvn = curr_ttvn;
920 skb_postpush_rcsum(skb, unicast_packet, sizeof(*unicast_packet));
914 921
915 batadv_hardif_put(primary_if); 922 batadv_hardif_put(primary_if);
916 923
917 unicast_packet->ttvn = curr_ttvn;
918
919 return true; 924 return true;
920} 925}
921 926
@@ -968,14 +973,10 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
968 struct batadv_orig_node *orig_node = NULL, *orig_node_gw = NULL; 973 struct batadv_orig_node *orig_node = NULL, *orig_node_gw = NULL;
969 int check, hdr_size = sizeof(*unicast_packet); 974 int check, hdr_size = sizeof(*unicast_packet);
970 enum batadv_subtype subtype; 975 enum batadv_subtype subtype;
971 struct ethhdr *ethhdr;
972 int ret = NET_RX_DROP; 976 int ret = NET_RX_DROP;
973 bool is4addr, is_gw; 977 bool is4addr, is_gw;
974 978
975 unicast_packet = (struct batadv_unicast_packet *)skb->data; 979 unicast_packet = (struct batadv_unicast_packet *)skb->data;
976 unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data;
977 ethhdr = eth_hdr(skb);
978
979 is4addr = unicast_packet->packet_type == BATADV_UNICAST_4ADDR; 980 is4addr = unicast_packet->packet_type == BATADV_UNICAST_4ADDR;
980 /* the caller function should have already pulled 2 bytes */ 981 /* the caller function should have already pulled 2 bytes */
981 if (is4addr) 982 if (is4addr)
@@ -995,12 +996,14 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
995 if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size)) 996 if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size))
996 goto free_skb; 997 goto free_skb;
997 998
999 unicast_packet = (struct batadv_unicast_packet *)skb->data;
1000
998 /* packet for me */ 1001 /* packet for me */
999 if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) { 1002 if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
1000 /* If this is a unicast packet from another backgone gw, 1003 /* If this is a unicast packet from another backgone gw,
1001 * drop it. 1004 * drop it.
1002 */ 1005 */
1003 orig_addr_gw = ethhdr->h_source; 1006 orig_addr_gw = eth_hdr(skb)->h_source;
1004 orig_node_gw = batadv_orig_hash_find(bat_priv, orig_addr_gw); 1007 orig_node_gw = batadv_orig_hash_find(bat_priv, orig_addr_gw);
1005 if (orig_node_gw) { 1008 if (orig_node_gw) {
1006 is_gw = batadv_bla_is_backbone_gw(skb, orig_node_gw, 1009 is_gw = batadv_bla_is_backbone_gw(skb, orig_node_gw,
@@ -1015,6 +1018,8 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
1015 } 1018 }
1016 1019
1017 if (is4addr) { 1020 if (is4addr) {
1021 unicast_4addr_packet =
1022 (struct batadv_unicast_4addr_packet *)skb->data;
1018 subtype = unicast_4addr_packet->subtype; 1023 subtype = unicast_4addr_packet->subtype;
1019 batadv_dat_inc_counter(bat_priv, subtype); 1024 batadv_dat_inc_counter(bat_priv, subtype);
1020 1025
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 900c5ce21cd4..367a81fb785f 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -459,13 +459,7 @@ void batadv_interface_rx(struct net_device *soft_iface,
459 459
460 /* skb->dev & skb->pkt_type are set here */ 460 /* skb->dev & skb->pkt_type are set here */
461 skb->protocol = eth_type_trans(skb, soft_iface); 461 skb->protocol = eth_type_trans(skb, soft_iface);
462 462 skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
463 /* should not be necessary anymore as we use skb_pull_rcsum()
464 * TODO: please verify this and remove this TODO
465 * -- Dec 21st 2009, Simon Wunderlich
466 */
467
468 /* skb->ip_summed = CHECKSUM_UNNECESSARY; */
469 463
470 batadv_inc_counter(bat_priv, BATADV_CNT_RX); 464 batadv_inc_counter(bat_priv, BATADV_CNT_RX);
471 batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES, 465 batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index bb1578410e0c..a5aa6d61f4e2 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -167,7 +167,7 @@ struct batadv_hard_iface {
167 struct list_head list; 167 struct list_head list;
168 168
169 /** @if_num: identificator of the interface */ 169 /** @if_num: identificator of the interface */
170 s16 if_num; 170 unsigned int if_num;
171 171
172 /** @if_status: status of the interface for batman-adv */ 172 /** @if_status: status of the interface for batman-adv */
173 char if_status; 173 char if_status;
@@ -1596,7 +1596,7 @@ struct batadv_priv {
1596 atomic_t batman_queue_left; 1596 atomic_t batman_queue_left;
1597 1597
1598 /** @num_ifaces: number of interfaces assigned to this mesh interface */ 1598 /** @num_ifaces: number of interfaces assigned to this mesh interface */
1599 char num_ifaces; 1599 unsigned int num_ifaces;
1600 1600
1601 /** @mesh_obj: kobject for sysfs mesh subdirectory */ 1601 /** @mesh_obj: kobject for sysfs mesh subdirectory */
1602 struct kobject *mesh_obj; 1602 struct kobject *mesh_obj;
@@ -2186,15 +2186,16 @@ struct batadv_algo_orig_ops {
2186 * orig_node due to a new hard-interface being added into the mesh 2186 * orig_node due to a new hard-interface being added into the mesh
2187 * (optional) 2187 * (optional)
2188 */ 2188 */
2189 int (*add_if)(struct batadv_orig_node *orig_node, int max_if_num); 2189 int (*add_if)(struct batadv_orig_node *orig_node,
2190 unsigned int max_if_num);
2190 2191
2191 /** 2192 /**
2192 * @del_if: ask the routing algorithm to apply the needed changes to the 2193 * @del_if: ask the routing algorithm to apply the needed changes to the
2193 * orig_node due to an hard-interface being removed from the mesh 2194 * orig_node due to an hard-interface being removed from the mesh
2194 * (optional) 2195 * (optional)
2195 */ 2196 */
2196 int (*del_if)(struct batadv_orig_node *orig_node, int max_if_num, 2197 int (*del_if)(struct batadv_orig_node *orig_node,
2197 int del_if_num); 2198 unsigned int max_if_num, unsigned int del_if_num);
2198 2199
2199#ifdef CONFIG_BATMAN_ADV_DEBUGFS 2200#ifdef CONFIG_BATMAN_ADV_DEBUGFS
2200 /** @print: print the originator table (optional) */ 2201 /** @print: print the originator table (optional) */
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 01117ae84f1d..a2ddae2f37d7 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -2296,8 +2296,14 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
2296 else 2296 else
2297 sec_level = authreq_to_seclevel(auth); 2297 sec_level = authreq_to_seclevel(auth);
2298 2298
2299 if (smp_sufficient_security(hcon, sec_level, SMP_USE_LTK)) 2299 if (smp_sufficient_security(hcon, sec_level, SMP_USE_LTK)) {
2300 /* If link is already encrypted with sufficient security we
2301 * still need refresh encryption as per Core Spec 5.0 Vol 3,
2302 * Part H 2.4.6
2303 */
2304 smp_ltk_encrypt(conn, hcon->sec_level);
2300 return 0; 2305 return 0;
2306 }
2301 2307
2302 if (sec_level > hcon->pending_sec_level) 2308 if (sec_level > hcon->pending_sec_level)
2303 hcon->pending_sec_level = sec_level; 2309 hcon->pending_sec_level = sec_level;
diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c
index 27f1d4f2114a..9b16eaf33819 100644
--- a/net/bridge/br_netfilter_hooks.c
+++ b/net/bridge/br_netfilter_hooks.c
@@ -214,7 +214,7 @@ static int br_validate_ipv4(struct net *net, struct sk_buff *skb)
214 214
215 iph = ip_hdr(skb); 215 iph = ip_hdr(skb);
216 if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl))) 216 if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
217 goto inhdr_error; 217 goto csum_error;
218 218
219 len = ntohs(iph->tot_len); 219 len = ntohs(iph->tot_len);
220 if (skb->len < len) { 220 if (skb->len < len) {
@@ -236,6 +236,8 @@ static int br_validate_ipv4(struct net *net, struct sk_buff *skb)
236 */ 236 */
237 return 0; 237 return 0;
238 238
239csum_error:
240 __IP_INC_STATS(net, IPSTATS_MIB_CSUMERRORS);
239inhdr_error: 241inhdr_error:
240 __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); 242 __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS);
241drop: 243drop:
diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
index 0254c35b2bf0..126a8ea73c96 100644
--- a/net/bridge/br_sysfs_if.c
+++ b/net/bridge/br_sysfs_if.c
@@ -255,6 +255,9 @@ static ssize_t brport_show(struct kobject *kobj,
255 struct brport_attribute *brport_attr = to_brport_attr(attr); 255 struct brport_attribute *brport_attr = to_brport_attr(attr);
256 struct net_bridge_port *p = to_brport(kobj); 256 struct net_bridge_port *p = to_brport(kobj);
257 257
258 if (!brport_attr->show)
259 return -EINVAL;
260
258 return brport_attr->show(p, buf); 261 return brport_attr->show(p, buf);
259} 262}
260 263
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 51935270c651..9896f4975353 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -168,6 +168,8 @@ static struct net_bridge_vlan *br_vlan_get_master(struct net_bridge *br, u16 vid
168 masterv = br_vlan_find(vg, vid); 168 masterv = br_vlan_find(vg, vid);
169 if (WARN_ON(!masterv)) 169 if (WARN_ON(!masterv))
170 return NULL; 170 return NULL;
171 refcount_set(&masterv->refcnt, 1);
172 return masterv;
171 } 173 }
172 refcount_inc(&masterv->refcnt); 174 refcount_inc(&masterv->refcnt);
173 175
diff --git a/net/bridge/netfilter/ebt_among.c b/net/bridge/netfilter/ebt_among.c
index 279527f8b1fe..620e54f08296 100644
--- a/net/bridge/netfilter/ebt_among.c
+++ b/net/bridge/netfilter/ebt_among.c
@@ -172,32 +172,83 @@ ebt_among_mt(const struct sk_buff *skb, struct xt_action_param *par)
172 return true; 172 return true;
173} 173}
174 174
175static bool poolsize_invalid(const struct ebt_mac_wormhash *w)
176{
177 return w && w->poolsize >= (INT_MAX / sizeof(struct ebt_mac_wormhash_tuple));
178}
179
180static bool wormhash_offset_invalid(int off, unsigned int len)
181{
182 if (off == 0) /* not present */
183 return false;
184
185 if (off < (int)sizeof(struct ebt_among_info) ||
186 off % __alignof__(struct ebt_mac_wormhash))
187 return true;
188
189 off += sizeof(struct ebt_mac_wormhash);
190
191 return off > len;
192}
193
194static bool wormhash_sizes_valid(const struct ebt_mac_wormhash *wh, int a, int b)
195{
196 if (a == 0)
197 a = sizeof(struct ebt_among_info);
198
199 return ebt_mac_wormhash_size(wh) + a == b;
200}
201
175static int ebt_among_mt_check(const struct xt_mtchk_param *par) 202static int ebt_among_mt_check(const struct xt_mtchk_param *par)
176{ 203{
177 const struct ebt_among_info *info = par->matchinfo; 204 const struct ebt_among_info *info = par->matchinfo;
178 const struct ebt_entry_match *em = 205 const struct ebt_entry_match *em =
179 container_of(par->matchinfo, const struct ebt_entry_match, data); 206 container_of(par->matchinfo, const struct ebt_entry_match, data);
180 int expected_length = sizeof(struct ebt_among_info); 207 unsigned int expected_length = sizeof(struct ebt_among_info);
181 const struct ebt_mac_wormhash *wh_dst, *wh_src; 208 const struct ebt_mac_wormhash *wh_dst, *wh_src;
182 int err; 209 int err;
183 210
211 if (expected_length > em->match_size)
212 return -EINVAL;
213
214 if (wormhash_offset_invalid(info->wh_dst_ofs, em->match_size) ||
215 wormhash_offset_invalid(info->wh_src_ofs, em->match_size))
216 return -EINVAL;
217
184 wh_dst = ebt_among_wh_dst(info); 218 wh_dst = ebt_among_wh_dst(info);
185 wh_src = ebt_among_wh_src(info); 219 if (poolsize_invalid(wh_dst))
220 return -EINVAL;
221
186 expected_length += ebt_mac_wormhash_size(wh_dst); 222 expected_length += ebt_mac_wormhash_size(wh_dst);
223 if (expected_length > em->match_size)
224 return -EINVAL;
225
226 wh_src = ebt_among_wh_src(info);
227 if (poolsize_invalid(wh_src))
228 return -EINVAL;
229
230 if (info->wh_src_ofs < info->wh_dst_ofs) {
231 if (!wormhash_sizes_valid(wh_src, info->wh_src_ofs, info->wh_dst_ofs))
232 return -EINVAL;
233 } else {
234 if (!wormhash_sizes_valid(wh_dst, info->wh_dst_ofs, info->wh_src_ofs))
235 return -EINVAL;
236 }
237
187 expected_length += ebt_mac_wormhash_size(wh_src); 238 expected_length += ebt_mac_wormhash_size(wh_src);
188 239
189 if (em->match_size != EBT_ALIGN(expected_length)) { 240 if (em->match_size != EBT_ALIGN(expected_length)) {
190 pr_info("wrong size: %d against expected %d, rounded to %zd\n", 241 pr_err_ratelimited("wrong size: %d against expected %d, rounded to %zd\n",
191 em->match_size, expected_length, 242 em->match_size, expected_length,
192 EBT_ALIGN(expected_length)); 243 EBT_ALIGN(expected_length));
193 return -EINVAL; 244 return -EINVAL;
194 } 245 }
195 if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) { 246 if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
196 pr_info("dst integrity fail: %x\n", -err); 247 pr_err_ratelimited("dst integrity fail: %x\n", -err);
197 return -EINVAL; 248 return -EINVAL;
198 } 249 }
199 if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) { 250 if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
200 pr_info("src integrity fail: %x\n", -err); 251 pr_err_ratelimited("src integrity fail: %x\n", -err);
201 return -EINVAL; 252 return -EINVAL;
202 } 253 }
203 return 0; 254 return 0;
diff --git a/net/bridge/netfilter/ebt_limit.c b/net/bridge/netfilter/ebt_limit.c
index 61a9f1be1263..165b9d678cf1 100644
--- a/net/bridge/netfilter/ebt_limit.c
+++ b/net/bridge/netfilter/ebt_limit.c
@@ -72,8 +72,8 @@ static int ebt_limit_mt_check(const struct xt_mtchk_param *par)
72 /* Check for overflow. */ 72 /* Check for overflow. */
73 if (info->burst == 0 || 73 if (info->burst == 0 ||
74 user2credits(info->avg * info->burst) < user2credits(info->avg)) { 74 user2credits(info->avg * info->burst) < user2credits(info->avg)) {
75 pr_info("overflow, try lower: %u/%u\n", 75 pr_info_ratelimited("overflow, try lower: %u/%u\n",
76 info->avg, info->burst); 76 info->avg, info->burst);
77 return -EINVAL; 77 return -EINVAL;
78 } 78 }
79 79
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index 02c4b409d317..a94d23b0a9af 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -1641,7 +1641,8 @@ static int compat_match_to_user(struct ebt_entry_match *m, void __user **dstptr,
1641 int off = ebt_compat_match_offset(match, m->match_size); 1641 int off = ebt_compat_match_offset(match, m->match_size);
1642 compat_uint_t msize = m->match_size - off; 1642 compat_uint_t msize = m->match_size - off;
1643 1643
1644 BUG_ON(off >= m->match_size); 1644 if (WARN_ON(off >= m->match_size))
1645 return -EINVAL;
1645 1646
1646 if (copy_to_user(cm->u.name, match->name, 1647 if (copy_to_user(cm->u.name, match->name,
1647 strlen(match->name) + 1) || put_user(msize, &cm->match_size)) 1648 strlen(match->name) + 1) || put_user(msize, &cm->match_size))
@@ -1671,7 +1672,8 @@ static int compat_target_to_user(struct ebt_entry_target *t,
1671 int off = xt_compat_target_offset(target); 1672 int off = xt_compat_target_offset(target);
1672 compat_uint_t tsize = t->target_size - off; 1673 compat_uint_t tsize = t->target_size - off;
1673 1674
1674 BUG_ON(off >= t->target_size); 1675 if (WARN_ON(off >= t->target_size))
1676 return -EINVAL;
1675 1677
1676 if (copy_to_user(cm->u.name, target->name, 1678 if (copy_to_user(cm->u.name, target->name,
1677 strlen(target->name) + 1) || put_user(tsize, &cm->match_size)) 1679 strlen(target->name) + 1) || put_user(tsize, &cm->match_size))
@@ -1902,7 +1904,8 @@ static int ebt_buf_add(struct ebt_entries_buf_state *state,
1902 if (state->buf_kern_start == NULL) 1904 if (state->buf_kern_start == NULL)
1903 goto count_only; 1905 goto count_only;
1904 1906
1905 BUG_ON(state->buf_kern_offset + sz > state->buf_kern_len); 1907 if (WARN_ON(state->buf_kern_offset + sz > state->buf_kern_len))
1908 return -EINVAL;
1906 1909
1907 memcpy(state->buf_kern_start + state->buf_kern_offset, data, sz); 1910 memcpy(state->buf_kern_start + state->buf_kern_offset, data, sz);
1908 1911
@@ -1915,7 +1918,8 @@ static int ebt_buf_add_pad(struct ebt_entries_buf_state *state, unsigned int sz)
1915{ 1918{
1916 char *b = state->buf_kern_start; 1919 char *b = state->buf_kern_start;
1917 1920
1918 BUG_ON(b && state->buf_kern_offset > state->buf_kern_len); 1921 if (WARN_ON(b && state->buf_kern_offset > state->buf_kern_len))
1922 return -EINVAL;
1919 1923
1920 if (b != NULL && sz > 0) 1924 if (b != NULL && sz > 0)
1921 memset(b + state->buf_kern_offset, 0, sz); 1925 memset(b + state->buf_kern_offset, 0, sz);
@@ -1992,8 +1996,10 @@ static int compat_mtw_from_user(struct compat_ebt_entry_mwt *mwt,
1992 pad = XT_ALIGN(size_kern) - size_kern; 1996 pad = XT_ALIGN(size_kern) - size_kern;
1993 1997
1994 if (pad > 0 && dst) { 1998 if (pad > 0 && dst) {
1995 BUG_ON(state->buf_kern_len <= pad); 1999 if (WARN_ON(state->buf_kern_len <= pad))
1996 BUG_ON(state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad); 2000 return -EINVAL;
2001 if (WARN_ON(state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad))
2002 return -EINVAL;
1997 memset(dst + size_kern, 0, pad); 2003 memset(dst + size_kern, 0, pad);
1998 } 2004 }
1999 return off + match_size; 2005 return off + match_size;
@@ -2043,7 +2049,8 @@ static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32,
2043 if (ret < 0) 2049 if (ret < 0)
2044 return ret; 2050 return ret;
2045 2051
2046 BUG_ON(ret < match32->match_size); 2052 if (WARN_ON(ret < match32->match_size))
2053 return -EINVAL;
2047 growth += ret - match32->match_size; 2054 growth += ret - match32->match_size;
2048 growth += ebt_compat_entry_padsize(); 2055 growth += ebt_compat_entry_padsize();
2049 2056
@@ -2053,7 +2060,9 @@ static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32,
2053 if (match_kern) 2060 if (match_kern)
2054 match_kern->match_size = ret; 2061 match_kern->match_size = ret;
2055 2062
2056 WARN_ON(type == EBT_COMPAT_TARGET && size_left); 2063 if (WARN_ON(type == EBT_COMPAT_TARGET && size_left))
2064 return -EINVAL;
2065
2057 match32 = (struct compat_ebt_entry_mwt *) buf; 2066 match32 = (struct compat_ebt_entry_mwt *) buf;
2058 } 2067 }
2059 2068
@@ -2109,6 +2118,19 @@ static int size_entry_mwt(struct ebt_entry *entry, const unsigned char *base,
2109 * 2118 *
2110 * offsets are relative to beginning of struct ebt_entry (i.e., 0). 2119 * offsets are relative to beginning of struct ebt_entry (i.e., 0).
2111 */ 2120 */
2121 for (i = 0; i < 4 ; ++i) {
2122 if (offsets[i] > *total)
2123 return -EINVAL;
2124
2125 if (i < 3 && offsets[i] == *total)
2126 return -EINVAL;
2127
2128 if (i == 0)
2129 continue;
2130 if (offsets[i-1] > offsets[i])
2131 return -EINVAL;
2132 }
2133
2112 for (i = 0, j = 1 ; j < 4 ; j++, i++) { 2134 for (i = 0, j = 1 ; j < 4 ; j++, i++) {
2113 struct compat_ebt_entry_mwt *match32; 2135 struct compat_ebt_entry_mwt *match32;
2114 unsigned int size; 2136 unsigned int size;
@@ -2140,7 +2162,8 @@ static int size_entry_mwt(struct ebt_entry *entry, const unsigned char *base,
2140 2162
2141 startoff = state->buf_user_offset - startoff; 2163 startoff = state->buf_user_offset - startoff;
2142 2164
2143 BUG_ON(*total < startoff); 2165 if (WARN_ON(*total < startoff))
2166 return -EINVAL;
2144 *total -= startoff; 2167 *total -= startoff;
2145 return 0; 2168 return 0;
2146} 2169}
@@ -2267,7 +2290,8 @@ static int compat_do_replace(struct net *net, void __user *user,
2267 state.buf_kern_len = size64; 2290 state.buf_kern_len = size64;
2268 2291
2269 ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state); 2292 ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state);
2270 BUG_ON(ret < 0); /* parses same data again */ 2293 if (WARN_ON(ret < 0))
2294 goto out_unlock;
2271 2295
2272 vfree(entries_tmp); 2296 vfree(entries_tmp);
2273 tmp.entries_size = size64; 2297 tmp.entries_size = size64;
diff --git a/net/ceph/ceph_common.c b/net/ceph/ceph_common.c
index 1e492ef2a33d..4d4c82229e9e 100644
--- a/net/ceph/ceph_common.c
+++ b/net/ceph/ceph_common.c
@@ -418,6 +418,7 @@ ceph_parse_options(char *options, const char *dev_name,
418 opt->flags |= CEPH_OPT_FSID; 418 opt->flags |= CEPH_OPT_FSID;
419 break; 419 break;
420 case Opt_name: 420 case Opt_name:
421 kfree(opt->name);
421 opt->name = kstrndup(argstr[0].from, 422 opt->name = kstrndup(argstr[0].from,
422 argstr[0].to-argstr[0].from, 423 argstr[0].to-argstr[0].from,
423 GFP_KERNEL); 424 GFP_KERNEL);
@@ -427,6 +428,9 @@ ceph_parse_options(char *options, const char *dev_name,
427 } 428 }
428 break; 429 break;
429 case Opt_secret: 430 case Opt_secret:
431 ceph_crypto_key_destroy(opt->key);
432 kfree(opt->key);
433
430 opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL); 434 opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
431 if (!opt->key) { 435 if (!opt->key) {
432 err = -ENOMEM; 436 err = -ENOMEM;
@@ -437,6 +441,9 @@ ceph_parse_options(char *options, const char *dev_name,
437 goto out; 441 goto out;
438 break; 442 break;
439 case Opt_key: 443 case Opt_key:
444 ceph_crypto_key_destroy(opt->key);
445 kfree(opt->key);
446
440 opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL); 447 opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
441 if (!opt->key) { 448 if (!opt->key) {
442 err = -ENOMEM; 449 err = -ENOMEM;
diff --git a/net/core/dev.c b/net/core/dev.c
index dda9d7b9a840..12be20535714 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2382,8 +2382,11 @@ EXPORT_SYMBOL(netdev_set_num_tc);
2382 */ 2382 */
2383int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) 2383int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)
2384{ 2384{
2385 bool disabling;
2385 int rc; 2386 int rc;
2386 2387
2388 disabling = txq < dev->real_num_tx_queues;
2389
2387 if (txq < 1 || txq > dev->num_tx_queues) 2390 if (txq < 1 || txq > dev->num_tx_queues)
2388 return -EINVAL; 2391 return -EINVAL;
2389 2392
@@ -2399,15 +2402,19 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)
2399 if (dev->num_tc) 2402 if (dev->num_tc)
2400 netif_setup_tc(dev, txq); 2403 netif_setup_tc(dev, txq);
2401 2404
2402 if (txq < dev->real_num_tx_queues) { 2405 dev->real_num_tx_queues = txq;
2406
2407 if (disabling) {
2408 synchronize_net();
2403 qdisc_reset_all_tx_gt(dev, txq); 2409 qdisc_reset_all_tx_gt(dev, txq);
2404#ifdef CONFIG_XPS 2410#ifdef CONFIG_XPS
2405 netif_reset_xps_queues_gt(dev, txq); 2411 netif_reset_xps_queues_gt(dev, txq);
2406#endif 2412#endif
2407 } 2413 }
2414 } else {
2415 dev->real_num_tx_queues = txq;
2408 } 2416 }
2409 2417
2410 dev->real_num_tx_queues = txq;
2411 return 0; 2418 return 0;
2412} 2419}
2413EXPORT_SYMBOL(netif_set_real_num_tx_queues); 2420EXPORT_SYMBOL(netif_set_real_num_tx_queues);
@@ -3271,15 +3278,23 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
3271#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO) 3278#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
3272static void skb_update_prio(struct sk_buff *skb) 3279static void skb_update_prio(struct sk_buff *skb)
3273{ 3280{
3274 struct netprio_map *map = rcu_dereference_bh(skb->dev->priomap); 3281 const struct netprio_map *map;
3282 const struct sock *sk;
3283 unsigned int prioidx;
3275 3284
3276 if (!skb->priority && skb->sk && map) { 3285 if (skb->priority)
3277 unsigned int prioidx = 3286 return;
3278 sock_cgroup_prioidx(&skb->sk->sk_cgrp_data); 3287 map = rcu_dereference_bh(skb->dev->priomap);
3288 if (!map)
3289 return;
3290 sk = skb_to_full_sk(skb);
3291 if (!sk)
3292 return;
3279 3293
3280 if (prioidx < map->priomap_len) 3294 prioidx = sock_cgroup_prioidx(&sk->sk_cgrp_data);
3281 skb->priority = map->priomap[prioidx]; 3295
3282 } 3296 if (prioidx < map->priomap_len)
3297 skb->priority = map->priomap[prioidx];
3283} 3298}
3284#else 3299#else
3285#define skb_update_prio(skb) 3300#define skb_update_prio(skb)
@@ -6389,6 +6404,7 @@ static int __netdev_upper_dev_link(struct net_device *dev,
6389 .linking = true, 6404 .linking = true,
6390 .upper_info = upper_info, 6405 .upper_info = upper_info,
6391 }; 6406 };
6407 struct net_device *master_dev;
6392 int ret = 0; 6408 int ret = 0;
6393 6409
6394 ASSERT_RTNL(); 6410 ASSERT_RTNL();
@@ -6400,11 +6416,14 @@ static int __netdev_upper_dev_link(struct net_device *dev,
6400 if (netdev_has_upper_dev(upper_dev, dev)) 6416 if (netdev_has_upper_dev(upper_dev, dev))
6401 return -EBUSY; 6417 return -EBUSY;
6402 6418
6403 if (netdev_has_upper_dev(dev, upper_dev)) 6419 if (!master) {
6404 return -EEXIST; 6420 if (netdev_has_upper_dev(dev, upper_dev))
6405 6421 return -EEXIST;
6406 if (master && netdev_master_upper_dev_get(dev)) 6422 } else {
6407 return -EBUSY; 6423 master_dev = netdev_master_upper_dev_get(dev);
6424 if (master_dev)
6425 return master_dev == upper_dev ? -EEXIST : -EBUSY;
6426 }
6408 6427
6409 ret = call_netdevice_notifiers_info(NETDEV_PRECHANGEUPPER, 6428 ret = call_netdevice_notifiers_info(NETDEV_PRECHANGEUPPER,
6410 &changeupper_info.info); 6429 &changeupper_info.info);
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 0ab1af04296c..a04e1e88bf3a 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -402,8 +402,6 @@ int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr, bool *need_c
402 if (colon) 402 if (colon)
403 *colon = 0; 403 *colon = 0;
404 404
405 dev_load(net, ifr->ifr_name);
406
407 /* 405 /*
408 * See which interface the caller is talking about. 406 * See which interface the caller is talking about.
409 */ 407 */
@@ -423,6 +421,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr, bool *need_c
423 case SIOCGIFMAP: 421 case SIOCGIFMAP:
424 case SIOCGIFINDEX: 422 case SIOCGIFINDEX:
425 case SIOCGIFTXQLEN: 423 case SIOCGIFTXQLEN:
424 dev_load(net, ifr->ifr_name);
426 rcu_read_lock(); 425 rcu_read_lock();
427 ret = dev_ifsioc_locked(net, ifr, cmd); 426 ret = dev_ifsioc_locked(net, ifr, cmd);
428 rcu_read_unlock(); 427 rcu_read_unlock();
@@ -431,6 +430,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr, bool *need_c
431 return ret; 430 return ret;
432 431
433 case SIOCETHTOOL: 432 case SIOCETHTOOL:
433 dev_load(net, ifr->ifr_name);
434 rtnl_lock(); 434 rtnl_lock();
435 ret = dev_ethtool(net, ifr); 435 ret = dev_ethtool(net, ifr);
436 rtnl_unlock(); 436 rtnl_unlock();
@@ -447,6 +447,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr, bool *need_c
447 case SIOCGMIIPHY: 447 case SIOCGMIIPHY:
448 case SIOCGMIIREG: 448 case SIOCGMIIREG:
449 case SIOCSIFNAME: 449 case SIOCSIFNAME:
450 dev_load(net, ifr->ifr_name);
450 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) 451 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
451 return -EPERM; 452 return -EPERM;
452 rtnl_lock(); 453 rtnl_lock();
@@ -494,6 +495,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr, bool *need_c
494 /* fall through */ 495 /* fall through */
495 case SIOCBONDSLAVEINFOQUERY: 496 case SIOCBONDSLAVEINFOQUERY:
496 case SIOCBONDINFOQUERY: 497 case SIOCBONDINFOQUERY:
498 dev_load(net, ifr->ifr_name);
497 rtnl_lock(); 499 rtnl_lock();
498 ret = dev_ifsioc(net, ifr, cmd); 500 ret = dev_ifsioc(net, ifr, cmd);
499 rtnl_unlock(); 501 rtnl_unlock();
@@ -518,6 +520,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr, bool *need_c
518 cmd == SIOCGHWTSTAMP || 520 cmd == SIOCGHWTSTAMP ||
519 (cmd >= SIOCDEVPRIVATE && 521 (cmd >= SIOCDEVPRIVATE &&
520 cmd <= SIOCDEVPRIVATE + 15)) { 522 cmd <= SIOCDEVPRIVATE + 15)) {
523 dev_load(net, ifr->ifr_name);
521 rtnl_lock(); 524 rtnl_lock();
522 ret = dev_ifsioc(net, ifr, cmd); 525 ret = dev_ifsioc(net, ifr, cmd);
523 rtnl_unlock(); 526 rtnl_unlock();
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 18d385ed8237..effd4848c2b4 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -1695,10 +1695,11 @@ static int devlink_dpipe_table_put(struct sk_buff *skb,
1695 goto nla_put_failure; 1695 goto nla_put_failure;
1696 1696
1697 if (table->resource_valid) { 1697 if (table->resource_valid) {
1698 nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID, 1698 if (nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID,
1699 table->resource_id, DEVLINK_ATTR_PAD); 1699 table->resource_id, DEVLINK_ATTR_PAD) ||
1700 nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS, 1700 nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS,
1701 table->resource_units, DEVLINK_ATTR_PAD); 1701 table->resource_units, DEVLINK_ATTR_PAD))
1702 goto nla_put_failure;
1702 } 1703 }
1703 if (devlink_dpipe_matches_put(table, skb)) 1704 if (devlink_dpipe_matches_put(table, skb))
1704 goto nla_put_failure; 1705 goto nla_put_failure;
@@ -1797,7 +1798,7 @@ send_done:
1797 if (!nlh) { 1798 if (!nlh) {
1798 err = devlink_dpipe_send_and_alloc_skb(&skb, info); 1799 err = devlink_dpipe_send_and_alloc_skb(&skb, info);
1799 if (err) 1800 if (err)
1800 goto err_skb_send_alloc; 1801 return err;
1801 goto send_done; 1802 goto send_done;
1802 } 1803 }
1803 1804
@@ -1806,7 +1807,6 @@ send_done:
1806nla_put_failure: 1807nla_put_failure:
1807 err = -EMSGSIZE; 1808 err = -EMSGSIZE;
1808err_table_put: 1809err_table_put:
1809err_skb_send_alloc:
1810 genlmsg_cancel(skb, hdr); 1810 genlmsg_cancel(skb, hdr);
1811 nlmsg_free(skb); 1811 nlmsg_free(skb);
1812 return err; 1812 return err;
@@ -2072,7 +2072,7 @@ static int devlink_dpipe_entries_fill(struct genl_info *info,
2072 table->counters_enabled, 2072 table->counters_enabled,
2073 &dump_ctx); 2073 &dump_ctx);
2074 if (err) 2074 if (err)
2075 goto err_entries_dump; 2075 return err;
2076 2076
2077send_done: 2077send_done:
2078 nlh = nlmsg_put(dump_ctx.skb, info->snd_portid, info->snd_seq, 2078 nlh = nlmsg_put(dump_ctx.skb, info->snd_portid, info->snd_seq,
@@ -2080,16 +2080,10 @@ send_done:
2080 if (!nlh) { 2080 if (!nlh) {
2081 err = devlink_dpipe_send_and_alloc_skb(&dump_ctx.skb, info); 2081 err = devlink_dpipe_send_and_alloc_skb(&dump_ctx.skb, info);
2082 if (err) 2082 if (err)
2083 goto err_skb_send_alloc; 2083 return err;
2084 goto send_done; 2084 goto send_done;
2085 } 2085 }
2086 return genlmsg_reply(dump_ctx.skb, info); 2086 return genlmsg_reply(dump_ctx.skb, info);
2087
2088err_entries_dump:
2089err_skb_send_alloc:
2090 genlmsg_cancel(dump_ctx.skb, dump_ctx.hdr);
2091 nlmsg_free(dump_ctx.skb);
2092 return err;
2093} 2087}
2094 2088
2095static int devlink_nl_cmd_dpipe_entries_get(struct sk_buff *skb, 2089static int devlink_nl_cmd_dpipe_entries_get(struct sk_buff *skb,
@@ -2228,7 +2222,7 @@ send_done:
2228 if (!nlh) { 2222 if (!nlh) {
2229 err = devlink_dpipe_send_and_alloc_skb(&skb, info); 2223 err = devlink_dpipe_send_and_alloc_skb(&skb, info);
2230 if (err) 2224 if (err)
2231 goto err_skb_send_alloc; 2225 return err;
2232 goto send_done; 2226 goto send_done;
2233 } 2227 }
2234 return genlmsg_reply(skb, info); 2228 return genlmsg_reply(skb, info);
@@ -2236,7 +2230,6 @@ send_done:
2236nla_put_failure: 2230nla_put_failure:
2237 err = -EMSGSIZE; 2231 err = -EMSGSIZE;
2238err_table_put: 2232err_table_put:
2239err_skb_send_alloc:
2240 genlmsg_cancel(skb, hdr); 2233 genlmsg_cancel(skb, hdr);
2241 nlmsg_free(skb); 2234 nlmsg_free(skb);
2242 return err; 2235 return err;
@@ -2332,7 +2325,7 @@ devlink_resource_validate_children(struct devlink_resource *resource)
2332 list_for_each_entry(child_resource, &resource->resource_list, list) 2325 list_for_each_entry(child_resource, &resource->resource_list, list)
2333 parts_size += child_resource->size_new; 2326 parts_size += child_resource->size_new;
2334 2327
2335 if (parts_size > resource->size) 2328 if (parts_size > resource->size_new)
2336 size_valid = false; 2329 size_valid = false;
2337out: 2330out:
2338 resource->size_valid = size_valid; 2331 resource->size_valid = size_valid;
@@ -2372,20 +2365,22 @@ static int devlink_nl_cmd_resource_set(struct sk_buff *skb,
2372 return 0; 2365 return 0;
2373} 2366}
2374 2367
2375static void 2368static int
2376devlink_resource_size_params_put(struct devlink_resource *resource, 2369devlink_resource_size_params_put(struct devlink_resource *resource,
2377 struct sk_buff *skb) 2370 struct sk_buff *skb)
2378{ 2371{
2379 struct devlink_resource_size_params *size_params; 2372 struct devlink_resource_size_params *size_params;
2380 2373
2381 size_params = resource->size_params; 2374 size_params = &resource->size_params;
2382 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_GRAN, 2375 if (nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_GRAN,
2383 size_params->size_granularity, DEVLINK_ATTR_PAD); 2376 size_params->size_granularity, DEVLINK_ATTR_PAD) ||
2384 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MAX, 2377 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MAX,
2385 size_params->size_max, DEVLINK_ATTR_PAD); 2378 size_params->size_max, DEVLINK_ATTR_PAD) ||
2386 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MIN, 2379 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MIN,
2387 size_params->size_min, DEVLINK_ATTR_PAD); 2380 size_params->size_min, DEVLINK_ATTR_PAD) ||
2388 nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_UNIT, size_params->unit); 2381 nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_UNIT, size_params->unit))
2382 return -EMSGSIZE;
2383 return 0;
2389} 2384}
2390 2385
2391static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb, 2386static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb,
@@ -2409,10 +2404,12 @@ static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb,
2409 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_NEW, 2404 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_NEW,
2410 resource->size_new, DEVLINK_ATTR_PAD); 2405 resource->size_new, DEVLINK_ATTR_PAD);
2411 if (resource->resource_ops && resource->resource_ops->occ_get) 2406 if (resource->resource_ops && resource->resource_ops->occ_get)
2412 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_OCC, 2407 if (nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_OCC,
2413 resource->resource_ops->occ_get(devlink), 2408 resource->resource_ops->occ_get(devlink),
2414 DEVLINK_ATTR_PAD); 2409 DEVLINK_ATTR_PAD))
2415 devlink_resource_size_params_put(resource, skb); 2410 goto nla_put_failure;
2411 if (devlink_resource_size_params_put(resource, skb))
2412 goto nla_put_failure;
2416 if (list_empty(&resource->resource_list)) 2413 if (list_empty(&resource->resource_list))
2417 goto out; 2414 goto out;
2418 2415
@@ -3151,7 +3148,7 @@ int devlink_resource_register(struct devlink *devlink,
3151 u64 resource_size, 3148 u64 resource_size,
3152 u64 resource_id, 3149 u64 resource_id,
3153 u64 parent_resource_id, 3150 u64 parent_resource_id,
3154 struct devlink_resource_size_params *size_params, 3151 const struct devlink_resource_size_params *size_params,
3155 const struct devlink_resource_ops *resource_ops) 3152 const struct devlink_resource_ops *resource_ops)
3156{ 3153{
3157 struct devlink_resource *resource; 3154 struct devlink_resource *resource;
@@ -3194,7 +3191,8 @@ int devlink_resource_register(struct devlink *devlink,
3194 resource->id = resource_id; 3191 resource->id = resource_id;
3195 resource->resource_ops = resource_ops; 3192 resource->resource_ops = resource_ops;
3196 resource->size_valid = true; 3193 resource->size_valid = true;
3197 resource->size_params = size_params; 3194 memcpy(&resource->size_params, size_params,
3195 sizeof(resource->size_params));
3198 INIT_LIST_HEAD(&resource->resource_list); 3196 INIT_LIST_HEAD(&resource->resource_list);
3199 list_add_tail(&resource->list, resource_list); 3197 list_add_tail(&resource->list, resource_list);
3200out: 3198out:
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 494e6a5d7306..3f89c76d5c24 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -2520,11 +2520,14 @@ static int set_phy_tunable(struct net_device *dev, void __user *useraddr)
2520static int ethtool_get_fecparam(struct net_device *dev, void __user *useraddr) 2520static int ethtool_get_fecparam(struct net_device *dev, void __user *useraddr)
2521{ 2521{
2522 struct ethtool_fecparam fecparam = { ETHTOOL_GFECPARAM }; 2522 struct ethtool_fecparam fecparam = { ETHTOOL_GFECPARAM };
2523 int rc;
2523 2524
2524 if (!dev->ethtool_ops->get_fecparam) 2525 if (!dev->ethtool_ops->get_fecparam)
2525 return -EOPNOTSUPP; 2526 return -EOPNOTSUPP;
2526 2527
2527 dev->ethtool_ops->get_fecparam(dev, &fecparam); 2528 rc = dev->ethtool_ops->get_fecparam(dev, &fecparam);
2529 if (rc)
2530 return rc;
2528 2531
2529 if (copy_to_user(useraddr, &fecparam, sizeof(fecparam))) 2532 if (copy_to_user(useraddr, &fecparam, sizeof(fecparam)))
2530 return -EFAULT; 2533 return -EFAULT;
diff --git a/net/core/filter.c b/net/core/filter.c
index 08ab4c65a998..48aa7c7320db 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2087,6 +2087,10 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb)
2087 u32 off = skb_mac_header_len(skb); 2087 u32 off = skb_mac_header_len(skb);
2088 int ret; 2088 int ret;
2089 2089
2090 /* SCTP uses GSO_BY_FRAGS, thus cannot adjust it. */
2091 if (skb_is_gso(skb) && unlikely(skb_is_gso_sctp(skb)))
2092 return -ENOTSUPP;
2093
2090 ret = skb_cow(skb, len_diff); 2094 ret = skb_cow(skb, len_diff);
2091 if (unlikely(ret < 0)) 2095 if (unlikely(ret < 0))
2092 return ret; 2096 return ret;
@@ -2096,19 +2100,21 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb)
2096 return ret; 2100 return ret;
2097 2101
2098 if (skb_is_gso(skb)) { 2102 if (skb_is_gso(skb)) {
2103 struct skb_shared_info *shinfo = skb_shinfo(skb);
2104
2099 /* SKB_GSO_TCPV4 needs to be changed into 2105 /* SKB_GSO_TCPV4 needs to be changed into
2100 * SKB_GSO_TCPV6. 2106 * SKB_GSO_TCPV6.
2101 */ 2107 */
2102 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) { 2108 if (shinfo->gso_type & SKB_GSO_TCPV4) {
2103 skb_shinfo(skb)->gso_type &= ~SKB_GSO_TCPV4; 2109 shinfo->gso_type &= ~SKB_GSO_TCPV4;
2104 skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6; 2110 shinfo->gso_type |= SKB_GSO_TCPV6;
2105 } 2111 }
2106 2112
2107 /* Due to IPv6 header, MSS needs to be downgraded. */ 2113 /* Due to IPv6 header, MSS needs to be downgraded. */
2108 skb_shinfo(skb)->gso_size -= len_diff; 2114 skb_decrease_gso_size(shinfo, len_diff);
2109 /* Header must be checked, and gso_segs recomputed. */ 2115 /* Header must be checked, and gso_segs recomputed. */
2110 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY; 2116 shinfo->gso_type |= SKB_GSO_DODGY;
2111 skb_shinfo(skb)->gso_segs = 0; 2117 shinfo->gso_segs = 0;
2112 } 2118 }
2113 2119
2114 skb->protocol = htons(ETH_P_IPV6); 2120 skb->protocol = htons(ETH_P_IPV6);
@@ -2123,6 +2129,10 @@ static int bpf_skb_proto_6_to_4(struct sk_buff *skb)
2123 u32 off = skb_mac_header_len(skb); 2129 u32 off = skb_mac_header_len(skb);
2124 int ret; 2130 int ret;
2125 2131
2132 /* SCTP uses GSO_BY_FRAGS, thus cannot adjust it. */
2133 if (skb_is_gso(skb) && unlikely(skb_is_gso_sctp(skb)))
2134 return -ENOTSUPP;
2135
2126 ret = skb_unclone(skb, GFP_ATOMIC); 2136 ret = skb_unclone(skb, GFP_ATOMIC);
2127 if (unlikely(ret < 0)) 2137 if (unlikely(ret < 0))
2128 return ret; 2138 return ret;
@@ -2132,19 +2142,21 @@ static int bpf_skb_proto_6_to_4(struct sk_buff *skb)
2132 return ret; 2142 return ret;
2133 2143
2134 if (skb_is_gso(skb)) { 2144 if (skb_is_gso(skb)) {
2145 struct skb_shared_info *shinfo = skb_shinfo(skb);
2146
2135 /* SKB_GSO_TCPV6 needs to be changed into 2147 /* SKB_GSO_TCPV6 needs to be changed into
2136 * SKB_GSO_TCPV4. 2148 * SKB_GSO_TCPV4.
2137 */ 2149 */
2138 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) { 2150 if (shinfo->gso_type & SKB_GSO_TCPV6) {
2139 skb_shinfo(skb)->gso_type &= ~SKB_GSO_TCPV6; 2151 shinfo->gso_type &= ~SKB_GSO_TCPV6;
2140 skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4; 2152 shinfo->gso_type |= SKB_GSO_TCPV4;
2141 } 2153 }
2142 2154
2143 /* Due to IPv4 header, MSS can be upgraded. */ 2155 /* Due to IPv4 header, MSS can be upgraded. */
2144 skb_shinfo(skb)->gso_size += len_diff; 2156 skb_increase_gso_size(shinfo, len_diff);
2145 /* Header must be checked, and gso_segs recomputed. */ 2157 /* Header must be checked, and gso_segs recomputed. */
2146 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY; 2158 shinfo->gso_type |= SKB_GSO_DODGY;
2147 skb_shinfo(skb)->gso_segs = 0; 2159 shinfo->gso_segs = 0;
2148 } 2160 }
2149 2161
2150 skb->protocol = htons(ETH_P_IP); 2162 skb->protocol = htons(ETH_P_IP);
@@ -2243,6 +2255,10 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 len_diff)
2243 u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb); 2255 u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb);
2244 int ret; 2256 int ret;
2245 2257
2258 /* SCTP uses GSO_BY_FRAGS, thus cannot adjust it. */
2259 if (skb_is_gso(skb) && unlikely(skb_is_gso_sctp(skb)))
2260 return -ENOTSUPP;
2261
2246 ret = skb_cow(skb, len_diff); 2262 ret = skb_cow(skb, len_diff);
2247 if (unlikely(ret < 0)) 2263 if (unlikely(ret < 0))
2248 return ret; 2264 return ret;
@@ -2252,11 +2268,13 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 len_diff)
2252 return ret; 2268 return ret;
2253 2269
2254 if (skb_is_gso(skb)) { 2270 if (skb_is_gso(skb)) {
2271 struct skb_shared_info *shinfo = skb_shinfo(skb);
2272
2255 /* Due to header grow, MSS needs to be downgraded. */ 2273 /* Due to header grow, MSS needs to be downgraded. */
2256 skb_shinfo(skb)->gso_size -= len_diff; 2274 skb_decrease_gso_size(shinfo, len_diff);
2257 /* Header must be checked, and gso_segs recomputed. */ 2275 /* Header must be checked, and gso_segs recomputed. */
2258 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY; 2276 shinfo->gso_type |= SKB_GSO_DODGY;
2259 skb_shinfo(skb)->gso_segs = 0; 2277 shinfo->gso_segs = 0;
2260 } 2278 }
2261 2279
2262 return 0; 2280 return 0;
@@ -2267,6 +2285,10 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 len_diff)
2267 u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb); 2285 u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb);
2268 int ret; 2286 int ret;
2269 2287
2288 /* SCTP uses GSO_BY_FRAGS, thus cannot adjust it. */
2289 if (skb_is_gso(skb) && unlikely(skb_is_gso_sctp(skb)))
2290 return -ENOTSUPP;
2291
2270 ret = skb_unclone(skb, GFP_ATOMIC); 2292 ret = skb_unclone(skb, GFP_ATOMIC);
2271 if (unlikely(ret < 0)) 2293 if (unlikely(ret < 0))
2272 return ret; 2294 return ret;
@@ -2276,11 +2298,13 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 len_diff)
2276 return ret; 2298 return ret;
2277 2299
2278 if (skb_is_gso(skb)) { 2300 if (skb_is_gso(skb)) {
2301 struct skb_shared_info *shinfo = skb_shinfo(skb);
2302
2279 /* Due to header shrink, MSS can be upgraded. */ 2303 /* Due to header shrink, MSS can be upgraded. */
2280 skb_shinfo(skb)->gso_size += len_diff; 2304 skb_increase_gso_size(shinfo, len_diff);
2281 /* Header must be checked, and gso_segs recomputed. */ 2305 /* Header must be checked, and gso_segs recomputed. */
2282 skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY; 2306 shinfo->gso_type |= SKB_GSO_DODGY;
2283 skb_shinfo(skb)->gso_segs = 0; 2307 shinfo->gso_segs = 0;
2284 } 2308 }
2285 2309
2286 return 0; 2310 return 0;
@@ -3381,17 +3405,13 @@ BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,
3381 struct sock *sk = bpf_sock->sk; 3405 struct sock *sk = bpf_sock->sk;
3382 int val = argval & BPF_SOCK_OPS_ALL_CB_FLAGS; 3406 int val = argval & BPF_SOCK_OPS_ALL_CB_FLAGS;
3383 3407
3384 if (!sk_fullsock(sk)) 3408 if (!IS_ENABLED(CONFIG_INET) || !sk_fullsock(sk))
3385 return -EINVAL; 3409 return -EINVAL;
3386 3410
3387#ifdef CONFIG_INET
3388 if (val) 3411 if (val)
3389 tcp_sk(sk)->bpf_sock_ops_cb_flags = val; 3412 tcp_sk(sk)->bpf_sock_ops_cb_flags = val;
3390 3413
3391 return argval & (~BPF_SOCK_OPS_ALL_CB_FLAGS); 3414 return argval & (~BPF_SOCK_OPS_ALL_CB_FLAGS);
3392#else
3393 return -EINVAL;
3394#endif
3395} 3415}
3396 3416
3397static const struct bpf_func_proto bpf_sock_ops_cb_flags_set_proto = { 3417static const struct bpf_func_proto bpf_sock_ops_cb_flags_set_proto = {
diff --git a/net/core/gen_estimator.c b/net/core/gen_estimator.c
index 0a3f88f08727..98fd12721221 100644
--- a/net/core/gen_estimator.c
+++ b/net/core/gen_estimator.c
@@ -66,6 +66,7 @@ struct net_rate_estimator {
66static void est_fetch_counters(struct net_rate_estimator *e, 66static void est_fetch_counters(struct net_rate_estimator *e,
67 struct gnet_stats_basic_packed *b) 67 struct gnet_stats_basic_packed *b)
68{ 68{
69 memset(b, 0, sizeof(*b));
69 if (e->stats_lock) 70 if (e->stats_lock)
70 spin_lock(e->stats_lock); 71 spin_lock(e->stats_lock);
71 72
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 09bd89c90a71..1e7acdc30732 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -4179,7 +4179,7 @@ int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
4179 4179
4180 skb_queue_tail(&sk->sk_error_queue, skb); 4180 skb_queue_tail(&sk->sk_error_queue, skb);
4181 if (!sock_flag(sk, SOCK_DEAD)) 4181 if (!sock_flag(sk, SOCK_DEAD))
4182 sk->sk_data_ready(sk); 4182 sk->sk_error_report(sk);
4183 return 0; 4183 return 0;
4184} 4184}
4185EXPORT_SYMBOL(sock_queue_err_skb); 4185EXPORT_SYMBOL(sock_queue_err_skb);
@@ -4891,7 +4891,7 @@ EXPORT_SYMBOL_GPL(skb_scrub_packet);
4891 * 4891 *
4892 * The MAC/L2 or network (IP, IPv6) headers are not accounted for. 4892 * The MAC/L2 or network (IP, IPv6) headers are not accounted for.
4893 */ 4893 */
4894unsigned int skb_gso_transport_seglen(const struct sk_buff *skb) 4894static unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)
4895{ 4895{
4896 const struct skb_shared_info *shinfo = skb_shinfo(skb); 4896 const struct skb_shared_info *shinfo = skb_shinfo(skb);
4897 unsigned int thlen = 0; 4897 unsigned int thlen = 0;
@@ -4904,7 +4904,7 @@ unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)
4904 thlen += inner_tcp_hdrlen(skb); 4904 thlen += inner_tcp_hdrlen(skb);
4905 } else if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) { 4905 } else if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) {
4906 thlen = tcp_hdrlen(skb); 4906 thlen = tcp_hdrlen(skb);
4907 } else if (unlikely(shinfo->gso_type & SKB_GSO_SCTP)) { 4907 } else if (unlikely(skb_is_gso_sctp(skb))) {
4908 thlen = sizeof(struct sctphdr); 4908 thlen = sizeof(struct sctphdr);
4909 } 4909 }
4910 /* UFO sets gso_size to the size of the fragmentation 4910 /* UFO sets gso_size to the size of the fragmentation
@@ -4913,7 +4913,40 @@ unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)
4913 */ 4913 */
4914 return thlen + shinfo->gso_size; 4914 return thlen + shinfo->gso_size;
4915} 4915}
4916EXPORT_SYMBOL_GPL(skb_gso_transport_seglen); 4916
4917/**
4918 * skb_gso_network_seglen - Return length of individual segments of a gso packet
4919 *
4920 * @skb: GSO skb
4921 *
4922 * skb_gso_network_seglen is used to determine the real size of the
4923 * individual segments, including Layer3 (IP, IPv6) and L4 headers (TCP/UDP).
4924 *
4925 * The MAC/L2 header is not accounted for.
4926 */
4927static unsigned int skb_gso_network_seglen(const struct sk_buff *skb)
4928{
4929 unsigned int hdr_len = skb_transport_header(skb) -
4930 skb_network_header(skb);
4931
4932 return hdr_len + skb_gso_transport_seglen(skb);
4933}
4934
4935/**
4936 * skb_gso_mac_seglen - Return length of individual segments of a gso packet
4937 *
4938 * @skb: GSO skb
4939 *
4940 * skb_gso_mac_seglen is used to determine the real size of the
4941 * individual segments, including MAC/L2, Layer3 (IP, IPv6) and L4
4942 * headers (TCP/UDP).
4943 */
4944static unsigned int skb_gso_mac_seglen(const struct sk_buff *skb)
4945{
4946 unsigned int hdr_len = skb_transport_header(skb) - skb_mac_header(skb);
4947
4948 return hdr_len + skb_gso_transport_seglen(skb);
4949}
4917 4950
4918/** 4951/**
4919 * skb_gso_size_check - check the skb size, considering GSO_BY_FRAGS 4952 * skb_gso_size_check - check the skb size, considering GSO_BY_FRAGS
@@ -4955,19 +4988,20 @@ static inline bool skb_gso_size_check(const struct sk_buff *skb,
4955} 4988}
4956 4989
4957/** 4990/**
4958 * skb_gso_validate_mtu - Return in case such skb fits a given MTU 4991 * skb_gso_validate_network_len - Will a split GSO skb fit into a given MTU?
4959 * 4992 *
4960 * @skb: GSO skb 4993 * @skb: GSO skb
4961 * @mtu: MTU to validate against 4994 * @mtu: MTU to validate against
4962 * 4995 *
4963 * skb_gso_validate_mtu validates if a given skb will fit a wanted MTU 4996 * skb_gso_validate_network_len validates if a given skb will fit a
4964 * once split. 4997 * wanted MTU once split. It considers L3 headers, L4 headers, and the
4998 * payload.
4965 */ 4999 */
4966bool skb_gso_validate_mtu(const struct sk_buff *skb, unsigned int mtu) 5000bool skb_gso_validate_network_len(const struct sk_buff *skb, unsigned int mtu)
4967{ 5001{
4968 return skb_gso_size_check(skb, skb_gso_network_seglen(skb), mtu); 5002 return skb_gso_size_check(skb, skb_gso_network_seglen(skb), mtu);
4969} 5003}
4970EXPORT_SYMBOL_GPL(skb_gso_validate_mtu); 5004EXPORT_SYMBOL_GPL(skb_gso_validate_network_len);
4971 5005
4972/** 5006/**
4973 * skb_gso_validate_mac_len - Will a split GSO skb fit in a given length? 5007 * skb_gso_validate_mac_len - Will a split GSO skb fit in a given length?
@@ -4986,13 +5020,16 @@ EXPORT_SYMBOL_GPL(skb_gso_validate_mac_len);
4986 5020
4987static struct sk_buff *skb_reorder_vlan_header(struct sk_buff *skb) 5021static struct sk_buff *skb_reorder_vlan_header(struct sk_buff *skb)
4988{ 5022{
5023 int mac_len;
5024
4989 if (skb_cow(skb, skb_headroom(skb)) < 0) { 5025 if (skb_cow(skb, skb_headroom(skb)) < 0) {
4990 kfree_skb(skb); 5026 kfree_skb(skb);
4991 return NULL; 5027 return NULL;
4992 } 5028 }
4993 5029
4994 memmove(skb->data - ETH_HLEN, skb->data - skb->mac_len - VLAN_HLEN, 5030 mac_len = skb->data - skb_mac_header(skb);
4995 2 * ETH_ALEN); 5031 memmove(skb_mac_header(skb) + VLAN_HLEN, skb_mac_header(skb),
5032 mac_len - VLAN_HLEN - ETH_TLEN);
4996 skb->mac_header += VLAN_HLEN; 5033 skb->mac_header += VLAN_HLEN;
4997 return skb; 5034 return skb;
4998} 5035}
diff --git a/net/core/sock.c b/net/core/sock.c
index c501499a04fe..85b0b64e7f9d 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3261,6 +3261,27 @@ void proto_unregister(struct proto *prot)
3261} 3261}
3262EXPORT_SYMBOL(proto_unregister); 3262EXPORT_SYMBOL(proto_unregister);
3263 3263
3264int sock_load_diag_module(int family, int protocol)
3265{
3266 if (!protocol) {
3267 if (!sock_is_registered(family))
3268 return -ENOENT;
3269
3270 return request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
3271 NETLINK_SOCK_DIAG, family);
3272 }
3273
3274#ifdef CONFIG_INET
3275 if (family == AF_INET &&
3276 !rcu_access_pointer(inet_protos[protocol]))
3277 return -ENOENT;
3278#endif
3279
3280 return request_module("net-pf-%d-proto-%d-type-%d-%d", PF_NETLINK,
3281 NETLINK_SOCK_DIAG, family, protocol);
3282}
3283EXPORT_SYMBOL(sock_load_diag_module);
3284
3264#ifdef CONFIG_PROC_FS 3285#ifdef CONFIG_PROC_FS
3265static void *proto_seq_start(struct seq_file *seq, loff_t *pos) 3286static void *proto_seq_start(struct seq_file *seq, loff_t *pos)
3266 __acquires(proto_list_mutex) 3287 __acquires(proto_list_mutex)
diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
index 146b50e30659..c37b5be7c5e4 100644
--- a/net/core/sock_diag.c
+++ b/net/core/sock_diag.c
@@ -220,8 +220,7 @@ static int __sock_diag_cmd(struct sk_buff *skb, struct nlmsghdr *nlh)
220 return -EINVAL; 220 return -EINVAL;
221 221
222 if (sock_diag_handlers[req->sdiag_family] == NULL) 222 if (sock_diag_handlers[req->sdiag_family] == NULL)
223 request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK, 223 sock_load_diag_module(req->sdiag_family, 0);
224 NETLINK_SOCK_DIAG, req->sdiag_family);
225 224
226 mutex_lock(&sock_diag_table_mutex); 225 mutex_lock(&sock_diag_table_mutex);
227 hndl = sock_diag_handlers[req->sdiag_family]; 226 hndl = sock_diag_handlers[req->sdiag_family];
@@ -247,8 +246,7 @@ static int sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
247 case TCPDIAG_GETSOCK: 246 case TCPDIAG_GETSOCK:
248 case DCCPDIAG_GETSOCK: 247 case DCCPDIAG_GETSOCK:
249 if (inet_rcv_compat == NULL) 248 if (inet_rcv_compat == NULL)
250 request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK, 249 sock_load_diag_module(AF_INET, 0);
251 NETLINK_SOCK_DIAG, AF_INET);
252 250
253 mutex_lock(&sock_diag_table_mutex); 251 mutex_lock(&sock_diag_table_mutex);
254 if (inet_rcv_compat != NULL) 252 if (inet_rcv_compat != NULL)
@@ -281,14 +279,12 @@ static int sock_diag_bind(struct net *net, int group)
281 case SKNLGRP_INET_TCP_DESTROY: 279 case SKNLGRP_INET_TCP_DESTROY:
282 case SKNLGRP_INET_UDP_DESTROY: 280 case SKNLGRP_INET_UDP_DESTROY:
283 if (!sock_diag_handlers[AF_INET]) 281 if (!sock_diag_handlers[AF_INET])
284 request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK, 282 sock_load_diag_module(AF_INET, 0);
285 NETLINK_SOCK_DIAG, AF_INET);
286 break; 283 break;
287 case SKNLGRP_INET6_TCP_DESTROY: 284 case SKNLGRP_INET6_TCP_DESTROY:
288 case SKNLGRP_INET6_UDP_DESTROY: 285 case SKNLGRP_INET6_UDP_DESTROY:
289 if (!sock_diag_handlers[AF_INET6]) 286 if (!sock_diag_handlers[AF_INET6])
290 request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK, 287 sock_load_diag_module(AF_INET6, 0);
291 NETLINK_SOCK_DIAG, AF_INET6);
292 break; 288 break;
293 } 289 }
294 return 0; 290 return 0;
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index 15bdc002d90c..84cd4e3fd01b 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -794,6 +794,11 @@ int dccp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
794 if (skb == NULL) 794 if (skb == NULL)
795 goto out_release; 795 goto out_release;
796 796
797 if (sk->sk_state == DCCP_CLOSED) {
798 rc = -ENOTCONN;
799 goto out_discard;
800 }
801
797 skb_reserve(skb, sk->sk_prot->max_header); 802 skb_reserve(skb, sk->sk_prot->max_header);
798 rc = memcpy_from_msg(skb_put(skb, len), msg, len); 803 rc = memcpy_from_msg(skb_put(skb, len), msg, len);
799 if (rc != 0) 804 if (rc != 0)
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 91dd09f79808..791aff68af88 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -1338,6 +1338,12 @@ static int dn_setsockopt(struct socket *sock, int level, int optname, char __use
1338 lock_sock(sk); 1338 lock_sock(sk);
1339 err = __dn_setsockopt(sock, level, optname, optval, optlen, 0); 1339 err = __dn_setsockopt(sock, level, optname, optval, optlen, 0);
1340 release_sock(sk); 1340 release_sock(sk);
1341#ifdef CONFIG_NETFILTER
1342 /* we need to exclude all possible ENOPROTOOPTs except default case */
1343 if (err == -ENOPROTOOPT && optname != DSO_LINKINFO &&
1344 optname != DSO_STREAM && optname != DSO_SEQPACKET)
1345 err = nf_setsockopt(sk, PF_DECnet, optname, optval, optlen);
1346#endif
1341 1347
1342 return err; 1348 return err;
1343} 1349}
@@ -1445,15 +1451,6 @@ static int __dn_setsockopt(struct socket *sock, int level,int optname, char __us
1445 dn_nsp_send_disc(sk, 0x38, 0, sk->sk_allocation); 1451 dn_nsp_send_disc(sk, 0x38, 0, sk->sk_allocation);
1446 break; 1452 break;
1447 1453
1448 default:
1449#ifdef CONFIG_NETFILTER
1450 return nf_setsockopt(sk, PF_DECnet, optname, optval, optlen);
1451#endif
1452 case DSO_LINKINFO:
1453 case DSO_STREAM:
1454 case DSO_SEQPACKET:
1455 return -ENOPROTOOPT;
1456
1457 case DSO_MAXWINDOW: 1454 case DSO_MAXWINDOW:
1458 if (optlen != sizeof(unsigned long)) 1455 if (optlen != sizeof(unsigned long))
1459 return -EINVAL; 1456 return -EINVAL;
@@ -1501,6 +1498,12 @@ static int __dn_setsockopt(struct socket *sock, int level,int optname, char __us
1501 return -EINVAL; 1498 return -EINVAL;
1502 scp->info_loc = u.info; 1499 scp->info_loc = u.info;
1503 break; 1500 break;
1501
1502 case DSO_LINKINFO:
1503 case DSO_STREAM:
1504 case DSO_SEQPACKET:
1505 default:
1506 return -ENOPROTOOPT;
1504 } 1507 }
1505 1508
1506 return 0; 1509 return 0;
@@ -1514,6 +1517,20 @@ static int dn_getsockopt(struct socket *sock, int level, int optname, char __use
1514 lock_sock(sk); 1517 lock_sock(sk);
1515 err = __dn_getsockopt(sock, level, optname, optval, optlen, 0); 1518 err = __dn_getsockopt(sock, level, optname, optval, optlen, 0);
1516 release_sock(sk); 1519 release_sock(sk);
1520#ifdef CONFIG_NETFILTER
1521 if (err == -ENOPROTOOPT && optname != DSO_STREAM &&
1522 optname != DSO_SEQPACKET && optname != DSO_CONACCEPT &&
1523 optname != DSO_CONREJECT) {
1524 int len;
1525
1526 if (get_user(len, optlen))
1527 return -EFAULT;
1528
1529 err = nf_getsockopt(sk, PF_DECnet, optname, optval, &len);
1530 if (err >= 0)
1531 err = put_user(len, optlen);
1532 }
1533#endif
1517 1534
1518 return err; 1535 return err;
1519} 1536}
@@ -1579,26 +1596,6 @@ static int __dn_getsockopt(struct socket *sock, int level,int optname, char __us
1579 r_data = &link; 1596 r_data = &link;
1580 break; 1597 break;
1581 1598
1582 default:
1583#ifdef CONFIG_NETFILTER
1584 {
1585 int ret, len;
1586
1587 if (get_user(len, optlen))
1588 return -EFAULT;
1589
1590 ret = nf_getsockopt(sk, PF_DECnet, optname, optval, &len);
1591 if (ret >= 0)
1592 ret = put_user(len, optlen);
1593 return ret;
1594 }
1595#endif
1596 case DSO_STREAM:
1597 case DSO_SEQPACKET:
1598 case DSO_CONACCEPT:
1599 case DSO_CONREJECT:
1600 return -ENOPROTOOPT;
1601
1602 case DSO_MAXWINDOW: 1599 case DSO_MAXWINDOW:
1603 if (r_len > sizeof(unsigned long)) 1600 if (r_len > sizeof(unsigned long))
1604 r_len = sizeof(unsigned long); 1601 r_len = sizeof(unsigned long);
@@ -1630,6 +1627,13 @@ static int __dn_getsockopt(struct socket *sock, int level,int optname, char __us
1630 r_len = sizeof(unsigned char); 1627 r_len = sizeof(unsigned char);
1631 r_data = &scp->info_rem; 1628 r_data = &scp->info_rem;
1632 break; 1629 break;
1630
1631 case DSO_STREAM:
1632 case DSO_SEQPACKET:
1633 case DSO_CONACCEPT:
1634 case DSO_CONREJECT:
1635 default:
1636 return -ENOPROTOOPT;
1633 } 1637 }
1634 1638
1635 if (r_data) { 1639 if (r_data) {
diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
index cb54b81d0bd9..42a7b85b84e1 100644
--- a/net/dsa/legacy.c
+++ b/net/dsa/legacy.c
@@ -194,7 +194,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
194 ds->ports[i].dn = cd->port_dn[i]; 194 ds->ports[i].dn = cd->port_dn[i];
195 ds->ports[i].cpu_dp = dst->cpu_dp; 195 ds->ports[i].cpu_dp = dst->cpu_dp;
196 196
197 if (dsa_is_user_port(ds, i)) 197 if (!dsa_is_user_port(ds, i))
198 continue; 198 continue;
199 199
200 ret = dsa_slave_create(&ds->ports[i]); 200 ret = dsa_slave_create(&ds->ports[i]);
diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c
index 974765b7d92a..e9f0489e4229 100644
--- a/net/ieee802154/6lowpan/core.c
+++ b/net/ieee802154/6lowpan/core.c
@@ -206,9 +206,13 @@ static inline void lowpan_netlink_fini(void)
206static int lowpan_device_event(struct notifier_block *unused, 206static int lowpan_device_event(struct notifier_block *unused,
207 unsigned long event, void *ptr) 207 unsigned long event, void *ptr)
208{ 208{
209 struct net_device *wdev = netdev_notifier_info_to_dev(ptr); 209 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
210 struct wpan_dev *wpan_dev;
210 211
211 if (wdev->type != ARPHRD_IEEE802154) 212 if (ndev->type != ARPHRD_IEEE802154)
213 return NOTIFY_DONE;
214 wpan_dev = ndev->ieee802154_ptr;
215 if (!wpan_dev)
212 return NOTIFY_DONE; 216 return NOTIFY_DONE;
213 217
214 switch (event) { 218 switch (event) {
@@ -217,8 +221,8 @@ static int lowpan_device_event(struct notifier_block *unused,
217 * also delete possible lowpan interfaces which belongs 221 * also delete possible lowpan interfaces which belongs
218 * to the wpan interface. 222 * to the wpan interface.
219 */ 223 */
220 if (wdev->ieee802154_ptr->lowpan_dev) 224 if (wpan_dev->lowpan_dev)
221 lowpan_dellink(wdev->ieee802154_ptr->lowpan_dev, NULL); 225 lowpan_dellink(wpan_dev->lowpan_dev, NULL);
222 break; 226 break;
223 default: 227 default:
224 return NOTIFY_DONE; 228 return NOTIFY_DONE;
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index c586597da20d..7d36a950d961 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -646,6 +646,11 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
646 fi->fib_nh, cfg, extack)) 646 fi->fib_nh, cfg, extack))
647 return 1; 647 return 1;
648 } 648 }
649#ifdef CONFIG_IP_ROUTE_CLASSID
650 if (cfg->fc_flow &&
651 cfg->fc_flow != fi->fib_nh->nh_tclassid)
652 return 1;
653#endif
649 if ((!cfg->fc_oif || cfg->fc_oif == fi->fib_nh->nh_oif) && 654 if ((!cfg->fc_oif || cfg->fc_oif == fi->fib_nh->nh_oif) &&
650 (!cfg->fc_gw || cfg->fc_gw == fi->fib_nh->nh_gw)) 655 (!cfg->fc_gw || cfg->fc_gw == fi->fib_nh->nh_gw))
651 return 0; 656 return 0;
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index a383f299ce24..4e5bc4b2f14e 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -53,8 +53,7 @@ static DEFINE_MUTEX(inet_diag_table_mutex);
53static const struct inet_diag_handler *inet_diag_lock_handler(int proto) 53static const struct inet_diag_handler *inet_diag_lock_handler(int proto)
54{ 54{
55 if (!inet_diag_table[proto]) 55 if (!inet_diag_table[proto])
56 request_module("net-pf-%d-proto-%d-type-%d-%d", PF_NETLINK, 56 sock_load_diag_module(AF_INET, proto);
57 NETLINK_SOCK_DIAG, AF_INET, proto);
58 57
59 mutex_lock(&inet_diag_table_mutex); 58 mutex_lock(&inet_diag_table_mutex);
60 if (!inet_diag_table[proto]) 59 if (!inet_diag_table[proto])
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index 26a3d0315728..e8ec28999f5c 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -119,6 +119,9 @@ out:
119 119
120static bool inet_fragq_should_evict(const struct inet_frag_queue *q) 120static bool inet_fragq_should_evict(const struct inet_frag_queue *q)
121{ 121{
122 if (!hlist_unhashed(&q->list_evictor))
123 return false;
124
122 return q->net->low_thresh == 0 || 125 return q->net->low_thresh == 0 ||
123 frag_mem_limit(q->net) >= q->net->low_thresh; 126 frag_mem_limit(q->net) >= q->net->low_thresh;
124} 127}
diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
index 2dd21c3281a1..b54b948b0596 100644
--- a/net/ipv4/ip_forward.c
+++ b/net/ipv4/ip_forward.c
@@ -55,7 +55,7 @@ static bool ip_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
55 if (skb->ignore_df) 55 if (skb->ignore_df)
56 return false; 56 return false;
57 57
58 if (skb_is_gso(skb) && skb_gso_validate_mtu(skb, mtu)) 58 if (skb_is_gso(skb) && skb_gso_validate_network_len(skb, mtu))
59 return false; 59 return false;
60 60
61 return true; 61 return true;
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 45d97e9b2759..0901de42ed85 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -970,9 +970,6 @@ static void __gre_tunnel_init(struct net_device *dev)
970 970
971 t_hlen = tunnel->hlen + sizeof(struct iphdr); 971 t_hlen = tunnel->hlen + sizeof(struct iphdr);
972 972
973 dev->needed_headroom = LL_MAX_HEADER + t_hlen + 4;
974 dev->mtu = ETH_DATA_LEN - t_hlen - 4;
975
976 dev->features |= GRE_FEATURES; 973 dev->features |= GRE_FEATURES;
977 dev->hw_features |= GRE_FEATURES; 974 dev->hw_features |= GRE_FEATURES;
978 975
@@ -1290,8 +1287,6 @@ static int erspan_tunnel_init(struct net_device *dev)
1290 erspan_hdr_len(tunnel->erspan_ver); 1287 erspan_hdr_len(tunnel->erspan_ver);
1291 t_hlen = tunnel->hlen + sizeof(struct iphdr); 1288 t_hlen = tunnel->hlen + sizeof(struct iphdr);
1292 1289
1293 dev->needed_headroom = LL_MAX_HEADER + t_hlen + 4;
1294 dev->mtu = ETH_DATA_LEN - t_hlen - 4;
1295 dev->features |= GRE_FEATURES; 1290 dev->features |= GRE_FEATURES;
1296 dev->hw_features |= GRE_FEATURES; 1291 dev->hw_features |= GRE_FEATURES;
1297 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 1292 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index e8e675be60ec..66340ab750e6 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -248,7 +248,7 @@ static int ip_finish_output_gso(struct net *net, struct sock *sk,
248 248
249 /* common case: seglen is <= mtu 249 /* common case: seglen is <= mtu
250 */ 250 */
251 if (skb_gso_validate_mtu(skb, mtu)) 251 if (skb_gso_validate_network_len(skb, mtu))
252 return ip_finish_output2(net, sk, skb); 252 return ip_finish_output2(net, sk, skb);
253 253
254 /* Slowpath - GSO segment length exceeds the egress MTU. 254 /* Slowpath - GSO segment length exceeds the egress MTU.
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 008be04ac1cc..74c962b9b09c 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -258,7 +258,8 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
258 src_info = (struct in6_pktinfo *)CMSG_DATA(cmsg); 258 src_info = (struct in6_pktinfo *)CMSG_DATA(cmsg);
259 if (!ipv6_addr_v4mapped(&src_info->ipi6_addr)) 259 if (!ipv6_addr_v4mapped(&src_info->ipi6_addr))
260 return -EINVAL; 260 return -EINVAL;
261 ipc->oif = src_info->ipi6_ifindex; 261 if (src_info->ipi6_ifindex)
262 ipc->oif = src_info->ipi6_ifindex;
262 ipc->addr = src_info->ipi6_addr.s6_addr32[3]; 263 ipc->addr = src_info->ipi6_addr.s6_addr32[3];
263 continue; 264 continue;
264 } 265 }
@@ -288,7 +289,8 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
288 if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct in_pktinfo))) 289 if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct in_pktinfo)))
289 return -EINVAL; 290 return -EINVAL;
290 info = (struct in_pktinfo *)CMSG_DATA(cmsg); 291 info = (struct in_pktinfo *)CMSG_DATA(cmsg);
291 ipc->oif = info->ipi_ifindex; 292 if (info->ipi_ifindex)
293 ipc->oif = info->ipi_ifindex;
292 ipc->addr = info->ipi_spec_dst.s_addr; 294 ipc->addr = info->ipi_spec_dst.s_addr;
293 break; 295 break;
294 } 296 }
@@ -1567,10 +1569,7 @@ int ip_getsockopt(struct sock *sk, int level,
1567 if (get_user(len, optlen)) 1569 if (get_user(len, optlen))
1568 return -EFAULT; 1570 return -EFAULT;
1569 1571
1570 lock_sock(sk); 1572 err = nf_getsockopt(sk, PF_INET, optname, optval, &len);
1571 err = nf_getsockopt(sk, PF_INET, optname, optval,
1572 &len);
1573 release_sock(sk);
1574 if (err >= 0) 1573 if (err >= 0)
1575 err = put_user(len, optlen); 1574 err = put_user(len, optlen);
1576 return err; 1575 return err;
@@ -1602,9 +1601,7 @@ int compat_ip_getsockopt(struct sock *sk, int level, int optname,
1602 if (get_user(len, optlen)) 1601 if (get_user(len, optlen))
1603 return -EFAULT; 1602 return -EFAULT;
1604 1603
1605 lock_sock(sk);
1606 err = compat_nf_getsockopt(sk, PF_INET, optname, optval, &len); 1604 err = compat_nf_getsockopt(sk, PF_INET, optname, optval, &len);
1607 release_sock(sk);
1608 if (err >= 0) 1605 if (err >= 0)
1609 err = put_user(len, optlen); 1606 err = put_user(len, optlen);
1610 return err; 1607 return err;
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index d786a8441bce..6d21068f9b55 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -710,16 +710,9 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
710 } 710 }
711 } 711 }
712 712
713 if (tunnel->fwmark) { 713 init_tunnel_flow(&fl4, protocol, dst, tnl_params->saddr,
714 init_tunnel_flow(&fl4, protocol, dst, tnl_params->saddr, 714 tunnel->parms.o_key, RT_TOS(tos), tunnel->parms.link,
715 tunnel->parms.o_key, RT_TOS(tos), tunnel->parms.link, 715 tunnel->fwmark);
716 tunnel->fwmark);
717 }
718 else {
719 init_tunnel_flow(&fl4, protocol, dst, tnl_params->saddr,
720 tunnel->parms.o_key, RT_TOS(tos), tunnel->parms.link,
721 skb->mark);
722 }
723 716
724 if (ip_tunnel_encap(skb, tunnel, &protocol, &fl4) < 0) 717 if (ip_tunnel_encap(skb, tunnel, &protocol, &fl4) < 0)
725 goto tx_error; 718 goto tx_error;
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 4ffe302f9b82..e3e420f3ba7b 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -252,6 +252,10 @@ unsigned int arpt_do_table(struct sk_buff *skb,
252 } 252 }
253 if (table_base + v 253 if (table_base + v
254 != arpt_next_entry(e)) { 254 != arpt_next_entry(e)) {
255 if (unlikely(stackidx >= private->stacksize)) {
256 verdict = NF_DROP;
257 break;
258 }
255 jumpstack[stackidx++] = e; 259 jumpstack[stackidx++] = e;
256 } 260 }
257 261
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 9a71f3149507..e38395a8dcf2 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -330,8 +330,13 @@ ipt_do_table(struct sk_buff *skb,
330 continue; 330 continue;
331 } 331 }
332 if (table_base + v != ipt_next_entry(e) && 332 if (table_base + v != ipt_next_entry(e) &&
333 !(e->ip.flags & IPT_F_GOTO)) 333 !(e->ip.flags & IPT_F_GOTO)) {
334 if (unlikely(stackidx >= private->stacksize)) {
335 verdict = NF_DROP;
336 break;
337 }
334 jumpstack[stackidx++] = e; 338 jumpstack[stackidx++] = e;
339 }
335 340
336 e = get_entry(table_base, v); 341 e = get_entry(table_base, v);
337 continue; 342 continue;
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 3a84a60f6b39..8a8ae61cea71 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -107,12 +107,6 @@ clusterip_config_entry_put(struct net *net, struct clusterip_config *c)
107 107
108 local_bh_disable(); 108 local_bh_disable();
109 if (refcount_dec_and_lock(&c->entries, &cn->lock)) { 109 if (refcount_dec_and_lock(&c->entries, &cn->lock)) {
110 list_del_rcu(&c->list);
111 spin_unlock(&cn->lock);
112 local_bh_enable();
113
114 unregister_netdevice_notifier(&c->notifier);
115
116 /* In case anyone still accesses the file, the open/close 110 /* In case anyone still accesses the file, the open/close
117 * functions are also incrementing the refcount on their own, 111 * functions are also incrementing the refcount on their own,
118 * so it's safe to remove the entry even if it's in use. */ 112 * so it's safe to remove the entry even if it's in use. */
@@ -120,6 +114,12 @@ clusterip_config_entry_put(struct net *net, struct clusterip_config *c)
120 if (cn->procdir) 114 if (cn->procdir)
121 proc_remove(c->pde); 115 proc_remove(c->pde);
122#endif 116#endif
117 list_del_rcu(&c->list);
118 spin_unlock(&cn->lock);
119 local_bh_enable();
120
121 unregister_netdevice_notifier(&c->notifier);
122
123 return; 123 return;
124 } 124 }
125 local_bh_enable(); 125 local_bh_enable();
@@ -154,8 +154,12 @@ clusterip_config_find_get(struct net *net, __be32 clusterip, int entry)
154#endif 154#endif
155 if (unlikely(!refcount_inc_not_zero(&c->refcount))) 155 if (unlikely(!refcount_inc_not_zero(&c->refcount)))
156 c = NULL; 156 c = NULL;
157 else if (entry) 157 else if (entry) {
158 refcount_inc(&c->entries); 158 if (unlikely(!refcount_inc_not_zero(&c->entries))) {
159 clusterip_config_put(c);
160 c = NULL;
161 }
162 }
159 } 163 }
160 rcu_read_unlock_bh(); 164 rcu_read_unlock_bh();
161 165
@@ -228,7 +232,6 @@ clusterip_config_init(struct net *net, const struct ipt_clusterip_tgt_info *i,
228 c->hash_mode = i->hash_mode; 232 c->hash_mode = i->hash_mode;
229 c->hash_initval = i->hash_initval; 233 c->hash_initval = i->hash_initval;
230 refcount_set(&c->refcount, 1); 234 refcount_set(&c->refcount, 1);
231 refcount_set(&c->entries, 1);
232 235
233 spin_lock_bh(&cn->lock); 236 spin_lock_bh(&cn->lock);
234 if (__clusterip_config_find(net, ip)) { 237 if (__clusterip_config_find(net, ip)) {
@@ -259,8 +262,10 @@ clusterip_config_init(struct net *net, const struct ipt_clusterip_tgt_info *i,
259 262
260 c->notifier.notifier_call = clusterip_netdev_event; 263 c->notifier.notifier_call = clusterip_netdev_event;
261 err = register_netdevice_notifier(&c->notifier); 264 err = register_netdevice_notifier(&c->notifier);
262 if (!err) 265 if (!err) {
266 refcount_set(&c->entries, 1);
263 return c; 267 return c;
268 }
264 269
265#ifdef CONFIG_PROC_FS 270#ifdef CONFIG_PROC_FS
266 proc_remove(c->pde); 271 proc_remove(c->pde);
@@ -269,7 +274,7 @@ err:
269 spin_lock_bh(&cn->lock); 274 spin_lock_bh(&cn->lock);
270 list_del_rcu(&c->list); 275 list_del_rcu(&c->list);
271 spin_unlock_bh(&cn->lock); 276 spin_unlock_bh(&cn->lock);
272 kfree(c); 277 clusterip_config_put(c);
273 278
274 return ERR_PTR(err); 279 return ERR_PTR(err);
275} 280}
@@ -492,12 +497,15 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
492 return PTR_ERR(config); 497 return PTR_ERR(config);
493 } 498 }
494 } 499 }
495 cipinfo->config = config;
496 500
497 ret = nf_ct_netns_get(par->net, par->family); 501 ret = nf_ct_netns_get(par->net, par->family);
498 if (ret < 0) 502 if (ret < 0) {
499 pr_info("cannot load conntrack support for proto=%u\n", 503 pr_info("cannot load conntrack support for proto=%u\n",
500 par->family); 504 par->family);
505 clusterip_config_entry_put(par->net, config);
506 clusterip_config_put(config);
507 return ret;
508 }
501 509
502 if (!par->net->xt.clusterip_deprecated_warning) { 510 if (!par->net->xt.clusterip_deprecated_warning) {
503 pr_info("ipt_CLUSTERIP is deprecated and it will removed soon, " 511 pr_info("ipt_CLUSTERIP is deprecated and it will removed soon, "
@@ -505,6 +513,7 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
505 par->net->xt.clusterip_deprecated_warning = true; 513 par->net->xt.clusterip_deprecated_warning = true;
506 } 514 }
507 515
516 cipinfo->config = config;
508 return ret; 517 return ret;
509} 518}
510 519
diff --git a/net/ipv4/netfilter/ipt_ECN.c b/net/ipv4/netfilter/ipt_ECN.c
index 270765236f5e..aaaf9a81fbc9 100644
--- a/net/ipv4/netfilter/ipt_ECN.c
+++ b/net/ipv4/netfilter/ipt_ECN.c
@@ -98,17 +98,15 @@ static int ecn_tg_check(const struct xt_tgchk_param *par)
98 const struct ipt_ECN_info *einfo = par->targinfo; 98 const struct ipt_ECN_info *einfo = par->targinfo;
99 const struct ipt_entry *e = par->entryinfo; 99 const struct ipt_entry *e = par->entryinfo;
100 100
101 if (einfo->operation & IPT_ECN_OP_MASK) { 101 if (einfo->operation & IPT_ECN_OP_MASK)
102 pr_info("unsupported ECN operation %x\n", einfo->operation);
103 return -EINVAL; 102 return -EINVAL;
104 } 103
105 if (einfo->ip_ect & ~IPT_ECN_IP_MASK) { 104 if (einfo->ip_ect & ~IPT_ECN_IP_MASK)
106 pr_info("new ECT codepoint %x out of mask\n", einfo->ip_ect);
107 return -EINVAL; 105 return -EINVAL;
108 } 106
109 if ((einfo->operation & (IPT_ECN_OP_SET_ECE|IPT_ECN_OP_SET_CWR)) && 107 if ((einfo->operation & (IPT_ECN_OP_SET_ECE|IPT_ECN_OP_SET_CWR)) &&
110 (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & XT_INV_PROTO))) { 108 (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & XT_INV_PROTO))) {
111 pr_info("cannot use TCP operations on a non-tcp rule\n"); 109 pr_info_ratelimited("cannot use operation on non-tcp rule\n");
112 return -EINVAL; 110 return -EINVAL;
113 } 111 }
114 return 0; 112 return 0;
diff --git a/net/ipv4/netfilter/ipt_REJECT.c b/net/ipv4/netfilter/ipt_REJECT.c
index 8bd0d7b26632..e8bed3390e58 100644
--- a/net/ipv4/netfilter/ipt_REJECT.c
+++ b/net/ipv4/netfilter/ipt_REJECT.c
@@ -74,13 +74,13 @@ static int reject_tg_check(const struct xt_tgchk_param *par)
74 const struct ipt_entry *e = par->entryinfo; 74 const struct ipt_entry *e = par->entryinfo;
75 75
76 if (rejinfo->with == IPT_ICMP_ECHOREPLY) { 76 if (rejinfo->with == IPT_ICMP_ECHOREPLY) {
77 pr_info("ECHOREPLY no longer supported.\n"); 77 pr_info_ratelimited("ECHOREPLY no longer supported.\n");
78 return -EINVAL; 78 return -EINVAL;
79 } else if (rejinfo->with == IPT_TCP_RESET) { 79 } else if (rejinfo->with == IPT_TCP_RESET) {
80 /* Must specify that it's a TCP packet */ 80 /* Must specify that it's a TCP packet */
81 if (e->ip.proto != IPPROTO_TCP || 81 if (e->ip.proto != IPPROTO_TCP ||
82 (e->ip.invflags & XT_INV_PROTO)) { 82 (e->ip.invflags & XT_INV_PROTO)) {
83 pr_info("TCP_RESET invalid for non-tcp\n"); 83 pr_info_ratelimited("TCP_RESET invalid for non-tcp\n");
84 return -EINVAL; 84 return -EINVAL;
85 } 85 }
86 } 86 }
diff --git a/net/ipv4/netfilter/ipt_rpfilter.c b/net/ipv4/netfilter/ipt_rpfilter.c
index 37fb9552e858..fd01f13c896a 100644
--- a/net/ipv4/netfilter/ipt_rpfilter.c
+++ b/net/ipv4/netfilter/ipt_rpfilter.c
@@ -105,14 +105,14 @@ static int rpfilter_check(const struct xt_mtchk_param *par)
105 const struct xt_rpfilter_info *info = par->matchinfo; 105 const struct xt_rpfilter_info *info = par->matchinfo;
106 unsigned int options = ~XT_RPFILTER_OPTION_MASK; 106 unsigned int options = ~XT_RPFILTER_OPTION_MASK;
107 if (info->flags & options) { 107 if (info->flags & options) {
108 pr_info("unknown options encountered"); 108 pr_info_ratelimited("unknown options\n");
109 return -EINVAL; 109 return -EINVAL;
110 } 110 }
111 111
112 if (strcmp(par->table, "mangle") != 0 && 112 if (strcmp(par->table, "mangle") != 0 &&
113 strcmp(par->table, "raw") != 0) { 113 strcmp(par->table, "raw") != 0) {
114 pr_info("match only valid in the \'raw\' " 114 pr_info_ratelimited("only valid in \'raw\' or \'mangle\' table, not \'%s\'\n",
115 "or \'mangle\' tables, not \'%s\'.\n", par->table); 115 par->table);
116 return -EINVAL; 116 return -EINVAL;
117 } 117 }
118 118
diff --git a/net/ipv4/netfilter/nf_flow_table_ipv4.c b/net/ipv4/netfilter/nf_flow_table_ipv4.c
index 25d2975da156..0cd46bffa469 100644
--- a/net/ipv4/netfilter/nf_flow_table_ipv4.c
+++ b/net/ipv4/netfilter/nf_flow_table_ipv4.c
@@ -111,6 +111,7 @@ static int nf_flow_dnat_ip(const struct flow_offload *flow, struct sk_buff *skb,
111 default: 111 default:
112 return -1; 112 return -1;
113 } 113 }
114 csum_replace4(&iph->check, addr, new_addr);
114 115
115 return nf_flow_nat_ip_l4proto(skb, iph, thoff, addr, new_addr); 116 return nf_flow_nat_ip_l4proto(skb, iph, thoff, addr, new_addr);
116} 117}
@@ -185,7 +186,7 @@ static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
185 if ((ip_hdr(skb)->frag_off & htons(IP_DF)) == 0) 186 if ((ip_hdr(skb)->frag_off & htons(IP_DF)) == 0)
186 return false; 187 return false;
187 188
188 if (skb_is_gso(skb) && skb_gso_validate_mtu(skb, mtu)) 189 if (skb_is_gso(skb) && skb_gso_validate_network_len(skb, mtu))
189 return false; 190 return false;
190 191
191 return true; 192 return true;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 49cc1c1df1ba..299e247b2032 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -128,10 +128,11 @@ static int ip_rt_redirect_silence __read_mostly = ((HZ / 50) << (9 + 1));
128static int ip_rt_error_cost __read_mostly = HZ; 128static int ip_rt_error_cost __read_mostly = HZ;
129static int ip_rt_error_burst __read_mostly = 5 * HZ; 129static int ip_rt_error_burst __read_mostly = 5 * HZ;
130static int ip_rt_mtu_expires __read_mostly = 10 * 60 * HZ; 130static int ip_rt_mtu_expires __read_mostly = 10 * 60 * HZ;
131static int ip_rt_min_pmtu __read_mostly = 512 + 20 + 20; 131static u32 ip_rt_min_pmtu __read_mostly = 512 + 20 + 20;
132static int ip_rt_min_advmss __read_mostly = 256; 132static int ip_rt_min_advmss __read_mostly = 256;
133 133
134static int ip_rt_gc_timeout __read_mostly = RT_GC_TIMEOUT; 134static int ip_rt_gc_timeout __read_mostly = RT_GC_TIMEOUT;
135
135/* 136/*
136 * Interface to generic destination cache. 137 * Interface to generic destination cache.
137 */ 138 */
@@ -633,6 +634,7 @@ static inline u32 fnhe_hashfun(__be32 daddr)
633static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnhe) 634static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnhe)
634{ 635{
635 rt->rt_pmtu = fnhe->fnhe_pmtu; 636 rt->rt_pmtu = fnhe->fnhe_pmtu;
637 rt->rt_mtu_locked = fnhe->fnhe_mtu_locked;
636 rt->dst.expires = fnhe->fnhe_expires; 638 rt->dst.expires = fnhe->fnhe_expires;
637 639
638 if (fnhe->fnhe_gw) { 640 if (fnhe->fnhe_gw) {
@@ -643,7 +645,7 @@ static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnh
643} 645}
644 646
645static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw, 647static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw,
646 u32 pmtu, unsigned long expires) 648 u32 pmtu, bool lock, unsigned long expires)
647{ 649{
648 struct fnhe_hash_bucket *hash; 650 struct fnhe_hash_bucket *hash;
649 struct fib_nh_exception *fnhe; 651 struct fib_nh_exception *fnhe;
@@ -680,8 +682,10 @@ static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw,
680 fnhe->fnhe_genid = genid; 682 fnhe->fnhe_genid = genid;
681 if (gw) 683 if (gw)
682 fnhe->fnhe_gw = gw; 684 fnhe->fnhe_gw = gw;
683 if (pmtu) 685 if (pmtu) {
684 fnhe->fnhe_pmtu = pmtu; 686 fnhe->fnhe_pmtu = pmtu;
687 fnhe->fnhe_mtu_locked = lock;
688 }
685 fnhe->fnhe_expires = max(1UL, expires); 689 fnhe->fnhe_expires = max(1UL, expires);
686 /* Update all cached dsts too */ 690 /* Update all cached dsts too */
687 rt = rcu_dereference(fnhe->fnhe_rth_input); 691 rt = rcu_dereference(fnhe->fnhe_rth_input);
@@ -705,6 +709,7 @@ static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw,
705 fnhe->fnhe_daddr = daddr; 709 fnhe->fnhe_daddr = daddr;
706 fnhe->fnhe_gw = gw; 710 fnhe->fnhe_gw = gw;
707 fnhe->fnhe_pmtu = pmtu; 711 fnhe->fnhe_pmtu = pmtu;
712 fnhe->fnhe_mtu_locked = lock;
708 fnhe->fnhe_expires = expires; 713 fnhe->fnhe_expires = expires;
709 714
710 /* Exception created; mark the cached routes for the nexthop 715 /* Exception created; mark the cached routes for the nexthop
@@ -786,7 +791,8 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow
786 struct fib_nh *nh = &FIB_RES_NH(res); 791 struct fib_nh *nh = &FIB_RES_NH(res);
787 792
788 update_or_create_fnhe(nh, fl4->daddr, new_gw, 793 update_or_create_fnhe(nh, fl4->daddr, new_gw,
789 0, jiffies + ip_rt_gc_timeout); 794 0, false,
795 jiffies + ip_rt_gc_timeout);
790 } 796 }
791 if (kill_route) 797 if (kill_route)
792 rt->dst.obsolete = DST_OBSOLETE_KILL; 798 rt->dst.obsolete = DST_OBSOLETE_KILL;
@@ -930,14 +936,23 @@ out_put_peer:
930 936
931static int ip_error(struct sk_buff *skb) 937static int ip_error(struct sk_buff *skb)
932{ 938{
933 struct in_device *in_dev = __in_dev_get_rcu(skb->dev);
934 struct rtable *rt = skb_rtable(skb); 939 struct rtable *rt = skb_rtable(skb);
940 struct net_device *dev = skb->dev;
941 struct in_device *in_dev;
935 struct inet_peer *peer; 942 struct inet_peer *peer;
936 unsigned long now; 943 unsigned long now;
937 struct net *net; 944 struct net *net;
938 bool send; 945 bool send;
939 int code; 946 int code;
940 947
948 if (netif_is_l3_master(skb->dev)) {
949 dev = __dev_get_by_index(dev_net(skb->dev), IPCB(skb)->iif);
950 if (!dev)
951 goto out;
952 }
953
954 in_dev = __in_dev_get_rcu(dev);
955
941 /* IP on this device is disabled. */ 956 /* IP on this device is disabled. */
942 if (!in_dev) 957 if (!in_dev)
943 goto out; 958 goto out;
@@ -999,15 +1014,18 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
999{ 1014{
1000 struct dst_entry *dst = &rt->dst; 1015 struct dst_entry *dst = &rt->dst;
1001 struct fib_result res; 1016 struct fib_result res;
1017 bool lock = false;
1002 1018
1003 if (dst_metric_locked(dst, RTAX_MTU)) 1019 if (ip_mtu_locked(dst))
1004 return; 1020 return;
1005 1021
1006 if (ipv4_mtu(dst) < mtu) 1022 if (ipv4_mtu(dst) < mtu)
1007 return; 1023 return;
1008 1024
1009 if (mtu < ip_rt_min_pmtu) 1025 if (mtu < ip_rt_min_pmtu) {
1026 lock = true;
1010 mtu = ip_rt_min_pmtu; 1027 mtu = ip_rt_min_pmtu;
1028 }
1011 1029
1012 if (rt->rt_pmtu == mtu && 1030 if (rt->rt_pmtu == mtu &&
1013 time_before(jiffies, dst->expires - ip_rt_mtu_expires / 2)) 1031 time_before(jiffies, dst->expires - ip_rt_mtu_expires / 2))
@@ -1017,7 +1035,7 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
1017 if (fib_lookup(dev_net(dst->dev), fl4, &res, 0) == 0) { 1035 if (fib_lookup(dev_net(dst->dev), fl4, &res, 0) == 0) {
1018 struct fib_nh *nh = &FIB_RES_NH(res); 1036 struct fib_nh *nh = &FIB_RES_NH(res);
1019 1037
1020 update_or_create_fnhe(nh, fl4->daddr, 0, mtu, 1038 update_or_create_fnhe(nh, fl4->daddr, 0, mtu, lock,
1021 jiffies + ip_rt_mtu_expires); 1039 jiffies + ip_rt_mtu_expires);
1022 } 1040 }
1023 rcu_read_unlock(); 1041 rcu_read_unlock();
@@ -1270,7 +1288,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst)
1270 1288
1271 mtu = READ_ONCE(dst->dev->mtu); 1289 mtu = READ_ONCE(dst->dev->mtu);
1272 1290
1273 if (unlikely(dst_metric_locked(dst, RTAX_MTU))) { 1291 if (unlikely(ip_mtu_locked(dst))) {
1274 if (rt->rt_uses_gateway && mtu > 576) 1292 if (rt->rt_uses_gateway && mtu > 576)
1275 mtu = 576; 1293 mtu = 576;
1276 } 1294 }
@@ -1383,7 +1401,7 @@ struct uncached_list {
1383 1401
1384static DEFINE_PER_CPU_ALIGNED(struct uncached_list, rt_uncached_list); 1402static DEFINE_PER_CPU_ALIGNED(struct uncached_list, rt_uncached_list);
1385 1403
1386static void rt_add_uncached_list(struct rtable *rt) 1404void rt_add_uncached_list(struct rtable *rt)
1387{ 1405{
1388 struct uncached_list *ul = raw_cpu_ptr(&rt_uncached_list); 1406 struct uncached_list *ul = raw_cpu_ptr(&rt_uncached_list);
1389 1407
@@ -1394,14 +1412,8 @@ static void rt_add_uncached_list(struct rtable *rt)
1394 spin_unlock_bh(&ul->lock); 1412 spin_unlock_bh(&ul->lock);
1395} 1413}
1396 1414
1397static void ipv4_dst_destroy(struct dst_entry *dst) 1415void rt_del_uncached_list(struct rtable *rt)
1398{ 1416{
1399 struct dst_metrics *p = (struct dst_metrics *)DST_METRICS_PTR(dst);
1400 struct rtable *rt = (struct rtable *) dst;
1401
1402 if (p != &dst_default_metrics && refcount_dec_and_test(&p->refcnt))
1403 kfree(p);
1404
1405 if (!list_empty(&rt->rt_uncached)) { 1417 if (!list_empty(&rt->rt_uncached)) {
1406 struct uncached_list *ul = rt->rt_uncached_list; 1418 struct uncached_list *ul = rt->rt_uncached_list;
1407 1419
@@ -1411,6 +1423,17 @@ static void ipv4_dst_destroy(struct dst_entry *dst)
1411 } 1423 }
1412} 1424}
1413 1425
1426static void ipv4_dst_destroy(struct dst_entry *dst)
1427{
1428 struct dst_metrics *p = (struct dst_metrics *)DST_METRICS_PTR(dst);
1429 struct rtable *rt = (struct rtable *)dst;
1430
1431 if (p != &dst_default_metrics && refcount_dec_and_test(&p->refcnt))
1432 kfree(p);
1433
1434 rt_del_uncached_list(rt);
1435}
1436
1414void rt_flush_dev(struct net_device *dev) 1437void rt_flush_dev(struct net_device *dev)
1415{ 1438{
1416 struct net *net = dev_net(dev); 1439 struct net *net = dev_net(dev);
@@ -1506,6 +1529,7 @@ struct rtable *rt_dst_alloc(struct net_device *dev,
1506 rt->rt_is_input = 0; 1529 rt->rt_is_input = 0;
1507 rt->rt_iif = 0; 1530 rt->rt_iif = 0;
1508 rt->rt_pmtu = 0; 1531 rt->rt_pmtu = 0;
1532 rt->rt_mtu_locked = 0;
1509 rt->rt_gateway = 0; 1533 rt->rt_gateway = 0;
1510 rt->rt_uses_gateway = 0; 1534 rt->rt_uses_gateway = 0;
1511 rt->rt_table_id = 0; 1535 rt->rt_table_id = 0;
@@ -1826,6 +1850,8 @@ int fib_multipath_hash(const struct fib_info *fi, const struct flowi4 *fl4,
1826 return skb_get_hash_raw(skb) >> 1; 1850 return skb_get_hash_raw(skb) >> 1;
1827 memset(&hash_keys, 0, sizeof(hash_keys)); 1851 memset(&hash_keys, 0, sizeof(hash_keys));
1828 skb_flow_dissect_flow_keys(skb, &keys, flag); 1852 skb_flow_dissect_flow_keys(skb, &keys, flag);
1853
1854 hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
1829 hash_keys.addrs.v4addrs.src = keys.addrs.v4addrs.src; 1855 hash_keys.addrs.v4addrs.src = keys.addrs.v4addrs.src;
1830 hash_keys.addrs.v4addrs.dst = keys.addrs.v4addrs.dst; 1856 hash_keys.addrs.v4addrs.dst = keys.addrs.v4addrs.dst;
1831 hash_keys.ports.src = keys.ports.src; 1857 hash_keys.ports.src = keys.ports.src;
@@ -2529,6 +2555,7 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or
2529 rt->rt_is_input = ort->rt_is_input; 2555 rt->rt_is_input = ort->rt_is_input;
2530 rt->rt_iif = ort->rt_iif; 2556 rt->rt_iif = ort->rt_iif;
2531 rt->rt_pmtu = ort->rt_pmtu; 2557 rt->rt_pmtu = ort->rt_pmtu;
2558 rt->rt_mtu_locked = ort->rt_mtu_locked;
2532 2559
2533 rt->rt_genid = rt_genid_ipv4(net); 2560 rt->rt_genid = rt_genid_ipv4(net);
2534 rt->rt_flags = ort->rt_flags; 2561 rt->rt_flags = ort->rt_flags;
@@ -2631,6 +2658,8 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src, u32 table_id,
2631 memcpy(metrics, dst_metrics_ptr(&rt->dst), sizeof(metrics)); 2658 memcpy(metrics, dst_metrics_ptr(&rt->dst), sizeof(metrics));
2632 if (rt->rt_pmtu && expires) 2659 if (rt->rt_pmtu && expires)
2633 metrics[RTAX_MTU - 1] = rt->rt_pmtu; 2660 metrics[RTAX_MTU - 1] = rt->rt_pmtu;
2661 if (rt->rt_mtu_locked && expires)
2662 metrics[RTAX_LOCK - 1] |= BIT(RTAX_MTU);
2634 if (rtnetlink_put_metrics(skb, metrics) < 0) 2663 if (rtnetlink_put_metrics(skb, metrics) < 0)
2635 goto nla_put_failure; 2664 goto nla_put_failure;
2636 2665
@@ -2816,6 +2845,7 @@ void ip_rt_multicast_event(struct in_device *in_dev)
2816static int ip_rt_gc_interval __read_mostly = 60 * HZ; 2845static int ip_rt_gc_interval __read_mostly = 60 * HZ;
2817static int ip_rt_gc_min_interval __read_mostly = HZ / 2; 2846static int ip_rt_gc_min_interval __read_mostly = HZ / 2;
2818static int ip_rt_gc_elasticity __read_mostly = 8; 2847static int ip_rt_gc_elasticity __read_mostly = 8;
2848static int ip_min_valid_pmtu __read_mostly = IPV4_MIN_MTU;
2819 2849
2820static int ipv4_sysctl_rtcache_flush(struct ctl_table *__ctl, int write, 2850static int ipv4_sysctl_rtcache_flush(struct ctl_table *__ctl, int write,
2821 void __user *buffer, 2851 void __user *buffer,
@@ -2931,7 +2961,8 @@ static struct ctl_table ipv4_route_table[] = {
2931 .data = &ip_rt_min_pmtu, 2961 .data = &ip_rt_min_pmtu,
2932 .maxlen = sizeof(int), 2962 .maxlen = sizeof(int),
2933 .mode = 0644, 2963 .mode = 0644,
2934 .proc_handler = proc_dointvec, 2964 .proc_handler = proc_dointvec_minmax,
2965 .extra1 = &ip_min_valid_pmtu,
2935 }, 2966 },
2936 { 2967 {
2937 .procname = "min_adv_mss", 2968 .procname = "min_adv_mss",
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 48636aee23c3..8b8059b7af4d 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3566,6 +3566,7 @@ int tcp_abort(struct sock *sk, int err)
3566 3566
3567 bh_unlock_sock(sk); 3567 bh_unlock_sock(sk);
3568 local_bh_enable(); 3568 local_bh_enable();
3569 tcp_write_queue_purge(sk);
3569 release_sock(sk); 3570 release_sock(sk);
3570 return 0; 3571 return 0;
3571} 3572}
diff --git a/net/ipv4/tcp_illinois.c b/net/ipv4/tcp_illinois.c
index 7c843578f233..faddf4f9a707 100644
--- a/net/ipv4/tcp_illinois.c
+++ b/net/ipv4/tcp_illinois.c
@@ -6,7 +6,7 @@
6 * The algorithm is described in: 6 * The algorithm is described in:
7 * "TCP-Illinois: A Loss and Delay-Based Congestion Control Algorithm 7 * "TCP-Illinois: A Loss and Delay-Based Congestion Control Algorithm
8 * for High-Speed Networks" 8 * for High-Speed Networks"
9 * http://www.ifp.illinois.edu/~srikant/Papers/liubassri06perf.pdf 9 * http://tamerbasar.csl.illinois.edu/LiuBasarSrikantPerfEvalArtJun2008.pdf
10 * 10 *
11 * Implemented from description in paper and ns-2 simulation. 11 * Implemented from description in paper and ns-2 simulation.
12 * Copyright (C) 2007 Stephen Hemminger <shemminger@linux-foundation.org> 12 * Copyright (C) 2007 Stephen Hemminger <shemminger@linux-foundation.org>
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 575d3c1fb6e8..9a1b3c1c1c14 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1971,11 +1971,6 @@ void tcp_enter_loss(struct sock *sk)
1971 /* F-RTO RFC5682 sec 3.1 step 1: retransmit SND.UNA if no previous 1971 /* F-RTO RFC5682 sec 3.1 step 1: retransmit SND.UNA if no previous
1972 * loss recovery is underway except recurring timeout(s) on 1972 * loss recovery is underway except recurring timeout(s) on
1973 * the same SND.UNA (sec 3.2). Disable F-RTO on path MTU probing 1973 * the same SND.UNA (sec 3.2). Disable F-RTO on path MTU probing
1974 *
1975 * In theory F-RTO can be used repeatedly during loss recovery.
1976 * In practice this interacts badly with broken middle-boxes that
1977 * falsely raise the receive window, which results in repeated
1978 * timeouts and stop-and-go behavior.
1979 */ 1974 */
1980 tp->frto = net->ipv4.sysctl_tcp_frto && 1975 tp->frto = net->ipv4.sysctl_tcp_frto &&
1981 (new_recovery || icsk->icsk_retransmits) && 1976 (new_recovery || icsk->icsk_retransmits) &&
@@ -2631,18 +2626,14 @@ static void tcp_process_loss(struct sock *sk, int flag, bool is_dupack,
2631 tcp_try_undo_loss(sk, false)) 2626 tcp_try_undo_loss(sk, false))
2632 return; 2627 return;
2633 2628
2634 /* The ACK (s)acks some never-retransmitted data meaning not all
2635 * the data packets before the timeout were lost. Therefore we
2636 * undo the congestion window and state. This is essentially
2637 * the operation in F-RTO (RFC5682 section 3.1 step 3.b). Since
2638 * a retransmitted skb is permantly marked, we can apply such an
2639 * operation even if F-RTO was not used.
2640 */
2641 if ((flag & FLAG_ORIG_SACK_ACKED) &&
2642 tcp_try_undo_loss(sk, tp->undo_marker))
2643 return;
2644
2645 if (tp->frto) { /* F-RTO RFC5682 sec 3.1 (sack enhanced version). */ 2629 if (tp->frto) { /* F-RTO RFC5682 sec 3.1 (sack enhanced version). */
2630 /* Step 3.b. A timeout is spurious if not all data are
2631 * lost, i.e., never-retransmitted data are (s)acked.
2632 */
2633 if ((flag & FLAG_ORIG_SACK_ACKED) &&
2634 tcp_try_undo_loss(sk, true))
2635 return;
2636
2646 if (after(tp->snd_nxt, tp->high_seq)) { 2637 if (after(tp->snd_nxt, tp->high_seq)) {
2647 if (flag & FLAG_DATA_SACKED || is_dupack) 2638 if (flag & FLAG_DATA_SACKED || is_dupack)
2648 tp->frto = 0; /* Step 3.a. loss was real */ 2639 tp->frto = 0; /* Step 3.a. loss was real */
@@ -4001,6 +3992,7 @@ void tcp_reset(struct sock *sk)
4001 /* This barrier is coupled with smp_rmb() in tcp_poll() */ 3992 /* This barrier is coupled with smp_rmb() in tcp_poll() */
4002 smp_wmb(); 3993 smp_wmb();
4003 3994
3995 tcp_write_queue_purge(sk);
4004 tcp_done(sk); 3996 tcp_done(sk);
4005 3997
4006 if (!sock_flag(sk, SOCK_DEAD)) 3998 if (!sock_flag(sk, SOCK_DEAD))
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index e9f985e42405..6818042cd8a9 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -1730,7 +1730,7 @@ u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now,
1730 */ 1730 */
1731 segs = max_t(u32, bytes / mss_now, min_tso_segs); 1731 segs = max_t(u32, bytes / mss_now, min_tso_segs);
1732 1732
1733 return min_t(u32, segs, sk->sk_gso_max_segs); 1733 return segs;
1734} 1734}
1735EXPORT_SYMBOL(tcp_tso_autosize); 1735EXPORT_SYMBOL(tcp_tso_autosize);
1736 1736
@@ -1742,9 +1742,10 @@ static u32 tcp_tso_segs(struct sock *sk, unsigned int mss_now)
1742 const struct tcp_congestion_ops *ca_ops = inet_csk(sk)->icsk_ca_ops; 1742 const struct tcp_congestion_ops *ca_ops = inet_csk(sk)->icsk_ca_ops;
1743 u32 tso_segs = ca_ops->tso_segs_goal ? ca_ops->tso_segs_goal(sk) : 0; 1743 u32 tso_segs = ca_ops->tso_segs_goal ? ca_ops->tso_segs_goal(sk) : 0;
1744 1744
1745 return tso_segs ? : 1745 if (!tso_segs)
1746 tcp_tso_autosize(sk, mss_now, 1746 tso_segs = tcp_tso_autosize(sk, mss_now,
1747 sock_net(sk)->ipv4.sysctl_tcp_min_tso_segs); 1747 sock_net(sk)->ipv4.sysctl_tcp_min_tso_segs);
1748 return min_t(u32, tso_segs, sk->sk_gso_max_segs);
1748} 1749}
1749 1750
1750/* Returns the portion of skb which can be sent right away */ 1751/* Returns the portion of skb which can be sent right away */
@@ -2027,6 +2028,24 @@ static inline void tcp_mtu_check_reprobe(struct sock *sk)
2027 } 2028 }
2028} 2029}
2029 2030
2031static bool tcp_can_coalesce_send_queue_head(struct sock *sk, int len)
2032{
2033 struct sk_buff *skb, *next;
2034
2035 skb = tcp_send_head(sk);
2036 tcp_for_write_queue_from_safe(skb, next, sk) {
2037 if (len <= skb->len)
2038 break;
2039
2040 if (unlikely(TCP_SKB_CB(skb)->eor))
2041 return false;
2042
2043 len -= skb->len;
2044 }
2045
2046 return true;
2047}
2048
2030/* Create a new MTU probe if we are ready. 2049/* Create a new MTU probe if we are ready.
2031 * MTU probe is regularly attempting to increase the path MTU by 2050 * MTU probe is regularly attempting to increase the path MTU by
2032 * deliberately sending larger packets. This discovers routing 2051 * deliberately sending larger packets. This discovers routing
@@ -2099,6 +2118,9 @@ static int tcp_mtu_probe(struct sock *sk)
2099 return 0; 2118 return 0;
2100 } 2119 }
2101 2120
2121 if (!tcp_can_coalesce_send_queue_head(sk, probe_size))
2122 return -1;
2123
2102 /* We're allowed to probe. Build it now. */ 2124 /* We're allowed to probe. Build it now. */
2103 nskb = sk_stream_alloc_skb(sk, probe_size, GFP_ATOMIC, false); 2125 nskb = sk_stream_alloc_skb(sk, probe_size, GFP_ATOMIC, false);
2104 if (!nskb) 2126 if (!nskb)
@@ -2134,6 +2156,10 @@ static int tcp_mtu_probe(struct sock *sk)
2134 /* We've eaten all the data from this skb. 2156 /* We've eaten all the data from this skb.
2135 * Throw it away. */ 2157 * Throw it away. */
2136 TCP_SKB_CB(nskb)->tcp_flags |= TCP_SKB_CB(skb)->tcp_flags; 2158 TCP_SKB_CB(nskb)->tcp_flags |= TCP_SKB_CB(skb)->tcp_flags;
2159 /* If this is the last SKB we copy and eor is set
2160 * we need to propagate it to the new skb.
2161 */
2162 TCP_SKB_CB(nskb)->eor = TCP_SKB_CB(skb)->eor;
2137 tcp_unlink_write_queue(skb, sk); 2163 tcp_unlink_write_queue(skb, sk);
2138 sk_wmem_free_skb(sk, skb); 2164 sk_wmem_free_skb(sk, skb);
2139 } else { 2165 } else {
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 71fc60f1b326..f7d944855f8e 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -34,6 +34,7 @@ static void tcp_write_err(struct sock *sk)
34 sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT; 34 sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT;
35 sk->sk_error_report(sk); 35 sk->sk_error_report(sk);
36 36
37 tcp_write_queue_purge(sk);
37 tcp_done(sk); 38 tcp_done(sk);
38 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONTIMEOUT); 39 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONTIMEOUT);
39} 40}
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index bfaefe560b5c..e5ef7c38c934 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2024,6 +2024,11 @@ static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh,
2024 err = udplite_checksum_init(skb, uh); 2024 err = udplite_checksum_init(skb, uh);
2025 if (err) 2025 if (err)
2026 return err; 2026 return err;
2027
2028 if (UDP_SKB_CB(skb)->partial_cov) {
2029 skb->csum = inet_compute_pseudo(skb, proto);
2030 return 0;
2031 }
2027 } 2032 }
2028 2033
2029 /* Note, we are only interested in != 0 or == 0, thus the 2034 /* Note, we are only interested in != 0 or == 0, thus the
diff --git a/net/ipv4/xfrm4_mode_tunnel.c b/net/ipv4/xfrm4_mode_tunnel.c
index 63faeee989a9..2a9764bd1719 100644
--- a/net/ipv4/xfrm4_mode_tunnel.c
+++ b/net/ipv4/xfrm4_mode_tunnel.c
@@ -92,7 +92,8 @@ static int xfrm4_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
92 92
93 skb_reset_network_header(skb); 93 skb_reset_network_header(skb);
94 skb_mac_header_rebuild(skb); 94 skb_mac_header_rebuild(skb);
95 eth_hdr(skb)->h_proto = skb->protocol; 95 if (skb->mac_len)
96 eth_hdr(skb)->h_proto = skb->protocol;
96 97
97 err = 0; 98 err = 0;
98 99
diff --git a/net/ipv4/xfrm4_output.c b/net/ipv4/xfrm4_output.c
index 94b8702603bc..be980c195fc5 100644
--- a/net/ipv4/xfrm4_output.c
+++ b/net/ipv4/xfrm4_output.c
@@ -30,7 +30,8 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb)
30 30
31 mtu = dst_mtu(skb_dst(skb)); 31 mtu = dst_mtu(skb_dst(skb));
32 if ((!skb_is_gso(skb) && skb->len > mtu) || 32 if ((!skb_is_gso(skb) && skb->len > mtu) ||
33 (skb_is_gso(skb) && skb_gso_network_seglen(skb) > ip_skb_dst_mtu(skb->sk, skb))) { 33 (skb_is_gso(skb) &&
34 !skb_gso_validate_network_len(skb, ip_skb_dst_mtu(skb->sk, skb)))) {
34 skb->protocol = htons(ETH_P_IP); 35 skb->protocol = htons(ETH_P_IP);
35 36
36 if (skb->sk) 37 if (skb->sk)
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index 05017e2c849c..fbebda67ac1b 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -100,8 +100,10 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
100 xdst->u.rt.rt_gateway = rt->rt_gateway; 100 xdst->u.rt.rt_gateway = rt->rt_gateway;
101 xdst->u.rt.rt_uses_gateway = rt->rt_uses_gateway; 101 xdst->u.rt.rt_uses_gateway = rt->rt_uses_gateway;
102 xdst->u.rt.rt_pmtu = rt->rt_pmtu; 102 xdst->u.rt.rt_pmtu = rt->rt_pmtu;
103 xdst->u.rt.rt_mtu_locked = rt->rt_mtu_locked;
103 xdst->u.rt.rt_table_id = rt->rt_table_id; 104 xdst->u.rt.rt_table_id = rt->rt_table_id;
104 INIT_LIST_HEAD(&xdst->u.rt.rt_uncached); 105 INIT_LIST_HEAD(&xdst->u.rt.rt_uncached);
106 rt_add_uncached_list(&xdst->u.rt);
105 107
106 return 0; 108 return 0;
107} 109}
@@ -241,7 +243,8 @@ static void xfrm4_dst_destroy(struct dst_entry *dst)
241 struct xfrm_dst *xdst = (struct xfrm_dst *)dst; 243 struct xfrm_dst *xdst = (struct xfrm_dst *)dst;
242 244
243 dst_destroy_metrics_generic(dst); 245 dst_destroy_metrics_generic(dst);
244 246 if (xdst->u.rt.rt_uncached_list)
247 rt_del_uncached_list(&xdst->u.rt);
245 xfrm_dst_destroy(xdst); 248 xfrm_dst_destroy(xdst);
246} 249}
247 250
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index fbf08ce3f5ab..a9f7eca0b6a3 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -146,10 +146,12 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr,
146 struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr; 146 struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr;
147 struct inet_sock *inet = inet_sk(sk); 147 struct inet_sock *inet = inet_sk(sk);
148 struct ipv6_pinfo *np = inet6_sk(sk); 148 struct ipv6_pinfo *np = inet6_sk(sk);
149 struct in6_addr *daddr; 149 struct in6_addr *daddr, old_daddr;
150 __be32 fl6_flowlabel = 0;
151 __be32 old_fl6_flowlabel;
152 __be16 old_dport;
150 int addr_type; 153 int addr_type;
151 int err; 154 int err;
152 __be32 fl6_flowlabel = 0;
153 155
154 if (usin->sin6_family == AF_INET) { 156 if (usin->sin6_family == AF_INET) {
155 if (__ipv6_only_sock(sk)) 157 if (__ipv6_only_sock(sk))
@@ -238,9 +240,13 @@ ipv4_connected:
238 } 240 }
239 } 241 }
240 242
243 /* save the current peer information before updating it */
244 old_daddr = sk->sk_v6_daddr;
245 old_fl6_flowlabel = np->flow_label;
246 old_dport = inet->inet_dport;
247
241 sk->sk_v6_daddr = *daddr; 248 sk->sk_v6_daddr = *daddr;
242 np->flow_label = fl6_flowlabel; 249 np->flow_label = fl6_flowlabel;
243
244 inet->inet_dport = usin->sin6_port; 250 inet->inet_dport = usin->sin6_port;
245 251
246 /* 252 /*
@@ -250,11 +256,12 @@ ipv4_connected:
250 256
251 err = ip6_datagram_dst_update(sk, true); 257 err = ip6_datagram_dst_update(sk, true);
252 if (err) { 258 if (err) {
253 /* Reset daddr and dport so that udp_v6_early_demux() 259 /* Restore the socket peer info, to keep it consistent with
254 * fails to find this socket 260 * the old socket state
255 */ 261 */
256 memset(&sk->sk_v6_daddr, 0, sizeof(sk->sk_v6_daddr)); 262 sk->sk_v6_daddr = old_daddr;
257 inet->inet_dport = 0; 263 np->flow_label = old_fl6_flowlabel;
264 inet->inet_dport = old_dport;
258 goto out; 265 goto out;
259 } 266 }
260 267
diff --git a/net/ipv6/ip6_checksum.c b/net/ipv6/ip6_checksum.c
index ec43d18b5ff9..547515e8450a 100644
--- a/net/ipv6/ip6_checksum.c
+++ b/net/ipv6/ip6_checksum.c
@@ -73,6 +73,11 @@ int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh, int proto)
73 err = udplite_checksum_init(skb, uh); 73 err = udplite_checksum_init(skb, uh);
74 if (err) 74 if (err)
75 return err; 75 return err;
76
77 if (UDP_SKB_CB(skb)->partial_cov) {
78 skb->csum = ip6_compute_pseudo(skb, proto);
79 return 0;
80 }
76 } 81 }
77 82
78 /* To support RFC 6936 (allow zero checksum in UDP/IPV6 for tunnels) 83 /* To support RFC 6936 (allow zero checksum in UDP/IPV6 for tunnels)
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 3c353125546d..1bbd0930063e 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -126,7 +126,8 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev,
126 struct ip6_tnl *t, *cand = NULL; 126 struct ip6_tnl *t, *cand = NULL;
127 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); 127 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
128 int dev_type = (gre_proto == htons(ETH_P_TEB) || 128 int dev_type = (gre_proto == htons(ETH_P_TEB) ||
129 gre_proto == htons(ETH_P_ERSPAN)) ? 129 gre_proto == htons(ETH_P_ERSPAN) ||
130 gre_proto == htons(ETH_P_ERSPAN2)) ?
130 ARPHRD_ETHER : ARPHRD_IP6GRE; 131 ARPHRD_ETHER : ARPHRD_IP6GRE;
131 int score, cand_score = 4; 132 int score, cand_score = 4;
132 133
@@ -902,6 +903,9 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
902 truncate = true; 903 truncate = true;
903 } 904 }
904 905
906 if (skb_cow_head(skb, dev->needed_headroom))
907 goto tx_err;
908
905 t->parms.o_flags &= ~TUNNEL_KEY; 909 t->parms.o_flags &= ~TUNNEL_KEY;
906 IPCB(skb)->flags = 0; 910 IPCB(skb)->flags = 0;
907 911
@@ -944,6 +948,8 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
944 md->u.md2.dir, 948 md->u.md2.dir,
945 get_hwid(&md->u.md2), 949 get_hwid(&md->u.md2),
946 truncate, false); 950 truncate, false);
951 } else {
952 goto tx_err;
947 } 953 }
948 } else { 954 } else {
949 switch (skb->protocol) { 955 switch (skb->protocol) {
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 997c7f19ad62..a8a919520090 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -412,7 +412,7 @@ static bool ip6_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)
412 if (skb->ignore_df) 412 if (skb->ignore_df)
413 return false; 413 return false;
414 414
415 if (skb_is_gso(skb) && skb_gso_validate_mtu(skb, mtu)) 415 if (skb_is_gso(skb) && skb_gso_validate_network_len(skb, mtu))
416 return false; 416 return false;
417 417
418 return true; 418 return true;
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 4b15fe928278..6e0f21eed88a 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1982,14 +1982,14 @@ static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
1982{ 1982{
1983 struct net *net = dev_net(dev); 1983 struct net *net = dev_net(dev);
1984 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id); 1984 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1985 struct ip6_tnl *nt, *t;
1986 struct ip_tunnel_encap ipencap; 1985 struct ip_tunnel_encap ipencap;
1986 struct ip6_tnl *nt, *t;
1987 int err;
1987 1988
1988 nt = netdev_priv(dev); 1989 nt = netdev_priv(dev);
1989 1990
1990 if (ip6_tnl_netlink_encap_parms(data, &ipencap)) { 1991 if (ip6_tnl_netlink_encap_parms(data, &ipencap)) {
1991 int err = ip6_tnl_encap_setup(nt, &ipencap); 1992 err = ip6_tnl_encap_setup(nt, &ipencap);
1992
1993 if (err < 0) 1993 if (err < 0)
1994 return err; 1994 return err;
1995 } 1995 }
@@ -2005,7 +2005,11 @@ static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
2005 return -EEXIST; 2005 return -EEXIST;
2006 } 2006 }
2007 2007
2008 return ip6_tnl_create2(dev); 2008 err = ip6_tnl_create2(dev);
2009 if (!err && tb[IFLA_MTU])
2010 ip6_tnl_change_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
2011
2012 return err;
2009} 2013}
2010 2014
2011static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[], 2015static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index d78d41fc4b1a..24535169663d 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -1367,10 +1367,7 @@ int ipv6_getsockopt(struct sock *sk, int level, int optname,
1367 if (get_user(len, optlen)) 1367 if (get_user(len, optlen))
1368 return -EFAULT; 1368 return -EFAULT;
1369 1369
1370 lock_sock(sk); 1370 err = nf_getsockopt(sk, PF_INET6, optname, optval, &len);
1371 err = nf_getsockopt(sk, PF_INET6, optname, optval,
1372 &len);
1373 release_sock(sk);
1374 if (err >= 0) 1371 if (err >= 0)
1375 err = put_user(len, optlen); 1372 err = put_user(len, optlen);
1376 } 1373 }
@@ -1409,10 +1406,7 @@ int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
1409 if (get_user(len, optlen)) 1406 if (get_user(len, optlen))
1410 return -EFAULT; 1407 return -EFAULT;
1411 1408
1412 lock_sock(sk); 1409 err = compat_nf_getsockopt(sk, PF_INET6, optname, optval, &len);
1413 err = compat_nf_getsockopt(sk, PF_INET6,
1414 optname, optval, &len);
1415 release_sock(sk);
1416 if (err >= 0) 1410 if (err >= 0)
1417 err = put_user(len, optlen); 1411 err = put_user(len, optlen);
1418 } 1412 }
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index f61a5b613b52..ba5e04c6ae17 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -1554,7 +1554,8 @@ static void ndisc_fill_redirect_hdr_option(struct sk_buff *skb,
1554 *(opt++) = (rd_len >> 3); 1554 *(opt++) = (rd_len >> 3);
1555 opt += 6; 1555 opt += 6;
1556 1556
1557 memcpy(opt, ipv6_hdr(orig_skb), rd_len - 8); 1557 skb_copy_bits(orig_skb, skb_network_offset(orig_skb), opt,
1558 rd_len - 8);
1558} 1559}
1559 1560
1560void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) 1561void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target)
diff --git a/net/ipv6/netfilter.c b/net/ipv6/netfilter.c
index d95ceca7ff8f..531d6957af36 100644
--- a/net/ipv6/netfilter.c
+++ b/net/ipv6/netfilter.c
@@ -21,18 +21,19 @@
21int ip6_route_me_harder(struct net *net, struct sk_buff *skb) 21int ip6_route_me_harder(struct net *net, struct sk_buff *skb)
22{ 22{
23 const struct ipv6hdr *iph = ipv6_hdr(skb); 23 const struct ipv6hdr *iph = ipv6_hdr(skb);
24 struct sock *sk = sk_to_full_sk(skb->sk);
24 unsigned int hh_len; 25 unsigned int hh_len;
25 struct dst_entry *dst; 26 struct dst_entry *dst;
26 struct flowi6 fl6 = { 27 struct flowi6 fl6 = {
27 .flowi6_oif = skb->sk ? skb->sk->sk_bound_dev_if : 0, 28 .flowi6_oif = sk ? sk->sk_bound_dev_if : 0,
28 .flowi6_mark = skb->mark, 29 .flowi6_mark = skb->mark,
29 .flowi6_uid = sock_net_uid(net, skb->sk), 30 .flowi6_uid = sock_net_uid(net, sk),
30 .daddr = iph->daddr, 31 .daddr = iph->daddr,
31 .saddr = iph->saddr, 32 .saddr = iph->saddr,
32 }; 33 };
33 int err; 34 int err;
34 35
35 dst = ip6_route_output(net, skb->sk, &fl6); 36 dst = ip6_route_output(net, sk, &fl6);
36 err = dst->error; 37 err = dst->error;
37 if (err) { 38 if (err) {
38 IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES); 39 IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
@@ -50,7 +51,7 @@ int ip6_route_me_harder(struct net *net, struct sk_buff *skb)
50 if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) && 51 if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) &&
51 xfrm_decode_session(skb, flowi6_to_flowi(&fl6), AF_INET6) == 0) { 52 xfrm_decode_session(skb, flowi6_to_flowi(&fl6), AF_INET6) == 0) {
52 skb_dst_set(skb, NULL); 53 skb_dst_set(skb, NULL);
53 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), skb->sk, 0); 54 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), sk, 0);
54 if (IS_ERR(dst)) 55 if (IS_ERR(dst))
55 return PTR_ERR(dst); 56 return PTR_ERR(dst);
56 skb_dst_set(skb, dst); 57 skb_dst_set(skb, dst);
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index af4c917e0836..62358b93bbac 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -352,6 +352,10 @@ ip6t_do_table(struct sk_buff *skb,
352 } 352 }
353 if (table_base + v != ip6t_next_entry(e) && 353 if (table_base + v != ip6t_next_entry(e) &&
354 !(e->ipv6.flags & IP6T_F_GOTO)) { 354 !(e->ipv6.flags & IP6T_F_GOTO)) {
355 if (unlikely(stackidx >= private->stacksize)) {
356 verdict = NF_DROP;
357 break;
358 }
355 jumpstack[stackidx++] = e; 359 jumpstack[stackidx++] = e;
356 } 360 }
357 361
diff --git a/net/ipv6/netfilter/ip6t_REJECT.c b/net/ipv6/netfilter/ip6t_REJECT.c
index fa51a205918d..38dea8ff680f 100644
--- a/net/ipv6/netfilter/ip6t_REJECT.c
+++ b/net/ipv6/netfilter/ip6t_REJECT.c
@@ -85,14 +85,14 @@ static int reject_tg6_check(const struct xt_tgchk_param *par)
85 const struct ip6t_entry *e = par->entryinfo; 85 const struct ip6t_entry *e = par->entryinfo;
86 86
87 if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) { 87 if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) {
88 pr_info("ECHOREPLY is not supported.\n"); 88 pr_info_ratelimited("ECHOREPLY is not supported\n");
89 return -EINVAL; 89 return -EINVAL;
90 } else if (rejinfo->with == IP6T_TCP_RESET) { 90 } else if (rejinfo->with == IP6T_TCP_RESET) {
91 /* Must specify that it's a TCP packet */ 91 /* Must specify that it's a TCP packet */
92 if (!(e->ipv6.flags & IP6T_F_PROTO) || 92 if (!(e->ipv6.flags & IP6T_F_PROTO) ||
93 e->ipv6.proto != IPPROTO_TCP || 93 e->ipv6.proto != IPPROTO_TCP ||
94 (e->ipv6.invflags & XT_INV_PROTO)) { 94 (e->ipv6.invflags & XT_INV_PROTO)) {
95 pr_info("TCP_RESET illegal for non-tcp\n"); 95 pr_info_ratelimited("TCP_RESET illegal for non-tcp\n");
96 return -EINVAL; 96 return -EINVAL;
97 } 97 }
98 } 98 }
diff --git a/net/ipv6/netfilter/ip6t_rpfilter.c b/net/ipv6/netfilter/ip6t_rpfilter.c
index b12e61b7b16c..91ed25a24b79 100644
--- a/net/ipv6/netfilter/ip6t_rpfilter.c
+++ b/net/ipv6/netfilter/ip6t_rpfilter.c
@@ -48,10 +48,6 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb,
48 } 48 }
49 49
50 fl6.flowi6_mark = flags & XT_RPFILTER_VALID_MARK ? skb->mark : 0; 50 fl6.flowi6_mark = flags & XT_RPFILTER_VALID_MARK ? skb->mark : 0;
51 if ((flags & XT_RPFILTER_LOOSE) == 0) {
52 fl6.flowi6_oif = dev->ifindex;
53 lookup_flags |= RT6_LOOKUP_F_IFACE;
54 }
55 51
56 rt = (void *) ip6_route_lookup(net, &fl6, lookup_flags); 52 rt = (void *) ip6_route_lookup(net, &fl6, lookup_flags);
57 if (rt->dst.error) 53 if (rt->dst.error)
@@ -103,14 +99,14 @@ static int rpfilter_check(const struct xt_mtchk_param *par)
103 unsigned int options = ~XT_RPFILTER_OPTION_MASK; 99 unsigned int options = ~XT_RPFILTER_OPTION_MASK;
104 100
105 if (info->flags & options) { 101 if (info->flags & options) {
106 pr_info("unknown options encountered"); 102 pr_info_ratelimited("unknown options\n");
107 return -EINVAL; 103 return -EINVAL;
108 } 104 }
109 105
110 if (strcmp(par->table, "mangle") != 0 && 106 if (strcmp(par->table, "mangle") != 0 &&
111 strcmp(par->table, "raw") != 0) { 107 strcmp(par->table, "raw") != 0) {
112 pr_info("match only valid in the \'raw\' " 108 pr_info_ratelimited("only valid in \'raw\' or \'mangle\' table, not \'%s\'\n",
113 "or \'mangle\' tables, not \'%s\'.\n", par->table); 109 par->table);
114 return -EINVAL; 110 return -EINVAL;
115 } 111 }
116 112
diff --git a/net/ipv6/netfilter/ip6t_srh.c b/net/ipv6/netfilter/ip6t_srh.c
index 9642164107ce..33719d5560c8 100644
--- a/net/ipv6/netfilter/ip6t_srh.c
+++ b/net/ipv6/netfilter/ip6t_srh.c
@@ -122,12 +122,14 @@ static int srh_mt6_check(const struct xt_mtchk_param *par)
122 const struct ip6t_srh *srhinfo = par->matchinfo; 122 const struct ip6t_srh *srhinfo = par->matchinfo;
123 123
124 if (srhinfo->mt_flags & ~IP6T_SRH_MASK) { 124 if (srhinfo->mt_flags & ~IP6T_SRH_MASK) {
125 pr_err("unknown srh match flags %X\n", srhinfo->mt_flags); 125 pr_info_ratelimited("unknown srh match flags %X\n",
126 srhinfo->mt_flags);
126 return -EINVAL; 127 return -EINVAL;
127 } 128 }
128 129
129 if (srhinfo->mt_invflags & ~IP6T_SRH_INV_MASK) { 130 if (srhinfo->mt_invflags & ~IP6T_SRH_INV_MASK) {
130 pr_err("unknown srh invflags %X\n", srhinfo->mt_invflags); 131 pr_info_ratelimited("unknown srh invflags %X\n",
132 srhinfo->mt_invflags);
131 return -EINVAL; 133 return -EINVAL;
132 } 134 }
133 135
diff --git a/net/ipv6/netfilter/nf_flow_table_ipv6.c b/net/ipv6/netfilter/nf_flow_table_ipv6.c
index d346705d6ee6..207cb35569b1 100644
--- a/net/ipv6/netfilter/nf_flow_table_ipv6.c
+++ b/net/ipv6/netfilter/nf_flow_table_ipv6.c
@@ -178,7 +178,7 @@ static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
178 if (skb->len <= mtu) 178 if (skb->len <= mtu)
179 return false; 179 return false;
180 180
181 if (skb_is_gso(skb) && skb_gso_validate_mtu(skb, mtu)) 181 if (skb_is_gso(skb) && skb_gso_validate_network_len(skb, mtu))
182 return false; 182 return false;
183 183
184 return true; 184 return true;
diff --git a/net/ipv6/netfilter/nf_nat_l3proto_ipv6.c b/net/ipv6/netfilter/nf_nat_l3proto_ipv6.c
index bed57ee65f7b..6b7f075f811f 100644
--- a/net/ipv6/netfilter/nf_nat_l3proto_ipv6.c
+++ b/net/ipv6/netfilter/nf_nat_l3proto_ipv6.c
@@ -99,6 +99,10 @@ static bool nf_nat_ipv6_manip_pkt(struct sk_buff *skb,
99 !l4proto->manip_pkt(skb, &nf_nat_l3proto_ipv6, iphdroff, hdroff, 99 !l4proto->manip_pkt(skb, &nf_nat_l3proto_ipv6, iphdroff, hdroff,
100 target, maniptype)) 100 target, maniptype))
101 return false; 101 return false;
102
103 /* must reload, offset might have changed */
104 ipv6h = (void *)skb->data + iphdroff;
105
102manip_addr: 106manip_addr:
103 if (maniptype == NF_NAT_MANIP_SRC) 107 if (maniptype == NF_NAT_MANIP_SRC)
104 ipv6h->saddr = target->src.u3.in6; 108 ipv6h->saddr = target->src.u3.in6;
diff --git a/net/ipv6/netfilter/nft_fib_ipv6.c b/net/ipv6/netfilter/nft_fib_ipv6.c
index cc5174c7254c..62fc84d7bdff 100644
--- a/net/ipv6/netfilter/nft_fib_ipv6.c
+++ b/net/ipv6/netfilter/nft_fib_ipv6.c
@@ -180,7 +180,6 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
180 } 180 }
181 181
182 *dest = 0; 182 *dest = 0;
183 again:
184 rt = (void *)ip6_route_lookup(nft_net(pkt), &fl6, lookup_flags); 183 rt = (void *)ip6_route_lookup(nft_net(pkt), &fl6, lookup_flags);
185 if (rt->dst.error) 184 if (rt->dst.error)
186 goto put_rt_err; 185 goto put_rt_err;
@@ -189,15 +188,8 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
189 if (rt->rt6i_flags & (RTF_REJECT | RTF_ANYCAST | RTF_LOCAL)) 188 if (rt->rt6i_flags & (RTF_REJECT | RTF_ANYCAST | RTF_LOCAL))
190 goto put_rt_err; 189 goto put_rt_err;
191 190
192 if (oif && oif != rt->rt6i_idev->dev) { 191 if (oif && oif != rt->rt6i_idev->dev)
193 /* multipath route? Try again with F_IFACE */ 192 goto put_rt_err;
194 if ((lookup_flags & RT6_LOOKUP_F_IFACE) == 0) {
195 lookup_flags |= RT6_LOOKUP_F_IFACE;
196 fl6.flowi6_oif = oif->ifindex;
197 ip6_rt_put(rt);
198 goto again;
199 }
200 }
201 193
202 switch (priv->result) { 194 switch (priv->result) {
203 case NFT_FIB_RESULT_OIF: 195 case NFT_FIB_RESULT_OIF:
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 9dcfadddd800..b0d5c64e1978 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -128,7 +128,7 @@ struct uncached_list {
128 128
129static DEFINE_PER_CPU_ALIGNED(struct uncached_list, rt6_uncached_list); 129static DEFINE_PER_CPU_ALIGNED(struct uncached_list, rt6_uncached_list);
130 130
131static void rt6_uncached_list_add(struct rt6_info *rt) 131void rt6_uncached_list_add(struct rt6_info *rt)
132{ 132{
133 struct uncached_list *ul = raw_cpu_ptr(&rt6_uncached_list); 133 struct uncached_list *ul = raw_cpu_ptr(&rt6_uncached_list);
134 134
@@ -139,7 +139,7 @@ static void rt6_uncached_list_add(struct rt6_info *rt)
139 spin_unlock_bh(&ul->lock); 139 spin_unlock_bh(&ul->lock);
140} 140}
141 141
142static void rt6_uncached_list_del(struct rt6_info *rt) 142void rt6_uncached_list_del(struct rt6_info *rt)
143{ 143{
144 if (!list_empty(&rt->rt6i_uncached)) { 144 if (!list_empty(&rt->rt6i_uncached)) {
145 struct uncached_list *ul = rt->rt6i_uncached_list; 145 struct uncached_list *ul = rt->rt6i_uncached_list;
@@ -1509,7 +1509,30 @@ static void rt6_exceptions_remove_prefsrc(struct rt6_info *rt)
1509 } 1509 }
1510} 1510}
1511 1511
1512static void rt6_exceptions_update_pmtu(struct rt6_info *rt, int mtu) 1512static bool rt6_mtu_change_route_allowed(struct inet6_dev *idev,
1513 struct rt6_info *rt, int mtu)
1514{
1515 /* If the new MTU is lower than the route PMTU, this new MTU will be the
1516 * lowest MTU in the path: always allow updating the route PMTU to
1517 * reflect PMTU decreases.
1518 *
1519 * If the new MTU is higher, and the route PMTU is equal to the local
1520 * MTU, this means the old MTU is the lowest in the path, so allow
1521 * updating it: if other nodes now have lower MTUs, PMTU discovery will
1522 * handle this.
1523 */
1524
1525 if (dst_mtu(&rt->dst) >= mtu)
1526 return true;
1527
1528 if (dst_mtu(&rt->dst) == idev->cnf.mtu6)
1529 return true;
1530
1531 return false;
1532}
1533
1534static void rt6_exceptions_update_pmtu(struct inet6_dev *idev,
1535 struct rt6_info *rt, int mtu)
1513{ 1536{
1514 struct rt6_exception_bucket *bucket; 1537 struct rt6_exception_bucket *bucket;
1515 struct rt6_exception *rt6_ex; 1538 struct rt6_exception *rt6_ex;
@@ -1518,20 +1541,22 @@ static void rt6_exceptions_update_pmtu(struct rt6_info *rt, int mtu)
1518 bucket = rcu_dereference_protected(rt->rt6i_exception_bucket, 1541 bucket = rcu_dereference_protected(rt->rt6i_exception_bucket,
1519 lockdep_is_held(&rt6_exception_lock)); 1542 lockdep_is_held(&rt6_exception_lock));
1520 1543
1521 if (bucket) { 1544 if (!bucket)
1522 for (i = 0; i < FIB6_EXCEPTION_BUCKET_SIZE; i++) { 1545 return;
1523 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { 1546
1524 struct rt6_info *entry = rt6_ex->rt6i; 1547 for (i = 0; i < FIB6_EXCEPTION_BUCKET_SIZE; i++) {
1525 /* For RTF_CACHE with rt6i_pmtu == 0 1548 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) {
1526 * (i.e. a redirected route), 1549 struct rt6_info *entry = rt6_ex->rt6i;
1527 * the metrics of its rt->dst.from has already 1550
1528 * been updated. 1551 /* For RTF_CACHE with rt6i_pmtu == 0 (i.e. a redirected
1529 */ 1552 * route), the metrics of its rt->dst.from have already
1530 if (entry->rt6i_pmtu && entry->rt6i_pmtu > mtu) 1553 * been updated.
1531 entry->rt6i_pmtu = mtu; 1554 */
1532 } 1555 if (entry->rt6i_pmtu &&
1533 bucket++; 1556 rt6_mtu_change_route_allowed(idev, entry, mtu))
1557 entry->rt6i_pmtu = mtu;
1534 } 1558 }
1559 bucket++;
1535 } 1560 }
1536} 1561}
1537 1562
@@ -3809,25 +3834,13 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg)
3809 Since RFC 1981 doesn't include administrative MTU increase 3834 Since RFC 1981 doesn't include administrative MTU increase
3810 update PMTU increase is a MUST. (i.e. jumbo frame) 3835 update PMTU increase is a MUST. (i.e. jumbo frame)
3811 */ 3836 */
3812 /*
3813 If new MTU is less than route PMTU, this new MTU will be the
3814 lowest MTU in the path, update the route PMTU to reflect PMTU
3815 decreases; if new MTU is greater than route PMTU, and the
3816 old MTU is the lowest MTU in the path, update the route PMTU
3817 to reflect the increase. In this case if the other nodes' MTU
3818 also have the lowest MTU, TOO BIG MESSAGE will be lead to
3819 PMTU discovery.
3820 */
3821 if (rt->dst.dev == arg->dev && 3837 if (rt->dst.dev == arg->dev &&
3822 dst_metric_raw(&rt->dst, RTAX_MTU) &&
3823 !dst_metric_locked(&rt->dst, RTAX_MTU)) { 3838 !dst_metric_locked(&rt->dst, RTAX_MTU)) {
3824 spin_lock_bh(&rt6_exception_lock); 3839 spin_lock_bh(&rt6_exception_lock);
3825 if (dst_mtu(&rt->dst) >= arg->mtu || 3840 if (dst_metric_raw(&rt->dst, RTAX_MTU) &&
3826 (dst_mtu(&rt->dst) < arg->mtu && 3841 rt6_mtu_change_route_allowed(idev, rt, arg->mtu))
3827 dst_mtu(&rt->dst) == idev->cnf.mtu6)) {
3828 dst_metric_set(&rt->dst, RTAX_MTU, arg->mtu); 3842 dst_metric_set(&rt->dst, RTAX_MTU, arg->mtu);
3829 } 3843 rt6_exceptions_update_pmtu(idev, rt, arg->mtu);
3830 rt6_exceptions_update_pmtu(rt, arg->mtu);
3831 spin_unlock_bh(&rt6_exception_lock); 3844 spin_unlock_bh(&rt6_exception_lock);
3832 } 3845 }
3833 return 0; 3846 return 0;
@@ -4099,6 +4112,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
4099 r_cfg.fc_encap_type = nla_get_u16(nla); 4112 r_cfg.fc_encap_type = nla_get_u16(nla);
4100 } 4113 }
4101 4114
4115 r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK);
4102 rt = ip6_route_info_create(&r_cfg, extack); 4116 rt = ip6_route_info_create(&r_cfg, extack);
4103 if (IS_ERR(rt)) { 4117 if (IS_ERR(rt)) {
4104 err = PTR_ERR(rt); 4118 err = PTR_ERR(rt);
diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
index bd6cc688bd19..7a78dcfda68a 100644
--- a/net/ipv6/seg6_iptunnel.c
+++ b/net/ipv6/seg6_iptunnel.c
@@ -93,7 +93,8 @@ static void set_tun_src(struct net *net, struct net_device *dev,
93/* encapsulate an IPv6 packet within an outer IPv6 header with a given SRH */ 93/* encapsulate an IPv6 packet within an outer IPv6 header with a given SRH */
94int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto) 94int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
95{ 95{
96 struct net *net = dev_net(skb_dst(skb)->dev); 96 struct dst_entry *dst = skb_dst(skb);
97 struct net *net = dev_net(dst->dev);
97 struct ipv6hdr *hdr, *inner_hdr; 98 struct ipv6hdr *hdr, *inner_hdr;
98 struct ipv6_sr_hdr *isrh; 99 struct ipv6_sr_hdr *isrh;
99 int hdrlen, tot_len, err; 100 int hdrlen, tot_len, err;
@@ -134,7 +135,7 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
134 isrh->nexthdr = proto; 135 isrh->nexthdr = proto;
135 136
136 hdr->daddr = isrh->segments[isrh->first_segment]; 137 hdr->daddr = isrh->segments[isrh->first_segment];
137 set_tun_src(net, skb->dev, &hdr->daddr, &hdr->saddr); 138 set_tun_src(net, ip6_dst_idev(dst)->dev, &hdr->daddr, &hdr->saddr);
138 139
139#ifdef CONFIG_IPV6_SEG6_HMAC 140#ifdef CONFIG_IPV6_SEG6_HMAC
140 if (sr_has_hmac(isrh)) { 141 if (sr_has_hmac(isrh)) {
@@ -418,7 +419,7 @@ static int seg6_build_state(struct nlattr *nla,
418 419
419 slwt = seg6_lwt_lwtunnel(newts); 420 slwt = seg6_lwt_lwtunnel(newts);
420 421
421 err = dst_cache_init(&slwt->cache, GFP_KERNEL); 422 err = dst_cache_init(&slwt->cache, GFP_ATOMIC);
422 if (err) { 423 if (err) {
423 kfree(newts); 424 kfree(newts);
424 return err; 425 return err;
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 3873d3877135..0195598f7bb5 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -182,7 +182,7 @@ static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn)
182#ifdef CONFIG_IPV6_SIT_6RD 182#ifdef CONFIG_IPV6_SIT_6RD
183 struct ip_tunnel *t = netdev_priv(dev); 183 struct ip_tunnel *t = netdev_priv(dev);
184 184
185 if (t->dev == sitn->fb_tunnel_dev) { 185 if (dev == sitn->fb_tunnel_dev) {
186 ipv6_addr_set(&t->ip6rd.prefix, htonl(0x20020000), 0, 0, 0); 186 ipv6_addr_set(&t->ip6rd.prefix, htonl(0x20020000), 0, 0, 0);
187 t->ip6rd.relay_prefix = 0; 187 t->ip6rd.relay_prefix = 0;
188 t->ip6rd.prefixlen = 16; 188 t->ip6rd.prefixlen = 16;
@@ -1578,6 +1578,13 @@ static int ipip6_newlink(struct net *src_net, struct net_device *dev,
1578 if (err < 0) 1578 if (err < 0)
1579 return err; 1579 return err;
1580 1580
1581 if (tb[IFLA_MTU]) {
1582 u32 mtu = nla_get_u32(tb[IFLA_MTU]);
1583
1584 if (mtu >= IPV6_MIN_MTU && mtu <= 0xFFF8 - dev->hard_header_len)
1585 dev->mtu = mtu;
1586 }
1587
1581#ifdef CONFIG_IPV6_SIT_6RD 1588#ifdef CONFIG_IPV6_SIT_6RD
1582 if (ipip6_netlink_6rd_parms(data, &ip6rd)) 1589 if (ipip6_netlink_6rd_parms(data, &ip6rd))
1583 err = ipip6_tunnel_update_6rd(nt, &ip6rd); 1590 err = ipip6_tunnel_update_6rd(nt, &ip6rd);
diff --git a/net/ipv6/xfrm6_mode_tunnel.c b/net/ipv6/xfrm6_mode_tunnel.c
index bb935a3b7fea..de1b0b8c53b0 100644
--- a/net/ipv6/xfrm6_mode_tunnel.c
+++ b/net/ipv6/xfrm6_mode_tunnel.c
@@ -92,7 +92,8 @@ static int xfrm6_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
92 92
93 skb_reset_network_header(skb); 93 skb_reset_network_header(skb);
94 skb_mac_header_rebuild(skb); 94 skb_mac_header_rebuild(skb);
95 eth_hdr(skb)->h_proto = skb->protocol; 95 if (skb->mac_len)
96 eth_hdr(skb)->h_proto = skb->protocol;
96 97
97 err = 0; 98 err = 0;
98 99
diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c
index 8ae87d4ec5ff..5959ce9620eb 100644
--- a/net/ipv6/xfrm6_output.c
+++ b/net/ipv6/xfrm6_output.c
@@ -82,7 +82,7 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb)
82 82
83 if ((!skb_is_gso(skb) && skb->len > mtu) || 83 if ((!skb_is_gso(skb) && skb->len > mtu) ||
84 (skb_is_gso(skb) && 84 (skb_is_gso(skb) &&
85 skb_gso_network_seglen(skb) > ip6_skb_dst_mtu(skb))) { 85 !skb_gso_validate_network_len(skb, ip6_skb_dst_mtu(skb)))) {
86 skb->dev = dst->dev; 86 skb->dev = dst->dev;
87 skb->protocol = htons(ETH_P_IPV6); 87 skb->protocol = htons(ETH_P_IPV6);
88 88
diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
index 09fb44ee3b45..416fe67271a9 100644
--- a/net/ipv6/xfrm6_policy.c
+++ b/net/ipv6/xfrm6_policy.c
@@ -113,6 +113,9 @@ static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
113 xdst->u.rt6.rt6i_gateway = rt->rt6i_gateway; 113 xdst->u.rt6.rt6i_gateway = rt->rt6i_gateway;
114 xdst->u.rt6.rt6i_dst = rt->rt6i_dst; 114 xdst->u.rt6.rt6i_dst = rt->rt6i_dst;
115 xdst->u.rt6.rt6i_src = rt->rt6i_src; 115 xdst->u.rt6.rt6i_src = rt->rt6i_src;
116 INIT_LIST_HEAD(&xdst->u.rt6.rt6i_uncached);
117 rt6_uncached_list_add(&xdst->u.rt6);
118 atomic_inc(&dev_net(dev)->ipv6.rt6_stats->fib_rt_uncache);
116 119
117 return 0; 120 return 0;
118} 121}
@@ -244,6 +247,8 @@ static void xfrm6_dst_destroy(struct dst_entry *dst)
244 if (likely(xdst->u.rt6.rt6i_idev)) 247 if (likely(xdst->u.rt6.rt6i_idev))
245 in6_dev_put(xdst->u.rt6.rt6i_idev); 248 in6_dev_put(xdst->u.rt6.rt6i_idev);
246 dst_destroy_metrics_generic(dst); 249 dst_destroy_metrics_generic(dst);
250 if (xdst->u.rt6.rt6i_uncached_list)
251 rt6_uncached_list_del(&xdst->u.rt6);
247 xfrm_dst_destroy(xdst); 252 xfrm_dst_destroy(xdst);
248} 253}
249 254
diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index 1e8cc7bcbca3..9e2643ab4ccb 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -2433,9 +2433,11 @@ static int afiucv_iucv_init(void)
2433 af_iucv_dev->driver = &af_iucv_driver; 2433 af_iucv_dev->driver = &af_iucv_driver;
2434 err = device_register(af_iucv_dev); 2434 err = device_register(af_iucv_dev);
2435 if (err) 2435 if (err)
2436 goto out_driver; 2436 goto out_iucv_dev;
2437 return 0; 2437 return 0;
2438 2438
2439out_iucv_dev:
2440 put_device(af_iucv_dev);
2439out_driver: 2441out_driver:
2440 driver_unregister(&af_iucv_driver); 2442 driver_unregister(&af_iucv_driver);
2441out_iucv: 2443out_iucv:
diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c
index f297d53a11aa..34355fd19f27 100644
--- a/net/kcm/kcmsock.c
+++ b/net/kcm/kcmsock.c
@@ -1381,24 +1381,32 @@ static int kcm_attach(struct socket *sock, struct socket *csock,
1381 .parse_msg = kcm_parse_func_strparser, 1381 .parse_msg = kcm_parse_func_strparser,
1382 .read_sock_done = kcm_read_sock_done, 1382 .read_sock_done = kcm_read_sock_done,
1383 }; 1383 };
1384 int err; 1384 int err = 0;
1385 1385
1386 csk = csock->sk; 1386 csk = csock->sk;
1387 if (!csk) 1387 if (!csk)
1388 return -EINVAL; 1388 return -EINVAL;
1389 1389
1390 lock_sock(csk);
1391
1390 /* Only allow TCP sockets to be attached for now */ 1392 /* Only allow TCP sockets to be attached for now */
1391 if ((csk->sk_family != AF_INET && csk->sk_family != AF_INET6) || 1393 if ((csk->sk_family != AF_INET && csk->sk_family != AF_INET6) ||
1392 csk->sk_protocol != IPPROTO_TCP) 1394 csk->sk_protocol != IPPROTO_TCP) {
1393 return -EOPNOTSUPP; 1395 err = -EOPNOTSUPP;
1396 goto out;
1397 }
1394 1398
1395 /* Don't allow listeners or closed sockets */ 1399 /* Don't allow listeners or closed sockets */
1396 if (csk->sk_state == TCP_LISTEN || csk->sk_state == TCP_CLOSE) 1400 if (csk->sk_state == TCP_LISTEN || csk->sk_state == TCP_CLOSE) {
1397 return -EOPNOTSUPP; 1401 err = -EOPNOTSUPP;
1402 goto out;
1403 }
1398 1404
1399 psock = kmem_cache_zalloc(kcm_psockp, GFP_KERNEL); 1405 psock = kmem_cache_zalloc(kcm_psockp, GFP_KERNEL);
1400 if (!psock) 1406 if (!psock) {
1401 return -ENOMEM; 1407 err = -ENOMEM;
1408 goto out;
1409 }
1402 1410
1403 psock->mux = mux; 1411 psock->mux = mux;
1404 psock->sk = csk; 1412 psock->sk = csk;
@@ -1407,7 +1415,7 @@ static int kcm_attach(struct socket *sock, struct socket *csock,
1407 err = strp_init(&psock->strp, csk, &cb); 1415 err = strp_init(&psock->strp, csk, &cb);
1408 if (err) { 1416 if (err) {
1409 kmem_cache_free(kcm_psockp, psock); 1417 kmem_cache_free(kcm_psockp, psock);
1410 return err; 1418 goto out;
1411 } 1419 }
1412 1420
1413 write_lock_bh(&csk->sk_callback_lock); 1421 write_lock_bh(&csk->sk_callback_lock);
@@ -1419,7 +1427,8 @@ static int kcm_attach(struct socket *sock, struct socket *csock,
1419 write_unlock_bh(&csk->sk_callback_lock); 1427 write_unlock_bh(&csk->sk_callback_lock);
1420 strp_done(&psock->strp); 1428 strp_done(&psock->strp);
1421 kmem_cache_free(kcm_psockp, psock); 1429 kmem_cache_free(kcm_psockp, psock);
1422 return -EALREADY; 1430 err = -EALREADY;
1431 goto out;
1423 } 1432 }
1424 1433
1425 psock->save_data_ready = csk->sk_data_ready; 1434 psock->save_data_ready = csk->sk_data_ready;
@@ -1455,7 +1464,10 @@ static int kcm_attach(struct socket *sock, struct socket *csock,
1455 /* Schedule RX work in case there are already bytes queued */ 1464 /* Schedule RX work in case there are already bytes queued */
1456 strp_check_rcv(&psock->strp); 1465 strp_check_rcv(&psock->strp);
1457 1466
1458 return 0; 1467out:
1468 release_sock(csk);
1469
1470 return err;
1459} 1471}
1460 1472
1461static int kcm_attach_ioctl(struct socket *sock, struct kcm_attach *info) 1473static int kcm_attach_ioctl(struct socket *sock, struct kcm_attach *info)
@@ -1507,6 +1519,7 @@ static void kcm_unattach(struct kcm_psock *psock)
1507 1519
1508 if (WARN_ON(psock->rx_kcm)) { 1520 if (WARN_ON(psock->rx_kcm)) {
1509 write_unlock_bh(&csk->sk_callback_lock); 1521 write_unlock_bh(&csk->sk_callback_lock);
1522 release_sock(csk);
1510 return; 1523 return;
1511 } 1524 }
1512 1525
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 194a7483bb93..14b67dfacc4b 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -111,6 +111,13 @@ struct l2tp_net {
111 spinlock_t l2tp_session_hlist_lock; 111 spinlock_t l2tp_session_hlist_lock;
112}; 112};
113 113
114#if IS_ENABLED(CONFIG_IPV6)
115static bool l2tp_sk_is_v6(struct sock *sk)
116{
117 return sk->sk_family == PF_INET6 &&
118 !ipv6_addr_v4mapped(&sk->sk_v6_daddr);
119}
120#endif
114 121
115static inline struct l2tp_tunnel *l2tp_tunnel(struct sock *sk) 122static inline struct l2tp_tunnel *l2tp_tunnel(struct sock *sk)
116{ 123{
@@ -136,51 +143,6 @@ l2tp_session_id_hash_2(struct l2tp_net *pn, u32 session_id)
136 143
137} 144}
138 145
139/* Lookup the tunnel socket, possibly involving the fs code if the socket is
140 * owned by userspace. A struct sock returned from this function must be
141 * released using l2tp_tunnel_sock_put once you're done with it.
142 */
143static struct sock *l2tp_tunnel_sock_lookup(struct l2tp_tunnel *tunnel)
144{
145 int err = 0;
146 struct socket *sock = NULL;
147 struct sock *sk = NULL;
148
149 if (!tunnel)
150 goto out;
151
152 if (tunnel->fd >= 0) {
153 /* Socket is owned by userspace, who might be in the process
154 * of closing it. Look the socket up using the fd to ensure
155 * consistency.
156 */
157 sock = sockfd_lookup(tunnel->fd, &err);
158 if (sock)
159 sk = sock->sk;
160 } else {
161 /* Socket is owned by kernelspace */
162 sk = tunnel->sock;
163 sock_hold(sk);
164 }
165
166out:
167 return sk;
168}
169
170/* Drop a reference to a tunnel socket obtained via. l2tp_tunnel_sock_put */
171static void l2tp_tunnel_sock_put(struct sock *sk)
172{
173 struct l2tp_tunnel *tunnel = l2tp_sock_to_tunnel(sk);
174 if (tunnel) {
175 if (tunnel->fd >= 0) {
176 /* Socket is owned by userspace */
177 sockfd_put(sk->sk_socket);
178 }
179 sock_put(sk);
180 }
181 sock_put(sk);
182}
183
184/* Session hash list. 146/* Session hash list.
185 * The session_id SHOULD be random according to RFC2661, but several 147 * The session_id SHOULD be random according to RFC2661, but several
186 * L2TP implementations (Cisco and Microsoft) use incrementing 148 * L2TP implementations (Cisco and Microsoft) use incrementing
@@ -193,6 +155,13 @@ l2tp_session_id_hash(struct l2tp_tunnel *tunnel, u32 session_id)
193 return &tunnel->session_hlist[hash_32(session_id, L2TP_HASH_BITS)]; 155 return &tunnel->session_hlist[hash_32(session_id, L2TP_HASH_BITS)];
194} 156}
195 157
158void l2tp_tunnel_free(struct l2tp_tunnel *tunnel)
159{
160 sock_put(tunnel->sock);
161 /* the tunnel is freed in the socket destructor */
162}
163EXPORT_SYMBOL(l2tp_tunnel_free);
164
196/* Lookup a tunnel. A new reference is held on the returned tunnel. */ 165/* Lookup a tunnel. A new reference is held on the returned tunnel. */
197struct l2tp_tunnel *l2tp_tunnel_get(const struct net *net, u32 tunnel_id) 166struct l2tp_tunnel *l2tp_tunnel_get(const struct net *net, u32 tunnel_id)
198{ 167{
@@ -345,13 +314,11 @@ int l2tp_session_register(struct l2tp_session *session,
345 } 314 }
346 315
347 l2tp_tunnel_inc_refcount(tunnel); 316 l2tp_tunnel_inc_refcount(tunnel);
348 sock_hold(tunnel->sock);
349 hlist_add_head_rcu(&session->global_hlist, g_head); 317 hlist_add_head_rcu(&session->global_hlist, g_head);
350 318
351 spin_unlock_bh(&pn->l2tp_session_hlist_lock); 319 spin_unlock_bh(&pn->l2tp_session_hlist_lock);
352 } else { 320 } else {
353 l2tp_tunnel_inc_refcount(tunnel); 321 l2tp_tunnel_inc_refcount(tunnel);
354 sock_hold(tunnel->sock);
355 } 322 }
356 323
357 hlist_add_head(&session->hlist, head); 324 hlist_add_head(&session->hlist, head);
@@ -969,7 +936,7 @@ int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
969{ 936{
970 struct l2tp_tunnel *tunnel; 937 struct l2tp_tunnel *tunnel;
971 938
972 tunnel = l2tp_sock_to_tunnel(sk); 939 tunnel = l2tp_tunnel(sk);
973 if (tunnel == NULL) 940 if (tunnel == NULL)
974 goto pass_up; 941 goto pass_up;
975 942
@@ -977,13 +944,10 @@ int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
977 tunnel->name, skb->len); 944 tunnel->name, skb->len);
978 945
979 if (l2tp_udp_recv_core(tunnel, skb, tunnel->recv_payload_hook)) 946 if (l2tp_udp_recv_core(tunnel, skb, tunnel->recv_payload_hook))
980 goto pass_up_put; 947 goto pass_up;
981 948
982 sock_put(sk);
983 return 0; 949 return 0;
984 950
985pass_up_put:
986 sock_put(sk);
987pass_up: 951pass_up:
988 return 1; 952 return 1;
989} 953}
@@ -1092,7 +1056,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
1092 /* Queue the packet to IP for output */ 1056 /* Queue the packet to IP for output */
1093 skb->ignore_df = 1; 1057 skb->ignore_df = 1;
1094#if IS_ENABLED(CONFIG_IPV6) 1058#if IS_ENABLED(CONFIG_IPV6)
1095 if (tunnel->sock->sk_family == PF_INET6 && !tunnel->v4mapped) 1059 if (l2tp_sk_is_v6(tunnel->sock))
1096 error = inet6_csk_xmit(tunnel->sock, skb, NULL); 1060 error = inet6_csk_xmit(tunnel->sock, skb, NULL);
1097 else 1061 else
1098#endif 1062#endif
@@ -1155,6 +1119,15 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
1155 goto out_unlock; 1119 goto out_unlock;
1156 } 1120 }
1157 1121
1122 /* The user-space may change the connection status for the user-space
1123 * provided socket at run time: we must check it under the socket lock
1124 */
1125 if (tunnel->fd >= 0 && sk->sk_state != TCP_ESTABLISHED) {
1126 kfree_skb(skb);
1127 ret = NET_XMIT_DROP;
1128 goto out_unlock;
1129 }
1130
1158 /* Get routing info from the tunnel socket */ 1131 /* Get routing info from the tunnel socket */
1159 skb_dst_drop(skb); 1132 skb_dst_drop(skb);
1160 skb_dst_set(skb, dst_clone(__sk_dst_check(sk, 0))); 1133 skb_dst_set(skb, dst_clone(__sk_dst_check(sk, 0)));
@@ -1174,7 +1147,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
1174 1147
1175 /* Calculate UDP checksum if configured to do so */ 1148 /* Calculate UDP checksum if configured to do so */
1176#if IS_ENABLED(CONFIG_IPV6) 1149#if IS_ENABLED(CONFIG_IPV6)
1177 if (sk->sk_family == PF_INET6 && !tunnel->v4mapped) 1150 if (l2tp_sk_is_v6(sk))
1178 udp6_set_csum(udp_get_no_check6_tx(sk), 1151 udp6_set_csum(udp_get_no_check6_tx(sk),
1179 skb, &inet6_sk(sk)->saddr, 1152 skb, &inet6_sk(sk)->saddr,
1180 &sk->sk_v6_daddr, udp_len); 1153 &sk->sk_v6_daddr, udp_len);
@@ -1207,14 +1180,12 @@ EXPORT_SYMBOL_GPL(l2tp_xmit_skb);
1207static void l2tp_tunnel_destruct(struct sock *sk) 1180static void l2tp_tunnel_destruct(struct sock *sk)
1208{ 1181{
1209 struct l2tp_tunnel *tunnel = l2tp_tunnel(sk); 1182 struct l2tp_tunnel *tunnel = l2tp_tunnel(sk);
1210 struct l2tp_net *pn;
1211 1183
1212 if (tunnel == NULL) 1184 if (tunnel == NULL)
1213 goto end; 1185 goto end;
1214 1186
1215 l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name); 1187 l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name);
1216 1188
1217
1218 /* Disable udp encapsulation */ 1189 /* Disable udp encapsulation */
1219 switch (tunnel->encap) { 1190 switch (tunnel->encap) {
1220 case L2TP_ENCAPTYPE_UDP: 1191 case L2TP_ENCAPTYPE_UDP:
@@ -1231,18 +1202,11 @@ static void l2tp_tunnel_destruct(struct sock *sk)
1231 sk->sk_destruct = tunnel->old_sk_destruct; 1202 sk->sk_destruct = tunnel->old_sk_destruct;
1232 sk->sk_user_data = NULL; 1203 sk->sk_user_data = NULL;
1233 1204
1234 /* Remove the tunnel struct from the tunnel list */
1235 pn = l2tp_pernet(tunnel->l2tp_net);
1236 spin_lock_bh(&pn->l2tp_tunnel_list_lock);
1237 list_del_rcu(&tunnel->list);
1238 spin_unlock_bh(&pn->l2tp_tunnel_list_lock);
1239
1240 tunnel->sock = NULL;
1241 l2tp_tunnel_dec_refcount(tunnel);
1242
1243 /* Call the original destructor */ 1205 /* Call the original destructor */
1244 if (sk->sk_destruct) 1206 if (sk->sk_destruct)
1245 (*sk->sk_destruct)(sk); 1207 (*sk->sk_destruct)(sk);
1208
1209 kfree_rcu(tunnel, rcu);
1246end: 1210end:
1247 return; 1211 return;
1248} 1212}
@@ -1303,49 +1267,43 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_closeall);
1303/* Tunnel socket destroy hook for UDP encapsulation */ 1267/* Tunnel socket destroy hook for UDP encapsulation */
1304static void l2tp_udp_encap_destroy(struct sock *sk) 1268static void l2tp_udp_encap_destroy(struct sock *sk)
1305{ 1269{
1306 struct l2tp_tunnel *tunnel = l2tp_sock_to_tunnel(sk); 1270 struct l2tp_tunnel *tunnel = l2tp_tunnel(sk);
1307 if (tunnel) { 1271
1308 l2tp_tunnel_closeall(tunnel); 1272 if (tunnel)
1309 sock_put(sk); 1273 l2tp_tunnel_delete(tunnel);
1310 }
1311} 1274}
1312 1275
1313/* Workqueue tunnel deletion function */ 1276/* Workqueue tunnel deletion function */
1314static void l2tp_tunnel_del_work(struct work_struct *work) 1277static void l2tp_tunnel_del_work(struct work_struct *work)
1315{ 1278{
1316 struct l2tp_tunnel *tunnel = NULL; 1279 struct l2tp_tunnel *tunnel = container_of(work, struct l2tp_tunnel,
1317 struct socket *sock = NULL; 1280 del_work);
1318 struct sock *sk = NULL; 1281 struct sock *sk = tunnel->sock;
1319 1282 struct socket *sock = sk->sk_socket;
1320 tunnel = container_of(work, struct l2tp_tunnel, del_work); 1283 struct l2tp_net *pn;
1321 1284
1322 l2tp_tunnel_closeall(tunnel); 1285 l2tp_tunnel_closeall(tunnel);
1323 1286
1324 sk = l2tp_tunnel_sock_lookup(tunnel); 1287 /* If the tunnel socket was created within the kernel, use
1325 if (!sk)
1326 goto out;
1327
1328 sock = sk->sk_socket;
1329
1330 /* If the tunnel socket was created by userspace, then go through the
1331 * inet layer to shut the socket down, and let userspace close it.
1332 * Otherwise, if we created the socket directly within the kernel, use
1333 * the sk API to release it here. 1288 * the sk API to release it here.
1334 * In either case the tunnel resources are freed in the socket
1335 * destructor when the tunnel socket goes away.
1336 */ 1289 */
1337 if (tunnel->fd >= 0) { 1290 if (tunnel->fd < 0) {
1338 if (sock)
1339 inet_shutdown(sock, 2);
1340 } else {
1341 if (sock) { 1291 if (sock) {
1342 kernel_sock_shutdown(sock, SHUT_RDWR); 1292 kernel_sock_shutdown(sock, SHUT_RDWR);
1343 sock_release(sock); 1293 sock_release(sock);
1344 } 1294 }
1345 } 1295 }
1346 1296
1347 l2tp_tunnel_sock_put(sk); 1297 /* Remove the tunnel struct from the tunnel list */
1348out: 1298 pn = l2tp_pernet(tunnel->l2tp_net);
1299 spin_lock_bh(&pn->l2tp_tunnel_list_lock);
1300 list_del_rcu(&tunnel->list);
1301 spin_unlock_bh(&pn->l2tp_tunnel_list_lock);
1302
1303 /* drop initial ref */
1304 l2tp_tunnel_dec_refcount(tunnel);
1305
1306 /* drop workqueue ref */
1349 l2tp_tunnel_dec_refcount(tunnel); 1307 l2tp_tunnel_dec_refcount(tunnel);
1350} 1308}
1351 1309
@@ -1515,9 +1473,14 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
1515 encap = cfg->encap; 1473 encap = cfg->encap;
1516 1474
1517 /* Quick sanity checks */ 1475 /* Quick sanity checks */
1476 err = -EPROTONOSUPPORT;
1477 if (sk->sk_type != SOCK_DGRAM) {
1478 pr_debug("tunl %hu: fd %d wrong socket type\n",
1479 tunnel_id, fd);
1480 goto err;
1481 }
1518 switch (encap) { 1482 switch (encap) {
1519 case L2TP_ENCAPTYPE_UDP: 1483 case L2TP_ENCAPTYPE_UDP:
1520 err = -EPROTONOSUPPORT;
1521 if (sk->sk_protocol != IPPROTO_UDP) { 1484 if (sk->sk_protocol != IPPROTO_UDP) {
1522 pr_err("tunl %hu: fd %d wrong protocol, got %d, expected %d\n", 1485 pr_err("tunl %hu: fd %d wrong protocol, got %d, expected %d\n",
1523 tunnel_id, fd, sk->sk_protocol, IPPROTO_UDP); 1486 tunnel_id, fd, sk->sk_protocol, IPPROTO_UDP);
@@ -1525,7 +1488,6 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
1525 } 1488 }
1526 break; 1489 break;
1527 case L2TP_ENCAPTYPE_IP: 1490 case L2TP_ENCAPTYPE_IP:
1528 err = -EPROTONOSUPPORT;
1529 if (sk->sk_protocol != IPPROTO_L2TP) { 1491 if (sk->sk_protocol != IPPROTO_L2TP) {
1530 pr_err("tunl %hu: fd %d wrong protocol, got %d, expected %d\n", 1492 pr_err("tunl %hu: fd %d wrong protocol, got %d, expected %d\n",
1531 tunnel_id, fd, sk->sk_protocol, IPPROTO_L2TP); 1493 tunnel_id, fd, sk->sk_protocol, IPPROTO_L2TP);
@@ -1565,24 +1527,6 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
1565 if (cfg != NULL) 1527 if (cfg != NULL)
1566 tunnel->debug = cfg->debug; 1528 tunnel->debug = cfg->debug;
1567 1529
1568#if IS_ENABLED(CONFIG_IPV6)
1569 if (sk->sk_family == PF_INET6) {
1570 struct ipv6_pinfo *np = inet6_sk(sk);
1571
1572 if (ipv6_addr_v4mapped(&np->saddr) &&
1573 ipv6_addr_v4mapped(&sk->sk_v6_daddr)) {
1574 struct inet_sock *inet = inet_sk(sk);
1575
1576 tunnel->v4mapped = true;
1577 inet->inet_saddr = np->saddr.s6_addr32[3];
1578 inet->inet_rcv_saddr = sk->sk_v6_rcv_saddr.s6_addr32[3];
1579 inet->inet_daddr = sk->sk_v6_daddr.s6_addr32[3];
1580 } else {
1581 tunnel->v4mapped = false;
1582 }
1583 }
1584#endif
1585
1586 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */ 1530 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
1587 tunnel->encap = encap; 1531 tunnel->encap = encap;
1588 if (encap == L2TP_ENCAPTYPE_UDP) { 1532 if (encap == L2TP_ENCAPTYPE_UDP) {
@@ -1598,13 +1542,22 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
1598 sk->sk_user_data = tunnel; 1542 sk->sk_user_data = tunnel;
1599 } 1543 }
1600 1544
1545 /* Bump the reference count. The tunnel context is deleted
1546 * only when this drops to zero. A reference is also held on
1547 * the tunnel socket to ensure that it is not released while
1548 * the tunnel is extant. Must be done before sk_destruct is
1549 * set.
1550 */
1551 refcount_set(&tunnel->ref_count, 1);
1552 sock_hold(sk);
1553 tunnel->sock = sk;
1554 tunnel->fd = fd;
1555
1601 /* Hook on the tunnel socket destructor so that we can cleanup 1556 /* Hook on the tunnel socket destructor so that we can cleanup
1602 * if the tunnel socket goes away. 1557 * if the tunnel socket goes away.
1603 */ 1558 */
1604 tunnel->old_sk_destruct = sk->sk_destruct; 1559 tunnel->old_sk_destruct = sk->sk_destruct;
1605 sk->sk_destruct = &l2tp_tunnel_destruct; 1560 sk->sk_destruct = &l2tp_tunnel_destruct;
1606 tunnel->sock = sk;
1607 tunnel->fd = fd;
1608 lockdep_set_class_and_name(&sk->sk_lock.slock, &l2tp_socket_class, "l2tp_sock"); 1561 lockdep_set_class_and_name(&sk->sk_lock.slock, &l2tp_socket_class, "l2tp_sock");
1609 1562
1610 sk->sk_allocation = GFP_ATOMIC; 1563 sk->sk_allocation = GFP_ATOMIC;
@@ -1614,11 +1567,6 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
1614 1567
1615 /* Add tunnel to our list */ 1568 /* Add tunnel to our list */
1616 INIT_LIST_HEAD(&tunnel->list); 1569 INIT_LIST_HEAD(&tunnel->list);
1617
1618 /* Bump the reference count. The tunnel context is deleted
1619 * only when this drops to zero. Must be done before list insertion
1620 */
1621 refcount_set(&tunnel->ref_count, 1);
1622 spin_lock_bh(&pn->l2tp_tunnel_list_lock); 1570 spin_lock_bh(&pn->l2tp_tunnel_list_lock);
1623 list_add_rcu(&tunnel->list, &pn->l2tp_tunnel_list); 1571 list_add_rcu(&tunnel->list, &pn->l2tp_tunnel_list);
1624 spin_unlock_bh(&pn->l2tp_tunnel_list_lock); 1572 spin_unlock_bh(&pn->l2tp_tunnel_list_lock);
@@ -1659,8 +1607,6 @@ void l2tp_session_free(struct l2tp_session *session)
1659 1607
1660 if (tunnel) { 1608 if (tunnel) {
1661 BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC); 1609 BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
1662 sock_put(tunnel->sock);
1663 session->tunnel = NULL;
1664 l2tp_tunnel_dec_refcount(tunnel); 1610 l2tp_tunnel_dec_refcount(tunnel);
1665 } 1611 }
1666 1612
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
index 9bbee90e9963..2718d0b284d0 100644
--- a/net/l2tp/l2tp_core.h
+++ b/net/l2tp/l2tp_core.h
@@ -188,9 +188,6 @@ struct l2tp_tunnel {
188 struct sock *sock; /* Parent socket */ 188 struct sock *sock; /* Parent socket */
189 int fd; /* Parent fd, if tunnel socket 189 int fd; /* Parent fd, if tunnel socket
190 * was created by userspace */ 190 * was created by userspace */
191#if IS_ENABLED(CONFIG_IPV6)
192 bool v4mapped;
193#endif
194 191
195 struct work_struct del_work; 192 struct work_struct del_work;
196 193
@@ -214,27 +211,8 @@ static inline void *l2tp_session_priv(struct l2tp_session *session)
214 return &session->priv[0]; 211 return &session->priv[0];
215} 212}
216 213
217static inline struct l2tp_tunnel *l2tp_sock_to_tunnel(struct sock *sk)
218{
219 struct l2tp_tunnel *tunnel;
220
221 if (sk == NULL)
222 return NULL;
223
224 sock_hold(sk);
225 tunnel = (struct l2tp_tunnel *)(sk->sk_user_data);
226 if (tunnel == NULL) {
227 sock_put(sk);
228 goto out;
229 }
230
231 BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
232
233out:
234 return tunnel;
235}
236
237struct l2tp_tunnel *l2tp_tunnel_get(const struct net *net, u32 tunnel_id); 214struct l2tp_tunnel *l2tp_tunnel_get(const struct net *net, u32 tunnel_id);
215void l2tp_tunnel_free(struct l2tp_tunnel *tunnel);
238 216
239struct l2tp_session *l2tp_session_get(const struct net *net, 217struct l2tp_session *l2tp_session_get(const struct net *net,
240 struct l2tp_tunnel *tunnel, 218 struct l2tp_tunnel *tunnel,
@@ -283,7 +261,7 @@ static inline void l2tp_tunnel_inc_refcount(struct l2tp_tunnel *tunnel)
283static inline void l2tp_tunnel_dec_refcount(struct l2tp_tunnel *tunnel) 261static inline void l2tp_tunnel_dec_refcount(struct l2tp_tunnel *tunnel)
284{ 262{
285 if (refcount_dec_and_test(&tunnel->ref_count)) 263 if (refcount_dec_and_test(&tunnel->ref_count))
286 kfree_rcu(tunnel, rcu); 264 l2tp_tunnel_free(tunnel);
287} 265}
288 266
289/* Session reference counts. Incremented when code obtains a reference 267/* Session reference counts. Incremented when code obtains a reference
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index ff61124fdf59..3428fba6f2b7 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -234,17 +234,13 @@ static void l2tp_ip_close(struct sock *sk, long timeout)
234static void l2tp_ip_destroy_sock(struct sock *sk) 234static void l2tp_ip_destroy_sock(struct sock *sk)
235{ 235{
236 struct sk_buff *skb; 236 struct sk_buff *skb;
237 struct l2tp_tunnel *tunnel = l2tp_sock_to_tunnel(sk); 237 struct l2tp_tunnel *tunnel = sk->sk_user_data;
238 238
239 while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL) 239 while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL)
240 kfree_skb(skb); 240 kfree_skb(skb);
241 241
242 if (tunnel) { 242 if (tunnel)
243 l2tp_tunnel_closeall(tunnel); 243 l2tp_tunnel_delete(tunnel);
244 sock_put(sk);
245 }
246
247 sk_refcnt_debug_dec(sk);
248} 244}
249 245
250static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) 246static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index 192344688c06..6f009eaa5fbe 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -248,16 +248,14 @@ static void l2tp_ip6_close(struct sock *sk, long timeout)
248 248
249static void l2tp_ip6_destroy_sock(struct sock *sk) 249static void l2tp_ip6_destroy_sock(struct sock *sk)
250{ 250{
251 struct l2tp_tunnel *tunnel = l2tp_sock_to_tunnel(sk); 251 struct l2tp_tunnel *tunnel = sk->sk_user_data;
252 252
253 lock_sock(sk); 253 lock_sock(sk);
254 ip6_flush_pending_frames(sk); 254 ip6_flush_pending_frames(sk);
255 release_sock(sk); 255 release_sock(sk);
256 256
257 if (tunnel) { 257 if (tunnel)
258 l2tp_tunnel_closeall(tunnel); 258 l2tp_tunnel_delete(tunnel);
259 sock_put(sk);
260 }
261 259
262 inet6_destroy_sock(sk); 260 inet6_destroy_sock(sk);
263} 261}
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index 59f246d7b290..3b02f24ea9ec 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -416,20 +416,28 @@ abort:
416 * Session (and tunnel control) socket create/destroy. 416 * Session (and tunnel control) socket create/destroy.
417 *****************************************************************************/ 417 *****************************************************************************/
418 418
419static void pppol2tp_put_sk(struct rcu_head *head)
420{
421 struct pppol2tp_session *ps;
422
423 ps = container_of(head, typeof(*ps), rcu);
424 sock_put(ps->__sk);
425}
426
419/* Called by l2tp_core when a session socket is being closed. 427/* Called by l2tp_core when a session socket is being closed.
420 */ 428 */
421static void pppol2tp_session_close(struct l2tp_session *session) 429static void pppol2tp_session_close(struct l2tp_session *session)
422{ 430{
423 struct sock *sk; 431 struct pppol2tp_session *ps;
424
425 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
426 432
427 sk = pppol2tp_session_get_sock(session); 433 ps = l2tp_session_priv(session);
428 if (sk) { 434 mutex_lock(&ps->sk_lock);
429 if (sk->sk_socket) 435 ps->__sk = rcu_dereference_protected(ps->sk,
430 inet_shutdown(sk->sk_socket, SEND_SHUTDOWN); 436 lockdep_is_held(&ps->sk_lock));
431 sock_put(sk); 437 RCU_INIT_POINTER(ps->sk, NULL);
432 } 438 if (ps->__sk)
439 call_rcu(&ps->rcu, pppol2tp_put_sk);
440 mutex_unlock(&ps->sk_lock);
433} 441}
434 442
435/* Really kill the session socket. (Called from sock_put() if 443/* Really kill the session socket. (Called from sock_put() if
@@ -449,14 +457,6 @@ static void pppol2tp_session_destruct(struct sock *sk)
449 } 457 }
450} 458}
451 459
452static void pppol2tp_put_sk(struct rcu_head *head)
453{
454 struct pppol2tp_session *ps;
455
456 ps = container_of(head, typeof(*ps), rcu);
457 sock_put(ps->__sk);
458}
459
460/* Called when the PPPoX socket (session) is closed. 460/* Called when the PPPoX socket (session) is closed.
461 */ 461 */
462static int pppol2tp_release(struct socket *sock) 462static int pppol2tp_release(struct socket *sock)
@@ -480,26 +480,17 @@ static int pppol2tp_release(struct socket *sock)
480 sock_orphan(sk); 480 sock_orphan(sk);
481 sock->sk = NULL; 481 sock->sk = NULL;
482 482
483 /* If the socket is associated with a session,
484 * l2tp_session_delete will call pppol2tp_session_close which
485 * will drop the session's ref on the socket.
486 */
483 session = pppol2tp_sock_to_session(sk); 487 session = pppol2tp_sock_to_session(sk);
484 488 if (session) {
485 if (session != NULL) {
486 struct pppol2tp_session *ps;
487
488 l2tp_session_delete(session); 489 l2tp_session_delete(session);
489 490 /* drop the ref obtained by pppol2tp_sock_to_session */
490 ps = l2tp_session_priv(session); 491 sock_put(sk);
491 mutex_lock(&ps->sk_lock);
492 ps->__sk = rcu_dereference_protected(ps->sk,
493 lockdep_is_held(&ps->sk_lock));
494 RCU_INIT_POINTER(ps->sk, NULL);
495 mutex_unlock(&ps->sk_lock);
496 call_rcu(&ps->rcu, pppol2tp_put_sk);
497
498 /* Rely on the sock_put() call at the end of the function for
499 * dropping the reference held by pppol2tp_sock_to_session().
500 * The last reference will be dropped by pppol2tp_put_sk().
501 */
502 } 492 }
493
503 release_sock(sk); 494 release_sock(sk);
504 495
505 /* This will delete the session context via 496 /* This will delete the session context via
@@ -796,6 +787,7 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
796 787
797out_no_ppp: 788out_no_ppp:
798 /* This is how we get the session context from the socket. */ 789 /* This is how we get the session context from the socket. */
790 sock_hold(sk);
799 sk->sk_user_data = session; 791 sk->sk_user_data = session;
800 rcu_assign_pointer(ps->sk, sk); 792 rcu_assign_pointer(ps->sk, sk);
801 mutex_unlock(&ps->sk_lock); 793 mutex_unlock(&ps->sk_lock);
diff --git a/net/mac80211/agg-rx.c b/net/mac80211/agg-rx.c
index a8b1616cec41..1f3188d03840 100644
--- a/net/mac80211/agg-rx.c
+++ b/net/mac80211/agg-rx.c
@@ -8,6 +8,7 @@
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net> 8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2007-2010, Intel Corporation 9 * Copyright 2007-2010, Intel Corporation
10 * Copyright(c) 2015-2017 Intel Deutschland GmbH 10 * Copyright(c) 2015-2017 Intel Deutschland GmbH
11 * Copyright (C) 2018 Intel Corporation
11 * 12 *
12 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as 14 * it under the terms of the GNU General Public License version 2 as
@@ -304,9 +305,6 @@ void ___ieee80211_start_rx_ba_session(struct sta_info *sta,
304 * driver so reject the timeout update. 305 * driver so reject the timeout update.
305 */ 306 */
306 status = WLAN_STATUS_REQUEST_DECLINED; 307 status = WLAN_STATUS_REQUEST_DECLINED;
307 ieee80211_send_addba_resp(sta->sdata, sta->sta.addr,
308 tid, dialog_token, status,
309 1, buf_size, timeout);
310 goto end; 308 goto end;
311 } 309 }
312 310
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 46028e12e216..f4195a0f0279 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -2892,7 +2892,7 @@ cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2892 } 2892 }
2893 if (beacon->probe_resp_len) { 2893 if (beacon->probe_resp_len) {
2894 new_beacon->probe_resp_len = beacon->probe_resp_len; 2894 new_beacon->probe_resp_len = beacon->probe_resp_len;
2895 beacon->probe_resp = pos; 2895 new_beacon->probe_resp = pos;
2896 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len); 2896 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2897 pos += beacon->probe_resp_len; 2897 pos += beacon->probe_resp_len;
2898 } 2898 }
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 1f466d12a6bc..94c7ee9df33b 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -212,6 +212,7 @@ static const char *hw_flag_names[] = {
212 FLAG(REPORTS_LOW_ACK), 212 FLAG(REPORTS_LOW_ACK),
213 FLAG(SUPPORTS_TX_FRAG), 213 FLAG(SUPPORTS_TX_FRAG),
214 FLAG(SUPPORTS_TDLS_BUFFER_STA), 214 FLAG(SUPPORTS_TDLS_BUFFER_STA),
215 FLAG(DOESNT_SUPPORT_QOS_NDP),
215#undef FLAG 216#undef FLAG
216}; 217};
217 218
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 26900025de2f..ae9c33cd8ada 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1467,7 +1467,7 @@ struct ieee802_11_elems {
1467 const struct ieee80211_timeout_interval_ie *timeout_int; 1467 const struct ieee80211_timeout_interval_ie *timeout_int;
1468 const u8 *opmode_notif; 1468 const u8 *opmode_notif;
1469 const struct ieee80211_sec_chan_offs_ie *sec_chan_offs; 1469 const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1470 const struct ieee80211_mesh_chansw_params_ie *mesh_chansw_params_ie; 1470 struct ieee80211_mesh_chansw_params_ie *mesh_chansw_params_ie;
1471 const struct ieee80211_bss_max_idle_period_ie *max_idle_period_ie; 1471 const struct ieee80211_bss_max_idle_period_ie *max_idle_period_ie;
1472 1472
1473 /* length of them, respectively */ 1473 /* length of them, respectively */
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 73ac607beb5d..6a381cbe1e33 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -1255,13 +1255,12 @@ int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
1255} 1255}
1256 1256
1257static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata, 1257static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
1258 struct ieee80211_mgmt *mgmt, size_t len) 1258 struct ieee80211_mgmt *mgmt, size_t len,
1259 struct ieee802_11_elems *elems)
1259{ 1260{
1260 struct ieee80211_mgmt *mgmt_fwd; 1261 struct ieee80211_mgmt *mgmt_fwd;
1261 struct sk_buff *skb; 1262 struct sk_buff *skb;
1262 struct ieee80211_local *local = sdata->local; 1263 struct ieee80211_local *local = sdata->local;
1263 u8 *pos = mgmt->u.action.u.chan_switch.variable;
1264 size_t offset_ttl;
1265 1264
1266 skb = dev_alloc_skb(local->tx_headroom + len); 1265 skb = dev_alloc_skb(local->tx_headroom + len);
1267 if (!skb) 1266 if (!skb)
@@ -1269,13 +1268,9 @@ static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
1269 skb_reserve(skb, local->tx_headroom); 1268 skb_reserve(skb, local->tx_headroom);
1270 mgmt_fwd = skb_put(skb, len); 1269 mgmt_fwd = skb_put(skb, len);
1271 1270
1272 /* offset_ttl is based on whether the secondary channel 1271 elems->mesh_chansw_params_ie->mesh_ttl--;
1273 * offset is available or not. Subtract 1 from the mesh TTL 1272 elems->mesh_chansw_params_ie->mesh_flags &=
1274 * and disable the initiator flag before forwarding. 1273 ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
1275 */
1276 offset_ttl = (len < 42) ? 7 : 10;
1277 *(pos + offset_ttl) -= 1;
1278 *(pos + offset_ttl + 1) &= ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
1279 1274
1280 memcpy(mgmt_fwd, mgmt, len); 1275 memcpy(mgmt_fwd, mgmt, len);
1281 eth_broadcast_addr(mgmt_fwd->da); 1276 eth_broadcast_addr(mgmt_fwd->da);
@@ -1323,7 +1318,7 @@ static void mesh_rx_csa_frame(struct ieee80211_sub_if_data *sdata,
1323 1318
1324 /* forward or re-broadcast the CSA frame */ 1319 /* forward or re-broadcast the CSA frame */
1325 if (fwd_csa) { 1320 if (fwd_csa) {
1326 if (mesh_fwd_csa_frame(sdata, mgmt, len) < 0) 1321 if (mesh_fwd_csa_frame(sdata, mgmt, len, &elems) < 0)
1327 mcsa_dbg(sdata, "Failed to forward the CSA frame"); 1322 mcsa_dbg(sdata, "Failed to forward the CSA frame");
1328 } 1323 }
1329} 1324}
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 39b660b9a908..5f303abac5ad 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -896,7 +896,8 @@ void ieee80211_send_nullfunc(struct ieee80211_local *local,
896 struct ieee80211_hdr_3addr *nullfunc; 896 struct ieee80211_hdr_3addr *nullfunc;
897 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 897 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
898 898
899 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, true); 899 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
900 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
900 if (!skb) 901 if (!skb)
901 return; 902 return;
902 903
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index fd580614085b..56fe16b07538 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -3921,7 +3921,7 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
3921 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS | 3921 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
3922 IEEE80211_FCTL_TODS)) != 3922 IEEE80211_FCTL_TODS)) !=
3923 fast_rx->expected_ds_bits) 3923 fast_rx->expected_ds_bits)
3924 goto drop; 3924 return false;
3925 3925
3926 /* assign the key to drop unencrypted frames (later) 3926 /* assign the key to drop unencrypted frames (later)
3927 * and strip the IV/MIC if necessary 3927 * and strip the IV/MIC if necessary
diff --git a/net/mac80211/spectmgmt.c b/net/mac80211/spectmgmt.c
index ee0181778a42..029334835747 100644
--- a/net/mac80211/spectmgmt.c
+++ b/net/mac80211/spectmgmt.c
@@ -8,6 +8,7 @@
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net> 8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2007-2008, Intel Corporation 9 * Copyright 2007-2008, Intel Corporation
10 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> 10 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
11 * Copyright (C) 2018 Intel Corporation
11 * 12 *
12 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as 14 * it under the terms of the GNU General Public License version 2 as
@@ -27,7 +28,7 @@ int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
27 u32 sta_flags, u8 *bssid, 28 u32 sta_flags, u8 *bssid,
28 struct ieee80211_csa_ie *csa_ie) 29 struct ieee80211_csa_ie *csa_ie)
29{ 30{
30 enum nl80211_band new_band; 31 enum nl80211_band new_band = current_band;
31 int new_freq; 32 int new_freq;
32 u8 new_chan_no; 33 u8 new_chan_no;
33 struct ieee80211_channel *new_chan; 34 struct ieee80211_channel *new_chan;
@@ -55,15 +56,13 @@ int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
55 elems->ext_chansw_ie->new_operating_class, 56 elems->ext_chansw_ie->new_operating_class,
56 &new_band)) { 57 &new_band)) {
57 sdata_info(sdata, 58 sdata_info(sdata,
58 "cannot understand ECSA IE operating class %d, disconnecting\n", 59 "cannot understand ECSA IE operating class, %d, ignoring\n",
59 elems->ext_chansw_ie->new_operating_class); 60 elems->ext_chansw_ie->new_operating_class);
60 return -EINVAL;
61 } 61 }
62 new_chan_no = elems->ext_chansw_ie->new_ch_num; 62 new_chan_no = elems->ext_chansw_ie->new_ch_num;
63 csa_ie->count = elems->ext_chansw_ie->count; 63 csa_ie->count = elems->ext_chansw_ie->count;
64 csa_ie->mode = elems->ext_chansw_ie->mode; 64 csa_ie->mode = elems->ext_chansw_ie->mode;
65 } else if (elems->ch_switch_ie) { 65 } else if (elems->ch_switch_ie) {
66 new_band = current_band;
67 new_chan_no = elems->ch_switch_ie->new_ch_num; 66 new_chan_no = elems->ch_switch_ie->new_ch_num;
68 csa_ie->count = elems->ch_switch_ie->count; 67 csa_ie->count = elems->ch_switch_ie->count;
69 csa_ie->mode = elems->ch_switch_ie->mode; 68 csa_ie->mode = elems->ch_switch_ie->mode;
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 0c5627f8a104..af0b608ee8ed 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -314,7 +314,7 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
314 314
315 if (ieee80211_hw_check(hw, USES_RSS)) { 315 if (ieee80211_hw_check(hw, USES_RSS)) {
316 sta->pcpu_rx_stats = 316 sta->pcpu_rx_stats =
317 alloc_percpu(struct ieee80211_sta_rx_stats); 317 alloc_percpu_gfp(struct ieee80211_sta_rx_stats, gfp);
318 if (!sta->pcpu_rx_stats) 318 if (!sta->pcpu_rx_stats)
319 goto free; 319 goto free;
320 } 320 }
@@ -433,6 +433,7 @@ free_txq:
433 if (sta->sta.txq[0]) 433 if (sta->sta.txq[0])
434 kfree(to_txq_info(sta->sta.txq[0])); 434 kfree(to_txq_info(sta->sta.txq[0]));
435free: 435free:
436 free_percpu(sta->pcpu_rx_stats);
436#ifdef CONFIG_MAC80211_MESH 437#ifdef CONFIG_MAC80211_MESH
437 kfree(sta->mesh); 438 kfree(sta->mesh);
438#endif 439#endif
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 25904af38839..69722504e3e1 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -3574,6 +3574,14 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb,
3574 if (!IS_ERR_OR_NULL(sta)) { 3574 if (!IS_ERR_OR_NULL(sta)) {
3575 struct ieee80211_fast_tx *fast_tx; 3575 struct ieee80211_fast_tx *fast_tx;
3576 3576
3577 /* We need a bit of data queued to build aggregates properly, so
3578 * instruct the TCP stack to allow more than a single ms of data
3579 * to be queued in the stack. The value is a bit-shift of 1
3580 * second, so 8 is ~4ms of queued data. Only affects local TCP
3581 * sockets.
3582 */
3583 sk_pacing_shift_update(skb->sk, 8);
3584
3577 fast_tx = rcu_dereference(sta->fast_tx); 3585 fast_tx = rcu_dereference(sta->fast_tx);
3578 3586
3579 if (fast_tx && 3587 if (fast_tx &&
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index e545a3c9365f..7a4de6d618b1 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -122,7 +122,7 @@ bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)
122 if (skb->len <= mtu) 122 if (skb->len <= mtu)
123 return false; 123 return false;
124 124
125 if (skb_is_gso(skb) && skb_gso_validate_mtu(skb, mtu)) 125 if (skb_is_gso(skb) && skb_gso_validate_network_len(skb, mtu))
126 return false; 126 return false;
127 127
128 return true; 128 return true;
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index 3e17d32b629d..58d5d05aec24 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -260,7 +260,7 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
260 buf_len = strlen(buf); 260 buf_len = strlen(buf);
261 261
262 ct = nf_ct_get(skb, &ctinfo); 262 ct = nf_ct_get(skb, &ctinfo);
263 if (ct && (ct->status & IPS_NAT_MASK)) { 263 if (ct) {
264 bool mangled; 264 bool mangled;
265 265
266 /* If mangling fails this function will return 0 266 /* If mangling fails this function will return 0
diff --git a/net/netfilter/nf_nat_proto_common.c b/net/netfilter/nf_nat_proto_common.c
index fbce552a796e..7d7466dbf663 100644
--- a/net/netfilter/nf_nat_proto_common.c
+++ b/net/netfilter/nf_nat_proto_common.c
@@ -41,7 +41,7 @@ void nf_nat_l4proto_unique_tuple(const struct nf_nat_l3proto *l3proto,
41 const struct nf_conn *ct, 41 const struct nf_conn *ct,
42 u16 *rover) 42 u16 *rover)
43{ 43{
44 unsigned int range_size, min, i; 44 unsigned int range_size, min, max, i;
45 __be16 *portptr; 45 __be16 *portptr;
46 u_int16_t off; 46 u_int16_t off;
47 47
@@ -71,7 +71,10 @@ void nf_nat_l4proto_unique_tuple(const struct nf_nat_l3proto *l3proto,
71 } 71 }
72 } else { 72 } else {
73 min = ntohs(range->min_proto.all); 73 min = ntohs(range->min_proto.all);
74 range_size = ntohs(range->max_proto.all) - min + 1; 74 max = ntohs(range->max_proto.all);
75 if (unlikely(max < min))
76 swap(max, min);
77 range_size = max - min + 1;
75 } 78 }
76 79
77 if (range->flags & NF_NAT_RANGE_PROTO_RANDOM) { 80 if (range->flags & NF_NAT_RANGE_PROTO_RANDOM) {
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 8b9fe30de0cd..c4acc7340eb1 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -5037,9 +5037,9 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
5037{ 5037{
5038 const struct nfgenmsg *nfmsg = nlmsg_data(nlh); 5038 const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
5039 const struct nf_flowtable_type *type; 5039 const struct nf_flowtable_type *type;
5040 struct nft_flowtable *flowtable, *ft;
5040 u8 genmask = nft_genmask_next(net); 5041 u8 genmask = nft_genmask_next(net);
5041 int family = nfmsg->nfgen_family; 5042 int family = nfmsg->nfgen_family;
5042 struct nft_flowtable *flowtable;
5043 struct nft_table *table; 5043 struct nft_table *table;
5044 struct nft_ctx ctx; 5044 struct nft_ctx ctx;
5045 int err, i, k; 5045 int err, i, k;
@@ -5099,6 +5099,22 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
5099 goto err3; 5099 goto err3;
5100 5100
5101 for (i = 0; i < flowtable->ops_len; i++) { 5101 for (i = 0; i < flowtable->ops_len; i++) {
5102 if (!flowtable->ops[i].dev)
5103 continue;
5104
5105 list_for_each_entry(ft, &table->flowtables, list) {
5106 for (k = 0; k < ft->ops_len; k++) {
5107 if (!ft->ops[k].dev)
5108 continue;
5109
5110 if (flowtable->ops[i].dev == ft->ops[k].dev &&
5111 flowtable->ops[i].pf == ft->ops[k].pf) {
5112 err = -EBUSY;
5113 goto err4;
5114 }
5115 }
5116 }
5117
5102 err = nf_register_net_hook(net, &flowtable->ops[i]); 5118 err = nf_register_net_hook(net, &flowtable->ops[i]);
5103 if (err < 0) 5119 if (err < 0)
5104 goto err4; 5120 goto err4;
@@ -5120,7 +5136,7 @@ err5:
5120 i = flowtable->ops_len; 5136 i = flowtable->ops_len;
5121err4: 5137err4:
5122 for (k = i - 1; k >= 0; k--) 5138 for (k = i - 1; k >= 0; k--)
5123 nf_unregister_net_hook(net, &flowtable->ops[i]); 5139 nf_unregister_net_hook(net, &flowtable->ops[k]);
5124 5140
5125 kfree(flowtable->ops); 5141 kfree(flowtable->ops);
5126err3: 5142err3:
@@ -5145,6 +5161,11 @@ static int nf_tables_delflowtable(struct net *net, struct sock *nlsk,
5145 struct nft_table *table; 5161 struct nft_table *table;
5146 struct nft_ctx ctx; 5162 struct nft_ctx ctx;
5147 5163
5164 if (!nla[NFTA_FLOWTABLE_TABLE] ||
5165 (!nla[NFTA_FLOWTABLE_NAME] &&
5166 !nla[NFTA_FLOWTABLE_HANDLE]))
5167 return -EINVAL;
5168
5148 table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], 5169 table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE],
5149 family, genmask); 5170 family, genmask);
5150 if (IS_ERR(table)) 5171 if (IS_ERR(table))
@@ -5402,6 +5423,7 @@ err:
5402static void nf_tables_flowtable_destroy(struct nft_flowtable *flowtable) 5423static void nf_tables_flowtable_destroy(struct nft_flowtable *flowtable)
5403{ 5424{
5404 cancel_delayed_work_sync(&flowtable->data.gc_work); 5425 cancel_delayed_work_sync(&flowtable->data.gc_work);
5426 kfree(flowtable->ops);
5405 kfree(flowtable->name); 5427 kfree(flowtable->name);
5406 flowtable->data.type->free(&flowtable->data); 5428 flowtable->data.type->free(&flowtable->data);
5407 rhashtable_destroy(&flowtable->data.rhashtable); 5429 rhashtable_destroy(&flowtable->data.rhashtable);
diff --git a/net/netfilter/nft_set_hash.c b/net/netfilter/nft_set_hash.c
index 3f1624ee056f..d40591fe1b2f 100644
--- a/net/netfilter/nft_set_hash.c
+++ b/net/netfilter/nft_set_hash.c
@@ -674,7 +674,7 @@ static const struct nft_set_ops *
674nft_hash_select_ops(const struct nft_ctx *ctx, const struct nft_set_desc *desc, 674nft_hash_select_ops(const struct nft_ctx *ctx, const struct nft_set_desc *desc,
675 u32 flags) 675 u32 flags)
676{ 676{
677 if (desc->size) { 677 if (desc->size && !(flags & NFT_SET_TIMEOUT)) {
678 switch (desc->klen) { 678 switch (desc->klen) {
679 case 4: 679 case 4:
680 return &nft_hash_fast_ops; 680 return &nft_hash_fast_ops;
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 2f685ee1f9c8..4aa01c90e9d1 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -423,6 +423,36 @@ textify_hooks(char *buf, size_t size, unsigned int mask, uint8_t nfproto)
423 return buf; 423 return buf;
424} 424}
425 425
426/**
427 * xt_check_proc_name - check that name is suitable for /proc file creation
428 *
429 * @name: file name candidate
430 * @size: length of buffer
431 *
432 * some x_tables modules wish to create a file in /proc.
433 * This function makes sure that the name is suitable for this
434 * purpose, it checks that name is NUL terminated and isn't a 'special'
435 * name, like "..".
436 *
437 * returns negative number on error or 0 if name is useable.
438 */
439int xt_check_proc_name(const char *name, unsigned int size)
440{
441 if (name[0] == '\0')
442 return -EINVAL;
443
444 if (strnlen(name, size) == size)
445 return -ENAMETOOLONG;
446
447 if (strcmp(name, ".") == 0 ||
448 strcmp(name, "..") == 0 ||
449 strchr(name, '/'))
450 return -EINVAL;
451
452 return 0;
453}
454EXPORT_SYMBOL(xt_check_proc_name);
455
426int xt_check_match(struct xt_mtchk_param *par, 456int xt_check_match(struct xt_mtchk_param *par,
427 unsigned int size, u_int8_t proto, bool inv_proto) 457 unsigned int size, u_int8_t proto, bool inv_proto)
428{ 458{
@@ -434,36 +464,35 @@ int xt_check_match(struct xt_mtchk_param *par,
434 * ebt_among is exempt from centralized matchsize checking 464 * ebt_among is exempt from centralized matchsize checking
435 * because it uses a dynamic-size data set. 465 * because it uses a dynamic-size data set.
436 */ 466 */
437 pr_err("%s_tables: %s.%u match: invalid size " 467 pr_err_ratelimited("%s_tables: %s.%u match: invalid size %u (kernel) != (user) %u\n",
438 "%u (kernel) != (user) %u\n", 468 xt_prefix[par->family], par->match->name,
439 xt_prefix[par->family], par->match->name, 469 par->match->revision,
440 par->match->revision, 470 XT_ALIGN(par->match->matchsize), size);
441 XT_ALIGN(par->match->matchsize), size);
442 return -EINVAL; 471 return -EINVAL;
443 } 472 }
444 if (par->match->table != NULL && 473 if (par->match->table != NULL &&
445 strcmp(par->match->table, par->table) != 0) { 474 strcmp(par->match->table, par->table) != 0) {
446 pr_err("%s_tables: %s match: only valid in %s table, not %s\n", 475 pr_info_ratelimited("%s_tables: %s match: only valid in %s table, not %s\n",
447 xt_prefix[par->family], par->match->name, 476 xt_prefix[par->family], par->match->name,
448 par->match->table, par->table); 477 par->match->table, par->table);
449 return -EINVAL; 478 return -EINVAL;
450 } 479 }
451 if (par->match->hooks && (par->hook_mask & ~par->match->hooks) != 0) { 480 if (par->match->hooks && (par->hook_mask & ~par->match->hooks) != 0) {
452 char used[64], allow[64]; 481 char used[64], allow[64];
453 482
454 pr_err("%s_tables: %s match: used from hooks %s, but only " 483 pr_info_ratelimited("%s_tables: %s match: used from hooks %s, but only valid from %s\n",
455 "valid from %s\n", 484 xt_prefix[par->family], par->match->name,
456 xt_prefix[par->family], par->match->name, 485 textify_hooks(used, sizeof(used),
457 textify_hooks(used, sizeof(used), par->hook_mask, 486 par->hook_mask, par->family),
458 par->family), 487 textify_hooks(allow, sizeof(allow),
459 textify_hooks(allow, sizeof(allow), par->match->hooks, 488 par->match->hooks,
460 par->family)); 489 par->family));
461 return -EINVAL; 490 return -EINVAL;
462 } 491 }
463 if (par->match->proto && (par->match->proto != proto || inv_proto)) { 492 if (par->match->proto && (par->match->proto != proto || inv_proto)) {
464 pr_err("%s_tables: %s match: only valid for protocol %u\n", 493 pr_info_ratelimited("%s_tables: %s match: only valid for protocol %u\n",
465 xt_prefix[par->family], par->match->name, 494 xt_prefix[par->family], par->match->name,
466 par->match->proto); 495 par->match->proto);
467 return -EINVAL; 496 return -EINVAL;
468 } 497 }
469 if (par->match->checkentry != NULL) { 498 if (par->match->checkentry != NULL) {
@@ -814,36 +843,35 @@ int xt_check_target(struct xt_tgchk_param *par,
814 int ret; 843 int ret;
815 844
816 if (XT_ALIGN(par->target->targetsize) != size) { 845 if (XT_ALIGN(par->target->targetsize) != size) {
817 pr_err("%s_tables: %s.%u target: invalid size " 846 pr_err_ratelimited("%s_tables: %s.%u target: invalid size %u (kernel) != (user) %u\n",
818 "%u (kernel) != (user) %u\n", 847 xt_prefix[par->family], par->target->name,
819 xt_prefix[par->family], par->target->name, 848 par->target->revision,
820 par->target->revision, 849 XT_ALIGN(par->target->targetsize), size);
821 XT_ALIGN(par->target->targetsize), size);
822 return -EINVAL; 850 return -EINVAL;
823 } 851 }
824 if (par->target->table != NULL && 852 if (par->target->table != NULL &&
825 strcmp(par->target->table, par->table) != 0) { 853 strcmp(par->target->table, par->table) != 0) {
826 pr_err("%s_tables: %s target: only valid in %s table, not %s\n", 854 pr_info_ratelimited("%s_tables: %s target: only valid in %s table, not %s\n",
827 xt_prefix[par->family], par->target->name, 855 xt_prefix[par->family], par->target->name,
828 par->target->table, par->table); 856 par->target->table, par->table);
829 return -EINVAL; 857 return -EINVAL;
830 } 858 }
831 if (par->target->hooks && (par->hook_mask & ~par->target->hooks) != 0) { 859 if (par->target->hooks && (par->hook_mask & ~par->target->hooks) != 0) {
832 char used[64], allow[64]; 860 char used[64], allow[64];
833 861
834 pr_err("%s_tables: %s target: used from hooks %s, but only " 862 pr_info_ratelimited("%s_tables: %s target: used from hooks %s, but only usable from %s\n",
835 "usable from %s\n", 863 xt_prefix[par->family], par->target->name,
836 xt_prefix[par->family], par->target->name, 864 textify_hooks(used, sizeof(used),
837 textify_hooks(used, sizeof(used), par->hook_mask, 865 par->hook_mask, par->family),
838 par->family), 866 textify_hooks(allow, sizeof(allow),
839 textify_hooks(allow, sizeof(allow), par->target->hooks, 867 par->target->hooks,
840 par->family)); 868 par->family));
841 return -EINVAL; 869 return -EINVAL;
842 } 870 }
843 if (par->target->proto && (par->target->proto != proto || inv_proto)) { 871 if (par->target->proto && (par->target->proto != proto || inv_proto)) {
844 pr_err("%s_tables: %s target: only valid for protocol %u\n", 872 pr_info_ratelimited("%s_tables: %s target: only valid for protocol %u\n",
845 xt_prefix[par->family], par->target->name, 873 xt_prefix[par->family], par->target->name,
846 par->target->proto); 874 par->target->proto);
847 return -EINVAL; 875 return -EINVAL;
848 } 876 }
849 if (par->target->checkentry != NULL) { 877 if (par->target->checkentry != NULL) {
@@ -1004,10 +1032,6 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
1004 if (sz < sizeof(*info)) 1032 if (sz < sizeof(*info))
1005 return NULL; 1033 return NULL;
1006 1034
1007 /* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */
1008 if ((size >> PAGE_SHIFT) + 2 > totalram_pages)
1009 return NULL;
1010
1011 /* __GFP_NORETRY is not fully supported by kvmalloc but it should 1035 /* __GFP_NORETRY is not fully supported by kvmalloc but it should
1012 * work reasonably well if sz is too large and bail out rather 1036 * work reasonably well if sz is too large and bail out rather
1013 * than shoot all processes down before realizing there is nothing 1037 * than shoot all processes down before realizing there is nothing
diff --git a/net/netfilter/xt_AUDIT.c b/net/netfilter/xt_AUDIT.c
index c502419d6306..f368ee6741db 100644
--- a/net/netfilter/xt_AUDIT.c
+++ b/net/netfilter/xt_AUDIT.c
@@ -120,8 +120,8 @@ static int audit_tg_check(const struct xt_tgchk_param *par)
120 const struct xt_audit_info *info = par->targinfo; 120 const struct xt_audit_info *info = par->targinfo;
121 121
122 if (info->type > XT_AUDIT_TYPE_MAX) { 122 if (info->type > XT_AUDIT_TYPE_MAX) {
123 pr_info("Audit type out of range (valid range: 0..%hhu)\n", 123 pr_info_ratelimited("Audit type out of range (valid range: 0..%hhu)\n",
124 XT_AUDIT_TYPE_MAX); 124 XT_AUDIT_TYPE_MAX);
125 return -ERANGE; 125 return -ERANGE;
126 } 126 }
127 127
diff --git a/net/netfilter/xt_CHECKSUM.c b/net/netfilter/xt_CHECKSUM.c
index 0f642ef8cd26..9f4151ec3e06 100644
--- a/net/netfilter/xt_CHECKSUM.c
+++ b/net/netfilter/xt_CHECKSUM.c
@@ -36,13 +36,13 @@ static int checksum_tg_check(const struct xt_tgchk_param *par)
36 const struct xt_CHECKSUM_info *einfo = par->targinfo; 36 const struct xt_CHECKSUM_info *einfo = par->targinfo;
37 37
38 if (einfo->operation & ~XT_CHECKSUM_OP_FILL) { 38 if (einfo->operation & ~XT_CHECKSUM_OP_FILL) {
39 pr_info("unsupported CHECKSUM operation %x\n", einfo->operation); 39 pr_info_ratelimited("unsupported CHECKSUM operation %x\n",
40 einfo->operation);
40 return -EINVAL; 41 return -EINVAL;
41 } 42 }
42 if (!einfo->operation) { 43 if (!einfo->operation)
43 pr_info("no CHECKSUM operation enabled\n");
44 return -EINVAL; 44 return -EINVAL;
45 } 45
46 return 0; 46 return 0;
47} 47}
48 48
diff --git a/net/netfilter/xt_CONNSECMARK.c b/net/netfilter/xt_CONNSECMARK.c
index da56c06a443c..f3f1caac949b 100644
--- a/net/netfilter/xt_CONNSECMARK.c
+++ b/net/netfilter/xt_CONNSECMARK.c
@@ -91,8 +91,8 @@ static int connsecmark_tg_check(const struct xt_tgchk_param *par)
91 91
92 if (strcmp(par->table, "mangle") != 0 && 92 if (strcmp(par->table, "mangle") != 0 &&
93 strcmp(par->table, "security") != 0) { 93 strcmp(par->table, "security") != 0) {
94 pr_info("target only valid in the \'mangle\' " 94 pr_info_ratelimited("only valid in \'mangle\' or \'security\' table, not \'%s\'\n",
95 "or \'security\' tables, not \'%s\'.\n", par->table); 95 par->table);
96 return -EINVAL; 96 return -EINVAL;
97 } 97 }
98 98
@@ -102,14 +102,14 @@ static int connsecmark_tg_check(const struct xt_tgchk_param *par)
102 break; 102 break;
103 103
104 default: 104 default:
105 pr_info("invalid mode: %hu\n", info->mode); 105 pr_info_ratelimited("invalid mode: %hu\n", info->mode);
106 return -EINVAL; 106 return -EINVAL;
107 } 107 }
108 108
109 ret = nf_ct_netns_get(par->net, par->family); 109 ret = nf_ct_netns_get(par->net, par->family);
110 if (ret < 0) 110 if (ret < 0)
111 pr_info("cannot load conntrack support for proto=%u\n", 111 pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
112 par->family); 112 par->family);
113 return ret; 113 return ret;
114} 114}
115 115
diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c
index 5a152e2acfd5..8790190c6feb 100644
--- a/net/netfilter/xt_CT.c
+++ b/net/netfilter/xt_CT.c
@@ -82,15 +82,14 @@ xt_ct_set_helper(struct nf_conn *ct, const char *helper_name,
82 82
83 proto = xt_ct_find_proto(par); 83 proto = xt_ct_find_proto(par);
84 if (!proto) { 84 if (!proto) {
85 pr_info("You must specify a L4 protocol, and not use " 85 pr_info_ratelimited("You must specify a L4 protocol and not use inversions on it\n");
86 "inversions on it.\n");
87 return -ENOENT; 86 return -ENOENT;
88 } 87 }
89 88
90 helper = nf_conntrack_helper_try_module_get(helper_name, par->family, 89 helper = nf_conntrack_helper_try_module_get(helper_name, par->family,
91 proto); 90 proto);
92 if (helper == NULL) { 91 if (helper == NULL) {
93 pr_info("No such helper \"%s\"\n", helper_name); 92 pr_info_ratelimited("No such helper \"%s\"\n", helper_name);
94 return -ENOENT; 93 return -ENOENT;
95 } 94 }
96 95
@@ -124,6 +123,7 @@ xt_ct_set_timeout(struct nf_conn *ct, const struct xt_tgchk_param *par,
124 const struct nf_conntrack_l4proto *l4proto; 123 const struct nf_conntrack_l4proto *l4proto;
125 struct ctnl_timeout *timeout; 124 struct ctnl_timeout *timeout;
126 struct nf_conn_timeout *timeout_ext; 125 struct nf_conn_timeout *timeout_ext;
126 const char *errmsg = NULL;
127 int ret = 0; 127 int ret = 0;
128 u8 proto; 128 u8 proto;
129 129
@@ -131,29 +131,29 @@ xt_ct_set_timeout(struct nf_conn *ct, const struct xt_tgchk_param *par,
131 timeout_find_get = rcu_dereference(nf_ct_timeout_find_get_hook); 131 timeout_find_get = rcu_dereference(nf_ct_timeout_find_get_hook);
132 if (timeout_find_get == NULL) { 132 if (timeout_find_get == NULL) {
133 ret = -ENOENT; 133 ret = -ENOENT;
134 pr_info("Timeout policy base is empty\n"); 134 errmsg = "Timeout policy base is empty";
135 goto out; 135 goto out;
136 } 136 }
137 137
138 proto = xt_ct_find_proto(par); 138 proto = xt_ct_find_proto(par);
139 if (!proto) { 139 if (!proto) {
140 ret = -EINVAL; 140 ret = -EINVAL;
141 pr_info("You must specify a L4 protocol, and not use " 141 errmsg = "You must specify a L4 protocol and not use inversions on it";
142 "inversions on it.\n");
143 goto out; 142 goto out;
144 } 143 }
145 144
146 timeout = timeout_find_get(par->net, timeout_name); 145 timeout = timeout_find_get(par->net, timeout_name);
147 if (timeout == NULL) { 146 if (timeout == NULL) {
148 ret = -ENOENT; 147 ret = -ENOENT;
149 pr_info("No such timeout policy \"%s\"\n", timeout_name); 148 pr_info_ratelimited("No such timeout policy \"%s\"\n",
149 timeout_name);
150 goto out; 150 goto out;
151 } 151 }
152 152
153 if (timeout->l3num != par->family) { 153 if (timeout->l3num != par->family) {
154 ret = -EINVAL; 154 ret = -EINVAL;
155 pr_info("Timeout policy `%s' can only be used by L3 protocol " 155 pr_info_ratelimited("Timeout policy `%s' can only be used by L%d protocol number %d\n",
156 "number %d\n", timeout_name, timeout->l3num); 156 timeout_name, 3, timeout->l3num);
157 goto err_put_timeout; 157 goto err_put_timeout;
158 } 158 }
159 /* Make sure the timeout policy matches any existing protocol tracker, 159 /* Make sure the timeout policy matches any existing protocol tracker,
@@ -162,9 +162,8 @@ xt_ct_set_timeout(struct nf_conn *ct, const struct xt_tgchk_param *par,
162 l4proto = __nf_ct_l4proto_find(par->family, proto); 162 l4proto = __nf_ct_l4proto_find(par->family, proto);
163 if (timeout->l4proto->l4proto != l4proto->l4proto) { 163 if (timeout->l4proto->l4proto != l4proto->l4proto) {
164 ret = -EINVAL; 164 ret = -EINVAL;
165 pr_info("Timeout policy `%s' can only be used by L4 protocol " 165 pr_info_ratelimited("Timeout policy `%s' can only be used by L%d protocol number %d\n",
166 "number %d\n", 166 timeout_name, 4, timeout->l4proto->l4proto);
167 timeout_name, timeout->l4proto->l4proto);
168 goto err_put_timeout; 167 goto err_put_timeout;
169 } 168 }
170 timeout_ext = nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC); 169 timeout_ext = nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC);
@@ -180,6 +179,8 @@ err_put_timeout:
180 __xt_ct_tg_timeout_put(timeout); 179 __xt_ct_tg_timeout_put(timeout);
181out: 180out:
182 rcu_read_unlock(); 181 rcu_read_unlock();
182 if (errmsg)
183 pr_info_ratelimited("%s\n", errmsg);
183 return ret; 184 return ret;
184#else 185#else
185 return -EOPNOTSUPP; 186 return -EOPNOTSUPP;
diff --git a/net/netfilter/xt_DSCP.c b/net/netfilter/xt_DSCP.c
index 3f83d38c4e5b..098ed851b7a7 100644
--- a/net/netfilter/xt_DSCP.c
+++ b/net/netfilter/xt_DSCP.c
@@ -66,10 +66,8 @@ static int dscp_tg_check(const struct xt_tgchk_param *par)
66{ 66{
67 const struct xt_DSCP_info *info = par->targinfo; 67 const struct xt_DSCP_info *info = par->targinfo;
68 68
69 if (info->dscp > XT_DSCP_MAX) { 69 if (info->dscp > XT_DSCP_MAX)
70 pr_info("dscp %x out of range\n", info->dscp);
71 return -EDOM; 70 return -EDOM;
72 }
73 return 0; 71 return 0;
74} 72}
75 73
diff --git a/net/netfilter/xt_HL.c b/net/netfilter/xt_HL.c
index 1535e87ed9bd..4653b071bed4 100644
--- a/net/netfilter/xt_HL.c
+++ b/net/netfilter/xt_HL.c
@@ -105,10 +105,8 @@ static int ttl_tg_check(const struct xt_tgchk_param *par)
105{ 105{
106 const struct ipt_TTL_info *info = par->targinfo; 106 const struct ipt_TTL_info *info = par->targinfo;
107 107
108 if (info->mode > IPT_TTL_MAXMODE) { 108 if (info->mode > IPT_TTL_MAXMODE)
109 pr_info("TTL: invalid or unknown mode %u\n", info->mode);
110 return -EINVAL; 109 return -EINVAL;
111 }
112 if (info->mode != IPT_TTL_SET && info->ttl == 0) 110 if (info->mode != IPT_TTL_SET && info->ttl == 0)
113 return -EINVAL; 111 return -EINVAL;
114 return 0; 112 return 0;
@@ -118,15 +116,10 @@ static int hl_tg6_check(const struct xt_tgchk_param *par)
118{ 116{
119 const struct ip6t_HL_info *info = par->targinfo; 117 const struct ip6t_HL_info *info = par->targinfo;
120 118
121 if (info->mode > IP6T_HL_MAXMODE) { 119 if (info->mode > IP6T_HL_MAXMODE)
122 pr_info("invalid or unknown mode %u\n", info->mode);
123 return -EINVAL; 120 return -EINVAL;
124 } 121 if (info->mode != IP6T_HL_SET && info->hop_limit == 0)
125 if (info->mode != IP6T_HL_SET && info->hop_limit == 0) {
126 pr_info("increment/decrement does not "
127 "make sense with value 0\n");
128 return -EINVAL; 122 return -EINVAL;
129 }
130 return 0; 123 return 0;
131} 124}
132 125
diff --git a/net/netfilter/xt_HMARK.c b/net/netfilter/xt_HMARK.c
index 60e6dbe12460..9c75f419cd80 100644
--- a/net/netfilter/xt_HMARK.c
+++ b/net/netfilter/xt_HMARK.c
@@ -9,6 +9,8 @@
9 * the Free Software Foundation. 9 * the Free Software Foundation.
10 */ 10 */
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
12#include <linux/module.h> 14#include <linux/module.h>
13#include <linux/skbuff.h> 15#include <linux/skbuff.h>
14#include <linux/icmp.h> 16#include <linux/icmp.h>
@@ -312,29 +314,30 @@ hmark_tg_v4(struct sk_buff *skb, const struct xt_action_param *par)
312static int hmark_tg_check(const struct xt_tgchk_param *par) 314static int hmark_tg_check(const struct xt_tgchk_param *par)
313{ 315{
314 const struct xt_hmark_info *info = par->targinfo; 316 const struct xt_hmark_info *info = par->targinfo;
317 const char *errmsg = "proto mask must be zero with L3 mode";
315 318
316 if (!info->hmodulus) { 319 if (!info->hmodulus)
317 pr_info("xt_HMARK: hash modulus can't be zero\n");
318 return -EINVAL; 320 return -EINVAL;
319 } 321
320 if (info->proto_mask && 322 if (info->proto_mask &&
321 (info->flags & XT_HMARK_FLAG(XT_HMARK_METHOD_L3))) { 323 (info->flags & XT_HMARK_FLAG(XT_HMARK_METHOD_L3)))
322 pr_info("xt_HMARK: proto mask must be zero with L3 mode\n"); 324 goto err;
323 return -EINVAL; 325
324 }
325 if (info->flags & XT_HMARK_FLAG(XT_HMARK_SPI_MASK) && 326 if (info->flags & XT_HMARK_FLAG(XT_HMARK_SPI_MASK) &&
326 (info->flags & (XT_HMARK_FLAG(XT_HMARK_SPORT_MASK) | 327 (info->flags & (XT_HMARK_FLAG(XT_HMARK_SPORT_MASK) |
327 XT_HMARK_FLAG(XT_HMARK_DPORT_MASK)))) { 328 XT_HMARK_FLAG(XT_HMARK_DPORT_MASK))))
328 pr_info("xt_HMARK: spi-mask and port-mask can't be combined\n");
329 return -EINVAL; 329 return -EINVAL;
330 } 330
331 if (info->flags & XT_HMARK_FLAG(XT_HMARK_SPI) && 331 if (info->flags & XT_HMARK_FLAG(XT_HMARK_SPI) &&
332 (info->flags & (XT_HMARK_FLAG(XT_HMARK_SPORT) | 332 (info->flags & (XT_HMARK_FLAG(XT_HMARK_SPORT) |
333 XT_HMARK_FLAG(XT_HMARK_DPORT)))) { 333 XT_HMARK_FLAG(XT_HMARK_DPORT)))) {
334 pr_info("xt_HMARK: spi-set and port-set can't be combined\n"); 334 errmsg = "spi-set and port-set can't be combined";
335 return -EINVAL; 335 goto err;
336 } 336 }
337 return 0; 337 return 0;
338err:
339 pr_info_ratelimited("%s\n", errmsg);
340 return -EINVAL;
338} 341}
339 342
340static struct xt_target hmark_tg_reg[] __read_mostly = { 343static struct xt_target hmark_tg_reg[] __read_mostly = {
diff --git a/net/netfilter/xt_IDLETIMER.c b/net/netfilter/xt_IDLETIMER.c
index 6c2482b709b1..1ac6600bfafd 100644
--- a/net/netfilter/xt_IDLETIMER.c
+++ b/net/netfilter/xt_IDLETIMER.c
@@ -146,11 +146,11 @@ static int idletimer_tg_create(struct idletimer_tg_info *info)
146 timer_setup(&info->timer->timer, idletimer_tg_expired, 0); 146 timer_setup(&info->timer->timer, idletimer_tg_expired, 0);
147 info->timer->refcnt = 1; 147 info->timer->refcnt = 1;
148 148
149 INIT_WORK(&info->timer->work, idletimer_tg_work);
150
149 mod_timer(&info->timer->timer, 151 mod_timer(&info->timer->timer,
150 msecs_to_jiffies(info->timeout * 1000) + jiffies); 152 msecs_to_jiffies(info->timeout * 1000) + jiffies);
151 153
152 INIT_WORK(&info->timer->work, idletimer_tg_work);
153
154 return 0; 154 return 0;
155 155
156out_free_attr: 156out_free_attr:
@@ -191,7 +191,10 @@ static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
191 pr_debug("timeout value is zero\n"); 191 pr_debug("timeout value is zero\n");
192 return -EINVAL; 192 return -EINVAL;
193 } 193 }
194 194 if (info->timeout >= INT_MAX / 1000) {
195 pr_debug("timeout value is too big\n");
196 return -EINVAL;
197 }
195 if (info->label[0] == '\0' || 198 if (info->label[0] == '\0' ||
196 strnlen(info->label, 199 strnlen(info->label,
197 MAX_IDLETIMER_LABEL_SIZE) == MAX_IDLETIMER_LABEL_SIZE) { 200 MAX_IDLETIMER_LABEL_SIZE) == MAX_IDLETIMER_LABEL_SIZE) {
diff --git a/net/netfilter/xt_LED.c b/net/netfilter/xt_LED.c
index 1dcad893df78..19846445504d 100644
--- a/net/netfilter/xt_LED.c
+++ b/net/netfilter/xt_LED.c
@@ -111,10 +111,8 @@ static int led_tg_check(const struct xt_tgchk_param *par)
111 struct xt_led_info_internal *ledinternal; 111 struct xt_led_info_internal *ledinternal;
112 int err; 112 int err;
113 113
114 if (ledinfo->id[0] == '\0') { 114 if (ledinfo->id[0] == '\0')
115 pr_info("No 'id' parameter given.\n");
116 return -EINVAL; 115 return -EINVAL;
117 }
118 116
119 mutex_lock(&xt_led_mutex); 117 mutex_lock(&xt_led_mutex);
120 118
@@ -138,13 +136,14 @@ static int led_tg_check(const struct xt_tgchk_param *par)
138 136
139 err = led_trigger_register(&ledinternal->netfilter_led_trigger); 137 err = led_trigger_register(&ledinternal->netfilter_led_trigger);
140 if (err) { 138 if (err) {
141 pr_err("Trigger name is already in use.\n"); 139 pr_info_ratelimited("Trigger name is already in use.\n");
142 goto exit_alloc; 140 goto exit_alloc;
143 } 141 }
144 142
145 /* See if we need to set up a timer */ 143 /* Since the letinternal timer can be shared between multiple targets,
146 if (ledinfo->delay > 0) 144 * always set it up, even if the current target does not need it
147 timer_setup(&ledinternal->timer, led_timeout_callback, 0); 145 */
146 timer_setup(&ledinternal->timer, led_timeout_callback, 0);
148 147
149 list_add_tail(&ledinternal->list, &xt_led_triggers); 148 list_add_tail(&ledinternal->list, &xt_led_triggers);
150 149
@@ -181,8 +180,7 @@ static void led_tg_destroy(const struct xt_tgdtor_param *par)
181 180
182 list_del(&ledinternal->list); 181 list_del(&ledinternal->list);
183 182
184 if (ledinfo->delay > 0) 183 del_timer_sync(&ledinternal->timer);
185 del_timer_sync(&ledinternal->timer);
186 184
187 led_trigger_unregister(&ledinternal->netfilter_led_trigger); 185 led_trigger_unregister(&ledinternal->netfilter_led_trigger);
188 186
diff --git a/net/netfilter/xt_NFQUEUE.c b/net/netfilter/xt_NFQUEUE.c
index a360b99a958a..a9aca80a32ae 100644
--- a/net/netfilter/xt_NFQUEUE.c
+++ b/net/netfilter/xt_NFQUEUE.c
@@ -8,6 +8,8 @@
8 * 8 *
9 */ 9 */
10 10
11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
11#include <linux/module.h> 13#include <linux/module.h>
12#include <linux/skbuff.h> 14#include <linux/skbuff.h>
13 15
@@ -67,13 +69,13 @@ static int nfqueue_tg_check(const struct xt_tgchk_param *par)
67 init_hashrandom(&jhash_initval); 69 init_hashrandom(&jhash_initval);
68 70
69 if (info->queues_total == 0) { 71 if (info->queues_total == 0) {
70 pr_err("NFQUEUE: number of total queues is 0\n"); 72 pr_info_ratelimited("number of total queues is 0\n");
71 return -EINVAL; 73 return -EINVAL;
72 } 74 }
73 maxid = info->queues_total - 1 + info->queuenum; 75 maxid = info->queues_total - 1 + info->queuenum;
74 if (maxid > 0xffff) { 76 if (maxid > 0xffff) {
75 pr_err("NFQUEUE: number of queues (%u) out of range (got %u)\n", 77 pr_info_ratelimited("number of queues (%u) out of range (got %u)\n",
76 info->queues_total, maxid); 78 info->queues_total, maxid);
77 return -ERANGE; 79 return -ERANGE;
78 } 80 }
79 if (par->target->revision == 2 && info->flags > 1) 81 if (par->target->revision == 2 && info->flags > 1)
diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c
index 9faf5e050b79..4ad5fe27e08b 100644
--- a/net/netfilter/xt_SECMARK.c
+++ b/net/netfilter/xt_SECMARK.c
@@ -60,18 +60,20 @@ static int checkentry_lsm(struct xt_secmark_target_info *info)
60 &info->secid); 60 &info->secid);
61 if (err) { 61 if (err) {
62 if (err == -EINVAL) 62 if (err == -EINVAL)
63 pr_info("invalid security context \'%s\'\n", info->secctx); 63 pr_info_ratelimited("invalid security context \'%s\'\n",
64 info->secctx);
64 return err; 65 return err;
65 } 66 }
66 67
67 if (!info->secid) { 68 if (!info->secid) {
68 pr_info("unable to map security context \'%s\'\n", info->secctx); 69 pr_info_ratelimited("unable to map security context \'%s\'\n",
70 info->secctx);
69 return -ENOENT; 71 return -ENOENT;
70 } 72 }
71 73
72 err = security_secmark_relabel_packet(info->secid); 74 err = security_secmark_relabel_packet(info->secid);
73 if (err) { 75 if (err) {
74 pr_info("unable to obtain relabeling permission\n"); 76 pr_info_ratelimited("unable to obtain relabeling permission\n");
75 return err; 77 return err;
76 } 78 }
77 79
@@ -86,14 +88,14 @@ static int secmark_tg_check(const struct xt_tgchk_param *par)
86 88
87 if (strcmp(par->table, "mangle") != 0 && 89 if (strcmp(par->table, "mangle") != 0 &&
88 strcmp(par->table, "security") != 0) { 90 strcmp(par->table, "security") != 0) {
89 pr_info("target only valid in the \'mangle\' " 91 pr_info_ratelimited("only valid in \'mangle\' or \'security\' table, not \'%s\'\n",
90 "or \'security\' tables, not \'%s\'.\n", par->table); 92 par->table);
91 return -EINVAL; 93 return -EINVAL;
92 } 94 }
93 95
94 if (mode && mode != info->mode) { 96 if (mode && mode != info->mode) {
95 pr_info("mode already set to %hu cannot mix with " 97 pr_info_ratelimited("mode already set to %hu cannot mix with rules for mode %hu\n",
96 "rules for mode %hu\n", mode, info->mode); 98 mode, info->mode);
97 return -EINVAL; 99 return -EINVAL;
98 } 100 }
99 101
@@ -101,7 +103,7 @@ static int secmark_tg_check(const struct xt_tgchk_param *par)
101 case SECMARK_MODE_SEL: 103 case SECMARK_MODE_SEL:
102 break; 104 break;
103 default: 105 default:
104 pr_info("invalid mode: %hu\n", info->mode); 106 pr_info_ratelimited("invalid mode: %hu\n", info->mode);
105 return -EINVAL; 107 return -EINVAL;
106 } 108 }
107 109
diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
index 99bb8e410f22..98efb202f8b4 100644
--- a/net/netfilter/xt_TCPMSS.c
+++ b/net/netfilter/xt_TCPMSS.c
@@ -273,8 +273,7 @@ static int tcpmss_tg4_check(const struct xt_tgchk_param *par)
273 (par->hook_mask & ~((1 << NF_INET_FORWARD) | 273 (par->hook_mask & ~((1 << NF_INET_FORWARD) |
274 (1 << NF_INET_LOCAL_OUT) | 274 (1 << NF_INET_LOCAL_OUT) |
275 (1 << NF_INET_POST_ROUTING))) != 0) { 275 (1 << NF_INET_POST_ROUTING))) != 0) {
276 pr_info("path-MTU clamping only supported in " 276 pr_info_ratelimited("path-MTU clamping only supported in FORWARD, OUTPUT and POSTROUTING hooks\n");
277 "FORWARD, OUTPUT and POSTROUTING hooks\n");
278 return -EINVAL; 277 return -EINVAL;
279 } 278 }
280 if (par->nft_compat) 279 if (par->nft_compat)
@@ -283,7 +282,7 @@ static int tcpmss_tg4_check(const struct xt_tgchk_param *par)
283 xt_ematch_foreach(ematch, e) 282 xt_ematch_foreach(ematch, e)
284 if (find_syn_match(ematch)) 283 if (find_syn_match(ematch))
285 return 0; 284 return 0;
286 pr_info("Only works on TCP SYN packets\n"); 285 pr_info_ratelimited("Only works on TCP SYN packets\n");
287 return -EINVAL; 286 return -EINVAL;
288} 287}
289 288
@@ -298,8 +297,7 @@ static int tcpmss_tg6_check(const struct xt_tgchk_param *par)
298 (par->hook_mask & ~((1 << NF_INET_FORWARD) | 297 (par->hook_mask & ~((1 << NF_INET_FORWARD) |
299 (1 << NF_INET_LOCAL_OUT) | 298 (1 << NF_INET_LOCAL_OUT) |
300 (1 << NF_INET_POST_ROUTING))) != 0) { 299 (1 << NF_INET_POST_ROUTING))) != 0) {
301 pr_info("path-MTU clamping only supported in " 300 pr_info_ratelimited("path-MTU clamping only supported in FORWARD, OUTPUT and POSTROUTING hooks\n");
302 "FORWARD, OUTPUT and POSTROUTING hooks\n");
303 return -EINVAL; 301 return -EINVAL;
304 } 302 }
305 if (par->nft_compat) 303 if (par->nft_compat)
@@ -308,7 +306,7 @@ static int tcpmss_tg6_check(const struct xt_tgchk_param *par)
308 xt_ematch_foreach(ematch, e) 306 xt_ematch_foreach(ematch, e)
309 if (find_syn_match(ematch)) 307 if (find_syn_match(ematch))
310 return 0; 308 return 0;
311 pr_info("Only works on TCP SYN packets\n"); 309 pr_info_ratelimited("Only works on TCP SYN packets\n");
312 return -EINVAL; 310 return -EINVAL;
313} 311}
314#endif 312#endif
diff --git a/net/netfilter/xt_TPROXY.c b/net/netfilter/xt_TPROXY.c
index 17d7705e3bd4..8c89323c06af 100644
--- a/net/netfilter/xt_TPROXY.c
+++ b/net/netfilter/xt_TPROXY.c
@@ -540,8 +540,7 @@ static int tproxy_tg6_check(const struct xt_tgchk_param *par)
540 !(i->invflags & IP6T_INV_PROTO)) 540 !(i->invflags & IP6T_INV_PROTO))
541 return 0; 541 return 0;
542 542
543 pr_info("Can be used only in combination with " 543 pr_info_ratelimited("Can be used only with -p tcp or -p udp\n");
544 "either -p tcp or -p udp\n");
545 return -EINVAL; 544 return -EINVAL;
546} 545}
547#endif 546#endif
@@ -559,8 +558,7 @@ static int tproxy_tg4_check(const struct xt_tgchk_param *par)
559 && !(i->invflags & IPT_INV_PROTO)) 558 && !(i->invflags & IPT_INV_PROTO))
560 return 0; 559 return 0;
561 560
562 pr_info("Can be used only in combination with " 561 pr_info_ratelimited("Can be used only with -p tcp or -p udp\n");
563 "either -p tcp or -p udp\n");
564 return -EINVAL; 562 return -EINVAL;
565} 563}
566 564
diff --git a/net/netfilter/xt_addrtype.c b/net/netfilter/xt_addrtype.c
index 911a7c0da504..89e281b3bfc2 100644
--- a/net/netfilter/xt_addrtype.c
+++ b/net/netfilter/xt_addrtype.c
@@ -164,48 +164,47 @@ addrtype_mt_v1(const struct sk_buff *skb, struct xt_action_param *par)
164 164
165static int addrtype_mt_checkentry_v1(const struct xt_mtchk_param *par) 165static int addrtype_mt_checkentry_v1(const struct xt_mtchk_param *par)
166{ 166{
167 const char *errmsg = "both incoming and outgoing interface limitation cannot be selected";
167 struct xt_addrtype_info_v1 *info = par->matchinfo; 168 struct xt_addrtype_info_v1 *info = par->matchinfo;
168 169
169 if (info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN && 170 if (info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN &&
170 info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT) { 171 info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT)
171 pr_info("both incoming and outgoing " 172 goto err;
172 "interface limitation cannot be selected\n");
173 return -EINVAL;
174 }
175 173
176 if (par->hook_mask & ((1 << NF_INET_PRE_ROUTING) | 174 if (par->hook_mask & ((1 << NF_INET_PRE_ROUTING) |
177 (1 << NF_INET_LOCAL_IN)) && 175 (1 << NF_INET_LOCAL_IN)) &&
178 info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT) { 176 info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT) {
179 pr_info("output interface limitation " 177 errmsg = "output interface limitation not valid in PREROUTING and INPUT";
180 "not valid in PREROUTING and INPUT\n"); 178 goto err;
181 return -EINVAL;
182 } 179 }
183 180
184 if (par->hook_mask & ((1 << NF_INET_POST_ROUTING) | 181 if (par->hook_mask & ((1 << NF_INET_POST_ROUTING) |
185 (1 << NF_INET_LOCAL_OUT)) && 182 (1 << NF_INET_LOCAL_OUT)) &&
186 info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN) { 183 info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN) {
187 pr_info("input interface limitation " 184 errmsg = "input interface limitation not valid in POSTROUTING and OUTPUT";
188 "not valid in POSTROUTING and OUTPUT\n"); 185 goto err;
189 return -EINVAL;
190 } 186 }
191 187
192#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES) 188#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
193 if (par->family == NFPROTO_IPV6) { 189 if (par->family == NFPROTO_IPV6) {
194 if ((info->source | info->dest) & XT_ADDRTYPE_BLACKHOLE) { 190 if ((info->source | info->dest) & XT_ADDRTYPE_BLACKHOLE) {
195 pr_err("ipv6 BLACKHOLE matching not supported\n"); 191 errmsg = "ipv6 BLACKHOLE matching not supported";
196 return -EINVAL; 192 goto err;
197 } 193 }
198 if ((info->source | info->dest) >= XT_ADDRTYPE_PROHIBIT) { 194 if ((info->source | info->dest) >= XT_ADDRTYPE_PROHIBIT) {
199 pr_err("ipv6 PROHIBIT (THROW, NAT ..) matching not supported\n"); 195 errmsg = "ipv6 PROHIBIT (THROW, NAT ..) matching not supported";
200 return -EINVAL; 196 goto err;
201 } 197 }
202 if ((info->source | info->dest) & XT_ADDRTYPE_BROADCAST) { 198 if ((info->source | info->dest) & XT_ADDRTYPE_BROADCAST) {
203 pr_err("ipv6 does not support BROADCAST matching\n"); 199 errmsg = "ipv6 does not support BROADCAST matching";
204 return -EINVAL; 200 goto err;
205 } 201 }
206 } 202 }
207#endif 203#endif
208 return 0; 204 return 0;
205err:
206 pr_info_ratelimited("%s\n", errmsg);
207 return -EINVAL;
209} 208}
210 209
211static struct xt_match addrtype_mt_reg[] __read_mostly = { 210static struct xt_match addrtype_mt_reg[] __read_mostly = {
diff --git a/net/netfilter/xt_bpf.c b/net/netfilter/xt_bpf.c
index 06b090d8e901..a2cf8a6236d6 100644
--- a/net/netfilter/xt_bpf.c
+++ b/net/netfilter/xt_bpf.c
@@ -7,6 +7,8 @@
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 */ 8 */
9 9
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
10#include <linux/module.h> 12#include <linux/module.h>
11#include <linux/syscalls.h> 13#include <linux/syscalls.h>
12#include <linux/skbuff.h> 14#include <linux/skbuff.h>
@@ -34,7 +36,7 @@ static int __bpf_mt_check_bytecode(struct sock_filter *insns, __u16 len,
34 program.filter = insns; 36 program.filter = insns;
35 37
36 if (bpf_prog_create(ret, &program)) { 38 if (bpf_prog_create(ret, &program)) {
37 pr_info("bpf: check failed: parse error\n"); 39 pr_info_ratelimited("check failed: parse error\n");
38 return -EINVAL; 40 return -EINVAL;
39 } 41 }
40 42
diff --git a/net/netfilter/xt_cgroup.c b/net/netfilter/xt_cgroup.c
index 891f4e7e8ea7..7df2dece57d3 100644
--- a/net/netfilter/xt_cgroup.c
+++ b/net/netfilter/xt_cgroup.c
@@ -12,6 +12,8 @@
12 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
13 */ 13 */
14 14
15#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16
15#include <linux/skbuff.h> 17#include <linux/skbuff.h>
16#include <linux/module.h> 18#include <linux/module.h>
17#include <linux/netfilter/x_tables.h> 19#include <linux/netfilter/x_tables.h>
@@ -48,7 +50,7 @@ static int cgroup_mt_check_v1(const struct xt_mtchk_param *par)
48 } 50 }
49 51
50 if (info->has_path && info->has_classid) { 52 if (info->has_path && info->has_classid) {
51 pr_info("xt_cgroup: both path and classid specified\n"); 53 pr_info_ratelimited("path and classid specified\n");
52 return -EINVAL; 54 return -EINVAL;
53 } 55 }
54 56
@@ -56,8 +58,8 @@ static int cgroup_mt_check_v1(const struct xt_mtchk_param *par)
56 if (info->has_path) { 58 if (info->has_path) {
57 cgrp = cgroup_get_from_path(info->path); 59 cgrp = cgroup_get_from_path(info->path);
58 if (IS_ERR(cgrp)) { 60 if (IS_ERR(cgrp)) {
59 pr_info("xt_cgroup: invalid path, errno=%ld\n", 61 pr_info_ratelimited("invalid path, errno=%ld\n",
60 PTR_ERR(cgrp)); 62 PTR_ERR(cgrp));
61 return -EINVAL; 63 return -EINVAL;
62 } 64 }
63 info->priv = cgrp; 65 info->priv = cgrp;
diff --git a/net/netfilter/xt_cluster.c b/net/netfilter/xt_cluster.c
index 57ef175dfbfa..0068688995c8 100644
--- a/net/netfilter/xt_cluster.c
+++ b/net/netfilter/xt_cluster.c
@@ -135,14 +135,12 @@ static int xt_cluster_mt_checkentry(const struct xt_mtchk_param *par)
135 struct xt_cluster_match_info *info = par->matchinfo; 135 struct xt_cluster_match_info *info = par->matchinfo;
136 136
137 if (info->total_nodes > XT_CLUSTER_NODES_MAX) { 137 if (info->total_nodes > XT_CLUSTER_NODES_MAX) {
138 pr_info("you have exceeded the maximum " 138 pr_info_ratelimited("you have exceeded the maximum number of cluster nodes (%u > %u)\n",
139 "number of cluster nodes (%u > %u)\n", 139 info->total_nodes, XT_CLUSTER_NODES_MAX);
140 info->total_nodes, XT_CLUSTER_NODES_MAX);
141 return -EINVAL; 140 return -EINVAL;
142 } 141 }
143 if (info->node_mask >= (1ULL << info->total_nodes)) { 142 if (info->node_mask >= (1ULL << info->total_nodes)) {
144 pr_info("this node mask cannot be " 143 pr_info_ratelimited("node mask cannot exceed total number of nodes\n");
145 "higher than the total number of nodes\n");
146 return -EDOM; 144 return -EDOM;
147 } 145 }
148 return 0; 146 return 0;
diff --git a/net/netfilter/xt_connbytes.c b/net/netfilter/xt_connbytes.c
index cad0b7b5eb35..93cb018c3055 100644
--- a/net/netfilter/xt_connbytes.c
+++ b/net/netfilter/xt_connbytes.c
@@ -112,8 +112,8 @@ static int connbytes_mt_check(const struct xt_mtchk_param *par)
112 112
113 ret = nf_ct_netns_get(par->net, par->family); 113 ret = nf_ct_netns_get(par->net, par->family);
114 if (ret < 0) 114 if (ret < 0)
115 pr_info("cannot load conntrack support for proto=%u\n", 115 pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
116 par->family); 116 par->family);
117 117
118 /* 118 /*
119 * This filter cannot function correctly unless connection tracking 119 * This filter cannot function correctly unless connection tracking
diff --git a/net/netfilter/xt_connlabel.c b/net/netfilter/xt_connlabel.c
index 23372879e6e3..4fa4efd24353 100644
--- a/net/netfilter/xt_connlabel.c
+++ b/net/netfilter/xt_connlabel.c
@@ -57,14 +57,15 @@ static int connlabel_mt_check(const struct xt_mtchk_param *par)
57 int ret; 57 int ret;
58 58
59 if (info->options & ~options) { 59 if (info->options & ~options) {
60 pr_err("Unknown options in mask %x\n", info->options); 60 pr_info_ratelimited("Unknown options in mask %x\n",
61 info->options);
61 return -EINVAL; 62 return -EINVAL;
62 } 63 }
63 64
64 ret = nf_ct_netns_get(par->net, par->family); 65 ret = nf_ct_netns_get(par->net, par->family);
65 if (ret < 0) { 66 if (ret < 0) {
66 pr_info("cannot load conntrack support for proto=%u\n", 67 pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
67 par->family); 68 par->family);
68 return ret; 69 return ret;
69 } 70 }
70 71
diff --git a/net/netfilter/xt_connmark.c b/net/netfilter/xt_connmark.c
index ec377cc6a369..809639ce6f5a 100644
--- a/net/netfilter/xt_connmark.c
+++ b/net/netfilter/xt_connmark.c
@@ -79,8 +79,8 @@ static int connmark_tg_check(const struct xt_tgchk_param *par)
79 79
80 ret = nf_ct_netns_get(par->net, par->family); 80 ret = nf_ct_netns_get(par->net, par->family);
81 if (ret < 0) 81 if (ret < 0)
82 pr_info("cannot load conntrack support for proto=%u\n", 82 pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
83 par->family); 83 par->family);
84 return ret; 84 return ret;
85} 85}
86 86
@@ -109,8 +109,8 @@ static int connmark_mt_check(const struct xt_mtchk_param *par)
109 109
110 ret = nf_ct_netns_get(par->net, par->family); 110 ret = nf_ct_netns_get(par->net, par->family);
111 if (ret < 0) 111 if (ret < 0)
112 pr_info("cannot load conntrack support for proto=%u\n", 112 pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
113 par->family); 113 par->family);
114 return ret; 114 return ret;
115} 115}
116 116
diff --git a/net/netfilter/xt_conntrack.c b/net/netfilter/xt_conntrack.c
index 39cf1d019240..df80fe7d391c 100644
--- a/net/netfilter/xt_conntrack.c
+++ b/net/netfilter/xt_conntrack.c
@@ -272,8 +272,8 @@ static int conntrack_mt_check(const struct xt_mtchk_param *par)
272 272
273 ret = nf_ct_netns_get(par->net, par->family); 273 ret = nf_ct_netns_get(par->net, par->family);
274 if (ret < 0) 274 if (ret < 0)
275 pr_info("cannot load conntrack support for proto=%u\n", 275 pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
276 par->family); 276 par->family);
277 return ret; 277 return ret;
278} 278}
279 279
diff --git a/net/netfilter/xt_dscp.c b/net/netfilter/xt_dscp.c
index 236ac8008909..a4c2b862f820 100644
--- a/net/netfilter/xt_dscp.c
+++ b/net/netfilter/xt_dscp.c
@@ -46,10 +46,8 @@ static int dscp_mt_check(const struct xt_mtchk_param *par)
46{ 46{
47 const struct xt_dscp_info *info = par->matchinfo; 47 const struct xt_dscp_info *info = par->matchinfo;
48 48
49 if (info->dscp > XT_DSCP_MAX) { 49 if (info->dscp > XT_DSCP_MAX)
50 pr_info("dscp %x out of range\n", info->dscp);
51 return -EDOM; 50 return -EDOM;
52 }
53 51
54 return 0; 52 return 0;
55} 53}
diff --git a/net/netfilter/xt_ecn.c b/net/netfilter/xt_ecn.c
index 3c831a8efebc..c7ad4afa5fb8 100644
--- a/net/netfilter/xt_ecn.c
+++ b/net/netfilter/xt_ecn.c
@@ -97,7 +97,7 @@ static int ecn_mt_check4(const struct xt_mtchk_param *par)
97 97
98 if (info->operation & (XT_ECN_OP_MATCH_ECE | XT_ECN_OP_MATCH_CWR) && 98 if (info->operation & (XT_ECN_OP_MATCH_ECE | XT_ECN_OP_MATCH_CWR) &&
99 (ip->proto != IPPROTO_TCP || ip->invflags & IPT_INV_PROTO)) { 99 (ip->proto != IPPROTO_TCP || ip->invflags & IPT_INV_PROTO)) {
100 pr_info("cannot match TCP bits in rule for non-tcp packets\n"); 100 pr_info_ratelimited("cannot match TCP bits for non-tcp packets\n");
101 return -EINVAL; 101 return -EINVAL;
102 } 102 }
103 103
@@ -139,7 +139,7 @@ static int ecn_mt_check6(const struct xt_mtchk_param *par)
139 139
140 if (info->operation & (XT_ECN_OP_MATCH_ECE | XT_ECN_OP_MATCH_CWR) && 140 if (info->operation & (XT_ECN_OP_MATCH_ECE | XT_ECN_OP_MATCH_CWR) &&
141 (ip->proto != IPPROTO_TCP || ip->invflags & IP6T_INV_PROTO)) { 141 (ip->proto != IPPROTO_TCP || ip->invflags & IP6T_INV_PROTO)) {
142 pr_info("cannot match TCP bits in rule for non-tcp packets\n"); 142 pr_info_ratelimited("cannot match TCP bits for non-tcp packets\n");
143 return -EINVAL; 143 return -EINVAL;
144 } 144 }
145 145
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index ca6847403ca2..3360f13dc208 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -523,7 +523,8 @@ static u64 user2rate(u64 user)
523 if (user != 0) { 523 if (user != 0) {
524 return div64_u64(XT_HASHLIMIT_SCALE_v2, user); 524 return div64_u64(XT_HASHLIMIT_SCALE_v2, user);
525 } else { 525 } else {
526 pr_warn("invalid rate from userspace: %llu\n", user); 526 pr_info_ratelimited("invalid rate from userspace: %llu\n",
527 user);
527 return 0; 528 return 0;
528 } 529 }
529} 530}
@@ -774,7 +775,7 @@ hashlimit_mt_common(const struct sk_buff *skb, struct xt_action_param *par,
774 if (!dh->rateinfo.prev_window && 775 if (!dh->rateinfo.prev_window &&
775 (dh->rateinfo.current_rate <= dh->rateinfo.burst)) { 776 (dh->rateinfo.current_rate <= dh->rateinfo.burst)) {
776 spin_unlock(&dh->lock); 777 spin_unlock(&dh->lock);
777 rcu_read_unlock_bh(); 778 local_bh_enable();
778 return !(cfg->mode & XT_HASHLIMIT_INVERT); 779 return !(cfg->mode & XT_HASHLIMIT_INVERT);
779 } else { 780 } else {
780 goto overlimit; 781 goto overlimit;
@@ -865,33 +866,34 @@ static int hashlimit_mt_check_common(const struct xt_mtchk_param *par,
865 } 866 }
866 867
867 if (cfg->mode & ~XT_HASHLIMIT_ALL) { 868 if (cfg->mode & ~XT_HASHLIMIT_ALL) {
868 pr_info("Unknown mode mask %X, kernel too old?\n", 869 pr_info_ratelimited("Unknown mode mask %X, kernel too old?\n",
869 cfg->mode); 870 cfg->mode);
870 return -EINVAL; 871 return -EINVAL;
871 } 872 }
872 873
873 /* Check for overflow. */ 874 /* Check for overflow. */
874 if (revision >= 3 && cfg->mode & XT_HASHLIMIT_RATE_MATCH) { 875 if (revision >= 3 && cfg->mode & XT_HASHLIMIT_RATE_MATCH) {
875 if (cfg->avg == 0 || cfg->avg > U32_MAX) { 876 if (cfg->avg == 0 || cfg->avg > U32_MAX) {
876 pr_info("hashlimit invalid rate\n"); 877 pr_info_ratelimited("invalid rate\n");
877 return -ERANGE; 878 return -ERANGE;
878 } 879 }
879 880
880 if (cfg->interval == 0) { 881 if (cfg->interval == 0) {
881 pr_info("hashlimit invalid interval\n"); 882 pr_info_ratelimited("invalid interval\n");
882 return -EINVAL; 883 return -EINVAL;
883 } 884 }
884 } else if (cfg->mode & XT_HASHLIMIT_BYTES) { 885 } else if (cfg->mode & XT_HASHLIMIT_BYTES) {
885 if (user2credits_byte(cfg->avg) == 0) { 886 if (user2credits_byte(cfg->avg) == 0) {
886 pr_info("overflow, rate too high: %llu\n", cfg->avg); 887 pr_info_ratelimited("overflow, rate too high: %llu\n",
888 cfg->avg);
887 return -EINVAL; 889 return -EINVAL;
888 } 890 }
889 } else if (cfg->burst == 0 || 891 } else if (cfg->burst == 0 ||
890 user2credits(cfg->avg * cfg->burst, revision) < 892 user2credits(cfg->avg * cfg->burst, revision) <
891 user2credits(cfg->avg, revision)) { 893 user2credits(cfg->avg, revision)) {
892 pr_info("overflow, try lower: %llu/%llu\n", 894 pr_info_ratelimited("overflow, try lower: %llu/%llu\n",
893 cfg->avg, cfg->burst); 895 cfg->avg, cfg->burst);
894 return -ERANGE; 896 return -ERANGE;
895 } 897 }
896 898
897 mutex_lock(&hashlimit_mutex); 899 mutex_lock(&hashlimit_mutex);
@@ -915,8 +917,9 @@ static int hashlimit_mt_check_v1(const struct xt_mtchk_param *par)
915 struct hashlimit_cfg3 cfg = {}; 917 struct hashlimit_cfg3 cfg = {};
916 int ret; 918 int ret;
917 919
918 if (info->name[sizeof(info->name) - 1] != '\0') 920 ret = xt_check_proc_name(info->name, sizeof(info->name));
919 return -EINVAL; 921 if (ret)
922 return ret;
920 923
921 ret = cfg_copy(&cfg, (void *)&info->cfg, 1); 924 ret = cfg_copy(&cfg, (void *)&info->cfg, 1);
922 925
@@ -933,8 +936,9 @@ static int hashlimit_mt_check_v2(const struct xt_mtchk_param *par)
933 struct hashlimit_cfg3 cfg = {}; 936 struct hashlimit_cfg3 cfg = {};
934 int ret; 937 int ret;
935 938
936 if (info->name[sizeof(info->name) - 1] != '\0') 939 ret = xt_check_proc_name(info->name, sizeof(info->name));
937 return -EINVAL; 940 if (ret)
941 return ret;
938 942
939 ret = cfg_copy(&cfg, (void *)&info->cfg, 2); 943 ret = cfg_copy(&cfg, (void *)&info->cfg, 2);
940 944
@@ -948,9 +952,11 @@ static int hashlimit_mt_check_v2(const struct xt_mtchk_param *par)
948static int hashlimit_mt_check(const struct xt_mtchk_param *par) 952static int hashlimit_mt_check(const struct xt_mtchk_param *par)
949{ 953{
950 struct xt_hashlimit_mtinfo3 *info = par->matchinfo; 954 struct xt_hashlimit_mtinfo3 *info = par->matchinfo;
955 int ret;
951 956
952 if (info->name[sizeof(info->name) - 1] != '\0') 957 ret = xt_check_proc_name(info->name, sizeof(info->name));
953 return -EINVAL; 958 if (ret)
959 return ret;
954 960
955 return hashlimit_mt_check_common(par, &info->hinfo, &info->cfg, 961 return hashlimit_mt_check_common(par, &info->hinfo, &info->cfg,
956 info->name, 3); 962 info->name, 3);
diff --git a/net/netfilter/xt_helper.c b/net/netfilter/xt_helper.c
index 38a78151c0e9..fd077aeaaed9 100644
--- a/net/netfilter/xt_helper.c
+++ b/net/netfilter/xt_helper.c
@@ -61,8 +61,8 @@ static int helper_mt_check(const struct xt_mtchk_param *par)
61 61
62 ret = nf_ct_netns_get(par->net, par->family); 62 ret = nf_ct_netns_get(par->net, par->family);
63 if (ret < 0) { 63 if (ret < 0) {
64 pr_info("cannot load conntrack support for proto=%u\n", 64 pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
65 par->family); 65 par->family);
66 return ret; 66 return ret;
67 } 67 }
68 info->name[sizeof(info->name) - 1] = '\0'; 68 info->name[sizeof(info->name) - 1] = '\0';
diff --git a/net/netfilter/xt_ipcomp.c b/net/netfilter/xt_ipcomp.c
index 7ca64a50db04..57f1df575701 100644
--- a/net/netfilter/xt_ipcomp.c
+++ b/net/netfilter/xt_ipcomp.c
@@ -72,7 +72,7 @@ static int comp_mt_check(const struct xt_mtchk_param *par)
72 72
73 /* Must specify no unknown invflags */ 73 /* Must specify no unknown invflags */
74 if (compinfo->invflags & ~XT_IPCOMP_INV_MASK) { 74 if (compinfo->invflags & ~XT_IPCOMP_INV_MASK) {
75 pr_err("unknown flags %X\n", compinfo->invflags); 75 pr_info_ratelimited("unknown flags %X\n", compinfo->invflags);
76 return -EINVAL; 76 return -EINVAL;
77 } 77 }
78 return 0; 78 return 0;
diff --git a/net/netfilter/xt_ipvs.c b/net/netfilter/xt_ipvs.c
index 42540d26c2b8..1d950a6100af 100644
--- a/net/netfilter/xt_ipvs.c
+++ b/net/netfilter/xt_ipvs.c
@@ -158,7 +158,8 @@ static int ipvs_mt_check(const struct xt_mtchk_param *par)
158 && par->family != NFPROTO_IPV6 158 && par->family != NFPROTO_IPV6
159#endif 159#endif
160 ) { 160 ) {
161 pr_info("protocol family %u not supported\n", par->family); 161 pr_info_ratelimited("protocol family %u not supported\n",
162 par->family);
162 return -EINVAL; 163 return -EINVAL;
163 } 164 }
164 165
diff --git a/net/netfilter/xt_l2tp.c b/net/netfilter/xt_l2tp.c
index 8aee572771f2..c43482bf48e6 100644
--- a/net/netfilter/xt_l2tp.c
+++ b/net/netfilter/xt_l2tp.c
@@ -216,7 +216,7 @@ static int l2tp_mt_check(const struct xt_mtchk_param *par)
216 /* Check for invalid flags */ 216 /* Check for invalid flags */
217 if (info->flags & ~(XT_L2TP_TID | XT_L2TP_SID | XT_L2TP_VERSION | 217 if (info->flags & ~(XT_L2TP_TID | XT_L2TP_SID | XT_L2TP_VERSION |
218 XT_L2TP_TYPE)) { 218 XT_L2TP_TYPE)) {
219 pr_info("unknown flags: %x\n", info->flags); 219 pr_info_ratelimited("unknown flags: %x\n", info->flags);
220 return -EINVAL; 220 return -EINVAL;
221 } 221 }
222 222
@@ -225,7 +225,8 @@ static int l2tp_mt_check(const struct xt_mtchk_param *par)
225 (!(info->flags & XT_L2TP_SID)) && 225 (!(info->flags & XT_L2TP_SID)) &&
226 ((!(info->flags & XT_L2TP_TYPE)) || 226 ((!(info->flags & XT_L2TP_TYPE)) ||
227 (info->type != XT_L2TP_TYPE_CONTROL))) { 227 (info->type != XT_L2TP_TYPE_CONTROL))) {
228 pr_info("invalid flags combination: %x\n", info->flags); 228 pr_info_ratelimited("invalid flags combination: %x\n",
229 info->flags);
229 return -EINVAL; 230 return -EINVAL;
230 } 231 }
231 232
@@ -234,19 +235,22 @@ static int l2tp_mt_check(const struct xt_mtchk_param *par)
234 */ 235 */
235 if (info->flags & XT_L2TP_VERSION) { 236 if (info->flags & XT_L2TP_VERSION) {
236 if ((info->version < 2) || (info->version > 3)) { 237 if ((info->version < 2) || (info->version > 3)) {
237 pr_info("wrong L2TP version: %u\n", info->version); 238 pr_info_ratelimited("wrong L2TP version: %u\n",
239 info->version);
238 return -EINVAL; 240 return -EINVAL;
239 } 241 }
240 242
241 if (info->version == 2) { 243 if (info->version == 2) {
242 if ((info->flags & XT_L2TP_TID) && 244 if ((info->flags & XT_L2TP_TID) &&
243 (info->tid > 0xffff)) { 245 (info->tid > 0xffff)) {
244 pr_info("v2 tid > 0xffff: %u\n", info->tid); 246 pr_info_ratelimited("v2 tid > 0xffff: %u\n",
247 info->tid);
245 return -EINVAL; 248 return -EINVAL;
246 } 249 }
247 if ((info->flags & XT_L2TP_SID) && 250 if ((info->flags & XT_L2TP_SID) &&
248 (info->sid > 0xffff)) { 251 (info->sid > 0xffff)) {
249 pr_info("v2 sid > 0xffff: %u\n", info->sid); 252 pr_info_ratelimited("v2 sid > 0xffff: %u\n",
253 info->sid);
250 return -EINVAL; 254 return -EINVAL;
251 } 255 }
252 } 256 }
@@ -268,13 +272,13 @@ static int l2tp_mt_check4(const struct xt_mtchk_param *par)
268 272
269 if ((ip->proto != IPPROTO_UDP) && 273 if ((ip->proto != IPPROTO_UDP) &&
270 (ip->proto != IPPROTO_L2TP)) { 274 (ip->proto != IPPROTO_L2TP)) {
271 pr_info("missing protocol rule (udp|l2tpip)\n"); 275 pr_info_ratelimited("missing protocol rule (udp|l2tpip)\n");
272 return -EINVAL; 276 return -EINVAL;
273 } 277 }
274 278
275 if ((ip->proto == IPPROTO_L2TP) && 279 if ((ip->proto == IPPROTO_L2TP) &&
276 (info->version == 2)) { 280 (info->version == 2)) {
277 pr_info("v2 doesn't support IP mode\n"); 281 pr_info_ratelimited("v2 doesn't support IP mode\n");
278 return -EINVAL; 282 return -EINVAL;
279 } 283 }
280 284
@@ -295,13 +299,13 @@ static int l2tp_mt_check6(const struct xt_mtchk_param *par)
295 299
296 if ((ip->proto != IPPROTO_UDP) && 300 if ((ip->proto != IPPROTO_UDP) &&
297 (ip->proto != IPPROTO_L2TP)) { 301 (ip->proto != IPPROTO_L2TP)) {
298 pr_info("missing protocol rule (udp|l2tpip)\n"); 302 pr_info_ratelimited("missing protocol rule (udp|l2tpip)\n");
299 return -EINVAL; 303 return -EINVAL;
300 } 304 }
301 305
302 if ((ip->proto == IPPROTO_L2TP) && 306 if ((ip->proto == IPPROTO_L2TP) &&
303 (info->version == 2)) { 307 (info->version == 2)) {
304 pr_info("v2 doesn't support IP mode\n"); 308 pr_info_ratelimited("v2 doesn't support IP mode\n");
305 return -EINVAL; 309 return -EINVAL;
306 } 310 }
307 311
diff --git a/net/netfilter/xt_limit.c b/net/netfilter/xt_limit.c
index 61403b77361c..55d18cd67635 100644
--- a/net/netfilter/xt_limit.c
+++ b/net/netfilter/xt_limit.c
@@ -106,8 +106,8 @@ static int limit_mt_check(const struct xt_mtchk_param *par)
106 /* Check for overflow. */ 106 /* Check for overflow. */
107 if (r->burst == 0 107 if (r->burst == 0
108 || user2credits(r->avg * r->burst) < user2credits(r->avg)) { 108 || user2credits(r->avg * r->burst) < user2credits(r->avg)) {
109 pr_info("Overflow, try lower: %u/%u\n", 109 pr_info_ratelimited("Overflow, try lower: %u/%u\n",
110 r->avg, r->burst); 110 r->avg, r->burst);
111 return -ERANGE; 111 return -ERANGE;
112 } 112 }
113 113
diff --git a/net/netfilter/xt_nat.c b/net/netfilter/xt_nat.c
index 0fd14d1eb09d..bdb689cdc829 100644
--- a/net/netfilter/xt_nat.c
+++ b/net/netfilter/xt_nat.c
@@ -8,6 +8,8 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
11#include <linux/module.h> 13#include <linux/module.h>
12#include <linux/skbuff.h> 14#include <linux/skbuff.h>
13#include <linux/netfilter.h> 15#include <linux/netfilter.h>
@@ -19,8 +21,7 @@ static int xt_nat_checkentry_v0(const struct xt_tgchk_param *par)
19 const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo; 21 const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo;
20 22
21 if (mr->rangesize != 1) { 23 if (mr->rangesize != 1) {
22 pr_info("%s: multiple ranges no longer supported\n", 24 pr_info_ratelimited("multiple ranges no longer supported\n");
23 par->target->name);
24 return -EINVAL; 25 return -EINVAL;
25 } 26 }
26 return nf_ct_netns_get(par->net, par->family); 27 return nf_ct_netns_get(par->net, par->family);
diff --git a/net/netfilter/xt_nfacct.c b/net/netfilter/xt_nfacct.c
index 6f92d25590a8..c8674deed4eb 100644
--- a/net/netfilter/xt_nfacct.c
+++ b/net/netfilter/xt_nfacct.c
@@ -6,6 +6,8 @@
6 * it under the terms of the GNU General Public License version 2 (or any 6 * it under the terms of the GNU General Public License version 2 (or any
7 * later at your option) as published by the Free Software Foundation. 7 * later at your option) as published by the Free Software Foundation.
8 */ 8 */
9#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10
9#include <linux/module.h> 11#include <linux/module.h>
10#include <linux/skbuff.h> 12#include <linux/skbuff.h>
11 13
@@ -39,8 +41,8 @@ nfacct_mt_checkentry(const struct xt_mtchk_param *par)
39 41
40 nfacct = nfnl_acct_find_get(par->net, info->name); 42 nfacct = nfnl_acct_find_get(par->net, info->name);
41 if (nfacct == NULL) { 43 if (nfacct == NULL) {
42 pr_info("xt_nfacct: accounting object with name `%s' " 44 pr_info_ratelimited("accounting object `%s' does not exists\n",
43 "does not exists\n", info->name); 45 info->name);
44 return -ENOENT; 46 return -ENOENT;
45 } 47 }
46 info->nfacct = nfacct; 48 info->nfacct = nfacct;
diff --git a/net/netfilter/xt_physdev.c b/net/netfilter/xt_physdev.c
index bb33598e4530..9d6d67b953ac 100644
--- a/net/netfilter/xt_physdev.c
+++ b/net/netfilter/xt_physdev.c
@@ -107,9 +107,7 @@ static int physdev_mt_check(const struct xt_mtchk_param *par)
107 info->invert & XT_PHYSDEV_OP_BRIDGED) && 107 info->invert & XT_PHYSDEV_OP_BRIDGED) &&
108 par->hook_mask & ((1 << NF_INET_LOCAL_OUT) | 108 par->hook_mask & ((1 << NF_INET_LOCAL_OUT) |
109 (1 << NF_INET_FORWARD) | (1 << NF_INET_POST_ROUTING))) { 109 (1 << NF_INET_FORWARD) | (1 << NF_INET_POST_ROUTING))) {
110 pr_info("using --physdev-out and --physdev-is-out are only " 110 pr_info_ratelimited("--physdev-out and --physdev-is-out only supported in the FORWARD and POSTROUTING chains with bridged traffic\n");
111 "supported in the FORWARD and POSTROUTING chains with "
112 "bridged traffic.\n");
113 if (par->hook_mask & (1 << NF_INET_LOCAL_OUT)) 111 if (par->hook_mask & (1 << NF_INET_LOCAL_OUT))
114 return -EINVAL; 112 return -EINVAL;
115 } 113 }
diff --git a/net/netfilter/xt_policy.c b/net/netfilter/xt_policy.c
index 5639fb03bdd9..13f8ccf946d6 100644
--- a/net/netfilter/xt_policy.c
+++ b/net/netfilter/xt_policy.c
@@ -132,26 +132,29 @@ policy_mt(const struct sk_buff *skb, struct xt_action_param *par)
132static int policy_mt_check(const struct xt_mtchk_param *par) 132static int policy_mt_check(const struct xt_mtchk_param *par)
133{ 133{
134 const struct xt_policy_info *info = par->matchinfo; 134 const struct xt_policy_info *info = par->matchinfo;
135 const char *errmsg = "neither incoming nor outgoing policy selected";
136
137 if (!(info->flags & (XT_POLICY_MATCH_IN|XT_POLICY_MATCH_OUT)))
138 goto err;
135 139
136 if (!(info->flags & (XT_POLICY_MATCH_IN|XT_POLICY_MATCH_OUT))) {
137 pr_info("neither incoming nor outgoing policy selected\n");
138 return -EINVAL;
139 }
140 if (par->hook_mask & ((1 << NF_INET_PRE_ROUTING) | 140 if (par->hook_mask & ((1 << NF_INET_PRE_ROUTING) |
141 (1 << NF_INET_LOCAL_IN)) && info->flags & XT_POLICY_MATCH_OUT) { 141 (1 << NF_INET_LOCAL_IN)) && info->flags & XT_POLICY_MATCH_OUT) {
142 pr_info("output policy not valid in PREROUTING and INPUT\n"); 142 errmsg = "output policy not valid in PREROUTING and INPUT";
143 return -EINVAL; 143 goto err;
144 } 144 }
145 if (par->hook_mask & ((1 << NF_INET_POST_ROUTING) | 145 if (par->hook_mask & ((1 << NF_INET_POST_ROUTING) |
146 (1 << NF_INET_LOCAL_OUT)) && info->flags & XT_POLICY_MATCH_IN) { 146 (1 << NF_INET_LOCAL_OUT)) && info->flags & XT_POLICY_MATCH_IN) {
147 pr_info("input policy not valid in POSTROUTING and OUTPUT\n"); 147 errmsg = "input policy not valid in POSTROUTING and OUTPUT";
148 return -EINVAL; 148 goto err;
149 } 149 }
150 if (info->len > XT_POLICY_MAX_ELEM) { 150 if (info->len > XT_POLICY_MAX_ELEM) {
151 pr_info("too many policy elements\n"); 151 errmsg = "too many policy elements";
152 return -EINVAL; 152 goto err;
153 } 153 }
154 return 0; 154 return 0;
155err:
156 pr_info_ratelimited("%s\n", errmsg);
157 return -EINVAL;
155} 158}
156 159
157static struct xt_match policy_mt_reg[] __read_mostly = { 160static struct xt_match policy_mt_reg[] __read_mostly = {
diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index 245fa350a7a8..81ee1d6543b2 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -342,8 +342,8 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
342 net_get_random_once(&hash_rnd, sizeof(hash_rnd)); 342 net_get_random_once(&hash_rnd, sizeof(hash_rnd));
343 343
344 if (info->check_set & ~XT_RECENT_VALID_FLAGS) { 344 if (info->check_set & ~XT_RECENT_VALID_FLAGS) {
345 pr_info("Unsupported user space flags (%08x)\n", 345 pr_info_ratelimited("Unsupported userspace flags (%08x)\n",
346 info->check_set); 346 info->check_set);
347 return -EINVAL; 347 return -EINVAL;
348 } 348 }
349 if (hweight8(info->check_set & 349 if (hweight8(info->check_set &
@@ -357,13 +357,13 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
357 if ((info->check_set & XT_RECENT_REAP) && !info->seconds) 357 if ((info->check_set & XT_RECENT_REAP) && !info->seconds)
358 return -EINVAL; 358 return -EINVAL;
359 if (info->hit_count >= XT_RECENT_MAX_NSTAMPS) { 359 if (info->hit_count >= XT_RECENT_MAX_NSTAMPS) {
360 pr_info("hitcount (%u) is larger than allowed maximum (%u)\n", 360 pr_info_ratelimited("hitcount (%u) is larger than allowed maximum (%u)\n",
361 info->hit_count, XT_RECENT_MAX_NSTAMPS - 1); 361 info->hit_count, XT_RECENT_MAX_NSTAMPS - 1);
362 return -EINVAL; 362 return -EINVAL;
363 } 363 }
364 if (info->name[0] == '\0' || 364 ret = xt_check_proc_name(info->name, sizeof(info->name));
365 strnlen(info->name, XT_RECENT_NAME_LEN) == XT_RECENT_NAME_LEN) 365 if (ret)
366 return -EINVAL; 366 return ret;
367 367
368 if (ip_pkt_list_tot && info->hit_count < ip_pkt_list_tot) 368 if (ip_pkt_list_tot && info->hit_count < ip_pkt_list_tot)
369 nstamp_mask = roundup_pow_of_two(ip_pkt_list_tot) - 1; 369 nstamp_mask = roundup_pow_of_two(ip_pkt_list_tot) - 1;
@@ -587,7 +587,7 @@ recent_mt_proc_write(struct file *file, const char __user *input,
587 add = true; 587 add = true;
588 break; 588 break;
589 default: 589 default:
590 pr_info("Need \"+ip\", \"-ip\" or \"/\"\n"); 590 pr_info_ratelimited("Need \"+ip\", \"-ip\" or \"/\"\n");
591 return -EINVAL; 591 return -EINVAL;
592 } 592 }
593 593
@@ -601,10 +601,8 @@ recent_mt_proc_write(struct file *file, const char __user *input,
601 succ = in4_pton(c, size, (void *)&addr, '\n', NULL); 601 succ = in4_pton(c, size, (void *)&addr, '\n', NULL);
602 } 602 }
603 603
604 if (!succ) { 604 if (!succ)
605 pr_info("illegal address written to procfs\n");
606 return -EINVAL; 605 return -EINVAL;
607 }
608 606
609 spin_lock_bh(&recent_lock); 607 spin_lock_bh(&recent_lock);
610 e = recent_entry_lookup(t, &addr, family, 0); 608 e = recent_entry_lookup(t, &addr, family, 0);
diff --git a/net/netfilter/xt_set.c b/net/netfilter/xt_set.c
index 16b6b11ee83f..6f4c5217d835 100644
--- a/net/netfilter/xt_set.c
+++ b/net/netfilter/xt_set.c
@@ -92,12 +92,12 @@ set_match_v0_checkentry(const struct xt_mtchk_param *par)
92 index = ip_set_nfnl_get_byindex(par->net, info->match_set.index); 92 index = ip_set_nfnl_get_byindex(par->net, info->match_set.index);
93 93
94 if (index == IPSET_INVALID_ID) { 94 if (index == IPSET_INVALID_ID) {
95 pr_warn("Cannot find set identified by id %u to match\n", 95 pr_info_ratelimited("Cannot find set identified by id %u to match\n",
96 info->match_set.index); 96 info->match_set.index);
97 return -ENOENT; 97 return -ENOENT;
98 } 98 }
99 if (info->match_set.u.flags[IPSET_DIM_MAX - 1] != 0) { 99 if (info->match_set.u.flags[IPSET_DIM_MAX - 1] != 0) {
100 pr_warn("Protocol error: set match dimension is over the limit!\n"); 100 pr_info_ratelimited("set match dimension is over the limit!\n");
101 ip_set_nfnl_put(par->net, info->match_set.index); 101 ip_set_nfnl_put(par->net, info->match_set.index);
102 return -ERANGE; 102 return -ERANGE;
103 } 103 }
@@ -143,12 +143,12 @@ set_match_v1_checkentry(const struct xt_mtchk_param *par)
143 index = ip_set_nfnl_get_byindex(par->net, info->match_set.index); 143 index = ip_set_nfnl_get_byindex(par->net, info->match_set.index);
144 144
145 if (index == IPSET_INVALID_ID) { 145 if (index == IPSET_INVALID_ID) {
146 pr_warn("Cannot find set identified by id %u to match\n", 146 pr_info_ratelimited("Cannot find set identified by id %u to match\n",
147 info->match_set.index); 147 info->match_set.index);
148 return -ENOENT; 148 return -ENOENT;
149 } 149 }
150 if (info->match_set.dim > IPSET_DIM_MAX) { 150 if (info->match_set.dim > IPSET_DIM_MAX) {
151 pr_warn("Protocol error: set match dimension is over the limit!\n"); 151 pr_info_ratelimited("set match dimension is over the limit!\n");
152 ip_set_nfnl_put(par->net, info->match_set.index); 152 ip_set_nfnl_put(par->net, info->match_set.index);
153 return -ERANGE; 153 return -ERANGE;
154 } 154 }
@@ -241,8 +241,8 @@ set_target_v0_checkentry(const struct xt_tgchk_param *par)
241 if (info->add_set.index != IPSET_INVALID_ID) { 241 if (info->add_set.index != IPSET_INVALID_ID) {
242 index = ip_set_nfnl_get_byindex(par->net, info->add_set.index); 242 index = ip_set_nfnl_get_byindex(par->net, info->add_set.index);
243 if (index == IPSET_INVALID_ID) { 243 if (index == IPSET_INVALID_ID) {
244 pr_warn("Cannot find add_set index %u as target\n", 244 pr_info_ratelimited("Cannot find add_set index %u as target\n",
245 info->add_set.index); 245 info->add_set.index);
246 return -ENOENT; 246 return -ENOENT;
247 } 247 }
248 } 248 }
@@ -250,8 +250,8 @@ set_target_v0_checkentry(const struct xt_tgchk_param *par)
250 if (info->del_set.index != IPSET_INVALID_ID) { 250 if (info->del_set.index != IPSET_INVALID_ID) {
251 index = ip_set_nfnl_get_byindex(par->net, info->del_set.index); 251 index = ip_set_nfnl_get_byindex(par->net, info->del_set.index);
252 if (index == IPSET_INVALID_ID) { 252 if (index == IPSET_INVALID_ID) {
253 pr_warn("Cannot find del_set index %u as target\n", 253 pr_info_ratelimited("Cannot find del_set index %u as target\n",
254 info->del_set.index); 254 info->del_set.index);
255 if (info->add_set.index != IPSET_INVALID_ID) 255 if (info->add_set.index != IPSET_INVALID_ID)
256 ip_set_nfnl_put(par->net, info->add_set.index); 256 ip_set_nfnl_put(par->net, info->add_set.index);
257 return -ENOENT; 257 return -ENOENT;
@@ -259,7 +259,7 @@ set_target_v0_checkentry(const struct xt_tgchk_param *par)
259 } 259 }
260 if (info->add_set.u.flags[IPSET_DIM_MAX - 1] != 0 || 260 if (info->add_set.u.flags[IPSET_DIM_MAX - 1] != 0 ||
261 info->del_set.u.flags[IPSET_DIM_MAX - 1] != 0) { 261 info->del_set.u.flags[IPSET_DIM_MAX - 1] != 0) {
262 pr_warn("Protocol error: SET target dimension is over the limit!\n"); 262 pr_info_ratelimited("SET target dimension over the limit!\n");
263 if (info->add_set.index != IPSET_INVALID_ID) 263 if (info->add_set.index != IPSET_INVALID_ID)
264 ip_set_nfnl_put(par->net, info->add_set.index); 264 ip_set_nfnl_put(par->net, info->add_set.index);
265 if (info->del_set.index != IPSET_INVALID_ID) 265 if (info->del_set.index != IPSET_INVALID_ID)
@@ -316,8 +316,8 @@ set_target_v1_checkentry(const struct xt_tgchk_param *par)
316 if (info->add_set.index != IPSET_INVALID_ID) { 316 if (info->add_set.index != IPSET_INVALID_ID) {
317 index = ip_set_nfnl_get_byindex(par->net, info->add_set.index); 317 index = ip_set_nfnl_get_byindex(par->net, info->add_set.index);
318 if (index == IPSET_INVALID_ID) { 318 if (index == IPSET_INVALID_ID) {
319 pr_warn("Cannot find add_set index %u as target\n", 319 pr_info_ratelimited("Cannot find add_set index %u as target\n",
320 info->add_set.index); 320 info->add_set.index);
321 return -ENOENT; 321 return -ENOENT;
322 } 322 }
323 } 323 }
@@ -325,8 +325,8 @@ set_target_v1_checkentry(const struct xt_tgchk_param *par)
325 if (info->del_set.index != IPSET_INVALID_ID) { 325 if (info->del_set.index != IPSET_INVALID_ID) {
326 index = ip_set_nfnl_get_byindex(par->net, info->del_set.index); 326 index = ip_set_nfnl_get_byindex(par->net, info->del_set.index);
327 if (index == IPSET_INVALID_ID) { 327 if (index == IPSET_INVALID_ID) {
328 pr_warn("Cannot find del_set index %u as target\n", 328 pr_info_ratelimited("Cannot find del_set index %u as target\n",
329 info->del_set.index); 329 info->del_set.index);
330 if (info->add_set.index != IPSET_INVALID_ID) 330 if (info->add_set.index != IPSET_INVALID_ID)
331 ip_set_nfnl_put(par->net, info->add_set.index); 331 ip_set_nfnl_put(par->net, info->add_set.index);
332 return -ENOENT; 332 return -ENOENT;
@@ -334,7 +334,7 @@ set_target_v1_checkentry(const struct xt_tgchk_param *par)
334 } 334 }
335 if (info->add_set.dim > IPSET_DIM_MAX || 335 if (info->add_set.dim > IPSET_DIM_MAX ||
336 info->del_set.dim > IPSET_DIM_MAX) { 336 info->del_set.dim > IPSET_DIM_MAX) {
337 pr_warn("Protocol error: SET target dimension is over the limit!\n"); 337 pr_info_ratelimited("SET target dimension over the limit!\n");
338 if (info->add_set.index != IPSET_INVALID_ID) 338 if (info->add_set.index != IPSET_INVALID_ID)
339 ip_set_nfnl_put(par->net, info->add_set.index); 339 ip_set_nfnl_put(par->net, info->add_set.index);
340 if (info->del_set.index != IPSET_INVALID_ID) 340 if (info->del_set.index != IPSET_INVALID_ID)
@@ -444,8 +444,8 @@ set_target_v3_checkentry(const struct xt_tgchk_param *par)
444 index = ip_set_nfnl_get_byindex(par->net, 444 index = ip_set_nfnl_get_byindex(par->net,
445 info->add_set.index); 445 info->add_set.index);
446 if (index == IPSET_INVALID_ID) { 446 if (index == IPSET_INVALID_ID) {
447 pr_warn("Cannot find add_set index %u as target\n", 447 pr_info_ratelimited("Cannot find add_set index %u as target\n",
448 info->add_set.index); 448 info->add_set.index);
449 return -ENOENT; 449 return -ENOENT;
450 } 450 }
451 } 451 }
@@ -454,8 +454,8 @@ set_target_v3_checkentry(const struct xt_tgchk_param *par)
454 index = ip_set_nfnl_get_byindex(par->net, 454 index = ip_set_nfnl_get_byindex(par->net,
455 info->del_set.index); 455 info->del_set.index);
456 if (index == IPSET_INVALID_ID) { 456 if (index == IPSET_INVALID_ID) {
457 pr_warn("Cannot find del_set index %u as target\n", 457 pr_info_ratelimited("Cannot find del_set index %u as target\n",
458 info->del_set.index); 458 info->del_set.index);
459 if (info->add_set.index != IPSET_INVALID_ID) 459 if (info->add_set.index != IPSET_INVALID_ID)
460 ip_set_nfnl_put(par->net, 460 ip_set_nfnl_put(par->net,
461 info->add_set.index); 461 info->add_set.index);
@@ -465,7 +465,7 @@ set_target_v3_checkentry(const struct xt_tgchk_param *par)
465 465
466 if (info->map_set.index != IPSET_INVALID_ID) { 466 if (info->map_set.index != IPSET_INVALID_ID) {
467 if (strncmp(par->table, "mangle", 7)) { 467 if (strncmp(par->table, "mangle", 7)) {
468 pr_warn("--map-set only usable from mangle table\n"); 468 pr_info_ratelimited("--map-set only usable from mangle table\n");
469 return -EINVAL; 469 return -EINVAL;
470 } 470 }
471 if (((info->flags & IPSET_FLAG_MAP_SKBPRIO) | 471 if (((info->flags & IPSET_FLAG_MAP_SKBPRIO) |
@@ -473,14 +473,14 @@ set_target_v3_checkentry(const struct xt_tgchk_param *par)
473 !(par->hook_mask & (1 << NF_INET_FORWARD | 473 !(par->hook_mask & (1 << NF_INET_FORWARD |
474 1 << NF_INET_LOCAL_OUT | 474 1 << NF_INET_LOCAL_OUT |
475 1 << NF_INET_POST_ROUTING))) { 475 1 << NF_INET_POST_ROUTING))) {
476 pr_warn("mapping of prio or/and queue is allowed only from OUTPUT/FORWARD/POSTROUTING chains\n"); 476 pr_info_ratelimited("mapping of prio or/and queue is allowed only from OUTPUT/FORWARD/POSTROUTING chains\n");
477 return -EINVAL; 477 return -EINVAL;
478 } 478 }
479 index = ip_set_nfnl_get_byindex(par->net, 479 index = ip_set_nfnl_get_byindex(par->net,
480 info->map_set.index); 480 info->map_set.index);
481 if (index == IPSET_INVALID_ID) { 481 if (index == IPSET_INVALID_ID) {
482 pr_warn("Cannot find map_set index %u as target\n", 482 pr_info_ratelimited("Cannot find map_set index %u as target\n",
483 info->map_set.index); 483 info->map_set.index);
484 if (info->add_set.index != IPSET_INVALID_ID) 484 if (info->add_set.index != IPSET_INVALID_ID)
485 ip_set_nfnl_put(par->net, 485 ip_set_nfnl_put(par->net,
486 info->add_set.index); 486 info->add_set.index);
@@ -494,7 +494,7 @@ set_target_v3_checkentry(const struct xt_tgchk_param *par)
494 if (info->add_set.dim > IPSET_DIM_MAX || 494 if (info->add_set.dim > IPSET_DIM_MAX ||
495 info->del_set.dim > IPSET_DIM_MAX || 495 info->del_set.dim > IPSET_DIM_MAX ||
496 info->map_set.dim > IPSET_DIM_MAX) { 496 info->map_set.dim > IPSET_DIM_MAX) {
497 pr_warn("Protocol error: SET target dimension is over the limit!\n"); 497 pr_info_ratelimited("SET target dimension over the limit!\n");
498 if (info->add_set.index != IPSET_INVALID_ID) 498 if (info->add_set.index != IPSET_INVALID_ID)
499 ip_set_nfnl_put(par->net, info->add_set.index); 499 ip_set_nfnl_put(par->net, info->add_set.index);
500 if (info->del_set.index != IPSET_INVALID_ID) 500 if (info->del_set.index != IPSET_INVALID_ID)
diff --git a/net/netfilter/xt_socket.c b/net/netfilter/xt_socket.c
index 575d2153e3b8..2ac7f674d19b 100644
--- a/net/netfilter/xt_socket.c
+++ b/net/netfilter/xt_socket.c
@@ -171,7 +171,8 @@ static int socket_mt_v1_check(const struct xt_mtchk_param *par)
171 return err; 171 return err;
172 172
173 if (info->flags & ~XT_SOCKET_FLAGS_V1) { 173 if (info->flags & ~XT_SOCKET_FLAGS_V1) {
174 pr_info("unknown flags 0x%x\n", info->flags & ~XT_SOCKET_FLAGS_V1); 174 pr_info_ratelimited("unknown flags 0x%x\n",
175 info->flags & ~XT_SOCKET_FLAGS_V1);
175 return -EINVAL; 176 return -EINVAL;
176 } 177 }
177 return 0; 178 return 0;
@@ -187,7 +188,8 @@ static int socket_mt_v2_check(const struct xt_mtchk_param *par)
187 return err; 188 return err;
188 189
189 if (info->flags & ~XT_SOCKET_FLAGS_V2) { 190 if (info->flags & ~XT_SOCKET_FLAGS_V2) {
190 pr_info("unknown flags 0x%x\n", info->flags & ~XT_SOCKET_FLAGS_V2); 191 pr_info_ratelimited("unknown flags 0x%x\n",
192 info->flags & ~XT_SOCKET_FLAGS_V2);
191 return -EINVAL; 193 return -EINVAL;
192 } 194 }
193 return 0; 195 return 0;
@@ -203,8 +205,8 @@ static int socket_mt_v3_check(const struct xt_mtchk_param *par)
203 if (err) 205 if (err)
204 return err; 206 return err;
205 if (info->flags & ~XT_SOCKET_FLAGS_V3) { 207 if (info->flags & ~XT_SOCKET_FLAGS_V3) {
206 pr_info("unknown flags 0x%x\n", 208 pr_info_ratelimited("unknown flags 0x%x\n",
207 info->flags & ~XT_SOCKET_FLAGS_V3); 209 info->flags & ~XT_SOCKET_FLAGS_V3);
208 return -EINVAL; 210 return -EINVAL;
209 } 211 }
210 return 0; 212 return 0;
diff --git a/net/netfilter/xt_state.c b/net/netfilter/xt_state.c
index 5fbd79194d21..0b41c0befe3c 100644
--- a/net/netfilter/xt_state.c
+++ b/net/netfilter/xt_state.c
@@ -44,8 +44,8 @@ static int state_mt_check(const struct xt_mtchk_param *par)
44 44
45 ret = nf_ct_netns_get(par->net, par->family); 45 ret = nf_ct_netns_get(par->net, par->family);
46 if (ret < 0) 46 if (ret < 0)
47 pr_info("cannot load conntrack support for proto=%u\n", 47 pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
48 par->family); 48 par->family);
49 return ret; 49 return ret;
50} 50}
51 51
diff --git a/net/netfilter/xt_time.c b/net/netfilter/xt_time.c
index 1b01eec1fbda..0160f505e337 100644
--- a/net/netfilter/xt_time.c
+++ b/net/netfilter/xt_time.c
@@ -235,13 +235,13 @@ static int time_mt_check(const struct xt_mtchk_param *par)
235 235
236 if (info->daytime_start > XT_TIME_MAX_DAYTIME || 236 if (info->daytime_start > XT_TIME_MAX_DAYTIME ||
237 info->daytime_stop > XT_TIME_MAX_DAYTIME) { 237 info->daytime_stop > XT_TIME_MAX_DAYTIME) {
238 pr_info("invalid argument - start or " 238 pr_info_ratelimited("invalid argument - start or stop time greater than 23:59:59\n");
239 "stop time greater than 23:59:59\n");
240 return -EDOM; 239 return -EDOM;
241 } 240 }
242 241
243 if (info->flags & ~XT_TIME_ALL_FLAGS) { 242 if (info->flags & ~XT_TIME_ALL_FLAGS) {
244 pr_info("unknown flags 0x%x\n", info->flags & ~XT_TIME_ALL_FLAGS); 243 pr_info_ratelimited("unknown flags 0x%x\n",
244 info->flags & ~XT_TIME_ALL_FLAGS);
245 return -EINVAL; 245 return -EINVAL;
246 } 246 }
247 247
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 2ad445c1d27c..07e8478068f0 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2308,7 +2308,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
2308 if (cb->start) { 2308 if (cb->start) {
2309 ret = cb->start(cb); 2309 ret = cb->start(cb);
2310 if (ret) 2310 if (ret)
2311 goto error_unlock; 2311 goto error_put;
2312 } 2312 }
2313 2313
2314 nlk->cb_running = true; 2314 nlk->cb_running = true;
@@ -2328,6 +2328,8 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
2328 */ 2328 */
2329 return -EINTR; 2329 return -EINTR;
2330 2330
2331error_put:
2332 module_put(control->module);
2331error_unlock: 2333error_unlock:
2332 sock_put(sk); 2334 sock_put(sk);
2333 mutex_unlock(nlk->cb_mutex); 2335 mutex_unlock(nlk->cb_mutex);
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 6f02499ef007..b9ce82c9440f 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -1106,7 +1106,7 @@ static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group,
1106 if (!err) 1106 if (!err)
1107 delivered = true; 1107 delivered = true;
1108 else if (err != -ESRCH) 1108 else if (err != -ESRCH)
1109 goto error; 1109 return err;
1110 return delivered ? 0 : -ESRCH; 1110 return delivered ? 0 : -ESRCH;
1111 error: 1111 error:
1112 kfree_skb(skb); 1112 kfree_skb(skb);
diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c
index 367d8c027101..2ceefa183cee 100644
--- a/net/nfc/llcp_commands.c
+++ b/net/nfc/llcp_commands.c
@@ -149,6 +149,10 @@ struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdreq_tlv(u8 tid, char *uri,
149 149
150 pr_debug("uri: %s, len: %zu\n", uri, uri_len); 150 pr_debug("uri: %s, len: %zu\n", uri, uri_len);
151 151
152 /* sdreq->tlv_len is u8, takes uri_len, + 3 for header, + 1 for NULL */
153 if (WARN_ON_ONCE(uri_len > U8_MAX - 4))
154 return NULL;
155
152 sdreq = kzalloc(sizeof(struct nfc_llcp_sdp_tlv), GFP_KERNEL); 156 sdreq = kzalloc(sizeof(struct nfc_llcp_sdp_tlv), GFP_KERNEL);
153 if (sdreq == NULL) 157 if (sdreq == NULL)
154 return NULL; 158 return NULL;
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index c0b83dc9d993..f018eafc2a0d 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -61,7 +61,8 @@ static const struct nla_policy nfc_genl_policy[NFC_ATTR_MAX + 1] = {
61}; 61};
62 62
63static const struct nla_policy nfc_sdp_genl_policy[NFC_SDP_ATTR_MAX + 1] = { 63static const struct nla_policy nfc_sdp_genl_policy[NFC_SDP_ATTR_MAX + 1] = {
64 [NFC_SDP_ATTR_URI] = { .type = NLA_STRING }, 64 [NFC_SDP_ATTR_URI] = { .type = NLA_STRING,
65 .len = U8_MAX - 4 },
65 [NFC_SDP_ATTR_SAP] = { .type = NLA_U8 }, 66 [NFC_SDP_ATTR_SAP] = { .type = NLA_U8 },
66}; 67};
67 68
diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c
index 04b94281a30b..b891a91577f8 100644
--- a/net/openvswitch/meter.c
+++ b/net/openvswitch/meter.c
@@ -242,14 +242,20 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
242 242
243 band->type = nla_get_u32(attr[OVS_BAND_ATTR_TYPE]); 243 band->type = nla_get_u32(attr[OVS_BAND_ATTR_TYPE]);
244 band->rate = nla_get_u32(attr[OVS_BAND_ATTR_RATE]); 244 band->rate = nla_get_u32(attr[OVS_BAND_ATTR_RATE]);
245 if (band->rate == 0) {
246 err = -EINVAL;
247 goto exit_free_meter;
248 }
249
245 band->burst_size = nla_get_u32(attr[OVS_BAND_ATTR_BURST]); 250 band->burst_size = nla_get_u32(attr[OVS_BAND_ATTR_BURST]);
246 /* Figure out max delta_t that is enough to fill any bucket. 251 /* Figure out max delta_t that is enough to fill any bucket.
247 * Keep max_delta_t size to the bucket units: 252 * Keep max_delta_t size to the bucket units:
248 * pkts => 1/1000 packets, kilobits => bits. 253 * pkts => 1/1000 packets, kilobits => bits.
254 *
255 * Start with a full bucket.
249 */ 256 */
250 band_max_delta_t = (band->burst_size + band->rate) * 1000; 257 band->bucket = (band->burst_size + band->rate) * 1000;
251 /* Start with a full bucket. */ 258 band_max_delta_t = band->bucket / band->rate;
252 band->bucket = band_max_delta_t;
253 if (band_max_delta_t > meter->max_delta_t) 259 if (band_max_delta_t > meter->max_delta_t)
254 meter->max_delta_t = band_max_delta_t; 260 meter->max_delta_t = band_max_delta_t;
255 band++; 261 band++;
diff --git a/net/qrtr/smd.c b/net/qrtr/smd.c
index 50615d5efac1..9cf089b9754e 100644
--- a/net/qrtr/smd.c
+++ b/net/qrtr/smd.c
@@ -114,5 +114,6 @@ static struct rpmsg_driver qcom_smd_qrtr_driver = {
114 114
115module_rpmsg_driver(qcom_smd_qrtr_driver); 115module_rpmsg_driver(qcom_smd_qrtr_driver);
116 116
117MODULE_ALIAS("rpmsg:IPCRTR");
117MODULE_DESCRIPTION("Qualcomm IPC-Router SMD interface driver"); 118MODULE_DESCRIPTION("Qualcomm IPC-Router SMD interface driver");
118MODULE_LICENSE("GPL v2"); 119MODULE_LICENSE("GPL v2");
diff --git a/net/rds/connection.c b/net/rds/connection.c
index 94e190febfdd..2da3176bf792 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -224,7 +224,7 @@ static struct rds_connection *__rds_conn_create(struct net *net,
224 if (rds_destroy_pending(conn)) 224 if (rds_destroy_pending(conn))
225 ret = -ENETDOWN; 225 ret = -ENETDOWN;
226 else 226 else
227 ret = trans->conn_alloc(conn, gfp); 227 ret = trans->conn_alloc(conn, GFP_ATOMIC);
228 if (ret) { 228 if (ret) {
229 rcu_read_unlock(); 229 rcu_read_unlock();
230 kfree(conn->c_path); 230 kfree(conn->c_path);
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index c061d6eb465d..22571189f21e 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Oracle. All rights reserved. 2 * Copyright (c) 2006, 2018 Oracle. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -142,12 +142,20 @@ int rds_tcp_accept_one(struct socket *sock)
142 if (ret) 142 if (ret)
143 goto out; 143 goto out;
144 144
145 new_sock->type = sock->type;
146 new_sock->ops = sock->ops;
147 ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, true); 145 ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, true);
148 if (ret < 0) 146 if (ret < 0)
149 goto out; 147 goto out;
150 148
149 /* sock_create_lite() does not get a hold on the owner module so we
150 * need to do it here. Note that sock_release() uses sock->ops to
151 * determine if it needs to decrement the reference count. So set
152 * sock->ops after calling accept() in case that fails. And there's
153 * no need to do try_module_get() as the listener should have a hold
154 * already.
155 */
156 new_sock->ops = sock->ops;
157 __module_get(new_sock->ops->owner);
158
151 ret = rds_tcp_keepalive(new_sock); 159 ret = rds_tcp_keepalive(new_sock);
152 if (ret < 0) 160 if (ret < 0)
153 goto out; 161 goto out;
diff --git a/net/rxrpc/output.c b/net/rxrpc/output.c
index 42410e910aff..cf73dc006c3b 100644
--- a/net/rxrpc/output.c
+++ b/net/rxrpc/output.c
@@ -445,7 +445,7 @@ send_fragmentable:
445 (char *)&opt, sizeof(opt)); 445 (char *)&opt, sizeof(opt));
446 if (ret == 0) { 446 if (ret == 0) {
447 ret = kernel_sendmsg(conn->params.local->socket, &msg, 447 ret = kernel_sendmsg(conn->params.local->socket, &msg,
448 iov, 1, iov[0].iov_len); 448 iov, 2, len);
449 449
450 opt = IPV6_PMTUDISC_DO; 450 opt = IPV6_PMTUDISC_DO;
451 kernel_setsockopt(conn->params.local->socket, 451 kernel_setsockopt(conn->params.local->socket,
diff --git a/net/rxrpc/recvmsg.c b/net/rxrpc/recvmsg.c
index cc21e8db25b0..9d45d8b56744 100644
--- a/net/rxrpc/recvmsg.c
+++ b/net/rxrpc/recvmsg.c
@@ -517,9 +517,10 @@ try_again:
517 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_USER_CALL_ID, 517 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_USER_CALL_ID,
518 sizeof(unsigned int), &id32); 518 sizeof(unsigned int), &id32);
519 } else { 519 } else {
520 unsigned long idl = call->user_call_ID;
521
520 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_USER_CALL_ID, 522 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_USER_CALL_ID,
521 sizeof(unsigned long), 523 sizeof(unsigned long), &idl);
522 &call->user_call_ID);
523 } 524 }
524 if (ret < 0) 525 if (ret < 0)
525 goto error_unlock_call; 526 goto error_unlock_call;
diff --git a/net/sched/act_bpf.c b/net/sched/act_bpf.c
index b3f2c15affa7..9d2cabf1dc7e 100644
--- a/net/sched/act_bpf.c
+++ b/net/sched/act_bpf.c
@@ -352,7 +352,7 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
352 return res; 352 return res;
353out: 353out:
354 if (res == ACT_P_CREATED) 354 if (res == ACT_P_CREATED)
355 tcf_idr_cleanup(*act, est); 355 tcf_idr_release(*act, bind);
356 356
357 return ret; 357 return ret;
358} 358}
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index b7ba9b06b147..2a5c8fd860cf 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -350,7 +350,7 @@ static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl,
350{ 350{
351 struct sctphdr *sctph; 351 struct sctphdr *sctph;
352 352
353 if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_SCTP) 353 if (skb_is_gso(skb) && skb_is_gso_sctp(skb))
354 return 1; 354 return 1;
355 355
356 sctph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*sctph)); 356 sctph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*sctph));
@@ -626,7 +626,8 @@ static void tcf_csum_cleanup(struct tc_action *a)
626 struct tcf_csum_params *params; 626 struct tcf_csum_params *params;
627 627
628 params = rcu_dereference_protected(p->params, 1); 628 params = rcu_dereference_protected(p->params, 1);
629 kfree_rcu(params, rcu); 629 if (params)
630 kfree_rcu(params, rcu);
630} 631}
631 632
632static int tcf_csum_walker(struct net *net, struct sk_buff *skb, 633static int tcf_csum_walker(struct net *net, struct sk_buff *skb,
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 06e380ae0928..7e06b9b62613 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -80,9 +80,12 @@ static void ipt_destroy_target(struct xt_entry_target *t)
80static void tcf_ipt_release(struct tc_action *a) 80static void tcf_ipt_release(struct tc_action *a)
81{ 81{
82 struct tcf_ipt *ipt = to_ipt(a); 82 struct tcf_ipt *ipt = to_ipt(a);
83 ipt_destroy_target(ipt->tcfi_t); 83
84 if (ipt->tcfi_t) {
85 ipt_destroy_target(ipt->tcfi_t);
86 kfree(ipt->tcfi_t);
87 }
84 kfree(ipt->tcfi_tname); 88 kfree(ipt->tcfi_tname);
85 kfree(ipt->tcfi_t);
86} 89}
87 90
88static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = { 91static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = {
@@ -187,7 +190,7 @@ err2:
187 kfree(tname); 190 kfree(tname);
188err1: 191err1:
189 if (ret == ACT_P_CREATED) 192 if (ret == ACT_P_CREATED)
190 tcf_idr_cleanup(*a, est); 193 tcf_idr_release(*a, bind);
191 return err; 194 return err;
192} 195}
193 196
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 349beaffb29e..fef08835f26d 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -176,7 +176,7 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
176 p = to_pedit(*a); 176 p = to_pedit(*a);
177 keys = kmalloc(ksize, GFP_KERNEL); 177 keys = kmalloc(ksize, GFP_KERNEL);
178 if (keys == NULL) { 178 if (keys == NULL) {
179 tcf_idr_cleanup(*a, est); 179 tcf_idr_release(*a, bind);
180 kfree(keys_ex); 180 kfree(keys_ex);
181 return -ENOMEM; 181 return -ENOMEM;
182 } 182 }
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 95d3c9097b25..faebf82b99f1 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -194,7 +194,7 @@ failure:
194 qdisc_put_rtab(P_tab); 194 qdisc_put_rtab(P_tab);
195 qdisc_put_rtab(R_tab); 195 qdisc_put_rtab(R_tab);
196 if (ret == ACT_P_CREATED) 196 if (ret == ACT_P_CREATED)
197 tcf_idr_cleanup(*a, est); 197 tcf_idr_release(*a, bind);
198 return err; 198 return err;
199} 199}
200 200
diff --git a/net/sched/act_sample.c b/net/sched/act_sample.c
index 1ba0df238756..74c5d7e6a0fa 100644
--- a/net/sched/act_sample.c
+++ b/net/sched/act_sample.c
@@ -103,7 +103,8 @@ static void tcf_sample_cleanup(struct tc_action *a)
103 103
104 psample_group = rtnl_dereference(s->psample_group); 104 psample_group = rtnl_dereference(s->psample_group);
105 RCU_INIT_POINTER(s->psample_group, NULL); 105 RCU_INIT_POINTER(s->psample_group, NULL);
106 psample_group_put(psample_group); 106 if (psample_group)
107 psample_group_put(psample_group);
107} 108}
108 109
109static bool tcf_sample_dev_ok_push(struct net_device *dev) 110static bool tcf_sample_dev_ok_push(struct net_device *dev)
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index 425eac11f6da..b1f38063ada0 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -121,7 +121,7 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
121 d = to_defact(*a); 121 d = to_defact(*a);
122 ret = alloc_defdata(d, defdata); 122 ret = alloc_defdata(d, defdata);
123 if (ret < 0) { 123 if (ret < 0) {
124 tcf_idr_cleanup(*a, est); 124 tcf_idr_release(*a, bind);
125 return ret; 125 return ret;
126 } 126 }
127 d->tcf_action = parm->action; 127 d->tcf_action = parm->action;
diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c
index fa975262dbac..7b0700f52b50 100644
--- a/net/sched/act_skbmod.c
+++ b/net/sched/act_skbmod.c
@@ -152,7 +152,7 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla,
152 ASSERT_RTNL(); 152 ASSERT_RTNL();
153 p = kzalloc(sizeof(struct tcf_skbmod_params), GFP_KERNEL); 153 p = kzalloc(sizeof(struct tcf_skbmod_params), GFP_KERNEL);
154 if (unlikely(!p)) { 154 if (unlikely(!p)) {
155 if (ovr) 155 if (ret == ACT_P_CREATED)
156 tcf_idr_release(*a, bind); 156 tcf_idr_release(*a, bind);
157 return -ENOMEM; 157 return -ENOMEM;
158 } 158 }
@@ -190,7 +190,8 @@ static void tcf_skbmod_cleanup(struct tc_action *a)
190 struct tcf_skbmod_params *p; 190 struct tcf_skbmod_params *p;
191 191
192 p = rcu_dereference_protected(d->skbmod_p, 1); 192 p = rcu_dereference_protected(d->skbmod_p, 1);
193 kfree_rcu(p, rcu); 193 if (p)
194 kfree_rcu(p, rcu);
194} 195}
195 196
196static int tcf_skbmod_dump(struct sk_buff *skb, struct tc_action *a, 197static int tcf_skbmod_dump(struct sk_buff *skb, struct tc_action *a,
diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index 0e23aac09ad6..1281ca463727 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -153,6 +153,7 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
153 metadata->u.tun_info.mode |= IP_TUNNEL_INFO_TX; 153 metadata->u.tun_info.mode |= IP_TUNNEL_INFO_TX;
154 break; 154 break;
155 default: 155 default:
156 ret = -EINVAL;
156 goto err_out; 157 goto err_out;
157 } 158 }
158 159
@@ -207,11 +208,12 @@ static void tunnel_key_release(struct tc_action *a)
207 struct tcf_tunnel_key_params *params; 208 struct tcf_tunnel_key_params *params;
208 209
209 params = rcu_dereference_protected(t->params, 1); 210 params = rcu_dereference_protected(t->params, 1);
211 if (params) {
212 if (params->tcft_action == TCA_TUNNEL_KEY_ACT_SET)
213 dst_release(&params->tcft_enc_metadata->dst);
210 214
211 if (params->tcft_action == TCA_TUNNEL_KEY_ACT_SET) 215 kfree_rcu(params, rcu);
212 dst_release(&params->tcft_enc_metadata->dst); 216 }
213
214 kfree_rcu(params, rcu);
215} 217}
216 218
217static int tunnel_key_dump_addresses(struct sk_buff *skb, 219static int tunnel_key_dump_addresses(struct sk_buff *skb,
diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index e1a1b3f3983a..c49cb61adedf 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -195,7 +195,7 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
195 ASSERT_RTNL(); 195 ASSERT_RTNL();
196 p = kzalloc(sizeof(*p), GFP_KERNEL); 196 p = kzalloc(sizeof(*p), GFP_KERNEL);
197 if (!p) { 197 if (!p) {
198 if (ovr) 198 if (ret == ACT_P_CREATED)
199 tcf_idr_release(*a, bind); 199 tcf_idr_release(*a, bind);
200 return -ENOMEM; 200 return -ENOMEM;
201 } 201 }
@@ -225,7 +225,8 @@ static void tcf_vlan_cleanup(struct tc_action *a)
225 struct tcf_vlan_params *p; 225 struct tcf_vlan_params *p;
226 226
227 p = rcu_dereference_protected(v->vlan_p, 1); 227 p = rcu_dereference_protected(v->vlan_p, 1);
228 kfree_rcu(p, rcu); 228 if (p)
229 kfree_rcu(p, rcu);
229} 230}
230 231
231static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a, 232static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 2bc1bc23d42e..247b7cc20c13 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -376,17 +376,12 @@ struct tcf_net {
376static unsigned int tcf_net_id; 376static unsigned int tcf_net_id;
377 377
378static int tcf_block_insert(struct tcf_block *block, struct net *net, 378static int tcf_block_insert(struct tcf_block *block, struct net *net,
379 u32 block_index, struct netlink_ext_ack *extack) 379 struct netlink_ext_ack *extack)
380{ 380{
381 struct tcf_net *tn = net_generic(net, tcf_net_id); 381 struct tcf_net *tn = net_generic(net, tcf_net_id);
382 int err;
383 382
384 err = idr_alloc_u32(&tn->idr, block, &block_index, block_index, 383 return idr_alloc_u32(&tn->idr, block, &block->index, block->index,
385 GFP_KERNEL); 384 GFP_KERNEL);
386 if (err)
387 return err;
388 block->index = block_index;
389 return 0;
390} 385}
391 386
392static void tcf_block_remove(struct tcf_block *block, struct net *net) 387static void tcf_block_remove(struct tcf_block *block, struct net *net)
@@ -397,6 +392,7 @@ static void tcf_block_remove(struct tcf_block *block, struct net *net)
397} 392}
398 393
399static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q, 394static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q,
395 u32 block_index,
400 struct netlink_ext_ack *extack) 396 struct netlink_ext_ack *extack)
401{ 397{
402 struct tcf_block *block; 398 struct tcf_block *block;
@@ -419,10 +415,13 @@ static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q,
419 err = -ENOMEM; 415 err = -ENOMEM;
420 goto err_chain_create; 416 goto err_chain_create;
421 } 417 }
422 block->net = qdisc_net(q);
423 block->refcnt = 1; 418 block->refcnt = 1;
424 block->net = net; 419 block->net = net;
425 block->q = q; 420 block->index = block_index;
421
422 /* Don't store q pointer for blocks which are shared */
423 if (!tcf_block_shared(block))
424 block->q = q;
426 return block; 425 return block;
427 426
428err_chain_create: 427err_chain_create:
@@ -518,13 +517,12 @@ int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
518 } 517 }
519 518
520 if (!block) { 519 if (!block) {
521 block = tcf_block_create(net, q, extack); 520 block = tcf_block_create(net, q, ei->block_index, extack);
522 if (IS_ERR(block)) 521 if (IS_ERR(block))
523 return PTR_ERR(block); 522 return PTR_ERR(block);
524 created = true; 523 created = true;
525 if (ei->block_index) { 524 if (tcf_block_shared(block)) {
526 err = tcf_block_insert(block, net, 525 err = tcf_block_insert(block, net, extack);
527 ei->block_index, extack);
528 if (err) 526 if (err)
529 goto err_block_insert; 527 goto err_block_insert;
530 } 528 }
@@ -1399,13 +1397,18 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
1399 nla_get_u32(tca[TCA_CHAIN]) != chain->index) 1397 nla_get_u32(tca[TCA_CHAIN]) != chain->index)
1400 continue; 1398 continue;
1401 if (!tcf_chain_dump(chain, q, parent, skb, cb, 1399 if (!tcf_chain_dump(chain, q, parent, skb, cb,
1402 index_start, &index)) 1400 index_start, &index)) {
1401 err = -EMSGSIZE;
1403 break; 1402 break;
1403 }
1404 } 1404 }
1405 1405
1406 cb->args[0] = index; 1406 cb->args[0] = index;
1407 1407
1408out: 1408out:
1409 /* If we did no progress, the error (EMSGSIZE) is real */
1410 if (skb->len == 0 && err)
1411 return err;
1409 return skb->len; 1412 return skb->len;
1410} 1413}
1411 1414
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index 6c7601a530e3..ed8b6a24b9e9 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -96,7 +96,7 @@ struct tc_u_hnode {
96 96
97struct tc_u_common { 97struct tc_u_common {
98 struct tc_u_hnode __rcu *hlist; 98 struct tc_u_hnode __rcu *hlist;
99 struct tcf_block *block; 99 void *ptr;
100 int refcnt; 100 int refcnt;
101 struct idr handle_idr; 101 struct idr handle_idr;
102 struct hlist_node hnode; 102 struct hlist_node hnode;
@@ -330,9 +330,25 @@ static struct hlist_head *tc_u_common_hash;
330#define U32_HASH_SHIFT 10 330#define U32_HASH_SHIFT 10
331#define U32_HASH_SIZE (1 << U32_HASH_SHIFT) 331#define U32_HASH_SIZE (1 << U32_HASH_SHIFT)
332 332
333static void *tc_u_common_ptr(const struct tcf_proto *tp)
334{
335 struct tcf_block *block = tp->chain->block;
336
337 /* The block sharing is currently supported only
338 * for classless qdiscs. In that case we use block
339 * for tc_u_common identification. In case the
340 * block is not shared, block->q is a valid pointer
341 * and we can use that. That works for classful qdiscs.
342 */
343 if (tcf_block_shared(block))
344 return block;
345 else
346 return block->q;
347}
348
333static unsigned int tc_u_hash(const struct tcf_proto *tp) 349static unsigned int tc_u_hash(const struct tcf_proto *tp)
334{ 350{
335 return hash_ptr(tp->chain->block, U32_HASH_SHIFT); 351 return hash_ptr(tc_u_common_ptr(tp), U32_HASH_SHIFT);
336} 352}
337 353
338static struct tc_u_common *tc_u_common_find(const struct tcf_proto *tp) 354static struct tc_u_common *tc_u_common_find(const struct tcf_proto *tp)
@@ -342,7 +358,7 @@ static struct tc_u_common *tc_u_common_find(const struct tcf_proto *tp)
342 358
343 h = tc_u_hash(tp); 359 h = tc_u_hash(tp);
344 hlist_for_each_entry(tc, &tc_u_common_hash[h], hnode) { 360 hlist_for_each_entry(tc, &tc_u_common_hash[h], hnode) {
345 if (tc->block == tp->chain->block) 361 if (tc->ptr == tc_u_common_ptr(tp))
346 return tc; 362 return tc;
347 } 363 }
348 return NULL; 364 return NULL;
@@ -371,7 +387,7 @@ static int u32_init(struct tcf_proto *tp)
371 kfree(root_ht); 387 kfree(root_ht);
372 return -ENOBUFS; 388 return -ENOBUFS;
373 } 389 }
374 tp_c->block = tp->chain->block; 390 tp_c->ptr = tc_u_common_ptr(tp);
375 INIT_HLIST_NODE(&tp_c->hnode); 391 INIT_HLIST_NODE(&tp_c->hnode);
376 idr_init(&tp_c->handle_idr); 392 idr_init(&tp_c->handle_idr);
377 393
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 190570f21b20..7e3fbe9cc936 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -106,6 +106,14 @@ static inline void qdisc_enqueue_skb_bad_txq(struct Qdisc *q,
106 106
107 __skb_queue_tail(&q->skb_bad_txq, skb); 107 __skb_queue_tail(&q->skb_bad_txq, skb);
108 108
109 if (qdisc_is_percpu_stats(q)) {
110 qdisc_qstats_cpu_backlog_inc(q, skb);
111 qdisc_qstats_cpu_qlen_inc(q);
112 } else {
113 qdisc_qstats_backlog_inc(q, skb);
114 q->q.qlen++;
115 }
116
109 if (lock) 117 if (lock)
110 spin_unlock(lock); 118 spin_unlock(lock);
111} 119}
@@ -196,14 +204,6 @@ static void try_bulk_dequeue_skb_slow(struct Qdisc *q,
196 break; 204 break;
197 if (unlikely(skb_get_queue_mapping(nskb) != mapping)) { 205 if (unlikely(skb_get_queue_mapping(nskb) != mapping)) {
198 qdisc_enqueue_skb_bad_txq(q, nskb); 206 qdisc_enqueue_skb_bad_txq(q, nskb);
199
200 if (qdisc_is_percpu_stats(q)) {
201 qdisc_qstats_cpu_backlog_inc(q, nskb);
202 qdisc_qstats_cpu_qlen_inc(q);
203 } else {
204 qdisc_qstats_backlog_inc(q, nskb);
205 q->q.qlen++;
206 }
207 break; 207 break;
208 } 208 }
209 skb->next = nskb; 209 skb->next = nskb;
@@ -628,6 +628,7 @@ static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc *qdisc,
628 int band = prio2band[skb->priority & TC_PRIO_MAX]; 628 int band = prio2band[skb->priority & TC_PRIO_MAX];
629 struct pfifo_fast_priv *priv = qdisc_priv(qdisc); 629 struct pfifo_fast_priv *priv = qdisc_priv(qdisc);
630 struct skb_array *q = band2list(priv, band); 630 struct skb_array *q = band2list(priv, band);
631 unsigned int pkt_len = qdisc_pkt_len(skb);
631 int err; 632 int err;
632 633
633 err = skb_array_produce(q, skb); 634 err = skb_array_produce(q, skb);
@@ -636,7 +637,10 @@ static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc *qdisc,
636 return qdisc_drop_cpu(skb, qdisc, to_free); 637 return qdisc_drop_cpu(skb, qdisc, to_free);
637 638
638 qdisc_qstats_cpu_qlen_inc(qdisc); 639 qdisc_qstats_cpu_qlen_inc(qdisc);
639 qdisc_qstats_cpu_backlog_inc(qdisc, skb); 640 /* Note: skb can not be used after skb_array_produce(),
641 * so we better not use qdisc_qstats_cpu_backlog_inc()
642 */
643 this_cpu_add(qdisc->cpu_qstats->backlog, pkt_len);
640 return NET_XMIT_SUCCESS; 644 return NET_XMIT_SUCCESS;
641} 645}
642 646
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 7c179addebcd..7d6801fc5340 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -509,7 +509,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
509 } 509 }
510 510
511 if (unlikely(sch->q.qlen >= sch->limit)) 511 if (unlikely(sch->q.qlen >= sch->limit))
512 return qdisc_drop(skb, sch, to_free); 512 return qdisc_drop_all(skb, sch, to_free);
513 513
514 qdisc_qstats_backlog_inc(sch, skb); 514 qdisc_qstats_backlog_inc(sch, skb);
515 515
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index 229172d509cc..03225a8df973 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -188,7 +188,8 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc *sch,
188 int ret; 188 int ret;
189 189
190 if (qdisc_pkt_len(skb) > q->max_size) { 190 if (qdisc_pkt_len(skb) > q->max_size) {
191 if (skb_is_gso(skb) && skb_gso_mac_seglen(skb) <= q->max_size) 191 if (skb_is_gso(skb) &&
192 skb_gso_validate_mac_len(skb, q->max_size))
192 return tbf_segment(skb, sch, to_free); 193 return tbf_segment(skb, sch, to_free);
193 return qdisc_drop(skb, sch, to_free); 194 return qdisc_drop(skb, sch, to_free);
194 } 195 }
diff --git a/net/sctp/debug.c b/net/sctp/debug.c
index 291c97b07058..8f6c2e8c0953 100644
--- a/net/sctp/debug.c
+++ b/net/sctp/debug.c
@@ -81,6 +81,12 @@ const char *sctp_cname(const union sctp_subtype cid)
81 case SCTP_CID_RECONF: 81 case SCTP_CID_RECONF:
82 return "RECONF"; 82 return "RECONF";
83 83
84 case SCTP_CID_I_DATA:
85 return "I_DATA";
86
87 case SCTP_CID_I_FWD_TSN:
88 return "I_FWD_TSN";
89
84 default: 90 default:
85 break; 91 break;
86 } 92 }
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 141c9c466ec1..b381d78548ac 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -106,6 +106,7 @@ int sctp_rcv(struct sk_buff *skb)
106 int family; 106 int family;
107 struct sctp_af *af; 107 struct sctp_af *af;
108 struct net *net = dev_net(skb->dev); 108 struct net *net = dev_net(skb->dev);
109 bool is_gso = skb_is_gso(skb) && skb_is_gso_sctp(skb);
109 110
110 if (skb->pkt_type != PACKET_HOST) 111 if (skb->pkt_type != PACKET_HOST)
111 goto discard_it; 112 goto discard_it;
@@ -123,8 +124,7 @@ int sctp_rcv(struct sk_buff *skb)
123 * it's better to just linearize it otherwise crc computing 124 * it's better to just linearize it otherwise crc computing
124 * takes longer. 125 * takes longer.
125 */ 126 */
126 if ((!(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP) && 127 if ((!is_gso && skb_linearize(skb)) ||
127 skb_linearize(skb)) ||
128 !pskb_may_pull(skb, sizeof(struct sctphdr))) 128 !pskb_may_pull(skb, sizeof(struct sctphdr)))
129 goto discard_it; 129 goto discard_it;
130 130
@@ -135,7 +135,7 @@ int sctp_rcv(struct sk_buff *skb)
135 if (skb_csum_unnecessary(skb)) 135 if (skb_csum_unnecessary(skb))
136 __skb_decr_checksum_unnecessary(skb); 136 __skb_decr_checksum_unnecessary(skb);
137 else if (!sctp_checksum_disable && 137 else if (!sctp_checksum_disable &&
138 !(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP) && 138 !is_gso &&
139 sctp_rcv_checksum(net, skb) < 0) 139 sctp_rcv_checksum(net, skb) < 0)
140 goto discard_it; 140 goto discard_it;
141 skb->csum_valid = 1; 141 skb->csum_valid = 1;
@@ -897,15 +897,12 @@ int sctp_hash_transport(struct sctp_transport *t)
897 rhl_for_each_entry_rcu(transport, tmp, list, node) 897 rhl_for_each_entry_rcu(transport, tmp, list, node)
898 if (transport->asoc->ep == t->asoc->ep) { 898 if (transport->asoc->ep == t->asoc->ep) {
899 rcu_read_unlock(); 899 rcu_read_unlock();
900 err = -EEXIST; 900 return -EEXIST;
901 goto out;
902 } 901 }
903 rcu_read_unlock(); 902 rcu_read_unlock();
904 903
905 err = rhltable_insert_key(&sctp_transport_hashtable, &arg, 904 err = rhltable_insert_key(&sctp_transport_hashtable, &arg,
906 &t->node, sctp_hash_params); 905 &t->node, sctp_hash_params);
907
908out:
909 if (err) 906 if (err)
910 pr_err_once("insert transport fail, errno %d\n", err); 907 pr_err_once("insert transport fail, errno %d\n", err);
911 908
@@ -1221,7 +1218,7 @@ static struct sctp_association *__sctp_rcv_lookup_harder(struct net *net,
1221 * issue as packets hitting this are mostly INIT or INIT-ACK and 1218 * issue as packets hitting this are mostly INIT or INIT-ACK and
1222 * those cannot be on GSO-style anyway. 1219 * those cannot be on GSO-style anyway.
1223 */ 1220 */
1224 if ((skb_shinfo(skb)->gso_type & SKB_GSO_SCTP) == SKB_GSO_SCTP) 1221 if (skb_is_gso(skb) && skb_is_gso_sctp(skb))
1225 return NULL; 1222 return NULL;
1226 1223
1227 ch = (struct sctp_chunkhdr *)skb->data; 1224 ch = (struct sctp_chunkhdr *)skb->data;
diff --git a/net/sctp/inqueue.c b/net/sctp/inqueue.c
index 48392552ee7c..23ebc5318edc 100644
--- a/net/sctp/inqueue.c
+++ b/net/sctp/inqueue.c
@@ -170,7 +170,7 @@ next_chunk:
170 170
171 chunk = list_entry(entry, struct sctp_chunk, list); 171 chunk = list_entry(entry, struct sctp_chunk, list);
172 172
173 if ((skb_shinfo(chunk->skb)->gso_type & SKB_GSO_SCTP) == SKB_GSO_SCTP) { 173 if (skb_is_gso(chunk->skb) && skb_is_gso_sctp(chunk->skb)) {
174 /* GSO-marked skbs but without frags, handle 174 /* GSO-marked skbs but without frags, handle
175 * them normally 175 * them normally
176 */ 176 */
diff --git a/net/sctp/offload.c b/net/sctp/offload.c
index 35bc7106d182..123e9f2dc226 100644
--- a/net/sctp/offload.c
+++ b/net/sctp/offload.c
@@ -45,7 +45,7 @@ static struct sk_buff *sctp_gso_segment(struct sk_buff *skb,
45 struct sk_buff *segs = ERR_PTR(-EINVAL); 45 struct sk_buff *segs = ERR_PTR(-EINVAL);
46 struct sctphdr *sh; 46 struct sctphdr *sh;
47 47
48 if (!(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP)) 48 if (!skb_is_gso_sctp(skb))
49 goto out; 49 goto out;
50 50
51 sh = sctp_hdr(skb); 51 sh = sctp_hdr(skb);
diff --git a/net/sctp/stream.c b/net/sctp/stream.c
index cedf672487f9..f799043abec9 100644
--- a/net/sctp/stream.c
+++ b/net/sctp/stream.c
@@ -6,7 +6,7 @@
6 * 6 *
7 * This file is part of the SCTP kernel implementation 7 * This file is part of the SCTP kernel implementation
8 * 8 *
9 * These functions manipulate sctp tsn mapping array. 9 * This file contains sctp stream maniuplation primitives and helpers.
10 * 10 *
11 * This SCTP implementation is free software; 11 * This SCTP implementation is free software;
12 * you can redistribute it and/or modify it under the terms of 12 * you can redistribute it and/or modify it under the terms of
diff --git a/net/sctp/stream_interleave.c b/net/sctp/stream_interleave.c
index 8c7cf8f08711..d3764c181299 100644
--- a/net/sctp/stream_interleave.c
+++ b/net/sctp/stream_interleave.c
@@ -3,7 +3,8 @@
3 * 3 *
4 * This file is part of the SCTP kernel implementation 4 * This file is part of the SCTP kernel implementation
5 * 5 *
6 * These functions manipulate sctp stream queue/scheduling. 6 * These functions implement sctp stream message interleaving, mostly
7 * including I-DATA and I-FORWARD-TSN chunks process.
7 * 8 *
8 * This SCTP implementation is free software; 9 * This SCTP implementation is free software;
9 * you can redistribute it and/or modify it under the terms of 10 * you can redistribute it and/or modify it under the terms of
@@ -954,12 +955,8 @@ static void sctp_renege_events(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
954 __u32 freed = 0; 955 __u32 freed = 0;
955 __u16 needed; 956 __u16 needed;
956 957
957 if (chunk) { 958 needed = ntohs(chunk->chunk_hdr->length) -
958 needed = ntohs(chunk->chunk_hdr->length); 959 sizeof(struct sctp_idata_chunk);
959 needed -= sizeof(struct sctp_idata_chunk);
960 } else {
961 needed = SCTP_DEFAULT_MAXWINDOW;
962 }
963 960
964 if (skb_queue_empty(&asoc->base.sk->sk_receive_queue)) { 961 if (skb_queue_empty(&asoc->base.sk->sk_receive_queue)) {
965 freed = sctp_ulpq_renege_list(ulpq, &ulpq->lobby, needed); 962 freed = sctp_ulpq_renege_list(ulpq, &ulpq->lobby, needed);
@@ -971,9 +968,8 @@ static void sctp_renege_events(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
971 needed); 968 needed);
972 } 969 }
973 970
974 if (chunk && freed >= needed) 971 if (freed >= needed && sctp_ulpevent_idata(ulpq, chunk, gfp) <= 0)
975 if (sctp_ulpevent_idata(ulpq, chunk, gfp) <= 0) 972 sctp_intl_start_pd(ulpq, gfp);
976 sctp_intl_start_pd(ulpq, gfp);
977 973
978 sk_mem_reclaim(asoc->base.sk); 974 sk_mem_reclaim(asoc->base.sk);
979} 975}
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index da1a5cdefd13..1e0d780855c3 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -978,10 +978,6 @@ out:
978 lsmc->clcsock = NULL; 978 lsmc->clcsock = NULL;
979 } 979 }
980 release_sock(lsk); 980 release_sock(lsk);
981 /* no more listening, wake up smc_close_wait_listen_clcsock and
982 * accept
983 */
984 lsk->sk_state_change(lsk);
985 sock_put(&lsmc->sk); /* sock_hold in smc_listen */ 981 sock_put(&lsmc->sk); /* sock_hold in smc_listen */
986} 982}
987 983
@@ -1406,8 +1402,10 @@ static int smc_create(struct net *net, struct socket *sock, int protocol,
1406 smc->use_fallback = false; /* assume rdma capability first */ 1402 smc->use_fallback = false; /* assume rdma capability first */
1407 rc = sock_create_kern(net, PF_INET, SOCK_STREAM, 1403 rc = sock_create_kern(net, PF_INET, SOCK_STREAM,
1408 IPPROTO_TCP, &smc->clcsock); 1404 IPPROTO_TCP, &smc->clcsock);
1409 if (rc) 1405 if (rc) {
1410 sk_common_release(sk); 1406 sk_common_release(sk);
1407 goto out;
1408 }
1411 smc->sk.sk_sndbuf = max(smc->clcsock->sk->sk_sndbuf, SMC_BUF_MIN_SIZE); 1409 smc->sk.sk_sndbuf = max(smc->clcsock->sk->sk_sndbuf, SMC_BUF_MIN_SIZE);
1412 smc->sk.sk_rcvbuf = max(smc->clcsock->sk->sk_rcvbuf, SMC_BUF_MIN_SIZE); 1410 smc->sk.sk_rcvbuf = max(smc->clcsock->sk->sk_rcvbuf, SMC_BUF_MIN_SIZE);
1413 1411
diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
index 3cd086e5bd28..b42395d24cba 100644
--- a/net/smc/smc_cdc.c
+++ b/net/smc/smc_cdc.c
@@ -269,7 +269,7 @@ static void smc_cdc_rx_handler(struct ib_wc *wc, void *buf)
269 269
270 if (wc->byte_len < offsetof(struct smc_cdc_msg, reserved)) 270 if (wc->byte_len < offsetof(struct smc_cdc_msg, reserved))
271 return; /* short message */ 271 return; /* short message */
272 if (cdc->len != sizeof(*cdc)) 272 if (cdc->len != SMC_WR_TX_SIZE)
273 return; /* invalid message */ 273 return; /* invalid message */
274 smc_cdc_msg_recv(cdc, link, wc->wr_id); 274 smc_cdc_msg_recv(cdc, link, wc->wr_id);
275} 275}
diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c
index e339c0186dcf..fa41d9881741 100644
--- a/net/smc/smc_close.c
+++ b/net/smc/smc_close.c
@@ -30,27 +30,6 @@ static void smc_close_cleanup_listen(struct sock *parent)
30 smc_close_non_accepted(sk); 30 smc_close_non_accepted(sk);
31} 31}
32 32
33static void smc_close_wait_listen_clcsock(struct smc_sock *smc)
34{
35 DEFINE_WAIT_FUNC(wait, woken_wake_function);
36 struct sock *sk = &smc->sk;
37 signed long timeout;
38
39 timeout = SMC_CLOSE_WAIT_LISTEN_CLCSOCK_TIME;
40 add_wait_queue(sk_sleep(sk), &wait);
41 do {
42 release_sock(sk);
43 if (smc->clcsock)
44 timeout = wait_woken(&wait, TASK_UNINTERRUPTIBLE,
45 timeout);
46 sched_annotate_sleep();
47 lock_sock(sk);
48 if (!smc->clcsock)
49 break;
50 } while (timeout);
51 remove_wait_queue(sk_sleep(sk), &wait);
52}
53
54/* wait for sndbuf data being transmitted */ 33/* wait for sndbuf data being transmitted */
55static void smc_close_stream_wait(struct smc_sock *smc, long timeout) 34static void smc_close_stream_wait(struct smc_sock *smc, long timeout)
56{ 35{
@@ -204,9 +183,11 @@ again:
204 rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR); 183 rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR);
205 /* wake up kernel_accept of smc_tcp_listen_worker */ 184 /* wake up kernel_accept of smc_tcp_listen_worker */
206 smc->clcsock->sk->sk_data_ready(smc->clcsock->sk); 185 smc->clcsock->sk->sk_data_ready(smc->clcsock->sk);
207 smc_close_wait_listen_clcsock(smc);
208 } 186 }
209 smc_close_cleanup_listen(sk); 187 smc_close_cleanup_listen(sk);
188 release_sock(sk);
189 flush_work(&smc->tcp_listen_work);
190 lock_sock(sk);
210 break; 191 break;
211 case SMC_ACTIVE: 192 case SMC_ACTIVE:
212 smc_close_stream_wait(smc, timeout); 193 smc_close_stream_wait(smc, timeout);
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 2424c7100aaf..645dd226177b 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -177,6 +177,7 @@ static int smc_lgr_create(struct smc_sock *smc, __be32 peer_in_addr,
177 177
178 lnk = &lgr->lnk[SMC_SINGLE_LINK]; 178 lnk = &lgr->lnk[SMC_SINGLE_LINK];
179 /* initialize link */ 179 /* initialize link */
180 lnk->link_id = SMC_SINGLE_LINK;
180 lnk->smcibdev = smcibdev; 181 lnk->smcibdev = smcibdev;
181 lnk->ibport = ibport; 182 lnk->ibport = ibport;
182 lnk->path_mtu = smcibdev->pattr[ibport - 1].active_mtu; 183 lnk->path_mtu = smcibdev->pattr[ibport - 1].active_mtu;
@@ -465,7 +466,7 @@ create:
465 rc = smc_link_determine_gid(conn->lgr); 466 rc = smc_link_determine_gid(conn->lgr);
466 } 467 }
467 conn->local_tx_ctrl.common.type = SMC_CDC_MSG_TYPE; 468 conn->local_tx_ctrl.common.type = SMC_CDC_MSG_TYPE;
468 conn->local_tx_ctrl.len = sizeof(struct smc_cdc_msg); 469 conn->local_tx_ctrl.len = SMC_WR_TX_SIZE;
469#ifndef KERNEL_HAS_ATOMIC64 470#ifndef KERNEL_HAS_ATOMIC64
470 spin_lock_init(&conn->acurs_lock); 471 spin_lock_init(&conn->acurs_lock);
471#endif 472#endif
diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c
index 92fe4cc8c82c..b4aa4fcedb96 100644
--- a/net/smc/smc_llc.c
+++ b/net/smc/smc_llc.c
@@ -92,7 +92,7 @@ int smc_llc_send_confirm_link(struct smc_link *link, u8 mac[],
92 memcpy(confllc->sender_mac, mac, ETH_ALEN); 92 memcpy(confllc->sender_mac, mac, ETH_ALEN);
93 memcpy(confllc->sender_gid, gid, SMC_GID_SIZE); 93 memcpy(confllc->sender_gid, gid, SMC_GID_SIZE);
94 hton24(confllc->sender_qp_num, link->roce_qp->qp_num); 94 hton24(confllc->sender_qp_num, link->roce_qp->qp_num);
95 /* confllc->link_num = SMC_SINGLE_LINK; already done by memset above */ 95 confllc->link_num = link->link_id;
96 memcpy(confllc->link_uid, lgr->id, SMC_LGR_ID_SIZE); 96 memcpy(confllc->link_uid, lgr->id, SMC_LGR_ID_SIZE);
97 confllc->max_links = SMC_LINKS_PER_LGR_MAX; 97 confllc->max_links = SMC_LINKS_PER_LGR_MAX;
98 /* send llc message */ 98 /* send llc message */
diff --git a/net/socket.c b/net/socket.c
index a93c99b518ca..08847c3b8c39 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2587,6 +2587,11 @@ void sock_unregister(int family)
2587} 2587}
2588EXPORT_SYMBOL(sock_unregister); 2588EXPORT_SYMBOL(sock_unregister);
2589 2589
2590bool sock_is_registered(int family)
2591{
2592 return family < NPROTO && rcu_access_pointer(net_families[family]);
2593}
2594
2590static int __init sock_init(void) 2595static int __init sock_init(void)
2591{ 2596{
2592 int err; 2597 int err;
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index c8001471da6c..3e3dce3d4c63 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -813,7 +813,7 @@ err_out:
813 return err; 813 return err;
814} 814}
815 815
816int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info) 816int __tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
817{ 817{
818 int err; 818 int err;
819 char *name; 819 char *name;
@@ -835,20 +835,27 @@ int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
835 835
836 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); 836 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
837 837
838 rtnl_lock();
839 bearer = tipc_bearer_find(net, name); 838 bearer = tipc_bearer_find(net, name);
840 if (!bearer) { 839 if (!bearer)
841 rtnl_unlock();
842 return -EINVAL; 840 return -EINVAL;
843 }
844 841
845 bearer_disable(net, bearer); 842 bearer_disable(net, bearer);
846 rtnl_unlock();
847 843
848 return 0; 844 return 0;
849} 845}
850 846
851int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) 847int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
848{
849 int err;
850
851 rtnl_lock();
852 err = __tipc_nl_bearer_disable(skb, info);
853 rtnl_unlock();
854
855 return err;
856}
857
858int __tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
852{ 859{
853 int err; 860 int err;
854 char *bearer; 861 char *bearer;
@@ -890,15 +897,18 @@ int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
890 prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]); 897 prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
891 } 898 }
892 899
900 return tipc_enable_bearer(net, bearer, domain, prio, attrs);
901}
902
903int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
904{
905 int err;
906
893 rtnl_lock(); 907 rtnl_lock();
894 err = tipc_enable_bearer(net, bearer, domain, prio, attrs); 908 err = __tipc_nl_bearer_enable(skb, info);
895 if (err) {
896 rtnl_unlock();
897 return err;
898 }
899 rtnl_unlock(); 909 rtnl_unlock();
900 910
901 return 0; 911 return err;
902} 912}
903 913
904int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info) 914int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info)
@@ -944,7 +954,7 @@ int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info)
944 return 0; 954 return 0;
945} 955}
946 956
947int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info) 957int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
948{ 958{
949 int err; 959 int err;
950 char *name; 960 char *name;
@@ -965,22 +975,17 @@ int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
965 return -EINVAL; 975 return -EINVAL;
966 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); 976 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
967 977
968 rtnl_lock();
969 b = tipc_bearer_find(net, name); 978 b = tipc_bearer_find(net, name);
970 if (!b) { 979 if (!b)
971 rtnl_unlock();
972 return -EINVAL; 980 return -EINVAL;
973 }
974 981
975 if (attrs[TIPC_NLA_BEARER_PROP]) { 982 if (attrs[TIPC_NLA_BEARER_PROP]) {
976 struct nlattr *props[TIPC_NLA_PROP_MAX + 1]; 983 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
977 984
978 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_BEARER_PROP], 985 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_BEARER_PROP],
979 props); 986 props);
980 if (err) { 987 if (err)
981 rtnl_unlock();
982 return err; 988 return err;
983 }
984 989
985 if (props[TIPC_NLA_PROP_TOL]) 990 if (props[TIPC_NLA_PROP_TOL])
986 b->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]); 991 b->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
@@ -989,11 +994,21 @@ int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
989 if (props[TIPC_NLA_PROP_WIN]) 994 if (props[TIPC_NLA_PROP_WIN])
990 b->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]); 995 b->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
991 } 996 }
992 rtnl_unlock();
993 997
994 return 0; 998 return 0;
995} 999}
996 1000
1001int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
1002{
1003 int err;
1004
1005 rtnl_lock();
1006 err = __tipc_nl_bearer_set(skb, info);
1007 rtnl_unlock();
1008
1009 return err;
1010}
1011
997static int __tipc_nl_add_media(struct tipc_nl_msg *msg, 1012static int __tipc_nl_add_media(struct tipc_nl_msg *msg,
998 struct tipc_media *media, int nlflags) 1013 struct tipc_media *media, int nlflags)
999{ 1014{
@@ -1115,7 +1130,7 @@ err_out:
1115 return err; 1130 return err;
1116} 1131}
1117 1132
1118int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info) 1133int __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
1119{ 1134{
1120 int err; 1135 int err;
1121 char *name; 1136 char *name;
@@ -1133,22 +1148,17 @@ int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
1133 return -EINVAL; 1148 return -EINVAL;
1134 name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]); 1149 name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);
1135 1150
1136 rtnl_lock();
1137 m = tipc_media_find(name); 1151 m = tipc_media_find(name);
1138 if (!m) { 1152 if (!m)
1139 rtnl_unlock();
1140 return -EINVAL; 1153 return -EINVAL;
1141 }
1142 1154
1143 if (attrs[TIPC_NLA_MEDIA_PROP]) { 1155 if (attrs[TIPC_NLA_MEDIA_PROP]) {
1144 struct nlattr *props[TIPC_NLA_PROP_MAX + 1]; 1156 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
1145 1157
1146 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_MEDIA_PROP], 1158 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_MEDIA_PROP],
1147 props); 1159 props);
1148 if (err) { 1160 if (err)
1149 rtnl_unlock();
1150 return err; 1161 return err;
1151 }
1152 1162
1153 if (props[TIPC_NLA_PROP_TOL]) 1163 if (props[TIPC_NLA_PROP_TOL])
1154 m->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]); 1164 m->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
@@ -1157,7 +1167,17 @@ int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
1157 if (props[TIPC_NLA_PROP_WIN]) 1167 if (props[TIPC_NLA_PROP_WIN])
1158 m->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]); 1168 m->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
1159 } 1169 }
1160 rtnl_unlock();
1161 1170
1162 return 0; 1171 return 0;
1163} 1172}
1173
1174int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
1175{
1176 int err;
1177
1178 rtnl_lock();
1179 err = __tipc_nl_media_set(skb, info);
1180 rtnl_unlock();
1181
1182 return err;
1183}
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index 42d6eeeb646d..a53613d95bc9 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -188,15 +188,19 @@ extern struct tipc_media udp_media_info;
188#endif 188#endif
189 189
190int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info); 190int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info);
191int __tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info);
191int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info); 192int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info);
193int __tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info);
192int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb); 194int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb);
193int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info); 195int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info);
194int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info); 196int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info);
197int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info);
195int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info); 198int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info);
196 199
197int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb); 200int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb);
198int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info); 201int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info);
199int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info); 202int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info);
203int __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info);
200 204
201int tipc_media_set_priority(const char *name, u32 new_value); 205int tipc_media_set_priority(const char *name, u32 new_value);
202int tipc_media_set_window(const char *name, u32 new_value); 206int tipc_media_set_window(const char *name, u32 new_value);
diff --git a/net/tipc/group.c b/net/tipc/group.c
index 122162a31816..04e516d18054 100644
--- a/net/tipc/group.c
+++ b/net/tipc/group.c
@@ -189,6 +189,7 @@ struct tipc_group *tipc_group_create(struct net *net, u32 portid,
189 grp->loopback = mreq->flags & TIPC_GROUP_LOOPBACK; 189 grp->loopback = mreq->flags & TIPC_GROUP_LOOPBACK;
190 grp->events = mreq->flags & TIPC_GROUP_MEMBER_EVTS; 190 grp->events = mreq->flags & TIPC_GROUP_MEMBER_EVTS;
191 grp->open = group_is_open; 191 grp->open = group_is_open;
192 *grp->open = false;
192 filter |= global ? TIPC_SUB_CLUSTER_SCOPE : TIPC_SUB_NODE_SCOPE; 193 filter |= global ? TIPC_SUB_CLUSTER_SCOPE : TIPC_SUB_NODE_SCOPE;
193 if (tipc_topsrv_kern_subscr(net, portid, type, 0, ~0, 194 if (tipc_topsrv_kern_subscr(net, portid, type, 0, ~0,
194 filter, &grp->subid)) 195 filter, &grp->subid))
diff --git a/net/tipc/net.c b/net/tipc/net.c
index 719c5924b638..1a2fde0d6f61 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -200,7 +200,7 @@ out:
200 return skb->len; 200 return skb->len;
201} 201}
202 202
203int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) 203int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
204{ 204{
205 struct net *net = sock_net(skb->sk); 205 struct net *net = sock_net(skb->sk);
206 struct tipc_net *tn = net_generic(net, tipc_net_id); 206 struct tipc_net *tn = net_generic(net, tipc_net_id);
@@ -241,10 +241,19 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
241 if (!tipc_addr_node_valid(addr)) 241 if (!tipc_addr_node_valid(addr))
242 return -EINVAL; 242 return -EINVAL;
243 243
244 rtnl_lock();
245 tipc_net_start(net, addr); 244 tipc_net_start(net, addr);
246 rtnl_unlock();
247 } 245 }
248 246
249 return 0; 247 return 0;
250} 248}
249
250int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
251{
252 int err;
253
254 rtnl_lock();
255 err = __tipc_nl_net_set(skb, info);
256 rtnl_unlock();
257
258 return err;
259}
diff --git a/net/tipc/net.h b/net/tipc/net.h
index c7c254902873..c0306aa2374b 100644
--- a/net/tipc/net.h
+++ b/net/tipc/net.h
@@ -47,5 +47,6 @@ void tipc_net_stop(struct net *net);
47 47
48int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb); 48int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb);
49int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info); 49int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info);
50int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info);
50 51
51#endif 52#endif
diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c
index e48f0b2c01b9..4492cda45566 100644
--- a/net/tipc/netlink_compat.c
+++ b/net/tipc/netlink_compat.c
@@ -285,10 +285,6 @@ static int __tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
285 if (!trans_buf) 285 if (!trans_buf)
286 return -ENOMEM; 286 return -ENOMEM;
287 287
288 err = (*cmd->transcode)(cmd, trans_buf, msg);
289 if (err)
290 goto trans_out;
291
292 attrbuf = kmalloc((tipc_genl_family.maxattr + 1) * 288 attrbuf = kmalloc((tipc_genl_family.maxattr + 1) *
293 sizeof(struct nlattr *), GFP_KERNEL); 289 sizeof(struct nlattr *), GFP_KERNEL);
294 if (!attrbuf) { 290 if (!attrbuf) {
@@ -296,27 +292,34 @@ static int __tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
296 goto trans_out; 292 goto trans_out;
297 } 293 }
298 294
299 err = nla_parse(attrbuf, tipc_genl_family.maxattr,
300 (const struct nlattr *)trans_buf->data,
301 trans_buf->len, NULL, NULL);
302 if (err)
303 goto parse_out;
304
305 doit_buf = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); 295 doit_buf = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
306 if (!doit_buf) { 296 if (!doit_buf) {
307 err = -ENOMEM; 297 err = -ENOMEM;
308 goto parse_out; 298 goto attrbuf_out;
309 } 299 }
310 300
311 doit_buf->sk = msg->dst_sk;
312
313 memset(&info, 0, sizeof(info)); 301 memset(&info, 0, sizeof(info));
314 info.attrs = attrbuf; 302 info.attrs = attrbuf;
315 303
304 rtnl_lock();
305 err = (*cmd->transcode)(cmd, trans_buf, msg);
306 if (err)
307 goto doit_out;
308
309 err = nla_parse(attrbuf, tipc_genl_family.maxattr,
310 (const struct nlattr *)trans_buf->data,
311 trans_buf->len, NULL, NULL);
312 if (err)
313 goto doit_out;
314
315 doit_buf->sk = msg->dst_sk;
316
316 err = (*cmd->doit)(doit_buf, &info); 317 err = (*cmd->doit)(doit_buf, &info);
318doit_out:
319 rtnl_unlock();
317 320
318 kfree_skb(doit_buf); 321 kfree_skb(doit_buf);
319parse_out: 322attrbuf_out:
320 kfree(attrbuf); 323 kfree(attrbuf);
321trans_out: 324trans_out:
322 kfree_skb(trans_buf); 325 kfree_skb(trans_buf);
@@ -722,13 +725,13 @@ static int tipc_nl_compat_link_set(struct tipc_nl_compat_cmd_doit *cmd,
722 725
723 media = tipc_media_find(lc->name); 726 media = tipc_media_find(lc->name);
724 if (media) { 727 if (media) {
725 cmd->doit = &tipc_nl_media_set; 728 cmd->doit = &__tipc_nl_media_set;
726 return tipc_nl_compat_media_set(skb, msg); 729 return tipc_nl_compat_media_set(skb, msg);
727 } 730 }
728 731
729 bearer = tipc_bearer_find(msg->net, lc->name); 732 bearer = tipc_bearer_find(msg->net, lc->name);
730 if (bearer) { 733 if (bearer) {
731 cmd->doit = &tipc_nl_bearer_set; 734 cmd->doit = &__tipc_nl_bearer_set;
732 return tipc_nl_compat_bearer_set(skb, msg); 735 return tipc_nl_compat_bearer_set(skb, msg);
733 } 736 }
734 737
@@ -1089,12 +1092,12 @@ static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
1089 return tipc_nl_compat_dumpit(&dump, msg); 1092 return tipc_nl_compat_dumpit(&dump, msg);
1090 case TIPC_CMD_ENABLE_BEARER: 1093 case TIPC_CMD_ENABLE_BEARER:
1091 msg->req_type = TIPC_TLV_BEARER_CONFIG; 1094 msg->req_type = TIPC_TLV_BEARER_CONFIG;
1092 doit.doit = tipc_nl_bearer_enable; 1095 doit.doit = __tipc_nl_bearer_enable;
1093 doit.transcode = tipc_nl_compat_bearer_enable; 1096 doit.transcode = tipc_nl_compat_bearer_enable;
1094 return tipc_nl_compat_doit(&doit, msg); 1097 return tipc_nl_compat_doit(&doit, msg);
1095 case TIPC_CMD_DISABLE_BEARER: 1098 case TIPC_CMD_DISABLE_BEARER:
1096 msg->req_type = TIPC_TLV_BEARER_NAME; 1099 msg->req_type = TIPC_TLV_BEARER_NAME;
1097 doit.doit = tipc_nl_bearer_disable; 1100 doit.doit = __tipc_nl_bearer_disable;
1098 doit.transcode = tipc_nl_compat_bearer_disable; 1101 doit.transcode = tipc_nl_compat_bearer_disable;
1099 return tipc_nl_compat_doit(&doit, msg); 1102 return tipc_nl_compat_doit(&doit, msg);
1100 case TIPC_CMD_SHOW_LINK_STATS: 1103 case TIPC_CMD_SHOW_LINK_STATS:
@@ -1148,12 +1151,12 @@ static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
1148 return tipc_nl_compat_dumpit(&dump, msg); 1151 return tipc_nl_compat_dumpit(&dump, msg);
1149 case TIPC_CMD_SET_NODE_ADDR: 1152 case TIPC_CMD_SET_NODE_ADDR:
1150 msg->req_type = TIPC_TLV_NET_ADDR; 1153 msg->req_type = TIPC_TLV_NET_ADDR;
1151 doit.doit = tipc_nl_net_set; 1154 doit.doit = __tipc_nl_net_set;
1152 doit.transcode = tipc_nl_compat_net_set; 1155 doit.transcode = tipc_nl_compat_net_set;
1153 return tipc_nl_compat_doit(&doit, msg); 1156 return tipc_nl_compat_doit(&doit, msg);
1154 case TIPC_CMD_SET_NETID: 1157 case TIPC_CMD_SET_NETID:
1155 msg->req_type = TIPC_TLV_UNSIGNED; 1158 msg->req_type = TIPC_TLV_UNSIGNED;
1156 doit.doit = tipc_nl_net_set; 1159 doit.doit = __tipc_nl_net_set;
1157 doit.transcode = tipc_nl_compat_net_set; 1160 doit.transcode = tipc_nl_compat_net_set;
1158 return tipc_nl_compat_doit(&doit, msg); 1161 return tipc_nl_compat_doit(&doit, msg);
1159 case TIPC_CMD_GET_NETID: 1162 case TIPC_CMD_GET_NETID:
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index b0323ec7971e..7dfa9fc99ec3 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -473,6 +473,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
473 sk->sk_write_space = tipc_write_space; 473 sk->sk_write_space = tipc_write_space;
474 sk->sk_destruct = tipc_sock_destruct; 474 sk->sk_destruct = tipc_sock_destruct;
475 tsk->conn_timeout = CONN_TIMEOUT_DEFAULT; 475 tsk->conn_timeout = CONN_TIMEOUT_DEFAULT;
476 tsk->group_is_open = true;
476 atomic_set(&tsk->dupl_rcvcnt, 0); 477 atomic_set(&tsk->dupl_rcvcnt, 0);
477 478
478 /* Start out with safe limits until we receive an advertised window */ 479 /* Start out with safe limits until we receive an advertised window */
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index b0d5fcea47e7..d824d548447e 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -46,16 +46,26 @@ MODULE_DESCRIPTION("Transport Layer Security Support");
46MODULE_LICENSE("Dual BSD/GPL"); 46MODULE_LICENSE("Dual BSD/GPL");
47 47
48enum { 48enum {
49 TLSV4,
50 TLSV6,
51 TLS_NUM_PROTS,
52};
53
54enum {
49 TLS_BASE_TX, 55 TLS_BASE_TX,
50 TLS_SW_TX, 56 TLS_SW_TX,
51 TLS_NUM_CONFIG, 57 TLS_NUM_CONFIG,
52}; 58};
53 59
54static struct proto tls_prots[TLS_NUM_CONFIG]; 60static struct proto *saved_tcpv6_prot;
61static DEFINE_MUTEX(tcpv6_prot_mutex);
62static struct proto tls_prots[TLS_NUM_PROTS][TLS_NUM_CONFIG];
55 63
56static inline void update_sk_prot(struct sock *sk, struct tls_context *ctx) 64static inline void update_sk_prot(struct sock *sk, struct tls_context *ctx)
57{ 65{
58 sk->sk_prot = &tls_prots[ctx->tx_conf]; 66 int ip_ver = sk->sk_family == AF_INET6 ? TLSV6 : TLSV4;
67
68 sk->sk_prot = &tls_prots[ip_ver][ctx->tx_conf];
59} 69}
60 70
61int wait_on_pending_writer(struct sock *sk, long *timeo) 71int wait_on_pending_writer(struct sock *sk, long *timeo)
@@ -308,8 +318,11 @@ static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval,
308 goto out; 318 goto out;
309 } 319 }
310 lock_sock(sk); 320 lock_sock(sk);
311 memcpy(crypto_info_aes_gcm_128->iv, ctx->iv, 321 memcpy(crypto_info_aes_gcm_128->iv,
322 ctx->iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE,
312 TLS_CIPHER_AES_GCM_128_IV_SIZE); 323 TLS_CIPHER_AES_GCM_128_IV_SIZE);
324 memcpy(crypto_info_aes_gcm_128->rec_seq, ctx->rec_seq,
325 TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
313 release_sock(sk); 326 release_sock(sk);
314 if (copy_to_user(optval, 327 if (copy_to_user(optval,
315 crypto_info_aes_gcm_128, 328 crypto_info_aes_gcm_128,
@@ -375,7 +388,7 @@ static int do_tls_setsockopt_tx(struct sock *sk, char __user *optval,
375 rc = copy_from_user(crypto_info, optval, sizeof(*crypto_info)); 388 rc = copy_from_user(crypto_info, optval, sizeof(*crypto_info));
376 if (rc) { 389 if (rc) {
377 rc = -EFAULT; 390 rc = -EFAULT;
378 goto out; 391 goto err_crypto_info;
379 } 392 }
380 393
381 /* check version */ 394 /* check version */
@@ -450,8 +463,21 @@ static int tls_setsockopt(struct sock *sk, int level, int optname,
450 return do_tls_setsockopt(sk, optname, optval, optlen); 463 return do_tls_setsockopt(sk, optname, optval, optlen);
451} 464}
452 465
466static void build_protos(struct proto *prot, struct proto *base)
467{
468 prot[TLS_BASE_TX] = *base;
469 prot[TLS_BASE_TX].setsockopt = tls_setsockopt;
470 prot[TLS_BASE_TX].getsockopt = tls_getsockopt;
471 prot[TLS_BASE_TX].close = tls_sk_proto_close;
472
473 prot[TLS_SW_TX] = prot[TLS_BASE_TX];
474 prot[TLS_SW_TX].sendmsg = tls_sw_sendmsg;
475 prot[TLS_SW_TX].sendpage = tls_sw_sendpage;
476}
477
453static int tls_init(struct sock *sk) 478static int tls_init(struct sock *sk)
454{ 479{
480 int ip_ver = sk->sk_family == AF_INET6 ? TLSV6 : TLSV4;
455 struct inet_connection_sock *icsk = inet_csk(sk); 481 struct inet_connection_sock *icsk = inet_csk(sk);
456 struct tls_context *ctx; 482 struct tls_context *ctx;
457 int rc = 0; 483 int rc = 0;
@@ -476,6 +502,17 @@ static int tls_init(struct sock *sk)
476 ctx->getsockopt = sk->sk_prot->getsockopt; 502 ctx->getsockopt = sk->sk_prot->getsockopt;
477 ctx->sk_proto_close = sk->sk_prot->close; 503 ctx->sk_proto_close = sk->sk_prot->close;
478 504
505 /* Build IPv6 TLS whenever the address of tcpv6_prot changes */
506 if (ip_ver == TLSV6 &&
507 unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv6_prot))) {
508 mutex_lock(&tcpv6_prot_mutex);
509 if (likely(sk->sk_prot != saved_tcpv6_prot)) {
510 build_protos(tls_prots[TLSV6], sk->sk_prot);
511 smp_store_release(&saved_tcpv6_prot, sk->sk_prot);
512 }
513 mutex_unlock(&tcpv6_prot_mutex);
514 }
515
479 ctx->tx_conf = TLS_BASE_TX; 516 ctx->tx_conf = TLS_BASE_TX;
480 update_sk_prot(sk, ctx); 517 update_sk_prot(sk, ctx);
481out: 518out:
@@ -490,21 +527,9 @@ static struct tcp_ulp_ops tcp_tls_ulp_ops __read_mostly = {
490 .init = tls_init, 527 .init = tls_init,
491}; 528};
492 529
493static void build_protos(struct proto *prot, struct proto *base)
494{
495 prot[TLS_BASE_TX] = *base;
496 prot[TLS_BASE_TX].setsockopt = tls_setsockopt;
497 prot[TLS_BASE_TX].getsockopt = tls_getsockopt;
498 prot[TLS_BASE_TX].close = tls_sk_proto_close;
499
500 prot[TLS_SW_TX] = prot[TLS_BASE_TX];
501 prot[TLS_SW_TX].sendmsg = tls_sw_sendmsg;
502 prot[TLS_SW_TX].sendpage = tls_sw_sendpage;
503}
504
505static int __init tls_register(void) 530static int __init tls_register(void)
506{ 531{
507 build_protos(tls_prots, &tcp_prot); 532 build_protos(tls_prots[TLSV4], &tcp_prot);
508 533
509 tcp_register_ulp(&tcp_tls_ulp_ops); 534 tcp_register_ulp(&tcp_tls_ulp_ops);
510 535
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index d545e1d0dea2..2d465bdeccbc 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1825,7 +1825,7 @@ out:
1825} 1825}
1826 1826
1827/* We use paged skbs for stream sockets, and limit occupancy to 32768 1827/* We use paged skbs for stream sockets, and limit occupancy to 32768
1828 * bytes, and a minimun of a full page. 1828 * bytes, and a minimum of a full page.
1829 */ 1829 */
1830#define UNIX_SKB_FRAGS_SZ (PAGE_SIZE << get_order(32768)) 1830#define UNIX_SKB_FRAGS_SZ (PAGE_SIZE << get_order(32768))
1831 1831
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig
index 1abcc4fc4df1..41722046b937 100644
--- a/net/wireless/Kconfig
+++ b/net/wireless/Kconfig
@@ -34,9 +34,10 @@ config CFG80211
34 34
35 When built as a module it will be called cfg80211. 35 When built as a module it will be called cfg80211.
36 36
37if CFG80211
38
37config NL80211_TESTMODE 39config NL80211_TESTMODE
38 bool "nl80211 testmode command" 40 bool "nl80211 testmode command"
39 depends on CFG80211
40 help 41 help
41 The nl80211 testmode command helps implementing things like 42 The nl80211 testmode command helps implementing things like
42 factory calibration or validation tools for wireless chips. 43 factory calibration or validation tools for wireless chips.
@@ -51,7 +52,6 @@ config NL80211_TESTMODE
51 52
52config CFG80211_DEVELOPER_WARNINGS 53config CFG80211_DEVELOPER_WARNINGS
53 bool "enable developer warnings" 54 bool "enable developer warnings"
54 depends on CFG80211
55 default n 55 default n
56 help 56 help
57 This option enables some additional warnings that help 57 This option enables some additional warnings that help
@@ -68,7 +68,7 @@ config CFG80211_DEVELOPER_WARNINGS
68 68
69config CFG80211_CERTIFICATION_ONUS 69config CFG80211_CERTIFICATION_ONUS
70 bool "cfg80211 certification onus" 70 bool "cfg80211 certification onus"
71 depends on CFG80211 && EXPERT 71 depends on EXPERT
72 default n 72 default n
73 ---help--- 73 ---help---
74 You should disable this option unless you are both capable 74 You should disable this option unless you are both capable
@@ -159,7 +159,6 @@ config CFG80211_REG_RELAX_NO_IR
159 159
160config CFG80211_DEFAULT_PS 160config CFG80211_DEFAULT_PS
161 bool "enable powersave by default" 161 bool "enable powersave by default"
162 depends on CFG80211
163 default y 162 default y
164 help 163 help
165 This option enables powersave mode by default. 164 This option enables powersave mode by default.
@@ -170,7 +169,6 @@ config CFG80211_DEFAULT_PS
170 169
171config CFG80211_DEBUGFS 170config CFG80211_DEBUGFS
172 bool "cfg80211 DebugFS entries" 171 bool "cfg80211 DebugFS entries"
173 depends on CFG80211
174 depends on DEBUG_FS 172 depends on DEBUG_FS
175 ---help--- 173 ---help---
176 You can enable this if you want debugfs entries for cfg80211. 174 You can enable this if you want debugfs entries for cfg80211.
@@ -180,7 +178,6 @@ config CFG80211_DEBUGFS
180config CFG80211_CRDA_SUPPORT 178config CFG80211_CRDA_SUPPORT
181 bool "support CRDA" if EXPERT 179 bool "support CRDA" if EXPERT
182 default y 180 default y
183 depends on CFG80211
184 help 181 help
185 You should enable this option unless you know for sure you have no 182 You should enable this option unless you know for sure you have no
186 need for it, for example when using internal regdb (above) or the 183 need for it, for example when using internal regdb (above) or the
@@ -190,7 +187,6 @@ config CFG80211_CRDA_SUPPORT
190 187
191config CFG80211_WEXT 188config CFG80211_WEXT
192 bool "cfg80211 wireless extensions compatibility" if !CFG80211_WEXT_EXPORT 189 bool "cfg80211 wireless extensions compatibility" if !CFG80211_WEXT_EXPORT
193 depends on CFG80211
194 select WEXT_CORE 190 select WEXT_CORE
195 default y if CFG80211_WEXT_EXPORT 191 default y if CFG80211_WEXT_EXPORT
196 help 192 help
@@ -199,11 +195,12 @@ config CFG80211_WEXT
199 195
200config CFG80211_WEXT_EXPORT 196config CFG80211_WEXT_EXPORT
201 bool 197 bool
202 depends on CFG80211
203 help 198 help
204 Drivers should select this option if they require cfg80211's 199 Drivers should select this option if they require cfg80211's
205 wext compatibility symbols to be exported. 200 wext compatibility symbols to be exported.
206 201
202endif # CFG80211
203
207config LIB80211 204config LIB80211
208 tristate 205 tristate
209 default n 206 default n
diff --git a/net/wireless/mesh.c b/net/wireless/mesh.c
index 51aa55618ef7..b12da6ef3c12 100644
--- a/net/wireless/mesh.c
+++ b/net/wireless/mesh.c
@@ -170,9 +170,28 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
170 enum nl80211_bss_scan_width scan_width; 170 enum nl80211_bss_scan_width scan_width;
171 struct ieee80211_supported_band *sband = 171 struct ieee80211_supported_band *sband =
172 rdev->wiphy.bands[setup->chandef.chan->band]; 172 rdev->wiphy.bands[setup->chandef.chan->band];
173 scan_width = cfg80211_chandef_to_scan_width(&setup->chandef); 173
174 setup->basic_rates = ieee80211_mandatory_rates(sband, 174 if (setup->chandef.chan->band == NL80211_BAND_2GHZ) {
175 scan_width); 175 int i;
176
177 /*
178 * Older versions selected the mandatory rates for
179 * 2.4 GHz as well, but were broken in that only
180 * 1 Mbps was regarded as a mandatory rate. Keep
181 * using just 1 Mbps as the default basic rate for
182 * mesh to be interoperable with older versions.
183 */
184 for (i = 0; i < sband->n_bitrates; i++) {
185 if (sband->bitrates[i].bitrate == 10) {
186 setup->basic_rates = BIT(i);
187 break;
188 }
189 }
190 } else {
191 scan_width = cfg80211_chandef_to_scan_width(&setup->chandef);
192 setup->basic_rates = ieee80211_mandatory_rates(sband,
193 scan_width);
194 }
176 } 195 }
177 196
178 err = cfg80211_chandef_dfs_required(&rdev->wiphy, 197 err = cfg80211_chandef_dfs_required(&rdev->wiphy,
diff --git a/net/wireless/sme.c b/net/wireless/sme.c
index fdb3646274a5..701cfd7acc1b 100644
--- a/net/wireless/sme.c
+++ b/net/wireless/sme.c
@@ -1032,6 +1032,8 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
1032 wdev->current_bss = NULL; 1032 wdev->current_bss = NULL;
1033 wdev->ssid_len = 0; 1033 wdev->ssid_len = 0;
1034 wdev->conn_owner_nlportid = 0; 1034 wdev->conn_owner_nlportid = 0;
1035 kzfree(wdev->connect_keys);
1036 wdev->connect_keys = NULL;
1035 1037
1036 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap); 1038 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
1037 1039
diff --git a/net/xfrm/xfrm_device.c b/net/xfrm/xfrm_device.c
index 8e70291e586a..e87d6c4dd5b6 100644
--- a/net/xfrm/xfrm_device.c
+++ b/net/xfrm/xfrm_device.c
@@ -217,7 +217,7 @@ bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x)
217 if (skb->len <= mtu) 217 if (skb->len <= mtu)
218 goto ok; 218 goto ok;
219 219
220 if (skb_is_gso(skb) && skb_gso_validate_mtu(skb, mtu)) 220 if (skb_is_gso(skb) && skb_gso_validate_network_len(skb, mtu))
221 goto ok; 221 goto ok;
222 } 222 }
223 223
diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index ccfdc7115a83..a00ec715aa46 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -283,7 +283,7 @@ static struct crypto_comp * __percpu *ipcomp_alloc_tfms(const char *alg_name)
283 struct crypto_comp *tfm; 283 struct crypto_comp *tfm;
284 284
285 /* This can be any valid CPU ID so we don't need locking. */ 285 /* This can be any valid CPU ID so we don't need locking. */
286 tfm = __this_cpu_read(*pos->tfms); 286 tfm = this_cpu_read(*pos->tfms);
287 287
288 if (!strcmp(crypto_comp_name(tfm), alg_name)) { 288 if (!strcmp(crypto_comp_name(tfm), alg_name)) {
289 pos->users++; 289 pos->users++;
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 7a23078132cf..625b3fca5704 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1458,10 +1458,13 @@ xfrm_tmpl_resolve(struct xfrm_policy **pols, int npols, const struct flowi *fl,
1458static int xfrm_get_tos(const struct flowi *fl, int family) 1458static int xfrm_get_tos(const struct flowi *fl, int family)
1459{ 1459{
1460 const struct xfrm_policy_afinfo *afinfo; 1460 const struct xfrm_policy_afinfo *afinfo;
1461 int tos = 0; 1461 int tos;
1462 1462
1463 afinfo = xfrm_policy_get_afinfo(family); 1463 afinfo = xfrm_policy_get_afinfo(family);
1464 tos = afinfo ? afinfo->get_tos(fl) : 0; 1464 if (!afinfo)
1465 return 0;
1466
1467 tos = afinfo->get_tos(fl);
1465 1468
1466 rcu_read_unlock(); 1469 rcu_read_unlock();
1467 1470
@@ -1891,7 +1894,7 @@ static void xfrm_policy_queue_process(struct timer_list *t)
1891 spin_unlock(&pq->hold_queue.lock); 1894 spin_unlock(&pq->hold_queue.lock);
1892 1895
1893 dst_hold(xfrm_dst_path(dst)); 1896 dst_hold(xfrm_dst_path(dst));
1894 dst = xfrm_lookup(net, xfrm_dst_path(dst), &fl, sk, 0); 1897 dst = xfrm_lookup(net, xfrm_dst_path(dst), &fl, sk, XFRM_LOOKUP_QUEUE);
1895 if (IS_ERR(dst)) 1898 if (IS_ERR(dst))
1896 goto purge_queue; 1899 goto purge_queue;
1897 1900
@@ -2729,14 +2732,14 @@ static const void *xfrm_get_dst_nexthop(const struct dst_entry *dst,
2729 while (dst->xfrm) { 2732 while (dst->xfrm) {
2730 const struct xfrm_state *xfrm = dst->xfrm; 2733 const struct xfrm_state *xfrm = dst->xfrm;
2731 2734
2735 dst = xfrm_dst_child(dst);
2736
2732 if (xfrm->props.mode == XFRM_MODE_TRANSPORT) 2737 if (xfrm->props.mode == XFRM_MODE_TRANSPORT)
2733 continue; 2738 continue;
2734 if (xfrm->type->flags & XFRM_TYPE_REMOTE_COADDR) 2739 if (xfrm->type->flags & XFRM_TYPE_REMOTE_COADDR)
2735 daddr = xfrm->coaddr; 2740 daddr = xfrm->coaddr;
2736 else if (!(xfrm->type->flags & XFRM_TYPE_LOCAL_COADDR)) 2741 else if (!(xfrm->type->flags & XFRM_TYPE_LOCAL_COADDR))
2737 daddr = &xfrm->id.daddr; 2742 daddr = &xfrm->id.daddr;
2738
2739 dst = xfrm_dst_child(dst);
2740 } 2743 }
2741 return daddr; 2744 return daddr;
2742} 2745}
diff --git a/net/xfrm/xfrm_replay.c b/net/xfrm/xfrm_replay.c
index 1d38c6acf8af..9e3a5e85f828 100644
--- a/net/xfrm/xfrm_replay.c
+++ b/net/xfrm/xfrm_replay.c
@@ -660,7 +660,7 @@ static int xfrm_replay_overflow_offload_esn(struct xfrm_state *x, struct sk_buff
660 } else { 660 } else {
661 XFRM_SKB_CB(skb)->seq.output.low = oseq + 1; 661 XFRM_SKB_CB(skb)->seq.output.low = oseq + 1;
662 XFRM_SKB_CB(skb)->seq.output.hi = oseq_hi; 662 XFRM_SKB_CB(skb)->seq.output.hi = oseq_hi;
663 xo->seq.low = oseq = oseq + 1; 663 xo->seq.low = oseq + 1;
664 xo->seq.hi = oseq_hi; 664 xo->seq.hi = oseq_hi;
665 oseq += skb_shinfo(skb)->gso_segs; 665 oseq += skb_shinfo(skb)->gso_segs;
666 } 666 }
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 54e21f19d722..f9d2f2233f09 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -2056,6 +2056,11 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
2056 struct xfrm_mgr *km; 2056 struct xfrm_mgr *km;
2057 struct xfrm_policy *pol = NULL; 2057 struct xfrm_policy *pol = NULL;
2058 2058
2059#ifdef CONFIG_COMPAT
2060 if (in_compat_syscall())
2061 return -EOPNOTSUPP;
2062#endif
2063
2059 if (!optval && !optlen) { 2064 if (!optval && !optlen) {
2060 xfrm_sk_policy_insert(sk, XFRM_POLICY_IN, NULL); 2065 xfrm_sk_policy_insert(sk, XFRM_POLICY_IN, NULL);
2061 xfrm_sk_policy_insert(sk, XFRM_POLICY_OUT, NULL); 2066 xfrm_sk_policy_insert(sk, XFRM_POLICY_OUT, NULL);
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 7f52b8eb177d..080035f056d9 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -121,22 +121,17 @@ static inline int verify_replay(struct xfrm_usersa_info *p,
121 struct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL]; 121 struct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL];
122 struct xfrm_replay_state_esn *rs; 122 struct xfrm_replay_state_esn *rs;
123 123
124 if (p->flags & XFRM_STATE_ESN) { 124 if (!rt)
125 if (!rt) 125 return (p->flags & XFRM_STATE_ESN) ? -EINVAL : 0;
126 return -EINVAL;
127 126
128 rs = nla_data(rt); 127 rs = nla_data(rt);
129 128
130 if (rs->bmp_len > XFRMA_REPLAY_ESN_MAX / sizeof(rs->bmp[0]) / 8) 129 if (rs->bmp_len > XFRMA_REPLAY_ESN_MAX / sizeof(rs->bmp[0]) / 8)
131 return -EINVAL; 130 return -EINVAL;
132
133 if (nla_len(rt) < (int)xfrm_replay_state_esn_len(rs) &&
134 nla_len(rt) != sizeof(*rs))
135 return -EINVAL;
136 }
137 131
138 if (!rt) 132 if (nla_len(rt) < (int)xfrm_replay_state_esn_len(rs) &&
139 return 0; 133 nla_len(rt) != sizeof(*rs))
134 return -EINVAL;
140 135
141 /* As only ESP and AH support ESN feature. */ 136 /* As only ESP and AH support ESN feature. */
142 if ((p->id.proto != IPPROTO_ESP) && (p->id.proto != IPPROTO_AH)) 137 if ((p->id.proto != IPPROTO_ESP) && (p->id.proto != IPPROTO_AH))
diff --git a/samples/seccomp/Makefile b/samples/seccomp/Makefile
index 0e349b80686e..ba942e3ead89 100644
--- a/samples/seccomp/Makefile
+++ b/samples/seccomp/Makefile
@@ -1,4 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2ifndef CROSS_COMPILE
2hostprogs-$(CONFIG_SAMPLE_SECCOMP) := bpf-fancy dropper bpf-direct 3hostprogs-$(CONFIG_SAMPLE_SECCOMP) := bpf-fancy dropper bpf-direct
3 4
4HOSTCFLAGS_bpf-fancy.o += -I$(objtree)/usr/include 5HOSTCFLAGS_bpf-fancy.o += -I$(objtree)/usr/include
@@ -16,7 +17,6 @@ HOSTCFLAGS_bpf-direct.o += -idirafter $(objtree)/include
16bpf-direct-objs := bpf-direct.o 17bpf-direct-objs := bpf-direct.o
17 18
18# Try to match the kernel target. 19# Try to match the kernel target.
19ifndef CROSS_COMPILE
20ifndef CONFIG_64BIT 20ifndef CONFIG_64BIT
21 21
22# s390 has -m31 flag to build 31 bit binaries 22# s390 has -m31 flag to build 31 bit binaries
@@ -35,12 +35,4 @@ HOSTLOADLIBES_bpf-fancy += $(MFLAG)
35HOSTLOADLIBES_dropper += $(MFLAG) 35HOSTLOADLIBES_dropper += $(MFLAG)
36endif 36endif
37always := $(hostprogs-m) 37always := $(hostprogs-m)
38else
39# MIPS system calls are defined based on the -mabi that is passed
40# to the toolchain which may or may not be a valid option
41# for the host toolchain. So disable tests if target architecture
42# is MIPS but the host isn't.
43ifndef CONFIG_MIPS
44always := $(hostprogs-m)
45endif
46endif 38endif
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 47cddf32aeba..4f2b25d43ec9 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -256,6 +256,8 @@ __objtool_obj := $(objtree)/tools/objtool/objtool
256 256
257objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check) 257objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check)
258 258
259objtool_args += $(if $(part-of-module), --module,)
260
259ifndef CONFIG_FRAME_POINTER 261ifndef CONFIG_FRAME_POINTER
260objtool_args += --no-fp 262objtool_args += --no-fp
261endif 263endif
@@ -264,6 +266,12 @@ objtool_args += --no-unreachable
264else 266else
265objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable) 267objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable)
266endif 268endif
269ifdef CONFIG_RETPOLINE
270ifneq ($(RETPOLINE_CFLAGS),)
271 objtool_args += --retpoline
272endif
273endif
274
267 275
268ifdef CONFIG_MODVERSIONS 276ifdef CONFIG_MODVERSIONS
269objtool_o = $(@D)/.tmp_$(@F) 277objtool_o = $(@D)/.tmp_$(@F)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 5589bae34af6..a6f538b31ad6 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -297,11 +297,11 @@ cmd_dt_S_dtb= \
297 echo '\#include <asm-generic/vmlinux.lds.h>'; \ 297 echo '\#include <asm-generic/vmlinux.lds.h>'; \
298 echo '.section .dtb.init.rodata,"a"'; \ 298 echo '.section .dtb.init.rodata,"a"'; \
299 echo '.balign STRUCT_ALIGNMENT'; \ 299 echo '.balign STRUCT_ALIGNMENT'; \
300 echo '.global __dtb_$(*F)_begin'; \ 300 echo '.global __dtb_$(subst -,_,$(*F))_begin'; \
301 echo '__dtb_$(*F)_begin:'; \ 301 echo '__dtb_$(subst -,_,$(*F))_begin:'; \
302 echo '.incbin "$<" '; \ 302 echo '.incbin "$<" '; \
303 echo '__dtb_$(*F)_end:'; \ 303 echo '__dtb_$(subst -,_,$(*F))_end:'; \
304 echo '.global __dtb_$(*F)_end'; \ 304 echo '.global __dtb_$(subst -,_,$(*F))_end'; \
305 echo '.balign STRUCT_ALIGNMENT'; \ 305 echo '.balign STRUCT_ALIGNMENT'; \
306) > $@ 306) > $@
307 307
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index fa3d39b6f23b..449b68c4c90c 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -93,14 +93,6 @@
93 * (Note: it'd be easy to port over the complete mkdep state machine, 93 * (Note: it'd be easy to port over the complete mkdep state machine,
94 * but I don't think the added complexity is worth it) 94 * but I don't think the added complexity is worth it)
95 */ 95 */
96/*
97 * Note 2: if somebody writes HELLO_CONFIG_BOOM in a file, it will depend onto
98 * CONFIG_BOOM. This could seem a bug (not too hard to fix), but please do not
99 * fix it! Some UserModeLinux files (look at arch/um/) call CONFIG_BOOM as
100 * UML_CONFIG_BOOM, to avoid conflicts with /usr/include/linux/autoconf.h,
101 * through arch/um/include/uml-config.h; this fixdep "bug" makes sure that
102 * those files will have correct dependencies.
103 */
104 96
105#include <sys/types.h> 97#include <sys/types.h>
106#include <sys/stat.h> 98#include <sys/stat.h>
@@ -233,8 +225,13 @@ static int str_ends_with(const char *s, int slen, const char *sub)
233static void parse_config_file(const char *p) 225static void parse_config_file(const char *p)
234{ 226{
235 const char *q, *r; 227 const char *q, *r;
228 const char *start = p;
236 229
237 while ((p = strstr(p, "CONFIG_"))) { 230 while ((p = strstr(p, "CONFIG_"))) {
231 if (p > start && (isalnum(p[-1]) || p[-1] == '_')) {
232 p += 7;
233 continue;
234 }
238 p += 7; 235 p += 7;
239 q = p; 236 q = p;
240 while (*q && (isalnum(*q) || *q == '_')) 237 while (*q && (isalnum(*q) || *q == '_'))
@@ -286,8 +283,6 @@ static int is_ignored_file(const char *s, int len)
286{ 283{
287 return str_ends_with(s, len, "include/generated/autoconf.h") || 284 return str_ends_with(s, len, "include/generated/autoconf.h") ||
288 str_ends_with(s, len, "include/generated/autoksyms.h") || 285 str_ends_with(s, len, "include/generated/autoksyms.h") ||
289 str_ends_with(s, len, "arch/um/include/uml-config.h") ||
290 str_ends_with(s, len, "include/linux/kconfig.h") ||
291 str_ends_with(s, len, ".ver"); 286 str_ends_with(s, len, ".ver");
292} 287}
293 288
diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter
index 94b664817ad9..d84a5674e95e 100755
--- a/scripts/bloat-o-meter
+++ b/scripts/bloat-o-meter
@@ -15,7 +15,7 @@ signal(SIGPIPE, SIG_DFL)
15if len(sys.argv) < 3: 15if len(sys.argv) < 3:
16 sys.stderr.write("usage: %s [option] file1 file2\n" % sys.argv[0]) 16 sys.stderr.write("usage: %s [option] file1 file2\n" % sys.argv[0])
17 sys.stderr.write("The options are:\n") 17 sys.stderr.write("The options are:\n")
18 sys.stderr.write("-c cateogrize output based on symbole type\n") 18 sys.stderr.write("-c categorize output based on symbol type\n")
19 sys.stderr.write("-d Show delta of Data Section\n") 19 sys.stderr.write("-d Show delta of Data Section\n")
20 sys.stderr.write("-t Show delta of text Section\n") 20 sys.stderr.write("-t Show delta of text Section\n")
21 sys.exit(-1) 21 sys.exit(-1)
diff --git a/scripts/coccinelle/api/memdup.cocci b/scripts/coccinelle/api/memdup.cocci
index 1249b727644b..8fd6437beda8 100644
--- a/scripts/coccinelle/api/memdup.cocci
+++ b/scripts/coccinelle/api/memdup.cocci
@@ -56,10 +56,10 @@ statement S;
56p << r.p; 56p << r.p;
57@@ 57@@
58 58
59coccilib.org.print_todo(p[0], "WARNING opportunity for kmemdep") 59coccilib.org.print_todo(p[0], "WARNING opportunity for kmemdup")
60 60
61@script:python depends on report@ 61@script:python depends on report@
62p << r.p; 62p << r.p;
63@@ 63@@
64 64
65coccilib.report.print_report(p[0], "WARNING opportunity for kmemdep") 65coccilib.report.print_report(p[0], "WARNING opportunity for kmemdup")
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 9ee9bf7fd1a2..65792650c630 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -595,7 +595,7 @@ static void optimize_result(void)
595 * original char code */ 595 * original char code */
596 if (!best_table_len[i]) { 596 if (!best_table_len[i]) {
597 597
598 /* find the token with the breates profit value */ 598 /* find the token with the best profit value */
599 best = find_best_token(); 599 best = find_best_token();
600 if (token_profit[best] == 0) 600 if (token_profit[best] == 0)
601 break; 601 break;
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 5c12dc91ef34..df26c7b0fe13 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -178,7 +178,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
178 case S_HEX: 178 case S_HEX:
179 done: 179 done:
180 if (sym_string_valid(sym, p)) { 180 if (sym_string_valid(sym, p)) {
181 sym->def[def].val = strdup(p); 181 sym->def[def].val = xstrdup(p);
182 sym->flags |= def_flags; 182 sym->flags |= def_flags;
183 } else { 183 } else {
184 if (def != S_DEF_AUTO) 184 if (def != S_DEF_AUTO)
diff --git a/scripts/kconfig/kxgettext.c b/scripts/kconfig/kxgettext.c
index 2858738b22d5..240880a89111 100644
--- a/scripts/kconfig/kxgettext.c
+++ b/scripts/kconfig/kxgettext.c
@@ -101,7 +101,7 @@ static struct message *message__new(const char *msg, char *option,
101 if (self->files == NULL) 101 if (self->files == NULL)
102 goto out_fail; 102 goto out_fail;
103 103
104 self->msg = strdup(msg); 104 self->msg = xstrdup(msg);
105 if (self->msg == NULL) 105 if (self->msg == NULL)
106 goto out_fail_msg; 106 goto out_fail_msg;
107 107
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 4e23febbe4b2..2d5ec2d0e952 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -115,6 +115,7 @@ int file_write_dep(const char *name);
115void *xmalloc(size_t size); 115void *xmalloc(size_t size);
116void *xcalloc(size_t nmemb, size_t size); 116void *xcalloc(size_t nmemb, size_t size);
117void *xrealloc(void *p, size_t size); 117void *xrealloc(void *p, size_t size);
118char *xstrdup(const char *s);
118 119
119struct gstr { 120struct gstr {
120 size_t len; 121 size_t len;
diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh
index a10bd9d6fafd..6c0bcd9c472d 100755
--- a/scripts/kconfig/lxdialog/check-lxdialog.sh
+++ b/scripts/kconfig/lxdialog/check-lxdialog.sh
@@ -55,7 +55,8 @@ EOF
55 echo " *** required header files." 1>&2 55 echo " *** required header files." 1>&2
56 echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2 56 echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
57 echo " *** " 1>&2 57 echo " *** " 1>&2
58 echo " *** Install ncurses (ncurses-devel) and try again." 1>&2 58 echo " *** Install ncurses (ncurses-devel or libncurses-dev " 1>&2
59 echo " *** depending on your distribution) and try again." 1>&2
59 echo " *** " 1>&2 60 echo " *** " 1>&2
60 exit 1 61 exit 1
61 fi 62 fi
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 99222855544c..36cd3e1f1c28 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -212,6 +212,7 @@ void menu_add_option(int token, char *arg)
212 sym_defconfig_list = current_entry->sym; 212 sym_defconfig_list = current_entry->sym;
213 else if (sym_defconfig_list != current_entry->sym) 213 else if (sym_defconfig_list != current_entry->sym)
214 zconf_error("trying to redefine defconfig symbol"); 214 zconf_error("trying to redefine defconfig symbol");
215 sym_defconfig_list->flags |= SYMBOL_AUTO;
215 break; 216 break;
216 case T_OPT_ENV: 217 case T_OPT_ENV:
217 prop_add_env(arg); 218 prop_add_env(arg);
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index cca9663be5dd..2220bc4b051b 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym)
183 sprintf(str, "%lld", val2); 183 sprintf(str, "%lld", val2);
184 else 184 else
185 sprintf(str, "0x%llx", val2); 185 sprintf(str, "0x%llx", val2);
186 sym->curr.val = strdup(str); 186 sym->curr.val = xstrdup(str);
187} 187}
188 188
189static void sym_set_changed(struct symbol *sym) 189static void sym_set_changed(struct symbol *sym)
@@ -849,7 +849,7 @@ struct symbol *sym_lookup(const char *name, int flags)
849 : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE)))) 849 : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE))))
850 return symbol; 850 return symbol;
851 } 851 }
852 new_name = strdup(name); 852 new_name = xstrdup(name);
853 } else { 853 } else {
854 new_name = NULL; 854 new_name = NULL;
855 hash = 0; 855 hash = 0;
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index b98a79e30e04..c6f6e21b809f 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size)
154 fprintf(stderr, "Out of memory.\n"); 154 fprintf(stderr, "Out of memory.\n");
155 exit(1); 155 exit(1);
156} 156}
157
158char *xstrdup(const char *s)
159{
160 char *p;
161
162 p = strdup(s);
163 if (p)
164 return p;
165 fprintf(stderr, "Out of memory.\n");
166 exit(1);
167}
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 02de6fe302a9..88b650eb9cc9 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -332,16 +332,12 @@ void zconf_nextfile(const char *name)
332 "Inclusion path:\n current file : '%s'\n", 332 "Inclusion path:\n current file : '%s'\n",
333 zconf_curname(), zconf_lineno(), 333 zconf_curname(), zconf_lineno(),
334 zconf_curname()); 334 zconf_curname());
335 iter = current_file->parent; 335 iter = current_file;
336 while (iter && \ 336 do {
337 strcmp(iter->name,current_file->name)) {
338 fprintf(stderr, " included from: '%s:%d'\n",
339 iter->name, iter->lineno-1);
340 iter = iter->parent; 337 iter = iter->parent;
341 }
342 if (iter)
343 fprintf(stderr, " included from: '%s:%d'\n", 338 fprintf(stderr, " included from: '%s:%d'\n",
344 iter->name, iter->lineno+1); 339 iter->name, iter->lineno - 1);
340 } while (strcmp(iter->name, current_file->name));
345 exit(1); 341 exit(1);
346 } 342 }
347 } 343 }
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 4be98050b961..ad6305b0f40c 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -127,7 +127,7 @@ no_mainmenu_stmt: /* empty */
127 * later regardless of whether it comes from the 'prompt' in 127 * later regardless of whether it comes from the 'prompt' in
128 * mainmenu_stmt or here 128 * mainmenu_stmt or here
129 */ 129 */
130 menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL); 130 menu_add_prompt(P_MENU, xstrdup("Linux Kernel Configuration"), NULL);
131}; 131};
132 132
133 133
@@ -276,6 +276,7 @@ choice: T_CHOICE word_opt T_EOL
276 sym->flags |= SYMBOL_AUTO; 276 sym->flags |= SYMBOL_AUTO;
277 menu_add_entry(sym); 277 menu_add_entry(sym);
278 menu_add_expr(P_CHOICE, NULL, NULL); 278 menu_add_expr(P_CHOICE, NULL, NULL);
279 free($2);
279 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno()); 280 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
280}; 281};
281 282
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index c0d129d7f430..be56a1153014 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -246,7 +246,7 @@ else
246fi; 246fi;
247 247
248# final build of init/ 248# final build of init/
249${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" 249${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
250 250
251archive_builtin 251archive_builtin
252 252
diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c
index 6f9e4ce568cd..9bb0a7f2863e 100644
--- a/security/integrity/digsig.c
+++ b/security/integrity/digsig.c
@@ -18,6 +18,7 @@
18#include <linux/cred.h> 18#include <linux/cred.h>
19#include <linux/key-type.h> 19#include <linux/key-type.h>
20#include <linux/digsig.h> 20#include <linux/digsig.h>
21#include <linux/vmalloc.h>
21#include <crypto/public_key.h> 22#include <crypto/public_key.h>
22#include <keys/system_keyring.h> 23#include <keys/system_keyring.h>
23 24
diff --git a/security/keys/big_key.c b/security/keys/big_key.c
index 929e14978c42..fa728f662a6f 100644
--- a/security/keys/big_key.c
+++ b/security/keys/big_key.c
@@ -22,6 +22,13 @@
22#include <keys/big_key-type.h> 22#include <keys/big_key-type.h>
23#include <crypto/aead.h> 23#include <crypto/aead.h>
24 24
25struct big_key_buf {
26 unsigned int nr_pages;
27 void *virt;
28 struct scatterlist *sg;
29 struct page *pages[];
30};
31
25/* 32/*
26 * Layout of key payload words. 33 * Layout of key payload words.
27 */ 34 */
@@ -91,10 +98,9 @@ static DEFINE_MUTEX(big_key_aead_lock);
91/* 98/*
92 * Encrypt/decrypt big_key data 99 * Encrypt/decrypt big_key data
93 */ 100 */
94static int big_key_crypt(enum big_key_op op, u8 *data, size_t datalen, u8 *key) 101static int big_key_crypt(enum big_key_op op, struct big_key_buf *buf, size_t datalen, u8 *key)
95{ 102{
96 int ret; 103 int ret;
97 struct scatterlist sgio;
98 struct aead_request *aead_req; 104 struct aead_request *aead_req;
99 /* We always use a zero nonce. The reason we can get away with this is 105 /* We always use a zero nonce. The reason we can get away with this is
100 * because we're using a different randomly generated key for every 106 * because we're using a different randomly generated key for every
@@ -109,8 +115,7 @@ static int big_key_crypt(enum big_key_op op, u8 *data, size_t datalen, u8 *key)
109 return -ENOMEM; 115 return -ENOMEM;
110 116
111 memset(zero_nonce, 0, sizeof(zero_nonce)); 117 memset(zero_nonce, 0, sizeof(zero_nonce));
112 sg_init_one(&sgio, data, datalen + (op == BIG_KEY_ENC ? ENC_AUTHTAG_SIZE : 0)); 118 aead_request_set_crypt(aead_req, buf->sg, buf->sg, datalen, zero_nonce);
113 aead_request_set_crypt(aead_req, &sgio, &sgio, datalen, zero_nonce);
114 aead_request_set_callback(aead_req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL); 119 aead_request_set_callback(aead_req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL);
115 aead_request_set_ad(aead_req, 0); 120 aead_request_set_ad(aead_req, 0);
116 121
@@ -130,21 +135,81 @@ error:
130} 135}
131 136
132/* 137/*
138 * Free up the buffer.
139 */
140static void big_key_free_buffer(struct big_key_buf *buf)
141{
142 unsigned int i;
143
144 if (buf->virt) {
145 memset(buf->virt, 0, buf->nr_pages * PAGE_SIZE);
146 vunmap(buf->virt);
147 }
148
149 for (i = 0; i < buf->nr_pages; i++)
150 if (buf->pages[i])
151 __free_page(buf->pages[i]);
152
153 kfree(buf);
154}
155
156/*
157 * Allocate a buffer consisting of a set of pages with a virtual mapping
158 * applied over them.
159 */
160static void *big_key_alloc_buffer(size_t len)
161{
162 struct big_key_buf *buf;
163 unsigned int npg = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
164 unsigned int i, l;
165
166 buf = kzalloc(sizeof(struct big_key_buf) +
167 sizeof(struct page) * npg +
168 sizeof(struct scatterlist) * npg,
169 GFP_KERNEL);
170 if (!buf)
171 return NULL;
172
173 buf->nr_pages = npg;
174 buf->sg = (void *)(buf->pages + npg);
175 sg_init_table(buf->sg, npg);
176
177 for (i = 0; i < buf->nr_pages; i++) {
178 buf->pages[i] = alloc_page(GFP_KERNEL);
179 if (!buf->pages[i])
180 goto nomem;
181
182 l = min_t(size_t, len, PAGE_SIZE);
183 sg_set_page(&buf->sg[i], buf->pages[i], l, 0);
184 len -= l;
185 }
186
187 buf->virt = vmap(buf->pages, buf->nr_pages, VM_MAP, PAGE_KERNEL);
188 if (!buf->virt)
189 goto nomem;
190
191 return buf;
192
193nomem:
194 big_key_free_buffer(buf);
195 return NULL;
196}
197
198/*
133 * Preparse a big key 199 * Preparse a big key
134 */ 200 */
135int big_key_preparse(struct key_preparsed_payload *prep) 201int big_key_preparse(struct key_preparsed_payload *prep)
136{ 202{
203 struct big_key_buf *buf;
137 struct path *path = (struct path *)&prep->payload.data[big_key_path]; 204 struct path *path = (struct path *)&prep->payload.data[big_key_path];
138 struct file *file; 205 struct file *file;
139 u8 *enckey; 206 u8 *enckey;
140 u8 *data = NULL;
141 ssize_t written; 207 ssize_t written;
142 size_t datalen = prep->datalen; 208 size_t datalen = prep->datalen, enclen = datalen + ENC_AUTHTAG_SIZE;
143 int ret; 209 int ret;
144 210
145 ret = -EINVAL;
146 if (datalen <= 0 || datalen > 1024 * 1024 || !prep->data) 211 if (datalen <= 0 || datalen > 1024 * 1024 || !prep->data)
147 goto error; 212 return -EINVAL;
148 213
149 /* Set an arbitrary quota */ 214 /* Set an arbitrary quota */
150 prep->quotalen = 16; 215 prep->quotalen = 16;
@@ -157,13 +222,12 @@ int big_key_preparse(struct key_preparsed_payload *prep)
157 * 222 *
158 * File content is stored encrypted with randomly generated key. 223 * File content is stored encrypted with randomly generated key.
159 */ 224 */
160 size_t enclen = datalen + ENC_AUTHTAG_SIZE;
161 loff_t pos = 0; 225 loff_t pos = 0;
162 226
163 data = kmalloc(enclen, GFP_KERNEL); 227 buf = big_key_alloc_buffer(enclen);
164 if (!data) 228 if (!buf)
165 return -ENOMEM; 229 return -ENOMEM;
166 memcpy(data, prep->data, datalen); 230 memcpy(buf->virt, prep->data, datalen);
167 231
168 /* generate random key */ 232 /* generate random key */
169 enckey = kmalloc(ENC_KEY_SIZE, GFP_KERNEL); 233 enckey = kmalloc(ENC_KEY_SIZE, GFP_KERNEL);
@@ -176,7 +240,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
176 goto err_enckey; 240 goto err_enckey;
177 241
178 /* encrypt aligned data */ 242 /* encrypt aligned data */
179 ret = big_key_crypt(BIG_KEY_ENC, data, datalen, enckey); 243 ret = big_key_crypt(BIG_KEY_ENC, buf, datalen, enckey);
180 if (ret) 244 if (ret)
181 goto err_enckey; 245 goto err_enckey;
182 246
@@ -187,7 +251,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
187 goto err_enckey; 251 goto err_enckey;
188 } 252 }
189 253
190 written = kernel_write(file, data, enclen, &pos); 254 written = kernel_write(file, buf->virt, enclen, &pos);
191 if (written != enclen) { 255 if (written != enclen) {
192 ret = written; 256 ret = written;
193 if (written >= 0) 257 if (written >= 0)
@@ -202,7 +266,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
202 *path = file->f_path; 266 *path = file->f_path;
203 path_get(path); 267 path_get(path);
204 fput(file); 268 fput(file);
205 kzfree(data); 269 big_key_free_buffer(buf);
206 } else { 270 } else {
207 /* Just store the data in a buffer */ 271 /* Just store the data in a buffer */
208 void *data = kmalloc(datalen, GFP_KERNEL); 272 void *data = kmalloc(datalen, GFP_KERNEL);
@@ -220,7 +284,7 @@ err_fput:
220err_enckey: 284err_enckey:
221 kzfree(enckey); 285 kzfree(enckey);
222error: 286error:
223 kzfree(data); 287 big_key_free_buffer(buf);
224 return ret; 288 return ret;
225} 289}
226 290
@@ -298,15 +362,15 @@ long big_key_read(const struct key *key, char __user *buffer, size_t buflen)
298 return datalen; 362 return datalen;
299 363
300 if (datalen > BIG_KEY_FILE_THRESHOLD) { 364 if (datalen > BIG_KEY_FILE_THRESHOLD) {
365 struct big_key_buf *buf;
301 struct path *path = (struct path *)&key->payload.data[big_key_path]; 366 struct path *path = (struct path *)&key->payload.data[big_key_path];
302 struct file *file; 367 struct file *file;
303 u8 *data;
304 u8 *enckey = (u8 *)key->payload.data[big_key_data]; 368 u8 *enckey = (u8 *)key->payload.data[big_key_data];
305 size_t enclen = datalen + ENC_AUTHTAG_SIZE; 369 size_t enclen = datalen + ENC_AUTHTAG_SIZE;
306 loff_t pos = 0; 370 loff_t pos = 0;
307 371
308 data = kmalloc(enclen, GFP_KERNEL); 372 buf = big_key_alloc_buffer(enclen);
309 if (!data) 373 if (!buf)
310 return -ENOMEM; 374 return -ENOMEM;
311 375
312 file = dentry_open(path, O_RDONLY, current_cred()); 376 file = dentry_open(path, O_RDONLY, current_cred());
@@ -316,26 +380,26 @@ long big_key_read(const struct key *key, char __user *buffer, size_t buflen)
316 } 380 }
317 381
318 /* read file to kernel and decrypt */ 382 /* read file to kernel and decrypt */
319 ret = kernel_read(file, data, enclen, &pos); 383 ret = kernel_read(file, buf->virt, enclen, &pos);
320 if (ret >= 0 && ret != enclen) { 384 if (ret >= 0 && ret != enclen) {
321 ret = -EIO; 385 ret = -EIO;
322 goto err_fput; 386 goto err_fput;
323 } 387 }
324 388
325 ret = big_key_crypt(BIG_KEY_DEC, data, enclen, enckey); 389 ret = big_key_crypt(BIG_KEY_DEC, buf, enclen, enckey);
326 if (ret) 390 if (ret)
327 goto err_fput; 391 goto err_fput;
328 392
329 ret = datalen; 393 ret = datalen;
330 394
331 /* copy decrypted data to user */ 395 /* copy decrypted data to user */
332 if (copy_to_user(buffer, data, datalen) != 0) 396 if (copy_to_user(buffer, buf->virt, datalen) != 0)
333 ret = -EFAULT; 397 ret = -EFAULT;
334 398
335err_fput: 399err_fput:
336 fput(file); 400 fput(file);
337error: 401error:
338 kzfree(data); 402 big_key_free_buffer(buf);
339 } else { 403 } else {
340 ret = datalen; 404 ret = datalen;
341 if (copy_to_user(buffer, key->payload.data[big_key_data], 405 if (copy_to_user(buffer, key->payload.data[big_key_data],
diff --git a/sound/ac97/Kconfig b/sound/ac97/Kconfig
index f8a64e15e5bf..baa5f8ef89d2 100644
--- a/sound/ac97/Kconfig
+++ b/sound/ac97/Kconfig
@@ -5,7 +5,6 @@
5 5
6config AC97_BUS_NEW 6config AC97_BUS_NEW
7 tristate 7 tristate
8 select AC97
9 help 8 help
10 This is the new AC97 bus type, successor of AC97_BUS. The ported 9 This is the new AC97 bus type, successor of AC97_BUS. The ported
11 drivers which benefit from the AC97 automatic probing should "select" 10 drivers which benefit from the AC97 automatic probing should "select"
diff --git a/sound/core/control.c b/sound/core/control.c
index 0b3026d937b1..8a77620a3854 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -889,7 +889,7 @@ static int snd_ctl_elem_read(struct snd_card *card,
889 889
890 index_offset = snd_ctl_get_ioff(kctl, &control->id); 890 index_offset = snd_ctl_get_ioff(kctl, &control->id);
891 vd = &kctl->vd[index_offset]; 891 vd = &kctl->vd[index_offset];
892 if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) && kctl->get == NULL) 892 if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) || kctl->get == NULL)
893 return -EPERM; 893 return -EPERM;
894 894
895 snd_ctl_build_ioff(&control->id, kctl, index_offset); 895 snd_ctl_build_ioff(&control->id, kctl, index_offset);
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index b044c0a5a674..02298c9c6020 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -1762,10 +1762,9 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
1762 return -ENOMEM; 1762 return -ENOMEM;
1763 _snd_pcm_hw_params_any(params); 1763 _snd_pcm_hw_params_any(params);
1764 err = snd_pcm_hw_refine(substream, params); 1764 err = snd_pcm_hw_refine(substream, params);
1765 format_mask = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT);
1766 kfree(params);
1767 if (err < 0) 1765 if (err < 0)
1768 return err; 1766 goto error;
1767 format_mask = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT);
1769 for (fmt = 0; fmt < 32; ++fmt) { 1768 for (fmt = 0; fmt < 32; ++fmt) {
1770 if (snd_mask_test(format_mask, fmt)) { 1769 if (snd_mask_test(format_mask, fmt)) {
1771 int f = snd_pcm_oss_format_to(fmt); 1770 int f = snd_pcm_oss_format_to(fmt);
@@ -1773,7 +1772,10 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
1773 formats |= f; 1772 formats |= f;
1774 } 1773 }
1775 } 1774 }
1776 return formats; 1775
1776 error:
1777 kfree(params);
1778 return err < 0 ? err : formats;
1777} 1779}
1778 1780
1779static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format) 1781static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format)
diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
index 60db32785f62..61a07fe34cd2 100644
--- a/sound/core/seq/seq_clientmgr.c
+++ b/sound/core/seq/seq_clientmgr.c
@@ -255,12 +255,12 @@ static int seq_free_client1(struct snd_seq_client *client)
255 255
256 if (!client) 256 if (!client)
257 return 0; 257 return 0;
258 snd_seq_delete_all_ports(client);
259 snd_seq_queue_client_leave(client->number);
260 spin_lock_irqsave(&clients_lock, flags); 258 spin_lock_irqsave(&clients_lock, flags);
261 clienttablock[client->number] = 1; 259 clienttablock[client->number] = 1;
262 clienttab[client->number] = NULL; 260 clienttab[client->number] = NULL;
263 spin_unlock_irqrestore(&clients_lock, flags); 261 spin_unlock_irqrestore(&clients_lock, flags);
262 snd_seq_delete_all_ports(client);
263 snd_seq_queue_client_leave(client->number);
264 snd_use_lock_sync(&client->use_lock); 264 snd_use_lock_sync(&client->use_lock);
265 snd_seq_queue_client_termination(client->number); 265 snd_seq_queue_client_termination(client->number);
266 if (client->pool) 266 if (client->pool)
@@ -910,7 +910,8 @@ int snd_seq_dispatch_event(struct snd_seq_event_cell *cell, int atomic, int hop)
910static int snd_seq_client_enqueue_event(struct snd_seq_client *client, 910static int snd_seq_client_enqueue_event(struct snd_seq_client *client,
911 struct snd_seq_event *event, 911 struct snd_seq_event *event,
912 struct file *file, int blocking, 912 struct file *file, int blocking,
913 int atomic, int hop) 913 int atomic, int hop,
914 struct mutex *mutexp)
914{ 915{
915 struct snd_seq_event_cell *cell; 916 struct snd_seq_event_cell *cell;
916 int err; 917 int err;
@@ -948,7 +949,8 @@ static int snd_seq_client_enqueue_event(struct snd_seq_client *client,
948 return -ENXIO; /* queue is not allocated */ 949 return -ENXIO; /* queue is not allocated */
949 950
950 /* allocate an event cell */ 951 /* allocate an event cell */
951 err = snd_seq_event_dup(client->pool, event, &cell, !blocking || atomic, file); 952 err = snd_seq_event_dup(client->pool, event, &cell, !blocking || atomic,
953 file, mutexp);
952 if (err < 0) 954 if (err < 0)
953 return err; 955 return err;
954 956
@@ -1003,7 +1005,7 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
1003{ 1005{
1004 struct snd_seq_client *client = file->private_data; 1006 struct snd_seq_client *client = file->private_data;
1005 int written = 0, len; 1007 int written = 0, len;
1006 int err = -EINVAL; 1008 int err;
1007 struct snd_seq_event event; 1009 struct snd_seq_event event;
1008 1010
1009 if (!(snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT)) 1011 if (!(snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT))
@@ -1017,12 +1019,15 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
1017 return -ENXIO; 1019 return -ENXIO;
1018 1020
1019 /* allocate the pool now if the pool is not allocated yet */ 1021 /* allocate the pool now if the pool is not allocated yet */
1022 mutex_lock(&client->ioctl_mutex);
1020 if (client->pool->size > 0 && !snd_seq_write_pool_allocated(client)) { 1023 if (client->pool->size > 0 && !snd_seq_write_pool_allocated(client)) {
1021 if (snd_seq_pool_init(client->pool) < 0) 1024 err = snd_seq_pool_init(client->pool);
1022 return -ENOMEM; 1025 if (err < 0)
1026 goto out;
1023 } 1027 }
1024 1028
1025 /* only process whole events */ 1029 /* only process whole events */
1030 err = -EINVAL;
1026 while (count >= sizeof(struct snd_seq_event)) { 1031 while (count >= sizeof(struct snd_seq_event)) {
1027 /* Read in the event header from the user */ 1032 /* Read in the event header from the user */
1028 len = sizeof(event); 1033 len = sizeof(event);
@@ -1069,7 +1074,7 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
1069 /* ok, enqueue it */ 1074 /* ok, enqueue it */
1070 err = snd_seq_client_enqueue_event(client, &event, file, 1075 err = snd_seq_client_enqueue_event(client, &event, file,
1071 !(file->f_flags & O_NONBLOCK), 1076 !(file->f_flags & O_NONBLOCK),
1072 0, 0); 1077 0, 0, &client->ioctl_mutex);
1073 if (err < 0) 1078 if (err < 0)
1074 break; 1079 break;
1075 1080
@@ -1080,6 +1085,8 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
1080 written += len; 1085 written += len;
1081 } 1086 }
1082 1087
1088 out:
1089 mutex_unlock(&client->ioctl_mutex);
1083 return written ? written : err; 1090 return written ? written : err;
1084} 1091}
1085 1092
@@ -1834,9 +1841,11 @@ static int snd_seq_ioctl_set_client_pool(struct snd_seq_client *client,
1834 (! snd_seq_write_pool_allocated(client) || 1841 (! snd_seq_write_pool_allocated(client) ||
1835 info->output_pool != client->pool->size)) { 1842 info->output_pool != client->pool->size)) {
1836 if (snd_seq_write_pool_allocated(client)) { 1843 if (snd_seq_write_pool_allocated(client)) {
1844 /* is the pool in use? */
1845 if (atomic_read(&client->pool->counter))
1846 return -EBUSY;
1837 /* remove all existing cells */ 1847 /* remove all existing cells */
1838 snd_seq_pool_mark_closing(client->pool); 1848 snd_seq_pool_mark_closing(client->pool);
1839 snd_seq_queue_client_leave_cells(client->number);
1840 snd_seq_pool_done(client->pool); 1849 snd_seq_pool_done(client->pool);
1841 } 1850 }
1842 client->pool->size = info->output_pool; 1851 client->pool->size = info->output_pool;
@@ -2256,7 +2265,8 @@ static int kernel_client_enqueue(int client, struct snd_seq_event *ev,
2256 if (! cptr->accept_output) 2265 if (! cptr->accept_output)
2257 result = -EPERM; 2266 result = -EPERM;
2258 else /* send it */ 2267 else /* send it */
2259 result = snd_seq_client_enqueue_event(cptr, ev, file, blocking, atomic, hop); 2268 result = snd_seq_client_enqueue_event(cptr, ev, file, blocking,
2269 atomic, hop, NULL);
2260 2270
2261 snd_seq_client_unlock(cptr); 2271 snd_seq_client_unlock(cptr);
2262 return result; 2272 return result;
diff --git a/sound/core/seq/seq_fifo.c b/sound/core/seq/seq_fifo.c
index a8c2822e0198..72c0302a55d2 100644
--- a/sound/core/seq/seq_fifo.c
+++ b/sound/core/seq/seq_fifo.c
@@ -125,7 +125,7 @@ int snd_seq_fifo_event_in(struct snd_seq_fifo *f,
125 return -EINVAL; 125 return -EINVAL;
126 126
127 snd_use_lock_use(&f->use_lock); 127 snd_use_lock_use(&f->use_lock);
128 err = snd_seq_event_dup(f->pool, event, &cell, 1, NULL); /* always non-blocking */ 128 err = snd_seq_event_dup(f->pool, event, &cell, 1, NULL, NULL); /* always non-blocking */
129 if (err < 0) { 129 if (err < 0) {
130 if ((err == -ENOMEM) || (err == -EAGAIN)) 130 if ((err == -ENOMEM) || (err == -EAGAIN))
131 atomic_inc(&f->overflow); 131 atomic_inc(&f->overflow);
diff --git a/sound/core/seq/seq_memory.c b/sound/core/seq/seq_memory.c
index f763682584a8..ab1112e90f88 100644
--- a/sound/core/seq/seq_memory.c
+++ b/sound/core/seq/seq_memory.c
@@ -220,7 +220,8 @@ void snd_seq_cell_free(struct snd_seq_event_cell * cell)
220 */ 220 */
221static int snd_seq_cell_alloc(struct snd_seq_pool *pool, 221static int snd_seq_cell_alloc(struct snd_seq_pool *pool,
222 struct snd_seq_event_cell **cellp, 222 struct snd_seq_event_cell **cellp,
223 int nonblock, struct file *file) 223 int nonblock, struct file *file,
224 struct mutex *mutexp)
224{ 225{
225 struct snd_seq_event_cell *cell; 226 struct snd_seq_event_cell *cell;
226 unsigned long flags; 227 unsigned long flags;
@@ -244,7 +245,11 @@ static int snd_seq_cell_alloc(struct snd_seq_pool *pool,
244 set_current_state(TASK_INTERRUPTIBLE); 245 set_current_state(TASK_INTERRUPTIBLE);
245 add_wait_queue(&pool->output_sleep, &wait); 246 add_wait_queue(&pool->output_sleep, &wait);
246 spin_unlock_irq(&pool->lock); 247 spin_unlock_irq(&pool->lock);
248 if (mutexp)
249 mutex_unlock(mutexp);
247 schedule(); 250 schedule();
251 if (mutexp)
252 mutex_lock(mutexp);
248 spin_lock_irq(&pool->lock); 253 spin_lock_irq(&pool->lock);
249 remove_wait_queue(&pool->output_sleep, &wait); 254 remove_wait_queue(&pool->output_sleep, &wait);
250 /* interrupted? */ 255 /* interrupted? */
@@ -287,7 +292,7 @@ __error:
287 */ 292 */
288int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event, 293int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
289 struct snd_seq_event_cell **cellp, int nonblock, 294 struct snd_seq_event_cell **cellp, int nonblock,
290 struct file *file) 295 struct file *file, struct mutex *mutexp)
291{ 296{
292 int ncells, err; 297 int ncells, err;
293 unsigned int extlen; 298 unsigned int extlen;
@@ -304,7 +309,7 @@ int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
304 if (ncells >= pool->total_elements) 309 if (ncells >= pool->total_elements)
305 return -ENOMEM; 310 return -ENOMEM;
306 311
307 err = snd_seq_cell_alloc(pool, &cell, nonblock, file); 312 err = snd_seq_cell_alloc(pool, &cell, nonblock, file, mutexp);
308 if (err < 0) 313 if (err < 0)
309 return err; 314 return err;
310 315
@@ -330,7 +335,8 @@ int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
330 int size = sizeof(struct snd_seq_event); 335 int size = sizeof(struct snd_seq_event);
331 if (len < size) 336 if (len < size)
332 size = len; 337 size = len;
333 err = snd_seq_cell_alloc(pool, &tmp, nonblock, file); 338 err = snd_seq_cell_alloc(pool, &tmp, nonblock, file,
339 mutexp);
334 if (err < 0) 340 if (err < 0)
335 goto __error; 341 goto __error;
336 if (cell->event.data.ext.ptr == NULL) 342 if (cell->event.data.ext.ptr == NULL)
diff --git a/sound/core/seq/seq_memory.h b/sound/core/seq/seq_memory.h
index 32f959c17786..3abe306c394a 100644
--- a/sound/core/seq/seq_memory.h
+++ b/sound/core/seq/seq_memory.h
@@ -66,7 +66,8 @@ struct snd_seq_pool {
66void snd_seq_cell_free(struct snd_seq_event_cell *cell); 66void snd_seq_cell_free(struct snd_seq_event_cell *cell);
67 67
68int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event, 68int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
69 struct snd_seq_event_cell **cellp, int nonblock, struct file *file); 69 struct snd_seq_event_cell **cellp, int nonblock,
70 struct file *file, struct mutex *mutexp);
70 71
71/* return number of unused (free) cells */ 72/* return number of unused (free) cells */
72static inline int snd_seq_unused_cells(struct snd_seq_pool *pool) 73static inline int snd_seq_unused_cells(struct snd_seq_pool *pool)
diff --git a/sound/core/seq/seq_prioq.c b/sound/core/seq/seq_prioq.c
index bc1c8488fc2a..2bc6759e4adc 100644
--- a/sound/core/seq/seq_prioq.c
+++ b/sound/core/seq/seq_prioq.c
@@ -87,7 +87,7 @@ void snd_seq_prioq_delete(struct snd_seq_prioq **fifo)
87 if (f->cells > 0) { 87 if (f->cells > 0) {
88 /* drain prioQ */ 88 /* drain prioQ */
89 while (f->cells > 0) 89 while (f->cells > 0)
90 snd_seq_cell_free(snd_seq_prioq_cell_out(f)); 90 snd_seq_cell_free(snd_seq_prioq_cell_out(f, NULL));
91 } 91 }
92 92
93 kfree(f); 93 kfree(f);
@@ -214,8 +214,18 @@ int snd_seq_prioq_cell_in(struct snd_seq_prioq * f,
214 return 0; 214 return 0;
215} 215}
216 216
217/* return 1 if the current time >= event timestamp */
218static int event_is_ready(struct snd_seq_event *ev, void *current_time)
219{
220 if ((ev->flags & SNDRV_SEQ_TIME_STAMP_MASK) == SNDRV_SEQ_TIME_STAMP_TICK)
221 return snd_seq_compare_tick_time(current_time, &ev->time.tick);
222 else
223 return snd_seq_compare_real_time(current_time, &ev->time.time);
224}
225
217/* dequeue cell from prioq */ 226/* dequeue cell from prioq */
218struct snd_seq_event_cell *snd_seq_prioq_cell_out(struct snd_seq_prioq *f) 227struct snd_seq_event_cell *snd_seq_prioq_cell_out(struct snd_seq_prioq *f,
228 void *current_time)
219{ 229{
220 struct snd_seq_event_cell *cell; 230 struct snd_seq_event_cell *cell;
221 unsigned long flags; 231 unsigned long flags;
@@ -227,6 +237,8 @@ struct snd_seq_event_cell *snd_seq_prioq_cell_out(struct snd_seq_prioq *f)
227 spin_lock_irqsave(&f->lock, flags); 237 spin_lock_irqsave(&f->lock, flags);
228 238
229 cell = f->head; 239 cell = f->head;
240 if (cell && current_time && !event_is_ready(&cell->event, current_time))
241 cell = NULL;
230 if (cell) { 242 if (cell) {
231 f->head = cell->next; 243 f->head = cell->next;
232 244
@@ -252,18 +264,6 @@ int snd_seq_prioq_avail(struct snd_seq_prioq * f)
252 return f->cells; 264 return f->cells;
253} 265}
254 266
255
256/* peek at cell at the head of the prioq */
257struct snd_seq_event_cell *snd_seq_prioq_cell_peek(struct snd_seq_prioq * f)
258{
259 if (f == NULL) {
260 pr_debug("ALSA: seq: snd_seq_prioq_cell_in() called with NULL prioq\n");
261 return NULL;
262 }
263 return f->head;
264}
265
266
267static inline int prioq_match(struct snd_seq_event_cell *cell, 267static inline int prioq_match(struct snd_seq_event_cell *cell,
268 int client, int timestamp) 268 int client, int timestamp)
269{ 269{
diff --git a/sound/core/seq/seq_prioq.h b/sound/core/seq/seq_prioq.h
index d38bb78d9345..2c315ca10fc4 100644
--- a/sound/core/seq/seq_prioq.h
+++ b/sound/core/seq/seq_prioq.h
@@ -44,14 +44,12 @@ void snd_seq_prioq_delete(struct snd_seq_prioq **fifo);
44int snd_seq_prioq_cell_in(struct snd_seq_prioq *f, struct snd_seq_event_cell *cell); 44int snd_seq_prioq_cell_in(struct snd_seq_prioq *f, struct snd_seq_event_cell *cell);
45 45
46/* dequeue cell from prioq */ 46/* dequeue cell from prioq */
47struct snd_seq_event_cell *snd_seq_prioq_cell_out(struct snd_seq_prioq *f); 47struct snd_seq_event_cell *snd_seq_prioq_cell_out(struct snd_seq_prioq *f,
48 void *current_time);
48 49
49/* return number of events available in prioq */ 50/* return number of events available in prioq */
50int snd_seq_prioq_avail(struct snd_seq_prioq *f); 51int snd_seq_prioq_avail(struct snd_seq_prioq *f);
51 52
52/* peek at cell at the head of the prioq */
53struct snd_seq_event_cell *snd_seq_prioq_cell_peek(struct snd_seq_prioq *f);
54
55/* client left queue */ 53/* client left queue */
56void snd_seq_prioq_leave(struct snd_seq_prioq *f, int client, int timestamp); 54void snd_seq_prioq_leave(struct snd_seq_prioq *f, int client, int timestamp);
57 55
diff --git a/sound/core/seq/seq_queue.c b/sound/core/seq/seq_queue.c
index 0428e9061b47..b377f5048352 100644
--- a/sound/core/seq/seq_queue.c
+++ b/sound/core/seq/seq_queue.c
@@ -277,30 +277,20 @@ void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
277 277
278 __again: 278 __again:
279 /* Process tick queue... */ 279 /* Process tick queue... */
280 while ((cell = snd_seq_prioq_cell_peek(q->tickq)) != NULL) { 280 for (;;) {
281 if (snd_seq_compare_tick_time(&q->timer->tick.cur_tick, 281 cell = snd_seq_prioq_cell_out(q->tickq,
282 &cell->event.time.tick)) { 282 &q->timer->tick.cur_tick);
283 cell = snd_seq_prioq_cell_out(q->tickq); 283 if (!cell)
284 if (cell)
285 snd_seq_dispatch_event(cell, atomic, hop);
286 } else {
287 /* event remains in the queue */
288 break; 284 break;
289 } 285 snd_seq_dispatch_event(cell, atomic, hop);
290 } 286 }
291 287
292
293 /* Process time queue... */ 288 /* Process time queue... */
294 while ((cell = snd_seq_prioq_cell_peek(q->timeq)) != NULL) { 289 for (;;) {
295 if (snd_seq_compare_real_time(&q->timer->cur_time, 290 cell = snd_seq_prioq_cell_out(q->timeq, &q->timer->cur_time);
296 &cell->event.time.time)) { 291 if (!cell)
297 cell = snd_seq_prioq_cell_out(q->timeq);
298 if (cell)
299 snd_seq_dispatch_event(cell, atomic, hop);
300 } else {
301 /* event remains in the queue */
302 break; 292 break;
303 } 293 snd_seq_dispatch_event(cell, atomic, hop);
304 } 294 }
305 295
306 /* free lock */ 296 /* free lock */
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c
index 0333143a1fa7..1063a4377502 100644
--- a/sound/drivers/aloop.c
+++ b/sound/drivers/aloop.c
@@ -192,6 +192,11 @@ static inline void loopback_timer_stop(struct loopback_pcm *dpcm)
192 dpcm->timer.expires = 0; 192 dpcm->timer.expires = 0;
193} 193}
194 194
195static inline void loopback_timer_stop_sync(struct loopback_pcm *dpcm)
196{
197 del_timer_sync(&dpcm->timer);
198}
199
195#define CABLE_VALID_PLAYBACK (1 << SNDRV_PCM_STREAM_PLAYBACK) 200#define CABLE_VALID_PLAYBACK (1 << SNDRV_PCM_STREAM_PLAYBACK)
196#define CABLE_VALID_CAPTURE (1 << SNDRV_PCM_STREAM_CAPTURE) 201#define CABLE_VALID_CAPTURE (1 << SNDRV_PCM_STREAM_CAPTURE)
197#define CABLE_VALID_BOTH (CABLE_VALID_PLAYBACK|CABLE_VALID_CAPTURE) 202#define CABLE_VALID_BOTH (CABLE_VALID_PLAYBACK|CABLE_VALID_CAPTURE)
@@ -326,6 +331,8 @@ static int loopback_prepare(struct snd_pcm_substream *substream)
326 struct loopback_cable *cable = dpcm->cable; 331 struct loopback_cable *cable = dpcm->cable;
327 int bps, salign; 332 int bps, salign;
328 333
334 loopback_timer_stop_sync(dpcm);
335
329 salign = (snd_pcm_format_width(runtime->format) * 336 salign = (snd_pcm_format_width(runtime->format) *
330 runtime->channels) / 8; 337 runtime->channels) / 8;
331 bps = salign * runtime->rate; 338 bps = salign * runtime->rate;
@@ -659,7 +666,9 @@ static void free_cable(struct snd_pcm_substream *substream)
659 return; 666 return;
660 if (cable->streams[!substream->stream]) { 667 if (cable->streams[!substream->stream]) {
661 /* other stream is still alive */ 668 /* other stream is still alive */
669 spin_lock_irq(&cable->lock);
662 cable->streams[substream->stream] = NULL; 670 cable->streams[substream->stream] = NULL;
671 spin_unlock_irq(&cable->lock);
663 } else { 672 } else {
664 /* free the cable */ 673 /* free the cable */
665 loopback->cables[substream->number][dev] = NULL; 674 loopback->cables[substream->number][dev] = NULL;
@@ -698,7 +707,6 @@ static int loopback_open(struct snd_pcm_substream *substream)
698 loopback->cables[substream->number][dev] = cable; 707 loopback->cables[substream->number][dev] = cable;
699 } 708 }
700 dpcm->cable = cable; 709 dpcm->cable = cable;
701 cable->streams[substream->stream] = dpcm;
702 710
703 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); 711 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
704 712
@@ -730,6 +738,11 @@ static int loopback_open(struct snd_pcm_substream *substream)
730 runtime->hw = loopback_pcm_hardware; 738 runtime->hw = loopback_pcm_hardware;
731 else 739 else
732 runtime->hw = cable->hw; 740 runtime->hw = cable->hw;
741
742 spin_lock_irq(&cable->lock);
743 cable->streams[substream->stream] = dpcm;
744 spin_unlock_irq(&cable->lock);
745
733 unlock: 746 unlock:
734 if (err < 0) { 747 if (err < 0) {
735 free_cable(substream); 748 free_cable(substream);
@@ -744,7 +757,7 @@ static int loopback_close(struct snd_pcm_substream *substream)
744 struct loopback *loopback = substream->private_data; 757 struct loopback *loopback = substream->private_data;
745 struct loopback_pcm *dpcm = substream->runtime->private_data; 758 struct loopback_pcm *dpcm = substream->runtime->private_data;
746 759
747 loopback_timer_stop(dpcm); 760 loopback_timer_stop_sync(dpcm);
748 mutex_lock(&loopback->cable_lock); 761 mutex_lock(&loopback->cable_lock);
749 free_cable(substream); 762 free_cable(substream);
750 mutex_unlock(&loopback->cable_lock); 763 mutex_unlock(&loopback->cable_lock);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index ec4e6b829ee2..e2f649fffd56 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -186,6 +186,10 @@ module_param(power_save, xint, 0644);
186MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " 186MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
187 "(in second, 0 = disable)."); 187 "(in second, 0 = disable).");
188 188
189static bool pm_blacklist = true;
190module_param(pm_blacklist, bool, 0644);
191MODULE_PARM_DESC(pm_blacklist, "Enable power-management blacklist");
192
189/* reset the HD-audio controller in power save mode. 193/* reset the HD-audio controller in power save mode.
190 * this may give more power-saving, but will take longer time to 194 * this may give more power-saving, but will take longer time to
191 * wake up. 195 * wake up.
@@ -371,6 +375,7 @@ enum {
371 ((pci)->device == 0x160c)) 375 ((pci)->device == 0x160c))
372 376
373#define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98) 377#define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98)
378#define IS_CFL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa348)
374 379
375static char *driver_short_names[] = { 380static char *driver_short_names[] = {
376 [AZX_DRIVER_ICH] = "HDA Intel", 381 [AZX_DRIVER_ICH] = "HDA Intel",
@@ -1744,6 +1749,10 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
1744 else 1749 else
1745 chip->bdl_pos_adj = bdl_pos_adj[dev]; 1750 chip->bdl_pos_adj = bdl_pos_adj[dev];
1746 1751
1752 /* Workaround for a communication error on CFL (bko#199007) */
1753 if (IS_CFL(pci))
1754 chip->polling_mode = 1;
1755
1747 err = azx_bus_init(chip, model[dev], &pci_hda_io_ops); 1756 err = azx_bus_init(chip, model[dev], &pci_hda_io_ops);
1748 if (err < 0) { 1757 if (err < 0) {
1749 kfree(hda); 1758 kfree(hda);
@@ -2190,6 +2199,24 @@ out_free:
2190 return err; 2199 return err;
2191} 2200}
2192 2201
2202#ifdef CONFIG_PM
2203/* On some boards setting power_save to a non 0 value leads to clicking /
2204 * popping sounds when ever we enter/leave powersaving mode. Ideally we would
2205 * figure out how to avoid these sounds, but that is not always feasible.
2206 * So we keep a list of devices where we disable powersaving as its known
2207 * to causes problems on these devices.
2208 */
2209static struct snd_pci_quirk power_save_blacklist[] = {
2210 /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
2211 SND_PCI_QUIRK(0x1849, 0x0c0c, "Asrock B85M-ITX", 0),
2212 /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
2213 SND_PCI_QUIRK(0x1043, 0x8733, "Asus Prime X370-Pro", 0),
2214 /* https://bugzilla.kernel.org/show_bug.cgi?id=198611 */
2215 SND_PCI_QUIRK(0x17aa, 0x2227, "Lenovo X1 Carbon 3rd Gen", 0),
2216 {}
2217};
2218#endif /* CONFIG_PM */
2219
2193/* number of codec slots for each chipset: 0 = default slots (i.e. 4) */ 2220/* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
2194static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = { 2221static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = {
2195 [AZX_DRIVER_NVIDIA] = 8, 2222 [AZX_DRIVER_NVIDIA] = 8,
@@ -2203,6 +2230,7 @@ static int azx_probe_continue(struct azx *chip)
2203 struct pci_dev *pci = chip->pci; 2230 struct pci_dev *pci = chip->pci;
2204 struct hda_codec *codec; 2231 struct hda_codec *codec;
2205 int dev = chip->dev_index; 2232 int dev = chip->dev_index;
2233 int val;
2206 int err; 2234 int err;
2207 2235
2208 hda->probe_continued = 1; 2236 hda->probe_continued = 1;
@@ -2284,6 +2312,19 @@ static int azx_probe_continue(struct azx *chip)
2284 chip->running = 1; 2312 chip->running = 1;
2285 azx_add_card_list(chip); 2313 azx_add_card_list(chip);
2286 2314
2315 val = power_save;
2316#ifdef CONFIG_PM
2317 if (pm_blacklist) {
2318 const struct snd_pci_quirk *q;
2319
2320 q = snd_pci_quirk_lookup(chip->pci, power_save_blacklist);
2321 if (q && val) {
2322 dev_info(chip->card->dev, "device %04x:%04x is on the power_save blacklist, forcing power_save to 0\n",
2323 q->subvendor, q->subdevice);
2324 val = 0;
2325 }
2326 }
2327#endif /* CONFIG_PM */
2287 /* 2328 /*
2288 * The discrete GPU cannot power down unless the HDA controller runtime 2329 * The discrete GPU cannot power down unless the HDA controller runtime
2289 * suspends, so activate runtime PM on codecs even if power_save == 0. 2330 * suspends, so activate runtime PM on codecs even if power_save == 0.
@@ -2292,7 +2333,7 @@ static int azx_probe_continue(struct azx *chip)
2292 list_for_each_codec(codec, &chip->bus) 2333 list_for_each_codec(codec, &chip->bus)
2293 codec->auto_runtime_pm = 1; 2334 codec->auto_runtime_pm = 1;
2294 2335
2295 snd_hda_set_power_save(&chip->bus, power_save * 1000); 2336 snd_hda_set_power_save(&chip->bus, val * 1000);
2296 if (azx_has_pm_runtime(chip)) 2337 if (azx_has_pm_runtime(chip))
2297 pm_runtime_put_autosuspend(&pci->dev); 2338 pm_runtime_put_autosuspend(&pci->dev);
2298 2339
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 37e1cf8218ff..5b4dbcec6de8 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -957,6 +957,8 @@ static const struct snd_pci_quirk cxt5066_fixups[] = {
957 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC), 957 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC),
958 SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC), 958 SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC),
959 SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK), 959 SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK),
960 SND_PCI_QUIRK(0x103c, 0x807C, "HP EliteBook 820 G3", CXT_FIXUP_HP_DOCK),
961 SND_PCI_QUIRK(0x103c, 0x80FD, "HP ProBook 640 G2", CXT_FIXUP_HP_DOCK),
960 SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE), 962 SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE),
961 SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC), 963 SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC),
962 SND_PCI_QUIRK(0x103c, 0x814f, "HP ZBook 15u G3", CXT_FIXUP_MUTE_LED_GPIO), 964 SND_PCI_QUIRK(0x103c, 0x814f, "HP ZBook 15u G3", CXT_FIXUP_MUTE_LED_GPIO),
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 23475888192b..aef1f52db7d9 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -3130,6 +3130,8 @@ static void alc256_init(struct hda_codec *codec)
3130 3130
3131 alc_update_coef_idx(codec, 0x46, 3 << 12, 0); 3131 alc_update_coef_idx(codec, 0x46, 3 << 12, 0);
3132 alc_update_coefex_idx(codec, 0x57, 0x04, 0x0007, 0x4); /* Hight power */ 3132 alc_update_coefex_idx(codec, 0x57, 0x04, 0x0007, 0x4); /* Hight power */
3133 alc_update_coefex_idx(codec, 0x53, 0x02, 0x8000, 1 << 15); /* Clear bit */
3134 alc_update_coefex_idx(codec, 0x53, 0x02, 0x8000, 0 << 15);
3133} 3135}
3134 3136
3135static void alc256_shutup(struct hda_codec *codec) 3137static void alc256_shutup(struct hda_codec *codec)
@@ -3465,6 +3467,19 @@ static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
3465 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; 3467 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
3466} 3468}
3467 3469
3470static void alc269_fixup_pincfg_U7x7_headset_mic(struct hda_codec *codec,
3471 const struct hda_fixup *fix,
3472 int action)
3473{
3474 unsigned int cfg_headphone = snd_hda_codec_get_pincfg(codec, 0x21);
3475 unsigned int cfg_headset_mic = snd_hda_codec_get_pincfg(codec, 0x19);
3476
3477 if (cfg_headphone && cfg_headset_mic == 0x411111f0)
3478 snd_hda_codec_set_pincfg(codec, 0x19,
3479 (cfg_headphone & ~AC_DEFCFG_DEVICE) |
3480 (AC_JACK_MIC_IN << AC_DEFCFG_DEVICE_SHIFT));
3481}
3482
3468static void alc269_fixup_hweq(struct hda_codec *codec, 3483static void alc269_fixup_hweq(struct hda_codec *codec,
3469 const struct hda_fixup *fix, int action) 3484 const struct hda_fixup *fix, int action)
3470{ 3485{
@@ -3583,8 +3598,12 @@ static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
3583 pinval = snd_hda_codec_get_pin_target(codec, spec->mute_led_nid); 3598 pinval = snd_hda_codec_get_pin_target(codec, spec->mute_led_nid);
3584 pinval &= ~AC_PINCTL_VREFEN; 3599 pinval &= ~AC_PINCTL_VREFEN;
3585 pinval |= enabled ? AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80; 3600 pinval |= enabled ? AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80;
3586 if (spec->mute_led_nid) 3601 if (spec->mute_led_nid) {
3602 /* temporarily power up/down for setting VREF */
3603 snd_hda_power_up_pm(codec);
3587 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval); 3604 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval);
3605 snd_hda_power_down_pm(codec);
3606 }
3588} 3607}
3589 3608
3590/* Make sure the led works even in runtime suspend */ 3609/* Make sure the led works even in runtime suspend */
@@ -4972,6 +4991,29 @@ static void alc_fixup_tpt440_dock(struct hda_codec *codec,
4972 } 4991 }
4973} 4992}
4974 4993
4994static void alc_fixup_tpt470_dock(struct hda_codec *codec,
4995 const struct hda_fixup *fix, int action)
4996{
4997 static const struct hda_pintbl pincfgs[] = {
4998 { 0x17, 0x21211010 }, /* dock headphone */
4999 { 0x19, 0x21a11010 }, /* dock mic */
5000 { }
5001 };
5002 struct alc_spec *spec = codec->spec;
5003
5004 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5005 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5006 snd_hda_apply_pincfgs(codec, pincfgs);
5007 } else if (action == HDA_FIXUP_ACT_INIT) {
5008 /* Enable DOCK device */
5009 snd_hda_codec_write(codec, 0x17, 0,
5010 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0);
5011 /* Enable DOCK device */
5012 snd_hda_codec_write(codec, 0x19, 0,
5013 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0);
5014 }
5015}
5016
4975static void alc_shutup_dell_xps13(struct hda_codec *codec) 5017static void alc_shutup_dell_xps13(struct hda_codec *codec)
4976{ 5018{
4977 struct alc_spec *spec = codec->spec; 5019 struct alc_spec *spec = codec->spec;
@@ -5238,6 +5280,16 @@ static void alc298_fixup_speaker_volume(struct hda_codec *codec,
5238 } 5280 }
5239} 5281}
5240 5282
5283/* disable DAC3 (0x06) selection on NID 0x17 as it has no volume amp control */
5284static void alc295_fixup_disable_dac3(struct hda_codec *codec,
5285 const struct hda_fixup *fix, int action)
5286{
5287 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5288 hda_nid_t conn[2] = { 0x02, 0x03 };
5289 snd_hda_override_conn_list(codec, 0x17, 2, conn);
5290 }
5291}
5292
5241/* Hook to update amp GPIO4 for automute */ 5293/* Hook to update amp GPIO4 for automute */
5242static void alc280_hp_gpio4_automute_hook(struct hda_codec *codec, 5294static void alc280_hp_gpio4_automute_hook(struct hda_codec *codec,
5243 struct hda_jack_callback *jack) 5295 struct hda_jack_callback *jack)
@@ -5351,6 +5403,7 @@ enum {
5351 ALC269_FIXUP_LIFEBOOK_EXTMIC, 5403 ALC269_FIXUP_LIFEBOOK_EXTMIC,
5352 ALC269_FIXUP_LIFEBOOK_HP_PIN, 5404 ALC269_FIXUP_LIFEBOOK_HP_PIN,
5353 ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT, 5405 ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT,
5406 ALC255_FIXUP_LIFEBOOK_U7x7_HEADSET_MIC,
5354 ALC269_FIXUP_AMIC, 5407 ALC269_FIXUP_AMIC,
5355 ALC269_FIXUP_DMIC, 5408 ALC269_FIXUP_DMIC,
5356 ALC269VB_FIXUP_AMIC, 5409 ALC269VB_FIXUP_AMIC,
@@ -5429,6 +5482,7 @@ enum {
5429 ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY, 5482 ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY,
5430 ALC255_FIXUP_DELL_SPK_NOISE, 5483 ALC255_FIXUP_DELL_SPK_NOISE,
5431 ALC225_FIXUP_DELL1_MIC_NO_PRESENCE, 5484 ALC225_FIXUP_DELL1_MIC_NO_PRESENCE,
5485 ALC295_FIXUP_DISABLE_DAC3,
5432 ALC280_FIXUP_HP_HEADSET_MIC, 5486 ALC280_FIXUP_HP_HEADSET_MIC,
5433 ALC221_FIXUP_HP_FRONT_MIC, 5487 ALC221_FIXUP_HP_FRONT_MIC,
5434 ALC292_FIXUP_TPT460, 5488 ALC292_FIXUP_TPT460,
@@ -5443,9 +5497,13 @@ enum {
5443 ALC233_FIXUP_EAPD_COEF_AND_MIC_NO_PRESENCE, 5497 ALC233_FIXUP_EAPD_COEF_AND_MIC_NO_PRESENCE,
5444 ALC233_FIXUP_LENOVO_MULTI_CODECS, 5498 ALC233_FIXUP_LENOVO_MULTI_CODECS,
5445 ALC294_FIXUP_LENOVO_MIC_LOCATION, 5499 ALC294_FIXUP_LENOVO_MIC_LOCATION,
5500 ALC225_FIXUP_DELL_WYSE_MIC_NO_PRESENCE,
5446 ALC700_FIXUP_INTEL_REFERENCE, 5501 ALC700_FIXUP_INTEL_REFERENCE,
5447 ALC274_FIXUP_DELL_BIND_DACS, 5502 ALC274_FIXUP_DELL_BIND_DACS,
5448 ALC274_FIXUP_DELL_AIO_LINEOUT_VERB, 5503 ALC274_FIXUP_DELL_AIO_LINEOUT_VERB,
5504 ALC298_FIXUP_TPT470_DOCK,
5505 ALC255_FIXUP_DUMMY_LINEOUT_VERB,
5506 ALC255_FIXUP_DELL_HEADSET_MIC,
5449}; 5507};
5450 5508
5451static const struct hda_fixup alc269_fixups[] = { 5509static const struct hda_fixup alc269_fixups[] = {
@@ -5556,6 +5614,10 @@ static const struct hda_fixup alc269_fixups[] = {
5556 .type = HDA_FIXUP_FUNC, 5614 .type = HDA_FIXUP_FUNC,
5557 .v.func = alc269_fixup_pincfg_no_hp_to_lineout, 5615 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
5558 }, 5616 },
5617 [ALC255_FIXUP_LIFEBOOK_U7x7_HEADSET_MIC] = {
5618 .type = HDA_FIXUP_FUNC,
5619 .v.func = alc269_fixup_pincfg_U7x7_headset_mic,
5620 },
5559 [ALC269_FIXUP_AMIC] = { 5621 [ALC269_FIXUP_AMIC] = {
5560 .type = HDA_FIXUP_PINS, 5622 .type = HDA_FIXUP_PINS,
5561 .v.pins = (const struct hda_pintbl[]) { 5623 .v.pins = (const struct hda_pintbl[]) {
@@ -6156,6 +6218,10 @@ static const struct hda_fixup alc269_fixups[] = {
6156 .chained = true, 6218 .chained = true,
6157 .chain_id = ALC298_FIXUP_DELL_AIO_MIC_NO_PRESENCE, 6219 .chain_id = ALC298_FIXUP_DELL_AIO_MIC_NO_PRESENCE,
6158 }, 6220 },
6221 [ALC295_FIXUP_DISABLE_DAC3] = {
6222 .type = HDA_FIXUP_FUNC,
6223 .v.func = alc295_fixup_disable_dac3,
6224 },
6159 [ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER] = { 6225 [ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER] = {
6160 .type = HDA_FIXUP_PINS, 6226 .type = HDA_FIXUP_PINS,
6161 .v.pins = (const struct hda_pintbl[]) { 6227 .v.pins = (const struct hda_pintbl[]) {
@@ -6241,6 +6307,18 @@ static const struct hda_fixup alc269_fixups[] = {
6241 { } 6307 { }
6242 }, 6308 },
6243 }, 6309 },
6310 [ALC225_FIXUP_DELL_WYSE_MIC_NO_PRESENCE] = {
6311 .type = HDA_FIXUP_PINS,
6312 .v.pins = (const struct hda_pintbl[]) {
6313 { 0x16, 0x0101102f }, /* Rear Headset HP */
6314 { 0x19, 0x02a1913c }, /* use as Front headset mic, without its own jack detect */
6315 { 0x1a, 0x01a19030 }, /* Rear Headset MIC */
6316 { 0x1b, 0x02011020 },
6317 { }
6318 },
6319 .chained = true,
6320 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
6321 },
6244 [ALC700_FIXUP_INTEL_REFERENCE] = { 6322 [ALC700_FIXUP_INTEL_REFERENCE] = {
6245 .type = HDA_FIXUP_VERBS, 6323 .type = HDA_FIXUP_VERBS,
6246 .v.verbs = (const struct hda_verb[]) { 6324 .v.verbs = (const struct hda_verb[]) {
@@ -6271,6 +6349,28 @@ static const struct hda_fixup alc269_fixups[] = {
6271 .chained = true, 6349 .chained = true,
6272 .chain_id = ALC274_FIXUP_DELL_BIND_DACS 6350 .chain_id = ALC274_FIXUP_DELL_BIND_DACS
6273 }, 6351 },
6352 [ALC298_FIXUP_TPT470_DOCK] = {
6353 .type = HDA_FIXUP_FUNC,
6354 .v.func = alc_fixup_tpt470_dock,
6355 .chained = true,
6356 .chain_id = ALC293_FIXUP_LENOVO_SPK_NOISE
6357 },
6358 [ALC255_FIXUP_DUMMY_LINEOUT_VERB] = {
6359 .type = HDA_FIXUP_PINS,
6360 .v.pins = (const struct hda_pintbl[]) {
6361 { 0x14, 0x0201101f },
6362 { }
6363 },
6364 .chained = true,
6365 .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE
6366 },
6367 [ALC255_FIXUP_DELL_HEADSET_MIC] = {
6368 .type = HDA_FIXUP_PINS,
6369 .v.pins = (const struct hda_pintbl[]) {
6370 { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
6371 { }
6372 },
6373 },
6274}; 6374};
6275 6375
6276static const struct snd_pci_quirk alc269_fixup_tbl[] = { 6376static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -6319,8 +6419,15 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6319 SND_PCI_QUIRK(0x1028, 0x0725, "Dell Inspiron 3162", ALC255_FIXUP_DELL_SPK_NOISE), 6419 SND_PCI_QUIRK(0x1028, 0x0725, "Dell Inspiron 3162", ALC255_FIXUP_DELL_SPK_NOISE),
6320 SND_PCI_QUIRK(0x1028, 0x075b, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE), 6420 SND_PCI_QUIRK(0x1028, 0x075b, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE),
6321 SND_PCI_QUIRK(0x1028, 0x075d, "Dell AIO", ALC298_FIXUP_SPK_VOLUME), 6421 SND_PCI_QUIRK(0x1028, 0x075d, "Dell AIO", ALC298_FIXUP_SPK_VOLUME),
6422 SND_PCI_QUIRK(0x1028, 0x07b0, "Dell Precision 7520", ALC295_FIXUP_DISABLE_DAC3),
6322 SND_PCI_QUIRK(0x1028, 0x0798, "Dell Inspiron 17 7000 Gaming", ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER), 6423 SND_PCI_QUIRK(0x1028, 0x0798, "Dell Inspiron 17 7000 Gaming", ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER),
6424 SND_PCI_QUIRK(0x1028, 0x080c, "Dell WYSE", ALC225_FIXUP_DELL_WYSE_MIC_NO_PRESENCE),
6323 SND_PCI_QUIRK(0x1028, 0x082a, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE), 6425 SND_PCI_QUIRK(0x1028, 0x082a, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE),
6426 SND_PCI_QUIRK(0x1028, 0x084b, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB),
6427 SND_PCI_QUIRK(0x1028, 0x084e, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB),
6428 SND_PCI_QUIRK(0x1028, 0x0871, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC),
6429 SND_PCI_QUIRK(0x1028, 0x0872, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC),
6430 SND_PCI_QUIRK(0x1028, 0x0873, "Dell Precision 3930", ALC255_FIXUP_DUMMY_LINEOUT_VERB),
6324 SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 6431 SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
6325 SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 6432 SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
6326 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2), 6433 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
@@ -6422,6 +6529,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6422 SND_PCI_QUIRK(0x10cf, 0x159f, "Lifebook E780", ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT), 6529 SND_PCI_QUIRK(0x10cf, 0x159f, "Lifebook E780", ALC269_FIXUP_LIFEBOOK_NO_HP_TO_LINEOUT),
6423 SND_PCI_QUIRK(0x10cf, 0x15dc, "Lifebook T731", ALC269_FIXUP_LIFEBOOK_HP_PIN), 6530 SND_PCI_QUIRK(0x10cf, 0x15dc, "Lifebook T731", ALC269_FIXUP_LIFEBOOK_HP_PIN),
6424 SND_PCI_QUIRK(0x10cf, 0x1757, "Lifebook E752", ALC269_FIXUP_LIFEBOOK_HP_PIN), 6531 SND_PCI_QUIRK(0x10cf, 0x1757, "Lifebook E752", ALC269_FIXUP_LIFEBOOK_HP_PIN),
6532 SND_PCI_QUIRK(0x10cf, 0x1629, "Lifebook U7x7", ALC255_FIXUP_LIFEBOOK_U7x7_HEADSET_MIC),
6425 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC), 6533 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
6426 SND_PCI_QUIRK(0x10ec, 0x10f2, "Intel Reference board", ALC700_FIXUP_INTEL_REFERENCE), 6534 SND_PCI_QUIRK(0x10ec, 0x10f2, "Intel Reference board", ALC700_FIXUP_INTEL_REFERENCE),
6427 SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC), 6535 SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC),
@@ -6450,8 +6558,18 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6450 SND_PCI_QUIRK(0x17aa, 0x2218, "Thinkpad X1 Carbon 2nd", ALC292_FIXUP_TPT440_DOCK), 6558 SND_PCI_QUIRK(0x17aa, 0x2218, "Thinkpad X1 Carbon 2nd", ALC292_FIXUP_TPT440_DOCK),
6451 SND_PCI_QUIRK(0x17aa, 0x2223, "ThinkPad T550", ALC292_FIXUP_TPT440_DOCK), 6559 SND_PCI_QUIRK(0x17aa, 0x2223, "ThinkPad T550", ALC292_FIXUP_TPT440_DOCK),
6452 SND_PCI_QUIRK(0x17aa, 0x2226, "ThinkPad X250", ALC292_FIXUP_TPT440_DOCK), 6560 SND_PCI_QUIRK(0x17aa, 0x2226, "ThinkPad X250", ALC292_FIXUP_TPT440_DOCK),
6561 SND_PCI_QUIRK(0x17aa, 0x222d, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6562 SND_PCI_QUIRK(0x17aa, 0x222e, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6453 SND_PCI_QUIRK(0x17aa, 0x2231, "Thinkpad T560", ALC292_FIXUP_TPT460), 6563 SND_PCI_QUIRK(0x17aa, 0x2231, "Thinkpad T560", ALC292_FIXUP_TPT460),
6454 SND_PCI_QUIRK(0x17aa, 0x2233, "Thinkpad", ALC292_FIXUP_TPT460), 6564 SND_PCI_QUIRK(0x17aa, 0x2233, "Thinkpad", ALC292_FIXUP_TPT460),
6565 SND_PCI_QUIRK(0x17aa, 0x2245, "Thinkpad T470", ALC298_FIXUP_TPT470_DOCK),
6566 SND_PCI_QUIRK(0x17aa, 0x2246, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6567 SND_PCI_QUIRK(0x17aa, 0x2247, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6568 SND_PCI_QUIRK(0x17aa, 0x2249, "Thinkpad", ALC292_FIXUP_TPT460),
6569 SND_PCI_QUIRK(0x17aa, 0x224b, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6570 SND_PCI_QUIRK(0x17aa, 0x224c, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6571 SND_PCI_QUIRK(0x17aa, 0x224d, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6572 SND_PCI_QUIRK(0x17aa, 0x225d, "Thinkpad T480", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6455 SND_PCI_QUIRK(0x17aa, 0x30bb, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY), 6573 SND_PCI_QUIRK(0x17aa, 0x30bb, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
6456 SND_PCI_QUIRK(0x17aa, 0x30e2, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY), 6574 SND_PCI_QUIRK(0x17aa, 0x30e2, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
6457 SND_PCI_QUIRK(0x17aa, 0x310c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION), 6575 SND_PCI_QUIRK(0x17aa, 0x310c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
@@ -6472,7 +6590,12 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6472 SND_PCI_QUIRK(0x17aa, 0x5050, "Thinkpad T560p", ALC292_FIXUP_TPT460), 6590 SND_PCI_QUIRK(0x17aa, 0x5050, "Thinkpad T560p", ALC292_FIXUP_TPT460),
6473 SND_PCI_QUIRK(0x17aa, 0x5051, "Thinkpad L460", ALC292_FIXUP_TPT460), 6591 SND_PCI_QUIRK(0x17aa, 0x5051, "Thinkpad L460", ALC292_FIXUP_TPT460),
6474 SND_PCI_QUIRK(0x17aa, 0x5053, "Thinkpad T460", ALC292_FIXUP_TPT460), 6592 SND_PCI_QUIRK(0x17aa, 0x5053, "Thinkpad T460", ALC292_FIXUP_TPT460),
6593 SND_PCI_QUIRK(0x17aa, 0x505d, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6594 SND_PCI_QUIRK(0x17aa, 0x505f, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6595 SND_PCI_QUIRK(0x17aa, 0x5062, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6475 SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 6596 SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
6597 SND_PCI_QUIRK(0x17aa, 0x511e, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6598 SND_PCI_QUIRK(0x17aa, 0x511f, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
6476 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K), 6599 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
6477 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), 6600 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
6478 SND_PCI_QUIRK(0x1b7d, 0xa831, "Ordissimo EVE2 ", ALC269VB_FIXUP_ORDISSIMO_EVE2), /* Also known as Malata PC-B1303 */ 6601 SND_PCI_QUIRK(0x1b7d, 0xa831, "Ordissimo EVE2 ", ALC269VB_FIXUP_ORDISSIMO_EVE2), /* Also known as Malata PC-B1303 */
@@ -6735,6 +6858,11 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
6735 {0x14, 0x90170110}, 6858 {0x14, 0x90170110},
6736 {0x21, 0x02211020}), 6859 {0x21, 0x02211020}),
6737 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, 6860 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6861 {0x12, 0x90a60130},
6862 {0x14, 0x90170110},
6863 {0x14, 0x01011020},
6864 {0x21, 0x0221101f}),
6865 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
6738 ALC256_STANDARD_PINS), 6866 ALC256_STANDARD_PINS),
6739 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1043, "ASUS", ALC256_FIXUP_ASUS_MIC, 6867 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1043, "ASUS", ALC256_FIXUP_ASUS_MIC,
6740 {0x14, 0x90170110}, 6868 {0x14, 0x90170110},
@@ -6803,6 +6931,10 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
6803 {0x12, 0x90a60120}, 6931 {0x12, 0x90a60120},
6804 {0x14, 0x90170110}, 6932 {0x14, 0x90170110},
6805 {0x21, 0x0321101f}), 6933 {0x21, 0x0321101f}),
6934 SND_HDA_PIN_QUIRK(0x10ec0289, 0x1028, "Dell", ALC269_FIXUP_DELL4_MIC_NO_PRESENCE,
6935 {0x12, 0xb7a60130},
6936 {0x14, 0x90170110},
6937 {0x21, 0x04211020}),
6806 SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1, 6938 SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
6807 ALC290_STANDARD_PINS, 6939 ALC290_STANDARD_PINS,
6808 {0x15, 0x04211040}, 6940 {0x15, 0x04211040},
@@ -7038,6 +7170,8 @@ static int patch_alc269(struct hda_codec *codec)
7038 break; 7170 break;
7039 case 0x10ec0257: 7171 case 0x10ec0257:
7040 spec->codec_variant = ALC269_TYPE_ALC257; 7172 spec->codec_variant = ALC269_TYPE_ALC257;
7173 spec->shutup = alc256_shutup;
7174 spec->init_hook = alc256_init;
7041 spec->gen.mixer_nid = 0; 7175 spec->gen.mixer_nid = 0;
7042 break; 7176 break;
7043 case 0x10ec0215: 7177 case 0x10ec0215:
diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c
index c33a512283a4..9fb356db3ab2 100644
--- a/sound/soc/amd/acp-pcm-dma.c
+++ b/sound/soc/amd/acp-pcm-dma.c
@@ -579,13 +579,6 @@ static int acp_init(void __iomem *acp_mmio, u32 asic_type)
579 for (bank = 1; bank < 48; bank++) 579 for (bank = 1; bank < 48; bank++)
580 acp_set_sram_bank_state(acp_mmio, bank, false); 580 acp_set_sram_bank_state(acp_mmio, bank, false);
581 } 581 }
582
583 /* Stoney supports 16bit resolution */
584 if (asic_type == CHIP_STONEY) {
585 val = acp_reg_read(acp_mmio, mmACP_I2S_16BIT_RESOLUTION_EN);
586 val |= 0x03;
587 acp_reg_write(val, acp_mmio, mmACP_I2S_16BIT_RESOLUTION_EN);
588 }
589 return 0; 582 return 0;
590} 583}
591 584
@@ -774,6 +767,7 @@ static int acp_dma_hw_params(struct snd_pcm_substream *substream,
774{ 767{
775 int status; 768 int status;
776 uint64_t size; 769 uint64_t size;
770 u32 val = 0;
777 struct page *pg; 771 struct page *pg;
778 struct snd_pcm_runtime *runtime; 772 struct snd_pcm_runtime *runtime;
779 struct audio_substream_data *rtd; 773 struct audio_substream_data *rtd;
@@ -786,6 +780,14 @@ static int acp_dma_hw_params(struct snd_pcm_substream *substream,
786 if (WARN_ON(!rtd)) 780 if (WARN_ON(!rtd))
787 return -EINVAL; 781 return -EINVAL;
788 782
783 if (adata->asic_type == CHIP_STONEY) {
784 val = acp_reg_read(adata->acp_mmio, mmACP_I2S_16BIT_RESOLUTION_EN);
785 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
786 val |= ACP_I2S_SP_16BIT_RESOLUTION_EN;
787 else
788 val |= ACP_I2S_MIC_16BIT_RESOLUTION_EN;
789 acp_reg_write(val, adata->acp_mmio, mmACP_I2S_16BIT_RESOLUTION_EN);
790 }
789 size = params_buffer_bytes(params); 791 size = params_buffer_bytes(params);
790 status = snd_pcm_lib_malloc_pages(substream, size); 792 status = snd_pcm_lib_malloc_pages(substream, size);
791 if (status < 0) 793 if (status < 0)
diff --git a/sound/soc/amd/acp.h b/sound/soc/amd/acp.h
index ecb458935d1e..9293f179f272 100644
--- a/sound/soc/amd/acp.h
+++ b/sound/soc/amd/acp.h
@@ -70,6 +70,8 @@
70#define CAPTURE_END_DMA_DESCR_CH15 7 70#define CAPTURE_END_DMA_DESCR_CH15 7
71 71
72#define mmACP_I2S_16BIT_RESOLUTION_EN 0x5209 72#define mmACP_I2S_16BIT_RESOLUTION_EN 0x5209
73#define ACP_I2S_MIC_16BIT_RESOLUTION_EN 0x01
74#define ACP_I2S_SP_16BIT_RESOLUTION_EN 0x02
73enum acp_dma_priority_level { 75enum acp_dma_priority_level {
74 /* 0x0 Specifies the DMA channel is given normal priority */ 76 /* 0x0 Specifies the DMA channel is given normal priority */
75 ACP_DMA_PRIORITY_LEVEL_NORMAL = 0x0, 77 ACP_DMA_PRIORITY_LEVEL_NORMAL = 0x0,
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 5672e516bec3..c1830ccd3bb8 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -798,12 +798,7 @@ static int hdmi_codec_probe(struct platform_device *pdev)
798 798
799static int hdmi_codec_remove(struct platform_device *pdev) 799static int hdmi_codec_remove(struct platform_device *pdev)
800{ 800{
801 struct device *dev = &pdev->dev; 801 snd_soc_unregister_codec(&pdev->dev);
802 struct hdmi_codec_priv *hcp;
803
804 hcp = dev_get_drvdata(dev);
805 kfree(hcp->chmap_info);
806 snd_soc_unregister_codec(dev);
807 802
808 return 0; 803 return 0;
809} 804}
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 831b297978a4..45a73049cf64 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -1722,6 +1722,7 @@ static const struct regmap_config rt5651_regmap = {
1722 .num_reg_defaults = ARRAY_SIZE(rt5651_reg), 1722 .num_reg_defaults = ARRAY_SIZE(rt5651_reg),
1723 .ranges = rt5651_ranges, 1723 .ranges = rt5651_ranges,
1724 .num_ranges = ARRAY_SIZE(rt5651_ranges), 1724 .num_ranges = ARRAY_SIZE(rt5651_ranges),
1725 .use_single_rw = true,
1725}; 1726};
1726 1727
1727#if defined(CONFIG_OF) 1728#if defined(CONFIG_OF)
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index e1ab5537d27a..c5c76ab8ccf1 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -529,10 +529,15 @@ static const struct snd_kcontrol_new sgtl5000_snd_controls[] = {
529static int sgtl5000_digital_mute(struct snd_soc_dai *codec_dai, int mute) 529static int sgtl5000_digital_mute(struct snd_soc_dai *codec_dai, int mute)
530{ 530{
531 struct snd_soc_codec *codec = codec_dai->codec; 531 struct snd_soc_codec *codec = codec_dai->codec;
532 u16 adcdac_ctrl = SGTL5000_DAC_MUTE_LEFT | SGTL5000_DAC_MUTE_RIGHT; 532 u16 i2s_pwr = SGTL5000_I2S_IN_POWERUP;
533 533
534 snd_soc_update_bits(codec, SGTL5000_CHIP_ADCDAC_CTRL, 534 /*
535 adcdac_ctrl, mute ? adcdac_ctrl : 0); 535 * During 'digital mute' do not mute DAC
536 * because LINE_IN would be muted aswell. We want to mute
537 * only I2S block - this can be done by powering it off
538 */
539 snd_soc_update_bits(codec, SGTL5000_CHIP_DIG_POWER,
540 i2s_pwr, mute ? 0 : i2s_pwr);
536 541
537 return 0; 542 return 0;
538} 543}
@@ -871,15 +876,26 @@ static int sgtl5000_pcm_hw_params(struct snd_pcm_substream *substream,
871static int sgtl5000_set_bias_level(struct snd_soc_codec *codec, 876static int sgtl5000_set_bias_level(struct snd_soc_codec *codec,
872 enum snd_soc_bias_level level) 877 enum snd_soc_bias_level level)
873{ 878{
879 struct sgtl5000_priv *sgtl = snd_soc_codec_get_drvdata(codec);
880 int ret;
881
874 switch (level) { 882 switch (level) {
875 case SND_SOC_BIAS_ON: 883 case SND_SOC_BIAS_ON:
876 case SND_SOC_BIAS_PREPARE: 884 case SND_SOC_BIAS_PREPARE:
877 case SND_SOC_BIAS_STANDBY: 885 case SND_SOC_BIAS_STANDBY:
886 regcache_cache_only(sgtl->regmap, false);
887 ret = regcache_sync(sgtl->regmap);
888 if (ret) {
889 regcache_cache_only(sgtl->regmap, true);
890 return ret;
891 }
892
878 snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER, 893 snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
879 SGTL5000_REFTOP_POWERUP, 894 SGTL5000_REFTOP_POWERUP,
880 SGTL5000_REFTOP_POWERUP); 895 SGTL5000_REFTOP_POWERUP);
881 break; 896 break;
882 case SND_SOC_BIAS_OFF: 897 case SND_SOC_BIAS_OFF:
898 regcache_cache_only(sgtl->regmap, true);
883 snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER, 899 snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
884 SGTL5000_REFTOP_POWERUP, 0); 900 SGTL5000_REFTOP_POWERUP, 0);
885 break; 901 break;
@@ -1237,6 +1253,10 @@ static int sgtl5000_probe(struct snd_soc_codec *codec)
1237 */ 1253 */
1238 snd_soc_write(codec, SGTL5000_DAP_CTRL, 0); 1254 snd_soc_write(codec, SGTL5000_DAP_CTRL, 0);
1239 1255
1256 /* Unmute DAC after start */
1257 snd_soc_update_bits(codec, SGTL5000_CHIP_ADCDAC_CTRL,
1258 SGTL5000_DAC_MUTE_LEFT | SGTL5000_DAC_MUTE_RIGHT, 0);
1259
1240 return 0; 1260 return 0;
1241 1261
1242err: 1262err:
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index 66e32f5d2917..989d093abda7 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -1204,12 +1204,14 @@ static int wmfw_add_ctl(struct wm_adsp *dsp, struct wm_coeff_ctl *ctl)
1204 kcontrol->put = wm_coeff_put_acked; 1204 kcontrol->put = wm_coeff_put_acked;
1205 break; 1205 break;
1206 default: 1206 default:
1207 kcontrol->get = wm_coeff_get; 1207 if (kcontrol->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
1208 kcontrol->put = wm_coeff_put; 1208 ctl->bytes_ext.max = ctl->len;
1209 1209 ctl->bytes_ext.get = wm_coeff_tlv_get;
1210 ctl->bytes_ext.max = ctl->len; 1210 ctl->bytes_ext.put = wm_coeff_tlv_put;
1211 ctl->bytes_ext.get = wm_coeff_tlv_get; 1211 } else {
1212 ctl->bytes_ext.put = wm_coeff_tlv_put; 1212 kcontrol->get = wm_coeff_get;
1213 kcontrol->put = wm_coeff_put;
1214 }
1213 break; 1215 break;
1214 } 1216 }
1215 1217
diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
index dca1143c1150..a4aa931ebfae 100644
--- a/sound/soc/sunxi/sun4i-i2s.c
+++ b/sound/soc/sunxi/sun4i-i2s.c
@@ -104,7 +104,7 @@
104 104
105#define SUN8I_I2S_CHAN_CFG_REG 0x30 105#define SUN8I_I2S_CHAN_CFG_REG 0x30
106#define SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM_MASK GENMASK(6, 4) 106#define SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM_MASK GENMASK(6, 4)
107#define SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM(chan) (chan - 1) 107#define SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM(chan) ((chan - 1) << 4)
108#define SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM_MASK GENMASK(2, 0) 108#define SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM_MASK GENMASK(2, 0)
109#define SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM(chan) (chan - 1) 109#define SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM(chan) (chan - 1)
110 110
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 9afb8ab524c7..06b22624ab7a 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -347,17 +347,20 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request,
347 int validx, int *value_ret) 347 int validx, int *value_ret)
348{ 348{
349 struct snd_usb_audio *chip = cval->head.mixer->chip; 349 struct snd_usb_audio *chip = cval->head.mixer->chip;
350 unsigned char buf[4 + 3 * sizeof(__u32)]; /* enough space for one range */ 350 /* enough space for one range */
351 unsigned char buf[sizeof(__u16) + 3 * sizeof(__u32)];
351 unsigned char *val; 352 unsigned char *val;
352 int idx = 0, ret, size; 353 int idx = 0, ret, val_size, size;
353 __u8 bRequest; 354 __u8 bRequest;
354 355
356 val_size = uac2_ctl_value_size(cval->val_type);
357
355 if (request == UAC_GET_CUR) { 358 if (request == UAC_GET_CUR) {
356 bRequest = UAC2_CS_CUR; 359 bRequest = UAC2_CS_CUR;
357 size = uac2_ctl_value_size(cval->val_type); 360 size = val_size;
358 } else { 361 } else {
359 bRequest = UAC2_CS_RANGE; 362 bRequest = UAC2_CS_RANGE;
360 size = sizeof(buf); 363 size = sizeof(__u16) + 3 * val_size;
361 } 364 }
362 365
363 memset(buf, 0, sizeof(buf)); 366 memset(buf, 0, sizeof(buf));
@@ -390,16 +393,17 @@ error:
390 val = buf + sizeof(__u16); 393 val = buf + sizeof(__u16);
391 break; 394 break;
392 case UAC_GET_MAX: 395 case UAC_GET_MAX:
393 val = buf + sizeof(__u16) * 2; 396 val = buf + sizeof(__u16) + val_size;
394 break; 397 break;
395 case UAC_GET_RES: 398 case UAC_GET_RES:
396 val = buf + sizeof(__u16) * 3; 399 val = buf + sizeof(__u16) + val_size * 2;
397 break; 400 break;
398 default: 401 default:
399 return -EINVAL; 402 return -EINVAL;
400 } 403 }
401 404
402 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(val, sizeof(__u16))); 405 *value_ret = convert_signed_value(cval,
406 snd_usb_combine_bytes(val, val_size));
403 407
404 return 0; 408 return 0;
405} 409}
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index b9c9a19f9588..3cbfae6604f9 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -357,6 +357,15 @@ static int set_sync_ep_implicit_fb_quirk(struct snd_usb_substream *subs,
357 357
358 alts = &iface->altsetting[1]; 358 alts = &iface->altsetting[1];
359 goto add_sync_ep; 359 goto add_sync_ep;
360 case USB_ID(0x1397, 0x0002):
361 ep = 0x81;
362 iface = usb_ifnum_to_if(dev, 1);
363
364 if (!iface || iface->num_altsetting == 0)
365 return -EINVAL;
366
367 alts = &iface->altsetting[1];
368 goto add_sync_ep;
360 369
361 } 370 }
362 if (attr == USB_ENDPOINT_SYNC_ASYNC && 371 if (attr == USB_ENDPOINT_SYNC_ASYNC &&
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index 50252046b01d..754e632a27bd 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -3325,4 +3325,51 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
3325 } 3325 }
3326}, 3326},
3327 3327
3328{
3329 /*
3330 * Bower's & Wilkins PX headphones only support the 48 kHz sample rate
3331 * even though it advertises more. The capture interface doesn't work
3332 * even on windows.
3333 */
3334 USB_DEVICE(0x19b5, 0x0021),
3335 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
3336 .ifnum = QUIRK_ANY_INTERFACE,
3337 .type = QUIRK_COMPOSITE,
3338 .data = (const struct snd_usb_audio_quirk[]) {
3339 {
3340 .ifnum = 0,
3341 .type = QUIRK_AUDIO_STANDARD_MIXER,
3342 },
3343 /* Capture */
3344 {
3345 .ifnum = 1,
3346 .type = QUIRK_IGNORE_INTERFACE,
3347 },
3348 /* Playback */
3349 {
3350 .ifnum = 2,
3351 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
3352 .data = &(const struct audioformat) {
3353 .formats = SNDRV_PCM_FMTBIT_S16_LE,
3354 .channels = 2,
3355 .iface = 2,
3356 .altsetting = 1,
3357 .altset_idx = 1,
3358 .attributes = UAC_EP_CS_ATTR_FILL_MAX |
3359 UAC_EP_CS_ATTR_SAMPLE_RATE,
3360 .endpoint = 0x03,
3361 .ep_attr = USB_ENDPOINT_XFER_ISOC,
3362 .rates = SNDRV_PCM_RATE_48000,
3363 .rate_min = 48000,
3364 .rate_max = 48000,
3365 .nr_rates = 1,
3366 .rate_table = (unsigned int[]) {
3367 48000
3368 }
3369 }
3370 },
3371 }
3372 }
3373},
3374
3328#undef USB_DEVICE_VENDOR_SPEC 3375#undef USB_DEVICE_VENDOR_SPEC
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index a66ef5777887..ea8f3de92fa4 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1363,8 +1363,11 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
1363 return SNDRV_PCM_FMTBIT_DSD_U32_BE; 1363 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1364 break; 1364 break;
1365 1365
1366 /* Amanero Combo384 USB interface with native DSD support */ 1366 /* Amanero Combo384 USB based DACs with native DSD support */
1367 case USB_ID(0x16d0, 0x071a): 1367 case USB_ID(0x16d0, 0x071a): /* Amanero - Combo384 */
1368 case USB_ID(0x2ab6, 0x0004): /* T+A DAC8DSD-V2.0, MP1000E-V2.0, MP2000R-V2.0, MP2500R-V2.0, MP3100HV-V2.0 */
1369 case USB_ID(0x2ab6, 0x0005): /* T+A USB HD Audio 1 */
1370 case USB_ID(0x2ab6, 0x0006): /* T+A USB HD Audio 2 */
1368 if (fp->altsetting == 2) { 1371 if (fp->altsetting == 2) {
1369 switch (le16_to_cpu(chip->dev->descriptor.bcdDevice)) { 1372 switch (le16_to_cpu(chip->dev->descriptor.bcdDevice)) {
1370 case 0x199: 1373 case 0x199:
diff --git a/sound/x86/intel_hdmi_audio.c b/sound/x86/intel_hdmi_audio.c
index a0951505c7f5..4ed9d0c41843 100644
--- a/sound/x86/intel_hdmi_audio.c
+++ b/sound/x86/intel_hdmi_audio.c
@@ -50,6 +50,7 @@
50/*standard module options for ALSA. This module supports only one card*/ 50/*standard module options for ALSA. This module supports only one card*/
51static int hdmi_card_index = SNDRV_DEFAULT_IDX1; 51static int hdmi_card_index = SNDRV_DEFAULT_IDX1;
52static char *hdmi_card_id = SNDRV_DEFAULT_STR1; 52static char *hdmi_card_id = SNDRV_DEFAULT_STR1;
53static bool single_port;
53 54
54module_param_named(index, hdmi_card_index, int, 0444); 55module_param_named(index, hdmi_card_index, int, 0444);
55MODULE_PARM_DESC(index, 56MODULE_PARM_DESC(index,
@@ -57,6 +58,9 @@ MODULE_PARM_DESC(index,
57module_param_named(id, hdmi_card_id, charp, 0444); 58module_param_named(id, hdmi_card_id, charp, 0444);
58MODULE_PARM_DESC(id, 59MODULE_PARM_DESC(id,
59 "ID string for INTEL Intel HDMI Audio controller."); 60 "ID string for INTEL Intel HDMI Audio controller.");
61module_param(single_port, bool, 0444);
62MODULE_PARM_DESC(single_port,
63 "Single-port mode (for compatibility)");
60 64
61/* 65/*
62 * ELD SA bits in the CEA Speaker Allocation data block 66 * ELD SA bits in the CEA Speaker Allocation data block
@@ -1579,7 +1583,11 @@ static irqreturn_t display_pipe_interrupt_handler(int irq, void *dev_id)
1579static void notify_audio_lpe(struct platform_device *pdev, int port) 1583static void notify_audio_lpe(struct platform_device *pdev, int port)
1580{ 1584{
1581 struct snd_intelhad_card *card_ctx = platform_get_drvdata(pdev); 1585 struct snd_intelhad_card *card_ctx = platform_get_drvdata(pdev);
1582 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port]; 1586 struct snd_intelhad *ctx;
1587
1588 ctx = &card_ctx->pcm_ctx[single_port ? 0 : port];
1589 if (single_port)
1590 ctx->port = port;
1583 1591
1584 schedule_work(&ctx->hdmi_audio_wq); 1592 schedule_work(&ctx->hdmi_audio_wq);
1585} 1593}
@@ -1743,6 +1751,7 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev)
1743{ 1751{
1744 struct snd_card *card; 1752 struct snd_card *card;
1745 struct snd_intelhad_card *card_ctx; 1753 struct snd_intelhad_card *card_ctx;
1754 struct snd_intelhad *ctx;
1746 struct snd_pcm *pcm; 1755 struct snd_pcm *pcm;
1747 struct intel_hdmi_lpe_audio_pdata *pdata; 1756 struct intel_hdmi_lpe_audio_pdata *pdata;
1748 int irq; 1757 int irq;
@@ -1787,6 +1796,21 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev)
1787 1796
1788 platform_set_drvdata(pdev, card_ctx); 1797 platform_set_drvdata(pdev, card_ctx);
1789 1798
1799 card_ctx->num_pipes = pdata->num_pipes;
1800 card_ctx->num_ports = single_port ? 1 : pdata->num_ports;
1801
1802 for_each_port(card_ctx, port) {
1803 ctx = &card_ctx->pcm_ctx[port];
1804 ctx->card_ctx = card_ctx;
1805 ctx->dev = card_ctx->dev;
1806 ctx->port = single_port ? -1 : port;
1807 ctx->pipe = -1;
1808
1809 spin_lock_init(&ctx->had_spinlock);
1810 mutex_init(&ctx->mutex);
1811 INIT_WORK(&ctx->hdmi_audio_wq, had_audio_wq);
1812 }
1813
1790 dev_dbg(&pdev->dev, "%s: mmio_start = 0x%x, mmio_end = 0x%x\n", 1814 dev_dbg(&pdev->dev, "%s: mmio_start = 0x%x, mmio_end = 0x%x\n",
1791 __func__, (unsigned int)res_mmio->start, 1815 __func__, (unsigned int)res_mmio->start,
1792 (unsigned int)res_mmio->end); 1816 (unsigned int)res_mmio->end);
@@ -1816,19 +1840,12 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev)
1816 init_channel_allocations(); 1840 init_channel_allocations();
1817 1841
1818 card_ctx->num_pipes = pdata->num_pipes; 1842 card_ctx->num_pipes = pdata->num_pipes;
1819 card_ctx->num_ports = pdata->num_ports; 1843 card_ctx->num_ports = single_port ? 1 : pdata->num_ports;
1820 1844
1821 for_each_port(card_ctx, port) { 1845 for_each_port(card_ctx, port) {
1822 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
1823 int i; 1846 int i;
1824 1847
1825 ctx->card_ctx = card_ctx; 1848 ctx = &card_ctx->pcm_ctx[port];
1826 ctx->dev = card_ctx->dev;
1827 ctx->port = port;
1828 ctx->pipe = -1;
1829
1830 INIT_WORK(&ctx->hdmi_audio_wq, had_audio_wq);
1831
1832 ret = snd_pcm_new(card, INTEL_HAD, port, MAX_PB_STREAMS, 1849 ret = snd_pcm_new(card, INTEL_HAD, port, MAX_PB_STREAMS,
1833 MAX_CAP_STREAMS, &pcm); 1850 MAX_CAP_STREAMS, &pcm);
1834 if (ret) 1851 if (ret)
diff --git a/tools/arch/powerpc/include/uapi/asm/kvm.h b/tools/arch/powerpc/include/uapi/asm/kvm.h
index 637b7263cb86..833ed9a16adf 100644
--- a/tools/arch/powerpc/include/uapi/asm/kvm.h
+++ b/tools/arch/powerpc/include/uapi/asm/kvm.h
@@ -632,6 +632,8 @@ struct kvm_ppc_cpu_char {
632#define KVM_REG_PPC_TIDR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbc) 632#define KVM_REG_PPC_TIDR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbc)
633#define KVM_REG_PPC_PSSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbd) 633#define KVM_REG_PPC_PSSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbd)
634 634
635#define KVM_REG_PPC_DEC_EXPIRY (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbe)
636
635/* Transactional Memory checkpointed state: 637/* Transactional Memory checkpointed state:
636 * This is all GPRs, all VSX regs and a subset of SPRs 638 * This is all GPRs, all VSX regs and a subset of SPRs
637 */ 639 */
diff --git a/tools/arch/s390/include/uapi/asm/unistd.h b/tools/arch/s390/include/uapi/asm/unistd.h
deleted file mode 100644
index 725120939051..000000000000
--- a/tools/arch/s390/include/uapi/asm/unistd.h
+++ /dev/null
@@ -1,412 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * S390 version
4 *
5 * Derived from "include/asm-i386/unistd.h"
6 */
7
8#ifndef _UAPI_ASM_S390_UNISTD_H_
9#define _UAPI_ASM_S390_UNISTD_H_
10
11/*
12 * This file contains the system call numbers.
13 */
14
15#define __NR_exit 1
16#define __NR_fork 2
17#define __NR_read 3
18#define __NR_write 4
19#define __NR_open 5
20#define __NR_close 6
21#define __NR_restart_syscall 7
22#define __NR_creat 8
23#define __NR_link 9
24#define __NR_unlink 10
25#define __NR_execve 11
26#define __NR_chdir 12
27#define __NR_mknod 14
28#define __NR_chmod 15
29#define __NR_lseek 19
30#define __NR_getpid 20
31#define __NR_mount 21
32#define __NR_umount 22
33#define __NR_ptrace 26
34#define __NR_alarm 27
35#define __NR_pause 29
36#define __NR_utime 30
37#define __NR_access 33
38#define __NR_nice 34
39#define __NR_sync 36
40#define __NR_kill 37
41#define __NR_rename 38
42#define __NR_mkdir 39
43#define __NR_rmdir 40
44#define __NR_dup 41
45#define __NR_pipe 42
46#define __NR_times 43
47#define __NR_brk 45
48#define __NR_signal 48
49#define __NR_acct 51
50#define __NR_umount2 52
51#define __NR_ioctl 54
52#define __NR_fcntl 55
53#define __NR_setpgid 57
54#define __NR_umask 60
55#define __NR_chroot 61
56#define __NR_ustat 62
57#define __NR_dup2 63
58#define __NR_getppid 64
59#define __NR_getpgrp 65
60#define __NR_setsid 66
61#define __NR_sigaction 67
62#define __NR_sigsuspend 72
63#define __NR_sigpending 73
64#define __NR_sethostname 74
65#define __NR_setrlimit 75
66#define __NR_getrusage 77
67#define __NR_gettimeofday 78
68#define __NR_settimeofday 79
69#define __NR_symlink 83
70#define __NR_readlink 85
71#define __NR_uselib 86
72#define __NR_swapon 87
73#define __NR_reboot 88
74#define __NR_readdir 89
75#define __NR_mmap 90
76#define __NR_munmap 91
77#define __NR_truncate 92
78#define __NR_ftruncate 93
79#define __NR_fchmod 94
80#define __NR_getpriority 96
81#define __NR_setpriority 97
82#define __NR_statfs 99
83#define __NR_fstatfs 100
84#define __NR_socketcall 102
85#define __NR_syslog 103
86#define __NR_setitimer 104
87#define __NR_getitimer 105
88#define __NR_stat 106
89#define __NR_lstat 107
90#define __NR_fstat 108
91#define __NR_lookup_dcookie 110
92#define __NR_vhangup 111
93#define __NR_idle 112
94#define __NR_wait4 114
95#define __NR_swapoff 115
96#define __NR_sysinfo 116
97#define __NR_ipc 117
98#define __NR_fsync 118
99#define __NR_sigreturn 119
100#define __NR_clone 120
101#define __NR_setdomainname 121
102#define __NR_uname 122
103#define __NR_adjtimex 124
104#define __NR_mprotect 125
105#define __NR_sigprocmask 126
106#define __NR_create_module 127
107#define __NR_init_module 128
108#define __NR_delete_module 129
109#define __NR_get_kernel_syms 130
110#define __NR_quotactl 131
111#define __NR_getpgid 132
112#define __NR_fchdir 133
113#define __NR_bdflush 134
114#define __NR_sysfs 135
115#define __NR_personality 136
116#define __NR_afs_syscall 137 /* Syscall for Andrew File System */
117#define __NR_getdents 141
118#define __NR_flock 143
119#define __NR_msync 144
120#define __NR_readv 145
121#define __NR_writev 146
122#define __NR_getsid 147
123#define __NR_fdatasync 148
124#define __NR__sysctl 149
125#define __NR_mlock 150
126#define __NR_munlock 151
127#define __NR_mlockall 152
128#define __NR_munlockall 153
129#define __NR_sched_setparam 154
130#define __NR_sched_getparam 155
131#define __NR_sched_setscheduler 156
132#define __NR_sched_getscheduler 157
133#define __NR_sched_yield 158
134#define __NR_sched_get_priority_max 159
135#define __NR_sched_get_priority_min 160
136#define __NR_sched_rr_get_interval 161
137#define __NR_nanosleep 162
138#define __NR_mremap 163
139#define __NR_query_module 167
140#define __NR_poll 168
141#define __NR_nfsservctl 169
142#define __NR_prctl 172
143#define __NR_rt_sigreturn 173
144#define __NR_rt_sigaction 174
145#define __NR_rt_sigprocmask 175
146#define __NR_rt_sigpending 176
147#define __NR_rt_sigtimedwait 177
148#define __NR_rt_sigqueueinfo 178
149#define __NR_rt_sigsuspend 179
150#define __NR_pread64 180
151#define __NR_pwrite64 181
152#define __NR_getcwd 183
153#define __NR_capget 184
154#define __NR_capset 185
155#define __NR_sigaltstack 186
156#define __NR_sendfile 187
157#define __NR_getpmsg 188
158#define __NR_putpmsg 189
159#define __NR_vfork 190
160#define __NR_pivot_root 217
161#define __NR_mincore 218
162#define __NR_madvise 219
163#define __NR_getdents64 220
164#define __NR_readahead 222
165#define __NR_setxattr 224
166#define __NR_lsetxattr 225
167#define __NR_fsetxattr 226
168#define __NR_getxattr 227
169#define __NR_lgetxattr 228
170#define __NR_fgetxattr 229
171#define __NR_listxattr 230
172#define __NR_llistxattr 231
173#define __NR_flistxattr 232
174#define __NR_removexattr 233
175#define __NR_lremovexattr 234
176#define __NR_fremovexattr 235
177#define __NR_gettid 236
178#define __NR_tkill 237
179#define __NR_futex 238
180#define __NR_sched_setaffinity 239
181#define __NR_sched_getaffinity 240
182#define __NR_tgkill 241
183/* Number 242 is reserved for tux */
184#define __NR_io_setup 243
185#define __NR_io_destroy 244
186#define __NR_io_getevents 245
187#define __NR_io_submit 246
188#define __NR_io_cancel 247
189#define __NR_exit_group 248
190#define __NR_epoll_create 249
191#define __NR_epoll_ctl 250
192#define __NR_epoll_wait 251
193#define __NR_set_tid_address 252
194#define __NR_fadvise64 253
195#define __NR_timer_create 254
196#define __NR_timer_settime 255
197#define __NR_timer_gettime 256
198#define __NR_timer_getoverrun 257
199#define __NR_timer_delete 258
200#define __NR_clock_settime 259
201#define __NR_clock_gettime 260
202#define __NR_clock_getres 261
203#define __NR_clock_nanosleep 262
204/* Number 263 is reserved for vserver */
205#define __NR_statfs64 265
206#define __NR_fstatfs64 266
207#define __NR_remap_file_pages 267
208#define __NR_mbind 268
209#define __NR_get_mempolicy 269
210#define __NR_set_mempolicy 270
211#define __NR_mq_open 271
212#define __NR_mq_unlink 272
213#define __NR_mq_timedsend 273
214#define __NR_mq_timedreceive 274
215#define __NR_mq_notify 275
216#define __NR_mq_getsetattr 276
217#define __NR_kexec_load 277
218#define __NR_add_key 278
219#define __NR_request_key 279
220#define __NR_keyctl 280
221#define __NR_waitid 281
222#define __NR_ioprio_set 282
223#define __NR_ioprio_get 283
224#define __NR_inotify_init 284
225#define __NR_inotify_add_watch 285
226#define __NR_inotify_rm_watch 286
227#define __NR_migrate_pages 287
228#define __NR_openat 288
229#define __NR_mkdirat 289
230#define __NR_mknodat 290
231#define __NR_fchownat 291
232#define __NR_futimesat 292
233#define __NR_unlinkat 294
234#define __NR_renameat 295
235#define __NR_linkat 296
236#define __NR_symlinkat 297
237#define __NR_readlinkat 298
238#define __NR_fchmodat 299
239#define __NR_faccessat 300
240#define __NR_pselect6 301
241#define __NR_ppoll 302
242#define __NR_unshare 303
243#define __NR_set_robust_list 304
244#define __NR_get_robust_list 305
245#define __NR_splice 306
246#define __NR_sync_file_range 307
247#define __NR_tee 308
248#define __NR_vmsplice 309
249#define __NR_move_pages 310
250#define __NR_getcpu 311
251#define __NR_epoll_pwait 312
252#define __NR_utimes 313
253#define __NR_fallocate 314
254#define __NR_utimensat 315
255#define __NR_signalfd 316
256#define __NR_timerfd 317
257#define __NR_eventfd 318
258#define __NR_timerfd_create 319
259#define __NR_timerfd_settime 320
260#define __NR_timerfd_gettime 321
261#define __NR_signalfd4 322
262#define __NR_eventfd2 323
263#define __NR_inotify_init1 324
264#define __NR_pipe2 325
265#define __NR_dup3 326
266#define __NR_epoll_create1 327
267#define __NR_preadv 328
268#define __NR_pwritev 329
269#define __NR_rt_tgsigqueueinfo 330
270#define __NR_perf_event_open 331
271#define __NR_fanotify_init 332
272#define __NR_fanotify_mark 333
273#define __NR_prlimit64 334
274#define __NR_name_to_handle_at 335
275#define __NR_open_by_handle_at 336
276#define __NR_clock_adjtime 337
277#define __NR_syncfs 338
278#define __NR_setns 339
279#define __NR_process_vm_readv 340
280#define __NR_process_vm_writev 341
281#define __NR_s390_runtime_instr 342
282#define __NR_kcmp 343
283#define __NR_finit_module 344
284#define __NR_sched_setattr 345
285#define __NR_sched_getattr 346
286#define __NR_renameat2 347
287#define __NR_seccomp 348
288#define __NR_getrandom 349
289#define __NR_memfd_create 350
290#define __NR_bpf 351
291#define __NR_s390_pci_mmio_write 352
292#define __NR_s390_pci_mmio_read 353
293#define __NR_execveat 354
294#define __NR_userfaultfd 355
295#define __NR_membarrier 356
296#define __NR_recvmmsg 357
297#define __NR_sendmmsg 358
298#define __NR_socket 359
299#define __NR_socketpair 360
300#define __NR_bind 361
301#define __NR_connect 362
302#define __NR_listen 363
303#define __NR_accept4 364
304#define __NR_getsockopt 365
305#define __NR_setsockopt 366
306#define __NR_getsockname 367
307#define __NR_getpeername 368
308#define __NR_sendto 369
309#define __NR_sendmsg 370
310#define __NR_recvfrom 371
311#define __NR_recvmsg 372
312#define __NR_shutdown 373
313#define __NR_mlock2 374
314#define __NR_copy_file_range 375
315#define __NR_preadv2 376
316#define __NR_pwritev2 377
317#define __NR_s390_guarded_storage 378
318#define __NR_statx 379
319#define __NR_s390_sthyi 380
320#define NR_syscalls 381
321
322/*
323 * There are some system calls that are not present on 64 bit, some
324 * have a different name although they do the same (e.g. __NR_chown32
325 * is __NR_chown on 64 bit).
326 */
327#ifndef __s390x__
328
329#define __NR_time 13
330#define __NR_lchown 16
331#define __NR_setuid 23
332#define __NR_getuid 24
333#define __NR_stime 25
334#define __NR_setgid 46
335#define __NR_getgid 47
336#define __NR_geteuid 49
337#define __NR_getegid 50
338#define __NR_setreuid 70
339#define __NR_setregid 71
340#define __NR_getrlimit 76
341#define __NR_getgroups 80
342#define __NR_setgroups 81
343#define __NR_fchown 95
344#define __NR_ioperm 101
345#define __NR_setfsuid 138
346#define __NR_setfsgid 139
347#define __NR__llseek 140
348#define __NR__newselect 142
349#define __NR_setresuid 164
350#define __NR_getresuid 165
351#define __NR_setresgid 170
352#define __NR_getresgid 171
353#define __NR_chown 182
354#define __NR_ugetrlimit 191 /* SuS compliant getrlimit */
355#define __NR_mmap2 192
356#define __NR_truncate64 193
357#define __NR_ftruncate64 194
358#define __NR_stat64 195
359#define __NR_lstat64 196
360#define __NR_fstat64 197
361#define __NR_lchown32 198
362#define __NR_getuid32 199
363#define __NR_getgid32 200
364#define __NR_geteuid32 201
365#define __NR_getegid32 202
366#define __NR_setreuid32 203
367#define __NR_setregid32 204
368#define __NR_getgroups32 205
369#define __NR_setgroups32 206
370#define __NR_fchown32 207
371#define __NR_setresuid32 208
372#define __NR_getresuid32 209
373#define __NR_setresgid32 210
374#define __NR_getresgid32 211
375#define __NR_chown32 212
376#define __NR_setuid32 213
377#define __NR_setgid32 214
378#define __NR_setfsuid32 215
379#define __NR_setfsgid32 216
380#define __NR_fcntl64 221
381#define __NR_sendfile64 223
382#define __NR_fadvise64_64 264
383#define __NR_fstatat64 293
384
385#else
386
387#define __NR_select 142
388#define __NR_getrlimit 191 /* SuS compliant getrlimit */
389#define __NR_lchown 198
390#define __NR_getuid 199
391#define __NR_getgid 200
392#define __NR_geteuid 201
393#define __NR_getegid 202
394#define __NR_setreuid 203
395#define __NR_setregid 204
396#define __NR_getgroups 205
397#define __NR_setgroups 206
398#define __NR_fchown 207
399#define __NR_setresuid 208
400#define __NR_getresuid 209
401#define __NR_setresgid 210
402#define __NR_getresgid 211
403#define __NR_chown 212
404#define __NR_setuid 213
405#define __NR_setgid 214
406#define __NR_setfsuid 215
407#define __NR_setfsgid 216
408#define __NR_newfstatat 293
409
410#endif
411
412#endif /* _UAPI_ASM_S390_UNISTD_H_ */
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index 1d9199e1c2ad..f41079da38c5 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -210,8 +210,10 @@
210 210
211#define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */ 211#define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */
212#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* "" Fill RSB on context switches */ 212#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* "" Fill RSB on context switches */
213#define X86_FEATURE_SEV ( 7*32+20) /* AMD Secure Encrypted Virtualization */
213 214
214#define X86_FEATURE_USE_IBPB ( 7*32+21) /* "" Indirect Branch Prediction Barrier enabled */ 215#define X86_FEATURE_USE_IBPB ( 7*32+21) /* "" Indirect Branch Prediction Barrier enabled */
216#define X86_FEATURE_USE_IBRS_FW ( 7*32+22) /* "" Use IBRS during runtime firmware calls */
215 217
216/* Virtualization flags: Linux defined, word 8 */ 218/* Virtualization flags: Linux defined, word 8 */
217#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ 219#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index 0b482c0070e0..465995281dcd 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -55,6 +55,10 @@
55 55
56#include "main.h" 56#include "main.h"
57 57
58#ifndef BPF_FS_MAGIC
59#define BPF_FS_MAGIC 0xcafe4a11
60#endif
61
58void p_err(const char *fmt, ...) 62void p_err(const char *fmt, ...)
59{ 63{
60 va_list ap; 64 va_list ap;
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 3a0396d87c42..185acfa229b5 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -244,7 +244,7 @@ static int do_batch(int argc, char **argv)
244 } 244 }
245 245
246 if (errno && errno != ENOENT) { 246 if (errno && errno != ENOENT) {
247 perror("reading batch file failed"); 247 p_err("reading batch file failed: %s", strerror(errno));
248 err = -1; 248 err = -1;
249 } else { 249 } else {
250 p_info("processed %d lines", lines); 250 p_info("processed %d lines", lines);
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index e8e2baaf93c2..e549e329be82 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -774,6 +774,9 @@ static int do_dump(int argc, char **argv)
774 n < 0 ? strerror(errno) : "short write"); 774 n < 0 ? strerror(errno) : "short write");
775 goto err_free; 775 goto err_free;
776 } 776 }
777
778 if (json_output)
779 jsonw_null(json_wtr);
777 } else { 780 } else {
778 if (member_len == &info.jited_prog_len) { 781 if (member_len == &info.jited_prog_len) {
779 const char *name = NULL; 782 const char *name = NULL;
diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile
index 860fa151640a..ffca068e4a76 100644
--- a/tools/cgroup/Makefile
+++ b/tools/cgroup/Makefile
@@ -1,7 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2# Makefile for cgroup tools 2# Makefile for cgroup tools
3 3
4CC = $(CROSS_COMPILE)gcc
5CFLAGS = -Wall -Wextra 4CFLAGS = -Wall -Wextra
6 5
7all: cgroup_event_listener 6all: cgroup_event_listener
diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile
index 805a2c0cf4cd..240eda014b37 100644
--- a/tools/gpio/Makefile
+++ b/tools/gpio/Makefile
@@ -12,8 +12,6 @@ endif
12# (this improves performance and avoids hard-to-debug behaviour); 12# (this improves performance and avoids hard-to-debug behaviour);
13MAKEFLAGS += -r 13MAKEFLAGS += -r
14 14
15CC = $(CROSS_COMPILE)gcc
16LD = $(CROSS_COMPILE)ld
17CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include 15CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
18 16
19ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon 17ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon
diff --git a/tools/hv/Makefile b/tools/hv/Makefile
index 1139d71fa0cf..5db5e62cebda 100644
--- a/tools/hv/Makefile
+++ b/tools/hv/Makefile
@@ -1,7 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2# Makefile for Hyper-V tools 2# Makefile for Hyper-V tools
3 3
4CC = $(CROSS_COMPILE)gcc
5WARNINGS = -Wall -Wextra 4WARNINGS = -Wall -Wextra
6CFLAGS = $(WARNINGS) -g $(shell getconf LFS_CFLAGS) 5CFLAGS = $(WARNINGS) -g $(shell getconf LFS_CFLAGS)
7 6
diff --git a/tools/iio/Makefile b/tools/iio/Makefile
index a08e7a47d6a3..332ed2f6c2c2 100644
--- a/tools/iio/Makefile
+++ b/tools/iio/Makefile
@@ -12,8 +12,6 @@ endif
12# (this improves performance and avoids hard-to-debug behaviour); 12# (this improves performance and avoids hard-to-debug behaviour);
13MAKEFLAGS += -r 13MAKEFLAGS += -r
14 14
15CC = $(CROSS_COMPILE)gcc
16LD = $(CROSS_COMPILE)ld
17CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include 15CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
18 16
19ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer 17ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer
diff --git a/tools/include/uapi/drm/i915_drm.h b/tools/include/uapi/drm/i915_drm.h
index ac3c6503ca27..536ee4febd74 100644
--- a/tools/include/uapi/drm/i915_drm.h
+++ b/tools/include/uapi/drm/i915_drm.h
@@ -86,6 +86,62 @@ enum i915_mocs_table_index {
86 I915_MOCS_CACHED, 86 I915_MOCS_CACHED,
87}; 87};
88 88
89/*
90 * Different engines serve different roles, and there may be more than one
91 * engine serving each role. enum drm_i915_gem_engine_class provides a
92 * classification of the role of the engine, which may be used when requesting
93 * operations to be performed on a certain subset of engines, or for providing
94 * information about that group.
95 */
96enum drm_i915_gem_engine_class {
97 I915_ENGINE_CLASS_RENDER = 0,
98 I915_ENGINE_CLASS_COPY = 1,
99 I915_ENGINE_CLASS_VIDEO = 2,
100 I915_ENGINE_CLASS_VIDEO_ENHANCE = 3,
101
102 I915_ENGINE_CLASS_INVALID = -1
103};
104
105/**
106 * DOC: perf_events exposed by i915 through /sys/bus/event_sources/drivers/i915
107 *
108 */
109
110enum drm_i915_pmu_engine_sample {
111 I915_SAMPLE_BUSY = 0,
112 I915_SAMPLE_WAIT = 1,
113 I915_SAMPLE_SEMA = 2
114};
115
116#define I915_PMU_SAMPLE_BITS (4)
117#define I915_PMU_SAMPLE_MASK (0xf)
118#define I915_PMU_SAMPLE_INSTANCE_BITS (8)
119#define I915_PMU_CLASS_SHIFT \
120 (I915_PMU_SAMPLE_BITS + I915_PMU_SAMPLE_INSTANCE_BITS)
121
122#define __I915_PMU_ENGINE(class, instance, sample) \
123 ((class) << I915_PMU_CLASS_SHIFT | \
124 (instance) << I915_PMU_SAMPLE_BITS | \
125 (sample))
126
127#define I915_PMU_ENGINE_BUSY(class, instance) \
128 __I915_PMU_ENGINE(class, instance, I915_SAMPLE_BUSY)
129
130#define I915_PMU_ENGINE_WAIT(class, instance) \
131 __I915_PMU_ENGINE(class, instance, I915_SAMPLE_WAIT)
132
133#define I915_PMU_ENGINE_SEMA(class, instance) \
134 __I915_PMU_ENGINE(class, instance, I915_SAMPLE_SEMA)
135
136#define __I915_PMU_OTHER(x) (__I915_PMU_ENGINE(0xff, 0xff, 0xf) + 1 + (x))
137
138#define I915_PMU_ACTUAL_FREQUENCY __I915_PMU_OTHER(0)
139#define I915_PMU_REQUESTED_FREQUENCY __I915_PMU_OTHER(1)
140#define I915_PMU_INTERRUPTS __I915_PMU_OTHER(2)
141#define I915_PMU_RC6_RESIDENCY __I915_PMU_OTHER(3)
142
143#define I915_PMU_LAST I915_PMU_RC6_RESIDENCY
144
89/* Each region is a minimum of 16k, and there are at most 255 of them. 145/* Each region is a minimum of 16k, and there are at most 255 of them.
90 */ 146 */
91#define I915_NR_TEX_REGIONS 255 /* table size 2k - maximum due to use 147#define I915_NR_TEX_REGIONS 255 /* table size 2k - maximum due to use
@@ -450,6 +506,27 @@ typedef struct drm_i915_irq_wait {
450 */ 506 */
451#define I915_PARAM_HAS_EXEC_FENCE_ARRAY 49 507#define I915_PARAM_HAS_EXEC_FENCE_ARRAY 49
452 508
509/*
510 * Query whether every context (both per-file default and user created) is
511 * isolated (insofar as HW supports). If this parameter is not true, then
512 * freshly created contexts may inherit values from an existing context,
513 * rather than default HW values. If true, it also ensures (insofar as HW
514 * supports) that all state set by this context will not leak to any other
515 * context.
516 *
517 * As not every engine across every gen support contexts, the returned
518 * value reports the support of context isolation for individual engines by
519 * returning a bitmask of each engine class set to true if that class supports
520 * isolation.
521 */
522#define I915_PARAM_HAS_CONTEXT_ISOLATION 50
523
524/* Frequency of the command streamer timestamps given by the *_TIMESTAMP
525 * registers. This used to be fixed per platform but from CNL onwards, this
526 * might vary depending on the parts.
527 */
528#define I915_PARAM_CS_TIMESTAMP_FREQUENCY 51
529
453typedef struct drm_i915_getparam { 530typedef struct drm_i915_getparam {
454 __s32 param; 531 __s32 param;
455 /* 532 /*
diff --git a/tools/include/uapi/linux/if_link.h b/tools/include/uapi/linux/if_link.h
index 8616131e2c61..6d9447700e18 100644
--- a/tools/include/uapi/linux/if_link.h
+++ b/tools/include/uapi/linux/if_link.h
@@ -163,6 +163,7 @@ enum {
163 IFLA_IF_NETNSID, 163 IFLA_IF_NETNSID,
164 IFLA_CARRIER_UP_COUNT, 164 IFLA_CARRIER_UP_COUNT,
165 IFLA_CARRIER_DOWN_COUNT, 165 IFLA_CARRIER_DOWN_COUNT,
166 IFLA_NEW_IFINDEX,
166 __IFLA_MAX 167 __IFLA_MAX
167}; 168};
168 169
diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h
index 8fb90a0819c3..7b26d4b0b052 100644
--- a/tools/include/uapi/linux/kvm.h
+++ b/tools/include/uapi/linux/kvm.h
@@ -761,6 +761,7 @@ struct kvm_ppc_resize_hpt {
761#define KVM_TRACE_PAUSE __KVM_DEPRECATED_MAIN_0x07 761#define KVM_TRACE_PAUSE __KVM_DEPRECATED_MAIN_0x07
762#define KVM_TRACE_DISABLE __KVM_DEPRECATED_MAIN_0x08 762#define KVM_TRACE_DISABLE __KVM_DEPRECATED_MAIN_0x08
763#define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2) 763#define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2)
764#define KVM_GET_MSR_FEATURE_INDEX_LIST _IOWR(KVMIO, 0x0a, struct kvm_msr_list)
764 765
765/* 766/*
766 * Extension capability list. 767 * Extension capability list.
@@ -934,6 +935,7 @@ struct kvm_ppc_resize_hpt {
934#define KVM_CAP_S390_AIS_MIGRATION 150 935#define KVM_CAP_S390_AIS_MIGRATION 150
935#define KVM_CAP_PPC_GET_CPU_CHAR 151 936#define KVM_CAP_PPC_GET_CPU_CHAR 151
936#define KVM_CAP_S390_BPB 152 937#define KVM_CAP_S390_BPB 152
938#define KVM_CAP_GET_MSR_FEATURES 153
937 939
938#ifdef KVM_CAP_IRQ_ROUTING 940#ifdef KVM_CAP_IRQ_ROUTING
939 941
@@ -1362,6 +1364,96 @@ struct kvm_s390_ucas_mapping {
1362/* Available with KVM_CAP_S390_CMMA_MIGRATION */ 1364/* Available with KVM_CAP_S390_CMMA_MIGRATION */
1363#define KVM_S390_GET_CMMA_BITS _IOWR(KVMIO, 0xb8, struct kvm_s390_cmma_log) 1365#define KVM_S390_GET_CMMA_BITS _IOWR(KVMIO, 0xb8, struct kvm_s390_cmma_log)
1364#define KVM_S390_SET_CMMA_BITS _IOW(KVMIO, 0xb9, struct kvm_s390_cmma_log) 1366#define KVM_S390_SET_CMMA_BITS _IOW(KVMIO, 0xb9, struct kvm_s390_cmma_log)
1367/* Memory Encryption Commands */
1368#define KVM_MEMORY_ENCRYPT_OP _IOWR(KVMIO, 0xba, unsigned long)
1369
1370struct kvm_enc_region {
1371 __u64 addr;
1372 __u64 size;
1373};
1374
1375#define KVM_MEMORY_ENCRYPT_REG_REGION _IOR(KVMIO, 0xbb, struct kvm_enc_region)
1376#define KVM_MEMORY_ENCRYPT_UNREG_REGION _IOR(KVMIO, 0xbc, struct kvm_enc_region)
1377
1378/* Secure Encrypted Virtualization command */
1379enum sev_cmd_id {
1380 /* Guest initialization commands */
1381 KVM_SEV_INIT = 0,
1382 KVM_SEV_ES_INIT,
1383 /* Guest launch commands */
1384 KVM_SEV_LAUNCH_START,
1385 KVM_SEV_LAUNCH_UPDATE_DATA,
1386 KVM_SEV_LAUNCH_UPDATE_VMSA,
1387 KVM_SEV_LAUNCH_SECRET,
1388 KVM_SEV_LAUNCH_MEASURE,
1389 KVM_SEV_LAUNCH_FINISH,
1390 /* Guest migration commands (outgoing) */
1391 KVM_SEV_SEND_START,
1392 KVM_SEV_SEND_UPDATE_DATA,
1393 KVM_SEV_SEND_UPDATE_VMSA,
1394 KVM_SEV_SEND_FINISH,
1395 /* Guest migration commands (incoming) */
1396 KVM_SEV_RECEIVE_START,
1397 KVM_SEV_RECEIVE_UPDATE_DATA,
1398 KVM_SEV_RECEIVE_UPDATE_VMSA,
1399 KVM_SEV_RECEIVE_FINISH,
1400 /* Guest status and debug commands */
1401 KVM_SEV_GUEST_STATUS,
1402 KVM_SEV_DBG_DECRYPT,
1403 KVM_SEV_DBG_ENCRYPT,
1404 /* Guest certificates commands */
1405 KVM_SEV_CERT_EXPORT,
1406
1407 KVM_SEV_NR_MAX,
1408};
1409
1410struct kvm_sev_cmd {
1411 __u32 id;
1412 __u64 data;
1413 __u32 error;
1414 __u32 sev_fd;
1415};
1416
1417struct kvm_sev_launch_start {
1418 __u32 handle;
1419 __u32 policy;
1420 __u64 dh_uaddr;
1421 __u32 dh_len;
1422 __u64 session_uaddr;
1423 __u32 session_len;
1424};
1425
1426struct kvm_sev_launch_update_data {
1427 __u64 uaddr;
1428 __u32 len;
1429};
1430
1431
1432struct kvm_sev_launch_secret {
1433 __u64 hdr_uaddr;
1434 __u32 hdr_len;
1435 __u64 guest_uaddr;
1436 __u32 guest_len;
1437 __u64 trans_uaddr;
1438 __u32 trans_len;
1439};
1440
1441struct kvm_sev_launch_measure {
1442 __u64 uaddr;
1443 __u32 len;
1444};
1445
1446struct kvm_sev_guest_status {
1447 __u32 handle;
1448 __u32 policy;
1449 __u32 state;
1450};
1451
1452struct kvm_sev_dbg {
1453 __u64 src_uaddr;
1454 __u64 dst_uaddr;
1455 __u32 len;
1456};
1365 1457
1366#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) 1458#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
1367#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) 1459#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index a5684d0968b4..5898c22ba310 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -33,7 +33,7 @@ import resource
33import struct 33import struct
34import re 34import re
35import subprocess 35import subprocess
36from collections import defaultdict 36from collections import defaultdict, namedtuple
37 37
38VMX_EXIT_REASONS = { 38VMX_EXIT_REASONS = {
39 'EXCEPTION_NMI': 0, 39 'EXCEPTION_NMI': 0,
@@ -228,6 +228,7 @@ IOCTL_NUMBERS = {
228} 228}
229 229
230ENCODING = locale.getpreferredencoding(False) 230ENCODING = locale.getpreferredencoding(False)
231TRACE_FILTER = re.compile(r'^[^\(]*$')
231 232
232 233
233class Arch(object): 234class Arch(object):
@@ -260,6 +261,11 @@ class Arch(object):
260 return ArchX86(SVM_EXIT_REASONS) 261 return ArchX86(SVM_EXIT_REASONS)
261 return 262 return
262 263
264 def tracepoint_is_child(self, field):
265 if (TRACE_FILTER.match(field)):
266 return None
267 return field.split('(', 1)[0]
268
263 269
264class ArchX86(Arch): 270class ArchX86(Arch):
265 def __init__(self, exit_reasons): 271 def __init__(self, exit_reasons):
@@ -267,6 +273,10 @@ class ArchX86(Arch):
267 self.ioctl_numbers = IOCTL_NUMBERS 273 self.ioctl_numbers = IOCTL_NUMBERS
268 self.exit_reasons = exit_reasons 274 self.exit_reasons = exit_reasons
269 275
276 def debugfs_is_child(self, field):
277 """ Returns name of parent if 'field' is a child, None otherwise """
278 return None
279
270 280
271class ArchPPC(Arch): 281class ArchPPC(Arch):
272 def __init__(self): 282 def __init__(self):
@@ -282,6 +292,10 @@ class ArchPPC(Arch):
282 self.ioctl_numbers['SET_FILTER'] = 0x80002406 | char_ptr_size << 16 292 self.ioctl_numbers['SET_FILTER'] = 0x80002406 | char_ptr_size << 16
283 self.exit_reasons = {} 293 self.exit_reasons = {}
284 294
295 def debugfs_is_child(self, field):
296 """ Returns name of parent if 'field' is a child, None otherwise """
297 return None
298
285 299
286class ArchA64(Arch): 300class ArchA64(Arch):
287 def __init__(self): 301 def __init__(self):
@@ -289,6 +303,10 @@ class ArchA64(Arch):
289 self.ioctl_numbers = IOCTL_NUMBERS 303 self.ioctl_numbers = IOCTL_NUMBERS
290 self.exit_reasons = AARCH64_EXIT_REASONS 304 self.exit_reasons = AARCH64_EXIT_REASONS
291 305
306 def debugfs_is_child(self, field):
307 """ Returns name of parent if 'field' is a child, None otherwise """
308 return None
309
292 310
293class ArchS390(Arch): 311class ArchS390(Arch):
294 def __init__(self): 312 def __init__(self):
@@ -296,6 +314,12 @@ class ArchS390(Arch):
296 self.ioctl_numbers = IOCTL_NUMBERS 314 self.ioctl_numbers = IOCTL_NUMBERS
297 self.exit_reasons = None 315 self.exit_reasons = None
298 316
317 def debugfs_is_child(self, field):
318 """ Returns name of parent if 'field' is a child, None otherwise """
319 if field.startswith('instruction_'):
320 return 'exit_instruction'
321
322
299ARCH = Arch.get_arch() 323ARCH = Arch.get_arch()
300 324
301 325
@@ -331,9 +355,6 @@ class perf_event_attr(ctypes.Structure):
331PERF_TYPE_TRACEPOINT = 2 355PERF_TYPE_TRACEPOINT = 2
332PERF_FORMAT_GROUP = 1 << 3 356PERF_FORMAT_GROUP = 1 << 3
333 357
334PATH_DEBUGFS_TRACING = '/sys/kernel/debug/tracing'
335PATH_DEBUGFS_KVM = '/sys/kernel/debug/kvm'
336
337 358
338class Group(object): 359class Group(object):
339 """Represents a perf event group.""" 360 """Represents a perf event group."""
@@ -376,8 +397,8 @@ class Event(object):
376 self.syscall = self.libc.syscall 397 self.syscall = self.libc.syscall
377 self.name = name 398 self.name = name
378 self.fd = None 399 self.fd = None
379 self.setup_event(group, trace_cpu, trace_pid, trace_point, 400 self._setup_event(group, trace_cpu, trace_pid, trace_point,
380 trace_filter, trace_set) 401 trace_filter, trace_set)
381 402
382 def __del__(self): 403 def __del__(self):
383 """Closes the event's file descriptor. 404 """Closes the event's file descriptor.
@@ -390,7 +411,7 @@ class Event(object):
390 if self.fd: 411 if self.fd:
391 os.close(self.fd) 412 os.close(self.fd)
392 413
393 def perf_event_open(self, attr, pid, cpu, group_fd, flags): 414 def _perf_event_open(self, attr, pid, cpu, group_fd, flags):
394 """Wrapper for the sys_perf_evt_open() syscall. 415 """Wrapper for the sys_perf_evt_open() syscall.
395 416
396 Used to set up performance events, returns a file descriptor or -1 417 Used to set up performance events, returns a file descriptor or -1
@@ -409,7 +430,7 @@ class Event(object):
409 ctypes.c_int(pid), ctypes.c_int(cpu), 430 ctypes.c_int(pid), ctypes.c_int(cpu),
410 ctypes.c_int(group_fd), ctypes.c_long(flags)) 431 ctypes.c_int(group_fd), ctypes.c_long(flags))
411 432
412 def setup_event_attribute(self, trace_set, trace_point): 433 def _setup_event_attribute(self, trace_set, trace_point):
413 """Returns an initialized ctype perf_event_attr struct.""" 434 """Returns an initialized ctype perf_event_attr struct."""
414 435
415 id_path = os.path.join(PATH_DEBUGFS_TRACING, 'events', trace_set, 436 id_path = os.path.join(PATH_DEBUGFS_TRACING, 'events', trace_set,
@@ -419,8 +440,8 @@ class Event(object):
419 event_attr.config = int(open(id_path).read()) 440 event_attr.config = int(open(id_path).read())
420 return event_attr 441 return event_attr
421 442
422 def setup_event(self, group, trace_cpu, trace_pid, trace_point, 443 def _setup_event(self, group, trace_cpu, trace_pid, trace_point,
423 trace_filter, trace_set): 444 trace_filter, trace_set):
424 """Sets up the perf event in Linux. 445 """Sets up the perf event in Linux.
425 446
426 Issues the syscall to register the event in the kernel and 447 Issues the syscall to register the event in the kernel and
@@ -428,7 +449,7 @@ class Event(object):
428 449
429 """ 450 """
430 451
431 event_attr = self.setup_event_attribute(trace_set, trace_point) 452 event_attr = self._setup_event_attribute(trace_set, trace_point)
432 453
433 # First event will be group leader. 454 # First event will be group leader.
434 group_leader = -1 455 group_leader = -1
@@ -437,8 +458,8 @@ class Event(object):
437 if group.events: 458 if group.events:
438 group_leader = group.events[0].fd 459 group_leader = group.events[0].fd
439 460
440 fd = self.perf_event_open(event_attr, trace_pid, 461 fd = self._perf_event_open(event_attr, trace_pid,
441 trace_cpu, group_leader, 0) 462 trace_cpu, group_leader, 0)
442 if fd == -1: 463 if fd == -1:
443 err = ctypes.get_errno() 464 err = ctypes.get_errno()
444 raise OSError(err, os.strerror(err), 465 raise OSError(err, os.strerror(err),
@@ -475,6 +496,10 @@ class Event(object):
475 496
476class Provider(object): 497class Provider(object):
477 """Encapsulates functionalities used by all providers.""" 498 """Encapsulates functionalities used by all providers."""
499 def __init__(self, pid):
500 self.child_events = False
501 self.pid = pid
502
478 @staticmethod 503 @staticmethod
479 def is_field_wanted(fields_filter, field): 504 def is_field_wanted(fields_filter, field):
480 """Indicate whether field is valid according to fields_filter.""" 505 """Indicate whether field is valid according to fields_filter."""
@@ -500,12 +525,12 @@ class TracepointProvider(Provider):
500 """ 525 """
501 def __init__(self, pid, fields_filter): 526 def __init__(self, pid, fields_filter):
502 self.group_leaders = [] 527 self.group_leaders = []
503 self.filters = self.get_filters() 528 self.filters = self._get_filters()
504 self.update_fields(fields_filter) 529 self.update_fields(fields_filter)
505 self.pid = pid 530 super(TracepointProvider, self).__init__(pid)
506 531
507 @staticmethod 532 @staticmethod
508 def get_filters(): 533 def _get_filters():
509 """Returns a dict of trace events, their filter ids and 534 """Returns a dict of trace events, their filter ids and
510 the values that can be filtered. 535 the values that can be filtered.
511 536
@@ -521,8 +546,8 @@ class TracepointProvider(Provider):
521 filters['kvm_exit'] = ('exit_reason', ARCH.exit_reasons) 546 filters['kvm_exit'] = ('exit_reason', ARCH.exit_reasons)
522 return filters 547 return filters
523 548
524 def get_available_fields(self): 549 def _get_available_fields(self):
525 """Returns a list of available event's of format 'event name(filter 550 """Returns a list of available events of format 'event name(filter
526 name)'. 551 name)'.
527 552
528 All available events have directories under 553 All available events have directories under
@@ -549,11 +574,12 @@ class TracepointProvider(Provider):
549 574
550 def update_fields(self, fields_filter): 575 def update_fields(self, fields_filter):
551 """Refresh fields, applying fields_filter""" 576 """Refresh fields, applying fields_filter"""
552 self.fields = [field for field in self.get_available_fields() 577 self.fields = [field for field in self._get_available_fields()
553 if self.is_field_wanted(fields_filter, field)] 578 if self.is_field_wanted(fields_filter, field) or
579 ARCH.tracepoint_is_child(field)]
554 580
555 @staticmethod 581 @staticmethod
556 def get_online_cpus(): 582 def _get_online_cpus():
557 """Returns a list of cpu id integers.""" 583 """Returns a list of cpu id integers."""
558 def parse_int_list(list_string): 584 def parse_int_list(list_string):
559 """Returns an int list from a string of comma separated integers and 585 """Returns an int list from a string of comma separated integers and
@@ -575,17 +601,17 @@ class TracepointProvider(Provider):
575 cpu_string = cpu_list.readline() 601 cpu_string = cpu_list.readline()
576 return parse_int_list(cpu_string) 602 return parse_int_list(cpu_string)
577 603
578 def setup_traces(self): 604 def _setup_traces(self):
579 """Creates all event and group objects needed to be able to retrieve 605 """Creates all event and group objects needed to be able to retrieve
580 data.""" 606 data."""
581 fields = self.get_available_fields() 607 fields = self._get_available_fields()
582 if self._pid > 0: 608 if self._pid > 0:
583 # Fetch list of all threads of the monitored pid, as qemu 609 # Fetch list of all threads of the monitored pid, as qemu
584 # starts a thread for each vcpu. 610 # starts a thread for each vcpu.
585 path = os.path.join('/proc', str(self._pid), 'task') 611 path = os.path.join('/proc', str(self._pid), 'task')
586 groupids = self.walkdir(path)[1] 612 groupids = self.walkdir(path)[1]
587 else: 613 else:
588 groupids = self.get_online_cpus() 614 groupids = self._get_online_cpus()
589 615
590 # The constant is needed as a buffer for python libs, std 616 # The constant is needed as a buffer for python libs, std
591 # streams and other files that the script opens. 617 # streams and other files that the script opens.
@@ -663,7 +689,7 @@ class TracepointProvider(Provider):
663 # The garbage collector will get rid of all Event/Group 689 # The garbage collector will get rid of all Event/Group
664 # objects and open files after removing the references. 690 # objects and open files after removing the references.
665 self.group_leaders = [] 691 self.group_leaders = []
666 self.setup_traces() 692 self._setup_traces()
667 self.fields = self._fields 693 self.fields = self._fields
668 694
669 def read(self, by_guest=0): 695 def read(self, by_guest=0):
@@ -671,8 +697,12 @@ class TracepointProvider(Provider):
671 ret = defaultdict(int) 697 ret = defaultdict(int)
672 for group in self.group_leaders: 698 for group in self.group_leaders:
673 for name, val in group.read().items(): 699 for name, val in group.read().items():
674 if name in self._fields: 700 if name not in self._fields:
675 ret[name] += val 701 continue
702 parent = ARCH.tracepoint_is_child(name)
703 if parent:
704 name += ' ' + parent
705 ret[name] += val
676 return ret 706 return ret
677 707
678 def reset(self): 708 def reset(self):
@@ -690,11 +720,11 @@ class DebugfsProvider(Provider):
690 self._baseline = {} 720 self._baseline = {}
691 self.do_read = True 721 self.do_read = True
692 self.paths = [] 722 self.paths = []
693 self.pid = pid 723 super(DebugfsProvider, self).__init__(pid)
694 if include_past: 724 if include_past:
695 self.restore() 725 self._restore()
696 726
697 def get_available_fields(self): 727 def _get_available_fields(self):
698 """"Returns a list of available fields. 728 """"Returns a list of available fields.
699 729
700 The fields are all available KVM debugfs files 730 The fields are all available KVM debugfs files
@@ -704,8 +734,9 @@ class DebugfsProvider(Provider):
704 734
705 def update_fields(self, fields_filter): 735 def update_fields(self, fields_filter):
706 """Refresh fields, applying fields_filter""" 736 """Refresh fields, applying fields_filter"""
707 self._fields = [field for field in self.get_available_fields() 737 self._fields = [field for field in self._get_available_fields()
708 if self.is_field_wanted(fields_filter, field)] 738 if self.is_field_wanted(fields_filter, field) or
739 ARCH.debugfs_is_child(field)]
709 740
710 @property 741 @property
711 def fields(self): 742 def fields(self):
@@ -758,7 +789,7 @@ class DebugfsProvider(Provider):
758 paths.append(dir) 789 paths.append(dir)
759 for path in paths: 790 for path in paths:
760 for field in self._fields: 791 for field in self._fields:
761 value = self.read_field(field, path) 792 value = self._read_field(field, path)
762 key = path + field 793 key = path + field
763 if reset == 1: 794 if reset == 1:
764 self._baseline[key] = value 795 self._baseline[key] = value
@@ -766,20 +797,21 @@ class DebugfsProvider(Provider):
766 self._baseline[key] = 0 797 self._baseline[key] = 0
767 if self._baseline.get(key, -1) == -1: 798 if self._baseline.get(key, -1) == -1:
768 self._baseline[key] = value 799 self._baseline[key] = value
769 increment = (results.get(field, 0) + value - 800 parent = ARCH.debugfs_is_child(field)
770 self._baseline.get(key, 0)) 801 if parent:
771 if by_guest: 802 field = field + ' ' + parent
772 pid = key.split('-')[0] 803 else:
773 if pid in results: 804 if by_guest:
774 results[pid] += increment 805 field = key.split('-')[0] # set 'field' to 'pid'
775 else: 806 increment = value - self._baseline.get(key, 0)
776 results[pid] = increment 807 if field in results:
808 results[field] += increment
777 else: 809 else:
778 results[field] = increment 810 results[field] = increment
779 811
780 return results 812 return results
781 813
782 def read_field(self, field, path): 814 def _read_field(self, field, path):
783 """Returns the value of a single field from a specific VM.""" 815 """Returns the value of a single field from a specific VM."""
784 try: 816 try:
785 return int(open(os.path.join(PATH_DEBUGFS_KVM, 817 return int(open(os.path.join(PATH_DEBUGFS_KVM,
@@ -794,12 +826,15 @@ class DebugfsProvider(Provider):
794 self._baseline = {} 826 self._baseline = {}
795 self.read(1) 827 self.read(1)
796 828
797 def restore(self): 829 def _restore(self):
798 """Reset field counters""" 830 """Reset field counters"""
799 self._baseline = {} 831 self._baseline = {}
800 self.read(2) 832 self.read(2)
801 833
802 834
835EventStat = namedtuple('EventStat', ['value', 'delta'])
836
837
803class Stats(object): 838class Stats(object):
804 """Manages the data providers and the data they provide. 839 """Manages the data providers and the data they provide.
805 840
@@ -808,13 +843,13 @@ class Stats(object):
808 843
809 """ 844 """
810 def __init__(self, options): 845 def __init__(self, options):
811 self.providers = self.get_providers(options) 846 self.providers = self._get_providers(options)
812 self._pid_filter = options.pid 847 self._pid_filter = options.pid
813 self._fields_filter = options.fields 848 self._fields_filter = options.fields
814 self.values = {} 849 self.values = {}
850 self._child_events = False
815 851
816 @staticmethod 852 def _get_providers(self, options):
817 def get_providers(options):
818 """Returns a list of data providers depending on the passed options.""" 853 """Returns a list of data providers depending on the passed options."""
819 providers = [] 854 providers = []
820 855
@@ -826,7 +861,7 @@ class Stats(object):
826 861
827 return providers 862 return providers
828 863
829 def update_provider_filters(self): 864 def _update_provider_filters(self):
830 """Propagates fields filters to providers.""" 865 """Propagates fields filters to providers."""
831 # As we reset the counters when updating the fields we can 866 # As we reset the counters when updating the fields we can
832 # also clear the cache of old values. 867 # also clear the cache of old values.
@@ -847,7 +882,7 @@ class Stats(object):
847 def fields_filter(self, fields_filter): 882 def fields_filter(self, fields_filter):
848 if fields_filter != self._fields_filter: 883 if fields_filter != self._fields_filter:
849 self._fields_filter = fields_filter 884 self._fields_filter = fields_filter
850 self.update_provider_filters() 885 self._update_provider_filters()
851 886
852 @property 887 @property
853 def pid_filter(self): 888 def pid_filter(self):
@@ -861,16 +896,33 @@ class Stats(object):
861 for provider in self.providers: 896 for provider in self.providers:
862 provider.pid = self._pid_filter 897 provider.pid = self._pid_filter
863 898
899 @property
900 def child_events(self):
901 return self._child_events
902
903 @child_events.setter
904 def child_events(self, val):
905 self._child_events = val
906 for provider in self.providers:
907 provider.child_events = val
908
864 def get(self, by_guest=0): 909 def get(self, by_guest=0):
865 """Returns a dict with field -> (value, delta to last value) of all 910 """Returns a dict with field -> (value, delta to last value) of all
866 provider data.""" 911 provider data.
912 Key formats:
913 * plain: 'key' is event name
914 * child-parent: 'key' is in format '<child> <parent>'
915 * pid: 'key' is the pid of the guest, and the record contains the
916 aggregated event data
917 These formats are generated by the providers, and handled in class TUI.
918 """
867 for provider in self.providers: 919 for provider in self.providers:
868 new = provider.read(by_guest=by_guest) 920 new = provider.read(by_guest=by_guest)
869 for key in new if by_guest else provider.fields: 921 for key in new:
870 oldval = self.values.get(key, (0, 0))[0] 922 oldval = self.values.get(key, EventStat(0, 0)).value
871 newval = new.get(key, 0) 923 newval = new.get(key, 0)
872 newdelta = newval - oldval 924 newdelta = newval - oldval
873 self.values[key] = (newval, newdelta) 925 self.values[key] = EventStat(newval, newdelta)
874 return self.values 926 return self.values
875 927
876 def toggle_display_guests(self, to_pid): 928 def toggle_display_guests(self, to_pid):
@@ -899,10 +951,10 @@ class Stats(object):
899 self.get(to_pid) 951 self.get(to_pid)
900 return 0 952 return 0
901 953
954
902DELAY_DEFAULT = 3.0 955DELAY_DEFAULT = 3.0
903MAX_GUEST_NAME_LEN = 48 956MAX_GUEST_NAME_LEN = 48
904MAX_REGEX_LEN = 44 957MAX_REGEX_LEN = 44
905DEFAULT_REGEX = r'^[^\(]*$'
906SORT_DEFAULT = 0 958SORT_DEFAULT = 0
907 959
908 960
@@ -969,7 +1021,7 @@ class Tui(object):
969 1021
970 return res 1022 return res
971 1023
972 def print_all_gnames(self, row): 1024 def _print_all_gnames(self, row):
973 """Print a list of all running guests along with their pids.""" 1025 """Print a list of all running guests along with their pids."""
974 self.screen.addstr(row, 2, '%8s %-60s' % 1026 self.screen.addstr(row, 2, '%8s %-60s' %
975 ('Pid', 'Guest Name (fuzzy list, might be ' 1027 ('Pid', 'Guest Name (fuzzy list, might be '
@@ -1032,19 +1084,13 @@ class Tui(object):
1032 1084
1033 return name 1085 return name
1034 1086
1035 def update_drilldown(self): 1087 def _update_pid(self, pid):
1036 """Sets or removes a filter that only allows fields without braces."""
1037 if not self.stats.fields_filter:
1038 self.stats.fields_filter = DEFAULT_REGEX
1039
1040 elif self.stats.fields_filter == DEFAULT_REGEX:
1041 self.stats.fields_filter = None
1042
1043 def update_pid(self, pid):
1044 """Propagates pid selection to stats object.""" 1088 """Propagates pid selection to stats object."""
1089 self.screen.addstr(4, 1, 'Updating pid filter...')
1090 self.screen.refresh()
1045 self.stats.pid_filter = pid 1091 self.stats.pid_filter = pid
1046 1092
1047 def refresh_header(self, pid=None): 1093 def _refresh_header(self, pid=None):
1048 """Refreshes the header.""" 1094 """Refreshes the header."""
1049 if pid is None: 1095 if pid is None:
1050 pid = self.stats.pid_filter 1096 pid = self.stats.pid_filter
@@ -1059,8 +1105,7 @@ class Tui(object):
1059 .format(pid, gname), curses.A_BOLD) 1105 .format(pid, gname), curses.A_BOLD)
1060 else: 1106 else:
1061 self.screen.addstr(0, 0, 'kvm statistics - summary', curses.A_BOLD) 1107 self.screen.addstr(0, 0, 'kvm statistics - summary', curses.A_BOLD)
1062 if self.stats.fields_filter and self.stats.fields_filter \ 1108 if self.stats.fields_filter:
1063 != DEFAULT_REGEX:
1064 regex = self.stats.fields_filter 1109 regex = self.stats.fields_filter
1065 if len(regex) > MAX_REGEX_LEN: 1110 if len(regex) > MAX_REGEX_LEN:
1066 regex = regex[:MAX_REGEX_LEN] + '...' 1111 regex = regex[:MAX_REGEX_LEN] + '...'
@@ -1075,56 +1120,99 @@ class Tui(object):
1075 self.screen.addstr(4, 1, 'Collecting data...') 1120 self.screen.addstr(4, 1, 'Collecting data...')
1076 self.screen.refresh() 1121 self.screen.refresh()
1077 1122
1078 def refresh_body(self, sleeptime): 1123 def _refresh_body(self, sleeptime):
1124 def is_child_field(field):
1125 return field.find('(') != -1
1126
1127 def insert_child(sorted_items, child, values, parent):
1128 num = len(sorted_items)
1129 for i in range(0, num):
1130 # only add child if parent is present
1131 if parent.startswith(sorted_items[i][0]):
1132 sorted_items.insert(i + 1, (' ' + child, values))
1133
1134 def get_sorted_events(self, stats):
1135 """ separate parent and child events """
1136 if self._sorting == SORT_DEFAULT:
1137 def sortkey((_k, v)):
1138 # sort by (delta value, overall value)
1139 return (v.delta, v.value)
1140 else:
1141 def sortkey((_k, v)):
1142 # sort by overall value
1143 return v.value
1144
1145 childs = []
1146 sorted_items = []
1147 # we can't rule out child events to appear prior to parents even
1148 # when sorted - separate out all children first, and add in later
1149 for key, values in sorted(stats.items(), key=sortkey,
1150 reverse=True):
1151 if values == (0, 0):
1152 continue
1153 if key.find(' ') != -1:
1154 if not self.stats.child_events:
1155 continue
1156 childs.insert(0, (key, values))
1157 else:
1158 sorted_items.append((key, values))
1159 if self.stats.child_events:
1160 for key, values in childs:
1161 (child, parent) = key.split(' ')
1162 insert_child(sorted_items, child, values, parent)
1163
1164 return sorted_items
1165
1079 row = 3 1166 row = 3
1080 self.screen.move(row, 0) 1167 self.screen.move(row, 0)
1081 self.screen.clrtobot() 1168 self.screen.clrtobot()
1082 stats = self.stats.get(self._display_guests) 1169 stats = self.stats.get(self._display_guests)
1083 1170 total = 0.
1084 def sortCurAvg(x): 1171 ctotal = 0.
1085 # sort by current events if available 1172 for key, values in stats.items():
1086 if stats[x][1]: 1173 if self._display_guests:
1087 return (-stats[x][1], -stats[x][0]) 1174 if self.get_gname_from_pid(key):
1175 total += values.value
1176 continue
1177 if not key.find(' ') != -1:
1178 total += values.value
1088 else: 1179 else:
1089 return (0, -stats[x][0]) 1180 ctotal += values.value
1181 if total == 0.:
1182 # we don't have any fields, or all non-child events are filtered
1183 total = ctotal
1090 1184
1091 def sortTotal(x): 1185 # print events
1092 # sort by totals
1093 return (0, -stats[x][0])
1094 total = 0.
1095 for key in stats.keys():
1096 if key.find('(') is -1:
1097 total += stats[key][0]
1098 if self._sorting == SORT_DEFAULT:
1099 sortkey = sortCurAvg
1100 else:
1101 sortkey = sortTotal
1102 tavg = 0 1186 tavg = 0
1103 for key in sorted(stats.keys(), key=sortkey): 1187 tcur = 0
1104 if row >= self.screen.getmaxyx()[0] - 1: 1188 for key, values in get_sorted_events(self, stats):
1105 break 1189 if row >= self.screen.getmaxyx()[0] - 1 or values == (0, 0):
1106 values = stats[key]
1107 if not values[0] and not values[1]:
1108 break 1190 break
1109 if values[0] is not None: 1191 if self._display_guests:
1110 cur = int(round(values[1] / sleeptime)) if values[1] else '' 1192 key = self.get_gname_from_pid(key)
1111 if self._display_guests: 1193 if not key:
1112 key = self.get_gname_from_pid(key) 1194 continue
1113 self.screen.addstr(row, 1, '%-40s %10d%7.1f %8s' % 1195 cur = int(round(values.delta / sleeptime)) if values.delta else ''
1114 (key, values[0], values[0] * 100 / total, 1196 if key[0] != ' ':
1115 cur)) 1197 if values.delta:
1116 if cur is not '' and key.find('(') is -1: 1198 tcur += values.delta
1117 tavg += cur 1199 ptotal = values.value
1200 ltotal = total
1201 else:
1202 ltotal = ptotal
1203 self.screen.addstr(row, 1, '%-40s %10d%7.1f %8s' % (key,
1204 values.value,
1205 values.value * 100 / float(ltotal), cur))
1118 row += 1 1206 row += 1
1119 if row == 3: 1207 if row == 3:
1120 self.screen.addstr(4, 1, 'No matching events reported yet') 1208 self.screen.addstr(4, 1, 'No matching events reported yet')
1121 else: 1209 if row > 4:
1210 tavg = int(round(tcur / sleeptime)) if tcur > 0 else ''
1122 self.screen.addstr(row, 1, '%-40s %10d %8s' % 1211 self.screen.addstr(row, 1, '%-40s %10d %8s' %
1123 ('Total', total, tavg if tavg else ''), 1212 ('Total', total, tavg), curses.A_BOLD)
1124 curses.A_BOLD)
1125 self.screen.refresh() 1213 self.screen.refresh()
1126 1214
1127 def show_msg(self, text): 1215 def _show_msg(self, text):
1128 """Display message centered text and exit on key press""" 1216 """Display message centered text and exit on key press"""
1129 hint = 'Press any key to continue' 1217 hint = 'Press any key to continue'
1130 curses.cbreak() 1218 curses.cbreak()
@@ -1139,16 +1227,16 @@ class Tui(object):
1139 curses.A_STANDOUT) 1227 curses.A_STANDOUT)
1140 self.screen.getkey() 1228 self.screen.getkey()
1141 1229
1142 def show_help_interactive(self): 1230 def _show_help_interactive(self):
1143 """Display help with list of interactive commands""" 1231 """Display help with list of interactive commands"""
1144 msg = (' b toggle events by guests (debugfs only, honors' 1232 msg = (' b toggle events by guests (debugfs only, honors'
1145 ' filters)', 1233 ' filters)',
1146 ' c clear filter', 1234 ' c clear filter',
1147 ' f filter by regular expression', 1235 ' f filter by regular expression',
1148 ' g filter by guest name', 1236 ' g filter by guest name/PID',
1149 ' h display interactive commands reference', 1237 ' h display interactive commands reference',
1150 ' o toggle sorting order (Total vs CurAvg/s)', 1238 ' o toggle sorting order (Total vs CurAvg/s)',
1151 ' p filter by PID', 1239 ' p filter by guest name/PID',
1152 ' q quit', 1240 ' q quit',
1153 ' r reset stats', 1241 ' r reset stats',
1154 ' s set update interval', 1242 ' s set update interval',
@@ -1165,14 +1253,15 @@ class Tui(object):
1165 self.screen.addstr(row, 0, line) 1253 self.screen.addstr(row, 0, line)
1166 row += 1 1254 row += 1
1167 self.screen.getkey() 1255 self.screen.getkey()
1168 self.refresh_header() 1256 self._refresh_header()
1169 1257
1170 def show_filter_selection(self): 1258 def _show_filter_selection(self):
1171 """Draws filter selection mask. 1259 """Draws filter selection mask.
1172 1260
1173 Asks for a valid regex and sets the fields filter accordingly. 1261 Asks for a valid regex and sets the fields filter accordingly.
1174 1262
1175 """ 1263 """
1264 msg = ''
1176 while True: 1265 while True:
1177 self.screen.erase() 1266 self.screen.erase()
1178 self.screen.addstr(0, 0, 1267 self.screen.addstr(0, 0,
@@ -1181,61 +1270,25 @@ class Tui(object):
1181 self.screen.addstr(2, 0, 1270 self.screen.addstr(2, 0,
1182 "Current regex: {0}" 1271 "Current regex: {0}"
1183 .format(self.stats.fields_filter)) 1272 .format(self.stats.fields_filter))
1273 self.screen.addstr(5, 0, msg)
1184 self.screen.addstr(3, 0, "New regex: ") 1274 self.screen.addstr(3, 0, "New regex: ")
1185 curses.echo() 1275 curses.echo()
1186 regex = self.screen.getstr().decode(ENCODING) 1276 regex = self.screen.getstr().decode(ENCODING)
1187 curses.noecho() 1277 curses.noecho()
1188 if len(regex) == 0: 1278 if len(regex) == 0:
1189 self.stats.fields_filter = DEFAULT_REGEX 1279 self.stats.fields_filter = ''
1190 self.refresh_header() 1280 self._refresh_header()
1191 return 1281 return
1192 try: 1282 try:
1193 re.compile(regex) 1283 re.compile(regex)
1194 self.stats.fields_filter = regex 1284 self.stats.fields_filter = regex
1195 self.refresh_header() 1285 self._refresh_header()
1196 return 1286 return
1197 except re.error: 1287 except re.error:
1288 msg = '"' + regex + '": Not a valid regular expression'
1198 continue 1289 continue
1199 1290
1200 def show_vm_selection_by_pid(self): 1291 def _show_set_update_interval(self):
1201 """Draws PID selection mask.
1202
1203 Asks for a pid until a valid pid or 0 has been entered.
1204
1205 """
1206 msg = ''
1207 while True:
1208 self.screen.erase()
1209 self.screen.addstr(0, 0,
1210 'Show statistics for specific pid.',
1211 curses.A_BOLD)
1212 self.screen.addstr(1, 0,
1213 'This might limit the shown data to the trace '
1214 'statistics.')
1215 self.screen.addstr(5, 0, msg)
1216 self.print_all_gnames(7)
1217
1218 curses.echo()
1219 self.screen.addstr(3, 0, "Pid [0 or pid]: ")
1220 pid = self.screen.getstr().decode(ENCODING)
1221 curses.noecho()
1222
1223 try:
1224 if len(pid) > 0:
1225 pid = int(pid)
1226 if pid != 0 and not os.path.isdir(os.path.join('/proc/',
1227 str(pid))):
1228 msg = '"' + str(pid) + '": Not a running process'
1229 continue
1230 else:
1231 pid = 0
1232 self.refresh_header(pid)
1233 self.update_pid(pid)
1234 break
1235 except ValueError:
1236 msg = '"' + str(pid) + '": Not a valid pid'
1237
1238 def show_set_update_interval(self):
1239 """Draws update interval selection mask.""" 1292 """Draws update interval selection mask."""
1240 msg = '' 1293 msg = ''
1241 while True: 1294 while True:
@@ -1265,60 +1318,67 @@ class Tui(object):
1265 1318
1266 except ValueError: 1319 except ValueError:
1267 msg = '"' + str(val) + '": Invalid value' 1320 msg = '"' + str(val) + '": Invalid value'
1268 self.refresh_header() 1321 self._refresh_header()
1269 1322
1270 def show_vm_selection_by_guest_name(self): 1323 def _show_vm_selection_by_guest(self):
1271 """Draws guest selection mask. 1324 """Draws guest selection mask.
1272 1325
1273 Asks for a guest name until a valid guest name or '' is entered. 1326 Asks for a guest name or pid until a valid guest name or '' is entered.
1274 1327
1275 """ 1328 """
1276 msg = '' 1329 msg = ''
1277 while True: 1330 while True:
1278 self.screen.erase() 1331 self.screen.erase()
1279 self.screen.addstr(0, 0, 1332 self.screen.addstr(0, 0,
1280 'Show statistics for specific guest.', 1333 'Show statistics for specific guest or pid.',
1281 curses.A_BOLD) 1334 curses.A_BOLD)
1282 self.screen.addstr(1, 0, 1335 self.screen.addstr(1, 0,
1283 'This might limit the shown data to the trace ' 1336 'This might limit the shown data to the trace '
1284 'statistics.') 1337 'statistics.')
1285 self.screen.addstr(5, 0, msg) 1338 self.screen.addstr(5, 0, msg)
1286 self.print_all_gnames(7) 1339 self._print_all_gnames(7)
1287 curses.echo() 1340 curses.echo()
1288 self.screen.addstr(3, 0, "Guest [ENTER or guest]: ") 1341 curses.curs_set(1)
1289 gname = self.screen.getstr().decode(ENCODING) 1342 self.screen.addstr(3, 0, "Guest or pid [ENTER exits]: ")
1343 guest = self.screen.getstr().decode(ENCODING)
1290 curses.noecho() 1344 curses.noecho()
1291 1345
1292 if not gname: 1346 pid = 0
1293 self.refresh_header(0) 1347 if not guest or guest == '0':
1294 self.update_pid(0)
1295 break 1348 break
1296 else: 1349 if guest.isdigit():
1297 pids = [] 1350 if not os.path.isdir(os.path.join('/proc/', guest)):
1298 try: 1351 msg = '"' + guest + '": Not a running process'
1299 pids = self.get_pid_from_gname(gname)
1300 except:
1301 msg = '"' + gname + '": Internal error while searching, ' \
1302 'use pid filter instead'
1303 continue
1304 if len(pids) == 0:
1305 msg = '"' + gname + '": Not an active guest'
1306 continue 1352 continue
1307 if len(pids) > 1: 1353 pid = int(guest)
1308 msg = '"' + gname + '": Multiple matches found, use pid ' \
1309 'filter instead'
1310 continue
1311 self.refresh_header(pids[0])
1312 self.update_pid(pids[0])
1313 break 1354 break
1355 pids = []
1356 try:
1357 pids = self.get_pid_from_gname(guest)
1358 except:
1359 msg = '"' + guest + '": Internal error while searching, ' \
1360 'use pid filter instead'
1361 continue
1362 if len(pids) == 0:
1363 msg = '"' + guest + '": Not an active guest'
1364 continue
1365 if len(pids) > 1:
1366 msg = '"' + guest + '": Multiple matches found, use pid ' \
1367 'filter instead'
1368 continue
1369 pid = pids[0]
1370 break
1371 curses.curs_set(0)
1372 self._refresh_header(pid)
1373 self._update_pid(pid)
1314 1374
1315 def show_stats(self): 1375 def show_stats(self):
1316 """Refreshes the screen and processes user input.""" 1376 """Refreshes the screen and processes user input."""
1317 sleeptime = self._delay_initial 1377 sleeptime = self._delay_initial
1318 self.refresh_header() 1378 self._refresh_header()
1319 start = 0.0 # result based on init value never appears on screen 1379 start = 0.0 # result based on init value never appears on screen
1320 while True: 1380 while True:
1321 self.refresh_body(time.time() - start) 1381 self._refresh_body(time.time() - start)
1322 curses.halfdelay(int(sleeptime * 10)) 1382 curses.halfdelay(int(sleeptime * 10))
1323 start = time.time() 1383 start = time.time()
1324 sleeptime = self._delay_regular 1384 sleeptime = self._delay_regular
@@ -1327,47 +1387,39 @@ class Tui(object):
1327 if char == 'b': 1387 if char == 'b':
1328 self._display_guests = not self._display_guests 1388 self._display_guests = not self._display_guests
1329 if self.stats.toggle_display_guests(self._display_guests): 1389 if self.stats.toggle_display_guests(self._display_guests):
1330 self.show_msg(['Command not available with tracepoints' 1390 self._show_msg(['Command not available with '
1331 ' enabled', 'Restart with debugfs only ' 1391 'tracepoints enabled', 'Restart with '
1332 '(see option \'-d\') and try again!']) 1392 'debugfs only (see option \'-d\') and '
1393 'try again!'])
1333 self._display_guests = not self._display_guests 1394 self._display_guests = not self._display_guests
1334 self.refresh_header() 1395 self._refresh_header()
1335 if char == 'c': 1396 if char == 'c':
1336 self.stats.fields_filter = DEFAULT_REGEX 1397 self.stats.fields_filter = ''
1337 self.refresh_header(0) 1398 self._refresh_header(0)
1338 self.update_pid(0) 1399 self._update_pid(0)
1339 if char == 'f': 1400 if char == 'f':
1340 curses.curs_set(1) 1401 curses.curs_set(1)
1341 self.show_filter_selection() 1402 self._show_filter_selection()
1342 curses.curs_set(0) 1403 curses.curs_set(0)
1343 sleeptime = self._delay_initial 1404 sleeptime = self._delay_initial
1344 if char == 'g': 1405 if char == 'g' or char == 'p':
1345 curses.curs_set(1) 1406 self._show_vm_selection_by_guest()
1346 self.show_vm_selection_by_guest_name()
1347 curses.curs_set(0)
1348 sleeptime = self._delay_initial 1407 sleeptime = self._delay_initial
1349 if char == 'h': 1408 if char == 'h':
1350 self.show_help_interactive() 1409 self._show_help_interactive()
1351 if char == 'o': 1410 if char == 'o':
1352 self._sorting = not self._sorting 1411 self._sorting = not self._sorting
1353 if char == 'p':
1354 curses.curs_set(1)
1355 self.show_vm_selection_by_pid()
1356 curses.curs_set(0)
1357 sleeptime = self._delay_initial
1358 if char == 'q': 1412 if char == 'q':
1359 break 1413 break
1360 if char == 'r': 1414 if char == 'r':
1361 self.stats.reset() 1415 self.stats.reset()
1362 if char == 's': 1416 if char == 's':
1363 curses.curs_set(1) 1417 curses.curs_set(1)
1364 self.show_set_update_interval() 1418 self._show_set_update_interval()
1365 curses.curs_set(0) 1419 curses.curs_set(0)
1366 sleeptime = self._delay_initial 1420 sleeptime = self._delay_initial
1367 if char == 'x': 1421 if char == 'x':
1368 self.update_drilldown() 1422 self.stats.child_events = not self.stats.child_events
1369 # prevents display of current values on next refresh
1370 self.stats.get(self._display_guests)
1371 except KeyboardInterrupt: 1423 except KeyboardInterrupt:
1372 break 1424 break
1373 except curses.error: 1425 except curses.error:
@@ -1380,9 +1432,9 @@ def batch(stats):
1380 s = stats.get() 1432 s = stats.get()
1381 time.sleep(1) 1433 time.sleep(1)
1382 s = stats.get() 1434 s = stats.get()
1383 for key in sorted(s.keys()): 1435 for key, values in sorted(s.items()):
1384 values = s[key] 1436 print('%-42s%10d%10d' % (key.split(' ')[0], values.value,
1385 print('%-42s%10d%10d' % (key, values[0], values[1])) 1437 values.delta))
1386 except KeyboardInterrupt: 1438 except KeyboardInterrupt:
1387 pass 1439 pass
1388 1440
@@ -1392,14 +1444,14 @@ def log(stats):
1392 keys = sorted(stats.get().keys()) 1444 keys = sorted(stats.get().keys())
1393 1445
1394 def banner(): 1446 def banner():
1395 for k in keys: 1447 for key in keys:
1396 print(k, end=' ') 1448 print(key.split(' ')[0], end=' ')
1397 print() 1449 print()
1398 1450
1399 def statline(): 1451 def statline():
1400 s = stats.get() 1452 s = stats.get()
1401 for k in keys: 1453 for key in keys:
1402 print(' %9d' % s[k][1], end=' ') 1454 print(' %9d' % s[key].delta, end=' ')
1403 print() 1455 print()
1404 line = 0 1456 line = 0
1405 banner_repeat = 20 1457 banner_repeat = 20
@@ -1504,7 +1556,7 @@ Press any other key to refresh statistics immediately.
1504 ) 1556 )
1505 optparser.add_option('-f', '--fields', 1557 optparser.add_option('-f', '--fields',
1506 action='store', 1558 action='store',
1507 default=DEFAULT_REGEX, 1559 default='',
1508 dest='fields', 1560 dest='fields',
1509 help='''fields to display (regex) 1561 help='''fields to display (regex)
1510 "-f help" for a list of available events''', 1562 "-f help" for a list of available events''',
@@ -1539,17 +1591,6 @@ Press any other key to refresh statistics immediately.
1539 1591
1540def check_access(options): 1592def check_access(options):
1541 """Exits if the current user can't access all needed directories.""" 1593 """Exits if the current user can't access all needed directories."""
1542 if not os.path.exists('/sys/kernel/debug'):
1543 sys.stderr.write('Please enable CONFIG_DEBUG_FS in your kernel.')
1544 sys.exit(1)
1545
1546 if not os.path.exists(PATH_DEBUGFS_KVM):
1547 sys.stderr.write("Please make sure, that debugfs is mounted and "
1548 "readable by the current user:\n"
1549 "('mount -t debugfs debugfs /sys/kernel/debug')\n"
1550 "Also ensure, that the kvm modules are loaded.\n")
1551 sys.exit(1)
1552
1553 if not os.path.exists(PATH_DEBUGFS_TRACING) and (options.tracepoints or 1594 if not os.path.exists(PATH_DEBUGFS_TRACING) and (options.tracepoints or
1554 not options.debugfs): 1595 not options.debugfs):
1555 sys.stderr.write("Please enable CONFIG_TRACING in your kernel " 1596 sys.stderr.write("Please enable CONFIG_TRACING in your kernel "
@@ -1567,7 +1608,33 @@ def check_access(options):
1567 return options 1608 return options
1568 1609
1569 1610
1611def assign_globals():
1612 global PATH_DEBUGFS_KVM
1613 global PATH_DEBUGFS_TRACING
1614
1615 debugfs = ''
1616 for line in file('/proc/mounts'):
1617 if line.split(' ')[0] == 'debugfs':
1618 debugfs = line.split(' ')[1]
1619 break
1620 if debugfs == '':
1621 sys.stderr.write("Please make sure that CONFIG_DEBUG_FS is enabled in "
1622 "your kernel, mounted and\nreadable by the current "
1623 "user:\n"
1624 "('mount -t debugfs debugfs /sys/kernel/debug')\n")
1625 sys.exit(1)
1626
1627 PATH_DEBUGFS_KVM = os.path.join(debugfs, 'kvm')
1628 PATH_DEBUGFS_TRACING = os.path.join(debugfs, 'tracing')
1629
1630 if not os.path.exists(PATH_DEBUGFS_KVM):
1631 sys.stderr.write("Please make sure that CONFIG_KVM is enabled in "
1632 "your kernel and that the modules are loaded.\n")
1633 sys.exit(1)
1634
1635
1570def main(): 1636def main():
1637 assign_globals()
1571 options = get_options() 1638 options = get_options()
1572 options = check_access(options) 1639 options = check_access(options)
1573 1640
diff --git a/tools/kvm/kvm_stat/kvm_stat.txt b/tools/kvm/kvm_stat/kvm_stat.txt
index b5b3810c9e94..0811d860fe75 100644
--- a/tools/kvm/kvm_stat/kvm_stat.txt
+++ b/tools/kvm/kvm_stat/kvm_stat.txt
@@ -35,13 +35,13 @@ INTERACTIVE COMMANDS
35 35
36*f*:: filter by regular expression 36*f*:: filter by regular expression
37 37
38*g*:: filter by guest name 38*g*:: filter by guest name/PID
39 39
40*h*:: display interactive commands reference 40*h*:: display interactive commands reference
41 41
42*o*:: toggle sorting order (Total vs CurAvg/s) 42*o*:: toggle sorting order (Total vs CurAvg/s)
43 43
44*p*:: filter by PID 44*p*:: filter by guest name/PID
45 45
46*q*:: quit 46*q*:: quit
47 47
diff --git a/tools/laptop/freefall/Makefile b/tools/laptop/freefall/Makefile
index 5f758c489a20..b572d94255f6 100644
--- a/tools/laptop/freefall/Makefile
+++ b/tools/laptop/freefall/Makefile
@@ -2,7 +2,6 @@
2PREFIX ?= /usr 2PREFIX ?= /usr
3SBINDIR ?= sbin 3SBINDIR ?= sbin
4INSTALL ?= install 4INSTALL ?= install
5CC = $(CROSS_COMPILE)gcc
6 5
7TARGET = freefall 6TARGET = freefall
8 7
diff --git a/tools/leds/Makefile b/tools/leds/Makefile
index c379af003807..7b6bed13daaa 100644
--- a/tools/leds/Makefile
+++ b/tools/leds/Makefile
@@ -1,7 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2# Makefile for LEDs tools 2# Makefile for LEDs tools
3 3
4CC = $(CROSS_COMPILE)gcc
5CFLAGS = -Wall -Wextra -g -I../../include/uapi 4CFLAGS = -Wall -Wextra -g -I../../include/uapi
6 5
7all: uledmon led_hw_brightness_mon 6all: uledmon led_hw_brightness_mon
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 97073d649c1a..5bbbf285af74 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1060,11 +1060,12 @@ bpf_program__reloc_text(struct bpf_program *prog, struct bpf_object *obj,
1060 prog->insns = new_insn; 1060 prog->insns = new_insn;
1061 prog->main_prog_cnt = prog->insns_cnt; 1061 prog->main_prog_cnt = prog->insns_cnt;
1062 prog->insns_cnt = new_cnt; 1062 prog->insns_cnt = new_cnt;
1063 pr_debug("added %zd insn from %s to prog %s\n",
1064 text->insns_cnt, text->section_name,
1065 prog->section_name);
1063 } 1066 }
1064 insn = &prog->insns[relo->insn_idx]; 1067 insn = &prog->insns[relo->insn_idx];
1065 insn->imm += prog->main_prog_cnt - relo->insn_idx; 1068 insn->imm += prog->main_prog_cnt - relo->insn_idx;
1066 pr_debug("added %zd insn from %s to prog %s\n",
1067 text->insns_cnt, text->section_name, prog->section_name);
1068 return 0; 1069 return 0;
1069} 1070}
1070 1071
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 57254f5b2779..694abc628e9b 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -29,7 +29,7 @@
29#include "builtin.h" 29#include "builtin.h"
30#include "check.h" 30#include "check.h"
31 31
32bool no_fp, no_unreachable; 32bool no_fp, no_unreachable, retpoline, module;
33 33
34static const char * const check_usage[] = { 34static const char * const check_usage[] = {
35 "objtool check [<options>] file.o", 35 "objtool check [<options>] file.o",
@@ -39,6 +39,8 @@ static const char * const check_usage[] = {
39const struct option check_options[] = { 39const struct option check_options[] = {
40 OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"), 40 OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"),
41 OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"), 41 OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"),
42 OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions"),
43 OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of a kernel module"),
42 OPT_END(), 44 OPT_END(),
43}; 45};
44 46
@@ -53,5 +55,5 @@ int cmd_check(int argc, const char **argv)
53 55
54 objname = argv[0]; 56 objname = argv[0];
55 57
56 return check(objname, no_fp, no_unreachable, false); 58 return check(objname, false);
57} 59}
diff --git a/tools/objtool/builtin-orc.c b/tools/objtool/builtin-orc.c
index 91e8e19ff5e0..77ea2b97117d 100644
--- a/tools/objtool/builtin-orc.c
+++ b/tools/objtool/builtin-orc.c
@@ -25,7 +25,6 @@
25 */ 25 */
26 26
27#include <string.h> 27#include <string.h>
28#include <subcmd/parse-options.h>
29#include "builtin.h" 28#include "builtin.h"
30#include "check.h" 29#include "check.h"
31 30
@@ -36,9 +35,6 @@ static const char *orc_usage[] = {
36 NULL, 35 NULL,
37}; 36};
38 37
39extern const struct option check_options[];
40extern bool no_fp, no_unreachable;
41
42int cmd_orc(int argc, const char **argv) 38int cmd_orc(int argc, const char **argv)
43{ 39{
44 const char *objname; 40 const char *objname;
@@ -54,7 +50,7 @@ int cmd_orc(int argc, const char **argv)
54 50
55 objname = argv[0]; 51 objname = argv[0];
56 52
57 return check(objname, no_fp, no_unreachable, true); 53 return check(objname, true);
58 } 54 }
59 55
60 if (!strcmp(argv[0], "dump")) { 56 if (!strcmp(argv[0], "dump")) {
diff --git a/tools/objtool/builtin.h b/tools/objtool/builtin.h
index dd526067fed5..28ff40e19a14 100644
--- a/tools/objtool/builtin.h
+++ b/tools/objtool/builtin.h
@@ -17,6 +17,11 @@
17#ifndef _BUILTIN_H 17#ifndef _BUILTIN_H
18#define _BUILTIN_H 18#define _BUILTIN_H
19 19
20#include <subcmd/parse-options.h>
21
22extern const struct option check_options[];
23extern bool no_fp, no_unreachable, retpoline, module;
24
20extern int cmd_check(int argc, const char **argv); 25extern int cmd_check(int argc, const char **argv);
21extern int cmd_orc(int argc, const char **argv); 26extern int cmd_orc(int argc, const char **argv);
22 27
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index b00b1896547e..92b6a2c21631 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -18,6 +18,7 @@
18#include <string.h> 18#include <string.h>
19#include <stdlib.h> 19#include <stdlib.h>
20 20
21#include "builtin.h"
21#include "check.h" 22#include "check.h"
22#include "elf.h" 23#include "elf.h"
23#include "special.h" 24#include "special.h"
@@ -33,7 +34,6 @@ struct alternative {
33}; 34};
34 35
35const char *objname; 36const char *objname;
36static bool no_fp;
37struct cfi_state initial_func_cfi; 37struct cfi_state initial_func_cfi;
38 38
39struct instruction *find_insn(struct objtool_file *file, 39struct instruction *find_insn(struct objtool_file *file,
@@ -497,6 +497,7 @@ static int add_jump_destinations(struct objtool_file *file)
497 * disguise, so convert them accordingly. 497 * disguise, so convert them accordingly.
498 */ 498 */
499 insn->type = INSN_JUMP_DYNAMIC; 499 insn->type = INSN_JUMP_DYNAMIC;
500 insn->retpoline_safe = true;
500 continue; 501 continue;
501 } else { 502 } else {
502 /* sibling call */ 503 /* sibling call */
@@ -548,7 +549,8 @@ static int add_call_destinations(struct objtool_file *file)
548 if (!insn->call_dest && !insn->ignore) { 549 if (!insn->call_dest && !insn->ignore) {
549 WARN_FUNC("unsupported intra-function call", 550 WARN_FUNC("unsupported intra-function call",
550 insn->sec, insn->offset); 551 insn->sec, insn->offset);
551 WARN("If this is a retpoline, please patch it in with alternatives and annotate it with ANNOTATE_NOSPEC_ALTERNATIVE."); 552 if (retpoline)
553 WARN("If this is a retpoline, please patch it in with alternatives and annotate it with ANNOTATE_NOSPEC_ALTERNATIVE.");
552 return -1; 554 return -1;
553 } 555 }
554 556
@@ -852,8 +854,14 @@ static int add_switch_table(struct objtool_file *file, struct symbol *func,
852 * This is a fairly uncommon pattern which is new for GCC 6. As of this 854 * This is a fairly uncommon pattern which is new for GCC 6. As of this
853 * writing, there are 11 occurrences of it in the allmodconfig kernel. 855 * writing, there are 11 occurrences of it in the allmodconfig kernel.
854 * 856 *
857 * As of GCC 7 there are quite a few more of these and the 'in between' code
858 * is significant. Esp. with KASAN enabled some of the code between the mov
859 * and jmpq uses .rodata itself, which can confuse things.
860 *
855 * TODO: Once we have DWARF CFI and smarter instruction decoding logic, 861 * TODO: Once we have DWARF CFI and smarter instruction decoding logic,
856 * ensure the same register is used in the mov and jump instructions. 862 * ensure the same register is used in the mov and jump instructions.
863 *
864 * NOTE: RETPOLINE made it harder still to decode dynamic jumps.
857 */ 865 */
858static struct rela *find_switch_table(struct objtool_file *file, 866static struct rela *find_switch_table(struct objtool_file *file,
859 struct symbol *func, 867 struct symbol *func,
@@ -875,12 +883,25 @@ static struct rela *find_switch_table(struct objtool_file *file,
875 text_rela->addend + 4); 883 text_rela->addend + 4);
876 if (!rodata_rela) 884 if (!rodata_rela)
877 return NULL; 885 return NULL;
886
878 file->ignore_unreachables = true; 887 file->ignore_unreachables = true;
879 return rodata_rela; 888 return rodata_rela;
880 } 889 }
881 890
882 /* case 3 */ 891 /* case 3 */
883 func_for_each_insn_continue_reverse(file, func, insn) { 892 /*
893 * Backward search using the @first_jump_src links, these help avoid
894 * much of the 'in between' code. Which avoids us getting confused by
895 * it.
896 */
897 for (insn = list_prev_entry(insn, list);
898
899 &insn->list != &file->insn_list &&
900 insn->sec == func->sec &&
901 insn->offset >= func->offset;
902
903 insn = insn->first_jump_src ?: list_prev_entry(insn, list)) {
904
884 if (insn->type == INSN_JUMP_DYNAMIC) 905 if (insn->type == INSN_JUMP_DYNAMIC)
885 break; 906 break;
886 907
@@ -904,20 +925,42 @@ static struct rela *find_switch_table(struct objtool_file *file,
904 if (find_symbol_containing(file->rodata, text_rela->addend)) 925 if (find_symbol_containing(file->rodata, text_rela->addend))
905 continue; 926 continue;
906 927
907 return find_rela_by_dest(file->rodata, text_rela->addend); 928 rodata_rela = find_rela_by_dest(file->rodata, text_rela->addend);
929 if (!rodata_rela)
930 continue;
931
932 return rodata_rela;
908 } 933 }
909 934
910 return NULL; 935 return NULL;
911} 936}
912 937
938
913static int add_func_switch_tables(struct objtool_file *file, 939static int add_func_switch_tables(struct objtool_file *file,
914 struct symbol *func) 940 struct symbol *func)
915{ 941{
916 struct instruction *insn, *prev_jump = NULL; 942 struct instruction *insn, *last = NULL, *prev_jump = NULL;
917 struct rela *rela, *prev_rela = NULL; 943 struct rela *rela, *prev_rela = NULL;
918 int ret; 944 int ret;
919 945
920 func_for_each_insn(file, func, insn) { 946 func_for_each_insn(file, func, insn) {
947 if (!last)
948 last = insn;
949
950 /*
951 * Store back-pointers for unconditional forward jumps such
952 * that find_switch_table() can back-track using those and
953 * avoid some potentially confusing code.
954 */
955 if (insn->type == INSN_JUMP_UNCONDITIONAL && insn->jump_dest &&
956 insn->offset > last->offset &&
957 insn->jump_dest->offset > insn->offset &&
958 !insn->jump_dest->first_jump_src) {
959
960 insn->jump_dest->first_jump_src = insn;
961 last = insn->jump_dest;
962 }
963
921 if (insn->type != INSN_JUMP_DYNAMIC) 964 if (insn->type != INSN_JUMP_DYNAMIC)
922 continue; 965 continue;
923 966
@@ -1071,6 +1114,41 @@ static int read_unwind_hints(struct objtool_file *file)
1071 return 0; 1114 return 0;
1072} 1115}
1073 1116
1117static int read_retpoline_hints(struct objtool_file *file)
1118{
1119 struct section *sec;
1120 struct instruction *insn;
1121 struct rela *rela;
1122
1123 sec = find_section_by_name(file->elf, ".rela.discard.retpoline_safe");
1124 if (!sec)
1125 return 0;
1126
1127 list_for_each_entry(rela, &sec->rela_list, list) {
1128 if (rela->sym->type != STT_SECTION) {
1129 WARN("unexpected relocation symbol type in %s", sec->name);
1130 return -1;
1131 }
1132
1133 insn = find_insn(file, rela->sym->sec, rela->addend);
1134 if (!insn) {
1135 WARN("bad .discard.retpoline_safe entry");
1136 return -1;
1137 }
1138
1139 if (insn->type != INSN_JUMP_DYNAMIC &&
1140 insn->type != INSN_CALL_DYNAMIC) {
1141 WARN_FUNC("retpoline_safe hint not an indirect jump/call",
1142 insn->sec, insn->offset);
1143 return -1;
1144 }
1145
1146 insn->retpoline_safe = true;
1147 }
1148
1149 return 0;
1150}
1151
1074static int decode_sections(struct objtool_file *file) 1152static int decode_sections(struct objtool_file *file)
1075{ 1153{
1076 int ret; 1154 int ret;
@@ -1109,6 +1187,10 @@ static int decode_sections(struct objtool_file *file)
1109 if (ret) 1187 if (ret)
1110 return ret; 1188 return ret;
1111 1189
1190 ret = read_retpoline_hints(file);
1191 if (ret)
1192 return ret;
1193
1112 return 0; 1194 return 0;
1113} 1195}
1114 1196
@@ -1854,6 +1936,38 @@ static int validate_unwind_hints(struct objtool_file *file)
1854 return warnings; 1936 return warnings;
1855} 1937}
1856 1938
1939static int validate_retpoline(struct objtool_file *file)
1940{
1941 struct instruction *insn;
1942 int warnings = 0;
1943
1944 for_each_insn(file, insn) {
1945 if (insn->type != INSN_JUMP_DYNAMIC &&
1946 insn->type != INSN_CALL_DYNAMIC)
1947 continue;
1948
1949 if (insn->retpoline_safe)
1950 continue;
1951
1952 /*
1953 * .init.text code is ran before userspace and thus doesn't
1954 * strictly need retpolines, except for modules which are
1955 * loaded late, they very much do need retpoline in their
1956 * .init.text
1957 */
1958 if (!strcmp(insn->sec->name, ".init.text") && !module)
1959 continue;
1960
1961 WARN_FUNC("indirect %s found in RETPOLINE build",
1962 insn->sec, insn->offset,
1963 insn->type == INSN_JUMP_DYNAMIC ? "jump" : "call");
1964
1965 warnings++;
1966 }
1967
1968 return warnings;
1969}
1970
1857static bool is_kasan_insn(struct instruction *insn) 1971static bool is_kasan_insn(struct instruction *insn)
1858{ 1972{
1859 return (insn->type == INSN_CALL && 1973 return (insn->type == INSN_CALL &&
@@ -1899,13 +2013,19 @@ static bool ignore_unreachable_insn(struct instruction *insn)
1899 if (is_kasan_insn(insn) || is_ubsan_insn(insn)) 2013 if (is_kasan_insn(insn) || is_ubsan_insn(insn))
1900 return true; 2014 return true;
1901 2015
1902 if (insn->type == INSN_JUMP_UNCONDITIONAL && insn->jump_dest) { 2016 if (insn->type == INSN_JUMP_UNCONDITIONAL) {
1903 insn = insn->jump_dest; 2017 if (insn->jump_dest &&
1904 continue; 2018 insn->jump_dest->func == insn->func) {
2019 insn = insn->jump_dest;
2020 continue;
2021 }
2022
2023 break;
1905 } 2024 }
1906 2025
1907 if (insn->offset + insn->len >= insn->func->offset + insn->func->len) 2026 if (insn->offset + insn->len >= insn->func->offset + insn->func->len)
1908 break; 2027 break;
2028
1909 insn = list_next_entry(insn, list); 2029 insn = list_next_entry(insn, list);
1910 } 2030 }
1911 2031
@@ -1979,13 +2099,12 @@ static void cleanup(struct objtool_file *file)
1979 elf_close(file->elf); 2099 elf_close(file->elf);
1980} 2100}
1981 2101
1982int check(const char *_objname, bool _no_fp, bool no_unreachable, bool orc) 2102int check(const char *_objname, bool orc)
1983{ 2103{
1984 struct objtool_file file; 2104 struct objtool_file file;
1985 int ret, warnings = 0; 2105 int ret, warnings = 0;
1986 2106
1987 objname = _objname; 2107 objname = _objname;
1988 no_fp = _no_fp;
1989 2108
1990 file.elf = elf_open(objname, orc ? O_RDWR : O_RDONLY); 2109 file.elf = elf_open(objname, orc ? O_RDWR : O_RDONLY);
1991 if (!file.elf) 2110 if (!file.elf)
@@ -2009,6 +2128,13 @@ int check(const char *_objname, bool _no_fp, bool no_unreachable, bool orc)
2009 if (list_empty(&file.insn_list)) 2128 if (list_empty(&file.insn_list))
2010 goto out; 2129 goto out;
2011 2130
2131 if (retpoline) {
2132 ret = validate_retpoline(&file);
2133 if (ret < 0)
2134 return ret;
2135 warnings += ret;
2136 }
2137
2012 ret = validate_functions(&file); 2138 ret = validate_functions(&file);
2013 if (ret < 0) 2139 if (ret < 0)
2014 goto out; 2140 goto out;
diff --git a/tools/objtool/check.h b/tools/objtool/check.h
index dbadb304a410..c6b68fcb926f 100644
--- a/tools/objtool/check.h
+++ b/tools/objtool/check.h
@@ -45,8 +45,10 @@ struct instruction {
45 unsigned char type; 45 unsigned char type;
46 unsigned long immediate; 46 unsigned long immediate;
47 bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts; 47 bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts;
48 bool retpoline_safe;
48 struct symbol *call_dest; 49 struct symbol *call_dest;
49 struct instruction *jump_dest; 50 struct instruction *jump_dest;
51 struct instruction *first_jump_src;
50 struct list_head alts; 52 struct list_head alts;
51 struct symbol *func; 53 struct symbol *func;
52 struct stack_op stack_op; 54 struct stack_op stack_op;
@@ -62,7 +64,7 @@ struct objtool_file {
62 bool ignore_unreachables, c_file, hints; 64 bool ignore_unreachables, c_file, hints;
63}; 65};
64 66
65int check(const char *objname, bool no_fp, bool no_unreachable, bool orc); 67int check(const char *objname, bool orc);
66 68
67struct instruction *find_insn(struct objtool_file *file, 69struct instruction *find_insn(struct objtool_file *file,
68 struct section *sec, unsigned long offset); 70 struct section *sec, unsigned long offset);
diff --git a/tools/perf/Documentation/perf-data.txt b/tools/perf/Documentation/perf-data.txt
index f0796a47dfa3..90bb4aabe4f8 100644
--- a/tools/perf/Documentation/perf-data.txt
+++ b/tools/perf/Documentation/perf-data.txt
@@ -30,6 +30,10 @@ OPTIONS for 'convert'
30-i:: 30-i::
31 Specify input perf data file path. 31 Specify input perf data file path.
32 32
33-f::
34--force::
35 Don't complain, do it.
36
33-v:: 37-v::
34--verbose:: 38--verbose::
35 Be more verbose (show counter open errors, etc). 39 Be more verbose (show counter open errors, etc).
diff --git a/tools/perf/Documentation/perf-kallsyms.txt b/tools/perf/Documentation/perf-kallsyms.txt
index 954ea9e21236..cf9f4040ea5c 100644
--- a/tools/perf/Documentation/perf-kallsyms.txt
+++ b/tools/perf/Documentation/perf-kallsyms.txt
@@ -8,7 +8,7 @@ perf-kallsyms - Searches running kernel for symbols
8SYNOPSIS 8SYNOPSIS
9-------- 9--------
10[verse] 10[verse]
11'perf kallsyms <options> symbol_name[,symbol_name...]' 11'perf kallsyms' [<options>] symbol_name[,symbol_name...]
12 12
13DESCRIPTION 13DESCRIPTION
14----------- 14-----------
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 9b0351d3ce34..012328038594 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -146,12 +146,6 @@ define allow-override
146 $(eval $(1) = $(2))) 146 $(eval $(1) = $(2)))
147endef 147endef
148 148
149# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix.
150$(call allow-override,CC,$(CROSS_COMPILE)gcc)
151$(call allow-override,AR,$(CROSS_COMPILE)ar)
152$(call allow-override,LD,$(CROSS_COMPILE)ld)
153$(call allow-override,CXX,$(CROSS_COMPILE)g++)
154
155LD += $(EXTRA_LDFLAGS) 149LD += $(EXTRA_LDFLAGS)
156 150
157HOSTCC ?= gcc 151HOSTCC ?= gcc
diff --git a/tools/perf/arch/s390/Makefile b/tools/perf/arch/s390/Makefile
index 48228de415d0..dfa6e3103437 100644
--- a/tools/perf/arch/s390/Makefile
+++ b/tools/perf/arch/s390/Makefile
@@ -10,15 +10,19 @@ PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
10 10
11out := $(OUTPUT)arch/s390/include/generated/asm 11out := $(OUTPUT)arch/s390/include/generated/asm
12header := $(out)/syscalls_64.c 12header := $(out)/syscalls_64.c
13sysdef := $(srctree)/tools/arch/s390/include/uapi/asm/unistd.h 13syskrn := $(srctree)/arch/s390/kernel/syscalls/syscall.tbl
14sysprf := $(srctree)/tools/perf/arch/s390/entry/syscalls/ 14sysprf := $(srctree)/tools/perf/arch/s390/entry/syscalls
15sysdef := $(sysprf)/syscall.tbl
15systbl := $(sysprf)/mksyscalltbl 16systbl := $(sysprf)/mksyscalltbl
16 17
17# Create output directory if not already present 18# Create output directory if not already present
18_dummy := $(shell [ -d '$(out)' ] || mkdir -p '$(out)') 19_dummy := $(shell [ -d '$(out)' ] || mkdir -p '$(out)')
19 20
20$(header): $(sysdef) $(systbl) 21$(header): $(sysdef) $(systbl)
21 $(Q)$(SHELL) '$(systbl)' '$(CC)' $(sysdef) > $@ 22 @(test -d ../../kernel -a -d ../../tools -a -d ../perf && ( \
23 (diff -B $(sysdef) $(syskrn) >/dev/null) \
24 || echo "Warning: Kernel ABI header at '$(sysdef)' differs from latest version at '$(syskrn)'" >&2 )) || true
25 $(Q)$(SHELL) '$(systbl)' $(sysdef) > $@
22 26
23clean:: 27clean::
24 $(call QUIET_CLEAN, s390) $(RM) $(header) 28 $(call QUIET_CLEAN, s390) $(RM) $(header)
diff --git a/tools/perf/arch/s390/entry/syscalls/mksyscalltbl b/tools/perf/arch/s390/entry/syscalls/mksyscalltbl
index 7fa0d0abd419..72ecbb676370 100755
--- a/tools/perf/arch/s390/entry/syscalls/mksyscalltbl
+++ b/tools/perf/arch/s390/entry/syscalls/mksyscalltbl
@@ -3,25 +3,23 @@
3# 3#
4# Generate system call table for perf 4# Generate system call table for perf
5# 5#
6# 6# Copyright IBM Corp. 2017, 2018
7# Copyright IBM Corp. 2017
8# Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com> 7# Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
9# 8#
10 9
11gcc=$1 10SYSCALL_TBL=$1
12input=$2
13 11
14if ! test -r $input; then 12if ! test -r $SYSCALL_TBL; then
15 echo "Could not read input file" >&2 13 echo "Could not read input file" >&2
16 exit 1 14 exit 1
17fi 15fi
18 16
19create_table() 17create_table()
20{ 18{
21 local max_nr 19 local max_nr nr abi sc discard
22 20
23 echo 'static const char *syscalltbl_s390_64[] = {' 21 echo 'static const char *syscalltbl_s390_64[] = {'
24 while read sc nr; do 22 while read nr abi sc discard; do
25 printf '\t[%d] = "%s",\n' $nr $sc 23 printf '\t[%d] = "%s",\n' $nr $sc
26 max_nr=$nr 24 max_nr=$nr
27 done 25 done
@@ -29,8 +27,6 @@ create_table()
29 echo "#define SYSCALLTBL_S390_64_MAX_ID $max_nr" 27 echo "#define SYSCALLTBL_S390_64_MAX_ID $max_nr"
30} 28}
31 29
32 30grep -E "^[[:digit:]]+[[:space:]]+(common|64)" $SYSCALL_TBL \
33$gcc -m64 -E -dM -x c $input \ 31 |sort -k1 -n \
34 |sed -ne 's/^#define __NR_//p' \
35 |sort -t' ' -k2 -nu \
36 |create_table 32 |create_table
diff --git a/tools/perf/arch/s390/entry/syscalls/syscall.tbl b/tools/perf/arch/s390/entry/syscalls/syscall.tbl
new file mode 100644
index 000000000000..b38d48464368
--- /dev/null
+++ b/tools/perf/arch/s390/entry/syscalls/syscall.tbl
@@ -0,0 +1,390 @@
1# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2#
3# System call table for s390
4#
5# Format:
6#
7# <nr> <abi> <syscall> <entry-64bit> <compat-entry>
8#
9# where <abi> can be common, 64, or 32
10
111 common exit sys_exit sys_exit
122 common fork sys_fork sys_fork
133 common read sys_read compat_sys_s390_read
144 common write sys_write compat_sys_s390_write
155 common open sys_open compat_sys_open
166 common close sys_close sys_close
177 common restart_syscall sys_restart_syscall sys_restart_syscall
188 common creat sys_creat compat_sys_creat
199 common link sys_link compat_sys_link
2010 common unlink sys_unlink compat_sys_unlink
2111 common execve sys_execve compat_sys_execve
2212 common chdir sys_chdir compat_sys_chdir
2313 32 time - compat_sys_time
2414 common mknod sys_mknod compat_sys_mknod
2515 common chmod sys_chmod compat_sys_chmod
2616 32 lchown - compat_sys_s390_lchown16
2719 common lseek sys_lseek compat_sys_lseek
2820 common getpid sys_getpid sys_getpid
2921 common mount sys_mount compat_sys_mount
3022 common umount sys_oldumount compat_sys_oldumount
3123 32 setuid - compat_sys_s390_setuid16
3224 32 getuid - compat_sys_s390_getuid16
3325 32 stime - compat_sys_stime
3426 common ptrace sys_ptrace compat_sys_ptrace
3527 common alarm sys_alarm sys_alarm
3629 common pause sys_pause sys_pause
3730 common utime sys_utime compat_sys_utime
3833 common access sys_access compat_sys_access
3934 common nice sys_nice sys_nice
4036 common sync sys_sync sys_sync
4137 common kill sys_kill sys_kill
4238 common rename sys_rename compat_sys_rename
4339 common mkdir sys_mkdir compat_sys_mkdir
4440 common rmdir sys_rmdir compat_sys_rmdir
4541 common dup sys_dup sys_dup
4642 common pipe sys_pipe compat_sys_pipe
4743 common times sys_times compat_sys_times
4845 common brk sys_brk compat_sys_brk
4946 32 setgid - compat_sys_s390_setgid16
5047 32 getgid - compat_sys_s390_getgid16
5148 common signal sys_signal compat_sys_signal
5249 32 geteuid - compat_sys_s390_geteuid16
5350 32 getegid - compat_sys_s390_getegid16
5451 common acct sys_acct compat_sys_acct
5552 common umount2 sys_umount compat_sys_umount
5654 common ioctl sys_ioctl compat_sys_ioctl
5755 common fcntl sys_fcntl compat_sys_fcntl
5857 common setpgid sys_setpgid sys_setpgid
5960 common umask sys_umask sys_umask
6061 common chroot sys_chroot compat_sys_chroot
6162 common ustat sys_ustat compat_sys_ustat
6263 common dup2 sys_dup2 sys_dup2
6364 common getppid sys_getppid sys_getppid
6465 common getpgrp sys_getpgrp sys_getpgrp
6566 common setsid sys_setsid sys_setsid
6667 common sigaction sys_sigaction compat_sys_sigaction
6770 32 setreuid - compat_sys_s390_setreuid16
6871 32 setregid - compat_sys_s390_setregid16
6972 common sigsuspend sys_sigsuspend compat_sys_sigsuspend
7073 common sigpending sys_sigpending compat_sys_sigpending
7174 common sethostname sys_sethostname compat_sys_sethostname
7275 common setrlimit sys_setrlimit compat_sys_setrlimit
7376 32 getrlimit - compat_sys_old_getrlimit
7477 common getrusage sys_getrusage compat_sys_getrusage
7578 common gettimeofday sys_gettimeofday compat_sys_gettimeofday
7679 common settimeofday sys_settimeofday compat_sys_settimeofday
7780 32 getgroups - compat_sys_s390_getgroups16
7881 32 setgroups - compat_sys_s390_setgroups16
7983 common symlink sys_symlink compat_sys_symlink
8085 common readlink sys_readlink compat_sys_readlink
8186 common uselib sys_uselib compat_sys_uselib
8287 common swapon sys_swapon compat_sys_swapon
8388 common reboot sys_reboot compat_sys_reboot
8489 common readdir - compat_sys_old_readdir
8590 common mmap sys_old_mmap compat_sys_s390_old_mmap
8691 common munmap sys_munmap compat_sys_munmap
8792 common truncate sys_truncate compat_sys_truncate
8893 common ftruncate sys_ftruncate compat_sys_ftruncate
8994 common fchmod sys_fchmod sys_fchmod
9095 32 fchown - compat_sys_s390_fchown16
9196 common getpriority sys_getpriority sys_getpriority
9297 common setpriority sys_setpriority sys_setpriority
9399 common statfs sys_statfs compat_sys_statfs
94100 common fstatfs sys_fstatfs compat_sys_fstatfs
95101 32 ioperm - -
96102 common socketcall sys_socketcall compat_sys_socketcall
97103 common syslog sys_syslog compat_sys_syslog
98104 common setitimer sys_setitimer compat_sys_setitimer
99105 common getitimer sys_getitimer compat_sys_getitimer
100106 common stat sys_newstat compat_sys_newstat
101107 common lstat sys_newlstat compat_sys_newlstat
102108 common fstat sys_newfstat compat_sys_newfstat
103110 common lookup_dcookie sys_lookup_dcookie compat_sys_lookup_dcookie
104111 common vhangup sys_vhangup sys_vhangup
105112 common idle - -
106114 common wait4 sys_wait4 compat_sys_wait4
107115 common swapoff sys_swapoff compat_sys_swapoff
108116 common sysinfo sys_sysinfo compat_sys_sysinfo
109117 common ipc sys_s390_ipc compat_sys_s390_ipc
110118 common fsync sys_fsync sys_fsync
111119 common sigreturn sys_sigreturn compat_sys_sigreturn
112120 common clone sys_clone compat_sys_clone
113121 common setdomainname sys_setdomainname compat_sys_setdomainname
114122 common uname sys_newuname compat_sys_newuname
115124 common adjtimex sys_adjtimex compat_sys_adjtimex
116125 common mprotect sys_mprotect compat_sys_mprotect
117126 common sigprocmask sys_sigprocmask compat_sys_sigprocmask
118127 common create_module - -
119128 common init_module sys_init_module compat_sys_init_module
120129 common delete_module sys_delete_module compat_sys_delete_module
121130 common get_kernel_syms - -
122131 common quotactl sys_quotactl compat_sys_quotactl
123132 common getpgid sys_getpgid sys_getpgid
124133 common fchdir sys_fchdir sys_fchdir
125134 common bdflush sys_bdflush compat_sys_bdflush
126135 common sysfs sys_sysfs compat_sys_sysfs
127136 common personality sys_s390_personality sys_s390_personality
128137 common afs_syscall - -
129138 32 setfsuid - compat_sys_s390_setfsuid16
130139 32 setfsgid - compat_sys_s390_setfsgid16
131140 32 _llseek - compat_sys_llseek
132141 common getdents sys_getdents compat_sys_getdents
133142 32 _newselect - compat_sys_select
134142 64 select sys_select -
135143 common flock sys_flock sys_flock
136144 common msync sys_msync compat_sys_msync
137145 common readv sys_readv compat_sys_readv
138146 common writev sys_writev compat_sys_writev
139147 common getsid sys_getsid sys_getsid
140148 common fdatasync sys_fdatasync sys_fdatasync
141149 common _sysctl sys_sysctl compat_sys_sysctl
142150 common mlock sys_mlock compat_sys_mlock
143151 common munlock sys_munlock compat_sys_munlock
144152 common mlockall sys_mlockall sys_mlockall
145153 common munlockall sys_munlockall sys_munlockall
146154 common sched_setparam sys_sched_setparam compat_sys_sched_setparam
147155 common sched_getparam sys_sched_getparam compat_sys_sched_getparam
148156 common sched_setscheduler sys_sched_setscheduler compat_sys_sched_setscheduler
149157 common sched_getscheduler sys_sched_getscheduler sys_sched_getscheduler
150158 common sched_yield sys_sched_yield sys_sched_yield
151159 common sched_get_priority_max sys_sched_get_priority_max sys_sched_get_priority_max
152160 common sched_get_priority_min sys_sched_get_priority_min sys_sched_get_priority_min
153161 common sched_rr_get_interval sys_sched_rr_get_interval compat_sys_sched_rr_get_interval
154162 common nanosleep sys_nanosleep compat_sys_nanosleep
155163 common mremap sys_mremap compat_sys_mremap
156164 32 setresuid - compat_sys_s390_setresuid16
157165 32 getresuid - compat_sys_s390_getresuid16
158167 common query_module - -
159168 common poll sys_poll compat_sys_poll
160169 common nfsservctl - -
161170 32 setresgid - compat_sys_s390_setresgid16
162171 32 getresgid - compat_sys_s390_getresgid16
163172 common prctl sys_prctl compat_sys_prctl
164173 common rt_sigreturn sys_rt_sigreturn compat_sys_rt_sigreturn
165174 common rt_sigaction sys_rt_sigaction compat_sys_rt_sigaction
166175 common rt_sigprocmask sys_rt_sigprocmask compat_sys_rt_sigprocmask
167176 common rt_sigpending sys_rt_sigpending compat_sys_rt_sigpending
168177 common rt_sigtimedwait sys_rt_sigtimedwait compat_sys_rt_sigtimedwait
169178 common rt_sigqueueinfo sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo
170179 common rt_sigsuspend sys_rt_sigsuspend compat_sys_rt_sigsuspend
171180 common pread64 sys_pread64 compat_sys_s390_pread64
172181 common pwrite64 sys_pwrite64 compat_sys_s390_pwrite64
173182 32 chown - compat_sys_s390_chown16
174183 common getcwd sys_getcwd compat_sys_getcwd
175184 common capget sys_capget compat_sys_capget
176185 common capset sys_capset compat_sys_capset
177186 common sigaltstack sys_sigaltstack compat_sys_sigaltstack
178187 common sendfile sys_sendfile64 compat_sys_sendfile
179188 common getpmsg - -
180189 common putpmsg - -
181190 common vfork sys_vfork sys_vfork
182191 32 ugetrlimit - compat_sys_getrlimit
183191 64 getrlimit sys_getrlimit -
184192 32 mmap2 - compat_sys_s390_mmap2
185193 32 truncate64 - compat_sys_s390_truncate64
186194 32 ftruncate64 - compat_sys_s390_ftruncate64
187195 32 stat64 - compat_sys_s390_stat64
188196 32 lstat64 - compat_sys_s390_lstat64
189197 32 fstat64 - compat_sys_s390_fstat64
190198 32 lchown32 - compat_sys_lchown
191198 64 lchown sys_lchown -
192199 32 getuid32 - sys_getuid
193199 64 getuid sys_getuid -
194200 32 getgid32 - sys_getgid
195200 64 getgid sys_getgid -
196201 32 geteuid32 - sys_geteuid
197201 64 geteuid sys_geteuid -
198202 32 getegid32 - sys_getegid
199202 64 getegid sys_getegid -
200203 32 setreuid32 - sys_setreuid
201203 64 setreuid sys_setreuid -
202204 32 setregid32 - sys_setregid
203204 64 setregid sys_setregid -
204205 32 getgroups32 - compat_sys_getgroups
205205 64 getgroups sys_getgroups -
206206 32 setgroups32 - compat_sys_setgroups
207206 64 setgroups sys_setgroups -
208207 32 fchown32 - sys_fchown
209207 64 fchown sys_fchown -
210208 32 setresuid32 - sys_setresuid
211208 64 setresuid sys_setresuid -
212209 32 getresuid32 - compat_sys_getresuid
213209 64 getresuid sys_getresuid -
214210 32 setresgid32 - sys_setresgid
215210 64 setresgid sys_setresgid -
216211 32 getresgid32 - compat_sys_getresgid
217211 64 getresgid sys_getresgid -
218212 32 chown32 - compat_sys_chown
219212 64 chown sys_chown -
220213 32 setuid32 - sys_setuid
221213 64 setuid sys_setuid -
222214 32 setgid32 - sys_setgid
223214 64 setgid sys_setgid -
224215 32 setfsuid32 - sys_setfsuid
225215 64 setfsuid sys_setfsuid -
226216 32 setfsgid32 - sys_setfsgid
227216 64 setfsgid sys_setfsgid -
228217 common pivot_root sys_pivot_root compat_sys_pivot_root
229218 common mincore sys_mincore compat_sys_mincore
230219 common madvise sys_madvise compat_sys_madvise
231220 common getdents64 sys_getdents64 compat_sys_getdents64
232221 32 fcntl64 - compat_sys_fcntl64
233222 common readahead sys_readahead compat_sys_s390_readahead
234223 32 sendfile64 - compat_sys_sendfile64
235224 common setxattr sys_setxattr compat_sys_setxattr
236225 common lsetxattr sys_lsetxattr compat_sys_lsetxattr
237226 common fsetxattr sys_fsetxattr compat_sys_fsetxattr
238227 common getxattr sys_getxattr compat_sys_getxattr
239228 common lgetxattr sys_lgetxattr compat_sys_lgetxattr
240229 common fgetxattr sys_fgetxattr compat_sys_fgetxattr
241230 common listxattr sys_listxattr compat_sys_listxattr
242231 common llistxattr sys_llistxattr compat_sys_llistxattr
243232 common flistxattr sys_flistxattr compat_sys_flistxattr
244233 common removexattr sys_removexattr compat_sys_removexattr
245234 common lremovexattr sys_lremovexattr compat_sys_lremovexattr
246235 common fremovexattr sys_fremovexattr compat_sys_fremovexattr
247236 common gettid sys_gettid sys_gettid
248237 common tkill sys_tkill sys_tkill
249238 common futex sys_futex compat_sys_futex
250239 common sched_setaffinity sys_sched_setaffinity compat_sys_sched_setaffinity
251240 common sched_getaffinity sys_sched_getaffinity compat_sys_sched_getaffinity
252241 common tgkill sys_tgkill sys_tgkill
253243 common io_setup sys_io_setup compat_sys_io_setup
254244 common io_destroy sys_io_destroy compat_sys_io_destroy
255245 common io_getevents sys_io_getevents compat_sys_io_getevents
256246 common io_submit sys_io_submit compat_sys_io_submit
257247 common io_cancel sys_io_cancel compat_sys_io_cancel
258248 common exit_group sys_exit_group sys_exit_group
259249 common epoll_create sys_epoll_create sys_epoll_create
260250 common epoll_ctl sys_epoll_ctl compat_sys_epoll_ctl
261251 common epoll_wait sys_epoll_wait compat_sys_epoll_wait
262252 common set_tid_address sys_set_tid_address compat_sys_set_tid_address
263253 common fadvise64 sys_fadvise64_64 compat_sys_s390_fadvise64
264254 common timer_create sys_timer_create compat_sys_timer_create
265255 common timer_settime sys_timer_settime compat_sys_timer_settime
266256 common timer_gettime sys_timer_gettime compat_sys_timer_gettime
267257 common timer_getoverrun sys_timer_getoverrun sys_timer_getoverrun
268258 common timer_delete sys_timer_delete sys_timer_delete
269259 common clock_settime sys_clock_settime compat_sys_clock_settime
270260 common clock_gettime sys_clock_gettime compat_sys_clock_gettime
271261 common clock_getres sys_clock_getres compat_sys_clock_getres
272262 common clock_nanosleep sys_clock_nanosleep compat_sys_clock_nanosleep
273264 32 fadvise64_64 - compat_sys_s390_fadvise64_64
274265 common statfs64 sys_statfs64 compat_sys_statfs64
275266 common fstatfs64 sys_fstatfs64 compat_sys_fstatfs64
276267 common remap_file_pages sys_remap_file_pages compat_sys_remap_file_pages
277268 common mbind sys_mbind compat_sys_mbind
278269 common get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy
279270 common set_mempolicy sys_set_mempolicy compat_sys_set_mempolicy
280271 common mq_open sys_mq_open compat_sys_mq_open
281272 common mq_unlink sys_mq_unlink compat_sys_mq_unlink
282273 common mq_timedsend sys_mq_timedsend compat_sys_mq_timedsend
283274 common mq_timedreceive sys_mq_timedreceive compat_sys_mq_timedreceive
284275 common mq_notify sys_mq_notify compat_sys_mq_notify
285276 common mq_getsetattr sys_mq_getsetattr compat_sys_mq_getsetattr
286277 common kexec_load sys_kexec_load compat_sys_kexec_load
287278 common add_key sys_add_key compat_sys_add_key
288279 common request_key sys_request_key compat_sys_request_key
289280 common keyctl sys_keyctl compat_sys_keyctl
290281 common waitid sys_waitid compat_sys_waitid
291282 common ioprio_set sys_ioprio_set sys_ioprio_set
292283 common ioprio_get sys_ioprio_get sys_ioprio_get
293284 common inotify_init sys_inotify_init sys_inotify_init
294285 common inotify_add_watch sys_inotify_add_watch compat_sys_inotify_add_watch
295286 common inotify_rm_watch sys_inotify_rm_watch sys_inotify_rm_watch
296287 common migrate_pages sys_migrate_pages compat_sys_migrate_pages
297288 common openat sys_openat compat_sys_openat
298289 common mkdirat sys_mkdirat compat_sys_mkdirat
299290 common mknodat sys_mknodat compat_sys_mknodat
300291 common fchownat sys_fchownat compat_sys_fchownat
301292 common futimesat sys_futimesat compat_sys_futimesat
302293 32 fstatat64 - compat_sys_s390_fstatat64
303293 64 newfstatat sys_newfstatat -
304294 common unlinkat sys_unlinkat compat_sys_unlinkat
305295 common renameat sys_renameat compat_sys_renameat
306296 common linkat sys_linkat compat_sys_linkat
307297 common symlinkat sys_symlinkat compat_sys_symlinkat
308298 common readlinkat sys_readlinkat compat_sys_readlinkat
309299 common fchmodat sys_fchmodat compat_sys_fchmodat
310300 common faccessat sys_faccessat compat_sys_faccessat
311301 common pselect6 sys_pselect6 compat_sys_pselect6
312302 common ppoll sys_ppoll compat_sys_ppoll
313303 common unshare sys_unshare compat_sys_unshare
314304 common set_robust_list sys_set_robust_list compat_sys_set_robust_list
315305 common get_robust_list sys_get_robust_list compat_sys_get_robust_list
316306 common splice sys_splice compat_sys_splice
317307 common sync_file_range sys_sync_file_range compat_sys_s390_sync_file_range
318308 common tee sys_tee compat_sys_tee
319309 common vmsplice sys_vmsplice compat_sys_vmsplice
320310 common move_pages sys_move_pages compat_sys_move_pages
321311 common getcpu sys_getcpu compat_sys_getcpu
322312 common epoll_pwait sys_epoll_pwait compat_sys_epoll_pwait
323313 common utimes sys_utimes compat_sys_utimes
324314 common fallocate sys_fallocate compat_sys_s390_fallocate
325315 common utimensat sys_utimensat compat_sys_utimensat
326316 common signalfd sys_signalfd compat_sys_signalfd
327317 common timerfd - -
328318 common eventfd sys_eventfd sys_eventfd
329319 common timerfd_create sys_timerfd_create sys_timerfd_create
330320 common timerfd_settime sys_timerfd_settime compat_sys_timerfd_settime
331321 common timerfd_gettime sys_timerfd_gettime compat_sys_timerfd_gettime
332322 common signalfd4 sys_signalfd4 compat_sys_signalfd4
333323 common eventfd2 sys_eventfd2 sys_eventfd2
334324 common inotify_init1 sys_inotify_init1 sys_inotify_init1
335325 common pipe2 sys_pipe2 compat_sys_pipe2
336326 common dup3 sys_dup3 sys_dup3
337327 common epoll_create1 sys_epoll_create1 sys_epoll_create1
338328 common preadv sys_preadv compat_sys_preadv
339329 common pwritev sys_pwritev compat_sys_pwritev
340330 common rt_tgsigqueueinfo sys_rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo
341331 common perf_event_open sys_perf_event_open compat_sys_perf_event_open
342332 common fanotify_init sys_fanotify_init sys_fanotify_init
343333 common fanotify_mark sys_fanotify_mark compat_sys_fanotify_mark
344334 common prlimit64 sys_prlimit64 compat_sys_prlimit64
345335 common name_to_handle_at sys_name_to_handle_at compat_sys_name_to_handle_at
346336 common open_by_handle_at sys_open_by_handle_at compat_sys_open_by_handle_at
347337 common clock_adjtime sys_clock_adjtime compat_sys_clock_adjtime
348338 common syncfs sys_syncfs sys_syncfs
349339 common setns sys_setns sys_setns
350340 common process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv
351341 common process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev
352342 common s390_runtime_instr sys_s390_runtime_instr sys_s390_runtime_instr
353343 common kcmp sys_kcmp compat_sys_kcmp
354344 common finit_module sys_finit_module compat_sys_finit_module
355345 common sched_setattr sys_sched_setattr compat_sys_sched_setattr
356346 common sched_getattr sys_sched_getattr compat_sys_sched_getattr
357347 common renameat2 sys_renameat2 compat_sys_renameat2
358348 common seccomp sys_seccomp compat_sys_seccomp
359349 common getrandom sys_getrandom compat_sys_getrandom
360350 common memfd_create sys_memfd_create compat_sys_memfd_create
361351 common bpf sys_bpf compat_sys_bpf
362352 common s390_pci_mmio_write sys_s390_pci_mmio_write compat_sys_s390_pci_mmio_write
363353 common s390_pci_mmio_read sys_s390_pci_mmio_read compat_sys_s390_pci_mmio_read
364354 common execveat sys_execveat compat_sys_execveat
365355 common userfaultfd sys_userfaultfd sys_userfaultfd
366356 common membarrier sys_membarrier sys_membarrier
367357 common recvmmsg sys_recvmmsg compat_sys_recvmmsg
368358 common sendmmsg sys_sendmmsg compat_sys_sendmmsg
369359 common socket sys_socket sys_socket
370360 common socketpair sys_socketpair compat_sys_socketpair
371361 common bind sys_bind compat_sys_bind
372362 common connect sys_connect compat_sys_connect
373363 common listen sys_listen sys_listen
374364 common accept4 sys_accept4 compat_sys_accept4
375365 common getsockopt sys_getsockopt compat_sys_getsockopt
376366 common setsockopt sys_setsockopt compat_sys_setsockopt
377367 common getsockname sys_getsockname compat_sys_getsockname
378368 common getpeername sys_getpeername compat_sys_getpeername
379369 common sendto sys_sendto compat_sys_sendto
380370 common sendmsg sys_sendmsg compat_sys_sendmsg
381371 common recvfrom sys_recvfrom compat_sys_recvfrom
382372 common recvmsg sys_recvmsg compat_sys_recvmsg
383373 common shutdown sys_shutdown sys_shutdown
384374 common mlock2 sys_mlock2 compat_sys_mlock2
385375 common copy_file_range sys_copy_file_range compat_sys_copy_file_range
386376 common preadv2 sys_preadv2 compat_sys_preadv2
387377 common pwritev2 sys_pwritev2 compat_sys_pwritev2
388378 common s390_guarded_storage sys_s390_guarded_storage compat_sys_s390_guarded_storage
389379 common statx sys_statx compat_sys_statx
390380 common s390_sthyi sys_s390_sthyi compat_sys_s390_sthyi
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index c0815a37fdb5..539c3d460158 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2245,7 +2245,7 @@ static int perf_c2c__browse_cacheline(struct hist_entry *he)
2245 c2c_browser__update_nr_entries(browser); 2245 c2c_browser__update_nr_entries(browser);
2246 2246
2247 while (1) { 2247 while (1) {
2248 key = hist_browser__run(browser, "? - help"); 2248 key = hist_browser__run(browser, "? - help", true);
2249 2249
2250 switch (key) { 2250 switch (key) {
2251 case 's': 2251 case 's':
@@ -2314,7 +2314,7 @@ static int perf_c2c__hists_browse(struct hists *hists)
2314 c2c_browser__update_nr_entries(browser); 2314 c2c_browser__update_nr_entries(browser);
2315 2315
2316 while (1) { 2316 while (1) {
2317 key = hist_browser__run(browser, "? - help"); 2317 key = hist_browser__run(browser, "? - help", true);
2318 2318
2319 switch (key) { 2319 switch (key) {
2320 case 'q': 2320 case 'q':
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index bf4ca749d1ac..a217623fec2e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -881,6 +881,15 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
881 } 881 }
882 } 882 }
883 883
884 /*
885 * If we have just single event and are sending data
886 * through pipe, we need to force the ids allocation,
887 * because we synthesize event name through the pipe
888 * and need the id for that.
889 */
890 if (data->is_pipe && rec->evlist->nr_entries == 1)
891 rec->opts.sample_id = true;
892
884 if (record__open(rec) != 0) { 893 if (record__open(rec) != 0) {
885 err = -1; 894 err = -1;
886 goto out_child; 895 goto out_child;
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 42a52dcc41cd..4ad5dc649716 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -530,7 +530,8 @@ static int report__browse_hists(struct report *rep)
530 case 1: 530 case 1:
531 ret = perf_evlist__tui_browse_hists(evlist, help, NULL, 531 ret = perf_evlist__tui_browse_hists(evlist, help, NULL,
532 rep->min_percent, 532 rep->min_percent,
533 &session->header.env); 533 &session->header.env,
534 true);
534 /* 535 /*
535 * Usually "ret" is the last pressed key, and we only 536 * Usually "ret" is the last pressed key, and we only
536 * care if the key notifies us to switch data file. 537 * care if the key notifies us to switch data file.
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 98bf9d32f222..54a4c152edb3 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -917,7 +917,7 @@ static void print_metric_csv(void *ctx,
917 char buf[64], *vals, *ends; 917 char buf[64], *vals, *ends;
918 918
919 if (unit == NULL || fmt == NULL) { 919 if (unit == NULL || fmt == NULL) {
920 fprintf(out, "%s%s%s%s", csv_sep, csv_sep, csv_sep, csv_sep); 920 fprintf(out, "%s%s", csv_sep, csv_sep);
921 return; 921 return;
922 } 922 }
923 snprintf(buf, sizeof(buf), fmt, val); 923 snprintf(buf, sizeof(buf), fmt, val);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index c6ccda52117d..35ac016fcb98 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -283,8 +283,9 @@ static void perf_top__print_sym_table(struct perf_top *top)
283 283
284 printf("%-*.*s\n", win_width, win_width, graph_dotted_line); 284 printf("%-*.*s\n", win_width, win_width, graph_dotted_line);
285 285
286 if (hists->stats.nr_lost_warned != 286 if (!top->record_opts.overwrite &&
287 hists->stats.nr_events[PERF_RECORD_LOST]) { 287 (hists->stats.nr_lost_warned !=
288 hists->stats.nr_events[PERF_RECORD_LOST])) {
288 hists->stats.nr_lost_warned = 289 hists->stats.nr_lost_warned =
289 hists->stats.nr_events[PERF_RECORD_LOST]; 290 hists->stats.nr_events[PERF_RECORD_LOST];
290 color_fprintf(stdout, PERF_COLOR_RED, 291 color_fprintf(stdout, PERF_COLOR_RED,
@@ -611,7 +612,8 @@ static void *display_thread_tui(void *arg)
611 612
612 perf_evlist__tui_browse_hists(top->evlist, help, &hbt, 613 perf_evlist__tui_browse_hists(top->evlist, help, &hbt,
613 top->min_percent, 614 top->min_percent,
614 &top->session->header.env); 615 &top->session->header.env,
616 !top->record_opts.overwrite);
615 617
616 done = 1; 618 done = 1;
617 return NULL; 619 return NULL;
@@ -807,15 +809,23 @@ static void perf_event__process_sample(struct perf_tool *tool,
807 809
808static void perf_top__mmap_read_idx(struct perf_top *top, int idx) 810static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
809{ 811{
812 struct record_opts *opts = &top->record_opts;
813 struct perf_evlist *evlist = top->evlist;
810 struct perf_sample sample; 814 struct perf_sample sample;
811 struct perf_evsel *evsel; 815 struct perf_evsel *evsel;
816 struct perf_mmap *md;
812 struct perf_session *session = top->session; 817 struct perf_session *session = top->session;
813 union perf_event *event; 818 union perf_event *event;
814 struct machine *machine; 819 struct machine *machine;
820 u64 end, start;
815 int ret; 821 int ret;
816 822
817 while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) { 823 md = opts->overwrite ? &evlist->overwrite_mmap[idx] : &evlist->mmap[idx];
818 ret = perf_evlist__parse_sample(top->evlist, event, &sample); 824 if (perf_mmap__read_init(md, opts->overwrite, &start, &end) < 0)
825 return;
826
827 while ((event = perf_mmap__read_event(md, opts->overwrite, &start, end)) != NULL) {
828 ret = perf_evlist__parse_sample(evlist, event, &sample);
819 if (ret) { 829 if (ret) {
820 pr_err("Can't parse sample, err = %d\n", ret); 830 pr_err("Can't parse sample, err = %d\n", ret);
821 goto next_event; 831 goto next_event;
@@ -869,16 +879,120 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
869 } else 879 } else
870 ++session->evlist->stats.nr_unknown_events; 880 ++session->evlist->stats.nr_unknown_events;
871next_event: 881next_event:
872 perf_evlist__mmap_consume(top->evlist, idx); 882 perf_mmap__consume(md, opts->overwrite);
873 } 883 }
884
885 perf_mmap__read_done(md);
874} 886}
875 887
876static void perf_top__mmap_read(struct perf_top *top) 888static void perf_top__mmap_read(struct perf_top *top)
877{ 889{
890 bool overwrite = top->record_opts.overwrite;
891 struct perf_evlist *evlist = top->evlist;
892 unsigned long long start, end;
878 int i; 893 int i;
879 894
895 start = rdclock();
896 if (overwrite)
897 perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_DATA_PENDING);
898
880 for (i = 0; i < top->evlist->nr_mmaps; i++) 899 for (i = 0; i < top->evlist->nr_mmaps; i++)
881 perf_top__mmap_read_idx(top, i); 900 perf_top__mmap_read_idx(top, i);
901
902 if (overwrite) {
903 perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_EMPTY);
904 perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_RUNNING);
905 }
906 end = rdclock();
907
908 if ((end - start) > (unsigned long long)top->delay_secs * NSEC_PER_SEC)
909 ui__warning("Too slow to read ring buffer.\n"
910 "Please try increasing the period (-c) or\n"
911 "decreasing the freq (-F) or\n"
912 "limiting the number of CPUs (-C)\n");
913}
914
915/*
916 * Check per-event overwrite term.
917 * perf top should support consistent term for all events.
918 * - All events don't have per-event term
919 * E.g. "cpu/cpu-cycles/,cpu/instructions/"
920 * Nothing change, return 0.
921 * - All events have same per-event term
922 * E.g. "cpu/cpu-cycles,no-overwrite/,cpu/instructions,no-overwrite/
923 * Using the per-event setting to replace the opts->overwrite if
924 * they are different, then return 0.
925 * - Events have different per-event term
926 * E.g. "cpu/cpu-cycles,overwrite/,cpu/instructions,no-overwrite/"
927 * Return -1
928 * - Some of the event set per-event term, but some not.
929 * E.g. "cpu/cpu-cycles/,cpu/instructions,no-overwrite/"
930 * Return -1
931 */
932static int perf_top__overwrite_check(struct perf_top *top)
933{
934 struct record_opts *opts = &top->record_opts;
935 struct perf_evlist *evlist = top->evlist;
936 struct perf_evsel_config_term *term;
937 struct list_head *config_terms;
938 struct perf_evsel *evsel;
939 int set, overwrite = -1;
940
941 evlist__for_each_entry(evlist, evsel) {
942 set = -1;
943 config_terms = &evsel->config_terms;
944 list_for_each_entry(term, config_terms, list) {
945 if (term->type == PERF_EVSEL__CONFIG_TERM_OVERWRITE)
946 set = term->val.overwrite ? 1 : 0;
947 }
948
949 /* no term for current and previous event (likely) */
950 if ((overwrite < 0) && (set < 0))
951 continue;
952
953 /* has term for both current and previous event, compare */
954 if ((overwrite >= 0) && (set >= 0) && (overwrite != set))
955 return -1;
956
957 /* no term for current event but has term for previous one */
958 if ((overwrite >= 0) && (set < 0))
959 return -1;
960
961 /* has term for current event */
962 if ((overwrite < 0) && (set >= 0)) {
963 /* if it's first event, set overwrite */
964 if (evsel == perf_evlist__first(evlist))
965 overwrite = set;
966 else
967 return -1;
968 }
969 }
970
971 if ((overwrite >= 0) && (opts->overwrite != overwrite))
972 opts->overwrite = overwrite;
973
974 return 0;
975}
976
977static int perf_top_overwrite_fallback(struct perf_top *top,
978 struct perf_evsel *evsel)
979{
980 struct record_opts *opts = &top->record_opts;
981 struct perf_evlist *evlist = top->evlist;
982 struct perf_evsel *counter;
983
984 if (!opts->overwrite)
985 return 0;
986
987 /* only fall back when first event fails */
988 if (evsel != perf_evlist__first(evlist))
989 return 0;
990
991 evlist__for_each_entry(evlist, counter)
992 counter->attr.write_backward = false;
993 opts->overwrite = false;
994 pr_debug2("fall back to non-overwrite mode\n");
995 return 1;
882} 996}
883 997
884static int perf_top__start_counters(struct perf_top *top) 998static int perf_top__start_counters(struct perf_top *top)
@@ -888,12 +1002,33 @@ static int perf_top__start_counters(struct perf_top *top)
888 struct perf_evlist *evlist = top->evlist; 1002 struct perf_evlist *evlist = top->evlist;
889 struct record_opts *opts = &top->record_opts; 1003 struct record_opts *opts = &top->record_opts;
890 1004
1005 if (perf_top__overwrite_check(top)) {
1006 ui__error("perf top only support consistent per-event "
1007 "overwrite setting for all events\n");
1008 goto out_err;
1009 }
1010
891 perf_evlist__config(evlist, opts, &callchain_param); 1011 perf_evlist__config(evlist, opts, &callchain_param);
892 1012
893 evlist__for_each_entry(evlist, counter) { 1013 evlist__for_each_entry(evlist, counter) {
894try_again: 1014try_again:
895 if (perf_evsel__open(counter, top->evlist->cpus, 1015 if (perf_evsel__open(counter, top->evlist->cpus,
896 top->evlist->threads) < 0) { 1016 top->evlist->threads) < 0) {
1017
1018 /*
1019 * Specially handle overwrite fall back.
1020 * Because perf top is the only tool which has
1021 * overwrite mode by default, support
1022 * both overwrite and non-overwrite mode, and
1023 * require consistent mode for all events.
1024 *
1025 * May move it to generic code with more tools
1026 * have similar attribute.
1027 */
1028 if (perf_missing_features.write_backward &&
1029 perf_top_overwrite_fallback(top, counter))
1030 goto try_again;
1031
897 if (perf_evsel__fallback(counter, errno, msg, sizeof(msg))) { 1032 if (perf_evsel__fallback(counter, errno, msg, sizeof(msg))) {
898 if (verbose > 0) 1033 if (verbose > 0)
899 ui__warning("%s\n", msg); 1034 ui__warning("%s\n", msg);
@@ -1033,7 +1168,7 @@ static int __cmd_top(struct perf_top *top)
1033 1168
1034 perf_top__mmap_read(top); 1169 perf_top__mmap_read(top);
1035 1170
1036 if (hits == top->samples) 1171 if (opts->overwrite || (hits == top->samples))
1037 ret = perf_evlist__poll(top->evlist, 100); 1172 ret = perf_evlist__poll(top->evlist, 100);
1038 1173
1039 if (resize) { 1174 if (resize) {
@@ -1127,6 +1262,7 @@ int cmd_top(int argc, const char **argv)
1127 .uses_mmap = true, 1262 .uses_mmap = true,
1128 }, 1263 },
1129 .proc_map_timeout = 500, 1264 .proc_map_timeout = 500,
1265 .overwrite = 1,
1130 }, 1266 },
1131 .max_stack = sysctl_perf_event_max_stack, 1267 .max_stack = sysctl_perf_event_max_stack,
1132 .sym_pcnt_filter = 5, 1268 .sym_pcnt_filter = 5,
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index 51abdb0a4047..790ec25919a0 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -33,7 +33,6 @@ arch/s390/include/uapi/asm/kvm.h
33arch/s390/include/uapi/asm/kvm_perf.h 33arch/s390/include/uapi/asm/kvm_perf.h
34arch/s390/include/uapi/asm/ptrace.h 34arch/s390/include/uapi/asm/ptrace.h
35arch/s390/include/uapi/asm/sie.h 35arch/s390/include/uapi/asm/sie.h
36arch/s390/include/uapi/asm/unistd.h
37arch/arm/include/uapi/asm/kvm.h 36arch/arm/include/uapi/asm/kvm.h
38arch/arm64/include/uapi/asm/kvm.h 37arch/arm64/include/uapi/asm/kvm.h
39arch/alpha/include/uapi/asm/errno.h 38arch/alpha/include/uapi/asm/errno.h
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index cfe46236a5e5..57b9b342d533 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -61,6 +61,7 @@ struct record_opts {
61 bool tail_synthesize; 61 bool tail_synthesize;
62 bool overwrite; 62 bool overwrite;
63 bool ignore_missing_thread; 63 bool ignore_missing_thread;
64 bool sample_id;
64 unsigned int freq; 65 unsigned int freq;
65 unsigned int mmap_pages; 66 unsigned int mmap_pages;
66 unsigned int auxtrace_mmap_pages; 67 unsigned int auxtrace_mmap_pages;
diff --git a/tools/perf/pmu-events/arch/arm64/cortex-a53/branch.json b/tools/perf/pmu-events/arch/arm64/cortex-a53/branch.json
new file mode 100644
index 000000000000..3b6208763e50
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/cortex-a53/branch.json
@@ -0,0 +1,27 @@
1[
2 {,
3 "EventCode": "0x7A",
4 "EventName": "BR_INDIRECT_SPEC",
5 "BriefDescription": "Branch speculatively executed - Indirect branch"
6 },
7 {,
8 "EventCode": "0xC9",
9 "EventName": "BR_COND",
10 "BriefDescription": "Conditional branch executed"
11 },
12 {,
13 "EventCode": "0xCA",
14 "EventName": "BR_INDIRECT_MISPRED",
15 "BriefDescription": "Indirect branch mispredicted"
16 },
17 {,
18 "EventCode": "0xCB",
19 "EventName": "BR_INDIRECT_MISPRED_ADDR",
20 "BriefDescription": "Indirect branch mispredicted because of address miscompare"
21 },
22 {,
23 "EventCode": "0xCC",
24 "EventName": "BR_COND_MISPRED",
25 "BriefDescription": "Conditional branch mispredicted"
26 }
27]
diff --git a/tools/perf/pmu-events/arch/arm64/cortex-a53/bus.json b/tools/perf/pmu-events/arch/arm64/cortex-a53/bus.json
new file mode 100644
index 000000000000..480d9f7460ab
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/cortex-a53/bus.json
@@ -0,0 +1,22 @@
1[
2 {,
3 "EventCode": "0x60",
4 "EventName": "BUS_ACCESS_LD",
5 "BriefDescription": "Bus access - Read"
6 },
7 {,
8 "EventCode": "0x61",
9 "EventName": "BUS_ACCESS_ST",
10 "BriefDescription": "Bus access - Write"
11 },
12 {,
13 "EventCode": "0xC0",
14 "EventName": "EXT_MEM_REQ",
15 "BriefDescription": "External memory request"
16 },
17 {,
18 "EventCode": "0xC1",
19 "EventName": "EXT_MEM_REQ_NC",
20 "BriefDescription": "Non-cacheable external memory request"
21 }
22]
diff --git a/tools/perf/pmu-events/arch/arm64/cortex-a53/cache.json b/tools/perf/pmu-events/arch/arm64/cortex-a53/cache.json
new file mode 100644
index 000000000000..11baad6344b9
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/cortex-a53/cache.json
@@ -0,0 +1,27 @@
1[
2 {,
3 "EventCode": "0xC2",
4 "EventName": "PREFETCH_LINEFILL",
5 "BriefDescription": "Linefill because of prefetch"
6 },
7 {,
8 "EventCode": "0xC3",
9 "EventName": "PREFETCH_LINEFILL_DROP",
10 "BriefDescription": "Instruction Cache Throttle occurred"
11 },
12 {,
13 "EventCode": "0xC4",
14 "EventName": "READ_ALLOC_ENTER",
15 "BriefDescription": "Entering read allocate mode"
16 },
17 {,
18 "EventCode": "0xC5",
19 "EventName": "READ_ALLOC",
20 "BriefDescription": "Read allocate mode"
21 },
22 {,
23 "EventCode": "0xC8",
24 "EventName": "EXT_SNOOP",
25 "BriefDescription": "SCU Snooped data from another CPU for this CPU"
26 }
27]
diff --git a/tools/perf/pmu-events/arch/arm64/cortex-a53/memory.json b/tools/perf/pmu-events/arch/arm64/cortex-a53/memory.json
new file mode 100644
index 000000000000..480d9f7460ab
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/cortex-a53/memory.json
@@ -0,0 +1,22 @@
1[
2 {,
3 "EventCode": "0x60",
4 "EventName": "BUS_ACCESS_LD",
5 "BriefDescription": "Bus access - Read"
6 },
7 {,
8 "EventCode": "0x61",
9 "EventName": "BUS_ACCESS_ST",
10 "BriefDescription": "Bus access - Write"
11 },
12 {,
13 "EventCode": "0xC0",
14 "EventName": "EXT_MEM_REQ",
15 "BriefDescription": "External memory request"
16 },
17 {,
18 "EventCode": "0xC1",
19 "EventName": "EXT_MEM_REQ_NC",
20 "BriefDescription": "Non-cacheable external memory request"
21 }
22]
diff --git a/tools/perf/pmu-events/arch/arm64/cortex-a53/other.json b/tools/perf/pmu-events/arch/arm64/cortex-a53/other.json
new file mode 100644
index 000000000000..73a22402d003
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/cortex-a53/other.json
@@ -0,0 +1,32 @@
1[
2 {,
3 "EventCode": "0x86",
4 "EventName": "EXC_IRQ",
5 "BriefDescription": "Exception taken, IRQ"
6 },
7 {,
8 "EventCode": "0x87",
9 "EventName": "EXC_FIQ",
10 "BriefDescription": "Exception taken, FIQ"
11 },
12 {,
13 "EventCode": "0xC6",
14 "EventName": "PRE_DECODE_ERR",
15 "BriefDescription": "Pre-decode error"
16 },
17 {,
18 "EventCode": "0xD0",
19 "EventName": "L1I_CACHE_ERR",
20 "BriefDescription": "L1 Instruction Cache (data or tag) memory error"
21 },
22 {,
23 "EventCode": "0xD1",
24 "EventName": "L1D_CACHE_ERR",
25 "BriefDescription": "L1 Data Cache (data, tag or dirty) memory error, correctable or non-correctable"
26 },
27 {,
28 "EventCode": "0xD2",
29 "EventName": "TLB_ERR",
30 "BriefDescription": "TLB memory error"
31 }
32]
diff --git a/tools/perf/pmu-events/arch/arm64/cortex-a53/pipeline.json b/tools/perf/pmu-events/arch/arm64/cortex-a53/pipeline.json
new file mode 100644
index 000000000000..3149fb90555a
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/cortex-a53/pipeline.json
@@ -0,0 +1,52 @@
1[
2 {,
3 "EventCode": "0xC7",
4 "EventName": "STALL_SB_FULL",
5 "BriefDescription": "Data Write operation that stalls the pipeline because the store buffer is full"
6 },
7 {,
8 "EventCode": "0xE0",
9 "EventName": "OTHER_IQ_DEP_STALL",
10 "BriefDescription": "Cycles that the DPU IQ is empty and that is not because of a recent micro-TLB miss, instruction cache miss or pre-decode error"
11 },
12 {,
13 "EventCode": "0xE1",
14 "EventName": "IC_DEP_STALL",
15 "BriefDescription": "Cycles the DPU IQ is empty and there is an instruction cache miss being processed"
16 },
17 {,
18 "EventCode": "0xE2",
19 "EventName": "IUTLB_DEP_STALL",
20 "BriefDescription": "Cycles the DPU IQ is empty and there is an instruction micro-TLB miss being processed"
21 },
22 {,
23 "EventCode": "0xE3",
24 "EventName": "DECODE_DEP_STALL",
25 "BriefDescription": "Cycles the DPU IQ is empty and there is a pre-decode error being processed"
26 },
27 {,
28 "EventCode": "0xE4",
29 "EventName": "OTHER_INTERLOCK_STALL",
30 "BriefDescription": "Cycles there is an interlock other than Advanced SIMD/Floating-point instructions or load/store instruction"
31 },
32 {,
33 "EventCode": "0xE5",
34 "EventName": "AGU_DEP_STALL",
35 "BriefDescription": "Cycles there is an interlock for a load/store instruction waiting for data to calculate the address in the AGU"
36 },
37 {,
38 "EventCode": "0xE6",
39 "EventName": "SIMD_DEP_STALL",
40 "BriefDescription": "Cycles there is an interlock for an Advanced SIMD/Floating-point operation."
41 },
42 {,
43 "EventCode": "0xE7",
44 "EventName": "LD_DEP_STALL",
45 "BriefDescription": "Cycles there is a stall in the Wr stage because of a load miss"
46 },
47 {,
48 "EventCode": "0xE8",
49 "EventName": "ST_DEP_STALL",
50 "BriefDescription": "Cycles there is a stall in the Wr stage because of a store"
51 }
52]
diff --git a/tools/perf/pmu-events/arch/arm64/mapfile.csv b/tools/perf/pmu-events/arch/arm64/mapfile.csv
index 219d6756134e..e61c9ca6cf9e 100644
--- a/tools/perf/pmu-events/arch/arm64/mapfile.csv
+++ b/tools/perf/pmu-events/arch/arm64/mapfile.csv
@@ -13,3 +13,4 @@
13# 13#
14#Family-model,Version,Filename,EventType 14#Family-model,Version,Filename,EventType
150x00000000420f5160,v1,cavium,core 150x00000000420f5160,v1,cavium,core
160x00000000410fd03[[:xdigit:]],v1,cortex-a53,core
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index 4035d43523c3..e0b1b414d466 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -31,10 +31,12 @@ static int count_samples(struct perf_evlist *evlist, int *sample_count,
31 int i; 31 int i;
32 32
33 for (i = 0; i < evlist->nr_mmaps; i++) { 33 for (i = 0; i < evlist->nr_mmaps; i++) {
34 struct perf_mmap *map = &evlist->overwrite_mmap[i];
34 union perf_event *event; 35 union perf_event *event;
36 u64 start, end;
35 37
36 perf_mmap__read_catchup(&evlist->overwrite_mmap[i]); 38 perf_mmap__read_init(map, true, &start, &end);
37 while ((event = perf_mmap__read_backward(&evlist->overwrite_mmap[i])) != NULL) { 39 while ((event = perf_mmap__read_event(map, true, &start, end)) != NULL) {
38 const u32 type = event->header.type; 40 const u32 type = event->header.type;
39 41
40 switch (type) { 42 switch (type) {
@@ -49,6 +51,7 @@ static int count_samples(struct perf_evlist *evlist, int *sample_count,
49 return TEST_FAIL; 51 return TEST_FAIL;
50 } 52 }
51 } 53 }
54 perf_mmap__read_done(map);
52 } 55 }
53 return TEST_OK; 56 return TEST_OK;
54} 57}
diff --git a/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh b/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh
index 8b3da21a08f1..c446c894b297 100755
--- a/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh
+++ b/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh
@@ -22,10 +22,23 @@ trace_libc_inet_pton_backtrace() {
22 expected[4]="rtt min.*" 22 expected[4]="rtt min.*"
23 expected[5]="[0-9]+\.[0-9]+[[:space:]]+probe_libc:inet_pton:\([[:xdigit:]]+\)" 23 expected[5]="[0-9]+\.[0-9]+[[:space:]]+probe_libc:inet_pton:\([[:xdigit:]]+\)"
24 expected[6]=".*inet_pton[[:space:]]\($libc\)$" 24 expected[6]=".*inet_pton[[:space:]]\($libc\)$"
25 expected[7]="getaddrinfo[[:space:]]\($libc\)$" 25 case "$(uname -m)" in
26 expected[8]=".*\(.*/bin/ping.*\)$" 26 s390x)
27 27 eventattr='call-graph=dwarf'
28 perf trace --no-syscalls -e probe_libc:inet_pton/max-stack=3/ ping -6 -c 1 ::1 2>&1 | grep -v ^$ | while read line ; do 28 expected[7]="gaih_inet[[:space:]]\(inlined\)$"
29 expected[8]="__GI_getaddrinfo[[:space:]]\(inlined\)$"
30 expected[9]="main[[:space:]]\(.*/bin/ping.*\)$"
31 expected[10]="__libc_start_main[[:space:]]\($libc\)$"
32 expected[11]="_start[[:space:]]\(.*/bin/ping.*\)$"
33 ;;
34 *)
35 eventattr='max-stack=3'
36 expected[7]="getaddrinfo[[:space:]]\($libc\)$"
37 expected[8]=".*\(.*/bin/ping.*\)$"
38 ;;
39 esac
40
41 perf trace --no-syscalls -e probe_libc:inet_pton/$eventattr/ ping -6 -c 1 ::1 2>&1 | grep -v ^$ | while read line ; do
29 echo $line 42 echo $line
30 echo "$line" | egrep -q "${expected[$idx]}" 43 echo "$line" | egrep -q "${expected[$idx]}"
31 if [ $? -ne 0 ] ; then 44 if [ $? -ne 0 ] ; then
@@ -33,7 +46,7 @@ trace_libc_inet_pton_backtrace() {
33 exit 1 46 exit 1
34 fi 47 fi
35 let idx+=1 48 let idx+=1
36 [ $idx -eq 9 ] && break 49 [ -z "${expected[$idx]}" ] && break
37 done 50 done
38} 51}
39 52
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 286427975112..fbf927cf775d 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -327,7 +327,32 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
327 if (!disasm_line__is_valid_jump(cursor, sym)) 327 if (!disasm_line__is_valid_jump(cursor, sym))
328 return; 328 return;
329 329
330 /*
331 * This first was seen with a gcc function, _cpp_lex_token, that
332 * has the usual jumps:
333 *
334 * │1159e6c: ↓ jne 115aa32 <_cpp_lex_token@@Base+0xf92>
335 *
336 * I.e. jumps to a label inside that function (_cpp_lex_token), and
337 * those works, but also this kind:
338 *
339 * │1159e8b: ↓ jne c469be <cpp_named_operator2name@@Base+0xa72>
340 *
341 * I.e. jumps to another function, outside _cpp_lex_token, which
342 * are not being correctly handled generating as a side effect references
343 * to ab->offset[] entries that are set to NULL, so to make this code
344 * more robust, check that here.
345 *
346 * A proper fix for will be put in place, looking at the function
347 * name right after the '<' token and probably treating this like a
348 * 'call' instruction.
349 */
330 target = ab->offsets[cursor->ops.target.offset]; 350 target = ab->offsets[cursor->ops.target.offset];
351 if (target == NULL) {
352 ui_helpline__printf("WARN: jump target inconsistency, press 'o', ab->offsets[%#x] = NULL\n",
353 cursor->ops.target.offset);
354 return;
355 }
331 356
332 bcursor = browser_line(&cursor->al); 357 bcursor = browser_line(&cursor->al);
333 btarget = browser_line(target); 358 btarget = browser_line(target);
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 68146f4620a5..6495ee55d9c3 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -608,7 +608,8 @@ static int hist_browser__title(struct hist_browser *browser, char *bf, size_t si
608 return browser->title ? browser->title(browser, bf, size) : 0; 608 return browser->title ? browser->title(browser, bf, size) : 0;
609} 609}
610 610
611int hist_browser__run(struct hist_browser *browser, const char *help) 611int hist_browser__run(struct hist_browser *browser, const char *help,
612 bool warn_lost_event)
612{ 613{
613 int key; 614 int key;
614 char title[160]; 615 char title[160];
@@ -638,8 +639,9 @@ int hist_browser__run(struct hist_browser *browser, const char *help)
638 nr_entries = hist_browser__nr_entries(browser); 639 nr_entries = hist_browser__nr_entries(browser);
639 ui_browser__update_nr_entries(&browser->b, nr_entries); 640 ui_browser__update_nr_entries(&browser->b, nr_entries);
640 641
641 if (browser->hists->stats.nr_lost_warned != 642 if (warn_lost_event &&
642 browser->hists->stats.nr_events[PERF_RECORD_LOST]) { 643 (browser->hists->stats.nr_lost_warned !=
644 browser->hists->stats.nr_events[PERF_RECORD_LOST])) {
643 browser->hists->stats.nr_lost_warned = 645 browser->hists->stats.nr_lost_warned =
644 browser->hists->stats.nr_events[PERF_RECORD_LOST]; 646 browser->hists->stats.nr_events[PERF_RECORD_LOST];
645 ui_browser__warn_lost_events(&browser->b); 647 ui_browser__warn_lost_events(&browser->b);
@@ -2763,7 +2765,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
2763 bool left_exits, 2765 bool left_exits,
2764 struct hist_browser_timer *hbt, 2766 struct hist_browser_timer *hbt,
2765 float min_pcnt, 2767 float min_pcnt,
2766 struct perf_env *env) 2768 struct perf_env *env,
2769 bool warn_lost_event)
2767{ 2770{
2768 struct hists *hists = evsel__hists(evsel); 2771 struct hists *hists = evsel__hists(evsel);
2769 struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env); 2772 struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env);
@@ -2844,7 +2847,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
2844 2847
2845 nr_options = 0; 2848 nr_options = 0;
2846 2849
2847 key = hist_browser__run(browser, helpline); 2850 key = hist_browser__run(browser, helpline,
2851 warn_lost_event);
2848 2852
2849 if (browser->he_selection != NULL) { 2853 if (browser->he_selection != NULL) {
2850 thread = hist_browser__selected_thread(browser); 2854 thread = hist_browser__selected_thread(browser);
@@ -3184,7 +3188,8 @@ static void perf_evsel_menu__write(struct ui_browser *browser,
3184 3188
3185static int perf_evsel_menu__run(struct perf_evsel_menu *menu, 3189static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
3186 int nr_events, const char *help, 3190 int nr_events, const char *help,
3187 struct hist_browser_timer *hbt) 3191 struct hist_browser_timer *hbt,
3192 bool warn_lost_event)
3188{ 3193{
3189 struct perf_evlist *evlist = menu->b.priv; 3194 struct perf_evlist *evlist = menu->b.priv;
3190 struct perf_evsel *pos; 3195 struct perf_evsel *pos;
@@ -3203,7 +3208,9 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
3203 case K_TIMER: 3208 case K_TIMER:
3204 hbt->timer(hbt->arg); 3209 hbt->timer(hbt->arg);
3205 3210
3206 if (!menu->lost_events_warned && menu->lost_events) { 3211 if (!menu->lost_events_warned &&
3212 menu->lost_events &&
3213 warn_lost_event) {
3207 ui_browser__warn_lost_events(&menu->b); 3214 ui_browser__warn_lost_events(&menu->b);
3208 menu->lost_events_warned = true; 3215 menu->lost_events_warned = true;
3209 } 3216 }
@@ -3224,7 +3231,8 @@ browse_hists:
3224 key = perf_evsel__hists_browse(pos, nr_events, help, 3231 key = perf_evsel__hists_browse(pos, nr_events, help,
3225 true, hbt, 3232 true, hbt,
3226 menu->min_pcnt, 3233 menu->min_pcnt,
3227 menu->env); 3234 menu->env,
3235 warn_lost_event);
3228 ui_browser__show_title(&menu->b, title); 3236 ui_browser__show_title(&menu->b, title);
3229 switch (key) { 3237 switch (key) {
3230 case K_TAB: 3238 case K_TAB:
@@ -3282,7 +3290,8 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
3282 int nr_entries, const char *help, 3290 int nr_entries, const char *help,
3283 struct hist_browser_timer *hbt, 3291 struct hist_browser_timer *hbt,
3284 float min_pcnt, 3292 float min_pcnt,
3285 struct perf_env *env) 3293 struct perf_env *env,
3294 bool warn_lost_event)
3286{ 3295{
3287 struct perf_evsel *pos; 3296 struct perf_evsel *pos;
3288 struct perf_evsel_menu menu = { 3297 struct perf_evsel_menu menu = {
@@ -3309,13 +3318,15 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
3309 menu.b.width = line_len; 3318 menu.b.width = line_len;
3310 } 3319 }
3311 3320
3312 return perf_evsel_menu__run(&menu, nr_entries, help, hbt); 3321 return perf_evsel_menu__run(&menu, nr_entries, help,
3322 hbt, warn_lost_event);
3313} 3323}
3314 3324
3315int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, 3325int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
3316 struct hist_browser_timer *hbt, 3326 struct hist_browser_timer *hbt,
3317 float min_pcnt, 3327 float min_pcnt,
3318 struct perf_env *env) 3328 struct perf_env *env,
3329 bool warn_lost_event)
3319{ 3330{
3320 int nr_entries = evlist->nr_entries; 3331 int nr_entries = evlist->nr_entries;
3321 3332
@@ -3325,7 +3336,7 @@ single_entry:
3325 3336
3326 return perf_evsel__hists_browse(first, nr_entries, help, 3337 return perf_evsel__hists_browse(first, nr_entries, help,
3327 false, hbt, min_pcnt, 3338 false, hbt, min_pcnt,
3328 env); 3339 env, warn_lost_event);
3329 } 3340 }
3330 3341
3331 if (symbol_conf.event_group) { 3342 if (symbol_conf.event_group) {
@@ -3342,5 +3353,6 @@ single_entry:
3342 } 3353 }
3343 3354
3344 return __perf_evlist__tui_browse_hists(evlist, nr_entries, help, 3355 return __perf_evlist__tui_browse_hists(evlist, nr_entries, help,
3345 hbt, min_pcnt, env); 3356 hbt, min_pcnt, env,
3357 warn_lost_event);
3346} 3358}
diff --git a/tools/perf/ui/browsers/hists.h b/tools/perf/ui/browsers/hists.h
index ba431777f559..9428bee076f2 100644
--- a/tools/perf/ui/browsers/hists.h
+++ b/tools/perf/ui/browsers/hists.h
@@ -28,7 +28,8 @@ struct hist_browser {
28 28
29struct hist_browser *hist_browser__new(struct hists *hists); 29struct hist_browser *hist_browser__new(struct hists *hists);
30void hist_browser__delete(struct hist_browser *browser); 30void hist_browser__delete(struct hist_browser *browser);
31int hist_browser__run(struct hist_browser *browser, const char *help); 31int hist_browser__run(struct hist_browser *browser, const char *help,
32 bool warn_lost_event);
32void hist_browser__init(struct hist_browser *browser, 33void hist_browser__init(struct hist_browser *browser,
33 struct hists *hists); 34 struct hists *hists);
34#endif /* _PERF_UI_BROWSER_HISTS_H_ */ 35#endif /* _PERF_UI_BROWSER_HISTS_H_ */
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 9faf3b5367db..6470ea2aa25e 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -60,6 +60,12 @@
60#include "sane_ctype.h" 60#include "sane_ctype.h"
61#include "symbol/kallsyms.h" 61#include "symbol/kallsyms.h"
62 62
63static bool auxtrace__dont_decode(struct perf_session *session)
64{
65 return !session->itrace_synth_opts ||
66 session->itrace_synth_opts->dont_decode;
67}
68
63int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, 69int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
64 struct auxtrace_mmap_params *mp, 70 struct auxtrace_mmap_params *mp,
65 void *userpg, int fd) 71 void *userpg, int fd)
@@ -762,6 +768,9 @@ int auxtrace_queues__process_index(struct auxtrace_queues *queues,
762 size_t i; 768 size_t i;
763 int err; 769 int err;
764 770
771 if (auxtrace__dont_decode(session))
772 return 0;
773
765 list_for_each_entry(auxtrace_index, &session->auxtrace_index, list) { 774 list_for_each_entry(auxtrace_index, &session->auxtrace_index, list) {
766 for (i = 0; i < auxtrace_index->nr; i++) { 775 for (i = 0; i < auxtrace_index->nr; i++) {
767 ent = &auxtrace_index->entries[i]; 776 ent = &auxtrace_index->entries[i];
@@ -892,12 +901,6 @@ out_free:
892 return err; 901 return err;
893} 902}
894 903
895static bool auxtrace__dont_decode(struct perf_session *session)
896{
897 return !session->itrace_synth_opts ||
898 session->itrace_synth_opts->dont_decode;
899}
900
901int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused, 904int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused,
902 union perf_event *event, 905 union perf_event *event,
903 struct perf_session *session) 906 struct perf_session *session)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index ac35cd214feb..e5fc14e53c05 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -715,28 +715,11 @@ union perf_event *perf_evlist__mmap_read_forward(struct perf_evlist *evlist, int
715 return perf_mmap__read_forward(md); 715 return perf_mmap__read_forward(md);
716} 716}
717 717
718union perf_event *perf_evlist__mmap_read_backward(struct perf_evlist *evlist, int idx)
719{
720 struct perf_mmap *md = &evlist->mmap[idx];
721
722 /*
723 * No need to check messup for backward ring buffer:
724 * We can always read arbitrary long data from a backward
725 * ring buffer unless we forget to pause it before reading.
726 */
727 return perf_mmap__read_backward(md);
728}
729
730union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx) 718union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
731{ 719{
732 return perf_evlist__mmap_read_forward(evlist, idx); 720 return perf_evlist__mmap_read_forward(evlist, idx);
733} 721}
734 722
735void perf_evlist__mmap_read_catchup(struct perf_evlist *evlist, int idx)
736{
737 perf_mmap__read_catchup(&evlist->mmap[idx]);
738}
739
740void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx) 723void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx)
741{ 724{
742 perf_mmap__consume(&evlist->mmap[idx], false); 725 perf_mmap__consume(&evlist->mmap[idx], false);
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 75f8e0ad5d76..336b838e6957 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -133,10 +133,6 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx);
133 133
134union perf_event *perf_evlist__mmap_read_forward(struct perf_evlist *evlist, 134union perf_event *perf_evlist__mmap_read_forward(struct perf_evlist *evlist,
135 int idx); 135 int idx);
136union perf_event *perf_evlist__mmap_read_backward(struct perf_evlist *evlist,
137 int idx);
138void perf_evlist__mmap_read_catchup(struct perf_evlist *evlist, int idx);
139
140void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx); 136void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx);
141 137
142int perf_evlist__open(struct perf_evlist *evlist); 138int perf_evlist__open(struct perf_evlist *evlist);
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ff359c9ece2e..ef351688b797 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -41,17 +41,7 @@
41 41
42#include "sane_ctype.h" 42#include "sane_ctype.h"
43 43
44static struct { 44struct perf_missing_features perf_missing_features;
45 bool sample_id_all;
46 bool exclude_guest;
47 bool mmap2;
48 bool cloexec;
49 bool clockid;
50 bool clockid_wrong;
51 bool lbr_flags;
52 bool write_backward;
53 bool group_read;
54} perf_missing_features;
55 45
56static clockid_t clockid; 46static clockid_t clockid;
57 47
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 846e41644525..a7487c6d1866 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -149,6 +149,20 @@ union u64_swap {
149 u32 val32[2]; 149 u32 val32[2];
150}; 150};
151 151
152struct perf_missing_features {
153 bool sample_id_all;
154 bool exclude_guest;
155 bool mmap2;
156 bool cloexec;
157 bool clockid;
158 bool clockid_wrong;
159 bool lbr_flags;
160 bool write_backward;
161 bool group_read;
162};
163
164extern struct perf_missing_features perf_missing_features;
165
152struct cpu_map; 166struct cpu_map;
153struct target; 167struct target;
154struct thread_map; 168struct thread_map;
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index f6630cb95eff..02721b579746 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -430,7 +430,8 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
430int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, 430int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
431 struct hist_browser_timer *hbt, 431 struct hist_browser_timer *hbt,
432 float min_pcnt, 432 float min_pcnt,
433 struct perf_env *env); 433 struct perf_env *env,
434 bool warn_lost_event);
434int script_browse(const char *script_opt); 435int script_browse(const char *script_opt);
435#else 436#else
436static inline 437static inline
@@ -438,7 +439,8 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
438 const char *help __maybe_unused, 439 const char *help __maybe_unused,
439 struct hist_browser_timer *hbt __maybe_unused, 440 struct hist_browser_timer *hbt __maybe_unused,
440 float min_pcnt __maybe_unused, 441 float min_pcnt __maybe_unused,
441 struct perf_env *env __maybe_unused) 442 struct perf_env *env __maybe_unused,
443 bool warn_lost_event __maybe_unused)
442{ 444{
443 return 0; 445 return 0;
444} 446}
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 05076e683938..91531a7c8fbf 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -22,29 +22,27 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map)
22 22
23/* When check_messup is true, 'end' must points to a good entry */ 23/* When check_messup is true, 'end' must points to a good entry */
24static union perf_event *perf_mmap__read(struct perf_mmap *map, 24static union perf_event *perf_mmap__read(struct perf_mmap *map,
25 u64 start, u64 end, u64 *prev) 25 u64 *startp, u64 end)
26{ 26{
27 unsigned char *data = map->base + page_size; 27 unsigned char *data = map->base + page_size;
28 union perf_event *event = NULL; 28 union perf_event *event = NULL;
29 int diff = end - start; 29 int diff = end - *startp;
30 30
31 if (diff >= (int)sizeof(event->header)) { 31 if (diff >= (int)sizeof(event->header)) {
32 size_t size; 32 size_t size;
33 33
34 event = (union perf_event *)&data[start & map->mask]; 34 event = (union perf_event *)&data[*startp & map->mask];
35 size = event->header.size; 35 size = event->header.size;
36 36
37 if (size < sizeof(event->header) || diff < (int)size) { 37 if (size < sizeof(event->header) || diff < (int)size)
38 event = NULL; 38 return NULL;
39 goto broken_event;
40 }
41 39
42 /* 40 /*
43 * Event straddles the mmap boundary -- header should always 41 * Event straddles the mmap boundary -- header should always
44 * be inside due to u64 alignment of output. 42 * be inside due to u64 alignment of output.
45 */ 43 */
46 if ((start & map->mask) + size != ((start + size) & map->mask)) { 44 if ((*startp & map->mask) + size != ((*startp + size) & map->mask)) {
47 unsigned int offset = start; 45 unsigned int offset = *startp;
48 unsigned int len = min(sizeof(*event), size), cpy; 46 unsigned int len = min(sizeof(*event), size), cpy;
49 void *dst = map->event_copy; 47 void *dst = map->event_copy;
50 48
@@ -59,20 +57,19 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map,
59 event = (union perf_event *)map->event_copy; 57 event = (union perf_event *)map->event_copy;
60 } 58 }
61 59
62 start += size; 60 *startp += size;
63 } 61 }
64 62
65broken_event:
66 if (prev)
67 *prev = start;
68
69 return event; 63 return event;
70} 64}
71 65
66/*
67 * legacy interface for mmap read.
68 * Don't use it. Use perf_mmap__read_event().
69 */
72union perf_event *perf_mmap__read_forward(struct perf_mmap *map) 70union perf_event *perf_mmap__read_forward(struct perf_mmap *map)
73{ 71{
74 u64 head; 72 u64 head;
75 u64 old = map->prev;
76 73
77 /* 74 /*
78 * Check if event was unmapped due to a POLLHUP/POLLERR. 75 * Check if event was unmapped due to a POLLHUP/POLLERR.
@@ -82,13 +79,26 @@ union perf_event *perf_mmap__read_forward(struct perf_mmap *map)
82 79
83 head = perf_mmap__read_head(map); 80 head = perf_mmap__read_head(map);
84 81
85 return perf_mmap__read(map, old, head, &map->prev); 82 return perf_mmap__read(map, &map->prev, head);
86} 83}
87 84
88union perf_event *perf_mmap__read_backward(struct perf_mmap *map) 85/*
86 * Read event from ring buffer one by one.
87 * Return one event for each call.
88 *
89 * Usage:
90 * perf_mmap__read_init()
91 * while(event = perf_mmap__read_event()) {
92 * //process the event
93 * perf_mmap__consume()
94 * }
95 * perf_mmap__read_done()
96 */
97union perf_event *perf_mmap__read_event(struct perf_mmap *map,
98 bool overwrite,
99 u64 *startp, u64 end)
89{ 100{
90 u64 head, end; 101 union perf_event *event;
91 u64 start = map->prev;
92 102
93 /* 103 /*
94 * Check if event was unmapped due to a POLLHUP/POLLERR. 104 * Check if event was unmapped due to a POLLHUP/POLLERR.
@@ -96,40 +106,19 @@ union perf_event *perf_mmap__read_backward(struct perf_mmap *map)
96 if (!refcount_read(&map->refcnt)) 106 if (!refcount_read(&map->refcnt))
97 return NULL; 107 return NULL;
98 108
99 head = perf_mmap__read_head(map); 109 if (startp == NULL)
100 if (!head)
101 return NULL; 110 return NULL;
102 111
103 /* 112 /* non-overwirte doesn't pause the ringbuffer */
104 * 'head' pointer starts from 0. Kernel minus sizeof(record) form 113 if (!overwrite)
105 * it each time when kernel writes to it, so in fact 'head' is 114 end = perf_mmap__read_head(map);
106 * negative. 'end' pointer is made manually by adding the size of
107 * the ring buffer to 'head' pointer, means the validate data can
108 * read is the whole ring buffer. If 'end' is positive, the ring
109 * buffer has not fully filled, so we must adjust 'end' to 0.
110 *
111 * However, since both 'head' and 'end' is unsigned, we can't
112 * simply compare 'end' against 0. Here we compare '-head' and
113 * the size of the ring buffer, where -head is the number of bytes
114 * kernel write to the ring buffer.
115 */
116 if (-head < (u64)(map->mask + 1))
117 end = 0;
118 else
119 end = head + map->mask + 1;
120
121 return perf_mmap__read(map, start, end, &map->prev);
122}
123 115
124void perf_mmap__read_catchup(struct perf_mmap *map) 116 event = perf_mmap__read(map, startp, end);
125{
126 u64 head;
127 117
128 if (!refcount_read(&map->refcnt)) 118 if (!overwrite)
129 return; 119 map->prev = *startp;
130 120
131 head = perf_mmap__read_head(map); 121 return event;
132 map->prev = head;
133} 122}
134 123
135static bool perf_mmap__empty(struct perf_mmap *map) 124static bool perf_mmap__empty(struct perf_mmap *map)
@@ -267,41 +256,60 @@ static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u6
267 return -1; 256 return -1;
268} 257}
269 258
270int perf_mmap__push(struct perf_mmap *md, bool overwrite, 259/*
271 void *to, int push(void *to, void *buf, size_t size)) 260 * Report the start and end of the available data in ringbuffer
261 */
262int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,
263 u64 *startp, u64 *endp)
272{ 264{
273 u64 head = perf_mmap__read_head(md); 265 u64 head = perf_mmap__read_head(md);
274 u64 old = md->prev; 266 u64 old = md->prev;
275 u64 end = head, start = old;
276 unsigned char *data = md->base + page_size; 267 unsigned char *data = md->base + page_size;
277 unsigned long size; 268 unsigned long size;
278 void *buf;
279 int rc = 0;
280 269
281 start = overwrite ? head : old; 270 *startp = overwrite ? head : old;
282 end = overwrite ? old : head; 271 *endp = overwrite ? old : head;
283 272
284 if (start == end) 273 if (*startp == *endp)
285 return 0; 274 return -EAGAIN;
286 275
287 size = end - start; 276 size = *endp - *startp;
288 if (size > (unsigned long)(md->mask) + 1) { 277 if (size > (unsigned long)(md->mask) + 1) {
289 if (!overwrite) { 278 if (!overwrite) {
290 WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n"); 279 WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
291 280
292 md->prev = head; 281 md->prev = head;
293 perf_mmap__consume(md, overwrite); 282 perf_mmap__consume(md, overwrite);
294 return 0; 283 return -EAGAIN;
295 } 284 }
296 285
297 /* 286 /*
298 * Backward ring buffer is full. We still have a chance to read 287 * Backward ring buffer is full. We still have a chance to read
299 * most of data from it. 288 * most of data from it.
300 */ 289 */
301 if (overwrite_rb_find_range(data, md->mask, head, &start, &end)) 290 if (overwrite_rb_find_range(data, md->mask, head, startp, endp))
302 return -1; 291 return -EINVAL;
303 } 292 }
304 293
294 return 0;
295}
296
297int perf_mmap__push(struct perf_mmap *md, bool overwrite,
298 void *to, int push(void *to, void *buf, size_t size))
299{
300 u64 head = perf_mmap__read_head(md);
301 u64 end, start;
302 unsigned char *data = md->base + page_size;
303 unsigned long size;
304 void *buf;
305 int rc = 0;
306
307 rc = perf_mmap__read_init(md, overwrite, &start, &end);
308 if (rc < 0)
309 return (rc == -EAGAIN) ? 0 : -1;
310
311 size = end - start;
312
305 if ((start & md->mask) + size != (end & md->mask)) { 313 if ((start & md->mask) + size != (end & md->mask)) {
306 buf = &data[start & md->mask]; 314 buf = &data[start & md->mask];
307 size = md->mask + 1 - (start & md->mask); 315 size = md->mask + 1 - (start & md->mask);
@@ -327,3 +335,14 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite,
327out: 335out:
328 return rc; 336 return rc;
329} 337}
338
339/*
340 * Mandatory for overwrite mode
341 * The direction of overwrite mode is backward.
342 * The last perf_mmap__read() will set tail to map->prev.
343 * Need to correct the map->prev to head which is the end of next read.
344 */
345void perf_mmap__read_done(struct perf_mmap *map)
346{
347 map->prev = perf_mmap__read_head(map);
348}
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index e43d7b55a55f..ec7d3a24e276 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -65,8 +65,6 @@ void perf_mmap__put(struct perf_mmap *map);
65 65
66void perf_mmap__consume(struct perf_mmap *map, bool overwrite); 66void perf_mmap__consume(struct perf_mmap *map, bool overwrite);
67 67
68void perf_mmap__read_catchup(struct perf_mmap *md);
69
70static inline u64 perf_mmap__read_head(struct perf_mmap *mm) 68static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
71{ 69{
72 struct perf_event_mmap_page *pc = mm->base; 70 struct perf_event_mmap_page *pc = mm->base;
@@ -87,11 +85,17 @@ static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
87} 85}
88 86
89union perf_event *perf_mmap__read_forward(struct perf_mmap *map); 87union perf_event *perf_mmap__read_forward(struct perf_mmap *map);
90union perf_event *perf_mmap__read_backward(struct perf_mmap *map); 88
89union perf_event *perf_mmap__read_event(struct perf_mmap *map,
90 bool overwrite,
91 u64 *startp, u64 end);
91 92
92int perf_mmap__push(struct perf_mmap *md, bool backward, 93int perf_mmap__push(struct perf_mmap *md, bool backward,
93 void *to, int push(void *to, void *buf, size_t size)); 94 void *to, int push(void *to, void *buf, size_t size));
94 95
95size_t perf_mmap__mmap_len(struct perf_mmap *map); 96size_t perf_mmap__mmap_len(struct perf_mmap *map);
96 97
98int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,
99 u64 *startp, u64 *endp);
100void perf_mmap__read_done(struct perf_mmap *map);
97#endif /*__PERF_MMAP_H */ 101#endif /*__PERF_MMAP_H */
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 1e97937b03a9..6f09e4962dad 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -137,6 +137,7 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts,
137 struct perf_evsel *evsel; 137 struct perf_evsel *evsel;
138 bool use_sample_identifier = false; 138 bool use_sample_identifier = false;
139 bool use_comm_exec; 139 bool use_comm_exec;
140 bool sample_id = opts->sample_id;
140 141
141 /* 142 /*
142 * Set the evsel leader links before we configure attributes, 143 * Set the evsel leader links before we configure attributes,
@@ -163,8 +164,7 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts,
163 * match the id. 164 * match the id.
164 */ 165 */
165 use_sample_identifier = perf_can_sample_identifier(); 166 use_sample_identifier = perf_can_sample_identifier();
166 evlist__for_each_entry(evlist, evsel) 167 sample_id = true;
167 perf_evsel__set_sample_id(evsel, use_sample_identifier);
168 } else if (evlist->nr_entries > 1) { 168 } else if (evlist->nr_entries > 1) {
169 struct perf_evsel *first = perf_evlist__first(evlist); 169 struct perf_evsel *first = perf_evlist__first(evlist);
170 170
@@ -174,6 +174,10 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts,
174 use_sample_identifier = perf_can_sample_identifier(); 174 use_sample_identifier = perf_can_sample_identifier();
175 break; 175 break;
176 } 176 }
177 sample_id = true;
178 }
179
180 if (sample_id) {
177 evlist__for_each_entry(evlist, evsel) 181 evlist__for_each_entry(evlist, evsel)
178 perf_evsel__set_sample_id(evsel, use_sample_identifier); 182 perf_evsel__set_sample_id(evsel, use_sample_identifier);
179 } 183 }
diff --git a/tools/perf/util/trigger.h b/tools/perf/util/trigger.h
index 370138e7e35c..88223bc7c82b 100644
--- a/tools/perf/util/trigger.h
+++ b/tools/perf/util/trigger.h
@@ -12,7 +12,7 @@
12 * States and transits: 12 * States and transits:
13 * 13 *
14 * 14 *
15 * OFF--(on)--> READY --(hit)--> HIT 15 * OFF--> ON --> READY --(hit)--> HIT
16 * ^ | 16 * ^ |
17 * | (ready) 17 * | (ready)
18 * | | 18 * | |
@@ -27,8 +27,9 @@ struct trigger {
27 volatile enum { 27 volatile enum {
28 TRIGGER_ERROR = -2, 28 TRIGGER_ERROR = -2,
29 TRIGGER_OFF = -1, 29 TRIGGER_OFF = -1,
30 TRIGGER_READY = 0, 30 TRIGGER_ON = 0,
31 TRIGGER_HIT = 1, 31 TRIGGER_READY = 1,
32 TRIGGER_HIT = 2,
32 } state; 33 } state;
33 const char *name; 34 const char *name;
34}; 35};
@@ -50,7 +51,7 @@ static inline bool trigger_is_error(struct trigger *t)
50static inline void trigger_on(struct trigger *t) 51static inline void trigger_on(struct trigger *t)
51{ 52{
52 TRIGGER_WARN_ONCE(t, TRIGGER_OFF); 53 TRIGGER_WARN_ONCE(t, TRIGGER_OFF);
53 t->state = TRIGGER_READY; 54 t->state = TRIGGER_ON;
54} 55}
55 56
56static inline void trigger_ready(struct trigger *t) 57static inline void trigger_ready(struct trigger *t)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 443892dabedb..1019bbc5dbd8 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -340,35 +340,15 @@ size_t hex_width(u64 v)
340 return n; 340 return n;
341} 341}
342 342
343static int hex(char ch)
344{
345 if ((ch >= '0') && (ch <= '9'))
346 return ch - '0';
347 if ((ch >= 'a') && (ch <= 'f'))
348 return ch - 'a' + 10;
349 if ((ch >= 'A') && (ch <= 'F'))
350 return ch - 'A' + 10;
351 return -1;
352}
353
354/* 343/*
355 * While we find nice hex chars, build a long_val. 344 * While we find nice hex chars, build a long_val.
356 * Return number of chars processed. 345 * Return number of chars processed.
357 */ 346 */
358int hex2u64(const char *ptr, u64 *long_val) 347int hex2u64(const char *ptr, u64 *long_val)
359{ 348{
360 const char *p = ptr; 349 char *p;
361 *long_val = 0;
362
363 while (*p) {
364 const int hex_val = hex(*p);
365 350
366 if (hex_val < 0) 351 *long_val = strtoull(ptr, &p, 16);
367 break;
368
369 *long_val = (*long_val << 4) | hex_val;
370 p++;
371 }
372 352
373 return p - ptr; 353 return p - ptr;
374} 354}
diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config
index a1883bbb0144..2cccbba64418 100644
--- a/tools/power/acpi/Makefile.config
+++ b/tools/power/acpi/Makefile.config
@@ -56,9 +56,6 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM}
56# to compile vs uClibc, that can be done here as well. 56# to compile vs uClibc, that can be done here as well.
57CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- 57CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
58CROSS_COMPILE ?= $(CROSS) 58CROSS_COMPILE ?= $(CROSS)
59CC = $(CROSS_COMPILE)gcc
60LD = $(CROSS_COMPILE)gcc
61STRIP = $(CROSS_COMPILE)strip
62HOSTCC = gcc 59HOSTCC = gcc
63 60
64# check if compiler option is supported 61# check if compiler option is supported
diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
index fcb3ed0be5f8..dd614463d4d6 100644
--- a/tools/scripts/Makefile.include
+++ b/tools/scripts/Makefile.include
@@ -42,6 +42,24 @@ EXTRA_WARNINGS += -Wformat
42 42
43CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) 43CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?)
44 44
45# Makefiles suck: This macro sets a default value of $(2) for the
46# variable named by $(1), unless the variable has been set by
47# environment or command line. This is necessary for CC and AR
48# because make sets default values, so the simpler ?= approach
49# won't work as expected.
50define allow-override
51 $(if $(or $(findstring environment,$(origin $(1))),\
52 $(findstring command line,$(origin $(1)))),,\
53 $(eval $(1) = $(2)))
54endef
55
56# Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix.
57$(call allow-override,CC,$(CROSS_COMPILE)gcc)
58$(call allow-override,AR,$(CROSS_COMPILE)ar)
59$(call allow-override,LD,$(CROSS_COMPILE)ld)
60$(call allow-override,CXX,$(CROSS_COMPILE)g++)
61$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
62
45ifeq ($(CC_NO_CLANG), 1) 63ifeq ($(CC_NO_CLANG), 1)
46EXTRA_WARNINGS += -Wstrict-aliasing=3 64EXTRA_WARNINGS += -Wstrict-aliasing=3
47endif 65endif
diff --git a/tools/spi/Makefile b/tools/spi/Makefile
index 90615e10c79a..815d15589177 100644
--- a/tools/spi/Makefile
+++ b/tools/spi/Makefile
@@ -11,8 +11,6 @@ endif
11# (this improves performance and avoids hard-to-debug behaviour); 11# (this improves performance and avoids hard-to-debug behaviour);
12MAKEFLAGS += -r 12MAKEFLAGS += -r
13 13
14CC = $(CROSS_COMPILE)gcc
15LD = $(CROSS_COMPILE)ld
16CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include 14CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
17 15
18ALL_TARGETS := spidev_test spidev_fdx 16ALL_TARGETS := spidev_test spidev_fdx
diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c
index 44ef9eba5a7a..6c645eb77d42 100644
--- a/tools/testing/radix-tree/idr-test.c
+++ b/tools/testing/radix-tree/idr-test.c
@@ -178,6 +178,55 @@ void idr_get_next_test(int base)
178 idr_destroy(&idr); 178 idr_destroy(&idr);
179} 179}
180 180
181int idr_u32_cb(int id, void *ptr, void *data)
182{
183 BUG_ON(id < 0);
184 BUG_ON(ptr != DUMMY_PTR);
185 return 0;
186}
187
188void idr_u32_test1(struct idr *idr, u32 handle)
189{
190 static bool warned = false;
191 u32 id = handle;
192 int sid = 0;
193 void *ptr;
194
195 BUG_ON(idr_alloc_u32(idr, DUMMY_PTR, &id, id, GFP_KERNEL));
196 BUG_ON(id != handle);
197 BUG_ON(idr_alloc_u32(idr, DUMMY_PTR, &id, id, GFP_KERNEL) != -ENOSPC);
198 BUG_ON(id != handle);
199 if (!warned && id > INT_MAX)
200 printk("vvv Ignore these warnings\n");
201 ptr = idr_get_next(idr, &sid);
202 if (id > INT_MAX) {
203 BUG_ON(ptr != NULL);
204 BUG_ON(sid != 0);
205 } else {
206 BUG_ON(ptr != DUMMY_PTR);
207 BUG_ON(sid != id);
208 }
209 idr_for_each(idr, idr_u32_cb, NULL);
210 if (!warned && id > INT_MAX) {
211 printk("^^^ Warnings over\n");
212 warned = true;
213 }
214 BUG_ON(idr_remove(idr, id) != DUMMY_PTR);
215 BUG_ON(!idr_is_empty(idr));
216}
217
218void idr_u32_test(int base)
219{
220 DEFINE_IDR(idr);
221 idr_init_base(&idr, base);
222 idr_u32_test1(&idr, 10);
223 idr_u32_test1(&idr, 0x7fffffff);
224 idr_u32_test1(&idr, 0x80000000);
225 idr_u32_test1(&idr, 0x80000001);
226 idr_u32_test1(&idr, 0xffe00000);
227 idr_u32_test1(&idr, 0xffffffff);
228}
229
181void idr_checks(void) 230void idr_checks(void)
182{ 231{
183 unsigned long i; 232 unsigned long i;
@@ -248,6 +297,9 @@ void idr_checks(void)
248 idr_get_next_test(0); 297 idr_get_next_test(0);
249 idr_get_next_test(1); 298 idr_get_next_test(1);
250 idr_get_next_test(4); 299 idr_get_next_test(4);
300 idr_u32_test(4);
301 idr_u32_test(1);
302 idr_u32_test(0);
251} 303}
252 304
253/* 305/*
diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c
index 6903ccf35595..44a0d1ad4408 100644
--- a/tools/testing/radix-tree/linux.c
+++ b/tools/testing/radix-tree/linux.c
@@ -29,7 +29,7 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, int flags)
29{ 29{
30 struct radix_tree_node *node; 30 struct radix_tree_node *node;
31 31
32 if (flags & __GFP_NOWARN) 32 if (!(flags & __GFP_DIRECT_RECLAIM))
33 return NULL; 33 return NULL;
34 34
35 pthread_mutex_lock(&cachep->lock); 35 pthread_mutex_lock(&cachep->lock);
@@ -73,10 +73,17 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp)
73 73
74void *kmalloc(size_t size, gfp_t gfp) 74void *kmalloc(size_t size, gfp_t gfp)
75{ 75{
76 void *ret = malloc(size); 76 void *ret;
77
78 if (!(gfp & __GFP_DIRECT_RECLAIM))
79 return NULL;
80
81 ret = malloc(size);
77 uatomic_inc(&nr_allocated); 82 uatomic_inc(&nr_allocated);
78 if (kmalloc_verbose) 83 if (kmalloc_verbose)
79 printf("Allocating %p from malloc\n", ret); 84 printf("Allocating %p from malloc\n", ret);
85 if (gfp & __GFP_ZERO)
86 memset(ret, 0, size);
80 return ret; 87 return ret;
81} 88}
82 89
diff --git a/tools/testing/radix-tree/linux/compiler_types.h b/tools/testing/radix-tree/linux/compiler_types.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/tools/testing/radix-tree/linux/compiler_types.h
diff --git a/tools/testing/radix-tree/linux/gfp.h b/tools/testing/radix-tree/linux/gfp.h
index e9fff59dfd8a..e3201ccf54c3 100644
--- a/tools/testing/radix-tree/linux/gfp.h
+++ b/tools/testing/radix-tree/linux/gfp.h
@@ -11,6 +11,7 @@
11#define __GFP_IO 0x40u 11#define __GFP_IO 0x40u
12#define __GFP_FS 0x80u 12#define __GFP_FS 0x80u
13#define __GFP_NOWARN 0x200u 13#define __GFP_NOWARN 0x200u
14#define __GFP_ZERO 0x8000u
14#define __GFP_ATOMIC 0x80000u 15#define __GFP_ATOMIC 0x80000u
15#define __GFP_ACCOUNT 0x100000u 16#define __GFP_ACCOUNT 0x100000u
16#define __GFP_DIRECT_RECLAIM 0x400000u 17#define __GFP_DIRECT_RECLAIM 0x400000u
diff --git a/tools/testing/radix-tree/linux/slab.h b/tools/testing/radix-tree/linux/slab.h
index 979baeec7e70..a037def0dec6 100644
--- a/tools/testing/radix-tree/linux/slab.h
+++ b/tools/testing/radix-tree/linux/slab.h
@@ -3,6 +3,7 @@
3#define SLAB_H 3#define SLAB_H
4 4
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/gfp.h>
6 7
7#define SLAB_HWCACHE_ALIGN 1 8#define SLAB_HWCACHE_ALIGN 1
8#define SLAB_PANIC 2 9#define SLAB_PANIC 2
@@ -11,6 +12,11 @@
11void *kmalloc(size_t size, gfp_t); 12void *kmalloc(size_t size, gfp_t);
12void kfree(void *); 13void kfree(void *);
13 14
15static inline void *kzalloc(size_t size, gfp_t gfp)
16{
17 return kmalloc(size, gfp | __GFP_ZERO);
18}
19
14void *kmem_cache_alloc(struct kmem_cache *cachep, int flags); 20void *kmem_cache_alloc(struct kmem_cache *cachep, int flags);
15void kmem_cache_free(struct kmem_cache *cachep, void *objp); 21void kmem_cache_free(struct kmem_cache *cachep, void *objp);
16 22
diff --git a/tools/testing/selftests/android/Makefile b/tools/testing/selftests/android/Makefile
index 1a7492268993..f6304d2be90c 100644
--- a/tools/testing/selftests/android/Makefile
+++ b/tools/testing/selftests/android/Makefile
@@ -11,11 +11,11 @@ all:
11 BUILD_TARGET=$(OUTPUT)/$$DIR; \ 11 BUILD_TARGET=$(OUTPUT)/$$DIR; \
12 mkdir $$BUILD_TARGET -p; \ 12 mkdir $$BUILD_TARGET -p; \
13 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\ 13 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
14 #SUBDIR test prog name should be in the form: SUBDIR_test.sh 14 #SUBDIR test prog name should be in the form: SUBDIR_test.sh \
15 TEST=$$DIR"_test.sh"; \ 15 TEST=$$DIR"_test.sh"; \
16 if [ -e $$DIR/$$TEST ]; then 16 if [ -e $$DIR/$$TEST ]; then \
17 rsync -a $$DIR/$$TEST $$BUILD_TARGET/; 17 rsync -a $$DIR/$$TEST $$BUILD_TARGET/; \
18 fi 18 fi \
19 done 19 done
20 20
21override define RUN_TESTS 21override define RUN_TESTS
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index cc15af2e54fe..9cf83f895d98 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -11,3 +11,4 @@ test_progs
11test_tcpbpf_user 11test_tcpbpf_user
12test_verifier_log 12test_verifier_log
13feature 13feature
14test_libbpf_open
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index 436c4c72414f..9e03a4c356a4 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -126,6 +126,8 @@ static void test_hashmap_sizes(int task, void *data)
126 fd = bpf_create_map(BPF_MAP_TYPE_HASH, i, j, 126 fd = bpf_create_map(BPF_MAP_TYPE_HASH, i, j,
127 2, map_flags); 127 2, map_flags);
128 if (fd < 0) { 128 if (fd < 0) {
129 if (errno == ENOMEM)
130 return;
129 printf("Failed to create hashmap key=%d value=%d '%s'\n", 131 printf("Failed to create hashmap key=%d value=%d '%s'\n",
130 i, j, strerror(errno)); 132 i, j, strerror(errno));
131 exit(1); 133 exit(1);
diff --git a/tools/testing/selftests/bpf/test_tcpbpf_kern.c b/tools/testing/selftests/bpf/test_tcpbpf_kern.c
index 57119ad57a3f..3e645ee41ed5 100644
--- a/tools/testing/selftests/bpf/test_tcpbpf_kern.c
+++ b/tools/testing/selftests/bpf/test_tcpbpf_kern.c
@@ -5,7 +5,6 @@
5#include <linux/if_ether.h> 5#include <linux/if_ether.h>
6#include <linux/if_packet.h> 6#include <linux/if_packet.h>
7#include <linux/ip.h> 7#include <linux/ip.h>
8#include <linux/in6.h>
9#include <linux/types.h> 8#include <linux/types.h>
10#include <linux/socket.h> 9#include <linux/socket.h>
11#include <linux/tcp.h> 10#include <linux/tcp.h>
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index c0f16e93f9bd..437c0b1c9d21 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -2587,6 +2587,32 @@ static struct bpf_test tests[] = {
2587 .result = ACCEPT, 2587 .result = ACCEPT,
2588 }, 2588 },
2589 { 2589 {
2590 "runtime/jit: pass negative index to tail_call",
2591 .insns = {
2592 BPF_MOV64_IMM(BPF_REG_3, -1),
2593 BPF_LD_MAP_FD(BPF_REG_2, 0),
2594 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
2595 BPF_FUNC_tail_call),
2596 BPF_MOV64_IMM(BPF_REG_0, 0),
2597 BPF_EXIT_INSN(),
2598 },
2599 .fixup_prog = { 1 },
2600 .result = ACCEPT,
2601 },
2602 {
2603 "runtime/jit: pass > 32bit index to tail_call",
2604 .insns = {
2605 BPF_LD_IMM64(BPF_REG_3, 0x100000000ULL),
2606 BPF_LD_MAP_FD(BPF_REG_2, 0),
2607 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
2608 BPF_FUNC_tail_call),
2609 BPF_MOV64_IMM(BPF_REG_0, 0),
2610 BPF_EXIT_INSN(),
2611 },
2612 .fixup_prog = { 2 },
2613 .result = ACCEPT,
2614 },
2615 {
2590 "stack pointer arithmetic", 2616 "stack pointer arithmetic",
2591 .insns = { 2617 .insns = {
2592 BPF_MOV64_IMM(BPF_REG_1, 4), 2618 BPF_MOV64_IMM(BPF_REG_1, 4),
@@ -11137,6 +11163,64 @@ static struct bpf_test tests[] = {
11137 .result = REJECT, 11163 .result = REJECT,
11138 .prog_type = BPF_PROG_TYPE_TRACEPOINT, 11164 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
11139 }, 11165 },
11166 {
11167 "xadd/w check unaligned stack",
11168 .insns = {
11169 BPF_MOV64_IMM(BPF_REG_0, 1),
11170 BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
11171 BPF_STX_XADD(BPF_W, BPF_REG_10, BPF_REG_0, -7),
11172 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_10, -8),
11173 BPF_EXIT_INSN(),
11174 },
11175 .result = REJECT,
11176 .errstr = "misaligned stack access off",
11177 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
11178 },
11179 {
11180 "xadd/w check unaligned map",
11181 .insns = {
11182 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
11183 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
11184 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
11185 BPF_LD_MAP_FD(BPF_REG_1, 0),
11186 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
11187 BPF_FUNC_map_lookup_elem),
11188 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
11189 BPF_EXIT_INSN(),
11190 BPF_MOV64_IMM(BPF_REG_1, 1),
11191 BPF_STX_XADD(BPF_W, BPF_REG_0, BPF_REG_1, 3),
11192 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, 3),
11193 BPF_EXIT_INSN(),
11194 },
11195 .fixup_map1 = { 3 },
11196 .result = REJECT,
11197 .errstr = "misaligned value access off",
11198 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
11199 },
11200 {
11201 "xadd/w check unaligned pkt",
11202 .insns = {
11203 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
11204 offsetof(struct xdp_md, data)),
11205 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
11206 offsetof(struct xdp_md, data_end)),
11207 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
11208 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
11209 BPF_JMP_REG(BPF_JLT, BPF_REG_1, BPF_REG_3, 2),
11210 BPF_MOV64_IMM(BPF_REG_0, 99),
11211 BPF_JMP_IMM(BPF_JA, 0, 0, 6),
11212 BPF_MOV64_IMM(BPF_REG_0, 1),
11213 BPF_ST_MEM(BPF_W, BPF_REG_2, 0, 0),
11214 BPF_ST_MEM(BPF_W, BPF_REG_2, 3, 0),
11215 BPF_STX_XADD(BPF_W, BPF_REG_2, BPF_REG_0, 1),
11216 BPF_STX_XADD(BPF_W, BPF_REG_2, BPF_REG_0, 2),
11217 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_2, 1),
11218 BPF_EXIT_INSN(),
11219 },
11220 .result = REJECT,
11221 .errstr = "BPF_XADD stores into R2 packet",
11222 .prog_type = BPF_PROG_TYPE_XDP,
11223 },
11140}; 11224};
11141 11225
11142static int probe_filter_length(const struct bpf_insn *fp) 11226static int probe_filter_length(const struct bpf_insn *fp)
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc
new file mode 100644
index 000000000000..5ba73035e1d9
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc
@@ -0,0 +1,46 @@
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobe event string type argument
4
5[ -f kprobe_events ] || exit_unsupported # this is configurable
6
7echo 0 > events/enable
8echo > kprobe_events
9
10case `uname -m` in
11x86_64)
12 ARG2=%si
13 OFFS=8
14;;
15i[3456]86)
16 ARG2=%cx
17 OFFS=4
18;;
19aarch64)
20 ARG2=%x1
21 OFFS=8
22;;
23arm*)
24 ARG2=%r1
25 OFFS=4
26;;
27*)
28 echo "Please implement other architecture here"
29 exit_untested
30esac
31
32: "Test get argument (1)"
33echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string" > kprobe_events
34echo 1 > events/kprobes/testprobe/enable
35! echo test >> kprobe_events
36tail -n 1 trace | grep -qe "testprobe.* arg1=\"test\""
37
38echo 0 > events/kprobes/testprobe/enable
39: "Test get argument (2)"
40echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string arg2=+0(+${OFFS}(${ARG2})):string" > kprobe_events
41echo 1 > events/kprobes/testprobe/enable
42! echo test1 test2 >> kprobe_events
43tail -n 1 trace | grep -qe "testprobe.* arg1=\"test1\" arg2=\"test2\""
44
45echo 0 > events/enable
46echo > kprobe_events
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc
new file mode 100644
index 000000000000..231bcd2c4eb5
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc
@@ -0,0 +1,97 @@
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobe event argument syntax
4
5[ -f kprobe_events ] || exit_unsupported # this is configurable
6
7grep "x8/16/32/64" README > /dev/null || exit_unsupported # version issue
8
9echo 0 > events/enable
10echo > kprobe_events
11
12PROBEFUNC="vfs_read"
13GOODREG=
14BADREG=
15GOODSYM="_sdata"
16if ! grep -qw ${GOODSYM} /proc/kallsyms ; then
17 GOODSYM=$PROBEFUNC
18fi
19BADSYM="deaqswdefr"
20SYMADDR=0x`grep -w ${GOODSYM} /proc/kallsyms | cut -f 1 -d " "`
21GOODTYPE="x16"
22BADTYPE="y16"
23
24case `uname -m` in
25x86_64|i[3456]86)
26 GOODREG=%ax
27 BADREG=%ex
28;;
29aarch64)
30 GOODREG=%x0
31 BADREG=%ax
32;;
33arm*)
34 GOODREG=%r0
35 BADREG=%ax
36;;
37esac
38
39test_goodarg() # Good-args
40{
41 while [ "$1" ]; do
42 echo "p ${PROBEFUNC} $1" > kprobe_events
43 shift 1
44 done;
45}
46
47test_badarg() # Bad-args
48{
49 while [ "$1" ]; do
50 ! echo "p ${PROBEFUNC} $1" > kprobe_events
51 shift 1
52 done;
53}
54
55echo > kprobe_events
56
57: "Register access"
58test_goodarg ${GOODREG}
59test_badarg ${BADREG}
60
61: "Symbol access"
62test_goodarg "@${GOODSYM}" "@${SYMADDR}" "@${GOODSYM}+10" "@${GOODSYM}-10"
63test_badarg "@" "@${BADSYM}" "@${GOODSYM}*10" "@${GOODSYM}/10" \
64 "@${GOODSYM}%10" "@${GOODSYM}&10" "@${GOODSYM}|10"
65
66: "Stack access"
67test_goodarg "\$stack" "\$stack0" "\$stack1"
68test_badarg "\$stackp" "\$stack0+10" "\$stack1-10"
69
70: "Retval access"
71echo "r ${PROBEFUNC} \$retval" > kprobe_events
72! echo "p ${PROBEFUNC} \$retval" > kprobe_events
73
74: "Comm access"
75test_goodarg "\$comm"
76
77: "Indirect memory access"
78test_goodarg "+0(${GOODREG})" "-0(${GOODREG})" "+10(\$stack)" \
79 "+0(\$stack1)" "+10(@${GOODSYM}-10)" "+0(+10(+20(\$stack)))"
80test_badarg "+(${GOODREG})" "(${GOODREG}+10)" "-(${GOODREG})" "(${GOODREG})" \
81 "+10(\$comm)" "+0(${GOODREG})+10"
82
83: "Name assignment"
84test_goodarg "varname=${GOODREG}"
85test_badarg "varname=varname2=${GOODREG}"
86
87: "Type syntax"
88test_goodarg "${GOODREG}:${GOODTYPE}"
89test_badarg "${GOODREG}::${GOODTYPE}" "${GOODREG}:${BADTYPE}" \
90 "${GOODTYPE}:${GOODREG}"
91
92: "Combination check"
93
94test_goodarg "\$comm:string" "+0(\$stack):string"
95test_badarg "\$comm:x64" "\$stack:string" "${GOODREG}:string"
96
97echo > kprobe_events
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc b/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc
new file mode 100644
index 000000000000..4fda01a08da4
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc
@@ -0,0 +1,43 @@
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobe events - probe points
4
5[ -f kprobe_events ] || exit_unsupported # this is configurable
6
7TARGET_FUNC=create_trace_kprobe
8
9dec_addr() { # hexaddr
10 printf "%d" "0x"`echo $1 | tail -c 8`
11}
12
13set_offs() { # prev target next
14 A1=`dec_addr $1`
15 A2=`dec_addr $2`
16 A3=`dec_addr $3`
17 TARGET="0x$2" # an address
18 PREV=`expr $A1 - $A2` # offset to previous symbol
19 NEXT=+`expr $A3 - $A2` # offset to next symbol
20 OVERFLOW=+`printf "0x%x" ${PREV}` # overflow offset to previous symbol
21}
22
23# We have to decode symbol addresses to get correct offsets.
24# If the offset is not an instruction boundary, it cause -EILSEQ.
25set_offs `grep -A1 -B1 ${TARGET_FUNC} /proc/kallsyms | cut -f 1 -d " " | xargs`
26
27UINT_TEST=no
28# printf "%x" -1 returns (unsigned long)-1.
29if [ `printf "%x" -1 | wc -c` != 9 ]; then
30 UINT_TEST=yes
31fi
32
33echo 0 > events/enable
34echo > kprobe_events
35echo "p:testprobe ${TARGET_FUNC}" > kprobe_events
36echo "p:testprobe ${TARGET}" > kprobe_events
37echo "p:testprobe ${TARGET_FUNC}${NEXT}" > kprobe_events
38! echo "p:testprobe ${TARGET_FUNC}${PREV}" > kprobe_events
39if [ "${UINT_TEST}" = yes ]; then
40! echo "p:testprobe ${TARGET_FUNC}${OVERFLOW}" > kprobe_events
41fi
42echo > kprobe_events
43clear_trace
diff --git a/tools/testing/selftests/futex/Makefile b/tools/testing/selftests/futex/Makefile
index cea4adcd42b8..a63e8453984d 100644
--- a/tools/testing/selftests/futex/Makefile
+++ b/tools/testing/selftests/futex/Makefile
@@ -12,9 +12,9 @@ all:
12 BUILD_TARGET=$(OUTPUT)/$$DIR; \ 12 BUILD_TARGET=$(OUTPUT)/$$DIR; \
13 mkdir $$BUILD_TARGET -p; \ 13 mkdir $$BUILD_TARGET -p; \
14 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\ 14 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
15 if [ -e $$DIR/$(TEST_PROGS) ]; then 15 if [ -e $$DIR/$(TEST_PROGS) ]; then \
16 rsync -a $$DIR/$(TEST_PROGS) $$BUILD_TARGET/; 16 rsync -a $$DIR/$(TEST_PROGS) $$BUILD_TARGET/; \
17 fi 17 fi \
18 done 18 done
19 19
20override define RUN_TESTS 20override define RUN_TESTS
diff --git a/tools/testing/selftests/memfd/Makefile b/tools/testing/selftests/memfd/Makefile
index a5276a91dfbf..0862e6f47a38 100644
--- a/tools/testing/selftests/memfd/Makefile
+++ b/tools/testing/selftests/memfd/Makefile
@@ -5,6 +5,7 @@ CFLAGS += -I../../../../include/
5CFLAGS += -I../../../../usr/include/ 5CFLAGS += -I../../../../usr/include/
6 6
7TEST_PROGS := run_tests.sh 7TEST_PROGS := run_tests.sh
8TEST_FILES := run_fuse_test.sh
8TEST_GEN_FILES := memfd_test fuse_mnt fuse_test 9TEST_GEN_FILES := memfd_test fuse_mnt fuse_test
9 10
10fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags) 11fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags)
diff --git a/tools/testing/selftests/memfd/config b/tools/testing/selftests/memfd/config
new file mode 100644
index 000000000000..835c7f4dadcd
--- /dev/null
+++ b/tools/testing/selftests/memfd/config
@@ -0,0 +1 @@
CONFIG_FUSE_FS=m
diff --git a/tools/testing/selftests/memory-hotplug/Makefile b/tools/testing/selftests/memory-hotplug/Makefile
index 86636d207adf..686da510f989 100644
--- a/tools/testing/selftests/memory-hotplug/Makefile
+++ b/tools/testing/selftests/memory-hotplug/Makefile
@@ -4,8 +4,9 @@ all:
4include ../lib.mk 4include ../lib.mk
5 5
6TEST_PROGS := mem-on-off-test.sh 6TEST_PROGS := mem-on-off-test.sh
7override RUN_TESTS := ./mem-on-off-test.sh -r 2 && echo "selftests: memory-hotplug [PASS]" || echo "selftests: memory-hotplug [FAIL]" 7override RUN_TESTS := @./mem-on-off-test.sh -r 2 && echo "selftests: memory-hotplug [PASS]" || echo "selftests: memory-hotplug [FAIL]"
8override EMIT_TESTS := echo "$(RUN_TESTS)" 8
9override EMIT_TESTS := echo "$(subst @,,$(RUN_TESTS))"
9 10
10run_full_test: 11run_full_test:
11 @/bin/bash ./mem-on-off-test.sh && echo "memory-hotplug selftests: [PASS]" || echo "memory-hotplug selftests: [FAIL]" 12 @/bin/bash ./mem-on-off-test.sh && echo "memory-hotplug selftests: [PASS]" || echo "memory-hotplug selftests: [FAIL]"
diff --git a/tools/testing/selftests/powerpc/alignment/alignment_handler.c b/tools/testing/selftests/powerpc/alignment/alignment_handler.c
index 39fd362415cf..0f2698f9fd6d 100644
--- a/tools/testing/selftests/powerpc/alignment/alignment_handler.c
+++ b/tools/testing/selftests/powerpc/alignment/alignment_handler.c
@@ -57,7 +57,7 @@ volatile int gotsig;
57 57
58void sighandler(int sig, siginfo_t *info, void *ctx) 58void sighandler(int sig, siginfo_t *info, void *ctx)
59{ 59{
60 struct ucontext *ucp = ctx; 60 ucontext_t *ucp = ctx;
61 61
62 if (!testing) { 62 if (!testing) {
63 signal(sig, SIG_DFL); 63 signal(sig, SIG_DFL);
diff --git a/tools/testing/selftests/powerpc/mm/subpage_prot.c b/tools/testing/selftests/powerpc/mm/subpage_prot.c
index 35ade7406dcd..3ae77ba93208 100644
--- a/tools/testing/selftests/powerpc/mm/subpage_prot.c
+++ b/tools/testing/selftests/powerpc/mm/subpage_prot.c
@@ -135,6 +135,16 @@ static int run_test(void *addr, unsigned long size)
135 return 0; 135 return 0;
136} 136}
137 137
138static int syscall_available(void)
139{
140 int rc;
141
142 errno = 0;
143 rc = syscall(__NR_subpage_prot, 0, 0, 0);
144
145 return rc == 0 || (errno != ENOENT && errno != ENOSYS);
146}
147
138int test_anon(void) 148int test_anon(void)
139{ 149{
140 unsigned long align; 150 unsigned long align;
@@ -145,6 +155,8 @@ int test_anon(void)
145 void *mallocblock; 155 void *mallocblock;
146 unsigned long mallocsize; 156 unsigned long mallocsize;
147 157
158 SKIP_IF(!syscall_available());
159
148 if (getpagesize() != 0x10000) { 160 if (getpagesize() != 0x10000) {
149 fprintf(stderr, "Kernel page size must be 64K!\n"); 161 fprintf(stderr, "Kernel page size must be 64K!\n");
150 return 1; 162 return 1;
@@ -180,6 +192,8 @@ int test_file(void)
180 off_t filesize; 192 off_t filesize;
181 int fd; 193 int fd;
182 194
195 SKIP_IF(!syscall_available());
196
183 fd = open(file_name, O_RDWR); 197 fd = open(file_name, O_RDWR);
184 if (fd == -1) { 198 if (fd == -1) {
185 perror("failed to open file"); 199 perror("failed to open file");
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index a23453943ad2..5c72ff978f27 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -16,7 +16,7 @@ $(OUTPUT)/tm-syscall: tm-syscall-asm.S
16$(OUTPUT)/tm-syscall: CFLAGS += -I../../../../../usr/include 16$(OUTPUT)/tm-syscall: CFLAGS += -I../../../../../usr/include
17$(OUTPUT)/tm-tmspr: CFLAGS += -pthread 17$(OUTPUT)/tm-tmspr: CFLAGS += -pthread
18$(OUTPUT)/tm-vmx-unavail: CFLAGS += -pthread -m64 18$(OUTPUT)/tm-vmx-unavail: CFLAGS += -pthread -m64
19$(OUTPUT)/tm-resched-dscr: ../pmu/lib.o 19$(OUTPUT)/tm-resched-dscr: ../pmu/lib.c
20$(OUTPUT)/tm-unavailable: CFLAGS += -O0 -pthread -m64 -Wno-error=uninitialized -mvsx 20$(OUTPUT)/tm-unavailable: CFLAGS += -O0 -pthread -m64 -Wno-error=uninitialized -mvsx
21$(OUTPUT)/tm-trap: CFLAGS += -O0 -pthread -m64 21$(OUTPUT)/tm-trap: CFLAGS += -O0 -pthread -m64
22 22
diff --git a/tools/testing/selftests/powerpc/tm/tm-trap.c b/tools/testing/selftests/powerpc/tm/tm-trap.c
index 5d92c23ee6cb..179d592f0073 100644
--- a/tools/testing/selftests/powerpc/tm/tm-trap.c
+++ b/tools/testing/selftests/powerpc/tm/tm-trap.c
@@ -255,6 +255,8 @@ int tm_trap_test(void)
255 255
256 struct sigaction trap_sa; 256 struct sigaction trap_sa;
257 257
258 SKIP_IF(!have_htm());
259
258 trap_sa.sa_flags = SA_SIGINFO; 260 trap_sa.sa_flags = SA_SIGINFO;
259 trap_sa.sa_sigaction = trap_signal_handler; 261 trap_sa.sa_sigaction = trap_signal_handler;
260 sigaction(SIGTRAP, &trap_sa, NULL); 262 sigaction(SIGTRAP, &trap_sa, NULL);
diff --git a/tools/testing/selftests/pstore/config b/tools/testing/selftests/pstore/config
index 6a8e5a9bfc10..d148f9f89fb6 100644
--- a/tools/testing/selftests/pstore/config
+++ b/tools/testing/selftests/pstore/config
@@ -2,3 +2,4 @@ CONFIG_MISC_FILESYSTEMS=y
2CONFIG_PSTORE=y 2CONFIG_PSTORE=y
3CONFIG_PSTORE_PMSG=y 3CONFIG_PSTORE_PMSG=y
4CONFIG_PSTORE_CONSOLE=y 4CONFIG_PSTORE_CONSOLE=y
5CONFIG_PSTORE_RAM=m
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 0b457e8e0f0c..5df609950a66 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -141,6 +141,15 @@ struct seccomp_data {
141#define SECCOMP_FILTER_FLAG_LOG 2 141#define SECCOMP_FILTER_FLAG_LOG 2
142#endif 142#endif
143 143
144#ifndef PTRACE_SECCOMP_GET_METADATA
145#define PTRACE_SECCOMP_GET_METADATA 0x420d
146
147struct seccomp_metadata {
148 __u64 filter_off; /* Input: which filter */
149 __u64 flags; /* Output: filter's flags */
150};
151#endif
152
144#ifndef seccomp 153#ifndef seccomp
145int seccomp(unsigned int op, unsigned int flags, void *args) 154int seccomp(unsigned int op, unsigned int flags, void *args)
146{ 155{
@@ -2845,6 +2854,58 @@ TEST(get_action_avail)
2845 EXPECT_EQ(errno, EOPNOTSUPP); 2854 EXPECT_EQ(errno, EOPNOTSUPP);
2846} 2855}
2847 2856
2857TEST(get_metadata)
2858{
2859 pid_t pid;
2860 int pipefd[2];
2861 char buf;
2862 struct seccomp_metadata md;
2863
2864 ASSERT_EQ(0, pipe(pipefd));
2865
2866 pid = fork();
2867 ASSERT_GE(pid, 0);
2868 if (pid == 0) {
2869 struct sock_filter filter[] = {
2870 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
2871 };
2872 struct sock_fprog prog = {
2873 .len = (unsigned short)ARRAY_SIZE(filter),
2874 .filter = filter,
2875 };
2876
2877 /* one with log, one without */
2878 ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER,
2879 SECCOMP_FILTER_FLAG_LOG, &prog));
2880 ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog));
2881
2882 ASSERT_EQ(0, close(pipefd[0]));
2883 ASSERT_EQ(1, write(pipefd[1], "1", 1));
2884 ASSERT_EQ(0, close(pipefd[1]));
2885
2886 while (1)
2887 sleep(100);
2888 }
2889
2890 ASSERT_EQ(0, close(pipefd[1]));
2891 ASSERT_EQ(1, read(pipefd[0], &buf, 1));
2892
2893 ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid));
2894 ASSERT_EQ(pid, waitpid(pid, NULL, 0));
2895
2896 md.filter_off = 0;
2897 ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
2898 EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG);
2899 EXPECT_EQ(md.filter_off, 0);
2900
2901 md.filter_off = 1;
2902 ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
2903 EXPECT_EQ(md.flags, 0);
2904 EXPECT_EQ(md.filter_off, 1);
2905
2906 ASSERT_EQ(0, kill(pid, SIGKILL));
2907}
2908
2848/* 2909/*
2849 * TODO: 2910 * TODO:
2850 * - add microbenchmarks 2911 * - add microbenchmarks
diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
index b3c8ba3cb668..d0121a8a3523 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -30,7 +30,7 @@ $(TEST_CUSTOM_PROGS): $(TESTS) $(OBJS)
30 $(CC) -o $(TEST_CUSTOM_PROGS) $(OBJS) $(TESTS) $(CFLAGS) $(LDFLAGS) 30 $(CC) -o $(TEST_CUSTOM_PROGS) $(OBJS) $(TESTS) $(CFLAGS) $(LDFLAGS)
31 31
32$(OBJS): $(OUTPUT)/%.o: %.c 32$(OBJS): $(OUTPUT)/%.o: %.c
33 $(CC) -c $^ -o $@ 33 $(CC) -c $^ -o $@ $(CFLAGS)
34 34
35$(TESTS): $(OUTPUT)/%.o: %.c 35$(TESTS): $(OUTPUT)/%.o: %.c
36 $(CC) -c $^ -o $@ 36 $(CC) -c $^ -o $@
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/skbmod.json b/tools/testing/selftests/tc-testing/tc-tests/actions/skbmod.json
index e34075059c26..90bba48c3f07 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/skbmod.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/skbmod.json
@@ -315,7 +315,7 @@
315 "cmdUnderTest": "$TC actions ls action skbmod", 315 "cmdUnderTest": "$TC actions ls action skbmod",
316 "expExitCode": "0", 316 "expExitCode": "0",
317 "verifyCmd": "$TC actions get action skbmod index 4", 317 "verifyCmd": "$TC actions get action skbmod index 4",
318 "matchPattern": "action order [0-9]*: skbmod pipe set etype 0x0031", 318 "matchPattern": "action order [0-9]*: skbmod pipe set etype 0x31",
319 "matchCount": "1", 319 "matchCount": "1",
320 "teardown": [ 320 "teardown": [
321 "$TC actions flush action skbmod" 321 "$TC actions flush action skbmod"
diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
index 3d5a62ff7d31..f5d7a7851e21 100644
--- a/tools/testing/selftests/vDSO/Makefile
+++ b/tools/testing/selftests/vDSO/Makefile
@@ -1,4 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2include ../lib.mk
3
2ifndef CROSS_COMPILE 4ifndef CROSS_COMPILE
3CFLAGS := -std=gnu99 5CFLAGS := -std=gnu99
4CFLAGS_vdso_standalone_test_x86 := -nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector 6CFLAGS_vdso_standalone_test_x86 := -nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector
@@ -6,16 +8,14 @@ ifeq ($(CONFIG_X86_32),y)
6LDLIBS += -lgcc_s 8LDLIBS += -lgcc_s
7endif 9endif
8 10
9TEST_PROGS := vdso_test vdso_standalone_test_x86 11TEST_PROGS := $(OUTPUT)/vdso_test $(OUTPUT)/vdso_standalone_test_x86
10 12
11all: $(TEST_PROGS) 13all: $(TEST_PROGS)
12vdso_test: parse_vdso.c vdso_test.c 14$(OUTPUT)/vdso_test: parse_vdso.c vdso_test.c
13vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c 15$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c
14 $(CC) $(CFLAGS) $(CFLAGS_vdso_standalone_test_x86) \ 16 $(CC) $(CFLAGS) $(CFLAGS_vdso_standalone_test_x86) \
15 vdso_standalone_test_x86.c parse_vdso.c \ 17 vdso_standalone_test_x86.c parse_vdso.c \
16 -o vdso_standalone_test_x86 18 -o $@
17 19
18include ../lib.mk 20EXTRA_CLEAN := $(TEST_PROGS)
19clean:
20 rm -fr $(TEST_PROGS)
21endif 21endif
diff --git a/tools/testing/selftests/vm/.gitignore b/tools/testing/selftests/vm/.gitignore
index 63c94d776e89..342c7bc9dc8c 100644
--- a/tools/testing/selftests/vm/.gitignore
+++ b/tools/testing/selftests/vm/.gitignore
@@ -11,3 +11,4 @@ mlock-intersect-test
11mlock-random-test 11mlock-random-test
12virtual_address_range 12virtual_address_range
13gup_benchmark 13gup_benchmark
14va_128TBswitch
diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests
index d2561895a021..22d564673830 100755
--- a/tools/testing/selftests/vm/run_vmtests
+++ b/tools/testing/selftests/vm/run_vmtests
@@ -2,25 +2,33 @@
2# SPDX-License-Identifier: GPL-2.0 2# SPDX-License-Identifier: GPL-2.0
3#please run as root 3#please run as root
4 4
5#we need 256M, below is the size in kB
6needmem=262144
7mnt=./huge 5mnt=./huge
8exitcode=0 6exitcode=0
9 7
10#get pagesize and freepages from /proc/meminfo 8#get huge pagesize and freepages from /proc/meminfo
11while read name size unit; do 9while read name size unit; do
12 if [ "$name" = "HugePages_Free:" ]; then 10 if [ "$name" = "HugePages_Free:" ]; then
13 freepgs=$size 11 freepgs=$size
14 fi 12 fi
15 if [ "$name" = "Hugepagesize:" ]; then 13 if [ "$name" = "Hugepagesize:" ]; then
16 pgsize=$size 14 hpgsize_KB=$size
17 fi 15 fi
18done < /proc/meminfo 16done < /proc/meminfo
19 17
18# Simple hugetlbfs tests have a hardcoded minimum requirement of
19# huge pages totaling 256MB (262144KB) in size. The userfaultfd
20# hugetlb test requires a minimum of 2 * nr_cpus huge pages. Take
21# both of these requirements into account and attempt to increase
22# number of huge pages available.
23nr_cpus=$(nproc)
24hpgsize_MB=$((hpgsize_KB / 1024))
25half_ufd_size_MB=$((((nr_cpus * hpgsize_MB + 127) / 128) * 128))
26needmem_KB=$((half_ufd_size_MB * 2 * 1024))
27
20#set proper nr_hugepages 28#set proper nr_hugepages
21if [ -n "$freepgs" ] && [ -n "$pgsize" ]; then 29if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then
22 nr_hugepgs=`cat /proc/sys/vm/nr_hugepages` 30 nr_hugepgs=`cat /proc/sys/vm/nr_hugepages`
23 needpgs=`expr $needmem / $pgsize` 31 needpgs=$((needmem_KB / hpgsize_KB))
24 tries=2 32 tries=2
25 while [ $tries -gt 0 ] && [ $freepgs -lt $needpgs ]; do 33 while [ $tries -gt 0 ] && [ $freepgs -lt $needpgs ]; do
26 lackpgs=$(( $needpgs - $freepgs )) 34 lackpgs=$(( $needpgs - $freepgs ))
@@ -107,8 +115,9 @@ fi
107echo "---------------------------" 115echo "---------------------------"
108echo "running userfaultfd_hugetlb" 116echo "running userfaultfd_hugetlb"
109echo "---------------------------" 117echo "---------------------------"
110# 256MB total huge pages == 128MB src and 128MB dst 118# Test requires source and destination huge pages. Size of source
111./userfaultfd hugetlb 128 32 $mnt/ufd_test_file 119# (half_ufd_size_MB) is passed as argument to test.
120./userfaultfd hugetlb $half_ufd_size_MB 32 $mnt/ufd_test_file
112if [ $? -ne 0 ]; then 121if [ $? -ne 0 ]; then
113 echo "[FAIL]" 122 echo "[FAIL]"
114 exitcode=1 123 exitcode=1
diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests/x86/Makefile
index 10ca46df1449..d744991c0f4f 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -5,16 +5,26 @@ include ../lib.mk
5 5
6.PHONY: all all_32 all_64 warn_32bit_failure clean 6.PHONY: all all_32 all_64 warn_32bit_failure clean
7 7
8TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_syscall test_mremap_vdso \ 8UNAME_M := $(shell uname -m)
9 check_initial_reg_state sigreturn ldt_gdt iopl mpx-mini-test ioperm \ 9CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
10CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
11
12TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \
13 check_initial_reg_state sigreturn iopl mpx-mini-test ioperm \
10 protection_keys test_vdso test_vsyscall 14 protection_keys test_vdso test_vsyscall
11TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \ 15TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
12 test_FCMOV test_FCOMI test_FISTTP \ 16 test_FCMOV test_FCOMI test_FISTTP \
13 vdso_restorer 17 vdso_restorer
14TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip 5lvl 18TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
19# Some selftests require 32bit support enabled also on 64bit systems
20TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
15 21
16TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) 22TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED)
17TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY) 23TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
24ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11)
25TARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED)
26endif
27
18BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32) 28BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
19BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64) 29BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
20 30
@@ -23,10 +33,6 @@ BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
23 33
24CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie 34CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie
25 35
26UNAME_M := $(shell uname -m)
27CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
28CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
29
30define gen-target-rule-32 36define gen-target-rule-32
31$(1) $(1)_32: $(OUTPUT)/$(1)_32 37$(1) $(1)_32: $(OUTPUT)/$(1)_32
32.PHONY: $(1) $(1)_32 38.PHONY: $(1) $(1)_32
@@ -40,12 +46,14 @@ endef
40ifeq ($(CAN_BUILD_I386),1) 46ifeq ($(CAN_BUILD_I386),1)
41all: all_32 47all: all_32
42TEST_PROGS += $(BINARIES_32) 48TEST_PROGS += $(BINARIES_32)
49EXTRA_CFLAGS += -DCAN_BUILD_32
43$(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t)))) 50$(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t))))
44endif 51endif
45 52
46ifeq ($(CAN_BUILD_X86_64),1) 53ifeq ($(CAN_BUILD_X86_64),1)
47all: all_64 54all: all_64
48TEST_PROGS += $(BINARIES_64) 55TEST_PROGS += $(BINARIES_64)
56EXTRA_CFLAGS += -DCAN_BUILD_64
49$(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t)))) 57$(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t))))
50endif 58endif
51 59
diff --git a/tools/testing/selftests/x86/entry_from_vm86.c b/tools/testing/selftests/x86/entry_from_vm86.c
index 361466a2eaef..ade443a88421 100644
--- a/tools/testing/selftests/x86/entry_from_vm86.c
+++ b/tools/testing/selftests/x86/entry_from_vm86.c
@@ -95,6 +95,10 @@ asm (
95 "int3\n\t" 95 "int3\n\t"
96 "vmcode_int80:\n\t" 96 "vmcode_int80:\n\t"
97 "int $0x80\n\t" 97 "int $0x80\n\t"
98 "vmcode_popf_hlt:\n\t"
99 "push %ax\n\t"
100 "popf\n\t"
101 "hlt\n\t"
98 "vmcode_umip:\n\t" 102 "vmcode_umip:\n\t"
99 /* addressing via displacements */ 103 /* addressing via displacements */
100 "smsw (2052)\n\t" 104 "smsw (2052)\n\t"
@@ -124,8 +128,8 @@ asm (
124 128
125extern unsigned char vmcode[], end_vmcode[]; 129extern unsigned char vmcode[], end_vmcode[];
126extern unsigned char vmcode_bound[], vmcode_sysenter[], vmcode_syscall[], 130extern unsigned char vmcode_bound[], vmcode_sysenter[], vmcode_syscall[],
127 vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_umip[], 131 vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_popf_hlt[],
128 vmcode_umip_str[], vmcode_umip_sldt[]; 132 vmcode_umip[], vmcode_umip_str[], vmcode_umip_sldt[];
129 133
130/* Returns false if the test was skipped. */ 134/* Returns false if the test was skipped. */
131static bool do_test(struct vm86plus_struct *v86, unsigned long eip, 135static bool do_test(struct vm86plus_struct *v86, unsigned long eip,
@@ -175,7 +179,7 @@ static bool do_test(struct vm86plus_struct *v86, unsigned long eip,
175 (VM86_TYPE(ret) == rettype && VM86_ARG(ret) == retarg)) { 179 (VM86_TYPE(ret) == rettype && VM86_ARG(ret) == retarg)) {
176 printf("[OK]\tReturned correctly\n"); 180 printf("[OK]\tReturned correctly\n");
177 } else { 181 } else {
178 printf("[FAIL]\tIncorrect return reason\n"); 182 printf("[FAIL]\tIncorrect return reason (started at eip = 0x%lx, ended at eip = 0x%lx)\n", eip, v86->regs.eip);
179 nerrs++; 183 nerrs++;
180 } 184 }
181 185
@@ -264,6 +268,9 @@ int main(void)
264 v86.regs.ds = load_addr / 16; 268 v86.regs.ds = load_addr / 16;
265 v86.regs.es = load_addr / 16; 269 v86.regs.es = load_addr / 16;
266 270
271 /* Use the end of the page as our stack. */
272 v86.regs.esp = 4096;
273
267 assert((v86.regs.cs & 3) == 0); /* Looks like RPL = 0 */ 274 assert((v86.regs.cs & 3) == 0); /* Looks like RPL = 0 */
268 275
269 /* #BR -- should deliver SIG??? */ 276 /* #BR -- should deliver SIG??? */
@@ -295,6 +302,23 @@ int main(void)
295 v86.regs.eflags &= ~X86_EFLAGS_IF; 302 v86.regs.eflags &= ~X86_EFLAGS_IF;
296 do_test(&v86, vmcode_sti - vmcode, VM86_STI, 0, "STI with VIP set"); 303 do_test(&v86, vmcode_sti - vmcode, VM86_STI, 0, "STI with VIP set");
297 304
305 /* POPF with VIP set but IF clear: should not trap */
306 v86.regs.eflags = X86_EFLAGS_VIP;
307 v86.regs.eax = 0;
308 do_test(&v86, vmcode_popf_hlt - vmcode, VM86_UNKNOWN, 0, "POPF with VIP set and IF clear");
309
310 /* POPF with VIP set and IF set: should trap */
311 v86.regs.eflags = X86_EFLAGS_VIP;
312 v86.regs.eax = X86_EFLAGS_IF;
313 do_test(&v86, vmcode_popf_hlt - vmcode, VM86_STI, 0, "POPF with VIP and IF set");
314
315 /* POPF with VIP clear and IF set: should not trap */
316 v86.regs.eflags = 0;
317 v86.regs.eax = X86_EFLAGS_IF;
318 do_test(&v86, vmcode_popf_hlt - vmcode, VM86_UNKNOWN, 0, "POPF with VIP clear and IF set");
319
320 v86.regs.eflags = 0;
321
298 /* INT3 -- should cause #BP */ 322 /* INT3 -- should cause #BP */
299 do_test(&v86, vmcode_int3 - vmcode, VM86_TRAP, 3, "INT3"); 323 do_test(&v86, vmcode_int3 - vmcode, VM86_TRAP, 3, "INT3");
300 324
@@ -318,7 +342,7 @@ int main(void)
318 clearhandler(SIGSEGV); 342 clearhandler(SIGSEGV);
319 343
320 /* Make sure nothing explodes if we fork. */ 344 /* Make sure nothing explodes if we fork. */
321 if (fork() > 0) 345 if (fork() == 0)
322 return 0; 346 return 0;
323 347
324 return (nerrs == 0 ? 0 : 1); 348 return (nerrs == 0 ? 0 : 1);
diff --git a/tools/testing/selftests/x86/mpx-mini-test.c b/tools/testing/selftests/x86/mpx-mini-test.c
index ec0f6b45ce8b..9c0325e1ea68 100644
--- a/tools/testing/selftests/x86/mpx-mini-test.c
+++ b/tools/testing/selftests/x86/mpx-mini-test.c
@@ -315,11 +315,39 @@ static inline void *__si_bounds_upper(siginfo_t *si)
315 return si->si_upper; 315 return si->si_upper;
316} 316}
317#else 317#else
318
319/*
320 * This deals with old version of _sigfault in some distros:
321 *
322
323old _sigfault:
324 struct {
325 void *si_addr;
326 } _sigfault;
327
328new _sigfault:
329 struct {
330 void __user *_addr;
331 int _trapno;
332 short _addr_lsb;
333 union {
334 struct {
335 void __user *_lower;
336 void __user *_upper;
337 } _addr_bnd;
338 __u32 _pkey;
339 };
340 } _sigfault;
341 *
342 */
343
318static inline void **__si_bounds_hack(siginfo_t *si) 344static inline void **__si_bounds_hack(siginfo_t *si)
319{ 345{
320 void *sigfault = &si->_sifields._sigfault; 346 void *sigfault = &si->_sifields._sigfault;
321 void *end_sigfault = sigfault + sizeof(si->_sifields._sigfault); 347 void *end_sigfault = sigfault + sizeof(si->_sifields._sigfault);
322 void **__si_lower = end_sigfault; 348 int *trapno = (int*)end_sigfault;
349 /* skip _trapno and _addr_lsb */
350 void **__si_lower = (void**)(trapno + 2);
323 351
324 return __si_lower; 352 return __si_lower;
325} 353}
@@ -331,7 +359,7 @@ static inline void *__si_bounds_lower(siginfo_t *si)
331 359
332static inline void *__si_bounds_upper(siginfo_t *si) 360static inline void *__si_bounds_upper(siginfo_t *si)
333{ 361{
334 return (*__si_bounds_hack(si)) + sizeof(void *); 362 return *(__si_bounds_hack(si) + 1);
335} 363}
336#endif 364#endif
337 365
diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c
index bc1b0735bb50..f15aa5a76fe3 100644
--- a/tools/testing/selftests/x86/protection_keys.c
+++ b/tools/testing/selftests/x86/protection_keys.c
@@ -393,34 +393,6 @@ pid_t fork_lazy_child(void)
393 return forkret; 393 return forkret;
394} 394}
395 395
396void davecmp(void *_a, void *_b, int len)
397{
398 int i;
399 unsigned long *a = _a;
400 unsigned long *b = _b;
401
402 for (i = 0; i < len / sizeof(*a); i++) {
403 if (a[i] == b[i])
404 continue;
405
406 dprintf3("[%3d]: a: %016lx b: %016lx\n", i, a[i], b[i]);
407 }
408}
409
410void dumpit(char *f)
411{
412 int fd = open(f, O_RDONLY);
413 char buf[100];
414 int nr_read;
415
416 dprintf2("maps fd: %d\n", fd);
417 do {
418 nr_read = read(fd, &buf[0], sizeof(buf));
419 write(1, buf, nr_read);
420 } while (nr_read > 0);
421 close(fd);
422}
423
424#define PKEY_DISABLE_ACCESS 0x1 396#define PKEY_DISABLE_ACCESS 0x1
425#define PKEY_DISABLE_WRITE 0x2 397#define PKEY_DISABLE_WRITE 0x2
426 398
diff --git a/tools/testing/selftests/x86/ptrace_syscall.c b/tools/testing/selftests/x86/ptrace_syscall.c
index 1ae1c5a7392e..6f22238f3217 100644
--- a/tools/testing/selftests/x86/ptrace_syscall.c
+++ b/tools/testing/selftests/x86/ptrace_syscall.c
@@ -183,8 +183,10 @@ static void test_ptrace_syscall_restart(void)
183 if (ptrace(PTRACE_TRACEME, 0, 0, 0) != 0) 183 if (ptrace(PTRACE_TRACEME, 0, 0, 0) != 0)
184 err(1, "PTRACE_TRACEME"); 184 err(1, "PTRACE_TRACEME");
185 185
186 pid_t pid = getpid(), tid = syscall(SYS_gettid);
187
186 printf("\tChild will make one syscall\n"); 188 printf("\tChild will make one syscall\n");
187 raise(SIGSTOP); 189 syscall(SYS_tgkill, pid, tid, SIGSTOP);
188 190
189 syscall(SYS_gettid, 10, 11, 12, 13, 14, 15); 191 syscall(SYS_gettid, 10, 11, 12, 13, 14, 15);
190 _exit(0); 192 _exit(0);
@@ -301,9 +303,11 @@ static void test_restart_under_ptrace(void)
301 if (ptrace(PTRACE_TRACEME, 0, 0, 0) != 0) 303 if (ptrace(PTRACE_TRACEME, 0, 0, 0) != 0)
302 err(1, "PTRACE_TRACEME"); 304 err(1, "PTRACE_TRACEME");
303 305
306 pid_t pid = getpid(), tid = syscall(SYS_gettid);
307
304 printf("\tChild will take a nap until signaled\n"); 308 printf("\tChild will take a nap until signaled\n");
305 setsigign(SIGUSR1, SA_RESTART); 309 setsigign(SIGUSR1, SA_RESTART);
306 raise(SIGSTOP); 310 syscall(SYS_tgkill, pid, tid, SIGSTOP);
307 311
308 syscall(SYS_pause, 0, 0, 0, 0, 0, 0); 312 syscall(SYS_pause, 0, 0, 0, 0, 0, 0);
309 _exit(0); 313 _exit(0);
diff --git a/tools/testing/selftests/x86/single_step_syscall.c b/tools/testing/selftests/x86/single_step_syscall.c
index a48da95c18fd..ddfdd635de16 100644
--- a/tools/testing/selftests/x86/single_step_syscall.c
+++ b/tools/testing/selftests/x86/single_step_syscall.c
@@ -119,7 +119,9 @@ static void check_result(void)
119 119
120int main() 120int main()
121{ 121{
122#ifdef CAN_BUILD_32
122 int tmp; 123 int tmp;
124#endif
123 125
124 sethandler(SIGTRAP, sigtrap, 0); 126 sethandler(SIGTRAP, sigtrap, 0);
125 127
@@ -139,12 +141,13 @@ int main()
139 : : "c" (post_nop) : "r11"); 141 : : "c" (post_nop) : "r11");
140 check_result(); 142 check_result();
141#endif 143#endif
142 144#ifdef CAN_BUILD_32
143 printf("[RUN]\tSet TF and check int80\n"); 145 printf("[RUN]\tSet TF and check int80\n");
144 set_eflags(get_eflags() | X86_EFLAGS_TF); 146 set_eflags(get_eflags() | X86_EFLAGS_TF);
145 asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid) 147 asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid)
146 : INT80_CLOBBERS); 148 : INT80_CLOBBERS);
147 check_result(); 149 check_result();
150#endif
148 151
149 /* 152 /*
150 * This test is particularly interesting if fast syscalls use 153 * This test is particularly interesting if fast syscalls use
diff --git a/tools/testing/selftests/x86/test_mremap_vdso.c b/tools/testing/selftests/x86/test_mremap_vdso.c
index bf0d687c7db7..64f11c8d9b76 100644
--- a/tools/testing/selftests/x86/test_mremap_vdso.c
+++ b/tools/testing/selftests/x86/test_mremap_vdso.c
@@ -90,8 +90,12 @@ int main(int argc, char **argv, char **envp)
90 vdso_size += PAGE_SIZE; 90 vdso_size += PAGE_SIZE;
91 } 91 }
92 92
93#ifdef __i386__
93 /* Glibc is likely to explode now - exit with raw syscall */ 94 /* Glibc is likely to explode now - exit with raw syscall */
94 asm volatile ("int $0x80" : : "a" (__NR_exit), "b" (!!ret)); 95 asm volatile ("int $0x80" : : "a" (__NR_exit), "b" (!!ret));
96#else /* __x86_64__ */
97 syscall(SYS_exit, ret);
98#endif
95 } else { 99 } else {
96 int status; 100 int status;
97 101
diff --git a/tools/testing/selftests/x86/test_vdso.c b/tools/testing/selftests/x86/test_vdso.c
index 29973cde06d3..235259011704 100644
--- a/tools/testing/selftests/x86/test_vdso.c
+++ b/tools/testing/selftests/x86/test_vdso.c
@@ -26,20 +26,59 @@
26# endif 26# endif
27#endif 27#endif
28 28
29/* max length of lines in /proc/self/maps - anything longer is skipped here */
30#define MAPS_LINE_LEN 128
31
29int nerrs = 0; 32int nerrs = 0;
30 33
34typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
35
36getcpu_t vgetcpu;
37getcpu_t vdso_getcpu;
38
39static void *vsyscall_getcpu(void)
40{
31#ifdef __x86_64__ 41#ifdef __x86_64__
32# define VSYS(x) (x) 42 FILE *maps;
43 char line[MAPS_LINE_LEN];
44 bool found = false;
45
46 maps = fopen("/proc/self/maps", "r");
47 if (!maps) /* might still be present, but ignore it here, as we test vDSO not vsyscall */
48 return NULL;
49
50 while (fgets(line, MAPS_LINE_LEN, maps)) {
51 char r, x;
52 void *start, *end;
53 char name[MAPS_LINE_LEN];
54
55 /* sscanf() is safe here as strlen(name) >= strlen(line) */
56 if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
57 &start, &end, &r, &x, name) != 5)
58 continue;
59
60 if (strcmp(name, "[vsyscall]"))
61 continue;
62
63 /* assume entries are OK, as we test vDSO here not vsyscall */
64 found = true;
65 break;
66 }
67
68 fclose(maps);
69
70 if (!found) {
71 printf("Warning: failed to find vsyscall getcpu\n");
72 return NULL;
73 }
74 return (void *) (0xffffffffff600800);
33#else 75#else
34# define VSYS(x) 0 76 return NULL;
35#endif 77#endif
78}
36 79
37typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
38
39const getcpu_t vgetcpu = (getcpu_t)VSYS(0xffffffffff600800);
40getcpu_t vdso_getcpu;
41 80
42void fill_function_pointers() 81static void fill_function_pointers()
43{ 82{
44 void *vdso = dlopen("linux-vdso.so.1", 83 void *vdso = dlopen("linux-vdso.so.1",
45 RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD); 84 RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
@@ -54,6 +93,8 @@ void fill_function_pointers()
54 vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu"); 93 vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu");
55 if (!vdso_getcpu) 94 if (!vdso_getcpu)
56 printf("Warning: failed to find getcpu in vDSO\n"); 95 printf("Warning: failed to find getcpu in vDSO\n");
96
97 vgetcpu = (getcpu_t) vsyscall_getcpu();
57} 98}
58 99
59static long sys_getcpu(unsigned * cpu, unsigned * node, 100static long sys_getcpu(unsigned * cpu, unsigned * node,
diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/selftests/x86/test_vsyscall.c
index 7a744fa7b786..0b4f1cc2291c 100644
--- a/tools/testing/selftests/x86/test_vsyscall.c
+++ b/tools/testing/selftests/x86/test_vsyscall.c
@@ -33,6 +33,9 @@
33# endif 33# endif
34#endif 34#endif
35 35
36/* max length of lines in /proc/self/maps - anything longer is skipped here */
37#define MAPS_LINE_LEN 128
38
36static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *), 39static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
37 int flags) 40 int flags)
38{ 41{
@@ -98,7 +101,7 @@ static int init_vsys(void)
98#ifdef __x86_64__ 101#ifdef __x86_64__
99 int nerrs = 0; 102 int nerrs = 0;
100 FILE *maps; 103 FILE *maps;
101 char line[128]; 104 char line[MAPS_LINE_LEN];
102 bool found = false; 105 bool found = false;
103 106
104 maps = fopen("/proc/self/maps", "r"); 107 maps = fopen("/proc/self/maps", "r");
@@ -108,10 +111,12 @@ static int init_vsys(void)
108 return 0; 111 return 0;
109 } 112 }
110 113
111 while (fgets(line, sizeof(line), maps)) { 114 while (fgets(line, MAPS_LINE_LEN, maps)) {
112 char r, x; 115 char r, x;
113 void *start, *end; 116 void *start, *end;
114 char name[128]; 117 char name[MAPS_LINE_LEN];
118
119 /* sscanf() is safe here as strlen(name) >= strlen(line) */
115 if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s", 120 if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
116 &start, &end, &r, &x, name) != 5) 121 &start, &end, &r, &x, name) != 5)
117 continue; 122 continue;
@@ -445,7 +450,7 @@ static void sigtrap(int sig, siginfo_t *info, void *ctx_void)
445 num_vsyscall_traps++; 450 num_vsyscall_traps++;
446} 451}
447 452
448static int test_native_vsyscall(void) 453static int test_emulation(void)
449{ 454{
450 time_t tmp; 455 time_t tmp;
451 bool is_native; 456 bool is_native;
@@ -453,7 +458,7 @@ static int test_native_vsyscall(void)
453 if (!vtime) 458 if (!vtime)
454 return 0; 459 return 0;
455 460
456 printf("[RUN]\tchecking for native vsyscall\n"); 461 printf("[RUN]\tchecking that vsyscalls are emulated\n");
457 sethandler(SIGTRAP, sigtrap, 0); 462 sethandler(SIGTRAP, sigtrap, 0);
458 set_eflags(get_eflags() | X86_EFLAGS_TF); 463 set_eflags(get_eflags() | X86_EFLAGS_TF);
459 vtime(&tmp); 464 vtime(&tmp);
@@ -469,11 +474,12 @@ static int test_native_vsyscall(void)
469 */ 474 */
470 is_native = (num_vsyscall_traps > 1); 475 is_native = (num_vsyscall_traps > 1);
471 476
472 printf("\tvsyscalls are %s (%d instructions in vsyscall page)\n", 477 printf("[%s]\tvsyscalls are %s (%d instructions in vsyscall page)\n",
478 (is_native ? "FAIL" : "OK"),
473 (is_native ? "native" : "emulated"), 479 (is_native ? "native" : "emulated"),
474 (int)num_vsyscall_traps); 480 (int)num_vsyscall_traps);
475 481
476 return 0; 482 return is_native;
477} 483}
478#endif 484#endif
479 485
@@ -493,7 +499,7 @@ int main(int argc, char **argv)
493 nerrs += test_vsys_r(); 499 nerrs += test_vsys_r();
494 500
495#ifdef __x86_64__ 501#ifdef __x86_64__
496 nerrs += test_native_vsyscall(); 502 nerrs += test_emulation();
497#endif 503#endif
498 504
499 return nerrs ? 1 : 0; 505 return nerrs ? 1 : 0;
diff --git a/tools/usb/Makefile b/tools/usb/Makefile
index 4e6506078494..01d758d73b6d 100644
--- a/tools/usb/Makefile
+++ b/tools/usb/Makefile
@@ -1,7 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2# Makefile for USB tools 2# Makefile for USB tools
3 3
4CC = $(CROSS_COMPILE)gcc
5PTHREAD_LIBS = -lpthread 4PTHREAD_LIBS = -lpthread
6WARNINGS = -Wall -Wextra 5WARNINGS = -Wall -Wextra
7CFLAGS = $(WARNINGS) -g -I../include 6CFLAGS = $(WARNINGS) -g -I../include
diff --git a/tools/vm/Makefile b/tools/vm/Makefile
index be320b905ea7..20f6cf04377f 100644
--- a/tools/vm/Makefile
+++ b/tools/vm/Makefile
@@ -6,7 +6,6 @@ TARGETS=page-types slabinfo page_owner_sort
6LIB_DIR = ../lib/api 6LIB_DIR = ../lib/api
7LIBS = $(LIB_DIR)/libapi.a 7LIBS = $(LIB_DIR)/libapi.a
8 8
9CC = $(CROSS_COMPILE)gcc
10CFLAGS = -Wall -Wextra -I../lib/ 9CFLAGS = -Wall -Wextra -I../lib/
11LDFLAGS = $(LIBS) 10LDFLAGS = $(LIBS)
12 11
diff --git a/tools/wmi/Makefile b/tools/wmi/Makefile
index e664f1167388..e0e87239126b 100644
--- a/tools/wmi/Makefile
+++ b/tools/wmi/Makefile
@@ -2,7 +2,6 @@ PREFIX ?= /usr
2SBINDIR ?= sbin 2SBINDIR ?= sbin
3INSTALL ?= install 3INSTALL ?= install
4CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include 4CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
5CC = $(CROSS_COMPILE)gcc
6 5
7TARGET = dell-smbios-example 6TARGET = dell-smbios-example
8 7
diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
index 70268c0bec79..282389eb204f 100644
--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -36,6 +36,8 @@ static struct timecounter *timecounter;
36static unsigned int host_vtimer_irq; 36static unsigned int host_vtimer_irq;
37static u32 host_vtimer_irq_flags; 37static u32 host_vtimer_irq_flags;
38 38
39static DEFINE_STATIC_KEY_FALSE(has_gic_active_state);
40
39static const struct kvm_irq_level default_ptimer_irq = { 41static const struct kvm_irq_level default_ptimer_irq = {
40 .irq = 30, 42 .irq = 30,
41 .level = 1, 43 .level = 1,
@@ -56,6 +58,12 @@ u64 kvm_phys_timer_read(void)
56 return timecounter->cc->read(timecounter->cc); 58 return timecounter->cc->read(timecounter->cc);
57} 59}
58 60
61static inline bool userspace_irqchip(struct kvm *kvm)
62{
63 return static_branch_unlikely(&userspace_irqchip_in_use) &&
64 unlikely(!irqchip_in_kernel(kvm));
65}
66
59static void soft_timer_start(struct hrtimer *hrt, u64 ns) 67static void soft_timer_start(struct hrtimer *hrt, u64 ns)
60{ 68{
61 hrtimer_start(hrt, ktime_add_ns(ktime_get(), ns), 69 hrtimer_start(hrt, ktime_add_ns(ktime_get(), ns),
@@ -69,25 +77,6 @@ static void soft_timer_cancel(struct hrtimer *hrt, struct work_struct *work)
69 cancel_work_sync(work); 77 cancel_work_sync(work);
70} 78}
71 79
72static void kvm_vtimer_update_mask_user(struct kvm_vcpu *vcpu)
73{
74 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
75
76 /*
77 * When using a userspace irqchip with the architected timers, we must
78 * prevent continuously exiting from the guest, and therefore mask the
79 * physical interrupt by disabling it on the host interrupt controller
80 * when the virtual level is high, such that the guest can make
81 * forward progress. Once we detect the output level being
82 * de-asserted, we unmask the interrupt again so that we exit from the
83 * guest when the timer fires.
84 */
85 if (vtimer->irq.level)
86 disable_percpu_irq(host_vtimer_irq);
87 else
88 enable_percpu_irq(host_vtimer_irq, 0);
89}
90
91static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id) 80static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id)
92{ 81{
93 struct kvm_vcpu *vcpu = *(struct kvm_vcpu **)dev_id; 82 struct kvm_vcpu *vcpu = *(struct kvm_vcpu **)dev_id;
@@ -106,9 +95,9 @@ static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id)
106 if (kvm_timer_should_fire(vtimer)) 95 if (kvm_timer_should_fire(vtimer))
107 kvm_timer_update_irq(vcpu, true, vtimer); 96 kvm_timer_update_irq(vcpu, true, vtimer);
108 97
109 if (static_branch_unlikely(&userspace_irqchip_in_use) && 98 if (userspace_irqchip(vcpu->kvm) &&
110 unlikely(!irqchip_in_kernel(vcpu->kvm))) 99 !static_branch_unlikely(&has_gic_active_state))
111 kvm_vtimer_update_mask_user(vcpu); 100 disable_percpu_irq(host_vtimer_irq);
112 101
113 return IRQ_HANDLED; 102 return IRQ_HANDLED;
114} 103}
@@ -290,8 +279,7 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level,
290 trace_kvm_timer_update_irq(vcpu->vcpu_id, timer_ctx->irq.irq, 279 trace_kvm_timer_update_irq(vcpu->vcpu_id, timer_ctx->irq.irq,
291 timer_ctx->irq.level); 280 timer_ctx->irq.level);
292 281
293 if (!static_branch_unlikely(&userspace_irqchip_in_use) || 282 if (!userspace_irqchip(vcpu->kvm)) {
294 likely(irqchip_in_kernel(vcpu->kvm))) {
295 ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id, 283 ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id,
296 timer_ctx->irq.irq, 284 timer_ctx->irq.irq,
297 timer_ctx->irq.level, 285 timer_ctx->irq.level,
@@ -350,12 +338,6 @@ static void kvm_timer_update_state(struct kvm_vcpu *vcpu)
350 phys_timer_emulate(vcpu); 338 phys_timer_emulate(vcpu);
351} 339}
352 340
353static void __timer_snapshot_state(struct arch_timer_context *timer)
354{
355 timer->cnt_ctl = read_sysreg_el0(cntv_ctl);
356 timer->cnt_cval = read_sysreg_el0(cntv_cval);
357}
358
359static void vtimer_save_state(struct kvm_vcpu *vcpu) 341static void vtimer_save_state(struct kvm_vcpu *vcpu)
360{ 342{
361 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 343 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
@@ -367,8 +349,10 @@ static void vtimer_save_state(struct kvm_vcpu *vcpu)
367 if (!vtimer->loaded) 349 if (!vtimer->loaded)
368 goto out; 350 goto out;
369 351
370 if (timer->enabled) 352 if (timer->enabled) {
371 __timer_snapshot_state(vtimer); 353 vtimer->cnt_ctl = read_sysreg_el0(cntv_ctl);
354 vtimer->cnt_cval = read_sysreg_el0(cntv_cval);
355 }
372 356
373 /* Disable the virtual timer */ 357 /* Disable the virtual timer */
374 write_sysreg_el0(0, cntv_ctl); 358 write_sysreg_el0(0, cntv_ctl);
@@ -460,23 +444,43 @@ static void set_cntvoff(u64 cntvoff)
460 kvm_call_hyp(__kvm_timer_set_cntvoff, low, high); 444 kvm_call_hyp(__kvm_timer_set_cntvoff, low, high);
461} 445}
462 446
463static void kvm_timer_vcpu_load_vgic(struct kvm_vcpu *vcpu) 447static inline void set_vtimer_irq_phys_active(struct kvm_vcpu *vcpu, bool active)
448{
449 int r;
450 r = irq_set_irqchip_state(host_vtimer_irq, IRQCHIP_STATE_ACTIVE, active);
451 WARN_ON(r);
452}
453
454static void kvm_timer_vcpu_load_gic(struct kvm_vcpu *vcpu)
464{ 455{
465 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 456 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
466 bool phys_active; 457 bool phys_active;
467 int ret;
468
469 phys_active = kvm_vgic_map_is_active(vcpu, vtimer->irq.irq);
470 458
471 ret = irq_set_irqchip_state(host_vtimer_irq, 459 if (irqchip_in_kernel(vcpu->kvm))
472 IRQCHIP_STATE_ACTIVE, 460 phys_active = kvm_vgic_map_is_active(vcpu, vtimer->irq.irq);
473 phys_active); 461 else
474 WARN_ON(ret); 462 phys_active = vtimer->irq.level;
463 set_vtimer_irq_phys_active(vcpu, phys_active);
475} 464}
476 465
477static void kvm_timer_vcpu_load_user(struct kvm_vcpu *vcpu) 466static void kvm_timer_vcpu_load_nogic(struct kvm_vcpu *vcpu)
478{ 467{
479 kvm_vtimer_update_mask_user(vcpu); 468 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
469
470 /*
471 * When using a userspace irqchip with the architected timers and a
472 * host interrupt controller that doesn't support an active state, we
473 * must still prevent continuously exiting from the guest, and
474 * therefore mask the physical interrupt by disabling it on the host
475 * interrupt controller when the virtual level is high, such that the
476 * guest can make forward progress. Once we detect the output level
477 * being de-asserted, we unmask the interrupt again so that we exit
478 * from the guest when the timer fires.
479 */
480 if (vtimer->irq.level)
481 disable_percpu_irq(host_vtimer_irq);
482 else
483 enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags);
480} 484}
481 485
482void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu) 486void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu)
@@ -487,10 +491,10 @@ void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu)
487 if (unlikely(!timer->enabled)) 491 if (unlikely(!timer->enabled))
488 return; 492 return;
489 493
490 if (unlikely(!irqchip_in_kernel(vcpu->kvm))) 494 if (static_branch_likely(&has_gic_active_state))
491 kvm_timer_vcpu_load_user(vcpu); 495 kvm_timer_vcpu_load_gic(vcpu);
492 else 496 else
493 kvm_timer_vcpu_load_vgic(vcpu); 497 kvm_timer_vcpu_load_nogic(vcpu);
494 498
495 set_cntvoff(vtimer->cntvoff); 499 set_cntvoff(vtimer->cntvoff);
496 500
@@ -555,22 +559,29 @@ static void unmask_vtimer_irq_user(struct kvm_vcpu *vcpu)
555{ 559{
556 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 560 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
557 561
558 if (unlikely(!irqchip_in_kernel(vcpu->kvm))) { 562 if (!kvm_timer_should_fire(vtimer)) {
559 __timer_snapshot_state(vtimer); 563 kvm_timer_update_irq(vcpu, false, vtimer);
560 if (!kvm_timer_should_fire(vtimer)) { 564 if (static_branch_likely(&has_gic_active_state))
561 kvm_timer_update_irq(vcpu, false, vtimer); 565 set_vtimer_irq_phys_active(vcpu, false);
562 kvm_vtimer_update_mask_user(vcpu); 566 else
563 } 567 enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags);
564 } 568 }
565} 569}
566 570
567void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) 571void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu)
568{ 572{
569 unmask_vtimer_irq_user(vcpu); 573 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
574
575 if (unlikely(!timer->enabled))
576 return;
577
578 if (unlikely(!irqchip_in_kernel(vcpu->kvm)))
579 unmask_vtimer_irq_user(vcpu);
570} 580}
571 581
572int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu) 582int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu)
573{ 583{
584 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
574 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 585 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
575 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); 586 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
576 587
@@ -584,6 +595,9 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu)
584 ptimer->cnt_ctl = 0; 595 ptimer->cnt_ctl = 0;
585 kvm_timer_update_state(vcpu); 596 kvm_timer_update_state(vcpu);
586 597
598 if (timer->enabled && irqchip_in_kernel(vcpu->kvm))
599 kvm_vgic_reset_mapped_irq(vcpu, vtimer->irq.irq);
600
587 return 0; 601 return 0;
588} 602}
589 603
@@ -753,9 +767,11 @@ int kvm_timer_hyp_init(bool has_gic)
753 kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); 767 kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
754 goto out_free_irq; 768 goto out_free_irq;
755 } 769 }
770
771 static_branch_enable(&has_gic_active_state);
756 } 772 }
757 773
758 kvm_info("virtual timer IRQ%d\n", host_vtimer_irq); 774 kvm_debug("virtual timer IRQ%d\n", host_vtimer_irq);
759 775
760 cpuhp_setup_state(CPUHP_AP_KVM_ARM_TIMER_STARTING, 776 cpuhp_setup_state(CPUHP_AP_KVM_ARM_TIMER_STARTING,
761 "kvm/arm/timer:starting", kvm_timer_starting_cpu, 777 "kvm/arm/timer:starting", kvm_timer_starting_cpu,
diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
index 86941f6181bb..53572304843b 100644
--- a/virt/kvm/arm/arm.c
+++ b/virt/kvm/arm/arm.c
@@ -384,14 +384,11 @@ static void vcpu_power_off(struct kvm_vcpu *vcpu)
384int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, 384int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
385 struct kvm_mp_state *mp_state) 385 struct kvm_mp_state *mp_state)
386{ 386{
387 vcpu_load(vcpu);
388
389 if (vcpu->arch.power_off) 387 if (vcpu->arch.power_off)
390 mp_state->mp_state = KVM_MP_STATE_STOPPED; 388 mp_state->mp_state = KVM_MP_STATE_STOPPED;
391 else 389 else
392 mp_state->mp_state = KVM_MP_STATE_RUNNABLE; 390 mp_state->mp_state = KVM_MP_STATE_RUNNABLE;
393 391
394 vcpu_put(vcpu);
395 return 0; 392 return 0;
396} 393}
397 394
@@ -400,8 +397,6 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
400{ 397{
401 int ret = 0; 398 int ret = 0;
402 399
403 vcpu_load(vcpu);
404
405 switch (mp_state->mp_state) { 400 switch (mp_state->mp_state) {
406 case KVM_MP_STATE_RUNNABLE: 401 case KVM_MP_STATE_RUNNABLE:
407 vcpu->arch.power_off = false; 402 vcpu->arch.power_off = false;
@@ -413,7 +408,6 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
413 ret = -EINVAL; 408 ret = -EINVAL;
414 } 409 }
415 410
416 vcpu_put(vcpu);
417 return ret; 411 return ret;
418} 412}
419 413
@@ -1036,8 +1030,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
1036 struct kvm_device_attr attr; 1030 struct kvm_device_attr attr;
1037 long r; 1031 long r;
1038 1032
1039 vcpu_load(vcpu);
1040
1041 switch (ioctl) { 1033 switch (ioctl) {
1042 case KVM_ARM_VCPU_INIT: { 1034 case KVM_ARM_VCPU_INIT: {
1043 struct kvm_vcpu_init init; 1035 struct kvm_vcpu_init init;
@@ -1114,7 +1106,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
1114 r = -EINVAL; 1106 r = -EINVAL;
1115 } 1107 }
1116 1108
1117 vcpu_put(vcpu);
1118 return r; 1109 return r;
1119} 1110}
1120 1111
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index f5c3d6d7019e..b89ce5432214 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -215,7 +215,8 @@ void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu)
215 * are now visible to the system register interface. 215 * are now visible to the system register interface.
216 */ 216 */
217 if (!cpu_if->vgic_sre) { 217 if (!cpu_if->vgic_sre) {
218 dsb(st); 218 dsb(sy);
219 isb();
219 cpu_if->vgic_vmcr = read_gicreg(ICH_VMCR_EL2); 220 cpu_if->vgic_vmcr = read_gicreg(ICH_VMCR_EL2);
220 } 221 }
221 222
diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
index ec62d1cccab7..b960acdd0c05 100644
--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -1810,9 +1810,9 @@ int kvm_mmu_init(void)
1810 */ 1810 */
1811 BUG_ON((hyp_idmap_start ^ (hyp_idmap_end - 1)) & PAGE_MASK); 1811 BUG_ON((hyp_idmap_start ^ (hyp_idmap_end - 1)) & PAGE_MASK);
1812 1812
1813 kvm_info("IDMAP page: %lx\n", hyp_idmap_start); 1813 kvm_debug("IDMAP page: %lx\n", hyp_idmap_start);
1814 kvm_info("HYP VA range: %lx:%lx\n", 1814 kvm_debug("HYP VA range: %lx:%lx\n",
1815 kern_hyp_va(PAGE_OFFSET), kern_hyp_va(~0UL)); 1815 kern_hyp_va(PAGE_OFFSET), kern_hyp_va(~0UL));
1816 1816
1817 if (hyp_idmap_start >= kern_hyp_va(PAGE_OFFSET) && 1817 if (hyp_idmap_start >= kern_hyp_va(PAGE_OFFSET) &&
1818 hyp_idmap_start < kern_hyp_va(~0UL) && 1818 hyp_idmap_start < kern_hyp_va(~0UL) &&
diff --git a/virt/kvm/arm/vgic/vgic-mmio.c b/virt/kvm/arm/vgic/vgic-mmio.c
index 83d82bd7dc4e..dbe99d635c80 100644
--- a/virt/kvm/arm/vgic/vgic-mmio.c
+++ b/virt/kvm/arm/vgic/vgic-mmio.c
@@ -113,9 +113,12 @@ unsigned long vgic_mmio_read_pending(struct kvm_vcpu *vcpu,
113 /* Loop over all IRQs affected by this read */ 113 /* Loop over all IRQs affected by this read */
114 for (i = 0; i < len * 8; i++) { 114 for (i = 0; i < len * 8; i++) {
115 struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i); 115 struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
116 unsigned long flags;
116 117
118 spin_lock_irqsave(&irq->irq_lock, flags);
117 if (irq_is_pending(irq)) 119 if (irq_is_pending(irq))
118 value |= (1U << i); 120 value |= (1U << i);
121 spin_unlock_irqrestore(&irq->irq_lock, flags);
119 122
120 vgic_put_irq(vcpu->kvm, irq); 123 vgic_put_irq(vcpu->kvm, irq);
121 } 124 }
diff --git a/virt/kvm/arm/vgic/vgic-v2.c b/virt/kvm/arm/vgic/vgic-v2.c
index c32d7b93ffd1..29556f71b691 100644
--- a/virt/kvm/arm/vgic/vgic-v2.c
+++ b/virt/kvm/arm/vgic/vgic-v2.c
@@ -37,6 +37,13 @@ void vgic_v2_init_lrs(void)
37 vgic_v2_write_lr(i, 0); 37 vgic_v2_write_lr(i, 0);
38} 38}
39 39
40void vgic_v2_set_npie(struct kvm_vcpu *vcpu)
41{
42 struct vgic_v2_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v2;
43
44 cpuif->vgic_hcr |= GICH_HCR_NPIE;
45}
46
40void vgic_v2_set_underflow(struct kvm_vcpu *vcpu) 47void vgic_v2_set_underflow(struct kvm_vcpu *vcpu)
41{ 48{
42 struct vgic_v2_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v2; 49 struct vgic_v2_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v2;
@@ -64,7 +71,7 @@ void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu)
64 int lr; 71 int lr;
65 unsigned long flags; 72 unsigned long flags;
66 73
67 cpuif->vgic_hcr &= ~GICH_HCR_UIE; 74 cpuif->vgic_hcr &= ~(GICH_HCR_UIE | GICH_HCR_NPIE);
68 75
69 for (lr = 0; lr < vgic_cpu->used_lrs; lr++) { 76 for (lr = 0; lr < vgic_cpu->used_lrs; lr++) {
70 u32 val = cpuif->vgic_lr[lr]; 77 u32 val = cpuif->vgic_lr[lr];
@@ -410,7 +417,7 @@ int vgic_v2_probe(const struct gic_kvm_info *info)
410 kvm_vgic_global_state.type = VGIC_V2; 417 kvm_vgic_global_state.type = VGIC_V2;
411 kvm_vgic_global_state.max_gic_vcpus = VGIC_V2_MAX_CPUS; 418 kvm_vgic_global_state.max_gic_vcpus = VGIC_V2_MAX_CPUS;
412 419
413 kvm_info("vgic-v2@%llx\n", info->vctrl.start); 420 kvm_debug("vgic-v2@%llx\n", info->vctrl.start);
414 421
415 return 0; 422 return 0;
416out: 423out:
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index 6b329414e57a..0ff2006f3781 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -26,6 +26,13 @@ static bool group1_trap;
26static bool common_trap; 26static bool common_trap;
27static bool gicv4_enable; 27static bool gicv4_enable;
28 28
29void vgic_v3_set_npie(struct kvm_vcpu *vcpu)
30{
31 struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3;
32
33 cpuif->vgic_hcr |= ICH_HCR_NPIE;
34}
35
29void vgic_v3_set_underflow(struct kvm_vcpu *vcpu) 36void vgic_v3_set_underflow(struct kvm_vcpu *vcpu)
30{ 37{
31 struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3; 38 struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3;
@@ -47,7 +54,7 @@ void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu)
47 int lr; 54 int lr;
48 unsigned long flags; 55 unsigned long flags;
49 56
50 cpuif->vgic_hcr &= ~ICH_HCR_UIE; 57 cpuif->vgic_hcr &= ~(ICH_HCR_UIE | ICH_HCR_NPIE);
51 58
52 for (lr = 0; lr < vgic_cpu->used_lrs; lr++) { 59 for (lr = 0; lr < vgic_cpu->used_lrs; lr++) {
53 u64 val = cpuif->vgic_lr[lr]; 60 u64 val = cpuif->vgic_lr[lr];
diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c
index c7c5ef190afa..8201899126f6 100644
--- a/virt/kvm/arm/vgic/vgic.c
+++ b/virt/kvm/arm/vgic/vgic.c
@@ -495,6 +495,32 @@ int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq,
495 return ret; 495 return ret;
496} 496}
497 497
498/**
499 * kvm_vgic_reset_mapped_irq - Reset a mapped IRQ
500 * @vcpu: The VCPU pointer
501 * @vintid: The INTID of the interrupt
502 *
503 * Reset the active and pending states of a mapped interrupt. Kernel
504 * subsystems injecting mapped interrupts should reset their interrupt lines
505 * when we are doing a reset of the VM.
506 */
507void kvm_vgic_reset_mapped_irq(struct kvm_vcpu *vcpu, u32 vintid)
508{
509 struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid);
510 unsigned long flags;
511
512 if (!irq->hw)
513 goto out;
514
515 spin_lock_irqsave(&irq->irq_lock, flags);
516 irq->active = false;
517 irq->pending_latch = false;
518 irq->line_level = false;
519 spin_unlock_irqrestore(&irq->irq_lock, flags);
520out:
521 vgic_put_irq(vcpu->kvm, irq);
522}
523
498int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid) 524int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid)
499{ 525{
500 struct vgic_irq *irq; 526 struct vgic_irq *irq;
@@ -684,22 +710,37 @@ static inline void vgic_set_underflow(struct kvm_vcpu *vcpu)
684 vgic_v3_set_underflow(vcpu); 710 vgic_v3_set_underflow(vcpu);
685} 711}
686 712
713static inline void vgic_set_npie(struct kvm_vcpu *vcpu)
714{
715 if (kvm_vgic_global_state.type == VGIC_V2)
716 vgic_v2_set_npie(vcpu);
717 else
718 vgic_v3_set_npie(vcpu);
719}
720
687/* Requires the ap_list_lock to be held. */ 721/* Requires the ap_list_lock to be held. */
688static int compute_ap_list_depth(struct kvm_vcpu *vcpu) 722static int compute_ap_list_depth(struct kvm_vcpu *vcpu,
723 bool *multi_sgi)
689{ 724{
690 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 725 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
691 struct vgic_irq *irq; 726 struct vgic_irq *irq;
692 int count = 0; 727 int count = 0;
693 728
729 *multi_sgi = false;
730
694 DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock)); 731 DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock));
695 732
696 list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) { 733 list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) {
697 spin_lock(&irq->irq_lock); 734 spin_lock(&irq->irq_lock);
698 /* GICv2 SGIs can count for more than one... */ 735 /* GICv2 SGIs can count for more than one... */
699 if (vgic_irq_is_sgi(irq->intid) && irq->source) 736 if (vgic_irq_is_sgi(irq->intid) && irq->source) {
700 count += hweight8(irq->source); 737 int w = hweight8(irq->source);
701 else 738
739 count += w;
740 *multi_sgi |= (w > 1);
741 } else {
702 count++; 742 count++;
743 }
703 spin_unlock(&irq->irq_lock); 744 spin_unlock(&irq->irq_lock);
704 } 745 }
705 return count; 746 return count;
@@ -710,28 +751,43 @@ static void vgic_flush_lr_state(struct kvm_vcpu *vcpu)
710{ 751{
711 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 752 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
712 struct vgic_irq *irq; 753 struct vgic_irq *irq;
713 int count = 0; 754 int count;
755 bool npie = false;
756 bool multi_sgi;
757 u8 prio = 0xff;
714 758
715 DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock)); 759 DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock));
716 760
717 if (compute_ap_list_depth(vcpu) > kvm_vgic_global_state.nr_lr) 761 count = compute_ap_list_depth(vcpu, &multi_sgi);
762 if (count > kvm_vgic_global_state.nr_lr || multi_sgi)
718 vgic_sort_ap_list(vcpu); 763 vgic_sort_ap_list(vcpu);
719 764
765 count = 0;
766
720 list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) { 767 list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) {
721 spin_lock(&irq->irq_lock); 768 spin_lock(&irq->irq_lock);
722 769
723 if (unlikely(vgic_target_oracle(irq) != vcpu))
724 goto next;
725
726 /* 770 /*
727 * If we get an SGI with multiple sources, try to get 771 * If we have multi-SGIs in the pipeline, we need to
728 * them in all at once. 772 * guarantee that they are all seen before any IRQ of
773 * lower priority. In that case, we need to filter out
774 * these interrupts by exiting early. This is easy as
775 * the AP list has been sorted already.
729 */ 776 */
730 do { 777 if (multi_sgi && irq->priority > prio) {
778 spin_unlock(&irq->irq_lock);
779 break;
780 }
781
782 if (likely(vgic_target_oracle(irq) == vcpu)) {
731 vgic_populate_lr(vcpu, irq, count++); 783 vgic_populate_lr(vcpu, irq, count++);
732 } while (irq->source && count < kvm_vgic_global_state.nr_lr);
733 784
734next: 785 if (irq->source) {
786 npie = true;
787 prio = irq->priority;
788 }
789 }
790
735 spin_unlock(&irq->irq_lock); 791 spin_unlock(&irq->irq_lock);
736 792
737 if (count == kvm_vgic_global_state.nr_lr) { 793 if (count == kvm_vgic_global_state.nr_lr) {
@@ -742,6 +798,9 @@ next:
742 } 798 }
743 } 799 }
744 800
801 if (npie)
802 vgic_set_npie(vcpu);
803
745 vcpu->arch.vgic_cpu.used_lrs = count; 804 vcpu->arch.vgic_cpu.used_lrs = count;
746 805
747 /* Nuke remaining LRs */ 806 /* Nuke remaining LRs */
diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h
index 12c37b89f7a3..f5b8519e5546 100644
--- a/virt/kvm/arm/vgic/vgic.h
+++ b/virt/kvm/arm/vgic/vgic.h
@@ -96,6 +96,7 @@
96/* we only support 64 kB translation table page size */ 96/* we only support 64 kB translation table page size */
97#define KVM_ITS_L1E_ADDR_MASK GENMASK_ULL(51, 16) 97#define KVM_ITS_L1E_ADDR_MASK GENMASK_ULL(51, 16)
98 98
99/* Requires the irq_lock to be held by the caller. */
99static inline bool irq_is_pending(struct vgic_irq *irq) 100static inline bool irq_is_pending(struct vgic_irq *irq)
100{ 101{
101 if (irq->config == VGIC_CONFIG_EDGE) 102 if (irq->config == VGIC_CONFIG_EDGE)
@@ -159,6 +160,7 @@ void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu);
159void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr); 160void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr);
160void vgic_v2_clear_lr(struct kvm_vcpu *vcpu, int lr); 161void vgic_v2_clear_lr(struct kvm_vcpu *vcpu, int lr);
161void vgic_v2_set_underflow(struct kvm_vcpu *vcpu); 162void vgic_v2_set_underflow(struct kvm_vcpu *vcpu);
163void vgic_v2_set_npie(struct kvm_vcpu *vcpu);
162int vgic_v2_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr); 164int vgic_v2_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr);
163int vgic_v2_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write, 165int vgic_v2_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write,
164 int offset, u32 *val); 166 int offset, u32 *val);
@@ -188,6 +190,7 @@ void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu);
188void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr); 190void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr);
189void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr); 191void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr);
190void vgic_v3_set_underflow(struct kvm_vcpu *vcpu); 192void vgic_v3_set_underflow(struct kvm_vcpu *vcpu);
193void vgic_v3_set_npie(struct kvm_vcpu *vcpu);
191void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 194void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
192void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 195void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
193void vgic_v3_enable(struct kvm_vcpu *vcpu); 196void vgic_v3_enable(struct kvm_vcpu *vcpu);
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 4501e658e8d6..65dea3ffef68 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -969,8 +969,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
969 /* Check for overlaps */ 969 /* Check for overlaps */
970 r = -EEXIST; 970 r = -EEXIST;
971 kvm_for_each_memslot(slot, __kvm_memslots(kvm, as_id)) { 971 kvm_for_each_memslot(slot, __kvm_memslots(kvm, as_id)) {
972 if ((slot->id >= KVM_USER_MEM_SLOTS) || 972 if (slot->id == id)
973 (slot->id == id))
974 continue; 973 continue;
975 if (!((base_gfn + npages <= slot->base_gfn) || 974 if (!((base_gfn + npages <= slot->base_gfn) ||
976 (base_gfn >= slot->base_gfn + slot->npages))) 975 (base_gfn >= slot->base_gfn + slot->npages)))