aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Documentation/00-INDEX24
-rw-r--r--Documentation/PCI/MSI-HOWTO.txt119
-rw-r--r--Documentation/RCU/00-INDEX2
-rw-r--r--Documentation/RCU/RTFP.txt149
-rw-r--r--Documentation/RCU/checklist.txt18
-rw-r--r--Documentation/arm/00-INDEX14
-rw-r--r--Documentation/arm64/memory.txt16
-rw-r--r--Documentation/blackfin/00-INDEX6
-rw-r--r--Documentation/block/00-INDEX2
-rw-r--r--Documentation/device-mapper/cache.txt11
-rw-r--r--Documentation/device-mapper/thin-provisioning.txt34
-rw-r--r--Documentation/devicetree/00-INDEX2
-rw-r--r--Documentation/devicetree/bindings/arm/omap/omap.txt2
-rw-r--r--Documentation/devicetree/bindings/clock/renesas,cpg-mstp-clocks.txt4
-rw-r--r--Documentation/devicetree/bindings/dma/fsl-imx-sdma.txt16
-rw-r--r--Documentation/devicetree/bindings/interrupt-controller/lsi,zevio-intc.txt18
-rw-r--r--Documentation/devicetree/bindings/mmc/atmel-hsmci.txt5
-rw-r--r--Documentation/devicetree/bindings/net/allwinner,sun4i-emac.txt5
-rw-r--r--Documentation/devicetree/bindings/net/allwinner,sun4i-mdio.txt5
-rw-r--r--Documentation/devicetree/bindings/net/micrel-ks8851.txt1
-rw-r--r--Documentation/devicetree/bindings/net/opencores-ethoc.txt22
-rw-r--r--Documentation/devicetree/bindings/net/sti-dwmac.txt58
-rw-r--r--Documentation/devicetree/bindings/pinctrl/brcm,bcm11351-pinctrl.txt (renamed from Documentation/devicetree/bindings/pinctrl/brcm,capri-pinctrl.txt)8
-rw-r--r--Documentation/devicetree/bindings/power/bq2415x.txt47
-rw-r--r--Documentation/devicetree/bindings/spi/spi_atmel.txt5
-rw-r--r--Documentation/devicetree/bindings/vendor-prefixes.txt6
-rw-r--r--Documentation/dvb/contributors.txt2
-rw-r--r--Documentation/fb/00-INDEX6
-rw-r--r--Documentation/filesystems/00-INDEX2
-rw-r--r--Documentation/filesystems/nfs/00-INDEX4
-rw-r--r--Documentation/i2c/instantiating-devices41
-rw-r--r--Documentation/ide/00-INDEX2
-rw-r--r--Documentation/kernel-parameters.txt19
-rw-r--r--Documentation/kernel-per-CPU-kthreads.txt13
-rw-r--r--Documentation/laptops/00-INDEX6
-rw-r--r--Documentation/leds/00-INDEX8
-rw-r--r--Documentation/m68k/00-INDEX2
-rw-r--r--Documentation/memory-barriers.txt137
-rw-r--r--Documentation/networking/00-INDEX30
-rw-r--r--Documentation/networking/3c505.txt45
-rw-r--r--Documentation/networking/can.txt6
-rw-r--r--Documentation/networking/netlink_mmap.txt4
-rw-r--r--Documentation/networking/packet_mmap.txt2
-rw-r--r--Documentation/networking/timestamping.txt52
-rw-r--r--Documentation/phy.txt26
-rw-r--r--Documentation/power/00-INDEX6
-rw-r--r--Documentation/ptp/testptp.c11
-rw-r--r--Documentation/s390/00-INDEX8
-rw-r--r--Documentation/scheduler/00-INDEX2
-rw-r--r--Documentation/scsi/00-INDEX16
-rw-r--r--Documentation/serial/00-INDEX6
-rw-r--r--Documentation/spi/00-INDEX22
-rw-r--r--Documentation/spi/spi-summary17
-rw-r--r--Documentation/sysctl/kernel.txt15
-rw-r--r--Documentation/timers/00-INDEX2
-rw-r--r--Documentation/virtual/kvm/00-INDEX2
-rw-r--r--Documentation/vm/00-INDEX4
-rw-r--r--Documentation/w1/masters/00-INDEX4
-rw-r--r--Documentation/w1/slaves/00-INDEX2
-rw-r--r--Documentation/x86/00-INDEX18
-rw-r--r--Documentation/x86/boot.txt4
-rw-r--r--Documentation/zh_CN/arm64/booting.txt65
-rw-r--r--Documentation/zh_CN/arm64/memory.txt46
-rw-r--r--Documentation/zh_CN/arm64/tagged-pointers.txt52
-rw-r--r--MAINTAINERS202
-rw-r--r--Makefile10
-rw-r--r--arch/alpha/include/asm/Kbuild7
-rw-r--r--arch/arc/include/asm/Kbuild7
-rw-r--r--arch/arc/mm/cache_arc700.c4
-rw-r--r--arch/arm/Kconfig3
-rw-r--r--arch/arm/boot/compressed/.gitignore1
-rw-r--r--arch/arm/boot/dts/Makefile4
-rw-r--r--arch/arm/boot/dts/am335x-evmsk.dts11
-rw-r--r--arch/arm/boot/dts/armada-xp-mv78260.dtsi3
-rw-r--r--arch/arm/boot/dts/at91-sama5d3_xplained.dts229
-rw-r--r--arch/arm/boot/dts/at91sam9263.dtsi2
-rw-r--r--arch/arm/boot/dts/at91sam9n12ek.dts4
-rw-r--r--arch/arm/boot/dts/bcm11351.dtsi2
-rw-r--r--arch/arm/boot/dts/dove.dtsi11
-rw-r--r--arch/arm/boot/dts/imx6dl-hummingboard.dts10
-rw-r--r--arch/arm/boot/dts/imx6qdl-cubox-i.dtsi10
-rw-r--r--arch/arm/boot/dts/keystone-clocks.dtsi2
-rw-r--r--arch/arm/boot/dts/omap3-gta04.dts8
-rw-r--r--arch/arm/boot/dts/omap3-igep0020.dts2
-rw-r--r--arch/arm/boot/dts/omap3-igep0030.dts2
-rw-r--r--arch/arm/boot/dts/omap3-n9.dts2
-rw-r--r--arch/arm/boot/dts/omap3-n900.dts4
-rw-r--r--arch/arm/boot/dts/omap3-n950.dts2
-rw-r--r--arch/arm/boot/dts/omap3-overo-storm-tobi.dts22
-rw-r--r--arch/arm/boot/dts/omap3-overo-tobi-common.dtsi (renamed from arch/arm/boot/dts/omap3-tobi.dts)3
-rw-r--r--arch/arm/boot/dts/omap3-overo-tobi.dts22
-rw-r--r--arch/arm/boot/dts/omap3-overo.dtsi3
-rw-r--r--arch/arm/boot/dts/sama5d3.dtsi2
-rw-r--r--arch/arm/boot/dts/sama5d36.dtsi2
-rw-r--r--arch/arm/boot/dts/ste-href.dtsi1
-rw-r--r--arch/arm/boot/dts/sun4i-a10.dtsi6
-rw-r--r--arch/arm/boot/dts/sun5i-a10s.dtsi6
-rw-r--r--arch/arm/boot/dts/sun5i-a13.dtsi2
-rw-r--r--arch/arm/boot/dts/sun7i-a20.dtsi16
-rw-r--r--arch/arm/boot/dts/tegra114.dtsi4
-rw-r--r--arch/arm/boot/dts/tegra20.dtsi4
-rw-r--r--arch/arm/boot/dts/tegra30-cardhu.dtsi2
-rw-r--r--arch/arm/boot/dts/tegra30.dtsi4
-rw-r--r--arch/arm/boot/dts/testcases/tests.dtsi2
-rw-r--r--arch/arm/boot/dts/versatile-pb.dts4
-rw-r--r--arch/arm/configs/multi_v7_defconfig1
-rw-r--r--arch/arm/configs/tegra_defconfig3
-rw-r--r--arch/arm/include/asm/Kbuild5
-rw-r--r--arch/arm/include/asm/cacheflush.h1
-rw-r--r--arch/arm/include/asm/memory.h9
-rw-r--r--arch/arm/include/asm/pgtable-3level.h15
-rw-r--r--arch/arm/include/asm/spinlock.h15
-rw-r--r--arch/arm/include/asm/topology.h3
-rw-r--r--arch/arm/kernel/head-common.S12
-rw-r--r--arch/arm/kernel/head.S2
-rw-r--r--arch/arm/kernel/process.c16
-rw-r--r--arch/arm/kernel/setup.c2
-rw-r--r--arch/arm/kvm/arm.c3
-rw-r--r--arch/arm/kvm/interrupts.S11
-rw-r--r--arch/arm/mach-hisi/Kconfig2
-rw-r--r--arch/arm/mach-imx/Makefile2
-rw-r--r--arch/arm/mach-imx/clk-imx6q.c3
-rw-r--r--arch/arm/mach-imx/clk-imx6sl.c3
-rw-r--r--arch/arm/mach-imx/common.h4
-rw-r--r--arch/arm/mach-imx/pm-imx6q.c2
-rw-r--r--arch/arm/mach-moxart/Kconfig1
-rw-r--r--arch/arm/mach-omap1/board-nokia770.c1
-rw-r--r--arch/arm/mach-omap2/Kconfig10
-rw-r--r--arch/arm/mach-omap2/cclock3xxx_data.c2
-rw-r--r--arch/arm/mach-omap2/cpuidle44xx.c8
-rw-r--r--arch/arm/mach-omap2/dpll3xxx.c92
-rw-r--r--arch/arm/mach-omap2/gpmc.c4
-rw-r--r--arch/arm/mach-omap2/io.c9
-rw-r--r--arch/arm/mach-omap2/omap_hwmod.c20
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_7xx_data.c9
-rw-r--r--arch/arm/mach-omap2/pdata-quirks.c21
-rw-r--r--arch/arm/mach-omap2/prminst44xx.c4
-rw-r--r--arch/arm/mach-pxa/am300epd.c1
-rw-r--r--arch/arm/mach-pxa/include/mach/balloon3.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/corgi.h1
-rw-r--r--arch/arm/mach-pxa/include/mach/csb726.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/gumstix.h1
-rw-r--r--arch/arm/mach-pxa/include/mach/idp.h1
-rw-r--r--arch/arm/mach-pxa/include/mach/palmld.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/palmt5.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/palmtc.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/palmtx.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/pcm027.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/pcm990_baseboard.h1
-rw-r--r--arch/arm/mach-pxa/include/mach/poodle.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/spitz.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/tosa.h2
-rw-r--r--arch/arm/mach-pxa/include/mach/trizeps4.h2
-rw-r--r--arch/arm/mach-pxa/mioa701.c9
-rw-r--r--arch/arm/mach-sa1100/include/mach/collie.h2
-rw-r--r--arch/arm/mach-shmobile/Kconfig2
-rw-r--r--arch/arm/mach-tegra/pm.c1
-rw-r--r--arch/arm/mach-tegra/tegra.c10
-rw-r--r--arch/arm/mach-zynq/common.c14
-rw-r--r--arch/arm/mm/dma-mapping.c2
-rw-r--r--arch/arm/mm/dump.c3
-rw-r--r--arch/arm/mm/mm.h1
-rw-r--r--arch/arm/mm/mmu.c7
-rw-r--r--arch/arm/mm/proc-v6.S3
-rw-r--r--arch/arm/mm/proc-v7.S2
-rw-r--r--arch/arm64/Kconfig27
-rw-r--r--arch/arm64/configs/defconfig18
-rw-r--r--arch/arm64/include/asm/Kbuild8
-rw-r--r--arch/arm64/include/asm/atomic.h53
-rw-r--r--arch/arm64/include/asm/barrier.h3
-rw-r--r--arch/arm64/include/asm/cacheflush.h8
-rw-r--r--arch/arm64/include/asm/cmpxchg.h17
-rw-r--r--arch/arm64/include/asm/compat.h2
-rw-r--r--arch/arm64/include/asm/cpufeature.h29
-rw-r--r--arch/arm64/include/asm/debug-monitors.h64
-rw-r--r--arch/arm64/include/asm/dma-mapping.h7
-rw-r--r--arch/arm64/include/asm/esr.h2
-rw-r--r--arch/arm64/include/asm/futex.h10
-rw-r--r--arch/arm64/include/asm/hwcap.h9
-rw-r--r--arch/arm64/include/asm/io.h2
-rw-r--r--arch/arm64/include/asm/irqflags.h23
-rw-r--r--arch/arm64/include/asm/kgdb.h84
-rw-r--r--arch/arm64/include/asm/kvm_arm.h17
-rw-r--r--arch/arm64/include/asm/percpu.h8
-rw-r--r--arch/arm64/include/asm/pgtable-hwdef.h5
-rw-r--r--arch/arm64/include/asm/pgtable.h70
-rw-r--r--arch/arm64/include/asm/psci.h2
-rw-r--r--arch/arm64/include/asm/ptrace.h5
-rw-r--r--arch/arm64/include/asm/spinlock.h10
-rw-r--r--arch/arm64/include/asm/tlb.h136
-rw-r--r--arch/arm64/include/asm/topology.h39
-rw-r--r--arch/arm64/include/asm/uaccess.h4
-rw-r--r--arch/arm64/include/asm/unistd.h1
-rw-r--r--arch/arm64/include/asm/unistd32.h5
-rw-r--r--arch/arm64/include/uapi/asm/Kbuild1
-rw-r--r--arch/arm64/include/uapi/asm/kvm.h9
-rw-r--r--arch/arm64/include/uapi/asm/perf_regs.h40
-rw-r--r--arch/arm64/kernel/Makefile6
-rw-r--r--arch/arm64/kernel/debug-monitors.c10
-rw-r--r--arch/arm64/kernel/head.S20
-rw-r--r--arch/arm64/kernel/kgdb.c336
-rw-r--r--arch/arm64/kernel/kuser32.S6
-rw-r--r--arch/arm64/kernel/perf_event.c75
-rw-r--r--arch/arm64/kernel/perf_regs.c44
-rw-r--r--arch/arm64/kernel/process.c18
-rw-r--r--arch/arm64/kernel/psci.c13
-rw-r--r--arch/arm64/kernel/setup.c33
-rw-r--r--arch/arm64/kernel/smp.c12
-rw-r--r--arch/arm64/kernel/smp_spin_table.c2
-rw-r--r--arch/arm64/kernel/stacktrace.c6
-rw-r--r--arch/arm64/kernel/topology.c95
-rw-r--r--arch/arm64/kernel/vdso.c46
-rw-r--r--arch/arm64/kernel/vdso/Makefile2
-rw-r--r--arch/arm64/kernel/vdso/gettimeofday.S7
-rw-r--r--arch/arm64/kvm/hyp-init.S6
-rw-r--r--arch/arm64/kvm/hyp.S27
-rw-r--r--arch/arm64/lib/bitops.S3
-rw-r--r--arch/arm64/mm/cache.S80
-rw-r--r--arch/arm64/mm/dma-mapping.c247
-rw-r--r--arch/arm64/mm/init.c33
-rw-r--r--arch/arm64/mm/mmu.c12
-rw-r--r--arch/arm64/mm/pgd.c11
-rw-r--r--arch/arm64/mm/proc.S14
-rw-r--r--arch/avr32/Makefile2
-rw-r--r--arch/avr32/boards/mimc200/fram.c1
-rw-r--r--arch/avr32/include/asm/Kbuild42
-rw-r--r--arch/avr32/include/asm/io.h2
-rw-r--r--arch/blackfin/include/asm/Kbuild7
-rw-r--r--arch/c6x/include/asm/Kbuild5
-rw-r--r--arch/c6x/include/asm/cache.h1
-rw-r--r--arch/cris/include/asm/Kbuild3
-rw-r--r--arch/cris/include/asm/bitops.h2
-rw-r--r--arch/frv/include/asm/Kbuild5
-rw-r--r--arch/hexagon/include/asm/Kbuild7
-rw-r--r--arch/ia64/configs/generic_defconfig4
-rw-r--r--arch/ia64/hp/common/sba_iommu.c6
-rw-r--r--arch/ia64/include/asm/Kbuild5
-rw-r--r--arch/ia64/include/asm/topology.h1
-rw-r--r--arch/ia64/include/asm/unistd.h2
-rw-r--r--arch/ia64/include/uapi/asm/unistd.h2
-rw-r--r--arch/ia64/kernel/efi.c7
-rw-r--r--arch/ia64/kernel/entry.S2
-rw-r--r--arch/ia64/kernel/mca.c4
-rw-r--r--arch/ia64/kernel/uncached.c2
-rw-r--r--arch/m32r/include/asm/Kbuild5
-rw-r--r--arch/m68k/Kconfig1
-rw-r--r--arch/m68k/configs/amiga_defconfig10
-rw-r--r--arch/m68k/configs/apollo_defconfig10
-rw-r--r--arch/m68k/configs/atari_defconfig10
-rw-r--r--arch/m68k/configs/bvme6000_defconfig10
-rw-r--r--arch/m68k/configs/hp300_defconfig10
-rw-r--r--arch/m68k/configs/mac_defconfig10
-rw-r--r--arch/m68k/configs/multi_defconfig10
-rw-r--r--arch/m68k/configs/mvme147_defconfig10
-rw-r--r--arch/m68k/configs/mvme16x_defconfig10
-rw-r--r--arch/m68k/configs/q40_defconfig10
-rw-r--r--arch/m68k/configs/sun3_defconfig10
-rw-r--r--arch/m68k/configs/sun3x_defconfig10
-rw-r--r--arch/m68k/include/asm/Kbuild9
-rw-r--r--arch/m68k/include/asm/barrier.h8
-rw-r--r--arch/m68k/include/asm/unistd.h2
-rw-r--r--arch/m68k/include/uapi/asm/unistd.h2
-rw-r--r--arch/m68k/kernel/head.S70
-rw-r--r--arch/m68k/kernel/syscalltable.S2
-rw-r--r--arch/metag/include/asm/Kbuild5
-rw-r--r--arch/microblaze/include/asm/Kbuild5
-rw-r--r--arch/microblaze/include/asm/delay.h2
-rw-r--r--arch/microblaze/include/asm/io.h6
-rw-r--r--arch/microblaze/kernel/head.S2
-rw-r--r--arch/mips/Kconfig24
-rw-r--r--arch/mips/alchemy/board-gpr.c4
-rw-r--r--arch/mips/alchemy/board-mtx1.c4
-rw-r--r--arch/mips/alchemy/devboards/db1000.c7
-rw-r--r--arch/mips/bcm47xx/board.c1
-rw-r--r--arch/mips/bcm47xx/nvram.c2
-rw-r--r--arch/mips/cavium-octeon/octeon-irq.c22
-rw-r--r--arch/mips/include/asm/Kbuild5
-rw-r--r--arch/mips/include/asm/asmmacro.h15
-rw-r--r--arch/mips/include/asm/fpu.h4
-rw-r--r--arch/mips/include/asm/ftrace.h20
-rw-r--r--arch/mips/include/asm/syscall.h10
-rw-r--r--arch/mips/include/asm/topology.h4
-rw-r--r--arch/mips/include/asm/unistd.h1
-rw-r--r--arch/mips/include/uapi/asm/inst.h4
-rw-r--r--arch/mips/include/uapi/asm/unistd.h18
-rw-r--r--arch/mips/kernel/ftrace.c5
-rw-r--r--arch/mips/kernel/r4k_fpu.S16
-rw-r--r--arch/mips/kernel/rtlx-cmp.c3
-rw-r--r--arch/mips/kernel/rtlx-mt.c3
-rw-r--r--arch/mips/kernel/scall32-o32.S2
-rw-r--r--arch/mips/kernel/scall64-64.S2
-rw-r--r--arch/mips/kernel/scall64-n32.S2
-rw-r--r--arch/mips/kernel/scall64-o32.S2
-rw-r--r--arch/mips/math-emu/cp1emu.c6
-rw-r--r--arch/mips/mti-malta/malta-amon.c2
-rw-r--r--arch/mips/mti-malta/malta-int.c4
-rw-r--r--arch/mips/pci/msi-octeon.c1
-rw-r--r--arch/mn10300/include/asm/Kbuild3
-rw-r--r--arch/openrisc/include/asm/Kbuild11
-rw-r--r--arch/parisc/hpux/fs.c15
-rw-r--r--arch/parisc/include/asm/Kbuild32
-rw-r--r--arch/parisc/include/asm/page.h11
-rw-r--r--arch/parisc/include/asm/spinlock.h4
-rw-r--r--arch/parisc/include/uapi/asm/unistd.h4
-rw-r--r--arch/parisc/kernel/cache.c64
-rw-r--r--arch/parisc/kernel/syscall_table.S1
-rw-r--r--arch/powerpc/include/asm/Kbuild5
-rw-r--r--arch/powerpc/include/asm/compat.h5
-rw-r--r--arch/powerpc/include/asm/dma-mapping.h1
-rw-r--r--arch/powerpc/include/asm/eeh.h21
-rw-r--r--arch/powerpc/include/asm/hugetlb.h2
-rw-r--r--arch/powerpc/include/asm/iommu.h1
-rw-r--r--arch/powerpc/include/asm/opal.h4
-rw-r--r--arch/powerpc/include/asm/pgtable-ppc64.h26
-rw-r--r--arch/powerpc/include/asm/pgtable.h22
-rw-r--r--arch/powerpc/include/asm/ptrace.h16
-rw-r--r--arch/powerpc/include/asm/sections.h12
-rw-r--r--arch/powerpc/include/asm/topology.h1
-rw-r--r--arch/powerpc/include/asm/vdso.h6
-rw-r--r--arch/powerpc/kernel/crash_dump.c8
-rw-r--r--arch/powerpc/kernel/dma.c10
-rw-r--r--arch/powerpc/kernel/eeh.c32
-rw-r--r--arch/powerpc/kernel/eeh_driver.c8
-rw-r--r--arch/powerpc/kernel/ftrace.c1
-rw-r--r--arch/powerpc/kernel/iommu.c12
-rw-r--r--arch/powerpc/kernel/irq.c5
-rw-r--r--arch/powerpc/kernel/machine_kexec.c14
-rw-r--r--arch/powerpc/kernel/machine_kexec_64.c6
-rw-r--r--arch/powerpc/kernel/misc_32.S5
-rw-r--r--arch/powerpc/kernel/process.c9
-rw-r--r--arch/powerpc/kernel/reloc_64.S5
-rw-r--r--arch/powerpc/kernel/setup_32.c5
-rw-r--r--arch/powerpc/kernel/signal_64.c4
-rw-r--r--arch/powerpc/kernel/vdso32/vdso32_wrapper.S2
-rw-r--r--arch/powerpc/kernel/vdso64/vdso64_wrapper.S2
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S71
-rw-r--r--arch/powerpc/mm/hash_utils_64.c14
-rw-r--r--arch/powerpc/mm/pgtable_64.c12
-rw-r--r--arch/powerpc/mm/subpage-prot.c2
-rw-r--r--arch/powerpc/perf/core-book3s.c5
-rw-r--r--arch/powerpc/perf/power8-pmu.c144
-rw-r--r--arch/powerpc/platforms/cell/ras.c3
-rw-r--r--arch/powerpc/platforms/cell/spufs/sched.c1
-rw-r--r--arch/powerpc/platforms/powernv/eeh-ioda.c128
-rw-r--r--arch/powerpc/platforms/powernv/eeh-powernv.c2
-rw-r--r--arch/powerpc/platforms/powernv/opal-xscom.c21
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c84
-rw-r--r--arch/powerpc/platforms/powernv/pci.c230
-rw-r--r--arch/powerpc/platforms/powernv/pci.h6
-rw-r--r--arch/powerpc/platforms/powernv/powernv.h8
-rw-r--r--arch/powerpc/platforms/powernv/setup.c22
-rw-r--r--arch/powerpc/platforms/pseries/Kconfig1
-rw-r--r--arch/powerpc/platforms/pseries/eeh_pseries.c2
-rw-r--r--arch/powerpc/platforms/pseries/hotplug-cpu.c22
-rw-r--r--arch/powerpc/platforms/pseries/pci.c22
-rw-r--r--arch/powerpc/platforms/pseries/setup.c37
-rw-r--r--arch/powerpc/sysdev/mpic.c38
-rw-r--r--arch/powerpc/xmon/xmon.c24
-rw-r--r--arch/s390/Kconfig6
-rw-r--r--arch/s390/appldata/appldata_base.c1
-rw-r--r--arch/s390/appldata/appldata_os.c2
-rw-r--r--arch/s390/configs/default_defconfig46
-rw-r--r--arch/s390/configs/gcov_defconfig33
-rw-r--r--arch/s390/configs/performance_defconfig33
-rw-r--r--arch/s390/configs/zfcpdump_defconfig1
-rw-r--r--arch/s390/crypto/aes_s390.c65
-rw-r--r--arch/s390/crypto/des_s390.c95
-rw-r--r--arch/s390/defconfig10
-rw-r--r--arch/s390/hypfs/hypfs_vm.c9
-rw-r--r--arch/s390/include/asm/Kbuild5
-rw-r--r--arch/s390/include/asm/airq.h14
-rw-r--r--arch/s390/include/asm/bitops.h8
-rw-r--r--arch/s390/include/asm/ccwdev.h4
-rw-r--r--arch/s390/include/asm/checksum.h11
-rw-r--r--arch/s390/include/asm/compat.h6
-rw-r--r--arch/s390/include/asm/futex.h13
-rw-r--r--arch/s390/include/asm/kvm_host.h5
-rw-r--r--arch/s390/include/asm/mmu_context.h39
-rw-r--r--arch/s390/include/asm/pgalloc.h18
-rw-r--r--arch/s390/include/asm/pgtable.h105
-rw-r--r--arch/s390/include/asm/ptrace.h1
-rw-r--r--arch/s390/include/asm/sclp.h1
-rw-r--r--arch/s390/include/asm/setup.h3
-rw-r--r--arch/s390/include/asm/thread_info.h3
-rw-r--r--arch/s390/include/asm/uaccess.h171
-rw-r--r--arch/s390/include/uapi/asm/ptrace.h6
-rw-r--r--arch/s390/kernel/Makefile5
-rw-r--r--arch/s390/kernel/compat_exec_domain.c29
-rw-r--r--arch/s390/kernel/compat_linux.c116
-rw-r--r--arch/s390/kernel/compat_linux.h81
-rw-r--r--arch/s390/kernel/compat_signal.c4
-rw-r--r--arch/s390/kernel/compat_wrapper.S1425
-rw-r--r--arch/s390/kernel/compat_wrapper.c215
-rw-r--r--arch/s390/kernel/early.c2
-rw-r--r--arch/s390/kernel/entry.S9
-rw-r--r--arch/s390/kernel/entry.h6
-rw-r--r--arch/s390/kernel/entry64.S9
-rw-r--r--arch/s390/kernel/head64.S7
-rw-r--r--arch/s390/kernel/perf_event.c2
-rw-r--r--arch/s390/kernel/ptrace.c13
-rw-r--r--arch/s390/kernel/setup.c17
-rw-r--r--arch/s390/kernel/smp.c8
-rw-r--r--arch/s390/kernel/syscalls.S504
-rw-r--r--arch/s390/kernel/topology.c1
-rw-r--r--arch/s390/kvm/diag.c3
-rw-r--r--arch/s390/kvm/kvm-s390.c25
-rw-r--r--arch/s390/kvm/kvm-s390.h2
-rw-r--r--arch/s390/kvm/priv.c41
-rw-r--r--arch/s390/lib/Makefile3
-rw-r--r--arch/s390/lib/find.c2
-rw-r--r--arch/s390/lib/uaccess.h8
-rw-r--r--arch/s390/lib/uaccess_mvcos.c116
-rw-r--r--arch/s390/lib/uaccess_pt.c69
-rw-r--r--arch/s390/mm/maccess.c28
-rw-r--r--arch/s390/mm/page-states.c10
-rw-r--r--arch/s390/mm/pgtable.c158
-rw-r--r--arch/s390/pci/pci_debug.c2
-rw-r--r--arch/s390/pci/pci_dma.c8
-rw-r--r--arch/score/include/asm/Kbuild5
-rw-r--r--arch/sh/include/asm/Kbuild9
-rw-r--r--arch/sh/include/cpu-sh2/cpu/cache.h2
-rw-r--r--arch/sh/include/cpu-sh2a/cpu/cache.h4
-rw-r--r--arch/sh/include/cpu-sh3/cpu/cache.h2
-rw-r--r--arch/sh/include/cpu-sh4/cpu/cache.h2
-rw-r--r--arch/sh/kernel/cpu/init.c4
-rw-r--r--arch/sh/kernel/idle.c4
-rw-r--r--arch/sh/mm/cache-debugfs.c2
-rw-r--r--arch/sh/mm/cache-sh2.c4
-rw-r--r--arch/sh/mm/cache-sh2a.c6
-rw-r--r--arch/sh/mm/cache-sh4.c4
-rw-r--r--arch/sh/mm/cache-shx3.c4
-rw-r--r--arch/sh/mm/cache.c4
-rw-r--r--arch/sparc/Kconfig2
-rw-r--r--arch/sparc/include/asm/Kbuild11
-rw-r--r--arch/sparc/include/asm/smp_64.h1
-rw-r--r--arch/sparc/include/asm/topology_64.h2
-rw-r--r--arch/sparc/kernel/mdesc.c4
-rw-r--r--arch/sparc/kernel/process_64.c4
-rw-r--r--arch/sparc/kernel/prom_64.c3
-rw-r--r--arch/sparc/kernel/smp_64.c2
-rw-r--r--arch/sparc/kernel/syscalls.S4
-rw-r--r--arch/sparc/mm/srmmu.c2
-rw-r--r--arch/sparc/mm/tsb.c2
-rw-r--r--arch/tile/include/asm/Kbuild5
-rw-r--r--arch/um/include/asm/Kbuild34
-rw-r--r--arch/unicore32/include/asm/Kbuild5
-rw-r--r--arch/x86/Kconfig21
-rw-r--r--arch/x86/Kconfig.cpu4
-rw-r--r--arch/x86/Kconfig.debug10
-rw-r--r--arch/x86/Makefile5
-rw-r--r--arch/x86/boot/Makefile2
-rw-r--r--arch/x86/boot/compressed/aslr.c9
-rw-r--r--arch/x86/boot/compressed/eboot.c1017
-rw-r--r--arch/x86/boot/compressed/eboot.h60
-rw-r--r--arch/x86/boot/compressed/efi_stub_64.S29
-rw-r--r--arch/x86/boot/compressed/head_32.S52
-rw-r--r--arch/x86/boot/compressed/head_64.S111
-rw-r--r--arch/x86/boot/cpucheck.c20
-rw-r--r--arch/x86/boot/header.S25
-rw-r--r--arch/x86/boot/tools/build.c77
-rw-r--r--arch/x86/include/asm/Kbuild1
-rw-r--r--arch/x86/include/asm/amd_nb.h2
-rw-r--r--arch/x86/include/asm/apic.h14
-rw-r--r--arch/x86/include/asm/barrier.h8
-rw-r--r--arch/x86/include/asm/cpufeature.h5
-rw-r--r--arch/x86/include/asm/efi.h46
-rw-r--r--arch/x86/include/asm/io.h2
-rw-r--r--arch/x86/include/asm/msr.h2
-rw-r--r--arch/x86/include/asm/nmi.h3
-rw-r--r--arch/x86/include/asm/pgtable.h3
-rw-r--r--arch/x86/include/asm/pgtable_types.h4
-rw-r--r--arch/x86/include/asm/special_insns.h8
-rw-r--r--arch/x86/include/asm/spinlock.h5
-rw-r--r--arch/x86/include/asm/tlbflush.h6
-rw-r--r--arch/x86/include/asm/topology.h9
-rw-r--r--arch/x86/include/asm/tsc.h2
-rw-r--r--arch/x86/include/asm/unistd.h3
-rw-r--r--arch/x86/include/asm/xen/page.h5
-rw-r--r--arch/x86/include/asm/xsave.h16
-rw-r--r--arch/x86/include/uapi/asm/msr-index.h75
-rw-r--r--arch/x86/kernel/acpi/boot.c8
-rw-r--r--arch/x86/kernel/amd_nb.c2
-rw-r--r--arch/x86/kernel/aperture_64.c20
-rw-r--r--arch/x86/kernel/apic/apic.c13
-rw-r--r--arch/x86/kernel/apic/apic_flat_64.c4
-rw-r--r--arch/x86/kernel/apic/apic_noop.c3
-rw-r--r--arch/x86/kernel/apic/apic_numachip.c2
-rw-r--r--arch/x86/kernel/apic/bigsmp_32.c3
-rw-r--r--arch/x86/kernel/apic/es7000_32.c12
-rw-r--r--arch/x86/kernel/apic/numaq_32.c3
-rw-r--r--arch/x86/kernel/apic/probe_32.c3
-rw-r--r--arch/x86/kernel/apic/summit_32.c3
-rw-r--r--arch/x86/kernel/apic/x2apic_cluster.c2
-rw-r--r--arch/x86/kernel/apic/x2apic_phys.c2
-rw-r--r--arch/x86/kernel/apic/x2apic_uv_x.c2
-rw-r--r--arch/x86/kernel/cpu/amd.c55
-rw-r--r--arch/x86/kernel/cpu/centaur.c272
-rw-r--r--arch/x86/kernel/cpu/common.c7
-rw-r--r--arch/x86/kernel/cpu/intel.c63
-rw-r--r--arch/x86/kernel/cpu/microcode/amd_early.c43
-rw-r--r--arch/x86/kernel/cpu/mshyperv.c6
-rw-r--r--arch/x86/kernel/cpu/mtrr/generic.c4
-rw-r--r--arch/x86/kernel/cpu/perf_event.c54
-rw-r--r--arch/x86/kernel/cpu/perf_event.h9
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel.c11
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_uncore.c557
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_uncore.h5
-rw-r--r--arch/x86/kernel/cpu/perf_event_p4.c34
-rw-r--r--arch/x86/kernel/cpu/perf_event_p6.c48
-rw-r--r--arch/x86/kernel/crash.c2
-rw-r--r--arch/x86/kernel/dumpstack_32.c2
-rw-r--r--arch/x86/kernel/ftrace.c83
-rw-r--r--arch/x86/kernel/head_32.S7
-rw-r--r--arch/x86/kernel/head_64.S6
-rw-r--r--arch/x86/kernel/i387.c15
-rw-r--r--arch/x86/kernel/irq.c9
-rw-r--r--arch/x86/kernel/machine_kexec_64.c2
-rw-r--r--arch/x86/kernel/module.c46
-rw-r--r--arch/x86/kernel/nmi.c37
-rw-r--r--arch/x86/kernel/pci-dma.c4
-rw-r--r--arch/x86/kernel/process.c5
-rw-r--r--arch/x86/kernel/quirks.c39
-rw-r--r--arch/x86/kernel/setup.c16
-rw-r--r--arch/x86/kernel/smpboot.c16
-rw-r--r--arch/x86/kernel/time.c2
-rw-r--r--arch/x86/kernel/tsc.c11
-rw-r--r--arch/x86/kernel/tsc_msr.c30
-rw-r--r--arch/x86/kvm/mmu.c1
-rw-r--r--arch/x86/kvm/svm.c6
-rw-r--r--arch/x86/kvm/vmx.c2
-rw-r--r--arch/x86/kvm/x86.c2
-rw-r--r--arch/x86/lib/hash.c22
-rw-r--r--arch/x86/lib/memcpy_32.c6
-rw-r--r--arch/x86/lib/msr.c89
-rw-r--r--arch/x86/mm/dump_pagetables.c84
-rw-r--r--arch/x86/mm/fault.c68
-rw-r--r--arch/x86/mm/numa.c21
-rw-r--r--arch/x86/mm/numa_32.c2
-rw-r--r--arch/x86/mm/pageattr.c70
-rw-r--r--arch/x86/mm/srat.c16
-rw-r--r--arch/x86/mm/tlb.c52
-rw-r--r--arch/x86/net/bpf_jit.S2
-rw-r--r--arch/x86/platform/efi/Makefile1
-rw-r--r--arch/x86/platform/efi/efi-bgrt.c12
-rw-r--r--arch/x86/platform/efi/efi.c436
-rw-r--r--arch/x86/platform/efi/efi_32.c13
-rw-r--r--arch/x86/platform/efi/efi_64.c377
-rw-r--r--arch/x86/platform/efi/efi_stub_64.S166
-rw-r--r--arch/x86/platform/efi/efi_thunk_64.S65
-rw-r--r--arch/x86/platform/ts5500/ts5500.c2
-rw-r--r--arch/x86/um/asm/barrier.h4
-rw-r--r--arch/x86/vdso/Makefile10
-rw-r--r--arch/x86/xen/enlighten.c12
-rw-r--r--arch/x86/xen/p2m.c17
-rw-r--r--arch/xtensa/Kconfig3
-rw-r--r--arch/xtensa/boot/dts/xtfpga.dtsi12
-rw-r--r--arch/xtensa/include/asm/Kbuild5
-rw-r--r--arch/xtensa/include/asm/io.h2
-rw-r--r--arch/xtensa/include/asm/traps.h44
-rw-r--r--arch/xtensa/include/asm/vectors.h2
-rw-r--r--arch/xtensa/include/uapi/asm/unistd.h7
-rw-r--r--arch/xtensa/kernel/entry.S449
-rw-r--r--arch/xtensa/kernel/setup.c2
-rw-r--r--arch/xtensa/kernel/time.c1
-rw-r--r--arch/xtensa/kernel/vectors.S2
-rw-r--r--arch/xtensa/kernel/xtensa_ksyms.c2
-rw-r--r--arch/xtensa/mm/init.c13
-rw-r--r--arch/xtensa/mm/mmu.c2
-rw-r--r--arch/xtensa/platforms/xtfpga/setup.c7
-rw-r--r--arch/xtensa/variants/fsf/include/variant/tie.h9
-rw-r--r--block/blk-core.c19
-rw-r--r--block/blk-exec.c2
-rw-r--r--block/blk-flush.c108
-rw-r--r--block/blk-lib.c8
-rw-r--r--block/blk-merge.c91
-rw-r--r--block/blk-mq-cpu.c14
-rw-r--r--block/blk-mq-tag.c2
-rw-r--r--block/blk-mq.c237
-rw-r--r--block/blk-mq.h5
-rw-r--r--block/blk-sysfs.c2
-rw-r--r--block/blk-timeout.c2
-rw-r--r--block/blk.h2
-rw-r--r--drivers/acpi/ac.c2
-rw-r--r--drivers/acpi/battery.c4
-rw-r--r--drivers/acpi/blacklist.c58
-rw-r--r--drivers/acpi/button.c2
-rw-r--r--drivers/acpi/container.c5
-rw-r--r--drivers/acpi/dock.c13
-rw-r--r--drivers/acpi/ec.c64
-rw-r--r--drivers/acpi/fan.c3
-rw-r--r--drivers/acpi/pci_irq.c1
-rw-r--r--drivers/acpi/proc.c2
-rw-r--r--drivers/acpi/processor_throttling.c69
-rw-r--r--drivers/acpi/resource.c10
-rw-r--r--drivers/acpi/sbs.c4
-rw-r--r--drivers/acpi/scan.c6
-rw-r--r--drivers/acpi/sleep.c32
-rw-r--r--drivers/acpi/thermal.c2
-rw-r--r--drivers/acpi/utils.c4
-rw-r--r--drivers/acpi/video.c147
-rw-r--r--drivers/acpi/video_detect.c8
-rw-r--r--drivers/ata/Kconfig1
-rw-r--r--drivers/ata/ahci.c18
-rw-r--r--drivers/ata/libata-core.c3
-rw-r--r--drivers/ata/libata-pmp.c7
-rw-r--r--drivers/ata/pata_imx.c8
-rw-r--r--drivers/ata/sata_mv.c16
-rw-r--r--drivers/ata/sata_sil.c1
-rw-r--r--drivers/base/component.c8
-rw-r--r--drivers/base/dma-buf.c25
-rw-r--r--drivers/base/firmware_class.c1
-rw-r--r--drivers/block/aoe/aoecmd.c4
-rw-r--r--drivers/block/floppy.c42
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c2
-rw-r--r--drivers/block/mtip32xx/mtip32xx.h2
-rw-r--r--drivers/block/null_blk.c97
-rw-r--r--drivers/block/nvme-core.c616
-rw-r--r--drivers/block/nvme-scsi.c147
-rw-r--r--drivers/block/rbd.c1
-rw-r--r--drivers/block/virtio_blk.c7
-rw-r--r--drivers/block/xen-blkback/blkback.c81
-rw-r--r--drivers/block/xen-blkback/common.h5
-rw-r--r--drivers/block/xen-blkback/xenbus.c14
-rw-r--r--drivers/block/xen-blkfront.c11
-rw-r--r--drivers/block/zram/zram_drv.c2
-rw-r--r--drivers/char/Kconfig1
-rw-r--r--drivers/char/raw.c2
-rw-r--r--drivers/char/virtio_console.c9
-rw-r--r--drivers/clk/at91/clk-master.c2
-rw-r--r--drivers/clk/clk-nomadik.c3
-rw-r--r--drivers/clk/clk.c13
-rw-r--r--drivers/clk/keystone/gate.c1
-rw-r--r--drivers/clk/mvebu/armada-370.c21
-rw-r--r--drivers/clk/mvebu/armada-xp.c20
-rw-r--r--drivers/clk/mvebu/dove.c19
-rw-r--r--drivers/clk/mvebu/kirkwood.c34
-rw-r--r--drivers/clk/shmobile/clk-rcar-gen2.c48
-rw-r--r--drivers/clk/tegra/clk-divider.c2
-rw-r--r--drivers/clk/tegra/clk-id.h4
-rw-r--r--drivers/clk/tegra/clk-tegra-periph.c10
-rw-r--r--drivers/clk/tegra/clk-tegra-super-gen4.c2
-rw-r--r--drivers/clk/tegra/clk-tegra114.c8
-rw-r--r--drivers/clk/tegra/clk-tegra124.c48
-rw-r--r--drivers/clk/tegra/clk-tegra20.c2
-rw-r--r--drivers/clocksource/bcm_kona_timer.c54
-rw-r--r--drivers/clocksource/vf_pit_timer.c2
-rw-r--r--drivers/cpufreq/Kconfig2
-rw-r--r--drivers/cpufreq/cpufreq.c58
-rw-r--r--drivers/cpufreq/intel_pstate.c61
-rw-r--r--drivers/cpufreq/powernow-k8.c10
-rw-r--r--drivers/cpuidle/cpuidle-powernv.c5
-rw-r--r--drivers/cpuidle/cpuidle-pseries.c6
-rw-r--r--drivers/crypto/nx/nx-842.c29
-rw-r--r--drivers/dma/Kconfig1
-rw-r--r--drivers/dma/imx-sdma.c1
-rw-r--r--drivers/dma/ioat/dma.c52
-rw-r--r--drivers/dma/ioat/dma.h1
-rw-r--r--drivers/dma/ioat/dma_v2.c11
-rw-r--r--drivers/dma/ioat/dma_v3.c3
-rw-r--r--drivers/dma/mv_xor.c24
-rw-r--r--drivers/dma/ste_dma40.c4
-rw-r--r--drivers/edac/edac_mc.c13
-rw-r--r--drivers/edac/edac_mc_sysfs.c10
-rw-r--r--drivers/edac/edac_module.h2
-rw-r--r--drivers/edac/i7300_edac.c38
-rw-r--r--drivers/edac/i7core_edac.c9
-rw-r--r--drivers/extcon/extcon-arizona.c12
-rw-r--r--drivers/firewire/core-device.c22
-rw-r--r--drivers/firewire/net.c6
-rw-r--r--drivers/firewire/ohci.c15
-rw-r--r--drivers/firewire/sbp2.c17
-rw-r--r--drivers/firmware/dcdbas.c2
-rw-r--r--drivers/firmware/efi/efi-stub-helper.c136
-rw-r--r--drivers/firmware/efi/efi.c5
-rw-r--r--drivers/firmware/efi/efivars.c2
-rw-r--r--drivers/fmc/fmc-write-eeprom.c2
-rw-r--r--drivers/gpio/Kconfig1
-rw-r--r--drivers/gpio/gpio-bcm-kona.c4
-rw-r--r--drivers/gpio/gpio-clps711x.c1
-rw-r--r--drivers/gpio/gpio-intel-mid.c4
-rw-r--r--drivers/gpio/gpio-xtensa.c16
-rw-r--r--drivers/gpu/drm/armada/armada_drv.c10
-rw-r--r--drivers/gpu/drm/ast/ast_fb.c2
-rw-r--r--drivers/gpu/drm/bochs/Kconfig1
-rw-r--r--drivers/gpu/drm/cirrus/cirrus_fbdev.c2
-rw-r--r--drivers/gpu/drm/drm_cache.c10
-rw-r--r--drivers/gpu/drm/drm_ioctl.c12
-rw-r--r--drivers/gpu/drm/drm_pci.c2
-rw-r--r--drivers/gpu/drm/exynos/Kconfig4
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.c18
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_g2d.c2
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_ipp.c3
-rw-r--r--drivers/gpu/drm/exynos/exynos_hdmi.c66
-rw-r--r--drivers/gpu/drm/i2c/tda998x_drv.c19
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c23
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h8
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.c2
-rw-r--r--drivers/gpu/drm/i915/i915_gem_stolen.c26
-rw-r--r--drivers/gpu/drm/i915/i915_gpu_error.c5
-rw-r--r--drivers/gpu/drm/i915/i915_irq.c74
-rw-r--r--drivers/gpu/drm/i915/intel_ddi.c1
-rw-r--r--drivers/gpu/drm/i915/intel_display.c22
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c43
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c6
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c7
-rw-r--r--drivers/gpu/drm/i915/intel_opregion.c9
-rw-r--r--drivers/gpu/drm/i915/intel_panel.c4
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c6
-rw-r--r--drivers/gpu/drm/i915/intel_ringbuffer.c21
-rw-r--r--drivers/gpu/drm/i915/intel_ringbuffer.h1
-rw-r--r--drivers/gpu/drm/mgag200/mgag200_fb.c2
-rw-r--r--drivers/gpu/drm/mgag200/mgag200_mode.c4
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c179
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c4
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c7
-rw-r--r--drivers/gpu/drm/msm/msm_gem.c2
-rw-r--r--drivers/gpu/drm/msm/msm_gem_submit.c9
-rw-r--r--drivers/gpu/drm/msm/msm_gpu.c3
-rw-r--r--drivers/gpu/drm/nouveau/Makefile1
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/device/nv40.c10
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/disp/nv50.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/graph/nv50.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/include/subdev/mc.h1
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/bios/base.c4
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/fb/nv1a.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/mc/nv04.h1
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/mc/nv44.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/mc/nv4c.c45
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_acpi.c26
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bo.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drm.c17
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_vga.c4
-rw-r--r--drivers/gpu/drm/radeon/atombios_crtc.c31
-rw-r--r--drivers/gpu/drm/radeon/atombios_encoders.c9
-rw-r--r--drivers/gpu/drm/radeon/btc_dpm.c32
-rw-r--r--drivers/gpu/drm/radeon/btcd.h4
-rw-r--r--drivers/gpu/drm/radeon/cik.c10
-rw-r--r--drivers/gpu/drm/radeon/cik_sdma.c14
-rw-r--r--drivers/gpu/drm/radeon/dce6_afmt.c15
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c7
-rw-r--r--drivers/gpu/drm/radeon/evergreen_hdmi.c26
-rw-r--r--drivers/gpu/drm/radeon/evergreen_smc.h2
-rw-r--r--drivers/gpu/drm/radeon/kv_dpm.c2
-rw-r--r--drivers/gpu/drm/radeon/ni.c3
-rw-r--r--drivers/gpu/drm/radeon/ni_dpm.c10
-rw-r--r--drivers/gpu/drm/radeon/r100.c2
-rw-r--r--drivers/gpu/drm/radeon/r300.c2
-rw-r--r--drivers/gpu/drm/radeon/r420.c2
-rw-r--r--drivers/gpu/drm/radeon/r520.c2
-rw-r--r--drivers/gpu/drm/radeon/r600.c7
-rw-r--r--drivers/gpu/drm/radeon/r600_audio.c14
-rw-r--r--drivers/gpu/drm/radeon/r600_cs.c18
-rw-r--r--drivers/gpu/drm/radeon/r600_hdmi.c15
-rw-r--r--drivers/gpu/drm/radeon/radeon.h10
-rw-r--r--drivers/gpu/drm/radeon/radeon_asic.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_asic.h2
-rw-r--r--drivers/gpu/drm/radeon/radeon_atpx_handler.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c5
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c20
-rw-r--r--drivers/gpu/drm/radeon/radeon_kms.c16
-rw-r--r--drivers/gpu/drm/radeon/radeon_ring.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_semaphore.c19
-rw-r--r--drivers/gpu/drm/radeon/radeon_ttm.c5
-rw-r--r--drivers/gpu/drm/radeon/radeon_uvd.c2
-rw-r--r--drivers/gpu/drm/radeon/reg_srcs/r6001
-rw-r--r--drivers/gpu/drm/radeon/rs400.c2
-rw-r--r--drivers/gpu/drm/radeon/rs600.c2
-rw-r--r--drivers/gpu/drm/radeon/rs690.c2
-rw-r--r--drivers/gpu/drm/radeon/rv515.c2
-rw-r--r--drivers/gpu/drm/radeon/rv770.c5
-rw-r--r--drivers/gpu/drm/radeon/rv770_dpm.c14
-rw-r--r--drivers/gpu/drm/radeon/si.c7
-rw-r--r--drivers/gpu/drm/radeon/si_dpm.c5
-rw-r--r--drivers/gpu/drm/radeon/sumo_dpm.c2
-rw-r--r--drivers/gpu/drm/radeon/trinity_dpm.c3
-rw-r--r--drivers/gpu/drm/radeon/uvd_v2_2.c1
-rw-r--r--drivers/gpu/drm/tegra/drm.c2
-rw-r--r--drivers/gpu/drm/tegra/rgb.c11
-rw-r--r--drivers/gpu/drm/ttm/ttm_agp_backend.c1
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c8
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c12
-rw-r--r--drivers/gpu/drm/ttm/ttm_object.c2
-rw-r--r--drivers/gpu/drm/ttm/ttm_tt.c3
-rw-r--r--drivers/gpu/drm/udl/udl_gem.c11
-rw-r--r--drivers/gpu/drm/vmwgfx/svga3d_reg.h153
-rw-r--r--drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h11
-rw-r--r--drivers/gpu/drm/vmwgfx/svga_reg.h9
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_context.c141
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c10
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h38
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c337
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c96
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_mob.c36
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c14
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_shader.c469
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_surface.c24
-rw-r--r--drivers/gpu/host1x/job.c2
-rw-r--r--drivers/hid/hid-apple.c3
-rw-r--r--drivers/hid/hid-core.c3
-rw-r--r--drivers/hid/hid-hyperv.c11
-rw-r--r--drivers/hid/hid-ids.h8
-rw-r--r--drivers/hid/hid-input.c2
-rw-r--r--drivers/hid/hid-lg4ff.c2
-rw-r--r--drivers/hid/hid-microsoft.c4
-rw-r--r--drivers/hid/hid-multitouch.c5
-rw-r--r--drivers/hid/hid-sensor-hub.c3
-rw-r--r--drivers/hid/hid-sony.c27
-rw-r--r--drivers/hid/hidraw.c4
-rw-r--r--drivers/hid/i2c-hid/i2c-hid.c2
-rw-r--r--drivers/hid/usbhid/hid-quirks.c1
-rw-r--r--drivers/hv/connection.c13
-rw-r--r--drivers/hwmon/da9055-hwmon.c4
-rw-r--r--drivers/hwmon/max1668.c2
-rw-r--r--drivers/hwmon/ntc_thermistor.c6
-rw-r--r--drivers/hwmon/pmbus/pmbus_core.c68
-rw-r--r--drivers/i2c/busses/Kconfig2
-rw-r--r--drivers/i2c/busses/i2c-cpm.c2
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c33
-rw-r--r--drivers/iio/accel/bma180.c16
-rw-r--r--drivers/iio/adc/max1363.c2
-rw-r--r--drivers/iio/gyro/Kconfig2
-rw-r--r--drivers/iio/gyro/st_gyro.h1
-rw-r--r--drivers/iio/gyro/st_gyro_core.c9
-rw-r--r--drivers/iio/gyro/st_gyro_i2c.c1
-rw-r--r--drivers/iio/gyro/st_gyro_spi.c1
-rw-r--r--drivers/iio/imu/adis16400.h1
-rw-r--r--drivers/iio/imu/adis16400_core.c10
-rw-r--r--drivers/iio/light/cm32181.c16
-rw-r--r--drivers/iio/light/cm36651.c45
-rw-r--r--drivers/iio/light/tsl2563.c16
-rw-r--r--drivers/iio/magnetometer/ak8975.c16
-rw-r--r--drivers/iio/magnetometer/mag3110.c8
-rw-r--r--drivers/infiniband/hw/amso1100/c2.c4
-rw-r--r--drivers/infiniband/hw/amso1100/c2_rnic.c3
-rw-r--r--drivers/infiniband/hw/cxgb4/cm.c1
-rw-r--r--drivers/infiniband/hw/mlx4/main.c189
-rw-r--r--drivers/infiniband/hw/mlx5/Kconfig2
-rw-r--r--drivers/infiniband/hw/mlx5/main.c26
-rw-r--r--drivers/infiniband/hw/mlx5/qp.c18
-rw-r--r--drivers/infiniband/hw/mlx5/user.h7
-rw-r--r--drivers/infiniband/hw/nes/nes.c5
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_main.c2
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_verbs.c4
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7322.c5
-rw-r--r--drivers/infiniband/hw/usnic/usnic_ib_qp_grp.c9
-rw-r--r--drivers/infiniband/ulp/iser/iser_initiator.c3
-rw-r--r--drivers/infiniband/ulp/iser/iser_verbs.c10
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.c181
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.h7
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c14
-rw-r--r--drivers/input/evdev.c4
-rw-r--r--drivers/input/keyboard/adp5588-keys.c12
-rw-r--r--drivers/input/misc/arizona-haptics.c19
-rw-r--r--drivers/input/misc/da9052_onkey.c29
-rw-r--r--drivers/input/mouse/cypress_ps2.c1
-rw-r--r--drivers/input/mouse/synaptics.c55
-rw-r--r--drivers/input/mousedev.c73
-rw-r--r--drivers/iommu/arm-smmu.c105
-rw-r--r--drivers/iommu/omap-iommu-debug.c4
-rw-r--r--drivers/irqchip/Makefile1
-rw-r--r--drivers/irqchip/irq-armada-370-xp.c4
-rw-r--r--drivers/irqchip/irq-metag-ext.c2
-rw-r--r--drivers/irqchip/irq-metag.c2
-rw-r--r--drivers/irqchip/irq-orion.c22
-rw-r--r--drivers/irqchip/irq-zevio.c127
-rw-r--r--drivers/isdn/capi/Kconfig18
-rw-r--r--drivers/isdn/hisax/q931.c2
-rw-r--r--drivers/md/Kconfig10
-rw-r--r--drivers/md/bcache/bcache.h4
-rw-r--r--drivers/md/bcache/bset.c7
-rw-r--r--drivers/md/bcache/btree.c4
-rw-r--r--drivers/md/bcache/extents.c2
-rw-r--r--drivers/md/bcache/request.c6
-rw-r--r--drivers/md/bcache/sysfs.c2
-rw-r--r--drivers/md/dm-cache-policy-mq.c4
-rw-r--r--drivers/md/dm-cache-target.c24
-rw-r--r--drivers/md/dm-io.c23
-rw-r--r--drivers/md/dm-mpath.c7
-rw-r--r--drivers/md/dm-raid1.c3
-rw-r--r--drivers/md/dm-snap-persistent.c3
-rw-r--r--drivers/md/dm-thin-metadata.c58
-rw-r--r--drivers/md/dm-thin-metadata.h21
-rw-r--r--drivers/md/dm-thin.c343
-rw-r--r--drivers/md/persistent-data/Kconfig10
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.c115
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.h11
-rw-r--r--drivers/md/raid1.c13
-rw-r--r--drivers/md/raid5.c90
-rw-r--r--drivers/media/dvb-frontends/cx24117.c10
-rw-r--r--drivers/media/dvb-frontends/nxt200x.c2
-rw-r--r--drivers/media/i2c/adv7842.c2
-rw-r--r--drivers/media/i2c/s5k5baf.c30
-rw-r--r--drivers/media/pci/bt8xx/bttv-cards.c2
-rw-r--r--drivers/media/pci/bt8xx/bttv-gpio.c2
-rw-r--r--drivers/media/pci/saa7134/saa7134-cards.c2
-rw-r--r--drivers/media/platform/exynos4-is/fimc-core.c5
-rw-r--r--drivers/media/platform/exynos4-is/fimc-lite.c7
-rw-r--r--drivers/media/platform/s5p-jpeg/jpeg-core.c8
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.c2
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c4
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c2
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c2
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c2
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c4
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h4
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf.c6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf.h2
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-core.c4
-rw-r--r--drivers/media/v4l2-core/v4l2-dv-timings.c1
-rw-r--r--drivers/media/v4l2-core/videobuf-dma-contig.c12
-rw-r--r--drivers/media/v4l2-core/videobuf-dma-sg.c10
-rw-r--r--drivers/media/v4l2-core/videobuf-vmalloc.c10
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c5
-rw-r--r--drivers/message/i2o/i2o_config.c4
-rw-r--r--drivers/mfd/da9055-i2c.c12
-rw-r--r--drivers/mfd/max14577.c2
-rw-r--r--drivers/mfd/max8997.c6
-rw-r--r--drivers/mfd/max8998.c6
-rw-r--r--drivers/mfd/sec-core.c2
-rw-r--r--drivers/mfd/tps65217.c4
-rw-r--r--drivers/mfd/wm8994-core.c2
-rw-r--r--drivers/misc/genwqe/card_dev.c1
-rw-r--r--drivers/misc/mei/client.c15
-rw-r--r--drivers/misc/mic/host/mic_virtio.c3
-rw-r--r--drivers/misc/sgi-gru/grukdump.c11
-rw-r--r--drivers/misc/sgi-xp/xpc_uv.c2
-rw-r--r--drivers/mmc/card/queue.c2
-rw-r--r--drivers/mmc/host/dw_mmc.c2
-rw-r--r--drivers/mtd/nand/nand_base.c2
-rw-r--r--drivers/mtd/nand/omap2.c61
-rw-r--r--drivers/mtd/ubi/fastmap.c8
-rw-r--r--drivers/net/Kconfig2
-rw-r--r--drivers/net/bonding/bond_3ad.c22
-rw-r--r--drivers/net/bonding/bond_3ad.h1
-rw-r--r--drivers/net/bonding/bond_alb.c2
-rw-r--r--drivers/net/bonding/bond_main.c159
-rw-r--r--drivers/net/bonding/bond_options.c3
-rw-r--r--drivers/net/bonding/bonding.h47
-rw-r--r--drivers/net/can/Kconfig2
-rw-r--r--drivers/net/can/dev.c15
-rw-r--r--drivers/net/can/flexcan.c179
-rw-r--r--drivers/net/can/janz-ican3.c20
-rw-r--r--drivers/net/can/usb/kvaser_usb.c2
-rw-r--r--drivers/net/can/vcan.c9
-rw-r--r--drivers/net/ethernet/3com/3c59x.c2
-rw-r--r--drivers/net/ethernet/allwinner/sun4i-emac.c3
-rw-r--r--drivers/net/ethernet/atheros/alx/main.c15
-rw-r--r--drivers/net/ethernet/atheros/atl1e/atl1e_main.c4
-rw-r--r--drivers/net/ethernet/broadcom/b44.c14
-rw-r--r--drivers/net/ethernet/broadcom/bnx2.c39
-rw-r--r--drivers/net/ethernet/broadcom/bnx2.h5
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c13
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h4
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c12
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c6
-rw-r--r--drivers/net/ethernet/broadcom/cnic.c111
-rw-r--r--drivers/net/ethernet/broadcom/cnic.h2
-rw-r--r--drivers/net/ethernet/broadcom/cnic_defs.h2
-rw-r--r--drivers/net/ethernet/broadcom/cnic_if.h16
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c25
-rw-r--r--drivers/net/ethernet/broadcom/tg3.h6
-rw-r--r--drivers/net/ethernet/brocade/bna/bfa_ioc.c2
-rw-r--r--drivers/net/ethernet/brocade/bna/bnad.c40
-rw-r--r--drivers/net/ethernet/cadence/macb.c16
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c1
-rw-r--r--drivers/net/ethernet/dec/tulip/tulip_core.c1
-rw-r--r--drivers/net/ethernet/emulex/benet/be.h4
-rw-r--r--drivers/net/ethernet/emulex/benet/be_main.c84
-rw-r--r--drivers/net/ethernet/ethoc.c138
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c31
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.c25
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.h1
-rw-r--r--drivers/net/ethernet/intel/e100.c2
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c6
-rw-r--r--drivers/net/ethernet/lantiq_etop.c2
-rw-r--r--drivers/net/ethernet/marvell/Kconfig6
-rw-r--r--drivers/net/ethernet/marvell/mvneta.c60
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_netdev.c10
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_tx.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/fw.c11
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/main.c20
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mlx4.h4
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mlx4_en.h6
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/Kconfig2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c4
-rw-r--r--drivers/net/ethernet/micrel/ks8851.c30
-rw-r--r--drivers/net/ethernet/neterion/vxge/vxge-main.c6
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c1
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c4
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c5
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c9
-rw-r--r--drivers/net/ethernet/qlogic/qlge/qlge_main.c4
-rw-r--r--drivers/net/ethernet/realtek/r8169.c4
-rw-r--r--drivers/net/ethernet/sfc/ptp.c7
-rw-r--r--drivers/net/ethernet/sfc/tx.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/Kconfig11
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/Makefile1
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/chain_mode.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/common.h20
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c330
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/ring_mode.c9
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac.h3
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c93
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c5
-rw-r--r--drivers/net/ethernet/ti/cpsw.c35
-rw-r--r--drivers/net/ethernet/ti/davinci_cpdma.c4
-rw-r--r--drivers/net/ethernet/ti/davinci_emac.c53
-rw-r--r--drivers/net/ethernet/tile/tilegx.c2
-rw-r--r--drivers/net/ethernet/via/via-rhine.c8
-rw-r--r--drivers/net/ethernet/xilinx/xilinx_axienet_main.c13
-rw-r--r--drivers/net/hyperv/netvsc_drv.c53
-rw-r--r--drivers/net/hyperv/rndis_filter.c21
-rw-r--r--drivers/net/ieee802154/at86rf230.c11
-rw-r--r--drivers/net/ifb.c3
-rw-r--r--drivers/net/irda/Kconfig7
-rw-r--r--drivers/net/irda/Makefile1
-rw-r--r--drivers/net/irda/ep7211-sir.c70
-rw-r--r--drivers/net/irda/irtty-sir.c1
-rw-r--r--drivers/net/macvlan.c12
-rw-r--r--drivers/net/phy/dp83640.c32
-rw-r--r--drivers/net/phy/mdio-sun4i.c3
-rw-r--r--drivers/net/phy/phy.c11
-rw-r--r--drivers/net/phy/phy_device.c57
-rw-r--r--drivers/net/team/team.c2
-rw-r--r--drivers/net/tun.c6
-rw-r--r--drivers/net/usb/Kconfig15
-rw-r--r--drivers/net/usb/Makefile3
-rw-r--r--drivers/net/usb/asix_devices.c3
-rw-r--r--drivers/net/usb/ax88179_178a.c46
-rw-r--r--drivers/net/usb/cdc_ether.c7
-rw-r--r--drivers/net/usb/cdc_ncm.c48
-rw-r--r--drivers/net/usb/gl620a.c4
-rw-r--r--drivers/net/usb/hso.c32
-rw-r--r--drivers/net/usb/mcs7830.c5
-rw-r--r--drivers/net/usb/net1080.c4
-rw-r--r--drivers/net/usb/qmi_wwan.c11
-rw-r--r--drivers/net/usb/r8152.c32
-rw-r--r--drivers/net/usb/r815x.c248
-rw-r--r--drivers/net/usb/rndis_host.c4
-rw-r--r--drivers/net/usb/smsc75xx.c4
-rw-r--r--drivers/net/usb/smsc95xx.c4
-rw-r--r--drivers/net/usb/sr9800.c874
-rw-r--r--drivers/net/usb/sr9800.h202
-rw-r--r--drivers/net/usb/usbnet.c58
-rw-r--r--drivers/net/veth.c6
-rw-r--r--drivers/net/virtio_net.c9
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c19
-rw-r--r--drivers/net/vxlan.c133
-rw-r--r--drivers/net/wan/dlci.c5
-rw-r--r--drivers/net/wireless/ath/ar5523/ar5523.c2
-rw-r--r--drivers/net/wireless/ath/ath5k/phy.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h4
-rw-r--r--drivers/net/wireless/ath/ath9k/htc.h2
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_init.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_main.c63
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c12
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c70
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c15
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c18
-rw-r--r--drivers/net/wireless/hostap/hostap_ap.c2
-rw-r--r--drivers/net/wireless/hostap/hostap_proc.c2
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/mac80211.c22
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/sta.c1
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/tx.c14
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-drv.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-modparams.h11
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-nvm-parse.c5
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/bt-coex.c7
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h4
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mac80211.c24
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mvm.h2
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/scan.c5
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/sta.c2
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/tx.c91
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/utils.c2
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/drv.c8
-rw-r--r--drivers/net/wireless/libertas/cfg.c2
-rw-r--r--drivers/net/wireless/mwifiex/11ac.c3
-rw-r--r--drivers/net/wireless/mwifiex/11n.c3
-rw-r--r--drivers/net/wireless/mwifiex/main.c2
-rw-r--r--drivers/net/wireless/mwifiex/pcie.c34
-rw-r--r--drivers/net/wireless/mwifiex/scan.c8
-rw-r--r--drivers/net/wireless/mwifiex/usb.c12
-rw-r--r--drivers/net/wireless/mwifiex/wmm.c3
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.c5
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c5
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c11
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c2
-rw-r--r--drivers/net/wireless/rtl818x/rtl8180/dev.c23
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187/rtl8187.h10
-rw-r--r--drivers/net/wireless/rtlwifi/ps.c2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/hw.c18
-rw-r--r--drivers/net/wireless/ti/wl1251/rx.c2
-rw-r--r--drivers/net/xen-netback/common.h6
-rw-r--r--drivers/net/xen-netback/interface.c4
-rw-r--r--drivers/net/xen-netback/netback.c55
-rw-r--r--drivers/net/xen-netfront.c6
-rw-r--r--drivers/of/address.c5
-rw-r--r--drivers/of/base.c128
-rw-r--r--drivers/of/of_mdio.c22
-rw-r--r--drivers/of/selftest.c67
-rw-r--r--drivers/of/testcase-data/testcases.dtsi3
-rw-r--r--drivers/of/testcase-data/tests-interrupts.dtsi (renamed from arch/arm/boot/dts/testcases/tests-interrupts.dtsi)0
-rw-r--r--drivers/of/testcase-data/tests-match.dtsi19
-rw-r--r--drivers/of/testcase-data/tests-phandle.dtsi (renamed from arch/arm/boot/dts/testcases/tests-phandle.dtsi)0
-rw-r--r--drivers/pci/bus.c2
-rw-r--r--drivers/pci/host/pci-mvebu.c11
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c70
-rw-r--r--drivers/pci/msi.c10
-rw-r--r--drivers/pci/pci.c13
-rw-r--r--drivers/phy/Kconfig3
-rw-r--r--drivers/phy/phy-core.c76
-rw-r--r--drivers/phy/phy-exynos-dp-video.c8
-rw-r--r--drivers/phy/phy-exynos-mipi-video.c10
-rw-r--r--drivers/phy/phy-mvebu-sata.c10
-rw-r--r--drivers/phy/phy-omap-usb2.c10
-rw-r--r--drivers/phy/phy-twl4030-usb.c10
-rw-r--r--drivers/pinctrl/Kconfig2
-rw-r--r--drivers/pinctrl/core.c8
-rw-r--r--drivers/pinctrl/pinctrl-at91.c10
-rw-r--r--drivers/pinctrl/pinctrl-capri.c2
-rw-r--r--drivers/pinctrl/pinctrl-imx1-core.c10
-rw-r--r--drivers/pinctrl/pinctrl-sunxi.c6
-rw-r--r--drivers/pinctrl/pinctrl-sunxi.h6
-rw-r--r--drivers/pinctrl/pinctrl-tegra.c2
-rw-r--r--drivers/pinctrl/sh-pfc/pfc-r8a7791.c6
-rw-r--r--drivers/pinctrl/sirf/pinctrl-prima2.c2
-rw-r--r--drivers/pinctrl/sirf/pinctrl-sirf.c4
-rw-r--r--drivers/pinctrl/vt8500/pinctrl-wmt.c15
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c15
-rw-r--r--drivers/pnp/pnpbios/bioscalls.c9
-rw-r--r--drivers/power/ds2782_battery.c2
-rw-r--r--drivers/power/isp1704_charger.c2
-rw-r--r--drivers/power/max17040_battery.c5
-rw-r--r--drivers/ps3/ps3-vuart.c4
-rw-r--r--drivers/pwm/pwm-lp3943.c4
-rw-r--r--drivers/rapidio/devices/tsi721.h1
-rw-r--r--drivers/rapidio/devices/tsi721_dma.c27
-rw-r--r--drivers/regulator/ab3100.c4
-rw-r--r--drivers/regulator/core.c59
-rw-r--r--drivers/regulator/da9055-regulator.c4
-rw-r--r--drivers/regulator/da9063-regulator.c4
-rw-r--r--drivers/regulator/max14577.c10
-rw-r--r--drivers/regulator/s2mps11.c1
-rw-r--r--drivers/regulator/s5m8767.c4
-rw-r--r--drivers/rtc/rtc-s3c.c17
-rw-r--r--drivers/s390/char/con3215.c8
-rw-r--r--drivers/s390/char/con3270.c13
-rw-r--r--drivers/s390/char/raw3270.c26
-rw-r--r--drivers/s390/char/raw3270.h3
-rw-r--r--drivers/s390/char/sclp_early.c31
-rw-r--r--drivers/s390/cio/airq.c66
-rw-r--r--drivers/s390/cio/chsc.c1
-rw-r--r--drivers/s390/cio/chsc_sch.c3
-rw-r--r--drivers/s390/cio/cio.c44
-rw-r--r--drivers/s390/cio/device.c52
-rw-r--r--drivers/s390/cio/qdio.h14
-rw-r--r--drivers/s390/cio/qdio_main.c2
-rw-r--r--drivers/s390/crypto/zcrypt_msgtype6.c24
-rw-r--r--drivers/s390/net/qeth_core_main.c9
-rw-r--r--drivers/s390/net/qeth_l2_main.c3
-rw-r--r--drivers/s390/net/qeth_l3_main.c3
-rw-r--r--drivers/sbus/char/jsflash.c1
-rw-r--r--drivers/scsi/atari_scsi.c12
-rw-r--r--drivers/scsi/be2iscsi/be_main.c2
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_io.c16
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_tgt.c38
-rw-r--r--drivers/scsi/bnx2i/bnx2i_hwi.c52
-rw-r--r--drivers/scsi/bnx2i/bnx2i_iscsi.c23
-rw-r--r--drivers/scsi/isci/host.h5
-rw-r--r--drivers/scsi/isci/port_config.c7
-rw-r--r--drivers/scsi/isci/task.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h3
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c46
-rw-r--r--drivers/scsi/qla2xxx/qla_target.c44
-rw-r--r--drivers/scsi/qla2xxx/qla_target.h3
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.c158
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.h7
-rw-r--r--drivers/scsi/scsi_lib.c2
-rw-r--r--drivers/scsi/storvsc_drv.c3
-rw-r--r--drivers/spi/Kconfig4
-rw-r--r--drivers/spi/spi-ath79.c4
-rw-r--r--drivers/spi/spi-atmel.c17
-rw-r--r--drivers/spi/spi-coldfire-qspi.c6
-rw-r--r--drivers/spi/spi-fsl-dspi.c6
-rw-r--r--drivers/spi/spi-imx.c4
-rw-r--r--drivers/spi/spi-nuc900.c2
-rw-r--r--drivers/spi/spi-topcliff-pch.c15
-rw-r--r--drivers/spi/spi.c4
-rw-r--r--drivers/staging/android/ashmem.c45
-rw-r--r--drivers/staging/android/binder.c3
-rw-r--r--drivers/staging/android/ion/compat_ion.c26
-rw-r--r--drivers/staging/android/ion/ion_dummy_driver.c12
-rw-r--r--drivers/staging/android/ion/ion_heap.c2
-rw-r--r--drivers/staging/android/ion/ion_priv.h1
-rw-r--r--drivers/staging/android/ion/ion_system_heap.c6
-rw-r--r--drivers/staging/android/sw_sync.h17
-rw-r--r--drivers/staging/android/sync.c14
-rw-r--r--drivers/staging/bcm/Bcmnet.c2
-rw-r--r--drivers/staging/comedi/drivers.c2
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1710.c17
-rw-r--r--drivers/staging/comedi/drivers/usbduxsigma.c6
-rw-r--r--drivers/staging/cxt1e1/linux.c2
-rw-r--r--drivers/staging/dgrp/dgrp_net_ops.c330
-rw-r--r--drivers/staging/fwserial/fwserial.c13
-rw-r--r--drivers/staging/fwserial/fwserial.h1
-rw-r--r--drivers/staging/gdm72xx/gdm_usb.c3
-rw-r--r--drivers/staging/iio/Documentation/iio_utils.h6
-rw-r--r--drivers/staging/iio/adc/ad799x_core.c13
-rw-r--r--drivers/staging/iio/adc/mxs-lradc.c7
-rw-r--r--drivers/staging/iio/impedance-analyzer/ad5933.c2
-rw-r--r--drivers/staging/imx-drm/imx-drm-core.c55
-rw-r--r--drivers/staging/imx-drm/imx-hdmi.c22
-rw-r--r--drivers/staging/lustre/TODO5
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h2
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_private.h2
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c2
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c5
-rw-r--r--drivers/staging/lustre/lustre/include/lustre/lustre_user.h3
-rw-r--r--drivers/staging/lustre/lustre/llite/dir.c2
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_request.c6
-rw-r--r--drivers/staging/media/go7007/go7007-loader.c4
-rw-r--r--drivers/staging/netlogic/xlr_net.c7
-rw-r--r--drivers/staging/octeon-usb/octeon-hcd.c273
-rw-r--r--drivers/staging/ozwpan/ozproto.c3
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_wlan_util.c22
-rw-r--r--drivers/staging/rtl8188eu/os_dep/ioctl_linux.c12
-rw-r--r--drivers/staging/rtl8188eu/os_dep/os_intfs.c2
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_intf.c3
-rw-r--r--drivers/staging/rtl8821ae/Kconfig2
-rw-r--r--drivers/staging/rtl8821ae/wifi.h2
-rw-r--r--drivers/staging/usbip/userspace/libsrc/names.c8
-rw-r--r--drivers/staging/usbip/vhci_sysfs.c3
-rw-r--r--drivers/staging/wlags49_h2/wl_wext.c2
-rw-r--r--drivers/target/iscsi/iscsi_target.c10
-rw-r--r--drivers/target/iscsi/iscsi_target_erl1.c4
-rw-r--r--drivers/target/iscsi/iscsi_target_erl2.c16
-rw-r--r--drivers/target/iscsi/iscsi_target_tpg.c2
-rw-r--r--drivers/target/target_core_alua.c2
-rw-r--r--drivers/target/target_core_pr.c11
-rw-r--r--drivers/target/target_core_sbc.c39
-rw-r--r--drivers/target/target_core_spc.c4
-rw-r--r--drivers/target/target_core_transport.c8
-rw-r--r--drivers/thermal/Kconfig13
-rw-r--r--drivers/thermal/thermal_core.c27
-rw-r--r--drivers/thermal/x86_pkg_temp_thermal.c11
-rw-r--r--drivers/tty/hvc/hvc_opal.c8
-rw-r--r--drivers/tty/hvc/hvc_rtas.c12
-rw-r--r--drivers/tty/hvc/hvc_udbg.c9
-rw-r--r--drivers/tty/hvc/hvc_xen.c17
-rw-r--r--drivers/tty/n_gsm.c11
-rw-r--r--drivers/tty/n_tty.c14
-rw-r--r--drivers/tty/serial/8250/8250_core.c18
-rw-r--r--drivers/tty/serial/8250/8250_dw.c4
-rw-r--r--drivers/tty/serial/8250/8250_pci.c3
-rw-r--r--drivers/tty/serial/omap-serial.c11
-rw-r--r--drivers/tty/serial/sirfsoc_uart.c4
-rw-r--r--drivers/tty/serial/sunhv.c22
-rw-r--r--drivers/tty/serial/sunsab.c14
-rw-r--r--drivers/tty/serial/sunsu.c14
-rw-r--r--drivers/tty/serial/sunzilog.c14
-rw-r--r--drivers/tty/tty_ldsem.c15
-rw-r--r--drivers/tty/vt/vt.c2
-rw-r--r--drivers/usb/chipidea/udc.c4
-rw-r--r--drivers/usb/core/config.c4
-rw-r--r--drivers/usb/core/driver.c24
-rw-r--r--drivers/usb/core/hcd.c1
-rw-r--r--drivers/usb/core/hub.c11
-rw-r--r--drivers/usb/core/quirks.c4
-rw-r--r--drivers/usb/core/usb.h1
-rw-r--r--drivers/usb/dwc2/core.c2
-rw-r--r--drivers/usb/dwc2/hcd.c11
-rw-r--r--drivers/usb/dwc2/platform.c3
-rw-r--r--drivers/usb/gadget/bcm63xx_udc.c58
-rw-r--r--drivers/usb/gadget/f_fs.c7
-rw-r--r--drivers/usb/gadget/printer.c2
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c13
-rw-r--r--drivers/usb/host/ehci-hub.c26
-rw-r--r--drivers/usb/host/xhci-dbg.c6
-rw-r--r--drivers/usb/host/xhci-mem.c14
-rw-r--r--drivers/usb/host/xhci-pci.c5
-rw-r--r--drivers/usb/host/xhci-ring.c68
-rw-r--r--drivers/usb/host/xhci.c24
-rw-r--r--drivers/usb/host/xhci.h41
-rw-r--r--drivers/usb/musb/musb_core.c15
-rw-r--r--drivers/usb/musb/musb_host.c3
-rw-r--r--drivers/usb/musb/musb_virthub.c26
-rw-r--r--drivers/usb/musb/omap2430.c2
-rw-r--r--drivers/usb/phy/phy-msm-usb.c57
-rw-r--r--drivers/usb/phy/phy.c8
-rw-r--r--drivers/usb/serial/ftdi_sio.c5
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h13
-rw-r--r--drivers/usb/serial/option.c6
-rw-r--r--drivers/usb/serial/qcserial.c3
-rw-r--r--drivers/usb/serial/usb-serial-simple.c3
-rw-r--r--drivers/usb/storage/Kconfig4
-rw-r--r--drivers/usb/storage/scsiglue.c6
-rw-r--r--drivers/usb/storage/unusual_cypress.h2
-rw-r--r--drivers/usb/storage/unusual_devs.h7
-rw-r--r--drivers/vfio/vfio_iommu_type1.c4
-rw-r--r--drivers/vhost/net.c67
-rw-r--r--drivers/vhost/scsi.c6
-rw-r--r--drivers/video/Kconfig2
-rw-r--r--drivers/video/exynos/Kconfig3
-rw-r--r--drivers/video/omap2/dss/dispc.c16
-rw-r--r--drivers/video/omap2/dss/dpi.c2
-rw-r--r--drivers/video/omap2/dss/sdi.c2
-rw-r--r--drivers/vme/bridges/vme_ca91cx42.c4
-rw-r--r--drivers/vme/bridges/vme_tsi148.c4
-rw-r--r--drivers/watchdog/Kconfig1
-rw-r--r--drivers/watchdog/w83697hf_wdt.c2
-rw-r--r--drivers/xen/Makefile1
-rw-r--r--drivers/xen/balloon.c24
-rw-r--r--drivers/xen/events/events_base.c2
-rw-r--r--drivers/xen/gntdev.c13
-rw-r--r--drivers/xen/grant-table.c89
-rw-r--r--drivers/xen/xencomm.c219
-rw-r--r--fs/afs/internal.h1
-rw-r--r--fs/afs/rxrpc.c12
-rw-r--r--fs/anon_inodes.c34
-rw-r--r--fs/bio-integrity.c18
-rw-r--r--fs/bio.c15
-rw-r--r--fs/btrfs/check-integrity.c4
-rw-r--r--fs/btrfs/compression.c2
-rw-r--r--fs/btrfs/disk-io.c5
-rw-r--r--fs/btrfs/extent-tree.c1
-rw-r--r--fs/btrfs/inode.c4
-rw-r--r--fs/btrfs/ioctl.c22
-rw-r--r--fs/btrfs/send.c22
-rw-r--r--fs/btrfs/super.c13
-rw-r--r--fs/btrfs/sysfs.c10
-rw-r--r--fs/buffer.c6
-rw-r--r--fs/ceph/acl.c11
-rw-r--r--fs/ceph/dir.c23
-rw-r--r--fs/ceph/file.c1
-rw-r--r--fs/ceph/super.c32
-rw-r--r--fs/ceph/super.h7
-rw-r--r--fs/ceph/xattr.c54
-rw-r--r--fs/cifs/cifsacl.c61
-rw-r--r--fs/cifs/cifsglob.h13
-rw-r--r--fs/cifs/cifsproto.h9
-rw-r--r--fs/cifs/cifssmb.c15
-rw-r--r--fs/cifs/dir.c2
-rw-r--r--fs/cifs/file.c94
-rw-r--r--fs/cifs/inode.c15
-rw-r--r--fs/cifs/smb1ops.c9
-rw-r--r--fs/cifs/smb2glob.h3
-rw-r--r--fs/cifs/smb2ops.c14
-rw-r--r--fs/cifs/smb2pdu.c9
-rw-r--r--fs/cifs/smb2proto.h3
-rw-r--r--fs/cifs/transport.c29
-rw-r--r--fs/cifs/xattr.c15
-rw-r--r--fs/compat.c121
-rw-r--r--fs/compat_binfmt_elf.c5
-rw-r--r--fs/compat_ioctl.c5
-rw-r--r--fs/dcache.c4
-rw-r--r--fs/efivarfs/file.c13
-rw-r--r--fs/exec.c51
-rw-r--r--fs/ext4/ext4.h2
-rw-r--r--fs/ext4/extents.c1
-rw-r--r--fs/ext4/file.c2
-rw-r--r--fs/ext4/inode.c15
-rw-r--r--fs/ext4/ioctl.c3
-rw-r--r--fs/ext4/resize.c34
-rw-r--r--fs/ext4/super.c20
-rw-r--r--fs/file.c49
-rw-r--r--fs/file_table.c1
-rw-r--r--fs/fs-writeback.c33
-rw-r--r--fs/fscache/object-list.c5
-rw-r--r--fs/fscache/object.c3
-rw-r--r--fs/hfsplus/catalog.c41
-rw-r--r--fs/hfsplus/hfsplus_fs.h1
-rw-r--r--fs/hfsplus/hfsplus_raw.h6
-rw-r--r--fs/hfsplus/inode.c9
-rw-r--r--fs/hfsplus/options.c2
-rw-r--r--fs/jbd2/transaction.c6
-rw-r--r--fs/jfs/acl.c2
-rw-r--r--fs/jfs/xattr.c14
-rw-r--r--fs/kernfs/dir.c12
-rw-r--r--fs/kernfs/mount.c8
-rw-r--r--fs/lockd/svclock.c8
-rw-r--r--fs/mount.h4
-rw-r--r--fs/namei.c61
-rw-r--r--fs/namespace.c177
-rw-r--r--fs/nfs/delegation.c11
-rw-r--r--fs/nfs/dir.c5
-rw-r--r--fs/nfs/inode.c14
-rw-r--r--fs/nfs/internal.h12
-rw-r--r--fs/nfs/nfs3acl.c34
-rw-r--r--fs/nfs/nfs3proc.c1
-rw-r--r--fs/nfs/nfs4client.c9
-rw-r--r--fs/nfs/nfs4filelayout.c10
-rw-r--r--fs/nfs/nfs4namespace.c12
-rw-r--r--fs/nfs/nfs4proc.c32
-rw-r--r--fs/nfs/nfs4session.c25
-rw-r--r--fs/nfs/nfs4session.h2
-rw-r--r--fs/nfs/nfs4state.c19
-rw-r--r--fs/nfsd/nfs4acl.c9
-rw-r--r--fs/nfsd/vfs.c1
-rw-r--r--fs/notify/dnotify/dnotify.c2
-rw-r--r--fs/notify/fanotify/fanotify.c8
-rw-r--r--fs/notify/fanotify/fanotify_user.c13
-rw-r--r--fs/notify/fsnotify.c2
-rw-r--r--fs/notify/group.c8
-rw-r--r--fs/notify/inotify/inotify.h2
-rw-r--r--fs/notify/inotify/inotify_fsnotify.c3
-rw-r--r--fs/notify/inotify/inotify_user.c14
-rw-r--r--fs/notify/notification.c20
-rw-r--r--fs/ntfs/file.c2
-rw-r--r--fs/ocfs2/alloc.c40
-rw-r--r--fs/ocfs2/file.c60
-rw-r--r--fs/ocfs2/localalloc.c42
-rw-r--r--fs/ocfs2/localalloc.h6
-rw-r--r--fs/ocfs2/namei.c17
-rw-r--r--fs/ocfs2/quota_global.c27
-rw-r--r--fs/ocfs2/quota_local.c4
-rw-r--r--fs/ocfs2/stackglue.c4
-rw-r--r--fs/open.c4
-rw-r--r--fs/pnode.c26
-rw-r--r--fs/pnode.h4
-rw-r--r--fs/posix_acl.c18
-rw-r--r--fs/proc/base.c1
-rw-r--r--fs/proc/page.c5
-rw-r--r--fs/proc/vmcore.c26
-rw-r--r--fs/quota/dquot.c14
-rw-r--r--fs/read_write.c80
-rw-r--r--fs/reiserfs/do_balan.c895
-rw-r--r--fs/sync.c32
-rw-r--r--fs/sysfs/mount.c5
-rw-r--r--fs/udf/file.c14
-rw-r--r--fs/udf/inode.c1
-rw-r--r--fs/xfs/xfs_file.c2
-rw-r--r--fs/xfs/xfs_iops.c16
-rw-r--r--fs/xfs/xfs_log_cil.c19
-rw-r--r--fs/xfs/xfs_mount.c24
-rw-r--r--fs/xfs/xfs_sb.c10
-rw-r--r--fs/xfs/xfs_super.c2
-rw-r--r--include/asm-generic/bitops/const_hweight.h17
-rw-r--r--include/asm-generic/mcs_spinlock.h13
-rw-r--r--include/asm-generic/pgtable.h52
-rw-r--r--include/asm-generic/rwsem.h10
-rw-r--r--include/drm/drmP.h3
-rw-r--r--include/drm/drm_crtc.h3
-rw-r--r--include/drm/ttm/ttm_page_alloc.h2
-rw-r--r--include/dt-bindings/clock/tegra124-car.h4
-rw-r--r--include/kvm/arm_vgic.h5
-rw-r--r--include/linux/audit.h3
-rw-r--r--include/linux/binfmts.h1
-rw-r--r--include/linux/bio.h12
-rw-r--r--include/linux/bitops.h15
-rw-r--r--include/linux/blk-mq.h16
-rw-r--r--include/linux/blkdev.h11
-rw-r--r--include/linux/can/skb.h38
-rw-r--r--include/linux/ceph/ceph_fs.h5
-rw-r--r--include/linux/cgroup.h2
-rw-r--r--include/linux/clk/ti.h4
-rw-r--r--include/linux/compat.h63
-rw-r--r--include/linux/compiler-gcc4.h6
-rw-r--r--include/linux/dma-buf.h2
-rw-r--r--include/linux/efi.h268
-rw-r--r--include/linux/file.h27
-rw-r--r--include/linux/firewire.h1
-rw-r--r--include/linux/fs.h17
-rw-r--r--include/linux/fsnotify_backend.h4
-rw-r--r--include/linux/ftrace_event.h4
-rw-r--r--include/linux/futex.h4
-rw-r--r--include/linux/gfp.h4
-rw-r--r--include/linux/gpio/consumer.h4
-rw-r--r--include/linux/huge_mm.h41
-rw-r--r--include/linux/hyperv.h2
-rw-r--r--include/linux/init.h20
-rw-r--r--include/linux/interrupt.h5
-rw-r--r--include/linux/io.h2
-rw-r--r--include/linux/ipc_namespace.h2
-rw-r--r--include/linux/irq_work.h4
-rw-r--r--include/linux/kernel.h2
-rw-r--r--include/linux/kernfs.h9
-rw-r--r--include/linux/kexec.h6
-rw-r--r--include/linux/linkage.h4
-rw-r--r--include/linux/lockdep.h29
-rw-r--r--include/linux/mfd/max8997-private.h2
-rw-r--r--include/linux/mfd/max8998-private.h2
-rw-r--r--include/linux/mfd/tps65217.h4
-rw-r--r--include/linux/mlx5/driver.h3
-rw-r--r--include/linux/mm.h30
-rw-r--r--include/linux/mmzone.h4
-rw-r--r--include/linux/mutex.h5
-rw-r--r--include/linux/netdev_features.h7
-rw-r--r--include/linux/netdevice.h38
-rw-r--r--include/linux/nfs_xdr.h7
-rw-r--r--include/linux/nvme.h7
-rw-r--r--include/linux/of.h153
-rw-r--r--include/linux/of_device.h4
-rw-r--r--include/linux/page-flags.h4
-rw-r--r--include/linux/pci.h20
-rw-r--r--include/linux/pci_ids.h3
-rw-r--r--include/linux/phy/phy.h14
-rw-r--r--include/linux/rculist.h17
-rw-r--r--include/linux/rcupdate.h96
-rw-r--r--include/linux/rcutiny.h20
-rw-r--r--include/linux/rcutree.h8
-rw-r--r--include/linux/rmap.h3
-rw-r--r--include/linux/sched.h47
-rw-r--r--include/linux/sched/prio.h44
-rw-r--r--include/linux/sched/rt.h26
-rw-r--r--include/linux/security.h10
-rw-r--r--include/linux/skbuff.h26
-rw-r--r--include/linux/slab.h2
-rw-r--r--include/linux/smp.h3
-rw-r--r--include/linux/spi/spi.h7
-rw-r--r--include/linux/srcu.h4
-rw-r--r--include/linux/syscalls.h8
-rw-r--r--include/linux/torture.h100
-rw-r--r--include/linux/tracepoint.h6
-rw-r--r--include/linux/usb.h2
-rw-r--r--include/linux/usb/cdc_ncm.h1
-rw-r--r--include/linux/usb/usbnet.h2
-rw-r--r--include/linux/vm_event_item.h4
-rw-r--r--include/linux/vmstat.h8
-rw-r--r--include/linux/workqueue.h43
-rw-r--r--include/linux/writeback.h2
-rw-r--r--include/net/datalink.h2
-rw-r--r--include/net/dn.h2
-rw-r--r--include/net/dn_route.h2
-rw-r--r--include/net/ethoc.h1
-rw-r--r--include/net/if_inet6.h4
-rw-r--r--include/net/ip_tunnels.h1
-rw-r--r--include/net/ipx.h11
-rw-r--r--include/net/net_namespace.h8
-rw-r--r--include/net/netfilter/nf_conntrack.h2
-rw-r--r--include/net/netfilter/nf_tables.h9
-rw-r--r--include/net/netfilter/nft_reject.h25
-rw-r--r--include/net/sctp/structs.h14
-rw-r--r--include/net/sock.h6
-rw-r--r--include/net/tcp.h14
-rw-r--r--include/net/xfrm.h11
-rw-r--r--include/rdma/ib_verbs.h3
-rw-r--r--include/sound/soc-dapm.h8
-rw-r--r--include/target/iscsi/iscsi_transport.h1
-rw-r--r--include/target/target_core_base.h1
-rw-r--r--include/trace/events/power.h7
-rw-r--r--include/trace/events/sunrpc.h4
-rw-r--r--include/trace/events/writeback.h6
-rw-r--r--include/trace/ftrace.h7
-rw-r--r--include/uapi/asm-generic/unistd.h7
-rw-r--r--include/uapi/drm/drm.h2
-rw-r--r--include/uapi/drm/vmwgfx_drm.h1
-rw-r--r--include/uapi/linux/btrfs.h1
-rw-r--r--include/uapi/linux/in6.h23
-rw-r--r--include/uapi/linux/mic_ioctl.h2
-rw-r--r--include/uapi/linux/nvme.h11
-rw-r--r--include/uapi/xen/Kbuild2
-rw-r--r--include/uapi/xen/gntalloc.h (renamed from include/xen/gntalloc.h)0
-rw-r--r--include/uapi/xen/gntdev.h (renamed from include/xen/gntdev.h)0
-rw-r--r--include/xen/grant_table.h8
-rw-r--r--include/xen/interface/io/blkif.h34
-rw-r--r--include/xen/interface/xencomm.h41
-rw-r--r--include/xen/xencomm.h77
-rw-r--r--init/Kconfig7
-rw-r--r--init/main.c4
-rw-r--r--ipc/compat.c13
-rw-r--r--ipc/compat_mq.c32
-rw-r--r--ipc/mq_sysctl.c18
-rw-r--r--ipc/mqueue.c6
-rw-r--r--ipc/msg.c2
-rw-r--r--kernel/Makefile5
-rw-r--r--kernel/audit.c43
-rw-r--r--kernel/audit.h2
-rw-r--r--kernel/audit_tree.c2
-rw-r--r--kernel/audit_watch.c2
-rw-r--r--kernel/auditfilter.c10
-rw-r--r--kernel/auditsc.c2
-rw-r--r--kernel/cgroup.c71
-rw-r--r--kernel/compat.c100
-rw-r--r--kernel/cpu/Makefile1
-rw-r--r--kernel/cpuset.c10
-rw-r--r--kernel/debug/debug_core.c2
-rw-r--r--kernel/events/core.c51
-rw-r--r--kernel/extable.c2
-rw-r--r--kernel/fork.c1
-rw-r--r--kernel/futex.c90
-rw-r--r--kernel/irq/Kconfig1
-rw-r--r--kernel/irq/devres.c45
-rw-r--r--kernel/irq/irqdesc.c1
-rw-r--r--kernel/irq/irqdomain.c1
-rw-r--r--kernel/irq/manage.c3
-rw-r--r--kernel/irq_work.c6
-rw-r--r--kernel/kexec.c8
-rw-r--r--kernel/kmod.c2
-rw-r--r--kernel/ksysfs.c2
-rw-r--r--kernel/locking/Makefile3
-rw-r--r--kernel/locking/lockdep.c23
-rw-r--r--kernel/locking/locktorture.c452
-rw-r--r--kernel/locking/mcs_spinlock.c178
-rw-r--r--kernel/locking/mcs_spinlock.h129
-rw-r--r--kernel/locking/mutex-debug.c6
-rw-r--r--kernel/locking/mutex.c104
-rw-r--r--kernel/locking/rtmutex.c12
-rw-r--r--kernel/locking/rwsem-xadd.c4
-rw-r--r--kernel/module.c6
-rw-r--r--kernel/notifier.c2
-rw-r--r--kernel/panic.c4
-rw-r--r--kernel/power/console.c1
-rw-r--r--kernel/printk/printk.c2
-rw-r--r--kernel/profile.c4
-rw-r--r--kernel/ptrace.c4
-rw-r--r--kernel/rcu/Makefile2
-rw-r--r--kernel/rcu/rcu.h7
-rw-r--r--kernel/rcu/rcutorture.c (renamed from kernel/rcu/torture.c)1004
-rw-r--r--kernel/rcu/srcu.c11
-rw-r--r--kernel/rcu/tiny.c8
-rw-r--r--kernel/rcu/tiny_plugin.h4
-rw-r--r--kernel/rcu/tree.c80
-rw-r--r--kernel/rcu/tree.h4
-rw-r--r--kernel/rcu/tree_plugin.h19
-rw-r--r--kernel/rcu/tree_trace.c6
-rw-r--r--kernel/rcu/update.c5
-rw-r--r--kernel/sched/Makefile2
-rw-r--r--kernel/sched/auto_group.c2
-rw-r--r--kernel/sched/clock.c4
-rw-r--r--kernel/sched/core.c248
-rw-r--r--kernel/sched/cpudeadline.c6
-rw-r--r--kernel/sched/cputime.c4
-rw-r--r--kernel/sched/deadline.c76
-rw-r--r--kernel/sched/debug.c7
-rw-r--r--kernel/sched/fair.c610
-rw-r--r--kernel/sched/idle.c (renamed from kernel/cpu/idle.c)7
-rw-r--r--kernel/sched/idle_task.c25
-rw-r--r--kernel/sched/rt.c110
-rw-r--r--kernel/sched/sched.h66
-rw-r--r--kernel/sched/stop_task.c15
-rw-r--r--kernel/stop_machine.c2
-rw-r--r--kernel/sys.c8
-rw-r--r--kernel/sysctl.c7
-rw-r--r--kernel/time/jiffies.c6
-rw-r--r--kernel/time/sched_clock.c46
-rw-r--r--kernel/time/tick-broadcast.c1
-rw-r--r--kernel/time/timekeeping.c3
-rw-r--r--kernel/timer.c2
-rw-r--r--kernel/torture.c719
-rw-r--r--kernel/trace/ring_buffer.c7
-rw-r--r--kernel/trace/ring_buffer_benchmark.c6
-rw-r--r--kernel/trace/trace.c27
-rw-r--r--kernel/trace/trace_event_perf.c22
-rw-r--r--kernel/trace/trace_events.c16
-rw-r--r--kernel/trace/trace_export.c7
-rw-r--r--kernel/trace/trace_irqsoff.c4
-rw-r--r--kernel/tracepoint.c7
-rw-r--r--kernel/user_namespace.c2
-rw-r--r--kernel/workqueue.c9
-rw-r--r--lib/Kconfig.debug22
-rw-r--r--lib/Makefile1
-rw-r--r--lib/dma-debug.c131
-rw-r--r--lib/fonts/Kconfig6
-rw-r--r--lib/percpu_ida.c7
-rw-r--r--lib/radix-tree.c4
-rw-r--r--lib/random32.c13
-rw-r--r--lib/string.c2
-rw-r--r--mm/Kconfig4
-rw-r--r--mm/compaction.c20
-rw-r--r--mm/filemap.c4
-rw-r--r--mm/fremap.c28
-rw-r--r--mm/huge_memory.c20
-rw-r--r--mm/ksm.c2
-rw-r--r--mm/memcontrol.c20
-rw-r--r--mm/memory-failure.c8
-rw-r--r--mm/memory.c15
-rw-r--r--mm/mempolicy.c92
-rw-r--r--mm/migrate.c43
-rw-r--r--mm/mmu_context.c3
-rw-r--r--mm/mprotect.c25
-rw-r--r--mm/page-writeback.c5
-rw-r--r--mm/page_alloc.c30
-rw-r--r--mm/percpu.c208
-rw-r--r--mm/process_vm_access.c26
-rw-r--r--mm/rmap.c15
-rw-r--r--mm/slub.c38
-rw-r--r--mm/swap.c4
-rw-r--r--mm/swap_state.c63
-rw-r--r--mm/swapfile.c11
-rw-r--r--mm/vmpressure.c1
-rw-r--r--mm/vmstat.c4
-rw-r--r--net/8021q/vlan.c4
-rw-r--r--net/8021q/vlan_dev.c9
-rw-r--r--net/9p/client.c2
-rw-r--r--net/9p/trans_virtio.c5
-rw-r--r--net/batman-adv/bat_iv_ogm.c30
-rw-r--r--net/batman-adv/hard-interface.c22
-rw-r--r--net/batman-adv/originator.c36
-rw-r--r--net/batman-adv/originator.h4
-rw-r--r--net/batman-adv/routing.c4
-rw-r--r--net/batman-adv/send.c9
-rw-r--r--net/batman-adv/translation-table.c23
-rw-r--r--net/bluetooth/hidp/core.c16
-rw-r--r--net/bluetooth/hidp/hidp.h4
-rw-r--r--net/bridge/br_device.c60
-rw-r--r--net/bridge/br_fdb.c137
-rw-r--r--net/bridge/br_if.c6
-rw-r--r--net/bridge/br_input.c15
-rw-r--r--net/bridge/br_multicast.c33
-rw-r--r--net/bridge/br_private.h13
-rw-r--r--net/bridge/br_stp_if.c2
-rw-r--r--net/bridge/br_vlan.c71
-rw-r--r--net/caif/caif_dev.c1
-rw-r--r--net/caif/cfsrvl.c1
-rw-r--r--net/can/af_can.c3
-rw-r--r--net/can/bcm.c4
-rw-r--r--net/can/raw.c27
-rw-r--r--net/ceph/messenger.c8
-rw-r--r--net/ceph/osd_client.c84
-rw-r--r--net/compat.c32
-rw-r--r--net/core/dev.c41
-rw-r--r--net/core/fib_rules.c7
-rw-r--r--net/core/flow_dissector.c20
-rw-r--r--net/core/neighbour.c8
-rw-r--r--net/core/netpoll.c6
-rw-r--r--net/core/rtnetlink.c31
-rw-r--r--net/core/skbuff.c131
-rw-r--r--net/core/sock.c11
-rw-r--r--net/dccp/ccids/lib/tfrc.c2
-rw-r--r--net/dccp/ccids/lib/tfrc.h1
-rw-r--r--net/decnet/af_decnet.c5
-rw-r--r--net/hsr/hsr_framereg.c2
-rw-r--r--net/ieee802154/6lowpan.c23
-rw-r--r--net/ipv4/af_inet.c7
-rw-r--r--net/ipv4/devinet.c3
-rw-r--r--net/ipv4/gre_demux.c8
-rw-r--r--net/ipv4/inet_fragment.c5
-rw-r--r--net/ipv4/ip_forward.c71
-rw-r--r--net/ipv4/ip_output.c3
-rw-r--r--net/ipv4/ip_tunnel.c85
-rw-r--r--net/ipv4/ip_tunnel_core.c46
-rw-r--r--net/ipv4/ipconfig.c2
-rw-r--r--net/ipv4/ipmr.c13
-rw-r--r--net/ipv4/netfilter/Kconfig5
-rw-r--r--net/ipv4/netfilter/Makefile1
-rw-r--r--net/ipv4/netfilter/nf_nat_h323.c5
-rw-r--r--net/ipv4/netfilter/nf_nat_snmp_basic.c4
-rw-r--r--net/ipv4/netfilter/nft_reject_ipv4.c75
-rw-r--r--net/ipv4/route.c13
-rw-r--r--net/ipv4/tcp.c10
-rw-r--r--net/ipv4/tcp_cong.c3
-rw-r--r--net/ipv4/tcp_input.c21
-rw-r--r--net/ipv4/tcp_ipv4.c2
-rw-r--r--net/ipv4/tcp_output.c48
-rw-r--r--net/ipv4/udp_offload.c17
-rw-r--r--net/ipv6/Kconfig1
-rw-r--r--net/ipv6/addrconf.c200
-rw-r--r--net/ipv6/exthdrs_core.c2
-rw-r--r--net/ipv6/exthdrs_offload.c4
-rw-r--r--net/ipv6/icmp.c2
-rw-r--r--net/ipv6/ip6_offload.c20
-rw-r--r--net/ipv6/ip6_output.c34
-rw-r--r--net/ipv6/ip6mr.c13
-rw-r--r--net/ipv6/netfilter/Kconfig5
-rw-r--r--net/ipv6/netfilter/Makefile1
-rw-r--r--net/ipv6/netfilter/nft_reject_ipv6.c76
-rw-r--r--net/ipv6/ping.c1
-rw-r--r--net/ipv6/route.c2
-rw-r--r--net/ipv6/sit.c19
-rw-r--r--net/ipv6/udp_offload.c2
-rw-r--r--net/ipx/af_ipx.c22
-rw-r--r--net/ipx/ipx_route.c4
-rw-r--r--net/key/af_key.c19
-rw-r--r--net/l2tp/l2tp_core.c6
-rw-r--r--net/l2tp/l2tp_core.h1
-rw-r--r--net/l2tp/l2tp_netlink.c4
-rw-r--r--net/l2tp/l2tp_ppp.c13
-rw-r--r--net/mac80211/cfg.c44
-rw-r--r--net/mac80211/chan.c6
-rw-r--r--net/mac80211/ht.c4
-rw-r--r--net/mac80211/ibss.c5
-rw-r--r--net/mac80211/ieee80211_i.h10
-rw-r--r--net/mac80211/iface.c33
-rw-r--r--net/mac80211/mesh_ps.c1
-rw-r--r--net/mac80211/mlme.c24
-rw-r--r--net/mac80211/rx.c7
-rw-r--r--net/mac80211/sta_info.c67
-rw-r--r--net/mac80211/sta_info.h7
-rw-r--r--net/mac80211/tx.c17
-rw-r--r--net/mac80211/util.c48
-rw-r--r--net/mac80211/wme.c5
-rw-r--r--net/netfilter/Kconfig6
-rw-r--r--net/netfilter/Makefile1
-rw-r--r--net/netfilter/ipvs/ip_vs_conn.c8
-rw-r--r--net/netfilter/nf_conntrack_core.c55
-rw-r--r--net/netfilter/nf_conntrack_netlink.c35
-rw-r--r--net/netfilter/nf_nat_core.c56
-rw-r--r--net/netfilter/nf_synproxy_core.c5
-rw-r--r--net/netfilter/nf_tables_api.c82
-rw-r--r--net/netfilter/nf_tables_core.c6
-rw-r--r--net/netfilter/nfnetlink_queue_core.c9
-rw-r--r--net/netfilter/nft_ct.c16
-rw-r--r--net/netfilter/nft_log.c5
-rw-r--r--net/netfilter/nft_lookup.c1
-rw-r--r--net/netfilter/nft_meta.c4
-rw-r--r--net/netfilter/nft_payload.c3
-rw-r--r--net/netfilter/nft_queue.c4
-rw-r--r--net/netfilter/nft_rbtree.c16
-rw-r--r--net/netfilter/nft_reject.c89
-rw-r--r--net/netfilter/nft_reject_inet.c63
-rw-r--r--net/netfilter/xt_CT.c7
-rw-r--r--net/netlink/af_netlink.c4
-rw-r--r--net/nfc/nci/core.c2
-rw-r--r--net/openvswitch/datapath.c38
-rw-r--r--net/openvswitch/flow.c29
-rw-r--r--net/openvswitch/flow_table.c88
-rw-r--r--net/openvswitch/flow_table.h2
-rw-r--r--net/packet/af_packet.c26
-rw-r--r--net/sched/sch_api.c7
-rw-r--r--net/sched/sch_fq.c21
-rw-r--r--net/sched/sch_pie.c21
-rw-r--r--net/sched/sch_tbf.c24
-rw-r--r--net/sctp/associola.c211
-rw-r--r--net/sctp/ipv6.c2
-rw-r--r--net/sctp/sm_make_chunk.c4
-rw-r--r--net/sctp/sm_sideeffect.c7
-rw-r--r--net/sctp/sm_statefuns.c12
-rw-r--r--net/sctp/socket.c47
-rw-r--r--net/sctp/sysctl.c18
-rw-r--r--net/sctp/ulpevent.c8
-rw-r--r--net/socket.c17
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c19
-rw-r--r--net/sunrpc/backchannel_rqst.c6
-rw-r--r--net/sunrpc/svc_xprt.c6
-rw-r--r--net/sunrpc/xprtsock.c6
-rw-r--r--net/tipc/bearer.c7
-rw-r--r--net/tipc/config.c11
-rw-r--r--net/tipc/core.c109
-rw-r--r--net/tipc/core.h2
-rw-r--r--net/tipc/handler.c1
-rw-r--r--net/tipc/link.c7
-rw-r--r--net/tipc/name_table.c40
-rw-r--r--net/tipc/netlink.c8
-rw-r--r--net/tipc/ref.c3
-rw-r--r--net/tipc/server.c19
-rw-r--r--net/tipc/server.h2
-rw-r--r--net/tipc/socket.c12
-rw-r--r--net/tipc/subscr.c48
-rw-r--r--net/unix/af_unix.c20
-rw-r--r--net/wireless/core.c19
-rw-r--r--net/wireless/core.h4
-rw-r--r--net/wireless/nl80211.c32
-rw-r--r--net/wireless/nl80211.h8
-rw-r--r--net/wireless/reg.c12
-rw-r--r--net/wireless/scan.c40
-rw-r--r--net/wireless/sme.c2
-rw-r--r--net/xfrm/xfrm_policy.c2
-rw-r--r--net/xfrm/xfrm_state.c23
-rw-r--r--net/xfrm/xfrm_user.c11
-rw-r--r--scripts/Kbuild.include9
-rw-r--r--scripts/Makefile.build2
-rw-r--r--scripts/Makefile.lib1
-rwxr-xr-xscripts/checkpatch.pl4
-rw-r--r--scripts/gcc-ld29
-rw-r--r--scripts/gen_initramfs_list.sh2
-rwxr-xr-xscripts/get_maintainer.pl2
-rwxr-xr-xscripts/ld-version.sh8
-rw-r--r--scripts/mod/file2alias.c4
-rw-r--r--scripts/mod/modpost.c38
-rw-r--r--scripts/mod/modpost.h2
-rw-r--r--security/Kconfig2
-rw-r--r--security/capability.c3
-rw-r--r--security/keys/compat.c4
-rw-r--r--security/keys/keyring.c6
-rw-r--r--security/security.c6
-rw-r--r--security/selinux/hooks.c13
-rw-r--r--security/selinux/include/security.h2
-rw-r--r--security/selinux/include/xfrm.h3
-rw-r--r--security/selinux/nlmsgtab.c2
-rw-r--r--security/selinux/selinuxfs.c28
-rw-r--r--security/selinux/ss/policydb.c8
-rw-r--r--security/selinux/ss/services.c10
-rw-r--r--security/selinux/xfrm.c14
-rw-r--r--sound/core/compress_offload.c2
-rw-r--r--sound/pci/hda/hda_codec.c34
-rw-r--r--sound/pci/hda/hda_generic.c8
-rw-r--r--sound/pci/hda/hda_generic.h1
-rw-r--r--sound/pci/hda/hda_intel.c2
-rw-r--r--sound/pci/hda/patch_analog.c31
-rw-r--r--sound/pci/hda/patch_ca0132.c68
-rw-r--r--sound/pci/hda/patch_conexant.c3
-rw-r--r--sound/pci/hda/patch_realtek.c92
-rw-r--r--sound/pci/hda/patch_sigmatel.c60
-rw-r--r--sound/pci/hda/thinkpad_helper.c1
-rw-r--r--sound/pci/oxygen/xonar_dg.c30
-rw-r--r--sound/soc/blackfin/Kconfig11
-rw-r--r--sound/soc/codecs/88pm860x-codec.c3
-rw-r--r--sound/soc/codecs/ad1980.c4
-rw-r--r--sound/soc/codecs/da732x.c12
-rw-r--r--sound/soc/codecs/da9055.c11
-rw-r--r--sound/soc/codecs/isabelle.c52
-rw-r--r--sound/soc/codecs/max98090.c21
-rw-r--r--sound/soc/codecs/rt5640.c1
-rw-r--r--sound/soc/codecs/si476x.c2
-rw-r--r--sound/soc/codecs/sta32x.c76
-rw-r--r--sound/soc/codecs/wm8400.c34
-rw-r--r--sound/soc/codecs/wm8770.c4
-rw-r--r--sound/soc/codecs/wm8900.c44
-rw-r--r--sound/soc/codecs/wm8958-dsp2.c2
-rw-r--r--sound/soc/codecs/wm8993.c1
-rw-r--r--sound/soc/codecs/wm8994.c135
-rw-r--r--sound/soc/davinci/davinci-evm.c1
-rw-r--r--sound/soc/davinci/davinci-mcasp.c83
-rw-r--r--sound/soc/fsl/fsl_esai.c4
-rw-r--r--sound/soc/fsl/fsl_esai.h2
-rw-r--r--sound/soc/fsl/imx-mc13783.c1
-rw-r--r--sound/soc/fsl/imx-sgtl5000.c10
-rw-r--r--sound/soc/fsl/imx-wm8962.c11
-rw-r--r--sound/soc/omap/n810.c4
-rw-r--r--sound/soc/samsung/Kconfig6
-rw-r--r--sound/soc/soc-dapm.c139
-rw-r--r--sound/soc/soc-pcm.c3
-rw-r--r--sound/soc/txx9/txx9aclc-ac97.c8
-rw-r--r--sound/usb/Kconfig1
-rw-r--r--sound/usb/mixer.c1
-rw-r--r--sound/usb/mixer_maps.c9
-rw-r--r--tools/include/linux/hash.h5
-rw-r--r--tools/lib/api/Makefile2
-rw-r--r--tools/lib/api/fs/fs.c (renamed from tools/perf/util/fs.c)11
-rw-r--r--tools/lib/api/fs/fs.h (renamed from tools/perf/util/include/linux/magic.h)12
-rw-r--r--tools/lib/lockdep/Makefile6
-rw-r--r--tools/lib/lockdep/preload.c2
-rwxr-xr-x[-rw-r--r--]tools/lib/lockdep/run_tests.sh0
-rw-r--r--tools/lib/lockdep/uinclude/asm/hash.h6
-rw-r--r--tools/lib/lockdep/uinclude/linux/rcu.h5
-rw-r--r--tools/net/Makefile2
-rw-r--r--tools/perf/Documentation/perf-mem.txt4
-rw-r--r--tools/perf/Documentation/perf-probe.txt2
-rw-r--r--tools/perf/MANIFEST1
-rw-r--r--tools/perf/Makefile.perf42
-rw-r--r--tools/perf/arch/arm/Makefile2
-rw-r--r--tools/perf/arch/arm/util/unwind-libunwind.c (renamed from tools/perf/arch/arm/util/unwind.c)2
-rw-r--r--tools/perf/arch/x86/Makefile9
-rw-r--r--tools/perf/arch/x86/include/perf_regs.h6
-rw-r--r--tools/perf/arch/x86/tests/dwarf-unwind.c59
-rw-r--r--tools/perf/arch/x86/tests/regs_load.S92
-rw-r--r--tools/perf/arch/x86/util/unwind-libdw.c51
-rw-r--r--tools/perf/arch/x86/util/unwind-libunwind.c (renamed from tools/perf/arch/x86/util/unwind.c)4
-rw-r--r--tools/perf/bench/bench.h3
-rw-r--r--tools/perf/bench/futex-hash.c212
-rw-r--r--tools/perf/bench/futex-requeue.c211
-rw-r--r--tools/perf/bench/futex-wake.c201
-rw-r--r--tools/perf/bench/futex.h71
-rw-r--r--tools/perf/bench/numa.c1
-rw-r--r--tools/perf/builtin-bench.c14
-rw-r--r--tools/perf/builtin-buildid-cache.c33
-rw-r--r--tools/perf/builtin-diff.c7
-rw-r--r--tools/perf/builtin-inject.c1
-rw-r--r--tools/perf/builtin-kvm.c12
-rw-r--r--tools/perf/builtin-probe.c12
-rw-r--r--tools/perf/builtin-record.c40
-rw-r--r--tools/perf/builtin-report.c68
-rw-r--r--tools/perf/builtin-sched.c10
-rw-r--r--tools/perf/builtin-timechart.c4
-rw-r--r--tools/perf/builtin-top.c18
-rw-r--r--tools/perf/builtin-trace.c32
-rw-r--r--tools/perf/config/Makefile234
-rw-r--r--tools/perf/config/feature-checks/Makefile8
-rw-r--r--tools/perf/config/feature-checks/test-all.c5
-rw-r--r--tools/perf/config/feature-checks/test-libdw-dwarf-unwind.c13
-rw-r--r--tools/perf/design.txt13
-rw-r--r--tools/perf/perf-completion.sh2
-rw-r--r--tools/perf/perf.h14
-rw-r--r--tools/perf/tests/builtin-test.c8
-rw-r--r--tools/perf/tests/dwarf-unwind.c144
-rw-r--r--tools/perf/tests/hists_link.c1
-rw-r--r--tools/perf/tests/make25
-rw-r--r--tools/perf/tests/parse-events.c2
-rw-r--r--tools/perf/tests/sample-parsing.c17
-rw-r--r--tools/perf/tests/tests.h9
-rw-r--r--tools/perf/tests/vmlinux-kallsyms.c10
-rw-r--r--tools/perf/ui/browsers/hists.c122
-rw-r--r--tools/perf/ui/gtk/hists.c78
-rw-r--r--tools/perf/ui/hist.c138
-rw-r--r--tools/perf/ui/stdio/hist.c11
-rw-r--r--tools/perf/util/annotate.c23
-rw-r--r--tools/perf/util/annotate.h2
-rw-r--r--tools/perf/util/cpumap.c2
-rw-r--r--tools/perf/util/dso.c4
-rw-r--r--tools/perf/util/dso.h10
-rw-r--r--tools/perf/util/event.c224
-rw-r--r--tools/perf/util/event.h11
-rw-r--r--tools/perf/util/evsel.c60
-rw-r--r--tools/perf/util/evsel.h18
-rw-r--r--tools/perf/util/fs.h7
-rw-r--r--tools/perf/util/hist.c13
-rw-r--r--tools/perf/util/hist.h29
-rw-r--r--tools/perf/util/include/asm/hash.h6
-rw-r--r--tools/perf/util/include/linux/bitops.h4
-rw-r--r--tools/perf/util/include/linux/hash.h5
-rw-r--r--tools/perf/util/include/linux/kernel.h6
-rw-r--r--tools/perf/util/include/linux/list.h1
-rw-r--r--tools/perf/util/include/linux/prefetch.h6
-rw-r--r--tools/perf/util/machine.c121
-rw-r--r--tools/perf/util/machine.h15
-rw-r--r--tools/perf/util/map.c5
-rw-r--r--tools/perf/util/map.h11
-rw-r--r--tools/perf/util/parse-events.c17
-rw-r--r--tools/perf/util/parse-options.c37
-rw-r--r--tools/perf/util/parse-options.h8
-rw-r--r--tools/perf/util/perf_regs.c19
-rw-r--r--tools/perf/util/perf_regs.h13
-rw-r--r--tools/perf/util/pmu.c2
-rw-r--r--tools/perf/util/probe-event.c865
-rw-r--r--tools/perf/util/probe-event.h12
-rw-r--r--tools/perf/util/probe-finder.c198
-rw-r--r--tools/perf/util/probe-finder.h5
-rw-r--r--tools/perf/util/python-ext-sources2
-rw-r--r--tools/perf/util/record.c2
-rw-r--r--tools/perf/util/session.c13
-rw-r--r--tools/perf/util/symbol-elf.c12
-rw-r--r--tools/perf/util/symbol.c130
-rw-r--r--tools/perf/util/symbol.h14
-rw-r--r--tools/perf/util/thread.c21
-rw-r--r--tools/perf/util/thread.h11
-rw-r--r--tools/perf/util/trace-event-parse.c1
-rw-r--r--tools/perf/util/unwind-libdw.c210
-rw-r--r--tools/perf/util/unwind-libdw.h21
-rw-r--r--tools/perf/util/unwind-libunwind.c (renamed from tools/perf/util/unwind.c)50
-rw-r--r--tools/perf/util/unwind.h11
-rw-r--r--tools/perf/util/util.c2
-rw-r--r--tools/testing/selftests/ipc/msgque.c1
-rw-r--r--tools/testing/selftests/rcutorture/bin/functions.sh1
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/kvm-recheck-lock.sh51
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/kvm-recheck-rcu.sh51
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/kvm-recheck.sh13
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh (renamed from tools/testing/selftests/rcutorture/bin/kvm-test-1-rcu.sh)53
-rw-r--r--tools/testing/selftests/rcutorture/bin/kvm.sh276
-rw-r--r--tools/testing/selftests/rcutorture/configs/lock/BUSTED6
-rw-r--r--tools/testing/selftests/rcutorture/configs/lock/BUSTED.boot1
-rw-r--r--tools/testing/selftests/rcutorture/configs/lock/CFLIST1
-rw-r--r--tools/testing/selftests/rcutorture/configs/lock/CFcommon2
-rw-r--r--tools/testing/selftests/rcutorture/configs/lock/LOCK016
-rw-r--r--tools/testing/selftests/rcutorture/configs/lock/ver_functions.sh43
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/BUSTED7
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/BUSTED.boot1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/CFLIST (renamed from tools/testing/selftests/rcutorture/configs/CFLIST)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/CFcommon2
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/SRCU-N (renamed from tools/testing/selftests/rcutorture/configs/SRCU-N)3
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/SRCU-N.boot (renamed from tools/testing/selftests/rcutorture/configs/SRCU-N.boot)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/SRCU-P (renamed from tools/testing/selftests/rcutorture/configs/SRCU-P)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/SRCU-P.boot (renamed from tools/testing/selftests/rcutorture/configs/SRCU-P.boot)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TINY01 (renamed from tools/testing/selftests/rcutorture/configs/TINY01)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TINY02 (renamed from tools/testing/selftests/rcutorture/configs/TINY02)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE01 (renamed from tools/testing/selftests/rcutorture/configs/TREE01)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE01.boot (renamed from tools/testing/selftests/rcutorture/configs/TREE01.boot)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE02 (renamed from tools/testing/selftests/rcutorture/configs/TREE02)3
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE03 (renamed from tools/testing/selftests/rcutorture/configs/TREE03)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE04 (renamed from tools/testing/selftests/rcutorture/configs/TREE04)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE04.boot (renamed from tools/testing/selftests/rcutorture/configs/TREE04.boot)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE05 (renamed from tools/testing/selftests/rcutorture/configs/TREE05)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE05.boot (renamed from tools/testing/selftests/rcutorture/configs/TREE05.boot)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE06 (renamed from tools/testing/selftests/rcutorture/configs/TREE06)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE07 (renamed from tools/testing/selftests/rcutorture/configs/TREE07)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE08 (renamed from tools/testing/selftests/rcutorture/configs/TREE08)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE08-T (renamed from tools/testing/selftests/rcutorture/configs/TREE08-T)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE09 (renamed from tools/testing/selftests/rcutorture/configs/TREE09)1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/CFLIST (renamed from tools/testing/selftests/rcutorture/configs/v0.0/CFLIST)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/N1-S-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v0.0/N1-S-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/N2-2-t-nh-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v0.0/N2-2-t-nh-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/N3-3-T-nh-SD-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v0.0/N3-3-T-nh-SD-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/N4-A-t-NH-sd-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v0.0/N4-A-t-NH-sd-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/N5-U-T-NH-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v0.0/N5-U-T-NH-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT1-nh (renamed from tools/testing/selftests/rcutorture/configs/v0.0/NT1-nh)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT3-NH (renamed from tools/testing/selftests/rcutorture/configs/v0.0/NT3-NH)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/P1-S-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v0.0/P1-S-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/P2-2-t-nh-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v0.0/P2-2-t-nh-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/P3-3-T-nh-SD-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v0.0/P3-3-T-nh-SD-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/P4-A-t-NH-sd-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v0.0/P4-A-t-NH-sd-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/P5-U-T-NH-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v0.0/P5-U-T-NH-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT1-nh (renamed from tools/testing/selftests/rcutorture/configs/v0.0/PT1-nh)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT2-NH (renamed from tools/testing/selftests/rcutorture/configs/v0.0/PT2-NH)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v0.0/ver_functions.sh (renamed from tools/testing/selftests/rcutorture/configs/v0.0/ver_functions.sh)22
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/CFLIST (renamed from tools/testing/selftests/rcutorture/configs/v3.12/CFLIST)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/N1-S-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.12/N1-S-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/N2-2-t-nh-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.12/N2-2-t-nh-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/N3-3-T-nh-SD-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.12/N3-3-T-nh-SD-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/N4-A-t-NH-sd-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.12/N4-A-t-NH-sd-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/N5-U-T-NH-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.12/N5-U-T-NH-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/N6---t-nh-SD-smp-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.12/N6---t-nh-SD-smp-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/N7-4-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.12/N7-4-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/N8-2-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.12/N8-2-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT1-nh (renamed from tools/testing/selftests/rcutorture/configs/v3.12/NT1-nh)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT3-NH (renamed from tools/testing/selftests/rcutorture/configs/v3.12/NT3-NH)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P1-S-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P1-S-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P2-2-t-nh-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P2-2-t-nh-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P3-3-T-nh-SD-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P3-3-T-nh-SD-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P4-A-t-NH-sd-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P4-A-t-NH-sd-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P5-U-T-NH-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P5-U-T-NH-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P6---t-nh-SD-smp-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P6---t-nh-SD-smp-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-all (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-HP-all)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-none (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-HP-none)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT1-nh (renamed from tools/testing/selftests/rcutorture/configs/v3.12/PT1-nh)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT2-NH (renamed from tools/testing/selftests/rcutorture/configs/v3.12/PT2-NH)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/CFLIST (renamed from tools/testing/selftests/rcutorture/configs/v3.3/CFLIST)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/N1-S-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.3/N1-S-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/N2-2-t-nh-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.3/N2-2-t-nh-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/N3-3-T-nh-SD-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.3/N3-3-T-nh-SD-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/N4-A-t-NH-sd-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.3/N4-A-t-NH-sd-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/N5-U-T-NH-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.3/N5-U-T-NH-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/NT1-nh (renamed from tools/testing/selftests/rcutorture/configs/v3.3/NT1-nh)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/NT3-NH (renamed from tools/testing/selftests/rcutorture/configs/v3.3/NT3-NH)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/P1-S-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.3/P1-S-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/P2-2-t-nh-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.3/P2-2-t-nh-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/P3-3-T-nh-SD-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.3/P3-3-T-nh-SD-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/P4-A-t-NH-sd-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.3/P4-A-t-NH-sd-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/P5-U-T-NH-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.3/P5-U-T-NH-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/PT1-nh (renamed from tools/testing/selftests/rcutorture/configs/v3.3/PT1-nh)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/PT2-NH (renamed from tools/testing/selftests/rcutorture/configs/v3.3/PT2-NH)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.3/ver_functions.sh (renamed from tools/testing/selftests/rcutorture/configs/ver_functions.sh)28
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/CFLIST (renamed from tools/testing/selftests/rcutorture/configs/v3.5/CFLIST)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/N1-S-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.5/N1-S-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/N2-2-t-nh-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.5/N2-2-t-nh-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/N3-3-T-nh-SD-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.5/N3-3-T-nh-SD-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/N4-A-t-NH-sd-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.5/N4-A-t-NH-sd-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/N5-U-T-NH-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.5/N5-U-T-NH-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/NT1-nh (renamed from tools/testing/selftests/rcutorture/configs/v3.5/NT1-nh)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/NT3-NH (renamed from tools/testing/selftests/rcutorture/configs/v3.5/NT3-NH)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/P1-S-T-NH-SD-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.5/P1-S-T-NH-SD-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/P2-2-t-nh-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.5/P2-2-t-nh-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/P3-3-T-nh-SD-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.5/P3-3-T-nh-SD-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/P4-A-t-NH-sd-SMP-HP (renamed from tools/testing/selftests/rcutorture/configs/v3.5/P4-A-t-NH-sd-SMP-HP)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/P5-U-T-NH-sd-SMP-hp (renamed from tools/testing/selftests/rcutorture/configs/v3.5/P5-U-T-NH-sd-SMP-hp)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/PT1-nh (renamed from tools/testing/selftests/rcutorture/configs/v3.5/PT1-nh)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/PT2-NH (renamed from tools/testing/selftests/rcutorture/configs/v3.5/PT2-NH)0
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/v3.5/ver_functions.sh (renamed from tools/testing/selftests/rcutorture/configs/v3.5/ver_functions.sh)23
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/ver_functions.sh (renamed from tools/testing/selftests/rcutorture/configs/v3.3/ver_functions.sh)26
-rw-r--r--tools/testing/selftests/rcutorture/doc/TREE_RCU-kconfig.txt (renamed from tools/testing/selftests/rcutorture/doc/TREE_RCU-Kconfig.txt)0
-rw-r--r--virt/kvm/arm/vgic.c1
-rw-r--r--virt/kvm/coalesced_mmio.c8
-rw-r--r--virt/kvm/kvm_main.c2
2145 files changed, 33749 insertions, 17995 deletions
diff --git a/.gitignore b/.gitignore
index 7e9932e55475..42fa0d5626a9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -92,3 +92,6 @@ extra_certificates
92signing_key.priv 92signing_key.priv
93signing_key.x509 93signing_key.x509
94x509.genkey 94x509.genkey
95
96# Kconfig presets
97all.config
diff --git a/Documentation/00-INDEX b/Documentation/00-INDEX
index 38f8444bdd0e..07de7e19b4ce 100644
--- a/Documentation/00-INDEX
+++ b/Documentation/00-INDEX
@@ -29,6 +29,8 @@ DMA-ISA-LPC.txt
29 - How to do DMA with ISA (and LPC) devices. 29 - How to do DMA with ISA (and LPC) devices.
30DMA-attributes.txt 30DMA-attributes.txt
31 - listing of the various possible attributes a DMA region can have 31 - listing of the various possible attributes a DMA region can have
32dmatest.txt
33 - how to compile, configure and use the dmatest system.
32DocBook/ 34DocBook/
33 - directory with DocBook templates etc. for kernel documentation. 35 - directory with DocBook templates etc. for kernel documentation.
34EDID/ 36EDID/
@@ -77,6 +79,8 @@ arm/
77 - directory with info about Linux on the ARM architecture. 79 - directory with info about Linux on the ARM architecture.
78arm64/ 80arm64/
79 - directory with info about Linux on the 64 bit ARM architecture. 81 - directory with info about Linux on the 64 bit ARM architecture.
82assoc_array.txt
83 - generic associative array intro.
80atomic_ops.txt 84atomic_ops.txt
81 - semantics and behavior of atomic and bitmask operations. 85 - semantics and behavior of atomic and bitmask operations.
82auxdisplay/ 86auxdisplay/
@@ -87,6 +91,8 @@ bad_memory.txt
87 - how to use kernel parameters to exclude bad RAM regions. 91 - how to use kernel parameters to exclude bad RAM regions.
88basic_profiling.txt 92basic_profiling.txt
89 - basic instructions for those who wants to profile Linux kernel. 93 - basic instructions for those who wants to profile Linux kernel.
94bcache.txt
95 - Block-layer cache on fast SSDs to improve slow (raid) I/O performance.
90binfmt_misc.txt 96binfmt_misc.txt
91 - info on the kernel support for extra binary formats. 97 - info on the kernel support for extra binary formats.
92blackfin/ 98blackfin/
@@ -171,6 +177,8 @@ early-userspace/
171 - info about initramfs, klibc, and userspace early during boot. 177 - info about initramfs, klibc, and userspace early during boot.
172edac.txt 178edac.txt
173 - information on EDAC - Error Detection And Correction 179 - information on EDAC - Error Detection And Correction
180efi-stub.txt
181 - How to use the EFI boot stub to bypass GRUB or elilo on EFI systems.
174eisa.txt 182eisa.txt
175 - info on EISA bus support. 183 - info on EISA bus support.
176email-clients.txt 184email-clients.txt
@@ -195,8 +203,8 @@ futex-requeue-pi.txt
195 - info on requeueing of tasks from a non-PI futex to a PI futex 203 - info on requeueing of tasks from a non-PI futex to a PI futex
196gcov.txt 204gcov.txt
197 - use of GCC's coverage testing tool "gcov" with the Linux kernel 205 - use of GCC's coverage testing tool "gcov" with the Linux kernel
198gpio.txt 206gpio/
199 - overview of GPIO (General Purpose Input/Output) access conventions. 207 - gpio related documentation
200hid/ 208hid/
201 - directory with information on human interface devices 209 - directory with information on human interface devices
202highuid.txt 210highuid.txt
@@ -255,6 +263,8 @@ kernel-docs.txt
255 - listing of various WWW + books that document kernel internals. 263 - listing of various WWW + books that document kernel internals.
256kernel-parameters.txt 264kernel-parameters.txt
257 - summary listing of command line / boot prompt args for the kernel. 265 - summary listing of command line / boot prompt args for the kernel.
266kernel-per-CPU-kthreads.txt
267 - List of all per-CPU kthreads and how they introduce jitter.
258kmemcheck.txt 268kmemcheck.txt
259 - info on dynamic checker that detects uses of uninitialized memory. 269 - info on dynamic checker that detects uses of uninitialized memory.
260kmemleak.txt 270kmemleak.txt
@@ -299,8 +309,6 @@ memory-devices/
299 - directory with info on parts like the Texas Instruments EMIF driver 309 - directory with info on parts like the Texas Instruments EMIF driver
300memory-hotplug.txt 310memory-hotplug.txt
301 - Hotpluggable memory support, how to use and current status. 311 - Hotpluggable memory support, how to use and current status.
302memory.txt
303 - info on typical Linux memory problems.
304metag/ 312metag/
305 - directory with info about Linux on Meta architecture. 313 - directory with info about Linux on Meta architecture.
306mips/ 314mips/
@@ -311,6 +319,8 @@ mmc/
311 - directory with info about the MMC subsystem 319 - directory with info about the MMC subsystem
312mn10300/ 320mn10300/
313 - directory with info about the mn10300 architecture port 321 - directory with info about the mn10300 architecture port
322module-signing.txt
323 - Kernel module signing for increased security when loading modules.
314mtd/ 324mtd/
315 - directory with info about memory technology devices (flash) 325 - directory with info about memory technology devices (flash)
316mono.txt 326mono.txt
@@ -343,6 +353,8 @@ pcmcia/
343 - info on the Linux PCMCIA driver. 353 - info on the Linux PCMCIA driver.
344percpu-rw-semaphore.txt 354percpu-rw-semaphore.txt
345 - RCU based read-write semaphore optimized for locking for reading 355 - RCU based read-write semaphore optimized for locking for reading
356phy.txt
357 - Description of the generic PHY framework.
346pi-futex.txt 358pi-futex.txt
347 - documentation on lightweight priority inheritance futexes. 359 - documentation on lightweight priority inheritance futexes.
348pinctrl.txt 360pinctrl.txt
@@ -431,6 +443,8 @@ sysrq.txt
431 - info on the magic SysRq key. 443 - info on the magic SysRq key.
432target/ 444target/
433 - directory with info on generating TCM v4 fabric .ko modules 445 - directory with info on generating TCM v4 fabric .ko modules
446this_cpu_ops.txt
447 - List rationale behind and the way to use this_cpu operations.
434thermal/ 448thermal/
435 - directory with information on managing thermal issues (CPU/temp) 449 - directory with information on managing thermal issues (CPU/temp)
436trace/ 450trace/
@@ -469,6 +483,8 @@ wimax/
469 - directory with info about Intel Wireless Wimax Connections 483 - directory with info about Intel Wireless Wimax Connections
470workqueue.txt 484workqueue.txt
471 - information on the Concurrency Managed Workqueue implementation 485 - information on the Concurrency Managed Workqueue implementation
486ww-mutex-design.txt
487 - Intro to Mutex wait/would deadlock handling.s
472x86/x86_64/ 488x86/x86_64/
473 - directory with info on Linux support for AMD x86-64 (Hammer) machines. 489 - directory with info on Linux support for AMD x86-64 (Hammer) machines.
474xtensa/ 490xtensa/
diff --git a/Documentation/PCI/MSI-HOWTO.txt b/Documentation/PCI/MSI-HOWTO.txt
index a8d01005f480..10a93696e55a 100644
--- a/Documentation/PCI/MSI-HOWTO.txt
+++ b/Documentation/PCI/MSI-HOWTO.txt
@@ -82,7 +82,19 @@ Most of the hard work is done for the driver in the PCI layer. It simply
82has to request that the PCI layer set up the MSI capability for this 82has to request that the PCI layer set up the MSI capability for this
83device. 83device.
84 84
854.2.1 pci_enable_msi_range 854.2.1 pci_enable_msi
86
87int pci_enable_msi(struct pci_dev *dev)
88
89A successful call allocates ONE interrupt to the device, regardless
90of how many MSIs the device supports. The device is switched from
91pin-based interrupt mode to MSI mode. The dev->irq number is changed
92to a new number which represents the message signaled interrupt;
93consequently, this function should be called before the driver calls
94request_irq(), because an MSI is delivered via a vector that is
95different from the vector of a pin-based interrupt.
96
974.2.2 pci_enable_msi_range
86 98
87int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec) 99int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec)
88 100
@@ -147,6 +159,11 @@ static int foo_driver_enable_msi(struct pci_dev *pdev, int nvec)
147 return pci_enable_msi_range(pdev, nvec, nvec); 159 return pci_enable_msi_range(pdev, nvec, nvec);
148} 160}
149 161
162Note, unlike pci_enable_msi_exact() function, which could be also used to
163enable a particular number of MSI-X interrupts, pci_enable_msi_range()
164returns either a negative errno or 'nvec' (not negative errno or 0 - as
165pci_enable_msi_exact() does).
166
1504.2.1.3 Single MSI mode 1674.2.1.3 Single MSI mode
151 168
152The most notorious example of the request type described above is 169The most notorious example of the request type described above is
@@ -158,7 +175,27 @@ static int foo_driver_enable_single_msi(struct pci_dev *pdev)
158 return pci_enable_msi_range(pdev, 1, 1); 175 return pci_enable_msi_range(pdev, 1, 1);
159} 176}
160 177
1614.2.2 pci_disable_msi 178Note, unlike pci_enable_msi() function, which could be also used to
179enable the single MSI mode, pci_enable_msi_range() returns either a
180negative errno or 1 (not negative errno or 0 - as pci_enable_msi()
181does).
182
1834.2.3 pci_enable_msi_exact
184
185int pci_enable_msi_exact(struct pci_dev *dev, int nvec)
186
187This variation on pci_enable_msi_range() call allows a device driver to
188request exactly 'nvec' MSIs.
189
190If this function returns a negative number, it indicates an error and
191the driver should not attempt to request any more MSI interrupts for
192this device.
193
194By contrast with pci_enable_msi_range() function, pci_enable_msi_exact()
195returns zero in case of success, which indicates MSI interrupts have been
196successfully allocated.
197
1984.2.4 pci_disable_msi
162 199
163void pci_disable_msi(struct pci_dev *dev) 200void pci_disable_msi(struct pci_dev *dev)
164 201
@@ -172,7 +209,7 @@ on any interrupt for which it previously called request_irq().
172Failure to do so results in a BUG_ON(), leaving the device with 209Failure to do so results in a BUG_ON(), leaving the device with
173MSI enabled and thus leaking its vector. 210MSI enabled and thus leaking its vector.
174 211
1754.2.3 pci_msi_vec_count 2124.2.4 pci_msi_vec_count
176 213
177int pci_msi_vec_count(struct pci_dev *dev) 214int pci_msi_vec_count(struct pci_dev *dev)
178 215
@@ -257,8 +294,8 @@ possible, likely up to the limit returned by pci_msix_vec_count() function:
257 294
258static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) 295static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec)
259{ 296{
260 return pci_enable_msi_range(adapter->pdev, adapter->msix_entries, 297 return pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
261 1, nvec); 298 1, nvec);
262} 299}
263 300
264Note the value of 'minvec' parameter is 1. As 'minvec' is inclusive, 301Note the value of 'minvec' parameter is 1. As 'minvec' is inclusive,
@@ -269,8 +306,8 @@ In this case the function could look like this:
269 306
270static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) 307static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec)
271{ 308{
272 return pci_enable_msi_range(adapter->pdev, adapter->msix_entries, 309 return pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
273 FOO_DRIVER_MINIMUM_NVEC, nvec); 310 FOO_DRIVER_MINIMUM_NVEC, nvec);
274} 311}
275 312
2764.3.1.2 Exact number of MSI-X interrupts 3134.3.1.2 Exact number of MSI-X interrupts
@@ -282,10 +319,15 @@ parameters:
282 319
283static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) 320static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec)
284{ 321{
285 return pci_enable_msi_range(adapter->pdev, adapter->msix_entries, 322 return pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
286 nvec, nvec); 323 nvec, nvec);
287} 324}
288 325
326Note, unlike pci_enable_msix_exact() function, which could be also used to
327enable a particular number of MSI-X interrupts, pci_enable_msix_range()
328returns either a negative errno or 'nvec' (not negative errno or 0 - as
329pci_enable_msix_exact() does).
330
2894.3.1.3 Specific requirements to the number of MSI-X interrupts 3314.3.1.3 Specific requirements to the number of MSI-X interrupts
290 332
291As noted above, there could be devices that can not operate with just any 333As noted above, there could be devices that can not operate with just any
@@ -332,7 +374,64 @@ Note how pci_enable_msix_range() return value is analized for a fallback -
332any error code other than -ENOSPC indicates a fatal error and should not 374any error code other than -ENOSPC indicates a fatal error and should not
333be retried. 375be retried.
334 376
3354.3.2 pci_disable_msix 3774.3.2 pci_enable_msix_exact
378
379int pci_enable_msix_exact(struct pci_dev *dev,
380 struct msix_entry *entries, int nvec)
381
382This variation on pci_enable_msix_range() call allows a device driver to
383request exactly 'nvec' MSI-Xs.
384
385If this function returns a negative number, it indicates an error and
386the driver should not attempt to allocate any more MSI-X interrupts for
387this device.
388
389By contrast with pci_enable_msix_range() function, pci_enable_msix_exact()
390returns zero in case of success, which indicates MSI-X interrupts have been
391successfully allocated.
392
393Another version of a routine that enables MSI-X mode for a device with
394specific requirements described in chapter 4.3.1.3 might look like this:
395
396/*
397 * Assume 'minvec' and 'maxvec' are non-zero
398 */
399static int foo_driver_enable_msix(struct foo_adapter *adapter,
400 int minvec, int maxvec)
401{
402 int rc;
403
404 minvec = roundup_pow_of_two(minvec);
405 maxvec = rounddown_pow_of_two(maxvec);
406
407 if (minvec > maxvec)
408 return -ERANGE;
409
410retry:
411 rc = pci_enable_msix_exact(adapter->pdev,
412 adapter->msix_entries, maxvec);
413
414 /*
415 * -ENOSPC is the only error code allowed to be analyzed
416 */
417 if (rc == -ENOSPC) {
418 if (maxvec == 1)
419 return -ENOSPC;
420
421 maxvec /= 2;
422
423 if (minvec > maxvec)
424 return -ENOSPC;
425
426 goto retry;
427 } else if (rc < 0) {
428 return rc;
429 }
430
431 return maxvec;
432}
433
4344.3.3 pci_disable_msix
336 435
337void pci_disable_msix(struct pci_dev *dev) 436void pci_disable_msix(struct pci_dev *dev)
338 437
diff --git a/Documentation/RCU/00-INDEX b/Documentation/RCU/00-INDEX
index 1d7a885761f5..fa57139f50bf 100644
--- a/Documentation/RCU/00-INDEX
+++ b/Documentation/RCU/00-INDEX
@@ -8,6 +8,8 @@ listRCU.txt
8 - Using RCU to Protect Read-Mostly Linked Lists 8 - Using RCU to Protect Read-Mostly Linked Lists
9lockdep.txt 9lockdep.txt
10 - RCU and lockdep checking 10 - RCU and lockdep checking
11lockdep-splat.txt
12 - RCU Lockdep splats explained.
11NMI-RCU.txt 13NMI-RCU.txt
12 - Using RCU to Protect Dynamic NMI Handlers 14 - Using RCU to Protect Dynamic NMI Handlers
13rcubarrier.txt 15rcubarrier.txt
diff --git a/Documentation/RCU/RTFP.txt b/Documentation/RCU/RTFP.txt
index 273e654d7d08..2f0fcb2112d2 100644
--- a/Documentation/RCU/RTFP.txt
+++ b/Documentation/RCU/RTFP.txt
@@ -31,6 +31,14 @@ has lapsed, so this approach may be used in non-GPL software, if desired.
31(In contrast, implementation of RCU is permitted only in software licensed 31(In contrast, implementation of RCU is permitted only in software licensed
32under either GPL or LGPL. Sorry!!!) 32under either GPL or LGPL. Sorry!!!)
33 33
34In 1987, Rashid et al. described lazy TLB-flush [RichardRashid87a].
35At first glance, this has nothing to do with RCU, but nevertheless
36this paper helped inspire the update-side batching used in the later
37RCU implementation in DYNIX/ptx. In 1988, Barbara Liskov published
38a description of Argus that noted that use of out-of-date values can
39be tolerated in some situations. Thus, this paper provides some early
40theoretical justification for use of stale data.
41
34In 1990, Pugh [Pugh90] noted that explicitly tracking which threads 42In 1990, Pugh [Pugh90] noted that explicitly tracking which threads
35were reading a given data structure permitted deferred free to operate 43were reading a given data structure permitted deferred free to operate
36in the presence of non-terminating threads. However, this explicit 44in the presence of non-terminating threads. However, this explicit
@@ -41,11 +49,11 @@ providing a fine-grained locking design, however, it would be interesting
41to see how much of the performance advantage reported in 1990 remains 49to see how much of the performance advantage reported in 1990 remains
42today. 50today.
43 51
44At about this same time, Adams [Adams91] described ``chaotic relaxation'', 52At about this same time, Andrews [Andrews91textbook] described ``chaotic
45where the normal barriers between successive iterations of convergent 53relaxation'', where the normal barriers between successive iterations
46numerical algorithms are relaxed, so that iteration $n$ might use 54of convergent numerical algorithms are relaxed, so that iteration $n$
47data from iteration $n-1$ or even $n-2$. This introduces error, 55might use data from iteration $n-1$ or even $n-2$. This introduces
48which typically slows convergence and thus increases the number of 56error, which typically slows convergence and thus increases the number of
49iterations required. However, this increase is sometimes more than made 57iterations required. However, this increase is sometimes more than made
50up for by a reduction in the number of expensive barrier operations, 58up for by a reduction in the number of expensive barrier operations,
51which are otherwise required to synchronize the threads at the end 59which are otherwise required to synchronize the threads at the end
@@ -55,7 +63,8 @@ is thus inapplicable to most data structures in operating-system kernels.
55 63
56In 1992, Henry (now Alexia) Massalin completed a dissertation advising 64In 1992, Henry (now Alexia) Massalin completed a dissertation advising
57parallel programmers to defer processing when feasible to simplify 65parallel programmers to defer processing when feasible to simplify
58synchronization. RCU makes extremely heavy use of this advice. 66synchronization [HMassalinPhD]. RCU makes extremely heavy use of
67this advice.
59 68
60In 1993, Jacobson [Jacobson93] verbally described what is perhaps the 69In 1993, Jacobson [Jacobson93] verbally described what is perhaps the
61simplest deferred-free technique: simply waiting a fixed amount of time 70simplest deferred-free technique: simply waiting a fixed amount of time
@@ -90,27 +99,29 @@ mechanism, which is quite similar to RCU [Gamsa99]. These operating
90systems made pervasive use of RCU in place of "existence locks", which 99systems made pervasive use of RCU in place of "existence locks", which
91greatly simplifies locking hierarchies and helps avoid deadlocks. 100greatly simplifies locking hierarchies and helps avoid deadlocks.
92 101
932001 saw the first RCU presentation involving Linux [McKenney01a] 102The year 2000 saw an email exchange that would likely have
94at OLS. The resulting abundance of RCU patches was presented the 103led to yet another independent invention of something like RCU
95following year [McKenney02a], and use of RCU in dcache was first 104[RustyRussell2000a,RustyRussell2000b]. Instead, 2001 saw the first
96described that same year [Linder02a]. 105RCU presentation involving Linux [McKenney01a] at OLS. The resulting
106abundance of RCU patches was presented the following year [McKenney02a],
107and use of RCU in dcache was first described that same year [Linder02a].
97 108
98Also in 2002, Michael [Michael02b,Michael02a] presented "hazard-pointer" 109Also in 2002, Michael [Michael02b,Michael02a] presented "hazard-pointer"
99techniques that defer the destruction of data structures to simplify 110techniques that defer the destruction of data structures to simplify
100non-blocking synchronization (wait-free synchronization, lock-free 111non-blocking synchronization (wait-free synchronization, lock-free
101synchronization, and obstruction-free synchronization are all examples of 112synchronization, and obstruction-free synchronization are all examples of
102non-blocking synchronization). In particular, this technique eliminates 113non-blocking synchronization). The corresponding journal article appeared
103locking, reduces contention, reduces memory latency for readers, and 114in 2004 [MagedMichael04a]. This technique eliminates locking, reduces
104parallelizes pipeline stalls and memory latency for writers. However, 115contention, reduces memory latency for readers, and parallelizes pipeline
105these techniques still impose significant read-side overhead in the 116stalls and memory latency for writers. However, these techniques still
106form of memory barriers. Researchers at Sun worked along similar lines 117impose significant read-side overhead in the form of memory barriers.
107in the same timeframe [HerlihyLM02]. These techniques can be thought 118Researchers at Sun worked along similar lines in the same timeframe
108of as inside-out reference counts, where the count is represented by the 119[HerlihyLM02]. These techniques can be thought of as inside-out reference
109number of hazard pointers referencing a given data structure rather than 120counts, where the count is represented by the number of hazard pointers
110the more conventional counter field within the data structure itself. 121referencing a given data structure rather than the more conventional
111The key advantage of inside-out reference counts is that they can be 122counter field within the data structure itself. The key advantage
112stored in immortal variables, thus allowing races between access and 123of inside-out reference counts is that they can be stored in immortal
113deletion to be avoided. 124variables, thus allowing races between access and deletion to be avoided.
114 125
115By the same token, RCU can be thought of as a "bulk reference count", 126By the same token, RCU can be thought of as a "bulk reference count",
116where some form of reference counter covers all reference by a given CPU 127where some form of reference counter covers all reference by a given CPU
@@ -123,8 +134,10 @@ can be thought of in other terms as well.
123 134
124In 2003, the K42 group described how RCU could be used to create 135In 2003, the K42 group described how RCU could be used to create
125hot-pluggable implementations of operating-system functions [Appavoo03a]. 136hot-pluggable implementations of operating-system functions [Appavoo03a].
126Later that year saw a paper describing an RCU implementation of System 137Later that year saw a paper describing an RCU implementation
127V IPC [Arcangeli03], and an introduction to RCU in Linux Journal 138of System V IPC [Arcangeli03] (following up on a suggestion by
139Hugh Dickins [Dickins02a] and an implementation by Mingming Cao
140[MingmingCao2002IPCRCU]), and an introduction to RCU in Linux Journal
128[McKenney03a]. 141[McKenney03a].
129 142
1302004 has seen a Linux-Journal article on use of RCU in dcache 1432004 has seen a Linux-Journal article on use of RCU in dcache
@@ -383,6 +396,21 @@ for Programming Languages and Operating Systems}"
383} 396}
384} 397}
385 398
399@phdthesis{HMassalinPhD
400,author="H. Massalin"
401,title="Synthesis: An Efficient Implementation of Fundamental Operating
402System Services"
403,school="Columbia University"
404,address="New York, NY"
405,year="1992"
406,annotation={
407 Mondo optimizing compiler.
408 Wait-free stuff.
409 Good advice: defer work to avoid synchronization. See page 90
410 (PDF page 106), Section 5.4, fourth bullet point.
411}
412}
413
386@unpublished{Jacobson93 414@unpublished{Jacobson93
387,author="Van Jacobson" 415,author="Van Jacobson"
388,title="Avoid Read-Side Locking Via Delayed Free" 416,title="Avoid Read-Side Locking Via Delayed Free"
@@ -671,6 +699,20 @@ Orran Krieger and Rusty Russell and Dipankar Sarma and Maneesh Soni"
671[Viewed October 18, 2004]" 699[Viewed October 18, 2004]"
672} 700}
673 701
702@conference{Michael02b
703,author="Maged M. Michael"
704,title="High Performance Dynamic Lock-Free Hash Tables and List-Based Sets"
705,Year="2002"
706,Month="August"
707,booktitle="{Proceedings of the 14\textsuperscript{th} Annual ACM
708Symposium on Parallel
709Algorithms and Architecture}"
710,pages="73-82"
711,annotation={
712Like the title says...
713}
714}
715
674@Conference{Linder02a 716@Conference{Linder02a
675,Author="Hanna Linder and Dipankar Sarma and Maneesh Soni" 717,Author="Hanna Linder and Dipankar Sarma and Maneesh Soni"
676,Title="Scalability of the Directory Entry Cache" 718,Title="Scalability of the Directory Entry Cache"
@@ -727,6 +769,24 @@ Andrea Arcangeli and Andi Kleen and Orran Krieger and Rusty Russell"
727} 769}
728} 770}
729 771
772@conference{Michael02a
773,author="Maged M. Michael"
774,title="Safe Memory Reclamation for Dynamic Lock-Free Objects Using Atomic
775Reads and Writes"
776,Year="2002"
777,Month="August"
778,booktitle="{Proceedings of the 21\textsuperscript{st} Annual ACM
779Symposium on Principles of Distributed Computing}"
780,pages="21-30"
781,annotation={
782 Each thread keeps an array of pointers to items that it is
783 currently referencing. Sort of an inside-out garbage collection
784 mechanism, but one that requires the accessing code to explicitly
785 state its needs. Also requires read-side memory barriers on
786 most architectures.
787}
788}
789
730@unpublished{Dickins02a 790@unpublished{Dickins02a
731,author="Hugh Dickins" 791,author="Hugh Dickins"
732,title="Use RCU for System-V IPC" 792,title="Use RCU for System-V IPC"
@@ -735,6 +795,17 @@ Andrea Arcangeli and Andi Kleen and Orran Krieger and Rusty Russell"
735,note="private communication" 795,note="private communication"
736} 796}
737 797
798@InProceedings{HerlihyLM02
799,author={Maurice Herlihy and Victor Luchangco and Mark Moir}
800,title="The Repeat Offender Problem: A Mechanism for Supporting Dynamic-Sized,
801Lock-Free Data Structures"
802,booktitle={Proceedings of 16\textsuperscript{th} International
803Symposium on Distributed Computing}
804,year=2002
805,month="October"
806,pages="339-353"
807}
808
738@unpublished{Sarma02b 809@unpublished{Sarma02b
739,Author="Dipankar Sarma" 810,Author="Dipankar Sarma"
740,Title="Some dcache\_rcu benchmark numbers" 811,Title="Some dcache\_rcu benchmark numbers"
@@ -749,6 +820,19 @@ Andrea Arcangeli and Andi Kleen and Orran Krieger and Rusty Russell"
749} 820}
750} 821}
751 822
823@unpublished{MingmingCao2002IPCRCU
824,Author="Mingming Cao"
825,Title="[PATCH]updated ipc lock patch"
826,month="October"
827,year="2002"
828,note="Available:
829\url{https://lkml.org/lkml/2002/10/24/262}
830[Viewed February 15, 2014]"
831,annotation={
832 Mingming Cao's patch to introduce RCU to SysV IPC.
833}
834}
835
752@unpublished{LinusTorvalds2003a 836@unpublished{LinusTorvalds2003a
753,Author="Linus Torvalds" 837,Author="Linus Torvalds"
754,Title="Re: {[PATCH]} small fixes in brlock.h" 838,Title="Re: {[PATCH]} small fixes in brlock.h"
@@ -982,6 +1066,23 @@ Realtime Applications"
982} 1066}
983} 1067}
984 1068
1069@article{MagedMichael04a
1070,author="Maged M. Michael"
1071,title="Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects"
1072,Year="2004"
1073,Month="June"
1074,journal="IEEE Transactions on Parallel and Distributed Systems"
1075,volume="15"
1076,number="6"
1077,pages="491-504"
1078,url="Available:
1079\url{http://www.research.ibm.com/people/m/michael/ieeetpds-2004.pdf}
1080[Viewed March 1, 2005]"
1081,annotation={
1082 New canonical hazard-pointer citation.
1083}
1084}
1085
985@phdthesis{PaulEdwardMcKenneyPhD 1086@phdthesis{PaulEdwardMcKenneyPhD
986,author="Paul E. McKenney" 1087,author="Paul E. McKenney"
987,title="Exploiting Deferred Destruction: 1088,title="Exploiting Deferred Destruction:
diff --git a/Documentation/RCU/checklist.txt b/Documentation/RCU/checklist.txt
index 91266193b8f4..9d10d1db16a5 100644
--- a/Documentation/RCU/checklist.txt
+++ b/Documentation/RCU/checklist.txt
@@ -256,10 +256,10 @@ over a rather long period of time, but improvements are always welcome!
256 variations on this theme. 256 variations on this theme.
257 257
258 b. Limiting update rate. For example, if updates occur only 258 b. Limiting update rate. For example, if updates occur only
259 once per hour, then no explicit rate limiting is required, 259 once per hour, then no explicit rate limiting is
260 unless your system is already badly broken. The dcache 260 required, unless your system is already badly broken.
261 subsystem takes this approach -- updates are guarded 261 Older versions of the dcache subsystem take this approach,
262 by a global lock, limiting their rate. 262 guarding updates with a global lock, limiting their rate.
263 263
264 c. Trusted update -- if updates can only be done manually by 264 c. Trusted update -- if updates can only be done manually by
265 superuser or some other trusted user, then it might not 265 superuser or some other trusted user, then it might not
@@ -268,7 +268,8 @@ over a rather long period of time, but improvements are always welcome!
268 the machine. 268 the machine.
269 269
270 d. Use call_rcu_bh() rather than call_rcu(), in order to take 270 d. Use call_rcu_bh() rather than call_rcu(), in order to take
271 advantage of call_rcu_bh()'s faster grace periods. 271 advantage of call_rcu_bh()'s faster grace periods. (This
272 is only a partial solution, though.)
272 273
273 e. Periodically invoke synchronize_rcu(), permitting a limited 274 e. Periodically invoke synchronize_rcu(), permitting a limited
274 number of updates per grace period. 275 number of updates per grace period.
@@ -276,6 +277,13 @@ over a rather long period of time, but improvements are always welcome!
276 The same cautions apply to call_rcu_bh(), call_rcu_sched(), 277 The same cautions apply to call_rcu_bh(), call_rcu_sched(),
277 call_srcu(), and kfree_rcu(). 278 call_srcu(), and kfree_rcu().
278 279
280 Note that although these primitives do take action to avoid memory
281 exhaustion when any given CPU has too many callbacks, a determined
282 user could still exhaust memory. This is especially the case
283 if a system with a large number of CPUs has been configured to
284 offload all of its RCU callbacks onto a single CPU, or if the
285 system has relatively little free memory.
286
2799. All RCU list-traversal primitives, which include 2879. All RCU list-traversal primitives, which include
280 rcu_dereference(), list_for_each_entry_rcu(), and 288 rcu_dereference(), list_for_each_entry_rcu(), and
281 list_for_each_safe_rcu(), must be either within an RCU read-side 289 list_for_each_safe_rcu(), must be either within an RCU read-side
diff --git a/Documentation/arm/00-INDEX b/Documentation/arm/00-INDEX
index 36420e116c90..a94090cc785d 100644
--- a/Documentation/arm/00-INDEX
+++ b/Documentation/arm/00-INDEX
@@ -4,6 +4,8 @@ Booting
4 - requirements for booting 4 - requirements for booting
5Interrupts 5Interrupts
6 - ARM Interrupt subsystem documentation 6 - ARM Interrupt subsystem documentation
7IXP4xx
8 - Intel IXP4xx Network processor.
7msm 9msm
8 - MSM specific documentation 10 - MSM specific documentation
9Netwinder 11Netwinder
@@ -24,8 +26,16 @@ SPEAr
24 - ST SPEAr platform Linux Overview 26 - ST SPEAr platform Linux Overview
25VFP/ 27VFP/
26 - Release notes for Linux Kernel Vector Floating Point support code 28 - Release notes for Linux Kernel Vector Floating Point support code
29cluster-pm-race-avoidance.txt
30 - Algorithm for CPU and Cluster setup/teardown
27empeg/ 31empeg/
28 - Ltd's Empeg MP3 Car Audio Player 32 - Ltd's Empeg MP3 Car Audio Player
33firmware.txt
34 - Secure firmware registration and calling.
35kernel_mode_neon.txt
36 - How to use NEON instructions in kernel mode
37kernel_user_helpers.txt
38 - Helper functions in kernel space made available for userspace.
29mem_alignment 39mem_alignment
30 - alignment abort handler documentation 40 - alignment abort handler documentation
31memory.txt 41memory.txt
@@ -34,3 +44,7 @@ nwfpe/
34 - NWFPE floating point emulator documentation 44 - NWFPE floating point emulator documentation
35swp_emulation 45swp_emulation
36 - SWP/SWPB emulation handler/logging description 46 - SWP/SWPB emulation handler/logging description
47tcm.txt
48 - ARM Tightly Coupled Memory
49vlocks.txt
50 - Voting locks, low-level mechanism relying on memory system atomic writes.
diff --git a/Documentation/arm64/memory.txt b/Documentation/arm64/memory.txt
index 5e054bfe4dde..85e24c4f215c 100644
--- a/Documentation/arm64/memory.txt
+++ b/Documentation/arm64/memory.txt
@@ -35,11 +35,13 @@ ffffffbc00000000 ffffffbdffffffff 8GB vmemmap
35 35
36ffffffbe00000000 ffffffbffbbfffff ~8GB [guard, future vmmemap] 36ffffffbe00000000 ffffffbffbbfffff ~8GB [guard, future vmmemap]
37 37
38ffffffbffbc00000 ffffffbffbdfffff 2MB earlyprintk device 38ffffffbffa000000 ffffffbffaffffff 16MB PCI I/O space
39
40ffffffbffb000000 ffffffbffbbfffff 12MB [guard]
39 41
40ffffffbffbe00000 ffffffbffbe0ffff 64KB PCI I/O space 42ffffffbffbc00000 ffffffbffbdfffff 2MB earlyprintk device
41 43
42ffffffbffbe10000 ffffffbcffffffff ~2MB [guard] 44ffffffbffbe00000 ffffffbffbffffff 2MB [guard]
43 45
44ffffffbffc000000 ffffffbfffffffff 64MB modules 46ffffffbffc000000 ffffffbfffffffff 64MB modules
45 47
@@ -60,11 +62,13 @@ fffffdfc00000000 fffffdfdffffffff 8GB vmemmap
60 62
61fffffdfe00000000 fffffdfffbbfffff ~8GB [guard, future vmmemap] 63fffffdfe00000000 fffffdfffbbfffff ~8GB [guard, future vmmemap]
62 64
63fffffdfffbc00000 fffffdfffbdfffff 2MB earlyprintk device 65fffffdfffa000000 fffffdfffaffffff 16MB PCI I/O space
66
67fffffdfffb000000 fffffdfffbbfffff 12MB [guard]
64 68
65fffffdfffbe00000 fffffdfffbe0ffff 64KB PCI I/O space 69fffffdfffbc00000 fffffdfffbdfffff 2MB earlyprintk device
66 70
67fffffdfffbe10000 fffffdfffbffffff ~2MB [guard] 71fffffdfffbe00000 fffffdfffbffffff 2MB [guard]
68 72
69fffffdfffc000000 fffffdffffffffff 64MB modules 73fffffdfffc000000 fffffdffffffffff 64MB modules
70 74
diff --git a/Documentation/blackfin/00-INDEX b/Documentation/blackfin/00-INDEX
index 2df0365f2dff..c54fcdd4ae9f 100644
--- a/Documentation/blackfin/00-INDEX
+++ b/Documentation/blackfin/00-INDEX
@@ -1,8 +1,10 @@
100-INDEX 100-INDEX
2 - This file 2 - This file
3 3Makefile
4 - Makefile for gptimers example file.
4bfin-gpio-notes.txt 5bfin-gpio-notes.txt
5 - Notes in developing/using bfin-gpio driver. 6 - Notes in developing/using bfin-gpio driver.
6
7bfin-spi-notes.txt 7bfin-spi-notes.txt
8 - Notes for using bfin spi bus driver. 8 - Notes for using bfin spi bus driver.
9gptimers-example.c
10 - gptimers example
diff --git a/Documentation/block/00-INDEX b/Documentation/block/00-INDEX
index 929d9904f74b..e840b47613f7 100644
--- a/Documentation/block/00-INDEX
+++ b/Documentation/block/00-INDEX
@@ -14,6 +14,8 @@ deadline-iosched.txt
14 - Deadline IO scheduler tunables 14 - Deadline IO scheduler tunables
15ioprio.txt 15ioprio.txt
16 - Block io priorities (in CFQ scheduler) 16 - Block io priorities (in CFQ scheduler)
17null_blk.txt
18 - Null block for block-layer benchmarking.
17queue-sysfs.txt 19queue-sysfs.txt
18 - Queue's sysfs entries 20 - Queue's sysfs entries
19request.txt 21request.txt
diff --git a/Documentation/device-mapper/cache.txt b/Documentation/device-mapper/cache.txt
index e6b72d355151..68c0f517c60e 100644
--- a/Documentation/device-mapper/cache.txt
+++ b/Documentation/device-mapper/cache.txt
@@ -124,12 +124,11 @@ the default being 204800 sectors (or 100MB).
124Updating on-disk metadata 124Updating on-disk metadata
125------------------------- 125-------------------------
126 126
127On-disk metadata is committed every time a REQ_SYNC or REQ_FUA bio is 127On-disk metadata is committed every time a FLUSH or FUA bio is written.
128written. If no such requests are made then commits will occur every 128If no such requests are made then commits will occur every second. This
129second. This means the cache behaves like a physical disk that has a 129means the cache behaves like a physical disk that has a volatile write
130write cache (the same is true of the thin-provisioning target). If 130cache. If power is lost you may lose some recent writes. The metadata
131power is lost you may lose some recent writes. The metadata should 131should always be consistent in spite of any crash.
132always be consistent in spite of any crash.
133 132
134The 'dirty' state for a cache block changes far too frequently for us 133The 'dirty' state for a cache block changes far too frequently for us
135to keep updating it on the fly. So we treat it as a hint. In normal 134to keep updating it on the fly. So we treat it as a hint. In normal
diff --git a/Documentation/device-mapper/thin-provisioning.txt b/Documentation/device-mapper/thin-provisioning.txt
index 8a7a3d46e0da..05a27e9442bd 100644
--- a/Documentation/device-mapper/thin-provisioning.txt
+++ b/Documentation/device-mapper/thin-provisioning.txt
@@ -116,6 +116,35 @@ Resuming a device with a new table itself triggers an event so the
116userspace daemon can use this to detect a situation where a new table 116userspace daemon can use this to detect a situation where a new table
117already exceeds the threshold. 117already exceeds the threshold.
118 118
119A low water mark for the metadata device is maintained in the kernel and
120will trigger a dm event if free space on the metadata device drops below
121it.
122
123Updating on-disk metadata
124-------------------------
125
126On-disk metadata is committed every time a FLUSH or FUA bio is written.
127If no such requests are made then commits will occur every second. This
128means the thin-provisioning target behaves like a physical disk that has
129a volatile write cache. If power is lost you may lose some recent
130writes. The metadata should always be consistent in spite of any crash.
131
132If data space is exhausted the pool will either error or queue IO
133according to the configuration (see: error_if_no_space). If metadata
134space is exhausted or a metadata operation fails: the pool will error IO
135until the pool is taken offline and repair is performed to 1) fix any
136potential inconsistencies and 2) clear the flag that imposes repair.
137Once the pool's metadata device is repaired it may be resized, which
138will allow the pool to return to normal operation. Note that if a pool
139is flagged as needing repair, the pool's data and metadata devices
140cannot be resized until repair is performed. It should also be noted
141that when the pool's metadata space is exhausted the current metadata
142transaction is aborted. Given that the pool will cache IO whose
143completion may have already been acknowledged to upper IO layers
144(e.g. filesystem) it is strongly suggested that consistency checks
145(e.g. fsck) be performed on those layers when repair of the pool is
146required.
147
119Thin provisioning 148Thin provisioning
120----------------- 149-----------------
121 150
@@ -258,10 +287,9 @@ ii) Status
258 should register for the event and then check the target's status. 287 should register for the event and then check the target's status.
259 288
260 held metadata root: 289 held metadata root:
261 The location, in sectors, of the metadata root that has been 290 The location, in blocks, of the metadata root that has been
262 'held' for userspace read access. '-' indicates there is no 291 'held' for userspace read access. '-' indicates there is no
263 held root. This feature is not yet implemented so '-' is 292 held root.
264 always returned.
265 293
266 discard_passdown|no_discard_passdown 294 discard_passdown|no_discard_passdown
267 Whether or not discards are actually being passed down to the 295 Whether or not discards are actually being passed down to the
diff --git a/Documentation/devicetree/00-INDEX b/Documentation/devicetree/00-INDEX
index b78f691fd847..8c4102c6a5e7 100644
--- a/Documentation/devicetree/00-INDEX
+++ b/Documentation/devicetree/00-INDEX
@@ -8,3 +8,5 @@ https://lists.ozlabs.org/listinfo/devicetree-discuss
8 - this file 8 - this file
9booting-without-of.txt 9booting-without-of.txt
10 - Booting Linux without Open Firmware, describes history and format of device trees. 10 - Booting Linux without Open Firmware, describes history and format of device trees.
11usage-model.txt
12 - How Linux uses DT and what DT aims to solve. \ No newline at end of file
diff --git a/Documentation/devicetree/bindings/arm/omap/omap.txt b/Documentation/devicetree/bindings/arm/omap/omap.txt
index 34dc40cffdfd..af9b4a0d902b 100644
--- a/Documentation/devicetree/bindings/arm/omap/omap.txt
+++ b/Documentation/devicetree/bindings/arm/omap/omap.txt
@@ -91,7 +91,7 @@ Boards:
91 compatible = "ti,omap3-beagle", "ti,omap3" 91 compatible = "ti,omap3-beagle", "ti,omap3"
92 92
93- OMAP3 Tobi with Overo : Commercial expansion board with daughter board 93- OMAP3 Tobi with Overo : Commercial expansion board with daughter board
94 compatible = "ti,omap3-tobi", "ti,omap3-overo", "ti,omap3" 94 compatible = "gumstix,omap3-overo-tobi", "gumstix,omap3-overo", "ti,omap3"
95 95
96- OMAP4 SDP : Software Development Board 96- OMAP4 SDP : Software Development Board
97 compatible = "ti,omap4-sdp", "ti,omap4430" 97 compatible = "ti,omap4-sdp", "ti,omap4430"
diff --git a/Documentation/devicetree/bindings/clock/renesas,cpg-mstp-clocks.txt b/Documentation/devicetree/bindings/clock/renesas,cpg-mstp-clocks.txt
index a6a352c2771e..5992dceec7af 100644
--- a/Documentation/devicetree/bindings/clock/renesas,cpg-mstp-clocks.txt
+++ b/Documentation/devicetree/bindings/clock/renesas,cpg-mstp-clocks.txt
@@ -21,9 +21,9 @@ Required Properties:
21 must appear in the same order as the output clocks. 21 must appear in the same order as the output clocks.
22 - #clock-cells: Must be 1 22 - #clock-cells: Must be 1
23 - clock-output-names: The name of the clocks as free-form strings 23 - clock-output-names: The name of the clocks as free-form strings
24 - renesas,indices: Indices of the gate clocks into the group (0 to 31) 24 - renesas,clock-indices: Indices of the gate clocks into the group (0 to 31)
25 25
26The clocks, clock-output-names and renesas,indices properties contain one 26The clocks, clock-output-names and renesas,clock-indices properties contain one
27entry per gate clock. The MSTP groups are sparsely populated. Unimplemented 27entry per gate clock. The MSTP groups are sparsely populated. Unimplemented
28gate clocks must not be declared. 28gate clocks must not be declared.
29 29
diff --git a/Documentation/devicetree/bindings/dma/fsl-imx-sdma.txt b/Documentation/devicetree/bindings/dma/fsl-imx-sdma.txt
index 68b83ecc3850..ee9be9961524 100644
--- a/Documentation/devicetree/bindings/dma/fsl-imx-sdma.txt
+++ b/Documentation/devicetree/bindings/dma/fsl-imx-sdma.txt
@@ -1,12 +1,16 @@
1* Freescale Smart Direct Memory Access (SDMA) Controller for i.MX 1* Freescale Smart Direct Memory Access (SDMA) Controller for i.MX
2 2
3Required properties: 3Required properties:
4- compatible : Should be "fsl,imx31-sdma", "fsl,imx31-to1-sdma", 4- compatible : Should be one of
5 "fsl,imx31-to2-sdma", "fsl,imx35-sdma", "fsl,imx35-to1-sdma", 5 "fsl,imx25-sdma"
6 "fsl,imx35-to2-sdma", "fsl,imx51-sdma", "fsl,imx53-sdma" or 6 "fsl,imx31-sdma", "fsl,imx31-to1-sdma", "fsl,imx31-to2-sdma"
7 "fsl,imx6q-sdma". The -to variants should be preferred since they 7 "fsl,imx35-sdma", "fsl,imx35-to1-sdma", "fsl,imx35-to2-sdma"
8 allow to determnine the correct ROM script addresses needed for 8 "fsl,imx51-sdma"
9 the driver to work without additional firmware. 9 "fsl,imx53-sdma"
10 "fsl,imx6q-sdma"
11 The -to variants should be preferred since they allow to determnine the
12 correct ROM script addresses needed for the driver to work without additional
13 firmware.
10- reg : Should contain SDMA registers location and length 14- reg : Should contain SDMA registers location and length
11- interrupts : Should contain SDMA interrupt 15- interrupts : Should contain SDMA interrupt
12- #dma-cells : Must be <3>. 16- #dma-cells : Must be <3>.
diff --git a/Documentation/devicetree/bindings/interrupt-controller/lsi,zevio-intc.txt b/Documentation/devicetree/bindings/interrupt-controller/lsi,zevio-intc.txt
new file mode 100644
index 000000000000..aee38e7c13e7
--- /dev/null
+++ b/Documentation/devicetree/bindings/interrupt-controller/lsi,zevio-intc.txt
@@ -0,0 +1,18 @@
1TI-NSPIRE interrupt controller
2
3Required properties:
4- compatible: Compatible property value should be "lsi,zevio-intc".
5
6- reg: Physical base address of the controller and length of memory mapped
7 region.
8
9- interrupt-controller : Identifies the node as an interrupt controller
10
11Example:
12
13interrupt-controller {
14 compatible = "lsi,zevio-intc";
15 interrupt-controller;
16 reg = <0xDC000000 0x1000>;
17 #interrupt-cells = <1>;
18};
diff --git a/Documentation/devicetree/bindings/mmc/atmel-hsmci.txt b/Documentation/devicetree/bindings/mmc/atmel-hsmci.txt
index 0a85c70cd30a..07ad02075a93 100644
--- a/Documentation/devicetree/bindings/mmc/atmel-hsmci.txt
+++ b/Documentation/devicetree/bindings/mmc/atmel-hsmci.txt
@@ -13,6 +13,9 @@ Required properties:
13- #address-cells: should be one. The cell is the slot id. 13- #address-cells: should be one. The cell is the slot id.
14- #size-cells: should be zero. 14- #size-cells: should be zero.
15- at least one slot node 15- at least one slot node
16- clock-names: tuple listing input clock names.
17 Required elements: "mci_clk"
18- clocks: phandles to input clocks.
16 19
17The node contains child nodes for each slot that the platform uses 20The node contains child nodes for each slot that the platform uses
18 21
@@ -24,6 +27,8 @@ mmc0: mmc@f0008000 {
24 interrupts = <12 4>; 27 interrupts = <12 4>;
25 #address-cells = <1>; 28 #address-cells = <1>;
26 #size-cells = <0>; 29 #size-cells = <0>;
30 clock-names = "mci_clk";
31 clocks = <&mci0_clk>;
27 32
28 [ child node definitions...] 33 [ child node definitions...]
29}; 34};
diff --git a/Documentation/devicetree/bindings/net/allwinner,sun4i-emac.txt b/Documentation/devicetree/bindings/net/allwinner,sun4i-emac.txt
index b90bfcd138ff..863d5b8155c7 100644
--- a/Documentation/devicetree/bindings/net/allwinner,sun4i-emac.txt
+++ b/Documentation/devicetree/bindings/net/allwinner,sun4i-emac.txt
@@ -1,7 +1,8 @@
1* Allwinner EMAC ethernet controller 1* Allwinner EMAC ethernet controller
2 2
3Required properties: 3Required properties:
4- compatible: should be "allwinner,sun4i-emac". 4- compatible: should be "allwinner,sun4i-a10-emac" (Deprecated:
5 "allwinner,sun4i-emac")
5- reg: address and length of the register set for the device. 6- reg: address and length of the register set for the device.
6- interrupts: interrupt for the device 7- interrupts: interrupt for the device
7- phy: A phandle to a phy node defining the PHY address (as the reg 8- phy: A phandle to a phy node defining the PHY address (as the reg
@@ -14,7 +15,7 @@ Optional properties:
14Example: 15Example:
15 16
16emac: ethernet@01c0b000 { 17emac: ethernet@01c0b000 {
17 compatible = "allwinner,sun4i-emac"; 18 compatible = "allwinner,sun4i-a10-emac";
18 reg = <0x01c0b000 0x1000>; 19 reg = <0x01c0b000 0x1000>;
19 interrupts = <55>; 20 interrupts = <55>;
20 clocks = <&ahb_gates 17>; 21 clocks = <&ahb_gates 17>;
diff --git a/Documentation/devicetree/bindings/net/allwinner,sun4i-mdio.txt b/Documentation/devicetree/bindings/net/allwinner,sun4i-mdio.txt
index 00b9f9a3ec1d..4ec56413779d 100644
--- a/Documentation/devicetree/bindings/net/allwinner,sun4i-mdio.txt
+++ b/Documentation/devicetree/bindings/net/allwinner,sun4i-mdio.txt
@@ -1,7 +1,8 @@
1* Allwinner A10 MDIO Ethernet Controller interface 1* Allwinner A10 MDIO Ethernet Controller interface
2 2
3Required properties: 3Required properties:
4- compatible: should be "allwinner,sun4i-mdio". 4- compatible: should be "allwinner,sun4i-a10-mdio"
5 (Deprecated: "allwinner,sun4i-mdio").
5- reg: address and length of the register set for the device. 6- reg: address and length of the register set for the device.
6 7
7Optional properties: 8Optional properties:
@@ -9,7 +10,7 @@ Optional properties:
9 10
10Example at the SoC level: 11Example at the SoC level:
11mdio@01c0b080 { 12mdio@01c0b080 {
12 compatible = "allwinner,sun4i-mdio"; 13 compatible = "allwinner,sun4i-a10-mdio";
13 reg = <0x01c0b080 0x14>; 14 reg = <0x01c0b080 0x14>;
14 #address-cells = <1>; 15 #address-cells = <1>;
15 #size-cells = <0>; 16 #size-cells = <0>;
diff --git a/Documentation/devicetree/bindings/net/micrel-ks8851.txt b/Documentation/devicetree/bindings/net/micrel-ks8851.txt
index 11ace3c3d805..4fc392763611 100644
--- a/Documentation/devicetree/bindings/net/micrel-ks8851.txt
+++ b/Documentation/devicetree/bindings/net/micrel-ks8851.txt
@@ -7,3 +7,4 @@ Required properties:
7 7
8Optional properties: 8Optional properties:
9- local-mac-address : Ethernet mac address to use 9- local-mac-address : Ethernet mac address to use
10- vdd-supply: supply for Ethernet mac
diff --git a/Documentation/devicetree/bindings/net/opencores-ethoc.txt b/Documentation/devicetree/bindings/net/opencores-ethoc.txt
new file mode 100644
index 000000000000..2dc127c30d9b
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/opencores-ethoc.txt
@@ -0,0 +1,22 @@
1* OpenCores MAC 10/100 Mbps
2
3Required properties:
4- compatible: Should be "opencores,ethoc".
5- reg: two memory regions (address and length),
6 first region is for the device registers and descriptor rings,
7 second is for the device packet memory.
8- interrupts: interrupt for the device.
9
10Optional properties:
11- clocks: phandle to refer to the clk used as per
12 Documentation/devicetree/bindings/clock/clock-bindings.txt
13
14Examples:
15
16 enet0: ethoc@fd030000 {
17 compatible = "opencores,ethoc";
18 reg = <0xfd030000 0x4000 0xfd800000 0x4000>;
19 interrupts = <1>;
20 local-mac-address = [00 50 c2 13 6f 00];
21 clocks = <&osc>;
22 };
diff --git a/Documentation/devicetree/bindings/net/sti-dwmac.txt b/Documentation/devicetree/bindings/net/sti-dwmac.txt
new file mode 100644
index 000000000000..3dd3d0bf112f
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/sti-dwmac.txt
@@ -0,0 +1,58 @@
1STMicroelectronics SoC DWMAC glue layer controller
2
3The device node has following properties.
4
5Required properties:
6 - compatible : Can be "st,stih415-dwmac", "st,stih416-dwmac" or
7 "st,stid127-dwmac".
8 - reg : Offset of the glue configuration register map in system
9 configuration regmap pointed by st,syscon property and size.
10
11 - reg-names : Should be "sti-ethconf".
12
13 - st,syscon : Should be phandle to system configuration node which
14 encompases this glue registers.
15
16 - st,tx-retime-src: On STi Parts for Giga bit speeds, 125Mhz clocks can be
17 wired up in from different sources. One via TXCLK pin and other via CLK_125
18 pin. This wiring is totally board dependent. However the retiming glue
19 logic should be configured accordingly. Possible values for this property
20
21 "txclk" - if 125Mhz clock is wired up via txclk line.
22 "clk_125" - if 125Mhz clock is wired up via clk_125 line.
23
24 This property is only valid for Giga bit setup( GMII, RGMII), and it is
25 un-used for non-giga bit (MII and RMII) setups. Also note that internal
26 clockgen can not generate stable 125Mhz clock.
27
28 - st,ext-phyclk: This boolean property indicates who is generating the clock
29 for tx and rx. This property is only valid for RMII case where the clock can
30 be generated from the MAC or PHY.
31
32 - clock-names: should be "sti-ethclk".
33 - clocks: Should point to ethernet clockgen which can generate phyclk.
34
35
36Example:
37
38ethernet0: dwmac@fe810000 {
39 device_type = "network";
40 compatible = "st,stih416-dwmac", "snps,dwmac", "snps,dwmac-3.710";
41 reg = <0xfe810000 0x8000>, <0x8bc 0x4>;
42 reg-names = "stmmaceth", "sti-ethconf";
43 interrupts = <0 133 0>, <0 134 0>, <0 135 0>;
44 interrupt-names = "macirq", "eth_wake_irq", "eth_lpi";
45 phy-mode = "mii";
46
47 st,syscon = <&syscfg_rear>;
48
49 snps,pbl = <32>;
50 snps,mixed-burst;
51
52 resets = <&softreset STIH416_ETH0_SOFTRESET>;
53 reset-names = "stmmaceth";
54 pinctrl-0 = <&pinctrl_mii0>;
55 pinctrl-names = "default";
56 clocks = <&CLK_S_GMAC0_PHY>;
57 clock-names = "stmmaceth";
58};
diff --git a/Documentation/devicetree/bindings/pinctrl/brcm,capri-pinctrl.txt b/Documentation/devicetree/bindings/pinctrl/brcm,bcm11351-pinctrl.txt
index 9e9e9ef9f852..c119debe6bab 100644
--- a/Documentation/devicetree/bindings/pinctrl/brcm,capri-pinctrl.txt
+++ b/Documentation/devicetree/bindings/pinctrl/brcm,bcm11351-pinctrl.txt
@@ -1,4 +1,4 @@
1Broadcom Capri Pin Controller 1Broadcom BCM281xx Pin Controller
2 2
3This is a pin controller for the Broadcom BCM281xx SoC family, which includes 3This is a pin controller for the Broadcom BCM281xx SoC family, which includes
4BCM11130, BCM11140, BCM11351, BCM28145, and BCM28155 SoCs. 4BCM11130, BCM11140, BCM11351, BCM28145, and BCM28155 SoCs.
@@ -7,14 +7,14 @@ BCM11130, BCM11140, BCM11351, BCM28145, and BCM28155 SoCs.
7 7
8Required Properties: 8Required Properties:
9 9
10- compatible: Must be "brcm,capri-pinctrl". 10- compatible: Must be "brcm,bcm11351-pinctrl"
11- reg: Base address of the PAD Controller register block and the size 11- reg: Base address of the PAD Controller register block and the size
12 of the block. 12 of the block.
13 13
14For example, the following is the bare minimum node: 14For example, the following is the bare minimum node:
15 15
16 pinctrl@35004800 { 16 pinctrl@35004800 {
17 compatible = "brcm,capri-pinctrl"; 17 compatible = "brcm,bcm11351-pinctrl";
18 reg = <0x35004800 0x430>; 18 reg = <0x35004800 0x430>;
19 }; 19 };
20 20
@@ -119,7 +119,7 @@ Optional Properties (for HDMI pins):
119Example: 119Example:
120// pin controller node 120// pin controller node
121pinctrl@35004800 { 121pinctrl@35004800 {
122 compatible = "brcm,capri-pinctrl"; 122 compatible = "brcmbcm11351-pinctrl";
123 reg = <0x35004800 0x430>; 123 reg = <0x35004800 0x430>;
124 124
125 // pin configuration node 125 // pin configuration node
diff --git a/Documentation/devicetree/bindings/power/bq2415x.txt b/Documentation/devicetree/bindings/power/bq2415x.txt
new file mode 100644
index 000000000000..d0327f0b59ad
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/bq2415x.txt
@@ -0,0 +1,47 @@
1Binding for TI bq2415x Li-Ion Charger
2
3Required properties:
4- compatible: Should contain one of the following:
5 * "ti,bq24150"
6 * "ti,bq24150"
7 * "ti,bq24150a"
8 * "ti,bq24151"
9 * "ti,bq24151a"
10 * "ti,bq24152"
11 * "ti,bq24153"
12 * "ti,bq24153a"
13 * "ti,bq24155"
14 * "ti,bq24156"
15 * "ti,bq24156a"
16 * "ti,bq24158"
17- reg: integer, i2c address of the device.
18- ti,current-limit: integer, initial maximum current charger can pull
19 from power supply in mA.
20- ti,weak-battery-voltage: integer, weak battery voltage threshold in mV.
21 The chip will use slow precharge if battery voltage
22 is below this value.
23- ti,battery-regulation-voltage: integer, maximum charging voltage in mV.
24- ti,charge-current: integer, maximum charging current in mA.
25- ti,termination-current: integer, charge will be terminated when current in
26 constant-voltage phase drops below this value (in mA).
27- ti,resistor-sense: integer, value of sensing resistor in milliohm.
28
29Optional properties:
30- ti,usb-charger-detection: phandle to usb charger detection device.
31 (required for auto mode)
32
33Example from Nokia N900:
34
35bq24150a {
36 compatible = "ti,bq24150a";
37 reg = <0x6b>;
38
39 ti,current-limit = <100>;
40 ti,weak-battery-voltage = <3400>;
41 ti,battery-regulation-voltage = <4200>;
42 ti,charge-current = <650>;
43 ti,termination-current = <100>;
44 ti,resistor-sense = <68>;
45
46 ti,usb-charger-detection = <&isp1704>;
47};
diff --git a/Documentation/devicetree/bindings/spi/spi_atmel.txt b/Documentation/devicetree/bindings/spi/spi_atmel.txt
index 07e04cdc0c9e..4f8184d069cb 100644
--- a/Documentation/devicetree/bindings/spi/spi_atmel.txt
+++ b/Documentation/devicetree/bindings/spi/spi_atmel.txt
@@ -5,6 +5,9 @@ Required properties:
5- reg: Address and length of the register set for the device 5- reg: Address and length of the register set for the device
6- interrupts: Should contain spi interrupt 6- interrupts: Should contain spi interrupt
7- cs-gpios: chipselects 7- cs-gpios: chipselects
8- clock-names: tuple listing input clock names.
9 Required elements: "spi_clk"
10- clocks: phandles to input clocks.
8 11
9Example: 12Example:
10 13
@@ -14,6 +17,8 @@ spi1: spi@fffcc000 {
14 interrupts = <13 4 5>; 17 interrupts = <13 4 5>;
15 #address-cells = <1>; 18 #address-cells = <1>;
16 #size-cells = <0>; 19 #size-cells = <0>;
20 clocks = <&spi1_clk>;
21 clock-names = "spi_clk";
17 cs-gpios = <&pioB 3 0>; 22 cs-gpios = <&pioB 3 0>;
18 status = "okay"; 23 status = "okay";
19 24
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 3f900cd51bf0..40ce2df0e0e9 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -8,6 +8,7 @@ ad Avionic Design GmbH
8adi Analog Devices, Inc. 8adi Analog Devices, Inc.
9aeroflexgaisler Aeroflex Gaisler AB 9aeroflexgaisler Aeroflex Gaisler AB
10ak Asahi Kasei Corp. 10ak Asahi Kasei Corp.
11allwinner Allwinner Technology Co., Ltd.
11altr Altera Corp. 12altr Altera Corp.
12amcc Applied Micro Circuits Corporation (APM, formally AMCC) 13amcc Applied Micro Circuits Corporation (APM, formally AMCC)
13amstaos AMS-Taos Inc. 14amstaos AMS-Taos Inc.
@@ -40,6 +41,7 @@ gmt Global Mixed-mode Technology, Inc.
40gumstix Gumstix, Inc. 41gumstix Gumstix, Inc.
41haoyu Haoyu Microelectronic Co. Ltd. 42haoyu Haoyu Microelectronic Co. Ltd.
42hisilicon Hisilicon Limited. 43hisilicon Hisilicon Limited.
44honeywell Honeywell
43hp Hewlett Packard 45hp Hewlett Packard
44ibm International Business Machines (IBM) 46ibm International Business Machines (IBM)
45idt Integrated Device Technologies, Inc. 47idt Integrated Device Technologies, Inc.
@@ -55,6 +57,7 @@ maxim Maxim Integrated Products
55microchip Microchip Technology Inc. 57microchip Microchip Technology Inc.
56mosaixtech Mosaix Technologies, Inc. 58mosaixtech Mosaix Technologies, Inc.
57national National Semiconductor 59national National Semiconductor
60neonode Neonode Inc.
58nintendo Nintendo 61nintendo Nintendo
59nvidia NVIDIA 62nvidia NVIDIA
60nxp NXP Semiconductors 63nxp NXP Semiconductors
@@ -64,7 +67,7 @@ phytec PHYTEC Messtechnik GmbH
64picochip Picochip Ltd 67picochip Picochip Ltd
65powervr PowerVR (deprecated, use img) 68powervr PowerVR (deprecated, use img)
66qca Qualcomm Atheros, Inc. 69qca Qualcomm Atheros, Inc.
67qcom Qualcomm, Inc. 70qcom Qualcomm Technologies, Inc
68ralink Mediatek/Ralink Technology Corp. 71ralink Mediatek/Ralink Technology Corp.
69ramtron Ramtron International 72ramtron Ramtron International
70realtek Realtek Semiconductor Corp. 73realtek Realtek Semiconductor Corp.
@@ -78,6 +81,7 @@ silabs Silicon Laboratories
78simtek 81simtek
79sirf SiRF Technology, Inc. 82sirf SiRF Technology, Inc.
80snps Synopsys, Inc. 83snps Synopsys, Inc.
84spansion Spansion Inc.
81st STMicroelectronics 85st STMicroelectronics
82ste ST-Ericsson 86ste ST-Ericsson
83stericsson ST-Ericsson 87stericsson ST-Ericsson
diff --git a/Documentation/dvb/contributors.txt b/Documentation/dvb/contributors.txt
index 47c30098dab6..731a009723c7 100644
--- a/Documentation/dvb/contributors.txt
+++ b/Documentation/dvb/contributors.txt
@@ -78,7 +78,7 @@ Peter Beutner <p.beutner@gmx.net>
78Wilson Michaels <wilsonmichaels@earthlink.net> 78Wilson Michaels <wilsonmichaels@earthlink.net>
79 for the lgdt330x frontend driver, and various bugfixes 79 for the lgdt330x frontend driver, and various bugfixes
80 80
81Michael Krufky <mkrufky@m1k.net> 81Michael Krufky <mkrufky@linuxtv.org>
82 for maintaining v4l/dvb inter-tree dependencies 82 for maintaining v4l/dvb inter-tree dependencies
83 83
84Taylor Jacob <rtjacob@earthlink.net> 84Taylor Jacob <rtjacob@earthlink.net>
diff --git a/Documentation/fb/00-INDEX b/Documentation/fb/00-INDEX
index 30a70542e823..fe85e7c5907a 100644
--- a/Documentation/fb/00-INDEX
+++ b/Documentation/fb/00-INDEX
@@ -5,6 +5,8 @@ please mail me.
5 5
600-INDEX 600-INDEX
7 - this file. 7 - this file.
8api.txt
9 - The frame buffer API between applications and buffer devices.
8arkfb.txt 10arkfb.txt
9 - info on the fbdev driver for ARK Logic chips. 11 - info on the fbdev driver for ARK Logic chips.
10aty128fb.txt 12aty128fb.txt
@@ -51,12 +53,16 @@ sh7760fb.txt
51 - info on the SH7760/SH7763 integrated LCDC Framebuffer driver. 53 - info on the SH7760/SH7763 integrated LCDC Framebuffer driver.
52sisfb.txt 54sisfb.txt
53 - info on the framebuffer device driver for various SiS chips. 55 - info on the framebuffer device driver for various SiS chips.
56sm501.txt
57 - info on the framebuffer device driver for sm501 videoframebuffer.
54sstfb.txt 58sstfb.txt
55 - info on the frame buffer driver for 3dfx' Voodoo Graphics boards. 59 - info on the frame buffer driver for 3dfx' Voodoo Graphics boards.
56tgafb.txt 60tgafb.txt
57 - info on the TGA (DECChip 21030) frame buffer driver. 61 - info on the TGA (DECChip 21030) frame buffer driver.
58tridentfb.txt 62tridentfb.txt
59 info on the framebuffer driver for some Trident chip based cards. 63 info on the framebuffer driver for some Trident chip based cards.
64udlfb.txt
65 - Driver for DisplayLink USB 2.0 chips.
60uvesafb.txt 66uvesafb.txt
61 - info on the userspace VESA (VBE2+ compliant) frame buffer device. 67 - info on the userspace VESA (VBE2+ compliant) frame buffer device.
62vesafb.txt 68vesafb.txt
diff --git a/Documentation/filesystems/00-INDEX b/Documentation/filesystems/00-INDEX
index 632211cbdd56..ac28149aede4 100644
--- a/Documentation/filesystems/00-INDEX
+++ b/Documentation/filesystems/00-INDEX
@@ -2,6 +2,8 @@
2 - this file (info on some of the filesystems supported by linux). 2 - this file (info on some of the filesystems supported by linux).
3Locking 3Locking
4 - info on locking rules as they pertain to Linux VFS. 4 - info on locking rules as they pertain to Linux VFS.
5Makefile
6 - Makefile for building the filsystems-part of DocBook.
59p.txt 79p.txt
6 - 9p (v9fs) is an implementation of the Plan 9 remote fs protocol. 8 - 9p (v9fs) is an implementation of the Plan 9 remote fs protocol.
7adfs.txt 9adfs.txt
diff --git a/Documentation/filesystems/nfs/00-INDEX b/Documentation/filesystems/nfs/00-INDEX
index 66eb6c8c5334..53f3b596ac0d 100644
--- a/Documentation/filesystems/nfs/00-INDEX
+++ b/Documentation/filesystems/nfs/00-INDEX
@@ -12,6 +12,8 @@ nfs41-server.txt
12 - info on the Linux server implementation of NFSv4 minor version 1. 12 - info on the Linux server implementation of NFSv4 minor version 1.
13nfs-rdma.txt 13nfs-rdma.txt
14 - how to install and setup the Linux NFS/RDMA client and server software 14 - how to install and setup the Linux NFS/RDMA client and server software
15nfsd-admin-interfaces.txt
16 - Administrative interfaces for nfsd.
15nfsroot.txt 17nfsroot.txt
16 - short guide on setting up a diskless box with NFS root filesystem. 18 - short guide on setting up a diskless box with NFS root filesystem.
17pnfs.txt 19pnfs.txt
@@ -20,5 +22,5 @@ rpc-cache.txt
20 - introduction to the caching mechanisms in the sunrpc layer. 22 - introduction to the caching mechanisms in the sunrpc layer.
21idmapper.txt 23idmapper.txt
22 - information for configuring request-keys to be used by idmapper 24 - information for configuring request-keys to be used by idmapper
23knfsd-rpcgss.txt 25rpc-server-gss.txt
24 - Information on GSS authentication support in the NFS Server 26 - Information on GSS authentication support in the NFS Server
diff --git a/Documentation/i2c/instantiating-devices b/Documentation/i2c/instantiating-devices
index c70e7a7638d1..0d85ac1935b7 100644
--- a/Documentation/i2c/instantiating-devices
+++ b/Documentation/i2c/instantiating-devices
@@ -8,8 +8,8 @@ reason, the kernel code must instantiate I2C devices explicitly. There are
8several ways to achieve this, depending on the context and requirements. 8several ways to achieve this, depending on the context and requirements.
9 9
10 10
11Method 1: Declare the I2C devices by bus number 11Method 1a: Declare the I2C devices by bus number
12----------------------------------------------- 12------------------------------------------------
13 13
14This method is appropriate when the I2C bus is a system bus as is the case 14This method is appropriate when the I2C bus is a system bus as is the case
15for many embedded systems. On such systems, each I2C bus has a number 15for many embedded systems. On such systems, each I2C bus has a number
@@ -51,6 +51,43 @@ The devices will be automatically unbound and destroyed when the I2C bus
51they sit on goes away (if ever.) 51they sit on goes away (if ever.)
52 52
53 53
54Method 1b: Declare the I2C devices via devicetree
55-------------------------------------------------
56
57This method has the same implications as method 1a. The declaration of I2C
58devices is here done via devicetree as subnodes of the master controller.
59
60Example:
61
62 i2c1: i2c@400a0000 {
63 /* ... master properties skipped ... */
64 clock-frequency = <100000>;
65
66 flash@50 {
67 compatible = "atmel,24c256";
68 reg = <0x50>;
69 };
70
71 pca9532: gpio@60 {
72 compatible = "nxp,pca9532";
73 gpio-controller;
74 #gpio-cells = <2>;
75 reg = <0x60>;
76 };
77 };
78
79Here, two devices are attached to the bus using a speed of 100kHz. For
80additional properties which might be needed to set up the device, please refer
81to its devicetree documentation in Documentation/devicetree/bindings/.
82
83
84Method 1c: Declare the I2C devices via ACPI
85-------------------------------------------
86
87ACPI can also describe I2C devices. There is special documentation for this
88which is currently located at Documentation/acpi/enumeration.txt.
89
90
54Method 2: Instantiate the devices explicitly 91Method 2: Instantiate the devices explicitly
55-------------------------------------------- 92--------------------------------------------
56 93
diff --git a/Documentation/ide/00-INDEX b/Documentation/ide/00-INDEX
index d6b778842b75..22f98ca79539 100644
--- a/Documentation/ide/00-INDEX
+++ b/Documentation/ide/00-INDEX
@@ -10,3 +10,5 @@ ide-tape.txt
10 - info on the IDE ATAPI streaming tape driver 10 - info on the IDE ATAPI streaming tape driver
11ide.txt 11ide.txt
12 - important info for users of ATA devices (IDE/EIDE disks and CD-ROMS). 12 - important info for users of ATA devices (IDE/EIDE disks and CD-ROMS).
13warm-plug-howto.txt
14 - using sysfs to remove and add IDE devices. \ No newline at end of file
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 8f441dab0396..67755ea834a7 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1011,6 +1011,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
1011 parameter will force ia64_sal_cache_flush to call 1011 parameter will force ia64_sal_cache_flush to call
1012 ia64_pal_cache_flush instead of SAL_CACHE_FLUSH. 1012 ia64_pal_cache_flush instead of SAL_CACHE_FLUSH.
1013 1013
1014 forcepae [X86-32]
1015 Forcefully enable Physical Address Extension (PAE).
1016 Many Pentium M systems disable PAE but may have a
1017 functionally usable PAE implementation.
1018 Warning: use of this parameter will taint the kernel
1019 and may cause unknown problems.
1020
1014 ftrace=[tracer] 1021 ftrace=[tracer]
1015 [FTRACE] will set and start the specified tracer 1022 [FTRACE] will set and start the specified tracer
1016 as early as possible in order to facilitate early 1023 as early as possible in order to facilitate early
@@ -1726,16 +1733,16 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
1726 option description. 1733 option description.
1727 1734
1728 memmap=nn[KMG]@ss[KMG] 1735 memmap=nn[KMG]@ss[KMG]
1729 [KNL] Force usage of a specific region of memory 1736 [KNL] Force usage of a specific region of memory.
1730 Region of memory to be used, from ss to ss+nn. 1737 Region of memory to be used is from ss to ss+nn.
1731 1738
1732 memmap=nn[KMG]#ss[KMG] 1739 memmap=nn[KMG]#ss[KMG]
1733 [KNL,ACPI] Mark specific memory as ACPI data. 1740 [KNL,ACPI] Mark specific memory as ACPI data.
1734 Region of memory to be used, from ss to ss+nn. 1741 Region of memory to be marked is from ss to ss+nn.
1735 1742
1736 memmap=nn[KMG]$ss[KMG] 1743 memmap=nn[KMG]$ss[KMG]
1737 [KNL,ACPI] Mark specific memory as reserved. 1744 [KNL,ACPI] Mark specific memory as reserved.
1738 Region of memory to be used, from ss to ss+nn. 1745 Region of memory to be reserved is from ss to ss+nn.
1739 Example: Exclude memory from 0x18690000-0x1869ffff 1746 Example: Exclude memory from 0x18690000-0x1869ffff
1740 memmap=64K$0x18690000 1747 memmap=64K$0x18690000
1741 or 1748 or
@@ -2053,8 +2060,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
2053 IOAPICs that may be present in the system. 2060 IOAPICs that may be present in the system.
2054 2061
2055 nokaslr [X86] 2062 nokaslr [X86]
2056 Disable kernel base offset ASLR (Address Space 2063 Disable kernel and module base offset ASLR (Address
2057 Layout Randomization) if built into the kernel. 2064 Space Layout Randomization) if built into the kernel.
2058 2065
2059 noautogroup Disable scheduler automatic task group creation. 2066 noautogroup Disable scheduler automatic task group creation.
2060 2067
diff --git a/Documentation/kernel-per-CPU-kthreads.txt b/Documentation/kernel-per-CPU-kthreads.txt
index 827104fb9364..f3cd299fcc41 100644
--- a/Documentation/kernel-per-CPU-kthreads.txt
+++ b/Documentation/kernel-per-CPU-kthreads.txt
@@ -162,7 +162,18 @@ Purpose: Execute workqueue requests
162To reduce its OS jitter, do any of the following: 162To reduce its OS jitter, do any of the following:
1631. Run your workload at a real-time priority, which will allow 1631. Run your workload at a real-time priority, which will allow
164 preempting the kworker daemons. 164 preempting the kworker daemons.
1652. Do any of the following needed to avoid jitter that your 1652. A given workqueue can be made visible in the sysfs filesystem
166 by passing the WQ_SYSFS to that workqueue's alloc_workqueue().
167 Such a workqueue can be confined to a given subset of the
168 CPUs using the /sys/devices/virtual/workqueue/*/cpumask sysfs
169 files. The set of WQ_SYSFS workqueues can be displayed using
170 "ls sys/devices/virtual/workqueue". That said, the workqueues
171 maintainer would like to caution people against indiscriminately
172 sprinkling WQ_SYSFS across all the workqueues. The reason for
173 caution is that it is easy to add WQ_SYSFS, but because sysfs is
174 part of the formal user/kernel API, it can be nearly impossible
175 to remove it, even if its addition was a mistake.
1763. Do any of the following needed to avoid jitter that your
166 application cannot tolerate: 177 application cannot tolerate:
167 a. Build your kernel with CONFIG_SLUB=y rather than 178 a. Build your kernel with CONFIG_SLUB=y rather than
168 CONFIG_SLAB=y, thus avoiding the slab allocator's periodic 179 CONFIG_SLAB=y, thus avoiding the slab allocator's periodic
diff --git a/Documentation/laptops/00-INDEX b/Documentation/laptops/00-INDEX
index fa688538e757..d13b9a9a9e00 100644
--- a/Documentation/laptops/00-INDEX
+++ b/Documentation/laptops/00-INDEX
@@ -1,13 +1,15 @@
100-INDEX 100-INDEX
2 - This file 2 - This file
3acer-wmi.txt 3Makefile
4 - information on the Acer Laptop WMI Extras driver. 4 - Makefile for building dslm example program.
5asus-laptop.txt 5asus-laptop.txt
6 - information on the Asus Laptop Extras driver. 6 - information on the Asus Laptop Extras driver.
7disk-shock-protection.txt 7disk-shock-protection.txt
8 - information on hard disk shock protection. 8 - information on hard disk shock protection.
9dslm.c 9dslm.c
10 - Simple Disk Sleep Monitor program 10 - Simple Disk Sleep Monitor program
11hpfall.c
12 - (HP) laptop accelerometer program for disk protection.
11laptop-mode.txt 13laptop-mode.txt
12 - how to conserve battery power using laptop-mode. 14 - how to conserve battery power using laptop-mode.
13sony-laptop.txt 15sony-laptop.txt
diff --git a/Documentation/leds/00-INDEX b/Documentation/leds/00-INDEX
index 1ecd1596633e..b4ef1f34e25f 100644
--- a/Documentation/leds/00-INDEX
+++ b/Documentation/leds/00-INDEX
@@ -1,3 +1,7 @@
100-INDEX
2 - This file
3leds-blinkm.txt
4 - Driver for BlinkM LED-devices.
1leds-class.txt 5leds-class.txt
2 - documents LED handling under Linux. 6 - documents LED handling under Linux.
3leds-lp3944.txt 7leds-lp3944.txt
@@ -12,3 +16,7 @@ leds-lp55xx.txt
12 - description about lp55xx common driver. 16 - description about lp55xx common driver.
13leds-lm3556.txt 17leds-lm3556.txt
14 - notes on how to use the leds-lm3556 driver. 18 - notes on how to use the leds-lm3556 driver.
19ledtrig-oneshot.txt
20 - One-shot LED trigger for both sporadic and dense events.
21ledtrig-transient.txt
22 - LED Transient Trigger, one shot timer activation.
diff --git a/Documentation/m68k/00-INDEX b/Documentation/m68k/00-INDEX
index a014e9f00765..2be8c6b00e74 100644
--- a/Documentation/m68k/00-INDEX
+++ b/Documentation/m68k/00-INDEX
@@ -1,5 +1,7 @@
100-INDEX 100-INDEX
2 - this file 2 - this file
3README.buddha
4 - Amiga Buddha and Catweasel IDE Driver
3kernel-options.txt 5kernel-options.txt
4 - command line options for Linux/m68k 6 - command line options for Linux/m68k
5 7
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
index 102dc19c4119..11c1d2049662 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -608,26 +608,30 @@ as follows:
608 b = p; /* BUG: Compiler can reorder!!! */ 608 b = p; /* BUG: Compiler can reorder!!! */
609 do_something(); 609 do_something();
610 610
611The solution is again ACCESS_ONCE(), which preserves the ordering between 611The solution is again ACCESS_ONCE() and barrier(), which preserves the
612the load from variable 'a' and the store to variable 'b': 612ordering between the load from variable 'a' and the store to variable 'b':
613 613
614 q = ACCESS_ONCE(a); 614 q = ACCESS_ONCE(a);
615 if (q) { 615 if (q) {
616 barrier();
616 ACCESS_ONCE(b) = p; 617 ACCESS_ONCE(b) = p;
617 do_something(); 618 do_something();
618 } else { 619 } else {
620 barrier();
619 ACCESS_ONCE(b) = p; 621 ACCESS_ONCE(b) = p;
620 do_something_else(); 622 do_something_else();
621 } 623 }
622 624
623You could also use barrier() to prevent the compiler from moving 625The initial ACCESS_ONCE() is required to prevent the compiler from
624the stores to variable 'b', but barrier() would not prevent the 626proving the value of 'a', and the pair of barrier() invocations are
625compiler from proving to itself that a==1 always, so ACCESS_ONCE() 627required to prevent the compiler from pulling the two identical stores
626is also needed. 628to 'b' out from the legs of the "if" statement.
627 629
628It is important to note that control dependencies absolutely require a 630It is important to note that control dependencies absolutely require a
629a conditional. For example, the following "optimized" version of 631a conditional. For example, the following "optimized" version of
630the above example breaks ordering: 632the above example breaks ordering, which is why the barrier() invocations
633are absolutely required if you have identical stores in both legs of
634the "if" statement:
631 635
632 q = ACCESS_ONCE(a); 636 q = ACCESS_ONCE(a);
633 ACCESS_ONCE(b) = p; /* BUG: No ordering vs. load from a!!! */ 637 ACCESS_ONCE(b) = p; /* BUG: No ordering vs. load from a!!! */
@@ -643,9 +647,11 @@ It is of course legal for the prior load to be part of the conditional,
643for example, as follows: 647for example, as follows:
644 648
645 if (ACCESS_ONCE(a) > 0) { 649 if (ACCESS_ONCE(a) > 0) {
650 barrier();
646 ACCESS_ONCE(b) = q / 2; 651 ACCESS_ONCE(b) = q / 2;
647 do_something(); 652 do_something();
648 } else { 653 } else {
654 barrier();
649 ACCESS_ONCE(b) = q / 3; 655 ACCESS_ONCE(b) = q / 3;
650 do_something_else(); 656 do_something_else();
651 } 657 }
@@ -659,9 +665,11 @@ the needed conditional. For example:
659 665
660 q = ACCESS_ONCE(a); 666 q = ACCESS_ONCE(a);
661 if (q % MAX) { 667 if (q % MAX) {
668 barrier();
662 ACCESS_ONCE(b) = p; 669 ACCESS_ONCE(b) = p;
663 do_something(); 670 do_something();
664 } else { 671 } else {
672 barrier();
665 ACCESS_ONCE(b) = p; 673 ACCESS_ONCE(b) = p;
666 do_something_else(); 674 do_something_else();
667 } 675 }
@@ -723,8 +731,13 @@ In summary:
723 use smb_rmb(), smp_wmb(), or, in the case of prior stores and 731 use smb_rmb(), smp_wmb(), or, in the case of prior stores and
724 later loads, smp_mb(). 732 later loads, smp_mb().
725 733
734 (*) If both legs of the "if" statement begin with identical stores
735 to the same variable, a barrier() statement is required at the
736 beginning of each leg of the "if" statement.
737
726 (*) Control dependencies require at least one run-time conditional 738 (*) Control dependencies require at least one run-time conditional
727 between the prior load and the subsequent store. If the compiler 739 between the prior load and the subsequent store, and this
740 conditional must involve the prior load. If the compiler
728 is able to optimize the conditional away, it will have also 741 is able to optimize the conditional away, it will have also
729 optimized away the ordering. Careful use of ACCESS_ONCE() can 742 optimized away the ordering. Careful use of ACCESS_ONCE() can
730 help to preserve the needed conditional. 743 help to preserve the needed conditional.
@@ -1249,6 +1262,23 @@ The ACCESS_ONCE() function can prevent any number of optimizations that,
1249while perfectly safe in single-threaded code, can be fatal in concurrent 1262while perfectly safe in single-threaded code, can be fatal in concurrent
1250code. Here are some examples of these sorts of optimizations: 1263code. Here are some examples of these sorts of optimizations:
1251 1264
1265 (*) The compiler is within its rights to reorder loads and stores
1266 to the same variable, and in some cases, the CPU is within its
1267 rights to reorder loads to the same variable. This means that
1268 the following code:
1269
1270 a[0] = x;
1271 a[1] = x;
1272
1273 Might result in an older value of x stored in a[1] than in a[0].
1274 Prevent both the compiler and the CPU from doing this as follows:
1275
1276 a[0] = ACCESS_ONCE(x);
1277 a[1] = ACCESS_ONCE(x);
1278
1279 In short, ACCESS_ONCE() provides cache coherence for accesses from
1280 multiple CPUs to a single variable.
1281
1252 (*) The compiler is within its rights to merge successive loads from 1282 (*) The compiler is within its rights to merge successive loads from
1253 the same variable. Such merging can cause the compiler to "optimize" 1283 the same variable. Such merging can cause the compiler to "optimize"
1254 the following code: 1284 the following code:
@@ -1644,12 +1674,12 @@ for each construct. These operations all imply certain barriers:
1644 Memory operations issued after the ACQUIRE will be completed after the 1674 Memory operations issued after the ACQUIRE will be completed after the
1645 ACQUIRE operation has completed. 1675 ACQUIRE operation has completed.
1646 1676
1647 Memory operations issued before the ACQUIRE may be completed after the 1677 Memory operations issued before the ACQUIRE may be completed after
1648 ACQUIRE operation has completed. An smp_mb__before_spinlock(), combined 1678 the ACQUIRE operation has completed. An smp_mb__before_spinlock(),
1649 with a following ACQUIRE, orders prior loads against subsequent stores and 1679 combined with a following ACQUIRE, orders prior loads against
1650 stores and prior stores against subsequent stores. Note that this is 1680 subsequent loads and stores and also orders prior stores against
1651 weaker than smp_mb()! The smp_mb__before_spinlock() primitive is free on 1681 subsequent stores. Note that this is weaker than smp_mb()! The
1652 many architectures. 1682 smp_mb__before_spinlock() primitive is free on many architectures.
1653 1683
1654 (2) RELEASE operation implication: 1684 (2) RELEASE operation implication:
1655 1685
@@ -1694,24 +1724,21 @@ may occur as:
1694 1724
1695 ACQUIRE M, STORE *B, STORE *A, RELEASE M 1725 ACQUIRE M, STORE *B, STORE *A, RELEASE M
1696 1726
1697This same reordering can of course occur if the lock's ACQUIRE and RELEASE are 1727When the ACQUIRE and RELEASE are a lock acquisition and release,
1698to the same lock variable, but only from the perspective of another CPU not 1728respectively, this same reordering can occur if the lock's ACQUIRE and
1699holding that lock. 1729RELEASE are to the same lock variable, but only from the perspective of
1700 1730another CPU not holding that lock. In short, a ACQUIRE followed by an
1701In short, a RELEASE followed by an ACQUIRE may -not- be assumed to be a full 1731RELEASE may -not- be assumed to be a full memory barrier.
1702memory barrier because it is possible for a preceding RELEASE to pass a 1732
1703later ACQUIRE from the viewpoint of the CPU, but not from the viewpoint 1733Similarly, the reverse case of a RELEASE followed by an ACQUIRE does not
1704of the compiler. Note that deadlocks cannot be introduced by this 1734imply a full memory barrier. If it is necessary for a RELEASE-ACQUIRE
1705interchange because if such a deadlock threatened, the RELEASE would 1735pair to produce a full barrier, the ACQUIRE can be followed by an
1706simply complete. 1736smp_mb__after_unlock_lock() invocation. This will produce a full barrier
1707 1737if either (a) the RELEASE and the ACQUIRE are executed by the same
1708If it is necessary for a RELEASE-ACQUIRE pair to produce a full barrier, the 1738CPU or task, or (b) the RELEASE and ACQUIRE act on the same variable.
1709ACQUIRE can be followed by an smp_mb__after_unlock_lock() invocation. This 1739The smp_mb__after_unlock_lock() primitive is free on many architectures.
1710will produce a full barrier if either (a) the RELEASE and the ACQUIRE are 1740Without smp_mb__after_unlock_lock(), the CPU's execution of the critical
1711executed by the same CPU or task, or (b) the RELEASE and ACQUIRE act on the 1741sections corresponding to the RELEASE and the ACQUIRE can cross, so that:
1712same variable. The smp_mb__after_unlock_lock() primitive is free on many
1713architectures. Without smp_mb__after_unlock_lock(), the critical sections
1714corresponding to the RELEASE and the ACQUIRE can cross:
1715 1742
1716 *A = a; 1743 *A = a;
1717 RELEASE M 1744 RELEASE M
@@ -1722,7 +1749,36 @@ could occur as:
1722 1749
1723 ACQUIRE N, STORE *B, STORE *A, RELEASE M 1750 ACQUIRE N, STORE *B, STORE *A, RELEASE M
1724 1751
1725With smp_mb__after_unlock_lock(), they cannot, so that: 1752It might appear that this reordering could introduce a deadlock.
1753However, this cannot happen because if such a deadlock threatened,
1754the RELEASE would simply complete, thereby avoiding the deadlock.
1755
1756 Why does this work?
1757
1758 One key point is that we are only talking about the CPU doing
1759 the reordering, not the compiler. If the compiler (or, for
1760 that matter, the developer) switched the operations, deadlock
1761 -could- occur.
1762
1763 But suppose the CPU reordered the operations. In this case,
1764 the unlock precedes the lock in the assembly code. The CPU
1765 simply elected to try executing the later lock operation first.
1766 If there is a deadlock, this lock operation will simply spin (or
1767 try to sleep, but more on that later). The CPU will eventually
1768 execute the unlock operation (which preceded the lock operation
1769 in the assembly code), which will unravel the potential deadlock,
1770 allowing the lock operation to succeed.
1771
1772 But what if the lock is a sleeplock? In that case, the code will
1773 try to enter the scheduler, where it will eventually encounter
1774 a memory barrier, which will force the earlier unlock operation
1775 to complete, again unraveling the deadlock. There might be
1776 a sleep-unlock race, but the locking primitive needs to resolve
1777 such races properly in any case.
1778
1779With smp_mb__after_unlock_lock(), the two critical sections cannot overlap.
1780For example, with the following code, the store to *A will always be
1781seen by other CPUs before the store to *B:
1726 1782
1727 *A = a; 1783 *A = a;
1728 RELEASE M 1784 RELEASE M
@@ -1730,13 +1786,18 @@ With smp_mb__after_unlock_lock(), they cannot, so that:
1730 smp_mb__after_unlock_lock(); 1786 smp_mb__after_unlock_lock();
1731 *B = b; 1787 *B = b;
1732 1788
1733will always occur as either of the following: 1789The operations will always occur in one of the following orders:
1734 1790
1735 STORE *A, RELEASE, ACQUIRE, STORE *B 1791 STORE *A, RELEASE, ACQUIRE, smp_mb__after_unlock_lock(), STORE *B
1736 STORE *A, ACQUIRE, RELEASE, STORE *B 1792 STORE *A, ACQUIRE, RELEASE, smp_mb__after_unlock_lock(), STORE *B
1793 ACQUIRE, STORE *A, RELEASE, smp_mb__after_unlock_lock(), STORE *B
1737 1794
1738If the RELEASE and ACQUIRE were instead both operating on the same lock 1795If the RELEASE and ACQUIRE were instead both operating on the same lock
1739variable, only the first of these two alternatives can occur. 1796variable, only the first of these alternatives can occur. In addition,
1797the more strongly ordered systems may rule out some of the above orders.
1798But in any case, as noted earlier, the smp_mb__after_unlock_lock()
1799ensures that the store to *A will always be seen as happening before
1800the store to *B.
1740 1801
1741Locks and semaphores may not provide any guarantee of ordering on UP compiled 1802Locks and semaphores may not provide any guarantee of ordering on UP compiled
1742systems, and so cannot be counted on in such a situation to actually achieve 1803systems, and so cannot be counted on in such a situation to actually achieve
@@ -2757,7 +2818,7 @@ in that order, but, without intervention, the sequence may have almost any
2757combination of elements combined or discarded, provided the program's view of 2818combination of elements combined or discarded, provided the program's view of
2758the world remains consistent. Note that ACCESS_ONCE() is -not- optional 2819the world remains consistent. Note that ACCESS_ONCE() is -not- optional
2759in the above example, as there are architectures where a given CPU might 2820in the above example, as there are architectures where a given CPU might
2760interchange successive loads to the same location. On such architectures, 2821reorder successive loads to the same location. On such architectures,
2761ACCESS_ONCE() does whatever is necessary to prevent this, for example, on 2822ACCESS_ONCE() does whatever is necessary to prevent this, for example, on
2762Itanium the volatile casts used by ACCESS_ONCE() cause GCC to emit the 2823Itanium the volatile casts used by ACCESS_ONCE() cause GCC to emit the
2763special ld.acq and st.rel instructions that prevent such reordering. 2824special ld.acq and st.rel instructions that prevent such reordering.
diff --git a/Documentation/networking/00-INDEX b/Documentation/networking/00-INDEX
index f11580f8719a..557b6ef70c26 100644
--- a/Documentation/networking/00-INDEX
+++ b/Documentation/networking/00-INDEX
@@ -6,8 +6,14 @@
6 - information on the 3Com Etherlink III Series Ethernet cards. 6 - information on the 3Com Etherlink III Series Ethernet cards.
76pack.txt 76pack.txt
8 - info on the 6pack protocol, an alternative to KISS for AX.25 8 - info on the 6pack protocol, an alternative to KISS for AX.25
9DLINK.txt 9LICENSE.qla3xxx
10 - info on the D-Link DE-600/DE-620 parallel port pocket adapters 10 - GPLv2 for QLogic Linux Networking HBA Driver
11LICENSE.qlge
12 - GPLv2 for QLogic Linux qlge NIC Driver
13LICENSE.qlcnic
14 - GPLv2 for QLogic Linux qlcnic NIC Driver
15Makefile
16 - Makefile for docsrc.
11PLIP.txt 17PLIP.txt
12 - PLIP: The Parallel Line Internet Protocol device driver 18 - PLIP: The Parallel Line Internet Protocol device driver
13README.ipw2100 19README.ipw2100
@@ -17,7 +23,7 @@ README.ipw2200
17README.sb1000 23README.sb1000
18 - info on General Instrument/NextLevel SURFboard1000 cable modem. 24 - info on General Instrument/NextLevel SURFboard1000 cable modem.
19alias.txt 25alias.txt
20 - info on using alias network devices 26 - info on using alias network devices.
21arcnet-hardware.txt 27arcnet-hardware.txt
22 - tons of info on ARCnet, hubs, jumper settings for ARCnet cards, etc. 28 - tons of info on ARCnet, hubs, jumper settings for ARCnet cards, etc.
23arcnet.txt 29arcnet.txt
@@ -80,7 +86,7 @@ framerelay.txt
80 - info on using Frame Relay/Data Link Connection Identifier (DLCI). 86 - info on using Frame Relay/Data Link Connection Identifier (DLCI).
81gen_stats.txt 87gen_stats.txt
82 - Generic networking statistics for netlink users. 88 - Generic networking statistics for netlink users.
83generic_hdlc.txt 89generic-hdlc.txt
84 - The generic High Level Data Link Control (HDLC) layer. 90 - The generic High Level Data Link Control (HDLC) layer.
85generic_netlink.txt 91generic_netlink.txt
86 - info on Generic Netlink 92 - info on Generic Netlink
@@ -88,6 +94,8 @@ gianfar.txt
88 - Gianfar Ethernet Driver. 94 - Gianfar Ethernet Driver.
89i40e.txt 95i40e.txt
90 - README for the Intel Ethernet Controller XL710 Driver (i40e). 96 - README for the Intel Ethernet Controller XL710 Driver (i40e).
97i40evf.txt
98 - Short note on the Driver for the Intel(R) XL710 X710 Virtual Function
91ieee802154.txt 99ieee802154.txt
92 - Linux IEEE 802.15.4 implementation, API and drivers 100 - Linux IEEE 802.15.4 implementation, API and drivers
93igb.txt 101igb.txt
@@ -102,6 +110,8 @@ ipddp.txt
102 - AppleTalk-IP Decapsulation and AppleTalk-IP Encapsulation 110 - AppleTalk-IP Decapsulation and AppleTalk-IP Encapsulation
103iphase.txt 111iphase.txt
104 - Interphase PCI ATM (i)Chip IA Linux driver info. 112 - Interphase PCI ATM (i)Chip IA Linux driver info.
113ipsec.txt
114 - Note on not compressing IPSec payload and resulting failed policy check.
105ipv6.txt 115ipv6.txt
106 - Options to the ipv6 kernel module. 116 - Options to the ipv6 kernel module.
107ipvs-sysctl.txt 117ipvs-sysctl.txt
@@ -120,6 +130,8 @@ lapb-module.txt
120 - programming information of the LAPB module. 130 - programming information of the LAPB module.
121ltpc.txt 131ltpc.txt
122 - the Apple or Farallon LocalTalk PC card driver 132 - the Apple or Farallon LocalTalk PC card driver
133mac80211-auth-assoc-deauth.txt
134 - authentication and association / deauth-disassoc with max80211
123mac80211-injection.txt 135mac80211-injection.txt
124 - HOWTO use packet injection with mac80211 136 - HOWTO use packet injection with mac80211
125multiqueue.txt 137multiqueue.txt
@@ -134,6 +146,10 @@ netdevices.txt
134 - info on network device driver functions exported to the kernel. 146 - info on network device driver functions exported to the kernel.
135netif-msg.txt 147netif-msg.txt
136 - Design of the network interface message level setting (NETIF_MSG_*). 148 - Design of the network interface message level setting (NETIF_MSG_*).
149netlink_mmap.txt
150 - memory mapped I/O with netlink
151nf_conntrack-sysctl.txt
152 - list of netfilter-sysctl knobs.
137nfc.txt 153nfc.txt
138 - The Linux Near Field Communication (NFS) subsystem. 154 - The Linux Near Field Communication (NFS) subsystem.
139openvswitch.txt 155openvswitch.txt
@@ -176,7 +192,7 @@ skfp.txt
176 - SysKonnect FDDI (SK-5xxx, Compaq Netelligent) driver info. 192 - SysKonnect FDDI (SK-5xxx, Compaq Netelligent) driver info.
177smc9.txt 193smc9.txt
178 - the driver for SMC's 9000 series of Ethernet cards 194 - the driver for SMC's 9000 series of Ethernet cards
179spider-net.txt 195spider_net.txt
180 - README for the Spidernet Driver (as found in PS3 / Cell BE). 196 - README for the Spidernet Driver (as found in PS3 / Cell BE).
181stmmac.txt 197stmmac.txt
182 - README for the STMicro Synopsys Ethernet driver. 198 - README for the STMicro Synopsys Ethernet driver.
@@ -188,6 +204,8 @@ tcp.txt
188 - short blurb on how TCP output takes place. 204 - short blurb on how TCP output takes place.
189tcp-thin.txt 205tcp-thin.txt
190 - kernel tuning options for low rate 'thin' TCP streams. 206 - kernel tuning options for low rate 'thin' TCP streams.
207team.txt
208 - pointer to information for ethernet teaming devices.
191tlan.txt 209tlan.txt
192 - ThunderLAN (Compaq Netelligent 10/100, Olicom OC-2xxx) driver info. 210 - ThunderLAN (Compaq Netelligent 10/100, Olicom OC-2xxx) driver info.
193tproxy.txt 211tproxy.txt
@@ -200,6 +218,8 @@ vortex.txt
200 - info on using 3Com Vortex (3c590, 3c592, 3c595, 3c597) Ethernet cards. 218 - info on using 3Com Vortex (3c590, 3c592, 3c595, 3c597) Ethernet cards.
201vxge.txt 219vxge.txt
202 - README for the Neterion X3100 PCIe Server Adapter. 220 - README for the Neterion X3100 PCIe Server Adapter.
221vxlan.txt
222 - Virtual extensible LAN overview
203x25.txt 223x25.txt
204 - general info on X.25 development. 224 - general info on X.25 development.
205x25-iface.txt 225x25-iface.txt
diff --git a/Documentation/networking/3c505.txt b/Documentation/networking/3c505.txt
deleted file mode 100644
index 72f38b13101d..000000000000
--- a/Documentation/networking/3c505.txt
+++ /dev/null
@@ -1,45 +0,0 @@
1The 3Com Etherlink Plus (3c505) driver.
2
3This driver now uses DMA. There is currently no support for PIO operation.
4The default DMA channel is 6; this is _not_ autoprobed, so you must
5make sure you configure it correctly. If loading the driver as a
6module, you can do this with "modprobe 3c505 dma=n". If the driver is
7linked statically into the kernel, you must either use an "ether="
8statement on the command line, or change the definition of ELP_DMA in 3c505.h.
9
10The driver will warn you if it has to fall back on the compiled in
11default DMA channel.
12
13If no base address is given at boot time, the driver will autoprobe
14ports 0x300, 0x280 and 0x310 (in that order). If no IRQ is given, the driver
15will try to probe for it.
16
17The driver can be used as a loadable module.
18
19Theoretically, one instance of the driver can now run multiple cards,
20in the standard way (when loading a module, say "modprobe 3c505
21io=0x300,0x340 irq=10,11 dma=6,7" or whatever). I have not tested
22this, though.
23
24The driver may now support revision 2 hardware; the dependency on
25being able to read the host control register has been removed. This
26is also untested, since I don't have a suitable card.
27
28Known problems:
29 I still see "DMA upload timed out" messages from time to time. These
30seem to be fairly non-fatal though.
31 The card is old and slow.
32
33To do:
34 Improve probe/setup code
35 Test multicast and promiscuous operation
36
37Authors:
38 The driver is mainly written by Craig Southeren, email
39 <craigs@ineluki.apana.org.au>.
40 Parts of the driver (adapting the driver to 1.1.4+ kernels,
41 IRQ/address detection, some changes) and this README by
42 Juha Laiho <jlaiho@ichaos.nullnet.fi>.
43 DMA mode, more fixes, etc, by Philip Blundell <pjb27@cam.ac.uk>
44 Multicard support, Software configurable DMA, etc., by
45 Christopher Collins <ccollins@pcug.org.au>
diff --git a/Documentation/networking/can.txt b/Documentation/networking/can.txt
index f3089d423515..0cbe6ec22d6f 100644
--- a/Documentation/networking/can.txt
+++ b/Documentation/networking/can.txt
@@ -554,12 +554,6 @@ solution for a couple of reasons:
554 not specified in the struct can_frame and therefore it is only valid in 554 not specified in the struct can_frame and therefore it is only valid in
555 CANFD_MTU sized CAN FD frames. 555 CANFD_MTU sized CAN FD frames.
556 556
557 As long as the payload length is <=8 the received CAN frames from CAN FD
558 capable CAN devices can be received and read by legacy sockets too. When
559 user-generated CAN FD frames have a payload length <=8 these can be send
560 by legacy CAN network interfaces too. Sending CAN FD frames with payload
561 length > 8 to a legacy CAN network interface returns an -EMSGSIZE error.
562
563 Implementation hint for new CAN applications: 557 Implementation hint for new CAN applications:
564 558
565 To build a CAN FD aware application use struct canfd_frame as basic CAN 559 To build a CAN FD aware application use struct canfd_frame as basic CAN
diff --git a/Documentation/networking/netlink_mmap.txt b/Documentation/networking/netlink_mmap.txt
index b26122973525..c6af4bac5aa8 100644
--- a/Documentation/networking/netlink_mmap.txt
+++ b/Documentation/networking/netlink_mmap.txt
@@ -226,9 +226,9 @@ Ring setup:
226 void *rx_ring, *tx_ring; 226 void *rx_ring, *tx_ring;
227 227
228 /* Configure ring parameters */ 228 /* Configure ring parameters */
229 if (setsockopt(fd, NETLINK_RX_RING, &req, sizeof(req)) < 0) 229 if (setsockopt(fd, SOL_NETLINK, NETLINK_RX_RING, &req, sizeof(req)) < 0)
230 exit(1); 230 exit(1);
231 if (setsockopt(fd, NETLINK_TX_RING, &req, sizeof(req)) < 0) 231 if (setsockopt(fd, SOL_NETLINK, NETLINK_TX_RING, &req, sizeof(req)) < 0)
232 exit(1) 232 exit(1)
233 233
234 /* Calculate size of each individual ring */ 234 /* Calculate size of each individual ring */
diff --git a/Documentation/networking/packet_mmap.txt b/Documentation/networking/packet_mmap.txt
index 1404674c0a02..6fea79efb4cb 100644
--- a/Documentation/networking/packet_mmap.txt
+++ b/Documentation/networking/packet_mmap.txt
@@ -453,7 +453,7 @@ TP_STATUS_COPY : This flag indicates that the frame (and associated
453 enabled previously with setsockopt() and 453 enabled previously with setsockopt() and
454 the PACKET_COPY_THRESH option. 454 the PACKET_COPY_THRESH option.
455 455
456 The number of frames than can be buffered to 456 The number of frames that can be buffered to
457 be read with recvfrom is limited like a normal socket. 457 be read with recvfrom is limited like a normal socket.
458 See the SO_RCVBUF option in the socket (7) man page. 458 See the SO_RCVBUF option in the socket (7) man page.
459 459
diff --git a/Documentation/networking/timestamping.txt b/Documentation/networking/timestamping.txt
index 661d3c316a17..048c92b487f6 100644
--- a/Documentation/networking/timestamping.txt
+++ b/Documentation/networking/timestamping.txt
@@ -21,26 +21,38 @@ has such a feature).
21 21
22SO_TIMESTAMPING: 22SO_TIMESTAMPING:
23 23
24Instructs the socket layer which kind of information is wanted. The 24Instructs the socket layer which kind of information should be collected
25parameter is an integer with some of the following bits set. Setting 25and/or reported. The parameter is an integer with some of the following
26other bits is an error and doesn't change the current state. 26bits set. Setting other bits is an error and doesn't change the current
27 27state.
28SOF_TIMESTAMPING_TX_HARDWARE: try to obtain send time stamp in hardware 28
29SOF_TIMESTAMPING_TX_SOFTWARE: if SOF_TIMESTAMPING_TX_HARDWARE is off or 29Four of the bits are requests to the stack to try to generate
30 fails, then do it in software 30timestamps. Any combination of them is valid.
31SOF_TIMESTAMPING_RX_HARDWARE: return the original, unmodified time stamp 31
32 as generated by the hardware 32SOF_TIMESTAMPING_TX_HARDWARE: try to obtain send time stamps in hardware
33SOF_TIMESTAMPING_RX_SOFTWARE: if SOF_TIMESTAMPING_RX_HARDWARE is off or 33SOF_TIMESTAMPING_TX_SOFTWARE: try to obtain send time stamps in software
34 fails, then do it in software 34SOF_TIMESTAMPING_RX_HARDWARE: try to obtain receive time stamps in hardware
35SOF_TIMESTAMPING_RAW_HARDWARE: return original raw hardware time stamp 35SOF_TIMESTAMPING_RX_SOFTWARE: try to obtain receive time stamps in software
36SOF_TIMESTAMPING_SYS_HARDWARE: return hardware time stamp transformed to 36
37 the system time base 37The other three bits control which timestamps will be reported in a
38SOF_TIMESTAMPING_SOFTWARE: return system time stamp generated in 38generated control message. If none of these bits are set or if none of
39 software 39the set bits correspond to data that is available, then the control
40 40message will not be generated:
41SOF_TIMESTAMPING_TX/RX determine how time stamps are generated. 41
42SOF_TIMESTAMPING_RAW/SYS determine how they are reported in the 42SOF_TIMESTAMPING_SOFTWARE: report systime if available
43following control message: 43SOF_TIMESTAMPING_SYS_HARDWARE: report hwtimetrans if available
44SOF_TIMESTAMPING_RAW_HARDWARE: report hwtimeraw if available
45
46It is worth noting that timestamps may be collected for reasons other
47than being requested by a particular socket with
48SOF_TIMESTAMPING_[TR]X_(HARD|SOFT)WARE. For example, most drivers that
49can generate hardware receive timestamps ignore
50SOF_TIMESTAMPING_RX_HARDWARE. It is still a good idea to set that flag
51in case future drivers pay attention.
52
53If timestamps are reported, they will appear in a control message with
54cmsg_level==SOL_SOCKET, cmsg_type==SO_TIMESTAMPING, and a payload like
55this:
44 56
45struct scm_timestamping { 57struct scm_timestamping {
46 struct timespec systime; 58 struct timespec systime;
diff --git a/Documentation/phy.txt b/Documentation/phy.txt
index 0103e4b15b0e..ebff6ee52441 100644
--- a/Documentation/phy.txt
+++ b/Documentation/phy.txt
@@ -75,14 +75,26 @@ Before the controller can make use of the PHY, it has to get a reference to
75it. This framework provides the following APIs to get a reference to the PHY. 75it. This framework provides the following APIs to get a reference to the PHY.
76 76
77struct phy *phy_get(struct device *dev, const char *string); 77struct phy *phy_get(struct device *dev, const char *string);
78struct phy *phy_optional_get(struct device *dev, const char *string);
78struct phy *devm_phy_get(struct device *dev, const char *string); 79struct phy *devm_phy_get(struct device *dev, const char *string);
79 80struct phy *devm_phy_optional_get(struct device *dev, const char *string);
80phy_get and devm_phy_get can be used to get the PHY. In the case of dt boot, 81
81the string arguments should contain the phy name as given in the dt data and 82phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can
82in the case of non-dt boot, it should contain the label of the PHY. 83be used to get the PHY. In the case of dt boot, the string arguments
83The only difference between the two APIs is that devm_phy_get associates the 84should contain the phy name as given in the dt data and in the case of
84device with the PHY using devres on successful PHY get. On driver detach, 85non-dt boot, it should contain the label of the PHY. The two
85release function is invoked on the the devres data and devres data is freed. 86devm_phy_get associates the device with the PHY using devres on
87successful PHY get. On driver detach, release function is invoked on
88the the devres data and devres data is freed. phy_optional_get and
89devm_phy_optional_get should be used when the phy is optional. These
90two functions will never return -ENODEV, but instead returns NULL when
91the phy cannot be found.
92
93It should be noted that NULL is a valid phy reference. All phy
94consumer calls on the NULL phy become NOPs. That is the release calls,
95the phy_init() and phy_exit() calls, and phy_power_on() and
96phy_power_off() calls are all NOP when applied to a NULL phy. The NULL
97phy is useful in devices for handling optional phy devices.
86 98
875. Releasing a reference to the PHY 995. Releasing a reference to the PHY
88 100
diff --git a/Documentation/power/00-INDEX b/Documentation/power/00-INDEX
index a4d682f54231..ad04cc8097ed 100644
--- a/Documentation/power/00-INDEX
+++ b/Documentation/power/00-INDEX
@@ -4,6 +4,8 @@ apm-acpi.txt
4 - basic info about the APM and ACPI support. 4 - basic info about the APM and ACPI support.
5basic-pm-debugging.txt 5basic-pm-debugging.txt
6 - Debugging suspend and resume 6 - Debugging suspend and resume
7charger-manager.txt
8 - Battery charger management.
7devices.txt 9devices.txt
8 - How drivers interact with system-wide power management 10 - How drivers interact with system-wide power management
9drivers-testing.txt 11drivers-testing.txt
@@ -22,6 +24,8 @@ pm_qos_interface.txt
22 - info on Linux PM Quality of Service interface 24 - info on Linux PM Quality of Service interface
23power_supply_class.txt 25power_supply_class.txt
24 - Tells userspace about battery, UPS, AC or DC power supply properties 26 - Tells userspace about battery, UPS, AC or DC power supply properties
27runtime_pm.txt
28 - Power management framework for I/O devices.
25s2ram.txt 29s2ram.txt
26 - How to get suspend to ram working (and debug it when it isn't) 30 - How to get suspend to ram working (and debug it when it isn't)
27states.txt 31states.txt
@@ -38,7 +42,5 @@ tricks.txt
38 - How to trick software suspend (to disk) into working when it isn't 42 - How to trick software suspend (to disk) into working when it isn't
39userland-swsusp.txt 43userland-swsusp.txt
40 - Experimental implementation of software suspend in userspace 44 - Experimental implementation of software suspend in userspace
41video_extension.txt
42 - ACPI video extensions
43video.txt 45video.txt
44 - Video issues during resume from suspend 46 - Video issues during resume from suspend
diff --git a/Documentation/ptp/testptp.c b/Documentation/ptp/testptp.c
index a74d0a84d329..4aba0436da65 100644
--- a/Documentation/ptp/testptp.c
+++ b/Documentation/ptp/testptp.c
@@ -117,6 +117,7 @@ static void usage(char *progname)
117 " -f val adjust the ptp clock frequency by 'val' ppb\n" 117 " -f val adjust the ptp clock frequency by 'val' ppb\n"
118 " -g get the ptp clock time\n" 118 " -g get the ptp clock time\n"
119 " -h prints this message\n" 119 " -h prints this message\n"
120 " -i val index for event/trigger\n"
120 " -k val measure the time offset between system and phc clock\n" 121 " -k val measure the time offset between system and phc clock\n"
121 " for 'val' times (Maximum 25)\n" 122 " for 'val' times (Maximum 25)\n"
122 " -p val enable output with a period of 'val' nanoseconds\n" 123 " -p val enable output with a period of 'val' nanoseconds\n"
@@ -154,6 +155,7 @@ int main(int argc, char *argv[])
154 int capabilities = 0; 155 int capabilities = 0;
155 int extts = 0; 156 int extts = 0;
156 int gettime = 0; 157 int gettime = 0;
158 int index = 0;
157 int oneshot = 0; 159 int oneshot = 0;
158 int pct_offset = 0; 160 int pct_offset = 0;
159 int n_samples = 0; 161 int n_samples = 0;
@@ -167,7 +169,7 @@ int main(int argc, char *argv[])
167 169
168 progname = strrchr(argv[0], '/'); 170 progname = strrchr(argv[0], '/');
169 progname = progname ? 1+progname : argv[0]; 171 progname = progname ? 1+progname : argv[0];
170 while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghk:p:P:sSt:v"))) { 172 while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghi:k:p:P:sSt:v"))) {
171 switch (c) { 173 switch (c) {
172 case 'a': 174 case 'a':
173 oneshot = atoi(optarg); 175 oneshot = atoi(optarg);
@@ -190,6 +192,9 @@ int main(int argc, char *argv[])
190 case 'g': 192 case 'g':
191 gettime = 1; 193 gettime = 1;
192 break; 194 break;
195 case 'i':
196 index = atoi(optarg);
197 break;
193 case 'k': 198 case 'k':
194 pct_offset = 1; 199 pct_offset = 1;
195 n_samples = atoi(optarg); 200 n_samples = atoi(optarg);
@@ -301,7 +306,7 @@ int main(int argc, char *argv[])
301 306
302 if (extts) { 307 if (extts) {
303 memset(&extts_request, 0, sizeof(extts_request)); 308 memset(&extts_request, 0, sizeof(extts_request));
304 extts_request.index = 0; 309 extts_request.index = index;
305 extts_request.flags = PTP_ENABLE_FEATURE; 310 extts_request.flags = PTP_ENABLE_FEATURE;
306 if (ioctl(fd, PTP_EXTTS_REQUEST, &extts_request)) { 311 if (ioctl(fd, PTP_EXTTS_REQUEST, &extts_request)) {
307 perror("PTP_EXTTS_REQUEST"); 312 perror("PTP_EXTTS_REQUEST");
@@ -375,7 +380,7 @@ int main(int argc, char *argv[])
375 return -1; 380 return -1;
376 } 381 }
377 memset(&perout_request, 0, sizeof(perout_request)); 382 memset(&perout_request, 0, sizeof(perout_request));
378 perout_request.index = 0; 383 perout_request.index = index;
379 perout_request.start.sec = ts.tv_sec + 2; 384 perout_request.start.sec = ts.tv_sec + 2;
380 perout_request.start.nsec = 0; 385 perout_request.start.nsec = 0;
381 perout_request.period.sec = 0; 386 perout_request.period.sec = 0;
diff --git a/Documentation/s390/00-INDEX b/Documentation/s390/00-INDEX
index 3a2b96302ecc..10c874ebdfe5 100644
--- a/Documentation/s390/00-INDEX
+++ b/Documentation/s390/00-INDEX
@@ -16,11 +16,13 @@ Debugging390.txt
16 - hints for debugging on s390 systems. 16 - hints for debugging on s390 systems.
17driver-model.txt 17driver-model.txt
18 - information on s390 devices and the driver model. 18 - information on s390 devices and the driver model.
19kvm.txt
20 - ioctl calls to /dev/kvm on s390.
19monreader.txt 21monreader.txt
20 - information on accessing the z/VM monitor stream from Linux. 22 - information on accessing the z/VM monitor stream from Linux.
23qeth.txt
24 - HiperSockets Bridge Port Support.
21s390dbf.txt 25s390dbf.txt
22 - information on using the s390 debug feature. 26 - information on using the s390 debug feature.
23TAPE 27zfcpdump.txt
24 - information on the driver for channel-attached tapes.
25zfcpdump
26 - information on the s390 SCSI dump tool. 28 - information on the s390 SCSI dump tool.
diff --git a/Documentation/scheduler/00-INDEX b/Documentation/scheduler/00-INDEX
index 46702e4f89c9..eccf7ad2e7f9 100644
--- a/Documentation/scheduler/00-INDEX
+++ b/Documentation/scheduler/00-INDEX
@@ -2,6 +2,8 @@
2 - this file. 2 - this file.
3sched-arch.txt 3sched-arch.txt
4 - CPU Scheduler implementation hints for architecture specific code. 4 - CPU Scheduler implementation hints for architecture specific code.
5sched-bwc.txt
6 - CFS bandwidth control overview.
5sched-design-CFS.txt 7sched-design-CFS.txt
6 - goals, design and implementation of the Completely Fair Scheduler. 8 - goals, design and implementation of the Completely Fair Scheduler.
7sched-domains.txt 9sched-domains.txt
diff --git a/Documentation/scsi/00-INDEX b/Documentation/scsi/00-INDEX
index 2044be565d93..c4b978a72f78 100644
--- a/Documentation/scsi/00-INDEX
+++ b/Documentation/scsi/00-INDEX
@@ -36,6 +36,8 @@ NinjaSCSI.txt
36 - info on WorkBiT NinjaSCSI-32/32Bi driver 36 - info on WorkBiT NinjaSCSI-32/32Bi driver
37aacraid.txt 37aacraid.txt
38 - Driver supporting Adaptec RAID controllers 38 - Driver supporting Adaptec RAID controllers
39advansys.txt
40 - List of Advansys Host Adapters
39aha152x.txt 41aha152x.txt
40 - info on driver for Adaptec AHA152x based adapters 42 - info on driver for Adaptec AHA152x based adapters
41aic79xx.txt 43aic79xx.txt
@@ -44,6 +46,12 @@ aic7xxx.txt
44 - info on driver for Adaptec controllers 46 - info on driver for Adaptec controllers
45arcmsr_spec.txt 47arcmsr_spec.txt
46 - ARECA FIRMWARE SPEC (for IOP331 adapter) 48 - ARECA FIRMWARE SPEC (for IOP331 adapter)
49bfa.txt
50 - Brocade FC/FCOE adapter driver.
51bnx2fc.txt
52 - FCoE hardware offload for Broadcom network interfaces.
53cxgb3i.txt
54 - Chelsio iSCSI Linux Driver
47dc395x.txt 55dc395x.txt
48 - README file for the dc395x SCSI driver 56 - README file for the dc395x SCSI driver
49dpti.txt 57dpti.txt
@@ -52,18 +60,24 @@ dtc3x80.txt
52 - info on driver for DTC 2x80 based adapters 60 - info on driver for DTC 2x80 based adapters
53g_NCR5380.txt 61g_NCR5380.txt
54 - info on driver for NCR5380 and NCR53c400 based adapters 62 - info on driver for NCR5380 and NCR53c400 based adapters
63hpsa.txt
64 - HP Smart Array Controller SCSI driver.
55hptiop.txt 65hptiop.txt
56 - HIGHPOINT ROCKETRAID 3xxx RAID DRIVER 66 - HIGHPOINT ROCKETRAID 3xxx RAID DRIVER
57in2000.txt 67in2000.txt
58 - info on in2000 driver 68 - info on in2000 driver
59libsas.txt 69libsas.txt
60 - Serial Attached SCSI management layer. 70 - Serial Attached SCSI management layer.
71link_power_management_policy.txt
72 - Link power management options.
61lpfc.txt 73lpfc.txt
62 - LPFC driver release notes 74 - LPFC driver release notes
63megaraid.txt 75megaraid.txt
64 - Common Management Module, shared code handling ioctls for LSI drivers 76 - Common Management Module, shared code handling ioctls for LSI drivers
65ncr53c8xx.txt 77ncr53c8xx.txt
66 - info on driver for NCR53c8xx based adapters 78 - info on driver for NCR53c8xx based adapters
79osd.txt
80 Object-Based Storage Device, command set introduction.
67osst.txt 81osst.txt
68 - info on driver for OnStream SC-x0 SCSI tape 82 - info on driver for OnStream SC-x0 SCSI tape
69ppa.txt 83ppa.txt
@@ -74,6 +88,8 @@ scsi-changer.txt
74 - README for the SCSI media changer driver 88 - README for the SCSI media changer driver
75scsi-generic.txt 89scsi-generic.txt
76 - info on the sg driver for generic (non-disk/CD/tape) SCSI devices. 90 - info on the sg driver for generic (non-disk/CD/tape) SCSI devices.
91scsi-parameters.txt
92 - List of SCSI-parameters to pass to the kernel at module load-time.
77scsi.txt 93scsi.txt
78 - short blurb on using SCSI support as a module. 94 - short blurb on using SCSI support as a module.
79scsi_mid_low_api.txt 95scsi_mid_low_api.txt
diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 1f1b22fbd739..f9c6b5ed03e7 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -4,10 +4,12 @@ README.cycladesZ
4 - info on Cyclades-Z firmware loading. 4 - info on Cyclades-Z firmware loading.
5digiepca.txt 5digiepca.txt
6 - info on Digi Intl. {PC,PCI,EISA}Xx and Xem series cards. 6 - info on Digi Intl. {PC,PCI,EISA}Xx and Xem series cards.
7hayes-esp.txt 7driver
8 - info on using the Hayes ESP serial driver. 8 - intro to the low level serial driver.
9moxa-smartio 9moxa-smartio
10 - file with info on installing/using Moxa multiport serial driver. 10 - file with info on installing/using Moxa multiport serial driver.
11n_gsm.txt
12 - GSM 0710 tty multiplexer howto.
11riscom8.txt 13riscom8.txt
12 - notes on using the RISCom/8 multi-port serial driver. 14 - notes on using the RISCom/8 multi-port serial driver.
13rocket.txt 15rocket.txt
diff --git a/Documentation/spi/00-INDEX b/Documentation/spi/00-INDEX
new file mode 100644
index 000000000000..a128fa835512
--- /dev/null
+++ b/Documentation/spi/00-INDEX
@@ -0,0 +1,22 @@
100-INDEX
2 - this file.
3Makefile
4 - Makefile for the example sourcefiles.
5butterfly
6 - AVR Butterfly SPI driver overview and pin configuration.
7ep93xx_spi
8 - Basic EP93xx SPI driver configuration.
9pxa2xx
10 - PXA2xx SPI master controller build by spi_message fifo wq
11spidev
12 - Intro to the userspace API for spi devices
13spidev_fdx.c
14 - spidev example file
15spi-lm70llp
16 - Connecting an LM70-LLP sensor to the kernel via the SPI subsys.
17spi-sc18is602
18 - NXP SC18IS602/603 I2C-bus to SPI bridge
19spi-summary
20 - (Linux) SPI overview. If unsure about SPI or SPI in Linux, start here.
21spidev_test.c
22 - SPI testing utility.
diff --git a/Documentation/spi/spi-summary b/Documentation/spi/spi-summary
index f72e0d1e0da8..7982bcc4d151 100644
--- a/Documentation/spi/spi-summary
+++ b/Documentation/spi/spi-summary
@@ -543,7 +543,22 @@ SPI MASTER METHODS
543 queuing transfers that arrive in the meantime. When the driver is 543 queuing transfers that arrive in the meantime. When the driver is
544 finished with this message, it must call 544 finished with this message, it must call
545 spi_finalize_current_message() so the subsystem can issue the next 545 spi_finalize_current_message() so the subsystem can issue the next
546 transfer. This may sleep. 546 message. This may sleep.
547
548 master->transfer_one(struct spi_master *master, struct spi_device *spi,
549 struct spi_transfer *transfer)
550 The subsystem calls the driver to transfer a single transfer while
551 queuing transfers that arrive in the meantime. When the driver is
552 finished with this transfer, it must call
553 spi_finalize_current_transfer() so the subsystem can issue the next
554 transfer. This may sleep. Note: transfer_one and transfer_one_message
555 are mutually exclusive; when both are set, the generic subsystem does
556 not call your transfer_one callback.
557
558 Return values:
559 negative errno: error
560 0: transfer is finished
561 1: transfer is still in progress
547 562
548 DEPRECATED METHODS 563 DEPRECATED METHODS
549 564
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index e55124e7c40c..ec8be46bf48d 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -320,10 +320,11 @@ This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
320 320
321============================================================== 321==============================================================
322 322
323hung_task_warning: 323hung_task_warnings:
324 324
325The maximum number of warnings to report. During a check interval 325The maximum number of warnings to report. During a check interval
326When this value is reached, no more the warnings will be reported. 326if a hung task is detected, this value is decreased by 1.
327When this value reaches 0, no more warnings will be reported.
327This file shows up if CONFIG_DETECT_HUNG_TASK is enabled. 328This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
328 329
329-1: report an infinite number of warnings. 330-1: report an infinite number of warnings.
@@ -441,8 +442,7 @@ feature should be disabled. Otherwise, if the system overhead from the
441feature is too high then the rate the kernel samples for NUMA hinting 442feature is too high then the rate the kernel samples for NUMA hinting
442faults may be controlled by the numa_balancing_scan_period_min_ms, 443faults may be controlled by the numa_balancing_scan_period_min_ms,
443numa_balancing_scan_delay_ms, numa_balancing_scan_period_max_ms, 444numa_balancing_scan_delay_ms, numa_balancing_scan_period_max_ms,
444numa_balancing_scan_size_mb, numa_balancing_settle_count sysctls and 445numa_balancing_scan_size_mb, and numa_balancing_settle_count sysctls.
445numa_balancing_migrate_deferred.
446 446
447============================================================== 447==============================================================
448 448
@@ -483,13 +483,6 @@ rate for each task.
483numa_balancing_scan_size_mb is how many megabytes worth of pages are 483numa_balancing_scan_size_mb is how many megabytes worth of pages are
484scanned for a given scan. 484scanned for a given scan.
485 485
486numa_balancing_migrate_deferred is how many page migrations get skipped
487unconditionally, after a page migration is skipped because a page is shared
488with other tasks. This reduces page migration overhead, and determines
489how much stronger the "move task near its memory" policy scheduler becomes,
490versus the "move memory near its task" memory management policy, for workloads
491with shared memory.
492
493============================================================== 486==============================================================
494 487
495osrelease, ostype & version: 488osrelease, ostype & version:
diff --git a/Documentation/timers/00-INDEX b/Documentation/timers/00-INDEX
index ef2ccbf77fa2..6d042dc1cce0 100644
--- a/Documentation/timers/00-INDEX
+++ b/Documentation/timers/00-INDEX
@@ -8,6 +8,8 @@ hpet_example.c
8 - sample hpet timer test program 8 - sample hpet timer test program
9hrtimers.txt 9hrtimers.txt
10 - subsystem for high-resolution kernel timers 10 - subsystem for high-resolution kernel timers
11Makefile
12 - Build and link hpet_example
11NO_HZ.txt 13NO_HZ.txt
12 - Summary of the different methods for the scheduler clock-interrupts management. 14 - Summary of the different methods for the scheduler clock-interrupts management.
13timers-howto.txt 15timers-howto.txt
diff --git a/Documentation/virtual/kvm/00-INDEX b/Documentation/virtual/kvm/00-INDEX
index 641ec9220179..fee9f2bf9c64 100644
--- a/Documentation/virtual/kvm/00-INDEX
+++ b/Documentation/virtual/kvm/00-INDEX
@@ -20,5 +20,7 @@ ppc-pv.txt
20 - the paravirtualization interface on PowerPC. 20 - the paravirtualization interface on PowerPC.
21review-checklist.txt 21review-checklist.txt
22 - review checklist for KVM patches. 22 - review checklist for KVM patches.
23s390-diag.txt
24 - Diagnose hypercall description (for IBM S/390)
23timekeeping.txt 25timekeeping.txt
24 - timekeeping virtualization for x86-based architectures. 26 - timekeeping virtualization for x86-based architectures.
diff --git a/Documentation/vm/00-INDEX b/Documentation/vm/00-INDEX
index a39d06680e1c..081c49777abb 100644
--- a/Documentation/vm/00-INDEX
+++ b/Documentation/vm/00-INDEX
@@ -16,8 +16,6 @@ hwpoison.txt
16 - explains what hwpoison is 16 - explains what hwpoison is
17ksm.txt 17ksm.txt
18 - how to use the Kernel Samepage Merging feature. 18 - how to use the Kernel Samepage Merging feature.
19locking
20 - info on how locking and synchronization is done in the Linux vm code.
21numa 19numa
22 - information about NUMA specific code in the Linux vm. 20 - information about NUMA specific code in the Linux vm.
23numa_memory_policy.txt 21numa_memory_policy.txt
@@ -32,6 +30,8 @@ slub.txt
32 - a short users guide for SLUB. 30 - a short users guide for SLUB.
33soft-dirty.txt 31soft-dirty.txt
34 - short explanation for soft-dirty PTEs 32 - short explanation for soft-dirty PTEs
33split_page_table_lock
34 - Separate per-table lock to improve scalability of the old page_table_lock.
35transhuge.txt 35transhuge.txt
36 - Transparent Hugepage Support, alternative way of using hugepages. 36 - Transparent Hugepage Support, alternative way of using hugepages.
37unevictable-lru.txt 37unevictable-lru.txt
diff --git a/Documentation/w1/masters/00-INDEX b/Documentation/w1/masters/00-INDEX
index d63fa024ac05..8330cf9325f0 100644
--- a/Documentation/w1/masters/00-INDEX
+++ b/Documentation/w1/masters/00-INDEX
@@ -4,7 +4,9 @@ ds2482
4 - The Maxim/Dallas Semiconductor DS2482 provides 1-wire busses. 4 - The Maxim/Dallas Semiconductor DS2482 provides 1-wire busses.
5ds2490 5ds2490
6 - The Maxim/Dallas Semiconductor DS2490 builds USB <-> W1 bridges. 6 - The Maxim/Dallas Semiconductor DS2490 builds USB <-> W1 bridges.
7mxc_w1 7mxc-w1
8 - W1 master controller driver found on Freescale MX2/MX3 SoCs 8 - W1 master controller driver found on Freescale MX2/MX3 SoCs
9omap-hdq
10 - HDQ/1-wire module of TI OMAP 2430/3430.
9w1-gpio 11w1-gpio
10 - GPIO 1-wire bus master driver. 12 - GPIO 1-wire bus master driver.
diff --git a/Documentation/w1/slaves/00-INDEX b/Documentation/w1/slaves/00-INDEX
index 75613c9ac4db..6e18c70c3474 100644
--- a/Documentation/w1/slaves/00-INDEX
+++ b/Documentation/w1/slaves/00-INDEX
@@ -4,3 +4,5 @@ w1_therm
4 - The Maxim/Dallas Semiconductor ds18*20 temperature sensor. 4 - The Maxim/Dallas Semiconductor ds18*20 temperature sensor.
5w1_ds2423 5w1_ds2423
6 - The Maxim/Dallas Semiconductor ds2423 counter device. 6 - The Maxim/Dallas Semiconductor ds2423 counter device.
7w1_ds28e04
8 - The Maxim/Dallas Semiconductor ds28e04 eeprom.
diff --git a/Documentation/x86/00-INDEX b/Documentation/x86/00-INDEX
index f37b46d34861..692264456f0f 100644
--- a/Documentation/x86/00-INDEX
+++ b/Documentation/x86/00-INDEX
@@ -1,6 +1,20 @@
100-INDEX 100-INDEX
2 - this file 2 - this file
3mtrr.txt 3boot.txt
4 - how to use x86 Memory Type Range Registers to increase performance 4 - List of boot protocol versions
5early-microcode.txt
6 - How to load microcode from an initrd-CPIO archive early to fix CPU issues.
7earlyprintk.txt
8 - Using earlyprintk with a USB2 debug port key.
9entry_64.txt
10 - Describe (some of the) kernel entry points for x86.
5exception-tables.txt 11exception-tables.txt
6 - why and how Linux kernel uses exception tables on x86 12 - why and how Linux kernel uses exception tables on x86
13mtrr.txt
14 - how to use x86 Memory Type Range Registers to increase performance
15pat.txt
16 - Page Attribute Table intro and API
17usb-legacy-support.txt
18 - how to fix/avoid quirks when using emulated PS/2 mouse/keyboard.
19zero-page.txt
20 - layout of the first page of memory.
diff --git a/Documentation/x86/boot.txt b/Documentation/x86/boot.txt
index cb81741d3b0b..a75e3adaa39d 100644
--- a/Documentation/x86/boot.txt
+++ b/Documentation/x86/boot.txt
@@ -182,7 +182,7 @@ Offset Proto Name Meaning
1820226/1 2.02+(3 ext_loader_ver Extended boot loader version 1820226/1 2.02+(3 ext_loader_ver Extended boot loader version
1830227/1 2.02+(3 ext_loader_type Extended boot loader ID 1830227/1 2.02+(3 ext_loader_type Extended boot loader ID
1840228/4 2.02+ cmd_line_ptr 32-bit pointer to the kernel command line 1840228/4 2.02+ cmd_line_ptr 32-bit pointer to the kernel command line
185022C/4 2.03+ ramdisk_max Highest legal initrd address 185022C/4 2.03+ initrd_addr_max Highest legal initrd address
1860230/4 2.05+ kernel_alignment Physical addr alignment required for kernel 1860230/4 2.05+ kernel_alignment Physical addr alignment required for kernel
1870234/1 2.05+ relocatable_kernel Whether kernel is relocatable or not 1870234/1 2.05+ relocatable_kernel Whether kernel is relocatable or not
1880235/1 2.10+ min_alignment Minimum alignment, as a power of two 1880235/1 2.10+ min_alignment Minimum alignment, as a power of two
@@ -534,7 +534,7 @@ Protocol: 2.02+
534 zero, the kernel will assume that your boot loader does not support 534 zero, the kernel will assume that your boot loader does not support
535 the 2.02+ protocol. 535 the 2.02+ protocol.
536 536
537Field name: ramdisk_max 537Field name: initrd_addr_max
538Type: read 538Type: read
539Offset/size: 0x22c/4 539Offset/size: 0x22c/4
540Protocol: 2.03+ 540Protocol: 2.03+
diff --git a/Documentation/zh_CN/arm64/booting.txt b/Documentation/zh_CN/arm64/booting.txt
index 28fa325b7461..6f6d956ac1c9 100644
--- a/Documentation/zh_CN/arm64/booting.txt
+++ b/Documentation/zh_CN/arm64/booting.txt
@@ -7,7 +7,7 @@ help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation. 7or if there is a problem with the translation.
8 8
9Maintainer: Will Deacon <will.deacon@arm.com> 9Maintainer: Will Deacon <will.deacon@arm.com>
10Chinese maintainer: Fu Wei <tekkamanninja@gmail.com> 10Chinese maintainer: Fu Wei <wefu@redhat.com>
11--------------------------------------------------------------------- 11---------------------------------------------------------------------
12Documentation/arm64/booting.txt 的中文翻译 12Documentation/arm64/booting.txt 的中文翻译
13 13
@@ -16,9 +16,9 @@ Documentation/arm64/booting.txt 的中文翻译
16译存在问题,请è”系中文版维护者。 16译存在问题,请è”系中文版维护者。
17 17
18英文版维护者: Will Deacon <will.deacon@arm.com> 18英文版维护者: Will Deacon <will.deacon@arm.com>
19中文版维护者: 傅炜 Fu Wei <tekkamanninja@gmail.com> 19中文版维护者: 傅炜 Fu Wei <wefu@redhat.com>
20中文版翻译者: 傅炜 Fu Wei <tekkamanninja@gmail.com> 20中文版翻译者: 傅炜 Fu Wei <wefu@redhat.com>
21中文版校译者: 傅炜 Fu Wei <tekkamanninja@gmail.com> 21中文版校译者: 傅炜 Fu Wei <wefu@redhat.com>
22 22
23以下为正文 23以下为正文
24--------------------------------------------------------------------- 24---------------------------------------------------------------------
@@ -64,8 +64,8 @@ RAM,或å¯èƒ½ä½¿ç”¨å¯¹è¿™ä¸ªè®¾å¤‡å·²çŸ¥çš„ RAM ä¿¡æ¯ï¼Œè¿˜å¯èƒ½ä½¿ç”¨ä»»ä½•
64 64
65å¿…è¦æ€§: 强制 65å¿…è¦æ€§: 强制
66 66
67设备树数æ®å—(dtb)大å°å¿…é¡»ä¸å¤§äºŽ 2 MB,且ä½äºŽä»Žå†…核映åƒèµ·å§‹ç®—起第一个 67设备树数æ®å—(dtb)必须 8 字节对é½ï¼Œå¹¶ä½äºŽä»Žå†…核映åƒèµ·å§‹ç®—起第一个 512MB
68512MB 内的 2MB 边界上。这使得内核å¯ä»¥é€šè¿‡åˆå§‹é¡µè¡¨ä¸­çš„å•ä¸ªèŠ‚æè¿°ç¬¦æ¥ 68内,且ä¸å¾—跨越 2MB 对é½è¾¹ç•Œã€‚这使得内核å¯ä»¥é€šè¿‡åˆå§‹é¡µè¡¨ä¸­çš„å•ä¸ªèŠ‚æ述符æ¥
69映射此数æ®å—。 69映射此数æ®å—。
70 70
71 71
@@ -84,13 +84,23 @@ AArch64 内核当å‰æ²¡æœ‰æ供自解压代ç ï¼Œå› æ­¤å¦‚果使用了压缩内
84 84
85å¿…è¦æ€§: 强制 85å¿…è¦æ€§: 强制
86 86
87已解压的内核映åƒåŒ…å«ä¸€ä¸ª 32 字节的头,内容如下: 87已解压的内核映åƒåŒ…å«ä¸€ä¸ª 64 字节的头,内容如下:
88 88
89 u32 magic = 0x14000008; /* 跳转到 stext, å°ç«¯ */ 89 u32 code0; /* å¯æ‰§è¡Œä»£ç  */
90 u32 res0 = 0; /* ä¿ç•™ */ 90 u32 code1; /* å¯æ‰§è¡Œä»£ç  */
91 u64 text_offset; /* 映åƒè£…è½½å移 */ 91 u64 text_offset; /* 映åƒè£…è½½å移 */
92 u64 res0 = 0; /* ä¿ç•™ */
92 u64 res1 = 0; /* ä¿ç•™ */ 93 u64 res1 = 0; /* ä¿ç•™ */
93 u64 res2 = 0; /* ä¿ç•™ */ 94 u64 res2 = 0; /* ä¿ç•™ */
95 u64 res3 = 0; /* ä¿ç•™ */
96 u64 res4 = 0; /* ä¿ç•™ */
97 u32 magic = 0x644d5241; /* 魔数, å°ç«¯, "ARM\x64" */
98 u32 res5 = 0; /* ä¿ç•™ */
99
100
101映åƒå¤´æ³¨é‡Šï¼š
102
103- code0/code1 负责跳转到 stext.
94 104
95映åƒå¿…é¡»ä½äºŽç³»ç»Ÿ RAM 起始处的特定å移(当å‰æ˜¯ 0x80000)。系统 RAM 105映åƒå¿…é¡»ä½äºŽç³»ç»Ÿ RAM 起始处的特定å移(当å‰æ˜¯ 0x80000)。系统 RAM
96的起始地å€å¿…须是以 2MB 对é½çš„。 106的起始地å€å¿…须是以 2MB 对é½çš„。
@@ -118,9 +128,9 @@ AArch64 内核当å‰æ²¡æœ‰æ供自解压代ç ï¼Œå› æ­¤å¦‚果使用了压缩内
118 外部高速缓存(如果存在)必须é…置并ç¦ç”¨ã€‚ 128 外部高速缓存(如果存在)必须é…置并ç¦ç”¨ã€‚
119 129
120- 架构计时器 130- 架构计时器
121 CNTFRQ 必须设定为计时器的频率ã 131 CNTFRQ 必须设定为计时器的频率,且 CNTVOFF 必须设定为对æ‰æœ‰ CPU
122 如果在 EL1 模å¼ä¸‹è¿›å…¥å†…核,则 CNTHCTL_EL2 中的 EL1PCTEN (bit 0) 132 都一致的值。如果在 EL1 模å¼ä¸‹è¿›å…¥å†…核,则 CNTHCTL_EL2 中的
123 必须置ä½ã€‚ 133 EL1PCTEN (bit 0) 必须置ä½ã€‚
124 134
125- 一致性 135- 一致性
126 通过内核å¯åŠ¨çš„所有 CPU 在内核入å£åœ°å€ä¸Šå¿…须处于相åŒçš„一致性域中。 136 通过内核å¯åŠ¨çš„所有 CPU 在内核入å£åœ°å€ä¸Šå¿…须处于相åŒçš„一致性域中。
@@ -131,23 +141,40 @@ AArch64 内核当å‰æ²¡æœ‰æ供自解压代ç ï¼Œå› æ­¤å¦‚果使用了压缩内
131 在进入内核映åƒçš„异常级中,所有构架中å¯å†™çš„系统寄存器必须通过软件 141 在进入内核映åƒçš„异常级中,所有构架中å¯å†™çš„系统寄存器必须通过软件
132 在一个更高的异常级别下åˆå§‹åŒ–,以防止在 未知 状æ€ä¸‹è¿è¡Œã€‚ 142 在一个更高的异常级别下åˆå§‹åŒ–,以防止在 未知 状æ€ä¸‹è¿è¡Œã€‚
133 143
144以上对于 CPU 模å¼ã€é«˜é€Ÿç¼“å­˜ã€MMUã€æž¶æž„计时器ã€ä¸€è‡´æ€§ã€ç³»ç»Ÿå¯„存器的
145å¿…è¦æ¡ä»¶æ述适用于所有 CPU。所有 CPU 必须在åŒä¸€å¼‚常级别跳入内核。
146
134引导装载程åºå¿…须在æ¯ä¸ª CPU 处于以下状æ€æ—¶è·³å…¥å†…核入å£ï¼š 147引导装载程åºå¿…须在æ¯ä¸ª CPU 处于以下状æ€æ—¶è·³å…¥å†…核入å£ï¼š
135 148
136- 主 CPU 必须直接跳入内核映åƒçš„第一æ¡æŒ‡ä»¤ã€‚通过此 CPU 传递的设备树 149- 主 CPU 必须直接跳入内核映åƒçš„第一æ¡æŒ‡ä»¤ã€‚通过此 CPU 传递的设备树
137 æ•°æ®å—必须在æ¯ä¸ª CPU 节点中包å«ä»¥ä¸‹å†…容: 150 æ•°æ®å—必须在æ¯ä¸ª CPU 节点中包å«ä¸€ä¸ª ‘enable-method’ 属性,所
138 151 支æŒçš„ enable-method 请è§ä¸‹æ–‡ã€‚
139 1ã€â€˜enable-method’属性。目å‰ï¼Œæ­¤å­—段支æŒçš„值仅为字符串“spin-tableâ€ã€‚
140
141 2ã€â€˜cpu-release-addr’标识一个 64-bitã€åˆå§‹åŒ–为零的内存ä½ç½®ã€‚
142 152
143 引导装载程åºå¿…须生æˆè¿™äº›è®¾å¤‡æ ‘属性,并在跳入内核入å£ä¹‹å‰å°†å…¶æ’å…¥ 153 引导装载程åºå¿…须生æˆè¿™äº›è®¾å¤‡æ ‘属性,并在跳入内核入å£ä¹‹å‰å°†å…¶æ’å…¥
144 æ•°æ®å—。 154 æ•°æ®å—。
145 155
146- 任何辅助 CPU 必须在内存ä¿ç•™åŒºï¼ˆé€šè¿‡è®¾å¤‡æ ‘中的 /memreserve/ 域传递 156- enable-method 为 “spin-table†的 CPU 必须在它们的 CPU
157 节点中包å«ä¸€ä¸ª ‘cpu-release-addr’ 属性。这个属性标识了一个
158 64 ä½è‡ªç„¶å¯¹é½ä¸”åˆå§‹åŒ–为零的内存ä½ç½®ã€‚
159
160 这些 CPU 必须在内存ä¿ç•™åŒºï¼ˆé€šè¿‡è®¾å¤‡æ ‘中的 /memreserve/ 域传递
147 给内核)中自旋于内核之外,轮询它们的 cpu-release-addr ä½ç½®ï¼ˆå¿…é¡» 161 给内核)中自旋于内核之外,轮询它们的 cpu-release-addr ä½ç½®ï¼ˆå¿…é¡»
148 包å«åœ¨ä¿ç•™åŒºä¸­ï¼‰ã€‚å¯é€šè¿‡æ’å…¥ wfe 指令æ¥é™ä½Žå¿™å¾ªçŽ¯å¼€é”€ï¼Œè€Œä¸» CPU å°† 162 包å«åœ¨ä¿ç•™åŒºä¸­ï¼‰ã€‚å¯é€šè¿‡æ’å…¥ wfe 指令æ¥é™ä½Žå¿™å¾ªçŽ¯å¼€é”€ï¼Œè€Œä¸» CPU å°†
149 å‘出 sev 指令。当对 cpu-release-addr 所指ä½ç½®çš„读å–æ“作返回éžé›¶å€¼ 163 å‘出 sev 指令。当对 cpu-release-addr 所指ä½ç½®çš„读å–æ“作返回éžé›¶å€¼
150 时,CPU 必须直接跳入此值所指å‘的地å€ã€‚ 164 时,CPU 必须跳入此值所指å‘的地å€ã€‚此值为一个å•ç‹¬çš„ 64 ä½å°ç«¯å€¼ï¼Œ
165 å› æ­¤ CPU 须在跳转å‰å°†æ‰€è¯»å–的值转æ¢ä¸ºå…¶æœ¬èº«çš„端模å¼ã€‚
166
167- enable-method 为 “psci†的 CPU ä¿æŒåœ¨å†…核外(比如,在
168 memory 节点中æ述为内核空间的内存区外,或在通过设备树 /memreserve/
169 域中æ述为内核ä¿ç•™åŒºçš„空间中)。内核将会å‘起在 ARM 文档(编å·
170 ARM DEN 0022A:用于 ARM 上的电æºçŠ¶æ€å调接å£ç³»ç»Ÿè½¯ä»¶ï¼‰ä¸­æè¿°çš„
171 CPU_ON 调用æ¥å°† CPU 带入内核。
172
173 *译者注:到文档翻译时,此文档已更新为 ARM DEN 0022B。
174
175 设备树必须包å«ä¸€ä¸ª ‘psci’ 节点,请å‚考以下文档:
176 Documentation/devicetree/bindings/arm/psci.txt
177
151 178
152- 辅助 CPU 通用寄存器设置 179- 辅助 CPU 通用寄存器设置
153 x0 = 0 (ä¿ç•™ï¼Œå°†æ¥å¯èƒ½ä½¿ç”¨) 180 x0 = 0 (ä¿ç•™ï¼Œå°†æ¥å¯èƒ½ä½¿ç”¨)
diff --git a/Documentation/zh_CN/arm64/memory.txt b/Documentation/zh_CN/arm64/memory.txt
index a5f6283829f9..a782704c1cb5 100644
--- a/Documentation/zh_CN/arm64/memory.txt
+++ b/Documentation/zh_CN/arm64/memory.txt
@@ -7,7 +7,7 @@ help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation. 7or if there is a problem with the translation.
8 8
9Maintainer: Catalin Marinas <catalin.marinas@arm.com> 9Maintainer: Catalin Marinas <catalin.marinas@arm.com>
10Chinese maintainer: Fu Wei <tekkamanninja@gmail.com> 10Chinese maintainer: Fu Wei <wefu@redhat.com>
11--------------------------------------------------------------------- 11---------------------------------------------------------------------
12Documentation/arm64/memory.txt 的中文翻译 12Documentation/arm64/memory.txt 的中文翻译
13 13
@@ -16,9 +16,9 @@ Documentation/arm64/memory.txt 的中文翻译
16译存在问题,请è”系中文版维护者。 16译存在问题,请è”系中文版维护者。
17 17
18英文版维护者: Catalin Marinas <catalin.marinas@arm.com> 18英文版维护者: Catalin Marinas <catalin.marinas@arm.com>
19中文版维护者: 傅炜 Fu Wei <tekkamanninja@gmail.com> 19中文版维护者: 傅炜 Fu Wei <wefu@redhat.com>
20中文版翻译者: 傅炜 Fu Wei <tekkamanninja@gmail.com> 20中文版翻译者: 傅炜 Fu Wei <wefu@redhat.com>
21中文版校译者: 傅炜 Fu Wei <tekkamanninja@gmail.com> 21中文版校译者: 傅炜 Fu Wei <wefu@redhat.com>
22 22
23以下为正文 23以下为正文
24--------------------------------------------------------------------- 24---------------------------------------------------------------------
@@ -41,7 +41,7 @@ AArch64 Linux 使用页大å°ä¸º 4KB çš„ 3 级转æ¢è¡¨é…置,对于用户和å
41TTBR1 中,且从ä¸å†™å…¥ TTBR0。 41TTBR1 中,且从ä¸å†™å…¥ TTBR0。
42 42
43 43
44AArch64 Linux 内存布局: 44AArch64 Linux 在页大å°ä¸º 4KB 时的内存布局:
45 45
46èµ·å§‹åœ°å€ ç»“æŸåœ°å€ å¤§å° ç”¨é€” 46èµ·å§‹åœ°å€ ç»“æŸåœ°å€ å¤§å° ç”¨é€”
47----------------------------------------------------------------------- 47-----------------------------------------------------------------------
@@ -55,15 +55,42 @@ ffffffbc00000000 ffffffbdffffffff 8GB vmemmap
55 55
56ffffffbe00000000 ffffffbffbbfffff ~8GB [防护页,未æ¥ç”¨äºŽ vmmemap] 56ffffffbe00000000 ffffffbffbbfffff ~8GB [防护页,未æ¥ç”¨äºŽ vmmemap]
57 57
58ffffffbffbc00000 ffffffbffbdfffff 2MB earlyprintk 设备
59
58ffffffbffbe00000 ffffffbffbe0ffff 64KB PCI I/O 空间 60ffffffbffbe00000 ffffffbffbe0ffff 64KB PCI I/O 空间
59 61
60ffffffbbffff0000 ffffffbcffffffff ~2MB [防护页] 62ffffffbffbe10000 ffffffbcffffffff ~2MB [防护页]
61 63
62ffffffbffc000000 ffffffbfffffffff 64MB æ¨¡å— 64ffffffbffc000000 ffffffbfffffffff 64MB 模å—
63 65
64ffffffc000000000 ffffffffffffffff 256GB 内核逻辑内存映射 66ffffffc000000000 ffffffffffffffff 256GB 内核逻辑内存映射
65 67
66 68
69AArch64 Linux 在页大å°ä¸º 64KB 时的内存布局:
70
71èµ·å§‹åœ°å€ ç»“æŸåœ°å€ å¤§å° ç”¨é€”
72-----------------------------------------------------------------------
730000000000000000 000003ffffffffff 4TB 用户空间
74
75fffffc0000000000 fffffdfbfffeffff ~2TB vmalloc
76
77fffffdfbffff0000 fffffdfbffffffff 64KB [防护页]
78
79fffffdfc00000000 fffffdfdffffffff 8GB vmemmap
80
81fffffdfe00000000 fffffdfffbbfffff ~8GB [防护页,未æ¥ç”¨äºŽ vmmemap]
82
83fffffdfffbc00000 fffffdfffbdfffff 2MB earlyprintk 设备
84
85fffffdfffbe00000 fffffdfffbe0ffff 64KB PCI I/O 空间
86
87fffffdfffbe10000 fffffdfffbffffff ~2MB [防护页]
88
89fffffdfffc000000 fffffdffffffffff 64MB 模å—
90
91fffffe0000000000 ffffffffffffffff 2TB 内核逻辑内存映射
92
93
674KB 页大å°çš„转æ¢è¡¨æŸ¥æ‰¾ï¼š 944KB 页大å°çš„转æ¢è¡¨æŸ¥æ‰¾ï¼š
68 95
69+--------+--------+--------+--------+--------+--------+--------+--------+ 96+--------+--------+--------+--------+--------+--------+--------+--------+
@@ -91,3 +118,10 @@ ffffffc000000000 ffffffffffffffff 256GB 内核逻辑内存映射
91 | | +--------------------------> [41:29] L2 索引 (仅使用 38:29 ) 118 | | +--------------------------> [41:29] L2 索引 (仅使用 38:29 )
92 | +-------------------------------> [47:42] L1 索引 (未使用) 119 | +-------------------------------> [47:42] L1 索引 (未使用)
93 +-------------------------------------------------> [63] TTBR0/1 120 +-------------------------------------------------> [63] TTBR0/1
121
122当使用 KVM æ—¶, 管ç†ç¨‹åºï¼ˆhypervisor)在 EL2 中通过相对内核虚拟地å€çš„
123一个固定å移æ¥æ˜ å°„内核页(内核虚拟地å€çš„高 24 ä½è®¾ä¸ºé›¶ï¼‰:
124
125èµ·å§‹åœ°å€ ç»“æŸåœ°å€ å¤§å° ç”¨é€”
126-----------------------------------------------------------------------
1270000004000000000 0000007fffffffff 256GB 在 HYP 中映射的内核对象
diff --git a/Documentation/zh_CN/arm64/tagged-pointers.txt b/Documentation/zh_CN/arm64/tagged-pointers.txt
new file mode 100644
index 000000000000..2664d1bd5a1c
--- /dev/null
+++ b/Documentation/zh_CN/arm64/tagged-pointers.txt
@@ -0,0 +1,52 @@
1Chinese translated version of Documentation/arm64/tagged-pointers.txt
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Maintainer: Will Deacon <will.deacon@arm.com>
10Chinese maintainer: Fu Wei <wefu@redhat.com>
11---------------------------------------------------------------------
12Documentation/arm64/tagged-pointers.txt 的中文翻译
13
14如果想评论或更新本文的内容,请直接è”系原文档的维护者。如果你使用英文
15交æµæœ‰å›°éš¾çš„è¯ï¼Œä¹Ÿå¯ä»¥å‘中文版维护者求助。如果本翻译更新ä¸åŠæ—¶æˆ–者翻
16译存在问题,请è”系中文版维护者。
17
18英文版维护者: Will Deacon <will.deacon@arm.com>
19中文版维护者: 傅炜 Fu Wei <wefu@redhat.com>
20中文版翻译者: 傅炜 Fu Wei <wefu@redhat.com>
21中文版校译者: 傅炜 Fu Wei <wefu@redhat.com>
22
23以下为正文
24---------------------------------------------------------------------
25 Linux 在 AArch64 中带标记的虚拟地å€
26 =================================
27
28作者: Will Deacon <will.deacon@arm.com>
29日期: 2013 年 06 月 12 日
30
31本文档简述了在 AArch64 地å€è½¬æ¢ç³»ç»Ÿä¸­æ供的带标记的虚拟地å€åŠå…¶åœ¨
32AArch64 Linux 中的潜在用途。
33
34内核æ供的地å€è½¬æ¢è¡¨é…置使通过 TTBR0 完æˆçš„虚拟地å€è½¬æ¢ï¼ˆå³ç”¨æˆ·ç©ºé—´
35映射),其虚拟地å€çš„最高 8 ä½ï¼ˆ63:56)会被转æ¢ç¡¬ä»¶æ‰€å¿½ç•¥ã€‚è¿™ç§æœºåˆ¶
36让这些ä½å¯ä¾›åº”用程åºè‡ªç”±ä½¿ç”¨ï¼Œå…¶æ³¨æ„事项如下:
37
38 (1) 内核è¦æ±‚所有传递到 EL1 的用户空间地å€å¸¦æœ‰ 0x00 标记。
39 è¿™æ„味ç€ä»»ä½•æºå¸¦ç”¨æˆ·ç©ºé—´è™šæ‹Ÿåœ°å€çš„系统调用(syscall)
40 å‚æ•° *å¿…é¡»* 在陷入内核å‰ä½¿å®ƒä»¬çš„最高字节被清零。
41
42 (2) éžé›¶æ ‡è®°åœ¨ä¼ é€’ä¿¡å·æ—¶ä¸è¢«ä¿å­˜ã€‚è¿™æ„味ç€åœ¨åº”用程åºä¸­åˆ©ç”¨äº†
43 标记的信å·å¤„ç†å‡½æ•°æ— æ³•ä¾èµ– siginfo_t 的用户空间虚拟
44 地å€æ‰€æºå¸¦çš„包å«å…¶å†…部域信æ¯çš„标记。此规则的一个例外是
45 当信å·æ˜¯åœ¨è°ƒè¯•è§‚察点的异常处ç†ç¨‹åºä¸­äº§ç”Ÿçš„,此时标记的
46 ä¿¡æ¯å°†è¢«ä¿å­˜ã€‚
47
48 (3) 当使用带标记的指针时需特别留心,因为仅对两个虚拟地å€
49 的高字节,C 编译器很å¯èƒ½æ— æ³•åˆ¤æ–­å®ƒä»¬æ˜¯ä¸åŒçš„。
50
51此构架会阻止对带标记的 PC 指针的利用,因此在异常返回时,其高字节
52将被设置æˆä¸€ä¸ªä¸º “55†的扩展符。
diff --git a/MAINTAINERS b/MAINTAINERS
index b2cf5cfb4d29..79031a56711b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -73,7 +73,8 @@ Descriptions of section entries:
73 L: Mailing list that is relevant to this area 73 L: Mailing list that is relevant to this area
74 W: Web-page with status/info 74 W: Web-page with status/info
75 Q: Patchwork web based patch tracking system site 75 Q: Patchwork web based patch tracking system site
76 T: SCM tree type and location. Type is one of: git, hg, quilt, stgit, topgit. 76 T: SCM tree type and location.
77 Type is one of: git, hg, quilt, stgit, topgit
77 S: Status, one of the following: 78 S: Status, one of the following:
78 Supported: Someone is actually paid to look after this. 79 Supported: Someone is actually paid to look after this.
79 Maintained: Someone actually looks after it. 80 Maintained: Someone actually looks after it.
@@ -473,7 +474,7 @@ F: net/rxrpc/af_rxrpc.c
473 474
474AGPGART DRIVER 475AGPGART DRIVER
475M: David Airlie <airlied@linux.ie> 476M: David Airlie <airlied@linux.ie>
476T: git git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git 477T: git git://people.freedesktop.org/~airlied/linux (part of drm maint)
477S: Maintained 478S: Maintained
478F: drivers/char/agp/ 479F: drivers/char/agp/
479F: include/linux/agp* 480F: include/linux/agp*
@@ -538,7 +539,7 @@ F: arch/alpha/
538ALTERA UART/JTAG UART SERIAL DRIVERS 539ALTERA UART/JTAG UART SERIAL DRIVERS
539M: Tobias Klauser <tklauser@distanz.ch> 540M: Tobias Klauser <tklauser@distanz.ch>
540L: linux-serial@vger.kernel.org 541L: linux-serial@vger.kernel.org
541L: nios2-dev@sopc.et.ntust.edu.tw (moderated for non-subscribers) 542L: nios2-dev@lists.rocketboards.org (moderated for non-subscribers)
542S: Maintained 543S: Maintained
543F: drivers/tty/serial/altera_uart.c 544F: drivers/tty/serial/altera_uart.c
544F: drivers/tty/serial/altera_jtaguart.c 545F: drivers/tty/serial/altera_jtaguart.c
@@ -910,11 +911,11 @@ F: arch/arm/include/asm/hardware/dec21285.h
910F: arch/arm/mach-footbridge/ 911F: arch/arm/mach-footbridge/
911 912
912ARM/FREESCALE IMX / MXC ARM ARCHITECTURE 913ARM/FREESCALE IMX / MXC ARM ARCHITECTURE
913M: Shawn Guo <shawn.guo@linaro.org> 914M: Shawn Guo <shawn.guo@freescale.com>
914M: Sascha Hauer <kernel@pengutronix.de> 915M: Sascha Hauer <kernel@pengutronix.de>
915L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 916L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
916S: Maintained 917S: Maintained
917T: git git://git.linaro.org/people/shawnguo/linux-2.6.git 918T: git git://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux.git
918F: arch/arm/mach-imx/ 919F: arch/arm/mach-imx/
919F: arch/arm/boot/dts/imx* 920F: arch/arm/boot/dts/imx*
920F: arch/arm/configs/imx*_defconfig 921F: arch/arm/configs/imx*_defconfig
@@ -1612,11 +1613,11 @@ S: Maintained
1612F: drivers/net/wireless/atmel* 1613F: drivers/net/wireless/atmel*
1613 1614
1614ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER 1615ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
1615M: Bradley Grove <linuxdrivers@attotech.com> 1616M: Bradley Grove <linuxdrivers@attotech.com>
1616L: linux-scsi@vger.kernel.org 1617L: linux-scsi@vger.kernel.org
1617W: http://www.attotech.com 1618W: http://www.attotech.com
1618S: Supported 1619S: Supported
1619F: drivers/scsi/esas2r 1620F: drivers/scsi/esas2r
1620 1621
1621AUDIT SUBSYSTEM 1622AUDIT SUBSYSTEM
1622M: Eric Paris <eparis@redhat.com> 1623M: Eric Paris <eparis@redhat.com>
@@ -1737,6 +1738,7 @@ F: include/uapi/linux/bfs_fs.h
1737BLACKFIN ARCHITECTURE 1738BLACKFIN ARCHITECTURE
1738M: Steven Miao <realmz6@gmail.com> 1739M: Steven Miao <realmz6@gmail.com>
1739L: adi-buildroot-devel@lists.sourceforge.net 1740L: adi-buildroot-devel@lists.sourceforge.net
1741T: git git://git.code.sf.net/p/adi-linux/code
1740W: http://blackfin.uclinux.org 1742W: http://blackfin.uclinux.org
1741S: Supported 1743S: Supported
1742F: arch/blackfin/ 1744F: arch/blackfin/
@@ -1830,8 +1832,8 @@ F: net/bluetooth/
1830F: include/net/bluetooth/ 1832F: include/net/bluetooth/
1831 1833
1832BONDING DRIVER 1834BONDING DRIVER
1833M: Jay Vosburgh <fubar@us.ibm.com> 1835M: Jay Vosburgh <j.vosburgh@gmail.com>
1834M: Veaceslav Falico <vfalico@redhat.com> 1836M: Veaceslav Falico <vfalico@gmail.com>
1835M: Andy Gospodarek <andy@greyhouse.net> 1837M: Andy Gospodarek <andy@greyhouse.net>
1836L: netdev@vger.kernel.org 1838L: netdev@vger.kernel.org
1837W: http://sourceforge.net/projects/bonding/ 1839W: http://sourceforge.net/projects/bonding/
@@ -1860,6 +1862,7 @@ F: drivers/net/ethernet/broadcom/bnx2x/
1860 1862
1861BROADCOM BCM281XX/BCM11XXX ARM ARCHITECTURE 1863BROADCOM BCM281XX/BCM11XXX ARM ARCHITECTURE
1862M: Christian Daudt <bcm@fixthebug.org> 1864M: Christian Daudt <bcm@fixthebug.org>
1865M: Matt Porter <mporter@linaro.org>
1863L: bcm-kernel-feedback-list@broadcom.com 1866L: bcm-kernel-feedback-list@broadcom.com
1864T: git git://git.github.com/broadcom/bcm11351 1867T: git git://git.github.com/broadcom/bcm11351
1865S: Maintained 1868S: Maintained
@@ -2158,7 +2161,7 @@ F: Documentation/zh_CN/
2158 2161
2159CHIPIDEA USB HIGH SPEED DUAL ROLE CONTROLLER 2162CHIPIDEA USB HIGH SPEED DUAL ROLE CONTROLLER
2160M: Peter Chen <Peter.Chen@freescale.com> 2163M: Peter Chen <Peter.Chen@freescale.com>
2161T: git://github.com/hzpeterchen/linux-usb.git 2164T: git git://github.com/hzpeterchen/linux-usb.git
2162L: linux-usb@vger.kernel.org 2165L: linux-usb@vger.kernel.org
2163S: Maintained 2166S: Maintained
2164F: drivers/usb/chipidea/ 2167F: drivers/usb/chipidea/
@@ -2178,9 +2181,9 @@ S: Supported
2178F: drivers/net/ethernet/cisco/enic/ 2181F: drivers/net/ethernet/cisco/enic/
2179 2182
2180CISCO VIC LOW LATENCY NIC DRIVER 2183CISCO VIC LOW LATENCY NIC DRIVER
2181M: Upinder Malhi <umalhi@cisco.com> 2184M: Upinder Malhi <umalhi@cisco.com>
2182S: Supported 2185S: Supported
2183F: drivers/infiniband/hw/usnic 2186F: drivers/infiniband/hw/usnic
2184 2187
2185CIRRUS LOGIC EP93XX ETHERNET DRIVER 2188CIRRUS LOGIC EP93XX ETHERNET DRIVER
2186M: Hartley Sweeten <hsweeten@visionengravers.com> 2189M: Hartley Sweeten <hsweeten@visionengravers.com>
@@ -2367,7 +2370,7 @@ F: include/linux/cpufreq.h
2367 2370
2368CPU FREQUENCY DRIVERS - ARM BIG LITTLE 2371CPU FREQUENCY DRIVERS - ARM BIG LITTLE
2369M: Viresh Kumar <viresh.kumar@linaro.org> 2372M: Viresh Kumar <viresh.kumar@linaro.org>
2370M: Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com> 2373M: Sudeep Holla <sudeep.holla@arm.com>
2371L: cpufreq@vger.kernel.org 2374L: cpufreq@vger.kernel.org
2372L: linux-pm@vger.kernel.org 2375L: linux-pm@vger.kernel.org
2373W: http://www.arm.com/products/processors/technologies/biglittleprocessing.php 2376W: http://www.arm.com/products/processors/technologies/biglittleprocessing.php
@@ -2377,20 +2380,20 @@ F: drivers/cpufreq/arm_big_little.c
2377F: drivers/cpufreq/arm_big_little_dt.c 2380F: drivers/cpufreq/arm_big_little_dt.c
2378 2381
2379CPUIDLE DRIVER - ARM BIG LITTLE 2382CPUIDLE DRIVER - ARM BIG LITTLE
2380M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> 2383M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2381M: Daniel Lezcano <daniel.lezcano@linaro.org> 2384M: Daniel Lezcano <daniel.lezcano@linaro.org>
2382L: linux-pm@vger.kernel.org 2385L: linux-pm@vger.kernel.org
2383L: linux-arm-kernel@lists.infradead.org 2386L: linux-arm-kernel@lists.infradead.org
2384T: git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git 2387T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
2385S: Maintained 2388S: Maintained
2386F: drivers/cpuidle/cpuidle-big_little.c 2389F: drivers/cpuidle/cpuidle-big_little.c
2387 2390
2388CPUIDLE DRIVERS 2391CPUIDLE DRIVERS
2389M: Rafael J. Wysocki <rjw@rjwysocki.net> 2392M: Rafael J. Wysocki <rjw@rjwysocki.net>
2390M: Daniel Lezcano <daniel.lezcano@linaro.org> 2393M: Daniel Lezcano <daniel.lezcano@linaro.org>
2391L: linux-pm@vger.kernel.org 2394L: linux-pm@vger.kernel.org
2392S: Maintained 2395S: Maintained
2393T: git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git 2396T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
2394F: drivers/cpuidle/* 2397F: drivers/cpuidle/*
2395F: include/linux/cpuidle.h 2398F: include/linux/cpuidle.h
2396 2399
@@ -2408,8 +2411,10 @@ F: tools/power/cpupower/
2408 2411
2409CPUSETS 2412CPUSETS
2410M: Li Zefan <lizefan@huawei.com> 2413M: Li Zefan <lizefan@huawei.com>
2414L: cgroups@vger.kernel.org
2411W: http://www.bullopensource.org/cpuset/ 2415W: http://www.bullopensource.org/cpuset/
2412W: http://oss.sgi.com/projects/cpusets/ 2416W: http://oss.sgi.com/projects/cpusets/
2417T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git
2413S: Maintained 2418S: Maintained
2414F: Documentation/cgroups/cpusets.txt 2419F: Documentation/cgroups/cpusets.txt
2415F: include/linux/cpuset.h 2420F: include/linux/cpuset.h
@@ -2455,9 +2460,9 @@ S: Maintained
2455F: sound/pci/cs5535audio/ 2460F: sound/pci/cs5535audio/
2456 2461
2457CW1200 WLAN driver 2462CW1200 WLAN driver
2458M: Solomon Peachy <pizza@shaftnet.org> 2463M: Solomon Peachy <pizza@shaftnet.org>
2459S: Maintained 2464S: Maintained
2460F: drivers/net/wireless/cw1200/ 2465F: drivers/net/wireless/cw1200/
2461 2466
2462CX18 VIDEO4LINUX DRIVER 2467CX18 VIDEO4LINUX DRIVER
2463M: Andy Walls <awalls@md.metrocast.net> 2468M: Andy Walls <awalls@md.metrocast.net>
@@ -2608,9 +2613,9 @@ DC395x SCSI driver
2608M: Oliver Neukum <oliver@neukum.org> 2613M: Oliver Neukum <oliver@neukum.org>
2609M: Ali Akcaagac <aliakc@web.de> 2614M: Ali Akcaagac <aliakc@web.de>
2610M: Jamie Lenehan <lenehan@twibble.org> 2615M: Jamie Lenehan <lenehan@twibble.org>
2611W: http://twibble.org/dist/dc395x/
2612L: dc395x@twibble.org 2616L: dc395x@twibble.org
2613L: http://lists.twibble.org/mailman/listinfo/dc395x/ 2617W: http://twibble.org/dist/dc395x/
2618W: http://lists.twibble.org/mailman/listinfo/dc395x/
2614S: Maintained 2619S: Maintained
2615F: Documentation/scsi/dc395x.txt 2620F: Documentation/scsi/dc395x.txt
2616F: drivers/scsi/dc395x.* 2621F: drivers/scsi/dc395x.*
@@ -2796,9 +2801,9 @@ S: Supported
2796F: drivers/acpi/dock.c 2801F: drivers/acpi/dock.c
2797 2802
2798DOCUMENTATION 2803DOCUMENTATION
2799M: Rob Landley <rob@landley.net> 2804M: Randy Dunlap <rdunlap@infradead.org>
2800L: linux-doc@vger.kernel.org 2805L: linux-doc@vger.kernel.org
2801T: TBD 2806T: quilt http://www.infradead.org/~rdunlap/Doc/patches/
2802S: Maintained 2807S: Maintained
2803F: Documentation/ 2808F: Documentation/
2804 2809
@@ -2845,19 +2850,29 @@ F: lib/kobj*
2845DRM DRIVERS 2850DRM DRIVERS
2846M: David Airlie <airlied@linux.ie> 2851M: David Airlie <airlied@linux.ie>
2847L: dri-devel@lists.freedesktop.org 2852L: dri-devel@lists.freedesktop.org
2848T: git git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git 2853T: git git://people.freedesktop.org/~airlied/linux
2849S: Maintained 2854S: Maintained
2850F: drivers/gpu/drm/ 2855F: drivers/gpu/drm/
2851F: include/drm/ 2856F: include/drm/
2852F: include/uapi/drm/ 2857F: include/uapi/drm/
2853 2858
2859RADEON DRM DRIVERS
2860M: Alex Deucher <alexander.deucher@amd.com>
2861M: Christian König <christian.koenig@amd.com>
2862L: dri-devel@lists.freedesktop.org
2863T: git git://people.freedesktop.org/~agd5f/linux
2864S: Supported
2865F: drivers/gpu/drm/radeon/
2866F: include/drm/radeon*
2867F: include/uapi/drm/radeon*
2868
2854INTEL DRM DRIVERS (excluding Poulsbo, Moorestown and derivative chipsets) 2869INTEL DRM DRIVERS (excluding Poulsbo, Moorestown and derivative chipsets)
2855M: Daniel Vetter <daniel.vetter@ffwll.ch> 2870M: Daniel Vetter <daniel.vetter@ffwll.ch>
2856M: Jani Nikula <jani.nikula@linux.intel.com> 2871M: Jani Nikula <jani.nikula@linux.intel.com>
2857L: intel-gfx@lists.freedesktop.org 2872L: intel-gfx@lists.freedesktop.org
2858L: dri-devel@lists.freedesktop.org 2873L: dri-devel@lists.freedesktop.org
2859Q: http://patchwork.freedesktop.org/project/intel-gfx/ 2874Q: http://patchwork.freedesktop.org/project/intel-gfx/
2860T: git git://people.freedesktop.org/~danvet/drm-intel 2875T: git git://anongit.freedesktop.org/drm-intel
2861S: Supported 2876S: Supported
2862F: drivers/gpu/drm/i915/ 2877F: drivers/gpu/drm/i915/
2863F: include/drm/i915* 2878F: include/drm/i915*
@@ -3082,6 +3097,8 @@ F: fs/ecryptfs/
3082 3097
3083EDAC-CORE 3098EDAC-CORE
3084M: Doug Thompson <dougthompson@xmission.com> 3099M: Doug Thompson <dougthompson@xmission.com>
3100M: Borislav Petkov <bp@alien8.de>
3101M: Mauro Carvalho Chehab <m.chehab@samsung.com>
3085L: linux-edac@vger.kernel.org 3102L: linux-edac@vger.kernel.org
3086W: bluesmoke.sourceforge.net 3103W: bluesmoke.sourceforge.net
3087S: Supported 3104S: Supported
@@ -3324,6 +3341,17 @@ S: Maintained
3324F: include/linux/netfilter_bridge/ 3341F: include/linux/netfilter_bridge/
3325F: net/bridge/ 3342F: net/bridge/
3326 3343
3344ETHERNET PHY LIBRARY
3345M: Florian Fainelli <f.fainelli@gmail.com>
3346L: netdev@vger.kernel.org
3347S: Maintained
3348F: include/linux/phy.h
3349F: include/linux/phy_fixed.h
3350F: drivers/net/phy/
3351F: Documentation/networking/phy.txt
3352F: drivers/of/of_mdio.c
3353F: drivers/of/of_net.c
3354
3327EXT2 FILE SYSTEM 3355EXT2 FILE SYSTEM
3328M: Jan Kara <jack@suse.cz> 3356M: Jan Kara <jack@suse.cz>
3329L: linux-ext4@vger.kernel.org 3357L: linux-ext4@vger.kernel.org
@@ -4517,6 +4545,7 @@ M: Greg Rose <gregory.v.rose@intel.com>
4517M: Alex Duyck <alexander.h.duyck@intel.com> 4545M: Alex Duyck <alexander.h.duyck@intel.com>
4518M: John Ronciak <john.ronciak@intel.com> 4546M: John Ronciak <john.ronciak@intel.com>
4519M: Mitch Williams <mitch.a.williams@intel.com> 4547M: Mitch Williams <mitch.a.williams@intel.com>
4548M: Linux NICS <linux.nics@intel.com>
4520L: e1000-devel@lists.sourceforge.net 4549L: e1000-devel@lists.sourceforge.net
4521W: http://www.intel.com/support/feedback.htm 4550W: http://www.intel.com/support/feedback.htm
4522W: http://e1000.sourceforge.net/ 4551W: http://e1000.sourceforge.net/
@@ -4534,6 +4563,7 @@ F: Documentation/networking/ixgbevf.txt
4534F: Documentation/networking/i40e.txt 4563F: Documentation/networking/i40e.txt
4535F: Documentation/networking/i40evf.txt 4564F: Documentation/networking/i40evf.txt
4536F: drivers/net/ethernet/intel/ 4565F: drivers/net/ethernet/intel/
4566F: drivers/net/ethernet/intel/*/
4537 4567
4538INTEL-MID GPIO DRIVER 4568INTEL-MID GPIO DRIVER
4539M: David Cohen <david.a.cohen@linux.intel.com> 4569M: David Cohen <david.a.cohen@linux.intel.com>
@@ -4890,7 +4920,7 @@ F: drivers/staging/ktap/
4890KCONFIG 4920KCONFIG
4891M: "Yann E. MORIN" <yann.morin.1998@free.fr> 4921M: "Yann E. MORIN" <yann.morin.1998@free.fr>
4892L: linux-kbuild@vger.kernel.org 4922L: linux-kbuild@vger.kernel.org
4893T: git://gitorious.org/linux-kconfig/linux-kconfig 4923T: git git://gitorious.org/linux-kconfig/linux-kconfig
4894S: Maintained 4924S: Maintained
4895F: Documentation/kbuild/kconfig-language.txt 4925F: Documentation/kbuild/kconfig-language.txt
4896F: scripts/kconfig/ 4926F: scripts/kconfig/
@@ -5447,11 +5477,11 @@ S: Maintained
5447F: drivers/media/tuners/m88ts2022* 5477F: drivers/media/tuners/m88ts2022*
5448 5478
5449MA901 MASTERKIT USB FM RADIO DRIVER 5479MA901 MASTERKIT USB FM RADIO DRIVER
5450M: Alexey Klimov <klimov.linux@gmail.com> 5480M: Alexey Klimov <klimov.linux@gmail.com>
5451L: linux-media@vger.kernel.org 5481L: linux-media@vger.kernel.org
5452T: git git://linuxtv.org/media_tree.git 5482T: git git://linuxtv.org/media_tree.git
5453S: Maintained 5483S: Maintained
5454F: drivers/media/radio/radio-ma901.c 5484F: drivers/media/radio/radio-ma901.c
5455 5485
5456MAC80211 5486MAC80211
5457M: Johannes Berg <johannes@sipsolutions.net> 5487M: Johannes Berg <johannes@sipsolutions.net>
@@ -5487,6 +5517,11 @@ W: http://www.kernel.org/doc/man-pages
5487L: linux-man@vger.kernel.org 5517L: linux-man@vger.kernel.org
5488S: Maintained 5518S: Maintained
5489 5519
5520MARVELL ARMADA DRM SUPPORT
5521M: Russell King <rmk+kernel@arm.linux.org.uk>
5522S: Maintained
5523F: drivers/gpu/drm/armada/
5524
5490MARVELL GIGABIT ETHERNET DRIVERS (skge/sky2) 5525MARVELL GIGABIT ETHERNET DRIVERS (skge/sky2)
5491M: Mirko Lindner <mlindner@marvell.com> 5526M: Mirko Lindner <mlindner@marvell.com>
5492M: Stephen Hemminger <stephen@networkplumber.org> 5527M: Stephen Hemminger <stephen@networkplumber.org>
@@ -5607,7 +5642,7 @@ F: drivers/scsi/megaraid/
5607 5642
5608MELLANOX ETHERNET DRIVER (mlx4_en) 5643MELLANOX ETHERNET DRIVER (mlx4_en)
5609M: Amir Vadai <amirv@mellanox.com> 5644M: Amir Vadai <amirv@mellanox.com>
5610L: netdev@vger.kernel.org 5645L: netdev@vger.kernel.org
5611S: Supported 5646S: Supported
5612W: http://www.mellanox.com 5647W: http://www.mellanox.com
5613Q: http://patchwork.ozlabs.org/project/netdev/list/ 5648Q: http://patchwork.ozlabs.org/project/netdev/list/
@@ -5648,7 +5683,7 @@ F: include/linux/mtd/
5648F: include/uapi/mtd/ 5683F: include/uapi/mtd/
5649 5684
5650MEN A21 WATCHDOG DRIVER 5685MEN A21 WATCHDOG DRIVER
5651M: Johannes Thumshirn <johannes.thumshirn@men.de> 5686M: Johannes Thumshirn <johannes.thumshirn@men.de>
5652L: linux-watchdog@vger.kernel.org 5687L: linux-watchdog@vger.kernel.org
5653S: Supported 5688S: Supported
5654F: drivers/watchdog/mena21_wdt.c 5689F: drivers/watchdog/mena21_wdt.c
@@ -5704,20 +5739,20 @@ L: linux-rdma@vger.kernel.org
5704W: http://www.mellanox.com 5739W: http://www.mellanox.com
5705Q: http://patchwork.ozlabs.org/project/netdev/list/ 5740Q: http://patchwork.ozlabs.org/project/netdev/list/
5706Q: http://patchwork.kernel.org/project/linux-rdma/list/ 5741Q: http://patchwork.kernel.org/project/linux-rdma/list/
5707T: git://openfabrics.org/~eli/connect-ib.git 5742T: git git://openfabrics.org/~eli/connect-ib.git
5708S: Supported 5743S: Supported
5709F: drivers/net/ethernet/mellanox/mlx5/core/ 5744F: drivers/net/ethernet/mellanox/mlx5/core/
5710F: include/linux/mlx5/ 5745F: include/linux/mlx5/
5711 5746
5712Mellanox MLX5 IB driver 5747Mellanox MLX5 IB driver
5713M: Eli Cohen <eli@mellanox.com> 5748M: Eli Cohen <eli@mellanox.com>
5714L: linux-rdma@vger.kernel.org 5749L: linux-rdma@vger.kernel.org
5715W: http://www.mellanox.com 5750W: http://www.mellanox.com
5716Q: http://patchwork.kernel.org/project/linux-rdma/list/ 5751Q: http://patchwork.kernel.org/project/linux-rdma/list/
5717T: git://openfabrics.org/~eli/connect-ib.git 5752T: git git://openfabrics.org/~eli/connect-ib.git
5718S: Supported 5753S: Supported
5719F: include/linux/mlx5/ 5754F: include/linux/mlx5/
5720F: drivers/infiniband/hw/mlx5/ 5755F: drivers/infiniband/hw/mlx5/
5721 5756
5722MODULE SUPPORT 5757MODULE SUPPORT
5723M: Rusty Russell <rusty@rustcorp.com.au> 5758M: Rusty Russell <rusty@rustcorp.com.au>
@@ -5969,6 +6004,9 @@ F: include/linux/netdevice.h
5969F: include/uapi/linux/in.h 6004F: include/uapi/linux/in.h
5970F: include/uapi/linux/net.h 6005F: include/uapi/linux/net.h
5971F: include/uapi/linux/netdevice.h 6006F: include/uapi/linux/netdevice.h
6007F: tools/net/
6008F: tools/testing/selftests/net/
6009F: lib/random32.c
5972 6010
5973NETWORKING [IPv4/IPv6] 6011NETWORKING [IPv4/IPv6]
5974M: "David S. Miller" <davem@davemloft.net> 6012M: "David S. Miller" <davem@davemloft.net>
@@ -6142,6 +6180,12 @@ S: Supported
6142F: drivers/block/nvme* 6180F: drivers/block/nvme*
6143F: include/linux/nvme.h 6181F: include/linux/nvme.h
6144 6182
6183NXP TDA998X DRM DRIVER
6184M: Russell King <rmk+kernel@arm.linux.org.uk>
6185S: Supported
6186F: drivers/gpu/drm/i2c/tda998x_drv.c
6187F: include/drm/i2c/tda998x.h
6188
6145OMAP SUPPORT 6189OMAP SUPPORT
6146M: Tony Lindgren <tony@atomide.com> 6190M: Tony Lindgren <tony@atomide.com>
6147L: linux-omap@vger.kernel.org 6191L: linux-omap@vger.kernel.org
@@ -7196,7 +7240,7 @@ S: Maintained
7196F: drivers/net/ethernet/rdc/r6040.c 7240F: drivers/net/ethernet/rdc/r6040.c
7197 7241
7198RDS - RELIABLE DATAGRAM SOCKETS 7242RDS - RELIABLE DATAGRAM SOCKETS
7199M: Venkat Venkatsubra <venkat.x.venkatsubra@oracle.com> 7243M: Chien Yen <chien.yen@oracle.com>
7200L: rds-devel@oss.oracle.com (moderated for non-subscribers) 7244L: rds-devel@oss.oracle.com (moderated for non-subscribers)
7201S: Supported 7245S: Supported
7202F: net/rds/ 7246F: net/rds/
@@ -7361,10 +7405,26 @@ W: http://www.ibm.com/developerworks/linux/linux390/
7361S: Supported 7405S: Supported
7362F: arch/s390/ 7406F: arch/s390/
7363F: drivers/s390/ 7407F: drivers/s390/
7364F: block/partitions/ibm.c
7365F: Documentation/s390/ 7408F: Documentation/s390/
7366F: Documentation/DocBook/s390* 7409F: Documentation/DocBook/s390*
7367 7410
7411S390 COMMON I/O LAYER
7412M: Sebastian Ott <sebott@linux.vnet.ibm.com>
7413M: Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
7414L: linux-s390@vger.kernel.org
7415W: http://www.ibm.com/developerworks/linux/linux390/
7416S: Supported
7417F: drivers/s390/cio/
7418
7419S390 DASD DRIVER
7420M: Stefan Weinhuber <wein@de.ibm.com>
7421M: Stefan Haberland <stefan.haberland@de.ibm.com>
7422L: linux-s390@vger.kernel.org
7423W: http://www.ibm.com/developerworks/linux/linux390/
7424S: Supported
7425F: drivers/s390/block/dasd*
7426F: block/partitions/ibm.c
7427
7368S390 NETWORK DRIVERS 7428S390 NETWORK DRIVERS
7369M: Ursula Braun <ursula.braun@de.ibm.com> 7429M: Ursula Braun <ursula.braun@de.ibm.com>
7370M: Frank Blaschka <blaschka@linux.vnet.ibm.com> 7430M: Frank Blaschka <blaschka@linux.vnet.ibm.com>
@@ -7374,6 +7434,15 @@ W: http://www.ibm.com/developerworks/linux/linux390/
7374S: Supported 7434S: Supported
7375F: drivers/s390/net/ 7435F: drivers/s390/net/
7376 7436
7437S390 PCI SUBSYSTEM
7438M: Sebastian Ott <sebott@linux.vnet.ibm.com>
7439M: Gerald Schaefer <gerald.schaefer@de.ibm.com>
7440L: linux-s390@vger.kernel.org
7441W: http://www.ibm.com/developerworks/linux/linux390/
7442S: Supported
7443F: arch/s390/pci/
7444F: drivers/pci/hotplug/s390_pci_hpc.c
7445
7377S390 ZCRYPT DRIVER 7446S390 ZCRYPT DRIVER
7378M: Ingo Tuchscherer <ingo.tuchscherer@de.ibm.com> 7447M: Ingo Tuchscherer <ingo.tuchscherer@de.ibm.com>
7379M: linux390@de.ibm.com 7448M: linux390@de.ibm.com
@@ -8429,8 +8498,8 @@ TARGET SUBSYSTEM
8429M: Nicholas A. Bellinger <nab@linux-iscsi.org> 8498M: Nicholas A. Bellinger <nab@linux-iscsi.org>
8430L: linux-scsi@vger.kernel.org 8499L: linux-scsi@vger.kernel.org
8431L: target-devel@vger.kernel.org 8500L: target-devel@vger.kernel.org
8432L: http://groups.google.com/group/linux-iscsi-target-dev
8433W: http://www.linux-iscsi.org 8501W: http://www.linux-iscsi.org
8502W: http://groups.google.com/group/linux-iscsi-target-dev
8434T: git git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git master 8503T: git git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git master
8435S: Supported 8504S: Supported
8436F: drivers/target/ 8505F: drivers/target/
@@ -8671,17 +8740,17 @@ S: Maintained
8671F: drivers/media/radio/radio-raremono.c 8740F: drivers/media/radio/radio-raremono.c
8672 8741
8673THERMAL 8742THERMAL
8674M: Zhang Rui <rui.zhang@intel.com> 8743M: Zhang Rui <rui.zhang@intel.com>
8675M: Eduardo Valentin <eduardo.valentin@ti.com> 8744M: Eduardo Valentin <eduardo.valentin@ti.com>
8676L: linux-pm@vger.kernel.org 8745L: linux-pm@vger.kernel.org
8677T: git git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git 8746T: git git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git
8678T: git git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git 8747T: git git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git
8679Q: https://patchwork.kernel.org/project/linux-pm/list/ 8748Q: https://patchwork.kernel.org/project/linux-pm/list/
8680S: Supported 8749S: Supported
8681F: drivers/thermal/ 8750F: drivers/thermal/
8682F: include/linux/thermal.h 8751F: include/linux/thermal.h
8683F: include/linux/cpu_cooling.h 8752F: include/linux/cpu_cooling.h
8684F: Documentation/devicetree/bindings/thermal/ 8753F: Documentation/devicetree/bindings/thermal/
8685 8754
8686THINGM BLINK(1) USB RGB LED DRIVER 8755THINGM BLINK(1) USB RGB LED DRIVER
8687M: Vivien Didelot <vivien.didelot@savoirfairelinux.com> 8756M: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
@@ -9715,7 +9784,6 @@ F: drivers/xen/*swiotlb*
9715XFS FILESYSTEM 9784XFS FILESYSTEM
9716P: Silicon Graphics Inc 9785P: Silicon Graphics Inc
9717M: Dave Chinner <david@fromorbit.com> 9786M: Dave Chinner <david@fromorbit.com>
9718M: Ben Myers <bpm@sgi.com>
9719M: xfs@oss.sgi.com 9787M: xfs@oss.sgi.com
9720L: xfs@oss.sgi.com 9788L: xfs@oss.sgi.com
9721W: http://oss.sgi.com/projects/xfs 9789W: http://oss.sgi.com/projects/xfs
@@ -9784,7 +9852,7 @@ ZR36067 VIDEO FOR LINUX DRIVER
9784L: mjpeg-users@lists.sourceforge.net 9852L: mjpeg-users@lists.sourceforge.net
9785L: linux-media@vger.kernel.org 9853L: linux-media@vger.kernel.org
9786W: http://mjpeg.sourceforge.net/driver-zoran/ 9854W: http://mjpeg.sourceforge.net/driver-zoran/
9787T: Mercurial http://linuxtv.org/hg/v4l-dvb 9855T: hg http://linuxtv.org/hg/v4l-dvb
9788S: Odd Fixes 9856S: Odd Fixes
9789F: drivers/media/pci/zoran/ 9857F: drivers/media/pci/zoran/
9790 9858
diff --git a/Makefile b/Makefile
index 606ef7c4a544..e5ac8a62e6e5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 3 1VERSION = 3
2PATCHLEVEL = 14 2PATCHLEVEL = 14
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc1 4EXTRAVERSION =
5NAME = Shuffling Zombie Juror 5NAME = Shuffling Zombie Juror
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
@@ -605,10 +605,11 @@ endif
605ifdef CONFIG_CC_STACKPROTECTOR_REGULAR 605ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
606 stackp-flag := -fstack-protector 606 stackp-flag := -fstack-protector
607 ifeq ($(call cc-option, $(stackp-flag)),) 607 ifeq ($(call cc-option, $(stackp-flag)),)
608 $(warning Cannot use CONFIG_CC_STACKPROTECTOR: \ 608 $(warning Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: \
609 -fstack-protector not supported by compiler)) 609 -fstack-protector not supported by compiler)
610 endif 610 endif
611else ifdef CONFIG_CC_STACKPROTECTOR_STRONG 611else
612ifdef CONFIG_CC_STACKPROTECTOR_STRONG
612 stackp-flag := -fstack-protector-strong 613 stackp-flag := -fstack-protector-strong
613 ifeq ($(call cc-option, $(stackp-flag)),) 614 ifeq ($(call cc-option, $(stackp-flag)),)
614 $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \ 615 $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \
@@ -618,6 +619,7 @@ else
618 # Force off for distro compilers that enable stack protector by default. 619 # Force off for distro compilers that enable stack protector by default.
619 stackp-flag := $(call cc-option, -fno-stack-protector) 620 stackp-flag := $(call cc-option, -fno-stack-protector)
620endif 621endif
622endif
621KBUILD_CFLAGS += $(stackp-flag) 623KBUILD_CFLAGS += $(stackp-flag)
622 624
623# This warning generated too much noise in a regular build. 625# This warning generated too much noise in a regular build.
diff --git a/arch/alpha/include/asm/Kbuild b/arch/alpha/include/asm/Kbuild
index a73a8e208a4a..7736f426ff3b 100644
--- a/arch/alpha/include/asm/Kbuild
+++ b/arch/alpha/include/asm/Kbuild
@@ -1,7 +1,8 @@
1 1
2generic-y += clkdev.h
3 2
3generic-y += clkdev.h
4generic-y += exec.h 4generic-y += exec.h
5generic-y += trace_clock.h
6generic-y += preempt.h
7generic-y += hash.h 5generic-y += hash.h
6generic-y += mcs_spinlock.h
7generic-y += preempt.h
8generic-y += trace_clock.h
diff --git a/arch/arc/include/asm/Kbuild b/arch/arc/include/asm/Kbuild
index 0d3362991c31..e76fd79f32b0 100644
--- a/arch/arc/include/asm/Kbuild
+++ b/arch/arc/include/asm/Kbuild
@@ -1,15 +1,15 @@
1generic-y += auxvec.h 1generic-y += auxvec.h
2generic-y += barrier.h 2generic-y += barrier.h
3generic-y += bugs.h
4generic-y += bitsperlong.h 3generic-y += bitsperlong.h
4generic-y += bugs.h
5generic-y += clkdev.h 5generic-y += clkdev.h
6generic-y += cputime.h 6generic-y += cputime.h
7generic-y += device.h 7generic-y += device.h
8generic-y += div64.h 8generic-y += div64.h
9generic-y += emergency-restart.h 9generic-y += emergency-restart.h
10generic-y += errno.h 10generic-y += errno.h
11generic-y += fcntl.h
12generic-y += fb.h 11generic-y += fb.h
12generic-y += fcntl.h
13generic-y += ftrace.h 13generic-y += ftrace.h
14generic-y += hardirq.h 14generic-y += hardirq.h
15generic-y += hash.h 15generic-y += hash.h
@@ -22,6 +22,7 @@ generic-y += kmap_types.h
22generic-y += kvm_para.h 22generic-y += kvm_para.h
23generic-y += local.h 23generic-y += local.h
24generic-y += local64.h 24generic-y += local64.h
25generic-y += mcs_spinlock.h
25generic-y += mman.h 26generic-y += mman.h
26generic-y += msgbuf.h 27generic-y += msgbuf.h
27generic-y += param.h 28generic-y += param.h
@@ -30,6 +31,7 @@ generic-y += pci.h
30generic-y += percpu.h 31generic-y += percpu.h
31generic-y += poll.h 32generic-y += poll.h
32generic-y += posix_types.h 33generic-y += posix_types.h
34generic-y += preempt.h
33generic-y += resource.h 35generic-y += resource.h
34generic-y += scatterlist.h 36generic-y += scatterlist.h
35generic-y += sembuf.h 37generic-y += sembuf.h
@@ -48,4 +50,3 @@ generic-y += ucontext.h
48generic-y += user.h 50generic-y += user.h
49generic-y += vga.h 51generic-y += vga.h
50generic-y += xor.h 52generic-y += xor.h
51generic-y += preempt.h
diff --git a/arch/arc/mm/cache_arc700.c b/arch/arc/mm/cache_arc700.c
index 6b58c1de7577..400c663b21c2 100644
--- a/arch/arc/mm/cache_arc700.c
+++ b/arch/arc/mm/cache_arc700.c
@@ -282,7 +282,7 @@ static inline void __cache_line_loop(unsigned long paddr, unsigned long vaddr,
282#else 282#else
283 /* if V-P const for loop, PTAG can be written once outside loop */ 283 /* if V-P const for loop, PTAG can be written once outside loop */
284 if (full_page_op) 284 if (full_page_op)
285 write_aux_reg(ARC_REG_DC_PTAG, paddr); 285 write_aux_reg(aux_tag, paddr);
286#endif 286#endif
287 287
288 while (num_lines-- > 0) { 288 while (num_lines-- > 0) {
@@ -296,7 +296,7 @@ static inline void __cache_line_loop(unsigned long paddr, unsigned long vaddr,
296 write_aux_reg(aux_cmd, vaddr); 296 write_aux_reg(aux_cmd, vaddr);
297 vaddr += L1_CACHE_BYTES; 297 vaddr += L1_CACHE_BYTES;
298#else 298#else
299 write_aux_reg(aux, paddr); 299 write_aux_reg(aux_cmd, paddr);
300 paddr += L1_CACHE_BYTES; 300 paddr += L1_CACHE_BYTES;
301#endif 301#endif
302 } 302 }
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index e25419817791..15949459611f 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1578,6 +1578,7 @@ config BL_SWITCHER_DUMMY_IF
1578 1578
1579choice 1579choice
1580 prompt "Memory split" 1580 prompt "Memory split"
1581 depends on MMU
1581 default VMSPLIT_3G 1582 default VMSPLIT_3G
1582 help 1583 help
1583 Select the desired split between kernel and user memory. 1584 Select the desired split between kernel and user memory.
@@ -1595,6 +1596,7 @@ endchoice
1595 1596
1596config PAGE_OFFSET 1597config PAGE_OFFSET
1597 hex 1598 hex
1599 default PHYS_OFFSET if !MMU
1598 default 0x40000000 if VMSPLIT_1G 1600 default 0x40000000 if VMSPLIT_1G
1599 default 0x80000000 if VMSPLIT_2G 1601 default 0x80000000 if VMSPLIT_2G
1600 default 0xC0000000 1602 default 0xC0000000
@@ -1903,6 +1905,7 @@ config XEN
1903 depends on ARM && AEABI && OF 1905 depends on ARM && AEABI && OF
1904 depends on CPU_V7 && !CPU_V6 1906 depends on CPU_V7 && !CPU_V6
1905 depends on !GENERIC_ATOMIC64 1907 depends on !GENERIC_ATOMIC64
1908 depends on MMU
1906 select ARM_PSCI 1909 select ARM_PSCI
1907 select SWIOTLB_XEN 1910 select SWIOTLB_XEN
1908 select ARCH_DMA_ADDR_T_64BIT 1911 select ARCH_DMA_ADDR_T_64BIT
diff --git a/arch/arm/boot/compressed/.gitignore b/arch/arm/boot/compressed/.gitignore
index 47279aa96a6a..0714e0334e33 100644
--- a/arch/arm/boot/compressed/.gitignore
+++ b/arch/arm/boot/compressed/.gitignore
@@ -1,4 +1,5 @@
1ashldi3.S 1ashldi3.S
2bswapsdi2.S
2font.c 3font.c
3lib1funcs.S 4lib1funcs.S
4hyp-stub.S 5hyp-stub.S
diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index b9d6a8b485e0..032030361bef 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -38,6 +38,7 @@ dtb-$(CONFIG_ARCH_AT91) += at91sam9g35ek.dtb
38dtb-$(CONFIG_ARCH_AT91) += at91sam9x25ek.dtb 38dtb-$(CONFIG_ARCH_AT91) += at91sam9x25ek.dtb
39dtb-$(CONFIG_ARCH_AT91) += at91sam9x35ek.dtb 39dtb-$(CONFIG_ARCH_AT91) += at91sam9x35ek.dtb
40# sama5d3 40# sama5d3
41dtb-$(CONFIG_ARCH_AT91) += at91-sama5d3_xplained.dtb
41dtb-$(CONFIG_ARCH_AT91) += sama5d31ek.dtb 42dtb-$(CONFIG_ARCH_AT91) += sama5d31ek.dtb
42dtb-$(CONFIG_ARCH_AT91) += sama5d33ek.dtb 43dtb-$(CONFIG_ARCH_AT91) += sama5d33ek.dtb
43dtb-$(CONFIG_ARCH_AT91) += sama5d34ek.dtb 44dtb-$(CONFIG_ARCH_AT91) += sama5d34ek.dtb
@@ -208,7 +209,8 @@ dtb-$(CONFIG_ARCH_OMAP2PLUS) += omap2420-h4.dtb \
208 omap3-n900.dtb \ 209 omap3-n900.dtb \
209 omap3-n9.dtb \ 210 omap3-n9.dtb \
210 omap3-n950.dtb \ 211 omap3-n950.dtb \
211 omap3-tobi.dtb \ 212 omap3-overo-tobi.dtb \
213 omap3-overo-storm-tobi.dtb \
212 omap3-gta04.dtb \ 214 omap3-gta04.dtb \
213 omap3-igep0020.dtb \ 215 omap3-igep0020.dtb \
214 omap3-igep0030.dtb \ 216 omap3-igep0030.dtb \
diff --git a/arch/arm/boot/dts/am335x-evmsk.dts b/arch/arm/boot/dts/am335x-evmsk.dts
index 4718ec4a4dbf..486880b74831 100644
--- a/arch/arm/boot/dts/am335x-evmsk.dts
+++ b/arch/arm/boot/dts/am335x-evmsk.dts
@@ -121,7 +121,7 @@
121 ti,model = "AM335x-EVMSK"; 121 ti,model = "AM335x-EVMSK";
122 ti,audio-codec = <&tlv320aic3106>; 122 ti,audio-codec = <&tlv320aic3106>;
123 ti,mcasp-controller = <&mcasp1>; 123 ti,mcasp-controller = <&mcasp1>;
124 ti,codec-clock-rate = <24576000>; 124 ti,codec-clock-rate = <24000000>;
125 ti,audio-routing = 125 ti,audio-routing =
126 "Headphone Jack", "HPLOUT", 126 "Headphone Jack", "HPLOUT",
127 "Headphone Jack", "HPROUT"; 127 "Headphone Jack", "HPROUT";
@@ -256,6 +256,12 @@
256 >; 256 >;
257 }; 257 };
258 258
259 mmc1_pins: pinmux_mmc1_pins {
260 pinctrl-single,pins = <
261 0x160 (PIN_INPUT | MUX_MODE7) /* spi0_cs1.gpio0_6 */
262 >;
263 };
264
259 mcasp1_pins: mcasp1_pins { 265 mcasp1_pins: mcasp1_pins {
260 pinctrl-single,pins = < 266 pinctrl-single,pins = <
261 0x10c (PIN_INPUT_PULLDOWN | MUX_MODE4) /* mii1_crs.mcasp1_aclkx */ 267 0x10c (PIN_INPUT_PULLDOWN | MUX_MODE4) /* mii1_crs.mcasp1_aclkx */
@@ -456,6 +462,9 @@
456 status = "okay"; 462 status = "okay";
457 vmmc-supply = <&vmmc_reg>; 463 vmmc-supply = <&vmmc_reg>;
458 bus-width = <4>; 464 bus-width = <4>;
465 pinctrl-names = "default";
466 pinctrl-0 = <&mmc1_pins>;
467 cd-gpios = <&gpio0 6 GPIO_ACTIVE_HIGH>;
459}; 468};
460 469
461&sham { 470&sham {
diff --git a/arch/arm/boot/dts/armada-xp-mv78260.dtsi b/arch/arm/boot/dts/armada-xp-mv78260.dtsi
index 66609684d41b..9480cf891f8c 100644
--- a/arch/arm/boot/dts/armada-xp-mv78260.dtsi
+++ b/arch/arm/boot/dts/armada-xp-mv78260.dtsi
@@ -23,6 +23,7 @@
23 gpio0 = &gpio0; 23 gpio0 = &gpio0;
24 gpio1 = &gpio1; 24 gpio1 = &gpio1;
25 gpio2 = &gpio2; 25 gpio2 = &gpio2;
26 eth3 = &eth3;
26 }; 27 };
27 28
28 cpus { 29 cpus {
@@ -291,7 +292,7 @@
291 interrupts = <91>; 292 interrupts = <91>;
292 }; 293 };
293 294
294 ethernet@34000 { 295 eth3: ethernet@34000 {
295 compatible = "marvell,armada-370-neta"; 296 compatible = "marvell,armada-370-neta";
296 reg = <0x34000 0x4000>; 297 reg = <0x34000 0x4000>;
297 interrupts = <14>; 298 interrupts = <14>;
diff --git a/arch/arm/boot/dts/at91-sama5d3_xplained.dts b/arch/arm/boot/dts/at91-sama5d3_xplained.dts
new file mode 100644
index 000000000000..ce1375595e5f
--- /dev/null
+++ b/arch/arm/boot/dts/at91-sama5d3_xplained.dts
@@ -0,0 +1,229 @@
1/*
2 * at91-sama5d3_xplained.dts - Device Tree file for the SAMA5D3 Xplained board
3 *
4 * Copyright (C) 2014 Atmel,
5 * 2014 Nicolas Ferre <nicolas.ferre@atmel.com>
6 *
7 * Licensed under GPLv2 or later.
8 */
9/dts-v1/;
10#include "sama5d36.dtsi"
11
12/ {
13 model = "SAMA5D3 Xplained";
14 compatible = "atmel,sama5d3-xplained", "atmel,sama5d3", "atmel,sama5";
15
16 chosen {
17 bootargs = "console=ttyS0,115200";
18 };
19
20 memory {
21 reg = <0x20000000 0x10000000>;
22 };
23
24 ahb {
25 apb {
26 mmc0: mmc@f0000000 {
27 pinctrl-0 = <&pinctrl_mmc0_clk_cmd_dat0 &pinctrl_mmc0_dat1_3 &pinctrl_mmc0_dat4_7 &pinctrl_mmc0_cd>;
28 status = "okay";
29 slot@0 {
30 reg = <0>;
31 bus-width = <8>;
32 cd-gpios = <&pioE 0 GPIO_ACTIVE_LOW>;
33 };
34 };
35
36 spi0: spi@f0004000 {
37 cs-gpios = <&pioD 13 0>;
38 status = "okay";
39 };
40
41 can0: can@f000c000 {
42 status = "okay";
43 };
44
45 i2c0: i2c@f0014000 {
46 status = "okay";
47 };
48
49 i2c1: i2c@f0018000 {
50 status = "okay";
51 };
52
53 macb0: ethernet@f0028000 {
54 phy-mode = "rgmii";
55 status = "okay";
56 };
57
58 usart0: serial@f001c000 {
59 status = "okay";
60 };
61
62 usart1: serial@f0020000 {
63 pinctrl-0 = <&pinctrl_usart1 &pinctrl_usart1_rts_cts>;
64 status = "okay";
65 };
66
67 uart0: serial@f0024000 {
68 status = "okay";
69 };
70
71 mmc1: mmc@f8000000 {
72 pinctrl-0 = <&pinctrl_mmc1_clk_cmd_dat0 &pinctrl_mmc1_dat1_3 &pinctrl_mmc1_cd>;
73 status = "okay";
74 slot@0 {
75 reg = <0>;
76 bus-width = <4>;
77 cd-gpios = <&pioE 1 GPIO_ACTIVE_HIGH>;
78 };
79 };
80
81 spi1: spi@f8008000 {
82 cs-gpios = <&pioC 25 0>, <0>, <0>, <&pioD 16 0>;
83 status = "okay";
84 };
85
86 adc0: adc@f8018000 {
87 pinctrl-0 = <
88 &pinctrl_adc0_adtrg
89 &pinctrl_adc0_ad0
90 &pinctrl_adc0_ad1
91 &pinctrl_adc0_ad2
92 &pinctrl_adc0_ad3
93 &pinctrl_adc0_ad4
94 &pinctrl_adc0_ad5
95 &pinctrl_adc0_ad6
96 &pinctrl_adc0_ad7
97 &pinctrl_adc0_ad8
98 &pinctrl_adc0_ad9
99 >;
100 status = "okay";
101 };
102
103 i2c2: i2c@f801c000 {
104 dmas = <0>, <0>; /* Do not use DMA for i2c2 */
105 status = "okay";
106 };
107
108 macb1: ethernet@f802c000 {
109 phy-mode = "rmii";
110 status = "okay";
111 };
112
113 dbgu: serial@ffffee00 {
114 status = "okay";
115 };
116
117 pinctrl@fffff200 {
118 board {
119 pinctrl_mmc0_cd: mmc0_cd {
120 atmel,pins =
121 <AT91_PIOE 0 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP_DEGLITCH>;
122 };
123
124 pinctrl_mmc1_cd: mmc1_cd {
125 atmel,pins =
126 <AT91_PIOE 1 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP_DEGLITCH>;
127 };
128
129 pinctrl_usba_vbus: usba_vbus {
130 atmel,pins =
131 <AT91_PIOE 9 AT91_PERIPH_GPIO AT91_PINCTRL_DEGLITCH>; /* PE9, conflicts with A9 */
132 };
133 };
134 };
135
136 pmc: pmc@fffffc00 {
137 main: mainck {
138 clock-frequency = <12000000>;
139 };
140 };
141 };
142
143 nand0: nand@60000000 {
144 nand-bus-width = <8>;
145 nand-ecc-mode = "hw";
146 atmel,has-pmecc;
147 atmel,pmecc-cap = <4>;
148 atmel,pmecc-sector-size = <512>;
149 nand-on-flash-bbt;
150 status = "okay";
151
152 at91bootstrap@0 {
153 label = "at91bootstrap";
154 reg = <0x0 0x40000>;
155 };
156
157 bootloader@40000 {
158 label = "bootloader";
159 reg = <0x40000 0x80000>;
160 };
161
162 bootloaderenv@c0000 {
163 label = "bootloader env";
164 reg = <0xc0000 0xc0000>;
165 };
166
167 dtb@180000 {
168 label = "device tree";
169 reg = <0x180000 0x80000>;
170 };
171
172 kernel@200000 {
173 label = "kernel";
174 reg = <0x200000 0x600000>;
175 };
176
177 rootfs@800000 {
178 label = "rootfs";
179 reg = <0x800000 0x0f800000>;
180 };
181 };
182
183 usb0: gadget@00500000 {
184 atmel,vbus-gpio = <&pioE 9 GPIO_ACTIVE_HIGH>; /* PE9, conflicts with A9 */
185 pinctrl-names = "default";
186 pinctrl-0 = <&pinctrl_usba_vbus>;
187 status = "okay";
188 };
189
190 usb1: ohci@00600000 {
191 num-ports = <3>;
192 atmel,vbus-gpio = <0
193 &pioE 3 GPIO_ACTIVE_LOW
194 &pioE 4 GPIO_ACTIVE_LOW
195 >;
196 status = "okay";
197 };
198
199 usb2: ehci@00700000 {
200 status = "okay";
201 };
202 };
203
204 gpio_keys {
205 compatible = "gpio-keys";
206
207 bp3 {
208 label = "PB_USER";
209 gpios = <&pioE 29 GPIO_ACTIVE_LOW>;
210 linux,code = <0x104>;
211 gpio-key,wakeup;
212 };
213 };
214
215 leds {
216 compatible = "gpio-leds";
217
218 d2 {
219 label = "d2";
220 gpios = <&pioE 23 GPIO_ACTIVE_LOW>; /* PE23, conflicts with A23, CTS2 */
221 linux,default-trigger = "heartbeat";
222 };
223
224 d3 {
225 label = "d3";
226 gpios = <&pioE 24 GPIO_ACTIVE_HIGH>;
227 };
228 };
229};
diff --git a/arch/arm/boot/dts/at91sam9263.dtsi b/arch/arm/boot/dts/at91sam9263.dtsi
index 0042f73068b0..fece8665fb63 100644
--- a/arch/arm/boot/dts/at91sam9263.dtsi
+++ b/arch/arm/boot/dts/at91sam9263.dtsi
@@ -523,7 +523,7 @@
523 }; 523 };
524 524
525 i2c0: i2c@fff88000 { 525 i2c0: i2c@fff88000 {
526 compatible = "atmel,at91sam9263-i2c"; 526 compatible = "atmel,at91sam9260-i2c";
527 reg = <0xfff88000 0x100>; 527 reg = <0xfff88000 0x100>;
528 interrupts = <13 IRQ_TYPE_LEVEL_HIGH 6>; 528 interrupts = <13 IRQ_TYPE_LEVEL_HIGH 6>;
529 #address-cells = <1>; 529 #address-cells = <1>;
diff --git a/arch/arm/boot/dts/at91sam9n12ek.dts b/arch/arm/boot/dts/at91sam9n12ek.dts
index e9487f6f0166..924a6a6ffd0f 100644
--- a/arch/arm/boot/dts/at91sam9n12ek.dts
+++ b/arch/arm/boot/dts/at91sam9n12ek.dts
@@ -124,6 +124,10 @@
124 nand-on-flash-bbt; 124 nand-on-flash-bbt;
125 status = "okay"; 125 status = "okay";
126 }; 126 };
127
128 usb0: ohci@00500000 {
129 status = "okay";
130 };
127 }; 131 };
128 132
129 leds { 133 leds {
diff --git a/arch/arm/boot/dts/bcm11351.dtsi b/arch/arm/boot/dts/bcm11351.dtsi
index e491b82f8d67..792fde1b7f75 100644
--- a/arch/arm/boot/dts/bcm11351.dtsi
+++ b/arch/arm/boot/dts/bcm11351.dtsi
@@ -147,7 +147,7 @@
147 }; 147 };
148 148
149 pinctrl@35004800 { 149 pinctrl@35004800 {
150 compatible = "brcm,capri-pinctrl"; 150 compatible = "brcm,bcm11351-pinctrl";
151 reg = <0x35004800 0x430>; 151 reg = <0x35004800 0x430>;
152 }; 152 };
153 153
diff --git a/arch/arm/boot/dts/dove.dtsi b/arch/arm/boot/dts/dove.dtsi
index 2b76524f4aa7..187fd46b7b5e 100644
--- a/arch/arm/boot/dts/dove.dtsi
+++ b/arch/arm/boot/dts/dove.dtsi
@@ -379,15 +379,6 @@
379 #clock-cells = <1>; 379 #clock-cells = <1>;
380 }; 380 };
381 381
382 pmu_intc: pmu-interrupt-ctrl@d0050 {
383 compatible = "marvell,dove-pmu-intc";
384 interrupt-controller;
385 #interrupt-cells = <1>;
386 reg = <0xd0050 0x8>;
387 interrupts = <33>;
388 marvell,#interrupts = <7>;
389 };
390
391 pinctrl: pin-ctrl@d0200 { 382 pinctrl: pin-ctrl@d0200 {
392 compatible = "marvell,dove-pinctrl"; 383 compatible = "marvell,dove-pinctrl";
393 reg = <0xd0200 0x10>; 384 reg = <0xd0200 0x10>;
@@ -610,8 +601,6 @@
610 rtc: real-time-clock@d8500 { 601 rtc: real-time-clock@d8500 {
611 compatible = "marvell,orion-rtc"; 602 compatible = "marvell,orion-rtc";
612 reg = <0xd8500 0x20>; 603 reg = <0xd8500 0x20>;
613 interrupt-parent = <&pmu_intc>;
614 interrupts = <5>;
615 }; 604 };
616 605
617 gpio2: gpio-ctrl@e8400 { 606 gpio2: gpio-ctrl@e8400 {
diff --git a/arch/arm/boot/dts/imx6dl-hummingboard.dts b/arch/arm/boot/dts/imx6dl-hummingboard.dts
index fd8fc7cd53f3..5bfae54fb780 100644
--- a/arch/arm/boot/dts/imx6dl-hummingboard.dts
+++ b/arch/arm/boot/dts/imx6dl-hummingboard.dts
@@ -52,12 +52,6 @@
52 }; 52 };
53 }; 53 };
54 54
55 codec: spdif-transmitter {
56 compatible = "linux,spdif-dit";
57 pinctrl-names = "default";
58 pinctrl-0 = <&pinctrl_hummingboard_spdif>;
59 };
60
61 sound-spdif { 55 sound-spdif {
62 compatible = "fsl,imx-audio-spdif"; 56 compatible = "fsl,imx-audio-spdif";
63 model = "imx-spdif"; 57 model = "imx-spdif";
@@ -111,7 +105,7 @@
111 }; 105 };
112 106
113 pinctrl_hummingboard_spdif: hummingboard-spdif { 107 pinctrl_hummingboard_spdif: hummingboard-spdif {
114 fsl,pins = <MX6QDL_PAD_GPIO_17__SPDIF_OUT 0x1b0b0>; 108 fsl,pins = <MX6QDL_PAD_GPIO_17__SPDIF_OUT 0x13091>;
115 }; 109 };
116 110
117 pinctrl_hummingboard_usbh1_vbus: hummingboard-usbh1-vbus { 111 pinctrl_hummingboard_usbh1_vbus: hummingboard-usbh1-vbus {
@@ -142,6 +136,8 @@
142}; 136};
143 137
144&spdif { 138&spdif {
139 pinctrl-names = "default";
140 pinctrl-0 = <&pinctrl_hummingboard_spdif>;
145 status = "okay"; 141 status = "okay";
146}; 142};
147 143
diff --git a/arch/arm/boot/dts/imx6qdl-cubox-i.dtsi b/arch/arm/boot/dts/imx6qdl-cubox-i.dtsi
index 64daa3b311f6..c2a24888a276 100644
--- a/arch/arm/boot/dts/imx6qdl-cubox-i.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-cubox-i.dtsi
@@ -46,12 +46,6 @@
46 }; 46 };
47 }; 47 };
48 48
49 codec: spdif-transmitter {
50 compatible = "linux,spdif-dit";
51 pinctrl-names = "default";
52 pinctrl-0 = <&pinctrl_cubox_i_spdif>;
53 };
54
55 sound-spdif { 49 sound-spdif {
56 compatible = "fsl,imx-audio-spdif"; 50 compatible = "fsl,imx-audio-spdif";
57 model = "imx-spdif"; 51 model = "imx-spdif";
@@ -89,7 +83,7 @@
89 }; 83 };
90 84
91 pinctrl_cubox_i_spdif: cubox-i-spdif { 85 pinctrl_cubox_i_spdif: cubox-i-spdif {
92 fsl,pins = <MX6QDL_PAD_GPIO_17__SPDIF_OUT 0x1b0b0>; 86 fsl,pins = <MX6QDL_PAD_GPIO_17__SPDIF_OUT 0x13091>;
93 }; 87 };
94 88
95 pinctrl_cubox_i_usbh1_vbus: cubox-i-usbh1-vbus { 89 pinctrl_cubox_i_usbh1_vbus: cubox-i-usbh1-vbus {
@@ -121,6 +115,8 @@
121}; 115};
122 116
123&spdif { 117&spdif {
118 pinctrl-names = "default";
119 pinctrl-0 = <&pinctrl_cubox_i_spdif>;
124 status = "okay"; 120 status = "okay";
125}; 121};
126 122
diff --git a/arch/arm/boot/dts/keystone-clocks.dtsi b/arch/arm/boot/dts/keystone-clocks.dtsi
index 2363593e1050..ef58d1c24313 100644
--- a/arch/arm/boot/dts/keystone-clocks.dtsi
+++ b/arch/arm/boot/dts/keystone-clocks.dtsi
@@ -612,7 +612,7 @@ clocks {
612 compatible = "ti,keystone,psc-clock"; 612 compatible = "ti,keystone,psc-clock";
613 clocks = <&chipclk13>; 613 clocks = <&chipclk13>;
614 clock-output-names = "vcp-3"; 614 clock-output-names = "vcp-3";
615 reg = <0x0235000a8 0xb00>, <0x02350060 0x400>; 615 reg = <0x023500a8 0xb00>, <0x02350060 0x400>;
616 reg-names = "control", "domain"; 616 reg-names = "control", "domain";
617 domain-id = <24>; 617 domain-id = <24>;
618 }; 618 };
diff --git a/arch/arm/boot/dts/omap3-gta04.dts b/arch/arm/boot/dts/omap3-gta04.dts
index b9b55c95a566..d3b253bbc885 100644
--- a/arch/arm/boot/dts/omap3-gta04.dts
+++ b/arch/arm/boot/dts/omap3-gta04.dts
@@ -13,7 +13,7 @@
13 13
14/ { 14/ {
15 model = "OMAP3 GTA04"; 15 model = "OMAP3 GTA04";
16 compatible = "ti,omap3-gta04", "ti,omap3"; 16 compatible = "ti,omap3-gta04", "ti,omap36xx", "ti,omap3";
17 17
18 cpus { 18 cpus {
19 cpu@0 { 19 cpu@0 {
@@ -32,7 +32,7 @@
32 aux-button { 32 aux-button {
33 label = "aux"; 33 label = "aux";
34 linux,code = <169>; 34 linux,code = <169>;
35 gpios = <&gpio1 7 GPIO_ACTIVE_LOW>; 35 gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
36 gpio-key,wakeup; 36 gpio-key,wakeup;
37 }; 37 };
38 }; 38 };
@@ -92,6 +92,8 @@
92 bmp085@77 { 92 bmp085@77 {
93 compatible = "bosch,bmp085"; 93 compatible = "bosch,bmp085";
94 reg = <0x77>; 94 reg = <0x77>;
95 interrupt-parent = <&gpio4>;
96 interrupts = <17 IRQ_TYPE_EDGE_RISING>;
95 }; 97 };
96 98
97 /* leds */ 99 /* leds */
@@ -141,8 +143,8 @@
141 pinctrl-names = "default"; 143 pinctrl-names = "default";
142 pinctrl-0 = <&mmc1_pins>; 144 pinctrl-0 = <&mmc1_pins>;
143 vmmc-supply = <&vmmc1>; 145 vmmc-supply = <&vmmc1>;
144 vmmc_aux-supply = <&vsim>;
145 bus-width = <4>; 146 bus-width = <4>;
147 ti,non-removable;
146}; 148};
147 149
148&mmc2 { 150&mmc2 {
diff --git a/arch/arm/boot/dts/omap3-igep0020.dts b/arch/arm/boot/dts/omap3-igep0020.dts
index 25a2b5f652fd..f2779ac75872 100644
--- a/arch/arm/boot/dts/omap3-igep0020.dts
+++ b/arch/arm/boot/dts/omap3-igep0020.dts
@@ -14,7 +14,7 @@
14 14
15/ { 15/ {
16 model = "IGEPv2 (TI OMAP AM/DM37x)"; 16 model = "IGEPv2 (TI OMAP AM/DM37x)";
17 compatible = "isee,omap3-igep0020", "ti,omap3"; 17 compatible = "isee,omap3-igep0020", "ti,omap36xx", "ti,omap3";
18 18
19 leds { 19 leds {
20 pinctrl-names = "default"; 20 pinctrl-names = "default";
diff --git a/arch/arm/boot/dts/omap3-igep0030.dts b/arch/arm/boot/dts/omap3-igep0030.dts
index 145c58cfc8ac..2793749eb1ba 100644
--- a/arch/arm/boot/dts/omap3-igep0030.dts
+++ b/arch/arm/boot/dts/omap3-igep0030.dts
@@ -13,7 +13,7 @@
13 13
14/ { 14/ {
15 model = "IGEP COM MODULE (TI OMAP AM/DM37x)"; 15 model = "IGEP COM MODULE (TI OMAP AM/DM37x)";
16 compatible = "isee,omap3-igep0030", "ti,omap3"; 16 compatible = "isee,omap3-igep0030", "ti,omap36xx", "ti,omap3";
17 17
18 leds { 18 leds {
19 pinctrl-names = "default"; 19 pinctrl-names = "default";
diff --git a/arch/arm/boot/dts/omap3-n9.dts b/arch/arm/boot/dts/omap3-n9.dts
index 39828ce464ee..9938b5dc1909 100644
--- a/arch/arm/boot/dts/omap3-n9.dts
+++ b/arch/arm/boot/dts/omap3-n9.dts
@@ -14,5 +14,5 @@
14 14
15/ { 15/ {
16 model = "Nokia N9"; 16 model = "Nokia N9";
17 compatible = "nokia,omap3-n9", "ti,omap3"; 17 compatible = "nokia,omap3-n9", "ti,omap36xx", "ti,omap3";
18}; 18};
diff --git a/arch/arm/boot/dts/omap3-n900.dts b/arch/arm/boot/dts/omap3-n900.dts
index 6fc85f963530..0bf40c90faba 100644
--- a/arch/arm/boot/dts/omap3-n900.dts
+++ b/arch/arm/boot/dts/omap3-n900.dts
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2013 Pavel Machek <pavel@ucw.cz> 2 * Copyright (C) 2013 Pavel Machek <pavel@ucw.cz>
3 * Copyright 2013 Aaro Koskinen <aaro.koskinen@iki.fi> 3 * Copyright (C) 2013-2014 Aaro Koskinen <aaro.koskinen@iki.fi>
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 (or later) as 6 * it under the terms of the GNU General Public License version 2 (or later) as
@@ -13,7 +13,7 @@
13 13
14/ { 14/ {
15 model = "Nokia N900"; 15 model = "Nokia N900";
16 compatible = "nokia,omap3-n900", "ti,omap3"; 16 compatible = "nokia,omap3-n900", "ti,omap3430", "ti,omap3";
17 17
18 cpus { 18 cpus {
19 cpu@0 { 19 cpu@0 {
diff --git a/arch/arm/boot/dts/omap3-n950.dts b/arch/arm/boot/dts/omap3-n950.dts
index b076a526b999..261c5589bfa3 100644
--- a/arch/arm/boot/dts/omap3-n950.dts
+++ b/arch/arm/boot/dts/omap3-n950.dts
@@ -14,5 +14,5 @@
14 14
15/ { 15/ {
16 model = "Nokia N950"; 16 model = "Nokia N950";
17 compatible = "nokia,omap3-n950", "ti,omap3"; 17 compatible = "nokia,omap3-n950", "ti,omap36xx", "ti,omap3";
18}; 18};
diff --git a/arch/arm/boot/dts/omap3-overo-storm-tobi.dts b/arch/arm/boot/dts/omap3-overo-storm-tobi.dts
new file mode 100644
index 000000000000..966b5c9cd96a
--- /dev/null
+++ b/arch/arm/boot/dts/omap3-overo-storm-tobi.dts
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2012 Florian Vaussard, EPFL Mobots group
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9/*
10 * Tobi expansion board is manufactured by Gumstix Inc.
11 */
12
13/dts-v1/;
14
15#include "omap36xx.dtsi"
16#include "omap3-overo-tobi-common.dtsi"
17
18/ {
19 model = "OMAP36xx/AM37xx/DM37xx Gumstix Overo on Tobi";
20 compatible = "gumstix,omap3-overo-tobi", "gumstix,omap3-overo", "ti,omap36xx", "ti,omap3";
21};
22
diff --git a/arch/arm/boot/dts/omap3-tobi.dts b/arch/arm/boot/dts/omap3-overo-tobi-common.dtsi
index 7e4ad2aec37a..4edc013a91c1 100644
--- a/arch/arm/boot/dts/omap3-tobi.dts
+++ b/arch/arm/boot/dts/omap3-overo-tobi-common.dtsi
@@ -13,9 +13,6 @@
13#include "omap3-overo.dtsi" 13#include "omap3-overo.dtsi"
14 14
15/ { 15/ {
16 model = "TI OMAP3 Gumstix Overo on Tobi";
17 compatible = "ti,omap3-tobi", "ti,omap3-overo", "ti,omap3";
18
19 leds { 16 leds {
20 compatible = "gpio-leds"; 17 compatible = "gpio-leds";
21 heartbeat { 18 heartbeat {
diff --git a/arch/arm/boot/dts/omap3-overo-tobi.dts b/arch/arm/boot/dts/omap3-overo-tobi.dts
new file mode 100644
index 000000000000..de5653e1b5ca
--- /dev/null
+++ b/arch/arm/boot/dts/omap3-overo-tobi.dts
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2012 Florian Vaussard, EPFL Mobots group
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9/*
10 * Tobi expansion board is manufactured by Gumstix Inc.
11 */
12
13/dts-v1/;
14
15#include "omap34xx.dtsi"
16#include "omap3-overo-tobi-common.dtsi"
17
18/ {
19 model = "OMAP35xx Gumstix Overo on Tobi";
20 compatible = "gumstix,omap3-overo-tobi", "gumstix,omap3-overo", "ti,omap3430", "ti,omap3";
21};
22
diff --git a/arch/arm/boot/dts/omap3-overo.dtsi b/arch/arm/boot/dts/omap3-overo.dtsi
index a461d2fd1fb0..597099907f8e 100644
--- a/arch/arm/boot/dts/omap3-overo.dtsi
+++ b/arch/arm/boot/dts/omap3-overo.dtsi
@@ -9,9 +9,6 @@
9/* 9/*
10 * The Gumstix Overo must be combined with an expansion board. 10 * The Gumstix Overo must be combined with an expansion board.
11 */ 11 */
12/dts-v1/;
13
14#include "omap34xx.dtsi"
15 12
16/ { 13/ {
17 pwmleds { 14 pwmleds {
diff --git a/arch/arm/boot/dts/sama5d3.dtsi b/arch/arm/boot/dts/sama5d3.dtsi
index 52447c17537a..3d5faf85f51b 100644
--- a/arch/arm/boot/dts/sama5d3.dtsi
+++ b/arch/arm/boot/dts/sama5d3.dtsi
@@ -1228,7 +1228,7 @@
1228 compatible = "atmel,at91rm9200-ohci", "usb-ohci"; 1228 compatible = "atmel,at91rm9200-ohci", "usb-ohci";
1229 reg = <0x00600000 0x100000>; 1229 reg = <0x00600000 0x100000>;
1230 interrupts = <32 IRQ_TYPE_LEVEL_HIGH 2>; 1230 interrupts = <32 IRQ_TYPE_LEVEL_HIGH 2>;
1231 clocks = <&usb>, <&uhphs_clk>, <&udphs_clk>, 1231 clocks = <&usb>, <&uhphs_clk>, <&uhphs_clk>,
1232 <&uhpck>; 1232 <&uhpck>;
1233 clock-names = "usb_clk", "ohci_clk", "hclk", "uhpck"; 1233 clock-names = "usb_clk", "ohci_clk", "hclk", "uhpck";
1234 status = "disabled"; 1234 status = "disabled";
diff --git a/arch/arm/boot/dts/sama5d36.dtsi b/arch/arm/boot/dts/sama5d36.dtsi
index 6c31c26e6cc0..db58cad6acd3 100644
--- a/arch/arm/boot/dts/sama5d36.dtsi
+++ b/arch/arm/boot/dts/sama5d36.dtsi
@@ -8,8 +8,8 @@
8 */ 8 */
9#include "sama5d3.dtsi" 9#include "sama5d3.dtsi"
10#include "sama5d3_can.dtsi" 10#include "sama5d3_can.dtsi"
11#include "sama5d3_emac.dtsi"
12#include "sama5d3_gmac.dtsi" 11#include "sama5d3_gmac.dtsi"
12#include "sama5d3_emac.dtsi"
13#include "sama5d3_lcd.dtsi" 13#include "sama5d3_lcd.dtsi"
14#include "sama5d3_mci2.dtsi" 14#include "sama5d3_mci2.dtsi"
15#include "sama5d3_tcb1.dtsi" 15#include "sama5d3_tcb1.dtsi"
diff --git a/arch/arm/boot/dts/ste-href.dtsi b/arch/arm/boot/dts/ste-href.dtsi
index 0c1e8d871ed1..6cb9b68e2188 100644
--- a/arch/arm/boot/dts/ste-href.dtsi
+++ b/arch/arm/boot/dts/ste-href.dtsi
@@ -188,7 +188,6 @@
188 msp2: msp@80117000 { 188 msp2: msp@80117000 {
189 pinctrl-names = "default"; 189 pinctrl-names = "default";
190 pinctrl-0 = <&msp2_default_mode>; 190 pinctrl-0 = <&msp2_default_mode>;
191 status = "okay";
192 }; 191 };
193 192
194 msp3: msp@80125000 { 193 msp3: msp@80125000 {
diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
index 040bb0eba152..d4d2763f4794 100644
--- a/arch/arm/boot/dts/sun4i-a10.dtsi
+++ b/arch/arm/boot/dts/sun4i-a10.dtsi
@@ -315,7 +315,7 @@
315 ranges; 315 ranges;
316 316
317 emac: ethernet@01c0b000 { 317 emac: ethernet@01c0b000 {
318 compatible = "allwinner,sun4i-emac"; 318 compatible = "allwinner,sun4i-a10-emac";
319 reg = <0x01c0b000 0x1000>; 319 reg = <0x01c0b000 0x1000>;
320 interrupts = <55>; 320 interrupts = <55>;
321 clocks = <&ahb_gates 17>; 321 clocks = <&ahb_gates 17>;
@@ -323,7 +323,7 @@
323 }; 323 };
324 324
325 mdio@01c0b080 { 325 mdio@01c0b080 {
326 compatible = "allwinner,sun4i-mdio"; 326 compatible = "allwinner,sun4i-a10-mdio";
327 reg = <0x01c0b080 0x14>; 327 reg = <0x01c0b080 0x14>;
328 status = "disabled"; 328 status = "disabled";
329 #address-cells = <1>; 329 #address-cells = <1>;
@@ -426,7 +426,7 @@
426 }; 426 };
427 427
428 rtp: rtp@01c25000 { 428 rtp: rtp@01c25000 {
429 compatible = "allwinner,sun4i-ts"; 429 compatible = "allwinner,sun4i-a10-ts";
430 reg = <0x01c25000 0x100>; 430 reg = <0x01c25000 0x100>;
431 interrupts = <29>; 431 interrupts = <29>;
432 }; 432 };
diff --git a/arch/arm/boot/dts/sun5i-a10s.dtsi b/arch/arm/boot/dts/sun5i-a10s.dtsi
index ea16054857a4..79fd412005b0 100644
--- a/arch/arm/boot/dts/sun5i-a10s.dtsi
+++ b/arch/arm/boot/dts/sun5i-a10s.dtsi
@@ -278,7 +278,7 @@
278 ranges; 278 ranges;
279 279
280 emac: ethernet@01c0b000 { 280 emac: ethernet@01c0b000 {
281 compatible = "allwinner,sun4i-emac"; 281 compatible = "allwinner,sun4i-a10-emac";
282 reg = <0x01c0b000 0x1000>; 282 reg = <0x01c0b000 0x1000>;
283 interrupts = <55>; 283 interrupts = <55>;
284 clocks = <&ahb_gates 17>; 284 clocks = <&ahb_gates 17>;
@@ -286,7 +286,7 @@
286 }; 286 };
287 287
288 mdio@01c0b080 { 288 mdio@01c0b080 {
289 compatible = "allwinner,sun4i-mdio"; 289 compatible = "allwinner,sun4i-a10-mdio";
290 reg = <0x01c0b080 0x14>; 290 reg = <0x01c0b080 0x14>;
291 status = "disabled"; 291 status = "disabled";
292 #address-cells = <1>; 292 #address-cells = <1>;
@@ -383,7 +383,7 @@
383 }; 383 };
384 384
385 rtp: rtp@01c25000 { 385 rtp: rtp@01c25000 {
386 compatible = "allwinner,sun4i-ts"; 386 compatible = "allwinner,sun4i-a10-ts";
387 reg = <0x01c25000 0x100>; 387 reg = <0x01c25000 0x100>;
388 interrupts = <29>; 388 interrupts = <29>;
389 }; 389 };
diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi
index 320335abfccd..c463fd730c91 100644
--- a/arch/arm/boot/dts/sun5i-a13.dtsi
+++ b/arch/arm/boot/dts/sun5i-a13.dtsi
@@ -346,7 +346,7 @@
346 }; 346 };
347 347
348 rtp: rtp@01c25000 { 348 rtp: rtp@01c25000 {
349 compatible = "allwinner,sun4i-ts"; 349 compatible = "allwinner,sun4i-a10-ts";
350 reg = <0x01c25000 0x100>; 350 reg = <0x01c25000 0x100>;
351 interrupts = <29>; 351 interrupts = <29>;
352 }; 352 };
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 119f066f0d98..6f25cf559ad0 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -340,7 +340,7 @@
340 ranges; 340 ranges;
341 341
342 emac: ethernet@01c0b000 { 342 emac: ethernet@01c0b000 {
343 compatible = "allwinner,sun4i-emac"; 343 compatible = "allwinner,sun4i-a10-emac";
344 reg = <0x01c0b000 0x1000>; 344 reg = <0x01c0b000 0x1000>;
345 interrupts = <0 55 4>; 345 interrupts = <0 55 4>;
346 clocks = <&ahb_gates 17>; 346 clocks = <&ahb_gates 17>;
@@ -348,7 +348,7 @@
348 }; 348 };
349 349
350 mdio@01c0b080 { 350 mdio@01c0b080 {
351 compatible = "allwinner,sun4i-mdio"; 351 compatible = "allwinner,sun4i-a10-mdio";
352 reg = <0x01c0b080 0x14>; 352 reg = <0x01c0b080 0x14>;
353 status = "disabled"; 353 status = "disabled";
354 #address-cells = <1>; 354 #address-cells = <1>;
@@ -454,7 +454,7 @@
454 rtc: rtc@01c20d00 { 454 rtc: rtc@01c20d00 {
455 compatible = "allwinner,sun7i-a20-rtc"; 455 compatible = "allwinner,sun7i-a20-rtc";
456 reg = <0x01c20d00 0x20>; 456 reg = <0x01c20d00 0x20>;
457 interrupts = <0 24 1>; 457 interrupts = <0 24 4>;
458 }; 458 };
459 459
460 sid: eeprom@01c23800 { 460 sid: eeprom@01c23800 {
@@ -463,7 +463,7 @@
463 }; 463 };
464 464
465 rtp: rtp@01c25000 { 465 rtp: rtp@01c25000 {
466 compatible = "allwinner,sun4i-ts"; 466 compatible = "allwinner,sun4i-a10-ts";
467 reg = <0x01c25000 0x100>; 467 reg = <0x01c25000 0x100>;
468 interrupts = <0 29 4>; 468 interrupts = <0 29 4>;
469 }; 469 };
@@ -596,10 +596,10 @@
596 hstimer@01c60000 { 596 hstimer@01c60000 {
597 compatible = "allwinner,sun7i-a20-hstimer"; 597 compatible = "allwinner,sun7i-a20-hstimer";
598 reg = <0x01c60000 0x1000>; 598 reg = <0x01c60000 0x1000>;
599 interrupts = <0 81 1>, 599 interrupts = <0 81 4>,
600 <0 82 1>, 600 <0 82 4>,
601 <0 83 1>, 601 <0 83 4>,
602 <0 84 1>; 602 <0 84 4>;
603 clocks = <&ahb_gates 28>; 603 clocks = <&ahb_gates 28>;
604 }; 604 };
605 605
diff --git a/arch/arm/boot/dts/tegra114.dtsi b/arch/arm/boot/dts/tegra114.dtsi
index 389e987ec281..44ec401ec366 100644
--- a/arch/arm/boot/dts/tegra114.dtsi
+++ b/arch/arm/boot/dts/tegra114.dtsi
@@ -57,6 +57,8 @@
57 resets = <&tegra_car 27>; 57 resets = <&tegra_car 27>;
58 reset-names = "dc"; 58 reset-names = "dc";
59 59
60 nvidia,head = <0>;
61
60 rgb { 62 rgb {
61 status = "disabled"; 63 status = "disabled";
62 }; 64 };
@@ -72,6 +74,8 @@
72 resets = <&tegra_car 26>; 74 resets = <&tegra_car 26>;
73 reset-names = "dc"; 75 reset-names = "dc";
74 76
77 nvidia,head = <1>;
78
75 rgb { 79 rgb {
76 status = "disabled"; 80 status = "disabled";
77 }; 81 };
diff --git a/arch/arm/boot/dts/tegra20.dtsi b/arch/arm/boot/dts/tegra20.dtsi
index 480ecda3416b..48d2a7f4d0c0 100644
--- a/arch/arm/boot/dts/tegra20.dtsi
+++ b/arch/arm/boot/dts/tegra20.dtsi
@@ -94,6 +94,8 @@
94 resets = <&tegra_car 27>; 94 resets = <&tegra_car 27>;
95 reset-names = "dc"; 95 reset-names = "dc";
96 96
97 nvidia,head = <0>;
98
97 rgb { 99 rgb {
98 status = "disabled"; 100 status = "disabled";
99 }; 101 };
@@ -109,6 +111,8 @@
109 resets = <&tegra_car 26>; 111 resets = <&tegra_car 26>;
110 reset-names = "dc"; 112 reset-names = "dc";
111 113
114 nvidia,head = <1>;
115
112 rgb { 116 rgb {
113 status = "disabled"; 117 status = "disabled";
114 }; 118 };
diff --git a/arch/arm/boot/dts/tegra30-cardhu.dtsi b/arch/arm/boot/dts/tegra30-cardhu.dtsi
index 9104224124ee..1e156d9d0506 100644
--- a/arch/arm/boot/dts/tegra30-cardhu.dtsi
+++ b/arch/arm/boot/dts/tegra30-cardhu.dtsi
@@ -28,7 +28,7 @@
28 compatible = "nvidia,cardhu", "nvidia,tegra30"; 28 compatible = "nvidia,cardhu", "nvidia,tegra30";
29 29
30 aliases { 30 aliases {
31 rtc0 = "/i2c@7000d000/tps6586x@34"; 31 rtc0 = "/i2c@7000d000/tps65911@2d";
32 rtc1 = "/rtc@7000e000"; 32 rtc1 = "/rtc@7000e000";
33 }; 33 };
34 34
diff --git a/arch/arm/boot/dts/tegra30.dtsi b/arch/arm/boot/dts/tegra30.dtsi
index ed8e7700b46d..19a84e933f4e 100644
--- a/arch/arm/boot/dts/tegra30.dtsi
+++ b/arch/arm/boot/dts/tegra30.dtsi
@@ -170,6 +170,8 @@
170 resets = <&tegra_car 27>; 170 resets = <&tegra_car 27>;
171 reset-names = "dc"; 171 reset-names = "dc";
172 172
173 nvidia,head = <0>;
174
173 rgb { 175 rgb {
174 status = "disabled"; 176 status = "disabled";
175 }; 177 };
@@ -185,6 +187,8 @@
185 resets = <&tegra_car 26>; 187 resets = <&tegra_car 26>;
186 reset-names = "dc"; 188 reset-names = "dc";
187 189
190 nvidia,head = <1>;
191
188 rgb { 192 rgb {
189 status = "disabled"; 193 status = "disabled";
190 }; 194 };
diff --git a/arch/arm/boot/dts/testcases/tests.dtsi b/arch/arm/boot/dts/testcases/tests.dtsi
deleted file mode 100644
index 3f123ecc9dd7..000000000000
--- a/arch/arm/boot/dts/testcases/tests.dtsi
+++ /dev/null
@@ -1,2 +0,0 @@
1/include/ "tests-phandle.dtsi"
2/include/ "tests-interrupts.dtsi"
diff --git a/arch/arm/boot/dts/versatile-pb.dts b/arch/arm/boot/dts/versatile-pb.dts
index f43907c40c93..65f657711323 100644
--- a/arch/arm/boot/dts/versatile-pb.dts
+++ b/arch/arm/boot/dts/versatile-pb.dts
@@ -1,4 +1,4 @@
1/include/ "versatile-ab.dts" 1#include <versatile-ab.dts>
2 2
3/ { 3/ {
4 model = "ARM Versatile PB"; 4 model = "ARM Versatile PB";
@@ -47,4 +47,4 @@
47 }; 47 };
48}; 48};
49 49
50/include/ "testcases/tests.dtsi" 50#include <testcases.dtsi>
diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index 845bc745706b..ee6982976d66 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -29,6 +29,7 @@ CONFIG_ARCH_OMAP3=y
29CONFIG_ARCH_OMAP4=y 29CONFIG_ARCH_OMAP4=y
30CONFIG_SOC_OMAP5=y 30CONFIG_SOC_OMAP5=y
31CONFIG_SOC_AM33XX=y 31CONFIG_SOC_AM33XX=y
32CONFIG_SOC_DRA7XX=y
32CONFIG_SOC_AM43XX=y 33CONFIG_SOC_AM43XX=y
33CONFIG_ARCH_ROCKCHIP=y 34CONFIG_ARCH_ROCKCHIP=y
34CONFIG_ARCH_SOCFPGA=y 35CONFIG_ARCH_SOCFPGA=y
diff --git a/arch/arm/configs/tegra_defconfig b/arch/arm/configs/tegra_defconfig
index 00fe9e9710fd..27d69b558c5d 100644
--- a/arch/arm/configs/tegra_defconfig
+++ b/arch/arm/configs/tegra_defconfig
@@ -204,7 +204,10 @@ CONFIG_MMC_BLOCK_MINORS=16
204CONFIG_MMC_SDHCI=y 204CONFIG_MMC_SDHCI=y
205CONFIG_MMC_SDHCI_PLTFM=y 205CONFIG_MMC_SDHCI_PLTFM=y
206CONFIG_MMC_SDHCI_TEGRA=y 206CONFIG_MMC_SDHCI_TEGRA=y
207CONFIG_NEW_LEDS=y
208CONFIG_LEDS_CLASS=y
207CONFIG_LEDS_GPIO=y 209CONFIG_LEDS_GPIO=y
210CONFIG_LEDS_TRIGGERS=y
208CONFIG_LEDS_TRIGGER_TIMER=y 211CONFIG_LEDS_TRIGGER_TIMER=y
209CONFIG_LEDS_TRIGGER_ONESHOT=y 212CONFIG_LEDS_TRIGGER_ONESHOT=y
210CONFIG_LEDS_TRIGGER_HEARTBEAT=y 213CONFIG_LEDS_TRIGGER_HEARTBEAT=y
diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild
index 3278afe2c3ab..23e728ecf8ab 100644
--- a/arch/arm/include/asm/Kbuild
+++ b/arch/arm/include/asm/Kbuild
@@ -7,16 +7,19 @@ generic-y += current.h
7generic-y += emergency-restart.h 7generic-y += emergency-restart.h
8generic-y += errno.h 8generic-y += errno.h
9generic-y += exec.h 9generic-y += exec.h
10generic-y += hash.h
10generic-y += ioctl.h 11generic-y += ioctl.h
11generic-y += ipcbuf.h 12generic-y += ipcbuf.h
12generic-y += irq_regs.h 13generic-y += irq_regs.h
13generic-y += kdebug.h 14generic-y += kdebug.h
14generic-y += local.h 15generic-y += local.h
15generic-y += local64.h 16generic-y += local64.h
17generic-y += mcs_spinlock.h
16generic-y += msgbuf.h 18generic-y += msgbuf.h
17generic-y += param.h 19generic-y += param.h
18generic-y += parport.h 20generic-y += parport.h
19generic-y += poll.h 21generic-y += poll.h
22generic-y += preempt.h
20generic-y += resource.h 23generic-y += resource.h
21generic-y += sections.h 24generic-y += sections.h
22generic-y += segment.h 25generic-y += segment.h
@@ -33,5 +36,3 @@ generic-y += termios.h
33generic-y += timex.h 36generic-y += timex.h
34generic-y += trace_clock.h 37generic-y += trace_clock.h
35generic-y += unaligned.h 38generic-y += unaligned.h
36generic-y += preempt.h
37generic-y += hash.h
diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
index e9a49fe0284e..8b8b61685a34 100644
--- a/arch/arm/include/asm/cacheflush.h
+++ b/arch/arm/include/asm/cacheflush.h
@@ -212,6 +212,7 @@ extern void copy_to_user_page(struct vm_area_struct *, struct page *,
212static inline void __flush_icache_all(void) 212static inline void __flush_icache_all(void)
213{ 213{
214 __flush_icache_preferred(); 214 __flush_icache_preferred();
215 dsb();
215} 216}
216 217
217/* 218/*
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 8756e4bcdba0..4afb376d9c7c 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -30,14 +30,15 @@
30 */ 30 */
31#define UL(x) _AC(x, UL) 31#define UL(x) _AC(x, UL)
32 32
33/* PAGE_OFFSET - the virtual address of the start of the kernel image */
34#define PAGE_OFFSET UL(CONFIG_PAGE_OFFSET)
35
33#ifdef CONFIG_MMU 36#ifdef CONFIG_MMU
34 37
35/* 38/*
36 * PAGE_OFFSET - the virtual address of the start of the kernel image
37 * TASK_SIZE - the maximum size of a user space task. 39 * TASK_SIZE - the maximum size of a user space task.
38 * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area 40 * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
39 */ 41 */
40#define PAGE_OFFSET UL(CONFIG_PAGE_OFFSET)
41#define TASK_SIZE (UL(CONFIG_PAGE_OFFSET) - UL(SZ_16M)) 42#define TASK_SIZE (UL(CONFIG_PAGE_OFFSET) - UL(SZ_16M))
42#define TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M) 43#define TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M)
43 44
@@ -104,10 +105,6 @@
104#define END_MEM (UL(CONFIG_DRAM_BASE) + CONFIG_DRAM_SIZE) 105#define END_MEM (UL(CONFIG_DRAM_BASE) + CONFIG_DRAM_SIZE)
105#endif 106#endif
106 107
107#ifndef PAGE_OFFSET
108#define PAGE_OFFSET PLAT_PHYS_OFFSET
109#endif
110
111/* 108/*
112 * The module can be at any place in ram in nommu mode. 109 * The module can be at any place in ram in nommu mode.
113 */ 110 */
diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
index 03243f7eeddf..85c60adc8b60 100644
--- a/arch/arm/include/asm/pgtable-3level.h
+++ b/arch/arm/include/asm/pgtable-3level.h
@@ -120,13 +120,16 @@
120/* 120/*
121 * 2nd stage PTE definitions for LPAE. 121 * 2nd stage PTE definitions for LPAE.
122 */ 122 */
123#define L_PTE_S2_MT_UNCACHED (_AT(pteval_t, 0x5) << 2) /* MemAttr[3:0] */ 123#define L_PTE_S2_MT_UNCACHED (_AT(pteval_t, 0x0) << 2) /* strongly ordered */
124#define L_PTE_S2_MT_WRITETHROUGH (_AT(pteval_t, 0xa) << 2) /* MemAttr[3:0] */ 124#define L_PTE_S2_MT_WRITETHROUGH (_AT(pteval_t, 0xa) << 2) /* normal inner write-through */
125#define L_PTE_S2_MT_WRITEBACK (_AT(pteval_t, 0xf) << 2) /* MemAttr[3:0] */ 125#define L_PTE_S2_MT_WRITEBACK (_AT(pteval_t, 0xf) << 2) /* normal inner write-back */
126#define L_PTE_S2_RDONLY (_AT(pteval_t, 1) << 6) /* HAP[1] */ 126#define L_PTE_S2_MT_DEV_SHARED (_AT(pteval_t, 0x1) << 2) /* device */
127#define L_PTE_S2_RDWR (_AT(pteval_t, 3) << 6) /* HAP[2:1] */ 127#define L_PTE_S2_MT_MASK (_AT(pteval_t, 0xf) << 2)
128 128
129#define L_PMD_S2_RDWR (_AT(pmdval_t, 3) << 6) /* HAP[2:1] */ 129#define L_PTE_S2_RDONLY (_AT(pteval_t, 1) << 6) /* HAP[1] */
130#define L_PTE_S2_RDWR (_AT(pteval_t, 3) << 6) /* HAP[2:1] */
131
132#define L_PMD_S2_RDWR (_AT(pmdval_t, 3) << 6) /* HAP[2:1] */
130 133
131/* 134/*
132 * Hyp-mode PL2 PTE definitions for LPAE. 135 * Hyp-mode PL2 PTE definitions for LPAE.
diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h
index ef3c6072aa45..ac4bfae26702 100644
--- a/arch/arm/include/asm/spinlock.h
+++ b/arch/arm/include/asm/spinlock.h
@@ -37,18 +37,9 @@
37 37
38static inline void dsb_sev(void) 38static inline void dsb_sev(void)
39{ 39{
40#if __LINUX_ARM_ARCH__ >= 7 40
41 __asm__ __volatile__ ( 41 dsb(ishst);
42 "dsb ishst\n" 42 __asm__(SEV);
43 SEV
44 );
45#else
46 __asm__ __volatile__ (
47 "mcr p15, 0, %0, c7, c10, 4\n"
48 SEV
49 : : "r" (0)
50 );
51#endif
52} 43}
53 44
54/* 45/*
diff --git a/arch/arm/include/asm/topology.h b/arch/arm/include/asm/topology.h
index 58b8b84adcd2..2fe85fff5cca 100644
--- a/arch/arm/include/asm/topology.h
+++ b/arch/arm/include/asm/topology.h
@@ -20,9 +20,6 @@ extern struct cputopo_arm cpu_topology[NR_CPUS];
20#define topology_core_cpumask(cpu) (&cpu_topology[cpu].core_sibling) 20#define topology_core_cpumask(cpu) (&cpu_topology[cpu].core_sibling)
21#define topology_thread_cpumask(cpu) (&cpu_topology[cpu].thread_sibling) 21#define topology_thread_cpumask(cpu) (&cpu_topology[cpu].thread_sibling)
22 22
23#define mc_capable() (cpu_topology[0].socket_id != -1)
24#define smt_capable() (cpu_topology[0].thread_id != -1)
25
26void init_cpu_topology(void); 23void init_cpu_topology(void);
27void store_cpu_topology(unsigned int cpuid); 24void store_cpu_topology(unsigned int cpuid);
28const struct cpumask *cpu_coregroup_mask(int cpu); 25const struct cpumask *cpu_coregroup_mask(int cpu);
diff --git a/arch/arm/kernel/head-common.S b/arch/arm/kernel/head-common.S
index 47cd974e57ea..c96ecacb2021 100644
--- a/arch/arm/kernel/head-common.S
+++ b/arch/arm/kernel/head-common.S
@@ -177,6 +177,18 @@ __lookup_processor_type_data:
177 .long __proc_info_end 177 .long __proc_info_end
178 .size __lookup_processor_type_data, . - __lookup_processor_type_data 178 .size __lookup_processor_type_data, . - __lookup_processor_type_data
179 179
180__error_lpae:
181#ifdef CONFIG_DEBUG_LL
182 adr r0, str_lpae
183 bl printascii
184 b __error
185str_lpae: .asciz "\nError: Kernel with LPAE support, but CPU does not support LPAE.\n"
186#else
187 b __error
188#endif
189 .align
190ENDPROC(__error_lpae)
191
180__error_p: 192__error_p:
181#ifdef CONFIG_DEBUG_LL 193#ifdef CONFIG_DEBUG_LL
182 adr r0, str_p1 194 adr r0, str_p1
diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index 914616e0bdcd..f5f381d91556 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -102,7 +102,7 @@ ENTRY(stext)
102 and r3, r3, #0xf @ extract VMSA support 102 and r3, r3, #0xf @ extract VMSA support
103 cmp r3, #5 @ long-descriptor translation table format? 103 cmp r3, #5 @ long-descriptor translation table format?
104 THUMB( it lo ) @ force fixup-able long branch encoding 104 THUMB( it lo ) @ force fixup-able long branch encoding
105 blo __error_p @ only classic page table format 105 blo __error_lpae @ only classic page table format
106#endif 106#endif
107 107
108#ifndef CONFIG_XIP_KERNEL 108#ifndef CONFIG_XIP_KERNEL
diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 92f7b15dd221..adabeababeb0 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -30,7 +30,6 @@
30#include <linux/uaccess.h> 30#include <linux/uaccess.h>
31#include <linux/random.h> 31#include <linux/random.h>
32#include <linux/hw_breakpoint.h> 32#include <linux/hw_breakpoint.h>
33#include <linux/cpuidle.h>
34#include <linux/leds.h> 33#include <linux/leds.h>
35#include <linux/reboot.h> 34#include <linux/reboot.h>
36 35
@@ -133,7 +132,11 @@ EXPORT_SYMBOL_GPL(arm_pm_restart);
133 132
134void (*arm_pm_idle)(void); 133void (*arm_pm_idle)(void);
135 134
136static void default_idle(void) 135/*
136 * Called from the core idle loop.
137 */
138
139void arch_cpu_idle(void)
137{ 140{
138 if (arm_pm_idle) 141 if (arm_pm_idle)
139 arm_pm_idle(); 142 arm_pm_idle();
@@ -168,15 +171,6 @@ void arch_cpu_idle_dead(void)
168#endif 171#endif
169 172
170/* 173/*
171 * Called from the core idle loop.
172 */
173void arch_cpu_idle(void)
174{
175 if (cpuidle_idle_call())
176 default_idle();
177}
178
179/*
180 * Called by kexec, immediately prior to machine_kexec(). 174 * Called by kexec, immediately prior to machine_kexec().
181 * 175 *
182 * This must completely disable all secondary CPUs; simply causing those CPUs 176 * This must completely disable all secondary CPUs; simply causing those CPUs
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index b0df9761de6d..1e8b030dbefd 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -731,7 +731,7 @@ static void __init request_standard_resources(const struct machine_desc *mdesc)
731 kernel_data.end = virt_to_phys(_end - 1); 731 kernel_data.end = virt_to_phys(_end - 1);
732 732
733 for_each_memblock(memory, region) { 733 for_each_memblock(memory, region) {
734 res = memblock_virt_alloc_low(sizeof(*res), 0); 734 res = memblock_virt_alloc(sizeof(*res), 0);
735 res->name = "System RAM"; 735 res->name = "System RAM";
736 res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region)); 736 res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
737 res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1; 737 res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 1d8248ea5669..bd18bb8b2770 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -878,7 +878,8 @@ static int hyp_init_cpu_pm_notifier(struct notifier_block *self,
878 unsigned long cmd, 878 unsigned long cmd,
879 void *v) 879 void *v)
880{ 880{
881 if (cmd == CPU_PM_EXIT) { 881 if (cmd == CPU_PM_EXIT &&
882 __hyp_get_vectors() == hyp_default_vectors) {
882 cpu_init_hyp_mode(NULL); 883 cpu_init_hyp_mode(NULL);
883 return NOTIFY_OK; 884 return NOTIFY_OK;
884 } 885 }
diff --git a/arch/arm/kvm/interrupts.S b/arch/arm/kvm/interrupts.S
index ddc15539bad2..0d68d4073068 100644
--- a/arch/arm/kvm/interrupts.S
+++ b/arch/arm/kvm/interrupts.S
@@ -220,6 +220,10 @@ after_vfp_restore:
220 * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are 220 * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are
221 * passed in r0 and r1. 221 * passed in r0 and r1.
222 * 222 *
223 * A function pointer with a value of 0xffffffff has a special meaning,
224 * and is used to implement __hyp_get_vectors in the same way as in
225 * arch/arm/kernel/hyp_stub.S.
226 *
223 * The calling convention follows the standard AAPCS: 227 * The calling convention follows the standard AAPCS:
224 * r0 - r3: caller save 228 * r0 - r3: caller save
225 * r12: caller save 229 * r12: caller save
@@ -363,6 +367,11 @@ hyp_hvc:
363host_switch_to_hyp: 367host_switch_to_hyp:
364 pop {r0, r1, r2} 368 pop {r0, r1, r2}
365 369
370 /* Check for __hyp_get_vectors */
371 cmp r0, #-1
372 mrceq p15, 4, r0, c12, c0, 0 @ get HVBAR
373 beq 1f
374
366 push {lr} 375 push {lr}
367 mrs lr, SPSR 376 mrs lr, SPSR
368 push {lr} 377 push {lr}
@@ -378,7 +387,7 @@ THUMB( orr lr, #1)
378 pop {lr} 387 pop {lr}
379 msr SPSR_csxf, lr 388 msr SPSR_csxf, lr
380 pop {lr} 389 pop {lr}
381 eret 3901: eret
382 391
383guest_trap: 392guest_trap:
384 load_vcpu @ Load VCPU pointer to r0 393 load_vcpu @ Load VCPU pointer to r0
diff --git a/arch/arm/mach-hisi/Kconfig b/arch/arm/mach-hisi/Kconfig
index 8f4649b301b2..1abae5f6a418 100644
--- a/arch/arm/mach-hisi/Kconfig
+++ b/arch/arm/mach-hisi/Kconfig
@@ -8,7 +8,7 @@ config ARCH_HI3xxx
8 select CLKSRC_OF 8 select CLKSRC_OF
9 select GENERIC_CLOCKEVENTS 9 select GENERIC_CLOCKEVENTS
10 select HAVE_ARM_SCU 10 select HAVE_ARM_SCU
11 select HAVE_ARM_TWD 11 select HAVE_ARM_TWD if SMP
12 select HAVE_SMP 12 select HAVE_SMP
13 select PINCTRL 13 select PINCTRL
14 select PINCTRL_SINGLE 14 select PINCTRL_SINGLE
diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index befcaf5d0574..ec419649320f 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -101,11 +101,9 @@ obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
101obj-$(CONFIG_SOC_IMX6Q) += clk-imx6q.o mach-imx6q.o 101obj-$(CONFIG_SOC_IMX6Q) += clk-imx6q.o mach-imx6q.o
102obj-$(CONFIG_SOC_IMX6SL) += clk-imx6sl.o mach-imx6sl.o 102obj-$(CONFIG_SOC_IMX6SL) += clk-imx6sl.o mach-imx6sl.o
103 103
104ifeq ($(CONFIG_PM),y)
105obj-$(CONFIG_SOC_IMX6Q) += pm-imx6q.o headsmp.o 104obj-$(CONFIG_SOC_IMX6Q) += pm-imx6q.o headsmp.o
106# i.MX6SL reuses i.MX6Q code 105# i.MX6SL reuses i.MX6Q code
107obj-$(CONFIG_SOC_IMX6SL) += pm-imx6q.o headsmp.o 106obj-$(CONFIG_SOC_IMX6SL) += pm-imx6q.o headsmp.o
108endif
109 107
110# i.MX5 based machines 108# i.MX5 based machines
111obj-$(CONFIG_MACH_MX51_BABBAGE) += mach-mx51_babbage.o 109obj-$(CONFIG_MACH_MX51_BABBAGE) += mach-mx51_babbage.o
diff --git a/arch/arm/mach-imx/clk-imx6q.c b/arch/arm/mach-imx/clk-imx6q.c
index af2e582d2b74..4d677f442539 100644
--- a/arch/arm/mach-imx/clk-imx6q.c
+++ b/arch/arm/mach-imx/clk-imx6q.c
@@ -482,6 +482,9 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
482 if (IS_ENABLED(CONFIG_PCI_IMX6)) 482 if (IS_ENABLED(CONFIG_PCI_IMX6))
483 clk_set_parent(clk[lvds1_sel], clk[sata_ref]); 483 clk_set_parent(clk[lvds1_sel], clk[sata_ref]);
484 484
485 /* Set initial power mode */
486 imx6q_set_lpm(WAIT_CLOCKED);
487
485 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpt"); 488 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpt");
486 base = of_iomap(np, 0); 489 base = of_iomap(np, 0);
487 WARN_ON(!base); 490 WARN_ON(!base);
diff --git a/arch/arm/mach-imx/clk-imx6sl.c b/arch/arm/mach-imx/clk-imx6sl.c
index 3781a1853998..4c86f3035205 100644
--- a/arch/arm/mach-imx/clk-imx6sl.c
+++ b/arch/arm/mach-imx/clk-imx6sl.c
@@ -266,6 +266,9 @@ static void __init imx6sl_clocks_init(struct device_node *ccm_node)
266 /* Audio-related clocks configuration */ 266 /* Audio-related clocks configuration */
267 clk_set_parent(clks[IMX6SL_CLK_SPDIF0_SEL], clks[IMX6SL_CLK_PLL3_PFD3]); 267 clk_set_parent(clks[IMX6SL_CLK_SPDIF0_SEL], clks[IMX6SL_CLK_PLL3_PFD3]);
268 268
269 /* Set initial power mode */
270 imx6q_set_lpm(WAIT_CLOCKED);
271
269 np = of_find_compatible_node(NULL, NULL, "fsl,imx6sl-gpt"); 272 np = of_find_compatible_node(NULL, NULL, "fsl,imx6sl-gpt");
270 base = of_iomap(np, 0); 273 base = of_iomap(np, 0);
271 WARN_ON(!base); 274 WARN_ON(!base);
diff --git a/arch/arm/mach-imx/common.h b/arch/arm/mach-imx/common.h
index 59c3b9b26bb4..baf439dc22d8 100644
--- a/arch/arm/mach-imx/common.h
+++ b/arch/arm/mach-imx/common.h
@@ -144,13 +144,11 @@ void imx6q_set_chicken_bit(void);
144void imx_cpu_die(unsigned int cpu); 144void imx_cpu_die(unsigned int cpu);
145int imx_cpu_kill(unsigned int cpu); 145int imx_cpu_kill(unsigned int cpu);
146 146
147#ifdef CONFIG_PM
148void imx6q_pm_init(void); 147void imx6q_pm_init(void);
149void imx6q_pm_set_ccm_base(void __iomem *base); 148void imx6q_pm_set_ccm_base(void __iomem *base);
149#ifdef CONFIG_PM
150void imx5_pm_init(void); 150void imx5_pm_init(void);
151#else 151#else
152static inline void imx6q_pm_init(void) {}
153static inline void imx6q_pm_set_ccm_base(void __iomem *base) {}
154static inline void imx5_pm_init(void) {} 152static inline void imx5_pm_init(void) {}
155#endif 153#endif
156 154
diff --git a/arch/arm/mach-imx/pm-imx6q.c b/arch/arm/mach-imx/pm-imx6q.c
index 9d47adc078aa..7a9b98589db7 100644
--- a/arch/arm/mach-imx/pm-imx6q.c
+++ b/arch/arm/mach-imx/pm-imx6q.c
@@ -236,8 +236,6 @@ void __init imx6q_pm_init(void)
236 regmap_update_bits(gpr, IOMUXC_GPR1, IMX6Q_GPR1_GINT, 236 regmap_update_bits(gpr, IOMUXC_GPR1, IMX6Q_GPR1_GINT,
237 IMX6Q_GPR1_GINT); 237 IMX6Q_GPR1_GINT);
238 238
239 /* Set initial power mode */
240 imx6q_set_lpm(WAIT_CLOCKED);
241 239
242 suspend_set_ops(&imx6q_pm_ops); 240 suspend_set_ops(&imx6q_pm_ops);
243} 241}
diff --git a/arch/arm/mach-moxart/Kconfig b/arch/arm/mach-moxart/Kconfig
index ba470d64493b..3795ae28a613 100644
--- a/arch/arm/mach-moxart/Kconfig
+++ b/arch/arm/mach-moxart/Kconfig
@@ -2,7 +2,6 @@ config ARCH_MOXART
2 bool "MOXA ART SoC" if ARCH_MULTI_V4T 2 bool "MOXA ART SoC" if ARCH_MULTI_V4T
3 select CPU_FA526 3 select CPU_FA526
4 select ARM_DMA_MEM_BUFFERABLE 4 select ARM_DMA_MEM_BUFFERABLE
5 select DMA_OF
6 select USE_OF 5 select USE_OF
7 select CLKSRC_OF 6 select CLKSRC_OF
8 select CLKSRC_MMIO 7 select CLKSRC_MMIO
diff --git a/arch/arm/mach-omap1/board-nokia770.c b/arch/arm/mach-omap1/board-nokia770.c
index 91449c5cb70f..85089d821982 100644
--- a/arch/arm/mach-omap1/board-nokia770.c
+++ b/arch/arm/mach-omap1/board-nokia770.c
@@ -156,6 +156,7 @@ static struct omap_usb_config nokia770_usb_config __initdata = {
156 .register_dev = 1, 156 .register_dev = 1,
157 .hmc_mode = 16, 157 .hmc_mode = 16,
158 .pins[0] = 6, 158 .pins[0] = 6,
159 .extcon = "tahvo-usb",
159}; 160};
160 161
161#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) 162#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
diff --git a/arch/arm/mach-omap2/Kconfig b/arch/arm/mach-omap2/Kconfig
index 653b489479e0..0af7ca02314d 100644
--- a/arch/arm/mach-omap2/Kconfig
+++ b/arch/arm/mach-omap2/Kconfig
@@ -50,11 +50,12 @@ config SOC_OMAP5
50 bool "TI OMAP5" 50 bool "TI OMAP5"
51 depends on ARCH_MULTI_V7 51 depends on ARCH_MULTI_V7
52 select ARCH_OMAP2PLUS 52 select ARCH_OMAP2PLUS
53 select ARCH_HAS_OPP
53 select ARM_CPU_SUSPEND if PM 54 select ARM_CPU_SUSPEND if PM
54 select ARM_GIC 55 select ARM_GIC
55 select CPU_V7 56 select CPU_V7
56 select HAVE_ARM_SCU if SMP 57 select HAVE_ARM_SCU if SMP
57 select HAVE_ARM_TWD if LOCAL_TIMERS 58 select HAVE_ARM_TWD if SMP
58 select HAVE_SMP 59 select HAVE_SMP
59 select HAVE_ARM_ARCH_TIMER 60 select HAVE_ARM_ARCH_TIMER
60 select ARM_ERRATA_798181 if SMP 61 select ARM_ERRATA_798181 if SMP
@@ -63,6 +64,7 @@ config SOC_AM33XX
63 bool "TI AM33XX" 64 bool "TI AM33XX"
64 depends on ARCH_MULTI_V7 65 depends on ARCH_MULTI_V7
65 select ARCH_OMAP2PLUS 66 select ARCH_OMAP2PLUS
67 select ARCH_HAS_OPP
66 select ARM_CPU_SUSPEND if PM 68 select ARM_CPU_SUSPEND if PM
67 select CPU_V7 69 select CPU_V7
68 select MULTI_IRQ_HANDLER 70 select MULTI_IRQ_HANDLER
@@ -72,6 +74,7 @@ config SOC_AM43XX
72 depends on ARCH_MULTI_V7 74 depends on ARCH_MULTI_V7
73 select CPU_V7 75 select CPU_V7
74 select ARCH_OMAP2PLUS 76 select ARCH_OMAP2PLUS
77 select ARCH_HAS_OPP
75 select MULTI_IRQ_HANDLER 78 select MULTI_IRQ_HANDLER
76 select ARM_GIC 79 select ARM_GIC
77 select MACH_OMAP_GENERIC 80 select MACH_OMAP_GENERIC
@@ -80,6 +83,7 @@ config SOC_DRA7XX
80 bool "TI DRA7XX" 83 bool "TI DRA7XX"
81 depends on ARCH_MULTI_V7 84 depends on ARCH_MULTI_V7
82 select ARCH_OMAP2PLUS 85 select ARCH_OMAP2PLUS
86 select ARCH_HAS_OPP
83 select ARM_CPU_SUSPEND if PM 87 select ARM_CPU_SUSPEND if PM
84 select ARM_GIC 88 select ARM_GIC
85 select CPU_V7 89 select CPU_V7
@@ -268,9 +272,6 @@ config MACH_OMAP_3430SDP
268 default y 272 default y
269 select OMAP_PACKAGE_CBB 273 select OMAP_PACKAGE_CBB
270 274
271config MACH_NOKIA_N800
272 bool
273
274config MACH_NOKIA_N810 275config MACH_NOKIA_N810
275 bool 276 bool
276 277
@@ -281,7 +282,6 @@ config MACH_NOKIA_N8X0
281 bool "Nokia N800/N810" 282 bool "Nokia N800/N810"
282 depends on SOC_OMAP2420 283 depends on SOC_OMAP2420
283 default y 284 default y
284 select MACH_NOKIA_N800
285 select MACH_NOKIA_N810 285 select MACH_NOKIA_N810
286 select MACH_NOKIA_N810_WIMAX 286 select MACH_NOKIA_N810_WIMAX
287 select OMAP_PACKAGE_ZAC 287 select OMAP_PACKAGE_ZAC
diff --git a/arch/arm/mach-omap2/cclock3xxx_data.c b/arch/arm/mach-omap2/cclock3xxx_data.c
index 3b05aea56d1f..11ed9152e665 100644
--- a/arch/arm/mach-omap2/cclock3xxx_data.c
+++ b/arch/arm/mach-omap2/cclock3xxx_data.c
@@ -433,7 +433,9 @@ static const struct clk_ops dpll4_m5x2_ck_ops = {
433 .enable = &omap2_dflt_clk_enable, 433 .enable = &omap2_dflt_clk_enable,
434 .disable = &omap2_dflt_clk_disable, 434 .disable = &omap2_dflt_clk_disable,
435 .is_enabled = &omap2_dflt_clk_is_enabled, 435 .is_enabled = &omap2_dflt_clk_is_enabled,
436 .set_rate = &omap3_clkoutx2_set_rate,
436 .recalc_rate = &omap3_clkoutx2_recalc, 437 .recalc_rate = &omap3_clkoutx2_recalc,
438 .round_rate = &omap3_clkoutx2_round_rate,
437}; 439};
438 440
439static const struct clk_ops dpll4_m5x2_ck_3630_ops = { 441static const struct clk_ops dpll4_m5x2_ck_3630_ops = {
diff --git a/arch/arm/mach-omap2/cpuidle44xx.c b/arch/arm/mach-omap2/cpuidle44xx.c
index 4c158c838d40..01fc710c8181 100644
--- a/arch/arm/mach-omap2/cpuidle44xx.c
+++ b/arch/arm/mach-omap2/cpuidle44xx.c
@@ -23,6 +23,8 @@
23#include "prm.h" 23#include "prm.h"
24#include "clockdomain.h" 24#include "clockdomain.h"
25 25
26#define MAX_CPUS 2
27
26/* Machine specific information */ 28/* Machine specific information */
27struct idle_statedata { 29struct idle_statedata {
28 u32 cpu_state; 30 u32 cpu_state;
@@ -48,11 +50,11 @@ static struct idle_statedata omap4_idle_data[] = {
48 }, 50 },
49}; 51};
50 52
51static struct powerdomain *mpu_pd, *cpu_pd[NR_CPUS]; 53static struct powerdomain *mpu_pd, *cpu_pd[MAX_CPUS];
52static struct clockdomain *cpu_clkdm[NR_CPUS]; 54static struct clockdomain *cpu_clkdm[MAX_CPUS];
53 55
54static atomic_t abort_barrier; 56static atomic_t abort_barrier;
55static bool cpu_done[NR_CPUS]; 57static bool cpu_done[MAX_CPUS];
56static struct idle_statedata *state_ptr = &omap4_idle_data[0]; 58static struct idle_statedata *state_ptr = &omap4_idle_data[0];
57 59
58/* Private functions */ 60/* Private functions */
diff --git a/arch/arm/mach-omap2/dpll3xxx.c b/arch/arm/mach-omap2/dpll3xxx.c
index 3185ced807c9..3c418ea54bbe 100644
--- a/arch/arm/mach-omap2/dpll3xxx.c
+++ b/arch/arm/mach-omap2/dpll3xxx.c
@@ -623,6 +623,32 @@ void omap3_dpll_deny_idle(struct clk_hw_omap *clk)
623 623
624/* Clock control for DPLL outputs */ 624/* Clock control for DPLL outputs */
625 625
626/* Find the parent DPLL for the given clkoutx2 clock */
627static struct clk_hw_omap *omap3_find_clkoutx2_dpll(struct clk_hw *hw)
628{
629 struct clk_hw_omap *pclk = NULL;
630 struct clk *parent;
631
632 /* Walk up the parents of clk, looking for a DPLL */
633 do {
634 do {
635 parent = __clk_get_parent(hw->clk);
636 hw = __clk_get_hw(parent);
637 } while (hw && (__clk_get_flags(hw->clk) & CLK_IS_BASIC));
638 if (!hw)
639 break;
640 pclk = to_clk_hw_omap(hw);
641 } while (pclk && !pclk->dpll_data);
642
643 /* clk does not have a DPLL as a parent? error in the clock data */
644 if (!pclk) {
645 WARN_ON(1);
646 return NULL;
647 }
648
649 return pclk;
650}
651
626/** 652/**
627 * omap3_clkoutx2_recalc - recalculate DPLL X2 output virtual clock rate 653 * omap3_clkoutx2_recalc - recalculate DPLL X2 output virtual clock rate
628 * @clk: DPLL output struct clk 654 * @clk: DPLL output struct clk
@@ -637,27 +663,14 @@ unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
637 unsigned long rate; 663 unsigned long rate;
638 u32 v; 664 u32 v;
639 struct clk_hw_omap *pclk = NULL; 665 struct clk_hw_omap *pclk = NULL;
640 struct clk *parent;
641 666
642 if (!parent_rate) 667 if (!parent_rate)
643 return 0; 668 return 0;
644 669
645 /* Walk up the parents of clk, looking for a DPLL */ 670 pclk = omap3_find_clkoutx2_dpll(hw);
646 do {
647 do {
648 parent = __clk_get_parent(hw->clk);
649 hw = __clk_get_hw(parent);
650 } while (hw && (__clk_get_flags(hw->clk) & CLK_IS_BASIC));
651 if (!hw)
652 break;
653 pclk = to_clk_hw_omap(hw);
654 } while (pclk && !pclk->dpll_data);
655 671
656 /* clk does not have a DPLL as a parent? error in the clock data */ 672 if (!pclk)
657 if (!pclk) {
658 WARN_ON(1);
659 return 0; 673 return 0;
660 }
661 674
662 dd = pclk->dpll_data; 675 dd = pclk->dpll_data;
663 676
@@ -672,6 +685,55 @@ unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
672 return rate; 685 return rate;
673} 686}
674 687
688int omap3_clkoutx2_set_rate(struct clk_hw *hw, unsigned long rate,
689 unsigned long parent_rate)
690{
691 return 0;
692}
693
694long omap3_clkoutx2_round_rate(struct clk_hw *hw, unsigned long rate,
695 unsigned long *prate)
696{
697 const struct dpll_data *dd;
698 u32 v;
699 struct clk_hw_omap *pclk = NULL;
700
701 if (!*prate)
702 return 0;
703
704 pclk = omap3_find_clkoutx2_dpll(hw);
705
706 if (!pclk)
707 return 0;
708
709 dd = pclk->dpll_data;
710
711 /* TYPE J does not have a clkoutx2 */
712 if (dd->flags & DPLL_J_TYPE) {
713 *prate = __clk_round_rate(__clk_get_parent(pclk->hw.clk), rate);
714 return *prate;
715 }
716
717 WARN_ON(!dd->enable_mask);
718
719 v = omap2_clk_readl(pclk, dd->control_reg) & dd->enable_mask;
720 v >>= __ffs(dd->enable_mask);
721
722 /* If in bypass, the rate is fixed to the bypass rate*/
723 if (v != OMAP3XXX_EN_DPLL_LOCKED)
724 return *prate;
725
726 if (__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT) {
727 unsigned long best_parent;
728
729 best_parent = (rate / 2);
730 *prate = __clk_round_rate(__clk_get_parent(hw->clk),
731 best_parent);
732 }
733
734 return *prate * 2;
735}
736
675/* OMAP3/4 non-CORE DPLL clkops */ 737/* OMAP3/4 non-CORE DPLL clkops */
676const struct clk_hw_omap_ops clkhwops_omap3_dpll = { 738const struct clk_hw_omap_ops clkhwops_omap3_dpll = {
677 .allow_idle = omap3_dpll_allow_idle, 739 .allow_idle = omap3_dpll_allow_idle,
diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
index d24926e6340f..ab43755364f5 100644
--- a/arch/arm/mach-omap2/gpmc.c
+++ b/arch/arm/mach-omap2/gpmc.c
@@ -1339,7 +1339,7 @@ static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
1339 of_property_read_bool(np, "gpmc,time-para-granularity"); 1339 of_property_read_bool(np, "gpmc,time-para-granularity");
1340} 1340}
1341 1341
1342#ifdef CONFIG_MTD_NAND 1342#if IS_ENABLED(CONFIG_MTD_NAND)
1343 1343
1344static const char * const nand_xfer_types[] = { 1344static const char * const nand_xfer_types[] = {
1345 [NAND_OMAP_PREFETCH_POLLED] = "prefetch-polled", 1345 [NAND_OMAP_PREFETCH_POLLED] = "prefetch-polled",
@@ -1429,7 +1429,7 @@ static int gpmc_probe_nand_child(struct platform_device *pdev,
1429} 1429}
1430#endif 1430#endif
1431 1431
1432#ifdef CONFIG_MTD_ONENAND 1432#if IS_ENABLED(CONFIG_MTD_ONENAND)
1433static int gpmc_probe_onenand_child(struct platform_device *pdev, 1433static int gpmc_probe_onenand_child(struct platform_device *pdev,
1434 struct device_node *child) 1434 struct device_node *child)
1435{ 1435{
diff --git a/arch/arm/mach-omap2/io.c b/arch/arm/mach-omap2/io.c
index d408b15b4fbf..af432b191255 100644
--- a/arch/arm/mach-omap2/io.c
+++ b/arch/arm/mach-omap2/io.c
@@ -179,15 +179,6 @@ static struct map_desc omap34xx_io_desc[] __initdata = {
179 .length = L4_EMU_34XX_SIZE, 179 .length = L4_EMU_34XX_SIZE,
180 .type = MT_DEVICE 180 .type = MT_DEVICE
181 }, 181 },
182#if defined(CONFIG_DEBUG_LL) && \
183 (defined(CONFIG_MACH_OMAP_ZOOM2) || defined(CONFIG_MACH_OMAP_ZOOM3))
184 {
185 .virtual = ZOOM_UART_VIRT,
186 .pfn = __phys_to_pfn(ZOOM_UART_BASE),
187 .length = SZ_1M,
188 .type = MT_DEVICE
189 },
190#endif
191}; 182};
192#endif 183#endif
193 184
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index 42d81885c700..1f33f5db10d5 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -1947,29 +1947,31 @@ static int _ocp_softreset(struct omap_hwmod *oh)
1947 goto dis_opt_clks; 1947 goto dis_opt_clks;
1948 1948
1949 _write_sysconfig(v, oh); 1949 _write_sysconfig(v, oh);
1950 ret = _clear_softreset(oh, &v);
1951 if (ret)
1952 goto dis_opt_clks;
1953
1954 _write_sysconfig(v, oh);
1955 1950
1956 if (oh->class->sysc->srst_udelay) 1951 if (oh->class->sysc->srst_udelay)
1957 udelay(oh->class->sysc->srst_udelay); 1952 udelay(oh->class->sysc->srst_udelay);
1958 1953
1959 c = _wait_softreset_complete(oh); 1954 c = _wait_softreset_complete(oh);
1960 if (c == MAX_MODULE_SOFTRESET_WAIT) 1955 if (c == MAX_MODULE_SOFTRESET_WAIT) {
1961 pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n", 1956 pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
1962 oh->name, MAX_MODULE_SOFTRESET_WAIT); 1957 oh->name, MAX_MODULE_SOFTRESET_WAIT);
1963 else 1958 ret = -ETIMEDOUT;
1959 goto dis_opt_clks;
1960 } else {
1964 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c); 1961 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
1962 }
1963
1964 ret = _clear_softreset(oh, &v);
1965 if (ret)
1966 goto dis_opt_clks;
1967
1968 _write_sysconfig(v, oh);
1965 1969
1966 /* 1970 /*
1967 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from 1971 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
1968 * _wait_target_ready() or _reset() 1972 * _wait_target_ready() or _reset()
1969 */ 1973 */
1970 1974
1971 ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
1972
1973dis_opt_clks: 1975dis_opt_clks:
1974 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET) 1976 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1975 _disable_optional_clocks(oh); 1977 _disable_optional_clocks(oh);
diff --git a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
index 18f333c440db..810c205d668b 100644
--- a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
@@ -1365,11 +1365,10 @@ static struct omap_hwmod_class_sysconfig dra7xx_spinlock_sysc = {
1365 .rev_offs = 0x0000, 1365 .rev_offs = 0x0000,
1366 .sysc_offs = 0x0010, 1366 .sysc_offs = 0x0010,
1367 .syss_offs = 0x0014, 1367 .syss_offs = 0x0014,
1368 .sysc_flags = (SYSC_HAS_AUTOIDLE | SYSC_HAS_CLOCKACTIVITY | 1368 .sysc_flags = (SYSC_HAS_AUTOIDLE | SYSC_HAS_ENAWAKEUP |
1369 SYSC_HAS_ENAWAKEUP | SYSC_HAS_SIDLEMODE | 1369 SYSC_HAS_SIDLEMODE | SYSC_HAS_SOFTRESET |
1370 SYSC_HAS_SOFTRESET | SYSS_HAS_RESET_STATUS), 1370 SYSS_HAS_RESET_STATUS),
1371 .idlemodes = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART | 1371 .idlemodes = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART),
1372 SIDLE_SMART_WKUP),
1373 .sysc_fields = &omap_hwmod_sysc_type1, 1372 .sysc_fields = &omap_hwmod_sysc_type1,
1374}; 1373};
1375 1374
diff --git a/arch/arm/mach-omap2/pdata-quirks.c b/arch/arm/mach-omap2/pdata-quirks.c
index 3d5b24dcd9a4..c33e07e2f0d4 100644
--- a/arch/arm/mach-omap2/pdata-quirks.c
+++ b/arch/arm/mach-omap2/pdata-quirks.c
@@ -22,6 +22,8 @@
22#include "common-board-devices.h" 22#include "common-board-devices.h"
23#include "dss-common.h" 23#include "dss-common.h"
24#include "control.h" 24#include "control.h"
25#include "omap-secure.h"
26#include "soc.h"
25 27
26struct pdata_init { 28struct pdata_init {
27 const char *compatible; 29 const char *compatible;
@@ -169,6 +171,22 @@ static void __init am3517_evm_legacy_init(void)
169 omap_ctrl_writel(v, AM35XX_CONTROL_IP_SW_RESET); 171 omap_ctrl_writel(v, AM35XX_CONTROL_IP_SW_RESET);
170 omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET); /* OCP barrier */ 172 omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET); /* OCP barrier */
171} 173}
174
175static void __init nokia_n900_legacy_init(void)
176{
177 hsmmc2_internal_input_clk();
178
179 if (omap_type() == OMAP2_DEVICE_TYPE_SEC) {
180 if (IS_ENABLED(CONFIG_ARM_ERRATA_430973)) {
181 pr_info("RX-51: Enabling ARM errata 430973 workaround\n");
182 /* set IBE to 1 */
183 rx51_secure_update_aux_cr(BIT(6), 0);
184 } else {
185 pr_warning("RX-51: Not enabling ARM errata 430973 workaround\n");
186 pr_warning("Thumb binaries may crash randomly without this workaround\n");
187 }
188 }
189}
172#endif /* CONFIG_ARCH_OMAP3 */ 190#endif /* CONFIG_ARCH_OMAP3 */
173 191
174#ifdef CONFIG_ARCH_OMAP4 192#ifdef CONFIG_ARCH_OMAP4
@@ -239,6 +257,7 @@ struct of_dev_auxdata omap_auxdata_lookup[] __initdata = {
239#endif 257#endif
240#ifdef CONFIG_ARCH_OMAP3 258#ifdef CONFIG_ARCH_OMAP3
241 OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002030, "48002030.pinmux", &pcs_pdata), 259 OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002030, "48002030.pinmux", &pcs_pdata),
260 OF_DEV_AUXDATA("ti,omap3-padconf", 0x480025a0, "480025a0.pinmux", &pcs_pdata),
242 OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002a00, "48002a00.pinmux", &pcs_pdata), 261 OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002a00, "48002a00.pinmux", &pcs_pdata),
243 /* Only on am3517 */ 262 /* Only on am3517 */
244 OF_DEV_AUXDATA("ti,davinci_mdio", 0x5c030000, "davinci_mdio.0", NULL), 263 OF_DEV_AUXDATA("ti,davinci_mdio", 0x5c030000, "davinci_mdio.0", NULL),
@@ -259,7 +278,7 @@ struct of_dev_auxdata omap_auxdata_lookup[] __initdata = {
259static struct pdata_init pdata_quirks[] __initdata = { 278static struct pdata_init pdata_quirks[] __initdata = {
260#ifdef CONFIG_ARCH_OMAP3 279#ifdef CONFIG_ARCH_OMAP3
261 { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_legacy_init, }, 280 { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_legacy_init, },
262 { "nokia,omap3-n900", hsmmc2_internal_input_clk, }, 281 { "nokia,omap3-n900", nokia_n900_legacy_init, },
263 { "nokia,omap3-n9", hsmmc2_internal_input_clk, }, 282 { "nokia,omap3-n9", hsmmc2_internal_input_clk, },
264 { "nokia,omap3-n950", hsmmc2_internal_input_clk, }, 283 { "nokia,omap3-n950", hsmmc2_internal_input_clk, },
265 { "isee,omap3-igep0020", omap3_igep0020_legacy_init, }, 284 { "isee,omap3-igep0020", omap3_igep0020_legacy_init, },
diff --git a/arch/arm/mach-omap2/prminst44xx.c b/arch/arm/mach-omap2/prminst44xx.c
index 6334b96b4097..280f3c58abe5 100644
--- a/arch/arm/mach-omap2/prminst44xx.c
+++ b/arch/arm/mach-omap2/prminst44xx.c
@@ -183,11 +183,11 @@ void omap4_prminst_global_warm_sw_reset(void)
183 OMAP4_PRM_RSTCTRL_OFFSET); 183 OMAP4_PRM_RSTCTRL_OFFSET);
184 v |= OMAP4430_RST_GLOBAL_WARM_SW_MASK; 184 v |= OMAP4430_RST_GLOBAL_WARM_SW_MASK;
185 omap4_prminst_write_inst_reg(v, OMAP4430_PRM_PARTITION, 185 omap4_prminst_write_inst_reg(v, OMAP4430_PRM_PARTITION,
186 OMAP4430_PRM_DEVICE_INST, 186 dev_inst,
187 OMAP4_PRM_RSTCTRL_OFFSET); 187 OMAP4_PRM_RSTCTRL_OFFSET);
188 188
189 /* OCP barrier */ 189 /* OCP barrier */
190 v = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION, 190 v = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
191 OMAP4430_PRM_DEVICE_INST, 191 dev_inst,
192 OMAP4_PRM_RSTCTRL_OFFSET); 192 OMAP4_PRM_RSTCTRL_OFFSET);
193} 193}
diff --git a/arch/arm/mach-pxa/am300epd.c b/arch/arm/mach-pxa/am300epd.c
index c9f309ae88c5..8b90c4f2d430 100644
--- a/arch/arm/mach-pxa/am300epd.c
+++ b/arch/arm/mach-pxa/am300epd.c
@@ -30,6 +30,7 @@
30 30
31#include <mach/gumstix.h> 31#include <mach/gumstix.h>
32#include <mach/mfp-pxa25x.h> 32#include <mach/mfp-pxa25x.h>
33#include <mach/irqs.h>
33#include <linux/platform_data/video-pxafb.h> 34#include <linux/platform_data/video-pxafb.h>
34 35
35#include "generic.h" 36#include "generic.h"
diff --git a/arch/arm/mach-pxa/include/mach/balloon3.h b/arch/arm/mach-pxa/include/mach/balloon3.h
index 954641e6c8b1..1b0825911e62 100644
--- a/arch/arm/mach-pxa/include/mach/balloon3.h
+++ b/arch/arm/mach-pxa/include/mach/balloon3.h
@@ -14,6 +14,8 @@
14#ifndef ASM_ARCH_BALLOON3_H 14#ifndef ASM_ARCH_BALLOON3_H
15#define ASM_ARCH_BALLOON3_H 15#define ASM_ARCH_BALLOON3_H
16 16
17#include "irqs.h" /* PXA_NR_BUILTIN_GPIO */
18
17enum balloon3_features { 19enum balloon3_features {
18 BALLOON3_FEATURE_OHCI, 20 BALLOON3_FEATURE_OHCI,
19 BALLOON3_FEATURE_MMC, 21 BALLOON3_FEATURE_MMC,
diff --git a/arch/arm/mach-pxa/include/mach/corgi.h b/arch/arm/mach-pxa/include/mach/corgi.h
index f3c3493b468d..c030d955bbd7 100644
--- a/arch/arm/mach-pxa/include/mach/corgi.h
+++ b/arch/arm/mach-pxa/include/mach/corgi.h
@@ -13,6 +13,7 @@
13#ifndef __ASM_ARCH_CORGI_H 13#ifndef __ASM_ARCH_CORGI_H
14#define __ASM_ARCH_CORGI_H 1 14#define __ASM_ARCH_CORGI_H 1
15 15
16#include "irqs.h" /* PXA_NR_BUILTIN_GPIO */
16 17
17/* 18/*
18 * Corgi (Non Standard) GPIO Definitions 19 * Corgi (Non Standard) GPIO Definitions
diff --git a/arch/arm/mach-pxa/include/mach/csb726.h b/arch/arm/mach-pxa/include/mach/csb726.h
index 2628e7b72116..00cfbbbf73f7 100644
--- a/arch/arm/mach-pxa/include/mach/csb726.h
+++ b/arch/arm/mach-pxa/include/mach/csb726.h
@@ -11,6 +11,8 @@
11#ifndef CSB726_H 11#ifndef CSB726_H
12#define CSB726_H 12#define CSB726_H
13 13
14#include "irqs.h" /* PXA_GPIO_TO_IRQ */
15
14#define CSB726_GPIO_IRQ_LAN 52 16#define CSB726_GPIO_IRQ_LAN 52
15#define CSB726_GPIO_IRQ_SM501 53 17#define CSB726_GPIO_IRQ_SM501 53
16#define CSB726_GPIO_MMC_DETECT 100 18#define CSB726_GPIO_MMC_DETECT 100
diff --git a/arch/arm/mach-pxa/include/mach/gumstix.h b/arch/arm/mach-pxa/include/mach/gumstix.h
index dba14b6503ad..f7df27bbb42e 100644
--- a/arch/arm/mach-pxa/include/mach/gumstix.h
+++ b/arch/arm/mach-pxa/include/mach/gumstix.h
@@ -6,6 +6,7 @@
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 */ 7 */
8 8
9#include "irqs.h" /* PXA_GPIO_TO_IRQ */
9 10
10/* BTRESET - Reset line to Bluetooth module, active low signal. */ 11/* BTRESET - Reset line to Bluetooth module, active low signal. */
11#define GPIO_GUMSTIX_BTRESET 7 12#define GPIO_GUMSTIX_BTRESET 7
diff --git a/arch/arm/mach-pxa/include/mach/idp.h b/arch/arm/mach-pxa/include/mach/idp.h
index 22a96f87232b..7e63f4680271 100644
--- a/arch/arm/mach-pxa/include/mach/idp.h
+++ b/arch/arm/mach-pxa/include/mach/idp.h
@@ -23,6 +23,7 @@
23 * IDP hardware. 23 * IDP hardware.
24 */ 24 */
25 25
26#include "irqs.h" /* PXA_GPIO_TO_IRQ */
26 27
27#define IDP_FLASH_PHYS (PXA_CS0_PHYS) 28#define IDP_FLASH_PHYS (PXA_CS0_PHYS)
28#define IDP_ALT_FLASH_PHYS (PXA_CS1_PHYS) 29#define IDP_ALT_FLASH_PHYS (PXA_CS1_PHYS)
diff --git a/arch/arm/mach-pxa/include/mach/palmld.h b/arch/arm/mach-pxa/include/mach/palmld.h
index 2c4471336570..b184f296023b 100644
--- a/arch/arm/mach-pxa/include/mach/palmld.h
+++ b/arch/arm/mach-pxa/include/mach/palmld.h
@@ -13,6 +13,8 @@
13#ifndef _INCLUDE_PALMLD_H_ 13#ifndef _INCLUDE_PALMLD_H_
14#define _INCLUDE_PALMLD_H_ 14#define _INCLUDE_PALMLD_H_
15 15
16#include "irqs.h" /* PXA_GPIO_TO_IRQ */
17
16/** HERE ARE GPIOs **/ 18/** HERE ARE GPIOs **/
17 19
18/* GPIOs */ 20/* GPIOs */
diff --git a/arch/arm/mach-pxa/include/mach/palmt5.h b/arch/arm/mach-pxa/include/mach/palmt5.h
index 0bd4f036c72f..e342c5921405 100644
--- a/arch/arm/mach-pxa/include/mach/palmt5.h
+++ b/arch/arm/mach-pxa/include/mach/palmt5.h
@@ -15,6 +15,8 @@
15#ifndef _INCLUDE_PALMT5_H_ 15#ifndef _INCLUDE_PALMT5_H_
16#define _INCLUDE_PALMT5_H_ 16#define _INCLUDE_PALMT5_H_
17 17
18#include "irqs.h" /* PXA_GPIO_TO_IRQ */
19
18/** HERE ARE GPIOs **/ 20/** HERE ARE GPIOs **/
19 21
20/* GPIOs */ 22/* GPIOs */
diff --git a/arch/arm/mach-pxa/include/mach/palmtc.h b/arch/arm/mach-pxa/include/mach/palmtc.h
index c383a21680b6..81c727b3cfd2 100644
--- a/arch/arm/mach-pxa/include/mach/palmtc.h
+++ b/arch/arm/mach-pxa/include/mach/palmtc.h
@@ -16,6 +16,8 @@
16#ifndef _INCLUDE_PALMTC_H_ 16#ifndef _INCLUDE_PALMTC_H_
17#define _INCLUDE_PALMTC_H_ 17#define _INCLUDE_PALMTC_H_
18 18
19#include "irqs.h" /* PXA_GPIO_TO_IRQ */
20
19/** HERE ARE GPIOs **/ 21/** HERE ARE GPIOs **/
20 22
21/* GPIOs */ 23/* GPIOs */
diff --git a/arch/arm/mach-pxa/include/mach/palmtx.h b/arch/arm/mach-pxa/include/mach/palmtx.h
index f2e530380253..92bc1f05300d 100644
--- a/arch/arm/mach-pxa/include/mach/palmtx.h
+++ b/arch/arm/mach-pxa/include/mach/palmtx.h
@@ -16,6 +16,8 @@
16#ifndef _INCLUDE_PALMTX_H_ 16#ifndef _INCLUDE_PALMTX_H_
17#define _INCLUDE_PALMTX_H_ 17#define _INCLUDE_PALMTX_H_
18 18
19#include "irqs.h" /* PXA_GPIO_TO_IRQ */
20
19/** HERE ARE GPIOs **/ 21/** HERE ARE GPIOs **/
20 22
21/* GPIOs */ 23/* GPIOs */
diff --git a/arch/arm/mach-pxa/include/mach/pcm027.h b/arch/arm/mach-pxa/include/mach/pcm027.h
index 6bf28de228bd..86ebd7b6c960 100644
--- a/arch/arm/mach-pxa/include/mach/pcm027.h
+++ b/arch/arm/mach-pxa/include/mach/pcm027.h
@@ -23,6 +23,8 @@
23 * Definitions of CPU card resources only 23 * Definitions of CPU card resources only
24 */ 24 */
25 25
26#include "irqs.h" /* PXA_GPIO_TO_IRQ */
27
26/* phyCORE-PXA270 (PCM027) Interrupts */ 28/* phyCORE-PXA270 (PCM027) Interrupts */
27#define PCM027_IRQ(x) (IRQ_BOARD_START + (x)) 29#define PCM027_IRQ(x) (IRQ_BOARD_START + (x))
28#define PCM027_BTDET_IRQ PCM027_IRQ(0) 30#define PCM027_BTDET_IRQ PCM027_IRQ(0)
diff --git a/arch/arm/mach-pxa/include/mach/pcm990_baseboard.h b/arch/arm/mach-pxa/include/mach/pcm990_baseboard.h
index 0260aaa2fc17..7e544c14967e 100644
--- a/arch/arm/mach-pxa/include/mach/pcm990_baseboard.h
+++ b/arch/arm/mach-pxa/include/mach/pcm990_baseboard.h
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include <mach/pcm027.h> 22#include <mach/pcm027.h>
23#include "irqs.h" /* PXA_GPIO_TO_IRQ */
23 24
24/* 25/*
25 * definitions relevant only when the PCM-990 26 * definitions relevant only when the PCM-990
diff --git a/arch/arm/mach-pxa/include/mach/poodle.h b/arch/arm/mach-pxa/include/mach/poodle.h
index f32ff75dcca8..b56b19351a03 100644
--- a/arch/arm/mach-pxa/include/mach/poodle.h
+++ b/arch/arm/mach-pxa/include/mach/poodle.h
@@ -15,6 +15,8 @@
15#ifndef __ASM_ARCH_POODLE_H 15#ifndef __ASM_ARCH_POODLE_H
16#define __ASM_ARCH_POODLE_H 1 16#define __ASM_ARCH_POODLE_H 1
17 17
18#include "irqs.h" /* PXA_GPIO_TO_IRQ */
19
18/* 20/*
19 * GPIOs 21 * GPIOs
20 */ 22 */
diff --git a/arch/arm/mach-pxa/include/mach/spitz.h b/arch/arm/mach-pxa/include/mach/spitz.h
index 0bfe6507c95d..25c9f62e46aa 100644
--- a/arch/arm/mach-pxa/include/mach/spitz.h
+++ b/arch/arm/mach-pxa/include/mach/spitz.h
@@ -15,8 +15,8 @@
15#define __ASM_ARCH_SPITZ_H 1 15#define __ASM_ARCH_SPITZ_H 1
16#endif 16#endif
17 17
18#include "irqs.h" /* PXA_NR_BUILTIN_GPIO, PXA_GPIO_TO_IRQ */
18#include <linux/fb.h> 19#include <linux/fb.h>
19#include <linux/gpio.h>
20 20
21/* Spitz/Akita GPIOs */ 21/* Spitz/Akita GPIOs */
22 22
diff --git a/arch/arm/mach-pxa/include/mach/tosa.h b/arch/arm/mach-pxa/include/mach/tosa.h
index 2bb0e862598c..0497d95cef25 100644
--- a/arch/arm/mach-pxa/include/mach/tosa.h
+++ b/arch/arm/mach-pxa/include/mach/tosa.h
@@ -13,6 +13,8 @@
13#ifndef _ASM_ARCH_TOSA_H_ 13#ifndef _ASM_ARCH_TOSA_H_
14#define _ASM_ARCH_TOSA_H_ 1 14#define _ASM_ARCH_TOSA_H_ 1
15 15
16#include "irqs.h" /* PXA_NR_BUILTIN_GPIO */
17
16/* TOSA Chip selects */ 18/* TOSA Chip selects */
17#define TOSA_LCDC_PHYS PXA_CS4_PHYS 19#define TOSA_LCDC_PHYS PXA_CS4_PHYS
18/* Internel Scoop */ 20/* Internel Scoop */
diff --git a/arch/arm/mach-pxa/include/mach/trizeps4.h b/arch/arm/mach-pxa/include/mach/trizeps4.h
index d2ca01053f69..ae3ca013afab 100644
--- a/arch/arm/mach-pxa/include/mach/trizeps4.h
+++ b/arch/arm/mach-pxa/include/mach/trizeps4.h
@@ -10,6 +10,8 @@
10#ifndef _TRIPEPS4_H_ 10#ifndef _TRIPEPS4_H_
11#define _TRIPEPS4_H_ 11#define _TRIPEPS4_H_
12 12
13#include "irqs.h" /* PXA_GPIO_TO_IRQ */
14
13/* physical memory regions */ 15/* physical memory regions */
14#define TRIZEPS4_FLASH_PHYS (PXA_CS0_PHYS) /* Flash region */ 16#define TRIZEPS4_FLASH_PHYS (PXA_CS0_PHYS) /* Flash region */
15#define TRIZEPS4_DISK_PHYS (PXA_CS1_PHYS) /* Disk On Chip region */ 17#define TRIZEPS4_DISK_PHYS (PXA_CS1_PHYS) /* Disk On Chip region */
diff --git a/arch/arm/mach-pxa/mioa701.c b/arch/arm/mach-pxa/mioa701.c
index f70583fee59f..29997bde277d 100644
--- a/arch/arm/mach-pxa/mioa701.c
+++ b/arch/arm/mach-pxa/mioa701.c
@@ -38,6 +38,7 @@
38#include <linux/mtd/physmap.h> 38#include <linux/mtd/physmap.h>
39#include <linux/usb/gpio_vbus.h> 39#include <linux/usb/gpio_vbus.h>
40#include <linux/reboot.h> 40#include <linux/reboot.h>
41#include <linux/regulator/fixed.h>
41#include <linux/regulator/max1586.h> 42#include <linux/regulator/max1586.h>
42#include <linux/slab.h> 43#include <linux/slab.h>
43#include <linux/i2c/pxa-i2c.h> 44#include <linux/i2c/pxa-i2c.h>
@@ -714,6 +715,10 @@ static struct gpio global_gpios[] = {
714 { GPIO56_MT9M111_nOE, GPIOF_OUT_INIT_LOW, "Camera nOE" }, 715 { GPIO56_MT9M111_nOE, GPIOF_OUT_INIT_LOW, "Camera nOE" },
715}; 716};
716 717
718static struct regulator_consumer_supply fixed_5v0_consumers[] = {
719 REGULATOR_SUPPLY("power", "pwm-backlight"),
720};
721
717static void __init mioa701_machine_init(void) 722static void __init mioa701_machine_init(void)
718{ 723{
719 int rc; 724 int rc;
@@ -753,6 +758,10 @@ static void __init mioa701_machine_init(void)
753 pxa_set_i2c_info(&i2c_pdata); 758 pxa_set_i2c_info(&i2c_pdata);
754 pxa27x_set_i2c_power_info(NULL); 759 pxa27x_set_i2c_power_info(NULL);
755 pxa_set_camera_info(&mioa701_pxacamera_platform_data); 760 pxa_set_camera_info(&mioa701_pxacamera_platform_data);
761
762 regulator_register_always_on(0, "fixed-5.0V", fixed_5v0_consumers,
763 ARRAY_SIZE(fixed_5v0_consumers),
764 5000000);
756} 765}
757 766
758static void mioa701_machine_exit(void) 767static void mioa701_machine_exit(void)
diff --git a/arch/arm/mach-sa1100/include/mach/collie.h b/arch/arm/mach-sa1100/include/mach/collie.h
index f33679d2d3ee..50e1d850ee2e 100644
--- a/arch/arm/mach-sa1100/include/mach/collie.h
+++ b/arch/arm/mach-sa1100/include/mach/collie.h
@@ -13,6 +13,8 @@
13#ifndef __ASM_ARCH_COLLIE_H 13#ifndef __ASM_ARCH_COLLIE_H
14#define __ASM_ARCH_COLLIE_H 14#define __ASM_ARCH_COLLIE_H
15 15
16#include "hardware.h" /* Gives GPIO_MAX */
17
16extern void locomolcd_power(int on); 18extern void locomolcd_power(int on);
17 19
18#define COLLIE_SCOOP_GPIO_BASE (GPIO_MAX + 1) 20#define COLLIE_SCOOP_GPIO_BASE (GPIO_MAX + 1)
diff --git a/arch/arm/mach-shmobile/Kconfig b/arch/arm/mach-shmobile/Kconfig
index 338640631e08..05fa505df585 100644
--- a/arch/arm/mach-shmobile/Kconfig
+++ b/arch/arm/mach-shmobile/Kconfig
@@ -8,7 +8,7 @@ config ARCH_SHMOBILE_MULTI
8 select CPU_V7 8 select CPU_V7
9 select GENERIC_CLOCKEVENTS 9 select GENERIC_CLOCKEVENTS
10 select HAVE_ARM_SCU if SMP 10 select HAVE_ARM_SCU if SMP
11 select HAVE_ARM_TWD if LOCAL_TIMERS 11 select HAVE_ARM_TWD if SMP
12 select HAVE_SMP 12 select HAVE_SMP
13 select ARM_GIC 13 select ARM_GIC
14 select MIGHT_HAVE_CACHE_L2X0 14 select MIGHT_HAVE_CACHE_L2X0
diff --git a/arch/arm/mach-tegra/pm.c b/arch/arm/mach-tegra/pm.c
index 4ae0286b468d..f55b05a29b55 100644
--- a/arch/arm/mach-tegra/pm.c
+++ b/arch/arm/mach-tegra/pm.c
@@ -24,6 +24,7 @@
24#include <linux/cpu_pm.h> 24#include <linux/cpu_pm.h>
25#include <linux/suspend.h> 25#include <linux/suspend.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/slab.h>
27#include <linux/clk/tegra.h> 28#include <linux/clk/tegra.h>
28 29
29#include <asm/smp_plat.h> 30#include <asm/smp_plat.h>
diff --git a/arch/arm/mach-tegra/tegra.c b/arch/arm/mach-tegra/tegra.c
index 303a285d80fd..6191603379e1 100644
--- a/arch/arm/mach-tegra/tegra.c
+++ b/arch/arm/mach-tegra/tegra.c
@@ -73,10 +73,20 @@ u32 tegra_uart_config[3] = {
73static void __init tegra_init_cache(void) 73static void __init tegra_init_cache(void)
74{ 74{
75#ifdef CONFIG_CACHE_L2X0 75#ifdef CONFIG_CACHE_L2X0
76 static const struct of_device_id pl310_ids[] __initconst = {
77 { .compatible = "arm,pl310-cache", },
78 {}
79 };
80
81 struct device_node *np;
76 int ret; 82 int ret;
77 void __iomem *p = IO_ADDRESS(TEGRA_ARM_PERIF_BASE) + 0x3000; 83 void __iomem *p = IO_ADDRESS(TEGRA_ARM_PERIF_BASE) + 0x3000;
78 u32 aux_ctrl, cache_type; 84 u32 aux_ctrl, cache_type;
79 85
86 np = of_find_matching_node(NULL, pl310_ids);
87 if (!np)
88 return;
89
80 cache_type = readl(p + L2X0_CACHE_TYPE); 90 cache_type = readl(p + L2X0_CACHE_TYPE);
81 aux_ctrl = (cache_type & 0x700) << (17-8); 91 aux_ctrl = (cache_type & 0x700) << (17-8);
82 aux_ctrl |= 0x7C400001; 92 aux_ctrl |= 0x7C400001;
diff --git a/arch/arm/mach-zynq/common.c b/arch/arm/mach-zynq/common.c
index 1db2a5ca9ab8..8c09a8393fb6 100644
--- a/arch/arm/mach-zynq/common.c
+++ b/arch/arm/mach-zynq/common.c
@@ -25,6 +25,7 @@
25#include <linux/of_irq.h> 25#include <linux/of_irq.h>
26#include <linux/of_platform.h> 26#include <linux/of_platform.h>
27#include <linux/of.h> 27#include <linux/of.h>
28#include <linux/memblock.h>
28#include <linux/irqchip.h> 29#include <linux/irqchip.h>
29#include <linux/irqchip/arm-gic.h> 30#include <linux/irqchip/arm-gic.h>
30 31
@@ -41,6 +42,18 @@
41 42
42void __iomem *zynq_scu_base; 43void __iomem *zynq_scu_base;
43 44
45/**
46 * zynq_memory_init - Initialize special memory
47 *
48 * We need to stop things allocating the low memory as DMA can't work in
49 * the 1st 512K of memory.
50 */
51static void __init zynq_memory_init(void)
52{
53 if (!__pa(PAGE_OFFSET))
54 memblock_reserve(__pa(PAGE_OFFSET), __pa(swapper_pg_dir));
55}
56
44static struct platform_device zynq_cpuidle_device = { 57static struct platform_device zynq_cpuidle_device = {
45 .name = "cpuidle-zynq", 58 .name = "cpuidle-zynq",
46}; 59};
@@ -117,5 +130,6 @@ DT_MACHINE_START(XILINX_EP107, "Xilinx Zynq Platform")
117 .init_machine = zynq_init_machine, 130 .init_machine = zynq_init_machine,
118 .init_time = zynq_timer_init, 131 .init_time = zynq_timer_init,
119 .dt_compat = zynq_dt_match, 132 .dt_compat = zynq_dt_match,
133 .reserve = zynq_memory_init,
120 .restart = zynq_system_reset, 134 .restart = zynq_system_reset,
121MACHINE_END 135MACHINE_END
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 1a77450e728a..11b3914660d2 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1358,7 +1358,7 @@ static void *arm_iommu_alloc_attrs(struct device *dev, size_t size,
1358 *handle = DMA_ERROR_CODE; 1358 *handle = DMA_ERROR_CODE;
1359 size = PAGE_ALIGN(size); 1359 size = PAGE_ALIGN(size);
1360 1360
1361 if (gfp & GFP_ATOMIC) 1361 if (!(gfp & __GFP_WAIT))
1362 return __iommu_alloc_atomic(dev, size, handle); 1362 return __iommu_alloc_atomic(dev, size, handle);
1363 1363
1364 /* 1364 /*
diff --git a/arch/arm/mm/dump.c b/arch/arm/mm/dump.c
index 2b3a56414271..ef69152f9b52 100644
--- a/arch/arm/mm/dump.c
+++ b/arch/arm/mm/dump.c
@@ -264,6 +264,9 @@ static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start)
264 note_page(st, addr, 3, pmd_val(*pmd)); 264 note_page(st, addr, 3, pmd_val(*pmd));
265 else 265 else
266 walk_pte(st, pmd, addr); 266 walk_pte(st, pmd, addr);
267
268 if (SECTION_SIZE < PMD_SIZE && pmd_large(pmd[1]))
269 note_page(st, addr + SECTION_SIZE, 3, pmd_val(pmd[1]));
267 } 270 }
268} 271}
269 272
diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h
index d5a982d15a88..7ea641b7aa7d 100644
--- a/arch/arm/mm/mm.h
+++ b/arch/arm/mm/mm.h
@@ -38,6 +38,7 @@ static inline pmd_t *pmd_off_k(unsigned long virt)
38 38
39struct mem_type { 39struct mem_type {
40 pteval_t prot_pte; 40 pteval_t prot_pte;
41 pteval_t prot_pte_s2;
41 pmdval_t prot_l1; 42 pmdval_t prot_l1;
42 pmdval_t prot_sect; 43 pmdval_t prot_sect;
43 unsigned int domain; 44 unsigned int domain;
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index 4f08c133cc25..a623cb3ad012 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -232,12 +232,16 @@ __setup("noalign", noalign_setup);
232#endif /* ifdef CONFIG_CPU_CP15 / else */ 232#endif /* ifdef CONFIG_CPU_CP15 / else */
233 233
234#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN 234#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
235#define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
235#define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE 236#define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
236 237
237static struct mem_type mem_types[] = { 238static struct mem_type mem_types[] = {
238 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */ 239 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
239 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED | 240 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
240 L_PTE_SHARED, 241 L_PTE_SHARED,
242 .prot_pte_s2 = s2_policy(PROT_PTE_S2_DEVICE) |
243 s2_policy(L_PTE_S2_MT_DEV_SHARED) |
244 L_PTE_SHARED,
241 .prot_l1 = PMD_TYPE_TABLE, 245 .prot_l1 = PMD_TYPE_TABLE,
242 .prot_sect = PROT_SECT_DEVICE | PMD_SECT_S, 246 .prot_sect = PROT_SECT_DEVICE | PMD_SECT_S,
243 .domain = DOMAIN_IO, 247 .domain = DOMAIN_IO,
@@ -508,7 +512,8 @@ static void __init build_mem_type_table(void)
508 cp = &cache_policies[cachepolicy]; 512 cp = &cache_policies[cachepolicy];
509 vecs_pgprot = kern_pgprot = user_pgprot = cp->pte; 513 vecs_pgprot = kern_pgprot = user_pgprot = cp->pte;
510 s2_pgprot = cp->pte_s2; 514 s2_pgprot = cp->pte_s2;
511 hyp_device_pgprot = s2_device_pgprot = mem_types[MT_DEVICE].prot_pte; 515 hyp_device_pgprot = mem_types[MT_DEVICE].prot_pte;
516 s2_device_pgprot = mem_types[MT_DEVICE].prot_pte_s2;
512 517
513 /* 518 /*
514 * ARMv6 and above have extended page tables. 519 * ARMv6 and above have extended page tables.
diff --git a/arch/arm/mm/proc-v6.S b/arch/arm/mm/proc-v6.S
index 45dc29f85d56..32b3558321c4 100644
--- a/arch/arm/mm/proc-v6.S
+++ b/arch/arm/mm/proc-v6.S
@@ -208,7 +208,6 @@ __v6_setup:
208 mcr p15, 0, r0, c7, c14, 0 @ clean+invalidate D cache 208 mcr p15, 0, r0, c7, c14, 0 @ clean+invalidate D cache
209 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache 209 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
210 mcr p15, 0, r0, c7, c15, 0 @ clean+invalidate cache 210 mcr p15, 0, r0, c7, c15, 0 @ clean+invalidate cache
211 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
212#ifdef CONFIG_MMU 211#ifdef CONFIG_MMU
213 mcr p15, 0, r0, c8, c7, 0 @ invalidate I + D TLBs 212 mcr p15, 0, r0, c8, c7, 0 @ invalidate I + D TLBs
214 mcr p15, 0, r0, c2, c0, 2 @ TTB control register 213 mcr p15, 0, r0, c2, c0, 2 @ TTB control register
@@ -218,6 +217,8 @@ __v6_setup:
218 ALT_UP(orr r8, r8, #TTB_FLAGS_UP) 217 ALT_UP(orr r8, r8, #TTB_FLAGS_UP)
219 mcr p15, 0, r8, c2, c0, 1 @ load TTB1 218 mcr p15, 0, r8, c2, c0, 1 @ load TTB1
220#endif /* CONFIG_MMU */ 219#endif /* CONFIG_MMU */
220 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer and
221 @ complete invalidations
221 adr r5, v6_crval 222 adr r5, v6_crval
222 ldmia r5, {r5, r6} 223 ldmia r5, {r5, r6}
223 ARM_BE8(orr r6, r6, #1 << 25) @ big-endian page tables 224 ARM_BE8(orr r6, r6, #1 << 25) @ big-endian page tables
diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S
index bd1781979a39..74f6033e76dd 100644
--- a/arch/arm/mm/proc-v7.S
+++ b/arch/arm/mm/proc-v7.S
@@ -351,7 +351,6 @@ __v7_setup:
351 351
3524: mov r10, #0 3524: mov r10, #0
353 mcr p15, 0, r10, c7, c5, 0 @ I+BTB cache invalidate 353 mcr p15, 0, r10, c7, c5, 0 @ I+BTB cache invalidate
354 dsb
355#ifdef CONFIG_MMU 354#ifdef CONFIG_MMU
356 mcr p15, 0, r10, c8, c7, 0 @ invalidate I + D TLBs 355 mcr p15, 0, r10, c8, c7, 0 @ invalidate I + D TLBs
357 v7_ttb_setup r10, r4, r8, r5 @ TTBCR, TTBRx setup 356 v7_ttb_setup r10, r4, r8, r5 @ TTBCR, TTBRx setup
@@ -360,6 +359,7 @@ __v7_setup:
360 mcr p15, 0, r5, c10, c2, 0 @ write PRRR 359 mcr p15, 0, r5, c10, c2, 0 @ write PRRR
361 mcr p15, 0, r6, c10, c2, 1 @ write NMRR 360 mcr p15, 0, r6, c10, c2, 1 @ write NMRR
362#endif 361#endif
362 dsb @ Complete invalidations
363#ifndef CONFIG_ARM_THUMBEE 363#ifndef CONFIG_ARM_THUMBEE
364 mrc p15, 0, r0, c0, c1, 0 @ read ID_PFR0 for ThumbEE 364 mrc p15, 0, r0, c0, c1, 0 @ read ID_PFR0 for ThumbEE
365 and r0, r0, #(0xf << 12) @ ThumbEE enabled field 365 and r0, r0, #(0xf << 12) @ ThumbEE enabled field
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index dd4327f09ba4..516d8a7ca697 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -16,6 +16,7 @@ config ARM64
16 select DCACHE_WORD_ACCESS 16 select DCACHE_WORD_ACCESS
17 select GENERIC_CLOCKEVENTS 17 select GENERIC_CLOCKEVENTS
18 select GENERIC_CLOCKEVENTS_BROADCAST if SMP 18 select GENERIC_CLOCKEVENTS_BROADCAST if SMP
19 select GENERIC_CPU_AUTOPROBE
19 select GENERIC_IOMAP 20 select GENERIC_IOMAP
20 select GENERIC_IRQ_PROBE 21 select GENERIC_IRQ_PROBE
21 select GENERIC_IRQ_SHOW 22 select GENERIC_IRQ_SHOW
@@ -26,6 +27,7 @@ config ARM64
26 select GENERIC_TIME_VSYSCALL 27 select GENERIC_TIME_VSYSCALL
27 select HARDIRQS_SW_RESEND 28 select HARDIRQS_SW_RESEND
28 select HAVE_ARCH_JUMP_LABEL 29 select HAVE_ARCH_JUMP_LABEL
30 select HAVE_ARCH_KGDB
29 select HAVE_ARCH_TRACEHOOK 31 select HAVE_ARCH_TRACEHOOK
30 select HAVE_DEBUG_BUGVERBOSE 32 select HAVE_DEBUG_BUGVERBOSE
31 select HAVE_DEBUG_KMEMLEAK 33 select HAVE_DEBUG_KMEMLEAK
@@ -36,7 +38,10 @@ config ARM64
36 select HAVE_GENERIC_DMA_COHERENT 38 select HAVE_GENERIC_DMA_COHERENT
37 select HAVE_HW_BREAKPOINT if PERF_EVENTS 39 select HAVE_HW_BREAKPOINT if PERF_EVENTS
38 select HAVE_MEMBLOCK 40 select HAVE_MEMBLOCK
41 select HAVE_PATA_PLATFORM
39 select HAVE_PERF_EVENTS 42 select HAVE_PERF_EVENTS
43 select HAVE_PERF_REGS
44 select HAVE_PERF_USER_STACK_DUMP
40 select IRQ_DOMAIN 45 select IRQ_DOMAIN
41 select MODULES_USE_ELF_RELA 46 select MODULES_USE_ELF_RELA
42 select NO_BOOTMEM 47 select NO_BOOTMEM
@@ -72,7 +77,7 @@ config LOCKDEP_SUPPORT
72config TRACE_IRQFLAGS_SUPPORT 77config TRACE_IRQFLAGS_SUPPORT
73 def_bool y 78 def_bool y
74 79
75config RWSEM_GENERIC_SPINLOCK 80config RWSEM_XCHGADD_ALGORITHM
76 def_bool y 81 def_bool y
77 82
78config GENERIC_HWEIGHT 83config GENERIC_HWEIGHT
@@ -84,7 +89,7 @@ config GENERIC_CSUM
84config GENERIC_CALIBRATE_DELAY 89config GENERIC_CALIBRATE_DELAY
85 def_bool y 90 def_bool y
86 91
87config ZONE_DMA32 92config ZONE_DMA
88 def_bool y 93 def_bool y
89 94
90config ARCH_DMA_ADDR_T_64BIT 95config ARCH_DMA_ADDR_T_64BIT
@@ -163,6 +168,22 @@ config SMP
163 168
164 If you don't know what to do here, say N. 169 If you don't know what to do here, say N.
165 170
171config SCHED_MC
172 bool "Multi-core scheduler support"
173 depends on SMP
174 help
175 Multi-core scheduler support improves the CPU scheduler's decision
176 making when dealing with multi-core CPU chips at a cost of slightly
177 increased overhead in some places. If unsure say N here.
178
179config SCHED_SMT
180 bool "SMT scheduler support"
181 depends on SMP
182 help
183 Improves the CPU scheduler's decision making when dealing with
184 MultiThreading at a cost of slightly increased overhead in some
185 places. If unsure say N here.
186
166config NR_CPUS 187config NR_CPUS
167 int "Maximum number of CPUs (2-32)" 188 int "Maximum number of CPUs (2-32)"
168 range 2 32 189 range 2 32
@@ -300,6 +321,8 @@ menu "CPU Power Management"
300 321
301source "drivers/cpuidle/Kconfig" 322source "drivers/cpuidle/Kconfig"
302 323
324source "drivers/cpufreq/Kconfig"
325
303endmenu 326endmenu
304 327
305source "net/Kconfig" 328source "net/Kconfig"
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 84139be62ae6..7959dd0ca5d5 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -1,4 +1,3 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_LOCALVERSION_AUTO is not set 1# CONFIG_LOCALVERSION_AUTO is not set
3# CONFIG_SWAP is not set 2# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y 3CONFIG_SYSVIPC=y
@@ -19,6 +18,7 @@ CONFIG_BLK_DEV_INITRD=y
19CONFIG_KALLSYMS_ALL=y 18CONFIG_KALLSYMS_ALL=y
20# CONFIG_COMPAT_BRK is not set 19# CONFIG_COMPAT_BRK is not set
21CONFIG_PROFILING=y 20CONFIG_PROFILING=y
21CONFIG_JUMP_LABEL=y
22CONFIG_MODULES=y 22CONFIG_MODULES=y
23CONFIG_MODULE_UNLOAD=y 23CONFIG_MODULE_UNLOAD=y
24# CONFIG_BLK_DEV_BSG is not set 24# CONFIG_BLK_DEV_BSG is not set
@@ -27,6 +27,7 @@ CONFIG_ARCH_VEXPRESS=y
27CONFIG_ARCH_XGENE=y 27CONFIG_ARCH_XGENE=y
28CONFIG_SMP=y 28CONFIG_SMP=y
29CONFIG_PREEMPT=y 29CONFIG_PREEMPT=y
30CONFIG_CMA=y
30CONFIG_CMDLINE="console=ttyAMA0" 31CONFIG_CMDLINE="console=ttyAMA0"
31# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set 32# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
32CONFIG_COMPAT=y 33CONFIG_COMPAT=y
@@ -42,14 +43,17 @@ CONFIG_IP_PNP_BOOTP=y
42# CONFIG_WIRELESS is not set 43# CONFIG_WIRELESS is not set
43CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 44CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
44CONFIG_DEVTMPFS=y 45CONFIG_DEVTMPFS=y
45CONFIG_BLK_DEV=y 46CONFIG_DMA_CMA=y
46CONFIG_SCSI=y 47CONFIG_SCSI=y
47# CONFIG_SCSI_PROC_FS is not set 48# CONFIG_SCSI_PROC_FS is not set
48CONFIG_BLK_DEV_SD=y 49CONFIG_BLK_DEV_SD=y
49# CONFIG_SCSI_LOWLEVEL is not set 50# CONFIG_SCSI_LOWLEVEL is not set
51CONFIG_ATA=y
52CONFIG_PATA_PLATFORM=y
53CONFIG_PATA_OF_PLATFORM=y
50CONFIG_NETDEVICES=y 54CONFIG_NETDEVICES=y
51CONFIG_MII=y
52CONFIG_SMC91X=y 55CONFIG_SMC91X=y
56CONFIG_SMSC911X=y
53# CONFIG_WLAN is not set 57# CONFIG_WLAN is not set
54CONFIG_INPUT_EVDEV=y 58CONFIG_INPUT_EVDEV=y
55# CONFIG_SERIO_I8042 is not set 59# CONFIG_SERIO_I8042 is not set
@@ -62,13 +66,19 @@ CONFIG_SERIAL_AMBA_PL011=y
62CONFIG_SERIAL_AMBA_PL011_CONSOLE=y 66CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
63# CONFIG_HW_RANDOM is not set 67# CONFIG_HW_RANDOM is not set
64# CONFIG_HWMON is not set 68# CONFIG_HWMON is not set
69CONFIG_REGULATOR=y
70CONFIG_REGULATOR_FIXED_VOLTAGE=y
65CONFIG_FB=y 71CONFIG_FB=y
66# CONFIG_VGA_CONSOLE is not set 72# CONFIG_VGA_CONSOLE is not set
67CONFIG_FRAMEBUFFER_CONSOLE=y 73CONFIG_FRAMEBUFFER_CONSOLE=y
68CONFIG_LOGO=y 74CONFIG_LOGO=y
69# CONFIG_LOGO_LINUX_MONO is not set 75# CONFIG_LOGO_LINUX_MONO is not set
70# CONFIG_LOGO_LINUX_VGA16 is not set 76# CONFIG_LOGO_LINUX_VGA16 is not set
71# CONFIG_USB_SUPPORT is not set 77CONFIG_USB=y
78CONFIG_USB_ISP1760_HCD=y
79CONFIG_USB_STORAGE=y
80CONFIG_MMC=y
81CONFIG_MMC_ARMMMCI=y
72# CONFIG_IOMMU_SUPPORT is not set 82# CONFIG_IOMMU_SUPPORT is not set
73CONFIG_EXT2_FS=y 83CONFIG_EXT2_FS=y
74CONFIG_EXT3_FS=y 84CONFIG_EXT3_FS=y
diff --git a/arch/arm64/include/asm/Kbuild b/arch/arm64/include/asm/Kbuild
index 71c53ecfcc3a..4bca4923fc0b 100644
--- a/arch/arm64/include/asm/Kbuild
+++ b/arch/arm64/include/asm/Kbuild
@@ -12,6 +12,7 @@ generic-y += dma.h
12generic-y += emergency-restart.h 12generic-y += emergency-restart.h
13generic-y += errno.h 13generic-y += errno.h
14generic-y += ftrace.h 14generic-y += ftrace.h
15generic-y += hash.h
15generic-y += hw_irq.h 16generic-y += hw_irq.h
16generic-y += ioctl.h 17generic-y += ioctl.h
17generic-y += ioctls.h 18generic-y += ioctls.h
@@ -22,13 +23,16 @@ generic-y += kmap_types.h
22generic-y += kvm_para.h 23generic-y += kvm_para.h
23generic-y += local.h 24generic-y += local.h
24generic-y += local64.h 25generic-y += local64.h
26generic-y += mcs_spinlock.h
25generic-y += mman.h 27generic-y += mman.h
26generic-y += msgbuf.h 28generic-y += msgbuf.h
27generic-y += mutex.h 29generic-y += mutex.h
28generic-y += pci.h 30generic-y += pci.h
29generic-y += poll.h 31generic-y += poll.h
30generic-y += posix_types.h 32generic-y += posix_types.h
33generic-y += preempt.h
31generic-y += resource.h 34generic-y += resource.h
35generic-y += rwsem.h
32generic-y += scatterlist.h 36generic-y += scatterlist.h
33generic-y += sections.h 37generic-y += sections.h
34generic-y += segment.h 38generic-y += segment.h
@@ -38,8 +42,8 @@ generic-y += shmbuf.h
38generic-y += sizes.h 42generic-y += sizes.h
39generic-y += socket.h 43generic-y += socket.h
40generic-y += sockios.h 44generic-y += sockios.h
41generic-y += switch_to.h
42generic-y += swab.h 45generic-y += swab.h
46generic-y += switch_to.h
43generic-y += termbits.h 47generic-y += termbits.h
44generic-y += termios.h 48generic-y += termios.h
45generic-y += topology.h 49generic-y += topology.h
@@ -49,5 +53,3 @@ generic-y += unaligned.h
49generic-y += user.h 53generic-y += user.h
50generic-y += vga.h 54generic-y += vga.h
51generic-y += xor.h 55generic-y += xor.h
52generic-y += preempt.h
53generic-y += hash.h
diff --git a/arch/arm64/include/asm/atomic.h b/arch/arm64/include/asm/atomic.h
index 01de5aaa3edc..0237f0867e37 100644
--- a/arch/arm64/include/asm/atomic.h
+++ b/arch/arm64/include/asm/atomic.h
@@ -54,8 +54,7 @@ static inline void atomic_add(int i, atomic_t *v)
54" stxr %w1, %w0, %2\n" 54" stxr %w1, %w0, %2\n"
55" cbnz %w1, 1b" 55" cbnz %w1, 1b"
56 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) 56 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter)
57 : "Ir" (i) 57 : "Ir" (i));
58 : "cc");
59} 58}
60 59
61static inline int atomic_add_return(int i, atomic_t *v) 60static inline int atomic_add_return(int i, atomic_t *v)
@@ -64,14 +63,15 @@ static inline int atomic_add_return(int i, atomic_t *v)
64 int result; 63 int result;
65 64
66 asm volatile("// atomic_add_return\n" 65 asm volatile("// atomic_add_return\n"
67"1: ldaxr %w0, %2\n" 66"1: ldxr %w0, %2\n"
68" add %w0, %w0, %w3\n" 67" add %w0, %w0, %w3\n"
69" stlxr %w1, %w0, %2\n" 68" stlxr %w1, %w0, %2\n"
70" cbnz %w1, 1b" 69" cbnz %w1, 1b"
71 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) 70 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter)
72 : "Ir" (i) 71 : "Ir" (i)
73 : "cc", "memory"); 72 : "memory");
74 73
74 smp_mb();
75 return result; 75 return result;
76} 76}
77 77
@@ -86,8 +86,7 @@ static inline void atomic_sub(int i, atomic_t *v)
86" stxr %w1, %w0, %2\n" 86" stxr %w1, %w0, %2\n"
87" cbnz %w1, 1b" 87" cbnz %w1, 1b"
88 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) 88 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter)
89 : "Ir" (i) 89 : "Ir" (i));
90 : "cc");
91} 90}
92 91
93static inline int atomic_sub_return(int i, atomic_t *v) 92static inline int atomic_sub_return(int i, atomic_t *v)
@@ -96,14 +95,15 @@ static inline int atomic_sub_return(int i, atomic_t *v)
96 int result; 95 int result;
97 96
98 asm volatile("// atomic_sub_return\n" 97 asm volatile("// atomic_sub_return\n"
99"1: ldaxr %w0, %2\n" 98"1: ldxr %w0, %2\n"
100" sub %w0, %w0, %w3\n" 99" sub %w0, %w0, %w3\n"
101" stlxr %w1, %w0, %2\n" 100" stlxr %w1, %w0, %2\n"
102" cbnz %w1, 1b" 101" cbnz %w1, 1b"
103 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) 102 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter)
104 : "Ir" (i) 103 : "Ir" (i)
105 : "cc", "memory"); 104 : "memory");
106 105
106 smp_mb();
107 return result; 107 return result;
108} 108}
109 109
@@ -112,17 +112,20 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
112 unsigned long tmp; 112 unsigned long tmp;
113 int oldval; 113 int oldval;
114 114
115 smp_mb();
116
115 asm volatile("// atomic_cmpxchg\n" 117 asm volatile("// atomic_cmpxchg\n"
116"1: ldaxr %w1, %2\n" 118"1: ldxr %w1, %2\n"
117" cmp %w1, %w3\n" 119" cmp %w1, %w3\n"
118" b.ne 2f\n" 120" b.ne 2f\n"
119" stlxr %w0, %w4, %2\n" 121" stxr %w0, %w4, %2\n"
120" cbnz %w0, 1b\n" 122" cbnz %w0, 1b\n"
121"2:" 123"2:"
122 : "=&r" (tmp), "=&r" (oldval), "+Q" (ptr->counter) 124 : "=&r" (tmp), "=&r" (oldval), "+Q" (ptr->counter)
123 : "Ir" (old), "r" (new) 125 : "Ir" (old), "r" (new)
124 : "cc", "memory"); 126 : "cc");
125 127
128 smp_mb();
126 return oldval; 129 return oldval;
127} 130}
128 131
@@ -173,8 +176,7 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
173" stxr %w1, %0, %2\n" 176" stxr %w1, %0, %2\n"
174" cbnz %w1, 1b" 177" cbnz %w1, 1b"
175 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) 178 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter)
176 : "Ir" (i) 179 : "Ir" (i));
177 : "cc");
178} 180}
179 181
180static inline long atomic64_add_return(long i, atomic64_t *v) 182static inline long atomic64_add_return(long i, atomic64_t *v)
@@ -183,14 +185,15 @@ static inline long atomic64_add_return(long i, atomic64_t *v)
183 unsigned long tmp; 185 unsigned long tmp;
184 186
185 asm volatile("// atomic64_add_return\n" 187 asm volatile("// atomic64_add_return\n"
186"1: ldaxr %0, %2\n" 188"1: ldxr %0, %2\n"
187" add %0, %0, %3\n" 189" add %0, %0, %3\n"
188" stlxr %w1, %0, %2\n" 190" stlxr %w1, %0, %2\n"
189" cbnz %w1, 1b" 191" cbnz %w1, 1b"
190 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) 192 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter)
191 : "Ir" (i) 193 : "Ir" (i)
192 : "cc", "memory"); 194 : "memory");
193 195
196 smp_mb();
194 return result; 197 return result;
195} 198}
196 199
@@ -205,8 +208,7 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
205" stxr %w1, %0, %2\n" 208" stxr %w1, %0, %2\n"
206" cbnz %w1, 1b" 209" cbnz %w1, 1b"
207 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) 210 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter)
208 : "Ir" (i) 211 : "Ir" (i));
209 : "cc");
210} 212}
211 213
212static inline long atomic64_sub_return(long i, atomic64_t *v) 214static inline long atomic64_sub_return(long i, atomic64_t *v)
@@ -215,14 +217,15 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
215 unsigned long tmp; 217 unsigned long tmp;
216 218
217 asm volatile("// atomic64_sub_return\n" 219 asm volatile("// atomic64_sub_return\n"
218"1: ldaxr %0, %2\n" 220"1: ldxr %0, %2\n"
219" sub %0, %0, %3\n" 221" sub %0, %0, %3\n"
220" stlxr %w1, %0, %2\n" 222" stlxr %w1, %0, %2\n"
221" cbnz %w1, 1b" 223" cbnz %w1, 1b"
222 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) 224 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter)
223 : "Ir" (i) 225 : "Ir" (i)
224 : "cc", "memory"); 226 : "memory");
225 227
228 smp_mb();
226 return result; 229 return result;
227} 230}
228 231
@@ -231,17 +234,20 @@ static inline long atomic64_cmpxchg(atomic64_t *ptr, long old, long new)
231 long oldval; 234 long oldval;
232 unsigned long res; 235 unsigned long res;
233 236
237 smp_mb();
238
234 asm volatile("// atomic64_cmpxchg\n" 239 asm volatile("// atomic64_cmpxchg\n"
235"1: ldaxr %1, %2\n" 240"1: ldxr %1, %2\n"
236" cmp %1, %3\n" 241" cmp %1, %3\n"
237" b.ne 2f\n" 242" b.ne 2f\n"
238" stlxr %w0, %4, %2\n" 243" stxr %w0, %4, %2\n"
239" cbnz %w0, 1b\n" 244" cbnz %w0, 1b\n"
240"2:" 245"2:"
241 : "=&r" (res), "=&r" (oldval), "+Q" (ptr->counter) 246 : "=&r" (res), "=&r" (oldval), "+Q" (ptr->counter)
242 : "Ir" (old), "r" (new) 247 : "Ir" (old), "r" (new)
243 : "cc", "memory"); 248 : "cc");
244 249
250 smp_mb();
245 return oldval; 251 return oldval;
246} 252}
247 253
@@ -253,11 +259,12 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
253 unsigned long tmp; 259 unsigned long tmp;
254 260
255 asm volatile("// atomic64_dec_if_positive\n" 261 asm volatile("// atomic64_dec_if_positive\n"
256"1: ldaxr %0, %2\n" 262"1: ldxr %0, %2\n"
257" subs %0, %0, #1\n" 263" subs %0, %0, #1\n"
258" b.mi 2f\n" 264" b.mi 2f\n"
259" stlxr %w1, %0, %2\n" 265" stlxr %w1, %0, %2\n"
260" cbnz %w1, 1b\n" 266" cbnz %w1, 1b\n"
267" dmb ish\n"
261"2:" 268"2:"
262 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) 269 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter)
263 : 270 :
diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
index 78e20ba8806b..66eb7648043b 100644
--- a/arch/arm64/include/asm/barrier.h
+++ b/arch/arm64/include/asm/barrier.h
@@ -25,7 +25,8 @@
25#define wfi() asm volatile("wfi" : : : "memory") 25#define wfi() asm volatile("wfi" : : : "memory")
26 26
27#define isb() asm volatile("isb" : : : "memory") 27#define isb() asm volatile("isb" : : : "memory")
28#define dsb() asm volatile("dsb sy" : : : "memory") 28#define dmb(opt) asm volatile("dmb sy" : : : "memory")
29#define dsb(opt) asm volatile("dsb sy" : : : "memory")
29 30
30#define mb() dsb() 31#define mb() dsb()
31#define rmb() asm volatile("dsb ld" : : : "memory") 32#define rmb() asm volatile("dsb ld" : : : "memory")
diff --git a/arch/arm64/include/asm/cacheflush.h b/arch/arm64/include/asm/cacheflush.h
index fea9ee327206..4c60e64a801c 100644
--- a/arch/arm64/include/asm/cacheflush.h
+++ b/arch/arm64/include/asm/cacheflush.h
@@ -85,6 +85,13 @@ static inline void flush_cache_page(struct vm_area_struct *vma,
85} 85}
86 86
87/* 87/*
88 * Cache maintenance functions used by the DMA API. No to be used directly.
89 */
90extern void __dma_map_area(const void *, size_t, int);
91extern void __dma_unmap_area(const void *, size_t, int);
92extern void __dma_flush_range(const void *, const void *);
93
94/*
88 * Copy user data from/to a page which is mapped into a different 95 * Copy user data from/to a page which is mapped into a different
89 * processes address space. Really, we want to allow our "user 96 * processes address space. Really, we want to allow our "user
90 * space" model to handle this. 97 * space" model to handle this.
@@ -116,6 +123,7 @@ extern void flush_dcache_page(struct page *);
116static inline void __flush_icache_all(void) 123static inline void __flush_icache_all(void)
117{ 124{
118 asm("ic ialluis"); 125 asm("ic ialluis");
126 dsb();
119} 127}
120 128
121#define flush_dcache_mmap_lock(mapping) \ 129#define flush_dcache_mmap_lock(mapping) \
diff --git a/arch/arm64/include/asm/cmpxchg.h b/arch/arm64/include/asm/cmpxchg.h
index 56166d7f4a25..57c0fa7bf711 100644
--- a/arch/arm64/include/asm/cmpxchg.h
+++ b/arch/arm64/include/asm/cmpxchg.h
@@ -29,44 +29,45 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
29 switch (size) { 29 switch (size) {
30 case 1: 30 case 1:
31 asm volatile("// __xchg1\n" 31 asm volatile("// __xchg1\n"
32 "1: ldaxrb %w0, %2\n" 32 "1: ldxrb %w0, %2\n"
33 " stlxrb %w1, %w3, %2\n" 33 " stlxrb %w1, %w3, %2\n"
34 " cbnz %w1, 1b\n" 34 " cbnz %w1, 1b\n"
35 : "=&r" (ret), "=&r" (tmp), "+Q" (*(u8 *)ptr) 35 : "=&r" (ret), "=&r" (tmp), "+Q" (*(u8 *)ptr)
36 : "r" (x) 36 : "r" (x)
37 : "cc", "memory"); 37 : "memory");
38 break; 38 break;
39 case 2: 39 case 2:
40 asm volatile("// __xchg2\n" 40 asm volatile("// __xchg2\n"
41 "1: ldaxrh %w0, %2\n" 41 "1: ldxrh %w0, %2\n"
42 " stlxrh %w1, %w3, %2\n" 42 " stlxrh %w1, %w3, %2\n"
43 " cbnz %w1, 1b\n" 43 " cbnz %w1, 1b\n"
44 : "=&r" (ret), "=&r" (tmp), "+Q" (*(u16 *)ptr) 44 : "=&r" (ret), "=&r" (tmp), "+Q" (*(u16 *)ptr)
45 : "r" (x) 45 : "r" (x)
46 : "cc", "memory"); 46 : "memory");
47 break; 47 break;
48 case 4: 48 case 4:
49 asm volatile("// __xchg4\n" 49 asm volatile("// __xchg4\n"
50 "1: ldaxr %w0, %2\n" 50 "1: ldxr %w0, %2\n"
51 " stlxr %w1, %w3, %2\n" 51 " stlxr %w1, %w3, %2\n"
52 " cbnz %w1, 1b\n" 52 " cbnz %w1, 1b\n"
53 : "=&r" (ret), "=&r" (tmp), "+Q" (*(u32 *)ptr) 53 : "=&r" (ret), "=&r" (tmp), "+Q" (*(u32 *)ptr)
54 : "r" (x) 54 : "r" (x)
55 : "cc", "memory"); 55 : "memory");
56 break; 56 break;
57 case 8: 57 case 8:
58 asm volatile("// __xchg8\n" 58 asm volatile("// __xchg8\n"
59 "1: ldaxr %0, %2\n" 59 "1: ldxr %0, %2\n"
60 " stlxr %w1, %3, %2\n" 60 " stlxr %w1, %3, %2\n"
61 " cbnz %w1, 1b\n" 61 " cbnz %w1, 1b\n"
62 : "=&r" (ret), "=&r" (tmp), "+Q" (*(u64 *)ptr) 62 : "=&r" (ret), "=&r" (tmp), "+Q" (*(u64 *)ptr)
63 : "r" (x) 63 : "r" (x)
64 : "cc", "memory"); 64 : "memory");
65 break; 65 break;
66 default: 66 default:
67 BUILD_BUG(); 67 BUILD_BUG();
68 } 68 }
69 69
70 smp_mb();
70 return ret; 71 return ret;
71} 72}
72 73
diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index fda2704b3f9f..e71f81fe127a 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -228,7 +228,7 @@ static inline compat_uptr_t ptr_to_compat(void __user *uptr)
228 return (u32)(unsigned long)uptr; 228 return (u32)(unsigned long)uptr;
229} 229}
230 230
231#define compat_user_stack_pointer() (current_pt_regs()->compat_sp) 231#define compat_user_stack_pointer() (user_stack_pointer(current_pt_regs()))
232 232
233static inline void __user *arch_compat_alloc_user_space(long len) 233static inline void __user *arch_compat_alloc_user_space(long len)
234{ 234{
diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
new file mode 100644
index 000000000000..cd4ac0516488
--- /dev/null
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -0,0 +1,29 @@
1/*
2 * Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#ifndef __ASM_CPUFEATURE_H
10#define __ASM_CPUFEATURE_H
11
12#include <asm/hwcap.h>
13
14/*
15 * In the arm64 world (as in the ARM world), elf_hwcap is used both internally
16 * in the kernel and for user space to keep track of which optional features
17 * are supported by the current system. So let's map feature 'x' to HWCAP_x.
18 * Note that HWCAP_x constants are bit fields so we need to take the log.
19 */
20
21#define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap))
22#define cpu_feature(x) ilog2(HWCAP_ ## x)
23
24static inline bool cpu_have_feature(unsigned int num)
25{
26 return elf_hwcap & (1UL << num);
27}
28
29#endif
diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h
index 62314791570c..6e9b5b36921c 100644
--- a/arch/arm64/include/asm/debug-monitors.h
+++ b/arch/arm64/include/asm/debug-monitors.h
@@ -26,6 +26,53 @@
26#define DBG_ESR_EVT_HWWP 0x2 26#define DBG_ESR_EVT_HWWP 0x2
27#define DBG_ESR_EVT_BRK 0x6 27#define DBG_ESR_EVT_BRK 0x6
28 28
29/*
30 * Break point instruction encoding
31 */
32#define BREAK_INSTR_SIZE 4
33
34/*
35 * ESR values expected for dynamic and compile time BRK instruction
36 */
37#define DBG_ESR_VAL_BRK(x) (0xf2000000 | ((x) & 0xfffff))
38
39/*
40 * #imm16 values used for BRK instruction generation
41 * Allowed values for kgbd are 0x400 - 0x7ff
42 * 0x400: for dynamic BRK instruction
43 * 0x401: for compile time BRK instruction
44 */
45#define KGDB_DYN_DGB_BRK_IMM 0x400
46#define KDBG_COMPILED_DBG_BRK_IMM 0x401
47
48/*
49 * BRK instruction encoding
50 * The #imm16 value should be placed at bits[20:5] within BRK ins
51 */
52#define AARCH64_BREAK_MON 0xd4200000
53
54/*
55 * Extract byte from BRK instruction
56 */
57#define KGDB_DYN_DGB_BRK_INS_BYTE(x) \
58 ((((AARCH64_BREAK_MON) & 0xffe0001f) >> (x * 8)) & 0xff)
59
60/*
61 * Extract byte from BRK #imm16
62 */
63#define KGBD_DYN_DGB_BRK_IMM_BYTE(x) \
64 (((((KGDB_DYN_DGB_BRK_IMM) & 0xffff) << 5) >> (x * 8)) & 0xff)
65
66#define KGDB_DYN_DGB_BRK_BYTE(x) \
67 (KGDB_DYN_DGB_BRK_INS_BYTE(x) | KGBD_DYN_DGB_BRK_IMM_BYTE(x))
68
69#define KGDB_DYN_BRK_INS_BYTE0 KGDB_DYN_DGB_BRK_BYTE(0)
70#define KGDB_DYN_BRK_INS_BYTE1 KGDB_DYN_DGB_BRK_BYTE(1)
71#define KGDB_DYN_BRK_INS_BYTE2 KGDB_DYN_DGB_BRK_BYTE(2)
72#define KGDB_DYN_BRK_INS_BYTE3 KGDB_DYN_DGB_BRK_BYTE(3)
73
74#define CACHE_FLUSH_IS_SAFE 1
75
29enum debug_el { 76enum debug_el {
30 DBG_ACTIVE_EL0 = 0, 77 DBG_ACTIVE_EL0 = 0,
31 DBG_ACTIVE_EL1, 78 DBG_ACTIVE_EL1,
@@ -43,23 +90,6 @@ enum debug_el {
43#ifndef __ASSEMBLY__ 90#ifndef __ASSEMBLY__
44struct task_struct; 91struct task_struct;
45 92
46#define local_dbg_save(flags) \
47 do { \
48 typecheck(unsigned long, flags); \
49 asm volatile( \
50 "mrs %0, daif // local_dbg_save\n" \
51 "msr daifset, #8" \
52 : "=r" (flags) : : "memory"); \
53 } while (0)
54
55#define local_dbg_restore(flags) \
56 do { \
57 typecheck(unsigned long, flags); \
58 asm volatile( \
59 "msr daif, %0 // local_dbg_restore\n" \
60 : : "r" (flags) : "memory"); \
61 } while (0)
62
63#define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */ 93#define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */
64 94
65#define DBG_HOOK_HANDLED 0 95#define DBG_HOOK_HANDLED 0
diff --git a/arch/arm64/include/asm/dma-mapping.h b/arch/arm64/include/asm/dma-mapping.h
index fd0c0c0e447a..3a4572ec3273 100644
--- a/arch/arm64/include/asm/dma-mapping.h
+++ b/arch/arm64/include/asm/dma-mapping.h
@@ -30,6 +30,8 @@
30 30
31#define DMA_ERROR_CODE (~(dma_addr_t)0) 31#define DMA_ERROR_CODE (~(dma_addr_t)0)
32extern struct dma_map_ops *dma_ops; 32extern struct dma_map_ops *dma_ops;
33extern struct dma_map_ops coherent_swiotlb_dma_ops;
34extern struct dma_map_ops noncoherent_swiotlb_dma_ops;
33 35
34static inline struct dma_map_ops *__generic_dma_ops(struct device *dev) 36static inline struct dma_map_ops *__generic_dma_ops(struct device *dev)
35{ 37{
@@ -47,6 +49,11 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
47 return __generic_dma_ops(dev); 49 return __generic_dma_ops(dev);
48} 50}
49 51
52static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
53{
54 dev->archdata.dma_ops = ops;
55}
56
50#include <asm-generic/dma-mapping-common.h> 57#include <asm-generic/dma-mapping-common.h>
51 58
52static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) 59static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h
index 78834123a32e..c4a7f940b387 100644
--- a/arch/arm64/include/asm/esr.h
+++ b/arch/arm64/include/asm/esr.h
@@ -42,7 +42,7 @@
42#define ESR_EL1_EC_SP_ALIGN (0x26) 42#define ESR_EL1_EC_SP_ALIGN (0x26)
43#define ESR_EL1_EC_FP_EXC32 (0x28) 43#define ESR_EL1_EC_FP_EXC32 (0x28)
44#define ESR_EL1_EC_FP_EXC64 (0x2C) 44#define ESR_EL1_EC_FP_EXC64 (0x2C)
45#define ESR_EL1_EC_SERRROR (0x2F) 45#define ESR_EL1_EC_SERROR (0x2F)
46#define ESR_EL1_EC_BREAKPT_EL0 (0x30) 46#define ESR_EL1_EC_BREAKPT_EL0 (0x30)
47#define ESR_EL1_EC_BREAKPT_EL1 (0x31) 47#define ESR_EL1_EC_BREAKPT_EL1 (0x31)
48#define ESR_EL1_EC_SOFTSTP_EL0 (0x32) 48#define ESR_EL1_EC_SOFTSTP_EL0 (0x32)
diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h
index 78cc3aba5d69..5f750dc96e0f 100644
--- a/arch/arm64/include/asm/futex.h
+++ b/arch/arm64/include/asm/futex.h
@@ -24,10 +24,11 @@
24 24
25#define __futex_atomic_op(insn, ret, oldval, uaddr, tmp, oparg) \ 25#define __futex_atomic_op(insn, ret, oldval, uaddr, tmp, oparg) \
26 asm volatile( \ 26 asm volatile( \
27"1: ldaxr %w1, %2\n" \ 27"1: ldxr %w1, %2\n" \
28 insn "\n" \ 28 insn "\n" \
29"2: stlxr %w3, %w0, %2\n" \ 29"2: stlxr %w3, %w0, %2\n" \
30" cbnz %w3, 1b\n" \ 30" cbnz %w3, 1b\n" \
31" dmb ish\n" \
31"3:\n" \ 32"3:\n" \
32" .pushsection .fixup,\"ax\"\n" \ 33" .pushsection .fixup,\"ax\"\n" \
33" .align 2\n" \ 34" .align 2\n" \
@@ -40,7 +41,7 @@
40" .popsection\n" \ 41" .popsection\n" \
41 : "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp) \ 42 : "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp) \
42 : "r" (oparg), "Ir" (-EFAULT) \ 43 : "r" (oparg), "Ir" (-EFAULT) \
43 : "cc", "memory") 44 : "memory")
44 45
45static inline int 46static inline int
46futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr) 47futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
@@ -111,11 +112,12 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
111 return -EFAULT; 112 return -EFAULT;
112 113
113 asm volatile("// futex_atomic_cmpxchg_inatomic\n" 114 asm volatile("// futex_atomic_cmpxchg_inatomic\n"
114"1: ldaxr %w1, %2\n" 115"1: ldxr %w1, %2\n"
115" sub %w3, %w1, %w4\n" 116" sub %w3, %w1, %w4\n"
116" cbnz %w3, 3f\n" 117" cbnz %w3, 3f\n"
117"2: stlxr %w3, %w5, %2\n" 118"2: stlxr %w3, %w5, %2\n"
118" cbnz %w3, 1b\n" 119" cbnz %w3, 1b\n"
120" dmb ish\n"
119"3:\n" 121"3:\n"
120" .pushsection .fixup,\"ax\"\n" 122" .pushsection .fixup,\"ax\"\n"
121"4: mov %w0, %w6\n" 123"4: mov %w0, %w6\n"
@@ -127,7 +129,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
127" .popsection\n" 129" .popsection\n"
128 : "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp) 130 : "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp)
129 : "r" (oldval), "r" (newval), "Ir" (-EFAULT) 131 : "r" (oldval), "r" (newval), "Ir" (-EFAULT)
130 : "cc", "memory"); 132 : "memory");
131 133
132 *uval = val; 134 *uval = val;
133 return ret; 135 return ret;
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index 6cddbb0c9f54..024c46183c3c 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -32,6 +32,12 @@
32#define COMPAT_HWCAP_IDIV (COMPAT_HWCAP_IDIVA|COMPAT_HWCAP_IDIVT) 32#define COMPAT_HWCAP_IDIV (COMPAT_HWCAP_IDIVA|COMPAT_HWCAP_IDIVT)
33#define COMPAT_HWCAP_EVTSTRM (1 << 21) 33#define COMPAT_HWCAP_EVTSTRM (1 << 21)
34 34
35#define COMPAT_HWCAP2_AES (1 << 0)
36#define COMPAT_HWCAP2_PMULL (1 << 1)
37#define COMPAT_HWCAP2_SHA1 (1 << 2)
38#define COMPAT_HWCAP2_SHA2 (1 << 3)
39#define COMPAT_HWCAP2_CRC32 (1 << 4)
40
35#ifndef __ASSEMBLY__ 41#ifndef __ASSEMBLY__
36/* 42/*
37 * This yields a mask that user programs can use to figure out what 43 * This yields a mask that user programs can use to figure out what
@@ -41,7 +47,8 @@
41 47
42#ifdef CONFIG_COMPAT 48#ifdef CONFIG_COMPAT
43#define COMPAT_ELF_HWCAP (compat_elf_hwcap) 49#define COMPAT_ELF_HWCAP (compat_elf_hwcap)
44extern unsigned int compat_elf_hwcap; 50#define COMPAT_ELF_HWCAP2 (compat_elf_hwcap2)
51extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
45#endif 52#endif
46 53
47extern unsigned long elf_hwcap; 54extern unsigned long elf_hwcap;
diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
index 4cc813eddacb..7846a6bb0833 100644
--- a/arch/arm64/include/asm/io.h
+++ b/arch/arm64/include/asm/io.h
@@ -121,7 +121,7 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
121 * I/O port access primitives. 121 * I/O port access primitives.
122 */ 122 */
123#define IO_SPACE_LIMIT 0xffff 123#define IO_SPACE_LIMIT 0xffff
124#define PCI_IOBASE ((void __iomem *)(MODULES_VADDR - SZ_2M)) 124#define PCI_IOBASE ((void __iomem *)(MODULES_VADDR - SZ_32M))
125 125
126static inline u8 inb(unsigned long addr) 126static inline u8 inb(unsigned long addr)
127{ 127{
diff --git a/arch/arm64/include/asm/irqflags.h b/arch/arm64/include/asm/irqflags.h
index b2fcfbc51ecc..11cc941bd107 100644
--- a/arch/arm64/include/asm/irqflags.h
+++ b/arch/arm64/include/asm/irqflags.h
@@ -90,5 +90,28 @@ static inline int arch_irqs_disabled_flags(unsigned long flags)
90 return flags & PSR_I_BIT; 90 return flags & PSR_I_BIT;
91} 91}
92 92
93/*
94 * save and restore debug state
95 */
96#define local_dbg_save(flags) \
97 do { \
98 typecheck(unsigned long, flags); \
99 asm volatile( \
100 "mrs %0, daif // local_dbg_save\n" \
101 "msr daifset, #8" \
102 : "=r" (flags) : : "memory"); \
103 } while (0)
104
105#define local_dbg_restore(flags) \
106 do { \
107 typecheck(unsigned long, flags); \
108 asm volatile( \
109 "msr daif, %0 // local_dbg_restore\n" \
110 : : "r" (flags) : "memory"); \
111 } while (0)
112
113#define local_dbg_enable() asm("msr daifclr, #8" : : : "memory")
114#define local_dbg_disable() asm("msr daifset, #8" : : : "memory")
115
93#endif 116#endif
94#endif 117#endif
diff --git a/arch/arm64/include/asm/kgdb.h b/arch/arm64/include/asm/kgdb.h
new file mode 100644
index 000000000000..3c8aafc1082f
--- /dev/null
+++ b/arch/arm64/include/asm/kgdb.h
@@ -0,0 +1,84 @@
1/*
2 * AArch64 KGDB support
3 *
4 * Based on arch/arm/include/kgdb.h
5 *
6 * Copyright (C) 2013 Cavium Inc.
7 * Author: Vijaya Kumar K <vijaya.kumar@caviumnetworks.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef __ARM_KGDB_H
23#define __ARM_KGDB_H
24
25#include <linux/ptrace.h>
26#include <asm/debug-monitors.h>
27
28#ifndef __ASSEMBLY__
29
30static inline void arch_kgdb_breakpoint(void)
31{
32 asm ("brk %0" : : "I" (KDBG_COMPILED_DBG_BRK_IMM));
33}
34
35extern void kgdb_handle_bus_error(void);
36extern int kgdb_fault_expected;
37
38#endif /* !__ASSEMBLY__ */
39
40/*
41 * gdb is expecting the following registers layout.
42 *
43 * General purpose regs:
44 * r0-r30: 64 bit
45 * sp,pc : 64 bit
46 * pstate : 64 bit
47 * Total: 34
48 * FPU regs:
49 * f0-f31: 128 bit
50 * Total: 32
51 * Extra regs
52 * fpsr & fpcr: 32 bit
53 * Total: 2
54 *
55 */
56
57#define _GP_REGS 34
58#define _FP_REGS 32
59#define _EXTRA_REGS 2
60/*
61 * general purpose registers size in bytes.
62 * pstate is only 4 bytes. subtract 4 bytes
63 */
64#define GP_REG_BYTES (_GP_REGS * 8)
65#define DBG_MAX_REG_NUM (_GP_REGS + _FP_REGS + _EXTRA_REGS)
66
67/*
68 * Size of I/O buffer for gdb packet.
69 * considering to hold all register contents, size is set
70 */
71
72#define BUFMAX 2048
73
74/*
75 * Number of bytes required for gdb_regs buffer.
76 * _GP_REGS: 8 bytes, _FP_REGS: 16 bytes and _EXTRA_REGS: 4 bytes each
77 * GDB fails to connect for size beyond this with error
78 * "'g' packet reply is too long"
79 */
80
81#define NUMREGBYTES ((_GP_REGS * 8) + (_FP_REGS * 16) + \
82 (_EXTRA_REGS * 4))
83
84#endif /* __ASM_KGDB_H */
diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index c98ef4771c73..21ef48d32ff2 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -106,7 +106,6 @@
106 106
107/* VTCR_EL2 Registers bits */ 107/* VTCR_EL2 Registers bits */
108#define VTCR_EL2_PS_MASK (7 << 16) 108#define VTCR_EL2_PS_MASK (7 << 16)
109#define VTCR_EL2_PS_40B (2 << 16)
110#define VTCR_EL2_TG0_MASK (1 << 14) 109#define VTCR_EL2_TG0_MASK (1 << 14)
111#define VTCR_EL2_TG0_4K (0 << 14) 110#define VTCR_EL2_TG0_4K (0 << 14)
112#define VTCR_EL2_TG0_64K (1 << 14) 111#define VTCR_EL2_TG0_64K (1 << 14)
@@ -129,10 +128,9 @@
129 * 64kB pages (TG0 = 1) 128 * 64kB pages (TG0 = 1)
130 * 2 level page tables (SL = 1) 129 * 2 level page tables (SL = 1)
131 */ 130 */
132#define VTCR_EL2_FLAGS (VTCR_EL2_PS_40B | VTCR_EL2_TG0_64K | \ 131#define VTCR_EL2_FLAGS (VTCR_EL2_TG0_64K | VTCR_EL2_SH0_INNER | \
133 VTCR_EL2_SH0_INNER | VTCR_EL2_ORGN0_WBWA | \ 132 VTCR_EL2_ORGN0_WBWA | VTCR_EL2_IRGN0_WBWA | \
134 VTCR_EL2_IRGN0_WBWA | VTCR_EL2_SL0_LVL1 | \ 133 VTCR_EL2_SL0_LVL1 | VTCR_EL2_T0SZ_40B)
135 VTCR_EL2_T0SZ_40B)
136#define VTTBR_X (38 - VTCR_EL2_T0SZ_40B) 134#define VTTBR_X (38 - VTCR_EL2_T0SZ_40B)
137#else 135#else
138/* 136/*
@@ -142,10 +140,9 @@
142 * 4kB pages (TG0 = 0) 140 * 4kB pages (TG0 = 0)
143 * 3 level page tables (SL = 1) 141 * 3 level page tables (SL = 1)
144 */ 142 */
145#define VTCR_EL2_FLAGS (VTCR_EL2_PS_40B | VTCR_EL2_TG0_4K | \ 143#define VTCR_EL2_FLAGS (VTCR_EL2_TG0_4K | VTCR_EL2_SH0_INNER | \
146 VTCR_EL2_SH0_INNER | VTCR_EL2_ORGN0_WBWA | \ 144 VTCR_EL2_ORGN0_WBWA | VTCR_EL2_IRGN0_WBWA | \
147 VTCR_EL2_IRGN0_WBWA | VTCR_EL2_SL0_LVL1 | \ 145 VTCR_EL2_SL0_LVL1 | VTCR_EL2_T0SZ_40B)
148 VTCR_EL2_T0SZ_40B)
149#define VTTBR_X (37 - VTCR_EL2_T0SZ_40B) 146#define VTTBR_X (37 - VTCR_EL2_T0SZ_40B)
150#endif 147#endif
151 148
@@ -231,7 +228,7 @@
231#define ESR_EL2_EC_SP_ALIGN (0x26) 228#define ESR_EL2_EC_SP_ALIGN (0x26)
232#define ESR_EL2_EC_FP_EXC32 (0x28) 229#define ESR_EL2_EC_FP_EXC32 (0x28)
233#define ESR_EL2_EC_FP_EXC64 (0x2C) 230#define ESR_EL2_EC_FP_EXC64 (0x2C)
234#define ESR_EL2_EC_SERRROR (0x2F) 231#define ESR_EL2_EC_SERROR (0x2F)
235#define ESR_EL2_EC_BREAKPT (0x30) 232#define ESR_EL2_EC_BREAKPT (0x30)
236#define ESR_EL2_EC_BREAKPT_HYP (0x31) 233#define ESR_EL2_EC_BREAKPT_HYP (0x31)
237#define ESR_EL2_EC_SOFTSTP (0x32) 234#define ESR_EL2_EC_SOFTSTP (0x32)
diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percpu.h
index 13fb0b3efc5f..453a179469a3 100644
--- a/arch/arm64/include/asm/percpu.h
+++ b/arch/arm64/include/asm/percpu.h
@@ -16,6 +16,8 @@
16#ifndef __ASM_PERCPU_H 16#ifndef __ASM_PERCPU_H
17#define __ASM_PERCPU_H 17#define __ASM_PERCPU_H
18 18
19#ifdef CONFIG_SMP
20
19static inline void set_my_cpu_offset(unsigned long off) 21static inline void set_my_cpu_offset(unsigned long off)
20{ 22{
21 asm volatile("msr tpidr_el1, %0" :: "r" (off) : "memory"); 23 asm volatile("msr tpidr_el1, %0" :: "r" (off) : "memory");
@@ -36,6 +38,12 @@ static inline unsigned long __my_cpu_offset(void)
36} 38}
37#define __my_cpu_offset __my_cpu_offset() 39#define __my_cpu_offset __my_cpu_offset()
38 40
41#else /* !CONFIG_SMP */
42
43#define set_my_cpu_offset(x) do { } while (0)
44
45#endif /* CONFIG_SMP */
46
39#include <asm-generic/percpu.h> 47#include <asm-generic/percpu.h>
40 48
41#endif /* __ASM_PERCPU_H */ 49#endif /* __ASM_PERCPU_H */
diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h
index b1d2e26c3c88..f7af66b54cb2 100644
--- a/arch/arm64/include/asm/pgtable-hwdef.h
+++ b/arch/arm64/include/asm/pgtable-hwdef.h
@@ -100,9 +100,9 @@
100#define PTE_HYP PTE_USER 100#define PTE_HYP PTE_USER
101 101
102/* 102/*
103 * 40-bit physical address supported. 103 * Highest possible physical address supported.
104 */ 104 */
105#define PHYS_MASK_SHIFT (40) 105#define PHYS_MASK_SHIFT (48)
106#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) 106#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1)
107 107
108/* 108/*
@@ -122,7 +122,6 @@
122#define TCR_SHARED ((UL(3) << 12) | (UL(3) << 28)) 122#define TCR_SHARED ((UL(3) << 12) | (UL(3) << 28))
123#define TCR_TG0_64K (UL(1) << 14) 123#define TCR_TG0_64K (UL(1) << 14)
124#define TCR_TG1_64K (UL(1) << 30) 124#define TCR_TG1_64K (UL(1) << 30)
125#define TCR_IPS_40BIT (UL(2) << 32)
126#define TCR_ASID16 (UL(1) << 36) 125#define TCR_ASID16 (UL(1) << 36)
127#define TCR_TBI0 (UL(1) << 37) 126#define TCR_TBI0 (UL(1) << 37)
128 127
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index b524dcd17243..90c811f05a2e 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -136,11 +136,11 @@ extern struct page *empty_zero_page;
136/* 136/*
137 * The following only work if pte_present(). Undefined behaviour otherwise. 137 * The following only work if pte_present(). Undefined behaviour otherwise.
138 */ 138 */
139#define pte_present(pte) (pte_val(pte) & (PTE_VALID | PTE_PROT_NONE)) 139#define pte_present(pte) (!!(pte_val(pte) & (PTE_VALID | PTE_PROT_NONE)))
140#define pte_dirty(pte) (pte_val(pte) & PTE_DIRTY) 140#define pte_dirty(pte) (!!(pte_val(pte) & PTE_DIRTY))
141#define pte_young(pte) (pte_val(pte) & PTE_AF) 141#define pte_young(pte) (!!(pte_val(pte) & PTE_AF))
142#define pte_special(pte) (pte_val(pte) & PTE_SPECIAL) 142#define pte_special(pte) (!!(pte_val(pte) & PTE_SPECIAL))
143#define pte_write(pte) (pte_val(pte) & PTE_WRITE) 143#define pte_write(pte) (!!(pte_val(pte) & PTE_WRITE))
144#define pte_exec(pte) (!(pte_val(pte) & PTE_UXN)) 144#define pte_exec(pte) (!(pte_val(pte) & PTE_UXN))
145 145
146#define pte_valid_user(pte) \ 146#define pte_valid_user(pte) \
@@ -199,7 +199,7 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
199 pte_t *ptep, pte_t pte) 199 pte_t *ptep, pte_t pte)
200{ 200{
201 if (pte_valid_user(pte)) { 201 if (pte_valid_user(pte)) {
202 if (pte_exec(pte)) 202 if (!pte_special(pte) && pte_exec(pte))
203 __sync_icache_dcache(pte, addr); 203 __sync_icache_dcache(pte, addr);
204 if (pte_dirty(pte) && pte_write(pte)) 204 if (pte_dirty(pte) && pte_write(pte))
205 pte_val(pte) &= ~PTE_RDONLY; 205 pte_val(pte) &= ~PTE_RDONLY;
@@ -227,36 +227,36 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
227 227
228#define __HAVE_ARCH_PTE_SPECIAL 228#define __HAVE_ARCH_PTE_SPECIAL
229 229
230/* 230static inline pte_t pmd_pte(pmd_t pmd)
231 * Software PMD bits for THP 231{
232 */ 232 return __pte(pmd_val(pmd));
233}
233 234
234#define PMD_SECT_DIRTY (_AT(pmdval_t, 1) << 55) 235static inline pmd_t pte_pmd(pte_t pte)
235#define PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 57) 236{
237 return __pmd(pte_val(pte));
238}
236 239
237/* 240/*
238 * THP definitions. 241 * THP definitions.
239 */ 242 */
240#define pmd_young(pmd) (pmd_val(pmd) & PMD_SECT_AF)
241
242#define __HAVE_ARCH_PMD_WRITE
243#define pmd_write(pmd) (!(pmd_val(pmd) & PMD_SECT_RDONLY))
244 243
245#ifdef CONFIG_TRANSPARENT_HUGEPAGE 244#ifdef CONFIG_TRANSPARENT_HUGEPAGE
246#define pmd_trans_huge(pmd) (pmd_val(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT)) 245#define pmd_trans_huge(pmd) (pmd_val(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT))
247#define pmd_trans_splitting(pmd) (pmd_val(pmd) & PMD_SECT_SPLITTING) 246#define pmd_trans_splitting(pmd) pte_special(pmd_pte(pmd))
248#endif 247#endif
249 248
250#define PMD_BIT_FUNC(fn,op) \ 249#define pmd_young(pmd) pte_young(pmd_pte(pmd))
251static inline pmd_t pmd_##fn(pmd_t pmd) { pmd_val(pmd) op; return pmd; } 250#define pmd_wrprotect(pmd) pte_pmd(pte_wrprotect(pmd_pte(pmd)))
251#define pmd_mksplitting(pmd) pte_pmd(pte_mkspecial(pmd_pte(pmd)))
252#define pmd_mkold(pmd) pte_pmd(pte_mkold(pmd_pte(pmd)))
253#define pmd_mkwrite(pmd) pte_pmd(pte_mkwrite(pmd_pte(pmd)))
254#define pmd_mkdirty(pmd) pte_pmd(pte_mkdirty(pmd_pte(pmd)))
255#define pmd_mkyoung(pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd)))
256#define pmd_mknotpresent(pmd) (__pmd(pmd_val(pmd) &= ~PMD_TYPE_MASK))
252 257
253PMD_BIT_FUNC(wrprotect, |= PMD_SECT_RDONLY); 258#define __HAVE_ARCH_PMD_WRITE
254PMD_BIT_FUNC(mkold, &= ~PMD_SECT_AF); 259#define pmd_write(pmd) pte_write(pmd_pte(pmd))
255PMD_BIT_FUNC(mksplitting, |= PMD_SECT_SPLITTING);
256PMD_BIT_FUNC(mkwrite, &= ~PMD_SECT_RDONLY);
257PMD_BIT_FUNC(mkdirty, |= PMD_SECT_DIRTY);
258PMD_BIT_FUNC(mkyoung, |= PMD_SECT_AF);
259PMD_BIT_FUNC(mknotpresent, &= ~PMD_TYPE_MASK);
260 260
261#define pmd_mkhuge(pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT)) 261#define pmd_mkhuge(pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT))
262 262
@@ -266,15 +266,6 @@ PMD_BIT_FUNC(mknotpresent, &= ~PMD_TYPE_MASK);
266 266
267#define pmd_page(pmd) pfn_to_page(__phys_to_pfn(pmd_val(pmd) & PHYS_MASK)) 267#define pmd_page(pmd) pfn_to_page(__phys_to_pfn(pmd_val(pmd) & PHYS_MASK))
268 268
269static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
270{
271 const pmdval_t mask = PMD_SECT_USER | PMD_SECT_PXN | PMD_SECT_UXN |
272 PMD_SECT_RDONLY | PMD_SECT_PROT_NONE |
273 PMD_SECT_VALID;
274 pmd_val(pmd) = (pmd_val(pmd) & ~mask) | (pgprot_val(newprot) & mask);
275 return pmd;
276}
277
278#define set_pmd_at(mm, addr, pmdp, pmd) set_pmd(pmdp, pmd) 269#define set_pmd_at(mm, addr, pmdp, pmd) set_pmd(pmdp, pmd)
279 270
280static inline int has_transparent_hugepage(void) 271static inline int has_transparent_hugepage(void)
@@ -286,11 +277,9 @@ static inline int has_transparent_hugepage(void)
286 * Mark the prot value as uncacheable and unbufferable. 277 * Mark the prot value as uncacheable and unbufferable.
287 */ 278 */
288#define pgprot_noncached(prot) \ 279#define pgprot_noncached(prot) \
289 __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRnE)) 280 __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRnE) | PTE_PXN | PTE_UXN)
290#define pgprot_writecombine(prot) \ 281#define pgprot_writecombine(prot) \
291 __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC)) 282 __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN)
292#define pgprot_dmacoherent(prot) \
293 __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC))
294#define __HAVE_PHYS_MEM_ACCESS_PROT 283#define __HAVE_PHYS_MEM_ACCESS_PROT
295struct file; 284struct file;
296extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, 285extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
@@ -383,6 +372,11 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
383 return pte; 372 return pte;
384} 373}
385 374
375static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
376{
377 return pte_pmd(pte_modify(pmd_pte(pmd), newprot));
378}
379
386extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; 380extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
387extern pgd_t idmap_pg_dir[PTRS_PER_PGD]; 381extern pgd_t idmap_pg_dir[PTRS_PER_PGD];
388 382
diff --git a/arch/arm64/include/asm/psci.h b/arch/arm64/include/asm/psci.h
index e5312ea0ec1a..d15ab8b46336 100644
--- a/arch/arm64/include/asm/psci.h
+++ b/arch/arm64/include/asm/psci.h
@@ -14,6 +14,6 @@
14#ifndef __ASM_PSCI_H 14#ifndef __ASM_PSCI_H
15#define __ASM_PSCI_H 15#define __ASM_PSCI_H
16 16
17int psci_init(void); 17void psci_init(void);
18 18
19#endif /* __ASM_PSCI_H */ 19#endif /* __ASM_PSCI_H */
diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
index 0e7fa4963735..c7ba261dd4b3 100644
--- a/arch/arm64/include/asm/ptrace.h
+++ b/arch/arm64/include/asm/ptrace.h
@@ -68,6 +68,7 @@
68 68
69/* Architecturally defined mapping between AArch32 and AArch64 registers */ 69/* Architecturally defined mapping between AArch32 and AArch64 registers */
70#define compat_usr(x) regs[(x)] 70#define compat_usr(x) regs[(x)]
71#define compat_fp regs[11]
71#define compat_sp regs[13] 72#define compat_sp regs[13]
72#define compat_lr regs[14] 73#define compat_lr regs[14]
73#define compat_sp_hyp regs[15] 74#define compat_sp_hyp regs[15]
@@ -132,7 +133,7 @@ struct pt_regs {
132 (!((regs)->pstate & PSR_F_BIT)) 133 (!((regs)->pstate & PSR_F_BIT))
133 134
134#define user_stack_pointer(regs) \ 135#define user_stack_pointer(regs) \
135 ((regs)->sp) 136 (!compat_user_mode(regs)) ? ((regs)->sp) : ((regs)->compat_sp)
136 137
137/* 138/*
138 * Are the current registers suitable for user mode? (used to maintain 139 * Are the current registers suitable for user mode? (used to maintain
@@ -164,7 +165,7 @@ static inline int valid_user_regs(struct user_pt_regs *regs)
164 return 0; 165 return 0;
165} 166}
166 167
167#define instruction_pointer(regs) (regs)->pc 168#define instruction_pointer(regs) ((unsigned long)(regs)->pc)
168 169
169#ifdef CONFIG_SMP 170#ifdef CONFIG_SMP
170extern unsigned long profile_pc(struct pt_regs *regs); 171extern unsigned long profile_pc(struct pt_regs *regs);
diff --git a/arch/arm64/include/asm/spinlock.h b/arch/arm64/include/asm/spinlock.h
index 3d5cf064d7a1..c45b7b1b7197 100644
--- a/arch/arm64/include/asm/spinlock.h
+++ b/arch/arm64/include/asm/spinlock.h
@@ -132,7 +132,7 @@ static inline void arch_write_lock(arch_rwlock_t *rw)
132 " cbnz %w0, 2b\n" 132 " cbnz %w0, 2b\n"
133 : "=&r" (tmp), "+Q" (rw->lock) 133 : "=&r" (tmp), "+Q" (rw->lock)
134 : "r" (0x80000000) 134 : "r" (0x80000000)
135 : "cc", "memory"); 135 : "memory");
136} 136}
137 137
138static inline int arch_write_trylock(arch_rwlock_t *rw) 138static inline int arch_write_trylock(arch_rwlock_t *rw)
@@ -146,7 +146,7 @@ static inline int arch_write_trylock(arch_rwlock_t *rw)
146 "1:\n" 146 "1:\n"
147 : "=&r" (tmp), "+Q" (rw->lock) 147 : "=&r" (tmp), "+Q" (rw->lock)
148 : "r" (0x80000000) 148 : "r" (0x80000000)
149 : "cc", "memory"); 149 : "memory");
150 150
151 return !tmp; 151 return !tmp;
152} 152}
@@ -187,7 +187,7 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
187 " cbnz %w1, 2b\n" 187 " cbnz %w1, 2b\n"
188 : "=&r" (tmp), "=&r" (tmp2), "+Q" (rw->lock) 188 : "=&r" (tmp), "=&r" (tmp2), "+Q" (rw->lock)
189 : 189 :
190 : "cc", "memory"); 190 : "memory");
191} 191}
192 192
193static inline void arch_read_unlock(arch_rwlock_t *rw) 193static inline void arch_read_unlock(arch_rwlock_t *rw)
@@ -201,7 +201,7 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
201 " cbnz %w1, 1b\n" 201 " cbnz %w1, 1b\n"
202 : "=&r" (tmp), "=&r" (tmp2), "+Q" (rw->lock) 202 : "=&r" (tmp), "=&r" (tmp2), "+Q" (rw->lock)
203 : 203 :
204 : "cc", "memory"); 204 : "memory");
205} 205}
206 206
207static inline int arch_read_trylock(arch_rwlock_t *rw) 207static inline int arch_read_trylock(arch_rwlock_t *rw)
@@ -216,7 +216,7 @@ static inline int arch_read_trylock(arch_rwlock_t *rw)
216 "1:\n" 216 "1:\n"
217 : "=&r" (tmp), "+r" (tmp2), "+Q" (rw->lock) 217 : "=&r" (tmp), "+r" (tmp2), "+Q" (rw->lock)
218 : 218 :
219 : "cc", "memory"); 219 : "memory");
220 220
221 return !tmp2; 221 return !tmp2;
222} 222}
diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h
index 717031a762c2..72cadf52ca80 100644
--- a/arch/arm64/include/asm/tlb.h
+++ b/arch/arm64/include/asm/tlb.h
@@ -19,115 +19,44 @@
19#ifndef __ASM_TLB_H 19#ifndef __ASM_TLB_H
20#define __ASM_TLB_H 20#define __ASM_TLB_H
21 21
22#include <linux/pagemap.h>
23#include <linux/swap.h>
24 22
25#include <asm/pgalloc.h> 23#include <asm-generic/tlb.h>
26#include <asm/tlbflush.h>
27
28#define MMU_GATHER_BUNDLE 8
29
30/*
31 * TLB handling. This allows us to remove pages from the page
32 * tables, and efficiently handle the TLB issues.
33 */
34struct mmu_gather {
35 struct mm_struct *mm;
36 unsigned int fullmm;
37 struct vm_area_struct *vma;
38 unsigned long start, end;
39 unsigned long range_start;
40 unsigned long range_end;
41 unsigned int nr;
42 unsigned int max;
43 struct page **pages;
44 struct page *local[MMU_GATHER_BUNDLE];
45};
46 24
47/* 25/*
48 * This is unnecessarily complex. There's three ways the TLB shootdown 26 * There's three ways the TLB shootdown code is used:
49 * code is used:
50 * 1. Unmapping a range of vmas. See zap_page_range(), unmap_region(). 27 * 1. Unmapping a range of vmas. See zap_page_range(), unmap_region().
51 * tlb->fullmm = 0, and tlb_start_vma/tlb_end_vma will be called. 28 * tlb->fullmm = 0, and tlb_start_vma/tlb_end_vma will be called.
52 * tlb->vma will be non-NULL.
53 * 2. Unmapping all vmas. See exit_mmap(). 29 * 2. Unmapping all vmas. See exit_mmap().
54 * tlb->fullmm = 1, and tlb_start_vma/tlb_end_vma will be called. 30 * tlb->fullmm = 1, and tlb_start_vma/tlb_end_vma will be called.
55 * tlb->vma will be non-NULL. Additionally, page tables will be freed. 31 * Page tables will be freed.
56 * 3. Unmapping argument pages. See shift_arg_pages(). 32 * 3. Unmapping argument pages. See shift_arg_pages().
57 * tlb->fullmm = 0, but tlb_start_vma/tlb_end_vma will not be called. 33 * tlb->fullmm = 0, but tlb_start_vma/tlb_end_vma will not be called.
58 * tlb->vma will be NULL.
59 */ 34 */
60static inline void tlb_flush(struct mmu_gather *tlb) 35static inline void tlb_flush(struct mmu_gather *tlb)
61{ 36{
62 if (tlb->fullmm || !tlb->vma) 37 if (tlb->fullmm) {
63 flush_tlb_mm(tlb->mm); 38 flush_tlb_mm(tlb->mm);
64 else if (tlb->range_end > 0) { 39 } else if (tlb->end > 0) {
65 flush_tlb_range(tlb->vma, tlb->range_start, tlb->range_end); 40 struct vm_area_struct vma = { .vm_mm = tlb->mm, };
66 tlb->range_start = TASK_SIZE; 41 flush_tlb_range(&vma, tlb->start, tlb->end);
67 tlb->range_end = 0; 42 tlb->start = TASK_SIZE;
43 tlb->end = 0;
68 } 44 }
69} 45}
70 46
71static inline void tlb_add_flush(struct mmu_gather *tlb, unsigned long addr) 47static inline void tlb_add_flush(struct mmu_gather *tlb, unsigned long addr)
72{ 48{
73 if (!tlb->fullmm) { 49 if (!tlb->fullmm) {
74 if (addr < tlb->range_start) 50 tlb->start = min(tlb->start, addr);
75 tlb->range_start = addr; 51 tlb->end = max(tlb->end, addr + PAGE_SIZE);
76 if (addr + PAGE_SIZE > tlb->range_end)
77 tlb->range_end = addr + PAGE_SIZE;
78 }
79}
80
81static inline void __tlb_alloc_page(struct mmu_gather *tlb)
82{
83 unsigned long addr = __get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0);
84
85 if (addr) {
86 tlb->pages = (void *)addr;
87 tlb->max = PAGE_SIZE / sizeof(struct page *);
88 } 52 }
89} 53}
90 54
91static inline void tlb_flush_mmu(struct mmu_gather *tlb)
92{
93 tlb_flush(tlb);
94 free_pages_and_swap_cache(tlb->pages, tlb->nr);
95 tlb->nr = 0;
96 if (tlb->pages == tlb->local)
97 __tlb_alloc_page(tlb);
98}
99
100static inline void
101tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
102{
103 tlb->mm = mm;
104 tlb->fullmm = !(start | (end+1));
105 tlb->start = start;
106 tlb->end = end;
107 tlb->vma = NULL;
108 tlb->max = ARRAY_SIZE(tlb->local);
109 tlb->pages = tlb->local;
110 tlb->nr = 0;
111 __tlb_alloc_page(tlb);
112}
113
114static inline void
115tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
116{
117 tlb_flush_mmu(tlb);
118
119 /* keep the page table cache within bounds */
120 check_pgt_cache();
121
122 if (tlb->pages != tlb->local)
123 free_pages((unsigned long)tlb->pages, 0);
124}
125
126/* 55/*
127 * Memorize the range for the TLB flush. 56 * Memorize the range for the TLB flush.
128 */ 57 */
129static inline void 58static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep,
130tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long addr) 59 unsigned long addr)
131{ 60{
132 tlb_add_flush(tlb, addr); 61 tlb_add_flush(tlb, addr);
133} 62}
@@ -137,38 +66,24 @@ tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long addr)
137 * case where we're doing a full MM flush. When we're doing a munmap, 66 * case where we're doing a full MM flush. When we're doing a munmap,
138 * the vmas are adjusted to only cover the region to be torn down. 67 * the vmas are adjusted to only cover the region to be torn down.
139 */ 68 */
140static inline void 69static inline void tlb_start_vma(struct mmu_gather *tlb,
141tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) 70 struct vm_area_struct *vma)
142{ 71{
143 if (!tlb->fullmm) { 72 if (!tlb->fullmm) {
144 tlb->vma = vma; 73 tlb->start = TASK_SIZE;
145 tlb->range_start = TASK_SIZE; 74 tlb->end = 0;
146 tlb->range_end = 0;
147 } 75 }
148} 76}
149 77
150static inline void 78static inline void tlb_end_vma(struct mmu_gather *tlb,
151tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) 79 struct vm_area_struct *vma)
152{ 80{
153 if (!tlb->fullmm) 81 if (!tlb->fullmm)
154 tlb_flush(tlb); 82 tlb_flush(tlb);
155} 83}
156 84
157static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
158{
159 tlb->pages[tlb->nr++] = page;
160 VM_BUG_ON(tlb->nr > tlb->max);
161 return tlb->max - tlb->nr;
162}
163
164static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
165{
166 if (!__tlb_remove_page(tlb, page))
167 tlb_flush_mmu(tlb);
168}
169
170static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, 85static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
171 unsigned long addr) 86 unsigned long addr)
172{ 87{
173 pgtable_page_dtor(pte); 88 pgtable_page_dtor(pte);
174 tlb_add_flush(tlb, addr); 89 tlb_add_flush(tlb, addr);
@@ -184,16 +99,5 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
184} 99}
185#endif 100#endif
186 101
187#define pte_free_tlb(tlb, ptep, addr) __pte_free_tlb(tlb, ptep, addr)
188#define pmd_free_tlb(tlb, pmdp, addr) __pmd_free_tlb(tlb, pmdp, addr)
189#define pud_free_tlb(tlb, pudp, addr) pud_free((tlb)->mm, pudp)
190
191#define tlb_migrate_finish(mm) do { } while (0)
192
193static inline void
194tlb_remove_pmd_tlb_entry(struct mmu_gather *tlb, pmd_t *pmdp, unsigned long addr)
195{
196 tlb_add_flush(tlb, addr);
197}
198 102
199#endif 103#endif
diff --git a/arch/arm64/include/asm/topology.h b/arch/arm64/include/asm/topology.h
new file mode 100644
index 000000000000..0172e6d76bf3
--- /dev/null
+++ b/arch/arm64/include/asm/topology.h
@@ -0,0 +1,39 @@
1#ifndef __ASM_TOPOLOGY_H
2#define __ASM_TOPOLOGY_H
3
4#ifdef CONFIG_SMP
5
6#include <linux/cpumask.h>
7
8struct cpu_topology {
9 int thread_id;
10 int core_id;
11 int cluster_id;
12 cpumask_t thread_sibling;
13 cpumask_t core_sibling;
14};
15
16extern struct cpu_topology cpu_topology[NR_CPUS];
17
18#define topology_physical_package_id(cpu) (cpu_topology[cpu].cluster_id)
19#define topology_core_id(cpu) (cpu_topology[cpu].core_id)
20#define topology_core_cpumask(cpu) (&cpu_topology[cpu].core_sibling)
21#define topology_thread_cpumask(cpu) (&cpu_topology[cpu].thread_sibling)
22
23#define mc_capable() (cpu_topology[0].cluster_id != -1)
24#define smt_capable() (cpu_topology[0].thread_id != -1)
25
26void init_cpu_topology(void);
27void store_cpu_topology(unsigned int cpuid);
28const struct cpumask *cpu_coregroup_mask(int cpu);
29
30#else
31
32static inline void init_cpu_topology(void) { }
33static inline void store_cpu_topology(unsigned int cpuid) { }
34
35#endif
36
37#include <asm-generic/topology.h>
38
39#endif /* _ASM_ARM_TOPOLOGY_H */
diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
index 6c0f684aca81..3bf8f4e99a51 100644
--- a/arch/arm64/include/asm/uaccess.h
+++ b/arch/arm64/include/asm/uaccess.h
@@ -83,7 +83,7 @@ static inline void set_fs(mm_segment_t fs)
83 * Returns 1 if the range is valid, 0 otherwise. 83 * Returns 1 if the range is valid, 0 otherwise.
84 * 84 *
85 * This is equivalent to the following test: 85 * This is equivalent to the following test:
86 * (u65)addr + (u65)size < (u65)current->addr_limit 86 * (u65)addr + (u65)size <= current->addr_limit
87 * 87 *
88 * This needs 65-bit arithmetic. 88 * This needs 65-bit arithmetic.
89 */ 89 */
@@ -91,7 +91,7 @@ static inline void set_fs(mm_segment_t fs)
91({ \ 91({ \
92 unsigned long flag, roksum; \ 92 unsigned long flag, roksum; \
93 __chk_user_ptr(addr); \ 93 __chk_user_ptr(addr); \
94 asm("adds %1, %1, %3; ccmp %1, %4, #2, cc; cset %0, cc" \ 94 asm("adds %1, %1, %3; ccmp %1, %4, #2, cc; cset %0, ls" \
95 : "=&r" (flag), "=&r" (roksum) \ 95 : "=&r" (flag), "=&r" (roksum) \
96 : "1" (addr), "Ir" (size), \ 96 : "1" (addr), "Ir" (size), \
97 "r" (current_thread_info()->addr_limit) \ 97 "r" (current_thread_info()->addr_limit) \
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 82ce217e94cf..a4654c656a1e 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -14,6 +14,7 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16#ifdef CONFIG_COMPAT 16#ifdef CONFIG_COMPAT
17#define __ARCH_WANT_COMPAT_SYS_GETDENTS64
17#define __ARCH_WANT_COMPAT_STAT64 18#define __ARCH_WANT_COMPAT_STAT64
18#define __ARCH_WANT_SYS_GETHOSTNAME 19#define __ARCH_WANT_SYS_GETHOSTNAME
19#define __ARCH_WANT_SYS_PAUSE 20#define __ARCH_WANT_SYS_PAUSE
diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h
index 58125bf008d3..bb8eb8a78e67 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -399,7 +399,10 @@ __SYSCALL(374, compat_sys_sendmmsg)
399__SYSCALL(375, sys_setns) 399__SYSCALL(375, sys_setns)
400__SYSCALL(376, compat_sys_process_vm_readv) 400__SYSCALL(376, compat_sys_process_vm_readv)
401__SYSCALL(377, compat_sys_process_vm_writev) 401__SYSCALL(377, compat_sys_process_vm_writev)
402__SYSCALL(378, sys_ni_syscall) /* 378 for kcmp */ 402__SYSCALL(378, sys_kcmp)
403__SYSCALL(379, sys_finit_module)
404__SYSCALL(380, sys_sched_setattr)
405__SYSCALL(381, sys_sched_getattr)
403 406
404#define __NR_compat_syscalls 379 407#define __NR_compat_syscalls 379
405 408
diff --git a/arch/arm64/include/uapi/asm/Kbuild b/arch/arm64/include/uapi/asm/Kbuild
index e4b78bdca19e..942376d37d22 100644
--- a/arch/arm64/include/uapi/asm/Kbuild
+++ b/arch/arm64/include/uapi/asm/Kbuild
@@ -9,6 +9,7 @@ header-y += byteorder.h
9header-y += fcntl.h 9header-y += fcntl.h
10header-y += hwcap.h 10header-y += hwcap.h
11header-y += kvm_para.h 11header-y += kvm_para.h
12header-y += perf_regs.h
12header-y += param.h 13header-y += param.h
13header-y += ptrace.h 14header-y += ptrace.h
14header-y += setup.h 15header-y += setup.h
diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
index 495ab6f84a61..eaf54a30bedc 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -148,6 +148,15 @@ struct kvm_arch_memory_slot {
148#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2) 148#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2)
149#define KVM_REG_ARM_TIMER_CVAL ARM64_SYS_REG(3, 3, 14, 0, 2) 149#define KVM_REG_ARM_TIMER_CVAL ARM64_SYS_REG(3, 3, 14, 0, 2)
150 150
151/* Device Control API: ARM VGIC */
152#define KVM_DEV_ARM_VGIC_GRP_ADDR 0
153#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
154#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2
155#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32
156#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)
157#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0
158#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)
159
151/* KVM_IRQ_LINE irq field index values */ 160/* KVM_IRQ_LINE irq field index values */
152#define KVM_ARM_IRQ_TYPE_SHIFT 24 161#define KVM_ARM_IRQ_TYPE_SHIFT 24
153#define KVM_ARM_IRQ_TYPE_MASK 0xff 162#define KVM_ARM_IRQ_TYPE_MASK 0xff
diff --git a/arch/arm64/include/uapi/asm/perf_regs.h b/arch/arm64/include/uapi/asm/perf_regs.h
new file mode 100644
index 000000000000..172b8317ee49
--- /dev/null
+++ b/arch/arm64/include/uapi/asm/perf_regs.h
@@ -0,0 +1,40 @@
1#ifndef _ASM_ARM64_PERF_REGS_H
2#define _ASM_ARM64_PERF_REGS_H
3
4enum perf_event_arm_regs {
5 PERF_REG_ARM64_X0,
6 PERF_REG_ARM64_X1,
7 PERF_REG_ARM64_X2,
8 PERF_REG_ARM64_X3,
9 PERF_REG_ARM64_X4,
10 PERF_REG_ARM64_X5,
11 PERF_REG_ARM64_X6,
12 PERF_REG_ARM64_X7,
13 PERF_REG_ARM64_X8,
14 PERF_REG_ARM64_X9,
15 PERF_REG_ARM64_X10,
16 PERF_REG_ARM64_X11,
17 PERF_REG_ARM64_X12,
18 PERF_REG_ARM64_X13,
19 PERF_REG_ARM64_X14,
20 PERF_REG_ARM64_X15,
21 PERF_REG_ARM64_X16,
22 PERF_REG_ARM64_X17,
23 PERF_REG_ARM64_X18,
24 PERF_REG_ARM64_X19,
25 PERF_REG_ARM64_X20,
26 PERF_REG_ARM64_X21,
27 PERF_REG_ARM64_X22,
28 PERF_REG_ARM64_X23,
29 PERF_REG_ARM64_X24,
30 PERF_REG_ARM64_X25,
31 PERF_REG_ARM64_X26,
32 PERF_REG_ARM64_X27,
33 PERF_REG_ARM64_X28,
34 PERF_REG_ARM64_X29,
35 PERF_REG_ARM64_LR,
36 PERF_REG_ARM64_SP,
37 PERF_REG_ARM64_PC,
38 PERF_REG_ARM64_MAX,
39};
40#endif /* _ASM_ARM64_PERF_REGS_H */
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 2d4554b13410..7d811d9522bc 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -14,12 +14,14 @@ arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \
14arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \ 14arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \
15 sys_compat.o 15 sys_compat.o
16arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o 16arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o
17arm64-obj-$(CONFIG_SMP) += smp.o smp_spin_table.o 17arm64-obj-$(CONFIG_SMP) += smp.o smp_spin_table.o topology.o
18arm64-obj-$(CONFIG_PERF_EVENTS) += perf_regs.o
18arm64-obj-$(CONFIG_HW_PERF_EVENTS) += perf_event.o 19arm64-obj-$(CONFIG_HW_PERF_EVENTS) += perf_event.o
19arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT)+= hw_breakpoint.o 20arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
20arm64-obj-$(CONFIG_EARLY_PRINTK) += early_printk.o 21arm64-obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
21arm64-obj-$(CONFIG_ARM64_CPU_SUSPEND) += sleep.o suspend.o 22arm64-obj-$(CONFIG_ARM64_CPU_SUSPEND) += sleep.o suspend.o
22arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o 23arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o
24arm64-obj-$(CONFIG_KGDB) += kgdb.o
23 25
24obj-y += $(arm64-obj-y) vdso/ 26obj-y += $(arm64-obj-y) vdso/
25obj-m += $(arm64-obj-m) 27obj-m += $(arm64-obj-m)
diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
index 636ba8b6240b..14ba23c61153 100644
--- a/arch/arm64/kernel/debug-monitors.c
+++ b/arch/arm64/kernel/debug-monitors.c
@@ -137,7 +137,6 @@ void disable_debug_monitors(enum debug_el el)
137static void clear_os_lock(void *unused) 137static void clear_os_lock(void *unused)
138{ 138{
139 asm volatile("msr oslar_el1, %0" : : "r" (0)); 139 asm volatile("msr oslar_el1, %0" : : "r" (0));
140 isb();
141} 140}
142 141
143static int os_lock_notify(struct notifier_block *self, 142static int os_lock_notify(struct notifier_block *self,
@@ -156,8 +155,9 @@ static struct notifier_block os_lock_nb = {
156static int debug_monitors_init(void) 155static int debug_monitors_init(void)
157{ 156{
158 /* Clear the OS lock. */ 157 /* Clear the OS lock. */
159 smp_call_function(clear_os_lock, NULL, 1); 158 on_each_cpu(clear_os_lock, NULL, 1);
160 clear_os_lock(NULL); 159 isb();
160 local_dbg_enable();
161 161
162 /* Register hotplug handler. */ 162 /* Register hotplug handler. */
163 register_cpu_notifier(&os_lock_nb); 163 register_cpu_notifier(&os_lock_nb);
@@ -189,7 +189,7 @@ static void clear_regs_spsr_ss(struct pt_regs *regs)
189 189
190/* EL1 Single Step Handler hooks */ 190/* EL1 Single Step Handler hooks */
191static LIST_HEAD(step_hook); 191static LIST_HEAD(step_hook);
192DEFINE_RWLOCK(step_hook_lock); 192static DEFINE_RWLOCK(step_hook_lock);
193 193
194void register_step_hook(struct step_hook *hook) 194void register_step_hook(struct step_hook *hook)
195{ 195{
@@ -276,7 +276,7 @@ static int single_step_handler(unsigned long addr, unsigned int esr,
276 * Use reader/writer locks instead of plain spinlock. 276 * Use reader/writer locks instead of plain spinlock.
277 */ 277 */
278static LIST_HEAD(break_hook); 278static LIST_HEAD(break_hook);
279DEFINE_RWLOCK(break_hook_lock); 279static DEFINE_RWLOCK(break_hook_lock);
280 280
281void register_break_hook(struct break_hook *hook) 281void register_break_hook(struct break_hook *hook)
282{ 282{
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 0b281fffda51..61035d6814cb 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -384,26 +384,18 @@ ENDPROC(__calc_phys_offset)
384 * Preserves: tbl, flags 384 * Preserves: tbl, flags
385 * Corrupts: phys, start, end, pstate 385 * Corrupts: phys, start, end, pstate
386 */ 386 */
387 .macro create_block_map, tbl, flags, phys, start, end, idmap=0 387 .macro create_block_map, tbl, flags, phys, start, end
388 lsr \phys, \phys, #BLOCK_SHIFT 388 lsr \phys, \phys, #BLOCK_SHIFT
389 .if \idmap
390 and \start, \phys, #PTRS_PER_PTE - 1 // table index
391 .else
392 lsr \start, \start, #BLOCK_SHIFT 389 lsr \start, \start, #BLOCK_SHIFT
393 and \start, \start, #PTRS_PER_PTE - 1 // table index 390 and \start, \start, #PTRS_PER_PTE - 1 // table index
394 .endif
395 orr \phys, \flags, \phys, lsl #BLOCK_SHIFT // table entry 391 orr \phys, \flags, \phys, lsl #BLOCK_SHIFT // table entry
396 .ifnc \start,\end
397 lsr \end, \end, #BLOCK_SHIFT 392 lsr \end, \end, #BLOCK_SHIFT
398 and \end, \end, #PTRS_PER_PTE - 1 // table end index 393 and \end, \end, #PTRS_PER_PTE - 1 // table end index
399 .endif
4009999: str \phys, [\tbl, \start, lsl #3] // store the entry 3949999: str \phys, [\tbl, \start, lsl #3] // store the entry
401 .ifnc \start,\end
402 add \start, \start, #1 // next entry 395 add \start, \start, #1 // next entry
403 add \phys, \phys, #BLOCK_SIZE // next block 396 add \phys, \phys, #BLOCK_SIZE // next block
404 cmp \start, \end 397 cmp \start, \end
405 b.ls 9999b 398 b.ls 9999b
406 .endif
407 .endm 399 .endm
408 400
409/* 401/*
@@ -435,9 +427,13 @@ __create_page_tables:
435 * Create the identity mapping. 427 * Create the identity mapping.
436 */ 428 */
437 add x0, x25, #PAGE_SIZE // section table address 429 add x0, x25, #PAGE_SIZE // section table address
438 adr x3, __turn_mmu_on // virtual/physical address 430 ldr x3, =KERNEL_START
431 add x3, x3, x28 // __pa(KERNEL_START)
439 create_pgd_entry x25, x0, x3, x5, x6 432 create_pgd_entry x25, x0, x3, x5, x6
440 create_block_map x0, x7, x3, x5, x5, idmap=1 433 ldr x6, =KERNEL_END
434 mov x5, x3 // __pa(KERNEL_START)
435 add x6, x6, x28 // __pa(KERNEL_END)
436 create_block_map x0, x7, x3, x5, x6
441 437
442 /* 438 /*
443 * Map the kernel image (starting with PHYS_OFFSET). 439 * Map the kernel image (starting with PHYS_OFFSET).
@@ -445,7 +441,7 @@ __create_page_tables:
445 add x0, x26, #PAGE_SIZE // section table address 441 add x0, x26, #PAGE_SIZE // section table address
446 mov x5, #PAGE_OFFSET 442 mov x5, #PAGE_OFFSET
447 create_pgd_entry x26, x0, x5, x3, x6 443 create_pgd_entry x26, x0, x5, x3, x6
448 ldr x6, =KERNEL_END - 1 444 ldr x6, =KERNEL_END
449 mov x3, x24 // phys offset 445 mov x3, x24 // phys offset
450 create_block_map x0, x7, x3, x5, x6 446 create_block_map x0, x7, x3, x5, x6
451 447
diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c
new file mode 100644
index 000000000000..75c9cf1aafee
--- /dev/null
+++ b/arch/arm64/kernel/kgdb.c
@@ -0,0 +1,336 @@
1/*
2 * AArch64 KGDB support
3 *
4 * Based on arch/arm/kernel/kgdb.c
5 *
6 * Copyright (C) 2013 Cavium Inc.
7 * Author: Vijaya Kumar K <vijaya.kumar@caviumnetworks.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <linux/irq.h>
23#include <linux/kdebug.h>
24#include <linux/kgdb.h>
25#include <asm/traps.h>
26
27struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
28 { "x0", 8, offsetof(struct pt_regs, regs[0])},
29 { "x1", 8, offsetof(struct pt_regs, regs[1])},
30 { "x2", 8, offsetof(struct pt_regs, regs[2])},
31 { "x3", 8, offsetof(struct pt_regs, regs[3])},
32 { "x4", 8, offsetof(struct pt_regs, regs[4])},
33 { "x5", 8, offsetof(struct pt_regs, regs[5])},
34 { "x6", 8, offsetof(struct pt_regs, regs[6])},
35 { "x7", 8, offsetof(struct pt_regs, regs[7])},
36 { "x8", 8, offsetof(struct pt_regs, regs[8])},
37 { "x9", 8, offsetof(struct pt_regs, regs[9])},
38 { "x10", 8, offsetof(struct pt_regs, regs[10])},
39 { "x11", 8, offsetof(struct pt_regs, regs[11])},
40 { "x12", 8, offsetof(struct pt_regs, regs[12])},
41 { "x13", 8, offsetof(struct pt_regs, regs[13])},
42 { "x14", 8, offsetof(struct pt_regs, regs[14])},
43 { "x15", 8, offsetof(struct pt_regs, regs[15])},
44 { "x16", 8, offsetof(struct pt_regs, regs[16])},
45 { "x17", 8, offsetof(struct pt_regs, regs[17])},
46 { "x18", 8, offsetof(struct pt_regs, regs[18])},
47 { "x19", 8, offsetof(struct pt_regs, regs[19])},
48 { "x20", 8, offsetof(struct pt_regs, regs[20])},
49 { "x21", 8, offsetof(struct pt_regs, regs[21])},
50 { "x22", 8, offsetof(struct pt_regs, regs[22])},
51 { "x23", 8, offsetof(struct pt_regs, regs[23])},
52 { "x24", 8, offsetof(struct pt_regs, regs[24])},
53 { "x25", 8, offsetof(struct pt_regs, regs[25])},
54 { "x26", 8, offsetof(struct pt_regs, regs[26])},
55 { "x27", 8, offsetof(struct pt_regs, regs[27])},
56 { "x28", 8, offsetof(struct pt_regs, regs[28])},
57 { "x29", 8, offsetof(struct pt_regs, regs[29])},
58 { "x30", 8, offsetof(struct pt_regs, regs[30])},
59 { "sp", 8, offsetof(struct pt_regs, sp)},
60 { "pc", 8, offsetof(struct pt_regs, pc)},
61 { "pstate", 8, offsetof(struct pt_regs, pstate)},
62 { "v0", 16, -1 },
63 { "v1", 16, -1 },
64 { "v2", 16, -1 },
65 { "v3", 16, -1 },
66 { "v4", 16, -1 },
67 { "v5", 16, -1 },
68 { "v6", 16, -1 },
69 { "v7", 16, -1 },
70 { "v8", 16, -1 },
71 { "v9", 16, -1 },
72 { "v10", 16, -1 },
73 { "v11", 16, -1 },
74 { "v12", 16, -1 },
75 { "v13", 16, -1 },
76 { "v14", 16, -1 },
77 { "v15", 16, -1 },
78 { "v16", 16, -1 },
79 { "v17", 16, -1 },
80 { "v18", 16, -1 },
81 { "v19", 16, -1 },
82 { "v20", 16, -1 },
83 { "v21", 16, -1 },
84 { "v22", 16, -1 },
85 { "v23", 16, -1 },
86 { "v24", 16, -1 },
87 { "v25", 16, -1 },
88 { "v26", 16, -1 },
89 { "v27", 16, -1 },
90 { "v28", 16, -1 },
91 { "v29", 16, -1 },
92 { "v30", 16, -1 },
93 { "v31", 16, -1 },
94 { "fpsr", 4, -1 },
95 { "fpcr", 4, -1 },
96};
97
98char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
99{
100 if (regno >= DBG_MAX_REG_NUM || regno < 0)
101 return NULL;
102
103 if (dbg_reg_def[regno].offset != -1)
104 memcpy(mem, (void *)regs + dbg_reg_def[regno].offset,
105 dbg_reg_def[regno].size);
106 else
107 memset(mem, 0, dbg_reg_def[regno].size);
108 return dbg_reg_def[regno].name;
109}
110
111int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
112{
113 if (regno >= DBG_MAX_REG_NUM || regno < 0)
114 return -EINVAL;
115
116 if (dbg_reg_def[regno].offset != -1)
117 memcpy((void *)regs + dbg_reg_def[regno].offset, mem,
118 dbg_reg_def[regno].size);
119 return 0;
120}
121
122void
123sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
124{
125 struct pt_regs *thread_regs;
126
127 /* Initialize to zero */
128 memset((char *)gdb_regs, 0, NUMREGBYTES);
129 thread_regs = task_pt_regs(task);
130 memcpy((void *)gdb_regs, (void *)thread_regs->regs, GP_REG_BYTES);
131}
132
133void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
134{
135 regs->pc = pc;
136}
137
138static int compiled_break;
139
140static void kgdb_arch_update_addr(struct pt_regs *regs,
141 char *remcom_in_buffer)
142{
143 unsigned long addr;
144 char *ptr;
145
146 ptr = &remcom_in_buffer[1];
147 if (kgdb_hex2long(&ptr, &addr))
148 kgdb_arch_set_pc(regs, addr);
149 else if (compiled_break == 1)
150 kgdb_arch_set_pc(regs, regs->pc + 4);
151
152 compiled_break = 0;
153}
154
155int kgdb_arch_handle_exception(int exception_vector, int signo,
156 int err_code, char *remcom_in_buffer,
157 char *remcom_out_buffer,
158 struct pt_regs *linux_regs)
159{
160 int err;
161
162 switch (remcom_in_buffer[0]) {
163 case 'D':
164 case 'k':
165 /*
166 * Packet D (Detach), k (kill). No special handling
167 * is required here. Handle same as c packet.
168 */
169 case 'c':
170 /*
171 * Packet c (Continue) to continue executing.
172 * Set pc to required address.
173 * Try to read optional parameter and set pc.
174 * If this was a compiled breakpoint, we need to move
175 * to the next instruction else we will just breakpoint
176 * over and over again.
177 */
178 kgdb_arch_update_addr(linux_regs, remcom_in_buffer);
179 atomic_set(&kgdb_cpu_doing_single_step, -1);
180 kgdb_single_step = 0;
181
182 /*
183 * Received continue command, disable single step
184 */
185 if (kernel_active_single_step())
186 kernel_disable_single_step();
187
188 err = 0;
189 break;
190 case 's':
191 /*
192 * Update step address value with address passed
193 * with step packet.
194 * On debug exception return PC is copied to ELR
195 * So just update PC.
196 * If no step address is passed, resume from the address
197 * pointed by PC. Do not update PC
198 */
199 kgdb_arch_update_addr(linux_regs, remcom_in_buffer);
200 atomic_set(&kgdb_cpu_doing_single_step, raw_smp_processor_id());
201 kgdb_single_step = 1;
202
203 /*
204 * Enable single step handling
205 */
206 if (!kernel_active_single_step())
207 kernel_enable_single_step(linux_regs);
208 err = 0;
209 break;
210 default:
211 err = -1;
212 }
213 return err;
214}
215
216static int kgdb_brk_fn(struct pt_regs *regs, unsigned int esr)
217{
218 kgdb_handle_exception(1, SIGTRAP, 0, regs);
219 return 0;
220}
221
222static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr)
223{
224 compiled_break = 1;
225 kgdb_handle_exception(1, SIGTRAP, 0, regs);
226
227 return 0;
228}
229
230static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr)
231{
232 kgdb_handle_exception(1, SIGTRAP, 0, regs);
233 return 0;
234}
235
236static struct break_hook kgdb_brkpt_hook = {
237 .esr_mask = 0xffffffff,
238 .esr_val = DBG_ESR_VAL_BRK(KGDB_DYN_DGB_BRK_IMM),
239 .fn = kgdb_brk_fn
240};
241
242static struct break_hook kgdb_compiled_brkpt_hook = {
243 .esr_mask = 0xffffffff,
244 .esr_val = DBG_ESR_VAL_BRK(KDBG_COMPILED_DBG_BRK_IMM),
245 .fn = kgdb_compiled_brk_fn
246};
247
248static struct step_hook kgdb_step_hook = {
249 .fn = kgdb_step_brk_fn
250};
251
252static void kgdb_call_nmi_hook(void *ignored)
253{
254 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
255}
256
257void kgdb_roundup_cpus(unsigned long flags)
258{
259 local_irq_enable();
260 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
261 local_irq_disable();
262}
263
264static int __kgdb_notify(struct die_args *args, unsigned long cmd)
265{
266 struct pt_regs *regs = args->regs;
267
268 if (kgdb_handle_exception(1, args->signr, cmd, regs))
269 return NOTIFY_DONE;
270 return NOTIFY_STOP;
271}
272
273static int
274kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
275{
276 unsigned long flags;
277 int ret;
278
279 local_irq_save(flags);
280 ret = __kgdb_notify(ptr, cmd);
281 local_irq_restore(flags);
282
283 return ret;
284}
285
286static struct notifier_block kgdb_notifier = {
287 .notifier_call = kgdb_notify,
288 /*
289 * Want to be lowest priority
290 */
291 .priority = -INT_MAX,
292};
293
294/*
295 * kgdb_arch_init - Perform any architecture specific initalization.
296 * This function will handle the initalization of any architecture
297 * specific callbacks.
298 */
299int kgdb_arch_init(void)
300{
301 int ret = register_die_notifier(&kgdb_notifier);
302
303 if (ret != 0)
304 return ret;
305
306 register_break_hook(&kgdb_brkpt_hook);
307 register_break_hook(&kgdb_compiled_brkpt_hook);
308 register_step_hook(&kgdb_step_hook);
309 return 0;
310}
311
312/*
313 * kgdb_arch_exit - Perform any architecture specific uninitalization.
314 * This function will handle the uninitalization of any architecture
315 * specific callbacks, for dynamic registration and unregistration.
316 */
317void kgdb_arch_exit(void)
318{
319 unregister_break_hook(&kgdb_brkpt_hook);
320 unregister_break_hook(&kgdb_compiled_brkpt_hook);
321 unregister_step_hook(&kgdb_step_hook);
322 unregister_die_notifier(&kgdb_notifier);
323}
324
325/*
326 * ARM instructions are always in LE.
327 * Break instruction is encoded in LE format
328 */
329struct kgdb_arch arch_kgdb_ops = {
330 .gdb_bpt_instr = {
331 KGDB_DYN_BRK_INS_BYTE0,
332 KGDB_DYN_BRK_INS_BYTE1,
333 KGDB_DYN_BRK_INS_BYTE2,
334 KGDB_DYN_BRK_INS_BYTE3,
335 }
336};
diff --git a/arch/arm64/kernel/kuser32.S b/arch/arm64/kernel/kuser32.S
index 63c48ffdf230..7787208e8cc6 100644
--- a/arch/arm64/kernel/kuser32.S
+++ b/arch/arm64/kernel/kuser32.S
@@ -38,12 +38,13 @@ __kuser_cmpxchg64: // 0xffff0f60
38 .inst 0xe92d00f0 // push {r4, r5, r6, r7} 38 .inst 0xe92d00f0 // push {r4, r5, r6, r7}
39 .inst 0xe1c040d0 // ldrd r4, r5, [r0] 39 .inst 0xe1c040d0 // ldrd r4, r5, [r0]
40 .inst 0xe1c160d0 // ldrd r6, r7, [r1] 40 .inst 0xe1c160d0 // ldrd r6, r7, [r1]
41 .inst 0xe1b20e9f // 1: ldaexd r0, r1, [r2] 41 .inst 0xe1b20f9f // 1: ldrexd r0, r1, [r2]
42 .inst 0xe0303004 // eors r3, r0, r4 42 .inst 0xe0303004 // eors r3, r0, r4
43 .inst 0x00313005 // eoreqs r3, r1, r5 43 .inst 0x00313005 // eoreqs r3, r1, r5
44 .inst 0x01a23e96 // stlexdeq r3, r6, [r2] 44 .inst 0x01a23e96 // stlexdeq r3, r6, [r2]
45 .inst 0x03330001 // teqeq r3, #1 45 .inst 0x03330001 // teqeq r3, #1
46 .inst 0x0afffff9 // beq 1b 46 .inst 0x0afffff9 // beq 1b
47 .inst 0xf57ff05b // dmb ish
47 .inst 0xe2730000 // rsbs r0, r3, #0 48 .inst 0xe2730000 // rsbs r0, r3, #0
48 .inst 0xe8bd00f0 // pop {r4, r5, r6, r7} 49 .inst 0xe8bd00f0 // pop {r4, r5, r6, r7}
49 .inst 0xe12fff1e // bx lr 50 .inst 0xe12fff1e // bx lr
@@ -55,11 +56,12 @@ __kuser_memory_barrier: // 0xffff0fa0
55 56
56 .align 5 57 .align 5
57__kuser_cmpxchg: // 0xffff0fc0 58__kuser_cmpxchg: // 0xffff0fc0
58 .inst 0xe1923e9f // 1: ldaex r3, [r2] 59 .inst 0xe1923f9f // 1: ldrex r3, [r2]
59 .inst 0xe0533000 // subs r3, r3, r0 60 .inst 0xe0533000 // subs r3, r3, r0
60 .inst 0x01823e91 // stlexeq r3, r1, [r2] 61 .inst 0x01823e91 // stlexeq r3, r1, [r2]
61 .inst 0x03330001 // teqeq r3, #1 62 .inst 0x03330001 // teqeq r3, #1
62 .inst 0x0afffffa // beq 1b 63 .inst 0x0afffffa // beq 1b
64 .inst 0xf57ff05b // dmb ish
63 .inst 0xe2730000 // rsbs r0, r3, #0 65 .inst 0xe2730000 // rsbs r0, r3, #0
64 .inst 0xe12fff1e // bx lr 66 .inst 0xe12fff1e // bx lr
65 67
diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index 5b1cd792274a..e868c72a7938 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -1348,8 +1348,8 @@ early_initcall(init_hw_perf_events);
1348 * Callchain handling code. 1348 * Callchain handling code.
1349 */ 1349 */
1350struct frame_tail { 1350struct frame_tail {
1351 struct frame_tail __user *fp; 1351 struct frame_tail __user *fp;
1352 unsigned long lr; 1352 unsigned long lr;
1353} __attribute__((packed)); 1353} __attribute__((packed));
1354 1354
1355/* 1355/*
@@ -1386,22 +1386,80 @@ user_backtrace(struct frame_tail __user *tail,
1386 return buftail.fp; 1386 return buftail.fp;
1387} 1387}
1388 1388
1389/*
1390 * The registers we're interested in are at the end of the variable
1391 * length saved register structure. The fp points at the end of this
1392 * structure so the address of this struct is:
1393 * (struct compat_frame_tail *)(xxx->fp)-1
1394 *
1395 * This code has been adapted from the ARM OProfile support.
1396 */
1397struct compat_frame_tail {
1398 compat_uptr_t fp; /* a (struct compat_frame_tail *) in compat mode */
1399 u32 sp;
1400 u32 lr;
1401} __attribute__((packed));
1402
1403static struct compat_frame_tail __user *
1404compat_user_backtrace(struct compat_frame_tail __user *tail,
1405 struct perf_callchain_entry *entry)
1406{
1407 struct compat_frame_tail buftail;
1408 unsigned long err;
1409
1410 /* Also check accessibility of one struct frame_tail beyond */
1411 if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
1412 return NULL;
1413
1414 pagefault_disable();
1415 err = __copy_from_user_inatomic(&buftail, tail, sizeof(buftail));
1416 pagefault_enable();
1417
1418 if (err)
1419 return NULL;
1420
1421 perf_callchain_store(entry, buftail.lr);
1422
1423 /*
1424 * Frame pointers should strictly progress back up the stack
1425 * (towards higher addresses).
1426 */
1427 if (tail + 1 >= (struct compat_frame_tail __user *)
1428 compat_ptr(buftail.fp))
1429 return NULL;
1430
1431 return (struct compat_frame_tail __user *)compat_ptr(buftail.fp) - 1;
1432}
1433
1389void perf_callchain_user(struct perf_callchain_entry *entry, 1434void perf_callchain_user(struct perf_callchain_entry *entry,
1390 struct pt_regs *regs) 1435 struct pt_regs *regs)
1391{ 1436{
1392 struct frame_tail __user *tail;
1393
1394 if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { 1437 if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
1395 /* We don't support guest os callchain now */ 1438 /* We don't support guest os callchain now */
1396 return; 1439 return;
1397 } 1440 }
1398 1441
1399 perf_callchain_store(entry, regs->pc); 1442 perf_callchain_store(entry, regs->pc);
1400 tail = (struct frame_tail __user *)regs->regs[29];
1401 1443
1402 while (entry->nr < PERF_MAX_STACK_DEPTH && 1444 if (!compat_user_mode(regs)) {
1403 tail && !((unsigned long)tail & 0xf)) 1445 /* AARCH64 mode */
1404 tail = user_backtrace(tail, entry); 1446 struct frame_tail __user *tail;
1447
1448 tail = (struct frame_tail __user *)regs->regs[29];
1449
1450 while (entry->nr < PERF_MAX_STACK_DEPTH &&
1451 tail && !((unsigned long)tail & 0xf))
1452 tail = user_backtrace(tail, entry);
1453 } else {
1454 /* AARCH32 compat mode */
1455 struct compat_frame_tail __user *tail;
1456
1457 tail = (struct compat_frame_tail __user *)regs->compat_fp - 1;
1458
1459 while ((entry->nr < PERF_MAX_STACK_DEPTH) &&
1460 tail && !((unsigned long)tail & 0x3))
1461 tail = compat_user_backtrace(tail, entry);
1462 }
1405} 1463}
1406 1464
1407/* 1465/*
@@ -1429,6 +1487,7 @@ void perf_callchain_kernel(struct perf_callchain_entry *entry,
1429 frame.fp = regs->regs[29]; 1487 frame.fp = regs->regs[29];
1430 frame.sp = regs->sp; 1488 frame.sp = regs->sp;
1431 frame.pc = regs->pc; 1489 frame.pc = regs->pc;
1490
1432 walk_stackframe(&frame, callchain_trace, entry); 1491 walk_stackframe(&frame, callchain_trace, entry);
1433} 1492}
1434 1493
diff --git a/arch/arm64/kernel/perf_regs.c b/arch/arm64/kernel/perf_regs.c
new file mode 100644
index 000000000000..f2d6f0a36d63
--- /dev/null
+++ b/arch/arm64/kernel/perf_regs.c
@@ -0,0 +1,44 @@
1#include <linux/errno.h>
2#include <linux/kernel.h>
3#include <linux/perf_event.h>
4#include <linux/bug.h>
5#include <asm/perf_regs.h>
6#include <asm/ptrace.h>
7
8u64 perf_reg_value(struct pt_regs *regs, int idx)
9{
10 if (WARN_ON_ONCE((u32)idx >= PERF_REG_ARM64_MAX))
11 return 0;
12
13 /*
14 * Compat (i.e. 32 bit) mode:
15 * - PC has been set in the pt_regs struct in kernel_entry,
16 * - Handle SP and LR here.
17 */
18 if (compat_user_mode(regs)) {
19 if ((u32)idx == PERF_REG_ARM64_SP)
20 return regs->compat_sp;
21 if ((u32)idx == PERF_REG_ARM64_LR)
22 return regs->compat_lr;
23 }
24
25 return regs->regs[idx];
26}
27
28#define REG_RESERVED (~((1ULL << PERF_REG_ARM64_MAX) - 1))
29
30int perf_reg_validate(u64 mask)
31{
32 if (!mask || mask & REG_RESERVED)
33 return -EINVAL;
34
35 return 0;
36}
37
38u64 perf_reg_abi(struct task_struct *task)
39{
40 if (is_compat_thread(task_thread_info(task)))
41 return PERF_SAMPLE_REGS_ABI_32;
42 else
43 return PERF_SAMPLE_REGS_ABI_64;
44}
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 1c0a9be2ffa8..6391485f342d 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -33,7 +33,6 @@
33#include <linux/kallsyms.h> 33#include <linux/kallsyms.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/cpu.h> 35#include <linux/cpu.h>
36#include <linux/cpuidle.h>
37#include <linux/elfcore.h> 36#include <linux/elfcore.h>
38#include <linux/pm.h> 37#include <linux/pm.h>
39#include <linux/tick.h> 38#include <linux/tick.h>
@@ -72,8 +71,17 @@ static void setup_restart(void)
72 71
73void soft_restart(unsigned long addr) 72void soft_restart(unsigned long addr)
74{ 73{
74 typedef void (*phys_reset_t)(unsigned long);
75 phys_reset_t phys_reset;
76
75 setup_restart(); 77 setup_restart();
76 cpu_reset(addr); 78
79 /* Switch to the identity mapping */
80 phys_reset = (phys_reset_t)virt_to_phys(cpu_reset);
81 phys_reset(addr);
82
83 /* Should never get here */
84 BUG();
77} 85}
78 86
79/* 87/*
@@ -94,10 +102,8 @@ void arch_cpu_idle(void)
94 * This should do all the clock switching and wait for interrupt 102 * This should do all the clock switching and wait for interrupt
95 * tricks 103 * tricks
96 */ 104 */
97 if (cpuidle_idle_call()) { 105 cpu_do_idle();
98 cpu_do_idle(); 106 local_irq_enable();
99 local_irq_enable();
100 }
101} 107}
102 108
103#ifdef CONFIG_HOTPLUG_CPU 109#ifdef CONFIG_HOTPLUG_CPU
diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
index 4f97db3d7363..ea4828a4aa96 100644
--- a/arch/arm64/kernel/psci.c
+++ b/arch/arm64/kernel/psci.c
@@ -176,22 +176,20 @@ static const struct of_device_id psci_of_match[] __initconst = {
176 {}, 176 {},
177}; 177};
178 178
179int __init psci_init(void) 179void __init psci_init(void)
180{ 180{
181 struct device_node *np; 181 struct device_node *np;
182 const char *method; 182 const char *method;
183 u32 id; 183 u32 id;
184 int err = 0;
185 184
186 np = of_find_matching_node(NULL, psci_of_match); 185 np = of_find_matching_node(NULL, psci_of_match);
187 if (!np) 186 if (!np)
188 return -ENODEV; 187 return;
189 188
190 pr_info("probing function IDs from device-tree\n"); 189 pr_info("probing function IDs from device-tree\n");
191 190
192 if (of_property_read_string(np, "method", &method)) { 191 if (of_property_read_string(np, "method", &method)) {
193 pr_warning("missing \"method\" property\n"); 192 pr_warning("missing \"method\" property\n");
194 err = -ENXIO;
195 goto out_put_node; 193 goto out_put_node;
196 } 194 }
197 195
@@ -201,7 +199,6 @@ int __init psci_init(void)
201 invoke_psci_fn = __invoke_psci_fn_smc; 199 invoke_psci_fn = __invoke_psci_fn_smc;
202 } else { 200 } else {
203 pr_warning("invalid \"method\" property: %s\n", method); 201 pr_warning("invalid \"method\" property: %s\n", method);
204 err = -EINVAL;
205 goto out_put_node; 202 goto out_put_node;
206 } 203 }
207 204
@@ -227,7 +224,7 @@ int __init psci_init(void)
227 224
228out_put_node: 225out_put_node:
229 of_node_put(np); 226 of_node_put(np);
230 return err; 227 return;
231} 228}
232 229
233#ifdef CONFIG_SMP 230#ifdef CONFIG_SMP
@@ -251,7 +248,7 @@ static int cpu_psci_cpu_boot(unsigned int cpu)
251{ 248{
252 int err = psci_ops.cpu_on(cpu_logical_map(cpu), __pa(secondary_entry)); 249 int err = psci_ops.cpu_on(cpu_logical_map(cpu), __pa(secondary_entry));
253 if (err) 250 if (err)
254 pr_err("psci: failed to boot CPU%d (%d)\n", cpu, err); 251 pr_err("failed to boot CPU%d (%d)\n", cpu, err);
255 252
256 return err; 253 return err;
257} 254}
@@ -278,7 +275,7 @@ static void cpu_psci_cpu_die(unsigned int cpu)
278 275
279 ret = psci_ops.cpu_off(state); 276 ret = psci_ops.cpu_off(state);
280 277
281 pr_crit("psci: unable to power off CPU%u (%d)\n", cpu, ret); 278 pr_crit("unable to power off CPU%u (%d)\n", cpu, ret);
282} 279}
283#endif 280#endif
284 281
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index c8e9effe52e1..67da30741a1b 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -69,6 +69,7 @@ EXPORT_SYMBOL_GPL(elf_hwcap);
69 COMPAT_HWCAP_VFPv3|COMPAT_HWCAP_VFPv4|\ 69 COMPAT_HWCAP_VFPv3|COMPAT_HWCAP_VFPv4|\
70 COMPAT_HWCAP_NEON|COMPAT_HWCAP_IDIV) 70 COMPAT_HWCAP_NEON|COMPAT_HWCAP_IDIV)
71unsigned int compat_elf_hwcap __read_mostly = COMPAT_ELF_HWCAP_DEFAULT; 71unsigned int compat_elf_hwcap __read_mostly = COMPAT_ELF_HWCAP_DEFAULT;
72unsigned int compat_elf_hwcap2 __read_mostly;
72#endif 73#endif
73 74
74static const char *cpu_name; 75static const char *cpu_name;
@@ -242,6 +243,38 @@ static void __init setup_processor(void)
242 block = (features >> 16) & 0xf; 243 block = (features >> 16) & 0xf;
243 if (block && !(block & 0x8)) 244 if (block && !(block & 0x8))
244 elf_hwcap |= HWCAP_CRC32; 245 elf_hwcap |= HWCAP_CRC32;
246
247#ifdef CONFIG_COMPAT
248 /*
249 * ID_ISAR5_EL1 carries similar information as above, but pertaining to
250 * the Aarch32 32-bit execution state.
251 */
252 features = read_cpuid(ID_ISAR5_EL1);
253 block = (features >> 4) & 0xf;
254 if (!(block & 0x8)) {
255 switch (block) {
256 default:
257 case 2:
258 compat_elf_hwcap2 |= COMPAT_HWCAP2_PMULL;
259 case 1:
260 compat_elf_hwcap2 |= COMPAT_HWCAP2_AES;
261 case 0:
262 break;
263 }
264 }
265
266 block = (features >> 8) & 0xf;
267 if (block && !(block & 0x8))
268 compat_elf_hwcap2 |= COMPAT_HWCAP2_SHA1;
269
270 block = (features >> 12) & 0xf;
271 if (block && !(block & 0x8))
272 compat_elf_hwcap2 |= COMPAT_HWCAP2_SHA2;
273
274 block = (features >> 16) & 0xf;
275 if (block && !(block & 0x8))
276 compat_elf_hwcap2 |= COMPAT_HWCAP2_CRC32;
277#endif
245} 278}
246 279
247static void __init setup_machine_fdt(phys_addr_t dt_phys) 280static void __init setup_machine_fdt(phys_addr_t dt_phys)
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 7cfb92a4ab66..f0a141dd5655 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -114,6 +114,11 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
114 return ret; 114 return ret;
115} 115}
116 116
117static void smp_store_cpu_info(unsigned int cpuid)
118{
119 store_cpu_topology(cpuid);
120}
121
117/* 122/*
118 * This is the secondary CPU boot entry. We're using this CPUs 123 * This is the secondary CPU boot entry. We're using this CPUs
119 * idle thread stack, but a set of temporary page tables. 124 * idle thread stack, but a set of temporary page tables.
@@ -152,6 +157,8 @@ asmlinkage void secondary_start_kernel(void)
152 */ 157 */
153 notify_cpu_starting(cpu); 158 notify_cpu_starting(cpu);
154 159
160 smp_store_cpu_info(cpu);
161
155 /* 162 /*
156 * OK, now it's safe to let the boot CPU continue. Wait for 163 * OK, now it's safe to let the boot CPU continue. Wait for
157 * the CPU migration code to notice that the CPU is online 164 * the CPU migration code to notice that the CPU is online
@@ -160,6 +167,7 @@ asmlinkage void secondary_start_kernel(void)
160 set_cpu_online(cpu, true); 167 set_cpu_online(cpu, true);
161 complete(&cpu_running); 168 complete(&cpu_running);
162 169
170 local_dbg_enable();
163 local_irq_enable(); 171 local_irq_enable();
164 local_async_enable(); 172 local_async_enable();
165 173
@@ -390,6 +398,10 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
390 int err; 398 int err;
391 unsigned int cpu, ncores = num_possible_cpus(); 399 unsigned int cpu, ncores = num_possible_cpus();
392 400
401 init_cpu_topology();
402
403 smp_store_cpu_info(smp_processor_id());
404
393 /* 405 /*
394 * are we trying to boot more cores than exist? 406 * are we trying to boot more cores than exist?
395 */ 407 */
diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c
index 44c22805d2e2..7a530d2cc807 100644
--- a/arch/arm64/kernel/smp_spin_table.c
+++ b/arch/arm64/kernel/smp_spin_table.c
@@ -128,7 +128,7 @@ static int smp_spin_table_cpu_boot(unsigned int cpu)
128 return secondary_holding_pen_release != INVALID_HWID ? -ENOSYS : 0; 128 return secondary_holding_pen_release != INVALID_HWID ? -ENOSYS : 0;
129} 129}
130 130
131void smp_spin_table_cpu_postboot(void) 131static void smp_spin_table_cpu_postboot(void)
132{ 132{
133 /* 133 /*
134 * Let the primary processor know we're out of the pen. 134 * Let the primary processor know we're out of the pen.
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index c3b6c63ea5fb..38f0558f0c0a 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -48,7 +48,11 @@ int unwind_frame(struct stackframe *frame)
48 48
49 frame->sp = fp + 0x10; 49 frame->sp = fp + 0x10;
50 frame->fp = *(unsigned long *)(fp); 50 frame->fp = *(unsigned long *)(fp);
51 frame->pc = *(unsigned long *)(fp + 8); 51 /*
52 * -4 here because we care about the PC at time of bl,
53 * not where the return will go.
54 */
55 frame->pc = *(unsigned long *)(fp + 8) - 4;
52 56
53 return 0; 57 return 0;
54} 58}
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
new file mode 100644
index 000000000000..3e06b0be4ec8
--- /dev/null
+++ b/arch/arm64/kernel/topology.c
@@ -0,0 +1,95 @@
1/*
2 * arch/arm64/kernel/topology.c
3 *
4 * Copyright (C) 2011,2013,2014 Linaro Limited.
5 *
6 * Based on the arm32 version written by Vincent Guittot in turn based on
7 * arch/sh/kernel/topology.c
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13
14#include <linux/cpu.h>
15#include <linux/cpumask.h>
16#include <linux/init.h>
17#include <linux/percpu.h>
18#include <linux/node.h>
19#include <linux/nodemask.h>
20#include <linux/sched.h>
21
22#include <asm/topology.h>
23
24/*
25 * cpu topology table
26 */
27struct cpu_topology cpu_topology[NR_CPUS];
28EXPORT_SYMBOL_GPL(cpu_topology);
29
30const struct cpumask *cpu_coregroup_mask(int cpu)
31{
32 return &cpu_topology[cpu].core_sibling;
33}
34
35static void update_siblings_masks(unsigned int cpuid)
36{
37 struct cpu_topology *cpu_topo, *cpuid_topo = &cpu_topology[cpuid];
38 int cpu;
39
40 if (cpuid_topo->cluster_id == -1) {
41 /*
42 * DT does not contain topology information for this cpu
43 * reset it to default behaviour
44 */
45 pr_debug("CPU%u: No topology information configured\n", cpuid);
46 cpuid_topo->core_id = 0;
47 cpumask_set_cpu(cpuid, &cpuid_topo->core_sibling);
48 cpumask_set_cpu(cpuid, &cpuid_topo->thread_sibling);
49 return;
50 }
51
52 /* update core and thread sibling masks */
53 for_each_possible_cpu(cpu) {
54 cpu_topo = &cpu_topology[cpu];
55
56 if (cpuid_topo->cluster_id != cpu_topo->cluster_id)
57 continue;
58
59 cpumask_set_cpu(cpuid, &cpu_topo->core_sibling);
60 if (cpu != cpuid)
61 cpumask_set_cpu(cpu, &cpuid_topo->core_sibling);
62
63 if (cpuid_topo->core_id != cpu_topo->core_id)
64 continue;
65
66 cpumask_set_cpu(cpuid, &cpu_topo->thread_sibling);
67 if (cpu != cpuid)
68 cpumask_set_cpu(cpu, &cpuid_topo->thread_sibling);
69 }
70}
71
72void store_cpu_topology(unsigned int cpuid)
73{
74 update_siblings_masks(cpuid);
75}
76
77/*
78 * init_cpu_topology is called at boot when only one cpu is running
79 * which prevent simultaneous write access to cpu_topology array
80 */
81void __init init_cpu_topology(void)
82{
83 unsigned int cpu;
84
85 /* init core mask and power*/
86 for_each_possible_cpu(cpu) {
87 struct cpu_topology *cpu_topo = &cpu_topology[cpu];
88
89 cpu_topo->thread_id = -1;
90 cpu_topo->core_id = -1;
91 cpu_topo->cluster_id = -1;
92 cpumask_clear(&cpu_topo->core_sibling);
93 cpumask_clear(&cpu_topo->thread_sibling);
94 }
95}
diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 65d40cf6945a..50384fec56c4 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -106,49 +106,31 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp)
106 106
107static int __init vdso_init(void) 107static int __init vdso_init(void)
108{ 108{
109 struct page *pg; 109 int i;
110 char *vbase; 110
111 int i, ret = 0; 111 if (memcmp(&vdso_start, "\177ELF", 4)) {
112 pr_err("vDSO is not a valid ELF object!\n");
113 return -EINVAL;
114 }
112 115
113 vdso_pages = (&vdso_end - &vdso_start) >> PAGE_SHIFT; 116 vdso_pages = (&vdso_end - &vdso_start) >> PAGE_SHIFT;
114 pr_info("vdso: %ld pages (%ld code, %ld data) at base %p\n", 117 pr_info("vdso: %ld pages (%ld code, %ld data) at base %p\n",
115 vdso_pages + 1, vdso_pages, 1L, &vdso_start); 118 vdso_pages + 1, vdso_pages, 1L, &vdso_start);
116 119
117 /* Allocate the vDSO pagelist, plus a page for the data. */ 120 /* Allocate the vDSO pagelist, plus a page for the data. */
118 vdso_pagelist = kzalloc(sizeof(struct page *) * (vdso_pages + 1), 121 vdso_pagelist = kcalloc(vdso_pages + 1, sizeof(struct page *),
119 GFP_KERNEL); 122 GFP_KERNEL);
120 if (vdso_pagelist == NULL) { 123 if (vdso_pagelist == NULL)
121 pr_err("Failed to allocate vDSO pagelist!\n");
122 return -ENOMEM; 124 return -ENOMEM;
123 }
124 125
125 /* Grab the vDSO code pages. */ 126 /* Grab the vDSO code pages. */
126 for (i = 0; i < vdso_pages; i++) { 127 for (i = 0; i < vdso_pages; i++)
127 pg = virt_to_page(&vdso_start + i*PAGE_SIZE); 128 vdso_pagelist[i] = virt_to_page(&vdso_start + i * PAGE_SIZE);
128 ClearPageReserved(pg);
129 get_page(pg);
130 vdso_pagelist[i] = pg;
131 }
132
133 /* Sanity check the shared object header. */
134 vbase = vmap(vdso_pagelist, 1, 0, PAGE_KERNEL);
135 if (vbase == NULL) {
136 pr_err("Failed to map vDSO pagelist!\n");
137 return -ENOMEM;
138 } else if (memcmp(vbase, "\177ELF", 4)) {
139 pr_err("vDSO is not a valid ELF object!\n");
140 ret = -EINVAL;
141 goto unmap;
142 }
143 129
144 /* Grab the vDSO data page. */ 130 /* Grab the vDSO data page. */
145 pg = virt_to_page(vdso_data); 131 vdso_pagelist[i] = virt_to_page(vdso_data);
146 get_page(pg);
147 vdso_pagelist[i] = pg;
148 132
149unmap: 133 return 0;
150 vunmap(vbase);
151 return ret;
152} 134}
153arch_initcall(vdso_init); 135arch_initcall(vdso_init);
154 136
@@ -238,6 +220,8 @@ void update_vsyscall(struct timekeeper *tk)
238 vdso_data->use_syscall = use_syscall; 220 vdso_data->use_syscall = use_syscall;
239 vdso_data->xtime_coarse_sec = xtime_coarse.tv_sec; 221 vdso_data->xtime_coarse_sec = xtime_coarse.tv_sec;
240 vdso_data->xtime_coarse_nsec = xtime_coarse.tv_nsec; 222 vdso_data->xtime_coarse_nsec = xtime_coarse.tv_nsec;
223 vdso_data->wtm_clock_sec = tk->wall_to_monotonic.tv_sec;
224 vdso_data->wtm_clock_nsec = tk->wall_to_monotonic.tv_nsec;
241 225
242 if (!use_syscall) { 226 if (!use_syscall) {
243 vdso_data->cs_cycle_last = tk->clock->cycle_last; 227 vdso_data->cs_cycle_last = tk->clock->cycle_last;
@@ -245,8 +229,6 @@ void update_vsyscall(struct timekeeper *tk)
245 vdso_data->xtime_clock_nsec = tk->xtime_nsec; 229 vdso_data->xtime_clock_nsec = tk->xtime_nsec;
246 vdso_data->cs_mult = tk->mult; 230 vdso_data->cs_mult = tk->mult;
247 vdso_data->cs_shift = tk->shift; 231 vdso_data->cs_shift = tk->shift;
248 vdso_data->wtm_clock_sec = tk->wall_to_monotonic.tv_sec;
249 vdso_data->wtm_clock_nsec = tk->wall_to_monotonic.tv_nsec;
250 } 232 }
251 233
252 smp_wmb(); 234 smp_wmb();
diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile
index d8064af42e62..6d20b7d162d8 100644
--- a/arch/arm64/kernel/vdso/Makefile
+++ b/arch/arm64/kernel/vdso/Makefile
@@ -48,7 +48,7 @@ $(obj-vdso): %.o: %.S
48 48
49# Actual build commands 49# Actual build commands
50quiet_cmd_vdsold = VDSOL $@ 50quiet_cmd_vdsold = VDSOL $@
51 cmd_vdsold = $(CC) $(c_flags) -Wl,-T $^ -o $@ 51 cmd_vdsold = $(CC) $(c_flags) -Wl,-n -Wl,-T $^ -o $@
52quiet_cmd_vdsoas = VDSOA $@ 52quiet_cmd_vdsoas = VDSOA $@
53 cmd_vdsoas = $(CC) $(a_flags) -c -o $@ $< 53 cmd_vdsoas = $(CC) $(a_flags) -c -o $@ $<
54 54
diff --git a/arch/arm64/kernel/vdso/gettimeofday.S b/arch/arm64/kernel/vdso/gettimeofday.S
index f0a6d10b5211..fe652ffd34c2 100644
--- a/arch/arm64/kernel/vdso/gettimeofday.S
+++ b/arch/arm64/kernel/vdso/gettimeofday.S
@@ -103,6 +103,8 @@ ENTRY(__kernel_clock_gettime)
103 bl __do_get_tspec 103 bl __do_get_tspec
104 seqcnt_check w9, 1b 104 seqcnt_check w9, 1b
105 105
106 mov x30, x2
107
106 cmp w0, #CLOCK_MONOTONIC 108 cmp w0, #CLOCK_MONOTONIC
107 b.ne 6f 109 b.ne 6f
108 110
@@ -118,6 +120,9 @@ ENTRY(__kernel_clock_gettime)
118 ccmp w0, #CLOCK_MONOTONIC_COARSE, #0x4, ne 120 ccmp w0, #CLOCK_MONOTONIC_COARSE, #0x4, ne
119 b.ne 8f 121 b.ne 8f
120 122
123 /* xtime_coarse_nsec is already right-shifted */
124 mov x12, #0
125
121 /* Get coarse timespec. */ 126 /* Get coarse timespec. */
122 adr vdso_data, _vdso_data 127 adr vdso_data, _vdso_data
1233: seqcnt_acquire 1283: seqcnt_acquire
@@ -156,7 +161,7 @@ ENTRY(__kernel_clock_gettime)
156 lsr x11, x11, x12 161 lsr x11, x11, x12
157 stp x10, x11, [x1, #TSPEC_TV_SEC] 162 stp x10, x11, [x1, #TSPEC_TV_SEC]
158 mov x0, xzr 163 mov x0, xzr
159 ret x2 164 ret
1607: 1657:
161 mov x30, x2 166 mov x30, x2
1628: /* Syscall fallback. */ 1678: /* Syscall fallback. */
diff --git a/arch/arm64/kvm/hyp-init.S b/arch/arm64/kvm/hyp-init.S
index 2b0244d65c16..d968796f4b2d 100644
--- a/arch/arm64/kvm/hyp-init.S
+++ b/arch/arm64/kvm/hyp-init.S
@@ -68,6 +68,12 @@ __do_hyp_init:
68 msr tcr_el2, x4 68 msr tcr_el2, x4
69 69
70 ldr x4, =VTCR_EL2_FLAGS 70 ldr x4, =VTCR_EL2_FLAGS
71 /*
72 * Read the PARange bits from ID_AA64MMFR0_EL1 and set the PS bits in
73 * VTCR_EL2.
74 */
75 mrs x5, ID_AA64MMFR0_EL1
76 bfi x4, x5, #16, #3
71 msr vtcr_el2, x4 77 msr vtcr_el2, x4
72 78
73 mrs x4, mair_el1 79 mrs x4, mair_el1
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index 3b47c36e10ff..2c56012cb2d2 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -694,6 +694,24 @@ __hyp_panic_str:
694 694
695 .align 2 695 .align 2
696 696
697/*
698 * u64 kvm_call_hyp(void *hypfn, ...);
699 *
700 * This is not really a variadic function in the classic C-way and care must
701 * be taken when calling this to ensure parameters are passed in registers
702 * only, since the stack will change between the caller and the callee.
703 *
704 * Call the function with the first argument containing a pointer to the
705 * function you wish to call in Hyp mode, and subsequent arguments will be
706 * passed as x0, x1, and x2 (a maximum of 3 arguments in addition to the
707 * function pointer can be passed). The function being called must be mapped
708 * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are
709 * passed in r0 and r1.
710 *
711 * A function pointer with a value of 0 has a special meaning, and is
712 * used to implement __hyp_get_vectors in the same way as in
713 * arch/arm64/kernel/hyp_stub.S.
714 */
697ENTRY(kvm_call_hyp) 715ENTRY(kvm_call_hyp)
698 hvc #0 716 hvc #0
699 ret 717 ret
@@ -737,7 +755,12 @@ el1_sync: // Guest trapped into EL2
737 pop x2, x3 755 pop x2, x3
738 pop x0, x1 756 pop x0, x1
739 757
740 push lr, xzr 758 /* Check for __hyp_get_vectors */
759 cbnz x0, 1f
760 mrs x0, vbar_el2
761 b 2f
762
7631: push lr, xzr
741 764
742 /* 765 /*
743 * Compute the function address in EL2, and shuffle the parameters. 766 * Compute the function address in EL2, and shuffle the parameters.
@@ -750,7 +773,7 @@ el1_sync: // Guest trapped into EL2
750 blr lr 773 blr lr
751 774
752 pop lr, xzr 775 pop lr, xzr
753 eret 7762: eret
754 777
755el1_trap: 778el1_trap:
756 /* 779 /*
diff --git a/arch/arm64/lib/bitops.S b/arch/arm64/lib/bitops.S
index e5db797790d3..7dac371cc9a2 100644
--- a/arch/arm64/lib/bitops.S
+++ b/arch/arm64/lib/bitops.S
@@ -46,11 +46,12 @@ ENTRY( \name )
46 mov x2, #1 46 mov x2, #1
47 add x1, x1, x0, lsr #3 // Get word offset 47 add x1, x1, x0, lsr #3 // Get word offset
48 lsl x4, x2, x3 // Create mask 48 lsl x4, x2, x3 // Create mask
491: ldaxr x2, [x1] 491: ldxr x2, [x1]
50 lsr x0, x2, x3 // Save old value of bit 50 lsr x0, x2, x3 // Save old value of bit
51 \instr x2, x2, x4 // toggle bit 51 \instr x2, x2, x4 // toggle bit
52 stlxr w5, x2, [x1] 52 stlxr w5, x2, [x1]
53 cbnz w5, 1b 53 cbnz w5, 1b
54 dmb ish
54 and x0, x0, #1 55 and x0, x0, #1
553: ret 563: ret
56ENDPROC(\name ) 57ENDPROC(\name )
diff --git a/arch/arm64/mm/cache.S b/arch/arm64/mm/cache.S
index 1ea9f26d1b70..c46f48b33c14 100644
--- a/arch/arm64/mm/cache.S
+++ b/arch/arm64/mm/cache.S
@@ -30,7 +30,7 @@
30 * 30 *
31 * Corrupted registers: x0-x7, x9-x11 31 * Corrupted registers: x0-x7, x9-x11
32 */ 32 */
33ENTRY(__flush_dcache_all) 33__flush_dcache_all:
34 dsb sy // ensure ordering with previous memory accesses 34 dsb sy // ensure ordering with previous memory accesses
35 mrs x0, clidr_el1 // read clidr 35 mrs x0, clidr_el1 // read clidr
36 and x3, x0, #0x7000000 // extract loc from clidr 36 and x3, x0, #0x7000000 // extract loc from clidr
@@ -166,3 +166,81 @@ ENTRY(__flush_dcache_area)
166 dsb sy 166 dsb sy
167 ret 167 ret
168ENDPROC(__flush_dcache_area) 168ENDPROC(__flush_dcache_area)
169
170/*
171 * __dma_inv_range(start, end)
172 * - start - virtual start address of region
173 * - end - virtual end address of region
174 */
175__dma_inv_range:
176 dcache_line_size x2, x3
177 sub x3, x2, #1
178 bic x0, x0, x3
179 bic x1, x1, x3
1801: dc ivac, x0 // invalidate D / U line
181 add x0, x0, x2
182 cmp x0, x1
183 b.lo 1b
184 dsb sy
185 ret
186ENDPROC(__dma_inv_range)
187
188/*
189 * __dma_clean_range(start, end)
190 * - start - virtual start address of region
191 * - end - virtual end address of region
192 */
193__dma_clean_range:
194 dcache_line_size x2, x3
195 sub x3, x2, #1
196 bic x0, x0, x3
1971: dc cvac, x0 // clean D / U line
198 add x0, x0, x2
199 cmp x0, x1
200 b.lo 1b
201 dsb sy
202 ret
203ENDPROC(__dma_clean_range)
204
205/*
206 * __dma_flush_range(start, end)
207 * - start - virtual start address of region
208 * - end - virtual end address of region
209 */
210ENTRY(__dma_flush_range)
211 dcache_line_size x2, x3
212 sub x3, x2, #1
213 bic x0, x0, x3
2141: dc civac, x0 // clean & invalidate D / U line
215 add x0, x0, x2
216 cmp x0, x1
217 b.lo 1b
218 dsb sy
219 ret
220ENDPROC(__dma_flush_range)
221
222/*
223 * __dma_map_area(start, size, dir)
224 * - start - kernel virtual start address
225 * - size - size of region
226 * - dir - DMA direction
227 */
228ENTRY(__dma_map_area)
229 add x1, x1, x0
230 cmp w2, #DMA_FROM_DEVICE
231 b.eq __dma_inv_range
232 b __dma_clean_range
233ENDPROC(__dma_map_area)
234
235/*
236 * __dma_unmap_area(start, size, dir)
237 * - start - kernel virtual start address
238 * - size - size of region
239 * - dir - DMA direction
240 */
241ENTRY(__dma_unmap_area)
242 add x1, x1, x0
243 cmp w2, #DMA_TO_DEVICE
244 b.ne __dma_inv_range
245 ret
246ENDPROC(__dma_unmap_area)
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 45b5ab54c9ee..0ba347e59f06 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -30,21 +30,30 @@
30struct dma_map_ops *dma_ops; 30struct dma_map_ops *dma_ops;
31EXPORT_SYMBOL(dma_ops); 31EXPORT_SYMBOL(dma_ops);
32 32
33static void *arm64_swiotlb_alloc_coherent(struct device *dev, size_t size, 33static pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot,
34 dma_addr_t *dma_handle, gfp_t flags, 34 bool coherent)
35 struct dma_attrs *attrs) 35{
36 if (!coherent || dma_get_attr(DMA_ATTR_WRITE_COMBINE, attrs))
37 return pgprot_writecombine(prot);
38 return prot;
39}
40
41static void *__dma_alloc_coherent(struct device *dev, size_t size,
42 dma_addr_t *dma_handle, gfp_t flags,
43 struct dma_attrs *attrs)
36{ 44{
37 if (dev == NULL) { 45 if (dev == NULL) {
38 WARN_ONCE(1, "Use an actual device structure for DMA allocation\n"); 46 WARN_ONCE(1, "Use an actual device structure for DMA allocation\n");
39 return NULL; 47 return NULL;
40 } 48 }
41 49
42 if (IS_ENABLED(CONFIG_ZONE_DMA32) && 50 if (IS_ENABLED(CONFIG_ZONE_DMA) &&
43 dev->coherent_dma_mask <= DMA_BIT_MASK(32)) 51 dev->coherent_dma_mask <= DMA_BIT_MASK(32))
44 flags |= GFP_DMA32; 52 flags |= GFP_DMA;
45 if (IS_ENABLED(CONFIG_DMA_CMA)) { 53 if (IS_ENABLED(CONFIG_DMA_CMA)) {
46 struct page *page; 54 struct page *page;
47 55
56 size = PAGE_ALIGN(size);
48 page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT, 57 page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT,
49 get_order(size)); 58 get_order(size));
50 if (!page) 59 if (!page)
@@ -57,9 +66,9 @@ static void *arm64_swiotlb_alloc_coherent(struct device *dev, size_t size,
57 } 66 }
58} 67}
59 68
60static void arm64_swiotlb_free_coherent(struct device *dev, size_t size, 69static void __dma_free_coherent(struct device *dev, size_t size,
61 void *vaddr, dma_addr_t dma_handle, 70 void *vaddr, dma_addr_t dma_handle,
62 struct dma_attrs *attrs) 71 struct dma_attrs *attrs)
63{ 72{
64 if (dev == NULL) { 73 if (dev == NULL) {
65 WARN_ONCE(1, "Use an actual device structure for DMA allocation\n"); 74 WARN_ONCE(1, "Use an actual device structure for DMA allocation\n");
@@ -77,9 +86,212 @@ static void arm64_swiotlb_free_coherent(struct device *dev, size_t size,
77 } 86 }
78} 87}
79 88
80static struct dma_map_ops arm64_swiotlb_dma_ops = { 89static void *__dma_alloc_noncoherent(struct device *dev, size_t size,
81 .alloc = arm64_swiotlb_alloc_coherent, 90 dma_addr_t *dma_handle, gfp_t flags,
82 .free = arm64_swiotlb_free_coherent, 91 struct dma_attrs *attrs)
92{
93 struct page *page, **map;
94 void *ptr, *coherent_ptr;
95 int order, i;
96
97 size = PAGE_ALIGN(size);
98 order = get_order(size);
99
100 ptr = __dma_alloc_coherent(dev, size, dma_handle, flags, attrs);
101 if (!ptr)
102 goto no_mem;
103 map = kmalloc(sizeof(struct page *) << order, flags & ~GFP_DMA);
104 if (!map)
105 goto no_map;
106
107 /* remove any dirty cache lines on the kernel alias */
108 __dma_flush_range(ptr, ptr + size);
109
110 /* create a coherent mapping */
111 page = virt_to_page(ptr);
112 for (i = 0; i < (size >> PAGE_SHIFT); i++)
113 map[i] = page + i;
114 coherent_ptr = vmap(map, size >> PAGE_SHIFT, VM_MAP,
115 __get_dma_pgprot(attrs, pgprot_default, false));
116 kfree(map);
117 if (!coherent_ptr)
118 goto no_map;
119
120 return coherent_ptr;
121
122no_map:
123 __dma_free_coherent(dev, size, ptr, *dma_handle, attrs);
124no_mem:
125 *dma_handle = ~0;
126 return NULL;
127}
128
129static void __dma_free_noncoherent(struct device *dev, size_t size,
130 void *vaddr, dma_addr_t dma_handle,
131 struct dma_attrs *attrs)
132{
133 void *swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle));
134
135 vunmap(vaddr);
136 __dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs);
137}
138
139static dma_addr_t __swiotlb_map_page(struct device *dev, struct page *page,
140 unsigned long offset, size_t size,
141 enum dma_data_direction dir,
142 struct dma_attrs *attrs)
143{
144 dma_addr_t dev_addr;
145
146 dev_addr = swiotlb_map_page(dev, page, offset, size, dir, attrs);
147 __dma_map_area(phys_to_virt(dma_to_phys(dev, dev_addr)), size, dir);
148
149 return dev_addr;
150}
151
152
153static void __swiotlb_unmap_page(struct device *dev, dma_addr_t dev_addr,
154 size_t size, enum dma_data_direction dir,
155 struct dma_attrs *attrs)
156{
157 __dma_unmap_area(phys_to_virt(dma_to_phys(dev, dev_addr)), size, dir);
158 swiotlb_unmap_page(dev, dev_addr, size, dir, attrs);
159}
160
161static int __swiotlb_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
162 int nelems, enum dma_data_direction dir,
163 struct dma_attrs *attrs)
164{
165 struct scatterlist *sg;
166 int i, ret;
167
168 ret = swiotlb_map_sg_attrs(dev, sgl, nelems, dir, attrs);
169 for_each_sg(sgl, sg, ret, i)
170 __dma_map_area(phys_to_virt(dma_to_phys(dev, sg->dma_address)),
171 sg->length, dir);
172
173 return ret;
174}
175
176static void __swiotlb_unmap_sg_attrs(struct device *dev,
177 struct scatterlist *sgl, int nelems,
178 enum dma_data_direction dir,
179 struct dma_attrs *attrs)
180{
181 struct scatterlist *sg;
182 int i;
183
184 for_each_sg(sgl, sg, nelems, i)
185 __dma_unmap_area(phys_to_virt(dma_to_phys(dev, sg->dma_address)),
186 sg->length, dir);
187 swiotlb_unmap_sg_attrs(dev, sgl, nelems, dir, attrs);
188}
189
190static void __swiotlb_sync_single_for_cpu(struct device *dev,
191 dma_addr_t dev_addr, size_t size,
192 enum dma_data_direction dir)
193{
194 __dma_unmap_area(phys_to_virt(dma_to_phys(dev, dev_addr)), size, dir);
195 swiotlb_sync_single_for_cpu(dev, dev_addr, size, dir);
196}
197
198static void __swiotlb_sync_single_for_device(struct device *dev,
199 dma_addr_t dev_addr, size_t size,
200 enum dma_data_direction dir)
201{
202 swiotlb_sync_single_for_device(dev, dev_addr, size, dir);
203 __dma_map_area(phys_to_virt(dma_to_phys(dev, dev_addr)), size, dir);
204}
205
206static void __swiotlb_sync_sg_for_cpu(struct device *dev,
207 struct scatterlist *sgl, int nelems,
208 enum dma_data_direction dir)
209{
210 struct scatterlist *sg;
211 int i;
212
213 for_each_sg(sgl, sg, nelems, i)
214 __dma_unmap_area(phys_to_virt(dma_to_phys(dev, sg->dma_address)),
215 sg->length, dir);
216 swiotlb_sync_sg_for_cpu(dev, sgl, nelems, dir);
217}
218
219static void __swiotlb_sync_sg_for_device(struct device *dev,
220 struct scatterlist *sgl, int nelems,
221 enum dma_data_direction dir)
222{
223 struct scatterlist *sg;
224 int i;
225
226 swiotlb_sync_sg_for_device(dev, sgl, nelems, dir);
227 for_each_sg(sgl, sg, nelems, i)
228 __dma_map_area(phys_to_virt(dma_to_phys(dev, sg->dma_address)),
229 sg->length, dir);
230}
231
232/* vma->vm_page_prot must be set appropriately before calling this function */
233static int __dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
234 void *cpu_addr, dma_addr_t dma_addr, size_t size)
235{
236 int ret = -ENXIO;
237 unsigned long nr_vma_pages = (vma->vm_end - vma->vm_start) >>
238 PAGE_SHIFT;
239 unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
240 unsigned long pfn = dma_to_phys(dev, dma_addr) >> PAGE_SHIFT;
241 unsigned long off = vma->vm_pgoff;
242
243 if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret))
244 return ret;
245
246 if (off < nr_pages && nr_vma_pages <= (nr_pages - off)) {
247 ret = remap_pfn_range(vma, vma->vm_start,
248 pfn + off,
249 vma->vm_end - vma->vm_start,
250 vma->vm_page_prot);
251 }
252
253 return ret;
254}
255
256static int __swiotlb_mmap_noncoherent(struct device *dev,
257 struct vm_area_struct *vma,
258 void *cpu_addr, dma_addr_t dma_addr, size_t size,
259 struct dma_attrs *attrs)
260{
261 vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot, false);
262 return __dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
263}
264
265static int __swiotlb_mmap_coherent(struct device *dev,
266 struct vm_area_struct *vma,
267 void *cpu_addr, dma_addr_t dma_addr, size_t size,
268 struct dma_attrs *attrs)
269{
270 /* Just use whatever page_prot attributes were specified */
271 return __dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
272}
273
274struct dma_map_ops noncoherent_swiotlb_dma_ops = {
275 .alloc = __dma_alloc_noncoherent,
276 .free = __dma_free_noncoherent,
277 .mmap = __swiotlb_mmap_noncoherent,
278 .map_page = __swiotlb_map_page,
279 .unmap_page = __swiotlb_unmap_page,
280 .map_sg = __swiotlb_map_sg_attrs,
281 .unmap_sg = __swiotlb_unmap_sg_attrs,
282 .sync_single_for_cpu = __swiotlb_sync_single_for_cpu,
283 .sync_single_for_device = __swiotlb_sync_single_for_device,
284 .sync_sg_for_cpu = __swiotlb_sync_sg_for_cpu,
285 .sync_sg_for_device = __swiotlb_sync_sg_for_device,
286 .dma_supported = swiotlb_dma_supported,
287 .mapping_error = swiotlb_dma_mapping_error,
288};
289EXPORT_SYMBOL(noncoherent_swiotlb_dma_ops);
290
291struct dma_map_ops coherent_swiotlb_dma_ops = {
292 .alloc = __dma_alloc_coherent,
293 .free = __dma_free_coherent,
294 .mmap = __swiotlb_mmap_coherent,
83 .map_page = swiotlb_map_page, 295 .map_page = swiotlb_map_page,
84 .unmap_page = swiotlb_unmap_page, 296 .unmap_page = swiotlb_unmap_page,
85 .map_sg = swiotlb_map_sg_attrs, 297 .map_sg = swiotlb_map_sg_attrs,
@@ -91,12 +303,19 @@ static struct dma_map_ops arm64_swiotlb_dma_ops = {
91 .dma_supported = swiotlb_dma_supported, 303 .dma_supported = swiotlb_dma_supported,
92 .mapping_error = swiotlb_dma_mapping_error, 304 .mapping_error = swiotlb_dma_mapping_error,
93}; 305};
306EXPORT_SYMBOL(coherent_swiotlb_dma_ops);
307
308extern int swiotlb_late_init_with_default_size(size_t default_size);
94 309
95void __init arm64_swiotlb_init(void) 310static int __init swiotlb_late_init(void)
96{ 311{
97 dma_ops = &arm64_swiotlb_dma_ops; 312 size_t swiotlb_size = min(SZ_64M, MAX_ORDER_NR_PAGES << PAGE_SHIFT);
98 swiotlb_init(1); 313
314 dma_ops = &coherent_swiotlb_dma_ops;
315
316 return swiotlb_late_init_with_default_size(swiotlb_size);
99} 317}
318subsys_initcall(swiotlb_late_init);
100 319
101#define PREALLOC_DMA_DEBUG_ENTRIES 4096 320#define PREALLOC_DMA_DEBUG_ENTRIES 4096
102 321
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index d0b4c2efda90..88627c450a6c 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -30,6 +30,7 @@
30#include <linux/memblock.h> 30#include <linux/memblock.h>
31#include <linux/sort.h> 31#include <linux/sort.h>
32#include <linux/of_fdt.h> 32#include <linux/of_fdt.h>
33#include <linux/dma-mapping.h>
33#include <linux/dma-contiguous.h> 34#include <linux/dma-contiguous.h>
34 35
35#include <asm/sections.h> 36#include <asm/sections.h>
@@ -59,22 +60,22 @@ static int __init early_initrd(char *p)
59early_param("initrd", early_initrd); 60early_param("initrd", early_initrd);
60#endif 61#endif
61 62
62#define MAX_DMA32_PFN ((4UL * 1024 * 1024 * 1024) >> PAGE_SHIFT)
63
64static void __init zone_sizes_init(unsigned long min, unsigned long max) 63static void __init zone_sizes_init(unsigned long min, unsigned long max)
65{ 64{
66 struct memblock_region *reg; 65 struct memblock_region *reg;
67 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES]; 66 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
68 unsigned long max_dma32 = min; 67 unsigned long max_dma = min;
69 68
70 memset(zone_size, 0, sizeof(zone_size)); 69 memset(zone_size, 0, sizeof(zone_size));
71 70
72#ifdef CONFIG_ZONE_DMA32
73 /* 4GB maximum for 32-bit only capable devices */ 71 /* 4GB maximum for 32-bit only capable devices */
74 max_dma32 = max(min, min(max, MAX_DMA32_PFN)); 72 if (IS_ENABLED(CONFIG_ZONE_DMA)) {
75 zone_size[ZONE_DMA32] = max_dma32 - min; 73 unsigned long max_dma_phys =
76#endif 74 (unsigned long)dma_to_phys(NULL, DMA_BIT_MASK(32) + 1);
77 zone_size[ZONE_NORMAL] = max - max_dma32; 75 max_dma = max(min, min(max, max_dma_phys >> PAGE_SHIFT));
76 zone_size[ZONE_DMA] = max_dma - min;
77 }
78 zone_size[ZONE_NORMAL] = max - max_dma;
78 79
79 memcpy(zhole_size, zone_size, sizeof(zhole_size)); 80 memcpy(zhole_size, zone_size, sizeof(zhole_size));
80 81
@@ -84,15 +85,15 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)
84 85
85 if (start >= max) 86 if (start >= max)
86 continue; 87 continue;
87#ifdef CONFIG_ZONE_DMA32 88
88 if (start < max_dma32) { 89 if (IS_ENABLED(CONFIG_ZONE_DMA) && start < max_dma) {
89 unsigned long dma_end = min(end, max_dma32); 90 unsigned long dma_end = min(end, max_dma);
90 zhole_size[ZONE_DMA32] -= dma_end - start; 91 zhole_size[ZONE_DMA] -= dma_end - start;
91 } 92 }
92#endif 93
93 if (end > max_dma32) { 94 if (end > max_dma) {
94 unsigned long normal_end = min(end, max); 95 unsigned long normal_end = min(end, max);
95 unsigned long normal_start = max(start, max_dma32); 96 unsigned long normal_start = max(start, max_dma);
96 zhole_size[ZONE_NORMAL] -= normal_end - normal_start; 97 zhole_size[ZONE_NORMAL] -= normal_end - normal_start;
97 } 98 }
98 } 99 }
@@ -261,8 +262,6 @@ static void __init free_unused_memmap(void)
261 */ 262 */
262void __init mem_init(void) 263void __init mem_init(void)
263{ 264{
264 arm64_swiotlb_init();
265
266 max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map; 265 max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map;
267 266
268#ifndef CONFIG_SPARSEMEM_VMEMMAP 267#ifndef CONFIG_SPARSEMEM_VMEMMAP
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index f557ebbe7013..f8dc7e8fce6f 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -203,10 +203,18 @@ static void __init alloc_init_pmd(pud_t *pud, unsigned long addr,
203 do { 203 do {
204 next = pmd_addr_end(addr, end); 204 next = pmd_addr_end(addr, end);
205 /* try section mapping first */ 205 /* try section mapping first */
206 if (((addr | next | phys) & ~SECTION_MASK) == 0) 206 if (((addr | next | phys) & ~SECTION_MASK) == 0) {
207 pmd_t old_pmd =*pmd;
207 set_pmd(pmd, __pmd(phys | prot_sect_kernel)); 208 set_pmd(pmd, __pmd(phys | prot_sect_kernel));
208 else 209 /*
210 * Check for previous table entries created during
211 * boot (__create_page_tables) and flush them.
212 */
213 if (!pmd_none(old_pmd))
214 flush_tlb_all();
215 } else {
209 alloc_init_pte(pmd, addr, next, __phys_to_pfn(phys)); 216 alloc_init_pte(pmd, addr, next, __phys_to_pfn(phys));
217 }
210 phys += next - addr; 218 phys += next - addr;
211 } while (pmd++, addr = next, addr != end); 219 } while (pmd++, addr = next, addr != end);
212} 220}
diff --git a/arch/arm64/mm/pgd.c b/arch/arm64/mm/pgd.c
index 7083cdada657..62c6101df260 100644
--- a/arch/arm64/mm/pgd.c
+++ b/arch/arm64/mm/pgd.c
@@ -32,17 +32,10 @@
32 32
33pgd_t *pgd_alloc(struct mm_struct *mm) 33pgd_t *pgd_alloc(struct mm_struct *mm)
34{ 34{
35 pgd_t *new_pgd;
36
37 if (PGD_SIZE == PAGE_SIZE) 35 if (PGD_SIZE == PAGE_SIZE)
38 new_pgd = (pgd_t *)get_zeroed_page(GFP_KERNEL); 36 return (pgd_t *)get_zeroed_page(GFP_KERNEL);
39 else 37 else
40 new_pgd = kzalloc(PGD_SIZE, GFP_KERNEL); 38 return kzalloc(PGD_SIZE, GFP_KERNEL);
41
42 if (!new_pgd)
43 return NULL;
44
45 return new_pgd;
46} 39}
47 40
48void pgd_free(struct mm_struct *mm, pgd_t *pgd) 41void pgd_free(struct mm_struct *mm, pgd_t *pgd)
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 1333e6f9a8e5..e085ee6ef4e2 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -173,12 +173,6 @@ ENDPROC(cpu_do_switch_mm)
173 * value of the SCTLR_EL1 register. 173 * value of the SCTLR_EL1 register.
174 */ 174 */
175ENTRY(__cpu_setup) 175ENTRY(__cpu_setup)
176 /*
177 * Preserve the link register across the function call.
178 */
179 mov x28, lr
180 bl __flush_dcache_all
181 mov lr, x28
182 ic iallu // I+BTB cache invalidate 176 ic iallu // I+BTB cache invalidate
183 tlbi vmalle1is // invalidate I + D TLBs 177 tlbi vmalle1is // invalidate I + D TLBs
184 dsb sy 178 dsb sy
@@ -215,8 +209,14 @@ ENTRY(__cpu_setup)
215 * Set/prepare TCR and TTBR. We use 512GB (39-bit) address range for 209 * Set/prepare TCR and TTBR. We use 512GB (39-bit) address range for
216 * both user and kernel. 210 * both user and kernel.
217 */ 211 */
218 ldr x10, =TCR_TxSZ(VA_BITS) | TCR_FLAGS | TCR_IPS_40BIT | \ 212 ldr x10, =TCR_TxSZ(VA_BITS) | TCR_FLAGS | \
219 TCR_ASID16 | TCR_TBI0 | (1 << 31) 213 TCR_ASID16 | TCR_TBI0 | (1 << 31)
214 /*
215 * Read the PARange bits from ID_AA64MMFR0_EL1 and set the IPS bits in
216 * TCR_EL1.
217 */
218 mrs x9, ID_AA64MMFR0_EL1
219 bfi x10, x9, #32, #3
220#ifdef CONFIG_ARM64_64K_PAGES 220#ifdef CONFIG_ARM64_64K_PAGES
221 orr x10, x10, TCR_TG0_64K 221 orr x10, x10, TCR_TG0_64K
222 orr x10, x10, TCR_TG1_64K 222 orr x10, x10, TCR_TG1_64K
diff --git a/arch/avr32/Makefile b/arch/avr32/Makefile
index 22fb66590dcd..dba48a5d5bb9 100644
--- a/arch/avr32/Makefile
+++ b/arch/avr32/Makefile
@@ -11,7 +11,7 @@ all: uImage vmlinux.elf
11 11
12KBUILD_DEFCONFIG := atstk1002_defconfig 12KBUILD_DEFCONFIG := atstk1002_defconfig
13 13
14KBUILD_CFLAGS += -pipe -fno-builtin -mno-pic 14KBUILD_CFLAGS += -pipe -fno-builtin -mno-pic -D__linux__
15KBUILD_AFLAGS += -mrelax -mno-pic 15KBUILD_AFLAGS += -mrelax -mno-pic
16KBUILD_CFLAGS_MODULE += -mno-relax 16KBUILD_CFLAGS_MODULE += -mno-relax
17LDFLAGS_vmlinux += --relax 17LDFLAGS_vmlinux += --relax
diff --git a/arch/avr32/boards/mimc200/fram.c b/arch/avr32/boards/mimc200/fram.c
index 9764a1a1073e..c1466a872b9c 100644
--- a/arch/avr32/boards/mimc200/fram.c
+++ b/arch/avr32/boards/mimc200/fram.c
@@ -11,6 +11,7 @@
11#define FRAM_VERSION "1.0" 11#define FRAM_VERSION "1.0"
12 12
13#include <linux/miscdevice.h> 13#include <linux/miscdevice.h>
14#include <linux/module.h>
14#include <linux/proc_fs.h> 15#include <linux/proc_fs.h>
15#include <linux/mm.h> 16#include <linux/mm.h>
16#include <linux/io.h> 17#include <linux/io.h>
diff --git a/arch/avr32/include/asm/Kbuild b/arch/avr32/include/asm/Kbuild
index cfb9fe1b8df9..00a0f3ccd6eb 100644
--- a/arch/avr32/include/asm/Kbuild
+++ b/arch/avr32/include/asm/Kbuild
@@ -1,21 +1,23 @@
1 1
2generic-y += clkdev.h 2generic-y += clkdev.h
3generic-y += cputime.h 3generic-y += cputime.h
4generic-y += delay.h 4generic-y += delay.h
5generic-y += device.h 5generic-y += device.h
6generic-y += div64.h 6generic-y += div64.h
7generic-y += emergency-restart.h 7generic-y += emergency-restart.h
8generic-y += exec.h 8generic-y += exec.h
9generic-y += futex.h 9generic-y += futex.h
10generic-y += preempt.h 10generic-y += hash.h
11generic-y += irq_regs.h 11generic-y += irq_regs.h
12generic-y += param.h 12generic-y += local.h
13generic-y += local.h 13generic-y += local64.h
14generic-y += local64.h 14generic-y += mcs_spinlock.h
15generic-y += percpu.h 15generic-y += param.h
16generic-y += scatterlist.h 16generic-y += percpu.h
17generic-y += sections.h 17generic-y += preempt.h
18generic-y += topology.h 18generic-y += scatterlist.h
19generic-y += trace_clock.h 19generic-y += sections.h
20generic-y += xor.h 20generic-y += topology.h
21generic-y += hash.h 21generic-y += trace_clock.h
22generic-y += vga.h
23generic-y += xor.h
diff --git a/arch/avr32/include/asm/io.h b/arch/avr32/include/asm/io.h
index fc6483f83ccc..4f5ec2bb7172 100644
--- a/arch/avr32/include/asm/io.h
+++ b/arch/avr32/include/asm/io.h
@@ -295,6 +295,8 @@ extern void __iounmap(void __iomem *addr);
295#define iounmap(addr) \ 295#define iounmap(addr) \
296 __iounmap(addr) 296 __iounmap(addr)
297 297
298#define ioremap_wc ioremap_nocache
299
298#define cached(addr) P1SEGADDR(addr) 300#define cached(addr) P1SEGADDR(addr)
299#define uncached(addr) P2SEGADDR(addr) 301#define uncached(addr) P2SEGADDR(addr)
300 302
diff --git a/arch/blackfin/include/asm/Kbuild b/arch/blackfin/include/asm/Kbuild
index 359d36fdc247..0d93b9a79ca9 100644
--- a/arch/blackfin/include/asm/Kbuild
+++ b/arch/blackfin/include/asm/Kbuild
@@ -10,6 +10,7 @@ generic-y += emergency-restart.h
10generic-y += errno.h 10generic-y += errno.h
11generic-y += fb.h 11generic-y += fb.h
12generic-y += futex.h 12generic-y += futex.h
13generic-y += hash.h
13generic-y += hw_irq.h 14generic-y += hw_irq.h
14generic-y += ioctl.h 15generic-y += ioctl.h
15generic-y += ipcbuf.h 16generic-y += ipcbuf.h
@@ -17,14 +18,16 @@ generic-y += irq_regs.h
17generic-y += kdebug.h 18generic-y += kdebug.h
18generic-y += kmap_types.h 19generic-y += kmap_types.h
19generic-y += kvm_para.h 20generic-y += kvm_para.h
20generic-y += local64.h
21generic-y += local.h 21generic-y += local.h
22generic-y += local64.h
23generic-y += mcs_spinlock.h
22generic-y += mman.h 24generic-y += mman.h
23generic-y += msgbuf.h 25generic-y += msgbuf.h
24generic-y += mutex.h 26generic-y += mutex.h
25generic-y += param.h 27generic-y += param.h
26generic-y += percpu.h 28generic-y += percpu.h
27generic-y += pgalloc.h 29generic-y += pgalloc.h
30generic-y += preempt.h
28generic-y += resource.h 31generic-y += resource.h
29generic-y += scatterlist.h 32generic-y += scatterlist.h
30generic-y += sembuf.h 33generic-y += sembuf.h
@@ -44,5 +47,3 @@ generic-y += ucontext.h
44generic-y += unaligned.h 47generic-y += unaligned.h
45generic-y += user.h 48generic-y += user.h
46generic-y += xor.h 49generic-y += xor.h
47generic-y += preempt.h
48generic-y += hash.h
diff --git a/arch/c6x/include/asm/Kbuild b/arch/c6x/include/asm/Kbuild
index d73bb85ccdd3..8dbdce8421b0 100644
--- a/arch/c6x/include/asm/Kbuild
+++ b/arch/c6x/include/asm/Kbuild
@@ -15,6 +15,7 @@ generic-y += exec.h
15generic-y += fb.h 15generic-y += fb.h
16generic-y += fcntl.h 16generic-y += fcntl.h
17generic-y += futex.h 17generic-y += futex.h
18generic-y += hash.h
18generic-y += hw_irq.h 19generic-y += hw_irq.h
19generic-y += io.h 20generic-y += io.h
20generic-y += ioctl.h 21generic-y += ioctl.h
@@ -24,6 +25,7 @@ generic-y += irq_regs.h
24generic-y += kdebug.h 25generic-y += kdebug.h
25generic-y += kmap_types.h 26generic-y += kmap_types.h
26generic-y += local.h 27generic-y += local.h
28generic-y += mcs_spinlock.h
27generic-y += mman.h 29generic-y += mman.h
28generic-y += mmu.h 30generic-y += mmu.h
29generic-y += mmu_context.h 31generic-y += mmu_context.h
@@ -34,6 +36,7 @@ generic-y += percpu.h
34generic-y += pgalloc.h 36generic-y += pgalloc.h
35generic-y += poll.h 37generic-y += poll.h
36generic-y += posix_types.h 38generic-y += posix_types.h
39generic-y += preempt.h
37generic-y += resource.h 40generic-y += resource.h
38generic-y += scatterlist.h 41generic-y += scatterlist.h
39generic-y += segment.h 42generic-y += segment.h
@@ -56,5 +59,3 @@ generic-y += ucontext.h
56generic-y += user.h 59generic-y += user.h
57generic-y += vga.h 60generic-y += vga.h
58generic-y += xor.h 61generic-y += xor.h
59generic-y += preempt.h
60generic-y += hash.h
diff --git a/arch/c6x/include/asm/cache.h b/arch/c6x/include/asm/cache.h
index 09c5a0f5f4d1..86648c083bb4 100644
--- a/arch/c6x/include/asm/cache.h
+++ b/arch/c6x/include/asm/cache.h
@@ -12,6 +12,7 @@
12#define _ASM_C6X_CACHE_H 12#define _ASM_C6X_CACHE_H
13 13
14#include <linux/irqflags.h> 14#include <linux/irqflags.h>
15#include <linux/init.h>
15 16
16/* 17/*
17 * Cache line size 18 * Cache line size
diff --git a/arch/cris/include/asm/Kbuild b/arch/cris/include/asm/Kbuild
index f3fd8768f095..056027f38351 100644
--- a/arch/cris/include/asm/Kbuild
+++ b/arch/cris/include/asm/Kbuild
@@ -9,8 +9,9 @@ generic-y += exec.h
9generic-y += hash.h 9generic-y += hash.h
10generic-y += kvm_para.h 10generic-y += kvm_para.h
11generic-y += linkage.h 11generic-y += linkage.h
12generic-y += mcs_spinlock.h
12generic-y += module.h 13generic-y += module.h
14generic-y += preempt.h
13generic-y += trace_clock.h 15generic-y += trace_clock.h
14generic-y += vga.h 16generic-y += vga.h
15generic-y += xor.h 17generic-y += xor.h
16generic-y += preempt.h
diff --git a/arch/cris/include/asm/bitops.h b/arch/cris/include/asm/bitops.h
index 184066ceb1f6..053c17b36559 100644
--- a/arch/cris/include/asm/bitops.h
+++ b/arch/cris/include/asm/bitops.h
@@ -144,7 +144,7 @@ static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
144 * definition, which doesn't have the same semantics. We don't want to 144 * definition, which doesn't have the same semantics. We don't want to
145 * use -fno-builtin, so just hide the name ffs. 145 * use -fno-builtin, so just hide the name ffs.
146 */ 146 */
147#define ffs kernel_ffs 147#define ffs(x) kernel_ffs(x)
148 148
149#include <asm-generic/bitops/fls.h> 149#include <asm-generic/bitops/fls.h>
150#include <asm-generic/bitops/__fls.h> 150#include <asm-generic/bitops/__fls.h>
diff --git a/arch/frv/include/asm/Kbuild b/arch/frv/include/asm/Kbuild
index bc42f14c9c2e..babb9338ebf8 100644
--- a/arch/frv/include/asm/Kbuild
+++ b/arch/frv/include/asm/Kbuild
@@ -1,6 +1,7 @@
1 1
2generic-y += clkdev.h 2generic-y += clkdev.h
3generic-y += exec.h 3generic-y += exec.h
4generic-y += trace_clock.h
5generic-y += preempt.h
6generic-y += hash.h 4generic-y += hash.h
5generic-y += mcs_spinlock.h
6generic-y += preempt.h
7generic-y += trace_clock.h
diff --git a/arch/hexagon/include/asm/Kbuild b/arch/hexagon/include/asm/Kbuild
index 38ca45d3df1e..eadcc118f950 100644
--- a/arch/hexagon/include/asm/Kbuild
+++ b/arch/hexagon/include/asm/Kbuild
@@ -25,14 +25,16 @@ generic-y += ipcbuf.h
25generic-y += irq_regs.h 25generic-y += irq_regs.h
26generic-y += kdebug.h 26generic-y += kdebug.h
27generic-y += kmap_types.h 27generic-y += kmap_types.h
28generic-y += local64.h
29generic-y += local.h 28generic-y += local.h
29generic-y += local64.h
30generic-y += mcs_spinlock.h
30generic-y += mman.h 31generic-y += mman.h
31generic-y += msgbuf.h 32generic-y += msgbuf.h
32generic-y += pci.h 33generic-y += pci.h
33generic-y += percpu.h 34generic-y += percpu.h
34generic-y += poll.h 35generic-y += poll.h
35generic-y += posix_types.h 36generic-y += posix_types.h
37generic-y += preempt.h
36generic-y += resource.h 38generic-y += resource.h
37generic-y += rwsem.h 39generic-y += rwsem.h
38generic-y += scatterlist.h 40generic-y += scatterlist.h
@@ -45,8 +47,8 @@ generic-y += siginfo.h
45generic-y += sizes.h 47generic-y += sizes.h
46generic-y += socket.h 48generic-y += socket.h
47generic-y += sockios.h 49generic-y += sockios.h
48generic-y += statfs.h
49generic-y += stat.h 50generic-y += stat.h
51generic-y += statfs.h
50generic-y += termbits.h 52generic-y += termbits.h
51generic-y += termios.h 53generic-y += termios.h
52generic-y += topology.h 54generic-y += topology.h
@@ -55,4 +57,3 @@ generic-y += types.h
55generic-y += ucontext.h 57generic-y += ucontext.h
56generic-y += unaligned.h 58generic-y += unaligned.h
57generic-y += xor.h 59generic-y += xor.h
58generic-y += preempt.h
diff --git a/arch/ia64/configs/generic_defconfig b/arch/ia64/configs/generic_defconfig
index efbd2929aeb7..6404acbb84b2 100644
--- a/arch/ia64/configs/generic_defconfig
+++ b/arch/ia64/configs/generic_defconfig
@@ -30,9 +30,9 @@ CONFIG_ACPI_BUTTON=m
30CONFIG_ACPI_FAN=m 30CONFIG_ACPI_FAN=m
31CONFIG_ACPI_DOCK=y 31CONFIG_ACPI_DOCK=y
32CONFIG_ACPI_PROCESSOR=m 32CONFIG_ACPI_PROCESSOR=m
33CONFIG_ACPI_CONTAINER=m 33CONFIG_ACPI_CONTAINER=y
34CONFIG_HOTPLUG_PCI=y 34CONFIG_HOTPLUG_PCI=y
35CONFIG_HOTPLUG_PCI_ACPI=m 35CONFIG_HOTPLUG_PCI_ACPI=y
36CONFIG_PACKET=y 36CONFIG_PACKET=y
37CONFIG_UNIX=y 37CONFIG_UNIX=y
38CONFIG_INET=y 38CONFIG_INET=y
diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
index 8e858b593e4f..30c43d39dede 100644
--- a/arch/ia64/hp/common/sba_iommu.c
+++ b/arch/ia64/hp/common/sba_iommu.c
@@ -1596,7 +1596,7 @@ static void sba_unmap_sg_attrs(struct device *dev, struct scatterlist *sglist,
1596* 1596*
1597***************************************************************/ 1597***************************************************************/
1598 1598
1599static void __init 1599static void
1600ioc_iova_init(struct ioc *ioc) 1600ioc_iova_init(struct ioc *ioc)
1601{ 1601{
1602 int tcnfg; 1602 int tcnfg;
@@ -1807,7 +1807,7 @@ static struct ioc_iommu ioc_iommu_info[] __initdata = {
1807 { SX2000_IOC_ID, "sx2000", NULL }, 1807 { SX2000_IOC_ID, "sx2000", NULL },
1808}; 1808};
1809 1809
1810static struct ioc * __init 1810static struct ioc *
1811ioc_init(unsigned long hpa, void *handle) 1811ioc_init(unsigned long hpa, void *handle)
1812{ 1812{
1813 struct ioc *ioc; 1813 struct ioc *ioc;
@@ -2041,7 +2041,7 @@ sba_map_ioc_to_node(struct ioc *ioc, acpi_handle handle)
2041#define sba_map_ioc_to_node(ioc, handle) 2041#define sba_map_ioc_to_node(ioc, handle)
2042#endif 2042#endif
2043 2043
2044static int __init 2044static int
2045acpi_sba_ioc_add(struct acpi_device *device, 2045acpi_sba_ioc_add(struct acpi_device *device,
2046 const struct acpi_device_id *not_used) 2046 const struct acpi_device_id *not_used)
2047{ 2047{
diff --git a/arch/ia64/include/asm/Kbuild b/arch/ia64/include/asm/Kbuild
index 283a83154b5e..0da4aa2602ae 100644
--- a/arch/ia64/include/asm/Kbuild
+++ b/arch/ia64/include/asm/Kbuild
@@ -1,8 +1,9 @@
1 1
2generic-y += clkdev.h 2generic-y += clkdev.h
3generic-y += exec.h 3generic-y += exec.h
4generic-y += hash.h
4generic-y += kvm_para.h 5generic-y += kvm_para.h
5generic-y += trace_clock.h 6generic-y += mcs_spinlock.h
6generic-y += preempt.h 7generic-y += preempt.h
8generic-y += trace_clock.h
7generic-y += vtime.h 9generic-y += vtime.h
8generic-y += hash.h
diff --git a/arch/ia64/include/asm/topology.h b/arch/ia64/include/asm/topology.h
index a2496e449b75..5cb55a1e606b 100644
--- a/arch/ia64/include/asm/topology.h
+++ b/arch/ia64/include/asm/topology.h
@@ -77,7 +77,6 @@ void build_cpu_to_node_map(void);
77#define topology_core_id(cpu) (cpu_data(cpu)->core_id) 77#define topology_core_id(cpu) (cpu_data(cpu)->core_id)
78#define topology_core_cpumask(cpu) (&cpu_core_map[cpu]) 78#define topology_core_cpumask(cpu) (&cpu_core_map[cpu])
79#define topology_thread_cpumask(cpu) (&per_cpu(cpu_sibling_map, cpu)) 79#define topology_thread_cpumask(cpu) (&per_cpu(cpu_sibling_map, cpu))
80#define smt_capable() (smp_num_siblings > 1)
81#endif 80#endif
82 81
83extern void arch_fix_phys_package_id(int num, u32 slot); 82extern void arch_fix_phys_package_id(int num, u32 slot);
diff --git a/arch/ia64/include/asm/unistd.h b/arch/ia64/include/asm/unistd.h
index afd45e0d552e..ae763d8bf55a 100644
--- a/arch/ia64/include/asm/unistd.h
+++ b/arch/ia64/include/asm/unistd.h
@@ -11,7 +11,7 @@
11 11
12 12
13 13
14#define NR_syscalls 312 /* length of syscall table */ 14#define NR_syscalls 314 /* length of syscall table */
15 15
16/* 16/*
17 * The following defines stop scripts/checksyscalls.sh from complaining about 17 * The following defines stop scripts/checksyscalls.sh from complaining about
diff --git a/arch/ia64/include/uapi/asm/unistd.h b/arch/ia64/include/uapi/asm/unistd.h
index 34fd6fe46da1..715e85f858de 100644
--- a/arch/ia64/include/uapi/asm/unistd.h
+++ b/arch/ia64/include/uapi/asm/unistd.h
@@ -325,5 +325,7 @@
325#define __NR_process_vm_writev 1333 325#define __NR_process_vm_writev 1333
326#define __NR_accept4 1334 326#define __NR_accept4 1334
327#define __NR_finit_module 1335 327#define __NR_finit_module 1335
328#define __NR_sched_setattr 1336
329#define __NR_sched_getattr 1337
328 330
329#endif /* _UAPI_ASM_IA64_UNISTD_H */ 331#endif /* _UAPI_ASM_IA64_UNISTD_H */
diff --git a/arch/ia64/kernel/efi.c b/arch/ia64/kernel/efi.c
index da5b462e6de6..741b99c1a0b1 100644
--- a/arch/ia64/kernel/efi.c
+++ b/arch/ia64/kernel/efi.c
@@ -477,6 +477,9 @@ efi_init (void)
477 char *cp, vendor[100] = "unknown"; 477 char *cp, vendor[100] = "unknown";
478 int i; 478 int i;
479 479
480 set_bit(EFI_BOOT, &efi.flags);
481 set_bit(EFI_64BIT, &efi.flags);
482
480 /* 483 /*
481 * It's too early to be able to use the standard kernel command line 484 * It's too early to be able to use the standard kernel command line
482 * support... 485 * support...
@@ -529,6 +532,8 @@ efi_init (void)
529 efi.systab->hdr.revision >> 16, 532 efi.systab->hdr.revision >> 16,
530 efi.systab->hdr.revision & 0xffff, vendor); 533 efi.systab->hdr.revision & 0xffff, vendor);
531 534
535 set_bit(EFI_SYSTEM_TABLES, &efi.flags);
536
532 palo_phys = EFI_INVALID_TABLE_ADDR; 537 palo_phys = EFI_INVALID_TABLE_ADDR;
533 538
534 if (efi_config_init(arch_tables) != 0) 539 if (efi_config_init(arch_tables) != 0)
@@ -657,6 +662,8 @@ efi_enter_virtual_mode (void)
657 return; 662 return;
658 } 663 }
659 664
665 set_bit(EFI_RUNTIME_SERVICES, &efi.flags);
666
660 /* 667 /*
661 * Now that EFI is in virtual mode, we call the EFI functions more 668 * Now that EFI is in virtual mode, we call the EFI functions more
662 * efficiently: 669 * efficiently:
diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S
index ddea607f948a..fa8d61a312a7 100644
--- a/arch/ia64/kernel/entry.S
+++ b/arch/ia64/kernel/entry.S
@@ -1773,6 +1773,8 @@ sys_call_table:
1773 data8 sys_process_vm_writev 1773 data8 sys_process_vm_writev
1774 data8 sys_accept4 1774 data8 sys_accept4
1775 data8 sys_finit_module // 1335 1775 data8 sys_finit_module // 1335
1776 data8 sys_sched_setattr
1777 data8 sys_sched_getattr
1776 1778
1777 .org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls 1779 .org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls
1778#endif /* __IA64_ASM_PARAVIRTUALIZED_NATIVE */ 1780#endif /* __IA64_ASM_PARAVIRTUALIZED_NATIVE */
diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
index b8edfa75a83f..601502ab7141 100644
--- a/arch/ia64/kernel/mca.c
+++ b/arch/ia64/kernel/mca.c
@@ -217,7 +217,7 @@ void ia64_mca_printk(const char *fmt, ...)
217 /* Copy the output into mlogbuf */ 217 /* Copy the output into mlogbuf */
218 if (oops_in_progress) { 218 if (oops_in_progress) {
219 /* mlogbuf was abandoned, use printk directly instead. */ 219 /* mlogbuf was abandoned, use printk directly instead. */
220 printk(temp_buf); 220 printk("%s", temp_buf);
221 } else { 221 } else {
222 spin_lock(&mlogbuf_wlock); 222 spin_lock(&mlogbuf_wlock);
223 for (p = temp_buf; *p; p++) { 223 for (p = temp_buf; *p; p++) {
@@ -268,7 +268,7 @@ void ia64_mlogbuf_dump(void)
268 } 268 }
269 *p = '\0'; 269 *p = '\0';
270 if (temp_buf[0]) 270 if (temp_buf[0])
271 printk(temp_buf); 271 printk("%s", temp_buf);
272 mlogbuf_start = index; 272 mlogbuf_start = index;
273 273
274 mlogbuf_timestamp = 0; 274 mlogbuf_timestamp = 0;
diff --git a/arch/ia64/kernel/uncached.c b/arch/ia64/kernel/uncached.c
index a96bcf83a735..20e8a9b21d75 100644
--- a/arch/ia64/kernel/uncached.c
+++ b/arch/ia64/kernel/uncached.c
@@ -98,7 +98,7 @@ static int uncached_add_chunk(struct uncached_pool *uc_pool, int nid)
98 /* attempt to allocate a granule's worth of cached memory pages */ 98 /* attempt to allocate a granule's worth of cached memory pages */
99 99
100 page = alloc_pages_exact_node(nid, 100 page = alloc_pages_exact_node(nid,
101 GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, 101 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
102 IA64_GRANULE_SHIFT-PAGE_SHIFT); 102 IA64_GRANULE_SHIFT-PAGE_SHIFT);
103 if (!page) { 103 if (!page) {
104 mutex_unlock(&uc_pool->add_chunk_mutex); 104 mutex_unlock(&uc_pool->add_chunk_mutex);
diff --git a/arch/m32r/include/asm/Kbuild b/arch/m32r/include/asm/Kbuild
index 932435ac4e5c..5825a35b2c56 100644
--- a/arch/m32r/include/asm/Kbuild
+++ b/arch/m32r/include/asm/Kbuild
@@ -1,7 +1,8 @@
1 1
2generic-y += clkdev.h 2generic-y += clkdev.h
3generic-y += exec.h 3generic-y += exec.h
4generic-y += hash.h
5generic-y += mcs_spinlock.h
4generic-y += module.h 6generic-y += module.h
5generic-y += trace_clock.h
6generic-y += preempt.h 7generic-y += preempt.h
7generic-y += hash.h 8generic-y += trace_clock.h
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index dbdd2231c75d..b2e322939256 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -17,6 +17,7 @@ config M68K
17 select FPU if MMU 17 select FPU if MMU
18 select ARCH_WANT_IPC_PARSE_VERSION 18 select ARCH_WANT_IPC_PARSE_VERSION
19 select ARCH_USES_GETTIMEOFFSET if MMU && !COLDFIRE 19 select ARCH_USES_GETTIMEOFFSET if MMU && !COLDFIRE
20 select HAVE_FUTEX_CMPXCHG if MMU && FUTEX
20 select HAVE_MOD_ARCH_SPECIFIC 21 select HAVE_MOD_ARCH_SPECIFIC
21 select MODULES_USE_ELF_REL 22 select MODULES_USE_ELF_REL
22 select MODULES_USE_ELF_RELA 23 select MODULES_USE_ELF_RELA
diff --git a/arch/m68k/configs/amiga_defconfig b/arch/m68k/configs/amiga_defconfig
index 559ff3af8ff7..96da4963d14b 100644
--- a/arch/m68k/configs/amiga_defconfig
+++ b/arch/m68k/configs/amiga_defconfig
@@ -24,6 +24,8 @@ CONFIG_SUN_PARTITION=y
24# CONFIG_EFI_PARTITION is not set 24# CONFIG_EFI_PARTITION is not set
25CONFIG_SYSV68_PARTITION=y 25CONFIG_SYSV68_PARTITION=y
26CONFIG_IOSCHED_DEADLINE=m 26CONFIG_IOSCHED_DEADLINE=m
27CONFIG_KEXEC=y
28CONFIG_BOOTINFO_PROC=y
27CONFIG_M68020=y 29CONFIG_M68020=y
28CONFIG_M68030=y 30CONFIG_M68030=y
29CONFIG_M68040=y 31CONFIG_M68040=y
@@ -85,6 +87,7 @@ CONFIG_NF_CONNTRACK_SANE=m
85CONFIG_NF_CONNTRACK_SIP=m 87CONFIG_NF_CONNTRACK_SIP=m
86CONFIG_NF_CONNTRACK_TFTP=m 88CONFIG_NF_CONNTRACK_TFTP=m
87CONFIG_NF_TABLES=m 89CONFIG_NF_TABLES=m
90CONFIG_NF_TABLES_INET=m
88CONFIG_NFT_EXTHDR=m 91CONFIG_NFT_EXTHDR=m
89CONFIG_NFT_META=m 92CONFIG_NFT_META=m
90CONFIG_NFT_CT=m 93CONFIG_NFT_CT=m
@@ -94,6 +97,8 @@ CONFIG_NFT_COUNTER=m
94CONFIG_NFT_LOG=m 97CONFIG_NFT_LOG=m
95CONFIG_NFT_LIMIT=m 98CONFIG_NFT_LIMIT=m
96CONFIG_NFT_NAT=m 99CONFIG_NFT_NAT=m
100CONFIG_NFT_QUEUE=m
101CONFIG_NFT_REJECT=m
97CONFIG_NFT_COMPAT=m 102CONFIG_NFT_COMPAT=m
98CONFIG_NETFILTER_XT_SET=m 103CONFIG_NETFILTER_XT_SET=m
99CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 104CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -126,6 +131,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
126CONFIG_NETFILTER_XT_MATCH_ESP=m 131CONFIG_NETFILTER_XT_MATCH_ESP=m
127CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 132CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
128CONFIG_NETFILTER_XT_MATCH_HELPER=m 133CONFIG_NETFILTER_XT_MATCH_HELPER=m
134CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
129CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 135CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
130CONFIG_NETFILTER_XT_MATCH_LENGTH=m 136CONFIG_NETFILTER_XT_MATCH_LENGTH=m
131CONFIG_NETFILTER_XT_MATCH_LIMIT=m 137CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -163,8 +169,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
163CONFIG_IP_SET_HASH_NETIFACE=m 169CONFIG_IP_SET_HASH_NETIFACE=m
164CONFIG_IP_SET_LIST_SET=m 170CONFIG_IP_SET_LIST_SET=m
165CONFIG_NF_CONNTRACK_IPV4=m 171CONFIG_NF_CONNTRACK_IPV4=m
166CONFIG_NF_TABLES_IPV4=m
167CONFIG_NFT_REJECT_IPV4=m
168CONFIG_NFT_CHAIN_ROUTE_IPV4=m 172CONFIG_NFT_CHAIN_ROUTE_IPV4=m
169CONFIG_NFT_CHAIN_NAT_IPV4=m 173CONFIG_NFT_CHAIN_NAT_IPV4=m
170CONFIG_NF_TABLES_ARP=m 174CONFIG_NF_TABLES_ARP=m
@@ -190,7 +194,6 @@ CONFIG_IP_NF_ARPTABLES=m
190CONFIG_IP_NF_ARPFILTER=m 194CONFIG_IP_NF_ARPFILTER=m
191CONFIG_IP_NF_ARP_MANGLE=m 195CONFIG_IP_NF_ARP_MANGLE=m
192CONFIG_NF_CONNTRACK_IPV6=m 196CONFIG_NF_CONNTRACK_IPV6=m
193CONFIG_NF_TABLES_IPV6=m
194CONFIG_NFT_CHAIN_ROUTE_IPV6=m 197CONFIG_NFT_CHAIN_ROUTE_IPV6=m
195CONFIG_NFT_CHAIN_NAT_IPV6=m 198CONFIG_NFT_CHAIN_NAT_IPV6=m
196CONFIG_IP6_NF_IPTABLES=m 199CONFIG_IP6_NF_IPTABLES=m
@@ -512,7 +515,6 @@ CONFIG_CRYPTO_LZ4HC=m
512CONFIG_CRYPTO_USER_API_HASH=m 515CONFIG_CRYPTO_USER_API_HASH=m
513CONFIG_CRYPTO_USER_API_SKCIPHER=m 516CONFIG_CRYPTO_USER_API_SKCIPHER=m
514# CONFIG_CRYPTO_HW is not set 517# CONFIG_CRYPTO_HW is not set
515CONFIG_CRC_T10DIF=y
516CONFIG_XZ_DEC_X86=y 518CONFIG_XZ_DEC_X86=y
517CONFIG_XZ_DEC_POWERPC=y 519CONFIG_XZ_DEC_POWERPC=y
518CONFIG_XZ_DEC_IA64=y 520CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/apollo_defconfig b/arch/m68k/configs/apollo_defconfig
index cb1f55df69b6..1b8739f50cbf 100644
--- a/arch/m68k/configs/apollo_defconfig
+++ b/arch/m68k/configs/apollo_defconfig
@@ -25,6 +25,8 @@ CONFIG_SUN_PARTITION=y
25# CONFIG_EFI_PARTITION is not set 25# CONFIG_EFI_PARTITION is not set
26CONFIG_SYSV68_PARTITION=y 26CONFIG_SYSV68_PARTITION=y
27CONFIG_IOSCHED_DEADLINE=m 27CONFIG_IOSCHED_DEADLINE=m
28CONFIG_KEXEC=y
29CONFIG_BOOTINFO_PROC=y
28CONFIG_M68020=y 30CONFIG_M68020=y
29CONFIG_M68030=y 31CONFIG_M68030=y
30CONFIG_M68040=y 32CONFIG_M68040=y
@@ -83,6 +85,7 @@ CONFIG_NF_CONNTRACK_SANE=m
83CONFIG_NF_CONNTRACK_SIP=m 85CONFIG_NF_CONNTRACK_SIP=m
84CONFIG_NF_CONNTRACK_TFTP=m 86CONFIG_NF_CONNTRACK_TFTP=m
85CONFIG_NF_TABLES=m 87CONFIG_NF_TABLES=m
88CONFIG_NF_TABLES_INET=m
86CONFIG_NFT_EXTHDR=m 89CONFIG_NFT_EXTHDR=m
87CONFIG_NFT_META=m 90CONFIG_NFT_META=m
88CONFIG_NFT_CT=m 91CONFIG_NFT_CT=m
@@ -92,6 +95,8 @@ CONFIG_NFT_COUNTER=m
92CONFIG_NFT_LOG=m 95CONFIG_NFT_LOG=m
93CONFIG_NFT_LIMIT=m 96CONFIG_NFT_LIMIT=m
94CONFIG_NFT_NAT=m 97CONFIG_NFT_NAT=m
98CONFIG_NFT_QUEUE=m
99CONFIG_NFT_REJECT=m
95CONFIG_NFT_COMPAT=m 100CONFIG_NFT_COMPAT=m
96CONFIG_NETFILTER_XT_SET=m 101CONFIG_NETFILTER_XT_SET=m
97CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 102CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -124,6 +129,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
124CONFIG_NETFILTER_XT_MATCH_ESP=m 129CONFIG_NETFILTER_XT_MATCH_ESP=m
125CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 130CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
126CONFIG_NETFILTER_XT_MATCH_HELPER=m 131CONFIG_NETFILTER_XT_MATCH_HELPER=m
132CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
127CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 133CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
128CONFIG_NETFILTER_XT_MATCH_LENGTH=m 134CONFIG_NETFILTER_XT_MATCH_LENGTH=m
129CONFIG_NETFILTER_XT_MATCH_LIMIT=m 135CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -161,8 +167,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
161CONFIG_IP_SET_HASH_NETIFACE=m 167CONFIG_IP_SET_HASH_NETIFACE=m
162CONFIG_IP_SET_LIST_SET=m 168CONFIG_IP_SET_LIST_SET=m
163CONFIG_NF_CONNTRACK_IPV4=m 169CONFIG_NF_CONNTRACK_IPV4=m
164CONFIG_NF_TABLES_IPV4=m
165CONFIG_NFT_REJECT_IPV4=m
166CONFIG_NFT_CHAIN_ROUTE_IPV4=m 170CONFIG_NFT_CHAIN_ROUTE_IPV4=m
167CONFIG_NFT_CHAIN_NAT_IPV4=m 171CONFIG_NFT_CHAIN_NAT_IPV4=m
168CONFIG_NF_TABLES_ARP=m 172CONFIG_NF_TABLES_ARP=m
@@ -188,7 +192,6 @@ CONFIG_IP_NF_ARPTABLES=m
188CONFIG_IP_NF_ARPFILTER=m 192CONFIG_IP_NF_ARPFILTER=m
189CONFIG_IP_NF_ARP_MANGLE=m 193CONFIG_IP_NF_ARP_MANGLE=m
190CONFIG_NF_CONNTRACK_IPV6=m 194CONFIG_NF_CONNTRACK_IPV6=m
191CONFIG_NF_TABLES_IPV6=m
192CONFIG_NFT_CHAIN_ROUTE_IPV6=m 195CONFIG_NFT_CHAIN_ROUTE_IPV6=m
193CONFIG_NFT_CHAIN_NAT_IPV6=m 196CONFIG_NFT_CHAIN_NAT_IPV6=m
194CONFIG_IP6_NF_IPTABLES=m 197CONFIG_IP6_NF_IPTABLES=m
@@ -470,7 +473,6 @@ CONFIG_CRYPTO_LZ4HC=m
470CONFIG_CRYPTO_USER_API_HASH=m 473CONFIG_CRYPTO_USER_API_HASH=m
471CONFIG_CRYPTO_USER_API_SKCIPHER=m 474CONFIG_CRYPTO_USER_API_SKCIPHER=m
472# CONFIG_CRYPTO_HW is not set 475# CONFIG_CRYPTO_HW is not set
473CONFIG_CRC_T10DIF=y
474CONFIG_XZ_DEC_X86=y 476CONFIG_XZ_DEC_X86=y
475CONFIG_XZ_DEC_POWERPC=y 477CONFIG_XZ_DEC_POWERPC=y
476CONFIG_XZ_DEC_IA64=y 478CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/atari_defconfig b/arch/m68k/configs/atari_defconfig
index e880cfbb62d9..6ea4e91f0caa 100644
--- a/arch/m68k/configs/atari_defconfig
+++ b/arch/m68k/configs/atari_defconfig
@@ -24,6 +24,8 @@ CONFIG_SUN_PARTITION=y
24# CONFIG_EFI_PARTITION is not set 24# CONFIG_EFI_PARTITION is not set
25CONFIG_SYSV68_PARTITION=y 25CONFIG_SYSV68_PARTITION=y
26CONFIG_IOSCHED_DEADLINE=m 26CONFIG_IOSCHED_DEADLINE=m
27CONFIG_KEXEC=y
28CONFIG_BOOTINFO_PROC=y
27CONFIG_M68020=y 29CONFIG_M68020=y
28CONFIG_M68030=y 30CONFIG_M68030=y
29CONFIG_M68040=y 31CONFIG_M68040=y
@@ -82,6 +84,7 @@ CONFIG_NF_CONNTRACK_SANE=m
82CONFIG_NF_CONNTRACK_SIP=m 84CONFIG_NF_CONNTRACK_SIP=m
83CONFIG_NF_CONNTRACK_TFTP=m 85CONFIG_NF_CONNTRACK_TFTP=m
84CONFIG_NF_TABLES=m 86CONFIG_NF_TABLES=m
87CONFIG_NF_TABLES_INET=m
85CONFIG_NFT_EXTHDR=m 88CONFIG_NFT_EXTHDR=m
86CONFIG_NFT_META=m 89CONFIG_NFT_META=m
87CONFIG_NFT_CT=m 90CONFIG_NFT_CT=m
@@ -91,6 +94,8 @@ CONFIG_NFT_COUNTER=m
91CONFIG_NFT_LOG=m 94CONFIG_NFT_LOG=m
92CONFIG_NFT_LIMIT=m 95CONFIG_NFT_LIMIT=m
93CONFIG_NFT_NAT=m 96CONFIG_NFT_NAT=m
97CONFIG_NFT_QUEUE=m
98CONFIG_NFT_REJECT=m
94CONFIG_NFT_COMPAT=m 99CONFIG_NFT_COMPAT=m
95CONFIG_NETFILTER_XT_SET=m 100CONFIG_NETFILTER_XT_SET=m
96CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 101CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -123,6 +128,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
123CONFIG_NETFILTER_XT_MATCH_ESP=m 128CONFIG_NETFILTER_XT_MATCH_ESP=m
124CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 129CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
125CONFIG_NETFILTER_XT_MATCH_HELPER=m 130CONFIG_NETFILTER_XT_MATCH_HELPER=m
131CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
126CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 132CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
127CONFIG_NETFILTER_XT_MATCH_LENGTH=m 133CONFIG_NETFILTER_XT_MATCH_LENGTH=m
128CONFIG_NETFILTER_XT_MATCH_LIMIT=m 134CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -160,8 +166,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
160CONFIG_IP_SET_HASH_NETIFACE=m 166CONFIG_IP_SET_HASH_NETIFACE=m
161CONFIG_IP_SET_LIST_SET=m 167CONFIG_IP_SET_LIST_SET=m
162CONFIG_NF_CONNTRACK_IPV4=m 168CONFIG_NF_CONNTRACK_IPV4=m
163CONFIG_NF_TABLES_IPV4=m
164CONFIG_NFT_REJECT_IPV4=m
165CONFIG_NFT_CHAIN_ROUTE_IPV4=m 169CONFIG_NFT_CHAIN_ROUTE_IPV4=m
166CONFIG_NFT_CHAIN_NAT_IPV4=m 170CONFIG_NFT_CHAIN_NAT_IPV4=m
167CONFIG_NF_TABLES_ARP=m 171CONFIG_NF_TABLES_ARP=m
@@ -187,7 +191,6 @@ CONFIG_IP_NF_ARPTABLES=m
187CONFIG_IP_NF_ARPFILTER=m 191CONFIG_IP_NF_ARPFILTER=m
188CONFIG_IP_NF_ARP_MANGLE=m 192CONFIG_IP_NF_ARP_MANGLE=m
189CONFIG_NF_CONNTRACK_IPV6=m 193CONFIG_NF_CONNTRACK_IPV6=m
190CONFIG_NF_TABLES_IPV6=m
191CONFIG_NFT_CHAIN_ROUTE_IPV6=m 194CONFIG_NFT_CHAIN_ROUTE_IPV6=m
192CONFIG_NFT_CHAIN_NAT_IPV6=m 195CONFIG_NFT_CHAIN_NAT_IPV6=m
193CONFIG_IP6_NF_IPTABLES=m 196CONFIG_IP6_NF_IPTABLES=m
@@ -487,7 +490,6 @@ CONFIG_CRYPTO_LZ4HC=m
487CONFIG_CRYPTO_USER_API_HASH=m 490CONFIG_CRYPTO_USER_API_HASH=m
488CONFIG_CRYPTO_USER_API_SKCIPHER=m 491CONFIG_CRYPTO_USER_API_SKCIPHER=m
489# CONFIG_CRYPTO_HW is not set 492# CONFIG_CRYPTO_HW is not set
490CONFIG_CRC_T10DIF=y
491CONFIG_XZ_DEC_X86=y 493CONFIG_XZ_DEC_X86=y
492CONFIG_XZ_DEC_POWERPC=y 494CONFIG_XZ_DEC_POWERPC=y
493CONFIG_XZ_DEC_IA64=y 495CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/bvme6000_defconfig b/arch/m68k/configs/bvme6000_defconfig
index 4aa4f45e52a8..e5a12739ff2d 100644
--- a/arch/m68k/configs/bvme6000_defconfig
+++ b/arch/m68k/configs/bvme6000_defconfig
@@ -24,6 +24,8 @@ CONFIG_UNIXWARE_DISKLABEL=y
24CONFIG_SUN_PARTITION=y 24CONFIG_SUN_PARTITION=y
25# CONFIG_EFI_PARTITION is not set 25# CONFIG_EFI_PARTITION is not set
26CONFIG_IOSCHED_DEADLINE=m 26CONFIG_IOSCHED_DEADLINE=m
27CONFIG_KEXEC=y
28CONFIG_BOOTINFO_PROC=y
27CONFIG_M68040=y 29CONFIG_M68040=y
28CONFIG_M68060=y 30CONFIG_M68060=y
29CONFIG_VME=y 31CONFIG_VME=y
@@ -81,6 +83,7 @@ CONFIG_NF_CONNTRACK_SANE=m
81CONFIG_NF_CONNTRACK_SIP=m 83CONFIG_NF_CONNTRACK_SIP=m
82CONFIG_NF_CONNTRACK_TFTP=m 84CONFIG_NF_CONNTRACK_TFTP=m
83CONFIG_NF_TABLES=m 85CONFIG_NF_TABLES=m
86CONFIG_NF_TABLES_INET=m
84CONFIG_NFT_EXTHDR=m 87CONFIG_NFT_EXTHDR=m
85CONFIG_NFT_META=m 88CONFIG_NFT_META=m
86CONFIG_NFT_CT=m 89CONFIG_NFT_CT=m
@@ -90,6 +93,8 @@ CONFIG_NFT_COUNTER=m
90CONFIG_NFT_LOG=m 93CONFIG_NFT_LOG=m
91CONFIG_NFT_LIMIT=m 94CONFIG_NFT_LIMIT=m
92CONFIG_NFT_NAT=m 95CONFIG_NFT_NAT=m
96CONFIG_NFT_QUEUE=m
97CONFIG_NFT_REJECT=m
93CONFIG_NFT_COMPAT=m 98CONFIG_NFT_COMPAT=m
94CONFIG_NETFILTER_XT_SET=m 99CONFIG_NETFILTER_XT_SET=m
95CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 100CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -122,6 +127,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
122CONFIG_NETFILTER_XT_MATCH_ESP=m 127CONFIG_NETFILTER_XT_MATCH_ESP=m
123CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 128CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
124CONFIG_NETFILTER_XT_MATCH_HELPER=m 129CONFIG_NETFILTER_XT_MATCH_HELPER=m
130CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
125CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 131CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
126CONFIG_NETFILTER_XT_MATCH_LENGTH=m 132CONFIG_NETFILTER_XT_MATCH_LENGTH=m
127CONFIG_NETFILTER_XT_MATCH_LIMIT=m 133CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -159,8 +165,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
159CONFIG_IP_SET_HASH_NETIFACE=m 165CONFIG_IP_SET_HASH_NETIFACE=m
160CONFIG_IP_SET_LIST_SET=m 166CONFIG_IP_SET_LIST_SET=m
161CONFIG_NF_CONNTRACK_IPV4=m 167CONFIG_NF_CONNTRACK_IPV4=m
162CONFIG_NF_TABLES_IPV4=m
163CONFIG_NFT_REJECT_IPV4=m
164CONFIG_NFT_CHAIN_ROUTE_IPV4=m 168CONFIG_NFT_CHAIN_ROUTE_IPV4=m
165CONFIG_NFT_CHAIN_NAT_IPV4=m 169CONFIG_NFT_CHAIN_NAT_IPV4=m
166CONFIG_NF_TABLES_ARP=m 170CONFIG_NF_TABLES_ARP=m
@@ -186,7 +190,6 @@ CONFIG_IP_NF_ARPTABLES=m
186CONFIG_IP_NF_ARPFILTER=m 190CONFIG_IP_NF_ARPFILTER=m
187CONFIG_IP_NF_ARP_MANGLE=m 191CONFIG_IP_NF_ARP_MANGLE=m
188CONFIG_NF_CONNTRACK_IPV6=m 192CONFIG_NF_CONNTRACK_IPV6=m
189CONFIG_NF_TABLES_IPV6=m
190CONFIG_NFT_CHAIN_ROUTE_IPV6=m 193CONFIG_NFT_CHAIN_ROUTE_IPV6=m
191CONFIG_NFT_CHAIN_NAT_IPV6=m 194CONFIG_NFT_CHAIN_NAT_IPV6=m
192CONFIG_IP6_NF_IPTABLES=m 195CONFIG_IP6_NF_IPTABLES=m
@@ -463,7 +466,6 @@ CONFIG_CRYPTO_LZ4HC=m
463CONFIG_CRYPTO_USER_API_HASH=m 466CONFIG_CRYPTO_USER_API_HASH=m
464CONFIG_CRYPTO_USER_API_SKCIPHER=m 467CONFIG_CRYPTO_USER_API_SKCIPHER=m
465# CONFIG_CRYPTO_HW is not set 468# CONFIG_CRYPTO_HW is not set
466CONFIG_CRC_T10DIF=y
467CONFIG_XZ_DEC_X86=y 469CONFIG_XZ_DEC_X86=y
468CONFIG_XZ_DEC_POWERPC=y 470CONFIG_XZ_DEC_POWERPC=y
469CONFIG_XZ_DEC_IA64=y 471CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/hp300_defconfig b/arch/m68k/configs/hp300_defconfig
index 7cd9d9f456fb..8936d7fb0f0f 100644
--- a/arch/m68k/configs/hp300_defconfig
+++ b/arch/m68k/configs/hp300_defconfig
@@ -25,6 +25,8 @@ CONFIG_SUN_PARTITION=y
25# CONFIG_EFI_PARTITION is not set 25# CONFIG_EFI_PARTITION is not set
26CONFIG_SYSV68_PARTITION=y 26CONFIG_SYSV68_PARTITION=y
27CONFIG_IOSCHED_DEADLINE=m 27CONFIG_IOSCHED_DEADLINE=m
28CONFIG_KEXEC=y
29CONFIG_BOOTINFO_PROC=y
28CONFIG_M68020=y 30CONFIG_M68020=y
29CONFIG_M68030=y 31CONFIG_M68030=y
30CONFIG_M68040=y 32CONFIG_M68040=y
@@ -83,6 +85,7 @@ CONFIG_NF_CONNTRACK_SANE=m
83CONFIG_NF_CONNTRACK_SIP=m 85CONFIG_NF_CONNTRACK_SIP=m
84CONFIG_NF_CONNTRACK_TFTP=m 86CONFIG_NF_CONNTRACK_TFTP=m
85CONFIG_NF_TABLES=m 87CONFIG_NF_TABLES=m
88CONFIG_NF_TABLES_INET=m
86CONFIG_NFT_EXTHDR=m 89CONFIG_NFT_EXTHDR=m
87CONFIG_NFT_META=m 90CONFIG_NFT_META=m
88CONFIG_NFT_CT=m 91CONFIG_NFT_CT=m
@@ -92,6 +95,8 @@ CONFIG_NFT_COUNTER=m
92CONFIG_NFT_LOG=m 95CONFIG_NFT_LOG=m
93CONFIG_NFT_LIMIT=m 96CONFIG_NFT_LIMIT=m
94CONFIG_NFT_NAT=m 97CONFIG_NFT_NAT=m
98CONFIG_NFT_QUEUE=m
99CONFIG_NFT_REJECT=m
95CONFIG_NFT_COMPAT=m 100CONFIG_NFT_COMPAT=m
96CONFIG_NETFILTER_XT_SET=m 101CONFIG_NETFILTER_XT_SET=m
97CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 102CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -124,6 +129,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
124CONFIG_NETFILTER_XT_MATCH_ESP=m 129CONFIG_NETFILTER_XT_MATCH_ESP=m
125CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 130CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
126CONFIG_NETFILTER_XT_MATCH_HELPER=m 131CONFIG_NETFILTER_XT_MATCH_HELPER=m
132CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
127CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 133CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
128CONFIG_NETFILTER_XT_MATCH_LENGTH=m 134CONFIG_NETFILTER_XT_MATCH_LENGTH=m
129CONFIG_NETFILTER_XT_MATCH_LIMIT=m 135CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -161,8 +167,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
161CONFIG_IP_SET_HASH_NETIFACE=m 167CONFIG_IP_SET_HASH_NETIFACE=m
162CONFIG_IP_SET_LIST_SET=m 168CONFIG_IP_SET_LIST_SET=m
163CONFIG_NF_CONNTRACK_IPV4=m 169CONFIG_NF_CONNTRACK_IPV4=m
164CONFIG_NF_TABLES_IPV4=m
165CONFIG_NFT_REJECT_IPV4=m
166CONFIG_NFT_CHAIN_ROUTE_IPV4=m 170CONFIG_NFT_CHAIN_ROUTE_IPV4=m
167CONFIG_NFT_CHAIN_NAT_IPV4=m 171CONFIG_NFT_CHAIN_NAT_IPV4=m
168CONFIG_NF_TABLES_ARP=m 172CONFIG_NF_TABLES_ARP=m
@@ -188,7 +192,6 @@ CONFIG_IP_NF_ARPTABLES=m
188CONFIG_IP_NF_ARPFILTER=m 192CONFIG_IP_NF_ARPFILTER=m
189CONFIG_IP_NF_ARP_MANGLE=m 193CONFIG_IP_NF_ARP_MANGLE=m
190CONFIG_NF_CONNTRACK_IPV6=m 194CONFIG_NF_CONNTRACK_IPV6=m
191CONFIG_NF_TABLES_IPV6=m
192CONFIG_NFT_CHAIN_ROUTE_IPV6=m 195CONFIG_NFT_CHAIN_ROUTE_IPV6=m
193CONFIG_NFT_CHAIN_NAT_IPV6=m 196CONFIG_NFT_CHAIN_NAT_IPV6=m
194CONFIG_IP6_NF_IPTABLES=m 197CONFIG_IP6_NF_IPTABLES=m
@@ -472,7 +475,6 @@ CONFIG_CRYPTO_LZ4HC=m
472CONFIG_CRYPTO_USER_API_HASH=m 475CONFIG_CRYPTO_USER_API_HASH=m
473CONFIG_CRYPTO_USER_API_SKCIPHER=m 476CONFIG_CRYPTO_USER_API_SKCIPHER=m
474# CONFIG_CRYPTO_HW is not set 477# CONFIG_CRYPTO_HW is not set
475CONFIG_CRC_T10DIF=y
476CONFIG_XZ_DEC_X86=y 478CONFIG_XZ_DEC_X86=y
477CONFIG_XZ_DEC_POWERPC=y 479CONFIG_XZ_DEC_POWERPC=y
478CONFIG_XZ_DEC_IA64=y 480CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/mac_defconfig b/arch/m68k/configs/mac_defconfig
index 31f5bd061d14..be5342cca25b 100644
--- a/arch/m68k/configs/mac_defconfig
+++ b/arch/m68k/configs/mac_defconfig
@@ -24,6 +24,8 @@ CONFIG_SUN_PARTITION=y
24# CONFIG_EFI_PARTITION is not set 24# CONFIG_EFI_PARTITION is not set
25CONFIG_SYSV68_PARTITION=y 25CONFIG_SYSV68_PARTITION=y
26CONFIG_IOSCHED_DEADLINE=m 26CONFIG_IOSCHED_DEADLINE=m
27CONFIG_KEXEC=y
28CONFIG_BOOTINFO_PROC=y
27CONFIG_M68020=y 29CONFIG_M68020=y
28CONFIG_M68030=y 30CONFIG_M68030=y
29CONFIG_M68040=y 31CONFIG_M68040=y
@@ -82,6 +84,7 @@ CONFIG_NF_CONNTRACK_SANE=m
82CONFIG_NF_CONNTRACK_SIP=m 84CONFIG_NF_CONNTRACK_SIP=m
83CONFIG_NF_CONNTRACK_TFTP=m 85CONFIG_NF_CONNTRACK_TFTP=m
84CONFIG_NF_TABLES=m 86CONFIG_NF_TABLES=m
87CONFIG_NF_TABLES_INET=m
85CONFIG_NFT_EXTHDR=m 88CONFIG_NFT_EXTHDR=m
86CONFIG_NFT_META=m 89CONFIG_NFT_META=m
87CONFIG_NFT_CT=m 90CONFIG_NFT_CT=m
@@ -91,6 +94,8 @@ CONFIG_NFT_COUNTER=m
91CONFIG_NFT_LOG=m 94CONFIG_NFT_LOG=m
92CONFIG_NFT_LIMIT=m 95CONFIG_NFT_LIMIT=m
93CONFIG_NFT_NAT=m 96CONFIG_NFT_NAT=m
97CONFIG_NFT_QUEUE=m
98CONFIG_NFT_REJECT=m
94CONFIG_NFT_COMPAT=m 99CONFIG_NFT_COMPAT=m
95CONFIG_NETFILTER_XT_SET=m 100CONFIG_NETFILTER_XT_SET=m
96CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 101CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -123,6 +128,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
123CONFIG_NETFILTER_XT_MATCH_ESP=m 128CONFIG_NETFILTER_XT_MATCH_ESP=m
124CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 129CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
125CONFIG_NETFILTER_XT_MATCH_HELPER=m 130CONFIG_NETFILTER_XT_MATCH_HELPER=m
131CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
126CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 132CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
127CONFIG_NETFILTER_XT_MATCH_LENGTH=m 133CONFIG_NETFILTER_XT_MATCH_LENGTH=m
128CONFIG_NETFILTER_XT_MATCH_LIMIT=m 134CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -160,8 +166,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
160CONFIG_IP_SET_HASH_NETIFACE=m 166CONFIG_IP_SET_HASH_NETIFACE=m
161CONFIG_IP_SET_LIST_SET=m 167CONFIG_IP_SET_LIST_SET=m
162CONFIG_NF_CONNTRACK_IPV4=m 168CONFIG_NF_CONNTRACK_IPV4=m
163CONFIG_NF_TABLES_IPV4=m
164CONFIG_NFT_REJECT_IPV4=m
165CONFIG_NFT_CHAIN_ROUTE_IPV4=m 169CONFIG_NFT_CHAIN_ROUTE_IPV4=m
166CONFIG_NFT_CHAIN_NAT_IPV4=m 170CONFIG_NFT_CHAIN_NAT_IPV4=m
167CONFIG_NF_TABLES_ARP=m 171CONFIG_NF_TABLES_ARP=m
@@ -187,7 +191,6 @@ CONFIG_IP_NF_ARPTABLES=m
187CONFIG_IP_NF_ARPFILTER=m 191CONFIG_IP_NF_ARPFILTER=m
188CONFIG_IP_NF_ARP_MANGLE=m 192CONFIG_IP_NF_ARP_MANGLE=m
189CONFIG_NF_CONNTRACK_IPV6=m 193CONFIG_NF_CONNTRACK_IPV6=m
190CONFIG_NF_TABLES_IPV6=m
191CONFIG_NFT_CHAIN_ROUTE_IPV6=m 194CONFIG_NFT_CHAIN_ROUTE_IPV6=m
192CONFIG_NFT_CHAIN_NAT_IPV6=m 195CONFIG_NFT_CHAIN_NAT_IPV6=m
193CONFIG_IP6_NF_IPTABLES=m 196CONFIG_IP6_NF_IPTABLES=m
@@ -495,7 +498,6 @@ CONFIG_CRYPTO_LZ4HC=m
495CONFIG_CRYPTO_USER_API_HASH=m 498CONFIG_CRYPTO_USER_API_HASH=m
496CONFIG_CRYPTO_USER_API_SKCIPHER=m 499CONFIG_CRYPTO_USER_API_SKCIPHER=m
497# CONFIG_CRYPTO_HW is not set 500# CONFIG_CRYPTO_HW is not set
498CONFIG_CRC_T10DIF=y
499CONFIG_XZ_DEC_X86=y 501CONFIG_XZ_DEC_X86=y
500CONFIG_XZ_DEC_POWERPC=y 502CONFIG_XZ_DEC_POWERPC=y
501CONFIG_XZ_DEC_IA64=y 503CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/multi_defconfig b/arch/m68k/configs/multi_defconfig
index 4e5adff326ee..f27194ade167 100644
--- a/arch/m68k/configs/multi_defconfig
+++ b/arch/m68k/configs/multi_defconfig
@@ -20,6 +20,8 @@ CONFIG_SOLARIS_X86_PARTITION=y
20CONFIG_UNIXWARE_DISKLABEL=y 20CONFIG_UNIXWARE_DISKLABEL=y
21# CONFIG_EFI_PARTITION is not set 21# CONFIG_EFI_PARTITION is not set
22CONFIG_IOSCHED_DEADLINE=m 22CONFIG_IOSCHED_DEADLINE=m
23CONFIG_KEXEC=y
24CONFIG_BOOTINFO_PROC=y
23CONFIG_M68020=y 25CONFIG_M68020=y
24CONFIG_M68040=y 26CONFIG_M68040=y
25CONFIG_M68060=y 27CONFIG_M68060=y
@@ -91,6 +93,7 @@ CONFIG_NF_CONNTRACK_SANE=m
91CONFIG_NF_CONNTRACK_SIP=m 93CONFIG_NF_CONNTRACK_SIP=m
92CONFIG_NF_CONNTRACK_TFTP=m 94CONFIG_NF_CONNTRACK_TFTP=m
93CONFIG_NF_TABLES=m 95CONFIG_NF_TABLES=m
96CONFIG_NF_TABLES_INET=m
94CONFIG_NFT_EXTHDR=m 97CONFIG_NFT_EXTHDR=m
95CONFIG_NFT_META=m 98CONFIG_NFT_META=m
96CONFIG_NFT_CT=m 99CONFIG_NFT_CT=m
@@ -100,6 +103,8 @@ CONFIG_NFT_COUNTER=m
100CONFIG_NFT_LOG=m 103CONFIG_NFT_LOG=m
101CONFIG_NFT_LIMIT=m 104CONFIG_NFT_LIMIT=m
102CONFIG_NFT_NAT=m 105CONFIG_NFT_NAT=m
106CONFIG_NFT_QUEUE=m
107CONFIG_NFT_REJECT=m
103CONFIG_NFT_COMPAT=m 108CONFIG_NFT_COMPAT=m
104CONFIG_NETFILTER_XT_SET=m 109CONFIG_NETFILTER_XT_SET=m
105CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 110CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -132,6 +137,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
132CONFIG_NETFILTER_XT_MATCH_ESP=m 137CONFIG_NETFILTER_XT_MATCH_ESP=m
133CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 138CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
134CONFIG_NETFILTER_XT_MATCH_HELPER=m 139CONFIG_NETFILTER_XT_MATCH_HELPER=m
140CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
135CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 141CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
136CONFIG_NETFILTER_XT_MATCH_LENGTH=m 142CONFIG_NETFILTER_XT_MATCH_LENGTH=m
137CONFIG_NETFILTER_XT_MATCH_LIMIT=m 143CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -169,8 +175,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
169CONFIG_IP_SET_HASH_NETIFACE=m 175CONFIG_IP_SET_HASH_NETIFACE=m
170CONFIG_IP_SET_LIST_SET=m 176CONFIG_IP_SET_LIST_SET=m
171CONFIG_NF_CONNTRACK_IPV4=m 177CONFIG_NF_CONNTRACK_IPV4=m
172CONFIG_NF_TABLES_IPV4=m
173CONFIG_NFT_REJECT_IPV4=m
174CONFIG_NFT_CHAIN_ROUTE_IPV4=m 178CONFIG_NFT_CHAIN_ROUTE_IPV4=m
175CONFIG_NFT_CHAIN_NAT_IPV4=m 179CONFIG_NFT_CHAIN_NAT_IPV4=m
176CONFIG_NF_TABLES_ARP=m 180CONFIG_NF_TABLES_ARP=m
@@ -196,7 +200,6 @@ CONFIG_IP_NF_ARPTABLES=m
196CONFIG_IP_NF_ARPFILTER=m 200CONFIG_IP_NF_ARPFILTER=m
197CONFIG_IP_NF_ARP_MANGLE=m 201CONFIG_IP_NF_ARP_MANGLE=m
198CONFIG_NF_CONNTRACK_IPV6=m 202CONFIG_NF_CONNTRACK_IPV6=m
199CONFIG_NF_TABLES_IPV6=m
200CONFIG_NFT_CHAIN_ROUTE_IPV6=m 203CONFIG_NFT_CHAIN_ROUTE_IPV6=m
201CONFIG_NFT_CHAIN_NAT_IPV6=m 204CONFIG_NFT_CHAIN_NAT_IPV6=m
202CONFIG_IP6_NF_IPTABLES=m 205CONFIG_IP6_NF_IPTABLES=m
@@ -571,7 +574,6 @@ CONFIG_CRYPTO_LZ4HC=m
571CONFIG_CRYPTO_USER_API_HASH=m 574CONFIG_CRYPTO_USER_API_HASH=m
572CONFIG_CRYPTO_USER_API_SKCIPHER=m 575CONFIG_CRYPTO_USER_API_SKCIPHER=m
573# CONFIG_CRYPTO_HW is not set 576# CONFIG_CRYPTO_HW is not set
574CONFIG_CRC_T10DIF=y
575CONFIG_XZ_DEC_X86=y 577CONFIG_XZ_DEC_X86=y
576CONFIG_XZ_DEC_POWERPC=y 578CONFIG_XZ_DEC_POWERPC=y
577CONFIG_XZ_DEC_IA64=y 579CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/mvme147_defconfig b/arch/m68k/configs/mvme147_defconfig
index 02cdbac5565e..c3887603c1db 100644
--- a/arch/m68k/configs/mvme147_defconfig
+++ b/arch/m68k/configs/mvme147_defconfig
@@ -24,6 +24,8 @@ CONFIG_UNIXWARE_DISKLABEL=y
24CONFIG_SUN_PARTITION=y 24CONFIG_SUN_PARTITION=y
25# CONFIG_EFI_PARTITION is not set 25# CONFIG_EFI_PARTITION is not set
26CONFIG_IOSCHED_DEADLINE=m 26CONFIG_IOSCHED_DEADLINE=m
27CONFIG_KEXEC=y
28CONFIG_BOOTINFO_PROC=y
27CONFIG_M68030=y 29CONFIG_M68030=y
28CONFIG_VME=y 30CONFIG_VME=y
29CONFIG_MVME147=y 31CONFIG_MVME147=y
@@ -80,6 +82,7 @@ CONFIG_NF_CONNTRACK_SANE=m
80CONFIG_NF_CONNTRACK_SIP=m 82CONFIG_NF_CONNTRACK_SIP=m
81CONFIG_NF_CONNTRACK_TFTP=m 83CONFIG_NF_CONNTRACK_TFTP=m
82CONFIG_NF_TABLES=m 84CONFIG_NF_TABLES=m
85CONFIG_NF_TABLES_INET=m
83CONFIG_NFT_EXTHDR=m 86CONFIG_NFT_EXTHDR=m
84CONFIG_NFT_META=m 87CONFIG_NFT_META=m
85CONFIG_NFT_CT=m 88CONFIG_NFT_CT=m
@@ -89,6 +92,8 @@ CONFIG_NFT_COUNTER=m
89CONFIG_NFT_LOG=m 92CONFIG_NFT_LOG=m
90CONFIG_NFT_LIMIT=m 93CONFIG_NFT_LIMIT=m
91CONFIG_NFT_NAT=m 94CONFIG_NFT_NAT=m
95CONFIG_NFT_QUEUE=m
96CONFIG_NFT_REJECT=m
92CONFIG_NFT_COMPAT=m 97CONFIG_NFT_COMPAT=m
93CONFIG_NETFILTER_XT_SET=m 98CONFIG_NETFILTER_XT_SET=m
94CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 99CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -121,6 +126,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
121CONFIG_NETFILTER_XT_MATCH_ESP=m 126CONFIG_NETFILTER_XT_MATCH_ESP=m
122CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 127CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
123CONFIG_NETFILTER_XT_MATCH_HELPER=m 128CONFIG_NETFILTER_XT_MATCH_HELPER=m
129CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
124CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 130CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
125CONFIG_NETFILTER_XT_MATCH_LENGTH=m 131CONFIG_NETFILTER_XT_MATCH_LENGTH=m
126CONFIG_NETFILTER_XT_MATCH_LIMIT=m 132CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -158,8 +164,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
158CONFIG_IP_SET_HASH_NETIFACE=m 164CONFIG_IP_SET_HASH_NETIFACE=m
159CONFIG_IP_SET_LIST_SET=m 165CONFIG_IP_SET_LIST_SET=m
160CONFIG_NF_CONNTRACK_IPV4=m 166CONFIG_NF_CONNTRACK_IPV4=m
161CONFIG_NF_TABLES_IPV4=m
162CONFIG_NFT_REJECT_IPV4=m
163CONFIG_NFT_CHAIN_ROUTE_IPV4=m 167CONFIG_NFT_CHAIN_ROUTE_IPV4=m
164CONFIG_NFT_CHAIN_NAT_IPV4=m 168CONFIG_NFT_CHAIN_NAT_IPV4=m
165CONFIG_NF_TABLES_ARP=m 169CONFIG_NF_TABLES_ARP=m
@@ -185,7 +189,6 @@ CONFIG_IP_NF_ARPTABLES=m
185CONFIG_IP_NF_ARPFILTER=m 189CONFIG_IP_NF_ARPFILTER=m
186CONFIG_IP_NF_ARP_MANGLE=m 190CONFIG_IP_NF_ARP_MANGLE=m
187CONFIG_NF_CONNTRACK_IPV6=m 191CONFIG_NF_CONNTRACK_IPV6=m
188CONFIG_NF_TABLES_IPV6=m
189CONFIG_NFT_CHAIN_ROUTE_IPV6=m 192CONFIG_NFT_CHAIN_ROUTE_IPV6=m
190CONFIG_NFT_CHAIN_NAT_IPV6=m 193CONFIG_NFT_CHAIN_NAT_IPV6=m
191CONFIG_IP6_NF_IPTABLES=m 194CONFIG_IP6_NF_IPTABLES=m
@@ -463,7 +466,6 @@ CONFIG_CRYPTO_LZ4HC=m
463CONFIG_CRYPTO_USER_API_HASH=m 466CONFIG_CRYPTO_USER_API_HASH=m
464CONFIG_CRYPTO_USER_API_SKCIPHER=m 467CONFIG_CRYPTO_USER_API_SKCIPHER=m
465# CONFIG_CRYPTO_HW is not set 468# CONFIG_CRYPTO_HW is not set
466CONFIG_CRC_T10DIF=y
467CONFIG_XZ_DEC_X86=y 469CONFIG_XZ_DEC_X86=y
468CONFIG_XZ_DEC_POWERPC=y 470CONFIG_XZ_DEC_POWERPC=y
469CONFIG_XZ_DEC_IA64=y 471CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/mvme16x_defconfig b/arch/m68k/configs/mvme16x_defconfig
index 05a990a9dbd4..f7ff784d05ac 100644
--- a/arch/m68k/configs/mvme16x_defconfig
+++ b/arch/m68k/configs/mvme16x_defconfig
@@ -24,6 +24,8 @@ CONFIG_UNIXWARE_DISKLABEL=y
24CONFIG_SUN_PARTITION=y 24CONFIG_SUN_PARTITION=y
25# CONFIG_EFI_PARTITION is not set 25# CONFIG_EFI_PARTITION is not set
26CONFIG_IOSCHED_DEADLINE=m 26CONFIG_IOSCHED_DEADLINE=m
27CONFIG_KEXEC=y
28CONFIG_BOOTINFO_PROC=y
27CONFIG_M68040=y 29CONFIG_M68040=y
28CONFIG_M68060=y 30CONFIG_M68060=y
29CONFIG_VME=y 31CONFIG_VME=y
@@ -81,6 +83,7 @@ CONFIG_NF_CONNTRACK_SANE=m
81CONFIG_NF_CONNTRACK_SIP=m 83CONFIG_NF_CONNTRACK_SIP=m
82CONFIG_NF_CONNTRACK_TFTP=m 84CONFIG_NF_CONNTRACK_TFTP=m
83CONFIG_NF_TABLES=m 85CONFIG_NF_TABLES=m
86CONFIG_NF_TABLES_INET=m
84CONFIG_NFT_EXTHDR=m 87CONFIG_NFT_EXTHDR=m
85CONFIG_NFT_META=m 88CONFIG_NFT_META=m
86CONFIG_NFT_CT=m 89CONFIG_NFT_CT=m
@@ -90,6 +93,8 @@ CONFIG_NFT_COUNTER=m
90CONFIG_NFT_LOG=m 93CONFIG_NFT_LOG=m
91CONFIG_NFT_LIMIT=m 94CONFIG_NFT_LIMIT=m
92CONFIG_NFT_NAT=m 95CONFIG_NFT_NAT=m
96CONFIG_NFT_QUEUE=m
97CONFIG_NFT_REJECT=m
93CONFIG_NFT_COMPAT=m 98CONFIG_NFT_COMPAT=m
94CONFIG_NETFILTER_XT_SET=m 99CONFIG_NETFILTER_XT_SET=m
95CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 100CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -122,6 +127,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
122CONFIG_NETFILTER_XT_MATCH_ESP=m 127CONFIG_NETFILTER_XT_MATCH_ESP=m
123CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 128CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
124CONFIG_NETFILTER_XT_MATCH_HELPER=m 129CONFIG_NETFILTER_XT_MATCH_HELPER=m
130CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
125CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 131CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
126CONFIG_NETFILTER_XT_MATCH_LENGTH=m 132CONFIG_NETFILTER_XT_MATCH_LENGTH=m
127CONFIG_NETFILTER_XT_MATCH_LIMIT=m 133CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -159,8 +165,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
159CONFIG_IP_SET_HASH_NETIFACE=m 165CONFIG_IP_SET_HASH_NETIFACE=m
160CONFIG_IP_SET_LIST_SET=m 166CONFIG_IP_SET_LIST_SET=m
161CONFIG_NF_CONNTRACK_IPV4=m 167CONFIG_NF_CONNTRACK_IPV4=m
162CONFIG_NF_TABLES_IPV4=m
163CONFIG_NFT_REJECT_IPV4=m
164CONFIG_NFT_CHAIN_ROUTE_IPV4=m 168CONFIG_NFT_CHAIN_ROUTE_IPV4=m
165CONFIG_NFT_CHAIN_NAT_IPV4=m 169CONFIG_NFT_CHAIN_NAT_IPV4=m
166CONFIG_NF_TABLES_ARP=m 170CONFIG_NF_TABLES_ARP=m
@@ -186,7 +190,6 @@ CONFIG_IP_NF_ARPTABLES=m
186CONFIG_IP_NF_ARPFILTER=m 190CONFIG_IP_NF_ARPFILTER=m
187CONFIG_IP_NF_ARP_MANGLE=m 191CONFIG_IP_NF_ARP_MANGLE=m
188CONFIG_NF_CONNTRACK_IPV6=m 192CONFIG_NF_CONNTRACK_IPV6=m
189CONFIG_NF_TABLES_IPV6=m
190CONFIG_NFT_CHAIN_ROUTE_IPV6=m 193CONFIG_NFT_CHAIN_ROUTE_IPV6=m
191CONFIG_NFT_CHAIN_NAT_IPV6=m 194CONFIG_NFT_CHAIN_NAT_IPV6=m
192CONFIG_IP6_NF_IPTABLES=m 195CONFIG_IP6_NF_IPTABLES=m
@@ -464,7 +467,6 @@ CONFIG_CRYPTO_LZ4HC=m
464CONFIG_CRYPTO_USER_API_HASH=m 467CONFIG_CRYPTO_USER_API_HASH=m
465CONFIG_CRYPTO_USER_API_SKCIPHER=m 468CONFIG_CRYPTO_USER_API_SKCIPHER=m
466# CONFIG_CRYPTO_HW is not set 469# CONFIG_CRYPTO_HW is not set
467CONFIG_CRC_T10DIF=y
468CONFIG_XZ_DEC_X86=y 470CONFIG_XZ_DEC_X86=y
469CONFIG_XZ_DEC_POWERPC=y 471CONFIG_XZ_DEC_POWERPC=y
470CONFIG_XZ_DEC_IA64=y 472CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/q40_defconfig b/arch/m68k/configs/q40_defconfig
index 568e2a98f976..f0c72ab037be 100644
--- a/arch/m68k/configs/q40_defconfig
+++ b/arch/m68k/configs/q40_defconfig
@@ -25,6 +25,8 @@ CONFIG_SUN_PARTITION=y
25# CONFIG_EFI_PARTITION is not set 25# CONFIG_EFI_PARTITION is not set
26CONFIG_SYSV68_PARTITION=y 26CONFIG_SYSV68_PARTITION=y
27CONFIG_IOSCHED_DEADLINE=m 27CONFIG_IOSCHED_DEADLINE=m
28CONFIG_KEXEC=y
29CONFIG_BOOTINFO_PROC=y
28CONFIG_M68040=y 30CONFIG_M68040=y
29CONFIG_M68060=y 31CONFIG_M68060=y
30CONFIG_Q40=y 32CONFIG_Q40=y
@@ -81,6 +83,7 @@ CONFIG_NF_CONNTRACK_SANE=m
81CONFIG_NF_CONNTRACK_SIP=m 83CONFIG_NF_CONNTRACK_SIP=m
82CONFIG_NF_CONNTRACK_TFTP=m 84CONFIG_NF_CONNTRACK_TFTP=m
83CONFIG_NF_TABLES=m 85CONFIG_NF_TABLES=m
86CONFIG_NF_TABLES_INET=m
84CONFIG_NFT_EXTHDR=m 87CONFIG_NFT_EXTHDR=m
85CONFIG_NFT_META=m 88CONFIG_NFT_META=m
86CONFIG_NFT_CT=m 89CONFIG_NFT_CT=m
@@ -90,6 +93,8 @@ CONFIG_NFT_COUNTER=m
90CONFIG_NFT_LOG=m 93CONFIG_NFT_LOG=m
91CONFIG_NFT_LIMIT=m 94CONFIG_NFT_LIMIT=m
92CONFIG_NFT_NAT=m 95CONFIG_NFT_NAT=m
96CONFIG_NFT_QUEUE=m
97CONFIG_NFT_REJECT=m
93CONFIG_NFT_COMPAT=m 98CONFIG_NFT_COMPAT=m
94CONFIG_NETFILTER_XT_SET=m 99CONFIG_NETFILTER_XT_SET=m
95CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 100CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -122,6 +127,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
122CONFIG_NETFILTER_XT_MATCH_ESP=m 127CONFIG_NETFILTER_XT_MATCH_ESP=m
123CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 128CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
124CONFIG_NETFILTER_XT_MATCH_HELPER=m 129CONFIG_NETFILTER_XT_MATCH_HELPER=m
130CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
125CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 131CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
126CONFIG_NETFILTER_XT_MATCH_LENGTH=m 132CONFIG_NETFILTER_XT_MATCH_LENGTH=m
127CONFIG_NETFILTER_XT_MATCH_LIMIT=m 133CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -159,8 +165,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
159CONFIG_IP_SET_HASH_NETIFACE=m 165CONFIG_IP_SET_HASH_NETIFACE=m
160CONFIG_IP_SET_LIST_SET=m 166CONFIG_IP_SET_LIST_SET=m
161CONFIG_NF_CONNTRACK_IPV4=m 167CONFIG_NF_CONNTRACK_IPV4=m
162CONFIG_NF_TABLES_IPV4=m
163CONFIG_NFT_REJECT_IPV4=m
164CONFIG_NFT_CHAIN_ROUTE_IPV4=m 168CONFIG_NFT_CHAIN_ROUTE_IPV4=m
165CONFIG_NFT_CHAIN_NAT_IPV4=m 169CONFIG_NFT_CHAIN_NAT_IPV4=m
166CONFIG_NF_TABLES_ARP=m 170CONFIG_NF_TABLES_ARP=m
@@ -186,7 +190,6 @@ CONFIG_IP_NF_ARPTABLES=m
186CONFIG_IP_NF_ARPFILTER=m 190CONFIG_IP_NF_ARPFILTER=m
187CONFIG_IP_NF_ARP_MANGLE=m 191CONFIG_IP_NF_ARP_MANGLE=m
188CONFIG_NF_CONNTRACK_IPV6=m 192CONFIG_NF_CONNTRACK_IPV6=m
189CONFIG_NF_TABLES_IPV6=m
190CONFIG_NFT_CHAIN_ROUTE_IPV6=m 193CONFIG_NFT_CHAIN_ROUTE_IPV6=m
191CONFIG_NFT_CHAIN_NAT_IPV6=m 194CONFIG_NFT_CHAIN_NAT_IPV6=m
192CONFIG_IP6_NF_IPTABLES=m 195CONFIG_IP6_NF_IPTABLES=m
@@ -485,7 +488,6 @@ CONFIG_CRYPTO_LZ4HC=m
485CONFIG_CRYPTO_USER_API_HASH=m 488CONFIG_CRYPTO_USER_API_HASH=m
486CONFIG_CRYPTO_USER_API_SKCIPHER=m 489CONFIG_CRYPTO_USER_API_SKCIPHER=m
487# CONFIG_CRYPTO_HW is not set 490# CONFIG_CRYPTO_HW is not set
488CONFIG_CRC_T10DIF=y
489CONFIG_XZ_DEC_X86=y 491CONFIG_XZ_DEC_X86=y
490CONFIG_XZ_DEC_POWERPC=y 492CONFIG_XZ_DEC_POWERPC=y
491CONFIG_XZ_DEC_IA64=y 493CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/sun3_defconfig b/arch/m68k/configs/sun3_defconfig
index 60b0aeac5742..7bca0f464521 100644
--- a/arch/m68k/configs/sun3_defconfig
+++ b/arch/m68k/configs/sun3_defconfig
@@ -24,6 +24,8 @@ CONFIG_UNIXWARE_DISKLABEL=y
24# CONFIG_EFI_PARTITION is not set 24# CONFIG_EFI_PARTITION is not set
25CONFIG_SYSV68_PARTITION=y 25CONFIG_SYSV68_PARTITION=y
26CONFIG_IOSCHED_DEADLINE=m 26CONFIG_IOSCHED_DEADLINE=m
27CONFIG_KEXEC=y
28CONFIG_BOOTINFO_PROC=y
27CONFIG_SUN3=y 29CONFIG_SUN3=y
28# CONFIG_COMPACTION is not set 30# CONFIG_COMPACTION is not set
29CONFIG_CLEANCACHE=y 31CONFIG_CLEANCACHE=y
@@ -78,6 +80,7 @@ CONFIG_NF_CONNTRACK_SANE=m
78CONFIG_NF_CONNTRACK_SIP=m 80CONFIG_NF_CONNTRACK_SIP=m
79CONFIG_NF_CONNTRACK_TFTP=m 81CONFIG_NF_CONNTRACK_TFTP=m
80CONFIG_NF_TABLES=m 82CONFIG_NF_TABLES=m
83CONFIG_NF_TABLES_INET=m
81CONFIG_NFT_EXTHDR=m 84CONFIG_NFT_EXTHDR=m
82CONFIG_NFT_META=m 85CONFIG_NFT_META=m
83CONFIG_NFT_CT=m 86CONFIG_NFT_CT=m
@@ -87,6 +90,8 @@ CONFIG_NFT_COUNTER=m
87CONFIG_NFT_LOG=m 90CONFIG_NFT_LOG=m
88CONFIG_NFT_LIMIT=m 91CONFIG_NFT_LIMIT=m
89CONFIG_NFT_NAT=m 92CONFIG_NFT_NAT=m
93CONFIG_NFT_QUEUE=m
94CONFIG_NFT_REJECT=m
90CONFIG_NFT_COMPAT=m 95CONFIG_NFT_COMPAT=m
91CONFIG_NETFILTER_XT_SET=m 96CONFIG_NETFILTER_XT_SET=m
92CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 97CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -119,6 +124,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
119CONFIG_NETFILTER_XT_MATCH_ESP=m 124CONFIG_NETFILTER_XT_MATCH_ESP=m
120CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 125CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
121CONFIG_NETFILTER_XT_MATCH_HELPER=m 126CONFIG_NETFILTER_XT_MATCH_HELPER=m
127CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
122CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 128CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
123CONFIG_NETFILTER_XT_MATCH_LENGTH=m 129CONFIG_NETFILTER_XT_MATCH_LENGTH=m
124CONFIG_NETFILTER_XT_MATCH_LIMIT=m 130CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -156,8 +162,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
156CONFIG_IP_SET_HASH_NETIFACE=m 162CONFIG_IP_SET_HASH_NETIFACE=m
157CONFIG_IP_SET_LIST_SET=m 163CONFIG_IP_SET_LIST_SET=m
158CONFIG_NF_CONNTRACK_IPV4=m 164CONFIG_NF_CONNTRACK_IPV4=m
159CONFIG_NF_TABLES_IPV4=m
160CONFIG_NFT_REJECT_IPV4=m
161CONFIG_NFT_CHAIN_ROUTE_IPV4=m 165CONFIG_NFT_CHAIN_ROUTE_IPV4=m
162CONFIG_NFT_CHAIN_NAT_IPV4=m 166CONFIG_NFT_CHAIN_NAT_IPV4=m
163CONFIG_NF_TABLES_ARP=m 167CONFIG_NF_TABLES_ARP=m
@@ -183,7 +187,6 @@ CONFIG_IP_NF_ARPTABLES=m
183CONFIG_IP_NF_ARPFILTER=m 187CONFIG_IP_NF_ARPFILTER=m
184CONFIG_IP_NF_ARP_MANGLE=m 188CONFIG_IP_NF_ARP_MANGLE=m
185CONFIG_NF_CONNTRACK_IPV6=m 189CONFIG_NF_CONNTRACK_IPV6=m
186CONFIG_NF_TABLES_IPV6=m
187CONFIG_NFT_CHAIN_ROUTE_IPV6=m 190CONFIG_NFT_CHAIN_ROUTE_IPV6=m
188CONFIG_NFT_CHAIN_NAT_IPV6=m 191CONFIG_NFT_CHAIN_NAT_IPV6=m
189CONFIG_IP6_NF_IPTABLES=m 192CONFIG_IP6_NF_IPTABLES=m
@@ -464,7 +467,6 @@ CONFIG_CRYPTO_LZ4HC=m
464CONFIG_CRYPTO_USER_API_HASH=m 467CONFIG_CRYPTO_USER_API_HASH=m
465CONFIG_CRYPTO_USER_API_SKCIPHER=m 468CONFIG_CRYPTO_USER_API_SKCIPHER=m
466# CONFIG_CRYPTO_HW is not set 469# CONFIG_CRYPTO_HW is not set
467CONFIG_CRC_T10DIF=y
468CONFIG_XZ_DEC_X86=y 470CONFIG_XZ_DEC_X86=y
469CONFIG_XZ_DEC_POWERPC=y 471CONFIG_XZ_DEC_POWERPC=y
470CONFIG_XZ_DEC_IA64=y 472CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/configs/sun3x_defconfig b/arch/m68k/configs/sun3x_defconfig
index 21bda331eebb..317f3e1fec95 100644
--- a/arch/m68k/configs/sun3x_defconfig
+++ b/arch/m68k/configs/sun3x_defconfig
@@ -24,6 +24,8 @@ CONFIG_UNIXWARE_DISKLABEL=y
24# CONFIG_EFI_PARTITION is not set 24# CONFIG_EFI_PARTITION is not set
25CONFIG_SYSV68_PARTITION=y 25CONFIG_SYSV68_PARTITION=y
26CONFIG_IOSCHED_DEADLINE=m 26CONFIG_IOSCHED_DEADLINE=m
27CONFIG_KEXEC=y
28CONFIG_BOOTINFO_PROC=y
27CONFIG_SUN3X=y 29CONFIG_SUN3X=y
28# CONFIG_COMPACTION is not set 30# CONFIG_COMPACTION is not set
29CONFIG_CLEANCACHE=y 31CONFIG_CLEANCACHE=y
@@ -78,6 +80,7 @@ CONFIG_NF_CONNTRACK_SANE=m
78CONFIG_NF_CONNTRACK_SIP=m 80CONFIG_NF_CONNTRACK_SIP=m
79CONFIG_NF_CONNTRACK_TFTP=m 81CONFIG_NF_CONNTRACK_TFTP=m
80CONFIG_NF_TABLES=m 82CONFIG_NF_TABLES=m
83CONFIG_NF_TABLES_INET=m
81CONFIG_NFT_EXTHDR=m 84CONFIG_NFT_EXTHDR=m
82CONFIG_NFT_META=m 85CONFIG_NFT_META=m
83CONFIG_NFT_CT=m 86CONFIG_NFT_CT=m
@@ -87,6 +90,8 @@ CONFIG_NFT_COUNTER=m
87CONFIG_NFT_LOG=m 90CONFIG_NFT_LOG=m
88CONFIG_NFT_LIMIT=m 91CONFIG_NFT_LIMIT=m
89CONFIG_NFT_NAT=m 92CONFIG_NFT_NAT=m
93CONFIG_NFT_QUEUE=m
94CONFIG_NFT_REJECT=m
90CONFIG_NFT_COMPAT=m 95CONFIG_NFT_COMPAT=m
91CONFIG_NETFILTER_XT_SET=m 96CONFIG_NETFILTER_XT_SET=m
92CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 97CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -119,6 +124,7 @@ CONFIG_NETFILTER_XT_MATCH_DSCP=m
119CONFIG_NETFILTER_XT_MATCH_ESP=m 124CONFIG_NETFILTER_XT_MATCH_ESP=m
120CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m 125CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
121CONFIG_NETFILTER_XT_MATCH_HELPER=m 126CONFIG_NETFILTER_XT_MATCH_HELPER=m
127CONFIG_NETFILTER_XT_MATCH_IPCOMP=m
122CONFIG_NETFILTER_XT_MATCH_IPRANGE=m 128CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
123CONFIG_NETFILTER_XT_MATCH_LENGTH=m 129CONFIG_NETFILTER_XT_MATCH_LENGTH=m
124CONFIG_NETFILTER_XT_MATCH_LIMIT=m 130CONFIG_NETFILTER_XT_MATCH_LIMIT=m
@@ -156,8 +162,6 @@ CONFIG_IP_SET_HASH_NETPORT=m
156CONFIG_IP_SET_HASH_NETIFACE=m 162CONFIG_IP_SET_HASH_NETIFACE=m
157CONFIG_IP_SET_LIST_SET=m 163CONFIG_IP_SET_LIST_SET=m
158CONFIG_NF_CONNTRACK_IPV4=m 164CONFIG_NF_CONNTRACK_IPV4=m
159CONFIG_NF_TABLES_IPV4=m
160CONFIG_NFT_REJECT_IPV4=m
161CONFIG_NFT_CHAIN_ROUTE_IPV4=m 165CONFIG_NFT_CHAIN_ROUTE_IPV4=m
162CONFIG_NFT_CHAIN_NAT_IPV4=m 166CONFIG_NFT_CHAIN_NAT_IPV4=m
163CONFIG_NF_TABLES_ARP=m 167CONFIG_NF_TABLES_ARP=m
@@ -183,7 +187,6 @@ CONFIG_IP_NF_ARPTABLES=m
183CONFIG_IP_NF_ARPFILTER=m 187CONFIG_IP_NF_ARPFILTER=m
184CONFIG_IP_NF_ARP_MANGLE=m 188CONFIG_IP_NF_ARP_MANGLE=m
185CONFIG_NF_CONNTRACK_IPV6=m 189CONFIG_NF_CONNTRACK_IPV6=m
186CONFIG_NF_TABLES_IPV6=m
187CONFIG_NFT_CHAIN_ROUTE_IPV6=m 190CONFIG_NFT_CHAIN_ROUTE_IPV6=m
188CONFIG_NFT_CHAIN_NAT_IPV6=m 191CONFIG_NFT_CHAIN_NAT_IPV6=m
189CONFIG_IP6_NF_IPTABLES=m 192CONFIG_IP6_NF_IPTABLES=m
@@ -464,7 +467,6 @@ CONFIG_CRYPTO_LZ4HC=m
464CONFIG_CRYPTO_USER_API_HASH=m 467CONFIG_CRYPTO_USER_API_HASH=m
465CONFIG_CRYPTO_USER_API_SKCIPHER=m 468CONFIG_CRYPTO_USER_API_SKCIPHER=m
466# CONFIG_CRYPTO_HW is not set 469# CONFIG_CRYPTO_HW is not set
467CONFIG_CRC_T10DIF=y
468CONFIG_XZ_DEC_X86=y 470CONFIG_XZ_DEC_X86=y
469CONFIG_XZ_DEC_POWERPC=y 471CONFIG_XZ_DEC_POWERPC=y
470CONFIG_XZ_DEC_IA64=y 472CONFIG_XZ_DEC_IA64=y
diff --git a/arch/m68k/include/asm/Kbuild b/arch/m68k/include/asm/Kbuild
index 7cc8c364924d..c67c94a2d672 100644
--- a/arch/m68k/include/asm/Kbuild
+++ b/arch/m68k/include/asm/Kbuild
@@ -1,4 +1,4 @@
1 1generic-y += barrier.h
2generic-y += bitsperlong.h 2generic-y += bitsperlong.h
3generic-y += clkdev.h 3generic-y += clkdev.h
4generic-y += cputime.h 4generic-y += cputime.h
@@ -6,6 +6,7 @@ generic-y += device.h
6generic-y += emergency-restart.h 6generic-y += emergency-restart.h
7generic-y += errno.h 7generic-y += errno.h
8generic-y += exec.h 8generic-y += exec.h
9generic-y += hash.h
9generic-y += hw_irq.h 10generic-y += hw_irq.h
10generic-y += ioctl.h 11generic-y += ioctl.h
11generic-y += ipcbuf.h 12generic-y += ipcbuf.h
@@ -13,11 +14,13 @@ generic-y += irq_regs.h
13generic-y += kdebug.h 14generic-y += kdebug.h
14generic-y += kmap_types.h 15generic-y += kmap_types.h
15generic-y += kvm_para.h 16generic-y += kvm_para.h
16generic-y += local64.h
17generic-y += local.h 17generic-y += local.h
18generic-y += local64.h
19generic-y += mcs_spinlock.h
18generic-y += mman.h 20generic-y += mman.h
19generic-y += mutex.h 21generic-y += mutex.h
20generic-y += percpu.h 22generic-y += percpu.h
23generic-y += preempt.h
21generic-y += resource.h 24generic-y += resource.h
22generic-y += scatterlist.h 25generic-y += scatterlist.h
23generic-y += sections.h 26generic-y += sections.h
@@ -31,5 +34,3 @@ generic-y += trace_clock.h
31generic-y += types.h 34generic-y += types.h
32generic-y += word-at-a-time.h 35generic-y += word-at-a-time.h
33generic-y += xor.h 36generic-y += xor.h
34generic-y += preempt.h
35generic-y += hash.h
diff --git a/arch/m68k/include/asm/barrier.h b/arch/m68k/include/asm/barrier.h
deleted file mode 100644
index 15c5f77c1614..000000000000
--- a/arch/m68k/include/asm/barrier.h
+++ /dev/null
@@ -1,8 +0,0 @@
1#ifndef _M68K_BARRIER_H
2#define _M68K_BARRIER_H
3
4#define nop() do { asm volatile ("nop"); barrier(); } while (0)
5
6#include <asm-generic/barrier.h>
7
8#endif /* _M68K_BARRIER_H */
diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
index 014f288fc813..9d38b73989eb 100644
--- a/arch/m68k/include/asm/unistd.h
+++ b/arch/m68k/include/asm/unistd.h
@@ -4,7 +4,7 @@
4#include <uapi/asm/unistd.h> 4#include <uapi/asm/unistd.h>
5 5
6 6
7#define NR_syscalls 349 7#define NR_syscalls 351
8 8
9#define __ARCH_WANT_OLD_READDIR 9#define __ARCH_WANT_OLD_READDIR
10#define __ARCH_WANT_OLD_STAT 10#define __ARCH_WANT_OLD_STAT
diff --git a/arch/m68k/include/uapi/asm/unistd.h b/arch/m68k/include/uapi/asm/unistd.h
index 625f321001dc..b932dd470041 100644
--- a/arch/m68k/include/uapi/asm/unistd.h
+++ b/arch/m68k/include/uapi/asm/unistd.h
@@ -354,5 +354,7 @@
354#define __NR_process_vm_writev 346 354#define __NR_process_vm_writev 346
355#define __NR_kcmp 347 355#define __NR_kcmp 347
356#define __NR_finit_module 348 356#define __NR_finit_module 348
357#define __NR_sched_setattr 349
358#define __NR_sched_getattr 350
357 359
358#endif /* _UAPI_ASM_M68K_UNISTD_H_ */ 360#endif /* _UAPI_ASM_M68K_UNISTD_H_ */
diff --git a/arch/m68k/kernel/head.S b/arch/m68k/kernel/head.S
index 4c99bab7e664..3ab329b88521 100644
--- a/arch/m68k/kernel/head.S
+++ b/arch/m68k/kernel/head.S
@@ -275,7 +275,6 @@
275 275
276#ifdef CONFIG_FRAMEBUFFER_CONSOLE 276#ifdef CONFIG_FRAMEBUFFER_CONSOLE
277#define CONSOLE 277#define CONSOLE
278#define CONSOLE_PENGUIN
279#endif 278#endif
280 279
281#ifdef CONFIG_EARLY_PRINTK 280#ifdef CONFIG_EARLY_PRINTK
@@ -658,27 +657,6 @@ ENTRY(__start)
658 movel %a0@,%a1@ 657 movel %a0@,%a1@
659#endif 658#endif
660 659
661#if 0
662 /*
663 * Clear the screen
664 */
665 lea %pc@(L(mac_videobase)),%a0
666 movel %a0@,%a1
667 lea %pc@(L(mac_dimensions)),%a0
668 movel %a0@,%d1
669 swap %d1 /* #rows is high bytes */
670 andl #0xFFFF,%d1 /* rows */
671 subl #10,%d1
672 lea %pc@(L(mac_rowbytes)),%a0
673loopy2:
674 movel %a0@,%d0
675 subql #1,%d0
676loopx2:
677 moveb #0x55, %a1@+
678 dbra %d0,loopx2
679 dbra %d1,loopy2
680#endif
681
682L(test_notmac): 660L(test_notmac):
683#endif /* CONFIG_MAC */ 661#endif /* CONFIG_MAC */
684 662
@@ -907,15 +885,15 @@ L(nothp):
907 */ 885 */
908#ifdef CONFIG_MAC 886#ifdef CONFIG_MAC
909 is_not_mac(L(nocon)) 887 is_not_mac(L(nocon))
910#ifdef CONSOLE 888# ifdef CONSOLE
911 console_init 889 console_init
912#ifdef CONSOLE_PENGUIN 890# ifdef CONFIG_LOGO
913 console_put_penguin 891 console_put_penguin
914#endif /* CONSOLE_PENGUIN */ 892# endif /* CONFIG_LOGO */
915 console_put_stats 893 console_put_stats
916#endif /* CONSOLE */ 894# endif /* CONSOLE */
917L(nocon): 895L(nocon):
918#endif /* CONFIG_MAC */ 896#endif /* CONFIG_MAC */
919 897
920 898
921 putc '\n' 899 putc '\n'
@@ -3324,14 +3302,13 @@ func_return set_leds
3324#define Lconsole_struct_num_columns 8 3302#define Lconsole_struct_num_columns 8
3325#define Lconsole_struct_num_rows 12 3303#define Lconsole_struct_num_rows 12
3326#define Lconsole_struct_left_edge 16 3304#define Lconsole_struct_left_edge 16
3327#define Lconsole_struct_penguin_putc 20
3328 3305
3329func_start console_init,%a0-%a4/%d0-%d7 3306func_start console_init,%a0-%a4/%d0-%d7
3330 /* 3307 /*
3331 * Some of the register usage that follows 3308 * Some of the register usage that follows
3332 * a0 = pointer to boot_info 3309 * a0 = pointer to boot_info
3333 * a1 = pointer to screen 3310 * a1 = pointer to screen
3334 * a2 = pointer to Lconsole_globals 3311 * a2 = pointer to console_globals
3335 * d3 = pixel width of screen 3312 * d3 = pixel width of screen
3336 * d4 = pixel height of screen 3313 * d4 = pixel height of screen
3337 * (d3,d4) ~= (x,y) of a point just below 3314 * (d3,d4) ~= (x,y) of a point just below
@@ -3456,7 +3433,7 @@ func_start console_put_stats,%a0/%d7
3456 3433
3457func_return console_put_stats 3434func_return console_put_stats
3458 3435
3459#ifdef CONSOLE_PENGUIN 3436#ifdef CONFIG_LOGO
3460func_start console_put_penguin,%a0-%a1/%d0-%d7 3437func_start console_put_penguin,%a0-%a1/%d0-%d7
3461 /* 3438 /*
3462 * Get 'that_penguin' onto the screen in the upper right corner 3439 * Get 'that_penguin' onto the screen in the upper right corner
@@ -3799,38 +3776,6 @@ L(console_plot_pixel_exit):
3799func_return console_plot_pixel 3776func_return console_plot_pixel
3800#endif /* CONSOLE */ 3777#endif /* CONSOLE */
3801 3778
3802#if 0
3803/*
3804 * This is some old code lying around. I don't believe
3805 * it's used or important anymore. My guess is it contributed
3806 * to getting to this point, but it's done for now.
3807 * It was still in the 2.1.77 head.S, so it's still here.
3808 * (And still not used!)
3809 */
3810L(showtest):
3811 moveml %a0/%d7,%sp@-
3812 puts "A="
3813 putn %a1
3814
3815 .long 0xf0119f15 | ptestr #5,%a1@,#7,%a0
3816
3817 puts "DA="
3818 putn %a0
3819
3820 puts "D="
3821 putn %a0@
3822
3823 puts "S="
3824 lea %pc@(L(mmu)),%a0
3825 .long 0xf0106200 | pmove %psr,%a0@
3826 clrl %d7
3827 movew %a0@,%d7
3828 putn %d7
3829
3830 putc '\n'
3831 moveml %sp@+,%a0/%d7
3832 rts
3833#endif /* 0 */
3834 3779
3835__INITDATA 3780__INITDATA
3836 .align 4 3781 .align 4
@@ -3849,7 +3794,6 @@ L(console_globals):
3849 .long 0 /* max num columns */ 3794 .long 0 /* max num columns */
3850 .long 0 /* max num rows */ 3795 .long 0 /* max num rows */
3851 .long 0 /* left edge */ 3796 .long 0 /* left edge */
3852 .long 0 /* mac putc */
3853L(console_font): 3797L(console_font):
3854 .long 0 /* pointer to console font (struct font_desc) */ 3798 .long 0 /* pointer to console font (struct font_desc) */
3855L(console_font_data): 3799L(console_font_data):
diff --git a/arch/m68k/kernel/syscalltable.S b/arch/m68k/kernel/syscalltable.S
index 3f04ea0ab802..b6223dc41d82 100644
--- a/arch/m68k/kernel/syscalltable.S
+++ b/arch/m68k/kernel/syscalltable.S
@@ -369,4 +369,6 @@ ENTRY(sys_call_table)
369 .long sys_process_vm_writev 369 .long sys_process_vm_writev
370 .long sys_kcmp 370 .long sys_kcmp
371 .long sys_finit_module 371 .long sys_finit_module
372 .long sys_sched_setattr
373 .long sys_sched_getattr /* 350 */
372 374
diff --git a/arch/metag/include/asm/Kbuild b/arch/metag/include/asm/Kbuild
index b716d807c2ec..c29ead89a317 100644
--- a/arch/metag/include/asm/Kbuild
+++ b/arch/metag/include/asm/Kbuild
@@ -13,6 +13,7 @@ generic-y += fb.h
13generic-y += fcntl.h 13generic-y += fcntl.h
14generic-y += futex.h 14generic-y += futex.h
15generic-y += hardirq.h 15generic-y += hardirq.h
16generic-y += hash.h
16generic-y += hw_irq.h 17generic-y += hw_irq.h
17generic-y += ioctl.h 18generic-y += ioctl.h
18generic-y += ioctls.h 19generic-y += ioctls.h
@@ -23,6 +24,7 @@ generic-y += kmap_types.h
23generic-y += kvm_para.h 24generic-y += kvm_para.h
24generic-y += local.h 25generic-y += local.h
25generic-y += local64.h 26generic-y += local64.h
27generic-y += mcs_spinlock.h
26generic-y += msgbuf.h 28generic-y += msgbuf.h
27generic-y += mutex.h 29generic-y += mutex.h
28generic-y += param.h 30generic-y += param.h
@@ -30,6 +32,7 @@ generic-y += pci.h
30generic-y += percpu.h 32generic-y += percpu.h
31generic-y += poll.h 33generic-y += poll.h
32generic-y += posix_types.h 34generic-y += posix_types.h
35generic-y += preempt.h
33generic-y += scatterlist.h 36generic-y += scatterlist.h
34generic-y += sections.h 37generic-y += sections.h
35generic-y += sembuf.h 38generic-y += sembuf.h
@@ -52,5 +55,3 @@ generic-y += unaligned.h
52generic-y += user.h 55generic-y += user.h
53generic-y += vga.h 56generic-y += vga.h
54generic-y += xor.h 57generic-y += xor.h
55generic-y += preempt.h
56generic-y += hash.h
diff --git a/arch/microblaze/include/asm/Kbuild b/arch/microblaze/include/asm/Kbuild
index 2b98bc73642a..1f590ab8f323 100644
--- a/arch/microblaze/include/asm/Kbuild
+++ b/arch/microblaze/include/asm/Kbuild
@@ -3,6 +3,7 @@ generic-y += barrier.h
3generic-y += clkdev.h 3generic-y += clkdev.h
4generic-y += exec.h 4generic-y += exec.h
5generic-y += hash.h 5generic-y += hash.h
6generic-y += trace_clock.h 6generic-y += mcs_spinlock.h
7generic-y += syscalls.h
8generic-y += preempt.h 7generic-y += preempt.h
8generic-y += syscalls.h
9generic-y += trace_clock.h
diff --git a/arch/microblaze/include/asm/delay.h b/arch/microblaze/include/asm/delay.h
index 05b7d39e4391..66fc24c24238 100644
--- a/arch/microblaze/include/asm/delay.h
+++ b/arch/microblaze/include/asm/delay.h
@@ -13,6 +13,8 @@
13#ifndef _ASM_MICROBLAZE_DELAY_H 13#ifndef _ASM_MICROBLAZE_DELAY_H
14#define _ASM_MICROBLAZE_DELAY_H 14#define _ASM_MICROBLAZE_DELAY_H
15 15
16#include <linux/param.h>
17
16extern inline void __delay(unsigned long loops) 18extern inline void __delay(unsigned long loops)
17{ 19{
18 asm volatile ("# __delay \n\t" \ 20 asm volatile ("# __delay \n\t" \
diff --git a/arch/microblaze/include/asm/io.h b/arch/microblaze/include/asm/io.h
index a2cea7206077..3fbb7f1db3bc 100644
--- a/arch/microblaze/include/asm/io.h
+++ b/arch/microblaze/include/asm/io.h
@@ -89,6 +89,11 @@ static inline unsigned int readl(const volatile void __iomem *addr)
89{ 89{
90 return le32_to_cpu(*(volatile unsigned int __force *)addr); 90 return le32_to_cpu(*(volatile unsigned int __force *)addr);
91} 91}
92#define readq readq
93static inline u64 readq(const volatile void __iomem *addr)
94{
95 return le64_to_cpu(__raw_readq(addr));
96}
92static inline void writeb(unsigned char v, volatile void __iomem *addr) 97static inline void writeb(unsigned char v, volatile void __iomem *addr)
93{ 98{
94 *(volatile unsigned char __force *)addr = v; 99 *(volatile unsigned char __force *)addr = v;
@@ -101,6 +106,7 @@ static inline void writel(unsigned int v, volatile void __iomem *addr)
101{ 106{
102 *(volatile unsigned int __force *)addr = cpu_to_le32(v); 107 *(volatile unsigned int __force *)addr = cpu_to_le32(v);
103} 108}
109#define writeq(b, addr) __raw_writeq(cpu_to_le64(b), addr)
104 110
105/* ioread and iowrite variants. thease are for now same as __raw_ 111/* ioread and iowrite variants. thease are for now same as __raw_
106 * variants of accessors. we might check for endianess in the feature 112 * variants of accessors. we might check for endianess in the feature
diff --git a/arch/microblaze/kernel/head.S b/arch/microblaze/kernel/head.S
index b7fb0438458c..17645b2e2f07 100644
--- a/arch/microblaze/kernel/head.S
+++ b/arch/microblaze/kernel/head.S
@@ -66,7 +66,7 @@ real_start:
66 mts rmsr, r0 66 mts rmsr, r0
67/* Disable stack protection from bootloader */ 67/* Disable stack protection from bootloader */
68 mts rslr, r0 68 mts rslr, r0
69 addi r8, r0, 0xFFFFFFF 69 addi r8, r0, 0xFFFFFFFF
70 mts rshr, r8 70 mts rshr, r8
71/* 71/*
72 * According to Xilinx, msrclr instruction behaves like 'mfs rX,rpc' 72 * According to Xilinx, msrclr instruction behaves like 'mfs rX,rpc'
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index dcae3a7035db..95fa1f1d5c8b 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1776,12 +1776,12 @@ endchoice
1776 1776
1777config FORCE_MAX_ZONEORDER 1777config FORCE_MAX_ZONEORDER
1778 int "Maximum zone order" 1778 int "Maximum zone order"
1779 range 14 64 if HUGETLB_PAGE && PAGE_SIZE_64KB 1779 range 14 64 if MIPS_HUGE_TLB_SUPPORT && PAGE_SIZE_64KB
1780 default "14" if HUGETLB_PAGE && PAGE_SIZE_64KB 1780 default "14" if MIPS_HUGE_TLB_SUPPORT && PAGE_SIZE_64KB
1781 range 13 64 if HUGETLB_PAGE && PAGE_SIZE_32KB 1781 range 13 64 if MIPS_HUGE_TLB_SUPPORT && PAGE_SIZE_32KB
1782 default "13" if HUGETLB_PAGE && PAGE_SIZE_32KB 1782 default "13" if MIPS_HUGE_TLB_SUPPORT && PAGE_SIZE_32KB
1783 range 12 64 if HUGETLB_PAGE && PAGE_SIZE_16KB 1783 range 12 64 if MIPS_HUGE_TLB_SUPPORT && PAGE_SIZE_16KB
1784 default "12" if HUGETLB_PAGE && PAGE_SIZE_16KB 1784 default "12" if MIPS_HUGE_TLB_SUPPORT && PAGE_SIZE_16KB
1785 range 11 64 1785 range 11 64
1786 default "11" 1786 default "11"
1787 help 1787 help
@@ -2353,9 +2353,8 @@ config SECCOMP
2353 If unsure, say Y. Only embedded should say N here. 2353 If unsure, say Y. Only embedded should say N here.
2354 2354
2355config MIPS_O32_FP64_SUPPORT 2355config MIPS_O32_FP64_SUPPORT
2356 bool "Support for O32 binaries using 64-bit FP" 2356 bool "Support for O32 binaries using 64-bit FP (EXPERIMENTAL)"
2357 depends on 32BIT || MIPS32_O32 2357 depends on 32BIT || MIPS32_O32
2358 default y
2359 help 2358 help
2360 When this is enabled, the kernel will support use of 64-bit floating 2359 When this is enabled, the kernel will support use of 64-bit floating
2361 point registers with binaries using the O32 ABI along with the 2360 point registers with binaries using the O32 ABI along with the
@@ -2367,7 +2366,14 @@ config MIPS_O32_FP64_SUPPORT
2367 of your kernel & potentially improve FP emulation performance by 2366 of your kernel & potentially improve FP emulation performance by
2368 saying N here. 2367 saying N here.
2369 2368
2370 If unsure, say Y. 2369 Although binutils currently supports use of this flag the details
2370 concerning its effect upon the O32 ABI in userland are still being
2371 worked on. In order to avoid userland becoming dependant upon current
2372 behaviour before the details have been finalised, this option should
2373 be considered experimental and only enabled by those working upon
2374 said details.
2375
2376 If unsure, say N.
2371 2377
2372config USE_OF 2378config USE_OF
2373 bool 2379 bool
diff --git a/arch/mips/alchemy/board-gpr.c b/arch/mips/alchemy/board-gpr.c
index 9edc35ff8cf1..acf9a2a37f5a 100644
--- a/arch/mips/alchemy/board-gpr.c
+++ b/arch/mips/alchemy/board-gpr.c
@@ -53,10 +53,8 @@ void __init prom_init(void)
53 prom_init_cmdline(); 53 prom_init_cmdline();
54 54
55 memsize_str = prom_getenv("memsize"); 55 memsize_str = prom_getenv("memsize");
56 if (!memsize_str) 56 if (!memsize_str || kstrtoul(memsize_str, 0, &memsize))
57 memsize = 0x04000000; 57 memsize = 0x04000000;
58 else
59 strict_strtoul(memsize_str, 0, &memsize);
60 add_memory_region(0, memsize, BOOT_MEM_RAM); 58 add_memory_region(0, memsize, BOOT_MEM_RAM);
61} 59}
62 60
diff --git a/arch/mips/alchemy/board-mtx1.c b/arch/mips/alchemy/board-mtx1.c
index 9969dbab19e3..25a59a23547e 100644
--- a/arch/mips/alchemy/board-mtx1.c
+++ b/arch/mips/alchemy/board-mtx1.c
@@ -52,10 +52,8 @@ void __init prom_init(void)
52 prom_init_cmdline(); 52 prom_init_cmdline();
53 53
54 memsize_str = prom_getenv("memsize"); 54 memsize_str = prom_getenv("memsize");
55 if (!memsize_str) 55 if (!memsize_str || kstrtoul(memsize_str, 0, &memsize))
56 memsize = 0x04000000; 56 memsize = 0x04000000;
57 else
58 strict_strtoul(memsize_str, 0, &memsize);
59 add_memory_region(0, memsize, BOOT_MEM_RAM); 57 add_memory_region(0, memsize, BOOT_MEM_RAM);
60} 58}
61 59
diff --git a/arch/mips/alchemy/devboards/db1000.c b/arch/mips/alchemy/devboards/db1000.c
index 11f3ad20321c..5483906e0f86 100644
--- a/arch/mips/alchemy/devboards/db1000.c
+++ b/arch/mips/alchemy/devboards/db1000.c
@@ -534,13 +534,10 @@ static int __init db1000_dev_init(void)
534 s0 = AU1100_GPIO1_INT; 534 s0 = AU1100_GPIO1_INT;
535 s1 = AU1100_GPIO4_INT; 535 s1 = AU1100_GPIO4_INT;
536 536
537 gpio_request(19, "sd0_cd");
538 gpio_request(20, "sd1_cd");
537 gpio_direction_input(19); /* sd0 cd# */ 539 gpio_direction_input(19); /* sd0 cd# */
538 gpio_direction_input(20); /* sd1 cd# */ 540 gpio_direction_input(20); /* sd1 cd# */
539 gpio_direction_input(21); /* touch pendown# */
540 gpio_direction_input(207); /* SPI MISO */
541 gpio_direction_output(208, 0); /* SPI MOSI */
542 gpio_direction_output(209, 1); /* SPI SCK */
543 gpio_direction_output(210, 1); /* SPI CS# */
544 541
545 /* spi_gpio on SSI0 pins */ 542 /* spi_gpio on SSI0 pins */
546 pfc = __raw_readl((void __iomem *)SYS_PINFUNC); 543 pfc = __raw_readl((void __iomem *)SYS_PINFUNC);
diff --git a/arch/mips/bcm47xx/board.c b/arch/mips/bcm47xx/board.c
index 6d612e2b949b..cdd8246f92b3 100644
--- a/arch/mips/bcm47xx/board.c
+++ b/arch/mips/bcm47xx/board.c
@@ -1,3 +1,4 @@
1#include <linux/errno.h>
1#include <linux/export.h> 2#include <linux/export.h>
2#include <linux/string.h> 3#include <linux/string.h>
3#include <bcm47xx_board.h> 4#include <bcm47xx_board.h>
diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
index 6decb27cf48b..2bed73a684ae 100644
--- a/arch/mips/bcm47xx/nvram.c
+++ b/arch/mips/bcm47xx/nvram.c
@@ -196,7 +196,7 @@ int bcm47xx_nvram_gpio_pin(const char *name)
196 char nvram_var[10]; 196 char nvram_var[10];
197 char buf[30]; 197 char buf[30];
198 198
199 for (i = 0; i < 16; i++) { 199 for (i = 0; i < 32; i++) {
200 err = snprintf(nvram_var, sizeof(nvram_var), "gpio%i", i); 200 err = snprintf(nvram_var, sizeof(nvram_var), "gpio%i", i);
201 if (err <= 0) 201 if (err <= 0)
202 continue; 202 continue;
diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon/octeon-irq.c
index 25fbfae06c1f..c2bb4f896ce7 100644
--- a/arch/mips/cavium-octeon/octeon-irq.c
+++ b/arch/mips/cavium-octeon/octeon-irq.c
@@ -975,10 +975,6 @@ static int octeon_irq_ciu_xlat(struct irq_domain *d,
975 if (ciu > 1 || bit > 63) 975 if (ciu > 1 || bit > 63)
976 return -EINVAL; 976 return -EINVAL;
977 977
978 /* These are the GPIO lines */
979 if (ciu == 0 && bit >= 16 && bit < 32)
980 return -EINVAL;
981
982 *out_hwirq = (ciu << 6) | bit; 978 *out_hwirq = (ciu << 6) | bit;
983 *out_type = 0; 979 *out_type = 0;
984 980
@@ -1007,6 +1003,10 @@ static int octeon_irq_ciu_map(struct irq_domain *d,
1007 if (!octeon_irq_virq_in_range(virq)) 1003 if (!octeon_irq_virq_in_range(virq))
1008 return -EINVAL; 1004 return -EINVAL;
1009 1005
1006 /* Don't map irq if it is reserved for GPIO. */
1007 if (line == 0 && bit >= 16 && bit <32)
1008 return 0;
1009
1010 if (line > 1 || octeon_irq_ciu_to_irq[line][bit] != 0) 1010 if (line > 1 || octeon_irq_ciu_to_irq[line][bit] != 0)
1011 return -EINVAL; 1011 return -EINVAL;
1012 1012
@@ -1525,10 +1525,6 @@ static int octeon_irq_ciu2_xlat(struct irq_domain *d,
1525 ciu = intspec[0]; 1525 ciu = intspec[0];
1526 bit = intspec[1]; 1526 bit = intspec[1];
1527 1527
1528 /* Line 7 are the GPIO lines */
1529 if (ciu > 6 || bit > 63)
1530 return -EINVAL;
1531
1532 *out_hwirq = (ciu << 6) | bit; 1528 *out_hwirq = (ciu << 6) | bit;
1533 *out_type = 0; 1529 *out_type = 0;
1534 1530
@@ -1570,8 +1566,14 @@ static int octeon_irq_ciu2_map(struct irq_domain *d,
1570 if (!octeon_irq_virq_in_range(virq)) 1566 if (!octeon_irq_virq_in_range(virq))
1571 return -EINVAL; 1567 return -EINVAL;
1572 1568
1573 /* Line 7 are the GPIO lines */ 1569 /*
1574 if (line > 6 || octeon_irq_ciu_to_irq[line][bit] != 0) 1570 * Don't map irq if it is reserved for GPIO.
1571 * (Line 7 are the GPIO lines.)
1572 */
1573 if (line == 7)
1574 return 0;
1575
1576 if (line > 7 || octeon_irq_ciu_to_irq[line][bit] != 0)
1575 return -EINVAL; 1577 return -EINVAL;
1576 1578
1577 if (octeon_irq_ciu2_is_edge(line, bit)) 1579 if (octeon_irq_ciu2_is_edge(line, bit))
diff --git a/arch/mips/include/asm/Kbuild b/arch/mips/include/asm/Kbuild
index 2d7f65052c1f..05439187891d 100644
--- a/arch/mips/include/asm/Kbuild
+++ b/arch/mips/include/asm/Kbuild
@@ -2,16 +2,17 @@
2generic-y += cputime.h 2generic-y += cputime.h
3generic-y += current.h 3generic-y += current.h
4generic-y += emergency-restart.h 4generic-y += emergency-restart.h
5generic-y += hash.h
5generic-y += local64.h 6generic-y += local64.h
7generic-y += mcs_spinlock.h
6generic-y += mutex.h 8generic-y += mutex.h
7generic-y += parport.h 9generic-y += parport.h
8generic-y += percpu.h 10generic-y += percpu.h
11generic-y += preempt.h
9generic-y += scatterlist.h 12generic-y += scatterlist.h
10generic-y += sections.h 13generic-y += sections.h
11generic-y += segment.h 14generic-y += segment.h
12generic-y += serial.h 15generic-y += serial.h
13generic-y += trace_clock.h 16generic-y += trace_clock.h
14generic-y += preempt.h
15generic-y += ucontext.h 17generic-y += ucontext.h
16generic-y += xor.h 18generic-y += xor.h
17generic-y += hash.h
diff --git a/arch/mips/include/asm/asmmacro.h b/arch/mips/include/asm/asmmacro.h
index 3220c93ea981..4225e99bd7bf 100644
--- a/arch/mips/include/asm/asmmacro.h
+++ b/arch/mips/include/asm/asmmacro.h
@@ -9,6 +9,7 @@
9#define _ASM_ASMMACRO_H 9#define _ASM_ASMMACRO_H
10 10
11#include <asm/hazards.h> 11#include <asm/hazards.h>
12#include <asm/asm-offsets.h>
12 13
13#ifdef CONFIG_32BIT 14#ifdef CONFIG_32BIT
14#include <asm/asmmacro-32.h> 15#include <asm/asmmacro-32.h>
@@ -54,11 +55,21 @@
54 .endm 55 .endm
55 56
56 .macro local_irq_disable reg=t0 57 .macro local_irq_disable reg=t0
58#ifdef CONFIG_PREEMPT
59 lw \reg, TI_PRE_COUNT($28)
60 addi \reg, \reg, 1
61 sw \reg, TI_PRE_COUNT($28)
62#endif
57 mfc0 \reg, CP0_STATUS 63 mfc0 \reg, CP0_STATUS
58 ori \reg, \reg, 1 64 ori \reg, \reg, 1
59 xori \reg, \reg, 1 65 xori \reg, \reg, 1
60 mtc0 \reg, CP0_STATUS 66 mtc0 \reg, CP0_STATUS
61 irq_disable_hazard 67 irq_disable_hazard
68#ifdef CONFIG_PREEMPT
69 lw \reg, TI_PRE_COUNT($28)
70 addi \reg, \reg, -1
71 sw \reg, TI_PRE_COUNT($28)
72#endif
62 .endm 73 .endm
63#endif /* CONFIG_MIPS_MT_SMTC */ 74#endif /* CONFIG_MIPS_MT_SMTC */
64 75
@@ -106,7 +117,7 @@
106 .endm 117 .endm
107 118
108 .macro fpu_save_double thread status tmp 119 .macro fpu_save_double thread status tmp
109#if defined(CONFIG_MIPS64) || defined(CONFIG_CPU_MIPS32_R2) 120#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
110 sll \tmp, \status, 5 121 sll \tmp, \status, 5
111 bgez \tmp, 10f 122 bgez \tmp, 10f
112 fpu_save_16odd \thread 123 fpu_save_16odd \thread
@@ -159,7 +170,7 @@
159 .endm 170 .endm
160 171
161 .macro fpu_restore_double thread status tmp 172 .macro fpu_restore_double thread status tmp
162#if defined(CONFIG_MIPS64) || defined(CONFIG_CPU_MIPS32_R2) 173#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
163 sll \tmp, \status, 5 174 sll \tmp, \status, 5
164 bgez \tmp, 10f # 16 register mode? 175 bgez \tmp, 10f # 16 register mode?
165 176
diff --git a/arch/mips/include/asm/fpu.h b/arch/mips/include/asm/fpu.h
index cfe092fc720d..58e50cbdb1a6 100644
--- a/arch/mips/include/asm/fpu.h
+++ b/arch/mips/include/asm/fpu.h
@@ -57,7 +57,7 @@ static inline int __enable_fpu(enum fpu_mode mode)
57 return 0; 57 return 0;
58 58
59 case FPU_64BIT: 59 case FPU_64BIT:
60#if !(defined(CONFIG_CPU_MIPS32_R2) || defined(CONFIG_MIPS64)) 60#if !(defined(CONFIG_CPU_MIPS32_R2) || defined(CONFIG_64BIT))
61 /* we only have a 32-bit FPU */ 61 /* we only have a 32-bit FPU */
62 return SIGFPE; 62 return SIGFPE;
63#endif 63#endif
@@ -74,6 +74,8 @@ static inline int __enable_fpu(enum fpu_mode mode)
74 default: 74 default:
75 BUG(); 75 BUG();
76 } 76 }
77
78 return SIGFPE;
77} 79}
78 80
79#define __disable_fpu() \ 81#define __disable_fpu() \
diff --git a/arch/mips/include/asm/ftrace.h b/arch/mips/include/asm/ftrace.h
index ce35c9af0c28..992aaba603b5 100644
--- a/arch/mips/include/asm/ftrace.h
+++ b/arch/mips/include/asm/ftrace.h
@@ -22,12 +22,12 @@ extern void _mcount(void);
22#define safe_load(load, src, dst, error) \ 22#define safe_load(load, src, dst, error) \
23do { \ 23do { \
24 asm volatile ( \ 24 asm volatile ( \
25 "1: " load " %[" STR(dst) "], 0(%[" STR(src) "])\n"\ 25 "1: " load " %[tmp_dst], 0(%[tmp_src])\n" \
26 " li %[" STR(error) "], 0\n" \ 26 " li %[tmp_err], 0\n" \
27 "2:\n" \ 27 "2:\n" \
28 \ 28 \
29 ".section .fixup, \"ax\"\n" \ 29 ".section .fixup, \"ax\"\n" \
30 "3: li %[" STR(error) "], 1\n" \ 30 "3: li %[tmp_err], 1\n" \
31 " j 2b\n" \ 31 " j 2b\n" \
32 ".previous\n" \ 32 ".previous\n" \
33 \ 33 \
@@ -35,8 +35,8 @@ do { \
35 STR(PTR) "\t1b, 3b\n\t" \ 35 STR(PTR) "\t1b, 3b\n\t" \
36 ".previous\n" \ 36 ".previous\n" \
37 \ 37 \
38 : [dst] "=&r" (dst), [error] "=r" (error)\ 38 : [tmp_dst] "=&r" (dst), [tmp_err] "=r" (error)\
39 : [src] "r" (src) \ 39 : [tmp_src] "r" (src) \
40 : "memory" \ 40 : "memory" \
41 ); \ 41 ); \
42} while (0) 42} while (0)
@@ -44,12 +44,12 @@ do { \
44#define safe_store(store, src, dst, error) \ 44#define safe_store(store, src, dst, error) \
45do { \ 45do { \
46 asm volatile ( \ 46 asm volatile ( \
47 "1: " store " %[" STR(src) "], 0(%[" STR(dst) "])\n"\ 47 "1: " store " %[tmp_src], 0(%[tmp_dst])\n"\
48 " li %[" STR(error) "], 0\n" \ 48 " li %[tmp_err], 0\n" \
49 "2:\n" \ 49 "2:\n" \
50 \ 50 \
51 ".section .fixup, \"ax\"\n" \ 51 ".section .fixup, \"ax\"\n" \
52 "3: li %[" STR(error) "], 1\n" \ 52 "3: li %[tmp_err], 1\n" \
53 " j 2b\n" \ 53 " j 2b\n" \
54 ".previous\n" \ 54 ".previous\n" \
55 \ 55 \
@@ -57,8 +57,8 @@ do { \
57 STR(PTR) "\t1b, 3b\n\t" \ 57 STR(PTR) "\t1b, 3b\n\t" \
58 ".previous\n" \ 58 ".previous\n" \
59 \ 59 \
60 : [error] "=r" (error) \ 60 : [tmp_err] "=r" (error) \
61 : [dst] "r" (dst), [src] "r" (src)\ 61 : [tmp_dst] "r" (dst), [tmp_src] "r" (src)\
62 : "memory" \ 62 : "memory" \
63 ); \ 63 ); \
64} while (0) 64} while (0)
diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h
index 33e8dbfc1b63..f35b131977e6 100644
--- a/arch/mips/include/asm/syscall.h
+++ b/arch/mips/include/asm/syscall.h
@@ -13,6 +13,7 @@
13#ifndef __ASM_MIPS_SYSCALL_H 13#ifndef __ASM_MIPS_SYSCALL_H
14#define __ASM_MIPS_SYSCALL_H 14#define __ASM_MIPS_SYSCALL_H
15 15
16#include <linux/compiler.h>
16#include <linux/audit.h> 17#include <linux/audit.h>
17#include <linux/elf-em.h> 18#include <linux/elf-em.h>
18#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -39,14 +40,14 @@ static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
39 40
40#ifdef CONFIG_32BIT 41#ifdef CONFIG_32BIT
41 case 4: case 5: case 6: case 7: 42 case 4: case 5: case 6: case 7:
42 return get_user(*arg, (int *)usp + 4 * n); 43 return get_user(*arg, (int *)usp + n);
43#endif 44#endif
44 45
45#ifdef CONFIG_64BIT 46#ifdef CONFIG_64BIT
46 case 4: case 5: case 6: case 7: 47 case 4: case 5: case 6: case 7:
47#ifdef CONFIG_MIPS32_O32 48#ifdef CONFIG_MIPS32_O32
48 if (test_thread_flag(TIF_32BIT_REGS)) 49 if (test_thread_flag(TIF_32BIT_REGS))
49 return get_user(*arg, (int *)usp + 4 * n); 50 return get_user(*arg, (int *)usp + n);
50 else 51 else
51#endif 52#endif
52 *arg = regs->regs[4 + n]; 53 *arg = regs->regs[4 + n];
@@ -57,6 +58,8 @@ static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
57 default: 58 default:
58 BUG(); 59 BUG();
59 } 60 }
61
62 unreachable();
60} 63}
61 64
62static inline long syscall_get_return_value(struct task_struct *task, 65static inline long syscall_get_return_value(struct task_struct *task,
@@ -83,11 +86,10 @@ static inline void syscall_get_arguments(struct task_struct *task,
83 unsigned int i, unsigned int n, 86 unsigned int i, unsigned int n,
84 unsigned long *args) 87 unsigned long *args)
85{ 88{
86 unsigned long arg;
87 int ret; 89 int ret;
88 90
89 while (n--) 91 while (n--)
90 ret |= mips_get_syscall_arg(&arg, task, regs, i++); 92 ret |= mips_get_syscall_arg(args++, task, regs, i++);
91 93
92 /* 94 /*
93 * No way to communicate an error because this is a void function. 95 * No way to communicate an error because this is a void function.
diff --git a/arch/mips/include/asm/topology.h b/arch/mips/include/asm/topology.h
index 12609a17dc8b..20ea4859c822 100644
--- a/arch/mips/include/asm/topology.h
+++ b/arch/mips/include/asm/topology.h
@@ -10,8 +10,4 @@
10 10
11#include <topology.h> 11#include <topology.h>
12 12
13#ifdef CONFIG_SMP
14#define smt_capable() (smp_num_siblings > 1)
15#endif
16
17#endif /* __ASM_TOPOLOGY_H */ 13#endif /* __ASM_TOPOLOGY_H */
diff --git a/arch/mips/include/asm/unistd.h b/arch/mips/include/asm/unistd.h
index 4d3b92886665..413d6c612bec 100644
--- a/arch/mips/include/asm/unistd.h
+++ b/arch/mips/include/asm/unistd.h
@@ -24,7 +24,6 @@
24 24
25#ifndef __ASSEMBLY__ 25#ifndef __ASSEMBLY__
26 26
27#define __ARCH_OMIT_COMPAT_SYS_GETDENTS64
28#define __ARCH_WANT_OLD_READDIR 27#define __ARCH_WANT_OLD_READDIR
29#define __ARCH_WANT_SYS_ALARM 28#define __ARCH_WANT_SYS_ALARM
30#define __ARCH_WANT_SYS_GETHOSTNAME 29#define __ARCH_WANT_SYS_GETHOSTNAME
diff --git a/arch/mips/include/uapi/asm/inst.h b/arch/mips/include/uapi/asm/inst.h
index b39ba25b41cc..f25181b19941 100644
--- a/arch/mips/include/uapi/asm/inst.h
+++ b/arch/mips/include/uapi/asm/inst.h
@@ -163,8 +163,8 @@ enum cop1_sdw_func {
163 */ 163 */
164enum cop1x_func { 164enum cop1x_func {
165 lwxc1_op = 0x00, ldxc1_op = 0x01, 165 lwxc1_op = 0x00, ldxc1_op = 0x01,
166 pfetch_op = 0x07, swxc1_op = 0x08, 166 swxc1_op = 0x08, sdxc1_op = 0x09,
167 sdxc1_op = 0x09, madd_s_op = 0x20, 167 pfetch_op = 0x0f, madd_s_op = 0x20,
168 madd_d_op = 0x21, madd_e_op = 0x22, 168 madd_d_op = 0x21, madd_e_op = 0x22,
169 msub_s_op = 0x28, msub_d_op = 0x29, 169 msub_s_op = 0x28, msub_d_op = 0x29,
170 msub_e_op = 0x2a, nmadd_s_op = 0x30, 170 msub_e_op = 0x2a, nmadd_s_op = 0x30,
diff --git a/arch/mips/include/uapi/asm/unistd.h b/arch/mips/include/uapi/asm/unistd.h
index 1dee279f9665..d6e154a9e6a5 100644
--- a/arch/mips/include/uapi/asm/unistd.h
+++ b/arch/mips/include/uapi/asm/unistd.h
@@ -369,16 +369,18 @@
369#define __NR_process_vm_writev (__NR_Linux + 346) 369#define __NR_process_vm_writev (__NR_Linux + 346)
370#define __NR_kcmp (__NR_Linux + 347) 370#define __NR_kcmp (__NR_Linux + 347)
371#define __NR_finit_module (__NR_Linux + 348) 371#define __NR_finit_module (__NR_Linux + 348)
372#define __NR_sched_setattr (__NR_Linux + 349)
373#define __NR_sched_getattr (__NR_Linux + 350)
372 374
373/* 375/*
374 * Offset of the last Linux o32 flavoured syscall 376 * Offset of the last Linux o32 flavoured syscall
375 */ 377 */
376#define __NR_Linux_syscalls 348 378#define __NR_Linux_syscalls 350
377 379
378#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */ 380#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */
379 381
380#define __NR_O32_Linux 4000 382#define __NR_O32_Linux 4000
381#define __NR_O32_Linux_syscalls 348 383#define __NR_O32_Linux_syscalls 350
382 384
383#if _MIPS_SIM == _MIPS_SIM_ABI64 385#if _MIPS_SIM == _MIPS_SIM_ABI64
384 386
@@ -695,16 +697,18 @@
695#define __NR_kcmp (__NR_Linux + 306) 697#define __NR_kcmp (__NR_Linux + 306)
696#define __NR_finit_module (__NR_Linux + 307) 698#define __NR_finit_module (__NR_Linux + 307)
697#define __NR_getdents64 (__NR_Linux + 308) 699#define __NR_getdents64 (__NR_Linux + 308)
700#define __NR_sched_setattr (__NR_Linux + 309)
701#define __NR_sched_getattr (__NR_Linux + 310)
698 702
699/* 703/*
700 * Offset of the last Linux 64-bit flavoured syscall 704 * Offset of the last Linux 64-bit flavoured syscall
701 */ 705 */
702#define __NR_Linux_syscalls 308 706#define __NR_Linux_syscalls 310
703 707
704#endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */ 708#endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */
705 709
706#define __NR_64_Linux 5000 710#define __NR_64_Linux 5000
707#define __NR_64_Linux_syscalls 308 711#define __NR_64_Linux_syscalls 310
708 712
709#if _MIPS_SIM == _MIPS_SIM_NABI32 713#if _MIPS_SIM == _MIPS_SIM_NABI32
710 714
@@ -1025,15 +1029,17 @@
1025#define __NR_process_vm_writev (__NR_Linux + 310) 1029#define __NR_process_vm_writev (__NR_Linux + 310)
1026#define __NR_kcmp (__NR_Linux + 311) 1030#define __NR_kcmp (__NR_Linux + 311)
1027#define __NR_finit_module (__NR_Linux + 312) 1031#define __NR_finit_module (__NR_Linux + 312)
1032#define __NR_sched_setattr (__NR_Linux + 313)
1033#define __NR_sched_getattr (__NR_Linux + 314)
1028 1034
1029/* 1035/*
1030 * Offset of the last N32 flavoured syscall 1036 * Offset of the last N32 flavoured syscall
1031 */ 1037 */
1032#define __NR_Linux_syscalls 312 1038#define __NR_Linux_syscalls 314
1033 1039
1034#endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */ 1040#endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */
1035 1041
1036#define __NR_N32_Linux 6000 1042#define __NR_N32_Linux 6000
1037#define __NR_N32_Linux_syscalls 312 1043#define __NR_N32_Linux_syscalls 314
1038 1044
1039#endif /* _UAPI_ASM_UNISTD_H */ 1045#endif /* _UAPI_ASM_UNISTD_H */
diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c
index 185ba258361b..374ed74cd516 100644
--- a/arch/mips/kernel/ftrace.c
+++ b/arch/mips/kernel/ftrace.c
@@ -111,11 +111,10 @@ static int ftrace_modify_code_2(unsigned long ip, unsigned int new_code1,
111 safe_store_code(new_code1, ip, faulted); 111 safe_store_code(new_code1, ip, faulted);
112 if (unlikely(faulted)) 112 if (unlikely(faulted))
113 return -EFAULT; 113 return -EFAULT;
114 ip += 4; 114 safe_store_code(new_code2, ip + 4, faulted);
115 safe_store_code(new_code2, ip, faulted);
116 if (unlikely(faulted)) 115 if (unlikely(faulted))
117 return -EFAULT; 116 return -EFAULT;
118 flush_icache_range(ip, ip + 8); /* original ip + 12 */ 117 flush_icache_range(ip, ip + 8);
119 return 0; 118 return 0;
120} 119}
121#endif 120#endif
diff --git a/arch/mips/kernel/r4k_fpu.S b/arch/mips/kernel/r4k_fpu.S
index 253b2fb52026..73b0ddf910d4 100644
--- a/arch/mips/kernel/r4k_fpu.S
+++ b/arch/mips/kernel/r4k_fpu.S
@@ -35,9 +35,9 @@
35LEAF(_save_fp_context) 35LEAF(_save_fp_context)
36 cfc1 t1, fcr31 36 cfc1 t1, fcr31
37 37
38#if defined(CONFIG_64BIT) || defined(CONFIG_MIPS32_R2) 38#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
39 .set push 39 .set push
40#ifdef CONFIG_MIPS32_R2 40#ifdef CONFIG_CPU_MIPS32_R2
41 .set mips64r2 41 .set mips64r2
42 mfc0 t0, CP0_STATUS 42 mfc0 t0, CP0_STATUS
43 sll t0, t0, 5 43 sll t0, t0, 5
@@ -146,11 +146,11 @@ LEAF(_save_fp_context32)
146 * - cp1 status/control register 146 * - cp1 status/control register
147 */ 147 */
148LEAF(_restore_fp_context) 148LEAF(_restore_fp_context)
149 EX lw t0, SC_FPC_CSR(a0) 149 EX lw t1, SC_FPC_CSR(a0)
150 150
151#if defined(CONFIG_64BIT) || defined(CONFIG_MIPS32_R2) 151#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
152 .set push 152 .set push
153#ifdef CONFIG_MIPS32_R2 153#ifdef CONFIG_CPU_MIPS32_R2
154 .set mips64r2 154 .set mips64r2
155 mfc0 t0, CP0_STATUS 155 mfc0 t0, CP0_STATUS
156 sll t0, t0, 5 156 sll t0, t0, 5
@@ -191,7 +191,7 @@ LEAF(_restore_fp_context)
191 EX ldc1 $f26, SC_FPREGS+208(a0) 191 EX ldc1 $f26, SC_FPREGS+208(a0)
192 EX ldc1 $f28, SC_FPREGS+224(a0) 192 EX ldc1 $f28, SC_FPREGS+224(a0)
193 EX ldc1 $f30, SC_FPREGS+240(a0) 193 EX ldc1 $f30, SC_FPREGS+240(a0)
194 ctc1 t0, fcr31 194 ctc1 t1, fcr31
195 jr ra 195 jr ra
196 li v0, 0 # success 196 li v0, 0 # success
197 END(_restore_fp_context) 197 END(_restore_fp_context)
@@ -199,7 +199,7 @@ LEAF(_restore_fp_context)
199#ifdef CONFIG_MIPS32_COMPAT 199#ifdef CONFIG_MIPS32_COMPAT
200LEAF(_restore_fp_context32) 200LEAF(_restore_fp_context32)
201 /* Restore an o32 sigcontext. */ 201 /* Restore an o32 sigcontext. */
202 EX lw t0, SC32_FPC_CSR(a0) 202 EX lw t1, SC32_FPC_CSR(a0)
203 203
204 mfc0 t0, CP0_STATUS 204 mfc0 t0, CP0_STATUS
205 sll t0, t0, 5 205 sll t0, t0, 5
@@ -239,7 +239,7 @@ LEAF(_restore_fp_context32)
239 EX ldc1 $f26, SC32_FPREGS+208(a0) 239 EX ldc1 $f26, SC32_FPREGS+208(a0)
240 EX ldc1 $f28, SC32_FPREGS+224(a0) 240 EX ldc1 $f28, SC32_FPREGS+224(a0)
241 EX ldc1 $f30, SC32_FPREGS+240(a0) 241 EX ldc1 $f30, SC32_FPREGS+240(a0)
242 ctc1 t0, fcr31 242 ctc1 t1, fcr31
243 jr ra 243 jr ra
244 li v0, 0 # success 244 li v0, 0 # success
245 END(_restore_fp_context32) 245 END(_restore_fp_context32)
diff --git a/arch/mips/kernel/rtlx-cmp.c b/arch/mips/kernel/rtlx-cmp.c
index 56dc69635153..758fb3cd2326 100644
--- a/arch/mips/kernel/rtlx-cmp.c
+++ b/arch/mips/kernel/rtlx-cmp.c
@@ -112,5 +112,8 @@ void __exit rtlx_module_exit(void)
112 112
113 for (i = 0; i < RTLX_CHANNELS; i++) 113 for (i = 0; i < RTLX_CHANNELS; i++)
114 device_destroy(mt_class, MKDEV(major, i)); 114 device_destroy(mt_class, MKDEV(major, i));
115
115 unregister_chrdev(major, RTLX_MODULE_NAME); 116 unregister_chrdev(major, RTLX_MODULE_NAME);
117
118 aprp_hook = NULL;
116} 119}
diff --git a/arch/mips/kernel/rtlx-mt.c b/arch/mips/kernel/rtlx-mt.c
index 91d61ba422b4..9c1aca00fd54 100644
--- a/arch/mips/kernel/rtlx-mt.c
+++ b/arch/mips/kernel/rtlx-mt.c
@@ -144,5 +144,8 @@ void __exit rtlx_module_exit(void)
144 144
145 for (i = 0; i < RTLX_CHANNELS; i++) 145 for (i = 0; i < RTLX_CHANNELS; i++)
146 device_destroy(mt_class, MKDEV(major, i)); 146 device_destroy(mt_class, MKDEV(major, i));
147
147 unregister_chrdev(major, RTLX_MODULE_NAME); 148 unregister_chrdev(major, RTLX_MODULE_NAME);
149
150 aprp_hook = NULL;
148} 151}
diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
index e8e541b40d86..a5b14f48e1af 100644
--- a/arch/mips/kernel/scall32-o32.S
+++ b/arch/mips/kernel/scall32-o32.S
@@ -563,3 +563,5 @@ EXPORT(sys_call_table)
563 PTR sys_process_vm_writev 563 PTR sys_process_vm_writev
564 PTR sys_kcmp 564 PTR sys_kcmp
565 PTR sys_finit_module 565 PTR sys_finit_module
566 PTR sys_sched_setattr
567 PTR sys_sched_getattr /* 4350 */
diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
index 57e3742fec59..b56e254beb15 100644
--- a/arch/mips/kernel/scall64-64.S
+++ b/arch/mips/kernel/scall64-64.S
@@ -425,4 +425,6 @@ EXPORT(sys_call_table)
425 PTR sys_kcmp 425 PTR sys_kcmp
426 PTR sys_finit_module 426 PTR sys_finit_module
427 PTR sys_getdents64 427 PTR sys_getdents64
428 PTR sys_sched_setattr
429 PTR sys_sched_getattr /* 5310 */
428 .size sys_call_table,.-sys_call_table 430 .size sys_call_table,.-sys_call_table
diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
index 2f48f5934399..f7e5b72cf481 100644
--- a/arch/mips/kernel/scall64-n32.S
+++ b/arch/mips/kernel/scall64-n32.S
@@ -418,4 +418,6 @@ EXPORT(sysn32_call_table)
418 PTR compat_sys_process_vm_writev /* 6310 */ 418 PTR compat_sys_process_vm_writev /* 6310 */
419 PTR sys_kcmp 419 PTR sys_kcmp
420 PTR sys_finit_module 420 PTR sys_finit_module
421 PTR sys_sched_setattr
422 PTR sys_sched_getattr
421 .size sysn32_call_table,.-sysn32_call_table 423 .size sysn32_call_table,.-sysn32_call_table
diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
index f1acdb429f4f..6788727d91af 100644
--- a/arch/mips/kernel/scall64-o32.S
+++ b/arch/mips/kernel/scall64-o32.S
@@ -541,4 +541,6 @@ EXPORT(sys32_call_table)
541 PTR compat_sys_process_vm_writev 541 PTR compat_sys_process_vm_writev
542 PTR sys_kcmp 542 PTR sys_kcmp
543 PTR sys_finit_module 543 PTR sys_finit_module
544 PTR sys_sched_setattr
545 PTR sys_sched_getattr /* 4350 */
544 .size sys32_call_table,.-sys32_call_table 546 .size sys32_call_table,.-sys32_call_table
diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c
index 506925b2c3f3..0b4e2e38294b 100644
--- a/arch/mips/math-emu/cp1emu.c
+++ b/arch/mips/math-emu/cp1emu.c
@@ -1538,10 +1538,10 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
1538 break; 1538 break;
1539 } 1539 }
1540 1540
1541 case 0x7: /* 7 */ 1541 case 0x3:
1542 if (MIPSInst_FUNC(ir) != pfetch_op) { 1542 if (MIPSInst_FUNC(ir) != pfetch_op)
1543 return SIGILL; 1543 return SIGILL;
1544 } 1544
1545 /* ignore prefx operation */ 1545 /* ignore prefx operation */
1546 break; 1546 break;
1547 1547
diff --git a/arch/mips/mti-malta/malta-amon.c b/arch/mips/mti-malta/malta-amon.c
index 592ac0427426..84ac523b0ce0 100644
--- a/arch/mips/mti-malta/malta-amon.c
+++ b/arch/mips/mti-malta/malta-amon.c
@@ -72,7 +72,7 @@ int amon_cpu_start(int cpu,
72 return 0; 72 return 0;
73} 73}
74 74
75#ifdef CONFIG_MIPS_VPE_LOADER 75#ifdef CONFIG_MIPS_VPE_LOADER_CMP
76int vpe_run(struct vpe *v) 76int vpe_run(struct vpe *v)
77{ 77{
78 struct vpe_notifications *n; 78 struct vpe_notifications *n;
diff --git a/arch/mips/mti-malta/malta-int.c b/arch/mips/mti-malta/malta-int.c
index ca3e3a46a42f..2242181a6284 100644
--- a/arch/mips/mti-malta/malta-int.c
+++ b/arch/mips/mti-malta/malta-int.c
@@ -119,7 +119,7 @@ static void malta_hw0_irqdispatch(void)
119 119
120 do_IRQ(MALTA_INT_BASE + irq); 120 do_IRQ(MALTA_INT_BASE + irq);
121 121
122#ifdef MIPS_VPE_APSP_API 122#ifdef CONFIG_MIPS_VPE_APSP_API_MT
123 if (aprp_hook) 123 if (aprp_hook)
124 aprp_hook(); 124 aprp_hook();
125#endif 125#endif
@@ -310,7 +310,7 @@ static void ipi_call_dispatch(void)
310 310
311static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id) 311static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id)
312{ 312{
313#ifdef MIPS_VPE_APSP_API 313#ifdef CONFIG_MIPS_VPE_APSP_API_CMP
314 if (aprp_hook) 314 if (aprp_hook)
315 aprp_hook(); 315 aprp_hook();
316#endif 316#endif
diff --git a/arch/mips/pci/msi-octeon.c b/arch/mips/pci/msi-octeon.c
index d37be36dc659..2b91b0e61566 100644
--- a/arch/mips/pci/msi-octeon.c
+++ b/arch/mips/pci/msi-octeon.c
@@ -150,6 +150,7 @@ msi_irq_allocated:
150 msg.address_lo = 150 msg.address_lo =
151 ((128ul << 20) + CVMX_PCI_MSI_RCV) & 0xffffffff; 151 ((128ul << 20) + CVMX_PCI_MSI_RCV) & 0xffffffff;
152 msg.address_hi = ((128ul << 20) + CVMX_PCI_MSI_RCV) >> 32; 152 msg.address_hi = ((128ul << 20) + CVMX_PCI_MSI_RCV) >> 32;
153 break;
153 case OCTEON_DMA_BAR_TYPE_BIG: 154 case OCTEON_DMA_BAR_TYPE_BIG:
154 /* When using big bar, Bar 0 is based at 0 */ 155 /* When using big bar, Bar 0 is based at 0 */
155 msg.address_lo = (0 + CVMX_PCI_MSI_RCV) & 0xffffffff; 156 msg.address_lo = (0 + CVMX_PCI_MSI_RCV) & 0xffffffff;
diff --git a/arch/mn10300/include/asm/Kbuild b/arch/mn10300/include/asm/Kbuild
index 992e989ab785..cbc6b9bf45da 100644
--- a/arch/mn10300/include/asm/Kbuild
+++ b/arch/mn10300/include/asm/Kbuild
@@ -3,5 +3,6 @@ generic-y += barrier.h
3generic-y += clkdev.h 3generic-y += clkdev.h
4generic-y += exec.h 4generic-y += exec.h
5generic-y += hash.h 5generic-y += hash.h
6generic-y += trace_clock.h 6generic-y += mcs_spinlock.h
7generic-y += preempt.h 7generic-y += preempt.h
8generic-y += trace_clock.h
diff --git a/arch/openrisc/include/asm/Kbuild b/arch/openrisc/include/asm/Kbuild
index 2e40f1ca8667..480af0d9c2f5 100644
--- a/arch/openrisc/include/asm/Kbuild
+++ b/arch/openrisc/include/asm/Kbuild
@@ -10,8 +10,8 @@ generic-y += bugs.h
10generic-y += cacheflush.h 10generic-y += cacheflush.h
11generic-y += checksum.h 11generic-y += checksum.h
12generic-y += clkdev.h 12generic-y += clkdev.h
13generic-y += cmpxchg.h
14generic-y += cmpxchg-local.h 13generic-y += cmpxchg-local.h
14generic-y += cmpxchg.h
15generic-y += cputime.h 15generic-y += cputime.h
16generic-y += current.h 16generic-y += current.h
17generic-y += device.h 17generic-y += device.h
@@ -25,6 +25,7 @@ generic-y += fcntl.h
25generic-y += ftrace.h 25generic-y += ftrace.h
26generic-y += futex.h 26generic-y += futex.h
27generic-y += hardirq.h 27generic-y += hardirq.h
28generic-y += hash.h
28generic-y += hw_irq.h 29generic-y += hw_irq.h
29generic-y += ioctl.h 30generic-y += ioctl.h
30generic-y += ioctls.h 31generic-y += ioctls.h
@@ -34,6 +35,7 @@ generic-y += kdebug.h
34generic-y += kmap_types.h 35generic-y += kmap_types.h
35generic-y += kvm_para.h 36generic-y += kvm_para.h
36generic-y += local.h 37generic-y += local.h
38generic-y += mcs_spinlock.h
37generic-y += mman.h 39generic-y += mman.h
38generic-y += module.h 40generic-y += module.h
39generic-y += msgbuf.h 41generic-y += msgbuf.h
@@ -41,6 +43,7 @@ generic-y += pci.h
41generic-y += percpu.h 43generic-y += percpu.h
42generic-y += poll.h 44generic-y += poll.h
43generic-y += posix_types.h 45generic-y += posix_types.h
46generic-y += preempt.h
44generic-y += resource.h 47generic-y += resource.h
45generic-y += scatterlist.h 48generic-y += scatterlist.h
46generic-y += sections.h 49generic-y += sections.h
@@ -53,11 +56,11 @@ generic-y += siginfo.h
53generic-y += signal.h 56generic-y += signal.h
54generic-y += socket.h 57generic-y += socket.h
55generic-y += sockios.h 58generic-y += sockios.h
56generic-y += statfs.h
57generic-y += stat.h 59generic-y += stat.h
60generic-y += statfs.h
58generic-y += string.h 61generic-y += string.h
59generic-y += switch_to.h
60generic-y += swab.h 62generic-y += swab.h
63generic-y += switch_to.h
61generic-y += termbits.h 64generic-y += termbits.h
62generic-y += termios.h 65generic-y += termios.h
63generic-y += topology.h 66generic-y += topology.h
@@ -68,5 +71,3 @@ generic-y += user.h
68generic-y += vga.h 71generic-y += vga.h
69generic-y += word-at-a-time.h 72generic-y += word-at-a-time.h
70generic-y += xor.h 73generic-y += xor.h
71generic-y += preempt.h
72generic-y += hash.h
diff --git a/arch/parisc/hpux/fs.c b/arch/parisc/hpux/fs.c
index 88d0962de65a..2bedafea3d94 100644
--- a/arch/parisc/hpux/fs.c
+++ b/arch/parisc/hpux/fs.c
@@ -33,22 +33,9 @@
33 33
34int hpux_execve(struct pt_regs *regs) 34int hpux_execve(struct pt_regs *regs)
35{ 35{
36 int error; 36 return do_execve(getname((const char __user *) regs->gr[26]),
37 struct filename *filename;
38
39 filename = getname((const char __user *) regs->gr[26]);
40 error = PTR_ERR(filename);
41 if (IS_ERR(filename))
42 goto out;
43
44 error = do_execve(filename->name,
45 (const char __user *const __user *) regs->gr[25], 37 (const char __user *const __user *) regs->gr[25],
46 (const char __user *const __user *) regs->gr[24]); 38 (const char __user *const __user *) regs->gr[24]);
47
48 putname(filename);
49
50out:
51 return error;
52} 39}
53 40
54struct hpux_dirent { 41struct hpux_dirent {
diff --git a/arch/parisc/include/asm/Kbuild b/arch/parisc/include/asm/Kbuild
index 752c981bc3c7..ecf25e6678ad 100644
--- a/arch/parisc/include/asm/Kbuild
+++ b/arch/parisc/include/asm/Kbuild
@@ -1,9 +1,29 @@
1 1
2generic-y += auxvec.h
2generic-y += barrier.h 3generic-y += barrier.h
3generic-y += word-at-a-time.h auxvec.h user.h cputime.h emergency-restart.h \ 4generic-y += clkdev.h
4 segment.h topology.h vga.h device.h percpu.h hw_irq.h mutex.h \ 5generic-y += cputime.h
5 div64.h irq_regs.h kdebug.h kvm_para.h local64.h local.h param.h \ 6generic-y += device.h
6 poll.h xor.h clkdev.h exec.h 7generic-y += div64.h
7generic-y += trace_clock.h 8generic-y += emergency-restart.h
8generic-y += preempt.h 9generic-y += exec.h
9generic-y += hash.h 10generic-y += hash.h
11generic-y += hw_irq.h
12generic-y += irq_regs.h
13generic-y += kdebug.h
14generic-y += kvm_para.h
15generic-y += local.h
16generic-y += local64.h
17generic-y += mcs_spinlock.h
18generic-y += mutex.h
19generic-y += param.h
20generic-y += percpu.h
21generic-y += poll.h
22generic-y += preempt.h
23generic-y += segment.h
24generic-y += topology.h
25generic-y += trace_clock.h
26generic-y += user.h
27generic-y += vga.h
28generic-y += word-at-a-time.h
29generic-y += xor.h
diff --git a/arch/parisc/include/asm/page.h b/arch/parisc/include/asm/page.h
index 637fe031aa84..60d5d174dfe4 100644
--- a/arch/parisc/include/asm/page.h
+++ b/arch/parisc/include/asm/page.h
@@ -32,17 +32,6 @@ void copy_page_asm(void *to, void *from);
32void copy_user_page(void *vto, void *vfrom, unsigned long vaddr, 32void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
33 struct page *pg); 33 struct page *pg);
34 34
35/* #define CONFIG_PARISC_TMPALIAS */
36
37#ifdef CONFIG_PARISC_TMPALIAS
38void clear_user_highpage(struct page *page, unsigned long vaddr);
39#define clear_user_highpage clear_user_highpage
40struct vm_area_struct;
41void copy_user_highpage(struct page *to, struct page *from,
42 unsigned long vaddr, struct vm_area_struct *vma);
43#define __HAVE_ARCH_COPY_USER_HIGHPAGE
44#endif
45
46/* 35/*
47 * These are used to make use of C type-checking.. 36 * These are used to make use of C type-checking..
48 */ 37 */
diff --git a/arch/parisc/include/asm/spinlock.h b/arch/parisc/include/asm/spinlock.h
index 3516e0b27044..64f2992e439f 100644
--- a/arch/parisc/include/asm/spinlock.h
+++ b/arch/parisc/include/asm/spinlock.h
@@ -191,8 +191,4 @@ static __inline__ int arch_write_can_lock(arch_rwlock_t *rw)
191#define arch_read_lock_flags(lock, flags) arch_read_lock(lock) 191#define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
192#define arch_write_lock_flags(lock, flags) arch_write_lock(lock) 192#define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
193 193
194#define arch_spin_relax(lock) cpu_relax()
195#define arch_read_relax(lock) cpu_relax()
196#define arch_write_relax(lock) cpu_relax()
197
198#endif /* __ASM_SPINLOCK_H */ 194#endif /* __ASM_SPINLOCK_H */
diff --git a/arch/parisc/include/uapi/asm/unistd.h b/arch/parisc/include/uapi/asm/unistd.h
index 42706794a36f..265ae5190b0a 100644
--- a/arch/parisc/include/uapi/asm/unistd.h
+++ b/arch/parisc/include/uapi/asm/unistd.h
@@ -828,13 +828,13 @@
828#define __NR_finit_module (__NR_Linux + 333) 828#define __NR_finit_module (__NR_Linux + 333)
829#define __NR_sched_setattr (__NR_Linux + 334) 829#define __NR_sched_setattr (__NR_Linux + 334)
830#define __NR_sched_getattr (__NR_Linux + 335) 830#define __NR_sched_getattr (__NR_Linux + 335)
831#define __NR_utimes (__NR_Linux + 336)
831 832
832#define __NR_Linux_syscalls (__NR_sched_getattr + 1) 833#define __NR_Linux_syscalls (__NR_utimes + 1)
833 834
834 835
835#define __IGNORE_select /* newselect */ 836#define __IGNORE_select /* newselect */
836#define __IGNORE_fadvise64 /* fadvise64_64 */ 837#define __IGNORE_fadvise64 /* fadvise64_64 */
837#define __IGNORE_utimes /* utime */
838 838
839 839
840#define HPUX_GATEWAY_ADDR 0xC0000004 840#define HPUX_GATEWAY_ADDR 0xC0000004
diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
index ac87a40502e6..a6ffc775a9f8 100644
--- a/arch/parisc/kernel/cache.c
+++ b/arch/parisc/kernel/cache.c
@@ -581,67 +581,3 @@ flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long
581 __flush_cache_page(vma, vmaddr, PFN_PHYS(pfn)); 581 __flush_cache_page(vma, vmaddr, PFN_PHYS(pfn));
582 } 582 }
583} 583}
584
585#ifdef CONFIG_PARISC_TMPALIAS
586
587void clear_user_highpage(struct page *page, unsigned long vaddr)
588{
589 void *vto;
590 unsigned long flags;
591
592 /* Clear using TMPALIAS region. The page doesn't need to
593 be flushed but the kernel mapping needs to be purged. */
594
595 vto = kmap_atomic(page);
596
597 /* The PA-RISC 2.0 Architecture book states on page F-6:
598 "Before a write-capable translation is enabled, *all*
599 non-equivalently-aliased translations must be removed
600 from the page table and purged from the TLB. (Note
601 that the caches are not required to be flushed at this
602 time.) Before any non-equivalent aliased translation
603 is re-enabled, the virtual address range for the writeable
604 page (the entire page) must be flushed from the cache,
605 and the write-capable translation removed from the page
606 table and purged from the TLB." */
607
608 purge_kernel_dcache_page_asm((unsigned long)vto);
609 purge_tlb_start(flags);
610 pdtlb_kernel(vto);
611 purge_tlb_end(flags);
612 preempt_disable();
613 clear_user_page_asm(vto, vaddr);
614 preempt_enable();
615
616 pagefault_enable(); /* kunmap_atomic(addr, KM_USER0); */
617}
618
619void copy_user_highpage(struct page *to, struct page *from,
620 unsigned long vaddr, struct vm_area_struct *vma)
621{
622 void *vfrom, *vto;
623 unsigned long flags;
624
625 /* Copy using TMPALIAS region. This has the advantage
626 that the `from' page doesn't need to be flushed. However,
627 the `to' page must be flushed in copy_user_page_asm since
628 it can be used to bring in executable code. */
629
630 vfrom = kmap_atomic(from);
631 vto = kmap_atomic(to);
632
633 purge_kernel_dcache_page_asm((unsigned long)vto);
634 purge_tlb_start(flags);
635 pdtlb_kernel(vto);
636 pdtlb_kernel(vfrom);
637 purge_tlb_end(flags);
638 preempt_disable();
639 copy_user_page_asm(vto, vfrom, vaddr);
640 flush_dcache_page_asm(__pa(vto), vaddr);
641 preempt_enable();
642
643 pagefault_enable(); /* kunmap_atomic(addr, KM_USER1); */
644 pagefault_enable(); /* kunmap_atomic(addr, KM_USER0); */
645}
646
647#endif /* CONFIG_PARISC_TMPALIAS */
diff --git a/arch/parisc/kernel/syscall_table.S b/arch/parisc/kernel/syscall_table.S
index 8fa3fbb3e4d3..80e5dd248934 100644
--- a/arch/parisc/kernel/syscall_table.S
+++ b/arch/parisc/kernel/syscall_table.S
@@ -431,6 +431,7 @@
431 ENTRY_SAME(finit_module) 431 ENTRY_SAME(finit_module)
432 ENTRY_SAME(sched_setattr) 432 ENTRY_SAME(sched_setattr)
433 ENTRY_SAME(sched_getattr) /* 335 */ 433 ENTRY_SAME(sched_getattr) /* 335 */
434 ENTRY_COMP(utimes)
434 435
435 /* Nothing yet */ 436 /* Nothing yet */
436 437
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 6c0a955a1b06..3fb1bc432f4f 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -1,7 +1,8 @@
1 1
2generic-y += clkdev.h 2generic-y += clkdev.h
3generic-y += hash.h
4generic-y += mcs_spinlock.h
5generic-y += preempt.h
3generic-y += rwsem.h 6generic-y += rwsem.h
4generic-y += trace_clock.h 7generic-y += trace_clock.h
5generic-y += preempt.h
6generic-y += vtime.h 8generic-y += vtime.h
7generic-y += hash.h
diff --git a/arch/powerpc/include/asm/compat.h b/arch/powerpc/include/asm/compat.h
index 84fdf6857c31..a613d2c82fd9 100644
--- a/arch/powerpc/include/asm/compat.h
+++ b/arch/powerpc/include/asm/compat.h
@@ -200,10 +200,11 @@ static inline void __user *arch_compat_alloc_user_space(long len)
200 200
201 /* 201 /*
202 * We can't access below the stack pointer in the 32bit ABI and 202 * We can't access below the stack pointer in the 32bit ABI and
203 * can access 288 bytes in the 64bit ABI 203 * can access 288 bytes in the 64bit big-endian ABI,
204 * or 512 bytes with the new ELFv2 little-endian ABI.
204 */ 205 */
205 if (!is_32bit_task()) 206 if (!is_32bit_task())
206 usp -= 288; 207 usp -= USER_REDZONE_SIZE;
207 208
208 return (void __user *) (usp - len); 209 return (void __user *) (usp - len);
209} 210}
diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h
index e27e9ad6818e..150866b2a3fe 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -134,6 +134,7 @@ static inline int dma_supported(struct device *dev, u64 mask)
134} 134}
135 135
136extern int dma_set_mask(struct device *dev, u64 dma_mask); 136extern int dma_set_mask(struct device *dev, u64 dma_mask);
137extern int __dma_set_mask(struct device *dev, u64 dma_mask);
137 138
138#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) 139#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
139 140
diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
index 9e39ceb1d19f..d4dd41fb951b 100644
--- a/arch/powerpc/include/asm/eeh.h
+++ b/arch/powerpc/include/asm/eeh.h
@@ -172,10 +172,20 @@ struct eeh_ops {
172}; 172};
173 173
174extern struct eeh_ops *eeh_ops; 174extern struct eeh_ops *eeh_ops;
175extern int eeh_subsystem_enabled; 175extern bool eeh_subsystem_enabled;
176extern raw_spinlock_t confirm_error_lock; 176extern raw_spinlock_t confirm_error_lock;
177extern int eeh_probe_mode; 177extern int eeh_probe_mode;
178 178
179static inline bool eeh_enabled(void)
180{
181 return eeh_subsystem_enabled;
182}
183
184static inline void eeh_set_enable(bool mode)
185{
186 eeh_subsystem_enabled = mode;
187}
188
179#define EEH_PROBE_MODE_DEV (1<<0) /* From PCI device */ 189#define EEH_PROBE_MODE_DEV (1<<0) /* From PCI device */
180#define EEH_PROBE_MODE_DEVTREE (1<<1) /* From device tree */ 190#define EEH_PROBE_MODE_DEVTREE (1<<1) /* From device tree */
181 191
@@ -246,7 +256,7 @@ void eeh_remove_device(struct pci_dev *);
246 * If this macro yields TRUE, the caller relays to eeh_check_failure() 256 * If this macro yields TRUE, the caller relays to eeh_check_failure()
247 * which does further tests out of line. 257 * which does further tests out of line.
248 */ 258 */
249#define EEH_POSSIBLE_ERROR(val, type) ((val) == (type)~0 && eeh_subsystem_enabled) 259#define EEH_POSSIBLE_ERROR(val, type) ((val) == (type)~0 && eeh_enabled())
250 260
251/* 261/*
252 * Reads from a device which has been isolated by EEH will return 262 * Reads from a device which has been isolated by EEH will return
@@ -257,6 +267,13 @@ void eeh_remove_device(struct pci_dev *);
257 267
258#else /* !CONFIG_EEH */ 268#else /* !CONFIG_EEH */
259 269
270static inline bool eeh_enabled(void)
271{
272 return false;
273}
274
275static inline void eeh_set_enable(bool mode) { }
276
260static inline int eeh_init(void) 277static inline int eeh_init(void)
261{ 278{
262 return 0; 279 return 0;
diff --git a/arch/powerpc/include/asm/hugetlb.h b/arch/powerpc/include/asm/hugetlb.h
index d750336b171d..623f2971ce0e 100644
--- a/arch/powerpc/include/asm/hugetlb.h
+++ b/arch/powerpc/include/asm/hugetlb.h
@@ -127,7 +127,7 @@ static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
127 unsigned long addr, pte_t *ptep) 127 unsigned long addr, pte_t *ptep)
128{ 128{
129#ifdef CONFIG_PPC64 129#ifdef CONFIG_PPC64
130 return __pte(pte_update(mm, addr, ptep, ~0UL, 1)); 130 return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));
131#else 131#else
132 return __pte(pte_update(ptep, ~0UL, 0)); 132 return __pte(pte_update(ptep, ~0UL, 0));
133#endif 133#endif
diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
index f7a8036579b5..42632c7a2a4e 100644
--- a/arch/powerpc/include/asm/iommu.h
+++ b/arch/powerpc/include/asm/iommu.h
@@ -77,6 +77,7 @@ struct iommu_table {
77#ifdef CONFIG_IOMMU_API 77#ifdef CONFIG_IOMMU_API
78 struct iommu_group *it_group; 78 struct iommu_group *it_group;
79#endif 79#endif
80 void (*set_bypass)(struct iommu_table *tbl, bool enable);
80}; 81};
81 82
82/* Pure 2^n version of get_order */ 83/* Pure 2^n version of get_order */
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 40157e2ca691..ed82142a3251 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -816,8 +816,8 @@ int64_t opal_pci_next_error(uint64_t phb_id, uint64_t *first_frozen_pe,
816int64_t opal_pci_poll(uint64_t phb_id); 816int64_t opal_pci_poll(uint64_t phb_id);
817int64_t opal_return_cpu(void); 817int64_t opal_return_cpu(void);
818 818
819int64_t opal_xscom_read(uint32_t gcid, uint32_t pcb_addr, __be64 *val); 819int64_t opal_xscom_read(uint32_t gcid, uint64_t pcb_addr, __be64 *val);
820int64_t opal_xscom_write(uint32_t gcid, uint32_t pcb_addr, uint64_t val); 820int64_t opal_xscom_write(uint32_t gcid, uint64_t pcb_addr, uint64_t val);
821 821
822int64_t opal_lpc_write(uint32_t chip_id, enum OpalLPCAddressType addr_type, 822int64_t opal_lpc_write(uint32_t chip_id, enum OpalLPCAddressType addr_type,
823 uint32_t addr, uint32_t data, uint32_t sz); 823 uint32_t addr, uint32_t data, uint32_t sz);
diff --git a/arch/powerpc/include/asm/pgtable-ppc64.h b/arch/powerpc/include/asm/pgtable-ppc64.h
index bc141c950b1e..eb9261024f51 100644
--- a/arch/powerpc/include/asm/pgtable-ppc64.h
+++ b/arch/powerpc/include/asm/pgtable-ppc64.h
@@ -195,6 +195,7 @@ extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
195static inline unsigned long pte_update(struct mm_struct *mm, 195static inline unsigned long pte_update(struct mm_struct *mm,
196 unsigned long addr, 196 unsigned long addr,
197 pte_t *ptep, unsigned long clr, 197 pte_t *ptep, unsigned long clr,
198 unsigned long set,
198 int huge) 199 int huge)
199{ 200{
200#ifdef PTE_ATOMIC_UPDATES 201#ifdef PTE_ATOMIC_UPDATES
@@ -205,14 +206,15 @@ static inline unsigned long pte_update(struct mm_struct *mm,
205 andi. %1,%0,%6\n\ 206 andi. %1,%0,%6\n\
206 bne- 1b \n\ 207 bne- 1b \n\
207 andc %1,%0,%4 \n\ 208 andc %1,%0,%4 \n\
209 or %1,%1,%7\n\
208 stdcx. %1,0,%3 \n\ 210 stdcx. %1,0,%3 \n\
209 bne- 1b" 211 bne- 1b"
210 : "=&r" (old), "=&r" (tmp), "=m" (*ptep) 212 : "=&r" (old), "=&r" (tmp), "=m" (*ptep)
211 : "r" (ptep), "r" (clr), "m" (*ptep), "i" (_PAGE_BUSY) 213 : "r" (ptep), "r" (clr), "m" (*ptep), "i" (_PAGE_BUSY), "r" (set)
212 : "cc" ); 214 : "cc" );
213#else 215#else
214 unsigned long old = pte_val(*ptep); 216 unsigned long old = pte_val(*ptep);
215 *ptep = __pte(old & ~clr); 217 *ptep = __pte((old & ~clr) | set);
216#endif 218#endif
217 /* huge pages use the old page table lock */ 219 /* huge pages use the old page table lock */
218 if (!huge) 220 if (!huge)
@@ -231,9 +233,9 @@ static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
231{ 233{
232 unsigned long old; 234 unsigned long old;
233 235
234 if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0) 236 if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
235 return 0; 237 return 0;
236 old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0); 238 old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
237 return (old & _PAGE_ACCESSED) != 0; 239 return (old & _PAGE_ACCESSED) != 0;
238} 240}
239#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 241#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
@@ -252,7 +254,7 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
252 if ((pte_val(*ptep) & _PAGE_RW) == 0) 254 if ((pte_val(*ptep) & _PAGE_RW) == 0)
253 return; 255 return;
254 256
255 pte_update(mm, addr, ptep, _PAGE_RW, 0); 257 pte_update(mm, addr, ptep, _PAGE_RW, 0, 0);
256} 258}
257 259
258static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, 260static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
@@ -261,7 +263,7 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
261 if ((pte_val(*ptep) & _PAGE_RW) == 0) 263 if ((pte_val(*ptep) & _PAGE_RW) == 0)
262 return; 264 return;
263 265
264 pte_update(mm, addr, ptep, _PAGE_RW, 1); 266 pte_update(mm, addr, ptep, _PAGE_RW, 0, 1);
265} 267}
266 268
267/* 269/*
@@ -284,14 +286,14 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
284static inline pte_t ptep_get_and_clear(struct mm_struct *mm, 286static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
285 unsigned long addr, pte_t *ptep) 287 unsigned long addr, pte_t *ptep)
286{ 288{
287 unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0); 289 unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0, 0);
288 return __pte(old); 290 return __pte(old);
289} 291}
290 292
291static inline void pte_clear(struct mm_struct *mm, unsigned long addr, 293static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
292 pte_t * ptep) 294 pte_t * ptep)
293{ 295{
294 pte_update(mm, addr, ptep, ~0UL, 0); 296 pte_update(mm, addr, ptep, ~0UL, 0, 0);
295} 297}
296 298
297 299
@@ -506,7 +508,9 @@ extern int pmdp_set_access_flags(struct vm_area_struct *vma,
506 508
507extern unsigned long pmd_hugepage_update(struct mm_struct *mm, 509extern unsigned long pmd_hugepage_update(struct mm_struct *mm,
508 unsigned long addr, 510 unsigned long addr,
509 pmd_t *pmdp, unsigned long clr); 511 pmd_t *pmdp,
512 unsigned long clr,
513 unsigned long set);
510 514
511static inline int __pmdp_test_and_clear_young(struct mm_struct *mm, 515static inline int __pmdp_test_and_clear_young(struct mm_struct *mm,
512 unsigned long addr, pmd_t *pmdp) 516 unsigned long addr, pmd_t *pmdp)
@@ -515,7 +519,7 @@ static inline int __pmdp_test_and_clear_young(struct mm_struct *mm,
515 519
516 if ((pmd_val(*pmdp) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0) 520 if ((pmd_val(*pmdp) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
517 return 0; 521 return 0;
518 old = pmd_hugepage_update(mm, addr, pmdp, _PAGE_ACCESSED); 522 old = pmd_hugepage_update(mm, addr, pmdp, _PAGE_ACCESSED, 0);
519 return ((old & _PAGE_ACCESSED) != 0); 523 return ((old & _PAGE_ACCESSED) != 0);
520} 524}
521 525
@@ -542,7 +546,7 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm, unsigned long addr,
542 if ((pmd_val(*pmdp) & _PAGE_RW) == 0) 546 if ((pmd_val(*pmdp) & _PAGE_RW) == 0)
543 return; 547 return;
544 548
545 pmd_hugepage_update(mm, addr, pmdp, _PAGE_RW); 549 pmd_hugepage_update(mm, addr, pmdp, _PAGE_RW, 0);
546} 550}
547 551
548#define __HAVE_ARCH_PMDP_SPLITTING_FLUSH 552#define __HAVE_ARCH_PMDP_SPLITTING_FLUSH
diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
index f83b6f3e1b39..3ebb188c3ff5 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -75,12 +75,34 @@ static inline pte_t pte_mknuma(pte_t pte)
75 return pte; 75 return pte;
76} 76}
77 77
78#define ptep_set_numa ptep_set_numa
79static inline void ptep_set_numa(struct mm_struct *mm, unsigned long addr,
80 pte_t *ptep)
81{
82 if ((pte_val(*ptep) & _PAGE_PRESENT) == 0)
83 VM_BUG_ON(1);
84
85 pte_update(mm, addr, ptep, _PAGE_PRESENT, _PAGE_NUMA, 0);
86 return;
87}
88
78#define pmd_numa pmd_numa 89#define pmd_numa pmd_numa
79static inline int pmd_numa(pmd_t pmd) 90static inline int pmd_numa(pmd_t pmd)
80{ 91{
81 return pte_numa(pmd_pte(pmd)); 92 return pte_numa(pmd_pte(pmd));
82} 93}
83 94
95#define pmdp_set_numa pmdp_set_numa
96static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
97 pmd_t *pmdp)
98{
99 if ((pmd_val(*pmdp) & _PAGE_PRESENT) == 0)
100 VM_BUG_ON(1);
101
102 pmd_hugepage_update(mm, addr, pmdp, _PAGE_PRESENT, _PAGE_NUMA);
103 return;
104}
105
84#define pmd_mknonnuma pmd_mknonnuma 106#define pmd_mknonnuma pmd_mknonnuma
85static inline pmd_t pmd_mknonnuma(pmd_t pmd) 107static inline pmd_t pmd_mknonnuma(pmd_t pmd)
86{ 108{
diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
index becc08e6a65c..279b80f3bb29 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -28,11 +28,23 @@
28 28
29#ifdef __powerpc64__ 29#ifdef __powerpc64__
30 30
31/*
32 * Size of redzone that userspace is allowed to use below the stack
33 * pointer. This is 288 in the 64-bit big-endian ELF ABI, and 512 in
34 * the new ELFv2 little-endian ABI, so we allow the larger amount.
35 *
36 * For kernel code we allow a 288-byte redzone, in order to conserve
37 * kernel stack space; gcc currently only uses 288 bytes, and will
38 * hopefully allow explicit control of the redzone size in future.
39 */
40#define USER_REDZONE_SIZE 512
41#define KERNEL_REDZONE_SIZE 288
42
31#define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */ 43#define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */
32#define STACK_FRAME_LR_SAVE 2 /* Location of LR in stack frame */ 44#define STACK_FRAME_LR_SAVE 2 /* Location of LR in stack frame */
33#define STACK_FRAME_REGS_MARKER ASM_CONST(0x7265677368657265) 45#define STACK_FRAME_REGS_MARKER ASM_CONST(0x7265677368657265)
34#define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + \ 46#define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + \
35 STACK_FRAME_OVERHEAD + 288) 47 STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
36#define STACK_FRAME_MARKER 12 48#define STACK_FRAME_MARKER 12
37 49
38/* Size of dummy stack frame allocated when calling signal handler. */ 50/* Size of dummy stack frame allocated when calling signal handler. */
@@ -41,6 +53,8 @@
41 53
42#else /* __powerpc64__ */ 54#else /* __powerpc64__ */
43 55
56#define USER_REDZONE_SIZE 0
57#define KERNEL_REDZONE_SIZE 0
44#define STACK_FRAME_OVERHEAD 16 /* size of minimum stack frame */ 58#define STACK_FRAME_OVERHEAD 16 /* size of minimum stack frame */
45#define STACK_FRAME_LR_SAVE 1 /* Location of LR in stack frame */ 59#define STACK_FRAME_LR_SAVE 1 /* Location of LR in stack frame */
46#define STACK_FRAME_REGS_MARKER ASM_CONST(0x72656773) 60#define STACK_FRAME_REGS_MARKER ASM_CONST(0x72656773)
diff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm/sections.h
index 4ee06fe15de4..d0e784e0ff48 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -8,6 +8,7 @@
8 8
9#ifdef __powerpc64__ 9#ifdef __powerpc64__
10 10
11extern char __start_interrupts[];
11extern char __end_interrupts[]; 12extern char __end_interrupts[];
12 13
13extern char __prom_init_toc_start[]; 14extern char __prom_init_toc_start[];
@@ -21,6 +22,17 @@ static inline int in_kernel_text(unsigned long addr)
21 return 0; 22 return 0;
22} 23}
23 24
25static inline int overlaps_interrupt_vector_text(unsigned long start,
26 unsigned long end)
27{
28 unsigned long real_start, real_end;
29 real_start = __start_interrupts - _stext;
30 real_end = __end_interrupts - _stext;
31
32 return start < (unsigned long)__va(real_end) &&
33 (unsigned long)__va(real_start) < end;
34}
35
24static inline int overlaps_kernel_text(unsigned long start, unsigned long end) 36static inline int overlaps_kernel_text(unsigned long start, unsigned long end)
25{ 37{
26 return start < (unsigned long)__init_end && 38 return start < (unsigned long)__init_end &&
diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
index d0b5fca6b077..c9202151079f 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -99,7 +99,6 @@ static inline int prrn_is_enabled(void)
99 99
100#ifdef CONFIG_SMP 100#ifdef CONFIG_SMP
101#include <asm/cputable.h> 101#include <asm/cputable.h>
102#define smt_capable() (cpu_has_feature(CPU_FTR_SMT))
103 102
104#ifdef CONFIG_PPC64 103#ifdef CONFIG_PPC64
105#include <asm/smp.h> 104#include <asm/smp.h>
diff --git a/arch/powerpc/include/asm/vdso.h b/arch/powerpc/include/asm/vdso.h
index 0d9cecddf8a4..c53f5f6d1761 100644
--- a/arch/powerpc/include/asm/vdso.h
+++ b/arch/powerpc/include/asm/vdso.h
@@ -4,11 +4,11 @@
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5 5
6/* Default link addresses for the vDSOs */ 6/* Default link addresses for the vDSOs */
7#define VDSO32_LBASE 0x100000 7#define VDSO32_LBASE 0x0
8#define VDSO64_LBASE 0x100000 8#define VDSO64_LBASE 0x0
9 9
10/* Default map addresses for 32bit vDSO */ 10/* Default map addresses for 32bit vDSO */
11#define VDSO32_MBASE VDSO32_LBASE 11#define VDSO32_MBASE 0x100000
12 12
13#define VDSO_VERSION_STRING LINUX_2.6.15 13#define VDSO_VERSION_STRING LINUX_2.6.15
14 14
diff --git a/arch/powerpc/kernel/crash_dump.c b/arch/powerpc/kernel/crash_dump.c
index 11c1d069d920..7a13f378ca2c 100644
--- a/arch/powerpc/kernel/crash_dump.c
+++ b/arch/powerpc/kernel/crash_dump.c
@@ -98,17 +98,19 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
98 size_t csize, unsigned long offset, int userbuf) 98 size_t csize, unsigned long offset, int userbuf)
99{ 99{
100 void *vaddr; 100 void *vaddr;
101 phys_addr_t paddr;
101 102
102 if (!csize) 103 if (!csize)
103 return 0; 104 return 0;
104 105
105 csize = min_t(size_t, csize, PAGE_SIZE); 106 csize = min_t(size_t, csize, PAGE_SIZE);
107 paddr = pfn << PAGE_SHIFT;
106 108
107 if ((min_low_pfn < pfn) && (pfn < max_pfn)) { 109 if (memblock_is_region_memory(paddr, csize)) {
108 vaddr = __va(pfn << PAGE_SHIFT); 110 vaddr = __va(paddr);
109 csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf); 111 csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf);
110 } else { 112 } else {
111 vaddr = __ioremap(pfn << PAGE_SHIFT, PAGE_SIZE, 0); 113 vaddr = __ioremap(paddr, PAGE_SIZE, 0);
112 csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf); 114 csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf);
113 iounmap(vaddr); 115 iounmap(vaddr);
114 } 116 }
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 8032b97ccdcb..ee78f6e49d64 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -191,12 +191,10 @@ EXPORT_SYMBOL(dma_direct_ops);
191 191
192#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 192#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
193 193
194int dma_set_mask(struct device *dev, u64 dma_mask) 194int __dma_set_mask(struct device *dev, u64 dma_mask)
195{ 195{
196 struct dma_map_ops *dma_ops = get_dma_ops(dev); 196 struct dma_map_ops *dma_ops = get_dma_ops(dev);
197 197
198 if (ppc_md.dma_set_mask)
199 return ppc_md.dma_set_mask(dev, dma_mask);
200 if ((dma_ops != NULL) && (dma_ops->set_dma_mask != NULL)) 198 if ((dma_ops != NULL) && (dma_ops->set_dma_mask != NULL))
201 return dma_ops->set_dma_mask(dev, dma_mask); 199 return dma_ops->set_dma_mask(dev, dma_mask);
202 if (!dev->dma_mask || !dma_supported(dev, dma_mask)) 200 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
@@ -204,6 +202,12 @@ int dma_set_mask(struct device *dev, u64 dma_mask)
204 *dev->dma_mask = dma_mask; 202 *dev->dma_mask = dma_mask;
205 return 0; 203 return 0;
206} 204}
205int dma_set_mask(struct device *dev, u64 dma_mask)
206{
207 if (ppc_md.dma_set_mask)
208 return ppc_md.dma_set_mask(dev, dma_mask);
209 return __dma_set_mask(dev, dma_mask);
210}
207EXPORT_SYMBOL(dma_set_mask); 211EXPORT_SYMBOL(dma_set_mask);
208 212
209u64 dma_get_required_mask(struct device *dev) 213u64 dma_get_required_mask(struct device *dev)
diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
index 148db72a8c43..e7b76a6bf150 100644
--- a/arch/powerpc/kernel/eeh.c
+++ b/arch/powerpc/kernel/eeh.c
@@ -28,6 +28,7 @@
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/proc_fs.h> 29#include <linux/proc_fs.h>
30#include <linux/rbtree.h> 30#include <linux/rbtree.h>
31#include <linux/reboot.h>
31#include <linux/seq_file.h> 32#include <linux/seq_file.h>
32#include <linux/spinlock.h> 33#include <linux/spinlock.h>
33#include <linux/export.h> 34#include <linux/export.h>
@@ -89,7 +90,7 @@
89/* Platform dependent EEH operations */ 90/* Platform dependent EEH operations */
90struct eeh_ops *eeh_ops = NULL; 91struct eeh_ops *eeh_ops = NULL;
91 92
92int eeh_subsystem_enabled; 93bool eeh_subsystem_enabled = false;
93EXPORT_SYMBOL(eeh_subsystem_enabled); 94EXPORT_SYMBOL(eeh_subsystem_enabled);
94 95
95/* 96/*
@@ -364,7 +365,7 @@ int eeh_dev_check_failure(struct eeh_dev *edev)
364 365
365 eeh_stats.total_mmio_ffs++; 366 eeh_stats.total_mmio_ffs++;
366 367
367 if (!eeh_subsystem_enabled) 368 if (!eeh_enabled())
368 return 0; 369 return 0;
369 370
370 if (!edev) { 371 if (!edev) {
@@ -747,6 +748,17 @@ int __exit eeh_ops_unregister(const char *name)
747 return -EEXIST; 748 return -EEXIST;
748} 749}
749 750
751static int eeh_reboot_notifier(struct notifier_block *nb,
752 unsigned long action, void *unused)
753{
754 eeh_set_enable(false);
755 return NOTIFY_DONE;
756}
757
758static struct notifier_block eeh_reboot_nb = {
759 .notifier_call = eeh_reboot_notifier,
760};
761
750/** 762/**
751 * eeh_init - EEH initialization 763 * eeh_init - EEH initialization
752 * 764 *
@@ -778,6 +790,14 @@ int eeh_init(void)
778 if (machine_is(powernv) && cnt++ <= 0) 790 if (machine_is(powernv) && cnt++ <= 0)
779 return ret; 791 return ret;
780 792
793 /* Register reboot notifier */
794 ret = register_reboot_notifier(&eeh_reboot_nb);
795 if (ret) {
796 pr_warn("%s: Failed to register notifier (%d)\n",
797 __func__, ret);
798 return ret;
799 }
800
781 /* call platform initialization function */ 801 /* call platform initialization function */
782 if (!eeh_ops) { 802 if (!eeh_ops) {
783 pr_warning("%s: Platform EEH operation not found\n", 803 pr_warning("%s: Platform EEH operation not found\n",
@@ -822,7 +842,7 @@ int eeh_init(void)
822 return ret; 842 return ret;
823 } 843 }
824 844
825 if (eeh_subsystem_enabled) 845 if (eeh_enabled())
826 pr_info("EEH: PCI Enhanced I/O Error Handling Enabled\n"); 846 pr_info("EEH: PCI Enhanced I/O Error Handling Enabled\n");
827 else 847 else
828 pr_warning("EEH: No capable adapters found\n"); 848 pr_warning("EEH: No capable adapters found\n");
@@ -897,7 +917,7 @@ void eeh_add_device_late(struct pci_dev *dev)
897 struct device_node *dn; 917 struct device_node *dn;
898 struct eeh_dev *edev; 918 struct eeh_dev *edev;
899 919
900 if (!dev || !eeh_subsystem_enabled) 920 if (!dev || !eeh_enabled())
901 return; 921 return;
902 922
903 pr_debug("EEH: Adding device %s\n", pci_name(dev)); 923 pr_debug("EEH: Adding device %s\n", pci_name(dev));
@@ -1005,7 +1025,7 @@ void eeh_remove_device(struct pci_dev *dev)
1005{ 1025{
1006 struct eeh_dev *edev; 1026 struct eeh_dev *edev;
1007 1027
1008 if (!dev || !eeh_subsystem_enabled) 1028 if (!dev || !eeh_enabled())
1009 return; 1029 return;
1010 edev = pci_dev_to_eeh_dev(dev); 1030 edev = pci_dev_to_eeh_dev(dev);
1011 1031
@@ -1045,7 +1065,7 @@ void eeh_remove_device(struct pci_dev *dev)
1045 1065
1046static int proc_eeh_show(struct seq_file *m, void *v) 1066static int proc_eeh_show(struct seq_file *m, void *v)
1047{ 1067{
1048 if (0 == eeh_subsystem_enabled) { 1068 if (!eeh_enabled()) {
1049 seq_printf(m, "EEH Subsystem is globally disabled\n"); 1069 seq_printf(m, "EEH Subsystem is globally disabled\n");
1050 seq_printf(m, "eeh_total_mmio_ffs=%llu\n", eeh_stats.total_mmio_ffs); 1070 seq_printf(m, "eeh_total_mmio_ffs=%llu\n", eeh_stats.total_mmio_ffs);
1051 } else { 1071 } else {
diff --git a/arch/powerpc/kernel/eeh_driver.c b/arch/powerpc/kernel/eeh_driver.c
index 7bb30dca4e19..fdc679d309ec 100644
--- a/arch/powerpc/kernel/eeh_driver.c
+++ b/arch/powerpc/kernel/eeh_driver.c
@@ -362,9 +362,13 @@ static void *eeh_rmv_device(void *data, void *userdata)
362 */ 362 */
363 if (!dev || (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)) 363 if (!dev || (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE))
364 return NULL; 364 return NULL;
365
365 driver = eeh_pcid_get(dev); 366 driver = eeh_pcid_get(dev);
366 if (driver && driver->err_handler) 367 if (driver) {
367 return NULL; 368 eeh_pcid_put(dev);
369 if (driver->err_handler)
370 return NULL;
371 }
368 372
369 /* Remove it from PCI subsystem */ 373 /* Remove it from PCI subsystem */
370 pr_debug("EEH: Removing %s without EEH sensitive driver\n", 374 pr_debug("EEH: Removing %s without EEH sensitive driver\n",
diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index 9b27b293a922..b0ded97ee4e1 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -74,6 +74,7 @@ ftrace_modify_code(unsigned long ip, unsigned int old, unsigned int new)
74 */ 74 */
75static int test_24bit_addr(unsigned long ip, unsigned long addr) 75static int test_24bit_addr(unsigned long ip, unsigned long addr)
76{ 76{
77 addr = ppc_function_entry((void *)addr);
77 78
78 /* use the create_branch to verify that this offset can be branched */ 79 /* use the create_branch to verify that this offset can be branched */
79 return create_branch((unsigned int *)ip, addr, 0); 80 return create_branch((unsigned int *)ip, addr, 0);
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index d773dd440a45..88e3ec6e1d96 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -1088,6 +1088,14 @@ int iommu_take_ownership(struct iommu_table *tbl)
1088 memset(tbl->it_map, 0xff, sz); 1088 memset(tbl->it_map, 0xff, sz);
1089 iommu_clear_tces_and_put_pages(tbl, tbl->it_offset, tbl->it_size); 1089 iommu_clear_tces_and_put_pages(tbl, tbl->it_offset, tbl->it_size);
1090 1090
1091 /*
1092 * Disable iommu bypass, otherwise the user can DMA to all of
1093 * our physical memory via the bypass window instead of just
1094 * the pages that has been explicitly mapped into the iommu
1095 */
1096 if (tbl->set_bypass)
1097 tbl->set_bypass(tbl, false);
1098
1091 return 0; 1099 return 0;
1092} 1100}
1093EXPORT_SYMBOL_GPL(iommu_take_ownership); 1101EXPORT_SYMBOL_GPL(iommu_take_ownership);
@@ -1102,6 +1110,10 @@ void iommu_release_ownership(struct iommu_table *tbl)
1102 /* Restore bit#0 set by iommu_init_table() */ 1110 /* Restore bit#0 set by iommu_init_table() */
1103 if (tbl->it_offset == 0) 1111 if (tbl->it_offset == 0)
1104 set_bit(0, tbl->it_map); 1112 set_bit(0, tbl->it_map);
1113
1114 /* The kernel owns the device now, we can restore the iommu bypass */
1115 if (tbl->set_bypass)
1116 tbl->set_bypass(tbl, true);
1105} 1117}
1106EXPORT_SYMBOL_GPL(iommu_release_ownership); 1118EXPORT_SYMBOL_GPL(iommu_release_ownership);
1107 1119
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index 9729b23bfb0a..1d0848bba049 100644
--- a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ -559,8 +559,13 @@ void exc_lvl_ctx_init(void)
559#ifdef CONFIG_PPC64 559#ifdef CONFIG_PPC64
560 cpu_nr = i; 560 cpu_nr = i;
561#else 561#else
562#ifdef CONFIG_SMP
562 cpu_nr = get_hard_smp_processor_id(i); 563 cpu_nr = get_hard_smp_processor_id(i);
564#else
565 cpu_nr = 0;
563#endif 566#endif
567#endif
568
564 memset((void *)critirq_ctx[cpu_nr], 0, THREAD_SIZE); 569 memset((void *)critirq_ctx[cpu_nr], 0, THREAD_SIZE);
565 tp = critirq_ctx[cpu_nr]; 570 tp = critirq_ctx[cpu_nr];
566 tp->cpu = cpu_nr; 571 tp->cpu = cpu_nr;
diff --git a/arch/powerpc/kernel/machine_kexec.c b/arch/powerpc/kernel/machine_kexec.c
index 75d4f7340da8..015ae55c1868 100644
--- a/arch/powerpc/kernel/machine_kexec.c
+++ b/arch/powerpc/kernel/machine_kexec.c
@@ -196,7 +196,9 @@ int overlaps_crashkernel(unsigned long start, unsigned long size)
196 196
197/* Values we need to export to the second kernel via the device tree. */ 197/* Values we need to export to the second kernel via the device tree. */
198static phys_addr_t kernel_end; 198static phys_addr_t kernel_end;
199static phys_addr_t crashk_base;
199static phys_addr_t crashk_size; 200static phys_addr_t crashk_size;
201static unsigned long long mem_limit;
200 202
201static struct property kernel_end_prop = { 203static struct property kernel_end_prop = {
202 .name = "linux,kernel-end", 204 .name = "linux,kernel-end",
@@ -207,7 +209,7 @@ static struct property kernel_end_prop = {
207static struct property crashk_base_prop = { 209static struct property crashk_base_prop = {
208 .name = "linux,crashkernel-base", 210 .name = "linux,crashkernel-base",
209 .length = sizeof(phys_addr_t), 211 .length = sizeof(phys_addr_t),
210 .value = &crashk_res.start, 212 .value = &crashk_base
211}; 213};
212 214
213static struct property crashk_size_prop = { 215static struct property crashk_size_prop = {
@@ -219,9 +221,11 @@ static struct property crashk_size_prop = {
219static struct property memory_limit_prop = { 221static struct property memory_limit_prop = {
220 .name = "linux,memory-limit", 222 .name = "linux,memory-limit",
221 .length = sizeof(unsigned long long), 223 .length = sizeof(unsigned long long),
222 .value = &memory_limit, 224 .value = &mem_limit,
223}; 225};
224 226
227#define cpu_to_be_ulong __PASTE(cpu_to_be, BITS_PER_LONG)
228
225static void __init export_crashk_values(struct device_node *node) 229static void __init export_crashk_values(struct device_node *node)
226{ 230{
227 struct property *prop; 231 struct property *prop;
@@ -237,8 +241,9 @@ static void __init export_crashk_values(struct device_node *node)
237 of_remove_property(node, prop); 241 of_remove_property(node, prop);
238 242
239 if (crashk_res.start != 0) { 243 if (crashk_res.start != 0) {
244 crashk_base = cpu_to_be_ulong(crashk_res.start),
240 of_add_property(node, &crashk_base_prop); 245 of_add_property(node, &crashk_base_prop);
241 crashk_size = resource_size(&crashk_res); 246 crashk_size = cpu_to_be_ulong(resource_size(&crashk_res));
242 of_add_property(node, &crashk_size_prop); 247 of_add_property(node, &crashk_size_prop);
243 } 248 }
244 249
@@ -246,6 +251,7 @@ static void __init export_crashk_values(struct device_node *node)
246 * memory_limit is required by the kexec-tools to limit the 251 * memory_limit is required by the kexec-tools to limit the
247 * crash regions to the actual memory used. 252 * crash regions to the actual memory used.
248 */ 253 */
254 mem_limit = cpu_to_be_ulong(memory_limit);
249 of_update_property(node, &memory_limit_prop); 255 of_update_property(node, &memory_limit_prop);
250} 256}
251 257
@@ -264,7 +270,7 @@ static int __init kexec_setup(void)
264 of_remove_property(node, prop); 270 of_remove_property(node, prop);
265 271
266 /* information needed by userspace when using default_machine_kexec */ 272 /* information needed by userspace when using default_machine_kexec */
267 kernel_end = __pa(_end); 273 kernel_end = cpu_to_be_ulong(__pa(_end));
268 of_add_property(node, &kernel_end_prop); 274 of_add_property(node, &kernel_end_prop);
269 275
270 export_crashk_values(node); 276 export_crashk_values(node);
diff --git a/arch/powerpc/kernel/machine_kexec_64.c b/arch/powerpc/kernel/machine_kexec_64.c
index be4e6d648f60..59d229a2a3e0 100644
--- a/arch/powerpc/kernel/machine_kexec_64.c
+++ b/arch/powerpc/kernel/machine_kexec_64.c
@@ -369,6 +369,7 @@ void default_machine_kexec(struct kimage *image)
369 369
370/* Values we need to export to the second kernel via the device tree. */ 370/* Values we need to export to the second kernel via the device tree. */
371static unsigned long htab_base; 371static unsigned long htab_base;
372static unsigned long htab_size;
372 373
373static struct property htab_base_prop = { 374static struct property htab_base_prop = {
374 .name = "linux,htab-base", 375 .name = "linux,htab-base",
@@ -379,7 +380,7 @@ static struct property htab_base_prop = {
379static struct property htab_size_prop = { 380static struct property htab_size_prop = {
380 .name = "linux,htab-size", 381 .name = "linux,htab-size",
381 .length = sizeof(unsigned long), 382 .length = sizeof(unsigned long),
382 .value = &htab_size_bytes, 383 .value = &htab_size,
383}; 384};
384 385
385static int __init export_htab_values(void) 386static int __init export_htab_values(void)
@@ -403,8 +404,9 @@ static int __init export_htab_values(void)
403 if (prop) 404 if (prop)
404 of_remove_property(node, prop); 405 of_remove_property(node, prop);
405 406
406 htab_base = __pa(htab_address); 407 htab_base = cpu_to_be64(__pa(htab_address));
407 of_add_property(node, &htab_base_prop); 408 of_add_property(node, &htab_base_prop);
409 htab_size = cpu_to_be64(htab_size_bytes);
408 of_add_property(node, &htab_size_prop); 410 of_add_property(node, &htab_size_prop);
409 411
410 of_node_put(node); 412 of_node_put(node);
diff --git a/arch/powerpc/kernel/misc_32.S b/arch/powerpc/kernel/misc_32.S
index 879f09620f83..7c6bb4b17b49 100644
--- a/arch/powerpc/kernel/misc_32.S
+++ b/arch/powerpc/kernel/misc_32.S
@@ -57,11 +57,14 @@ _GLOBAL(call_do_softirq)
57 mtlr r0 57 mtlr r0
58 blr 58 blr
59 59
60/*
61 * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp);
62 */
60_GLOBAL(call_do_irq) 63_GLOBAL(call_do_irq)
61 mflr r0 64 mflr r0
62 stw r0,4(r1) 65 stw r0,4(r1)
63 lwz r10,THREAD+KSP_LIMIT(r2) 66 lwz r10,THREAD+KSP_LIMIT(r2)
64 addi r11,r3,THREAD_INFO_GAP 67 addi r11,r4,THREAD_INFO_GAP
65 stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4) 68 stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
66 mr r1,r4 69 mr r1,r4
67 stw r10,8(r1) 70 stw r10,8(r1)
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 8d4c247f1738..af064d28b365 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1048,6 +1048,15 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
1048 flush_altivec_to_thread(src); 1048 flush_altivec_to_thread(src);
1049 flush_vsx_to_thread(src); 1049 flush_vsx_to_thread(src);
1050 flush_spe_to_thread(src); 1050 flush_spe_to_thread(src);
1051 /*
1052 * Flush TM state out so we can copy it. __switch_to_tm() does this
1053 * flush but it removes the checkpointed state from the current CPU and
1054 * transitions the CPU out of TM mode. Hence we need to call
1055 * tm_recheckpoint_new_task() (on the same task) to restore the
1056 * checkpointed state back and the TM mode.
1057 */
1058 __switch_to_tm(src);
1059 tm_recheckpoint_new_task(src);
1051 1060
1052 *dst = *src; 1061 *dst = *src;
1053 1062
diff --git a/arch/powerpc/kernel/reloc_64.S b/arch/powerpc/kernel/reloc_64.S
index b47a0e1ab001..d88736fbece6 100644
--- a/arch/powerpc/kernel/reloc_64.S
+++ b/arch/powerpc/kernel/reloc_64.S
@@ -69,8 +69,8 @@ _GLOBAL(relocate)
69 * R_PPC64_RELATIVE ones. 69 * R_PPC64_RELATIVE ones.
70 */ 70 */
71 mtctr r8 71 mtctr r8
725: lwz r0,12(9) /* ELF64_R_TYPE(reloc->r_info) */ 725: ld r0,8(9) /* ELF64_R_TYPE(reloc->r_info) */
73 cmpwi r0,R_PPC64_RELATIVE 73 cmpdi r0,R_PPC64_RELATIVE
74 bne 6f 74 bne 6f
75 ld r6,0(r9) /* reloc->r_offset */ 75 ld r6,0(r9) /* reloc->r_offset */
76 ld r0,16(r9) /* reloc->r_addend */ 76 ld r0,16(r9) /* reloc->r_addend */
@@ -81,6 +81,7 @@ _GLOBAL(relocate)
81 81
826: blr 826: blr
83 83
84.balign 8
84p_dyn: .llong __dynamic_start - 0b 85p_dyn: .llong __dynamic_start - 0b
85p_rela: .llong __rela_dyn_start - 0b 86p_rela: .llong __rela_dyn_start - 0b
86p_st: .llong _stext - 0b 87p_st: .llong _stext - 0b
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 2b0da27eaee4..04cc4fcca78b 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -247,7 +247,12 @@ static void __init exc_lvl_early_init(void)
247 /* interrupt stacks must be in lowmem, we get that for free on ppc32 247 /* interrupt stacks must be in lowmem, we get that for free on ppc32
248 * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */ 248 * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */
249 for_each_possible_cpu(i) { 249 for_each_possible_cpu(i) {
250#ifdef CONFIG_SMP
250 hw_cpu = get_hard_smp_processor_id(i); 251 hw_cpu = get_hard_smp_processor_id(i);
252#else
253 hw_cpu = 0;
254#endif
255
251 critirq_ctx[hw_cpu] = (struct thread_info *) 256 critirq_ctx[hw_cpu] = (struct thread_info *)
252 __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 257 __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
253#ifdef CONFIG_BOOKE 258#ifdef CONFIG_BOOKE
diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
index e35bf773df7a..8d253c29649b 100644
--- a/arch/powerpc/kernel/signal_64.c
+++ b/arch/powerpc/kernel/signal_64.c
@@ -65,8 +65,8 @@ struct rt_sigframe {
65 struct siginfo __user *pinfo; 65 struct siginfo __user *pinfo;
66 void __user *puc; 66 void __user *puc;
67 struct siginfo info; 67 struct siginfo info;
68 /* 64 bit ABI allows for 288 bytes below sp before decrementing it. */ 68 /* New 64 bit little-endian ABI allows redzone of 512 bytes below sp */
69 char abigap[288]; 69 char abigap[USER_REDZONE_SIZE];
70} __attribute__ ((aligned (16))); 70} __attribute__ ((aligned (16)));
71 71
72static const char fmt32[] = KERN_INFO \ 72static const char fmt32[] = KERN_INFO \
diff --git a/arch/powerpc/kernel/vdso32/vdso32_wrapper.S b/arch/powerpc/kernel/vdso32/vdso32_wrapper.S
index 79683d0393f5..6ac107ac402a 100644
--- a/arch/powerpc/kernel/vdso32/vdso32_wrapper.S
+++ b/arch/powerpc/kernel/vdso32/vdso32_wrapper.S
@@ -6,7 +6,7 @@
6 .globl vdso32_start, vdso32_end 6 .globl vdso32_start, vdso32_end
7 .balign PAGE_SIZE 7 .balign PAGE_SIZE
8vdso32_start: 8vdso32_start:
9 .incbin "arch/powerpc/kernel/vdso32/vdso32.so" 9 .incbin "arch/powerpc/kernel/vdso32/vdso32.so.dbg"
10 .balign PAGE_SIZE 10 .balign PAGE_SIZE
11vdso32_end: 11vdso32_end:
12 12
diff --git a/arch/powerpc/kernel/vdso64/vdso64_wrapper.S b/arch/powerpc/kernel/vdso64/vdso64_wrapper.S
index 8df9e2463007..df60fca6a13d 100644
--- a/arch/powerpc/kernel/vdso64/vdso64_wrapper.S
+++ b/arch/powerpc/kernel/vdso64/vdso64_wrapper.S
@@ -6,7 +6,7 @@
6 .globl vdso64_start, vdso64_end 6 .globl vdso64_start, vdso64_end
7 .balign PAGE_SIZE 7 .balign PAGE_SIZE
8vdso64_start: 8vdso64_start:
9 .incbin "arch/powerpc/kernel/vdso64/vdso64.so" 9 .incbin "arch/powerpc/kernel/vdso64/vdso64.so.dbg"
10 .balign PAGE_SIZE 10 .balign PAGE_SIZE
11vdso64_end: 11vdso64_end:
12 12
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index e66d4ec04d95..818dce344e82 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -1504,73 +1504,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
15041: addi r8,r8,16 15041: addi r8,r8,16
1505 .endr 1505 .endr
1506 1506
1507 /* Save DEC */
1508 mfspr r5,SPRN_DEC
1509 mftb r6
1510 extsw r5,r5
1511 add r5,r5,r6
1512 std r5,VCPU_DEC_EXPIRES(r9)
1513
1514BEGIN_FTR_SECTION
1515 b 8f
1516END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
1517 /* Turn on TM so we can access TFHAR/TFIAR/TEXASR */
1518 mfmsr r8
1519 li r0, 1
1520 rldimi r8, r0, MSR_TM_LG, 63-MSR_TM_LG
1521 mtmsrd r8
1522
1523 /* Save POWER8-specific registers */
1524 mfspr r5, SPRN_IAMR
1525 mfspr r6, SPRN_PSPB
1526 mfspr r7, SPRN_FSCR
1527 std r5, VCPU_IAMR(r9)
1528 stw r6, VCPU_PSPB(r9)
1529 std r7, VCPU_FSCR(r9)
1530 mfspr r5, SPRN_IC
1531 mfspr r6, SPRN_VTB
1532 mfspr r7, SPRN_TAR
1533 std r5, VCPU_IC(r9)
1534 std r6, VCPU_VTB(r9)
1535 std r7, VCPU_TAR(r9)
1536#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1537 mfspr r5, SPRN_TFHAR
1538 mfspr r6, SPRN_TFIAR
1539 mfspr r7, SPRN_TEXASR
1540 std r5, VCPU_TFHAR(r9)
1541 std r6, VCPU_TFIAR(r9)
1542 std r7, VCPU_TEXASR(r9)
1543#endif
1544 mfspr r8, SPRN_EBBHR
1545 std r8, VCPU_EBBHR(r9)
1546 mfspr r5, SPRN_EBBRR
1547 mfspr r6, SPRN_BESCR
1548 mfspr r7, SPRN_CSIGR
1549 mfspr r8, SPRN_TACR
1550 std r5, VCPU_EBBRR(r9)
1551 std r6, VCPU_BESCR(r9)
1552 std r7, VCPU_CSIGR(r9)
1553 std r8, VCPU_TACR(r9)
1554 mfspr r5, SPRN_TCSCR
1555 mfspr r6, SPRN_ACOP
1556 mfspr r7, SPRN_PID
1557 mfspr r8, SPRN_WORT
1558 std r5, VCPU_TCSCR(r9)
1559 std r6, VCPU_ACOP(r9)
1560 stw r7, VCPU_GUEST_PID(r9)
1561 std r8, VCPU_WORT(r9)
15628:
1563
1564 /* Save and reset AMR and UAMOR before turning on the MMU */
1565BEGIN_FTR_SECTION
1566 mfspr r5,SPRN_AMR
1567 mfspr r6,SPRN_UAMOR
1568 std r5,VCPU_AMR(r9)
1569 std r6,VCPU_UAMOR(r9)
1570 li r6,0
1571 mtspr SPRN_AMR,r6
1572END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
1573
1574 /* Unset guest mode */ 1507 /* Unset guest mode */
1575 li r0, KVM_GUEST_MODE_NONE 1508 li r0, KVM_GUEST_MODE_NONE
1576 stb r0, HSTATE_IN_GUEST(r13) 1509 stb r0, HSTATE_IN_GUEST(r13)
@@ -2203,7 +2136,7 @@ BEGIN_FTR_SECTION
2203END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) 2136END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
2204#endif 2137#endif
2205 mfspr r6,SPRN_VRSAVE 2138 mfspr r6,SPRN_VRSAVE
2206 stw r6,VCPU_VRSAVE(r3) 2139 stw r6,VCPU_VRSAVE(r31)
2207 mtlr r30 2140 mtlr r30
2208 mtmsrd r5 2141 mtmsrd r5
2209 isync 2142 isync
@@ -2240,7 +2173,7 @@ BEGIN_FTR_SECTION
2240 bl .load_vr_state 2173 bl .load_vr_state
2241END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) 2174END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
2242#endif 2175#endif
2243 lwz r7,VCPU_VRSAVE(r4) 2176 lwz r7,VCPU_VRSAVE(r31)
2244 mtspr SPRN_VRSAVE,r7 2177 mtspr SPRN_VRSAVE,r7
2245 mtlr r30 2178 mtlr r30
2246 mr r4,r31 2179 mr r4,r31
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index de6881259aef..d766d6ee33fe 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -207,6 +207,20 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
207 if (overlaps_kernel_text(vaddr, vaddr + step)) 207 if (overlaps_kernel_text(vaddr, vaddr + step))
208 tprot &= ~HPTE_R_N; 208 tprot &= ~HPTE_R_N;
209 209
210 /*
211 * If relocatable, check if it overlaps interrupt vectors that
212 * are copied down to real 0. For relocatable kernel
213 * (e.g. kdump case) we copy interrupt vectors down to real
214 * address 0. Mark that region as executable. This is
215 * because on p8 system with relocation on exception feature
216 * enabled, exceptions are raised with MMU (IR=DR=1) ON. Hence
217 * in order to execute the interrupt handlers in virtual
218 * mode the vector region need to be marked as executable.
219 */
220 if ((PHYSICAL_START > MEMORY_START) &&
221 overlaps_interrupt_vector_text(vaddr, vaddr + step))
222 tprot &= ~HPTE_R_N;
223
210 hash = hpt_hash(vpn, shift, ssize); 224 hash = hpt_hash(vpn, shift, ssize);
211 hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP); 225 hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
212 226
diff --git a/arch/powerpc/mm/pgtable_64.c b/arch/powerpc/mm/pgtable_64.c
index 65b7b65e8708..62bf5e8e78da 100644
--- a/arch/powerpc/mm/pgtable_64.c
+++ b/arch/powerpc/mm/pgtable_64.c
@@ -510,7 +510,8 @@ int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
510} 510}
511 511
512unsigned long pmd_hugepage_update(struct mm_struct *mm, unsigned long addr, 512unsigned long pmd_hugepage_update(struct mm_struct *mm, unsigned long addr,
513 pmd_t *pmdp, unsigned long clr) 513 pmd_t *pmdp, unsigned long clr,
514 unsigned long set)
514{ 515{
515 516
516 unsigned long old, tmp; 517 unsigned long old, tmp;
@@ -526,14 +527,15 @@ unsigned long pmd_hugepage_update(struct mm_struct *mm, unsigned long addr,
526 andi. %1,%0,%6\n\ 527 andi. %1,%0,%6\n\
527 bne- 1b \n\ 528 bne- 1b \n\
528 andc %1,%0,%4 \n\ 529 andc %1,%0,%4 \n\
530 or %1,%1,%7\n\
529 stdcx. %1,0,%3 \n\ 531 stdcx. %1,0,%3 \n\
530 bne- 1b" 532 bne- 1b"
531 : "=&r" (old), "=&r" (tmp), "=m" (*pmdp) 533 : "=&r" (old), "=&r" (tmp), "=m" (*pmdp)
532 : "r" (pmdp), "r" (clr), "m" (*pmdp), "i" (_PAGE_BUSY) 534 : "r" (pmdp), "r" (clr), "m" (*pmdp), "i" (_PAGE_BUSY), "r" (set)
533 : "cc" ); 535 : "cc" );
534#else 536#else
535 old = pmd_val(*pmdp); 537 old = pmd_val(*pmdp);
536 *pmdp = __pmd(old & ~clr); 538 *pmdp = __pmd((old & ~clr) | set);
537#endif 539#endif
538 if (old & _PAGE_HASHPTE) 540 if (old & _PAGE_HASHPTE)
539 hpte_do_hugepage_flush(mm, addr, pmdp); 541 hpte_do_hugepage_flush(mm, addr, pmdp);
@@ -708,7 +710,7 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,
708void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address, 710void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
709 pmd_t *pmdp) 711 pmd_t *pmdp)
710{ 712{
711 pmd_hugepage_update(vma->vm_mm, address, pmdp, _PAGE_PRESENT); 713 pmd_hugepage_update(vma->vm_mm, address, pmdp, _PAGE_PRESENT, 0);
712} 714}
713 715
714/* 716/*
@@ -835,7 +837,7 @@ pmd_t pmdp_get_and_clear(struct mm_struct *mm,
835 unsigned long old; 837 unsigned long old;
836 pgtable_t *pgtable_slot; 838 pgtable_t *pgtable_slot;
837 839
838 old = pmd_hugepage_update(mm, addr, pmdp, ~0UL); 840 old = pmd_hugepage_update(mm, addr, pmdp, ~0UL, 0);
839 old_pmd = __pmd(old); 841 old_pmd = __pmd(old);
840 /* 842 /*
841 * We have pmd == none and we are holding page_table_lock. 843 * We have pmd == none and we are holding page_table_lock.
diff --git a/arch/powerpc/mm/subpage-prot.c b/arch/powerpc/mm/subpage-prot.c
index a770df2dae70..6c0b1f5f8d2c 100644
--- a/arch/powerpc/mm/subpage-prot.c
+++ b/arch/powerpc/mm/subpage-prot.c
@@ -78,7 +78,7 @@ static void hpte_flush_range(struct mm_struct *mm, unsigned long addr,
78 pte = pte_offset_map_lock(mm, pmd, addr, &ptl); 78 pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
79 arch_enter_lazy_mmu_mode(); 79 arch_enter_lazy_mmu_mode();
80 for (; npages > 0; --npages) { 80 for (; npages > 0; --npages) {
81 pte_update(mm, addr, pte, 0, 0); 81 pte_update(mm, addr, pte, 0, 0, 0);
82 addr += PAGE_SIZE; 82 addr += PAGE_SIZE;
83 ++pte; 83 ++pte;
84 } 84 }
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 29b89e863d7c..67cf22083f4c 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -1147,6 +1147,9 @@ static void power_pmu_enable(struct pmu *pmu)
1147 mmcr0 = ebb_switch_in(ebb, cpuhw->mmcr[0]); 1147 mmcr0 = ebb_switch_in(ebb, cpuhw->mmcr[0]);
1148 1148
1149 mb(); 1149 mb();
1150 if (cpuhw->bhrb_users)
1151 ppmu->config_bhrb(cpuhw->bhrb_filter);
1152
1150 write_mmcr0(cpuhw, mmcr0); 1153 write_mmcr0(cpuhw, mmcr0);
1151 1154
1152 /* 1155 /*
@@ -1158,8 +1161,6 @@ static void power_pmu_enable(struct pmu *pmu)
1158 } 1161 }
1159 1162
1160 out: 1163 out:
1161 if (cpuhw->bhrb_users)
1162 ppmu->config_bhrb(cpuhw->bhrb_filter);
1163 1164
1164 local_irq_restore(flags); 1165 local_irq_restore(flags);
1165} 1166}
diff --git a/arch/powerpc/perf/power8-pmu.c b/arch/powerpc/perf/power8-pmu.c
index a3f7abd2f13f..96cee20dcd34 100644
--- a/arch/powerpc/perf/power8-pmu.c
+++ b/arch/powerpc/perf/power8-pmu.c
@@ -25,6 +25,37 @@
25#define PM_BRU_FIN 0x10068 25#define PM_BRU_FIN 0x10068
26#define PM_BR_MPRED_CMPL 0x400f6 26#define PM_BR_MPRED_CMPL 0x400f6
27 27
28/* All L1 D cache load references counted at finish, gated by reject */
29#define PM_LD_REF_L1 0x100ee
30/* Load Missed L1 */
31#define PM_LD_MISS_L1 0x3e054
32/* Store Missed L1 */
33#define PM_ST_MISS_L1 0x300f0
34/* L1 cache data prefetches */
35#define PM_L1_PREF 0x0d8b8
36/* Instruction fetches from L1 */
37#define PM_INST_FROM_L1 0x04080
38/* Demand iCache Miss */
39#define PM_L1_ICACHE_MISS 0x200fd
40/* Instruction Demand sectors wriittent into IL1 */
41#define PM_L1_DEMAND_WRITE 0x0408c
42/* Instruction prefetch written into IL1 */
43#define PM_IC_PREF_WRITE 0x0408e
44/* The data cache was reloaded from local core's L3 due to a demand load */
45#define PM_DATA_FROM_L3 0x4c042
46/* Demand LD - L3 Miss (not L2 hit and not L3 hit) */
47#define PM_DATA_FROM_L3MISS 0x300fe
48/* All successful D-side store dispatches for this thread */
49#define PM_L2_ST 0x17080
50/* All successful D-side store dispatches for this thread that were L2 Miss */
51#define PM_L2_ST_MISS 0x17082
52/* Total HW L3 prefetches(Load+store) */
53#define PM_L3_PREF_ALL 0x4e052
54/* Data PTEG reload */
55#define PM_DTLB_MISS 0x300fc
56/* ITLB Reloaded */
57#define PM_ITLB_MISS 0x400fc
58
28 59
29/* 60/*
30 * Raw event encoding for POWER8: 61 * Raw event encoding for POWER8:
@@ -557,6 +588,8 @@ static int power8_generic_events[] = {
557 [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL, 588 [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL,
558 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PM_BRU_FIN, 589 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PM_BRU_FIN,
559 [PERF_COUNT_HW_BRANCH_MISSES] = PM_BR_MPRED_CMPL, 590 [PERF_COUNT_HW_BRANCH_MISSES] = PM_BR_MPRED_CMPL,
591 [PERF_COUNT_HW_CACHE_REFERENCES] = PM_LD_REF_L1,
592 [PERF_COUNT_HW_CACHE_MISSES] = PM_LD_MISS_L1,
560}; 593};
561 594
562static u64 power8_bhrb_filter_map(u64 branch_sample_type) 595static u64 power8_bhrb_filter_map(u64 branch_sample_type)
@@ -596,6 +629,116 @@ static void power8_config_bhrb(u64 pmu_bhrb_filter)
596 mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter)); 629 mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter));
597} 630}
598 631
632#define C(x) PERF_COUNT_HW_CACHE_##x
633
634/*
635 * Table of generalized cache-related events.
636 * 0 means not supported, -1 means nonsensical, other values
637 * are event codes.
638 */
639static int power8_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
640 [ C(L1D) ] = {
641 [ C(OP_READ) ] = {
642 [ C(RESULT_ACCESS) ] = PM_LD_REF_L1,
643 [ C(RESULT_MISS) ] = PM_LD_MISS_L1,
644 },
645 [ C(OP_WRITE) ] = {
646 [ C(RESULT_ACCESS) ] = 0,
647 [ C(RESULT_MISS) ] = PM_ST_MISS_L1,
648 },
649 [ C(OP_PREFETCH) ] = {
650 [ C(RESULT_ACCESS) ] = PM_L1_PREF,
651 [ C(RESULT_MISS) ] = 0,
652 },
653 },
654 [ C(L1I) ] = {
655 [ C(OP_READ) ] = {
656 [ C(RESULT_ACCESS) ] = PM_INST_FROM_L1,
657 [ C(RESULT_MISS) ] = PM_L1_ICACHE_MISS,
658 },
659 [ C(OP_WRITE) ] = {
660 [ C(RESULT_ACCESS) ] = PM_L1_DEMAND_WRITE,
661 [ C(RESULT_MISS) ] = -1,
662 },
663 [ C(OP_PREFETCH) ] = {
664 [ C(RESULT_ACCESS) ] = PM_IC_PREF_WRITE,
665 [ C(RESULT_MISS) ] = 0,
666 },
667 },
668 [ C(LL) ] = {
669 [ C(OP_READ) ] = {
670 [ C(RESULT_ACCESS) ] = PM_DATA_FROM_L3,
671 [ C(RESULT_MISS) ] = PM_DATA_FROM_L3MISS,
672 },
673 [ C(OP_WRITE) ] = {
674 [ C(RESULT_ACCESS) ] = PM_L2_ST,
675 [ C(RESULT_MISS) ] = PM_L2_ST_MISS,
676 },
677 [ C(OP_PREFETCH) ] = {
678 [ C(RESULT_ACCESS) ] = PM_L3_PREF_ALL,
679 [ C(RESULT_MISS) ] = 0,
680 },
681 },
682 [ C(DTLB) ] = {
683 [ C(OP_READ) ] = {
684 [ C(RESULT_ACCESS) ] = 0,
685 [ C(RESULT_MISS) ] = PM_DTLB_MISS,
686 },
687 [ C(OP_WRITE) ] = {
688 [ C(RESULT_ACCESS) ] = -1,
689 [ C(RESULT_MISS) ] = -1,
690 },
691 [ C(OP_PREFETCH) ] = {
692 [ C(RESULT_ACCESS) ] = -1,
693 [ C(RESULT_MISS) ] = -1,
694 },
695 },
696 [ C(ITLB) ] = {
697 [ C(OP_READ) ] = {
698 [ C(RESULT_ACCESS) ] = 0,
699 [ C(RESULT_MISS) ] = PM_ITLB_MISS,
700 },
701 [ C(OP_WRITE) ] = {
702 [ C(RESULT_ACCESS) ] = -1,
703 [ C(RESULT_MISS) ] = -1,
704 },
705 [ C(OP_PREFETCH) ] = {
706 [ C(RESULT_ACCESS) ] = -1,
707 [ C(RESULT_MISS) ] = -1,
708 },
709 },
710 [ C(BPU) ] = {
711 [ C(OP_READ) ] = {
712 [ C(RESULT_ACCESS) ] = PM_BRU_FIN,
713 [ C(RESULT_MISS) ] = PM_BR_MPRED_CMPL,
714 },
715 [ C(OP_WRITE) ] = {
716 [ C(RESULT_ACCESS) ] = -1,
717 [ C(RESULT_MISS) ] = -1,
718 },
719 [ C(OP_PREFETCH) ] = {
720 [ C(RESULT_ACCESS) ] = -1,
721 [ C(RESULT_MISS) ] = -1,
722 },
723 },
724 [ C(NODE) ] = {
725 [ C(OP_READ) ] = {
726 [ C(RESULT_ACCESS) ] = -1,
727 [ C(RESULT_MISS) ] = -1,
728 },
729 [ C(OP_WRITE) ] = {
730 [ C(RESULT_ACCESS) ] = -1,
731 [ C(RESULT_MISS) ] = -1,
732 },
733 [ C(OP_PREFETCH) ] = {
734 [ C(RESULT_ACCESS) ] = -1,
735 [ C(RESULT_MISS) ] = -1,
736 },
737 },
738};
739
740#undef C
741
599static struct power_pmu power8_pmu = { 742static struct power_pmu power8_pmu = {
600 .name = "POWER8", 743 .name = "POWER8",
601 .n_counter = 6, 744 .n_counter = 6,
@@ -611,6 +754,7 @@ static struct power_pmu power8_pmu = {
611 .flags = PPMU_HAS_SSLOT | PPMU_HAS_SIER | PPMU_BHRB | PPMU_EBB, 754 .flags = PPMU_HAS_SSLOT | PPMU_HAS_SIER | PPMU_BHRB | PPMU_EBB,
612 .n_generic = ARRAY_SIZE(power8_generic_events), 755 .n_generic = ARRAY_SIZE(power8_generic_events),
613 .generic_events = power8_generic_events, 756 .generic_events = power8_generic_events,
757 .cache_events = &power8_cache_events,
614 .attr_groups = power8_pmu_attr_groups, 758 .attr_groups = power8_pmu_attr_groups,
615 .bhrb_nr = 32, 759 .bhrb_nr = 32,
616}; 760};
diff --git a/arch/powerpc/platforms/cell/ras.c b/arch/powerpc/platforms/cell/ras.c
index 5ec1e47a0d77..e865d748179b 100644
--- a/arch/powerpc/platforms/cell/ras.c
+++ b/arch/powerpc/platforms/cell/ras.c
@@ -123,7 +123,8 @@ static int __init cbe_ptcal_enable_on_node(int nid, int order)
123 123
124 area->nid = nid; 124 area->nid = nid;
125 area->order = order; 125 area->order = order;
126 area->pages = alloc_pages_exact_node(area->nid, GFP_KERNEL|GFP_THISNODE, 126 area->pages = alloc_pages_exact_node(area->nid,
127 GFP_KERNEL|__GFP_THISNODE,
127 area->order); 128 area->order);
128 129
129 if (!area->pages) { 130 if (!area->pages) {
diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
index 49318385d4fa..4a0a64fe25df 100644
--- a/arch/powerpc/platforms/cell/spufs/sched.c
+++ b/arch/powerpc/platforms/cell/spufs/sched.c
@@ -83,7 +83,6 @@ static struct timer_list spuloadavg_timer;
83#define MIN_SPU_TIMESLICE max(5 * HZ / (1000 * SPUSCHED_TICK), 1) 83#define MIN_SPU_TIMESLICE max(5 * HZ / (1000 * SPUSCHED_TICK), 1)
84#define DEF_SPU_TIMESLICE (100 * HZ / (1000 * SPUSCHED_TICK)) 84#define DEF_SPU_TIMESLICE (100 * HZ / (1000 * SPUSCHED_TICK))
85 85
86#define MAX_USER_PRIO (MAX_PRIO - MAX_RT_PRIO)
87#define SCALE_PRIO(x, prio) \ 86#define SCALE_PRIO(x, prio) \
88 max(x * (MAX_PRIO - prio) / (MAX_USER_PRIO / 2), MIN_SPU_TIMESLICE) 87 max(x * (MAX_PRIO - prio) / (MAX_USER_PRIO / 2), MIN_SPU_TIMESLICE)
89 88
diff --git a/arch/powerpc/platforms/powernv/eeh-ioda.c b/arch/powerpc/platforms/powernv/eeh-ioda.c
index e1e71618b70c..253fefe3d1a0 100644
--- a/arch/powerpc/platforms/powernv/eeh-ioda.c
+++ b/arch/powerpc/platforms/powernv/eeh-ioda.c
@@ -44,7 +44,8 @@ static int ioda_eeh_event(struct notifier_block *nb,
44 44
45 /* We simply send special EEH event */ 45 /* We simply send special EEH event */
46 if ((changed_evts & OPAL_EVENT_PCI_ERROR) && 46 if ((changed_evts & OPAL_EVENT_PCI_ERROR) &&
47 (events & OPAL_EVENT_PCI_ERROR)) 47 (events & OPAL_EVENT_PCI_ERROR) &&
48 eeh_enabled())
48 eeh_send_failure_event(NULL); 49 eeh_send_failure_event(NULL);
49 50
50 return 0; 51 return 0;
@@ -113,6 +114,7 @@ DEFINE_SIMPLE_ATTRIBUTE(ioda_eeh_inbB_dbgfs_ops, ioda_eeh_inbB_dbgfs_get,
113 ioda_eeh_inbB_dbgfs_set, "0x%llx\n"); 114 ioda_eeh_inbB_dbgfs_set, "0x%llx\n");
114#endif /* CONFIG_DEBUG_FS */ 115#endif /* CONFIG_DEBUG_FS */
115 116
117
116/** 118/**
117 * ioda_eeh_post_init - Chip dependent post initialization 119 * ioda_eeh_post_init - Chip dependent post initialization
118 * @hose: PCI controller 120 * @hose: PCI controller
@@ -220,6 +222,22 @@ static int ioda_eeh_set_option(struct eeh_pe *pe, int option)
220 return ret; 222 return ret;
221} 223}
222 224
225static void ioda_eeh_phb_diag(struct pci_controller *hose)
226{
227 struct pnv_phb *phb = hose->private_data;
228 long rc;
229
230 rc = opal_pci_get_phb_diag_data2(phb->opal_id, phb->diag.blob,
231 PNV_PCI_DIAG_BUF_SIZE);
232 if (rc != OPAL_SUCCESS) {
233 pr_warning("%s: Failed to get diag-data for PHB#%x (%ld)\n",
234 __func__, hose->global_number, rc);
235 return;
236 }
237
238 pnv_pci_dump_phb_diag_data(hose, phb->diag.blob);
239}
240
223/** 241/**
224 * ioda_eeh_get_state - Retrieve the state of PE 242 * ioda_eeh_get_state - Retrieve the state of PE
225 * @pe: EEH PE 243 * @pe: EEH PE
@@ -271,6 +289,9 @@ static int ioda_eeh_get_state(struct eeh_pe *pe)
271 result |= EEH_STATE_DMA_ACTIVE; 289 result |= EEH_STATE_DMA_ACTIVE;
272 result |= EEH_STATE_MMIO_ENABLED; 290 result |= EEH_STATE_MMIO_ENABLED;
273 result |= EEH_STATE_DMA_ENABLED; 291 result |= EEH_STATE_DMA_ENABLED;
292 } else if (!(pe->state & EEH_PE_ISOLATED)) {
293 eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
294 ioda_eeh_phb_diag(hose);
274 } 295 }
275 296
276 return result; 297 return result;
@@ -314,6 +335,15 @@ static int ioda_eeh_get_state(struct eeh_pe *pe)
314 __func__, fstate, hose->global_number, pe_no); 335 __func__, fstate, hose->global_number, pe_no);
315 } 336 }
316 337
338 /* Dump PHB diag-data for frozen PE */
339 if (result != EEH_STATE_NOT_SUPPORT &&
340 (result & (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE)) !=
341 (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE) &&
342 !(pe->state & EEH_PE_ISOLATED)) {
343 eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
344 ioda_eeh_phb_diag(hose);
345 }
346
317 return result; 347 return result;
318} 348}
319 349
@@ -489,8 +519,7 @@ static int ioda_eeh_bridge_reset(struct pci_controller *hose,
489static int ioda_eeh_reset(struct eeh_pe *pe, int option) 519static int ioda_eeh_reset(struct eeh_pe *pe, int option)
490{ 520{
491 struct pci_controller *hose = pe->phb; 521 struct pci_controller *hose = pe->phb;
492 struct eeh_dev *edev; 522 struct pci_bus *bus;
493 struct pci_dev *dev;
494 int ret; 523 int ret;
495 524
496 /* 525 /*
@@ -519,73 +548,17 @@ static int ioda_eeh_reset(struct eeh_pe *pe, int option)
519 if (pe->type & EEH_PE_PHB) { 548 if (pe->type & EEH_PE_PHB) {
520 ret = ioda_eeh_phb_reset(hose, option); 549 ret = ioda_eeh_phb_reset(hose, option);
521 } else { 550 } else {
522 if (pe->type & EEH_PE_DEVICE) { 551 bus = eeh_pe_bus_get(pe);
523 /* 552 if (pci_is_root_bus(bus))
524 * If it's device PE, we didn't refer to the parent
525 * PCI bus yet. So we have to figure it out indirectly.
526 */
527 edev = list_first_entry(&pe->edevs,
528 struct eeh_dev, list);
529 dev = eeh_dev_to_pci_dev(edev);
530 dev = dev->bus->self;
531 } else {
532 /*
533 * If it's bus PE, the parent PCI bus is already there
534 * and just pick it up.
535 */
536 dev = pe->bus->self;
537 }
538
539 /*
540 * Do reset based on the fact that the direct upstream bridge
541 * is root bridge (port) or not.
542 */
543 if (dev->bus->number == 0)
544 ret = ioda_eeh_root_reset(hose, option); 553 ret = ioda_eeh_root_reset(hose, option);
545 else 554 else
546 ret = ioda_eeh_bridge_reset(hose, dev, option); 555 ret = ioda_eeh_bridge_reset(hose, bus->self, option);
547 } 556 }
548 557
549 return ret; 558 return ret;
550} 559}
551 560
552/** 561/**
553 * ioda_eeh_get_log - Retrieve error log
554 * @pe: EEH PE
555 * @severity: Severity level of the log
556 * @drv_log: buffer to store the log
557 * @len: space of the log buffer
558 *
559 * The function is used to retrieve error log from P7IOC.
560 */
561static int ioda_eeh_get_log(struct eeh_pe *pe, int severity,
562 char *drv_log, unsigned long len)
563{
564 s64 ret;
565 unsigned long flags;
566 struct pci_controller *hose = pe->phb;
567 struct pnv_phb *phb = hose->private_data;
568
569 spin_lock_irqsave(&phb->lock, flags);
570
571 ret = opal_pci_get_phb_diag_data2(phb->opal_id,
572 phb->diag.blob, PNV_PCI_DIAG_BUF_SIZE);
573 if (ret) {
574 spin_unlock_irqrestore(&phb->lock, flags);
575 pr_warning("%s: Can't get log for PHB#%x-PE#%x (%lld)\n",
576 __func__, hose->global_number, pe->addr, ret);
577 return -EIO;
578 }
579
580 /* The PHB diag-data is always indicative */
581 pnv_pci_dump_phb_diag_data(hose, phb->diag.blob);
582
583 spin_unlock_irqrestore(&phb->lock, flags);
584
585 return 0;
586}
587
588/**
589 * ioda_eeh_configure_bridge - Configure the PCI bridges for the indicated PE 562 * ioda_eeh_configure_bridge - Configure the PCI bridges for the indicated PE
590 * @pe: EEH PE 563 * @pe: EEH PE
591 * 564 *
@@ -666,22 +639,6 @@ static void ioda_eeh_hub_diag(struct pci_controller *hose)
666 } 639 }
667} 640}
668 641
669static void ioda_eeh_phb_diag(struct pci_controller *hose)
670{
671 struct pnv_phb *phb = hose->private_data;
672 long rc;
673
674 rc = opal_pci_get_phb_diag_data2(phb->opal_id, phb->diag.blob,
675 PNV_PCI_DIAG_BUF_SIZE);
676 if (rc != OPAL_SUCCESS) {
677 pr_warning("%s: Failed to get diag-data for PHB#%x (%ld)\n",
678 __func__, hose->global_number, rc);
679 return;
680 }
681
682 pnv_pci_dump_phb_diag_data(hose, phb->diag.blob);
683}
684
685static int ioda_eeh_get_phb_pe(struct pci_controller *hose, 642static int ioda_eeh_get_phb_pe(struct pci_controller *hose,
686 struct eeh_pe **pe) 643 struct eeh_pe **pe)
687{ 644{
@@ -855,6 +812,20 @@ static int ioda_eeh_next_error(struct eeh_pe **pe)
855 } 812 }
856 813
857 /* 814 /*
815 * EEH core will try recover from fenced PHB or
816 * frozen PE. In the time for frozen PE, EEH core
817 * enable IO path for that before collecting logs,
818 * but it ruins the site. So we have to dump the
819 * log in advance here.
820 */
821 if ((ret == EEH_NEXT_ERR_FROZEN_PE ||
822 ret == EEH_NEXT_ERR_FENCED_PHB) &&
823 !((*pe)->state & EEH_PE_ISOLATED)) {
824 eeh_pe_state_mark(*pe, EEH_PE_ISOLATED);
825 ioda_eeh_phb_diag(hose);
826 }
827
828 /*
858 * If we have no errors on the specific PHB or only 829 * If we have no errors on the specific PHB or only
859 * informative error there, we continue poking it. 830 * informative error there, we continue poking it.
860 * Otherwise, we need actions to be taken by upper 831 * Otherwise, we need actions to be taken by upper
@@ -872,7 +843,6 @@ struct pnv_eeh_ops ioda_eeh_ops = {
872 .set_option = ioda_eeh_set_option, 843 .set_option = ioda_eeh_set_option,
873 .get_state = ioda_eeh_get_state, 844 .get_state = ioda_eeh_get_state,
874 .reset = ioda_eeh_reset, 845 .reset = ioda_eeh_reset,
875 .get_log = ioda_eeh_get_log,
876 .configure_bridge = ioda_eeh_configure_bridge, 846 .configure_bridge = ioda_eeh_configure_bridge,
877 .next_error = ioda_eeh_next_error 847 .next_error = ioda_eeh_next_error
878}; 848};
diff --git a/arch/powerpc/platforms/powernv/eeh-powernv.c b/arch/powerpc/platforms/powernv/eeh-powernv.c
index a79fddc5e74e..a59788e83b8b 100644
--- a/arch/powerpc/platforms/powernv/eeh-powernv.c
+++ b/arch/powerpc/platforms/powernv/eeh-powernv.c
@@ -145,7 +145,7 @@ static int powernv_eeh_dev_probe(struct pci_dev *dev, void *flag)
145 * Enable EEH explicitly so that we will do EEH check 145 * Enable EEH explicitly so that we will do EEH check
146 * while accessing I/O stuff 146 * while accessing I/O stuff
147 */ 147 */
148 eeh_subsystem_enabled = 1; 148 eeh_set_enable(true);
149 149
150 /* Save memory bars */ 150 /* Save memory bars */
151 eeh_save_bars(edev); 151 eeh_save_bars(edev);
diff --git a/arch/powerpc/platforms/powernv/opal-xscom.c b/arch/powerpc/platforms/powernv/opal-xscom.c
index 4fbf276ac99e..4cd2ea6c0dbe 100644
--- a/arch/powerpc/platforms/powernv/opal-xscom.c
+++ b/arch/powerpc/platforms/powernv/opal-xscom.c
@@ -71,11 +71,11 @@ static int opal_xscom_err_xlate(int64_t rc)
71 } 71 }
72} 72}
73 73
74static u64 opal_scom_unmangle(u64 reg) 74static u64 opal_scom_unmangle(u64 addr)
75{ 75{
76 /* 76 /*
77 * XSCOM indirect addresses have the top bit set. Additionally 77 * XSCOM indirect addresses have the top bit set. Additionally
78 * the reset of the top 3 nibbles is always 0. 78 * the rest of the top 3 nibbles is always 0.
79 * 79 *
80 * Because the debugfs interface uses signed offsets and shifts 80 * Because the debugfs interface uses signed offsets and shifts
81 * the address left by 3, we basically cannot use the top 4 bits 81 * the address left by 3, we basically cannot use the top 4 bits
@@ -86,10 +86,13 @@ static u64 opal_scom_unmangle(u64 reg)
86 * conversion here. To leave room for further xscom address 86 * conversion here. To leave room for further xscom address
87 * expansion, we only clear out the top byte 87 * expansion, we only clear out the top byte
88 * 88 *
89 * For in-kernel use, we also support the real indirect bit, so
90 * we test for any of the top 5 bits
91 *
89 */ 92 */
90 if (reg & (1ull << 59)) 93 if (addr & (0x1full << 59))
91 reg = (reg & ~(0xffull << 56)) | (1ull << 63); 94 addr = (addr & ~(0xffull << 56)) | (1ull << 63);
92 return reg; 95 return addr;
93} 96}
94 97
95static int opal_scom_read(scom_map_t map, u64 reg, u64 *value) 98static int opal_scom_read(scom_map_t map, u64 reg, u64 *value)
@@ -98,8 +101,8 @@ static int opal_scom_read(scom_map_t map, u64 reg, u64 *value)
98 int64_t rc; 101 int64_t rc;
99 __be64 v; 102 __be64 v;
100 103
101 reg = opal_scom_unmangle(reg); 104 reg = opal_scom_unmangle(m->addr + reg);
102 rc = opal_xscom_read(m->chip, m->addr + reg, (__be64 *)__pa(&v)); 105 rc = opal_xscom_read(m->chip, reg, (__be64 *)__pa(&v));
103 *value = be64_to_cpu(v); 106 *value = be64_to_cpu(v);
104 return opal_xscom_err_xlate(rc); 107 return opal_xscom_err_xlate(rc);
105} 108}
@@ -109,8 +112,8 @@ static int opal_scom_write(scom_map_t map, u64 reg, u64 value)
109 struct opal_scom_map *m = map; 112 struct opal_scom_map *m = map;
110 int64_t rc; 113 int64_t rc;
111 114
112 reg = opal_scom_unmangle(reg); 115 reg = opal_scom_unmangle(m->addr + reg);
113 rc = opal_xscom_write(m->chip, m->addr + reg, value); 116 rc = opal_xscom_write(m->chip, reg, value);
114 return opal_xscom_err_xlate(rc); 117 return opal_xscom_err_xlate(rc);
115} 118}
116 119
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 7d6dcc6d5fa9..3b2b4fb3585b 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -21,6 +21,7 @@
21#include <linux/irq.h> 21#include <linux/irq.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/msi.h> 23#include <linux/msi.h>
24#include <linux/memblock.h>
24 25
25#include <asm/sections.h> 26#include <asm/sections.h>
26#include <asm/io.h> 27#include <asm/io.h>
@@ -460,9 +461,39 @@ static void pnv_pci_ioda_dma_dev_setup(struct pnv_phb *phb, struct pci_dev *pdev
460 return; 461 return;
461 462
462 pe = &phb->ioda.pe_array[pdn->pe_number]; 463 pe = &phb->ioda.pe_array[pdn->pe_number];
464 WARN_ON(get_dma_ops(&pdev->dev) != &dma_iommu_ops);
463 set_iommu_table_base_and_group(&pdev->dev, &pe->tce32_table); 465 set_iommu_table_base_and_group(&pdev->dev, &pe->tce32_table);
464} 466}
465 467
468static int pnv_pci_ioda_dma_set_mask(struct pnv_phb *phb,
469 struct pci_dev *pdev, u64 dma_mask)
470{
471 struct pci_dn *pdn = pci_get_pdn(pdev);
472 struct pnv_ioda_pe *pe;
473 uint64_t top;
474 bool bypass = false;
475
476 if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE))
477 return -ENODEV;;
478
479 pe = &phb->ioda.pe_array[pdn->pe_number];
480 if (pe->tce_bypass_enabled) {
481 top = pe->tce_bypass_base + memblock_end_of_DRAM() - 1;
482 bypass = (dma_mask >= top);
483 }
484
485 if (bypass) {
486 dev_info(&pdev->dev, "Using 64-bit DMA iommu bypass\n");
487 set_dma_ops(&pdev->dev, &dma_direct_ops);
488 set_dma_offset(&pdev->dev, pe->tce_bypass_base);
489 } else {
490 dev_info(&pdev->dev, "Using 32-bit DMA via iommu\n");
491 set_dma_ops(&pdev->dev, &dma_iommu_ops);
492 set_iommu_table_base(&pdev->dev, &pe->tce32_table);
493 }
494 return 0;
495}
496
466static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, struct pci_bus *bus) 497static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, struct pci_bus *bus)
467{ 498{
468 struct pci_dev *dev; 499 struct pci_dev *dev;
@@ -657,6 +688,56 @@ static void pnv_pci_ioda_setup_dma_pe(struct pnv_phb *phb,
657 __free_pages(tce_mem, get_order(TCE32_TABLE_SIZE * segs)); 688 __free_pages(tce_mem, get_order(TCE32_TABLE_SIZE * segs));
658} 689}
659 690
691static void pnv_pci_ioda2_set_bypass(struct iommu_table *tbl, bool enable)
692{
693 struct pnv_ioda_pe *pe = container_of(tbl, struct pnv_ioda_pe,
694 tce32_table);
695 uint16_t window_id = (pe->pe_number << 1 ) + 1;
696 int64_t rc;
697
698 pe_info(pe, "%sabling 64-bit DMA bypass\n", enable ? "En" : "Dis");
699 if (enable) {
700 phys_addr_t top = memblock_end_of_DRAM();
701
702 top = roundup_pow_of_two(top);
703 rc = opal_pci_map_pe_dma_window_real(pe->phb->opal_id,
704 pe->pe_number,
705 window_id,
706 pe->tce_bypass_base,
707 top);
708 } else {
709 rc = opal_pci_map_pe_dma_window_real(pe->phb->opal_id,
710 pe->pe_number,
711 window_id,
712 pe->tce_bypass_base,
713 0);
714
715 /*
716 * We might want to reset the DMA ops of all devices on
717 * this PE. However in theory, that shouldn't be necessary
718 * as this is used for VFIO/KVM pass-through and the device
719 * hasn't yet been returned to its kernel driver
720 */
721 }
722 if (rc)
723 pe_err(pe, "OPAL error %lld configuring bypass window\n", rc);
724 else
725 pe->tce_bypass_enabled = enable;
726}
727
728static void pnv_pci_ioda2_setup_bypass_pe(struct pnv_phb *phb,
729 struct pnv_ioda_pe *pe)
730{
731 /* TVE #1 is selected by PCI address bit 59 */
732 pe->tce_bypass_base = 1ull << 59;
733
734 /* Install set_bypass callback for VFIO */
735 pe->tce32_table.set_bypass = pnv_pci_ioda2_set_bypass;
736
737 /* Enable bypass by default */
738 pnv_pci_ioda2_set_bypass(&pe->tce32_table, true);
739}
740
660static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb, 741static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,
661 struct pnv_ioda_pe *pe) 742 struct pnv_ioda_pe *pe)
662{ 743{
@@ -727,6 +808,8 @@ static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,
727 else 808 else
728 pnv_ioda_setup_bus_dma(pe, pe->pbus); 809 pnv_ioda_setup_bus_dma(pe, pe->pbus);
729 810
811 /* Also create a bypass window */
812 pnv_pci_ioda2_setup_bypass_pe(phb, pe);
730 return; 813 return;
731fail: 814fail:
732 if (pe->tce32_seg >= 0) 815 if (pe->tce32_seg >= 0)
@@ -1286,6 +1369,7 @@ void __init pnv_pci_init_ioda_phb(struct device_node *np,
1286 1369
1287 /* Setup TCEs */ 1370 /* Setup TCEs */
1288 phb->dma_dev_setup = pnv_pci_ioda_dma_dev_setup; 1371 phb->dma_dev_setup = pnv_pci_ioda_dma_dev_setup;
1372 phb->dma_set_mask = pnv_pci_ioda_dma_set_mask;
1289 1373
1290 /* Setup shutdown function for kexec */ 1374 /* Setup shutdown function for kexec */
1291 phb->shutdown = pnv_pci_ioda_shutdown; 1375 phb->shutdown = pnv_pci_ioda_shutdown;
diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
index b555ebc57ef5..8518817dcdfd 100644
--- a/arch/powerpc/platforms/powernv/pci.c
+++ b/arch/powerpc/platforms/powernv/pci.c
@@ -134,57 +134,72 @@ static void pnv_pci_dump_p7ioc_diag_data(struct pci_controller *hose,
134 pr_info("P7IOC PHB#%d Diag-data (Version: %d)\n\n", 134 pr_info("P7IOC PHB#%d Diag-data (Version: %d)\n\n",
135 hose->global_number, common->version); 135 hose->global_number, common->version);
136 136
137 pr_info(" brdgCtl: %08x\n", data->brdgCtl); 137 if (data->brdgCtl)
138 138 pr_info(" brdgCtl: %08x\n",
139 pr_info(" portStatusReg: %08x\n", data->portStatusReg); 139 data->brdgCtl);
140 pr_info(" rootCmplxStatus: %08x\n", data->rootCmplxStatus); 140 if (data->portStatusReg || data->rootCmplxStatus ||
141 pr_info(" busAgentStatus: %08x\n", data->busAgentStatus); 141 data->busAgentStatus)
142 142 pr_info(" UtlSts: %08x %08x %08x\n",
143 pr_info(" deviceStatus: %08x\n", data->deviceStatus); 143 data->portStatusReg, data->rootCmplxStatus,
144 pr_info(" slotStatus: %08x\n", data->slotStatus); 144 data->busAgentStatus);
145 pr_info(" linkStatus: %08x\n", data->linkStatus); 145 if (data->deviceStatus || data->slotStatus ||
146 pr_info(" devCmdStatus: %08x\n", data->devCmdStatus); 146 data->linkStatus || data->devCmdStatus ||
147 pr_info(" devSecStatus: %08x\n", data->devSecStatus); 147 data->devSecStatus)
148 148 pr_info(" RootSts: %08x %08x %08x %08x %08x\n",
149 pr_info(" rootErrorStatus: %08x\n", data->rootErrorStatus); 149 data->deviceStatus, data->slotStatus,
150 pr_info(" uncorrErrorStatus: %08x\n", data->uncorrErrorStatus); 150 data->linkStatus, data->devCmdStatus,
151 pr_info(" corrErrorStatus: %08x\n", data->corrErrorStatus); 151 data->devSecStatus);
152 pr_info(" tlpHdr1: %08x\n", data->tlpHdr1); 152 if (data->rootErrorStatus || data->uncorrErrorStatus ||
153 pr_info(" tlpHdr2: %08x\n", data->tlpHdr2); 153 data->corrErrorStatus)
154 pr_info(" tlpHdr3: %08x\n", data->tlpHdr3); 154 pr_info(" RootErrSts: %08x %08x %08x\n",
155 pr_info(" tlpHdr4: %08x\n", data->tlpHdr4); 155 data->rootErrorStatus, data->uncorrErrorStatus,
156 pr_info(" sourceId: %08x\n", data->sourceId); 156 data->corrErrorStatus);
157 pr_info(" errorClass: %016llx\n", data->errorClass); 157 if (data->tlpHdr1 || data->tlpHdr2 ||
158 pr_info(" correlator: %016llx\n", data->correlator); 158 data->tlpHdr3 || data->tlpHdr4)
159 pr_info(" p7iocPlssr: %016llx\n", data->p7iocPlssr); 159 pr_info(" RootErrLog: %08x %08x %08x %08x\n",
160 pr_info(" p7iocCsr: %016llx\n", data->p7iocCsr); 160 data->tlpHdr1, data->tlpHdr2,
161 pr_info(" lemFir: %016llx\n", data->lemFir); 161 data->tlpHdr3, data->tlpHdr4);
162 pr_info(" lemErrorMask: %016llx\n", data->lemErrorMask); 162 if (data->sourceId || data->errorClass ||
163 pr_info(" lemWOF: %016llx\n", data->lemWOF); 163 data->correlator)
164 pr_info(" phbErrorStatus: %016llx\n", data->phbErrorStatus); 164 pr_info(" RootErrLog1: %08x %016llx %016llx\n",
165 pr_info(" phbFirstErrorStatus: %016llx\n", data->phbFirstErrorStatus); 165 data->sourceId, data->errorClass,
166 pr_info(" phbErrorLog0: %016llx\n", data->phbErrorLog0); 166 data->correlator);
167 pr_info(" phbErrorLog1: %016llx\n", data->phbErrorLog1); 167 if (data->p7iocPlssr || data->p7iocCsr)
168 pr_info(" mmioErrorStatus: %016llx\n", data->mmioErrorStatus); 168 pr_info(" PhbSts: %016llx %016llx\n",
169 pr_info(" mmioFirstErrorStatus: %016llx\n", data->mmioFirstErrorStatus); 169 data->p7iocPlssr, data->p7iocCsr);
170 pr_info(" mmioErrorLog0: %016llx\n", data->mmioErrorLog0); 170 if (data->lemFir || data->lemErrorMask ||
171 pr_info(" mmioErrorLog1: %016llx\n", data->mmioErrorLog1); 171 data->lemWOF)
172 pr_info(" dma0ErrorStatus: %016llx\n", data->dma0ErrorStatus); 172 pr_info(" Lem: %016llx %016llx %016llx\n",
173 pr_info(" dma0FirstErrorStatus: %016llx\n", data->dma0FirstErrorStatus); 173 data->lemFir, data->lemErrorMask,
174 pr_info(" dma0ErrorLog0: %016llx\n", data->dma0ErrorLog0); 174 data->lemWOF);
175 pr_info(" dma0ErrorLog1: %016llx\n", data->dma0ErrorLog1); 175 if (data->phbErrorStatus || data->phbFirstErrorStatus ||
176 pr_info(" dma1ErrorStatus: %016llx\n", data->dma1ErrorStatus); 176 data->phbErrorLog0 || data->phbErrorLog1)
177 pr_info(" dma1FirstErrorStatus: %016llx\n", data->dma1FirstErrorStatus); 177 pr_info(" PhbErr: %016llx %016llx %016llx %016llx\n",
178 pr_info(" dma1ErrorLog0: %016llx\n", data->dma1ErrorLog0); 178 data->phbErrorStatus, data->phbFirstErrorStatus,
179 pr_info(" dma1ErrorLog1: %016llx\n", data->dma1ErrorLog1); 179 data->phbErrorLog0, data->phbErrorLog1);
180 if (data->mmioErrorStatus || data->mmioFirstErrorStatus ||
181 data->mmioErrorLog0 || data->mmioErrorLog1)
182 pr_info(" OutErr: %016llx %016llx %016llx %016llx\n",
183 data->mmioErrorStatus, data->mmioFirstErrorStatus,
184 data->mmioErrorLog0, data->mmioErrorLog1);
185 if (data->dma0ErrorStatus || data->dma0FirstErrorStatus ||
186 data->dma0ErrorLog0 || data->dma0ErrorLog1)
187 pr_info(" InAErr: %016llx %016llx %016llx %016llx\n",
188 data->dma0ErrorStatus, data->dma0FirstErrorStatus,
189 data->dma0ErrorLog0, data->dma0ErrorLog1);
190 if (data->dma1ErrorStatus || data->dma1FirstErrorStatus ||
191 data->dma1ErrorLog0 || data->dma1ErrorLog1)
192 pr_info(" InBErr: %016llx %016llx %016llx %016llx\n",
193 data->dma1ErrorStatus, data->dma1FirstErrorStatus,
194 data->dma1ErrorLog0, data->dma1ErrorLog1);
180 195
181 for (i = 0; i < OPAL_P7IOC_NUM_PEST_REGS; i++) { 196 for (i = 0; i < OPAL_P7IOC_NUM_PEST_REGS; i++) {
182 if ((data->pestA[i] >> 63) == 0 && 197 if ((data->pestA[i] >> 63) == 0 &&
183 (data->pestB[i] >> 63) == 0) 198 (data->pestB[i] >> 63) == 0)
184 continue; 199 continue;
185 200
186 pr_info(" PE[%3d] PESTA: %016llx\n", i, data->pestA[i]); 201 pr_info(" PE[%3d] A/B: %016llx %016llx\n",
187 pr_info(" PESTB: %016llx\n", data->pestB[i]); 202 i, data->pestA[i], data->pestB[i]);
188 } 203 }
189} 204}
190 205
@@ -197,62 +212,77 @@ static void pnv_pci_dump_phb3_diag_data(struct pci_controller *hose,
197 data = (struct OpalIoPhb3ErrorData*)common; 212 data = (struct OpalIoPhb3ErrorData*)common;
198 pr_info("PHB3 PHB#%d Diag-data (Version: %d)\n\n", 213 pr_info("PHB3 PHB#%d Diag-data (Version: %d)\n\n",
199 hose->global_number, common->version); 214 hose->global_number, common->version);
200 215 if (data->brdgCtl)
201 pr_info(" brdgCtl: %08x\n", data->brdgCtl); 216 pr_info(" brdgCtl: %08x\n",
202 217 data->brdgCtl);
203 pr_info(" portStatusReg: %08x\n", data->portStatusReg); 218 if (data->portStatusReg || data->rootCmplxStatus ||
204 pr_info(" rootCmplxStatus: %08x\n", data->rootCmplxStatus); 219 data->busAgentStatus)
205 pr_info(" busAgentStatus: %08x\n", data->busAgentStatus); 220 pr_info(" UtlSts: %08x %08x %08x\n",
206 221 data->portStatusReg, data->rootCmplxStatus,
207 pr_info(" deviceStatus: %08x\n", data->deviceStatus); 222 data->busAgentStatus);
208 pr_info(" slotStatus: %08x\n", data->slotStatus); 223 if (data->deviceStatus || data->slotStatus ||
209 pr_info(" linkStatus: %08x\n", data->linkStatus); 224 data->linkStatus || data->devCmdStatus ||
210 pr_info(" devCmdStatus: %08x\n", data->devCmdStatus); 225 data->devSecStatus)
211 pr_info(" devSecStatus: %08x\n", data->devSecStatus); 226 pr_info(" RootSts: %08x %08x %08x %08x %08x\n",
212 227 data->deviceStatus, data->slotStatus,
213 pr_info(" rootErrorStatus: %08x\n", data->rootErrorStatus); 228 data->linkStatus, data->devCmdStatus,
214 pr_info(" uncorrErrorStatus: %08x\n", data->uncorrErrorStatus); 229 data->devSecStatus);
215 pr_info(" corrErrorStatus: %08x\n", data->corrErrorStatus); 230 if (data->rootErrorStatus || data->uncorrErrorStatus ||
216 pr_info(" tlpHdr1: %08x\n", data->tlpHdr1); 231 data->corrErrorStatus)
217 pr_info(" tlpHdr2: %08x\n", data->tlpHdr2); 232 pr_info(" RootErrSts: %08x %08x %08x\n",
218 pr_info(" tlpHdr3: %08x\n", data->tlpHdr3); 233 data->rootErrorStatus, data->uncorrErrorStatus,
219 pr_info(" tlpHdr4: %08x\n", data->tlpHdr4); 234 data->corrErrorStatus);
220 pr_info(" sourceId: %08x\n", data->sourceId); 235 if (data->tlpHdr1 || data->tlpHdr2 ||
221 pr_info(" errorClass: %016llx\n", data->errorClass); 236 data->tlpHdr3 || data->tlpHdr4)
222 pr_info(" correlator: %016llx\n", data->correlator); 237 pr_info(" RootErrLog: %08x %08x %08x %08x\n",
223 238 data->tlpHdr1, data->tlpHdr2,
224 pr_info(" nFir: %016llx\n", data->nFir); 239 data->tlpHdr3, data->tlpHdr4);
225 pr_info(" nFirMask: %016llx\n", data->nFirMask); 240 if (data->sourceId || data->errorClass ||
226 pr_info(" nFirWOF: %016llx\n", data->nFirWOF); 241 data->correlator)
227 pr_info(" PhbPlssr: %016llx\n", data->phbPlssr); 242 pr_info(" RootErrLog1: %08x %016llx %016llx\n",
228 pr_info(" PhbCsr: %016llx\n", data->phbCsr); 243 data->sourceId, data->errorClass,
229 pr_info(" lemFir: %016llx\n", data->lemFir); 244 data->correlator);
230 pr_info(" lemErrorMask: %016llx\n", data->lemErrorMask); 245 if (data->nFir || data->nFirMask ||
231 pr_info(" lemWOF: %016llx\n", data->lemWOF); 246 data->nFirWOF)
232 pr_info(" phbErrorStatus: %016llx\n", data->phbErrorStatus); 247 pr_info(" nFir: %016llx %016llx %016llx\n",
233 pr_info(" phbFirstErrorStatus: %016llx\n", data->phbFirstErrorStatus); 248 data->nFir, data->nFirMask,
234 pr_info(" phbErrorLog0: %016llx\n", data->phbErrorLog0); 249 data->nFirWOF);
235 pr_info(" phbErrorLog1: %016llx\n", data->phbErrorLog1); 250 if (data->phbPlssr || data->phbCsr)
236 pr_info(" mmioErrorStatus: %016llx\n", data->mmioErrorStatus); 251 pr_info(" PhbSts: %016llx %016llx\n",
237 pr_info(" mmioFirstErrorStatus: %016llx\n", data->mmioFirstErrorStatus); 252 data->phbPlssr, data->phbCsr);
238 pr_info(" mmioErrorLog0: %016llx\n", data->mmioErrorLog0); 253 if (data->lemFir || data->lemErrorMask ||
239 pr_info(" mmioErrorLog1: %016llx\n", data->mmioErrorLog1); 254 data->lemWOF)
240 pr_info(" dma0ErrorStatus: %016llx\n", data->dma0ErrorStatus); 255 pr_info(" Lem: %016llx %016llx %016llx\n",
241 pr_info(" dma0FirstErrorStatus: %016llx\n", data->dma0FirstErrorStatus); 256 data->lemFir, data->lemErrorMask,
242 pr_info(" dma0ErrorLog0: %016llx\n", data->dma0ErrorLog0); 257 data->lemWOF);
243 pr_info(" dma0ErrorLog1: %016llx\n", data->dma0ErrorLog1); 258 if (data->phbErrorStatus || data->phbFirstErrorStatus ||
244 pr_info(" dma1ErrorStatus: %016llx\n", data->dma1ErrorStatus); 259 data->phbErrorLog0 || data->phbErrorLog1)
245 pr_info(" dma1FirstErrorStatus: %016llx\n", data->dma1FirstErrorStatus); 260 pr_info(" PhbErr: %016llx %016llx %016llx %016llx\n",
246 pr_info(" dma1ErrorLog0: %016llx\n", data->dma1ErrorLog0); 261 data->phbErrorStatus, data->phbFirstErrorStatus,
247 pr_info(" dma1ErrorLog1: %016llx\n", data->dma1ErrorLog1); 262 data->phbErrorLog0, data->phbErrorLog1);
263 if (data->mmioErrorStatus || data->mmioFirstErrorStatus ||
264 data->mmioErrorLog0 || data->mmioErrorLog1)
265 pr_info(" OutErr: %016llx %016llx %016llx %016llx\n",
266 data->mmioErrorStatus, data->mmioFirstErrorStatus,
267 data->mmioErrorLog0, data->mmioErrorLog1);
268 if (data->dma0ErrorStatus || data->dma0FirstErrorStatus ||
269 data->dma0ErrorLog0 || data->dma0ErrorLog1)
270 pr_info(" InAErr: %016llx %016llx %016llx %016llx\n",
271 data->dma0ErrorStatus, data->dma0FirstErrorStatus,
272 data->dma0ErrorLog0, data->dma0ErrorLog1);
273 if (data->dma1ErrorStatus || data->dma1FirstErrorStatus ||
274 data->dma1ErrorLog0 || data->dma1ErrorLog1)
275 pr_info(" InBErr: %016llx %016llx %016llx %016llx\n",
276 data->dma1ErrorStatus, data->dma1FirstErrorStatus,
277 data->dma1ErrorLog0, data->dma1ErrorLog1);
248 278
249 for (i = 0; i < OPAL_PHB3_NUM_PEST_REGS; i++) { 279 for (i = 0; i < OPAL_PHB3_NUM_PEST_REGS; i++) {
250 if ((data->pestA[i] >> 63) == 0 && 280 if ((data->pestA[i] >> 63) == 0 &&
251 (data->pestB[i] >> 63) == 0) 281 (data->pestB[i] >> 63) == 0)
252 continue; 282 continue;
253 283
254 pr_info(" PE[%3d] PESTA: %016llx\n", i, data->pestA[i]); 284 pr_info(" PE[%3d] A/B: %016llx %016llx\n",
255 pr_info(" PESTB: %016llx\n", data->pestB[i]); 285 i, data->pestA[i], data->pestB[i]);
256 } 286 }
257} 287}
258 288
@@ -634,6 +664,16 @@ static void pnv_pci_dma_dev_setup(struct pci_dev *pdev)
634 pnv_pci_dma_fallback_setup(hose, pdev); 664 pnv_pci_dma_fallback_setup(hose, pdev);
635} 665}
636 666
667int pnv_pci_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
668{
669 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
670 struct pnv_phb *phb = hose->private_data;
671
672 if (phb && phb->dma_set_mask)
673 return phb->dma_set_mask(phb, pdev, dma_mask);
674 return __dma_set_mask(&pdev->dev, dma_mask);
675}
676
637void pnv_pci_shutdown(void) 677void pnv_pci_shutdown(void)
638{ 678{
639 struct pci_controller *hose; 679 struct pci_controller *hose;
diff --git a/arch/powerpc/platforms/powernv/pci.h b/arch/powerpc/platforms/powernv/pci.h
index 13f1942a9a5f..cde169442775 100644
--- a/arch/powerpc/platforms/powernv/pci.h
+++ b/arch/powerpc/platforms/powernv/pci.h
@@ -54,7 +54,9 @@ struct pnv_ioda_pe {
54 struct iommu_table tce32_table; 54 struct iommu_table tce32_table;
55 phys_addr_t tce_inval_reg_phys; 55 phys_addr_t tce_inval_reg_phys;
56 56
57 /* XXX TODO: Add support for additional 64-bit iommus */ 57 /* 64-bit TCE bypass region */
58 bool tce_bypass_enabled;
59 uint64_t tce_bypass_base;
58 60
59 /* MSIs. MVE index is identical for for 32 and 64 bit MSI 61 /* MSIs. MVE index is identical for for 32 and 64 bit MSI
60 * and -1 if not supported. (It's actually identical to the 62 * and -1 if not supported. (It's actually identical to the
@@ -113,6 +115,8 @@ struct pnv_phb {
113 unsigned int hwirq, unsigned int virq, 115 unsigned int hwirq, unsigned int virq,
114 unsigned int is_64, struct msi_msg *msg); 116 unsigned int is_64, struct msi_msg *msg);
115 void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev); 117 void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
118 int (*dma_set_mask)(struct pnv_phb *phb, struct pci_dev *pdev,
119 u64 dma_mask);
116 void (*fixup_phb)(struct pci_controller *hose); 120 void (*fixup_phb)(struct pci_controller *hose);
117 u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn); 121 u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
118 void (*shutdown)(struct pnv_phb *phb); 122 void (*shutdown)(struct pnv_phb *phb);
diff --git a/arch/powerpc/platforms/powernv/powernv.h b/arch/powerpc/platforms/powernv/powernv.h
index de6819be1f95..0051e108ef0f 100644
--- a/arch/powerpc/platforms/powernv/powernv.h
+++ b/arch/powerpc/platforms/powernv/powernv.h
@@ -7,12 +7,20 @@ extern void pnv_smp_init(void);
7static inline void pnv_smp_init(void) { } 7static inline void pnv_smp_init(void) { }
8#endif 8#endif
9 9
10struct pci_dev;
11
10#ifdef CONFIG_PCI 12#ifdef CONFIG_PCI
11extern void pnv_pci_init(void); 13extern void pnv_pci_init(void);
12extern void pnv_pci_shutdown(void); 14extern void pnv_pci_shutdown(void);
15extern int pnv_pci_dma_set_mask(struct pci_dev *pdev, u64 dma_mask);
13#else 16#else
14static inline void pnv_pci_init(void) { } 17static inline void pnv_pci_init(void) { }
15static inline void pnv_pci_shutdown(void) { } 18static inline void pnv_pci_shutdown(void) { }
19
20static inline int pnv_pci_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
21{
22 return -ENODEV;
23}
16#endif 24#endif
17 25
18extern void pnv_lpc_init(void); 26extern void pnv_lpc_init(void);
diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c
index 21166f65c97c..81a7a0a79be7 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -26,7 +26,7 @@
26#include <linux/of_fdt.h> 26#include <linux/of_fdt.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/bug.h> 28#include <linux/bug.h>
29#include <linux/cpuidle.h> 29#include <linux/pci.h>
30 30
31#include <asm/machdep.h> 31#include <asm/machdep.h>
32#include <asm/firmware.h> 32#include <asm/firmware.h>
@@ -141,6 +141,13 @@ static void pnv_progress(char *s, unsigned short hex)
141{ 141{
142} 142}
143 143
144static int pnv_dma_set_mask(struct device *dev, u64 dma_mask)
145{
146 if (dev_is_pci(dev))
147 return pnv_pci_dma_set_mask(to_pci_dev(dev), dma_mask);
148 return __dma_set_mask(dev, dma_mask);
149}
150
144static void pnv_shutdown(void) 151static void pnv_shutdown(void)
145{ 152{
146 /* Let the PCI code clear up IODA tables */ 153 /* Let the PCI code clear up IODA tables */
@@ -217,16 +224,6 @@ static int __init pnv_probe(void)
217 return 1; 224 return 1;
218} 225}
219 226
220void powernv_idle(void)
221{
222 /* Hook to cpuidle framework if available, else
223 * call on default platform idle code
224 */
225 if (cpuidle_idle_call()) {
226 power7_idle();
227 }
228}
229
230define_machine(powernv) { 227define_machine(powernv) {
231 .name = "PowerNV", 228 .name = "PowerNV",
232 .probe = pnv_probe, 229 .probe = pnv_probe,
@@ -236,8 +233,9 @@ define_machine(powernv) {
236 .show_cpuinfo = pnv_show_cpuinfo, 233 .show_cpuinfo = pnv_show_cpuinfo,
237 .progress = pnv_progress, 234 .progress = pnv_progress,
238 .machine_shutdown = pnv_shutdown, 235 .machine_shutdown = pnv_shutdown,
239 .power_save = powernv_idle, 236 .power_save = power7_idle,
240 .calibrate_decr = generic_calibrate_decr, 237 .calibrate_decr = generic_calibrate_decr,
238 .dma_set_mask = pnv_dma_set_mask,
241#ifdef CONFIG_KEXEC 239#ifdef CONFIG_KEXEC
242 .kexec_cpu_down = pnv_kexec_cpu_down, 240 .kexec_cpu_down = pnv_kexec_cpu_down,
243#endif 241#endif
diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
index 37300f6ee244..80b1d57c306a 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -20,6 +20,7 @@ config PPC_PSERIES
20 select PPC_DOORBELL 20 select PPC_DOORBELL
21 select HAVE_CONTEXT_TRACKING 21 select HAVE_CONTEXT_TRACKING
22 select HOTPLUG_CPU if SMP 22 select HOTPLUG_CPU if SMP
23 select ARCH_RANDOM
23 default y 24 default y
24 25
25config PPC_SPLPAR 26config PPC_SPLPAR
diff --git a/arch/powerpc/platforms/pseries/eeh_pseries.c b/arch/powerpc/platforms/pseries/eeh_pseries.c
index 9ef3cc8ebc11..8a8f0472d98f 100644
--- a/arch/powerpc/platforms/pseries/eeh_pseries.c
+++ b/arch/powerpc/platforms/pseries/eeh_pseries.c
@@ -265,7 +265,7 @@ static void *pseries_eeh_of_probe(struct device_node *dn, void *flag)
265 enable = 1; 265 enable = 1;
266 266
267 if (enable) { 267 if (enable) {
268 eeh_subsystem_enabled = 1; 268 eeh_set_enable(true);
269 eeh_add_to_parent_pe(edev); 269 eeh_add_to_parent_pe(edev);
270 270
271 pr_debug("%s: EEH enabled on %s PHB#%d-PE#%x, config addr#%x\n", 271 pr_debug("%s: EEH enabled on %s PHB#%d-PE#%x, config addr#%x\n",
diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index 82789e79e539..0ea99e3d4815 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -35,12 +35,7 @@
35#include "offline_states.h" 35#include "offline_states.h"
36 36
37/* This version can't take the spinlock, because it never returns */ 37/* This version can't take the spinlock, because it never returns */
38static struct rtas_args rtas_stop_self_args = { 38static int rtas_stop_self_token = RTAS_UNKNOWN_SERVICE;
39 .token = RTAS_UNKNOWN_SERVICE,
40 .nargs = 0,
41 .nret = 1,
42 .rets = &rtas_stop_self_args.args[0],
43};
44 39
45static DEFINE_PER_CPU(enum cpu_state_vals, preferred_offline_state) = 40static DEFINE_PER_CPU(enum cpu_state_vals, preferred_offline_state) =
46 CPU_STATE_OFFLINE; 41 CPU_STATE_OFFLINE;
@@ -93,15 +88,20 @@ void set_default_offline_state(int cpu)
93 88
94static void rtas_stop_self(void) 89static void rtas_stop_self(void)
95{ 90{
96 struct rtas_args *args = &rtas_stop_self_args; 91 struct rtas_args args = {
92 .token = cpu_to_be32(rtas_stop_self_token),
93 .nargs = 0,
94 .nret = 1,
95 .rets = &args.args[0],
96 };
97 97
98 local_irq_disable(); 98 local_irq_disable();
99 99
100 BUG_ON(args->token == RTAS_UNKNOWN_SERVICE); 100 BUG_ON(rtas_stop_self_token == RTAS_UNKNOWN_SERVICE);
101 101
102 printk("cpu %u (hwid %u) Ready to die...\n", 102 printk("cpu %u (hwid %u) Ready to die...\n",
103 smp_processor_id(), hard_smp_processor_id()); 103 smp_processor_id(), hard_smp_processor_id());
104 enter_rtas(__pa(args)); 104 enter_rtas(__pa(&args));
105 105
106 panic("Alas, I survived.\n"); 106 panic("Alas, I survived.\n");
107} 107}
@@ -392,10 +392,10 @@ static int __init pseries_cpu_hotplug_init(void)
392 } 392 }
393 } 393 }
394 394
395 rtas_stop_self_args.token = rtas_token("stop-self"); 395 rtas_stop_self_token = rtas_token("stop-self");
396 qcss_tok = rtas_token("query-cpu-stopped-state"); 396 qcss_tok = rtas_token("query-cpu-stopped-state");
397 397
398 if (rtas_stop_self_args.token == RTAS_UNKNOWN_SERVICE || 398 if (rtas_stop_self_token == RTAS_UNKNOWN_SERVICE ||
399 qcss_tok == RTAS_UNKNOWN_SERVICE) { 399 qcss_tok == RTAS_UNKNOWN_SERVICE) {
400 printk(KERN_INFO "CPU Hotplug not supported by firmware " 400 printk(KERN_INFO "CPU Hotplug not supported by firmware "
401 "- disabling.\n"); 401 "- disabling.\n");
diff --git a/arch/powerpc/platforms/pseries/pci.c b/arch/powerpc/platforms/pseries/pci.c
index 70670a2d9cf2..c413ec158ff5 100644
--- a/arch/powerpc/platforms/pseries/pci.c
+++ b/arch/powerpc/platforms/pseries/pci.c
@@ -113,7 +113,8 @@ int pseries_root_bridge_prepare(struct pci_host_bridge *bridge)
113{ 113{
114 struct device_node *dn, *pdn; 114 struct device_node *dn, *pdn;
115 struct pci_bus *bus; 115 struct pci_bus *bus;
116 const __be32 *pcie_link_speed_stats; 116 u32 pcie_link_speed_stats[2];
117 int rc;
117 118
118 bus = bridge->bus; 119 bus = bridge->bus;
119 120
@@ -122,38 +123,45 @@ int pseries_root_bridge_prepare(struct pci_host_bridge *bridge)
122 return 0; 123 return 0;
123 124
124 for (pdn = dn; pdn != NULL; pdn = of_get_next_parent(pdn)) { 125 for (pdn = dn; pdn != NULL; pdn = of_get_next_parent(pdn)) {
125 pcie_link_speed_stats = of_get_property(pdn, 126 rc = of_property_read_u32_array(pdn,
126 "ibm,pcie-link-speed-stats", NULL); 127 "ibm,pcie-link-speed-stats",
127 if (pcie_link_speed_stats) 128 &pcie_link_speed_stats[0], 2);
129 if (!rc)
128 break; 130 break;
129 } 131 }
130 132
131 of_node_put(pdn); 133 of_node_put(pdn);
132 134
133 if (!pcie_link_speed_stats) { 135 if (rc) {
134 pr_err("no ibm,pcie-link-speed-stats property\n"); 136 pr_err("no ibm,pcie-link-speed-stats property\n");
135 return 0; 137 return 0;
136 } 138 }
137 139
138 switch (be32_to_cpup(pcie_link_speed_stats)) { 140 switch (pcie_link_speed_stats[0]) {
139 case 0x01: 141 case 0x01:
140 bus->max_bus_speed = PCIE_SPEED_2_5GT; 142 bus->max_bus_speed = PCIE_SPEED_2_5GT;
141 break; 143 break;
142 case 0x02: 144 case 0x02:
143 bus->max_bus_speed = PCIE_SPEED_5_0GT; 145 bus->max_bus_speed = PCIE_SPEED_5_0GT;
144 break; 146 break;
147 case 0x04:
148 bus->max_bus_speed = PCIE_SPEED_8_0GT;
149 break;
145 default: 150 default:
146 bus->max_bus_speed = PCI_SPEED_UNKNOWN; 151 bus->max_bus_speed = PCI_SPEED_UNKNOWN;
147 break; 152 break;
148 } 153 }
149 154
150 switch (be32_to_cpup(pcie_link_speed_stats)) { 155 switch (pcie_link_speed_stats[1]) {
151 case 0x01: 156 case 0x01:
152 bus->cur_bus_speed = PCIE_SPEED_2_5GT; 157 bus->cur_bus_speed = PCIE_SPEED_2_5GT;
153 break; 158 break;
154 case 0x02: 159 case 0x02:
155 bus->cur_bus_speed = PCIE_SPEED_5_0GT; 160 bus->cur_bus_speed = PCIE_SPEED_5_0GT;
156 break; 161 break;
162 case 0x04:
163 bus->cur_bus_speed = PCIE_SPEED_8_0GT;
164 break;
157 default: 165 default:
158 bus->cur_bus_speed = PCI_SPEED_UNKNOWN; 166 bus->cur_bus_speed = PCI_SPEED_UNKNOWN;
159 break; 167 break;
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 8e639d7cbda7..2db8cc691bf4 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -39,7 +39,6 @@
39#include <linux/irq.h> 39#include <linux/irq.h>
40#include <linux/seq_file.h> 40#include <linux/seq_file.h>
41#include <linux/root_dev.h> 41#include <linux/root_dev.h>
42#include <linux/cpuidle.h>
43#include <linux/of.h> 42#include <linux/of.h>
44#include <linux/kexec.h> 43#include <linux/kexec.h>
45 44
@@ -356,29 +355,24 @@ early_initcall(alloc_dispatch_log_kmem_cache);
356 355
357static void pseries_lpar_idle(void) 356static void pseries_lpar_idle(void)
358{ 357{
359 /* This would call on the cpuidle framework, and the back-end pseries 358 /*
360 * driver to go to idle states 359 * Default handler to go into low thread priority and possibly
360 * low power mode by cedeing processor to hypervisor
361 */ 361 */
362 if (cpuidle_idle_call()) {
363 /* On error, execute default handler
364 * to go into low thread priority and possibly
365 * low power mode by cedeing processor to hypervisor
366 */
367 362
368 /* Indicate to hypervisor that we are idle. */ 363 /* Indicate to hypervisor that we are idle. */
369 get_lppaca()->idle = 1; 364 get_lppaca()->idle = 1;
370 365
371 /* 366 /*
372 * Yield the processor to the hypervisor. We return if 367 * Yield the processor to the hypervisor. We return if
373 * an external interrupt occurs (which are driven prior 368 * an external interrupt occurs (which are driven prior
374 * to returning here) or if a prod occurs from another 369 * to returning here) or if a prod occurs from another
375 * processor. When returning here, external interrupts 370 * processor. When returning here, external interrupts
376 * are enabled. 371 * are enabled.
377 */ 372 */
378 cede_processor(); 373 cede_processor();
379 374
380 get_lppaca()->idle = 0; 375 get_lppaca()->idle = 0;
381 }
382} 376}
383 377
384/* 378/*
@@ -430,8 +424,7 @@ static void pSeries_machine_kexec(struct kimage *image)
430{ 424{
431 long rc; 425 long rc;
432 426
433 if (firmware_has_feature(FW_FEATURE_SET_MODE) && 427 if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
434 (image->type != KEXEC_TYPE_CRASH)) {
435 rc = pSeries_disable_reloc_on_exc(); 428 rc = pSeries_disable_reloc_on_exc();
436 if (rc != H_SUCCESS) 429 if (rc != H_SUCCESS)
437 pr_warning("Warning: Failed to disable relocation on " 430 pr_warning("Warning: Failed to disable relocation on "
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 0e166ed4cd16..8209744b2829 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -886,25 +886,25 @@ int mpic_set_irq_type(struct irq_data *d, unsigned int flow_type)
886 886
887 /* Default: read HW settings */ 887 /* Default: read HW settings */
888 if (flow_type == IRQ_TYPE_DEFAULT) { 888 if (flow_type == IRQ_TYPE_DEFAULT) {
889 switch(vold & (MPIC_INFO(VECPRI_POLARITY_MASK) | 889 int vold_ps;
890 MPIC_INFO(VECPRI_SENSE_MASK))) { 890
891 case MPIC_INFO(VECPRI_SENSE_EDGE) | 891 vold_ps = vold & (MPIC_INFO(VECPRI_POLARITY_MASK) |
892 MPIC_INFO(VECPRI_POLARITY_POSITIVE): 892 MPIC_INFO(VECPRI_SENSE_MASK));
893 flow_type = IRQ_TYPE_EDGE_RISING; 893
894 break; 894 if (vold_ps == (MPIC_INFO(VECPRI_SENSE_EDGE) |
895 case MPIC_INFO(VECPRI_SENSE_EDGE) | 895 MPIC_INFO(VECPRI_POLARITY_POSITIVE)))
896 MPIC_INFO(VECPRI_POLARITY_NEGATIVE): 896 flow_type = IRQ_TYPE_EDGE_RISING;
897 flow_type = IRQ_TYPE_EDGE_FALLING; 897 else if (vold_ps == (MPIC_INFO(VECPRI_SENSE_EDGE) |
898 break; 898 MPIC_INFO(VECPRI_POLARITY_NEGATIVE)))
899 case MPIC_INFO(VECPRI_SENSE_LEVEL) | 899 flow_type = IRQ_TYPE_EDGE_FALLING;
900 MPIC_INFO(VECPRI_POLARITY_POSITIVE): 900 else if (vold_ps == (MPIC_INFO(VECPRI_SENSE_LEVEL) |
901 flow_type = IRQ_TYPE_LEVEL_HIGH; 901 MPIC_INFO(VECPRI_POLARITY_POSITIVE)))
902 break; 902 flow_type = IRQ_TYPE_LEVEL_HIGH;
903 case MPIC_INFO(VECPRI_SENSE_LEVEL) | 903 else if (vold_ps == (MPIC_INFO(VECPRI_SENSE_LEVEL) |
904 MPIC_INFO(VECPRI_POLARITY_NEGATIVE): 904 MPIC_INFO(VECPRI_POLARITY_NEGATIVE)))
905 flow_type = IRQ_TYPE_LEVEL_LOW; 905 flow_type = IRQ_TYPE_LEVEL_LOW;
906 break; 906 else
907 } 907 WARN_ONCE(1, "mpic: unknown IRQ type %d\n", vold);
908 } 908 }
909 909
910 /* Apply to irq desc */ 910 /* Apply to irq desc */
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index a90731b3d44a..b07909850f77 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -309,16 +309,23 @@ static void get_output_lock(void)
309 309
310 if (xmon_speaker == me) 310 if (xmon_speaker == me)
311 return; 311 return;
312
312 for (;;) { 313 for (;;) {
313 if (xmon_speaker == 0) { 314 last_speaker = cmpxchg(&xmon_speaker, 0, me);
314 last_speaker = cmpxchg(&xmon_speaker, 0, me); 315 if (last_speaker == 0)
315 if (last_speaker == 0) 316 return;
316 return; 317
317 } 318 /*
318 timeout = 10000000; 319 * Wait a full second for the lock, we might be on a slow
320 * console, but check every 100us.
321 */
322 timeout = 10000;
319 while (xmon_speaker == last_speaker) { 323 while (xmon_speaker == last_speaker) {
320 if (--timeout > 0) 324 if (--timeout > 0) {
325 udelay(100);
321 continue; 326 continue;
327 }
328
322 /* hostile takeover */ 329 /* hostile takeover */
323 prev = cmpxchg(&xmon_speaker, last_speaker, me); 330 prev = cmpxchg(&xmon_speaker, last_speaker, me);
324 if (prev == last_speaker) 331 if (prev == last_speaker)
@@ -397,7 +404,6 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
397 } 404 }
398 405
399 xmon_fault_jmp[cpu] = recurse_jmp; 406 xmon_fault_jmp[cpu] = recurse_jmp;
400 cpumask_set_cpu(cpu, &cpus_in_xmon);
401 407
402 bp = NULL; 408 bp = NULL;
403 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT)) 409 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT))
@@ -419,6 +425,8 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
419 release_output_lock(); 425 release_output_lock();
420 } 426 }
421 427
428 cpumask_set_cpu(cpu, &cpus_in_xmon);
429
422 waiting: 430 waiting:
423 secondary = 1; 431 secondary = 1;
424 while (secondary && !xmon_gate) { 432 while (secondary && !xmon_gate) {
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 65a07750f4f9..953f17c8d17c 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -117,6 +117,7 @@ config S390
117 select HAVE_FUNCTION_GRAPH_TRACER 117 select HAVE_FUNCTION_GRAPH_TRACER
118 select HAVE_FUNCTION_TRACER 118 select HAVE_FUNCTION_TRACER
119 select HAVE_FUNCTION_TRACE_MCOUNT_TEST 119 select HAVE_FUNCTION_TRACE_MCOUNT_TEST
120 select HAVE_FUTEX_CMPXCHG if FUTEX
120 select HAVE_KERNEL_BZIP2 121 select HAVE_KERNEL_BZIP2
121 select HAVE_KERNEL_GZIP 122 select HAVE_KERNEL_GZIP
122 select HAVE_KERNEL_LZ4 123 select HAVE_KERNEL_LZ4
@@ -140,6 +141,7 @@ config S390
140 select OLD_SIGACTION 141 select OLD_SIGACTION
141 select OLD_SIGSUSPEND3 142 select OLD_SIGSUSPEND3
142 select SYSCTL_EXCEPTION_TRACE 143 select SYSCTL_EXCEPTION_TRACE
144 select TTY
143 select VIRT_CPU_ACCOUNTING 145 select VIRT_CPU_ACCOUNTING
144 select VIRT_TO_BUS 146 select VIRT_TO_BUS
145 147
@@ -415,6 +417,10 @@ config ARCH_ENABLE_MEMORY_HOTPLUG
415config ARCH_ENABLE_MEMORY_HOTREMOVE 417config ARCH_ENABLE_MEMORY_HOTREMOVE
416 def_bool y 418 def_bool y
417 419
420config ARCH_ENABLE_SPLIT_PMD_PTLOCK
421 def_bool y
422 depends on 64BIT
423
418config FORCE_MAX_ZONEORDER 424config FORCE_MAX_ZONEORDER
419 int 425 int
420 default "9" 426 default "9"
diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c
index 4c4a1cef5208..47c8630c93cd 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -529,6 +529,7 @@ static int __init appldata_init(void)
529{ 529{
530 int rc; 530 int rc;
531 531
532 init_virt_timer(&appldata_timer);
532 appldata_timer.function = appldata_timer_function; 533 appldata_timer.function = appldata_timer_function;
533 appldata_timer.data = (unsigned long) &appldata_work; 534 appldata_timer.data = (unsigned long) &appldata_work;
534 535
diff --git a/arch/s390/appldata/appldata_os.c b/arch/s390/appldata/appldata_os.c
index de8e2b3b0180..69b23b25ac34 100644
--- a/arch/s390/appldata/appldata_os.c
+++ b/arch/s390/appldata/appldata_os.c
@@ -171,7 +171,7 @@ static int __init appldata_os_init(void)
171 int rc, max_size; 171 int rc, max_size;
172 172
173 max_size = sizeof(struct appldata_os_data) + 173 max_size = sizeof(struct appldata_os_data) +
174 (NR_CPUS * sizeof(struct appldata_os_per_cpu)); 174 (num_possible_cpus() * sizeof(struct appldata_os_per_cpu));
175 if (max_size > APPLDATA_MAX_REC_SIZE) { 175 if (max_size > APPLDATA_MAX_REC_SIZE) {
176 pr_err("Maximum OS record size %i exceeds the maximum " 176 pr_err("Maximum OS record size %i exceeds the maximum "
177 "record size %i\n", max_size, APPLDATA_MAX_REC_SIZE); 177 "record size %i\n", max_size, APPLDATA_MAX_REC_SIZE);
diff --git a/arch/s390/configs/default_defconfig b/arch/s390/configs/default_defconfig
index e0af2ee58751..ddaae2f5c913 100644
--- a/arch/s390/configs/default_defconfig
+++ b/arch/s390/configs/default_defconfig
@@ -46,6 +46,7 @@ CONFIG_UNIXWARE_DISKLABEL=y
46CONFIG_CFQ_GROUP_IOSCHED=y 46CONFIG_CFQ_GROUP_IOSCHED=y
47CONFIG_DEFAULT_DEADLINE=y 47CONFIG_DEFAULT_DEADLINE=y
48CONFIG_MARCH_Z9_109=y 48CONFIG_MARCH_Z9_109=y
49CONFIG_NR_CPUS=256
49CONFIG_PREEMPT=y 50CONFIG_PREEMPT=y
50CONFIG_HZ_100=y 51CONFIG_HZ_100=y
51CONFIG_MEMORY_HOTPLUG=y 52CONFIG_MEMORY_HOTPLUG=y
@@ -58,7 +59,6 @@ CONFIG_HOTPLUG_PCI=y
58CONFIG_HOTPLUG_PCI_S390=y 59CONFIG_HOTPLUG_PCI_S390=y
59CONFIG_CHSC_SCH=y 60CONFIG_CHSC_SCH=y
60CONFIG_CRASH_DUMP=y 61CONFIG_CRASH_DUMP=y
61CONFIG_ZFCPDUMP=y
62# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set 62# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
63CONFIG_BINFMT_MISC=m 63CONFIG_BINFMT_MISC=m
64CONFIG_HIBERNATION=y 64CONFIG_HIBERNATION=y
@@ -101,7 +101,6 @@ CONFIG_TCP_CONG_VENO=m
101CONFIG_TCP_CONG_YEAH=m 101CONFIG_TCP_CONG_YEAH=m
102CONFIG_TCP_CONG_ILLINOIS=m 102CONFIG_TCP_CONG_ILLINOIS=m
103CONFIG_IPV6=y 103CONFIG_IPV6=y
104CONFIG_IPV6_PRIVACY=y
105CONFIG_IPV6_ROUTER_PREF=y 104CONFIG_IPV6_ROUTER_PREF=y
106CONFIG_INET6_AH=m 105CONFIG_INET6_AH=m
107CONFIG_INET6_ESP=m 106CONFIG_INET6_ESP=m
@@ -111,6 +110,7 @@ CONFIG_INET6_XFRM_MODE_TRANSPORT=m
111CONFIG_INET6_XFRM_MODE_TUNNEL=m 110CONFIG_INET6_XFRM_MODE_TUNNEL=m
112CONFIG_INET6_XFRM_MODE_BEET=m 111CONFIG_INET6_XFRM_MODE_BEET=m
113CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m 112CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m
113CONFIG_IPV6_VTI=m
114CONFIG_IPV6_SIT=m 114CONFIG_IPV6_SIT=m
115CONFIG_IPV6_GRE=m 115CONFIG_IPV6_GRE=m
116CONFIG_IPV6_MULTIPLE_TABLES=y 116CONFIG_IPV6_MULTIPLE_TABLES=y
@@ -135,7 +135,17 @@ CONFIG_NF_CONNTRACK_SIP=m
135CONFIG_NF_CONNTRACK_TFTP=m 135CONFIG_NF_CONNTRACK_TFTP=m
136CONFIG_NF_CT_NETLINK=m 136CONFIG_NF_CT_NETLINK=m
137CONFIG_NF_CT_NETLINK_TIMEOUT=m 137CONFIG_NF_CT_NETLINK_TIMEOUT=m
138CONFIG_NETFILTER_TPROXY=m 138CONFIG_NF_TABLES=m
139CONFIG_NFT_EXTHDR=m
140CONFIG_NFT_META=m
141CONFIG_NFT_CT=m
142CONFIG_NFT_RBTREE=m
143CONFIG_NFT_HASH=m
144CONFIG_NFT_COUNTER=m
145CONFIG_NFT_LOG=m
146CONFIG_NFT_LIMIT=m
147CONFIG_NFT_NAT=m
148CONFIG_NFT_COMPAT=m
139CONFIG_NETFILTER_XT_SET=m 149CONFIG_NETFILTER_XT_SET=m
140CONFIG_NETFILTER_XT_TARGET_AUDIT=m 150CONFIG_NETFILTER_XT_TARGET_AUDIT=m
141CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 151CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -204,7 +214,9 @@ CONFIG_IP_SET_HASH_IP=m
204CONFIG_IP_SET_HASH_IPPORT=m 214CONFIG_IP_SET_HASH_IPPORT=m
205CONFIG_IP_SET_HASH_IPPORTIP=m 215CONFIG_IP_SET_HASH_IPPORTIP=m
206CONFIG_IP_SET_HASH_IPPORTNET=m 216CONFIG_IP_SET_HASH_IPPORTNET=m
217CONFIG_IP_SET_HASH_NETPORTNET=m
207CONFIG_IP_SET_HASH_NET=m 218CONFIG_IP_SET_HASH_NET=m
219CONFIG_IP_SET_HASH_NETNET=m
208CONFIG_IP_SET_HASH_NETPORT=m 220CONFIG_IP_SET_HASH_NETPORT=m
209CONFIG_IP_SET_HASH_NETIFACE=m 221CONFIG_IP_SET_HASH_NETIFACE=m
210CONFIG_IP_SET_LIST_SET=m 222CONFIG_IP_SET_LIST_SET=m
@@ -227,6 +239,11 @@ CONFIG_IP_VS_FTP=m
227CONFIG_IP_VS_PE_SIP=m 239CONFIG_IP_VS_PE_SIP=m
228CONFIG_NF_CONNTRACK_IPV4=m 240CONFIG_NF_CONNTRACK_IPV4=m
229# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set 241# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set
242CONFIG_NF_TABLES_IPV4=m
243CONFIG_NFT_REJECT_IPV4=m
244CONFIG_NFT_CHAIN_ROUTE_IPV4=m
245CONFIG_NFT_CHAIN_NAT_IPV4=m
246CONFIG_NF_TABLES_ARP=m
230CONFIG_IP_NF_IPTABLES=m 247CONFIG_IP_NF_IPTABLES=m
231CONFIG_IP_NF_MATCH_AH=m 248CONFIG_IP_NF_MATCH_AH=m
232CONFIG_IP_NF_MATCH_ECN=m 249CONFIG_IP_NF_MATCH_ECN=m
@@ -249,6 +266,9 @@ CONFIG_IP_NF_ARPTABLES=m
249CONFIG_IP_NF_ARPFILTER=m 266CONFIG_IP_NF_ARPFILTER=m
250CONFIG_IP_NF_ARP_MANGLE=m 267CONFIG_IP_NF_ARP_MANGLE=m
251CONFIG_NF_CONNTRACK_IPV6=m 268CONFIG_NF_CONNTRACK_IPV6=m
269CONFIG_NF_TABLES_IPV6=m
270CONFIG_NFT_CHAIN_ROUTE_IPV6=m
271CONFIG_NFT_CHAIN_NAT_IPV6=m
252CONFIG_IP6_NF_IPTABLES=m 272CONFIG_IP6_NF_IPTABLES=m
253CONFIG_IP6_NF_MATCH_AH=m 273CONFIG_IP6_NF_MATCH_AH=m
254CONFIG_IP6_NF_MATCH_EUI64=m 274CONFIG_IP6_NF_MATCH_EUI64=m
@@ -268,6 +288,7 @@ CONFIG_IP6_NF_SECURITY=m
268CONFIG_NF_NAT_IPV6=m 288CONFIG_NF_NAT_IPV6=m
269CONFIG_IP6_NF_TARGET_MASQUERADE=m 289CONFIG_IP6_NF_TARGET_MASQUERADE=m
270CONFIG_IP6_NF_TARGET_NPT=m 290CONFIG_IP6_NF_TARGET_NPT=m
291CONFIG_NF_TABLES_BRIDGE=m
271CONFIG_NET_SCTPPROBE=m 292CONFIG_NET_SCTPPROBE=m
272CONFIG_RDS=m 293CONFIG_RDS=m
273CONFIG_RDS_RDMA=m 294CONFIG_RDS_RDMA=m
@@ -314,6 +335,7 @@ CONFIG_NET_CLS_RSVP=m
314CONFIG_NET_CLS_RSVP6=m 335CONFIG_NET_CLS_RSVP6=m
315CONFIG_NET_CLS_FLOW=m 336CONFIG_NET_CLS_FLOW=m
316CONFIG_NET_CLS_CGROUP=y 337CONFIG_NET_CLS_CGROUP=y
338CONFIG_NET_CLS_BPF=m
317CONFIG_NET_CLS_ACT=y 339CONFIG_NET_CLS_ACT=y
318CONFIG_NET_ACT_POLICE=m 340CONFIG_NET_ACT_POLICE=m
319CONFIG_NET_ACT_GACT=m 341CONFIG_NET_ACT_GACT=m
@@ -381,8 +403,8 @@ CONFIG_BLK_DEV_DM=m
381CONFIG_DM_CRYPT=m 403CONFIG_DM_CRYPT=m
382CONFIG_DM_SNAPSHOT=m 404CONFIG_DM_SNAPSHOT=m
383CONFIG_DM_MIRROR=m 405CONFIG_DM_MIRROR=m
384CONFIG_DM_RAID=m
385CONFIG_DM_LOG_USERSPACE=m 406CONFIG_DM_LOG_USERSPACE=m
407CONFIG_DM_RAID=m
386CONFIG_DM_ZERO=m 408CONFIG_DM_ZERO=m
387CONFIG_DM_MULTIPATH=m 409CONFIG_DM_MULTIPATH=m
388CONFIG_DM_MULTIPATH_QL=m 410CONFIG_DM_MULTIPATH_QL=m
@@ -434,7 +456,6 @@ CONFIG_TN3270_FS=y
434CONFIG_WATCHDOG=y 456CONFIG_WATCHDOG=y
435CONFIG_WATCHDOG_NOWAYOUT=y 457CONFIG_WATCHDOG_NOWAYOUT=y
436CONFIG_SOFT_WATCHDOG=m 458CONFIG_SOFT_WATCHDOG=m
437CONFIG_ZVM_WATCHDOG=m
438# CONFIG_HID is not set 459# CONFIG_HID is not set
439# CONFIG_USB_SUPPORT is not set 460# CONFIG_USB_SUPPORT is not set
440CONFIG_INFINIBAND=m 461CONFIG_INFINIBAND=m
@@ -534,13 +555,23 @@ CONFIG_UNUSED_SYMBOLS=y
534CONFIG_MAGIC_SYSRQ=y 555CONFIG_MAGIC_SYSRQ=y
535CONFIG_DEBUG_KERNEL=y 556CONFIG_DEBUG_KERNEL=y
536CONFIG_DEBUG_PAGEALLOC=y 557CONFIG_DEBUG_PAGEALLOC=y
558CONFIG_DEBUG_OBJECTS=y
559CONFIG_DEBUG_OBJECTS_SELFTEST=y
560CONFIG_DEBUG_OBJECTS_FREE=y
561CONFIG_DEBUG_OBJECTS_TIMERS=y
562CONFIG_DEBUG_OBJECTS_WORK=y
563CONFIG_DEBUG_OBJECTS_RCU_HEAD=y
564CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER=y
537CONFIG_SLUB_DEBUG_ON=y 565CONFIG_SLUB_DEBUG_ON=y
538CONFIG_SLUB_STATS=y 566CONFIG_SLUB_STATS=y
567CONFIG_DEBUG_KMEMLEAK=y
539CONFIG_DEBUG_STACK_USAGE=y 568CONFIG_DEBUG_STACK_USAGE=y
540CONFIG_DEBUG_VM=y 569CONFIG_DEBUG_VM=y
541CONFIG_DEBUG_VM_RB=y 570CONFIG_DEBUG_VM_RB=y
542CONFIG_MEMORY_NOTIFIER_ERROR_INJECT=m 571CONFIG_MEMORY_NOTIFIER_ERROR_INJECT=m
543CONFIG_DEBUG_PER_CPU_MAPS=y 572CONFIG_DEBUG_PER_CPU_MAPS=y
573CONFIG_DEBUG_SHIRQ=y
574CONFIG_DETECT_HUNG_TASK=y
544CONFIG_TIMER_STATS=y 575CONFIG_TIMER_STATS=y
545CONFIG_DEBUG_RT_MUTEXES=y 576CONFIG_DEBUG_RT_MUTEXES=y
546CONFIG_RT_MUTEX_TESTER=y 577CONFIG_RT_MUTEX_TESTER=y
@@ -573,9 +604,11 @@ CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y
573CONFIG_BLK_DEV_IO_TRACE=y 604CONFIG_BLK_DEV_IO_TRACE=y
574# CONFIG_KPROBE_EVENT is not set 605# CONFIG_KPROBE_EVENT is not set
575CONFIG_LKDTM=m 606CONFIG_LKDTM=m
607CONFIG_TEST_LIST_SORT=y
576CONFIG_KPROBES_SANITY_TEST=y 608CONFIG_KPROBES_SANITY_TEST=y
577CONFIG_RBTREE_TEST=m 609CONFIG_RBTREE_TEST=y
578CONFIG_INTERVAL_TREE_TEST=m 610CONFIG_INTERVAL_TREE_TEST=m
611CONFIG_PERCPU_TEST=m
579CONFIG_ATOMIC64_SELFTEST=y 612CONFIG_ATOMIC64_SELFTEST=y
580CONFIG_DMA_API_DEBUG=y 613CONFIG_DMA_API_DEBUG=y
581# CONFIG_STRICT_DEVMEM is not set 614# CONFIG_STRICT_DEVMEM is not set
@@ -638,7 +671,6 @@ CONFIG_CRYPTO_AES_S390=m
638CONFIG_CRYPTO_GHASH_S390=m 671CONFIG_CRYPTO_GHASH_S390=m
639CONFIG_ASYMMETRIC_KEY_TYPE=m 672CONFIG_ASYMMETRIC_KEY_TYPE=m
640CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m 673CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m
641CONFIG_PUBLIC_KEY_ALGO_RSA=m
642CONFIG_X509_CERTIFICATE_PARSER=m 674CONFIG_X509_CERTIFICATE_PARSER=m
643CONFIG_CRC7=m 675CONFIG_CRC7=m
644CONFIG_CRC8=m 676CONFIG_CRC8=m
diff --git a/arch/s390/configs/gcov_defconfig b/arch/s390/configs/gcov_defconfig
index b9f6b4cab927..c81a74e3e25a 100644
--- a/arch/s390/configs/gcov_defconfig
+++ b/arch/s390/configs/gcov_defconfig
@@ -46,6 +46,7 @@ CONFIG_UNIXWARE_DISKLABEL=y
46CONFIG_CFQ_GROUP_IOSCHED=y 46CONFIG_CFQ_GROUP_IOSCHED=y
47CONFIG_DEFAULT_DEADLINE=y 47CONFIG_DEFAULT_DEADLINE=y
48CONFIG_MARCH_Z9_109=y 48CONFIG_MARCH_Z9_109=y
49CONFIG_NR_CPUS=256
49CONFIG_HZ_100=y 50CONFIG_HZ_100=y
50CONFIG_MEMORY_HOTPLUG=y 51CONFIG_MEMORY_HOTPLUG=y
51CONFIG_MEMORY_HOTREMOVE=y 52CONFIG_MEMORY_HOTREMOVE=y
@@ -56,7 +57,6 @@ CONFIG_HOTPLUG_PCI=y
56CONFIG_HOTPLUG_PCI_S390=y 57CONFIG_HOTPLUG_PCI_S390=y
57CONFIG_CHSC_SCH=y 58CONFIG_CHSC_SCH=y
58CONFIG_CRASH_DUMP=y 59CONFIG_CRASH_DUMP=y
59CONFIG_ZFCPDUMP=y
60# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set 60# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
61CONFIG_BINFMT_MISC=m 61CONFIG_BINFMT_MISC=m
62CONFIG_HIBERNATION=y 62CONFIG_HIBERNATION=y
@@ -99,7 +99,6 @@ CONFIG_TCP_CONG_VENO=m
99CONFIG_TCP_CONG_YEAH=m 99CONFIG_TCP_CONG_YEAH=m
100CONFIG_TCP_CONG_ILLINOIS=m 100CONFIG_TCP_CONG_ILLINOIS=m
101CONFIG_IPV6=y 101CONFIG_IPV6=y
102CONFIG_IPV6_PRIVACY=y
103CONFIG_IPV6_ROUTER_PREF=y 102CONFIG_IPV6_ROUTER_PREF=y
104CONFIG_INET6_AH=m 103CONFIG_INET6_AH=m
105CONFIG_INET6_ESP=m 104CONFIG_INET6_ESP=m
@@ -109,6 +108,7 @@ CONFIG_INET6_XFRM_MODE_TRANSPORT=m
109CONFIG_INET6_XFRM_MODE_TUNNEL=m 108CONFIG_INET6_XFRM_MODE_TUNNEL=m
110CONFIG_INET6_XFRM_MODE_BEET=m 109CONFIG_INET6_XFRM_MODE_BEET=m
111CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m 110CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m
111CONFIG_IPV6_VTI=m
112CONFIG_IPV6_SIT=m 112CONFIG_IPV6_SIT=m
113CONFIG_IPV6_GRE=m 113CONFIG_IPV6_GRE=m
114CONFIG_IPV6_MULTIPLE_TABLES=y 114CONFIG_IPV6_MULTIPLE_TABLES=y
@@ -133,7 +133,17 @@ CONFIG_NF_CONNTRACK_SIP=m
133CONFIG_NF_CONNTRACK_TFTP=m 133CONFIG_NF_CONNTRACK_TFTP=m
134CONFIG_NF_CT_NETLINK=m 134CONFIG_NF_CT_NETLINK=m
135CONFIG_NF_CT_NETLINK_TIMEOUT=m 135CONFIG_NF_CT_NETLINK_TIMEOUT=m
136CONFIG_NETFILTER_TPROXY=m 136CONFIG_NF_TABLES=m
137CONFIG_NFT_EXTHDR=m
138CONFIG_NFT_META=m
139CONFIG_NFT_CT=m
140CONFIG_NFT_RBTREE=m
141CONFIG_NFT_HASH=m
142CONFIG_NFT_COUNTER=m
143CONFIG_NFT_LOG=m
144CONFIG_NFT_LIMIT=m
145CONFIG_NFT_NAT=m
146CONFIG_NFT_COMPAT=m
137CONFIG_NETFILTER_XT_SET=m 147CONFIG_NETFILTER_XT_SET=m
138CONFIG_NETFILTER_XT_TARGET_AUDIT=m 148CONFIG_NETFILTER_XT_TARGET_AUDIT=m
139CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 149CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -202,7 +212,9 @@ CONFIG_IP_SET_HASH_IP=m
202CONFIG_IP_SET_HASH_IPPORT=m 212CONFIG_IP_SET_HASH_IPPORT=m
203CONFIG_IP_SET_HASH_IPPORTIP=m 213CONFIG_IP_SET_HASH_IPPORTIP=m
204CONFIG_IP_SET_HASH_IPPORTNET=m 214CONFIG_IP_SET_HASH_IPPORTNET=m
215CONFIG_IP_SET_HASH_NETPORTNET=m
205CONFIG_IP_SET_HASH_NET=m 216CONFIG_IP_SET_HASH_NET=m
217CONFIG_IP_SET_HASH_NETNET=m
206CONFIG_IP_SET_HASH_NETPORT=m 218CONFIG_IP_SET_HASH_NETPORT=m
207CONFIG_IP_SET_HASH_NETIFACE=m 219CONFIG_IP_SET_HASH_NETIFACE=m
208CONFIG_IP_SET_LIST_SET=m 220CONFIG_IP_SET_LIST_SET=m
@@ -225,6 +237,11 @@ CONFIG_IP_VS_FTP=m
225CONFIG_IP_VS_PE_SIP=m 237CONFIG_IP_VS_PE_SIP=m
226CONFIG_NF_CONNTRACK_IPV4=m 238CONFIG_NF_CONNTRACK_IPV4=m
227# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set 239# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set
240CONFIG_NF_TABLES_IPV4=m
241CONFIG_NFT_REJECT_IPV4=m
242CONFIG_NFT_CHAIN_ROUTE_IPV4=m
243CONFIG_NFT_CHAIN_NAT_IPV4=m
244CONFIG_NF_TABLES_ARP=m
228CONFIG_IP_NF_IPTABLES=m 245CONFIG_IP_NF_IPTABLES=m
229CONFIG_IP_NF_MATCH_AH=m 246CONFIG_IP_NF_MATCH_AH=m
230CONFIG_IP_NF_MATCH_ECN=m 247CONFIG_IP_NF_MATCH_ECN=m
@@ -247,6 +264,9 @@ CONFIG_IP_NF_ARPTABLES=m
247CONFIG_IP_NF_ARPFILTER=m 264CONFIG_IP_NF_ARPFILTER=m
248CONFIG_IP_NF_ARP_MANGLE=m 265CONFIG_IP_NF_ARP_MANGLE=m
249CONFIG_NF_CONNTRACK_IPV6=m 266CONFIG_NF_CONNTRACK_IPV6=m
267CONFIG_NF_TABLES_IPV6=m
268CONFIG_NFT_CHAIN_ROUTE_IPV6=m
269CONFIG_NFT_CHAIN_NAT_IPV6=m
250CONFIG_IP6_NF_IPTABLES=m 270CONFIG_IP6_NF_IPTABLES=m
251CONFIG_IP6_NF_MATCH_AH=m 271CONFIG_IP6_NF_MATCH_AH=m
252CONFIG_IP6_NF_MATCH_EUI64=m 272CONFIG_IP6_NF_MATCH_EUI64=m
@@ -266,6 +286,7 @@ CONFIG_IP6_NF_SECURITY=m
266CONFIG_NF_NAT_IPV6=m 286CONFIG_NF_NAT_IPV6=m
267CONFIG_IP6_NF_TARGET_MASQUERADE=m 287CONFIG_IP6_NF_TARGET_MASQUERADE=m
268CONFIG_IP6_NF_TARGET_NPT=m 288CONFIG_IP6_NF_TARGET_NPT=m
289CONFIG_NF_TABLES_BRIDGE=m
269CONFIG_NET_SCTPPROBE=m 290CONFIG_NET_SCTPPROBE=m
270CONFIG_RDS=m 291CONFIG_RDS=m
271CONFIG_RDS_RDMA=m 292CONFIG_RDS_RDMA=m
@@ -311,6 +332,7 @@ CONFIG_NET_CLS_RSVP=m
311CONFIG_NET_CLS_RSVP6=m 332CONFIG_NET_CLS_RSVP6=m
312CONFIG_NET_CLS_FLOW=m 333CONFIG_NET_CLS_FLOW=m
313CONFIG_NET_CLS_CGROUP=y 334CONFIG_NET_CLS_CGROUP=y
335CONFIG_NET_CLS_BPF=m
314CONFIG_NET_CLS_ACT=y 336CONFIG_NET_CLS_ACT=y
315CONFIG_NET_ACT_POLICE=m 337CONFIG_NET_ACT_POLICE=m
316CONFIG_NET_ACT_GACT=m 338CONFIG_NET_ACT_GACT=m
@@ -378,8 +400,8 @@ CONFIG_BLK_DEV_DM=m
378CONFIG_DM_CRYPT=m 400CONFIG_DM_CRYPT=m
379CONFIG_DM_SNAPSHOT=m 401CONFIG_DM_SNAPSHOT=m
380CONFIG_DM_MIRROR=m 402CONFIG_DM_MIRROR=m
381CONFIG_DM_RAID=m
382CONFIG_DM_LOG_USERSPACE=m 403CONFIG_DM_LOG_USERSPACE=m
404CONFIG_DM_RAID=m
383CONFIG_DM_ZERO=m 405CONFIG_DM_ZERO=m
384CONFIG_DM_MULTIPATH=m 406CONFIG_DM_MULTIPATH=m
385CONFIG_DM_MULTIPATH_QL=m 407CONFIG_DM_MULTIPATH_QL=m
@@ -431,7 +453,6 @@ CONFIG_TN3270_FS=y
431CONFIG_WATCHDOG=y 453CONFIG_WATCHDOG=y
432CONFIG_WATCHDOG_NOWAYOUT=y 454CONFIG_WATCHDOG_NOWAYOUT=y
433CONFIG_SOFT_WATCHDOG=m 455CONFIG_SOFT_WATCHDOG=m
434CONFIG_ZVM_WATCHDOG=m
435# CONFIG_HID is not set 456# CONFIG_HID is not set
436# CONFIG_USB_SUPPORT is not set 457# CONFIG_USB_SUPPORT is not set
437CONFIG_INFINIBAND=m 458CONFIG_INFINIBAND=m
@@ -540,6 +561,7 @@ CONFIG_BLK_DEV_IO_TRACE=y
540CONFIG_LKDTM=m 561CONFIG_LKDTM=m
541CONFIG_RBTREE_TEST=m 562CONFIG_RBTREE_TEST=m
542CONFIG_INTERVAL_TREE_TEST=m 563CONFIG_INTERVAL_TREE_TEST=m
564CONFIG_PERCPU_TEST=m
543CONFIG_ATOMIC64_SELFTEST=y 565CONFIG_ATOMIC64_SELFTEST=y
544# CONFIG_STRICT_DEVMEM is not set 566# CONFIG_STRICT_DEVMEM is not set
545CONFIG_S390_PTDUMP=y 567CONFIG_S390_PTDUMP=y
@@ -601,7 +623,6 @@ CONFIG_CRYPTO_AES_S390=m
601CONFIG_CRYPTO_GHASH_S390=m 623CONFIG_CRYPTO_GHASH_S390=m
602CONFIG_ASYMMETRIC_KEY_TYPE=m 624CONFIG_ASYMMETRIC_KEY_TYPE=m
603CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m 625CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m
604CONFIG_PUBLIC_KEY_ALGO_RSA=m
605CONFIG_X509_CERTIFICATE_PARSER=m 626CONFIG_X509_CERTIFICATE_PARSER=m
606CONFIG_CRC7=m 627CONFIG_CRC7=m
607CONFIG_CRC8=m 628CONFIG_CRC8=m
diff --git a/arch/s390/configs/performance_defconfig b/arch/s390/configs/performance_defconfig
index 91087b43e8fa..b5ba8fe1cc64 100644
--- a/arch/s390/configs/performance_defconfig
+++ b/arch/s390/configs/performance_defconfig
@@ -44,6 +44,7 @@ CONFIG_UNIXWARE_DISKLABEL=y
44CONFIG_CFQ_GROUP_IOSCHED=y 44CONFIG_CFQ_GROUP_IOSCHED=y
45CONFIG_DEFAULT_DEADLINE=y 45CONFIG_DEFAULT_DEADLINE=y
46CONFIG_MARCH_Z9_109=y 46CONFIG_MARCH_Z9_109=y
47CONFIG_NR_CPUS=256
47CONFIG_HZ_100=y 48CONFIG_HZ_100=y
48CONFIG_MEMORY_HOTPLUG=y 49CONFIG_MEMORY_HOTPLUG=y
49CONFIG_MEMORY_HOTREMOVE=y 50CONFIG_MEMORY_HOTREMOVE=y
@@ -54,7 +55,6 @@ CONFIG_HOTPLUG_PCI=y
54CONFIG_HOTPLUG_PCI_S390=y 55CONFIG_HOTPLUG_PCI_S390=y
55CONFIG_CHSC_SCH=y 56CONFIG_CHSC_SCH=y
56CONFIG_CRASH_DUMP=y 57CONFIG_CRASH_DUMP=y
57CONFIG_ZFCPDUMP=y
58# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set 58# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
59CONFIG_BINFMT_MISC=m 59CONFIG_BINFMT_MISC=m
60CONFIG_HIBERNATION=y 60CONFIG_HIBERNATION=y
@@ -97,7 +97,6 @@ CONFIG_TCP_CONG_VENO=m
97CONFIG_TCP_CONG_YEAH=m 97CONFIG_TCP_CONG_YEAH=m
98CONFIG_TCP_CONG_ILLINOIS=m 98CONFIG_TCP_CONG_ILLINOIS=m
99CONFIG_IPV6=y 99CONFIG_IPV6=y
100CONFIG_IPV6_PRIVACY=y
101CONFIG_IPV6_ROUTER_PREF=y 100CONFIG_IPV6_ROUTER_PREF=y
102CONFIG_INET6_AH=m 101CONFIG_INET6_AH=m
103CONFIG_INET6_ESP=m 102CONFIG_INET6_ESP=m
@@ -107,6 +106,7 @@ CONFIG_INET6_XFRM_MODE_TRANSPORT=m
107CONFIG_INET6_XFRM_MODE_TUNNEL=m 106CONFIG_INET6_XFRM_MODE_TUNNEL=m
108CONFIG_INET6_XFRM_MODE_BEET=m 107CONFIG_INET6_XFRM_MODE_BEET=m
109CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m 108CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m
109CONFIG_IPV6_VTI=m
110CONFIG_IPV6_SIT=m 110CONFIG_IPV6_SIT=m
111CONFIG_IPV6_GRE=m 111CONFIG_IPV6_GRE=m
112CONFIG_IPV6_MULTIPLE_TABLES=y 112CONFIG_IPV6_MULTIPLE_TABLES=y
@@ -131,7 +131,17 @@ CONFIG_NF_CONNTRACK_SIP=m
131CONFIG_NF_CONNTRACK_TFTP=m 131CONFIG_NF_CONNTRACK_TFTP=m
132CONFIG_NF_CT_NETLINK=m 132CONFIG_NF_CT_NETLINK=m
133CONFIG_NF_CT_NETLINK_TIMEOUT=m 133CONFIG_NF_CT_NETLINK_TIMEOUT=m
134CONFIG_NETFILTER_TPROXY=m 134CONFIG_NF_TABLES=m
135CONFIG_NFT_EXTHDR=m
136CONFIG_NFT_META=m
137CONFIG_NFT_CT=m
138CONFIG_NFT_RBTREE=m
139CONFIG_NFT_HASH=m
140CONFIG_NFT_COUNTER=m
141CONFIG_NFT_LOG=m
142CONFIG_NFT_LIMIT=m
143CONFIG_NFT_NAT=m
144CONFIG_NFT_COMPAT=m
135CONFIG_NETFILTER_XT_SET=m 145CONFIG_NETFILTER_XT_SET=m
136CONFIG_NETFILTER_XT_TARGET_AUDIT=m 146CONFIG_NETFILTER_XT_TARGET_AUDIT=m
137CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m 147CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
@@ -200,7 +210,9 @@ CONFIG_IP_SET_HASH_IP=m
200CONFIG_IP_SET_HASH_IPPORT=m 210CONFIG_IP_SET_HASH_IPPORT=m
201CONFIG_IP_SET_HASH_IPPORTIP=m 211CONFIG_IP_SET_HASH_IPPORTIP=m
202CONFIG_IP_SET_HASH_IPPORTNET=m 212CONFIG_IP_SET_HASH_IPPORTNET=m
213CONFIG_IP_SET_HASH_NETPORTNET=m
203CONFIG_IP_SET_HASH_NET=m 214CONFIG_IP_SET_HASH_NET=m
215CONFIG_IP_SET_HASH_NETNET=m
204CONFIG_IP_SET_HASH_NETPORT=m 216CONFIG_IP_SET_HASH_NETPORT=m
205CONFIG_IP_SET_HASH_NETIFACE=m 217CONFIG_IP_SET_HASH_NETIFACE=m
206CONFIG_IP_SET_LIST_SET=m 218CONFIG_IP_SET_LIST_SET=m
@@ -223,6 +235,11 @@ CONFIG_IP_VS_FTP=m
223CONFIG_IP_VS_PE_SIP=m 235CONFIG_IP_VS_PE_SIP=m
224CONFIG_NF_CONNTRACK_IPV4=m 236CONFIG_NF_CONNTRACK_IPV4=m
225# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set 237# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set
238CONFIG_NF_TABLES_IPV4=m
239CONFIG_NFT_REJECT_IPV4=m
240CONFIG_NFT_CHAIN_ROUTE_IPV4=m
241CONFIG_NFT_CHAIN_NAT_IPV4=m
242CONFIG_NF_TABLES_ARP=m
226CONFIG_IP_NF_IPTABLES=m 243CONFIG_IP_NF_IPTABLES=m
227CONFIG_IP_NF_MATCH_AH=m 244CONFIG_IP_NF_MATCH_AH=m
228CONFIG_IP_NF_MATCH_ECN=m 245CONFIG_IP_NF_MATCH_ECN=m
@@ -245,6 +262,9 @@ CONFIG_IP_NF_ARPTABLES=m
245CONFIG_IP_NF_ARPFILTER=m 262CONFIG_IP_NF_ARPFILTER=m
246CONFIG_IP_NF_ARP_MANGLE=m 263CONFIG_IP_NF_ARP_MANGLE=m
247CONFIG_NF_CONNTRACK_IPV6=m 264CONFIG_NF_CONNTRACK_IPV6=m
265CONFIG_NF_TABLES_IPV6=m
266CONFIG_NFT_CHAIN_ROUTE_IPV6=m
267CONFIG_NFT_CHAIN_NAT_IPV6=m
248CONFIG_IP6_NF_IPTABLES=m 268CONFIG_IP6_NF_IPTABLES=m
249CONFIG_IP6_NF_MATCH_AH=m 269CONFIG_IP6_NF_MATCH_AH=m
250CONFIG_IP6_NF_MATCH_EUI64=m 270CONFIG_IP6_NF_MATCH_EUI64=m
@@ -264,6 +284,7 @@ CONFIG_IP6_NF_SECURITY=m
264CONFIG_NF_NAT_IPV6=m 284CONFIG_NF_NAT_IPV6=m
265CONFIG_IP6_NF_TARGET_MASQUERADE=m 285CONFIG_IP6_NF_TARGET_MASQUERADE=m
266CONFIG_IP6_NF_TARGET_NPT=m 286CONFIG_IP6_NF_TARGET_NPT=m
287CONFIG_NF_TABLES_BRIDGE=m
267CONFIG_NET_SCTPPROBE=m 288CONFIG_NET_SCTPPROBE=m
268CONFIG_RDS=m 289CONFIG_RDS=m
269CONFIG_RDS_RDMA=m 290CONFIG_RDS_RDMA=m
@@ -309,6 +330,7 @@ CONFIG_NET_CLS_RSVP=m
309CONFIG_NET_CLS_RSVP6=m 330CONFIG_NET_CLS_RSVP6=m
310CONFIG_NET_CLS_FLOW=m 331CONFIG_NET_CLS_FLOW=m
311CONFIG_NET_CLS_CGROUP=y 332CONFIG_NET_CLS_CGROUP=y
333CONFIG_NET_CLS_BPF=m
312CONFIG_NET_CLS_ACT=y 334CONFIG_NET_CLS_ACT=y
313CONFIG_NET_ACT_POLICE=m 335CONFIG_NET_ACT_POLICE=m
314CONFIG_NET_ACT_GACT=m 336CONFIG_NET_ACT_GACT=m
@@ -376,8 +398,8 @@ CONFIG_BLK_DEV_DM=m
376CONFIG_DM_CRYPT=m 398CONFIG_DM_CRYPT=m
377CONFIG_DM_SNAPSHOT=m 399CONFIG_DM_SNAPSHOT=m
378CONFIG_DM_MIRROR=m 400CONFIG_DM_MIRROR=m
379CONFIG_DM_RAID=m
380CONFIG_DM_LOG_USERSPACE=m 401CONFIG_DM_LOG_USERSPACE=m
402CONFIG_DM_RAID=m
381CONFIG_DM_ZERO=m 403CONFIG_DM_ZERO=m
382CONFIG_DM_MULTIPATH=m 404CONFIG_DM_MULTIPATH=m
383CONFIG_DM_MULTIPATH_QL=m 405CONFIG_DM_MULTIPATH_QL=m
@@ -429,7 +451,6 @@ CONFIG_TN3270_FS=y
429CONFIG_WATCHDOG=y 451CONFIG_WATCHDOG=y
430CONFIG_WATCHDOG_NOWAYOUT=y 452CONFIG_WATCHDOG_NOWAYOUT=y
431CONFIG_SOFT_WATCHDOG=m 453CONFIG_SOFT_WATCHDOG=m
432CONFIG_ZVM_WATCHDOG=m
433# CONFIG_HID is not set 454# CONFIG_HID is not set
434# CONFIG_USB_SUPPORT is not set 455# CONFIG_USB_SUPPORT is not set
435CONFIG_INFINIBAND=m 456CONFIG_INFINIBAND=m
@@ -532,6 +553,7 @@ CONFIG_LATENCYTOP=y
532CONFIG_BLK_DEV_IO_TRACE=y 553CONFIG_BLK_DEV_IO_TRACE=y
533# CONFIG_KPROBE_EVENT is not set 554# CONFIG_KPROBE_EVENT is not set
534CONFIG_LKDTM=m 555CONFIG_LKDTM=m
556CONFIG_PERCPU_TEST=m
535CONFIG_ATOMIC64_SELFTEST=y 557CONFIG_ATOMIC64_SELFTEST=y
536# CONFIG_STRICT_DEVMEM is not set 558# CONFIG_STRICT_DEVMEM is not set
537CONFIG_S390_PTDUMP=y 559CONFIG_S390_PTDUMP=y
@@ -593,7 +615,6 @@ CONFIG_CRYPTO_AES_S390=m
593CONFIG_CRYPTO_GHASH_S390=m 615CONFIG_CRYPTO_GHASH_S390=m
594CONFIG_ASYMMETRIC_KEY_TYPE=m 616CONFIG_ASYMMETRIC_KEY_TYPE=m
595CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m 617CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m
596CONFIG_PUBLIC_KEY_ALGO_RSA=m
597CONFIG_X509_CERTIFICATE_PARSER=m 618CONFIG_X509_CERTIFICATE_PARSER=m
598CONFIG_CRC7=m 619CONFIG_CRC7=m
599CONFIG_CRC8=m 620CONFIG_CRC8=m
diff --git a/arch/s390/configs/zfcpdump_defconfig b/arch/s390/configs/zfcpdump_defconfig
index d725c4d956e4..cef073ca1f07 100644
--- a/arch/s390/configs/zfcpdump_defconfig
+++ b/arch/s390/configs/zfcpdump_defconfig
@@ -19,7 +19,6 @@ CONFIG_HZ_100=y
19# CONFIG_CHSC_SCH is not set 19# CONFIG_CHSC_SCH is not set
20# CONFIG_SCM_BUS is not set 20# CONFIG_SCM_BUS is not set
21CONFIG_CRASH_DUMP=y 21CONFIG_CRASH_DUMP=y
22CONFIG_ZFCPDUMP=y
23# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set 22# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
24# CONFIG_SECCOMP is not set 23# CONFIG_SECCOMP is not set
25# CONFIG_IUCV is not set 24# CONFIG_IUCV is not set
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c
index b3feabd39f31..cf3c0089bef2 100644
--- a/arch/s390/crypto/aes_s390.c
+++ b/arch/s390/crypto/aes_s390.c
@@ -25,6 +25,7 @@
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/spinlock.h>
28#include "crypt_s390.h" 29#include "crypt_s390.h"
29 30
30#define AES_KEYLEN_128 1 31#define AES_KEYLEN_128 1
@@ -32,6 +33,7 @@
32#define AES_KEYLEN_256 4 33#define AES_KEYLEN_256 4
33 34
34static u8 *ctrblk; 35static u8 *ctrblk;
36static DEFINE_SPINLOCK(ctrblk_lock);
35static char keylen_flag; 37static char keylen_flag;
36 38
37struct s390_aes_ctx { 39struct s390_aes_ctx {
@@ -758,43 +760,67 @@ static int ctr_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
758 return aes_set_key(tfm, in_key, key_len); 760 return aes_set_key(tfm, in_key, key_len);
759} 761}
760 762
763static unsigned int __ctrblk_init(u8 *ctrptr, unsigned int nbytes)
764{
765 unsigned int i, n;
766
767 /* only use complete blocks, max. PAGE_SIZE */
768 n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : nbytes & ~(AES_BLOCK_SIZE - 1);
769 for (i = AES_BLOCK_SIZE; i < n; i += AES_BLOCK_SIZE) {
770 memcpy(ctrptr + i, ctrptr + i - AES_BLOCK_SIZE,
771 AES_BLOCK_SIZE);
772 crypto_inc(ctrptr + i, AES_BLOCK_SIZE);
773 }
774 return n;
775}
776
761static int ctr_aes_crypt(struct blkcipher_desc *desc, long func, 777static int ctr_aes_crypt(struct blkcipher_desc *desc, long func,
762 struct s390_aes_ctx *sctx, struct blkcipher_walk *walk) 778 struct s390_aes_ctx *sctx, struct blkcipher_walk *walk)
763{ 779{
764 int ret = blkcipher_walk_virt_block(desc, walk, AES_BLOCK_SIZE); 780 int ret = blkcipher_walk_virt_block(desc, walk, AES_BLOCK_SIZE);
765 unsigned int i, n, nbytes; 781 unsigned int n, nbytes;
766 u8 buf[AES_BLOCK_SIZE]; 782 u8 buf[AES_BLOCK_SIZE], ctrbuf[AES_BLOCK_SIZE];
767 u8 *out, *in; 783 u8 *out, *in, *ctrptr = ctrbuf;
768 784
769 if (!walk->nbytes) 785 if (!walk->nbytes)
770 return ret; 786 return ret;
771 787
772 memcpy(ctrblk, walk->iv, AES_BLOCK_SIZE); 788 if (spin_trylock(&ctrblk_lock))
789 ctrptr = ctrblk;
790
791 memcpy(ctrptr, walk->iv, AES_BLOCK_SIZE);
773 while ((nbytes = walk->nbytes) >= AES_BLOCK_SIZE) { 792 while ((nbytes = walk->nbytes) >= AES_BLOCK_SIZE) {
774 out = walk->dst.virt.addr; 793 out = walk->dst.virt.addr;
775 in = walk->src.virt.addr; 794 in = walk->src.virt.addr;
776 while (nbytes >= AES_BLOCK_SIZE) { 795 while (nbytes >= AES_BLOCK_SIZE) {
777 /* only use complete blocks, max. PAGE_SIZE */ 796 if (ctrptr == ctrblk)
778 n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : 797 n = __ctrblk_init(ctrptr, nbytes);
779 nbytes & ~(AES_BLOCK_SIZE - 1); 798 else
780 for (i = AES_BLOCK_SIZE; i < n; i += AES_BLOCK_SIZE) { 799 n = AES_BLOCK_SIZE;
781 memcpy(ctrblk + i, ctrblk + i - AES_BLOCK_SIZE, 800 ret = crypt_s390_kmctr(func, sctx->key, out, in,
782 AES_BLOCK_SIZE); 801 n, ctrptr);
783 crypto_inc(ctrblk + i, AES_BLOCK_SIZE); 802 if (ret < 0 || ret != n) {
784 } 803 if (ctrptr == ctrblk)
785 ret = crypt_s390_kmctr(func, sctx->key, out, in, n, ctrblk); 804 spin_unlock(&ctrblk_lock);
786 if (ret < 0 || ret != n)
787 return -EIO; 805 return -EIO;
806 }
788 if (n > AES_BLOCK_SIZE) 807 if (n > AES_BLOCK_SIZE)
789 memcpy(ctrblk, ctrblk + n - AES_BLOCK_SIZE, 808 memcpy(ctrptr, ctrptr + n - AES_BLOCK_SIZE,
790 AES_BLOCK_SIZE); 809 AES_BLOCK_SIZE);
791 crypto_inc(ctrblk, AES_BLOCK_SIZE); 810 crypto_inc(ctrptr, AES_BLOCK_SIZE);
792 out += n; 811 out += n;
793 in += n; 812 in += n;
794 nbytes -= n; 813 nbytes -= n;
795 } 814 }
796 ret = blkcipher_walk_done(desc, walk, nbytes); 815 ret = blkcipher_walk_done(desc, walk, nbytes);
797 } 816 }
817 if (ctrptr == ctrblk) {
818 if (nbytes)
819 memcpy(ctrbuf, ctrptr, AES_BLOCK_SIZE);
820 else
821 memcpy(walk->iv, ctrptr, AES_BLOCK_SIZE);
822 spin_unlock(&ctrblk_lock);
823 }
798 /* 824 /*
799 * final block may be < AES_BLOCK_SIZE, copy only nbytes 825 * final block may be < AES_BLOCK_SIZE, copy only nbytes
800 */ 826 */
@@ -802,14 +828,15 @@ static int ctr_aes_crypt(struct blkcipher_desc *desc, long func,
802 out = walk->dst.virt.addr; 828 out = walk->dst.virt.addr;
803 in = walk->src.virt.addr; 829 in = walk->src.virt.addr;
804 ret = crypt_s390_kmctr(func, sctx->key, buf, in, 830 ret = crypt_s390_kmctr(func, sctx->key, buf, in,
805 AES_BLOCK_SIZE, ctrblk); 831 AES_BLOCK_SIZE, ctrbuf);
806 if (ret < 0 || ret != AES_BLOCK_SIZE) 832 if (ret < 0 || ret != AES_BLOCK_SIZE)
807 return -EIO; 833 return -EIO;
808 memcpy(out, buf, nbytes); 834 memcpy(out, buf, nbytes);
809 crypto_inc(ctrblk, AES_BLOCK_SIZE); 835 crypto_inc(ctrbuf, AES_BLOCK_SIZE);
810 ret = blkcipher_walk_done(desc, walk, 0); 836 ret = blkcipher_walk_done(desc, walk, 0);
837 memcpy(walk->iv, ctrbuf, AES_BLOCK_SIZE);
811 } 838 }
812 memcpy(walk->iv, ctrblk, AES_BLOCK_SIZE); 839
813 return ret; 840 return ret;
814} 841}
815 842
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c
index 200f2a1b599d..0a5aac8a9412 100644
--- a/arch/s390/crypto/des_s390.c
+++ b/arch/s390/crypto/des_s390.c
@@ -25,6 +25,7 @@
25#define DES3_KEY_SIZE (3 * DES_KEY_SIZE) 25#define DES3_KEY_SIZE (3 * DES_KEY_SIZE)
26 26
27static u8 *ctrblk; 27static u8 *ctrblk;
28static DEFINE_SPINLOCK(ctrblk_lock);
28 29
29struct s390_des_ctx { 30struct s390_des_ctx {
30 u8 iv[DES_BLOCK_SIZE]; 31 u8 iv[DES_BLOCK_SIZE];
@@ -105,29 +106,35 @@ static int ecb_desall_crypt(struct blkcipher_desc *desc, long func,
105} 106}
106 107
107static int cbc_desall_crypt(struct blkcipher_desc *desc, long func, 108static int cbc_desall_crypt(struct blkcipher_desc *desc, long func,
108 u8 *iv, struct blkcipher_walk *walk) 109 struct blkcipher_walk *walk)
109{ 110{
111 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
110 int ret = blkcipher_walk_virt(desc, walk); 112 int ret = blkcipher_walk_virt(desc, walk);
111 unsigned int nbytes = walk->nbytes; 113 unsigned int nbytes = walk->nbytes;
114 struct {
115 u8 iv[DES_BLOCK_SIZE];
116 u8 key[DES3_KEY_SIZE];
117 } param;
112 118
113 if (!nbytes) 119 if (!nbytes)
114 goto out; 120 goto out;
115 121
116 memcpy(iv, walk->iv, DES_BLOCK_SIZE); 122 memcpy(param.iv, walk->iv, DES_BLOCK_SIZE);
123 memcpy(param.key, ctx->key, DES3_KEY_SIZE);
117 do { 124 do {
118 /* only use complete blocks */ 125 /* only use complete blocks */
119 unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1); 126 unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1);
120 u8 *out = walk->dst.virt.addr; 127 u8 *out = walk->dst.virt.addr;
121 u8 *in = walk->src.virt.addr; 128 u8 *in = walk->src.virt.addr;
122 129
123 ret = crypt_s390_kmc(func, iv, out, in, n); 130 ret = crypt_s390_kmc(func, &param, out, in, n);
124 if (ret < 0 || ret != n) 131 if (ret < 0 || ret != n)
125 return -EIO; 132 return -EIO;
126 133
127 nbytes &= DES_BLOCK_SIZE - 1; 134 nbytes &= DES_BLOCK_SIZE - 1;
128 ret = blkcipher_walk_done(desc, walk, nbytes); 135 ret = blkcipher_walk_done(desc, walk, nbytes);
129 } while ((nbytes = walk->nbytes)); 136 } while ((nbytes = walk->nbytes));
130 memcpy(walk->iv, iv, DES_BLOCK_SIZE); 137 memcpy(walk->iv, param.iv, DES_BLOCK_SIZE);
131 138
132out: 139out:
133 return ret; 140 return ret;
@@ -179,22 +186,20 @@ static int cbc_des_encrypt(struct blkcipher_desc *desc,
179 struct scatterlist *dst, struct scatterlist *src, 186 struct scatterlist *dst, struct scatterlist *src,
180 unsigned int nbytes) 187 unsigned int nbytes)
181{ 188{
182 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
183 struct blkcipher_walk walk; 189 struct blkcipher_walk walk;
184 190
185 blkcipher_walk_init(&walk, dst, src, nbytes); 191 blkcipher_walk_init(&walk, dst, src, nbytes);
186 return cbc_desall_crypt(desc, KMC_DEA_ENCRYPT, ctx->iv, &walk); 192 return cbc_desall_crypt(desc, KMC_DEA_ENCRYPT, &walk);
187} 193}
188 194
189static int cbc_des_decrypt(struct blkcipher_desc *desc, 195static int cbc_des_decrypt(struct blkcipher_desc *desc,
190 struct scatterlist *dst, struct scatterlist *src, 196 struct scatterlist *dst, struct scatterlist *src,
191 unsigned int nbytes) 197 unsigned int nbytes)
192{ 198{
193 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
194 struct blkcipher_walk walk; 199 struct blkcipher_walk walk;
195 200
196 blkcipher_walk_init(&walk, dst, src, nbytes); 201 blkcipher_walk_init(&walk, dst, src, nbytes);
197 return cbc_desall_crypt(desc, KMC_DEA_DECRYPT, ctx->iv, &walk); 202 return cbc_desall_crypt(desc, KMC_DEA_DECRYPT, &walk);
198} 203}
199 204
200static struct crypto_alg cbc_des_alg = { 205static struct crypto_alg cbc_des_alg = {
@@ -327,22 +332,20 @@ static int cbc_des3_encrypt(struct blkcipher_desc *desc,
327 struct scatterlist *dst, struct scatterlist *src, 332 struct scatterlist *dst, struct scatterlist *src,
328 unsigned int nbytes) 333 unsigned int nbytes)
329{ 334{
330 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
331 struct blkcipher_walk walk; 335 struct blkcipher_walk walk;
332 336
333 blkcipher_walk_init(&walk, dst, src, nbytes); 337 blkcipher_walk_init(&walk, dst, src, nbytes);
334 return cbc_desall_crypt(desc, KMC_TDEA_192_ENCRYPT, ctx->iv, &walk); 338 return cbc_desall_crypt(desc, KMC_TDEA_192_ENCRYPT, &walk);
335} 339}
336 340
337static int cbc_des3_decrypt(struct blkcipher_desc *desc, 341static int cbc_des3_decrypt(struct blkcipher_desc *desc,
338 struct scatterlist *dst, struct scatterlist *src, 342 struct scatterlist *dst, struct scatterlist *src,
339 unsigned int nbytes) 343 unsigned int nbytes)
340{ 344{
341 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
342 struct blkcipher_walk walk; 345 struct blkcipher_walk walk;
343 346
344 blkcipher_walk_init(&walk, dst, src, nbytes); 347 blkcipher_walk_init(&walk, dst, src, nbytes);
345 return cbc_desall_crypt(desc, KMC_TDEA_192_DECRYPT, ctx->iv, &walk); 348 return cbc_desall_crypt(desc, KMC_TDEA_192_DECRYPT, &walk);
346} 349}
347 350
348static struct crypto_alg cbc_des3_alg = { 351static struct crypto_alg cbc_des3_alg = {
@@ -366,54 +369,80 @@ static struct crypto_alg cbc_des3_alg = {
366 } 369 }
367}; 370};
368 371
372static unsigned int __ctrblk_init(u8 *ctrptr, unsigned int nbytes)
373{
374 unsigned int i, n;
375
376 /* align to block size, max. PAGE_SIZE */
377 n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : nbytes & ~(DES_BLOCK_SIZE - 1);
378 for (i = DES_BLOCK_SIZE; i < n; i += DES_BLOCK_SIZE) {
379 memcpy(ctrptr + i, ctrptr + i - DES_BLOCK_SIZE, DES_BLOCK_SIZE);
380 crypto_inc(ctrptr + i, DES_BLOCK_SIZE);
381 }
382 return n;
383}
384
369static int ctr_desall_crypt(struct blkcipher_desc *desc, long func, 385static int ctr_desall_crypt(struct blkcipher_desc *desc, long func,
370 struct s390_des_ctx *ctx, struct blkcipher_walk *walk) 386 struct s390_des_ctx *ctx,
387 struct blkcipher_walk *walk)
371{ 388{
372 int ret = blkcipher_walk_virt_block(desc, walk, DES_BLOCK_SIZE); 389 int ret = blkcipher_walk_virt_block(desc, walk, DES_BLOCK_SIZE);
373 unsigned int i, n, nbytes; 390 unsigned int n, nbytes;
374 u8 buf[DES_BLOCK_SIZE]; 391 u8 buf[DES_BLOCK_SIZE], ctrbuf[DES_BLOCK_SIZE];
375 u8 *out, *in; 392 u8 *out, *in, *ctrptr = ctrbuf;
393
394 if (!walk->nbytes)
395 return ret;
376 396
377 memcpy(ctrblk, walk->iv, DES_BLOCK_SIZE); 397 if (spin_trylock(&ctrblk_lock))
398 ctrptr = ctrblk;
399
400 memcpy(ctrptr, walk->iv, DES_BLOCK_SIZE);
378 while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) { 401 while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
379 out = walk->dst.virt.addr; 402 out = walk->dst.virt.addr;
380 in = walk->src.virt.addr; 403 in = walk->src.virt.addr;
381 while (nbytes >= DES_BLOCK_SIZE) { 404 while (nbytes >= DES_BLOCK_SIZE) {
382 /* align to block size, max. PAGE_SIZE */ 405 if (ctrptr == ctrblk)
383 n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : 406 n = __ctrblk_init(ctrptr, nbytes);
384 nbytes & ~(DES_BLOCK_SIZE - 1); 407 else
385 for (i = DES_BLOCK_SIZE; i < n; i += DES_BLOCK_SIZE) { 408 n = DES_BLOCK_SIZE;
386 memcpy(ctrblk + i, ctrblk + i - DES_BLOCK_SIZE, 409 ret = crypt_s390_kmctr(func, ctx->key, out, in,
387 DES_BLOCK_SIZE); 410 n, ctrptr);
388 crypto_inc(ctrblk + i, DES_BLOCK_SIZE); 411 if (ret < 0 || ret != n) {
389 } 412 if (ctrptr == ctrblk)
390 ret = crypt_s390_kmctr(func, ctx->key, out, in, n, ctrblk); 413 spin_unlock(&ctrblk_lock);
391 if (ret < 0 || ret != n)
392 return -EIO; 414 return -EIO;
415 }
393 if (n > DES_BLOCK_SIZE) 416 if (n > DES_BLOCK_SIZE)
394 memcpy(ctrblk, ctrblk + n - DES_BLOCK_SIZE, 417 memcpy(ctrptr, ctrptr + n - DES_BLOCK_SIZE,
395 DES_BLOCK_SIZE); 418 DES_BLOCK_SIZE);
396 crypto_inc(ctrblk, DES_BLOCK_SIZE); 419 crypto_inc(ctrptr, DES_BLOCK_SIZE);
397 out += n; 420 out += n;
398 in += n; 421 in += n;
399 nbytes -= n; 422 nbytes -= n;
400 } 423 }
401 ret = blkcipher_walk_done(desc, walk, nbytes); 424 ret = blkcipher_walk_done(desc, walk, nbytes);
402 } 425 }
403 426 if (ctrptr == ctrblk) {
427 if (nbytes)
428 memcpy(ctrbuf, ctrptr, DES_BLOCK_SIZE);
429 else
430 memcpy(walk->iv, ctrptr, DES_BLOCK_SIZE);
431 spin_unlock(&ctrblk_lock);
432 }
404 /* final block may be < DES_BLOCK_SIZE, copy only nbytes */ 433 /* final block may be < DES_BLOCK_SIZE, copy only nbytes */
405 if (nbytes) { 434 if (nbytes) {
406 out = walk->dst.virt.addr; 435 out = walk->dst.virt.addr;
407 in = walk->src.virt.addr; 436 in = walk->src.virt.addr;
408 ret = crypt_s390_kmctr(func, ctx->key, buf, in, 437 ret = crypt_s390_kmctr(func, ctx->key, buf, in,
409 DES_BLOCK_SIZE, ctrblk); 438 DES_BLOCK_SIZE, ctrbuf);
410 if (ret < 0 || ret != DES_BLOCK_SIZE) 439 if (ret < 0 || ret != DES_BLOCK_SIZE)
411 return -EIO; 440 return -EIO;
412 memcpy(out, buf, nbytes); 441 memcpy(out, buf, nbytes);
413 crypto_inc(ctrblk, DES_BLOCK_SIZE); 442 crypto_inc(ctrbuf, DES_BLOCK_SIZE);
414 ret = blkcipher_walk_done(desc, walk, 0); 443 ret = blkcipher_walk_done(desc, walk, 0);
444 memcpy(walk->iv, ctrbuf, DES_BLOCK_SIZE);
415 } 445 }
416 memcpy(walk->iv, ctrblk, DES_BLOCK_SIZE);
417 return ret; 446 return ret;
418} 447}
419 448
diff --git a/arch/s390/defconfig b/arch/s390/defconfig
index 33f57514f424..4557cb7ffddf 100644
--- a/arch/s390/defconfig
+++ b/arch/s390/defconfig
@@ -40,6 +40,7 @@ CONFIG_PARTITION_ADVANCED=y
40CONFIG_IBM_PARTITION=y 40CONFIG_IBM_PARTITION=y
41CONFIG_DEFAULT_DEADLINE=y 41CONFIG_DEFAULT_DEADLINE=y
42CONFIG_MARCH_Z196=y 42CONFIG_MARCH_Z196=y
43CONFIG_NR_CPUS=256
43CONFIG_HZ_100=y 44CONFIG_HZ_100=y
44CONFIG_MEMORY_HOTPLUG=y 45CONFIG_MEMORY_HOTPLUG=y
45CONFIG_MEMORY_HOTREMOVE=y 46CONFIG_MEMORY_HOTREMOVE=y
@@ -122,22 +123,31 @@ CONFIG_TMPFS=y
122CONFIG_TMPFS_POSIX_ACL=y 123CONFIG_TMPFS_POSIX_ACL=y
123CONFIG_HUGETLBFS=y 124CONFIG_HUGETLBFS=y
124# CONFIG_NETWORK_FILESYSTEMS is not set 125# CONFIG_NETWORK_FILESYSTEMS is not set
126CONFIG_UNUSED_SYMBOLS=y
127CONFIG_DEBUG_SECTION_MISMATCH=y
125CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y 128CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y
126CONFIG_MAGIC_SYSRQ=y 129CONFIG_MAGIC_SYSRQ=y
127CONFIG_DEBUG_PAGEALLOC=y 130CONFIG_DEBUG_PAGEALLOC=y
131CONFIG_DETECT_HUNG_TASK=y
128CONFIG_TIMER_STATS=y 132CONFIG_TIMER_STATS=y
133CONFIG_DEBUG_RT_MUTEXES=y
129CONFIG_PROVE_LOCKING=y 134CONFIG_PROVE_LOCKING=y
130CONFIG_LOCK_STAT=y 135CONFIG_LOCK_STAT=y
131CONFIG_DEBUG_LOCKDEP=y 136CONFIG_DEBUG_LOCKDEP=y
137CONFIG_DEBUG_ATOMIC_SLEEP=y
138CONFIG_DEBUG_WRITECOUNT=y
132CONFIG_DEBUG_LIST=y 139CONFIG_DEBUG_LIST=y
140CONFIG_DEBUG_SG=y
133CONFIG_DEBUG_NOTIFIERS=y 141CONFIG_DEBUG_NOTIFIERS=y
134CONFIG_PROVE_RCU=y 142CONFIG_PROVE_RCU=y
135CONFIG_RCU_CPU_STALL_TIMEOUT=60 143CONFIG_RCU_CPU_STALL_TIMEOUT=60
136CONFIG_RCU_TRACE=y 144CONFIG_RCU_TRACE=y
137CONFIG_LATENCYTOP=y 145CONFIG_LATENCYTOP=y
146CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y
138CONFIG_BLK_DEV_IO_TRACE=y 147CONFIG_BLK_DEV_IO_TRACE=y
139CONFIG_KPROBES_SANITY_TEST=y 148CONFIG_KPROBES_SANITY_TEST=y
140# CONFIG_STRICT_DEVMEM is not set 149# CONFIG_STRICT_DEVMEM is not set
150CONFIG_S390_PTDUMP=y
141CONFIG_CRYPTO_CRYPTD=m 151CONFIG_CRYPTO_CRYPTD=m
142CONFIG_CRYPTO_AUTHENC=m 152CONFIG_CRYPTO_AUTHENC=m
143CONFIG_CRYPTO_TEST=m 153CONFIG_CRYPTO_TEST=m
diff --git a/arch/s390/hypfs/hypfs_vm.c b/arch/s390/hypfs/hypfs_vm.c
index 24908ce149f1..32040ace00ea 100644
--- a/arch/s390/hypfs/hypfs_vm.c
+++ b/arch/s390/hypfs/hypfs_vm.c
@@ -32,7 +32,7 @@ struct diag2fc_data {
32 __u32 pcpus; 32 __u32 pcpus;
33 __u32 lcpus; 33 __u32 lcpus;
34 __u32 vcpus; 34 __u32 vcpus;
35 __u32 cpu_min; 35 __u32 ocpus;
36 __u32 cpu_max; 36 __u32 cpu_max;
37 __u32 cpu_shares; 37 __u32 cpu_shares;
38 __u32 cpu_use_samp; 38 __u32 cpu_use_samp;
@@ -142,7 +142,12 @@ static int hpyfs_vm_create_guest(struct dentry *systems_dir,
142 ATTRIBUTE(cpus_dir, "capped", capped_value); 142 ATTRIBUTE(cpus_dir, "capped", capped_value);
143 ATTRIBUTE(cpus_dir, "dedicated", dedicated_flag); 143 ATTRIBUTE(cpus_dir, "dedicated", dedicated_flag);
144 ATTRIBUTE(cpus_dir, "count", data->vcpus); 144 ATTRIBUTE(cpus_dir, "count", data->vcpus);
145 ATTRIBUTE(cpus_dir, "weight_min", data->cpu_min); 145 /*
146 * Note: The "weight_min" attribute got the wrong name.
147 * The value represents the number of non-stopped (operating)
148 * CPUS.
149 */
150 ATTRIBUTE(cpus_dir, "weight_min", data->ocpus);
146 ATTRIBUTE(cpus_dir, "weight_max", data->cpu_max); 151 ATTRIBUTE(cpus_dir, "weight_max", data->cpu_max);
147 ATTRIBUTE(cpus_dir, "weight_cur", data->cpu_shares); 152 ATTRIBUTE(cpus_dir, "weight_cur", data->cpu_shares);
148 153
diff --git a/arch/s390/include/asm/Kbuild b/arch/s390/include/asm/Kbuild
index 8386a4a1f19a..57892a8a9055 100644
--- a/arch/s390/include/asm/Kbuild
+++ b/arch/s390/include/asm/Kbuild
@@ -1,6 +1,7 @@
1 1
2 2
3generic-y += clkdev.h 3generic-y += clkdev.h
4generic-y += trace_clock.h
5generic-y += preempt.h
6generic-y += hash.h 4generic-y += hash.h
5generic-y += mcs_spinlock.h
6generic-y += preempt.h
7generic-y += trace_clock.h
diff --git a/arch/s390/include/asm/airq.h b/arch/s390/include/asm/airq.h
index 4bbb5957ed1b..bd93ff6661b8 100644
--- a/arch/s390/include/asm/airq.h
+++ b/arch/s390/include/asm/airq.h
@@ -44,11 +44,21 @@ struct airq_iv {
44 44
45struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags); 45struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags);
46void airq_iv_release(struct airq_iv *iv); 46void airq_iv_release(struct airq_iv *iv);
47unsigned long airq_iv_alloc_bit(struct airq_iv *iv); 47unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num);
48void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit); 48void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num);
49unsigned long airq_iv_scan(struct airq_iv *iv, unsigned long start, 49unsigned long airq_iv_scan(struct airq_iv *iv, unsigned long start,
50 unsigned long end); 50 unsigned long end);
51 51
52static inline unsigned long airq_iv_alloc_bit(struct airq_iv *iv)
53{
54 return airq_iv_alloc(iv, 1);
55}
56
57static inline void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit)
58{
59 airq_iv_free(iv, bit, 1);
60}
61
52static inline unsigned long airq_iv_end(struct airq_iv *iv) 62static inline unsigned long airq_iv_end(struct airq_iv *iv)
53{ 63{
54 return iv->end; 64 return iv->end;
diff --git a/arch/s390/include/asm/bitops.h b/arch/s390/include/asm/bitops.h
index 6e6ad0680829..ec5ef891db6b 100644
--- a/arch/s390/include/asm/bitops.h
+++ b/arch/s390/include/asm/bitops.h
@@ -13,9 +13,9 @@
13 * 13 *
14 * The bitop functions are defined to work on unsigned longs, so for an 14 * The bitop functions are defined to work on unsigned longs, so for an
15 * s390x system the bits end up numbered: 15 * s390x system the bits end up numbered:
16 * |63..............0|127............64|191...........128|255...........196| 16 * |63..............0|127............64|191...........128|255...........192|
17 * and on s390: 17 * and on s390:
18 * |31.....0|63....31|95....64|127...96|159..128|191..160|223..192|255..224| 18 * |31.....0|63....32|95....64|127...96|159..128|191..160|223..192|255..224|
19 * 19 *
20 * There are a few little-endian macros used mostly for filesystem 20 * There are a few little-endian macros used mostly for filesystem
21 * bitmaps, these work on similar bit arrays layouts, but 21 * bitmaps, these work on similar bit arrays layouts, but
@@ -30,7 +30,7 @@
30 * on an s390x system the bits are numbered: 30 * on an s390x system the bits are numbered:
31 * |0..............63|64............127|128...........191|192...........255| 31 * |0..............63|64............127|128...........191|192...........255|
32 * and on s390: 32 * and on s390:
33 * |0.....31|31....63|64....95|96...127|128..159|160..191|192..223|224..255| 33 * |0.....31|32....63|64....95|96...127|128..159|160..191|192..223|224..255|
34 * 34 *
35 * The main difference is that bit 0-63 (64b) or 0-31 (32b) in the bit 35 * The main difference is that bit 0-63 (64b) or 0-31 (32b) in the bit
36 * number field needs to be reversed compared to the LSB0 encoded bit 36 * number field needs to be reversed compared to the LSB0 encoded bit
@@ -304,7 +304,7 @@ static inline int test_bit(unsigned long nr, const volatile unsigned long *ptr)
304 * On an s390x system the bits are numbered: 304 * On an s390x system the bits are numbered:
305 * |0..............63|64............127|128...........191|192...........255| 305 * |0..............63|64............127|128...........191|192...........255|
306 * and on s390: 306 * and on s390:
307 * |0.....31|31....63|64....95|96...127|128..159|160..191|192..223|224..255| 307 * |0.....31|32....63|64....95|96...127|128..159|160..191|192..223|224..255|
308 */ 308 */
309unsigned long find_first_bit_inv(const unsigned long *addr, unsigned long size); 309unsigned long find_first_bit_inv(const unsigned long *addr, unsigned long size);
310unsigned long find_next_bit_inv(const unsigned long *addr, unsigned long size, 310unsigned long find_next_bit_inv(const unsigned long *addr, unsigned long size,
diff --git a/arch/s390/include/asm/ccwdev.h b/arch/s390/include/asm/ccwdev.h
index f201af8be580..a9c2c0686177 100644
--- a/arch/s390/include/asm/ccwdev.h
+++ b/arch/s390/include/asm/ccwdev.h
@@ -219,7 +219,9 @@ extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
219#define to_ccwdev(n) container_of(n, struct ccw_device, dev) 219#define to_ccwdev(n) container_of(n, struct ccw_device, dev)
220#define to_ccwdrv(n) container_of(n, struct ccw_driver, driver) 220#define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
221 221
222extern struct ccw_device *ccw_device_probe_console(void); 222extern struct ccw_device *ccw_device_create_console(struct ccw_driver *);
223extern void ccw_device_destroy_console(struct ccw_device *);
224extern int ccw_device_enable_console(struct ccw_device *);
223extern void ccw_device_wait_idle(struct ccw_device *); 225extern void ccw_device_wait_idle(struct ccw_device *);
224extern int ccw_device_force_console(struct ccw_device *); 226extern int ccw_device_force_console(struct ccw_device *);
225 227
diff --git a/arch/s390/include/asm/checksum.h b/arch/s390/include/asm/checksum.h
index 4f57a4f3909a..740364856355 100644
--- a/arch/s390/include/asm/checksum.h
+++ b/arch/s390/include/asm/checksum.h
@@ -44,22 +44,15 @@ csum_partial(const void *buff, int len, __wsum sum)
44 * here even more important to align src and dst on a 32-bit (or even 44 * here even more important to align src and dst on a 32-bit (or even
45 * better 64-bit) boundary 45 * better 64-bit) boundary
46 * 46 *
47 * Copy from userspace and compute checksum. If we catch an exception 47 * Copy from userspace and compute checksum.
48 * then zero the rest of the buffer.
49 */ 48 */
50static inline __wsum 49static inline __wsum
51csum_partial_copy_from_user(const void __user *src, void *dst, 50csum_partial_copy_from_user(const void __user *src, void *dst,
52 int len, __wsum sum, 51 int len, __wsum sum,
53 int *err_ptr) 52 int *err_ptr)
54{ 53{
55 int missing; 54 if (unlikely(copy_from_user(dst, src, len)))
56
57 missing = copy_from_user(dst, src, len);
58 if (missing) {
59 memset(dst + len - missing, 0, missing);
60 *err_ptr = -EFAULT; 55 *err_ptr = -EFAULT;
61 }
62
63 return csum_partial(dst, len, sum); 56 return csum_partial(dst, len, sum);
64} 57}
65 58
diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
index 5d7e8cf83bd6..d350ed9d0fbb 100644
--- a/arch/s390/include/asm/compat.h
+++ b/arch/s390/include/asm/compat.h
@@ -8,7 +8,11 @@
8#include <linux/thread_info.h> 8#include <linux/thread_info.h>
9 9
10#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), u64)) 10#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), u64))
11#define __SC_DELOUSE(t,v) (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)) 11
12#define __SC_DELOUSE(t,v) ({ \
13 BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
14 (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
15})
12 16
13#define PSW32_MASK_PER 0x40000000UL 17#define PSW32_MASK_PER 0x40000000UL
14#define PSW32_MASK_DAT 0x04000000UL 18#define PSW32_MASK_DAT 0x04000000UL
diff --git a/arch/s390/include/asm/futex.h b/arch/s390/include/asm/futex.h
index 51bcaa0fdeef..fda46bd38c99 100644
--- a/arch/s390/include/asm/futex.h
+++ b/arch/s390/include/asm/futex.h
@@ -5,7 +5,10 @@
5#include <linux/uaccess.h> 5#include <linux/uaccess.h>
6#include <asm/errno.h> 6#include <asm/errno.h>
7 7
8static inline int futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr) 8int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 oldval, u32 newval);
9int __futex_atomic_op_inuser(int op, u32 __user *uaddr, int oparg, int *old);
10
11static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
9{ 12{
10 int op = (encoded_op >> 28) & 7; 13 int op = (encoded_op >> 28) & 7;
11 int cmp = (encoded_op >> 24) & 15; 14 int cmp = (encoded_op >> 24) & 15;
@@ -17,7 +20,7 @@ static inline int futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
17 oparg = 1 << oparg; 20 oparg = 1 << oparg;
18 21
19 pagefault_disable(); 22 pagefault_disable();
20 ret = uaccess.futex_atomic_op(op, uaddr, oparg, &oldval); 23 ret = __futex_atomic_op_inuser(op, uaddr, oparg, &oldval);
21 pagefault_enable(); 24 pagefault_enable();
22 25
23 if (!ret) { 26 if (!ret) {
@@ -34,10 +37,4 @@ static inline int futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
34 return ret; 37 return ret;
35} 38}
36 39
37static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
38 u32 oldval, u32 newval)
39{
40 return uaccess.futex_atomic_cmpxchg(uval, uaddr, oldval, newval);
41}
42
43#endif /* _ASM_S390_FUTEX_H */ 40#endif /* _ASM_S390_FUTEX_H */
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index eef3dd3fd9a9..9bf95bb30f1a 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -106,7 +106,9 @@ struct kvm_s390_sie_block {
106 __u64 gbea; /* 0x0180 */ 106 __u64 gbea; /* 0x0180 */
107 __u8 reserved188[24]; /* 0x0188 */ 107 __u8 reserved188[24]; /* 0x0188 */
108 __u32 fac; /* 0x01a0 */ 108 __u32 fac; /* 0x01a0 */
109 __u8 reserved1a4[68]; /* 0x01a4 */ 109 __u8 reserved1a4[20]; /* 0x01a4 */
110 __u64 cbrlo; /* 0x01b8 */
111 __u8 reserved1c0[40]; /* 0x01c0 */
110 __u64 itdba; /* 0x01e8 */ 112 __u64 itdba; /* 0x01e8 */
111 __u8 reserved1f0[16]; /* 0x01f0 */ 113 __u8 reserved1f0[16]; /* 0x01f0 */
112} __attribute__((packed)); 114} __attribute__((packed));
@@ -155,6 +157,7 @@ struct kvm_vcpu_stat {
155 u32 instruction_stsi; 157 u32 instruction_stsi;
156 u32 instruction_stfl; 158 u32 instruction_stfl;
157 u32 instruction_tprot; 159 u32 instruction_tprot;
160 u32 instruction_essa;
158 u32 instruction_sigp_sense; 161 u32 instruction_sigp_sense;
159 u32 instruction_sigp_sense_running; 162 u32 instruction_sigp_sense_running;
160 u32 instruction_sigp_external_call; 163 u32 instruction_sigp_external_call;
diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h
index 5d1f950704dc..38149b63dc44 100644
--- a/arch/s390/include/asm/mmu_context.h
+++ b/arch/s390/include/asm/mmu_context.h
@@ -48,13 +48,42 @@ static inline void update_mm(struct mm_struct *mm, struct task_struct *tsk)
48static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 48static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
49 struct task_struct *tsk) 49 struct task_struct *tsk)
50{ 50{
51 cpumask_set_cpu(smp_processor_id(), mm_cpumask(next)); 51 int cpu = smp_processor_id();
52 update_mm(next, tsk); 52
53 if (prev == next)
54 return;
55 if (atomic_inc_return(&next->context.attach_count) >> 16) {
56 /* Delay update_mm until all TLB flushes are done. */
57 set_tsk_thread_flag(tsk, TIF_TLB_WAIT);
58 } else {
59 cpumask_set_cpu(cpu, mm_cpumask(next));
60 update_mm(next, tsk);
61 if (next->context.flush_mm)
62 /* Flush pending TLBs */
63 __tlb_flush_mm(next);
64 }
53 atomic_dec(&prev->context.attach_count); 65 atomic_dec(&prev->context.attach_count);
54 WARN_ON(atomic_read(&prev->context.attach_count) < 0); 66 WARN_ON(atomic_read(&prev->context.attach_count) < 0);
55 atomic_inc(&next->context.attach_count); 67}
56 /* Check for TLBs not flushed yet */ 68
57 __tlb_flush_mm_lazy(next); 69#define finish_arch_post_lock_switch finish_arch_post_lock_switch
70static inline void finish_arch_post_lock_switch(void)
71{
72 struct task_struct *tsk = current;
73 struct mm_struct *mm = tsk->mm;
74
75 if (!test_tsk_thread_flag(tsk, TIF_TLB_WAIT))
76 return;
77 preempt_disable();
78 clear_tsk_thread_flag(tsk, TIF_TLB_WAIT);
79 while (atomic_read(&mm->context.attach_count) >> 16)
80 cpu_relax();
81
82 cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
83 update_mm(mm, tsk);
84 if (mm->context.flush_mm)
85 __tlb_flush_mm(mm);
86 preempt_enable();
58} 87}
59 88
60#define enter_lazy_tlb(mm,tsk) do { } while (0) 89#define enter_lazy_tlb(mm,tsk) do { } while (0)
diff --git a/arch/s390/include/asm/pgalloc.h b/arch/s390/include/asm/pgalloc.h
index e1408ddb94f8..884017cbfa9f 100644
--- a/arch/s390/include/asm/pgalloc.h
+++ b/arch/s390/include/asm/pgalloc.h
@@ -22,6 +22,7 @@ unsigned long *page_table_alloc(struct mm_struct *, unsigned long);
22void page_table_free(struct mm_struct *, unsigned long *); 22void page_table_free(struct mm_struct *, unsigned long *);
23void page_table_free_rcu(struct mmu_gather *, unsigned long *); 23void page_table_free_rcu(struct mmu_gather *, unsigned long *);
24 24
25void page_table_reset_pgste(struct mm_struct *, unsigned long, unsigned long);
25int set_guest_storage_key(struct mm_struct *mm, unsigned long addr, 26int set_guest_storage_key(struct mm_struct *mm, unsigned long addr,
26 unsigned long key, bool nq); 27 unsigned long key, bool nq);
27 28
@@ -91,11 +92,22 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
91static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr) 92static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
92{ 93{
93 unsigned long *table = crst_table_alloc(mm); 94 unsigned long *table = crst_table_alloc(mm);
94 if (table) 95
95 crst_table_init(table, _SEGMENT_ENTRY_EMPTY); 96 if (!table)
97 return NULL;
98 crst_table_init(table, _SEGMENT_ENTRY_EMPTY);
99 if (!pgtable_pmd_page_ctor(virt_to_page(table))) {
100 crst_table_free(mm, table);
101 return NULL;
102 }
96 return (pmd_t *) table; 103 return (pmd_t *) table;
97} 104}
98#define pmd_free(mm, pmd) crst_table_free(mm, (unsigned long *) pmd) 105
106static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
107{
108 pgtable_pmd_page_dtor(virt_to_page(pmd));
109 crst_table_free(mm, (unsigned long *) pmd);
110}
99 111
100static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud) 112static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
101{ 113{
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 2204400d0bd5..1ab75eaacbd4 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -229,6 +229,7 @@ extern unsigned long MODULES_END;
229#define _PAGE_READ 0x010 /* SW pte read bit */ 229#define _PAGE_READ 0x010 /* SW pte read bit */
230#define _PAGE_WRITE 0x020 /* SW pte write bit */ 230#define _PAGE_WRITE 0x020 /* SW pte write bit */
231#define _PAGE_SPECIAL 0x040 /* SW associated with special page */ 231#define _PAGE_SPECIAL 0x040 /* SW associated with special page */
232#define _PAGE_UNUSED 0x080 /* SW bit for pgste usage state */
232#define __HAVE_ARCH_PTE_SPECIAL 233#define __HAVE_ARCH_PTE_SPECIAL
233 234
234/* Set of bits not changed in pte_modify */ 235/* Set of bits not changed in pte_modify */
@@ -394,6 +395,12 @@ extern unsigned long MODULES_END;
394 395
395#endif /* CONFIG_64BIT */ 396#endif /* CONFIG_64BIT */
396 397
398/* Guest Page State used for virtualization */
399#define _PGSTE_GPS_ZERO 0x0000000080000000UL
400#define _PGSTE_GPS_USAGE_MASK 0x0000000003000000UL
401#define _PGSTE_GPS_USAGE_STABLE 0x0000000000000000UL
402#define _PGSTE_GPS_USAGE_UNUSED 0x0000000001000000UL
403
397/* 404/*
398 * A user page table pointer has the space-switch-event bit, the 405 * A user page table pointer has the space-switch-event bit, the
399 * private-space-control bit and the storage-alteration-event-control 406 * private-space-control bit and the storage-alteration-event-control
@@ -617,6 +624,14 @@ static inline int pte_none(pte_t pte)
617 return pte_val(pte) == _PAGE_INVALID; 624 return pte_val(pte) == _PAGE_INVALID;
618} 625}
619 626
627static inline int pte_swap(pte_t pte)
628{
629 /* Bit pattern: (pte & 0x603) == 0x402 */
630 return (pte_val(pte) & (_PAGE_INVALID | _PAGE_PROTECT |
631 _PAGE_TYPE | _PAGE_PRESENT))
632 == (_PAGE_INVALID | _PAGE_TYPE);
633}
634
620static inline int pte_file(pte_t pte) 635static inline int pte_file(pte_t pte)
621{ 636{
622 /* Bit pattern: (pte & 0x601) == 0x600 */ 637 /* Bit pattern: (pte & 0x601) == 0x600 */
@@ -821,20 +836,20 @@ unsigned long gmap_translate(unsigned long address, struct gmap *);
821unsigned long __gmap_fault(unsigned long address, struct gmap *); 836unsigned long __gmap_fault(unsigned long address, struct gmap *);
822unsigned long gmap_fault(unsigned long address, struct gmap *); 837unsigned long gmap_fault(unsigned long address, struct gmap *);
823void gmap_discard(unsigned long from, unsigned long to, struct gmap *); 838void gmap_discard(unsigned long from, unsigned long to, struct gmap *);
839void __gmap_zap(unsigned long address, struct gmap *);
824 840
825void gmap_register_ipte_notifier(struct gmap_notifier *); 841void gmap_register_ipte_notifier(struct gmap_notifier *);
826void gmap_unregister_ipte_notifier(struct gmap_notifier *); 842void gmap_unregister_ipte_notifier(struct gmap_notifier *);
827int gmap_ipte_notify(struct gmap *, unsigned long start, unsigned long len); 843int gmap_ipte_notify(struct gmap *, unsigned long start, unsigned long len);
828void gmap_do_ipte_notify(struct mm_struct *, unsigned long addr, pte_t *); 844void gmap_do_ipte_notify(struct mm_struct *, pte_t *);
829 845
830static inline pgste_t pgste_ipte_notify(struct mm_struct *mm, 846static inline pgste_t pgste_ipte_notify(struct mm_struct *mm,
831 unsigned long addr,
832 pte_t *ptep, pgste_t pgste) 847 pte_t *ptep, pgste_t pgste)
833{ 848{
834#ifdef CONFIG_PGSTE 849#ifdef CONFIG_PGSTE
835 if (pgste_val(pgste) & PGSTE_IN_BIT) { 850 if (pgste_val(pgste) & PGSTE_IN_BIT) {
836 pgste_val(pgste) &= ~PGSTE_IN_BIT; 851 pgste_val(pgste) &= ~PGSTE_IN_BIT;
837 gmap_do_ipte_notify(mm, addr, ptep); 852 gmap_do_ipte_notify(mm, ptep);
838 } 853 }
839#endif 854#endif
840 return pgste; 855 return pgste;
@@ -852,6 +867,7 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
852 867
853 if (mm_has_pgste(mm)) { 868 if (mm_has_pgste(mm)) {
854 pgste = pgste_get_lock(ptep); 869 pgste = pgste_get_lock(ptep);
870 pgste_val(pgste) &= ~_PGSTE_GPS_ZERO;
855 pgste_set_key(ptep, pgste, entry); 871 pgste_set_key(ptep, pgste, entry);
856 pgste_set_pte(ptep, entry); 872 pgste_set_pte(ptep, entry);
857 pgste_set_unlock(ptep, pgste); 873 pgste_set_unlock(ptep, pgste);
@@ -881,6 +897,12 @@ static inline int pte_young(pte_t pte)
881 return (pte_val(pte) & _PAGE_YOUNG) != 0; 897 return (pte_val(pte) & _PAGE_YOUNG) != 0;
882} 898}
883 899
900#define __HAVE_ARCH_PTE_UNUSED
901static inline int pte_unused(pte_t pte)
902{
903 return pte_val(pte) & _PAGE_UNUSED;
904}
905
884/* 906/*
885 * pgd/pmd/pte modification functions 907 * pgd/pmd/pte modification functions
886 */ 908 */
@@ -1034,30 +1056,41 @@ static inline int ptep_test_and_clear_user_young(struct mm_struct *mm,
1034 1056
1035static inline void __ptep_ipte(unsigned long address, pte_t *ptep) 1057static inline void __ptep_ipte(unsigned long address, pte_t *ptep)
1036{ 1058{
1037 if (!(pte_val(*ptep) & _PAGE_INVALID)) { 1059 unsigned long pto = (unsigned long) ptep;
1060
1038#ifndef CONFIG_64BIT 1061#ifndef CONFIG_64BIT
1039 /* pto must point to the start of the segment table */ 1062 /* pto in ESA mode must point to the start of the segment table */
1040 pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00); 1063 pto &= 0x7ffffc00;
1041#else
1042 /* ipte in zarch mode can do the math */
1043 pte_t *pto = ptep;
1044#endif 1064#endif
1045 asm volatile( 1065 /* Invalidation + global TLB flush for the pte */
1046 " ipte %2,%3" 1066 asm volatile(
1047 : "=m" (*ptep) : "m" (*ptep), 1067 " ipte %2,%3"
1048 "a" (pto), "a" (address)); 1068 : "=m" (*ptep) : "m" (*ptep), "a" (pto), "a" (address));
1049 } 1069}
1070
1071static inline void ptep_flush_direct(struct mm_struct *mm,
1072 unsigned long address, pte_t *ptep)
1073{
1074 if (pte_val(*ptep) & _PAGE_INVALID)
1075 return;
1076 __ptep_ipte(address, ptep);
1050} 1077}
1051 1078
1052static inline void ptep_flush_lazy(struct mm_struct *mm, 1079static inline void ptep_flush_lazy(struct mm_struct *mm,
1053 unsigned long address, pte_t *ptep) 1080 unsigned long address, pte_t *ptep)
1054{ 1081{
1055 int active = (mm == current->active_mm) ? 1 : 0; 1082 int active, count;
1056 1083
1057 if (atomic_read(&mm->context.attach_count) > active) 1084 if (pte_val(*ptep) & _PAGE_INVALID)
1058 __ptep_ipte(address, ptep); 1085 return;
1059 else 1086 active = (mm == current->active_mm) ? 1 : 0;
1087 count = atomic_add_return(0x10000, &mm->context.attach_count);
1088 if ((count & 0xffff) <= active) {
1089 pte_val(*ptep) |= _PAGE_INVALID;
1060 mm->context.flush_mm = 1; 1090 mm->context.flush_mm = 1;
1091 } else
1092 __ptep_ipte(address, ptep);
1093 atomic_sub(0x10000, &mm->context.attach_count);
1061} 1094}
1062 1095
1063#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 1096#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
@@ -1070,11 +1103,11 @@ static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
1070 1103
1071 if (mm_has_pgste(vma->vm_mm)) { 1104 if (mm_has_pgste(vma->vm_mm)) {
1072 pgste = pgste_get_lock(ptep); 1105 pgste = pgste_get_lock(ptep);
1073 pgste = pgste_ipte_notify(vma->vm_mm, addr, ptep, pgste); 1106 pgste = pgste_ipte_notify(vma->vm_mm, ptep, pgste);
1074 } 1107 }
1075 1108
1076 pte = *ptep; 1109 pte = *ptep;
1077 __ptep_ipte(addr, ptep); 1110 ptep_flush_direct(vma->vm_mm, addr, ptep);
1078 young = pte_young(pte); 1111 young = pte_young(pte);
1079 pte = pte_mkold(pte); 1112 pte = pte_mkold(pte);
1080 1113
@@ -1116,7 +1149,7 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
1116 1149
1117 if (mm_has_pgste(mm)) { 1150 if (mm_has_pgste(mm)) {
1118 pgste = pgste_get_lock(ptep); 1151 pgste = pgste_get_lock(ptep);
1119 pgste = pgste_ipte_notify(mm, address, ptep, pgste); 1152 pgste = pgste_ipte_notify(mm, ptep, pgste);
1120 } 1153 }
1121 1154
1122 pte = *ptep; 1155 pte = *ptep;
@@ -1140,12 +1173,11 @@ static inline pte_t ptep_modify_prot_start(struct mm_struct *mm,
1140 1173
1141 if (mm_has_pgste(mm)) { 1174 if (mm_has_pgste(mm)) {
1142 pgste = pgste_get_lock(ptep); 1175 pgste = pgste_get_lock(ptep);
1143 pgste_ipte_notify(mm, address, ptep, pgste); 1176 pgste_ipte_notify(mm, ptep, pgste);
1144 } 1177 }
1145 1178
1146 pte = *ptep; 1179 pte = *ptep;
1147 ptep_flush_lazy(mm, address, ptep); 1180 ptep_flush_lazy(mm, address, ptep);
1148 pte_val(*ptep) |= _PAGE_INVALID;
1149 1181
1150 if (mm_has_pgste(mm)) { 1182 if (mm_has_pgste(mm)) {
1151 pgste = pgste_update_all(&pte, pgste); 1183 pgste = pgste_update_all(&pte, pgste);
@@ -1178,14 +1210,17 @@ static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
1178 1210
1179 if (mm_has_pgste(vma->vm_mm)) { 1211 if (mm_has_pgste(vma->vm_mm)) {
1180 pgste = pgste_get_lock(ptep); 1212 pgste = pgste_get_lock(ptep);
1181 pgste = pgste_ipte_notify(vma->vm_mm, address, ptep, pgste); 1213 pgste = pgste_ipte_notify(vma->vm_mm, ptep, pgste);
1182 } 1214 }
1183 1215
1184 pte = *ptep; 1216 pte = *ptep;
1185 __ptep_ipte(address, ptep); 1217 ptep_flush_direct(vma->vm_mm, address, ptep);
1186 pte_val(*ptep) = _PAGE_INVALID; 1218 pte_val(*ptep) = _PAGE_INVALID;
1187 1219
1188 if (mm_has_pgste(vma->vm_mm)) { 1220 if (mm_has_pgste(vma->vm_mm)) {
1221 if ((pgste_val(pgste) & _PGSTE_GPS_USAGE_MASK) ==
1222 _PGSTE_GPS_USAGE_UNUSED)
1223 pte_val(pte) |= _PAGE_UNUSED;
1189 pgste = pgste_update_all(&pte, pgste); 1224 pgste = pgste_update_all(&pte, pgste);
1190 pgste_set_unlock(ptep, pgste); 1225 pgste_set_unlock(ptep, pgste);
1191 } 1226 }
@@ -1209,7 +1244,7 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
1209 1244
1210 if (!full && mm_has_pgste(mm)) { 1245 if (!full && mm_has_pgste(mm)) {
1211 pgste = pgste_get_lock(ptep); 1246 pgste = pgste_get_lock(ptep);
1212 pgste = pgste_ipte_notify(mm, address, ptep, pgste); 1247 pgste = pgste_ipte_notify(mm, ptep, pgste);
1213 } 1248 }
1214 1249
1215 pte = *ptep; 1250 pte = *ptep;
@@ -1234,7 +1269,7 @@ static inline pte_t ptep_set_wrprotect(struct mm_struct *mm,
1234 if (pte_write(pte)) { 1269 if (pte_write(pte)) {
1235 if (mm_has_pgste(mm)) { 1270 if (mm_has_pgste(mm)) {
1236 pgste = pgste_get_lock(ptep); 1271 pgste = pgste_get_lock(ptep);
1237 pgste = pgste_ipte_notify(mm, address, ptep, pgste); 1272 pgste = pgste_ipte_notify(mm, ptep, pgste);
1238 } 1273 }
1239 1274
1240 ptep_flush_lazy(mm, address, ptep); 1275 ptep_flush_lazy(mm, address, ptep);
@@ -1260,10 +1295,10 @@ static inline int ptep_set_access_flags(struct vm_area_struct *vma,
1260 return 0; 1295 return 0;
1261 if (mm_has_pgste(vma->vm_mm)) { 1296 if (mm_has_pgste(vma->vm_mm)) {
1262 pgste = pgste_get_lock(ptep); 1297 pgste = pgste_get_lock(ptep);
1263 pgste = pgste_ipte_notify(vma->vm_mm, address, ptep, pgste); 1298 pgste = pgste_ipte_notify(vma->vm_mm, ptep, pgste);
1264 } 1299 }
1265 1300
1266 __ptep_ipte(address, ptep); 1301 ptep_flush_direct(vma->vm_mm, address, ptep);
1267 1302
1268 if (mm_has_pgste(vma->vm_mm)) { 1303 if (mm_has_pgste(vma->vm_mm)) {
1269 pgste_set_pte(ptep, entry); 1304 pgste_set_pte(ptep, entry);
@@ -1447,12 +1482,16 @@ static inline pmd_t pmd_mkwrite(pmd_t pmd)
1447static inline void pmdp_flush_lazy(struct mm_struct *mm, 1482static inline void pmdp_flush_lazy(struct mm_struct *mm,
1448 unsigned long address, pmd_t *pmdp) 1483 unsigned long address, pmd_t *pmdp)
1449{ 1484{
1450 int active = (mm == current->active_mm) ? 1 : 0; 1485 int active, count;
1451 1486
1452 if ((atomic_read(&mm->context.attach_count) & 0xffff) > active) 1487 active = (mm == current->active_mm) ? 1 : 0;
1453 __pmd_idte(address, pmdp); 1488 count = atomic_add_return(0x10000, &mm->context.attach_count);
1454 else 1489 if ((count & 0xffff) <= active) {
1490 pmd_val(*pmdp) |= _SEGMENT_ENTRY_INVALID;
1455 mm->context.flush_mm = 1; 1491 mm->context.flush_mm = 1;
1492 } else
1493 __pmd_idte(address, pmdp);
1494 atomic_sub(0x10000, &mm->context.attach_count);
1456} 1495}
1457 1496
1458#ifdef CONFIG_TRANSPARENT_HUGEPAGE 1497#ifdef CONFIG_TRANSPARENT_HUGEPAGE
diff --git a/arch/s390/include/asm/ptrace.h b/arch/s390/include/asm/ptrace.h
index 9c82cebddabd..f4783c0b7b43 100644
--- a/arch/s390/include/asm/ptrace.h
+++ b/arch/s390/include/asm/ptrace.h
@@ -83,6 +83,7 @@ struct per_struct_kernel {
83 * These are defined as per linux/ptrace.h, which see. 83 * These are defined as per linux/ptrace.h, which see.
84 */ 84 */
85#define arch_has_single_step() (1) 85#define arch_has_single_step() (1)
86#define arch_has_block_step() (1)
86 87
87#define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0) 88#define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)
88#define instruction_pointer(regs) ((regs)->psw.addr & PSW_ADDR_INSN) 89#define instruction_pointer(regs) ((regs)->psw.addr & PSW_ADDR_INSN)
diff --git a/arch/s390/include/asm/sclp.h b/arch/s390/include/asm/sclp.h
index abaca2275c7a..2f5e9932b4de 100644
--- a/arch/s390/include/asm/sclp.h
+++ b/arch/s390/include/asm/sclp.h
@@ -46,6 +46,7 @@ int sclp_cpu_configure(u8 cpu);
46int sclp_cpu_deconfigure(u8 cpu); 46int sclp_cpu_deconfigure(u8 cpu);
47unsigned long long sclp_get_rnmax(void); 47unsigned long long sclp_get_rnmax(void);
48unsigned long long sclp_get_rzm(void); 48unsigned long long sclp_get_rzm(void);
49unsigned int sclp_get_max_cpu(void);
49int sclp_sdias_blk_count(void); 50int sclp_sdias_blk_count(void);
50int sclp_sdias_copy(void *dest, int blk_num, int nr_blks); 51int sclp_sdias_copy(void *dest, int blk_num, int nr_blks);
51int sclp_chp_configure(struct chp_id chpid); 52int sclp_chp_configure(struct chp_id chpid);
diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h
index 94cfbe442f12..406f3a1e63ef 100644
--- a/arch/s390/include/asm/setup.h
+++ b/arch/s390/include/asm/setup.h
@@ -59,7 +59,6 @@ void create_mem_hole(struct mem_chunk mem_chunk[], unsigned long addr,
59#define MACHINE_FLAG_DIAG44 (1UL << 4) 59#define MACHINE_FLAG_DIAG44 (1UL << 4)
60#define MACHINE_FLAG_IDTE (1UL << 5) 60#define MACHINE_FLAG_IDTE (1UL << 5)
61#define MACHINE_FLAG_DIAG9C (1UL << 6) 61#define MACHINE_FLAG_DIAG9C (1UL << 6)
62#define MACHINE_FLAG_MVCOS (1UL << 7)
63#define MACHINE_FLAG_KVM (1UL << 8) 62#define MACHINE_FLAG_KVM (1UL << 8)
64#define MACHINE_FLAG_ESOP (1UL << 9) 63#define MACHINE_FLAG_ESOP (1UL << 9)
65#define MACHINE_FLAG_EDAT1 (1UL << 10) 64#define MACHINE_FLAG_EDAT1 (1UL << 10)
@@ -85,7 +84,6 @@ void create_mem_hole(struct mem_chunk mem_chunk[], unsigned long addr,
85#define MACHINE_HAS_IDTE (0) 84#define MACHINE_HAS_IDTE (0)
86#define MACHINE_HAS_DIAG44 (1) 85#define MACHINE_HAS_DIAG44 (1)
87#define MACHINE_HAS_MVPG (S390_lowcore.machine_flags & MACHINE_FLAG_MVPG) 86#define MACHINE_HAS_MVPG (S390_lowcore.machine_flags & MACHINE_FLAG_MVPG)
88#define MACHINE_HAS_MVCOS (0)
89#define MACHINE_HAS_EDAT1 (0) 87#define MACHINE_HAS_EDAT1 (0)
90#define MACHINE_HAS_EDAT2 (0) 88#define MACHINE_HAS_EDAT2 (0)
91#define MACHINE_HAS_LPP (0) 89#define MACHINE_HAS_LPP (0)
@@ -98,7 +96,6 @@ void create_mem_hole(struct mem_chunk mem_chunk[], unsigned long addr,
98#define MACHINE_HAS_IDTE (S390_lowcore.machine_flags & MACHINE_FLAG_IDTE) 96#define MACHINE_HAS_IDTE (S390_lowcore.machine_flags & MACHINE_FLAG_IDTE)
99#define MACHINE_HAS_DIAG44 (S390_lowcore.machine_flags & MACHINE_FLAG_DIAG44) 97#define MACHINE_HAS_DIAG44 (S390_lowcore.machine_flags & MACHINE_FLAG_DIAG44)
100#define MACHINE_HAS_MVPG (1) 98#define MACHINE_HAS_MVPG (1)
101#define MACHINE_HAS_MVCOS (S390_lowcore.machine_flags & MACHINE_FLAG_MVCOS)
102#define MACHINE_HAS_EDAT1 (S390_lowcore.machine_flags & MACHINE_FLAG_EDAT1) 99#define MACHINE_HAS_EDAT1 (S390_lowcore.machine_flags & MACHINE_FLAG_EDAT1)
103#define MACHINE_HAS_EDAT2 (S390_lowcore.machine_flags & MACHINE_FLAG_EDAT2) 100#define MACHINE_HAS_EDAT2 (S390_lowcore.machine_flags & MACHINE_FLAG_EDAT2)
104#define MACHINE_HAS_LPP (S390_lowcore.machine_flags & MACHINE_FLAG_LPP) 101#define MACHINE_HAS_LPP (S390_lowcore.machine_flags & MACHINE_FLAG_LPP)
diff --git a/arch/s390/include/asm/thread_info.h b/arch/s390/include/asm/thread_info.h
index 10e0fcd3633d..3ccd71b90345 100644
--- a/arch/s390/include/asm/thread_info.h
+++ b/arch/s390/include/asm/thread_info.h
@@ -81,6 +81,7 @@ static inline struct thread_info *current_thread_info(void)
81#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */ 81#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
82#define TIF_SIGPENDING 2 /* signal pending */ 82#define TIF_SIGPENDING 2 /* signal pending */
83#define TIF_NEED_RESCHED 3 /* rescheduling necessary */ 83#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
84#define TIF_TLB_WAIT 4 /* wait for TLB flush completion */
84#define TIF_PER_TRAP 6 /* deliver sigtrap on return to user */ 85#define TIF_PER_TRAP 6 /* deliver sigtrap on return to user */
85#define TIF_MCCK_PENDING 7 /* machine check handling is pending */ 86#define TIF_MCCK_PENDING 7 /* machine check handling is pending */
86#define TIF_SYSCALL_TRACE 8 /* syscall trace active */ 87#define TIF_SYSCALL_TRACE 8 /* syscall trace active */
@@ -91,11 +92,13 @@ static inline struct thread_info *current_thread_info(void)
91#define TIF_MEMDIE 18 /* is terminating due to OOM killer */ 92#define TIF_MEMDIE 18 /* is terminating due to OOM killer */
92#define TIF_RESTORE_SIGMASK 19 /* restore signal mask in do_signal() */ 93#define TIF_RESTORE_SIGMASK 19 /* restore signal mask in do_signal() */
93#define TIF_SINGLE_STEP 20 /* This task is single stepped */ 94#define TIF_SINGLE_STEP 20 /* This task is single stepped */
95#define TIF_BLOCK_STEP 21 /* This task is block stepped */
94 96
95#define _TIF_SYSCALL (1<<TIF_SYSCALL) 97#define _TIF_SYSCALL (1<<TIF_SYSCALL)
96#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME) 98#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
97#define _TIF_SIGPENDING (1<<TIF_SIGPENDING) 99#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
98#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED) 100#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
101#define _TIF_TLB_WAIT (1<<TIF_TLB_WAIT)
99#define _TIF_PER_TRAP (1<<TIF_PER_TRAP) 102#define _TIF_PER_TRAP (1<<TIF_PER_TRAP)
100#define _TIF_MCCK_PENDING (1<<TIF_MCCK_PENDING) 103#define _TIF_MCCK_PENDING (1<<TIF_MCCK_PENDING)
101#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) 104#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
index 79330af9a5f8..4133b3f72fb0 100644
--- a/arch/s390/include/asm/uaccess.h
+++ b/arch/s390/include/asm/uaccess.h
@@ -92,33 +92,58 @@ static inline unsigned long extable_fixup(const struct exception_table_entry *x)
92#define ARCH_HAS_SORT_EXTABLE 92#define ARCH_HAS_SORT_EXTABLE
93#define ARCH_HAS_SEARCH_EXTABLE 93#define ARCH_HAS_SEARCH_EXTABLE
94 94
95struct uaccess_ops { 95int __handle_fault(unsigned long, unsigned long, int);
96 size_t (*copy_from_user)(size_t, const void __user *, void *);
97 size_t (*copy_to_user)(size_t, void __user *, const void *);
98 size_t (*copy_in_user)(size_t, void __user *, const void __user *);
99 size_t (*clear_user)(size_t, void __user *);
100 size_t (*strnlen_user)(size_t, const char __user *);
101 size_t (*strncpy_from_user)(size_t, const char __user *, char *);
102 int (*futex_atomic_op)(int op, u32 __user *, int oparg, int *old);
103 int (*futex_atomic_cmpxchg)(u32 *, u32 __user *, u32 old, u32 new);
104};
105 96
106extern struct uaccess_ops uaccess; 97/**
107extern struct uaccess_ops uaccess_mvcos; 98 * __copy_from_user: - Copy a block of data from user space, with less checking.
108extern struct uaccess_ops uaccess_pt; 99 * @to: Destination address, in kernel space.
100 * @from: Source address, in user space.
101 * @n: Number of bytes to copy.
102 *
103 * Context: User context only. This function may sleep.
104 *
105 * Copy data from user space to kernel space. Caller must check
106 * the specified block with access_ok() before calling this function.
107 *
108 * Returns number of bytes that could not be copied.
109 * On success, this will be zero.
110 *
111 * If some data could not be copied, this function will pad the copied
112 * data to the requested size using zero bytes.
113 */
114unsigned long __must_check __copy_from_user(void *to, const void __user *from,
115 unsigned long n);
116
117/**
118 * __copy_to_user: - Copy a block of data into user space, with less checking.
119 * @to: Destination address, in user space.
120 * @from: Source address, in kernel space.
121 * @n: Number of bytes to copy.
122 *
123 * Context: User context only. This function may sleep.
124 *
125 * Copy data from kernel space to user space. Caller must check
126 * the specified block with access_ok() before calling this function.
127 *
128 * Returns number of bytes that could not be copied.
129 * On success, this will be zero.
130 */
131unsigned long __must_check __copy_to_user(void __user *to, const void *from,
132 unsigned long n);
109 133
110extern int __handle_fault(unsigned long, unsigned long, int); 134#define __copy_to_user_inatomic __copy_to_user
135#define __copy_from_user_inatomic __copy_from_user
111 136
112static inline int __put_user_fn(size_t size, void __user *ptr, void *x) 137static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
113{ 138{
114 size = uaccess.copy_to_user(size, ptr, x); 139 size = __copy_to_user(ptr, x, size);
115 return size ? -EFAULT : size; 140 return size ? -EFAULT : 0;
116} 141}
117 142
118static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) 143static inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size)
119{ 144{
120 size = uaccess.copy_from_user(size, ptr, x); 145 size = __copy_from_user(x, ptr, size);
121 return size ? -EFAULT : size; 146 return size ? -EFAULT : 0;
122} 147}
123 148
124/* 149/*
@@ -135,8 +160,8 @@ static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
135 case 2: \ 160 case 2: \
136 case 4: \ 161 case 4: \
137 case 8: \ 162 case 8: \
138 __pu_err = __put_user_fn(sizeof (*(ptr)), \ 163 __pu_err = __put_user_fn(&__x, ptr, \
139 ptr, &__x); \ 164 sizeof(*(ptr))); \
140 break; \ 165 break; \
141 default: \ 166 default: \
142 __put_user_bad(); \ 167 __put_user_bad(); \
@@ -152,7 +177,7 @@ static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
152}) 177})
153 178
154 179
155extern int __put_user_bad(void) __attribute__((noreturn)); 180int __put_user_bad(void) __attribute__((noreturn));
156 181
157#define __get_user(x, ptr) \ 182#define __get_user(x, ptr) \
158({ \ 183({ \
@@ -161,29 +186,29 @@ extern int __put_user_bad(void) __attribute__((noreturn));
161 switch (sizeof(*(ptr))) { \ 186 switch (sizeof(*(ptr))) { \
162 case 1: { \ 187 case 1: { \
163 unsigned char __x; \ 188 unsigned char __x; \
164 __gu_err = __get_user_fn(sizeof (*(ptr)), \ 189 __gu_err = __get_user_fn(&__x, ptr, \
165 ptr, &__x); \ 190 sizeof(*(ptr))); \
166 (x) = *(__force __typeof__(*(ptr)) *) &__x; \ 191 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
167 break; \ 192 break; \
168 }; \ 193 }; \
169 case 2: { \ 194 case 2: { \
170 unsigned short __x; \ 195 unsigned short __x; \
171 __gu_err = __get_user_fn(sizeof (*(ptr)), \ 196 __gu_err = __get_user_fn(&__x, ptr, \
172 ptr, &__x); \ 197 sizeof(*(ptr))); \
173 (x) = *(__force __typeof__(*(ptr)) *) &__x; \ 198 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
174 break; \ 199 break; \
175 }; \ 200 }; \
176 case 4: { \ 201 case 4: { \
177 unsigned int __x; \ 202 unsigned int __x; \
178 __gu_err = __get_user_fn(sizeof (*(ptr)), \ 203 __gu_err = __get_user_fn(&__x, ptr, \
179 ptr, &__x); \ 204 sizeof(*(ptr))); \
180 (x) = *(__force __typeof__(*(ptr)) *) &__x; \ 205 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
181 break; \ 206 break; \
182 }; \ 207 }; \
183 case 8: { \ 208 case 8: { \
184 unsigned long long __x; \ 209 unsigned long long __x; \
185 __gu_err = __get_user_fn(sizeof (*(ptr)), \ 210 __gu_err = __get_user_fn(&__x, ptr, \
186 ptr, &__x); \ 211 sizeof(*(ptr))); \
187 (x) = *(__force __typeof__(*(ptr)) *) &__x; \ 212 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
188 break; \ 213 break; \
189 }; \ 214 }; \
@@ -200,35 +225,12 @@ extern int __put_user_bad(void) __attribute__((noreturn));
200 __get_user(x, ptr); \ 225 __get_user(x, ptr); \
201}) 226})
202 227
203extern int __get_user_bad(void) __attribute__((noreturn)); 228int __get_user_bad(void) __attribute__((noreturn));
204 229
205#define __put_user_unaligned __put_user 230#define __put_user_unaligned __put_user
206#define __get_user_unaligned __get_user 231#define __get_user_unaligned __get_user
207 232
208/** 233/**
209 * __copy_to_user: - Copy a block of data into user space, with less checking.
210 * @to: Destination address, in user space.
211 * @from: Source address, in kernel space.
212 * @n: Number of bytes to copy.
213 *
214 * Context: User context only. This function may sleep.
215 *
216 * Copy data from kernel space to user space. Caller must check
217 * the specified block with access_ok() before calling this function.
218 *
219 * Returns number of bytes that could not be copied.
220 * On success, this will be zero.
221 */
222static inline unsigned long __must_check
223__copy_to_user(void __user *to, const void *from, unsigned long n)
224{
225 return uaccess.copy_to_user(n, to, from);
226}
227
228#define __copy_to_user_inatomic __copy_to_user
229#define __copy_from_user_inatomic __copy_from_user
230
231/**
232 * copy_to_user: - Copy a block of data into user space. 234 * copy_to_user: - Copy a block of data into user space.
233 * @to: Destination address, in user space. 235 * @to: Destination address, in user space.
234 * @from: Source address, in kernel space. 236 * @from: Source address, in kernel space.
@@ -248,30 +250,7 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
248 return __copy_to_user(to, from, n); 250 return __copy_to_user(to, from, n);
249} 251}
250 252
251/** 253void copy_from_user_overflow(void)
252 * __copy_from_user: - Copy a block of data from user space, with less checking.
253 * @to: Destination address, in kernel space.
254 * @from: Source address, in user space.
255 * @n: Number of bytes to copy.
256 *
257 * Context: User context only. This function may sleep.
258 *
259 * Copy data from user space to kernel space. Caller must check
260 * the specified block with access_ok() before calling this function.
261 *
262 * Returns number of bytes that could not be copied.
263 * On success, this will be zero.
264 *
265 * If some data could not be copied, this function will pad the copied
266 * data to the requested size using zero bytes.
267 */
268static inline unsigned long __must_check
269__copy_from_user(void *to, const void __user *from, unsigned long n)
270{
271 return uaccess.copy_from_user(n, from, to);
272}
273
274extern void copy_from_user_overflow(void)
275#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS 254#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
276__compiletime_warning("copy_from_user() buffer size is not provably correct") 255__compiletime_warning("copy_from_user() buffer size is not provably correct")
277#endif 256#endif
@@ -306,11 +285,8 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
306 return __copy_from_user(to, from, n); 285 return __copy_from_user(to, from, n);
307} 286}
308 287
309static inline unsigned long __must_check 288unsigned long __must_check
310__copy_in_user(void __user *to, const void __user *from, unsigned long n) 289__copy_in_user(void __user *to, const void __user *from, unsigned long n);
311{
312 return uaccess.copy_in_user(n, to, from);
313}
314 290
315static inline unsigned long __must_check 291static inline unsigned long __must_check
316copy_in_user(void __user *to, const void __user *from, unsigned long n) 292copy_in_user(void __user *to, const void __user *from, unsigned long n)
@@ -322,18 +298,22 @@ copy_in_user(void __user *to, const void __user *from, unsigned long n)
322/* 298/*
323 * Copy a null terminated string from userspace. 299 * Copy a null terminated string from userspace.
324 */ 300 */
301
302long __strncpy_from_user(char *dst, const char __user *src, long count);
303
325static inline long __must_check 304static inline long __must_check
326strncpy_from_user(char *dst, const char __user *src, long count) 305strncpy_from_user(char *dst, const char __user *src, long count)
327{ 306{
328 might_fault(); 307 might_fault();
329 return uaccess.strncpy_from_user(count, src, dst); 308 return __strncpy_from_user(dst, src, count);
330} 309}
331 310
332static inline unsigned long 311unsigned long __must_check __strnlen_user(const char __user *src, unsigned long count);
333strnlen_user(const char __user * src, unsigned long n) 312
313static inline unsigned long strnlen_user(const char __user *src, unsigned long n)
334{ 314{
335 might_fault(); 315 might_fault();
336 return uaccess.strnlen_user(n, src); 316 return __strnlen_user(src, n);
337} 317}
338 318
339/** 319/**
@@ -355,21 +335,14 @@ strnlen_user(const char __user * src, unsigned long n)
355/* 335/*
356 * Zero Userspace 336 * Zero Userspace
357 */ 337 */
338unsigned long __must_check __clear_user(void __user *to, unsigned long size);
358 339
359static inline unsigned long __must_check 340static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
360__clear_user(void __user *to, unsigned long n)
361{
362 return uaccess.clear_user(n, to);
363}
364
365static inline unsigned long __must_check
366clear_user(void __user *to, unsigned long n)
367{ 341{
368 might_fault(); 342 might_fault();
369 return uaccess.clear_user(n, to); 343 return __clear_user(to, n);
370} 344}
371 345
372extern int copy_to_user_real(void __user *dest, void *src, size_t count); 346int copy_to_user_real(void __user *dest, void *src, unsigned long count);
373extern int copy_from_user_real(void *dest, void __user *src, size_t count);
374 347
375#endif /* __S390_UACCESS_H */ 348#endif /* __S390_UACCESS_H */
diff --git a/arch/s390/include/uapi/asm/ptrace.h b/arch/s390/include/uapi/asm/ptrace.h
index 7e0b498a2c2b..a150f4fabe43 100644
--- a/arch/s390/include/uapi/asm/ptrace.h
+++ b/arch/s390/include/uapi/asm/ptrace.h
@@ -403,6 +403,12 @@ typedef struct
403#define PTRACE_TE_ABORT_RAND 0x5011 403#define PTRACE_TE_ABORT_RAND 0x5011
404 404
405/* 405/*
406 * The numbers chosen here are somewhat arbitrary but absolutely MUST
407 * not overlap with any of the number assigned in <linux/ptrace.h>.
408 */
409#define PTRACE_SINGLEBLOCK 12 /* resume execution until next branch */
410
411/*
406 * PT_PROT definition is loosely based on hppa bsd definition in 412 * PT_PROT definition is loosely based on hppa bsd definition in
407 * gdb/hppab-nat.c 413 * gdb/hppab-nat.c
408 */ 414 */
diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
index 1b3ac09c11b6..a95c4ca99617 100644
--- a/arch/s390/kernel/Makefile
+++ b/arch/s390/kernel/Makefile
@@ -47,9 +47,8 @@ obj-$(CONFIG_SCHED_BOOK) += topology.o
47obj-$(CONFIG_HIBERNATION) += suspend.o swsusp_asm64.o 47obj-$(CONFIG_HIBERNATION) += suspend.o swsusp_asm64.o
48obj-$(CONFIG_AUDIT) += audit.o 48obj-$(CONFIG_AUDIT) += audit.o
49compat-obj-$(CONFIG_AUDIT) += compat_audit.o 49compat-obj-$(CONFIG_AUDIT) += compat_audit.o
50obj-$(CONFIG_COMPAT) += compat_linux.o compat_signal.o \ 50obj-$(CONFIG_COMPAT) += compat_linux.o compat_signal.o
51 compat_wrapper.o compat_exec_domain.o \ 51obj-$(CONFIG_COMPAT) += compat_wrapper.o $(compat-obj-y)
52 $(compat-obj-y)
53 52
54obj-$(CONFIG_STACKTRACE) += stacktrace.o 53obj-$(CONFIG_STACKTRACE) += stacktrace.o
55obj-$(CONFIG_KPROBES) += kprobes.o 54obj-$(CONFIG_KPROBES) += kprobes.o
diff --git a/arch/s390/kernel/compat_exec_domain.c b/arch/s390/kernel/compat_exec_domain.c
deleted file mode 100644
index 765fabdada9f..000000000000
--- a/arch/s390/kernel/compat_exec_domain.c
+++ /dev/null
@@ -1,29 +0,0 @@
1/*
2 * Support for 32-bit Linux for S390 personality.
3 *
4 * Copyright IBM Corp. 2000
5 * Author(s): Gerhard Tonn (ton@de.ibm.com)
6 *
7 *
8 */
9
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/personality.h>
13#include <linux/sched.h>
14
15static struct exec_domain s390_exec_domain;
16
17static int __init s390_init (void)
18{
19 s390_exec_domain.name = "Linux/s390";
20 s390_exec_domain.handler = NULL;
21 s390_exec_domain.pers_low = PER_LINUX32;
22 s390_exec_domain.pers_high = PER_LINUX32;
23 s390_exec_domain.signal_map = default_exec_domain.signal_map;
24 s390_exec_domain.signal_invmap = default_exec_domain.signal_invmap;
25 register_exec_domain(&s390_exec_domain);
26 return 0;
27}
28
29__initcall(s390_init);
diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c
index db02052bd137..ca38139423ae 100644
--- a/arch/s390/kernel/compat_linux.c
+++ b/arch/s390/kernel/compat_linux.c
@@ -86,48 +86,51 @@
86#define SET_STAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid) 86#define SET_STAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
87#define SET_STAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid) 87#define SET_STAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
88 88
89asmlinkage long sys32_chown16(const char __user * filename, u16 user, u16 group) 89COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
90 u16, user, u16, group)
90{ 91{
91 return sys_chown(filename, low2highuid(user), low2highgid(group)); 92 return sys_chown(filename, low2highuid(user), low2highgid(group));
92} 93}
93 94
94asmlinkage long sys32_lchown16(const char __user * filename, u16 user, u16 group) 95COMPAT_SYSCALL_DEFINE3(s390_lchown16, const char __user *,
96 filename, u16, user, u16, group)
95{ 97{
96 return sys_lchown(filename, low2highuid(user), low2highgid(group)); 98 return sys_lchown(filename, low2highuid(user), low2highgid(group));
97} 99}
98 100
99asmlinkage long sys32_fchown16(unsigned int fd, u16 user, u16 group) 101COMPAT_SYSCALL_DEFINE3(s390_fchown16, unsigned int, fd, u16, user, u16, group)
100{ 102{
101 return sys_fchown(fd, low2highuid(user), low2highgid(group)); 103 return sys_fchown(fd, low2highuid(user), low2highgid(group));
102} 104}
103 105
104asmlinkage long sys32_setregid16(u16 rgid, u16 egid) 106COMPAT_SYSCALL_DEFINE2(s390_setregid16, u16, rgid, u16, egid)
105{ 107{
106 return sys_setregid(low2highgid(rgid), low2highgid(egid)); 108 return sys_setregid(low2highgid(rgid), low2highgid(egid));
107} 109}
108 110
109asmlinkage long sys32_setgid16(u16 gid) 111COMPAT_SYSCALL_DEFINE1(s390_setgid16, u16, gid)
110{ 112{
111 return sys_setgid((gid_t)gid); 113 return sys_setgid((gid_t)gid);
112} 114}
113 115
114asmlinkage long sys32_setreuid16(u16 ruid, u16 euid) 116COMPAT_SYSCALL_DEFINE2(s390_setreuid16, u16, ruid, u16, euid)
115{ 117{
116 return sys_setreuid(low2highuid(ruid), low2highuid(euid)); 118 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
117} 119}
118 120
119asmlinkage long sys32_setuid16(u16 uid) 121COMPAT_SYSCALL_DEFINE1(s390_setuid16, u16, uid)
120{ 122{
121 return sys_setuid((uid_t)uid); 123 return sys_setuid((uid_t)uid);
122} 124}
123 125
124asmlinkage long sys32_setresuid16(u16 ruid, u16 euid, u16 suid) 126COMPAT_SYSCALL_DEFINE3(s390_setresuid16, u16, ruid, u16, euid, u16, suid)
125{ 127{
126 return sys_setresuid(low2highuid(ruid), low2highuid(euid), 128 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
127 low2highuid(suid)); 129 low2highuid(suid));
128} 130}
129 131
130asmlinkage long sys32_getresuid16(u16 __user *ruidp, u16 __user *euidp, u16 __user *suidp) 132COMPAT_SYSCALL_DEFINE3(s390_getresuid16, u16 __user *, ruidp,
133 u16 __user *, euidp, u16 __user *, suidp)
131{ 134{
132 const struct cred *cred = current_cred(); 135 const struct cred *cred = current_cred();
133 int retval; 136 int retval;
@@ -144,13 +147,14 @@ asmlinkage long sys32_getresuid16(u16 __user *ruidp, u16 __user *euidp, u16 __us
144 return retval; 147 return retval;
145} 148}
146 149
147asmlinkage long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid) 150COMPAT_SYSCALL_DEFINE3(s390_setresgid16, u16, rgid, u16, egid, u16, sgid)
148{ 151{
149 return sys_setresgid(low2highgid(rgid), low2highgid(egid), 152 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
150 low2highgid(sgid)); 153 low2highgid(sgid));
151} 154}
152 155
153asmlinkage long sys32_getresgid16(u16 __user *rgidp, u16 __user *egidp, u16 __user *sgidp) 156COMPAT_SYSCALL_DEFINE3(s390_getresgid16, u16 __user *, rgidp,
157 u16 __user *, egidp, u16 __user *, sgidp)
154{ 158{
155 const struct cred *cred = current_cred(); 159 const struct cred *cred = current_cred();
156 int retval; 160 int retval;
@@ -167,12 +171,12 @@ asmlinkage long sys32_getresgid16(u16 __user *rgidp, u16 __user *egidp, u16 __us
167 return retval; 171 return retval;
168} 172}
169 173
170asmlinkage long sys32_setfsuid16(u16 uid) 174COMPAT_SYSCALL_DEFINE1(s390_setfsuid16, u16, uid)
171{ 175{
172 return sys_setfsuid((uid_t)uid); 176 return sys_setfsuid((uid_t)uid);
173} 177}
174 178
175asmlinkage long sys32_setfsgid16(u16 gid) 179COMPAT_SYSCALL_DEFINE1(s390_setfsgid16, u16, gid)
176{ 180{
177 return sys_setfsgid((gid_t)gid); 181 return sys_setfsgid((gid_t)gid);
178} 182}
@@ -215,7 +219,7 @@ static int groups16_from_user(struct group_info *group_info, u16 __user *groupli
215 return 0; 219 return 0;
216} 220}
217 221
218asmlinkage long sys32_getgroups16(int gidsetsize, u16 __user *grouplist) 222COMPAT_SYSCALL_DEFINE2(s390_getgroups16, int, gidsetsize, u16 __user *, grouplist)
219{ 223{
220 const struct cred *cred = current_cred(); 224 const struct cred *cred = current_cred();
221 int i; 225 int i;
@@ -240,7 +244,7 @@ out:
240 return i; 244 return i;
241} 245}
242 246
243asmlinkage long sys32_setgroups16(int gidsetsize, u16 __user *grouplist) 247COMPAT_SYSCALL_DEFINE2(s390_setgroups16, int, gidsetsize, u16 __user *, grouplist)
244{ 248{
245 struct group_info *group_info; 249 struct group_info *group_info;
246 int retval; 250 int retval;
@@ -265,22 +269,22 @@ asmlinkage long sys32_setgroups16(int gidsetsize, u16 __user *grouplist)
265 return retval; 269 return retval;
266} 270}
267 271
268asmlinkage long sys32_getuid16(void) 272COMPAT_SYSCALL_DEFINE0(s390_getuid16)
269{ 273{
270 return high2lowuid(from_kuid_munged(current_user_ns(), current_uid())); 274 return high2lowuid(from_kuid_munged(current_user_ns(), current_uid()));
271} 275}
272 276
273asmlinkage long sys32_geteuid16(void) 277COMPAT_SYSCALL_DEFINE0(s390_geteuid16)
274{ 278{
275 return high2lowuid(from_kuid_munged(current_user_ns(), current_euid())); 279 return high2lowuid(from_kuid_munged(current_user_ns(), current_euid()));
276} 280}
277 281
278asmlinkage long sys32_getgid16(void) 282COMPAT_SYSCALL_DEFINE0(s390_getgid16)
279{ 283{
280 return high2lowgid(from_kgid_munged(current_user_ns(), current_gid())); 284 return high2lowgid(from_kgid_munged(current_user_ns(), current_gid()));
281} 285}
282 286
283asmlinkage long sys32_getegid16(void) 287COMPAT_SYSCALL_DEFINE0(s390_getegid16)
284{ 288{
285 return high2lowgid(from_kgid_munged(current_user_ns(), current_egid())); 289 return high2lowgid(from_kgid_munged(current_user_ns(), current_egid()));
286} 290}
@@ -295,41 +299,35 @@ COMPAT_SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, compat_ulong_t, second,
295} 299}
296#endif 300#endif
297 301
298asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low) 302COMPAT_SYSCALL_DEFINE3(s390_truncate64, const char __user *, path, u32, high, u32, low)
299{ 303{
300 if ((int)high < 0) 304 return sys_truncate(path, (unsigned long)high << 32 | low);
301 return -EINVAL;
302 else
303 return sys_truncate(path, (high << 32) | low);
304} 305}
305 306
306asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low) 307COMPAT_SYSCALL_DEFINE3(s390_ftruncate64, unsigned int, fd, u32, high, u32, low)
307{ 308{
308 if ((int)high < 0) 309 return sys_ftruncate(fd, (unsigned long)high << 32 | low);
309 return -EINVAL;
310 else
311 return sys_ftruncate(fd, (high << 32) | low);
312} 310}
313 311
314asmlinkage long sys32_pread64(unsigned int fd, char __user *ubuf, 312COMPAT_SYSCALL_DEFINE5(s390_pread64, unsigned int, fd, char __user *, ubuf,
315 size_t count, u32 poshi, u32 poslo) 313 compat_size_t, count, u32, high, u32, low)
316{ 314{
317 if ((compat_ssize_t) count < 0) 315 if ((compat_ssize_t) count < 0)
318 return -EINVAL; 316 return -EINVAL;
319 return sys_pread64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo)); 317 return sys_pread64(fd, ubuf, count, (unsigned long)high << 32 | low);
320} 318}
321 319
322asmlinkage long sys32_pwrite64(unsigned int fd, const char __user *ubuf, 320COMPAT_SYSCALL_DEFINE5(s390_pwrite64, unsigned int, fd, const char __user *, ubuf,
323 size_t count, u32 poshi, u32 poslo) 321 compat_size_t, count, u32, high, u32, low)
324{ 322{
325 if ((compat_ssize_t) count < 0) 323 if ((compat_ssize_t) count < 0)
326 return -EINVAL; 324 return -EINVAL;
327 return sys_pwrite64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo)); 325 return sys_pwrite64(fd, ubuf, count, (unsigned long)high << 32 | low);
328} 326}
329 327
330asmlinkage compat_ssize_t sys32_readahead(int fd, u32 offhi, u32 offlo, s32 count) 328COMPAT_SYSCALL_DEFINE4(s390_readahead, int, fd, u32, high, u32, low, s32, count)
331{ 329{
332 return sys_readahead(fd, ((loff_t)AA(offhi) << 32) | AA(offlo), count); 330 return sys_readahead(fd, (unsigned long)high << 32 | low, count);
333} 331}
334 332
335struct stat64_emu31 { 333struct stat64_emu31 {
@@ -381,7 +379,7 @@ static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
381 return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0; 379 return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
382} 380}
383 381
384asmlinkage long sys32_stat64(const char __user * filename, struct stat64_emu31 __user * statbuf) 382COMPAT_SYSCALL_DEFINE2(s390_stat64, const char __user *, filename, struct stat64_emu31 __user *, statbuf)
385{ 383{
386 struct kstat stat; 384 struct kstat stat;
387 int ret = vfs_stat(filename, &stat); 385 int ret = vfs_stat(filename, &stat);
@@ -390,7 +388,7 @@ asmlinkage long sys32_stat64(const char __user * filename, struct stat64_emu31 _
390 return ret; 388 return ret;
391} 389}
392 390
393asmlinkage long sys32_lstat64(const char __user * filename, struct stat64_emu31 __user * statbuf) 391COMPAT_SYSCALL_DEFINE2(s390_lstat64, const char __user *, filename, struct stat64_emu31 __user *, statbuf)
394{ 392{
395 struct kstat stat; 393 struct kstat stat;
396 int ret = vfs_lstat(filename, &stat); 394 int ret = vfs_lstat(filename, &stat);
@@ -399,7 +397,7 @@ asmlinkage long sys32_lstat64(const char __user * filename, struct stat64_emu31
399 return ret; 397 return ret;
400} 398}
401 399
402asmlinkage long sys32_fstat64(unsigned long fd, struct stat64_emu31 __user * statbuf) 400COMPAT_SYSCALL_DEFINE2(s390_fstat64, unsigned int, fd, struct stat64_emu31 __user *, statbuf)
403{ 401{
404 struct kstat stat; 402 struct kstat stat;
405 int ret = vfs_fstat(fd, &stat); 403 int ret = vfs_fstat(fd, &stat);
@@ -408,8 +406,8 @@ asmlinkage long sys32_fstat64(unsigned long fd, struct stat64_emu31 __user * sta
408 return ret; 406 return ret;
409} 407}
410 408
411asmlinkage long sys32_fstatat64(unsigned int dfd, const char __user *filename, 409COMPAT_SYSCALL_DEFINE4(s390_fstatat64, unsigned int, dfd, const char __user *, filename,
412 struct stat64_emu31 __user* statbuf, int flag) 410 struct stat64_emu31 __user *, statbuf, int, flag)
413{ 411{
414 struct kstat stat; 412 struct kstat stat;
415 int error; 413 int error;
@@ -435,7 +433,7 @@ struct mmap_arg_struct_emu31 {
435 compat_ulong_t offset; 433 compat_ulong_t offset;
436}; 434};
437 435
438asmlinkage unsigned long old32_mmap(struct mmap_arg_struct_emu31 __user *arg) 436COMPAT_SYSCALL_DEFINE1(s390_old_mmap, struct mmap_arg_struct_emu31 __user *, arg)
439{ 437{
440 struct mmap_arg_struct_emu31 a; 438 struct mmap_arg_struct_emu31 a;
441 439
@@ -447,7 +445,7 @@ asmlinkage unsigned long old32_mmap(struct mmap_arg_struct_emu31 __user *arg)
447 a.offset >> PAGE_SHIFT); 445 a.offset >> PAGE_SHIFT);
448} 446}
449 447
450asmlinkage long sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg) 448COMPAT_SYSCALL_DEFINE1(s390_mmap2, struct mmap_arg_struct_emu31 __user *, arg)
451{ 449{
452 struct mmap_arg_struct_emu31 a; 450 struct mmap_arg_struct_emu31 a;
453 451
@@ -456,7 +454,7 @@ asmlinkage long sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg)
456 return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); 454 return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
457} 455}
458 456
459asmlinkage long sys32_read(unsigned int fd, char __user * buf, size_t count) 457COMPAT_SYSCALL_DEFINE3(s390_read, unsigned int, fd, char __user *, buf, compat_size_t, count)
460{ 458{
461 if ((compat_ssize_t) count < 0) 459 if ((compat_ssize_t) count < 0)
462 return -EINVAL; 460 return -EINVAL;
@@ -464,7 +462,7 @@ asmlinkage long sys32_read(unsigned int fd, char __user * buf, size_t count)
464 return sys_read(fd, buf, count); 462 return sys_read(fd, buf, count);
465} 463}
466 464
467asmlinkage long sys32_write(unsigned int fd, const char __user * buf, size_t count) 465COMPAT_SYSCALL_DEFINE3(s390_write, unsigned int, fd, const char __user *, buf, compat_size_t, count)
468{ 466{
469 if ((compat_ssize_t) count < 0) 467 if ((compat_ssize_t) count < 0)
470 return -EINVAL; 468 return -EINVAL;
@@ -478,14 +476,13 @@ asmlinkage long sys32_write(unsigned int fd, const char __user * buf, size_t cou
478 * because the 31 bit values differ from the 64 bit values. 476 * because the 31 bit values differ from the 64 bit values.
479 */ 477 */
480 478
481asmlinkage long 479COMPAT_SYSCALL_DEFINE5(s390_fadvise64, int, fd, u32, high, u32, low, compat_size_t, len, int, advise)
482sys32_fadvise64(int fd, loff_t offset, size_t len, int advise)
483{ 480{
484 if (advise == 4) 481 if (advise == 4)
485 advise = POSIX_FADV_DONTNEED; 482 advise = POSIX_FADV_DONTNEED;
486 else if (advise == 5) 483 else if (advise == 5)
487 advise = POSIX_FADV_NOREUSE; 484 advise = POSIX_FADV_NOREUSE;
488 return sys_fadvise64(fd, offset, len, advise); 485 return sys_fadvise64(fd, (unsigned long)high << 32 | low, len, advise);
489} 486}
490 487
491struct fadvise64_64_args { 488struct fadvise64_64_args {
@@ -495,8 +492,7 @@ struct fadvise64_64_args {
495 int advice; 492 int advice;
496}; 493};
497 494
498asmlinkage long 495COMPAT_SYSCALL_DEFINE1(s390_fadvise64_64, struct fadvise64_64_args __user *, args)
499sys32_fadvise64_64(struct fadvise64_64_args __user *args)
500{ 496{
501 struct fadvise64_64_args a; 497 struct fadvise64_64_args a;
502 498
@@ -508,3 +504,17 @@ sys32_fadvise64_64(struct fadvise64_64_args __user *args)
508 a.advice = POSIX_FADV_NOREUSE; 504 a.advice = POSIX_FADV_NOREUSE;
509 return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice); 505 return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
510} 506}
507
508COMPAT_SYSCALL_DEFINE6(s390_sync_file_range, int, fd, u32, offhigh, u32, offlow,
509 u32, nhigh, u32, nlow, unsigned int, flags)
510{
511 return sys_sync_file_range(fd, ((loff_t)offhigh << 32) + offlow,
512 ((u64)nhigh << 32) + nlow, flags);
513}
514
515COMPAT_SYSCALL_DEFINE6(s390_fallocate, int, fd, int, mode, u32, offhigh, u32, offlow,
516 u32, lenhigh, u32, lenlow)
517{
518 return sys_fallocate(fd, mode, ((loff_t)offhigh << 32) + offlow,
519 ((u64)lenhigh << 32) + lenlow);
520}
diff --git a/arch/s390/kernel/compat_linux.h b/arch/s390/kernel/compat_linux.h
index 1bfda3eca379..39ddfdb40ae8 100644
--- a/arch/s390/kernel/compat_linux.h
+++ b/arch/s390/kernel/compat_linux.h
@@ -76,46 +76,43 @@ struct stat64_emu31;
76struct mmap_arg_struct_emu31; 76struct mmap_arg_struct_emu31;
77struct fadvise64_64_args; 77struct fadvise64_64_args;
78 78
79long sys32_chown16(const char __user * filename, u16 user, u16 group); 79long compat_sys_s390_chown16(const char __user *filename, u16 user, u16 group);
80long sys32_lchown16(const char __user * filename, u16 user, u16 group); 80long compat_sys_s390_lchown16(const char __user *filename, u16 user, u16 group);
81long sys32_fchown16(unsigned int fd, u16 user, u16 group); 81long compat_sys_s390_fchown16(unsigned int fd, u16 user, u16 group);
82long sys32_setregid16(u16 rgid, u16 egid); 82long compat_sys_s390_setregid16(u16 rgid, u16 egid);
83long sys32_setgid16(u16 gid); 83long compat_sys_s390_setgid16(u16 gid);
84long sys32_setreuid16(u16 ruid, u16 euid); 84long compat_sys_s390_setreuid16(u16 ruid, u16 euid);
85long sys32_setuid16(u16 uid); 85long compat_sys_s390_setuid16(u16 uid);
86long sys32_setresuid16(u16 ruid, u16 euid, u16 suid); 86long compat_sys_s390_setresuid16(u16 ruid, u16 euid, u16 suid);
87long sys32_getresuid16(u16 __user *ruid, u16 __user *euid, u16 __user *suid); 87long compat_sys_s390_getresuid16(u16 __user *ruid, u16 __user *euid, u16 __user *suid);
88long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid); 88long compat_sys_s390_setresgid16(u16 rgid, u16 egid, u16 sgid);
89long sys32_getresgid16(u16 __user *rgid, u16 __user *egid, u16 __user *sgid); 89long compat_sys_s390_getresgid16(u16 __user *rgid, u16 __user *egid, u16 __user *sgid);
90long sys32_setfsuid16(u16 uid); 90long compat_sys_s390_setfsuid16(u16 uid);
91long sys32_setfsgid16(u16 gid); 91long compat_sys_s390_setfsgid16(u16 gid);
92long sys32_getgroups16(int gidsetsize, u16 __user *grouplist); 92long compat_sys_s390_getgroups16(int gidsetsize, u16 __user *grouplist);
93long sys32_setgroups16(int gidsetsize, u16 __user *grouplist); 93long compat_sys_s390_setgroups16(int gidsetsize, u16 __user *grouplist);
94long sys32_getuid16(void); 94long compat_sys_s390_getuid16(void);
95long sys32_geteuid16(void); 95long compat_sys_s390_geteuid16(void);
96long sys32_getgid16(void); 96long compat_sys_s390_getgid16(void);
97long sys32_getegid16(void); 97long compat_sys_s390_getegid16(void);
98long sys32_truncate64(const char __user * path, unsigned long high, 98long compat_sys_s390_truncate64(const char __user *path, u32 high, u32 low);
99 unsigned long low); 99long compat_sys_s390_ftruncate64(unsigned int fd, u32 high, u32 low);
100long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low); 100long compat_sys_s390_pread64(unsigned int fd, char __user *ubuf, compat_size_t count, u32 high, u32 low);
101long sys32_init_module(void __user *umod, unsigned long len, 101long compat_sys_s390_pwrite64(unsigned int fd, const char __user *ubuf, compat_size_t count, u32 high, u32 low);
102 const char __user *uargs); 102long compat_sys_s390_readahead(int fd, u32 high, u32 low, s32 count);
103long sys32_delete_module(const char __user *name_user, unsigned int flags); 103long compat_sys_s390_stat64(const char __user *filename, struct stat64_emu31 __user *statbuf);
104long sys32_pread64(unsigned int fd, char __user *ubuf, size_t count, 104long compat_sys_s390_lstat64(const char __user *filename, struct stat64_emu31 __user *statbuf);
105 u32 poshi, u32 poslo); 105long compat_sys_s390_fstat64(unsigned int fd, struct stat64_emu31 __user *statbuf);
106long sys32_pwrite64(unsigned int fd, const char __user *ubuf, 106long compat_sys_s390_fstatat64(unsigned int dfd, const char __user *filename, struct stat64_emu31 __user *statbuf, int flag);
107 size_t count, u32 poshi, u32 poslo); 107long compat_sys_s390_old_mmap(struct mmap_arg_struct_emu31 __user *arg);
108compat_ssize_t sys32_readahead(int fd, u32 offhi, u32 offlo, s32 count); 108long compat_sys_s390_mmap2(struct mmap_arg_struct_emu31 __user *arg);
109long sys32_stat64(const char __user * filename, struct stat64_emu31 __user * statbuf); 109long compat_sys_s390_read(unsigned int fd, char __user * buf, compat_size_t count);
110long sys32_lstat64(const char __user * filename, 110long compat_sys_s390_write(unsigned int fd, const char __user * buf, compat_size_t count);
111 struct stat64_emu31 __user * statbuf); 111long compat_sys_s390_fadvise64(int fd, u32 high, u32 low, compat_size_t len, int advise);
112long sys32_fstat64(unsigned long fd, struct stat64_emu31 __user * statbuf); 112long compat_sys_s390_fadvise64_64(struct fadvise64_64_args __user *args);
113long sys32_fstatat64(unsigned int dfd, const char __user *filename, 113long compat_sys_s390_sync_file_range(int fd, u32 offhigh, u32 offlow, u32 nhigh, u32 nlow, unsigned int flags);
114 struct stat64_emu31 __user* statbuf, int flag); 114long compat_sys_s390_fallocate(int fd, int mode, u32 offhigh, u32 offlow, u32 lenhigh, u32 lenlow);
115unsigned long old32_mmap(struct mmap_arg_struct_emu31 __user *arg); 115long compat_sys_sigreturn(void);
116long sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg); 116long compat_sys_rt_sigreturn(void);
117long sys32_read(unsigned int fd, char __user * buf, size_t count); 117
118long sys32_write(unsigned int fd, const char __user * buf, size_t count);
119long sys32_fadvise64(int fd, loff_t offset, size_t len, int advise);
120long sys32_fadvise64_64(struct fadvise64_64_args __user *args);
121#endif /* _ASM_S390X_S390_H */ 118#endif /* _ASM_S390X_S390_H */
diff --git a/arch/s390/kernel/compat_signal.c b/arch/s390/kernel/compat_signal.c
index 8b84bc373e94..7df5ed9f44d7 100644
--- a/arch/s390/kernel/compat_signal.c
+++ b/arch/s390/kernel/compat_signal.c
@@ -241,7 +241,7 @@ static int restore_sigregs_gprs_high(struct pt_regs *regs, __u32 __user *uregs)
241 return 0; 241 return 0;
242} 242}
243 243
244asmlinkage long sys32_sigreturn(void) 244COMPAT_SYSCALL_DEFINE0(sigreturn)
245{ 245{
246 struct pt_regs *regs = task_pt_regs(current); 246 struct pt_regs *regs = task_pt_regs(current);
247 sigframe32 __user *frame = (sigframe32 __user *)regs->gprs[15]; 247 sigframe32 __user *frame = (sigframe32 __user *)regs->gprs[15];
@@ -260,7 +260,7 @@ badframe:
260 return 0; 260 return 0;
261} 261}
262 262
263asmlinkage long sys32_rt_sigreturn(void) 263COMPAT_SYSCALL_DEFINE0(rt_sigreturn)
264{ 264{
265 struct pt_regs *regs = task_pt_regs(current); 265 struct pt_regs *regs = task_pt_regs(current);
266 rt_sigframe32 __user *frame = (rt_sigframe32 __user *)regs->gprs[15]; 266 rt_sigframe32 __user *frame = (rt_sigframe32 __user *)regs->gprs[15];
diff --git a/arch/s390/kernel/compat_wrapper.S b/arch/s390/kernel/compat_wrapper.S
deleted file mode 100644
index 59c8efce1b99..000000000000
--- a/arch/s390/kernel/compat_wrapper.S
+++ /dev/null
@@ -1,1425 +0,0 @@
1/*
2* wrapper for 31 bit compatible system calls.
3*
4* Copyright IBM Corp. 2000, 2006
5* Author(s): Gerhard Tonn (ton@de.ibm.com),
6* Thomas Spatzier (tspat@de.ibm.com)
7*/
8
9#include <linux/linkage.h>
10
11ENTRY(sys32_exit_wrapper)
12 lgfr %r2,%r2 # int
13 jg sys_exit # branch to sys_exit
14
15ENTRY(sys32_read_wrapper)
16 llgfr %r2,%r2 # unsigned int
17 llgtr %r3,%r3 # char *
18 llgfr %r4,%r4 # size_t
19 jg sys32_read # branch to sys_read
20
21ENTRY(sys32_write_wrapper)
22 llgfr %r2,%r2 # unsigned int
23 llgtr %r3,%r3 # const char *
24 llgfr %r4,%r4 # size_t
25 jg sys32_write # branch to system call
26
27ENTRY(sys32_close_wrapper)
28 llgfr %r2,%r2 # unsigned int
29 jg sys_close # branch to system call
30
31ENTRY(sys32_creat_wrapper)
32 llgtr %r2,%r2 # const char *
33 lgfr %r3,%r3 # int
34 jg sys_creat # branch to system call
35
36ENTRY(sys32_link_wrapper)
37 llgtr %r2,%r2 # const char *
38 llgtr %r3,%r3 # const char *
39 jg sys_link # branch to system call
40
41ENTRY(sys32_unlink_wrapper)
42 llgtr %r2,%r2 # const char *
43 jg sys_unlink # branch to system call
44
45ENTRY(sys32_chdir_wrapper)
46 llgtr %r2,%r2 # const char *
47 jg sys_chdir # branch to system call
48
49ENTRY(sys32_time_wrapper)
50 llgtr %r2,%r2 # int *
51 jg compat_sys_time # branch to system call
52
53ENTRY(sys32_mknod_wrapper)
54 llgtr %r2,%r2 # const char *
55 lgfr %r3,%r3 # int
56 llgfr %r4,%r4 # dev
57 jg sys_mknod # branch to system call
58
59ENTRY(sys32_chmod_wrapper)
60 llgtr %r2,%r2 # const char *
61 llgfr %r3,%r3 # mode_t
62 jg sys_chmod # branch to system call
63
64ENTRY(sys32_lchown16_wrapper)
65 llgtr %r2,%r2 # const char *
66 llgfr %r3,%r3 # __kernel_old_uid_emu31_t
67 llgfr %r4,%r4 # __kernel_old_uid_emu31_t
68 jg sys32_lchown16 # branch to system call
69
70#sys32_getpid_wrapper # void
71
72ENTRY(sys32_mount_wrapper)
73 llgtr %r2,%r2 # char *
74 llgtr %r3,%r3 # char *
75 llgtr %r4,%r4 # char *
76 llgfr %r5,%r5 # unsigned long
77 llgtr %r6,%r6 # void *
78 jg compat_sys_mount # branch to system call
79
80ENTRY(sys32_oldumount_wrapper)
81 llgtr %r2,%r2 # char *
82 jg sys_oldumount # branch to system call
83
84ENTRY(sys32_setuid16_wrapper)
85 llgfr %r2,%r2 # __kernel_old_uid_emu31_t
86 jg sys32_setuid16 # branch to system call
87
88#sys32_getuid16_wrapper # void
89
90ENTRY(sys32_ptrace_wrapper)
91 lgfr %r2,%r2 # long
92 lgfr %r3,%r3 # long
93 llgtr %r4,%r4 # long
94 llgfr %r5,%r5 # long
95 jg compat_sys_ptrace # branch to system call
96
97ENTRY(sys32_alarm_wrapper)
98 llgfr %r2,%r2 # unsigned int
99 jg sys_alarm # branch to system call
100
101ENTRY(compat_sys_utime_wrapper)
102 llgtr %r2,%r2 # char *
103 llgtr %r3,%r3 # struct compat_utimbuf *
104 jg compat_sys_utime # branch to system call
105
106ENTRY(sys32_access_wrapper)
107 llgtr %r2,%r2 # const char *
108 lgfr %r3,%r3 # int
109 jg sys_access # branch to system call
110
111ENTRY(sys32_nice_wrapper)
112 lgfr %r2,%r2 # int
113 jg sys_nice # branch to system call
114
115#sys32_sync_wrapper # void
116
117ENTRY(sys32_kill_wrapper)
118 lgfr %r2,%r2 # int
119 lgfr %r3,%r3 # int
120 jg sys_kill # branch to system call
121
122ENTRY(sys32_rename_wrapper)
123 llgtr %r2,%r2 # const char *
124 llgtr %r3,%r3 # const char *
125 jg sys_rename # branch to system call
126
127ENTRY(sys32_mkdir_wrapper)
128 llgtr %r2,%r2 # const char *
129 lgfr %r3,%r3 # int
130 jg sys_mkdir # branch to system call
131
132ENTRY(sys32_rmdir_wrapper)
133 llgtr %r2,%r2 # const char *
134 jg sys_rmdir # branch to system call
135
136ENTRY(sys32_dup_wrapper)
137 llgfr %r2,%r2 # unsigned int
138 jg sys_dup # branch to system call
139
140ENTRY(sys32_pipe_wrapper)
141 llgtr %r2,%r2 # u32 *
142 jg sys_pipe # branch to system call
143
144ENTRY(compat_sys_times_wrapper)
145 llgtr %r2,%r2 # struct compat_tms *
146 jg compat_sys_times # branch to system call
147
148ENTRY(sys32_brk_wrapper)
149 llgtr %r2,%r2 # unsigned long
150 jg sys_brk # branch to system call
151
152ENTRY(sys32_setgid16_wrapper)
153 llgfr %r2,%r2 # __kernel_old_gid_emu31_t
154 jg sys32_setgid16 # branch to system call
155
156#sys32_getgid16_wrapper # void
157
158ENTRY(sys32_signal_wrapper)
159 lgfr %r2,%r2 # int
160 llgtr %r3,%r3 # __sighandler_t
161 jg sys_signal
162
163#sys32_geteuid16_wrapper # void
164
165#sys32_getegid16_wrapper # void
166
167ENTRY(sys32_acct_wrapper)
168 llgtr %r2,%r2 # char *
169 jg sys_acct # branch to system call
170
171ENTRY(sys32_umount_wrapper)
172 llgtr %r2,%r2 # char *
173 lgfr %r3,%r3 # int
174 jg sys_umount # branch to system call
175
176ENTRY(compat_sys_ioctl_wrapper)
177 llgfr %r2,%r2 # unsigned int
178 llgfr %r3,%r3 # unsigned int
179 llgfr %r4,%r4 # unsigned int
180 jg compat_sys_ioctl # branch to system call
181
182ENTRY(compat_sys_fcntl_wrapper)
183 llgfr %r2,%r2 # unsigned int
184 llgfr %r3,%r3 # unsigned int
185 llgfr %r4,%r4 # unsigned long
186 jg compat_sys_fcntl # branch to system call
187
188ENTRY(sys32_setpgid_wrapper)
189 lgfr %r2,%r2 # pid_t
190 lgfr %r3,%r3 # pid_t
191 jg sys_setpgid # branch to system call
192
193ENTRY(sys32_umask_wrapper)
194 lgfr %r2,%r2 # int
195 jg sys_umask # branch to system call
196
197ENTRY(sys32_chroot_wrapper)
198 llgtr %r2,%r2 # char *
199 jg sys_chroot # branch to system call
200
201ENTRY(sys32_ustat_wrapper)
202 llgfr %r2,%r2 # dev_t
203 llgtr %r3,%r3 # struct ustat *
204 jg compat_sys_ustat
205
206ENTRY(sys32_dup2_wrapper)
207 llgfr %r2,%r2 # unsigned int
208 llgfr %r3,%r3 # unsigned int
209 jg sys_dup2 # branch to system call
210
211#sys32_getppid_wrapper # void
212
213#sys32_getpgrp_wrapper # void
214
215#sys32_setsid_wrapper # void
216
217ENTRY(sys32_setreuid16_wrapper)
218 llgfr %r2,%r2 # __kernel_old_uid_emu31_t
219 llgfr %r3,%r3 # __kernel_old_uid_emu31_t
220 jg sys32_setreuid16 # branch to system call
221
222ENTRY(sys32_setregid16_wrapper)
223 llgfr %r2,%r2 # __kernel_old_gid_emu31_t
224 llgfr %r3,%r3 # __kernel_old_gid_emu31_t
225 jg sys32_setregid16 # branch to system call
226
227ENTRY(sys_sigsuspend_wrapper)
228 lgfr %r2,%r2 # int
229 lgfr %r3,%r3 # int
230 llgfr %r4,%r4 # old_sigset_t
231 jg sys_sigsuspend
232
233ENTRY(compat_sys_sigpending_wrapper)
234 llgtr %r2,%r2 # compat_old_sigset_t *
235 jg compat_sys_sigpending # branch to system call
236
237ENTRY(sys32_sethostname_wrapper)
238 llgtr %r2,%r2 # char *
239 lgfr %r3,%r3 # int
240 jg sys_sethostname # branch to system call
241
242ENTRY(compat_sys_setrlimit_wrapper)
243 llgfr %r2,%r2 # unsigned int
244 llgtr %r3,%r3 # struct rlimit_emu31 *
245 jg compat_sys_setrlimit # branch to system call
246
247ENTRY(compat_sys_old_getrlimit_wrapper)
248 llgfr %r2,%r2 # unsigned int
249 llgtr %r3,%r3 # struct rlimit_emu31 *
250 jg compat_sys_old_getrlimit # branch to system call
251
252ENTRY(compat_sys_getrlimit_wrapper)
253 llgfr %r2,%r2 # unsigned int
254 llgtr %r3,%r3 # struct rlimit_emu31 *
255 jg compat_sys_getrlimit # branch to system call
256
257ENTRY(sys32_mmap2_wrapper)
258 llgtr %r2,%r2 # struct mmap_arg_struct_emu31 *
259 jg sys32_mmap2 # branch to system call
260
261ENTRY(compat_sys_gettimeofday_wrapper)
262 llgtr %r2,%r2 # struct timeval_emu31 *
263 llgtr %r3,%r3 # struct timezone *
264 jg compat_sys_gettimeofday # branch to system call
265
266ENTRY(compat_sys_settimeofday_wrapper)
267 llgtr %r2,%r2 # struct timeval_emu31 *
268 llgtr %r3,%r3 # struct timezone *
269 jg compat_sys_settimeofday # branch to system call
270
271ENTRY(sys32_getgroups16_wrapper)
272 lgfr %r2,%r2 # int
273 llgtr %r3,%r3 # __kernel_old_gid_emu31_t *
274 jg sys32_getgroups16 # branch to system call
275
276ENTRY(sys32_setgroups16_wrapper)
277 lgfr %r2,%r2 # int
278 llgtr %r3,%r3 # __kernel_old_gid_emu31_t *
279 jg sys32_setgroups16 # branch to system call
280
281ENTRY(sys32_symlink_wrapper)
282 llgtr %r2,%r2 # const char *
283 llgtr %r3,%r3 # const char *
284 jg sys_symlink # branch to system call
285
286ENTRY(sys32_readlink_wrapper)
287 llgtr %r2,%r2 # const char *
288 llgtr %r3,%r3 # char *
289 lgfr %r4,%r4 # int
290 jg sys_readlink # branch to system call
291
292ENTRY(sys32_uselib_wrapper)
293 llgtr %r2,%r2 # const char *
294 jg sys_uselib # branch to system call
295
296ENTRY(sys32_swapon_wrapper)
297 llgtr %r2,%r2 # const char *
298 lgfr %r3,%r3 # int
299 jg sys_swapon # branch to system call
300
301ENTRY(sys32_reboot_wrapper)
302 lgfr %r2,%r2 # int
303 lgfr %r3,%r3 # int
304 llgfr %r4,%r4 # unsigned int
305 llgtr %r5,%r5 # void *
306 jg sys_reboot # branch to system call
307
308ENTRY(old32_readdir_wrapper)
309 llgfr %r2,%r2 # unsigned int
310 llgtr %r3,%r3 # void *
311 llgfr %r4,%r4 # unsigned int
312 jg compat_sys_old_readdir # branch to system call
313
314ENTRY(old32_mmap_wrapper)
315 llgtr %r2,%r2 # struct mmap_arg_struct_emu31 *
316 jg old32_mmap # branch to system call
317
318ENTRY(sys32_munmap_wrapper)
319 llgfr %r2,%r2 # unsigned long
320 llgfr %r3,%r3 # size_t
321 jg sys_munmap # branch to system call
322
323ENTRY(sys32_fchmod_wrapper)
324 llgfr %r2,%r2 # unsigned int
325 llgfr %r3,%r3 # mode_t
326 jg sys_fchmod # branch to system call
327
328ENTRY(sys32_fchown16_wrapper)
329 llgfr %r2,%r2 # unsigned int
330 llgfr %r3,%r3 # compat_uid_t
331 llgfr %r4,%r4 # compat_uid_t
332 jg sys32_fchown16 # branch to system call
333
334ENTRY(sys32_getpriority_wrapper)
335 lgfr %r2,%r2 # int
336 lgfr %r3,%r3 # int
337 jg sys_getpriority # branch to system call
338
339ENTRY(sys32_setpriority_wrapper)
340 lgfr %r2,%r2 # int
341 lgfr %r3,%r3 # int
342 lgfr %r4,%r4 # int
343 jg sys_setpriority # branch to system call
344
345ENTRY(compat_sys_statfs_wrapper)
346 llgtr %r2,%r2 # char *
347 llgtr %r3,%r3 # struct compat_statfs *
348 jg compat_sys_statfs # branch to system call
349
350ENTRY(compat_sys_fstatfs_wrapper)
351 llgfr %r2,%r2 # unsigned int
352 llgtr %r3,%r3 # struct compat_statfs *
353 jg compat_sys_fstatfs # branch to system call
354
355ENTRY(compat_sys_socketcall_wrapper)
356 lgfr %r2,%r2 # int
357 llgtr %r3,%r3 # u32 *
358 jg compat_sys_socketcall # branch to system call
359
360ENTRY(sys32_syslog_wrapper)
361 lgfr %r2,%r2 # int
362 llgtr %r3,%r3 # char *
363 lgfr %r4,%r4 # int
364 jg sys_syslog # branch to system call
365
366ENTRY(compat_sys_newstat_wrapper)
367 llgtr %r2,%r2 # char *
368 llgtr %r3,%r3 # struct stat_emu31 *
369 jg compat_sys_newstat # branch to system call
370
371ENTRY(compat_sys_newlstat_wrapper)
372 llgtr %r2,%r2 # char *
373 llgtr %r3,%r3 # struct stat_emu31 *
374 jg compat_sys_newlstat # branch to system call
375
376ENTRY(compat_sys_newfstat_wrapper)
377 llgfr %r2,%r2 # unsigned int
378 llgtr %r3,%r3 # struct stat_emu31 *
379 jg compat_sys_newfstat # branch to system call
380
381#sys32_vhangup_wrapper # void
382
383ENTRY(sys32_swapoff_wrapper)
384 llgtr %r2,%r2 # const char *
385 jg sys_swapoff # branch to system call
386
387ENTRY(compat_sys_sysinfo_wrapper)
388 llgtr %r2,%r2 # struct sysinfo_emu31 *
389 jg compat_sys_sysinfo # branch to system call
390
391ENTRY(sys32_fsync_wrapper)
392 llgfr %r2,%r2 # unsigned int
393 jg sys_fsync # branch to system call
394
395#sys32_sigreturn_wrapper # done in sigreturn_glue
396
397#sys32_clone_wrapper # done in clone_glue
398
399ENTRY(sys32_setdomainname_wrapper)
400 llgtr %r2,%r2 # char *
401 lgfr %r3,%r3 # int
402 jg sys_setdomainname # branch to system call
403
404ENTRY(sys32_newuname_wrapper)
405 llgtr %r2,%r2 # struct new_utsname *
406 jg sys_newuname # branch to system call
407
408ENTRY(compat_sys_adjtimex_wrapper)
409 llgtr %r2,%r2 # struct compat_timex *
410 jg compat_sys_adjtimex # branch to system call
411
412ENTRY(sys32_mprotect_wrapper)
413 llgtr %r2,%r2 # unsigned long (actually pointer
414 llgfr %r3,%r3 # size_t
415 llgfr %r4,%r4 # unsigned long
416 jg sys_mprotect # branch to system call
417
418ENTRY(sys_init_module_wrapper)
419 llgtr %r2,%r2 # void *
420 llgfr %r3,%r3 # unsigned long
421 llgtr %r4,%r4 # char *
422 jg sys_init_module # branch to system call
423
424ENTRY(sys_delete_module_wrapper)
425 llgtr %r2,%r2 # const char *
426 llgfr %r3,%r3 # unsigned int
427 jg sys_delete_module # branch to system call
428
429ENTRY(sys32_quotactl_wrapper)
430 llgfr %r2,%r2 # unsigned int
431 llgtr %r3,%r3 # const char *
432 llgfr %r4,%r4 # qid_t
433 llgtr %r5,%r5 # caddr_t
434 jg sys_quotactl # branch to system call
435
436ENTRY(sys32_getpgid_wrapper)
437 lgfr %r2,%r2 # pid_t
438 jg sys_getpgid # branch to system call
439
440ENTRY(sys32_fchdir_wrapper)
441 llgfr %r2,%r2 # unsigned int
442 jg sys_fchdir # branch to system call
443
444ENTRY(sys32_bdflush_wrapper)
445 lgfr %r2,%r2 # int
446 lgfr %r3,%r3 # long
447 jg sys_bdflush # branch to system call
448
449ENTRY(sys32_sysfs_wrapper)
450 lgfr %r2,%r2 # int
451 llgfr %r3,%r3 # unsigned long
452 llgfr %r4,%r4 # unsigned long
453 jg sys_sysfs # branch to system call
454
455ENTRY(sys32_personality_wrapper)
456 llgfr %r2,%r2 # unsigned int
457 jg sys_s390_personality # branch to system call
458
459ENTRY(sys32_setfsuid16_wrapper)
460 llgfr %r2,%r2 # __kernel_old_uid_emu31_t
461 jg sys32_setfsuid16 # branch to system call
462
463ENTRY(sys32_setfsgid16_wrapper)
464 llgfr %r2,%r2 # __kernel_old_gid_emu31_t
465 jg sys32_setfsgid16 # branch to system call
466
467ENTRY(sys32_llseek_wrapper)
468 llgfr %r2,%r2 # unsigned int
469 llgfr %r3,%r3 # unsigned long
470 llgfr %r4,%r4 # unsigned long
471 llgtr %r5,%r5 # loff_t *
472 llgfr %r6,%r6 # unsigned int
473 jg sys_llseek # branch to system call
474
475ENTRY(sys32_getdents_wrapper)
476 llgfr %r2,%r2 # unsigned int
477 llgtr %r3,%r3 # void *
478 llgfr %r4,%r4 # unsigned int
479 jg compat_sys_getdents # branch to system call
480
481ENTRY(compat_sys_select_wrapper)
482 lgfr %r2,%r2 # int
483 llgtr %r3,%r3 # compat_fd_set *
484 llgtr %r4,%r4 # compat_fd_set *
485 llgtr %r5,%r5 # compat_fd_set *
486 llgtr %r6,%r6 # struct compat_timeval *
487 jg compat_sys_select # branch to system call
488
489ENTRY(sys32_flock_wrapper)
490 llgfr %r2,%r2 # unsigned int
491 llgfr %r3,%r3 # unsigned int
492 jg sys_flock # branch to system call
493
494ENTRY(sys32_msync_wrapper)
495 llgfr %r2,%r2 # unsigned long
496 llgfr %r3,%r3 # size_t
497 lgfr %r4,%r4 # int
498 jg sys_msync # branch to system call
499
500ENTRY(compat_sys_readv_wrapper)
501 lgfr %r2,%r2 # int
502 llgtr %r3,%r3 # const struct compat_iovec *
503 llgfr %r4,%r4 # unsigned long
504 jg compat_sys_readv # branch to system call
505
506ENTRY(compat_sys_writev_wrapper)
507 lgfr %r2,%r2 # int
508 llgtr %r3,%r3 # const struct compat_iovec *
509 llgfr %r4,%r4 # unsigned long
510 jg compat_sys_writev # branch to system call
511
512ENTRY(sys32_getsid_wrapper)
513 lgfr %r2,%r2 # pid_t
514 jg sys_getsid # branch to system call
515
516ENTRY(sys32_fdatasync_wrapper)
517 llgfr %r2,%r2 # unsigned int
518 jg sys_fdatasync # branch to system call
519
520ENTRY(sys32_mlock_wrapper)
521 llgfr %r2,%r2 # unsigned long
522 llgfr %r3,%r3 # size_t
523 jg sys_mlock # branch to system call
524
525ENTRY(sys32_munlock_wrapper)
526 llgfr %r2,%r2 # unsigned long
527 llgfr %r3,%r3 # size_t
528 jg sys_munlock # branch to system call
529
530ENTRY(sys32_mlockall_wrapper)
531 lgfr %r2,%r2 # int
532 jg sys_mlockall # branch to system call
533
534#sys32_munlockall_wrapper # void
535
536ENTRY(sys32_sched_setparam_wrapper)
537 lgfr %r2,%r2 # pid_t
538 llgtr %r3,%r3 # struct sched_param *
539 jg sys_sched_setparam # branch to system call
540
541ENTRY(sys32_sched_getparam_wrapper)
542 lgfr %r2,%r2 # pid_t
543 llgtr %r3,%r3 # struct sched_param *
544 jg sys_sched_getparam # branch to system call
545
546ENTRY(sys32_sched_setscheduler_wrapper)
547 lgfr %r2,%r2 # pid_t
548 lgfr %r3,%r3 # int
549 llgtr %r4,%r4 # struct sched_param *
550 jg sys_sched_setscheduler # branch to system call
551
552ENTRY(sys32_sched_getscheduler_wrapper)
553 lgfr %r2,%r2 # pid_t
554 jg sys_sched_getscheduler # branch to system call
555
556#sys32_sched_yield_wrapper # void
557
558ENTRY(sys32_sched_get_priority_max_wrapper)
559 lgfr %r2,%r2 # int
560 jg sys_sched_get_priority_max # branch to system call
561
562ENTRY(sys32_sched_get_priority_min_wrapper)
563 lgfr %r2,%r2 # int
564 jg sys_sched_get_priority_min # branch to system call
565
566ENTRY(compat_sys_nanosleep_wrapper)
567 llgtr %r2,%r2 # struct compat_timespec *
568 llgtr %r3,%r3 # struct compat_timespec *
569 jg compat_sys_nanosleep # branch to system call
570
571ENTRY(sys32_mremap_wrapper)
572 llgfr %r2,%r2 # unsigned long
573 llgfr %r3,%r3 # unsigned long
574 llgfr %r4,%r4 # unsigned long
575 llgfr %r5,%r5 # unsigned long
576 llgfr %r6,%r6 # unsigned long
577 jg sys_mremap # branch to system call
578
579ENTRY(sys32_setresuid16_wrapper)
580 llgfr %r2,%r2 # __kernel_old_uid_emu31_t
581 llgfr %r3,%r3 # __kernel_old_uid_emu31_t
582 llgfr %r4,%r4 # __kernel_old_uid_emu31_t
583 jg sys32_setresuid16 # branch to system call
584
585ENTRY(sys32_getresuid16_wrapper)
586 llgtr %r2,%r2 # __kernel_old_uid_emu31_t *
587 llgtr %r3,%r3 # __kernel_old_uid_emu31_t *
588 llgtr %r4,%r4 # __kernel_old_uid_emu31_t *
589 jg sys32_getresuid16 # branch to system call
590
591ENTRY(sys32_poll_wrapper)
592 llgtr %r2,%r2 # struct pollfd *
593 llgfr %r3,%r3 # unsigned int
594 lgfr %r4,%r4 # int
595 jg sys_poll # branch to system call
596
597ENTRY(sys32_setresgid16_wrapper)
598 llgfr %r2,%r2 # __kernel_old_gid_emu31_t
599 llgfr %r3,%r3 # __kernel_old_gid_emu31_t
600 llgfr %r4,%r4 # __kernel_old_gid_emu31_t
601 jg sys32_setresgid16 # branch to system call
602
603ENTRY(sys32_getresgid16_wrapper)
604 llgtr %r2,%r2 # __kernel_old_gid_emu31_t *
605 llgtr %r3,%r3 # __kernel_old_gid_emu31_t *
606 llgtr %r4,%r4 # __kernel_old_gid_emu31_t *
607 jg sys32_getresgid16 # branch to system call
608
609ENTRY(sys32_prctl_wrapper)
610 lgfr %r2,%r2 # int
611 llgfr %r3,%r3 # unsigned long
612 llgfr %r4,%r4 # unsigned long
613 llgfr %r5,%r5 # unsigned long
614 llgfr %r6,%r6 # unsigned long
615 jg sys_prctl # branch to system call
616
617#sys32_rt_sigreturn_wrapper # done in rt_sigreturn_glue
618
619ENTRY(sys32_pread64_wrapper)
620 llgfr %r2,%r2 # unsigned int
621 llgtr %r3,%r3 # char *
622 llgfr %r4,%r4 # size_t
623 llgfr %r5,%r5 # u32
624 llgfr %r6,%r6 # u32
625 jg sys32_pread64 # branch to system call
626
627ENTRY(sys32_pwrite64_wrapper)
628 llgfr %r2,%r2 # unsigned int
629 llgtr %r3,%r3 # const char *
630 llgfr %r4,%r4 # size_t
631 llgfr %r5,%r5 # u32
632 llgfr %r6,%r6 # u32
633 jg sys32_pwrite64 # branch to system call
634
635ENTRY(sys32_chown16_wrapper)
636 llgtr %r2,%r2 # const char *
637 llgfr %r3,%r3 # __kernel_old_uid_emu31_t
638 llgfr %r4,%r4 # __kernel_old_gid_emu31_t
639 jg sys32_chown16 # branch to system call
640
641ENTRY(sys32_getcwd_wrapper)
642 llgtr %r2,%r2 # char *
643 llgfr %r3,%r3 # unsigned long
644 jg sys_getcwd # branch to system call
645
646ENTRY(sys32_capget_wrapper)
647 llgtr %r2,%r2 # cap_user_header_t
648 llgtr %r3,%r3 # cap_user_data_t
649 jg sys_capget # branch to system call
650
651ENTRY(sys32_capset_wrapper)
652 llgtr %r2,%r2 # cap_user_header_t
653 llgtr %r3,%r3 # const cap_user_data_t
654 jg sys_capset # branch to system call
655
656#sys32_vfork_wrapper # done in vfork_glue
657
658ENTRY(sys32_truncate64_wrapper)
659 llgtr %r2,%r2 # const char *
660 llgfr %r3,%r3 # unsigned long
661 llgfr %r4,%r4 # unsigned long
662 jg sys32_truncate64 # branch to system call
663
664ENTRY(sys32_ftruncate64_wrapper)
665 llgfr %r2,%r2 # unsigned int
666 llgfr %r3,%r3 # unsigned long
667 llgfr %r4,%r4 # unsigned long
668 jg sys32_ftruncate64 # branch to system call
669
670ENTRY(sys32_lchown_wrapper)
671 llgtr %r2,%r2 # const char *
672 llgfr %r3,%r3 # uid_t
673 llgfr %r4,%r4 # gid_t
674 jg sys_lchown # branch to system call
675
676#sys32_getuid_wrapper # void
677#sys32_getgid_wrapper # void
678#sys32_geteuid_wrapper # void
679#sys32_getegid_wrapper # void
680
681ENTRY(sys32_setreuid_wrapper)
682 llgfr %r2,%r2 # uid_t
683 llgfr %r3,%r3 # uid_t
684 jg sys_setreuid # branch to system call
685
686ENTRY(sys32_setregid_wrapper)
687 llgfr %r2,%r2 # gid_t
688 llgfr %r3,%r3 # gid_t
689 jg sys_setregid # branch to system call
690
691ENTRY(sys32_getgroups_wrapper)
692 lgfr %r2,%r2 # int
693 llgtr %r3,%r3 # gid_t *
694 jg sys_getgroups # branch to system call
695
696ENTRY(sys32_setgroups_wrapper)
697 lgfr %r2,%r2 # int
698 llgtr %r3,%r3 # gid_t *
699 jg sys_setgroups # branch to system call
700
701ENTRY(sys32_fchown_wrapper)
702 llgfr %r2,%r2 # unsigned int
703 llgfr %r3,%r3 # uid_t
704 llgfr %r4,%r4 # gid_t
705 jg sys_fchown # branch to system call
706
707ENTRY(sys32_setresuid_wrapper)
708 llgfr %r2,%r2 # uid_t
709 llgfr %r3,%r3 # uid_t
710 llgfr %r4,%r4 # uid_t
711 jg sys_setresuid # branch to system call
712
713ENTRY(sys32_getresuid_wrapper)
714 llgtr %r2,%r2 # uid_t *
715 llgtr %r3,%r3 # uid_t *
716 llgtr %r4,%r4 # uid_t *
717 jg sys_getresuid # branch to system call
718
719ENTRY(sys32_setresgid_wrapper)
720 llgfr %r2,%r2 # gid_t
721 llgfr %r3,%r3 # gid_t
722 llgfr %r4,%r4 # gid_t
723 jg sys_setresgid # branch to system call
724
725ENTRY(sys32_getresgid_wrapper)
726 llgtr %r2,%r2 # gid_t *
727 llgtr %r3,%r3 # gid_t *
728 llgtr %r4,%r4 # gid_t *
729 jg sys_getresgid # branch to system call
730
731ENTRY(sys32_chown_wrapper)
732 llgtr %r2,%r2 # const char *
733 llgfr %r3,%r3 # uid_t
734 llgfr %r4,%r4 # gid_t
735 jg sys_chown # branch to system call
736
737ENTRY(sys32_setuid_wrapper)
738 llgfr %r2,%r2 # uid_t
739 jg sys_setuid # branch to system call
740
741ENTRY(sys32_setgid_wrapper)
742 llgfr %r2,%r2 # gid_t
743 jg sys_setgid # branch to system call
744
745ENTRY(sys32_setfsuid_wrapper)
746 llgfr %r2,%r2 # uid_t
747 jg sys_setfsuid # branch to system call
748
749ENTRY(sys32_setfsgid_wrapper)
750 llgfr %r2,%r2 # gid_t
751 jg sys_setfsgid # branch to system call
752
753ENTRY(sys32_pivot_root_wrapper)
754 llgtr %r2,%r2 # const char *
755 llgtr %r3,%r3 # const char *
756 jg sys_pivot_root # branch to system call
757
758ENTRY(sys32_mincore_wrapper)
759 llgfr %r2,%r2 # unsigned long
760 llgfr %r3,%r3 # size_t
761 llgtr %r4,%r4 # unsigned char *
762 jg sys_mincore # branch to system call
763
764ENTRY(sys32_madvise_wrapper)
765 llgfr %r2,%r2 # unsigned long
766 llgfr %r3,%r3 # size_t
767 lgfr %r4,%r4 # int
768 jg sys_madvise # branch to system call
769
770ENTRY(sys32_getdents64_wrapper)
771 llgfr %r2,%r2 # unsigned int
772 llgtr %r3,%r3 # void *
773 llgfr %r4,%r4 # unsigned int
774 jg sys_getdents64 # branch to system call
775
776ENTRY(compat_sys_fcntl64_wrapper)
777 llgfr %r2,%r2 # unsigned int
778 llgfr %r3,%r3 # unsigned int
779 llgfr %r4,%r4 # unsigned long
780 jg compat_sys_fcntl64 # branch to system call
781
782ENTRY(sys32_stat64_wrapper)
783 llgtr %r2,%r2 # char *
784 llgtr %r3,%r3 # struct stat64 *
785 jg sys32_stat64 # branch to system call
786
787ENTRY(sys32_lstat64_wrapper)
788 llgtr %r2,%r2 # char *
789 llgtr %r3,%r3 # struct stat64 *
790 jg sys32_lstat64 # branch to system call
791
792ENTRY(sys32_stime_wrapper)
793 llgtr %r2,%r2 # long *
794 jg compat_sys_stime # branch to system call
795
796ENTRY(sys32_fstat64_wrapper)
797 llgfr %r2,%r2 # unsigned long
798 llgtr %r3,%r3 # struct stat64 *
799 jg sys32_fstat64 # branch to system call
800
801ENTRY(sys32_setxattr_wrapper)
802 llgtr %r2,%r2 # char *
803 llgtr %r3,%r3 # char *
804 llgtr %r4,%r4 # void *
805 llgfr %r5,%r5 # size_t
806 lgfr %r6,%r6 # int
807 jg sys_setxattr
808
809ENTRY(sys32_lsetxattr_wrapper)
810 llgtr %r2,%r2 # char *
811 llgtr %r3,%r3 # char *
812 llgtr %r4,%r4 # void *
813 llgfr %r5,%r5 # size_t
814 lgfr %r6,%r6 # int
815 jg sys_lsetxattr
816
817ENTRY(sys32_fsetxattr_wrapper)
818 lgfr %r2,%r2 # int
819 llgtr %r3,%r3 # char *
820 llgtr %r4,%r4 # void *
821 llgfr %r5,%r5 # size_t
822 lgfr %r6,%r6 # int
823 jg sys_fsetxattr
824
825ENTRY(sys32_getxattr_wrapper)
826 llgtr %r2,%r2 # char *
827 llgtr %r3,%r3 # char *
828 llgtr %r4,%r4 # void *
829 llgfr %r5,%r5 # size_t
830 jg sys_getxattr
831
832ENTRY(sys32_lgetxattr_wrapper)
833 llgtr %r2,%r2 # char *
834 llgtr %r3,%r3 # char *
835 llgtr %r4,%r4 # void *
836 llgfr %r5,%r5 # size_t
837 jg sys_lgetxattr
838
839ENTRY(sys32_fgetxattr_wrapper)
840 lgfr %r2,%r2 # int
841 llgtr %r3,%r3 # char *
842 llgtr %r4,%r4 # void *
843 llgfr %r5,%r5 # size_t
844 jg sys_fgetxattr
845
846ENTRY(sys32_listxattr_wrapper)
847 llgtr %r2,%r2 # char *
848 llgtr %r3,%r3 # char *
849 llgfr %r4,%r4 # size_t
850 jg sys_listxattr
851
852ENTRY(sys32_llistxattr_wrapper)
853 llgtr %r2,%r2 # char *
854 llgtr %r3,%r3 # char *
855 llgfr %r4,%r4 # size_t
856 jg sys_llistxattr
857
858ENTRY(sys32_flistxattr_wrapper)
859 lgfr %r2,%r2 # int
860 llgtr %r3,%r3 # char *
861 llgfr %r4,%r4 # size_t
862 jg sys_flistxattr
863
864ENTRY(sys32_removexattr_wrapper)
865 llgtr %r2,%r2 # char *
866 llgtr %r3,%r3 # char *
867 jg sys_removexattr
868
869ENTRY(sys32_lremovexattr_wrapper)
870 llgtr %r2,%r2 # char *
871 llgtr %r3,%r3 # char *
872 jg sys_lremovexattr
873
874ENTRY(sys32_fremovexattr_wrapper)
875 lgfr %r2,%r2 # int
876 llgtr %r3,%r3 # char *
877 jg sys_fremovexattr
878
879ENTRY(sys32_sched_setaffinity_wrapper)
880 lgfr %r2,%r2 # int
881 llgfr %r3,%r3 # unsigned int
882 llgtr %r4,%r4 # unsigned long *
883 jg compat_sys_sched_setaffinity
884
885ENTRY(sys32_sched_getaffinity_wrapper)
886 lgfr %r2,%r2 # int
887 llgfr %r3,%r3 # unsigned int
888 llgtr %r4,%r4 # unsigned long *
889 jg compat_sys_sched_getaffinity
890
891ENTRY(sys32_exit_group_wrapper)
892 lgfr %r2,%r2 # int
893 jg sys_exit_group # branch to system call
894
895ENTRY(sys32_set_tid_address_wrapper)
896 llgtr %r2,%r2 # int *
897 jg sys_set_tid_address # branch to system call
898
899ENTRY(sys_epoll_create_wrapper)
900 lgfr %r2,%r2 # int
901 jg sys_epoll_create # branch to system call
902
903ENTRY(sys_epoll_ctl_wrapper)
904 lgfr %r2,%r2 # int
905 lgfr %r3,%r3 # int
906 lgfr %r4,%r4 # int
907 llgtr %r5,%r5 # struct epoll_event *
908 jg sys_epoll_ctl # branch to system call
909
910ENTRY(sys_epoll_wait_wrapper)
911 lgfr %r2,%r2 # int
912 llgtr %r3,%r3 # struct epoll_event *
913 lgfr %r4,%r4 # int
914 lgfr %r5,%r5 # int
915 jg sys_epoll_wait # branch to system call
916
917ENTRY(sys32_fadvise64_wrapper)
918 lgfr %r2,%r2 # int
919 sllg %r3,%r3,32 # get high word of 64bit loff_t
920 or %r3,%r4 # get low word of 64bit loff_t
921 llgfr %r4,%r5 # size_t (unsigned long)
922 lgfr %r5,%r6 # int
923 jg sys32_fadvise64
924
925ENTRY(sys32_fadvise64_64_wrapper)
926 llgtr %r2,%r2 # struct fadvise64_64_args *
927 jg sys32_fadvise64_64
928
929ENTRY(sys32_clock_settime_wrapper)
930 lgfr %r2,%r2 # clockid_t (int)
931 llgtr %r3,%r3 # struct compat_timespec *
932 jg compat_sys_clock_settime
933
934ENTRY(sys32_clock_gettime_wrapper)
935 lgfr %r2,%r2 # clockid_t (int)
936 llgtr %r3,%r3 # struct compat_timespec *
937 jg compat_sys_clock_gettime
938
939ENTRY(sys32_clock_getres_wrapper)
940 lgfr %r2,%r2 # clockid_t (int)
941 llgtr %r3,%r3 # struct compat_timespec *
942 jg compat_sys_clock_getres
943
944ENTRY(sys32_clock_nanosleep_wrapper)
945 lgfr %r2,%r2 # clockid_t (int)
946 lgfr %r3,%r3 # int
947 llgtr %r4,%r4 # struct compat_timespec *
948 llgtr %r5,%r5 # struct compat_timespec *
949 jg compat_sys_clock_nanosleep
950
951ENTRY(sys32_timer_create_wrapper)
952 lgfr %r2,%r2 # timer_t (int)
953 llgtr %r3,%r3 # struct compat_sigevent *
954 llgtr %r4,%r4 # timer_t *
955 jg compat_sys_timer_create
956
957ENTRY(sys32_timer_settime_wrapper)
958 lgfr %r2,%r2 # timer_t (int)
959 lgfr %r3,%r3 # int
960 llgtr %r4,%r4 # struct compat_itimerspec *
961 llgtr %r5,%r5 # struct compat_itimerspec *
962 jg compat_sys_timer_settime
963
964ENTRY(sys32_timer_gettime_wrapper)
965 lgfr %r2,%r2 # timer_t (int)
966 llgtr %r3,%r3 # struct compat_itimerspec *
967 jg compat_sys_timer_gettime
968
969ENTRY(sys32_timer_getoverrun_wrapper)
970 lgfr %r2,%r2 # timer_t (int)
971 jg sys_timer_getoverrun
972
973ENTRY(sys32_timer_delete_wrapper)
974 lgfr %r2,%r2 # timer_t (int)
975 jg sys_timer_delete
976
977ENTRY(sys32_io_setup_wrapper)
978 llgfr %r2,%r2 # unsigned int
979 llgtr %r3,%r3 # u32 *
980 jg compat_sys_io_setup
981
982ENTRY(sys32_io_destroy_wrapper)
983 llgfr %r2,%r2 # (aio_context_t) u32
984 jg sys_io_destroy
985
986ENTRY(sys32_io_getevents_wrapper)
987 llgfr %r2,%r2 # (aio_context_t) u32
988 lgfr %r3,%r3 # long
989 lgfr %r4,%r4 # long
990 llgtr %r5,%r5 # struct io_event *
991 llgtr %r6,%r6 # struct compat_timespec *
992 jg compat_sys_io_getevents
993
994ENTRY(sys32_io_submit_wrapper)
995 llgfr %r2,%r2 # (aio_context_t) u32
996 lgfr %r3,%r3 # long
997 llgtr %r4,%r4 # struct iocb **
998 jg compat_sys_io_submit
999
1000ENTRY(sys32_io_cancel_wrapper)
1001 llgfr %r2,%r2 # (aio_context_t) u32
1002 llgtr %r3,%r3 # struct iocb *
1003 llgtr %r4,%r4 # struct io_event *
1004 jg sys_io_cancel
1005
1006ENTRY(compat_sys_statfs64_wrapper)
1007 llgtr %r2,%r2 # const char *
1008 llgfr %r3,%r3 # compat_size_t
1009 llgtr %r4,%r4 # struct compat_statfs64 *
1010 jg compat_sys_statfs64
1011
1012ENTRY(compat_sys_fstatfs64_wrapper)
1013 llgfr %r2,%r2 # unsigned int fd
1014 llgfr %r3,%r3 # compat_size_t
1015 llgtr %r4,%r4 # struct compat_statfs64 *
1016 jg compat_sys_fstatfs64
1017
1018ENTRY(compat_sys_mq_open_wrapper)
1019 llgtr %r2,%r2 # const char *
1020 lgfr %r3,%r3 # int
1021 llgfr %r4,%r4 # mode_t
1022 llgtr %r5,%r5 # struct compat_mq_attr *
1023 jg compat_sys_mq_open
1024
1025ENTRY(sys32_mq_unlink_wrapper)
1026 llgtr %r2,%r2 # const char *
1027 jg sys_mq_unlink
1028
1029ENTRY(compat_sys_mq_timedsend_wrapper)
1030 lgfr %r2,%r2 # mqd_t
1031 llgtr %r3,%r3 # const char *
1032 llgfr %r4,%r4 # size_t
1033 llgfr %r5,%r5 # unsigned int
1034 llgtr %r6,%r6 # const struct compat_timespec *
1035 jg compat_sys_mq_timedsend
1036
1037ENTRY(compat_sys_mq_timedreceive_wrapper)
1038 lgfr %r2,%r2 # mqd_t
1039 llgtr %r3,%r3 # char *
1040 llgfr %r4,%r4 # size_t
1041 llgtr %r5,%r5 # unsigned int *
1042 llgtr %r6,%r6 # const struct compat_timespec *
1043 jg compat_sys_mq_timedreceive
1044
1045ENTRY(compat_sys_mq_notify_wrapper)
1046 lgfr %r2,%r2 # mqd_t
1047 llgtr %r3,%r3 # struct compat_sigevent *
1048 jg compat_sys_mq_notify
1049
1050ENTRY(compat_sys_mq_getsetattr_wrapper)
1051 lgfr %r2,%r2 # mqd_t
1052 llgtr %r3,%r3 # struct compat_mq_attr *
1053 llgtr %r4,%r4 # struct compat_mq_attr *
1054 jg compat_sys_mq_getsetattr
1055
1056ENTRY(compat_sys_add_key_wrapper)
1057 llgtr %r2,%r2 # const char *
1058 llgtr %r3,%r3 # const char *
1059 llgtr %r4,%r4 # const void *
1060 llgfr %r5,%r5 # size_t
1061 llgfr %r6,%r6 # (key_serial_t) u32
1062 jg sys_add_key
1063
1064ENTRY(compat_sys_request_key_wrapper)
1065 llgtr %r2,%r2 # const char *
1066 llgtr %r3,%r3 # const char *
1067 llgtr %r4,%r4 # const void *
1068 llgfr %r5,%r5 # (key_serial_t) u32
1069 jg sys_request_key
1070
1071ENTRY(sys32_remap_file_pages_wrapper)
1072 llgfr %r2,%r2 # unsigned long
1073 llgfr %r3,%r3 # unsigned long
1074 llgfr %r4,%r4 # unsigned long
1075 llgfr %r5,%r5 # unsigned long
1076 llgfr %r6,%r6 # unsigned long
1077 jg sys_remap_file_pages
1078
1079ENTRY(compat_sys_kexec_load_wrapper)
1080 llgfr %r2,%r2 # unsigned long
1081 llgfr %r3,%r3 # unsigned long
1082 llgtr %r4,%r4 # struct kexec_segment *
1083 llgfr %r5,%r5 # unsigned long
1084 jg compat_sys_kexec_load
1085
1086ENTRY(sys_ioprio_set_wrapper)
1087 lgfr %r2,%r2 # int
1088 lgfr %r3,%r3 # int
1089 lgfr %r4,%r4 # int
1090 jg sys_ioprio_set
1091
1092ENTRY(sys_ioprio_get_wrapper)
1093 lgfr %r2,%r2 # int
1094 lgfr %r3,%r3 # int
1095 jg sys_ioprio_get
1096
1097ENTRY(sys_inotify_add_watch_wrapper)
1098 lgfr %r2,%r2 # int
1099 llgtr %r3,%r3 # const char *
1100 llgfr %r4,%r4 # u32
1101 jg sys_inotify_add_watch
1102
1103ENTRY(sys_inotify_rm_watch_wrapper)
1104 lgfr %r2,%r2 # int
1105 llgfr %r3,%r3 # u32
1106 jg sys_inotify_rm_watch
1107
1108ENTRY(sys_mkdirat_wrapper)
1109 lgfr %r2,%r2 # int
1110 llgtr %r3,%r3 # const char *
1111 lgfr %r4,%r4 # int
1112 jg sys_mkdirat
1113
1114ENTRY(sys_mknodat_wrapper)
1115 lgfr %r2,%r2 # int
1116 llgtr %r3,%r3 # const char *
1117 lgfr %r4,%r4 # int
1118 llgfr %r5,%r5 # unsigned int
1119 jg sys_mknodat
1120
1121ENTRY(sys_fchownat_wrapper)
1122 lgfr %r2,%r2 # int
1123 llgtr %r3,%r3 # const char *
1124 llgfr %r4,%r4 # uid_t
1125 llgfr %r5,%r5 # gid_t
1126 lgfr %r6,%r6 # int
1127 jg sys_fchownat
1128
1129ENTRY(compat_sys_futimesat_wrapper)
1130 llgfr %r2,%r2 # unsigned int
1131 llgtr %r3,%r3 # char *
1132 llgtr %r4,%r4 # struct timeval *
1133 jg compat_sys_futimesat
1134
1135ENTRY(sys32_fstatat64_wrapper)
1136 llgfr %r2,%r2 # unsigned int
1137 llgtr %r3,%r3 # char *
1138 llgtr %r4,%r4 # struct stat64 *
1139 lgfr %r5,%r5 # int
1140 jg sys32_fstatat64
1141
1142ENTRY(sys_unlinkat_wrapper)
1143 lgfr %r2,%r2 # int
1144 llgtr %r3,%r3 # const char *
1145 lgfr %r4,%r4 # int
1146 jg sys_unlinkat
1147
1148ENTRY(sys_renameat_wrapper)
1149 lgfr %r2,%r2 # int
1150 llgtr %r3,%r3 # const char *
1151 lgfr %r4,%r4 # int
1152 llgtr %r5,%r5 # const char *
1153 jg sys_renameat
1154
1155ENTRY(sys_linkat_wrapper)
1156 lgfr %r2,%r2 # int
1157 llgtr %r3,%r3 # const char *
1158 lgfr %r4,%r4 # int
1159 llgtr %r5,%r5 # const char *
1160 lgfr %r6,%r6 # int
1161 jg sys_linkat
1162
1163ENTRY(sys_symlinkat_wrapper)
1164 llgtr %r2,%r2 # const char *
1165 lgfr %r3,%r3 # int
1166 llgtr %r4,%r4 # const char *
1167 jg sys_symlinkat
1168
1169ENTRY(sys_readlinkat_wrapper)
1170 lgfr %r2,%r2 # int
1171 llgtr %r3,%r3 # const char *
1172 llgtr %r4,%r4 # char *
1173 lgfr %r5,%r5 # int
1174 jg sys_readlinkat
1175
1176ENTRY(sys_fchmodat_wrapper)
1177 lgfr %r2,%r2 # int
1178 llgtr %r3,%r3 # const char *
1179 llgfr %r4,%r4 # mode_t
1180 jg sys_fchmodat
1181
1182ENTRY(sys_faccessat_wrapper)
1183 lgfr %r2,%r2 # int
1184 llgtr %r3,%r3 # const char *
1185 lgfr %r4,%r4 # int
1186 jg sys_faccessat
1187
1188ENTRY(compat_sys_pselect6_wrapper)
1189 lgfr %r2,%r2 # int
1190 llgtr %r3,%r3 # fd_set *
1191 llgtr %r4,%r4 # fd_set *
1192 llgtr %r5,%r5 # fd_set *
1193 llgtr %r6,%r6 # struct timespec *
1194 llgt %r0,164(%r15) # void *
1195 stg %r0,160(%r15)
1196 jg compat_sys_pselect6
1197
1198ENTRY(compat_sys_ppoll_wrapper)
1199 llgtr %r2,%r2 # struct pollfd *
1200 llgfr %r3,%r3 # unsigned int
1201 llgtr %r4,%r4 # struct timespec *
1202 llgtr %r5,%r5 # const sigset_t *
1203 llgfr %r6,%r6 # size_t
1204 jg compat_sys_ppoll
1205
1206ENTRY(sys_unshare_wrapper)
1207 llgfr %r2,%r2 # unsigned long
1208 jg sys_unshare
1209
1210ENTRY(sys_splice_wrapper)
1211 lgfr %r2,%r2 # int
1212 llgtr %r3,%r3 # loff_t *
1213 lgfr %r4,%r4 # int
1214 llgtr %r5,%r5 # loff_t *
1215 llgfr %r6,%r6 # size_t
1216 llgf %r0,164(%r15) # unsigned int
1217 stg %r0,160(%r15)
1218 jg sys_splice
1219
1220ENTRY(sys_sync_file_range_wrapper)
1221 lgfr %r2,%r2 # int
1222 sllg %r3,%r3,32 # get high word of 64bit loff_t
1223 or %r3,%r4 # get low word of 64bit loff_t
1224 sllg %r4,%r5,32 # get high word of 64bit loff_t
1225 or %r4,%r6 # get low word of 64bit loff_t
1226 llgf %r5,164(%r15) # unsigned int
1227 jg sys_sync_file_range
1228
1229ENTRY(sys_tee_wrapper)
1230 lgfr %r2,%r2 # int
1231 lgfr %r3,%r3 # int
1232 llgfr %r4,%r4 # size_t
1233 llgfr %r5,%r5 # unsigned int
1234 jg sys_tee
1235
1236ENTRY(sys_getcpu_wrapper)
1237 llgtr %r2,%r2 # unsigned *
1238 llgtr %r3,%r3 # unsigned *
1239 llgtr %r4,%r4 # struct getcpu_cache *
1240 jg sys_getcpu
1241
1242ENTRY(compat_sys_utimes_wrapper)
1243 llgtr %r2,%r2 # char *
1244 llgtr %r3,%r3 # struct compat_timeval *
1245 jg compat_sys_utimes
1246
1247ENTRY(compat_sys_utimensat_wrapper)
1248 llgfr %r2,%r2 # unsigned int
1249 llgtr %r3,%r3 # char *
1250 llgtr %r4,%r4 # struct compat_timespec *
1251 lgfr %r5,%r5 # int
1252 jg compat_sys_utimensat
1253
1254ENTRY(sys_eventfd_wrapper)
1255 llgfr %r2,%r2 # unsigned int
1256 jg sys_eventfd
1257
1258ENTRY(sys_fallocate_wrapper)
1259 lgfr %r2,%r2 # int
1260 lgfr %r3,%r3 # int
1261 sllg %r4,%r4,32 # get high word of 64bit loff_t
1262 lr %r4,%r5 # get low word of 64bit loff_t
1263 sllg %r5,%r6,32 # get high word of 64bit loff_t
1264 l %r5,164(%r15) # get low word of 64bit loff_t
1265 jg sys_fallocate
1266
1267ENTRY(sys_timerfd_create_wrapper)
1268 lgfr %r2,%r2 # int
1269 lgfr %r3,%r3 # int
1270 jg sys_timerfd_create
1271
1272ENTRY(sys_eventfd2_wrapper)
1273 llgfr %r2,%r2 # unsigned int
1274 lgfr %r3,%r3 # int
1275 jg sys_eventfd2
1276
1277ENTRY(sys_inotify_init1_wrapper)
1278 lgfr %r2,%r2 # int
1279 jg sys_inotify_init1
1280
1281ENTRY(sys_pipe2_wrapper)
1282 llgtr %r2,%r2 # u32 *
1283 lgfr %r3,%r3 # int
1284 jg sys_pipe2 # branch to system call
1285
1286ENTRY(sys_dup3_wrapper)
1287 llgfr %r2,%r2 # unsigned int
1288 llgfr %r3,%r3 # unsigned int
1289 lgfr %r4,%r4 # int
1290 jg sys_dup3 # branch to system call
1291
1292ENTRY(sys_epoll_create1_wrapper)
1293 lgfr %r2,%r2 # int
1294 jg sys_epoll_create1 # branch to system call
1295
1296ENTRY(sys32_readahead_wrapper)
1297 lgfr %r2,%r2 # int
1298 llgfr %r3,%r3 # u32
1299 llgfr %r4,%r4 # u32
1300 lgfr %r5,%r5 # s32
1301 jg sys32_readahead # branch to system call
1302
1303ENTRY(sys_tkill_wrapper)
1304 lgfr %r2,%r2 # pid_t
1305 lgfr %r3,%r3 # int
1306 jg sys_tkill # branch to system call
1307
1308ENTRY(sys_tgkill_wrapper)
1309 lgfr %r2,%r2 # pid_t
1310 lgfr %r3,%r3 # pid_t
1311 lgfr %r4,%r4 # int
1312 jg sys_tgkill # branch to system call
1313
1314ENTRY(compat_sys_keyctl_wrapper)
1315 llgfr %r2,%r2 # u32
1316 llgfr %r3,%r3 # u32
1317 llgfr %r4,%r4 # u32
1318 llgfr %r5,%r5 # u32
1319 llgfr %r6,%r6 # u32
1320 jg compat_sys_keyctl # branch to system call
1321
1322ENTRY(sys_perf_event_open_wrapper)
1323 llgtr %r2,%r2 # const struct perf_event_attr *
1324 lgfr %r3,%r3 # pid_t
1325 lgfr %r4,%r4 # int
1326 lgfr %r5,%r5 # int
1327 llgfr %r6,%r6 # unsigned long
1328 jg sys_perf_event_open # branch to system call
1329
1330ENTRY(sys_clone_wrapper)
1331 llgfr %r2,%r2 # unsigned long
1332 llgfr %r3,%r3 # unsigned long
1333 llgtr %r4,%r4 # int *
1334 llgtr %r5,%r5 # int *
1335 jg sys_clone # branch to system call
1336
1337ENTRY(sys32_execve_wrapper)
1338 llgtr %r2,%r2 # char *
1339 llgtr %r3,%r3 # compat_uptr_t *
1340 llgtr %r4,%r4 # compat_uptr_t *
1341 jg compat_sys_execve # branch to system call
1342
1343ENTRY(sys_fanotify_init_wrapper)
1344 llgfr %r2,%r2 # unsigned int
1345 llgfr %r3,%r3 # unsigned int
1346 jg sys_fanotify_init # branch to system call
1347
1348ENTRY(sys_prlimit64_wrapper)
1349 lgfr %r2,%r2 # pid_t
1350 llgfr %r3,%r3 # unsigned int
1351 llgtr %r4,%r4 # const struct rlimit64 __user *
1352 llgtr %r5,%r5 # struct rlimit64 __user *
1353 jg sys_prlimit64 # branch to system call
1354
1355ENTRY(sys_name_to_handle_at_wrapper)
1356 lgfr %r2,%r2 # int
1357 llgtr %r3,%r3 # const char __user *
1358 llgtr %r4,%r4 # struct file_handle __user *
1359 llgtr %r5,%r5 # int __user *
1360 lgfr %r6,%r6 # int
1361 jg sys_name_to_handle_at
1362
1363ENTRY(compat_sys_clock_adjtime_wrapper)
1364 lgfr %r2,%r2 # clockid_t (int)
1365 llgtr %r3,%r3 # struct compat_timex __user *
1366 jg compat_sys_clock_adjtime
1367
1368ENTRY(sys_syncfs_wrapper)
1369 lgfr %r2,%r2 # int
1370 jg sys_syncfs
1371
1372ENTRY(sys_setns_wrapper)
1373 lgfr %r2,%r2 # int
1374 lgfr %r3,%r3 # int
1375 jg sys_setns
1376
1377ENTRY(compat_sys_process_vm_readv_wrapper)
1378 lgfr %r2,%r2 # compat_pid_t
1379 llgtr %r3,%r3 # struct compat_iovec __user *
1380 llgfr %r4,%r4 # unsigned long
1381 llgtr %r5,%r5 # struct compat_iovec __user *
1382 llgfr %r6,%r6 # unsigned long
1383 llgf %r0,164(%r15) # unsigned long
1384 stg %r0,160(%r15)
1385 jg compat_sys_process_vm_readv
1386
1387ENTRY(compat_sys_process_vm_writev_wrapper)
1388 lgfr %r2,%r2 # compat_pid_t
1389 llgtr %r3,%r3 # struct compat_iovec __user *
1390 llgfr %r4,%r4 # unsigned long
1391 llgtr %r5,%r5 # struct compat_iovec __user *
1392 llgfr %r6,%r6 # unsigned long
1393 llgf %r0,164(%r15) # unsigned long
1394 stg %r0,160(%r15)
1395 jg compat_sys_process_vm_writev
1396
1397ENTRY(sys_s390_runtime_instr_wrapper)
1398 lgfr %r2,%r2 # int
1399 lgfr %r3,%r3 # int
1400 jg sys_s390_runtime_instr
1401
1402ENTRY(sys_kcmp_wrapper)
1403 lgfr %r2,%r2 # pid_t
1404 lgfr %r3,%r3 # pid_t
1405 lgfr %r4,%r4 # int
1406 llgfr %r5,%r5 # unsigned long
1407 llgfr %r6,%r6 # unsigned long
1408 jg sys_kcmp
1409
1410ENTRY(sys_finit_module_wrapper)
1411 lgfr %r2,%r2 # int
1412 llgtr %r3,%r3 # const char __user *
1413 lgfr %r4,%r4 # int
1414 jg sys_finit_module
1415
1416ENTRY(sys_sched_setattr_wrapper)
1417 lgfr %r2,%r2 # pid_t
1418 llgtr %r3,%r3 # struct sched_attr __user *
1419 jg sys_sched_setattr
1420
1421ENTRY(sys_sched_getattr_wrapper)
1422 lgfr %r2,%r2 # pid_t
1423 llgtr %r3,%r3 # const char __user *
1424 llgfr %r3,%r3 # unsigned int
1425 jg sys_sched_getattr
diff --git a/arch/s390/kernel/compat_wrapper.c b/arch/s390/kernel/compat_wrapper.c
new file mode 100644
index 000000000000..824c39dfddfc
--- /dev/null
+++ b/arch/s390/kernel/compat_wrapper.c
@@ -0,0 +1,215 @@
1/*
2 * Compat sytem call wrappers.
3 *
4 * Copyright IBM Corp. 2014
5 */
6
7#include <linux/syscalls.h>
8#include <linux/compat.h>
9#include "entry.h"
10
11#define COMPAT_SYSCALL_WRAP1(name, ...) \
12 COMPAT_SYSCALL_WRAPx(1, _##name, __VA_ARGS__)
13#define COMPAT_SYSCALL_WRAP2(name, ...) \
14 COMPAT_SYSCALL_WRAPx(2, _##name, __VA_ARGS__)
15#define COMPAT_SYSCALL_WRAP3(name, ...) \
16 COMPAT_SYSCALL_WRAPx(3, _##name, __VA_ARGS__)
17#define COMPAT_SYSCALL_WRAP4(name, ...) \
18 COMPAT_SYSCALL_WRAPx(4, _##name, __VA_ARGS__)
19#define COMPAT_SYSCALL_WRAP5(name, ...) \
20 COMPAT_SYSCALL_WRAPx(5, _##name, __VA_ARGS__)
21#define COMPAT_SYSCALL_WRAP6(name, ...) \
22 COMPAT_SYSCALL_WRAPx(6, _##name, __VA_ARGS__)
23
24#define __SC_COMPAT_TYPE(t, a) \
25 __typeof(__builtin_choose_expr(sizeof(t) > 4, 0L, (t)0)) a
26
27#define __SC_COMPAT_CAST(t, a) \
28({ \
29 long __ReS = a; \
30 \
31 BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) && \
32 !__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t)); \
33 if (__TYPE_IS_L(t)) \
34 __ReS = (s32)a; \
35 if (__TYPE_IS_UL(t)) \
36 __ReS = (u32)a; \
37 if (__TYPE_IS_PTR(t)) \
38 __ReS = a & 0x7fffffff; \
39 (t)__ReS; \
40})
41
42/*
43 * The COMPAT_SYSCALL_WRAP macro generates system call wrappers to be used by
44 * compat tasks. These wrappers will only be used for system calls where only
45 * the system call arguments need sign or zero extension or zeroing of the upper
46 * 33 bits of pointers.
47 * Note: since the wrapper function will afterwards call a system call which
48 * again performs zero and sign extension for all system call arguments with
49 * a size of less than eight bytes, these compat wrappers only touch those
50 * system call arguments with a size of eight bytes ((unsigned) long and
51 * pointers). Zero and sign extension for e.g. int parameters will be done by
52 * the regular system call wrappers.
53 */
54#define COMPAT_SYSCALL_WRAPx(x, name, ...) \
55 asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
56 asmlinkage long compat_sys##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__));\
57 asmlinkage long compat_sys##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__)) \
58 { \
59 return sys##name(__MAP(x,__SC_COMPAT_CAST,__VA_ARGS__)); \
60 }
61
62COMPAT_SYSCALL_WRAP1(exit, int, error_code);
63COMPAT_SYSCALL_WRAP1(close, unsigned int, fd);
64COMPAT_SYSCALL_WRAP2(creat, const char __user *, pathname, umode_t, mode);
65COMPAT_SYSCALL_WRAP2(link, const char __user *, oldname, const char __user *, newname);
66COMPAT_SYSCALL_WRAP1(unlink, const char __user *, pathname);
67COMPAT_SYSCALL_WRAP1(chdir, const char __user *, filename);
68COMPAT_SYSCALL_WRAP3(mknod, const char __user *, filename, umode_t, mode, unsigned, dev);
69COMPAT_SYSCALL_WRAP2(chmod, const char __user *, filename, umode_t, mode);
70COMPAT_SYSCALL_WRAP1(oldumount, char __user *, name);
71COMPAT_SYSCALL_WRAP1(alarm, unsigned int, seconds);
72COMPAT_SYSCALL_WRAP2(access, const char __user *, filename, int, mode);
73COMPAT_SYSCALL_WRAP1(nice, int, increment);
74COMPAT_SYSCALL_WRAP2(kill, int, pid, int, sig);
75COMPAT_SYSCALL_WRAP2(rename, const char __user *, oldname, const char __user *, newname);
76COMPAT_SYSCALL_WRAP2(mkdir, const char __user *, pathname, umode_t, mode);
77COMPAT_SYSCALL_WRAP1(rmdir, const char __user *, pathname);
78COMPAT_SYSCALL_WRAP1(dup, unsigned int, fildes);
79COMPAT_SYSCALL_WRAP1(pipe, int __user *, fildes);
80COMPAT_SYSCALL_WRAP1(brk, unsigned long, brk);
81COMPAT_SYSCALL_WRAP2(signal, int, sig, __sighandler_t, handler);
82COMPAT_SYSCALL_WRAP1(acct, const char __user *, name);
83COMPAT_SYSCALL_WRAP2(umount, char __user *, name, int, flags);
84COMPAT_SYSCALL_WRAP2(setpgid, pid_t, pid, pid_t, pgid);
85COMPAT_SYSCALL_WRAP1(umask, int, mask);
86COMPAT_SYSCALL_WRAP1(chroot, const char __user *, filename);
87COMPAT_SYSCALL_WRAP2(dup2, unsigned int, oldfd, unsigned int, newfd);
88COMPAT_SYSCALL_WRAP3(sigsuspend, int, unused1, int, unused2, old_sigset_t, mask);
89COMPAT_SYSCALL_WRAP2(sethostname, char __user *, name, int, len);
90COMPAT_SYSCALL_WRAP2(symlink, const char __user *, old, const char __user *, new);
91COMPAT_SYSCALL_WRAP3(readlink, const char __user *, path, char __user *, buf, int, bufsiz);
92COMPAT_SYSCALL_WRAP1(uselib, const char __user *, library);
93COMPAT_SYSCALL_WRAP2(swapon, const char __user *, specialfile, int, swap_flags);
94COMPAT_SYSCALL_WRAP4(reboot, int, magic1, int, magic2, unsigned int, cmd, void __user *, arg);
95COMPAT_SYSCALL_WRAP2(munmap, unsigned long, addr, size_t, len);
96COMPAT_SYSCALL_WRAP2(fchmod, unsigned int, fd, umode_t, mode);
97COMPAT_SYSCALL_WRAP2(getpriority, int, which, int, who);
98COMPAT_SYSCALL_WRAP3(setpriority, int, which, int, who, int, niceval);
99COMPAT_SYSCALL_WRAP3(syslog, int, type, char __user *, buf, int, len);
100COMPAT_SYSCALL_WRAP1(swapoff, const char __user *, specialfile);
101COMPAT_SYSCALL_WRAP1(fsync, unsigned int, fd);
102COMPAT_SYSCALL_WRAP2(setdomainname, char __user *, name, int, len);
103COMPAT_SYSCALL_WRAP1(newuname, struct new_utsname __user *, name);
104COMPAT_SYSCALL_WRAP3(mprotect, unsigned long, start, size_t, len, unsigned long, prot);
105COMPAT_SYSCALL_WRAP3(init_module, void __user *, umod, unsigned long, len, const char __user *, uargs);
106COMPAT_SYSCALL_WRAP2(delete_module, const char __user *, name_user, unsigned int, flags);
107COMPAT_SYSCALL_WRAP4(quotactl, unsigned int, cmd, const char __user *, special, qid_t, id, void __user *, addr);
108COMPAT_SYSCALL_WRAP1(getpgid, pid_t, pid);
109COMPAT_SYSCALL_WRAP1(fchdir, unsigned int, fd);
110COMPAT_SYSCALL_WRAP2(bdflush, int, func, long, data);
111COMPAT_SYSCALL_WRAP3(sysfs, int, option, unsigned long, arg1, unsigned long, arg2);
112COMPAT_SYSCALL_WRAP1(s390_personality, unsigned int, personality);
113COMPAT_SYSCALL_WRAP5(llseek, unsigned int, fd, unsigned long, high, unsigned long, low, loff_t __user *, result, unsigned int, whence);
114COMPAT_SYSCALL_WRAP2(flock, unsigned int, fd, unsigned int, cmd);
115COMPAT_SYSCALL_WRAP3(msync, unsigned long, start, size_t, len, int, flags);
116COMPAT_SYSCALL_WRAP1(getsid, pid_t, pid);
117COMPAT_SYSCALL_WRAP1(fdatasync, unsigned int, fd);
118COMPAT_SYSCALL_WRAP2(mlock, unsigned long, start, size_t, len);
119COMPAT_SYSCALL_WRAP2(munlock, unsigned long, start, size_t, len);
120COMPAT_SYSCALL_WRAP1(mlockall, int, flags);
121COMPAT_SYSCALL_WRAP2(sched_setparam, pid_t, pid, struct sched_param __user *, param);
122COMPAT_SYSCALL_WRAP2(sched_getparam, pid_t, pid, struct sched_param __user *, param);
123COMPAT_SYSCALL_WRAP3(sched_setscheduler, pid_t, pid, int, policy, struct sched_param __user *, param);
124COMPAT_SYSCALL_WRAP1(sched_getscheduler, pid_t, pid);
125COMPAT_SYSCALL_WRAP1(sched_get_priority_max, int, policy);
126COMPAT_SYSCALL_WRAP1(sched_get_priority_min, int, policy);
127COMPAT_SYSCALL_WRAP5(mremap, unsigned long, addr, unsigned long, old_len, unsigned long, new_len, unsigned long, flags, unsigned long, new_addr);
128COMPAT_SYSCALL_WRAP3(poll, struct pollfd __user *, ufds, unsigned int, nfds, int, timeout);
129COMPAT_SYSCALL_WRAP5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, unsigned long, arg4, unsigned long, arg5);
130COMPAT_SYSCALL_WRAP2(getcwd, char __user *, buf, unsigned long, size);
131COMPAT_SYSCALL_WRAP2(capget, cap_user_header_t, header, cap_user_data_t, dataptr);
132COMPAT_SYSCALL_WRAP2(capset, cap_user_header_t, header, const cap_user_data_t, data);
133COMPAT_SYSCALL_WRAP3(lchown, const char __user *, filename, uid_t, user, gid_t, group);
134COMPAT_SYSCALL_WRAP2(setreuid, uid_t, ruid, uid_t, euid);
135COMPAT_SYSCALL_WRAP2(setregid, gid_t, rgid, gid_t, egid);
136COMPAT_SYSCALL_WRAP2(getgroups, int, gidsetsize, gid_t __user *, grouplist);
137COMPAT_SYSCALL_WRAP2(setgroups, int, gidsetsize, gid_t __user *, grouplist);
138COMPAT_SYSCALL_WRAP3(fchown, unsigned int, fd, uid_t, user, gid_t, group);
139COMPAT_SYSCALL_WRAP3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid);
140COMPAT_SYSCALL_WRAP3(getresuid, uid_t __user *, ruid, uid_t __user *, euid, uid_t __user *, suid);
141COMPAT_SYSCALL_WRAP3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid);
142COMPAT_SYSCALL_WRAP3(getresgid, gid_t __user *, rgid, gid_t __user *, egid, gid_t __user *, sgid);
143COMPAT_SYSCALL_WRAP3(chown, const char __user *, filename, uid_t, user, gid_t, group);
144COMPAT_SYSCALL_WRAP1(setuid, uid_t, uid);
145COMPAT_SYSCALL_WRAP1(setgid, gid_t, gid);
146COMPAT_SYSCALL_WRAP1(setfsuid, uid_t, uid);
147COMPAT_SYSCALL_WRAP1(setfsgid, gid_t, gid);
148COMPAT_SYSCALL_WRAP2(pivot_root, const char __user *, new_root, const char __user *, put_old);
149COMPAT_SYSCALL_WRAP3(mincore, unsigned long, start, size_t, len, unsigned char __user *, vec);
150COMPAT_SYSCALL_WRAP3(madvise, unsigned long, start, size_t, len, int, behavior);
151COMPAT_SYSCALL_WRAP5(setxattr, const char __user *, path, const char __user *, name, const void __user *, value, size_t, size, int, flags);
152COMPAT_SYSCALL_WRAP5(lsetxattr, const char __user *, path, const char __user *, name, const void __user *, value, size_t, size, int, flags);
153COMPAT_SYSCALL_WRAP5(fsetxattr, int, fd, const char __user *, name, const void __user *, value, size_t, size, int, flags);
154COMPAT_SYSCALL_WRAP3(getdents64, unsigned int, fd, struct linux_dirent64 __user *, dirent, unsigned int, count);
155COMPAT_SYSCALL_WRAP4(getxattr, const char __user *, path, const char __user *, name, void __user *, value, size_t, size);
156COMPAT_SYSCALL_WRAP4(lgetxattr, const char __user *, path, const char __user *, name, void __user *, value, size_t, size);
157COMPAT_SYSCALL_WRAP4(fgetxattr, int, fd, const char __user *, name, void __user *, value, size_t, size);
158COMPAT_SYSCALL_WRAP3(listxattr, const char __user *, path, char __user *, list, size_t, size);
159COMPAT_SYSCALL_WRAP3(llistxattr, const char __user *, path, char __user *, list, size_t, size);
160COMPAT_SYSCALL_WRAP3(flistxattr, int, fd, char __user *, list, size_t, size);
161COMPAT_SYSCALL_WRAP2(removexattr, const char __user *, path, const char __user *, name);
162COMPAT_SYSCALL_WRAP2(lremovexattr, const char __user *, path, const char __user *, name);
163COMPAT_SYSCALL_WRAP2(fremovexattr, int, fd, const char __user *, name);
164COMPAT_SYSCALL_WRAP1(exit_group, int, error_code);
165COMPAT_SYSCALL_WRAP1(set_tid_address, int __user *, tidptr);
166COMPAT_SYSCALL_WRAP1(epoll_create, int, size);
167COMPAT_SYSCALL_WRAP4(epoll_ctl, int, epfd, int, op, int, fd, struct epoll_event __user *, event);
168COMPAT_SYSCALL_WRAP4(epoll_wait, int, epfd, struct epoll_event __user *, events, int, maxevents, int, timeout);
169COMPAT_SYSCALL_WRAP1(timer_getoverrun, timer_t, timer_id);
170COMPAT_SYSCALL_WRAP1(timer_delete, compat_timer_t, compat_timer_id);
171COMPAT_SYSCALL_WRAP1(io_destroy, aio_context_t, ctx);
172COMPAT_SYSCALL_WRAP3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb, struct io_event __user *, result);
173COMPAT_SYSCALL_WRAP1(mq_unlink, const char __user *, name);
174COMPAT_SYSCALL_WRAP5(add_key, const char __user *, tp, const char __user *, dsc, const void __user *, pld, size_t, len, key_serial_t, id);
175COMPAT_SYSCALL_WRAP4(request_key, const char __user *, tp, const char __user *, dsc, const char __user *, info, key_serial_t, id);
176COMPAT_SYSCALL_WRAP5(remap_file_pages, unsigned long, start, unsigned long, size, unsigned long, prot, unsigned long, pgoff, unsigned long, flags);
177COMPAT_SYSCALL_WRAP3(ioprio_set, int, which, int, who, int, ioprio);
178COMPAT_SYSCALL_WRAP2(ioprio_get, int, which, int, who);
179COMPAT_SYSCALL_WRAP3(inotify_add_watch, int, fd, const char __user *, path, u32, mask);
180COMPAT_SYSCALL_WRAP2(inotify_rm_watch, int, fd, __s32, wd);
181COMPAT_SYSCALL_WRAP3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode);
182COMPAT_SYSCALL_WRAP4(mknodat, int, dfd, const char __user *, filename, umode_t, mode, unsigned, dev);
183COMPAT_SYSCALL_WRAP5(fchownat, int, dfd, const char __user *, filename, uid_t, user, gid_t, group, int, flag);
184COMPAT_SYSCALL_WRAP3(unlinkat, int, dfd, const char __user *, pathname, int, flag);
185COMPAT_SYSCALL_WRAP4(renameat, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname);
186COMPAT_SYSCALL_WRAP5(linkat, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname, int, flags);
187COMPAT_SYSCALL_WRAP3(symlinkat, const char __user *, oldname, int, newdfd, const char __user *, newname);
188COMPAT_SYSCALL_WRAP4(readlinkat, int, dfd, const char __user *, path, char __user *, buf, int, bufsiz);
189COMPAT_SYSCALL_WRAP3(fchmodat, int, dfd, const char __user *, filename, umode_t, mode);
190COMPAT_SYSCALL_WRAP3(faccessat, int, dfd, const char __user *, filename, int, mode);
191COMPAT_SYSCALL_WRAP1(unshare, unsigned long, unshare_flags);
192COMPAT_SYSCALL_WRAP6(splice, int, fd_in, loff_t __user *, off_in, int, fd_out, loff_t __user *, off_out, size_t, len, unsigned int, flags);
193COMPAT_SYSCALL_WRAP4(tee, int, fdin, int, fdout, size_t, len, unsigned int, flags);
194COMPAT_SYSCALL_WRAP3(getcpu, unsigned __user *, cpu, unsigned __user *, node, struct getcpu_cache __user *, cache);
195COMPAT_SYSCALL_WRAP1(eventfd, unsigned int, count);
196COMPAT_SYSCALL_WRAP2(timerfd_create, int, clockid, int, flags);
197COMPAT_SYSCALL_WRAP2(eventfd2, unsigned int, count, int, flags);
198COMPAT_SYSCALL_WRAP1(inotify_init1, int, flags);
199COMPAT_SYSCALL_WRAP2(pipe2, int __user *, fildes, int, flags);
200COMPAT_SYSCALL_WRAP3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags);
201COMPAT_SYSCALL_WRAP1(epoll_create1, int, flags);
202COMPAT_SYSCALL_WRAP2(tkill, int, pid, int, sig);
203COMPAT_SYSCALL_WRAP3(tgkill, int, tgid, int, pid, int, sig);
204COMPAT_SYSCALL_WRAP5(perf_event_open, struct perf_event_attr __user *, attr_uptr, pid_t, pid, int, cpu, int, group_fd, unsigned long, flags);
205COMPAT_SYSCALL_WRAP5(clone, unsigned long, newsp, unsigned long, clone_flags, int __user *, parent_tidptr, int __user *, child_tidptr, int, tls_val);
206COMPAT_SYSCALL_WRAP2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags);
207COMPAT_SYSCALL_WRAP4(prlimit64, pid_t, pid, unsigned int, resource, const struct rlimit64 __user *, new_rlim, struct rlimit64 __user *, old_rlim);
208COMPAT_SYSCALL_WRAP5(name_to_handle_at, int, dfd, const char __user *, name, struct file_handle __user *, handle, int __user *, mnt_id, int, flag);
209COMPAT_SYSCALL_WRAP1(syncfs, int, fd);
210COMPAT_SYSCALL_WRAP2(setns, int, fd, int, nstype);
211COMPAT_SYSCALL_WRAP2(s390_runtime_instr, int, command, int, signum);
212COMPAT_SYSCALL_WRAP5(kcmp, pid_t, pid1, pid_t, pid2, int, type, unsigned long, idx1, unsigned long, idx2);
213COMPAT_SYSCALL_WRAP3(finit_module, int, fd, const char __user *, uargs, int, flags);
214COMPAT_SYSCALL_WRAP3(sched_setattr, pid_t, pid, struct sched_attr __user *, attr, unsigned int, flags);
215COMPAT_SYSCALL_WRAP4(sched_getattr, pid_t, pid, struct sched_attr __user *, attr, unsigned int, size, unsigned int, flags);
diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
index fca20b5fe79e..6b594439cca5 100644
--- a/arch/s390/kernel/early.c
+++ b/arch/s390/kernel/early.c
@@ -380,8 +380,6 @@ static __init void detect_machine_facilities(void)
380 S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT2; 380 S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT2;
381 if (test_facility(3)) 381 if (test_facility(3))
382 S390_lowcore.machine_flags |= MACHINE_FLAG_IDTE; 382 S390_lowcore.machine_flags |= MACHINE_FLAG_IDTE;
383 if (test_facility(27))
384 S390_lowcore.machine_flags |= MACHINE_FLAG_MVCOS;
385 if (test_facility(40)) 383 if (test_facility(40))
386 S390_lowcore.machine_flags |= MACHINE_FLAG_LPP; 384 S390_lowcore.machine_flags |= MACHINE_FLAG_LPP;
387 if (test_facility(50) && test_facility(73)) 385 if (test_facility(50) && test_facility(73))
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 0dc2b6d0a1ec..526d3735ed29 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -43,6 +43,7 @@ _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
43 _TIF_MCCK_PENDING) 43 _TIF_MCCK_PENDING)
44_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \ 44_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
45 _TIF_SYSCALL_TRACEPOINT) 45 _TIF_SYSCALL_TRACEPOINT)
46_TIF_TRANSFER = (_TIF_MCCK_PENDING | _TIF_TLB_WAIT)
46 47
47STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER 48STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
48STACK_SIZE = 1 << STACK_SHIFT 49STACK_SIZE = 1 << STACK_SHIFT
@@ -159,10 +160,12 @@ ENTRY(__switch_to)
159 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4 160 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
160 mvc __LC_CURRENT_PID(4,%r0),__TASK_pid(%r3) # store pid of next 161 mvc __LC_CURRENT_PID(4,%r0),__TASK_pid(%r3) # store pid of next
161 l %r15,__THREAD_ksp(%r3) # load kernel stack of next 162 l %r15,__THREAD_ksp(%r3) # load kernel stack of next
162 tm __TI_flags+3(%r4),_TIF_MCCK_PENDING # machine check pending? 163 lhi %r6,_TIF_TRANSFER # transfer TIF bits
164 n %r6,__TI_flags(%r4) # isolate TIF bits
163 jz 0f 165 jz 0f
164 ni __TI_flags+3(%r4),255-_TIF_MCCK_PENDING # clear flag in prev 166 o %r6,__TI_flags(%r5) # set TIF bits of next
165 oi __TI_flags+3(%r5),_TIF_MCCK_PENDING # set it in next 167 st %r6,__TI_flags(%r5)
168 ni __TI_flags+3(%r4),255-_TIF_TRANSFER # clear TIF bits of prev
1660: lm %r6,%r15,__SF_GPRS(%r15) # load gprs of next task 1690: lm %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
167 br %r14 170 br %r14
168 171
diff --git a/arch/s390/kernel/entry.h b/arch/s390/kernel/entry.h
index cb533f78c09e..6ac78192455f 100644
--- a/arch/s390/kernel/entry.h
+++ b/arch/s390/kernel/entry.h
@@ -67,9 +67,7 @@ struct s390_mmap_arg_struct;
67struct fadvise64_64_args; 67struct fadvise64_64_args;
68struct old_sigaction; 68struct old_sigaction;
69 69
70long sys_sigreturn(void); 70long sys_s390_personality(unsigned int personality);
71long sys_rt_sigreturn(void); 71long sys_s390_runtime_instr(int command, int signum);
72long sys32_sigreturn(void);
73long sys32_rt_sigreturn(void);
74 72
75#endif /* _ENTRY_H */ 73#endif /* _ENTRY_H */
diff --git a/arch/s390/kernel/entry64.S b/arch/s390/kernel/entry64.S
index 384e609b4711..e09dbe5f2901 100644
--- a/arch/s390/kernel/entry64.S
+++ b/arch/s390/kernel/entry64.S
@@ -48,6 +48,7 @@ _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
48 _TIF_MCCK_PENDING) 48 _TIF_MCCK_PENDING)
49_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \ 49_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
50 _TIF_SYSCALL_TRACEPOINT) 50 _TIF_SYSCALL_TRACEPOINT)
51_TIF_TRANSFER = (_TIF_MCCK_PENDING | _TIF_TLB_WAIT)
51 52
52#define BASED(name) name-system_call(%r13) 53#define BASED(name) name-system_call(%r13)
53 54
@@ -189,10 +190,12 @@ ENTRY(__switch_to)
189 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4 190 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
190 mvc __LC_CURRENT_PID+4(4,%r0),__TASK_pid(%r3) # store pid of next 191 mvc __LC_CURRENT_PID+4(4,%r0),__TASK_pid(%r3) # store pid of next
191 lg %r15,__THREAD_ksp(%r3) # load kernel stack of next 192 lg %r15,__THREAD_ksp(%r3) # load kernel stack of next
192 tm __TI_flags+7(%r4),_TIF_MCCK_PENDING # machine check pending? 193 llill %r6,_TIF_TRANSFER # transfer TIF bits
194 ng %r6,__TI_flags(%r4) # isolate TIF bits
193 jz 0f 195 jz 0f
194 ni __TI_flags+7(%r4),255-_TIF_MCCK_PENDING # clear flag in prev 196 og %r6,__TI_flags(%r5) # set TIF bits of next
195 oi __TI_flags+7(%r5),_TIF_MCCK_PENDING # set it in next 197 stg %r6,__TI_flags(%r5)
198 ni __TI_flags+7(%r4),255-_TIF_TRANSFER # clear TIF bits of prev
1960: lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task 1990: lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
197 br %r14 200 br %r14
198 201
diff --git a/arch/s390/kernel/head64.S b/arch/s390/kernel/head64.S
index b9e25ae2579c..d7c00507568a 100644
--- a/arch/s390/kernel/head64.S
+++ b/arch/s390/kernel/head64.S
@@ -59,7 +59,7 @@ ENTRY(startup_continue)
59 .quad 0 # cr12: tracing off 59 .quad 0 # cr12: tracing off
60 .quad 0 # cr13: home space segment table 60 .quad 0 # cr13: home space segment table
61 .quad 0xc0000000 # cr14: machine check handling off 61 .quad 0xc0000000 # cr14: machine check handling off
62 .quad 0 # cr15: linkage stack operations 62 .quad .Llinkage_stack # cr15: linkage stack operations
63.Lpcmsk:.quad 0x0000000180000000 63.Lpcmsk:.quad 0x0000000180000000
64.L4malign:.quad 0xffffffffffc00000 64.L4malign:.quad 0xffffffffffc00000
65.Lscan2g:.quad 0x80000000 + 0x20000 - 8 # 2GB + 128K - 8 65.Lscan2g:.quad 0x80000000 + 0x20000 - 8 # 2GB + 128K - 8
@@ -67,12 +67,15 @@ ENTRY(startup_continue)
67.Lparmaddr: 67.Lparmaddr:
68 .quad PARMAREA 68 .quad PARMAREA
69 .align 64 69 .align 64
70.Lduct: .long 0,0,0,0,.Lduald,0,0,0 70.Lduct: .long 0,.Laste,.Laste,0,.Lduald,0,0,0
71 .long 0,0,0,0,0,0,0,0 71 .long 0,0,0,0,0,0,0,0
72.Laste: .quad 0,0xffffffffffffffff,0,0,0,0,0,0
72 .align 128 73 .align 128
73.Lduald:.rept 8 74.Lduald:.rept 8
74 .long 0x80000000,0,0,0 # invalid access-list entries 75 .long 0x80000000,0,0,0 # invalid access-list entries
75 .endr 76 .endr
77.Llinkage_stack:
78 .long 0,0,0x89000000,0,0,0,0x8a000000,0
76 79
77ENTRY(_ehead) 80ENTRY(_ehead)
78 81
diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c
index 5d2dfa31c4ef..61595c1f0a0f 100644
--- a/arch/s390/kernel/perf_event.c
+++ b/arch/s390/kernel/perf_event.c
@@ -121,7 +121,7 @@ unsigned long perf_misc_flags(struct pt_regs *regs)
121 : PERF_RECORD_MISC_KERNEL; 121 : PERF_RECORD_MISC_KERNEL;
122} 122}
123 123
124void print_debug_cf(void) 124static void print_debug_cf(void)
125{ 125{
126 struct cpumf_ctr_info cf_info; 126 struct cpumf_ctr_info cf_info;
127 int cpu = smp_processor_id(); 127 int cpu = smp_processor_id();
diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c
index f6be6087a0e9..4ac8fafec95f 100644
--- a/arch/s390/kernel/ptrace.c
+++ b/arch/s390/kernel/ptrace.c
@@ -85,7 +85,10 @@ void update_cr_regs(struct task_struct *task)
85 85
86 /* merge TIF_SINGLE_STEP into user specified PER registers. */ 86 /* merge TIF_SINGLE_STEP into user specified PER registers. */
87 if (test_tsk_thread_flag(task, TIF_SINGLE_STEP)) { 87 if (test_tsk_thread_flag(task, TIF_SINGLE_STEP)) {
88 new.control |= PER_EVENT_IFETCH; 88 if (test_tsk_thread_flag(task, TIF_BLOCK_STEP))
89 new.control |= PER_EVENT_BRANCH;
90 else
91 new.control |= PER_EVENT_IFETCH;
89#ifdef CONFIG_64BIT 92#ifdef CONFIG_64BIT
90 new.control |= PER_CONTROL_SUSPENSION; 93 new.control |= PER_CONTROL_SUSPENSION;
91 new.control |= PER_EVENT_TRANSACTION_END; 94 new.control |= PER_EVENT_TRANSACTION_END;
@@ -107,14 +110,22 @@ void update_cr_regs(struct task_struct *task)
107 110
108void user_enable_single_step(struct task_struct *task) 111void user_enable_single_step(struct task_struct *task)
109{ 112{
113 clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
110 set_tsk_thread_flag(task, TIF_SINGLE_STEP); 114 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
111} 115}
112 116
113void user_disable_single_step(struct task_struct *task) 117void user_disable_single_step(struct task_struct *task)
114{ 118{
119 clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
115 clear_tsk_thread_flag(task, TIF_SINGLE_STEP); 120 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
116} 121}
117 122
123void user_enable_block_step(struct task_struct *task)
124{
125 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
126 set_tsk_thread_flag(task, TIF_BLOCK_STEP);
127}
128
118/* 129/*
119 * Called by kernel/ptrace.c when detaching.. 130 * Called by kernel/ptrace.c when detaching..
120 * 131 *
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index 09e2f468f48b..f70f2489fa5f 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -47,7 +47,6 @@
47#include <linux/compat.h> 47#include <linux/compat.h>
48 48
49#include <asm/ipl.h> 49#include <asm/ipl.h>
50#include <asm/uaccess.h>
51#include <asm/facility.h> 50#include <asm/facility.h>
52#include <asm/smp.h> 51#include <asm/smp.h>
53#include <asm/mmu_context.h> 52#include <asm/mmu_context.h>
@@ -65,12 +64,6 @@
65#include "entry.h" 64#include "entry.h"
66 65
67/* 66/*
68 * User copy operations.
69 */
70struct uaccess_ops uaccess;
71EXPORT_SYMBOL(uaccess);
72
73/*
74 * Machine setup.. 67 * Machine setup..
75 */ 68 */
76unsigned int console_mode = 0; 69unsigned int console_mode = 0;
@@ -294,14 +287,6 @@ static int __init parse_vmalloc(char *arg)
294} 287}
295early_param("vmalloc", parse_vmalloc); 288early_param("vmalloc", parse_vmalloc);
296 289
297static int __init early_parse_user_mode(char *p)
298{
299 if (!p || strcmp(p, "primary") == 0)
300 return 0;
301 return 1;
302}
303early_param("user_mode", early_parse_user_mode);
304
305void *restart_stack __attribute__((__section__(".data"))); 290void *restart_stack __attribute__((__section__(".data")));
306 291
307static void __init setup_lowcore(void) 292static void __init setup_lowcore(void)
@@ -1009,8 +994,6 @@ void __init setup_arch(char **cmdline_p)
1009 init_mm.end_data = (unsigned long) &_edata; 994 init_mm.end_data = (unsigned long) &_edata;
1010 init_mm.brk = (unsigned long) &_end; 995 init_mm.brk = (unsigned long) &_end;
1011 996
1012 uaccess = MACHINE_HAS_MVCOS ? uaccess_mvcos : uaccess_pt;
1013
1014 parse_early_param(); 997 parse_early_param();
1015 detect_memory_layout(memory_chunk, memory_end); 998 detect_memory_layout(memory_chunk, memory_end);
1016 os_info_init(); 999 os_info_init();
diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
index a7125b62a9a6..8827883310dd 100644
--- a/arch/s390/kernel/smp.c
+++ b/arch/s390/kernel/smp.c
@@ -773,11 +773,11 @@ void __noreturn cpu_die(void)
773 773
774void __init smp_fill_possible_mask(void) 774void __init smp_fill_possible_mask(void)
775{ 775{
776 unsigned int possible, cpu; 776 unsigned int possible, sclp, cpu;
777 777
778 possible = setup_possible_cpus; 778 sclp = sclp_get_max_cpu() ?: nr_cpu_ids;
779 if (!possible) 779 possible = setup_possible_cpus ?: nr_cpu_ids;
780 possible = MACHINE_IS_VM ? 64 : nr_cpu_ids; 780 possible = min(possible, sclp);
781 for (cpu = 0; cpu < possible && cpu < nr_cpu_ids; cpu++) 781 for (cpu = 0; cpu < possible && cpu < nr_cpu_ids; cpu++)
782 set_cpu_possible(cpu, true); 782 set_cpu_possible(cpu, true);
783} 783}
diff --git a/arch/s390/kernel/syscalls.S b/arch/s390/kernel/syscalls.S
index 143992152ec9..542ef488bac1 100644
--- a/arch/s390/kernel/syscalls.S
+++ b/arch/s390/kernel/syscalls.S
@@ -9,349 +9,349 @@
9#define NI_SYSCALL SYSCALL(sys_ni_syscall,sys_ni_syscall,sys_ni_syscall) 9#define NI_SYSCALL SYSCALL(sys_ni_syscall,sys_ni_syscall,sys_ni_syscall)
10 10
11NI_SYSCALL /* 0 */ 11NI_SYSCALL /* 0 */
12SYSCALL(sys_exit,sys_exit,sys32_exit_wrapper) 12SYSCALL(sys_exit,sys_exit,compat_sys_exit)
13SYSCALL(sys_fork,sys_fork,sys_fork) 13SYSCALL(sys_fork,sys_fork,sys_fork)
14SYSCALL(sys_read,sys_read,sys32_read_wrapper) 14SYSCALL(sys_read,sys_read,compat_sys_s390_read)
15SYSCALL(sys_write,sys_write,sys32_write_wrapper) 15SYSCALL(sys_write,sys_write,compat_sys_s390_write)
16SYSCALL(sys_open,sys_open,compat_sys_open) /* 5 */ 16SYSCALL(sys_open,sys_open,compat_sys_open) /* 5 */
17SYSCALL(sys_close,sys_close,sys32_close_wrapper) 17SYSCALL(sys_close,sys_close,compat_sys_close)
18SYSCALL(sys_restart_syscall,sys_restart_syscall,sys_restart_syscall) 18SYSCALL(sys_restart_syscall,sys_restart_syscall,sys_restart_syscall)
19SYSCALL(sys_creat,sys_creat,sys32_creat_wrapper) 19SYSCALL(sys_creat,sys_creat,compat_sys_creat)
20SYSCALL(sys_link,sys_link,sys32_link_wrapper) 20SYSCALL(sys_link,sys_link,compat_sys_link)
21SYSCALL(sys_unlink,sys_unlink,sys32_unlink_wrapper) /* 10 */ 21SYSCALL(sys_unlink,sys_unlink,compat_sys_unlink) /* 10 */
22SYSCALL(sys_execve,sys_execve,sys32_execve_wrapper) 22SYSCALL(sys_execve,sys_execve,compat_sys_execve)
23SYSCALL(sys_chdir,sys_chdir,sys32_chdir_wrapper) 23SYSCALL(sys_chdir,sys_chdir,compat_sys_chdir)
24SYSCALL(sys_time,sys_ni_syscall,sys32_time_wrapper) /* old time syscall */ 24SYSCALL(sys_time,sys_ni_syscall,compat_sys_time) /* old time syscall */
25SYSCALL(sys_mknod,sys_mknod,sys32_mknod_wrapper) 25SYSCALL(sys_mknod,sys_mknod,compat_sys_mknod)
26SYSCALL(sys_chmod,sys_chmod,sys32_chmod_wrapper) /* 15 */ 26SYSCALL(sys_chmod,sys_chmod,compat_sys_chmod) /* 15 */
27SYSCALL(sys_lchown16,sys_ni_syscall,sys32_lchown16_wrapper) /* old lchown16 syscall*/ 27SYSCALL(sys_lchown16,sys_ni_syscall,compat_sys_s390_lchown16) /* old lchown16 syscall*/
28NI_SYSCALL /* old break syscall holder */ 28NI_SYSCALL /* old break syscall holder */
29NI_SYSCALL /* old stat syscall holder */ 29NI_SYSCALL /* old stat syscall holder */
30SYSCALL(sys_lseek,sys_lseek,compat_sys_lseek) 30SYSCALL(sys_lseek,sys_lseek,compat_sys_lseek)
31SYSCALL(sys_getpid,sys_getpid,sys_getpid) /* 20 */ 31SYSCALL(sys_getpid,sys_getpid,sys_getpid) /* 20 */
32SYSCALL(sys_mount,sys_mount,sys32_mount_wrapper) 32SYSCALL(sys_mount,sys_mount,compat_sys_mount)
33SYSCALL(sys_oldumount,sys_oldumount,sys32_oldumount_wrapper) 33SYSCALL(sys_oldumount,sys_oldumount,compat_sys_oldumount)
34SYSCALL(sys_setuid16,sys_ni_syscall,sys32_setuid16_wrapper) /* old setuid16 syscall*/ 34SYSCALL(sys_setuid16,sys_ni_syscall,compat_sys_s390_setuid16) /* old setuid16 syscall*/
35SYSCALL(sys_getuid16,sys_ni_syscall,sys32_getuid16) /* old getuid16 syscall*/ 35SYSCALL(sys_getuid16,sys_ni_syscall,compat_sys_s390_getuid16) /* old getuid16 syscall*/
36SYSCALL(sys_stime,sys_ni_syscall,sys32_stime_wrapper) /* 25 old stime syscall */ 36SYSCALL(sys_stime,sys_ni_syscall,compat_sys_stime) /* 25 old stime syscall */
37SYSCALL(sys_ptrace,sys_ptrace,sys32_ptrace_wrapper) 37SYSCALL(sys_ptrace,sys_ptrace,compat_sys_ptrace)
38SYSCALL(sys_alarm,sys_alarm,sys32_alarm_wrapper) 38SYSCALL(sys_alarm,sys_alarm,compat_sys_alarm)
39NI_SYSCALL /* old fstat syscall */ 39NI_SYSCALL /* old fstat syscall */
40SYSCALL(sys_pause,sys_pause,sys_pause) 40SYSCALL(sys_pause,sys_pause,sys_pause)
41SYSCALL(sys_utime,sys_utime,compat_sys_utime_wrapper) /* 30 */ 41SYSCALL(sys_utime,sys_utime,compat_sys_utime) /* 30 */
42NI_SYSCALL /* old stty syscall */ 42NI_SYSCALL /* old stty syscall */
43NI_SYSCALL /* old gtty syscall */ 43NI_SYSCALL /* old gtty syscall */
44SYSCALL(sys_access,sys_access,sys32_access_wrapper) 44SYSCALL(sys_access,sys_access,compat_sys_access)
45SYSCALL(sys_nice,sys_nice,sys32_nice_wrapper) 45SYSCALL(sys_nice,sys_nice,compat_sys_nice)
46NI_SYSCALL /* 35 old ftime syscall */ 46NI_SYSCALL /* 35 old ftime syscall */
47SYSCALL(sys_sync,sys_sync,sys_sync) 47SYSCALL(sys_sync,sys_sync,sys_sync)
48SYSCALL(sys_kill,sys_kill,sys32_kill_wrapper) 48SYSCALL(sys_kill,sys_kill,compat_sys_kill)
49SYSCALL(sys_rename,sys_rename,sys32_rename_wrapper) 49SYSCALL(sys_rename,sys_rename,compat_sys_rename)
50SYSCALL(sys_mkdir,sys_mkdir,sys32_mkdir_wrapper) 50SYSCALL(sys_mkdir,sys_mkdir,compat_sys_mkdir)
51SYSCALL(sys_rmdir,sys_rmdir,sys32_rmdir_wrapper) /* 40 */ 51SYSCALL(sys_rmdir,sys_rmdir,compat_sys_rmdir) /* 40 */
52SYSCALL(sys_dup,sys_dup,sys32_dup_wrapper) 52SYSCALL(sys_dup,sys_dup,compat_sys_dup)
53SYSCALL(sys_pipe,sys_pipe,sys32_pipe_wrapper) 53SYSCALL(sys_pipe,sys_pipe,compat_sys_pipe)
54SYSCALL(sys_times,sys_times,compat_sys_times_wrapper) 54SYSCALL(sys_times,sys_times,compat_sys_times)
55NI_SYSCALL /* old prof syscall */ 55NI_SYSCALL /* old prof syscall */
56SYSCALL(sys_brk,sys_brk,sys32_brk_wrapper) /* 45 */ 56SYSCALL(sys_brk,sys_brk,compat_sys_brk) /* 45 */
57SYSCALL(sys_setgid16,sys_ni_syscall,sys32_setgid16_wrapper) /* old setgid16 syscall*/ 57SYSCALL(sys_setgid16,sys_ni_syscall,compat_sys_s390_setgid16) /* old setgid16 syscall*/
58SYSCALL(sys_getgid16,sys_ni_syscall,sys32_getgid16) /* old getgid16 syscall*/ 58SYSCALL(sys_getgid16,sys_ni_syscall,compat_sys_s390_getgid16) /* old getgid16 syscall*/
59SYSCALL(sys_signal,sys_signal,sys32_signal_wrapper) 59SYSCALL(sys_signal,sys_signal,compat_sys_signal)
60SYSCALL(sys_geteuid16,sys_ni_syscall,sys32_geteuid16) /* old geteuid16 syscall */ 60SYSCALL(sys_geteuid16,sys_ni_syscall,compat_sys_s390_geteuid16) /* old geteuid16 syscall */
61SYSCALL(sys_getegid16,sys_ni_syscall,sys32_getegid16) /* 50 old getegid16 syscall */ 61SYSCALL(sys_getegid16,sys_ni_syscall,compat_sys_s390_getegid16) /* 50 old getegid16 syscall */
62SYSCALL(sys_acct,sys_acct,sys32_acct_wrapper) 62SYSCALL(sys_acct,sys_acct,compat_sys_acct)
63SYSCALL(sys_umount,sys_umount,sys32_umount_wrapper) 63SYSCALL(sys_umount,sys_umount,compat_sys_umount)
64NI_SYSCALL /* old lock syscall */ 64NI_SYSCALL /* old lock syscall */
65SYSCALL(sys_ioctl,sys_ioctl,compat_sys_ioctl_wrapper) 65SYSCALL(sys_ioctl,sys_ioctl,compat_sys_ioctl)
66SYSCALL(sys_fcntl,sys_fcntl,compat_sys_fcntl_wrapper) /* 55 */ 66SYSCALL(sys_fcntl,sys_fcntl,compat_sys_fcntl) /* 55 */
67NI_SYSCALL /* intel mpx syscall */ 67NI_SYSCALL /* intel mpx syscall */
68SYSCALL(sys_setpgid,sys_setpgid,sys32_setpgid_wrapper) 68SYSCALL(sys_setpgid,sys_setpgid,compat_sys_setpgid)
69NI_SYSCALL /* old ulimit syscall */ 69NI_SYSCALL /* old ulimit syscall */
70NI_SYSCALL /* old uname syscall */ 70NI_SYSCALL /* old uname syscall */
71SYSCALL(sys_umask,sys_umask,sys32_umask_wrapper) /* 60 */ 71SYSCALL(sys_umask,sys_umask,compat_sys_umask) /* 60 */
72SYSCALL(sys_chroot,sys_chroot,sys32_chroot_wrapper) 72SYSCALL(sys_chroot,sys_chroot,compat_sys_chroot)
73SYSCALL(sys_ustat,sys_ustat,sys32_ustat_wrapper) 73SYSCALL(sys_ustat,sys_ustat,compat_sys_ustat)
74SYSCALL(sys_dup2,sys_dup2,sys32_dup2_wrapper) 74SYSCALL(sys_dup2,sys_dup2,compat_sys_dup2)
75SYSCALL(sys_getppid,sys_getppid,sys_getppid) 75SYSCALL(sys_getppid,sys_getppid,sys_getppid)
76SYSCALL(sys_getpgrp,sys_getpgrp,sys_getpgrp) /* 65 */ 76SYSCALL(sys_getpgrp,sys_getpgrp,sys_getpgrp) /* 65 */
77SYSCALL(sys_setsid,sys_setsid,sys_setsid) 77SYSCALL(sys_setsid,sys_setsid,sys_setsid)
78SYSCALL(sys_sigaction,sys_sigaction,compat_sys_sigaction) 78SYSCALL(sys_sigaction,sys_sigaction,compat_sys_sigaction)
79NI_SYSCALL /* old sgetmask syscall*/ 79NI_SYSCALL /* old sgetmask syscall*/
80NI_SYSCALL /* old ssetmask syscall*/ 80NI_SYSCALL /* old ssetmask syscall*/
81SYSCALL(sys_setreuid16,sys_ni_syscall,sys32_setreuid16_wrapper) /* old setreuid16 syscall */ 81SYSCALL(sys_setreuid16,sys_ni_syscall,compat_sys_s390_setreuid16) /* old setreuid16 syscall */
82SYSCALL(sys_setregid16,sys_ni_syscall,sys32_setregid16_wrapper) /* old setregid16 syscall */ 82SYSCALL(sys_setregid16,sys_ni_syscall,compat_sys_s390_setregid16) /* old setregid16 syscall */
83SYSCALL(sys_sigsuspend,sys_sigsuspend,sys_sigsuspend_wrapper) 83SYSCALL(sys_sigsuspend,sys_sigsuspend,compat_sys_sigsuspend)
84SYSCALL(sys_sigpending,sys_sigpending,compat_sys_sigpending_wrapper) 84SYSCALL(sys_sigpending,sys_sigpending,compat_sys_sigpending)
85SYSCALL(sys_sethostname,sys_sethostname,sys32_sethostname_wrapper) 85SYSCALL(sys_sethostname,sys_sethostname,compat_sys_sethostname)
86SYSCALL(sys_setrlimit,sys_setrlimit,compat_sys_setrlimit_wrapper) /* 75 */ 86SYSCALL(sys_setrlimit,sys_setrlimit,compat_sys_setrlimit) /* 75 */
87SYSCALL(sys_old_getrlimit,sys_getrlimit,compat_sys_old_getrlimit_wrapper) 87SYSCALL(sys_old_getrlimit,sys_getrlimit,compat_sys_old_getrlimit)
88SYSCALL(sys_getrusage,sys_getrusage,compat_sys_getrusage) 88SYSCALL(sys_getrusage,sys_getrusage,compat_sys_getrusage)
89SYSCALL(sys_gettimeofday,sys_gettimeofday,compat_sys_gettimeofday_wrapper) 89SYSCALL(sys_gettimeofday,sys_gettimeofday,compat_sys_gettimeofday)
90SYSCALL(sys_settimeofday,sys_settimeofday,compat_sys_settimeofday_wrapper) 90SYSCALL(sys_settimeofday,sys_settimeofday,compat_sys_settimeofday)
91SYSCALL(sys_getgroups16,sys_ni_syscall,sys32_getgroups16_wrapper) /* 80 old getgroups16 syscall */ 91SYSCALL(sys_getgroups16,sys_ni_syscall,compat_sys_s390_getgroups16) /* 80 old getgroups16 syscall */
92SYSCALL(sys_setgroups16,sys_ni_syscall,sys32_setgroups16_wrapper) /* old setgroups16 syscall */ 92SYSCALL(sys_setgroups16,sys_ni_syscall,compat_sys_s390_setgroups16) /* old setgroups16 syscall */
93NI_SYSCALL /* old select syscall */ 93NI_SYSCALL /* old select syscall */
94SYSCALL(sys_symlink,sys_symlink,sys32_symlink_wrapper) 94SYSCALL(sys_symlink,sys_symlink,compat_sys_symlink)
95NI_SYSCALL /* old lstat syscall */ 95NI_SYSCALL /* old lstat syscall */
96SYSCALL(sys_readlink,sys_readlink,sys32_readlink_wrapper) /* 85 */ 96SYSCALL(sys_readlink,sys_readlink,compat_sys_readlink) /* 85 */
97SYSCALL(sys_uselib,sys_uselib,sys32_uselib_wrapper) 97SYSCALL(sys_uselib,sys_uselib,compat_sys_uselib)
98SYSCALL(sys_swapon,sys_swapon,sys32_swapon_wrapper) 98SYSCALL(sys_swapon,sys_swapon,compat_sys_swapon)
99SYSCALL(sys_reboot,sys_reboot,sys32_reboot_wrapper) 99SYSCALL(sys_reboot,sys_reboot,compat_sys_reboot)
100SYSCALL(sys_ni_syscall,sys_ni_syscall,old32_readdir_wrapper) /* old readdir syscall */ 100SYSCALL(sys_ni_syscall,sys_ni_syscall,compat_sys_old_readdir) /* old readdir syscall */
101SYSCALL(sys_old_mmap,sys_old_mmap,old32_mmap_wrapper) /* 90 */ 101SYSCALL(sys_old_mmap,sys_old_mmap,compat_sys_s390_old_mmap) /* 90 */
102SYSCALL(sys_munmap,sys_munmap,sys32_munmap_wrapper) 102SYSCALL(sys_munmap,sys_munmap,compat_sys_munmap)
103SYSCALL(sys_truncate,sys_truncate,compat_sys_truncate) 103SYSCALL(sys_truncate,sys_truncate,compat_sys_truncate)
104SYSCALL(sys_ftruncate,sys_ftruncate,compat_sys_ftruncate) 104SYSCALL(sys_ftruncate,sys_ftruncate,compat_sys_ftruncate)
105SYSCALL(sys_fchmod,sys_fchmod,sys32_fchmod_wrapper) 105SYSCALL(sys_fchmod,sys_fchmod,compat_sys_fchmod)
106SYSCALL(sys_fchown16,sys_ni_syscall,sys32_fchown16_wrapper) /* 95 old fchown16 syscall*/ 106SYSCALL(sys_fchown16,sys_ni_syscall,compat_sys_s390_fchown16) /* 95 old fchown16 syscall*/
107SYSCALL(sys_getpriority,sys_getpriority,sys32_getpriority_wrapper) 107SYSCALL(sys_getpriority,sys_getpriority,compat_sys_getpriority)
108SYSCALL(sys_setpriority,sys_setpriority,sys32_setpriority_wrapper) 108SYSCALL(sys_setpriority,sys_setpriority,compat_sys_setpriority)
109NI_SYSCALL /* old profil syscall */ 109NI_SYSCALL /* old profil syscall */
110SYSCALL(sys_statfs,sys_statfs,compat_sys_statfs_wrapper) 110SYSCALL(sys_statfs,sys_statfs,compat_sys_statfs)
111SYSCALL(sys_fstatfs,sys_fstatfs,compat_sys_fstatfs_wrapper) /* 100 */ 111SYSCALL(sys_fstatfs,sys_fstatfs,compat_sys_fstatfs) /* 100 */
112NI_SYSCALL /* ioperm for i386 */ 112NI_SYSCALL /* ioperm for i386 */
113SYSCALL(sys_socketcall,sys_socketcall,compat_sys_socketcall_wrapper) 113SYSCALL(sys_socketcall,sys_socketcall,compat_sys_socketcall)
114SYSCALL(sys_syslog,sys_syslog,sys32_syslog_wrapper) 114SYSCALL(sys_syslog,sys_syslog,compat_sys_syslog)
115SYSCALL(sys_setitimer,sys_setitimer,compat_sys_setitimer) 115SYSCALL(sys_setitimer,sys_setitimer,compat_sys_setitimer)
116SYSCALL(sys_getitimer,sys_getitimer,compat_sys_getitimer) /* 105 */ 116SYSCALL(sys_getitimer,sys_getitimer,compat_sys_getitimer) /* 105 */
117SYSCALL(sys_newstat,sys_newstat,compat_sys_newstat_wrapper) 117SYSCALL(sys_newstat,sys_newstat,compat_sys_newstat)
118SYSCALL(sys_newlstat,sys_newlstat,compat_sys_newlstat_wrapper) 118SYSCALL(sys_newlstat,sys_newlstat,compat_sys_newlstat)
119SYSCALL(sys_newfstat,sys_newfstat,compat_sys_newfstat_wrapper) 119SYSCALL(sys_newfstat,sys_newfstat,compat_sys_newfstat)
120NI_SYSCALL /* old uname syscall */ 120NI_SYSCALL /* old uname syscall */
121SYSCALL(sys_lookup_dcookie,sys_lookup_dcookie,compat_sys_lookup_dcookie) /* 110 */ 121SYSCALL(sys_lookup_dcookie,sys_lookup_dcookie,compat_sys_lookup_dcookie) /* 110 */
122SYSCALL(sys_vhangup,sys_vhangup,sys_vhangup) 122SYSCALL(sys_vhangup,sys_vhangup,sys_vhangup)
123NI_SYSCALL /* old "idle" system call */ 123NI_SYSCALL /* old "idle" system call */
124NI_SYSCALL /* vm86old for i386 */ 124NI_SYSCALL /* vm86old for i386 */
125SYSCALL(sys_wait4,sys_wait4,compat_sys_wait4) 125SYSCALL(sys_wait4,sys_wait4,compat_sys_wait4)
126SYSCALL(sys_swapoff,sys_swapoff,sys32_swapoff_wrapper) /* 115 */ 126SYSCALL(sys_swapoff,sys_swapoff,compat_sys_swapoff) /* 115 */
127SYSCALL(sys_sysinfo,sys_sysinfo,compat_sys_sysinfo_wrapper) 127SYSCALL(sys_sysinfo,sys_sysinfo,compat_sys_sysinfo)
128SYSCALL(sys_s390_ipc,sys_s390_ipc,compat_sys_s390_ipc) 128SYSCALL(sys_s390_ipc,sys_s390_ipc,compat_sys_s390_ipc)
129SYSCALL(sys_fsync,sys_fsync,sys32_fsync_wrapper) 129SYSCALL(sys_fsync,sys_fsync,compat_sys_fsync)
130SYSCALL(sys_sigreturn,sys_sigreturn,sys32_sigreturn) 130SYSCALL(sys_sigreturn,sys_sigreturn,compat_sys_sigreturn)
131SYSCALL(sys_clone,sys_clone,sys_clone_wrapper) /* 120 */ 131SYSCALL(sys_clone,sys_clone,compat_sys_clone) /* 120 */
132SYSCALL(sys_setdomainname,sys_setdomainname,sys32_setdomainname_wrapper) 132SYSCALL(sys_setdomainname,sys_setdomainname,compat_sys_setdomainname)
133SYSCALL(sys_newuname,sys_newuname,sys32_newuname_wrapper) 133SYSCALL(sys_newuname,sys_newuname,compat_sys_newuname)
134NI_SYSCALL /* modify_ldt for i386 */ 134NI_SYSCALL /* modify_ldt for i386 */
135SYSCALL(sys_adjtimex,sys_adjtimex,compat_sys_adjtimex_wrapper) 135SYSCALL(sys_adjtimex,sys_adjtimex,compat_sys_adjtimex)
136SYSCALL(sys_mprotect,sys_mprotect,sys32_mprotect_wrapper) /* 125 */ 136SYSCALL(sys_mprotect,sys_mprotect,compat_sys_mprotect) /* 125 */
137SYSCALL(sys_sigprocmask,sys_sigprocmask,compat_sys_sigprocmask) 137SYSCALL(sys_sigprocmask,sys_sigprocmask,compat_sys_sigprocmask)
138NI_SYSCALL /* old "create module" */ 138NI_SYSCALL /* old "create module" */
139SYSCALL(sys_init_module,sys_init_module,sys_init_module_wrapper) 139SYSCALL(sys_init_module,sys_init_module,compat_sys_init_module)
140SYSCALL(sys_delete_module,sys_delete_module,sys_delete_module_wrapper) 140SYSCALL(sys_delete_module,sys_delete_module,compat_sys_delete_module)
141NI_SYSCALL /* 130: old get_kernel_syms */ 141NI_SYSCALL /* 130: old get_kernel_syms */
142SYSCALL(sys_quotactl,sys_quotactl,sys32_quotactl_wrapper) 142SYSCALL(sys_quotactl,sys_quotactl,compat_sys_quotactl)
143SYSCALL(sys_getpgid,sys_getpgid,sys32_getpgid_wrapper) 143SYSCALL(sys_getpgid,sys_getpgid,compat_sys_getpgid)
144SYSCALL(sys_fchdir,sys_fchdir,sys32_fchdir_wrapper) 144SYSCALL(sys_fchdir,sys_fchdir,compat_sys_fchdir)
145SYSCALL(sys_bdflush,sys_bdflush,sys32_bdflush_wrapper) 145SYSCALL(sys_bdflush,sys_bdflush,compat_sys_bdflush)
146SYSCALL(sys_sysfs,sys_sysfs,sys32_sysfs_wrapper) /* 135 */ 146SYSCALL(sys_sysfs,sys_sysfs,compat_sys_sysfs) /* 135 */
147SYSCALL(sys_personality,sys_s390_personality,sys32_personality_wrapper) 147SYSCALL(sys_personality,sys_s390_personality,compat_sys_s390_personality)
148NI_SYSCALL /* for afs_syscall */ 148NI_SYSCALL /* for afs_syscall */
149SYSCALL(sys_setfsuid16,sys_ni_syscall,sys32_setfsuid16_wrapper) /* old setfsuid16 syscall */ 149SYSCALL(sys_setfsuid16,sys_ni_syscall,compat_sys_s390_setfsuid16) /* old setfsuid16 syscall */
150SYSCALL(sys_setfsgid16,sys_ni_syscall,sys32_setfsgid16_wrapper) /* old setfsgid16 syscall */ 150SYSCALL(sys_setfsgid16,sys_ni_syscall,compat_sys_s390_setfsgid16) /* old setfsgid16 syscall */
151SYSCALL(sys_llseek,sys_llseek,sys32_llseek_wrapper) /* 140 */ 151SYSCALL(sys_llseek,sys_llseek,compat_sys_llseek) /* 140 */
152SYSCALL(sys_getdents,sys_getdents,sys32_getdents_wrapper) 152SYSCALL(sys_getdents,sys_getdents,compat_sys_getdents)
153SYSCALL(sys_select,sys_select,compat_sys_select_wrapper) 153SYSCALL(sys_select,sys_select,compat_sys_select)
154SYSCALL(sys_flock,sys_flock,sys32_flock_wrapper) 154SYSCALL(sys_flock,sys_flock,compat_sys_flock)
155SYSCALL(sys_msync,sys_msync,sys32_msync_wrapper) 155SYSCALL(sys_msync,sys_msync,compat_sys_msync)
156SYSCALL(sys_readv,sys_readv,compat_sys_readv_wrapper) /* 145 */ 156SYSCALL(sys_readv,sys_readv,compat_sys_readv) /* 145 */
157SYSCALL(sys_writev,sys_writev,compat_sys_writev_wrapper) 157SYSCALL(sys_writev,sys_writev,compat_sys_writev)
158SYSCALL(sys_getsid,sys_getsid,sys32_getsid_wrapper) 158SYSCALL(sys_getsid,sys_getsid,compat_sys_getsid)
159SYSCALL(sys_fdatasync,sys_fdatasync,sys32_fdatasync_wrapper) 159SYSCALL(sys_fdatasync,sys_fdatasync,compat_sys_fdatasync)
160SYSCALL(sys_sysctl,sys_sysctl,compat_sys_sysctl) 160SYSCALL(sys_sysctl,sys_sysctl,compat_sys_sysctl)
161SYSCALL(sys_mlock,sys_mlock,sys32_mlock_wrapper) /* 150 */ 161SYSCALL(sys_mlock,sys_mlock,compat_sys_mlock) /* 150 */
162SYSCALL(sys_munlock,sys_munlock,sys32_munlock_wrapper) 162SYSCALL(sys_munlock,sys_munlock,compat_sys_munlock)
163SYSCALL(sys_mlockall,sys_mlockall,sys32_mlockall_wrapper) 163SYSCALL(sys_mlockall,sys_mlockall,compat_sys_mlockall)
164SYSCALL(sys_munlockall,sys_munlockall,sys_munlockall) 164SYSCALL(sys_munlockall,sys_munlockall,sys_munlockall)
165SYSCALL(sys_sched_setparam,sys_sched_setparam,sys32_sched_setparam_wrapper) 165SYSCALL(sys_sched_setparam,sys_sched_setparam,compat_sys_sched_setparam)
166SYSCALL(sys_sched_getparam,sys_sched_getparam,sys32_sched_getparam_wrapper) /* 155 */ 166SYSCALL(sys_sched_getparam,sys_sched_getparam,compat_sys_sched_getparam) /* 155 */
167SYSCALL(sys_sched_setscheduler,sys_sched_setscheduler,sys32_sched_setscheduler_wrapper) 167SYSCALL(sys_sched_setscheduler,sys_sched_setscheduler,compat_sys_sched_setscheduler)
168SYSCALL(sys_sched_getscheduler,sys_sched_getscheduler,sys32_sched_getscheduler_wrapper) 168SYSCALL(sys_sched_getscheduler,sys_sched_getscheduler,compat_sys_sched_getscheduler)
169SYSCALL(sys_sched_yield,sys_sched_yield,sys_sched_yield) 169SYSCALL(sys_sched_yield,sys_sched_yield,sys_sched_yield)
170SYSCALL(sys_sched_get_priority_max,sys_sched_get_priority_max,sys32_sched_get_priority_max_wrapper) 170SYSCALL(sys_sched_get_priority_max,sys_sched_get_priority_max,compat_sys_sched_get_priority_max)
171SYSCALL(sys_sched_get_priority_min,sys_sched_get_priority_min,sys32_sched_get_priority_min_wrapper) /* 160 */ 171SYSCALL(sys_sched_get_priority_min,sys_sched_get_priority_min,compat_sys_sched_get_priority_min) /* 160 */
172SYSCALL(sys_sched_rr_get_interval,sys_sched_rr_get_interval,compat_sys_sched_rr_get_interval) 172SYSCALL(sys_sched_rr_get_interval,sys_sched_rr_get_interval,compat_sys_sched_rr_get_interval)
173SYSCALL(sys_nanosleep,sys_nanosleep,compat_sys_nanosleep_wrapper) 173SYSCALL(sys_nanosleep,sys_nanosleep,compat_sys_nanosleep)
174SYSCALL(sys_mremap,sys_mremap,sys32_mremap_wrapper) 174SYSCALL(sys_mremap,sys_mremap,compat_sys_mremap)
175SYSCALL(sys_setresuid16,sys_ni_syscall,sys32_setresuid16_wrapper) /* old setresuid16 syscall */ 175SYSCALL(sys_setresuid16,sys_ni_syscall,compat_sys_s390_setresuid16) /* old setresuid16 syscall */
176SYSCALL(sys_getresuid16,sys_ni_syscall,sys32_getresuid16_wrapper) /* 165 old getresuid16 syscall */ 176SYSCALL(sys_getresuid16,sys_ni_syscall,compat_sys_s390_getresuid16) /* 165 old getresuid16 syscall */
177NI_SYSCALL /* for vm86 */ 177NI_SYSCALL /* for vm86 */
178NI_SYSCALL /* old sys_query_module */ 178NI_SYSCALL /* old sys_query_module */
179SYSCALL(sys_poll,sys_poll,sys32_poll_wrapper) 179SYSCALL(sys_poll,sys_poll,compat_sys_poll)
180NI_SYSCALL /* old nfsservctl */ 180NI_SYSCALL /* old nfsservctl */
181SYSCALL(sys_setresgid16,sys_ni_syscall,sys32_setresgid16_wrapper) /* 170 old setresgid16 syscall */ 181SYSCALL(sys_setresgid16,sys_ni_syscall,compat_sys_s390_setresgid16) /* 170 old setresgid16 syscall */
182SYSCALL(sys_getresgid16,sys_ni_syscall,sys32_getresgid16_wrapper) /* old getresgid16 syscall */ 182SYSCALL(sys_getresgid16,sys_ni_syscall,compat_sys_s390_getresgid16) /* old getresgid16 syscall */
183SYSCALL(sys_prctl,sys_prctl,sys32_prctl_wrapper) 183SYSCALL(sys_prctl,sys_prctl,compat_sys_prctl)
184SYSCALL(sys_rt_sigreturn,sys_rt_sigreturn,sys32_rt_sigreturn) 184SYSCALL(sys_rt_sigreturn,sys_rt_sigreturn,compat_sys_rt_sigreturn)
185SYSCALL(sys_rt_sigaction,sys_rt_sigaction,compat_sys_rt_sigaction) 185SYSCALL(sys_rt_sigaction,sys_rt_sigaction,compat_sys_rt_sigaction)
186SYSCALL(sys_rt_sigprocmask,sys_rt_sigprocmask,compat_sys_rt_sigprocmask) /* 175 */ 186SYSCALL(sys_rt_sigprocmask,sys_rt_sigprocmask,compat_sys_rt_sigprocmask) /* 175 */
187SYSCALL(sys_rt_sigpending,sys_rt_sigpending,compat_sys_rt_sigpending) 187SYSCALL(sys_rt_sigpending,sys_rt_sigpending,compat_sys_rt_sigpending)
188SYSCALL(sys_rt_sigtimedwait,sys_rt_sigtimedwait,compat_sys_rt_sigtimedwait) 188SYSCALL(sys_rt_sigtimedwait,sys_rt_sigtimedwait,compat_sys_rt_sigtimedwait)
189SYSCALL(sys_rt_sigqueueinfo,sys_rt_sigqueueinfo,compat_sys_rt_sigqueueinfo) 189SYSCALL(sys_rt_sigqueueinfo,sys_rt_sigqueueinfo,compat_sys_rt_sigqueueinfo)
190SYSCALL(sys_rt_sigsuspend,sys_rt_sigsuspend,compat_sys_rt_sigsuspend) 190SYSCALL(sys_rt_sigsuspend,sys_rt_sigsuspend,compat_sys_rt_sigsuspend)
191SYSCALL(sys_pread64,sys_pread64,sys32_pread64_wrapper) /* 180 */ 191SYSCALL(sys_pread64,sys_pread64,compat_sys_s390_pread64) /* 180 */
192SYSCALL(sys_pwrite64,sys_pwrite64,sys32_pwrite64_wrapper) 192SYSCALL(sys_pwrite64,sys_pwrite64,compat_sys_s390_pwrite64)
193SYSCALL(sys_chown16,sys_ni_syscall,sys32_chown16_wrapper) /* old chown16 syscall */ 193SYSCALL(sys_chown16,sys_ni_syscall,compat_sys_s390_chown16) /* old chown16 syscall */
194SYSCALL(sys_getcwd,sys_getcwd,sys32_getcwd_wrapper) 194SYSCALL(sys_getcwd,sys_getcwd,compat_sys_getcwd)
195SYSCALL(sys_capget,sys_capget,sys32_capget_wrapper) 195SYSCALL(sys_capget,sys_capget,compat_sys_capget)
196SYSCALL(sys_capset,sys_capset,sys32_capset_wrapper) /* 185 */ 196SYSCALL(sys_capset,sys_capset,compat_sys_capset) /* 185 */
197SYSCALL(sys_sigaltstack,sys_sigaltstack,compat_sys_sigaltstack) 197SYSCALL(sys_sigaltstack,sys_sigaltstack,compat_sys_sigaltstack)
198SYSCALL(sys_sendfile,sys_sendfile64,compat_sys_sendfile) 198SYSCALL(sys_sendfile,sys_sendfile64,compat_sys_sendfile)
199NI_SYSCALL /* streams1 */ 199NI_SYSCALL /* streams1 */
200NI_SYSCALL /* streams2 */ 200NI_SYSCALL /* streams2 */
201SYSCALL(sys_vfork,sys_vfork,sys_vfork) /* 190 */ 201SYSCALL(sys_vfork,sys_vfork,sys_vfork) /* 190 */
202SYSCALL(sys_getrlimit,sys_getrlimit,compat_sys_getrlimit_wrapper) 202SYSCALL(sys_getrlimit,sys_getrlimit,compat_sys_getrlimit)
203SYSCALL(sys_mmap2,sys_mmap2,sys32_mmap2_wrapper) 203SYSCALL(sys_mmap2,sys_mmap2,compat_sys_s390_mmap2)
204SYSCALL(sys_truncate64,sys_ni_syscall,sys32_truncate64_wrapper) 204SYSCALL(sys_truncate64,sys_ni_syscall,compat_sys_s390_truncate64)
205SYSCALL(sys_ftruncate64,sys_ni_syscall,sys32_ftruncate64_wrapper) 205SYSCALL(sys_ftruncate64,sys_ni_syscall,compat_sys_s390_ftruncate64)
206SYSCALL(sys_stat64,sys_ni_syscall,sys32_stat64_wrapper) /* 195 */ 206SYSCALL(sys_stat64,sys_ni_syscall,compat_sys_s390_stat64) /* 195 */
207SYSCALL(sys_lstat64,sys_ni_syscall,sys32_lstat64_wrapper) 207SYSCALL(sys_lstat64,sys_ni_syscall,compat_sys_s390_lstat64)
208SYSCALL(sys_fstat64,sys_ni_syscall,sys32_fstat64_wrapper) 208SYSCALL(sys_fstat64,sys_ni_syscall,compat_sys_s390_fstat64)
209SYSCALL(sys_lchown,sys_lchown,sys32_lchown_wrapper) 209SYSCALL(sys_lchown,sys_lchown,compat_sys_lchown)
210SYSCALL(sys_getuid,sys_getuid,sys_getuid) 210SYSCALL(sys_getuid,sys_getuid,sys_getuid)
211SYSCALL(sys_getgid,sys_getgid,sys_getgid) /* 200 */ 211SYSCALL(sys_getgid,sys_getgid,sys_getgid) /* 200 */
212SYSCALL(sys_geteuid,sys_geteuid,sys_geteuid) 212SYSCALL(sys_geteuid,sys_geteuid,sys_geteuid)
213SYSCALL(sys_getegid,sys_getegid,sys_getegid) 213SYSCALL(sys_getegid,sys_getegid,sys_getegid)
214SYSCALL(sys_setreuid,sys_setreuid,sys32_setreuid_wrapper) 214SYSCALL(sys_setreuid,sys_setreuid,compat_sys_setreuid)
215SYSCALL(sys_setregid,sys_setregid,sys32_setregid_wrapper) 215SYSCALL(sys_setregid,sys_setregid,compat_sys_setregid)
216SYSCALL(sys_getgroups,sys_getgroups,sys32_getgroups_wrapper) /* 205 */ 216SYSCALL(sys_getgroups,sys_getgroups,compat_sys_getgroups) /* 205 */
217SYSCALL(sys_setgroups,sys_setgroups,sys32_setgroups_wrapper) 217SYSCALL(sys_setgroups,sys_setgroups,compat_sys_setgroups)
218SYSCALL(sys_fchown,sys_fchown,sys32_fchown_wrapper) 218SYSCALL(sys_fchown,sys_fchown,compat_sys_fchown)
219SYSCALL(sys_setresuid,sys_setresuid,sys32_setresuid_wrapper) 219SYSCALL(sys_setresuid,sys_setresuid,compat_sys_setresuid)
220SYSCALL(sys_getresuid,sys_getresuid,sys32_getresuid_wrapper) 220SYSCALL(sys_getresuid,sys_getresuid,compat_sys_getresuid)
221SYSCALL(sys_setresgid,sys_setresgid,sys32_setresgid_wrapper) /* 210 */ 221SYSCALL(sys_setresgid,sys_setresgid,compat_sys_setresgid) /* 210 */
222SYSCALL(sys_getresgid,sys_getresgid,sys32_getresgid_wrapper) 222SYSCALL(sys_getresgid,sys_getresgid,compat_sys_getresgid)
223SYSCALL(sys_chown,sys_chown,sys32_chown_wrapper) 223SYSCALL(sys_chown,sys_chown,compat_sys_chown)
224SYSCALL(sys_setuid,sys_setuid,sys32_setuid_wrapper) 224SYSCALL(sys_setuid,sys_setuid,compat_sys_setuid)
225SYSCALL(sys_setgid,sys_setgid,sys32_setgid_wrapper) 225SYSCALL(sys_setgid,sys_setgid,compat_sys_setgid)
226SYSCALL(sys_setfsuid,sys_setfsuid,sys32_setfsuid_wrapper) /* 215 */ 226SYSCALL(sys_setfsuid,sys_setfsuid,compat_sys_setfsuid) /* 215 */
227SYSCALL(sys_setfsgid,sys_setfsgid,sys32_setfsgid_wrapper) 227SYSCALL(sys_setfsgid,sys_setfsgid,compat_sys_setfsgid)
228SYSCALL(sys_pivot_root,sys_pivot_root,sys32_pivot_root_wrapper) 228SYSCALL(sys_pivot_root,sys_pivot_root,compat_sys_pivot_root)
229SYSCALL(sys_mincore,sys_mincore,sys32_mincore_wrapper) 229SYSCALL(sys_mincore,sys_mincore,compat_sys_mincore)
230SYSCALL(sys_madvise,sys_madvise,sys32_madvise_wrapper) 230SYSCALL(sys_madvise,sys_madvise,compat_sys_madvise)
231SYSCALL(sys_getdents64,sys_getdents64,sys32_getdents64_wrapper) /* 220 */ 231SYSCALL(sys_getdents64,sys_getdents64,compat_sys_getdents64) /* 220 */
232SYSCALL(sys_fcntl64,sys_ni_syscall,compat_sys_fcntl64_wrapper) 232SYSCALL(sys_fcntl64,sys_ni_syscall,compat_sys_fcntl64)
233SYSCALL(sys_readahead,sys_readahead,sys32_readahead_wrapper) 233SYSCALL(sys_readahead,sys_readahead,compat_sys_s390_readahead)
234SYSCALL(sys_sendfile64,sys_ni_syscall,compat_sys_sendfile64) 234SYSCALL(sys_sendfile64,sys_ni_syscall,compat_sys_sendfile64)
235SYSCALL(sys_setxattr,sys_setxattr,sys32_setxattr_wrapper) 235SYSCALL(sys_setxattr,sys_setxattr,compat_sys_setxattr)
236SYSCALL(sys_lsetxattr,sys_lsetxattr,sys32_lsetxattr_wrapper) /* 225 */ 236SYSCALL(sys_lsetxattr,sys_lsetxattr,compat_sys_lsetxattr) /* 225 */
237SYSCALL(sys_fsetxattr,sys_fsetxattr,sys32_fsetxattr_wrapper) 237SYSCALL(sys_fsetxattr,sys_fsetxattr,compat_sys_fsetxattr)
238SYSCALL(sys_getxattr,sys_getxattr,sys32_getxattr_wrapper) 238SYSCALL(sys_getxattr,sys_getxattr,compat_sys_getxattr)
239SYSCALL(sys_lgetxattr,sys_lgetxattr,sys32_lgetxattr_wrapper) 239SYSCALL(sys_lgetxattr,sys_lgetxattr,compat_sys_lgetxattr)
240SYSCALL(sys_fgetxattr,sys_fgetxattr,sys32_fgetxattr_wrapper) 240SYSCALL(sys_fgetxattr,sys_fgetxattr,compat_sys_fgetxattr)
241SYSCALL(sys_listxattr,sys_listxattr,sys32_listxattr_wrapper) /* 230 */ 241SYSCALL(sys_listxattr,sys_listxattr,compat_sys_listxattr) /* 230 */
242SYSCALL(sys_llistxattr,sys_llistxattr,sys32_llistxattr_wrapper) 242SYSCALL(sys_llistxattr,sys_llistxattr,compat_sys_llistxattr)
243SYSCALL(sys_flistxattr,sys_flistxattr,sys32_flistxattr_wrapper) 243SYSCALL(sys_flistxattr,sys_flistxattr,compat_sys_flistxattr)
244SYSCALL(sys_removexattr,sys_removexattr,sys32_removexattr_wrapper) 244SYSCALL(sys_removexattr,sys_removexattr,compat_sys_removexattr)
245SYSCALL(sys_lremovexattr,sys_lremovexattr,sys32_lremovexattr_wrapper) 245SYSCALL(sys_lremovexattr,sys_lremovexattr,compat_sys_lremovexattr)
246SYSCALL(sys_fremovexattr,sys_fremovexattr,sys32_fremovexattr_wrapper) /* 235 */ 246SYSCALL(sys_fremovexattr,sys_fremovexattr,compat_sys_fremovexattr) /* 235 */
247SYSCALL(sys_gettid,sys_gettid,sys_gettid) 247SYSCALL(sys_gettid,sys_gettid,sys_gettid)
248SYSCALL(sys_tkill,sys_tkill,sys_tkill_wrapper) 248SYSCALL(sys_tkill,sys_tkill,compat_sys_tkill)
249SYSCALL(sys_futex,sys_futex,compat_sys_futex) 249SYSCALL(sys_futex,sys_futex,compat_sys_futex)
250SYSCALL(sys_sched_setaffinity,sys_sched_setaffinity,sys32_sched_setaffinity_wrapper) 250SYSCALL(sys_sched_setaffinity,sys_sched_setaffinity,compat_sys_sched_setaffinity)
251SYSCALL(sys_sched_getaffinity,sys_sched_getaffinity,sys32_sched_getaffinity_wrapper) /* 240 */ 251SYSCALL(sys_sched_getaffinity,sys_sched_getaffinity,compat_sys_sched_getaffinity) /* 240 */
252SYSCALL(sys_tgkill,sys_tgkill,sys_tgkill_wrapper) 252SYSCALL(sys_tgkill,sys_tgkill,compat_sys_tgkill)
253NI_SYSCALL /* reserved for TUX */ 253NI_SYSCALL /* reserved for TUX */
254SYSCALL(sys_io_setup,sys_io_setup,sys32_io_setup_wrapper) 254SYSCALL(sys_io_setup,sys_io_setup,compat_sys_io_setup)
255SYSCALL(sys_io_destroy,sys_io_destroy,sys32_io_destroy_wrapper) 255SYSCALL(sys_io_destroy,sys_io_destroy,compat_sys_io_destroy)
256SYSCALL(sys_io_getevents,sys_io_getevents,sys32_io_getevents_wrapper) /* 245 */ 256SYSCALL(sys_io_getevents,sys_io_getevents,compat_sys_io_getevents) /* 245 */
257SYSCALL(sys_io_submit,sys_io_submit,sys32_io_submit_wrapper) 257SYSCALL(sys_io_submit,sys_io_submit,compat_sys_io_submit)
258SYSCALL(sys_io_cancel,sys_io_cancel,sys32_io_cancel_wrapper) 258SYSCALL(sys_io_cancel,sys_io_cancel,compat_sys_io_cancel)
259SYSCALL(sys_exit_group,sys_exit_group,sys32_exit_group_wrapper) 259SYSCALL(sys_exit_group,sys_exit_group,compat_sys_exit_group)
260SYSCALL(sys_epoll_create,sys_epoll_create,sys_epoll_create_wrapper) 260SYSCALL(sys_epoll_create,sys_epoll_create,compat_sys_epoll_create)
261SYSCALL(sys_epoll_ctl,sys_epoll_ctl,sys_epoll_ctl_wrapper) /* 250 */ 261SYSCALL(sys_epoll_ctl,sys_epoll_ctl,compat_sys_epoll_ctl) /* 250 */
262SYSCALL(sys_epoll_wait,sys_epoll_wait,sys_epoll_wait_wrapper) 262SYSCALL(sys_epoll_wait,sys_epoll_wait,compat_sys_epoll_wait)
263SYSCALL(sys_set_tid_address,sys_set_tid_address,sys32_set_tid_address_wrapper) 263SYSCALL(sys_set_tid_address,sys_set_tid_address,compat_sys_set_tid_address)
264SYSCALL(sys_s390_fadvise64,sys_fadvise64_64,sys32_fadvise64_wrapper) 264SYSCALL(sys_s390_fadvise64,sys_fadvise64_64,compat_sys_s390_fadvise64)
265SYSCALL(sys_timer_create,sys_timer_create,sys32_timer_create_wrapper) 265SYSCALL(sys_timer_create,sys_timer_create,compat_sys_timer_create)
266SYSCALL(sys_timer_settime,sys_timer_settime,sys32_timer_settime_wrapper) /* 255 */ 266SYSCALL(sys_timer_settime,sys_timer_settime,compat_sys_timer_settime) /* 255 */
267SYSCALL(sys_timer_gettime,sys_timer_gettime,sys32_timer_gettime_wrapper) 267SYSCALL(sys_timer_gettime,sys_timer_gettime,compat_sys_timer_gettime)
268SYSCALL(sys_timer_getoverrun,sys_timer_getoverrun,sys32_timer_getoverrun_wrapper) 268SYSCALL(sys_timer_getoverrun,sys_timer_getoverrun,compat_sys_timer_getoverrun)
269SYSCALL(sys_timer_delete,sys_timer_delete,sys32_timer_delete_wrapper) 269SYSCALL(sys_timer_delete,sys_timer_delete,compat_sys_timer_delete)
270SYSCALL(sys_clock_settime,sys_clock_settime,sys32_clock_settime_wrapper) 270SYSCALL(sys_clock_settime,sys_clock_settime,compat_sys_clock_settime)
271SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper) /* 260 */ 271SYSCALL(sys_clock_gettime,sys_clock_gettime,compat_sys_clock_gettime) /* 260 */
272SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper) 272SYSCALL(sys_clock_getres,sys_clock_getres,compat_sys_clock_getres)
273SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper) 273SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,compat_sys_clock_nanosleep)
274NI_SYSCALL /* reserved for vserver */ 274NI_SYSCALL /* reserved for vserver */
275SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper) 275SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,compat_sys_s390_fadvise64_64)
276SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper) 276SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64)
277SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper) 277SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64)
278SYSCALL(sys_remap_file_pages,sys_remap_file_pages,sys32_remap_file_pages_wrapper) 278SYSCALL(sys_remap_file_pages,sys_remap_file_pages,compat_sys_remap_file_pages)
279NI_SYSCALL /* 268 sys_mbind */ 279NI_SYSCALL /* 268 sys_mbind */
280NI_SYSCALL /* 269 sys_get_mempolicy */ 280NI_SYSCALL /* 269 sys_get_mempolicy */
281NI_SYSCALL /* 270 sys_set_mempolicy */ 281NI_SYSCALL /* 270 sys_set_mempolicy */
282SYSCALL(sys_mq_open,sys_mq_open,compat_sys_mq_open_wrapper) 282SYSCALL(sys_mq_open,sys_mq_open,compat_sys_mq_open)
283SYSCALL(sys_mq_unlink,sys_mq_unlink,sys32_mq_unlink_wrapper) 283SYSCALL(sys_mq_unlink,sys_mq_unlink,compat_sys_mq_unlink)
284SYSCALL(sys_mq_timedsend,sys_mq_timedsend,compat_sys_mq_timedsend_wrapper) 284SYSCALL(sys_mq_timedsend,sys_mq_timedsend,compat_sys_mq_timedsend)
285SYSCALL(sys_mq_timedreceive,sys_mq_timedreceive,compat_sys_mq_timedreceive_wrapper) 285SYSCALL(sys_mq_timedreceive,sys_mq_timedreceive,compat_sys_mq_timedreceive)
286SYSCALL(sys_mq_notify,sys_mq_notify,compat_sys_mq_notify_wrapper) /* 275 */ 286SYSCALL(sys_mq_notify,sys_mq_notify,compat_sys_mq_notify) /* 275 */
287SYSCALL(sys_mq_getsetattr,sys_mq_getsetattr,compat_sys_mq_getsetattr_wrapper) 287SYSCALL(sys_mq_getsetattr,sys_mq_getsetattr,compat_sys_mq_getsetattr)
288SYSCALL(sys_kexec_load,sys_kexec_load,compat_sys_kexec_load_wrapper) 288SYSCALL(sys_kexec_load,sys_kexec_load,compat_sys_kexec_load)
289SYSCALL(sys_add_key,sys_add_key,compat_sys_add_key_wrapper) 289SYSCALL(sys_add_key,sys_add_key,compat_sys_add_key)
290SYSCALL(sys_request_key,sys_request_key,compat_sys_request_key_wrapper) 290SYSCALL(sys_request_key,sys_request_key,compat_sys_request_key)
291SYSCALL(sys_keyctl,sys_keyctl,compat_sys_keyctl_wrapper) /* 280 */ 291SYSCALL(sys_keyctl,sys_keyctl,compat_sys_keyctl) /* 280 */
292SYSCALL(sys_waitid,sys_waitid,compat_sys_waitid) 292SYSCALL(sys_waitid,sys_waitid,compat_sys_waitid)
293SYSCALL(sys_ioprio_set,sys_ioprio_set,sys_ioprio_set_wrapper) 293SYSCALL(sys_ioprio_set,sys_ioprio_set,compat_sys_ioprio_set)
294SYSCALL(sys_ioprio_get,sys_ioprio_get,sys_ioprio_get_wrapper) 294SYSCALL(sys_ioprio_get,sys_ioprio_get,compat_sys_ioprio_get)
295SYSCALL(sys_inotify_init,sys_inotify_init,sys_inotify_init) 295SYSCALL(sys_inotify_init,sys_inotify_init,sys_inotify_init)
296SYSCALL(sys_inotify_add_watch,sys_inotify_add_watch,sys_inotify_add_watch_wrapper) /* 285 */ 296SYSCALL(sys_inotify_add_watch,sys_inotify_add_watch,compat_sys_inotify_add_watch) /* 285 */
297SYSCALL(sys_inotify_rm_watch,sys_inotify_rm_watch,sys_inotify_rm_watch_wrapper) 297SYSCALL(sys_inotify_rm_watch,sys_inotify_rm_watch,compat_sys_inotify_rm_watch)
298NI_SYSCALL /* 287 sys_migrate_pages */ 298NI_SYSCALL /* 287 sys_migrate_pages */
299SYSCALL(sys_openat,sys_openat,compat_sys_openat) 299SYSCALL(sys_openat,sys_openat,compat_sys_openat)
300SYSCALL(sys_mkdirat,sys_mkdirat,sys_mkdirat_wrapper) 300SYSCALL(sys_mkdirat,sys_mkdirat,compat_sys_mkdirat)
301SYSCALL(sys_mknodat,sys_mknodat,sys_mknodat_wrapper) /* 290 */ 301SYSCALL(sys_mknodat,sys_mknodat,compat_sys_mknodat) /* 290 */
302SYSCALL(sys_fchownat,sys_fchownat,sys_fchownat_wrapper) 302SYSCALL(sys_fchownat,sys_fchownat,compat_sys_fchownat)
303SYSCALL(sys_futimesat,sys_futimesat,compat_sys_futimesat_wrapper) 303SYSCALL(sys_futimesat,sys_futimesat,compat_sys_futimesat)
304SYSCALL(sys_fstatat64,sys_newfstatat,sys32_fstatat64_wrapper) 304SYSCALL(sys_fstatat64,sys_newfstatat,compat_sys_s390_fstatat64)
305SYSCALL(sys_unlinkat,sys_unlinkat,sys_unlinkat_wrapper) 305SYSCALL(sys_unlinkat,sys_unlinkat,compat_sys_unlinkat)
306SYSCALL(sys_renameat,sys_renameat,sys_renameat_wrapper) /* 295 */ 306SYSCALL(sys_renameat,sys_renameat,compat_sys_renameat) /* 295 */
307SYSCALL(sys_linkat,sys_linkat,sys_linkat_wrapper) 307SYSCALL(sys_linkat,sys_linkat,compat_sys_linkat)
308SYSCALL(sys_symlinkat,sys_symlinkat,sys_symlinkat_wrapper) 308SYSCALL(sys_symlinkat,sys_symlinkat,compat_sys_symlinkat)
309SYSCALL(sys_readlinkat,sys_readlinkat,sys_readlinkat_wrapper) 309SYSCALL(sys_readlinkat,sys_readlinkat,compat_sys_readlinkat)
310SYSCALL(sys_fchmodat,sys_fchmodat,sys_fchmodat_wrapper) 310SYSCALL(sys_fchmodat,sys_fchmodat,compat_sys_fchmodat)
311SYSCALL(sys_faccessat,sys_faccessat,sys_faccessat_wrapper) /* 300 */ 311SYSCALL(sys_faccessat,sys_faccessat,compat_sys_faccessat) /* 300 */
312SYSCALL(sys_pselect6,sys_pselect6,compat_sys_pselect6_wrapper) 312SYSCALL(sys_pselect6,sys_pselect6,compat_sys_pselect6)
313SYSCALL(sys_ppoll,sys_ppoll,compat_sys_ppoll_wrapper) 313SYSCALL(sys_ppoll,sys_ppoll,compat_sys_ppoll)
314SYSCALL(sys_unshare,sys_unshare,sys_unshare_wrapper) 314SYSCALL(sys_unshare,sys_unshare,compat_sys_unshare)
315SYSCALL(sys_set_robust_list,sys_set_robust_list,compat_sys_set_robust_list) 315SYSCALL(sys_set_robust_list,sys_set_robust_list,compat_sys_set_robust_list)
316SYSCALL(sys_get_robust_list,sys_get_robust_list,compat_sys_get_robust_list) 316SYSCALL(sys_get_robust_list,sys_get_robust_list,compat_sys_get_robust_list)
317SYSCALL(sys_splice,sys_splice,sys_splice_wrapper) 317SYSCALL(sys_splice,sys_splice,compat_sys_splice)
318SYSCALL(sys_sync_file_range,sys_sync_file_range,sys_sync_file_range_wrapper) 318SYSCALL(sys_sync_file_range,sys_sync_file_range,compat_sys_s390_sync_file_range)
319SYSCALL(sys_tee,sys_tee,sys_tee_wrapper) 319SYSCALL(sys_tee,sys_tee,compat_sys_tee)
320SYSCALL(sys_vmsplice,sys_vmsplice,compat_sys_vmsplice) 320SYSCALL(sys_vmsplice,sys_vmsplice,compat_sys_vmsplice)
321NI_SYSCALL /* 310 sys_move_pages */ 321NI_SYSCALL /* 310 sys_move_pages */
322SYSCALL(sys_getcpu,sys_getcpu,sys_getcpu_wrapper) 322SYSCALL(sys_getcpu,sys_getcpu,compat_sys_getcpu)
323SYSCALL(sys_epoll_pwait,sys_epoll_pwait,compat_sys_epoll_pwait) 323SYSCALL(sys_epoll_pwait,sys_epoll_pwait,compat_sys_epoll_pwait)
324SYSCALL(sys_utimes,sys_utimes,compat_sys_utimes_wrapper) 324SYSCALL(sys_utimes,sys_utimes,compat_sys_utimes)
325SYSCALL(sys_s390_fallocate,sys_fallocate,sys_fallocate_wrapper) 325SYSCALL(sys_s390_fallocate,sys_fallocate,compat_sys_s390_fallocate)
326SYSCALL(sys_utimensat,sys_utimensat,compat_sys_utimensat_wrapper) /* 315 */ 326SYSCALL(sys_utimensat,sys_utimensat,compat_sys_utimensat) /* 315 */
327SYSCALL(sys_signalfd,sys_signalfd,compat_sys_signalfd) 327SYSCALL(sys_signalfd,sys_signalfd,compat_sys_signalfd)
328NI_SYSCALL /* 317 old sys_timer_fd */ 328NI_SYSCALL /* 317 old sys_timer_fd */
329SYSCALL(sys_eventfd,sys_eventfd,sys_eventfd_wrapper) 329SYSCALL(sys_eventfd,sys_eventfd,compat_sys_eventfd)
330SYSCALL(sys_timerfd_create,sys_timerfd_create,sys_timerfd_create_wrapper) 330SYSCALL(sys_timerfd_create,sys_timerfd_create,compat_sys_timerfd_create)
331SYSCALL(sys_timerfd_settime,sys_timerfd_settime,compat_sys_timerfd_settime) /* 320 */ 331SYSCALL(sys_timerfd_settime,sys_timerfd_settime,compat_sys_timerfd_settime) /* 320 */
332SYSCALL(sys_timerfd_gettime,sys_timerfd_gettime,compat_sys_timerfd_gettime) 332SYSCALL(sys_timerfd_gettime,sys_timerfd_gettime,compat_sys_timerfd_gettime)
333SYSCALL(sys_signalfd4,sys_signalfd4,compat_sys_signalfd4) 333SYSCALL(sys_signalfd4,sys_signalfd4,compat_sys_signalfd4)
334SYSCALL(sys_eventfd2,sys_eventfd2,sys_eventfd2_wrapper) 334SYSCALL(sys_eventfd2,sys_eventfd2,compat_sys_eventfd2)
335SYSCALL(sys_inotify_init1,sys_inotify_init1,sys_inotify_init1_wrapper) 335SYSCALL(sys_inotify_init1,sys_inotify_init1,compat_sys_inotify_init1)
336SYSCALL(sys_pipe2,sys_pipe2,sys_pipe2_wrapper) /* 325 */ 336SYSCALL(sys_pipe2,sys_pipe2,compat_sys_pipe2) /* 325 */
337SYSCALL(sys_dup3,sys_dup3,sys_dup3_wrapper) 337SYSCALL(sys_dup3,sys_dup3,compat_sys_dup3)
338SYSCALL(sys_epoll_create1,sys_epoll_create1,sys_epoll_create1_wrapper) 338SYSCALL(sys_epoll_create1,sys_epoll_create1,compat_sys_epoll_create1)
339SYSCALL(sys_preadv,sys_preadv,compat_sys_preadv) 339SYSCALL(sys_preadv,sys_preadv,compat_sys_preadv)
340SYSCALL(sys_pwritev,sys_pwritev,compat_sys_pwritev) 340SYSCALL(sys_pwritev,sys_pwritev,compat_sys_pwritev)
341SYSCALL(sys_rt_tgsigqueueinfo,sys_rt_tgsigqueueinfo,compat_sys_rt_tgsigqueueinfo) /* 330 */ 341SYSCALL(sys_rt_tgsigqueueinfo,sys_rt_tgsigqueueinfo,compat_sys_rt_tgsigqueueinfo) /* 330 */
342SYSCALL(sys_perf_event_open,sys_perf_event_open,sys_perf_event_open_wrapper) 342SYSCALL(sys_perf_event_open,sys_perf_event_open,compat_sys_perf_event_open)
343SYSCALL(sys_fanotify_init,sys_fanotify_init,sys_fanotify_init_wrapper) 343SYSCALL(sys_fanotify_init,sys_fanotify_init,compat_sys_fanotify_init)
344SYSCALL(sys_fanotify_mark,sys_fanotify_mark,compat_sys_fanotify_mark) 344SYSCALL(sys_fanotify_mark,sys_fanotify_mark,compat_sys_fanotify_mark)
345SYSCALL(sys_prlimit64,sys_prlimit64,sys_prlimit64_wrapper) 345SYSCALL(sys_prlimit64,sys_prlimit64,compat_sys_prlimit64)
346SYSCALL(sys_name_to_handle_at,sys_name_to_handle_at,sys_name_to_handle_at_wrapper) /* 335 */ 346SYSCALL(sys_name_to_handle_at,sys_name_to_handle_at,compat_sys_name_to_handle_at) /* 335 */
347SYSCALL(sys_open_by_handle_at,sys_open_by_handle_at,compat_sys_open_by_handle_at) 347SYSCALL(sys_open_by_handle_at,sys_open_by_handle_at,compat_sys_open_by_handle_at)
348SYSCALL(sys_clock_adjtime,sys_clock_adjtime,compat_sys_clock_adjtime_wrapper) 348SYSCALL(sys_clock_adjtime,sys_clock_adjtime,compat_sys_clock_adjtime)
349SYSCALL(sys_syncfs,sys_syncfs,sys_syncfs_wrapper) 349SYSCALL(sys_syncfs,sys_syncfs,compat_sys_syncfs)
350SYSCALL(sys_setns,sys_setns,sys_setns_wrapper) 350SYSCALL(sys_setns,sys_setns,compat_sys_setns)
351SYSCALL(sys_process_vm_readv,sys_process_vm_readv,compat_sys_process_vm_readv_wrapper) /* 340 */ 351SYSCALL(sys_process_vm_readv,sys_process_vm_readv,compat_sys_process_vm_readv) /* 340 */
352SYSCALL(sys_process_vm_writev,sys_process_vm_writev,compat_sys_process_vm_writev_wrapper) 352SYSCALL(sys_process_vm_writev,sys_process_vm_writev,compat_sys_process_vm_writev)
353SYSCALL(sys_ni_syscall,sys_s390_runtime_instr,sys_s390_runtime_instr_wrapper) 353SYSCALL(sys_ni_syscall,sys_s390_runtime_instr,compat_sys_s390_runtime_instr)
354SYSCALL(sys_kcmp,sys_kcmp,sys_kcmp_wrapper) 354SYSCALL(sys_kcmp,sys_kcmp,compat_sys_kcmp)
355SYSCALL(sys_finit_module,sys_finit_module,sys_finit_module_wrapper) 355SYSCALL(sys_finit_module,sys_finit_module,compat_sys_finit_module)
356SYSCALL(sys_sched_setattr,sys_sched_setattr,sys_sched_setattr_wrapper) /* 345 */ 356SYSCALL(sys_sched_setattr,sys_sched_setattr,compat_sys_sched_setattr) /* 345 */
357SYSCALL(sys_sched_getattr,sys_sched_getattr,sys_sched_getattr_wrapper) 357SYSCALL(sys_sched_getattr,sys_sched_getattr,compat_sys_sched_getattr)
diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
index 4b2e3e317004..6298fed11ced 100644
--- a/arch/s390/kernel/topology.c
+++ b/arch/s390/kernel/topology.c
@@ -451,7 +451,6 @@ static int __init topology_init(void)
451 } 451 }
452 set_topology_timer(); 452 set_topology_timer();
453out: 453out:
454 update_cpu_masks();
455 return device_create_file(cpu_subsys.dev_root, &dev_attr_dispatching); 454 return device_create_file(cpu_subsys.dev_root, &dev_attr_dispatching);
456} 455}
457device_initcall(topology_init); 456device_initcall(topology_init);
diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
index 8216c0e0b2e2..6f9cfa500372 100644
--- a/arch/s390/kvm/diag.c
+++ b/arch/s390/kvm/diag.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/kvm.h> 14#include <linux/kvm.h>
15#include <linux/kvm_host.h> 15#include <linux/kvm_host.h>
16#include <asm/pgalloc.h>
16#include <asm/virtio-ccw.h> 17#include <asm/virtio-ccw.h>
17#include "kvm-s390.h" 18#include "kvm-s390.h"
18#include "trace.h" 19#include "trace.h"
@@ -86,9 +87,11 @@ static int __diag_ipl_functions(struct kvm_vcpu *vcpu)
86 switch (subcode) { 87 switch (subcode) {
87 case 3: 88 case 3:
88 vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR; 89 vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR;
90 page_table_reset_pgste(current->mm, 0, TASK_SIZE);
89 break; 91 break;
90 case 4: 92 case 4:
91 vcpu->run->s390_reset_flags = 0; 93 vcpu->run->s390_reset_flags = 0;
94 page_table_reset_pgste(current->mm, 0, TASK_SIZE);
92 break; 95 break;
93 default: 96 default:
94 return -EOPNOTSUPP; 97 return -EOPNOTSUPP;
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index e0676f390d57..10b5db3c9bc4 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -68,6 +68,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
68 { "instruction_storage_key", VCPU_STAT(instruction_storage_key) }, 68 { "instruction_storage_key", VCPU_STAT(instruction_storage_key) },
69 { "instruction_stsch", VCPU_STAT(instruction_stsch) }, 69 { "instruction_stsch", VCPU_STAT(instruction_stsch) },
70 { "instruction_chsc", VCPU_STAT(instruction_chsc) }, 70 { "instruction_chsc", VCPU_STAT(instruction_chsc) },
71 { "instruction_essa", VCPU_STAT(instruction_essa) },
71 { "instruction_stsi", VCPU_STAT(instruction_stsi) }, 72 { "instruction_stsi", VCPU_STAT(instruction_stsi) },
72 { "instruction_stfl", VCPU_STAT(instruction_stfl) }, 73 { "instruction_stfl", VCPU_STAT(instruction_stfl) },
73 { "instruction_tprot", VCPU_STAT(instruction_tprot) }, 74 { "instruction_tprot", VCPU_STAT(instruction_tprot) },
@@ -283,7 +284,11 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
283 if (kvm_is_ucontrol(vcpu->kvm)) 284 if (kvm_is_ucontrol(vcpu->kvm))
284 gmap_free(vcpu->arch.gmap); 285 gmap_free(vcpu->arch.gmap);
285 286
287 if (vcpu->arch.sie_block->cbrlo)
288 __free_page(__pfn_to_page(
289 vcpu->arch.sie_block->cbrlo >> PAGE_SHIFT));
286 free_page((unsigned long)(vcpu->arch.sie_block)); 290 free_page((unsigned long)(vcpu->arch.sie_block));
291
287 kvm_vcpu_uninit(vcpu); 292 kvm_vcpu_uninit(vcpu);
288 kmem_cache_free(kvm_vcpu_cache, vcpu); 293 kmem_cache_free(kvm_vcpu_cache, vcpu);
289} 294}
@@ -390,6 +395,8 @@ int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
390 395
391int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) 396int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
392{ 397{
398 struct page *cbrl;
399
393 atomic_set(&vcpu->arch.sie_block->cpuflags, CPUSTAT_ZARCH | 400 atomic_set(&vcpu->arch.sie_block->cpuflags, CPUSTAT_ZARCH |
394 CPUSTAT_SM | 401 CPUSTAT_SM |
395 CPUSTAT_STOPPED | 402 CPUSTAT_STOPPED |
@@ -401,6 +408,14 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
401 vcpu->arch.sie_block->ecb2 = 8; 408 vcpu->arch.sie_block->ecb2 = 8;
402 vcpu->arch.sie_block->eca = 0xC1002001U; 409 vcpu->arch.sie_block->eca = 0xC1002001U;
403 vcpu->arch.sie_block->fac = (int) (long) vfacilities; 410 vcpu->arch.sie_block->fac = (int) (long) vfacilities;
411 if (kvm_enabled_cmma()) {
412 cbrl = alloc_page(GFP_KERNEL | __GFP_ZERO);
413 if (cbrl) {
414 vcpu->arch.sie_block->ecb2 |= 0x80;
415 vcpu->arch.sie_block->ecb2 &= ~0x08;
416 vcpu->arch.sie_block->cbrlo = page_to_phys(cbrl);
417 }
418 }
404 hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); 419 hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
405 tasklet_init(&vcpu->arch.tasklet, kvm_s390_tasklet, 420 tasklet_init(&vcpu->arch.tasklet, kvm_s390_tasklet,
406 (unsigned long) vcpu); 421 (unsigned long) vcpu);
@@ -761,6 +776,16 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)
761 return rc; 776 return rc;
762} 777}
763 778
779bool kvm_enabled_cmma(void)
780{
781 if (!MACHINE_IS_LPAR)
782 return false;
783 /* only enable for z10 and later */
784 if (!MACHINE_HAS_EDAT1)
785 return false;
786 return true;
787}
788
764static int __vcpu_run(struct kvm_vcpu *vcpu) 789static int __vcpu_run(struct kvm_vcpu *vcpu)
765{ 790{
766 int rc, exit_reason; 791 int rc, exit_reason;
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index f9559b0bd620..564514f410f4 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -156,6 +156,8 @@ void s390_vcpu_block(struct kvm_vcpu *vcpu);
156void s390_vcpu_unblock(struct kvm_vcpu *vcpu); 156void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
157void exit_sie(struct kvm_vcpu *vcpu); 157void exit_sie(struct kvm_vcpu *vcpu);
158void exit_sie_sync(struct kvm_vcpu *vcpu); 158void exit_sie_sync(struct kvm_vcpu *vcpu);
159/* are we going to support cmma? */
160bool kvm_enabled_cmma(void);
159/* implemented in diag.c */ 161/* implemented in diag.c */
160int kvm_s390_handle_diag(struct kvm_vcpu *vcpu); 162int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
161 163
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 75beea632a10..aacb6b129914 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -636,8 +636,49 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)
636 return 0; 636 return 0;
637} 637}
638 638
639static int handle_essa(struct kvm_vcpu *vcpu)
640{
641 /* entries expected to be 1FF */
642 int entries = (vcpu->arch.sie_block->cbrlo & ~PAGE_MASK) >> 3;
643 unsigned long *cbrlo, cbrle;
644 struct gmap *gmap;
645 int i;
646
647 VCPU_EVENT(vcpu, 5, "cmma release %d pages", entries);
648 gmap = vcpu->arch.gmap;
649 vcpu->stat.instruction_essa++;
650 if (!kvm_enabled_cmma() || !vcpu->arch.sie_block->cbrlo)
651 return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
652
653 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
654 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
655
656 if (((vcpu->arch.sie_block->ipb & 0xf0000000) >> 28) > 6)
657 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
658
659 /* Rewind PSW to repeat the ESSA instruction */
660 vcpu->arch.sie_block->gpsw.addr =
661 __rewind_psw(vcpu->arch.sie_block->gpsw, 4);
662 vcpu->arch.sie_block->cbrlo &= PAGE_MASK; /* reset nceo */
663 cbrlo = phys_to_virt(vcpu->arch.sie_block->cbrlo);
664 down_read(&gmap->mm->mmap_sem);
665 for (i = 0; i < entries; ++i) {
666 cbrle = cbrlo[i];
667 if (unlikely(cbrle & ~PAGE_MASK || cbrle < 2 * PAGE_SIZE))
668 /* invalid entry */
669 break;
670 /* try to free backing */
671 __gmap_zap(cbrle, gmap);
672 }
673 up_read(&gmap->mm->mmap_sem);
674 if (i < entries)
675 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
676 return 0;
677}
678
639static const intercept_handler_t b9_handlers[256] = { 679static const intercept_handler_t b9_handlers[256] = {
640 [0x8d] = handle_epsw, 680 [0x8d] = handle_epsw,
681 [0xab] = handle_essa,
641 [0xaf] = handle_pfmf, 682 [0xaf] = handle_pfmf,
642}; 683};
643 684
diff --git a/arch/s390/lib/Makefile b/arch/s390/lib/Makefile
index b068729e50ac..e3fffe1dff51 100644
--- a/arch/s390/lib/Makefile
+++ b/arch/s390/lib/Makefile
@@ -2,8 +2,7 @@
2# Makefile for s390-specific library files.. 2# Makefile for s390-specific library files..
3# 3#
4 4
5lib-y += delay.o string.o uaccess_pt.o find.o 5lib-y += delay.o string.o uaccess_pt.o uaccess_mvcos.o find.o
6obj-$(CONFIG_32BIT) += div64.o qrnnd.o ucmpdi2.o mem32.o 6obj-$(CONFIG_32BIT) += div64.o qrnnd.o ucmpdi2.o mem32.o
7obj-$(CONFIG_64BIT) += mem64.o 7obj-$(CONFIG_64BIT) += mem64.o
8lib-$(CONFIG_64BIT) += uaccess_mvcos.o
9lib-$(CONFIG_SMP) += spinlock.o 8lib-$(CONFIG_SMP) += spinlock.o
diff --git a/arch/s390/lib/find.c b/arch/s390/lib/find.c
index 620d34d6487e..922003c1b90d 100644
--- a/arch/s390/lib/find.c
+++ b/arch/s390/lib/find.c
@@ -4,7 +4,7 @@
4 * On s390x the bits are numbered: 4 * On s390x the bits are numbered:
5 * |0..............63|64............127|128...........191|192...........255| 5 * |0..............63|64............127|128...........191|192...........255|
6 * and on s390: 6 * and on s390:
7 * |0.....31|31....63|64....95|96...127|128..159|160..191|192..223|224..255| 7 * |0.....31|32....63|64....95|96...127|128..159|160..191|192..223|224..255|
8 * 8 *
9 * The reason for this bit numbering is the fact that the hardware sets bits 9 * The reason for this bit numbering is the fact that the hardware sets bits
10 * in a bitmap starting at bit 0 (MSB) and we don't want to scan the bitmap 10 * in a bitmap starting at bit 0 (MSB) and we don't want to scan the bitmap
diff --git a/arch/s390/lib/uaccess.h b/arch/s390/lib/uaccess.h
index b1a22173d027..c7e0e81f4b4e 100644
--- a/arch/s390/lib/uaccess.h
+++ b/arch/s390/lib/uaccess.h
@@ -6,7 +6,11 @@
6#ifndef __ARCH_S390_LIB_UACCESS_H 6#ifndef __ARCH_S390_LIB_UACCESS_H
7#define __ARCH_S390_LIB_UACCESS_H 7#define __ARCH_S390_LIB_UACCESS_H
8 8
9extern int futex_atomic_op_pt(int, u32 __user *, int, int *); 9unsigned long copy_from_user_pt(void *to, const void __user *from, unsigned long n);
10extern int futex_atomic_cmpxchg_pt(u32 *, u32 __user *, u32, u32); 10unsigned long copy_to_user_pt(void __user *to, const void *from, unsigned long n);
11unsigned long copy_in_user_pt(void __user *to, const void __user *from, unsigned long n);
12unsigned long clear_user_pt(void __user *to, unsigned long n);
13unsigned long strnlen_user_pt(const char __user *src, unsigned long count);
14long strncpy_from_user_pt(char *dst, const char __user *src, long count);
11 15
12#endif /* __ARCH_S390_LIB_UACCESS_H */ 16#endif /* __ARCH_S390_LIB_UACCESS_H */
diff --git a/arch/s390/lib/uaccess_mvcos.c b/arch/s390/lib/uaccess_mvcos.c
index 4b7993bf69b9..ae97b8df11aa 100644
--- a/arch/s390/lib/uaccess_mvcos.c
+++ b/arch/s390/lib/uaccess_mvcos.c
@@ -6,8 +6,11 @@
6 * Gerald Schaefer (gerald.schaefer@de.ibm.com) 6 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
7 */ 7 */
8 8
9#include <linux/jump_label.h>
9#include <linux/errno.h> 10#include <linux/errno.h>
11#include <linux/init.h>
10#include <linux/mm.h> 12#include <linux/mm.h>
13#include <asm/facility.h>
11#include <asm/uaccess.h> 14#include <asm/uaccess.h>
12#include <asm/futex.h> 15#include <asm/futex.h>
13#include "uaccess.h" 16#include "uaccess.h"
@@ -26,7 +29,10 @@
26#define SLR "slgr" 29#define SLR "slgr"
27#endif 30#endif
28 31
29static size_t copy_from_user_mvcos(size_t size, const void __user *ptr, void *x) 32static struct static_key have_mvcos = STATIC_KEY_INIT_TRUE;
33
34static inline unsigned long copy_from_user_mvcos(void *x, const void __user *ptr,
35 unsigned long size)
30{ 36{
31 register unsigned long reg0 asm("0") = 0x81UL; 37 register unsigned long reg0 asm("0") = 0x81UL;
32 unsigned long tmp1, tmp2; 38 unsigned long tmp1, tmp2;
@@ -65,7 +71,16 @@ static size_t copy_from_user_mvcos(size_t size, const void __user *ptr, void *x)
65 return size; 71 return size;
66} 72}
67 73
68static size_t copy_to_user_mvcos(size_t size, void __user *ptr, const void *x) 74unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
75{
76 if (static_key_true(&have_mvcos))
77 return copy_from_user_mvcos(to, from, n);
78 return copy_from_user_pt(to, from, n);
79}
80EXPORT_SYMBOL(__copy_from_user);
81
82static inline unsigned long copy_to_user_mvcos(void __user *ptr, const void *x,
83 unsigned long size)
69{ 84{
70 register unsigned long reg0 asm("0") = 0x810000UL; 85 register unsigned long reg0 asm("0") = 0x810000UL;
71 unsigned long tmp1, tmp2; 86 unsigned long tmp1, tmp2;
@@ -94,8 +109,16 @@ static size_t copy_to_user_mvcos(size_t size, void __user *ptr, const void *x)
94 return size; 109 return size;
95} 110}
96 111
97static size_t copy_in_user_mvcos(size_t size, void __user *to, 112unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
98 const void __user *from) 113{
114 if (static_key_true(&have_mvcos))
115 return copy_to_user_mvcos(to, from, n);
116 return copy_to_user_pt(to, from, n);
117}
118EXPORT_SYMBOL(__copy_to_user);
119
120static inline unsigned long copy_in_user_mvcos(void __user *to, const void __user *from,
121 unsigned long size)
99{ 122{
100 register unsigned long reg0 asm("0") = 0x810081UL; 123 register unsigned long reg0 asm("0") = 0x810081UL;
101 unsigned long tmp1, tmp2; 124 unsigned long tmp1, tmp2;
@@ -117,7 +140,15 @@ static size_t copy_in_user_mvcos(size_t size, void __user *to,
117 return size; 140 return size;
118} 141}
119 142
120static size_t clear_user_mvcos(size_t size, void __user *to) 143unsigned long __copy_in_user(void __user *to, const void __user *from, unsigned long n)
144{
145 if (static_key_true(&have_mvcos))
146 return copy_in_user_mvcos(to, from, n);
147 return copy_in_user_pt(to, from, n);
148}
149EXPORT_SYMBOL(__copy_in_user);
150
151static inline unsigned long clear_user_mvcos(void __user *to, unsigned long size)
121{ 152{
122 register unsigned long reg0 asm("0") = 0x810000UL; 153 register unsigned long reg0 asm("0") = 0x810000UL;
123 unsigned long tmp1, tmp2; 154 unsigned long tmp1, tmp2;
@@ -145,17 +176,26 @@ static size_t clear_user_mvcos(size_t size, void __user *to)
145 return size; 176 return size;
146} 177}
147 178
148static size_t strnlen_user_mvcos(size_t count, const char __user *src) 179unsigned long __clear_user(void __user *to, unsigned long size)
149{ 180{
150 size_t done, len, offset, len_str; 181 if (static_key_true(&have_mvcos))
182 return clear_user_mvcos(to, size);
183 return clear_user_pt(to, size);
184}
185EXPORT_SYMBOL(__clear_user);
186
187static inline unsigned long strnlen_user_mvcos(const char __user *src,
188 unsigned long count)
189{
190 unsigned long done, len, offset, len_str;
151 char buf[256]; 191 char buf[256];
152 192
153 done = 0; 193 done = 0;
154 do { 194 do {
155 offset = (size_t)src & ~PAGE_MASK; 195 offset = (unsigned long)src & ~PAGE_MASK;
156 len = min(256UL, PAGE_SIZE - offset); 196 len = min(256UL, PAGE_SIZE - offset);
157 len = min(count - done, len); 197 len = min(count - done, len);
158 if (copy_from_user_mvcos(len, src, buf)) 198 if (copy_from_user_mvcos(buf, src, len))
159 return 0; 199 return 0;
160 len_str = strnlen(buf, len); 200 len_str = strnlen(buf, len);
161 done += len_str; 201 done += len_str;
@@ -164,18 +204,26 @@ static size_t strnlen_user_mvcos(size_t count, const char __user *src)
164 return done + 1; 204 return done + 1;
165} 205}
166 206
167static size_t strncpy_from_user_mvcos(size_t count, const char __user *src, 207unsigned long __strnlen_user(const char __user *src, unsigned long count)
168 char *dst)
169{ 208{
170 size_t done, len, offset, len_str; 209 if (static_key_true(&have_mvcos))
210 return strnlen_user_mvcos(src, count);
211 return strnlen_user_pt(src, count);
212}
213EXPORT_SYMBOL(__strnlen_user);
171 214
172 if (unlikely(!count)) 215static inline long strncpy_from_user_mvcos(char *dst, const char __user *src,
216 long count)
217{
218 unsigned long done, len, offset, len_str;
219
220 if (unlikely(count <= 0))
173 return 0; 221 return 0;
174 done = 0; 222 done = 0;
175 do { 223 do {
176 offset = (size_t)src & ~PAGE_MASK; 224 offset = (unsigned long)src & ~PAGE_MASK;
177 len = min(count - done, PAGE_SIZE - offset); 225 len = min(count - done, PAGE_SIZE - offset);
178 if (copy_from_user_mvcos(len, src, dst)) 226 if (copy_from_user_mvcos(dst, src, len))
179 return -EFAULT; 227 return -EFAULT;
180 len_str = strnlen(dst, len); 228 len_str = strnlen(dst, len);
181 done += len_str; 229 done += len_str;
@@ -185,13 +233,31 @@ static size_t strncpy_from_user_mvcos(size_t count, const char __user *src,
185 return done; 233 return done;
186} 234}
187 235
188struct uaccess_ops uaccess_mvcos = { 236long __strncpy_from_user(char *dst, const char __user *src, long count)
189 .copy_from_user = copy_from_user_mvcos, 237{
190 .copy_to_user = copy_to_user_mvcos, 238 if (static_key_true(&have_mvcos))
191 .copy_in_user = copy_in_user_mvcos, 239 return strncpy_from_user_mvcos(dst, src, count);
192 .clear_user = clear_user_mvcos, 240 return strncpy_from_user_pt(dst, src, count);
193 .strnlen_user = strnlen_user_mvcos, 241}
194 .strncpy_from_user = strncpy_from_user_mvcos, 242EXPORT_SYMBOL(__strncpy_from_user);
195 .futex_atomic_op = futex_atomic_op_pt, 243
196 .futex_atomic_cmpxchg = futex_atomic_cmpxchg_pt, 244/*
197}; 245 * The uaccess page tabe walk variant can be enforced with the "uaccesspt"
246 * kernel parameter. This is mainly for debugging purposes.
247 */
248static int force_uaccess_pt __initdata;
249
250static int __init parse_uaccess_pt(char *__unused)
251{
252 force_uaccess_pt = 1;
253 return 0;
254}
255early_param("uaccesspt", parse_uaccess_pt);
256
257static int __init uaccess_init(void)
258{
259 if (IS_ENABLED(CONFIG_32BIT) || force_uaccess_pt || !test_facility(27))
260 static_key_slow_dec(&have_mvcos);
261 return 0;
262}
263early_initcall(uaccess_init);
diff --git a/arch/s390/lib/uaccess_pt.c b/arch/s390/lib/uaccess_pt.c
index 61ebcc9ccb34..8d39760bae68 100644
--- a/arch/s390/lib/uaccess_pt.c
+++ b/arch/s390/lib/uaccess_pt.c
@@ -22,7 +22,7 @@
22#define SLR "slgr" 22#define SLR "slgr"
23#endif 23#endif
24 24
25static size_t strnlen_kernel(size_t count, const char __user *src) 25static unsigned long strnlen_kernel(const char __user *src, unsigned long count)
26{ 26{
27 register unsigned long reg0 asm("0") = 0UL; 27 register unsigned long reg0 asm("0") = 0UL;
28 unsigned long tmp1, tmp2; 28 unsigned long tmp1, tmp2;
@@ -42,8 +42,8 @@ static size_t strnlen_kernel(size_t count, const char __user *src)
42 return count; 42 return count;
43} 43}
44 44
45static size_t copy_in_kernel(size_t count, void __user *to, 45static unsigned long copy_in_kernel(void __user *to, const void __user *from,
46 const void __user *from) 46 unsigned long count)
47{ 47{
48 unsigned long tmp1; 48 unsigned long tmp1;
49 49
@@ -146,8 +146,8 @@ static unsigned long follow_table(struct mm_struct *mm,
146 146
147#endif /* CONFIG_64BIT */ 147#endif /* CONFIG_64BIT */
148 148
149static __always_inline size_t __user_copy_pt(unsigned long uaddr, void *kptr, 149static inline unsigned long __user_copy_pt(unsigned long uaddr, void *kptr,
150 size_t n, int write_user) 150 unsigned long n, int write_user)
151{ 151{
152 struct mm_struct *mm = current->mm; 152 struct mm_struct *mm = current->mm;
153 unsigned long offset, done, size, kaddr; 153 unsigned long offset, done, size, kaddr;
@@ -189,8 +189,7 @@ fault:
189 * Do DAT for user address by page table walk, return kernel address. 189 * Do DAT for user address by page table walk, return kernel address.
190 * This function needs to be called with current->mm->page_table_lock held. 190 * This function needs to be called with current->mm->page_table_lock held.
191 */ 191 */
192static __always_inline unsigned long __dat_user_addr(unsigned long uaddr, 192static inline unsigned long __dat_user_addr(unsigned long uaddr, int write)
193 int write)
194{ 193{
195 struct mm_struct *mm = current->mm; 194 struct mm_struct *mm = current->mm;
196 unsigned long kaddr; 195 unsigned long kaddr;
@@ -211,29 +210,29 @@ fault:
211 return 0; 210 return 0;
212} 211}
213 212
214static size_t copy_from_user_pt(size_t n, const void __user *from, void *to) 213unsigned long copy_from_user_pt(void *to, const void __user *from, unsigned long n)
215{ 214{
216 size_t rc; 215 unsigned long rc;
217 216
218 if (segment_eq(get_fs(), KERNEL_DS)) 217 if (segment_eq(get_fs(), KERNEL_DS))
219 return copy_in_kernel(n, (void __user *) to, from); 218 return copy_in_kernel((void __user *) to, from, n);
220 rc = __user_copy_pt((unsigned long) from, to, n, 0); 219 rc = __user_copy_pt((unsigned long) from, to, n, 0);
221 if (unlikely(rc)) 220 if (unlikely(rc))
222 memset(to + n - rc, 0, rc); 221 memset(to + n - rc, 0, rc);
223 return rc; 222 return rc;
224} 223}
225 224
226static size_t copy_to_user_pt(size_t n, void __user *to, const void *from) 225unsigned long copy_to_user_pt(void __user *to, const void *from, unsigned long n)
227{ 226{
228 if (segment_eq(get_fs(), KERNEL_DS)) 227 if (segment_eq(get_fs(), KERNEL_DS))
229 return copy_in_kernel(n, to, (void __user *) from); 228 return copy_in_kernel(to, (void __user *) from, n);
230 return __user_copy_pt((unsigned long) to, (void *) from, n, 1); 229 return __user_copy_pt((unsigned long) to, (void *) from, n, 1);
231} 230}
232 231
233static size_t clear_user_pt(size_t n, void __user *to) 232unsigned long clear_user_pt(void __user *to, unsigned long n)
234{ 233{
235 void *zpage = (void *) empty_zero_page; 234 void *zpage = (void *) empty_zero_page;
236 long done, size, ret; 235 unsigned long done, size, ret;
237 236
238 done = 0; 237 done = 0;
239 do { 238 do {
@@ -242,7 +241,7 @@ static size_t clear_user_pt(size_t n, void __user *to)
242 else 241 else
243 size = n - done; 242 size = n - done;
244 if (segment_eq(get_fs(), KERNEL_DS)) 243 if (segment_eq(get_fs(), KERNEL_DS))
245 ret = copy_in_kernel(n, to, (void __user *) zpage); 244 ret = copy_in_kernel(to, (void __user *) zpage, n);
246 else 245 else
247 ret = __user_copy_pt((unsigned long) to, zpage, size, 1); 246 ret = __user_copy_pt((unsigned long) to, zpage, size, 1);
248 done += size; 247 done += size;
@@ -253,17 +252,17 @@ static size_t clear_user_pt(size_t n, void __user *to)
253 return 0; 252 return 0;
254} 253}
255 254
256static size_t strnlen_user_pt(size_t count, const char __user *src) 255unsigned long strnlen_user_pt(const char __user *src, unsigned long count)
257{ 256{
258 unsigned long uaddr = (unsigned long) src; 257 unsigned long uaddr = (unsigned long) src;
259 struct mm_struct *mm = current->mm; 258 struct mm_struct *mm = current->mm;
260 unsigned long offset, done, len, kaddr; 259 unsigned long offset, done, len, kaddr;
261 size_t len_str; 260 unsigned long len_str;
262 261
263 if (unlikely(!count)) 262 if (unlikely(!count))
264 return 0; 263 return 0;
265 if (segment_eq(get_fs(), KERNEL_DS)) 264 if (segment_eq(get_fs(), KERNEL_DS))
266 return strnlen_kernel(count, src); 265 return strnlen_kernel(src, count);
267 if (!mm) 266 if (!mm)
268 return 0; 267 return 0;
269 done = 0; 268 done = 0;
@@ -289,19 +288,18 @@ fault:
289 goto retry; 288 goto retry;
290} 289}
291 290
292static size_t strncpy_from_user_pt(size_t count, const char __user *src, 291long strncpy_from_user_pt(char *dst, const char __user *src, long count)
293 char *dst)
294{ 292{
295 size_t done, len, offset, len_str; 293 unsigned long done, len, offset, len_str;
296 294
297 if (unlikely(!count)) 295 if (unlikely(count <= 0))
298 return 0; 296 return 0;
299 done = 0; 297 done = 0;
300 do { 298 do {
301 offset = (size_t)src & ~PAGE_MASK; 299 offset = (unsigned long)src & ~PAGE_MASK;
302 len = min(count - done, PAGE_SIZE - offset); 300 len = min(count - done, PAGE_SIZE - offset);
303 if (segment_eq(get_fs(), KERNEL_DS)) { 301 if (segment_eq(get_fs(), KERNEL_DS)) {
304 if (copy_in_kernel(len, (void __user *) dst, src)) 302 if (copy_in_kernel((void __user *) dst, src, len))
305 return -EFAULT; 303 return -EFAULT;
306 } else { 304 } else {
307 if (__user_copy_pt((unsigned long) src, dst, len, 0)) 305 if (__user_copy_pt((unsigned long) src, dst, len, 0))
@@ -315,8 +313,8 @@ static size_t strncpy_from_user_pt(size_t count, const char __user *src,
315 return done; 313 return done;
316} 314}
317 315
318static size_t copy_in_user_pt(size_t n, void __user *to, 316unsigned long copy_in_user_pt(void __user *to, const void __user *from,
319 const void __user *from) 317 unsigned long n)
320{ 318{
321 struct mm_struct *mm = current->mm; 319 struct mm_struct *mm = current->mm;
322 unsigned long offset_max, uaddr, done, size, error_code; 320 unsigned long offset_max, uaddr, done, size, error_code;
@@ -326,7 +324,7 @@ static size_t copy_in_user_pt(size_t n, void __user *to,
326 int write_user; 324 int write_user;
327 325
328 if (segment_eq(get_fs(), KERNEL_DS)) 326 if (segment_eq(get_fs(), KERNEL_DS))
329 return copy_in_kernel(n, to, from); 327 return copy_in_kernel(to, from, n);
330 if (!mm) 328 if (!mm)
331 return n; 329 return n;
332 done = 0; 330 done = 0;
@@ -411,7 +409,7 @@ static int __futex_atomic_op_pt(int op, u32 __user *uaddr, int oparg, int *old)
411 return ret; 409 return ret;
412} 410}
413 411
414int futex_atomic_op_pt(int op, u32 __user *uaddr, int oparg, int *old) 412int __futex_atomic_op_inuser(int op, u32 __user *uaddr, int oparg, int *old)
415{ 413{
416 int ret; 414 int ret;
417 415
@@ -449,8 +447,8 @@ static int __futex_atomic_cmpxchg_pt(u32 *uval, u32 __user *uaddr,
449 return ret; 447 return ret;
450} 448}
451 449
452int futex_atomic_cmpxchg_pt(u32 *uval, u32 __user *uaddr, 450int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
453 u32 oldval, u32 newval) 451 u32 oldval, u32 newval)
454{ 452{
455 int ret; 453 int ret;
456 454
@@ -471,14 +469,3 @@ int futex_atomic_cmpxchg_pt(u32 *uval, u32 __user *uaddr,
471 put_page(virt_to_page(uaddr)); 469 put_page(virt_to_page(uaddr));
472 return ret; 470 return ret;
473} 471}
474
475struct uaccess_ops uaccess_pt = {
476 .copy_from_user = copy_from_user_pt,
477 .copy_to_user = copy_to_user_pt,
478 .copy_in_user = copy_in_user_pt,
479 .clear_user = clear_user_pt,
480 .strnlen_user = strnlen_user_pt,
481 .strncpy_from_user = strncpy_from_user_pt,
482 .futex_atomic_op = futex_atomic_op_pt,
483 .futex_atomic_cmpxchg = futex_atomic_cmpxchg_pt,
484};
diff --git a/arch/s390/mm/maccess.c b/arch/s390/mm/maccess.c
index d1e0e0c7a7e2..2a2e35416d2f 100644
--- a/arch/s390/mm/maccess.c
+++ b/arch/s390/mm/maccess.c
@@ -128,7 +128,7 @@ void memcpy_absolute(void *dest, void *src, size_t count)
128/* 128/*
129 * Copy memory from kernel (real) to user (virtual) 129 * Copy memory from kernel (real) to user (virtual)
130 */ 130 */
131int copy_to_user_real(void __user *dest, void *src, size_t count) 131int copy_to_user_real(void __user *dest, void *src, unsigned long count)
132{ 132{
133 int offs = 0, size, rc; 133 int offs = 0, size, rc;
134 char *buf; 134 char *buf;
@@ -152,32 +152,6 @@ out:
152} 152}
153 153
154/* 154/*
155 * Copy memory from user (virtual) to kernel (real)
156 */
157int copy_from_user_real(void *dest, void __user *src, size_t count)
158{
159 int offs = 0, size, rc;
160 char *buf;
161
162 buf = (char *) __get_free_page(GFP_KERNEL);
163 if (!buf)
164 return -ENOMEM;
165 rc = -EFAULT;
166 while (offs < count) {
167 size = min(PAGE_SIZE, count - offs);
168 if (copy_from_user(buf, src + offs, size))
169 goto out;
170 if (memcpy_real(dest + offs, buf, size))
171 goto out;
172 offs += size;
173 }
174 rc = 0;
175out:
176 free_page((unsigned long) buf);
177 return rc;
178}
179
180/*
181 * Check if physical address is within prefix or zero page 155 * Check if physical address is within prefix or zero page
182 */ 156 */
183static int is_swapped(unsigned long addr) 157static int is_swapped(unsigned long addr)
diff --git a/arch/s390/mm/page-states.c b/arch/s390/mm/page-states.c
index a90d45e9dfb0..27c50f4d90cb 100644
--- a/arch/s390/mm/page-states.c
+++ b/arch/s390/mm/page-states.c
@@ -12,6 +12,8 @@
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <linux/gfp.h> 13#include <linux/gfp.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <asm/setup.h>
16#include <asm/ipl.h>
15 17
16#define ESSA_SET_STABLE 1 18#define ESSA_SET_STABLE 1
17#define ESSA_SET_UNUSED 2 19#define ESSA_SET_UNUSED 2
@@ -41,6 +43,14 @@ void __init cmma_init(void)
41 43
42 if (!cmma_flag) 44 if (!cmma_flag)
43 return; 45 return;
46 /*
47 * Disable CMM for dump, otherwise the tprot based memory
48 * detection can fail because of unstable pages.
49 */
50 if (OLDMEM_BASE || ipl_info.type == IPL_TYPE_FCP_DUMP) {
51 cmma_flag = 0;
52 return;
53 }
44 asm volatile( 54 asm volatile(
45 " .insn rrf,0xb9ab0000,%1,%1,0,0\n" 55 " .insn rrf,0xb9ab0000,%1,%1,0,0\n"
46 "0: la %0,0\n" 56 "0: la %0,0\n"
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index 3584ed9b20a1..796c9320c709 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -17,6 +17,7 @@
17#include <linux/quicklist.h> 17#include <linux/quicklist.h>
18#include <linux/rcupdate.h> 18#include <linux/rcupdate.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/swapops.h>
20 21
21#include <asm/pgtable.h> 22#include <asm/pgtable.h>
22#include <asm/pgalloc.h> 23#include <asm/pgalloc.h>
@@ -594,6 +595,82 @@ unsigned long gmap_fault(unsigned long address, struct gmap *gmap)
594} 595}
595EXPORT_SYMBOL_GPL(gmap_fault); 596EXPORT_SYMBOL_GPL(gmap_fault);
596 597
598static void gmap_zap_swap_entry(swp_entry_t entry, struct mm_struct *mm)
599{
600 if (!non_swap_entry(entry))
601 dec_mm_counter(mm, MM_SWAPENTS);
602 else if (is_migration_entry(entry)) {
603 struct page *page = migration_entry_to_page(entry);
604
605 if (PageAnon(page))
606 dec_mm_counter(mm, MM_ANONPAGES);
607 else
608 dec_mm_counter(mm, MM_FILEPAGES);
609 }
610 free_swap_and_cache(entry);
611}
612
613/**
614 * The mm->mmap_sem lock must be held
615 */
616static void gmap_zap_unused(struct mm_struct *mm, unsigned long address)
617{
618 unsigned long ptev, pgstev;
619 spinlock_t *ptl;
620 pgste_t pgste;
621 pte_t *ptep, pte;
622
623 ptep = get_locked_pte(mm, address, &ptl);
624 if (unlikely(!ptep))
625 return;
626 pte = *ptep;
627 if (!pte_swap(pte))
628 goto out_pte;
629 /* Zap unused and logically-zero pages */
630 pgste = pgste_get_lock(ptep);
631 pgstev = pgste_val(pgste);
632 ptev = pte_val(pte);
633 if (((pgstev & _PGSTE_GPS_USAGE_MASK) == _PGSTE_GPS_USAGE_UNUSED) ||
634 ((pgstev & _PGSTE_GPS_ZERO) && (ptev & _PAGE_INVALID))) {
635 gmap_zap_swap_entry(pte_to_swp_entry(pte), mm);
636 pte_clear(mm, address, ptep);
637 }
638 pgste_set_unlock(ptep, pgste);
639out_pte:
640 pte_unmap_unlock(*ptep, ptl);
641}
642
643/*
644 * this function is assumed to be called with mmap_sem held
645 */
646void __gmap_zap(unsigned long address, struct gmap *gmap)
647{
648 unsigned long *table, *segment_ptr;
649 unsigned long segment, pgstev, ptev;
650 struct gmap_pgtable *mp;
651 struct page *page;
652
653 segment_ptr = gmap_table_walk(address, gmap);
654 if (IS_ERR(segment_ptr))
655 return;
656 segment = *segment_ptr;
657 if (segment & _SEGMENT_ENTRY_INVALID)
658 return;
659 page = pfn_to_page(segment >> PAGE_SHIFT);
660 mp = (struct gmap_pgtable *) page->index;
661 address = mp->vmaddr | (address & ~PMD_MASK);
662 /* Page table is present */
663 table = (unsigned long *)(segment & _SEGMENT_ENTRY_ORIGIN);
664 table = table + ((address >> 12) & 0xff);
665 pgstev = table[PTRS_PER_PTE];
666 ptev = table[0];
667 /* quick check, checked again with locks held */
668 if (((pgstev & _PGSTE_GPS_USAGE_MASK) == _PGSTE_GPS_USAGE_UNUSED) ||
669 ((pgstev & _PGSTE_GPS_ZERO) && (ptev & _PAGE_INVALID)))
670 gmap_zap_unused(gmap->mm, address);
671}
672EXPORT_SYMBOL_GPL(__gmap_zap);
673
597void gmap_discard(unsigned long from, unsigned long to, struct gmap *gmap) 674void gmap_discard(unsigned long from, unsigned long to, struct gmap *gmap)
598{ 675{
599 676
@@ -671,7 +748,7 @@ EXPORT_SYMBOL_GPL(gmap_unregister_ipte_notifier);
671/** 748/**
672 * gmap_ipte_notify - mark a range of ptes for invalidation notification 749 * gmap_ipte_notify - mark a range of ptes for invalidation notification
673 * @gmap: pointer to guest mapping meta data structure 750 * @gmap: pointer to guest mapping meta data structure
674 * @address: virtual address in the guest address space 751 * @start: virtual address in the guest address space
675 * @len: size of area 752 * @len: size of area
676 * 753 *
677 * Returns 0 if for each page in the given range a gmap mapping exists and 754 * Returns 0 if for each page in the given range a gmap mapping exists and
@@ -725,13 +802,12 @@ EXPORT_SYMBOL_GPL(gmap_ipte_notify);
725/** 802/**
726 * gmap_do_ipte_notify - call all invalidation callbacks for a specific pte. 803 * gmap_do_ipte_notify - call all invalidation callbacks for a specific pte.
727 * @mm: pointer to the process mm_struct 804 * @mm: pointer to the process mm_struct
728 * @addr: virtual address in the process address space
729 * @pte: pointer to the page table entry 805 * @pte: pointer to the page table entry
730 * 806 *
731 * This function is assumed to be called with the page table lock held 807 * This function is assumed to be called with the page table lock held
732 * for the pte to notify. 808 * for the pte to notify.
733 */ 809 */
734void gmap_do_ipte_notify(struct mm_struct *mm, unsigned long addr, pte_t *pte) 810void gmap_do_ipte_notify(struct mm_struct *mm, pte_t *pte)
735{ 811{
736 unsigned long segment_offset; 812 unsigned long segment_offset;
737 struct gmap_notifier *nb; 813 struct gmap_notifier *nb;
@@ -802,6 +878,78 @@ static inline void page_table_free_pgste(unsigned long *table)
802 __free_page(page); 878 __free_page(page);
803} 879}
804 880
881static inline unsigned long page_table_reset_pte(struct mm_struct *mm,
882 pmd_t *pmd, unsigned long addr, unsigned long end)
883{
884 pte_t *start_pte, *pte;
885 spinlock_t *ptl;
886 pgste_t pgste;
887
888 start_pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
889 pte = start_pte;
890 do {
891 pgste = pgste_get_lock(pte);
892 pgste_val(pgste) &= ~_PGSTE_GPS_USAGE_MASK;
893 pgste_set_unlock(pte, pgste);
894 } while (pte++, addr += PAGE_SIZE, addr != end);
895 pte_unmap_unlock(start_pte, ptl);
896
897 return addr;
898}
899
900static inline unsigned long page_table_reset_pmd(struct mm_struct *mm,
901 pud_t *pud, unsigned long addr, unsigned long end)
902{
903 unsigned long next;
904 pmd_t *pmd;
905
906 pmd = pmd_offset(pud, addr);
907 do {
908 next = pmd_addr_end(addr, end);
909 if (pmd_none_or_clear_bad(pmd))
910 continue;
911 next = page_table_reset_pte(mm, pmd, addr, next);
912 } while (pmd++, addr = next, addr != end);
913
914 return addr;
915}
916
917static inline unsigned long page_table_reset_pud(struct mm_struct *mm,
918 pgd_t *pgd, unsigned long addr, unsigned long end)
919{
920 unsigned long next;
921 pud_t *pud;
922
923 pud = pud_offset(pgd, addr);
924 do {
925 next = pud_addr_end(addr, end);
926 if (pud_none_or_clear_bad(pud))
927 continue;
928 next = page_table_reset_pmd(mm, pud, addr, next);
929 } while (pud++, addr = next, addr != end);
930
931 return addr;
932}
933
934void page_table_reset_pgste(struct mm_struct *mm,
935 unsigned long start, unsigned long end)
936{
937 unsigned long addr, next;
938 pgd_t *pgd;
939
940 addr = start;
941 down_read(&mm->mmap_sem);
942 pgd = pgd_offset(mm, addr);
943 do {
944 next = pgd_addr_end(addr, end);
945 if (pgd_none_or_clear_bad(pgd))
946 continue;
947 next = page_table_reset_pud(mm, pgd, addr, next);
948 } while (pgd++, addr = next, addr != end);
949 up_read(&mm->mmap_sem);
950}
951EXPORT_SYMBOL(page_table_reset_pgste);
952
805int set_guest_storage_key(struct mm_struct *mm, unsigned long addr, 953int set_guest_storage_key(struct mm_struct *mm, unsigned long addr,
806 unsigned long key, bool nq) 954 unsigned long key, bool nq)
807{ 955{
@@ -1248,7 +1396,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
1248{ 1396{
1249 struct list_head *lh = (struct list_head *) pgtable; 1397 struct list_head *lh = (struct list_head *) pgtable;
1250 1398
1251 assert_spin_locked(&mm->page_table_lock); 1399 assert_spin_locked(pmd_lockptr(mm, pmdp));
1252 1400
1253 /* FIFO */ 1401 /* FIFO */
1254 if (!pmd_huge_pte(mm, pmdp)) 1402 if (!pmd_huge_pte(mm, pmdp))
@@ -1264,7 +1412,7 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
1264 pgtable_t pgtable; 1412 pgtable_t pgtable;
1265 pte_t *ptep; 1413 pte_t *ptep;
1266 1414
1267 assert_spin_locked(&mm->page_table_lock); 1415 assert_spin_locked(pmd_lockptr(mm, pmdp));
1268 1416
1269 /* FIFO */ 1417 /* FIFO */
1270 pgtable = pmd_huge_pte(mm, pmdp); 1418 pgtable = pmd_huge_pte(mm, pmdp);
diff --git a/arch/s390/pci/pci_debug.c b/arch/s390/pci/pci_debug.c
index 75c69b402e05..c5c66840ac00 100644
--- a/arch/s390/pci/pci_debug.c
+++ b/arch/s390/pci/pci_debug.c
@@ -139,7 +139,7 @@ void zpci_debug_exit_device(struct zpci_dev *zdev)
139int __init zpci_debug_init(void) 139int __init zpci_debug_init(void)
140{ 140{
141 /* event trace buffer */ 141 /* event trace buffer */
142 pci_debug_msg_id = debug_register("pci_msg", 16, 1, 16 * sizeof(long)); 142 pci_debug_msg_id = debug_register("pci_msg", 8, 1, 8 * sizeof(long));
143 if (!pci_debug_msg_id) 143 if (!pci_debug_msg_id)
144 return -EINVAL; 144 return -EINVAL;
145 debug_register_view(pci_debug_msg_id, &debug_sprintf_view); 145 debug_register_view(pci_debug_msg_id, &debug_sprintf_view);
diff --git a/arch/s390/pci/pci_dma.c b/arch/s390/pci/pci_dma.c
index 60c11a629d96..f91c03119804 100644
--- a/arch/s390/pci/pci_dma.c
+++ b/arch/s390/pci/pci_dma.c
@@ -206,11 +206,13 @@ static void dma_cleanup_tables(struct zpci_dev *zdev)
206 zdev->dma_table = NULL; 206 zdev->dma_table = NULL;
207} 207}
208 208
209static unsigned long __dma_alloc_iommu(struct zpci_dev *zdev, unsigned long start, 209static unsigned long __dma_alloc_iommu(struct zpci_dev *zdev,
210 int size) 210 unsigned long start, int size)
211{ 211{
212 unsigned long boundary_size = 0x1000000; 212 unsigned long boundary_size;
213 213
214 boundary_size = ALIGN(dma_get_seg_boundary(&zdev->pdev->dev) + 1,
215 PAGE_SIZE) >> PAGE_SHIFT;
214 return iommu_area_alloc(zdev->iommu_bitmap, zdev->iommu_pages, 216 return iommu_area_alloc(zdev->iommu_bitmap, zdev->iommu_pages,
215 start, size, 0, boundary_size, 0); 217 start, size, 0, boundary_size, 0);
216} 218}
diff --git a/arch/score/include/asm/Kbuild b/arch/score/include/asm/Kbuild
index 146b9d5e89f8..4630cf217b5b 100644
--- a/arch/score/include/asm/Kbuild
+++ b/arch/score/include/asm/Kbuild
@@ -1,10 +1,11 @@
1 1
2header-y += 2header-y +=
3 3
4
4generic-y += barrier.h 5generic-y += barrier.h
5generic-y += clkdev.h 6generic-y += clkdev.h
6generic-y += hash.h 7generic-y += hash.h
8generic-y += mcs_spinlock.h
9generic-y += preempt.h
7generic-y += trace_clock.h 10generic-y += trace_clock.h
8generic-y += xor.h 11generic-y += xor.h
9generic-y += preempt.h
10
diff --git a/arch/sh/include/asm/Kbuild b/arch/sh/include/asm/Kbuild
index 0cd7198a4524..c19e47dacb31 100644
--- a/arch/sh/include/asm/Kbuild
+++ b/arch/sh/include/asm/Kbuild
@@ -8,18 +8,21 @@ generic-y += emergency-restart.h
8generic-y += errno.h 8generic-y += errno.h
9generic-y += exec.h 9generic-y += exec.h
10generic-y += fcntl.h 10generic-y += fcntl.h
11generic-y += hash.h
11generic-y += ioctl.h 12generic-y += ioctl.h
12generic-y += ipcbuf.h 13generic-y += ipcbuf.h
13generic-y += irq_regs.h 14generic-y += irq_regs.h
14generic-y += kvm_para.h 15generic-y += kvm_para.h
15generic-y += local.h 16generic-y += local.h
16generic-y += local64.h 17generic-y += local64.h
18generic-y += mcs_spinlock.h
19generic-y += mman.h
20generic-y += msgbuf.h
17generic-y += param.h 21generic-y += param.h
18generic-y += parport.h 22generic-y += parport.h
19generic-y += percpu.h 23generic-y += percpu.h
20generic-y += poll.h 24generic-y += poll.h
21generic-y += mman.h 25generic-y += preempt.h
22generic-y += msgbuf.h
23generic-y += resource.h 26generic-y += resource.h
24generic-y += scatterlist.h 27generic-y += scatterlist.h
25generic-y += sembuf.h 28generic-y += sembuf.h
@@ -34,5 +37,3 @@ generic-y += termios.h
34generic-y += trace_clock.h 37generic-y += trace_clock.h
35generic-y += ucontext.h 38generic-y += ucontext.h
36generic-y += xor.h 39generic-y += xor.h
37generic-y += preempt.h
38generic-y += hash.h
diff --git a/arch/sh/include/cpu-sh2/cpu/cache.h b/arch/sh/include/cpu-sh2/cpu/cache.h
index 673515bc4135..aa1b2b9088a7 100644
--- a/arch/sh/include/cpu-sh2/cpu/cache.h
+++ b/arch/sh/include/cpu-sh2/cpu/cache.h
@@ -18,7 +18,7 @@
18#define SH_CACHE_ASSOC 8 18#define SH_CACHE_ASSOC 8
19 19
20#if defined(CONFIG_CPU_SUBTYPE_SH7619) 20#if defined(CONFIG_CPU_SUBTYPE_SH7619)
21#define CCR 0xffffffec 21#define SH_CCR 0xffffffec
22 22
23#define CCR_CACHE_CE 0x01 /* Cache enable */ 23#define CCR_CACHE_CE 0x01 /* Cache enable */
24#define CCR_CACHE_WT 0x02 /* CCR[bit1=1,bit2=1] */ 24#define CCR_CACHE_WT 0x02 /* CCR[bit1=1,bit2=1] */
diff --git a/arch/sh/include/cpu-sh2a/cpu/cache.h b/arch/sh/include/cpu-sh2a/cpu/cache.h
index defb0baa5a06..b27ce92cb600 100644
--- a/arch/sh/include/cpu-sh2a/cpu/cache.h
+++ b/arch/sh/include/cpu-sh2a/cpu/cache.h
@@ -17,8 +17,8 @@
17#define SH_CACHE_COMBINED 4 17#define SH_CACHE_COMBINED 4
18#define SH_CACHE_ASSOC 8 18#define SH_CACHE_ASSOC 8
19 19
20#define CCR 0xfffc1000 /* CCR1 */ 20#define SH_CCR 0xfffc1000 /* CCR1 */
21#define CCR2 0xfffc1004 21#define SH_CCR2 0xfffc1004
22 22
23/* 23/*
24 * Most of the SH-2A CCR1 definitions resemble the SH-4 ones. All others not 24 * Most of the SH-2A CCR1 definitions resemble the SH-4 ones. All others not
diff --git a/arch/sh/include/cpu-sh3/cpu/cache.h b/arch/sh/include/cpu-sh3/cpu/cache.h
index bee2d81c56bf..29700fd88c75 100644
--- a/arch/sh/include/cpu-sh3/cpu/cache.h
+++ b/arch/sh/include/cpu-sh3/cpu/cache.h
@@ -17,7 +17,7 @@
17#define SH_CACHE_COMBINED 4 17#define SH_CACHE_COMBINED 4
18#define SH_CACHE_ASSOC 8 18#define SH_CACHE_ASSOC 8
19 19
20#define CCR 0xffffffec /* Address of Cache Control Register */ 20#define SH_CCR 0xffffffec /* Address of Cache Control Register */
21 21
22#define CCR_CACHE_CE 0x01 /* Cache Enable */ 22#define CCR_CACHE_CE 0x01 /* Cache Enable */
23#define CCR_CACHE_WT 0x02 /* Write-Through (for P0,U0,P3) (else writeback) */ 23#define CCR_CACHE_WT 0x02 /* Write-Through (for P0,U0,P3) (else writeback) */
diff --git a/arch/sh/include/cpu-sh4/cpu/cache.h b/arch/sh/include/cpu-sh4/cpu/cache.h
index 7bfb9e8b069c..92c4cd119b66 100644
--- a/arch/sh/include/cpu-sh4/cpu/cache.h
+++ b/arch/sh/include/cpu-sh4/cpu/cache.h
@@ -17,7 +17,7 @@
17#define SH_CACHE_COMBINED 4 17#define SH_CACHE_COMBINED 4
18#define SH_CACHE_ASSOC 8 18#define SH_CACHE_ASSOC 8
19 19
20#define CCR 0xff00001c /* Address of Cache Control Register */ 20#define SH_CCR 0xff00001c /* Address of Cache Control Register */
21#define CCR_CACHE_OCE 0x0001 /* Operand Cache Enable */ 21#define CCR_CACHE_OCE 0x0001 /* Operand Cache Enable */
22#define CCR_CACHE_WT 0x0002 /* Write-Through (for P0,U0,P3) (else writeback)*/ 22#define CCR_CACHE_WT 0x0002 /* Write-Through (for P0,U0,P3) (else writeback)*/
23#define CCR_CACHE_CB 0x0004 /* Copy-Back (for P1) (else writethrough) */ 23#define CCR_CACHE_CB 0x0004 /* Copy-Back (for P1) (else writethrough) */
diff --git a/arch/sh/kernel/cpu/init.c b/arch/sh/kernel/cpu/init.c
index ecf83cd158dc..0d7360d549c1 100644
--- a/arch/sh/kernel/cpu/init.c
+++ b/arch/sh/kernel/cpu/init.c
@@ -112,7 +112,7 @@ static void cache_init(void)
112 unsigned long ccr, flags; 112 unsigned long ccr, flags;
113 113
114 jump_to_uncached(); 114 jump_to_uncached();
115 ccr = __raw_readl(CCR); 115 ccr = __raw_readl(SH_CCR);
116 116
117 /* 117 /*
118 * At this point we don't know whether the cache is enabled or not - a 118 * At this point we don't know whether the cache is enabled or not - a
@@ -189,7 +189,7 @@ static void cache_init(void)
189 189
190 l2_cache_init(); 190 l2_cache_init();
191 191
192 __raw_writel(flags, CCR); 192 __raw_writel(flags, SH_CCR);
193 back_to_cached(); 193 back_to_cached();
194} 194}
195#else 195#else
diff --git a/arch/sh/kernel/idle.c b/arch/sh/kernel/idle.c
index 2ea4483fd722..be616ee0cf87 100644
--- a/arch/sh/kernel/idle.c
+++ b/arch/sh/kernel/idle.c
@@ -16,7 +16,6 @@
16#include <linux/thread_info.h> 16#include <linux/thread_info.h>
17#include <linux/irqflags.h> 17#include <linux/irqflags.h>
18#include <linux/smp.h> 18#include <linux/smp.h>
19#include <linux/cpuidle.h>
20#include <linux/atomic.h> 19#include <linux/atomic.h>
21#include <asm/pgalloc.h> 20#include <asm/pgalloc.h>
22#include <asm/smp.h> 21#include <asm/smp.h>
@@ -40,8 +39,7 @@ void arch_cpu_idle_dead(void)
40 39
41void arch_cpu_idle(void) 40void arch_cpu_idle(void)
42{ 41{
43 if (cpuidle_idle_call()) 42 sh_idle();
44 sh_idle();
45} 43}
46 44
47void __init select_idle_routine(void) 45void __init select_idle_routine(void)
diff --git a/arch/sh/mm/cache-debugfs.c b/arch/sh/mm/cache-debugfs.c
index 115725198038..777e50f33c00 100644
--- a/arch/sh/mm/cache-debugfs.c
+++ b/arch/sh/mm/cache-debugfs.c
@@ -36,7 +36,7 @@ static int cache_seq_show(struct seq_file *file, void *iter)
36 */ 36 */
37 jump_to_uncached(); 37 jump_to_uncached();
38 38
39 ccr = __raw_readl(CCR); 39 ccr = __raw_readl(SH_CCR);
40 if ((ccr & CCR_CACHE_ENABLE) == 0) { 40 if ((ccr & CCR_CACHE_ENABLE) == 0) {
41 back_to_cached(); 41 back_to_cached();
42 42
diff --git a/arch/sh/mm/cache-sh2.c b/arch/sh/mm/cache-sh2.c
index defcf719f2e8..a74259f2f981 100644
--- a/arch/sh/mm/cache-sh2.c
+++ b/arch/sh/mm/cache-sh2.c
@@ -63,9 +63,9 @@ static void sh2__flush_invalidate_region(void *start, int size)
63 local_irq_save(flags); 63 local_irq_save(flags);
64 jump_to_uncached(); 64 jump_to_uncached();
65 65
66 ccr = __raw_readl(CCR); 66 ccr = __raw_readl(SH_CCR);
67 ccr |= CCR_CACHE_INVALIDATE; 67 ccr |= CCR_CACHE_INVALIDATE;
68 __raw_writel(ccr, CCR); 68 __raw_writel(ccr, SH_CCR);
69 69
70 back_to_cached(); 70 back_to_cached();
71 local_irq_restore(flags); 71 local_irq_restore(flags);
diff --git a/arch/sh/mm/cache-sh2a.c b/arch/sh/mm/cache-sh2a.c
index 949e2d3138a0..ee87d081259b 100644
--- a/arch/sh/mm/cache-sh2a.c
+++ b/arch/sh/mm/cache-sh2a.c
@@ -134,7 +134,8 @@ static void sh2a__flush_invalidate_region(void *start, int size)
134 134
135 /* If there are too many pages then just blow the cache */ 135 /* If there are too many pages then just blow the cache */
136 if (((end - begin) >> PAGE_SHIFT) >= MAX_OCACHE_PAGES) { 136 if (((end - begin) >> PAGE_SHIFT) >= MAX_OCACHE_PAGES) {
137 __raw_writel(__raw_readl(CCR) | CCR_OCACHE_INVALIDATE, CCR); 137 __raw_writel(__raw_readl(SH_CCR) | CCR_OCACHE_INVALIDATE,
138 SH_CCR);
138 } else { 139 } else {
139 for (v = begin; v < end; v += L1_CACHE_BYTES) 140 for (v = begin; v < end; v += L1_CACHE_BYTES)
140 sh2a_invalidate_line(CACHE_OC_ADDRESS_ARRAY, v); 141 sh2a_invalidate_line(CACHE_OC_ADDRESS_ARRAY, v);
@@ -167,7 +168,8 @@ static void sh2a_flush_icache_range(void *args)
167 /* I-Cache invalidate */ 168 /* I-Cache invalidate */
168 /* If there are too many pages then just blow the cache */ 169 /* If there are too many pages then just blow the cache */
169 if (((end - start) >> PAGE_SHIFT) >= MAX_ICACHE_PAGES) { 170 if (((end - start) >> PAGE_SHIFT) >= MAX_ICACHE_PAGES) {
170 __raw_writel(__raw_readl(CCR) | CCR_ICACHE_INVALIDATE, CCR); 171 __raw_writel(__raw_readl(SH_CCR) | CCR_ICACHE_INVALIDATE,
172 SH_CCR);
171 } else { 173 } else {
172 for (v = start; v < end; v += L1_CACHE_BYTES) 174 for (v = start; v < end; v += L1_CACHE_BYTES)
173 sh2a_invalidate_line(CACHE_IC_ADDRESS_ARRAY, v); 175 sh2a_invalidate_line(CACHE_IC_ADDRESS_ARRAY, v);
diff --git a/arch/sh/mm/cache-sh4.c b/arch/sh/mm/cache-sh4.c
index 0e529285b28d..51d8f7f31d1d 100644
--- a/arch/sh/mm/cache-sh4.c
+++ b/arch/sh/mm/cache-sh4.c
@@ -133,9 +133,9 @@ static void flush_icache_all(void)
133 jump_to_uncached(); 133 jump_to_uncached();
134 134
135 /* Flush I-cache */ 135 /* Flush I-cache */
136 ccr = __raw_readl(CCR); 136 ccr = __raw_readl(SH_CCR);
137 ccr |= CCR_CACHE_ICI; 137 ccr |= CCR_CACHE_ICI;
138 __raw_writel(ccr, CCR); 138 __raw_writel(ccr, SH_CCR);
139 139
140 /* 140 /*
141 * back_to_cached() will take care of the barrier for us, don't add 141 * back_to_cached() will take care of the barrier for us, don't add
diff --git a/arch/sh/mm/cache-shx3.c b/arch/sh/mm/cache-shx3.c
index c0adbee97b5f..24c58b7dc022 100644
--- a/arch/sh/mm/cache-shx3.c
+++ b/arch/sh/mm/cache-shx3.c
@@ -19,7 +19,7 @@ void __init shx3_cache_init(void)
19{ 19{
20 unsigned int ccr; 20 unsigned int ccr;
21 21
22 ccr = __raw_readl(CCR); 22 ccr = __raw_readl(SH_CCR);
23 23
24 /* 24 /*
25 * If we've got cache aliases, resolve them in hardware. 25 * If we've got cache aliases, resolve them in hardware.
@@ -40,5 +40,5 @@ void __init shx3_cache_init(void)
40 ccr |= CCR_CACHE_IBE; 40 ccr |= CCR_CACHE_IBE;
41#endif 41#endif
42 42
43 writel_uncached(ccr, CCR); 43 writel_uncached(ccr, SH_CCR);
44} 44}
diff --git a/arch/sh/mm/cache.c b/arch/sh/mm/cache.c
index 616966a96cba..097c2cdd117f 100644
--- a/arch/sh/mm/cache.c
+++ b/arch/sh/mm/cache.c
@@ -285,8 +285,8 @@ void __init cpu_cache_init(void)
285{ 285{
286 unsigned int cache_disabled = 0; 286 unsigned int cache_disabled = 0;
287 287
288#ifdef CCR 288#ifdef SH_CCR
289 cache_disabled = !(__raw_readl(CCR) & CCR_CACHE_ENABLE); 289 cache_disabled = !(__raw_readl(SH_CCR) & CCR_CACHE_ENABLE);
290#endif 290#endif
291 291
292 compute_alias(&boot_cpu_data.icache); 292 compute_alias(&boot_cpu_data.icache);
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index c51efdcd07a2..7d8b7e94b93b 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -27,7 +27,7 @@ config SPARC
27 select RTC_DRV_M48T59 27 select RTC_DRV_M48T59
28 select HAVE_DMA_ATTRS 28 select HAVE_DMA_ATTRS
29 select HAVE_DMA_API_DEBUG 29 select HAVE_DMA_API_DEBUG
30 select HAVE_ARCH_JUMP_LABEL 30 select HAVE_ARCH_JUMP_LABEL if SPARC64
31 select GENERIC_IRQ_SHOW 31 select GENERIC_IRQ_SHOW
32 select ARCH_WANT_IPC_PARSE_VERSION 32 select ARCH_WANT_IPC_PARSE_VERSION
33 select GENERIC_PCI_IOMAP 33 select GENERIC_PCI_IOMAP
diff --git a/arch/sparc/include/asm/Kbuild b/arch/sparc/include/asm/Kbuild
index 4b60a0c325ec..a45821818003 100644
--- a/arch/sparc/include/asm/Kbuild
+++ b/arch/sparc/include/asm/Kbuild
@@ -6,15 +6,16 @@ generic-y += cputime.h
6generic-y += div64.h 6generic-y += div64.h
7generic-y += emergency-restart.h 7generic-y += emergency-restart.h
8generic-y += exec.h 8generic-y += exec.h
9generic-y += linkage.h 9generic-y += hash.h
10generic-y += local64.h
11generic-y += mutex.h
12generic-y += irq_regs.h 10generic-y += irq_regs.h
11generic-y += linkage.h
13generic-y += local.h 12generic-y += local.h
13generic-y += local64.h
14generic-y += mcs_spinlock.h
14generic-y += module.h 15generic-y += module.h
16generic-y += mutex.h
17generic-y += preempt.h
15generic-y += serial.h 18generic-y += serial.h
16generic-y += trace_clock.h 19generic-y += trace_clock.h
17generic-y += types.h 20generic-y += types.h
18generic-y += word-at-a-time.h 21generic-y += word-at-a-time.h
19generic-y += preempt.h
20generic-y += hash.h
diff --git a/arch/sparc/include/asm/smp_64.h b/arch/sparc/include/asm/smp_64.h
index dd3bef4b9896..05710393959f 100644
--- a/arch/sparc/include/asm/smp_64.h
+++ b/arch/sparc/include/asm/smp_64.h
@@ -32,7 +32,6 @@
32 32
33DECLARE_PER_CPU(cpumask_t, cpu_sibling_map); 33DECLARE_PER_CPU(cpumask_t, cpu_sibling_map);
34extern cpumask_t cpu_core_map[NR_CPUS]; 34extern cpumask_t cpu_core_map[NR_CPUS];
35extern int sparc64_multi_core;
36 35
37extern void arch_send_call_function_single_ipi(int cpu); 36extern void arch_send_call_function_single_ipi(int cpu);
38extern void arch_send_call_function_ipi_mask(const struct cpumask *mask); 37extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
diff --git a/arch/sparc/include/asm/topology_64.h b/arch/sparc/include/asm/topology_64.h
index 1754390a426f..a2d10fc64faf 100644
--- a/arch/sparc/include/asm/topology_64.h
+++ b/arch/sparc/include/asm/topology_64.h
@@ -42,8 +42,6 @@ static inline int pcibus_to_node(struct pci_bus *pbus)
42#define topology_core_id(cpu) (cpu_data(cpu).core_id) 42#define topology_core_id(cpu) (cpu_data(cpu).core_id)
43#define topology_core_cpumask(cpu) (&cpu_core_map[cpu]) 43#define topology_core_cpumask(cpu) (&cpu_core_map[cpu])
44#define topology_thread_cpumask(cpu) (&per_cpu(cpu_sibling_map, cpu)) 44#define topology_thread_cpumask(cpu) (&per_cpu(cpu_sibling_map, cpu))
45#define mc_capable() (sparc64_multi_core)
46#define smt_capable() (sparc64_multi_core)
47#endif /* CONFIG_SMP */ 45#endif /* CONFIG_SMP */
48 46
49extern cpumask_t cpu_core_map[NR_CPUS]; 47extern cpumask_t cpu_core_map[NR_CPUS];
diff --git a/arch/sparc/kernel/mdesc.c b/arch/sparc/kernel/mdesc.c
index b90bf23e3aab..a1a4400d4025 100644
--- a/arch/sparc/kernel/mdesc.c
+++ b/arch/sparc/kernel/mdesc.c
@@ -896,10 +896,6 @@ void mdesc_fill_in_cpu_data(cpumask_t *mask)
896 896
897 mdesc_iterate_over_cpus(fill_in_one_cpu, NULL, mask); 897 mdesc_iterate_over_cpus(fill_in_one_cpu, NULL, mask);
898 898
899#ifdef CONFIG_SMP
900 sparc64_multi_core = 1;
901#endif
902
903 hp = mdesc_grab(); 899 hp = mdesc_grab();
904 900
905 set_core_ids(hp); 901 set_core_ids(hp);
diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
index 32a280ec38c1..d7b4967f8fa6 100644
--- a/arch/sparc/kernel/process_64.c
+++ b/arch/sparc/kernel/process_64.c
@@ -58,9 +58,12 @@ void arch_cpu_idle(void)
58{ 58{
59 if (tlb_type != hypervisor) { 59 if (tlb_type != hypervisor) {
60 touch_nmi_watchdog(); 60 touch_nmi_watchdog();
61 local_irq_enable();
61 } else { 62 } else {
62 unsigned long pstate; 63 unsigned long pstate;
63 64
65 local_irq_enable();
66
64 /* The sun4v sleeping code requires that we have PSTATE.IE cleared over 67 /* The sun4v sleeping code requires that we have PSTATE.IE cleared over
65 * the cpu sleep hypervisor call. 68 * the cpu sleep hypervisor call.
66 */ 69 */
@@ -82,7 +85,6 @@ void arch_cpu_idle(void)
82 : "=&r" (pstate) 85 : "=&r" (pstate)
83 : "i" (PSTATE_IE)); 86 : "i" (PSTATE_IE));
84 } 87 }
85 local_irq_enable();
86} 88}
87 89
88#ifdef CONFIG_HOTPLUG_CPU 90#ifdef CONFIG_HOTPLUG_CPU
diff --git a/arch/sparc/kernel/prom_64.c b/arch/sparc/kernel/prom_64.c
index 6b39125eb927..9a690d39c01b 100644
--- a/arch/sparc/kernel/prom_64.c
+++ b/arch/sparc/kernel/prom_64.c
@@ -555,9 +555,6 @@ static void *fill_in_one_cpu(struct device_node *dp, int cpuid, int arg)
555 555
556 cpu_data(cpuid).core_id = portid + 1; 556 cpu_data(cpuid).core_id = portid + 1;
557 cpu_data(cpuid).proc_id = portid; 557 cpu_data(cpuid).proc_id = portid;
558#ifdef CONFIG_SMP
559 sparc64_multi_core = 1;
560#endif
561 } else { 558 } else {
562 cpu_data(cpuid).dcache_size = 559 cpu_data(cpuid).dcache_size =
563 of_getintprop_default(dp, "dcache-size", 16 * 1024); 560 of_getintprop_default(dp, "dcache-size", 16 * 1024);
diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
index b085311dcd0e..9781048161ab 100644
--- a/arch/sparc/kernel/smp_64.c
+++ b/arch/sparc/kernel/smp_64.c
@@ -53,8 +53,6 @@
53 53
54#include "cpumap.h" 54#include "cpumap.h"
55 55
56int sparc64_multi_core __read_mostly;
57
58DEFINE_PER_CPU(cpumask_t, cpu_sibling_map) = CPU_MASK_NONE; 56DEFINE_PER_CPU(cpumask_t, cpu_sibling_map) = CPU_MASK_NONE;
59cpumask_t cpu_core_map[NR_CPUS] __read_mostly = 57cpumask_t cpu_core_map[NR_CPUS] __read_mostly =
60 { [0 ... NR_CPUS-1] = CPU_MASK_NONE }; 58 { [0 ... NR_CPUS-1] = CPU_MASK_NONE };
diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
index 87729fff13b9..33a17e7b3ccd 100644
--- a/arch/sparc/kernel/syscalls.S
+++ b/arch/sparc/kernel/syscalls.S
@@ -189,7 +189,8 @@ linux_sparc_syscall32:
189 mov %i0, %l5 ! IEU1 189 mov %i0, %l5 ! IEU1
1905: call %l7 ! CTI Group brk forced 1905: call %l7 ! CTI Group brk forced
191 srl %i5, 0, %o5 ! IEU1 191 srl %i5, 0, %o5 ! IEU1
192 ba,a,pt %xcc, 3f 192 ba,pt %xcc, 3f
193 sra %o0, 0, %o0
193 194
194 /* Linux native system calls enter here... */ 195 /* Linux native system calls enter here... */
195 .align 32 196 .align 32
@@ -217,7 +218,6 @@ linux_sparc_syscall:
2173: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0] 2183: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
218ret_sys_call: 219ret_sys_call:
219 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3 220 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
220 sra %o0, 0, %o0
221 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2 221 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
222 sllx %g2, 32, %g2 222 sllx %g2, 32, %g2
223 223
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index 869023abe5a4..cfbe53c17b0d 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -14,6 +14,7 @@
14#include <linux/pagemap.h> 14#include <linux/pagemap.h>
15#include <linux/vmalloc.h> 15#include <linux/vmalloc.h>
16#include <linux/kdebug.h> 16#include <linux/kdebug.h>
17#include <linux/export.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/log2.h> 20#include <linux/log2.h>
@@ -62,6 +63,7 @@ extern unsigned long last_valid_pfn;
62static pgd_t *srmmu_swapper_pg_dir; 63static pgd_t *srmmu_swapper_pg_dir;
63 64
64const struct sparc32_cachetlb_ops *sparc32_cachetlb_ops; 65const struct sparc32_cachetlb_ops *sparc32_cachetlb_ops;
66EXPORT_SYMBOL(sparc32_cachetlb_ops);
65 67
66#ifdef CONFIG_SMP 68#ifdef CONFIG_SMP
67const struct sparc32_cachetlb_ops *local_ops; 69const struct sparc32_cachetlb_ops *local_ops;
diff --git a/arch/sparc/mm/tsb.c b/arch/sparc/mm/tsb.c
index 3b3a360b429a..f5d506fdddad 100644
--- a/arch/sparc/mm/tsb.c
+++ b/arch/sparc/mm/tsb.c
@@ -273,7 +273,7 @@ void __init pgtable_cache_init(void)
273 prom_halt(); 273 prom_halt();
274 } 274 }
275 275
276 for (i = 0; i < 8; i++) { 276 for (i = 0; i < ARRAY_SIZE(tsb_cache_names); i++) {
277 unsigned long size = 8192 << i; 277 unsigned long size = 8192 << i;
278 const char *name = tsb_cache_names[i]; 278 const char *name = tsb_cache_names[i];
279 279
diff --git a/arch/tile/include/asm/Kbuild b/arch/tile/include/asm/Kbuild
index 3793c75e45d9..0aa5675e7025 100644
--- a/arch/tile/include/asm/Kbuild
+++ b/arch/tile/include/asm/Kbuild
@@ -11,6 +11,7 @@ generic-y += errno.h
11generic-y += exec.h 11generic-y += exec.h
12generic-y += fb.h 12generic-y += fb.h
13generic-y += fcntl.h 13generic-y += fcntl.h
14generic-y += hash.h
14generic-y += hw_irq.h 15generic-y += hw_irq.h
15generic-y += ioctl.h 16generic-y += ioctl.h
16generic-y += ioctls.h 17generic-y += ioctls.h
@@ -18,12 +19,14 @@ generic-y += ipcbuf.h
18generic-y += irq_regs.h 19generic-y += irq_regs.h
19generic-y += local.h 20generic-y += local.h
20generic-y += local64.h 21generic-y += local64.h
22generic-y += mcs_spinlock.h
21generic-y += msgbuf.h 23generic-y += msgbuf.h
22generic-y += mutex.h 24generic-y += mutex.h
23generic-y += param.h 25generic-y += param.h
24generic-y += parport.h 26generic-y += parport.h
25generic-y += poll.h 27generic-y += poll.h
26generic-y += posix_types.h 28generic-y += posix_types.h
29generic-y += preempt.h
27generic-y += resource.h 30generic-y += resource.h
28generic-y += scatterlist.h 31generic-y += scatterlist.h
29generic-y += sembuf.h 32generic-y += sembuf.h
@@ -38,5 +41,3 @@ generic-y += termios.h
38generic-y += trace_clock.h 41generic-y += trace_clock.h
39generic-y += types.h 42generic-y += types.h
40generic-y += xor.h 43generic-y += xor.h
41generic-y += preempt.h
42generic-y += hash.h
diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild
index 88a330dcdede..a5e4b6068213 100644
--- a/arch/um/include/asm/Kbuild
+++ b/arch/um/include/asm/Kbuild
@@ -1,8 +1,28 @@
1generic-y += bug.h cputime.h device.h emergency-restart.h futex.h hardirq.h
2generic-y += hw_irq.h irq_regs.h kdebug.h percpu.h sections.h topology.h xor.h
3generic-y += ftrace.h pci.h io.h param.h delay.h mutex.h current.h exec.h
4generic-y += switch_to.h clkdev.h
5generic-y += trace_clock.h
6generic-y += preempt.h
7generic-y += hash.h
8generic-y += barrier.h 1generic-y += barrier.h
2generic-y += bug.h
3generic-y += clkdev.h
4generic-y += cputime.h
5generic-y += current.h
6generic-y += delay.h
7generic-y += device.h
8generic-y += emergency-restart.h
9generic-y += exec.h
10generic-y += ftrace.h
11generic-y += futex.h
12generic-y += hardirq.h
13generic-y += hash.h
14generic-y += hw_irq.h
15generic-y += io.h
16generic-y += irq_regs.h
17generic-y += kdebug.h
18generic-y += mcs_spinlock.h
19generic-y += mutex.h
20generic-y += param.h
21generic-y += pci.h
22generic-y += percpu.h
23generic-y += preempt.h
24generic-y += sections.h
25generic-y += switch_to.h
26generic-y += topology.h
27generic-y += trace_clock.h
28generic-y += xor.h
diff --git a/arch/unicore32/include/asm/Kbuild b/arch/unicore32/include/asm/Kbuild
index 3ef4f9d9bf5d..1e5fb872a4aa 100644
--- a/arch/unicore32/include/asm/Kbuild
+++ b/arch/unicore32/include/asm/Kbuild
@@ -16,6 +16,7 @@ generic-y += fcntl.h
16generic-y += ftrace.h 16generic-y += ftrace.h
17generic-y += futex.h 17generic-y += futex.h
18generic-y += hardirq.h 18generic-y += hardirq.h
19generic-y += hash.h
19generic-y += hw_irq.h 20generic-y += hw_irq.h
20generic-y += ioctl.h 21generic-y += ioctl.h
21generic-y += ioctls.h 22generic-y += ioctls.h
@@ -24,6 +25,7 @@ generic-y += irq_regs.h
24generic-y += kdebug.h 25generic-y += kdebug.h
25generic-y += kmap_types.h 26generic-y += kmap_types.h
26generic-y += local.h 27generic-y += local.h
28generic-y += mcs_spinlock.h
27generic-y += mman.h 29generic-y += mman.h
28generic-y += module.h 30generic-y += module.h
29generic-y += msgbuf.h 31generic-y += msgbuf.h
@@ -32,6 +34,7 @@ generic-y += parport.h
32generic-y += percpu.h 34generic-y += percpu.h
33generic-y += poll.h 35generic-y += poll.h
34generic-y += posix_types.h 36generic-y += posix_types.h
37generic-y += preempt.h
35generic-y += resource.h 38generic-y += resource.h
36generic-y += scatterlist.h 39generic-y += scatterlist.h
37generic-y += sections.h 40generic-y += sections.h
@@ -60,5 +63,3 @@ generic-y += unaligned.h
60generic-y += user.h 63generic-y += user.h
61generic-y += vga.h 64generic-y += vga.h
62generic-y += xor.h 65generic-y += xor.h
63generic-y += preempt.h
64generic-y += hash.h
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 940e50ebfafa..8453fe1342ea 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -444,6 +444,7 @@ config X86_INTEL_MID
444 bool "Intel MID platform support" 444 bool "Intel MID platform support"
445 depends on X86_32 445 depends on X86_32
446 depends on X86_EXTENDED_PLATFORM 446 depends on X86_EXTENDED_PLATFORM
447 depends on X86_PLATFORM_DEVICES
447 depends on PCI 448 depends on PCI
448 depends on PCI_GOANY 449 depends on PCI_GOANY
449 depends on X86_IO_APIC 450 depends on X86_IO_APIC
@@ -1051,9 +1052,9 @@ config MICROCODE_INTEL
1051 This options enables microcode patch loading support for Intel 1052 This options enables microcode patch loading support for Intel
1052 processors. 1053 processors.
1053 1054
1054 For latest news and information on obtaining all the required 1055 For the current Intel microcode data package go to
1055 Intel ingredients for this driver, check: 1056 <https://downloadcenter.intel.com> and search for
1056 <http://www.urbanmyth.org/microcode/>. 1057 'Linux Processor Microcode Data File'.
1057 1058
1058config MICROCODE_AMD 1059config MICROCODE_AMD
1059 bool "AMD microcode loading support" 1060 bool "AMD microcode loading support"
@@ -1584,6 +1585,20 @@ config EFI_STUB
1584 1585
1585 See Documentation/efi-stub.txt for more information. 1586 See Documentation/efi-stub.txt for more information.
1586 1587
1588config EFI_MIXED
1589 bool "EFI mixed-mode support"
1590 depends on EFI_STUB && X86_64
1591 ---help---
1592 Enabling this feature allows a 64-bit kernel to be booted
1593 on a 32-bit firmware, provided that your CPU supports 64-bit
1594 mode.
1595
1596 Note that it is not possible to boot a mixed-mode enabled
1597 kernel via the EFI boot stub - a bootloader that supports
1598 the EFI handover protocol must be used.
1599
1600 If unsure, say N.
1601
1587config SECCOMP 1602config SECCOMP
1588 def_bool y 1603 def_bool y
1589 prompt "Enable seccomp to safely compute untrusted bytecode" 1604 prompt "Enable seccomp to safely compute untrusted bytecode"
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index c026cca5602c..f3aaf231b4e5 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -341,10 +341,6 @@ config X86_USE_3DNOW
341 def_bool y 341 def_bool y
342 depends on (MCYRIXIII || MK7 || MGEODE_LX) && !UML 342 depends on (MCYRIXIII || MK7 || MGEODE_LX) && !UML
343 343
344config X86_OOSTORE
345 def_bool y
346 depends on (MWINCHIP3D || MWINCHIPC6) && MTRR
347
348# 344#
349# P6_NOPs are a relatively minor optimization that require a family >= 345# P6_NOPs are a relatively minor optimization that require a family >=
350# 6 processor, except that it is broken on certain VIA chips. 346# 6 processor, except that it is broken on certain VIA chips.
diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index 0f3621ed1db6..61bd2ad94281 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -81,6 +81,15 @@ config X86_PTDUMP
81 kernel. 81 kernel.
82 If in doubt, say "N" 82 If in doubt, say "N"
83 83
84config EFI_PGT_DUMP
85 bool "Dump the EFI pagetable"
86 depends on EFI && X86_PTDUMP
87 ---help---
88 Enable this if you want to dump the EFI page table before
89 enabling virtual mode. This can be used to debug miscellaneous
90 issues with the mapping of the EFI runtime regions into that
91 table.
92
84config DEBUG_RODATA 93config DEBUG_RODATA
85 bool "Write protect kernel read-only data structures" 94 bool "Write protect kernel read-only data structures"
86 default y 95 default y
@@ -184,6 +193,7 @@ config HAVE_MMIOTRACE_SUPPORT
184config X86_DECODER_SELFTEST 193config X86_DECODER_SELFTEST
185 bool "x86 instruction decoder selftest" 194 bool "x86 instruction decoder selftest"
186 depends on DEBUG_KERNEL && KPROBES 195 depends on DEBUG_KERNEL && KPROBES
196 depends on !COMPILE_TEST
187 ---help--- 197 ---help---
188 Perform x86 instruction decoder selftests at build time. 198 Perform x86 instruction decoder selftests at build time.
189 This option is useful for checking the sanity of x86 instruction 199 This option is useful for checking the sanity of x86 instruction
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index eeda43abed6e..3b9348a0c1a4 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -82,8 +82,8 @@ else
82 KBUILD_AFLAGS += -m64 82 KBUILD_AFLAGS += -m64
83 KBUILD_CFLAGS += -m64 83 KBUILD_CFLAGS += -m64
84 84
85 # Don't autogenerate MMX or SSE instructions 85 # Don't autogenerate traditional x87, MMX or SSE instructions
86 KBUILD_CFLAGS += -mno-mmx -mno-sse 86 KBUILD_CFLAGS += -mno-mmx -mno-sse -mno-80387 -mno-fp-ret-in-387
87 87
88 # Use -mpreferred-stack-boundary=3 if supported. 88 # Use -mpreferred-stack-boundary=3 if supported.
89 KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3) 89 KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)
@@ -152,6 +152,7 @@ cfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTI
152 152
153# does binutils support specific instructions? 153# does binutils support specific instructions?
154asinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1) 154asinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1)
155asinstr += $(call as-instr,crc32l %eax$(comma)%eax,-DCONFIG_AS_CRC32=1)
155avx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1) 156avx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1)
156avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1) 157avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
157 158
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 878df7e88cd4..abb9eba61b50 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -80,7 +80,7 @@ targets += voffset.h
80$(obj)/voffset.h: vmlinux FORCE 80$(obj)/voffset.h: vmlinux FORCE
81 $(call if_changed,voffset) 81 $(call if_changed,voffset)
82 82
83sed-zoffset := -e 's/^\([0-9a-fA-F]*\) . \(startup_32\|startup_64\|efi_pe_entry\|efi_stub_entry\|input_data\|_end\|z_.*\)$$/\#define ZO_\2 0x\1/p' 83sed-zoffset := -e 's/^\([0-9a-fA-F]*\) . \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|input_data\|_end\|z_.*\)$$/\#define ZO_\2 0x\1/p'
84 84
85quiet_cmd_zoffset = ZOFFSET $@ 85quiet_cmd_zoffset = ZOFFSET $@
86 cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@ 86 cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@
diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c
index 90a21f430117..4dbf967da50d 100644
--- a/arch/x86/boot/compressed/aslr.c
+++ b/arch/x86/boot/compressed/aslr.c
@@ -111,7 +111,7 @@ struct mem_vector {
111}; 111};
112 112
113#define MEM_AVOID_MAX 5 113#define MEM_AVOID_MAX 5
114struct mem_vector mem_avoid[MEM_AVOID_MAX]; 114static struct mem_vector mem_avoid[MEM_AVOID_MAX];
115 115
116static bool mem_contains(struct mem_vector *region, struct mem_vector *item) 116static bool mem_contains(struct mem_vector *region, struct mem_vector *item)
117{ 117{
@@ -180,7 +180,7 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,
180} 180}
181 181
182/* Does this memory vector overlap a known avoided area? */ 182/* Does this memory vector overlap a known avoided area? */
183bool mem_avoid_overlap(struct mem_vector *img) 183static bool mem_avoid_overlap(struct mem_vector *img)
184{ 184{
185 int i; 185 int i;
186 186
@@ -192,8 +192,9 @@ bool mem_avoid_overlap(struct mem_vector *img)
192 return false; 192 return false;
193} 193}
194 194
195unsigned long slots[CONFIG_RANDOMIZE_BASE_MAX_OFFSET / CONFIG_PHYSICAL_ALIGN]; 195static unsigned long slots[CONFIG_RANDOMIZE_BASE_MAX_OFFSET /
196unsigned long slot_max = 0; 196 CONFIG_PHYSICAL_ALIGN];
197static unsigned long slot_max;
197 198
198static void slots_append(unsigned long addr) 199static void slots_append(unsigned long addr)
199{ 200{
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index a7677babf946..1e6146137f8e 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -19,10 +19,272 @@
19 19
20static efi_system_table_t *sys_table; 20static efi_system_table_t *sys_table;
21 21
22static struct efi_config *efi_early;
23
24#define efi_call_early(f, ...) \
25 efi_early->call(efi_early->f, __VA_ARGS__);
26
27#define BOOT_SERVICES(bits) \
28static void setup_boot_services##bits(struct efi_config *c) \
29{ \
30 efi_system_table_##bits##_t *table; \
31 efi_boot_services_##bits##_t *bt; \
32 \
33 table = (typeof(table))sys_table; \
34 \
35 c->text_output = table->con_out; \
36 \
37 bt = (typeof(bt))(unsigned long)(table->boottime); \
38 \
39 c->allocate_pool = bt->allocate_pool; \
40 c->allocate_pages = bt->allocate_pages; \
41 c->get_memory_map = bt->get_memory_map; \
42 c->free_pool = bt->free_pool; \
43 c->free_pages = bt->free_pages; \
44 c->locate_handle = bt->locate_handle; \
45 c->handle_protocol = bt->handle_protocol; \
46 c->exit_boot_services = bt->exit_boot_services; \
47}
48BOOT_SERVICES(32);
49BOOT_SERVICES(64);
22 50
23#include "../../../../drivers/firmware/efi/efi-stub-helper.c" 51static void efi_printk(efi_system_table_t *, char *);
52static void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
53
54static efi_status_t
55__file_size32(void *__fh, efi_char16_t *filename_16,
56 void **handle, u64 *file_sz)
57{
58 efi_file_handle_32_t *h, *fh = __fh;
59 efi_file_info_t *info;
60 efi_status_t status;
61 efi_guid_t info_guid = EFI_FILE_INFO_ID;
62 u32 info_sz;
63
64 status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16,
65 EFI_FILE_MODE_READ, (u64)0);
66 if (status != EFI_SUCCESS) {
67 efi_printk(sys_table, "Failed to open file: ");
68 efi_char16_printk(sys_table, filename_16);
69 efi_printk(sys_table, "\n");
70 return status;
71 }
72
73 *handle = h;
74
75 info_sz = 0;
76 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
77 &info_sz, NULL);
78 if (status != EFI_BUFFER_TOO_SMALL) {
79 efi_printk(sys_table, "Failed to get file info size\n");
80 return status;
81 }
82
83grow:
84 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
85 info_sz, (void **)&info);
86 if (status != EFI_SUCCESS) {
87 efi_printk(sys_table, "Failed to alloc mem for file info\n");
88 return status;
89 }
90
91 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
92 &info_sz, info);
93 if (status == EFI_BUFFER_TOO_SMALL) {
94 efi_call_early(free_pool, info);
95 goto grow;
96 }
97
98 *file_sz = info->file_size;
99 efi_call_early(free_pool, info);
100
101 if (status != EFI_SUCCESS)
102 efi_printk(sys_table, "Failed to get initrd info\n");
103
104 return status;
105}
106
107static efi_status_t
108__file_size64(void *__fh, efi_char16_t *filename_16,
109 void **handle, u64 *file_sz)
110{
111 efi_file_handle_64_t *h, *fh = __fh;
112 efi_file_info_t *info;
113 efi_status_t status;
114 efi_guid_t info_guid = EFI_FILE_INFO_ID;
115 u32 info_sz;
24 116
117 status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16,
118 EFI_FILE_MODE_READ, (u64)0);
119 if (status != EFI_SUCCESS) {
120 efi_printk(sys_table, "Failed to open file: ");
121 efi_char16_printk(sys_table, filename_16);
122 efi_printk(sys_table, "\n");
123 return status;
124 }
25 125
126 *handle = h;
127
128 info_sz = 0;
129 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
130 &info_sz, NULL);
131 if (status != EFI_BUFFER_TOO_SMALL) {
132 efi_printk(sys_table, "Failed to get file info size\n");
133 return status;
134 }
135
136grow:
137 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
138 info_sz, (void **)&info);
139 if (status != EFI_SUCCESS) {
140 efi_printk(sys_table, "Failed to alloc mem for file info\n");
141 return status;
142 }
143
144 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
145 &info_sz, info);
146 if (status == EFI_BUFFER_TOO_SMALL) {
147 efi_call_early(free_pool, info);
148 goto grow;
149 }
150
151 *file_sz = info->file_size;
152 efi_call_early(free_pool, info);
153
154 if (status != EFI_SUCCESS)
155 efi_printk(sys_table, "Failed to get initrd info\n");
156
157 return status;
158}
159static efi_status_t
160efi_file_size(efi_system_table_t *sys_table, void *__fh,
161 efi_char16_t *filename_16, void **handle, u64 *file_sz)
162{
163 if (efi_early->is64)
164 return __file_size64(__fh, filename_16, handle, file_sz);
165
166 return __file_size32(__fh, filename_16, handle, file_sz);
167}
168
169static inline efi_status_t
170efi_file_read(void *__fh, void *handle, unsigned long *size, void *addr)
171{
172 unsigned long func;
173
174 if (efi_early->is64) {
175 efi_file_handle_64_t *fh = __fh;
176
177 func = (unsigned long)fh->read;
178 return efi_early->call(func, handle, size, addr);
179 } else {
180 efi_file_handle_32_t *fh = __fh;
181
182 func = (unsigned long)fh->read;
183 return efi_early->call(func, handle, size, addr);
184 }
185}
186
187static inline efi_status_t efi_file_close(void *__fh, void *handle)
188{
189 if (efi_early->is64) {
190 efi_file_handle_64_t *fh = __fh;
191
192 return efi_early->call((unsigned long)fh->close, handle);
193 } else {
194 efi_file_handle_32_t *fh = __fh;
195
196 return efi_early->call((unsigned long)fh->close, handle);
197 }
198}
199
200static inline efi_status_t __open_volume32(void *__image, void **__fh)
201{
202 efi_file_io_interface_t *io;
203 efi_loaded_image_32_t *image = __image;
204 efi_file_handle_32_t *fh;
205 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
206 efi_status_t status;
207 void *handle = (void *)(unsigned long)image->device_handle;
208 unsigned long func;
209
210 status = efi_call_early(handle_protocol, handle,
211 &fs_proto, (void **)&io);
212 if (status != EFI_SUCCESS) {
213 efi_printk(sys_table, "Failed to handle fs_proto\n");
214 return status;
215 }
216
217 func = (unsigned long)io->open_volume;
218 status = efi_early->call(func, io, &fh);
219 if (status != EFI_SUCCESS)
220 efi_printk(sys_table, "Failed to open volume\n");
221
222 *__fh = fh;
223 return status;
224}
225
226static inline efi_status_t __open_volume64(void *__image, void **__fh)
227{
228 efi_file_io_interface_t *io;
229 efi_loaded_image_64_t *image = __image;
230 efi_file_handle_64_t *fh;
231 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
232 efi_status_t status;
233 void *handle = (void *)(unsigned long)image->device_handle;
234 unsigned long func;
235
236 status = efi_call_early(handle_protocol, handle,
237 &fs_proto, (void **)&io);
238 if (status != EFI_SUCCESS) {
239 efi_printk(sys_table, "Failed to handle fs_proto\n");
240 return status;
241 }
242
243 func = (unsigned long)io->open_volume;
244 status = efi_early->call(func, io, &fh);
245 if (status != EFI_SUCCESS)
246 efi_printk(sys_table, "Failed to open volume\n");
247
248 *__fh = fh;
249 return status;
250}
251
252static inline efi_status_t
253efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
254{
255 if (efi_early->is64)
256 return __open_volume64(__image, __fh);
257
258 return __open_volume32(__image, __fh);
259}
260
261static void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
262{
263 unsigned long output_string;
264 size_t offset;
265
266 if (efi_early->is64) {
267 struct efi_simple_text_output_protocol_64 *out;
268 u64 *func;
269
270 offset = offsetof(typeof(*out), output_string);
271 output_string = efi_early->text_output + offset;
272 func = (u64 *)output_string;
273
274 efi_early->call(*func, efi_early->text_output, str);
275 } else {
276 struct efi_simple_text_output_protocol_32 *out;
277 u32 *func;
278
279 offset = offsetof(typeof(*out), output_string);
280 output_string = efi_early->text_output + offset;
281 func = (u32 *)output_string;
282
283 efi_early->call(*func, efi_early->text_output, str);
284 }
285}
286
287#include "../../../../drivers/firmware/efi/efi-stub-helper.c"
26 288
27static void find_bits(unsigned long mask, u8 *pos, u8 *size) 289static void find_bits(unsigned long mask, u8 *pos, u8 *size)
28{ 290{
@@ -47,105 +309,97 @@ static void find_bits(unsigned long mask, u8 *pos, u8 *size)
47 *size = len; 309 *size = len;
48} 310}
49 311
50static efi_status_t setup_efi_pci(struct boot_params *params) 312static efi_status_t
313__setup_efi_pci32(efi_pci_io_protocol_32 *pci, struct pci_setup_rom **__rom)
51{ 314{
52 efi_pci_io_protocol *pci; 315 struct pci_setup_rom *rom = NULL;
53 efi_status_t status; 316 efi_status_t status;
54 void **pci_handle; 317 unsigned long size;
55 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; 318 uint64_t attributes;
56 unsigned long nr_pci, size = 0;
57 int i;
58 struct setup_data *data;
59 319
60 data = (struct setup_data *)(unsigned long)params->hdr.setup_data; 320 status = efi_early->call(pci->attributes, pci,
321 EfiPciIoAttributeOperationGet, 0, 0,
322 &attributes);
323 if (status != EFI_SUCCESS)
324 return status;
61 325
62 while (data && data->next) 326 if (!pci->romimage || !pci->romsize)
63 data = (struct setup_data *)(unsigned long)data->next; 327 return EFI_INVALID_PARAMETER;
64 328
65 status = efi_call_phys5(sys_table->boottime->locate_handle, 329 size = pci->romsize + sizeof(*rom);
66 EFI_LOCATE_BY_PROTOCOL, &pci_proto,
67 NULL, &size, pci_handle);
68 330
69 if (status == EFI_BUFFER_TOO_SMALL) { 331 status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
70 status = efi_call_phys3(sys_table->boottime->allocate_pool, 332 if (status != EFI_SUCCESS)
71 EFI_LOADER_DATA, size, &pci_handle); 333 return status;
72 334
73 if (status != EFI_SUCCESS) 335 memset(rom, 0, sizeof(*rom));
74 return status;
75 336
76 status = efi_call_phys5(sys_table->boottime->locate_handle, 337 rom->data.type = SETUP_PCI;
77 EFI_LOCATE_BY_PROTOCOL, &pci_proto, 338 rom->data.len = size - sizeof(struct setup_data);
78 NULL, &size, pci_handle); 339 rom->data.next = 0;
79 } 340 rom->pcilen = pci->romsize;
341 *__rom = rom;
80 342
81 if (status != EFI_SUCCESS) 343 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
82 goto free_handle; 344 PCI_VENDOR_ID, 1, &(rom->vendor));
83
84 nr_pci = size / sizeof(void *);
85 for (i = 0; i < nr_pci; i++) {
86 void *h = pci_handle[i];
87 uint64_t attributes;
88 struct pci_setup_rom *rom;
89 345
90 status = efi_call_phys3(sys_table->boottime->handle_protocol, 346 if (status != EFI_SUCCESS)
91 h, &pci_proto, &pci); 347 goto free_struct;
92 348
93 if (status != EFI_SUCCESS) 349 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
94 continue; 350 PCI_DEVICE_ID, 1, &(rom->devid));
95 351
96 if (!pci) 352 if (status != EFI_SUCCESS)
97 continue; 353 goto free_struct;
98 354
99#ifdef CONFIG_X86_64 355 status = efi_early->call(pci->get_location, pci, &(rom->segment),
100 status = efi_call_phys4(pci->attributes, pci, 356 &(rom->bus), &(rom->device), &(rom->function));
101 EfiPciIoAttributeOperationGet, 0,
102 &attributes);
103#else
104 status = efi_call_phys5(pci->attributes, pci,
105 EfiPciIoAttributeOperationGet, 0, 0,
106 &attributes);
107#endif
108 if (status != EFI_SUCCESS)
109 continue;
110 357
111 if (!pci->romimage || !pci->romsize) 358 if (status != EFI_SUCCESS)
112 continue; 359 goto free_struct;
113 360
114 size = pci->romsize + sizeof(*rom); 361 memcpy(rom->romdata, pci->romimage, pci->romsize);
362 return status;
115 363
116 status = efi_call_phys3(sys_table->boottime->allocate_pool, 364free_struct:
117 EFI_LOADER_DATA, size, &rom); 365 efi_call_early(free_pool, rom);
366 return status;
367}
118 368
119 if (status != EFI_SUCCESS) 369static efi_status_t
120 continue; 370setup_efi_pci32(struct boot_params *params, void **pci_handle,
371 unsigned long size)
372{
373 efi_pci_io_protocol_32 *pci = NULL;
374 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
375 u32 *handles = (u32 *)(unsigned long)pci_handle;
376 efi_status_t status;
377 unsigned long nr_pci;
378 struct setup_data *data;
379 int i;
121 380
122 rom->data.type = SETUP_PCI; 381 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
123 rom->data.len = size - sizeof(struct setup_data);
124 rom->data.next = 0;
125 rom->pcilen = pci->romsize;
126 382
127 status = efi_call_phys5(pci->pci.read, pci, 383 while (data && data->next)
128 EfiPciIoWidthUint16, PCI_VENDOR_ID, 384 data = (struct setup_data *)(unsigned long)data->next;
129 1, &(rom->vendor));
130 385
131 if (status != EFI_SUCCESS) 386 nr_pci = size / sizeof(u32);
132 goto free_struct; 387 for (i = 0; i < nr_pci; i++) {
388 struct pci_setup_rom *rom = NULL;
389 u32 h = handles[i];
133 390
134 status = efi_call_phys5(pci->pci.read, pci, 391 status = efi_call_early(handle_protocol, h,
135 EfiPciIoWidthUint16, PCI_DEVICE_ID, 392 &pci_proto, (void **)&pci);
136 1, &(rom->devid));
137 393
138 if (status != EFI_SUCCESS) 394 if (status != EFI_SUCCESS)
139 goto free_struct; 395 continue;
140 396
141 status = efi_call_phys5(pci->get_location, pci, 397 if (!pci)
142 &(rom->segment), &(rom->bus), 398 continue;
143 &(rom->device), &(rom->function));
144 399
400 status = __setup_efi_pci32(pci, &rom);
145 if (status != EFI_SUCCESS) 401 if (status != EFI_SUCCESS)
146 goto free_struct; 402 continue;
147
148 memcpy(rom->romdata, pci->romimage, pci->romsize);
149 403
150 if (data) 404 if (data)
151 data->next = (unsigned long)rom; 405 data->next = (unsigned long)rom;
@@ -154,105 +408,155 @@ static efi_status_t setup_efi_pci(struct boot_params *params)
154 408
155 data = (struct setup_data *)rom; 409 data = (struct setup_data *)rom;
156 410
157 continue;
158 free_struct:
159 efi_call_phys1(sys_table->boottime->free_pool, rom);
160 } 411 }
161 412
162free_handle:
163 efi_call_phys1(sys_table->boottime->free_pool, pci_handle);
164 return status; 413 return status;
165} 414}
166 415
167/* 416static efi_status_t
168 * See if we have Graphics Output Protocol 417__setup_efi_pci64(efi_pci_io_protocol_64 *pci, struct pci_setup_rom **__rom)
169 */
170static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
171 unsigned long size)
172{ 418{
173 struct efi_graphics_output_protocol *gop, *first_gop; 419 struct pci_setup_rom *rom;
174 struct efi_pixel_bitmask pixel_info;
175 unsigned long nr_gops;
176 efi_status_t status; 420 efi_status_t status;
177 void **gop_handle; 421 unsigned long size;
178 u16 width, height; 422 uint64_t attributes;
179 u32 fb_base, fb_size;
180 u32 pixels_per_scan_line;
181 int pixel_format;
182 int i;
183 423
184 status = efi_call_phys3(sys_table->boottime->allocate_pool, 424 status = efi_early->call(pci->attributes, pci,
185 EFI_LOADER_DATA, size, &gop_handle); 425 EfiPciIoAttributeOperationGet, 0,
426 &attributes);
186 if (status != EFI_SUCCESS) 427 if (status != EFI_SUCCESS)
187 return status; 428 return status;
188 429
189 status = efi_call_phys5(sys_table->boottime->locate_handle, 430 if (!pci->romimage || !pci->romsize)
190 EFI_LOCATE_BY_PROTOCOL, proto, 431 return EFI_INVALID_PARAMETER;
191 NULL, &size, gop_handle); 432
433 size = pci->romsize + sizeof(*rom);
434
435 status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
192 if (status != EFI_SUCCESS) 436 if (status != EFI_SUCCESS)
193 goto free_handle; 437 return status;
194 438
195 first_gop = NULL; 439 rom->data.type = SETUP_PCI;
440 rom->data.len = size - sizeof(struct setup_data);
441 rom->data.next = 0;
442 rom->pcilen = pci->romsize;
443 *__rom = rom;
196 444
197 nr_gops = size / sizeof(void *); 445 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
198 for (i = 0; i < nr_gops; i++) { 446 PCI_VENDOR_ID, 1, &(rom->vendor));
199 struct efi_graphics_output_mode_info *info; 447
200 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID; 448 if (status != EFI_SUCCESS)
201 bool conout_found = false; 449 goto free_struct;
202 void *dummy; 450
203 void *h = gop_handle[i]; 451 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
452 PCI_DEVICE_ID, 1, &(rom->devid));
453
454 if (status != EFI_SUCCESS)
455 goto free_struct;
456
457 status = efi_early->call(pci->get_location, pci, &(rom->segment),
458 &(rom->bus), &(rom->device), &(rom->function));
459
460 if (status != EFI_SUCCESS)
461 goto free_struct;
462
463 memcpy(rom->romdata, pci->romimage, pci->romsize);
464 return status;
465
466free_struct:
467 efi_call_early(free_pool, rom);
468 return status;
469
470}
471
472static efi_status_t
473setup_efi_pci64(struct boot_params *params, void **pci_handle,
474 unsigned long size)
475{
476 efi_pci_io_protocol_64 *pci = NULL;
477 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
478 u64 *handles = (u64 *)(unsigned long)pci_handle;
479 efi_status_t status;
480 unsigned long nr_pci;
481 struct setup_data *data;
482 int i;
483
484 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
485
486 while (data && data->next)
487 data = (struct setup_data *)(unsigned long)data->next;
488
489 nr_pci = size / sizeof(u64);
490 for (i = 0; i < nr_pci; i++) {
491 struct pci_setup_rom *rom = NULL;
492 u64 h = handles[i];
493
494 status = efi_call_early(handle_protocol, h,
495 &pci_proto, (void **)&pci);
204 496
205 status = efi_call_phys3(sys_table->boottime->handle_protocol,
206 h, proto, &gop);
207 if (status != EFI_SUCCESS) 497 if (status != EFI_SUCCESS)
208 continue; 498 continue;
209 499
210 status = efi_call_phys3(sys_table->boottime->handle_protocol, 500 if (!pci)
211 h, &conout_proto, &dummy); 501 continue;
212 502
213 if (status == EFI_SUCCESS) 503 status = __setup_efi_pci64(pci, &rom);
214 conout_found = true; 504 if (status != EFI_SUCCESS)
505 continue;
215 506
216 status = efi_call_phys4(gop->query_mode, gop, 507 if (data)
217 gop->mode->mode, &size, &info); 508 data->next = (unsigned long)rom;
218 if (status == EFI_SUCCESS && (!first_gop || conout_found)) { 509 else
219 /* 510 params->hdr.setup_data = (unsigned long)rom;
220 * Systems that use the UEFI Console Splitter may 511
221 * provide multiple GOP devices, not all of which are 512 data = (struct setup_data *)rom;
222 * backed by real hardware. The workaround is to search
223 * for a GOP implementing the ConOut protocol, and if
224 * one isn't found, to just fall back to the first GOP.
225 */
226 width = info->horizontal_resolution;
227 height = info->vertical_resolution;
228 fb_base = gop->mode->frame_buffer_base;
229 fb_size = gop->mode->frame_buffer_size;
230 pixel_format = info->pixel_format;
231 pixel_info = info->pixel_information;
232 pixels_per_scan_line = info->pixels_per_scan_line;
233 513
234 /*
235 * Once we've found a GOP supporting ConOut,
236 * don't bother looking any further.
237 */
238 first_gop = gop;
239 if (conout_found)
240 break;
241 }
242 } 514 }
243 515
244 /* Did we find any GOPs? */ 516 return status;
245 if (!first_gop) 517}
518
519static efi_status_t setup_efi_pci(struct boot_params *params)
520{
521 efi_status_t status;
522 void **pci_handle = NULL;
523 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
524 unsigned long size = 0;
525
526 status = efi_call_early(locate_handle,
527 EFI_LOCATE_BY_PROTOCOL,
528 &pci_proto, NULL, &size, pci_handle);
529
530 if (status == EFI_BUFFER_TOO_SMALL) {
531 status = efi_call_early(allocate_pool,
532 EFI_LOADER_DATA,
533 size, (void **)&pci_handle);
534
535 if (status != EFI_SUCCESS)
536 return status;
537
538 status = efi_call_early(locate_handle,
539 EFI_LOCATE_BY_PROTOCOL, &pci_proto,
540 NULL, &size, pci_handle);
541 }
542
543 if (status != EFI_SUCCESS)
246 goto free_handle; 544 goto free_handle;
247 545
248 /* EFI framebuffer */ 546 if (efi_early->is64)
249 si->orig_video_isVGA = VIDEO_TYPE_EFI; 547 status = setup_efi_pci64(params, pci_handle, size);
548 else
549 status = setup_efi_pci32(params, pci_handle, size);
250 550
251 si->lfb_width = width; 551free_handle:
252 si->lfb_height = height; 552 efi_call_early(free_pool, pci_handle);
253 si->lfb_base = fb_base; 553 return status;
254 si->pages = 1; 554}
255 555
556static void
557setup_pixel_info(struct screen_info *si, u32 pixels_per_scan_line,
558 struct efi_pixel_bitmask pixel_info, int pixel_format)
559{
256 if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) { 560 if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) {
257 si->lfb_depth = 32; 561 si->lfb_depth = 32;
258 si->lfb_linelength = pixels_per_scan_line * 4; 562 si->lfb_linelength = pixels_per_scan_line * 4;
@@ -297,62 +601,319 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
297 si->rsvd_size = 0; 601 si->rsvd_size = 0;
298 si->rsvd_pos = 0; 602 si->rsvd_pos = 0;
299 } 603 }
604}
605
606static efi_status_t
607__gop_query32(struct efi_graphics_output_protocol_32 *gop32,
608 struct efi_graphics_output_mode_info **info,
609 unsigned long *size, u32 *fb_base)
610{
611 struct efi_graphics_output_protocol_mode_32 *mode;
612 efi_status_t status;
613 unsigned long m;
614
615 m = gop32->mode;
616 mode = (struct efi_graphics_output_protocol_mode_32 *)m;
617
618 status = efi_early->call(gop32->query_mode, gop32,
619 mode->mode, size, info);
620 if (status != EFI_SUCCESS)
621 return status;
622
623 *fb_base = mode->frame_buffer_base;
624 return status;
625}
626
627static efi_status_t
628setup_gop32(struct screen_info *si, efi_guid_t *proto,
629 unsigned long size, void **gop_handle)
630{
631 struct efi_graphics_output_protocol_32 *gop32, *first_gop;
632 unsigned long nr_gops;
633 u16 width, height;
634 u32 pixels_per_scan_line;
635 u32 fb_base;
636 struct efi_pixel_bitmask pixel_info;
637 int pixel_format;
638 efi_status_t status;
639 u32 *handles = (u32 *)(unsigned long)gop_handle;
640 int i;
641
642 first_gop = NULL;
643 gop32 = NULL;
644
645 nr_gops = size / sizeof(u32);
646 for (i = 0; i < nr_gops; i++) {
647 struct efi_graphics_output_mode_info *info = NULL;
648 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
649 bool conout_found = false;
650 void *dummy = NULL;
651 u32 h = handles[i];
652
653 status = efi_call_early(handle_protocol, h,
654 proto, (void **)&gop32);
655 if (status != EFI_SUCCESS)
656 continue;
657
658 status = efi_call_early(handle_protocol, h,
659 &conout_proto, &dummy);
660 if (status == EFI_SUCCESS)
661 conout_found = true;
662
663 status = __gop_query32(gop32, &info, &size, &fb_base);
664 if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
665 /*
666 * Systems that use the UEFI Console Splitter may
667 * provide multiple GOP devices, not all of which are
668 * backed by real hardware. The workaround is to search
669 * for a GOP implementing the ConOut protocol, and if
670 * one isn't found, to just fall back to the first GOP.
671 */
672 width = info->horizontal_resolution;
673 height = info->vertical_resolution;
674 pixel_format = info->pixel_format;
675 pixel_info = info->pixel_information;
676 pixels_per_scan_line = info->pixels_per_scan_line;
677
678 /*
679 * Once we've found a GOP supporting ConOut,
680 * don't bother looking any further.
681 */
682 first_gop = gop32;
683 if (conout_found)
684 break;
685 }
686 }
687
688 /* Did we find any GOPs? */
689 if (!first_gop)
690 goto out;
691
692 /* EFI framebuffer */
693 si->orig_video_isVGA = VIDEO_TYPE_EFI;
694
695 si->lfb_width = width;
696 si->lfb_height = height;
697 si->lfb_base = fb_base;
698 si->pages = 1;
699
700 setup_pixel_info(si, pixels_per_scan_line, pixel_info, pixel_format);
300 701
301 si->lfb_size = si->lfb_linelength * si->lfb_height; 702 si->lfb_size = si->lfb_linelength * si->lfb_height;
302 703
303 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS; 704 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS;
705out:
706 return status;
707}
304 708
305free_handle: 709static efi_status_t
306 efi_call_phys1(sys_table->boottime->free_pool, gop_handle); 710__gop_query64(struct efi_graphics_output_protocol_64 *gop64,
711 struct efi_graphics_output_mode_info **info,
712 unsigned long *size, u32 *fb_base)
713{
714 struct efi_graphics_output_protocol_mode_64 *mode;
715 efi_status_t status;
716 unsigned long m;
717
718 m = gop64->mode;
719 mode = (struct efi_graphics_output_protocol_mode_64 *)m;
720
721 status = efi_early->call(gop64->query_mode, gop64,
722 mode->mode, size, info);
723 if (status != EFI_SUCCESS)
724 return status;
725
726 *fb_base = mode->frame_buffer_base;
727 return status;
728}
729
730static efi_status_t
731setup_gop64(struct screen_info *si, efi_guid_t *proto,
732 unsigned long size, void **gop_handle)
733{
734 struct efi_graphics_output_protocol_64 *gop64, *first_gop;
735 unsigned long nr_gops;
736 u16 width, height;
737 u32 pixels_per_scan_line;
738 u32 fb_base;
739 struct efi_pixel_bitmask pixel_info;
740 int pixel_format;
741 efi_status_t status;
742 u64 *handles = (u64 *)(unsigned long)gop_handle;
743 int i;
744
745 first_gop = NULL;
746 gop64 = NULL;
747
748 nr_gops = size / sizeof(u64);
749 for (i = 0; i < nr_gops; i++) {
750 struct efi_graphics_output_mode_info *info = NULL;
751 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
752 bool conout_found = false;
753 void *dummy = NULL;
754 u64 h = handles[i];
755
756 status = efi_call_early(handle_protocol, h,
757 proto, (void **)&gop64);
758 if (status != EFI_SUCCESS)
759 continue;
760
761 status = efi_call_early(handle_protocol, h,
762 &conout_proto, &dummy);
763 if (status == EFI_SUCCESS)
764 conout_found = true;
765
766 status = __gop_query64(gop64, &info, &size, &fb_base);
767 if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
768 /*
769 * Systems that use the UEFI Console Splitter may
770 * provide multiple GOP devices, not all of which are
771 * backed by real hardware. The workaround is to search
772 * for a GOP implementing the ConOut protocol, and if
773 * one isn't found, to just fall back to the first GOP.
774 */
775 width = info->horizontal_resolution;
776 height = info->vertical_resolution;
777 pixel_format = info->pixel_format;
778 pixel_info = info->pixel_information;
779 pixels_per_scan_line = info->pixels_per_scan_line;
780
781 /*
782 * Once we've found a GOP supporting ConOut,
783 * don't bother looking any further.
784 */
785 first_gop = gop64;
786 if (conout_found)
787 break;
788 }
789 }
790
791 /* Did we find any GOPs? */
792 if (!first_gop)
793 goto out;
794
795 /* EFI framebuffer */
796 si->orig_video_isVGA = VIDEO_TYPE_EFI;
797
798 si->lfb_width = width;
799 si->lfb_height = height;
800 si->lfb_base = fb_base;
801 si->pages = 1;
802
803 setup_pixel_info(si, pixels_per_scan_line, pixel_info, pixel_format);
804
805 si->lfb_size = si->lfb_linelength * si->lfb_height;
806
807 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS;
808out:
307 return status; 809 return status;
308} 810}
309 811
310/* 812/*
311 * See if we have Universal Graphics Adapter (UGA) protocol 813 * See if we have Graphics Output Protocol
312 */ 814 */
313static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, 815static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
314 unsigned long size) 816 unsigned long size)
315{ 817{
316 struct efi_uga_draw_protocol *uga, *first_uga;
317 unsigned long nr_ugas;
318 efi_status_t status; 818 efi_status_t status;
319 u32 width, height; 819 void **gop_handle = NULL;
320 void **uga_handle = NULL;
321 int i;
322 820
323 status = efi_call_phys3(sys_table->boottime->allocate_pool, 821 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
324 EFI_LOADER_DATA, size, &uga_handle); 822 size, (void **)&gop_handle);
325 if (status != EFI_SUCCESS) 823 if (status != EFI_SUCCESS)
326 return status; 824 return status;
327 825
328 status = efi_call_phys5(sys_table->boottime->locate_handle, 826 status = efi_call_early(locate_handle,
329 EFI_LOCATE_BY_PROTOCOL, uga_proto, 827 EFI_LOCATE_BY_PROTOCOL,
330 NULL, &size, uga_handle); 828 proto, NULL, &size, gop_handle);
331 if (status != EFI_SUCCESS) 829 if (status != EFI_SUCCESS)
332 goto free_handle; 830 goto free_handle;
333 831
832 if (efi_early->is64)
833 status = setup_gop64(si, proto, size, gop_handle);
834 else
835 status = setup_gop32(si, proto, size, gop_handle);
836
837free_handle:
838 efi_call_early(free_pool, gop_handle);
839 return status;
840}
841
842static efi_status_t
843setup_uga32(void **uga_handle, unsigned long size, u32 *width, u32 *height)
844{
845 struct efi_uga_draw_protocol *uga = NULL, *first_uga;
846 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
847 unsigned long nr_ugas;
848 u32 *handles = (u32 *)uga_handle;;
849 efi_status_t status;
850 int i;
851
334 first_uga = NULL; 852 first_uga = NULL;
853 nr_ugas = size / sizeof(u32);
854 for (i = 0; i < nr_ugas; i++) {
855 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID;
856 u32 w, h, depth, refresh;
857 void *pciio;
858 u32 handle = handles[i];
859
860 status = efi_call_early(handle_protocol, handle,
861 &uga_proto, (void **)&uga);
862 if (status != EFI_SUCCESS)
863 continue;
864
865 efi_call_early(handle_protocol, handle, &pciio_proto, &pciio);
866
867 status = efi_early->call((unsigned long)uga->get_mode, uga,
868 &w, &h, &depth, &refresh);
869 if (status == EFI_SUCCESS && (!first_uga || pciio)) {
870 *width = w;
871 *height = h;
872
873 /*
874 * Once we've found a UGA supporting PCIIO,
875 * don't bother looking any further.
876 */
877 if (pciio)
878 break;
335 879
336 nr_ugas = size / sizeof(void *); 880 first_uga = uga;
881 }
882 }
883
884 return status;
885}
886
887static efi_status_t
888setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height)
889{
890 struct efi_uga_draw_protocol *uga = NULL, *first_uga;
891 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
892 unsigned long nr_ugas;
893 u64 *handles = (u64 *)uga_handle;;
894 efi_status_t status;
895 int i;
896
897 first_uga = NULL;
898 nr_ugas = size / sizeof(u64);
337 for (i = 0; i < nr_ugas; i++) { 899 for (i = 0; i < nr_ugas; i++) {
338 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; 900 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID;
339 void *handle = uga_handle[i];
340 u32 w, h, depth, refresh; 901 u32 w, h, depth, refresh;
341 void *pciio; 902 void *pciio;
903 u64 handle = handles[i];
342 904
343 status = efi_call_phys3(sys_table->boottime->handle_protocol, 905 status = efi_call_early(handle_protocol, handle,
344 handle, uga_proto, &uga); 906 &uga_proto, (void **)&uga);
345 if (status != EFI_SUCCESS) 907 if (status != EFI_SUCCESS)
346 continue; 908 continue;
347 909
348 efi_call_phys3(sys_table->boottime->handle_protocol, 910 efi_call_early(handle_protocol, handle, &pciio_proto, &pciio);
349 handle, &pciio_proto, &pciio);
350 911
351 status = efi_call_phys5(uga->get_mode, uga, &w, &h, 912 status = efi_early->call((unsigned long)uga->get_mode, uga,
352 &depth, &refresh); 913 &w, &h, &depth, &refresh);
353 if (status == EFI_SUCCESS && (!first_uga || pciio)) { 914 if (status == EFI_SUCCESS && (!first_uga || pciio)) {
354 width = w; 915 *width = w;
355 height = h; 916 *height = h;
356 917
357 /* 918 /*
358 * Once we've found a UGA supporting PCIIO, 919 * Once we've found a UGA supporting PCIIO,
@@ -365,7 +926,39 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
365 } 926 }
366 } 927 }
367 928
368 if (!first_uga) 929 return status;
930}
931
932/*
933 * See if we have Universal Graphics Adapter (UGA) protocol
934 */
935static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
936 unsigned long size)
937{
938 efi_status_t status;
939 u32 width, height;
940 void **uga_handle = NULL;
941
942 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
943 size, (void **)&uga_handle);
944 if (status != EFI_SUCCESS)
945 return status;
946
947 status = efi_call_early(locate_handle,
948 EFI_LOCATE_BY_PROTOCOL,
949 uga_proto, NULL, &size, uga_handle);
950 if (status != EFI_SUCCESS)
951 goto free_handle;
952
953 height = 0;
954 width = 0;
955
956 if (efi_early->is64)
957 status = setup_uga64(uga_handle, size, &width, &height);
958 else
959 status = setup_uga32(uga_handle, size, &width, &height);
960
961 if (!width && !height)
369 goto free_handle; 962 goto free_handle;
370 963
371 /* EFI framebuffer */ 964 /* EFI framebuffer */
@@ -384,9 +977,8 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
384 si->rsvd_size = 8; 977 si->rsvd_size = 8;
385 si->rsvd_pos = 24; 978 si->rsvd_pos = 24;
386 979
387
388free_handle: 980free_handle:
389 efi_call_phys1(sys_table->boottime->free_pool, uga_handle); 981 efi_call_early(free_pool, uga_handle);
390 return status; 982 return status;
391} 983}
392 984
@@ -404,29 +996,28 @@ void setup_graphics(struct boot_params *boot_params)
404 memset(si, 0, sizeof(*si)); 996 memset(si, 0, sizeof(*si));
405 997
406 size = 0; 998 size = 0;
407 status = efi_call_phys5(sys_table->boottime->locate_handle, 999 status = efi_call_early(locate_handle,
408 EFI_LOCATE_BY_PROTOCOL, &graphics_proto, 1000 EFI_LOCATE_BY_PROTOCOL,
409 NULL, &size, gop_handle); 1001 &graphics_proto, NULL, &size, gop_handle);
410 if (status == EFI_BUFFER_TOO_SMALL) 1002 if (status == EFI_BUFFER_TOO_SMALL)
411 status = setup_gop(si, &graphics_proto, size); 1003 status = setup_gop(si, &graphics_proto, size);
412 1004
413 if (status != EFI_SUCCESS) { 1005 if (status != EFI_SUCCESS) {
414 size = 0; 1006 size = 0;
415 status = efi_call_phys5(sys_table->boottime->locate_handle, 1007 status = efi_call_early(locate_handle,
416 EFI_LOCATE_BY_PROTOCOL, &uga_proto, 1008 EFI_LOCATE_BY_PROTOCOL,
417 NULL, &size, uga_handle); 1009 &uga_proto, NULL, &size, uga_handle);
418 if (status == EFI_BUFFER_TOO_SMALL) 1010 if (status == EFI_BUFFER_TOO_SMALL)
419 setup_uga(si, &uga_proto, size); 1011 setup_uga(si, &uga_proto, size);
420 } 1012 }
421} 1013}
422 1014
423
424/* 1015/*
425 * Because the x86 boot code expects to be passed a boot_params we 1016 * Because the x86 boot code expects to be passed a boot_params we
426 * need to create one ourselves (usually the bootloader would create 1017 * need to create one ourselves (usually the bootloader would create
427 * one for us). 1018 * one for us).
428 */ 1019 */
429struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) 1020struct boot_params *make_boot_params(struct efi_config *c)
430{ 1021{
431 struct boot_params *boot_params; 1022 struct boot_params *boot_params;
432 struct sys_desc_table *sdt; 1023 struct sys_desc_table *sdt;
@@ -434,7 +1025,7 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table)
434 struct setup_header *hdr; 1025 struct setup_header *hdr;
435 struct efi_info *efi; 1026 struct efi_info *efi;
436 efi_loaded_image_t *image; 1027 efi_loaded_image_t *image;
437 void *options; 1028 void *options, *handle;
438 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; 1029 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
439 int options_size = 0; 1030 int options_size = 0;
440 efi_status_t status; 1031 efi_status_t status;
@@ -445,14 +1036,21 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table)
445 unsigned long ramdisk_addr; 1036 unsigned long ramdisk_addr;
446 unsigned long ramdisk_size; 1037 unsigned long ramdisk_size;
447 1038
448 sys_table = _table; 1039 efi_early = c;
1040 sys_table = (efi_system_table_t *)(unsigned long)efi_early->table;
1041 handle = (void *)(unsigned long)efi_early->image_handle;
449 1042
450 /* Check if we were booted by the EFI firmware */ 1043 /* Check if we were booted by the EFI firmware */
451 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 1044 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
452 return NULL; 1045 return NULL;
453 1046
454 status = efi_call_phys3(sys_table->boottime->handle_protocol, 1047 if (efi_early->is64)
455 handle, &proto, (void *)&image); 1048 setup_boot_services64(efi_early);
1049 else
1050 setup_boot_services32(efi_early);
1051
1052 status = efi_call_early(handle_protocol, handle,
1053 &proto, (void *)&image);
456 if (status != EFI_SUCCESS) { 1054 if (status != EFI_SUCCESS) {
457 efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); 1055 efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
458 return NULL; 1056 return NULL;
@@ -641,14 +1239,13 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
641 sizeof(struct e820entry) * nr_desc; 1239 sizeof(struct e820entry) * nr_desc;
642 1240
643 if (*e820ext) { 1241 if (*e820ext) {
644 efi_call_phys1(sys_table->boottime->free_pool, *e820ext); 1242 efi_call_early(free_pool, *e820ext);
645 *e820ext = NULL; 1243 *e820ext = NULL;
646 *e820ext_size = 0; 1244 *e820ext_size = 0;
647 } 1245 }
648 1246
649 status = efi_call_phys3(sys_table->boottime->allocate_pool, 1247 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
650 EFI_LOADER_DATA, size, e820ext); 1248 size, (void **)e820ext);
651
652 if (status == EFI_SUCCESS) 1249 if (status == EFI_SUCCESS)
653 *e820ext_size = size; 1250 *e820ext_size = size;
654 1251
@@ -656,12 +1253,13 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
656} 1253}
657 1254
658static efi_status_t exit_boot(struct boot_params *boot_params, 1255static efi_status_t exit_boot(struct boot_params *boot_params,
659 void *handle) 1256 void *handle, bool is64)
660{ 1257{
661 struct efi_info *efi = &boot_params->efi_info; 1258 struct efi_info *efi = &boot_params->efi_info;
662 unsigned long map_sz, key, desc_size; 1259 unsigned long map_sz, key, desc_size;
663 efi_memory_desc_t *mem_map; 1260 efi_memory_desc_t *mem_map;
664 struct setup_data *e820ext; 1261 struct setup_data *e820ext;
1262 const char *signature;
665 __u32 e820ext_size; 1263 __u32 e820ext_size;
666 __u32 nr_desc, prev_nr_desc; 1264 __u32 nr_desc, prev_nr_desc;
667 efi_status_t status; 1265 efi_status_t status;
@@ -691,11 +1289,13 @@ get_map:
691 if (status != EFI_SUCCESS) 1289 if (status != EFI_SUCCESS)
692 goto free_mem_map; 1290 goto free_mem_map;
693 1291
694 efi_call_phys1(sys_table->boottime->free_pool, mem_map); 1292 efi_call_early(free_pool, mem_map);
695 goto get_map; /* Allocated memory, get map again */ 1293 goto get_map; /* Allocated memory, get map again */
696 } 1294 }
697 1295
698 memcpy(&efi->efi_loader_signature, EFI_LOADER_SIGNATURE, sizeof(__u32)); 1296 signature = is64 ? EFI64_LOADER_SIGNATURE : EFI32_LOADER_SIGNATURE;
1297 memcpy(&efi->efi_loader_signature, signature, sizeof(__u32));
1298
699 efi->efi_systab = (unsigned long)sys_table; 1299 efi->efi_systab = (unsigned long)sys_table;
700 efi->efi_memdesc_size = desc_size; 1300 efi->efi_memdesc_size = desc_size;
701 efi->efi_memdesc_version = desc_version; 1301 efi->efi_memdesc_version = desc_version;
@@ -708,8 +1308,7 @@ get_map:
708#endif 1308#endif
709 1309
710 /* Might as well exit boot services now */ 1310 /* Might as well exit boot services now */
711 status = efi_call_phys2(sys_table->boottime->exit_boot_services, 1311 status = efi_call_early(exit_boot_services, handle, key);
712 handle, key);
713 if (status != EFI_SUCCESS) { 1312 if (status != EFI_SUCCESS) {
714 /* 1313 /*
715 * ExitBootServices() will fail if any of the event 1314 * ExitBootServices() will fail if any of the event
@@ -722,7 +1321,7 @@ get_map:
722 goto free_mem_map; 1321 goto free_mem_map;
723 1322
724 called_exit = true; 1323 called_exit = true;
725 efi_call_phys1(sys_table->boottime->free_pool, mem_map); 1324 efi_call_early(free_pool, mem_map);
726 goto get_map; 1325 goto get_map;
727 } 1326 }
728 1327
@@ -736,23 +1335,31 @@ get_map:
736 return EFI_SUCCESS; 1335 return EFI_SUCCESS;
737 1336
738free_mem_map: 1337free_mem_map:
739 efi_call_phys1(sys_table->boottime->free_pool, mem_map); 1338 efi_call_early(free_pool, mem_map);
740 return status; 1339 return status;
741} 1340}
742 1341
743
744/* 1342/*
745 * On success we return a pointer to a boot_params structure, and NULL 1343 * On success we return a pointer to a boot_params structure, and NULL
746 * on failure. 1344 * on failure.
747 */ 1345 */
748struct boot_params *efi_main(void *handle, efi_system_table_t *_table, 1346struct boot_params *efi_main(struct efi_config *c,
749 struct boot_params *boot_params) 1347 struct boot_params *boot_params)
750{ 1348{
751 struct desc_ptr *gdt; 1349 struct desc_ptr *gdt = NULL;
752 efi_loaded_image_t *image; 1350 efi_loaded_image_t *image;
753 struct setup_header *hdr = &boot_params->hdr; 1351 struct setup_header *hdr = &boot_params->hdr;
754 efi_status_t status; 1352 efi_status_t status;
755 struct desc_struct *desc; 1353 struct desc_struct *desc;
1354 void *handle;
1355 efi_system_table_t *_table;
1356 bool is64;
1357
1358 efi_early = c;
1359
1360 _table = (efi_system_table_t *)(unsigned long)efi_early->table;
1361 handle = (void *)(unsigned long)efi_early->image_handle;
1362 is64 = efi_early->is64;
756 1363
757 sys_table = _table; 1364 sys_table = _table;
758 1365
@@ -760,13 +1367,17 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table,
760 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 1367 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
761 goto fail; 1368 goto fail;
762 1369
1370 if (is64)
1371 setup_boot_services64(efi_early);
1372 else
1373 setup_boot_services32(efi_early);
1374
763 setup_graphics(boot_params); 1375 setup_graphics(boot_params);
764 1376
765 setup_efi_pci(boot_params); 1377 setup_efi_pci(boot_params);
766 1378
767 status = efi_call_phys3(sys_table->boottime->allocate_pool, 1379 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
768 EFI_LOADER_DATA, sizeof(*gdt), 1380 sizeof(*gdt), (void **)&gdt);
769 (void **)&gdt);
770 if (status != EFI_SUCCESS) { 1381 if (status != EFI_SUCCESS) {
771 efi_printk(sys_table, "Failed to alloc mem for gdt structure\n"); 1382 efi_printk(sys_table, "Failed to alloc mem for gdt structure\n");
772 goto fail; 1383 goto fail;
@@ -797,7 +1408,7 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table,
797 hdr->code32_start = bzimage_addr; 1408 hdr->code32_start = bzimage_addr;
798 } 1409 }
799 1410
800 status = exit_boot(boot_params, handle); 1411 status = exit_boot(boot_params, handle, is64);
801 if (status != EFI_SUCCESS) 1412 if (status != EFI_SUCCESS)
802 goto fail; 1413 goto fail;
803 1414
diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
index 81b6b652b46a..c88c31ecad12 100644
--- a/arch/x86/boot/compressed/eboot.h
+++ b/arch/x86/boot/compressed/eboot.h
@@ -37,6 +37,24 @@ struct efi_graphics_output_mode_info {
37 u32 pixels_per_scan_line; 37 u32 pixels_per_scan_line;
38} __packed; 38} __packed;
39 39
40struct efi_graphics_output_protocol_mode_32 {
41 u32 max_mode;
42 u32 mode;
43 u32 info;
44 u32 size_of_info;
45 u64 frame_buffer_base;
46 u32 frame_buffer_size;
47} __packed;
48
49struct efi_graphics_output_protocol_mode_64 {
50 u32 max_mode;
51 u32 mode;
52 u64 info;
53 u64 size_of_info;
54 u64 frame_buffer_base;
55 u64 frame_buffer_size;
56} __packed;
57
40struct efi_graphics_output_protocol_mode { 58struct efi_graphics_output_protocol_mode {
41 u32 max_mode; 59 u32 max_mode;
42 u32 mode; 60 u32 mode;
@@ -46,6 +64,20 @@ struct efi_graphics_output_protocol_mode {
46 unsigned long frame_buffer_size; 64 unsigned long frame_buffer_size;
47} __packed; 65} __packed;
48 66
67struct efi_graphics_output_protocol_32 {
68 u32 query_mode;
69 u32 set_mode;
70 u32 blt;
71 u32 mode;
72};
73
74struct efi_graphics_output_protocol_64 {
75 u64 query_mode;
76 u64 set_mode;
77 u64 blt;
78 u64 mode;
79};
80
49struct efi_graphics_output_protocol { 81struct efi_graphics_output_protocol {
50 void *query_mode; 82 void *query_mode;
51 unsigned long set_mode; 83 unsigned long set_mode;
@@ -53,10 +85,38 @@ struct efi_graphics_output_protocol {
53 struct efi_graphics_output_protocol_mode *mode; 85 struct efi_graphics_output_protocol_mode *mode;
54}; 86};
55 87
88struct efi_uga_draw_protocol_32 {
89 u32 get_mode;
90 u32 set_mode;
91 u32 blt;
92};
93
94struct efi_uga_draw_protocol_64 {
95 u64 get_mode;
96 u64 set_mode;
97 u64 blt;
98};
99
56struct efi_uga_draw_protocol { 100struct efi_uga_draw_protocol {
57 void *get_mode; 101 void *get_mode;
58 void *set_mode; 102 void *set_mode;
59 void *blt; 103 void *blt;
60}; 104};
61 105
106struct efi_config {
107 u64 image_handle;
108 u64 table;
109 u64 allocate_pool;
110 u64 allocate_pages;
111 u64 get_memory_map;
112 u64 free_pool;
113 u64 free_pages;
114 u64 locate_handle;
115 u64 handle_protocol;
116 u64 exit_boot_services;
117 u64 text_output;
118 efi_status_t (*call)(unsigned long, ...);
119 bool is64;
120} __packed;
121
62#endif /* BOOT_COMPRESSED_EBOOT_H */ 122#endif /* BOOT_COMPRESSED_EBOOT_H */
diff --git a/arch/x86/boot/compressed/efi_stub_64.S b/arch/x86/boot/compressed/efi_stub_64.S
index cedc60de86eb..7ff3632806b1 100644
--- a/arch/x86/boot/compressed/efi_stub_64.S
+++ b/arch/x86/boot/compressed/efi_stub_64.S
@@ -1 +1,30 @@
1#include <asm/segment.h>
2#include <asm/msr.h>
3#include <asm/processor-flags.h>
4
1#include "../../platform/efi/efi_stub_64.S" 5#include "../../platform/efi/efi_stub_64.S"
6
7#ifdef CONFIG_EFI_MIXED
8 .code64
9 .text
10ENTRY(efi64_thunk)
11 push %rbp
12 push %rbx
13
14 subq $16, %rsp
15 leaq efi_exit32(%rip), %rax
16 movl %eax, 8(%rsp)
17 leaq efi_gdt64(%rip), %rax
18 movl %eax, 4(%rsp)
19 movl %eax, 2(%rax) /* Fixup the gdt base address */
20 leaq efi32_boot_gdt(%rip), %rax
21 movl %eax, (%rsp)
22
23 call __efi64_thunk
24
25 addq $16, %rsp
26 pop %rbx
27 pop %rbp
28 ret
29ENDPROC(efi64_thunk)
30#endif /* CONFIG_EFI_MIXED */
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index 9116aac232c7..de9d4200d305 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -42,26 +42,53 @@ ENTRY(startup_32)
42ENTRY(efi_pe_entry) 42ENTRY(efi_pe_entry)
43 add $0x4, %esp 43 add $0x4, %esp
44 44
45 call 1f
461: popl %esi
47 subl $1b, %esi
48
49 popl %ecx
50 movl %ecx, efi32_config(%esi) /* Handle */
51 popl %ecx
52 movl %ecx, efi32_config+8(%esi) /* EFI System table pointer */
53
54 /* Relocate efi_config->call() */
55 leal efi32_config(%esi), %eax
56 add %esi, 88(%eax)
57 pushl %eax
58
45 call make_boot_params 59 call make_boot_params
46 cmpl $0, %eax 60 cmpl $0, %eax
47 je 1f 61 je fail
48 movl 0x4(%esp), %esi 62 popl %ecx
49 movl (%esp), %ecx
50 pushl %eax 63 pushl %eax
51 pushl %esi
52 pushl %ecx 64 pushl %ecx
53 sub $0x4, %esp 65 jmp 2f /* Skip efi_config initialization */
54 66
55ENTRY(efi_stub_entry) 67ENTRY(efi32_stub_entry)
56 add $0x4, %esp 68 add $0x4, %esp
69 popl %ecx
70 popl %edx
71
72 call 1f
731: popl %esi
74 subl $1b, %esi
75
76 movl %ecx, efi32_config(%esi) /* Handle */
77 movl %edx, efi32_config+8(%esi) /* EFI System table pointer */
78
79 /* Relocate efi_config->call() */
80 leal efi32_config(%esi), %eax
81 add %esi, 88(%eax)
82 pushl %eax
832:
57 call efi_main 84 call efi_main
58 cmpl $0, %eax 85 cmpl $0, %eax
59 movl %eax, %esi 86 movl %eax, %esi
60 jne 2f 87 jne 2f
611: 88fail:
62 /* EFI init failed, so hang. */ 89 /* EFI init failed, so hang. */
63 hlt 90 hlt
64 jmp 1b 91 jmp fail
652: 922:
66 call 3f 93 call 3f
673: 943:
@@ -202,6 +229,15 @@ relocated:
202 xorl %ebx, %ebx 229 xorl %ebx, %ebx
203 jmp *%eax 230 jmp *%eax
204 231
232#ifdef CONFIG_EFI_STUB
233 .data
234efi32_config:
235 .fill 11,8,0
236 .long efi_call_phys
237 .long 0
238 .byte 0
239#endif
240
205/* 241/*
206 * Stack and heap for uncompression 242 * Stack and heap for uncompression
207 */ 243 */
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index c5c1ae0997e7..57e58a5fa210 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -113,7 +113,8 @@ ENTRY(startup_32)
113 lgdt gdt(%ebp) 113 lgdt gdt(%ebp)
114 114
115 /* Enable PAE mode */ 115 /* Enable PAE mode */
116 movl $(X86_CR4_PAE), %eax 116 movl %cr4, %eax
117 orl $X86_CR4_PAE, %eax
117 movl %eax, %cr4 118 movl %eax, %cr4
118 119
119 /* 120 /*
@@ -178,6 +179,13 @@ ENTRY(startup_32)
178 */ 179 */
179 pushl $__KERNEL_CS 180 pushl $__KERNEL_CS
180 leal startup_64(%ebp), %eax 181 leal startup_64(%ebp), %eax
182#ifdef CONFIG_EFI_MIXED
183 movl efi32_config(%ebp), %ebx
184 cmp $0, %ebx
185 jz 1f
186 leal handover_entry(%ebp), %eax
1871:
188#endif
181 pushl %eax 189 pushl %eax
182 190
183 /* Enter paged protected Mode, activating Long Mode */ 191 /* Enter paged protected Mode, activating Long Mode */
@@ -188,6 +196,30 @@ ENTRY(startup_32)
188 lret 196 lret
189ENDPROC(startup_32) 197ENDPROC(startup_32)
190 198
199#ifdef CONFIG_EFI_MIXED
200 .org 0x190
201ENTRY(efi32_stub_entry)
202 add $0x4, %esp /* Discard return address */
203 popl %ecx
204 popl %edx
205 popl %esi
206
207 leal (BP_scratch+4)(%esi), %esp
208 call 1f
2091: pop %ebp
210 subl $1b, %ebp
211
212 movl %ecx, efi32_config(%ebp)
213 movl %edx, efi32_config+8(%ebp)
214 sgdtl efi32_boot_gdt(%ebp)
215
216 leal efi32_config(%ebp), %eax
217 movl %eax, efi_config(%ebp)
218
219 jmp startup_32
220ENDPROC(efi32_stub_entry)
221#endif
222
191 .code64 223 .code64
192 .org 0x200 224 .org 0x200
193ENTRY(startup_64) 225ENTRY(startup_64)
@@ -209,26 +241,48 @@ ENTRY(startup_64)
209 jmp preferred_addr 241 jmp preferred_addr
210 242
211ENTRY(efi_pe_entry) 243ENTRY(efi_pe_entry)
212 mov %rcx, %rdi 244 movq %rcx, efi64_config(%rip) /* Handle */
213 mov %rdx, %rsi 245 movq %rdx, efi64_config+8(%rip) /* EFI System table pointer */
214 pushq %rdi 246
215 pushq %rsi 247 leaq efi64_config(%rip), %rax
248 movq %rax, efi_config(%rip)
249
250 call 1f
2511: popq %rbp
252 subq $1b, %rbp
253
254 /*
255 * Relocate efi_config->call().
256 */
257 addq %rbp, efi64_config+88(%rip)
258
259 movq %rax, %rdi
216 call make_boot_params 260 call make_boot_params
217 cmpq $0,%rax 261 cmpq $0,%rax
218 je 1f 262 je fail
219 mov %rax, %rdx 263 mov %rax, %rsi
220 popq %rsi 264 jmp 2f /* Skip the relocation */
221 popq %rdi
222 265
223ENTRY(efi_stub_entry) 266handover_entry:
267 call 1f
2681: popq %rbp
269 subq $1b, %rbp
270
271 /*
272 * Relocate efi_config->call().
273 */
274 movq efi_config(%rip), %rax
275 addq %rbp, 88(%rax)
2762:
277 movq efi_config(%rip), %rdi
224 call efi_main 278 call efi_main
225 movq %rax,%rsi 279 movq %rax,%rsi
226 cmpq $0,%rax 280 cmpq $0,%rax
227 jne 2f 281 jne 2f
2281: 282fail:
229 /* EFI init failed, so hang. */ 283 /* EFI init failed, so hang. */
230 hlt 284 hlt
231 jmp 1b 285 jmp fail
2322: 2862:
233 call 3f 287 call 3f
2343: 2883:
@@ -307,6 +361,20 @@ preferred_addr:
307 leaq relocated(%rbx), %rax 361 leaq relocated(%rbx), %rax
308 jmp *%rax 362 jmp *%rax
309 363
364#ifdef CONFIG_EFI_STUB
365 .org 0x390
366ENTRY(efi64_stub_entry)
367 movq %rdi, efi64_config(%rip) /* Handle */
368 movq %rsi, efi64_config+8(%rip) /* EFI System table pointer */
369
370 leaq efi64_config(%rip), %rax
371 movq %rax, efi_config(%rip)
372
373 movq %rdx, %rsi
374 jmp handover_entry
375ENDPROC(efi64_stub_entry)
376#endif
377
310 .text 378 .text
311relocated: 379relocated:
312 380
@@ -372,6 +440,25 @@ gdt:
372 .quad 0x0000000000000000 /* TS continued */ 440 .quad 0x0000000000000000 /* TS continued */
373gdt_end: 441gdt_end:
374 442
443#ifdef CONFIG_EFI_STUB
444efi_config:
445 .quad 0
446
447#ifdef CONFIG_EFI_MIXED
448 .global efi32_config
449efi32_config:
450 .fill 11,8,0
451 .quad efi64_thunk
452 .byte 0
453#endif
454
455 .global efi64_config
456efi64_config:
457 .fill 11,8,0
458 .quad efi_call6
459 .byte 1
460#endif /* CONFIG_EFI_STUB */
461
375/* 462/*
376 * Stack and heap for uncompression 463 * Stack and heap for uncompression
377 */ 464 */
diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
index 100a9a10076a..f0d0b20fe149 100644
--- a/arch/x86/boot/cpucheck.c
+++ b/arch/x86/boot/cpucheck.c
@@ -67,6 +67,13 @@ static int is_transmeta(void)
67 cpu_vendor[2] == A32('M', 'x', '8', '6'); 67 cpu_vendor[2] == A32('M', 'x', '8', '6');
68} 68}
69 69
70static int is_intel(void)
71{
72 return cpu_vendor[0] == A32('G', 'e', 'n', 'u') &&
73 cpu_vendor[1] == A32('i', 'n', 'e', 'I') &&
74 cpu_vendor[2] == A32('n', 't', 'e', 'l');
75}
76
70/* Returns a bitmask of which words we have error bits in */ 77/* Returns a bitmask of which words we have error bits in */
71static int check_cpuflags(void) 78static int check_cpuflags(void)
72{ 79{
@@ -153,6 +160,19 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
153 asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx)); 160 asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
154 161
155 err = check_cpuflags(); 162 err = check_cpuflags();
163 } else if (err == 0x01 &&
164 !(err_flags[0] & ~(1 << X86_FEATURE_PAE)) &&
165 is_intel() && cpu.level == 6 &&
166 (cpu.model == 9 || cpu.model == 13)) {
167 /* PAE is disabled on this Pentium M but can be forced */
168 if (cmdline_find_option_bool("forcepae")) {
169 puts("WARNING: Forcing PAE in CPU flags\n");
170 set_bit(X86_FEATURE_PAE, cpu.flags);
171 err = check_cpuflags();
172 }
173 else {
174 puts("WARNING: PAE disabled. Use parameter 'forcepae' to enable at your own risk!\n");
175 }
156 } 176 }
157 177
158 if (err_flags_ptr) 178 if (err_flags_ptr)
diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
index ec3b8ba68096..0ca9a5c362bc 100644
--- a/arch/x86/boot/header.S
+++ b/arch/x86/boot/header.S
@@ -283,7 +283,7 @@ _start:
283 # Part 2 of the header, from the old setup.S 283 # Part 2 of the header, from the old setup.S
284 284
285 .ascii "HdrS" # header signature 285 .ascii "HdrS" # header signature
286 .word 0x020c # header version number (>= 0x0105) 286 .word 0x020d # header version number (>= 0x0105)
287 # or else old loadlin-1.5 will fail) 287 # or else old loadlin-1.5 will fail)
288 .globl realmode_swtch 288 .globl realmode_swtch
289realmode_swtch: .word 0, 0 # default_switch, SETUPSEG 289realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
@@ -350,7 +350,7 @@ cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
350 # can be located anywhere in 350 # can be located anywhere in
351 # low memory 0x10000 or higher. 351 # low memory 0x10000 or higher.
352 352
353ramdisk_max: .long 0x7fffffff 353initrd_addr_max: .long 0x7fffffff
354 # (Header version 0x0203 or later) 354 # (Header version 0x0203 or later)
355 # The highest safe address for 355 # The highest safe address for
356 # the contents of an initrd 356 # the contents of an initrd
@@ -375,7 +375,8 @@ xloadflags:
375# define XLF0 0 375# define XLF0 0
376#endif 376#endif
377 377
378#if defined(CONFIG_RELOCATABLE) && defined(CONFIG_X86_64) 378#if defined(CONFIG_RELOCATABLE) && defined(CONFIG_X86_64) && \
379 !defined(CONFIG_EFI_MIXED)
379 /* kernel/boot_param/ramdisk could be loaded above 4g */ 380 /* kernel/boot_param/ramdisk could be loaded above 4g */
380# define XLF1 XLF_CAN_BE_LOADED_ABOVE_4G 381# define XLF1 XLF_CAN_BE_LOADED_ABOVE_4G
381#else 382#else
@@ -383,10 +384,14 @@ xloadflags:
383#endif 384#endif
384 385
385#ifdef CONFIG_EFI_STUB 386#ifdef CONFIG_EFI_STUB
386# ifdef CONFIG_X86_64 387# ifdef CONFIG_EFI_MIXED
387# define XLF23 XLF_EFI_HANDOVER_64 /* 64-bit EFI handover ok */ 388# define XLF23 (XLF_EFI_HANDOVER_32|XLF_EFI_HANDOVER_64)
388# else 389# else
389# define XLF23 XLF_EFI_HANDOVER_32 /* 32-bit EFI handover ok */ 390# ifdef CONFIG_X86_64
391# define XLF23 XLF_EFI_HANDOVER_64 /* 64-bit EFI handover ok */
392# else
393# define XLF23 XLF_EFI_HANDOVER_32 /* 32-bit EFI handover ok */
394# endif
390# endif 395# endif
391#else 396#else
392# define XLF23 0 397# define XLF23 0
@@ -426,13 +431,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
426#define INIT_SIZE VO_INIT_SIZE 431#define INIT_SIZE VO_INIT_SIZE
427#endif 432#endif
428init_size: .long INIT_SIZE # kernel initialization size 433init_size: .long INIT_SIZE # kernel initialization size
429handover_offset: 434handover_offset: .long 0 # Filled in by build.c
430#ifdef CONFIG_EFI_STUB
431 .long 0x30 # offset to the handover
432 # protocol entry point
433#else
434 .long 0
435#endif
436 435
437# End of setup header ##################################################### 436# End of setup header #####################################################
438 437
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 8e15b22391fc..1a2f2121cada 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -53,7 +53,8 @@ int is_big_kernel;
53 53
54#define PECOFF_RELOC_RESERVE 0x20 54#define PECOFF_RELOC_RESERVE 0x20
55 55
56unsigned long efi_stub_entry; 56unsigned long efi32_stub_entry;
57unsigned long efi64_stub_entry;
57unsigned long efi_pe_entry; 58unsigned long efi_pe_entry;
58unsigned long startup_64; 59unsigned long startup_64;
59 60
@@ -219,6 +220,52 @@ static void update_pecoff_text(unsigned int text_start, unsigned int file_sz)
219 update_pecoff_section_header(".text", text_start, text_sz); 220 update_pecoff_section_header(".text", text_start, text_sz);
220} 221}
221 222
223static int reserve_pecoff_reloc_section(int c)
224{
225 /* Reserve 0x20 bytes for .reloc section */
226 memset(buf+c, 0, PECOFF_RELOC_RESERVE);
227 return PECOFF_RELOC_RESERVE;
228}
229
230static void efi_stub_defaults(void)
231{
232 /* Defaults for old kernel */
233#ifdef CONFIG_X86_32
234 efi_pe_entry = 0x10;
235#else
236 efi_pe_entry = 0x210;
237 startup_64 = 0x200;
238#endif
239}
240
241static void efi_stub_entry_update(void)
242{
243 unsigned long addr = efi32_stub_entry;
244
245#ifdef CONFIG_X86_64
246 /* Yes, this is really how we defined it :( */
247 addr = efi64_stub_entry - 0x200;
248#endif
249
250#ifdef CONFIG_EFI_MIXED
251 if (efi32_stub_entry != addr)
252 die("32-bit and 64-bit EFI entry points do not match\n");
253#endif
254 put_unaligned_le32(addr, &buf[0x264]);
255}
256
257#else
258
259static inline void update_pecoff_setup_and_reloc(unsigned int size) {}
260static inline void update_pecoff_text(unsigned int text_start,
261 unsigned int file_sz) {}
262static inline void efi_stub_defaults(void) {}
263static inline void efi_stub_entry_update(void) {}
264
265static inline int reserve_pecoff_reloc_section(int c)
266{
267 return 0;
268}
222#endif /* CONFIG_EFI_STUB */ 269#endif /* CONFIG_EFI_STUB */
223 270
224 271
@@ -250,7 +297,8 @@ static void parse_zoffset(char *fname)
250 p = (char *)buf; 297 p = (char *)buf;
251 298
252 while (p && *p) { 299 while (p && *p) {
253 PARSE_ZOFS(p, efi_stub_entry); 300 PARSE_ZOFS(p, efi32_stub_entry);
301 PARSE_ZOFS(p, efi64_stub_entry);
254 PARSE_ZOFS(p, efi_pe_entry); 302 PARSE_ZOFS(p, efi_pe_entry);
255 PARSE_ZOFS(p, startup_64); 303 PARSE_ZOFS(p, startup_64);
256 304
@@ -271,15 +319,7 @@ int main(int argc, char ** argv)
271 void *kernel; 319 void *kernel;
272 u32 crc = 0xffffffffUL; 320 u32 crc = 0xffffffffUL;
273 321
274 /* Defaults for old kernel */ 322 efi_stub_defaults();
275#ifdef CONFIG_X86_32
276 efi_pe_entry = 0x10;
277 efi_stub_entry = 0x30;
278#else
279 efi_pe_entry = 0x210;
280 efi_stub_entry = 0x230;
281 startup_64 = 0x200;
282#endif
283 323
284 if (argc != 5) 324 if (argc != 5)
285 usage(); 325 usage();
@@ -302,11 +342,7 @@ int main(int argc, char ** argv)
302 die("Boot block hasn't got boot flag (0xAA55)"); 342 die("Boot block hasn't got boot flag (0xAA55)");
303 fclose(file); 343 fclose(file);
304 344
305#ifdef CONFIG_EFI_STUB 345 c += reserve_pecoff_reloc_section(c);
306 /* Reserve 0x20 bytes for .reloc section */
307 memset(buf+c, 0, PECOFF_RELOC_RESERVE);
308 c += PECOFF_RELOC_RESERVE;
309#endif
310 346
311 /* Pad unused space with zeros */ 347 /* Pad unused space with zeros */
312 setup_sectors = (c + 511) / 512; 348 setup_sectors = (c + 511) / 512;
@@ -315,9 +351,7 @@ int main(int argc, char ** argv)
315 i = setup_sectors*512; 351 i = setup_sectors*512;
316 memset(buf+c, 0, i-c); 352 memset(buf+c, 0, i-c);
317 353
318#ifdef CONFIG_EFI_STUB
319 update_pecoff_setup_and_reloc(i); 354 update_pecoff_setup_and_reloc(i);
320#endif
321 355
322 /* Set the default root device */ 356 /* Set the default root device */
323 put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); 357 put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]);
@@ -342,14 +376,9 @@ int main(int argc, char ** argv)
342 buf[0x1f1] = setup_sectors-1; 376 buf[0x1f1] = setup_sectors-1;
343 put_unaligned_le32(sys_size, &buf[0x1f4]); 377 put_unaligned_le32(sys_size, &buf[0x1f4]);
344 378
345#ifdef CONFIG_EFI_STUB
346 update_pecoff_text(setup_sectors * 512, sz + i + ((sys_size * 16) - sz)); 379 update_pecoff_text(setup_sectors * 512, sz + i + ((sys_size * 16) - sz));
347 380
348#ifdef CONFIG_X86_64 /* Yes, this is really how we defined it :( */ 381 efi_stub_entry_update();
349 efi_stub_entry -= 0x200;
350#endif
351 put_unaligned_le32(efi_stub_entry, &buf[0x264]);
352#endif
353 382
354 crc = partial_crc32(buf, i, crc); 383 crc = partial_crc32(buf, i, crc);
355 if (fwrite(buf, 1, i, dest) != i) 384 if (fwrite(buf, 1, i, dest) != i)
diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index 7f669853317a..a8fee078b92f 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -5,3 +5,4 @@ genhdr-y += unistd_64.h
5genhdr-y += unistd_x32.h 5genhdr-y += unistd_x32.h
6 6
7generic-y += clkdev.h 7generic-y += clkdev.h
8generic-y += mcs_spinlock.h
diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h
index a54ee1d054d9..aaac3b2fb746 100644
--- a/arch/x86/include/asm/amd_nb.h
+++ b/arch/x86/include/asm/amd_nb.h
@@ -19,7 +19,7 @@ extern int amd_cache_northbridges(void);
19extern void amd_flush_garts(void); 19extern void amd_flush_garts(void);
20extern int amd_numa_init(void); 20extern int amd_numa_init(void);
21extern int amd_get_subcaches(int); 21extern int amd_get_subcaches(int);
22extern int amd_set_subcaches(int, int); 22extern int amd_set_subcaches(int, unsigned long);
23 23
24struct amd_l3_cache { 24struct amd_l3_cache {
25 unsigned indices; 25 unsigned indices;
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index 1d2091a226bc..19b0ebafcd3e 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -93,9 +93,6 @@ static inline int is_vsmp_box(void)
93 return 0; 93 return 0;
94} 94}
95#endif 95#endif
96extern void xapic_wait_icr_idle(void);
97extern u32 safe_xapic_wait_icr_idle(void);
98extern void xapic_icr_write(u32, u32);
99extern int setup_profiling_timer(unsigned int); 96extern int setup_profiling_timer(unsigned int);
100 97
101static inline void native_apic_mem_write(u32 reg, u32 v) 98static inline void native_apic_mem_write(u32 reg, u32 v)
@@ -184,7 +181,6 @@ extern int x2apic_phys;
184extern int x2apic_preenabled; 181extern int x2apic_preenabled;
185extern void check_x2apic(void); 182extern void check_x2apic(void);
186extern void enable_x2apic(void); 183extern void enable_x2apic(void);
187extern void x2apic_icr_write(u32 low, u32 id);
188static inline int x2apic_enabled(void) 184static inline int x2apic_enabled(void)
189{ 185{
190 u64 msr; 186 u64 msr;
@@ -221,7 +217,6 @@ static inline void x2apic_force_phys(void)
221{ 217{
222} 218}
223 219
224#define nox2apic 0
225#define x2apic_preenabled 0 220#define x2apic_preenabled 0
226#define x2apic_supported() 0 221#define x2apic_supported() 0
227#endif 222#endif
@@ -351,7 +346,7 @@ struct apic {
351 int trampoline_phys_low; 346 int trampoline_phys_low;
352 int trampoline_phys_high; 347 int trampoline_phys_high;
353 348
354 void (*wait_for_init_deassert)(atomic_t *deassert); 349 bool wait_for_init_deassert;
355 void (*smp_callin_clear_local_apic)(void); 350 void (*smp_callin_clear_local_apic)(void);
356 void (*inquire_remote_apic)(int apicid); 351 void (*inquire_remote_apic)(int apicid);
357 352
@@ -517,13 +512,6 @@ extern int default_cpu_present_to_apicid(int mps_cpu);
517extern int default_check_phys_apicid_present(int phys_apicid); 512extern int default_check_phys_apicid_present(int phys_apicid);
518#endif 513#endif
519 514
520static inline void default_wait_for_init_deassert(atomic_t *deassert)
521{
522 while (!atomic_read(deassert))
523 cpu_relax();
524 return;
525}
526
527extern void generic_bigsmp_probe(void); 515extern void generic_bigsmp_probe(void);
528 516
529 517
diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
index 04a48903b2eb..69bbb4845020 100644
--- a/arch/x86/include/asm/barrier.h
+++ b/arch/x86/include/asm/barrier.h
@@ -85,11 +85,7 @@
85#else 85#else
86# define smp_rmb() barrier() 86# define smp_rmb() barrier()
87#endif 87#endif
88#ifdef CONFIG_X86_OOSTORE 88#define smp_wmb() barrier()
89# define smp_wmb() wmb()
90#else
91# define smp_wmb() barrier()
92#endif
93#define smp_read_barrier_depends() read_barrier_depends() 89#define smp_read_barrier_depends() read_barrier_depends()
94#define set_mb(var, value) do { (void)xchg(&var, value); } while (0) 90#define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
95#else /* !SMP */ 91#else /* !SMP */
@@ -100,7 +96,7 @@
100#define set_mb(var, value) do { var = value; barrier(); } while (0) 96#define set_mb(var, value) do { var = value; barrier(); } while (0)
101#endif /* SMP */ 97#endif /* SMP */
102 98
103#if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE) 99#if defined(CONFIG_X86_PPRO_FENCE)
104 100
105/* 101/*
106 * For either of these options x86 doesn't have a strong TSO memory 102 * For either of these options x86 doesn't have a strong TSO memory
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index e099f9502ace..bc507d7640f8 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -217,9 +217,14 @@
217#define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */ 217#define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
218#define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */ 218#define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
219#define X86_FEATURE_MPX (9*32+14) /* Memory Protection Extension */ 219#define X86_FEATURE_MPX (9*32+14) /* Memory Protection Extension */
220#define X86_FEATURE_AVX512F (9*32+16) /* AVX-512 Foundation */
220#define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */ 221#define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
221#define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */ 222#define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
222#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */ 223#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
224#define X86_FEATURE_CLFLUSHOPT (9*32+23) /* CLFLUSHOPT instruction */
225#define X86_FEATURE_AVX512PF (9*32+26) /* AVX-512 Prefetch */
226#define X86_FEATURE_AVX512ER (9*32+27) /* AVX-512 Exponential and Reciprocal */
227#define X86_FEATURE_AVX512CD (9*32+28) /* AVX-512 Conflict Detection */
223 228
224/* 229/*
225 * BUG word(s) 230 * BUG word(s)
diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 3b978c472d08..0869434eaf72 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -19,9 +19,11 @@
19 */ 19 */
20#define EFI_OLD_MEMMAP EFI_ARCH_1 20#define EFI_OLD_MEMMAP EFI_ARCH_1
21 21
22#define EFI32_LOADER_SIGNATURE "EL32"
23#define EFI64_LOADER_SIGNATURE "EL64"
24
22#ifdef CONFIG_X86_32 25#ifdef CONFIG_X86_32
23 26
24#define EFI_LOADER_SIGNATURE "EL32"
25 27
26extern unsigned long asmlinkage efi_call_phys(void *, ...); 28extern unsigned long asmlinkage efi_call_phys(void *, ...);
27 29
@@ -57,8 +59,6 @@ extern unsigned long asmlinkage efi_call_phys(void *, ...);
57 59
58#else /* !CONFIG_X86_32 */ 60#else /* !CONFIG_X86_32 */
59 61
60#define EFI_LOADER_SIGNATURE "EL64"
61
62extern u64 efi_call0(void *fp); 62extern u64 efi_call0(void *fp);
63extern u64 efi_call1(void *fp, u64 arg1); 63extern u64 efi_call1(void *fp, u64 arg1);
64extern u64 efi_call2(void *fp, u64 arg1, u64 arg2); 64extern u64 efi_call2(void *fp, u64 arg1, u64 arg2);
@@ -119,7 +119,6 @@ extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
119#endif /* CONFIG_X86_32 */ 119#endif /* CONFIG_X86_32 */
120 120
121extern int add_efi_memmap; 121extern int add_efi_memmap;
122extern unsigned long x86_efi_facility;
123extern struct efi_scratch efi_scratch; 122extern struct efi_scratch efi_scratch;
124extern void efi_set_executable(efi_memory_desc_t *md, bool executable); 123extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
125extern int efi_memblock_x86_reserve_range(void); 124extern int efi_memblock_x86_reserve_range(void);
@@ -130,8 +129,13 @@ extern void efi_memory_uc(u64 addr, unsigned long size);
130extern void __init efi_map_region(efi_memory_desc_t *md); 129extern void __init efi_map_region(efi_memory_desc_t *md);
131extern void __init efi_map_region_fixed(efi_memory_desc_t *md); 130extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
132extern void efi_sync_low_kernel_mappings(void); 131extern void efi_sync_low_kernel_mappings(void);
133extern void efi_setup_page_tables(void); 132extern int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
133extern void efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
134extern void __init old_map_region(efi_memory_desc_t *md); 134extern void __init old_map_region(efi_memory_desc_t *md);
135extern void __init runtime_code_page_mkexec(void);
136extern void __init efi_runtime_mkexec(void);
137extern void __init efi_dump_pagetable(void);
138extern void __init efi_apply_memmap_quirks(void);
135 139
136struct efi_setup_data { 140struct efi_setup_data {
137 u64 fw_vendor; 141 u64 fw_vendor;
@@ -150,8 +154,40 @@ static inline bool efi_is_native(void)
150 return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT); 154 return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
151} 155}
152 156
157static inline bool efi_runtime_supported(void)
158{
159 if (efi_is_native())
160 return true;
161
162 if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_enabled(EFI_OLD_MEMMAP))
163 return true;
164
165 return false;
166}
167
153extern struct console early_efi_console; 168extern struct console early_efi_console;
154extern void parse_efi_setup(u64 phys_addr, u32 data_len); 169extern void parse_efi_setup(u64 phys_addr, u32 data_len);
170
171#ifdef CONFIG_EFI_MIXED
172extern void efi_thunk_runtime_setup(void);
173extern efi_status_t efi_thunk_set_virtual_address_map(
174 void *phys_set_virtual_address_map,
175 unsigned long memory_map_size,
176 unsigned long descriptor_size,
177 u32 descriptor_version,
178 efi_memory_desc_t *virtual_map);
179#else
180static inline void efi_thunk_runtime_setup(void) {}
181static inline efi_status_t efi_thunk_set_virtual_address_map(
182 void *phys_set_virtual_address_map,
183 unsigned long memory_map_size,
184 unsigned long descriptor_size,
185 u32 descriptor_version,
186 efi_memory_desc_t *virtual_map)
187{
188 return EFI_SUCCESS;
189}
190#endif /* CONFIG_EFI_MIXED */
155#else 191#else
156/* 192/*
157 * IF EFI is not configured, have the EFI calls return -ENOSYS. 193 * IF EFI is not configured, have the EFI calls return -ENOSYS.
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index 34f69cb9350a..91d9c69a629e 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -237,7 +237,7 @@ memcpy_toio(volatile void __iomem *dst, const void *src, size_t count)
237 237
238static inline void flush_write_buffers(void) 238static inline void flush_write_buffers(void)
239{ 239{
240#if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE) 240#if defined(CONFIG_X86_PPRO_FENCE)
241 asm volatile("lock; addl $0,0(%%esp)": : :"memory"); 241 asm volatile("lock; addl $0,0(%%esp)": : :"memory");
242#endif 242#endif
243} 243}
diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
index e139b13f2a33..de36f22eb0b9 100644
--- a/arch/x86/include/asm/msr.h
+++ b/arch/x86/include/asm/msr.h
@@ -214,6 +214,8 @@ do { \
214 214
215struct msr *msrs_alloc(void); 215struct msr *msrs_alloc(void);
216void msrs_free(struct msr *msrs); 216void msrs_free(struct msr *msrs);
217int msr_set_bit(u32 msr, u8 bit);
218int msr_clear_bit(u32 msr, u8 bit);
217 219
218#ifdef CONFIG_SMP 220#ifdef CONFIG_SMP
219int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h); 221int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
index 86f9301903c8..5f2fc4441b11 100644
--- a/arch/x86/include/asm/nmi.h
+++ b/arch/x86/include/asm/nmi.h
@@ -1,6 +1,7 @@
1#ifndef _ASM_X86_NMI_H 1#ifndef _ASM_X86_NMI_H
2#define _ASM_X86_NMI_H 2#define _ASM_X86_NMI_H
3 3
4#include <linux/irq_work.h>
4#include <linux/pm.h> 5#include <linux/pm.h>
5#include <asm/irq.h> 6#include <asm/irq.h>
6#include <asm/io.h> 7#include <asm/io.h>
@@ -38,6 +39,8 @@ typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
38struct nmiaction { 39struct nmiaction {
39 struct list_head list; 40 struct list_head list;
40 nmi_handler_t handler; 41 nmi_handler_t handler;
42 u64 max_duration;
43 struct irq_work irq_work;
41 unsigned long flags; 44 unsigned long flags;
42 const char *name; 45 const char *name;
43}; 46};
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index bbc8b12fa443..b459ddf27d64 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -15,9 +15,10 @@
15 : (prot)) 15 : (prot))
16 16
17#ifndef __ASSEMBLY__ 17#ifndef __ASSEMBLY__
18
19#include <asm/x86_init.h> 18#include <asm/x86_init.h>
20 19
20void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd);
21
21/* 22/*
22 * ZERO_PAGE is a global shared page that is always zero: used 23 * ZERO_PAGE is a global shared page that is always zero: used
23 * for zero-mapped memory areas etc.. 24 * for zero-mapped memory areas etc..
diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
index 1aa9ccd43223..708f19fb4fc7 100644
--- a/arch/x86/include/asm/pgtable_types.h
+++ b/arch/x86/include/asm/pgtable_types.h
@@ -382,9 +382,13 @@ static inline void update_page_count(int level, unsigned long pages) { }
382 * as a pte too. 382 * as a pte too.
383 */ 383 */
384extern pte_t *lookup_address(unsigned long address, unsigned int *level); 384extern pte_t *lookup_address(unsigned long address, unsigned int *level);
385extern pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
386 unsigned int *level);
385extern phys_addr_t slow_virt_to_phys(void *__address); 387extern phys_addr_t slow_virt_to_phys(void *__address);
386extern int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address, 388extern int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
387 unsigned numpages, unsigned long page_flags); 389 unsigned numpages, unsigned long page_flags);
390void kernel_unmap_pages_in_pgd(pgd_t *root, unsigned long address,
391 unsigned numpages);
388#endif /* !__ASSEMBLY__ */ 392#endif /* !__ASSEMBLY__ */
389 393
390#endif /* _ASM_X86_PGTABLE_DEFS_H */ 394#endif /* _ASM_X86_PGTABLE_DEFS_H */
diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index 645cad2c95ff..e820c080a4e9 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -191,6 +191,14 @@ static inline void clflush(volatile void *__p)
191 asm volatile("clflush %0" : "+m" (*(volatile char __force *)__p)); 191 asm volatile("clflush %0" : "+m" (*(volatile char __force *)__p));
192} 192}
193 193
194static inline void clflushopt(volatile void *__p)
195{
196 alternative_io(".byte " __stringify(NOP_DS_PREFIX) "; clflush %P0",
197 ".byte 0x66; clflush %P0",
198 X86_FEATURE_CLFLUSHOPT,
199 "+m" (*(volatile char __force *)__p));
200}
201
194#define nop() asm volatile ("nop") 202#define nop() asm volatile ("nop")
195 203
196 204
diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
index bf156ded74b5..0f62f5482d91 100644
--- a/arch/x86/include/asm/spinlock.h
+++ b/arch/x86/include/asm/spinlock.h
@@ -26,10 +26,9 @@
26# define LOCK_PTR_REG "D" 26# define LOCK_PTR_REG "D"
27#endif 27#endif
28 28
29#if defined(CONFIG_X86_32) && \ 29#if defined(CONFIG_X86_32) && (defined(CONFIG_X86_PPRO_FENCE))
30 (defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE))
31/* 30/*
32 * On PPro SMP or if we are using OOSTORE, we use a locked operation to unlock 31 * On PPro SMP, we use a locked operation to unlock
33 * (PPro errata 66, 92) 32 * (PPro errata 66, 92)
34 */ 33 */
35# define UNLOCK_LOCK_PREFIX LOCK_PREFIX 34# define UNLOCK_LOCK_PREFIX LOCK_PREFIX
diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index e6d90babc245..04905bfc508b 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -62,7 +62,7 @@ static inline void __flush_tlb_all(void)
62 62
63static inline void __flush_tlb_one(unsigned long addr) 63static inline void __flush_tlb_one(unsigned long addr)
64{ 64{
65 count_vm_event(NR_TLB_LOCAL_FLUSH_ONE); 65 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ONE);
66 __flush_tlb_single(addr); 66 __flush_tlb_single(addr);
67} 67}
68 68
@@ -93,13 +93,13 @@ static inline void __flush_tlb_one(unsigned long addr)
93 */ 93 */
94static inline void __flush_tlb_up(void) 94static inline void __flush_tlb_up(void)
95{ 95{
96 count_vm_event(NR_TLB_LOCAL_FLUSH_ALL); 96 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL);
97 __flush_tlb(); 97 __flush_tlb();
98} 98}
99 99
100static inline void flush_tlb_all(void) 100static inline void flush_tlb_all(void)
101{ 101{
102 count_vm_event(NR_TLB_LOCAL_FLUSH_ALL); 102 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL);
103 __flush_tlb_all(); 103 __flush_tlb_all();
104} 104}
105 105
diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index d35f24e231cd..b28097e4c8c3 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -119,9 +119,10 @@ static inline void setup_node_to_cpumask_map(void) { }
119 119
120extern const struct cpumask *cpu_coregroup_mask(int cpu); 120extern const struct cpumask *cpu_coregroup_mask(int cpu);
121 121
122#ifdef ENABLE_TOPO_DEFINES
123#define topology_physical_package_id(cpu) (cpu_data(cpu).phys_proc_id) 122#define topology_physical_package_id(cpu) (cpu_data(cpu).phys_proc_id)
124#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) 123#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id)
124
125#ifdef ENABLE_TOPO_DEFINES
125#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) 126#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
126#define topology_thread_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) 127#define topology_thread_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
127#endif 128#endif
@@ -133,12 +134,6 @@ static inline void arch_fix_phys_package_id(int num, u32 slot)
133struct pci_bus; 134struct pci_bus;
134void x86_pci_root_bus_resources(int bus, struct list_head *resources); 135void x86_pci_root_bus_resources(int bus, struct list_head *resources);
135 136
136#ifdef CONFIG_SMP
137#define mc_capable() ((boot_cpu_data.x86_max_cores > 1) && \
138 (cpumask_weight(cpu_core_mask(0)) != nr_cpu_ids))
139#define smt_capable() (smp_num_siblings > 1)
140#endif
141
142#ifdef CONFIG_NUMA 137#ifdef CONFIG_NUMA
143extern int get_mp_bus_to_node(int busnum); 138extern int get_mp_bus_to_node(int busnum);
144extern void set_mp_bus_to_node(int busnum, int node); 139extern void set_mp_bus_to_node(int busnum, int node);
diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h
index 57ae63cd6ee2..94605c0e9cee 100644
--- a/arch/x86/include/asm/tsc.h
+++ b/arch/x86/include/asm/tsc.h
@@ -66,6 +66,6 @@ extern void tsc_save_sched_clock_state(void);
66extern void tsc_restore_sched_clock_state(void); 66extern void tsc_restore_sched_clock_state(void);
67 67
68/* MSR based TSC calibration for Intel Atom SoC platforms */ 68/* MSR based TSC calibration for Intel Atom SoC platforms */
69int try_msr_calibrate_tsc(unsigned long *fast_calibrate); 69unsigned long try_msr_calibrate_tsc(void);
70 70
71#endif /* _ASM_X86_TSC_H */ 71#endif /* _ASM_X86_TSC_H */
diff --git a/arch/x86/include/asm/unistd.h b/arch/x86/include/asm/unistd.h
index c2a48139c340..3f556c6a0157 100644
--- a/arch/x86/include/asm/unistd.h
+++ b/arch/x86/include/asm/unistd.h
@@ -23,6 +23,9 @@
23# include <asm/unistd_64.h> 23# include <asm/unistd_64.h>
24# include <asm/unistd_64_x32.h> 24# include <asm/unistd_64_x32.h>
25# define __ARCH_WANT_COMPAT_SYS_TIME 25# define __ARCH_WANT_COMPAT_SYS_TIME
26# define __ARCH_WANT_COMPAT_SYS_GETDENTS64
27# define __ARCH_WANT_COMPAT_SYS_PREADV64
28# define __ARCH_WANT_COMPAT_SYS_PWRITEV64
26 29
27# endif 30# endif
28 31
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 787e1bb5aafc..3e276eb23d1b 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -52,8 +52,7 @@ extern unsigned long set_phys_range_identity(unsigned long pfn_s,
52extern int m2p_add_override(unsigned long mfn, struct page *page, 52extern int m2p_add_override(unsigned long mfn, struct page *page,
53 struct gnttab_map_grant_ref *kmap_op); 53 struct gnttab_map_grant_ref *kmap_op);
54extern int m2p_remove_override(struct page *page, 54extern int m2p_remove_override(struct page *page,
55 struct gnttab_map_grant_ref *kmap_op, 55 struct gnttab_map_grant_ref *kmap_op);
56 unsigned long mfn);
57extern struct page *m2p_find_override(unsigned long mfn); 56extern struct page *m2p_find_override(unsigned long mfn);
58extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn); 57extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
59 58
@@ -122,7 +121,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
122 pfn = m2p_find_override_pfn(mfn, ~0); 121 pfn = m2p_find_override_pfn(mfn, ~0);
123 } 122 }
124 123
125 /* 124 /*
126 * pfn is ~0 if there are no entries in the m2p for mfn or if the 125 * pfn is ~0 if there are no entries in the m2p for mfn or if the
127 * entry doesn't map back to the mfn and m2p_override doesn't have a 126 * entry doesn't map back to the mfn and m2p_override doesn't have a
128 * valid entry for it. 127 * valid entry for it.
diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
index 554738963b28..6c1d7411eb00 100644
--- a/arch/x86/include/asm/xsave.h
+++ b/arch/x86/include/asm/xsave.h
@@ -6,11 +6,14 @@
6 6
7#define XSTATE_CPUID 0x0000000d 7#define XSTATE_CPUID 0x0000000d
8 8
9#define XSTATE_FP 0x1 9#define XSTATE_FP 0x1
10#define XSTATE_SSE 0x2 10#define XSTATE_SSE 0x2
11#define XSTATE_YMM 0x4 11#define XSTATE_YMM 0x4
12#define XSTATE_BNDREGS 0x8 12#define XSTATE_BNDREGS 0x8
13#define XSTATE_BNDCSR 0x10 13#define XSTATE_BNDCSR 0x10
14#define XSTATE_OPMASK 0x20
15#define XSTATE_ZMM_Hi256 0x40
16#define XSTATE_Hi16_ZMM 0x80
14 17
15#define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE) 18#define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE)
16 19
@@ -23,7 +26,8 @@
23#define XSAVE_YMM_OFFSET (XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET) 26#define XSAVE_YMM_OFFSET (XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET)
24 27
25/* Supported features which support lazy state saving */ 28/* Supported features which support lazy state saving */
26#define XSTATE_LAZY (XSTATE_FP | XSTATE_SSE | XSTATE_YMM) 29#define XSTATE_LAZY (XSTATE_FP | XSTATE_SSE | XSTATE_YMM \
30 | XSTATE_OPMASK | XSTATE_ZMM_Hi256 | XSTATE_Hi16_ZMM)
27 31
28/* Supported features which require eager state saving */ 32/* Supported features which require eager state saving */
29#define XSTATE_EAGER (XSTATE_BNDREGS | XSTATE_BNDCSR) 33#define XSTATE_EAGER (XSTATE_BNDREGS | XSTATE_BNDCSR)
diff --git a/arch/x86/include/uapi/asm/msr-index.h b/arch/x86/include/uapi/asm/msr-index.h
index c19fc60ff062..4924f4be2b99 100644
--- a/arch/x86/include/uapi/asm/msr-index.h
+++ b/arch/x86/include/uapi/asm/msr-index.h
@@ -368,33 +368,58 @@
368#define THERM_LOG_THRESHOLD1 (1 << 9) 368#define THERM_LOG_THRESHOLD1 (1 << 9)
369 369
370/* MISC_ENABLE bits: architectural */ 370/* MISC_ENABLE bits: architectural */
371#define MSR_IA32_MISC_ENABLE_FAST_STRING (1ULL << 0) 371#define MSR_IA32_MISC_ENABLE_FAST_STRING_BIT 0
372#define MSR_IA32_MISC_ENABLE_TCC (1ULL << 1) 372#define MSR_IA32_MISC_ENABLE_FAST_STRING (1ULL << MSR_IA32_MISC_ENABLE_FAST_STRING_BIT)
373#define MSR_IA32_MISC_ENABLE_EMON (1ULL << 7) 373#define MSR_IA32_MISC_ENABLE_TCC_BIT 1
374#define MSR_IA32_MISC_ENABLE_BTS_UNAVAIL (1ULL << 11) 374#define MSR_IA32_MISC_ENABLE_TCC (1ULL << MSR_IA32_MISC_ENABLE_TCC_BIT)
375#define MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL (1ULL << 12) 375#define MSR_IA32_MISC_ENABLE_EMON_BIT 7
376#define MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP (1ULL << 16) 376#define MSR_IA32_MISC_ENABLE_EMON (1ULL << MSR_IA32_MISC_ENABLE_EMON_BIT)
377#define MSR_IA32_MISC_ENABLE_MWAIT (1ULL << 18) 377#define MSR_IA32_MISC_ENABLE_BTS_UNAVAIL_BIT 11
378#define MSR_IA32_MISC_ENABLE_LIMIT_CPUID (1ULL << 22) 378#define MSR_IA32_MISC_ENABLE_BTS_UNAVAIL (1ULL << MSR_IA32_MISC_ENABLE_BTS_UNAVAIL_BIT)
379#define MSR_IA32_MISC_ENABLE_XTPR_DISABLE (1ULL << 23) 379#define MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL_BIT 12
380#define MSR_IA32_MISC_ENABLE_XD_DISABLE (1ULL << 34) 380#define MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL (1ULL << MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL_BIT)
381#define MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP_BIT 16
382#define MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP (1ULL << MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP_BIT)
383#define MSR_IA32_MISC_ENABLE_MWAIT_BIT 18
384#define MSR_IA32_MISC_ENABLE_MWAIT (1ULL << MSR_IA32_MISC_ENABLE_MWAIT_BIT)
385#define MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT 22
386#define MSR_IA32_MISC_ENABLE_LIMIT_CPUID (1ULL << MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT);
387#define MSR_IA32_MISC_ENABLE_XTPR_DISABLE_BIT 23
388#define MSR_IA32_MISC_ENABLE_XTPR_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_XTPR_DISABLE_BIT)
389#define MSR_IA32_MISC_ENABLE_XD_DISABLE_BIT 34
390#define MSR_IA32_MISC_ENABLE_XD_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_XD_DISABLE_BIT)
381 391
382/* MISC_ENABLE bits: model-specific, meaning may vary from core to core */ 392/* MISC_ENABLE bits: model-specific, meaning may vary from core to core */
383#define MSR_IA32_MISC_ENABLE_X87_COMPAT (1ULL << 2) 393#define MSR_IA32_MISC_ENABLE_X87_COMPAT_BIT 2
384#define MSR_IA32_MISC_ENABLE_TM1 (1ULL << 3) 394#define MSR_IA32_MISC_ENABLE_X87_COMPAT (1ULL << MSR_IA32_MISC_ENABLE_X87_COMPAT_BIT)
385#define MSR_IA32_MISC_ENABLE_SPLIT_LOCK_DISABLE (1ULL << 4) 395#define MSR_IA32_MISC_ENABLE_TM1_BIT 3
386#define MSR_IA32_MISC_ENABLE_L3CACHE_DISABLE (1ULL << 6) 396#define MSR_IA32_MISC_ENABLE_TM1 (1ULL << MSR_IA32_MISC_ENABLE_TM1_BIT)
387#define MSR_IA32_MISC_ENABLE_SUPPRESS_LOCK (1ULL << 8) 397#define MSR_IA32_MISC_ENABLE_SPLIT_LOCK_DISABLE_BIT 4
388#define MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE (1ULL << 9) 398#define MSR_IA32_MISC_ENABLE_SPLIT_LOCK_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_SPLIT_LOCK_DISABLE_BIT)
389#define MSR_IA32_MISC_ENABLE_FERR (1ULL << 10) 399#define MSR_IA32_MISC_ENABLE_L3CACHE_DISABLE_BIT 6
390#define MSR_IA32_MISC_ENABLE_FERR_MULTIPLEX (1ULL << 10) 400#define MSR_IA32_MISC_ENABLE_L3CACHE_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_L3CACHE_DISABLE_BIT)
391#define MSR_IA32_MISC_ENABLE_TM2 (1ULL << 13) 401#define MSR_IA32_MISC_ENABLE_SUPPRESS_LOCK_BIT 8
392#define MSR_IA32_MISC_ENABLE_ADJ_PREF_DISABLE (1ULL << 19) 402#define MSR_IA32_MISC_ENABLE_SUPPRESS_LOCK (1ULL << MSR_IA32_MISC_ENABLE_SUPPRESS_LOCK_BIT)
393#define MSR_IA32_MISC_ENABLE_SPEEDSTEP_LOCK (1ULL << 20) 403#define MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT 9
394#define MSR_IA32_MISC_ENABLE_L1D_CONTEXT (1ULL << 24) 404#define MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT)
395#define MSR_IA32_MISC_ENABLE_DCU_PREF_DISABLE (1ULL << 37) 405#define MSR_IA32_MISC_ENABLE_FERR_BIT 10
396#define MSR_IA32_MISC_ENABLE_TURBO_DISABLE (1ULL << 38) 406#define MSR_IA32_MISC_ENABLE_FERR (1ULL << MSR_IA32_MISC_ENABLE_FERR_BIT)
397#define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE (1ULL << 39) 407#define MSR_IA32_MISC_ENABLE_FERR_MULTIPLEX_BIT 10
408#define MSR_IA32_MISC_ENABLE_FERR_MULTIPLEX (1ULL << MSR_IA32_MISC_ENABLE_FERR_MULTIPLEX_BIT)
409#define MSR_IA32_MISC_ENABLE_TM2_BIT 13
410#define MSR_IA32_MISC_ENABLE_TM2 (1ULL << MSR_IA32_MISC_ENABLE_TM2_BIT)
411#define MSR_IA32_MISC_ENABLE_ADJ_PREF_DISABLE_BIT 19
412#define MSR_IA32_MISC_ENABLE_ADJ_PREF_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_ADJ_PREF_DISABLE_BIT)
413#define MSR_IA32_MISC_ENABLE_SPEEDSTEP_LOCK_BIT 20
414#define MSR_IA32_MISC_ENABLE_SPEEDSTEP_LOCK (1ULL << MSR_IA32_MISC_ENABLE_SPEEDSTEP_LOCK_BIT)
415#define MSR_IA32_MISC_ENABLE_L1D_CONTEXT_BIT 24
416#define MSR_IA32_MISC_ENABLE_L1D_CONTEXT (1ULL << MSR_IA32_MISC_ENABLE_L1D_CONTEXT_BIT)
417#define MSR_IA32_MISC_ENABLE_DCU_PREF_DISABLE_BIT 37
418#define MSR_IA32_MISC_ENABLE_DCU_PREF_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_DCU_PREF_DISABLE_BIT)
419#define MSR_IA32_MISC_ENABLE_TURBO_DISABLE_BIT 38
420#define MSR_IA32_MISC_ENABLE_TURBO_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_TURBO_DISABLE_BIT)
421#define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT 39
422#define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT)
398 423
399#define MSR_IA32_TSC_DEADLINE 0x000006E0 424#define MSR_IA32_TSC_DEADLINE 0x000006E0
400 425
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 1dac94265b59..9f46f2b1cfc2 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -613,10 +613,10 @@ static void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
613 int nid; 613 int nid;
614 614
615 nid = acpi_get_node(handle); 615 nid = acpi_get_node(handle);
616 if (nid == -1 || !node_online(nid)) 616 if (nid != -1) {
617 return; 617 set_apicid_to_node(physid, nid);
618 set_apicid_to_node(physid, nid); 618 numa_set_node(cpu, nid);
619 numa_set_node(cpu, nid); 619 }
620#endif 620#endif
621} 621}
622 622
diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index 59554dca96ec..dec8de4e1663 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -179,7 +179,7 @@ int amd_get_subcaches(int cpu)
179 return (mask >> (4 * cuid)) & 0xf; 179 return (mask >> (4 * cuid)) & 0xf;
180} 180}
181 181
182int amd_set_subcaches(int cpu, int mask) 182int amd_set_subcaches(int cpu, unsigned long mask)
183{ 183{
184 static unsigned int reset, ban; 184 static unsigned int reset, ban;
185 struct amd_northbridge *nb = node_to_amd_nb(amd_get_nb_id(cpu)); 185 struct amd_northbridge *nb = node_to_amd_nb(amd_get_nb_id(cpu));
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index fd972a3e4cbb..9fa8aa051f54 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -18,7 +18,6 @@
18#include <linux/pci_ids.h> 18#include <linux/pci_ids.h>
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/bitops.h> 20#include <linux/bitops.h>
21#include <linux/ioport.h>
22#include <linux/suspend.h> 21#include <linux/suspend.h>
23#include <asm/e820.h> 22#include <asm/e820.h>
24#include <asm/io.h> 23#include <asm/io.h>
@@ -54,18 +53,6 @@ int fallback_aper_force __initdata;
54 53
55int fix_aperture __initdata = 1; 54int fix_aperture __initdata = 1;
56 55
57static struct resource gart_resource = {
58 .name = "GART",
59 .flags = IORESOURCE_MEM,
60};
61
62static void __init insert_aperture_resource(u32 aper_base, u32 aper_size)
63{
64 gart_resource.start = aper_base;
65 gart_resource.end = aper_base + aper_size - 1;
66 insert_resource(&iomem_resource, &gart_resource);
67}
68
69/* This code runs before the PCI subsystem is initialized, so just 56/* This code runs before the PCI subsystem is initialized, so just
70 access the northbridge directly. */ 57 access the northbridge directly. */
71 58
@@ -96,7 +83,6 @@ static u32 __init allocate_aperture(void)
96 memblock_reserve(addr, aper_size); 83 memblock_reserve(addr, aper_size);
97 printk(KERN_INFO "Mapping aperture over %d KB of RAM @ %lx\n", 84 printk(KERN_INFO "Mapping aperture over %d KB of RAM @ %lx\n",
98 aper_size >> 10, addr); 85 aper_size >> 10, addr);
99 insert_aperture_resource((u32)addr, aper_size);
100 register_nosave_region(addr >> PAGE_SHIFT, 86 register_nosave_region(addr >> PAGE_SHIFT,
101 (addr+aper_size) >> PAGE_SHIFT); 87 (addr+aper_size) >> PAGE_SHIFT);
102 88
@@ -444,12 +430,8 @@ int __init gart_iommu_hole_init(void)
444 430
445out: 431out:
446 if (!fix && !fallback_aper_force) { 432 if (!fix && !fallback_aper_force) {
447 if (last_aper_base) { 433 if (last_aper_base)
448 unsigned long n = (32 * 1024 * 1024) << last_aper_order;
449
450 insert_aperture_resource((u32)last_aper_base, n);
451 return 1; 434 return 1;
452 }
453 return 0; 435 return 0;
454 } 436 }
455 437
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 7f26c9a70a9e..53e20531470e 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -133,6 +133,10 @@ static inline void imcr_apic_to_pic(void)
133 * +1=force-enable 133 * +1=force-enable
134 */ 134 */
135static int force_enable_local_apic __initdata; 135static int force_enable_local_apic __initdata;
136
137/* Control whether x2APIC mode is enabled or not */
138static bool nox2apic __initdata;
139
136/* 140/*
137 * APIC command line parameters 141 * APIC command line parameters
138 */ 142 */
@@ -162,8 +166,7 @@ int x2apic_mode;
162/* x2apic enabled before OS handover */ 166/* x2apic enabled before OS handover */
163int x2apic_preenabled; 167int x2apic_preenabled;
164static int x2apic_disabled; 168static int x2apic_disabled;
165static int nox2apic; 169static int __init setup_nox2apic(char *str)
166static __init int setup_nox2apic(char *str)
167{ 170{
168 if (x2apic_enabled()) { 171 if (x2apic_enabled()) {
169 int apicid = native_apic_msr_read(APIC_ID); 172 int apicid = native_apic_msr_read(APIC_ID);
@@ -178,7 +181,7 @@ static __init int setup_nox2apic(char *str)
178 } else 181 } else
179 setup_clear_cpu_cap(X86_FEATURE_X2APIC); 182 setup_clear_cpu_cap(X86_FEATURE_X2APIC);
180 183
181 nox2apic = 1; 184 nox2apic = true;
182 185
183 return 0; 186 return 0;
184} 187}
@@ -283,8 +286,12 @@ u32 native_safe_apic_wait_icr_idle(void)
283 286
284void native_apic_icr_write(u32 low, u32 id) 287void native_apic_icr_write(u32 low, u32 id)
285{ 288{
289 unsigned long flags;
290
291 local_irq_save(flags);
286 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(id)); 292 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(id));
287 apic_write(APIC_ICR, low); 293 apic_write(APIC_ICR, low);
294 local_irq_restore(flags);
288} 295}
289 296
290u64 native_apic_icr_read(void) 297u64 native_apic_icr_read(void)
diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
index 2c621a6b901a..7c1b29479513 100644
--- a/arch/x86/kernel/apic/apic_flat_64.c
+++ b/arch/x86/kernel/apic/apic_flat_64.c
@@ -198,7 +198,7 @@ static struct apic apic_flat = {
198 198
199 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 199 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
200 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 200 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
201 .wait_for_init_deassert = NULL, 201 .wait_for_init_deassert = false,
202 .smp_callin_clear_local_apic = NULL, 202 .smp_callin_clear_local_apic = NULL,
203 .inquire_remote_apic = default_inquire_remote_apic, 203 .inquire_remote_apic = default_inquire_remote_apic,
204 204
@@ -314,7 +314,7 @@ static struct apic apic_physflat = {
314 314
315 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 315 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
316 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 316 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
317 .wait_for_init_deassert = NULL, 317 .wait_for_init_deassert = false,
318 .smp_callin_clear_local_apic = NULL, 318 .smp_callin_clear_local_apic = NULL,
319 .inquire_remote_apic = default_inquire_remote_apic, 319 .inquire_remote_apic = default_inquire_remote_apic,
320 320
diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
index 191ce75c0e54..8c7c98249c20 100644
--- a/arch/x86/kernel/apic/apic_noop.c
+++ b/arch/x86/kernel/apic/apic_noop.c
@@ -172,8 +172,7 @@ struct apic apic_noop = {
172 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 172 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
173 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 173 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
174 174
175 .wait_for_init_deassert = NULL, 175 .wait_for_init_deassert = false,
176
177 .smp_callin_clear_local_apic = NULL, 176 .smp_callin_clear_local_apic = NULL,
178 .inquire_remote_apic = NULL, 177 .inquire_remote_apic = NULL,
179 178
diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
index 3e67f9e3d7ef..a5b45df8bc88 100644
--- a/arch/x86/kernel/apic/apic_numachip.c
+++ b/arch/x86/kernel/apic/apic_numachip.c
@@ -248,7 +248,7 @@ static const struct apic apic_numachip __refconst = {
248 .wakeup_secondary_cpu = numachip_wakeup_secondary, 248 .wakeup_secondary_cpu = numachip_wakeup_secondary,
249 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 249 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
250 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 250 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
251 .wait_for_init_deassert = NULL, 251 .wait_for_init_deassert = false,
252 .smp_callin_clear_local_apic = NULL, 252 .smp_callin_clear_local_apic = NULL,
253 .inquire_remote_apic = NULL, /* REMRD not supported */ 253 .inquire_remote_apic = NULL, /* REMRD not supported */
254 254
diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
index d50e3640d5ae..e4840aa7a255 100644
--- a/arch/x86/kernel/apic/bigsmp_32.c
+++ b/arch/x86/kernel/apic/bigsmp_32.c
@@ -199,8 +199,7 @@ static struct apic apic_bigsmp = {
199 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 199 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
200 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 200 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
201 201
202 .wait_for_init_deassert = default_wait_for_init_deassert, 202 .wait_for_init_deassert = true,
203
204 .smp_callin_clear_local_apic = NULL, 203 .smp_callin_clear_local_apic = NULL,
205 .inquire_remote_apic = default_inquire_remote_apic, 204 .inquire_remote_apic = default_inquire_remote_apic,
206 205
diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
index c55224731b2d..6f8f8b348a39 100644
--- a/arch/x86/kernel/apic/es7000_32.c
+++ b/arch/x86/kernel/apic/es7000_32.c
@@ -394,12 +394,6 @@ static void es7000_enable_apic_mode(void)
394 WARN(1, "Command failed, status = %x\n", mip_status); 394 WARN(1, "Command failed, status = %x\n", mip_status);
395} 395}
396 396
397static void es7000_wait_for_init_deassert(atomic_t *deassert)
398{
399 while (!atomic_read(deassert))
400 cpu_relax();
401}
402
403static unsigned int es7000_get_apic_id(unsigned long x) 397static unsigned int es7000_get_apic_id(unsigned long x)
404{ 398{
405 return (x >> 24) & 0xFF; 399 return (x >> 24) & 0xFF;
@@ -658,8 +652,7 @@ static struct apic __refdata apic_es7000_cluster = {
658 .trampoline_phys_low = 0x467, 652 .trampoline_phys_low = 0x467,
659 .trampoline_phys_high = 0x469, 653 .trampoline_phys_high = 0x469,
660 654
661 .wait_for_init_deassert = NULL, 655 .wait_for_init_deassert = false,
662
663 /* Nothing to do for most platforms, since cleared by the INIT cycle: */ 656 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
664 .smp_callin_clear_local_apic = NULL, 657 .smp_callin_clear_local_apic = NULL,
665 .inquire_remote_apic = default_inquire_remote_apic, 658 .inquire_remote_apic = default_inquire_remote_apic,
@@ -722,8 +715,7 @@ static struct apic __refdata apic_es7000 = {
722 .trampoline_phys_low = 0x467, 715 .trampoline_phys_low = 0x467,
723 .trampoline_phys_high = 0x469, 716 .trampoline_phys_high = 0x469,
724 717
725 .wait_for_init_deassert = es7000_wait_for_init_deassert, 718 .wait_for_init_deassert = true,
726
727 /* Nothing to do for most platforms, since cleared by the INIT cycle: */ 719 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
728 .smp_callin_clear_local_apic = NULL, 720 .smp_callin_clear_local_apic = NULL,
729 .inquire_remote_apic = default_inquire_remote_apic, 721 .inquire_remote_apic = default_inquire_remote_apic,
diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
index 1e42e8f305ee..030ea1c04f72 100644
--- a/arch/x86/kernel/apic/numaq_32.c
+++ b/arch/x86/kernel/apic/numaq_32.c
@@ -505,8 +505,7 @@ static struct apic __refdata apic_numaq = {
505 .trampoline_phys_high = NUMAQ_TRAMPOLINE_PHYS_HIGH, 505 .trampoline_phys_high = NUMAQ_TRAMPOLINE_PHYS_HIGH,
506 506
507 /* We don't do anything here because we use NMI's to boot instead */ 507 /* We don't do anything here because we use NMI's to boot instead */
508 .wait_for_init_deassert = NULL, 508 .wait_for_init_deassert = false,
509
510 .smp_callin_clear_local_apic = numaq_smp_callin_clear_local_apic, 509 .smp_callin_clear_local_apic = numaq_smp_callin_clear_local_apic,
511 .inquire_remote_apic = NULL, 510 .inquire_remote_apic = NULL,
512 511
diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
index eb35ef9ee63f..cceb352c968c 100644
--- a/arch/x86/kernel/apic/probe_32.c
+++ b/arch/x86/kernel/apic/probe_32.c
@@ -119,8 +119,7 @@ static struct apic apic_default = {
119 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 119 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
120 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 120 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
121 121
122 .wait_for_init_deassert = default_wait_for_init_deassert, 122 .wait_for_init_deassert = true,
123
124 .smp_callin_clear_local_apic = NULL, 123 .smp_callin_clear_local_apic = NULL,
125 .inquire_remote_apic = default_inquire_remote_apic, 124 .inquire_remote_apic = default_inquire_remote_apic,
126 125
diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
index 00146f9b0254..b656128611cd 100644
--- a/arch/x86/kernel/apic/summit_32.c
+++ b/arch/x86/kernel/apic/summit_32.c
@@ -532,8 +532,7 @@ static struct apic apic_summit = {
532 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 532 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
533 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 533 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
534 534
535 .wait_for_init_deassert = default_wait_for_init_deassert, 535 .wait_for_init_deassert = true,
536
537 .smp_callin_clear_local_apic = NULL, 536 .smp_callin_clear_local_apic = NULL,
538 .inquire_remote_apic = default_inquire_remote_apic, 537 .inquire_remote_apic = default_inquire_remote_apic,
539 538
diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
index cac85ee6913f..e66766bf1641 100644
--- a/arch/x86/kernel/apic/x2apic_cluster.c
+++ b/arch/x86/kernel/apic/x2apic_cluster.c
@@ -279,7 +279,7 @@ static struct apic apic_x2apic_cluster = {
279 279
280 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 280 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
281 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 281 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
282 .wait_for_init_deassert = NULL, 282 .wait_for_init_deassert = false,
283 .smp_callin_clear_local_apic = NULL, 283 .smp_callin_clear_local_apic = NULL,
284 .inquire_remote_apic = NULL, 284 .inquire_remote_apic = NULL,
285 285
diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
index de231e328cae..6d600ebf6c12 100644
--- a/arch/x86/kernel/apic/x2apic_phys.c
+++ b/arch/x86/kernel/apic/x2apic_phys.c
@@ -133,7 +133,7 @@ static struct apic apic_x2apic_phys = {
133 133
134 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 134 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
135 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 135 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
136 .wait_for_init_deassert = NULL, 136 .wait_for_init_deassert = false,
137 .smp_callin_clear_local_apic = NULL, 137 .smp_callin_clear_local_apic = NULL,
138 .inquire_remote_apic = NULL, 138 .inquire_remote_apic = NULL,
139 139
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index d263b1307de1..7834389ba5be 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -396,7 +396,7 @@ static struct apic __refdata apic_x2apic_uv_x = {
396 .wakeup_secondary_cpu = uv_wakeup_secondary, 396 .wakeup_secondary_cpu = uv_wakeup_secondary,
397 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, 397 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
398 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, 398 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
399 .wait_for_init_deassert = NULL, 399 .wait_for_init_deassert = false,
400 .smp_callin_clear_local_apic = NULL, 400 .smp_callin_clear_local_apic = NULL,
401 .inquire_remote_apic = NULL, 401 .inquire_remote_apic = NULL,
402 402
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index d3153e281d72..ce8b8ff0e0ef 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -218,7 +218,7 @@ static void amd_k7_smp_check(struct cpuinfo_x86 *c)
218 */ 218 */
219 WARN_ONCE(1, "WARNING: This combination of AMD" 219 WARN_ONCE(1, "WARNING: This combination of AMD"
220 " processors is not suitable for SMP.\n"); 220 " processors is not suitable for SMP.\n");
221 add_taint(TAINT_UNSAFE_SMP, LOCKDEP_NOW_UNRELIABLE); 221 add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_NOW_UNRELIABLE);
222} 222}
223 223
224static void init_amd_k7(struct cpuinfo_x86 *c) 224static void init_amd_k7(struct cpuinfo_x86 *c)
@@ -233,9 +233,7 @@ static void init_amd_k7(struct cpuinfo_x86 *c)
233 if (c->x86_model >= 6 && c->x86_model <= 10) { 233 if (c->x86_model >= 6 && c->x86_model <= 10) {
234 if (!cpu_has(c, X86_FEATURE_XMM)) { 234 if (!cpu_has(c, X86_FEATURE_XMM)) {
235 printk(KERN_INFO "Enabling disabled K7/SSE Support.\n"); 235 printk(KERN_INFO "Enabling disabled K7/SSE Support.\n");
236 rdmsr(MSR_K7_HWCR, l, h); 236 msr_clear_bit(MSR_K7_HWCR, 15);
237 l &= ~0x00008000;
238 wrmsr(MSR_K7_HWCR, l, h);
239 set_cpu_cap(c, X86_FEATURE_XMM); 237 set_cpu_cap(c, X86_FEATURE_XMM);
240 } 238 }
241 } 239 }
@@ -509,14 +507,8 @@ static void early_init_amd(struct cpuinfo_x86 *c)
509#endif 507#endif
510 508
511 /* F16h erratum 793, CVE-2013-6885 */ 509 /* F16h erratum 793, CVE-2013-6885 */
512 if (c->x86 == 0x16 && c->x86_model <= 0xf) { 510 if (c->x86 == 0x16 && c->x86_model <= 0xf)
513 u64 val; 511 msr_set_bit(MSR_AMD64_LS_CFG, 15);
514
515 rdmsrl(MSR_AMD64_LS_CFG, val);
516 if (!(val & BIT(15)))
517 wrmsrl(MSR_AMD64_LS_CFG, val | BIT(15));
518 }
519
520} 512}
521 513
522static const int amd_erratum_383[]; 514static const int amd_erratum_383[];
@@ -536,11 +528,8 @@ static void init_amd(struct cpuinfo_x86 *c)
536 * Errata 63 for SH-B3 steppings 528 * Errata 63 for SH-B3 steppings
537 * Errata 122 for all steppings (F+ have it disabled by default) 529 * Errata 122 for all steppings (F+ have it disabled by default)
538 */ 530 */
539 if (c->x86 == 0xf) { 531 if (c->x86 == 0xf)
540 rdmsrl(MSR_K7_HWCR, value); 532 msr_set_bit(MSR_K7_HWCR, 6);
541 value |= 1 << 6;
542 wrmsrl(MSR_K7_HWCR, value);
543 }
544#endif 533#endif
545 534
546 early_init_amd(c); 535 early_init_amd(c);
@@ -623,14 +612,11 @@ static void init_amd(struct cpuinfo_x86 *c)
623 (c->x86_model >= 0x10) && (c->x86_model <= 0x1f) && 612 (c->x86_model >= 0x10) && (c->x86_model <= 0x1f) &&
624 !cpu_has(c, X86_FEATURE_TOPOEXT)) { 613 !cpu_has(c, X86_FEATURE_TOPOEXT)) {
625 614
626 if (!rdmsrl_safe(0xc0011005, &value)) { 615 if (msr_set_bit(0xc0011005, 54) > 0) {
627 value |= 1ULL << 54;
628 wrmsrl_safe(0xc0011005, value);
629 rdmsrl(0xc0011005, value); 616 rdmsrl(0xc0011005, value);
630 if (value & (1ULL << 54)) { 617 if (value & BIT_64(54)) {
631 set_cpu_cap(c, X86_FEATURE_TOPOEXT); 618 set_cpu_cap(c, X86_FEATURE_TOPOEXT);
632 printk(KERN_INFO FW_INFO "CPU: Re-enabling " 619 pr_info(FW_INFO "CPU: Re-enabling disabled Topology Extensions Support.\n");
633 "disabled Topology Extensions Support\n");
634 } 620 }
635 } 621 }
636 } 622 }
@@ -709,19 +695,12 @@ static void init_amd(struct cpuinfo_x86 *c)
709 * Disable GART TLB Walk Errors on Fam10h. We do this here 695 * Disable GART TLB Walk Errors on Fam10h. We do this here
710 * because this is always needed when GART is enabled, even in a 696 * because this is always needed when GART is enabled, even in a
711 * kernel which has no MCE support built in. 697 * kernel which has no MCE support built in.
712 * BIOS should disable GartTlbWlk Errors themself. If 698 * BIOS should disable GartTlbWlk Errors already. If
713 * it doesn't do it here as suggested by the BKDG. 699 * it doesn't, do it here as suggested by the BKDG.
714 * 700 *
715 * Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=33012 701 * Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=33012
716 */ 702 */
717 u64 mask; 703 msr_set_bit(MSR_AMD64_MCx_MASK(4), 10);
718 int err;
719
720 err = rdmsrl_safe(MSR_AMD64_MCx_MASK(4), &mask);
721 if (err == 0) {
722 mask |= (1 << 10);
723 wrmsrl_safe(MSR_AMD64_MCx_MASK(4), mask);
724 }
725 704
726 /* 705 /*
727 * On family 10h BIOS may not have properly enabled WC+ support, 706 * On family 10h BIOS may not have properly enabled WC+ support,
@@ -733,10 +712,7 @@ static void init_amd(struct cpuinfo_x86 *c)
733 * NOTE: we want to use the _safe accessors so as not to #GP kvm 712 * NOTE: we want to use the _safe accessors so as not to #GP kvm
734 * guests on older kvm hosts. 713 * guests on older kvm hosts.
735 */ 714 */
736 715 msr_clear_bit(MSR_AMD64_BU_CFG2, 24);
737 rdmsrl_safe(MSR_AMD64_BU_CFG2, &value);
738 value &= ~(1ULL << 24);
739 wrmsrl_safe(MSR_AMD64_BU_CFG2, value);
740 716
741 if (cpu_has_amd_erratum(c, amd_erratum_383)) 717 if (cpu_has_amd_erratum(c, amd_erratum_383))
742 set_cpu_bug(c, X86_BUG_AMD_TLB_MMATCH); 718 set_cpu_bug(c, X86_BUG_AMD_TLB_MMATCH);
@@ -767,10 +743,7 @@ static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
767 743
768static void cpu_set_tlb_flushall_shift(struct cpuinfo_x86 *c) 744static void cpu_set_tlb_flushall_shift(struct cpuinfo_x86 *c)
769{ 745{
770 tlb_flushall_shift = 5; 746 tlb_flushall_shift = 6;
771
772 if (c->x86 <= 0x11)
773 tlb_flushall_shift = 4;
774} 747}
775 748
776static void cpu_detect_tlb_amd(struct cpuinfo_x86 *c) 749static void cpu_detect_tlb_amd(struct cpuinfo_x86 *c)
diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index 8779edab684e..d8fba5c15fbd 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -8,236 +8,6 @@
8 8
9#include "cpu.h" 9#include "cpu.h"
10 10
11#ifdef CONFIG_X86_OOSTORE
12
13static u32 power2(u32 x)
14{
15 u32 s = 1;
16
17 while (s <= x)
18 s <<= 1;
19
20 return s >>= 1;
21}
22
23
24/*
25 * Set up an actual MCR
26 */
27static void centaur_mcr_insert(int reg, u32 base, u32 size, int key)
28{
29 u32 lo, hi;
30
31 hi = base & ~0xFFF;
32 lo = ~(size-1); /* Size is a power of 2 so this makes a mask */
33 lo &= ~0xFFF; /* Remove the ctrl value bits */
34 lo |= key; /* Attribute we wish to set */
35 wrmsr(reg+MSR_IDT_MCR0, lo, hi);
36 mtrr_centaur_report_mcr(reg, lo, hi); /* Tell the mtrr driver */
37}
38
39/*
40 * Figure what we can cover with MCR's
41 *
42 * Shortcut: We know you can't put 4Gig of RAM on a winchip
43 */
44static u32 ramtop(void)
45{
46 u32 clip = 0xFFFFFFFFUL;
47 u32 top = 0;
48 int i;
49
50 for (i = 0; i < e820.nr_map; i++) {
51 unsigned long start, end;
52
53 if (e820.map[i].addr > 0xFFFFFFFFUL)
54 continue;
55 /*
56 * Don't MCR over reserved space. Ignore the ISA hole
57 * we frob around that catastrophe already
58 */
59 if (e820.map[i].type == E820_RESERVED) {
60 if (e820.map[i].addr >= 0x100000UL &&
61 e820.map[i].addr < clip)
62 clip = e820.map[i].addr;
63 continue;
64 }
65 start = e820.map[i].addr;
66 end = e820.map[i].addr + e820.map[i].size;
67 if (start >= end)
68 continue;
69 if (end > top)
70 top = end;
71 }
72 /*
73 * Everything below 'top' should be RAM except for the ISA hole.
74 * Because of the limited MCR's we want to map NV/ACPI into our
75 * MCR range for gunk in RAM
76 *
77 * Clip might cause us to MCR insufficient RAM but that is an
78 * acceptable failure mode and should only bite obscure boxes with
79 * a VESA hole at 15Mb
80 *
81 * The second case Clip sometimes kicks in is when the EBDA is marked
82 * as reserved. Again we fail safe with reasonable results
83 */
84 if (top > clip)
85 top = clip;
86
87 return top;
88}
89
90/*
91 * Compute a set of MCR's to give maximum coverage
92 */
93static int centaur_mcr_compute(int nr, int key)
94{
95 u32 mem = ramtop();
96 u32 root = power2(mem);
97 u32 base = root;
98 u32 top = root;
99 u32 floor = 0;
100 int ct = 0;
101
102 while (ct < nr) {
103 u32 fspace = 0;
104 u32 high;
105 u32 low;
106
107 /*
108 * Find the largest block we will fill going upwards
109 */
110 high = power2(mem-top);
111
112 /*
113 * Find the largest block we will fill going downwards
114 */
115 low = base/2;
116
117 /*
118 * Don't fill below 1Mb going downwards as there
119 * is an ISA hole in the way.
120 */
121 if (base <= 1024*1024)
122 low = 0;
123
124 /*
125 * See how much space we could cover by filling below
126 * the ISA hole
127 */
128
129 if (floor == 0)
130 fspace = 512*1024;
131 else if (floor == 512*1024)
132 fspace = 128*1024;
133
134 /* And forget ROM space */
135
136 /*
137 * Now install the largest coverage we get
138 */
139 if (fspace > high && fspace > low) {
140 centaur_mcr_insert(ct, floor, fspace, key);
141 floor += fspace;
142 } else if (high > low) {
143 centaur_mcr_insert(ct, top, high, key);
144 top += high;
145 } else if (low > 0) {
146 base -= low;
147 centaur_mcr_insert(ct, base, low, key);
148 } else
149 break;
150 ct++;
151 }
152 /*
153 * We loaded ct values. We now need to set the mask. The caller
154 * must do this bit.
155 */
156 return ct;
157}
158
159static void centaur_create_optimal_mcr(void)
160{
161 int used;
162 int i;
163
164 /*
165 * Allocate up to 6 mcrs to mark as much of ram as possible
166 * as write combining and weak write ordered.
167 *
168 * To experiment with: Linux never uses stack operations for
169 * mmio spaces so we could globally enable stack operation wc
170 *
171 * Load the registers with type 31 - full write combining, all
172 * writes weakly ordered.
173 */
174 used = centaur_mcr_compute(6, 31);
175
176 /*
177 * Wipe unused MCRs
178 */
179 for (i = used; i < 8; i++)
180 wrmsr(MSR_IDT_MCR0+i, 0, 0);
181}
182
183static void winchip2_create_optimal_mcr(void)
184{
185 u32 lo, hi;
186 int used;
187 int i;
188
189 /*
190 * Allocate up to 6 mcrs to mark as much of ram as possible
191 * as write combining, weak store ordered.
192 *
193 * Load the registers with type 25
194 * 8 - weak write ordering
195 * 16 - weak read ordering
196 * 1 - write combining
197 */
198 used = centaur_mcr_compute(6, 25);
199
200 /*
201 * Mark the registers we are using.
202 */
203 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
204 for (i = 0; i < used; i++)
205 lo |= 1<<(9+i);
206 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
207
208 /*
209 * Wipe unused MCRs
210 */
211
212 for (i = used; i < 8; i++)
213 wrmsr(MSR_IDT_MCR0+i, 0, 0);
214}
215
216/*
217 * Handle the MCR key on the Winchip 2.
218 */
219static void winchip2_unprotect_mcr(void)
220{
221 u32 lo, hi;
222 u32 key;
223
224 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
225 lo &= ~0x1C0; /* blank bits 8-6 */
226 key = (lo>>17) & 7;
227 lo |= key<<6; /* replace with unlock key */
228 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
229}
230
231static void winchip2_protect_mcr(void)
232{
233 u32 lo, hi;
234
235 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
236 lo &= ~0x1C0; /* blank bits 8-6 */
237 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
238}
239#endif /* CONFIG_X86_OOSTORE */
240
241#define ACE_PRESENT (1 << 6) 11#define ACE_PRESENT (1 << 6)
242#define ACE_ENABLED (1 << 7) 12#define ACE_ENABLED (1 << 7)
243#define ACE_FCR (1 << 28) /* MSR_VIA_FCR */ 13#define ACE_FCR (1 << 28) /* MSR_VIA_FCR */
@@ -362,20 +132,6 @@ static void init_centaur(struct cpuinfo_x86 *c)
362 fcr_clr = DPDC; 132 fcr_clr = DPDC;
363 printk(KERN_NOTICE "Disabling bugged TSC.\n"); 133 printk(KERN_NOTICE "Disabling bugged TSC.\n");
364 clear_cpu_cap(c, X86_FEATURE_TSC); 134 clear_cpu_cap(c, X86_FEATURE_TSC);
365#ifdef CONFIG_X86_OOSTORE
366 centaur_create_optimal_mcr();
367 /*
368 * Enable:
369 * write combining on non-stack, non-string
370 * write combining on string, all types
371 * weak write ordering
372 *
373 * The C6 original lacks weak read order
374 *
375 * Note 0x120 is write only on Winchip 1
376 */
377 wrmsr(MSR_IDT_MCR_CTRL, 0x01F0001F, 0);
378#endif
379 break; 135 break;
380 case 8: 136 case 8:
381 switch (c->x86_mask) { 137 switch (c->x86_mask) {
@@ -392,40 +148,12 @@ static void init_centaur(struct cpuinfo_x86 *c)
392 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK| 148 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
393 E2MMX|EAMD3D; 149 E2MMX|EAMD3D;
394 fcr_clr = DPDC; 150 fcr_clr = DPDC;
395#ifdef CONFIG_X86_OOSTORE
396 winchip2_unprotect_mcr();
397 winchip2_create_optimal_mcr();
398 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
399 /*
400 * Enable:
401 * write combining on non-stack, non-string
402 * write combining on string, all types
403 * weak write ordering
404 */
405 lo |= 31;
406 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
407 winchip2_protect_mcr();
408#endif
409 break; 151 break;
410 case 9: 152 case 9:
411 name = "3"; 153 name = "3";
412 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK| 154 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
413 E2MMX|EAMD3D; 155 E2MMX|EAMD3D;
414 fcr_clr = DPDC; 156 fcr_clr = DPDC;
415#ifdef CONFIG_X86_OOSTORE
416 winchip2_unprotect_mcr();
417 winchip2_create_optimal_mcr();
418 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
419 /*
420 * Enable:
421 * write combining on non-stack, non-string
422 * write combining on string, all types
423 * weak write ordering
424 */
425 lo |= 31;
426 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
427 winchip2_protect_mcr();
428#endif
429 break; 157 break;
430 default: 158 default:
431 name = "??"; 159 name = "??";
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 24b6fd10625a..8e28bf2fc3ef 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -284,8 +284,13 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
284 raw_local_save_flags(eflags); 284 raw_local_save_flags(eflags);
285 BUG_ON(eflags & X86_EFLAGS_AC); 285 BUG_ON(eflags & X86_EFLAGS_AC);
286 286
287 if (cpu_has(c, X86_FEATURE_SMAP)) 287 if (cpu_has(c, X86_FEATURE_SMAP)) {
288#ifdef CONFIG_X86_SMAP
288 set_in_cr4(X86_CR4_SMAP); 289 set_in_cr4(X86_CR4_SMAP);
290#else
291 clear_in_cr4(X86_CR4_SMAP);
292#endif
293 }
289} 294}
290 295
291/* 296/*
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index 3db61c644e44..897d6201ef10 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -31,11 +31,8 @@ static void early_init_intel(struct cpuinfo_x86 *c)
31 31
32 /* Unmask CPUID levels if masked: */ 32 /* Unmask CPUID levels if masked: */
33 if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) { 33 if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
34 rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable); 34 if (msr_clear_bit(MSR_IA32_MISC_ENABLE,
35 35 MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT) > 0) {
36 if (misc_enable & MSR_IA32_MISC_ENABLE_LIMIT_CPUID) {
37 misc_enable &= ~MSR_IA32_MISC_ENABLE_LIMIT_CPUID;
38 wrmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
39 c->cpuid_level = cpuid_eax(0); 36 c->cpuid_level = cpuid_eax(0);
40 get_cpu_cap(c); 37 get_cpu_cap(c);
41 } 38 }
@@ -129,16 +126,10 @@ static void early_init_intel(struct cpuinfo_x86 *c)
129 * Ingo Molnar reported a Pentium D (model 6) and a Xeon 126 * Ingo Molnar reported a Pentium D (model 6) and a Xeon
130 * (model 2) with the same problem. 127 * (model 2) with the same problem.
131 */ 128 */
132 if (c->x86 == 15) { 129 if (c->x86 == 15)
133 rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable); 130 if (msr_clear_bit(MSR_IA32_MISC_ENABLE,
134 131 MSR_IA32_MISC_ENABLE_FAST_STRING_BIT) > 0)
135 if (misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING) { 132 pr_info("kmemcheck: Disabling fast string operations\n");
136 printk(KERN_INFO "kmemcheck: Disabling fast string operations\n");
137
138 misc_enable &= ~MSR_IA32_MISC_ENABLE_FAST_STRING;
139 wrmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
140 }
141 }
142#endif 133#endif
143 134
144 /* 135 /*
@@ -195,10 +186,16 @@ static void intel_smp_check(struct cpuinfo_x86 *c)
195 } 186 }
196} 187}
197 188
198static void intel_workarounds(struct cpuinfo_x86 *c) 189static int forcepae;
190static int __init forcepae_setup(char *__unused)
199{ 191{
200 unsigned long lo, hi; 192 forcepae = 1;
193 return 1;
194}
195__setup("forcepae", forcepae_setup);
201 196
197static void intel_workarounds(struct cpuinfo_x86 *c)
198{
202#ifdef CONFIG_X86_F00F_BUG 199#ifdef CONFIG_X86_F00F_BUG
203 /* 200 /*
204 * All current models of Pentium and Pentium with MMX technology CPUs 201 * All current models of Pentium and Pentium with MMX technology CPUs
@@ -225,16 +222,26 @@ static void intel_workarounds(struct cpuinfo_x86 *c)
225 clear_cpu_cap(c, X86_FEATURE_SEP); 222 clear_cpu_cap(c, X86_FEATURE_SEP);
226 223
227 /* 224 /*
225 * PAE CPUID issue: many Pentium M report no PAE but may have a
226 * functionally usable PAE implementation.
227 * Forcefully enable PAE if kernel parameter "forcepae" is present.
228 */
229 if (forcepae) {
230 printk(KERN_WARNING "PAE forced!\n");
231 set_cpu_cap(c, X86_FEATURE_PAE);
232 add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_NOW_UNRELIABLE);
233 }
234
235 /*
228 * P4 Xeon errata 037 workaround. 236 * P4 Xeon errata 037 workaround.
229 * Hardware prefetcher may cause stale data to be loaded into the cache. 237 * Hardware prefetcher may cause stale data to be loaded into the cache.
230 */ 238 */
231 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) { 239 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
232 rdmsr(MSR_IA32_MISC_ENABLE, lo, hi); 240 if (msr_set_bit(MSR_IA32_MISC_ENABLE,
233 if ((lo & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE) == 0) { 241 MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT)
234 printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n"); 242 > 0) {
235 printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n"); 243 pr_info("CPU: C0 stepping P4 Xeon detected.\n");
236 lo |= MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE; 244 pr_info("CPU: Disabling hardware prefetching (Errata 037)\n");
237 wrmsr(MSR_IA32_MISC_ENABLE, lo, hi);
238 } 245 }
239 } 246 }
240 247
@@ -640,21 +647,17 @@ static void intel_tlb_flushall_shift_set(struct cpuinfo_x86 *c)
640 case 0x61d: /* six-core 45 nm xeon "Dunnington" */ 647 case 0x61d: /* six-core 45 nm xeon "Dunnington" */
641 tlb_flushall_shift = -1; 648 tlb_flushall_shift = -1;
642 break; 649 break;
650 case 0x63a: /* Ivybridge */
651 tlb_flushall_shift = 2;
652 break;
643 case 0x61a: /* 45 nm nehalem, "Bloomfield" */ 653 case 0x61a: /* 45 nm nehalem, "Bloomfield" */
644 case 0x61e: /* 45 nm nehalem, "Lynnfield" */ 654 case 0x61e: /* 45 nm nehalem, "Lynnfield" */
645 case 0x625: /* 32 nm nehalem, "Clarkdale" */ 655 case 0x625: /* 32 nm nehalem, "Clarkdale" */
646 case 0x62c: /* 32 nm nehalem, "Gulftown" */ 656 case 0x62c: /* 32 nm nehalem, "Gulftown" */
647 case 0x62e: /* 45 nm nehalem-ex, "Beckton" */ 657 case 0x62e: /* 45 nm nehalem-ex, "Beckton" */
648 case 0x62f: /* 32 nm Xeon E7 */ 658 case 0x62f: /* 32 nm Xeon E7 */
649 tlb_flushall_shift = 6;
650 break;
651 case 0x62a: /* SandyBridge */ 659 case 0x62a: /* SandyBridge */
652 case 0x62d: /* SandyBridge, "Romely-EP" */ 660 case 0x62d: /* SandyBridge, "Romely-EP" */
653 tlb_flushall_shift = 5;
654 break;
655 case 0x63a: /* Ivybridge */
656 tlb_flushall_shift = 1;
657 break;
658 default: 661 default:
659 tlb_flushall_shift = 6; 662 tlb_flushall_shift = 6;
660 } 663 }
diff --git a/arch/x86/kernel/cpu/microcode/amd_early.c b/arch/x86/kernel/cpu/microcode/amd_early.c
index 8384c0fa206f..617a9e284245 100644
--- a/arch/x86/kernel/cpu/microcode/amd_early.c
+++ b/arch/x86/kernel/cpu/microcode/amd_early.c
@@ -285,6 +285,15 @@ static void __init collect_cpu_sig_on_bsp(void *arg)
285 285
286 uci->cpu_sig.sig = cpuid_eax(0x00000001); 286 uci->cpu_sig.sig = cpuid_eax(0x00000001);
287} 287}
288
289static void __init get_bsp_sig(void)
290{
291 unsigned int bsp = boot_cpu_data.cpu_index;
292 struct ucode_cpu_info *uci = ucode_cpu_info + bsp;
293
294 if (!uci->cpu_sig.sig)
295 smp_call_function_single(bsp, collect_cpu_sig_on_bsp, NULL, 1);
296}
288#else 297#else
289void load_ucode_amd_ap(void) 298void load_ucode_amd_ap(void)
290{ 299{
@@ -337,31 +346,37 @@ void load_ucode_amd_ap(void)
337 346
338int __init save_microcode_in_initrd_amd(void) 347int __init save_microcode_in_initrd_amd(void)
339{ 348{
349 unsigned long cont;
340 enum ucode_state ret; 350 enum ucode_state ret;
341 u32 eax; 351 u32 eax;
342 352
343#ifdef CONFIG_X86_32 353 if (!container)
344 unsigned int bsp = boot_cpu_data.cpu_index; 354 return -EINVAL;
345 struct ucode_cpu_info *uci = ucode_cpu_info + bsp;
346
347 if (!uci->cpu_sig.sig)
348 smp_call_function_single(bsp, collect_cpu_sig_on_bsp, NULL, 1);
349 355
356#ifdef CONFIG_X86_32
357 get_bsp_sig();
358 cont = (unsigned long)container;
359#else
350 /* 360 /*
351 * Take into account the fact that the ramdisk might get relocated 361 * We need the physical address of the container for both bitness since
352 * and therefore we need to recompute the container's position in 362 * boot_params.hdr.ramdisk_image is a physical address.
353 * virtual memory space.
354 */ 363 */
355 container = (u8 *)(__va((u32)relocated_ramdisk) + 364 cont = __pa(container);
356 ((u32)container - boot_params.hdr.ramdisk_image));
357#endif 365#endif
366
367 /*
368 * Take into account the fact that the ramdisk might get relocated and
369 * therefore we need to recompute the container's position in virtual
370 * memory space.
371 */
372 if (relocated_ramdisk)
373 container = (u8 *)(__va(relocated_ramdisk) +
374 (cont - boot_params.hdr.ramdisk_image));
375
358 if (ucode_new_rev) 376 if (ucode_new_rev)
359 pr_info("microcode: updated early to new patch_level=0x%08x\n", 377 pr_info("microcode: updated early to new patch_level=0x%08x\n",
360 ucode_new_rev); 378 ucode_new_rev);
361 379
362 if (!container)
363 return -EINVAL;
364
365 eax = cpuid_eax(0x00000001); 380 eax = cpuid_eax(0x00000001);
366 eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff); 381 eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff);
367 382
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 9f7ca266864a..832d05a914ba 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -26,6 +26,7 @@
26#include <asm/irq_regs.h> 26#include <asm/irq_regs.h>
27#include <asm/i8259.h> 27#include <asm/i8259.h>
28#include <asm/apic.h> 28#include <asm/apic.h>
29#include <asm/timer.h>
29 30
30struct ms_hyperv_info ms_hyperv; 31struct ms_hyperv_info ms_hyperv;
31EXPORT_SYMBOL_GPL(ms_hyperv); 32EXPORT_SYMBOL_GPL(ms_hyperv);
@@ -105,6 +106,11 @@ static void __init ms_hyperv_init_platform(void)
105 106
106 if (ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE) 107 if (ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE)
107 clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100); 108 clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
109
110#ifdef CONFIG_X86_IO_APIC
111 no_timer_check = 1;
112#endif
113
108} 114}
109 115
110const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = { 116const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index ce2d0a2c3e4f..0e25a1bc5ab5 100644
--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -683,7 +683,7 @@ static void prepare_set(void) __acquires(set_atomicity_lock)
683 } 683 }
684 684
685 /* Flush all TLBs via a mov %cr3, %reg; mov %reg, %cr3 */ 685 /* Flush all TLBs via a mov %cr3, %reg; mov %reg, %cr3 */
686 count_vm_event(NR_TLB_LOCAL_FLUSH_ALL); 686 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL);
687 __flush_tlb(); 687 __flush_tlb();
688 688
689 /* Save MTRR state */ 689 /* Save MTRR state */
@@ -697,7 +697,7 @@ static void prepare_set(void) __acquires(set_atomicity_lock)
697static void post_set(void) __releases(set_atomicity_lock) 697static void post_set(void) __releases(set_atomicity_lock)
698{ 698{
699 /* Flush TLBs (no need to flush caches - they are disabled) */ 699 /* Flush TLBs (no need to flush caches - they are disabled) */
700 count_vm_event(NR_TLB_LOCAL_FLUSH_ALL); 700 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL);
701 __flush_tlb(); 701 __flush_tlb();
702 702
703 /* Intel (P6) standard MTRRs */ 703 /* Intel (P6) standard MTRRs */
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index b88645191fe5..ae407f7226c8 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -892,7 +892,6 @@ static void x86_pmu_enable(struct pmu *pmu)
892 * hw_perf_group_sched_in() or x86_pmu_enable() 892 * hw_perf_group_sched_in() or x86_pmu_enable()
893 * 893 *
894 * step1: save events moving to new counters 894 * step1: save events moving to new counters
895 * step2: reprogram moved events into new counters
896 */ 895 */
897 for (i = 0; i < n_running; i++) { 896 for (i = 0; i < n_running; i++) {
898 event = cpuc->event_list[i]; 897 event = cpuc->event_list[i];
@@ -918,6 +917,9 @@ static void x86_pmu_enable(struct pmu *pmu)
918 x86_pmu_stop(event, PERF_EF_UPDATE); 917 x86_pmu_stop(event, PERF_EF_UPDATE);
919 } 918 }
920 919
920 /*
921 * step2: reprogram moved events into new counters
922 */
921 for (i = 0; i < cpuc->n_events; i++) { 923 for (i = 0; i < cpuc->n_events; i++) {
922 event = cpuc->event_list[i]; 924 event = cpuc->event_list[i];
923 hwc = &event->hw; 925 hwc = &event->hw;
@@ -1043,7 +1045,7 @@ static int x86_pmu_add(struct perf_event *event, int flags)
1043 /* 1045 /*
1044 * If group events scheduling transaction was started, 1046 * If group events scheduling transaction was started,
1045 * skip the schedulability test here, it will be performed 1047 * skip the schedulability test here, it will be performed
1046 * at commit time (->commit_txn) as a whole 1048 * at commit time (->commit_txn) as a whole.
1047 */ 1049 */
1048 if (cpuc->group_flag & PERF_EVENT_TXN) 1050 if (cpuc->group_flag & PERF_EVENT_TXN)
1049 goto done_collect; 1051 goto done_collect;
@@ -1058,6 +1060,10 @@ static int x86_pmu_add(struct perf_event *event, int flags)
1058 memcpy(cpuc->assign, assign, n*sizeof(int)); 1060 memcpy(cpuc->assign, assign, n*sizeof(int));
1059 1061
1060done_collect: 1062done_collect:
1063 /*
1064 * Commit the collect_events() state. See x86_pmu_del() and
1065 * x86_pmu_*_txn().
1066 */
1061 cpuc->n_events = n; 1067 cpuc->n_events = n;
1062 cpuc->n_added += n - n0; 1068 cpuc->n_added += n - n0;
1063 cpuc->n_txn += n - n0; 1069 cpuc->n_txn += n - n0;
@@ -1183,25 +1189,38 @@ static void x86_pmu_del(struct perf_event *event, int flags)
1183 * If we're called during a txn, we don't need to do anything. 1189 * If we're called during a txn, we don't need to do anything.
1184 * The events never got scheduled and ->cancel_txn will truncate 1190 * The events never got scheduled and ->cancel_txn will truncate
1185 * the event_list. 1191 * the event_list.
1192 *
1193 * XXX assumes any ->del() called during a TXN will only be on
1194 * an event added during that same TXN.
1186 */ 1195 */
1187 if (cpuc->group_flag & PERF_EVENT_TXN) 1196 if (cpuc->group_flag & PERF_EVENT_TXN)
1188 return; 1197 return;
1189 1198
1199 /*
1200 * Not a TXN, therefore cleanup properly.
1201 */
1190 x86_pmu_stop(event, PERF_EF_UPDATE); 1202 x86_pmu_stop(event, PERF_EF_UPDATE);
1191 1203
1192 for (i = 0; i < cpuc->n_events; i++) { 1204 for (i = 0; i < cpuc->n_events; i++) {
1193 if (event == cpuc->event_list[i]) { 1205 if (event == cpuc->event_list[i])
1206 break;
1207 }
1194 1208
1195 if (x86_pmu.put_event_constraints) 1209 if (WARN_ON_ONCE(i == cpuc->n_events)) /* called ->del() without ->add() ? */
1196 x86_pmu.put_event_constraints(cpuc, event); 1210 return;
1197 1211
1198 while (++i < cpuc->n_events) 1212 /* If we have a newly added event; make sure to decrease n_added. */
1199 cpuc->event_list[i-1] = cpuc->event_list[i]; 1213 if (i >= cpuc->n_events - cpuc->n_added)
1214 --cpuc->n_added;
1215
1216 if (x86_pmu.put_event_constraints)
1217 x86_pmu.put_event_constraints(cpuc, event);
1218
1219 /* Delete the array entry. */
1220 while (++i < cpuc->n_events)
1221 cpuc->event_list[i-1] = cpuc->event_list[i];
1222 --cpuc->n_events;
1200 1223
1201 --cpuc->n_events;
1202 break;
1203 }
1204 }
1205 perf_event_update_userpage(event); 1224 perf_event_update_userpage(event);
1206} 1225}
1207 1226
@@ -1521,6 +1540,8 @@ static int __init init_hw_perf_events(void)
1521 1540
1522 pr_cont("%s PMU driver.\n", x86_pmu.name); 1541 pr_cont("%s PMU driver.\n", x86_pmu.name);
1523 1542
1543 x86_pmu.attr_rdpmc = 1; /* enable userspace RDPMC usage by default */
1544
1524 for (quirk = x86_pmu.quirks; quirk; quirk = quirk->next) 1545 for (quirk = x86_pmu.quirks; quirk; quirk = quirk->next)
1525 quirk->func(); 1546 quirk->func();
1526 1547
@@ -1534,7 +1555,6 @@ static int __init init_hw_perf_events(void)
1534 __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_counters) - 1, 1555 __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_counters) - 1,
1535 0, x86_pmu.num_counters, 0, 0); 1556 0, x86_pmu.num_counters, 0, 0);
1536 1557
1537 x86_pmu.attr_rdpmc = 1; /* enable userspace RDPMC usage by default */
1538 x86_pmu_format_group.attrs = x86_pmu.format_attrs; 1558 x86_pmu_format_group.attrs = x86_pmu.format_attrs;
1539 1559
1540 if (x86_pmu.event_attrs) 1560 if (x86_pmu.event_attrs)
@@ -1594,7 +1614,8 @@ static void x86_pmu_cancel_txn(struct pmu *pmu)
1594{ 1614{
1595 __this_cpu_and(cpu_hw_events.group_flag, ~PERF_EVENT_TXN); 1615 __this_cpu_and(cpu_hw_events.group_flag, ~PERF_EVENT_TXN);
1596 /* 1616 /*
1597 * Truncate the collected events. 1617 * Truncate collected array by the number of events added in this
1618 * transaction. See x86_pmu_add() and x86_pmu_*_txn().
1598 */ 1619 */
1599 __this_cpu_sub(cpu_hw_events.n_added, __this_cpu_read(cpu_hw_events.n_txn)); 1620 __this_cpu_sub(cpu_hw_events.n_added, __this_cpu_read(cpu_hw_events.n_txn));
1600 __this_cpu_sub(cpu_hw_events.n_events, __this_cpu_read(cpu_hw_events.n_txn)); 1621 __this_cpu_sub(cpu_hw_events.n_events, __this_cpu_read(cpu_hw_events.n_txn));
@@ -1605,6 +1626,8 @@ static void x86_pmu_cancel_txn(struct pmu *pmu)
1605 * Commit group events scheduling transaction 1626 * Commit group events scheduling transaction
1606 * Perform the group schedulability test as a whole 1627 * Perform the group schedulability test as a whole
1607 * Return 0 if success 1628 * Return 0 if success
1629 *
1630 * Does not cancel the transaction on failure; expects the caller to do this.
1608 */ 1631 */
1609static int x86_pmu_commit_txn(struct pmu *pmu) 1632static int x86_pmu_commit_txn(struct pmu *pmu)
1610{ 1633{
@@ -1820,9 +1843,12 @@ static ssize_t set_attr_rdpmc(struct device *cdev,
1820 if (ret) 1843 if (ret)
1821 return ret; 1844 return ret;
1822 1845
1846 if (x86_pmu.attr_rdpmc_broken)
1847 return -ENOTSUPP;
1848
1823 if (!!val != !!x86_pmu.attr_rdpmc) { 1849 if (!!val != !!x86_pmu.attr_rdpmc) {
1824 x86_pmu.attr_rdpmc = !!val; 1850 x86_pmu.attr_rdpmc = !!val;
1825 smp_call_function(change_rdpmc, (void *)val, 1); 1851 on_each_cpu(change_rdpmc, (void *)val, 1);
1826 } 1852 }
1827 1853
1828 return count; 1854 return count;
diff --git a/arch/x86/kernel/cpu/perf_event.h b/arch/x86/kernel/cpu/perf_event.h
index c1a861829d81..3b2f9bdd974b 100644
--- a/arch/x86/kernel/cpu/perf_event.h
+++ b/arch/x86/kernel/cpu/perf_event.h
@@ -130,9 +130,11 @@ struct cpu_hw_events {
130 unsigned long running[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; 130 unsigned long running[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
131 int enabled; 131 int enabled;
132 132
133 int n_events; 133 int n_events; /* the # of events in the below arrays */
134 int n_added; 134 int n_added; /* the # last events in the below arrays;
135 int n_txn; 135 they've never been enabled yet */
136 int n_txn; /* the # last events in the below arrays;
137 added in the current transaction */
136 int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */ 138 int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */
137 u64 tags[X86_PMC_IDX_MAX]; 139 u64 tags[X86_PMC_IDX_MAX];
138 struct perf_event *event_list[X86_PMC_IDX_MAX]; /* in enabled order */ 140 struct perf_event *event_list[X86_PMC_IDX_MAX]; /* in enabled order */
@@ -409,6 +411,7 @@ struct x86_pmu {
409 /* 411 /*
410 * sysfs attrs 412 * sysfs attrs
411 */ 413 */
414 int attr_rdpmc_broken;
412 int attr_rdpmc; 415 int attr_rdpmc;
413 struct attribute **format_attrs; 416 struct attribute **format_attrs;
414 struct attribute **event_attrs; 417 struct attribute **event_attrs;
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 0fa4f242f050..aa333d966886 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -1361,10 +1361,8 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)
1361 intel_pmu_disable_all(); 1361 intel_pmu_disable_all();
1362 handled = intel_pmu_drain_bts_buffer(); 1362 handled = intel_pmu_drain_bts_buffer();
1363 status = intel_pmu_get_status(); 1363 status = intel_pmu_get_status();
1364 if (!status) { 1364 if (!status)
1365 intel_pmu_enable_all(0); 1365 goto done;
1366 return handled;
1367 }
1368 1366
1369 loops = 0; 1367 loops = 0;
1370again: 1368again:
@@ -2310,10 +2308,7 @@ __init int intel_pmu_init(void)
2310 if (version > 1) 2308 if (version > 1)
2311 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3); 2309 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
2312 2310
2313 /* 2311 if (boot_cpu_has(X86_FEATURE_PDCM)) {
2314 * v2 and above have a perf capabilities MSR
2315 */
2316 if (version > 1) {
2317 u64 capabilities; 2312 u64 capabilities;
2318 2313
2319 rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities); 2314 rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
index 29c248799ced..bd2253d40cff 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
@@ -66,6 +66,47 @@ DEFINE_UNCORE_FORMAT_ATTR(mask_vnw, mask_vnw, "config2:3-4");
66DEFINE_UNCORE_FORMAT_ATTR(mask0, mask0, "config2:0-31"); 66DEFINE_UNCORE_FORMAT_ATTR(mask0, mask0, "config2:0-31");
67DEFINE_UNCORE_FORMAT_ATTR(mask1, mask1, "config2:32-63"); 67DEFINE_UNCORE_FORMAT_ATTR(mask1, mask1, "config2:32-63");
68 68
69static void uncore_pmu_start_hrtimer(struct intel_uncore_box *box);
70static void uncore_pmu_cancel_hrtimer(struct intel_uncore_box *box);
71static void uncore_perf_event_update(struct intel_uncore_box *box, struct perf_event *event);
72static void uncore_pmu_event_read(struct perf_event *event);
73
74static struct intel_uncore_pmu *uncore_event_to_pmu(struct perf_event *event)
75{
76 return container_of(event->pmu, struct intel_uncore_pmu, pmu);
77}
78
79static struct intel_uncore_box *
80uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpu)
81{
82 struct intel_uncore_box *box;
83
84 box = *per_cpu_ptr(pmu->box, cpu);
85 if (box)
86 return box;
87
88 raw_spin_lock(&uncore_box_lock);
89 list_for_each_entry(box, &pmu->box_list, list) {
90 if (box->phys_id == topology_physical_package_id(cpu)) {
91 atomic_inc(&box->refcnt);
92 *per_cpu_ptr(pmu->box, cpu) = box;
93 break;
94 }
95 }
96 raw_spin_unlock(&uncore_box_lock);
97
98 return *per_cpu_ptr(pmu->box, cpu);
99}
100
101static struct intel_uncore_box *uncore_event_to_box(struct perf_event *event)
102{
103 /*
104 * perf core schedules event on the basis of cpu, uncore events are
105 * collected by one of the cpus inside a physical package.
106 */
107 return uncore_pmu_to_box(uncore_event_to_pmu(event), smp_processor_id());
108}
109
69static u64 uncore_msr_read_counter(struct intel_uncore_box *box, struct perf_event *event) 110static u64 uncore_msr_read_counter(struct intel_uncore_box *box, struct perf_event *event)
70{ 111{
71 u64 count; 112 u64 count;
@@ -501,8 +542,11 @@ static struct extra_reg snbep_uncore_cbox_extra_regs[] = {
501 SNBEP_CBO_EVENT_EXTRA_REG(SNBEP_CBO_PMON_CTL_TID_EN, 542 SNBEP_CBO_EVENT_EXTRA_REG(SNBEP_CBO_PMON_CTL_TID_EN,
502 SNBEP_CBO_PMON_CTL_TID_EN, 0x1), 543 SNBEP_CBO_PMON_CTL_TID_EN, 0x1),
503 SNBEP_CBO_EVENT_EXTRA_REG(0x0334, 0xffff, 0x4), 544 SNBEP_CBO_EVENT_EXTRA_REG(0x0334, 0xffff, 0x4),
545 SNBEP_CBO_EVENT_EXTRA_REG(0x4334, 0xffff, 0x6),
504 SNBEP_CBO_EVENT_EXTRA_REG(0x0534, 0xffff, 0x4), 546 SNBEP_CBO_EVENT_EXTRA_REG(0x0534, 0xffff, 0x4),
547 SNBEP_CBO_EVENT_EXTRA_REG(0x4534, 0xffff, 0x6),
505 SNBEP_CBO_EVENT_EXTRA_REG(0x0934, 0xffff, 0x4), 548 SNBEP_CBO_EVENT_EXTRA_REG(0x0934, 0xffff, 0x4),
549 SNBEP_CBO_EVENT_EXTRA_REG(0x4934, 0xffff, 0x6),
506 SNBEP_CBO_EVENT_EXTRA_REG(0x4134, 0xffff, 0x6), 550 SNBEP_CBO_EVENT_EXTRA_REG(0x4134, 0xffff, 0x6),
507 SNBEP_CBO_EVENT_EXTRA_REG(0x0135, 0xffff, 0x8), 551 SNBEP_CBO_EVENT_EXTRA_REG(0x0135, 0xffff, 0x8),
508 SNBEP_CBO_EVENT_EXTRA_REG(0x0335, 0xffff, 0x8), 552 SNBEP_CBO_EVENT_EXTRA_REG(0x0335, 0xffff, 0x8),
@@ -1178,10 +1222,15 @@ static struct extra_reg ivt_uncore_cbox_extra_regs[] = {
1178 SNBEP_CBO_EVENT_EXTRA_REG(SNBEP_CBO_PMON_CTL_TID_EN, 1222 SNBEP_CBO_EVENT_EXTRA_REG(SNBEP_CBO_PMON_CTL_TID_EN,
1179 SNBEP_CBO_PMON_CTL_TID_EN, 0x1), 1223 SNBEP_CBO_PMON_CTL_TID_EN, 0x1),
1180 SNBEP_CBO_EVENT_EXTRA_REG(0x1031, 0x10ff, 0x2), 1224 SNBEP_CBO_EVENT_EXTRA_REG(0x1031, 0x10ff, 0x2),
1225 SNBEP_CBO_EVENT_EXTRA_REG(0x1134, 0xffff, 0x4),
1226 SNBEP_CBO_EVENT_EXTRA_REG(0x4134, 0xffff, 0xc),
1227 SNBEP_CBO_EVENT_EXTRA_REG(0x5134, 0xffff, 0xc),
1181 SNBEP_CBO_EVENT_EXTRA_REG(0x0334, 0xffff, 0x4), 1228 SNBEP_CBO_EVENT_EXTRA_REG(0x0334, 0xffff, 0x4),
1229 SNBEP_CBO_EVENT_EXTRA_REG(0x4334, 0xffff, 0xc),
1182 SNBEP_CBO_EVENT_EXTRA_REG(0x0534, 0xffff, 0x4), 1230 SNBEP_CBO_EVENT_EXTRA_REG(0x0534, 0xffff, 0x4),
1231 SNBEP_CBO_EVENT_EXTRA_REG(0x4534, 0xffff, 0xc),
1183 SNBEP_CBO_EVENT_EXTRA_REG(0x0934, 0xffff, 0x4), 1232 SNBEP_CBO_EVENT_EXTRA_REG(0x0934, 0xffff, 0x4),
1184 SNBEP_CBO_EVENT_EXTRA_REG(0x4134, 0xffff, 0xc), 1233 SNBEP_CBO_EVENT_EXTRA_REG(0x4934, 0xffff, 0xc),
1185 SNBEP_CBO_EVENT_EXTRA_REG(0x0135, 0xffff, 0x10), 1234 SNBEP_CBO_EVENT_EXTRA_REG(0x0135, 0xffff, 0x10),
1186 SNBEP_CBO_EVENT_EXTRA_REG(0x0335, 0xffff, 0x10), 1235 SNBEP_CBO_EVENT_EXTRA_REG(0x0335, 0xffff, 0x10),
1187 SNBEP_CBO_EVENT_EXTRA_REG(0x2135, 0xffff, 0x10), 1236 SNBEP_CBO_EVENT_EXTRA_REG(0x2135, 0xffff, 0x10),
@@ -1631,6 +1680,349 @@ static struct intel_uncore_type *snb_msr_uncores[] = {
1631 &snb_uncore_cbox, 1680 &snb_uncore_cbox,
1632 NULL, 1681 NULL,
1633}; 1682};
1683
1684enum {
1685 SNB_PCI_UNCORE_IMC,
1686};
1687
1688static struct uncore_event_desc snb_uncore_imc_events[] = {
1689 INTEL_UNCORE_EVENT_DESC(data_reads, "event=0x01"),
1690 INTEL_UNCORE_EVENT_DESC(data_reads.scale, "6.103515625e-5"),
1691 INTEL_UNCORE_EVENT_DESC(data_reads.unit, "MiB"),
1692
1693 INTEL_UNCORE_EVENT_DESC(data_writes, "event=0x02"),
1694 INTEL_UNCORE_EVENT_DESC(data_writes.scale, "6.103515625e-5"),
1695 INTEL_UNCORE_EVENT_DESC(data_writes.unit, "MiB"),
1696
1697 { /* end: all zeroes */ },
1698};
1699
1700#define SNB_UNCORE_PCI_IMC_EVENT_MASK 0xff
1701#define SNB_UNCORE_PCI_IMC_BAR_OFFSET 0x48
1702
1703/* page size multiple covering all config regs */
1704#define SNB_UNCORE_PCI_IMC_MAP_SIZE 0x6000
1705
1706#define SNB_UNCORE_PCI_IMC_DATA_READS 0x1
1707#define SNB_UNCORE_PCI_IMC_DATA_READS_BASE 0x5050
1708#define SNB_UNCORE_PCI_IMC_DATA_WRITES 0x2
1709#define SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE 0x5054
1710#define SNB_UNCORE_PCI_IMC_CTR_BASE SNB_UNCORE_PCI_IMC_DATA_READS_BASE
1711
1712static struct attribute *snb_uncore_imc_formats_attr[] = {
1713 &format_attr_event.attr,
1714 NULL,
1715};
1716
1717static struct attribute_group snb_uncore_imc_format_group = {
1718 .name = "format",
1719 .attrs = snb_uncore_imc_formats_attr,
1720};
1721
1722static void snb_uncore_imc_init_box(struct intel_uncore_box *box)
1723{
1724 struct pci_dev *pdev = box->pci_dev;
1725 int where = SNB_UNCORE_PCI_IMC_BAR_OFFSET;
1726 resource_size_t addr;
1727 u32 pci_dword;
1728
1729 pci_read_config_dword(pdev, where, &pci_dword);
1730 addr = pci_dword;
1731
1732#ifdef CONFIG_PHYS_ADDR_T_64BIT
1733 pci_read_config_dword(pdev, where + 4, &pci_dword);
1734 addr |= ((resource_size_t)pci_dword << 32);
1735#endif
1736
1737 addr &= ~(PAGE_SIZE - 1);
1738
1739 box->io_addr = ioremap(addr, SNB_UNCORE_PCI_IMC_MAP_SIZE);
1740 box->hrtimer_duration = UNCORE_SNB_IMC_HRTIMER_INTERVAL;
1741}
1742
1743static void snb_uncore_imc_enable_box(struct intel_uncore_box *box)
1744{}
1745
1746static void snb_uncore_imc_disable_box(struct intel_uncore_box *box)
1747{}
1748
1749static void snb_uncore_imc_enable_event(struct intel_uncore_box *box, struct perf_event *event)
1750{}
1751
1752static void snb_uncore_imc_disable_event(struct intel_uncore_box *box, struct perf_event *event)
1753{}
1754
1755static u64 snb_uncore_imc_read_counter(struct intel_uncore_box *box, struct perf_event *event)
1756{
1757 struct hw_perf_event *hwc = &event->hw;
1758
1759 return (u64)*(unsigned int *)(box->io_addr + hwc->event_base);
1760}
1761
1762/*
1763 * custom event_init() function because we define our own fixed, free
1764 * running counters, so we do not want to conflict with generic uncore
1765 * logic. Also simplifies processing
1766 */
1767static int snb_uncore_imc_event_init(struct perf_event *event)
1768{
1769 struct intel_uncore_pmu *pmu;
1770 struct intel_uncore_box *box;
1771 struct hw_perf_event *hwc = &event->hw;
1772 u64 cfg = event->attr.config & SNB_UNCORE_PCI_IMC_EVENT_MASK;
1773 int idx, base;
1774
1775 if (event->attr.type != event->pmu->type)
1776 return -ENOENT;
1777
1778 pmu = uncore_event_to_pmu(event);
1779 /* no device found for this pmu */
1780 if (pmu->func_id < 0)
1781 return -ENOENT;
1782
1783 /* Sampling not supported yet */
1784 if (hwc->sample_period)
1785 return -EINVAL;
1786
1787 /* unsupported modes and filters */
1788 if (event->attr.exclude_user ||
1789 event->attr.exclude_kernel ||
1790 event->attr.exclude_hv ||
1791 event->attr.exclude_idle ||
1792 event->attr.exclude_host ||
1793 event->attr.exclude_guest ||
1794 event->attr.sample_period) /* no sampling */
1795 return -EINVAL;
1796
1797 /*
1798 * Place all uncore events for a particular physical package
1799 * onto a single cpu
1800 */
1801 if (event->cpu < 0)
1802 return -EINVAL;
1803
1804 /* check only supported bits are set */
1805 if (event->attr.config & ~SNB_UNCORE_PCI_IMC_EVENT_MASK)
1806 return -EINVAL;
1807
1808 box = uncore_pmu_to_box(pmu, event->cpu);
1809 if (!box || box->cpu < 0)
1810 return -EINVAL;
1811
1812 event->cpu = box->cpu;
1813
1814 event->hw.idx = -1;
1815 event->hw.last_tag = ~0ULL;
1816 event->hw.extra_reg.idx = EXTRA_REG_NONE;
1817 event->hw.branch_reg.idx = EXTRA_REG_NONE;
1818 /*
1819 * check event is known (whitelist, determines counter)
1820 */
1821 switch (cfg) {
1822 case SNB_UNCORE_PCI_IMC_DATA_READS:
1823 base = SNB_UNCORE_PCI_IMC_DATA_READS_BASE;
1824 idx = UNCORE_PMC_IDX_FIXED;
1825 break;
1826 case SNB_UNCORE_PCI_IMC_DATA_WRITES:
1827 base = SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE;
1828 idx = UNCORE_PMC_IDX_FIXED + 1;
1829 break;
1830 default:
1831 return -EINVAL;
1832 }
1833
1834 /* must be done before validate_group */
1835 event->hw.event_base = base;
1836 event->hw.config = cfg;
1837 event->hw.idx = idx;
1838
1839 /* no group validation needed, we have free running counters */
1840
1841 return 0;
1842}
1843
1844static int snb_uncore_imc_hw_config(struct intel_uncore_box *box, struct perf_event *event)
1845{
1846 return 0;
1847}
1848
1849static void snb_uncore_imc_event_start(struct perf_event *event, int flags)
1850{
1851 struct intel_uncore_box *box = uncore_event_to_box(event);
1852 u64 count;
1853
1854 if (WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED)))
1855 return;
1856
1857 event->hw.state = 0;
1858 box->n_active++;
1859
1860 list_add_tail(&event->active_entry, &box->active_list);
1861
1862 count = snb_uncore_imc_read_counter(box, event);
1863 local64_set(&event->hw.prev_count, count);
1864
1865 if (box->n_active == 1)
1866 uncore_pmu_start_hrtimer(box);
1867}
1868
1869static void snb_uncore_imc_event_stop(struct perf_event *event, int flags)
1870{
1871 struct intel_uncore_box *box = uncore_event_to_box(event);
1872 struct hw_perf_event *hwc = &event->hw;
1873
1874 if (!(hwc->state & PERF_HES_STOPPED)) {
1875 box->n_active--;
1876
1877 WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED);
1878 hwc->state |= PERF_HES_STOPPED;
1879
1880 list_del(&event->active_entry);
1881
1882 if (box->n_active == 0)
1883 uncore_pmu_cancel_hrtimer(box);
1884 }
1885
1886 if ((flags & PERF_EF_UPDATE) && !(hwc->state & PERF_HES_UPTODATE)) {
1887 /*
1888 * Drain the remaining delta count out of a event
1889 * that we are disabling:
1890 */
1891 uncore_perf_event_update(box, event);
1892 hwc->state |= PERF_HES_UPTODATE;
1893 }
1894}
1895
1896static int snb_uncore_imc_event_add(struct perf_event *event, int flags)
1897{
1898 struct intel_uncore_box *box = uncore_event_to_box(event);
1899 struct hw_perf_event *hwc = &event->hw;
1900
1901 if (!box)
1902 return -ENODEV;
1903
1904 hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
1905 if (!(flags & PERF_EF_START))
1906 hwc->state |= PERF_HES_ARCH;
1907
1908 snb_uncore_imc_event_start(event, 0);
1909
1910 box->n_events++;
1911
1912 return 0;
1913}
1914
1915static void snb_uncore_imc_event_del(struct perf_event *event, int flags)
1916{
1917 struct intel_uncore_box *box = uncore_event_to_box(event);
1918 int i;
1919
1920 snb_uncore_imc_event_stop(event, PERF_EF_UPDATE);
1921
1922 for (i = 0; i < box->n_events; i++) {
1923 if (event == box->event_list[i]) {
1924 --box->n_events;
1925 break;
1926 }
1927 }
1928}
1929
1930static int snb_pci2phy_map_init(int devid)
1931{
1932 struct pci_dev *dev = NULL;
1933 int bus;
1934
1935 dev = pci_get_device(PCI_VENDOR_ID_INTEL, devid, dev);
1936 if (!dev)
1937 return -ENOTTY;
1938
1939 bus = dev->bus->number;
1940
1941 pcibus_to_physid[bus] = 0;
1942
1943 pci_dev_put(dev);
1944
1945 return 0;
1946}
1947
1948static struct pmu snb_uncore_imc_pmu = {
1949 .task_ctx_nr = perf_invalid_context,
1950 .event_init = snb_uncore_imc_event_init,
1951 .add = snb_uncore_imc_event_add,
1952 .del = snb_uncore_imc_event_del,
1953 .start = snb_uncore_imc_event_start,
1954 .stop = snb_uncore_imc_event_stop,
1955 .read = uncore_pmu_event_read,
1956};
1957
1958static struct intel_uncore_ops snb_uncore_imc_ops = {
1959 .init_box = snb_uncore_imc_init_box,
1960 .enable_box = snb_uncore_imc_enable_box,
1961 .disable_box = snb_uncore_imc_disable_box,
1962 .disable_event = snb_uncore_imc_disable_event,
1963 .enable_event = snb_uncore_imc_enable_event,
1964 .hw_config = snb_uncore_imc_hw_config,
1965 .read_counter = snb_uncore_imc_read_counter,
1966};
1967
1968static struct intel_uncore_type snb_uncore_imc = {
1969 .name = "imc",
1970 .num_counters = 2,
1971 .num_boxes = 1,
1972 .fixed_ctr_bits = 32,
1973 .fixed_ctr = SNB_UNCORE_PCI_IMC_CTR_BASE,
1974 .event_descs = snb_uncore_imc_events,
1975 .format_group = &snb_uncore_imc_format_group,
1976 .perf_ctr = SNB_UNCORE_PCI_IMC_DATA_READS_BASE,
1977 .event_mask = SNB_UNCORE_PCI_IMC_EVENT_MASK,
1978 .ops = &snb_uncore_imc_ops,
1979 .pmu = &snb_uncore_imc_pmu,
1980};
1981
1982static struct intel_uncore_type *snb_pci_uncores[] = {
1983 [SNB_PCI_UNCORE_IMC] = &snb_uncore_imc,
1984 NULL,
1985};
1986
1987static DEFINE_PCI_DEVICE_TABLE(snb_uncore_pci_ids) = {
1988 { /* IMC */
1989 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SNB_IMC),
1990 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
1991 },
1992 { /* end: all zeroes */ },
1993};
1994
1995static DEFINE_PCI_DEVICE_TABLE(ivb_uncore_pci_ids) = {
1996 { /* IMC */
1997 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IVB_IMC),
1998 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
1999 },
2000 { /* end: all zeroes */ },
2001};
2002
2003static DEFINE_PCI_DEVICE_TABLE(hsw_uncore_pci_ids) = {
2004 { /* IMC */
2005 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HSW_IMC),
2006 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
2007 },
2008 { /* end: all zeroes */ },
2009};
2010
2011static struct pci_driver snb_uncore_pci_driver = {
2012 .name = "snb_uncore",
2013 .id_table = snb_uncore_pci_ids,
2014};
2015
2016static struct pci_driver ivb_uncore_pci_driver = {
2017 .name = "ivb_uncore",
2018 .id_table = ivb_uncore_pci_ids,
2019};
2020
2021static struct pci_driver hsw_uncore_pci_driver = {
2022 .name = "hsw_uncore",
2023 .id_table = hsw_uncore_pci_ids,
2024};
2025
1634/* end of Sandy Bridge uncore support */ 2026/* end of Sandy Bridge uncore support */
1635 2027
1636/* Nehalem uncore support */ 2028/* Nehalem uncore support */
@@ -2781,6 +3173,7 @@ again:
2781static enum hrtimer_restart uncore_pmu_hrtimer(struct hrtimer *hrtimer) 3173static enum hrtimer_restart uncore_pmu_hrtimer(struct hrtimer *hrtimer)
2782{ 3174{
2783 struct intel_uncore_box *box; 3175 struct intel_uncore_box *box;
3176 struct perf_event *event;
2784 unsigned long flags; 3177 unsigned long flags;
2785 int bit; 3178 int bit;
2786 3179
@@ -2793,19 +3186,27 @@ static enum hrtimer_restart uncore_pmu_hrtimer(struct hrtimer *hrtimer)
2793 */ 3186 */
2794 local_irq_save(flags); 3187 local_irq_save(flags);
2795 3188
3189 /*
3190 * handle boxes with an active event list as opposed to active
3191 * counters
3192 */
3193 list_for_each_entry(event, &box->active_list, active_entry) {
3194 uncore_perf_event_update(box, event);
3195 }
3196
2796 for_each_set_bit(bit, box->active_mask, UNCORE_PMC_IDX_MAX) 3197 for_each_set_bit(bit, box->active_mask, UNCORE_PMC_IDX_MAX)
2797 uncore_perf_event_update(box, box->events[bit]); 3198 uncore_perf_event_update(box, box->events[bit]);
2798 3199
2799 local_irq_restore(flags); 3200 local_irq_restore(flags);
2800 3201
2801 hrtimer_forward_now(hrtimer, ns_to_ktime(UNCORE_PMU_HRTIMER_INTERVAL)); 3202 hrtimer_forward_now(hrtimer, ns_to_ktime(box->hrtimer_duration));
2802 return HRTIMER_RESTART; 3203 return HRTIMER_RESTART;
2803} 3204}
2804 3205
2805static void uncore_pmu_start_hrtimer(struct intel_uncore_box *box) 3206static void uncore_pmu_start_hrtimer(struct intel_uncore_box *box)
2806{ 3207{
2807 __hrtimer_start_range_ns(&box->hrtimer, 3208 __hrtimer_start_range_ns(&box->hrtimer,
2808 ns_to_ktime(UNCORE_PMU_HRTIMER_INTERVAL), 0, 3209 ns_to_ktime(box->hrtimer_duration), 0,
2809 HRTIMER_MODE_REL_PINNED, 0); 3210 HRTIMER_MODE_REL_PINNED, 0);
2810} 3211}
2811 3212
@@ -2839,43 +3240,12 @@ static struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type,
2839 box->cpu = -1; 3240 box->cpu = -1;
2840 box->phys_id = -1; 3241 box->phys_id = -1;
2841 3242
2842 return box; 3243 /* set default hrtimer timeout */
2843} 3244 box->hrtimer_duration = UNCORE_PMU_HRTIMER_INTERVAL;
2844
2845static struct intel_uncore_box *
2846uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpu)
2847{
2848 struct intel_uncore_box *box;
2849
2850 box = *per_cpu_ptr(pmu->box, cpu);
2851 if (box)
2852 return box;
2853 3245
2854 raw_spin_lock(&uncore_box_lock); 3246 INIT_LIST_HEAD(&box->active_list);
2855 list_for_each_entry(box, &pmu->box_list, list) {
2856 if (box->phys_id == topology_physical_package_id(cpu)) {
2857 atomic_inc(&box->refcnt);
2858 *per_cpu_ptr(pmu->box, cpu) = box;
2859 break;
2860 }
2861 }
2862 raw_spin_unlock(&uncore_box_lock);
2863 3247
2864 return *per_cpu_ptr(pmu->box, cpu); 3248 return box;
2865}
2866
2867static struct intel_uncore_pmu *uncore_event_to_pmu(struct perf_event *event)
2868{
2869 return container_of(event->pmu, struct intel_uncore_pmu, pmu);
2870}
2871
2872static struct intel_uncore_box *uncore_event_to_box(struct perf_event *event)
2873{
2874 /*
2875 * perf core schedules event on the basis of cpu, uncore events are
2876 * collected by one of the cpus inside a physical package.
2877 */
2878 return uncore_pmu_to_box(uncore_event_to_pmu(event), smp_processor_id());
2879} 3249}
2880 3250
2881static int 3251static int
@@ -3271,16 +3641,21 @@ static int __init uncore_pmu_register(struct intel_uncore_pmu *pmu)
3271{ 3641{
3272 int ret; 3642 int ret;
3273 3643
3274 pmu->pmu = (struct pmu) { 3644 if (!pmu->type->pmu) {
3275 .attr_groups = pmu->type->attr_groups, 3645 pmu->pmu = (struct pmu) {
3276 .task_ctx_nr = perf_invalid_context, 3646 .attr_groups = pmu->type->attr_groups,
3277 .event_init = uncore_pmu_event_init, 3647 .task_ctx_nr = perf_invalid_context,
3278 .add = uncore_pmu_event_add, 3648 .event_init = uncore_pmu_event_init,
3279 .del = uncore_pmu_event_del, 3649 .add = uncore_pmu_event_add,
3280 .start = uncore_pmu_event_start, 3650 .del = uncore_pmu_event_del,
3281 .stop = uncore_pmu_event_stop, 3651 .start = uncore_pmu_event_start,
3282 .read = uncore_pmu_event_read, 3652 .stop = uncore_pmu_event_stop,
3283 }; 3653 .read = uncore_pmu_event_read,
3654 };
3655 } else {
3656 pmu->pmu = *pmu->type->pmu;
3657 pmu->pmu.attr_groups = pmu->type->attr_groups;
3658 }
3284 3659
3285 if (pmu->type->num_boxes == 1) { 3660 if (pmu->type->num_boxes == 1) {
3286 if (strlen(pmu->type->name) > 0) 3661 if (strlen(pmu->type->name) > 0)
@@ -3326,6 +3701,8 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
3326 if (!pmus) 3701 if (!pmus)
3327 return -ENOMEM; 3702 return -ENOMEM;
3328 3703
3704 type->pmus = pmus;
3705
3329 type->unconstrainted = (struct event_constraint) 3706 type->unconstrainted = (struct event_constraint)
3330 __EVENT_CONSTRAINT(0, (1ULL << type->num_counters) - 1, 3707 __EVENT_CONSTRAINT(0, (1ULL << type->num_counters) - 1,
3331 0, type->num_counters, 0, 0); 3708 0, type->num_counters, 0, 0);
@@ -3361,7 +3738,6 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
3361 } 3738 }
3362 3739
3363 type->pmu_group = &uncore_pmu_attr_group; 3740 type->pmu_group = &uncore_pmu_attr_group;
3364 type->pmus = pmus;
3365 return 0; 3741 return 0;
3366fail: 3742fail:
3367 uncore_type_exit(type); 3743 uncore_type_exit(type);
@@ -3493,6 +3869,28 @@ static int __init uncore_pci_init(void)
3493 pci_uncores = ivt_pci_uncores; 3869 pci_uncores = ivt_pci_uncores;
3494 uncore_pci_driver = &ivt_uncore_pci_driver; 3870 uncore_pci_driver = &ivt_uncore_pci_driver;
3495 break; 3871 break;
3872 case 42: /* Sandy Bridge */
3873 ret = snb_pci2phy_map_init(PCI_DEVICE_ID_INTEL_SNB_IMC);
3874 if (ret)
3875 return ret;
3876 pci_uncores = snb_pci_uncores;
3877 uncore_pci_driver = &snb_uncore_pci_driver;
3878 break;
3879 case 58: /* Ivy Bridge */
3880 ret = snb_pci2phy_map_init(PCI_DEVICE_ID_INTEL_IVB_IMC);
3881 if (ret)
3882 return ret;
3883 pci_uncores = snb_pci_uncores;
3884 uncore_pci_driver = &ivb_uncore_pci_driver;
3885 break;
3886 case 60: /* Haswell */
3887 case 69: /* Haswell Celeron */
3888 ret = snb_pci2phy_map_init(PCI_DEVICE_ID_INTEL_HSW_IMC);
3889 if (ret)
3890 return ret;
3891 pci_uncores = snb_pci_uncores;
3892 uncore_pci_driver = &hsw_uncore_pci_driver;
3893 break;
3496 default: 3894 default:
3497 return 0; 3895 return 0;
3498 } 3896 }
@@ -3764,7 +4162,7 @@ static void __init uncore_cpu_setup(void *dummy)
3764 4162
3765static int __init uncore_cpu_init(void) 4163static int __init uncore_cpu_init(void)
3766{ 4164{
3767 int ret, cpu, max_cores; 4165 int ret, max_cores;
3768 4166
3769 max_cores = boot_cpu_data.x86_max_cores; 4167 max_cores = boot_cpu_data.x86_max_cores;
3770 switch (boot_cpu_data.x86_model) { 4168 switch (boot_cpu_data.x86_model) {
@@ -3808,29 +4206,6 @@ static int __init uncore_cpu_init(void)
3808 if (ret) 4206 if (ret)
3809 return ret; 4207 return ret;
3810 4208
3811 get_online_cpus();
3812
3813 for_each_online_cpu(cpu) {
3814 int i, phys_id = topology_physical_package_id(cpu);
3815
3816 for_each_cpu(i, &uncore_cpu_mask) {
3817 if (phys_id == topology_physical_package_id(i)) {
3818 phys_id = -1;
3819 break;
3820 }
3821 }
3822 if (phys_id < 0)
3823 continue;
3824
3825 uncore_cpu_prepare(cpu, phys_id);
3826 uncore_event_init_cpu(cpu);
3827 }
3828 on_each_cpu(uncore_cpu_setup, NULL, 1);
3829
3830 register_cpu_notifier(&uncore_cpu_nb);
3831
3832 put_online_cpus();
3833
3834 return 0; 4209 return 0;
3835} 4210}
3836 4211
@@ -3859,6 +4234,41 @@ static int __init uncore_pmus_register(void)
3859 return 0; 4234 return 0;
3860} 4235}
3861 4236
4237static void __init uncore_cpumask_init(void)
4238{
4239 int cpu;
4240
4241 /*
4242 * ony invoke once from msr or pci init code
4243 */
4244 if (!cpumask_empty(&uncore_cpu_mask))
4245 return;
4246
4247 get_online_cpus();
4248
4249 for_each_online_cpu(cpu) {
4250 int i, phys_id = topology_physical_package_id(cpu);
4251
4252 for_each_cpu(i, &uncore_cpu_mask) {
4253 if (phys_id == topology_physical_package_id(i)) {
4254 phys_id = -1;
4255 break;
4256 }
4257 }
4258 if (phys_id < 0)
4259 continue;
4260
4261 uncore_cpu_prepare(cpu, phys_id);
4262 uncore_event_init_cpu(cpu);
4263 }
4264 on_each_cpu(uncore_cpu_setup, NULL, 1);
4265
4266 register_cpu_notifier(&uncore_cpu_nb);
4267
4268 put_online_cpus();
4269}
4270
4271
3862static int __init intel_uncore_init(void) 4272static int __init intel_uncore_init(void)
3863{ 4273{
3864 int ret; 4274 int ret;
@@ -3877,6 +4287,7 @@ static int __init intel_uncore_init(void)
3877 uncore_pci_exit(); 4287 uncore_pci_exit();
3878 goto fail; 4288 goto fail;
3879 } 4289 }
4290 uncore_cpumask_init();
3880 4291
3881 uncore_pmus_register(); 4292 uncore_pmus_register();
3882 return 0; 4293 return 0;
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
index a80ab71a883d..90236f0c94a9 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
@@ -6,6 +6,7 @@
6 6
7#define UNCORE_PMU_NAME_LEN 32 7#define UNCORE_PMU_NAME_LEN 32
8#define UNCORE_PMU_HRTIMER_INTERVAL (60LL * NSEC_PER_SEC) 8#define UNCORE_PMU_HRTIMER_INTERVAL (60LL * NSEC_PER_SEC)
9#define UNCORE_SNB_IMC_HRTIMER_INTERVAL (5ULL * NSEC_PER_SEC)
9 10
10#define UNCORE_FIXED_EVENT 0xff 11#define UNCORE_FIXED_EVENT 0xff
11#define UNCORE_PMC_IDX_MAX_GENERIC 8 12#define UNCORE_PMC_IDX_MAX_GENERIC 8
@@ -440,6 +441,7 @@ struct intel_uncore_type {
440 struct intel_uncore_ops *ops; 441 struct intel_uncore_ops *ops;
441 struct uncore_event_desc *event_descs; 442 struct uncore_event_desc *event_descs;
442 const struct attribute_group *attr_groups[4]; 443 const struct attribute_group *attr_groups[4];
444 struct pmu *pmu; /* for custom pmu ops */
443}; 445};
444 446
445#define pmu_group attr_groups[0] 447#define pmu_group attr_groups[0]
@@ -488,8 +490,11 @@ struct intel_uncore_box {
488 u64 tags[UNCORE_PMC_IDX_MAX]; 490 u64 tags[UNCORE_PMC_IDX_MAX];
489 struct pci_dev *pci_dev; 491 struct pci_dev *pci_dev;
490 struct intel_uncore_pmu *pmu; 492 struct intel_uncore_pmu *pmu;
493 u64 hrtimer_duration; /* hrtimer timeout for this box */
491 struct hrtimer hrtimer; 494 struct hrtimer hrtimer;
492 struct list_head list; 495 struct list_head list;
496 struct list_head active_list;
497 void *io_addr;
493 struct intel_uncore_extra_reg shared_regs[0]; 498 struct intel_uncore_extra_reg shared_regs[0];
494}; 499};
495 500
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c
index 3486e6660357..5d466b7d8609 100644
--- a/arch/x86/kernel/cpu/perf_event_p4.c
+++ b/arch/x86/kernel/cpu/perf_event_p4.c
@@ -1257,7 +1257,24 @@ again:
1257 pass++; 1257 pass++;
1258 goto again; 1258 goto again;
1259 } 1259 }
1260 1260 /*
1261 * Perf does test runs to see if a whole group can be assigned
1262 * together succesfully. There can be multiple rounds of this.
1263 * Unfortunately, p4_pmu_swap_config_ts touches the hwc->config
1264 * bits, such that the next round of group assignments will
1265 * cause the above p4_should_swap_ts to pass instead of fail.
1266 * This leads to counters exclusive to thread0 being used by
1267 * thread1.
1268 *
1269 * Solve this with a cheap hack, reset the idx back to -1 to
1270 * force a new lookup (p4_next_cntr) to get the right counter
1271 * for the right thread.
1272 *
1273 * This probably doesn't comply with the general spirit of how
1274 * perf wants to work, but P4 is special. :-(
1275 */
1276 if (p4_should_swap_ts(hwc->config, cpu))
1277 hwc->idx = -1;
1261 p4_pmu_swap_config_ts(hwc, cpu); 1278 p4_pmu_swap_config_ts(hwc, cpu);
1262 if (assign) 1279 if (assign)
1263 assign[i] = cntr_idx; 1280 assign[i] = cntr_idx;
@@ -1322,6 +1339,7 @@ static __initconst const struct x86_pmu p4_pmu = {
1322__init int p4_pmu_init(void) 1339__init int p4_pmu_init(void)
1323{ 1340{
1324 unsigned int low, high; 1341 unsigned int low, high;
1342 int i, reg;
1325 1343
1326 /* If we get stripped -- indexing fails */ 1344 /* If we get stripped -- indexing fails */
1327 BUILD_BUG_ON(ARCH_P4_MAX_CCCR > INTEL_PMC_MAX_GENERIC); 1345 BUILD_BUG_ON(ARCH_P4_MAX_CCCR > INTEL_PMC_MAX_GENERIC);
@@ -1340,5 +1358,19 @@ __init int p4_pmu_init(void)
1340 1358
1341 x86_pmu = p4_pmu; 1359 x86_pmu = p4_pmu;
1342 1360
1361 /*
1362 * Even though the counters are configured to interrupt a particular
1363 * logical processor when an overflow happens, testing has shown that
1364 * on kdump kernels (which uses a single cpu), thread1's counter
1365 * continues to run and will report an NMI on thread0. Due to the
1366 * overflow bug, this leads to a stream of unknown NMIs.
1367 *
1368 * Solve this by zero'ing out the registers to mimic a reset.
1369 */
1370 for (i = 0; i < x86_pmu.num_counters; i++) {
1371 reg = x86_pmu_config_addr(i);
1372 wrmsrl_safe(reg, 0ULL);
1373 }
1374
1343 return 0; 1375 return 0;
1344} 1376}
diff --git a/arch/x86/kernel/cpu/perf_event_p6.c b/arch/x86/kernel/cpu/perf_event_p6.c
index b1e2fe115323..7c1a0c07b607 100644
--- a/arch/x86/kernel/cpu/perf_event_p6.c
+++ b/arch/x86/kernel/cpu/perf_event_p6.c
@@ -231,31 +231,49 @@ static __initconst const struct x86_pmu p6_pmu = {
231 231
232}; 232};
233 233
234static __init void p6_pmu_rdpmc_quirk(void)
235{
236 if (boot_cpu_data.x86_mask < 9) {
237 /*
238 * PPro erratum 26; fixed in stepping 9 and above.
239 */
240 pr_warn("Userspace RDPMC support disabled due to a CPU erratum\n");
241 x86_pmu.attr_rdpmc_broken = 1;
242 x86_pmu.attr_rdpmc = 0;
243 }
244}
245
234__init int p6_pmu_init(void) 246__init int p6_pmu_init(void)
235{ 247{
248 x86_pmu = p6_pmu;
249
236 switch (boot_cpu_data.x86_model) { 250 switch (boot_cpu_data.x86_model) {
237 case 1: 251 case 1: /* Pentium Pro */
238 case 3: /* Pentium Pro */ 252 x86_add_quirk(p6_pmu_rdpmc_quirk);
239 case 5: 253 break;
240 case 6: /* Pentium II */ 254
241 case 7: 255 case 3: /* Pentium II - Klamath */
242 case 8: 256 case 5: /* Pentium II - Deschutes */
243 case 11: /* Pentium III */ 257 case 6: /* Pentium II - Mendocino */
244 case 9:
245 case 13:
246 /* Pentium M */
247 break; 258 break;
259
260 case 7: /* Pentium III - Katmai */
261 case 8: /* Pentium III - Coppermine */
262 case 10: /* Pentium III Xeon */
263 case 11: /* Pentium III - Tualatin */
264 break;
265
266 case 9: /* Pentium M - Banias */
267 case 13: /* Pentium M - Dothan */
268 break;
269
248 default: 270 default:
249 pr_cont("unsupported p6 CPU model %d ", 271 pr_cont("unsupported p6 CPU model %d ", boot_cpu_data.x86_model);
250 boot_cpu_data.x86_model);
251 return -ENODEV; 272 return -ENODEV;
252 } 273 }
253 274
254 x86_pmu = p6_pmu;
255
256 memcpy(hw_cache_event_ids, p6_hw_cache_event_ids, 275 memcpy(hw_cache_event_ids, p6_hw_cache_event_ids,
257 sizeof(hw_cache_event_ids)); 276 sizeof(hw_cache_event_ids));
258 277
259
260 return 0; 278 return 0;
261} 279}
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index a57902efe2d5..507de8066594 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -57,9 +57,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
57{ 57{
58#ifdef CONFIG_X86_32 58#ifdef CONFIG_X86_32
59 struct pt_regs fixed_regs; 59 struct pt_regs fixed_regs;
60#endif
61 60
62#ifdef CONFIG_X86_32
63 if (!user_mode_vm(regs)) { 61 if (!user_mode_vm(regs)) {
64 crash_fixup_ss_esp(&fixed_regs, regs); 62 crash_fixup_ss_esp(&fixed_regs, regs);
65 regs = &fixed_regs; 63 regs = &fixed_regs;
diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
index f2a1770ca176..a21d49c071db 100644
--- a/arch/x86/kernel/dumpstack_32.c
+++ b/arch/x86/kernel/dumpstack_32.c
@@ -30,7 +30,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
30 unsigned long dummy; 30 unsigned long dummy;
31 31
32 stack = &dummy; 32 stack = &dummy;
33 if (task && task != current) 33 if (task != current)
34 stack = (unsigned long *)task->thread.sp; 34 stack = (unsigned long *)task->thread.sp;
35 } 35 }
36 36
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index d4bdd253fea7..e6253195a301 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -77,8 +77,7 @@ within(unsigned long addr, unsigned long start, unsigned long end)
77 return addr >= start && addr < end; 77 return addr >= start && addr < end;
78} 78}
79 79
80static int 80static unsigned long text_ip_addr(unsigned long ip)
81do_ftrace_mod_code(unsigned long ip, const void *new_code)
82{ 81{
83 /* 82 /*
84 * On x86_64, kernel text mappings are mapped read-only with 83 * On x86_64, kernel text mappings are mapped read-only with
@@ -91,7 +90,7 @@ do_ftrace_mod_code(unsigned long ip, const void *new_code)
91 if (within(ip, (unsigned long)_text, (unsigned long)_etext)) 90 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
92 ip = (unsigned long)__va(__pa_symbol(ip)); 91 ip = (unsigned long)__va(__pa_symbol(ip));
93 92
94 return probe_kernel_write((void *)ip, new_code, MCOUNT_INSN_SIZE); 93 return ip;
95} 94}
96 95
97static const unsigned char *ftrace_nop_replace(void) 96static const unsigned char *ftrace_nop_replace(void)
@@ -123,8 +122,10 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
123 if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0) 122 if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
124 return -EINVAL; 123 return -EINVAL;
125 124
125 ip = text_ip_addr(ip);
126
126 /* replace the text with the new text */ 127 /* replace the text with the new text */
127 if (do_ftrace_mod_code(ip, new_code)) 128 if (probe_kernel_write((void *)ip, new_code, MCOUNT_INSN_SIZE))
128 return -EPERM; 129 return -EPERM;
129 130
130 sync_core(); 131 sync_core();
@@ -221,37 +222,51 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
221 return -EINVAL; 222 return -EINVAL;
222} 223}
223 224
224int ftrace_update_ftrace_func(ftrace_func_t func) 225static unsigned long ftrace_update_func;
226
227static int update_ftrace_func(unsigned long ip, void *new)
225{ 228{
226 unsigned long ip = (unsigned long)(&ftrace_call); 229 unsigned char old[MCOUNT_INSN_SIZE];
227 unsigned char old[MCOUNT_INSN_SIZE], *new;
228 int ret; 230 int ret;
229 231
230 memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE); 232 memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
231 new = ftrace_call_replace(ip, (unsigned long)func); 233
234 ftrace_update_func = ip;
235 /* Make sure the breakpoints see the ftrace_update_func update */
236 smp_wmb();
232 237
233 /* See comment above by declaration of modifying_ftrace_code */ 238 /* See comment above by declaration of modifying_ftrace_code */
234 atomic_inc(&modifying_ftrace_code); 239 atomic_inc(&modifying_ftrace_code);
235 240
236 ret = ftrace_modify_code(ip, old, new); 241 ret = ftrace_modify_code(ip, old, new);
237 242
243 atomic_dec(&modifying_ftrace_code);
244
245 return ret;
246}
247
248int ftrace_update_ftrace_func(ftrace_func_t func)
249{
250 unsigned long ip = (unsigned long)(&ftrace_call);
251 unsigned char *new;
252 int ret;
253
254 new = ftrace_call_replace(ip, (unsigned long)func);
255 ret = update_ftrace_func(ip, new);
256
238 /* Also update the regs callback function */ 257 /* Also update the regs callback function */
239 if (!ret) { 258 if (!ret) {
240 ip = (unsigned long)(&ftrace_regs_call); 259 ip = (unsigned long)(&ftrace_regs_call);
241 memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
242 new = ftrace_call_replace(ip, (unsigned long)func); 260 new = ftrace_call_replace(ip, (unsigned long)func);
243 ret = ftrace_modify_code(ip, old, new); 261 ret = update_ftrace_func(ip, new);
244 } 262 }
245 263
246 atomic_dec(&modifying_ftrace_code);
247
248 return ret; 264 return ret;
249} 265}
250 266
251static int is_ftrace_caller(unsigned long ip) 267static int is_ftrace_caller(unsigned long ip)
252{ 268{
253 if (ip == (unsigned long)(&ftrace_call) || 269 if (ip == ftrace_update_func)
254 ip == (unsigned long)(&ftrace_regs_call))
255 return 1; 270 return 1;
256 271
257 return 0; 272 return 0;
@@ -677,45 +692,41 @@ int __init ftrace_dyn_arch_init(void *data)
677#ifdef CONFIG_DYNAMIC_FTRACE 692#ifdef CONFIG_DYNAMIC_FTRACE
678extern void ftrace_graph_call(void); 693extern void ftrace_graph_call(void);
679 694
680static int ftrace_mod_jmp(unsigned long ip, 695static unsigned char *ftrace_jmp_replace(unsigned long ip, unsigned long addr)
681 int old_offset, int new_offset)
682{ 696{
683 unsigned char code[MCOUNT_INSN_SIZE]; 697 static union ftrace_code_union calc;
684 698
685 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE)) 699 /* Jmp not a call (ignore the .e8) */
686 return -EFAULT; 700 calc.e8 = 0xe9;
701 calc.offset = ftrace_calc_offset(ip + MCOUNT_INSN_SIZE, addr);
687 702
688 if (code[0] != 0xe9 || old_offset != *(int *)(&code[1])) 703 /*
689 return -EINVAL; 704 * ftrace external locks synchronize the access to the static variable.
705 */
706 return calc.code;
707}
690 708
691 *(int *)(&code[1]) = new_offset; 709static int ftrace_mod_jmp(unsigned long ip, void *func)
710{
711 unsigned char *new;
692 712
693 if (do_ftrace_mod_code(ip, &code)) 713 new = ftrace_jmp_replace(ip, (unsigned long)func);
694 return -EPERM;
695 714
696 return 0; 715 return update_ftrace_func(ip, new);
697} 716}
698 717
699int ftrace_enable_ftrace_graph_caller(void) 718int ftrace_enable_ftrace_graph_caller(void)
700{ 719{
701 unsigned long ip = (unsigned long)(&ftrace_graph_call); 720 unsigned long ip = (unsigned long)(&ftrace_graph_call);
702 int old_offset, new_offset;
703 721
704 old_offset = (unsigned long)(&ftrace_stub) - (ip + MCOUNT_INSN_SIZE); 722 return ftrace_mod_jmp(ip, &ftrace_graph_caller);
705 new_offset = (unsigned long)(&ftrace_graph_caller) - (ip + MCOUNT_INSN_SIZE);
706
707 return ftrace_mod_jmp(ip, old_offset, new_offset);
708} 723}
709 724
710int ftrace_disable_ftrace_graph_caller(void) 725int ftrace_disable_ftrace_graph_caller(void)
711{ 726{
712 unsigned long ip = (unsigned long)(&ftrace_graph_call); 727 unsigned long ip = (unsigned long)(&ftrace_graph_call);
713 int old_offset, new_offset;
714
715 old_offset = (unsigned long)(&ftrace_graph_caller) - (ip + MCOUNT_INSN_SIZE);
716 new_offset = (unsigned long)(&ftrace_stub) - (ip + MCOUNT_INSN_SIZE);
717 728
718 return ftrace_mod_jmp(ip, old_offset, new_offset); 729 return ftrace_mod_jmp(ip, &ftrace_stub);
719} 730}
720 731
721#endif /* !CONFIG_DYNAMIC_FTRACE */ 732#endif /* !CONFIG_DYNAMIC_FTRACE */
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 81ba27679f18..f36bd42d6f0c 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -544,6 +544,10 @@ ENDPROC(early_idt_handlers)
544 /* This is global to keep gas from relaxing the jumps */ 544 /* This is global to keep gas from relaxing the jumps */
545ENTRY(early_idt_handler) 545ENTRY(early_idt_handler)
546 cld 546 cld
547
548 cmpl $2,(%esp) # X86_TRAP_NMI
549 je is_nmi # Ignore NMI
550
547 cmpl $2,%ss:early_recursion_flag 551 cmpl $2,%ss:early_recursion_flag
548 je hlt_loop 552 je hlt_loop
549 incl %ss:early_recursion_flag 553 incl %ss:early_recursion_flag
@@ -594,8 +598,9 @@ ex_entry:
594 pop %edx 598 pop %edx
595 pop %ecx 599 pop %ecx
596 pop %eax 600 pop %eax
597 addl $8,%esp /* drop vector number and error code */
598 decl %ss:early_recursion_flag 601 decl %ss:early_recursion_flag
602is_nmi:
603 addl $8,%esp /* drop vector number and error code */
599 iret 604 iret
600ENDPROC(early_idt_handler) 605ENDPROC(early_idt_handler)
601 606
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index e1aabdb314c8..a468c0a65c42 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -343,6 +343,9 @@ early_idt_handlers:
343ENTRY(early_idt_handler) 343ENTRY(early_idt_handler)
344 cld 344 cld
345 345
346 cmpl $2,(%rsp) # X86_TRAP_NMI
347 je is_nmi # Ignore NMI
348
346 cmpl $2,early_recursion_flag(%rip) 349 cmpl $2,early_recursion_flag(%rip)
347 jz 1f 350 jz 1f
348 incl early_recursion_flag(%rip) 351 incl early_recursion_flag(%rip)
@@ -405,8 +408,9 @@ ENTRY(early_idt_handler)
405 popq %rdx 408 popq %rdx
406 popq %rcx 409 popq %rcx
407 popq %rax 410 popq %rax
408 addq $16,%rsp # drop vector number and error code
409 decl early_recursion_flag(%rip) 411 decl early_recursion_flag(%rip)
412is_nmi:
413 addq $16,%rsp # drop vector number and error code
410 INTERRUPT_RETURN 414 INTERRUPT_RETURN
411ENDPROC(early_idt_handler) 415ENDPROC(early_idt_handler)
412 416
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index e8368c6dd2a2..d5dd80814419 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -86,10 +86,19 @@ EXPORT_SYMBOL(__kernel_fpu_begin);
86 86
87void __kernel_fpu_end(void) 87void __kernel_fpu_end(void)
88{ 88{
89 if (use_eager_fpu()) 89 if (use_eager_fpu()) {
90 math_state_restore(); 90 /*
91 else 91 * For eager fpu, most the time, tsk_used_math() is true.
92 * Restore the user math as we are done with the kernel usage.
93 * At few instances during thread exit, signal handling etc,
94 * tsk_used_math() is false. Those few places will take proper
95 * actions, so we don't need to restore the math here.
96 */
97 if (likely(tsk_used_math(current)))
98 math_state_restore();
99 } else {
92 stts(); 100 stts();
101 }
93} 102}
94EXPORT_SYMBOL(__kernel_fpu_end); 103EXPORT_SYMBOL(__kernel_fpu_end);
95 104
diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
index dbb60878b744..d99f31d9a750 100644
--- a/arch/x86/kernel/irq.c
+++ b/arch/x86/kernel/irq.c
@@ -266,6 +266,14 @@ __visible void smp_trace_x86_platform_ipi(struct pt_regs *regs)
266EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq); 266EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);
267 267
268#ifdef CONFIG_HOTPLUG_CPU 268#ifdef CONFIG_HOTPLUG_CPU
269
270/* These two declarations are only used in check_irq_vectors_for_cpu_disable()
271 * below, which is protected by stop_machine(). Putting them on the stack
272 * results in a stack frame overflow. Dynamically allocating could result in a
273 * failure so declare these two cpumasks as global.
274 */
275static struct cpumask affinity_new, online_new;
276
269/* 277/*
270 * This cpu is going to be removed and its vectors migrated to the remaining 278 * This cpu is going to be removed and its vectors migrated to the remaining
271 * online cpus. Check to see if there are enough vectors in the remaining cpus. 279 * online cpus. Check to see if there are enough vectors in the remaining cpus.
@@ -277,7 +285,6 @@ int check_irq_vectors_for_cpu_disable(void)
277 unsigned int this_cpu, vector, this_count, count; 285 unsigned int this_cpu, vector, this_count, count;
278 struct irq_desc *desc; 286 struct irq_desc *desc;
279 struct irq_data *data; 287 struct irq_data *data;
280 struct cpumask affinity_new, online_new;
281 288
282 this_cpu = smp_processor_id(); 289 this_cpu = smp_processor_id();
283 cpumask_copy(&online_new, cpu_online_mask); 290 cpumask_copy(&online_new, cpu_online_mask);
diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c
index 4eabc160696f..679cef0791cd 100644
--- a/arch/x86/kernel/machine_kexec_64.c
+++ b/arch/x86/kernel/machine_kexec_64.c
@@ -279,5 +279,7 @@ void arch_crash_save_vmcoreinfo(void)
279 VMCOREINFO_SYMBOL(node_data); 279 VMCOREINFO_SYMBOL(node_data);
280 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES); 280 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
281#endif 281#endif
282 vmcoreinfo_append_str("KERNELOFFSET=%lx\n",
283 (unsigned long)&_text - __START_KERNEL);
282} 284}
283 285
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index 18be189368bb..e69f9882bf95 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -28,6 +28,7 @@
28#include <linux/mm.h> 28#include <linux/mm.h>
29#include <linux/gfp.h> 29#include <linux/gfp.h>
30#include <linux/jump_label.h> 30#include <linux/jump_label.h>
31#include <linux/random.h>
31 32
32#include <asm/page.h> 33#include <asm/page.h>
33#include <asm/pgtable.h> 34#include <asm/pgtable.h>
@@ -43,13 +44,52 @@ do { \
43} while (0) 44} while (0)
44#endif 45#endif
45 46
47#ifdef CONFIG_RANDOMIZE_BASE
48static unsigned long module_load_offset;
49static int randomize_modules = 1;
50
51/* Mutex protects the module_load_offset. */
52static DEFINE_MUTEX(module_kaslr_mutex);
53
54static int __init parse_nokaslr(char *p)
55{
56 randomize_modules = 0;
57 return 0;
58}
59early_param("nokaslr", parse_nokaslr);
60
61static unsigned long int get_module_load_offset(void)
62{
63 if (randomize_modules) {
64 mutex_lock(&module_kaslr_mutex);
65 /*
66 * Calculate the module_load_offset the first time this
67 * code is called. Once calculated it stays the same until
68 * reboot.
69 */
70 if (module_load_offset == 0)
71 module_load_offset =
72 (get_random_int() % 1024 + 1) * PAGE_SIZE;
73 mutex_unlock(&module_kaslr_mutex);
74 }
75 return module_load_offset;
76}
77#else
78static unsigned long int get_module_load_offset(void)
79{
80 return 0;
81}
82#endif
83
46void *module_alloc(unsigned long size) 84void *module_alloc(unsigned long size)
47{ 85{
48 if (PAGE_ALIGN(size) > MODULES_LEN) 86 if (PAGE_ALIGN(size) > MODULES_LEN)
49 return NULL; 87 return NULL;
50 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, 88 return __vmalloc_node_range(size, 1,
51 GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC, 89 MODULES_VADDR + get_module_load_offset(),
52 NUMA_NO_NODE, __builtin_return_address(0)); 90 MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
91 PAGE_KERNEL_EXEC, NUMA_NO_NODE,
92 __builtin_return_address(0));
53} 93}
54 94
55#ifdef CONFIG_X86_32 95#ifdef CONFIG_X86_32
diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index 6fcb49ce50a1..b4872b999a71 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -87,6 +87,7 @@ __setup("unknown_nmi_panic", setup_unknown_nmi_panic);
87#define nmi_to_desc(type) (&nmi_desc[type]) 87#define nmi_to_desc(type) (&nmi_desc[type])
88 88
89static u64 nmi_longest_ns = 1 * NSEC_PER_MSEC; 89static u64 nmi_longest_ns = 1 * NSEC_PER_MSEC;
90
90static int __init nmi_warning_debugfs(void) 91static int __init nmi_warning_debugfs(void)
91{ 92{
92 debugfs_create_u64("nmi_longest_ns", 0644, 93 debugfs_create_u64("nmi_longest_ns", 0644,
@@ -95,6 +96,20 @@ static int __init nmi_warning_debugfs(void)
95} 96}
96fs_initcall(nmi_warning_debugfs); 97fs_initcall(nmi_warning_debugfs);
97 98
99static void nmi_max_handler(struct irq_work *w)
100{
101 struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
102 int remainder_ns, decimal_msecs;
103 u64 whole_msecs = ACCESS_ONCE(a->max_duration);
104
105 remainder_ns = do_div(whole_msecs, (1000 * 1000));
106 decimal_msecs = remainder_ns / 1000;
107
108 printk_ratelimited(KERN_INFO
109 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
110 a->handler, whole_msecs, decimal_msecs);
111}
112
98static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b) 113static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
99{ 114{
100 struct nmi_desc *desc = nmi_to_desc(type); 115 struct nmi_desc *desc = nmi_to_desc(type);
@@ -110,26 +125,20 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
110 * to handle those situations. 125 * to handle those situations.
111 */ 126 */
112 list_for_each_entry_rcu(a, &desc->head, list) { 127 list_for_each_entry_rcu(a, &desc->head, list) {
113 u64 before, delta, whole_msecs; 128 int thishandled;
114 int remainder_ns, decimal_msecs, thishandled; 129 u64 delta;
115 130
116 before = sched_clock(); 131 delta = sched_clock();
117 thishandled = a->handler(type, regs); 132 thishandled = a->handler(type, regs);
118 handled += thishandled; 133 handled += thishandled;
119 delta = sched_clock() - before; 134 delta = sched_clock() - delta;
120 trace_nmi_handler(a->handler, (int)delta, thishandled); 135 trace_nmi_handler(a->handler, (int)delta, thishandled);
121 136
122 if (delta < nmi_longest_ns) 137 if (delta < nmi_longest_ns || delta < a->max_duration)
123 continue; 138 continue;
124 139
125 nmi_longest_ns = delta; 140 a->max_duration = delta;
126 whole_msecs = delta; 141 irq_work_queue(&a->irq_work);
127 remainder_ns = do_div(whole_msecs, (1000 * 1000));
128 decimal_msecs = remainder_ns / 1000;
129 printk_ratelimited(KERN_INFO
130 "INFO: NMI handler (%ps) took too long to run: "
131 "%lld.%03d msecs\n", a->handler, whole_msecs,
132 decimal_msecs);
133 } 142 }
134 143
135 rcu_read_unlock(); 144 rcu_read_unlock();
@@ -146,6 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
146 if (!action->handler) 155 if (!action->handler)
147 return -EINVAL; 156 return -EINVAL;
148 157
158 init_irq_work(&action->irq_work, nmi_max_handler);
159
149 spin_lock_irqsave(&desc->lock, flags); 160 spin_lock_irqsave(&desc->lock, flags);
150 161
151 /* 162 /*
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 872079a67e4d..f7d0672481fd 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -100,8 +100,10 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size,
100 flag |= __GFP_ZERO; 100 flag |= __GFP_ZERO;
101again: 101again:
102 page = NULL; 102 page = NULL;
103 if (!(flag & GFP_ATOMIC)) 103 /* CMA can be used only in the context which permits sleeping */
104 if (flag & __GFP_WAIT)
104 page = dma_alloc_from_contiguous(dev, count, get_order(size)); 105 page = dma_alloc_from_contiguous(dev, count, get_order(size));
106 /* fallback */
105 if (!page) 107 if (!page)
106 page = alloc_pages_node(dev_to_node(dev), flag, get_order(size)); 108 page = alloc_pages_node(dev_to_node(dev), flag, get_order(size));
107 if (!page) 109 if (!page)
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 3fb8d95ab8b5..4505e2a950d8 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -298,10 +298,7 @@ void arch_cpu_idle_dead(void)
298 */ 298 */
299void arch_cpu_idle(void) 299void arch_cpu_idle(void)
300{ 300{
301 if (cpuidle_idle_call()) 301 x86_idle();
302 x86_idle();
303 else
304 local_irq_enable();
305} 302}
306 303
307/* 304/*
diff --git a/arch/x86/kernel/quirks.c b/arch/x86/kernel/quirks.c
index 04ee1e2e4c02..ff898bbf579d 100644
--- a/arch/x86/kernel/quirks.c
+++ b/arch/x86/kernel/quirks.c
@@ -529,7 +529,7 @@ static void quirk_amd_nb_node(struct pci_dev *dev)
529 return; 529 return;
530 530
531 pci_read_config_dword(nb_ht, 0x60, &val); 531 pci_read_config_dword(nb_ht, 0x60, &val);
532 node = val & 7; 532 node = pcibus_to_node(dev->bus) | (val & 7);
533 /* 533 /*
534 * Some hardware may return an invalid node ID, 534 * Some hardware may return an invalid node ID,
535 * so check it first: 535 * so check it first:
@@ -571,3 +571,40 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F5,
571 quirk_amd_nb_node); 571 quirk_amd_nb_node);
572 572
573#endif 573#endif
574
575#ifdef CONFIG_PCI
576/*
577 * Processor does not ensure DRAM scrub read/write sequence
578 * is atomic wrt accesses to CC6 save state area. Therefore
579 * if a concurrent scrub read/write access is to same address
580 * the entry may appear as if it is not written. This quirk
581 * applies to Fam16h models 00h-0Fh
582 *
583 * See "Revision Guide" for AMD F16h models 00h-0fh,
584 * document 51810 rev. 3.04, Nov 2013
585 */
586static void amd_disable_seq_and_redirect_scrub(struct pci_dev *dev)
587{
588 u32 val;
589
590 /*
591 * Suggested workaround:
592 * set D18F3x58[4:0] = 00h and set D18F3x5C[0] = 0b
593 */
594 pci_read_config_dword(dev, 0x58, &val);
595 if (val & 0x1F) {
596 val &= ~(0x1F);
597 pci_write_config_dword(dev, 0x58, val);
598 }
599
600 pci_read_config_dword(dev, 0x5C, &val);
601 if (val & BIT(0)) {
602 val &= ~BIT(0);
603 pci_write_config_dword(dev, 0x5c, val);
604 }
605}
606
607DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3,
608 amd_disable_seq_and_redirect_scrub);
609
610#endif
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 06853e670354..fa511acff7e6 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -926,11 +926,11 @@ void __init setup_arch(char **cmdline_p)
926#ifdef CONFIG_EFI 926#ifdef CONFIG_EFI
927 if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 927 if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
928 "EL32", 4)) { 928 "EL32", 4)) {
929 set_bit(EFI_BOOT, &x86_efi_facility); 929 set_bit(EFI_BOOT, &efi.flags);
930 } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 930 } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
931 "EL64", 4)) { 931 "EL64", 4)) {
932 set_bit(EFI_BOOT, &x86_efi_facility); 932 set_bit(EFI_BOOT, &efi.flags);
933 set_bit(EFI_64BIT, &x86_efi_facility); 933 set_bit(EFI_64BIT, &efi.flags);
934 } 934 }
935 935
936 if (efi_enabled(EFI_BOOT)) 936 if (efi_enabled(EFI_BOOT))
@@ -1239,14 +1239,8 @@ void __init setup_arch(char **cmdline_p)
1239 register_refined_jiffies(CLOCK_TICK_RATE); 1239 register_refined_jiffies(CLOCK_TICK_RATE);
1240 1240
1241#ifdef CONFIG_EFI 1241#ifdef CONFIG_EFI
1242 /* Once setup is done above, unmap the EFI memory map on 1242 if (efi_enabled(EFI_BOOT))
1243 * mismatched firmware/kernel archtectures since there is no 1243 efi_apply_memmap_quirks();
1244 * support for runtime services.
1245 */
1246 if (efi_enabled(EFI_BOOT) && !efi_is_native()) {
1247 pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n");
1248 efi_unmap_memmap();
1249 }
1250#endif 1244#endif
1251} 1245}
1252 1246
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index a32da804252e..60179ec39d4c 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -122,8 +122,9 @@ static void smp_callin(void)
122 * Since CPU0 is not wakened up by INIT, it doesn't wait for the IPI. 122 * Since CPU0 is not wakened up by INIT, it doesn't wait for the IPI.
123 */ 123 */
124 cpuid = smp_processor_id(); 124 cpuid = smp_processor_id();
125 if (apic->wait_for_init_deassert && cpuid != 0) 125 if (apic->wait_for_init_deassert && cpuid)
126 apic->wait_for_init_deassert(&init_deasserted); 126 while (!atomic_read(&init_deasserted))
127 cpu_relax();
127 128
128 /* 129 /*
129 * (This works even if the APIC is not enabled.) 130 * (This works even if the APIC is not enabled.)
@@ -701,11 +702,15 @@ wakeup_cpu_via_init_nmi(int cpu, unsigned long start_ip, int apicid,
701 int id; 702 int id;
702 int boot_error; 703 int boot_error;
703 704
705 preempt_disable();
706
704 /* 707 /*
705 * Wake up AP by INIT, INIT, STARTUP sequence. 708 * Wake up AP by INIT, INIT, STARTUP sequence.
706 */ 709 */
707 if (cpu) 710 if (cpu) {
708 return wakeup_secondary_cpu_via_init(apicid, start_ip); 711 boot_error = wakeup_secondary_cpu_via_init(apicid, start_ip);
712 goto out;
713 }
709 714
710 /* 715 /*
711 * Wake up BSP by nmi. 716 * Wake up BSP by nmi.
@@ -725,6 +730,9 @@ wakeup_cpu_via_init_nmi(int cpu, unsigned long start_ip, int apicid,
725 boot_error = wakeup_secondary_cpu_via_nmi(id, start_ip); 730 boot_error = wakeup_secondary_cpu_via_nmi(id, start_ip);
726 } 731 }
727 732
733out:
734 preempt_enable();
735
728 return boot_error; 736 return boot_error;
729} 737}
730 738
diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
index 24d3c91e9812..6ec91c00d84d 100644
--- a/arch/x86/kernel/time.c
+++ b/arch/x86/kernel/time.c
@@ -23,7 +23,7 @@
23#include <asm/time.h> 23#include <asm/time.h>
24 24
25#ifdef CONFIG_X86_64 25#ifdef CONFIG_X86_64
26DEFINE_VVAR(volatile unsigned long, jiffies) = INITIAL_JIFFIES; 26__visible DEFINE_VVAR(volatile unsigned long, jiffies) = INITIAL_JIFFIES;
27#endif 27#endif
28 28
29unsigned long profile_pc(struct pt_regs *regs) 29unsigned long profile_pc(struct pt_regs *regs)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 19e5adb49a27..cfbe99f88830 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -209,7 +209,7 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
209 * dance when its actually needed. 209 * dance when its actually needed.
210 */ 210 */
211 211
212 preempt_disable(); 212 preempt_disable_notrace();
213 data = this_cpu_read(cyc2ns.head); 213 data = this_cpu_read(cyc2ns.head);
214 tail = this_cpu_read(cyc2ns.tail); 214 tail = this_cpu_read(cyc2ns.tail);
215 215
@@ -229,7 +229,7 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
229 if (!--data->__count) 229 if (!--data->__count)
230 this_cpu_write(cyc2ns.tail, data); 230 this_cpu_write(cyc2ns.tail, data);
231 } 231 }
232 preempt_enable(); 232 preempt_enable_notrace();
233 233
234 return ns; 234 return ns;
235} 235}
@@ -653,13 +653,10 @@ unsigned long native_calibrate_tsc(void)
653 653
654 /* Calibrate TSC using MSR for Intel Atom SoCs */ 654 /* Calibrate TSC using MSR for Intel Atom SoCs */
655 local_irq_save(flags); 655 local_irq_save(flags);
656 i = try_msr_calibrate_tsc(&fast_calibrate); 656 fast_calibrate = try_msr_calibrate_tsc();
657 local_irq_restore(flags); 657 local_irq_restore(flags);
658 if (i >= 0) { 658 if (fast_calibrate)
659 if (i == 0)
660 pr_warn("Fast TSC calibration using MSR failed\n");
661 return fast_calibrate; 659 return fast_calibrate;
662 }
663 660
664 local_irq_save(flags); 661 local_irq_save(flags);
665 fast_calibrate = quick_pit_calibrate(); 662 fast_calibrate = quick_pit_calibrate();
diff --git a/arch/x86/kernel/tsc_msr.c b/arch/x86/kernel/tsc_msr.c
index 8b5434f4389f..92ae6acac8a7 100644
--- a/arch/x86/kernel/tsc_msr.c
+++ b/arch/x86/kernel/tsc_msr.c
@@ -53,7 +53,7 @@ static struct freq_desc freq_desc_tables[] = {
53 /* TNG */ 53 /* TNG */
54 { 6, 0x4a, 1, { 0, FREQ_100, FREQ_133, 0, 0, 0, 0, 0 } }, 54 { 6, 0x4a, 1, { 0, FREQ_100, FREQ_133, 0, 0, 0, 0, 0 } },
55 /* VLV2 */ 55 /* VLV2 */
56 { 6, 0x37, 1, { 0, FREQ_100, FREQ_133, FREQ_166, 0, 0, 0, 0 } }, 56 { 6, 0x37, 1, { FREQ_83, FREQ_100, FREQ_133, FREQ_166, 0, 0, 0, 0 } },
57 /* ANN */ 57 /* ANN */
58 { 6, 0x5a, 1, { FREQ_83, FREQ_100, FREQ_133, FREQ_100, 0, 0, 0, 0 } }, 58 { 6, 0x5a, 1, { FREQ_83, FREQ_100, FREQ_133, FREQ_100, 0, 0, 0, 0 } },
59}; 59};
@@ -77,21 +77,18 @@ static int match_cpu(u8 family, u8 model)
77 77
78/* 78/*
79 * Do MSR calibration only for known/supported CPUs. 79 * Do MSR calibration only for known/supported CPUs.
80 * Return values: 80 *
81 * -1: CPU is unknown/unsupported for MSR based calibration 81 * Returns the calibration value or 0 if MSR calibration failed.
82 * 0: CPU is known/supported, but calibration failed
83 * 1: CPU is known/supported, and calibration succeeded
84 */ 82 */
85int try_msr_calibrate_tsc(unsigned long *fast_calibrate) 83unsigned long try_msr_calibrate_tsc(void)
86{ 84{
87 int cpu_index;
88 u32 lo, hi, ratio, freq_id, freq; 85 u32 lo, hi, ratio, freq_id, freq;
86 unsigned long res;
87 int cpu_index;
89 88
90 cpu_index = match_cpu(boot_cpu_data.x86, boot_cpu_data.x86_model); 89 cpu_index = match_cpu(boot_cpu_data.x86, boot_cpu_data.x86_model);
91 if (cpu_index < 0) 90 if (cpu_index < 0)
92 return -1; 91 return 0;
93
94 *fast_calibrate = 0;
95 92
96 if (freq_desc_tables[cpu_index].msr_plat) { 93 if (freq_desc_tables[cpu_index].msr_plat) {
97 rdmsr(MSR_PLATFORM_INFO, lo, hi); 94 rdmsr(MSR_PLATFORM_INFO, lo, hi);
@@ -103,7 +100,7 @@ int try_msr_calibrate_tsc(unsigned long *fast_calibrate)
103 pr_info("Maximum core-clock to bus-clock ratio: 0x%x\n", ratio); 100 pr_info("Maximum core-clock to bus-clock ratio: 0x%x\n", ratio);
104 101
105 if (!ratio) 102 if (!ratio)
106 return 0; 103 goto fail;
107 104
108 /* Get FSB FREQ ID */ 105 /* Get FSB FREQ ID */
109 rdmsr(MSR_FSB_FREQ, lo, hi); 106 rdmsr(MSR_FSB_FREQ, lo, hi);
@@ -112,16 +109,19 @@ int try_msr_calibrate_tsc(unsigned long *fast_calibrate)
112 pr_info("Resolved frequency ID: %u, frequency: %u KHz\n", 109 pr_info("Resolved frequency ID: %u, frequency: %u KHz\n",
113 freq_id, freq); 110 freq_id, freq);
114 if (!freq) 111 if (!freq)
115 return 0; 112 goto fail;
116 113
117 /* TSC frequency = maximum resolved freq * maximum resolved bus ratio */ 114 /* TSC frequency = maximum resolved freq * maximum resolved bus ratio */
118 *fast_calibrate = freq * ratio; 115 res = freq * ratio;
119 pr_info("TSC runs at %lu KHz\n", *fast_calibrate); 116 pr_info("TSC runs at %lu KHz\n", res);
120 117
121#ifdef CONFIG_X86_LOCAL_APIC 118#ifdef CONFIG_X86_LOCAL_APIC
122 lapic_timer_frequency = (freq * 1000) / HZ; 119 lapic_timer_frequency = (freq * 1000) / HZ;
123 pr_info("lapic_timer_frequency = %d\n", lapic_timer_frequency); 120 pr_info("lapic_timer_frequency = %d\n", lapic_timer_frequency);
124#endif 121#endif
122 return res;
125 123
126 return 1; 124fail:
125 pr_warn("Fast TSC calibration using MSR failed\n");
126 return 0;
127} 127}
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index e50425d0f5f7..9b531351a587 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2672,6 +2672,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
2672 break; 2672 break;
2673 } 2673 }
2674 2674
2675 drop_large_spte(vcpu, iterator.sptep);
2675 if (!is_shadow_present_pte(*iterator.sptep)) { 2676 if (!is_shadow_present_pte(*iterator.sptep)) {
2676 u64 base_addr = iterator.addr; 2677 u64 base_addr = iterator.addr;
2677 2678
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index e81df8fce027..2de1bc09a8d4 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -3002,10 +3002,8 @@ static int cr8_write_interception(struct vcpu_svm *svm)
3002 u8 cr8_prev = kvm_get_cr8(&svm->vcpu); 3002 u8 cr8_prev = kvm_get_cr8(&svm->vcpu);
3003 /* instruction emulation calls kvm_set_cr8() */ 3003 /* instruction emulation calls kvm_set_cr8() */
3004 r = cr_interception(svm); 3004 r = cr_interception(svm);
3005 if (irqchip_in_kernel(svm->vcpu.kvm)) { 3005 if (irqchip_in_kernel(svm->vcpu.kvm))
3006 clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
3007 return r; 3006 return r;
3008 }
3009 if (cr8_prev <= kvm_get_cr8(&svm->vcpu)) 3007 if (cr8_prev <= kvm_get_cr8(&svm->vcpu))
3010 return r; 3008 return r;
3011 kvm_run->exit_reason = KVM_EXIT_SET_TPR; 3009 kvm_run->exit_reason = KVM_EXIT_SET_TPR;
@@ -3567,6 +3565,8 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr)
3567 if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK)) 3565 if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK))
3568 return; 3566 return;
3569 3567
3568 clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
3569
3570 if (irr == -1) 3570 if (irr == -1)
3571 return; 3571 return;
3572 3572
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index a06f101ef64b..392752834751 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6688,7 +6688,7 @@ static bool nested_vmx_exit_handled(struct kvm_vcpu *vcpu)
6688 else if (is_page_fault(intr_info)) 6688 else if (is_page_fault(intr_info))
6689 return enable_ept; 6689 return enable_ept;
6690 else if (is_no_device(intr_info) && 6690 else if (is_no_device(intr_info) &&
6691 !(nested_read_cr0(vmcs12) & X86_CR0_TS)) 6691 !(vmcs12->guest_cr0 & X86_CR0_TS))
6692 return 0; 6692 return 0;
6693 return vmcs12->exception_bitmap & 6693 return vmcs12->exception_bitmap &
6694 (1u << (intr_info & INTR_INFO_VECTOR_MASK)); 6694 (1u << (intr_info & INTR_INFO_VECTOR_MASK));
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 39c28f09dfd5..2b8578432d5b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6186,7 +6186,7 @@ static int complete_emulated_mmio(struct kvm_vcpu *vcpu)
6186 frag->len -= len; 6186 frag->len -= len;
6187 } 6187 }
6188 6188
6189 if (vcpu->mmio_cur_fragment == vcpu->mmio_nr_fragments) { 6189 if (vcpu->mmio_cur_fragment >= vcpu->mmio_nr_fragments) {
6190 vcpu->mmio_needed = 0; 6190 vcpu->mmio_needed = 0;
6191 6191
6192 /* FIXME: return into emulator if single-stepping. */ 6192 /* FIXME: return into emulator if single-stepping. */
diff --git a/arch/x86/lib/hash.c b/arch/x86/lib/hash.c
index 3056702e81fb..ff4fa51a5b1f 100644
--- a/arch/x86/lib/hash.c
+++ b/arch/x86/lib/hash.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include <linux/hash.h> 34#include <linux/hash.h>
35#include <linux/init.h>
35 36
36#include <asm/processor.h> 37#include <asm/processor.h>
37#include <asm/cpufeature.h> 38#include <asm/cpufeature.h>
@@ -39,7 +40,11 @@
39 40
40static inline u32 crc32_u32(u32 crc, u32 val) 41static inline u32 crc32_u32(u32 crc, u32 val)
41{ 42{
43#ifdef CONFIG_AS_CRC32
42 asm ("crc32l %1,%0\n" : "+r" (crc) : "rm" (val)); 44 asm ("crc32l %1,%0\n" : "+r" (crc) : "rm" (val));
45#else
46 asm (".byte 0xf2, 0x0f, 0x38, 0xf1, 0xc1" : "+a" (crc) : "c" (val));
47#endif
43 return crc; 48 return crc;
44} 49}
45 50
@@ -49,19 +54,18 @@ static u32 intel_crc4_2_hash(const void *data, u32 len, u32 seed)
49 u32 i, tmp = 0; 54 u32 i, tmp = 0;
50 55
51 for (i = 0; i < len / 4; i++) 56 for (i = 0; i < len / 4; i++)
52 seed = crc32_u32(*p32++, seed); 57 seed = crc32_u32(seed, *p32++);
53 58
54 switch (3 - (len & 0x03)) { 59 switch (len & 3) {
55 case 0: 60 case 3:
56 tmp |= *((const u8 *) p32 + 2) << 16; 61 tmp |= *((const u8 *) p32 + 2) << 16;
57 /* fallthrough */ 62 /* fallthrough */
58 case 1: 63 case 2:
59 tmp |= *((const u8 *) p32 + 1) << 8; 64 tmp |= *((const u8 *) p32 + 1) << 8;
60 /* fallthrough */ 65 /* fallthrough */
61 case 2: 66 case 1:
62 tmp |= *((const u8 *) p32); 67 tmp |= *((const u8 *) p32);
63 seed = crc32_u32(tmp, seed); 68 seed = crc32_u32(seed, tmp);
64 default:
65 break; 69 break;
66 } 70 }
67 71
@@ -74,12 +78,12 @@ static u32 intel_crc4_2_hash2(const u32 *data, u32 len, u32 seed)
74 u32 i; 78 u32 i;
75 79
76 for (i = 0; i < len; i++) 80 for (i = 0; i < len; i++)
77 seed = crc32_u32(*p32++, seed); 81 seed = crc32_u32(seed, *p32++);
78 82
79 return seed; 83 return seed;
80} 84}
81 85
82void setup_arch_fast_hash(struct fast_hash_ops *ops) 86void __init setup_arch_fast_hash(struct fast_hash_ops *ops)
83{ 87{
84 if (cpu_has_xmm4_2) { 88 if (cpu_has_xmm4_2) {
85 ops->hash = intel_crc4_2_hash; 89 ops->hash = intel_crc4_2_hash;
diff --git a/arch/x86/lib/memcpy_32.c b/arch/x86/lib/memcpy_32.c
index e78761d6b7f8..a404b4b75533 100644
--- a/arch/x86/lib/memcpy_32.c
+++ b/arch/x86/lib/memcpy_32.c
@@ -4,7 +4,7 @@
4#undef memcpy 4#undef memcpy
5#undef memset 5#undef memset
6 6
7void *memcpy(void *to, const void *from, size_t n) 7__visible void *memcpy(void *to, const void *from, size_t n)
8{ 8{
9#ifdef CONFIG_X86_USE_3DNOW 9#ifdef CONFIG_X86_USE_3DNOW
10 return __memcpy3d(to, from, n); 10 return __memcpy3d(to, from, n);
@@ -14,13 +14,13 @@ void *memcpy(void *to, const void *from, size_t n)
14} 14}
15EXPORT_SYMBOL(memcpy); 15EXPORT_SYMBOL(memcpy);
16 16
17void *memset(void *s, int c, size_t count) 17__visible void *memset(void *s, int c, size_t count)
18{ 18{
19 return __memset(s, c, count); 19 return __memset(s, c, count);
20} 20}
21EXPORT_SYMBOL(memset); 21EXPORT_SYMBOL(memset);
22 22
23void *memmove(void *dest, const void *src, size_t n) 23__visible void *memmove(void *dest, const void *src, size_t n)
24{ 24{
25 int d0,d1,d2,d3,d4,d5; 25 int d0,d1,d2,d3,d4,d5;
26 char *ret = dest; 26 char *ret = dest;
diff --git a/arch/x86/lib/msr.c b/arch/x86/lib/msr.c
index 8f8eebdca7d4..db9db446b71a 100644
--- a/arch/x86/lib/msr.c
+++ b/arch/x86/lib/msr.c
@@ -8,7 +8,7 @@ struct msr *msrs_alloc(void)
8 8
9 msrs = alloc_percpu(struct msr); 9 msrs = alloc_percpu(struct msr);
10 if (!msrs) { 10 if (!msrs) {
11 pr_warning("%s: error allocating msrs\n", __func__); 11 pr_warn("%s: error allocating msrs\n", __func__);
12 return NULL; 12 return NULL;
13 } 13 }
14 14
@@ -21,3 +21,90 @@ void msrs_free(struct msr *msrs)
21 free_percpu(msrs); 21 free_percpu(msrs);
22} 22}
23EXPORT_SYMBOL(msrs_free); 23EXPORT_SYMBOL(msrs_free);
24
25/**
26 * Read an MSR with error handling
27 *
28 * @msr: MSR to read
29 * @m: value to read into
30 *
31 * It returns read data only on success, otherwise it doesn't change the output
32 * argument @m.
33 *
34 */
35int msr_read(u32 msr, struct msr *m)
36{
37 int err;
38 u64 val;
39
40 err = rdmsrl_safe(msr, &val);
41 if (!err)
42 m->q = val;
43
44 return err;
45}
46
47/**
48 * Write an MSR with error handling
49 *
50 * @msr: MSR to write
51 * @m: value to write
52 */
53int msr_write(u32 msr, struct msr *m)
54{
55 return wrmsrl_safe(msr, m->q);
56}
57
58static inline int __flip_bit(u32 msr, u8 bit, bool set)
59{
60 struct msr m, m1;
61 int err = -EINVAL;
62
63 if (bit > 63)
64 return err;
65
66 err = msr_read(msr, &m);
67 if (err)
68 return err;
69
70 m1 = m;
71 if (set)
72 m1.q |= BIT_64(bit);
73 else
74 m1.q &= ~BIT_64(bit);
75
76 if (m1.q == m.q)
77 return 0;
78
79 err = msr_write(msr, &m);
80 if (err)
81 return err;
82
83 return 1;
84}
85
86/**
87 * Set @bit in a MSR @msr.
88 *
89 * Retval:
90 * < 0: An error was encountered.
91 * = 0: Bit was already set.
92 * > 0: Hardware accepted the MSR write.
93 */
94int msr_set_bit(u32 msr, u8 bit)
95{
96 return __flip_bit(msr, bit, true);
97}
98
99/**
100 * Clear @bit in a MSR @msr.
101 *
102 * Retval:
103 * < 0: An error was encountered.
104 * = 0: Bit was already cleared.
105 * > 0: Hardware accepted the MSR write.
106 */
107int msr_clear_bit(u32 msr, u8 bit)
108{
109 return __flip_bit(msr, bit, false);
110}
diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
index 0002a3a33081..20621d753d5f 100644
--- a/arch/x86/mm/dump_pagetables.c
+++ b/arch/x86/mm/dump_pagetables.c
@@ -30,6 +30,7 @@ struct pg_state {
30 unsigned long start_address; 30 unsigned long start_address;
31 unsigned long current_address; 31 unsigned long current_address;
32 const struct addr_marker *marker; 32 const struct addr_marker *marker;
33 bool to_dmesg;
33}; 34};
34 35
35struct addr_marker { 36struct addr_marker {
@@ -88,10 +89,28 @@ static struct addr_marker address_markers[] = {
88#define PUD_LEVEL_MULT (PTRS_PER_PMD * PMD_LEVEL_MULT) 89#define PUD_LEVEL_MULT (PTRS_PER_PMD * PMD_LEVEL_MULT)
89#define PGD_LEVEL_MULT (PTRS_PER_PUD * PUD_LEVEL_MULT) 90#define PGD_LEVEL_MULT (PTRS_PER_PUD * PUD_LEVEL_MULT)
90 91
92#define pt_dump_seq_printf(m, to_dmesg, fmt, args...) \
93({ \
94 if (to_dmesg) \
95 printk(KERN_INFO fmt, ##args); \
96 else \
97 if (m) \
98 seq_printf(m, fmt, ##args); \
99})
100
101#define pt_dump_cont_printf(m, to_dmesg, fmt, args...) \
102({ \
103 if (to_dmesg) \
104 printk(KERN_CONT fmt, ##args); \
105 else \
106 if (m) \
107 seq_printf(m, fmt, ##args); \
108})
109
91/* 110/*
92 * Print a readable form of a pgprot_t to the seq_file 111 * Print a readable form of a pgprot_t to the seq_file
93 */ 112 */
94static void printk_prot(struct seq_file *m, pgprot_t prot, int level) 113static void printk_prot(struct seq_file *m, pgprot_t prot, int level, bool dmsg)
95{ 114{
96 pgprotval_t pr = pgprot_val(prot); 115 pgprotval_t pr = pgprot_val(prot);
97 static const char * const level_name[] = 116 static const char * const level_name[] =
@@ -99,47 +118,47 @@ static void printk_prot(struct seq_file *m, pgprot_t prot, int level)
99 118
100 if (!pgprot_val(prot)) { 119 if (!pgprot_val(prot)) {
101 /* Not present */ 120 /* Not present */
102 seq_printf(m, " "); 121 pt_dump_cont_printf(m, dmsg, " ");
103 } else { 122 } else {
104 if (pr & _PAGE_USER) 123 if (pr & _PAGE_USER)
105 seq_printf(m, "USR "); 124 pt_dump_cont_printf(m, dmsg, "USR ");
106 else 125 else
107 seq_printf(m, " "); 126 pt_dump_cont_printf(m, dmsg, " ");
108 if (pr & _PAGE_RW) 127 if (pr & _PAGE_RW)
109 seq_printf(m, "RW "); 128 pt_dump_cont_printf(m, dmsg, "RW ");
110 else 129 else
111 seq_printf(m, "ro "); 130 pt_dump_cont_printf(m, dmsg, "ro ");
112 if (pr & _PAGE_PWT) 131 if (pr & _PAGE_PWT)
113 seq_printf(m, "PWT "); 132 pt_dump_cont_printf(m, dmsg, "PWT ");
114 else 133 else
115 seq_printf(m, " "); 134 pt_dump_cont_printf(m, dmsg, " ");
116 if (pr & _PAGE_PCD) 135 if (pr & _PAGE_PCD)
117 seq_printf(m, "PCD "); 136 pt_dump_cont_printf(m, dmsg, "PCD ");
118 else 137 else
119 seq_printf(m, " "); 138 pt_dump_cont_printf(m, dmsg, " ");
120 139
121 /* Bit 9 has a different meaning on level 3 vs 4 */ 140 /* Bit 9 has a different meaning on level 3 vs 4 */
122 if (level <= 3) { 141 if (level <= 3) {
123 if (pr & _PAGE_PSE) 142 if (pr & _PAGE_PSE)
124 seq_printf(m, "PSE "); 143 pt_dump_cont_printf(m, dmsg, "PSE ");
125 else 144 else
126 seq_printf(m, " "); 145 pt_dump_cont_printf(m, dmsg, " ");
127 } else { 146 } else {
128 if (pr & _PAGE_PAT) 147 if (pr & _PAGE_PAT)
129 seq_printf(m, "pat "); 148 pt_dump_cont_printf(m, dmsg, "pat ");
130 else 149 else
131 seq_printf(m, " "); 150 pt_dump_cont_printf(m, dmsg, " ");
132 } 151 }
133 if (pr & _PAGE_GLOBAL) 152 if (pr & _PAGE_GLOBAL)
134 seq_printf(m, "GLB "); 153 pt_dump_cont_printf(m, dmsg, "GLB ");
135 else 154 else
136 seq_printf(m, " "); 155 pt_dump_cont_printf(m, dmsg, " ");
137 if (pr & _PAGE_NX) 156 if (pr & _PAGE_NX)
138 seq_printf(m, "NX "); 157 pt_dump_cont_printf(m, dmsg, "NX ");
139 else 158 else
140 seq_printf(m, "x "); 159 pt_dump_cont_printf(m, dmsg, "x ");
141 } 160 }
142 seq_printf(m, "%s\n", level_name[level]); 161 pt_dump_cont_printf(m, dmsg, "%s\n", level_name[level]);
143} 162}
144 163
145/* 164/*
@@ -178,7 +197,8 @@ static void note_page(struct seq_file *m, struct pg_state *st,
178 st->current_prot = new_prot; 197 st->current_prot = new_prot;
179 st->level = level; 198 st->level = level;
180 st->marker = address_markers; 199 st->marker = address_markers;
181 seq_printf(m, "---[ %s ]---\n", st->marker->name); 200 pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n",
201 st->marker->name);
182 } else if (prot != cur || level != st->level || 202 } else if (prot != cur || level != st->level ||
183 st->current_address >= st->marker[1].start_address) { 203 st->current_address >= st->marker[1].start_address) {
184 const char *unit = units; 204 const char *unit = units;
@@ -188,17 +208,17 @@ static void note_page(struct seq_file *m, struct pg_state *st,
188 /* 208 /*
189 * Now print the actual finished series 209 * Now print the actual finished series
190 */ 210 */
191 seq_printf(m, "0x%0*lx-0x%0*lx ", 211 pt_dump_seq_printf(m, st->to_dmesg, "0x%0*lx-0x%0*lx ",
192 width, st->start_address, 212 width, st->start_address,
193 width, st->current_address); 213 width, st->current_address);
194 214
195 delta = (st->current_address - st->start_address) >> 10; 215 delta = (st->current_address - st->start_address) >> 10;
196 while (!(delta & 1023) && unit[1]) { 216 while (!(delta & 1023) && unit[1]) {
197 delta >>= 10; 217 delta >>= 10;
198 unit++; 218 unit++;
199 } 219 }
200 seq_printf(m, "%9lu%c ", delta, *unit); 220 pt_dump_cont_printf(m, st->to_dmesg, "%9lu%c ", delta, *unit);
201 printk_prot(m, st->current_prot, st->level); 221 printk_prot(m, st->current_prot, st->level, st->to_dmesg);
202 222
203 /* 223 /*
204 * We print markers for special areas of address space, 224 * We print markers for special areas of address space,
@@ -207,7 +227,8 @@ static void note_page(struct seq_file *m, struct pg_state *st,
207 */ 227 */
208 if (st->current_address >= st->marker[1].start_address) { 228 if (st->current_address >= st->marker[1].start_address) {
209 st->marker++; 229 st->marker++;
210 seq_printf(m, "---[ %s ]---\n", st->marker->name); 230 pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n",
231 st->marker->name);
211 } 232 }
212 233
213 st->start_address = st->current_address; 234 st->start_address = st->current_address;
@@ -296,7 +317,7 @@ static void walk_pud_level(struct seq_file *m, struct pg_state *st, pgd_t addr,
296#define pgd_none(a) pud_none(__pud(pgd_val(a))) 317#define pgd_none(a) pud_none(__pud(pgd_val(a)))
297#endif 318#endif
298 319
299static void walk_pgd_level(struct seq_file *m) 320void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd)
300{ 321{
301#ifdef CONFIG_X86_64 322#ifdef CONFIG_X86_64
302 pgd_t *start = (pgd_t *) &init_level4_pgt; 323 pgd_t *start = (pgd_t *) &init_level4_pgt;
@@ -304,9 +325,12 @@ static void walk_pgd_level(struct seq_file *m)
304 pgd_t *start = swapper_pg_dir; 325 pgd_t *start = swapper_pg_dir;
305#endif 326#endif
306 int i; 327 int i;
307 struct pg_state st; 328 struct pg_state st = {};
308 329
309 memset(&st, 0, sizeof(st)); 330 if (pgd) {
331 start = pgd;
332 st.to_dmesg = true;
333 }
310 334
311 for (i = 0; i < PTRS_PER_PGD; i++) { 335 for (i = 0; i < PTRS_PER_PGD; i++) {
312 st.current_address = normalize_addr(i * PGD_LEVEL_MULT); 336 st.current_address = normalize_addr(i * PGD_LEVEL_MULT);
@@ -331,7 +355,7 @@ static void walk_pgd_level(struct seq_file *m)
331 355
332static int ptdump_show(struct seq_file *m, void *v) 356static int ptdump_show(struct seq_file *m, void *v)
333{ 357{
334 walk_pgd_level(m); 358 ptdump_walk_pgd_level(m, NULL);
335 return 0; 359 return 0;
336} 360}
337 361
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 9d591c895803..8e5722992677 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -584,8 +584,13 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
584 584
585 if (error_code & PF_INSTR) { 585 if (error_code & PF_INSTR) {
586 unsigned int level; 586 unsigned int level;
587 pgd_t *pgd;
588 pte_t *pte;
587 589
588 pte_t *pte = lookup_address(address, &level); 590 pgd = __va(read_cr3() & PHYSICAL_PAGE_MASK);
591 pgd += pgd_index(address);
592
593 pte = lookup_address_in_pgd(pgd, address, &level);
589 594
590 if (pte && pte_present(*pte) && !pte_exec(*pte)) 595 if (pte && pte_present(*pte) && !pte_exec(*pte))
591 printk(nx_warning, from_kuid(&init_user_ns, current_uid())); 596 printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
@@ -1001,6 +1006,12 @@ static int fault_in_kernel_space(unsigned long address)
1001 1006
1002static inline bool smap_violation(int error_code, struct pt_regs *regs) 1007static inline bool smap_violation(int error_code, struct pt_regs *regs)
1003{ 1008{
1009 if (!IS_ENABLED(CONFIG_X86_SMAP))
1010 return false;
1011
1012 if (!static_cpu_has(X86_FEATURE_SMAP))
1013 return false;
1014
1004 if (error_code & PF_USER) 1015 if (error_code & PF_USER)
1005 return false; 1016 return false;
1006 1017
@@ -1014,13 +1025,17 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
1014 * This routine handles page faults. It determines the address, 1025 * This routine handles page faults. It determines the address,
1015 * and the problem, and then passes it off to one of the appropriate 1026 * and the problem, and then passes it off to one of the appropriate
1016 * routines. 1027 * routines.
1028 *
1029 * This function must have noinline because both callers
1030 * {,trace_}do_page_fault() have notrace on. Having this an actual function
1031 * guarantees there's a function trace entry.
1017 */ 1032 */
1018static void __kprobes 1033static void __kprobes noinline
1019__do_page_fault(struct pt_regs *regs, unsigned long error_code) 1034__do_page_fault(struct pt_regs *regs, unsigned long error_code,
1035 unsigned long address)
1020{ 1036{
1021 struct vm_area_struct *vma; 1037 struct vm_area_struct *vma;
1022 struct task_struct *tsk; 1038 struct task_struct *tsk;
1023 unsigned long address;
1024 struct mm_struct *mm; 1039 struct mm_struct *mm;
1025 int fault; 1040 int fault;
1026 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; 1041 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
@@ -1028,9 +1043,6 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
1028 tsk = current; 1043 tsk = current;
1029 mm = tsk->mm; 1044 mm = tsk->mm;
1030 1045
1031 /* Get the faulting address: */
1032 address = read_cr2();
1033
1034 /* 1046 /*
1035 * Detect and handle instructions that would cause a page fault for 1047 * Detect and handle instructions that would cause a page fault for
1036 * both a tracked kernel page and a userspace page. 1048 * both a tracked kernel page and a userspace page.
@@ -1087,11 +1099,9 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
1087 if (unlikely(error_code & PF_RSVD)) 1099 if (unlikely(error_code & PF_RSVD))
1088 pgtable_bad(regs, error_code, address); 1100 pgtable_bad(regs, error_code, address);
1089 1101
1090 if (static_cpu_has(X86_FEATURE_SMAP)) { 1102 if (unlikely(smap_violation(error_code, regs))) {
1091 if (unlikely(smap_violation(error_code, regs))) { 1103 bad_area_nosemaphore(regs, error_code, address);
1092 bad_area_nosemaphore(regs, error_code, address); 1104 return;
1093 return;
1094 }
1095 } 1105 }
1096 1106
1097 /* 1107 /*
@@ -1244,32 +1254,50 @@ good_area:
1244 up_read(&mm->mmap_sem); 1254 up_read(&mm->mmap_sem);
1245} 1255}
1246 1256
1247dotraplinkage void __kprobes 1257dotraplinkage void __kprobes notrace
1248do_page_fault(struct pt_regs *regs, unsigned long error_code) 1258do_page_fault(struct pt_regs *regs, unsigned long error_code)
1249{ 1259{
1260 unsigned long address = read_cr2(); /* Get the faulting address */
1250 enum ctx_state prev_state; 1261 enum ctx_state prev_state;
1251 1262
1263 /*
1264 * We must have this function tagged with __kprobes, notrace and call
1265 * read_cr2() before calling anything else. To avoid calling any kind
1266 * of tracing machinery before we've observed the CR2 value.
1267 *
1268 * exception_{enter,exit}() contain all sorts of tracepoints.
1269 */
1270
1252 prev_state = exception_enter(); 1271 prev_state = exception_enter();
1253 __do_page_fault(regs, error_code); 1272 __do_page_fault(regs, error_code, address);
1254 exception_exit(prev_state); 1273 exception_exit(prev_state);
1255} 1274}
1256 1275
1257static void trace_page_fault_entries(struct pt_regs *regs, 1276#ifdef CONFIG_TRACING
1277static void trace_page_fault_entries(unsigned long address, struct pt_regs *regs,
1258 unsigned long error_code) 1278 unsigned long error_code)
1259{ 1279{
1260 if (user_mode(regs)) 1280 if (user_mode(regs))
1261 trace_page_fault_user(read_cr2(), regs, error_code); 1281 trace_page_fault_user(address, regs, error_code);
1262 else 1282 else
1263 trace_page_fault_kernel(read_cr2(), regs, error_code); 1283 trace_page_fault_kernel(address, regs, error_code);
1264} 1284}
1265 1285
1266dotraplinkage void __kprobes 1286dotraplinkage void __kprobes notrace
1267trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) 1287trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
1268{ 1288{
1289 /*
1290 * The exception_enter and tracepoint processing could
1291 * trigger another page faults (user space callchain
1292 * reading) and destroy the original cr2 value, so read
1293 * the faulting address now.
1294 */
1295 unsigned long address = read_cr2();
1269 enum ctx_state prev_state; 1296 enum ctx_state prev_state;
1270 1297
1271 prev_state = exception_enter(); 1298 prev_state = exception_enter();
1272 trace_page_fault_entries(regs, error_code); 1299 trace_page_fault_entries(address, regs, error_code);
1273 __do_page_fault(regs, error_code); 1300 __do_page_fault(regs, error_code, address);
1274 exception_exit(prev_state); 1301 exception_exit(prev_state);
1275} 1302}
1303#endif /* CONFIG_TRACING */
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 81b2750f3666..27aa0455fab3 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -493,14 +493,6 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)
493 struct numa_memblk *mb = &mi->blk[i]; 493 struct numa_memblk *mb = &mi->blk[i];
494 memblock_set_node(mb->start, mb->end - mb->start, 494 memblock_set_node(mb->start, mb->end - mb->start,
495 &memblock.memory, mb->nid); 495 &memblock.memory, mb->nid);
496
497 /*
498 * At this time, all memory regions reserved by memblock are
499 * used by the kernel. Set the nid in memblock.reserved will
500 * mark out all the nodes the kernel resides in.
501 */
502 memblock_set_node(mb->start, mb->end - mb->start,
503 &memblock.reserved, mb->nid);
504 } 496 }
505 497
506 /* 498 /*
@@ -565,10 +557,21 @@ static void __init numa_init_array(void)
565static void __init numa_clear_kernel_node_hotplug(void) 557static void __init numa_clear_kernel_node_hotplug(void)
566{ 558{
567 int i, nid; 559 int i, nid;
568 nodemask_t numa_kernel_nodes; 560 nodemask_t numa_kernel_nodes = NODE_MASK_NONE;
569 unsigned long start, end; 561 unsigned long start, end;
570 struct memblock_type *type = &memblock.reserved; 562 struct memblock_type *type = &memblock.reserved;
571 563
564 /*
565 * At this time, all memory regions reserved by memblock are
566 * used by the kernel. Set the nid in memblock.reserved will
567 * mark out all the nodes the kernel resides in.
568 */
569 for (i = 0; i < numa_meminfo.nr_blks; i++) {
570 struct numa_memblk *mb = &numa_meminfo.blk[i];
571 memblock_set_node(mb->start, mb->end - mb->start,
572 &memblock.reserved, mb->nid);
573 }
574
572 /* Mark all kernel nodes. */ 575 /* Mark all kernel nodes. */
573 for (i = 0; i < type->cnt; i++) 576 for (i = 0; i < type->cnt; i++)
574 node_set(type->regions[i].nid, numa_kernel_nodes); 577 node_set(type->regions[i].nid, numa_kernel_nodes);
diff --git a/arch/x86/mm/numa_32.c b/arch/x86/mm/numa_32.c
index 0342d27ca798..47b6436e41c2 100644
--- a/arch/x86/mm/numa_32.c
+++ b/arch/x86/mm/numa_32.c
@@ -52,6 +52,8 @@ void memory_present(int nid, unsigned long start, unsigned long end)
52 nid, start, end); 52 nid, start, end);
53 printk(KERN_DEBUG " Setting physnode_map array to node %d for pfns:\n", nid); 53 printk(KERN_DEBUG " Setting physnode_map array to node %d for pfns:\n", nid);
54 printk(KERN_DEBUG " "); 54 printk(KERN_DEBUG " ");
55 start = round_down(start, PAGES_PER_SECTION);
56 end = round_up(end, PAGES_PER_SECTION);
55 for (pfn = start; pfn < end; pfn += PAGES_PER_SECTION) { 57 for (pfn = start; pfn < end; pfn += PAGES_PER_SECTION) {
56 physnode_map[pfn / PAGES_PER_SECTION] = nid; 58 physnode_map[pfn / PAGES_PER_SECTION] = nid;
57 printk(KERN_CONT "%lx ", pfn); 59 printk(KERN_CONT "%lx ", pfn);
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index b3b19f46c016..ae242a7c11c7 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -126,8 +126,8 @@ within(unsigned long addr, unsigned long start, unsigned long end)
126 * @vaddr: virtual start address 126 * @vaddr: virtual start address
127 * @size: number of bytes to flush 127 * @size: number of bytes to flush
128 * 128 *
129 * clflush is an unordered instruction which needs fencing with mfence 129 * clflushopt is an unordered instruction which needs fencing with mfence or
130 * to avoid ordering issues. 130 * sfence to avoid ordering issues.
131 */ 131 */
132void clflush_cache_range(void *vaddr, unsigned int size) 132void clflush_cache_range(void *vaddr, unsigned int size)
133{ 133{
@@ -136,11 +136,11 @@ void clflush_cache_range(void *vaddr, unsigned int size)
136 mb(); 136 mb();
137 137
138 for (; vaddr < vend; vaddr += boot_cpu_data.x86_clflush_size) 138 for (; vaddr < vend; vaddr += boot_cpu_data.x86_clflush_size)
139 clflush(vaddr); 139 clflushopt(vaddr);
140 /* 140 /*
141 * Flush any possible final partial cacheline: 141 * Flush any possible final partial cacheline:
142 */ 142 */
143 clflush(vend); 143 clflushopt(vend);
144 144
145 mb(); 145 mb();
146} 146}
@@ -323,8 +323,12 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
323 return prot; 323 return prot;
324} 324}
325 325
326static pte_t *__lookup_address_in_pgd(pgd_t *pgd, unsigned long address, 326/*
327 unsigned int *level) 327 * Lookup the page table entry for a virtual address in a specific pgd.
328 * Return a pointer to the entry and the level of the mapping.
329 */
330pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
331 unsigned int *level)
328{ 332{
329 pud_t *pud; 333 pud_t *pud;
330 pmd_t *pmd; 334 pmd_t *pmd;
@@ -365,7 +369,7 @@ static pte_t *__lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
365 */ 369 */
366pte_t *lookup_address(unsigned long address, unsigned int *level) 370pte_t *lookup_address(unsigned long address, unsigned int *level)
367{ 371{
368 return __lookup_address_in_pgd(pgd_offset_k(address), address, level); 372 return lookup_address_in_pgd(pgd_offset_k(address), address, level);
369} 373}
370EXPORT_SYMBOL_GPL(lookup_address); 374EXPORT_SYMBOL_GPL(lookup_address);
371 375
@@ -373,7 +377,7 @@ static pte_t *_lookup_address_cpa(struct cpa_data *cpa, unsigned long address,
373 unsigned int *level) 377 unsigned int *level)
374{ 378{
375 if (cpa->pgd) 379 if (cpa->pgd)
376 return __lookup_address_in_pgd(cpa->pgd + pgd_index(address), 380 return lookup_address_in_pgd(cpa->pgd + pgd_index(address),
377 address, level); 381 address, level);
378 382
379 return lookup_address(address, level); 383 return lookup_address(address, level);
@@ -692,6 +696,18 @@ static bool try_to_free_pmd_page(pmd_t *pmd)
692 return true; 696 return true;
693} 697}
694 698
699static bool try_to_free_pud_page(pud_t *pud)
700{
701 int i;
702
703 for (i = 0; i < PTRS_PER_PUD; i++)
704 if (!pud_none(pud[i]))
705 return false;
706
707 free_page((unsigned long)pud);
708 return true;
709}
710
695static bool unmap_pte_range(pmd_t *pmd, unsigned long start, unsigned long end) 711static bool unmap_pte_range(pmd_t *pmd, unsigned long start, unsigned long end)
696{ 712{
697 pte_t *pte = pte_offset_kernel(pmd, start); 713 pte_t *pte = pte_offset_kernel(pmd, start);
@@ -805,6 +821,16 @@ static void unmap_pud_range(pgd_t *pgd, unsigned long start, unsigned long end)
805 */ 821 */
806} 822}
807 823
824static void unmap_pgd_range(pgd_t *root, unsigned long addr, unsigned long end)
825{
826 pgd_t *pgd_entry = root + pgd_index(addr);
827
828 unmap_pud_range(pgd_entry, addr, end);
829
830 if (try_to_free_pud_page((pud_t *)pgd_page_vaddr(*pgd_entry)))
831 pgd_clear(pgd_entry);
832}
833
808static int alloc_pte_page(pmd_t *pmd) 834static int alloc_pte_page(pmd_t *pmd)
809{ 835{
810 pte_t *pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_NOTRACK); 836 pte_t *pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_NOTRACK);
@@ -999,9 +1025,8 @@ static int populate_pud(struct cpa_data *cpa, unsigned long start, pgd_t *pgd,
999static int populate_pgd(struct cpa_data *cpa, unsigned long addr) 1025static int populate_pgd(struct cpa_data *cpa, unsigned long addr)
1000{ 1026{
1001 pgprot_t pgprot = __pgprot(_KERNPG_TABLE); 1027 pgprot_t pgprot = __pgprot(_KERNPG_TABLE);
1002 bool allocd_pgd = false;
1003 pgd_t *pgd_entry;
1004 pud_t *pud = NULL; /* shut up gcc */ 1028 pud_t *pud = NULL; /* shut up gcc */
1029 pgd_t *pgd_entry;
1005 int ret; 1030 int ret;
1006 1031
1007 pgd_entry = cpa->pgd + pgd_index(addr); 1032 pgd_entry = cpa->pgd + pgd_index(addr);
@@ -1015,7 +1040,6 @@ static int populate_pgd(struct cpa_data *cpa, unsigned long addr)
1015 return -1; 1040 return -1;
1016 1041
1017 set_pgd(pgd_entry, __pgd(__pa(pud) | _KERNPG_TABLE)); 1042 set_pgd(pgd_entry, __pgd(__pa(pud) | _KERNPG_TABLE));
1018 allocd_pgd = true;
1019 } 1043 }
1020 1044
1021 pgprot_val(pgprot) &= ~pgprot_val(cpa->mask_clr); 1045 pgprot_val(pgprot) &= ~pgprot_val(cpa->mask_clr);
@@ -1023,19 +1047,11 @@ static int populate_pgd(struct cpa_data *cpa, unsigned long addr)
1023 1047
1024 ret = populate_pud(cpa, addr, pgd_entry, pgprot); 1048 ret = populate_pud(cpa, addr, pgd_entry, pgprot);
1025 if (ret < 0) { 1049 if (ret < 0) {
1026 unmap_pud_range(pgd_entry, addr, 1050 unmap_pgd_range(cpa->pgd, addr,
1027 addr + (cpa->numpages << PAGE_SHIFT)); 1051 addr + (cpa->numpages << PAGE_SHIFT));
1028
1029 if (allocd_pgd) {
1030 /*
1031 * If I allocated this PUD page, I can just as well
1032 * free it in this error path.
1033 */
1034 pgd_clear(pgd_entry);
1035 free_page((unsigned long)pud);
1036 }
1037 return ret; 1052 return ret;
1038 } 1053 }
1054
1039 cpa->numpages = ret; 1055 cpa->numpages = ret;
1040 return 0; 1056 return 0;
1041} 1057}
@@ -1377,10 +1393,10 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages,
1377 cache = cache_attr(mask_set); 1393 cache = cache_attr(mask_set);
1378 1394
1379 /* 1395 /*
1380 * On success we use clflush, when the CPU supports it to 1396 * On success we use CLFLUSH, when the CPU supports it to
1381 * avoid the wbindv. If the CPU does not support it and in the 1397 * avoid the WBINVD. If the CPU does not support it and in the
1382 * error case we fall back to cpa_flush_all (which uses 1398 * error case we fall back to cpa_flush_all (which uses
1383 * wbindv): 1399 * WBINVD):
1384 */ 1400 */
1385 if (!ret && cpu_has_clflush) { 1401 if (!ret && cpu_has_clflush) {
1386 if (cpa.flags & (CPA_PAGES_ARRAY | CPA_ARRAY)) { 1402 if (cpa.flags & (CPA_PAGES_ARRAY | CPA_ARRAY)) {
@@ -1861,6 +1877,12 @@ out:
1861 return retval; 1877 return retval;
1862} 1878}
1863 1879
1880void kernel_unmap_pages_in_pgd(pgd_t *root, unsigned long address,
1881 unsigned numpages)
1882{
1883 unmap_pgd_range(root, address, address + (numpages << PAGE_SHIFT));
1884}
1885
1864/* 1886/*
1865 * The testcases use internal knowledge of the implementation that shouldn't 1887 * The testcases use internal knowledge of the implementation that shouldn't
1866 * be exposed to the rest of the kernel. Include these directly here. 1888 * be exposed to the rest of the kernel. Include these directly here.
diff --git a/arch/x86/mm/srat.c b/arch/x86/mm/srat.c
index 1a25187e151e..1953e9c9391a 100644
--- a/arch/x86/mm/srat.c
+++ b/arch/x86/mm/srat.c
@@ -42,15 +42,25 @@ static __init inline int srat_disabled(void)
42 return acpi_numa < 0; 42 return acpi_numa < 0;
43} 43}
44 44
45/* Callback for SLIT parsing */ 45/*
46 * Callback for SLIT parsing. pxm_to_node() returns NUMA_NO_NODE for
47 * I/O localities since SRAT does not list them. I/O localities are
48 * not supported at this point.
49 */
46void __init acpi_numa_slit_init(struct acpi_table_slit *slit) 50void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
47{ 51{
48 int i, j; 52 int i, j;
49 53
50 for (i = 0; i < slit->locality_count; i++) 54 for (i = 0; i < slit->locality_count; i++) {
51 for (j = 0; j < slit->locality_count; j++) 55 if (pxm_to_node(i) == NUMA_NO_NODE)
56 continue;
57 for (j = 0; j < slit->locality_count; j++) {
58 if (pxm_to_node(j) == NUMA_NO_NODE)
59 continue;
52 numa_set_distance(pxm_to_node(i), pxm_to_node(j), 60 numa_set_distance(pxm_to_node(i), pxm_to_node(j),
53 slit->entry[slit->locality_count * i + j]); 61 slit->entry[slit->locality_count * i + j]);
62 }
63 }
54} 64}
55 65
56/* Callback for Proximity Domain -> x2APIC mapping */ 66/* Callback for Proximity Domain -> x2APIC mapping */
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index ae699b3bbac8..dd8dda167a24 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -103,7 +103,7 @@ static void flush_tlb_func(void *info)
103 if (f->flush_mm != this_cpu_read(cpu_tlbstate.active_mm)) 103 if (f->flush_mm != this_cpu_read(cpu_tlbstate.active_mm))
104 return; 104 return;
105 105
106 count_vm_event(NR_TLB_REMOTE_FLUSH_RECEIVED); 106 count_vm_tlb_event(NR_TLB_REMOTE_FLUSH_RECEIVED);
107 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK) { 107 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK) {
108 if (f->flush_end == TLB_FLUSH_ALL) 108 if (f->flush_end == TLB_FLUSH_ALL)
109 local_flush_tlb(); 109 local_flush_tlb();
@@ -131,7 +131,7 @@ void native_flush_tlb_others(const struct cpumask *cpumask,
131 info.flush_start = start; 131 info.flush_start = start;
132 info.flush_end = end; 132 info.flush_end = end;
133 133
134 count_vm_event(NR_TLB_REMOTE_FLUSH); 134 count_vm_tlb_event(NR_TLB_REMOTE_FLUSH);
135 if (is_uv_system()) { 135 if (is_uv_system()) {
136 unsigned int cpu; 136 unsigned int cpu;
137 137
@@ -151,44 +151,19 @@ void flush_tlb_current_task(void)
151 151
152 preempt_disable(); 152 preempt_disable();
153 153
154 count_vm_event(NR_TLB_LOCAL_FLUSH_ALL); 154 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL);
155 local_flush_tlb(); 155 local_flush_tlb();
156 if (cpumask_any_but(mm_cpumask(mm), smp_processor_id()) < nr_cpu_ids) 156 if (cpumask_any_but(mm_cpumask(mm), smp_processor_id()) < nr_cpu_ids)
157 flush_tlb_others(mm_cpumask(mm), mm, 0UL, TLB_FLUSH_ALL); 157 flush_tlb_others(mm_cpumask(mm), mm, 0UL, TLB_FLUSH_ALL);
158 preempt_enable(); 158 preempt_enable();
159} 159}
160 160
161/*
162 * It can find out the THP large page, or
163 * HUGETLB page in tlb_flush when THP disabled
164 */
165static inline unsigned long has_large_page(struct mm_struct *mm,
166 unsigned long start, unsigned long end)
167{
168 pgd_t *pgd;
169 pud_t *pud;
170 pmd_t *pmd;
171 unsigned long addr = ALIGN(start, HPAGE_SIZE);
172 for (; addr < end; addr += HPAGE_SIZE) {
173 pgd = pgd_offset(mm, addr);
174 if (likely(!pgd_none(*pgd))) {
175 pud = pud_offset(pgd, addr);
176 if (likely(!pud_none(*pud))) {
177 pmd = pmd_offset(pud, addr);
178 if (likely(!pmd_none(*pmd)))
179 if (pmd_large(*pmd))
180 return addr;
181 }
182 }
183 }
184 return 0;
185}
186
187void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, 161void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
188 unsigned long end, unsigned long vmflag) 162 unsigned long end, unsigned long vmflag)
189{ 163{
190 unsigned long addr; 164 unsigned long addr;
191 unsigned act_entries, tlb_entries = 0; 165 unsigned act_entries, tlb_entries = 0;
166 unsigned long nr_base_pages;
192 167
193 preempt_disable(); 168 preempt_disable();
194 if (current->active_mm != mm) 169 if (current->active_mm != mm)
@@ -210,21 +185,20 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
210 tlb_entries = tlb_lli_4k[ENTRIES]; 185 tlb_entries = tlb_lli_4k[ENTRIES];
211 else 186 else
212 tlb_entries = tlb_lld_4k[ENTRIES]; 187 tlb_entries = tlb_lld_4k[ENTRIES];
188
213 /* Assume all of TLB entries was occupied by this task */ 189 /* Assume all of TLB entries was occupied by this task */
214 act_entries = mm->total_vm > tlb_entries ? tlb_entries : mm->total_vm; 190 act_entries = tlb_entries >> tlb_flushall_shift;
191 act_entries = mm->total_vm > act_entries ? act_entries : mm->total_vm;
192 nr_base_pages = (end - start) >> PAGE_SHIFT;
215 193
216 /* tlb_flushall_shift is on balance point, details in commit log */ 194 /* tlb_flushall_shift is on balance point, details in commit log */
217 if ((end - start) >> PAGE_SHIFT > act_entries >> tlb_flushall_shift) { 195 if (nr_base_pages > act_entries) {
218 count_vm_event(NR_TLB_LOCAL_FLUSH_ALL); 196 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL);
219 local_flush_tlb(); 197 local_flush_tlb();
220 } else { 198 } else {
221 if (has_large_page(mm, start, end)) {
222 local_flush_tlb();
223 goto flush_all;
224 }
225 /* flush range by one by one 'invlpg' */ 199 /* flush range by one by one 'invlpg' */
226 for (addr = start; addr < end; addr += PAGE_SIZE) { 200 for (addr = start; addr < end; addr += PAGE_SIZE) {
227 count_vm_event(NR_TLB_LOCAL_FLUSH_ONE); 201 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ONE);
228 __flush_tlb_single(addr); 202 __flush_tlb_single(addr);
229 } 203 }
230 204
@@ -262,7 +236,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long start)
262 236
263static void do_flush_tlb_all(void *info) 237static void do_flush_tlb_all(void *info)
264{ 238{
265 count_vm_event(NR_TLB_REMOTE_FLUSH_RECEIVED); 239 count_vm_tlb_event(NR_TLB_REMOTE_FLUSH_RECEIVED);
266 __flush_tlb_all(); 240 __flush_tlb_all();
267 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_LAZY) 241 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_LAZY)
268 leave_mm(smp_processor_id()); 242 leave_mm(smp_processor_id());
@@ -270,7 +244,7 @@ static void do_flush_tlb_all(void *info)
270 244
271void flush_tlb_all(void) 245void flush_tlb_all(void)
272{ 246{
273 count_vm_event(NR_TLB_REMOTE_FLUSH); 247 count_vm_tlb_event(NR_TLB_REMOTE_FLUSH);
274 on_each_cpu(do_flush_tlb_all, NULL, 1); 248 on_each_cpu(do_flush_tlb_all, NULL, 1);
275} 249}
276 250
diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
index 877b9a1b2152..01495755701b 100644
--- a/arch/x86/net/bpf_jit.S
+++ b/arch/x86/net/bpf_jit.S
@@ -140,7 +140,7 @@ bpf_slow_path_byte_msh:
140 push %r9; \ 140 push %r9; \
141 push SKBDATA; \ 141 push SKBDATA; \
142/* rsi already has offset */ \ 142/* rsi already has offset */ \
143 mov $SIZE,%ecx; /* size */ \ 143 mov $SIZE,%edx; /* size */ \
144 call bpf_internal_load_pointer_neg_helper; \ 144 call bpf_internal_load_pointer_neg_helper; \
145 test %rax,%rax; \ 145 test %rax,%rax; \
146 pop SKBDATA; \ 146 pop SKBDATA; \
diff --git a/arch/x86/platform/efi/Makefile b/arch/x86/platform/efi/Makefile
index b7b0b35c1981..d51045afcaaf 100644
--- a/arch/x86/platform/efi/Makefile
+++ b/arch/x86/platform/efi/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o 1obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o
2obj-$(CONFIG_ACPI_BGRT) += efi-bgrt.o 2obj-$(CONFIG_ACPI_BGRT) += efi-bgrt.o
3obj-$(CONFIG_EARLY_PRINTK_EFI) += early_printk.o 3obj-$(CONFIG_EARLY_PRINTK_EFI) += early_printk.o
4obj-$(CONFIG_EFI_MIXED) += efi_thunk_$(BITS).o
diff --git a/arch/x86/platform/efi/efi-bgrt.c b/arch/x86/platform/efi/efi-bgrt.c
index 7145ec63c520..f15103dff4b4 100644
--- a/arch/x86/platform/efi/efi-bgrt.c
+++ b/arch/x86/platform/efi/efi-bgrt.c
@@ -42,14 +42,15 @@ void __init efi_bgrt_init(void)
42 42
43 if (bgrt_tab->header.length < sizeof(*bgrt_tab)) 43 if (bgrt_tab->header.length < sizeof(*bgrt_tab))
44 return; 44 return;
45 if (bgrt_tab->version != 1) 45 if (bgrt_tab->version != 1 || bgrt_tab->status != 1)
46 return; 46 return;
47 if (bgrt_tab->image_type != 0 || !bgrt_tab->image_address) 47 if (bgrt_tab->image_type != 0 || !bgrt_tab->image_address)
48 return; 48 return;
49 49
50 image = efi_lookup_mapped_addr(bgrt_tab->image_address); 50 image = efi_lookup_mapped_addr(bgrt_tab->image_address);
51 if (!image) { 51 if (!image) {
52 image = ioremap(bgrt_tab->image_address, sizeof(bmp_header)); 52 image = early_memremap(bgrt_tab->image_address,
53 sizeof(bmp_header));
53 ioremapped = true; 54 ioremapped = true;
54 if (!image) 55 if (!image)
55 return; 56 return;
@@ -57,7 +58,7 @@ void __init efi_bgrt_init(void)
57 58
58 memcpy_fromio(&bmp_header, image, sizeof(bmp_header)); 59 memcpy_fromio(&bmp_header, image, sizeof(bmp_header));
59 if (ioremapped) 60 if (ioremapped)
60 iounmap(image); 61 early_iounmap(image, sizeof(bmp_header));
61 bgrt_image_size = bmp_header.size; 62 bgrt_image_size = bmp_header.size;
62 63
63 bgrt_image = kmalloc(bgrt_image_size, GFP_KERNEL); 64 bgrt_image = kmalloc(bgrt_image_size, GFP_KERNEL);
@@ -65,7 +66,8 @@ void __init efi_bgrt_init(void)
65 return; 66 return;
66 67
67 if (ioremapped) { 68 if (ioremapped) {
68 image = ioremap(bgrt_tab->image_address, bmp_header.size); 69 image = early_memremap(bgrt_tab->image_address,
70 bmp_header.size);
69 if (!image) { 71 if (!image) {
70 kfree(bgrt_image); 72 kfree(bgrt_image);
71 bgrt_image = NULL; 73 bgrt_image = NULL;
@@ -75,5 +77,5 @@ void __init efi_bgrt_init(void)
75 77
76 memcpy_fromio(bgrt_image, image, bgrt_image_size); 78 memcpy_fromio(bgrt_image, image, bgrt_image_size);
77 if (ioremapped) 79 if (ioremapped)
78 iounmap(image); 80 early_iounmap(image, bmp_header.size);
79} 81}
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index d62ec87a2b26..3781dd39e8bd 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -52,6 +52,7 @@
52#include <asm/tlbflush.h> 52#include <asm/tlbflush.h>
53#include <asm/x86_init.h> 53#include <asm/x86_init.h>
54#include <asm/rtc.h> 54#include <asm/rtc.h>
55#include <asm/uv/uv.h>
55 56
56#define EFI_DEBUG 57#define EFI_DEBUG
57 58
@@ -67,9 +68,7 @@ struct efi_memory_map memmap;
67static struct efi efi_phys __initdata; 68static struct efi efi_phys __initdata;
68static efi_system_table_t efi_systab __initdata; 69static efi_system_table_t efi_systab __initdata;
69 70
70unsigned long x86_efi_facility; 71static efi_config_table_type_t arch_tables[] __initdata = {
71
72static __initdata efi_config_table_type_t arch_tables[] = {
73#ifdef CONFIG_X86_UV 72#ifdef CONFIG_X86_UV
74 {UV_SYSTEM_TABLE_GUID, "UVsystab", &efi.uv_systab}, 73 {UV_SYSTEM_TABLE_GUID, "UVsystab", &efi.uv_systab},
75#endif 74#endif
@@ -78,16 +77,7 @@ static __initdata efi_config_table_type_t arch_tables[] = {
78 77
79u64 efi_setup; /* efi setup_data physical address */ 78u64 efi_setup; /* efi setup_data physical address */
80 79
81/* 80static bool disable_runtime __initdata = false;
82 * Returns 1 if 'facility' is enabled, 0 otherwise.
83 */
84int efi_enabled(int facility)
85{
86 return test_bit(facility, &x86_efi_facility) != 0;
87}
88EXPORT_SYMBOL(efi_enabled);
89
90static bool __initdata disable_runtime = false;
91static int __init setup_noefi(char *arg) 81static int __init setup_noefi(char *arg)
92{ 82{
93 disable_runtime = true; 83 disable_runtime = true;
@@ -256,27 +246,12 @@ static efi_status_t __init phys_efi_set_virtual_address_map(
256 return status; 246 return status;
257} 247}
258 248
259static efi_status_t __init phys_efi_get_time(efi_time_t *tm,
260 efi_time_cap_t *tc)
261{
262 unsigned long flags;
263 efi_status_t status;
264
265 spin_lock_irqsave(&rtc_lock, flags);
266 efi_call_phys_prelog();
267 status = efi_call_phys2(efi_phys.get_time, virt_to_phys(tm),
268 virt_to_phys(tc));
269 efi_call_phys_epilog();
270 spin_unlock_irqrestore(&rtc_lock, flags);
271 return status;
272}
273
274int efi_set_rtc_mmss(const struct timespec *now) 249int efi_set_rtc_mmss(const struct timespec *now)
275{ 250{
276 unsigned long nowtime = now->tv_sec; 251 unsigned long nowtime = now->tv_sec;
277 efi_status_t status; 252 efi_status_t status;
278 efi_time_t eft; 253 efi_time_t eft;
279 efi_time_cap_t cap; 254 efi_time_cap_t cap;
280 struct rtc_time tm; 255 struct rtc_time tm;
281 256
282 status = efi.get_time(&eft, &cap); 257 status = efi.get_time(&eft, &cap);
@@ -294,9 +269,8 @@ int efi_set_rtc_mmss(const struct timespec *now)
294 eft.second = tm.tm_sec; 269 eft.second = tm.tm_sec;
295 eft.nanosecond = 0; 270 eft.nanosecond = 0;
296 } else { 271 } else {
297 printk(KERN_ERR 272 pr_err("%s: Invalid EFI RTC value: write of %lx to EFI RTC failed\n",
298 "%s: Invalid EFI RTC value: write of %lx to EFI RTC failed\n", 273 __func__, nowtime);
299 __FUNCTION__, nowtime);
300 return -1; 274 return -1;
301 } 275 }
302 276
@@ -412,8 +386,7 @@ static void __init print_efi_memmap(void)
412 p < memmap.map_end; 386 p < memmap.map_end;
413 p += memmap.desc_size, i++) { 387 p += memmap.desc_size, i++) {
414 md = p; 388 md = p;
415 pr_info("mem%02u: type=%u, attr=0x%llx, " 389 pr_info("mem%02u: type=%u, attr=0x%llx, range=[0x%016llx-0x%016llx) (%lluMB)\n",
416 "range=[0x%016llx-0x%016llx) (%lluMB)\n",
417 i, md->type, md->attribute, md->phys_addr, 390 i, md->type, md->attribute, md->phys_addr,
418 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT), 391 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
419 (md->num_pages >> (20 - EFI_PAGE_SHIFT))); 392 (md->num_pages >> (20 - EFI_PAGE_SHIFT)));
@@ -445,9 +418,8 @@ void __init efi_reserve_boot_services(void)
445 memblock_is_region_reserved(start, size)) { 418 memblock_is_region_reserved(start, size)) {
446 /* Could not reserve, skip it */ 419 /* Could not reserve, skip it */
447 md->num_pages = 0; 420 md->num_pages = 0;
448 memblock_dbg("Could not reserve boot range " 421 memblock_dbg("Could not reserve boot range [0x%010llx-0x%010llx]\n",
449 "[0x%010llx-0x%010llx]\n", 422 start, start+size-1);
450 start, start+size-1);
451 } else 423 } else
452 memblock_reserve(start, size); 424 memblock_reserve(start, size);
453 } 425 }
@@ -455,7 +427,7 @@ void __init efi_reserve_boot_services(void)
455 427
456void __init efi_unmap_memmap(void) 428void __init efi_unmap_memmap(void)
457{ 429{
458 clear_bit(EFI_MEMMAP, &x86_efi_facility); 430 clear_bit(EFI_MEMMAP, &efi.flags);
459 if (memmap.map) { 431 if (memmap.map) {
460 early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size); 432 early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size);
461 memmap.map = NULL; 433 memmap.map = NULL;
@@ -466,9 +438,6 @@ void __init efi_free_boot_services(void)
466{ 438{
467 void *p; 439 void *p;
468 440
469 if (!efi_is_native())
470 return;
471
472 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { 441 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
473 efi_memory_desc_t *md = p; 442 efi_memory_desc_t *md = p;
474 unsigned long long start = md->phys_addr; 443 unsigned long long start = md->phys_addr;
@@ -583,45 +552,82 @@ static int __init efi_systab_init(void *phys)
583 return -EINVAL; 552 return -EINVAL;
584 } 553 }
585 if ((efi.systab->hdr.revision >> 16) == 0) 554 if ((efi.systab->hdr.revision >> 16) == 0)
586 pr_err("Warning: System table version " 555 pr_err("Warning: System table version %d.%02d, expected 1.00 or greater!\n",
587 "%d.%02d, expected 1.00 or greater!\n",
588 efi.systab->hdr.revision >> 16, 556 efi.systab->hdr.revision >> 16,
589 efi.systab->hdr.revision & 0xffff); 557 efi.systab->hdr.revision & 0xffff);
590 558
559 set_bit(EFI_SYSTEM_TABLES, &efi.flags);
560
591 return 0; 561 return 0;
592} 562}
593 563
594static int __init efi_runtime_init(void) 564static int __init efi_runtime_init32(void)
595{ 565{
596 efi_runtime_services_t *runtime; 566 efi_runtime_services_32_t *runtime;
567
568 runtime = early_ioremap((unsigned long)efi.systab->runtime,
569 sizeof(efi_runtime_services_32_t));
570 if (!runtime) {
571 pr_err("Could not map the runtime service table!\n");
572 return -ENOMEM;
573 }
597 574
598 /* 575 /*
599 * Check out the runtime services table. We need to map 576 * We will only need *early* access to the following two
600 * the runtime services table so that we can grab the physical 577 * EFI runtime services before set_virtual_address_map
601 * address of several of the EFI runtime functions, needed to 578 * is invoked.
602 * set the firmware into virtual mode.
603 */ 579 */
580 efi_phys.set_virtual_address_map =
581 (efi_set_virtual_address_map_t *)
582 (unsigned long)runtime->set_virtual_address_map;
583 early_iounmap(runtime, sizeof(efi_runtime_services_32_t));
584
585 return 0;
586}
587
588static int __init efi_runtime_init64(void)
589{
590 efi_runtime_services_64_t *runtime;
591
604 runtime = early_ioremap((unsigned long)efi.systab->runtime, 592 runtime = early_ioremap((unsigned long)efi.systab->runtime,
605 sizeof(efi_runtime_services_t)); 593 sizeof(efi_runtime_services_64_t));
606 if (!runtime) { 594 if (!runtime) {
607 pr_err("Could not map the runtime service table!\n"); 595 pr_err("Could not map the runtime service table!\n");
608 return -ENOMEM; 596 return -ENOMEM;
609 } 597 }
598
610 /* 599 /*
611 * We will only need *early* access to the following 600 * We will only need *early* access to the following two
612 * two EFI runtime services before set_virtual_address_map 601 * EFI runtime services before set_virtual_address_map
613 * is invoked. 602 * is invoked.
614 */ 603 */
615 efi_phys.get_time = (efi_get_time_t *)runtime->get_time;
616 efi_phys.set_virtual_address_map = 604 efi_phys.set_virtual_address_map =
617 (efi_set_virtual_address_map_t *) 605 (efi_set_virtual_address_map_t *)
618 runtime->set_virtual_address_map; 606 (unsigned long)runtime->set_virtual_address_map;
607 early_iounmap(runtime, sizeof(efi_runtime_services_64_t));
608
609 return 0;
610}
611
612static int __init efi_runtime_init(void)
613{
614 int rv;
615
619 /* 616 /*
620 * Make efi_get_time can be called before entering 617 * Check out the runtime services table. We need to map
621 * virtual mode. 618 * the runtime services table so that we can grab the physical
619 * address of several of the EFI runtime functions, needed to
620 * set the firmware into virtual mode.
622 */ 621 */
623 efi.get_time = phys_efi_get_time; 622 if (efi_enabled(EFI_64BIT))
624 early_iounmap(runtime, sizeof(efi_runtime_services_t)); 623 rv = efi_runtime_init64();
624 else
625 rv = efi_runtime_init32();
626
627 if (rv)
628 return rv;
629
630 set_bit(EFI_RUNTIME_SERVICES, &efi.flags);
625 631
626 return 0; 632 return 0;
627} 633}
@@ -640,6 +646,8 @@ static int __init efi_memmap_init(void)
640 if (add_efi_memmap) 646 if (add_efi_memmap)
641 do_add_efi_memmap(); 647 do_add_efi_memmap();
642 648
649 set_bit(EFI_MEMMAP, &efi.flags);
650
643 return 0; 651 return 0;
644} 652}
645 653
@@ -722,7 +730,7 @@ void __init efi_init(void)
722 if (efi_systab_init(efi_phys.systab)) 730 if (efi_systab_init(efi_phys.systab))
723 return; 731 return;
724 732
725 set_bit(EFI_SYSTEM_TABLES, &x86_efi_facility); 733 set_bit(EFI_SYSTEM_TABLES, &efi.flags);
726 734
727 efi.config_table = (unsigned long)efi.systab->tables; 735 efi.config_table = (unsigned long)efi.systab->tables;
728 efi.fw_vendor = (unsigned long)efi.systab->fw_vendor; 736 efi.fw_vendor = (unsigned long)efi.systab->fw_vendor;
@@ -750,24 +758,21 @@ void __init efi_init(void)
750 if (efi_config_init(arch_tables)) 758 if (efi_config_init(arch_tables))
751 return; 759 return;
752 760
753 set_bit(EFI_CONFIG_TABLES, &x86_efi_facility);
754
755 /* 761 /*
756 * Note: We currently don't support runtime services on an EFI 762 * Note: We currently don't support runtime services on an EFI
757 * that doesn't match the kernel 32/64-bit mode. 763 * that doesn't match the kernel 32/64-bit mode.
758 */ 764 */
759 765
760 if (!efi_is_native()) 766 if (!efi_runtime_supported())
761 pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n"); 767 pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n");
762 else { 768 else {
763 if (disable_runtime || efi_runtime_init()) 769 if (disable_runtime || efi_runtime_init())
764 return; 770 return;
765 set_bit(EFI_RUNTIME_SERVICES, &x86_efi_facility);
766 } 771 }
767 if (efi_memmap_init()) 772 if (efi_memmap_init())
768 return; 773 return;
769 774
770 set_bit(EFI_MEMMAP, &x86_efi_facility); 775 set_bit(EFI_MEMMAP, &efi.flags);
771 776
772 print_efi_memmap(); 777 print_efi_memmap();
773} 778}
@@ -792,7 +797,7 @@ void __init efi_set_executable(efi_memory_desc_t *md, bool executable)
792 set_memory_nx(addr, npages); 797 set_memory_nx(addr, npages);
793} 798}
794 799
795static void __init runtime_code_page_mkexec(void) 800void __init runtime_code_page_mkexec(void)
796{ 801{
797 efi_memory_desc_t *md; 802 efi_memory_desc_t *md;
798 void *p; 803 void *p;
@@ -844,6 +849,22 @@ void __init old_map_region(efi_memory_desc_t *md)
844 (unsigned long long)md->phys_addr); 849 (unsigned long long)md->phys_addr);
845} 850}
846 851
852static void native_runtime_setup(void)
853{
854 efi.get_time = virt_efi_get_time;
855 efi.set_time = virt_efi_set_time;
856 efi.get_wakeup_time = virt_efi_get_wakeup_time;
857 efi.set_wakeup_time = virt_efi_set_wakeup_time;
858 efi.get_variable = virt_efi_get_variable;
859 efi.get_next_variable = virt_efi_get_next_variable;
860 efi.set_variable = virt_efi_set_variable;
861 efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
862 efi.reset_system = virt_efi_reset_system;
863 efi.query_variable_info = virt_efi_query_variable_info;
864 efi.update_capsule = virt_efi_update_capsule;
865 efi.query_capsule_caps = virt_efi_query_capsule_caps;
866}
867
847/* Merge contiguous regions of the same type and attribute */ 868/* Merge contiguous regions of the same type and attribute */
848static void __init efi_merge_regions(void) 869static void __init efi_merge_regions(void)
849{ 870{
@@ -891,8 +912,9 @@ static void __init get_systab_virt_addr(efi_memory_desc_t *md)
891 } 912 }
892} 913}
893 914
894static int __init save_runtime_map(void) 915static void __init save_runtime_map(void)
895{ 916{
917#ifdef CONFIG_KEXEC
896 efi_memory_desc_t *md; 918 efi_memory_desc_t *md;
897 void *tmp, *p, *q = NULL; 919 void *tmp, *p, *q = NULL;
898 int count = 0; 920 int count = 0;
@@ -914,38 +936,44 @@ static int __init save_runtime_map(void)
914 } 936 }
915 937
916 efi_runtime_map_setup(q, count, memmap.desc_size); 938 efi_runtime_map_setup(q, count, memmap.desc_size);
939 return;
917 940
918 return 0;
919out: 941out:
920 kfree(q); 942 kfree(q);
921 return -ENOMEM; 943 pr_err("Error saving runtime map, efi runtime on kexec non-functional!!\n");
944#endif
922} 945}
923 946
924/* 947static void *realloc_pages(void *old_memmap, int old_shift)
925 * Map efi regions which were passed via setup_data. The virt_addr is a fixed
926 * addr which was used in first kernel of a kexec boot.
927 */
928static void __init efi_map_regions_fixed(void)
929{ 948{
930 void *p; 949 void *ret;
931 efi_memory_desc_t *md;
932 950
933 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { 951 ret = (void *)__get_free_pages(GFP_KERNEL, old_shift + 1);
934 md = p; 952 if (!ret)
935 efi_map_region_fixed(md); /* FIXME: add error handling */ 953 goto out;
936 get_systab_virt_addr(md); 954
937 } 955 /*
956 * A first-time allocation doesn't have anything to copy.
957 */
958 if (!old_memmap)
959 return ret;
938 960
961 memcpy(ret, old_memmap, PAGE_SIZE << old_shift);
962
963out:
964 free_pages((unsigned long)old_memmap, old_shift);
965 return ret;
939} 966}
940 967
941/* 968/*
942 * Map efi memory ranges for runtime serivce and update new_memmap with virtual 969 * Map the efi memory ranges of the runtime services and update new_mmap with
943 * addresses. 970 * virtual addresses.
944 */ 971 */
945static void * __init efi_map_regions(int *count) 972static void * __init efi_map_regions(int *count, int *pg_shift)
946{ 973{
974 void *p, *new_memmap = NULL;
975 unsigned long left = 0;
947 efi_memory_desc_t *md; 976 efi_memory_desc_t *md;
948 void *p, *tmp, *new_memmap = NULL;
949 977
950 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { 978 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
951 md = p; 979 md = p;
@@ -960,20 +988,80 @@ static void * __init efi_map_regions(int *count)
960 efi_map_region(md); 988 efi_map_region(md);
961 get_systab_virt_addr(md); 989 get_systab_virt_addr(md);
962 990
963 tmp = krealloc(new_memmap, (*count + 1) * memmap.desc_size, 991 if (left < memmap.desc_size) {
964 GFP_KERNEL); 992 new_memmap = realloc_pages(new_memmap, *pg_shift);
965 if (!tmp) 993 if (!new_memmap)
966 goto out; 994 return NULL;
967 new_memmap = tmp; 995
996 left += PAGE_SIZE << *pg_shift;
997 (*pg_shift)++;
998 }
999
968 memcpy(new_memmap + (*count * memmap.desc_size), md, 1000 memcpy(new_memmap + (*count * memmap.desc_size), md,
969 memmap.desc_size); 1001 memmap.desc_size);
1002
1003 left -= memmap.desc_size;
970 (*count)++; 1004 (*count)++;
971 } 1005 }
972 1006
973 return new_memmap; 1007 return new_memmap;
974out: 1008}
975 kfree(new_memmap); 1009
976 return NULL; 1010static void __init kexec_enter_virtual_mode(void)
1011{
1012#ifdef CONFIG_KEXEC
1013 efi_memory_desc_t *md;
1014 void *p;
1015
1016 efi.systab = NULL;
1017
1018 /*
1019 * We don't do virtual mode, since we don't do runtime services, on
1020 * non-native EFI
1021 */
1022 if (!efi_is_native()) {
1023 efi_unmap_memmap();
1024 return;
1025 }
1026
1027 /*
1028 * Map efi regions which were passed via setup_data. The virt_addr is a
1029 * fixed addr which was used in first kernel of a kexec boot.
1030 */
1031 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
1032 md = p;
1033 efi_map_region_fixed(md); /* FIXME: add error handling */
1034 get_systab_virt_addr(md);
1035 }
1036
1037 save_runtime_map();
1038
1039 BUG_ON(!efi.systab);
1040
1041 efi_sync_low_kernel_mappings();
1042
1043 /*
1044 * Now that EFI is in virtual mode, update the function
1045 * pointers in the runtime service table to the new virtual addresses.
1046 *
1047 * Call EFI services through wrapper functions.
1048 */
1049 efi.runtime_version = efi_systab.hdr.revision;
1050
1051 native_runtime_setup();
1052
1053 efi.set_virtual_address_map = NULL;
1054
1055 if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX))
1056 runtime_code_page_mkexec();
1057
1058 /* clean DUMMY object */
1059 efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID,
1060 EFI_VARIABLE_NON_VOLATILE |
1061 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1062 EFI_VARIABLE_RUNTIME_ACCESS,
1063 0, NULL);
1064#endif
977} 1065}
978 1066
979/* 1067/*
@@ -995,57 +1083,53 @@ out:
995 * 1083 *
996 * Specially for kexec boot, efi runtime maps in previous kernel should 1084 * Specially for kexec boot, efi runtime maps in previous kernel should
997 * be passed in via setup_data. In that case runtime ranges will be mapped 1085 * be passed in via setup_data. In that case runtime ranges will be mapped
998 * to the same virtual addresses as the first kernel. 1086 * to the same virtual addresses as the first kernel, see
1087 * kexec_enter_virtual_mode().
999 */ 1088 */
1000void __init efi_enter_virtual_mode(void) 1089static void __init __efi_enter_virtual_mode(void)
1001{ 1090{
1002 efi_status_t status; 1091 int count = 0, pg_shift = 0;
1003 void *new_memmap = NULL; 1092 void *new_memmap = NULL;
1004 int err, count = 0; 1093 efi_status_t status;
1005 1094
1006 efi.systab = NULL; 1095 efi.systab = NULL;
1007 1096
1008 /* 1097 efi_merge_regions();
1009 * We don't do virtual mode, since we don't do runtime services, on 1098 new_memmap = efi_map_regions(&count, &pg_shift);
1010 * non-native EFI 1099 if (!new_memmap) {
1011 */ 1100 pr_err("Error reallocating memory, EFI runtime non-functional!\n");
1012 if (!efi_is_native()) {
1013 efi_unmap_memmap();
1014 return; 1101 return;
1015 } 1102 }
1016 1103
1017 if (efi_setup) { 1104 save_runtime_map();
1018 efi_map_regions_fixed();
1019 } else {
1020 efi_merge_regions();
1021 new_memmap = efi_map_regions(&count);
1022 if (!new_memmap) {
1023 pr_err("Error reallocating memory, EFI runtime non-functional!\n");
1024 return;
1025 }
1026 }
1027
1028 err = save_runtime_map();
1029 if (err)
1030 pr_err("Error saving runtime map, efi runtime on kexec non-functional!!\n");
1031 1105
1032 BUG_ON(!efi.systab); 1106 BUG_ON(!efi.systab);
1033 1107
1034 efi_setup_page_tables(); 1108 if (efi_setup_page_tables(__pa(new_memmap), 1 << pg_shift))
1109 return;
1110
1035 efi_sync_low_kernel_mappings(); 1111 efi_sync_low_kernel_mappings();
1112 efi_dump_pagetable();
1036 1113
1037 if (!efi_setup) { 1114 if (efi_is_native()) {
1038 status = phys_efi_set_virtual_address_map( 1115 status = phys_efi_set_virtual_address_map(
1039 memmap.desc_size * count, 1116 memmap.desc_size * count,
1040 memmap.desc_size, 1117 memmap.desc_size,
1041 memmap.desc_version, 1118 memmap.desc_version,
1042 (efi_memory_desc_t *)__pa(new_memmap)); 1119 (efi_memory_desc_t *)__pa(new_memmap));
1043 1120 } else {
1044 if (status != EFI_SUCCESS) { 1121 status = efi_thunk_set_virtual_address_map(
1045 pr_alert("Unable to switch EFI into virtual mode (status=%lx)!\n", 1122 efi_phys.set_virtual_address_map,
1046 status); 1123 memmap.desc_size * count,
1047 panic("EFI call to SetVirtualAddressMap() failed!"); 1124 memmap.desc_size,
1048 } 1125 memmap.desc_version,
1126 (efi_memory_desc_t *)__pa(new_memmap));
1127 }
1128
1129 if (status != EFI_SUCCESS) {
1130 pr_alert("Unable to switch EFI into virtual mode (status=%lx)!\n",
1131 status);
1132 panic("EFI call to SetVirtualAddressMap() failed!");
1049 } 1133 }
1050 1134
1051 /* 1135 /*
@@ -1055,24 +1139,43 @@ void __init efi_enter_virtual_mode(void)
1055 * Call EFI services through wrapper functions. 1139 * Call EFI services through wrapper functions.
1056 */ 1140 */
1057 efi.runtime_version = efi_systab.hdr.revision; 1141 efi.runtime_version = efi_systab.hdr.revision;
1058 efi.get_time = virt_efi_get_time; 1142
1059 efi.set_time = virt_efi_set_time; 1143 if (efi_is_native())
1060 efi.get_wakeup_time = virt_efi_get_wakeup_time; 1144 native_runtime_setup();
1061 efi.set_wakeup_time = virt_efi_set_wakeup_time; 1145 else
1062 efi.get_variable = virt_efi_get_variable; 1146 efi_thunk_runtime_setup();
1063 efi.get_next_variable = virt_efi_get_next_variable; 1147
1064 efi.set_variable = virt_efi_set_variable;
1065 efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
1066 efi.reset_system = virt_efi_reset_system;
1067 efi.set_virtual_address_map = NULL; 1148 efi.set_virtual_address_map = NULL;
1068 efi.query_variable_info = virt_efi_query_variable_info;
1069 efi.update_capsule = virt_efi_update_capsule;
1070 efi.query_capsule_caps = virt_efi_query_capsule_caps;
1071 1149
1072 if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX)) 1150 efi_runtime_mkexec();
1073 runtime_code_page_mkexec();
1074 1151
1075 kfree(new_memmap); 1152 /*
1153 * We mapped the descriptor array into the EFI pagetable above but we're
1154 * not unmapping it here. Here's why:
1155 *
1156 * We're copying select PGDs from the kernel page table to the EFI page
1157 * table and when we do so and make changes to those PGDs like unmapping
1158 * stuff from them, those changes appear in the kernel page table and we
1159 * go boom.
1160 *
1161 * From setup_real_mode():
1162 *
1163 * ...
1164 * trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
1165 *
1166 * In this particular case, our allocation is in PGD 0 of the EFI page
1167 * table but we've copied that PGD from PGD[272] of the EFI page table:
1168 *
1169 * pgd_index(__PAGE_OFFSET = 0xffff880000000000) = 272
1170 *
1171 * where the direct memory mapping in kernel space is.
1172 *
1173 * new_memmap's VA comes from that direct mapping and thus clearing it,
1174 * it would get cleared in the kernel page table too.
1175 *
1176 * efi_cleanup_page_tables(__pa(new_memmap), 1 << pg_shift);
1177 */
1178 free_pages((unsigned long)new_memmap, pg_shift);
1076 1179
1077 /* clean DUMMY object */ 1180 /* clean DUMMY object */
1078 efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, 1181 efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID,
@@ -1082,6 +1185,14 @@ void __init efi_enter_virtual_mode(void)
1082 0, NULL); 1185 0, NULL);
1083} 1186}
1084 1187
1188void __init efi_enter_virtual_mode(void)
1189{
1190 if (efi_setup)
1191 kexec_enter_virtual_mode();
1192 else
1193 __efi_enter_virtual_mode();
1194}
1195
1085/* 1196/*
1086 * Convenience functions to obtain memory types and attributes 1197 * Convenience functions to obtain memory types and attributes
1087 */ 1198 */
@@ -1119,9 +1230,8 @@ u64 efi_mem_attributes(unsigned long phys_addr)
1119} 1230}
1120 1231
1121/* 1232/*
1122 * Some firmware has serious problems when using more than 50% of the EFI 1233 * Some firmware implementations refuse to boot if there's insufficient space
1123 * variable store, i.e. it triggers bugs that can brick machines. Ensure that 1234 * in the variable store. Ensure that we never use more than a safe limit.
1124 * we never use more than this safe limit.
1125 * 1235 *
1126 * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable 1236 * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable
1127 * store. 1237 * store.
@@ -1140,10 +1250,9 @@ efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)
1140 return status; 1250 return status;
1141 1251
1142 /* 1252 /*
1143 * Some firmware implementations refuse to boot if there's insufficient 1253 * We account for that by refusing the write if permitting it would
1144 * space in the variable store. We account for that by refusing the 1254 * reduce the available space to under 5KB. This figure was provided by
1145 * write if permitting it would reduce the available space to under 1255 * Samsung, so should be safe.
1146 * 5KB. This figure was provided by Samsung, so should be safe.
1147 */ 1256 */
1148 if ((remaining_size - size < EFI_MIN_RESERVE) && 1257 if ((remaining_size - size < EFI_MIN_RESERVE) &&
1149 !efi_no_storage_paranoia) { 1258 !efi_no_storage_paranoia) {
@@ -1206,8 +1315,27 @@ static int __init parse_efi_cmdline(char *str)
1206 str++; 1315 str++;
1207 1316
1208 if (!strncmp(str, "old_map", 7)) 1317 if (!strncmp(str, "old_map", 7))
1209 set_bit(EFI_OLD_MEMMAP, &x86_efi_facility); 1318 set_bit(EFI_OLD_MEMMAP, &efi.flags);
1210 1319
1211 return 0; 1320 return 0;
1212} 1321}
1213early_param("efi", parse_efi_cmdline); 1322early_param("efi", parse_efi_cmdline);
1323
1324void __init efi_apply_memmap_quirks(void)
1325{
1326 /*
1327 * Once setup is done earlier, unmap the EFI memory map on mismatched
1328 * firmware/kernel architectures since there is no support for runtime
1329 * services.
1330 */
1331 if (!efi_runtime_supported()) {
1332 pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n");
1333 efi_unmap_memmap();
1334 }
1335
1336 /*
1337 * UV doesn't support the new EFI pagetable mapping yet.
1338 */
1339 if (is_uv_system())
1340 set_bit(EFI_OLD_MEMMAP, &efi.flags);
1341}
diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
index 249b183cf417..9ee3491e31fb 100644
--- a/arch/x86/platform/efi/efi_32.c
+++ b/arch/x86/platform/efi/efi_32.c
@@ -40,7 +40,12 @@
40static unsigned long efi_rt_eflags; 40static unsigned long efi_rt_eflags;
41 41
42void efi_sync_low_kernel_mappings(void) {} 42void efi_sync_low_kernel_mappings(void) {}
43void efi_setup_page_tables(void) {} 43void __init efi_dump_pagetable(void) {}
44int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
45{
46 return 0;
47}
48void efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages) {}
44 49
45void __init efi_map_region(efi_memory_desc_t *md) 50void __init efi_map_region(efi_memory_desc_t *md)
46{ 51{
@@ -77,3 +82,9 @@ void efi_call_phys_epilog(void)
77 82
78 local_irq_restore(efi_rt_eflags); 83 local_irq_restore(efi_rt_eflags);
79} 84}
85
86void __init efi_runtime_mkexec(void)
87{
88 if (__supported_pte_mask & _PAGE_NX)
89 runtime_code_page_mkexec();
90}
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index 6284f158a47d..290d397e1dd9 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -39,6 +39,7 @@
39#include <asm/cacheflush.h> 39#include <asm/cacheflush.h>
40#include <asm/fixmap.h> 40#include <asm/fixmap.h>
41#include <asm/realmode.h> 41#include <asm/realmode.h>
42#include <asm/time.h>
42 43
43static pgd_t *save_pgd __initdata; 44static pgd_t *save_pgd __initdata;
44static unsigned long efi_flags __initdata; 45static unsigned long efi_flags __initdata;
@@ -58,7 +59,8 @@ struct efi_scratch {
58 u64 prev_cr3; 59 u64 prev_cr3;
59 pgd_t *efi_pgt; 60 pgd_t *efi_pgt;
60 bool use_pgd; 61 bool use_pgd;
61}; 62 u64 phys_stack;
63} __packed;
62 64
63static void __init early_code_mapping_set_exec(int executable) 65static void __init early_code_mapping_set_exec(int executable)
64{ 66{
@@ -137,12 +139,64 @@ void efi_sync_low_kernel_mappings(void)
137 sizeof(pgd_t) * num_pgds); 139 sizeof(pgd_t) * num_pgds);
138} 140}
139 141
140void efi_setup_page_tables(void) 142int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
141{ 143{
144 unsigned long text;
145 struct page *page;
146 unsigned npages;
147 pgd_t *pgd;
148
149 if (efi_enabled(EFI_OLD_MEMMAP))
150 return 0;
151
142 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd; 152 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
153 pgd = __va(efi_scratch.efi_pgt);
143 154
144 if (!efi_enabled(EFI_OLD_MEMMAP)) 155 /*
145 efi_scratch.use_pgd = true; 156 * It can happen that the physical address of new_memmap lands in memory
157 * which is not mapped in the EFI page table. Therefore we need to go
158 * and ident-map those pages containing the map before calling
159 * phys_efi_set_virtual_address_map().
160 */
161 if (kernel_map_pages_in_pgd(pgd, pa_memmap, pa_memmap, num_pages, _PAGE_NX)) {
162 pr_err("Error ident-mapping new memmap (0x%lx)!\n", pa_memmap);
163 return 1;
164 }
165
166 efi_scratch.use_pgd = true;
167
168 /*
169 * When making calls to the firmware everything needs to be 1:1
170 * mapped and addressable with 32-bit pointers. Map the kernel
171 * text and allocate a new stack because we can't rely on the
172 * stack pointer being < 4GB.
173 */
174 if (!IS_ENABLED(CONFIG_EFI_MIXED))
175 return 0;
176
177 page = alloc_page(GFP_KERNEL|__GFP_DMA32);
178 if (!page)
179 panic("Unable to allocate EFI runtime stack < 4GB\n");
180
181 efi_scratch.phys_stack = virt_to_phys(page_address(page));
182 efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */
183
184 npages = (_end - _text) >> PAGE_SHIFT;
185 text = __pa(_text);
186
187 if (kernel_map_pages_in_pgd(pgd, text >> PAGE_SHIFT, text, npages, 0)) {
188 pr_err("Failed to map kernel text 1:1\n");
189 return 1;
190 }
191
192 return 0;
193}
194
195void efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages)
196{
197 pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
198
199 kernel_unmap_pages_in_pgd(pgd, pa_memmap, num_pages);
146} 200}
147 201
148static void __init __map_region(efi_memory_desc_t *md, u64 va) 202static void __init __map_region(efi_memory_desc_t *md, u64 va)
@@ -173,6 +227,16 @@ void __init efi_map_region(efi_memory_desc_t *md)
173 */ 227 */
174 __map_region(md, md->phys_addr); 228 __map_region(md, md->phys_addr);
175 229
230 /*
231 * Enforce the 1:1 mapping as the default virtual address when
232 * booting in EFI mixed mode, because even though we may be
233 * running a 64-bit kernel, the firmware may only be 32-bit.
234 */
235 if (!efi_is_native () && IS_ENABLED(CONFIG_EFI_MIXED)) {
236 md->virt_addr = md->phys_addr;
237 return;
238 }
239
176 efi_va -= size; 240 efi_va -= size;
177 241
178 /* Is PA 2M-aligned? */ 242 /* Is PA 2M-aligned? */
@@ -233,3 +297,308 @@ void __init parse_efi_setup(u64 phys_addr, u32 data_len)
233{ 297{
234 efi_setup = phys_addr + sizeof(struct setup_data); 298 efi_setup = phys_addr + sizeof(struct setup_data);
235} 299}
300
301void __init efi_runtime_mkexec(void)
302{
303 if (!efi_enabled(EFI_OLD_MEMMAP))
304 return;
305
306 if (__supported_pte_mask & _PAGE_NX)
307 runtime_code_page_mkexec();
308}
309
310void __init efi_dump_pagetable(void)
311{
312#ifdef CONFIG_EFI_PGT_DUMP
313 pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
314
315 ptdump_walk_pgd_level(NULL, pgd);
316#endif
317}
318
319#ifdef CONFIG_EFI_MIXED
320extern efi_status_t efi64_thunk(u32, ...);
321
322#define runtime_service32(func) \
323({ \
324 u32 table = (u32)(unsigned long)efi.systab; \
325 u32 *rt, *___f; \
326 \
327 rt = (u32 *)(table + offsetof(efi_system_table_32_t, runtime)); \
328 ___f = (u32 *)(*rt + offsetof(efi_runtime_services_32_t, func)); \
329 *___f; \
330})
331
332/*
333 * Switch to the EFI page tables early so that we can access the 1:1
334 * runtime services mappings which are not mapped in any other page
335 * tables. This function must be called before runtime_service32().
336 *
337 * Also, disable interrupts because the IDT points to 64-bit handlers,
338 * which aren't going to function correctly when we switch to 32-bit.
339 */
340#define efi_thunk(f, ...) \
341({ \
342 efi_status_t __s; \
343 unsigned long flags; \
344 u32 func; \
345 \
346 efi_sync_low_kernel_mappings(); \
347 local_irq_save(flags); \
348 \
349 efi_scratch.prev_cr3 = read_cr3(); \
350 write_cr3((unsigned long)efi_scratch.efi_pgt); \
351 __flush_tlb_all(); \
352 \
353 func = runtime_service32(f); \
354 __s = efi64_thunk(func, __VA_ARGS__); \
355 \
356 write_cr3(efi_scratch.prev_cr3); \
357 __flush_tlb_all(); \
358 local_irq_restore(flags); \
359 \
360 __s; \
361})
362
363efi_status_t efi_thunk_set_virtual_address_map(
364 void *phys_set_virtual_address_map,
365 unsigned long memory_map_size,
366 unsigned long descriptor_size,
367 u32 descriptor_version,
368 efi_memory_desc_t *virtual_map)
369{
370 efi_status_t status;
371 unsigned long flags;
372 u32 func;
373
374 efi_sync_low_kernel_mappings();
375 local_irq_save(flags);
376
377 efi_scratch.prev_cr3 = read_cr3();
378 write_cr3((unsigned long)efi_scratch.efi_pgt);
379 __flush_tlb_all();
380
381 func = (u32)(unsigned long)phys_set_virtual_address_map;
382 status = efi64_thunk(func, memory_map_size, descriptor_size,
383 descriptor_version, virtual_map);
384
385 write_cr3(efi_scratch.prev_cr3);
386 __flush_tlb_all();
387 local_irq_restore(flags);
388
389 return status;
390}
391
392static efi_status_t efi_thunk_get_time(efi_time_t *tm, efi_time_cap_t *tc)
393{
394 efi_status_t status;
395 u32 phys_tm, phys_tc;
396
397 spin_lock(&rtc_lock);
398
399 phys_tm = virt_to_phys(tm);
400 phys_tc = virt_to_phys(tc);
401
402 status = efi_thunk(get_time, phys_tm, phys_tc);
403
404 spin_unlock(&rtc_lock);
405
406 return status;
407}
408
409static efi_status_t efi_thunk_set_time(efi_time_t *tm)
410{
411 efi_status_t status;
412 u32 phys_tm;
413
414 spin_lock(&rtc_lock);
415
416 phys_tm = virt_to_phys(tm);
417
418 status = efi_thunk(set_time, phys_tm);
419
420 spin_unlock(&rtc_lock);
421
422 return status;
423}
424
425static efi_status_t
426efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
427 efi_time_t *tm)
428{
429 efi_status_t status;
430 u32 phys_enabled, phys_pending, phys_tm;
431
432 spin_lock(&rtc_lock);
433
434 phys_enabled = virt_to_phys(enabled);
435 phys_pending = virt_to_phys(pending);
436 phys_tm = virt_to_phys(tm);
437
438 status = efi_thunk(get_wakeup_time, phys_enabled,
439 phys_pending, phys_tm);
440
441 spin_unlock(&rtc_lock);
442
443 return status;
444}
445
446static efi_status_t
447efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
448{
449 efi_status_t status;
450 u32 phys_tm;
451
452 spin_lock(&rtc_lock);
453
454 phys_tm = virt_to_phys(tm);
455
456 status = efi_thunk(set_wakeup_time, enabled, phys_tm);
457
458 spin_unlock(&rtc_lock);
459
460 return status;
461}
462
463
464static efi_status_t
465efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
466 u32 *attr, unsigned long *data_size, void *data)
467{
468 efi_status_t status;
469 u32 phys_name, phys_vendor, phys_attr;
470 u32 phys_data_size, phys_data;
471
472 phys_data_size = virt_to_phys(data_size);
473 phys_vendor = virt_to_phys(vendor);
474 phys_name = virt_to_phys(name);
475 phys_attr = virt_to_phys(attr);
476 phys_data = virt_to_phys(data);
477
478 status = efi_thunk(get_variable, phys_name, phys_vendor,
479 phys_attr, phys_data_size, phys_data);
480
481 return status;
482}
483
484static efi_status_t
485efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor,
486 u32 attr, unsigned long data_size, void *data)
487{
488 u32 phys_name, phys_vendor, phys_data;
489 efi_status_t status;
490
491 phys_name = virt_to_phys(name);
492 phys_vendor = virt_to_phys(vendor);
493 phys_data = virt_to_phys(data);
494
495 /* If data_size is > sizeof(u32) we've got problems */
496 status = efi_thunk(set_variable, phys_name, phys_vendor,
497 attr, data_size, phys_data);
498
499 return status;
500}
501
502static efi_status_t
503efi_thunk_get_next_variable(unsigned long *name_size,
504 efi_char16_t *name,
505 efi_guid_t *vendor)
506{
507 efi_status_t status;
508 u32 phys_name_size, phys_name, phys_vendor;
509
510 phys_name_size = virt_to_phys(name_size);
511 phys_vendor = virt_to_phys(vendor);
512 phys_name = virt_to_phys(name);
513
514 status = efi_thunk(get_next_variable, phys_name_size,
515 phys_name, phys_vendor);
516
517 return status;
518}
519
520static efi_status_t
521efi_thunk_get_next_high_mono_count(u32 *count)
522{
523 efi_status_t status;
524 u32 phys_count;
525
526 phys_count = virt_to_phys(count);
527 status = efi_thunk(get_next_high_mono_count, phys_count);
528
529 return status;
530}
531
532static void
533efi_thunk_reset_system(int reset_type, efi_status_t status,
534 unsigned long data_size, efi_char16_t *data)
535{
536 u32 phys_data;
537
538 phys_data = virt_to_phys(data);
539
540 efi_thunk(reset_system, reset_type, status, data_size, phys_data);
541}
542
543static efi_status_t
544efi_thunk_update_capsule(efi_capsule_header_t **capsules,
545 unsigned long count, unsigned long sg_list)
546{
547 /*
548 * To properly support this function we would need to repackage
549 * 'capsules' because the firmware doesn't understand 64-bit
550 * pointers.
551 */
552 return EFI_UNSUPPORTED;
553}
554
555static efi_status_t
556efi_thunk_query_variable_info(u32 attr, u64 *storage_space,
557 u64 *remaining_space,
558 u64 *max_variable_size)
559{
560 efi_status_t status;
561 u32 phys_storage, phys_remaining, phys_max;
562
563 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
564 return EFI_UNSUPPORTED;
565
566 phys_storage = virt_to_phys(storage_space);
567 phys_remaining = virt_to_phys(remaining_space);
568 phys_max = virt_to_phys(max_variable_size);
569
570 status = efi_thunk(query_variable_info, attr, phys_storage,
571 phys_remaining, phys_max);
572
573 return status;
574}
575
576static efi_status_t
577efi_thunk_query_capsule_caps(efi_capsule_header_t **capsules,
578 unsigned long count, u64 *max_size,
579 int *reset_type)
580{
581 /*
582 * To properly support this function we would need to repackage
583 * 'capsules' because the firmware doesn't understand 64-bit
584 * pointers.
585 */
586 return EFI_UNSUPPORTED;
587}
588
589void efi_thunk_runtime_setup(void)
590{
591 efi.get_time = efi_thunk_get_time;
592 efi.set_time = efi_thunk_set_time;
593 efi.get_wakeup_time = efi_thunk_get_wakeup_time;
594 efi.set_wakeup_time = efi_thunk_set_wakeup_time;
595 efi.get_variable = efi_thunk_get_variable;
596 efi.get_next_variable = efi_thunk_get_next_variable;
597 efi.set_variable = efi_thunk_set_variable;
598 efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count;
599 efi.reset_system = efi_thunk_reset_system;
600 efi.query_variable_info = efi_thunk_query_variable_info;
601 efi.update_capsule = efi_thunk_update_capsule;
602 efi.query_capsule_caps = efi_thunk_query_capsule_caps;
603}
604#endif /* CONFIG_EFI_MIXED */
diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
index 88073b140298..e0984ef0374b 100644
--- a/arch/x86/platform/efi/efi_stub_64.S
+++ b/arch/x86/platform/efi/efi_stub_64.S
@@ -7,6 +7,10 @@
7 */ 7 */
8 8
9#include <linux/linkage.h> 9#include <linux/linkage.h>
10#include <asm/segment.h>
11#include <asm/msr.h>
12#include <asm/processor-flags.h>
13#include <asm/page_types.h>
10 14
11#define SAVE_XMM \ 15#define SAVE_XMM \
12 mov %rsp, %rax; \ 16 mov %rsp, %rax; \
@@ -164,7 +168,169 @@ ENTRY(efi_call6)
164 ret 168 ret
165ENDPROC(efi_call6) 169ENDPROC(efi_call6)
166 170
171#ifdef CONFIG_EFI_MIXED
172
173/*
174 * We run this function from the 1:1 mapping.
175 *
176 * This function must be invoked with a 1:1 mapped stack.
177 */
178ENTRY(__efi64_thunk)
179 movl %ds, %eax
180 push %rax
181 movl %es, %eax
182 push %rax
183 movl %ss, %eax
184 push %rax
185
186 subq $32, %rsp
187 movl %esi, 0x0(%rsp)
188 movl %edx, 0x4(%rsp)
189 movl %ecx, 0x8(%rsp)
190 movq %r8, %rsi
191 movl %esi, 0xc(%rsp)
192 movq %r9, %rsi
193 movl %esi, 0x10(%rsp)
194
195 sgdt save_gdt(%rip)
196
197 leaq 1f(%rip), %rbx
198 movq %rbx, func_rt_ptr(%rip)
199
200 /* Switch to gdt with 32-bit segments */
201 movl 64(%rsp), %eax
202 lgdt (%rax)
203
204 leaq efi_enter32(%rip), %rax
205 pushq $__KERNEL_CS
206 pushq %rax
207 lretq
208
2091: addq $32, %rsp
210
211 lgdt save_gdt(%rip)
212
213 pop %rbx
214 movl %ebx, %ss
215 pop %rbx
216 movl %ebx, %es
217 pop %rbx
218 movl %ebx, %ds
219
220 /*
221 * Convert 32-bit status code into 64-bit.
222 */
223 test %rax, %rax
224 jz 1f
225 movl %eax, %ecx
226 andl $0x0fffffff, %ecx
227 andl $0xf0000000, %eax
228 shl $32, %rax
229 or %rcx, %rax
2301:
231 ret
232ENDPROC(__efi64_thunk)
233
234ENTRY(efi_exit32)
235 movq func_rt_ptr(%rip), %rax
236 push %rax
237 mov %rdi, %rax
238 ret
239ENDPROC(efi_exit32)
240
241 .code32
242/*
243 * EFI service pointer must be in %edi.
244 *
245 * The stack should represent the 32-bit calling convention.
246 */
247ENTRY(efi_enter32)
248 movl $__KERNEL_DS, %eax
249 movl %eax, %ds
250 movl %eax, %es
251 movl %eax, %ss
252
253 /* Reload pgtables */
254 movl %cr3, %eax
255 movl %eax, %cr3
256
257 /* Disable paging */
258 movl %cr0, %eax
259 btrl $X86_CR0_PG_BIT, %eax
260 movl %eax, %cr0
261
262 /* Disable long mode via EFER */
263 movl $MSR_EFER, %ecx
264 rdmsr
265 btrl $_EFER_LME, %eax
266 wrmsr
267
268 call *%edi
269
270 /* We must preserve return value */
271 movl %eax, %edi
272
273 /*
274 * Some firmware will return with interrupts enabled. Be sure to
275 * disable them before we switch GDTs.
276 */
277 cli
278
279 movl 68(%esp), %eax
280 movl %eax, 2(%eax)
281 lgdtl (%eax)
282
283 movl %cr4, %eax
284 btsl $(X86_CR4_PAE_BIT), %eax
285 movl %eax, %cr4
286
287 movl %cr3, %eax
288 movl %eax, %cr3
289
290 movl $MSR_EFER, %ecx
291 rdmsr
292 btsl $_EFER_LME, %eax
293 wrmsr
294
295 xorl %eax, %eax
296 lldt %ax
297
298 movl 72(%esp), %eax
299 pushl $__KERNEL_CS
300 pushl %eax
301
302 /* Enable paging */
303 movl %cr0, %eax
304 btsl $X86_CR0_PG_BIT, %eax
305 movl %eax, %cr0
306 lret
307ENDPROC(efi_enter32)
308
309 .data
310 .balign 8
311 .global efi32_boot_gdt
312efi32_boot_gdt: .word 0
313 .quad 0
314
315save_gdt: .word 0
316 .quad 0
317func_rt_ptr: .quad 0
318
319 .global efi_gdt64
320efi_gdt64:
321 .word efi_gdt64_end - efi_gdt64
322 .long 0 /* Filled out by user */
323 .word 0
324 .quad 0x0000000000000000 /* NULL descriptor */
325 .quad 0x00af9a000000ffff /* __KERNEL_CS */
326 .quad 0x00cf92000000ffff /* __KERNEL_DS */
327 .quad 0x0080890000000000 /* TS descriptor */
328 .quad 0x0000000000000000 /* TS continued */
329efi_gdt64_end:
330#endif /* CONFIG_EFI_MIXED */
331
167 .data 332 .data
168ENTRY(efi_scratch) 333ENTRY(efi_scratch)
169 .fill 3,8,0 334 .fill 3,8,0
170 .byte 0 335 .byte 0
336 .quad 0
diff --git a/arch/x86/platform/efi/efi_thunk_64.S b/arch/x86/platform/efi/efi_thunk_64.S
new file mode 100644
index 000000000000..8806fa73e6e6
--- /dev/null
+++ b/arch/x86/platform/efi/efi_thunk_64.S
@@ -0,0 +1,65 @@
1/*
2 * Copyright (C) 2014 Intel Corporation; author Matt Fleming
3 */
4
5#include <linux/linkage.h>
6#include <asm/page_types.h>
7
8 .text
9 .code64
10ENTRY(efi64_thunk)
11 push %rbp
12 push %rbx
13
14 /*
15 * Switch to 1:1 mapped 32-bit stack pointer.
16 */
17 movq %rsp, efi_saved_sp(%rip)
18 movq efi_scratch+25(%rip), %rsp
19
20 /*
21 * Calculate the physical address of the kernel text.
22 */
23 movq $__START_KERNEL_map, %rax
24 subq phys_base(%rip), %rax
25
26 /*
27 * Push some physical addresses onto the stack. This is easier
28 * to do now in a code64 section while the assembler can address
29 * 64-bit values. Note that all the addresses on the stack are
30 * 32-bit.
31 */
32 subq $16, %rsp
33 leaq efi_exit32(%rip), %rbx
34 subq %rax, %rbx
35 movl %ebx, 8(%rsp)
36 leaq efi_gdt64(%rip), %rbx
37 subq %rax, %rbx
38 movl %ebx, 2(%ebx)
39 movl %ebx, 4(%rsp)
40 leaq efi_gdt32(%rip), %rbx
41 subq %rax, %rbx
42 movl %ebx, 2(%ebx)
43 movl %ebx, (%rsp)
44
45 leaq __efi64_thunk(%rip), %rbx
46 subq %rax, %rbx
47 call *%rbx
48
49 movq efi_saved_sp(%rip), %rsp
50 pop %rbx
51 pop %rbp
52 retq
53ENDPROC(efi64_thunk)
54
55 .data
56efi_gdt32:
57 .word efi_gdt32_end - efi_gdt32
58 .long 0 /* Filled out above */
59 .word 0
60 .quad 0x0000000000000000 /* NULL descriptor */
61 .quad 0x00cf9a000000ffff /* __KERNEL_CS */
62 .quad 0x00cf93000000ffff /* __KERNEL_DS */
63efi_gdt32_end:
64
65efi_saved_sp: .quad 0
diff --git a/arch/x86/platform/ts5500/ts5500.c b/arch/x86/platform/ts5500/ts5500.c
index 39febb214e8c..9471b9456f25 100644
--- a/arch/x86/platform/ts5500/ts5500.c
+++ b/arch/x86/platform/ts5500/ts5500.c
@@ -88,7 +88,7 @@ struct ts5500_sbc {
88static const struct { 88static const struct {
89 const char * const string; 89 const char * const string;
90 const ssize_t offset; 90 const ssize_t offset;
91} ts5500_signatures[] __initdata = { 91} ts5500_signatures[] __initconst = {
92 { "TS-5x00 AMD Elan", 0xb14 }, 92 { "TS-5x00 AMD Elan", 0xb14 },
93}; 93};
94 94
diff --git a/arch/x86/um/asm/barrier.h b/arch/x86/um/asm/barrier.h
index 7d01b8c56c00..cc04e67bfd05 100644
--- a/arch/x86/um/asm/barrier.h
+++ b/arch/x86/um/asm/barrier.h
@@ -40,11 +40,7 @@
40#define smp_rmb() barrier() 40#define smp_rmb() barrier()
41#endif /* CONFIG_X86_PPRO_FENCE */ 41#endif /* CONFIG_X86_PPRO_FENCE */
42 42
43#ifdef CONFIG_X86_OOSTORE
44#define smp_wmb() wmb()
45#else /* CONFIG_X86_OOSTORE */
46#define smp_wmb() barrier() 43#define smp_wmb() barrier()
47#endif /* CONFIG_X86_OOSTORE */
48 44
49#define smp_read_barrier_depends() read_barrier_depends() 45#define smp_read_barrier_depends() read_barrier_depends()
50#define set_mb(var, value) do { (void)xchg(&var, value); } while (0) 46#define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
index fd14be1d1472..9206ac7961a5 100644
--- a/arch/x86/vdso/Makefile
+++ b/arch/x86/vdso/Makefile
@@ -2,6 +2,8 @@
2# Building vDSO images for x86. 2# Building vDSO images for x86.
3# 3#
4 4
5KBUILD_CFLAGS += $(DISABLE_LTO)
6
5VDSO64-$(CONFIG_X86_64) := y 7VDSO64-$(CONFIG_X86_64) := y
6VDSOX32-$(CONFIG_X86_X32_ABI) := y 8VDSOX32-$(CONFIG_X86_X32_ABI) := y
7VDSO32-$(CONFIG_X86_32) := y 9VDSO32-$(CONFIG_X86_32) := y
@@ -35,7 +37,8 @@ export CPPFLAGS_vdso.lds += -P -C
35 37
36VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \ 38VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
37 -Wl,--no-undefined \ 39 -Wl,--no-undefined \
38 -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 40 -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \
41 $(DISABLE_LTO)
39 42
40$(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so 43$(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
41 44
@@ -127,7 +130,7 @@ vdso32.so-$(VDSO32-y) += sysenter
127vdso32-images = $(vdso32.so-y:%=vdso32-%.so) 130vdso32-images = $(vdso32.so-y:%=vdso32-%.so)
128 131
129CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds) 132CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
130VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-soname=linux-gate.so.1 133VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1
131 134
132# This makes sure the $(obj) subdirectory exists even though vdso32/ 135# This makes sure the $(obj) subdirectory exists even though vdso32/
133# is not a kbuild sub-make subdirectory. 136# is not a kbuild sub-make subdirectory.
@@ -181,7 +184,8 @@ quiet_cmd_vdso = VDSO $@
181 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \ 184 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
182 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' 185 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
183 186
184VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) 187VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
188 $(LTO_CFLAGS)
185GCOV_PROFILE := n 189GCOV_PROFILE := n
186 190
187# 191#
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index a4d7b647867f..201d09a7c46b 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1473,6 +1473,18 @@ static void xen_pvh_set_cr_flags(int cpu)
1473 * X86_CR0_TS, X86_CR0_PE, X86_CR0_ET are set by Xen for HVM guests 1473 * X86_CR0_TS, X86_CR0_PE, X86_CR0_ET are set by Xen for HVM guests
1474 * (which PVH shared codepaths), while X86_CR0_PG is for PVH. */ 1474 * (which PVH shared codepaths), while X86_CR0_PG is for PVH. */
1475 write_cr0(read_cr0() | X86_CR0_MP | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM); 1475 write_cr0(read_cr0() | X86_CR0_MP | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM);
1476
1477 if (!cpu)
1478 return;
1479 /*
1480 * For BSP, PSE PGE are set in probe_page_size_mask(), for APs
1481 * set them here. For all, OSFXSR OSXMMEXCPT are set in fpu_init.
1482 */
1483 if (cpu_has_pse)
1484 set_in_cr4(X86_CR4_PSE);
1485
1486 if (cpu_has_pge)
1487 set_in_cr4(X86_CR4_PGE);
1476} 1488}
1477 1489
1478/* 1490/*
diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c
index 8009acbe41e4..696c694986d0 100644
--- a/arch/x86/xen/p2m.c
+++ b/arch/x86/xen/p2m.c
@@ -899,6 +899,13 @@ int m2p_add_override(unsigned long mfn, struct page *page,
899 "m2p_add_override: pfn %lx not mapped", pfn)) 899 "m2p_add_override: pfn %lx not mapped", pfn))
900 return -EINVAL; 900 return -EINVAL;
901 } 901 }
902 WARN_ON(PagePrivate(page));
903 SetPagePrivate(page);
904 set_page_private(page, mfn);
905 page->index = pfn_to_mfn(pfn);
906
907 if (unlikely(!set_phys_to_machine(pfn, FOREIGN_FRAME(mfn))))
908 return -ENOMEM;
902 909
903 if (kmap_op != NULL) { 910 if (kmap_op != NULL) {
904 if (!PageHighMem(page)) { 911 if (!PageHighMem(page)) {
@@ -937,16 +944,19 @@ int m2p_add_override(unsigned long mfn, struct page *page,
937} 944}
938EXPORT_SYMBOL_GPL(m2p_add_override); 945EXPORT_SYMBOL_GPL(m2p_add_override);
939int m2p_remove_override(struct page *page, 946int m2p_remove_override(struct page *page,
940 struct gnttab_map_grant_ref *kmap_op, 947 struct gnttab_map_grant_ref *kmap_op)
941 unsigned long mfn)
942{ 948{
943 unsigned long flags; 949 unsigned long flags;
950 unsigned long mfn;
944 unsigned long pfn; 951 unsigned long pfn;
945 unsigned long uninitialized_var(address); 952 unsigned long uninitialized_var(address);
946 unsigned level; 953 unsigned level;
947 pte_t *ptep = NULL; 954 pte_t *ptep = NULL;
948 955
949 pfn = page_to_pfn(page); 956 pfn = page_to_pfn(page);
957 mfn = get_phys_to_machine(pfn);
958 if (mfn == INVALID_P2M_ENTRY || !(mfn & FOREIGN_FRAME_BIT))
959 return -EINVAL;
950 960
951 if (!PageHighMem(page)) { 961 if (!PageHighMem(page)) {
952 address = (unsigned long)__va(pfn << PAGE_SHIFT); 962 address = (unsigned long)__va(pfn << PAGE_SHIFT);
@@ -960,7 +970,10 @@ int m2p_remove_override(struct page *page,
960 spin_lock_irqsave(&m2p_override_lock, flags); 970 spin_lock_irqsave(&m2p_override_lock, flags);
961 list_del(&page->lru); 971 list_del(&page->lru);
962 spin_unlock_irqrestore(&m2p_override_lock, flags); 972 spin_unlock_irqrestore(&m2p_override_lock, flags);
973 WARN_ON(!PagePrivate(page));
974 ClearPagePrivate(page);
963 975
976 set_phys_to_machine(pfn, page->index);
964 if (kmap_op != NULL) { 977 if (kmap_op != NULL) {
965 if (!PageHighMem(page)) { 978 if (!PageHighMem(page)) {
966 struct multicall_space mcs; 979 struct multicall_space mcs;
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index ba56e11cbf77..c87ae7c6e5f9 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -20,6 +20,7 @@ config XTENSA
20 select HAVE_FUNCTION_TRACER 20 select HAVE_FUNCTION_TRACER
21 select HAVE_IRQ_TIME_ACCOUNTING 21 select HAVE_IRQ_TIME_ACCOUNTING
22 select HAVE_PERF_EVENTS 22 select HAVE_PERF_EVENTS
23 select COMMON_CLK
23 help 24 help
24 Xtensa processors are 32-bit RISC machines designed by Tensilica 25 Xtensa processors are 32-bit RISC machines designed by Tensilica
25 primarily for embedded systems. These processors are both 26 primarily for embedded systems. These processors are both
@@ -80,7 +81,6 @@ choice
80config XTENSA_VARIANT_FSF 81config XTENSA_VARIANT_FSF
81 bool "fsf - default (not generic) configuration" 82 bool "fsf - default (not generic) configuration"
82 select MMU 83 select MMU
83 select HAVE_XTENSA_GPIO32
84 84
85config XTENSA_VARIANT_DC232B 85config XTENSA_VARIANT_DC232B
86 bool "dc232b - Diamond 232L Standard Core Rev.B (LE)" 86 bool "dc232b - Diamond 232L Standard Core Rev.B (LE)"
@@ -135,7 +135,6 @@ config HAVE_SMP
135config SMP 135config SMP
136 bool "Enable Symmetric multi-processing support" 136 bool "Enable Symmetric multi-processing support"
137 depends on HAVE_SMP 137 depends on HAVE_SMP
138 select USE_GENERIC_SMP_HELPERS
139 select GENERIC_SMP_IDLE_THREAD 138 select GENERIC_SMP_IDLE_THREAD
140 help 139 help
141 Enabled SMP Software; allows more than one CPU/CORE 140 Enabled SMP Software; allows more than one CPU/CORE
diff --git a/arch/xtensa/boot/dts/xtfpga.dtsi b/arch/xtensa/boot/dts/xtfpga.dtsi
index 46b4f5eab421..e7370b11348e 100644
--- a/arch/xtensa/boot/dts/xtfpga.dtsi
+++ b/arch/xtensa/boot/dts/xtfpga.dtsi
@@ -35,6 +35,13 @@
35 interrupt-controller; 35 interrupt-controller;
36 }; 36 };
37 37
38 clocks {
39 osc: main-oscillator {
40 #clock-cells = <0>;
41 compatible = "fixed-clock";
42 };
43 };
44
38 serial0: serial@fd050020 { 45 serial0: serial@fd050020 {
39 device_type = "serial"; 46 device_type = "serial";
40 compatible = "ns16550a"; 47 compatible = "ns16550a";
@@ -42,9 +49,7 @@
42 reg = <0xfd050020 0x20>; 49 reg = <0xfd050020 0x20>;
43 reg-shift = <2>; 50 reg-shift = <2>;
44 interrupts = <0 1>; /* external irq 0 */ 51 interrupts = <0 1>; /* external irq 0 */
45 /* Filled in by platform_setup from FPGA register 52 clocks = <&osc>;
46 * clock-frequency = <100000000>;
47 */
48 }; 53 };
49 54
50 enet0: ethoc@fd030000 { 55 enet0: ethoc@fd030000 {
@@ -52,5 +57,6 @@
52 reg = <0xfd030000 0x4000 0xfd800000 0x4000>; 57 reg = <0xfd030000 0x4000 0xfd800000 0x4000>;
53 interrupts = <1 1>; /* external irq 1 */ 58 interrupts = <1 1>; /* external irq 1 */
54 local-mac-address = [00 50 c2 13 6f 00]; 59 local-mac-address = [00 50 c2 13 6f 00];
60 clocks = <&osc>;
55 }; 61 };
56}; 62};
diff --git a/arch/xtensa/include/asm/Kbuild b/arch/xtensa/include/asm/Kbuild
index 0a337e4a8370..c3d20ba6eb86 100644
--- a/arch/xtensa/include/asm/Kbuild
+++ b/arch/xtensa/include/asm/Kbuild
@@ -9,6 +9,7 @@ generic-y += errno.h
9generic-y += exec.h 9generic-y += exec.h
10generic-y += fcntl.h 10generic-y += fcntl.h
11generic-y += hardirq.h 11generic-y += hardirq.h
12generic-y += hash.h
12generic-y += ioctl.h 13generic-y += ioctl.h
13generic-y += irq_regs.h 14generic-y += irq_regs.h
14generic-y += kdebug.h 15generic-y += kdebug.h
@@ -17,7 +18,9 @@ generic-y += kvm_para.h
17generic-y += linkage.h 18generic-y += linkage.h
18generic-y += local.h 19generic-y += local.h
19generic-y += local64.h 20generic-y += local64.h
21generic-y += mcs_spinlock.h
20generic-y += percpu.h 22generic-y += percpu.h
23generic-y += preempt.h
21generic-y += resource.h 24generic-y += resource.h
22generic-y += scatterlist.h 25generic-y += scatterlist.h
23generic-y += sections.h 26generic-y += sections.h
@@ -27,5 +30,3 @@ generic-y += termios.h
27generic-y += topology.h 30generic-y += topology.h
28generic-y += trace_clock.h 31generic-y += trace_clock.h
29generic-y += xor.h 32generic-y += xor.h
30generic-y += preempt.h
31generic-y += hash.h
diff --git a/arch/xtensa/include/asm/io.h b/arch/xtensa/include/asm/io.h
index 2a042d430c25..74944207167e 100644
--- a/arch/xtensa/include/asm/io.h
+++ b/arch/xtensa/include/asm/io.h
@@ -25,7 +25,7 @@
25 25
26#ifdef CONFIG_MMU 26#ifdef CONFIG_MMU
27 27
28#if XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY && CONFIG_OF 28#if XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY && defined(CONFIG_OF)
29extern unsigned long xtensa_kio_paddr; 29extern unsigned long xtensa_kio_paddr;
30 30
31static inline unsigned long xtensa_get_kio_paddr(void) 31static inline unsigned long xtensa_get_kio_paddr(void)
diff --git a/arch/xtensa/include/asm/traps.h b/arch/xtensa/include/asm/traps.h
index 8c194f6af45e..677bfcf4ee5d 100644
--- a/arch/xtensa/include/asm/traps.h
+++ b/arch/xtensa/include/asm/traps.h
@@ -23,25 +23,37 @@ void secondary_trap_init(void);
23 23
24static inline void spill_registers(void) 24static inline void spill_registers(void)
25{ 25{
26 26#if XCHAL_NUM_AREGS > 16
27 __asm__ __volatile__ ( 27 __asm__ __volatile__ (
28 "movi a14, "__stringify((1 << PS_EXCM_BIT) | LOCKLEVEL)"\n\t" 28 " call12 1f\n"
29 "mov a12, a0\n\t" 29 " _j 2f\n"
30 "rsr a13, sar\n\t" 30 " retw\n"
31 "xsr a14, ps\n\t" 31 " .align 4\n"
32 "movi a0, _spill_registers\n\t" 32 "1:\n"
33 "rsync\n\t" 33 " _entry a1, 48\n"
34 "callx0 a0\n\t" 34 " addi a12, a0, 3\n"
35 "mov a0, a12\n\t" 35#if XCHAL_NUM_AREGS > 32
36 "wsr a13, sar\n\t" 36 " .rept (" __stringify(XCHAL_NUM_AREGS) " - 32) / 12\n"
37 "wsr a14, ps\n\t" 37 " _entry a1, 48\n"
38 : : 38 " mov a12, a0\n"
39#if defined(CONFIG_FRAME_POINTER) 39 " .endr\n"
40 : "a2", "a3", "a4", "a11", "a12", "a13", "a14", "a15", 40#endif
41 " _entry a1, 48\n"
42#if XCHAL_NUM_AREGS % 12 == 0
43 " mov a8, a8\n"
44#elif XCHAL_NUM_AREGS % 12 == 4
45 " mov a12, a12\n"
46#elif XCHAL_NUM_AREGS % 12 == 8
47 " mov a4, a4\n"
48#endif
49 " retw\n"
50 "2:\n"
51 : : : "a12", "a13", "memory");
41#else 52#else
42 : "a2", "a3", "a4", "a7", "a11", "a12", "a13", "a14", "a15", 53 __asm__ __volatile__ (
54 " mov a12, a12\n"
55 : : : "memory");
43#endif 56#endif
44 "memory");
45} 57}
46 58
47#endif /* _XTENSA_TRAPS_H */ 59#endif /* _XTENSA_TRAPS_H */
diff --git a/arch/xtensa/include/asm/vectors.h b/arch/xtensa/include/asm/vectors.h
index 5791b45d5a5d..f74ddfbb92ef 100644
--- a/arch/xtensa/include/asm/vectors.h
+++ b/arch/xtensa/include/asm/vectors.h
@@ -25,7 +25,7 @@
25#define XCHAL_KIO_DEFAULT_PADDR 0xf0000000 25#define XCHAL_KIO_DEFAULT_PADDR 0xf0000000
26#define XCHAL_KIO_SIZE 0x10000000 26#define XCHAL_KIO_SIZE 0x10000000
27 27
28#if XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY && CONFIG_OF 28#if XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY && defined(CONFIG_OF)
29#define XCHAL_KIO_PADDR xtensa_get_kio_paddr() 29#define XCHAL_KIO_PADDR xtensa_get_kio_paddr()
30#else 30#else
31#define XCHAL_KIO_PADDR XCHAL_KIO_DEFAULT_PADDR 31#define XCHAL_KIO_PADDR XCHAL_KIO_DEFAULT_PADDR
diff --git a/arch/xtensa/include/uapi/asm/unistd.h b/arch/xtensa/include/uapi/asm/unistd.h
index 51940fec6990..b9395529f02d 100644
--- a/arch/xtensa/include/uapi/asm/unistd.h
+++ b/arch/xtensa/include/uapi/asm/unistd.h
@@ -734,7 +734,12 @@ __SYSCALL(332, sys_finit_module, 3)
734#define __NR_accept4 333 734#define __NR_accept4 333
735__SYSCALL(333, sys_accept4, 4) 735__SYSCALL(333, sys_accept4, 4)
736 736
737#define __NR_syscall_count 334 737#define __NR_sched_setattr 334
738__SYSCALL(334, sys_sched_setattr, 2)
739#define __NR_sched_getattr 335
740__SYSCALL(335, sys_sched_getattr, 3)
741
742#define __NR_syscall_count 336
738 743
739/* 744/*
740 * sysxtensa syscall handler 745 * sysxtensa syscall handler
diff --git a/arch/xtensa/kernel/entry.S b/arch/xtensa/kernel/entry.S
index 21dbe6bdb8ed..ef7f4990722b 100644
--- a/arch/xtensa/kernel/entry.S
+++ b/arch/xtensa/kernel/entry.S
@@ -1081,196 +1081,53 @@ ENTRY(fast_syscall_spill_registers)
1081 1081
1082 rsr a0, sar 1082 rsr a0, sar
1083 s32i a3, a2, PT_AREG3 1083 s32i a3, a2, PT_AREG3
1084 s32i a4, a2, PT_AREG4 1084 s32i a0, a2, PT_SAR
1085 s32i a0, a2, PT_AREG5 # store SAR to PT_AREG5
1086 1085
1087 /* The spill routine might clobber a7, a11, and a15. */ 1086 /* The spill routine might clobber a4, a7, a8, a11, a12, and a15. */
1088 1087
1088 s32i a4, a2, PT_AREG4
1089 s32i a7, a2, PT_AREG7 1089 s32i a7, a2, PT_AREG7
1090 s32i a8, a2, PT_AREG8
1090 s32i a11, a2, PT_AREG11 1091 s32i a11, a2, PT_AREG11
1092 s32i a12, a2, PT_AREG12
1091 s32i a15, a2, PT_AREG15 1093 s32i a15, a2, PT_AREG15
1092 1094
1093 call0 _spill_registers # destroys a3, a4, and SAR
1094
1095 /* Advance PC, restore registers and SAR, and return from exception. */
1096
1097 l32i a3, a2, PT_AREG5
1098 l32i a4, a2, PT_AREG4
1099 l32i a0, a2, PT_AREG0
1100 wsr a3, sar
1101 l32i a3, a2, PT_AREG3
1102
1103 /* Restore clobbered registers. */
1104
1105 l32i a7, a2, PT_AREG7
1106 l32i a11, a2, PT_AREG11
1107 l32i a15, a2, PT_AREG15
1108
1109 movi a2, 0
1110 rfe
1111
1112ENDPROC(fast_syscall_spill_registers)
1113
1114/* Fixup handler.
1115 *
1116 * We get here if the spill routine causes an exception, e.g. tlb miss.
1117 * We basically restore WINDOWBASE and WINDOWSTART to the condition when
1118 * we entered the spill routine and jump to the user exception handler.
1119 *
1120 * a0: value of depc, original value in depc
1121 * a2: trashed, original value in EXC_TABLE_DOUBLE_SAVE
1122 * a3: exctable, original value in excsave1
1123 */
1124
1125ENTRY(fast_syscall_spill_registers_fixup)
1126
1127 rsr a2, windowbase # get current windowbase (a2 is saved)
1128 xsr a0, depc # restore depc and a0
1129 ssl a2 # set shift (32 - WB)
1130
1131 /* We need to make sure the current registers (a0-a3) are preserved.
1132 * To do this, we simply set the bit for the current window frame
1133 * in WS, so that the exception handlers save them to the task stack.
1134 */
1135
1136 xsr a3, excsave1 # get spill-mask
1137 slli a3, a3, 1 # shift left by one
1138
1139 slli a2, a3, 32-WSBITS
1140 src a2, a3, a2 # a2 = xxwww1yyxxxwww1yy......
1141 wsr a2, windowstart # set corrected windowstart
1142
1143 srli a3, a3, 1
1144 rsr a2, excsave1
1145 l32i a2, a2, EXC_TABLE_DOUBLE_SAVE # restore a2
1146 xsr a2, excsave1
1147 s32i a3, a2, EXC_TABLE_DOUBLE_SAVE # save a3
1148 l32i a3, a2, EXC_TABLE_PARAM # original WB (in user task)
1149 xsr a2, excsave1
1150
1151 /* Return to the original (user task) WINDOWBASE.
1152 * We leave the following frame behind:
1153 * a0, a1, a2 same
1154 * a3: trashed (saved in EXC_TABLE_DOUBLE_SAVE)
1155 * depc: depc (we have to return to that address)
1156 * excsave_1: exctable
1157 */
1158
1159 wsr a3, windowbase
1160 rsync
1161
1162 /* We are now in the original frame when we entered _spill_registers:
1163 * a0: return address
1164 * a1: used, stack pointer
1165 * a2: kernel stack pointer
1166 * a3: available
1167 * depc: exception address
1168 * excsave: exctable
1169 * Note: This frame might be the same as above.
1170 */
1171
1172 /* Setup stack pointer. */
1173
1174 addi a2, a2, -PT_USER_SIZE
1175 s32i a0, a2, PT_AREG0
1176
1177 /* Make sure we return to this fixup handler. */
1178
1179 movi a3, fast_syscall_spill_registers_fixup_return
1180 s32i a3, a2, PT_DEPC # setup depc
1181
1182 /* Jump to the exception handler. */
1183
1184 rsr a3, excsave1
1185 rsr a0, exccause
1186 addx4 a0, a0, a3 # find entry in table
1187 l32i a0, a0, EXC_TABLE_FAST_USER # load handler
1188 l32i a3, a3, EXC_TABLE_DOUBLE_SAVE
1189 jx a0
1190
1191ENDPROC(fast_syscall_spill_registers_fixup)
1192
1193ENTRY(fast_syscall_spill_registers_fixup_return)
1194
1195 /* When we return here, all registers have been restored (a2: DEPC) */
1196
1197 wsr a2, depc # exception address
1198
1199 /* Restore fixup handler. */
1200
1201 rsr a2, excsave1
1202 s32i a3, a2, EXC_TABLE_DOUBLE_SAVE
1203 movi a3, fast_syscall_spill_registers_fixup
1204 s32i a3, a2, EXC_TABLE_FIXUP
1205 rsr a3, windowbase
1206 s32i a3, a2, EXC_TABLE_PARAM
1207 l32i a2, a2, EXC_TABLE_KSTK
1208
1209 /* Load WB at the time the exception occurred. */
1210
1211 rsr a3, sar # WB is still in SAR
1212 neg a3, a3
1213 wsr a3, windowbase
1214 rsync
1215
1216 rsr a3, excsave1
1217 l32i a3, a3, EXC_TABLE_DOUBLE_SAVE
1218
1219 rfde
1220
1221ENDPROC(fast_syscall_spill_registers_fixup_return)
1222
1223/*
1224 * spill all registers.
1225 *
1226 * This is not a real function. The following conditions must be met:
1227 *
1228 * - must be called with call0.
1229 * - uses a3, a4 and SAR.
1230 * - the last 'valid' register of each frame are clobbered.
1231 * - the caller must have registered a fixup handler
1232 * (or be inside a critical section)
1233 * - PS_EXCM must be set (PS_WOE cleared?)
1234 */
1235
1236ENTRY(_spill_registers)
1237
1238 /* 1095 /*
1239 * Rotate ws so that the current windowbase is at bit 0. 1096 * Rotate ws so that the current windowbase is at bit 0.
1240 * Assume ws = xxxwww1yy (www1 current window frame). 1097 * Assume ws = xxxwww1yy (www1 current window frame).
1241 * Rotate ws right so that a4 = yyxxxwww1. 1098 * Rotate ws right so that a4 = yyxxxwww1.
1242 */ 1099 */
1243 1100
1244 rsr a4, windowbase 1101 rsr a0, windowbase
1245 rsr a3, windowstart # a3 = xxxwww1yy 1102 rsr a3, windowstart # a3 = xxxwww1yy
1246 ssr a4 # holds WB 1103 ssr a0 # holds WB
1247 slli a4, a3, WSBITS 1104 slli a0, a3, WSBITS
1248 or a3, a3, a4 # a3 = xxxwww1yyxxxwww1yy 1105 or a3, a3, a0 # a3 = xxxwww1yyxxxwww1yy
1249 srl a3, a3 # a3 = 00xxxwww1yyxxxwww1 1106 srl a3, a3 # a3 = 00xxxwww1yyxxxwww1
1250 1107
1251 /* We are done if there are no more than the current register frame. */ 1108 /* We are done if there are no more than the current register frame. */
1252 1109
1253 extui a3, a3, 1, WSBITS-1 # a3 = 0yyxxxwww 1110 extui a3, a3, 1, WSBITS-1 # a3 = 0yyxxxwww
1254 movi a4, (1 << (WSBITS-1)) 1111 movi a0, (1 << (WSBITS-1))
1255 _beqz a3, .Lnospill # only one active frame? jump 1112 _beqz a3, .Lnospill # only one active frame? jump
1256 1113
1257 /* We want 1 at the top, so that we return to the current windowbase */ 1114 /* We want 1 at the top, so that we return to the current windowbase */
1258 1115
1259 or a3, a3, a4 # 1yyxxxwww 1116 or a3, a3, a0 # 1yyxxxwww
1260 1117
1261 /* Skip empty frames - get 'oldest' WINDOWSTART-bit. */ 1118 /* Skip empty frames - get 'oldest' WINDOWSTART-bit. */
1262 1119
1263 wsr a3, windowstart # save shifted windowstart 1120 wsr a3, windowstart # save shifted windowstart
1264 neg a4, a3 1121 neg a0, a3
1265 and a3, a4, a3 # first bit set from right: 000010000 1122 and a3, a0, a3 # first bit set from right: 000010000
1266 1123
1267 ffs_ws a4, a3 # a4: shifts to skip empty frames 1124 ffs_ws a0, a3 # a0: shifts to skip empty frames
1268 movi a3, WSBITS 1125 movi a3, WSBITS
1269 sub a4, a3, a4 # WSBITS-a4:number of 0-bits from right 1126 sub a0, a3, a0 # WSBITS-a0:number of 0-bits from right
1270 ssr a4 # save in SAR for later. 1127 ssr a0 # save in SAR for later.
1271 1128
1272 rsr a3, windowbase 1129 rsr a3, windowbase
1273 add a3, a3, a4 1130 add a3, a3, a0
1274 wsr a3, windowbase 1131 wsr a3, windowbase
1275 rsync 1132 rsync
1276 1133
@@ -1285,22 +1142,6 @@ ENTRY(_spill_registers)
1285 * we have to save 4,8. or 12 registers. 1142 * we have to save 4,8. or 12 registers.
1286 */ 1143 */
1287 1144
1288 _bbsi.l a3, 1, .Lc4
1289 _bbsi.l a3, 2, .Lc8
1290
1291 /* Special case: we have a call12-frame starting at a4. */
1292
1293 _bbci.l a3, 3, .Lc12 # bit 3 shouldn't be zero! (Jump to Lc12 first)
1294
1295 s32e a4, a1, -16 # a1 is valid with an empty spill area
1296 l32e a4, a5, -12
1297 s32e a8, a4, -48
1298 mov a8, a4
1299 l32e a4, a1, -16
1300 j .Lc12c
1301
1302.Lnospill:
1303 ret
1304 1145
1305.Lloop: _bbsi.l a3, 1, .Lc4 1146.Lloop: _bbsi.l a3, 1, .Lc4
1306 _bbci.l a3, 2, .Lc12 1147 _bbci.l a3, 2, .Lc12
@@ -1314,20 +1155,10 @@ ENTRY(_spill_registers)
1314 s32e a9, a4, -28 1155 s32e a9, a4, -28
1315 s32e a10, a4, -24 1156 s32e a10, a4, -24
1316 s32e a11, a4, -20 1157 s32e a11, a4, -20
1317
1318 srli a11, a3, 2 # shift windowbase by 2 1158 srli a11, a3, 2 # shift windowbase by 2
1319 rotw 2 1159 rotw 2
1320 _bnei a3, 1, .Lloop 1160 _bnei a3, 1, .Lloop
1321 1161 j .Lexit
1322.Lexit: /* Done. Do the final rotation, set WS, and return. */
1323
1324 rotw 1
1325 rsr a3, windowbase
1326 ssl a3
1327 movi a3, 1
1328 sll a3, a3
1329 wsr a3, windowstart
1330 ret
1331 1162
1332.Lc4: s32e a4, a9, -16 1163.Lc4: s32e a4, a9, -16
1333 s32e a5, a9, -12 1164 s32e a5, a9, -12
@@ -1343,11 +1174,11 @@ ENTRY(_spill_registers)
1343 1174
1344 /* 12-register frame (call12) */ 1175 /* 12-register frame (call12) */
1345 1176
1346 l32e a2, a5, -12 1177 l32e a0, a5, -12
1347 s32e a8, a2, -48 1178 s32e a8, a0, -48
1348 mov a8, a2 1179 mov a8, a0
1349 1180
1350.Lc12c: s32e a9, a8, -44 1181 s32e a9, a8, -44
1351 s32e a10, a8, -40 1182 s32e a10, a8, -40
1352 s32e a11, a8, -36 1183 s32e a11, a8, -36
1353 s32e a12, a8, -32 1184 s32e a12, a8, -32
@@ -1367,30 +1198,54 @@ ENTRY(_spill_registers)
1367 */ 1198 */
1368 1199
1369 rotw 1 1200 rotw 1
1370 mov a5, a13 1201 mov a4, a13
1371 rotw -1 1202 rotw -1
1372 1203
1373 s32e a4, a9, -16 1204 s32e a4, a8, -16
1374 s32e a5, a9, -12 1205 s32e a5, a8, -12
1375 s32e a6, a9, -8 1206 s32e a6, a8, -8
1376 s32e a7, a9, -4 1207 s32e a7, a8, -4
1377 1208
1378 rotw 3 1209 rotw 3
1379 1210
1380 _beqi a3, 1, .Lexit 1211 _beqi a3, 1, .Lexit
1381 j .Lloop 1212 j .Lloop
1382 1213
1383.Linvalid_mask: 1214.Lexit:
1384 1215
1385 /* We get here because of an unrecoverable error in the window 1216 /* Done. Do the final rotation and set WS */
1386 * registers. If we are in user space, we kill the application, 1217
1387 * however, this condition is unrecoverable in kernel space. 1218 rotw 1
1388 */ 1219 rsr a3, windowbase
1220 ssl a3
1221 movi a3, 1
1222 sll a3, a3
1223 wsr a3, windowstart
1224.Lnospill:
1225
1226 /* Advance PC, restore registers and SAR, and return from exception. */
1227
1228 l32i a3, a2, PT_SAR
1229 l32i a0, a2, PT_AREG0
1230 wsr a3, sar
1231 l32i a3, a2, PT_AREG3
1389 1232
1390 rsr a0, ps 1233 /* Restore clobbered registers. */
1391 _bbci.l a0, PS_UM_BIT, 1f
1392 1234
1393 /* User space: Setup a dummy frame and kill application. 1235 l32i a4, a2, PT_AREG4
1236 l32i a7, a2, PT_AREG7
1237 l32i a8, a2, PT_AREG8
1238 l32i a11, a2, PT_AREG11
1239 l32i a12, a2, PT_AREG12
1240 l32i a15, a2, PT_AREG15
1241
1242 movi a2, 0
1243 rfe
1244
1245.Linvalid_mask:
1246
1247 /* We get here because of an unrecoverable error in the window
1248 * registers, so set up a dummy frame and kill the user application.
1394 * Note: We assume EXC_TABLE_KSTK contains a valid stack pointer. 1249 * Note: We assume EXC_TABLE_KSTK contains a valid stack pointer.
1395 */ 1250 */
1396 1251
@@ -1414,14 +1269,136 @@ ENTRY(_spill_registers)
1414 movi a4, do_exit 1269 movi a4, do_exit
1415 callx4 a4 1270 callx4 a4
1416 1271
14171: /* Kernel space: PANIC! */ 1272 /* shouldn't return, so panic */
1418 1273
1419 wsr a0, excsave1 1274 wsr a0, excsave1
1420 movi a0, unrecoverable_exception 1275 movi a0, unrecoverable_exception
1421 callx0 a0 # should not return 1276 callx0 a0 # should not return
14221: j 1b 12771: j 1b
1423 1278
1424ENDPROC(_spill_registers) 1279
1280ENDPROC(fast_syscall_spill_registers)
1281
1282/* Fixup handler.
1283 *
1284 * We get here if the spill routine causes an exception, e.g. tlb miss.
1285 * We basically restore WINDOWBASE and WINDOWSTART to the condition when
1286 * we entered the spill routine and jump to the user exception handler.
1287 *
1288 * Note that we only need to restore the bits in windowstart that have not
1289 * been spilled yet by the _spill_register routine. Luckily, a3 contains a
1290 * rotated windowstart with only those bits set for frames that haven't been
1291 * spilled yet. Because a3 is rotated such that bit 0 represents the register
1292 * frame for the current windowbase - 1, we need to rotate a3 left by the
1293 * value of the current windowbase + 1 and move it to windowstart.
1294 *
1295 * a0: value of depc, original value in depc
1296 * a2: trashed, original value in EXC_TABLE_DOUBLE_SAVE
1297 * a3: exctable, original value in excsave1
1298 */
1299
1300ENTRY(fast_syscall_spill_registers_fixup)
1301
1302 rsr a2, windowbase # get current windowbase (a2 is saved)
1303 xsr a0, depc # restore depc and a0
1304 ssl a2 # set shift (32 - WB)
1305
1306 /* We need to make sure the current registers (a0-a3) are preserved.
1307 * To do this, we simply set the bit for the current window frame
1308 * in WS, so that the exception handlers save them to the task stack.
1309 *
1310 * Note: we use a3 to set the windowbase, so we take a special care
1311 * of it, saving it in the original _spill_registers frame across
1312 * the exception handler call.
1313 */
1314
1315 xsr a3, excsave1 # get spill-mask
1316 slli a3, a3, 1 # shift left by one
1317 addi a3, a3, 1 # set the bit for the current window frame
1318
1319 slli a2, a3, 32-WSBITS
1320 src a2, a3, a2 # a2 = xxwww1yyxxxwww1yy......
1321 wsr a2, windowstart # set corrected windowstart
1322
1323 srli a3, a3, 1
1324 rsr a2, excsave1
1325 l32i a2, a2, EXC_TABLE_DOUBLE_SAVE # restore a2
1326 xsr a2, excsave1
1327 s32i a3, a2, EXC_TABLE_DOUBLE_SAVE # save a3
1328 l32i a3, a2, EXC_TABLE_PARAM # original WB (in user task)
1329 xsr a2, excsave1
1330
1331 /* Return to the original (user task) WINDOWBASE.
1332 * We leave the following frame behind:
1333 * a0, a1, a2 same
1334 * a3: trashed (saved in EXC_TABLE_DOUBLE_SAVE)
1335 * depc: depc (we have to return to that address)
1336 * excsave_1: exctable
1337 */
1338
1339 wsr a3, windowbase
1340 rsync
1341
1342 /* We are now in the original frame when we entered _spill_registers:
1343 * a0: return address
1344 * a1: used, stack pointer
1345 * a2: kernel stack pointer
1346 * a3: available
1347 * depc: exception address
1348 * excsave: exctable
1349 * Note: This frame might be the same as above.
1350 */
1351
1352 /* Setup stack pointer. */
1353
1354 addi a2, a2, -PT_USER_SIZE
1355 s32i a0, a2, PT_AREG0
1356
1357 /* Make sure we return to this fixup handler. */
1358
1359 movi a3, fast_syscall_spill_registers_fixup_return
1360 s32i a3, a2, PT_DEPC # setup depc
1361
1362 /* Jump to the exception handler. */
1363
1364 rsr a3, excsave1
1365 rsr a0, exccause
1366 addx4 a0, a0, a3 # find entry in table
1367 l32i a0, a0, EXC_TABLE_FAST_USER # load handler
1368 l32i a3, a3, EXC_TABLE_DOUBLE_SAVE
1369 jx a0
1370
1371ENDPROC(fast_syscall_spill_registers_fixup)
1372
1373ENTRY(fast_syscall_spill_registers_fixup_return)
1374
1375 /* When we return here, all registers have been restored (a2: DEPC) */
1376
1377 wsr a2, depc # exception address
1378
1379 /* Restore fixup handler. */
1380
1381 rsr a2, excsave1
1382 s32i a3, a2, EXC_TABLE_DOUBLE_SAVE
1383 movi a3, fast_syscall_spill_registers_fixup
1384 s32i a3, a2, EXC_TABLE_FIXUP
1385 rsr a3, windowbase
1386 s32i a3, a2, EXC_TABLE_PARAM
1387 l32i a2, a2, EXC_TABLE_KSTK
1388
1389 /* Load WB at the time the exception occurred. */
1390
1391 rsr a3, sar # WB is still in SAR
1392 neg a3, a3
1393 wsr a3, windowbase
1394 rsync
1395
1396 rsr a3, excsave1
1397 l32i a3, a3, EXC_TABLE_DOUBLE_SAVE
1398
1399 rfde
1400
1401ENDPROC(fast_syscall_spill_registers_fixup_return)
1425 1402
1426#ifdef CONFIG_MMU 1403#ifdef CONFIG_MMU
1427/* 1404/*
@@ -1794,6 +1771,43 @@ ENTRY(system_call)
1794 1771
1795ENDPROC(system_call) 1772ENDPROC(system_call)
1796 1773
1774/*
1775 * Spill live registers on the kernel stack macro.
1776 *
1777 * Entry condition: ps.woe is set, ps.excm is cleared
1778 * Exit condition: windowstart has single bit set
1779 * May clobber: a12, a13
1780 */
1781 .macro spill_registers_kernel
1782
1783#if XCHAL_NUM_AREGS > 16
1784 call12 1f
1785 _j 2f
1786 retw
1787 .align 4
17881:
1789 _entry a1, 48
1790 addi a12, a0, 3
1791#if XCHAL_NUM_AREGS > 32
1792 .rept (XCHAL_NUM_AREGS - 32) / 12
1793 _entry a1, 48
1794 mov a12, a0
1795 .endr
1796#endif
1797 _entry a1, 48
1798#if XCHAL_NUM_AREGS % 12 == 0
1799 mov a8, a8
1800#elif XCHAL_NUM_AREGS % 12 == 4
1801 mov a12, a12
1802#elif XCHAL_NUM_AREGS % 12 == 8
1803 mov a4, a4
1804#endif
1805 retw
18062:
1807#else
1808 mov a12, a12
1809#endif
1810 .endm
1797 1811
1798/* 1812/*
1799 * Task switch. 1813 * Task switch.
@@ -1806,21 +1820,20 @@ ENTRY(_switch_to)
1806 1820
1807 entry a1, 16 1821 entry a1, 16
1808 1822
1809 mov a12, a2 # preserve 'prev' (a2) 1823 mov a10, a2 # preserve 'prev' (a2)
1810 mov a13, a3 # and 'next' (a3) 1824 mov a11, a3 # and 'next' (a3)
1811 1825
1812 l32i a4, a2, TASK_THREAD_INFO 1826 l32i a4, a2, TASK_THREAD_INFO
1813 l32i a5, a3, TASK_THREAD_INFO 1827 l32i a5, a3, TASK_THREAD_INFO
1814 1828
1815 save_xtregs_user a4 a6 a8 a9 a10 a11 THREAD_XTREGS_USER 1829 save_xtregs_user a4 a6 a8 a9 a12 a13 THREAD_XTREGS_USER
1816 1830
1817 s32i a0, a12, THREAD_RA # save return address 1831 s32i a0, a10, THREAD_RA # save return address
1818 s32i a1, a12, THREAD_SP # save stack pointer 1832 s32i a1, a10, THREAD_SP # save stack pointer
1819 1833
1820 /* Disable ints while we manipulate the stack pointer. */ 1834 /* Disable ints while we manipulate the stack pointer. */
1821 1835
1822 movi a14, (1 << PS_EXCM_BIT) | LOCKLEVEL 1836 rsil a14, LOCKLEVEL
1823 xsr a14, ps
1824 rsr a3, excsave1 1837 rsr a3, excsave1
1825 rsync 1838 rsync
1826 s32i a3, a3, EXC_TABLE_FIXUP /* enter critical section */ 1839 s32i a3, a3, EXC_TABLE_FIXUP /* enter critical section */
@@ -1835,7 +1848,7 @@ ENTRY(_switch_to)
1835 1848
1836 /* Flush register file. */ 1849 /* Flush register file. */
1837 1850
1838 call0 _spill_registers # destroys a3, a4, and SAR 1851 spill_registers_kernel
1839 1852
1840 /* Set kernel stack (and leave critical section) 1853 /* Set kernel stack (and leave critical section)
1841 * Note: It's save to set it here. The stack will not be overwritten 1854 * Note: It's save to set it here. The stack will not be overwritten
@@ -1851,13 +1864,13 @@ ENTRY(_switch_to)
1851 1864
1852 /* restore context of the task 'next' */ 1865 /* restore context of the task 'next' */
1853 1866
1854 l32i a0, a13, THREAD_RA # restore return address 1867 l32i a0, a11, THREAD_RA # restore return address
1855 l32i a1, a13, THREAD_SP # restore stack pointer 1868 l32i a1, a11, THREAD_SP # restore stack pointer
1856 1869
1857 load_xtregs_user a5 a6 a8 a9 a10 a11 THREAD_XTREGS_USER 1870 load_xtregs_user a5 a6 a8 a9 a12 a13 THREAD_XTREGS_USER
1858 1871
1859 wsr a14, ps 1872 wsr a14, ps
1860 mov a2, a12 # return 'prev' 1873 mov a2, a10 # return 'prev'
1861 rsync 1874 rsync
1862 1875
1863 retw 1876 retw
diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index 7d12af1317f1..84fe931bb60e 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -22,6 +22,7 @@
22#include <linux/bootmem.h> 22#include <linux/bootmem.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/percpu.h> 24#include <linux/percpu.h>
25#include <linux/clk-provider.h>
25#include <linux/cpu.h> 26#include <linux/cpu.h>
26#include <linux/of_fdt.h> 27#include <linux/of_fdt.h>
27#include <linux/of_platform.h> 28#include <linux/of_platform.h>
@@ -276,6 +277,7 @@ void __init early_init_devtree(void *params)
276 277
277static int __init xtensa_device_probe(void) 278static int __init xtensa_device_probe(void)
278{ 279{
280 of_clk_init(NULL);
279 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); 281 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
280 return 0; 282 return 0;
281} 283}
diff --git a/arch/xtensa/kernel/time.c b/arch/xtensa/kernel/time.c
index 08b769d3b3a1..2a1823de69cc 100644
--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -30,6 +30,7 @@
30#include <asm/platform.h> 30#include <asm/platform.h>
31 31
32unsigned long ccount_freq; /* ccount Hz */ 32unsigned long ccount_freq; /* ccount Hz */
33EXPORT_SYMBOL(ccount_freq);
33 34
34static cycle_t ccount_read(struct clocksource *cs) 35static cycle_t ccount_read(struct clocksource *cs)
35{ 36{
diff --git a/arch/xtensa/kernel/vectors.S b/arch/xtensa/kernel/vectors.S
index cb8fd44caabc..f9e1ec346e35 100644
--- a/arch/xtensa/kernel/vectors.S
+++ b/arch/xtensa/kernel/vectors.S
@@ -235,7 +235,7 @@ ENTRY(_DoubleExceptionVector)
235 235
236 /* Check for overflow/underflow exception, jump if overflow. */ 236 /* Check for overflow/underflow exception, jump if overflow. */
237 237
238 _bbci.l a0, 6, _DoubleExceptionVector_WindowOverflow 238 bbci.l a0, 6, _DoubleExceptionVector_WindowOverflow
239 239
240 /* 240 /*
241 * Restart window underflow exception. 241 * Restart window underflow exception.
diff --git a/arch/xtensa/kernel/xtensa_ksyms.c b/arch/xtensa/kernel/xtensa_ksyms.c
index 74a60c7e085e..80b33ed51f31 100644
--- a/arch/xtensa/kernel/xtensa_ksyms.c
+++ b/arch/xtensa/kernel/xtensa_ksyms.c
@@ -122,9 +122,7 @@ EXPORT_SYMBOL(insw);
122EXPORT_SYMBOL(insl); 122EXPORT_SYMBOL(insl);
123 123
124extern long common_exception_return; 124extern long common_exception_return;
125extern long _spill_registers;
126EXPORT_SYMBOL(common_exception_return); 125EXPORT_SYMBOL(common_exception_return);
127EXPORT_SYMBOL(_spill_registers);
128 126
129#ifdef CONFIG_FUNCTION_TRACER 127#ifdef CONFIG_FUNCTION_TRACER
130EXPORT_SYMBOL(_mcount); 128EXPORT_SYMBOL(_mcount);
diff --git a/arch/xtensa/mm/init.c b/arch/xtensa/mm/init.c
index 479d7537a32a..aff108df92d3 100644
--- a/arch/xtensa/mm/init.c
+++ b/arch/xtensa/mm/init.c
@@ -90,7 +90,7 @@ int __init mem_reserve(unsigned long start, unsigned long end, int must_exist)
90 90
91 91
92/* 92/*
93 * Initialize the bootmem system and give it all the memory we have available. 93 * Initialize the bootmem system and give it all low memory we have available.
94 */ 94 */
95 95
96void __init bootmem_init(void) 96void __init bootmem_init(void)
@@ -142,9 +142,14 @@ void __init bootmem_init(void)
142 142
143 /* Add all remaining memory pieces into the bootmem map */ 143 /* Add all remaining memory pieces into the bootmem map */
144 144
145 for (i=0; i<sysmem.nr_banks; i++) 145 for (i = 0; i < sysmem.nr_banks; i++) {
146 free_bootmem(sysmem.bank[i].start, 146 if (sysmem.bank[i].start >> PAGE_SHIFT < max_low_pfn) {
147 sysmem.bank[i].end - sysmem.bank[i].start); 147 unsigned long end = min(max_low_pfn << PAGE_SHIFT,
148 sysmem.bank[i].end);
149 free_bootmem(sysmem.bank[i].start,
150 end - sysmem.bank[i].start);
151 }
152 }
148 153
149} 154}
150 155
diff --git a/arch/xtensa/mm/mmu.c b/arch/xtensa/mm/mmu.c
index 36ec171698b8..861203e958da 100644
--- a/arch/xtensa/mm/mmu.c
+++ b/arch/xtensa/mm/mmu.c
@@ -39,7 +39,7 @@ void init_mmu(void)
39 set_itlbcfg_register(0); 39 set_itlbcfg_register(0);
40 set_dtlbcfg_register(0); 40 set_dtlbcfg_register(0);
41#endif 41#endif
42#if XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY && CONFIG_OF 42#if XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY && defined(CONFIG_OF)
43 /* 43 /*
44 * Update the IO area mapping in case xtensa_kio_paddr has changed 44 * Update the IO area mapping in case xtensa_kio_paddr has changed
45 */ 45 */
diff --git a/arch/xtensa/platforms/xtfpga/setup.c b/arch/xtensa/platforms/xtfpga/setup.c
index 800227862fe8..57fd08b36f51 100644
--- a/arch/xtensa/platforms/xtfpga/setup.c
+++ b/arch/xtensa/platforms/xtfpga/setup.c
@@ -135,11 +135,11 @@ static void __init update_local_mac(struct device_node *node)
135 135
136static int __init machine_setup(void) 136static int __init machine_setup(void)
137{ 137{
138 struct device_node *serial; 138 struct device_node *clock;
139 struct device_node *eth = NULL; 139 struct device_node *eth = NULL;
140 140
141 for_each_compatible_node(serial, NULL, "ns16550a") 141 for_each_node_by_name(clock, "main-oscillator")
142 update_clock_frequency(serial); 142 update_clock_frequency(clock);
143 143
144 if ((eth = of_find_compatible_node(eth, NULL, "opencores,ethoc"))) 144 if ((eth = of_find_compatible_node(eth, NULL, "opencores,ethoc")))
145 update_local_mac(eth); 145 update_local_mac(eth);
@@ -290,6 +290,7 @@ static int __init xtavnet_init(void)
290 * knows whether they set it correctly on the DIP switches. 290 * knows whether they set it correctly on the DIP switches.
291 */ 291 */
292 pr_info("XTFPGA: Ethernet MAC %pM\n", ethoc_pdata.hwaddr); 292 pr_info("XTFPGA: Ethernet MAC %pM\n", ethoc_pdata.hwaddr);
293 ethoc_pdata.eth_clkfreq = *(long *)XTFPGA_CLKFRQ_VADDR;
293 294
294 return 0; 295 return 0;
295} 296}
diff --git a/arch/xtensa/variants/fsf/include/variant/tie.h b/arch/xtensa/variants/fsf/include/variant/tie.h
index bf4020116df5..244cdea4dee5 100644
--- a/arch/xtensa/variants/fsf/include/variant/tie.h
+++ b/arch/xtensa/variants/fsf/include/variant/tie.h
@@ -18,13 +18,6 @@
18#define XCHAL_CP_MASK 0x00 /* bitmask of all CPs by ID */ 18#define XCHAL_CP_MASK 0x00 /* bitmask of all CPs by ID */
19#define XCHAL_CP_PORT_MASK 0x00 /* bitmask of only port CPs */ 19#define XCHAL_CP_PORT_MASK 0x00 /* bitmask of only port CPs */
20 20
21/* Basic parameters of each coprocessor: */
22#define XCHAL_CP7_NAME "XTIOP"
23#define XCHAL_CP7_IDENT XTIOP
24#define XCHAL_CP7_SA_SIZE 0 /* size of state save area */
25#define XCHAL_CP7_SA_ALIGN 1 /* min alignment of save area */
26#define XCHAL_CP_ID_XTIOP 7 /* coprocessor ID (0..7) */
27
28/* Filler info for unassigned coprocessors, to simplify arrays etc: */ 21/* Filler info for unassigned coprocessors, to simplify arrays etc: */
29#define XCHAL_NCP_SA_SIZE 0 22#define XCHAL_NCP_SA_SIZE 0
30#define XCHAL_NCP_SA_ALIGN 1 23#define XCHAL_NCP_SA_ALIGN 1
@@ -42,6 +35,8 @@
42#define XCHAL_CP5_SA_ALIGN 1 35#define XCHAL_CP5_SA_ALIGN 1
43#define XCHAL_CP6_SA_SIZE 0 36#define XCHAL_CP6_SA_SIZE 0
44#define XCHAL_CP6_SA_ALIGN 1 37#define XCHAL_CP6_SA_ALIGN 1
38#define XCHAL_CP7_SA_SIZE 0
39#define XCHAL_CP7_SA_ALIGN 1
45 40
46/* Save area for non-coprocessor optional and custom (TIE) state: */ 41/* Save area for non-coprocessor optional and custom (TIE) state: */
47#define XCHAL_NCP_SA_SIZE 0 42#define XCHAL_NCP_SA_SIZE 0
diff --git a/block/blk-core.c b/block/blk-core.c
index c00e0bdeab4a..bfe16d5af9f9 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -708,9 +708,13 @@ blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn,
708 if (!q) 708 if (!q)
709 return NULL; 709 return NULL;
710 710
711 if (blk_init_rl(&q->root_rl, q, GFP_KERNEL)) 711 q->flush_rq = kzalloc(sizeof(struct request), GFP_KERNEL);
712 if (!q->flush_rq)
712 return NULL; 713 return NULL;
713 714
715 if (blk_init_rl(&q->root_rl, q, GFP_KERNEL))
716 goto fail;
717
714 q->request_fn = rfn; 718 q->request_fn = rfn;
715 q->prep_rq_fn = NULL; 719 q->prep_rq_fn = NULL;
716 q->unprep_rq_fn = NULL; 720 q->unprep_rq_fn = NULL;
@@ -733,12 +737,16 @@ blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn,
733 /* init elevator */ 737 /* init elevator */
734 if (elevator_init(q, NULL)) { 738 if (elevator_init(q, NULL)) {
735 mutex_unlock(&q->sysfs_lock); 739 mutex_unlock(&q->sysfs_lock);
736 return NULL; 740 goto fail;
737 } 741 }
738 742
739 mutex_unlock(&q->sysfs_lock); 743 mutex_unlock(&q->sysfs_lock);
740 744
741 return q; 745 return q;
746
747fail:
748 kfree(q->flush_rq);
749 return NULL;
742} 750}
743EXPORT_SYMBOL(blk_init_allocated_queue); 751EXPORT_SYMBOL(blk_init_allocated_queue);
744 752
@@ -1127,7 +1135,7 @@ static struct request *blk_old_get_request(struct request_queue *q, int rw,
1127struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask) 1135struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
1128{ 1136{
1129 if (q->mq_ops) 1137 if (q->mq_ops)
1130 return blk_mq_alloc_request(q, rw, gfp_mask, false); 1138 return blk_mq_alloc_request(q, rw, gfp_mask);
1131 else 1139 else
1132 return blk_old_get_request(q, rw, gfp_mask); 1140 return blk_old_get_request(q, rw, gfp_mask);
1133} 1141}
@@ -1278,6 +1286,11 @@ void __blk_put_request(struct request_queue *q, struct request *req)
1278 if (unlikely(!q)) 1286 if (unlikely(!q))
1279 return; 1287 return;
1280 1288
1289 if (q->mq_ops) {
1290 blk_mq_free_request(req);
1291 return;
1292 }
1293
1281 blk_pm_put_request(req); 1294 blk_pm_put_request(req);
1282 1295
1283 elv_completed_request(q, req); 1296 elv_completed_request(q, req);
diff --git a/block/blk-exec.c b/block/blk-exec.c
index bbfc072a79c2..dbf4502b1d67 100644
--- a/block/blk-exec.c
+++ b/block/blk-exec.c
@@ -65,7 +65,7 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
65 * be resued after dying flag is set 65 * be resued after dying flag is set
66 */ 66 */
67 if (q->mq_ops) { 67 if (q->mq_ops) {
68 blk_mq_insert_request(q, rq, true); 68 blk_mq_insert_request(rq, at_head, true, false);
69 return; 69 return;
70 } 70 }
71 71
diff --git a/block/blk-flush.c b/block/blk-flush.c
index 9288aaf35c21..43e6b4755e9a 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -130,20 +130,29 @@ static void blk_flush_restore_request(struct request *rq)
130 blk_clear_rq_complete(rq); 130 blk_clear_rq_complete(rq);
131} 131}
132 132
133static void mq_flush_data_run(struct work_struct *work) 133static void mq_flush_run(struct work_struct *work)
134{ 134{
135 struct request *rq; 135 struct request *rq;
136 136
137 rq = container_of(work, struct request, mq_flush_data); 137 rq = container_of(work, struct request, mq_flush_work);
138 138
139 memset(&rq->csd, 0, sizeof(rq->csd)); 139 memset(&rq->csd, 0, sizeof(rq->csd));
140 blk_mq_run_request(rq, true, false); 140 blk_mq_insert_request(rq, false, true, false);
141} 141}
142 142
143static void blk_mq_flush_data_insert(struct request *rq) 143static bool blk_flush_queue_rq(struct request *rq, bool add_front)
144{ 144{
145 INIT_WORK(&rq->mq_flush_data, mq_flush_data_run); 145 if (rq->q->mq_ops) {
146 kblockd_schedule_work(rq->q, &rq->mq_flush_data); 146 INIT_WORK(&rq->mq_flush_work, mq_flush_run);
147 kblockd_schedule_work(rq->q, &rq->mq_flush_work);
148 return false;
149 } else {
150 if (add_front)
151 list_add(&rq->queuelist, &rq->q->queue_head);
152 else
153 list_add_tail(&rq->queuelist, &rq->q->queue_head);
154 return true;
155 }
147} 156}
148 157
149/** 158/**
@@ -187,12 +196,7 @@ static bool blk_flush_complete_seq(struct request *rq, unsigned int seq,
187 196
188 case REQ_FSEQ_DATA: 197 case REQ_FSEQ_DATA:
189 list_move_tail(&rq->flush.list, &q->flush_data_in_flight); 198 list_move_tail(&rq->flush.list, &q->flush_data_in_flight);
190 if (q->mq_ops) 199 queued = blk_flush_queue_rq(rq, true);
191 blk_mq_flush_data_insert(rq);
192 else {
193 list_add(&rq->queuelist, &q->queue_head);
194 queued = true;
195 }
196 break; 200 break;
197 201
198 case REQ_FSEQ_DONE: 202 case REQ_FSEQ_DONE:
@@ -216,9 +220,6 @@ static bool blk_flush_complete_seq(struct request *rq, unsigned int seq,
216 } 220 }
217 221
218 kicked = blk_kick_flush(q); 222 kicked = blk_kick_flush(q);
219 /* blk_mq_run_flush will run queue */
220 if (q->mq_ops)
221 return queued;
222 return kicked | queued; 223 return kicked | queued;
223} 224}
224 225
@@ -230,10 +231,9 @@ static void flush_end_io(struct request *flush_rq, int error)
230 struct request *rq, *n; 231 struct request *rq, *n;
231 unsigned long flags = 0; 232 unsigned long flags = 0;
232 233
233 if (q->mq_ops) { 234 if (q->mq_ops)
234 blk_mq_free_request(flush_rq);
235 spin_lock_irqsave(&q->mq_flush_lock, flags); 235 spin_lock_irqsave(&q->mq_flush_lock, flags);
236 } 236
237 running = &q->flush_queue[q->flush_running_idx]; 237 running = &q->flush_queue[q->flush_running_idx];
238 BUG_ON(q->flush_pending_idx == q->flush_running_idx); 238 BUG_ON(q->flush_pending_idx == q->flush_running_idx);
239 239
@@ -263,49 +263,14 @@ static void flush_end_io(struct request *flush_rq, int error)
263 * kblockd. 263 * kblockd.
264 */ 264 */
265 if (queued || q->flush_queue_delayed) { 265 if (queued || q->flush_queue_delayed) {
266 if (!q->mq_ops) 266 WARN_ON(q->mq_ops);
267 blk_run_queue_async(q); 267 blk_run_queue_async(q);
268 else
269 /*
270 * This can be optimized to only run queues with requests
271 * queued if necessary.
272 */
273 blk_mq_run_queues(q, true);
274 } 268 }
275 q->flush_queue_delayed = 0; 269 q->flush_queue_delayed = 0;
276 if (q->mq_ops) 270 if (q->mq_ops)
277 spin_unlock_irqrestore(&q->mq_flush_lock, flags); 271 spin_unlock_irqrestore(&q->mq_flush_lock, flags);
278} 272}
279 273
280static void mq_flush_work(struct work_struct *work)
281{
282 struct request_queue *q;
283 struct request *rq;
284
285 q = container_of(work, struct request_queue, mq_flush_work);
286
287 /* We don't need set REQ_FLUSH_SEQ, it's for consistency */
288 rq = blk_mq_alloc_request(q, WRITE_FLUSH|REQ_FLUSH_SEQ,
289 __GFP_WAIT|GFP_ATOMIC, true);
290 rq->cmd_type = REQ_TYPE_FS;
291 rq->end_io = flush_end_io;
292
293 blk_mq_run_request(rq, true, false);
294}
295
296/*
297 * We can't directly use q->flush_rq, because it doesn't have tag and is not in
298 * hctx->rqs[]. so we must allocate a new request, since we can't sleep here,
299 * so offload the work to workqueue.
300 *
301 * Note: we assume a flush request finished in any hardware queue will flush
302 * the whole disk cache.
303 */
304static void mq_run_flush(struct request_queue *q)
305{
306 kblockd_schedule_work(q, &q->mq_flush_work);
307}
308
309/** 274/**
310 * blk_kick_flush - consider issuing flush request 275 * blk_kick_flush - consider issuing flush request
311 * @q: request_queue being kicked 276 * @q: request_queue being kicked
@@ -340,19 +305,31 @@ static bool blk_kick_flush(struct request_queue *q)
340 * different from running_idx, which means flush is in flight. 305 * different from running_idx, which means flush is in flight.
341 */ 306 */
342 q->flush_pending_idx ^= 1; 307 q->flush_pending_idx ^= 1;
308
343 if (q->mq_ops) { 309 if (q->mq_ops) {
344 mq_run_flush(q); 310 struct blk_mq_ctx *ctx = first_rq->mq_ctx;
345 return true; 311 struct blk_mq_hw_ctx *hctx = q->mq_ops->map_queue(q, ctx->cpu);
312
313 blk_mq_rq_init(hctx, q->flush_rq);
314 q->flush_rq->mq_ctx = ctx;
315
316 /*
317 * Reuse the tag value from the fist waiting request,
318 * with blk-mq the tag is generated during request
319 * allocation and drivers can rely on it being inside
320 * the range they asked for.
321 */
322 q->flush_rq->tag = first_rq->tag;
323 } else {
324 blk_rq_init(q, q->flush_rq);
346 } 325 }
347 326
348 blk_rq_init(q, &q->flush_rq); 327 q->flush_rq->cmd_type = REQ_TYPE_FS;
349 q->flush_rq.cmd_type = REQ_TYPE_FS; 328 q->flush_rq->cmd_flags = WRITE_FLUSH | REQ_FLUSH_SEQ;
350 q->flush_rq.cmd_flags = WRITE_FLUSH | REQ_FLUSH_SEQ; 329 q->flush_rq->rq_disk = first_rq->rq_disk;
351 q->flush_rq.rq_disk = first_rq->rq_disk; 330 q->flush_rq->end_io = flush_end_io;
352 q->flush_rq.end_io = flush_end_io;
353 331
354 list_add_tail(&q->flush_rq.queuelist, &q->queue_head); 332 return blk_flush_queue_rq(q->flush_rq, false);
355 return true;
356} 333}
357 334
358static void flush_data_end_io(struct request *rq, int error) 335static void flush_data_end_io(struct request *rq, int error)
@@ -437,7 +414,7 @@ void blk_insert_flush(struct request *rq)
437 if ((policy & REQ_FSEQ_DATA) && 414 if ((policy & REQ_FSEQ_DATA) &&
438 !(policy & (REQ_FSEQ_PREFLUSH | REQ_FSEQ_POSTFLUSH))) { 415 !(policy & (REQ_FSEQ_PREFLUSH | REQ_FSEQ_POSTFLUSH))) {
439 if (q->mq_ops) { 416 if (q->mq_ops) {
440 blk_mq_run_request(rq, false, true); 417 blk_mq_insert_request(rq, false, false, true);
441 } else 418 } else
442 list_add_tail(&rq->queuelist, &q->queue_head); 419 list_add_tail(&rq->queuelist, &q->queue_head);
443 return; 420 return;
@@ -558,5 +535,4 @@ EXPORT_SYMBOL(blkdev_issue_flush);
558void blk_mq_init_flush(struct request_queue *q) 535void blk_mq_init_flush(struct request_queue *q)
559{ 536{
560 spin_lock_init(&q->mq_flush_lock); 537 spin_lock_init(&q->mq_flush_lock);
561 INIT_WORK(&q->mq_flush_work, mq_flush_work);
562} 538}
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 2da76c999ef3..97a733cf3d5f 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -119,6 +119,14 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
119 119
120 atomic_inc(&bb.done); 120 atomic_inc(&bb.done);
121 submit_bio(type, bio); 121 submit_bio(type, bio);
122
123 /*
124 * We can loop for a long time in here, if someone does
125 * full device discards (like mkfs). Be nice and allow
126 * us to schedule out to avoid softlocking if preempt
127 * is disabled.
128 */
129 cond_resched();
122 } 130 }
123 blk_finish_plug(&plug); 131 blk_finish_plug(&plug);
124 132
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 8f8adaa95466..6c583f9c5b65 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -21,6 +21,16 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
21 if (!bio) 21 if (!bio)
22 return 0; 22 return 0;
23 23
24 /*
25 * This should probably be returning 0, but blk_add_request_payload()
26 * (Christoph!!!!)
27 */
28 if (bio->bi_rw & REQ_DISCARD)
29 return 1;
30
31 if (bio->bi_rw & REQ_WRITE_SAME)
32 return 1;
33
24 fbio = bio; 34 fbio = bio;
25 cluster = blk_queue_cluster(q); 35 cluster = blk_queue_cluster(q);
26 seg_size = 0; 36 seg_size = 0;
@@ -161,30 +171,60 @@ new_segment:
161 *bvprv = *bvec; 171 *bvprv = *bvec;
162} 172}
163 173
164/* 174static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
165 * map a request to scatterlist, return number of sg entries setup. Caller 175 struct scatterlist *sglist,
166 * must make sure sg can hold rq->nr_phys_segments entries 176 struct scatterlist **sg)
167 */
168int blk_rq_map_sg(struct request_queue *q, struct request *rq,
169 struct scatterlist *sglist)
170{ 177{
171 struct bio_vec bvec, bvprv = { NULL }; 178 struct bio_vec bvec, bvprv = { NULL };
172 struct req_iterator iter; 179 struct bvec_iter iter;
173 struct scatterlist *sg;
174 int nsegs, cluster; 180 int nsegs, cluster;
175 181
176 nsegs = 0; 182 nsegs = 0;
177 cluster = blk_queue_cluster(q); 183 cluster = blk_queue_cluster(q);
178 184
179 /* 185 if (bio->bi_rw & REQ_DISCARD) {
180 * for each bio in rq 186 /*
181 */ 187 * This is a hack - drivers should be neither modifying the
182 sg = NULL; 188 * biovec, nor relying on bi_vcnt - but because of
183 rq_for_each_segment(bvec, rq, iter) { 189 * blk_add_request_payload(), a discard bio may or may not have
184 __blk_segment_map_sg(q, &bvec, sglist, &bvprv, &sg, 190 * a payload we need to set up here (thank you Christoph) and
185 &nsegs, &cluster); 191 * bi_vcnt is really the only way of telling if we need to.
186 } /* segments in rq */ 192 */
193
194 if (bio->bi_vcnt)
195 goto single_segment;
196
197 return 0;
198 }
199
200 if (bio->bi_rw & REQ_WRITE_SAME) {
201single_segment:
202 *sg = sglist;
203 bvec = bio_iovec(bio);
204 sg_set_page(*sg, bvec.bv_page, bvec.bv_len, bvec.bv_offset);
205 return 1;
206 }
207
208 for_each_bio(bio)
209 bio_for_each_segment(bvec, bio, iter)
210 __blk_segment_map_sg(q, &bvec, sglist, &bvprv, sg,
211 &nsegs, &cluster);
187 212
213 return nsegs;
214}
215
216/*
217 * map a request to scatterlist, return number of sg entries setup. Caller
218 * must make sure sg can hold rq->nr_phys_segments entries
219 */
220int blk_rq_map_sg(struct request_queue *q, struct request *rq,
221 struct scatterlist *sglist)
222{
223 struct scatterlist *sg = NULL;
224 int nsegs = 0;
225
226 if (rq->bio)
227 nsegs = __blk_bios_map_sg(q, rq->bio, sglist, &sg);
188 228
189 if (unlikely(rq->cmd_flags & REQ_COPY_USER) && 229 if (unlikely(rq->cmd_flags & REQ_COPY_USER) &&
190 (blk_rq_bytes(rq) & q->dma_pad_mask)) { 230 (blk_rq_bytes(rq) & q->dma_pad_mask)) {
@@ -230,20 +270,13 @@ EXPORT_SYMBOL(blk_rq_map_sg);
230int blk_bio_map_sg(struct request_queue *q, struct bio *bio, 270int blk_bio_map_sg(struct request_queue *q, struct bio *bio,
231 struct scatterlist *sglist) 271 struct scatterlist *sglist)
232{ 272{
233 struct bio_vec bvec, bvprv = { NULL }; 273 struct scatterlist *sg = NULL;
234 struct scatterlist *sg; 274 int nsegs;
235 int nsegs, cluster; 275 struct bio *next = bio->bi_next;
236 struct bvec_iter iter; 276 bio->bi_next = NULL;
237
238 nsegs = 0;
239 cluster = blk_queue_cluster(q);
240
241 sg = NULL;
242 bio_for_each_segment(bvec, bio, iter) {
243 __blk_segment_map_sg(q, &bvec, sglist, &bvprv, &sg,
244 &nsegs, &cluster);
245 } /* segments in bio */
246 277
278 nsegs = __blk_bios_map_sg(q, bio, sglist, &sg);
279 bio->bi_next = next;
247 if (sg) 280 if (sg)
248 sg_mark_end(sg); 281 sg_mark_end(sg);
249 282
diff --git a/block/blk-mq-cpu.c b/block/blk-mq-cpu.c
index 3146befb56aa..136ef8643bba 100644
--- a/block/blk-mq-cpu.c
+++ b/block/blk-mq-cpu.c
@@ -11,7 +11,7 @@
11#include "blk-mq.h" 11#include "blk-mq.h"
12 12
13static LIST_HEAD(blk_mq_cpu_notify_list); 13static LIST_HEAD(blk_mq_cpu_notify_list);
14static DEFINE_SPINLOCK(blk_mq_cpu_notify_lock); 14static DEFINE_RAW_SPINLOCK(blk_mq_cpu_notify_lock);
15 15
16static int blk_mq_main_cpu_notify(struct notifier_block *self, 16static int blk_mq_main_cpu_notify(struct notifier_block *self,
17 unsigned long action, void *hcpu) 17 unsigned long action, void *hcpu)
@@ -19,12 +19,12 @@ static int blk_mq_main_cpu_notify(struct notifier_block *self,
19 unsigned int cpu = (unsigned long) hcpu; 19 unsigned int cpu = (unsigned long) hcpu;
20 struct blk_mq_cpu_notifier *notify; 20 struct blk_mq_cpu_notifier *notify;
21 21
22 spin_lock(&blk_mq_cpu_notify_lock); 22 raw_spin_lock(&blk_mq_cpu_notify_lock);
23 23
24 list_for_each_entry(notify, &blk_mq_cpu_notify_list, list) 24 list_for_each_entry(notify, &blk_mq_cpu_notify_list, list)
25 notify->notify(notify->data, action, cpu); 25 notify->notify(notify->data, action, cpu);
26 26
27 spin_unlock(&blk_mq_cpu_notify_lock); 27 raw_spin_unlock(&blk_mq_cpu_notify_lock);
28 return NOTIFY_OK; 28 return NOTIFY_OK;
29} 29}
30 30
@@ -32,16 +32,16 @@ void blk_mq_register_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
32{ 32{
33 BUG_ON(!notifier->notify); 33 BUG_ON(!notifier->notify);
34 34
35 spin_lock(&blk_mq_cpu_notify_lock); 35 raw_spin_lock(&blk_mq_cpu_notify_lock);
36 list_add_tail(&notifier->list, &blk_mq_cpu_notify_list); 36 list_add_tail(&notifier->list, &blk_mq_cpu_notify_list);
37 spin_unlock(&blk_mq_cpu_notify_lock); 37 raw_spin_unlock(&blk_mq_cpu_notify_lock);
38} 38}
39 39
40void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier) 40void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
41{ 41{
42 spin_lock(&blk_mq_cpu_notify_lock); 42 raw_spin_lock(&blk_mq_cpu_notify_lock);
43 list_del(&notifier->list); 43 list_del(&notifier->list);
44 spin_unlock(&blk_mq_cpu_notify_lock); 44 raw_spin_unlock(&blk_mq_cpu_notify_lock);
45} 45}
46 46
47void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier, 47void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier,
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index 5d70edc9855f..83ae96c51a27 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -184,7 +184,7 @@ void blk_mq_free_tags(struct blk_mq_tags *tags)
184ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page) 184ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page)
185{ 185{
186 char *orig_page = page; 186 char *orig_page = page;
187 int cpu; 187 unsigned int cpu;
188 188
189 if (!tags) 189 if (!tags)
190 return 0; 190 return 0;
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 57039fcd9c93..883f72089015 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -73,8 +73,8 @@ static void blk_mq_hctx_mark_pending(struct blk_mq_hw_ctx *hctx,
73 set_bit(ctx->index_hw, hctx->ctx_map); 73 set_bit(ctx->index_hw, hctx->ctx_map);
74} 74}
75 75
76static struct request *blk_mq_alloc_rq(struct blk_mq_hw_ctx *hctx, gfp_t gfp, 76static struct request *__blk_mq_alloc_request(struct blk_mq_hw_ctx *hctx,
77 bool reserved) 77 gfp_t gfp, bool reserved)
78{ 78{
79 struct request *rq; 79 struct request *rq;
80 unsigned int tag; 80 unsigned int tag;
@@ -193,12 +193,6 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
193 ctx->rq_dispatched[rw_is_sync(rw_flags)]++; 193 ctx->rq_dispatched[rw_is_sync(rw_flags)]++;
194} 194}
195 195
196static struct request *__blk_mq_alloc_request(struct blk_mq_hw_ctx *hctx,
197 gfp_t gfp, bool reserved)
198{
199 return blk_mq_alloc_rq(hctx, gfp, reserved);
200}
201
202static struct request *blk_mq_alloc_request_pinned(struct request_queue *q, 196static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
203 int rw, gfp_t gfp, 197 int rw, gfp_t gfp,
204 bool reserved) 198 bool reserved)
@@ -226,15 +220,14 @@ static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
226 return rq; 220 return rq;
227} 221}
228 222
229struct request *blk_mq_alloc_request(struct request_queue *q, int rw, 223struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp)
230 gfp_t gfp, bool reserved)
231{ 224{
232 struct request *rq; 225 struct request *rq;
233 226
234 if (blk_mq_queue_enter(q)) 227 if (blk_mq_queue_enter(q))
235 return NULL; 228 return NULL;
236 229
237 rq = blk_mq_alloc_request_pinned(q, rw, gfp, reserved); 230 rq = blk_mq_alloc_request_pinned(q, rw, gfp, false);
238 if (rq) 231 if (rq)
239 blk_mq_put_ctx(rq->mq_ctx); 232 blk_mq_put_ctx(rq->mq_ctx);
240 return rq; 233 return rq;
@@ -258,7 +251,7 @@ EXPORT_SYMBOL(blk_mq_alloc_reserved_request);
258/* 251/*
259 * Re-init and set pdu, if we have it 252 * Re-init and set pdu, if we have it
260 */ 253 */
261static void blk_mq_rq_init(struct blk_mq_hw_ctx *hctx, struct request *rq) 254void blk_mq_rq_init(struct blk_mq_hw_ctx *hctx, struct request *rq)
262{ 255{
263 blk_rq_init(hctx->queue, rq); 256 blk_rq_init(hctx->queue, rq);
264 257
@@ -290,38 +283,10 @@ void blk_mq_free_request(struct request *rq)
290 __blk_mq_free_request(hctx, ctx, rq); 283 __blk_mq_free_request(hctx, ctx, rq);
291} 284}
292 285
293static void blk_mq_bio_endio(struct request *rq, struct bio *bio, int error) 286bool blk_mq_end_io_partial(struct request *rq, int error, unsigned int nr_bytes)
294{
295 if (error)
296 clear_bit(BIO_UPTODATE, &bio->bi_flags);
297 else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
298 error = -EIO;
299
300 if (unlikely(rq->cmd_flags & REQ_QUIET))
301 set_bit(BIO_QUIET, &bio->bi_flags);
302
303 /* don't actually finish bio if it's part of flush sequence */
304 if (!(rq->cmd_flags & REQ_FLUSH_SEQ))
305 bio_endio(bio, error);
306}
307
308void blk_mq_complete_request(struct request *rq, int error)
309{ 287{
310 struct bio *bio = rq->bio; 288 if (blk_update_request(rq, error, blk_rq_bytes(rq)))
311 unsigned int bytes = 0; 289 return true;
312
313 trace_block_rq_complete(rq->q, rq);
314
315 while (bio) {
316 struct bio *next = bio->bi_next;
317
318 bio->bi_next = NULL;
319 bytes += bio->bi_iter.bi_size;
320 blk_mq_bio_endio(rq, bio, error);
321 bio = next;
322 }
323
324 blk_account_io_completion(rq, bytes);
325 290
326 blk_account_io_done(rq); 291 blk_account_io_done(rq);
327 292
@@ -329,49 +294,57 @@ void blk_mq_complete_request(struct request *rq, int error)
329 rq->end_io(rq, error); 294 rq->end_io(rq, error);
330 else 295 else
331 blk_mq_free_request(rq); 296 blk_mq_free_request(rq);
297 return false;
332} 298}
299EXPORT_SYMBOL(blk_mq_end_io_partial);
333 300
334void __blk_mq_end_io(struct request *rq, int error) 301static void __blk_mq_complete_request_remote(void *data)
335{
336 if (!blk_mark_rq_complete(rq))
337 blk_mq_complete_request(rq, error);
338}
339
340static void blk_mq_end_io_remote(void *data)
341{ 302{
342 struct request *rq = data; 303 struct request *rq = data;
343 304
344 __blk_mq_end_io(rq, rq->errors); 305 rq->q->softirq_done_fn(rq);
345} 306}
346 307
347/* 308void __blk_mq_complete_request(struct request *rq)
348 * End IO on this request on a multiqueue enabled driver. We'll either do
349 * it directly inline, or punt to a local IPI handler on the matching
350 * remote CPU.
351 */
352void blk_mq_end_io(struct request *rq, int error)
353{ 309{
354 struct blk_mq_ctx *ctx = rq->mq_ctx; 310 struct blk_mq_ctx *ctx = rq->mq_ctx;
355 int cpu; 311 int cpu;
356 312
357 if (!ctx->ipi_redirect) 313 if (!ctx->ipi_redirect) {
358 return __blk_mq_end_io(rq, error); 314 rq->q->softirq_done_fn(rq);
315 return;
316 }
359 317
360 cpu = get_cpu(); 318 cpu = get_cpu();
361 if (cpu != ctx->cpu && cpu_online(ctx->cpu)) { 319 if (cpu != ctx->cpu && cpu_online(ctx->cpu)) {
362 rq->errors = error; 320 rq->csd.func = __blk_mq_complete_request_remote;
363 rq->csd.func = blk_mq_end_io_remote;
364 rq->csd.info = rq; 321 rq->csd.info = rq;
365 rq->csd.flags = 0; 322 rq->csd.flags = 0;
366 __smp_call_function_single(ctx->cpu, &rq->csd, 0); 323 __smp_call_function_single(ctx->cpu, &rq->csd, 0);
367 } else { 324 } else {
368 __blk_mq_end_io(rq, error); 325 rq->q->softirq_done_fn(rq);
369 } 326 }
370 put_cpu(); 327 put_cpu();
371} 328}
372EXPORT_SYMBOL(blk_mq_end_io);
373 329
374static void blk_mq_start_request(struct request *rq) 330/**
331 * blk_mq_complete_request - end I/O on a request
332 * @rq: the request being processed
333 *
334 * Description:
335 * Ends all I/O on a request. It does not handle partial completions.
336 * The actual completion happens out-of-order, through a IPI handler.
337 **/
338void blk_mq_complete_request(struct request *rq)
339{
340 if (unlikely(blk_should_fake_timeout(rq->q)))
341 return;
342 if (!blk_mark_rq_complete(rq))
343 __blk_mq_complete_request(rq);
344}
345EXPORT_SYMBOL(blk_mq_complete_request);
346
347static void blk_mq_start_request(struct request *rq, bool last)
375{ 348{
376 struct request_queue *q = rq->q; 349 struct request_queue *q = rq->q;
377 350
@@ -384,6 +357,25 @@ static void blk_mq_start_request(struct request *rq)
384 */ 357 */
385 rq->deadline = jiffies + q->rq_timeout; 358 rq->deadline = jiffies + q->rq_timeout;
386 set_bit(REQ_ATOM_STARTED, &rq->atomic_flags); 359 set_bit(REQ_ATOM_STARTED, &rq->atomic_flags);
360
361 if (q->dma_drain_size && blk_rq_bytes(rq)) {
362 /*
363 * Make sure space for the drain appears. We know we can do
364 * this because max_hw_segments has been adjusted to be one
365 * fewer than the device can handle.
366 */
367 rq->nr_phys_segments++;
368 }
369
370 /*
371 * Flag the last request in the series so that drivers know when IO
372 * should be kicked off, if they don't do it on a per-request basis.
373 *
374 * Note: the flag isn't the only condition drivers should do kick off.
375 * If drive is busy, the last request might not have the bit set.
376 */
377 if (last)
378 rq->cmd_flags |= REQ_END;
387} 379}
388 380
389static void blk_mq_requeue_request(struct request *rq) 381static void blk_mq_requeue_request(struct request *rq)
@@ -392,6 +384,11 @@ static void blk_mq_requeue_request(struct request *rq)
392 384
393 trace_block_rq_requeue(q, rq); 385 trace_block_rq_requeue(q, rq);
394 clear_bit(REQ_ATOM_STARTED, &rq->atomic_flags); 386 clear_bit(REQ_ATOM_STARTED, &rq->atomic_flags);
387
388 rq->cmd_flags &= ~REQ_END;
389
390 if (q->dma_drain_size && blk_rq_bytes(rq))
391 rq->nr_phys_segments--;
395} 392}
396 393
397struct blk_mq_timeout_data { 394struct blk_mq_timeout_data {
@@ -559,19 +556,8 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
559 556
560 rq = list_first_entry(&rq_list, struct request, queuelist); 557 rq = list_first_entry(&rq_list, struct request, queuelist);
561 list_del_init(&rq->queuelist); 558 list_del_init(&rq->queuelist);
562 blk_mq_start_request(rq);
563 559
564 /* 560 blk_mq_start_request(rq, list_empty(&rq_list));
565 * Last request in the series. Flag it as such, this
566 * enables drivers to know when IO should be kicked off,
567 * if they don't do it on a per-request basis.
568 *
569 * Note: the flag isn't the only condition drivers
570 * should do kick off. If drive is busy, the last
571 * request might not have the bit set.
572 */
573 if (list_empty(&rq_list))
574 rq->cmd_flags |= REQ_END;
575 561
576 ret = q->mq_ops->queue_rq(hctx, rq); 562 ret = q->mq_ops->queue_rq(hctx, rq);
577 switch (ret) { 563 switch (ret) {
@@ -589,8 +575,8 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
589 break; 575 break;
590 default: 576 default:
591 pr_err("blk-mq: bad return on queue: %d\n", ret); 577 pr_err("blk-mq: bad return on queue: %d\n", ret);
592 rq->errors = -EIO;
593 case BLK_MQ_RQ_QUEUE_ERROR: 578 case BLK_MQ_RQ_QUEUE_ERROR:
579 rq->errors = -EIO;
594 blk_mq_end_io(rq, rq->errors); 580 blk_mq_end_io(rq, rq->errors);
595 break; 581 break;
596 } 582 }
@@ -693,13 +679,16 @@ static void blk_mq_work_fn(struct work_struct *work)
693} 679}
694 680
695static void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, 681static void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx,
696 struct request *rq) 682 struct request *rq, bool at_head)
697{ 683{
698 struct blk_mq_ctx *ctx = rq->mq_ctx; 684 struct blk_mq_ctx *ctx = rq->mq_ctx;
699 685
700 trace_block_rq_insert(hctx->queue, rq); 686 trace_block_rq_insert(hctx->queue, rq);
701 687
702 list_add_tail(&rq->queuelist, &ctx->rq_list); 688 if (at_head)
689 list_add(&rq->queuelist, &ctx->rq_list);
690 else
691 list_add_tail(&rq->queuelist, &ctx->rq_list);
703 blk_mq_hctx_mark_pending(hctx, ctx); 692 blk_mq_hctx_mark_pending(hctx, ctx);
704 693
705 /* 694 /*
@@ -708,61 +697,28 @@ static void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx,
708 blk_mq_add_timer(rq); 697 blk_mq_add_timer(rq);
709} 698}
710 699
711void blk_mq_insert_request(struct request_queue *q, struct request *rq, 700void blk_mq_insert_request(struct request *rq, bool at_head, bool run_queue,
712 bool run_queue) 701 bool async)
713{ 702{
703 struct request_queue *q = rq->q;
714 struct blk_mq_hw_ctx *hctx; 704 struct blk_mq_hw_ctx *hctx;
715 struct blk_mq_ctx *ctx, *current_ctx; 705 struct blk_mq_ctx *ctx = rq->mq_ctx, *current_ctx;
706
707 current_ctx = blk_mq_get_ctx(q);
708 if (!cpu_online(ctx->cpu))
709 rq->mq_ctx = ctx = current_ctx;
716 710
717 ctx = rq->mq_ctx;
718 hctx = q->mq_ops->map_queue(q, ctx->cpu); 711 hctx = q->mq_ops->map_queue(q, ctx->cpu);
719 712
720 if (rq->cmd_flags & (REQ_FLUSH | REQ_FUA)) { 713 if (rq->cmd_flags & (REQ_FLUSH | REQ_FUA) &&
714 !(rq->cmd_flags & (REQ_FLUSH_SEQ))) {
721 blk_insert_flush(rq); 715 blk_insert_flush(rq);
722 } else { 716 } else {
723 current_ctx = blk_mq_get_ctx(q);
724
725 if (!cpu_online(ctx->cpu)) {
726 ctx = current_ctx;
727 hctx = q->mq_ops->map_queue(q, ctx->cpu);
728 rq->mq_ctx = ctx;
729 }
730 spin_lock(&ctx->lock); 717 spin_lock(&ctx->lock);
731 __blk_mq_insert_request(hctx, rq); 718 __blk_mq_insert_request(hctx, rq, at_head);
732 spin_unlock(&ctx->lock); 719 spin_unlock(&ctx->lock);
733
734 blk_mq_put_ctx(current_ctx);
735 } 720 }
736 721
737 if (run_queue)
738 __blk_mq_run_hw_queue(hctx);
739}
740EXPORT_SYMBOL(blk_mq_insert_request);
741
742/*
743 * This is a special version of blk_mq_insert_request to bypass FLUSH request
744 * check. Should only be used internally.
745 */
746void blk_mq_run_request(struct request *rq, bool run_queue, bool async)
747{
748 struct request_queue *q = rq->q;
749 struct blk_mq_hw_ctx *hctx;
750 struct blk_mq_ctx *ctx, *current_ctx;
751
752 current_ctx = blk_mq_get_ctx(q);
753
754 ctx = rq->mq_ctx;
755 if (!cpu_online(ctx->cpu)) {
756 ctx = current_ctx;
757 rq->mq_ctx = ctx;
758 }
759 hctx = q->mq_ops->map_queue(q, ctx->cpu);
760
761 /* ctx->cpu might be offline */
762 spin_lock(&ctx->lock);
763 __blk_mq_insert_request(hctx, rq);
764 spin_unlock(&ctx->lock);
765
766 blk_mq_put_ctx(current_ctx); 722 blk_mq_put_ctx(current_ctx);
767 723
768 if (run_queue) 724 if (run_queue)
@@ -798,7 +754,7 @@ static void blk_mq_insert_requests(struct request_queue *q,
798 rq = list_first_entry(list, struct request, queuelist); 754 rq = list_first_entry(list, struct request, queuelist);
799 list_del_init(&rq->queuelist); 755 list_del_init(&rq->queuelist);
800 rq->mq_ctx = ctx; 756 rq->mq_ctx = ctx;
801 __blk_mq_insert_request(hctx, rq); 757 __blk_mq_insert_request(hctx, rq, false);
802 } 758 }
803 spin_unlock(&ctx->lock); 759 spin_unlock(&ctx->lock);
804 760
@@ -888,6 +844,11 @@ static void blk_mq_make_request(struct request_queue *q, struct bio *bio)
888 844
889 blk_queue_bounce(q, &bio); 845 blk_queue_bounce(q, &bio);
890 846
847 if (bio_integrity_enabled(bio) && bio_integrity_prep(bio)) {
848 bio_endio(bio, -EIO);
849 return;
850 }
851
891 if (use_plug && blk_attempt_plug_merge(q, bio, &request_count)) 852 if (use_plug && blk_attempt_plug_merge(q, bio, &request_count))
892 return; 853 return;
893 854
@@ -899,6 +860,8 @@ static void blk_mq_make_request(struct request_queue *q, struct bio *bio)
899 ctx = blk_mq_get_ctx(q); 860 ctx = blk_mq_get_ctx(q);
900 hctx = q->mq_ops->map_queue(q, ctx->cpu); 861 hctx = q->mq_ops->map_queue(q, ctx->cpu);
901 862
863 if (is_sync)
864 rw |= REQ_SYNC;
902 trace_block_getrq(q, bio, rw); 865 trace_block_getrq(q, bio, rw);
903 rq = __blk_mq_alloc_request(hctx, GFP_ATOMIC, false); 866 rq = __blk_mq_alloc_request(hctx, GFP_ATOMIC, false);
904 if (likely(rq)) 867 if (likely(rq))
@@ -950,7 +913,7 @@ static void blk_mq_make_request(struct request_queue *q, struct bio *bio)
950 __blk_mq_free_request(hctx, ctx, rq); 913 __blk_mq_free_request(hctx, ctx, rq);
951 else { 914 else {
952 blk_mq_bio_to_request(rq, bio); 915 blk_mq_bio_to_request(rq, bio);
953 __blk_mq_insert_request(hctx, rq); 916 __blk_mq_insert_request(hctx, rq, false);
954 } 917 }
955 918
956 spin_unlock(&ctx->lock); 919 spin_unlock(&ctx->lock);
@@ -1309,15 +1272,6 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_reg *reg,
1309 reg->queue_depth = BLK_MQ_MAX_DEPTH; 1272 reg->queue_depth = BLK_MQ_MAX_DEPTH;
1310 } 1273 }
1311 1274
1312 /*
1313 * Set aside a tag for flush requests. It will only be used while
1314 * another flush request is in progress but outside the driver.
1315 *
1316 * TODO: only allocate if flushes are supported
1317 */
1318 reg->queue_depth++;
1319 reg->reserved_tags++;
1320
1321 if (reg->queue_depth < (reg->reserved_tags + BLK_MQ_TAG_MIN)) 1275 if (reg->queue_depth < (reg->reserved_tags + BLK_MQ_TAG_MIN))
1322 return ERR_PTR(-EINVAL); 1276 return ERR_PTR(-EINVAL);
1323 1277
@@ -1360,17 +1314,27 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_reg *reg,
1360 q->mq_ops = reg->ops; 1314 q->mq_ops = reg->ops;
1361 q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT; 1315 q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT;
1362 1316
1317 q->sg_reserved_size = INT_MAX;
1318
1363 blk_queue_make_request(q, blk_mq_make_request); 1319 blk_queue_make_request(q, blk_mq_make_request);
1364 blk_queue_rq_timed_out(q, reg->ops->timeout); 1320 blk_queue_rq_timed_out(q, reg->ops->timeout);
1365 if (reg->timeout) 1321 if (reg->timeout)
1366 blk_queue_rq_timeout(q, reg->timeout); 1322 blk_queue_rq_timeout(q, reg->timeout);
1367 1323
1324 if (reg->ops->complete)
1325 blk_queue_softirq_done(q, reg->ops->complete);
1326
1368 blk_mq_init_flush(q); 1327 blk_mq_init_flush(q);
1369 blk_mq_init_cpu_queues(q, reg->nr_hw_queues); 1328 blk_mq_init_cpu_queues(q, reg->nr_hw_queues);
1370 1329
1371 if (blk_mq_init_hw_queues(q, reg, driver_data)) 1330 q->flush_rq = kzalloc(round_up(sizeof(struct request) + reg->cmd_size,
1331 cache_line_size()), GFP_KERNEL);
1332 if (!q->flush_rq)
1372 goto err_hw; 1333 goto err_hw;
1373 1334
1335 if (blk_mq_init_hw_queues(q, reg, driver_data))
1336 goto err_flush_rq;
1337
1374 blk_mq_map_swqueue(q); 1338 blk_mq_map_swqueue(q);
1375 1339
1376 mutex_lock(&all_q_mutex); 1340 mutex_lock(&all_q_mutex);
@@ -1378,6 +1342,9 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_reg *reg,
1378 mutex_unlock(&all_q_mutex); 1342 mutex_unlock(&all_q_mutex);
1379 1343
1380 return q; 1344 return q;
1345
1346err_flush_rq:
1347 kfree(q->flush_rq);
1381err_hw: 1348err_hw:
1382 kfree(q->mq_map); 1349 kfree(q->mq_map);
1383err_map: 1350err_map:
diff --git a/block/blk-mq.h b/block/blk-mq.h
index 5c3917984b00..72beba1f9d55 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -22,13 +22,12 @@ struct blk_mq_ctx {
22 struct kobject kobj; 22 struct kobject kobj;
23}; 23};
24 24
25void __blk_mq_end_io(struct request *rq, int error); 25void __blk_mq_complete_request(struct request *rq);
26void blk_mq_complete_request(struct request *rq, int error);
27void blk_mq_run_request(struct request *rq, bool run_queue, bool async);
28void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async); 26void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
29void blk_mq_init_flush(struct request_queue *q); 27void blk_mq_init_flush(struct request_queue *q);
30void blk_mq_drain_queue(struct request_queue *q); 28void blk_mq_drain_queue(struct request_queue *q);
31void blk_mq_free_queue(struct request_queue *q); 29void blk_mq_free_queue(struct request_queue *q);
30void blk_mq_rq_init(struct blk_mq_hw_ctx *hctx, struct request *rq);
32 31
33/* 32/*
34 * CPU hotplug helpers 33 * CPU hotplug helpers
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 8095c4a21fc0..7500f876dae4 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -549,6 +549,8 @@ static void blk_release_queue(struct kobject *kobj)
549 if (q->mq_ops) 549 if (q->mq_ops)
550 blk_mq_free_queue(q); 550 blk_mq_free_queue(q);
551 551
552 kfree(q->flush_rq);
553
552 blk_trace_shutdown(q); 554 blk_trace_shutdown(q);
553 555
554 bdi_destroy(&q->backing_dev_info); 556 bdi_destroy(&q->backing_dev_info);
diff --git a/block/blk-timeout.c b/block/blk-timeout.c
index bba81c9348e1..d96f7061c6fd 100644
--- a/block/blk-timeout.c
+++ b/block/blk-timeout.c
@@ -91,7 +91,7 @@ static void blk_rq_timed_out(struct request *req)
91 case BLK_EH_HANDLED: 91 case BLK_EH_HANDLED:
92 /* Can we use req->errors here? */ 92 /* Can we use req->errors here? */
93 if (q->mq_ops) 93 if (q->mq_ops)
94 blk_mq_complete_request(req, req->errors); 94 __blk_mq_complete_request(req);
95 else 95 else
96 __blk_complete_request(req); 96 __blk_complete_request(req);
97 break; 97 break;
diff --git a/block/blk.h b/block/blk.h
index c90e1d8f7a2b..d23b415b8a28 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -113,7 +113,7 @@ static inline struct request *__elv_next_request(struct request_queue *q)
113 q->flush_queue_delayed = 1; 113 q->flush_queue_delayed = 1;
114 return NULL; 114 return NULL;
115 } 115 }
116 if (unlikely(blk_queue_dying(q)) || 116 if (unlikely(blk_queue_bypass(q)) ||
117 !q->elevator->type->ops.elevator_dispatch_fn(q, 0)) 117 !q->elevator->type->ops.elevator_dispatch_fn(q, 0))
118 return NULL; 118 return NULL;
119 } 119 }
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index e7515aa43d6b..6f190bc2b8b7 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -243,6 +243,8 @@ static int acpi_ac_resume(struct device *dev)
243 kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); 243 kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
244 return 0; 244 return 0;
245} 245}
246#else
247#define acpi_ac_resume NULL
246#endif 248#endif
247static SIMPLE_DEV_PM_OPS(acpi_ac_pm_ops, NULL, acpi_ac_resume); 249static SIMPLE_DEV_PM_OPS(acpi_ac_pm_ops, NULL, acpi_ac_resume);
248 250
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 470e7542bf31..797a6938d051 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -549,7 +549,7 @@ static ssize_t acpi_battery_alarm_store(struct device *dev,
549{ 549{
550 unsigned long x; 550 unsigned long x;
551 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); 551 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
552 if (sscanf(buf, "%ld\n", &x) == 1) 552 if (sscanf(buf, "%lu\n", &x) == 1)
553 battery->alarm = x/1000; 553 battery->alarm = x/1000;
554 if (acpi_battery_present(battery)) 554 if (acpi_battery_present(battery))
555 acpi_battery_set_alarm(battery); 555 acpi_battery_set_alarm(battery);
@@ -841,6 +841,8 @@ static int acpi_battery_resume(struct device *dev)
841 acpi_battery_update(battery); 841 acpi_battery_update(battery);
842 return 0; 842 return 0;
843} 843}
844#else
845#define acpi_battery_resume NULL
844#endif 846#endif
845 847
846static SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume); 848static SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume);
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index 10e4964d051a..afec4526c48a 100644
--- a/drivers/acpi/blacklist.c
+++ b/drivers/acpi/blacklist.c
@@ -260,14 +260,6 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
260 }, 260 },
261 { 261 {
262 .callback = dmi_disable_osi_win8, 262 .callback = dmi_disable_osi_win8,
263 .ident = "Dell Inspiron 15R SE",
264 .matches = {
265 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
266 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7520"),
267 },
268 },
269 {
270 .callback = dmi_disable_osi_win8,
271 .ident = "ThinkPad Edge E530", 263 .ident = "ThinkPad Edge E530",
272 .matches = { 264 .matches = {
273 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 265 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
@@ -322,56 +314,6 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
322 DMI_MATCH(DMI_PRODUCT_VERSION, "2349D15"), 314 DMI_MATCH(DMI_PRODUCT_VERSION, "2349D15"),
323 }, 315 },
324 }, 316 },
325 {
326 .callback = dmi_disable_osi_win8,
327 .ident = "HP ProBook 2013 models",
328 .matches = {
329 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
330 DMI_MATCH(DMI_PRODUCT_NAME, "HP ProBook "),
331 DMI_MATCH(DMI_PRODUCT_NAME, " G1"),
332 },
333 },
334 {
335 .callback = dmi_disable_osi_win8,
336 .ident = "HP EliteBook 2013 models",
337 .matches = {
338 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
339 DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook "),
340 DMI_MATCH(DMI_PRODUCT_NAME, " G1"),
341 },
342 },
343 {
344 .callback = dmi_disable_osi_win8,
345 .ident = "HP ZBook 14",
346 .matches = {
347 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
348 DMI_MATCH(DMI_PRODUCT_NAME, "HP ZBook 14"),
349 },
350 },
351 {
352 .callback = dmi_disable_osi_win8,
353 .ident = "HP ZBook 15",
354 .matches = {
355 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
356 DMI_MATCH(DMI_PRODUCT_NAME, "HP ZBook 15"),
357 },
358 },
359 {
360 .callback = dmi_disable_osi_win8,
361 .ident = "HP ZBook 17",
362 .matches = {
363 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
364 DMI_MATCH(DMI_PRODUCT_NAME, "HP ZBook 17"),
365 },
366 },
367 {
368 .callback = dmi_disable_osi_win8,
369 .ident = "HP EliteBook 8780w",
370 .matches = {
371 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
372 DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook 8780w"),
373 },
374 },
375 317
376 /* 318 /*
377 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug. 319 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug.
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 11c11f6b8fa1..714e957a871a 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -80,6 +80,8 @@ static void acpi_button_notify(struct acpi_device *device, u32 event);
80 80
81#ifdef CONFIG_PM_SLEEP 81#ifdef CONFIG_PM_SLEEP
82static int acpi_button_resume(struct device *dev); 82static int acpi_button_resume(struct device *dev);
83#else
84#define acpi_button_resume NULL
83#endif 85#endif
84static SIMPLE_DEV_PM_OPS(acpi_button_pm, NULL, acpi_button_resume); 86static SIMPLE_DEV_PM_OPS(acpi_button_pm, NULL, acpi_button_resume);
85 87
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 0b6ae6eb5c4a..368f9ddb8480 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -79,9 +79,10 @@ static int container_device_attach(struct acpi_device *adev,
79 ACPI_COMPANION_SET(dev, adev); 79 ACPI_COMPANION_SET(dev, adev);
80 dev->release = acpi_container_release; 80 dev->release = acpi_container_release;
81 ret = device_register(dev); 81 ret = device_register(dev);
82 if (ret) 82 if (ret) {
83 put_device(dev);
83 return ret; 84 return ret;
84 85 }
85 adev->driver_data = dev; 86 adev->driver_data = dev;
86 return 1; 87 return 1;
87} 88}
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index c431c88faaff..5bfd769fc91f 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -609,7 +609,7 @@ static int handle_eject_request(struct dock_station *ds, u32 event)
609static void dock_notify(struct dock_station *ds, u32 event) 609static void dock_notify(struct dock_station *ds, u32 event)
610{ 610{
611 acpi_handle handle = ds->handle; 611 acpi_handle handle = ds->handle;
612 struct acpi_device *ad; 612 struct acpi_device *adev = NULL;
613 int surprise_removal = 0; 613 int surprise_removal = 0;
614 614
615 /* 615 /*
@@ -632,7 +632,8 @@ static void dock_notify(struct dock_station *ds, u32 event)
632 switch (event) { 632 switch (event) {
633 case ACPI_NOTIFY_BUS_CHECK: 633 case ACPI_NOTIFY_BUS_CHECK:
634 case ACPI_NOTIFY_DEVICE_CHECK: 634 case ACPI_NOTIFY_DEVICE_CHECK:
635 if (!dock_in_progress(ds) && acpi_bus_get_device(handle, &ad)) { 635 acpi_bus_get_device(handle, &adev);
636 if (!dock_in_progress(ds) && !acpi_device_enumerated(adev)) {
636 begin_dock(ds); 637 begin_dock(ds);
637 dock(ds); 638 dock(ds);
638 if (!dock_present(ds)) { 639 if (!dock_present(ds)) {
@@ -712,13 +713,11 @@ static acpi_status __init find_dock_devices(acpi_handle handle, u32 lvl,
712static ssize_t show_docked(struct device *dev, 713static ssize_t show_docked(struct device *dev,
713 struct device_attribute *attr, char *buf) 714 struct device_attribute *attr, char *buf)
714{ 715{
715 struct acpi_device *tmp;
716
717 struct dock_station *dock_station = dev->platform_data; 716 struct dock_station *dock_station = dev->platform_data;
717 struct acpi_device *adev = NULL;
718 718
719 if (!acpi_bus_get_device(dock_station->handle, &tmp)) 719 acpi_bus_get_device(dock_station->handle, &adev);
720 return snprintf(buf, PAGE_SIZE, "1\n"); 720 return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev));
721 return snprintf(buf, PAGE_SIZE, "0\n");
722} 721}
723static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); 722static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
724 723
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 959d41acc108..d7d32c28829b 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -67,6 +67,8 @@ enum ec_command {
67#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ 67#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
68#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 68#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
69#define ACPI_EC_MSI_UDELAY 550 /* Wait 550us for MSI EC */ 69#define ACPI_EC_MSI_UDELAY 550 /* Wait 550us for MSI EC */
70#define ACPI_EC_CLEAR_MAX 100 /* Maximum number of events to query
71 * when trying to clear the EC */
70 72
71enum { 73enum {
72 EC_FLAGS_QUERY_PENDING, /* Query is pending */ 74 EC_FLAGS_QUERY_PENDING, /* Query is pending */
@@ -116,6 +118,7 @@ EXPORT_SYMBOL(first_ec);
116static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */ 118static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */
117static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */ 119static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */
118static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */ 120static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */
121static int EC_FLAGS_CLEAR_ON_RESUME; /* Needs acpi_ec_clear() on boot/resume */
119 122
120/* -------------------------------------------------------------------------- 123/* --------------------------------------------------------------------------
121 Transaction Management 124 Transaction Management
@@ -440,6 +443,29 @@ acpi_handle ec_get_handle(void)
440 443
441EXPORT_SYMBOL(ec_get_handle); 444EXPORT_SYMBOL(ec_get_handle);
442 445
446static int acpi_ec_query_unlocked(struct acpi_ec *ec, u8 *data);
447
448/*
449 * Clears stale _Q events that might have accumulated in the EC.
450 * Run with locked ec mutex.
451 */
452static void acpi_ec_clear(struct acpi_ec *ec)
453{
454 int i, status;
455 u8 value = 0;
456
457 for (i = 0; i < ACPI_EC_CLEAR_MAX; i++) {
458 status = acpi_ec_query_unlocked(ec, &value);
459 if (status || !value)
460 break;
461 }
462
463 if (unlikely(i == ACPI_EC_CLEAR_MAX))
464 pr_warn("Warning: Maximum of %d stale EC events cleared\n", i);
465 else
466 pr_info("%d stale EC events cleared\n", i);
467}
468
443void acpi_ec_block_transactions(void) 469void acpi_ec_block_transactions(void)
444{ 470{
445 struct acpi_ec *ec = first_ec; 471 struct acpi_ec *ec = first_ec;
@@ -463,6 +489,10 @@ void acpi_ec_unblock_transactions(void)
463 mutex_lock(&ec->mutex); 489 mutex_lock(&ec->mutex);
464 /* Allow transactions to be carried out again */ 490 /* Allow transactions to be carried out again */
465 clear_bit(EC_FLAGS_BLOCKED, &ec->flags); 491 clear_bit(EC_FLAGS_BLOCKED, &ec->flags);
492
493 if (EC_FLAGS_CLEAR_ON_RESUME)
494 acpi_ec_clear(ec);
495
466 mutex_unlock(&ec->mutex); 496 mutex_unlock(&ec->mutex);
467} 497}
468 498
@@ -821,6 +851,13 @@ static int acpi_ec_add(struct acpi_device *device)
821 851
822 /* EC is fully operational, allow queries */ 852 /* EC is fully operational, allow queries */
823 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); 853 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
854
855 /* Clear stale _Q events if hardware might require that */
856 if (EC_FLAGS_CLEAR_ON_RESUME) {
857 mutex_lock(&ec->mutex);
858 acpi_ec_clear(ec);
859 mutex_unlock(&ec->mutex);
860 }
824 return ret; 861 return ret;
825} 862}
826 863
@@ -922,6 +959,30 @@ static int ec_enlarge_storm_threshold(const struct dmi_system_id *id)
922 return 0; 959 return 0;
923} 960}
924 961
962/*
963 * On some hardware it is necessary to clear events accumulated by the EC during
964 * sleep. These ECs stop reporting GPEs until they are manually polled, if too
965 * many events are accumulated. (e.g. Samsung Series 5/9 notebooks)
966 *
967 * https://bugzilla.kernel.org/show_bug.cgi?id=44161
968 *
969 * Ideally, the EC should also be instructed NOT to accumulate events during
970 * sleep (which Windows seems to do somehow), but the interface to control this
971 * behaviour is not known at this time.
972 *
973 * Models known to be affected are Samsung 530Uxx/535Uxx/540Uxx/550Pxx/900Xxx,
974 * however it is very likely that other Samsung models are affected.
975 *
976 * On systems which don't accumulate _Q events during sleep, this extra check
977 * should be harmless.
978 */
979static int ec_clear_on_resume(const struct dmi_system_id *id)
980{
981 pr_debug("Detected system needing EC poll on resume.\n");
982 EC_FLAGS_CLEAR_ON_RESUME = 1;
983 return 0;
984}
985
925static struct dmi_system_id ec_dmi_table[] __initdata = { 986static struct dmi_system_id ec_dmi_table[] __initdata = {
926 { 987 {
927 ec_skip_dsdt_scan, "Compal JFL92", { 988 ec_skip_dsdt_scan, "Compal JFL92", {
@@ -965,6 +1026,9 @@ static struct dmi_system_id ec_dmi_table[] __initdata = {
965 ec_validate_ecdt, "ASUS hardware", { 1026 ec_validate_ecdt, "ASUS hardware", {
966 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTek Computer Inc."), 1027 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTek Computer Inc."),
967 DMI_MATCH(DMI_PRODUCT_NAME, "L4R"),}, NULL}, 1028 DMI_MATCH(DMI_PRODUCT_NAME, "L4R"),}, NULL},
1029 {
1030 ec_clear_on_resume, "Samsung hardware", {
1031 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD.")}, NULL},
968 {}, 1032 {},
969}; 1033};
970 1034
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 1fb62900f32a..09e423f3d8ad 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -55,6 +55,9 @@ MODULE_DEVICE_TABLE(acpi, fan_device_ids);
55#ifdef CONFIG_PM_SLEEP 55#ifdef CONFIG_PM_SLEEP
56static int acpi_fan_suspend(struct device *dev); 56static int acpi_fan_suspend(struct device *dev);
57static int acpi_fan_resume(struct device *dev); 57static int acpi_fan_resume(struct device *dev);
58#else
59#define acpi_fan_suspend NULL
60#define acpi_fan_resume NULL
58#endif 61#endif
59static SIMPLE_DEV_PM_OPS(acpi_fan_pm, acpi_fan_suspend, acpi_fan_resume); 62static SIMPLE_DEV_PM_OPS(acpi_fan_pm, acpi_fan_suspend, acpi_fan_resume);
60 63
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index 52d45ea2bc4f..361b40c10c3f 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -430,6 +430,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
430 pin_name(pin)); 430 pin_name(pin));
431 } 431 }
432 432
433 kfree(entry);
433 return 0; 434 return 0;
434 } 435 }
435 436
diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
index 50fe34ffe932..75c28eae8860 100644
--- a/drivers/acpi/proc.c
+++ b/drivers/acpi/proc.c
@@ -60,7 +60,7 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
60 seq_printf(seq, "%c%-8s %s:%s\n", 60 seq_printf(seq, "%c%-8s %s:%s\n",
61 dev->wakeup.flags.run_wake ? '*' : ' ', 61 dev->wakeup.flags.run_wake ? '*' : ' ',
62 (device_may_wakeup(&dev->dev) || 62 (device_may_wakeup(&dev->dev) ||
63 (ldev && device_may_wakeup(ldev))) ? 63 device_may_wakeup(ldev)) ?
64 "enabled" : "disabled", 64 "enabled" : "disabled",
65 ldev->bus ? ldev->bus->name : 65 ldev->bus ? ldev->bus->name :
66 "no-bus", dev_name(ldev)); 66 "no-bus", dev_name(ldev));
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 28baa05b8018..84243c32e29c 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -56,6 +56,12 @@ struct throttling_tstate {
56 int target_state; /* target T-state */ 56 int target_state; /* target T-state */
57}; 57};
58 58
59struct acpi_processor_throttling_arg {
60 struct acpi_processor *pr;
61 int target_state;
62 bool force;
63};
64
59#define THROTTLING_PRECHANGE (1) 65#define THROTTLING_PRECHANGE (1)
60#define THROTTLING_POSTCHANGE (2) 66#define THROTTLING_POSTCHANGE (2)
61 67
@@ -1060,16 +1066,24 @@ static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
1060 return 0; 1066 return 0;
1061} 1067}
1062 1068
1069static long acpi_processor_throttling_fn(void *data)
1070{
1071 struct acpi_processor_throttling_arg *arg = data;
1072 struct acpi_processor *pr = arg->pr;
1073
1074 return pr->throttling.acpi_processor_set_throttling(pr,
1075 arg->target_state, arg->force);
1076}
1077
1063int acpi_processor_set_throttling(struct acpi_processor *pr, 1078int acpi_processor_set_throttling(struct acpi_processor *pr,
1064 int state, bool force) 1079 int state, bool force)
1065{ 1080{
1066 cpumask_var_t saved_mask;
1067 int ret = 0; 1081 int ret = 0;
1068 unsigned int i; 1082 unsigned int i;
1069 struct acpi_processor *match_pr; 1083 struct acpi_processor *match_pr;
1070 struct acpi_processor_throttling *p_throttling; 1084 struct acpi_processor_throttling *p_throttling;
1085 struct acpi_processor_throttling_arg arg;
1071 struct throttling_tstate t_state; 1086 struct throttling_tstate t_state;
1072 cpumask_var_t online_throttling_cpus;
1073 1087
1074 if (!pr) 1088 if (!pr)
1075 return -EINVAL; 1089 return -EINVAL;
@@ -1080,14 +1094,6 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1080 if ((state < 0) || (state > (pr->throttling.state_count - 1))) 1094 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
1081 return -EINVAL; 1095 return -EINVAL;
1082 1096
1083 if (!alloc_cpumask_var(&saved_mask, GFP_KERNEL))
1084 return -ENOMEM;
1085
1086 if (!alloc_cpumask_var(&online_throttling_cpus, GFP_KERNEL)) {
1087 free_cpumask_var(saved_mask);
1088 return -ENOMEM;
1089 }
1090
1091 if (cpu_is_offline(pr->id)) { 1097 if (cpu_is_offline(pr->id)) {
1092 /* 1098 /*
1093 * the cpu pointed by pr->id is offline. Unnecessary to change 1099 * the cpu pointed by pr->id is offline. Unnecessary to change
@@ -1096,17 +1102,15 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1096 return -ENODEV; 1102 return -ENODEV;
1097 } 1103 }
1098 1104
1099 cpumask_copy(saved_mask, &current->cpus_allowed);
1100 t_state.target_state = state; 1105 t_state.target_state = state;
1101 p_throttling = &(pr->throttling); 1106 p_throttling = &(pr->throttling);
1102 cpumask_and(online_throttling_cpus, cpu_online_mask, 1107
1103 p_throttling->shared_cpu_map);
1104 /* 1108 /*
1105 * The throttling notifier will be called for every 1109 * The throttling notifier will be called for every
1106 * affected cpu in order to get one proper T-state. 1110 * affected cpu in order to get one proper T-state.
1107 * The notifier event is THROTTLING_PRECHANGE. 1111 * The notifier event is THROTTLING_PRECHANGE.
1108 */ 1112 */
1109 for_each_cpu(i, online_throttling_cpus) { 1113 for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
1110 t_state.cpu = i; 1114 t_state.cpu = i;
1111 acpi_processor_throttling_notifier(THROTTLING_PRECHANGE, 1115 acpi_processor_throttling_notifier(THROTTLING_PRECHANGE,
1112 &t_state); 1116 &t_state);
@@ -1118,21 +1122,18 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1118 * it can be called only for the cpu pointed by pr. 1122 * it can be called only for the cpu pointed by pr.
1119 */ 1123 */
1120 if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) { 1124 if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) {
1121 /* FIXME: use work_on_cpu() */ 1125 arg.pr = pr;
1122 if (set_cpus_allowed_ptr(current, cpumask_of(pr->id))) { 1126 arg.target_state = state;
1123 /* Can't migrate to the pr->id CPU. Exit */ 1127 arg.force = force;
1124 ret = -ENODEV; 1128 ret = work_on_cpu(pr->id, acpi_processor_throttling_fn, &arg);
1125 goto exit;
1126 }
1127 ret = p_throttling->acpi_processor_set_throttling(pr,
1128 t_state.target_state, force);
1129 } else { 1129 } else {
1130 /* 1130 /*
1131 * When the T-state coordination is SW_ALL or HW_ALL, 1131 * When the T-state coordination is SW_ALL or HW_ALL,
1132 * it is necessary to set T-state for every affected 1132 * it is necessary to set T-state for every affected
1133 * cpus. 1133 * cpus.
1134 */ 1134 */
1135 for_each_cpu(i, online_throttling_cpus) { 1135 for_each_cpu_and(i, cpu_online_mask,
1136 p_throttling->shared_cpu_map) {
1136 match_pr = per_cpu(processors, i); 1137 match_pr = per_cpu(processors, i);
1137 /* 1138 /*
1138 * If the pointer is invalid, we will report the 1139 * If the pointer is invalid, we will report the
@@ -1153,13 +1154,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1153 "on CPU %d\n", i)); 1154 "on CPU %d\n", i));
1154 continue; 1155 continue;
1155 } 1156 }
1156 t_state.cpu = i; 1157
1157 /* FIXME: use work_on_cpu() */ 1158 arg.pr = match_pr;
1158 if (set_cpus_allowed_ptr(current, cpumask_of(i))) 1159 arg.target_state = state;
1159 continue; 1160 arg.force = force;
1160 ret = match_pr->throttling. 1161 ret = work_on_cpu(pr->id, acpi_processor_throttling_fn,
1161 acpi_processor_set_throttling( 1162 &arg);
1162 match_pr, t_state.target_state, force);
1163 } 1163 }
1164 } 1164 }
1165 /* 1165 /*
@@ -1168,17 +1168,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1168 * affected cpu to update the T-states. 1168 * affected cpu to update the T-states.
1169 * The notifier event is THROTTLING_POSTCHANGE 1169 * The notifier event is THROTTLING_POSTCHANGE
1170 */ 1170 */
1171 for_each_cpu(i, online_throttling_cpus) { 1171 for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
1172 t_state.cpu = i; 1172 t_state.cpu = i;
1173 acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE, 1173 acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE,
1174 &t_state); 1174 &t_state);
1175 } 1175 }
1176 /* restore the previous state */ 1176
1177 /* FIXME: use work_on_cpu() */
1178 set_cpus_allowed_ptr(current, saved_mask);
1179exit:
1180 free_cpumask_var(online_throttling_cpus);
1181 free_cpumask_var(saved_mask);
1182 return ret; 1177 return ret;
1183} 1178}
1184 1179
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index b7201fc6f1e1..0bdacc5e26a3 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -77,18 +77,24 @@ bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res)
77 switch (ares->type) { 77 switch (ares->type) {
78 case ACPI_RESOURCE_TYPE_MEMORY24: 78 case ACPI_RESOURCE_TYPE_MEMORY24:
79 memory24 = &ares->data.memory24; 79 memory24 = &ares->data.memory24;
80 if (!memory24->address_length)
81 return false;
80 acpi_dev_get_memresource(res, memory24->minimum, 82 acpi_dev_get_memresource(res, memory24->minimum,
81 memory24->address_length, 83 memory24->address_length,
82 memory24->write_protect); 84 memory24->write_protect);
83 break; 85 break;
84 case ACPI_RESOURCE_TYPE_MEMORY32: 86 case ACPI_RESOURCE_TYPE_MEMORY32:
85 memory32 = &ares->data.memory32; 87 memory32 = &ares->data.memory32;
88 if (!memory32->address_length)
89 return false;
86 acpi_dev_get_memresource(res, memory32->minimum, 90 acpi_dev_get_memresource(res, memory32->minimum,
87 memory32->address_length, 91 memory32->address_length,
88 memory32->write_protect); 92 memory32->write_protect);
89 break; 93 break;
90 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 94 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
91 fixed_memory32 = &ares->data.fixed_memory32; 95 fixed_memory32 = &ares->data.fixed_memory32;
96 if (!fixed_memory32->address_length)
97 return false;
92 acpi_dev_get_memresource(res, fixed_memory32->address, 98 acpi_dev_get_memresource(res, fixed_memory32->address,
93 fixed_memory32->address_length, 99 fixed_memory32->address_length,
94 fixed_memory32->write_protect); 100 fixed_memory32->write_protect);
@@ -144,12 +150,16 @@ bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res)
144 switch (ares->type) { 150 switch (ares->type) {
145 case ACPI_RESOURCE_TYPE_IO: 151 case ACPI_RESOURCE_TYPE_IO:
146 io = &ares->data.io; 152 io = &ares->data.io;
153 if (!io->address_length)
154 return false;
147 acpi_dev_get_ioresource(res, io->minimum, 155 acpi_dev_get_ioresource(res, io->minimum,
148 io->address_length, 156 io->address_length,
149 io->io_decode); 157 io->io_decode);
150 break; 158 break;
151 case ACPI_RESOURCE_TYPE_FIXED_IO: 159 case ACPI_RESOURCE_TYPE_FIXED_IO:
152 fixed_io = &ares->data.fixed_io; 160 fixed_io = &ares->data.fixed_io;
161 if (!fixed_io->address_length)
162 return false;
153 acpi_dev_get_ioresource(res, fixed_io->address, 163 acpi_dev_get_ioresource(res, fixed_io->address,
154 fixed_io->address_length, 164 fixed_io->address_length,
155 ACPI_DECODE_10); 165 ACPI_DECODE_10);
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index d465ae6cdd00..dbd48498b938 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -450,7 +450,7 @@ static ssize_t acpi_battery_alarm_store(struct device *dev,
450{ 450{
451 unsigned long x; 451 unsigned long x;
452 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); 452 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
453 if (sscanf(buf, "%ld\n", &x) == 1) 453 if (sscanf(buf, "%lu\n", &x) == 1)
454 battery->alarm_capacity = x / 454 battery->alarm_capacity = x /
455 (1000 * acpi_battery_scale(battery)); 455 (1000 * acpi_battery_scale(battery));
456 if (battery->present) 456 if (battery->present)
@@ -668,6 +668,8 @@ static int acpi_sbs_resume(struct device *dev)
668 acpi_sbs_callback(sbs); 668 acpi_sbs_callback(sbs);
669 return 0; 669 return 0;
670} 670}
671#else
672#define acpi_sbs_resume NULL
671#endif 673#endif
672 674
673static SIMPLE_DEV_PM_OPS(acpi_sbs_pm, NULL, acpi_sbs_resume); 675static SIMPLE_DEV_PM_OPS(acpi_sbs_pm, NULL, acpi_sbs_resume);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 7384158c7f87..57b053f424d1 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -484,7 +484,6 @@ static void acpi_device_hotplug(void *data, u32 src)
484static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data) 484static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
485{ 485{
486 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; 486 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
487 struct acpi_scan_handler *handler = data;
488 struct acpi_device *adev; 487 struct acpi_device *adev;
489 acpi_status status; 488 acpi_status status;
490 489
@@ -500,7 +499,10 @@ static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
500 break; 499 break;
501 case ACPI_NOTIFY_EJECT_REQUEST: 500 case ACPI_NOTIFY_EJECT_REQUEST:
502 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); 501 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
503 if (!handler->hotplug.enabled) { 502 if (!adev->handler)
503 goto err_out;
504
505 if (!adev->handler->hotplug.enabled) {
504 acpi_handle_err(handle, "Eject disabled\n"); 506 acpi_handle_err(handle, "Eject disabled\n");
505 ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED; 507 ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
506 goto err_out; 508 goto err_out;
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index b718806657cd..c40fb2e81bbc 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -71,6 +71,17 @@ static int acpi_sleep_prepare(u32 acpi_state)
71 return 0; 71 return 0;
72} 72}
73 73
74static bool acpi_sleep_state_supported(u8 sleep_state)
75{
76 acpi_status status;
77 u8 type_a, type_b;
78
79 status = acpi_get_sleep_type_data(sleep_state, &type_a, &type_b);
80 return ACPI_SUCCESS(status) && (!acpi_gbl_reduced_hardware
81 || (acpi_gbl_FADT.sleep_control.address
82 && acpi_gbl_FADT.sleep_status.address));
83}
84
74#ifdef CONFIG_ACPI_SLEEP 85#ifdef CONFIG_ACPI_SLEEP
75static u32 acpi_target_sleep_state = ACPI_STATE_S0; 86static u32 acpi_target_sleep_state = ACPI_STATE_S0;
76 87
@@ -604,15 +615,9 @@ static void acpi_sleep_suspend_setup(void)
604{ 615{
605 int i; 616 int i;
606 617
607 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) { 618 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++)
608 acpi_status status; 619 if (acpi_sleep_state_supported(i))
609 u8 type_a, type_b;
610
611 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
612 if (ACPI_SUCCESS(status)) {
613 sleep_states[i] = 1; 620 sleep_states[i] = 1;
614 }
615 }
616 621
617 suspend_set_ops(old_suspend_ordering ? 622 suspend_set_ops(old_suspend_ordering ?
618 &acpi_suspend_ops_old : &acpi_suspend_ops); 623 &acpi_suspend_ops_old : &acpi_suspend_ops);
@@ -740,11 +745,7 @@ static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
740 745
741static void acpi_sleep_hibernate_setup(void) 746static void acpi_sleep_hibernate_setup(void)
742{ 747{
743 acpi_status status; 748 if (!acpi_sleep_state_supported(ACPI_STATE_S4))
744 u8 type_a, type_b;
745
746 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
747 if (ACPI_FAILURE(status))
748 return; 749 return;
749 750
750 hibernation_set_ops(old_suspend_ordering ? 751 hibernation_set_ops(old_suspend_ordering ?
@@ -793,8 +794,6 @@ static void acpi_power_off(void)
793 794
794int __init acpi_sleep_init(void) 795int __init acpi_sleep_init(void)
795{ 796{
796 acpi_status status;
797 u8 type_a, type_b;
798 char supported[ACPI_S_STATE_COUNT * 3 + 1]; 797 char supported[ACPI_S_STATE_COUNT * 3 + 1];
799 char *pos = supported; 798 char *pos = supported;
800 int i; 799 int i;
@@ -806,8 +805,7 @@ int __init acpi_sleep_init(void)
806 acpi_sleep_suspend_setup(); 805 acpi_sleep_suspend_setup();
807 acpi_sleep_hibernate_setup(); 806 acpi_sleep_hibernate_setup();
808 807
809 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); 808 if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
810 if (ACPI_SUCCESS(status)) {
811 sleep_states[ACPI_STATE_S5] = 1; 809 sleep_states[ACPI_STATE_S5] = 1;
812 pm_power_off_prepare = acpi_power_off_prepare; 810 pm_power_off_prepare = acpi_power_off_prepare;
813 pm_power_off = acpi_power_off; 811 pm_power_off = acpi_power_off;
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 8349a555b92b..08626c851be7 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -102,6 +102,8 @@ MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
102 102
103#ifdef CONFIG_PM_SLEEP 103#ifdef CONFIG_PM_SLEEP
104static int acpi_thermal_resume(struct device *dev); 104static int acpi_thermal_resume(struct device *dev);
105#else
106#define acpi_thermal_resume NULL
105#endif 107#endif
106static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume); 108static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume);
107 109
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 0347a37eb438..85e3b612bdc0 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -99,10 +99,6 @@ acpi_extract_package(union acpi_object *package,
99 99
100 union acpi_object *element = &(package->package.elements[i]); 100 union acpi_object *element = &(package->package.elements[i]);
101 101
102 if (!element) {
103 return AE_BAD_DATA;
104 }
105
106 switch (element->type) { 102 switch (element->type) {
107 103
108 case ACPI_TYPE_INTEGER: 104 case ACPI_TYPE_INTEGER:
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index b727d105046d..b6ba88ed31ae 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -81,11 +81,12 @@ static bool allow_duplicates;
81module_param(allow_duplicates, bool, 0644); 81module_param(allow_duplicates, bool, 0644);
82 82
83/* 83/*
84 * For Windows 8 systems: if set ture and the GPU driver has 84 * For Windows 8 systems: used to decide if video module
85 * registered a backlight interface, skip registering ACPI video's. 85 * should skip registering backlight interface of its own.
86 */ 86 */
87static bool use_native_backlight = false; 87static int use_native_backlight_param = -1;
88module_param(use_native_backlight, bool, 0644); 88module_param_named(use_native_backlight, use_native_backlight_param, int, 0444);
89static bool use_native_backlight_dmi = false;
89 90
90static int register_count; 91static int register_count;
91static struct mutex video_list_lock; 92static struct mutex video_list_lock;
@@ -231,9 +232,17 @@ static int acpi_video_get_next_level(struct acpi_video_device *device,
231static int acpi_video_switch_brightness(struct acpi_video_device *device, 232static int acpi_video_switch_brightness(struct acpi_video_device *device,
232 int event); 233 int event);
233 234
235static bool acpi_video_use_native_backlight(void)
236{
237 if (use_native_backlight_param != -1)
238 return use_native_backlight_param;
239 else
240 return use_native_backlight_dmi;
241}
242
234static bool acpi_video_verify_backlight_support(void) 243static bool acpi_video_verify_backlight_support(void)
235{ 244{
236 if (acpi_osi_is_win8() && use_native_backlight && 245 if (acpi_osi_is_win8() && acpi_video_use_native_backlight() &&
237 backlight_device_registered(BACKLIGHT_RAW)) 246 backlight_device_registered(BACKLIGHT_RAW))
238 return false; 247 return false;
239 return acpi_video_backlight_support(); 248 return acpi_video_backlight_support();
@@ -398,6 +407,12 @@ static int __init video_set_bqc_offset(const struct dmi_system_id *d)
398 return 0; 407 return 0;
399} 408}
400 409
410static int __init video_set_use_native_backlight(const struct dmi_system_id *d)
411{
412 use_native_backlight_dmi = true;
413 return 0;
414}
415
401static struct dmi_system_id video_dmi_table[] __initdata = { 416static struct dmi_system_id video_dmi_table[] __initdata = {
402 /* 417 /*
403 * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121 418 * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
@@ -442,6 +457,120 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
442 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720"), 457 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720"),
443 }, 458 },
444 }, 459 },
460 {
461 .callback = video_set_use_native_backlight,
462 .ident = "ThinkPad T430s",
463 .matches = {
464 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
465 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T430s"),
466 },
467 },
468 {
469 .callback = video_set_use_native_backlight,
470 .ident = "ThinkPad X230",
471 .matches = {
472 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
473 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X230"),
474 },
475 },
476 {
477 .callback = video_set_use_native_backlight,
478 .ident = "ThinkPad X1 Carbon",
479 .matches = {
480 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
481 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X1 Carbon"),
482 },
483 },
484 {
485 .callback = video_set_use_native_backlight,
486 .ident = "Lenovo Yoga 13",
487 .matches = {
488 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
489 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo IdeaPad Yoga 13"),
490 },
491 },
492 {
493 .callback = video_set_use_native_backlight,
494 .ident = "Dell Inspiron 7520",
495 .matches = {
496 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
497 DMI_MATCH(DMI_PRODUCT_VERSION, "Inspiron 7520"),
498 },
499 },
500 {
501 .callback = video_set_use_native_backlight,
502 .ident = "Acer Aspire 5733Z",
503 .matches = {
504 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
505 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5733Z"),
506 },
507 },
508 {
509 .callback = video_set_use_native_backlight,
510 .ident = "Acer Aspire V5-431",
511 .matches = {
512 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
513 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-431"),
514 },
515 },
516 {
517 .callback = video_set_use_native_backlight,
518 .ident = "HP ProBook 4340s",
519 .matches = {
520 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
521 DMI_MATCH(DMI_PRODUCT_VERSION, "HP ProBook 4340s"),
522 },
523 },
524 {
525 .callback = video_set_use_native_backlight,
526 .ident = "HP ProBook 2013 models",
527 .matches = {
528 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
529 DMI_MATCH(DMI_PRODUCT_NAME, "HP ProBook "),
530 DMI_MATCH(DMI_PRODUCT_NAME, " G1"),
531 },
532 },
533 {
534 .callback = video_set_use_native_backlight,
535 .ident = "HP EliteBook 2013 models",
536 .matches = {
537 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
538 DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook "),
539 DMI_MATCH(DMI_PRODUCT_NAME, " G1"),
540 },
541 },
542 {
543 .callback = video_set_use_native_backlight,
544 .ident = "HP ZBook 14",
545 .matches = {
546 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
547 DMI_MATCH(DMI_PRODUCT_NAME, "HP ZBook 14"),
548 },
549 },
550 {
551 .callback = video_set_use_native_backlight,
552 .ident = "HP ZBook 15",
553 .matches = {
554 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
555 DMI_MATCH(DMI_PRODUCT_NAME, "HP ZBook 15"),
556 },
557 },
558 {
559 .callback = video_set_use_native_backlight,
560 .ident = "HP ZBook 17",
561 .matches = {
562 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
563 DMI_MATCH(DMI_PRODUCT_NAME, "HP ZBook 17"),
564 },
565 },
566 {
567 .callback = video_set_use_native_backlight,
568 .ident = "HP EliteBook 8780w",
569 .matches = {
570 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
571 DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook 8780w"),
572 },
573 },
445 {} 574 {}
446}; 575};
447 576
@@ -685,6 +814,7 @@ acpi_video_init_brightness(struct acpi_video_device *device)
685 union acpi_object *o; 814 union acpi_object *o;
686 struct acpi_video_device_brightness *br = NULL; 815 struct acpi_video_device_brightness *br = NULL;
687 int result = -EINVAL; 816 int result = -EINVAL;
817 u32 value;
688 818
689 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) { 819 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
690 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available " 820 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
@@ -715,7 +845,12 @@ acpi_video_init_brightness(struct acpi_video_device *device)
715 printk(KERN_ERR PREFIX "Invalid data\n"); 845 printk(KERN_ERR PREFIX "Invalid data\n");
716 continue; 846 continue;
717 } 847 }
718 br->levels[count] = (u32) o->integer.value; 848 value = (u32) o->integer.value;
849 /* Skip duplicate entries */
850 if (count > 2 && br->levels[count - 1] == value)
851 continue;
852
853 br->levels[count] = value;
719 854
720 if (br->levels[count] > max_level) 855 if (br->levels[count] > max_level)
721 max_level = br->levels[count]; 856 max_level = br->levels[count];
diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
index f0447d3daf2c..19080c8e2f2a 100644
--- a/drivers/acpi/video_detect.c
+++ b/drivers/acpi/video_detect.c
@@ -168,14 +168,6 @@ static struct dmi_system_id video_detect_dmi_table[] = {
168 DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"), 168 DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
169 }, 169 },
170 }, 170 },
171 {
172 .callback = video_detect_force_vendor,
173 .ident = "Lenovo Yoga 13",
174 .matches = {
175 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
176 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo IdeaPad Yoga 13"),
177 },
178 },
179 { }, 171 { },
180}; 172};
181 173
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 71bd29ce0c5c..20e03a7eb8b4 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -283,6 +283,7 @@ config SATA_MV
283 tristate "Marvell SATA support" 283 tristate "Marvell SATA support"
284 depends on PCI || ARCH_DOVE || ARCH_KIRKWOOD || ARCH_MV78XX0 || \ 284 depends on PCI || ARCH_DOVE || ARCH_KIRKWOOD || ARCH_MV78XX0 || \
285 ARCH_MVEBU || ARCH_ORION5X || COMPILE_TEST 285 ARCH_MVEBU || ARCH_ORION5X || COMPILE_TEST
286 select GENERIC_PHY
286 help 287 help
287 This option enables support for the Marvell Serial ATA family. 288 This option enables support for the Marvell Serial ATA family.
288 Currently supports 88SX[56]0[48][01] PCI(-X) chips, 289 Currently supports 88SX[56]0[48][01] PCI(-X) chips,
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 1d4efe540604..a52a5b662f35 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -60,6 +60,7 @@ enum board_ids {
60 /* board IDs by feature in alphabetical order */ 60 /* board IDs by feature in alphabetical order */
61 board_ahci, 61 board_ahci,
62 board_ahci_ign_iferr, 62 board_ahci_ign_iferr,
63 board_ahci_noncq,
63 board_ahci_nosntf, 64 board_ahci_nosntf,
64 board_ahci_yes_fbs, 65 board_ahci_yes_fbs,
65 66
@@ -120,6 +121,13 @@ static const struct ata_port_info ahci_port_info[] = {
120 .udma_mask = ATA_UDMA6, 121 .udma_mask = ATA_UDMA6,
121 .port_ops = &ahci_ops, 122 .port_ops = &ahci_ops,
122 }, 123 },
124 [board_ahci_noncq] = {
125 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ),
126 .flags = AHCI_FLAG_COMMON,
127 .pio_mask = ATA_PIO4,
128 .udma_mask = ATA_UDMA6,
129 .port_ops = &ahci_ops,
130 },
123 [board_ahci_nosntf] = { 131 [board_ahci_nosntf] = {
124 AHCI_HFLAGS (AHCI_HFLAG_NO_SNTF), 132 AHCI_HFLAGS (AHCI_HFLAG_NO_SNTF),
125 .flags = AHCI_FLAG_COMMON, 133 .flags = AHCI_FLAG_COMMON,
@@ -451,6 +459,12 @@ static const struct pci_device_id ahci_pci_tbl[] = {
451 { PCI_VDEVICE(ASMEDIA, 0x0611), board_ahci }, /* ASM1061 */ 459 { PCI_VDEVICE(ASMEDIA, 0x0611), board_ahci }, /* ASM1061 */
452 { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1062 */ 460 { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1062 */
453 461
462 /*
463 * Samsung SSDs found on some macbooks. NCQ times out.
464 * https://bugzilla.kernel.org/show_bug.cgi?id=60731
465 */
466 { PCI_VDEVICE(SAMSUNG, 0x1600), board_ahci_noncq },
467
454 /* Enmotus */ 468 /* Enmotus */
455 { PCI_DEVICE(0x1c44, 0x8000), board_ahci }, 469 { PCI_DEVICE(0x1c44, 0x8000), board_ahci },
456 470
@@ -1171,8 +1185,10 @@ static int ahci_init_interrupts(struct pci_dev *pdev, unsigned int n_ports,
1171 1185
1172 nvec = rc; 1186 nvec = rc;
1173 rc = pci_enable_msi_block(pdev, nvec); 1187 rc = pci_enable_msi_block(pdev, nvec);
1174 if (rc) 1188 if (rc < 0)
1175 goto intx; 1189 goto intx;
1190 else if (rc > 0)
1191 goto single_msi;
1176 1192
1177 return nvec; 1193 return nvec;
1178 1194
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index c37eb02c7136..34406f7fdd7a 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4175,6 +4175,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4175 4175
4176 /* Seagate Momentus SpinPoint M8 seem to have FPMDA_AA issues */ 4176 /* Seagate Momentus SpinPoint M8 seem to have FPMDA_AA issues */
4177 { "ST1000LM024 HN-M101MBB", "2AR10001", ATA_HORKAGE_BROKEN_FPDMA_AA }, 4177 { "ST1000LM024 HN-M101MBB", "2AR10001", ATA_HORKAGE_BROKEN_FPDMA_AA },
4178 { "ST1000LM024 HN-M101MBB", "2BA30001", ATA_HORKAGE_BROKEN_FPDMA_AA },
4178 4179
4179 /* Blacklist entries taken from Silicon Image 3124/3132 4180 /* Blacklist entries taken from Silicon Image 3124/3132
4180 Windows driver .inf file - also several Linux problem reports */ 4181 Windows driver .inf file - also several Linux problem reports */
@@ -4224,7 +4225,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4224 4225
4225 /* devices that don't properly handle queued TRIM commands */ 4226 /* devices that don't properly handle queued TRIM commands */
4226 { "Micron_M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, }, 4227 { "Micron_M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
4227 { "Crucial_CT???M500SSD1", NULL, ATA_HORKAGE_NO_NCQ_TRIM, }, 4228 { "Crucial_CT???M500SSD*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
4228 4229
4229 /* 4230 /*
4230 * Some WD SATA-I drives spin up and down erratically when the link 4231 * Some WD SATA-I drives spin up and down erratically when the link
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index 20fd337a5731..7ccc084bf1df 100644
--- a/drivers/ata/libata-pmp.c
+++ b/drivers/ata/libata-pmp.c
@@ -447,8 +447,11 @@ static void sata_pmp_quirks(struct ata_port *ap)
447 * otherwise. Don't try hard to recover it. 447 * otherwise. Don't try hard to recover it.
448 */ 448 */
449 ap->pmp_link[ap->nr_pmp_links - 1].flags |= ATA_LFLAG_NO_RETRY; 449 ap->pmp_link[ap->nr_pmp_links - 1].flags |= ATA_LFLAG_NO_RETRY;
450 } else if (vendor == 0x197b && devid == 0x2352) { 450 } else if (vendor == 0x197b && (devid == 0x2352 || devid == 0x0325)) {
451 /* chip found in Thermaltake BlackX Duet, jmicron JMB350? */ 451 /*
452 * 0x2352: found in Thermaltake BlackX Duet, jmicron JMB350?
453 * 0x0325: jmicron JMB394.
454 */
452 ata_for_each_link(link, ap, EDGE) { 455 ata_for_each_link(link, ap, EDGE) {
453 /* SRST breaks detection and disks get misclassified 456 /* SRST breaks detection and disks get misclassified
454 * LPM disabled to avoid potential problems 457 * LPM disabled to avoid potential problems
diff --git a/drivers/ata/pata_imx.c b/drivers/ata/pata_imx.c
index 161769343ce7..e0872db913d6 100644
--- a/drivers/ata/pata_imx.c
+++ b/drivers/ata/pata_imx.c
@@ -114,7 +114,9 @@ static int pata_imx_probe(struct platform_device *pdev)
114 return PTR_ERR(priv->clk); 114 return PTR_ERR(priv->clk);
115 } 115 }
116 116
117 clk_prepare_enable(priv->clk); 117 ret = clk_prepare_enable(priv->clk);
118 if (ret)
119 return ret;
118 120
119 host = ata_host_alloc(&pdev->dev, 1); 121 host = ata_host_alloc(&pdev->dev, 1);
120 if (!host) { 122 if (!host) {
@@ -206,7 +208,9 @@ static int pata_imx_resume(struct device *dev)
206 struct ata_host *host = dev_get_drvdata(dev); 208 struct ata_host *host = dev_get_drvdata(dev);
207 struct pata_imx_priv *priv = host->private_data; 209 struct pata_imx_priv *priv = host->private_data;
208 210
209 clk_prepare_enable(priv->clk); 211 int ret = clk_prepare_enable(priv->clk);
212 if (ret)
213 return ret;
210 214
211 __raw_writel(priv->ata_ctl, priv->host_regs + PATA_IMX_ATA_CONTROL); 215 __raw_writel(priv->ata_ctl, priv->host_regs + PATA_IMX_ATA_CONTROL);
212 216
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 20a7517bd339..05c8a44adf8e 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -4104,7 +4104,6 @@ static int mv_platform_probe(struct platform_device *pdev)
4104 if (!hpriv->port_phys) 4104 if (!hpriv->port_phys)
4105 return -ENOMEM; 4105 return -ENOMEM;
4106 host->private_data = hpriv; 4106 host->private_data = hpriv;
4107 hpriv->n_ports = n_ports;
4108 hpriv->board_idx = chip_soc; 4107 hpriv->board_idx = chip_soc;
4109 4108
4110 host->iomap = NULL; 4109 host->iomap = NULL;
@@ -4126,17 +4125,24 @@ static int mv_platform_probe(struct platform_device *pdev)
4126 clk_prepare_enable(hpriv->port_clks[port]); 4125 clk_prepare_enable(hpriv->port_clks[port]);
4127 4126
4128 sprintf(port_number, "port%d", port); 4127 sprintf(port_number, "port%d", port);
4129 hpriv->port_phys[port] = devm_phy_get(&pdev->dev, port_number); 4128 hpriv->port_phys[port] = devm_phy_optional_get(&pdev->dev,
4129 port_number);
4130 if (IS_ERR(hpriv->port_phys[port])) { 4130 if (IS_ERR(hpriv->port_phys[port])) {
4131 rc = PTR_ERR(hpriv->port_phys[port]); 4131 rc = PTR_ERR(hpriv->port_phys[port]);
4132 hpriv->port_phys[port] = NULL; 4132 hpriv->port_phys[port] = NULL;
4133 if ((rc != -EPROBE_DEFER) && (rc != -ENODEV)) 4133 if (rc != -EPROBE_DEFER)
4134 dev_warn(&pdev->dev, "error getting phy"); 4134 dev_warn(&pdev->dev, "error getting phy %d", rc);
4135
4136 /* Cleanup only the initialized ports */
4137 hpriv->n_ports = port;
4135 goto err; 4138 goto err;
4136 } else 4139 } else
4137 phy_power_on(hpriv->port_phys[port]); 4140 phy_power_on(hpriv->port_phys[port]);
4138 } 4141 }
4139 4142
4143 /* All the ports have been initialized */
4144 hpriv->n_ports = n_ports;
4145
4140 /* 4146 /*
4141 * (Re-)program MBUS remapping windows if we are asked to. 4147 * (Re-)program MBUS remapping windows if we are asked to.
4142 */ 4148 */
@@ -4174,7 +4180,7 @@ err:
4174 clk_disable_unprepare(hpriv->clk); 4180 clk_disable_unprepare(hpriv->clk);
4175 clk_put(hpriv->clk); 4181 clk_put(hpriv->clk);
4176 } 4182 }
4177 for (port = 0; port < n_ports; port++) { 4183 for (port = 0; port < hpriv->n_ports; port++) {
4178 if (!IS_ERR(hpriv->port_clks[port])) { 4184 if (!IS_ERR(hpriv->port_clks[port])) {
4179 clk_disable_unprepare(hpriv->port_clks[port]); 4185 clk_disable_unprepare(hpriv->port_clks[port]);
4180 clk_put(hpriv->port_clks[port]); 4186 clk_put(hpriv->port_clks[port]);
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index e476e7b9a441..3062f8605b29 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -156,6 +156,7 @@ static const struct sil_drivelist {
156 { "ST380011ASL", SIL_QUIRK_MOD15WRITE }, 156 { "ST380011ASL", SIL_QUIRK_MOD15WRITE },
157 { "ST3120022ASL", SIL_QUIRK_MOD15WRITE }, 157 { "ST3120022ASL", SIL_QUIRK_MOD15WRITE },
158 { "ST3160021ASL", SIL_QUIRK_MOD15WRITE }, 158 { "ST3160021ASL", SIL_QUIRK_MOD15WRITE },
159 { "TOSHIBA MK2561GSYN", SIL_QUIRK_MOD15WRITE },
159 { "Maxtor 4D060H3", SIL_QUIRK_UDMA5MAX }, 160 { "Maxtor 4D060H3", SIL_QUIRK_UDMA5MAX },
160 { } 161 { }
161}; 162};
diff --git a/drivers/base/component.c b/drivers/base/component.c
index c53efe6c6d8e..c4778995cd72 100644
--- a/drivers/base/component.c
+++ b/drivers/base/component.c
@@ -133,9 +133,16 @@ static int try_to_bring_up_master(struct master *master,
133 goto out; 133 goto out;
134 } 134 }
135 135
136 if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) {
137 ret = -ENOMEM;
138 goto out;
139 }
140
136 /* Found all components */ 141 /* Found all components */
137 ret = master->ops->bind(master->dev); 142 ret = master->ops->bind(master->dev);
138 if (ret < 0) { 143 if (ret < 0) {
144 devres_release_group(master->dev, NULL);
145 dev_info(master->dev, "master bind failed: %d\n", ret);
139 master_remove_components(master); 146 master_remove_components(master);
140 goto out; 147 goto out;
141 } 148 }
@@ -166,6 +173,7 @@ static void take_down_master(struct master *master)
166{ 173{
167 if (master->bound) { 174 if (master->bound) {
168 master->ops->unbind(master->dev); 175 master->ops->unbind(master->dev);
176 devres_release_group(master->dev, NULL);
169 master->bound = false; 177 master->bound = false;
170 } 178 }
171 179
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c
index 1e16cbd61da2..61d6d62cc0d3 100644
--- a/drivers/base/dma-buf.c
+++ b/drivers/base/dma-buf.c
@@ -616,36 +616,35 @@ static int dma_buf_describe(struct seq_file *s)
616 if (ret) 616 if (ret)
617 return ret; 617 return ret;
618 618
619 seq_printf(s, "\nDma-buf Objects:\n"); 619 seq_puts(s, "\nDma-buf Objects:\n");
620 seq_printf(s, "\texp_name\tsize\tflags\tmode\tcount\n"); 620 seq_puts(s, "size\tflags\tmode\tcount\texp_name\n");
621 621
622 list_for_each_entry(buf_obj, &db_list.head, list_node) { 622 list_for_each_entry(buf_obj, &db_list.head, list_node) {
623 ret = mutex_lock_interruptible(&buf_obj->lock); 623 ret = mutex_lock_interruptible(&buf_obj->lock);
624 624
625 if (ret) { 625 if (ret) {
626 seq_printf(s, 626 seq_puts(s,
627 "\tERROR locking buffer object: skipping\n"); 627 "\tERROR locking buffer object: skipping\n");
628 continue; 628 continue;
629 } 629 }
630 630
631 seq_printf(s, "\t"); 631 seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\n",
632 632 buf_obj->size,
633 seq_printf(s, "\t%s\t%08zu\t%08x\t%08x\t%08ld\n",
634 buf_obj->exp_name, buf_obj->size,
635 buf_obj->file->f_flags, buf_obj->file->f_mode, 633 buf_obj->file->f_flags, buf_obj->file->f_mode,
636 (long)(buf_obj->file->f_count.counter)); 634 (long)(buf_obj->file->f_count.counter),
635 buf_obj->exp_name);
637 636
638 seq_printf(s, "\t\tAttached Devices:\n"); 637 seq_puts(s, "\tAttached Devices:\n");
639 attach_count = 0; 638 attach_count = 0;
640 639
641 list_for_each_entry(attach_obj, &buf_obj->attachments, node) { 640 list_for_each_entry(attach_obj, &buf_obj->attachments, node) {
642 seq_printf(s, "\t\t"); 641 seq_puts(s, "\t");
643 642
644 seq_printf(s, "%s\n", attach_obj->dev->init_name); 643 seq_printf(s, "%s\n", dev_name(attach_obj->dev));
645 attach_count++; 644 attach_count++;
646 } 645 }
647 646
648 seq_printf(s, "\n\t\tTotal %d devices attached\n", 647 seq_printf(s, "Total %d devices attached\n\n",
649 attach_count); 648 attach_count);
650 649
651 count++; 650 count++;
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 8a97ddfa6122..c30df50e4440 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1580,6 +1580,7 @@ static int fw_pm_notify(struct notifier_block *notify_block,
1580 switch (mode) { 1580 switch (mode) {
1581 case PM_HIBERNATION_PREPARE: 1581 case PM_HIBERNATION_PREPARE:
1582 case PM_SUSPEND_PREPARE: 1582 case PM_SUSPEND_PREPARE:
1583 case PM_RESTORE_PREPARE:
1583 kill_requests_without_uevent(); 1584 kill_requests_without_uevent();
1584 device_cache_fw_images(); 1585 device_cache_fw_images();
1585 break; 1586 break;
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 8184451b57c0..422b7d84f686 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -874,7 +874,7 @@ bio_pageinc(struct bio *bio)
874 /* Non-zero page count for non-head members of 874 /* Non-zero page count for non-head members of
875 * compound pages is no longer allowed by the kernel. 875 * compound pages is no longer allowed by the kernel.
876 */ 876 */
877 page = compound_trans_head(bv.bv_page); 877 page = compound_head(bv.bv_page);
878 atomic_inc(&page->_count); 878 atomic_inc(&page->_count);
879 } 879 }
880} 880}
@@ -887,7 +887,7 @@ bio_pagedec(struct bio *bio)
887 struct bvec_iter iter; 887 struct bvec_iter iter;
888 888
889 bio_for_each_segment(bv, bio, iter) { 889 bio_for_each_segment(bv, bio, iter) {
890 page = compound_trans_head(bv.bv_page); 890 page = compound_head(bv.bv_page);
891 atomic_dec(&page->_count); 891 atomic_dec(&page->_count);
892 } 892 }
893} 893}
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 2023043ce7c0..8f5565bf34cd 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -961,17 +961,31 @@ static void empty(void)
961{ 961{
962} 962}
963 963
964static DECLARE_WORK(floppy_work, NULL); 964static void (*floppy_work_fn)(void);
965
966static void floppy_work_workfn(struct work_struct *work)
967{
968 floppy_work_fn();
969}
970
971static DECLARE_WORK(floppy_work, floppy_work_workfn);
965 972
966static void schedule_bh(void (*handler)(void)) 973static void schedule_bh(void (*handler)(void))
967{ 974{
968 WARN_ON(work_pending(&floppy_work)); 975 WARN_ON(work_pending(&floppy_work));
969 976
970 PREPARE_WORK(&floppy_work, (work_func_t)handler); 977 floppy_work_fn = handler;
971 queue_work(floppy_wq, &floppy_work); 978 queue_work(floppy_wq, &floppy_work);
972} 979}
973 980
974static DECLARE_DELAYED_WORK(fd_timer, NULL); 981static void (*fd_timer_fn)(void) = NULL;
982
983static void fd_timer_workfn(struct work_struct *work)
984{
985 fd_timer_fn();
986}
987
988static DECLARE_DELAYED_WORK(fd_timer, fd_timer_workfn);
975 989
976static void cancel_activity(void) 990static void cancel_activity(void)
977{ 991{
@@ -982,7 +996,7 @@ static void cancel_activity(void)
982 996
983/* this function makes sure that the disk stays in the drive during the 997/* this function makes sure that the disk stays in the drive during the
984 * transfer */ 998 * transfer */
985static void fd_watchdog(struct work_struct *arg) 999static void fd_watchdog(void)
986{ 1000{
987 debug_dcl(DP->flags, "calling disk change from watchdog\n"); 1001 debug_dcl(DP->flags, "calling disk change from watchdog\n");
988 1002
@@ -993,7 +1007,7 @@ static void fd_watchdog(struct work_struct *arg)
993 reset_fdc(); 1007 reset_fdc();
994 } else { 1008 } else {
995 cancel_delayed_work(&fd_timer); 1009 cancel_delayed_work(&fd_timer);
996 PREPARE_DELAYED_WORK(&fd_timer, fd_watchdog); 1010 fd_timer_fn = fd_watchdog;
997 queue_delayed_work(floppy_wq, &fd_timer, HZ / 10); 1011 queue_delayed_work(floppy_wq, &fd_timer, HZ / 10);
998 } 1012 }
999} 1013}
@@ -1005,7 +1019,8 @@ static void main_command_interrupt(void)
1005} 1019}
1006 1020
1007/* waits for a delay (spinup or select) to pass */ 1021/* waits for a delay (spinup or select) to pass */
1008static int fd_wait_for_completion(unsigned long expires, work_func_t function) 1022static int fd_wait_for_completion(unsigned long expires,
1023 void (*function)(void))
1009{ 1024{
1010 if (FDCS->reset) { 1025 if (FDCS->reset) {
1011 reset_fdc(); /* do the reset during sleep to win time 1026 reset_fdc(); /* do the reset during sleep to win time
@@ -1016,7 +1031,7 @@ static int fd_wait_for_completion(unsigned long expires, work_func_t function)
1016 1031
1017 if (time_before(jiffies, expires)) { 1032 if (time_before(jiffies, expires)) {
1018 cancel_delayed_work(&fd_timer); 1033 cancel_delayed_work(&fd_timer);
1019 PREPARE_DELAYED_WORK(&fd_timer, function); 1034 fd_timer_fn = function;
1020 queue_delayed_work(floppy_wq, &fd_timer, expires - jiffies); 1035 queue_delayed_work(floppy_wq, &fd_timer, expires - jiffies);
1021 return 1; 1036 return 1;
1022 } 1037 }
@@ -1334,8 +1349,7 @@ static int fdc_dtr(void)
1334 * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies) 1349 * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies)
1335 */ 1350 */
1336 FDCS->dtr = raw_cmd->rate & 3; 1351 FDCS->dtr = raw_cmd->rate & 3;
1337 return fd_wait_for_completion(jiffies + 2UL * HZ / 100, 1352 return fd_wait_for_completion(jiffies + 2UL * HZ / 100, floppy_ready);
1338 (work_func_t)floppy_ready);
1339} /* fdc_dtr */ 1353} /* fdc_dtr */
1340 1354
1341static void tell_sector(void) 1355static void tell_sector(void)
@@ -1440,7 +1454,7 @@ static void setup_rw_floppy(void)
1440 int flags; 1454 int flags;
1441 int dflags; 1455 int dflags;
1442 unsigned long ready_date; 1456 unsigned long ready_date;
1443 work_func_t function; 1457 void (*function)(void);
1444 1458
1445 flags = raw_cmd->flags; 1459 flags = raw_cmd->flags;
1446 if (flags & (FD_RAW_READ | FD_RAW_WRITE)) 1460 if (flags & (FD_RAW_READ | FD_RAW_WRITE))
@@ -1454,9 +1468,9 @@ static void setup_rw_floppy(void)
1454 */ 1468 */
1455 if (time_after(ready_date, jiffies + DP->select_delay)) { 1469 if (time_after(ready_date, jiffies + DP->select_delay)) {
1456 ready_date -= DP->select_delay; 1470 ready_date -= DP->select_delay;
1457 function = (work_func_t)floppy_start; 1471 function = floppy_start;
1458 } else 1472 } else
1459 function = (work_func_t)setup_rw_floppy; 1473 function = setup_rw_floppy;
1460 1474
1461 /* wait until the floppy is spinning fast enough */ 1475 /* wait until the floppy is spinning fast enough */
1462 if (fd_wait_for_completion(ready_date, function)) 1476 if (fd_wait_for_completion(ready_date, function))
@@ -1486,7 +1500,7 @@ static void setup_rw_floppy(void)
1486 inr = result(); 1500 inr = result();
1487 cont->interrupt(); 1501 cont->interrupt();
1488 } else if (flags & FD_RAW_NEED_DISK) 1502 } else if (flags & FD_RAW_NEED_DISK)
1489 fd_watchdog(NULL); 1503 fd_watchdog();
1490} 1504}
1491 1505
1492static int blind_seek; 1506static int blind_seek;
@@ -1863,7 +1877,7 @@ static int start_motor(void (*function)(void))
1863 1877
1864 /* wait_for_completion also schedules reset if needed. */ 1878 /* wait_for_completion also schedules reset if needed. */
1865 return fd_wait_for_completion(DRS->select_date + DP->select_delay, 1879 return fd_wait_for_completion(DRS->select_date + DP->select_delay,
1866 (work_func_t)function); 1880 function);
1867} 1881}
1868 1882
1869static void floppy_ready(void) 1883static void floppy_ready(void)
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 516026954be6..d777bb7cea93 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -4498,7 +4498,7 @@ static int mtip_pci_probe(struct pci_dev *pdev,
4498 } 4498 }
4499 dev_info(&pdev->dev, "NUMA node %d (closest: %d,%d, probe on %d:%d)\n", 4499 dev_info(&pdev->dev, "NUMA node %d (closest: %d,%d, probe on %d:%d)\n",
4500 my_node, pcibus_to_node(pdev->bus), dev_to_node(&pdev->dev), 4500 my_node, pcibus_to_node(pdev->bus), dev_to_node(&pdev->dev),
4501 cpu_to_node(smp_processor_id()), smp_processor_id()); 4501 cpu_to_node(raw_smp_processor_id()), raw_smp_processor_id());
4502 4502
4503 dd = kzalloc_node(sizeof(struct driver_data), GFP_KERNEL, my_node); 4503 dd = kzalloc_node(sizeof(struct driver_data), GFP_KERNEL, my_node);
4504 if (dd == NULL) { 4504 if (dd == NULL) {
diff --git a/drivers/block/mtip32xx/mtip32xx.h b/drivers/block/mtip32xx/mtip32xx.h
index b52e9a6d6aad..54174cb32feb 100644
--- a/drivers/block/mtip32xx/mtip32xx.h
+++ b/drivers/block/mtip32xx/mtip32xx.h
@@ -53,7 +53,7 @@
53#define MTIP_FTL_REBUILD_TIMEOUT_MS 2400000 53#define MTIP_FTL_REBUILD_TIMEOUT_MS 2400000
54 54
55/* unaligned IO handling */ 55/* unaligned IO handling */
56#define MTIP_MAX_UNALIGNED_SLOTS 8 56#define MTIP_MAX_UNALIGNED_SLOTS 2
57 57
58/* Macro to extract the tag bit number from a tag value. */ 58/* Macro to extract the tag bit number from a tag value. */
59#define MTIP_TAG_BIT(tag) (tag & 0x1F) 59#define MTIP_TAG_BIT(tag) (tag & 0x1F)
diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
index 3107282a9741..091b9ea14feb 100644
--- a/drivers/block/null_blk.c
+++ b/drivers/block/null_blk.c
@@ -60,7 +60,9 @@ enum {
60 NULL_IRQ_NONE = 0, 60 NULL_IRQ_NONE = 0,
61 NULL_IRQ_SOFTIRQ = 1, 61 NULL_IRQ_SOFTIRQ = 1,
62 NULL_IRQ_TIMER = 2, 62 NULL_IRQ_TIMER = 2,
63};
63 64
65enum {
64 NULL_Q_BIO = 0, 66 NULL_Q_BIO = 0,
65 NULL_Q_RQ = 1, 67 NULL_Q_RQ = 1,
66 NULL_Q_MQ = 2, 68 NULL_Q_MQ = 2,
@@ -172,18 +174,20 @@ static struct nullb_cmd *alloc_cmd(struct nullb_queue *nq, int can_wait)
172 174
173static void end_cmd(struct nullb_cmd *cmd) 175static void end_cmd(struct nullb_cmd *cmd)
174{ 176{
175 if (cmd->rq) { 177 switch (queue_mode) {
176 if (queue_mode == NULL_Q_MQ) 178 case NULL_Q_MQ:
177 blk_mq_end_io(cmd->rq, 0); 179 blk_mq_end_io(cmd->rq, 0);
178 else { 180 return;
179 INIT_LIST_HEAD(&cmd->rq->queuelist); 181 case NULL_Q_RQ:
180 blk_end_request_all(cmd->rq, 0); 182 INIT_LIST_HEAD(&cmd->rq->queuelist);
181 } 183 blk_end_request_all(cmd->rq, 0);
182 } else if (cmd->bio) 184 break;
185 case NULL_Q_BIO:
183 bio_endio(cmd->bio, 0); 186 bio_endio(cmd->bio, 0);
187 break;
188 }
184 189
185 if (queue_mode != NULL_Q_MQ) 190 free_cmd(cmd);
186 free_cmd(cmd);
187} 191}
188 192
189static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer) 193static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer)
@@ -195,6 +199,7 @@ static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer)
195 cq = &per_cpu(completion_queues, smp_processor_id()); 199 cq = &per_cpu(completion_queues, smp_processor_id());
196 200
197 while ((entry = llist_del_all(&cq->list)) != NULL) { 201 while ((entry = llist_del_all(&cq->list)) != NULL) {
202 entry = llist_reverse_order(entry);
198 do { 203 do {
199 cmd = container_of(entry, struct nullb_cmd, ll_list); 204 cmd = container_of(entry, struct nullb_cmd, ll_list);
200 end_cmd(cmd); 205 end_cmd(cmd);
@@ -221,61 +226,31 @@ static void null_cmd_end_timer(struct nullb_cmd *cmd)
221 226
222static void null_softirq_done_fn(struct request *rq) 227static void null_softirq_done_fn(struct request *rq)
223{ 228{
224 blk_end_request_all(rq, 0); 229 end_cmd(rq->special);
225}
226
227#ifdef CONFIG_SMP
228
229static void null_ipi_cmd_end_io(void *data)
230{
231 struct completion_queue *cq;
232 struct llist_node *entry, *next;
233 struct nullb_cmd *cmd;
234
235 cq = &per_cpu(completion_queues, smp_processor_id());
236
237 entry = llist_del_all(&cq->list);
238
239 while (entry) {
240 next = entry->next;
241 cmd = llist_entry(entry, struct nullb_cmd, ll_list);
242 end_cmd(cmd);
243 entry = next;
244 }
245}
246
247static void null_cmd_end_ipi(struct nullb_cmd *cmd)
248{
249 struct call_single_data *data = &cmd->csd;
250 int cpu = get_cpu();
251 struct completion_queue *cq = &per_cpu(completion_queues, cpu);
252
253 cmd->ll_list.next = NULL;
254
255 if (llist_add(&cmd->ll_list, &cq->list)) {
256 data->func = null_ipi_cmd_end_io;
257 data->flags = 0;
258 __smp_call_function_single(cpu, data, 0);
259 }
260
261 put_cpu();
262} 230}
263 231
264#endif /* CONFIG_SMP */
265
266static inline void null_handle_cmd(struct nullb_cmd *cmd) 232static inline void null_handle_cmd(struct nullb_cmd *cmd)
267{ 233{
268 /* Complete IO by inline, softirq or timer */ 234 /* Complete IO by inline, softirq or timer */
269 switch (irqmode) { 235 switch (irqmode) {
270 case NULL_IRQ_NONE:
271 end_cmd(cmd);
272 break;
273 case NULL_IRQ_SOFTIRQ: 236 case NULL_IRQ_SOFTIRQ:
274#ifdef CONFIG_SMP 237 switch (queue_mode) {
275 null_cmd_end_ipi(cmd); 238 case NULL_Q_MQ:
276#else 239 blk_mq_complete_request(cmd->rq);
240 break;
241 case NULL_Q_RQ:
242 blk_complete_request(cmd->rq);
243 break;
244 case NULL_Q_BIO:
245 /*
246 * XXX: no proper submitting cpu information available.
247 */
248 end_cmd(cmd);
249 break;
250 }
251 break;
252 case NULL_IRQ_NONE:
277 end_cmd(cmd); 253 end_cmd(cmd);
278#endif
279 break; 254 break;
280 case NULL_IRQ_TIMER: 255 case NULL_IRQ_TIMER:
281 null_cmd_end_timer(cmd); 256 null_cmd_end_timer(cmd);
@@ -411,6 +386,7 @@ static struct blk_mq_ops null_mq_ops = {
411 .queue_rq = null_queue_rq, 386 .queue_rq = null_queue_rq,
412 .map_queue = blk_mq_map_queue, 387 .map_queue = blk_mq_map_queue,
413 .init_hctx = null_init_hctx, 388 .init_hctx = null_init_hctx,
389 .complete = null_softirq_done_fn,
414}; 390};
415 391
416static struct blk_mq_reg null_mq_reg = { 392static struct blk_mq_reg null_mq_reg = {
@@ -609,13 +585,6 @@ static int __init null_init(void)
609{ 585{
610 unsigned int i; 586 unsigned int i;
611 587
612#if !defined(CONFIG_SMP)
613 if (irqmode == NULL_IRQ_SOFTIRQ) {
614 pr_warn("null_blk: softirq completions not available.\n");
615 pr_warn("null_blk: using direct completions.\n");
616 irqmode = NULL_IRQ_NONE;
617 }
618#endif
619 if (bs > PAGE_SIZE) { 588 if (bs > PAGE_SIZE) {
620 pr_warn("null_blk: invalid block size\n"); 589 pr_warn("null_blk: invalid block size\n");
621 pr_warn("null_blk: defaults block size to %lu\n", PAGE_SIZE); 590 pr_warn("null_blk: defaults block size to %lu\n", PAGE_SIZE);
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index 1f14ac403945..8459e4e7c719 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -46,7 +46,6 @@
46#define NVME_Q_DEPTH 1024 46#define NVME_Q_DEPTH 1024
47#define SQ_SIZE(depth) (depth * sizeof(struct nvme_command)) 47#define SQ_SIZE(depth) (depth * sizeof(struct nvme_command))
48#define CQ_SIZE(depth) (depth * sizeof(struct nvme_completion)) 48#define CQ_SIZE(depth) (depth * sizeof(struct nvme_completion))
49#define NVME_MINORS 64
50#define ADMIN_TIMEOUT (60 * HZ) 49#define ADMIN_TIMEOUT (60 * HZ)
51 50
52static int nvme_major; 51static int nvme_major;
@@ -58,6 +57,17 @@ module_param(use_threaded_interrupts, int, 0);
58static DEFINE_SPINLOCK(dev_list_lock); 57static DEFINE_SPINLOCK(dev_list_lock);
59static LIST_HEAD(dev_list); 58static LIST_HEAD(dev_list);
60static struct task_struct *nvme_thread; 59static struct task_struct *nvme_thread;
60static struct workqueue_struct *nvme_workq;
61
62static void nvme_reset_failed_dev(struct work_struct *ws);
63
64struct async_cmd_info {
65 struct kthread_work work;
66 struct kthread_worker *worker;
67 u32 result;
68 int status;
69 void *ctx;
70};
61 71
62/* 72/*
63 * An NVM Express queue. Each device has at least two (one for admin 73 * An NVM Express queue. Each device has at least two (one for admin
@@ -66,6 +76,7 @@ static struct task_struct *nvme_thread;
66struct nvme_queue { 76struct nvme_queue {
67 struct device *q_dmadev; 77 struct device *q_dmadev;
68 struct nvme_dev *dev; 78 struct nvme_dev *dev;
79 char irqname[24]; /* nvme4294967295-65535\0 */
69 spinlock_t q_lock; 80 spinlock_t q_lock;
70 struct nvme_command *sq_cmds; 81 struct nvme_command *sq_cmds;
71 volatile struct nvme_completion *cqes; 82 volatile struct nvme_completion *cqes;
@@ -80,9 +91,11 @@ struct nvme_queue {
80 u16 sq_head; 91 u16 sq_head;
81 u16 sq_tail; 92 u16 sq_tail;
82 u16 cq_head; 93 u16 cq_head;
94 u16 qid;
83 u8 cq_phase; 95 u8 cq_phase;
84 u8 cqe_seen; 96 u8 cqe_seen;
85 u8 q_suspended; 97 u8 q_suspended;
98 struct async_cmd_info cmdinfo;
86 unsigned long cmdid_data[]; 99 unsigned long cmdid_data[];
87}; 100};
88 101
@@ -97,6 +110,7 @@ static inline void _nvme_check_size(void)
97 BUILD_BUG_ON(sizeof(struct nvme_delete_queue) != 64); 110 BUILD_BUG_ON(sizeof(struct nvme_delete_queue) != 64);
98 BUILD_BUG_ON(sizeof(struct nvme_features) != 64); 111 BUILD_BUG_ON(sizeof(struct nvme_features) != 64);
99 BUILD_BUG_ON(sizeof(struct nvme_format_cmd) != 64); 112 BUILD_BUG_ON(sizeof(struct nvme_format_cmd) != 64);
113 BUILD_BUG_ON(sizeof(struct nvme_abort_cmd) != 64);
100 BUILD_BUG_ON(sizeof(struct nvme_command) != 64); 114 BUILD_BUG_ON(sizeof(struct nvme_command) != 64);
101 BUILD_BUG_ON(sizeof(struct nvme_id_ctrl) != 4096); 115 BUILD_BUG_ON(sizeof(struct nvme_id_ctrl) != 4096);
102 BUILD_BUG_ON(sizeof(struct nvme_id_ns) != 4096); 116 BUILD_BUG_ON(sizeof(struct nvme_id_ns) != 4096);
@@ -111,6 +125,7 @@ struct nvme_cmd_info {
111 nvme_completion_fn fn; 125 nvme_completion_fn fn;
112 void *ctx; 126 void *ctx;
113 unsigned long timeout; 127 unsigned long timeout;
128 int aborted;
114}; 129};
115 130
116static struct nvme_cmd_info *nvme_cmd_info(struct nvme_queue *nvmeq) 131static struct nvme_cmd_info *nvme_cmd_info(struct nvme_queue *nvmeq)
@@ -154,6 +169,7 @@ static int alloc_cmdid(struct nvme_queue *nvmeq, void *ctx,
154 info[cmdid].fn = handler; 169 info[cmdid].fn = handler;
155 info[cmdid].ctx = ctx; 170 info[cmdid].ctx = ctx;
156 info[cmdid].timeout = jiffies + timeout; 171 info[cmdid].timeout = jiffies + timeout;
172 info[cmdid].aborted = 0;
157 return cmdid; 173 return cmdid;
158} 174}
159 175
@@ -172,6 +188,7 @@ static int alloc_cmdid_killable(struct nvme_queue *nvmeq, void *ctx,
172#define CMD_CTX_COMPLETED (0x310 + CMD_CTX_BASE) 188#define CMD_CTX_COMPLETED (0x310 + CMD_CTX_BASE)
173#define CMD_CTX_INVALID (0x314 + CMD_CTX_BASE) 189#define CMD_CTX_INVALID (0x314 + CMD_CTX_BASE)
174#define CMD_CTX_FLUSH (0x318 + CMD_CTX_BASE) 190#define CMD_CTX_FLUSH (0x318 + CMD_CTX_BASE)
191#define CMD_CTX_ABORT (0x31C + CMD_CTX_BASE)
175 192
176static void special_completion(struct nvme_dev *dev, void *ctx, 193static void special_completion(struct nvme_dev *dev, void *ctx,
177 struct nvme_completion *cqe) 194 struct nvme_completion *cqe)
@@ -180,6 +197,10 @@ static void special_completion(struct nvme_dev *dev, void *ctx,
180 return; 197 return;
181 if (ctx == CMD_CTX_FLUSH) 198 if (ctx == CMD_CTX_FLUSH)
182 return; 199 return;
200 if (ctx == CMD_CTX_ABORT) {
201 ++dev->abort_limit;
202 return;
203 }
183 if (ctx == CMD_CTX_COMPLETED) { 204 if (ctx == CMD_CTX_COMPLETED) {
184 dev_warn(&dev->pci_dev->dev, 205 dev_warn(&dev->pci_dev->dev,
185 "completed id %d twice on queue %d\n", 206 "completed id %d twice on queue %d\n",
@@ -196,6 +217,15 @@ static void special_completion(struct nvme_dev *dev, void *ctx,
196 dev_warn(&dev->pci_dev->dev, "Unknown special completion %p\n", ctx); 217 dev_warn(&dev->pci_dev->dev, "Unknown special completion %p\n", ctx);
197} 218}
198 219
220static void async_completion(struct nvme_dev *dev, void *ctx,
221 struct nvme_completion *cqe)
222{
223 struct async_cmd_info *cmdinfo = ctx;
224 cmdinfo->result = le32_to_cpup(&cqe->result);
225 cmdinfo->status = le16_to_cpup(&cqe->status) >> 1;
226 queue_kthread_work(cmdinfo->worker, &cmdinfo->work);
227}
228
199/* 229/*
200 * Called with local interrupts disabled and the q_lock held. May not sleep. 230 * Called with local interrupts disabled and the q_lock held. May not sleep.
201 */ 231 */
@@ -693,7 +723,7 @@ static int nvme_process_cq(struct nvme_queue *nvmeq)
693 if (head == nvmeq->cq_head && phase == nvmeq->cq_phase) 723 if (head == nvmeq->cq_head && phase == nvmeq->cq_phase)
694 return 0; 724 return 0;
695 725
696 writel(head, nvmeq->q_db + (1 << nvmeq->dev->db_stride)); 726 writel(head, nvmeq->q_db + nvmeq->dev->db_stride);
697 nvmeq->cq_head = head; 727 nvmeq->cq_head = head;
698 nvmeq->cq_phase = phase; 728 nvmeq->cq_phase = phase;
699 729
@@ -804,12 +834,34 @@ int nvme_submit_sync_cmd(struct nvme_queue *nvmeq, struct nvme_command *cmd,
804 return cmdinfo.status; 834 return cmdinfo.status;
805} 835}
806 836
837static int nvme_submit_async_cmd(struct nvme_queue *nvmeq,
838 struct nvme_command *cmd,
839 struct async_cmd_info *cmdinfo, unsigned timeout)
840{
841 int cmdid;
842
843 cmdid = alloc_cmdid_killable(nvmeq, cmdinfo, async_completion, timeout);
844 if (cmdid < 0)
845 return cmdid;
846 cmdinfo->status = -EINTR;
847 cmd->common.command_id = cmdid;
848 nvme_submit_cmd(nvmeq, cmd);
849 return 0;
850}
851
807int nvme_submit_admin_cmd(struct nvme_dev *dev, struct nvme_command *cmd, 852int nvme_submit_admin_cmd(struct nvme_dev *dev, struct nvme_command *cmd,
808 u32 *result) 853 u32 *result)
809{ 854{
810 return nvme_submit_sync_cmd(dev->queues[0], cmd, result, ADMIN_TIMEOUT); 855 return nvme_submit_sync_cmd(dev->queues[0], cmd, result, ADMIN_TIMEOUT);
811} 856}
812 857
858static int nvme_submit_admin_cmd_async(struct nvme_dev *dev,
859 struct nvme_command *cmd, struct async_cmd_info *cmdinfo)
860{
861 return nvme_submit_async_cmd(dev->queues[0], cmd, cmdinfo,
862 ADMIN_TIMEOUT);
863}
864
813static int adapter_delete_queue(struct nvme_dev *dev, u8 opcode, u16 id) 865static int adapter_delete_queue(struct nvme_dev *dev, u8 opcode, u16 id)
814{ 866{
815 int status; 867 int status;
@@ -920,6 +972,56 @@ int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
920} 972}
921 973
922/** 974/**
975 * nvme_abort_cmd - Attempt aborting a command
976 * @cmdid: Command id of a timed out IO
977 * @queue: The queue with timed out IO
978 *
979 * Schedule controller reset if the command was already aborted once before and
980 * still hasn't been returned to the driver, or if this is the admin queue.
981 */
982static void nvme_abort_cmd(int cmdid, struct nvme_queue *nvmeq)
983{
984 int a_cmdid;
985 struct nvme_command cmd;
986 struct nvme_dev *dev = nvmeq->dev;
987 struct nvme_cmd_info *info = nvme_cmd_info(nvmeq);
988
989 if (!nvmeq->qid || info[cmdid].aborted) {
990 if (work_busy(&dev->reset_work))
991 return;
992 list_del_init(&dev->node);
993 dev_warn(&dev->pci_dev->dev,
994 "I/O %d QID %d timeout, reset controller\n", cmdid,
995 nvmeq->qid);
996 dev->reset_workfn = nvme_reset_failed_dev;
997 queue_work(nvme_workq, &dev->reset_work);
998 return;
999 }
1000
1001 if (!dev->abort_limit)
1002 return;
1003
1004 a_cmdid = alloc_cmdid(dev->queues[0], CMD_CTX_ABORT, special_completion,
1005 ADMIN_TIMEOUT);
1006 if (a_cmdid < 0)
1007 return;
1008
1009 memset(&cmd, 0, sizeof(cmd));
1010 cmd.abort.opcode = nvme_admin_abort_cmd;
1011 cmd.abort.cid = cmdid;
1012 cmd.abort.sqid = cpu_to_le16(nvmeq->qid);
1013 cmd.abort.command_id = a_cmdid;
1014
1015 --dev->abort_limit;
1016 info[cmdid].aborted = 1;
1017 info[cmdid].timeout = jiffies + ADMIN_TIMEOUT;
1018
1019 dev_warn(nvmeq->q_dmadev, "Aborting I/O %d QID %d\n", cmdid,
1020 nvmeq->qid);
1021 nvme_submit_cmd(dev->queues[0], &cmd);
1022}
1023
1024/**
923 * nvme_cancel_ios - Cancel outstanding I/Os 1025 * nvme_cancel_ios - Cancel outstanding I/Os
924 * @queue: The queue to cancel I/Os on 1026 * @queue: The queue to cancel I/Os on
925 * @timeout: True to only cancel I/Os which have timed out 1027 * @timeout: True to only cancel I/Os which have timed out
@@ -942,7 +1044,12 @@ static void nvme_cancel_ios(struct nvme_queue *nvmeq, bool timeout)
942 continue; 1044 continue;
943 if (info[cmdid].ctx == CMD_CTX_CANCELLED) 1045 if (info[cmdid].ctx == CMD_CTX_CANCELLED)
944 continue; 1046 continue;
945 dev_warn(nvmeq->q_dmadev, "Cancelling I/O %d\n", cmdid); 1047 if (timeout && nvmeq->dev->initialized) {
1048 nvme_abort_cmd(cmdid, nvmeq);
1049 continue;
1050 }
1051 dev_warn(nvmeq->q_dmadev, "Cancelling I/O %d QID %d\n", cmdid,
1052 nvmeq->qid);
946 ctx = cancel_cmdid(nvmeq, cmdid, &fn); 1053 ctx = cancel_cmdid(nvmeq, cmdid, &fn);
947 fn(nvmeq->dev, ctx, &cqe); 1054 fn(nvmeq->dev, ctx, &cqe);
948 } 1055 }
@@ -964,26 +1071,31 @@ static void nvme_free_queue(struct nvme_queue *nvmeq)
964 kfree(nvmeq); 1071 kfree(nvmeq);
965} 1072}
966 1073
967static void nvme_free_queues(struct nvme_dev *dev) 1074static void nvme_free_queues(struct nvme_dev *dev, int lowest)
968{ 1075{
969 int i; 1076 int i;
970 1077
971 for (i = dev->queue_count - 1; i >= 0; i--) { 1078 for (i = dev->queue_count - 1; i >= lowest; i--) {
972 nvme_free_queue(dev->queues[i]); 1079 nvme_free_queue(dev->queues[i]);
973 dev->queue_count--; 1080 dev->queue_count--;
974 dev->queues[i] = NULL; 1081 dev->queues[i] = NULL;
975 } 1082 }
976} 1083}
977 1084
978static void nvme_disable_queue(struct nvme_dev *dev, int qid) 1085/**
1086 * nvme_suspend_queue - put queue into suspended state
1087 * @nvmeq - queue to suspend
1088 *
1089 * Returns 1 if already suspended, 0 otherwise.
1090 */
1091static int nvme_suspend_queue(struct nvme_queue *nvmeq)
979{ 1092{
980 struct nvme_queue *nvmeq = dev->queues[qid]; 1093 int vector = nvmeq->dev->entry[nvmeq->cq_vector].vector;
981 int vector = dev->entry[nvmeq->cq_vector].vector;
982 1094
983 spin_lock_irq(&nvmeq->q_lock); 1095 spin_lock_irq(&nvmeq->q_lock);
984 if (nvmeq->q_suspended) { 1096 if (nvmeq->q_suspended) {
985 spin_unlock_irq(&nvmeq->q_lock); 1097 spin_unlock_irq(&nvmeq->q_lock);
986 return; 1098 return 1;
987 } 1099 }
988 nvmeq->q_suspended = 1; 1100 nvmeq->q_suspended = 1;
989 spin_unlock_irq(&nvmeq->q_lock); 1101 spin_unlock_irq(&nvmeq->q_lock);
@@ -991,18 +1103,35 @@ static void nvme_disable_queue(struct nvme_dev *dev, int qid)
991 irq_set_affinity_hint(vector, NULL); 1103 irq_set_affinity_hint(vector, NULL);
992 free_irq(vector, nvmeq); 1104 free_irq(vector, nvmeq);
993 1105
994 /* Don't tell the adapter to delete the admin queue */ 1106 return 0;
995 if (qid) { 1107}
996 adapter_delete_sq(dev, qid);
997 adapter_delete_cq(dev, qid);
998 }
999 1108
1109static void nvme_clear_queue(struct nvme_queue *nvmeq)
1110{
1000 spin_lock_irq(&nvmeq->q_lock); 1111 spin_lock_irq(&nvmeq->q_lock);
1001 nvme_process_cq(nvmeq); 1112 nvme_process_cq(nvmeq);
1002 nvme_cancel_ios(nvmeq, false); 1113 nvme_cancel_ios(nvmeq, false);
1003 spin_unlock_irq(&nvmeq->q_lock); 1114 spin_unlock_irq(&nvmeq->q_lock);
1004} 1115}
1005 1116
1117static void nvme_disable_queue(struct nvme_dev *dev, int qid)
1118{
1119 struct nvme_queue *nvmeq = dev->queues[qid];
1120
1121 if (!nvmeq)
1122 return;
1123 if (nvme_suspend_queue(nvmeq))
1124 return;
1125
1126 /* Don't tell the adapter to delete the admin queue.
1127 * Don't tell a removed adapter to delete IO queues. */
1128 if (qid && readl(&dev->bar->csts) != -1) {
1129 adapter_delete_sq(dev, qid);
1130 adapter_delete_cq(dev, qid);
1131 }
1132 nvme_clear_queue(nvmeq);
1133}
1134
1006static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid, 1135static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
1007 int depth, int vector) 1136 int depth, int vector)
1008{ 1137{
@@ -1025,15 +1154,18 @@ static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
1025 1154
1026 nvmeq->q_dmadev = dmadev; 1155 nvmeq->q_dmadev = dmadev;
1027 nvmeq->dev = dev; 1156 nvmeq->dev = dev;
1157 snprintf(nvmeq->irqname, sizeof(nvmeq->irqname), "nvme%dq%d",
1158 dev->instance, qid);
1028 spin_lock_init(&nvmeq->q_lock); 1159 spin_lock_init(&nvmeq->q_lock);
1029 nvmeq->cq_head = 0; 1160 nvmeq->cq_head = 0;
1030 nvmeq->cq_phase = 1; 1161 nvmeq->cq_phase = 1;
1031 init_waitqueue_head(&nvmeq->sq_full); 1162 init_waitqueue_head(&nvmeq->sq_full);
1032 init_waitqueue_entry(&nvmeq->sq_cong_wait, nvme_thread); 1163 init_waitqueue_entry(&nvmeq->sq_cong_wait, nvme_thread);
1033 bio_list_init(&nvmeq->sq_cong); 1164 bio_list_init(&nvmeq->sq_cong);
1034 nvmeq->q_db = &dev->dbs[qid << (dev->db_stride + 1)]; 1165 nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride];
1035 nvmeq->q_depth = depth; 1166 nvmeq->q_depth = depth;
1036 nvmeq->cq_vector = vector; 1167 nvmeq->cq_vector = vector;
1168 nvmeq->qid = qid;
1037 nvmeq->q_suspended = 1; 1169 nvmeq->q_suspended = 1;
1038 dev->queue_count++; 1170 dev->queue_count++;
1039 1171
@@ -1052,11 +1184,10 @@ static int queue_request_irq(struct nvme_dev *dev, struct nvme_queue *nvmeq,
1052{ 1184{
1053 if (use_threaded_interrupts) 1185 if (use_threaded_interrupts)
1054 return request_threaded_irq(dev->entry[nvmeq->cq_vector].vector, 1186 return request_threaded_irq(dev->entry[nvmeq->cq_vector].vector,
1055 nvme_irq_check, nvme_irq, 1187 nvme_irq_check, nvme_irq, IRQF_SHARED,
1056 IRQF_DISABLED | IRQF_SHARED,
1057 name, nvmeq); 1188 name, nvmeq);
1058 return request_irq(dev->entry[nvmeq->cq_vector].vector, nvme_irq, 1189 return request_irq(dev->entry[nvmeq->cq_vector].vector, nvme_irq,
1059 IRQF_DISABLED | IRQF_SHARED, name, nvmeq); 1190 IRQF_SHARED, name, nvmeq);
1060} 1191}
1061 1192
1062static void nvme_init_queue(struct nvme_queue *nvmeq, u16 qid) 1193static void nvme_init_queue(struct nvme_queue *nvmeq, u16 qid)
@@ -1067,7 +1198,7 @@ static void nvme_init_queue(struct nvme_queue *nvmeq, u16 qid)
1067 nvmeq->sq_tail = 0; 1198 nvmeq->sq_tail = 0;
1068 nvmeq->cq_head = 0; 1199 nvmeq->cq_head = 0;
1069 nvmeq->cq_phase = 1; 1200 nvmeq->cq_phase = 1;
1070 nvmeq->q_db = &dev->dbs[qid << (dev->db_stride + 1)]; 1201 nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride];
1071 memset(nvmeq->cmdid_data, 0, extra); 1202 memset(nvmeq->cmdid_data, 0, extra);
1072 memset((void *)nvmeq->cqes, 0, CQ_SIZE(nvmeq->q_depth)); 1203 memset((void *)nvmeq->cqes, 0, CQ_SIZE(nvmeq->q_depth));
1073 nvme_cancel_ios(nvmeq, false); 1204 nvme_cancel_ios(nvmeq, false);
@@ -1087,13 +1218,13 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
1087 if (result < 0) 1218 if (result < 0)
1088 goto release_cq; 1219 goto release_cq;
1089 1220
1090 result = queue_request_irq(dev, nvmeq, "nvme"); 1221 result = queue_request_irq(dev, nvmeq, nvmeq->irqname);
1091 if (result < 0) 1222 if (result < 0)
1092 goto release_sq; 1223 goto release_sq;
1093 1224
1094 spin_lock(&nvmeq->q_lock); 1225 spin_lock_irq(&nvmeq->q_lock);
1095 nvme_init_queue(nvmeq, qid); 1226 nvme_init_queue(nvmeq, qid);
1096 spin_unlock(&nvmeq->q_lock); 1227 spin_unlock_irq(&nvmeq->q_lock);
1097 1228
1098 return result; 1229 return result;
1099 1230
@@ -1205,13 +1336,13 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
1205 if (result) 1336 if (result)
1206 return result; 1337 return result;
1207 1338
1208 result = queue_request_irq(dev, nvmeq, "nvme admin"); 1339 result = queue_request_irq(dev, nvmeq, nvmeq->irqname);
1209 if (result) 1340 if (result)
1210 return result; 1341 return result;
1211 1342
1212 spin_lock(&nvmeq->q_lock); 1343 spin_lock_irq(&nvmeq->q_lock);
1213 nvme_init_queue(nvmeq, 0); 1344 nvme_init_queue(nvmeq, 0);
1214 spin_unlock(&nvmeq->q_lock); 1345 spin_unlock_irq(&nvmeq->q_lock);
1215 return result; 1346 return result;
1216} 1347}
1217 1348
@@ -1487,10 +1618,47 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
1487 } 1618 }
1488} 1619}
1489 1620
1621#ifdef CONFIG_COMPAT
1622static int nvme_compat_ioctl(struct block_device *bdev, fmode_t mode,
1623 unsigned int cmd, unsigned long arg)
1624{
1625 struct nvme_ns *ns = bdev->bd_disk->private_data;
1626
1627 switch (cmd) {
1628 case SG_IO:
1629 return nvme_sg_io32(ns, arg);
1630 }
1631 return nvme_ioctl(bdev, mode, cmd, arg);
1632}
1633#else
1634#define nvme_compat_ioctl NULL
1635#endif
1636
1637static int nvme_open(struct block_device *bdev, fmode_t mode)
1638{
1639 struct nvme_ns *ns = bdev->bd_disk->private_data;
1640 struct nvme_dev *dev = ns->dev;
1641
1642 kref_get(&dev->kref);
1643 return 0;
1644}
1645
1646static void nvme_free_dev(struct kref *kref);
1647
1648static void nvme_release(struct gendisk *disk, fmode_t mode)
1649{
1650 struct nvme_ns *ns = disk->private_data;
1651 struct nvme_dev *dev = ns->dev;
1652
1653 kref_put(&dev->kref, nvme_free_dev);
1654}
1655
1490static const struct block_device_operations nvme_fops = { 1656static const struct block_device_operations nvme_fops = {
1491 .owner = THIS_MODULE, 1657 .owner = THIS_MODULE,
1492 .ioctl = nvme_ioctl, 1658 .ioctl = nvme_ioctl,
1493 .compat_ioctl = nvme_ioctl, 1659 .compat_ioctl = nvme_compat_ioctl,
1660 .open = nvme_open,
1661 .release = nvme_release,
1494}; 1662};
1495 1663
1496static void nvme_resubmit_bios(struct nvme_queue *nvmeq) 1664static void nvme_resubmit_bios(struct nvme_queue *nvmeq)
@@ -1514,13 +1682,24 @@ static void nvme_resubmit_bios(struct nvme_queue *nvmeq)
1514 1682
1515static int nvme_kthread(void *data) 1683static int nvme_kthread(void *data)
1516{ 1684{
1517 struct nvme_dev *dev; 1685 struct nvme_dev *dev, *next;
1518 1686
1519 while (!kthread_should_stop()) { 1687 while (!kthread_should_stop()) {
1520 set_current_state(TASK_INTERRUPTIBLE); 1688 set_current_state(TASK_INTERRUPTIBLE);
1521 spin_lock(&dev_list_lock); 1689 spin_lock(&dev_list_lock);
1522 list_for_each_entry(dev, &dev_list, node) { 1690 list_for_each_entry_safe(dev, next, &dev_list, node) {
1523 int i; 1691 int i;
1692 if (readl(&dev->bar->csts) & NVME_CSTS_CFS &&
1693 dev->initialized) {
1694 if (work_busy(&dev->reset_work))
1695 continue;
1696 list_del_init(&dev->node);
1697 dev_warn(&dev->pci_dev->dev,
1698 "Failed status, reset controller\n");
1699 dev->reset_workfn = nvme_reset_failed_dev;
1700 queue_work(nvme_workq, &dev->reset_work);
1701 continue;
1702 }
1524 for (i = 0; i < dev->queue_count; i++) { 1703 for (i = 0; i < dev->queue_count; i++) {
1525 struct nvme_queue *nvmeq = dev->queues[i]; 1704 struct nvme_queue *nvmeq = dev->queues[i];
1526 if (!nvmeq) 1705 if (!nvmeq)
@@ -1541,33 +1720,6 @@ static int nvme_kthread(void *data)
1541 return 0; 1720 return 0;
1542} 1721}
1543 1722
1544static DEFINE_IDA(nvme_index_ida);
1545
1546static int nvme_get_ns_idx(void)
1547{
1548 int index, error;
1549
1550 do {
1551 if (!ida_pre_get(&nvme_index_ida, GFP_KERNEL))
1552 return -1;
1553
1554 spin_lock(&dev_list_lock);
1555 error = ida_get_new(&nvme_index_ida, &index);
1556 spin_unlock(&dev_list_lock);
1557 } while (error == -EAGAIN);
1558
1559 if (error)
1560 index = -1;
1561 return index;
1562}
1563
1564static void nvme_put_ns_idx(int index)
1565{
1566 spin_lock(&dev_list_lock);
1567 ida_remove(&nvme_index_ida, index);
1568 spin_unlock(&dev_list_lock);
1569}
1570
1571static void nvme_config_discard(struct nvme_ns *ns) 1723static void nvme_config_discard(struct nvme_ns *ns)
1572{ 1724{
1573 u32 logical_block_size = queue_logical_block_size(ns->queue); 1725 u32 logical_block_size = queue_logical_block_size(ns->queue);
@@ -1601,7 +1753,7 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid,
1601 ns->dev = dev; 1753 ns->dev = dev;
1602 ns->queue->queuedata = ns; 1754 ns->queue->queuedata = ns;
1603 1755
1604 disk = alloc_disk(NVME_MINORS); 1756 disk = alloc_disk(0);
1605 if (!disk) 1757 if (!disk)
1606 goto out_free_queue; 1758 goto out_free_queue;
1607 ns->ns_id = nsid; 1759 ns->ns_id = nsid;
@@ -1614,12 +1766,12 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid,
1614 blk_queue_max_hw_sectors(ns->queue, dev->max_hw_sectors); 1766 blk_queue_max_hw_sectors(ns->queue, dev->max_hw_sectors);
1615 1767
1616 disk->major = nvme_major; 1768 disk->major = nvme_major;
1617 disk->minors = NVME_MINORS; 1769 disk->first_minor = 0;
1618 disk->first_minor = NVME_MINORS * nvme_get_ns_idx();
1619 disk->fops = &nvme_fops; 1770 disk->fops = &nvme_fops;
1620 disk->private_data = ns; 1771 disk->private_data = ns;
1621 disk->queue = ns->queue; 1772 disk->queue = ns->queue;
1622 disk->driverfs_dev = &dev->pci_dev->dev; 1773 disk->driverfs_dev = &dev->pci_dev->dev;
1774 disk->flags = GENHD_FL_EXT_DEVT;
1623 sprintf(disk->disk_name, "nvme%dn%d", dev->instance, nsid); 1775 sprintf(disk->disk_name, "nvme%dn%d", dev->instance, nsid);
1624 set_capacity(disk, le64_to_cpup(&id->nsze) << (ns->lba_shift - 9)); 1776 set_capacity(disk, le64_to_cpup(&id->nsze) << (ns->lba_shift - 9));
1625 1777
@@ -1635,15 +1787,6 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid,
1635 return NULL; 1787 return NULL;
1636} 1788}
1637 1789
1638static void nvme_ns_free(struct nvme_ns *ns)
1639{
1640 int index = ns->disk->first_minor / NVME_MINORS;
1641 put_disk(ns->disk);
1642 nvme_put_ns_idx(index);
1643 blk_cleanup_queue(ns->queue);
1644 kfree(ns);
1645}
1646
1647static int set_queue_count(struct nvme_dev *dev, int count) 1790static int set_queue_count(struct nvme_dev *dev, int count)
1648{ 1791{
1649 int status; 1792 int status;
@@ -1659,11 +1802,12 @@ static int set_queue_count(struct nvme_dev *dev, int count)
1659 1802
1660static size_t db_bar_size(struct nvme_dev *dev, unsigned nr_io_queues) 1803static size_t db_bar_size(struct nvme_dev *dev, unsigned nr_io_queues)
1661{ 1804{
1662 return 4096 + ((nr_io_queues + 1) << (dev->db_stride + 3)); 1805 return 4096 + ((nr_io_queues + 1) * 8 * dev->db_stride);
1663} 1806}
1664 1807
1665static int nvme_setup_io_queues(struct nvme_dev *dev) 1808static int nvme_setup_io_queues(struct nvme_dev *dev)
1666{ 1809{
1810 struct nvme_queue *adminq = dev->queues[0];
1667 struct pci_dev *pdev = dev->pci_dev; 1811 struct pci_dev *pdev = dev->pci_dev;
1668 int result, cpu, i, vecs, nr_io_queues, size, q_depth; 1812 int result, cpu, i, vecs, nr_io_queues, size, q_depth;
1669 1813
@@ -1690,7 +1834,7 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
1690 } 1834 }
1691 1835
1692 /* Deregister the admin queue's interrupt */ 1836 /* Deregister the admin queue's interrupt */
1693 free_irq(dev->entry[0].vector, dev->queues[0]); 1837 free_irq(dev->entry[0].vector, adminq);
1694 1838
1695 vecs = nr_io_queues; 1839 vecs = nr_io_queues;
1696 for (i = 0; i < vecs; i++) 1840 for (i = 0; i < vecs; i++)
@@ -1728,9 +1872,9 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
1728 */ 1872 */
1729 nr_io_queues = vecs; 1873 nr_io_queues = vecs;
1730 1874
1731 result = queue_request_irq(dev, dev->queues[0], "nvme admin"); 1875 result = queue_request_irq(dev, adminq, adminq->irqname);
1732 if (result) { 1876 if (result) {
1733 dev->queues[0]->q_suspended = 1; 1877 adminq->q_suspended = 1;
1734 goto free_queues; 1878 goto free_queues;
1735 } 1879 }
1736 1880
@@ -1739,9 +1883,9 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
1739 for (i = dev->queue_count - 1; i > nr_io_queues; i--) { 1883 for (i = dev->queue_count - 1; i > nr_io_queues; i--) {
1740 struct nvme_queue *nvmeq = dev->queues[i]; 1884 struct nvme_queue *nvmeq = dev->queues[i];
1741 1885
1742 spin_lock(&nvmeq->q_lock); 1886 spin_lock_irq(&nvmeq->q_lock);
1743 nvme_cancel_ios(nvmeq, false); 1887 nvme_cancel_ios(nvmeq, false);
1744 spin_unlock(&nvmeq->q_lock); 1888 spin_unlock_irq(&nvmeq->q_lock);
1745 1889
1746 nvme_free_queue(nvmeq); 1890 nvme_free_queue(nvmeq);
1747 dev->queue_count--; 1891 dev->queue_count--;
@@ -1782,7 +1926,7 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
1782 return 0; 1926 return 0;
1783 1927
1784 free_queues: 1928 free_queues:
1785 nvme_free_queues(dev); 1929 nvme_free_queues(dev, 1);
1786 return result; 1930 return result;
1787} 1931}
1788 1932
@@ -1794,6 +1938,7 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
1794 */ 1938 */
1795static int nvme_dev_add(struct nvme_dev *dev) 1939static int nvme_dev_add(struct nvme_dev *dev)
1796{ 1940{
1941 struct pci_dev *pdev = dev->pci_dev;
1797 int res; 1942 int res;
1798 unsigned nn, i; 1943 unsigned nn, i;
1799 struct nvme_ns *ns; 1944 struct nvme_ns *ns;
@@ -1803,8 +1948,7 @@ static int nvme_dev_add(struct nvme_dev *dev)
1803 dma_addr_t dma_addr; 1948 dma_addr_t dma_addr;
1804 int shift = NVME_CAP_MPSMIN(readq(&dev->bar->cap)) + 12; 1949 int shift = NVME_CAP_MPSMIN(readq(&dev->bar->cap)) + 12;
1805 1950
1806 mem = dma_alloc_coherent(&dev->pci_dev->dev, 8192, &dma_addr, 1951 mem = dma_alloc_coherent(&pdev->dev, 8192, &dma_addr, GFP_KERNEL);
1807 GFP_KERNEL);
1808 if (!mem) 1952 if (!mem)
1809 return -ENOMEM; 1953 return -ENOMEM;
1810 1954
@@ -1817,13 +1961,14 @@ static int nvme_dev_add(struct nvme_dev *dev)
1817 ctrl = mem; 1961 ctrl = mem;
1818 nn = le32_to_cpup(&ctrl->nn); 1962 nn = le32_to_cpup(&ctrl->nn);
1819 dev->oncs = le16_to_cpup(&ctrl->oncs); 1963 dev->oncs = le16_to_cpup(&ctrl->oncs);
1964 dev->abort_limit = ctrl->acl + 1;
1820 memcpy(dev->serial, ctrl->sn, sizeof(ctrl->sn)); 1965 memcpy(dev->serial, ctrl->sn, sizeof(ctrl->sn));
1821 memcpy(dev->model, ctrl->mn, sizeof(ctrl->mn)); 1966 memcpy(dev->model, ctrl->mn, sizeof(ctrl->mn));
1822 memcpy(dev->firmware_rev, ctrl->fr, sizeof(ctrl->fr)); 1967 memcpy(dev->firmware_rev, ctrl->fr, sizeof(ctrl->fr));
1823 if (ctrl->mdts) 1968 if (ctrl->mdts)
1824 dev->max_hw_sectors = 1 << (ctrl->mdts + shift - 9); 1969 dev->max_hw_sectors = 1 << (ctrl->mdts + shift - 9);
1825 if ((dev->pci_dev->vendor == PCI_VENDOR_ID_INTEL) && 1970 if ((pdev->vendor == PCI_VENDOR_ID_INTEL) &&
1826 (dev->pci_dev->device == 0x0953) && ctrl->vs[3]) 1971 (pdev->device == 0x0953) && ctrl->vs[3])
1827 dev->stripe_size = 1 << (ctrl->vs[3] + shift); 1972 dev->stripe_size = 1 << (ctrl->vs[3] + shift);
1828 1973
1829 id_ns = mem; 1974 id_ns = mem;
@@ -1871,16 +2016,21 @@ static int nvme_dev_map(struct nvme_dev *dev)
1871 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) 2016 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))
1872 goto disable; 2017 goto disable;
1873 2018
1874 pci_set_drvdata(pdev, dev);
1875 dev->bar = ioremap(pci_resource_start(pdev, 0), 8192); 2019 dev->bar = ioremap(pci_resource_start(pdev, 0), 8192);
1876 if (!dev->bar) 2020 if (!dev->bar)
1877 goto disable; 2021 goto disable;
1878 2022 if (readl(&dev->bar->csts) == -1) {
1879 dev->db_stride = NVME_CAP_STRIDE(readq(&dev->bar->cap)); 2023 result = -ENODEV;
2024 goto unmap;
2025 }
2026 dev->db_stride = 1 << NVME_CAP_STRIDE(readq(&dev->bar->cap));
1880 dev->dbs = ((void __iomem *)dev->bar) + 4096; 2027 dev->dbs = ((void __iomem *)dev->bar) + 4096;
1881 2028
1882 return 0; 2029 return 0;
1883 2030
2031 unmap:
2032 iounmap(dev->bar);
2033 dev->bar = NULL;
1884 disable: 2034 disable:
1885 pci_release_regions(pdev); 2035 pci_release_regions(pdev);
1886 disable_pci: 2036 disable_pci:
@@ -1898,37 +2048,183 @@ static void nvme_dev_unmap(struct nvme_dev *dev)
1898 if (dev->bar) { 2048 if (dev->bar) {
1899 iounmap(dev->bar); 2049 iounmap(dev->bar);
1900 dev->bar = NULL; 2050 dev->bar = NULL;
2051 pci_release_regions(dev->pci_dev);
1901 } 2052 }
1902 2053
1903 pci_release_regions(dev->pci_dev);
1904 if (pci_is_enabled(dev->pci_dev)) 2054 if (pci_is_enabled(dev->pci_dev))
1905 pci_disable_device(dev->pci_dev); 2055 pci_disable_device(dev->pci_dev);
1906} 2056}
1907 2057
2058struct nvme_delq_ctx {
2059 struct task_struct *waiter;
2060 struct kthread_worker *worker;
2061 atomic_t refcount;
2062};
2063
2064static void nvme_wait_dq(struct nvme_delq_ctx *dq, struct nvme_dev *dev)
2065{
2066 dq->waiter = current;
2067 mb();
2068
2069 for (;;) {
2070 set_current_state(TASK_KILLABLE);
2071 if (!atomic_read(&dq->refcount))
2072 break;
2073 if (!schedule_timeout(ADMIN_TIMEOUT) ||
2074 fatal_signal_pending(current)) {
2075 set_current_state(TASK_RUNNING);
2076
2077 nvme_disable_ctrl(dev, readq(&dev->bar->cap));
2078 nvme_disable_queue(dev, 0);
2079
2080 send_sig(SIGKILL, dq->worker->task, 1);
2081 flush_kthread_worker(dq->worker);
2082 return;
2083 }
2084 }
2085 set_current_state(TASK_RUNNING);
2086}
2087
2088static void nvme_put_dq(struct nvme_delq_ctx *dq)
2089{
2090 atomic_dec(&dq->refcount);
2091 if (dq->waiter)
2092 wake_up_process(dq->waiter);
2093}
2094
2095static struct nvme_delq_ctx *nvme_get_dq(struct nvme_delq_ctx *dq)
2096{
2097 atomic_inc(&dq->refcount);
2098 return dq;
2099}
2100
2101static void nvme_del_queue_end(struct nvme_queue *nvmeq)
2102{
2103 struct nvme_delq_ctx *dq = nvmeq->cmdinfo.ctx;
2104
2105 nvme_clear_queue(nvmeq);
2106 nvme_put_dq(dq);
2107}
2108
2109static int adapter_async_del_queue(struct nvme_queue *nvmeq, u8 opcode,
2110 kthread_work_func_t fn)
2111{
2112 struct nvme_command c;
2113
2114 memset(&c, 0, sizeof(c));
2115 c.delete_queue.opcode = opcode;
2116 c.delete_queue.qid = cpu_to_le16(nvmeq->qid);
2117
2118 init_kthread_work(&nvmeq->cmdinfo.work, fn);
2119 return nvme_submit_admin_cmd_async(nvmeq->dev, &c, &nvmeq->cmdinfo);
2120}
2121
2122static void nvme_del_cq_work_handler(struct kthread_work *work)
2123{
2124 struct nvme_queue *nvmeq = container_of(work, struct nvme_queue,
2125 cmdinfo.work);
2126 nvme_del_queue_end(nvmeq);
2127}
2128
2129static int nvme_delete_cq(struct nvme_queue *nvmeq)
2130{
2131 return adapter_async_del_queue(nvmeq, nvme_admin_delete_cq,
2132 nvme_del_cq_work_handler);
2133}
2134
2135static void nvme_del_sq_work_handler(struct kthread_work *work)
2136{
2137 struct nvme_queue *nvmeq = container_of(work, struct nvme_queue,
2138 cmdinfo.work);
2139 int status = nvmeq->cmdinfo.status;
2140
2141 if (!status)
2142 status = nvme_delete_cq(nvmeq);
2143 if (status)
2144 nvme_del_queue_end(nvmeq);
2145}
2146
2147static int nvme_delete_sq(struct nvme_queue *nvmeq)
2148{
2149 return adapter_async_del_queue(nvmeq, nvme_admin_delete_sq,
2150 nvme_del_sq_work_handler);
2151}
2152
2153static void nvme_del_queue_start(struct kthread_work *work)
2154{
2155 struct nvme_queue *nvmeq = container_of(work, struct nvme_queue,
2156 cmdinfo.work);
2157 allow_signal(SIGKILL);
2158 if (nvme_delete_sq(nvmeq))
2159 nvme_del_queue_end(nvmeq);
2160}
2161
2162static void nvme_disable_io_queues(struct nvme_dev *dev)
2163{
2164 int i;
2165 DEFINE_KTHREAD_WORKER_ONSTACK(worker);
2166 struct nvme_delq_ctx dq;
2167 struct task_struct *kworker_task = kthread_run(kthread_worker_fn,
2168 &worker, "nvme%d", dev->instance);
2169
2170 if (IS_ERR(kworker_task)) {
2171 dev_err(&dev->pci_dev->dev,
2172 "Failed to create queue del task\n");
2173 for (i = dev->queue_count - 1; i > 0; i--)
2174 nvme_disable_queue(dev, i);
2175 return;
2176 }
2177
2178 dq.waiter = NULL;
2179 atomic_set(&dq.refcount, 0);
2180 dq.worker = &worker;
2181 for (i = dev->queue_count - 1; i > 0; i--) {
2182 struct nvme_queue *nvmeq = dev->queues[i];
2183
2184 if (nvme_suspend_queue(nvmeq))
2185 continue;
2186 nvmeq->cmdinfo.ctx = nvme_get_dq(&dq);
2187 nvmeq->cmdinfo.worker = dq.worker;
2188 init_kthread_work(&nvmeq->cmdinfo.work, nvme_del_queue_start);
2189 queue_kthread_work(dq.worker, &nvmeq->cmdinfo.work);
2190 }
2191 nvme_wait_dq(&dq, dev);
2192 kthread_stop(kworker_task);
2193}
2194
1908static void nvme_dev_shutdown(struct nvme_dev *dev) 2195static void nvme_dev_shutdown(struct nvme_dev *dev)
1909{ 2196{
1910 int i; 2197 int i;
1911 2198
1912 for (i = dev->queue_count - 1; i >= 0; i--) 2199 dev->initialized = 0;
1913 nvme_disable_queue(dev, i);
1914 2200
1915 spin_lock(&dev_list_lock); 2201 spin_lock(&dev_list_lock);
1916 list_del_init(&dev->node); 2202 list_del_init(&dev->node);
1917 spin_unlock(&dev_list_lock); 2203 spin_unlock(&dev_list_lock);
1918 2204
1919 if (dev->bar) 2205 if (!dev->bar || (dev->bar && readl(&dev->bar->csts) == -1)) {
2206 for (i = dev->queue_count - 1; i >= 0; i--) {
2207 struct nvme_queue *nvmeq = dev->queues[i];
2208 nvme_suspend_queue(nvmeq);
2209 nvme_clear_queue(nvmeq);
2210 }
2211 } else {
2212 nvme_disable_io_queues(dev);
1920 nvme_shutdown_ctrl(dev); 2213 nvme_shutdown_ctrl(dev);
2214 nvme_disable_queue(dev, 0);
2215 }
1921 nvme_dev_unmap(dev); 2216 nvme_dev_unmap(dev);
1922} 2217}
1923 2218
1924static void nvme_dev_remove(struct nvme_dev *dev) 2219static void nvme_dev_remove(struct nvme_dev *dev)
1925{ 2220{
1926 struct nvme_ns *ns, *next; 2221 struct nvme_ns *ns;
1927 2222
1928 list_for_each_entry_safe(ns, next, &dev->namespaces, list) { 2223 list_for_each_entry(ns, &dev->namespaces, list) {
1929 list_del(&ns->list); 2224 if (ns->disk->flags & GENHD_FL_UP)
1930 del_gendisk(ns->disk); 2225 del_gendisk(ns->disk);
1931 nvme_ns_free(ns); 2226 if (!blk_queue_dying(ns->queue))
2227 blk_cleanup_queue(ns->queue);
1932 } 2228 }
1933} 2229}
1934 2230
@@ -1985,14 +2281,22 @@ static void nvme_release_instance(struct nvme_dev *dev)
1985 spin_unlock(&dev_list_lock); 2281 spin_unlock(&dev_list_lock);
1986} 2282}
1987 2283
2284static void nvme_free_namespaces(struct nvme_dev *dev)
2285{
2286 struct nvme_ns *ns, *next;
2287
2288 list_for_each_entry_safe(ns, next, &dev->namespaces, list) {
2289 list_del(&ns->list);
2290 put_disk(ns->disk);
2291 kfree(ns);
2292 }
2293}
2294
1988static void nvme_free_dev(struct kref *kref) 2295static void nvme_free_dev(struct kref *kref)
1989{ 2296{
1990 struct nvme_dev *dev = container_of(kref, struct nvme_dev, kref); 2297 struct nvme_dev *dev = container_of(kref, struct nvme_dev, kref);
1991 nvme_dev_remove(dev); 2298
1992 nvme_dev_shutdown(dev); 2299 nvme_free_namespaces(dev);
1993 nvme_free_queues(dev);
1994 nvme_release_instance(dev);
1995 nvme_release_prp_pools(dev);
1996 kfree(dev->queues); 2300 kfree(dev->queues);
1997 kfree(dev->entry); 2301 kfree(dev->entry);
1998 kfree(dev); 2302 kfree(dev);
@@ -2056,6 +2360,7 @@ static int nvme_dev_start(struct nvme_dev *dev)
2056 return result; 2360 return result;
2057 2361
2058 disable: 2362 disable:
2363 nvme_disable_queue(dev, 0);
2059 spin_lock(&dev_list_lock); 2364 spin_lock(&dev_list_lock);
2060 list_del_init(&dev->node); 2365 list_del_init(&dev->node);
2061 spin_unlock(&dev_list_lock); 2366 spin_unlock(&dev_list_lock);
@@ -2064,6 +2369,77 @@ static int nvme_dev_start(struct nvme_dev *dev)
2064 return result; 2369 return result;
2065} 2370}
2066 2371
2372static int nvme_remove_dead_ctrl(void *arg)
2373{
2374 struct nvme_dev *dev = (struct nvme_dev *)arg;
2375 struct pci_dev *pdev = dev->pci_dev;
2376
2377 if (pci_get_drvdata(pdev))
2378 pci_stop_and_remove_bus_device(pdev);
2379 kref_put(&dev->kref, nvme_free_dev);
2380 return 0;
2381}
2382
2383static void nvme_remove_disks(struct work_struct *ws)
2384{
2385 int i;
2386 struct nvme_dev *dev = container_of(ws, struct nvme_dev, reset_work);
2387
2388 nvme_dev_remove(dev);
2389 spin_lock(&dev_list_lock);
2390 for (i = dev->queue_count - 1; i > 0; i--) {
2391 BUG_ON(!dev->queues[i] || !dev->queues[i]->q_suspended);
2392 nvme_free_queue(dev->queues[i]);
2393 dev->queue_count--;
2394 dev->queues[i] = NULL;
2395 }
2396 spin_unlock(&dev_list_lock);
2397}
2398
2399static int nvme_dev_resume(struct nvme_dev *dev)
2400{
2401 int ret;
2402
2403 ret = nvme_dev_start(dev);
2404 if (ret && ret != -EBUSY)
2405 return ret;
2406 if (ret == -EBUSY) {
2407 spin_lock(&dev_list_lock);
2408 dev->reset_workfn = nvme_remove_disks;
2409 queue_work(nvme_workq, &dev->reset_work);
2410 spin_unlock(&dev_list_lock);
2411 }
2412 dev->initialized = 1;
2413 return 0;
2414}
2415
2416static void nvme_dev_reset(struct nvme_dev *dev)
2417{
2418 nvme_dev_shutdown(dev);
2419 if (nvme_dev_resume(dev)) {
2420 dev_err(&dev->pci_dev->dev, "Device failed to resume\n");
2421 kref_get(&dev->kref);
2422 if (IS_ERR(kthread_run(nvme_remove_dead_ctrl, dev, "nvme%d",
2423 dev->instance))) {
2424 dev_err(&dev->pci_dev->dev,
2425 "Failed to start controller remove task\n");
2426 kref_put(&dev->kref, nvme_free_dev);
2427 }
2428 }
2429}
2430
2431static void nvme_reset_failed_dev(struct work_struct *ws)
2432{
2433 struct nvme_dev *dev = container_of(ws, struct nvme_dev, reset_work);
2434 nvme_dev_reset(dev);
2435}
2436
2437static void nvme_reset_workfn(struct work_struct *work)
2438{
2439 struct nvme_dev *dev = container_of(work, struct nvme_dev, reset_work);
2440 dev->reset_workfn(work);
2441}
2442
2067static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) 2443static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2068{ 2444{
2069 int result = -ENOMEM; 2445 int result = -ENOMEM;
@@ -2082,8 +2458,10 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2082 goto free; 2458 goto free;
2083 2459
2084 INIT_LIST_HEAD(&dev->namespaces); 2460 INIT_LIST_HEAD(&dev->namespaces);
2461 dev->reset_workfn = nvme_reset_failed_dev;
2462 INIT_WORK(&dev->reset_work, nvme_reset_workfn);
2085 dev->pci_dev = pdev; 2463 dev->pci_dev = pdev;
2086 2464 pci_set_drvdata(pdev, dev);
2087 result = nvme_set_instance(dev); 2465 result = nvme_set_instance(dev);
2088 if (result) 2466 if (result)
2089 goto free; 2467 goto free;
@@ -2099,6 +2477,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2099 goto release_pools; 2477 goto release_pools;
2100 } 2478 }
2101 2479
2480 kref_init(&dev->kref);
2102 result = nvme_dev_add(dev); 2481 result = nvme_dev_add(dev);
2103 if (result) 2482 if (result)
2104 goto shutdown; 2483 goto shutdown;
@@ -2113,15 +2492,16 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2113 if (result) 2492 if (result)
2114 goto remove; 2493 goto remove;
2115 2494
2116 kref_init(&dev->kref); 2495 dev->initialized = 1;
2117 return 0; 2496 return 0;
2118 2497
2119 remove: 2498 remove:
2120 nvme_dev_remove(dev); 2499 nvme_dev_remove(dev);
2500 nvme_free_namespaces(dev);
2121 shutdown: 2501 shutdown:
2122 nvme_dev_shutdown(dev); 2502 nvme_dev_shutdown(dev);
2123 release_pools: 2503 release_pools:
2124 nvme_free_queues(dev); 2504 nvme_free_queues(dev, 0);
2125 nvme_release_prp_pools(dev); 2505 nvme_release_prp_pools(dev);
2126 release: 2506 release:
2127 nvme_release_instance(dev); 2507 nvme_release_instance(dev);
@@ -2132,10 +2512,28 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2132 return result; 2512 return result;
2133} 2513}
2134 2514
2515static void nvme_shutdown(struct pci_dev *pdev)
2516{
2517 struct nvme_dev *dev = pci_get_drvdata(pdev);
2518 nvme_dev_shutdown(dev);
2519}
2520
2135static void nvme_remove(struct pci_dev *pdev) 2521static void nvme_remove(struct pci_dev *pdev)
2136{ 2522{
2137 struct nvme_dev *dev = pci_get_drvdata(pdev); 2523 struct nvme_dev *dev = pci_get_drvdata(pdev);
2524
2525 spin_lock(&dev_list_lock);
2526 list_del_init(&dev->node);
2527 spin_unlock(&dev_list_lock);
2528
2529 pci_set_drvdata(pdev, NULL);
2530 flush_work(&dev->reset_work);
2138 misc_deregister(&dev->miscdev); 2531 misc_deregister(&dev->miscdev);
2532 nvme_dev_remove(dev);
2533 nvme_dev_shutdown(dev);
2534 nvme_free_queues(dev, 0);
2535 nvme_release_instance(dev);
2536 nvme_release_prp_pools(dev);
2139 kref_put(&dev->kref, nvme_free_dev); 2537 kref_put(&dev->kref, nvme_free_dev);
2140} 2538}
2141 2539
@@ -2159,13 +2557,12 @@ static int nvme_resume(struct device *dev)
2159{ 2557{
2160 struct pci_dev *pdev = to_pci_dev(dev); 2558 struct pci_dev *pdev = to_pci_dev(dev);
2161 struct nvme_dev *ndev = pci_get_drvdata(pdev); 2559 struct nvme_dev *ndev = pci_get_drvdata(pdev);
2162 int ret;
2163 2560
2164 ret = nvme_dev_start(ndev); 2561 if (nvme_dev_resume(ndev) && !work_busy(&ndev->reset_work)) {
2165 /* XXX: should remove gendisks if resume fails */ 2562 ndev->reset_workfn = nvme_reset_failed_dev;
2166 if (ret) 2563 queue_work(nvme_workq, &ndev->reset_work);
2167 nvme_free_queues(ndev); 2564 }
2168 return ret; 2565 return 0;
2169} 2566}
2170 2567
2171static SIMPLE_DEV_PM_OPS(nvme_dev_pm_ops, nvme_suspend, nvme_resume); 2568static SIMPLE_DEV_PM_OPS(nvme_dev_pm_ops, nvme_suspend, nvme_resume);
@@ -2192,6 +2589,7 @@ static struct pci_driver nvme_driver = {
2192 .id_table = nvme_id_table, 2589 .id_table = nvme_id_table,
2193 .probe = nvme_probe, 2590 .probe = nvme_probe,
2194 .remove = nvme_remove, 2591 .remove = nvme_remove,
2592 .shutdown = nvme_shutdown,
2195 .driver = { 2593 .driver = {
2196 .pm = &nvme_dev_pm_ops, 2594 .pm = &nvme_dev_pm_ops,
2197 }, 2595 },
@@ -2206,9 +2604,14 @@ static int __init nvme_init(void)
2206 if (IS_ERR(nvme_thread)) 2604 if (IS_ERR(nvme_thread))
2207 return PTR_ERR(nvme_thread); 2605 return PTR_ERR(nvme_thread);
2208 2606
2607 result = -ENOMEM;
2608 nvme_workq = create_singlethread_workqueue("nvme");
2609 if (!nvme_workq)
2610 goto kill_kthread;
2611
2209 result = register_blkdev(nvme_major, "nvme"); 2612 result = register_blkdev(nvme_major, "nvme");
2210 if (result < 0) 2613 if (result < 0)
2211 goto kill_kthread; 2614 goto kill_workq;
2212 else if (result > 0) 2615 else if (result > 0)
2213 nvme_major = result; 2616 nvme_major = result;
2214 2617
@@ -2219,6 +2622,8 @@ static int __init nvme_init(void)
2219 2622
2220 unregister_blkdev: 2623 unregister_blkdev:
2221 unregister_blkdev(nvme_major, "nvme"); 2624 unregister_blkdev(nvme_major, "nvme");
2625 kill_workq:
2626 destroy_workqueue(nvme_workq);
2222 kill_kthread: 2627 kill_kthread:
2223 kthread_stop(nvme_thread); 2628 kthread_stop(nvme_thread);
2224 return result; 2629 return result;
@@ -2228,6 +2633,7 @@ static void __exit nvme_exit(void)
2228{ 2633{
2229 pci_unregister_driver(&nvme_driver); 2634 pci_unregister_driver(&nvme_driver);
2230 unregister_blkdev(nvme_major, "nvme"); 2635 unregister_blkdev(nvme_major, "nvme");
2636 destroy_workqueue(nvme_workq);
2231 kthread_stop(nvme_thread); 2637 kthread_stop(nvme_thread);
2232} 2638}
2233 2639
diff --git a/drivers/block/nvme-scsi.c b/drivers/block/nvme-scsi.c
index 4a4ff4eb8e23..4a0ceb64e269 100644
--- a/drivers/block/nvme-scsi.c
+++ b/drivers/block/nvme-scsi.c
@@ -25,6 +25,7 @@
25#include <linux/bio.h> 25#include <linux/bio.h>
26#include <linux/bitops.h> 26#include <linux/bitops.h>
27#include <linux/blkdev.h> 27#include <linux/blkdev.h>
28#include <linux/compat.h>
28#include <linux/delay.h> 29#include <linux/delay.h>
29#include <linux/errno.h> 30#include <linux/errno.h>
30#include <linux/fs.h> 31#include <linux/fs.h>
@@ -3038,6 +3039,152 @@ int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr)
3038 return retcode; 3039 return retcode;
3039} 3040}
3040 3041
3042#ifdef CONFIG_COMPAT
3043typedef struct sg_io_hdr32 {
3044 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
3045 compat_int_t dxfer_direction; /* [i] data transfer direction */
3046 unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
3047 unsigned char mx_sb_len; /* [i] max length to write to sbp */
3048 unsigned short iovec_count; /* [i] 0 implies no scatter gather */
3049 compat_uint_t dxfer_len; /* [i] byte count of data transfer */
3050 compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
3051 or scatter gather list */
3052 compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
3053 compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
3054 compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
3055 compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
3056 compat_int_t pack_id; /* [i->o] unused internally (normally) */
3057 compat_uptr_t usr_ptr; /* [i->o] unused internally */
3058 unsigned char status; /* [o] scsi status */
3059 unsigned char masked_status; /* [o] shifted, masked scsi status */
3060 unsigned char msg_status; /* [o] messaging level data (optional) */
3061 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
3062 unsigned short host_status; /* [o] errors from host adapter */
3063 unsigned short driver_status; /* [o] errors from software driver */
3064 compat_int_t resid; /* [o] dxfer_len - actual_transferred */
3065 compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
3066 compat_uint_t info; /* [o] auxiliary information */
3067} sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
3068
3069typedef struct sg_iovec32 {
3070 compat_uint_t iov_base;
3071 compat_uint_t iov_len;
3072} sg_iovec32_t;
3073
3074static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
3075{
3076 sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
3077 sg_iovec32_t __user *iov32 = dxferp;
3078 int i;
3079
3080 for (i = 0; i < iovec_count; i++) {
3081 u32 base, len;
3082
3083 if (get_user(base, &iov32[i].iov_base) ||
3084 get_user(len, &iov32[i].iov_len) ||
3085 put_user(compat_ptr(base), &iov[i].iov_base) ||
3086 put_user(len, &iov[i].iov_len))
3087 return -EFAULT;
3088 }
3089
3090 if (put_user(iov, &sgio->dxferp))
3091 return -EFAULT;
3092 return 0;
3093}
3094
3095int nvme_sg_io32(struct nvme_ns *ns, unsigned long arg)
3096{
3097 sg_io_hdr32_t __user *sgio32 = (sg_io_hdr32_t __user *)arg;
3098 sg_io_hdr_t __user *sgio;
3099 u16 iovec_count;
3100 u32 data;
3101 void __user *dxferp;
3102 int err;
3103 int interface_id;
3104
3105 if (get_user(interface_id, &sgio32->interface_id))
3106 return -EFAULT;
3107 if (interface_id != 'S')
3108 return -EINVAL;
3109
3110 if (get_user(iovec_count, &sgio32->iovec_count))
3111 return -EFAULT;
3112
3113 {
3114 void __user *top = compat_alloc_user_space(0);
3115 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
3116 (iovec_count * sizeof(sg_iovec_t)));
3117 if (new > top)
3118 return -EINVAL;
3119
3120 sgio = new;
3121 }
3122
3123 /* Ok, now construct. */
3124 if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
3125 (2 * sizeof(int)) +
3126 (2 * sizeof(unsigned char)) +
3127 (1 * sizeof(unsigned short)) +
3128 (1 * sizeof(unsigned int))))
3129 return -EFAULT;
3130
3131 if (get_user(data, &sgio32->dxferp))
3132 return -EFAULT;
3133 dxferp = compat_ptr(data);
3134 if (iovec_count) {
3135 if (sg_build_iovec(sgio, dxferp, iovec_count))
3136 return -EFAULT;
3137 } else {
3138 if (put_user(dxferp, &sgio->dxferp))
3139 return -EFAULT;
3140 }
3141
3142 {
3143 unsigned char __user *cmdp;
3144 unsigned char __user *sbp;
3145
3146 if (get_user(data, &sgio32->cmdp))
3147 return -EFAULT;
3148 cmdp = compat_ptr(data);
3149
3150 if (get_user(data, &sgio32->sbp))
3151 return -EFAULT;
3152 sbp = compat_ptr(data);
3153
3154 if (put_user(cmdp, &sgio->cmdp) ||
3155 put_user(sbp, &sgio->sbp))
3156 return -EFAULT;
3157 }
3158
3159 if (copy_in_user(&sgio->timeout, &sgio32->timeout,
3160 3 * sizeof(int)))
3161 return -EFAULT;
3162
3163 if (get_user(data, &sgio32->usr_ptr))
3164 return -EFAULT;
3165 if (put_user(compat_ptr(data), &sgio->usr_ptr))
3166 return -EFAULT;
3167
3168 err = nvme_sg_io(ns, sgio);
3169 if (err >= 0) {
3170 void __user *datap;
3171
3172 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
3173 sizeof(int)) ||
3174 get_user(datap, &sgio->usr_ptr) ||
3175 put_user((u32)(unsigned long)datap,
3176 &sgio32->usr_ptr) ||
3177 copy_in_user(&sgio32->status, &sgio->status,
3178 (4 * sizeof(unsigned char)) +
3179 (2 * sizeof(unsigned short)) +
3180 (3 * sizeof(int))))
3181 err = -EFAULT;
3182 }
3183
3184 return err;
3185}
3186#endif
3187
3041int nvme_sg_get_version_num(int __user *ip) 3188int nvme_sg_get_version_num(int __user *ip)
3042{ 3189{
3043 return put_user(sg_version_num, ip); 3190 return put_user(sg_version_num, ip);
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index b365e0dfccb6..34898d53395b 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2109,7 +2109,6 @@ static void rbd_img_obj_callback(struct rbd_obj_request *obj_request)
2109 rbd_assert(img_request->obj_request_count > 0); 2109 rbd_assert(img_request->obj_request_count > 0);
2110 rbd_assert(which != BAD_WHICH); 2110 rbd_assert(which != BAD_WHICH);
2111 rbd_assert(which < img_request->obj_request_count); 2111 rbd_assert(which < img_request->obj_request_count);
2112 rbd_assert(which >= img_request->next_completion);
2113 2112
2114 spin_lock_irq(&img_request->completion_lock); 2113 spin_lock_irq(&img_request->completion_lock);
2115 if (which != img_request->next_completion) 2114 if (which != img_request->next_completion)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 6a680d4de7f1..b1cb3f4c4db4 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -110,9 +110,9 @@ static int __virtblk_add_req(struct virtqueue *vq,
110 return virtqueue_add_sgs(vq, sgs, num_out, num_in, vbr, GFP_ATOMIC); 110 return virtqueue_add_sgs(vq, sgs, num_out, num_in, vbr, GFP_ATOMIC);
111} 111}
112 112
113static inline void virtblk_request_done(struct virtblk_req *vbr) 113static inline void virtblk_request_done(struct request *req)
114{ 114{
115 struct request *req = vbr->req; 115 struct virtblk_req *vbr = req->special;
116 int error = virtblk_result(vbr); 116 int error = virtblk_result(vbr);
117 117
118 if (req->cmd_type == REQ_TYPE_BLOCK_PC) { 118 if (req->cmd_type == REQ_TYPE_BLOCK_PC) {
@@ -138,7 +138,7 @@ static void virtblk_done(struct virtqueue *vq)
138 do { 138 do {
139 virtqueue_disable_cb(vq); 139 virtqueue_disable_cb(vq);
140 while ((vbr = virtqueue_get_buf(vblk->vq, &len)) != NULL) { 140 while ((vbr = virtqueue_get_buf(vblk->vq, &len)) != NULL) {
141 virtblk_request_done(vbr); 141 blk_mq_complete_request(vbr->req);
142 req_done = true; 142 req_done = true;
143 } 143 }
144 if (unlikely(virtqueue_is_broken(vq))) 144 if (unlikely(virtqueue_is_broken(vq)))
@@ -479,6 +479,7 @@ static struct blk_mq_ops virtio_mq_ops = {
479 .map_queue = blk_mq_map_queue, 479 .map_queue = blk_mq_map_queue,
480 .alloc_hctx = blk_mq_alloc_single_hw_queue, 480 .alloc_hctx = blk_mq_alloc_single_hw_queue,
481 .free_hctx = blk_mq_free_single_hw_queue, 481 .free_hctx = blk_mq_free_single_hw_queue,
482 .complete = virtblk_request_done,
482}; 483};
483 484
484static struct blk_mq_reg virtio_mq_reg = { 485static struct blk_mq_reg virtio_mq_reg = {
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index da18046d0e07..64c60edcdfbc 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -285,7 +285,8 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
285 285
286 if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST || 286 if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST ||
287 !rb_next(&persistent_gnt->node)) { 287 !rb_next(&persistent_gnt->node)) {
288 ret = gnttab_unmap_refs(unmap, pages, segs_to_unmap); 288 ret = gnttab_unmap_refs(unmap, NULL, pages,
289 segs_to_unmap);
289 BUG_ON(ret); 290 BUG_ON(ret);
290 put_free_pages(blkif, pages, segs_to_unmap); 291 put_free_pages(blkif, pages, segs_to_unmap);
291 segs_to_unmap = 0; 292 segs_to_unmap = 0;
@@ -298,7 +299,7 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
298 BUG_ON(num != 0); 299 BUG_ON(num != 0);
299} 300}
300 301
301static void unmap_purged_grants(struct work_struct *work) 302void xen_blkbk_unmap_purged_grants(struct work_struct *work)
302{ 303{
303 struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 304 struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
304 struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 305 struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
@@ -320,7 +321,8 @@ static void unmap_purged_grants(struct work_struct *work)
320 pages[segs_to_unmap] = persistent_gnt->page; 321 pages[segs_to_unmap] = persistent_gnt->page;
321 322
322 if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) { 323 if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
323 ret = gnttab_unmap_refs(unmap, pages, segs_to_unmap); 324 ret = gnttab_unmap_refs(unmap, NULL, pages,
325 segs_to_unmap);
324 BUG_ON(ret); 326 BUG_ON(ret);
325 put_free_pages(blkif, pages, segs_to_unmap); 327 put_free_pages(blkif, pages, segs_to_unmap);
326 segs_to_unmap = 0; 328 segs_to_unmap = 0;
@@ -328,7 +330,7 @@ static void unmap_purged_grants(struct work_struct *work)
328 kfree(persistent_gnt); 330 kfree(persistent_gnt);
329 } 331 }
330 if (segs_to_unmap > 0) { 332 if (segs_to_unmap > 0) {
331 ret = gnttab_unmap_refs(unmap, pages, segs_to_unmap); 333 ret = gnttab_unmap_refs(unmap, NULL, pages, segs_to_unmap);
332 BUG_ON(ret); 334 BUG_ON(ret);
333 put_free_pages(blkif, pages, segs_to_unmap); 335 put_free_pages(blkif, pages, segs_to_unmap);
334 } 336 }
@@ -373,7 +375,7 @@ static void purge_persistent_gnt(struct xen_blkif *blkif)
373 375
374 pr_debug(DRV_PFX "Going to purge %u persistent grants\n", num_clean); 376 pr_debug(DRV_PFX "Going to purge %u persistent grants\n", num_clean);
375 377
376 INIT_LIST_HEAD(&blkif->persistent_purge_list); 378 BUG_ON(!list_empty(&blkif->persistent_purge_list));
377 root = &blkif->persistent_gnts; 379 root = &blkif->persistent_gnts;
378purge_list: 380purge_list:
379 foreach_grant_safe(persistent_gnt, n, root, node) { 381 foreach_grant_safe(persistent_gnt, n, root, node) {
@@ -418,7 +420,6 @@ finished:
418 blkif->vbd.overflow_max_grants = 0; 420 blkif->vbd.overflow_max_grants = 0;
419 421
420 /* We can defer this work */ 422 /* We can defer this work */
421 INIT_WORK(&blkif->persistent_purge_work, unmap_purged_grants);
422 schedule_work(&blkif->persistent_purge_work); 423 schedule_work(&blkif->persistent_purge_work);
423 pr_debug(DRV_PFX "Purged %u/%u\n", (total - num_clean), total); 424 pr_debug(DRV_PFX "Purged %u/%u\n", (total - num_clean), total);
424 return; 425 return;
@@ -623,9 +624,23 @@ purge_gnt_list:
623 print_stats(blkif); 624 print_stats(blkif);
624 } 625 }
625 626
626 /* Since we are shutting down remove all pages from the buffer */ 627 /* Drain pending purge work */
627 shrink_free_pagepool(blkif, 0 /* All */); 628 flush_work(&blkif->persistent_purge_work);
628 629
630 if (log_stats)
631 print_stats(blkif);
632
633 blkif->xenblkd = NULL;
634 xen_blkif_put(blkif);
635
636 return 0;
637}
638
639/*
640 * Remove persistent grants and empty the pool of free pages
641 */
642void xen_blkbk_free_caches(struct xen_blkif *blkif)
643{
629 /* Free all persistent grant pages */ 644 /* Free all persistent grant pages */
630 if (!RB_EMPTY_ROOT(&blkif->persistent_gnts)) 645 if (!RB_EMPTY_ROOT(&blkif->persistent_gnts))
631 free_persistent_gnts(blkif, &blkif->persistent_gnts, 646 free_persistent_gnts(blkif, &blkif->persistent_gnts,
@@ -634,13 +649,8 @@ purge_gnt_list:
634 BUG_ON(!RB_EMPTY_ROOT(&blkif->persistent_gnts)); 649 BUG_ON(!RB_EMPTY_ROOT(&blkif->persistent_gnts));
635 blkif->persistent_gnt_c = 0; 650 blkif->persistent_gnt_c = 0;
636 651
637 if (log_stats) 652 /* Since we are shutting down remove all pages from the buffer */
638 print_stats(blkif); 653 shrink_free_pagepool(blkif, 0 /* All */);
639
640 blkif->xenblkd = NULL;
641 xen_blkif_put(blkif);
642
643 return 0;
644} 654}
645 655
646/* 656/*
@@ -668,14 +678,15 @@ static void xen_blkbk_unmap(struct xen_blkif *blkif,
668 GNTMAP_host_map, pages[i]->handle); 678 GNTMAP_host_map, pages[i]->handle);
669 pages[i]->handle = BLKBACK_INVALID_HANDLE; 679 pages[i]->handle = BLKBACK_INVALID_HANDLE;
670 if (++invcount == BLKIF_MAX_SEGMENTS_PER_REQUEST) { 680 if (++invcount == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
671 ret = gnttab_unmap_refs(unmap, unmap_pages, invcount); 681 ret = gnttab_unmap_refs(unmap, NULL, unmap_pages,
682 invcount);
672 BUG_ON(ret); 683 BUG_ON(ret);
673 put_free_pages(blkif, unmap_pages, invcount); 684 put_free_pages(blkif, unmap_pages, invcount);
674 invcount = 0; 685 invcount = 0;
675 } 686 }
676 } 687 }
677 if (invcount) { 688 if (invcount) {
678 ret = gnttab_unmap_refs(unmap, unmap_pages, invcount); 689 ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount);
679 BUG_ON(ret); 690 BUG_ON(ret);
680 put_free_pages(blkif, unmap_pages, invcount); 691 put_free_pages(blkif, unmap_pages, invcount);
681 } 692 }
@@ -737,7 +748,7 @@ again:
737 } 748 }
738 749
739 if (segs_to_map) { 750 if (segs_to_map) {
740 ret = gnttab_map_refs(map, pages_to_gnt, segs_to_map); 751 ret = gnttab_map_refs(map, NULL, pages_to_gnt, segs_to_map);
741 BUG_ON(ret); 752 BUG_ON(ret);
742 } 753 }
743 754
@@ -835,7 +846,7 @@ static int xen_blkbk_parse_indirect(struct blkif_request *req,
835 struct grant_page **pages = pending_req->indirect_pages; 846 struct grant_page **pages = pending_req->indirect_pages;
836 struct xen_blkif *blkif = pending_req->blkif; 847 struct xen_blkif *blkif = pending_req->blkif;
837 int indirect_grefs, rc, n, nseg, i; 848 int indirect_grefs, rc, n, nseg, i;
838 struct blkif_request_segment_aligned *segments = NULL; 849 struct blkif_request_segment *segments = NULL;
839 850
840 nseg = pending_req->nr_pages; 851 nseg = pending_req->nr_pages;
841 indirect_grefs = INDIRECT_PAGES(nseg); 852 indirect_grefs = INDIRECT_PAGES(nseg);
@@ -931,9 +942,7 @@ static void xen_blk_drain_io(struct xen_blkif *blkif)
931{ 942{
932 atomic_set(&blkif->drain, 1); 943 atomic_set(&blkif->drain, 1);
933 do { 944 do {
934 /* The initial value is one, and one refcnt taken at the 945 if (atomic_read(&blkif->inflight) == 0)
935 * start of the xen_blkif_schedule thread. */
936 if (atomic_read(&blkif->refcnt) <= 2)
937 break; 946 break;
938 wait_for_completion_interruptible_timeout( 947 wait_for_completion_interruptible_timeout(
939 &blkif->drain_complete, HZ); 948 &blkif->drain_complete, HZ);
@@ -973,17 +982,30 @@ static void __end_block_io_op(struct pending_req *pending_req, int error)
973 * the proper response on the ring. 982 * the proper response on the ring.
974 */ 983 */
975 if (atomic_dec_and_test(&pending_req->pendcnt)) { 984 if (atomic_dec_and_test(&pending_req->pendcnt)) {
976 xen_blkbk_unmap(pending_req->blkif, 985 struct xen_blkif *blkif = pending_req->blkif;
986
987 xen_blkbk_unmap(blkif,
977 pending_req->segments, 988 pending_req->segments,
978 pending_req->nr_pages); 989 pending_req->nr_pages);
979 make_response(pending_req->blkif, pending_req->id, 990 make_response(blkif, pending_req->id,
980 pending_req->operation, pending_req->status); 991 pending_req->operation, pending_req->status);
981 xen_blkif_put(pending_req->blkif); 992 free_req(blkif, pending_req);
982 if (atomic_read(&pending_req->blkif->refcnt) <= 2) { 993 /*
983 if (atomic_read(&pending_req->blkif->drain)) 994 * Make sure the request is freed before releasing blkif,
984 complete(&pending_req->blkif->drain_complete); 995 * or there could be a race between free_req and the
996 * cleanup done in xen_blkif_free during shutdown.
997 *
998 * NB: The fact that we might try to wake up pending_free_wq
999 * before drain_complete (in case there's a drain going on)
1000 * it's not a problem with our current implementation
1001 * because we can assure there's no thread waiting on
1002 * pending_free_wq if there's a drain going on, but it has
1003 * to be taken into account if the current model is changed.
1004 */
1005 if (atomic_dec_and_test(&blkif->inflight) && atomic_read(&blkif->drain)) {
1006 complete(&blkif->drain_complete);
985 } 1007 }
986 free_req(pending_req->blkif, pending_req); 1008 xen_blkif_put(blkif);
987 } 1009 }
988} 1010}
989 1011
@@ -1237,6 +1259,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
1237 * below (in "!bio") if we are handling a BLKIF_OP_DISCARD. 1259 * below (in "!bio") if we are handling a BLKIF_OP_DISCARD.
1238 */ 1260 */
1239 xen_blkif_get(blkif); 1261 xen_blkif_get(blkif);
1262 atomic_inc(&blkif->inflight);
1240 1263
1241 for (i = 0; i < nseg; i++) { 1264 for (i = 0; i < nseg; i++) {
1242 while ((bio == NULL) || 1265 while ((bio == NULL) ||
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
index 8d8807563d99..be052773ad03 100644
--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -57,7 +57,7 @@
57#define MAX_INDIRECT_SEGMENTS 256 57#define MAX_INDIRECT_SEGMENTS 256
58 58
59#define SEGS_PER_INDIRECT_FRAME \ 59#define SEGS_PER_INDIRECT_FRAME \
60 (PAGE_SIZE/sizeof(struct blkif_request_segment_aligned)) 60 (PAGE_SIZE/sizeof(struct blkif_request_segment))
61#define MAX_INDIRECT_PAGES \ 61#define MAX_INDIRECT_PAGES \
62 ((MAX_INDIRECT_SEGMENTS + SEGS_PER_INDIRECT_FRAME - 1)/SEGS_PER_INDIRECT_FRAME) 62 ((MAX_INDIRECT_SEGMENTS + SEGS_PER_INDIRECT_FRAME - 1)/SEGS_PER_INDIRECT_FRAME)
63#define INDIRECT_PAGES(_segs) \ 63#define INDIRECT_PAGES(_segs) \
@@ -278,6 +278,7 @@ struct xen_blkif {
278 /* for barrier (drain) requests */ 278 /* for barrier (drain) requests */
279 struct completion drain_complete; 279 struct completion drain_complete;
280 atomic_t drain; 280 atomic_t drain;
281 atomic_t inflight;
281 /* One thread per one blkif. */ 282 /* One thread per one blkif. */
282 struct task_struct *xenblkd; 283 struct task_struct *xenblkd;
283 unsigned int waiting_reqs; 284 unsigned int waiting_reqs;
@@ -376,6 +377,7 @@ int xen_blkif_xenbus_init(void);
376irqreturn_t xen_blkif_be_int(int irq, void *dev_id); 377irqreturn_t xen_blkif_be_int(int irq, void *dev_id);
377int xen_blkif_schedule(void *arg); 378int xen_blkif_schedule(void *arg);
378int xen_blkif_purge_persistent(void *arg); 379int xen_blkif_purge_persistent(void *arg);
380void xen_blkbk_free_caches(struct xen_blkif *blkif);
379 381
380int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt, 382int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
381 struct backend_info *be, int state); 383 struct backend_info *be, int state);
@@ -383,6 +385,7 @@ int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
383int xen_blkbk_barrier(struct xenbus_transaction xbt, 385int xen_blkbk_barrier(struct xenbus_transaction xbt,
384 struct backend_info *be, int state); 386 struct backend_info *be, int state);
385struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be); 387struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be);
388void xen_blkbk_unmap_purged_grants(struct work_struct *work);
386 389
387static inline void blkif_get_x86_32_req(struct blkif_request *dst, 390static inline void blkif_get_x86_32_req(struct blkif_request *dst,
388 struct blkif_x86_32_request *src) 391 struct blkif_x86_32_request *src)
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index c2014a0aa206..9a547e6b6ebf 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -125,8 +125,11 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
125 blkif->persistent_gnts.rb_node = NULL; 125 blkif->persistent_gnts.rb_node = NULL;
126 spin_lock_init(&blkif->free_pages_lock); 126 spin_lock_init(&blkif->free_pages_lock);
127 INIT_LIST_HEAD(&blkif->free_pages); 127 INIT_LIST_HEAD(&blkif->free_pages);
128 INIT_LIST_HEAD(&blkif->persistent_purge_list);
128 blkif->free_pages_num = 0; 129 blkif->free_pages_num = 0;
129 atomic_set(&blkif->persistent_gnt_in_use, 0); 130 atomic_set(&blkif->persistent_gnt_in_use, 0);
131 atomic_set(&blkif->inflight, 0);
132 INIT_WORK(&blkif->persistent_purge_work, xen_blkbk_unmap_purged_grants);
130 133
131 INIT_LIST_HEAD(&blkif->pending_free); 134 INIT_LIST_HEAD(&blkif->pending_free);
132 135
@@ -259,6 +262,17 @@ static void xen_blkif_free(struct xen_blkif *blkif)
259 if (!atomic_dec_and_test(&blkif->refcnt)) 262 if (!atomic_dec_and_test(&blkif->refcnt))
260 BUG(); 263 BUG();
261 264
265 /* Remove all persistent grants and the cache of ballooned pages. */
266 xen_blkbk_free_caches(blkif);
267
268 /* Make sure everything is drained before shutting down */
269 BUG_ON(blkif->persistent_gnt_c != 0);
270 BUG_ON(atomic_read(&blkif->persistent_gnt_in_use) != 0);
271 BUG_ON(blkif->free_pages_num != 0);
272 BUG_ON(!list_empty(&blkif->persistent_purge_list));
273 BUG_ON(!list_empty(&blkif->free_pages));
274 BUG_ON(!RB_EMPTY_ROOT(&blkif->persistent_gnts));
275
262 /* Check that there is no request in use */ 276 /* Check that there is no request in use */
263 list_for_each_entry_safe(req, n, &blkif->pending_free, free_list) { 277 list_for_each_entry_safe(req, n, &blkif->pending_free, free_list) {
264 list_del(&req->free_list); 278 list_del(&req->free_list);
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 8dcfb54f1603..efe1b4761735 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -162,7 +162,7 @@ static DEFINE_SPINLOCK(minor_lock);
162#define DEV_NAME "xvd" /* name in /dev */ 162#define DEV_NAME "xvd" /* name in /dev */
163 163
164#define SEGS_PER_INDIRECT_FRAME \ 164#define SEGS_PER_INDIRECT_FRAME \
165 (PAGE_SIZE/sizeof(struct blkif_request_segment_aligned)) 165 (PAGE_SIZE/sizeof(struct blkif_request_segment))
166#define INDIRECT_GREFS(_segs) \ 166#define INDIRECT_GREFS(_segs) \
167 ((_segs + SEGS_PER_INDIRECT_FRAME - 1)/SEGS_PER_INDIRECT_FRAME) 167 ((_segs + SEGS_PER_INDIRECT_FRAME - 1)/SEGS_PER_INDIRECT_FRAME)
168 168
@@ -393,7 +393,7 @@ static int blkif_queue_request(struct request *req)
393 unsigned long id; 393 unsigned long id;
394 unsigned int fsect, lsect; 394 unsigned int fsect, lsect;
395 int i, ref, n; 395 int i, ref, n;
396 struct blkif_request_segment_aligned *segments = NULL; 396 struct blkif_request_segment *segments = NULL;
397 397
398 /* 398 /*
399 * Used to store if we are able to queue the request by just using 399 * Used to store if we are able to queue the request by just using
@@ -550,7 +550,7 @@ static int blkif_queue_request(struct request *req)
550 } else { 550 } else {
551 n = i % SEGS_PER_INDIRECT_FRAME; 551 n = i % SEGS_PER_INDIRECT_FRAME;
552 segments[n] = 552 segments[n] =
553 (struct blkif_request_segment_aligned) { 553 (struct blkif_request_segment) {
554 .gref = ref, 554 .gref = ref,
555 .first_sect = fsect, 555 .first_sect = fsect,
556 .last_sect = lsect }; 556 .last_sect = lsect };
@@ -1904,13 +1904,16 @@ static void blkback_changed(struct xenbus_device *dev,
1904 case XenbusStateReconfiguring: 1904 case XenbusStateReconfiguring:
1905 case XenbusStateReconfigured: 1905 case XenbusStateReconfigured:
1906 case XenbusStateUnknown: 1906 case XenbusStateUnknown:
1907 case XenbusStateClosed:
1908 break; 1907 break;
1909 1908
1910 case XenbusStateConnected: 1909 case XenbusStateConnected:
1911 blkfront_connect(info); 1910 blkfront_connect(info);
1912 break; 1911 break;
1913 1912
1913 case XenbusStateClosed:
1914 if (dev->state == XenbusStateClosed)
1915 break;
1916 /* Missed the backend's Closing state -- fallthrough */
1914 case XenbusStateClosing: 1917 case XenbusStateClosing:
1915 blkfront_closing(info); 1918 blkfront_closing(info);
1916 break; 1919 break;
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 011e55d820b1..51c557cfd92b 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -612,6 +612,8 @@ static ssize_t disksize_store(struct device *dev,
612 612
613 disksize = PAGE_ALIGN(disksize); 613 disksize = PAGE_ALIGN(disksize);
614 meta = zram_meta_alloc(disksize); 614 meta = zram_meta_alloc(disksize);
615 if (!meta)
616 return -ENOMEM;
615 down_write(&zram->init_lock); 617 down_write(&zram->init_lock);
616 if (zram->init_done) { 618 if (zram->init_done) {
617 up_write(&zram->init_lock); 619 up_write(&zram->init_lock);
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index fa3243d71c76..1386749b48ff 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -499,6 +499,7 @@ config RAW_DRIVER
499config MAX_RAW_DEVS 499config MAX_RAW_DEVS
500 int "Maximum number of RAW devices to support (1-65536)" 500 int "Maximum number of RAW devices to support (1-65536)"
501 depends on RAW_DRIVER 501 depends on RAW_DRIVER
502 range 1 65536
502 default "256" 503 default "256"
503 help 504 help
504 The maximum number of RAW devices that are supported. 505 The maximum number of RAW devices that are supported.
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index f3223aac4df1..6e8d65e9b1d3 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -190,7 +190,7 @@ static int bind_get(int number, dev_t *dev)
190 struct raw_device_data *rawdev; 190 struct raw_device_data *rawdev;
191 struct block_device *bdev; 191 struct block_device *bdev;
192 192
193 if (number <= 0 || number >= MAX_RAW_MINORS) 193 if (number <= 0 || number >= max_raw_minors)
194 return -EINVAL; 194 return -EINVAL;
195 195
196 rawdev = &raw_devices[number]; 196 rawdev = &raw_devices[number];
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index feea87cc6b8f..6928d094451d 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -890,12 +890,10 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
890 } else { 890 } else {
891 /* Failback to copying a page */ 891 /* Failback to copying a page */
892 struct page *page = alloc_page(GFP_KERNEL); 892 struct page *page = alloc_page(GFP_KERNEL);
893 char *src = buf->ops->map(pipe, buf, 1); 893 char *src;
894 char *dst;
895 894
896 if (!page) 895 if (!page)
897 return -ENOMEM; 896 return -ENOMEM;
898 dst = kmap(page);
899 897
900 offset = sd->pos & ~PAGE_MASK; 898 offset = sd->pos & ~PAGE_MASK;
901 899
@@ -903,9 +901,8 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
903 if (len + offset > PAGE_SIZE) 901 if (len + offset > PAGE_SIZE)
904 len = PAGE_SIZE - offset; 902 len = PAGE_SIZE - offset;
905 903
906 memcpy(dst + offset, src + buf->offset, len); 904 src = buf->ops->map(pipe, buf, 1);
907 905 memcpy(page_address(page) + offset, src + buf->offset, len);
908 kunmap(page);
909 buf->ops->unmap(pipe, buf, src); 906 buf->ops->unmap(pipe, buf, src);
910 907
911 sg_set_page(&(sgl->sg[sgl->n]), page, len, offset); 908 sg_set_page(&(sgl->sg[sgl->n]), page, len, offset);
diff --git a/drivers/clk/at91/clk-master.c b/drivers/clk/at91/clk-master.c
index bd313f7816a8..c1af80bcdf20 100644
--- a/drivers/clk/at91/clk-master.c
+++ b/drivers/clk/at91/clk-master.c
@@ -242,7 +242,7 @@ of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc,
242 242
243 irq = irq_of_parse_and_map(np, 0); 243 irq = irq_of_parse_and_map(np, 0);
244 if (!irq) 244 if (!irq)
245 return; 245 goto out_free_characteristics;
246 246
247 clk = at91_clk_register_master(pmc, irq, name, num_parents, 247 clk = at91_clk_register_master(pmc, irq, name, num_parents,
248 parent_names, layout, 248 parent_names, layout,
diff --git a/drivers/clk/clk-nomadik.c b/drivers/clk/clk-nomadik.c
index 6a934a5296bd..05e04ce0f148 100644
--- a/drivers/clk/clk-nomadik.c
+++ b/drivers/clk/clk-nomadik.c
@@ -494,6 +494,9 @@ static const struct file_operations nomadik_src_clk_debugfs_ops = {
494 494
495static int __init nomadik_src_clk_init_debugfs(void) 495static int __init nomadik_src_clk_init_debugfs(void)
496{ 496{
497 /* Vital for multiplatform */
498 if (!src_base)
499 return -ENODEV;
497 src_pcksr0_boot = readl(src_base + SRC_PCKSR0); 500 src_pcksr0_boot = readl(src_base + SRC_PCKSR0);
498 src_pcksr1_boot = readl(src_base + SRC_PCKSR1); 501 src_pcksr1_boot = readl(src_base + SRC_PCKSR1);
499 debugfs_create_file("nomadik-src-clk", S_IFREG | S_IRUGO, 502 debugfs_create_file("nomadik-src-clk", S_IFREG | S_IRUGO,
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 5517944495d8..c42e608af6bb 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2226,24 +2226,25 @@ EXPORT_SYMBOL_GPL(devm_clk_unregister);
2226 */ 2226 */
2227int __clk_get(struct clk *clk) 2227int __clk_get(struct clk *clk)
2228{ 2228{
2229 if (clk && !try_module_get(clk->owner)) 2229 if (clk) {
2230 return 0; 2230 if (!try_module_get(clk->owner))
2231 return 0;
2231 2232
2232 kref_get(&clk->ref); 2233 kref_get(&clk->ref);
2234 }
2233 return 1; 2235 return 1;
2234} 2236}
2235 2237
2236void __clk_put(struct clk *clk) 2238void __clk_put(struct clk *clk)
2237{ 2239{
2238 if (WARN_ON_ONCE(IS_ERR(clk))) 2240 if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
2239 return; 2241 return;
2240 2242
2241 clk_prepare_lock(); 2243 clk_prepare_lock();
2242 kref_put(&clk->ref, __clk_release); 2244 kref_put(&clk->ref, __clk_release);
2243 clk_prepare_unlock(); 2245 clk_prepare_unlock();
2244 2246
2245 if (clk) 2247 module_put(clk->owner);
2246 module_put(clk->owner);
2247} 2248}
2248 2249
2249/*** clk rate change notifiers ***/ 2250/*** clk rate change notifiers ***/
diff --git a/drivers/clk/keystone/gate.c b/drivers/clk/keystone/gate.c
index 17a598398a53..86f1e362eafb 100644
--- a/drivers/clk/keystone/gate.c
+++ b/drivers/clk/keystone/gate.c
@@ -179,6 +179,7 @@ static struct clk *clk_register_psc(struct device *dev,
179 179
180 init.name = name; 180 init.name = name;
181 init.ops = &clk_psc_ops; 181 init.ops = &clk_psc_ops;
182 init.flags = 0;
182 init.parent_names = (parent_name ? &parent_name : NULL); 183 init.parent_names = (parent_name ? &parent_name : NULL);
183 init.num_parents = (parent_name ? 1 : 0); 184 init.num_parents = (parent_name ? 1 : 0);
184 185
diff --git a/drivers/clk/mvebu/armada-370.c b/drivers/clk/mvebu/armada-370.c
index 81a202d12a7a..bef198a83863 100644
--- a/drivers/clk/mvebu/armada-370.c
+++ b/drivers/clk/mvebu/armada-370.c
@@ -141,13 +141,6 @@ static const struct coreclk_soc_desc a370_coreclks = {
141 .num_ratios = ARRAY_SIZE(a370_coreclk_ratios), 141 .num_ratios = ARRAY_SIZE(a370_coreclk_ratios),
142}; 142};
143 143
144static void __init a370_coreclk_init(struct device_node *np)
145{
146 mvebu_coreclk_setup(np, &a370_coreclks);
147}
148CLK_OF_DECLARE(a370_core_clk, "marvell,armada-370-core-clock",
149 a370_coreclk_init);
150
151/* 144/*
152 * Clock Gating Control 145 * Clock Gating Control
153 */ 146 */
@@ -168,9 +161,15 @@ static const struct clk_gating_soc_desc a370_gating_desc[] __initconst = {
168 { } 161 { }
169}; 162};
170 163
171static void __init a370_clk_gating_init(struct device_node *np) 164static void __init a370_clk_init(struct device_node *np)
172{ 165{
173 mvebu_clk_gating_setup(np, a370_gating_desc); 166 struct device_node *cgnp =
167 of_find_compatible_node(NULL, NULL, "marvell,armada-370-gating-clock");
168
169 mvebu_coreclk_setup(np, &a370_coreclks);
170
171 if (cgnp)
172 mvebu_clk_gating_setup(cgnp, a370_gating_desc);
174} 173}
175CLK_OF_DECLARE(a370_clk_gating, "marvell,armada-370-gating-clock", 174CLK_OF_DECLARE(a370_clk, "marvell,armada-370-core-clock", a370_clk_init);
176 a370_clk_gating_init); 175
diff --git a/drivers/clk/mvebu/armada-xp.c b/drivers/clk/mvebu/armada-xp.c
index 9922c4475aa8..b3094315a3c0 100644
--- a/drivers/clk/mvebu/armada-xp.c
+++ b/drivers/clk/mvebu/armada-xp.c
@@ -158,13 +158,6 @@ static const struct coreclk_soc_desc axp_coreclks = {
158 .num_ratios = ARRAY_SIZE(axp_coreclk_ratios), 158 .num_ratios = ARRAY_SIZE(axp_coreclk_ratios),
159}; 159};
160 160
161static void __init axp_coreclk_init(struct device_node *np)
162{
163 mvebu_coreclk_setup(np, &axp_coreclks);
164}
165CLK_OF_DECLARE(axp_core_clk, "marvell,armada-xp-core-clock",
166 axp_coreclk_init);
167
168/* 161/*
169 * Clock Gating Control 162 * Clock Gating Control
170 */ 163 */
@@ -202,9 +195,14 @@ static const struct clk_gating_soc_desc axp_gating_desc[] __initconst = {
202 { } 195 { }
203}; 196};
204 197
205static void __init axp_clk_gating_init(struct device_node *np) 198static void __init axp_clk_init(struct device_node *np)
206{ 199{
207 mvebu_clk_gating_setup(np, axp_gating_desc); 200 struct device_node *cgnp =
201 of_find_compatible_node(NULL, NULL, "marvell,armada-xp-gating-clock");
202
203 mvebu_coreclk_setup(np, &axp_coreclks);
204
205 if (cgnp)
206 mvebu_clk_gating_setup(cgnp, axp_gating_desc);
208} 207}
209CLK_OF_DECLARE(axp_clk_gating, "marvell,armada-xp-gating-clock", 208CLK_OF_DECLARE(axp_clk, "marvell,armada-xp-core-clock", axp_clk_init);
210 axp_clk_gating_init);
diff --git a/drivers/clk/mvebu/dove.c b/drivers/clk/mvebu/dove.c
index 38aee1e3f242..b8c2424ac926 100644
--- a/drivers/clk/mvebu/dove.c
+++ b/drivers/clk/mvebu/dove.c
@@ -154,12 +154,6 @@ static const struct coreclk_soc_desc dove_coreclks = {
154 .num_ratios = ARRAY_SIZE(dove_coreclk_ratios), 154 .num_ratios = ARRAY_SIZE(dove_coreclk_ratios),
155}; 155};
156 156
157static void __init dove_coreclk_init(struct device_node *np)
158{
159 mvebu_coreclk_setup(np, &dove_coreclks);
160}
161CLK_OF_DECLARE(dove_core_clk, "marvell,dove-core-clock", dove_coreclk_init);
162
163/* 157/*
164 * Clock Gating Control 158 * Clock Gating Control
165 */ 159 */
@@ -186,9 +180,14 @@ static const struct clk_gating_soc_desc dove_gating_desc[] __initconst = {
186 { } 180 { }
187}; 181};
188 182
189static void __init dove_clk_gating_init(struct device_node *np) 183static void __init dove_clk_init(struct device_node *np)
190{ 184{
191 mvebu_clk_gating_setup(np, dove_gating_desc); 185 struct device_node *cgnp =
186 of_find_compatible_node(NULL, NULL, "marvell,dove-gating-clock");
187
188 mvebu_coreclk_setup(np, &dove_coreclks);
189
190 if (cgnp)
191 mvebu_clk_gating_setup(cgnp, dove_gating_desc);
192} 192}
193CLK_OF_DECLARE(dove_clk_gating, "marvell,dove-gating-clock", 193CLK_OF_DECLARE(dove_clk, "marvell,dove-core-clock", dove_clk_init);
194 dove_clk_gating_init);
diff --git a/drivers/clk/mvebu/kirkwood.c b/drivers/clk/mvebu/kirkwood.c
index 2636a55f29f9..ddb666a86500 100644
--- a/drivers/clk/mvebu/kirkwood.c
+++ b/drivers/clk/mvebu/kirkwood.c
@@ -193,13 +193,6 @@ static const struct coreclk_soc_desc kirkwood_coreclks = {
193 .num_ratios = ARRAY_SIZE(kirkwood_coreclk_ratios), 193 .num_ratios = ARRAY_SIZE(kirkwood_coreclk_ratios),
194}; 194};
195 195
196static void __init kirkwood_coreclk_init(struct device_node *np)
197{
198 mvebu_coreclk_setup(np, &kirkwood_coreclks);
199}
200CLK_OF_DECLARE(kirkwood_core_clk, "marvell,kirkwood-core-clock",
201 kirkwood_coreclk_init);
202
203static const struct coreclk_soc_desc mv88f6180_coreclks = { 196static const struct coreclk_soc_desc mv88f6180_coreclks = {
204 .get_tclk_freq = kirkwood_get_tclk_freq, 197 .get_tclk_freq = kirkwood_get_tclk_freq,
205 .get_cpu_freq = mv88f6180_get_cpu_freq, 198 .get_cpu_freq = mv88f6180_get_cpu_freq,
@@ -208,13 +201,6 @@ static const struct coreclk_soc_desc mv88f6180_coreclks = {
208 .num_ratios = ARRAY_SIZE(kirkwood_coreclk_ratios), 201 .num_ratios = ARRAY_SIZE(kirkwood_coreclk_ratios),
209}; 202};
210 203
211static void __init mv88f6180_coreclk_init(struct device_node *np)
212{
213 mvebu_coreclk_setup(np, &mv88f6180_coreclks);
214}
215CLK_OF_DECLARE(mv88f6180_core_clk, "marvell,mv88f6180-core-clock",
216 mv88f6180_coreclk_init);
217
218/* 204/*
219 * Clock Gating Control 205 * Clock Gating Control
220 */ 206 */
@@ -239,9 +225,21 @@ static const struct clk_gating_soc_desc kirkwood_gating_desc[] __initconst = {
239 { } 225 { }
240}; 226};
241 227
242static void __init kirkwood_clk_gating_init(struct device_node *np) 228static void __init kirkwood_clk_init(struct device_node *np)
243{ 229{
244 mvebu_clk_gating_setup(np, kirkwood_gating_desc); 230 struct device_node *cgnp =
231 of_find_compatible_node(NULL, NULL, "marvell,kirkwood-gating-clock");
232
233
234 if (of_device_is_compatible(np, "marvell,mv88f6180-core-clock"))
235 mvebu_coreclk_setup(np, &mv88f6180_coreclks);
236 else
237 mvebu_coreclk_setup(np, &kirkwood_coreclks);
238
239 if (cgnp)
240 mvebu_clk_gating_setup(cgnp, kirkwood_gating_desc);
245} 241}
246CLK_OF_DECLARE(kirkwood_clk_gating, "marvell,kirkwood-gating-clock", 242CLK_OF_DECLARE(kirkwood_clk, "marvell,kirkwood-core-clock",
247 kirkwood_clk_gating_init); 243 kirkwood_clk_init);
244CLK_OF_DECLARE(mv88f6180_clk, "marvell,mv88f6180-core-clock",
245 kirkwood_clk_init);
diff --git a/drivers/clk/shmobile/clk-rcar-gen2.c b/drivers/clk/shmobile/clk-rcar-gen2.c
index a59ec217a124..99c27b1c625b 100644
--- a/drivers/clk/shmobile/clk-rcar-gen2.c
+++ b/drivers/clk/shmobile/clk-rcar-gen2.c
@@ -26,6 +26,8 @@ struct rcar_gen2_cpg {
26 void __iomem *reg; 26 void __iomem *reg;
27}; 27};
28 28
29#define CPG_FRQCRB 0x00000004
30#define CPG_FRQCRB_KICK BIT(31)
29#define CPG_SDCKCR 0x00000074 31#define CPG_SDCKCR 0x00000074
30#define CPG_PLL0CR 0x000000d8 32#define CPG_PLL0CR 0x000000d8
31#define CPG_FRQCRC 0x000000e0 33#define CPG_FRQCRC 0x000000e0
@@ -45,6 +47,7 @@ struct rcar_gen2_cpg {
45struct cpg_z_clk { 47struct cpg_z_clk {
46 struct clk_hw hw; 48 struct clk_hw hw;
47 void __iomem *reg; 49 void __iomem *reg;
50 void __iomem *kick_reg;
48}; 51};
49 52
50#define to_z_clk(_hw) container_of(_hw, struct cpg_z_clk, hw) 53#define to_z_clk(_hw) container_of(_hw, struct cpg_z_clk, hw)
@@ -83,17 +86,45 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
83{ 86{
84 struct cpg_z_clk *zclk = to_z_clk(hw); 87 struct cpg_z_clk *zclk = to_z_clk(hw);
85 unsigned int mult; 88 unsigned int mult;
86 u32 val; 89 u32 val, kick;
90 unsigned int i;
87 91
88 mult = div_u64((u64)rate * 32, parent_rate); 92 mult = div_u64((u64)rate * 32, parent_rate);
89 mult = clamp(mult, 1U, 32U); 93 mult = clamp(mult, 1U, 32U);
90 94
95 if (clk_readl(zclk->kick_reg) & CPG_FRQCRB_KICK)
96 return -EBUSY;
97
91 val = clk_readl(zclk->reg); 98 val = clk_readl(zclk->reg);
92 val &= ~CPG_FRQCRC_ZFC_MASK; 99 val &= ~CPG_FRQCRC_ZFC_MASK;
93 val |= (32 - mult) << CPG_FRQCRC_ZFC_SHIFT; 100 val |= (32 - mult) << CPG_FRQCRC_ZFC_SHIFT;
94 clk_writel(val, zclk->reg); 101 clk_writel(val, zclk->reg);
95 102
96 return 0; 103 /*
104 * Set KICK bit in FRQCRB to update hardware setting and wait for
105 * clock change completion.
106 */
107 kick = clk_readl(zclk->kick_reg);
108 kick |= CPG_FRQCRB_KICK;
109 clk_writel(kick, zclk->kick_reg);
110
111 /*
112 * Note: There is no HW information about the worst case latency.
113 *
114 * Using experimental measurements, it seems that no more than
115 * ~10 iterations are needed, independently of the CPU rate.
116 * Since this value might be dependant of external xtal rate, pll1
117 * rate or even the other emulation clocks rate, use 1000 as a
118 * "super" safe value.
119 */
120 for (i = 1000; i; i--) {
121 if (!(clk_readl(zclk->kick_reg) & CPG_FRQCRB_KICK))
122 return 0;
123
124 cpu_relax();
125 }
126
127 return -ETIMEDOUT;
97} 128}
98 129
99static const struct clk_ops cpg_z_clk_ops = { 130static const struct clk_ops cpg_z_clk_ops = {
@@ -120,6 +151,7 @@ static struct clk * __init cpg_z_clk_register(struct rcar_gen2_cpg *cpg)
120 init.num_parents = 1; 151 init.num_parents = 1;
121 152
122 zclk->reg = cpg->reg + CPG_FRQCRC; 153 zclk->reg = cpg->reg + CPG_FRQCRC;
154 zclk->kick_reg = cpg->reg + CPG_FRQCRB;
123 zclk->hw.init = &init; 155 zclk->hw.init = &init;
124 156
125 clk = clk_register(NULL, &zclk->hw); 157 clk = clk_register(NULL, &zclk->hw);
@@ -186,7 +218,7 @@ rcar_gen2_cpg_register_clock(struct device_node *np, struct rcar_gen2_cpg *cpg,
186 const char *name) 218 const char *name)
187{ 219{
188 const struct clk_div_table *table = NULL; 220 const struct clk_div_table *table = NULL;
189 const char *parent_name = "main"; 221 const char *parent_name;
190 unsigned int shift; 222 unsigned int shift;
191 unsigned int mult = 1; 223 unsigned int mult = 1;
192 unsigned int div = 1; 224 unsigned int div = 1;
@@ -201,23 +233,31 @@ rcar_gen2_cpg_register_clock(struct device_node *np, struct rcar_gen2_cpg *cpg,
201 * the multiplier value. 233 * the multiplier value.
202 */ 234 */
203 u32 value = clk_readl(cpg->reg + CPG_PLL0CR); 235 u32 value = clk_readl(cpg->reg + CPG_PLL0CR);
236 parent_name = "main";
204 mult = ((value >> 24) & ((1 << 7) - 1)) + 1; 237 mult = ((value >> 24) & ((1 << 7) - 1)) + 1;
205 } else if (!strcmp(name, "pll1")) { 238 } else if (!strcmp(name, "pll1")) {
239 parent_name = "main";
206 mult = config->pll1_mult / 2; 240 mult = config->pll1_mult / 2;
207 } else if (!strcmp(name, "pll3")) { 241 } else if (!strcmp(name, "pll3")) {
242 parent_name = "main";
208 mult = config->pll3_mult; 243 mult = config->pll3_mult;
209 } else if (!strcmp(name, "lb")) { 244 } else if (!strcmp(name, "lb")) {
245 parent_name = "pll1_div2";
210 div = cpg_mode & BIT(18) ? 36 : 24; 246 div = cpg_mode & BIT(18) ? 36 : 24;
211 } else if (!strcmp(name, "qspi")) { 247 } else if (!strcmp(name, "qspi")) {
248 parent_name = "pll1_div2";
212 div = (cpg_mode & (BIT(3) | BIT(2) | BIT(1))) == BIT(2) 249 div = (cpg_mode & (BIT(3) | BIT(2) | BIT(1))) == BIT(2)
213 ? 16 : 20; 250 ? 8 : 10;
214 } else if (!strcmp(name, "sdh")) { 251 } else if (!strcmp(name, "sdh")) {
252 parent_name = "pll1_div2";
215 table = cpg_sdh_div_table; 253 table = cpg_sdh_div_table;
216 shift = 8; 254 shift = 8;
217 } else if (!strcmp(name, "sd0")) { 255 } else if (!strcmp(name, "sd0")) {
256 parent_name = "pll1_div2";
218 table = cpg_sd01_div_table; 257 table = cpg_sd01_div_table;
219 shift = 4; 258 shift = 4;
220 } else if (!strcmp(name, "sd1")) { 259 } else if (!strcmp(name, "sd1")) {
260 parent_name = "pll1_div2";
221 table = cpg_sd01_div_table; 261 table = cpg_sd01_div_table;
222 shift = 0; 262 shift = 0;
223 } else if (!strcmp(name, "z")) { 263 } else if (!strcmp(name, "z")) {
diff --git a/drivers/clk/tegra/clk-divider.c b/drivers/clk/tegra/clk-divider.c
index 4d75b1f37e3a..290f9c1a3749 100644
--- a/drivers/clk/tegra/clk-divider.c
+++ b/drivers/clk/tegra/clk-divider.c
@@ -59,7 +59,7 @@ static int get_div(struct tegra_clk_frac_div *divider, unsigned long rate,
59 return 0; 59 return 0;
60 60
61 if (divider_ux1 > get_max_div(divider)) 61 if (divider_ux1 > get_max_div(divider))
62 return -EINVAL; 62 return get_max_div(divider);
63 63
64 return divider_ux1; 64 return divider_ux1;
65} 65}
diff --git a/drivers/clk/tegra/clk-id.h b/drivers/clk/tegra/clk-id.h
index cf0c323f2c36..c39613c519af 100644
--- a/drivers/clk/tegra/clk-id.h
+++ b/drivers/clk/tegra/clk-id.h
@@ -180,9 +180,13 @@ enum clk_id {
180 tegra_clk_sbc6_8, 180 tegra_clk_sbc6_8,
181 tegra_clk_sclk, 181 tegra_clk_sclk,
182 tegra_clk_sdmmc1, 182 tegra_clk_sdmmc1,
183 tegra_clk_sdmmc1_8,
183 tegra_clk_sdmmc2, 184 tegra_clk_sdmmc2,
185 tegra_clk_sdmmc2_8,
184 tegra_clk_sdmmc3, 186 tegra_clk_sdmmc3,
187 tegra_clk_sdmmc3_8,
185 tegra_clk_sdmmc4, 188 tegra_clk_sdmmc4,
189 tegra_clk_sdmmc4_8,
186 tegra_clk_se, 190 tegra_clk_se,
187 tegra_clk_soc_therm, 191 tegra_clk_soc_therm,
188 tegra_clk_sor0, 192 tegra_clk_sor0,
diff --git a/drivers/clk/tegra/clk-tegra-periph.c b/drivers/clk/tegra/clk-tegra-periph.c
index 5c35885f4a7c..1fa5c3f33b20 100644
--- a/drivers/clk/tegra/clk-tegra-periph.c
+++ b/drivers/clk/tegra/clk-tegra-periph.c
@@ -371,9 +371,7 @@ static const char *mux_pllp3_pllc_clkm[] = {
371static const char *mux_pllm_pllc_pllp_plla_pllc2_c3_clkm[] = { 371static const char *mux_pllm_pllc_pllp_plla_pllc2_c3_clkm[] = {
372 "pll_m", "pll_c", "pll_p", "pll_a", "pll_c2", "pll_c3", "clk_m" 372 "pll_m", "pll_c", "pll_p", "pll_a", "pll_c2", "pll_c3", "clk_m"
373}; 373};
374static u32 mux_pllm_pllc_pllp_plla_pllc2_c3_clkm_idx[] = { 374#define mux_pllm_pllc_pllp_plla_pllc2_c3_clkm_idx NULL
375 [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 6,
376};
377 375
378static const char *mux_pllm_pllc2_c_c3_pllp_plla_pllc4[] = { 376static const char *mux_pllm_pllc2_c_c3_pllp_plla_pllc4[] = {
379 "pll_m", "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a_out0", "pll_c4", 377 "pll_m", "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a_out0", "pll_c4",
@@ -465,6 +463,10 @@ static struct tegra_periph_init_data periph_clks[] = {
465 MUX("adx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_ADX1, 180, TEGRA_PERIPH_ON_APB, tegra_clk_adx1), 463 MUX("adx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_ADX1, 180, TEGRA_PERIPH_ON_APB, tegra_clk_adx1),
466 MUX("amx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_AMX1, 185, TEGRA_PERIPH_ON_APB, tegra_clk_amx1), 464 MUX("amx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_AMX1, 185, TEGRA_PERIPH_ON_APB, tegra_clk_amx1),
467 MUX("vi_sensor2", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI_SENSOR2, 20, TEGRA_PERIPH_NO_RESET, tegra_clk_vi_sensor2), 465 MUX("vi_sensor2", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI_SENSOR2, 20, TEGRA_PERIPH_NO_RESET, tegra_clk_vi_sensor2),
466 MUX8("sdmmc1", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC1, 14, 0, tegra_clk_sdmmc1_8),
467 MUX8("sdmmc2", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC2, 9, 0, tegra_clk_sdmmc2_8),
468 MUX8("sdmmc3", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC3, 69, 0, tegra_clk_sdmmc3_8),
469 MUX8("sdmmc4", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC4, 15, 0, tegra_clk_sdmmc4_8),
468 MUX8("sbc1", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC1, 41, TEGRA_PERIPH_ON_APB, tegra_clk_sbc1_8), 470 MUX8("sbc1", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC1, 41, TEGRA_PERIPH_ON_APB, tegra_clk_sbc1_8),
469 MUX8("sbc2", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC2, 44, TEGRA_PERIPH_ON_APB, tegra_clk_sbc2_8), 471 MUX8("sbc2", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC2, 44, TEGRA_PERIPH_ON_APB, tegra_clk_sbc2_8),
470 MUX8("sbc3", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC3, 46, TEGRA_PERIPH_ON_APB, tegra_clk_sbc3_8), 472 MUX8("sbc3", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC3, 46, TEGRA_PERIPH_ON_APB, tegra_clk_sbc3_8),
@@ -492,7 +494,7 @@ static struct tegra_periph_init_data periph_clks[] = {
492 UART("uartb", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTB, 7, tegra_clk_uartb), 494 UART("uartb", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTB, 7, tegra_clk_uartb),
493 UART("uartc", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTC, 55, tegra_clk_uartc), 495 UART("uartc", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTC, 55, tegra_clk_uartc),
494 UART("uartd", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTD, 65, tegra_clk_uartd), 496 UART("uartd", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTD, 65, tegra_clk_uartd),
495 UART("uarte", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTE, 65, tegra_clk_uarte), 497 UART("uarte", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTE, 66, tegra_clk_uarte),
496 XUSB("xusb_host_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_HOST_SRC, 143, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_host_src), 498 XUSB("xusb_host_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_HOST_SRC, 143, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_host_src),
497 XUSB("xusb_falcon_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_FALCON_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_falcon_src), 499 XUSB("xusb_falcon_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_FALCON_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_falcon_src),
498 XUSB("xusb_fs_src", mux_clkm_48M_pllp_480M, CLK_SOURCE_XUSB_FS_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_fs_src), 500 XUSB("xusb_fs_src", mux_clkm_48M_pllp_480M, CLK_SOURCE_XUSB_FS_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_fs_src),
diff --git a/drivers/clk/tegra/clk-tegra-super-gen4.c b/drivers/clk/tegra/clk-tegra-super-gen4.c
index 05dce4aa2c11..feb3201c85ce 100644
--- a/drivers/clk/tegra/clk-tegra-super-gen4.c
+++ b/drivers/clk/tegra/clk-tegra-super-gen4.c
@@ -120,7 +120,7 @@ void __init tegra_super_clk_gen4_init(void __iomem *clk_base,
120 ARRAY_SIZE(cclk_lp_parents), 120 ARRAY_SIZE(cclk_lp_parents),
121 CLK_SET_RATE_PARENT, 121 CLK_SET_RATE_PARENT,
122 clk_base + CCLKLP_BURST_POLICY, 122 clk_base + CCLKLP_BURST_POLICY,
123 0, 4, 8, 9, NULL); 123 TEGRA_DIVIDER_2, 4, 8, 9, NULL);
124 *dt_clk = clk; 124 *dt_clk = clk;
125 } 125 }
126 126
diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
index 90d9d25f2228..80431f0fb268 100644
--- a/drivers/clk/tegra/clk-tegra114.c
+++ b/drivers/clk/tegra/clk-tegra114.c
@@ -682,12 +682,12 @@ static struct tegra_clk tegra114_clks[tegra_clk_max] __initdata = {
682 [tegra_clk_timer] = { .dt_id = TEGRA114_CLK_TIMER, .present = true }, 682 [tegra_clk_timer] = { .dt_id = TEGRA114_CLK_TIMER, .present = true },
683 [tegra_clk_uarta] = { .dt_id = TEGRA114_CLK_UARTA, .present = true }, 683 [tegra_clk_uarta] = { .dt_id = TEGRA114_CLK_UARTA, .present = true },
684 [tegra_clk_uartd] = { .dt_id = TEGRA114_CLK_UARTD, .present = true }, 684 [tegra_clk_uartd] = { .dt_id = TEGRA114_CLK_UARTD, .present = true },
685 [tegra_clk_sdmmc2] = { .dt_id = TEGRA114_CLK_SDMMC2, .present = true }, 685 [tegra_clk_sdmmc2_8] = { .dt_id = TEGRA114_CLK_SDMMC2, .present = true },
686 [tegra_clk_i2s1] = { .dt_id = TEGRA114_CLK_I2S1, .present = true }, 686 [tegra_clk_i2s1] = { .dt_id = TEGRA114_CLK_I2S1, .present = true },
687 [tegra_clk_i2c1] = { .dt_id = TEGRA114_CLK_I2C1, .present = true }, 687 [tegra_clk_i2c1] = { .dt_id = TEGRA114_CLK_I2C1, .present = true },
688 [tegra_clk_ndflash] = { .dt_id = TEGRA114_CLK_NDFLASH, .present = true }, 688 [tegra_clk_ndflash] = { .dt_id = TEGRA114_CLK_NDFLASH, .present = true },
689 [tegra_clk_sdmmc1] = { .dt_id = TEGRA114_CLK_SDMMC1, .present = true }, 689 [tegra_clk_sdmmc1_8] = { .dt_id = TEGRA114_CLK_SDMMC1, .present = true },
690 [tegra_clk_sdmmc4] = { .dt_id = TEGRA114_CLK_SDMMC4, .present = true }, 690 [tegra_clk_sdmmc4_8] = { .dt_id = TEGRA114_CLK_SDMMC4, .present = true },
691 [tegra_clk_pwm] = { .dt_id = TEGRA114_CLK_PWM, .present = true }, 691 [tegra_clk_pwm] = { .dt_id = TEGRA114_CLK_PWM, .present = true },
692 [tegra_clk_i2s0] = { .dt_id = TEGRA114_CLK_I2S0, .present = true }, 692 [tegra_clk_i2s0] = { .dt_id = TEGRA114_CLK_I2S0, .present = true },
693 [tegra_clk_i2s2] = { .dt_id = TEGRA114_CLK_I2S2, .present = true }, 693 [tegra_clk_i2s2] = { .dt_id = TEGRA114_CLK_I2S2, .present = true },
@@ -723,7 +723,7 @@ static struct tegra_clk tegra114_clks[tegra_clk_max] __initdata = {
723 [tegra_clk_bsev] = { .dt_id = TEGRA114_CLK_BSEV, .present = true }, 723 [tegra_clk_bsev] = { .dt_id = TEGRA114_CLK_BSEV, .present = true },
724 [tegra_clk_i2c3] = { .dt_id = TEGRA114_CLK_I2C3, .present = true }, 724 [tegra_clk_i2c3] = { .dt_id = TEGRA114_CLK_I2C3, .present = true },
725 [tegra_clk_sbc4_8] = { .dt_id = TEGRA114_CLK_SBC4, .present = true }, 725 [tegra_clk_sbc4_8] = { .dt_id = TEGRA114_CLK_SBC4, .present = true },
726 [tegra_clk_sdmmc3] = { .dt_id = TEGRA114_CLK_SDMMC3, .present = true }, 726 [tegra_clk_sdmmc3_8] = { .dt_id = TEGRA114_CLK_SDMMC3, .present = true },
727 [tegra_clk_owr] = { .dt_id = TEGRA114_CLK_OWR, .present = true }, 727 [tegra_clk_owr] = { .dt_id = TEGRA114_CLK_OWR, .present = true },
728 [tegra_clk_csite] = { .dt_id = TEGRA114_CLK_CSITE, .present = true }, 728 [tegra_clk_csite] = { .dt_id = TEGRA114_CLK_CSITE, .present = true },
729 [tegra_clk_la] = { .dt_id = TEGRA114_CLK_LA, .present = true }, 729 [tegra_clk_la] = { .dt_id = TEGRA114_CLK_LA, .present = true },
diff --git a/drivers/clk/tegra/clk-tegra124.c b/drivers/clk/tegra/clk-tegra124.c
index aff86b5bc745..166e02f16c8a 100644
--- a/drivers/clk/tegra/clk-tegra124.c
+++ b/drivers/clk/tegra/clk-tegra124.c
@@ -516,11 +516,11 @@ static struct div_nmp pllp_nmp = {
516}; 516};
517 517
518static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { 518static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
519 {12000000, 216000000, 432, 12, 1, 8}, 519 {12000000, 408000000, 408, 12, 0, 8},
520 {13000000, 216000000, 432, 13, 1, 8}, 520 {13000000, 408000000, 408, 13, 0, 8},
521 {16800000, 216000000, 360, 14, 1, 8}, 521 {16800000, 408000000, 340, 14, 0, 8},
522 {19200000, 216000000, 360, 16, 1, 8}, 522 {19200000, 408000000, 340, 16, 0, 8},
523 {26000000, 216000000, 432, 26, 1, 8}, 523 {26000000, 408000000, 408, 26, 0, 8},
524 {0, 0, 0, 0, 0, 0}, 524 {0, 0, 0, 0, 0, 0},
525}; 525};
526 526
@@ -570,6 +570,15 @@ static struct tegra_clk_pll_params pll_a_params = {
570 .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK, 570 .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK,
571}; 571};
572 572
573static struct div_nmp plld_nmp = {
574 .divm_shift = 0,
575 .divm_width = 5,
576 .divn_shift = 8,
577 .divn_width = 11,
578 .divp_shift = 20,
579 .divp_width = 3,
580};
581
573static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { 582static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
574 {12000000, 216000000, 864, 12, 4, 12}, 583 {12000000, 216000000, 864, 12, 4, 12},
575 {13000000, 216000000, 864, 13, 4, 12}, 584 {13000000, 216000000, 864, 13, 4, 12},
@@ -603,19 +612,18 @@ static struct tegra_clk_pll_params pll_d_params = {
603 .lock_mask = PLL_BASE_LOCK, 612 .lock_mask = PLL_BASE_LOCK,
604 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, 613 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
605 .lock_delay = 1000, 614 .lock_delay = 1000,
606 .div_nmp = &pllp_nmp, 615 .div_nmp = &plld_nmp,
607 .freq_table = pll_d_freq_table, 616 .freq_table = pll_d_freq_table,
608 .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | 617 .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
609 TEGRA_PLL_USE_LOCK, 618 TEGRA_PLL_USE_LOCK,
610}; 619};
611 620
612static struct tegra_clk_pll_freq_table tegra124_pll_d2_freq_table[] = { 621static struct tegra_clk_pll_freq_table tegra124_pll_d2_freq_table[] = {
613 { 12000000, 148500000, 99, 1, 8}, 622 { 12000000, 594000000, 99, 1, 2},
614 { 12000000, 594000000, 99, 1, 1}, 623 { 13000000, 594000000, 91, 1, 2}, /* actual: 591.5 MHz */
615 { 13000000, 594000000, 91, 1, 1}, /* actual: 591.5 MHz */ 624 { 16800000, 594000000, 71, 1, 2}, /* actual: 596.4 MHz */
616 { 16800000, 594000000, 71, 1, 1}, /* actual: 596.4 MHz */ 625 { 19200000, 594000000, 62, 1, 2}, /* actual: 595.2 MHz */
617 { 19200000, 594000000, 62, 1, 1}, /* actual: 595.2 MHz */ 626 { 26000000, 594000000, 91, 2, 2}, /* actual: 591.5 MHz */
618 { 26000000, 594000000, 91, 2, 1}, /* actual: 591.5 MHz */
619 { 0, 0, 0, 0, 0, 0 }, 627 { 0, 0, 0, 0, 0, 0 },
620}; 628};
621 629
@@ -753,21 +761,19 @@ static struct tegra_clk tegra124_clks[tegra_clk_max] __initdata = {
753 [tegra_clk_rtc] = { .dt_id = TEGRA124_CLK_RTC, .present = true }, 761 [tegra_clk_rtc] = { .dt_id = TEGRA124_CLK_RTC, .present = true },
754 [tegra_clk_timer] = { .dt_id = TEGRA124_CLK_TIMER, .present = true }, 762 [tegra_clk_timer] = { .dt_id = TEGRA124_CLK_TIMER, .present = true },
755 [tegra_clk_uarta] = { .dt_id = TEGRA124_CLK_UARTA, .present = true }, 763 [tegra_clk_uarta] = { .dt_id = TEGRA124_CLK_UARTA, .present = true },
756 [tegra_clk_sdmmc2] = { .dt_id = TEGRA124_CLK_SDMMC2, .present = true }, 764 [tegra_clk_sdmmc2_8] = { .dt_id = TEGRA124_CLK_SDMMC2, .present = true },
757 [tegra_clk_i2s1] = { .dt_id = TEGRA124_CLK_I2S1, .present = true }, 765 [tegra_clk_i2s1] = { .dt_id = TEGRA124_CLK_I2S1, .present = true },
758 [tegra_clk_i2c1] = { .dt_id = TEGRA124_CLK_I2C1, .present = true }, 766 [tegra_clk_i2c1] = { .dt_id = TEGRA124_CLK_I2C1, .present = true },
759 [tegra_clk_ndflash] = { .dt_id = TEGRA124_CLK_NDFLASH, .present = true }, 767 [tegra_clk_ndflash] = { .dt_id = TEGRA124_CLK_NDFLASH, .present = true },
760 [tegra_clk_sdmmc1] = { .dt_id = TEGRA124_CLK_SDMMC1, .present = true }, 768 [tegra_clk_sdmmc1_8] = { .dt_id = TEGRA124_CLK_SDMMC1, .present = true },
761 [tegra_clk_sdmmc4] = { .dt_id = TEGRA124_CLK_SDMMC4, .present = true }, 769 [tegra_clk_sdmmc4_8] = { .dt_id = TEGRA124_CLK_SDMMC4, .present = true },
762 [tegra_clk_pwm] = { .dt_id = TEGRA124_CLK_PWM, .present = true }, 770 [tegra_clk_pwm] = { .dt_id = TEGRA124_CLK_PWM, .present = true },
763 [tegra_clk_i2s2] = { .dt_id = TEGRA124_CLK_I2S2, .present = true }, 771 [tegra_clk_i2s2] = { .dt_id = TEGRA124_CLK_I2S2, .present = true },
764 [tegra_clk_gr2d] = { .dt_id = TEGRA124_CLK_GR_2D, .present = true },
765 [tegra_clk_usbd] = { .dt_id = TEGRA124_CLK_USBD, .present = true }, 772 [tegra_clk_usbd] = { .dt_id = TEGRA124_CLK_USBD, .present = true },
766 [tegra_clk_isp_8] = { .dt_id = TEGRA124_CLK_ISP, .present = true }, 773 [tegra_clk_isp_8] = { .dt_id = TEGRA124_CLK_ISP, .present = true },
767 [tegra_clk_gr3d] = { .dt_id = TEGRA124_CLK_GR_3D, .present = true },
768 [tegra_clk_disp2] = { .dt_id = TEGRA124_CLK_DISP2, .present = true }, 774 [tegra_clk_disp2] = { .dt_id = TEGRA124_CLK_DISP2, .present = true },
769 [tegra_clk_disp1] = { .dt_id = TEGRA124_CLK_DISP1, .present = true }, 775 [tegra_clk_disp1] = { .dt_id = TEGRA124_CLK_DISP1, .present = true },
770 [tegra_clk_host1x] = { .dt_id = TEGRA124_CLK_HOST1X, .present = true }, 776 [tegra_clk_host1x_8] = { .dt_id = TEGRA124_CLK_HOST1X, .present = true },
771 [tegra_clk_vcp] = { .dt_id = TEGRA124_CLK_VCP, .present = true }, 777 [tegra_clk_vcp] = { .dt_id = TEGRA124_CLK_VCP, .present = true },
772 [tegra_clk_i2s0] = { .dt_id = TEGRA124_CLK_I2S0, .present = true }, 778 [tegra_clk_i2s0] = { .dt_id = TEGRA124_CLK_I2S0, .present = true },
773 [tegra_clk_apbdma] = { .dt_id = TEGRA124_CLK_APBDMA, .present = true }, 779 [tegra_clk_apbdma] = { .dt_id = TEGRA124_CLK_APBDMA, .present = true },
@@ -794,7 +800,7 @@ static struct tegra_clk tegra124_clks[tegra_clk_max] __initdata = {
794 [tegra_clk_uartd] = { .dt_id = TEGRA124_CLK_UARTD, .present = true }, 800 [tegra_clk_uartd] = { .dt_id = TEGRA124_CLK_UARTD, .present = true },
795 [tegra_clk_i2c3] = { .dt_id = TEGRA124_CLK_I2C3, .present = true }, 801 [tegra_clk_i2c3] = { .dt_id = TEGRA124_CLK_I2C3, .present = true },
796 [tegra_clk_sbc4] = { .dt_id = TEGRA124_CLK_SBC4, .present = true }, 802 [tegra_clk_sbc4] = { .dt_id = TEGRA124_CLK_SBC4, .present = true },
797 [tegra_clk_sdmmc3] = { .dt_id = TEGRA124_CLK_SDMMC3, .present = true }, 803 [tegra_clk_sdmmc3_8] = { .dt_id = TEGRA124_CLK_SDMMC3, .present = true },
798 [tegra_clk_pcie] = { .dt_id = TEGRA124_CLK_PCIE, .present = true }, 804 [tegra_clk_pcie] = { .dt_id = TEGRA124_CLK_PCIE, .present = true },
799 [tegra_clk_owr] = { .dt_id = TEGRA124_CLK_OWR, .present = true }, 805 [tegra_clk_owr] = { .dt_id = TEGRA124_CLK_OWR, .present = true },
800 [tegra_clk_afi] = { .dt_id = TEGRA124_CLK_AFI, .present = true }, 806 [tegra_clk_afi] = { .dt_id = TEGRA124_CLK_AFI, .present = true },
@@ -1286,9 +1292,9 @@ static void __init tegra124_pll_init(void __iomem *clk_base,
1286 clk_register_clkdev(clk, "pll_d2", NULL); 1292 clk_register_clkdev(clk, "pll_d2", NULL);
1287 clks[TEGRA124_CLK_PLL_D2] = clk; 1293 clks[TEGRA124_CLK_PLL_D2] = clk;
1288 1294
1289 /* PLLD2_OUT0 ?? */ 1295 /* PLLD2_OUT0 */
1290 clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2", 1296 clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2",
1291 CLK_SET_RATE_PARENT, 1, 2); 1297 CLK_SET_RATE_PARENT, 1, 1);
1292 clk_register_clkdev(clk, "pll_d2_out0", NULL); 1298 clk_register_clkdev(clk, "pll_d2_out0", NULL);
1293 clks[TEGRA124_CLK_PLL_D2_OUT0] = clk; 1299 clks[TEGRA124_CLK_PLL_D2_OUT0] = clk;
1294 1300
diff --git a/drivers/clk/tegra/clk-tegra20.c b/drivers/clk/tegra/clk-tegra20.c
index dbace152b2fa..dace2b1b5ae6 100644
--- a/drivers/clk/tegra/clk-tegra20.c
+++ b/drivers/clk/tegra/clk-tegra20.c
@@ -574,6 +574,8 @@ static struct tegra_clk tegra20_clks[tegra_clk_max] __initdata = {
574 [tegra_clk_tvdac] = { .dt_id = TEGRA20_CLK_TVDAC, .present = true }, 574 [tegra_clk_tvdac] = { .dt_id = TEGRA20_CLK_TVDAC, .present = true },
575 [tegra_clk_vi_sensor] = { .dt_id = TEGRA20_CLK_VI_SENSOR, .present = true }, 575 [tegra_clk_vi_sensor] = { .dt_id = TEGRA20_CLK_VI_SENSOR, .present = true },
576 [tegra_clk_afi] = { .dt_id = TEGRA20_CLK_AFI, .present = true }, 576 [tegra_clk_afi] = { .dt_id = TEGRA20_CLK_AFI, .present = true },
577 [tegra_clk_fuse] = { .dt_id = TEGRA20_CLK_FUSE, .present = true },
578 [tegra_clk_kfuse] = { .dt_id = TEGRA20_CLK_KFUSE, .present = true },
577}; 579};
578 580
579static unsigned long tegra20_clk_measure_input_freq(void) 581static unsigned long tegra20_clk_measure_input_freq(void)
diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c
index 974b2db2fe10..0595dc6c453e 100644
--- a/drivers/clocksource/bcm_kona_timer.c
+++ b/drivers/clocksource/bcm_kona_timer.c
@@ -99,31 +99,6 @@ kona_timer_get_counter(void *timer_base, uint32_t *msw, uint32_t *lsw)
99 return; 99 return;
100} 100}
101 101
102static void __init kona_timers_init(struct device_node *node)
103{
104 u32 freq;
105 struct clk *external_clk;
106
107 external_clk = of_clk_get_by_name(node, NULL);
108
109 if (!IS_ERR(external_clk)) {
110 arch_timer_rate = clk_get_rate(external_clk);
111 clk_prepare_enable(external_clk);
112 } else if (!of_property_read_u32(node, "clock-frequency", &freq)) {
113 arch_timer_rate = freq;
114 } else {
115 panic("unable to determine clock-frequency");
116 }
117
118 /* Setup IRQ numbers */
119 timers.tmr_irq = irq_of_parse_and_map(node, 0);
120
121 /* Setup IO addresses */
122 timers.tmr_regs = of_iomap(node, 0);
123
124 kona_timer_disable_and_clear(timers.tmr_regs);
125}
126
127static int kona_timer_set_next_event(unsigned long clc, 102static int kona_timer_set_next_event(unsigned long clc,
128 struct clock_event_device *unused) 103 struct clock_event_device *unused)
129{ 104{
@@ -198,7 +173,34 @@ static struct irqaction kona_timer_irq = {
198 173
199static void __init kona_timer_init(struct device_node *node) 174static void __init kona_timer_init(struct device_node *node)
200{ 175{
201 kona_timers_init(node); 176 u32 freq;
177 struct clk *external_clk;
178
179 if (!of_device_is_available(node)) {
180 pr_info("Kona Timer v1 marked as disabled in device tree\n");
181 return;
182 }
183
184 external_clk = of_clk_get_by_name(node, NULL);
185
186 if (!IS_ERR(external_clk)) {
187 arch_timer_rate = clk_get_rate(external_clk);
188 clk_prepare_enable(external_clk);
189 } else if (!of_property_read_u32(node, "clock-frequency", &freq)) {
190 arch_timer_rate = freq;
191 } else {
192 pr_err("Kona Timer v1 unable to determine clock-frequency");
193 return;
194 }
195
196 /* Setup IRQ numbers */
197 timers.tmr_irq = irq_of_parse_and_map(node, 0);
198
199 /* Setup IO addresses */
200 timers.tmr_regs = of_iomap(node, 0);
201
202 kona_timer_disable_and_clear(timers.tmr_regs);
203
202 kona_timer_clockevents_init(); 204 kona_timer_clockevents_init();
203 setup_irq(timers.tmr_irq, &kona_timer_irq); 205 setup_irq(timers.tmr_irq, &kona_timer_irq);
204 kona_timer_set_next_event((arch_timer_rate / HZ), NULL); 206 kona_timer_set_next_event((arch_timer_rate / HZ), NULL);
diff --git a/drivers/clocksource/vf_pit_timer.c b/drivers/clocksource/vf_pit_timer.c
index 02821b06a39e..a918bc481c52 100644
--- a/drivers/clocksource/vf_pit_timer.c
+++ b/drivers/clocksource/vf_pit_timer.c
@@ -54,7 +54,7 @@ static inline void pit_irq_acknowledge(void)
54 54
55static u64 pit_read_sched_clock(void) 55static u64 pit_read_sched_clock(void)
56{ 56{
57 return __raw_readl(clksrc_base + PITCVAL); 57 return ~__raw_readl(clksrc_base + PITCVAL);
58} 58}
59 59
60static int __init pit_clocksource_init(unsigned long rate) 60static int __init pit_clocksource_init(unsigned long rate)
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig
index 4b029c0944af..1fbe11f2a146 100644
--- a/drivers/cpufreq/Kconfig
+++ b/drivers/cpufreq/Kconfig
@@ -200,7 +200,7 @@ source "drivers/cpufreq/Kconfig.x86"
200endmenu 200endmenu
201 201
202menu "ARM CPU frequency scaling drivers" 202menu "ARM CPU frequency scaling drivers"
203depends on ARM 203depends on ARM || ARM64
204source "drivers/cpufreq/Kconfig.arm" 204source "drivers/cpufreq/Kconfig.arm"
205endmenu 205endmenu
206 206
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 08ca8c9f41cd..199b52b7c3e1 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1109,12 +1109,27 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1109 goto err_set_policy_cpu; 1109 goto err_set_policy_cpu;
1110 } 1110 }
1111 1111
1112 /* related cpus should atleast have policy->cpus */
1113 cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);
1114
1115 /*
1116 * affected cpus must always be the one, which are online. We aren't
1117 * managing offline cpus here.
1118 */
1119 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1120
1121 if (!frozen) {
1122 policy->user_policy.min = policy->min;
1123 policy->user_policy.max = policy->max;
1124 }
1125
1126 down_write(&policy->rwsem);
1112 write_lock_irqsave(&cpufreq_driver_lock, flags); 1127 write_lock_irqsave(&cpufreq_driver_lock, flags);
1113 for_each_cpu(j, policy->cpus) 1128 for_each_cpu(j, policy->cpus)
1114 per_cpu(cpufreq_cpu_data, j) = policy; 1129 per_cpu(cpufreq_cpu_data, j) = policy;
1115 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1130 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1116 1131
1117 if (cpufreq_driver->get) { 1132 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
1118 policy->cur = cpufreq_driver->get(policy->cpu); 1133 policy->cur = cpufreq_driver->get(policy->cpu);
1119 if (!policy->cur) { 1134 if (!policy->cur) {
1120 pr_err("%s: ->get() failed\n", __func__); 1135 pr_err("%s: ->get() failed\n", __func__);
@@ -1162,20 +1177,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1162 } 1177 }
1163 } 1178 }
1164 1179
1165 /* related cpus should atleast have policy->cpus */
1166 cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);
1167
1168 /*
1169 * affected cpus must always be the one, which are online. We aren't
1170 * managing offline cpus here.
1171 */
1172 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1173
1174 if (!frozen) {
1175 policy->user_policy.min = policy->min;
1176 policy->user_policy.max = policy->max;
1177 }
1178
1179 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1180 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1180 CPUFREQ_START, policy); 1181 CPUFREQ_START, policy);
1181 1182
@@ -1206,6 +1207,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1206 policy->user_policy.policy = policy->policy; 1207 policy->user_policy.policy = policy->policy;
1207 policy->user_policy.governor = policy->governor; 1208 policy->user_policy.governor = policy->governor;
1208 } 1209 }
1210 up_write(&policy->rwsem);
1209 1211
1210 kobject_uevent(&policy->kobj, KOBJ_ADD); 1212 kobject_uevent(&policy->kobj, KOBJ_ADD);
1211 up_read(&cpufreq_rwsem); 1213 up_read(&cpufreq_rwsem);
@@ -1323,8 +1325,7 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1323 up_read(&policy->rwsem); 1325 up_read(&policy->rwsem);
1324 1326
1325 if (cpu != policy->cpu) { 1327 if (cpu != policy->cpu) {
1326 if (!frozen) 1328 sysfs_remove_link(&dev->kobj, "cpufreq");
1327 sysfs_remove_link(&dev->kobj, "cpufreq");
1328 } else if (cpus > 1) { 1329 } else if (cpus > 1) {
1329 new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu); 1330 new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu);
1330 if (new_cpu >= 0) { 1331 if (new_cpu >= 0) {
@@ -1547,23 +1548,16 @@ static unsigned int __cpufreq_get(unsigned int cpu)
1547 */ 1548 */
1548unsigned int cpufreq_get(unsigned int cpu) 1549unsigned int cpufreq_get(unsigned int cpu)
1549{ 1550{
1550 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); 1551 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1551 unsigned int ret_freq = 0; 1552 unsigned int ret_freq = 0;
1552 1553
1553 if (cpufreq_disabled() || !cpufreq_driver) 1554 if (policy) {
1554 return -ENOENT; 1555 down_read(&policy->rwsem);
1555 1556 ret_freq = __cpufreq_get(cpu);
1556 BUG_ON(!policy); 1557 up_read(&policy->rwsem);
1557
1558 if (!down_read_trylock(&cpufreq_rwsem))
1559 return 0;
1560
1561 down_read(&policy->rwsem);
1562
1563 ret_freq = __cpufreq_get(cpu);
1564 1558
1565 up_read(&policy->rwsem); 1559 cpufreq_cpu_put(policy);
1566 up_read(&cpufreq_rwsem); 1560 }
1567 1561
1568 return ret_freq; 1562 return ret_freq;
1569} 1563}
@@ -2149,7 +2143,7 @@ int cpufreq_update_policy(unsigned int cpu)
2149 * BIOS might change freq behind our back 2143 * BIOS might change freq behind our back
2150 * -> ask driver for current freq and notify governors about a change 2144 * -> ask driver for current freq and notify governors about a change
2151 */ 2145 */
2152 if (cpufreq_driver->get) { 2146 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
2153 new_policy.cur = cpufreq_driver->get(cpu); 2147 new_policy.cur = cpufreq_driver->get(cpu);
2154 if (!policy->cur) { 2148 if (!policy->cur) {
2155 pr_debug("Driver did not initialize current freq"); 2149 pr_debug("Driver did not initialize current freq");
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 7e257b233602..2cd36b9297f3 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -34,12 +34,15 @@
34 34
35#define SAMPLE_COUNT 3 35#define SAMPLE_COUNT 3
36 36
37#define BYT_RATIOS 0x66a 37#define BYT_RATIOS 0x66a
38#define BYT_VIDS 0x66b 38#define BYT_VIDS 0x66b
39#define BYT_TURBO_RATIOS 0x66c
39 40
40#define FRAC_BITS 8 41
42#define FRAC_BITS 6
41#define int_tofp(X) ((int64_t)(X) << FRAC_BITS) 43#define int_tofp(X) ((int64_t)(X) << FRAC_BITS)
42#define fp_toint(X) ((X) >> FRAC_BITS) 44#define fp_toint(X) ((X) >> FRAC_BITS)
45#define FP_ROUNDUP(X) ((X) += 1 << FRAC_BITS)
43 46
44static inline int32_t mul_fp(int32_t x, int32_t y) 47static inline int32_t mul_fp(int32_t x, int32_t y)
45{ 48{
@@ -51,12 +54,11 @@ static inline int32_t div_fp(int32_t x, int32_t y)
51 return div_s64((int64_t)x << FRAC_BITS, (int64_t)y); 54 return div_s64((int64_t)x << FRAC_BITS, (int64_t)y);
52} 55}
53 56
54static u64 energy_divisor;
55
56struct sample { 57struct sample {
57 int32_t core_pct_busy; 58 int32_t core_pct_busy;
58 u64 aperf; 59 u64 aperf;
59 u64 mperf; 60 u64 mperf;
61 unsigned long long tsc;
60 int freq; 62 int freq;
61}; 63};
62 64
@@ -96,6 +98,7 @@ struct cpudata {
96 98
97 u64 prev_aperf; 99 u64 prev_aperf;
98 u64 prev_mperf; 100 u64 prev_mperf;
101 unsigned long long prev_tsc;
99 int sample_ptr; 102 int sample_ptr;
100 struct sample samples[SAMPLE_COUNT]; 103 struct sample samples[SAMPLE_COUNT];
101}; 104};
@@ -357,7 +360,7 @@ static int byt_get_min_pstate(void)
357{ 360{
358 u64 value; 361 u64 value;
359 rdmsrl(BYT_RATIOS, value); 362 rdmsrl(BYT_RATIOS, value);
360 return value & 0xFF; 363 return (value >> 8) & 0xFF;
361} 364}
362 365
363static int byt_get_max_pstate(void) 366static int byt_get_max_pstate(void)
@@ -367,6 +370,13 @@ static int byt_get_max_pstate(void)
367 return (value >> 16) & 0xFF; 370 return (value >> 16) & 0xFF;
368} 371}
369 372
373static int byt_get_turbo_pstate(void)
374{
375 u64 value;
376 rdmsrl(BYT_TURBO_RATIOS, value);
377 return value & 0x3F;
378}
379
370static void byt_set_pstate(struct cpudata *cpudata, int pstate) 380static void byt_set_pstate(struct cpudata *cpudata, int pstate)
371{ 381{
372 u64 val; 382 u64 val;
@@ -469,7 +479,7 @@ static struct cpu_defaults byt_params = {
469 .funcs = { 479 .funcs = {
470 .get_max = byt_get_max_pstate, 480 .get_max = byt_get_max_pstate,
471 .get_min = byt_get_min_pstate, 481 .get_min = byt_get_min_pstate,
472 .get_turbo = byt_get_max_pstate, 482 .get_turbo = byt_get_turbo_pstate,
473 .set = byt_set_pstate, 483 .set = byt_set_pstate,
474 .get_vid = byt_get_vid, 484 .get_vid = byt_get_vid,
475 }, 485 },
@@ -547,31 +557,48 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
547static inline void intel_pstate_calc_busy(struct cpudata *cpu, 557static inline void intel_pstate_calc_busy(struct cpudata *cpu,
548 struct sample *sample) 558 struct sample *sample)
549{ 559{
550 u64 core_pct; 560 int32_t core_pct;
551 core_pct = div64_u64(int_tofp(sample->aperf * 100), 561 int32_t c0_pct;
552 sample->mperf); 562
553 sample->freq = fp_toint(cpu->pstate.max_pstate * core_pct * 1000); 563 core_pct = div_fp(int_tofp((sample->aperf)),
564 int_tofp((sample->mperf)));
565 core_pct = mul_fp(core_pct, int_tofp(100));
566 FP_ROUNDUP(core_pct);
567
568 c0_pct = div_fp(int_tofp(sample->mperf), int_tofp(sample->tsc));
554 569
555 sample->core_pct_busy = core_pct; 570 sample->freq = fp_toint(
571 mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct));
572
573 sample->core_pct_busy = mul_fp(core_pct, c0_pct);
556} 574}
557 575
558static inline void intel_pstate_sample(struct cpudata *cpu) 576static inline void intel_pstate_sample(struct cpudata *cpu)
559{ 577{
560 u64 aperf, mperf; 578 u64 aperf, mperf;
579 unsigned long long tsc;
561 580
562 rdmsrl(MSR_IA32_APERF, aperf); 581 rdmsrl(MSR_IA32_APERF, aperf);
563 rdmsrl(MSR_IA32_MPERF, mperf); 582 rdmsrl(MSR_IA32_MPERF, mperf);
583 tsc = native_read_tsc();
584
585 aperf = aperf >> FRAC_BITS;
586 mperf = mperf >> FRAC_BITS;
587 tsc = tsc >> FRAC_BITS;
564 588
565 cpu->sample_ptr = (cpu->sample_ptr + 1) % SAMPLE_COUNT; 589 cpu->sample_ptr = (cpu->sample_ptr + 1) % SAMPLE_COUNT;
566 cpu->samples[cpu->sample_ptr].aperf = aperf; 590 cpu->samples[cpu->sample_ptr].aperf = aperf;
567 cpu->samples[cpu->sample_ptr].mperf = mperf; 591 cpu->samples[cpu->sample_ptr].mperf = mperf;
592 cpu->samples[cpu->sample_ptr].tsc = tsc;
568 cpu->samples[cpu->sample_ptr].aperf -= cpu->prev_aperf; 593 cpu->samples[cpu->sample_ptr].aperf -= cpu->prev_aperf;
569 cpu->samples[cpu->sample_ptr].mperf -= cpu->prev_mperf; 594 cpu->samples[cpu->sample_ptr].mperf -= cpu->prev_mperf;
595 cpu->samples[cpu->sample_ptr].tsc -= cpu->prev_tsc;
570 596
571 intel_pstate_calc_busy(cpu, &cpu->samples[cpu->sample_ptr]); 597 intel_pstate_calc_busy(cpu, &cpu->samples[cpu->sample_ptr]);
572 598
573 cpu->prev_aperf = aperf; 599 cpu->prev_aperf = aperf;
574 cpu->prev_mperf = mperf; 600 cpu->prev_mperf = mperf;
601 cpu->prev_tsc = tsc;
575} 602}
576 603
577static inline void intel_pstate_set_sample_time(struct cpudata *cpu) 604static inline void intel_pstate_set_sample_time(struct cpudata *cpu)
@@ -590,7 +617,8 @@ static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu)
590 core_busy = cpu->samples[cpu->sample_ptr].core_pct_busy; 617 core_busy = cpu->samples[cpu->sample_ptr].core_pct_busy;
591 max_pstate = int_tofp(cpu->pstate.max_pstate); 618 max_pstate = int_tofp(cpu->pstate.max_pstate);
592 current_pstate = int_tofp(cpu->pstate.current_pstate); 619 current_pstate = int_tofp(cpu->pstate.current_pstate);
593 return mul_fp(core_busy, div_fp(max_pstate, current_pstate)); 620 core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate));
621 return FP_ROUNDUP(core_busy);
594} 622}
595 623
596static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu) 624static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
@@ -617,12 +645,10 @@ static void intel_pstate_timer_func(unsigned long __data)
617{ 645{
618 struct cpudata *cpu = (struct cpudata *) __data; 646 struct cpudata *cpu = (struct cpudata *) __data;
619 struct sample *sample; 647 struct sample *sample;
620 u64 energy;
621 648
622 intel_pstate_sample(cpu); 649 intel_pstate_sample(cpu);
623 650
624 sample = &cpu->samples[cpu->sample_ptr]; 651 sample = &cpu->samples[cpu->sample_ptr];
625 rdmsrl(MSR_PKG_ENERGY_STATUS, energy);
626 652
627 intel_pstate_adjust_busy_pstate(cpu); 653 intel_pstate_adjust_busy_pstate(cpu);
628 654
@@ -631,7 +657,6 @@ static void intel_pstate_timer_func(unsigned long __data)
631 cpu->pstate.current_pstate, 657 cpu->pstate.current_pstate,
632 sample->mperf, 658 sample->mperf,
633 sample->aperf, 659 sample->aperf,
634 div64_u64(energy, energy_divisor),
635 sample->freq); 660 sample->freq);
636 661
637 intel_pstate_set_sample_time(cpu); 662 intel_pstate_set_sample_time(cpu);
@@ -913,7 +938,6 @@ static int __init intel_pstate_init(void)
913 int cpu, rc = 0; 938 int cpu, rc = 0;
914 const struct x86_cpu_id *id; 939 const struct x86_cpu_id *id;
915 struct cpu_defaults *cpu_info; 940 struct cpu_defaults *cpu_info;
916 u64 units;
917 941
918 if (no_load) 942 if (no_load)
919 return -ENODEV; 943 return -ENODEV;
@@ -947,9 +971,6 @@ static int __init intel_pstate_init(void)
947 if (rc) 971 if (rc)
948 goto out; 972 goto out;
949 973
950 rdmsrl(MSR_RAPL_POWER_UNIT, units);
951 energy_divisor = 1 << ((units >> 8) & 0x1f); /* bits{12:8} */
952
953 intel_pstate_debug_expose_params(); 974 intel_pstate_debug_expose_params();
954 intel_pstate_sysfs_expose_params(); 975 intel_pstate_sysfs_expose_params();
955 976
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index e10b646634d7..6684e0342792 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -1076,7 +1076,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1076{ 1076{
1077 struct powernow_k8_data *data; 1077 struct powernow_k8_data *data;
1078 struct init_on_cpu init_on_cpu; 1078 struct init_on_cpu init_on_cpu;
1079 int rc; 1079 int rc, cpu;
1080 1080
1081 smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1); 1081 smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1);
1082 if (rc) 1082 if (rc)
@@ -1140,7 +1140,9 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1140 pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n", 1140 pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n",
1141 data->currfid, data->currvid); 1141 data->currfid, data->currvid);
1142 1142
1143 per_cpu(powernow_data, pol->cpu) = data; 1143 /* Point all the CPUs in this policy to the same data */
1144 for_each_cpu(cpu, pol->cpus)
1145 per_cpu(powernow_data, cpu) = data;
1144 1146
1145 return 0; 1147 return 0;
1146 1148
@@ -1155,6 +1157,7 @@ err_out:
1155static int powernowk8_cpu_exit(struct cpufreq_policy *pol) 1157static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
1156{ 1158{
1157 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); 1159 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
1160 int cpu;
1158 1161
1159 if (!data) 1162 if (!data)
1160 return -EINVAL; 1163 return -EINVAL;
@@ -1165,7 +1168,8 @@ static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
1165 1168
1166 kfree(data->powernow_table); 1169 kfree(data->powernow_table);
1167 kfree(data); 1170 kfree(data);
1168 per_cpu(powernow_data, pol->cpu) = NULL; 1171 for_each_cpu(cpu, pol->cpus)
1172 per_cpu(powernow_data, cpu) = NULL;
1169 1173
1170 return 0; 1174 return 0;
1171} 1175}
diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
index 78fd174c57e8..f48607cd2540 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -14,6 +14,7 @@
14 14
15#include <asm/machdep.h> 15#include <asm/machdep.h>
16#include <asm/firmware.h> 16#include <asm/firmware.h>
17#include <asm/runlatch.h>
17 18
18struct cpuidle_driver powernv_idle_driver = { 19struct cpuidle_driver powernv_idle_driver = {
19 .name = "powernv_idle", 20 .name = "powernv_idle",
@@ -30,12 +31,14 @@ static int snooze_loop(struct cpuidle_device *dev,
30 local_irq_enable(); 31 local_irq_enable();
31 set_thread_flag(TIF_POLLING_NRFLAG); 32 set_thread_flag(TIF_POLLING_NRFLAG);
32 33
34 ppc64_runlatch_off();
33 while (!need_resched()) { 35 while (!need_resched()) {
34 HMT_low(); 36 HMT_low();
35 HMT_very_low(); 37 HMT_very_low();
36 } 38 }
37 39
38 HMT_medium(); 40 HMT_medium();
41 ppc64_runlatch_on();
39 clear_thread_flag(TIF_POLLING_NRFLAG); 42 clear_thread_flag(TIF_POLLING_NRFLAG);
40 smp_mb(); 43 smp_mb();
41 return index; 44 return index;
@@ -45,7 +48,9 @@ static int nap_loop(struct cpuidle_device *dev,
45 struct cpuidle_driver *drv, 48 struct cpuidle_driver *drv,
46 int index) 49 int index)
47{ 50{
51 ppc64_runlatch_off();
48 power7_idle(); 52 power7_idle();
53 ppc64_runlatch_on();
49 return index; 54 return index;
50} 55}
51 56
diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
index 7ab564aa0b1c..6f7b01956885 100644
--- a/drivers/cpuidle/cpuidle-pseries.c
+++ b/drivers/cpuidle/cpuidle-pseries.c
@@ -17,6 +17,7 @@
17#include <asm/reg.h> 17#include <asm/reg.h>
18#include <asm/machdep.h> 18#include <asm/machdep.h>
19#include <asm/firmware.h> 19#include <asm/firmware.h>
20#include <asm/runlatch.h>
20#include <asm/plpar_wrappers.h> 21#include <asm/plpar_wrappers.h>
21 22
22struct cpuidle_driver pseries_idle_driver = { 23struct cpuidle_driver pseries_idle_driver = {
@@ -29,6 +30,7 @@ static struct cpuidle_state *cpuidle_state_table;
29 30
30static inline void idle_loop_prolog(unsigned long *in_purr) 31static inline void idle_loop_prolog(unsigned long *in_purr)
31{ 32{
33 ppc64_runlatch_off();
32 *in_purr = mfspr(SPRN_PURR); 34 *in_purr = mfspr(SPRN_PURR);
33 /* 35 /*
34 * Indicate to the HV that we are idle. Now would be 36 * Indicate to the HV that we are idle. Now would be
@@ -45,6 +47,10 @@ static inline void idle_loop_epilog(unsigned long in_purr)
45 wait_cycles += mfspr(SPRN_PURR) - in_purr; 47 wait_cycles += mfspr(SPRN_PURR) - in_purr;
46 get_lppaca()->wait_state_cycles = cpu_to_be64(wait_cycles); 48 get_lppaca()->wait_state_cycles = cpu_to_be64(wait_cycles);
47 get_lppaca()->idle = 0; 49 get_lppaca()->idle = 0;
50
51 if (irqs_disabled())
52 local_irq_enable();
53 ppc64_runlatch_on();
48} 54}
49 55
50static int snooze_loop(struct cpuidle_device *dev, 56static int snooze_loop(struct cpuidle_device *dev,
diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index 6c4c000671c5..1e5481d88a26 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -158,6 +158,15 @@ static inline unsigned long nx842_get_scatterlist_size(
158 return sl->entry_nr * sizeof(struct nx842_slentry); 158 return sl->entry_nr * sizeof(struct nx842_slentry);
159} 159}
160 160
161static inline unsigned long nx842_get_pa(void *addr)
162{
163 if (is_vmalloc_addr(addr))
164 return page_to_phys(vmalloc_to_page(addr))
165 + offset_in_page(addr);
166 else
167 return __pa(addr);
168}
169
161static int nx842_build_scatterlist(unsigned long buf, int len, 170static int nx842_build_scatterlist(unsigned long buf, int len,
162 struct nx842_scatterlist *sl) 171 struct nx842_scatterlist *sl)
163{ 172{
@@ -168,7 +177,7 @@ static int nx842_build_scatterlist(unsigned long buf, int len,
168 177
169 entry = sl->entries; 178 entry = sl->entries;
170 while (len) { 179 while (len) {
171 entry->ptr = __pa(buf); 180 entry->ptr = nx842_get_pa((void *)buf);
172 nextpage = ALIGN(buf + 1, NX842_HW_PAGE_SIZE); 181 nextpage = ALIGN(buf + 1, NX842_HW_PAGE_SIZE);
173 if (nextpage < buf + len) { 182 if (nextpage < buf + len) {
174 /* we aren't at the end yet */ 183 /* we aren't at the end yet */
@@ -370,8 +379,8 @@ int nx842_compress(const unsigned char *in, unsigned int inlen,
370 op.flags = NX842_OP_COMPRESS; 379 op.flags = NX842_OP_COMPRESS;
371 csbcpb = &workmem->csbcpb; 380 csbcpb = &workmem->csbcpb;
372 memset(csbcpb, 0, sizeof(*csbcpb)); 381 memset(csbcpb, 0, sizeof(*csbcpb));
373 op.csbcpb = __pa(csbcpb); 382 op.csbcpb = nx842_get_pa(csbcpb);
374 op.out = __pa(slout.entries); 383 op.out = nx842_get_pa(slout.entries);
375 384
376 for (i = 0; i < hdr->blocks_nr; i++) { 385 for (i = 0; i < hdr->blocks_nr; i++) {
377 /* 386 /*
@@ -401,13 +410,13 @@ int nx842_compress(const unsigned char *in, unsigned int inlen,
401 */ 410 */
402 if (likely(max_sync_size == NX842_HW_PAGE_SIZE)) { 411 if (likely(max_sync_size == NX842_HW_PAGE_SIZE)) {
403 /* Create direct DDE */ 412 /* Create direct DDE */
404 op.in = __pa(inbuf); 413 op.in = nx842_get_pa((void *)inbuf);
405 op.inlen = max_sync_size; 414 op.inlen = max_sync_size;
406 415
407 } else { 416 } else {
408 /* Create indirect DDE (scatterlist) */ 417 /* Create indirect DDE (scatterlist) */
409 nx842_build_scatterlist(inbuf, max_sync_size, &slin); 418 nx842_build_scatterlist(inbuf, max_sync_size, &slin);
410 op.in = __pa(slin.entries); 419 op.in = nx842_get_pa(slin.entries);
411 op.inlen = -nx842_get_scatterlist_size(&slin); 420 op.inlen = -nx842_get_scatterlist_size(&slin);
412 } 421 }
413 422
@@ -565,7 +574,7 @@ int nx842_decompress(const unsigned char *in, unsigned int inlen,
565 op.flags = NX842_OP_DECOMPRESS; 574 op.flags = NX842_OP_DECOMPRESS;
566 csbcpb = &workmem->csbcpb; 575 csbcpb = &workmem->csbcpb;
567 memset(csbcpb, 0, sizeof(*csbcpb)); 576 memset(csbcpb, 0, sizeof(*csbcpb));
568 op.csbcpb = __pa(csbcpb); 577 op.csbcpb = nx842_get_pa(csbcpb);
569 578
570 /* 579 /*
571 * max_sync_size may have changed since compression, 580 * max_sync_size may have changed since compression,
@@ -597,12 +606,12 @@ int nx842_decompress(const unsigned char *in, unsigned int inlen,
597 if (likely((inbuf & NX842_HW_PAGE_MASK) == 606 if (likely((inbuf & NX842_HW_PAGE_MASK) ==
598 ((inbuf + hdr->sizes[i] - 1) & NX842_HW_PAGE_MASK))) { 607 ((inbuf + hdr->sizes[i] - 1) & NX842_HW_PAGE_MASK))) {
599 /* Create direct DDE */ 608 /* Create direct DDE */
600 op.in = __pa(inbuf); 609 op.in = nx842_get_pa((void *)inbuf);
601 op.inlen = hdr->sizes[i]; 610 op.inlen = hdr->sizes[i];
602 } else { 611 } else {
603 /* Create indirect DDE (scatterlist) */ 612 /* Create indirect DDE (scatterlist) */
604 nx842_build_scatterlist(inbuf, hdr->sizes[i] , &slin); 613 nx842_build_scatterlist(inbuf, hdr->sizes[i] , &slin);
605 op.in = __pa(slin.entries); 614 op.in = nx842_get_pa(slin.entries);
606 op.inlen = -nx842_get_scatterlist_size(&slin); 615 op.inlen = -nx842_get_scatterlist_size(&slin);
607 } 616 }
608 617
@@ -613,12 +622,12 @@ int nx842_decompress(const unsigned char *in, unsigned int inlen,
613 */ 622 */
614 if (likely(max_sync_size == NX842_HW_PAGE_SIZE)) { 623 if (likely(max_sync_size == NX842_HW_PAGE_SIZE)) {
615 /* Create direct DDE */ 624 /* Create direct DDE */
616 op.out = __pa(outbuf); 625 op.out = nx842_get_pa((void *)outbuf);
617 op.outlen = max_sync_size; 626 op.outlen = max_sync_size;
618 } else { 627 } else {
619 /* Create indirect DDE (scatterlist) */ 628 /* Create indirect DDE (scatterlist) */
620 nx842_build_scatterlist(outbuf, max_sync_size, &slout); 629 nx842_build_scatterlist(outbuf, max_sync_size, &slout);
621 op.out = __pa(slout.entries); 630 op.out = nx842_get_pa(slout.entries);
622 op.outlen = -nx842_get_scatterlist_size(&slout); 631 op.outlen = -nx842_get_scatterlist_size(&slout);
623 } 632 }
624 633
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index 9bed1a2a67a1..605b016bcea4 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -346,6 +346,7 @@ config MOXART_DMA
346 tristate "MOXART DMA support" 346 tristate "MOXART DMA support"
347 depends on ARCH_MOXART 347 depends on ARCH_MOXART
348 select DMA_ENGINE 348 select DMA_ENGINE
349 select DMA_OF
349 select DMA_VIRTUAL_CHANNELS 350 select DMA_VIRTUAL_CHANNELS
350 help 351 help
351 Enable support for the MOXA ART SoC DMA controller. 352 Enable support for the MOXA ART SoC DMA controller.
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 4e7918339b12..19041cefabb1 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -449,6 +449,7 @@ static const struct of_device_id sdma_dt_ids[] = {
449 { .compatible = "fsl,imx51-sdma", .data = &sdma_imx51, }, 449 { .compatible = "fsl,imx51-sdma", .data = &sdma_imx51, },
450 { .compatible = "fsl,imx35-sdma", .data = &sdma_imx35, }, 450 { .compatible = "fsl,imx35-sdma", .data = &sdma_imx35, },
451 { .compatible = "fsl,imx31-sdma", .data = &sdma_imx31, }, 451 { .compatible = "fsl,imx31-sdma", .data = &sdma_imx31, },
452 { .compatible = "fsl,imx25-sdma", .data = &sdma_imx25, },
452 { /* sentinel */ } 453 { /* sentinel */ }
453}; 454};
454MODULE_DEVICE_TABLE(of, sdma_dt_ids); 455MODULE_DEVICE_TABLE(of, sdma_dt_ids);
diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
index 87529181efcc..4e3549a16132 100644
--- a/drivers/dma/ioat/dma.c
+++ b/drivers/dma/ioat/dma.c
@@ -77,7 +77,8 @@ static irqreturn_t ioat_dma_do_interrupt(int irq, void *data)
77 attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET); 77 attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET);
78 for_each_set_bit(bit, &attnstatus, BITS_PER_LONG) { 78 for_each_set_bit(bit, &attnstatus, BITS_PER_LONG) {
79 chan = ioat_chan_by_index(instance, bit); 79 chan = ioat_chan_by_index(instance, bit);
80 tasklet_schedule(&chan->cleanup_task); 80 if (test_bit(IOAT_RUN, &chan->state))
81 tasklet_schedule(&chan->cleanup_task);
81 } 82 }
82 83
83 writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET); 84 writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
@@ -93,7 +94,8 @@ static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)
93{ 94{
94 struct ioat_chan_common *chan = data; 95 struct ioat_chan_common *chan = data;
95 96
96 tasklet_schedule(&chan->cleanup_task); 97 if (test_bit(IOAT_RUN, &chan->state))
98 tasklet_schedule(&chan->cleanup_task);
97 99
98 return IRQ_HANDLED; 100 return IRQ_HANDLED;
99} 101}
@@ -116,7 +118,6 @@ void ioat_init_channel(struct ioatdma_device *device, struct ioat_chan_common *c
116 chan->timer.function = device->timer_fn; 118 chan->timer.function = device->timer_fn;
117 chan->timer.data = data; 119 chan->timer.data = data;
118 tasklet_init(&chan->cleanup_task, device->cleanup_fn, data); 120 tasklet_init(&chan->cleanup_task, device->cleanup_fn, data);
119 tasklet_disable(&chan->cleanup_task);
120} 121}
121 122
122/** 123/**
@@ -354,13 +355,49 @@ static int ioat1_dma_alloc_chan_resources(struct dma_chan *c)
354 writel(((u64) chan->completion_dma) >> 32, 355 writel(((u64) chan->completion_dma) >> 32,
355 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH); 356 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
356 357
357 tasklet_enable(&chan->cleanup_task); 358 set_bit(IOAT_RUN, &chan->state);
358 ioat1_dma_start_null_desc(ioat); /* give chain to dma device */ 359 ioat1_dma_start_null_desc(ioat); /* give chain to dma device */
359 dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n", 360 dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n",
360 __func__, ioat->desccount); 361 __func__, ioat->desccount);
361 return ioat->desccount; 362 return ioat->desccount;
362} 363}
363 364
365void ioat_stop(struct ioat_chan_common *chan)
366{
367 struct ioatdma_device *device = chan->device;
368 struct pci_dev *pdev = device->pdev;
369 int chan_id = chan_num(chan);
370 struct msix_entry *msix;
371
372 /* 1/ stop irq from firing tasklets
373 * 2/ stop the tasklet from re-arming irqs
374 */
375 clear_bit(IOAT_RUN, &chan->state);
376
377 /* flush inflight interrupts */
378 switch (device->irq_mode) {
379 case IOAT_MSIX:
380 msix = &device->msix_entries[chan_id];
381 synchronize_irq(msix->vector);
382 break;
383 case IOAT_MSI:
384 case IOAT_INTX:
385 synchronize_irq(pdev->irq);
386 break;
387 default:
388 break;
389 }
390
391 /* flush inflight timers */
392 del_timer_sync(&chan->timer);
393
394 /* flush inflight tasklet runs */
395 tasklet_kill(&chan->cleanup_task);
396
397 /* final cleanup now that everything is quiesced and can't re-arm */
398 device->cleanup_fn((unsigned long) &chan->common);
399}
400
364/** 401/**
365 * ioat1_dma_free_chan_resources - release all the descriptors 402 * ioat1_dma_free_chan_resources - release all the descriptors
366 * @chan: the channel to be cleaned 403 * @chan: the channel to be cleaned
@@ -379,9 +416,7 @@ static void ioat1_dma_free_chan_resources(struct dma_chan *c)
379 if (ioat->desccount == 0) 416 if (ioat->desccount == 0)
380 return; 417 return;
381 418
382 tasklet_disable(&chan->cleanup_task); 419 ioat_stop(chan);
383 del_timer_sync(&chan->timer);
384 ioat1_cleanup(ioat);
385 420
386 /* Delay 100ms after reset to allow internal DMA logic to quiesce 421 /* Delay 100ms after reset to allow internal DMA logic to quiesce
387 * before removing DMA descriptor resources. 422 * before removing DMA descriptor resources.
@@ -526,8 +561,11 @@ ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
526static void ioat1_cleanup_event(unsigned long data) 561static void ioat1_cleanup_event(unsigned long data)
527{ 562{
528 struct ioat_dma_chan *ioat = to_ioat_chan((void *) data); 563 struct ioat_dma_chan *ioat = to_ioat_chan((void *) data);
564 struct ioat_chan_common *chan = &ioat->base;
529 565
530 ioat1_cleanup(ioat); 566 ioat1_cleanup(ioat);
567 if (!test_bit(IOAT_RUN, &chan->state))
568 return;
531 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET); 569 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
532} 570}
533 571
diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
index 11fb877ddca9..e982f00a9843 100644
--- a/drivers/dma/ioat/dma.h
+++ b/drivers/dma/ioat/dma.h
@@ -356,6 +356,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
356void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type); 356void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
357void ioat_kobject_del(struct ioatdma_device *device); 357void ioat_kobject_del(struct ioatdma_device *device);
358int ioat_dma_setup_interrupts(struct ioatdma_device *device); 358int ioat_dma_setup_interrupts(struct ioatdma_device *device);
359void ioat_stop(struct ioat_chan_common *chan);
359extern const struct sysfs_ops ioat_sysfs_ops; 360extern const struct sysfs_ops ioat_sysfs_ops;
360extern struct ioat_sysfs_entry ioat_version_attr; 361extern struct ioat_sysfs_entry ioat_version_attr;
361extern struct ioat_sysfs_entry ioat_cap_attr; 362extern struct ioat_sysfs_entry ioat_cap_attr;
diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index 5d3affe7e976..8d1058085eeb 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -190,8 +190,11 @@ static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
190void ioat2_cleanup_event(unsigned long data) 190void ioat2_cleanup_event(unsigned long data)
191{ 191{
192 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data); 192 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
193 struct ioat_chan_common *chan = &ioat->base;
193 194
194 ioat2_cleanup(ioat); 195 ioat2_cleanup(ioat);
196 if (!test_bit(IOAT_RUN, &chan->state))
197 return;
195 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET); 198 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
196} 199}
197 200
@@ -553,10 +556,10 @@ int ioat2_alloc_chan_resources(struct dma_chan *c)
553 ioat->issued = 0; 556 ioat->issued = 0;
554 ioat->tail = 0; 557 ioat->tail = 0;
555 ioat->alloc_order = order; 558 ioat->alloc_order = order;
559 set_bit(IOAT_RUN, &chan->state);
556 spin_unlock_bh(&ioat->prep_lock); 560 spin_unlock_bh(&ioat->prep_lock);
557 spin_unlock_bh(&chan->cleanup_lock); 561 spin_unlock_bh(&chan->cleanup_lock);
558 562
559 tasklet_enable(&chan->cleanup_task);
560 ioat2_start_null_desc(ioat); 563 ioat2_start_null_desc(ioat);
561 564
562 /* check that we got off the ground */ 565 /* check that we got off the ground */
@@ -566,7 +569,6 @@ int ioat2_alloc_chan_resources(struct dma_chan *c)
566 } while (i++ < 20 && !is_ioat_active(status) && !is_ioat_idle(status)); 569 } while (i++ < 20 && !is_ioat_active(status) && !is_ioat_idle(status));
567 570
568 if (is_ioat_active(status) || is_ioat_idle(status)) { 571 if (is_ioat_active(status) || is_ioat_idle(status)) {
569 set_bit(IOAT_RUN, &chan->state);
570 return 1 << ioat->alloc_order; 572 return 1 << ioat->alloc_order;
571 } else { 573 } else {
572 u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); 574 u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
@@ -809,11 +811,8 @@ void ioat2_free_chan_resources(struct dma_chan *c)
809 if (!ioat->ring) 811 if (!ioat->ring)
810 return; 812 return;
811 813
812 tasklet_disable(&chan->cleanup_task); 814 ioat_stop(chan);
813 del_timer_sync(&chan->timer);
814 device->cleanup_fn((unsigned long) c);
815 device->reset_hw(chan); 815 device->reset_hw(chan);
816 clear_bit(IOAT_RUN, &chan->state);
817 816
818 spin_lock_bh(&chan->cleanup_lock); 817 spin_lock_bh(&chan->cleanup_lock);
819 spin_lock_bh(&ioat->prep_lock); 818 spin_lock_bh(&ioat->prep_lock);
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index 820817e97e62..b9b38a1cf92f 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -464,8 +464,11 @@ static void ioat3_cleanup(struct ioat2_dma_chan *ioat)
464static void ioat3_cleanup_event(unsigned long data) 464static void ioat3_cleanup_event(unsigned long data)
465{ 465{
466 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data); 466 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
467 struct ioat_chan_common *chan = &ioat->base;
467 468
468 ioat3_cleanup(ioat); 469 ioat3_cleanup(ioat);
470 if (!test_bit(IOAT_RUN, &chan->state))
471 return;
469 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET); 472 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
470} 473}
471 474
diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 53fb0c8365b0..766b68ed505c 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -497,8 +497,8 @@ mv_xor_tx_submit(struct dma_async_tx_descriptor *tx)
497 if (!mv_can_chain(grp_start)) 497 if (!mv_can_chain(grp_start))
498 goto submit_done; 498 goto submit_done;
499 499
500 dev_dbg(mv_chan_to_devp(mv_chan), "Append to last desc %x\n", 500 dev_dbg(mv_chan_to_devp(mv_chan), "Append to last desc %pa\n",
501 old_chain_tail->async_tx.phys); 501 &old_chain_tail->async_tx.phys);
502 502
503 /* fix up the hardware chain */ 503 /* fix up the hardware chain */
504 mv_desc_set_next_desc(old_chain_tail, grp_start->async_tx.phys); 504 mv_desc_set_next_desc(old_chain_tail, grp_start->async_tx.phys);
@@ -527,7 +527,8 @@ submit_done:
527/* returns the number of allocated descriptors */ 527/* returns the number of allocated descriptors */
528static int mv_xor_alloc_chan_resources(struct dma_chan *chan) 528static int mv_xor_alloc_chan_resources(struct dma_chan *chan)
529{ 529{
530 char *hw_desc; 530 void *virt_desc;
531 dma_addr_t dma_desc;
531 int idx; 532 int idx;
532 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan); 533 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
533 struct mv_xor_desc_slot *slot = NULL; 534 struct mv_xor_desc_slot *slot = NULL;
@@ -542,17 +543,16 @@ static int mv_xor_alloc_chan_resources(struct dma_chan *chan)
542 " %d descriptor slots", idx); 543 " %d descriptor slots", idx);
543 break; 544 break;
544 } 545 }
545 hw_desc = (char *) mv_chan->dma_desc_pool_virt; 546 virt_desc = mv_chan->dma_desc_pool_virt;
546 slot->hw_desc = (void *) &hw_desc[idx * MV_XOR_SLOT_SIZE]; 547 slot->hw_desc = virt_desc + idx * MV_XOR_SLOT_SIZE;
547 548
548 dma_async_tx_descriptor_init(&slot->async_tx, chan); 549 dma_async_tx_descriptor_init(&slot->async_tx, chan);
549 slot->async_tx.tx_submit = mv_xor_tx_submit; 550 slot->async_tx.tx_submit = mv_xor_tx_submit;
550 INIT_LIST_HEAD(&slot->chain_node); 551 INIT_LIST_HEAD(&slot->chain_node);
551 INIT_LIST_HEAD(&slot->slot_node); 552 INIT_LIST_HEAD(&slot->slot_node);
552 INIT_LIST_HEAD(&slot->tx_list); 553 INIT_LIST_HEAD(&slot->tx_list);
553 hw_desc = (char *) mv_chan->dma_desc_pool; 554 dma_desc = mv_chan->dma_desc_pool;
554 slot->async_tx.phys = 555 slot->async_tx.phys = dma_desc + idx * MV_XOR_SLOT_SIZE;
555 (dma_addr_t) &hw_desc[idx * MV_XOR_SLOT_SIZE];
556 slot->idx = idx++; 556 slot->idx = idx++;
557 557
558 spin_lock_bh(&mv_chan->lock); 558 spin_lock_bh(&mv_chan->lock);
@@ -582,8 +582,8 @@ mv_xor_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
582 int slot_cnt; 582 int slot_cnt;
583 583
584 dev_dbg(mv_chan_to_devp(mv_chan), 584 dev_dbg(mv_chan_to_devp(mv_chan),
585 "%s dest: %x src %x len: %u flags: %ld\n", 585 "%s dest: %pad src %pad len: %u flags: %ld\n",
586 __func__, dest, src, len, flags); 586 __func__, &dest, &src, len, flags);
587 if (unlikely(len < MV_XOR_MIN_BYTE_COUNT)) 587 if (unlikely(len < MV_XOR_MIN_BYTE_COUNT))
588 return NULL; 588 return NULL;
589 589
@@ -626,8 +626,8 @@ mv_xor_prep_dma_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
626 BUG_ON(len > MV_XOR_MAX_BYTE_COUNT); 626 BUG_ON(len > MV_XOR_MAX_BYTE_COUNT);
627 627
628 dev_dbg(mv_chan_to_devp(mv_chan), 628 dev_dbg(mv_chan_to_devp(mv_chan),
629 "%s src_cnt: %d len: dest %x %u flags: %ld\n", 629 "%s src_cnt: %d len: %u dest %pad flags: %ld\n",
630 __func__, src_cnt, len, dest, flags); 630 __func__, src_cnt, len, &dest, flags);
631 631
632 spin_lock_bh(&mv_chan->lock); 632 spin_lock_bh(&mv_chan->lock);
633 slot_cnt = mv_chan_xor_slot_count(len, src_cnt); 633 slot_cnt = mv_chan_xor_slot_count(len, src_cnt);
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index 00a2de957b23..bf18c786ed40 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -1641,6 +1641,7 @@ static void dma_tasklet(unsigned long data)
1641 struct d40_chan *d40c = (struct d40_chan *) data; 1641 struct d40_chan *d40c = (struct d40_chan *) data;
1642 struct d40_desc *d40d; 1642 struct d40_desc *d40d;
1643 unsigned long flags; 1643 unsigned long flags;
1644 bool callback_active;
1644 dma_async_tx_callback callback; 1645 dma_async_tx_callback callback;
1645 void *callback_param; 1646 void *callback_param;
1646 1647
@@ -1668,6 +1669,7 @@ static void dma_tasklet(unsigned long data)
1668 } 1669 }
1669 1670
1670 /* Callback to client */ 1671 /* Callback to client */
1672 callback_active = !!(d40d->txd.flags & DMA_PREP_INTERRUPT);
1671 callback = d40d->txd.callback; 1673 callback = d40d->txd.callback;
1672 callback_param = d40d->txd.callback_param; 1674 callback_param = d40d->txd.callback_param;
1673 1675
@@ -1690,7 +1692,7 @@ static void dma_tasklet(unsigned long data)
1690 1692
1691 spin_unlock_irqrestore(&d40c->lock, flags); 1693 spin_unlock_irqrestore(&d40c->lock, flags);
1692 1694
1693 if (callback && (d40d->txd.flags & DMA_PREP_INTERRUPT)) 1695 if (callback_active && callback)
1694 callback(callback_param); 1696 callback(callback_param);
1695 1697
1696 return; 1698 return;
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index e8c9ef03495b..33edd6766344 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -559,7 +559,8 @@ static void edac_mc_workq_function(struct work_struct *work_req)
559 * 559 *
560 * called with the mem_ctls_mutex held 560 * called with the mem_ctls_mutex held
561 */ 561 */
562static void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec) 562static void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec,
563 bool init)
563{ 564{
564 edac_dbg(0, "\n"); 565 edac_dbg(0, "\n");
565 566
@@ -567,7 +568,9 @@ static void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec)
567 if (mci->op_state != OP_RUNNING_POLL) 568 if (mci->op_state != OP_RUNNING_POLL)
568 return; 569 return;
569 570
570 INIT_DELAYED_WORK(&mci->work, edac_mc_workq_function); 571 if (init)
572 INIT_DELAYED_WORK(&mci->work, edac_mc_workq_function);
573
571 mod_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec)); 574 mod_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec));
572} 575}
573 576
@@ -601,7 +604,7 @@ static void edac_mc_workq_teardown(struct mem_ctl_info *mci)
601 * user space has updated our poll period value, need to 604 * user space has updated our poll period value, need to
602 * reset our workq delays 605 * reset our workq delays
603 */ 606 */
604void edac_mc_reset_delay_period(int value) 607void edac_mc_reset_delay_period(unsigned long value)
605{ 608{
606 struct mem_ctl_info *mci; 609 struct mem_ctl_info *mci;
607 struct list_head *item; 610 struct list_head *item;
@@ -611,7 +614,7 @@ void edac_mc_reset_delay_period(int value)
611 list_for_each(item, &mc_devices) { 614 list_for_each(item, &mc_devices) {
612 mci = list_entry(item, struct mem_ctl_info, link); 615 mci = list_entry(item, struct mem_ctl_info, link);
613 616
614 edac_mc_workq_setup(mci, (unsigned long) value); 617 edac_mc_workq_setup(mci, value, false);
615 } 618 }
616 619
617 mutex_unlock(&mem_ctls_mutex); 620 mutex_unlock(&mem_ctls_mutex);
@@ -782,7 +785,7 @@ int edac_mc_add_mc(struct mem_ctl_info *mci)
782 /* This instance is NOW RUNNING */ 785 /* This instance is NOW RUNNING */
783 mci->op_state = OP_RUNNING_POLL; 786 mci->op_state = OP_RUNNING_POLL;
784 787
785 edac_mc_workq_setup(mci, edac_mc_get_poll_msec()); 788 edac_mc_workq_setup(mci, edac_mc_get_poll_msec(), true);
786 } else { 789 } else {
787 mci->op_state = OP_RUNNING_INTERRUPT; 790 mci->op_state = OP_RUNNING_INTERRUPT;
788 } 791 }
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 51c0362acf5c..b335c6ab5efe 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -52,18 +52,20 @@ int edac_mc_get_poll_msec(void)
52 52
53static int edac_set_poll_msec(const char *val, struct kernel_param *kp) 53static int edac_set_poll_msec(const char *val, struct kernel_param *kp)
54{ 54{
55 long l; 55 unsigned long l;
56 int ret; 56 int ret;
57 57
58 if (!val) 58 if (!val)
59 return -EINVAL; 59 return -EINVAL;
60 60
61 ret = kstrtol(val, 0, &l); 61 ret = kstrtoul(val, 0, &l);
62 if (ret) 62 if (ret)
63 return ret; 63 return ret;
64 if ((int)l != l) 64
65 if (l < 1000)
65 return -EINVAL; 66 return -EINVAL;
66 *((int *)kp->arg) = l; 67
68 *((unsigned long *)kp->arg) = l;
67 69
68 /* notify edac_mc engine to reset the poll period */ 70 /* notify edac_mc engine to reset the poll period */
69 edac_mc_reset_delay_period(l); 71 edac_mc_reset_delay_period(l);
diff --git a/drivers/edac/edac_module.h b/drivers/edac/edac_module.h
index 3d139c6e7fe3..f2118bfcf8df 100644
--- a/drivers/edac/edac_module.h
+++ b/drivers/edac/edac_module.h
@@ -52,7 +52,7 @@ extern void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev,
52extern void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev); 52extern void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev);
53extern void edac_device_reset_delay_period(struct edac_device_ctl_info 53extern void edac_device_reset_delay_period(struct edac_device_ctl_info
54 *edac_dev, unsigned long value); 54 *edac_dev, unsigned long value);
55extern void edac_mc_reset_delay_period(int value); 55extern void edac_mc_reset_delay_period(unsigned long value);
56 56
57extern void *edac_align_ptr(void **p, unsigned size, int n_elems); 57extern void *edac_align_ptr(void **p, unsigned size, int n_elems);
58 58
diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
index d63f4798f7d0..57e96a3350f0 100644
--- a/drivers/edac/i7300_edac.c
+++ b/drivers/edac/i7300_edac.c
@@ -943,33 +943,35 @@ static int i7300_get_devices(struct mem_ctl_info *mci)
943 943
944 /* Attempt to 'get' the MCH register we want */ 944 /* Attempt to 'get' the MCH register we want */
945 pdev = NULL; 945 pdev = NULL;
946 while (!pvt->pci_dev_16_1_fsb_addr_map || 946 while ((pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
947 !pvt->pci_dev_16_2_fsb_err_regs) { 947 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
948 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 948 pdev))) {
949 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
950 if (!pdev) {
951 /* End of list, leave */
952 i7300_printk(KERN_ERR,
953 "'system address,Process Bus' "
954 "device not found:"
955 "vendor 0x%x device 0x%x ERR funcs "
956 "(broken BIOS?)\n",
957 PCI_VENDOR_ID_INTEL,
958 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
959 goto error;
960 }
961
962 /* Store device 16 funcs 1 and 2 */ 949 /* Store device 16 funcs 1 and 2 */
963 switch (PCI_FUNC(pdev->devfn)) { 950 switch (PCI_FUNC(pdev->devfn)) {
964 case 1: 951 case 1:
965 pvt->pci_dev_16_1_fsb_addr_map = pdev; 952 if (!pvt->pci_dev_16_1_fsb_addr_map)
953 pvt->pci_dev_16_1_fsb_addr_map =
954 pci_dev_get(pdev);
966 break; 955 break;
967 case 2: 956 case 2:
968 pvt->pci_dev_16_2_fsb_err_regs = pdev; 957 if (!pvt->pci_dev_16_2_fsb_err_regs)
958 pvt->pci_dev_16_2_fsb_err_regs =
959 pci_dev_get(pdev);
969 break; 960 break;
970 } 961 }
971 } 962 }
972 963
964 if (!pvt->pci_dev_16_1_fsb_addr_map ||
965 !pvt->pci_dev_16_2_fsb_err_regs) {
966 /* At least one device was not found */
967 i7300_printk(KERN_ERR,
968 "'system address,Process Bus' device not found:"
969 "vendor 0x%x device 0x%x ERR funcs (broken BIOS?)\n",
970 PCI_VENDOR_ID_INTEL,
971 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
972 goto error;
973 }
974
973 edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n", 975 edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n",
974 pci_name(pvt->pci_dev_16_0_fsb_ctlr), 976 pci_name(pvt->pci_dev_16_0_fsb_ctlr),
975 pvt->pci_dev_16_0_fsb_ctlr->vendor, 977 pvt->pci_dev_16_0_fsb_ctlr->vendor,
diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
index 87533ca7752e..d871275196f6 100644
--- a/drivers/edac/i7core_edac.c
+++ b/drivers/edac/i7core_edac.c
@@ -1334,14 +1334,19 @@ static int i7core_get_onedevice(struct pci_dev **prev,
1334 * is at addr 8086:2c40, instead of 8086:2c41. So, we need 1334 * is at addr 8086:2c40, instead of 8086:2c41. So, we need
1335 * to probe for the alternate address in case of failure 1335 * to probe for the alternate address in case of failure
1336 */ 1336 */
1337 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_I7_NONCORE && !pdev) 1337 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_I7_NONCORE && !pdev) {
1338 pci_dev_get(*prev); /* pci_get_device will put it */
1338 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 1339 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1339 PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT, *prev); 1340 PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT, *prev);
1341 }
1340 1342
1341 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE && !pdev) 1343 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE &&
1344 !pdev) {
1345 pci_dev_get(*prev); /* pci_get_device will put it */
1342 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 1346 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1343 PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT, 1347 PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT,
1344 *prev); 1348 *prev);
1349 }
1345 1350
1346 if (!pdev) { 1351 if (!pdev) {
1347 if (*prev) { 1352 if (*prev) {
diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index c20602f601ee..98a14f6143a7 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -222,27 +222,19 @@ static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
222 struct snd_soc_dapm_context *dapm = arizona->dapm; 222 struct snd_soc_dapm_context *dapm = arizona->dapm;
223 int ret; 223 int ret;
224 224
225 mutex_lock(&dapm->card->dapm_mutex);
226
227 ret = snd_soc_dapm_force_enable_pin(dapm, widget); 225 ret = snd_soc_dapm_force_enable_pin(dapm, widget);
228 if (ret != 0) 226 if (ret != 0)
229 dev_warn(arizona->dev, "Failed to enable %s: %d\n", 227 dev_warn(arizona->dev, "Failed to enable %s: %d\n",
230 widget, ret); 228 widget, ret);
231 229
232 mutex_unlock(&dapm->card->dapm_mutex);
233
234 snd_soc_dapm_sync(dapm); 230 snd_soc_dapm_sync(dapm);
235 231
236 if (!arizona->pdata.micd_force_micbias) { 232 if (!arizona->pdata.micd_force_micbias) {
237 mutex_lock(&dapm->card->dapm_mutex);
238
239 ret = snd_soc_dapm_disable_pin(arizona->dapm, widget); 233 ret = snd_soc_dapm_disable_pin(arizona->dapm, widget);
240 if (ret != 0) 234 if (ret != 0)
241 dev_warn(arizona->dev, "Failed to disable %s: %d\n", 235 dev_warn(arizona->dev, "Failed to disable %s: %d\n",
242 widget, ret); 236 widget, ret);
243 237
244 mutex_unlock(&dapm->card->dapm_mutex);
245
246 snd_soc_dapm_sync(dapm); 238 snd_soc_dapm_sync(dapm);
247 } 239 }
248} 240}
@@ -304,16 +296,12 @@ static void arizona_stop_mic(struct arizona_extcon_info *info)
304 ARIZONA_MICD_ENA, 0, 296 ARIZONA_MICD_ENA, 0,
305 &change); 297 &change);
306 298
307 mutex_lock(&dapm->card->dapm_mutex);
308
309 ret = snd_soc_dapm_disable_pin(dapm, widget); 299 ret = snd_soc_dapm_disable_pin(dapm, widget);
310 if (ret != 0) 300 if (ret != 0)
311 dev_warn(arizona->dev, 301 dev_warn(arizona->dev,
312 "Failed to disable %s: %d\n", 302 "Failed to disable %s: %d\n",
313 widget, ret); 303 widget, ret);
314 304
315 mutex_unlock(&dapm->card->dapm_mutex);
316
317 snd_soc_dapm_sync(dapm); 305 snd_soc_dapm_sync(dapm);
318 306
319 if (info->micd_reva) { 307 if (info->micd_reva) {
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index de4aa409abe2..2c6d5e118ac1 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -916,7 +916,7 @@ static int lookup_existing_device(struct device *dev, void *data)
916 old->config_rom_retries = 0; 916 old->config_rom_retries = 0;
917 fw_notice(card, "rediscovered device %s\n", dev_name(dev)); 917 fw_notice(card, "rediscovered device %s\n", dev_name(dev));
918 918
919 PREPARE_DELAYED_WORK(&old->work, fw_device_update); 919 old->workfn = fw_device_update;
920 fw_schedule_device_work(old, 0); 920 fw_schedule_device_work(old, 0);
921 921
922 if (current_node == card->root_node) 922 if (current_node == card->root_node)
@@ -1075,7 +1075,7 @@ static void fw_device_init(struct work_struct *work)
1075 if (atomic_cmpxchg(&device->state, 1075 if (atomic_cmpxchg(&device->state,
1076 FW_DEVICE_INITIALIZING, 1076 FW_DEVICE_INITIALIZING,
1077 FW_DEVICE_RUNNING) == FW_DEVICE_GONE) { 1077 FW_DEVICE_RUNNING) == FW_DEVICE_GONE) {
1078 PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown); 1078 device->workfn = fw_device_shutdown;
1079 fw_schedule_device_work(device, SHUTDOWN_DELAY); 1079 fw_schedule_device_work(device, SHUTDOWN_DELAY);
1080 } else { 1080 } else {
1081 fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n", 1081 fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n",
@@ -1196,13 +1196,20 @@ static void fw_device_refresh(struct work_struct *work)
1196 dev_name(&device->device), fw_rcode_string(ret)); 1196 dev_name(&device->device), fw_rcode_string(ret));
1197 gone: 1197 gone:
1198 atomic_set(&device->state, FW_DEVICE_GONE); 1198 atomic_set(&device->state, FW_DEVICE_GONE);
1199 PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown); 1199 device->workfn = fw_device_shutdown;
1200 fw_schedule_device_work(device, SHUTDOWN_DELAY); 1200 fw_schedule_device_work(device, SHUTDOWN_DELAY);
1201 out: 1201 out:
1202 if (node_id == card->root_node->node_id) 1202 if (node_id == card->root_node->node_id)
1203 fw_schedule_bm_work(card, 0); 1203 fw_schedule_bm_work(card, 0);
1204} 1204}
1205 1205
1206static void fw_device_workfn(struct work_struct *work)
1207{
1208 struct fw_device *device = container_of(to_delayed_work(work),
1209 struct fw_device, work);
1210 device->workfn(work);
1211}
1212
1206void fw_node_event(struct fw_card *card, struct fw_node *node, int event) 1213void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1207{ 1214{
1208 struct fw_device *device; 1215 struct fw_device *device;
@@ -1252,7 +1259,8 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1252 * power-up after getting plugged in. We schedule the 1259 * power-up after getting plugged in. We schedule the
1253 * first config rom scan half a second after bus reset. 1260 * first config rom scan half a second after bus reset.
1254 */ 1261 */
1255 INIT_DELAYED_WORK(&device->work, fw_device_init); 1262 device->workfn = fw_device_init;
1263 INIT_DELAYED_WORK(&device->work, fw_device_workfn);
1256 fw_schedule_device_work(device, INITIAL_DELAY); 1264 fw_schedule_device_work(device, INITIAL_DELAY);
1257 break; 1265 break;
1258 1266
@@ -1268,7 +1276,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1268 if (atomic_cmpxchg(&device->state, 1276 if (atomic_cmpxchg(&device->state,
1269 FW_DEVICE_RUNNING, 1277 FW_DEVICE_RUNNING,
1270 FW_DEVICE_INITIALIZING) == FW_DEVICE_RUNNING) { 1278 FW_DEVICE_INITIALIZING) == FW_DEVICE_RUNNING) {
1271 PREPARE_DELAYED_WORK(&device->work, fw_device_refresh); 1279 device->workfn = fw_device_refresh;
1272 fw_schedule_device_work(device, 1280 fw_schedule_device_work(device,
1273 device->is_local ? 0 : INITIAL_DELAY); 1281 device->is_local ? 0 : INITIAL_DELAY);
1274 } 1282 }
@@ -1283,7 +1291,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1283 smp_wmb(); /* update node_id before generation */ 1291 smp_wmb(); /* update node_id before generation */
1284 device->generation = card->generation; 1292 device->generation = card->generation;
1285 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) { 1293 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) {
1286 PREPARE_DELAYED_WORK(&device->work, fw_device_update); 1294 device->workfn = fw_device_update;
1287 fw_schedule_device_work(device, 0); 1295 fw_schedule_device_work(device, 0);
1288 } 1296 }
1289 break; 1297 break;
@@ -1308,7 +1316,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1308 device = node->data; 1316 device = node->data;
1309 if (atomic_xchg(&device->state, 1317 if (atomic_xchg(&device->state,
1310 FW_DEVICE_GONE) == FW_DEVICE_RUNNING) { 1318 FW_DEVICE_GONE) == FW_DEVICE_RUNNING) {
1311 PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown); 1319 device->workfn = fw_device_shutdown;
1312 fw_schedule_device_work(device, 1320 fw_schedule_device_work(device,
1313 list_empty(&card->link) ? 0 : SHUTDOWN_DELAY); 1321 list_empty(&card->link) ? 0 : SHUTDOWN_DELAY);
1314 } 1322 }
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
index 6b895986dc22..4af0a7bad7f2 100644
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -929,8 +929,6 @@ static void fwnet_write_complete(struct fw_card *card, int rcode,
929 if (rcode == RCODE_COMPLETE) { 929 if (rcode == RCODE_COMPLETE) {
930 fwnet_transmit_packet_done(ptask); 930 fwnet_transmit_packet_done(ptask);
931 } else { 931 } else {
932 fwnet_transmit_packet_failed(ptask);
933
934 if (printk_timed_ratelimit(&j, 1000) || rcode != last_rcode) { 932 if (printk_timed_ratelimit(&j, 1000) || rcode != last_rcode) {
935 dev_err(&ptask->dev->netdev->dev, 933 dev_err(&ptask->dev->netdev->dev,
936 "fwnet_write_complete failed: %x (skipped %d)\n", 934 "fwnet_write_complete failed: %x (skipped %d)\n",
@@ -938,8 +936,10 @@ static void fwnet_write_complete(struct fw_card *card, int rcode,
938 936
939 errors_skipped = 0; 937 errors_skipped = 0;
940 last_rcode = rcode; 938 last_rcode = rcode;
941 } else 939 } else {
942 errors_skipped++; 940 errors_skipped++;
941 }
942 fwnet_transmit_packet_failed(ptask);
943 } 943 }
944} 944}
945 945
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index 6f74d8d3f700..8db663219560 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -290,7 +290,6 @@ static char ohci_driver_name[] = KBUILD_MODNAME;
290#define QUIRK_NO_MSI 0x10 290#define QUIRK_NO_MSI 0x10
291#define QUIRK_TI_SLLZ059 0x20 291#define QUIRK_TI_SLLZ059 0x20
292#define QUIRK_IR_WAKE 0x40 292#define QUIRK_IR_WAKE 0x40
293#define QUIRK_PHY_LCTRL_TIMEOUT 0x80
294 293
295/* In case of multiple matches in ohci_quirks[], only the first one is used. */ 294/* In case of multiple matches in ohci_quirks[], only the first one is used. */
296static const struct { 295static const struct {
@@ -303,10 +302,7 @@ static const struct {
303 QUIRK_BE_HEADERS}, 302 QUIRK_BE_HEADERS},
304 303
305 {PCI_VENDOR_ID_ATT, PCI_DEVICE_ID_AGERE_FW643, 6, 304 {PCI_VENDOR_ID_ATT, PCI_DEVICE_ID_AGERE_FW643, 6,
306 QUIRK_PHY_LCTRL_TIMEOUT | QUIRK_NO_MSI}, 305 QUIRK_NO_MSI},
307
308 {PCI_VENDOR_ID_ATT, PCI_ANY_ID, PCI_ANY_ID,
309 QUIRK_PHY_LCTRL_TIMEOUT},
310 306
311 {PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_SB1394, PCI_ANY_ID, 307 {PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_SB1394, PCI_ANY_ID,
312 QUIRK_RESET_PACKET}, 308 QUIRK_RESET_PACKET},
@@ -353,7 +349,6 @@ MODULE_PARM_DESC(quirks, "Chip quirks (default = 0"
353 ", disable MSI = " __stringify(QUIRK_NO_MSI) 349 ", disable MSI = " __stringify(QUIRK_NO_MSI)
354 ", TI SLLZ059 erratum = " __stringify(QUIRK_TI_SLLZ059) 350 ", TI SLLZ059 erratum = " __stringify(QUIRK_TI_SLLZ059)
355 ", IR wake unreliable = " __stringify(QUIRK_IR_WAKE) 351 ", IR wake unreliable = " __stringify(QUIRK_IR_WAKE)
356 ", phy LCtrl timeout = " __stringify(QUIRK_PHY_LCTRL_TIMEOUT)
357 ")"); 352 ")");
358 353
359#define OHCI_PARAM_DEBUG_AT_AR 1 354#define OHCI_PARAM_DEBUG_AT_AR 1
@@ -2299,9 +2294,6 @@ static int ohci_enable(struct fw_card *card,
2299 * TI TSB82AA2 + TSB81BA3(A) cards signal LPS enabled early but 2294 * TI TSB82AA2 + TSB81BA3(A) cards signal LPS enabled early but
2300 * cannot actually use the phy at that time. These need tens of 2295 * cannot actually use the phy at that time. These need tens of
2301 * millisecods pause between LPS write and first phy access too. 2296 * millisecods pause between LPS write and first phy access too.
2302 *
2303 * But do not wait for 50msec on Agere/LSI cards. Their phy
2304 * arbitration state machine may time out during such a long wait.
2305 */ 2297 */
2306 2298
2307 reg_write(ohci, OHCI1394_HCControlSet, 2299 reg_write(ohci, OHCI1394_HCControlSet,
@@ -2309,11 +2301,8 @@ static int ohci_enable(struct fw_card *card,
2309 OHCI1394_HCControl_postedWriteEnable); 2301 OHCI1394_HCControl_postedWriteEnable);
2310 flush_writes(ohci); 2302 flush_writes(ohci);
2311 2303
2312 if (!(ohci->quirks & QUIRK_PHY_LCTRL_TIMEOUT)) 2304 for (lps = 0, i = 0; !lps && i < 3; i++) {
2313 msleep(50); 2305 msleep(50);
2314
2315 for (lps = 0, i = 0; !lps && i < 150; i++) {
2316 msleep(1);
2317 lps = reg_read(ohci, OHCI1394_HCControlSet) & 2306 lps = reg_read(ohci, OHCI1394_HCControlSet) &
2318 OHCI1394_HCControl_LPS; 2307 OHCI1394_HCControl_LPS;
2319 } 2308 }
diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c
index 281029daf98c..7aef911fdc71 100644
--- a/drivers/firewire/sbp2.c
+++ b/drivers/firewire/sbp2.c
@@ -146,6 +146,7 @@ struct sbp2_logical_unit {
146 */ 146 */
147 int generation; 147 int generation;
148 int retries; 148 int retries;
149 work_func_t workfn;
149 struct delayed_work work; 150 struct delayed_work work;
150 bool has_sdev; 151 bool has_sdev;
151 bool blocked; 152 bool blocked;
@@ -864,7 +865,7 @@ static void sbp2_login(struct work_struct *work)
864 /* set appropriate retry limit(s) in BUSY_TIMEOUT register */ 865 /* set appropriate retry limit(s) in BUSY_TIMEOUT register */
865 sbp2_set_busy_timeout(lu); 866 sbp2_set_busy_timeout(lu);
866 867
867 PREPARE_DELAYED_WORK(&lu->work, sbp2_reconnect); 868 lu->workfn = sbp2_reconnect;
868 sbp2_agent_reset(lu); 869 sbp2_agent_reset(lu);
869 870
870 /* This was a re-login. */ 871 /* This was a re-login. */
@@ -918,7 +919,7 @@ static void sbp2_login(struct work_struct *work)
918 * If a bus reset happened, sbp2_update will have requeued 919 * If a bus reset happened, sbp2_update will have requeued
919 * lu->work already. Reset the work from reconnect to login. 920 * lu->work already. Reset the work from reconnect to login.
920 */ 921 */
921 PREPARE_DELAYED_WORK(&lu->work, sbp2_login); 922 lu->workfn = sbp2_login;
922} 923}
923 924
924static void sbp2_reconnect(struct work_struct *work) 925static void sbp2_reconnect(struct work_struct *work)
@@ -952,7 +953,7 @@ static void sbp2_reconnect(struct work_struct *work)
952 lu->retries++ >= 5) { 953 lu->retries++ >= 5) {
953 dev_err(tgt_dev(tgt), "failed to reconnect\n"); 954 dev_err(tgt_dev(tgt), "failed to reconnect\n");
954 lu->retries = 0; 955 lu->retries = 0;
955 PREPARE_DELAYED_WORK(&lu->work, sbp2_login); 956 lu->workfn = sbp2_login;
956 } 957 }
957 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5)); 958 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
958 959
@@ -972,6 +973,13 @@ static void sbp2_reconnect(struct work_struct *work)
972 sbp2_conditionally_unblock(lu); 973 sbp2_conditionally_unblock(lu);
973} 974}
974 975
976static void sbp2_lu_workfn(struct work_struct *work)
977{
978 struct sbp2_logical_unit *lu = container_of(to_delayed_work(work),
979 struct sbp2_logical_unit, work);
980 lu->workfn(work);
981}
982
975static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry) 983static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
976{ 984{
977 struct sbp2_logical_unit *lu; 985 struct sbp2_logical_unit *lu;
@@ -998,7 +1006,8 @@ static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
998 lu->blocked = false; 1006 lu->blocked = false;
999 ++tgt->dont_block; 1007 ++tgt->dont_block;
1000 INIT_LIST_HEAD(&lu->orb_list); 1008 INIT_LIST_HEAD(&lu->orb_list);
1001 INIT_DELAYED_WORK(&lu->work, sbp2_login); 1009 lu->workfn = sbp2_login;
1010 INIT_DELAYED_WORK(&lu->work, sbp2_lu_workfn);
1002 1011
1003 list_add_tail(&lu->link, &tgt->lu_list); 1012 list_add_tail(&lu->link, &tgt->lu_list);
1004 return 0; 1013 return 0;
diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c
index 1b5e8e46226d..7160c43c59fc 100644
--- a/drivers/firmware/dcdbas.c
+++ b/drivers/firmware/dcdbas.c
@@ -584,7 +584,7 @@ static struct platform_driver dcdbas_driver = {
584 .remove = dcdbas_remove, 584 .remove = dcdbas_remove,
585}; 585};
586 586
587static const struct platform_device_info dcdbas_dev_info __initdata = { 587static const struct platform_device_info dcdbas_dev_info __initconst = {
588 .name = DRIVER_NAME, 588 .name = DRIVER_NAME,
589 .id = -1, 589 .id = -1,
590 .dma_mask = DMA_BIT_MASK(32), 590 .dma_mask = DMA_BIT_MASK(32),
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c
index b6bffbfd3be7..ff50aeebf0d9 100644
--- a/drivers/firmware/efi/efi-stub-helper.c
+++ b/drivers/firmware/efi/efi-stub-helper.c
@@ -16,18 +16,6 @@ struct file_info {
16 u64 size; 16 u64 size;
17}; 17};
18 18
19
20
21
22static void efi_char16_printk(efi_system_table_t *sys_table_arg,
23 efi_char16_t *str)
24{
25 struct efi_simple_text_output_protocol *out;
26
27 out = (struct efi_simple_text_output_protocol *)sys_table_arg->con_out;
28 efi_call_phys2(out->output_string, out, str);
29}
30
31static void efi_printk(efi_system_table_t *sys_table_arg, char *str) 19static void efi_printk(efi_system_table_t *sys_table_arg, char *str)
32{ 20{
33 char *s8; 21 char *s8;
@@ -65,20 +53,23 @@ again:
65 * allocation which may be in a new descriptor region. 53 * allocation which may be in a new descriptor region.
66 */ 54 */
67 *map_size += sizeof(*m); 55 *map_size += sizeof(*m);
68 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, 56 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
69 EFI_LOADER_DATA, *map_size, (void **)&m); 57 *map_size, (void **)&m);
70 if (status != EFI_SUCCESS) 58 if (status != EFI_SUCCESS)
71 goto fail; 59 goto fail;
72 60
73 status = efi_call_phys5(sys_table_arg->boottime->get_memory_map, 61 *desc_size = 0;
74 map_size, m, &key, desc_size, &desc_version); 62 key = 0;
63 status = efi_call_early(get_memory_map, map_size, m,
64 &key, desc_size, &desc_version);
75 if (status == EFI_BUFFER_TOO_SMALL) { 65 if (status == EFI_BUFFER_TOO_SMALL) {
76 efi_call_phys1(sys_table_arg->boottime->free_pool, m); 66 efi_call_early(free_pool, m);
77 goto again; 67 goto again;
78 } 68 }
79 69
80 if (status != EFI_SUCCESS) 70 if (status != EFI_SUCCESS)
81 efi_call_phys1(sys_table_arg->boottime->free_pool, m); 71 efi_call_early(free_pool, m);
72
82 if (key_ptr && status == EFI_SUCCESS) 73 if (key_ptr && status == EFI_SUCCESS)
83 *key_ptr = key; 74 *key_ptr = key;
84 if (desc_ver && status == EFI_SUCCESS) 75 if (desc_ver && status == EFI_SUCCESS)
@@ -158,7 +149,7 @@ again:
158 if (!max_addr) 149 if (!max_addr)
159 status = EFI_NOT_FOUND; 150 status = EFI_NOT_FOUND;
160 else { 151 else {
161 status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, 152 status = efi_call_early(allocate_pages,
162 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, 153 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
163 nr_pages, &max_addr); 154 nr_pages, &max_addr);
164 if (status != EFI_SUCCESS) { 155 if (status != EFI_SUCCESS) {
@@ -170,8 +161,7 @@ again:
170 *addr = max_addr; 161 *addr = max_addr;
171 } 162 }
172 163
173 efi_call_phys1(sys_table_arg->boottime->free_pool, map); 164 efi_call_early(free_pool, map);
174
175fail: 165fail:
176 return status; 166 return status;
177} 167}
@@ -231,7 +221,7 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
231 if ((start + size) > end) 221 if ((start + size) > end)
232 continue; 222 continue;
233 223
234 status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, 224 status = efi_call_early(allocate_pages,
235 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, 225 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
236 nr_pages, &start); 226 nr_pages, &start);
237 if (status == EFI_SUCCESS) { 227 if (status == EFI_SUCCESS) {
@@ -243,7 +233,7 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
243 if (i == map_size / desc_size) 233 if (i == map_size / desc_size)
244 status = EFI_NOT_FOUND; 234 status = EFI_NOT_FOUND;
245 235
246 efi_call_phys1(sys_table_arg->boottime->free_pool, map); 236 efi_call_early(free_pool, map);
247fail: 237fail:
248 return status; 238 return status;
249} 239}
@@ -257,7 +247,7 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
257 return; 247 return;
258 248
259 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 249 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
260 efi_call_phys2(sys_table_arg->boottime->free_pages, addr, nr_pages); 250 efi_call_early(free_pages, addr, nr_pages);
261} 251}
262 252
263 253
@@ -276,9 +266,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
276{ 266{
277 struct file_info *files; 267 struct file_info *files;
278 unsigned long file_addr; 268 unsigned long file_addr;
279 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
280 u64 file_size_total; 269 u64 file_size_total;
281 efi_file_io_interface_t *io;
282 efi_file_handle_t *fh; 270 efi_file_handle_t *fh;
283 efi_status_t status; 271 efi_status_t status;
284 int nr_files; 272 int nr_files;
@@ -319,10 +307,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
319 if (!nr_files) 307 if (!nr_files)
320 return EFI_SUCCESS; 308 return EFI_SUCCESS;
321 309
322 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, 310 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
323 EFI_LOADER_DATA, 311 nr_files * sizeof(*files), (void **)&files);
324 nr_files * sizeof(*files),
325 (void **)&files);
326 if (status != EFI_SUCCESS) { 312 if (status != EFI_SUCCESS) {
327 efi_printk(sys_table_arg, "Failed to alloc mem for file handle list\n"); 313 efi_printk(sys_table_arg, "Failed to alloc mem for file handle list\n");
328 goto fail; 314 goto fail;
@@ -331,13 +317,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
331 str = cmd_line; 317 str = cmd_line;
332 for (i = 0; i < nr_files; i++) { 318 for (i = 0; i < nr_files; i++) {
333 struct file_info *file; 319 struct file_info *file;
334 efi_file_handle_t *h;
335 efi_file_info_t *info;
336 efi_char16_t filename_16[256]; 320 efi_char16_t filename_16[256];
337 unsigned long info_sz;
338 efi_guid_t info_guid = EFI_FILE_INFO_ID;
339 efi_char16_t *p; 321 efi_char16_t *p;
340 u64 file_sz;
341 322
342 str = strstr(str, option_string); 323 str = strstr(str, option_string);
343 if (!str) 324 if (!str)
@@ -368,71 +349,18 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
368 349
369 /* Only open the volume once. */ 350 /* Only open the volume once. */
370 if (!i) { 351 if (!i) {
371 efi_boot_services_t *boottime; 352 status = efi_open_volume(sys_table_arg, image,
372 353 (void **)&fh);
373 boottime = sys_table_arg->boottime; 354 if (status != EFI_SUCCESS)
374
375 status = efi_call_phys3(boottime->handle_protocol,
376 image->device_handle, &fs_proto,
377 (void **)&io);
378 if (status != EFI_SUCCESS) {
379 efi_printk(sys_table_arg, "Failed to handle fs_proto\n");
380 goto free_files;
381 }
382
383 status = efi_call_phys2(io->open_volume, io, &fh);
384 if (status != EFI_SUCCESS) {
385 efi_printk(sys_table_arg, "Failed to open volume\n");
386 goto free_files; 355 goto free_files;
387 }
388 } 356 }
389 357
390 status = efi_call_phys5(fh->open, fh, &h, filename_16, 358 status = efi_file_size(sys_table_arg, fh, filename_16,
391 EFI_FILE_MODE_READ, (u64)0); 359 (void **)&file->handle, &file->size);
392 if (status != EFI_SUCCESS) { 360 if (status != EFI_SUCCESS)
393 efi_printk(sys_table_arg, "Failed to open file: ");
394 efi_char16_printk(sys_table_arg, filename_16);
395 efi_printk(sys_table_arg, "\n");
396 goto close_handles; 361 goto close_handles;
397 }
398 362
399 file->handle = h; 363 file_size_total += file->size;
400
401 info_sz = 0;
402 status = efi_call_phys4(h->get_info, h, &info_guid,
403 &info_sz, NULL);
404 if (status != EFI_BUFFER_TOO_SMALL) {
405 efi_printk(sys_table_arg, "Failed to get file info size\n");
406 goto close_handles;
407 }
408
409grow:
410 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool,
411 EFI_LOADER_DATA, info_sz,
412 (void **)&info);
413 if (status != EFI_SUCCESS) {
414 efi_printk(sys_table_arg, "Failed to alloc mem for file info\n");
415 goto close_handles;
416 }
417
418 status = efi_call_phys4(h->get_info, h, &info_guid,
419 &info_sz, info);
420 if (status == EFI_BUFFER_TOO_SMALL) {
421 efi_call_phys1(sys_table_arg->boottime->free_pool,
422 info);
423 goto grow;
424 }
425
426 file_sz = info->file_size;
427 efi_call_phys1(sys_table_arg->boottime->free_pool, info);
428
429 if (status != EFI_SUCCESS) {
430 efi_printk(sys_table_arg, "Failed to get file info\n");
431 goto close_handles;
432 }
433
434 file->size = file_sz;
435 file_size_total += file_sz;
436 } 364 }
437 365
438 if (file_size_total) { 366 if (file_size_total) {
@@ -468,10 +396,10 @@ grow:
468 chunksize = EFI_READ_CHUNK_SIZE; 396 chunksize = EFI_READ_CHUNK_SIZE;
469 else 397 else
470 chunksize = size; 398 chunksize = size;
471 status = efi_call_phys3(fh->read, 399
472 files[j].handle, 400 status = efi_file_read(fh, files[j].handle,
473 &chunksize, 401 &chunksize,
474 (void *)addr); 402 (void *)addr);
475 if (status != EFI_SUCCESS) { 403 if (status != EFI_SUCCESS) {
476 efi_printk(sys_table_arg, "Failed to read file\n"); 404 efi_printk(sys_table_arg, "Failed to read file\n");
477 goto free_file_total; 405 goto free_file_total;
@@ -480,12 +408,12 @@ grow:
480 size -= chunksize; 408 size -= chunksize;
481 } 409 }
482 410
483 efi_call_phys1(fh->close, files[j].handle); 411 efi_file_close(fh, files[j].handle);
484 } 412 }
485 413
486 } 414 }
487 415
488 efi_call_phys1(sys_table_arg->boottime->free_pool, files); 416 efi_call_early(free_pool, files);
489 417
490 *load_addr = file_addr; 418 *load_addr = file_addr;
491 *load_size = file_size_total; 419 *load_size = file_size_total;
@@ -497,9 +425,9 @@ free_file_total:
497 425
498close_handles: 426close_handles:
499 for (k = j; k < i; k++) 427 for (k = j; k < i; k++)
500 efi_call_phys1(fh->close, files[k].handle); 428 efi_file_close(fh, files[k].handle);
501free_files: 429free_files:
502 efi_call_phys1(sys_table_arg->boottime->free_pool, files); 430 efi_call_early(free_pool, files);
503fail: 431fail:
504 *load_addr = 0; 432 *load_addr = 0;
505 *load_size = 0; 433 *load_size = 0;
@@ -545,7 +473,7 @@ static efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
545 * as possible while respecting the required alignment. 473 * as possible while respecting the required alignment.
546 */ 474 */
547 nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 475 nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
548 status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, 476 status = efi_call_early(allocate_pages,
549 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, 477 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
550 nr_pages, &efi_addr); 478 nr_pages, &efi_addr);
551 new_addr = efi_addr; 479 new_addr = efi_addr;
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 4753bac65279..af20f1712337 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -233,7 +233,7 @@ static __initdata efi_config_table_type_t common_tables[] = {
233 {SAL_SYSTEM_TABLE_GUID, "SALsystab", &efi.sal_systab}, 233 {SAL_SYSTEM_TABLE_GUID, "SALsystab", &efi.sal_systab},
234 {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios}, 234 {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios},
235 {UGA_IO_PROTOCOL_GUID, "UGA", &efi.uga}, 235 {UGA_IO_PROTOCOL_GUID, "UGA", &efi.uga},
236 {NULL_GUID, NULL, 0}, 236 {NULL_GUID, NULL, NULL},
237}; 237};
238 238
239static __init int match_config_table(efi_guid_t *guid, 239static __init int match_config_table(efi_guid_t *guid,
@@ -313,5 +313,8 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables)
313 } 313 }
314 pr_cont("\n"); 314 pr_cont("\n");
315 early_iounmap(config_tables, efi.systab->nr_tables * sz); 315 early_iounmap(config_tables, efi.systab->nr_tables * sz);
316
317 set_bit(EFI_CONFIG_TABLES, &efi.flags);
318
316 return 0; 319 return 0;
317} 320}
diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
index 3dc248239197..50ea412a25e6 100644
--- a/drivers/firmware/efi/efivars.c
+++ b/drivers/firmware/efi/efivars.c
@@ -227,7 +227,7 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
227 memcpy(&entry->var, new_var, count); 227 memcpy(&entry->var, new_var, count);
228 228
229 err = efivar_entry_set(entry, new_var->Attributes, 229 err = efivar_entry_set(entry, new_var->Attributes,
230 new_var->DataSize, new_var->Data, false); 230 new_var->DataSize, new_var->Data, NULL);
231 if (err) { 231 if (err) {
232 printk(KERN_WARNING "efivars: set_variable() failed: status=%d\n", err); 232 printk(KERN_WARNING "efivars: set_variable() failed: status=%d\n", err);
233 return -EIO; 233 return -EIO;
diff --git a/drivers/fmc/fmc-write-eeprom.c b/drivers/fmc/fmc-write-eeprom.c
index ee5b47904130..9bb2cbd5c9f2 100644
--- a/drivers/fmc/fmc-write-eeprom.c
+++ b/drivers/fmc/fmc-write-eeprom.c
@@ -27,7 +27,7 @@ FMC_PARAM_BUSID(fwe_drv);
27/* The "file=" is like the generic "gateware=" used elsewhere */ 27/* The "file=" is like the generic "gateware=" used elsewhere */
28static char *fwe_file[FMC_MAX_CARDS]; 28static char *fwe_file[FMC_MAX_CARDS];
29static int fwe_file_n; 29static int fwe_file_n;
30module_param_array_named(file, fwe_file, charp, &fwe_file_n, 444); 30module_param_array_named(file, fwe_file, charp, &fwe_file_n, 0444);
31 31
32static int fwe_run_tlv(struct fmc_device *fmc, const struct firmware *fw, 32static int fwe_run_tlv(struct fmc_device *fmc, const struct firmware *fw,
33 int write) 33 int write)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 697338772b64..903f24d28ba0 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -403,6 +403,7 @@ config GPIO_GRGPIO
403 403
404config GPIO_TB10X 404config GPIO_TB10X
405 bool 405 bool
406 select GENERIC_IRQ_CHIP
406 select OF_GPIO 407 select OF_GPIO
407 408
408comment "I2C GPIO expanders:" 409comment "I2C GPIO expanders:"
diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
index 233d088ac59f..f32357e2d78d 100644
--- a/drivers/gpio/gpio-bcm-kona.c
+++ b/drivers/gpio/gpio-bcm-kona.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2012-2013 Broadcom Corporation 2 * Copyright (C) 2012-2014 Broadcom Corporation
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as 5 * modify it under the terms of the GNU General Public License as
@@ -657,6 +657,6 @@ static struct platform_driver bcm_kona_gpio_driver = {
657 657
658module_platform_driver(bcm_kona_gpio_driver); 658module_platform_driver(bcm_kona_gpio_driver);
659 659
660MODULE_AUTHOR("Broadcom"); 660MODULE_AUTHOR("Broadcom Corporation <bcm-kernel-feedback-list@broadcom.com>");
661MODULE_DESCRIPTION("Broadcom Kona GPIO Driver"); 661MODULE_DESCRIPTION("Broadcom Kona GPIO Driver");
662MODULE_LICENSE("GPL v2"); 662MODULE_LICENSE("GPL v2");
diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c
index d3550274b8f7..3c2ba2ad0ada 100644
--- a/drivers/gpio/gpio-clps711x.c
+++ b/drivers/gpio/gpio-clps711x.c
@@ -97,3 +97,4 @@ module_platform_driver(clps711x_gpio_driver);
97MODULE_LICENSE("GPL"); 97MODULE_LICENSE("GPL");
98MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>"); 98MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
99MODULE_DESCRIPTION("CLPS711X GPIO driver"); 99MODULE_DESCRIPTION("CLPS711X GPIO driver");
100MODULE_ALIAS("platform:clps711x-gpio");
diff --git a/drivers/gpio/gpio-intel-mid.c b/drivers/gpio/gpio-intel-mid.c
index d1b50ef5fab8..e585163f1ad5 100644
--- a/drivers/gpio/gpio-intel-mid.c
+++ b/drivers/gpio/gpio-intel-mid.c
@@ -394,8 +394,8 @@ static const struct irq_domain_ops intel_gpio_irq_ops = {
394 394
395static int intel_gpio_runtime_idle(struct device *dev) 395static int intel_gpio_runtime_idle(struct device *dev)
396{ 396{
397 pm_schedule_suspend(dev, 500); 397 int err = pm_schedule_suspend(dev, 500);
398 return -EBUSY; 398 return err ?: -EBUSY;
399} 399}
400 400
401static const struct dev_pm_ops intel_gpio_pm_ops = { 401static const struct dev_pm_ops intel_gpio_pm_ops = {
diff --git a/drivers/gpio/gpio-xtensa.c b/drivers/gpio/gpio-xtensa.c
index 1d136eceda62..7081304d6797 100644
--- a/drivers/gpio/gpio-xtensa.c
+++ b/drivers/gpio/gpio-xtensa.c
@@ -40,6 +40,8 @@
40#error GPIO32 option is not enabled for your xtensa core variant 40#error GPIO32 option is not enabled for your xtensa core variant
41#endif 41#endif
42 42
43#if XCHAL_HAVE_CP
44
43static inline unsigned long enable_cp(unsigned long *cpenable) 45static inline unsigned long enable_cp(unsigned long *cpenable)
44{ 46{
45 unsigned long flags; 47 unsigned long flags;
@@ -57,6 +59,20 @@ static inline void disable_cp(unsigned long flags, unsigned long cpenable)
57 local_irq_restore(flags); 59 local_irq_restore(flags);
58} 60}
59 61
62#else
63
64static inline unsigned long enable_cp(unsigned long *cpenable)
65{
66 *cpenable = 0; /* avoid uninitialized value warning */
67 return 0;
68}
69
70static inline void disable_cp(unsigned long flags, unsigned long cpenable)
71{
72}
73
74#endif /* XCHAL_HAVE_CP */
75
60static int xtensa_impwire_get_direction(struct gpio_chip *gc, unsigned offset) 76static int xtensa_impwire_get_direction(struct gpio_chip *gc, unsigned offset)
61{ 77{
62 return 1; /* input only */ 78 return 1; /* input only */
diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c
index acf3a36c9ebc..32982da82694 100644
--- a/drivers/gpu/drm/armada/armada_drv.c
+++ b/drivers/gpu/drm/armada/armada_drv.c
@@ -68,15 +68,7 @@ void __armada_drm_queue_unref_work(struct drm_device *dev,
68{ 68{
69 struct armada_private *priv = dev->dev_private; 69 struct armada_private *priv = dev->dev_private;
70 70
71 /* 71 WARN_ON(!kfifo_put(&priv->fb_unref, fb));
72 * Yes, we really must jump through these hoops just to store a
73 * _pointer_ to something into the kfifo. This is utterly insane
74 * and idiotic, because it kfifo requires the _data_ pointed to by
75 * the pointer const, not the pointer itself. Not only that, but
76 * you have to pass a pointer _to_ the pointer you want stored.
77 */
78 const struct drm_framebuffer *silly_api_alert = fb;
79 WARN_ON(!kfifo_put(&priv->fb_unref, &silly_api_alert));
80 schedule_work(&priv->fb_unref_work); 72 schedule_work(&priv->fb_unref_work);
81} 73}
82 74
diff --git a/drivers/gpu/drm/ast/ast_fb.c b/drivers/gpu/drm/ast/ast_fb.c
index 3f65dd6676b2..a28640f47c27 100644
--- a/drivers/gpu/drm/ast/ast_fb.c
+++ b/drivers/gpu/drm/ast/ast_fb.c
@@ -65,7 +65,7 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,
65 * then the BO is being moved and we should 65 * then the BO is being moved and we should
66 * store up the damage until later. 66 * store up the damage until later.
67 */ 67 */
68 if (!drm_can_sleep()) 68 if (drm_can_sleep())
69 ret = ast_bo_reserve(bo, true); 69 ret = ast_bo_reserve(bo, true);
70 if (ret) { 70 if (ret) {
71 if (ret != -EBUSY) 71 if (ret != -EBUSY)
diff --git a/drivers/gpu/drm/bochs/Kconfig b/drivers/gpu/drm/bochs/Kconfig
index c8fcf12019f0..5f8b0c2b9a44 100644
--- a/drivers/gpu/drm/bochs/Kconfig
+++ b/drivers/gpu/drm/bochs/Kconfig
@@ -2,6 +2,7 @@ config DRM_BOCHS
2 tristate "DRM Support for bochs dispi vga interface (qemu stdvga)" 2 tristate "DRM Support for bochs dispi vga interface (qemu stdvga)"
3 depends on DRM && PCI 3 depends on DRM && PCI
4 select DRM_KMS_HELPER 4 select DRM_KMS_HELPER
5 select DRM_KMS_FB_HELPER
5 select FB_SYS_FILLRECT 6 select FB_SYS_FILLRECT
6 select FB_SYS_COPYAREA 7 select FB_SYS_COPYAREA
7 select FB_SYS_IMAGEBLIT 8 select FB_SYS_IMAGEBLIT
diff --git a/drivers/gpu/drm/cirrus/cirrus_fbdev.c b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
index 2fd4a92162cb..32bbba0a787b 100644
--- a/drivers/gpu/drm/cirrus/cirrus_fbdev.c
+++ b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
@@ -39,7 +39,7 @@ static void cirrus_dirty_update(struct cirrus_fbdev *afbdev,
39 * then the BO is being moved and we should 39 * then the BO is being moved and we should
40 * store up the damage until later. 40 * store up the damage until later.
41 */ 41 */
42 if (!drm_can_sleep()) 42 if (drm_can_sleep())
43 ret = cirrus_bo_reserve(bo, true); 43 ret = cirrus_bo_reserve(bo, true);
44 if (ret) { 44 if (ret) {
45 if (ret != -EBUSY) 45 if (ret != -EBUSY)
diff --git a/drivers/gpu/drm/drm_cache.c b/drivers/gpu/drm/drm_cache.c
index bb8f58012189..534cb89b160d 100644
--- a/drivers/gpu/drm/drm_cache.c
+++ b/drivers/gpu/drm/drm_cache.c
@@ -32,6 +32,12 @@
32#include <drm/drmP.h> 32#include <drm/drmP.h>
33 33
34#if defined(CONFIG_X86) 34#if defined(CONFIG_X86)
35
36/*
37 * clflushopt is an unordered instruction which needs fencing with mfence or
38 * sfence to avoid ordering issues. For drm_clflush_page this fencing happens
39 * in the caller.
40 */
35static void 41static void
36drm_clflush_page(struct page *page) 42drm_clflush_page(struct page *page)
37{ 43{
@@ -44,7 +50,7 @@ drm_clflush_page(struct page *page)
44 50
45 page_virtual = kmap_atomic(page); 51 page_virtual = kmap_atomic(page);
46 for (i = 0; i < PAGE_SIZE; i += size) 52 for (i = 0; i < PAGE_SIZE; i += size)
47 clflush(page_virtual + i); 53 clflushopt(page_virtual + i);
48 kunmap_atomic(page_virtual); 54 kunmap_atomic(page_virtual);
49} 55}
50 56
@@ -133,7 +139,7 @@ drm_clflush_virt_range(char *addr, unsigned long length)
133 mb(); 139 mb();
134 for (; addr < end; addr += boot_cpu_data.x86_clflush_size) 140 for (; addr < end; addr += boot_cpu_data.x86_clflush_size)
135 clflush(addr); 141 clflush(addr);
136 clflush(end - 1); 142 clflushopt(end - 1);
137 mb(); 143 mb();
138 return; 144 return;
139 } 145 }
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index dffc836144cc..f4dc9b7a3831 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -296,6 +296,18 @@ int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
296 case DRM_CAP_ASYNC_PAGE_FLIP: 296 case DRM_CAP_ASYNC_PAGE_FLIP:
297 req->value = dev->mode_config.async_page_flip; 297 req->value = dev->mode_config.async_page_flip;
298 break; 298 break;
299 case DRM_CAP_CURSOR_WIDTH:
300 if (dev->mode_config.cursor_width)
301 req->value = dev->mode_config.cursor_width;
302 else
303 req->value = 64;
304 break;
305 case DRM_CAP_CURSOR_HEIGHT:
306 if (dev->mode_config.cursor_height)
307 req->value = dev->mode_config.cursor_height;
308 else
309 req->value = 64;
310 break;
299 default: 311 default:
300 return -EINVAL; 312 return -EINVAL;
301 } 313 }
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index 5736aaa7e86c..f7af69bcf3f4 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -468,8 +468,8 @@ void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver)
468 } else { 468 } else {
469 list_for_each_entry_safe(dev, tmp, &driver->legacy_dev_list, 469 list_for_each_entry_safe(dev, tmp, &driver->legacy_dev_list,
470 legacy_dev_list) { 470 legacy_dev_list) {
471 drm_put_dev(dev);
472 list_del(&dev->legacy_dev_list); 471 list_del(&dev->legacy_dev_list);
472 drm_put_dev(dev);
473 } 473 }
474 } 474 }
475 DRM_INFO("Module unloaded\n"); 475 DRM_INFO("Module unloaded\n");
diff --git a/drivers/gpu/drm/exynos/Kconfig b/drivers/gpu/drm/exynos/Kconfig
index f227f544aa36..6e1a1a20cf6b 100644
--- a/drivers/gpu/drm/exynos/Kconfig
+++ b/drivers/gpu/drm/exynos/Kconfig
@@ -51,7 +51,7 @@ config DRM_EXYNOS_G2D
51 51
52config DRM_EXYNOS_IPP 52config DRM_EXYNOS_IPP
53 bool "Exynos DRM IPP" 53 bool "Exynos DRM IPP"
54 depends on DRM_EXYNOS && !ARCH_MULTIPLATFORM 54 depends on DRM_EXYNOS
55 help 55 help
56 Choose this option if you want to use IPP feature for DRM. 56 Choose this option if you want to use IPP feature for DRM.
57 57
@@ -69,6 +69,6 @@ config DRM_EXYNOS_ROTATOR
69 69
70config DRM_EXYNOS_GSC 70config DRM_EXYNOS_GSC
71 bool "Exynos DRM GSC" 71 bool "Exynos DRM GSC"
72 depends on DRM_EXYNOS_IPP && ARCH_EXYNOS5 72 depends on DRM_EXYNOS_IPP && ARCH_EXYNOS5 && !ARCH_MULTIPLATFORM
73 help 73 help
74 Choose this option if you want to use Exynos GSC for DRM. 74 Choose this option if you want to use Exynos GSC for DRM.
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index 9d096a0c5f8d..c204b4e3356e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -171,22 +171,28 @@ static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
171 file->driver_priv = file_priv; 171 file->driver_priv = file_priv;
172 172
173 ret = exynos_drm_subdrv_open(dev, file); 173 ret = exynos_drm_subdrv_open(dev, file);
174 if (ret) { 174 if (ret)
175 kfree(file_priv); 175 goto err_file_priv_free;
176 file->driver_priv = NULL;
177 }
178 176
179 anon_filp = anon_inode_getfile("exynos_gem", &exynos_drm_gem_fops, 177 anon_filp = anon_inode_getfile("exynos_gem", &exynos_drm_gem_fops,
180 NULL, 0); 178 NULL, 0);
181 if (IS_ERR(anon_filp)) { 179 if (IS_ERR(anon_filp)) {
182 kfree(file_priv); 180 ret = PTR_ERR(anon_filp);
183 return PTR_ERR(anon_filp); 181 goto err_subdrv_close;
184 } 182 }
185 183
186 anon_filp->f_mode = FMODE_READ | FMODE_WRITE; 184 anon_filp->f_mode = FMODE_READ | FMODE_WRITE;
187 file_priv->anon_filp = anon_filp; 185 file_priv->anon_filp = anon_filp;
188 186
189 return ret; 187 return ret;
188
189err_subdrv_close:
190 exynos_drm_subdrv_close(dev, file);
191
192err_file_priv_free:
193 kfree(file_priv);
194 file->driver_priv = NULL;
195 return ret;
190} 196}
191 197
192static void exynos_drm_preclose(struct drm_device *dev, 198static void exynos_drm_preclose(struct drm_device *dev,
diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index 380aec28840b..6c1885eedfdf 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -607,7 +607,7 @@ static enum g2d_reg_type g2d_get_reg_type(int reg_offset)
607 reg_type = REG_TYPE_NONE; 607 reg_type = REG_TYPE_NONE;
608 DRM_ERROR("Unknown register offset![%d]\n", reg_offset); 608 DRM_ERROR("Unknown register offset![%d]\n", reg_offset);
609 break; 609 break;
610 }; 610 }
611 611
612 return reg_type; 612 return reg_type;
613} 613}
diff --git a/drivers/gpu/drm/exynos/exynos_drm_ipp.c b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
index d519a4e5fe40..09312b877470 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_ipp.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
@@ -16,7 +16,6 @@
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/clk.h> 17#include <linux/clk.h>
18#include <linux/pm_runtime.h> 18#include <linux/pm_runtime.h>
19#include <plat/map-base.h>
20 19
21#include <drm/drmP.h> 20#include <drm/drmP.h>
22#include <drm/exynos_drm.h> 21#include <drm/exynos_drm.h>
@@ -826,7 +825,7 @@ static void ipp_put_event(struct drm_exynos_ipp_cmd_node *c_node,
826 DRM_DEBUG_KMS("count[%d]e[0x%x]\n", count++, (int)e); 825 DRM_DEBUG_KMS("count[%d]e[0x%x]\n", count++, (int)e);
827 826
828 /* 827 /*
829 * quf == NULL condition means all event deletion. 828 * qbuf == NULL condition means all event deletion.
830 * stop operations want to delete all event list. 829 * stop operations want to delete all event list.
831 * another case delete only same buf id. 830 * another case delete only same buf id.
832 */ 831 */
diff --git a/drivers/gpu/drm/exynos/exynos_hdmi.c b/drivers/gpu/drm/exynos/exynos_hdmi.c
index a0e10aeb0e67..c021ddc1ffb4 100644
--- a/drivers/gpu/drm/exynos/exynos_hdmi.c
+++ b/drivers/gpu/drm/exynos/exynos_hdmi.c
@@ -34,6 +34,7 @@
34#include <linux/io.h> 34#include <linux/io.h>
35#include <linux/of.h> 35#include <linux/of.h>
36#include <linux/of_gpio.h> 36#include <linux/of_gpio.h>
37#include <linux/hdmi.h>
37 38
38#include <drm/exynos_drm.h> 39#include <drm/exynos_drm.h>
39 40
@@ -59,19 +60,6 @@
59#define HDMI_AUI_VERSION 0x01 60#define HDMI_AUI_VERSION 0x01
60#define HDMI_AUI_LENGTH 0x0A 61#define HDMI_AUI_LENGTH 0x0A
61 62
62/* HDMI infoframe to configure HDMI out packet header, AUI and AVI */
63enum HDMI_PACKET_TYPE {
64 /* refer to Table 5-8 Packet Type in HDMI specification v1.4a */
65 /* InfoFrame packet type */
66 HDMI_PACKET_TYPE_INFOFRAME = 0x80,
67 /* Vendor-Specific InfoFrame */
68 HDMI_PACKET_TYPE_VSI = HDMI_PACKET_TYPE_INFOFRAME + 1,
69 /* Auxiliary Video information InfoFrame */
70 HDMI_PACKET_TYPE_AVI = HDMI_PACKET_TYPE_INFOFRAME + 2,
71 /* Audio information InfoFrame */
72 HDMI_PACKET_TYPE_AUI = HDMI_PACKET_TYPE_INFOFRAME + 4
73};
74
75enum hdmi_type { 63enum hdmi_type {
76 HDMI_TYPE13, 64 HDMI_TYPE13,
77 HDMI_TYPE14, 65 HDMI_TYPE14,
@@ -379,12 +367,6 @@ static const struct hdmiphy_config hdmiphy_v14_configs[] = {
379 }, 367 },
380}; 368};
381 369
382struct hdmi_infoframe {
383 enum HDMI_PACKET_TYPE type;
384 u8 ver;
385 u8 len;
386};
387
388static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id) 370static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
389{ 371{
390 return readl(hdata->regs + reg_id); 372 return readl(hdata->regs + reg_id);
@@ -682,7 +664,7 @@ static u8 hdmi_chksum(struct hdmi_context *hdata,
682} 664}
683 665
684static void hdmi_reg_infoframe(struct hdmi_context *hdata, 666static void hdmi_reg_infoframe(struct hdmi_context *hdata,
685 struct hdmi_infoframe *infoframe) 667 union hdmi_infoframe *infoframe)
686{ 668{
687 u32 hdr_sum; 669 u32 hdr_sum;
688 u8 chksum; 670 u8 chksum;
@@ -700,13 +682,15 @@ static void hdmi_reg_infoframe(struct hdmi_context *hdata,
700 return; 682 return;
701 } 683 }
702 684
703 switch (infoframe->type) { 685 switch (infoframe->any.type) {
704 case HDMI_PACKET_TYPE_AVI: 686 case HDMI_INFOFRAME_TYPE_AVI:
705 hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC); 687 hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
706 hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->type); 688 hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->any.type);
707 hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1, infoframe->ver); 689 hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1,
708 hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->len); 690 infoframe->any.version);
709 hdr_sum = infoframe->type + infoframe->ver + infoframe->len; 691 hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->any.length);
692 hdr_sum = infoframe->any.type + infoframe->any.version +
693 infoframe->any.length;
710 694
711 /* Output format zero hardcoded ,RGB YBCR selection */ 695 /* Output format zero hardcoded ,RGB YBCR selection */
712 hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 | 696 hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 |
@@ -722,18 +706,20 @@ static void hdmi_reg_infoframe(struct hdmi_context *hdata,
722 hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), vic); 706 hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), vic);
723 707
724 chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1), 708 chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1),
725 infoframe->len, hdr_sum); 709 infoframe->any.length, hdr_sum);
726 DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum); 710 DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum);
727 hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum); 711 hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum);
728 break; 712 break;
729 case HDMI_PACKET_TYPE_AUI: 713 case HDMI_INFOFRAME_TYPE_AUDIO:
730 hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02); 714 hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
731 hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->type); 715 hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->any.type);
732 hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1, infoframe->ver); 716 hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1,
733 hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->len); 717 infoframe->any.version);
734 hdr_sum = infoframe->type + infoframe->ver + infoframe->len; 718 hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->any.length);
719 hdr_sum = infoframe->any.type + infoframe->any.version +
720 infoframe->any.length;
735 chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1), 721 chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1),
736 infoframe->len, hdr_sum); 722 infoframe->any.length, hdr_sum);
737 DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum); 723 DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum);
738 hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum); 724 hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum);
739 break; 725 break;
@@ -985,7 +971,7 @@ static void hdmi_conf_reset(struct hdmi_context *hdata)
985 971
986static void hdmi_conf_init(struct hdmi_context *hdata) 972static void hdmi_conf_init(struct hdmi_context *hdata)
987{ 973{
988 struct hdmi_infoframe infoframe; 974 union hdmi_infoframe infoframe;
989 975
990 /* disable HPD interrupts from HDMI IP block, use GPIO instead */ 976 /* disable HPD interrupts from HDMI IP block, use GPIO instead */
991 hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL | 977 hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
@@ -1021,14 +1007,14 @@ static void hdmi_conf_init(struct hdmi_context *hdata)
1021 hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02); 1007 hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
1022 hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04); 1008 hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
1023 } else { 1009 } else {
1024 infoframe.type = HDMI_PACKET_TYPE_AVI; 1010 infoframe.any.type = HDMI_INFOFRAME_TYPE_AVI;
1025 infoframe.ver = HDMI_AVI_VERSION; 1011 infoframe.any.version = HDMI_AVI_VERSION;
1026 infoframe.len = HDMI_AVI_LENGTH; 1012 infoframe.any.length = HDMI_AVI_LENGTH;
1027 hdmi_reg_infoframe(hdata, &infoframe); 1013 hdmi_reg_infoframe(hdata, &infoframe);
1028 1014
1029 infoframe.type = HDMI_PACKET_TYPE_AUI; 1015 infoframe.any.type = HDMI_INFOFRAME_TYPE_AUDIO;
1030 infoframe.ver = HDMI_AUI_VERSION; 1016 infoframe.any.version = HDMI_AUI_VERSION;
1031 infoframe.len = HDMI_AUI_LENGTH; 1017 infoframe.any.length = HDMI_AUI_LENGTH;
1032 hdmi_reg_infoframe(hdata, &infoframe); 1018 hdmi_reg_infoframe(hdata, &infoframe);
1033 1019
1034 /* enable AVI packet every vsync, fixes purple line problem */ 1020 /* enable AVI packet every vsync, fixes purple line problem */
diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c
index 400b0c4a10fb..faa77f543a07 100644
--- a/drivers/gpu/drm/i2c/tda998x_drv.c
+++ b/drivers/gpu/drm/i2c/tda998x_drv.c
@@ -208,7 +208,7 @@ struct tda998x_priv {
208# define PLL_SERIAL_1_SRL_IZ(x) (((x) & 3) << 1) 208# define PLL_SERIAL_1_SRL_IZ(x) (((x) & 3) << 1)
209# define PLL_SERIAL_1_SRL_MAN_IZ (1 << 6) 209# define PLL_SERIAL_1_SRL_MAN_IZ (1 << 6)
210#define REG_PLL_SERIAL_2 REG(0x02, 0x01) /* read/write */ 210#define REG_PLL_SERIAL_2 REG(0x02, 0x01) /* read/write */
211# define PLL_SERIAL_2_SRL_NOSC(x) (((x) & 3) << 0) 211# define PLL_SERIAL_2_SRL_NOSC(x) ((x) << 0)
212# define PLL_SERIAL_2_SRL_PR(x) (((x) & 0xf) << 4) 212# define PLL_SERIAL_2_SRL_PR(x) (((x) & 0xf) << 4)
213#define REG_PLL_SERIAL_3 REG(0x02, 0x02) /* read/write */ 213#define REG_PLL_SERIAL_3 REG(0x02, 0x02) /* read/write */
214# define PLL_SERIAL_3_SRL_CCIR (1 << 0) 214# define PLL_SERIAL_3_SRL_CCIR (1 << 0)
@@ -528,10 +528,10 @@ tda998x_write_aif(struct drm_encoder *encoder, struct tda998x_encoder_params *p)
528{ 528{
529 uint8_t buf[PB(5) + 1]; 529 uint8_t buf[PB(5) + 1];
530 530
531 memset(buf, 0, sizeof(buf));
531 buf[HB(0)] = 0x84; 532 buf[HB(0)] = 0x84;
532 buf[HB(1)] = 0x01; 533 buf[HB(1)] = 0x01;
533 buf[HB(2)] = 10; 534 buf[HB(2)] = 10;
534 buf[PB(0)] = 0;
535 buf[PB(1)] = p->audio_frame[1] & 0x07; /* CC */ 535 buf[PB(1)] = p->audio_frame[1] & 0x07; /* CC */
536 buf[PB(2)] = p->audio_frame[2] & 0x1c; /* SF */ 536 buf[PB(2)] = p->audio_frame[2] & 0x1c; /* SF */
537 buf[PB(4)] = p->audio_frame[4]; 537 buf[PB(4)] = p->audio_frame[4];
@@ -824,6 +824,11 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
824 } 824 }
825 825
826 div = 148500 / mode->clock; 826 div = 148500 / mode->clock;
827 if (div != 0) {
828 div--;
829 if (div > 3)
830 div = 3;
831 }
827 832
828 /* mute the audio FIFO: */ 833 /* mute the audio FIFO: */
829 reg_set(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO); 834 reg_set(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO);
@@ -913,7 +918,7 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
913 918
914 if (priv->rev == TDA19988) { 919 if (priv->rev == TDA19988) {
915 /* let incoming pixels fill the active space (if any) */ 920 /* let incoming pixels fill the active space (if any) */
916 reg_write(encoder, REG_ENABLE_SPACE, 0x01); 921 reg_write(encoder, REG_ENABLE_SPACE, 0x00);
917 } 922 }
918 923
919 /* must be last register set: */ 924 /* must be last register set: */
@@ -1094,6 +1099,8 @@ tda998x_encoder_destroy(struct drm_encoder *encoder)
1094{ 1099{
1095 struct tda998x_priv *priv = to_tda998x_priv(encoder); 1100 struct tda998x_priv *priv = to_tda998x_priv(encoder);
1096 drm_i2c_encoder_destroy(encoder); 1101 drm_i2c_encoder_destroy(encoder);
1102 if (priv->cec)
1103 i2c_unregister_device(priv->cec);
1097 kfree(priv); 1104 kfree(priv);
1098} 1105}
1099 1106
@@ -1142,8 +1149,12 @@ tda998x_encoder_init(struct i2c_client *client,
1142 priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(0) | VIP_CNTRL_1_SWAP_D(1); 1149 priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(0) | VIP_CNTRL_1_SWAP_D(1);
1143 priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(4) | VIP_CNTRL_2_SWAP_F(5); 1150 priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(4) | VIP_CNTRL_2_SWAP_F(5);
1144 1151
1145 priv->current_page = 0; 1152 priv->current_page = 0xff;
1146 priv->cec = i2c_new_dummy(client->adapter, 0x34); 1153 priv->cec = i2c_new_dummy(client->adapter, 0x34);
1154 if (!priv->cec) {
1155 kfree(priv);
1156 return -ENODEV;
1157 }
1147 priv->dpms = DRM_MODE_DPMS_OFF; 1158 priv->dpms = DRM_MODE_DPMS_OFF;
1148 1159
1149 encoder_slave->slave_priv = priv; 1160 encoder_slave->slave_priv = priv;
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 04f1f02c4019..ec7bb0fc71bc 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -403,7 +403,7 @@ MODULE_DEVICE_TABLE(pci, pciidlist);
403void intel_detect_pch(struct drm_device *dev) 403void intel_detect_pch(struct drm_device *dev)
404{ 404{
405 struct drm_i915_private *dev_priv = dev->dev_private; 405 struct drm_i915_private *dev_priv = dev->dev_private;
406 struct pci_dev *pch; 406 struct pci_dev *pch = NULL;
407 407
408 /* In all current cases, num_pipes is equivalent to the PCH_NOP setting 408 /* In all current cases, num_pipes is equivalent to the PCH_NOP setting
409 * (which really amounts to a PCH but no South Display). 409 * (which really amounts to a PCH but no South Display).
@@ -424,12 +424,9 @@ void intel_detect_pch(struct drm_device *dev)
424 * all the ISA bridge devices and check for the first match, instead 424 * all the ISA bridge devices and check for the first match, instead
425 * of only checking the first one. 425 * of only checking the first one.
426 */ 426 */
427 pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); 427 while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) {
428 while (pch) {
429 struct pci_dev *curr = pch;
430 if (pch->vendor == PCI_VENDOR_ID_INTEL) { 428 if (pch->vendor == PCI_VENDOR_ID_INTEL) {
431 unsigned short id; 429 unsigned short id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
432 id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
433 dev_priv->pch_id = id; 430 dev_priv->pch_id = id;
434 431
435 if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) { 432 if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
@@ -461,18 +458,16 @@ void intel_detect_pch(struct drm_device *dev)
461 DRM_DEBUG_KMS("Found LynxPoint LP PCH\n"); 458 DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
462 WARN_ON(!IS_HASWELL(dev)); 459 WARN_ON(!IS_HASWELL(dev));
463 WARN_ON(!IS_ULT(dev)); 460 WARN_ON(!IS_ULT(dev));
464 } else { 461 } else
465 goto check_next; 462 continue;
466 } 463
467 pci_dev_put(pch);
468 break; 464 break;
469 } 465 }
470check_next:
471 pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, curr);
472 pci_dev_put(curr);
473 } 466 }
474 if (!pch) 467 if (!pch)
475 DRM_DEBUG_KMS("No PCH found?\n"); 468 DRM_DEBUG_KMS("No PCH found.\n");
469
470 pci_dev_put(pch);
476} 471}
477 472
478bool i915_semaphore_is_enabled(struct drm_device *dev) 473bool i915_semaphore_is_enabled(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 4a2bf8e3f739..df77e20e3c3d 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1831,6 +1831,14 @@ struct drm_i915_file_private {
1831 1831
1832/* Early gen2 have a totally busted CS tlb and require pinned batches. */ 1832/* Early gen2 have a totally busted CS tlb and require pinned batches. */
1833#define HAS_BROKEN_CS_TLB(dev) (IS_I830(dev) || IS_845G(dev)) 1833#define HAS_BROKEN_CS_TLB(dev) (IS_I830(dev) || IS_845G(dev))
1834/*
1835 * dp aux and gmbus irq on gen4 seems to be able to generate legacy interrupts
1836 * even when in MSI mode. This results in spurious interrupt warnings if the
1837 * legacy irq no. is shared with another device. The kernel then disables that
1838 * interrupt source and so prevents the other device from working properly.
1839 */
1840#define HAS_AUX_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
1841#define HAS_GMBUS_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
1834 1842
1835/* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte 1843/* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
1836 * rows, which changed the alignment requirements and fence programming. 1844 * rows, which changed the alignment requirements and fence programming.
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 40a2b36b276b..d278be110805 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -842,7 +842,7 @@ void i915_gem_suspend_gtt_mappings(struct drm_device *dev)
842 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base, 842 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base,
843 dev_priv->gtt.base.start / PAGE_SIZE, 843 dev_priv->gtt.base.start / PAGE_SIZE,
844 dev_priv->gtt.base.total / PAGE_SIZE, 844 dev_priv->gtt.base.total / PAGE_SIZE,
845 false); 845 true);
846} 846}
847 847
848void i915_gem_restore_gtt_mappings(struct drm_device *dev) 848void i915_gem_restore_gtt_mappings(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c
index 1a24e84f2315..28d24caa49f3 100644
--- a/drivers/gpu/drm/i915/i915_gem_stolen.c
+++ b/drivers/gpu/drm/i915/i915_gem_stolen.c
@@ -82,9 +82,22 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
82 r = devm_request_mem_region(dev->dev, base, dev_priv->gtt.stolen_size, 82 r = devm_request_mem_region(dev->dev, base, dev_priv->gtt.stolen_size,
83 "Graphics Stolen Memory"); 83 "Graphics Stolen Memory");
84 if (r == NULL) { 84 if (r == NULL) {
85 DRM_ERROR("conflict detected with stolen region: [0x%08x - 0x%08x]\n", 85 /*
86 base, base + (uint32_t)dev_priv->gtt.stolen_size); 86 * One more attempt but this time requesting region from
87 base = 0; 87 * base + 1, as we have seen that this resolves the region
88 * conflict with the PCI Bus.
89 * This is a BIOS w/a: Some BIOS wrap stolen in the root
90 * PCI bus, but have an off-by-one error. Hence retry the
91 * reservation starting from 1 instead of 0.
92 */
93 r = devm_request_mem_region(dev->dev, base + 1,
94 dev_priv->gtt.stolen_size - 1,
95 "Graphics Stolen Memory");
96 if (r == NULL) {
97 DRM_ERROR("conflict detected with stolen region: [0x%08x - 0x%08x]\n",
98 base, base + (uint32_t)dev_priv->gtt.stolen_size);
99 base = 0;
100 }
88 } 101 }
89 102
90 return base; 103 return base;
@@ -201,6 +214,13 @@ int i915_gem_init_stolen(struct drm_device *dev)
201 struct drm_i915_private *dev_priv = dev->dev_private; 214 struct drm_i915_private *dev_priv = dev->dev_private;
202 int bios_reserved = 0; 215 int bios_reserved = 0;
203 216
217#ifdef CONFIG_INTEL_IOMMU
218 if (intel_iommu_gfx_mapped) {
219 DRM_INFO("DMAR active, disabling use of stolen memory\n");
220 return 0;
221 }
222#endif
223
204 if (dev_priv->gtt.stolen_size == 0) 224 if (dev_priv->gtt.stolen_size == 0)
205 return 0; 225 return 0;
206 226
diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
index d7fd2fd2f0a5..990cf8f43efd 100644
--- a/drivers/gpu/drm/i915/i915_gpu_error.c
+++ b/drivers/gpu/drm/i915/i915_gpu_error.c
@@ -146,7 +146,10 @@ static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
146 va_list tmp; 146 va_list tmp;
147 147
148 va_copy(tmp, args); 148 va_copy(tmp, args);
149 if (!__i915_error_seek(e, vsnprintf(NULL, 0, f, tmp))) 149 len = vsnprintf(NULL, 0, f, tmp);
150 va_end(tmp);
151
152 if (!__i915_error_seek(e, len))
150 return; 153 return;
151 } 154 }
152 155
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 17d8fcb1b6f7..d554169ac592 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -567,8 +567,7 @@ static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
567 567
568 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal; 568 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
569 } else { 569 } else {
570 enum transcoder cpu_transcoder = 570 enum transcoder cpu_transcoder = (enum transcoder) pipe;
571 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
572 u32 htotal; 571 u32 htotal;
573 572
574 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1; 573 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
@@ -619,33 +618,25 @@ static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
619 618
620/* raw reads, only for fast reads of display block, no need for forcewake etc. */ 619/* raw reads, only for fast reads of display block, no need for forcewake etc. */
621#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__)) 620#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
622#define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__))
623 621
624static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe) 622static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
625{ 623{
626 struct drm_i915_private *dev_priv = dev->dev_private; 624 struct drm_i915_private *dev_priv = dev->dev_private;
627 uint32_t status; 625 uint32_t status;
628 626 int reg;
629 if (INTEL_INFO(dev)->gen < 7) { 627
630 status = pipe == PIPE_A ? 628 if (INTEL_INFO(dev)->gen >= 8) {
631 DE_PIPEA_VBLANK : 629 status = GEN8_PIPE_VBLANK;
632 DE_PIPEB_VBLANK; 630 reg = GEN8_DE_PIPE_ISR(pipe);
631 } else if (INTEL_INFO(dev)->gen >= 7) {
632 status = DE_PIPE_VBLANK_IVB(pipe);
633 reg = DEISR;
633 } else { 634 } else {
634 switch (pipe) { 635 status = DE_PIPE_VBLANK(pipe);
635 default: 636 reg = DEISR;
636 case PIPE_A:
637 status = DE_PIPEA_VBLANK_IVB;
638 break;
639 case PIPE_B:
640 status = DE_PIPEB_VBLANK_IVB;
641 break;
642 case PIPE_C:
643 status = DE_PIPEC_VBLANK_IVB;
644 break;
645 }
646 } 637 }
647 638
648 return __raw_i915_read32(dev_priv, DEISR) & status; 639 return __raw_i915_read32(dev_priv, reg) & status;
649} 640}
650 641
651static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, 642static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
@@ -703,7 +694,28 @@ static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
703 else 694 else
704 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 695 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
705 696
706 if (HAS_PCH_SPLIT(dev)) { 697 if (HAS_DDI(dev)) {
698 /*
699 * On HSW HDMI outputs there seems to be a 2 line
700 * difference, whereas eDP has the normal 1 line
701 * difference that earlier platforms have. External
702 * DP is unknown. For now just check for the 2 line
703 * difference case on all output types on HSW+.
704 *
705 * This might misinterpret the scanline counter being
706 * one line too far along on eDP, but that's less
707 * dangerous than the alternative since that would lead
708 * the vblank timestamp code astray when it sees a
709 * scanline count before vblank_start during a vblank
710 * interrupt.
711 */
712 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
713 if ((in_vbl && (position == vbl_start - 2 ||
714 position == vbl_start - 1)) ||
715 (!in_vbl && (position == vbl_end - 2 ||
716 position == vbl_end - 1)))
717 position = (position + 2) % vtotal;
718 } else if (HAS_PCH_SPLIT(dev)) {
707 /* 719 /*
708 * The scanline counter increments at the leading edge 720 * The scanline counter increments at the leading edge
709 * of hsync, ie. it completely misses the active portion 721 * of hsync, ie. it completely misses the active portion
@@ -2770,10 +2782,9 @@ static void ibx_irq_postinstall(struct drm_device *dev)
2770 return; 2782 return;
2771 2783
2772 if (HAS_PCH_IBX(dev)) { 2784 if (HAS_PCH_IBX(dev)) {
2773 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER | 2785 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
2774 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
2775 } else { 2786 } else {
2776 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT; 2787 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
2777 2788
2778 I915_WRITE(SERR_INT, I915_READ(SERR_INT)); 2789 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2779 } 2790 }
@@ -2833,20 +2844,19 @@ static int ironlake_irq_postinstall(struct drm_device *dev)
2833 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 2844 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2834 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | 2845 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2835 DE_PLANEB_FLIP_DONE_IVB | 2846 DE_PLANEB_FLIP_DONE_IVB |
2836 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB | 2847 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
2837 DE_ERR_INT_IVB);
2838 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 2848 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2839 DE_PIPEA_VBLANK_IVB); 2849 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
2840 2850
2841 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); 2851 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2842 } else { 2852 } else {
2843 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 2853 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2844 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | 2854 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
2845 DE_AUX_CHANNEL_A | 2855 DE_AUX_CHANNEL_A |
2846 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2847 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE | 2856 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2848 DE_POISON); 2857 DE_POISON);
2849 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT; 2858 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
2859 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
2850 } 2860 }
2851 2861
2852 dev_priv->irq_mask = ~display_mask; 2862 dev_priv->irq_mask = ~display_mask;
@@ -2962,9 +2972,9 @@ static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
2962 struct drm_device *dev = dev_priv->dev; 2972 struct drm_device *dev = dev_priv->dev;
2963 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE | 2973 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
2964 GEN8_PIPE_CDCLK_CRC_DONE | 2974 GEN8_PIPE_CDCLK_CRC_DONE |
2965 GEN8_PIPE_FIFO_UNDERRUN |
2966 GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 2975 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2967 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK; 2976 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
2977 GEN8_PIPE_FIFO_UNDERRUN;
2968 int pipe; 2978 int pipe;
2969 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; 2979 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
2970 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; 2980 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index e06b9e017d6b..234ac5f7bc5a 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -1244,6 +1244,7 @@ static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
1244 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { 1244 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
1245 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1245 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1246 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); 1246 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
1247 ironlake_edp_panel_vdd_on(intel_dp);
1247 ironlake_edp_panel_off(intel_dp); 1248 ironlake_edp_panel_off(intel_dp);
1248 } 1249 }
1249 1250
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 9fa24347963a..9b8a7c7ea7fc 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -1092,12 +1092,12 @@ static void assert_cursor(struct drm_i915_private *dev_priv,
1092 struct drm_device *dev = dev_priv->dev; 1092 struct drm_device *dev = dev_priv->dev;
1093 bool cur_state; 1093 bool cur_state;
1094 1094
1095 if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) 1095 if (IS_845G(dev) || IS_I865G(dev))
1096 cur_state = I915_READ(CURCNTR_IVB(pipe)) & CURSOR_MODE;
1097 else if (IS_845G(dev) || IS_I865G(dev))
1098 cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; 1096 cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
1099 else 1097 else if (INTEL_INFO(dev)->gen <= 6 || IS_VALLEYVIEW(dev))
1100 cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; 1098 cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
1099 else
1100 cur_state = I915_READ(CURCNTR_IVB(pipe)) & CURSOR_MODE;
1101 1101
1102 WARN(cur_state != state, 1102 WARN(cur_state != state,
1103 "cursor on pipe %c assertion failure (expected %s, current %s)\n", 1103 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
@@ -8586,6 +8586,20 @@ static int intel_gen7_queue_flip(struct drm_device *dev,
8586 if (ring->id == RCS) 8586 if (ring->id == RCS)
8587 len += 6; 8587 len += 6;
8588 8588
8589 /*
8590 * BSpec MI_DISPLAY_FLIP for IVB:
8591 * "The full packet must be contained within the same cache line."
8592 *
8593 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
8594 * cacheline, if we ever start emitting more commands before
8595 * the MI_DISPLAY_FLIP we may need to first emit everything else,
8596 * then do the cacheline alignment, and finally emit the
8597 * MI_DISPLAY_FLIP.
8598 */
8599 ret = intel_ring_cacheline_align(ring);
8600 if (ret)
8601 goto err_unpin;
8602
8589 ret = intel_ring_begin(ring, len); 8603 ret = intel_ring_begin(ring, len);
8590 if (ret) 8604 if (ret)
8591 goto err_unpin; 8605 goto err_unpin;
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 5ede4e8e290d..2688f6d64bb9 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -404,7 +404,7 @@ intel_dp_aux_ch(struct intel_dp *intel_dp,
404 int i, ret, recv_bytes; 404 int i, ret, recv_bytes;
405 uint32_t status; 405 uint32_t status;
406 int try, precharge, clock = 0; 406 int try, precharge, clock = 0;
407 bool has_aux_irq = true; 407 bool has_aux_irq = HAS_AUX_IRQ(dev);
408 uint32_t timeout; 408 uint32_t timeout;
409 409
410 /* dp aux is extremely sensitive to irq latency, hence request the 410 /* dp aux is extremely sensitive to irq latency, hence request the
@@ -537,6 +537,7 @@ intel_dp_aux_native_write(struct intel_dp *intel_dp,
537 uint8_t msg[20]; 537 uint8_t msg[20];
538 int msg_bytes; 538 int msg_bytes;
539 uint8_t ack; 539 uint8_t ack;
540 int retry;
540 541
541 if (WARN_ON(send_bytes > 16)) 542 if (WARN_ON(send_bytes > 16))
542 return -E2BIG; 543 return -E2BIG;
@@ -548,19 +549,21 @@ intel_dp_aux_native_write(struct intel_dp *intel_dp,
548 msg[3] = send_bytes - 1; 549 msg[3] = send_bytes - 1;
549 memcpy(&msg[4], send, send_bytes); 550 memcpy(&msg[4], send, send_bytes);
550 msg_bytes = send_bytes + 4; 551 msg_bytes = send_bytes + 4;
551 for (;;) { 552 for (retry = 0; retry < 7; retry++) {
552 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1); 553 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
553 if (ret < 0) 554 if (ret < 0)
554 return ret; 555 return ret;
555 ack >>= 4; 556 ack >>= 4;
556 if ((ack & DP_AUX_NATIVE_REPLY_MASK) == DP_AUX_NATIVE_REPLY_ACK) 557 if ((ack & DP_AUX_NATIVE_REPLY_MASK) == DP_AUX_NATIVE_REPLY_ACK)
557 break; 558 return send_bytes;
558 else if ((ack & DP_AUX_NATIVE_REPLY_MASK) == DP_AUX_NATIVE_REPLY_DEFER) 559 else if ((ack & DP_AUX_NATIVE_REPLY_MASK) == DP_AUX_NATIVE_REPLY_DEFER)
559 udelay(100); 560 usleep_range(400, 500);
560 else 561 else
561 return -EIO; 562 return -EIO;
562 } 563 }
563 return send_bytes; 564
565 DRM_ERROR("too many retries, giving up\n");
566 return -EIO;
564} 567}
565 568
566/* Write a single byte to the aux channel in native mode */ 569/* Write a single byte to the aux channel in native mode */
@@ -582,6 +585,7 @@ intel_dp_aux_native_read(struct intel_dp *intel_dp,
582 int reply_bytes; 585 int reply_bytes;
583 uint8_t ack; 586 uint8_t ack;
584 int ret; 587 int ret;
588 int retry;
585 589
586 if (WARN_ON(recv_bytes > 19)) 590 if (WARN_ON(recv_bytes > 19))
587 return -E2BIG; 591 return -E2BIG;
@@ -595,7 +599,7 @@ intel_dp_aux_native_read(struct intel_dp *intel_dp,
595 msg_bytes = 4; 599 msg_bytes = 4;
596 reply_bytes = recv_bytes + 1; 600 reply_bytes = recv_bytes + 1;
597 601
598 for (;;) { 602 for (retry = 0; retry < 7; retry++) {
599 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, 603 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
600 reply, reply_bytes); 604 reply, reply_bytes);
601 if (ret == 0) 605 if (ret == 0)
@@ -608,10 +612,13 @@ intel_dp_aux_native_read(struct intel_dp *intel_dp,
608 return ret - 1; 612 return ret - 1;
609 } 613 }
610 else if ((ack & DP_AUX_NATIVE_REPLY_MASK) == DP_AUX_NATIVE_REPLY_DEFER) 614 else if ((ack & DP_AUX_NATIVE_REPLY_MASK) == DP_AUX_NATIVE_REPLY_DEFER)
611 udelay(100); 615 usleep_range(400, 500);
612 else 616 else
613 return -EIO; 617 return -EIO;
614 } 618 }
619
620 DRM_ERROR("too many retries, giving up\n");
621 return -EIO;
615} 622}
616 623
617static int 624static int
@@ -1242,17 +1249,24 @@ void ironlake_edp_panel_off(struct intel_dp *intel_dp)
1242 1249
1243 DRM_DEBUG_KMS("Turn eDP power off\n"); 1250 DRM_DEBUG_KMS("Turn eDP power off\n");
1244 1251
1252 WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
1253
1245 pp = ironlake_get_pp_control(intel_dp); 1254 pp = ironlake_get_pp_control(intel_dp);
1246 /* We need to switch off panel power _and_ force vdd, for otherwise some 1255 /* We need to switch off panel power _and_ force vdd, for otherwise some
1247 * panels get very unhappy and cease to work. */ 1256 * panels get very unhappy and cease to work. */
1248 pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_BLC_ENABLE); 1257 pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
1249 1258
1250 pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 1259 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1251 1260
1252 I915_WRITE(pp_ctrl_reg, pp); 1261 I915_WRITE(pp_ctrl_reg, pp);
1253 POSTING_READ(pp_ctrl_reg); 1262 POSTING_READ(pp_ctrl_reg);
1254 1263
1264 intel_dp->want_panel_vdd = false;
1265
1255 ironlake_wait_panel_off(intel_dp); 1266 ironlake_wait_panel_off(intel_dp);
1267
1268 /* We got a reference when we enabled the VDD. */
1269 intel_runtime_pm_put(dev_priv);
1256} 1270}
1257 1271
1258void ironlake_edp_backlight_on(struct intel_dp *intel_dp) 1272void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
@@ -1632,7 +1646,7 @@ static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
1632 val |= EDP_PSR_LINK_DISABLE; 1646 val |= EDP_PSR_LINK_DISABLE;
1633 1647
1634 I915_WRITE(EDP_PSR_CTL(dev), val | 1648 I915_WRITE(EDP_PSR_CTL(dev), val |
1635 IS_BROADWELL(dev) ? 0 : link_entry_time | 1649 (IS_BROADWELL(dev) ? 0 : link_entry_time) |
1636 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT | 1650 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
1637 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT | 1651 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
1638 EDP_PSR_ENABLE); 1652 EDP_PSR_ENABLE);
@@ -1777,6 +1791,7 @@ static void intel_disable_dp(struct intel_encoder *encoder)
1777 1791
1778 /* Make sure the panel is off before trying to change the mode. But also 1792 /* Make sure the panel is off before trying to change the mode. But also
1779 * ensure that we have vdd while we switch off the panel. */ 1793 * ensure that we have vdd while we switch off the panel. */
1794 ironlake_edp_panel_vdd_on(intel_dp);
1780 ironlake_edp_backlight_off(intel_dp); 1795 ironlake_edp_backlight_off(intel_dp);
1781 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); 1796 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
1782 ironlake_edp_panel_off(intel_dp); 1797 ironlake_edp_panel_off(intel_dp);
@@ -1869,10 +1884,12 @@ static void vlv_pre_enable_dp(struct intel_encoder *encoder)
1869 1884
1870 mutex_unlock(&dev_priv->dpio_lock); 1885 mutex_unlock(&dev_priv->dpio_lock);
1871 1886
1872 /* init power sequencer on this pipe and port */ 1887 if (is_edp(intel_dp)) {
1873 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq); 1888 /* init power sequencer on this pipe and port */
1874 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, 1889 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
1875 &power_seq); 1890 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
1891 &power_seq);
1892 }
1876 1893
1877 intel_enable_dp(encoder); 1894 intel_enable_dp(encoder);
1878 1895
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 6db0d9d17f47..ee3181ebcc92 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -845,7 +845,7 @@ static int hdmi_portclock_limit(struct intel_hdmi *hdmi)
845{ 845{
846 struct drm_device *dev = intel_hdmi_to_dev(hdmi); 846 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
847 847
848 if (IS_G4X(dev)) 848 if (!hdmi->has_hdmi_sink || IS_G4X(dev))
849 return 165000; 849 return 165000;
850 else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8) 850 else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8)
851 return 300000; 851 return 300000;
@@ -899,8 +899,8 @@ bool intel_hdmi_compute_config(struct intel_encoder *encoder,
899 * outputs. We also need to check that the higher clock still fits 899 * outputs. We also need to check that the higher clock still fits
900 * within limits. 900 * within limits.
901 */ 901 */
902 if (pipe_config->pipe_bpp > 8*3 && clock_12bpc <= portclock_limit 902 if (pipe_config->pipe_bpp > 8*3 && intel_hdmi->has_hdmi_sink &&
903 && HAS_PCH_SPLIT(dev)) { 903 clock_12bpc <= portclock_limit && HAS_PCH_SPLIT(dev)) {
904 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n"); 904 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
905 desired_bpp = 12*3; 905 desired_bpp = 12*3;
906 906
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index b1dc33f47899..d33b61d0dd33 100644
--- a/drivers/gpu/drm/i915/intel_i2c.c
+++ b/drivers/gpu/drm/i915/intel_i2c.c
@@ -258,13 +258,6 @@ intel_gpio_setup(struct intel_gmbus *bus, u32 pin)
258 algo->data = bus; 258 algo->data = bus;
259} 259}
260 260
261/*
262 * gmbus on gen4 seems to be able to generate legacy interrupts even when in MSI
263 * mode. This results in spurious interrupt warnings if the legacy irq no. is
264 * shared with another device. The kernel then disables that interrupt source
265 * and so prevents the other device from working properly.
266 */
267#define HAS_GMBUS_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
268static int 261static int
269gmbus_wait_hw_status(struct drm_i915_private *dev_priv, 262gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
270 u32 gmbus2_status, 263 u32 gmbus2_status,
diff --git a/drivers/gpu/drm/i915/intel_opregion.c b/drivers/gpu/drm/i915/intel_opregion.c
index 4e960ec7419f..acde2945eb8a 100644
--- a/drivers/gpu/drm/i915/intel_opregion.c
+++ b/drivers/gpu/drm/i915/intel_opregion.c
@@ -226,6 +226,8 @@ struct opregion_asle {
226#define ACPI_DIGITAL_OUTPUT (3<<8) 226#define ACPI_DIGITAL_OUTPUT (3<<8)
227#define ACPI_LVDS_OUTPUT (4<<8) 227#define ACPI_LVDS_OUTPUT (4<<8)
228 228
229#define MAX_DSLP 1500
230
229#ifdef CONFIG_ACPI 231#ifdef CONFIG_ACPI
230static int swsci(struct drm_device *dev, u32 function, u32 parm, u32 *parm_out) 232static int swsci(struct drm_device *dev, u32 function, u32 parm, u32 *parm_out)
231{ 233{
@@ -260,10 +262,11 @@ static int swsci(struct drm_device *dev, u32 function, u32 parm, u32 *parm_out)
260 /* The spec says 2ms should be the default, but it's too small 262 /* The spec says 2ms should be the default, but it's too small
261 * for some machines. */ 263 * for some machines. */
262 dslp = 50; 264 dslp = 50;
263 } else if (dslp > 500) { 265 } else if (dslp > MAX_DSLP) {
264 /* Hey bios, trust must be earned. */ 266 /* Hey bios, trust must be earned. */
265 WARN_ONCE(1, "excessive driver sleep timeout (DSPL) %u\n", dslp); 267 DRM_INFO_ONCE("ACPI BIOS requests an excessive sleep of %u ms, "
266 dslp = 500; 268 "using %u ms instead\n", dslp, MAX_DSLP);
269 dslp = MAX_DSLP;
267 } 270 }
268 271
269 /* The spec tells us to do this, but we are the only user... */ 272 /* The spec tells us to do this, but we are the only user... */
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index 350de359123a..079ea38f14d9 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -698,7 +698,7 @@ static void i9xx_enable_backlight(struct intel_connector *connector)
698 freq /= 0xff; 698 freq /= 0xff;
699 699
700 ctl = freq << 17; 700 ctl = freq << 17;
701 if (IS_GEN2(dev) && panel->backlight.combination_mode) 701 if (panel->backlight.combination_mode)
702 ctl |= BLM_LEGACY_MODE; 702 ctl |= BLM_LEGACY_MODE;
703 if (IS_PINEVIEW(dev) && panel->backlight.active_low_pwm) 703 if (IS_PINEVIEW(dev) && panel->backlight.active_low_pwm)
704 ctl |= BLM_POLARITY_PNV; 704 ctl |= BLM_POLARITY_PNV;
@@ -979,7 +979,7 @@ static int i9xx_setup_backlight(struct intel_connector *connector)
979 979
980 ctl = I915_READ(BLC_PWM_CTL); 980 ctl = I915_READ(BLC_PWM_CTL);
981 981
982 if (IS_GEN2(dev)) 982 if (IS_GEN2(dev) || IS_I915GM(dev) || IS_I945GM(dev))
983 panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE; 983 panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE;
984 984
985 if (IS_PINEVIEW(dev)) 985 if (IS_PINEVIEW(dev))
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index d77cc81900f9..e1fc35a72656 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -3493,6 +3493,8 @@ static void valleyview_setup_pctx(struct drm_device *dev)
3493 u32 pcbr; 3493 u32 pcbr;
3494 int pctx_size = 24*1024; 3494 int pctx_size = 24*1024;
3495 3495
3496 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
3497
3496 pcbr = I915_READ(VLV_PCBR); 3498 pcbr = I915_READ(VLV_PCBR);
3497 if (pcbr) { 3499 if (pcbr) {
3498 /* BIOS set it up already, grab the pre-alloc'd space */ 3500 /* BIOS set it up already, grab the pre-alloc'd space */
@@ -3542,8 +3544,6 @@ static void valleyview_enable_rps(struct drm_device *dev)
3542 I915_WRITE(GTFIFODBG, gtfifodbg); 3544 I915_WRITE(GTFIFODBG, gtfifodbg);
3543 } 3545 }
3544 3546
3545 valleyview_setup_pctx(dev);
3546
3547 /* If VLV, Forcewake all wells, else re-direct to regular path */ 3547 /* If VLV, Forcewake all wells, else re-direct to regular path */
3548 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); 3548 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
3549 3549
@@ -4395,6 +4395,8 @@ void intel_enable_gt_powersave(struct drm_device *dev)
4395 ironlake_enable_rc6(dev); 4395 ironlake_enable_rc6(dev);
4396 intel_init_emon(dev); 4396 intel_init_emon(dev);
4397 } else if (IS_GEN6(dev) || IS_GEN7(dev)) { 4397 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
4398 if (IS_VALLEYVIEW(dev))
4399 valleyview_setup_pctx(dev);
4398 /* 4400 /*
4399 * PCU communication is slow and this doesn't need to be 4401 * PCU communication is slow and this doesn't need to be
4400 * done at any specific time, so do this out of our fast path 4402 * done at any specific time, so do this out of our fast path
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index b7f1742caf87..31b36c5ac894 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -1653,6 +1653,27 @@ int intel_ring_begin(struct intel_ring_buffer *ring,
1653 return 0; 1653 return 0;
1654} 1654}
1655 1655
1656/* Align the ring tail to a cacheline boundary */
1657int intel_ring_cacheline_align(struct intel_ring_buffer *ring)
1658{
1659 int num_dwords = (64 - (ring->tail & 63)) / sizeof(uint32_t);
1660 int ret;
1661
1662 if (num_dwords == 0)
1663 return 0;
1664
1665 ret = intel_ring_begin(ring, num_dwords);
1666 if (ret)
1667 return ret;
1668
1669 while (num_dwords--)
1670 intel_ring_emit(ring, MI_NOOP);
1671
1672 intel_ring_advance(ring);
1673
1674 return 0;
1675}
1676
1656void intel_ring_init_seqno(struct intel_ring_buffer *ring, u32 seqno) 1677void intel_ring_init_seqno(struct intel_ring_buffer *ring, u32 seqno)
1657{ 1678{
1658 struct drm_i915_private *dev_priv = ring->dev->dev_private; 1679 struct drm_i915_private *dev_priv = ring->dev->dev_private;
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 71a73f4fe252..0b243ce33714 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -233,6 +233,7 @@ intel_write_status_page(struct intel_ring_buffer *ring,
233void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring); 233void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
234 234
235int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n); 235int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n);
236int __must_check intel_ring_cacheline_align(struct intel_ring_buffer *ring);
236static inline void intel_ring_emit(struct intel_ring_buffer *ring, 237static inline void intel_ring_emit(struct intel_ring_buffer *ring,
237 u32 data) 238 u32 data)
238{ 239{
diff --git a/drivers/gpu/drm/mgag200/mgag200_fb.c b/drivers/gpu/drm/mgag200/mgag200_fb.c
index f9adc27ef32a..13b7dd83faa9 100644
--- a/drivers/gpu/drm/mgag200/mgag200_fb.c
+++ b/drivers/gpu/drm/mgag200/mgag200_fb.c
@@ -41,7 +41,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
41 * then the BO is being moved and we should 41 * then the BO is being moved and we should
42 * store up the damage until later. 42 * store up the damage until later.
43 */ 43 */
44 if (!drm_can_sleep()) 44 if (drm_can_sleep())
45 ret = mgag200_bo_reserve(bo, true); 45 ret = mgag200_bo_reserve(bo, true);
46 if (ret) { 46 if (ret) {
47 if (ret != -EBUSY) 47 if (ret != -EBUSY)
diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c
index b8583f275e80..968374776db9 100644
--- a/drivers/gpu/drm/mgag200/mgag200_mode.c
+++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
@@ -1519,11 +1519,11 @@ static int mga_vga_mode_valid(struct drm_connector *connector,
1519 (mga_vga_calculate_mode_bandwidth(mode, bpp) 1519 (mga_vga_calculate_mode_bandwidth(mode, bpp)
1520 > (32700 * 1024))) { 1520 > (32700 * 1024))) {
1521 return MODE_BANDWIDTH; 1521 return MODE_BANDWIDTH;
1522 } else if (mode->type == G200_EH && 1522 } else if (mdev->type == G200_EH &&
1523 (mga_vga_calculate_mode_bandwidth(mode, bpp) 1523 (mga_vga_calculate_mode_bandwidth(mode, bpp)
1524 > (37500 * 1024))) { 1524 > (37500 * 1024))) {
1525 return MODE_BANDWIDTH; 1525 return MODE_BANDWIDTH;
1526 } else if (mode->type == G200_ER && 1526 } else if (mdev->type == G200_ER &&
1527 (mga_vga_calculate_mode_bandwidth(mode, 1527 (mga_vga_calculate_mode_bandwidth(mode,
1528 bpp) > (55000 * 1024))) { 1528 bpp) > (55000 * 1024))) {
1529 return MODE_BANDWIDTH; 1529 return MODE_BANDWIDTH;
diff --git a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c
index 1964f4f0d452..84c5b13b33c9 100644
--- a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c
+++ b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c
@@ -39,6 +39,7 @@ struct mdp4_crtc {
39 spinlock_t lock; 39 spinlock_t lock;
40 bool stale; 40 bool stale;
41 uint32_t width, height; 41 uint32_t width, height;
42 uint32_t x, y;
42 43
43 /* next cursor to scan-out: */ 44 /* next cursor to scan-out: */
44 uint32_t next_iova; 45 uint32_t next_iova;
@@ -57,9 +58,16 @@ struct mdp4_crtc {
57#define PENDING_FLIP 0x2 58#define PENDING_FLIP 0x2
58 atomic_t pending; 59 atomic_t pending;
59 60
60 /* the fb that we currently hold a scanout ref to: */ 61 /* the fb that we logically (from PoV of KMS API) hold a ref
62 * to. Which we may not yet be scanning out (we may still
63 * be scanning out previous in case of page_flip while waiting
64 * for gpu rendering to complete:
65 */
61 struct drm_framebuffer *fb; 66 struct drm_framebuffer *fb;
62 67
68 /* the fb that we currently hold a scanout ref to: */
69 struct drm_framebuffer *scanout_fb;
70
63 /* for unref'ing framebuffers after scanout completes: */ 71 /* for unref'ing framebuffers after scanout completes: */
64 struct drm_flip_work unref_fb_work; 72 struct drm_flip_work unref_fb_work;
65 73
@@ -77,24 +85,73 @@ static struct mdp4_kms *get_kms(struct drm_crtc *crtc)
77 return to_mdp4_kms(to_mdp_kms(priv->kms)); 85 return to_mdp4_kms(to_mdp_kms(priv->kms));
78} 86}
79 87
80static void update_fb(struct drm_crtc *crtc, bool async, 88static void request_pending(struct drm_crtc *crtc, uint32_t pending)
81 struct drm_framebuffer *new_fb)
82{ 89{
83 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc); 90 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
84 struct drm_framebuffer *old_fb = mdp4_crtc->fb;
85 91
86 if (old_fb) 92 atomic_or(pending, &mdp4_crtc->pending);
87 drm_flip_work_queue(&mdp4_crtc->unref_fb_work, old_fb); 93 mdp_irq_register(&get_kms(crtc)->base, &mdp4_crtc->vblank);
94}
95
96static void crtc_flush(struct drm_crtc *crtc)
97{
98 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
99 struct mdp4_kms *mdp4_kms = get_kms(crtc);
100 uint32_t i, flush = 0;
101
102 for (i = 0; i < ARRAY_SIZE(mdp4_crtc->planes); i++) {
103 struct drm_plane *plane = mdp4_crtc->planes[i];
104 if (plane) {
105 enum mdp4_pipe pipe_id = mdp4_plane_pipe(plane);
106 flush |= pipe2flush(pipe_id);
107 }
108 }
109 flush |= ovlp2flush(mdp4_crtc->ovlp);
110
111 DBG("%s: flush=%08x", mdp4_crtc->name, flush);
112
113 mdp4_write(mdp4_kms, REG_MDP4_OVERLAY_FLUSH, flush);
114}
115
116static void update_fb(struct drm_crtc *crtc, struct drm_framebuffer *new_fb)
117{
118 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
119 struct drm_framebuffer *old_fb = mdp4_crtc->fb;
88 120
89 /* grab reference to incoming scanout fb: */ 121 /* grab reference to incoming scanout fb: */
90 drm_framebuffer_reference(new_fb); 122 drm_framebuffer_reference(new_fb);
91 mdp4_crtc->base.fb = new_fb; 123 mdp4_crtc->base.fb = new_fb;
92 mdp4_crtc->fb = new_fb; 124 mdp4_crtc->fb = new_fb;
93 125
94 if (!async) { 126 if (old_fb)
95 /* enable vblank to pick up the old_fb */ 127 drm_flip_work_queue(&mdp4_crtc->unref_fb_work, old_fb);
96 mdp_irq_register(&get_kms(crtc)->base, &mdp4_crtc->vblank); 128}
97 } 129
130/* unlike update_fb(), take a ref to the new scanout fb *before* updating
131 * plane, then call this. Needed to ensure we don't unref the buffer that
132 * is actually still being scanned out.
133 *
134 * Note that this whole thing goes away with atomic.. since we can defer
135 * calling into driver until rendering is done.
136 */
137static void update_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb)
138{
139 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
140
141 /* flush updates, to make sure hw is updated to new scanout fb,
142 * so that we can safely queue unref to current fb (ie. next
143 * vblank we know hw is done w/ previous scanout_fb).
144 */
145 crtc_flush(crtc);
146
147 if (mdp4_crtc->scanout_fb)
148 drm_flip_work_queue(&mdp4_crtc->unref_fb_work,
149 mdp4_crtc->scanout_fb);
150
151 mdp4_crtc->scanout_fb = fb;
152
153 /* enable vblank to complete flip: */
154 request_pending(crtc, PENDING_FLIP);
98} 155}
99 156
100/* if file!=NULL, this is preclose potential cancel-flip path */ 157/* if file!=NULL, this is preclose potential cancel-flip path */
@@ -120,34 +177,6 @@ static void complete_flip(struct drm_crtc *crtc, struct drm_file *file)
120 spin_unlock_irqrestore(&dev->event_lock, flags); 177 spin_unlock_irqrestore(&dev->event_lock, flags);
121} 178}
122 179
123static void crtc_flush(struct drm_crtc *crtc)
124{
125 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
126 struct mdp4_kms *mdp4_kms = get_kms(crtc);
127 uint32_t i, flush = 0;
128
129 for (i = 0; i < ARRAY_SIZE(mdp4_crtc->planes); i++) {
130 struct drm_plane *plane = mdp4_crtc->planes[i];
131 if (plane) {
132 enum mdp4_pipe pipe_id = mdp4_plane_pipe(plane);
133 flush |= pipe2flush(pipe_id);
134 }
135 }
136 flush |= ovlp2flush(mdp4_crtc->ovlp);
137
138 DBG("%s: flush=%08x", mdp4_crtc->name, flush);
139
140 mdp4_write(mdp4_kms, REG_MDP4_OVERLAY_FLUSH, flush);
141}
142
143static void request_pending(struct drm_crtc *crtc, uint32_t pending)
144{
145 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
146
147 atomic_or(pending, &mdp4_crtc->pending);
148 mdp_irq_register(&get_kms(crtc)->base, &mdp4_crtc->vblank);
149}
150
151static void pageflip_cb(struct msm_fence_cb *cb) 180static void pageflip_cb(struct msm_fence_cb *cb)
152{ 181{
153 struct mdp4_crtc *mdp4_crtc = 182 struct mdp4_crtc *mdp4_crtc =
@@ -158,11 +187,9 @@ static void pageflip_cb(struct msm_fence_cb *cb)
158 if (!fb) 187 if (!fb)
159 return; 188 return;
160 189
190 drm_framebuffer_reference(fb);
161 mdp4_plane_set_scanout(mdp4_crtc->plane, fb); 191 mdp4_plane_set_scanout(mdp4_crtc->plane, fb);
162 crtc_flush(crtc); 192 update_scanout(crtc, fb);
163
164 /* enable vblank to complete flip: */
165 request_pending(crtc, PENDING_FLIP);
166} 193}
167 194
168static void unref_fb_worker(struct drm_flip_work *work, void *val) 195static void unref_fb_worker(struct drm_flip_work *work, void *val)
@@ -320,6 +347,20 @@ static int mdp4_crtc_mode_set(struct drm_crtc *crtc,
320 mode->vsync_end, mode->vtotal, 347 mode->vsync_end, mode->vtotal,
321 mode->type, mode->flags); 348 mode->type, mode->flags);
322 349
350 /* grab extra ref for update_scanout() */
351 drm_framebuffer_reference(crtc->fb);
352
353 ret = mdp4_plane_mode_set(mdp4_crtc->plane, crtc, crtc->fb,
354 0, 0, mode->hdisplay, mode->vdisplay,
355 x << 16, y << 16,
356 mode->hdisplay << 16, mode->vdisplay << 16);
357 if (ret) {
358 drm_framebuffer_unreference(crtc->fb);
359 dev_err(crtc->dev->dev, "%s: failed to set mode on plane: %d\n",
360 mdp4_crtc->name, ret);
361 return ret;
362 }
363
323 mdp4_write(mdp4_kms, REG_MDP4_DMA_SRC_SIZE(dma), 364 mdp4_write(mdp4_kms, REG_MDP4_DMA_SRC_SIZE(dma),
324 MDP4_DMA_SRC_SIZE_WIDTH(mode->hdisplay) | 365 MDP4_DMA_SRC_SIZE_WIDTH(mode->hdisplay) |
325 MDP4_DMA_SRC_SIZE_HEIGHT(mode->vdisplay)); 366 MDP4_DMA_SRC_SIZE_HEIGHT(mode->vdisplay));
@@ -341,24 +382,15 @@ static int mdp4_crtc_mode_set(struct drm_crtc *crtc,
341 382
342 mdp4_write(mdp4_kms, REG_MDP4_OVLP_CFG(ovlp), 1); 383 mdp4_write(mdp4_kms, REG_MDP4_OVLP_CFG(ovlp), 1);
343 384
344 update_fb(crtc, false, crtc->fb);
345
346 ret = mdp4_plane_mode_set(mdp4_crtc->plane, crtc, crtc->fb,
347 0, 0, mode->hdisplay, mode->vdisplay,
348 x << 16, y << 16,
349 mode->hdisplay << 16, mode->vdisplay << 16);
350 if (ret) {
351 dev_err(crtc->dev->dev, "%s: failed to set mode on plane: %d\n",
352 mdp4_crtc->name, ret);
353 return ret;
354 }
355
356 if (dma == DMA_E) { 385 if (dma == DMA_E) {
357 mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(0), 0x00ff0000); 386 mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(0), 0x00ff0000);
358 mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(1), 0x00ff0000); 387 mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(1), 0x00ff0000);
359 mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(2), 0x00ff0000); 388 mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(2), 0x00ff0000);
360 } 389 }
361 390
391 update_fb(crtc, crtc->fb);
392 update_scanout(crtc, crtc->fb);
393
362 return 0; 394 return 0;
363} 395}
364 396
@@ -385,13 +417,24 @@ static int mdp4_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
385 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc); 417 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
386 struct drm_plane *plane = mdp4_crtc->plane; 418 struct drm_plane *plane = mdp4_crtc->plane;
387 struct drm_display_mode *mode = &crtc->mode; 419 struct drm_display_mode *mode = &crtc->mode;
420 int ret;
388 421
389 update_fb(crtc, false, crtc->fb); 422 /* grab extra ref for update_scanout() */
423 drm_framebuffer_reference(crtc->fb);
390 424
391 return mdp4_plane_mode_set(plane, crtc, crtc->fb, 425 ret = mdp4_plane_mode_set(plane, crtc, crtc->fb,
392 0, 0, mode->hdisplay, mode->vdisplay, 426 0, 0, mode->hdisplay, mode->vdisplay,
393 x << 16, y << 16, 427 x << 16, y << 16,
394 mode->hdisplay << 16, mode->vdisplay << 16); 428 mode->hdisplay << 16, mode->vdisplay << 16);
429 if (ret) {
430 drm_framebuffer_unreference(crtc->fb);
431 return ret;
432 }
433
434 update_fb(crtc, crtc->fb);
435 update_scanout(crtc, crtc->fb);
436
437 return 0;
395} 438}
396 439
397static void mdp4_crtc_load_lut(struct drm_crtc *crtc) 440static void mdp4_crtc_load_lut(struct drm_crtc *crtc)
@@ -419,7 +462,7 @@ static int mdp4_crtc_page_flip(struct drm_crtc *crtc,
419 mdp4_crtc->event = event; 462 mdp4_crtc->event = event;
420 spin_unlock_irqrestore(&dev->event_lock, flags); 463 spin_unlock_irqrestore(&dev->event_lock, flags);
421 464
422 update_fb(crtc, true, new_fb); 465 update_fb(crtc, new_fb);
423 466
424 return msm_gem_queue_inactive_cb(obj, &mdp4_crtc->pageflip_cb); 467 return msm_gem_queue_inactive_cb(obj, &mdp4_crtc->pageflip_cb);
425} 468}
@@ -442,12 +485,12 @@ static int mdp4_crtc_set_property(struct drm_crtc *crtc,
442static void update_cursor(struct drm_crtc *crtc) 485static void update_cursor(struct drm_crtc *crtc)
443{ 486{
444 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc); 487 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
488 struct mdp4_kms *mdp4_kms = get_kms(crtc);
445 enum mdp4_dma dma = mdp4_crtc->dma; 489 enum mdp4_dma dma = mdp4_crtc->dma;
446 unsigned long flags; 490 unsigned long flags;
447 491
448 spin_lock_irqsave(&mdp4_crtc->cursor.lock, flags); 492 spin_lock_irqsave(&mdp4_crtc->cursor.lock, flags);
449 if (mdp4_crtc->cursor.stale) { 493 if (mdp4_crtc->cursor.stale) {
450 struct mdp4_kms *mdp4_kms = get_kms(crtc);
451 struct drm_gem_object *next_bo = mdp4_crtc->cursor.next_bo; 494 struct drm_gem_object *next_bo = mdp4_crtc->cursor.next_bo;
452 struct drm_gem_object *prev_bo = mdp4_crtc->cursor.scanout_bo; 495 struct drm_gem_object *prev_bo = mdp4_crtc->cursor.scanout_bo;
453 uint32_t iova = mdp4_crtc->cursor.next_iova; 496 uint32_t iova = mdp4_crtc->cursor.next_iova;
@@ -479,6 +522,11 @@ static void update_cursor(struct drm_crtc *crtc)
479 mdp4_crtc->cursor.scanout_bo = next_bo; 522 mdp4_crtc->cursor.scanout_bo = next_bo;
480 mdp4_crtc->cursor.stale = false; 523 mdp4_crtc->cursor.stale = false;
481 } 524 }
525
526 mdp4_write(mdp4_kms, REG_MDP4_DMA_CURSOR_POS(dma),
527 MDP4_DMA_CURSOR_POS_X(mdp4_crtc->cursor.x) |
528 MDP4_DMA_CURSOR_POS_Y(mdp4_crtc->cursor.y));
529
482 spin_unlock_irqrestore(&mdp4_crtc->cursor.lock, flags); 530 spin_unlock_irqrestore(&mdp4_crtc->cursor.lock, flags);
483} 531}
484 532
@@ -530,6 +578,7 @@ static int mdp4_crtc_cursor_set(struct drm_crtc *crtc,
530 drm_gem_object_unreference_unlocked(old_bo); 578 drm_gem_object_unreference_unlocked(old_bo);
531 } 579 }
532 580
581 crtc_flush(crtc);
533 request_pending(crtc, PENDING_CURSOR); 582 request_pending(crtc, PENDING_CURSOR);
534 583
535 return 0; 584 return 0;
@@ -542,12 +591,15 @@ fail:
542static int mdp4_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) 591static int mdp4_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
543{ 592{
544 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc); 593 struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
545 struct mdp4_kms *mdp4_kms = get_kms(crtc); 594 unsigned long flags;
546 enum mdp4_dma dma = mdp4_crtc->dma;
547 595
548 mdp4_write(mdp4_kms, REG_MDP4_DMA_CURSOR_POS(dma), 596 spin_lock_irqsave(&mdp4_crtc->cursor.lock, flags);
549 MDP4_DMA_CURSOR_POS_X(x) | 597 mdp4_crtc->cursor.x = x;
550 MDP4_DMA_CURSOR_POS_Y(y)); 598 mdp4_crtc->cursor.y = y;
599 spin_unlock_irqrestore(&mdp4_crtc->cursor.lock, flags);
600
601 crtc_flush(crtc);
602 request_pending(crtc, PENDING_CURSOR);
551 603
552 return 0; 604 return 0;
553} 605}
@@ -713,6 +765,7 @@ struct drm_crtc *mdp4_crtc_init(struct drm_device *dev,
713 crtc = &mdp4_crtc->base; 765 crtc = &mdp4_crtc->base;
714 766
715 mdp4_crtc->plane = plane; 767 mdp4_crtc->plane = plane;
768 mdp4_crtc->id = id;
716 769
717 mdp4_crtc->ovlp = ovlp_id; 770 mdp4_crtc->ovlp = ovlp_id;
718 mdp4_crtc->dma = dma_id; 771 mdp4_crtc->dma = dma_id;
diff --git a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c
index 2406027200ec..1e893dd13859 100644
--- a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c
+++ b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c
@@ -170,8 +170,8 @@ int mdp4_plane_mode_set(struct drm_plane *plane,
170 MDP4_PIPE_DST_SIZE_HEIGHT(crtc_h)); 170 MDP4_PIPE_DST_SIZE_HEIGHT(crtc_h));
171 171
172 mdp4_write(mdp4_kms, REG_MDP4_PIPE_DST_XY(pipe), 172 mdp4_write(mdp4_kms, REG_MDP4_PIPE_DST_XY(pipe),
173 MDP4_PIPE_SRC_XY_X(crtc_x) | 173 MDP4_PIPE_DST_XY_X(crtc_x) |
174 MDP4_PIPE_SRC_XY_Y(crtc_y)); 174 MDP4_PIPE_DST_XY_Y(crtc_y));
175 175
176 mdp4_plane_set_scanout(plane, fb); 176 mdp4_plane_set_scanout(plane, fb);
177 177
diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
index 71a3b2345eb3..f2794021f086 100644
--- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
+++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
@@ -296,6 +296,7 @@ static int mdp5_crtc_mode_set(struct drm_crtc *crtc,
296 x << 16, y << 16, 296 x << 16, y << 16,
297 mode->hdisplay << 16, mode->vdisplay << 16); 297 mode->hdisplay << 16, mode->vdisplay << 16);
298 if (ret) { 298 if (ret) {
299 drm_framebuffer_unreference(crtc->fb);
299 dev_err(crtc->dev->dev, "%s: failed to set mode on plane: %d\n", 300 dev_err(crtc->dev->dev, "%s: failed to set mode on plane: %d\n",
300 mdp5_crtc->name, ret); 301 mdp5_crtc->name, ret);
301 return ret; 302 return ret;
@@ -343,11 +344,15 @@ static int mdp5_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
343 0, 0, mode->hdisplay, mode->vdisplay, 344 0, 0, mode->hdisplay, mode->vdisplay,
344 x << 16, y << 16, 345 x << 16, y << 16,
345 mode->hdisplay << 16, mode->vdisplay << 16); 346 mode->hdisplay << 16, mode->vdisplay << 16);
347 if (ret) {
348 drm_framebuffer_unreference(crtc->fb);
349 return ret;
350 }
346 351
347 update_fb(crtc, crtc->fb); 352 update_fb(crtc, crtc->fb);
348 update_scanout(crtc, crtc->fb); 353 update_scanout(crtc, crtc->fb);
349 354
350 return ret; 355 return 0;
351} 356}
352 357
353static void mdp5_crtc_load_lut(struct drm_crtc *crtc) 358static void mdp5_crtc_load_lut(struct drm_crtc *crtc)
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index d8d60c969ac7..3da8264d3039 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -644,7 +644,7 @@ struct drm_gem_object *msm_gem_new(struct drm_device *dev,
644 644
645fail: 645fail:
646 if (obj) 646 if (obj)
647 drm_gem_object_unreference_unlocked(obj); 647 drm_gem_object_unreference(obj);
648 648
649 return ERR_PTR(ret); 649 return ERR_PTR(ret);
650} 650}
diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c
index 5281d4bc37f7..5423e914e491 100644
--- a/drivers/gpu/drm/msm/msm_gem_submit.c
+++ b/drivers/gpu/drm/msm/msm_gem_submit.c
@@ -163,7 +163,7 @@ retry:
163 163
164 164
165 /* if locking succeeded, pin bo: */ 165 /* if locking succeeded, pin bo: */
166 ret = msm_gem_get_iova(&msm_obj->base, 166 ret = msm_gem_get_iova_locked(&msm_obj->base,
167 submit->gpu->id, &iova); 167 submit->gpu->id, &iova);
168 168
169 /* this would break the logic in the fail path.. there is no 169 /* this would break the logic in the fail path.. there is no
@@ -247,7 +247,7 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob
247 /* For now, just map the entire thing. Eventually we probably 247 /* For now, just map the entire thing. Eventually we probably
248 * to do it page-by-page, w/ kmap() if not vmap()d.. 248 * to do it page-by-page, w/ kmap() if not vmap()d..
249 */ 249 */
250 ptr = msm_gem_vaddr(&obj->base); 250 ptr = msm_gem_vaddr_locked(&obj->base);
251 251
252 if (IS_ERR(ptr)) { 252 if (IS_ERR(ptr)) {
253 ret = PTR_ERR(ptr); 253 ret = PTR_ERR(ptr);
@@ -307,14 +307,12 @@ static void submit_cleanup(struct msm_gem_submit *submit, bool fail)
307{ 307{
308 unsigned i; 308 unsigned i;
309 309
310 mutex_lock(&submit->dev->struct_mutex);
311 for (i = 0; i < submit->nr_bos; i++) { 310 for (i = 0; i < submit->nr_bos; i++) {
312 struct msm_gem_object *msm_obj = submit->bos[i].obj; 311 struct msm_gem_object *msm_obj = submit->bos[i].obj;
313 submit_unlock_unpin_bo(submit, i); 312 submit_unlock_unpin_bo(submit, i);
314 list_del_init(&msm_obj->submit_entry); 313 list_del_init(&msm_obj->submit_entry);
315 drm_gem_object_unreference(&msm_obj->base); 314 drm_gem_object_unreference(&msm_obj->base);
316 } 315 }
317 mutex_unlock(&submit->dev->struct_mutex);
318 316
319 ww_acquire_fini(&submit->ticket); 317 ww_acquire_fini(&submit->ticket);
320 kfree(submit); 318 kfree(submit);
@@ -342,6 +340,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
342 if (args->nr_cmds > MAX_CMDS) 340 if (args->nr_cmds > MAX_CMDS)
343 return -EINVAL; 341 return -EINVAL;
344 342
343 mutex_lock(&dev->struct_mutex);
344
345 submit = submit_create(dev, gpu, args->nr_bos); 345 submit = submit_create(dev, gpu, args->nr_bos);
346 if (!submit) { 346 if (!submit) {
347 ret = -ENOMEM; 347 ret = -ENOMEM;
@@ -410,5 +410,6 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
410out: 410out:
411 if (submit) 411 if (submit)
412 submit_cleanup(submit, !!ret); 412 submit_cleanup(submit, !!ret);
413 mutex_unlock(&dev->struct_mutex);
413 return ret; 414 return ret;
414} 415}
diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c
index 4ebce8be489d..0cfe3f426ee4 100644
--- a/drivers/gpu/drm/msm/msm_gpu.c
+++ b/drivers/gpu/drm/msm/msm_gpu.c
@@ -298,8 +298,6 @@ int msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
298 struct msm_drm_private *priv = dev->dev_private; 298 struct msm_drm_private *priv = dev->dev_private;
299 int i, ret; 299 int i, ret;
300 300
301 mutex_lock(&dev->struct_mutex);
302
303 submit->fence = ++priv->next_fence; 301 submit->fence = ++priv->next_fence;
304 302
305 gpu->submitted_fence = submit->fence; 303 gpu->submitted_fence = submit->fence;
@@ -331,7 +329,6 @@ int msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
331 msm_gem_move_to_active(&msm_obj->base, gpu, true, submit->fence); 329 msm_gem_move_to_active(&msm_obj->base, gpu, true, submit->fence);
332 } 330 }
333 hangcheck_timer_reset(gpu); 331 hangcheck_timer_reset(gpu);
334 mutex_unlock(&dev->struct_mutex);
335 332
336 return ret; 333 return ret;
337} 334}
diff --git a/drivers/gpu/drm/nouveau/Makefile b/drivers/gpu/drm/nouveau/Makefile
index e88145ba1bf5..d310c195bdfe 100644
--- a/drivers/gpu/drm/nouveau/Makefile
+++ b/drivers/gpu/drm/nouveau/Makefile
@@ -141,6 +141,7 @@ nouveau-y += core/subdev/mc/base.o
141nouveau-y += core/subdev/mc/nv04.o 141nouveau-y += core/subdev/mc/nv04.o
142nouveau-y += core/subdev/mc/nv40.o 142nouveau-y += core/subdev/mc/nv40.o
143nouveau-y += core/subdev/mc/nv44.o 143nouveau-y += core/subdev/mc/nv44.o
144nouveau-y += core/subdev/mc/nv4c.o
144nouveau-y += core/subdev/mc/nv50.o 145nouveau-y += core/subdev/mc/nv50.o
145nouveau-y += core/subdev/mc/nv94.o 146nouveau-y += core/subdev/mc/nv94.o
146nouveau-y += core/subdev/mc/nv98.o 147nouveau-y += core/subdev/mc/nv98.o
diff --git a/drivers/gpu/drm/nouveau/core/engine/device/nv40.c b/drivers/gpu/drm/nouveau/core/engine/device/nv40.c
index 1b653dd74a70..08b88591ed60 100644
--- a/drivers/gpu/drm/nouveau/core/engine/device/nv40.c
+++ b/drivers/gpu/drm/nouveau/core/engine/device/nv40.c
@@ -311,7 +311,7 @@ nv40_identify(struct nouveau_device *device)
311 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass; 311 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass;
312 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass; 312 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass;
313 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass; 313 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass;
314 device->oclass[NVDEV_SUBDEV_MC ] = nv44_mc_oclass; 314 device->oclass[NVDEV_SUBDEV_MC ] = nv4c_mc_oclass;
315 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass; 315 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass;
316 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass; 316 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass;
317 device->oclass[NVDEV_SUBDEV_FB ] = nv46_fb_oclass; 317 device->oclass[NVDEV_SUBDEV_FB ] = nv46_fb_oclass;
@@ -334,7 +334,7 @@ nv40_identify(struct nouveau_device *device)
334 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass; 334 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass;
335 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass; 335 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass;
336 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass; 336 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass;
337 device->oclass[NVDEV_SUBDEV_MC ] = nv44_mc_oclass; 337 device->oclass[NVDEV_SUBDEV_MC ] = nv4c_mc_oclass;
338 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass; 338 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass;
339 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass; 339 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass;
340 device->oclass[NVDEV_SUBDEV_FB ] = nv4e_fb_oclass; 340 device->oclass[NVDEV_SUBDEV_FB ] = nv4e_fb_oclass;
@@ -357,7 +357,7 @@ nv40_identify(struct nouveau_device *device)
357 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass; 357 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass;
358 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass; 358 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass;
359 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass; 359 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass;
360 device->oclass[NVDEV_SUBDEV_MC ] = nv44_mc_oclass; 360 device->oclass[NVDEV_SUBDEV_MC ] = nv4c_mc_oclass;
361 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass; 361 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass;
362 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass; 362 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass;
363 device->oclass[NVDEV_SUBDEV_FB ] = nv46_fb_oclass; 363 device->oclass[NVDEV_SUBDEV_FB ] = nv46_fb_oclass;
@@ -380,7 +380,7 @@ nv40_identify(struct nouveau_device *device)
380 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass; 380 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass;
381 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass; 381 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass;
382 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass; 382 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass;
383 device->oclass[NVDEV_SUBDEV_MC ] = nv44_mc_oclass; 383 device->oclass[NVDEV_SUBDEV_MC ] = nv4c_mc_oclass;
384 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass; 384 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass;
385 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass; 385 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass;
386 device->oclass[NVDEV_SUBDEV_FB ] = nv46_fb_oclass; 386 device->oclass[NVDEV_SUBDEV_FB ] = nv46_fb_oclass;
@@ -403,7 +403,7 @@ nv40_identify(struct nouveau_device *device)
403 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass; 403 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv40_clock_oclass;
404 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass; 404 device->oclass[NVDEV_SUBDEV_THERM ] = &nv40_therm_oclass;
405 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass; 405 device->oclass[NVDEV_SUBDEV_DEVINIT] = nv1a_devinit_oclass;
406 device->oclass[NVDEV_SUBDEV_MC ] = nv44_mc_oclass; 406 device->oclass[NVDEV_SUBDEV_MC ] = nv4c_mc_oclass;
407 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass; 407 device->oclass[NVDEV_SUBDEV_BUS ] = nv31_bus_oclass;
408 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass; 408 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass;
409 device->oclass[NVDEV_SUBDEV_FB ] = nv46_fb_oclass; 409 device->oclass[NVDEV_SUBDEV_FB ] = nv46_fb_oclass;
diff --git a/drivers/gpu/drm/nouveau/core/engine/disp/nv50.c b/drivers/gpu/drm/nouveau/core/engine/disp/nv50.c
index 940eaa5d8b9a..9ad722e4e087 100644
--- a/drivers/gpu/drm/nouveau/core/engine/disp/nv50.c
+++ b/drivers/gpu/drm/nouveau/core/engine/disp/nv50.c
@@ -1142,7 +1142,7 @@ nv50_disp_intr_unk20_2(struct nv50_disp_priv *priv, int head)
1142 if (conf != ~0) { 1142 if (conf != ~0) {
1143 if (outp.location == 0 && outp.type == DCB_OUTPUT_DP) { 1143 if (outp.location == 0 && outp.type == DCB_OUTPUT_DP) {
1144 u32 soff = (ffs(outp.or) - 1) * 0x08; 1144 u32 soff = (ffs(outp.or) - 1) * 0x08;
1145 u32 ctrl = nv_rd32(priv, 0x610798 + soff); 1145 u32 ctrl = nv_rd32(priv, 0x610794 + soff);
1146 u32 datarate; 1146 u32 datarate;
1147 1147
1148 switch ((ctrl & 0x000f0000) >> 16) { 1148 switch ((ctrl & 0x000f0000) >> 16) {
diff --git a/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c b/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c
index 9a850fe19515..54c1b5b471cd 100644
--- a/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c
+++ b/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c
@@ -112,7 +112,7 @@ nve0_fifo_runlist_update(struct nve0_fifo_priv *priv, u32 engine)
112 112
113 nv_wr32(priv, 0x002270, cur->addr >> 12); 113 nv_wr32(priv, 0x002270, cur->addr >> 12);
114 nv_wr32(priv, 0x002274, (engine << 20) | (p >> 3)); 114 nv_wr32(priv, 0x002274, (engine << 20) | (p >> 3));
115 if (!nv_wait(priv, 0x002284 + (engine * 4), 0x00100000, 0x00000000)) 115 if (!nv_wait(priv, 0x002284 + (engine * 8), 0x00100000, 0x00000000))
116 nv_error(priv, "runlist %d update timeout\n", engine); 116 nv_error(priv, "runlist %d update timeout\n", engine);
117 mutex_unlock(&nv_subdev(priv)->mutex); 117 mutex_unlock(&nv_subdev(priv)->mutex);
118} 118}
diff --git a/drivers/gpu/drm/nouveau/core/engine/graph/nv50.c b/drivers/gpu/drm/nouveau/core/engine/graph/nv50.c
index 30ed19c52e05..7a367c402978 100644
--- a/drivers/gpu/drm/nouveau/core/engine/graph/nv50.c
+++ b/drivers/gpu/drm/nouveau/core/engine/graph/nv50.c
@@ -539,7 +539,7 @@ nv50_priv_tp_trap(struct nv50_graph_priv *priv, int type, u32 ustatus_old,
539 ustatus &= ~0x04030000; 539 ustatus &= ~0x04030000;
540 } 540 }
541 if (ustatus && display) { 541 if (ustatus && display) {
542 nv_error("%s - TP%d:", name, i); 542 nv_error(priv, "%s - TP%d:", name, i);
543 nouveau_bitfield_print(nv50_mpc_traps, ustatus); 543 nouveau_bitfield_print(nv50_mpc_traps, ustatus);
544 pr_cont("\n"); 544 pr_cont("\n");
545 ustatus = 0; 545 ustatus = 0;
diff --git a/drivers/gpu/drm/nouveau/core/include/subdev/mc.h b/drivers/gpu/drm/nouveau/core/include/subdev/mc.h
index adc88b73d911..3c6738edd127 100644
--- a/drivers/gpu/drm/nouveau/core/include/subdev/mc.h
+++ b/drivers/gpu/drm/nouveau/core/include/subdev/mc.h
@@ -47,6 +47,7 @@ struct nouveau_mc_oclass {
47extern struct nouveau_oclass *nv04_mc_oclass; 47extern struct nouveau_oclass *nv04_mc_oclass;
48extern struct nouveau_oclass *nv40_mc_oclass; 48extern struct nouveau_oclass *nv40_mc_oclass;
49extern struct nouveau_oclass *nv44_mc_oclass; 49extern struct nouveau_oclass *nv44_mc_oclass;
50extern struct nouveau_oclass *nv4c_mc_oclass;
50extern struct nouveau_oclass *nv50_mc_oclass; 51extern struct nouveau_oclass *nv50_mc_oclass;
51extern struct nouveau_oclass *nv94_mc_oclass; 52extern struct nouveau_oclass *nv94_mc_oclass;
52extern struct nouveau_oclass *nv98_mc_oclass; 53extern struct nouveau_oclass *nv98_mc_oclass;
diff --git a/drivers/gpu/drm/nouveau/core/subdev/bios/base.c b/drivers/gpu/drm/nouveau/core/subdev/bios/base.c
index aa0fbbec7f08..ef0c9c4a8cc3 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/bios/base.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/bios/base.c
@@ -130,6 +130,10 @@ nouveau_bios_shadow_prom(struct nouveau_bios *bios)
130 u16 pcir; 130 u16 pcir;
131 int i; 131 int i;
132 132
133 /* there is no prom on nv4x IGP's */
134 if (device->card_type == NV_40 && device->chipset >= 0x4c)
135 return;
136
133 /* enable access to rom */ 137 /* enable access to rom */
134 if (device->card_type >= NV_50) 138 if (device->card_type >= NV_50)
135 pcireg = 0x088050; 139 pcireg = 0x088050;
diff --git a/drivers/gpu/drm/nouveau/core/subdev/fb/nv1a.c b/drivers/gpu/drm/nouveau/core/subdev/fb/nv1a.c
index 9159a5ccee93..265d1253624a 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/fb/nv1a.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/fb/nv1a.c
@@ -36,7 +36,7 @@ nv1a_fb_oclass = &(struct nv04_fb_impl) {
36 .fini = _nouveau_fb_fini, 36 .fini = _nouveau_fb_fini,
37 }, 37 },
38 .base.memtype = nv04_fb_memtype_valid, 38 .base.memtype = nv04_fb_memtype_valid,
39 .base.ram = &nv10_ram_oclass, 39 .base.ram = &nv1a_ram_oclass,
40 .tile.regions = 8, 40 .tile.regions = 8,
41 .tile.init = nv10_fb_tile_init, 41 .tile.init = nv10_fb_tile_init,
42 .tile.fini = nv10_fb_tile_fini, 42 .tile.fini = nv10_fb_tile_fini,
diff --git a/drivers/gpu/drm/nouveau/core/subdev/mc/nv04.h b/drivers/gpu/drm/nouveau/core/subdev/mc/nv04.h
index b0d5c31606c1..81a408e7d034 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/mc/nv04.h
+++ b/drivers/gpu/drm/nouveau/core/subdev/mc/nv04.h
@@ -14,6 +14,7 @@ int nv04_mc_ctor(struct nouveau_object *, struct nouveau_object *,
14extern const struct nouveau_mc_intr nv04_mc_intr[]; 14extern const struct nouveau_mc_intr nv04_mc_intr[];
15int nv04_mc_init(struct nouveau_object *); 15int nv04_mc_init(struct nouveau_object *);
16void nv40_mc_msi_rearm(struct nouveau_mc *); 16void nv40_mc_msi_rearm(struct nouveau_mc *);
17int nv44_mc_init(struct nouveau_object *object);
17int nv50_mc_init(struct nouveau_object *); 18int nv50_mc_init(struct nouveau_object *);
18extern const struct nouveau_mc_intr nv50_mc_intr[]; 19extern const struct nouveau_mc_intr nv50_mc_intr[];
19extern const struct nouveau_mc_intr nvc0_mc_intr[]; 20extern const struct nouveau_mc_intr nvc0_mc_intr[];
diff --git a/drivers/gpu/drm/nouveau/core/subdev/mc/nv44.c b/drivers/gpu/drm/nouveau/core/subdev/mc/nv44.c
index 3bfee5c6c4f2..cc4d0d2d886e 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/mc/nv44.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/mc/nv44.c
@@ -24,7 +24,7 @@
24 24
25#include "nv04.h" 25#include "nv04.h"
26 26
27static int 27int
28nv44_mc_init(struct nouveau_object *object) 28nv44_mc_init(struct nouveau_object *object)
29{ 29{
30 struct nv04_mc_priv *priv = (void *)object; 30 struct nv04_mc_priv *priv = (void *)object;
diff --git a/drivers/gpu/drm/nouveau/core/subdev/mc/nv4c.c b/drivers/gpu/drm/nouveau/core/subdev/mc/nv4c.c
new file mode 100644
index 000000000000..a75c35ccf25c
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/core/subdev/mc/nv4c.c
@@ -0,0 +1,45 @@
1/*
2 * Copyright 2014 Ilia Mirkin
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ilia Mirkin
23 */
24
25#include "nv04.h"
26
27static void
28nv4c_mc_msi_rearm(struct nouveau_mc *pmc)
29{
30 struct nv04_mc_priv *priv = (void *)pmc;
31 nv_wr08(priv, 0x088050, 0xff);
32}
33
34struct nouveau_oclass *
35nv4c_mc_oclass = &(struct nouveau_mc_oclass) {
36 .base.handle = NV_SUBDEV(MC, 0x4c),
37 .base.ofuncs = &(struct nouveau_ofuncs) {
38 .ctor = nv04_mc_ctor,
39 .dtor = _nouveau_mc_dtor,
40 .init = nv44_mc_init,
41 .fini = _nouveau_mc_fini,
42 },
43 .intr = nv04_mc_intr,
44 .msi_rearm = nv4c_mc_msi_rearm,
45}.base;
diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.c b/drivers/gpu/drm/nouveau/nouveau_acpi.c
index 4ef83df2b246..83face3f608f 100644
--- a/drivers/gpu/drm/nouveau/nouveau_acpi.c
+++ b/drivers/gpu/drm/nouveau/nouveau_acpi.c
@@ -106,6 +106,29 @@ static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *
106 return 0; 106 return 0;
107} 107}
108 108
109/*
110 * On some platforms, _DSM(nouveau_op_dsm_muid, func0) has special
111 * requirements on the fourth parameter, so a private implementation
112 * instead of using acpi_check_dsm().
113 */
114static int nouveau_check_optimus_dsm(acpi_handle handle)
115{
116 int result;
117
118 /*
119 * Function 0 returns a Buffer containing available functions.
120 * The args parameter is ignored for function 0, so just put 0 in it
121 */
122 if (nouveau_optimus_dsm(handle, 0, 0, &result))
123 return 0;
124
125 /*
126 * ACPI Spec v4 9.14.1: if bit 0 is zero, no function is supported.
127 * If the n-th bit is enabled, function n is supported
128 */
129 return result & 1 && result & (1 << NOUVEAU_DSM_OPTIMUS_CAPS);
130}
131
109static int nouveau_dsm(acpi_handle handle, int func, int arg) 132static int nouveau_dsm(acpi_handle handle, int func, int arg)
110{ 133{
111 int ret = 0; 134 int ret = 0;
@@ -207,8 +230,7 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
207 1 << NOUVEAU_DSM_POWER)) 230 1 << NOUVEAU_DSM_POWER))
208 retval |= NOUVEAU_DSM_HAS_MUX; 231 retval |= NOUVEAU_DSM_HAS_MUX;
209 232
210 if (acpi_check_dsm(dhandle, nouveau_op_dsm_muid, 0x00000100, 233 if (nouveau_check_optimus_dsm(dhandle))
211 1 << NOUVEAU_DSM_OPTIMUS_CAPS))
212 retval |= NOUVEAU_DSM_HAS_OPT; 234 retval |= NOUVEAU_DSM_HAS_OPT;
213 235
214 if (retval & NOUVEAU_DSM_HAS_OPT) { 236 if (retval & NOUVEAU_DSM_HAS_OPT) {
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 488686d490c0..4aed1714b9ab 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1249,7 +1249,7 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
1249 mem->bus.is_iomem = !dev->agp->cant_use_aperture; 1249 mem->bus.is_iomem = !dev->agp->cant_use_aperture;
1250 } 1250 }
1251#endif 1251#endif
1252 if (!node->memtype) 1252 if (nv_device(drm->device)->card_type < NV_50 || !node->memtype)
1253 /* untiled */ 1253 /* untiled */
1254 break; 1254 break;
1255 /* fallthrough, tiled memory */ 1255 /* fallthrough, tiled memory */
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 78c8e7146d56..4ee702ac8907 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -376,6 +376,8 @@ nouveau_drm_load(struct drm_device *dev, unsigned long flags)
376 if (ret) 376 if (ret)
377 goto fail_device; 377 goto fail_device;
378 378
379 dev->irq_enabled = true;
380
379 /* workaround an odd issue on nvc1 by disabling the device's 381 /* workaround an odd issue on nvc1 by disabling the device's
380 * nosnoop capability. hopefully won't cause issues until a 382 * nosnoop capability. hopefully won't cause issues until a
381 * better fix is found - assuming there is one... 383 * better fix is found - assuming there is one...
@@ -475,6 +477,7 @@ nouveau_drm_remove(struct pci_dev *pdev)
475 struct nouveau_drm *drm = nouveau_drm(dev); 477 struct nouveau_drm *drm = nouveau_drm(dev);
476 struct nouveau_object *device; 478 struct nouveau_object *device;
477 479
480 dev->irq_enabled = false;
478 device = drm->client.base.device; 481 device = drm->client.base.device;
479 drm_put_dev(dev); 482 drm_put_dev(dev);
480 483
@@ -863,13 +866,16 @@ static int nouveau_pmops_runtime_suspend(struct device *dev)
863 struct drm_device *drm_dev = pci_get_drvdata(pdev); 866 struct drm_device *drm_dev = pci_get_drvdata(pdev);
864 int ret; 867 int ret;
865 868
866 if (nouveau_runtime_pm == 0) 869 if (nouveau_runtime_pm == 0) {
867 return -EINVAL; 870 pm_runtime_forbid(dev);
871 return -EBUSY;
872 }
868 873
869 /* are we optimus enabled? */ 874 /* are we optimus enabled? */
870 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) { 875 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) {
871 DRM_DEBUG_DRIVER("failing to power off - not optimus\n"); 876 DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
872 return -EINVAL; 877 pm_runtime_forbid(dev);
878 return -EBUSY;
873 } 879 }
874 880
875 nv_debug_level(SILENT); 881 nv_debug_level(SILENT);
@@ -920,12 +926,15 @@ static int nouveau_pmops_runtime_idle(struct device *dev)
920 struct nouveau_drm *drm = nouveau_drm(drm_dev); 926 struct nouveau_drm *drm = nouveau_drm(drm_dev);
921 struct drm_crtc *crtc; 927 struct drm_crtc *crtc;
922 928
923 if (nouveau_runtime_pm == 0) 929 if (nouveau_runtime_pm == 0) {
930 pm_runtime_forbid(dev);
924 return -EBUSY; 931 return -EBUSY;
932 }
925 933
926 /* are we optimus enabled? */ 934 /* are we optimus enabled? */
927 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) { 935 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) {
928 DRM_DEBUG_DRIVER("failing to power off - not optimus\n"); 936 DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
937 pm_runtime_forbid(dev);
929 return -EBUSY; 938 return -EBUSY;
930 } 939 }
931 940
diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
index 81638d7f2eff..471347edc27e 100644
--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
@@ -14,7 +14,9 @@ nouveau_vga_set_decode(void *priv, bool state)
14{ 14{
15 struct nouveau_device *device = nouveau_dev(priv); 15 struct nouveau_device *device = nouveau_dev(priv);
16 16
17 if (device->chipset >= 0x40) 17 if (device->card_type == NV_40 && device->chipset >= 0x4c)
18 nv_wr32(device, 0x088060, state);
19 else if (device->chipset >= 0x40)
18 nv_wr32(device, 0x088054, state); 20 nv_wr32(device, 0x088054, state);
19 else 21 else
20 nv_wr32(device, 0x001854, state); 22 nv_wr32(device, 0x001854, state);
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index a9338c85630f..daa4dd375ab1 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -559,7 +559,7 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc,
559 u32 adjusted_clock = mode->clock; 559 u32 adjusted_clock = mode->clock;
560 int encoder_mode = atombios_get_encoder_mode(encoder); 560 int encoder_mode = atombios_get_encoder_mode(encoder);
561 u32 dp_clock = mode->clock; 561 u32 dp_clock = mode->clock;
562 int bpc = radeon_get_monitor_bpc(connector); 562 int bpc = radeon_crtc->bpc;
563 bool is_duallink = radeon_dig_monitor_is_duallink(encoder, mode->clock); 563 bool is_duallink = radeon_dig_monitor_is_duallink(encoder, mode->clock);
564 564
565 /* reset the pll flags */ 565 /* reset the pll flags */
@@ -1176,7 +1176,7 @@ static int dce4_crtc_do_set_base(struct drm_crtc *crtc,
1176 evergreen_tiling_fields(tiling_flags, &bankw, &bankh, &mtaspect, &tile_split); 1176 evergreen_tiling_fields(tiling_flags, &bankw, &bankh, &mtaspect, &tile_split);
1177 1177
1178 /* Set NUM_BANKS. */ 1178 /* Set NUM_BANKS. */
1179 if (rdev->family >= CHIP_BONAIRE) { 1179 if (rdev->family >= CHIP_TAHITI) {
1180 unsigned tileb, index, num_banks, tile_split_bytes; 1180 unsigned tileb, index, num_banks, tile_split_bytes;
1181 1181
1182 /* Calculate the macrotile mode index. */ 1182 /* Calculate the macrotile mode index. */
@@ -1194,13 +1194,14 @@ static int dce4_crtc_do_set_base(struct drm_crtc *crtc,
1194 return -EINVAL; 1194 return -EINVAL;
1195 } 1195 }
1196 1196
1197 num_banks = (rdev->config.cik.macrotile_mode_array[index] >> 6) & 0x3; 1197 if (rdev->family >= CHIP_BONAIRE)
1198 num_banks = (rdev->config.cik.macrotile_mode_array[index] >> 6) & 0x3;
1199 else
1200 num_banks = (rdev->config.si.tile_mode_array[index] >> 20) & 0x3;
1198 fb_format |= EVERGREEN_GRPH_NUM_BANKS(num_banks); 1201 fb_format |= EVERGREEN_GRPH_NUM_BANKS(num_banks);
1199 } else { 1202 } else {
1200 /* SI and older. */ 1203 /* NI and older. */
1201 if (rdev->family >= CHIP_TAHITI) 1204 if (rdev->family >= CHIP_CAYMAN)
1202 tmp = rdev->config.si.tile_config;
1203 else if (rdev->family >= CHIP_CAYMAN)
1204 tmp = rdev->config.cayman.tile_config; 1205 tmp = rdev->config.cayman.tile_config;
1205 else 1206 else
1206 tmp = rdev->config.evergreen.tile_config; 1207 tmp = rdev->config.evergreen.tile_config;
@@ -1773,6 +1774,20 @@ static int radeon_atom_pick_pll(struct drm_crtc *crtc)
1773 return ATOM_PPLL1; 1774 return ATOM_PPLL1;
1774 DRM_ERROR("unable to allocate a PPLL\n"); 1775 DRM_ERROR("unable to allocate a PPLL\n");
1775 return ATOM_PPLL_INVALID; 1776 return ATOM_PPLL_INVALID;
1777 } else if (ASIC_IS_DCE41(rdev)) {
1778 /* Don't share PLLs on DCE4.1 chips */
1779 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) {
1780 if (rdev->clock.dp_extclk)
1781 /* skip PPLL programming if using ext clock */
1782 return ATOM_PPLL_INVALID;
1783 }
1784 pll_in_use = radeon_get_pll_use_mask(crtc);
1785 if (!(pll_in_use & (1 << ATOM_PPLL1)))
1786 return ATOM_PPLL1;
1787 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1788 return ATOM_PPLL2;
1789 DRM_ERROR("unable to allocate a PPLL\n");
1790 return ATOM_PPLL_INVALID;
1776 } else if (ASIC_IS_DCE4(rdev)) { 1791 } else if (ASIC_IS_DCE4(rdev)) {
1777 /* in DP mode, the DP ref clock can come from PPLL, DCPLL, or ext clock, 1792 /* in DP mode, the DP ref clock can come from PPLL, DCPLL, or ext clock,
1778 * depending on the asic: 1793 * depending on the asic:
@@ -1800,7 +1815,7 @@ static int radeon_atom_pick_pll(struct drm_crtc *crtc)
1800 if (pll != ATOM_PPLL_INVALID) 1815 if (pll != ATOM_PPLL_INVALID)
1801 return pll; 1816 return pll;
1802 } 1817 }
1803 } else if (!ASIC_IS_DCE41(rdev)) { /* Don't share PLLs on DCE4.1 chips */ 1818 } else {
1804 /* use the same PPLL for all monitors with the same clock */ 1819 /* use the same PPLL for all monitors with the same clock */
1805 pll = radeon_get_shared_nondp_ppll(crtc); 1820 pll = radeon_get_shared_nondp_ppll(crtc);
1806 if (pll != ATOM_PPLL_INVALID) 1821 if (pll != ATOM_PPLL_INVALID)
diff --git a/drivers/gpu/drm/radeon/atombios_encoders.c b/drivers/gpu/drm/radeon/atombios_encoders.c
index a42d61571f49..607dc14d195e 100644
--- a/drivers/gpu/drm/radeon/atombios_encoders.c
+++ b/drivers/gpu/drm/radeon/atombios_encoders.c
@@ -464,11 +464,12 @@ atombios_tv_setup(struct drm_encoder *encoder, int action)
464 464
465static u8 radeon_atom_get_bpc(struct drm_encoder *encoder) 465static u8 radeon_atom_get_bpc(struct drm_encoder *encoder)
466{ 466{
467 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
468 int bpc = 8; 467 int bpc = 8;
469 468
470 if (connector) 469 if (encoder->crtc) {
471 bpc = radeon_get_monitor_bpc(connector); 470 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
471 bpc = radeon_crtc->bpc;
472 }
472 473
473 switch (bpc) { 474 switch (bpc) {
474 case 0: 475 case 0:
@@ -1313,7 +1314,7 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t
1313 } 1314 }
1314 if (is_dp) 1315 if (is_dp)
1315 args.v5.ucLaneNum = dp_lane_count; 1316 args.v5.ucLaneNum = dp_lane_count;
1316 else if (radeon_encoder->pixel_clock > 165000) 1317 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1317 args.v5.ucLaneNum = 8; 1318 args.v5.ucLaneNum = 8;
1318 else 1319 else
1319 args.v5.ucLaneNum = 4; 1320 args.v5.ucLaneNum = 4;
diff --git a/drivers/gpu/drm/radeon/btc_dpm.c b/drivers/gpu/drm/radeon/btc_dpm.c
index 0fbd36f3d4e9..ea103ccdf4bd 100644
--- a/drivers/gpu/drm/radeon/btc_dpm.c
+++ b/drivers/gpu/drm/radeon/btc_dpm.c
@@ -29,6 +29,7 @@
29#include "cypress_dpm.h" 29#include "cypress_dpm.h"
30#include "btc_dpm.h" 30#include "btc_dpm.h"
31#include "atom.h" 31#include "atom.h"
32#include <linux/seq_file.h>
32 33
33#define MC_CG_ARB_FREQ_F0 0x0a 34#define MC_CG_ARB_FREQ_F0 0x0a
34#define MC_CG_ARB_FREQ_F1 0x0b 35#define MC_CG_ARB_FREQ_F1 0x0b
@@ -2756,6 +2757,37 @@ void btc_dpm_fini(struct radeon_device *rdev)
2756 r600_free_extended_power_table(rdev); 2757 r600_free_extended_power_table(rdev);
2757} 2758}
2758 2759
2760void btc_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
2761 struct seq_file *m)
2762{
2763 struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
2764 struct radeon_ps *rps = &eg_pi->current_rps;
2765 struct rv7xx_ps *ps = rv770_get_ps(rps);
2766 struct rv7xx_pl *pl;
2767 u32 current_index =
2768 (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
2769 CURRENT_PROFILE_INDEX_SHIFT;
2770
2771 if (current_index > 2) {
2772 seq_printf(m, "invalid dpm profile %d\n", current_index);
2773 } else {
2774 if (current_index == 0)
2775 pl = &ps->low;
2776 else if (current_index == 1)
2777 pl = &ps->medium;
2778 else /* current_index == 2 */
2779 pl = &ps->high;
2780 seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
2781 if (rdev->family >= CHIP_CEDAR) {
2782 seq_printf(m, "power level %d sclk: %u mclk: %u vddc: %u vddci: %u\n",
2783 current_index, pl->sclk, pl->mclk, pl->vddc, pl->vddci);
2784 } else {
2785 seq_printf(m, "power level %d sclk: %u mclk: %u vddc: %u\n",
2786 current_index, pl->sclk, pl->mclk, pl->vddc);
2787 }
2788 }
2789}
2790
2759u32 btc_dpm_get_sclk(struct radeon_device *rdev, bool low) 2791u32 btc_dpm_get_sclk(struct radeon_device *rdev, bool low)
2760{ 2792{
2761 struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev); 2793 struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
diff --git a/drivers/gpu/drm/radeon/btcd.h b/drivers/gpu/drm/radeon/btcd.h
index 29e32de7e025..9c65be2d55a9 100644
--- a/drivers/gpu/drm/radeon/btcd.h
+++ b/drivers/gpu/drm/radeon/btcd.h
@@ -44,6 +44,10 @@
44# define DYN_SPREAD_SPECTRUM_EN (1 << 23) 44# define DYN_SPREAD_SPECTRUM_EN (1 << 23)
45# define AC_DC_SW (1 << 24) 45# define AC_DC_SW (1 << 24)
46 46
47#define TARGET_AND_CURRENT_PROFILE_INDEX 0x66c
48# define CURRENT_PROFILE_INDEX_MASK (0xf << 4)
49# define CURRENT_PROFILE_INDEX_SHIFT 4
50
47#define CG_BIF_REQ_AND_RSP 0x7f4 51#define CG_BIF_REQ_AND_RSP 0x7f4
48#define CG_CLIENT_REQ(x) ((x) << 0) 52#define CG_CLIENT_REQ(x) ((x) << 0)
49#define CG_CLIENT_REQ_MASK (0xff << 0) 53#define CG_CLIENT_REQ_MASK (0xff << 0)
diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
index e6419ca7cd37..bbb17841a9e5 100644
--- a/drivers/gpu/drm/radeon/cik.c
+++ b/drivers/gpu/drm/radeon/cik.c
@@ -3046,7 +3046,7 @@ static u32 cik_create_bitmask(u32 bit_width)
3046} 3046}
3047 3047
3048/** 3048/**
3049 * cik_select_se_sh - select which SE, SH to address 3049 * cik_get_rb_disabled - computes the mask of disabled RBs
3050 * 3050 *
3051 * @rdev: radeon_device pointer 3051 * @rdev: radeon_device pointer
3052 * @max_rb_num: max RBs (render backends) for the asic 3052 * @max_rb_num: max RBs (render backends) for the asic
@@ -4134,8 +4134,11 @@ static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
4134{ 4134{
4135 if (enable) 4135 if (enable)
4136 WREG32(CP_MEC_CNTL, 0); 4136 WREG32(CP_MEC_CNTL, 0);
4137 else 4137 else {
4138 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT)); 4138 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
4139 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
4140 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
4141 }
4139 udelay(50); 4142 udelay(50);
4140} 4143}
4141 4144
@@ -7902,7 +7905,8 @@ int cik_resume(struct radeon_device *rdev)
7902 /* init golden registers */ 7905 /* init golden registers */
7903 cik_init_golden_registers(rdev); 7906 cik_init_golden_registers(rdev);
7904 7907
7905 radeon_pm_resume(rdev); 7908 if (rdev->pm.pm_method == PM_METHOD_DPM)
7909 radeon_pm_resume(rdev);
7906 7910
7907 rdev->accel_working = true; 7911 rdev->accel_working = true;
7908 r = cik_startup(rdev); 7912 r = cik_startup(rdev);
diff --git a/drivers/gpu/drm/radeon/cik_sdma.c b/drivers/gpu/drm/radeon/cik_sdma.c
index 1ecb3f1070e3..94626ea90fa5 100644
--- a/drivers/gpu/drm/radeon/cik_sdma.c
+++ b/drivers/gpu/drm/radeon/cik_sdma.c
@@ -264,6 +264,8 @@ static void cik_sdma_gfx_stop(struct radeon_device *rdev)
264 WREG32(SDMA0_GFX_RB_CNTL + reg_offset, rb_cntl); 264 WREG32(SDMA0_GFX_RB_CNTL + reg_offset, rb_cntl);
265 WREG32(SDMA0_GFX_IB_CNTL + reg_offset, 0); 265 WREG32(SDMA0_GFX_IB_CNTL + reg_offset, 0);
266 } 266 }
267 rdev->ring[R600_RING_TYPE_DMA_INDEX].ready = false;
268 rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX].ready = false;
267} 269}
268 270
269/** 271/**
@@ -291,6 +293,11 @@ void cik_sdma_enable(struct radeon_device *rdev, bool enable)
291 u32 me_cntl, reg_offset; 293 u32 me_cntl, reg_offset;
292 int i; 294 int i;
293 295
296 if (enable == false) {
297 cik_sdma_gfx_stop(rdev);
298 cik_sdma_rlc_stop(rdev);
299 }
300
294 for (i = 0; i < 2; i++) { 301 for (i = 0; i < 2; i++) {
295 if (i == 0) 302 if (i == 0)
296 reg_offset = SDMA0_REGISTER_OFFSET; 303 reg_offset = SDMA0_REGISTER_OFFSET;
@@ -420,10 +427,6 @@ static int cik_sdma_load_microcode(struct radeon_device *rdev)
420 if (!rdev->sdma_fw) 427 if (!rdev->sdma_fw)
421 return -EINVAL; 428 return -EINVAL;
422 429
423 /* stop the gfx rings and rlc compute queues */
424 cik_sdma_gfx_stop(rdev);
425 cik_sdma_rlc_stop(rdev);
426
427 /* halt the MEs */ 430 /* halt the MEs */
428 cik_sdma_enable(rdev, false); 431 cik_sdma_enable(rdev, false);
429 432
@@ -492,9 +495,6 @@ int cik_sdma_resume(struct radeon_device *rdev)
492 */ 495 */
493void cik_sdma_fini(struct radeon_device *rdev) 496void cik_sdma_fini(struct radeon_device *rdev)
494{ 497{
495 /* stop the gfx rings and rlc compute queues */
496 cik_sdma_gfx_stop(rdev);
497 cik_sdma_rlc_stop(rdev);
498 /* halt the MEs */ 498 /* halt the MEs */
499 cik_sdma_enable(rdev, false); 499 cik_sdma_enable(rdev, false);
500 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]); 500 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c b/drivers/gpu/drm/radeon/dce6_afmt.c
index 713a5d359901..94e858751994 100644
--- a/drivers/gpu/drm/radeon/dce6_afmt.c
+++ b/drivers/gpu/drm/radeon/dce6_afmt.c
@@ -278,13 +278,15 @@ static int dce6_audio_chipset_supported(struct radeon_device *rdev)
278 return !ASIC_IS_NODCE(rdev); 278 return !ASIC_IS_NODCE(rdev);
279} 279}
280 280
281static void dce6_audio_enable(struct radeon_device *rdev, 281void dce6_audio_enable(struct radeon_device *rdev,
282 struct r600_audio_pin *pin, 282 struct r600_audio_pin *pin,
283 bool enable) 283 bool enable)
284{ 284{
285 if (!pin)
286 return;
287
285 WREG32_ENDPOINT(pin->offset, AZ_F0_CODEC_PIN_CONTROL_HOTPLUG_CONTROL, 288 WREG32_ENDPOINT(pin->offset, AZ_F0_CODEC_PIN_CONTROL_HOTPLUG_CONTROL,
286 AUDIO_ENABLED); 289 enable ? AUDIO_ENABLED : 0);
287 DRM_INFO("%s audio %d support\n", enable ? "Enabling" : "Disabling", pin->id);
288} 290}
289 291
290static const u32 pin_offsets[7] = 292static const u32 pin_offsets[7] =
@@ -323,7 +325,8 @@ int dce6_audio_init(struct radeon_device *rdev)
323 rdev->audio.pin[i].connected = false; 325 rdev->audio.pin[i].connected = false;
324 rdev->audio.pin[i].offset = pin_offsets[i]; 326 rdev->audio.pin[i].offset = pin_offsets[i];
325 rdev->audio.pin[i].id = i; 327 rdev->audio.pin[i].id = i;
326 dce6_audio_enable(rdev, &rdev->audio.pin[i], true); 328 /* disable audio. it will be set up later */
329 dce6_audio_enable(rdev, &rdev->audio.pin[i], false);
327 } 330 }
328 331
329 return 0; 332 return 0;
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index f2b9e21ce4da..27b0ff16082e 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -1680,7 +1680,7 @@ bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
1680 case RADEON_HPD_6: 1680 case RADEON_HPD_6:
1681 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE) 1681 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
1682 connected = true; 1682 connected = true;
1683 break; 1683 break;
1684 default: 1684 default:
1685 break; 1685 break;
1686 } 1686 }
@@ -5299,7 +5299,8 @@ int evergreen_resume(struct radeon_device *rdev)
5299 /* init golden registers */ 5299 /* init golden registers */
5300 evergreen_init_golden_registers(rdev); 5300 evergreen_init_golden_registers(rdev);
5301 5301
5302 radeon_pm_resume(rdev); 5302 if (rdev->pm.pm_method == PM_METHOD_DPM)
5303 radeon_pm_resume(rdev);
5303 5304
5304 rdev->accel_working = true; 5305 rdev->accel_working = true;
5305 r = evergreen_startup(rdev); 5306 r = evergreen_startup(rdev);
@@ -5475,9 +5476,9 @@ void evergreen_fini(struct radeon_device *rdev)
5475 radeon_wb_fini(rdev); 5476 radeon_wb_fini(rdev);
5476 radeon_ib_pool_fini(rdev); 5477 radeon_ib_pool_fini(rdev);
5477 radeon_irq_kms_fini(rdev); 5478 radeon_irq_kms_fini(rdev);
5478 evergreen_pcie_gart_fini(rdev);
5479 uvd_v1_0_fini(rdev); 5479 uvd_v1_0_fini(rdev);
5480 radeon_uvd_fini(rdev); 5480 radeon_uvd_fini(rdev);
5481 evergreen_pcie_gart_fini(rdev);
5481 r600_vram_scratch_fini(rdev); 5482 r600_vram_scratch_fini(rdev);
5482 radeon_gem_fini(rdev); 5483 radeon_gem_fini(rdev);
5483 radeon_fence_driver_fini(rdev); 5484 radeon_fence_driver_fini(rdev);
diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c b/drivers/gpu/drm/radeon/evergreen_hdmi.c
index 0c6d5cef4cf1..05b0c95813fd 100644
--- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
+++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
@@ -306,6 +306,15 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode
306 return; 306 return;
307 offset = dig->afmt->offset; 307 offset = dig->afmt->offset;
308 308
309 /* disable audio prior to setting up hw */
310 if (ASIC_IS_DCE6(rdev)) {
311 dig->afmt->pin = dce6_audio_get_pin(rdev);
312 dce6_audio_enable(rdev, dig->afmt->pin, false);
313 } else {
314 dig->afmt->pin = r600_audio_get_pin(rdev);
315 r600_audio_enable(rdev, dig->afmt->pin, false);
316 }
317
309 evergreen_audio_set_dto(encoder, mode->clock); 318 evergreen_audio_set_dto(encoder, mode->clock);
310 319
311 WREG32(HDMI_VBI_PACKET_CONTROL + offset, 320 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
@@ -409,12 +418,16 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode
409 WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF); 418 WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
410 WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001); 419 WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
411 WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001); 420 WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
421
422 /* enable audio after to setting up hw */
423 if (ASIC_IS_DCE6(rdev))
424 dce6_audio_enable(rdev, dig->afmt->pin, true);
425 else
426 r600_audio_enable(rdev, dig->afmt->pin, true);
412} 427}
413 428
414void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable) 429void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
415{ 430{
416 struct drm_device *dev = encoder->dev;
417 struct radeon_device *rdev = dev->dev_private;
418 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 431 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
419 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 432 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
420 433
@@ -427,15 +440,6 @@ void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
427 if (!enable && !dig->afmt->enabled) 440 if (!enable && !dig->afmt->enabled)
428 return; 441 return;
429 442
430 if (enable) {
431 if (ASIC_IS_DCE6(rdev))
432 dig->afmt->pin = dce6_audio_get_pin(rdev);
433 else
434 dig->afmt->pin = r600_audio_get_pin(rdev);
435 } else {
436 dig->afmt->pin = NULL;
437 }
438
439 dig->afmt->enabled = enable; 443 dig->afmt->enabled = enable;
440 444
441 DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n", 445 DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
diff --git a/drivers/gpu/drm/radeon/evergreen_smc.h b/drivers/gpu/drm/radeon/evergreen_smc.h
index 76ada8cfe902..3a03ba37d043 100644
--- a/drivers/gpu/drm/radeon/evergreen_smc.h
+++ b/drivers/gpu/drm/radeon/evergreen_smc.h
@@ -57,7 +57,7 @@ typedef struct SMC_Evergreen_MCRegisters SMC_Evergreen_MCRegisters;
57 57
58#define EVERGREEN_SMC_FIRMWARE_HEADER_LOCATION 0x100 58#define EVERGREEN_SMC_FIRMWARE_HEADER_LOCATION 0x100
59 59
60#define EVERGREEN_SMC_FIRMWARE_HEADER_softRegisters 0x0 60#define EVERGREEN_SMC_FIRMWARE_HEADER_softRegisters 0x8
61#define EVERGREEN_SMC_FIRMWARE_HEADER_stateTable 0xC 61#define EVERGREEN_SMC_FIRMWARE_HEADER_stateTable 0xC
62#define EVERGREEN_SMC_FIRMWARE_HEADER_mcRegisterTable 0x20 62#define EVERGREEN_SMC_FIRMWARE_HEADER_mcRegisterTable 0x20
63 63
diff --git a/drivers/gpu/drm/radeon/kv_dpm.c b/drivers/gpu/drm/radeon/kv_dpm.c
index b6e01d5d2cce..351db361239d 100644
--- a/drivers/gpu/drm/radeon/kv_dpm.c
+++ b/drivers/gpu/drm/radeon/kv_dpm.c
@@ -1223,7 +1223,7 @@ int kv_dpm_enable(struct radeon_device *rdev)
1223 1223
1224int kv_dpm_late_enable(struct radeon_device *rdev) 1224int kv_dpm_late_enable(struct radeon_device *rdev)
1225{ 1225{
1226 int ret; 1226 int ret = 0;
1227 1227
1228 if (rdev->irq.installed && 1228 if (rdev->irq.installed &&
1229 r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) { 1229 r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index ea932ac66fc6..bf6300cfd62d 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -2105,7 +2105,8 @@ int cayman_resume(struct radeon_device *rdev)
2105 /* init golden registers */ 2105 /* init golden registers */
2106 ni_init_golden_registers(rdev); 2106 ni_init_golden_registers(rdev);
2107 2107
2108 radeon_pm_resume(rdev); 2108 if (rdev->pm.pm_method == PM_METHOD_DPM)
2109 radeon_pm_resume(rdev);
2109 2110
2110 rdev->accel_working = true; 2111 rdev->accel_working = true;
2111 r = cayman_startup(rdev); 2112 r = cayman_startup(rdev);
diff --git a/drivers/gpu/drm/radeon/ni_dpm.c b/drivers/gpu/drm/radeon/ni_dpm.c
index c351226ecb31..ca814276b075 100644
--- a/drivers/gpu/drm/radeon/ni_dpm.c
+++ b/drivers/gpu/drm/radeon/ni_dpm.c
@@ -2588,7 +2588,7 @@ static int ni_populate_sq_ramping_values(struct radeon_device *rdev,
2588 if (NISLANDS_DPM2_SQ_RAMP_STI_SIZE > (STI_SIZE_MASK >> STI_SIZE_SHIFT)) 2588 if (NISLANDS_DPM2_SQ_RAMP_STI_SIZE > (STI_SIZE_MASK >> STI_SIZE_SHIFT))
2589 enable_sq_ramping = false; 2589 enable_sq_ramping = false;
2590 2590
2591 if (NISLANDS_DPM2_SQ_RAMP_LTI_RATIO <= (LTI_RATIO_MASK >> LTI_RATIO_SHIFT)) 2591 if (NISLANDS_DPM2_SQ_RAMP_LTI_RATIO > (LTI_RATIO_MASK >> LTI_RATIO_SHIFT))
2592 enable_sq_ramping = false; 2592 enable_sq_ramping = false;
2593 2593
2594 for (i = 0; i < state->performance_level_count; i++) { 2594 for (i = 0; i < state->performance_level_count; i++) {
@@ -3945,7 +3945,6 @@ static void ni_parse_pplib_clock_info(struct radeon_device *rdev,
3945 struct rv7xx_power_info *pi = rv770_get_pi(rdev); 3945 struct rv7xx_power_info *pi = rv770_get_pi(rdev);
3946 struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev); 3946 struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
3947 struct ni_ps *ps = ni_get_ps(rps); 3947 struct ni_ps *ps = ni_get_ps(rps);
3948 u16 vddc;
3949 struct rv7xx_pl *pl = &ps->performance_levels[index]; 3948 struct rv7xx_pl *pl = &ps->performance_levels[index];
3950 3949
3951 ps->performance_level_count = index + 1; 3950 ps->performance_level_count = index + 1;
@@ -3961,8 +3960,8 @@ static void ni_parse_pplib_clock_info(struct radeon_device *rdev,
3961 3960
3962 /* patch up vddc if necessary */ 3961 /* patch up vddc if necessary */
3963 if (pl->vddc == 0xff01) { 3962 if (pl->vddc == 0xff01) {
3964 if (radeon_atom_get_max_vddc(rdev, 0, 0, &vddc) == 0) 3963 if (pi->max_vddc)
3965 pl->vddc = vddc; 3964 pl->vddc = pi->max_vddc;
3966 } 3965 }
3967 3966
3968 if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) { 3967 if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) {
@@ -4322,7 +4321,8 @@ void ni_dpm_print_power_state(struct radeon_device *rdev,
4322void ni_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev, 4321void ni_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
4323 struct seq_file *m) 4322 struct seq_file *m)
4324{ 4323{
4325 struct radeon_ps *rps = rdev->pm.dpm.current_ps; 4324 struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
4325 struct radeon_ps *rps = &eg_pi->current_rps;
4326 struct ni_ps *ps = ni_get_ps(rps); 4326 struct ni_ps *ps = ni_get_ps(rps);
4327 struct rv7xx_pl *pl; 4327 struct rv7xx_pl *pl;
4328 u32 current_index = 4328 u32 current_index =
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index ef024ce3f7cc..3cc78bb66042 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -3942,8 +3942,6 @@ int r100_resume(struct radeon_device *rdev)
3942 /* Initialize surface registers */ 3942 /* Initialize surface registers */
3943 radeon_surface_init(rdev); 3943 radeon_surface_init(rdev);
3944 3944
3945 radeon_pm_resume(rdev);
3946
3947 rdev->accel_working = true; 3945 rdev->accel_working = true;
3948 r = r100_startup(rdev); 3946 r = r100_startup(rdev);
3949 if (r) { 3947 if (r) {
diff --git a/drivers/gpu/drm/radeon/r300.c b/drivers/gpu/drm/radeon/r300.c
index 7c63ef840e86..0b658b34b33a 100644
--- a/drivers/gpu/drm/radeon/r300.c
+++ b/drivers/gpu/drm/radeon/r300.c
@@ -1430,8 +1430,6 @@ int r300_resume(struct radeon_device *rdev)
1430 /* Initialize surface registers */ 1430 /* Initialize surface registers */
1431 radeon_surface_init(rdev); 1431 radeon_surface_init(rdev);
1432 1432
1433 radeon_pm_resume(rdev);
1434
1435 rdev->accel_working = true; 1433 rdev->accel_working = true;
1436 r = r300_startup(rdev); 1434 r = r300_startup(rdev);
1437 if (r) { 1435 if (r) {
diff --git a/drivers/gpu/drm/radeon/r420.c b/drivers/gpu/drm/radeon/r420.c
index 3768aab2710b..802b19220a21 100644
--- a/drivers/gpu/drm/radeon/r420.c
+++ b/drivers/gpu/drm/radeon/r420.c
@@ -325,8 +325,6 @@ int r420_resume(struct radeon_device *rdev)
325 /* Initialize surface registers */ 325 /* Initialize surface registers */
326 radeon_surface_init(rdev); 326 radeon_surface_init(rdev);
327 327
328 radeon_pm_resume(rdev);
329
330 rdev->accel_working = true; 328 rdev->accel_working = true;
331 r = r420_startup(rdev); 329 r = r420_startup(rdev);
332 if (r) { 330 if (r) {
diff --git a/drivers/gpu/drm/radeon/r520.c b/drivers/gpu/drm/radeon/r520.c
index e209eb75024f..98d6053c36c6 100644
--- a/drivers/gpu/drm/radeon/r520.c
+++ b/drivers/gpu/drm/radeon/r520.c
@@ -240,8 +240,6 @@ int r520_resume(struct radeon_device *rdev)
240 /* Initialize surface registers */ 240 /* Initialize surface registers */
241 radeon_surface_init(rdev); 241 radeon_surface_init(rdev);
242 242
243 radeon_pm_resume(rdev);
244
245 rdev->accel_working = true; 243 rdev->accel_working = true;
246 r = r520_startup(rdev); 244 r = r520_startup(rdev);
247 if (r) { 245 if (r) {
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index 56140b4e5bb2..647ef4079217 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -2968,7 +2968,8 @@ int r600_resume(struct radeon_device *rdev)
2968 /* post card */ 2968 /* post card */
2969 atom_asic_init(rdev->mode_info.atom_context); 2969 atom_asic_init(rdev->mode_info.atom_context);
2970 2970
2971 radeon_pm_resume(rdev); 2971 if (rdev->pm.pm_method == PM_METHOD_DPM)
2972 radeon_pm_resume(rdev);
2972 2973
2973 rdev->accel_working = true; 2974 rdev->accel_working = true;
2974 r = r600_startup(rdev); 2975 r = r600_startup(rdev);
@@ -3991,6 +3992,10 @@ restart_ih:
3991 break; 3992 break;
3992 } 3993 }
3993 break; 3994 break;
3995 case 124: /* UVD */
3996 DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
3997 radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
3998 break;
3994 case 176: /* CP_INT in ring buffer */ 3999 case 176: /* CP_INT in ring buffer */
3995 case 177: /* CP_INT in IB1 */ 4000 case 177: /* CP_INT in IB1 */
3996 case 178: /* CP_INT in IB2 */ 4001 case 178: /* CP_INT in IB2 */
diff --git a/drivers/gpu/drm/radeon/r600_audio.c b/drivers/gpu/drm/radeon/r600_audio.c
index 47fc2b886979..bffac10c4296 100644
--- a/drivers/gpu/drm/radeon/r600_audio.c
+++ b/drivers/gpu/drm/radeon/r600_audio.c
@@ -142,12 +142,15 @@ void r600_audio_update_hdmi(struct work_struct *work)
142} 142}
143 143
144/* enable the audio stream */ 144/* enable the audio stream */
145static void r600_audio_enable(struct radeon_device *rdev, 145void r600_audio_enable(struct radeon_device *rdev,
146 struct r600_audio_pin *pin, 146 struct r600_audio_pin *pin,
147 bool enable) 147 bool enable)
148{ 148{
149 u32 value = 0; 149 u32 value = 0;
150 150
151 if (!pin)
152 return;
153
151 if (ASIC_IS_DCE4(rdev)) { 154 if (ASIC_IS_DCE4(rdev)) {
152 if (enable) { 155 if (enable) {
153 value |= 0x81000000; /* Required to enable audio */ 156 value |= 0x81000000; /* Required to enable audio */
@@ -158,7 +161,6 @@ static void r600_audio_enable(struct radeon_device *rdev,
158 WREG32_P(R600_AUDIO_ENABLE, 161 WREG32_P(R600_AUDIO_ENABLE,
159 enable ? 0x81000000 : 0x0, ~0x81000000); 162 enable ? 0x81000000 : 0x0, ~0x81000000);
160 } 163 }
161 DRM_INFO("%s audio %d support\n", enable ? "Enabling" : "Disabling", pin->id);
162} 164}
163 165
164/* 166/*
@@ -178,8 +180,8 @@ int r600_audio_init(struct radeon_device *rdev)
178 rdev->audio.pin[0].status_bits = 0; 180 rdev->audio.pin[0].status_bits = 0;
179 rdev->audio.pin[0].category_code = 0; 181 rdev->audio.pin[0].category_code = 0;
180 rdev->audio.pin[0].id = 0; 182 rdev->audio.pin[0].id = 0;
181 183 /* disable audio. it will be set up later */
182 r600_audio_enable(rdev, &rdev->audio.pin[0], true); 184 r600_audio_enable(rdev, &rdev->audio.pin[0], false);
183 185
184 return 0; 186 return 0;
185} 187}
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index 7b399dc5fd54..2812c7d1ae6f 100644
--- a/drivers/gpu/drm/radeon/r600_cs.c
+++ b/drivers/gpu/drm/radeon/r600_cs.c
@@ -1007,8 +1007,22 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
1007 case R_008C64_SQ_VSTMP_RING_SIZE: 1007 case R_008C64_SQ_VSTMP_RING_SIZE:
1008 case R_0288C8_SQ_GS_VERT_ITEMSIZE: 1008 case R_0288C8_SQ_GS_VERT_ITEMSIZE:
1009 /* get value to populate the IB don't remove */ 1009 /* get value to populate the IB don't remove */
1010 tmp =radeon_get_ib_value(p, idx); 1010 /*tmp =radeon_get_ib_value(p, idx);
1011 ib[idx] = 0; 1011 ib[idx] = 0;*/
1012 break;
1013 case SQ_ESGS_RING_BASE:
1014 case SQ_GSVS_RING_BASE:
1015 case SQ_ESTMP_RING_BASE:
1016 case SQ_GSTMP_RING_BASE:
1017 case SQ_PSTMP_RING_BASE:
1018 case SQ_VSTMP_RING_BASE:
1019 r = radeon_cs_packet_next_reloc(p, &reloc, 0);
1020 if (r) {
1021 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1022 "0x%04X\n", reg);
1023 return -EINVAL;
1024 }
1025 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1012 break; 1026 break;
1013 case SQ_CONFIG: 1027 case SQ_CONFIG:
1014 track->sq_config = radeon_get_ib_value(p, idx); 1028 track->sq_config = radeon_get_ib_value(p, idx);
diff --git a/drivers/gpu/drm/radeon/r600_hdmi.c b/drivers/gpu/drm/radeon/r600_hdmi.c
index 3016fc14f502..85a2bb28aed2 100644
--- a/drivers/gpu/drm/radeon/r600_hdmi.c
+++ b/drivers/gpu/drm/radeon/r600_hdmi.c
@@ -329,9 +329,6 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
329 u8 *sadb; 329 u8 *sadb;
330 int sad_count; 330 int sad_count;
331 331
332 /* XXX: setting this register causes hangs on some asics */
333 return;
334
335 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { 332 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
336 if (connector->encoder == encoder) { 333 if (connector->encoder == encoder) {
337 radeon_connector = to_radeon_connector(connector); 334 radeon_connector = to_radeon_connector(connector);
@@ -460,6 +457,10 @@ void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mod
460 return; 457 return;
461 offset = dig->afmt->offset; 458 offset = dig->afmt->offset;
462 459
460 /* disable audio prior to setting up hw */
461 dig->afmt->pin = r600_audio_get_pin(rdev);
462 r600_audio_enable(rdev, dig->afmt->pin, false);
463
463 r600_audio_set_dto(encoder, mode->clock); 464 r600_audio_set_dto(encoder, mode->clock);
464 465
465 WREG32(HDMI0_VBI_PACKET_CONTROL + offset, 466 WREG32(HDMI0_VBI_PACKET_CONTROL + offset,
@@ -531,6 +532,9 @@ void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mod
531 WREG32(HDMI0_RAMP_CONTROL3 + offset, 0x00000001); 532 WREG32(HDMI0_RAMP_CONTROL3 + offset, 0x00000001);
532 533
533 r600_hdmi_audio_workaround(encoder); 534 r600_hdmi_audio_workaround(encoder);
535
536 /* enable audio after to setting up hw */
537 r600_audio_enable(rdev, dig->afmt->pin, true);
534} 538}
535 539
536/* 540/*
@@ -651,11 +655,6 @@ void r600_hdmi_enable(struct drm_encoder *encoder, bool enable)
651 if (!enable && !dig->afmt->enabled) 655 if (!enable && !dig->afmt->enabled)
652 return; 656 return;
653 657
654 if (enable)
655 dig->afmt->pin = r600_audio_get_pin(rdev);
656 else
657 dig->afmt->pin = NULL;
658
659 /* Older chipsets require setting HDMI and routing manually */ 658 /* Older chipsets require setting HDMI and routing manually */
660 if (!ASIC_IS_DCE3(rdev)) { 659 if (!ASIC_IS_DCE3(rdev)) {
661 if (enable) 660 if (enable)
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 4a8ac1cd6b4c..e887d027b6d0 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -135,6 +135,9 @@ extern int radeon_hard_reset;
135/* R600+ */ 135/* R600+ */
136#define R600_RING_TYPE_UVD_INDEX 5 136#define R600_RING_TYPE_UVD_INDEX 5
137 137
138/* number of hw syncs before falling back on blocking */
139#define RADEON_NUM_SYNCS 4
140
138/* hardcode those limit for now */ 141/* hardcode those limit for now */
139#define RADEON_VA_IB_OFFSET (1 << 20) 142#define RADEON_VA_IB_OFFSET (1 << 20)
140#define RADEON_VA_RESERVED_SIZE (8 << 20) 143#define RADEON_VA_RESERVED_SIZE (8 << 20)
@@ -554,7 +557,6 @@ int radeon_mode_dumb_mmap(struct drm_file *filp,
554/* 557/*
555 * Semaphores. 558 * Semaphores.
556 */ 559 */
557/* everything here is constant */
558struct radeon_semaphore { 560struct radeon_semaphore {
559 struct radeon_sa_bo *sa_bo; 561 struct radeon_sa_bo *sa_bo;
560 signed waiters; 562 signed waiters;
@@ -2745,6 +2747,12 @@ int radeon_vm_bo_rmv(struct radeon_device *rdev,
2745void r600_audio_update_hdmi(struct work_struct *work); 2747void r600_audio_update_hdmi(struct work_struct *work);
2746struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev); 2748struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev);
2747struct r600_audio_pin *dce6_audio_get_pin(struct radeon_device *rdev); 2749struct r600_audio_pin *dce6_audio_get_pin(struct radeon_device *rdev);
2750void r600_audio_enable(struct radeon_device *rdev,
2751 struct r600_audio_pin *pin,
2752 bool enable);
2753void dce6_audio_enable(struct radeon_device *rdev,
2754 struct r600_audio_pin *pin,
2755 bool enable);
2748 2756
2749/* 2757/*
2750 * R600 vram scratch functions 2758 * R600 vram scratch functions
diff --git a/drivers/gpu/drm/radeon/radeon_asic.c b/drivers/gpu/drm/radeon/radeon_asic.c
index f74db43346fd..dda02bfc10a4 100644
--- a/drivers/gpu/drm/radeon/radeon_asic.c
+++ b/drivers/gpu/drm/radeon/radeon_asic.c
@@ -1555,7 +1555,7 @@ static struct radeon_asic btc_asic = {
1555 .get_sclk = &btc_dpm_get_sclk, 1555 .get_sclk = &btc_dpm_get_sclk,
1556 .get_mclk = &btc_dpm_get_mclk, 1556 .get_mclk = &btc_dpm_get_mclk,
1557 .print_power_state = &rv770_dpm_print_power_state, 1557 .print_power_state = &rv770_dpm_print_power_state,
1558 .debugfs_print_current_performance_level = &rv770_dpm_debugfs_print_current_performance_level, 1558 .debugfs_print_current_performance_level = &btc_dpm_debugfs_print_current_performance_level,
1559 .force_performance_level = &rv770_dpm_force_performance_level, 1559 .force_performance_level = &rv770_dpm_force_performance_level,
1560 .vblank_too_short = &btc_dpm_vblank_too_short, 1560 .vblank_too_short = &btc_dpm_vblank_too_short,
1561 }, 1561 },
diff --git a/drivers/gpu/drm/radeon/radeon_asic.h b/drivers/gpu/drm/radeon/radeon_asic.h
index b3bc433eed4c..ae637cfda783 100644
--- a/drivers/gpu/drm/radeon/radeon_asic.h
+++ b/drivers/gpu/drm/radeon/radeon_asic.h
@@ -551,6 +551,8 @@ void btc_dpm_fini(struct radeon_device *rdev);
551u32 btc_dpm_get_sclk(struct radeon_device *rdev, bool low); 551u32 btc_dpm_get_sclk(struct radeon_device *rdev, bool low);
552u32 btc_dpm_get_mclk(struct radeon_device *rdev, bool low); 552u32 btc_dpm_get_mclk(struct radeon_device *rdev, bool low);
553bool btc_dpm_vblank_too_short(struct radeon_device *rdev); 553bool btc_dpm_vblank_too_short(struct radeon_device *rdev);
554void btc_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
555 struct seq_file *m);
554int sumo_dpm_init(struct radeon_device *rdev); 556int sumo_dpm_init(struct radeon_device *rdev);
555int sumo_dpm_enable(struct radeon_device *rdev); 557int sumo_dpm_enable(struct radeon_device *rdev);
556int sumo_dpm_late_enable(struct radeon_device *rdev); 558int sumo_dpm_late_enable(struct radeon_device *rdev);
diff --git a/drivers/gpu/drm/radeon/radeon_atpx_handler.c b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
index 485848f889f5..fa9a9c02751e 100644
--- a/drivers/gpu/drm/radeon/radeon_atpx_handler.c
+++ b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
@@ -219,7 +219,8 @@ static int radeon_atpx_verify_interface(struct radeon_atpx *atpx)
219 memcpy(&output, info->buffer.pointer, size); 219 memcpy(&output, info->buffer.pointer, size);
220 220
221 /* TODO: check version? */ 221 /* TODO: check version? */
222 printk("ATPX version %u\n", output.version); 222 printk("ATPX version %u, functions 0x%08x\n",
223 output.version, output.function_bits);
223 224
224 radeon_atpx_parse_functions(&atpx->functions, output.function_bits); 225 radeon_atpx_parse_functions(&atpx->functions, output.function_bits);
225 226
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index b012cbbc3ed5..044bc98fb459 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -1521,13 +1521,16 @@ int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon)
1521 if (r) 1521 if (r)
1522 DRM_ERROR("ib ring test failed (%d).\n", r); 1522 DRM_ERROR("ib ring test failed (%d).\n", r);
1523 1523
1524 if (rdev->pm.dpm_enabled) { 1524 if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
1525 /* do dpm late init */ 1525 /* do dpm late init */
1526 r = radeon_pm_late_init(rdev); 1526 r = radeon_pm_late_init(rdev);
1527 if (r) { 1527 if (r) {
1528 rdev->pm.dpm_enabled = false; 1528 rdev->pm.dpm_enabled = false;
1529 DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n"); 1529 DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n");
1530 } 1530 }
1531 } else {
1532 /* resume old pm late */
1533 radeon_pm_resume(rdev);
1531 } 1534 }
1532 1535
1533 radeon_restore_bios_scratch_regs(rdev); 1536 radeon_restore_bios_scratch_regs(rdev);
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index d680608f6f5b..fbd8b930f2be 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -571,6 +571,8 @@ static void radeon_crtc_init(struct drm_device *dev, int index)
571 radeon_crtc->max_cursor_width = CURSOR_WIDTH; 571 radeon_crtc->max_cursor_width = CURSOR_WIDTH;
572 radeon_crtc->max_cursor_height = CURSOR_HEIGHT; 572 radeon_crtc->max_cursor_height = CURSOR_HEIGHT;
573 } 573 }
574 dev->mode_config.cursor_width = radeon_crtc->max_cursor_width;
575 dev->mode_config.cursor_height = radeon_crtc->max_cursor_height;
574 576
575#if 0 577#if 0
576 radeon_crtc->mode_set.crtc = &radeon_crtc->base; 578 radeon_crtc->mode_set.crtc = &radeon_crtc->base;
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index ec8c388eec17..f633c2782170 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -78,9 +78,10 @@
78 * 2.34.0 - Add CIK tiling mode array query 78 * 2.34.0 - Add CIK tiling mode array query
79 * 2.35.0 - Add CIK macrotile mode array query 79 * 2.35.0 - Add CIK macrotile mode array query
80 * 2.36.0 - Fix CIK DCE tiling setup 80 * 2.36.0 - Fix CIK DCE tiling setup
81 * 2.37.0 - allow GS ring setup on r6xx/r7xx
81 */ 82 */
82#define KMS_DRIVER_MAJOR 2 83#define KMS_DRIVER_MAJOR 2
83#define KMS_DRIVER_MINOR 36 84#define KMS_DRIVER_MINOR 37
84#define KMS_DRIVER_PATCHLEVEL 0 85#define KMS_DRIVER_PATCHLEVEL 0
85int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags); 86int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags);
86int radeon_driver_unload_kms(struct drm_device *dev); 87int radeon_driver_unload_kms(struct drm_device *dev);
@@ -402,11 +403,15 @@ static int radeon_pmops_runtime_suspend(struct device *dev)
402 struct drm_device *drm_dev = pci_get_drvdata(pdev); 403 struct drm_device *drm_dev = pci_get_drvdata(pdev);
403 int ret; 404 int ret;
404 405
405 if (radeon_runtime_pm == 0) 406 if (radeon_runtime_pm == 0) {
406 return -EINVAL; 407 pm_runtime_forbid(dev);
408 return -EBUSY;
409 }
407 410
408 if (radeon_runtime_pm == -1 && !radeon_is_px()) 411 if (radeon_runtime_pm == -1 && !radeon_is_px()) {
409 return -EINVAL; 412 pm_runtime_forbid(dev);
413 return -EBUSY;
414 }
410 415
411 drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; 416 drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
412 drm_kms_helper_poll_disable(drm_dev); 417 drm_kms_helper_poll_disable(drm_dev);
@@ -455,12 +460,15 @@ static int radeon_pmops_runtime_idle(struct device *dev)
455 struct drm_device *drm_dev = pci_get_drvdata(pdev); 460 struct drm_device *drm_dev = pci_get_drvdata(pdev);
456 struct drm_crtc *crtc; 461 struct drm_crtc *crtc;
457 462
458 if (radeon_runtime_pm == 0) 463 if (radeon_runtime_pm == 0) {
464 pm_runtime_forbid(dev);
459 return -EBUSY; 465 return -EBUSY;
466 }
460 467
461 /* are we PX enabled? */ 468 /* are we PX enabled? */
462 if (radeon_runtime_pm == -1 && !radeon_is_px()) { 469 if (radeon_runtime_pm == -1 && !radeon_is_px()) {
463 DRM_DEBUG_DRIVER("failing to power off - not px\n"); 470 DRM_DEBUG_DRIVER("failing to power off - not px\n");
471 pm_runtime_forbid(dev);
464 return -EBUSY; 472 return -EBUSY;
465 } 473 }
466 474
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
index 114d1672d616..66ed3ea71440 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -33,6 +33,13 @@
33#include <linux/vga_switcheroo.h> 33#include <linux/vga_switcheroo.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
36
37#if defined(CONFIG_VGA_SWITCHEROO)
38bool radeon_is_px(void);
39#else
40static inline bool radeon_is_px(void) { return false; }
41#endif
42
36/** 43/**
37 * radeon_driver_unload_kms - Main unload function for KMS. 44 * radeon_driver_unload_kms - Main unload function for KMS.
38 * 45 *
@@ -130,7 +137,8 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
130 "Error during ACPI methods call\n"); 137 "Error during ACPI methods call\n");
131 } 138 }
132 139
133 if (radeon_runtime_pm != 0) { 140 if ((radeon_runtime_pm == 1) ||
141 ((radeon_runtime_pm == -1) && radeon_is_px())) {
134 pm_runtime_use_autosuspend(dev->dev); 142 pm_runtime_use_autosuspend(dev->dev);
135 pm_runtime_set_autosuspend_delay(dev->dev, 5000); 143 pm_runtime_set_autosuspend_delay(dev->dev, 5000);
136 pm_runtime_set_active(dev->dev); 144 pm_runtime_set_active(dev->dev);
@@ -537,6 +545,10 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
537 545
538 radeon_vm_init(rdev, &fpriv->vm); 546 radeon_vm_init(rdev, &fpriv->vm);
539 547
548 r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
549 if (r)
550 return r;
551
540 /* map the ib pool buffer read only into 552 /* map the ib pool buffer read only into
541 * virtual address space */ 553 * virtual address space */
542 bo_va = radeon_vm_bo_add(rdev, &fpriv->vm, 554 bo_va = radeon_vm_bo_add(rdev, &fpriv->vm,
@@ -544,6 +556,8 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
544 r = radeon_vm_bo_set_addr(rdev, bo_va, RADEON_VA_IB_OFFSET, 556 r = radeon_vm_bo_set_addr(rdev, bo_va, RADEON_VA_IB_OFFSET,
545 RADEON_VM_PAGE_READABLE | 557 RADEON_VM_PAGE_READABLE |
546 RADEON_VM_PAGE_SNOOPED); 558 RADEON_VM_PAGE_SNOOPED);
559
560 radeon_bo_unreserve(rdev->ring_tmp_bo.bo);
547 if (r) { 561 if (r) {
548 radeon_vm_fini(rdev, &fpriv->vm); 562 radeon_vm_fini(rdev, &fpriv->vm);
549 kfree(fpriv); 563 kfree(fpriv);
diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
index 1b783f0e6d3a..15e44a7281ab 100644
--- a/drivers/gpu/drm/radeon/radeon_ring.c
+++ b/drivers/gpu/drm/radeon/radeon_ring.c
@@ -139,7 +139,7 @@ int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib,
139 } 139 }
140 140
141 /* 64 dwords should be enough for fence too */ 141 /* 64 dwords should be enough for fence too */
142 r = radeon_ring_lock(rdev, ring, 64 + RADEON_NUM_RINGS * 8); 142 r = radeon_ring_lock(rdev, ring, 64 + RADEON_NUM_SYNCS * 8);
143 if (r) { 143 if (r) {
144 dev_err(rdev->dev, "scheduling IB failed (%d).\n", r); 144 dev_err(rdev->dev, "scheduling IB failed (%d).\n", r);
145 return r; 145 return r;
diff --git a/drivers/gpu/drm/radeon/radeon_semaphore.c b/drivers/gpu/drm/radeon/radeon_semaphore.c
index 2b42aa1914f2..9006b32d5eed 100644
--- a/drivers/gpu/drm/radeon/radeon_semaphore.c
+++ b/drivers/gpu/drm/radeon/radeon_semaphore.c
@@ -34,14 +34,15 @@
34int radeon_semaphore_create(struct radeon_device *rdev, 34int radeon_semaphore_create(struct radeon_device *rdev,
35 struct radeon_semaphore **semaphore) 35 struct radeon_semaphore **semaphore)
36{ 36{
37 uint32_t *cpu_addr;
37 int i, r; 38 int i, r;
38 39
39 *semaphore = kmalloc(sizeof(struct radeon_semaphore), GFP_KERNEL); 40 *semaphore = kmalloc(sizeof(struct radeon_semaphore), GFP_KERNEL);
40 if (*semaphore == NULL) { 41 if (*semaphore == NULL) {
41 return -ENOMEM; 42 return -ENOMEM;
42 } 43 }
43 r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo, 44 r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo, &(*semaphore)->sa_bo,
44 &(*semaphore)->sa_bo, 8, 8, true); 45 8 * RADEON_NUM_SYNCS, 8, true);
45 if (r) { 46 if (r) {
46 kfree(*semaphore); 47 kfree(*semaphore);
47 *semaphore = NULL; 48 *semaphore = NULL;
@@ -49,7 +50,10 @@ int radeon_semaphore_create(struct radeon_device *rdev,
49 } 50 }
50 (*semaphore)->waiters = 0; 51 (*semaphore)->waiters = 0;
51 (*semaphore)->gpu_addr = radeon_sa_bo_gpu_addr((*semaphore)->sa_bo); 52 (*semaphore)->gpu_addr = radeon_sa_bo_gpu_addr((*semaphore)->sa_bo);
52 *((uint64_t*)radeon_sa_bo_cpu_addr((*semaphore)->sa_bo)) = 0; 53
54 cpu_addr = radeon_sa_bo_cpu_addr((*semaphore)->sa_bo);
55 for (i = 0; i < RADEON_NUM_SYNCS; ++i)
56 cpu_addr[i] = 0;
53 57
54 for (i = 0; i < RADEON_NUM_RINGS; ++i) 58 for (i = 0; i < RADEON_NUM_RINGS; ++i)
55 (*semaphore)->sync_to[i] = NULL; 59 (*semaphore)->sync_to[i] = NULL;
@@ -125,6 +129,7 @@ int radeon_semaphore_sync_rings(struct radeon_device *rdev,
125 struct radeon_semaphore *semaphore, 129 struct radeon_semaphore *semaphore,
126 int ring) 130 int ring)
127{ 131{
132 unsigned count = 0;
128 int i, r; 133 int i, r;
129 134
130 for (i = 0; i < RADEON_NUM_RINGS; ++i) { 135 for (i = 0; i < RADEON_NUM_RINGS; ++i) {
@@ -140,6 +145,12 @@ int radeon_semaphore_sync_rings(struct radeon_device *rdev,
140 return -EINVAL; 145 return -EINVAL;
141 } 146 }
142 147
148 if (++count > RADEON_NUM_SYNCS) {
149 /* not enough room, wait manually */
150 radeon_fence_wait_locked(fence);
151 continue;
152 }
153
143 /* allocate enough space for sync command */ 154 /* allocate enough space for sync command */
144 r = radeon_ring_alloc(rdev, &rdev->ring[i], 16); 155 r = radeon_ring_alloc(rdev, &rdev->ring[i], 16);
145 if (r) { 156 if (r) {
@@ -164,6 +175,8 @@ int radeon_semaphore_sync_rings(struct radeon_device *rdev,
164 175
165 radeon_ring_commit(rdev, &rdev->ring[i]); 176 radeon_ring_commit(rdev, &rdev->ring[i]);
166 radeon_fence_note_sync(fence, ring); 177 radeon_fence_note_sync(fence, ring);
178
179 semaphore->gpu_addr += 8;
167 } 180 }
168 181
169 return 0; 182 return 0;
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 77f5b0c3edb8..040a2a10ea17 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -714,6 +714,9 @@ int radeon_ttm_init(struct radeon_device *rdev)
714 DRM_ERROR("Failed initializing VRAM heap.\n"); 714 DRM_ERROR("Failed initializing VRAM heap.\n");
715 return r; 715 return r;
716 } 716 }
717 /* Change the size here instead of the init above so only lpfn is affected */
718 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
719
717 r = radeon_bo_create(rdev, 256 * 1024, PAGE_SIZE, true, 720 r = radeon_bo_create(rdev, 256 * 1024, PAGE_SIZE, true,
718 RADEON_GEM_DOMAIN_VRAM, 721 RADEON_GEM_DOMAIN_VRAM,
719 NULL, &rdev->stollen_vga_memory); 722 NULL, &rdev->stollen_vga_memory);
@@ -935,7 +938,7 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf,
935 while (size) { 938 while (size) {
936 loff_t p = *pos / PAGE_SIZE; 939 loff_t p = *pos / PAGE_SIZE;
937 unsigned off = *pos & ~PAGE_MASK; 940 unsigned off = *pos & ~PAGE_MASK;
938 ssize_t cur_size = min(size, PAGE_SIZE - off); 941 size_t cur_size = min_t(size_t, size, PAGE_SIZE - off);
939 struct page *page; 942 struct page *page;
940 void *ptr; 943 void *ptr;
941 944
diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c
index 6781fee1eaad..3e6804b2b2ef 100644
--- a/drivers/gpu/drm/radeon/radeon_uvd.c
+++ b/drivers/gpu/drm/radeon/radeon_uvd.c
@@ -171,6 +171,8 @@ void radeon_uvd_fini(struct radeon_device *rdev)
171 171
172 radeon_bo_unref(&rdev->uvd.vcpu_bo); 172 radeon_bo_unref(&rdev->uvd.vcpu_bo);
173 173
174 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX]);
175
174 release_firmware(rdev->uvd_fw); 176 release_firmware(rdev->uvd_fw);
175} 177}
176 178
diff --git a/drivers/gpu/drm/radeon/reg_srcs/r600 b/drivers/gpu/drm/radeon/reg_srcs/r600
index 20bfbda7b3f1..ec0c6829c1dc 100644
--- a/drivers/gpu/drm/radeon/reg_srcs/r600
+++ b/drivers/gpu/drm/radeon/reg_srcs/r600
@@ -18,6 +18,7 @@ r600 0x9400
180x00028A3C VGT_GROUP_VECT_1_FMT_CNTL 180x00028A3C VGT_GROUP_VECT_1_FMT_CNTL
190x00028A40 VGT_GS_MODE 190x00028A40 VGT_GS_MODE
200x00028A6C VGT_GS_OUT_PRIM_TYPE 200x00028A6C VGT_GS_OUT_PRIM_TYPE
210x00028B38 VGT_GS_MAX_VERT_OUT
210x000088C8 VGT_GS_PER_ES 220x000088C8 VGT_GS_PER_ES
220x000088E8 VGT_GS_PER_VS 230x000088E8 VGT_GS_PER_VS
230x000088D4 VGT_GS_VERTEX_REUSE 240x000088D4 VGT_GS_VERTEX_REUSE
diff --git a/drivers/gpu/drm/radeon/rs400.c b/drivers/gpu/drm/radeon/rs400.c
index b5c2369cda2f..130d5cc50d43 100644
--- a/drivers/gpu/drm/radeon/rs400.c
+++ b/drivers/gpu/drm/radeon/rs400.c
@@ -474,8 +474,6 @@ int rs400_resume(struct radeon_device *rdev)
474 /* Initialize surface registers */ 474 /* Initialize surface registers */
475 radeon_surface_init(rdev); 475 radeon_surface_init(rdev);
476 476
477 radeon_pm_resume(rdev);
478
479 rdev->accel_working = true; 477 rdev->accel_working = true;
480 r = rs400_startup(rdev); 478 r = rs400_startup(rdev);
481 if (r) { 479 if (r) {
diff --git a/drivers/gpu/drm/radeon/rs600.c b/drivers/gpu/drm/radeon/rs600.c
index fdcde7693032..72d3616de08e 100644
--- a/drivers/gpu/drm/radeon/rs600.c
+++ b/drivers/gpu/drm/radeon/rs600.c
@@ -1048,8 +1048,6 @@ int rs600_resume(struct radeon_device *rdev)
1048 /* Initialize surface registers */ 1048 /* Initialize surface registers */
1049 radeon_surface_init(rdev); 1049 radeon_surface_init(rdev);
1050 1050
1051 radeon_pm_resume(rdev);
1052
1053 rdev->accel_working = true; 1051 rdev->accel_working = true;
1054 r = rs600_startup(rdev); 1052 r = rs600_startup(rdev);
1055 if (r) { 1053 if (r) {
diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
index 35950738bd5e..3462b64369bf 100644
--- a/drivers/gpu/drm/radeon/rs690.c
+++ b/drivers/gpu/drm/radeon/rs690.c
@@ -756,8 +756,6 @@ int rs690_resume(struct radeon_device *rdev)
756 /* Initialize surface registers */ 756 /* Initialize surface registers */
757 radeon_surface_init(rdev); 757 radeon_surface_init(rdev);
758 758
759 radeon_pm_resume(rdev);
760
761 rdev->accel_working = true; 759 rdev->accel_working = true;
762 r = rs690_startup(rdev); 760 r = rs690_startup(rdev);
763 if (r) { 761 if (r) {
diff --git a/drivers/gpu/drm/radeon/rv515.c b/drivers/gpu/drm/radeon/rv515.c
index 98e8138ff779..237dd29d9f1c 100644
--- a/drivers/gpu/drm/radeon/rv515.c
+++ b/drivers/gpu/drm/radeon/rv515.c
@@ -586,8 +586,6 @@ int rv515_resume(struct radeon_device *rdev)
586 /* Initialize surface registers */ 586 /* Initialize surface registers */
587 radeon_surface_init(rdev); 587 radeon_surface_init(rdev);
588 588
589 radeon_pm_resume(rdev);
590
591 rdev->accel_working = true; 589 rdev->accel_working = true;
592 r = rv515_startup(rdev); 590 r = rv515_startup(rdev);
593 if (r) { 591 if (r) {
diff --git a/drivers/gpu/drm/radeon/rv770.c b/drivers/gpu/drm/radeon/rv770.c
index 6c772e58c784..fef310773aad 100644
--- a/drivers/gpu/drm/radeon/rv770.c
+++ b/drivers/gpu/drm/radeon/rv770.c
@@ -1811,7 +1811,8 @@ int rv770_resume(struct radeon_device *rdev)
1811 /* init golden registers */ 1811 /* init golden registers */
1812 rv770_init_golden_registers(rdev); 1812 rv770_init_golden_registers(rdev);
1813 1813
1814 radeon_pm_resume(rdev); 1814 if (rdev->pm.pm_method == PM_METHOD_DPM)
1815 radeon_pm_resume(rdev);
1815 1816
1816 rdev->accel_working = true; 1817 rdev->accel_working = true;
1817 r = rv770_startup(rdev); 1818 r = rv770_startup(rdev);
@@ -1955,9 +1956,9 @@ void rv770_fini(struct radeon_device *rdev)
1955 radeon_wb_fini(rdev); 1956 radeon_wb_fini(rdev);
1956 radeon_ib_pool_fini(rdev); 1957 radeon_ib_pool_fini(rdev);
1957 radeon_irq_kms_fini(rdev); 1958 radeon_irq_kms_fini(rdev);
1958 rv770_pcie_gart_fini(rdev);
1959 uvd_v1_0_fini(rdev); 1959 uvd_v1_0_fini(rdev);
1960 radeon_uvd_fini(rdev); 1960 radeon_uvd_fini(rdev);
1961 rv770_pcie_gart_fini(rdev);
1961 r600_vram_scratch_fini(rdev); 1962 r600_vram_scratch_fini(rdev);
1962 radeon_gem_fini(rdev); 1963 radeon_gem_fini(rdev);
1963 radeon_fence_driver_fini(rdev); 1964 radeon_fence_driver_fini(rdev);
diff --git a/drivers/gpu/drm/radeon/rv770_dpm.c b/drivers/gpu/drm/radeon/rv770_dpm.c
index 80c595aba359..b5f63f5e22a3 100644
--- a/drivers/gpu/drm/radeon/rv770_dpm.c
+++ b/drivers/gpu/drm/radeon/rv770_dpm.c
@@ -2174,7 +2174,6 @@ static void rv7xx_parse_pplib_clock_info(struct radeon_device *rdev,
2174 struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev); 2174 struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
2175 struct rv7xx_ps *ps = rv770_get_ps(rps); 2175 struct rv7xx_ps *ps = rv770_get_ps(rps);
2176 u32 sclk, mclk; 2176 u32 sclk, mclk;
2177 u16 vddc;
2178 struct rv7xx_pl *pl; 2177 struct rv7xx_pl *pl;
2179 2178
2180 switch (index) { 2179 switch (index) {
@@ -2214,8 +2213,8 @@ static void rv7xx_parse_pplib_clock_info(struct radeon_device *rdev,
2214 2213
2215 /* patch up vddc if necessary */ 2214 /* patch up vddc if necessary */
2216 if (pl->vddc == 0xff01) { 2215 if (pl->vddc == 0xff01) {
2217 if (radeon_atom_get_max_vddc(rdev, 0, 0, &vddc) == 0) 2216 if (pi->max_vddc)
2218 pl->vddc = vddc; 2217 pl->vddc = pi->max_vddc;
2219 } 2218 }
2220 2219
2221 if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) { 2220 if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) {
@@ -2527,14 +2526,7 @@ u32 rv770_dpm_get_mclk(struct radeon_device *rdev, bool low)
2527bool rv770_dpm_vblank_too_short(struct radeon_device *rdev) 2526bool rv770_dpm_vblank_too_short(struct radeon_device *rdev)
2528{ 2527{
2529 u32 vblank_time = r600_dpm_get_vblank_time(rdev); 2528 u32 vblank_time = r600_dpm_get_vblank_time(rdev);
2530 u32 switch_limit = 300; 2529 u32 switch_limit = 200; /* 300 */
2531
2532 /* quirks */
2533 /* ASUS K70AF */
2534 if ((rdev->pdev->device == 0x9553) &&
2535 (rdev->pdev->subsystem_vendor == 0x1043) &&
2536 (rdev->pdev->subsystem_device == 0x1c42))
2537 switch_limit = 200;
2538 2530
2539 /* RV770 */ 2531 /* RV770 */
2540 /* mclk switching doesn't seem to work reliably on desktop RV770s */ 2532 /* mclk switching doesn't seem to work reliably on desktop RV770s */
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index 09ec4f6c53bb..9a124d0608b3 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -6338,6 +6338,10 @@ restart_ih:
6338 break; 6338 break;
6339 } 6339 }
6340 break; 6340 break;
6341 case 124: /* UVD */
6342 DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
6343 radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
6344 break;
6341 case 146: 6345 case 146:
6342 case 147: 6346 case 147:
6343 addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR); 6347 addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
@@ -6614,7 +6618,8 @@ int si_resume(struct radeon_device *rdev)
6614 /* init golden registers */ 6618 /* init golden registers */
6615 si_init_golden_registers(rdev); 6619 si_init_golden_registers(rdev);
6616 6620
6617 radeon_pm_resume(rdev); 6621 if (rdev->pm.pm_method == PM_METHOD_DPM)
6622 radeon_pm_resume(rdev);
6618 6623
6619 rdev->accel_working = true; 6624 rdev->accel_working = true;
6620 r = si_startup(rdev); 6625 r = si_startup(rdev);
diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
index 0471501338fb..0a2f5b4bca43 100644
--- a/drivers/gpu/drm/radeon/si_dpm.c
+++ b/drivers/gpu/drm/radeon/si_dpm.c
@@ -2395,7 +2395,7 @@ static int si_populate_sq_ramping_values(struct radeon_device *rdev,
2395 if (SISLANDS_DPM2_SQ_RAMP_STI_SIZE > (STI_SIZE_MASK >> STI_SIZE_SHIFT)) 2395 if (SISLANDS_DPM2_SQ_RAMP_STI_SIZE > (STI_SIZE_MASK >> STI_SIZE_SHIFT))
2396 enable_sq_ramping = false; 2396 enable_sq_ramping = false;
2397 2397
2398 if (SISLANDS_DPM2_SQ_RAMP_LTI_RATIO <= (LTI_RATIO_MASK >> LTI_RATIO_SHIFT)) 2398 if (SISLANDS_DPM2_SQ_RAMP_LTI_RATIO > (LTI_RATIO_MASK >> LTI_RATIO_SHIFT))
2399 enable_sq_ramping = false; 2399 enable_sq_ramping = false;
2400 2400
2401 for (i = 0; i < state->performance_level_count; i++) { 2401 for (i = 0; i < state->performance_level_count; i++) {
@@ -6472,7 +6472,8 @@ void si_dpm_fini(struct radeon_device *rdev)
6472void si_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev, 6472void si_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
6473 struct seq_file *m) 6473 struct seq_file *m)
6474{ 6474{
6475 struct radeon_ps *rps = rdev->pm.dpm.current_ps; 6475 struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
6476 struct radeon_ps *rps = &eg_pi->current_rps;
6476 struct ni_ps *ps = ni_get_ps(rps); 6477 struct ni_ps *ps = ni_get_ps(rps);
6477 struct rv7xx_pl *pl; 6478 struct rv7xx_pl *pl;
6478 u32 current_index = 6479 u32 current_index =
diff --git a/drivers/gpu/drm/radeon/sumo_dpm.c b/drivers/gpu/drm/radeon/sumo_dpm.c
index f121efe12dc5..8b47b3cd0357 100644
--- a/drivers/gpu/drm/radeon/sumo_dpm.c
+++ b/drivers/gpu/drm/radeon/sumo_dpm.c
@@ -1807,7 +1807,7 @@ void sumo_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev
1807 struct seq_file *m) 1807 struct seq_file *m)
1808{ 1808{
1809 struct sumo_power_info *pi = sumo_get_pi(rdev); 1809 struct sumo_power_info *pi = sumo_get_pi(rdev);
1810 struct radeon_ps *rps = rdev->pm.dpm.current_ps; 1810 struct radeon_ps *rps = &pi->current_rps;
1811 struct sumo_ps *ps = sumo_get_ps(rps); 1811 struct sumo_ps *ps = sumo_get_ps(rps);
1812 struct sumo_pl *pl; 1812 struct sumo_pl *pl;
1813 u32 current_index = 1813 u32 current_index =
diff --git a/drivers/gpu/drm/radeon/trinity_dpm.c b/drivers/gpu/drm/radeon/trinity_dpm.c
index 2d447192d6f7..2da0e17eb960 100644
--- a/drivers/gpu/drm/radeon/trinity_dpm.c
+++ b/drivers/gpu/drm/radeon/trinity_dpm.c
@@ -1926,7 +1926,8 @@ void trinity_dpm_print_power_state(struct radeon_device *rdev,
1926void trinity_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev, 1926void trinity_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
1927 struct seq_file *m) 1927 struct seq_file *m)
1928{ 1928{
1929 struct radeon_ps *rps = rdev->pm.dpm.current_ps; 1929 struct trinity_power_info *pi = trinity_get_pi(rdev);
1930 struct radeon_ps *rps = &pi->current_rps;
1930 struct trinity_ps *ps = trinity_get_ps(rps); 1931 struct trinity_ps *ps = trinity_get_ps(rps);
1931 struct trinity_pl *pl; 1932 struct trinity_pl *pl;
1932 u32 current_index = 1933 u32 current_index =
diff --git a/drivers/gpu/drm/radeon/uvd_v2_2.c b/drivers/gpu/drm/radeon/uvd_v2_2.c
index 824550db3fed..d1771004cb52 100644
--- a/drivers/gpu/drm/radeon/uvd_v2_2.c
+++ b/drivers/gpu/drm/radeon/uvd_v2_2.c
@@ -57,7 +57,6 @@ void uvd_v2_2_fence_emit(struct radeon_device *rdev,
57 radeon_ring_write(ring, 0); 57 radeon_ring_write(ring, 0);
58 radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_CMD, 0)); 58 radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_CMD, 0));
59 radeon_ring_write(ring, 2); 59 radeon_ring_write(ring, 2);
60 return;
61} 60}
62 61
63/** 62/**
diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
index 88a529008ce0..c71594754f46 100644
--- a/drivers/gpu/drm/tegra/drm.c
+++ b/drivers/gpu/drm/tegra/drm.c
@@ -104,7 +104,7 @@ static void tegra_drm_context_free(struct tegra_drm_context *context)
104 104
105static void tegra_drm_lastclose(struct drm_device *drm) 105static void tegra_drm_lastclose(struct drm_device *drm)
106{ 106{
107#ifdef CONFIG_TEGRA_DRM_FBDEV 107#ifdef CONFIG_DRM_TEGRA_FBDEV
108 struct tegra_drm *tegra = drm->dev_private; 108 struct tegra_drm *tegra = drm->dev_private;
109 109
110 tegra_fbdev_restore_mode(tegra->fbdev); 110 tegra_fbdev_restore_mode(tegra->fbdev);
diff --git a/drivers/gpu/drm/tegra/rgb.c b/drivers/gpu/drm/tegra/rgb.c
index 338f7f6561d7..0266fb40479e 100644
--- a/drivers/gpu/drm/tegra/rgb.c
+++ b/drivers/gpu/drm/tegra/rgb.c
@@ -15,6 +15,7 @@
15struct tegra_rgb { 15struct tegra_rgb {
16 struct tegra_output output; 16 struct tegra_output output;
17 struct tegra_dc *dc; 17 struct tegra_dc *dc;
18 bool enabled;
18 19
19 struct clk *clk_parent; 20 struct clk *clk_parent;
20 struct clk *clk; 21 struct clk *clk;
@@ -89,6 +90,9 @@ static int tegra_output_rgb_enable(struct tegra_output *output)
89 struct tegra_rgb *rgb = to_rgb(output); 90 struct tegra_rgb *rgb = to_rgb(output);
90 unsigned long value; 91 unsigned long value;
91 92
93 if (rgb->enabled)
94 return 0;
95
92 tegra_dc_write_regs(rgb->dc, rgb_enable, ARRAY_SIZE(rgb_enable)); 96 tegra_dc_write_regs(rgb->dc, rgb_enable, ARRAY_SIZE(rgb_enable));
93 97
94 value = DE_SELECT_ACTIVE | DE_CONTROL_NORMAL; 98 value = DE_SELECT_ACTIVE | DE_CONTROL_NORMAL;
@@ -122,6 +126,8 @@ static int tegra_output_rgb_enable(struct tegra_output *output)
122 tegra_dc_writel(rgb->dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL); 126 tegra_dc_writel(rgb->dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
123 tegra_dc_writel(rgb->dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL); 127 tegra_dc_writel(rgb->dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
124 128
129 rgb->enabled = true;
130
125 return 0; 131 return 0;
126} 132}
127 133
@@ -130,6 +136,9 @@ static int tegra_output_rgb_disable(struct tegra_output *output)
130 struct tegra_rgb *rgb = to_rgb(output); 136 struct tegra_rgb *rgb = to_rgb(output);
131 unsigned long value; 137 unsigned long value;
132 138
139 if (!rgb->enabled)
140 return 0;
141
133 value = tegra_dc_readl(rgb->dc, DC_CMD_DISPLAY_POWER_CONTROL); 142 value = tegra_dc_readl(rgb->dc, DC_CMD_DISPLAY_POWER_CONTROL);
134 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE | 143 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
135 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE); 144 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
@@ -144,6 +153,8 @@ static int tegra_output_rgb_disable(struct tegra_output *output)
144 153
145 tegra_dc_write_regs(rgb->dc, rgb_disable, ARRAY_SIZE(rgb_disable)); 154 tegra_dc_write_regs(rgb->dc, rgb_disable, ARRAY_SIZE(rgb_disable));
146 155
156 rgb->enabled = false;
157
147 return 0; 158 return 0;
148} 159}
149 160
diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index 3302f99e7497..764be36397fd 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -126,6 +126,7 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,
126 agp_be->ttm.func = &ttm_agp_func; 126 agp_be->ttm.func = &ttm_agp_func;
127 127
128 if (ttm_tt_init(&agp_be->ttm, bdev, size, page_flags, dummy_read_page)) { 128 if (ttm_tt_init(&agp_be->ttm, bdev, size, page_flags, dummy_read_page)) {
129 kfree(agp_be);
129 return NULL; 130 return NULL;
130 } 131 }
131 132
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index a06651309388..214b7992a3aa 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -351,9 +351,11 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
351 351
352moved: 352moved:
353 if (bo->evicted) { 353 if (bo->evicted) {
354 ret = bdev->driver->invalidate_caches(bdev, bo->mem.placement); 354 if (bdev->driver->invalidate_caches) {
355 if (ret) 355 ret = bdev->driver->invalidate_caches(bdev, bo->mem.placement);
356 pr_err("Can not flush read caches\n"); 356 if (ret)
357 pr_err("Can not flush read caches\n");
358 }
357 bo->evicted = false; 359 bo->evicted = false;
358 } 360 }
359 361
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 801231c9ae48..0ce48e5a9cb4 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -339,11 +339,13 @@ int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
339 vma->vm_private_data = bo; 339 vma->vm_private_data = bo;
340 340
341 /* 341 /*
342 * PFNMAP is faster than MIXEDMAP due to reduced page 342 * We'd like to use VM_PFNMAP on shared mappings, where
343 * administration. So use MIXEDMAP only if private VMA, where 343 * (vma->vm_flags & VM_SHARED) != 0, for performance reasons,
344 * we need to support COW. 344 * but for some reason VM_PFNMAP + x86 PAT + write-combine is very
345 * bad for performance. Until that has been sorted out, use
346 * VM_MIXEDMAP on all mappings. See freedesktop.org bug #75719
345 */ 347 */
346 vma->vm_flags |= (vma->vm_flags & VM_SHARED) ? VM_PFNMAP : VM_MIXEDMAP; 348 vma->vm_flags |= VM_MIXEDMAP;
347 vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP; 349 vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
348 return 0; 350 return 0;
349out_unref: 351out_unref:
@@ -359,7 +361,7 @@ int ttm_fbdev_mmap(struct vm_area_struct *vma, struct ttm_buffer_object *bo)
359 361
360 vma->vm_ops = &ttm_bo_vm_ops; 362 vma->vm_ops = &ttm_bo_vm_ops;
361 vma->vm_private_data = ttm_bo_reference(bo); 363 vma->vm_private_data = ttm_bo_reference(bo);
362 vma->vm_flags |= (vma->vm_flags & VM_SHARED) ? VM_PFNMAP : VM_MIXEDMAP; 364 vma->vm_flags |= VM_MIXEDMAP;
363 vma->vm_flags |= VM_IO | VM_DONTEXPAND; 365 vma->vm_flags |= VM_IO | VM_DONTEXPAND;
364 return 0; 366 return 0;
365} 367}
diff --git a/drivers/gpu/drm/ttm/ttm_object.c b/drivers/gpu/drm/ttm/ttm_object.c
index 37079859afc8..53b51c4e671a 100644
--- a/drivers/gpu/drm/ttm/ttm_object.c
+++ b/drivers/gpu/drm/ttm/ttm_object.c
@@ -292,7 +292,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
292 292
293 if (ret == 0) { 293 if (ret == 0) {
294 ref = drm_hash_entry(hash, struct ttm_ref_object, hash); 294 ref = drm_hash_entry(hash, struct ttm_ref_object, hash);
295 if (!kref_get_unless_zero(&ref->kref)) { 295 if (kref_get_unless_zero(&ref->kref)) {
296 rcu_read_unlock(); 296 rcu_read_unlock();
297 break; 297 break;
298 } 298 }
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 9af99084b344..75f319090043 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -380,6 +380,9 @@ static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
380 pgoff_t i; 380 pgoff_t i;
381 struct page **page = ttm->pages; 381 struct page **page = ttm->pages;
382 382
383 if (ttm->page_flags & TTM_PAGE_FLAG_SG)
384 return;
385
383 for (i = 0; i < ttm->num_pages; ++i) { 386 for (i = 0; i < ttm->num_pages; ++i) {
384 (*page)->mapping = NULL; 387 (*page)->mapping = NULL;
385 (*page++)->index = 0; 388 (*page++)->index = 0;
diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c
index 8d67b943ac05..0394811251bd 100644
--- a/drivers/gpu/drm/udl/udl_gem.c
+++ b/drivers/gpu/drm/udl/udl_gem.c
@@ -177,8 +177,10 @@ void udl_gem_free_object(struct drm_gem_object *gem_obj)
177 if (obj->vmapping) 177 if (obj->vmapping)
178 udl_gem_vunmap(obj); 178 udl_gem_vunmap(obj);
179 179
180 if (gem_obj->import_attach) 180 if (gem_obj->import_attach) {
181 drm_prime_gem_destroy(gem_obj, obj->sg); 181 drm_prime_gem_destroy(gem_obj, obj->sg);
182 put_device(gem_obj->dev->dev);
183 }
182 184
183 if (obj->pages) 185 if (obj->pages)
184 udl_gem_put_pages(obj); 186 udl_gem_put_pages(obj);
@@ -256,9 +258,12 @@ struct drm_gem_object *udl_gem_prime_import(struct drm_device *dev,
256 int ret; 258 int ret;
257 259
258 /* need to attach */ 260 /* need to attach */
261 get_device(dev->dev);
259 attach = dma_buf_attach(dma_buf, dev->dev); 262 attach = dma_buf_attach(dma_buf, dev->dev);
260 if (IS_ERR(attach)) 263 if (IS_ERR(attach)) {
264 put_device(dev->dev);
261 return ERR_CAST(attach); 265 return ERR_CAST(attach);
266 }
262 267
263 get_dma_buf(dma_buf); 268 get_dma_buf(dma_buf);
264 269
@@ -282,6 +287,6 @@ fail_unmap:
282fail_detach: 287fail_detach:
283 dma_buf_detach(dma_buf, attach); 288 dma_buf_detach(dma_buf, attach);
284 dma_buf_put(dma_buf); 289 dma_buf_put(dma_buf);
285 290 put_device(dev->dev);
286 return ERR_PTR(ret); 291 return ERR_PTR(ret);
287} 292}
diff --git a/drivers/gpu/drm/vmwgfx/svga3d_reg.h b/drivers/gpu/drm/vmwgfx/svga3d_reg.h
index d95335cb90bd..f58dc7dd15c5 100644
--- a/drivers/gpu/drm/vmwgfx/svga3d_reg.h
+++ b/drivers/gpu/drm/vmwgfx/svga3d_reg.h
@@ -261,12 +261,7 @@ typedef enum SVGA3dSurfaceFormat {
261 /* Planar video formats. */ 261 /* Planar video formats. */
262 SVGA3D_YV12 = 121, 262 SVGA3D_YV12 = 121,
263 263
264 /* Shader constant formats. */ 264 SVGA3D_FORMAT_MAX = 122,
265 SVGA3D_SURFACE_SHADERCONST_FLOAT = 122,
266 SVGA3D_SURFACE_SHADERCONST_INT = 123,
267 SVGA3D_SURFACE_SHADERCONST_BOOL = 124,
268
269 SVGA3D_FORMAT_MAX = 125,
270} SVGA3dSurfaceFormat; 265} SVGA3dSurfaceFormat;
271 266
272typedef uint32 SVGA3dColor; /* a, r, g, b */ 267typedef uint32 SVGA3dColor; /* a, r, g, b */
@@ -1223,9 +1218,19 @@ typedef enum {
1223#define SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL 1129 1218#define SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL 1129
1224 1219
1225#define SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE 1130 1220#define SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE 1130
1226 1221#define SVGA_3D_CMD_GB_SCREEN_DMA 1131
1222#define SVGA_3D_CMD_BIND_GB_SURFACE_WITH_PITCH 1132
1223#define SVGA_3D_CMD_GB_MOB_FENCE 1133
1224#define SVGA_3D_CMD_DEFINE_GB_SURFACE_V2 1134
1227#define SVGA_3D_CMD_DEFINE_GB_MOB64 1135 1225#define SVGA_3D_CMD_DEFINE_GB_MOB64 1135
1228#define SVGA_3D_CMD_REDEFINE_GB_MOB64 1136 1226#define SVGA_3D_CMD_REDEFINE_GB_MOB64 1136
1227#define SVGA_3D_CMD_NOP_ERROR 1137
1228
1229#define SVGA_3D_CMD_RESERVED1 1138
1230#define SVGA_3D_CMD_RESERVED2 1139
1231#define SVGA_3D_CMD_RESERVED3 1140
1232#define SVGA_3D_CMD_RESERVED4 1141
1233#define SVGA_3D_CMD_RESERVED5 1142
1229 1234
1230#define SVGA_3D_CMD_MAX 1142 1235#define SVGA_3D_CMD_MAX 1142
1231#define SVGA_3D_CMD_FUTURE_MAX 3000 1236#define SVGA_3D_CMD_FUTURE_MAX 3000
@@ -1973,8 +1978,7 @@ struct {
1973 uint32 sizeInBytes; 1978 uint32 sizeInBytes;
1974 uint32 validSizeInBytes; 1979 uint32 validSizeInBytes;
1975 SVGAMobFormat ptDepth; 1980 SVGAMobFormat ptDepth;
1976} 1981} __packed
1977__attribute__((__packed__))
1978SVGA3dCmdSetOTableBase; /* SVGA_3D_CMD_SET_OTABLE_BASE */ 1982SVGA3dCmdSetOTableBase; /* SVGA_3D_CMD_SET_OTABLE_BASE */
1979 1983
1980typedef 1984typedef
@@ -1984,15 +1988,13 @@ struct {
1984 uint32 sizeInBytes; 1988 uint32 sizeInBytes;
1985 uint32 validSizeInBytes; 1989 uint32 validSizeInBytes;
1986 SVGAMobFormat ptDepth; 1990 SVGAMobFormat ptDepth;
1987} 1991} __packed
1988__attribute__((__packed__))
1989SVGA3dCmdSetOTableBase64; /* SVGA_3D_CMD_SET_OTABLE_BASE64 */ 1992SVGA3dCmdSetOTableBase64; /* SVGA_3D_CMD_SET_OTABLE_BASE64 */
1990 1993
1991typedef 1994typedef
1992struct { 1995struct {
1993 SVGAOTableType type; 1996 SVGAOTableType type;
1994} 1997} __packed
1995__attribute__((__packed__))
1996SVGA3dCmdReadbackOTable; /* SVGA_3D_CMD_READBACK_OTABLE */ 1998SVGA3dCmdReadbackOTable; /* SVGA_3D_CMD_READBACK_OTABLE */
1997 1999
1998/* 2000/*
@@ -2005,8 +2007,7 @@ struct SVGA3dCmdDefineGBMob {
2005 SVGAMobFormat ptDepth; 2007 SVGAMobFormat ptDepth;
2006 PPN base; 2008 PPN base;
2007 uint32 sizeInBytes; 2009 uint32 sizeInBytes;
2008} 2010} __packed
2009__attribute__((__packed__))
2010SVGA3dCmdDefineGBMob; /* SVGA_3D_CMD_DEFINE_GB_MOB */ 2011SVGA3dCmdDefineGBMob; /* SVGA_3D_CMD_DEFINE_GB_MOB */
2011 2012
2012 2013
@@ -2017,8 +2018,7 @@ SVGA3dCmdDefineGBMob; /* SVGA_3D_CMD_DEFINE_GB_MOB */
2017typedef 2018typedef
2018struct SVGA3dCmdDestroyGBMob { 2019struct SVGA3dCmdDestroyGBMob {
2019 SVGAMobId mobid; 2020 SVGAMobId mobid;
2020} 2021} __packed
2021__attribute__((__packed__))
2022SVGA3dCmdDestroyGBMob; /* SVGA_3D_CMD_DESTROY_GB_MOB */ 2022SVGA3dCmdDestroyGBMob; /* SVGA_3D_CMD_DESTROY_GB_MOB */
2023 2023
2024/* 2024/*
@@ -2031,8 +2031,7 @@ struct SVGA3dCmdRedefineGBMob {
2031 SVGAMobFormat ptDepth; 2031 SVGAMobFormat ptDepth;
2032 PPN base; 2032 PPN base;
2033 uint32 sizeInBytes; 2033 uint32 sizeInBytes;
2034} 2034} __packed
2035__attribute__((__packed__))
2036SVGA3dCmdRedefineGBMob; /* SVGA_3D_CMD_REDEFINE_GB_MOB */ 2035SVGA3dCmdRedefineGBMob; /* SVGA_3D_CMD_REDEFINE_GB_MOB */
2037 2036
2038/* 2037/*
@@ -2045,8 +2044,7 @@ struct SVGA3dCmdDefineGBMob64 {
2045 SVGAMobFormat ptDepth; 2044 SVGAMobFormat ptDepth;
2046 PPN64 base; 2045 PPN64 base;
2047 uint32 sizeInBytes; 2046 uint32 sizeInBytes;
2048} 2047} __packed
2049__attribute__((__packed__))
2050SVGA3dCmdDefineGBMob64; /* SVGA_3D_CMD_DEFINE_GB_MOB64 */ 2048SVGA3dCmdDefineGBMob64; /* SVGA_3D_CMD_DEFINE_GB_MOB64 */
2051 2049
2052/* 2050/*
@@ -2059,8 +2057,7 @@ struct SVGA3dCmdRedefineGBMob64 {
2059 SVGAMobFormat ptDepth; 2057 SVGAMobFormat ptDepth;
2060 PPN64 base; 2058 PPN64 base;
2061 uint32 sizeInBytes; 2059 uint32 sizeInBytes;
2062} 2060} __packed
2063__attribute__((__packed__))
2064SVGA3dCmdRedefineGBMob64; /* SVGA_3D_CMD_REDEFINE_GB_MOB64 */ 2061SVGA3dCmdRedefineGBMob64; /* SVGA_3D_CMD_REDEFINE_GB_MOB64 */
2065 2062
2066/* 2063/*
@@ -2070,8 +2067,7 @@ SVGA3dCmdRedefineGBMob64; /* SVGA_3D_CMD_REDEFINE_GB_MOB64 */
2070typedef 2067typedef
2071struct SVGA3dCmdUpdateGBMobMapping { 2068struct SVGA3dCmdUpdateGBMobMapping {
2072 SVGAMobId mobid; 2069 SVGAMobId mobid;
2073} 2070} __packed
2074__attribute__((__packed__))
2075SVGA3dCmdUpdateGBMobMapping; /* SVGA_3D_CMD_UPDATE_GB_MOB_MAPPING */ 2071SVGA3dCmdUpdateGBMobMapping; /* SVGA_3D_CMD_UPDATE_GB_MOB_MAPPING */
2076 2072
2077/* 2073/*
@@ -2087,7 +2083,8 @@ struct SVGA3dCmdDefineGBSurface {
2087 uint32 multisampleCount; 2083 uint32 multisampleCount;
2088 SVGA3dTextureFilter autogenFilter; 2084 SVGA3dTextureFilter autogenFilter;
2089 SVGA3dSize size; 2085 SVGA3dSize size;
2090} SVGA3dCmdDefineGBSurface; /* SVGA_3D_CMD_DEFINE_GB_SURFACE */ 2086} __packed
2087SVGA3dCmdDefineGBSurface; /* SVGA_3D_CMD_DEFINE_GB_SURFACE */
2091 2088
2092/* 2089/*
2093 * Destroy a guest-backed surface. 2090 * Destroy a guest-backed surface.
@@ -2096,7 +2093,8 @@ struct SVGA3dCmdDefineGBSurface {
2096typedef 2093typedef
2097struct SVGA3dCmdDestroyGBSurface { 2094struct SVGA3dCmdDestroyGBSurface {
2098 uint32 sid; 2095 uint32 sid;
2099} SVGA3dCmdDestroyGBSurface; /* SVGA_3D_CMD_DESTROY_GB_SURFACE */ 2096} __packed
2097SVGA3dCmdDestroyGBSurface; /* SVGA_3D_CMD_DESTROY_GB_SURFACE */
2100 2098
2101/* 2099/*
2102 * Bind a guest-backed surface to an object. 2100 * Bind a guest-backed surface to an object.
@@ -2106,7 +2104,8 @@ typedef
2106struct SVGA3dCmdBindGBSurface { 2104struct SVGA3dCmdBindGBSurface {
2107 uint32 sid; 2105 uint32 sid;
2108 SVGAMobId mobid; 2106 SVGAMobId mobid;
2109} SVGA3dCmdBindGBSurface; /* SVGA_3D_CMD_BIND_GB_SURFACE */ 2107} __packed
2108SVGA3dCmdBindGBSurface; /* SVGA_3D_CMD_BIND_GB_SURFACE */
2110 2109
2111/* 2110/*
2112 * Conditionally bind a mob to a guest backed surface if testMobid 2111 * Conditionally bind a mob to a guest backed surface if testMobid
@@ -2123,7 +2122,7 @@ struct{
2123 SVGAMobId testMobid; 2122 SVGAMobId testMobid;
2124 SVGAMobId mobid; 2123 SVGAMobId mobid;
2125 uint32 flags; 2124 uint32 flags;
2126} 2125} __packed
2127SVGA3dCmdCondBindGBSurface; /* SVGA_3D_CMD_COND_BIND_GB_SURFACE */ 2126SVGA3dCmdCondBindGBSurface; /* SVGA_3D_CMD_COND_BIND_GB_SURFACE */
2128 2127
2129/* 2128/*
@@ -2135,7 +2134,8 @@ typedef
2135struct SVGA3dCmdUpdateGBImage { 2134struct SVGA3dCmdUpdateGBImage {
2136 SVGA3dSurfaceImageId image; 2135 SVGA3dSurfaceImageId image;
2137 SVGA3dBox box; 2136 SVGA3dBox box;
2138} SVGA3dCmdUpdateGBImage; /* SVGA_3D_CMD_UPDATE_GB_IMAGE */ 2137} __packed
2138SVGA3dCmdUpdateGBImage; /* SVGA_3D_CMD_UPDATE_GB_IMAGE */
2139 2139
2140/* 2140/*
2141 * Update an entire guest-backed surface. 2141 * Update an entire guest-backed surface.
@@ -2145,7 +2145,8 @@ struct SVGA3dCmdUpdateGBImage {
2145typedef 2145typedef
2146struct SVGA3dCmdUpdateGBSurface { 2146struct SVGA3dCmdUpdateGBSurface {
2147 uint32 sid; 2147 uint32 sid;
2148} SVGA3dCmdUpdateGBSurface; /* SVGA_3D_CMD_UPDATE_GB_SURFACE */ 2148} __packed
2149SVGA3dCmdUpdateGBSurface; /* SVGA_3D_CMD_UPDATE_GB_SURFACE */
2149 2150
2150/* 2151/*
2151 * Readback an image in a guest-backed surface. 2152 * Readback an image in a guest-backed surface.
@@ -2155,7 +2156,8 @@ struct SVGA3dCmdUpdateGBSurface {
2155typedef 2156typedef
2156struct SVGA3dCmdReadbackGBImage { 2157struct SVGA3dCmdReadbackGBImage {
2157 SVGA3dSurfaceImageId image; 2158 SVGA3dSurfaceImageId image;
2158} SVGA3dCmdReadbackGBImage; /* SVGA_3D_CMD_READBACK_GB_IMAGE*/ 2159} __packed
2160SVGA3dCmdReadbackGBImage; /* SVGA_3D_CMD_READBACK_GB_IMAGE*/
2159 2161
2160/* 2162/*
2161 * Readback an entire guest-backed surface. 2163 * Readback an entire guest-backed surface.
@@ -2165,7 +2167,8 @@ struct SVGA3dCmdReadbackGBImage {
2165typedef 2167typedef
2166struct SVGA3dCmdReadbackGBSurface { 2168struct SVGA3dCmdReadbackGBSurface {
2167 uint32 sid; 2169 uint32 sid;
2168} SVGA3dCmdReadbackGBSurface; /* SVGA_3D_CMD_READBACK_GB_SURFACE */ 2170} __packed
2171SVGA3dCmdReadbackGBSurface; /* SVGA_3D_CMD_READBACK_GB_SURFACE */
2169 2172
2170/* 2173/*
2171 * Readback a sub rect of an image in a guest-backed surface. After 2174 * Readback a sub rect of an image in a guest-backed surface. After
@@ -2179,7 +2182,7 @@ struct SVGA3dCmdReadbackGBImagePartial {
2179 SVGA3dSurfaceImageId image; 2182 SVGA3dSurfaceImageId image;
2180 SVGA3dBox box; 2183 SVGA3dBox box;
2181 uint32 invertBox; 2184 uint32 invertBox;
2182} 2185} __packed
2183SVGA3dCmdReadbackGBImagePartial; /* SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL */ 2186SVGA3dCmdReadbackGBImagePartial; /* SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL */
2184 2187
2185/* 2188/*
@@ -2190,7 +2193,8 @@ SVGA3dCmdReadbackGBImagePartial; /* SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL */
2190typedef 2193typedef
2191struct SVGA3dCmdInvalidateGBImage { 2194struct SVGA3dCmdInvalidateGBImage {
2192 SVGA3dSurfaceImageId image; 2195 SVGA3dSurfaceImageId image;
2193} SVGA3dCmdInvalidateGBImage; /* SVGA_3D_CMD_INVALIDATE_GB_IMAGE */ 2196} __packed
2197SVGA3dCmdInvalidateGBImage; /* SVGA_3D_CMD_INVALIDATE_GB_IMAGE */
2194 2198
2195/* 2199/*
2196 * Invalidate an entire guest-backed surface. 2200 * Invalidate an entire guest-backed surface.
@@ -2200,7 +2204,8 @@ struct SVGA3dCmdInvalidateGBImage {
2200typedef 2204typedef
2201struct SVGA3dCmdInvalidateGBSurface { 2205struct SVGA3dCmdInvalidateGBSurface {
2202 uint32 sid; 2206 uint32 sid;
2203} SVGA3dCmdInvalidateGBSurface; /* SVGA_3D_CMD_INVALIDATE_GB_SURFACE */ 2207} __packed
2208SVGA3dCmdInvalidateGBSurface; /* SVGA_3D_CMD_INVALIDATE_GB_SURFACE */
2204 2209
2205/* 2210/*
2206 * Invalidate a sub rect of an image in a guest-backed surface. After 2211 * Invalidate a sub rect of an image in a guest-backed surface. After
@@ -2214,7 +2219,7 @@ struct SVGA3dCmdInvalidateGBImagePartial {
2214 SVGA3dSurfaceImageId image; 2219 SVGA3dSurfaceImageId image;
2215 SVGA3dBox box; 2220 SVGA3dBox box;
2216 uint32 invertBox; 2221 uint32 invertBox;
2217} 2222} __packed
2218SVGA3dCmdInvalidateGBImagePartial; /* SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL */ 2223SVGA3dCmdInvalidateGBImagePartial; /* SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL */
2219 2224
2220/* 2225/*
@@ -2224,7 +2229,8 @@ SVGA3dCmdInvalidateGBImagePartial; /* SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL */
2224typedef 2229typedef
2225struct SVGA3dCmdDefineGBContext { 2230struct SVGA3dCmdDefineGBContext {
2226 uint32 cid; 2231 uint32 cid;
2227} SVGA3dCmdDefineGBContext; /* SVGA_3D_CMD_DEFINE_GB_CONTEXT */ 2232} __packed
2233SVGA3dCmdDefineGBContext; /* SVGA_3D_CMD_DEFINE_GB_CONTEXT */
2228 2234
2229/* 2235/*
2230 * Destroy a guest-backed context. 2236 * Destroy a guest-backed context.
@@ -2233,7 +2239,8 @@ struct SVGA3dCmdDefineGBContext {
2233typedef 2239typedef
2234struct SVGA3dCmdDestroyGBContext { 2240struct SVGA3dCmdDestroyGBContext {
2235 uint32 cid; 2241 uint32 cid;
2236} SVGA3dCmdDestroyGBContext; /* SVGA_3D_CMD_DESTROY_GB_CONTEXT */ 2242} __packed
2243SVGA3dCmdDestroyGBContext; /* SVGA_3D_CMD_DESTROY_GB_CONTEXT */
2237 2244
2238/* 2245/*
2239 * Bind a guest-backed context. 2246 * Bind a guest-backed context.
@@ -2252,7 +2259,8 @@ struct SVGA3dCmdBindGBContext {
2252 uint32 cid; 2259 uint32 cid;
2253 SVGAMobId mobid; 2260 SVGAMobId mobid;
2254 uint32 validContents; 2261 uint32 validContents;
2255} SVGA3dCmdBindGBContext; /* SVGA_3D_CMD_BIND_GB_CONTEXT */ 2262} __packed
2263SVGA3dCmdBindGBContext; /* SVGA_3D_CMD_BIND_GB_CONTEXT */
2256 2264
2257/* 2265/*
2258 * Readback a guest-backed context. 2266 * Readback a guest-backed context.
@@ -2262,7 +2270,8 @@ struct SVGA3dCmdBindGBContext {
2262typedef 2270typedef
2263struct SVGA3dCmdReadbackGBContext { 2271struct SVGA3dCmdReadbackGBContext {
2264 uint32 cid; 2272 uint32 cid;
2265} SVGA3dCmdReadbackGBContext; /* SVGA_3D_CMD_READBACK_GB_CONTEXT */ 2273} __packed
2274SVGA3dCmdReadbackGBContext; /* SVGA_3D_CMD_READBACK_GB_CONTEXT */
2266 2275
2267/* 2276/*
2268 * Invalidate a guest-backed context. 2277 * Invalidate a guest-backed context.
@@ -2270,7 +2279,8 @@ struct SVGA3dCmdReadbackGBContext {
2270typedef 2279typedef
2271struct SVGA3dCmdInvalidateGBContext { 2280struct SVGA3dCmdInvalidateGBContext {
2272 uint32 cid; 2281 uint32 cid;
2273} SVGA3dCmdInvalidateGBContext; /* SVGA_3D_CMD_INVALIDATE_GB_CONTEXT */ 2282} __packed
2283SVGA3dCmdInvalidateGBContext; /* SVGA_3D_CMD_INVALIDATE_GB_CONTEXT */
2274 2284
2275/* 2285/*
2276 * Define a guest-backed shader. 2286 * Define a guest-backed shader.
@@ -2281,7 +2291,8 @@ struct SVGA3dCmdDefineGBShader {
2281 uint32 shid; 2291 uint32 shid;
2282 SVGA3dShaderType type; 2292 SVGA3dShaderType type;
2283 uint32 sizeInBytes; 2293 uint32 sizeInBytes;
2284} SVGA3dCmdDefineGBShader; /* SVGA_3D_CMD_DEFINE_GB_SHADER */ 2294} __packed
2295SVGA3dCmdDefineGBShader; /* SVGA_3D_CMD_DEFINE_GB_SHADER */
2285 2296
2286/* 2297/*
2287 * Bind a guest-backed shader. 2298 * Bind a guest-backed shader.
@@ -2291,7 +2302,8 @@ typedef struct SVGA3dCmdBindGBShader {
2291 uint32 shid; 2302 uint32 shid;
2292 SVGAMobId mobid; 2303 SVGAMobId mobid;
2293 uint32 offsetInBytes; 2304 uint32 offsetInBytes;
2294} SVGA3dCmdBindGBShader; /* SVGA_3D_CMD_BIND_GB_SHADER */ 2305} __packed
2306SVGA3dCmdBindGBShader; /* SVGA_3D_CMD_BIND_GB_SHADER */
2295 2307
2296/* 2308/*
2297 * Destroy a guest-backed shader. 2309 * Destroy a guest-backed shader.
@@ -2299,7 +2311,8 @@ typedef struct SVGA3dCmdBindGBShader {
2299 2311
2300typedef struct SVGA3dCmdDestroyGBShader { 2312typedef struct SVGA3dCmdDestroyGBShader {
2301 uint32 shid; 2313 uint32 shid;
2302} SVGA3dCmdDestroyGBShader; /* SVGA_3D_CMD_DESTROY_GB_SHADER */ 2314} __packed
2315SVGA3dCmdDestroyGBShader; /* SVGA_3D_CMD_DESTROY_GB_SHADER */
2303 2316
2304typedef 2317typedef
2305struct { 2318struct {
@@ -2314,14 +2327,16 @@ struct {
2314 * Note that FLOAT and INT constants are 4-dwords in length, while 2327 * Note that FLOAT and INT constants are 4-dwords in length, while
2315 * BOOL constants are 1-dword in length. 2328 * BOOL constants are 1-dword in length.
2316 */ 2329 */
2317} SVGA3dCmdSetGBShaderConstInline; 2330} __packed
2331SVGA3dCmdSetGBShaderConstInline;
2318/* SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE */ 2332/* SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE */
2319 2333
2320typedef 2334typedef
2321struct { 2335struct {
2322 uint32 cid; 2336 uint32 cid;
2323 SVGA3dQueryType type; 2337 SVGA3dQueryType type;
2324} SVGA3dCmdBeginGBQuery; /* SVGA_3D_CMD_BEGIN_GB_QUERY */ 2338} __packed
2339SVGA3dCmdBeginGBQuery; /* SVGA_3D_CMD_BEGIN_GB_QUERY */
2325 2340
2326typedef 2341typedef
2327struct { 2342struct {
@@ -2329,7 +2344,8 @@ struct {
2329 SVGA3dQueryType type; 2344 SVGA3dQueryType type;
2330 SVGAMobId mobid; 2345 SVGAMobId mobid;
2331 uint32 offset; 2346 uint32 offset;
2332} SVGA3dCmdEndGBQuery; /* SVGA_3D_CMD_END_GB_QUERY */ 2347} __packed
2348SVGA3dCmdEndGBQuery; /* SVGA_3D_CMD_END_GB_QUERY */
2333 2349
2334 2350
2335/* 2351/*
@@ -2346,21 +2362,22 @@ struct {
2346 SVGA3dQueryType type; 2362 SVGA3dQueryType type;
2347 SVGAMobId mobid; 2363 SVGAMobId mobid;
2348 uint32 offset; 2364 uint32 offset;
2349} SVGA3dCmdWaitForGBQuery; /* SVGA_3D_CMD_WAIT_FOR_GB_QUERY */ 2365} __packed
2366SVGA3dCmdWaitForGBQuery; /* SVGA_3D_CMD_WAIT_FOR_GB_QUERY */
2350 2367
2351typedef 2368typedef
2352struct { 2369struct {
2353 SVGAMobId mobid; 2370 SVGAMobId mobid;
2354 uint32 fbOffset; 2371 uint32 fbOffset;
2355 uint32 initalized; 2372 uint32 initalized;
2356} 2373} __packed
2357SVGA3dCmdEnableGart; /* SVGA_3D_CMD_ENABLE_GART */ 2374SVGA3dCmdEnableGart; /* SVGA_3D_CMD_ENABLE_GART */
2358 2375
2359typedef 2376typedef
2360struct { 2377struct {
2361 SVGAMobId mobid; 2378 SVGAMobId mobid;
2362 uint32 gartOffset; 2379 uint32 gartOffset;
2363} 2380} __packed
2364SVGA3dCmdMapMobIntoGart; /* SVGA_3D_CMD_MAP_MOB_INTO_GART */ 2381SVGA3dCmdMapMobIntoGart; /* SVGA_3D_CMD_MAP_MOB_INTO_GART */
2365 2382
2366 2383
@@ -2368,7 +2385,7 @@ typedef
2368struct { 2385struct {
2369 uint32 gartOffset; 2386 uint32 gartOffset;
2370 uint32 numPages; 2387 uint32 numPages;
2371} 2388} __packed
2372SVGA3dCmdUnmapGartRange; /* SVGA_3D_CMD_UNMAP_GART_RANGE */ 2389SVGA3dCmdUnmapGartRange; /* SVGA_3D_CMD_UNMAP_GART_RANGE */
2373 2390
2374 2391
@@ -2385,27 +2402,27 @@ struct {
2385 int32 xRoot; 2402 int32 xRoot;
2386 int32 yRoot; 2403 int32 yRoot;
2387 uint32 flags; 2404 uint32 flags;
2388} 2405} __packed
2389SVGA3dCmdDefineGBScreenTarget; /* SVGA_3D_CMD_DEFINE_GB_SCREENTARGET */ 2406SVGA3dCmdDefineGBScreenTarget; /* SVGA_3D_CMD_DEFINE_GB_SCREENTARGET */
2390 2407
2391typedef 2408typedef
2392struct { 2409struct {
2393 uint32 stid; 2410 uint32 stid;
2394} 2411} __packed
2395SVGA3dCmdDestroyGBScreenTarget; /* SVGA_3D_CMD_DESTROY_GB_SCREENTARGET */ 2412SVGA3dCmdDestroyGBScreenTarget; /* SVGA_3D_CMD_DESTROY_GB_SCREENTARGET */
2396 2413
2397typedef 2414typedef
2398struct { 2415struct {
2399 uint32 stid; 2416 uint32 stid;
2400 SVGA3dSurfaceImageId image; 2417 SVGA3dSurfaceImageId image;
2401} 2418} __packed
2402SVGA3dCmdBindGBScreenTarget; /* SVGA_3D_CMD_BIND_GB_SCREENTARGET */ 2419SVGA3dCmdBindGBScreenTarget; /* SVGA_3D_CMD_BIND_GB_SCREENTARGET */
2403 2420
2404typedef 2421typedef
2405struct { 2422struct {
2406 uint32 stid; 2423 uint32 stid;
2407 SVGA3dBox box; 2424 SVGA3dBox box;
2408} 2425} __packed
2409SVGA3dCmdUpdateGBScreenTarget; /* SVGA_3D_CMD_UPDATE_GB_SCREENTARGET */ 2426SVGA3dCmdUpdateGBScreenTarget; /* SVGA_3D_CMD_UPDATE_GB_SCREENTARGET */
2410 2427
2411/* 2428/*
@@ -2583,4 +2600,28 @@ typedef union {
2583 float f; 2600 float f;
2584} SVGA3dDevCapResult; 2601} SVGA3dDevCapResult;
2585 2602
2603typedef enum {
2604 SVGA3DCAPS_RECORD_UNKNOWN = 0,
2605 SVGA3DCAPS_RECORD_DEVCAPS_MIN = 0x100,
2606 SVGA3DCAPS_RECORD_DEVCAPS = 0x100,
2607 SVGA3DCAPS_RECORD_DEVCAPS_MAX = 0x1ff,
2608} SVGA3dCapsRecordType;
2609
2610typedef
2611struct SVGA3dCapsRecordHeader {
2612 uint32 length;
2613 SVGA3dCapsRecordType type;
2614}
2615SVGA3dCapsRecordHeader;
2616
2617typedef
2618struct SVGA3dCapsRecord {
2619 SVGA3dCapsRecordHeader header;
2620 uint32 data[1];
2621}
2622SVGA3dCapsRecord;
2623
2624
2625typedef uint32 SVGA3dCapPair[2];
2626
2586#endif /* _SVGA3D_REG_H_ */ 2627#endif /* _SVGA3D_REG_H_ */
diff --git a/drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h b/drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h
index 8369c3ba10fe..ef3385096145 100644
--- a/drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h
+++ b/drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h
@@ -38,8 +38,11 @@
38 38
39#define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y)) 39#define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y))
40#define max_t(type, x, y) ((x) > (y) ? (x) : (y)) 40#define max_t(type, x, y) ((x) > (y) ? (x) : (y))
41#define min_t(type, x, y) ((x) < (y) ? (x) : (y))
41#define surf_size_struct SVGA3dSize 42#define surf_size_struct SVGA3dSize
42#define u32 uint32 43#define u32 uint32
44#define u64 uint64_t
45#define U32_MAX ((u32)~0U)
43 46
44#endif /* __KERNEL__ */ 47#endif /* __KERNEL__ */
45 48
@@ -704,8 +707,8 @@ static const struct svga3d_surface_desc svga3d_surface_descs[] = {
704 707
705static inline u32 clamped_umul32(u32 a, u32 b) 708static inline u32 clamped_umul32(u32 a, u32 b)
706{ 709{
707 uint64_t tmp = (uint64_t) a*b; 710 u64 tmp = (u64) a*b;
708 return (tmp > (uint64_t) ((u32) -1)) ? (u32) -1 : tmp; 711 return (tmp > (u64) U32_MAX) ? U32_MAX : tmp;
709} 712}
710 713
711static inline const struct svga3d_surface_desc * 714static inline const struct svga3d_surface_desc *
@@ -834,7 +837,7 @@ svga3dsurface_get_serialized_size(SVGA3dSurfaceFormat format,
834 bool cubemap) 837 bool cubemap)
835{ 838{
836 const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(format); 839 const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(format);
837 u32 total_size = 0; 840 u64 total_size = 0;
838 u32 mip; 841 u32 mip;
839 842
840 for (mip = 0; mip < num_mip_levels; mip++) { 843 for (mip = 0; mip < num_mip_levels; mip++) {
@@ -847,7 +850,7 @@ svga3dsurface_get_serialized_size(SVGA3dSurfaceFormat format,
847 if (cubemap) 850 if (cubemap)
848 total_size *= SVGA3D_MAX_SURFACE_FACES; 851 total_size *= SVGA3D_MAX_SURFACE_FACES;
849 852
850 return total_size; 853 return (u32) min_t(u64, total_size, (u64) U32_MAX);
851} 854}
852 855
853 856
diff --git a/drivers/gpu/drm/vmwgfx/svga_reg.h b/drivers/gpu/drm/vmwgfx/svga_reg.h
index 71defa4d2d75..11323dd5196f 100644
--- a/drivers/gpu/drm/vmwgfx/svga_reg.h
+++ b/drivers/gpu/drm/vmwgfx/svga_reg.h
@@ -169,10 +169,17 @@ enum {
169 SVGA_REG_TRACES = 45, /* Enable trace-based updates even when FIFO is on */ 169 SVGA_REG_TRACES = 45, /* Enable trace-based updates even when FIFO is on */
170 SVGA_REG_GMRS_MAX_PAGES = 46, /* Maximum number of 4KB pages for all GMRs */ 170 SVGA_REG_GMRS_MAX_PAGES = 46, /* Maximum number of 4KB pages for all GMRs */
171 SVGA_REG_MEMORY_SIZE = 47, /* Total dedicated device memory excluding FIFO */ 171 SVGA_REG_MEMORY_SIZE = 47, /* Total dedicated device memory excluding FIFO */
172 SVGA_REG_COMMAND_LOW = 48, /* Lower 32 bits and submits commands */
173 SVGA_REG_COMMAND_HIGH = 49, /* Upper 32 bits of command buffer PA */
172 SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM = 50, /* Max primary memory */ 174 SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM = 50, /* Max primary memory */
173 SVGA_REG_SUGGESTED_GBOBJECT_MEM_SIZE_KB = 51, /* Suggested limit on mob mem */ 175 SVGA_REG_SUGGESTED_GBOBJECT_MEM_SIZE_KB = 51, /* Suggested limit on mob mem */
174 SVGA_REG_DEV_CAP = 52, /* Write dev cap index, read value */ 176 SVGA_REG_DEV_CAP = 52, /* Write dev cap index, read value */
175 SVGA_REG_TOP = 53, /* Must be 1 more than the last register */ 177 SVGA_REG_CMD_PREPEND_LOW = 53,
178 SVGA_REG_CMD_PREPEND_HIGH = 54,
179 SVGA_REG_SCREENTARGET_MAX_WIDTH = 55,
180 SVGA_REG_SCREENTARGET_MAX_HEIGHT = 56,
181 SVGA_REG_MOB_MAX_SIZE = 57,
182 SVGA_REG_TOP = 58, /* Must be 1 more than the last register */
176 183
177 SVGA_PALETTE_BASE = 1024, /* Base of SVGA color map */ 184 SVGA_PALETTE_BASE = 1024, /* Base of SVGA color map */
178 /* Next 768 (== 256*3) registers exist for colormap */ 185 /* Next 768 (== 256*3) registers exist for colormap */
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
index 82c41daebc0e..1e80152674b5 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
@@ -37,7 +37,7 @@ struct vmw_user_context {
37 37
38 38
39 39
40typedef int (*vmw_scrub_func)(struct vmw_ctx_bindinfo *); 40typedef int (*vmw_scrub_func)(struct vmw_ctx_bindinfo *, bool);
41 41
42static void vmw_user_context_free(struct vmw_resource *res); 42static void vmw_user_context_free(struct vmw_resource *res);
43static struct vmw_resource * 43static struct vmw_resource *
@@ -50,9 +50,11 @@ static int vmw_gb_context_unbind(struct vmw_resource *res,
50 bool readback, 50 bool readback,
51 struct ttm_validate_buffer *val_buf); 51 struct ttm_validate_buffer *val_buf);
52static int vmw_gb_context_destroy(struct vmw_resource *res); 52static int vmw_gb_context_destroy(struct vmw_resource *res);
53static int vmw_context_scrub_shader(struct vmw_ctx_bindinfo *bi); 53static int vmw_context_scrub_shader(struct vmw_ctx_bindinfo *bi, bool rebind);
54static int vmw_context_scrub_render_target(struct vmw_ctx_bindinfo *bi); 54static int vmw_context_scrub_render_target(struct vmw_ctx_bindinfo *bi,
55static int vmw_context_scrub_texture(struct vmw_ctx_bindinfo *bi); 55 bool rebind);
56static int vmw_context_scrub_texture(struct vmw_ctx_bindinfo *bi, bool rebind);
57static void vmw_context_binding_state_scrub(struct vmw_ctx_binding_state *cbs);
56static void vmw_context_binding_state_kill(struct vmw_ctx_binding_state *cbs); 58static void vmw_context_binding_state_kill(struct vmw_ctx_binding_state *cbs);
57static uint64_t vmw_user_context_size; 59static uint64_t vmw_user_context_size;
58 60
@@ -111,10 +113,14 @@ static void vmw_hw_context_destroy(struct vmw_resource *res)
111 113
112 if (res->func->destroy == vmw_gb_context_destroy) { 114 if (res->func->destroy == vmw_gb_context_destroy) {
113 mutex_lock(&dev_priv->cmdbuf_mutex); 115 mutex_lock(&dev_priv->cmdbuf_mutex);
116 mutex_lock(&dev_priv->binding_mutex);
117 (void) vmw_context_binding_state_kill
118 (&container_of(res, struct vmw_user_context, res)->cbs);
114 (void) vmw_gb_context_destroy(res); 119 (void) vmw_gb_context_destroy(res);
115 if (dev_priv->pinned_bo != NULL && 120 if (dev_priv->pinned_bo != NULL &&
116 !dev_priv->query_cid_valid) 121 !dev_priv->query_cid_valid)
117 __vmw_execbuf_release_pinned_bo(dev_priv, NULL); 122 __vmw_execbuf_release_pinned_bo(dev_priv, NULL);
123 mutex_unlock(&dev_priv->binding_mutex);
118 mutex_unlock(&dev_priv->cmdbuf_mutex); 124 mutex_unlock(&dev_priv->cmdbuf_mutex);
119 return; 125 return;
120 } 126 }
@@ -328,7 +334,7 @@ static int vmw_gb_context_unbind(struct vmw_resource *res,
328 BUG_ON(bo->mem.mem_type != VMW_PL_MOB); 334 BUG_ON(bo->mem.mem_type != VMW_PL_MOB);
329 335
330 mutex_lock(&dev_priv->binding_mutex); 336 mutex_lock(&dev_priv->binding_mutex);
331 vmw_context_binding_state_kill(&uctx->cbs); 337 vmw_context_binding_state_scrub(&uctx->cbs);
332 338
333 submit_size = sizeof(*cmd2) + (readback ? sizeof(*cmd1) : 0); 339 submit_size = sizeof(*cmd2) + (readback ? sizeof(*cmd1) : 0);
334 340
@@ -378,10 +384,6 @@ static int vmw_gb_context_destroy(struct vmw_resource *res)
378 SVGA3dCmdHeader header; 384 SVGA3dCmdHeader header;
379 SVGA3dCmdDestroyGBContext body; 385 SVGA3dCmdDestroyGBContext body;
380 } *cmd; 386 } *cmd;
381 struct vmw_user_context *uctx =
382 container_of(res, struct vmw_user_context, res);
383
384 BUG_ON(!list_empty(&uctx->cbs.list));
385 387
386 if (likely(res->id == -1)) 388 if (likely(res->id == -1))
387 return 0; 389 return 0;
@@ -528,8 +530,9 @@ out_unlock:
528 * vmw_context_scrub_shader - scrub a shader binding from a context. 530 * vmw_context_scrub_shader - scrub a shader binding from a context.
529 * 531 *
530 * @bi: single binding information. 532 * @bi: single binding information.
533 * @rebind: Whether to issue a bind instead of scrub command.
531 */ 534 */
532static int vmw_context_scrub_shader(struct vmw_ctx_bindinfo *bi) 535static int vmw_context_scrub_shader(struct vmw_ctx_bindinfo *bi, bool rebind)
533{ 536{
534 struct vmw_private *dev_priv = bi->ctx->dev_priv; 537 struct vmw_private *dev_priv = bi->ctx->dev_priv;
535 struct { 538 struct {
@@ -548,7 +551,7 @@ static int vmw_context_scrub_shader(struct vmw_ctx_bindinfo *bi)
548 cmd->header.size = sizeof(cmd->body); 551 cmd->header.size = sizeof(cmd->body);
549 cmd->body.cid = bi->ctx->id; 552 cmd->body.cid = bi->ctx->id;
550 cmd->body.type = bi->i1.shader_type; 553 cmd->body.type = bi->i1.shader_type;
551 cmd->body.shid = SVGA3D_INVALID_ID; 554 cmd->body.shid = ((rebind) ? bi->res->id : SVGA3D_INVALID_ID);
552 vmw_fifo_commit(dev_priv, sizeof(*cmd)); 555 vmw_fifo_commit(dev_priv, sizeof(*cmd));
553 556
554 return 0; 557 return 0;
@@ -559,8 +562,10 @@ static int vmw_context_scrub_shader(struct vmw_ctx_bindinfo *bi)
559 * from a context. 562 * from a context.
560 * 563 *
561 * @bi: single binding information. 564 * @bi: single binding information.
565 * @rebind: Whether to issue a bind instead of scrub command.
562 */ 566 */
563static int vmw_context_scrub_render_target(struct vmw_ctx_bindinfo *bi) 567static int vmw_context_scrub_render_target(struct vmw_ctx_bindinfo *bi,
568 bool rebind)
564{ 569{
565 struct vmw_private *dev_priv = bi->ctx->dev_priv; 570 struct vmw_private *dev_priv = bi->ctx->dev_priv;
566 struct { 571 struct {
@@ -579,7 +584,7 @@ static int vmw_context_scrub_render_target(struct vmw_ctx_bindinfo *bi)
579 cmd->header.size = sizeof(cmd->body); 584 cmd->header.size = sizeof(cmd->body);
580 cmd->body.cid = bi->ctx->id; 585 cmd->body.cid = bi->ctx->id;
581 cmd->body.type = bi->i1.rt_type; 586 cmd->body.type = bi->i1.rt_type;
582 cmd->body.target.sid = SVGA3D_INVALID_ID; 587 cmd->body.target.sid = ((rebind) ? bi->res->id : SVGA3D_INVALID_ID);
583 cmd->body.target.face = 0; 588 cmd->body.target.face = 0;
584 cmd->body.target.mipmap = 0; 589 cmd->body.target.mipmap = 0;
585 vmw_fifo_commit(dev_priv, sizeof(*cmd)); 590 vmw_fifo_commit(dev_priv, sizeof(*cmd));
@@ -591,11 +596,13 @@ static int vmw_context_scrub_render_target(struct vmw_ctx_bindinfo *bi)
591 * vmw_context_scrub_texture - scrub a texture binding from a context. 596 * vmw_context_scrub_texture - scrub a texture binding from a context.
592 * 597 *
593 * @bi: single binding information. 598 * @bi: single binding information.
599 * @rebind: Whether to issue a bind instead of scrub command.
594 * 600 *
595 * TODO: Possibly complement this function with a function that takes 601 * TODO: Possibly complement this function with a function that takes
596 * a list of texture bindings and combines them to a single command. 602 * a list of texture bindings and combines them to a single command.
597 */ 603 */
598static int vmw_context_scrub_texture(struct vmw_ctx_bindinfo *bi) 604static int vmw_context_scrub_texture(struct vmw_ctx_bindinfo *bi,
605 bool rebind)
599{ 606{
600 struct vmw_private *dev_priv = bi->ctx->dev_priv; 607 struct vmw_private *dev_priv = bi->ctx->dev_priv;
601 struct { 608 struct {
@@ -619,7 +626,7 @@ static int vmw_context_scrub_texture(struct vmw_ctx_bindinfo *bi)
619 cmd->body.c.cid = bi->ctx->id; 626 cmd->body.c.cid = bi->ctx->id;
620 cmd->body.s1.stage = bi->i1.texture_stage; 627 cmd->body.s1.stage = bi->i1.texture_stage;
621 cmd->body.s1.name = SVGA3D_TS_BIND_TEXTURE; 628 cmd->body.s1.name = SVGA3D_TS_BIND_TEXTURE;
622 cmd->body.s1.value = (uint32) SVGA3D_INVALID_ID; 629 cmd->body.s1.value = ((rebind) ? bi->res->id : SVGA3D_INVALID_ID);
623 vmw_fifo_commit(dev_priv, sizeof(*cmd)); 630 vmw_fifo_commit(dev_priv, sizeof(*cmd));
624 631
625 return 0; 632 return 0;
@@ -692,6 +699,7 @@ int vmw_context_binding_add(struct vmw_ctx_binding_state *cbs,
692 vmw_context_binding_drop(loc); 699 vmw_context_binding_drop(loc);
693 700
694 loc->bi = *bi; 701 loc->bi = *bi;
702 loc->bi.scrubbed = false;
695 list_add_tail(&loc->ctx_list, &cbs->list); 703 list_add_tail(&loc->ctx_list, &cbs->list);
696 INIT_LIST_HEAD(&loc->res_list); 704 INIT_LIST_HEAD(&loc->res_list);
697 705
@@ -727,12 +735,11 @@ static void vmw_context_binding_transfer(struct vmw_ctx_binding_state *cbs,
727 if (loc->bi.ctx != NULL) 735 if (loc->bi.ctx != NULL)
728 vmw_context_binding_drop(loc); 736 vmw_context_binding_drop(loc);
729 737
730 loc->bi = *bi; 738 if (bi->res != NULL) {
731 list_add_tail(&loc->ctx_list, &cbs->list); 739 loc->bi = *bi;
732 if (bi->res != NULL) 740 list_add_tail(&loc->ctx_list, &cbs->list);
733 list_add_tail(&loc->res_list, &bi->res->binding_head); 741 list_add_tail(&loc->res_list, &bi->res->binding_head);
734 else 742 }
735 INIT_LIST_HEAD(&loc->res_list);
736} 743}
737 744
738/** 745/**
@@ -746,7 +753,10 @@ static void vmw_context_binding_transfer(struct vmw_ctx_binding_state *cbs,
746 */ 753 */
747static void vmw_context_binding_kill(struct vmw_ctx_binding *cb) 754static void vmw_context_binding_kill(struct vmw_ctx_binding *cb)
748{ 755{
749 (void) vmw_scrub_funcs[cb->bi.bt](&cb->bi); 756 if (!cb->bi.scrubbed) {
757 (void) vmw_scrub_funcs[cb->bi.bt](&cb->bi, false);
758 cb->bi.scrubbed = true;
759 }
750 vmw_context_binding_drop(cb); 760 vmw_context_binding_drop(cb);
751} 761}
752 762
@@ -768,6 +778,27 @@ static void vmw_context_binding_state_kill(struct vmw_ctx_binding_state *cbs)
768} 778}
769 779
770/** 780/**
781 * vmw_context_binding_state_scrub - Scrub all bindings associated with a
782 * struct vmw_ctx_binding state structure.
783 *
784 * @cbs: Pointer to the context binding state tracker.
785 *
786 * Emits commands to scrub all bindings associated with the
787 * context binding state tracker.
788 */
789static void vmw_context_binding_state_scrub(struct vmw_ctx_binding_state *cbs)
790{
791 struct vmw_ctx_binding *entry;
792
793 list_for_each_entry(entry, &cbs->list, ctx_list) {
794 if (!entry->bi.scrubbed) {
795 (void) vmw_scrub_funcs[entry->bi.bt](&entry->bi, false);
796 entry->bi.scrubbed = true;
797 }
798 }
799}
800
801/**
771 * vmw_context_binding_res_list_kill - Kill all bindings on a 802 * vmw_context_binding_res_list_kill - Kill all bindings on a
772 * resource binding list 803 * resource binding list
773 * 804 *
@@ -785,6 +816,27 @@ void vmw_context_binding_res_list_kill(struct list_head *head)
785} 816}
786 817
787/** 818/**
819 * vmw_context_binding_res_list_scrub - Scrub all bindings on a
820 * resource binding list
821 *
822 * @head: list head of resource binding list
823 *
824 * Scrub all bindings associated with a specific resource. Typically
825 * called before the resource is evicted.
826 */
827void vmw_context_binding_res_list_scrub(struct list_head *head)
828{
829 struct vmw_ctx_binding *entry;
830
831 list_for_each_entry(entry, head, res_list) {
832 if (!entry->bi.scrubbed) {
833 (void) vmw_scrub_funcs[entry->bi.bt](&entry->bi, false);
834 entry->bi.scrubbed = true;
835 }
836 }
837}
838
839/**
788 * vmw_context_binding_state_transfer - Commit staged binding info 840 * vmw_context_binding_state_transfer - Commit staged binding info
789 * 841 *
790 * @ctx: Pointer to context to commit the staged binding info to. 842 * @ctx: Pointer to context to commit the staged binding info to.
@@ -803,3 +855,50 @@ void vmw_context_binding_state_transfer(struct vmw_resource *ctx,
803 list_for_each_entry_safe(entry, next, &from->list, ctx_list) 855 list_for_each_entry_safe(entry, next, &from->list, ctx_list)
804 vmw_context_binding_transfer(&uctx->cbs, &entry->bi); 856 vmw_context_binding_transfer(&uctx->cbs, &entry->bi);
805} 857}
858
859/**
860 * vmw_context_rebind_all - Rebind all scrubbed bindings of a context
861 *
862 * @ctx: The context resource
863 *
864 * Walks through the context binding list and rebinds all scrubbed
865 * resources.
866 */
867int vmw_context_rebind_all(struct vmw_resource *ctx)
868{
869 struct vmw_ctx_binding *entry;
870 struct vmw_user_context *uctx =
871 container_of(ctx, struct vmw_user_context, res);
872 struct vmw_ctx_binding_state *cbs = &uctx->cbs;
873 int ret;
874
875 list_for_each_entry(entry, &cbs->list, ctx_list) {
876 if (likely(!entry->bi.scrubbed))
877 continue;
878
879 if (WARN_ON(entry->bi.res == NULL || entry->bi.res->id ==
880 SVGA3D_INVALID_ID))
881 continue;
882
883 ret = vmw_scrub_funcs[entry->bi.bt](&entry->bi, true);
884 if (unlikely(ret != 0))
885 return ret;
886
887 entry->bi.scrubbed = false;
888 }
889
890 return 0;
891}
892
893/**
894 * vmw_context_binding_list - Return a list of context bindings
895 *
896 * @ctx: The context resource
897 *
898 * Returns the current list of bindings of the given context. Note that
899 * this list becomes stale as soon as the dev_priv::binding_mutex is unlocked.
900 */
901struct list_head *vmw_context_binding_list(struct vmw_resource *ctx)
902{
903 return &(container_of(ctx, struct vmw_user_context, res)->cbs.list);
904}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 9893328f8fdc..0083cbf99edf 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -667,6 +667,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
667 dev_priv->memory_size = 512*1024*1024; 667 dev_priv->memory_size = 512*1024*1024;
668 } 668 }
669 dev_priv->max_mob_pages = 0; 669 dev_priv->max_mob_pages = 0;
670 dev_priv->max_mob_size = 0;
670 if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS) { 671 if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS) {
671 uint64_t mem_size = 672 uint64_t mem_size =
672 vmw_read(dev_priv, 673 vmw_read(dev_priv,
@@ -676,6 +677,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
676 dev_priv->prim_bb_mem = 677 dev_priv->prim_bb_mem =
677 vmw_read(dev_priv, 678 vmw_read(dev_priv,
678 SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM); 679 SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM);
680 dev_priv->max_mob_size =
681 vmw_read(dev_priv, SVGA_REG_MOB_MAX_SIZE);
679 } else 682 } else
680 dev_priv->prim_bb_mem = dev_priv->vram_size; 683 dev_priv->prim_bb_mem = dev_priv->vram_size;
681 684
@@ -941,6 +944,7 @@ static void vmw_postclose(struct drm_device *dev,
941 drm_master_put(&vmw_fp->locked_master); 944 drm_master_put(&vmw_fp->locked_master);
942 } 945 }
943 946
947 vmw_compat_shader_man_destroy(vmw_fp->shman);
944 ttm_object_file_release(&vmw_fp->tfile); 948 ttm_object_file_release(&vmw_fp->tfile);
945 kfree(vmw_fp); 949 kfree(vmw_fp);
946} 950}
@@ -960,11 +964,17 @@ static int vmw_driver_open(struct drm_device *dev, struct drm_file *file_priv)
960 if (unlikely(vmw_fp->tfile == NULL)) 964 if (unlikely(vmw_fp->tfile == NULL))
961 goto out_no_tfile; 965 goto out_no_tfile;
962 966
967 vmw_fp->shman = vmw_compat_shader_man_create(dev_priv);
968 if (IS_ERR(vmw_fp->shman))
969 goto out_no_shman;
970
963 file_priv->driver_priv = vmw_fp; 971 file_priv->driver_priv = vmw_fp;
964 dev_priv->bdev.dev_mapping = dev->dev_mapping; 972 dev_priv->bdev.dev_mapping = dev->dev_mapping;
965 973
966 return 0; 974 return 0;
967 975
976out_no_shman:
977 ttm_object_file_release(&vmw_fp->tfile);
968out_no_tfile: 978out_no_tfile:
969 kfree(vmw_fp); 979 kfree(vmw_fp);
970 return ret; 980 return ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 554e7fa33082..07831554dad7 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -40,7 +40,7 @@
40#include <drm/ttm/ttm_module.h> 40#include <drm/ttm/ttm_module.h>
41#include "vmwgfx_fence.h" 41#include "vmwgfx_fence.h"
42 42
43#define VMWGFX_DRIVER_DATE "20121114" 43#define VMWGFX_DRIVER_DATE "20140228"
44#define VMWGFX_DRIVER_MAJOR 2 44#define VMWGFX_DRIVER_MAJOR 2
45#define VMWGFX_DRIVER_MINOR 5 45#define VMWGFX_DRIVER_MINOR 5
46#define VMWGFX_DRIVER_PATCHLEVEL 0 46#define VMWGFX_DRIVER_PATCHLEVEL 0
@@ -75,10 +75,14 @@
75#define VMW_RES_FENCE ttm_driver_type3 75#define VMW_RES_FENCE ttm_driver_type3
76#define VMW_RES_SHADER ttm_driver_type4 76#define VMW_RES_SHADER ttm_driver_type4
77 77
78struct vmw_compat_shader_manager;
79
78struct vmw_fpriv { 80struct vmw_fpriv {
79 struct drm_master *locked_master; 81 struct drm_master *locked_master;
80 struct ttm_object_file *tfile; 82 struct ttm_object_file *tfile;
81 struct list_head fence_events; 83 struct list_head fence_events;
84 bool gb_aware;
85 struct vmw_compat_shader_manager *shman;
82}; 86};
83 87
84struct vmw_dma_buffer { 88struct vmw_dma_buffer {
@@ -272,6 +276,7 @@ struct vmw_ctx_bindinfo {
272 struct vmw_resource *ctx; 276 struct vmw_resource *ctx;
273 struct vmw_resource *res; 277 struct vmw_resource *res;
274 enum vmw_ctx_binding_type bt; 278 enum vmw_ctx_binding_type bt;
279 bool scrubbed;
275 union { 280 union {
276 SVGA3dShaderType shader_type; 281 SVGA3dShaderType shader_type;
277 SVGA3dRenderTargetType rt_type; 282 SVGA3dRenderTargetType rt_type;
@@ -318,7 +323,7 @@ struct vmw_sw_context{
318 struct drm_open_hash res_ht; 323 struct drm_open_hash res_ht;
319 bool res_ht_initialized; 324 bool res_ht_initialized;
320 bool kernel; /**< is the called made from the kernel */ 325 bool kernel; /**< is the called made from the kernel */
321 struct ttm_object_file *tfile; 326 struct vmw_fpriv *fp;
322 struct list_head validate_nodes; 327 struct list_head validate_nodes;
323 struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS]; 328 struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
324 uint32_t cur_reloc; 329 uint32_t cur_reloc;
@@ -336,6 +341,7 @@ struct vmw_sw_context{
336 bool needs_post_query_barrier; 341 bool needs_post_query_barrier;
337 struct vmw_resource *error_resource; 342 struct vmw_resource *error_resource;
338 struct vmw_ctx_binding_state staged_bindings; 343 struct vmw_ctx_binding_state staged_bindings;
344 struct list_head staged_shaders;
339}; 345};
340 346
341struct vmw_legacy_display; 347struct vmw_legacy_display;
@@ -380,6 +386,7 @@ struct vmw_private {
380 uint32_t max_gmr_ids; 386 uint32_t max_gmr_ids;
381 uint32_t max_gmr_pages; 387 uint32_t max_gmr_pages;
382 uint32_t max_mob_pages; 388 uint32_t max_mob_pages;
389 uint32_t max_mob_size;
383 uint32_t memory_size; 390 uint32_t memory_size;
384 bool has_gmr; 391 bool has_gmr;
385 bool has_mob; 392 bool has_mob;
@@ -569,6 +576,8 @@ struct vmw_user_resource_conv;
569 576
570extern void vmw_resource_unreference(struct vmw_resource **p_res); 577extern void vmw_resource_unreference(struct vmw_resource **p_res);
571extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res); 578extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
579extern struct vmw_resource *
580vmw_resource_reference_unless_doomed(struct vmw_resource *res);
572extern int vmw_resource_validate(struct vmw_resource *res); 581extern int vmw_resource_validate(struct vmw_resource *res);
573extern int vmw_resource_reserve(struct vmw_resource *res, bool no_backup); 582extern int vmw_resource_reserve(struct vmw_resource *res, bool no_backup);
574extern bool vmw_resource_needs_backup(const struct vmw_resource *res); 583extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
@@ -957,6 +966,9 @@ extern void
957vmw_context_binding_state_transfer(struct vmw_resource *res, 966vmw_context_binding_state_transfer(struct vmw_resource *res,
958 struct vmw_ctx_binding_state *cbs); 967 struct vmw_ctx_binding_state *cbs);
959extern void vmw_context_binding_res_list_kill(struct list_head *head); 968extern void vmw_context_binding_res_list_kill(struct list_head *head);
969extern void vmw_context_binding_res_list_scrub(struct list_head *head);
970extern int vmw_context_rebind_all(struct vmw_resource *ctx);
971extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
960 972
961/* 973/*
962 * Surface management - vmwgfx_surface.c 974 * Surface management - vmwgfx_surface.c
@@ -991,6 +1003,28 @@ extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
991 struct drm_file *file_priv); 1003 struct drm_file *file_priv);
992extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data, 1004extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
993 struct drm_file *file_priv); 1005 struct drm_file *file_priv);
1006extern int vmw_compat_shader_lookup(struct vmw_compat_shader_manager *man,
1007 SVGA3dShaderType shader_type,
1008 u32 *user_key);
1009extern void vmw_compat_shaders_commit(struct vmw_compat_shader_manager *man,
1010 struct list_head *list);
1011extern void vmw_compat_shaders_revert(struct vmw_compat_shader_manager *man,
1012 struct list_head *list);
1013extern int vmw_compat_shader_remove(struct vmw_compat_shader_manager *man,
1014 u32 user_key,
1015 SVGA3dShaderType shader_type,
1016 struct list_head *list);
1017extern int vmw_compat_shader_add(struct vmw_compat_shader_manager *man,
1018 u32 user_key, const void *bytecode,
1019 SVGA3dShaderType shader_type,
1020 size_t size,
1021 struct ttm_object_file *tfile,
1022 struct list_head *list);
1023extern struct vmw_compat_shader_manager *
1024vmw_compat_shader_man_create(struct vmw_private *dev_priv);
1025extern void
1026vmw_compat_shader_man_destroy(struct vmw_compat_shader_manager *man);
1027
994 1028
995/** 1029/**
996 * Inline helper functions 1030 * Inline helper functions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index 7a5f1eb55c5a..efb575a7996c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -114,8 +114,10 @@ static void vmw_resource_list_unreserve(struct list_head *list,
114 * persistent context binding tracker. 114 * persistent context binding tracker.
115 */ 115 */
116 if (unlikely(val->staged_bindings)) { 116 if (unlikely(val->staged_bindings)) {
117 vmw_context_binding_state_transfer 117 if (!backoff) {
118 (val->res, val->staged_bindings); 118 vmw_context_binding_state_transfer
119 (val->res, val->staged_bindings);
120 }
119 kfree(val->staged_bindings); 121 kfree(val->staged_bindings);
120 val->staged_bindings = NULL; 122 val->staged_bindings = NULL;
121 } 123 }
@@ -178,6 +180,44 @@ static int vmw_resource_val_add(struct vmw_sw_context *sw_context,
178} 180}
179 181
180/** 182/**
183 * vmw_resource_context_res_add - Put resources previously bound to a context on
184 * the validation list
185 *
186 * @dev_priv: Pointer to a device private structure
187 * @sw_context: Pointer to a software context used for this command submission
188 * @ctx: Pointer to the context resource
189 *
190 * This function puts all resources that were previously bound to @ctx on
191 * the resource validation list. This is part of the context state reemission
192 */
193static int vmw_resource_context_res_add(struct vmw_private *dev_priv,
194 struct vmw_sw_context *sw_context,
195 struct vmw_resource *ctx)
196{
197 struct list_head *binding_list;
198 struct vmw_ctx_binding *entry;
199 int ret = 0;
200 struct vmw_resource *res;
201
202 mutex_lock(&dev_priv->binding_mutex);
203 binding_list = vmw_context_binding_list(ctx);
204
205 list_for_each_entry(entry, binding_list, ctx_list) {
206 res = vmw_resource_reference_unless_doomed(entry->bi.res);
207 if (unlikely(res == NULL))
208 continue;
209
210 ret = vmw_resource_val_add(sw_context, entry->bi.res, NULL);
211 vmw_resource_unreference(&res);
212 if (unlikely(ret != 0))
213 break;
214 }
215
216 mutex_unlock(&dev_priv->binding_mutex);
217 return ret;
218}
219
220/**
181 * vmw_resource_relocation_add - Add a relocation to the relocation list 221 * vmw_resource_relocation_add - Add a relocation to the relocation list
182 * 222 *
183 * @list: Pointer to head of relocation list. 223 * @list: Pointer to head of relocation list.
@@ -233,8 +273,12 @@ static void vmw_resource_relocations_apply(uint32_t *cb,
233{ 273{
234 struct vmw_resource_relocation *rel; 274 struct vmw_resource_relocation *rel;
235 275
236 list_for_each_entry(rel, list, head) 276 list_for_each_entry(rel, list, head) {
237 cb[rel->offset] = rel->res->id; 277 if (likely(rel->res != NULL))
278 cb[rel->offset] = rel->res->id;
279 else
280 cb[rel->offset] = SVGA_3D_CMD_NOP;
281 }
238} 282}
239 283
240static int vmw_cmd_invalid(struct vmw_private *dev_priv, 284static int vmw_cmd_invalid(struct vmw_private *dev_priv,
@@ -379,22 +423,27 @@ static int vmw_resources_validate(struct vmw_sw_context *sw_context)
379} 423}
380 424
381/** 425/**
382 * vmw_cmd_res_check - Check that a resource is present and if so, put it 426 * vmw_cmd_compat_res_check - Check that a resource is present and if so, put it
383 * on the resource validate list unless it's already there. 427 * on the resource validate list unless it's already there.
384 * 428 *
385 * @dev_priv: Pointer to a device private structure. 429 * @dev_priv: Pointer to a device private structure.
386 * @sw_context: Pointer to the software context. 430 * @sw_context: Pointer to the software context.
387 * @res_type: Resource type. 431 * @res_type: Resource type.
388 * @converter: User-space visisble type specific information. 432 * @converter: User-space visisble type specific information.
389 * @id: Pointer to the location in the command buffer currently being 433 * @id: user-space resource id handle.
434 * @id_loc: Pointer to the location in the command buffer currently being
390 * parsed from where the user-space resource id handle is located. 435 * parsed from where the user-space resource id handle is located.
436 * @p_val: Pointer to pointer to resource validalidation node. Populated
437 * on exit.
391 */ 438 */
392static int vmw_cmd_res_check(struct vmw_private *dev_priv, 439static int
393 struct vmw_sw_context *sw_context, 440vmw_cmd_compat_res_check(struct vmw_private *dev_priv,
394 enum vmw_res_type res_type, 441 struct vmw_sw_context *sw_context,
395 const struct vmw_user_resource_conv *converter, 442 enum vmw_res_type res_type,
396 uint32_t *id, 443 const struct vmw_user_resource_conv *converter,
397 struct vmw_resource_val_node **p_val) 444 uint32_t id,
445 uint32_t *id_loc,
446 struct vmw_resource_val_node **p_val)
398{ 447{
399 struct vmw_res_cache_entry *rcache = 448 struct vmw_res_cache_entry *rcache =
400 &sw_context->res_cache[res_type]; 449 &sw_context->res_cache[res_type];
@@ -402,7 +451,7 @@ static int vmw_cmd_res_check(struct vmw_private *dev_priv,
402 struct vmw_resource_val_node *node; 451 struct vmw_resource_val_node *node;
403 int ret; 452 int ret;
404 453
405 if (*id == SVGA3D_INVALID_ID) { 454 if (id == SVGA3D_INVALID_ID) {
406 if (p_val) 455 if (p_val)
407 *p_val = NULL; 456 *p_val = NULL;
408 if (res_type == vmw_res_context) { 457 if (res_type == vmw_res_context) {
@@ -417,7 +466,7 @@ static int vmw_cmd_res_check(struct vmw_private *dev_priv,
417 * resource 466 * resource
418 */ 467 */
419 468
420 if (likely(rcache->valid && *id == rcache->handle)) { 469 if (likely(rcache->valid && id == rcache->handle)) {
421 const struct vmw_resource *res = rcache->res; 470 const struct vmw_resource *res = rcache->res;
422 471
423 rcache->node->first_usage = false; 472 rcache->node->first_usage = false;
@@ -426,28 +475,28 @@ static int vmw_cmd_res_check(struct vmw_private *dev_priv,
426 475
427 return vmw_resource_relocation_add 476 return vmw_resource_relocation_add
428 (&sw_context->res_relocations, res, 477 (&sw_context->res_relocations, res,
429 id - sw_context->buf_start); 478 id_loc - sw_context->buf_start);
430 } 479 }
431 480
432 ret = vmw_user_resource_lookup_handle(dev_priv, 481 ret = vmw_user_resource_lookup_handle(dev_priv,
433 sw_context->tfile, 482 sw_context->fp->tfile,
434 *id, 483 id,
435 converter, 484 converter,
436 &res); 485 &res);
437 if (unlikely(ret != 0)) { 486 if (unlikely(ret != 0)) {
438 DRM_ERROR("Could not find or use resource 0x%08x.\n", 487 DRM_ERROR("Could not find or use resource 0x%08x.\n",
439 (unsigned) *id); 488 (unsigned) id);
440 dump_stack(); 489 dump_stack();
441 return ret; 490 return ret;
442 } 491 }
443 492
444 rcache->valid = true; 493 rcache->valid = true;
445 rcache->res = res; 494 rcache->res = res;
446 rcache->handle = *id; 495 rcache->handle = id;
447 496
448 ret = vmw_resource_relocation_add(&sw_context->res_relocations, 497 ret = vmw_resource_relocation_add(&sw_context->res_relocations,
449 res, 498 res,
450 id - sw_context->buf_start); 499 id_loc - sw_context->buf_start);
451 if (unlikely(ret != 0)) 500 if (unlikely(ret != 0))
452 goto out_no_reloc; 501 goto out_no_reloc;
453 502
@@ -459,7 +508,11 @@ static int vmw_cmd_res_check(struct vmw_private *dev_priv,
459 if (p_val) 508 if (p_val)
460 *p_val = node; 509 *p_val = node;
461 510
462 if (node->first_usage && res_type == vmw_res_context) { 511 if (dev_priv->has_mob && node->first_usage &&
512 res_type == vmw_res_context) {
513 ret = vmw_resource_context_res_add(dev_priv, sw_context, res);
514 if (unlikely(ret != 0))
515 goto out_no_reloc;
463 node->staged_bindings = 516 node->staged_bindings =
464 kzalloc(sizeof(*node->staged_bindings), GFP_KERNEL); 517 kzalloc(sizeof(*node->staged_bindings), GFP_KERNEL);
465 if (node->staged_bindings == NULL) { 518 if (node->staged_bindings == NULL) {
@@ -481,6 +534,59 @@ out_no_reloc:
481} 534}
482 535
483/** 536/**
537 * vmw_cmd_res_check - Check that a resource is present and if so, put it
538 * on the resource validate list unless it's already there.
539 *
540 * @dev_priv: Pointer to a device private structure.
541 * @sw_context: Pointer to the software context.
542 * @res_type: Resource type.
543 * @converter: User-space visisble type specific information.
544 * @id_loc: Pointer to the location in the command buffer currently being
545 * parsed from where the user-space resource id handle is located.
546 * @p_val: Pointer to pointer to resource validalidation node. Populated
547 * on exit.
548 */
549static int
550vmw_cmd_res_check(struct vmw_private *dev_priv,
551 struct vmw_sw_context *sw_context,
552 enum vmw_res_type res_type,
553 const struct vmw_user_resource_conv *converter,
554 uint32_t *id_loc,
555 struct vmw_resource_val_node **p_val)
556{
557 return vmw_cmd_compat_res_check(dev_priv, sw_context, res_type,
558 converter, *id_loc, id_loc, p_val);
559}
560
561/**
562 * vmw_rebind_contexts - Rebind all resources previously bound to
563 * referenced contexts.
564 *
565 * @sw_context: Pointer to the software context.
566 *
567 * Rebind context binding points that have been scrubbed because of eviction.
568 */
569static int vmw_rebind_contexts(struct vmw_sw_context *sw_context)
570{
571 struct vmw_resource_val_node *val;
572 int ret;
573
574 list_for_each_entry(val, &sw_context->resource_list, head) {
575 if (likely(!val->staged_bindings))
576 continue;
577
578 ret = vmw_context_rebind_all(val->res);
579 if (unlikely(ret != 0)) {
580 if (ret != -ERESTARTSYS)
581 DRM_ERROR("Failed to rebind context.\n");
582 return ret;
583 }
584 }
585
586 return 0;
587}
588
589/**
484 * vmw_cmd_cid_check - Check a command header for valid context information. 590 * vmw_cmd_cid_check - Check a command header for valid context information.
485 * 591 *
486 * @dev_priv: Pointer to a device private structure. 592 * @dev_priv: Pointer to a device private structure.
@@ -496,7 +602,7 @@ static int vmw_cmd_cid_check(struct vmw_private *dev_priv,
496{ 602{
497 struct vmw_cid_cmd { 603 struct vmw_cid_cmd {
498 SVGA3dCmdHeader header; 604 SVGA3dCmdHeader header;
499 __le32 cid; 605 uint32_t cid;
500 } *cmd; 606 } *cmd;
501 607
502 cmd = container_of(header, struct vmw_cid_cmd, header); 608 cmd = container_of(header, struct vmw_cid_cmd, header);
@@ -767,7 +873,7 @@ static int vmw_translate_mob_ptr(struct vmw_private *dev_priv,
767 struct vmw_relocation *reloc; 873 struct vmw_relocation *reloc;
768 int ret; 874 int ret;
769 875
770 ret = vmw_user_dmabuf_lookup(sw_context->tfile, handle, &vmw_bo); 876 ret = vmw_user_dmabuf_lookup(sw_context->fp->tfile, handle, &vmw_bo);
771 if (unlikely(ret != 0)) { 877 if (unlikely(ret != 0)) {
772 DRM_ERROR("Could not find or use MOB buffer.\n"); 878 DRM_ERROR("Could not find or use MOB buffer.\n");
773 return -EINVAL; 879 return -EINVAL;
@@ -828,7 +934,7 @@ static int vmw_translate_guest_ptr(struct vmw_private *dev_priv,
828 struct vmw_relocation *reloc; 934 struct vmw_relocation *reloc;
829 int ret; 935 int ret;
830 936
831 ret = vmw_user_dmabuf_lookup(sw_context->tfile, handle, &vmw_bo); 937 ret = vmw_user_dmabuf_lookup(sw_context->fp->tfile, handle, &vmw_bo);
832 if (unlikely(ret != 0)) { 938 if (unlikely(ret != 0)) {
833 DRM_ERROR("Could not find or use GMR region.\n"); 939 DRM_ERROR("Could not find or use GMR region.\n");
834 return -EINVAL; 940 return -EINVAL;
@@ -1127,7 +1233,8 @@ static int vmw_cmd_dma(struct vmw_private *dev_priv,
1127 1233
1128 srf = vmw_res_to_srf(sw_context->res_cache[vmw_res_surface].res); 1234 srf = vmw_res_to_srf(sw_context->res_cache[vmw_res_surface].res);
1129 1235
1130 vmw_kms_cursor_snoop(srf, sw_context->tfile, &vmw_bo->base, header); 1236 vmw_kms_cursor_snoop(srf, sw_context->fp->tfile, &vmw_bo->base,
1237 header);
1131 1238
1132out_no_surface: 1239out_no_surface:
1133 vmw_dmabuf_unreference(&vmw_bo); 1240 vmw_dmabuf_unreference(&vmw_bo);
@@ -1478,6 +1585,98 @@ static int vmw_cmd_invalidate_gb_surface(struct vmw_private *dev_priv,
1478 &cmd->body.sid, NULL); 1585 &cmd->body.sid, NULL);
1479} 1586}
1480 1587
1588
1589/**
1590 * vmw_cmd_shader_define - Validate an SVGA_3D_CMD_SHADER_DEFINE
1591 * command
1592 *
1593 * @dev_priv: Pointer to a device private struct.
1594 * @sw_context: The software context being used for this batch.
1595 * @header: Pointer to the command header in the command stream.
1596 */
1597static int vmw_cmd_shader_define(struct vmw_private *dev_priv,
1598 struct vmw_sw_context *sw_context,
1599 SVGA3dCmdHeader *header)
1600{
1601 struct vmw_shader_define_cmd {
1602 SVGA3dCmdHeader header;
1603 SVGA3dCmdDefineShader body;
1604 } *cmd;
1605 int ret;
1606 size_t size;
1607
1608 cmd = container_of(header, struct vmw_shader_define_cmd,
1609 header);
1610
1611 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
1612 user_context_converter, &cmd->body.cid,
1613 NULL);
1614 if (unlikely(ret != 0))
1615 return ret;
1616
1617 if (unlikely(!dev_priv->has_mob))
1618 return 0;
1619
1620 size = cmd->header.size - sizeof(cmd->body);
1621 ret = vmw_compat_shader_add(sw_context->fp->shman,
1622 cmd->body.shid, cmd + 1,
1623 cmd->body.type, size,
1624 sw_context->fp->tfile,
1625 &sw_context->staged_shaders);
1626 if (unlikely(ret != 0))
1627 return ret;
1628
1629 return vmw_resource_relocation_add(&sw_context->res_relocations,
1630 NULL, &cmd->header.id -
1631 sw_context->buf_start);
1632
1633 return 0;
1634}
1635
1636/**
1637 * vmw_cmd_shader_destroy - Validate an SVGA_3D_CMD_SHADER_DESTROY
1638 * command
1639 *
1640 * @dev_priv: Pointer to a device private struct.
1641 * @sw_context: The software context being used for this batch.
1642 * @header: Pointer to the command header in the command stream.
1643 */
1644static int vmw_cmd_shader_destroy(struct vmw_private *dev_priv,
1645 struct vmw_sw_context *sw_context,
1646 SVGA3dCmdHeader *header)
1647{
1648 struct vmw_shader_destroy_cmd {
1649 SVGA3dCmdHeader header;
1650 SVGA3dCmdDestroyShader body;
1651 } *cmd;
1652 int ret;
1653
1654 cmd = container_of(header, struct vmw_shader_destroy_cmd,
1655 header);
1656
1657 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
1658 user_context_converter, &cmd->body.cid,
1659 NULL);
1660 if (unlikely(ret != 0))
1661 return ret;
1662
1663 if (unlikely(!dev_priv->has_mob))
1664 return 0;
1665
1666 ret = vmw_compat_shader_remove(sw_context->fp->shman,
1667 cmd->body.shid,
1668 cmd->body.type,
1669 &sw_context->staged_shaders);
1670 if (unlikely(ret != 0))
1671 return ret;
1672
1673 return vmw_resource_relocation_add(&sw_context->res_relocations,
1674 NULL, &cmd->header.id -
1675 sw_context->buf_start);
1676
1677 return 0;
1678}
1679
1481/** 1680/**
1482 * vmw_cmd_set_shader - Validate an SVGA_3D_CMD_SET_SHADER 1681 * vmw_cmd_set_shader - Validate an SVGA_3D_CMD_SET_SHADER
1483 * command 1682 * command
@@ -1509,10 +1708,18 @@ static int vmw_cmd_set_shader(struct vmw_private *dev_priv,
1509 if (dev_priv->has_mob) { 1708 if (dev_priv->has_mob) {
1510 struct vmw_ctx_bindinfo bi; 1709 struct vmw_ctx_bindinfo bi;
1511 struct vmw_resource_val_node *res_node; 1710 struct vmw_resource_val_node *res_node;
1512 1711 u32 shid = cmd->body.shid;
1513 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_shader, 1712
1514 user_shader_converter, 1713 if (shid != SVGA3D_INVALID_ID)
1515 &cmd->body.shid, &res_node); 1714 (void) vmw_compat_shader_lookup(sw_context->fp->shman,
1715 cmd->body.type,
1716 &shid);
1717
1718 ret = vmw_cmd_compat_res_check(dev_priv, sw_context,
1719 vmw_res_shader,
1720 user_shader_converter,
1721 shid,
1722 &cmd->body.shid, &res_node);
1516 if (unlikely(ret != 0)) 1723 if (unlikely(ret != 0))
1517 return ret; 1724 return ret;
1518 1725
@@ -1527,6 +1734,39 @@ static int vmw_cmd_set_shader(struct vmw_private *dev_priv,
1527} 1734}
1528 1735
1529/** 1736/**
1737 * vmw_cmd_set_shader_const - Validate an SVGA_3D_CMD_SET_SHADER_CONST
1738 * command
1739 *
1740 * @dev_priv: Pointer to a device private struct.
1741 * @sw_context: The software context being used for this batch.
1742 * @header: Pointer to the command header in the command stream.
1743 */
1744static int vmw_cmd_set_shader_const(struct vmw_private *dev_priv,
1745 struct vmw_sw_context *sw_context,
1746 SVGA3dCmdHeader *header)
1747{
1748 struct vmw_set_shader_const_cmd {
1749 SVGA3dCmdHeader header;
1750 SVGA3dCmdSetShaderConst body;
1751 } *cmd;
1752 int ret;
1753
1754 cmd = container_of(header, struct vmw_set_shader_const_cmd,
1755 header);
1756
1757 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
1758 user_context_converter, &cmd->body.cid,
1759 NULL);
1760 if (unlikely(ret != 0))
1761 return ret;
1762
1763 if (dev_priv->has_mob)
1764 header->id = SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE;
1765
1766 return 0;
1767}
1768
1769/**
1530 * vmw_cmd_bind_gb_shader - Validate an SVGA_3D_CMD_BIND_GB_SHADER 1770 * vmw_cmd_bind_gb_shader - Validate an SVGA_3D_CMD_BIND_GB_SHADER
1531 * command 1771 * command
1532 * 1772 *
@@ -1595,7 +1835,7 @@ static int vmw_cmd_check_not_3d(struct vmw_private *dev_priv,
1595 return 0; 1835 return 0;
1596} 1836}
1597 1837
1598static const struct vmw_cmd_entry const vmw_cmd_entries[SVGA_3D_CMD_MAX] = { 1838static const struct vmw_cmd_entry vmw_cmd_entries[SVGA_3D_CMD_MAX] = {
1599 VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DEFINE, &vmw_cmd_invalid, 1839 VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DEFINE, &vmw_cmd_invalid,
1600 false, false, false), 1840 false, false, false),
1601 VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DESTROY, &vmw_cmd_invalid, 1841 VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DESTROY, &vmw_cmd_invalid,
@@ -1634,14 +1874,14 @@ static const struct vmw_cmd_entry const vmw_cmd_entries[SVGA_3D_CMD_MAX] = {
1634 true, false, false), 1874 true, false, false),
1635 VMW_CMD_DEF(SVGA_3D_CMD_PRESENT, &vmw_cmd_present_check, 1875 VMW_CMD_DEF(SVGA_3D_CMD_PRESENT, &vmw_cmd_present_check,
1636 false, false, false), 1876 false, false, false),
1637 VMW_CMD_DEF(SVGA_3D_CMD_SHADER_DEFINE, &vmw_cmd_cid_check, 1877 VMW_CMD_DEF(SVGA_3D_CMD_SHADER_DEFINE, &vmw_cmd_shader_define,
1638 true, true, false), 1878 true, false, false),
1639 VMW_CMD_DEF(SVGA_3D_CMD_SHADER_DESTROY, &vmw_cmd_cid_check, 1879 VMW_CMD_DEF(SVGA_3D_CMD_SHADER_DESTROY, &vmw_cmd_shader_destroy,
1640 true, true, false), 1880 true, false, false),
1641 VMW_CMD_DEF(SVGA_3D_CMD_SET_SHADER, &vmw_cmd_set_shader, 1881 VMW_CMD_DEF(SVGA_3D_CMD_SET_SHADER, &vmw_cmd_set_shader,
1642 true, false, false), 1882 true, false, false),
1643 VMW_CMD_DEF(SVGA_3D_CMD_SET_SHADER_CONST, &vmw_cmd_cid_check, 1883 VMW_CMD_DEF(SVGA_3D_CMD_SET_SHADER_CONST, &vmw_cmd_set_shader_const,
1644 true, true, false), 1884 true, false, false),
1645 VMW_CMD_DEF(SVGA_3D_CMD_DRAW_PRIMITIVES, &vmw_cmd_draw, 1885 VMW_CMD_DEF(SVGA_3D_CMD_DRAW_PRIMITIVES, &vmw_cmd_draw,
1646 true, false, false), 1886 true, false, false),
1647 VMW_CMD_DEF(SVGA_3D_CMD_SETSCISSORRECT, &vmw_cmd_cid_check, 1887 VMW_CMD_DEF(SVGA_3D_CMD_SETSCISSORRECT, &vmw_cmd_cid_check,
@@ -1792,6 +2032,9 @@ static int vmw_cmd_check(struct vmw_private *dev_priv,
1792 goto out_invalid; 2032 goto out_invalid;
1793 2033
1794 entry = &vmw_cmd_entries[cmd_id]; 2034 entry = &vmw_cmd_entries[cmd_id];
2035 if (unlikely(!entry->func))
2036 goto out_invalid;
2037
1795 if (unlikely(!entry->user_allow && !sw_context->kernel)) 2038 if (unlikely(!entry->user_allow && !sw_context->kernel))
1796 goto out_privileged; 2039 goto out_privileged;
1797 2040
@@ -2171,7 +2414,7 @@ int vmw_execbuf_process(struct drm_file *file_priv,
2171 } else 2414 } else
2172 sw_context->kernel = true; 2415 sw_context->kernel = true;
2173 2416
2174 sw_context->tfile = vmw_fpriv(file_priv)->tfile; 2417 sw_context->fp = vmw_fpriv(file_priv);
2175 sw_context->cur_reloc = 0; 2418 sw_context->cur_reloc = 0;
2176 sw_context->cur_val_buf = 0; 2419 sw_context->cur_val_buf = 0;
2177 sw_context->fence_flags = 0; 2420 sw_context->fence_flags = 0;
@@ -2188,16 +2431,17 @@ int vmw_execbuf_process(struct drm_file *file_priv,
2188 goto out_unlock; 2431 goto out_unlock;
2189 sw_context->res_ht_initialized = true; 2432 sw_context->res_ht_initialized = true;
2190 } 2433 }
2434 INIT_LIST_HEAD(&sw_context->staged_shaders);
2191 2435
2192 INIT_LIST_HEAD(&resource_list); 2436 INIT_LIST_HEAD(&resource_list);
2193 ret = vmw_cmd_check_all(dev_priv, sw_context, kernel_commands, 2437 ret = vmw_cmd_check_all(dev_priv, sw_context, kernel_commands,
2194 command_size); 2438 command_size);
2195 if (unlikely(ret != 0)) 2439 if (unlikely(ret != 0))
2196 goto out_err; 2440 goto out_err_nores;
2197 2441
2198 ret = vmw_resources_reserve(sw_context); 2442 ret = vmw_resources_reserve(sw_context);
2199 if (unlikely(ret != 0)) 2443 if (unlikely(ret != 0))
2200 goto out_err; 2444 goto out_err_nores;
2201 2445
2202 ret = ttm_eu_reserve_buffers(&ticket, &sw_context->validate_nodes); 2446 ret = ttm_eu_reserve_buffers(&ticket, &sw_context->validate_nodes);
2203 if (unlikely(ret != 0)) 2447 if (unlikely(ret != 0))
@@ -2225,6 +2469,12 @@ int vmw_execbuf_process(struct drm_file *file_priv,
2225 goto out_err; 2469 goto out_err;
2226 } 2470 }
2227 2471
2472 if (dev_priv->has_mob) {
2473 ret = vmw_rebind_contexts(sw_context);
2474 if (unlikely(ret != 0))
2475 goto out_unlock_binding;
2476 }
2477
2228 cmd = vmw_fifo_reserve(dev_priv, command_size); 2478 cmd = vmw_fifo_reserve(dev_priv, command_size);
2229 if (unlikely(cmd == NULL)) { 2479 if (unlikely(cmd == NULL)) {
2230 DRM_ERROR("Failed reserving fifo space for commands.\n"); 2480 DRM_ERROR("Failed reserving fifo space for commands.\n");
@@ -2276,6 +2526,8 @@ int vmw_execbuf_process(struct drm_file *file_priv,
2276 } 2526 }
2277 2527
2278 list_splice_init(&sw_context->resource_list, &resource_list); 2528 list_splice_init(&sw_context->resource_list, &resource_list);
2529 vmw_compat_shaders_commit(sw_context->fp->shman,
2530 &sw_context->staged_shaders);
2279 mutex_unlock(&dev_priv->cmdbuf_mutex); 2531 mutex_unlock(&dev_priv->cmdbuf_mutex);
2280 2532
2281 /* 2533 /*
@@ -2289,10 +2541,11 @@ int vmw_execbuf_process(struct drm_file *file_priv,
2289out_unlock_binding: 2541out_unlock_binding:
2290 mutex_unlock(&dev_priv->binding_mutex); 2542 mutex_unlock(&dev_priv->binding_mutex);
2291out_err: 2543out_err:
2292 vmw_resource_relocations_free(&sw_context->res_relocations);
2293 vmw_free_relocations(sw_context);
2294 ttm_eu_backoff_reservation(&ticket, &sw_context->validate_nodes); 2544 ttm_eu_backoff_reservation(&ticket, &sw_context->validate_nodes);
2545out_err_nores:
2295 vmw_resource_list_unreserve(&sw_context->resource_list, true); 2546 vmw_resource_list_unreserve(&sw_context->resource_list, true);
2547 vmw_resource_relocations_free(&sw_context->res_relocations);
2548 vmw_free_relocations(sw_context);
2296 vmw_clear_validations(sw_context); 2549 vmw_clear_validations(sw_context);
2297 if (unlikely(dev_priv->pinned_bo != NULL && 2550 if (unlikely(dev_priv->pinned_bo != NULL &&
2298 !dev_priv->query_cid_valid)) 2551 !dev_priv->query_cid_valid))
@@ -2301,6 +2554,8 @@ out_unlock:
2301 list_splice_init(&sw_context->resource_list, &resource_list); 2554 list_splice_init(&sw_context->resource_list, &resource_list);
2302 error_resource = sw_context->error_resource; 2555 error_resource = sw_context->error_resource;
2303 sw_context->error_resource = NULL; 2556 sw_context->error_resource = NULL;
2557 vmw_compat_shaders_revert(sw_context->fp->shman,
2558 &sw_context->staged_shaders);
2304 mutex_unlock(&dev_priv->cmdbuf_mutex); 2559 mutex_unlock(&dev_priv->cmdbuf_mutex);
2305 2560
2306 /* 2561 /*
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
index 116c49736763..47b70949bf3a 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
@@ -29,12 +29,18 @@
29#include <drm/vmwgfx_drm.h> 29#include <drm/vmwgfx_drm.h>
30#include "vmwgfx_kms.h" 30#include "vmwgfx_kms.h"
31 31
32struct svga_3d_compat_cap {
33 SVGA3dCapsRecordHeader header;
34 SVGA3dCapPair pairs[SVGA3D_DEVCAP_MAX];
35};
36
32int vmw_getparam_ioctl(struct drm_device *dev, void *data, 37int vmw_getparam_ioctl(struct drm_device *dev, void *data,
33 struct drm_file *file_priv) 38 struct drm_file *file_priv)
34{ 39{
35 struct vmw_private *dev_priv = vmw_priv(dev); 40 struct vmw_private *dev_priv = vmw_priv(dev);
36 struct drm_vmw_getparam_arg *param = 41 struct drm_vmw_getparam_arg *param =
37 (struct drm_vmw_getparam_arg *)data; 42 (struct drm_vmw_getparam_arg *)data;
43 struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
38 44
39 switch (param->param) { 45 switch (param->param) {
40 case DRM_VMW_PARAM_NUM_STREAMS: 46 case DRM_VMW_PARAM_NUM_STREAMS:
@@ -60,6 +66,11 @@ int vmw_getparam_ioctl(struct drm_device *dev, void *data,
60 __le32 __iomem *fifo_mem = dev_priv->mmio_virt; 66 __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
61 const struct vmw_fifo_state *fifo = &dev_priv->fifo; 67 const struct vmw_fifo_state *fifo = &dev_priv->fifo;
62 68
69 if ((dev_priv->capabilities & SVGA_CAP_GBOBJECTS)) {
70 param->value = SVGA3D_HWVERSION_WS8_B1;
71 break;
72 }
73
63 param->value = 74 param->value =
64 ioread32(fifo_mem + 75 ioread32(fifo_mem +
65 ((fifo->capabilities & 76 ((fifo->capabilities &
@@ -69,19 +80,31 @@ int vmw_getparam_ioctl(struct drm_device *dev, void *data,
69 break; 80 break;
70 } 81 }
71 case DRM_VMW_PARAM_MAX_SURF_MEMORY: 82 case DRM_VMW_PARAM_MAX_SURF_MEMORY:
72 param->value = dev_priv->memory_size; 83 if ((dev_priv->capabilities & SVGA_CAP_GBOBJECTS) &&
84 !vmw_fp->gb_aware)
85 param->value = dev_priv->max_mob_pages * PAGE_SIZE / 2;
86 else
87 param->value = dev_priv->memory_size;
73 break; 88 break;
74 case DRM_VMW_PARAM_3D_CAPS_SIZE: 89 case DRM_VMW_PARAM_3D_CAPS_SIZE:
75 if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS) 90 if ((dev_priv->capabilities & SVGA_CAP_GBOBJECTS) &&
76 param->value = SVGA3D_DEVCAP_MAX; 91 vmw_fp->gb_aware)
92 param->value = SVGA3D_DEVCAP_MAX * sizeof(uint32_t);
93 else if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS)
94 param->value = sizeof(struct svga_3d_compat_cap) +
95 sizeof(uint32_t);
77 else 96 else
78 param->value = (SVGA_FIFO_3D_CAPS_LAST - 97 param->value = (SVGA_FIFO_3D_CAPS_LAST -
79 SVGA_FIFO_3D_CAPS + 1); 98 SVGA_FIFO_3D_CAPS + 1) *
80 param->value *= sizeof(uint32_t); 99 sizeof(uint32_t);
81 break; 100 break;
82 case DRM_VMW_PARAM_MAX_MOB_MEMORY: 101 case DRM_VMW_PARAM_MAX_MOB_MEMORY:
102 vmw_fp->gb_aware = true;
83 param->value = dev_priv->max_mob_pages * PAGE_SIZE; 103 param->value = dev_priv->max_mob_pages * PAGE_SIZE;
84 break; 104 break;
105 case DRM_VMW_PARAM_MAX_MOB_SIZE:
106 param->value = dev_priv->max_mob_size;
107 break;
85 default: 108 default:
86 DRM_ERROR("Illegal vmwgfx get param request: %d\n", 109 DRM_ERROR("Illegal vmwgfx get param request: %d\n",
87 param->param); 110 param->param);
@@ -91,6 +114,38 @@ int vmw_getparam_ioctl(struct drm_device *dev, void *data,
91 return 0; 114 return 0;
92} 115}
93 116
117static int vmw_fill_compat_cap(struct vmw_private *dev_priv, void *bounce,
118 size_t size)
119{
120 struct svga_3d_compat_cap *compat_cap =
121 (struct svga_3d_compat_cap *) bounce;
122 unsigned int i;
123 size_t pair_offset = offsetof(struct svga_3d_compat_cap, pairs);
124 unsigned int max_size;
125
126 if (size < pair_offset)
127 return -EINVAL;
128
129 max_size = (size - pair_offset) / sizeof(SVGA3dCapPair);
130
131 if (max_size > SVGA3D_DEVCAP_MAX)
132 max_size = SVGA3D_DEVCAP_MAX;
133
134 compat_cap->header.length =
135 (pair_offset + max_size * sizeof(SVGA3dCapPair)) / sizeof(u32);
136 compat_cap->header.type = SVGA3DCAPS_RECORD_DEVCAPS;
137
138 mutex_lock(&dev_priv->hw_mutex);
139 for (i = 0; i < max_size; ++i) {
140 vmw_write(dev_priv, SVGA_REG_DEV_CAP, i);
141 compat_cap->pairs[i][0] = i;
142 compat_cap->pairs[i][1] = vmw_read(dev_priv, SVGA_REG_DEV_CAP);
143 }
144 mutex_unlock(&dev_priv->hw_mutex);
145
146 return 0;
147}
148
94 149
95int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data, 150int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
96 struct drm_file *file_priv) 151 struct drm_file *file_priv)
@@ -104,41 +159,49 @@ int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
104 void *bounce; 159 void *bounce;
105 int ret; 160 int ret;
106 bool gb_objects = !!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS); 161 bool gb_objects = !!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS);
162 struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
107 163
108 if (unlikely(arg->pad64 != 0)) { 164 if (unlikely(arg->pad64 != 0)) {
109 DRM_ERROR("Illegal GET_3D_CAP argument.\n"); 165 DRM_ERROR("Illegal GET_3D_CAP argument.\n");
110 return -EINVAL; 166 return -EINVAL;
111 } 167 }
112 168
113 if (gb_objects) 169 if (gb_objects && vmw_fp->gb_aware)
114 size = SVGA3D_DEVCAP_MAX; 170 size = SVGA3D_DEVCAP_MAX * sizeof(uint32_t);
171 else if (gb_objects)
172 size = sizeof(struct svga_3d_compat_cap) + sizeof(uint32_t);
115 else 173 else
116 size = (SVGA_FIFO_3D_CAPS_LAST - SVGA_FIFO_3D_CAPS + 1); 174 size = (SVGA_FIFO_3D_CAPS_LAST - SVGA_FIFO_3D_CAPS + 1) *
117 175 sizeof(uint32_t);
118 size *= sizeof(uint32_t);
119 176
120 if (arg->max_size < size) 177 if (arg->max_size < size)
121 size = arg->max_size; 178 size = arg->max_size;
122 179
123 bounce = vmalloc(size); 180 bounce = vzalloc(size);
124 if (unlikely(bounce == NULL)) { 181 if (unlikely(bounce == NULL)) {
125 DRM_ERROR("Failed to allocate bounce buffer for 3D caps.\n"); 182 DRM_ERROR("Failed to allocate bounce buffer for 3D caps.\n");
126 return -ENOMEM; 183 return -ENOMEM;
127 } 184 }
128 185
129 if (gb_objects) { 186 if (gb_objects && vmw_fp->gb_aware) {
130 int i; 187 int i, num;
131 uint32_t *bounce32 = (uint32_t *) bounce; 188 uint32_t *bounce32 = (uint32_t *) bounce;
132 189
190 num = size / sizeof(uint32_t);
191 if (num > SVGA3D_DEVCAP_MAX)
192 num = SVGA3D_DEVCAP_MAX;
193
133 mutex_lock(&dev_priv->hw_mutex); 194 mutex_lock(&dev_priv->hw_mutex);
134 for (i = 0; i < SVGA3D_DEVCAP_MAX; ++i) { 195 for (i = 0; i < num; ++i) {
135 vmw_write(dev_priv, SVGA_REG_DEV_CAP, i); 196 vmw_write(dev_priv, SVGA_REG_DEV_CAP, i);
136 *bounce32++ = vmw_read(dev_priv, SVGA_REG_DEV_CAP); 197 *bounce32++ = vmw_read(dev_priv, SVGA_REG_DEV_CAP);
137 } 198 }
138 mutex_unlock(&dev_priv->hw_mutex); 199 mutex_unlock(&dev_priv->hw_mutex);
139 200 } else if (gb_objects) {
201 ret = vmw_fill_compat_cap(dev_priv, bounce, size);
202 if (unlikely(ret != 0))
203 goto out_err;
140 } else { 204 } else {
141
142 fifo_mem = dev_priv->mmio_virt; 205 fifo_mem = dev_priv->mmio_virt;
143 memcpy_fromio(bounce, &fifo_mem[SVGA_FIFO_3D_CAPS], size); 206 memcpy_fromio(bounce, &fifo_mem[SVGA_FIFO_3D_CAPS], size);
144 } 207 }
@@ -146,6 +209,7 @@ int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
146 ret = copy_to_user(buffer, bounce, size); 209 ret = copy_to_user(buffer, bounce, size);
147 if (ret) 210 if (ret)
148 ret = -EFAULT; 211 ret = -EFAULT;
212out_err:
149 vfree(bounce); 213 vfree(bounce);
150 214
151 if (unlikely(ret != 0)) 215 if (unlikely(ret != 0))
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
index 4910e7b81811..04a64b8cd3cd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
@@ -134,6 +134,7 @@ static int vmw_setup_otable_base(struct vmw_private *dev_priv,
134 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); 134 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
135 if (unlikely(cmd == NULL)) { 135 if (unlikely(cmd == NULL)) {
136 DRM_ERROR("Failed reserving FIFO space for OTable setup.\n"); 136 DRM_ERROR("Failed reserving FIFO space for OTable setup.\n");
137 ret = -ENOMEM;
137 goto out_no_fifo; 138 goto out_no_fifo;
138 } 139 }
139 140
@@ -187,18 +188,20 @@ static void vmw_takedown_otable_base(struct vmw_private *dev_priv,
187 188
188 bo = otable->page_table->pt_bo; 189 bo = otable->page_table->pt_bo;
189 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); 190 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
190 if (unlikely(cmd == NULL)) 191 if (unlikely(cmd == NULL)) {
191 DRM_ERROR("Failed reserving FIFO space for OTable setup.\n"); 192 DRM_ERROR("Failed reserving FIFO space for OTable "
192 193 "takedown.\n");
193 memset(cmd, 0, sizeof(*cmd)); 194 } else {
194 cmd->header.id = SVGA_3D_CMD_SET_OTABLE_BASE; 195 memset(cmd, 0, sizeof(*cmd));
195 cmd->header.size = sizeof(cmd->body); 196 cmd->header.id = SVGA_3D_CMD_SET_OTABLE_BASE;
196 cmd->body.type = type; 197 cmd->header.size = sizeof(cmd->body);
197 cmd->body.baseAddress = 0; 198 cmd->body.type = type;
198 cmd->body.sizeInBytes = 0; 199 cmd->body.baseAddress = 0;
199 cmd->body.validSizeInBytes = 0; 200 cmd->body.sizeInBytes = 0;
200 cmd->body.ptDepth = SVGA3D_MOBFMT_INVALID; 201 cmd->body.validSizeInBytes = 0;
201 vmw_fifo_commit(dev_priv, sizeof(*cmd)); 202 cmd->body.ptDepth = SVGA3D_MOBFMT_INVALID;
203 vmw_fifo_commit(dev_priv, sizeof(*cmd));
204 }
202 205
203 if (bo) { 206 if (bo) {
204 int ret; 207 int ret;
@@ -561,11 +564,12 @@ void vmw_mob_unbind(struct vmw_private *dev_priv,
561 if (unlikely(cmd == NULL)) { 564 if (unlikely(cmd == NULL)) {
562 DRM_ERROR("Failed reserving FIFO space for Memory " 565 DRM_ERROR("Failed reserving FIFO space for Memory "
563 "Object unbinding.\n"); 566 "Object unbinding.\n");
567 } else {
568 cmd->header.id = SVGA_3D_CMD_DESTROY_GB_MOB;
569 cmd->header.size = sizeof(cmd->body);
570 cmd->body.mobid = mob->id;
571 vmw_fifo_commit(dev_priv, sizeof(*cmd));
564 } 572 }
565 cmd->header.id = SVGA_3D_CMD_DESTROY_GB_MOB;
566 cmd->header.size = sizeof(cmd->body);
567 cmd->body.mobid = mob->id;
568 vmw_fifo_commit(dev_priv, sizeof(*cmd));
569 if (bo) { 573 if (bo) {
570 vmw_fence_single_bo(bo, NULL); 574 vmw_fence_single_bo(bo, NULL);
571 ttm_bo_unreserve(bo); 575 ttm_bo_unreserve(bo);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 6fdd82d42f65..9757b57f8388 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -88,6 +88,11 @@ struct vmw_resource *vmw_resource_reference(struct vmw_resource *res)
88 return res; 88 return res;
89} 89}
90 90
91struct vmw_resource *
92vmw_resource_reference_unless_doomed(struct vmw_resource *res)
93{
94 return kref_get_unless_zero(&res->kref) ? res : NULL;
95}
91 96
92/** 97/**
93 * vmw_resource_release_id - release a resource id to the id manager. 98 * vmw_resource_release_id - release a resource id to the id manager.
@@ -136,8 +141,12 @@ static void vmw_resource_release(struct kref *kref)
136 vmw_dmabuf_unreference(&res->backup); 141 vmw_dmabuf_unreference(&res->backup);
137 } 142 }
138 143
139 if (likely(res->hw_destroy != NULL)) 144 if (likely(res->hw_destroy != NULL)) {
140 res->hw_destroy(res); 145 res->hw_destroy(res);
146 mutex_lock(&dev_priv->binding_mutex);
147 vmw_context_binding_res_list_kill(&res->binding_head);
148 mutex_unlock(&dev_priv->binding_mutex);
149 }
141 150
142 id = res->id; 151 id = res->id;
143 if (res->res_free != NULL) 152 if (res->res_free != NULL)
@@ -418,8 +427,7 @@ int vmw_dmabuf_init(struct vmw_private *dev_priv,
418 INIT_LIST_HEAD(&vmw_bo->res_list); 427 INIT_LIST_HEAD(&vmw_bo->res_list);
419 428
420 ret = ttm_bo_init(bdev, &vmw_bo->base, size, 429 ret = ttm_bo_init(bdev, &vmw_bo->base, size,
421 (user) ? ttm_bo_type_device : 430 ttm_bo_type_device, placement,
422 ttm_bo_type_kernel, placement,
423 0, interruptible, 431 0, interruptible,
424 NULL, acc_size, NULL, bo_free); 432 NULL, acc_size, NULL, bo_free);
425 return ret; 433 return ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
index 1457ec4b7125..ee3856578a12 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
@@ -29,6 +29,8 @@
29#include "vmwgfx_resource_priv.h" 29#include "vmwgfx_resource_priv.h"
30#include "ttm/ttm_placement.h" 30#include "ttm/ttm_placement.h"
31 31
32#define VMW_COMPAT_SHADER_HT_ORDER 12
33
32struct vmw_shader { 34struct vmw_shader {
33 struct vmw_resource res; 35 struct vmw_resource res;
34 SVGA3dShaderType type; 36 SVGA3dShaderType type;
@@ -40,6 +42,50 @@ struct vmw_user_shader {
40 struct vmw_shader shader; 42 struct vmw_shader shader;
41}; 43};
42 44
45/**
46 * enum vmw_compat_shader_state - Staging state for compat shaders
47 */
48enum vmw_compat_shader_state {
49 VMW_COMPAT_COMMITED,
50 VMW_COMPAT_ADD,
51 VMW_COMPAT_DEL
52};
53
54/**
55 * struct vmw_compat_shader - Metadata for compat shaders.
56 *
57 * @handle: The TTM handle of the guest backed shader.
58 * @tfile: The struct ttm_object_file the guest backed shader is registered
59 * with.
60 * @hash: Hash item for lookup.
61 * @head: List head for staging lists or the compat shader manager list.
62 * @state: Staging state.
63 *
64 * The structure is protected by the cmdbuf lock.
65 */
66struct vmw_compat_shader {
67 u32 handle;
68 struct ttm_object_file *tfile;
69 struct drm_hash_item hash;
70 struct list_head head;
71 enum vmw_compat_shader_state state;
72};
73
74/**
75 * struct vmw_compat_shader_manager - Compat shader manager.
76 *
77 * @shaders: Hash table containing staged and commited compat shaders
78 * @list: List of commited shaders.
79 * @dev_priv: Pointer to a device private structure.
80 *
81 * @shaders and @list are protected by the cmdbuf mutex for now.
82 */
83struct vmw_compat_shader_manager {
84 struct drm_open_hash shaders;
85 struct list_head list;
86 struct vmw_private *dev_priv;
87};
88
43static void vmw_user_shader_free(struct vmw_resource *res); 89static void vmw_user_shader_free(struct vmw_resource *res);
44static struct vmw_resource * 90static struct vmw_resource *
45vmw_user_shader_base_to_res(struct ttm_base_object *base); 91vmw_user_shader_base_to_res(struct ttm_base_object *base);
@@ -258,7 +304,7 @@ static int vmw_gb_shader_destroy(struct vmw_resource *res)
258 return 0; 304 return 0;
259 305
260 mutex_lock(&dev_priv->binding_mutex); 306 mutex_lock(&dev_priv->binding_mutex);
261 vmw_context_binding_res_list_kill(&res->binding_head); 307 vmw_context_binding_res_list_scrub(&res->binding_head);
262 308
263 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); 309 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
264 if (unlikely(cmd == NULL)) { 310 if (unlikely(cmd == NULL)) {
@@ -325,13 +371,81 @@ int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
325 TTM_REF_USAGE); 371 TTM_REF_USAGE);
326} 372}
327 373
374static int vmw_shader_alloc(struct vmw_private *dev_priv,
375 struct vmw_dma_buffer *buffer,
376 size_t shader_size,
377 size_t offset,
378 SVGA3dShaderType shader_type,
379 struct ttm_object_file *tfile,
380 u32 *handle)
381{
382 struct vmw_user_shader *ushader;
383 struct vmw_resource *res, *tmp;
384 int ret;
385
386 /*
387 * Approximate idr memory usage with 128 bytes. It will be limited
388 * by maximum number_of shaders anyway.
389 */
390 if (unlikely(vmw_user_shader_size == 0))
391 vmw_user_shader_size =
392 ttm_round_pot(sizeof(struct vmw_user_shader)) + 128;
393
394 ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
395 vmw_user_shader_size,
396 false, true);
397 if (unlikely(ret != 0)) {
398 if (ret != -ERESTARTSYS)
399 DRM_ERROR("Out of graphics memory for shader "
400 "creation.\n");
401 goto out;
402 }
403
404 ushader = kzalloc(sizeof(*ushader), GFP_KERNEL);
405 if (unlikely(ushader == NULL)) {
406 ttm_mem_global_free(vmw_mem_glob(dev_priv),
407 vmw_user_shader_size);
408 ret = -ENOMEM;
409 goto out;
410 }
411
412 res = &ushader->shader.res;
413 ushader->base.shareable = false;
414 ushader->base.tfile = NULL;
415
416 /*
417 * From here on, the destructor takes over resource freeing.
418 */
419
420 ret = vmw_gb_shader_init(dev_priv, res, shader_size,
421 offset, shader_type, buffer,
422 vmw_user_shader_free);
423 if (unlikely(ret != 0))
424 goto out;
425
426 tmp = vmw_resource_reference(res);
427 ret = ttm_base_object_init(tfile, &ushader->base, false,
428 VMW_RES_SHADER,
429 &vmw_user_shader_base_release, NULL);
430
431 if (unlikely(ret != 0)) {
432 vmw_resource_unreference(&tmp);
433 goto out_err;
434 }
435
436 if (handle)
437 *handle = ushader->base.hash.key;
438out_err:
439 vmw_resource_unreference(&res);
440out:
441 return ret;
442}
443
444
328int vmw_shader_define_ioctl(struct drm_device *dev, void *data, 445int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
329 struct drm_file *file_priv) 446 struct drm_file *file_priv)
330{ 447{
331 struct vmw_private *dev_priv = vmw_priv(dev); 448 struct vmw_private *dev_priv = vmw_priv(dev);
332 struct vmw_user_shader *ushader;
333 struct vmw_resource *res;
334 struct vmw_resource *tmp;
335 struct drm_vmw_shader_create_arg *arg = 449 struct drm_vmw_shader_create_arg *arg =
336 (struct drm_vmw_shader_create_arg *)data; 450 (struct drm_vmw_shader_create_arg *)data;
337 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; 451 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
@@ -373,69 +487,326 @@ int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
373 goto out_bad_arg; 487 goto out_bad_arg;
374 } 488 }
375 489
376 /* 490 ret = ttm_read_lock(&vmaster->lock, true);
377 * Approximate idr memory usage with 128 bytes. It will be limited 491 if (unlikely(ret != 0))
378 * by maximum number_of shaders anyway. 492 goto out_bad_arg;
379 */
380 493
381 if (unlikely(vmw_user_shader_size == 0)) 494 ret = vmw_shader_alloc(dev_priv, buffer, arg->size, arg->offset,
382 vmw_user_shader_size = ttm_round_pot(sizeof(*ushader)) 495 shader_type, tfile, &arg->shader_handle);
383 + 128;
384 496
385 ret = ttm_read_lock(&vmaster->lock, true); 497 ttm_read_unlock(&vmaster->lock);
498out_bad_arg:
499 vmw_dmabuf_unreference(&buffer);
500 return ret;
501}
502
503/**
504 * vmw_compat_shader_lookup - Look up a compat shader
505 *
506 * @man: Pointer to the compat shader manager.
507 * @shader_type: The shader type, that combined with the user_key identifies
508 * the shader.
509 * @user_key: On entry, this should be a pointer to the user_key.
510 * On successful exit, it will contain the guest-backed shader's TTM handle.
511 *
512 * Returns 0 on success. Non-zero on failure, in which case the value pointed
513 * to by @user_key is unmodified.
514 */
515int vmw_compat_shader_lookup(struct vmw_compat_shader_manager *man,
516 SVGA3dShaderType shader_type,
517 u32 *user_key)
518{
519 struct drm_hash_item *hash;
520 int ret;
521 unsigned long key = *user_key | (shader_type << 24);
522
523 ret = drm_ht_find_item(&man->shaders, key, &hash);
386 if (unlikely(ret != 0)) 524 if (unlikely(ret != 0))
387 return ret; 525 return ret;
388 526
389 ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), 527 *user_key = drm_hash_entry(hash, struct vmw_compat_shader,
390 vmw_user_shader_size, 528 hash)->handle;
391 false, true); 529
392 if (unlikely(ret != 0)) { 530 return 0;
393 if (ret != -ERESTARTSYS) 531}
394 DRM_ERROR("Out of graphics memory for shader" 532
395 " creation.\n"); 533/**
396 goto out_unlock; 534 * vmw_compat_shader_free - Free a compat shader.
535 *
536 * @man: Pointer to the compat shader manager.
537 * @entry: Pointer to a struct vmw_compat_shader.
538 *
539 * Frees a struct vmw_compat_shder entry and drops its reference to the
540 * guest backed shader.
541 */
542static void vmw_compat_shader_free(struct vmw_compat_shader_manager *man,
543 struct vmw_compat_shader *entry)
544{
545 list_del(&entry->head);
546 WARN_ON(drm_ht_remove_item(&man->shaders, &entry->hash));
547 WARN_ON(ttm_ref_object_base_unref(entry->tfile, entry->handle,
548 TTM_REF_USAGE));
549 kfree(entry);
550}
551
552/**
553 * vmw_compat_shaders_commit - Commit a list of compat shader actions.
554 *
555 * @man: Pointer to the compat shader manager.
556 * @list: Caller's list of compat shader actions.
557 *
558 * This function commits a list of compat shader additions or removals.
559 * It is typically called when the execbuf ioctl call triggering these
560 * actions has commited the fifo contents to the device.
561 */
562void vmw_compat_shaders_commit(struct vmw_compat_shader_manager *man,
563 struct list_head *list)
564{
565 struct vmw_compat_shader *entry, *next;
566
567 list_for_each_entry_safe(entry, next, list, head) {
568 list_del(&entry->head);
569 switch (entry->state) {
570 case VMW_COMPAT_ADD:
571 entry->state = VMW_COMPAT_COMMITED;
572 list_add_tail(&entry->head, &man->list);
573 break;
574 case VMW_COMPAT_DEL:
575 ttm_ref_object_base_unref(entry->tfile, entry->handle,
576 TTM_REF_USAGE);
577 kfree(entry);
578 break;
579 default:
580 BUG();
581 break;
582 }
397 } 583 }
584}
398 585
399 ushader = kzalloc(sizeof(*ushader), GFP_KERNEL); 586/**
400 if (unlikely(ushader == NULL)) { 587 * vmw_compat_shaders_revert - Revert a list of compat shader actions
401 ttm_mem_global_free(vmw_mem_glob(dev_priv), 588 *
402 vmw_user_shader_size); 589 * @man: Pointer to the compat shader manager.
403 ret = -ENOMEM; 590 * @list: Caller's list of compat shader actions.
404 goto out_unlock; 591 *
592 * This function reverts a list of compat shader additions or removals.
593 * It is typically called when the execbuf ioctl call triggering these
594 * actions failed for some reason, and the command stream was never
595 * submitted.
596 */
597void vmw_compat_shaders_revert(struct vmw_compat_shader_manager *man,
598 struct list_head *list)
599{
600 struct vmw_compat_shader *entry, *next;
601 int ret;
602
603 list_for_each_entry_safe(entry, next, list, head) {
604 switch (entry->state) {
605 case VMW_COMPAT_ADD:
606 vmw_compat_shader_free(man, entry);
607 break;
608 case VMW_COMPAT_DEL:
609 ret = drm_ht_insert_item(&man->shaders, &entry->hash);
610 list_del(&entry->head);
611 list_add_tail(&entry->head, &man->list);
612 entry->state = VMW_COMPAT_COMMITED;
613 break;
614 default:
615 BUG();
616 break;
617 }
405 } 618 }
619}
406 620
407 res = &ushader->shader.res; 621/**
408 ushader->base.shareable = false; 622 * vmw_compat_shader_remove - Stage a compat shader for removal.
409 ushader->base.tfile = NULL; 623 *
624 * @man: Pointer to the compat shader manager
625 * @user_key: The key that is used to identify the shader. The key is
626 * unique to the shader type.
627 * @shader_type: Shader type.
628 * @list: Caller's list of staged shader actions.
629 *
630 * This function stages a compat shader for removal and removes the key from
631 * the shader manager's hash table. If the shader was previously only staged
632 * for addition it is completely removed (But the execbuf code may keep a
633 * reference if it was bound to a context between addition and removal). If
634 * it was previously commited to the manager, it is staged for removal.
635 */
636int vmw_compat_shader_remove(struct vmw_compat_shader_manager *man,
637 u32 user_key, SVGA3dShaderType shader_type,
638 struct list_head *list)
639{
640 struct vmw_compat_shader *entry;
641 struct drm_hash_item *hash;
642 int ret;
410 643
411 /* 644 ret = drm_ht_find_item(&man->shaders, user_key | (shader_type << 24),
412 * From here on, the destructor takes over resource freeing. 645 &hash);
413 */ 646 if (likely(ret != 0))
647 return -EINVAL;
414 648
415 ret = vmw_gb_shader_init(dev_priv, res, arg->size, 649 entry = drm_hash_entry(hash, struct vmw_compat_shader, hash);
416 arg->offset, shader_type, buffer, 650
417 vmw_user_shader_free); 651 switch (entry->state) {
652 case VMW_COMPAT_ADD:
653 vmw_compat_shader_free(man, entry);
654 break;
655 case VMW_COMPAT_COMMITED:
656 (void) drm_ht_remove_item(&man->shaders, &entry->hash);
657 list_del(&entry->head);
658 entry->state = VMW_COMPAT_DEL;
659 list_add_tail(&entry->head, list);
660 break;
661 default:
662 BUG();
663 break;
664 }
665
666 return 0;
667}
668
669/**
670 * vmw_compat_shader_add - Create a compat shader and add the
671 * key to the manager
672 *
673 * @man: Pointer to the compat shader manager
674 * @user_key: The key that is used to identify the shader. The key is
675 * unique to the shader type.
676 * @bytecode: Pointer to the bytecode of the shader.
677 * @shader_type: Shader type.
678 * @tfile: Pointer to a struct ttm_object_file that the guest-backed shader is
679 * to be created with.
680 * @list: Caller's list of staged shader actions.
681 *
682 * Note that only the key is added to the shader manager's hash table.
683 * The shader is not yet added to the shader manager's list of shaders.
684 */
685int vmw_compat_shader_add(struct vmw_compat_shader_manager *man,
686 u32 user_key, const void *bytecode,
687 SVGA3dShaderType shader_type,
688 size_t size,
689 struct ttm_object_file *tfile,
690 struct list_head *list)
691{
692 struct vmw_dma_buffer *buf;
693 struct ttm_bo_kmap_obj map;
694 bool is_iomem;
695 struct vmw_compat_shader *compat;
696 u32 handle;
697 int ret;
698
699 if (user_key > ((1 << 24) - 1) || (unsigned) shader_type > 16)
700 return -EINVAL;
701
702 /* Allocate and pin a DMA buffer */
703 buf = kzalloc(sizeof(*buf), GFP_KERNEL);
704 if (unlikely(buf == NULL))
705 return -ENOMEM;
706
707 ret = vmw_dmabuf_init(man->dev_priv, buf, size, &vmw_sys_ne_placement,
708 true, vmw_dmabuf_bo_free);
418 if (unlikely(ret != 0)) 709 if (unlikely(ret != 0))
419 goto out_unlock; 710 goto out;
420 711
421 tmp = vmw_resource_reference(res); 712 ret = ttm_bo_reserve(&buf->base, false, true, false, NULL);
422 ret = ttm_base_object_init(tfile, &ushader->base, false, 713 if (unlikely(ret != 0))
423 VMW_RES_SHADER, 714 goto no_reserve;
424 &vmw_user_shader_base_release, NULL);
425 715
716 /* Map and copy shader bytecode. */
717 ret = ttm_bo_kmap(&buf->base, 0, PAGE_ALIGN(size) >> PAGE_SHIFT,
718 &map);
426 if (unlikely(ret != 0)) { 719 if (unlikely(ret != 0)) {
427 vmw_resource_unreference(&tmp); 720 ttm_bo_unreserve(&buf->base);
428 goto out_err; 721 goto no_reserve;
429 } 722 }
430 723
431 arg->shader_handle = ushader->base.hash.key; 724 memcpy(ttm_kmap_obj_virtual(&map, &is_iomem), bytecode, size);
432out_err: 725 WARN_ON(is_iomem);
433 vmw_resource_unreference(&res); 726
434out_unlock: 727 ttm_bo_kunmap(&map);
435 ttm_read_unlock(&vmaster->lock); 728 ret = ttm_bo_validate(&buf->base, &vmw_sys_placement, false, true);
436out_bad_arg: 729 WARN_ON(ret != 0);
437 vmw_dmabuf_unreference(&buffer); 730 ttm_bo_unreserve(&buf->base);
731
732 /* Create a guest-backed shader container backed by the dma buffer */
733 ret = vmw_shader_alloc(man->dev_priv, buf, size, 0, shader_type,
734 tfile, &handle);
735 vmw_dmabuf_unreference(&buf);
736 if (unlikely(ret != 0))
737 goto no_reserve;
738 /*
739 * Create a compat shader structure and stage it for insertion
740 * in the manager
741 */
742 compat = kzalloc(sizeof(*compat), GFP_KERNEL);
743 if (compat == NULL)
744 goto no_compat;
745
746 compat->hash.key = user_key | (shader_type << 24);
747 ret = drm_ht_insert_item(&man->shaders, &compat->hash);
748 if (unlikely(ret != 0))
749 goto out_invalid_key;
750
751 compat->state = VMW_COMPAT_ADD;
752 compat->handle = handle;
753 compat->tfile = tfile;
754 list_add_tail(&compat->head, list);
438 755
756 return 0;
757
758out_invalid_key:
759 kfree(compat);
760no_compat:
761 ttm_ref_object_base_unref(tfile, handle, TTM_REF_USAGE);
762no_reserve:
763out:
439 return ret; 764 return ret;
765}
766
767/**
768 * vmw_compat_shader_man_create - Create a compat shader manager
769 *
770 * @dev_priv: Pointer to a device private structure.
771 *
772 * Typically done at file open time. If successful returns a pointer to a
773 * compat shader manager. Otherwise returns an error pointer.
774 */
775struct vmw_compat_shader_manager *
776vmw_compat_shader_man_create(struct vmw_private *dev_priv)
777{
778 struct vmw_compat_shader_manager *man;
779 int ret;
780
781 man = kzalloc(sizeof(*man), GFP_KERNEL);
782 if (man == NULL)
783 return ERR_PTR(-ENOMEM);
784
785 man->dev_priv = dev_priv;
786 INIT_LIST_HEAD(&man->list);
787 ret = drm_ht_create(&man->shaders, VMW_COMPAT_SHADER_HT_ORDER);
788 if (ret == 0)
789 return man;
790
791 kfree(man);
792 return ERR_PTR(ret);
793}
794
795/**
796 * vmw_compat_shader_man_destroy - Destroy a compat shader manager
797 *
798 * @man: Pointer to the shader manager to destroy.
799 *
800 * Typically done at file close time.
801 */
802void vmw_compat_shader_man_destroy(struct vmw_compat_shader_manager *man)
803{
804 struct vmw_compat_shader *entry, *next;
805
806 mutex_lock(&man->dev_priv->cmdbuf_mutex);
807 list_for_each_entry_safe(entry, next, &man->list, head)
808 vmw_compat_shader_free(man, entry);
440 809
810 mutex_unlock(&man->dev_priv->cmdbuf_mutex);
811 kfree(man);
441} 812}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index 979da1c246a5..e7af580ab977 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -830,6 +830,24 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
830 if (unlikely(ret != 0)) 830 if (unlikely(ret != 0))
831 goto out_unlock; 831 goto out_unlock;
832 832
833 /*
834 * A gb-aware client referencing a shared surface will
835 * expect a backup buffer to be present.
836 */
837 if (dev_priv->has_mob && req->shareable) {
838 uint32_t backup_handle;
839
840 ret = vmw_user_dmabuf_alloc(dev_priv, tfile,
841 res->backup_size,
842 true,
843 &backup_handle,
844 &res->backup);
845 if (unlikely(ret != 0)) {
846 vmw_resource_unreference(&res);
847 goto out_unlock;
848 }
849 }
850
833 tmp = vmw_resource_reference(&srf->res); 851 tmp = vmw_resource_reference(&srf->res);
834 ret = ttm_prime_object_init(tfile, res->backup_size, &user_srf->prime, 852 ret = ttm_prime_object_init(tfile, res->backup_size, &user_srf->prime,
835 req->shareable, VMW_RES_SURFACE, 853 req->shareable, VMW_RES_SURFACE,
@@ -908,8 +926,8 @@ int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
908 rep->size_addr; 926 rep->size_addr;
909 927
910 if (user_sizes) 928 if (user_sizes)
911 ret = copy_to_user(user_sizes, srf->sizes, 929 ret = copy_to_user(user_sizes, &srf->base_size,
912 srf->num_sizes * sizeof(*srf->sizes)); 930 sizeof(srf->base_size));
913 if (unlikely(ret != 0)) { 931 if (unlikely(ret != 0)) {
914 DRM_ERROR("copy_to_user failed %p %u\n", 932 DRM_ERROR("copy_to_user failed %p %u\n",
915 user_sizes, srf->num_sizes); 933 user_sizes, srf->num_sizes);
@@ -1111,7 +1129,7 @@ static int vmw_gb_surface_destroy(struct vmw_resource *res)
1111 return 0; 1129 return 0;
1112 1130
1113 mutex_lock(&dev_priv->binding_mutex); 1131 mutex_lock(&dev_priv->binding_mutex);
1114 vmw_context_binding_res_list_kill(&res->binding_head); 1132 vmw_context_binding_res_list_scrub(&res->binding_head);
1115 1133
1116 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); 1134 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
1117 if (unlikely(cmd == NULL)) { 1135 if (unlikely(cmd == NULL)) {
diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c
index 1146e3bba6e1..112f27e51bc7 100644
--- a/drivers/gpu/host1x/job.c
+++ b/drivers/gpu/host1x/job.c
@@ -538,7 +538,7 @@ int host1x_job_pin(struct host1x_job *job, struct device *dev)
538 538
539 g->base = job->gather_addr_phys[i]; 539 g->base = job->gather_addr_phys[i];
540 540
541 for (j = 0; j < job->num_gathers; j++) 541 for (j = i + 1; j < job->num_gathers; j++)
542 if (job->gathers[j].bo == g->bo) 542 if (job->gathers[j].bo == g->bo)
543 job->gathers[j].handled = true; 543 job->gathers[j].handled = true;
544 544
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 497558127bb3..f822fd2a1ada 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -469,6 +469,9 @@ static const struct hid_device_id apple_devices[] = {
469 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 469 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
470 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI), 470 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI),
471 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, 471 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
472 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
473 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS),
474 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
472 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS), 475 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
473 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, 476 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
474 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI), 477 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 3bfac3accd22..cc32a6f96c64 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1679,6 +1679,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1679 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, 1679 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1680 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) }, 1680 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) },
1681 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) }, 1681 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
1682 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
1682 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 1683 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1683 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1684 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1684 { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) }, 1685 { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) },
@@ -1779,6 +1780,8 @@ static const struct hid_device_id hid_have_special_driver[] = {
1779 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) }, 1780 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1780 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) }, 1781 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
1781 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, 1782 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
1783 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_2) },
1784 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TOUCH_COVER_2) },
1782 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, 1785 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
1783 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) }, 1786 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
1784 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) }, 1787 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c
index 8fae6d1414cc..c24908f14934 100644
--- a/drivers/hid/hid-hyperv.c
+++ b/drivers/hid/hid-hyperv.c
@@ -157,6 +157,7 @@ struct mousevsc_dev {
157 u32 report_desc_size; 157 u32 report_desc_size;
158 struct hv_input_dev_info hid_dev_info; 158 struct hv_input_dev_info hid_dev_info;
159 struct hid_device *hid_device; 159 struct hid_device *hid_device;
160 u8 input_buf[HID_MAX_BUFFER_SIZE];
160}; 161};
161 162
162 163
@@ -256,6 +257,7 @@ static void mousevsc_on_receive(struct hv_device *device,
256 struct synthhid_msg *hid_msg; 257 struct synthhid_msg *hid_msg;
257 struct mousevsc_dev *input_dev = hv_get_drvdata(device); 258 struct mousevsc_dev *input_dev = hv_get_drvdata(device);
258 struct synthhid_input_report *input_report; 259 struct synthhid_input_report *input_report;
260 size_t len;
259 261
260 pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet + 262 pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet +
261 (packet->offset8 << 3)); 263 (packet->offset8 << 3));
@@ -300,9 +302,12 @@ static void mousevsc_on_receive(struct hv_device *device,
300 (struct synthhid_input_report *)pipe_msg->data; 302 (struct synthhid_input_report *)pipe_msg->data;
301 if (!input_dev->init_complete) 303 if (!input_dev->init_complete)
302 break; 304 break;
303 hid_input_report(input_dev->hid_device, 305
304 HID_INPUT_REPORT, input_report->buffer, 306 len = min(input_report->header.size,
305 input_report->header.size, 1); 307 (u32)sizeof(input_dev->input_buf));
308 memcpy(input_dev->input_buf, input_report->buffer, len);
309 hid_input_report(input_dev->hid_device, HID_INPUT_REPORT,
310 input_dev->input_buf, len, 1);
306 break; 311 break;
307 default: 312 default:
308 pr_err("unsupported hid msg type - type %d len %d", 313 pr_err("unsupported hid msg type - type %d len %d",
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 5a5248f2cc07..22f28d6b33a8 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -135,6 +135,7 @@
135#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b 135#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
136#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI 0x0255 136#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI 0x0255
137#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256 137#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256
138#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS 0x0257
138#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290 139#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290
139#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291 140#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291
140#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292 141#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292
@@ -240,6 +241,7 @@
240 241
241#define USB_VENDOR_ID_CYGNAL 0x10c4 242#define USB_VENDOR_ID_CYGNAL 0x10c4
242#define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a 243#define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a
244#define USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH 0x81b9
243 245
244#define USB_DEVICE_ID_CYGNAL_RADIO_SI4713 0x8244 246#define USB_DEVICE_ID_CYGNAL_RADIO_SI4713 0x8244
245 247
@@ -451,6 +453,9 @@
451#define USB_VENDOR_ID_INTEL_1 0x8087 453#define USB_VENDOR_ID_INTEL_1 0x8087
452#define USB_DEVICE_ID_INTEL_HID_SENSOR 0x09fa 454#define USB_DEVICE_ID_INTEL_HID_SENSOR 0x09fa
453 455
456#define USB_VENDOR_ID_STM_0 0x0483
457#define USB_DEVICE_ID_STM_HID_SENSOR 0x91d1
458
454#define USB_VENDOR_ID_ION 0x15e4 459#define USB_VENDOR_ID_ION 0x15e4
455#define USB_DEVICE_ID_ICADE 0x0132 460#define USB_DEVICE_ID_ICADE 0x0132
456 461
@@ -619,6 +624,8 @@
619#define USB_DEVICE_ID_MS_PRESENTER_8K_USB 0x0713 624#define USB_DEVICE_ID_MS_PRESENTER_8K_USB 0x0713
620#define USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K 0x0730 625#define USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K 0x0730
621#define USB_DEVICE_ID_MS_COMFORT_MOUSE_4500 0x076c 626#define USB_DEVICE_ID_MS_COMFORT_MOUSE_4500 0x076c
627#define USB_DEVICE_ID_MS_TOUCH_COVER_2 0x07a7
628#define USB_DEVICE_ID_MS_TYPE_COVER_2 0x07a9
622 629
623#define USB_VENDOR_ID_MOJO 0x8282 630#define USB_VENDOR_ID_MOJO 0x8282
624#define USB_DEVICE_ID_RETRO_ADAPTER 0x3201 631#define USB_DEVICE_ID_RETRO_ADAPTER 0x3201
@@ -644,6 +651,7 @@
644 651
645#define USB_VENDOR_ID_NEXIO 0x1870 652#define USB_VENDOR_ID_NEXIO 0x1870
646#define USB_DEVICE_ID_NEXIO_MULTITOUCH_420 0x010d 653#define USB_DEVICE_ID_NEXIO_MULTITOUCH_420 0x010d
654#define USB_DEVICE_ID_NEXIO_MULTITOUCH_PTI0750 0x0110
647 655
648#define USB_VENDOR_ID_NEXTWINDOW 0x1926 656#define USB_VENDOR_ID_NEXTWINDOW 0x1926
649#define USB_DEVICE_ID_NEXTWINDOW_TOUCHSCREEN 0x0003 657#define USB_DEVICE_ID_NEXTWINDOW_TOUCHSCREEN 0x0003
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index d50e7313b171..a713e6211419 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -1178,7 +1178,7 @@ static void hidinput_led_worker(struct work_struct *work)
1178 1178
1179 /* fall back to generic raw-output-report */ 1179 /* fall back to generic raw-output-report */
1180 len = ((report->size - 1) >> 3) + 1 + (report->id > 0); 1180 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
1181 buf = kmalloc(len, GFP_KERNEL); 1181 buf = hid_alloc_report_buf(report, GFP_KERNEL);
1182 if (!buf) 1182 if (!buf)
1183 return; 1183 return;
1184 1184
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
index befe0e336471..24883b4d1a49 100644
--- a/drivers/hid/hid-lg4ff.c
+++ b/drivers/hid/hid-lg4ff.c
@@ -43,6 +43,7 @@
43#define G25_REV_MIN 0x22 43#define G25_REV_MIN 0x22
44#define G27_REV_MAJ 0x12 44#define G27_REV_MAJ 0x12
45#define G27_REV_MIN 0x38 45#define G27_REV_MIN 0x38
46#define G27_2_REV_MIN 0x39
46 47
47#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) 48#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev)
48 49
@@ -130,6 +131,7 @@ static const struct lg4ff_usb_revision lg4ff_revs[] = {
130 {DFP_REV_MAJ, DFP_REV_MIN, &native_dfp}, /* Driving Force Pro */ 131 {DFP_REV_MAJ, DFP_REV_MIN, &native_dfp}, /* Driving Force Pro */
131 {G25_REV_MAJ, G25_REV_MIN, &native_g25}, /* G25 */ 132 {G25_REV_MAJ, G25_REV_MIN, &native_g25}, /* G25 */
132 {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */ 133 {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */
134 {G27_REV_MAJ, G27_2_REV_MIN, &native_g27}, /* G27 v2 */
133}; 135};
134 136
135/* Recalculates X axis value accordingly to currently selected range */ 137/* Recalculates X axis value accordingly to currently selected range */
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index c6ef6eed3091..404a3a8a82f1 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -208,6 +208,10 @@ static const struct hid_device_id ms_devices[] = {
208 .driver_data = MS_NOGET }, 208 .driver_data = MS_NOGET },
209 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500), 209 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500),
210 .driver_data = MS_DUPLICATE_USAGES }, 210 .driver_data = MS_DUPLICATE_USAGES },
211 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_2),
212 .driver_data = 0 },
213 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TOUCH_COVER_2),
214 .driver_data = 0 },
211 215
212 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), 216 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT),
213 .driver_data = MS_PRESENTER }, 217 .driver_data = MS_PRESENTER },
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index f134d73beca1..221d503f1c24 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -1166,6 +1166,11 @@ static const struct hid_device_id mt_devices[] = {
1166 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG, 1166 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1167 USB_DEVICE_ID_MULTITOUCH_3200) }, 1167 USB_DEVICE_ID_MULTITOUCH_3200) },
1168 1168
1169 /* FocalTech Panels */
1170 { .driver_data = MT_CLS_SERIAL,
1171 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
1172 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
1173
1169 /* GeneralTouch panel */ 1174 /* GeneralTouch panel */
1170 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS, 1175 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1171 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 1176 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 46f4480035bc..9c22e14c57f0 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -665,6 +665,9 @@ static const struct hid_device_id sensor_hub_devices[] = {
665 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_INTEL_1, 665 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_INTEL_1,
666 USB_DEVICE_ID_INTEL_HID_SENSOR), 666 USB_DEVICE_ID_INTEL_HID_SENSOR),
667 .driver_data = HID_SENSOR_HUB_ENUM_QUIRK}, 667 .driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
668 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_STM_0,
669 USB_DEVICE_ID_STM_HID_SENSOR),
670 .driver_data = HID_SENSOR_HUB_ENUM_QUIRK},
668 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, HID_ANY_ID, 671 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, HID_ANY_ID,
669 HID_ANY_ID) }, 672 HID_ANY_ID) },
670 { } 673 { }
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 12354055d474..2f19b15f47f2 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -42,6 +42,7 @@
42#define DUALSHOCK4_CONTROLLER_BT BIT(6) 42#define DUALSHOCK4_CONTROLLER_BT BIT(6)
43 43
44#define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER | DUALSHOCK4_CONTROLLER_USB) 44#define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER | DUALSHOCK4_CONTROLLER_USB)
45#define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER_USB | DUALSHOCK4_CONTROLLER_USB)
45 46
46#define MAX_LEDS 4 47#define MAX_LEDS 4
47 48
@@ -499,6 +500,7 @@ struct sony_sc {
499 __u8 right; 500 __u8 right;
500#endif 501#endif
501 502
503 __u8 worker_initialized;
502 __u8 led_state[MAX_LEDS]; 504 __u8 led_state[MAX_LEDS];
503 __u8 led_count; 505 __u8 led_count;
504}; 506};
@@ -993,22 +995,11 @@ static int sony_init_ff(struct hid_device *hdev)
993 return input_ff_create_memless(input_dev, NULL, sony_play_effect); 995 return input_ff_create_memless(input_dev, NULL, sony_play_effect);
994} 996}
995 997
996static void sony_destroy_ff(struct hid_device *hdev)
997{
998 struct sony_sc *sc = hid_get_drvdata(hdev);
999
1000 cancel_work_sync(&sc->state_worker);
1001}
1002
1003#else 998#else
1004static int sony_init_ff(struct hid_device *hdev) 999static int sony_init_ff(struct hid_device *hdev)
1005{ 1000{
1006 return 0; 1001 return 0;
1007} 1002}
1008
1009static void sony_destroy_ff(struct hid_device *hdev)
1010{
1011}
1012#endif 1003#endif
1013 1004
1014static int sony_set_output_report(struct sony_sc *sc, int req_id, int req_size) 1005static int sony_set_output_report(struct sony_sc *sc, int req_id, int req_size)
@@ -1077,6 +1068,8 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
1077 if (sc->quirks & SIXAXIS_CONTROLLER_USB) { 1068 if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
1078 hdev->hid_output_raw_report = sixaxis_usb_output_raw_report; 1069 hdev->hid_output_raw_report = sixaxis_usb_output_raw_report;
1079 ret = sixaxis_set_operational_usb(hdev); 1070 ret = sixaxis_set_operational_usb(hdev);
1071
1072 sc->worker_initialized = 1;
1080 INIT_WORK(&sc->state_worker, sixaxis_state_worker); 1073 INIT_WORK(&sc->state_worker, sixaxis_state_worker);
1081 } 1074 }
1082 else if (sc->quirks & SIXAXIS_CONTROLLER_BT) 1075 else if (sc->quirks & SIXAXIS_CONTROLLER_BT)
@@ -1087,6 +1080,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
1087 if (ret < 0) 1080 if (ret < 0)
1088 goto err_stop; 1081 goto err_stop;
1089 1082
1083 sc->worker_initialized = 1;
1090 INIT_WORK(&sc->state_worker, dualshock4_state_worker); 1084 INIT_WORK(&sc->state_worker, dualshock4_state_worker);
1091 } else { 1085 } else {
1092 ret = 0; 1086 ret = 0;
@@ -1101,9 +1095,11 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
1101 goto err_stop; 1095 goto err_stop;
1102 } 1096 }
1103 1097
1104 ret = sony_init_ff(hdev); 1098 if (sc->quirks & SONY_FF_SUPPORT) {
1105 if (ret < 0) 1099 ret = sony_init_ff(hdev);
1106 goto err_stop; 1100 if (ret < 0)
1101 goto err_stop;
1102 }
1107 1103
1108 return 0; 1104 return 0;
1109err_stop: 1105err_stop:
@@ -1120,7 +1116,8 @@ static void sony_remove(struct hid_device *hdev)
1120 if (sc->quirks & SONY_LED_SUPPORT) 1116 if (sc->quirks & SONY_LED_SUPPORT)
1121 sony_leds_remove(hdev); 1117 sony_leds_remove(hdev);
1122 1118
1123 sony_destroy_ff(hdev); 1119 if (sc->worker_initialized)
1120 cancel_work_sync(&sc->state_worker);
1124 1121
1125 hid_hw_stop(hdev); 1122 hid_hw_stop(hdev);
1126} 1123}
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index cb0137b3718d..ab24ce2eb28f 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -320,13 +320,13 @@ static void drop_ref(struct hidraw *hidraw, int exists_bit)
320 hid_hw_close(hidraw->hid); 320 hid_hw_close(hidraw->hid);
321 wake_up_interruptible(&hidraw->wait); 321 wake_up_interruptible(&hidraw->wait);
322 } 322 }
323 device_destroy(hidraw_class,
324 MKDEV(hidraw_major, hidraw->minor));
323 } else { 325 } else {
324 --hidraw->open; 326 --hidraw->open;
325 } 327 }
326 if (!hidraw->open) { 328 if (!hidraw->open) {
327 if (!hidraw->exist) { 329 if (!hidraw->exist) {
328 device_destroy(hidraw_class,
329 MKDEV(hidraw_major, hidraw->minor));
330 hidraw_table[hidraw->minor] = NULL; 330 hidraw_table[hidraw->minor] = NULL;
331 kfree(hidraw); 331 kfree(hidraw);
332 } else { 332 } else {
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index d1f81f52481a..42eebd14de1f 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -582,7 +582,7 @@ static void i2c_hid_request(struct hid_device *hid, struct hid_report *rep,
582 int ret; 582 int ret;
583 int len = i2c_hid_get_report_length(rep) - 2; 583 int len = i2c_hid_get_report_length(rep) - 2;
584 584
585 buf = kzalloc(len, GFP_KERNEL); 585 buf = hid_alloc_report_buf(rep, GFP_KERNEL);
586 if (!buf) 586 if (!buf)
587 return; 587 return;
588 588
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 175ec0afb70c..dbd83878ff99 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -74,6 +74,7 @@ static const struct hid_blacklist {
74 { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET }, 74 { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET },
75 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET }, 75 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET },
76 { USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GX680R_LED_PANEL, HID_QUIRK_NO_INIT_REPORTS }, 76 { USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GX680R_LED_PANEL, HID_QUIRK_NO_INIT_REPORTS },
77 { USB_VENDOR_ID_NEXIO, USB_DEVICE_ID_NEXIO_MULTITOUCH_PTI0750, HID_QUIRK_NO_INIT_REPORTS },
77 { USB_VENDOR_ID_NOVATEK, USB_DEVICE_ID_NOVATEK_MOUSE, HID_QUIRK_NO_INIT_REPORTS }, 78 { USB_VENDOR_ID_NOVATEK, USB_DEVICE_ID_NOVATEK_MOUSE, HID_QUIRK_NO_INIT_REPORTS },
78 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS }, 79 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS },
79 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS }, 80 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS },
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index af6edf9b1936..f2d7bf90c9fe 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -67,7 +67,6 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
67 int ret = 0; 67 int ret = 0;
68 struct vmbus_channel_initiate_contact *msg; 68 struct vmbus_channel_initiate_contact *msg;
69 unsigned long flags; 69 unsigned long flags;
70 int t;
71 70
72 init_completion(&msginfo->waitevent); 71 init_completion(&msginfo->waitevent);
73 72
@@ -78,6 +77,8 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
78 msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); 77 msg->interrupt_page = virt_to_phys(vmbus_connection.int_page);
79 msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]); 78 msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]);
80 msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]); 79 msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]);
80 if (version == VERSION_WIN8)
81 msg->target_vcpu = hv_context.vp_index[smp_processor_id()];
81 82
82 /* 83 /*
83 * Add to list before we send the request since we may 84 * Add to list before we send the request since we may
@@ -100,15 +101,7 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
100 } 101 }
101 102
102 /* Wait for the connection response */ 103 /* Wait for the connection response */
103 t = wait_for_completion_timeout(&msginfo->waitevent, 5*HZ); 104 wait_for_completion(&msginfo->waitevent);
104 if (t == 0) {
105 spin_lock_irqsave(&vmbus_connection.channelmsg_lock,
106 flags);
107 list_del(&msginfo->msglistentry);
108 spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock,
109 flags);
110 return -ETIMEDOUT;
111 }
112 105
113 spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); 106 spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
114 list_del(&msginfo->msglistentry); 107 list_del(&msginfo->msglistentry);
diff --git a/drivers/hwmon/da9055-hwmon.c b/drivers/hwmon/da9055-hwmon.c
index 029ecabc4380..73b3865f1207 100644
--- a/drivers/hwmon/da9055-hwmon.c
+++ b/drivers/hwmon/da9055-hwmon.c
@@ -278,10 +278,6 @@ static int da9055_hwmon_probe(struct platform_device *pdev)
278 if (hwmon_irq < 0) 278 if (hwmon_irq < 0)
279 return hwmon_irq; 279 return hwmon_irq;
280 280
281 hwmon_irq = regmap_irq_get_virq(hwmon->da9055->irq_data, hwmon_irq);
282 if (hwmon_irq < 0)
283 return hwmon_irq;
284
285 ret = devm_request_threaded_irq(&pdev->dev, hwmon_irq, 281 ret = devm_request_threaded_irq(&pdev->dev, hwmon_irq,
286 NULL, da9055_auxadc_irq, 282 NULL, da9055_auxadc_irq,
287 IRQF_TRIGGER_HIGH | IRQF_ONESHOT, 283 IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c
index a7626358c95d..029b65e6c589 100644
--- a/drivers/hwmon/max1668.c
+++ b/drivers/hwmon/max1668.c
@@ -243,7 +243,7 @@ static ssize_t set_temp_min(struct device *dev,
243 data->temp_min[index] = clamp_val(temp/1000, -128, 127); 243 data->temp_min[index] = clamp_val(temp/1000, -128, 127);
244 if (i2c_smbus_write_byte_data(client, 244 if (i2c_smbus_write_byte_data(client,
245 MAX1668_REG_LIML_WR(index), 245 MAX1668_REG_LIML_WR(index),
246 data->temp_max[index])) 246 data->temp_min[index]))
247 count = -EIO; 247 count = -EIO;
248 mutex_unlock(&data->update_lock); 248 mutex_unlock(&data->update_lock);
249 249
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index 8c23203915af..8a17f01e8672 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -145,7 +145,7 @@ struct ntc_data {
145static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata) 145static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
146{ 146{
147 struct iio_channel *channel = pdata->chan; 147 struct iio_channel *channel = pdata->chan;
148 unsigned int result; 148 s64 result;
149 int val, ret; 149 int val, ret;
150 150
151 ret = iio_read_channel_raw(channel, &val); 151 ret = iio_read_channel_raw(channel, &val);
@@ -155,10 +155,10 @@ static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
155 } 155 }
156 156
157 /* unit: mV */ 157 /* unit: mV */
158 result = pdata->pullup_uv * val; 158 result = pdata->pullup_uv * (s64) val;
159 result >>= 12; 159 result >>= 12;
160 160
161 return result; 161 return (int)result;
162} 162}
163 163
164static const struct of_device_id ntc_match[] = { 164static const struct of_device_id ntc_match[] = {
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 3cbf66e9d861..291d11fe93e7 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -90,7 +90,8 @@ struct pmbus_data {
90 90
91 u32 flags; /* from platform data */ 91 u32 flags; /* from platform data */
92 92
93 int exponent; /* linear mode: exponent for output voltages */ 93 int exponent[PMBUS_PAGES];
94 /* linear mode: exponent for output voltages */
94 95
95 const struct pmbus_driver_info *info; 96 const struct pmbus_driver_info *info;
96 97
@@ -410,7 +411,7 @@ static long pmbus_reg2data_linear(struct pmbus_data *data,
410 long val; 411 long val;
411 412
412 if (sensor->class == PSC_VOLTAGE_OUT) { /* LINEAR16 */ 413 if (sensor->class == PSC_VOLTAGE_OUT) { /* LINEAR16 */
413 exponent = data->exponent; 414 exponent = data->exponent[sensor->page];
414 mantissa = (u16) sensor->data; 415 mantissa = (u16) sensor->data;
415 } else { /* LINEAR11 */ 416 } else { /* LINEAR11 */
416 exponent = ((s16)sensor->data) >> 11; 417 exponent = ((s16)sensor->data) >> 11;
@@ -516,7 +517,7 @@ static long pmbus_reg2data(struct pmbus_data *data, struct pmbus_sensor *sensor)
516#define MIN_MANTISSA (511 * 1000) 517#define MIN_MANTISSA (511 * 1000)
517 518
518static u16 pmbus_data2reg_linear(struct pmbus_data *data, 519static u16 pmbus_data2reg_linear(struct pmbus_data *data,
519 enum pmbus_sensor_classes class, long val) 520 struct pmbus_sensor *sensor, long val)
520{ 521{
521 s16 exponent = 0, mantissa; 522 s16 exponent = 0, mantissa;
522 bool negative = false; 523 bool negative = false;
@@ -525,7 +526,7 @@ static u16 pmbus_data2reg_linear(struct pmbus_data *data,
525 if (val == 0) 526 if (val == 0)
526 return 0; 527 return 0;
527 528
528 if (class == PSC_VOLTAGE_OUT) { 529 if (sensor->class == PSC_VOLTAGE_OUT) {
529 /* LINEAR16 does not support negative voltages */ 530 /* LINEAR16 does not support negative voltages */
530 if (val < 0) 531 if (val < 0)
531 return 0; 532 return 0;
@@ -534,10 +535,10 @@ static u16 pmbus_data2reg_linear(struct pmbus_data *data,
534 * For a static exponents, we don't have a choice 535 * For a static exponents, we don't have a choice
535 * but to adjust the value to it. 536 * but to adjust the value to it.
536 */ 537 */
537 if (data->exponent < 0) 538 if (data->exponent[sensor->page] < 0)
538 val <<= -data->exponent; 539 val <<= -data->exponent[sensor->page];
539 else 540 else
540 val >>= data->exponent; 541 val >>= data->exponent[sensor->page];
541 val = DIV_ROUND_CLOSEST(val, 1000); 542 val = DIV_ROUND_CLOSEST(val, 1000);
542 return val & 0xffff; 543 return val & 0xffff;
543 } 544 }
@@ -548,14 +549,14 @@ static u16 pmbus_data2reg_linear(struct pmbus_data *data,
548 } 549 }
549 550
550 /* Power is in uW. Convert to mW before converting. */ 551 /* Power is in uW. Convert to mW before converting. */
551 if (class == PSC_POWER) 552 if (sensor->class == PSC_POWER)
552 val = DIV_ROUND_CLOSEST(val, 1000L); 553 val = DIV_ROUND_CLOSEST(val, 1000L);
553 554
554 /* 555 /*
555 * For simplicity, convert fan data to milli-units 556 * For simplicity, convert fan data to milli-units
556 * before calculating the exponent. 557 * before calculating the exponent.
557 */ 558 */
558 if (class == PSC_FAN) 559 if (sensor->class == PSC_FAN)
559 val = val * 1000; 560 val = val * 1000;
560 561
561 /* Reduce large mantissa until it fits into 10 bit */ 562 /* Reduce large mantissa until it fits into 10 bit */
@@ -585,22 +586,22 @@ static u16 pmbus_data2reg_linear(struct pmbus_data *data,
585} 586}
586 587
587static u16 pmbus_data2reg_direct(struct pmbus_data *data, 588static u16 pmbus_data2reg_direct(struct pmbus_data *data,
588 enum pmbus_sensor_classes class, long val) 589 struct pmbus_sensor *sensor, long val)
589{ 590{
590 long m, b, R; 591 long m, b, R;
591 592
592 m = data->info->m[class]; 593 m = data->info->m[sensor->class];
593 b = data->info->b[class]; 594 b = data->info->b[sensor->class];
594 R = data->info->R[class]; 595 R = data->info->R[sensor->class];
595 596
596 /* Power is in uW. Adjust R and b. */ 597 /* Power is in uW. Adjust R and b. */
597 if (class == PSC_POWER) { 598 if (sensor->class == PSC_POWER) {
598 R -= 3; 599 R -= 3;
599 b *= 1000; 600 b *= 1000;
600 } 601 }
601 602
602 /* Calculate Y = (m * X + b) * 10^R */ 603 /* Calculate Y = (m * X + b) * 10^R */
603 if (class != PSC_FAN) { 604 if (sensor->class != PSC_FAN) {
604 R -= 3; /* Adjust R and b for data in milli-units */ 605 R -= 3; /* Adjust R and b for data in milli-units */
605 b *= 1000; 606 b *= 1000;
606 } 607 }
@@ -619,7 +620,7 @@ static u16 pmbus_data2reg_direct(struct pmbus_data *data,
619} 620}
620 621
621static u16 pmbus_data2reg_vid(struct pmbus_data *data, 622static u16 pmbus_data2reg_vid(struct pmbus_data *data,
622 enum pmbus_sensor_classes class, long val) 623 struct pmbus_sensor *sensor, long val)
623{ 624{
624 val = clamp_val(val, 500, 1600); 625 val = clamp_val(val, 500, 1600);
625 626
@@ -627,20 +628,20 @@ static u16 pmbus_data2reg_vid(struct pmbus_data *data,
627} 628}
628 629
629static u16 pmbus_data2reg(struct pmbus_data *data, 630static u16 pmbus_data2reg(struct pmbus_data *data,
630 enum pmbus_sensor_classes class, long val) 631 struct pmbus_sensor *sensor, long val)
631{ 632{
632 u16 regval; 633 u16 regval;
633 634
634 switch (data->info->format[class]) { 635 switch (data->info->format[sensor->class]) {
635 case direct: 636 case direct:
636 regval = pmbus_data2reg_direct(data, class, val); 637 regval = pmbus_data2reg_direct(data, sensor, val);
637 break; 638 break;
638 case vid: 639 case vid:
639 regval = pmbus_data2reg_vid(data, class, val); 640 regval = pmbus_data2reg_vid(data, sensor, val);
640 break; 641 break;
641 case linear: 642 case linear:
642 default: 643 default:
643 regval = pmbus_data2reg_linear(data, class, val); 644 regval = pmbus_data2reg_linear(data, sensor, val);
644 break; 645 break;
645 } 646 }
646 return regval; 647 return regval;
@@ -746,7 +747,7 @@ static ssize_t pmbus_set_sensor(struct device *dev,
746 return -EINVAL; 747 return -EINVAL;
747 748
748 mutex_lock(&data->update_lock); 749 mutex_lock(&data->update_lock);
749 regval = pmbus_data2reg(data, sensor->class, val); 750 regval = pmbus_data2reg(data, sensor, val);
750 ret = _pmbus_write_word_data(client, sensor->page, sensor->reg, regval); 751 ret = _pmbus_write_word_data(client, sensor->page, sensor->reg, regval);
751 if (ret < 0) 752 if (ret < 0)
752 rv = ret; 753 rv = ret;
@@ -1643,12 +1644,13 @@ static int pmbus_find_attributes(struct i2c_client *client,
1643 * This function is called for all chips. 1644 * This function is called for all chips.
1644 */ 1645 */
1645static int pmbus_identify_common(struct i2c_client *client, 1646static int pmbus_identify_common(struct i2c_client *client,
1646 struct pmbus_data *data) 1647 struct pmbus_data *data, int page)
1647{ 1648{
1648 int vout_mode = -1; 1649 int vout_mode = -1;
1649 1650
1650 if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE)) 1651 if (pmbus_check_byte_register(client, page, PMBUS_VOUT_MODE))
1651 vout_mode = _pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE); 1652 vout_mode = _pmbus_read_byte_data(client, page,
1653 PMBUS_VOUT_MODE);
1652 if (vout_mode >= 0 && vout_mode != 0xff) { 1654 if (vout_mode >= 0 && vout_mode != 0xff) {
1653 /* 1655 /*
1654 * Not all chips support the VOUT_MODE command, 1656 * Not all chips support the VOUT_MODE command,
@@ -1659,7 +1661,7 @@ static int pmbus_identify_common(struct i2c_client *client,
1659 if (data->info->format[PSC_VOLTAGE_OUT] != linear) 1661 if (data->info->format[PSC_VOLTAGE_OUT] != linear)
1660 return -ENODEV; 1662 return -ENODEV;
1661 1663
1662 data->exponent = ((s8)(vout_mode << 3)) >> 3; 1664 data->exponent[page] = ((s8)(vout_mode << 3)) >> 3;
1663 break; 1665 break;
1664 case 1: /* VID mode */ 1666 case 1: /* VID mode */
1665 if (data->info->format[PSC_VOLTAGE_OUT] != vid) 1667 if (data->info->format[PSC_VOLTAGE_OUT] != vid)
@@ -1674,7 +1676,7 @@ static int pmbus_identify_common(struct i2c_client *client,
1674 } 1676 }
1675 } 1677 }
1676 1678
1677 pmbus_clear_fault_page(client, 0); 1679 pmbus_clear_fault_page(client, page);
1678 return 0; 1680 return 0;
1679} 1681}
1680 1682
@@ -1682,7 +1684,7 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
1682 struct pmbus_driver_info *info) 1684 struct pmbus_driver_info *info)
1683{ 1685{
1684 struct device *dev = &client->dev; 1686 struct device *dev = &client->dev;
1685 int ret; 1687 int page, ret;
1686 1688
1687 /* 1689 /*
1688 * Some PMBus chips don't support PMBUS_STATUS_BYTE, so try 1690 * Some PMBus chips don't support PMBUS_STATUS_BYTE, so try
@@ -1715,10 +1717,12 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
1715 return -ENODEV; 1717 return -ENODEV;
1716 } 1718 }
1717 1719
1718 ret = pmbus_identify_common(client, data); 1720 for (page = 0; page < info->pages; page++) {
1719 if (ret < 0) { 1721 ret = pmbus_identify_common(client, data, page);
1720 dev_err(dev, "Failed to identify chip capabilities\n"); 1722 if (ret < 0) {
1721 return ret; 1723 dev_err(dev, "Failed to identify chip capabilities\n");
1724 return ret;
1725 }
1722 } 1726 }
1723 return 0; 1727 return 0;
1724} 1728}
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index f5ed03164d86..de17c5593d97 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -387,7 +387,7 @@ config I2C_CBUS_GPIO
387 387
388config I2C_CPM 388config I2C_CPM
389 tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)" 389 tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)"
390 depends on (CPM1 || CPM2) && OF_I2C 390 depends on CPM1 || CPM2
391 help 391 help
392 This supports the use of the I2C interface on Freescale 392 This supports the use of the I2C interface on Freescale
393 processors with CPM1 or CPM2. 393 processors with CPM1 or CPM2.
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index be7f0a20d634..f3b89a4698b6 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -39,7 +39,9 @@
39#include <linux/i2c.h> 39#include <linux/i2c.h>
40#include <linux/io.h> 40#include <linux/io.h>
41#include <linux/dma-mapping.h> 41#include <linux/dma-mapping.h>
42#include <linux/of_address.h>
42#include <linux/of_device.h> 43#include <linux/of_device.h>
44#include <linux/of_irq.h>
43#include <linux/of_platform.h> 45#include <linux/of_platform.h>
44#include <sysdev/fsl_soc.h> 46#include <sysdev/fsl_soc.h>
45#include <asm/cpm.h> 47#include <asm/cpm.h>
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index b8c5187b9ee0..d52d84937ad3 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -97,7 +97,6 @@ enum {
97enum { 97enum {
98 MV64XXX_I2C_ACTION_INVALID, 98 MV64XXX_I2C_ACTION_INVALID,
99 MV64XXX_I2C_ACTION_CONTINUE, 99 MV64XXX_I2C_ACTION_CONTINUE,
100 MV64XXX_I2C_ACTION_OFFLOAD_SEND_START,
101 MV64XXX_I2C_ACTION_SEND_START, 100 MV64XXX_I2C_ACTION_SEND_START,
102 MV64XXX_I2C_ACTION_SEND_RESTART, 101 MV64XXX_I2C_ACTION_SEND_RESTART,
103 MV64XXX_I2C_ACTION_OFFLOAD_RESTART, 102 MV64XXX_I2C_ACTION_OFFLOAD_RESTART,
@@ -204,6 +203,9 @@ static int mv64xxx_i2c_offload_msg(struct mv64xxx_i2c_data *drv_data)
204 unsigned long ctrl_reg; 203 unsigned long ctrl_reg;
205 struct i2c_msg *msg = drv_data->msgs; 204 struct i2c_msg *msg = drv_data->msgs;
206 205
206 if (!drv_data->offload_enabled)
207 return -EOPNOTSUPP;
208
207 drv_data->msg = msg; 209 drv_data->msg = msg;
208 drv_data->byte_posn = 0; 210 drv_data->byte_posn = 0;
209 drv_data->bytes_left = msg->len; 211 drv_data->bytes_left = msg->len;
@@ -433,8 +435,7 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
433 435
434 drv_data->msgs++; 436 drv_data->msgs++;
435 drv_data->num_msgs--; 437 drv_data->num_msgs--;
436 if (!(drv_data->offload_enabled && 438 if (mv64xxx_i2c_offload_msg(drv_data) < 0) {
437 mv64xxx_i2c_offload_msg(drv_data))) {
438 drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START; 439 drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START;
439 writel(drv_data->cntl_bits, 440 writel(drv_data->cntl_bits,
440 drv_data->reg_base + drv_data->reg_offsets.control); 441 drv_data->reg_base + drv_data->reg_offsets.control);
@@ -458,15 +459,14 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
458 drv_data->reg_base + drv_data->reg_offsets.control); 459 drv_data->reg_base + drv_data->reg_offsets.control);
459 break; 460 break;
460 461
461 case MV64XXX_I2C_ACTION_OFFLOAD_SEND_START:
462 if (!mv64xxx_i2c_offload_msg(drv_data))
463 break;
464 else
465 drv_data->action = MV64XXX_I2C_ACTION_SEND_START;
466 /* FALLTHRU */
467 case MV64XXX_I2C_ACTION_SEND_START: 462 case MV64XXX_I2C_ACTION_SEND_START:
468 writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START, 463 /* Can we offload this msg ? */
469 drv_data->reg_base + drv_data->reg_offsets.control); 464 if (mv64xxx_i2c_offload_msg(drv_data) < 0) {
465 /* No, switch to standard path */
466 mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs);
467 writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START,
468 drv_data->reg_base + drv_data->reg_offsets.control);
469 }
470 break; 470 break;
471 471
472 case MV64XXX_I2C_ACTION_SEND_ADDR_1: 472 case MV64XXX_I2C_ACTION_SEND_ADDR_1:
@@ -625,15 +625,10 @@ mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg,
625 unsigned long flags; 625 unsigned long flags;
626 626
627 spin_lock_irqsave(&drv_data->lock, flags); 627 spin_lock_irqsave(&drv_data->lock, flags);
628 if (drv_data->offload_enabled) {
629 drv_data->action = MV64XXX_I2C_ACTION_OFFLOAD_SEND_START;
630 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND;
631 } else {
632 mv64xxx_i2c_prepare_for_io(drv_data, msg);
633 628
634 drv_data->action = MV64XXX_I2C_ACTION_SEND_START; 629 drv_data->action = MV64XXX_I2C_ACTION_SEND_START;
635 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND; 630 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND;
636 } 631
637 drv_data->send_stop = is_last; 632 drv_data->send_stop = is_last;
638 drv_data->block = 1; 633 drv_data->block = 1;
639 mv64xxx_i2c_do_action(drv_data); 634 mv64xxx_i2c_do_action(drv_data);
diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
index 3bec9220df04..bfec313492b3 100644
--- a/drivers/iio/accel/bma180.c
+++ b/drivers/iio/accel/bma180.c
@@ -447,14 +447,14 @@ static const struct iio_chan_spec_ext_info bma180_ext_info[] = {
447 { }, 447 { },
448}; 448};
449 449
450#define BMA180_CHANNEL(_index) { \ 450#define BMA180_CHANNEL(_axis) { \
451 .type = IIO_ACCEL, \ 451 .type = IIO_ACCEL, \
452 .indexed = 1, \ 452 .modified = 1, \
453 .channel = (_index), \ 453 .channel2 = IIO_MOD_##_axis, \
454 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 454 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
455 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ 455 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
456 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 456 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
457 .scan_index = (_index), \ 457 .scan_index = AXIS_##_axis, \
458 .scan_type = { \ 458 .scan_type = { \
459 .sign = 's', \ 459 .sign = 's', \
460 .realbits = 14, \ 460 .realbits = 14, \
@@ -465,10 +465,10 @@ static const struct iio_chan_spec_ext_info bma180_ext_info[] = {
465} 465}
466 466
467static const struct iio_chan_spec bma180_channels[] = { 467static const struct iio_chan_spec bma180_channels[] = {
468 BMA180_CHANNEL(AXIS_X), 468 BMA180_CHANNEL(X),
469 BMA180_CHANNEL(AXIS_Y), 469 BMA180_CHANNEL(Y),
470 BMA180_CHANNEL(AXIS_Z), 470 BMA180_CHANNEL(Z),
471 IIO_CHAN_SOFT_TIMESTAMP(4), 471 IIO_CHAN_SOFT_TIMESTAMP(3),
472}; 472};
473 473
474static irqreturn_t bma180_trigger_handler(int irq, void *p) 474static irqreturn_t bma180_trigger_handler(int irq, void *p)
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index e283f2f2ee2f..360259266d4f 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -1560,7 +1560,7 @@ static int max1363_probe(struct i2c_client *client,
1560 st->client = client; 1560 st->client = client;
1561 1561
1562 st->vref_uv = st->chip_info->int_vref_mv * 1000; 1562 st->vref_uv = st->chip_info->int_vref_mv * 1000;
1563 vref = devm_regulator_get(&client->dev, "vref"); 1563 vref = devm_regulator_get_optional(&client->dev, "vref");
1564 if (!IS_ERR(vref)) { 1564 if (!IS_ERR(vref)) {
1565 int vref_uv; 1565 int vref_uv;
1566 1566
diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index 41c64a43bcab..ac2d69e34c8c 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -70,7 +70,7 @@ config IIO_ST_GYRO_3AXIS
70 select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) 70 select IIO_TRIGGERED_BUFFER if (IIO_BUFFER)
71 help 71 help
72 Say yes here to build support for STMicroelectronics gyroscopes: 72 Say yes here to build support for STMicroelectronics gyroscopes:
73 L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330. 73 L3G4200D, LSM330DL, L3GD20, LSM330DLC, L3G4IS, LSM330.
74 74
75 This driver can also be built as a module. If so, these modules 75 This driver can also be built as a module. If so, these modules
76 will be created: 76 will be created:
diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h
index f8f2bf84a5a2..c197360c450b 100644
--- a/drivers/iio/gyro/st_gyro.h
+++ b/drivers/iio/gyro/st_gyro.h
@@ -19,7 +19,6 @@
19#define LSM330DL_GYRO_DEV_NAME "lsm330dl_gyro" 19#define LSM330DL_GYRO_DEV_NAME "lsm330dl_gyro"
20#define LSM330DLC_GYRO_DEV_NAME "lsm330dlc_gyro" 20#define LSM330DLC_GYRO_DEV_NAME "lsm330dlc_gyro"
21#define L3GD20_GYRO_DEV_NAME "l3gd20" 21#define L3GD20_GYRO_DEV_NAME "l3gd20"
22#define L3GD20H_GYRO_DEV_NAME "l3gd20h"
23#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui" 22#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui"
24#define LSM330_GYRO_DEV_NAME "lsm330_gyro" 23#define LSM330_GYRO_DEV_NAME "lsm330_gyro"
25 24
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index d53d91adfb55..a8e174a47bc4 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -167,11 +167,10 @@ static const struct st_sensors st_gyro_sensors[] = {
167 .wai = ST_GYRO_2_WAI_EXP, 167 .wai = ST_GYRO_2_WAI_EXP,
168 .sensors_supported = { 168 .sensors_supported = {
169 [0] = L3GD20_GYRO_DEV_NAME, 169 [0] = L3GD20_GYRO_DEV_NAME,
170 [1] = L3GD20H_GYRO_DEV_NAME, 170 [1] = LSM330D_GYRO_DEV_NAME,
171 [2] = LSM330D_GYRO_DEV_NAME, 171 [2] = LSM330DLC_GYRO_DEV_NAME,
172 [3] = LSM330DLC_GYRO_DEV_NAME, 172 [3] = L3G4IS_GYRO_DEV_NAME,
173 [4] = L3G4IS_GYRO_DEV_NAME, 173 [4] = LSM330_GYRO_DEV_NAME,
174 [5] = LSM330_GYRO_DEV_NAME,
175 }, 174 },
176 .ch = (struct iio_chan_spec *)st_gyro_16bit_channels, 175 .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
177 .odr = { 176 .odr = {
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index 16b8b8d70bf1..23c12f361b05 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -55,7 +55,6 @@ static const struct i2c_device_id st_gyro_id_table[] = {
55 { LSM330DL_GYRO_DEV_NAME }, 55 { LSM330DL_GYRO_DEV_NAME },
56 { LSM330DLC_GYRO_DEV_NAME }, 56 { LSM330DLC_GYRO_DEV_NAME },
57 { L3GD20_GYRO_DEV_NAME }, 57 { L3GD20_GYRO_DEV_NAME },
58 { L3GD20H_GYRO_DEV_NAME },
59 { L3G4IS_GYRO_DEV_NAME }, 58 { L3G4IS_GYRO_DEV_NAME },
60 { LSM330_GYRO_DEV_NAME }, 59 { LSM330_GYRO_DEV_NAME },
61 {}, 60 {},
diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c
index 94763e25caf9..b4ad3be26687 100644
--- a/drivers/iio/gyro/st_gyro_spi.c
+++ b/drivers/iio/gyro/st_gyro_spi.c
@@ -54,7 +54,6 @@ static const struct spi_device_id st_gyro_id_table[] = {
54 { LSM330DL_GYRO_DEV_NAME }, 54 { LSM330DL_GYRO_DEV_NAME },
55 { LSM330DLC_GYRO_DEV_NAME }, 55 { LSM330DLC_GYRO_DEV_NAME },
56 { L3GD20_GYRO_DEV_NAME }, 56 { L3GD20_GYRO_DEV_NAME },
57 { L3GD20H_GYRO_DEV_NAME },
58 { L3G4IS_GYRO_DEV_NAME }, 57 { L3G4IS_GYRO_DEV_NAME },
59 { LSM330_GYRO_DEV_NAME }, 58 { LSM330_GYRO_DEV_NAME },
60 {}, 59 {},
diff --git a/drivers/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h
index 2f8f9d632386..0916bf6b6c31 100644
--- a/drivers/iio/imu/adis16400.h
+++ b/drivers/iio/imu/adis16400.h
@@ -189,6 +189,7 @@ enum {
189 ADIS16300_SCAN_INCLI_X, 189 ADIS16300_SCAN_INCLI_X,
190 ADIS16300_SCAN_INCLI_Y, 190 ADIS16300_SCAN_INCLI_Y,
191 ADIS16400_SCAN_ADC, 191 ADIS16400_SCAN_ADC,
192 ADIS16400_SCAN_TIMESTAMP,
192}; 193};
193 194
194#ifdef CONFIG_IIO_BUFFER 195#ifdef CONFIG_IIO_BUFFER
diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index 368660dfe135..7c582f7ae34e 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -632,7 +632,7 @@ static const struct iio_chan_spec adis16400_channels[] = {
632 ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), 632 ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14),
633 ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT, 12), 633 ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT, 12),
634 ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC, 12), 634 ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC, 12),
635 IIO_CHAN_SOFT_TIMESTAMP(12) 635 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP),
636}; 636};
637 637
638static const struct iio_chan_spec adis16448_channels[] = { 638static const struct iio_chan_spec adis16448_channels[] = {
@@ -659,7 +659,7 @@ static const struct iio_chan_spec adis16448_channels[] = {
659 }, 659 },
660 }, 660 },
661 ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT, 12), 661 ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT, 12),
662 IIO_CHAN_SOFT_TIMESTAMP(11) 662 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP),
663}; 663};
664 664
665static const struct iio_chan_spec adis16350_channels[] = { 665static const struct iio_chan_spec adis16350_channels[] = {
@@ -677,7 +677,7 @@ static const struct iio_chan_spec adis16350_channels[] = {
677 ADIS16400_MOD_TEMP_CHAN(X, ADIS16350_XTEMP_OUT, 12), 677 ADIS16400_MOD_TEMP_CHAN(X, ADIS16350_XTEMP_OUT, 12),
678 ADIS16400_MOD_TEMP_CHAN(Y, ADIS16350_YTEMP_OUT, 12), 678 ADIS16400_MOD_TEMP_CHAN(Y, ADIS16350_YTEMP_OUT, 12),
679 ADIS16400_MOD_TEMP_CHAN(Z, ADIS16350_ZTEMP_OUT, 12), 679 ADIS16400_MOD_TEMP_CHAN(Z, ADIS16350_ZTEMP_OUT, 12),
680 IIO_CHAN_SOFT_TIMESTAMP(11) 680 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP),
681}; 681};
682 682
683static const struct iio_chan_spec adis16300_channels[] = { 683static const struct iio_chan_spec adis16300_channels[] = {
@@ -690,7 +690,7 @@ static const struct iio_chan_spec adis16300_channels[] = {
690 ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), 690 ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12),
691 ADIS16400_INCLI_CHAN(X, ADIS16300_PITCH_OUT, 13), 691 ADIS16400_INCLI_CHAN(X, ADIS16300_PITCH_OUT, 13),
692 ADIS16400_INCLI_CHAN(Y, ADIS16300_ROLL_OUT, 13), 692 ADIS16400_INCLI_CHAN(Y, ADIS16300_ROLL_OUT, 13),
693 IIO_CHAN_SOFT_TIMESTAMP(14) 693 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP),
694}; 694};
695 695
696static const struct iio_chan_spec adis16334_channels[] = { 696static const struct iio_chan_spec adis16334_channels[] = {
@@ -701,7 +701,7 @@ static const struct iio_chan_spec adis16334_channels[] = {
701 ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), 701 ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14),
702 ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), 702 ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14),
703 ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), 703 ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12),
704 IIO_CHAN_SOFT_TIMESTAMP(8) 704 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP),
705}; 705};
706 706
707static struct attribute *adis16400_attributes[] = { 707static struct attribute *adis16400_attributes[] = {
diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c
index f17b4e6183c6..47a6dbac2d0c 100644
--- a/drivers/iio/light/cm32181.c
+++ b/drivers/iio/light/cm32181.c
@@ -103,13 +103,13 @@ static int cm32181_reg_init(struct cm32181_chip *cm32181)
103/** 103/**
104 * cm32181_read_als_it() - Get sensor integration time (ms) 104 * cm32181_read_als_it() - Get sensor integration time (ms)
105 * @cm32181: pointer of struct cm32181 105 * @cm32181: pointer of struct cm32181
106 * @val: pointer of int to load the als_it value. 106 * @val2: pointer of int to load the als_it value.
107 * 107 *
108 * Report the current integartion time by millisecond. 108 * Report the current integartion time by millisecond.
109 * 109 *
110 * Return: IIO_VAL_INT for success, otherwise -EINVAL. 110 * Return: IIO_VAL_INT_PLUS_MICRO for success, otherwise -EINVAL.
111 */ 111 */
112static int cm32181_read_als_it(struct cm32181_chip *cm32181, int *val) 112static int cm32181_read_als_it(struct cm32181_chip *cm32181, int *val2)
113{ 113{
114 u16 als_it; 114 u16 als_it;
115 int i; 115 int i;
@@ -119,8 +119,8 @@ static int cm32181_read_als_it(struct cm32181_chip *cm32181, int *val)
119 als_it >>= CM32181_CMD_ALS_IT_SHIFT; 119 als_it >>= CM32181_CMD_ALS_IT_SHIFT;
120 for (i = 0; i < ARRAY_SIZE(als_it_bits); i++) { 120 for (i = 0; i < ARRAY_SIZE(als_it_bits); i++) {
121 if (als_it == als_it_bits[i]) { 121 if (als_it == als_it_bits[i]) {
122 *val = als_it_value[i]; 122 *val2 = als_it_value[i];
123 return IIO_VAL_INT; 123 return IIO_VAL_INT_PLUS_MICRO;
124 } 124 }
125 } 125 }
126 126
@@ -221,7 +221,7 @@ static int cm32181_read_raw(struct iio_dev *indio_dev,
221 *val = cm32181->calibscale; 221 *val = cm32181->calibscale;
222 return IIO_VAL_INT; 222 return IIO_VAL_INT;
223 case IIO_CHAN_INFO_INT_TIME: 223 case IIO_CHAN_INFO_INT_TIME:
224 ret = cm32181_read_als_it(cm32181, val); 224 ret = cm32181_read_als_it(cm32181, val2);
225 return ret; 225 return ret;
226 } 226 }
227 227
@@ -240,7 +240,7 @@ static int cm32181_write_raw(struct iio_dev *indio_dev,
240 cm32181->calibscale = val; 240 cm32181->calibscale = val;
241 return val; 241 return val;
242 case IIO_CHAN_INFO_INT_TIME: 242 case IIO_CHAN_INFO_INT_TIME:
243 ret = cm32181_write_als_it(cm32181, val); 243 ret = cm32181_write_als_it(cm32181, val2);
244 return ret; 244 return ret;
245 } 245 }
246 246
@@ -264,7 +264,7 @@ static ssize_t cm32181_get_it_available(struct device *dev,
264 264
265 n = ARRAY_SIZE(als_it_value); 265 n = ARRAY_SIZE(als_it_value);
266 for (i = 0, len = 0; i < n; i++) 266 for (i = 0, len = 0; i < n; i++)
267 len += sprintf(buf + len, "%d ", als_it_value[i]); 267 len += sprintf(buf + len, "0.%06u ", als_it_value[i]);
268 return len + sprintf(buf + len, "\n"); 268 return len + sprintf(buf + len, "\n");
269} 269}
270 270
diff --git a/drivers/iio/light/cm36651.c b/drivers/iio/light/cm36651.c
index 0a142af83e25..a45e07492db3 100644
--- a/drivers/iio/light/cm36651.c
+++ b/drivers/iio/light/cm36651.c
@@ -50,10 +50,10 @@
50#define CM36651_CS_CONF2_DEFAULT_BIT 0x08 50#define CM36651_CS_CONF2_DEFAULT_BIT 0x08
51 51
52/* CS_CONF3 channel integration time */ 52/* CS_CONF3 channel integration time */
53#define CM36651_CS_IT1 0x00 /* Integration time 80000 usec */ 53#define CM36651_CS_IT1 0x00 /* Integration time 80 msec */
54#define CM36651_CS_IT2 0x40 /* Integration time 160000 usec */ 54#define CM36651_CS_IT2 0x40 /* Integration time 160 msec */
55#define CM36651_CS_IT3 0x80 /* Integration time 320000 usec */ 55#define CM36651_CS_IT3 0x80 /* Integration time 320 msec */
56#define CM36651_CS_IT4 0xC0 /* Integration time 640000 usec */ 56#define CM36651_CS_IT4 0xC0 /* Integration time 640 msec */
57 57
58/* PS_CONF1 command code */ 58/* PS_CONF1 command code */
59#define CM36651_PS_ENABLE 0x00 59#define CM36651_PS_ENABLE 0x00
@@ -64,10 +64,10 @@
64#define CM36651_PS_PERS4 0x0C 64#define CM36651_PS_PERS4 0x0C
65 65
66/* PS_CONF1 command code: integration time */ 66/* PS_CONF1 command code: integration time */
67#define CM36651_PS_IT1 0x00 /* Integration time 320 usec */ 67#define CM36651_PS_IT1 0x00 /* Integration time 0.32 msec */
68#define CM36651_PS_IT2 0x10 /* Integration time 420 usec */ 68#define CM36651_PS_IT2 0x10 /* Integration time 0.42 msec */
69#define CM36651_PS_IT3 0x20 /* Integration time 520 usec */ 69#define CM36651_PS_IT3 0x20 /* Integration time 0.52 msec */
70#define CM36651_PS_IT4 0x30 /* Integration time 640 usec */ 70#define CM36651_PS_IT4 0x30 /* Integration time 0.64 msec */
71 71
72/* PS_CONF1 command code: duty ratio */ 72/* PS_CONF1 command code: duty ratio */
73#define CM36651_PS_DR1 0x00 /* Duty ratio 1/80 */ 73#define CM36651_PS_DR1 0x00 /* Duty ratio 1/80 */
@@ -93,8 +93,8 @@
93#define CM36651_CLOSE_PROXIMITY 0x32 93#define CM36651_CLOSE_PROXIMITY 0x32
94#define CM36651_FAR_PROXIMITY 0x33 94#define CM36651_FAR_PROXIMITY 0x33
95 95
96#define CM36651_CS_INT_TIME_AVAIL "80000 160000 320000 640000" 96#define CM36651_CS_INT_TIME_AVAIL "0.08 0.16 0.32 0.64"
97#define CM36651_PS_INT_TIME_AVAIL "320 420 520 640" 97#define CM36651_PS_INT_TIME_AVAIL "0.000320 0.000420 0.000520 0.000640"
98 98
99enum cm36651_operation_mode { 99enum cm36651_operation_mode {
100 CM36651_LIGHT_EN, 100 CM36651_LIGHT_EN,
@@ -356,30 +356,30 @@ static int cm36651_read_channel(struct cm36651_data *cm36651,
356} 356}
357 357
358static int cm36651_read_int_time(struct cm36651_data *cm36651, 358static int cm36651_read_int_time(struct cm36651_data *cm36651,
359 struct iio_chan_spec const *chan, int *val) 359 struct iio_chan_spec const *chan, int *val2)
360{ 360{
361 switch (chan->type) { 361 switch (chan->type) {
362 case IIO_LIGHT: 362 case IIO_LIGHT:
363 if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT1) 363 if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT1)
364 *val = 80000; 364 *val2 = 80000;
365 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT2) 365 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT2)
366 *val = 160000; 366 *val2 = 160000;
367 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT3) 367 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT3)
368 *val = 320000; 368 *val2 = 320000;
369 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT4) 369 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT4)
370 *val = 640000; 370 *val2 = 640000;
371 else 371 else
372 return -EINVAL; 372 return -EINVAL;
373 break; 373 break;
374 case IIO_PROXIMITY: 374 case IIO_PROXIMITY:
375 if (cm36651->ps_int_time == CM36651_PS_IT1) 375 if (cm36651->ps_int_time == CM36651_PS_IT1)
376 *val = 320; 376 *val2 = 320;
377 else if (cm36651->ps_int_time == CM36651_PS_IT2) 377 else if (cm36651->ps_int_time == CM36651_PS_IT2)
378 *val = 420; 378 *val2 = 420;
379 else if (cm36651->ps_int_time == CM36651_PS_IT3) 379 else if (cm36651->ps_int_time == CM36651_PS_IT3)
380 *val = 520; 380 *val2 = 520;
381 else if (cm36651->ps_int_time == CM36651_PS_IT4) 381 else if (cm36651->ps_int_time == CM36651_PS_IT4)
382 *val = 640; 382 *val2 = 640;
383 else 383 else
384 return -EINVAL; 384 return -EINVAL;
385 break; 385 break;
@@ -387,7 +387,7 @@ static int cm36651_read_int_time(struct cm36651_data *cm36651,
387 return -EINVAL; 387 return -EINVAL;
388 } 388 }
389 389
390 return IIO_VAL_INT; 390 return IIO_VAL_INT_PLUS_MICRO;
391} 391}
392 392
393static int cm36651_write_int_time(struct cm36651_data *cm36651, 393static int cm36651_write_int_time(struct cm36651_data *cm36651,
@@ -459,7 +459,8 @@ static int cm36651_read_raw(struct iio_dev *indio_dev,
459 ret = cm36651_read_channel(cm36651, chan, val); 459 ret = cm36651_read_channel(cm36651, chan, val);
460 break; 460 break;
461 case IIO_CHAN_INFO_INT_TIME: 461 case IIO_CHAN_INFO_INT_TIME:
462 ret = cm36651_read_int_time(cm36651, chan, val); 462 *val = 0;
463 ret = cm36651_read_int_time(cm36651, chan, val2);
463 break; 464 break;
464 default: 465 default:
465 ret = -EINVAL; 466 ret = -EINVAL;
@@ -479,7 +480,7 @@ static int cm36651_write_raw(struct iio_dev *indio_dev,
479 int ret = -EINVAL; 480 int ret = -EINVAL;
480 481
481 if (mask == IIO_CHAN_INFO_INT_TIME) { 482 if (mask == IIO_CHAN_INFO_INT_TIME) {
482 ret = cm36651_write_int_time(cm36651, chan, val); 483 ret = cm36651_write_int_time(cm36651, chan, val2);
483 if (ret < 0) 484 if (ret < 0)
484 dev_err(&client->dev, "Integration time write failed\n"); 485 dev_err(&client->dev, "Integration time write failed\n");
485 } 486 }
diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
index 3d8110157f2d..94daa9fc1247 100644
--- a/drivers/iio/light/tsl2563.c
+++ b/drivers/iio/light/tsl2563.c
@@ -460,10 +460,14 @@ static int tsl2563_write_raw(struct iio_dev *indio_dev,
460{ 460{
461 struct tsl2563_chip *chip = iio_priv(indio_dev); 461 struct tsl2563_chip *chip = iio_priv(indio_dev);
462 462
463 if (chan->channel == IIO_MOD_LIGHT_BOTH) 463 if (mask != IIO_CHAN_INFO_CALIBSCALE)
464 return -EINVAL;
465 if (chan->channel2 == IIO_MOD_LIGHT_BOTH)
464 chip->calib0 = calib_from_sysfs(val); 466 chip->calib0 = calib_from_sysfs(val);
465 else 467 else if (chan->channel2 == IIO_MOD_LIGHT_IR)
466 chip->calib1 = calib_from_sysfs(val); 468 chip->calib1 = calib_from_sysfs(val);
469 else
470 return -EINVAL;
467 471
468 return 0; 472 return 0;
469} 473}
@@ -472,14 +476,14 @@ static int tsl2563_read_raw(struct iio_dev *indio_dev,
472 struct iio_chan_spec const *chan, 476 struct iio_chan_spec const *chan,
473 int *val, 477 int *val,
474 int *val2, 478 int *val2,
475 long m) 479 long mask)
476{ 480{
477 int ret = -EINVAL; 481 int ret = -EINVAL;
478 u32 calib0, calib1; 482 u32 calib0, calib1;
479 struct tsl2563_chip *chip = iio_priv(indio_dev); 483 struct tsl2563_chip *chip = iio_priv(indio_dev);
480 484
481 mutex_lock(&chip->lock); 485 mutex_lock(&chip->lock);
482 switch (m) { 486 switch (mask) {
483 case IIO_CHAN_INFO_RAW: 487 case IIO_CHAN_INFO_RAW:
484 case IIO_CHAN_INFO_PROCESSED: 488 case IIO_CHAN_INFO_PROCESSED:
485 switch (chan->type) { 489 switch (chan->type) {
@@ -498,7 +502,7 @@ static int tsl2563_read_raw(struct iio_dev *indio_dev,
498 ret = tsl2563_get_adc(chip); 502 ret = tsl2563_get_adc(chip);
499 if (ret) 503 if (ret)
500 goto error_ret; 504 goto error_ret;
501 if (chan->channel == 0) 505 if (chan->channel2 == IIO_MOD_LIGHT_BOTH)
502 *val = chip->data0; 506 *val = chip->data0;
503 else 507 else
504 *val = chip->data1; 508 *val = chip->data1;
@@ -510,7 +514,7 @@ static int tsl2563_read_raw(struct iio_dev *indio_dev,
510 break; 514 break;
511 515
512 case IIO_CHAN_INFO_CALIBSCALE: 516 case IIO_CHAN_INFO_CALIBSCALE:
513 if (chan->channel == 0) 517 if (chan->channel2 == IIO_MOD_LIGHT_BOTH)
514 *val = calib_to_sysfs(chip->calib0); 518 *val = calib_to_sysfs(chip->calib0);
515 else 519 else
516 *val = calib_to_sysfs(chip->calib1); 520 *val = calib_to_sysfs(chip->calib1);
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index ff284e5afd95..05423543f89d 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -85,6 +85,7 @@
85#define AK8975_MAX_CONVERSION_TIMEOUT 500 85#define AK8975_MAX_CONVERSION_TIMEOUT 500
86#define AK8975_CONVERSION_DONE_POLL_TIME 10 86#define AK8975_CONVERSION_DONE_POLL_TIME 10
87#define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000) 87#define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000)
88#define RAW_TO_GAUSS(asa) ((((asa) + 128) * 3000) / 256)
88 89
89/* 90/*
90 * Per-instance context data for the device. 91 * Per-instance context data for the device.
@@ -265,15 +266,15 @@ static int ak8975_setup(struct i2c_client *client)
265 * 266 *
266 * Since 1uT = 0.01 gauss, our final scale factor becomes: 267 * Since 1uT = 0.01 gauss, our final scale factor becomes:
267 * 268 *
268 * Hadj = H * ((ASA + 128) / 256) * 3/10 * 100 269 * Hadj = H * ((ASA + 128) / 256) * 3/10 * 1/100
269 * Hadj = H * ((ASA + 128) * 30 / 256 270 * Hadj = H * ((ASA + 128) * 0.003) / 256
270 * 271 *
271 * Since ASA doesn't change, we cache the resultant scale factor into the 272 * Since ASA doesn't change, we cache the resultant scale factor into the
272 * device context in ak8975_setup(). 273 * device context in ak8975_setup().
273 */ 274 */
274 data->raw_to_gauss[0] = ((data->asa[0] + 128) * 30) >> 8; 275 data->raw_to_gauss[0] = RAW_TO_GAUSS(data->asa[0]);
275 data->raw_to_gauss[1] = ((data->asa[1] + 128) * 30) >> 8; 276 data->raw_to_gauss[1] = RAW_TO_GAUSS(data->asa[1]);
276 data->raw_to_gauss[2] = ((data->asa[2] + 128) * 30) >> 8; 277 data->raw_to_gauss[2] = RAW_TO_GAUSS(data->asa[2]);
277 278
278 return 0; 279 return 0;
279} 280}
@@ -428,8 +429,9 @@ static int ak8975_read_raw(struct iio_dev *indio_dev,
428 case IIO_CHAN_INFO_RAW: 429 case IIO_CHAN_INFO_RAW:
429 return ak8975_read_axis(indio_dev, chan->address, val); 430 return ak8975_read_axis(indio_dev, chan->address, val);
430 case IIO_CHAN_INFO_SCALE: 431 case IIO_CHAN_INFO_SCALE:
431 *val = data->raw_to_gauss[chan->address]; 432 *val = 0;
432 return IIO_VAL_INT; 433 *val2 = data->raw_to_gauss[chan->address];
434 return IIO_VAL_INT_PLUS_MICRO;
433 } 435 }
434 return -EINVAL; 436 return -EINVAL;
435} 437}
diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c
index 4b65b6d3bdb1..f66955fb3509 100644
--- a/drivers/iio/magnetometer/mag3110.c
+++ b/drivers/iio/magnetometer/mag3110.c
@@ -106,7 +106,7 @@ static ssize_t mag3110_show_int_plus_micros(char *buf,
106 106
107 while (n-- > 0) 107 while (n-- > 0)
108 len += scnprintf(buf + len, PAGE_SIZE - len, 108 len += scnprintf(buf + len, PAGE_SIZE - len,
109 "%d.%d ", vals[n][0], vals[n][1]); 109 "%d.%06d ", vals[n][0], vals[n][1]);
110 110
111 /* replace trailing space by newline */ 111 /* replace trailing space by newline */
112 buf[len - 1] = '\n'; 112 buf[len - 1] = '\n';
@@ -154,6 +154,9 @@ static int mag3110_read_raw(struct iio_dev *indio_dev,
154 154
155 switch (mask) { 155 switch (mask) {
156 case IIO_CHAN_INFO_RAW: 156 case IIO_CHAN_INFO_RAW:
157 if (iio_buffer_enabled(indio_dev))
158 return -EBUSY;
159
157 switch (chan->type) { 160 switch (chan->type) {
158 case IIO_MAGN: /* in 0.1 uT / LSB */ 161 case IIO_MAGN: /* in 0.1 uT / LSB */
159 ret = mag3110_read(data, buffer); 162 ret = mag3110_read(data, buffer);
@@ -199,6 +202,9 @@ static int mag3110_write_raw(struct iio_dev *indio_dev,
199 struct mag3110_data *data = iio_priv(indio_dev); 202 struct mag3110_data *data = iio_priv(indio_dev);
200 int rate; 203 int rate;
201 204
205 if (iio_buffer_enabled(indio_dev))
206 return -EBUSY;
207
202 switch (mask) { 208 switch (mask) {
203 case IIO_CHAN_INFO_SAMP_FREQ: 209 case IIO_CHAN_INFO_SAMP_FREQ:
204 rate = mag3110_get_samp_freq_index(data, val, val2); 210 rate = mag3110_get_samp_freq_index(data, val, val2);
diff --git a/drivers/infiniband/hw/amso1100/c2.c b/drivers/infiniband/hw/amso1100/c2.c
index d53cf519f42a..00400c352c1a 100644
--- a/drivers/infiniband/hw/amso1100/c2.c
+++ b/drivers/infiniband/hw/amso1100/c2.c
@@ -1082,6 +1082,7 @@ static int c2_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
1082 1082
1083 /* Initialize network device */ 1083 /* Initialize network device */
1084 if ((netdev = c2_devinit(c2dev, mmio_regs)) == NULL) { 1084 if ((netdev = c2_devinit(c2dev, mmio_regs)) == NULL) {
1085 ret = -ENOMEM;
1085 iounmap(mmio_regs); 1086 iounmap(mmio_regs);
1086 goto bail4; 1087 goto bail4;
1087 } 1088 }
@@ -1151,7 +1152,8 @@ static int c2_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
1151 goto bail10; 1152 goto bail10;
1152 } 1153 }
1153 1154
1154 if (c2_register_device(c2dev)) 1155 ret = c2_register_device(c2dev);
1156 if (ret)
1155 goto bail10; 1157 goto bail10;
1156 1158
1157 return 0; 1159 return 0;
diff --git a/drivers/infiniband/hw/amso1100/c2_rnic.c b/drivers/infiniband/hw/amso1100/c2_rnic.c
index b7c986990053..d2a6d961344b 100644
--- a/drivers/infiniband/hw/amso1100/c2_rnic.c
+++ b/drivers/infiniband/hw/amso1100/c2_rnic.c
@@ -576,7 +576,8 @@ int c2_rnic_init(struct c2_dev *c2dev)
576 goto bail4; 576 goto bail4;
577 577
578 /* Initialize cached the adapter limits */ 578 /* Initialize cached the adapter limits */
579 if (c2_rnic_query(c2dev, &c2dev->props)) 579 err = c2_rnic_query(c2dev, &c2dev->props);
580 if (err)
580 goto bail5; 581 goto bail5;
581 582
582 /* Initialize the PD pool */ 583 /* Initialize the PD pool */
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index 45126879ad28..d286bdebe2ab 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -3352,6 +3352,7 @@ static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3352 goto free_dst; 3352 goto free_dst;
3353 } 3353 }
3354 3354
3355 neigh_release(neigh);
3355 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan; 3356 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3356 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step]; 3357 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3357 window = (__force u16) htons((__force u16)tcph->window); 3358 window = (__force u16) htons((__force u16)tcph->window);
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index c2702f549f10..f9c12e92fdd6 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -53,8 +53,8 @@
53#include "user.h" 53#include "user.h"
54 54
55#define DRV_NAME MLX4_IB_DRV_NAME 55#define DRV_NAME MLX4_IB_DRV_NAME
56#define DRV_VERSION "1.0" 56#define DRV_VERSION "2.2-1"
57#define DRV_RELDATE "April 4, 2008" 57#define DRV_RELDATE "Feb 2014"
58 58
59#define MLX4_IB_FLOW_MAX_PRIO 0xFFF 59#define MLX4_IB_FLOW_MAX_PRIO 0xFFF
60#define MLX4_IB_FLOW_QPN_MASK 0xFFFFFF 60#define MLX4_IB_FLOW_QPN_MASK 0xFFFFFF
@@ -347,7 +347,7 @@ static int eth_link_query_port(struct ib_device *ibdev, u8 port,
347 props->active_width = (((u8 *)mailbox->buf)[5] == 0x40) ? 347 props->active_width = (((u8 *)mailbox->buf)[5] == 0x40) ?
348 IB_WIDTH_4X : IB_WIDTH_1X; 348 IB_WIDTH_4X : IB_WIDTH_1X;
349 props->active_speed = IB_SPEED_QDR; 349 props->active_speed = IB_SPEED_QDR;
350 props->port_cap_flags = IB_PORT_CM_SUP; 350 props->port_cap_flags = IB_PORT_CM_SUP | IB_PORT_IP_BASED_GIDS;
351 props->gid_tbl_len = mdev->dev->caps.gid_table_len[port]; 351 props->gid_tbl_len = mdev->dev->caps.gid_table_len[port];
352 props->max_msg_sz = mdev->dev->caps.max_msg_sz; 352 props->max_msg_sz = mdev->dev->caps.max_msg_sz;
353 props->pkey_tbl_len = 1; 353 props->pkey_tbl_len = 1;
@@ -1357,6 +1357,21 @@ static struct device_attribute *mlx4_class_attributes[] = {
1357 &dev_attr_board_id 1357 &dev_attr_board_id
1358}; 1358};
1359 1359
1360static void mlx4_addrconf_ifid_eui48(u8 *eui, u16 vlan_id,
1361 struct net_device *dev)
1362{
1363 memcpy(eui, dev->dev_addr, 3);
1364 memcpy(eui + 5, dev->dev_addr + 3, 3);
1365 if (vlan_id < 0x1000) {
1366 eui[3] = vlan_id >> 8;
1367 eui[4] = vlan_id & 0xff;
1368 } else {
1369 eui[3] = 0xff;
1370 eui[4] = 0xfe;
1371 }
1372 eui[0] ^= 2;
1373}
1374
1360static void update_gids_task(struct work_struct *work) 1375static void update_gids_task(struct work_struct *work)
1361{ 1376{
1362 struct update_gid_work *gw = container_of(work, struct update_gid_work, work); 1377 struct update_gid_work *gw = container_of(work, struct update_gid_work, work);
@@ -1393,7 +1408,6 @@ static void reset_gids_task(struct work_struct *work)
1393 struct mlx4_cmd_mailbox *mailbox; 1408 struct mlx4_cmd_mailbox *mailbox;
1394 union ib_gid *gids; 1409 union ib_gid *gids;
1395 int err; 1410 int err;
1396 int i;
1397 struct mlx4_dev *dev = gw->dev->dev; 1411 struct mlx4_dev *dev = gw->dev->dev;
1398 1412
1399 mailbox = mlx4_alloc_cmd_mailbox(dev); 1413 mailbox = mlx4_alloc_cmd_mailbox(dev);
@@ -1405,18 +1419,16 @@ static void reset_gids_task(struct work_struct *work)
1405 gids = mailbox->buf; 1419 gids = mailbox->buf;
1406 memcpy(gids, gw->gids, sizeof(gw->gids)); 1420 memcpy(gids, gw->gids, sizeof(gw->gids));
1407 1421
1408 for (i = 1; i < gw->dev->num_ports + 1; i++) { 1422 if (mlx4_ib_port_link_layer(&gw->dev->ib_dev, gw->port) ==
1409 if (mlx4_ib_port_link_layer(&gw->dev->ib_dev, i) == 1423 IB_LINK_LAYER_ETHERNET) {
1410 IB_LINK_LAYER_ETHERNET) { 1424 err = mlx4_cmd(dev, mailbox->dma,
1411 err = mlx4_cmd(dev, mailbox->dma, 1425 MLX4_SET_PORT_GID_TABLE << 8 | gw->port,
1412 MLX4_SET_PORT_GID_TABLE << 8 | i, 1426 1, MLX4_CMD_SET_PORT,
1413 1, MLX4_CMD_SET_PORT, 1427 MLX4_CMD_TIME_CLASS_B,
1414 MLX4_CMD_TIME_CLASS_B, 1428 MLX4_CMD_WRAPPED);
1415 MLX4_CMD_WRAPPED); 1429 if (err)
1416 if (err) 1430 pr_warn(KERN_WARNING
1417 pr_warn(KERN_WARNING 1431 "set port %d command failed\n", gw->port);
1418 "set port %d command failed\n", i);
1419 }
1420 } 1432 }
1421 1433
1422 mlx4_free_cmd_mailbox(dev, mailbox); 1434 mlx4_free_cmd_mailbox(dev, mailbox);
@@ -1425,7 +1437,8 @@ free:
1425} 1437}
1426 1438
1427static int update_gid_table(struct mlx4_ib_dev *dev, int port, 1439static int update_gid_table(struct mlx4_ib_dev *dev, int port,
1428 union ib_gid *gid, int clear) 1440 union ib_gid *gid, int clear,
1441 int default_gid)
1429{ 1442{
1430 struct update_gid_work *work; 1443 struct update_gid_work *work;
1431 int i; 1444 int i;
@@ -1434,26 +1447,31 @@ static int update_gid_table(struct mlx4_ib_dev *dev, int port,
1434 int found = -1; 1447 int found = -1;
1435 int max_gids; 1448 int max_gids;
1436 1449
1437 max_gids = dev->dev->caps.gid_table_len[port]; 1450 if (default_gid) {
1438 for (i = 0; i < max_gids; ++i) { 1451 free = 0;
1439 if (!memcmp(&dev->iboe.gid_table[port - 1][i], gid, 1452 } else {
1440 sizeof(*gid))) 1453 max_gids = dev->dev->caps.gid_table_len[port];
1441 found = i; 1454 for (i = 1; i < max_gids; ++i) {
1442 1455 if (!memcmp(&dev->iboe.gid_table[port - 1][i], gid,
1443 if (clear) {
1444 if (found >= 0) {
1445 need_update = 1;
1446 dev->iboe.gid_table[port - 1][found] = zgid;
1447 break;
1448 }
1449 } else {
1450 if (found >= 0)
1451 break;
1452
1453 if (free < 0 &&
1454 !memcmp(&dev->iboe.gid_table[port - 1][i], &zgid,
1455 sizeof(*gid))) 1456 sizeof(*gid)))
1456 free = i; 1457 found = i;
1458
1459 if (clear) {
1460 if (found >= 0) {
1461 need_update = 1;
1462 dev->iboe.gid_table[port - 1][found] =
1463 zgid;
1464 break;
1465 }
1466 } else {
1467 if (found >= 0)
1468 break;
1469
1470 if (free < 0 &&
1471 !memcmp(&dev->iboe.gid_table[port - 1][i],
1472 &zgid, sizeof(*gid)))
1473 free = i;
1474 }
1457 } 1475 }
1458 } 1476 }
1459 1477
@@ -1478,18 +1496,26 @@ static int update_gid_table(struct mlx4_ib_dev *dev, int port,
1478 return 0; 1496 return 0;
1479} 1497}
1480 1498
1481static int reset_gid_table(struct mlx4_ib_dev *dev) 1499static void mlx4_make_default_gid(struct net_device *dev, union ib_gid *gid)
1482{ 1500{
1483 struct update_gid_work *work; 1501 gid->global.subnet_prefix = cpu_to_be64(0xfe80000000000000LL);
1502 mlx4_addrconf_ifid_eui48(&gid->raw[8], 0xffff, dev);
1503}
1504
1484 1505
1506static int reset_gid_table(struct mlx4_ib_dev *dev, u8 port)
1507{
1508 struct update_gid_work *work;
1485 1509
1486 work = kzalloc(sizeof(*work), GFP_ATOMIC); 1510 work = kzalloc(sizeof(*work), GFP_ATOMIC);
1487 if (!work) 1511 if (!work)
1488 return -ENOMEM; 1512 return -ENOMEM;
1489 memset(dev->iboe.gid_table, 0, sizeof(dev->iboe.gid_table)); 1513
1514 memset(dev->iboe.gid_table[port - 1], 0, sizeof(work->gids));
1490 memset(work->gids, 0, sizeof(work->gids)); 1515 memset(work->gids, 0, sizeof(work->gids));
1491 INIT_WORK(&work->work, reset_gids_task); 1516 INIT_WORK(&work->work, reset_gids_task);
1492 work->dev = dev; 1517 work->dev = dev;
1518 work->port = port;
1493 queue_work(wq, &work->work); 1519 queue_work(wq, &work->work);
1494 return 0; 1520 return 0;
1495} 1521}
@@ -1502,6 +1528,12 @@ static int mlx4_ib_addr_event(int event, struct net_device *event_netdev,
1502 struct net_device *real_dev = rdma_vlan_dev_real_dev(event_netdev) ? 1528 struct net_device *real_dev = rdma_vlan_dev_real_dev(event_netdev) ?
1503 rdma_vlan_dev_real_dev(event_netdev) : 1529 rdma_vlan_dev_real_dev(event_netdev) :
1504 event_netdev; 1530 event_netdev;
1531 union ib_gid default_gid;
1532
1533 mlx4_make_default_gid(real_dev, &default_gid);
1534
1535 if (!memcmp(gid, &default_gid, sizeof(*gid)))
1536 return 0;
1505 1537
1506 if (event != NETDEV_DOWN && event != NETDEV_UP) 1538 if (event != NETDEV_DOWN && event != NETDEV_UP)
1507 return 0; 1539 return 0;
@@ -1520,7 +1552,7 @@ static int mlx4_ib_addr_event(int event, struct net_device *event_netdev,
1520 (!netif_is_bond_master(real_dev) && 1552 (!netif_is_bond_master(real_dev) &&
1521 (real_dev == iboe->netdevs[port - 1]))) 1553 (real_dev == iboe->netdevs[port - 1])))
1522 update_gid_table(ibdev, port, gid, 1554 update_gid_table(ibdev, port, gid,
1523 event == NETDEV_DOWN); 1555 event == NETDEV_DOWN, 0);
1524 1556
1525 spin_unlock(&iboe->lock); 1557 spin_unlock(&iboe->lock);
1526 return 0; 1558 return 0;
@@ -1536,7 +1568,6 @@ static u8 mlx4_ib_get_dev_port(struct net_device *dev,
1536 rdma_vlan_dev_real_dev(dev) : dev; 1568 rdma_vlan_dev_real_dev(dev) : dev;
1537 1569
1538 iboe = &ibdev->iboe; 1570 iboe = &ibdev->iboe;
1539 spin_lock(&iboe->lock);
1540 1571
1541 for (port = 1; port <= MLX4_MAX_PORTS; ++port) 1572 for (port = 1; port <= MLX4_MAX_PORTS; ++port)
1542 if ((netif_is_bond_master(real_dev) && 1573 if ((netif_is_bond_master(real_dev) &&
@@ -1545,8 +1576,6 @@ static u8 mlx4_ib_get_dev_port(struct net_device *dev,
1545 (real_dev == iboe->netdevs[port - 1]))) 1576 (real_dev == iboe->netdevs[port - 1])))
1546 break; 1577 break;
1547 1578
1548 spin_unlock(&iboe->lock);
1549
1550 if ((port == 0) || (port > MLX4_MAX_PORTS)) 1579 if ((port == 0) || (port > MLX4_MAX_PORTS))
1551 return 0; 1580 return 0;
1552 else 1581 else
@@ -1607,7 +1636,7 @@ static void mlx4_ib_get_dev_addr(struct net_device *dev,
1607 /*ifa->ifa_address;*/ 1636 /*ifa->ifa_address;*/
1608 ipv6_addr_set_v4mapped(ifa->ifa_address, 1637 ipv6_addr_set_v4mapped(ifa->ifa_address,
1609 (struct in6_addr *)&gid); 1638 (struct in6_addr *)&gid);
1610 update_gid_table(ibdev, port, &gid, 0); 1639 update_gid_table(ibdev, port, &gid, 0, 0);
1611 } 1640 }
1612 endfor_ifa(in_dev); 1641 endfor_ifa(in_dev);
1613 in_dev_put(in_dev); 1642 in_dev_put(in_dev);
@@ -1619,7 +1648,7 @@ static void mlx4_ib_get_dev_addr(struct net_device *dev,
1619 read_lock_bh(&in6_dev->lock); 1648 read_lock_bh(&in6_dev->lock);
1620 list_for_each_entry(ifp, &in6_dev->addr_list, if_list) { 1649 list_for_each_entry(ifp, &in6_dev->addr_list, if_list) {
1621 pgid = (union ib_gid *)&ifp->addr; 1650 pgid = (union ib_gid *)&ifp->addr;
1622 update_gid_table(ibdev, port, pgid, 0); 1651 update_gid_table(ibdev, port, pgid, 0, 0);
1623 } 1652 }
1624 read_unlock_bh(&in6_dev->lock); 1653 read_unlock_bh(&in6_dev->lock);
1625 in6_dev_put(in6_dev); 1654 in6_dev_put(in6_dev);
@@ -1627,14 +1656,26 @@ static void mlx4_ib_get_dev_addr(struct net_device *dev,
1627#endif 1656#endif
1628} 1657}
1629 1658
1659static void mlx4_ib_set_default_gid(struct mlx4_ib_dev *ibdev,
1660 struct net_device *dev, u8 port)
1661{
1662 union ib_gid gid;
1663 mlx4_make_default_gid(dev, &gid);
1664 update_gid_table(ibdev, port, &gid, 0, 1);
1665}
1666
1630static int mlx4_ib_init_gid_table(struct mlx4_ib_dev *ibdev) 1667static int mlx4_ib_init_gid_table(struct mlx4_ib_dev *ibdev)
1631{ 1668{
1632 struct net_device *dev; 1669 struct net_device *dev;
1670 struct mlx4_ib_iboe *iboe = &ibdev->iboe;
1671 int i;
1633 1672
1634 if (reset_gid_table(ibdev)) 1673 for (i = 1; i <= ibdev->num_ports; ++i)
1635 return -1; 1674 if (reset_gid_table(ibdev, i))
1675 return -1;
1636 1676
1637 read_lock(&dev_base_lock); 1677 read_lock(&dev_base_lock);
1678 spin_lock(&iboe->lock);
1638 1679
1639 for_each_netdev(&init_net, dev) { 1680 for_each_netdev(&init_net, dev) {
1640 u8 port = mlx4_ib_get_dev_port(dev, ibdev); 1681 u8 port = mlx4_ib_get_dev_port(dev, ibdev);
@@ -1642,6 +1683,7 @@ static int mlx4_ib_init_gid_table(struct mlx4_ib_dev *ibdev)
1642 mlx4_ib_get_dev_addr(dev, ibdev, port); 1683 mlx4_ib_get_dev_addr(dev, ibdev, port);
1643 } 1684 }
1644 1685
1686 spin_unlock(&iboe->lock);
1645 read_unlock(&dev_base_lock); 1687 read_unlock(&dev_base_lock);
1646 1688
1647 return 0; 1689 return 0;
@@ -1656,25 +1698,57 @@ static void mlx4_ib_scan_netdevs(struct mlx4_ib_dev *ibdev)
1656 1698
1657 spin_lock(&iboe->lock); 1699 spin_lock(&iboe->lock);
1658 mlx4_foreach_ib_transport_port(port, ibdev->dev) { 1700 mlx4_foreach_ib_transport_port(port, ibdev->dev) {
1701 enum ib_port_state port_state = IB_PORT_NOP;
1659 struct net_device *old_master = iboe->masters[port - 1]; 1702 struct net_device *old_master = iboe->masters[port - 1];
1703 struct net_device *curr_netdev;
1660 struct net_device *curr_master; 1704 struct net_device *curr_master;
1705
1661 iboe->netdevs[port - 1] = 1706 iboe->netdevs[port - 1] =
1662 mlx4_get_protocol_dev(ibdev->dev, MLX4_PROT_ETH, port); 1707 mlx4_get_protocol_dev(ibdev->dev, MLX4_PROT_ETH, port);
1708 if (iboe->netdevs[port - 1])
1709 mlx4_ib_set_default_gid(ibdev,
1710 iboe->netdevs[port - 1], port);
1711 curr_netdev = iboe->netdevs[port - 1];
1663 1712
1664 if (iboe->netdevs[port - 1] && 1713 if (iboe->netdevs[port - 1] &&
1665 netif_is_bond_slave(iboe->netdevs[port - 1])) { 1714 netif_is_bond_slave(iboe->netdevs[port - 1])) {
1666 rtnl_lock();
1667 iboe->masters[port - 1] = netdev_master_upper_dev_get( 1715 iboe->masters[port - 1] = netdev_master_upper_dev_get(
1668 iboe->netdevs[port - 1]); 1716 iboe->netdevs[port - 1]);
1669 rtnl_unlock(); 1717 } else {
1718 iboe->masters[port - 1] = NULL;
1670 } 1719 }
1671 curr_master = iboe->masters[port - 1]; 1720 curr_master = iboe->masters[port - 1];
1672 1721
1722 if (curr_netdev) {
1723 port_state = (netif_running(curr_netdev) && netif_carrier_ok(curr_netdev)) ?
1724 IB_PORT_ACTIVE : IB_PORT_DOWN;
1725 mlx4_ib_set_default_gid(ibdev, curr_netdev, port);
1726 } else {
1727 reset_gid_table(ibdev, port);
1728 }
1729 /* if using bonding/team and a slave port is down, we don't the bond IP
1730 * based gids in the table since flows that select port by gid may get
1731 * the down port.
1732 */
1733 if (curr_master && (port_state == IB_PORT_DOWN)) {
1734 reset_gid_table(ibdev, port);
1735 mlx4_ib_set_default_gid(ibdev, curr_netdev, port);
1736 }
1673 /* if bonding is used it is possible that we add it to masters 1737 /* if bonding is used it is possible that we add it to masters
1674 only after IP address is assigned to the net bonding 1738 * only after IP address is assigned to the net bonding
1675 interface */ 1739 * interface.
1676 if (curr_master && (old_master != curr_master)) 1740 */
1741 if (curr_master && (old_master != curr_master)) {
1742 reset_gid_table(ibdev, port);
1743 mlx4_ib_set_default_gid(ibdev, curr_netdev, port);
1677 mlx4_ib_get_dev_addr(curr_master, ibdev, port); 1744 mlx4_ib_get_dev_addr(curr_master, ibdev, port);
1745 }
1746
1747 if (!curr_master && (old_master != curr_master)) {
1748 reset_gid_table(ibdev, port);
1749 mlx4_ib_set_default_gid(ibdev, curr_netdev, port);
1750 mlx4_ib_get_dev_addr(curr_netdev, ibdev, port);
1751 }
1678 } 1752 }
1679 1753
1680 spin_unlock(&iboe->lock); 1754 spin_unlock(&iboe->lock);
@@ -1810,6 +1884,7 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
1810 int i, j; 1884 int i, j;
1811 int err; 1885 int err;
1812 struct mlx4_ib_iboe *iboe; 1886 struct mlx4_ib_iboe *iboe;
1887 int ib_num_ports = 0;
1813 1888
1814 pr_info_once("%s", mlx4_ib_version); 1889 pr_info_once("%s", mlx4_ib_version);
1815 1890
@@ -1985,10 +2060,14 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
1985 ibdev->counters[i] = -1; 2060 ibdev->counters[i] = -1;
1986 } 2061 }
1987 2062
2063 mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB)
2064 ib_num_ports++;
2065
1988 spin_lock_init(&ibdev->sm_lock); 2066 spin_lock_init(&ibdev->sm_lock);
1989 mutex_init(&ibdev->cap_mask_mutex); 2067 mutex_init(&ibdev->cap_mask_mutex);
1990 2068
1991 if (ibdev->steering_support == MLX4_STEERING_MODE_DEVICE_MANAGED) { 2069 if (ibdev->steering_support == MLX4_STEERING_MODE_DEVICE_MANAGED &&
2070 ib_num_ports) {
1992 ibdev->steer_qpn_count = MLX4_IB_UC_MAX_NUM_QPS; 2071 ibdev->steer_qpn_count = MLX4_IB_UC_MAX_NUM_QPS;
1993 err = mlx4_qp_reserve_range(dev, ibdev->steer_qpn_count, 2072 err = mlx4_qp_reserve_range(dev, ibdev->steer_qpn_count,
1994 MLX4_IB_UC_STEER_QPN_ALIGN, 2073 MLX4_IB_UC_STEER_QPN_ALIGN,
@@ -2051,7 +2130,11 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
2051 } 2130 }
2052 } 2131 }
2053#endif 2132#endif
2133 for (i = 1 ; i <= ibdev->num_ports ; ++i)
2134 reset_gid_table(ibdev, i);
2135 rtnl_lock();
2054 mlx4_ib_scan_netdevs(ibdev); 2136 mlx4_ib_scan_netdevs(ibdev);
2137 rtnl_unlock();
2055 mlx4_ib_init_gid_table(ibdev); 2138 mlx4_ib_init_gid_table(ibdev);
2056 } 2139 }
2057 2140
diff --git a/drivers/infiniband/hw/mlx5/Kconfig b/drivers/infiniband/hw/mlx5/Kconfig
index 8e6aebfaf8a4..10df386c6344 100644
--- a/drivers/infiniband/hw/mlx5/Kconfig
+++ b/drivers/infiniband/hw/mlx5/Kconfig
@@ -1,6 +1,6 @@
1config MLX5_INFINIBAND 1config MLX5_INFINIBAND
2 tristate "Mellanox Connect-IB HCA support" 2 tristate "Mellanox Connect-IB HCA support"
3 depends on NETDEVICES && ETHERNET && PCI && X86 3 depends on NETDEVICES && ETHERNET && PCI
4 select NET_VENDOR_MELLANOX 4 select NET_VENDOR_MELLANOX
5 select MLX5_CORE 5 select MLX5_CORE
6 ---help--- 6 ---help---
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 9660d093f8cf..bf900579ac08 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -46,8 +46,8 @@
46#include "mlx5_ib.h" 46#include "mlx5_ib.h"
47 47
48#define DRIVER_NAME "mlx5_ib" 48#define DRIVER_NAME "mlx5_ib"
49#define DRIVER_VERSION "1.0" 49#define DRIVER_VERSION "2.2-1"
50#define DRIVER_RELDATE "June 2013" 50#define DRIVER_RELDATE "Feb 2014"
51 51
52MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); 52MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
53MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); 53MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver");
@@ -261,8 +261,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
261 props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT | 261 props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT |
262 IB_DEVICE_PORT_ACTIVE_EVENT | 262 IB_DEVICE_PORT_ACTIVE_EVENT |
263 IB_DEVICE_SYS_IMAGE_GUID | 263 IB_DEVICE_SYS_IMAGE_GUID |
264 IB_DEVICE_RC_RNR_NAK_GEN | 264 IB_DEVICE_RC_RNR_NAK_GEN;
265 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK;
266 flags = dev->mdev.caps.flags; 265 flags = dev->mdev.caps.flags;
267 if (flags & MLX5_DEV_CAP_FLAG_BAD_PKEY_CNTR) 266 if (flags & MLX5_DEV_CAP_FLAG_BAD_PKEY_CNTR)
268 props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR; 267 props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR;
@@ -536,24 +535,38 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
536 struct ib_udata *udata) 535 struct ib_udata *udata)
537{ 536{
538 struct mlx5_ib_dev *dev = to_mdev(ibdev); 537 struct mlx5_ib_dev *dev = to_mdev(ibdev);
539 struct mlx5_ib_alloc_ucontext_req req; 538 struct mlx5_ib_alloc_ucontext_req_v2 req;
540 struct mlx5_ib_alloc_ucontext_resp resp; 539 struct mlx5_ib_alloc_ucontext_resp resp;
541 struct mlx5_ib_ucontext *context; 540 struct mlx5_ib_ucontext *context;
542 struct mlx5_uuar_info *uuari; 541 struct mlx5_uuar_info *uuari;
543 struct mlx5_uar *uars; 542 struct mlx5_uar *uars;
544 int gross_uuars; 543 int gross_uuars;
545 int num_uars; 544 int num_uars;
545 int ver;
546 int uuarn; 546 int uuarn;
547 int err; 547 int err;
548 int i; 548 int i;
549 int reqlen;
549 550
550 if (!dev->ib_active) 551 if (!dev->ib_active)
551 return ERR_PTR(-EAGAIN); 552 return ERR_PTR(-EAGAIN);
552 553
553 err = ib_copy_from_udata(&req, udata, sizeof(req)); 554 memset(&req, 0, sizeof(req));
555 reqlen = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr);
556 if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req))
557 ver = 0;
558 else if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req_v2))
559 ver = 2;
560 else
561 return ERR_PTR(-EINVAL);
562
563 err = ib_copy_from_udata(&req, udata, reqlen);
554 if (err) 564 if (err)
555 return ERR_PTR(err); 565 return ERR_PTR(err);
556 566
567 if (req.flags || req.reserved)
568 return ERR_PTR(-EINVAL);
569
557 if (req.total_num_uuars > MLX5_MAX_UUARS) 570 if (req.total_num_uuars > MLX5_MAX_UUARS)
558 return ERR_PTR(-ENOMEM); 571 return ERR_PTR(-ENOMEM);
559 572
@@ -626,6 +639,7 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
626 if (err) 639 if (err)
627 goto out_uars; 640 goto out_uars;
628 641
642 uuari->ver = ver;
629 uuari->num_low_latency_uuars = req.num_low_latency_uuars; 643 uuari->num_low_latency_uuars = req.num_low_latency_uuars;
630 uuari->uars = uars; 644 uuari->uars = uars;
631 uuari->num_uars = num_uars; 645 uuari->num_uars = num_uars;
diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
index ae37fb9bf262..7dfe8a1c84cf 100644
--- a/drivers/infiniband/hw/mlx5/qp.c
+++ b/drivers/infiniband/hw/mlx5/qp.c
@@ -216,7 +216,9 @@ static int sq_overhead(enum ib_qp_type qp_type)
216 216
217 case IB_QPT_UC: 217 case IB_QPT_UC:
218 size += sizeof(struct mlx5_wqe_ctrl_seg) + 218 size += sizeof(struct mlx5_wqe_ctrl_seg) +
219 sizeof(struct mlx5_wqe_raddr_seg); 219 sizeof(struct mlx5_wqe_raddr_seg) +
220 sizeof(struct mlx5_wqe_umr_ctrl_seg) +
221 sizeof(struct mlx5_mkey_seg);
220 break; 222 break;
221 223
222 case IB_QPT_UD: 224 case IB_QPT_UD:
@@ -428,11 +430,17 @@ static int alloc_uuar(struct mlx5_uuar_info *uuari,
428 break; 430 break;
429 431
430 case MLX5_IB_LATENCY_CLASS_MEDIUM: 432 case MLX5_IB_LATENCY_CLASS_MEDIUM:
431 uuarn = alloc_med_class_uuar(uuari); 433 if (uuari->ver < 2)
434 uuarn = -ENOMEM;
435 else
436 uuarn = alloc_med_class_uuar(uuari);
432 break; 437 break;
433 438
434 case MLX5_IB_LATENCY_CLASS_HIGH: 439 case MLX5_IB_LATENCY_CLASS_HIGH:
435 uuarn = alloc_high_class_uuar(uuari); 440 if (uuari->ver < 2)
441 uuarn = -ENOMEM;
442 else
443 uuarn = alloc_high_class_uuar(uuari);
436 break; 444 break;
437 445
438 case MLX5_IB_LATENCY_CLASS_FAST_PATH: 446 case MLX5_IB_LATENCY_CLASS_FAST_PATH:
@@ -657,8 +665,8 @@ static int create_kernel_qp(struct mlx5_ib_dev *dev,
657 int err; 665 int err;
658 666
659 uuari = &dev->mdev.priv.uuari; 667 uuari = &dev->mdev.priv.uuari;
660 if (init_attr->create_flags & IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK) 668 if (init_attr->create_flags)
661 qp->flags |= MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK; 669 return -EINVAL;
662 670
663 if (init_attr->qp_type == MLX5_IB_QPT_REG_UMR) 671 if (init_attr->qp_type == MLX5_IB_QPT_REG_UMR)
664 lc = MLX5_IB_LATENCY_CLASS_FAST_PATH; 672 lc = MLX5_IB_LATENCY_CLASS_FAST_PATH;
diff --git a/drivers/infiniband/hw/mlx5/user.h b/drivers/infiniband/hw/mlx5/user.h
index 32a2a5dfc523..0f4f8e42a17f 100644
--- a/drivers/infiniband/hw/mlx5/user.h
+++ b/drivers/infiniband/hw/mlx5/user.h
@@ -62,6 +62,13 @@ struct mlx5_ib_alloc_ucontext_req {
62 __u32 num_low_latency_uuars; 62 __u32 num_low_latency_uuars;
63}; 63};
64 64
65struct mlx5_ib_alloc_ucontext_req_v2 {
66 __u32 total_num_uuars;
67 __u32 num_low_latency_uuars;
68 __u32 flags;
69 __u32 reserved;
70};
71
65struct mlx5_ib_alloc_ucontext_resp { 72struct mlx5_ib_alloc_ucontext_resp {
66 __u32 qp_tab_size; 73 __u32 qp_tab_size;
67 __u32 bf_reg_size; 74 __u32 bf_reg_size;
diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
index 429141078eec..353c7b05a90a 100644
--- a/drivers/infiniband/hw/nes/nes.c
+++ b/drivers/infiniband/hw/nes/nes.c
@@ -675,8 +675,11 @@ static int nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
675 INIT_DELAYED_WORK(&nesdev->work, nes_recheck_link_status); 675 INIT_DELAYED_WORK(&nesdev->work, nes_recheck_link_status);
676 676
677 /* Initialize network devices */ 677 /* Initialize network devices */
678 if ((netdev = nes_netdev_init(nesdev, mmio_regs)) == NULL) 678 netdev = nes_netdev_init(nesdev, mmio_regs);
679 if (netdev == NULL) {
680 ret = -ENOMEM;
679 goto bail7; 681 goto bail7;
682 }
680 683
681 /* Register network device */ 684 /* Register network device */
682 ret = register_netdev(netdev); 685 ret = register_netdev(netdev);
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
index 2ca86ca818bd..1a8a945efa60 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
@@ -127,7 +127,7 @@ static int ocrdma_addr_event(unsigned long event, struct net_device *netdev,
127 127
128 is_vlan = netdev->priv_flags & IFF_802_1Q_VLAN; 128 is_vlan = netdev->priv_flags & IFF_802_1Q_VLAN;
129 if (is_vlan) 129 if (is_vlan)
130 netdev = vlan_dev_real_dev(netdev); 130 netdev = rdma_vlan_dev_real_dev(netdev);
131 131
132 rcu_read_lock(); 132 rcu_read_lock();
133 list_for_each_entry_rcu(dev, &ocrdma_dev_list, entry) { 133 list_for_each_entry_rcu(dev, &ocrdma_dev_list, entry) {
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index aa92f40c9d50..e0cc201be41a 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -176,7 +176,7 @@ int ocrdma_query_port(struct ib_device *ibdev,
176 props->port_cap_flags = 176 props->port_cap_flags =
177 IB_PORT_CM_SUP | 177 IB_PORT_CM_SUP |
178 IB_PORT_REINIT_SUP | 178 IB_PORT_REINIT_SUP |
179 IB_PORT_DEVICE_MGMT_SUP | IB_PORT_VENDOR_CLASS_SUP; 179 IB_PORT_DEVICE_MGMT_SUP | IB_PORT_VENDOR_CLASS_SUP | IB_PORT_IP_BASED_GIDS;
180 props->gid_tbl_len = OCRDMA_MAX_SGID; 180 props->gid_tbl_len = OCRDMA_MAX_SGID;
181 props->pkey_tbl_len = 1; 181 props->pkey_tbl_len = 1;
182 props->bad_pkey_cntr = 0; 182 props->bad_pkey_cntr = 0;
@@ -1416,7 +1416,7 @@ int ocrdma_query_qp(struct ib_qp *ibqp,
1416 OCRDMA_QP_PARAMS_HOP_LMT_MASK) >> 1416 OCRDMA_QP_PARAMS_HOP_LMT_MASK) >>
1417 OCRDMA_QP_PARAMS_HOP_LMT_SHIFT; 1417 OCRDMA_QP_PARAMS_HOP_LMT_SHIFT;
1418 qp_attr->ah_attr.grh.traffic_class = (params.tclass_sq_psn & 1418 qp_attr->ah_attr.grh.traffic_class = (params.tclass_sq_psn &
1419 OCRDMA_QP_PARAMS_SQ_PSN_MASK) >> 1419 OCRDMA_QP_PARAMS_TCLASS_MASK) >>
1420 OCRDMA_QP_PARAMS_TCLASS_SHIFT; 1420 OCRDMA_QP_PARAMS_TCLASS_SHIFT;
1421 1421
1422 qp_attr->ah_attr.ah_flags = IB_AH_GRH; 1422 qp_attr->ah_attr.ah_flags = IB_AH_GRH;
diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/hw/qib/qib_iba7322.c
index 5bfc02f450e6..d1bd21319d7d 100644
--- a/drivers/infiniband/hw/qib/qib_iba7322.c
+++ b/drivers/infiniband/hw/qib/qib_iba7322.c
@@ -2395,6 +2395,11 @@ static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
2395 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a); 2395 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
2396 qib_write_kreg(dd, kr_scratch, 0ULL); 2396 qib_write_kreg(dd, kr_scratch, 0ULL);
2397 2397
2398 /* ensure previous Tx parameters are not still forced */
2399 qib_write_kreg_port(ppd, krp_tx_deemph_override,
2400 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
2401 reset_tx_deemphasis_override));
2402
2398 if (qib_compat_ddr_negotiate) { 2403 if (qib_compat_ddr_negotiate) {
2399 ppd->cpspec->ibdeltainprog = 1; 2404 ppd->cpspec->ibdeltainprog = 1;
2400 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd, 2405 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
diff --git a/drivers/infiniband/hw/usnic/usnic_ib_qp_grp.c b/drivers/infiniband/hw/usnic/usnic_ib_qp_grp.c
index 7ecc6061f1f4..f8dfd76be89f 100644
--- a/drivers/infiniband/hw/usnic/usnic_ib_qp_grp.c
+++ b/drivers/infiniband/hw/usnic/usnic_ib_qp_grp.c
@@ -629,6 +629,7 @@ static int qp_grp_id_from_flow(struct usnic_ib_qp_grp_flow *qp_flow,
629{ 629{
630 enum usnic_transport_type trans_type = qp_flow->trans_type; 630 enum usnic_transport_type trans_type = qp_flow->trans_type;
631 int err; 631 int err;
632 uint16_t port_num = 0;
632 633
633 switch (trans_type) { 634 switch (trans_type) {
634 case USNIC_TRANSPORT_ROCE_CUSTOM: 635 case USNIC_TRANSPORT_ROCE_CUSTOM:
@@ -637,9 +638,15 @@ static int qp_grp_id_from_flow(struct usnic_ib_qp_grp_flow *qp_flow,
637 case USNIC_TRANSPORT_IPV4_UDP: 638 case USNIC_TRANSPORT_IPV4_UDP:
638 err = usnic_transport_sock_get_addr(qp_flow->udp.sock, 639 err = usnic_transport_sock_get_addr(qp_flow->udp.sock,
639 NULL, NULL, 640 NULL, NULL,
640 (uint16_t *) id); 641 &port_num);
641 if (err) 642 if (err)
642 return err; 643 return err;
644 /*
645 * Copy port_num to stack first and then to *id,
646 * so that the short to int cast works for little
647 * and big endian systems.
648 */
649 *id = port_num;
643 break; 650 break;
644 default: 651 default:
645 usnic_err("Unsupported transport %u\n", trans_type); 652 usnic_err("Unsupported transport %u\n", trans_type);
diff --git a/drivers/infiniband/ulp/iser/iser_initiator.c b/drivers/infiniband/ulp/iser/iser_initiator.c
index 538822684d5b..334f34b1cd46 100644
--- a/drivers/infiniband/ulp/iser/iser_initiator.c
+++ b/drivers/infiniband/ulp/iser/iser_initiator.c
@@ -610,11 +610,12 @@ void iser_snd_completion(struct iser_tx_desc *tx_desc,
610 ib_dma_unmap_single(device->ib_device, tx_desc->dma_addr, 610 ib_dma_unmap_single(device->ib_device, tx_desc->dma_addr,
611 ISER_HEADERS_LEN, DMA_TO_DEVICE); 611 ISER_HEADERS_LEN, DMA_TO_DEVICE);
612 kmem_cache_free(ig.desc_cache, tx_desc); 612 kmem_cache_free(ig.desc_cache, tx_desc);
613 tx_desc = NULL;
613 } 614 }
614 615
615 atomic_dec(&ib_conn->post_send_buf_count); 616 atomic_dec(&ib_conn->post_send_buf_count);
616 617
617 if (tx_desc->type == ISCSI_TX_CONTROL) { 618 if (tx_desc && tx_desc->type == ISCSI_TX_CONTROL) {
618 /* this arithmetic is legal by libiscsi dd_data allocation */ 619 /* this arithmetic is legal by libiscsi dd_data allocation */
619 task = (void *) ((long)(void *)tx_desc - 620 task = (void *) ((long)(void *)tx_desc -
620 sizeof(struct iscsi_task)); 621 sizeof(struct iscsi_task));
diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
index afe95674008b..ca37edef2791 100644
--- a/drivers/infiniband/ulp/iser/iser_verbs.c
+++ b/drivers/infiniband/ulp/iser/iser_verbs.c
@@ -652,9 +652,13 @@ static int iser_disconnected_handler(struct rdma_cm_id *cma_id)
652 /* getting here when the state is UP means that the conn is being * 652 /* getting here when the state is UP means that the conn is being *
653 * terminated asynchronously from the iSCSI layer's perspective. */ 653 * terminated asynchronously from the iSCSI layer's perspective. */
654 if (iser_conn_state_comp_exch(ib_conn, ISER_CONN_UP, 654 if (iser_conn_state_comp_exch(ib_conn, ISER_CONN_UP,
655 ISER_CONN_TERMINATING)) 655 ISER_CONN_TERMINATING)){
656 iscsi_conn_failure(ib_conn->iser_conn->iscsi_conn, 656 if (ib_conn->iser_conn)
657 ISCSI_ERR_CONN_FAILED); 657 iscsi_conn_failure(ib_conn->iser_conn->iscsi_conn,
658 ISCSI_ERR_CONN_FAILED);
659 else
660 iser_err("iscsi_iser connection isn't bound\n");
661 }
658 662
659 /* Complete the termination process if no posts are pending */ 663 /* Complete the termination process if no posts are pending */
660 if (ib_conn->post_recv_buf_count == 0 && 664 if (ib_conn->post_recv_buf_count == 0 &&
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index 2b161be3c1a3..8ee228e9ab5a 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -453,6 +453,7 @@ isert_conn_create_fastreg_pool(struct isert_conn *isert_conn)
453 if (ret) { 453 if (ret) {
454 pr_err("Failed to create fastreg descriptor err=%d\n", 454 pr_err("Failed to create fastreg descriptor err=%d\n",
455 ret); 455 ret);
456 kfree(fr_desc);
456 goto err; 457 goto err;
457 } 458 }
458 459
@@ -491,12 +492,11 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
491 isert_conn->state = ISER_CONN_INIT; 492 isert_conn->state = ISER_CONN_INIT;
492 INIT_LIST_HEAD(&isert_conn->conn_accept_node); 493 INIT_LIST_HEAD(&isert_conn->conn_accept_node);
493 init_completion(&isert_conn->conn_login_comp); 494 init_completion(&isert_conn->conn_login_comp);
494 init_waitqueue_head(&isert_conn->conn_wait); 495 init_completion(&isert_conn->conn_wait);
495 init_waitqueue_head(&isert_conn->conn_wait_comp_err); 496 init_completion(&isert_conn->conn_wait_comp_err);
496 kref_init(&isert_conn->conn_kref); 497 kref_init(&isert_conn->conn_kref);
497 kref_get(&isert_conn->conn_kref); 498 kref_get(&isert_conn->conn_kref);
498 mutex_init(&isert_conn->conn_mutex); 499 mutex_init(&isert_conn->conn_mutex);
499 mutex_init(&isert_conn->conn_comp_mutex);
500 spin_lock_init(&isert_conn->conn_lock); 500 spin_lock_init(&isert_conn->conn_lock);
501 501
502 cma_id->context = isert_conn; 502 cma_id->context = isert_conn;
@@ -687,11 +687,11 @@ isert_disconnect_work(struct work_struct *work)
687 687
688 pr_debug("isert_disconnect_work(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); 688 pr_debug("isert_disconnect_work(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
689 mutex_lock(&isert_conn->conn_mutex); 689 mutex_lock(&isert_conn->conn_mutex);
690 isert_conn->state = ISER_CONN_DOWN; 690 if (isert_conn->state == ISER_CONN_UP)
691 isert_conn->state = ISER_CONN_TERMINATING;
691 692
692 if (isert_conn->post_recv_buf_count == 0 && 693 if (isert_conn->post_recv_buf_count == 0 &&
693 atomic_read(&isert_conn->post_send_buf_count) == 0) { 694 atomic_read(&isert_conn->post_send_buf_count) == 0) {
694 pr_debug("Calling wake_up(&isert_conn->conn_wait);\n");
695 mutex_unlock(&isert_conn->conn_mutex); 695 mutex_unlock(&isert_conn->conn_mutex);
696 goto wake_up; 696 goto wake_up;
697 } 697 }
@@ -711,7 +711,7 @@ isert_disconnect_work(struct work_struct *work)
711 mutex_unlock(&isert_conn->conn_mutex); 711 mutex_unlock(&isert_conn->conn_mutex);
712 712
713wake_up: 713wake_up:
714 wake_up(&isert_conn->conn_wait); 714 complete(&isert_conn->conn_wait);
715 isert_put_conn(isert_conn); 715 isert_put_conn(isert_conn);
716} 716}
717 717
@@ -887,16 +887,17 @@ isert_init_send_wr(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd,
887 * Coalesce send completion interrupts by only setting IB_SEND_SIGNALED 887 * Coalesce send completion interrupts by only setting IB_SEND_SIGNALED
888 * bit for every ISERT_COMP_BATCH_COUNT number of ib_post_send() calls. 888 * bit for every ISERT_COMP_BATCH_COUNT number of ib_post_send() calls.
889 */ 889 */
890 mutex_lock(&isert_conn->conn_comp_mutex); 890 mutex_lock(&isert_conn->conn_mutex);
891 if (coalesce && 891 if (coalesce && isert_conn->state == ISER_CONN_UP &&
892 ++isert_conn->conn_comp_batch < ISERT_COMP_BATCH_COUNT) { 892 ++isert_conn->conn_comp_batch < ISERT_COMP_BATCH_COUNT) {
893 tx_desc->llnode_active = true;
893 llist_add(&tx_desc->comp_llnode, &isert_conn->conn_comp_llist); 894 llist_add(&tx_desc->comp_llnode, &isert_conn->conn_comp_llist);
894 mutex_unlock(&isert_conn->conn_comp_mutex); 895 mutex_unlock(&isert_conn->conn_mutex);
895 return; 896 return;
896 } 897 }
897 isert_conn->conn_comp_batch = 0; 898 isert_conn->conn_comp_batch = 0;
898 tx_desc->comp_llnode_batch = llist_del_all(&isert_conn->conn_comp_llist); 899 tx_desc->comp_llnode_batch = llist_del_all(&isert_conn->conn_comp_llist);
899 mutex_unlock(&isert_conn->conn_comp_mutex); 900 mutex_unlock(&isert_conn->conn_mutex);
900 901
901 send_wr->send_flags = IB_SEND_SIGNALED; 902 send_wr->send_flags = IB_SEND_SIGNALED;
902} 903}
@@ -1463,7 +1464,7 @@ isert_put_cmd(struct isert_cmd *isert_cmd)
1463 case ISCSI_OP_SCSI_CMD: 1464 case ISCSI_OP_SCSI_CMD:
1464 spin_lock_bh(&conn->cmd_lock); 1465 spin_lock_bh(&conn->cmd_lock);
1465 if (!list_empty(&cmd->i_conn_node)) 1466 if (!list_empty(&cmd->i_conn_node))
1466 list_del(&cmd->i_conn_node); 1467 list_del_init(&cmd->i_conn_node);
1467 spin_unlock_bh(&conn->cmd_lock); 1468 spin_unlock_bh(&conn->cmd_lock);
1468 1469
1469 if (cmd->data_direction == DMA_TO_DEVICE) 1470 if (cmd->data_direction == DMA_TO_DEVICE)
@@ -1475,7 +1476,7 @@ isert_put_cmd(struct isert_cmd *isert_cmd)
1475 case ISCSI_OP_SCSI_TMFUNC: 1476 case ISCSI_OP_SCSI_TMFUNC:
1476 spin_lock_bh(&conn->cmd_lock); 1477 spin_lock_bh(&conn->cmd_lock);
1477 if (!list_empty(&cmd->i_conn_node)) 1478 if (!list_empty(&cmd->i_conn_node))
1478 list_del(&cmd->i_conn_node); 1479 list_del_init(&cmd->i_conn_node);
1479 spin_unlock_bh(&conn->cmd_lock); 1480 spin_unlock_bh(&conn->cmd_lock);
1480 1481
1481 transport_generic_free_cmd(&cmd->se_cmd, 0); 1482 transport_generic_free_cmd(&cmd->se_cmd, 0);
@@ -1485,7 +1486,7 @@ isert_put_cmd(struct isert_cmd *isert_cmd)
1485 case ISCSI_OP_TEXT: 1486 case ISCSI_OP_TEXT:
1486 spin_lock_bh(&conn->cmd_lock); 1487 spin_lock_bh(&conn->cmd_lock);
1487 if (!list_empty(&cmd->i_conn_node)) 1488 if (!list_empty(&cmd->i_conn_node))
1488 list_del(&cmd->i_conn_node); 1489 list_del_init(&cmd->i_conn_node);
1489 spin_unlock_bh(&conn->cmd_lock); 1490 spin_unlock_bh(&conn->cmd_lock);
1490 1491
1491 /* 1492 /*
@@ -1548,6 +1549,7 @@ isert_completion_rdma_read(struct iser_tx_desc *tx_desc,
1548 iscsit_stop_dataout_timer(cmd); 1549 iscsit_stop_dataout_timer(cmd);
1549 device->unreg_rdma_mem(isert_cmd, isert_conn); 1550 device->unreg_rdma_mem(isert_cmd, isert_conn);
1550 cmd->write_data_done = wr->cur_rdma_length; 1551 cmd->write_data_done = wr->cur_rdma_length;
1552 wr->send_wr_num = 0;
1551 1553
1552 pr_debug("Cmd: %p RDMA_READ comp calling execute_cmd\n", isert_cmd); 1554 pr_debug("Cmd: %p RDMA_READ comp calling execute_cmd\n", isert_cmd);
1553 spin_lock_bh(&cmd->istate_lock); 1555 spin_lock_bh(&cmd->istate_lock);
@@ -1588,7 +1590,7 @@ isert_do_control_comp(struct work_struct *work)
1588 pr_debug("Calling iscsit_logout_post_handler >>>>>>>>>>>>>>\n"); 1590 pr_debug("Calling iscsit_logout_post_handler >>>>>>>>>>>>>>\n");
1589 /* 1591 /*
1590 * Call atomic_dec(&isert_conn->post_send_buf_count) 1592 * Call atomic_dec(&isert_conn->post_send_buf_count)
1591 * from isert_free_conn() 1593 * from isert_wait_conn()
1592 */ 1594 */
1593 isert_conn->logout_posted = true; 1595 isert_conn->logout_posted = true;
1594 iscsit_logout_post_handler(cmd, cmd->conn); 1596 iscsit_logout_post_handler(cmd, cmd->conn);
@@ -1612,6 +1614,7 @@ isert_response_completion(struct iser_tx_desc *tx_desc,
1612 struct ib_device *ib_dev) 1614 struct ib_device *ib_dev)
1613{ 1615{
1614 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; 1616 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd;
1617 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr;
1615 1618
1616 if (cmd->i_state == ISTATE_SEND_TASKMGTRSP || 1619 if (cmd->i_state == ISTATE_SEND_TASKMGTRSP ||
1617 cmd->i_state == ISTATE_SEND_LOGOUTRSP || 1620 cmd->i_state == ISTATE_SEND_LOGOUTRSP ||
@@ -1623,7 +1626,7 @@ isert_response_completion(struct iser_tx_desc *tx_desc,
1623 queue_work(isert_comp_wq, &isert_cmd->comp_work); 1626 queue_work(isert_comp_wq, &isert_cmd->comp_work);
1624 return; 1627 return;
1625 } 1628 }
1626 atomic_dec(&isert_conn->post_send_buf_count); 1629 atomic_sub(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
1627 1630
1628 cmd->i_state = ISTATE_SENT_STATUS; 1631 cmd->i_state = ISTATE_SENT_STATUS;
1629 isert_completion_put(tx_desc, isert_cmd, ib_dev); 1632 isert_completion_put(tx_desc, isert_cmd, ib_dev);
@@ -1661,7 +1664,7 @@ __isert_send_completion(struct iser_tx_desc *tx_desc,
1661 case ISER_IB_RDMA_READ: 1664 case ISER_IB_RDMA_READ:
1662 pr_debug("isert_send_completion: Got ISER_IB_RDMA_READ:\n"); 1665 pr_debug("isert_send_completion: Got ISER_IB_RDMA_READ:\n");
1663 1666
1664 atomic_dec(&isert_conn->post_send_buf_count); 1667 atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count);
1665 isert_completion_rdma_read(tx_desc, isert_cmd); 1668 isert_completion_rdma_read(tx_desc, isert_cmd);
1666 break; 1669 break;
1667 default: 1670 default:
@@ -1690,31 +1693,76 @@ isert_send_completion(struct iser_tx_desc *tx_desc,
1690} 1693}
1691 1694
1692static void 1695static void
1693isert_cq_comp_err(struct iser_tx_desc *tx_desc, struct isert_conn *isert_conn) 1696isert_cq_drain_comp_llist(struct isert_conn *isert_conn, struct ib_device *ib_dev)
1697{
1698 struct llist_node *llnode;
1699 struct isert_rdma_wr *wr;
1700 struct iser_tx_desc *t;
1701
1702 mutex_lock(&isert_conn->conn_mutex);
1703 llnode = llist_del_all(&isert_conn->conn_comp_llist);
1704 isert_conn->conn_comp_batch = 0;
1705 mutex_unlock(&isert_conn->conn_mutex);
1706
1707 while (llnode) {
1708 t = llist_entry(llnode, struct iser_tx_desc, comp_llnode);
1709 llnode = llist_next(llnode);
1710 wr = &t->isert_cmd->rdma_wr;
1711
1712 atomic_sub(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
1713 isert_completion_put(t, t->isert_cmd, ib_dev);
1714 }
1715}
1716
1717static void
1718isert_cq_tx_comp_err(struct iser_tx_desc *tx_desc, struct isert_conn *isert_conn)
1694{ 1719{
1695 struct ib_device *ib_dev = isert_conn->conn_cm_id->device; 1720 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1721 struct isert_cmd *isert_cmd = tx_desc->isert_cmd;
1722 struct llist_node *llnode = tx_desc->comp_llnode_batch;
1723 struct isert_rdma_wr *wr;
1724 struct iser_tx_desc *t;
1696 1725
1697 if (tx_desc) { 1726 while (llnode) {
1698 struct isert_cmd *isert_cmd = tx_desc->isert_cmd; 1727 t = llist_entry(llnode, struct iser_tx_desc, comp_llnode);
1728 llnode = llist_next(llnode);
1729 wr = &t->isert_cmd->rdma_wr;
1699 1730
1700 if (!isert_cmd) 1731 atomic_sub(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
1701 isert_unmap_tx_desc(tx_desc, ib_dev); 1732 isert_completion_put(t, t->isert_cmd, ib_dev);
1702 else
1703 isert_completion_put(tx_desc, isert_cmd, ib_dev);
1704 } 1733 }
1734 tx_desc->comp_llnode_batch = NULL;
1705 1735
1706 if (isert_conn->post_recv_buf_count == 0 && 1736 if (!isert_cmd)
1707 atomic_read(&isert_conn->post_send_buf_count) == 0) { 1737 isert_unmap_tx_desc(tx_desc, ib_dev);
1708 pr_debug("isert_cq_comp_err >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); 1738 else
1709 pr_debug("Calling wake_up from isert_cq_comp_err\n"); 1739 isert_completion_put(tx_desc, isert_cmd, ib_dev);
1740}
1710 1741
1711 mutex_lock(&isert_conn->conn_mutex); 1742static void
1712 if (isert_conn->state != ISER_CONN_DOWN) 1743isert_cq_rx_comp_err(struct isert_conn *isert_conn)
1713 isert_conn->state = ISER_CONN_TERMINATING; 1744{
1714 mutex_unlock(&isert_conn->conn_mutex); 1745 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1746 struct iscsi_conn *conn = isert_conn->conn;
1715 1747
1716 wake_up(&isert_conn->conn_wait_comp_err); 1748 if (isert_conn->post_recv_buf_count)
1749 return;
1750
1751 isert_cq_drain_comp_llist(isert_conn, ib_dev);
1752
1753 if (conn->sess) {
1754 target_sess_cmd_list_set_waiting(conn->sess->se_sess);
1755 target_wait_for_sess_cmds(conn->sess->se_sess);
1717 } 1756 }
1757
1758 while (atomic_read(&isert_conn->post_send_buf_count))
1759 msleep(3000);
1760
1761 mutex_lock(&isert_conn->conn_mutex);
1762 isert_conn->state = ISER_CONN_DOWN;
1763 mutex_unlock(&isert_conn->conn_mutex);
1764
1765 complete(&isert_conn->conn_wait_comp_err);
1718} 1766}
1719 1767
1720static void 1768static void
@@ -1739,8 +1787,14 @@ isert_cq_tx_work(struct work_struct *work)
1739 pr_debug("TX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n"); 1787 pr_debug("TX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n");
1740 pr_debug("TX wc.status: 0x%08x\n", wc.status); 1788 pr_debug("TX wc.status: 0x%08x\n", wc.status);
1741 pr_debug("TX wc.vendor_err: 0x%08x\n", wc.vendor_err); 1789 pr_debug("TX wc.vendor_err: 0x%08x\n", wc.vendor_err);
1742 atomic_dec(&isert_conn->post_send_buf_count); 1790
1743 isert_cq_comp_err(tx_desc, isert_conn); 1791 if (wc.wr_id != ISER_FASTREG_LI_WRID) {
1792 if (tx_desc->llnode_active)
1793 continue;
1794
1795 atomic_dec(&isert_conn->post_send_buf_count);
1796 isert_cq_tx_comp_err(tx_desc, isert_conn);
1797 }
1744 } 1798 }
1745 } 1799 }
1746 1800
@@ -1783,7 +1837,7 @@ isert_cq_rx_work(struct work_struct *work)
1783 wc.vendor_err); 1837 wc.vendor_err);
1784 } 1838 }
1785 isert_conn->post_recv_buf_count--; 1839 isert_conn->post_recv_buf_count--;
1786 isert_cq_comp_err(NULL, isert_conn); 1840 isert_cq_rx_comp_err(isert_conn);
1787 } 1841 }
1788 } 1842 }
1789 1843
@@ -2201,6 +2255,7 @@ isert_fast_reg_mr(struct fast_reg_descriptor *fr_desc,
2201 2255
2202 if (!fr_desc->valid) { 2256 if (!fr_desc->valid) {
2203 memset(&inv_wr, 0, sizeof(inv_wr)); 2257 memset(&inv_wr, 0, sizeof(inv_wr));
2258 inv_wr.wr_id = ISER_FASTREG_LI_WRID;
2204 inv_wr.opcode = IB_WR_LOCAL_INV; 2259 inv_wr.opcode = IB_WR_LOCAL_INV;
2205 inv_wr.ex.invalidate_rkey = fr_desc->data_mr->rkey; 2260 inv_wr.ex.invalidate_rkey = fr_desc->data_mr->rkey;
2206 wr = &inv_wr; 2261 wr = &inv_wr;
@@ -2211,6 +2266,7 @@ isert_fast_reg_mr(struct fast_reg_descriptor *fr_desc,
2211 2266
2212 /* Prepare FASTREG WR */ 2267 /* Prepare FASTREG WR */
2213 memset(&fr_wr, 0, sizeof(fr_wr)); 2268 memset(&fr_wr, 0, sizeof(fr_wr));
2269 fr_wr.wr_id = ISER_FASTREG_LI_WRID;
2214 fr_wr.opcode = IB_WR_FAST_REG_MR; 2270 fr_wr.opcode = IB_WR_FAST_REG_MR;
2215 fr_wr.wr.fast_reg.iova_start = 2271 fr_wr.wr.fast_reg.iova_start =
2216 fr_desc->data_frpl->page_list[0] + page_off; 2272 fr_desc->data_frpl->page_list[0] + page_off;
@@ -2376,12 +2432,12 @@ isert_put_datain(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
2376 isert_init_send_wr(isert_conn, isert_cmd, 2432 isert_init_send_wr(isert_conn, isert_cmd,
2377 &isert_cmd->tx_desc.send_wr, true); 2433 &isert_cmd->tx_desc.send_wr, true);
2378 2434
2379 atomic_inc(&isert_conn->post_send_buf_count); 2435 atomic_add(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
2380 2436
2381 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed); 2437 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed);
2382 if (rc) { 2438 if (rc) {
2383 pr_warn("ib_post_send() failed for IB_WR_RDMA_WRITE\n"); 2439 pr_warn("ib_post_send() failed for IB_WR_RDMA_WRITE\n");
2384 atomic_dec(&isert_conn->post_send_buf_count); 2440 atomic_sub(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
2385 } 2441 }
2386 pr_debug("Cmd: %p posted RDMA_WRITE + Response for iSER Data READ\n", 2442 pr_debug("Cmd: %p posted RDMA_WRITE + Response for iSER Data READ\n",
2387 isert_cmd); 2443 isert_cmd);
@@ -2409,12 +2465,12 @@ isert_get_dataout(struct iscsi_conn *conn, struct iscsi_cmd *cmd, bool recovery)
2409 return rc; 2465 return rc;
2410 } 2466 }
2411 2467
2412 atomic_inc(&isert_conn->post_send_buf_count); 2468 atomic_add(wr->send_wr_num, &isert_conn->post_send_buf_count);
2413 2469
2414 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed); 2470 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed);
2415 if (rc) { 2471 if (rc) {
2416 pr_warn("ib_post_send() failed for IB_WR_RDMA_READ\n"); 2472 pr_warn("ib_post_send() failed for IB_WR_RDMA_READ\n");
2417 atomic_dec(&isert_conn->post_send_buf_count); 2473 atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count);
2418 } 2474 }
2419 pr_debug("Cmd: %p posted RDMA_READ memory for ISER Data WRITE\n", 2475 pr_debug("Cmd: %p posted RDMA_READ memory for ISER Data WRITE\n",
2420 isert_cmd); 2476 isert_cmd);
@@ -2701,22 +2757,11 @@ isert_free_np(struct iscsi_np *np)
2701 kfree(isert_np); 2757 kfree(isert_np);
2702} 2758}
2703 2759
2704static int isert_check_state(struct isert_conn *isert_conn, int state) 2760static void isert_wait_conn(struct iscsi_conn *conn)
2705{
2706 int ret;
2707
2708 mutex_lock(&isert_conn->conn_mutex);
2709 ret = (isert_conn->state == state);
2710 mutex_unlock(&isert_conn->conn_mutex);
2711
2712 return ret;
2713}
2714
2715static void isert_free_conn(struct iscsi_conn *conn)
2716{ 2761{
2717 struct isert_conn *isert_conn = conn->context; 2762 struct isert_conn *isert_conn = conn->context;
2718 2763
2719 pr_debug("isert_free_conn: Starting \n"); 2764 pr_debug("isert_wait_conn: Starting \n");
2720 /* 2765 /*
2721 * Decrement post_send_buf_count for special case when called 2766 * Decrement post_send_buf_count for special case when called
2722 * from isert_do_control_comp() -> iscsit_logout_post_handler() 2767 * from isert_do_control_comp() -> iscsit_logout_post_handler()
@@ -2726,38 +2771,29 @@ static void isert_free_conn(struct iscsi_conn *conn)
2726 atomic_dec(&isert_conn->post_send_buf_count); 2771 atomic_dec(&isert_conn->post_send_buf_count);
2727 2772
2728 if (isert_conn->conn_cm_id && isert_conn->state != ISER_CONN_DOWN) { 2773 if (isert_conn->conn_cm_id && isert_conn->state != ISER_CONN_DOWN) {
2729 pr_debug("Calling rdma_disconnect from isert_free_conn\n"); 2774 pr_debug("Calling rdma_disconnect from isert_wait_conn\n");
2730 rdma_disconnect(isert_conn->conn_cm_id); 2775 rdma_disconnect(isert_conn->conn_cm_id);
2731 } 2776 }
2732 /* 2777 /*
2733 * Only wait for conn_wait_comp_err if the isert_conn made it 2778 * Only wait for conn_wait_comp_err if the isert_conn made it
2734 * into full feature phase.. 2779 * into full feature phase..
2735 */ 2780 */
2736 if (isert_conn->state == ISER_CONN_UP) {
2737 pr_debug("isert_free_conn: Before wait_event comp_err %d\n",
2738 isert_conn->state);
2739 mutex_unlock(&isert_conn->conn_mutex);
2740
2741 wait_event(isert_conn->conn_wait_comp_err,
2742 (isert_check_state(isert_conn, ISER_CONN_TERMINATING)));
2743
2744 wait_event(isert_conn->conn_wait,
2745 (isert_check_state(isert_conn, ISER_CONN_DOWN)));
2746
2747 isert_put_conn(isert_conn);
2748 return;
2749 }
2750 if (isert_conn->state == ISER_CONN_INIT) { 2781 if (isert_conn->state == ISER_CONN_INIT) {
2751 mutex_unlock(&isert_conn->conn_mutex); 2782 mutex_unlock(&isert_conn->conn_mutex);
2752 isert_put_conn(isert_conn);
2753 return; 2783 return;
2754 } 2784 }
2755 pr_debug("isert_free_conn: wait_event conn_wait %d\n", 2785 if (isert_conn->state == ISER_CONN_UP)
2756 isert_conn->state); 2786 isert_conn->state = ISER_CONN_TERMINATING;
2757 mutex_unlock(&isert_conn->conn_mutex); 2787 mutex_unlock(&isert_conn->conn_mutex);
2758 2788
2759 wait_event(isert_conn->conn_wait, 2789 wait_for_completion(&isert_conn->conn_wait_comp_err);
2760 (isert_check_state(isert_conn, ISER_CONN_DOWN))); 2790
2791 wait_for_completion(&isert_conn->conn_wait);
2792}
2793
2794static void isert_free_conn(struct iscsi_conn *conn)
2795{
2796 struct isert_conn *isert_conn = conn->context;
2761 2797
2762 isert_put_conn(isert_conn); 2798 isert_put_conn(isert_conn);
2763} 2799}
@@ -2770,6 +2806,7 @@ static struct iscsit_transport iser_target_transport = {
2770 .iscsit_setup_np = isert_setup_np, 2806 .iscsit_setup_np = isert_setup_np,
2771 .iscsit_accept_np = isert_accept_np, 2807 .iscsit_accept_np = isert_accept_np,
2772 .iscsit_free_np = isert_free_np, 2808 .iscsit_free_np = isert_free_np,
2809 .iscsit_wait_conn = isert_wait_conn,
2773 .iscsit_free_conn = isert_free_conn, 2810 .iscsit_free_conn = isert_free_conn,
2774 .iscsit_get_login_rx = isert_get_login_rx, 2811 .iscsit_get_login_rx = isert_get_login_rx,
2775 .iscsit_put_login_tx = isert_put_login_tx, 2812 .iscsit_put_login_tx = isert_put_login_tx,
diff --git a/drivers/infiniband/ulp/isert/ib_isert.h b/drivers/infiniband/ulp/isert/ib_isert.h
index 708a069002f3..f6ae7f5dd408 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.h
+++ b/drivers/infiniband/ulp/isert/ib_isert.h
@@ -6,6 +6,7 @@
6 6
7#define ISERT_RDMA_LISTEN_BACKLOG 10 7#define ISERT_RDMA_LISTEN_BACKLOG 10
8#define ISCSI_ISER_SG_TABLESIZE 256 8#define ISCSI_ISER_SG_TABLESIZE 256
9#define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL
9 10
10enum isert_desc_type { 11enum isert_desc_type {
11 ISCSI_TX_CONTROL, 12 ISCSI_TX_CONTROL,
@@ -45,6 +46,7 @@ struct iser_tx_desc {
45 struct isert_cmd *isert_cmd; 46 struct isert_cmd *isert_cmd;
46 struct llist_node *comp_llnode_batch; 47 struct llist_node *comp_llnode_batch;
47 struct llist_node comp_llnode; 48 struct llist_node comp_llnode;
49 bool llnode_active;
48 struct ib_send_wr send_wr; 50 struct ib_send_wr send_wr;
49} __packed; 51} __packed;
50 52
@@ -116,8 +118,8 @@ struct isert_conn {
116 struct isert_device *conn_device; 118 struct isert_device *conn_device;
117 struct work_struct conn_logout_work; 119 struct work_struct conn_logout_work;
118 struct mutex conn_mutex; 120 struct mutex conn_mutex;
119 wait_queue_head_t conn_wait; 121 struct completion conn_wait;
120 wait_queue_head_t conn_wait_comp_err; 122 struct completion conn_wait_comp_err;
121 struct kref conn_kref; 123 struct kref conn_kref;
122 struct list_head conn_fr_pool; 124 struct list_head conn_fr_pool;
123 int conn_fr_pool_size; 125 int conn_fr_pool_size;
@@ -126,7 +128,6 @@ struct isert_conn {
126#define ISERT_COMP_BATCH_COUNT 8 128#define ISERT_COMP_BATCH_COUNT 8
127 int conn_comp_batch; 129 int conn_comp_batch;
128 struct llist_head conn_comp_llist; 130 struct llist_head conn_comp_llist;
129 struct mutex conn_comp_mutex;
130}; 131};
131 132
132#define ISERT_MAX_CQ 64 133#define ISERT_MAX_CQ 64
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 520a7e5a490b..0e537d8d0e47 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -3666,9 +3666,9 @@ static ssize_t srpt_tpg_attrib_store_srp_max_rdma_size(
3666 unsigned long val; 3666 unsigned long val;
3667 int ret; 3667 int ret;
3668 3668
3669 ret = strict_strtoul(page, 0, &val); 3669 ret = kstrtoul(page, 0, &val);
3670 if (ret < 0) { 3670 if (ret < 0) {
3671 pr_err("strict_strtoul() failed with ret: %d\n", ret); 3671 pr_err("kstrtoul() failed with ret: %d\n", ret);
3672 return -EINVAL; 3672 return -EINVAL;
3673 } 3673 }
3674 if (val > MAX_SRPT_RDMA_SIZE) { 3674 if (val > MAX_SRPT_RDMA_SIZE) {
@@ -3706,9 +3706,9 @@ static ssize_t srpt_tpg_attrib_store_srp_max_rsp_size(
3706 unsigned long val; 3706 unsigned long val;
3707 int ret; 3707 int ret;
3708 3708
3709 ret = strict_strtoul(page, 0, &val); 3709 ret = kstrtoul(page, 0, &val);
3710 if (ret < 0) { 3710 if (ret < 0) {
3711 pr_err("strict_strtoul() failed with ret: %d\n", ret); 3711 pr_err("kstrtoul() failed with ret: %d\n", ret);
3712 return -EINVAL; 3712 return -EINVAL;
3713 } 3713 }
3714 if (val > MAX_SRPT_RSP_SIZE) { 3714 if (val > MAX_SRPT_RSP_SIZE) {
@@ -3746,9 +3746,9 @@ static ssize_t srpt_tpg_attrib_store_srp_sq_size(
3746 unsigned long val; 3746 unsigned long val;
3747 int ret; 3747 int ret;
3748 3748
3749 ret = strict_strtoul(page, 0, &val); 3749 ret = kstrtoul(page, 0, &val);
3750 if (ret < 0) { 3750 if (ret < 0) {
3751 pr_err("strict_strtoul() failed with ret: %d\n", ret); 3751 pr_err("kstrtoul() failed with ret: %d\n", ret);
3752 return -EINVAL; 3752 return -EINVAL;
3753 } 3753 }
3754 if (val > MAX_SRPT_SRQ_SIZE) { 3754 if (val > MAX_SRPT_SRQ_SIZE) {
@@ -3793,7 +3793,7 @@ static ssize_t srpt_tpg_store_enable(
3793 unsigned long tmp; 3793 unsigned long tmp;
3794 int ret; 3794 int ret;
3795 3795
3796 ret = strict_strtoul(page, 0, &tmp); 3796 ret = kstrtoul(page, 0, &tmp);
3797 if (ret < 0) { 3797 if (ret < 0) {
3798 printk(KERN_ERR "Unable to extract srpt_tpg_store_enable\n"); 3798 printk(KERN_ERR "Unable to extract srpt_tpg_store_enable\n");
3799 return -EINVAL; 3799 return -EINVAL;
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index a06e12552886..ce953d895f5b 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -954,11 +954,13 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
954 return -EFAULT; 954 return -EFAULT;
955 955
956 error = input_ff_upload(dev, &effect, file); 956 error = input_ff_upload(dev, &effect, file);
957 if (error)
958 return error;
957 959
958 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id))) 960 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
959 return -EFAULT; 961 return -EFAULT;
960 962
961 return error; 963 return 0;
962 } 964 }
963 965
964 /* Multi-number variable-length handlers */ 966 /* Multi-number variable-length handlers */
diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index bb3b57bea8ba..5ef7fcf0e250 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -76,8 +76,18 @@ static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
76 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 76 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
77 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 77 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
78 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 78 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
79 int val;
79 80
80 return !!(adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank) & bit); 81 mutex_lock(&kpad->gpio_lock);
82
83 if (kpad->dir[bank] & bit)
84 val = kpad->dat_out[bank];
85 else
86 val = adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank);
87
88 mutex_unlock(&kpad->gpio_lock);
89
90 return !!(val & bit);
81} 91}
82 92
83static void adp5588_gpio_set_value(struct gpio_chip *chip, 93static void adp5588_gpio_set_value(struct gpio_chip *chip,
diff --git a/drivers/input/misc/arizona-haptics.c b/drivers/input/misc/arizona-haptics.c
index 7a04f54ef961..ef2e281b0a43 100644
--- a/drivers/input/misc/arizona-haptics.c
+++ b/drivers/input/misc/arizona-haptics.c
@@ -37,7 +37,6 @@ static void arizona_haptics_work(struct work_struct *work)
37 struct arizona_haptics, 37 struct arizona_haptics,
38 work); 38 work);
39 struct arizona *arizona = haptics->arizona; 39 struct arizona *arizona = haptics->arizona;
40 struct mutex *dapm_mutex = &arizona->dapm->card->dapm_mutex;
41 int ret; 40 int ret;
42 41
43 if (!haptics->arizona->dapm) { 42 if (!haptics->arizona->dapm) {
@@ -67,13 +66,10 @@ static void arizona_haptics_work(struct work_struct *work)
67 return; 66 return;
68 } 67 }
69 68
70 mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
71
72 ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS"); 69 ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS");
73 if (ret != 0) { 70 if (ret != 0) {
74 dev_err(arizona->dev, "Failed to start HAPTICS: %d\n", 71 dev_err(arizona->dev, "Failed to start HAPTICS: %d\n",
75 ret); 72 ret);
76 mutex_unlock(dapm_mutex);
77 return; 73 return;
78 } 74 }
79 75
@@ -81,21 +77,14 @@ static void arizona_haptics_work(struct work_struct *work)
81 if (ret != 0) { 77 if (ret != 0) {
82 dev_err(arizona->dev, "Failed to sync DAPM: %d\n", 78 dev_err(arizona->dev, "Failed to sync DAPM: %d\n",
83 ret); 79 ret);
84 mutex_unlock(dapm_mutex);
85 return; 80 return;
86 } 81 }
87
88 mutex_unlock(dapm_mutex);
89
90 } else { 82 } else {
91 /* This disable sequence will be a noop if already enabled */ 83 /* This disable sequence will be a noop if already enabled */
92 mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
93
94 ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS"); 84 ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS");
95 if (ret != 0) { 85 if (ret != 0) {
96 dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n", 86 dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n",
97 ret); 87 ret);
98 mutex_unlock(dapm_mutex);
99 return; 88 return;
100 } 89 }
101 90
@@ -103,12 +92,9 @@ static void arizona_haptics_work(struct work_struct *work)
103 if (ret != 0) { 92 if (ret != 0) {
104 dev_err(arizona->dev, "Failed to sync DAPM: %d\n", 93 dev_err(arizona->dev, "Failed to sync DAPM: %d\n",
105 ret); 94 ret);
106 mutex_unlock(dapm_mutex);
107 return; 95 return;
108 } 96 }
109 97
110 mutex_unlock(dapm_mutex);
111
112 ret = regmap_update_bits(arizona->regmap, 98 ret = regmap_update_bits(arizona->regmap,
113 ARIZONA_HAPTICS_CONTROL_1, 99 ARIZONA_HAPTICS_CONTROL_1,
114 ARIZONA_HAP_CTRL_MASK, 100 ARIZONA_HAP_CTRL_MASK,
@@ -155,16 +141,11 @@ static int arizona_haptics_play(struct input_dev *input, void *data,
155static void arizona_haptics_close(struct input_dev *input) 141static void arizona_haptics_close(struct input_dev *input)
156{ 142{
157 struct arizona_haptics *haptics = input_get_drvdata(input); 143 struct arizona_haptics *haptics = input_get_drvdata(input);
158 struct mutex *dapm_mutex = &haptics->arizona->dapm->card->dapm_mutex;
159 144
160 cancel_work_sync(&haptics->work); 145 cancel_work_sync(&haptics->work);
161 146
162 mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
163
164 if (haptics->arizona->dapm) 147 if (haptics->arizona->dapm)
165 snd_soc_dapm_disable_pin(haptics->arizona->dapm, "HAPTICS"); 148 snd_soc_dapm_disable_pin(haptics->arizona->dapm, "HAPTICS");
166
167 mutex_unlock(dapm_mutex);
168} 149}
169 150
170static int arizona_haptics_probe(struct platform_device *pdev) 151static int arizona_haptics_probe(struct platform_device *pdev)
diff --git a/drivers/input/misc/da9052_onkey.c b/drivers/input/misc/da9052_onkey.c
index 1f695f229ea8..184c8f21ab59 100644
--- a/drivers/input/misc/da9052_onkey.c
+++ b/drivers/input/misc/da9052_onkey.c
@@ -27,29 +27,32 @@ struct da9052_onkey {
27 27
28static void da9052_onkey_query(struct da9052_onkey *onkey) 28static void da9052_onkey_query(struct da9052_onkey *onkey)
29{ 29{
30 int key_stat; 30 int ret;
31 31
32 key_stat = da9052_reg_read(onkey->da9052, DA9052_EVENT_B_REG); 32 ret = da9052_reg_read(onkey->da9052, DA9052_STATUS_A_REG);
33 if (key_stat < 0) { 33 if (ret < 0) {
34 dev_err(onkey->da9052->dev, 34 dev_err(onkey->da9052->dev,
35 "Failed to read onkey event %d\n", key_stat); 35 "Failed to read onkey event err=%d\n", ret);
36 } else { 36 } else {
37 /* 37 /*
38 * Since interrupt for deassertion of ONKEY pin is not 38 * Since interrupt for deassertion of ONKEY pin is not
39 * generated, onkey event state determines the onkey 39 * generated, onkey event state determines the onkey
40 * button state. 40 * button state.
41 */ 41 */
42 key_stat &= DA9052_EVENTB_ENONKEY; 42 bool pressed = !(ret & DA9052_STATUSA_NONKEY);
43 input_report_key(onkey->input, KEY_POWER, key_stat); 43
44 input_report_key(onkey->input, KEY_POWER, pressed);
44 input_sync(onkey->input); 45 input_sync(onkey->input);
45 }
46 46
47 /* 47 /*
48 * Interrupt is generated only when the ONKEY pin is asserted. 48 * Interrupt is generated only when the ONKEY pin
49 * Hence the deassertion of the pin is simulated through work queue. 49 * is asserted. Hence the deassertion of the pin
50 */ 50 * is simulated through work queue.
51 if (key_stat) 51 */
52 schedule_delayed_work(&onkey->work, msecs_to_jiffies(50)); 52 if (pressed)
53 schedule_delayed_work(&onkey->work,
54 msecs_to_jiffies(50));
55 }
53} 56}
54 57
55static void da9052_onkey_work(struct work_struct *work) 58static void da9052_onkey_work(struct work_struct *work)
diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c
index 87095e2f5153..8af34ffe208b 100644
--- a/drivers/input/mouse/cypress_ps2.c
+++ b/drivers/input/mouse/cypress_ps2.c
@@ -409,7 +409,6 @@ static int cypress_set_input_params(struct input_dev *input,
409 __clear_bit(REL_X, input->relbit); 409 __clear_bit(REL_X, input->relbit);
410 __clear_bit(REL_Y, input->relbit); 410 __clear_bit(REL_Y, input->relbit);
411 411
412 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
413 __set_bit(EV_KEY, input->evbit); 412 __set_bit(EV_KEY, input->evbit);
414 __set_bit(BTN_LEFT, input->keybit); 413 __set_bit(BTN_LEFT, input->keybit);
415 __set_bit(BTN_RIGHT, input->keybit); 414 __set_bit(BTN_RIGHT, input->keybit);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 26386f9d2569..d8d49d10f9bb 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -265,11 +265,22 @@ static int synaptics_identify(struct psmouse *psmouse)
265 * Read touchpad resolution and maximum reported coordinates 265 * Read touchpad resolution and maximum reported coordinates
266 * Resolution is left zero if touchpad does not support the query 266 * Resolution is left zero if touchpad does not support the query
267 */ 267 */
268
269static const int *quirk_min_max;
270
268static int synaptics_resolution(struct psmouse *psmouse) 271static int synaptics_resolution(struct psmouse *psmouse)
269{ 272{
270 struct synaptics_data *priv = psmouse->private; 273 struct synaptics_data *priv = psmouse->private;
271 unsigned char resp[3]; 274 unsigned char resp[3];
272 275
276 if (quirk_min_max) {
277 priv->x_min = quirk_min_max[0];
278 priv->x_max = quirk_min_max[1];
279 priv->y_min = quirk_min_max[2];
280 priv->y_max = quirk_min_max[3];
281 return 0;
282 }
283
273 if (SYN_ID_MAJOR(priv->identity) < 4) 284 if (SYN_ID_MAJOR(priv->identity) < 4)
274 return 0; 285 return 0;
275 286
@@ -1485,10 +1496,54 @@ static const struct dmi_system_id olpc_dmi_table[] __initconst = {
1485 { } 1496 { }
1486}; 1497};
1487 1498
1499static const struct dmi_system_id min_max_dmi_table[] __initconst = {
1500#if defined(CONFIG_DMI)
1501 {
1502 /* Lenovo ThinkPad Helix */
1503 .matches = {
1504 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1505 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Helix"),
1506 },
1507 .driver_data = (int []){1024, 5052, 2258, 4832},
1508 },
1509 {
1510 /* Lenovo ThinkPad X240 */
1511 .matches = {
1512 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1513 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X240"),
1514 },
1515 .driver_data = (int []){1232, 5710, 1156, 4696},
1516 },
1517 {
1518 /* Lenovo ThinkPad T440s */
1519 .matches = {
1520 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1521 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T440"),
1522 },
1523 .driver_data = (int []){1024, 5112, 2024, 4832},
1524 },
1525 {
1526 /* Lenovo ThinkPad T540p */
1527 .matches = {
1528 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1529 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T540"),
1530 },
1531 .driver_data = (int []){1024, 5056, 2058, 4832},
1532 },
1533#endif
1534 { }
1535};
1536
1488void __init synaptics_module_init(void) 1537void __init synaptics_module_init(void)
1489{ 1538{
1539 const struct dmi_system_id *min_max_dmi;
1540
1490 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table); 1541 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
1491 broken_olpc_ec = dmi_check_system(olpc_dmi_table); 1542 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
1543
1544 min_max_dmi = dmi_first_match(min_max_dmi_table);
1545 if (min_max_dmi)
1546 quirk_min_max = min_max_dmi->driver_data;
1492} 1547}
1493 1548
1494static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode) 1549static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 4c842c320c2e..b604564dec5c 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -67,7 +67,6 @@ struct mousedev {
67 struct device dev; 67 struct device dev;
68 struct cdev cdev; 68 struct cdev cdev;
69 bool exist; 69 bool exist;
70 bool is_mixdev;
71 70
72 struct list_head mixdev_node; 71 struct list_head mixdev_node;
73 bool opened_by_mixdev; 72 bool opened_by_mixdev;
@@ -77,6 +76,9 @@ struct mousedev {
77 int old_x[4], old_y[4]; 76 int old_x[4], old_y[4];
78 int frac_dx, frac_dy; 77 int frac_dx, frac_dy;
79 unsigned long touch; 78 unsigned long touch;
79
80 int (*open_device)(struct mousedev *mousedev);
81 void (*close_device)(struct mousedev *mousedev);
80}; 82};
81 83
82enum mousedev_emul { 84enum mousedev_emul {
@@ -116,9 +118,6 @@ static unsigned char mousedev_imex_seq[] = { 0xf3, 200, 0xf3, 200, 0xf3, 80 };
116static struct mousedev *mousedev_mix; 118static struct mousedev *mousedev_mix;
117static LIST_HEAD(mousedev_mix_list); 119static LIST_HEAD(mousedev_mix_list);
118 120
119static void mixdev_open_devices(void);
120static void mixdev_close_devices(void);
121
122#define fx(i) (mousedev->old_x[(mousedev->pkt_count - (i)) & 03]) 121#define fx(i) (mousedev->old_x[(mousedev->pkt_count - (i)) & 03])
123#define fy(i) (mousedev->old_y[(mousedev->pkt_count - (i)) & 03]) 122#define fy(i) (mousedev->old_y[(mousedev->pkt_count - (i)) & 03])
124 123
@@ -428,9 +427,7 @@ static int mousedev_open_device(struct mousedev *mousedev)
428 if (retval) 427 if (retval)
429 return retval; 428 return retval;
430 429
431 if (mousedev->is_mixdev) 430 if (!mousedev->exist)
432 mixdev_open_devices();
433 else if (!mousedev->exist)
434 retval = -ENODEV; 431 retval = -ENODEV;
435 else if (!mousedev->open++) { 432 else if (!mousedev->open++) {
436 retval = input_open_device(&mousedev->handle); 433 retval = input_open_device(&mousedev->handle);
@@ -446,9 +443,7 @@ static void mousedev_close_device(struct mousedev *mousedev)
446{ 443{
447 mutex_lock(&mousedev->mutex); 444 mutex_lock(&mousedev->mutex);
448 445
449 if (mousedev->is_mixdev) 446 if (mousedev->exist && !--mousedev->open)
450 mixdev_close_devices();
451 else if (mousedev->exist && !--mousedev->open)
452 input_close_device(&mousedev->handle); 447 input_close_device(&mousedev->handle);
453 448
454 mutex_unlock(&mousedev->mutex); 449 mutex_unlock(&mousedev->mutex);
@@ -459,21 +454,29 @@ static void mousedev_close_device(struct mousedev *mousedev)
459 * stream. Note that this function is called with mousedev_mix->mutex 454 * stream. Note that this function is called with mousedev_mix->mutex
460 * held. 455 * held.
461 */ 456 */
462static void mixdev_open_devices(void) 457static int mixdev_open_devices(struct mousedev *mixdev)
463{ 458{
464 struct mousedev *mousedev; 459 int error;
460
461 error = mutex_lock_interruptible(&mixdev->mutex);
462 if (error)
463 return error;
465 464
466 if (mousedev_mix->open++) 465 if (!mixdev->open++) {
467 return; 466 struct mousedev *mousedev;
468 467
469 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) { 468 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
470 if (!mousedev->opened_by_mixdev) { 469 if (!mousedev->opened_by_mixdev) {
471 if (mousedev_open_device(mousedev)) 470 if (mousedev_open_device(mousedev))
472 continue; 471 continue;
473 472
474 mousedev->opened_by_mixdev = true; 473 mousedev->opened_by_mixdev = true;
474 }
475 } 475 }
476 } 476 }
477
478 mutex_unlock(&mixdev->mutex);
479 return 0;
477} 480}
478 481
479/* 482/*
@@ -481,19 +484,22 @@ static void mixdev_open_devices(void)
481 * device. Note that this function is called with mousedev_mix->mutex 484 * device. Note that this function is called with mousedev_mix->mutex
482 * held. 485 * held.
483 */ 486 */
484static void mixdev_close_devices(void) 487static void mixdev_close_devices(struct mousedev *mixdev)
485{ 488{
486 struct mousedev *mousedev; 489 mutex_lock(&mixdev->mutex);
487 490
488 if (--mousedev_mix->open) 491 if (!--mixdev->open) {
489 return; 492 struct mousedev *mousedev;
490 493
491 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) { 494 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
492 if (mousedev->opened_by_mixdev) { 495 if (mousedev->opened_by_mixdev) {
493 mousedev->opened_by_mixdev = false; 496 mousedev->opened_by_mixdev = false;
494 mousedev_close_device(mousedev); 497 mousedev_close_device(mousedev);
498 }
495 } 499 }
496 } 500 }
501
502 mutex_unlock(&mixdev->mutex);
497} 503}
498 504
499 505
@@ -522,7 +528,7 @@ static int mousedev_release(struct inode *inode, struct file *file)
522 mousedev_detach_client(mousedev, client); 528 mousedev_detach_client(mousedev, client);
523 kfree(client); 529 kfree(client);
524 530
525 mousedev_close_device(mousedev); 531 mousedev->close_device(mousedev);
526 532
527 return 0; 533 return 0;
528} 534}
@@ -550,7 +556,7 @@ static int mousedev_open(struct inode *inode, struct file *file)
550 client->mousedev = mousedev; 556 client->mousedev = mousedev;
551 mousedev_attach_client(mousedev, client); 557 mousedev_attach_client(mousedev, client);
552 558
553 error = mousedev_open_device(mousedev); 559 error = mousedev->open_device(mousedev);
554 if (error) 560 if (error)
555 goto err_free_client; 561 goto err_free_client;
556 562
@@ -861,16 +867,21 @@ static struct mousedev *mousedev_create(struct input_dev *dev,
861 867
862 if (mixdev) { 868 if (mixdev) {
863 dev_set_name(&mousedev->dev, "mice"); 869 dev_set_name(&mousedev->dev, "mice");
870
871 mousedev->open_device = mixdev_open_devices;
872 mousedev->close_device = mixdev_close_devices;
864 } else { 873 } else {
865 int dev_no = minor; 874 int dev_no = minor;
866 /* Normalize device number if it falls into legacy range */ 875 /* Normalize device number if it falls into legacy range */
867 if (dev_no < MOUSEDEV_MINOR_BASE + MOUSEDEV_MINORS) 876 if (dev_no < MOUSEDEV_MINOR_BASE + MOUSEDEV_MINORS)
868 dev_no -= MOUSEDEV_MINOR_BASE; 877 dev_no -= MOUSEDEV_MINOR_BASE;
869 dev_set_name(&mousedev->dev, "mouse%d", dev_no); 878 dev_set_name(&mousedev->dev, "mouse%d", dev_no);
879
880 mousedev->open_device = mousedev_open_device;
881 mousedev->close_device = mousedev_close_device;
870 } 882 }
871 883
872 mousedev->exist = true; 884 mousedev->exist = true;
873 mousedev->is_mixdev = mixdev;
874 mousedev->handle.dev = input_get_device(dev); 885 mousedev->handle.dev = input_get_device(dev);
875 mousedev->handle.name = dev_name(&mousedev->dev); 886 mousedev->handle.name = dev_name(&mousedev->dev);
876 mousedev->handle.handler = handler; 887 mousedev->handle.handler = handler;
@@ -919,7 +930,7 @@ static void mousedev_destroy(struct mousedev *mousedev)
919 device_del(&mousedev->dev); 930 device_del(&mousedev->dev);
920 mousedev_cleanup(mousedev); 931 mousedev_cleanup(mousedev);
921 input_free_minor(MINOR(mousedev->dev.devt)); 932 input_free_minor(MINOR(mousedev->dev.devt));
922 if (!mousedev->is_mixdev) 933 if (mousedev != mousedev_mix)
923 input_unregister_handle(&mousedev->handle); 934 input_unregister_handle(&mousedev->handle);
924 put_device(&mousedev->dev); 935 put_device(&mousedev->dev);
925} 936}
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 8911850c9444..1d9ab39af29f 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -79,7 +79,6 @@
79 79
80#define ARM_SMMU_PTE_CONT_SIZE (PAGE_SIZE * ARM_SMMU_PTE_CONT_ENTRIES) 80#define ARM_SMMU_PTE_CONT_SIZE (PAGE_SIZE * ARM_SMMU_PTE_CONT_ENTRIES)
81#define ARM_SMMU_PTE_CONT_MASK (~(ARM_SMMU_PTE_CONT_SIZE - 1)) 81#define ARM_SMMU_PTE_CONT_MASK (~(ARM_SMMU_PTE_CONT_SIZE - 1))
82#define ARM_SMMU_PTE_HWTABLE_SIZE (PTRS_PER_PTE * sizeof(pte_t))
83 82
84/* Stage-1 PTE */ 83/* Stage-1 PTE */
85#define ARM_SMMU_PTE_AP_UNPRIV (((pteval_t)1) << 6) 84#define ARM_SMMU_PTE_AP_UNPRIV (((pteval_t)1) << 6)
@@ -191,6 +190,9 @@
191#define ARM_SMMU_GR1_CBAR(n) (0x0 + ((n) << 2)) 190#define ARM_SMMU_GR1_CBAR(n) (0x0 + ((n) << 2))
192#define CBAR_VMID_SHIFT 0 191#define CBAR_VMID_SHIFT 0
193#define CBAR_VMID_MASK 0xff 192#define CBAR_VMID_MASK 0xff
193#define CBAR_S1_BPSHCFG_SHIFT 8
194#define CBAR_S1_BPSHCFG_MASK 3
195#define CBAR_S1_BPSHCFG_NSH 3
194#define CBAR_S1_MEMATTR_SHIFT 12 196#define CBAR_S1_MEMATTR_SHIFT 12
195#define CBAR_S1_MEMATTR_MASK 0xf 197#define CBAR_S1_MEMATTR_MASK 0xf
196#define CBAR_S1_MEMATTR_WB 0xf 198#define CBAR_S1_MEMATTR_WB 0xf
@@ -393,7 +395,7 @@ struct arm_smmu_domain {
393 struct arm_smmu_cfg root_cfg; 395 struct arm_smmu_cfg root_cfg;
394 phys_addr_t output_mask; 396 phys_addr_t output_mask;
395 397
396 struct mutex lock; 398 spinlock_t lock;
397}; 399};
398 400
399static DEFINE_SPINLOCK(arm_smmu_devices_lock); 401static DEFINE_SPINLOCK(arm_smmu_devices_lock);
@@ -632,6 +634,28 @@ static irqreturn_t arm_smmu_global_fault(int irq, void *dev)
632 return IRQ_HANDLED; 634 return IRQ_HANDLED;
633} 635}
634 636
637static void arm_smmu_flush_pgtable(struct arm_smmu_device *smmu, void *addr,
638 size_t size)
639{
640 unsigned long offset = (unsigned long)addr & ~PAGE_MASK;
641
642
643 /* Ensure new page tables are visible to the hardware walker */
644 if (smmu->features & ARM_SMMU_FEAT_COHERENT_WALK) {
645 dsb();
646 } else {
647 /*
648 * If the SMMU can't walk tables in the CPU caches, treat them
649 * like non-coherent DMA since we need to flush the new entries
650 * all the way out to memory. There's no possibility of
651 * recursion here as the SMMU table walker will not be wired
652 * through another SMMU.
653 */
654 dma_map_page(smmu->dev, virt_to_page(addr), offset, size,
655 DMA_TO_DEVICE);
656 }
657}
658
635static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain) 659static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain)
636{ 660{
637 u32 reg; 661 u32 reg;
@@ -650,11 +674,16 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain)
650 if (smmu->version == 1) 674 if (smmu->version == 1)
651 reg |= root_cfg->irptndx << CBAR_IRPTNDX_SHIFT; 675 reg |= root_cfg->irptndx << CBAR_IRPTNDX_SHIFT;
652 676
653 /* Use the weakest memory type, so it is overridden by the pte */ 677 /*
654 if (stage1) 678 * Use the weakest shareability/memory types, so they are
655 reg |= (CBAR_S1_MEMATTR_WB << CBAR_S1_MEMATTR_SHIFT); 679 * overridden by the ttbcr/pte.
656 else 680 */
681 if (stage1) {
682 reg |= (CBAR_S1_BPSHCFG_NSH << CBAR_S1_BPSHCFG_SHIFT) |
683 (CBAR_S1_MEMATTR_WB << CBAR_S1_MEMATTR_SHIFT);
684 } else {
657 reg |= ARM_SMMU_CB_VMID(root_cfg) << CBAR_VMID_SHIFT; 685 reg |= ARM_SMMU_CB_VMID(root_cfg) << CBAR_VMID_SHIFT;
686 }
658 writel_relaxed(reg, gr1_base + ARM_SMMU_GR1_CBAR(root_cfg->cbndx)); 687 writel_relaxed(reg, gr1_base + ARM_SMMU_GR1_CBAR(root_cfg->cbndx));
659 688
660 if (smmu->version > 1) { 689 if (smmu->version > 1) {
@@ -715,6 +744,8 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain)
715 } 744 }
716 745
717 /* TTBR0 */ 746 /* TTBR0 */
747 arm_smmu_flush_pgtable(smmu, root_cfg->pgd,
748 PTRS_PER_PGD * sizeof(pgd_t));
718 reg = __pa(root_cfg->pgd); 749 reg = __pa(root_cfg->pgd);
719 writel_relaxed(reg, cb_base + ARM_SMMU_CB_TTBR0_LO); 750 writel_relaxed(reg, cb_base + ARM_SMMU_CB_TTBR0_LO);
720 reg = (phys_addr_t)__pa(root_cfg->pgd) >> 32; 751 reg = (phys_addr_t)__pa(root_cfg->pgd) >> 32;
@@ -901,7 +932,7 @@ static int arm_smmu_domain_init(struct iommu_domain *domain)
901 goto out_free_domain; 932 goto out_free_domain;
902 smmu_domain->root_cfg.pgd = pgd; 933 smmu_domain->root_cfg.pgd = pgd;
903 934
904 mutex_init(&smmu_domain->lock); 935 spin_lock_init(&smmu_domain->lock);
905 domain->priv = smmu_domain; 936 domain->priv = smmu_domain;
906 return 0; 937 return 0;
907 938
@@ -1128,6 +1159,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1128 struct arm_smmu_domain *smmu_domain = domain->priv; 1159 struct arm_smmu_domain *smmu_domain = domain->priv;
1129 struct arm_smmu_device *device_smmu = dev->archdata.iommu; 1160 struct arm_smmu_device *device_smmu = dev->archdata.iommu;
1130 struct arm_smmu_master *master; 1161 struct arm_smmu_master *master;
1162 unsigned long flags;
1131 1163
1132 if (!device_smmu) { 1164 if (!device_smmu) {
1133 dev_err(dev, "cannot attach to SMMU, is it on the same bus?\n"); 1165 dev_err(dev, "cannot attach to SMMU, is it on the same bus?\n");
@@ -1138,7 +1170,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1138 * Sanity check the domain. We don't currently support domains 1170 * Sanity check the domain. We don't currently support domains
1139 * that cross between different SMMU chains. 1171 * that cross between different SMMU chains.
1140 */ 1172 */
1141 mutex_lock(&smmu_domain->lock); 1173 spin_lock_irqsave(&smmu_domain->lock, flags);
1142 if (!smmu_domain->leaf_smmu) { 1174 if (!smmu_domain->leaf_smmu) {
1143 /* Now that we have a master, we can finalise the domain */ 1175 /* Now that we have a master, we can finalise the domain */
1144 ret = arm_smmu_init_domain_context(domain, dev); 1176 ret = arm_smmu_init_domain_context(domain, dev);
@@ -1153,7 +1185,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1153 dev_name(device_smmu->dev)); 1185 dev_name(device_smmu->dev));
1154 goto err_unlock; 1186 goto err_unlock;
1155 } 1187 }
1156 mutex_unlock(&smmu_domain->lock); 1188 spin_unlock_irqrestore(&smmu_domain->lock, flags);
1157 1189
1158 /* Looks ok, so add the device to the domain */ 1190 /* Looks ok, so add the device to the domain */
1159 master = find_smmu_master(smmu_domain->leaf_smmu, dev->of_node); 1191 master = find_smmu_master(smmu_domain->leaf_smmu, dev->of_node);
@@ -1163,7 +1195,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1163 return arm_smmu_domain_add_master(smmu_domain, master); 1195 return arm_smmu_domain_add_master(smmu_domain, master);
1164 1196
1165err_unlock: 1197err_unlock:
1166 mutex_unlock(&smmu_domain->lock); 1198 spin_unlock_irqrestore(&smmu_domain->lock, flags);
1167 return ret; 1199 return ret;
1168} 1200}
1169 1201
@@ -1177,23 +1209,6 @@ static void arm_smmu_detach_dev(struct iommu_domain *domain, struct device *dev)
1177 arm_smmu_domain_remove_master(smmu_domain, master); 1209 arm_smmu_domain_remove_master(smmu_domain, master);
1178} 1210}
1179 1211
1180static void arm_smmu_flush_pgtable(struct arm_smmu_device *smmu, void *addr,
1181 size_t size)
1182{
1183 unsigned long offset = (unsigned long)addr & ~PAGE_MASK;
1184
1185 /*
1186 * If the SMMU can't walk tables in the CPU caches, treat them
1187 * like non-coherent DMA since we need to flush the new entries
1188 * all the way out to memory. There's no possibility of recursion
1189 * here as the SMMU table walker will not be wired through another
1190 * SMMU.
1191 */
1192 if (!(smmu->features & ARM_SMMU_FEAT_COHERENT_WALK))
1193 dma_map_page(smmu->dev, virt_to_page(addr), offset, size,
1194 DMA_TO_DEVICE);
1195}
1196
1197static bool arm_smmu_pte_is_contiguous_range(unsigned long addr, 1212static bool arm_smmu_pte_is_contiguous_range(unsigned long addr,
1198 unsigned long end) 1213 unsigned long end)
1199{ 1214{
@@ -1210,12 +1225,11 @@ static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd,
1210 1225
1211 if (pmd_none(*pmd)) { 1226 if (pmd_none(*pmd)) {
1212 /* Allocate a new set of tables */ 1227 /* Allocate a new set of tables */
1213 pgtable_t table = alloc_page(PGALLOC_GFP); 1228 pgtable_t table = alloc_page(GFP_ATOMIC|__GFP_ZERO);
1214 if (!table) 1229 if (!table)
1215 return -ENOMEM; 1230 return -ENOMEM;
1216 1231
1217 arm_smmu_flush_pgtable(smmu, page_address(table), 1232 arm_smmu_flush_pgtable(smmu, page_address(table), PAGE_SIZE);
1218 ARM_SMMU_PTE_HWTABLE_SIZE);
1219 if (!pgtable_page_ctor(table)) { 1233 if (!pgtable_page_ctor(table)) {
1220 __free_page(table); 1234 __free_page(table);
1221 return -ENOMEM; 1235 return -ENOMEM;
@@ -1317,9 +1331,15 @@ static int arm_smmu_alloc_init_pmd(struct arm_smmu_device *smmu, pud_t *pud,
1317 1331
1318#ifndef __PAGETABLE_PMD_FOLDED 1332#ifndef __PAGETABLE_PMD_FOLDED
1319 if (pud_none(*pud)) { 1333 if (pud_none(*pud)) {
1320 pmd = pmd_alloc_one(NULL, addr); 1334 pmd = (pmd_t *)get_zeroed_page(GFP_ATOMIC);
1321 if (!pmd) 1335 if (!pmd)
1322 return -ENOMEM; 1336 return -ENOMEM;
1337
1338 arm_smmu_flush_pgtable(smmu, pmd, PAGE_SIZE);
1339 pud_populate(NULL, pud, pmd);
1340 arm_smmu_flush_pgtable(smmu, pud, sizeof(*pud));
1341
1342 pmd += pmd_index(addr);
1323 } else 1343 } else
1324#endif 1344#endif
1325 pmd = pmd_offset(pud, addr); 1345 pmd = pmd_offset(pud, addr);
@@ -1328,8 +1348,6 @@ static int arm_smmu_alloc_init_pmd(struct arm_smmu_device *smmu, pud_t *pud,
1328 next = pmd_addr_end(addr, end); 1348 next = pmd_addr_end(addr, end);
1329 ret = arm_smmu_alloc_init_pte(smmu, pmd, addr, end, pfn, 1349 ret = arm_smmu_alloc_init_pte(smmu, pmd, addr, end, pfn,
1330 flags, stage); 1350 flags, stage);
1331 pud_populate(NULL, pud, pmd);
1332 arm_smmu_flush_pgtable(smmu, pud, sizeof(*pud));
1333 phys += next - addr; 1351 phys += next - addr;
1334 } while (pmd++, addr = next, addr < end); 1352 } while (pmd++, addr = next, addr < end);
1335 1353
@@ -1346,9 +1364,15 @@ static int arm_smmu_alloc_init_pud(struct arm_smmu_device *smmu, pgd_t *pgd,
1346 1364
1347#ifndef __PAGETABLE_PUD_FOLDED 1365#ifndef __PAGETABLE_PUD_FOLDED
1348 if (pgd_none(*pgd)) { 1366 if (pgd_none(*pgd)) {
1349 pud = pud_alloc_one(NULL, addr); 1367 pud = (pud_t *)get_zeroed_page(GFP_ATOMIC);
1350 if (!pud) 1368 if (!pud)
1351 return -ENOMEM; 1369 return -ENOMEM;
1370
1371 arm_smmu_flush_pgtable(smmu, pud, PAGE_SIZE);
1372 pgd_populate(NULL, pgd, pud);
1373 arm_smmu_flush_pgtable(smmu, pgd, sizeof(*pgd));
1374
1375 pud += pud_index(addr);
1352 } else 1376 } else
1353#endif 1377#endif
1354 pud = pud_offset(pgd, addr); 1378 pud = pud_offset(pgd, addr);
@@ -1357,8 +1381,6 @@ static int arm_smmu_alloc_init_pud(struct arm_smmu_device *smmu, pgd_t *pgd,
1357 next = pud_addr_end(addr, end); 1381 next = pud_addr_end(addr, end);
1358 ret = arm_smmu_alloc_init_pmd(smmu, pud, addr, next, phys, 1382 ret = arm_smmu_alloc_init_pmd(smmu, pud, addr, next, phys,
1359 flags, stage); 1383 flags, stage);
1360 pgd_populate(NULL, pud, pgd);
1361 arm_smmu_flush_pgtable(smmu, pgd, sizeof(*pgd));
1362 phys += next - addr; 1384 phys += next - addr;
1363 } while (pud++, addr = next, addr < end); 1385 } while (pud++, addr = next, addr < end);
1364 1386
@@ -1375,6 +1397,7 @@ static int arm_smmu_handle_mapping(struct arm_smmu_domain *smmu_domain,
1375 struct arm_smmu_cfg *root_cfg = &smmu_domain->root_cfg; 1397 struct arm_smmu_cfg *root_cfg = &smmu_domain->root_cfg;
1376 pgd_t *pgd = root_cfg->pgd; 1398 pgd_t *pgd = root_cfg->pgd;
1377 struct arm_smmu_device *smmu = root_cfg->smmu; 1399 struct arm_smmu_device *smmu = root_cfg->smmu;
1400 unsigned long irqflags;
1378 1401
1379 if (root_cfg->cbar == CBAR_TYPE_S2_TRANS) { 1402 if (root_cfg->cbar == CBAR_TYPE_S2_TRANS) {
1380 stage = 2; 1403 stage = 2;
@@ -1397,7 +1420,7 @@ static int arm_smmu_handle_mapping(struct arm_smmu_domain *smmu_domain,
1397 if (paddr & ~output_mask) 1420 if (paddr & ~output_mask)
1398 return -ERANGE; 1421 return -ERANGE;
1399 1422
1400 mutex_lock(&smmu_domain->lock); 1423 spin_lock_irqsave(&smmu_domain->lock, irqflags);
1401 pgd += pgd_index(iova); 1424 pgd += pgd_index(iova);
1402 end = iova + size; 1425 end = iova + size;
1403 do { 1426 do {
@@ -1413,11 +1436,7 @@ static int arm_smmu_handle_mapping(struct arm_smmu_domain *smmu_domain,
1413 } while (pgd++, iova != end); 1436 } while (pgd++, iova != end);
1414 1437
1415out_unlock: 1438out_unlock:
1416 mutex_unlock(&smmu_domain->lock); 1439 spin_unlock_irqrestore(&smmu_domain->lock, irqflags);
1417
1418 /* Ensure new page tables are visible to the hardware walker */
1419 if (smmu->features & ARM_SMMU_FEAT_COHERENT_WALK)
1420 dsb();
1421 1440
1422 return ret; 1441 return ret;
1423} 1442}
@@ -1987,8 +2006,10 @@ static int __init arm_smmu_init(void)
1987 if (!iommu_present(&platform_bus_type)) 2006 if (!iommu_present(&platform_bus_type))
1988 bus_set_iommu(&platform_bus_type, &arm_smmu_ops); 2007 bus_set_iommu(&platform_bus_type, &arm_smmu_ops);
1989 2008
2009#ifdef CONFIG_ARM_AMBA
1990 if (!iommu_present(&amba_bustype)) 2010 if (!iommu_present(&amba_bustype))
1991 bus_set_iommu(&amba_bustype, &arm_smmu_ops); 2011 bus_set_iommu(&amba_bustype, &arm_smmu_ops);
2012#endif
1992 2013
1993 return 0; 2014 return 0;
1994} 2015}
diff --git a/drivers/iommu/omap-iommu-debug.c b/drivers/iommu/omap-iommu-debug.c
index d97fbe4fb9b1..80fffba7f12d 100644
--- a/drivers/iommu/omap-iommu-debug.c
+++ b/drivers/iommu/omap-iommu-debug.c
@@ -354,8 +354,8 @@ DEBUG_FOPS(mem);
354 return -ENOMEM; \ 354 return -ENOMEM; \
355 } 355 }
356 356
357#define DEBUG_ADD_FILE(name) __DEBUG_ADD_FILE(name, 600) 357#define DEBUG_ADD_FILE(name) __DEBUG_ADD_FILE(name, 0600)
358#define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 400) 358#define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400)
359 359
360static int iommu_debug_register(struct device *dev, void *data) 360static int iommu_debug_register(struct device *dev, void *data)
361{ 361{
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 86b484cb3ec2..5194afb39e78 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_SIRF_IRQ) += irq-sirfsoc.o
21obj-$(CONFIG_RENESAS_INTC_IRQPIN) += irq-renesas-intc-irqpin.o 21obj-$(CONFIG_RENESAS_INTC_IRQPIN) += irq-renesas-intc-irqpin.o
22obj-$(CONFIG_RENESAS_IRQC) += irq-renesas-irqc.o 22obj-$(CONFIG_RENESAS_IRQC) += irq-renesas-irqc.o
23obj-$(CONFIG_VERSATILE_FPGA_IRQ) += irq-versatile-fpga.o 23obj-$(CONFIG_VERSATILE_FPGA_IRQ) += irq-versatile-fpga.o
24obj-$(CONFIG_ARCH_NSPIRE) += irq-zevio.o
24obj-$(CONFIG_ARCH_VT8500) += irq-vt8500.o 25obj-$(CONFIG_ARCH_VT8500) += irq-vt8500.o
25obj-$(CONFIG_TB10X_IRQC) += irq-tb10x.o 26obj-$(CONFIG_TB10X_IRQC) += irq-tb10x.o
26obj-$(CONFIG_XTENSA) += irq-xtensa-pic.o 27obj-$(CONFIG_XTENSA) += irq-xtensa-pic.o
diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c
index 9300bc32784e..540956465ed2 100644
--- a/drivers/irqchip/irq-armada-370-xp.c
+++ b/drivers/irqchip/irq-armada-370-xp.c
@@ -381,7 +381,7 @@ armada_370_xp_handle_irq(struct pt_regs *regs)
381 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) 381 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
382 & PCI_MSI_DOORBELL_MASK; 382 & PCI_MSI_DOORBELL_MASK;
383 383
384 writel(~PCI_MSI_DOORBELL_MASK, per_cpu_int_base + 384 writel(~msimask, per_cpu_int_base +
385 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); 385 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
386 386
387 for (msinr = PCI_MSI_DOORBELL_START; 387 for (msinr = PCI_MSI_DOORBELL_START;
@@ -407,7 +407,7 @@ armada_370_xp_handle_irq(struct pt_regs *regs)
407 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) 407 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
408 & IPI_DOORBELL_MASK; 408 & IPI_DOORBELL_MASK;
409 409
410 writel(~IPI_DOORBELL_MASK, per_cpu_int_base + 410 writel(~ipimask, per_cpu_int_base +
411 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); 411 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
412 412
413 /* Handle all pending doorbells */ 413 /* Handle all pending doorbells */
diff --git a/drivers/irqchip/irq-metag-ext.c b/drivers/irqchip/irq-metag-ext.c
index 92c41ab4dbfd..2cb474ad8809 100644
--- a/drivers/irqchip/irq-metag-ext.c
+++ b/drivers/irqchip/irq-metag-ext.c
@@ -515,7 +515,7 @@ static int meta_intc_set_affinity(struct irq_data *data,
515 * one cpu (the interrupt code doesn't support it), so we just 515 * one cpu (the interrupt code doesn't support it), so we just
516 * pick the first cpu we find in 'cpumask'. 516 * pick the first cpu we find in 'cpumask'.
517 */ 517 */
518 cpu = cpumask_any(cpumask); 518 cpu = cpumask_any_and(cpumask, cpu_online_mask);
519 thread = cpu_2_hwthread_id[cpu]; 519 thread = cpu_2_hwthread_id[cpu];
520 520
521 metag_out32(TBI_TRIG_VEC(TBID_SIGNUM_TR2(thread)), vec_addr); 521 metag_out32(TBI_TRIG_VEC(TBID_SIGNUM_TR2(thread)), vec_addr);
diff --git a/drivers/irqchip/irq-metag.c b/drivers/irqchip/irq-metag.c
index 8e94d7a3b20d..c16c186d97d3 100644
--- a/drivers/irqchip/irq-metag.c
+++ b/drivers/irqchip/irq-metag.c
@@ -201,7 +201,7 @@ static int metag_internal_irq_set_affinity(struct irq_data *data,
201 * one cpu (the interrupt code doesn't support it), so we just 201 * one cpu (the interrupt code doesn't support it), so we just
202 * pick the first cpu we find in 'cpumask'. 202 * pick the first cpu we find in 'cpumask'.
203 */ 203 */
204 cpu = cpumask_any(cpumask); 204 cpu = cpumask_any_and(cpumask, cpu_online_mask);
205 thread = cpu_2_hwthread_id[cpu]; 205 thread = cpu_2_hwthread_id[cpu];
206 206
207 metag_out32(TBI_TRIG_VEC(TBID_SIGNUM_TR1(thread)), 207 metag_out32(TBI_TRIG_VEC(TBID_SIGNUM_TR1(thread)),
diff --git a/drivers/irqchip/irq-orion.c b/drivers/irqchip/irq-orion.c
index e51d40031884..8e41be62812e 100644
--- a/drivers/irqchip/irq-orion.c
+++ b/drivers/irqchip/irq-orion.c
@@ -111,7 +111,8 @@ IRQCHIP_DECLARE(orion_intc, "marvell,orion-intc", orion_irq_init);
111static void orion_bridge_irq_handler(unsigned int irq, struct irq_desc *desc) 111static void orion_bridge_irq_handler(unsigned int irq, struct irq_desc *desc)
112{ 112{
113 struct irq_domain *d = irq_get_handler_data(irq); 113 struct irq_domain *d = irq_get_handler_data(irq);
114 struct irq_chip_generic *gc = irq_get_domain_generic_chip(d, irq); 114
115 struct irq_chip_generic *gc = irq_get_domain_generic_chip(d, 0);
115 u32 stat = readl_relaxed(gc->reg_base + ORION_BRIDGE_IRQ_CAUSE) & 116 u32 stat = readl_relaxed(gc->reg_base + ORION_BRIDGE_IRQ_CAUSE) &
116 gc->mask_cache; 117 gc->mask_cache;
117 118
@@ -123,6 +124,19 @@ static void orion_bridge_irq_handler(unsigned int irq, struct irq_desc *desc)
123 } 124 }
124} 125}
125 126
127/*
128 * Bridge IRQ_CAUSE is asserted regardless of IRQ_MASK register.
129 * To avoid interrupt events on stale irqs, we clear them before unmask.
130 */
131static unsigned int orion_bridge_irq_startup(struct irq_data *d)
132{
133 struct irq_chip_type *ct = irq_data_get_chip_type(d);
134
135 ct->chip.irq_ack(d);
136 ct->chip.irq_unmask(d);
137 return 0;
138}
139
126static int __init orion_bridge_irq_init(struct device_node *np, 140static int __init orion_bridge_irq_init(struct device_node *np,
127 struct device_node *parent) 141 struct device_node *parent)
128{ 142{
@@ -143,7 +157,7 @@ static int __init orion_bridge_irq_init(struct device_node *np,
143 } 157 }
144 158
145 ret = irq_alloc_domain_generic_chips(domain, nrirqs, 1, np->name, 159 ret = irq_alloc_domain_generic_chips(domain, nrirqs, 1, np->name,
146 handle_level_irq, clr, 0, IRQ_GC_INIT_MASK_CACHE); 160 handle_edge_irq, clr, 0, IRQ_GC_INIT_MASK_CACHE);
147 if (ret) { 161 if (ret) {
148 pr_err("%s: unable to alloc irq domain gc\n", np->name); 162 pr_err("%s: unable to alloc irq domain gc\n", np->name);
149 return ret; 163 return ret;
@@ -176,12 +190,14 @@ static int __init orion_bridge_irq_init(struct device_node *np,
176 190
177 gc->chip_types[0].regs.ack = ORION_BRIDGE_IRQ_CAUSE; 191 gc->chip_types[0].regs.ack = ORION_BRIDGE_IRQ_CAUSE;
178 gc->chip_types[0].regs.mask = ORION_BRIDGE_IRQ_MASK; 192 gc->chip_types[0].regs.mask = ORION_BRIDGE_IRQ_MASK;
193 gc->chip_types[0].chip.irq_startup = orion_bridge_irq_startup;
179 gc->chip_types[0].chip.irq_ack = irq_gc_ack_clr_bit; 194 gc->chip_types[0].chip.irq_ack = irq_gc_ack_clr_bit;
180 gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit; 195 gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit;
181 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit; 196 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit;
182 197
183 /* mask all interrupts */ 198 /* mask and clear all interrupts */
184 writel(0, gc->reg_base + ORION_BRIDGE_IRQ_MASK); 199 writel(0, gc->reg_base + ORION_BRIDGE_IRQ_MASK);
200 writel(0, gc->reg_base + ORION_BRIDGE_IRQ_CAUSE);
185 201
186 irq_set_handler_data(irq, domain); 202 irq_set_handler_data(irq, domain);
187 irq_set_chained_handler(irq, orion_bridge_irq_handler); 203 irq_set_chained_handler(irq, orion_bridge_irq_handler);
diff --git a/drivers/irqchip/irq-zevio.c b/drivers/irqchip/irq-zevio.c
new file mode 100644
index 000000000000..8ed04c4a43ee
--- /dev/null
+++ b/drivers/irqchip/irq-zevio.c
@@ -0,0 +1,127 @@
1/*
2 * linux/drivers/irqchip/irq-zevio.c
3 *
4 * Copyright (C) 2013 Daniel Tang <tangrs@tangrs.id.au>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/io.h>
13#include <linux/irq.h>
14#include <linux/of.h>
15#include <linux/of_address.h>
16#include <linux/of_irq.h>
17
18#include <asm/mach/irq.h>
19#include <asm/exception.h>
20
21#include "irqchip.h"
22
23#define IO_STATUS 0x000
24#define IO_RAW_STATUS 0x004
25#define IO_ENABLE 0x008
26#define IO_DISABLE 0x00C
27#define IO_CURRENT 0x020
28#define IO_RESET 0x028
29#define IO_MAX_PRIOTY 0x02C
30
31#define IO_IRQ_BASE 0x000
32#define IO_FIQ_BASE 0x100
33
34#define IO_INVERT_SEL 0x200
35#define IO_STICKY_SEL 0x204
36#define IO_PRIORITY_SEL 0x300
37
38#define MAX_INTRS 32
39#define FIQ_START MAX_INTRS
40
41static struct irq_domain *zevio_irq_domain;
42static void __iomem *zevio_irq_io;
43
44static void zevio_irq_ack(struct irq_data *irqd)
45{
46 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(irqd);
47 struct irq_chip_regs *regs =
48 &container_of(irqd->chip, struct irq_chip_type, chip)->regs;
49
50 readl(gc->reg_base + regs->ack);
51}
52
53static asmlinkage void __exception_irq_entry zevio_handle_irq(struct pt_regs *regs)
54{
55 int irqnr;
56
57 while (readl(zevio_irq_io + IO_STATUS)) {
58 irqnr = readl(zevio_irq_io + IO_CURRENT);
59 irqnr = irq_find_mapping(zevio_irq_domain, irqnr);
60 handle_IRQ(irqnr, regs);
61 };
62}
63
64static void __init zevio_init_irq_base(void __iomem *base)
65{
66 /* Disable all interrupts */
67 writel(~0, base + IO_DISABLE);
68
69 /* Accept interrupts of all priorities */
70 writel(0xF, base + IO_MAX_PRIOTY);
71
72 /* Reset existing interrupts */
73 readl(base + IO_RESET);
74}
75
76static int __init zevio_of_init(struct device_node *node,
77 struct device_node *parent)
78{
79 unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
80 struct irq_chip_generic *gc;
81 int ret;
82
83 if (WARN_ON(zevio_irq_io || zevio_irq_domain))
84 return -EBUSY;
85
86 zevio_irq_io = of_iomap(node, 0);
87 BUG_ON(!zevio_irq_io);
88
89 /* Do not invert interrupt status bits */
90 writel(~0, zevio_irq_io + IO_INVERT_SEL);
91
92 /* Disable sticky interrupts */
93 writel(0, zevio_irq_io + IO_STICKY_SEL);
94
95 /* We don't use IRQ priorities. Set each IRQ to highest priority. */
96 memset_io(zevio_irq_io + IO_PRIORITY_SEL, 0, MAX_INTRS * sizeof(u32));
97
98 /* Init IRQ and FIQ */
99 zevio_init_irq_base(zevio_irq_io + IO_IRQ_BASE);
100 zevio_init_irq_base(zevio_irq_io + IO_FIQ_BASE);
101
102 zevio_irq_domain = irq_domain_add_linear(node, MAX_INTRS,
103 &irq_generic_chip_ops, NULL);
104 BUG_ON(!zevio_irq_domain);
105
106 ret = irq_alloc_domain_generic_chips(zevio_irq_domain, MAX_INTRS, 1,
107 "zevio_intc", handle_level_irq,
108 clr, 0, IRQ_GC_INIT_MASK_CACHE);
109 BUG_ON(ret);
110
111 gc = irq_get_domain_generic_chip(zevio_irq_domain, 0);
112 gc->reg_base = zevio_irq_io;
113 gc->chip_types[0].chip.irq_ack = zevio_irq_ack;
114 gc->chip_types[0].chip.irq_mask = irq_gc_mask_disable_reg;
115 gc->chip_types[0].chip.irq_unmask = irq_gc_unmask_enable_reg;
116 gc->chip_types[0].regs.mask = IO_IRQ_BASE + IO_ENABLE;
117 gc->chip_types[0].regs.enable = IO_IRQ_BASE + IO_ENABLE;
118 gc->chip_types[0].regs.disable = IO_IRQ_BASE + IO_DISABLE;
119 gc->chip_types[0].regs.ack = IO_IRQ_BASE + IO_RESET;
120
121 set_handle_irq(zevio_handle_irq);
122
123 pr_info("TI-NSPIRE classic IRQ controller\n");
124 return 0;
125}
126
127IRQCHIP_DECLARE(zevio_irq, "lsi,zevio-intc", zevio_of_init);
diff --git a/drivers/isdn/capi/Kconfig b/drivers/isdn/capi/Kconfig
index f04686580040..9816c51eb5c2 100644
--- a/drivers/isdn/capi/Kconfig
+++ b/drivers/isdn/capi/Kconfig
@@ -16,9 +16,17 @@ config CAPI_TRACE
16 This will increase the size of the kernelcapi module by 20 KB. 16 This will increase the size of the kernelcapi module by 20 KB.
17 If unsure, say Y. 17 If unsure, say Y.
18 18
19config ISDN_CAPI_CAPI20
20 tristate "CAPI2.0 /dev/capi support"
21 help
22 This option will provide the CAPI 2.0 interface to userspace
23 applications via /dev/capi20. Applications should use the
24 standardized libcapi20 to access this functionality. You should say
25 Y/M here.
26
19config ISDN_CAPI_MIDDLEWARE 27config ISDN_CAPI_MIDDLEWARE
20 bool "CAPI2.0 Middleware support" 28 bool "CAPI2.0 Middleware support"
21 depends on TTY 29 depends on ISDN_CAPI_CAPI20 && TTY
22 help 30 help
23 This option will enhance the capabilities of the /dev/capi20 31 This option will enhance the capabilities of the /dev/capi20
24 interface. It will provide a means of moving a data connection, 32 interface. It will provide a means of moving a data connection,
@@ -26,14 +34,6 @@ config ISDN_CAPI_MIDDLEWARE
26 device. If you want to use pppd with pppdcapiplugin to dial up to 34 device. If you want to use pppd with pppdcapiplugin to dial up to
27 your ISP, say Y here. 35 your ISP, say Y here.
28 36
29config ISDN_CAPI_CAPI20
30 tristate "CAPI2.0 /dev/capi support"
31 help
32 This option will provide the CAPI 2.0 interface to userspace
33 applications via /dev/capi20. Applications should use the
34 standardized libcapi20 to access this functionality. You should say
35 Y/M here.
36
37config ISDN_CAPI_CAPIDRV 37config ISDN_CAPI_CAPIDRV
38 tristate "CAPI2.0 capidrv interface support" 38 tristate "CAPI2.0 capidrv interface support"
39 depends on ISDN_I4L 39 depends on ISDN_I4L
diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
index af1b020a81f1..b420f8bd862e 100644
--- a/drivers/isdn/hisax/q931.c
+++ b/drivers/isdn/hisax/q931.c
@@ -810,7 +810,7 @@ prfeatureind(char *dest, u_char *p)
810 dp += sprintf(dp, " octet 3 "); 810 dp += sprintf(dp, " octet 3 ");
811 dp += prbits(dp, *p, 8, 8); 811 dp += prbits(dp, *p, 8, 8);
812 *dp++ = '\n'; 812 *dp++ = '\n';
813 if (!(*p++ & 80)) { 813 if (!(*p++ & 0x80)) {
814 dp += sprintf(dp, " octet 4 "); 814 dp += sprintf(dp, " octet 4 ");
815 dp += prbits(dp, *p++, 8, 8); 815 dp += prbits(dp, *p++, 8, 8);
816 *dp++ = '\n'; 816 *dp++ = '\n';
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 9a06fe883766..95ad936e6048 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -254,16 +254,6 @@ config DM_THIN_PROVISIONING
254 ---help--- 254 ---help---
255 Provides thin provisioning and snapshots that share a data store. 255 Provides thin provisioning and snapshots that share a data store.
256 256
257config DM_DEBUG_BLOCK_STACK_TRACING
258 boolean "Keep stack trace of persistent data block lock holders"
259 depends on STACKTRACE_SUPPORT && DM_PERSISTENT_DATA
260 select STACKTRACE
261 ---help---
262 Enable this for messages that may help debug problems with the
263 block manager locking used by thin provisioning and caching.
264
265 If unsure, say N.
266
267config DM_CACHE 257config DM_CACHE
268 tristate "Cache target (EXPERIMENTAL)" 258 tristate "Cache target (EXPERIMENTAL)"
269 depends on BLK_DEV_DM 259 depends on BLK_DEV_DM
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 0c707e4f4eaf..a4c7306ff43d 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -210,7 +210,9 @@ BITMASK(GC_MARK, struct bucket, gc_mark, 0, 2);
210#define GC_MARK_RECLAIMABLE 0 210#define GC_MARK_RECLAIMABLE 0
211#define GC_MARK_DIRTY 1 211#define GC_MARK_DIRTY 1
212#define GC_MARK_METADATA 2 212#define GC_MARK_METADATA 2
213BITMASK(GC_SECTORS_USED, struct bucket, gc_mark, 2, 13); 213#define GC_SECTORS_USED_SIZE 13
214#define MAX_GC_SECTORS_USED (~(~0ULL << GC_SECTORS_USED_SIZE))
215BITMASK(GC_SECTORS_USED, struct bucket, gc_mark, 2, GC_SECTORS_USED_SIZE);
214BITMASK(GC_MOVE, struct bucket, gc_mark, 15, 1); 216BITMASK(GC_MOVE, struct bucket, gc_mark, 15, 1);
215 217
216#include "journal.h" 218#include "journal.h"
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index 4f6b5940e609..3f74b4b0747b 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -23,7 +23,7 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set)
23 for (k = i->start; k < bset_bkey_last(i); k = next) { 23 for (k = i->start; k < bset_bkey_last(i); k = next) {
24 next = bkey_next(k); 24 next = bkey_next(k);
25 25
26 printk(KERN_ERR "block %u key %zi/%u: ", set, 26 printk(KERN_ERR "block %u key %li/%u: ", set,
27 (uint64_t *) k - i->d, i->keys); 27 (uint64_t *) k - i->d, i->keys);
28 28
29 if (b->ops->key_dump) 29 if (b->ops->key_dump)
@@ -1185,9 +1185,12 @@ static void __btree_sort(struct btree_keys *b, struct btree_iter *iter,
1185 struct bset *out = (void *) __get_free_pages(__GFP_NOWARN|GFP_NOIO, 1185 struct bset *out = (void *) __get_free_pages(__GFP_NOWARN|GFP_NOIO,
1186 order); 1186 order);
1187 if (!out) { 1187 if (!out) {
1188 struct page *outp;
1189
1188 BUG_ON(order > state->page_order); 1190 BUG_ON(order > state->page_order);
1189 1191
1190 out = page_address(mempool_alloc(state->pool, GFP_NOIO)); 1192 outp = mempool_alloc(state->pool, GFP_NOIO);
1193 out = page_address(outp);
1191 used_mempool = true; 1194 used_mempool = true;
1192 order = state->page_order; 1195 order = state->page_order;
1193 } 1196 }
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 98cc0a810a36..5f9c2a665ca5 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -1167,7 +1167,7 @@ uint8_t __bch_btree_mark_key(struct cache_set *c, int level, struct bkey *k)
1167 /* guard against overflow */ 1167 /* guard against overflow */
1168 SET_GC_SECTORS_USED(g, min_t(unsigned, 1168 SET_GC_SECTORS_USED(g, min_t(unsigned,
1169 GC_SECTORS_USED(g) + KEY_SIZE(k), 1169 GC_SECTORS_USED(g) + KEY_SIZE(k),
1170 (1 << 14) - 1)); 1170 MAX_GC_SECTORS_USED));
1171 1171
1172 BUG_ON(!GC_SECTORS_USED(g)); 1172 BUG_ON(!GC_SECTORS_USED(g));
1173 } 1173 }
@@ -1805,7 +1805,7 @@ static bool btree_insert_key(struct btree *b, struct bkey *k,
1805 1805
1806static size_t insert_u64s_remaining(struct btree *b) 1806static size_t insert_u64s_remaining(struct btree *b)
1807{ 1807{
1808 ssize_t ret = bch_btree_keys_u64s_remaining(&b->keys); 1808 long ret = bch_btree_keys_u64s_remaining(&b->keys);
1809 1809
1810 /* 1810 /*
1811 * Might land in the middle of an existing extent and have to split it 1811 * Might land in the middle of an existing extent and have to split it
diff --git a/drivers/md/bcache/extents.c b/drivers/md/bcache/extents.c
index c3ead586dc27..416d1a3e028e 100644
--- a/drivers/md/bcache/extents.c
+++ b/drivers/md/bcache/extents.c
@@ -194,7 +194,7 @@ err:
194 mutex_unlock(&b->c->bucket_lock); 194 mutex_unlock(&b->c->bucket_lock);
195 bch_extent_to_text(buf, sizeof(buf), k); 195 bch_extent_to_text(buf, sizeof(buf), k);
196 btree_bug(b, 196 btree_bug(b,
197"inconsistent btree pointer %s: bucket %li pin %i prio %i gen %i last_gc %i mark %llu gc_gen %i", 197"inconsistent btree pointer %s: bucket %zi pin %i prio %i gen %i last_gc %i mark %llu gc_gen %i",
198 buf, PTR_BUCKET_NR(b->c, k, i), atomic_read(&g->pin), 198 buf, PTR_BUCKET_NR(b->c, k, i), atomic_read(&g->pin),
199 g->prio, g->gen, g->last_gc, GC_MARK(g), g->gc_gen); 199 g->prio, g->gen, g->last_gc, GC_MARK(g), g->gc_gen);
200 return true; 200 return true;
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index 72cd213f213f..5d5d031cf381 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -353,14 +353,14 @@ static void bch_data_insert_start(struct closure *cl)
353 struct data_insert_op *op = container_of(cl, struct data_insert_op, cl); 353 struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
354 struct bio *bio = op->bio, *n; 354 struct bio *bio = op->bio, *n;
355 355
356 if (op->bypass)
357 return bch_data_invalidate(cl);
358
359 if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0) { 356 if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0) {
360 set_gc_sectors(op->c); 357 set_gc_sectors(op->c);
361 wake_up_gc(op->c); 358 wake_up_gc(op->c);
362 } 359 }
363 360
361 if (op->bypass)
362 return bch_data_invalidate(cl);
363
364 /* 364 /*
365 * Journal writes are marked REQ_FLUSH; if the original write was a 365 * Journal writes are marked REQ_FLUSH; if the original write was a
366 * flush, it'll wait on the journal write. 366 * flush, it'll wait on the journal write.
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index c6ab69333a6d..d8458d477a12 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -416,7 +416,7 @@ static int btree_bset_stats(struct btree_op *b_op, struct btree *b)
416 return MAP_CONTINUE; 416 return MAP_CONTINUE;
417} 417}
418 418
419int bch_bset_print_stats(struct cache_set *c, char *buf) 419static int bch_bset_print_stats(struct cache_set *c, char *buf)
420{ 420{
421 struct bset_stats_op op; 421 struct bset_stats_op op;
422 int ret; 422 int ret;
diff --git a/drivers/md/dm-cache-policy-mq.c b/drivers/md/dm-cache-policy-mq.c
index 1e018e986610..0e385e40909e 100644
--- a/drivers/md/dm-cache-policy-mq.c
+++ b/drivers/md/dm-cache-policy-mq.c
@@ -872,7 +872,7 @@ static void mq_destroy(struct dm_cache_policy *p)
872{ 872{
873 struct mq_policy *mq = to_mq_policy(p); 873 struct mq_policy *mq = to_mq_policy(p);
874 874
875 kfree(mq->table); 875 vfree(mq->table);
876 epool_exit(&mq->cache_pool); 876 epool_exit(&mq->cache_pool);
877 epool_exit(&mq->pre_cache_pool); 877 epool_exit(&mq->pre_cache_pool);
878 kfree(mq); 878 kfree(mq);
@@ -1245,7 +1245,7 @@ static struct dm_cache_policy *mq_create(dm_cblock_t cache_size,
1245 1245
1246 mq->nr_buckets = next_power(from_cblock(cache_size) / 2, 16); 1246 mq->nr_buckets = next_power(from_cblock(cache_size) / 2, 16);
1247 mq->hash_bits = ffs(mq->nr_buckets) - 1; 1247 mq->hash_bits = ffs(mq->nr_buckets) - 1;
1248 mq->table = kzalloc(sizeof(*mq->table) * mq->nr_buckets, GFP_KERNEL); 1248 mq->table = vzalloc(sizeof(*mq->table) * mq->nr_buckets);
1249 if (!mq->table) 1249 if (!mq->table)
1250 goto bad_alloc_table; 1250 goto bad_alloc_table;
1251 1251
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index ffd472e015ca..074b9c8e4cf0 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -289,6 +289,7 @@ struct per_bio_data {
289 bool tick:1; 289 bool tick:1;
290 unsigned req_nr:2; 290 unsigned req_nr:2;
291 struct dm_deferred_entry *all_io_entry; 291 struct dm_deferred_entry *all_io_entry;
292 struct dm_hook_info hook_info;
292 293
293 /* 294 /*
294 * writethrough fields. These MUST remain at the end of this 295 * writethrough fields. These MUST remain at the end of this
@@ -297,7 +298,6 @@ struct per_bio_data {
297 */ 298 */
298 struct cache *cache; 299 struct cache *cache;
299 dm_cblock_t cblock; 300 dm_cblock_t cblock;
300 struct dm_hook_info hook_info;
301 struct dm_bio_details bio_details; 301 struct dm_bio_details bio_details;
302}; 302};
303 303
@@ -671,15 +671,16 @@ static void remap_to_cache(struct cache *cache, struct bio *bio,
671 dm_cblock_t cblock) 671 dm_cblock_t cblock)
672{ 672{
673 sector_t bi_sector = bio->bi_iter.bi_sector; 673 sector_t bi_sector = bio->bi_iter.bi_sector;
674 sector_t block = from_cblock(cblock);
674 675
675 bio->bi_bdev = cache->cache_dev->bdev; 676 bio->bi_bdev = cache->cache_dev->bdev;
676 if (!block_size_is_power_of_two(cache)) 677 if (!block_size_is_power_of_two(cache))
677 bio->bi_iter.bi_sector = 678 bio->bi_iter.bi_sector =
678 (from_cblock(cblock) * cache->sectors_per_block) + 679 (block * cache->sectors_per_block) +
679 sector_div(bi_sector, cache->sectors_per_block); 680 sector_div(bi_sector, cache->sectors_per_block);
680 else 681 else
681 bio->bi_iter.bi_sector = 682 bio->bi_iter.bi_sector =
682 (from_cblock(cblock) << cache->sectors_per_block_shift) | 683 (block << cache->sectors_per_block_shift) |
683 (bi_sector & (cache->sectors_per_block - 1)); 684 (bi_sector & (cache->sectors_per_block - 1));
684} 685}
685 686
@@ -978,12 +979,13 @@ static void issue_copy_real(struct dm_cache_migration *mg)
978 int r; 979 int r;
979 struct dm_io_region o_region, c_region; 980 struct dm_io_region o_region, c_region;
980 struct cache *cache = mg->cache; 981 struct cache *cache = mg->cache;
982 sector_t cblock = from_cblock(mg->cblock);
981 983
982 o_region.bdev = cache->origin_dev->bdev; 984 o_region.bdev = cache->origin_dev->bdev;
983 o_region.count = cache->sectors_per_block; 985 o_region.count = cache->sectors_per_block;
984 986
985 c_region.bdev = cache->cache_dev->bdev; 987 c_region.bdev = cache->cache_dev->bdev;
986 c_region.sector = from_cblock(mg->cblock) * cache->sectors_per_block; 988 c_region.sector = cblock * cache->sectors_per_block;
987 c_region.count = cache->sectors_per_block; 989 c_region.count = cache->sectors_per_block;
988 990
989 if (mg->writeback || mg->demote) { 991 if (mg->writeback || mg->demote) {
@@ -1010,13 +1012,15 @@ static void overwrite_endio(struct bio *bio, int err)
1010 struct per_bio_data *pb = get_per_bio_data(bio, pb_data_size); 1012 struct per_bio_data *pb = get_per_bio_data(bio, pb_data_size);
1011 unsigned long flags; 1013 unsigned long flags;
1012 1014
1015 dm_unhook_bio(&pb->hook_info, bio);
1016
1013 if (err) 1017 if (err)
1014 mg->err = true; 1018 mg->err = true;
1015 1019
1020 mg->requeue_holder = false;
1021
1016 spin_lock_irqsave(&cache->lock, flags); 1022 spin_lock_irqsave(&cache->lock, flags);
1017 list_add_tail(&mg->list, &cache->completed_migrations); 1023 list_add_tail(&mg->list, &cache->completed_migrations);
1018 dm_unhook_bio(&pb->hook_info, bio);
1019 mg->requeue_holder = false;
1020 spin_unlock_irqrestore(&cache->lock, flags); 1024 spin_unlock_irqrestore(&cache->lock, flags);
1021 1025
1022 wake_worker(cache); 1026 wake_worker(cache);
@@ -2461,20 +2465,18 @@ static int cache_map(struct dm_target *ti, struct bio *bio)
2461 bool discarded_block; 2465 bool discarded_block;
2462 struct dm_bio_prison_cell *cell; 2466 struct dm_bio_prison_cell *cell;
2463 struct policy_result lookup_result; 2467 struct policy_result lookup_result;
2464 struct per_bio_data *pb; 2468 struct per_bio_data *pb = init_per_bio_data(bio, pb_data_size);
2465 2469
2466 if (from_oblock(block) > from_oblock(cache->origin_blocks)) { 2470 if (unlikely(from_oblock(block) >= from_oblock(cache->origin_blocks))) {
2467 /* 2471 /*
2468 * This can only occur if the io goes to a partial block at 2472 * This can only occur if the io goes to a partial block at
2469 * the end of the origin device. We don't cache these. 2473 * the end of the origin device. We don't cache these.
2470 * Just remap to the origin and carry on. 2474 * Just remap to the origin and carry on.
2471 */ 2475 */
2472 remap_to_origin_clear_discard(cache, bio, block); 2476 remap_to_origin(cache, bio);
2473 return DM_MAPIO_REMAPPED; 2477 return DM_MAPIO_REMAPPED;
2474 } 2478 }
2475 2479
2476 pb = init_per_bio_data(bio, pb_data_size);
2477
2478 if (bio->bi_rw & (REQ_FLUSH | REQ_FUA | REQ_DISCARD)) { 2480 if (bio->bi_rw & (REQ_FLUSH | REQ_FUA | REQ_DISCARD)) {
2479 defer_bio(cache, bio); 2481 defer_bio(cache, bio);
2480 return DM_MAPIO_SUBMITTED; 2482 return DM_MAPIO_SUBMITTED;
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index b2b8a10e8427..3842ac738f98 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -201,29 +201,28 @@ static void list_dp_init(struct dpages *dp, struct page_list *pl, unsigned offse
201/* 201/*
202 * Functions for getting the pages from a bvec. 202 * Functions for getting the pages from a bvec.
203 */ 203 */
204static void bio_get_page(struct dpages *dp, 204static void bio_get_page(struct dpages *dp, struct page **p,
205 struct page **p, unsigned long *len, unsigned *offset) 205 unsigned long *len, unsigned *offset)
206{ 206{
207 struct bio *bio = dp->context_ptr; 207 struct bio_vec *bvec = dp->context_ptr;
208 struct bio_vec bvec = bio_iovec(bio); 208 *p = bvec->bv_page;
209 *p = bvec.bv_page; 209 *len = bvec->bv_len - dp->context_u;
210 *len = bvec.bv_len; 210 *offset = bvec->bv_offset + dp->context_u;
211 *offset = bvec.bv_offset;
212} 211}
213 212
214static void bio_next_page(struct dpages *dp) 213static void bio_next_page(struct dpages *dp)
215{ 214{
216 struct bio *bio = dp->context_ptr; 215 struct bio_vec *bvec = dp->context_ptr;
217 struct bio_vec bvec = bio_iovec(bio); 216 dp->context_ptr = bvec + 1;
218 217 dp->context_u = 0;
219 bio_advance(bio, bvec.bv_len);
220} 218}
221 219
222static void bio_dp_init(struct dpages *dp, struct bio *bio) 220static void bio_dp_init(struct dpages *dp, struct bio *bio)
223{ 221{
224 dp->get_page = bio_get_page; 222 dp->get_page = bio_get_page;
225 dp->next_page = bio_next_page; 223 dp->next_page = bio_next_page;
226 dp->context_ptr = bio; 224 dp->context_ptr = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
225 dp->context_u = bio->bi_iter.bi_bvec_done;
227} 226}
228 227
229/* 228/*
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 6eb9dc9ef8f3..422a9fdeb53e 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1626,8 +1626,11 @@ static int multipath_ioctl(struct dm_target *ti, unsigned int cmd,
1626 /* 1626 /*
1627 * Only pass ioctls through if the device sizes match exactly. 1627 * Only pass ioctls through if the device sizes match exactly.
1628 */ 1628 */
1629 if (!r && ti->len != i_size_read(bdev->bd_inode) >> SECTOR_SHIFT) 1629 if (!bdev || ti->len != i_size_read(bdev->bd_inode) >> SECTOR_SHIFT) {
1630 r = scsi_verify_blk_ioctl(NULL, cmd); 1630 int err = scsi_verify_blk_ioctl(NULL, cmd);
1631 if (err)
1632 r = err;
1633 }
1631 1634
1632 if (r == -ENOTCONN && !fatal_signal_pending(current)) 1635 if (r == -ENOTCONN && !fatal_signal_pending(current))
1633 queue_work(kmultipathd, &m->process_queued_ios); 1636 queue_work(kmultipathd, &m->process_queued_ios);
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index f284e0bfb25f..7dfdb5c746d6 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -1244,6 +1244,9 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1244 1244
1245 dm_bio_restore(bd, bio); 1245 dm_bio_restore(bd, bio);
1246 bio_record->details.bi_bdev = NULL; 1246 bio_record->details.bi_bdev = NULL;
1247
1248 atomic_inc(&bio->bi_remaining);
1249
1247 queue_bio(ms, bio, rw); 1250 queue_bio(ms, bio, rw);
1248 return DM_ENDIO_INCOMPLETE; 1251 return DM_ENDIO_INCOMPLETE;
1249 } 1252 }
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index afc3d017de4c..d6e88178d22c 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -546,6 +546,9 @@ static int read_exceptions(struct pstore *ps,
546 r = insert_exceptions(ps, area, callback, callback_context, 546 r = insert_exceptions(ps, area, callback, callback_context,
547 &full); 547 &full);
548 548
549 if (!full)
550 memcpy(ps->area, area, ps->store->chunk_size << SECTOR_SHIFT);
551
549 dm_bufio_release(bp); 552 dm_bufio_release(bp);
550 553
551 dm_bufio_forget(client, chunk); 554 dm_bufio_forget(client, chunk);
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index 7da347665552..fb9efc829182 100644
--- a/drivers/md/dm-thin-metadata.c
+++ b/drivers/md/dm-thin-metadata.c
@@ -76,7 +76,7 @@
76 76
77#define THIN_SUPERBLOCK_MAGIC 27022010 77#define THIN_SUPERBLOCK_MAGIC 27022010
78#define THIN_SUPERBLOCK_LOCATION 0 78#define THIN_SUPERBLOCK_LOCATION 0
79#define THIN_VERSION 1 79#define THIN_VERSION 2
80#define THIN_METADATA_CACHE_SIZE 64 80#define THIN_METADATA_CACHE_SIZE 64
81#define SECTOR_TO_BLOCK_SHIFT 3 81#define SECTOR_TO_BLOCK_SHIFT 3
82 82
@@ -483,7 +483,7 @@ static int __write_initial_superblock(struct dm_pool_metadata *pmd)
483 483
484 disk_super->data_mapping_root = cpu_to_le64(pmd->root); 484 disk_super->data_mapping_root = cpu_to_le64(pmd->root);
485 disk_super->device_details_root = cpu_to_le64(pmd->details_root); 485 disk_super->device_details_root = cpu_to_le64(pmd->details_root);
486 disk_super->metadata_block_size = cpu_to_le32(THIN_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); 486 disk_super->metadata_block_size = cpu_to_le32(THIN_METADATA_BLOCK_SIZE);
487 disk_super->metadata_nr_blocks = cpu_to_le64(bdev_size >> SECTOR_TO_BLOCK_SHIFT); 487 disk_super->metadata_nr_blocks = cpu_to_le64(bdev_size >> SECTOR_TO_BLOCK_SHIFT);
488 disk_super->data_block_size = cpu_to_le32(pmd->data_block_size); 488 disk_super->data_block_size = cpu_to_le32(pmd->data_block_size);
489 489
@@ -651,7 +651,7 @@ static int __create_persistent_data_objects(struct dm_pool_metadata *pmd, bool f
651{ 651{
652 int r; 652 int r;
653 653
654 pmd->bm = dm_block_manager_create(pmd->bdev, THIN_METADATA_BLOCK_SIZE, 654 pmd->bm = dm_block_manager_create(pmd->bdev, THIN_METADATA_BLOCK_SIZE << SECTOR_SHIFT,
655 THIN_METADATA_CACHE_SIZE, 655 THIN_METADATA_CACHE_SIZE,
656 THIN_MAX_CONCURRENT_LOCKS); 656 THIN_MAX_CONCURRENT_LOCKS);
657 if (IS_ERR(pmd->bm)) { 657 if (IS_ERR(pmd->bm)) {
@@ -1489,6 +1489,23 @@ bool dm_thin_changed_this_transaction(struct dm_thin_device *td)
1489 return r; 1489 return r;
1490} 1490}
1491 1491
1492bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd)
1493{
1494 bool r = false;
1495 struct dm_thin_device *td, *tmp;
1496
1497 down_read(&pmd->root_lock);
1498 list_for_each_entry_safe(td, tmp, &pmd->thin_devices, list) {
1499 if (td->changed) {
1500 r = td->changed;
1501 break;
1502 }
1503 }
1504 up_read(&pmd->root_lock);
1505
1506 return r;
1507}
1508
1492bool dm_thin_aborted_changes(struct dm_thin_device *td) 1509bool dm_thin_aborted_changes(struct dm_thin_device *td)
1493{ 1510{
1494 bool r; 1511 bool r;
@@ -1738,3 +1755,38 @@ int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
1738 1755
1739 return r; 1756 return r;
1740} 1757}
1758
1759int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd)
1760{
1761 int r;
1762 struct dm_block *sblock;
1763 struct thin_disk_superblock *disk_super;
1764
1765 down_write(&pmd->root_lock);
1766 pmd->flags |= THIN_METADATA_NEEDS_CHECK_FLAG;
1767
1768 r = superblock_lock(pmd, &sblock);
1769 if (r) {
1770 DMERR("couldn't read superblock");
1771 goto out;
1772 }
1773
1774 disk_super = dm_block_data(sblock);
1775 disk_super->flags = cpu_to_le32(pmd->flags);
1776
1777 dm_bm_unlock(sblock);
1778out:
1779 up_write(&pmd->root_lock);
1780 return r;
1781}
1782
1783bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd)
1784{
1785 bool needs_check;
1786
1787 down_read(&pmd->root_lock);
1788 needs_check = pmd->flags & THIN_METADATA_NEEDS_CHECK_FLAG;
1789 up_read(&pmd->root_lock);
1790
1791 return needs_check;
1792}
diff --git a/drivers/md/dm-thin-metadata.h b/drivers/md/dm-thin-metadata.h
index 9a368567632f..e3c857db195a 100644
--- a/drivers/md/dm-thin-metadata.h
+++ b/drivers/md/dm-thin-metadata.h
@@ -9,16 +9,14 @@
9 9
10#include "persistent-data/dm-block-manager.h" 10#include "persistent-data/dm-block-manager.h"
11#include "persistent-data/dm-space-map.h" 11#include "persistent-data/dm-space-map.h"
12#include "persistent-data/dm-space-map-metadata.h"
12 13
13#define THIN_METADATA_BLOCK_SIZE 4096 14#define THIN_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
14 15
15/* 16/*
16 * The metadata device is currently limited in size. 17 * The metadata device is currently limited in size.
17 *
18 * We have one block of index, which can hold 255 index entries. Each
19 * index entry contains allocation info about 16k metadata blocks.
20 */ 18 */
21#define THIN_METADATA_MAX_SECTORS (255 * (1 << 14) * (THIN_METADATA_BLOCK_SIZE / (1 << SECTOR_SHIFT))) 19#define THIN_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
22 20
23/* 21/*
24 * A metadata device larger than 16GB triggers a warning. 22 * A metadata device larger than 16GB triggers a warning.
@@ -27,6 +25,11 @@
27 25
28/*----------------------------------------------------------------*/ 26/*----------------------------------------------------------------*/
29 27
28/*
29 * Thin metadata superblock flags.
30 */
31#define THIN_METADATA_NEEDS_CHECK_FLAG (1 << 0)
32
30struct dm_pool_metadata; 33struct dm_pool_metadata;
31struct dm_thin_device; 34struct dm_thin_device;
32 35
@@ -161,6 +164,8 @@ int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
161 */ 164 */
162bool dm_thin_changed_this_transaction(struct dm_thin_device *td); 165bool dm_thin_changed_this_transaction(struct dm_thin_device *td);
163 166
167bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd);
168
164bool dm_thin_aborted_changes(struct dm_thin_device *td); 169bool dm_thin_aborted_changes(struct dm_thin_device *td);
165 170
166int dm_thin_get_highest_mapped_block(struct dm_thin_device *td, 171int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
@@ -202,6 +207,12 @@ int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
202 dm_sm_threshold_fn fn, 207 dm_sm_threshold_fn fn,
203 void *context); 208 void *context);
204 209
210/*
211 * Updates the superblock immediately.
212 */
213int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd);
214bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd);
215
205/*----------------------------------------------------------------*/ 216/*----------------------------------------------------------------*/
206 217
207#endif 218#endif
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index faaf944597ab..be70d38745f7 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -130,10 +130,11 @@ static void build_virtual_key(struct dm_thin_device *td, dm_block_t b,
130struct dm_thin_new_mapping; 130struct dm_thin_new_mapping;
131 131
132/* 132/*
133 * The pool runs in 3 modes. Ordered in degraded order for comparisons. 133 * The pool runs in 4 modes. Ordered in degraded order for comparisons.
134 */ 134 */
135enum pool_mode { 135enum pool_mode {
136 PM_WRITE, /* metadata may be changed */ 136 PM_WRITE, /* metadata may be changed */
137 PM_OUT_OF_DATA_SPACE, /* metadata may be changed, though data may not be allocated */
137 PM_READ_ONLY, /* metadata may not be changed */ 138 PM_READ_ONLY, /* metadata may not be changed */
138 PM_FAIL, /* all I/O fails */ 139 PM_FAIL, /* all I/O fails */
139}; 140};
@@ -198,7 +199,6 @@ struct pool {
198}; 199};
199 200
200static enum pool_mode get_pool_mode(struct pool *pool); 201static enum pool_mode get_pool_mode(struct pool *pool);
201static void out_of_data_space(struct pool *pool);
202static void metadata_operation_failed(struct pool *pool, const char *op, int r); 202static void metadata_operation_failed(struct pool *pool, const char *op, int r);
203 203
204/* 204/*
@@ -226,6 +226,7 @@ struct thin_c {
226 226
227 struct pool *pool; 227 struct pool *pool;
228 struct dm_thin_device *td; 228 struct dm_thin_device *td;
229 bool requeue_mode:1;
229}; 230};
230 231
231/*----------------------------------------------------------------*/ 232/*----------------------------------------------------------------*/
@@ -369,14 +370,18 @@ struct dm_thin_endio_hook {
369 struct dm_thin_new_mapping *overwrite_mapping; 370 struct dm_thin_new_mapping *overwrite_mapping;
370}; 371};
371 372
372static void __requeue_bio_list(struct thin_c *tc, struct bio_list *master) 373static void requeue_bio_list(struct thin_c *tc, struct bio_list *master)
373{ 374{
374 struct bio *bio; 375 struct bio *bio;
375 struct bio_list bios; 376 struct bio_list bios;
377 unsigned long flags;
376 378
377 bio_list_init(&bios); 379 bio_list_init(&bios);
380
381 spin_lock_irqsave(&tc->pool->lock, flags);
378 bio_list_merge(&bios, master); 382 bio_list_merge(&bios, master);
379 bio_list_init(master); 383 bio_list_init(master);
384 spin_unlock_irqrestore(&tc->pool->lock, flags);
380 385
381 while ((bio = bio_list_pop(&bios))) { 386 while ((bio = bio_list_pop(&bios))) {
382 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook)); 387 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
@@ -391,12 +396,26 @@ static void __requeue_bio_list(struct thin_c *tc, struct bio_list *master)
391static void requeue_io(struct thin_c *tc) 396static void requeue_io(struct thin_c *tc)
392{ 397{
393 struct pool *pool = tc->pool; 398 struct pool *pool = tc->pool;
399
400 requeue_bio_list(tc, &pool->deferred_bios);
401 requeue_bio_list(tc, &pool->retry_on_resume_list);
402}
403
404static void error_retry_list(struct pool *pool)
405{
406 struct bio *bio;
394 unsigned long flags; 407 unsigned long flags;
408 struct bio_list bios;
409
410 bio_list_init(&bios);
395 411
396 spin_lock_irqsave(&pool->lock, flags); 412 spin_lock_irqsave(&pool->lock, flags);
397 __requeue_bio_list(tc, &pool->deferred_bios); 413 bio_list_merge(&bios, &pool->retry_on_resume_list);
398 __requeue_bio_list(tc, &pool->retry_on_resume_list); 414 bio_list_init(&pool->retry_on_resume_list);
399 spin_unlock_irqrestore(&pool->lock, flags); 415 spin_unlock_irqrestore(&pool->lock, flags);
416
417 while ((bio = bio_list_pop(&bios)))
418 bio_io_error(bio);
400} 419}
401 420
402/* 421/*
@@ -925,13 +944,15 @@ static void check_low_water_mark(struct pool *pool, dm_block_t free_blocks)
925 } 944 }
926} 945}
927 946
947static void set_pool_mode(struct pool *pool, enum pool_mode new_mode);
948
928static int alloc_data_block(struct thin_c *tc, dm_block_t *result) 949static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
929{ 950{
930 int r; 951 int r;
931 dm_block_t free_blocks; 952 dm_block_t free_blocks;
932 struct pool *pool = tc->pool; 953 struct pool *pool = tc->pool;
933 954
934 if (get_pool_mode(pool) != PM_WRITE) 955 if (WARN_ON(get_pool_mode(pool) != PM_WRITE))
935 return -EINVAL; 956 return -EINVAL;
936 957
937 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks); 958 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
@@ -958,7 +979,7 @@ static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
958 } 979 }
959 980
960 if (!free_blocks) { 981 if (!free_blocks) {
961 out_of_data_space(pool); 982 set_pool_mode(pool, PM_OUT_OF_DATA_SPACE);
962 return -ENOSPC; 983 return -ENOSPC;
963 } 984 }
964 } 985 }
@@ -988,15 +1009,32 @@ static void retry_on_resume(struct bio *bio)
988 spin_unlock_irqrestore(&pool->lock, flags); 1009 spin_unlock_irqrestore(&pool->lock, flags);
989} 1010}
990 1011
991static void handle_unserviceable_bio(struct pool *pool, struct bio *bio) 1012static bool should_error_unserviceable_bio(struct pool *pool)
992{ 1013{
993 /* 1014 enum pool_mode m = get_pool_mode(pool);
994 * When pool is read-only, no cell locking is needed because
995 * nothing is changing.
996 */
997 WARN_ON_ONCE(get_pool_mode(pool) != PM_READ_ONLY);
998 1015
999 if (pool->pf.error_if_no_space) 1016 switch (m) {
1017 case PM_WRITE:
1018 /* Shouldn't get here */
1019 DMERR_LIMIT("bio unserviceable, yet pool is in PM_WRITE mode");
1020 return true;
1021
1022 case PM_OUT_OF_DATA_SPACE:
1023 return pool->pf.error_if_no_space;
1024
1025 case PM_READ_ONLY:
1026 case PM_FAIL:
1027 return true;
1028 default:
1029 /* Shouldn't get here */
1030 DMERR_LIMIT("bio unserviceable, yet pool has an unknown mode");
1031 return true;
1032 }
1033}
1034
1035static void handle_unserviceable_bio(struct pool *pool, struct bio *bio)
1036{
1037 if (should_error_unserviceable_bio(pool))
1000 bio_io_error(bio); 1038 bio_io_error(bio);
1001 else 1039 else
1002 retry_on_resume(bio); 1040 retry_on_resume(bio);
@@ -1007,11 +1045,20 @@ static void retry_bios_on_resume(struct pool *pool, struct dm_bio_prison_cell *c
1007 struct bio *bio; 1045 struct bio *bio;
1008 struct bio_list bios; 1046 struct bio_list bios;
1009 1047
1048 if (should_error_unserviceable_bio(pool)) {
1049 cell_error(pool, cell);
1050 return;
1051 }
1052
1010 bio_list_init(&bios); 1053 bio_list_init(&bios);
1011 cell_release(pool, cell, &bios); 1054 cell_release(pool, cell, &bios);
1012 1055
1013 while ((bio = bio_list_pop(&bios))) 1056 if (should_error_unserviceable_bio(pool))
1014 handle_unserviceable_bio(pool, bio); 1057 while ((bio = bio_list_pop(&bios)))
1058 bio_io_error(bio);
1059 else
1060 while ((bio = bio_list_pop(&bios)))
1061 retry_on_resume(bio);
1015} 1062}
1016 1063
1017static void process_discard(struct thin_c *tc, struct bio *bio) 1064static void process_discard(struct thin_c *tc, struct bio *bio)
@@ -1296,6 +1343,11 @@ static void process_bio_read_only(struct thin_c *tc, struct bio *bio)
1296 } 1343 }
1297} 1344}
1298 1345
1346static void process_bio_success(struct thin_c *tc, struct bio *bio)
1347{
1348 bio_endio(bio, 0);
1349}
1350
1299static void process_bio_fail(struct thin_c *tc, struct bio *bio) 1351static void process_bio_fail(struct thin_c *tc, struct bio *bio)
1300{ 1352{
1301 bio_io_error(bio); 1353 bio_io_error(bio);
@@ -1328,6 +1380,11 @@ static void process_deferred_bios(struct pool *pool)
1328 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook)); 1380 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
1329 struct thin_c *tc = h->tc; 1381 struct thin_c *tc = h->tc;
1330 1382
1383 if (tc->requeue_mode) {
1384 bio_endio(bio, DM_ENDIO_REQUEUE);
1385 continue;
1386 }
1387
1331 /* 1388 /*
1332 * If we've got no free new_mapping structs, and processing 1389 * If we've got no free new_mapping structs, and processing
1333 * this bio might require one, we pause until there are some 1390 * this bio might require one, we pause until there are some
@@ -1357,7 +1414,8 @@ static void process_deferred_bios(struct pool *pool)
1357 bio_list_init(&pool->deferred_flush_bios); 1414 bio_list_init(&pool->deferred_flush_bios);
1358 spin_unlock_irqrestore(&pool->lock, flags); 1415 spin_unlock_irqrestore(&pool->lock, flags);
1359 1416
1360 if (bio_list_empty(&bios) && !need_commit_due_to_time(pool)) 1417 if (bio_list_empty(&bios) &&
1418 !(dm_pool_changed_this_transaction(pool->pmd) && need_commit_due_to_time(pool)))
1361 return; 1419 return;
1362 1420
1363 if (commit(pool)) { 1421 if (commit(pool)) {
@@ -1393,51 +1451,134 @@ static void do_waker(struct work_struct *ws)
1393 1451
1394/*----------------------------------------------------------------*/ 1452/*----------------------------------------------------------------*/
1395 1453
1454struct noflush_work {
1455 struct work_struct worker;
1456 struct thin_c *tc;
1457
1458 atomic_t complete;
1459 wait_queue_head_t wait;
1460};
1461
1462static void complete_noflush_work(struct noflush_work *w)
1463{
1464 atomic_set(&w->complete, 1);
1465 wake_up(&w->wait);
1466}
1467
1468static void do_noflush_start(struct work_struct *ws)
1469{
1470 struct noflush_work *w = container_of(ws, struct noflush_work, worker);
1471 w->tc->requeue_mode = true;
1472 requeue_io(w->tc);
1473 complete_noflush_work(w);
1474}
1475
1476static void do_noflush_stop(struct work_struct *ws)
1477{
1478 struct noflush_work *w = container_of(ws, struct noflush_work, worker);
1479 w->tc->requeue_mode = false;
1480 complete_noflush_work(w);
1481}
1482
1483static void noflush_work(struct thin_c *tc, void (*fn)(struct work_struct *))
1484{
1485 struct noflush_work w;
1486
1487 INIT_WORK(&w.worker, fn);
1488 w.tc = tc;
1489 atomic_set(&w.complete, 0);
1490 init_waitqueue_head(&w.wait);
1491
1492 queue_work(tc->pool->wq, &w.worker);
1493
1494 wait_event(w.wait, atomic_read(&w.complete));
1495}
1496
1497/*----------------------------------------------------------------*/
1498
1396static enum pool_mode get_pool_mode(struct pool *pool) 1499static enum pool_mode get_pool_mode(struct pool *pool)
1397{ 1500{
1398 return pool->pf.mode; 1501 return pool->pf.mode;
1399} 1502}
1400 1503
1504static void notify_of_pool_mode_change(struct pool *pool, const char *new_mode)
1505{
1506 dm_table_event(pool->ti->table);
1507 DMINFO("%s: switching pool to %s mode",
1508 dm_device_name(pool->pool_md), new_mode);
1509}
1510
1401static void set_pool_mode(struct pool *pool, enum pool_mode new_mode) 1511static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
1402{ 1512{
1403 int r; 1513 struct pool_c *pt = pool->ti->private;
1404 enum pool_mode old_mode = pool->pf.mode; 1514 bool needs_check = dm_pool_metadata_needs_check(pool->pmd);
1515 enum pool_mode old_mode = get_pool_mode(pool);
1516
1517 /*
1518 * Never allow the pool to transition to PM_WRITE mode if user
1519 * intervention is required to verify metadata and data consistency.
1520 */
1521 if (new_mode == PM_WRITE && needs_check) {
1522 DMERR("%s: unable to switch pool to write mode until repaired.",
1523 dm_device_name(pool->pool_md));
1524 if (old_mode != new_mode)
1525 new_mode = old_mode;
1526 else
1527 new_mode = PM_READ_ONLY;
1528 }
1529 /*
1530 * If we were in PM_FAIL mode, rollback of metadata failed. We're
1531 * not going to recover without a thin_repair. So we never let the
1532 * pool move out of the old mode.
1533 */
1534 if (old_mode == PM_FAIL)
1535 new_mode = old_mode;
1405 1536
1406 switch (new_mode) { 1537 switch (new_mode) {
1407 case PM_FAIL: 1538 case PM_FAIL:
1408 if (old_mode != new_mode) 1539 if (old_mode != new_mode)
1409 DMERR("%s: switching pool to failure mode", 1540 notify_of_pool_mode_change(pool, "failure");
1410 dm_device_name(pool->pool_md));
1411 dm_pool_metadata_read_only(pool->pmd); 1541 dm_pool_metadata_read_only(pool->pmd);
1412 pool->process_bio = process_bio_fail; 1542 pool->process_bio = process_bio_fail;
1413 pool->process_discard = process_bio_fail; 1543 pool->process_discard = process_bio_fail;
1414 pool->process_prepared_mapping = process_prepared_mapping_fail; 1544 pool->process_prepared_mapping = process_prepared_mapping_fail;
1415 pool->process_prepared_discard = process_prepared_discard_fail; 1545 pool->process_prepared_discard = process_prepared_discard_fail;
1546
1547 error_retry_list(pool);
1416 break; 1548 break;
1417 1549
1418 case PM_READ_ONLY: 1550 case PM_READ_ONLY:
1419 if (old_mode != new_mode) 1551 if (old_mode != new_mode)
1420 DMERR("%s: switching pool to read-only mode", 1552 notify_of_pool_mode_change(pool, "read-only");
1421 dm_device_name(pool->pool_md)); 1553 dm_pool_metadata_read_only(pool->pmd);
1422 r = dm_pool_abort_metadata(pool->pmd); 1554 pool->process_bio = process_bio_read_only;
1423 if (r) { 1555 pool->process_discard = process_bio_success;
1424 DMERR("%s: aborting transaction failed", 1556 pool->process_prepared_mapping = process_prepared_mapping_fail;
1425 dm_device_name(pool->pool_md)); 1557 pool->process_prepared_discard = process_prepared_discard_passdown;
1426 new_mode = PM_FAIL; 1558
1427 set_pool_mode(pool, new_mode); 1559 error_retry_list(pool);
1428 } else { 1560 break;
1429 dm_pool_metadata_read_only(pool->pmd); 1561
1430 pool->process_bio = process_bio_read_only; 1562 case PM_OUT_OF_DATA_SPACE:
1431 pool->process_discard = process_discard; 1563 /*
1432 pool->process_prepared_mapping = process_prepared_mapping_fail; 1564 * Ideally we'd never hit this state; the low water mark
1433 pool->process_prepared_discard = process_prepared_discard_passdown; 1565 * would trigger userland to extend the pool before we
1434 } 1566 * completely run out of data space. However, many small
1567 * IOs to unprovisioned space can consume data space at an
1568 * alarming rate. Adjust your low water mark if you're
1569 * frequently seeing this mode.
1570 */
1571 if (old_mode != new_mode)
1572 notify_of_pool_mode_change(pool, "out-of-data-space");
1573 pool->process_bio = process_bio_read_only;
1574 pool->process_discard = process_discard;
1575 pool->process_prepared_mapping = process_prepared_mapping;
1576 pool->process_prepared_discard = process_prepared_discard_passdown;
1435 break; 1577 break;
1436 1578
1437 case PM_WRITE: 1579 case PM_WRITE:
1438 if (old_mode != new_mode) 1580 if (old_mode != new_mode)
1439 DMINFO("%s: switching pool to write mode", 1581 notify_of_pool_mode_change(pool, "write");
1440 dm_device_name(pool->pool_md));
1441 dm_pool_metadata_read_write(pool->pmd); 1582 dm_pool_metadata_read_write(pool->pmd);
1442 pool->process_bio = process_bio; 1583 pool->process_bio = process_bio;
1443 pool->process_discard = process_discard; 1584 pool->process_discard = process_discard;
@@ -1447,32 +1588,35 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
1447 } 1588 }
1448 1589
1449 pool->pf.mode = new_mode; 1590 pool->pf.mode = new_mode;
1591 /*
1592 * The pool mode may have changed, sync it so bind_control_target()
1593 * doesn't cause an unexpected mode transition on resume.
1594 */
1595 pt->adjusted_pf.mode = new_mode;
1450} 1596}
1451 1597
1452/* 1598static void abort_transaction(struct pool *pool)
1453 * Rather than calling set_pool_mode directly, use these which describe the
1454 * reason for mode degradation.
1455 */
1456static void out_of_data_space(struct pool *pool)
1457{ 1599{
1458 DMERR_LIMIT("%s: no free data space available.", 1600 const char *dev_name = dm_device_name(pool->pool_md);
1459 dm_device_name(pool->pool_md)); 1601
1460 set_pool_mode(pool, PM_READ_ONLY); 1602 DMERR_LIMIT("%s: aborting current metadata transaction", dev_name);
1603 if (dm_pool_abort_metadata(pool->pmd)) {
1604 DMERR("%s: failed to abort metadata transaction", dev_name);
1605 set_pool_mode(pool, PM_FAIL);
1606 }
1607
1608 if (dm_pool_metadata_set_needs_check(pool->pmd)) {
1609 DMERR("%s: failed to set 'needs_check' flag in metadata", dev_name);
1610 set_pool_mode(pool, PM_FAIL);
1611 }
1461} 1612}
1462 1613
1463static void metadata_operation_failed(struct pool *pool, const char *op, int r) 1614static void metadata_operation_failed(struct pool *pool, const char *op, int r)
1464{ 1615{
1465 dm_block_t free_blocks;
1466
1467 DMERR_LIMIT("%s: metadata operation '%s' failed: error = %d", 1616 DMERR_LIMIT("%s: metadata operation '%s' failed: error = %d",
1468 dm_device_name(pool->pool_md), op, r); 1617 dm_device_name(pool->pool_md), op, r);
1469 1618
1470 if (r == -ENOSPC && 1619 abort_transaction(pool);
1471 !dm_pool_get_free_metadata_block_count(pool->pmd, &free_blocks) &&
1472 !free_blocks)
1473 DMERR_LIMIT("%s: no free metadata space available.",
1474 dm_device_name(pool->pool_md));
1475
1476 set_pool_mode(pool, PM_READ_ONLY); 1620 set_pool_mode(pool, PM_READ_ONLY);
1477} 1621}
1478 1622
@@ -1523,6 +1667,11 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)
1523 1667
1524 thin_hook_bio(tc, bio); 1668 thin_hook_bio(tc, bio);
1525 1669
1670 if (tc->requeue_mode) {
1671 bio_endio(bio, DM_ENDIO_REQUEUE);
1672 return DM_MAPIO_SUBMITTED;
1673 }
1674
1526 if (get_pool_mode(tc->pool) == PM_FAIL) { 1675 if (get_pool_mode(tc->pool) == PM_FAIL) {
1527 bio_io_error(bio); 1676 bio_io_error(bio);
1528 return DM_MAPIO_SUBMITTED; 1677 return DM_MAPIO_SUBMITTED;
@@ -1686,7 +1835,7 @@ static int bind_control_target(struct pool *pool, struct dm_target *ti)
1686 /* 1835 /*
1687 * We want to make sure that a pool in PM_FAIL mode is never upgraded. 1836 * We want to make sure that a pool in PM_FAIL mode is never upgraded.
1688 */ 1837 */
1689 enum pool_mode old_mode = pool->pf.mode; 1838 enum pool_mode old_mode = get_pool_mode(pool);
1690 enum pool_mode new_mode = pt->adjusted_pf.mode; 1839 enum pool_mode new_mode = pt->adjusted_pf.mode;
1691 1840
1692 /* 1841 /*
@@ -1700,16 +1849,6 @@ static int bind_control_target(struct pool *pool, struct dm_target *ti)
1700 pool->pf = pt->adjusted_pf; 1849 pool->pf = pt->adjusted_pf;
1701 pool->low_water_blocks = pt->low_water_blocks; 1850 pool->low_water_blocks = pt->low_water_blocks;
1702 1851
1703 /*
1704 * If we were in PM_FAIL mode, rollback of metadata failed. We're
1705 * not going to recover without a thin_repair. So we never let the
1706 * pool move out of the old mode. On the other hand a PM_READ_ONLY
1707 * may have been due to a lack of metadata or data space, and may
1708 * now work (ie. if the underlying devices have been resized).
1709 */
1710 if (old_mode == PM_FAIL)
1711 new_mode = old_mode;
1712
1713 set_pool_mode(pool, new_mode); 1852 set_pool_mode(pool, new_mode);
1714 1853
1715 return 0; 1854 return 0;
@@ -1999,16 +2138,27 @@ static void metadata_low_callback(void *context)
1999 dm_table_event(pool->ti->table); 2138 dm_table_event(pool->ti->table);
2000} 2139}
2001 2140
2002static sector_t get_metadata_dev_size(struct block_device *bdev) 2141static sector_t get_dev_size(struct block_device *bdev)
2142{
2143 return i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
2144}
2145
2146static void warn_if_metadata_device_too_big(struct block_device *bdev)
2003{ 2147{
2004 sector_t metadata_dev_size = i_size_read(bdev->bd_inode) >> SECTOR_SHIFT; 2148 sector_t metadata_dev_size = get_dev_size(bdev);
2005 char buffer[BDEVNAME_SIZE]; 2149 char buffer[BDEVNAME_SIZE];
2006 2150
2007 if (metadata_dev_size > THIN_METADATA_MAX_SECTORS_WARNING) { 2151 if (metadata_dev_size > THIN_METADATA_MAX_SECTORS_WARNING)
2008 DMWARN("Metadata device %s is larger than %u sectors: excess space will not be used.", 2152 DMWARN("Metadata device %s is larger than %u sectors: excess space will not be used.",
2009 bdevname(bdev, buffer), THIN_METADATA_MAX_SECTORS); 2153 bdevname(bdev, buffer), THIN_METADATA_MAX_SECTORS);
2010 metadata_dev_size = THIN_METADATA_MAX_SECTORS_WARNING; 2154}
2011 } 2155
2156static sector_t get_metadata_dev_size(struct block_device *bdev)
2157{
2158 sector_t metadata_dev_size = get_dev_size(bdev);
2159
2160 if (metadata_dev_size > THIN_METADATA_MAX_SECTORS)
2161 metadata_dev_size = THIN_METADATA_MAX_SECTORS;
2012 2162
2013 return metadata_dev_size; 2163 return metadata_dev_size;
2014} 2164}
@@ -2017,7 +2167,7 @@ static dm_block_t get_metadata_dev_size_in_blocks(struct block_device *bdev)
2017{ 2167{
2018 sector_t metadata_dev_size = get_metadata_dev_size(bdev); 2168 sector_t metadata_dev_size = get_metadata_dev_size(bdev);
2019 2169
2020 sector_div(metadata_dev_size, THIN_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); 2170 sector_div(metadata_dev_size, THIN_METADATA_BLOCK_SIZE);
2021 2171
2022 return metadata_dev_size; 2172 return metadata_dev_size;
2023} 2173}
@@ -2095,12 +2245,7 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
2095 ti->error = "Error opening metadata block device"; 2245 ti->error = "Error opening metadata block device";
2096 goto out_unlock; 2246 goto out_unlock;
2097 } 2247 }
2098 2248 warn_if_metadata_device_too_big(metadata_dev->bdev);
2099 /*
2100 * Run for the side-effect of possibly issuing a warning if the
2101 * device is too big.
2102 */
2103 (void) get_metadata_dev_size(metadata_dev->bdev);
2104 2249
2105 r = dm_get_device(ti, argv[1], FMODE_READ | FMODE_WRITE, &data_dev); 2250 r = dm_get_device(ti, argv[1], FMODE_READ | FMODE_WRITE, &data_dev);
2106 if (r) { 2251 if (r) {
@@ -2246,6 +2391,12 @@ static int maybe_resize_data_dev(struct dm_target *ti, bool *need_commit)
2246 return -EINVAL; 2391 return -EINVAL;
2247 2392
2248 } else if (data_size > sb_data_size) { 2393 } else if (data_size > sb_data_size) {
2394 if (dm_pool_metadata_needs_check(pool->pmd)) {
2395 DMERR("%s: unable to grow the data device until repaired.",
2396 dm_device_name(pool->pool_md));
2397 return 0;
2398 }
2399
2249 if (sb_data_size) 2400 if (sb_data_size)
2250 DMINFO("%s: growing the data device from %llu to %llu blocks", 2401 DMINFO("%s: growing the data device from %llu to %llu blocks",
2251 dm_device_name(pool->pool_md), 2402 dm_device_name(pool->pool_md),
@@ -2287,6 +2438,13 @@ static int maybe_resize_metadata_dev(struct dm_target *ti, bool *need_commit)
2287 return -EINVAL; 2438 return -EINVAL;
2288 2439
2289 } else if (metadata_dev_size > sb_metadata_dev_size) { 2440 } else if (metadata_dev_size > sb_metadata_dev_size) {
2441 if (dm_pool_metadata_needs_check(pool->pmd)) {
2442 DMERR("%s: unable to grow the metadata device until repaired.",
2443 dm_device_name(pool->pool_md));
2444 return 0;
2445 }
2446
2447 warn_if_metadata_device_too_big(pool->md_dev);
2290 DMINFO("%s: growing the metadata device from %llu to %llu blocks", 2448 DMINFO("%s: growing the metadata device from %llu to %llu blocks",
2291 dm_device_name(pool->pool_md), 2449 dm_device_name(pool->pool_md),
2292 sb_metadata_dev_size, metadata_dev_size); 2450 sb_metadata_dev_size, metadata_dev_size);
@@ -2673,7 +2831,9 @@ static void pool_status(struct dm_target *ti, status_type_t type,
2673 else 2831 else
2674 DMEMIT("- "); 2832 DMEMIT("- ");
2675 2833
2676 if (pool->pf.mode == PM_READ_ONLY) 2834 if (pool->pf.mode == PM_OUT_OF_DATA_SPACE)
2835 DMEMIT("out_of_data_space ");
2836 else if (pool->pf.mode == PM_READ_ONLY)
2677 DMEMIT("ro "); 2837 DMEMIT("ro ");
2678 else 2838 else
2679 DMEMIT("rw "); 2839 DMEMIT("rw ");
@@ -2787,7 +2947,7 @@ static struct target_type pool_target = {
2787 .name = "thin-pool", 2947 .name = "thin-pool",
2788 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE | 2948 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE |
2789 DM_TARGET_IMMUTABLE, 2949 DM_TARGET_IMMUTABLE,
2790 .version = {1, 10, 0}, 2950 .version = {1, 11, 0},
2791 .module = THIS_MODULE, 2951 .module = THIS_MODULE,
2792 .ctr = pool_ctr, 2952 .ctr = pool_ctr,
2793 .dtr = pool_dtr, 2953 .dtr = pool_dtr,
@@ -2894,6 +3054,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2894 3054
2895 if (get_pool_mode(tc->pool) == PM_FAIL) { 3055 if (get_pool_mode(tc->pool) == PM_FAIL) {
2896 ti->error = "Couldn't open thin device, Pool is in fail mode"; 3056 ti->error = "Couldn't open thin device, Pool is in fail mode";
3057 r = -EINVAL;
2897 goto bad_thin_open; 3058 goto bad_thin_open;
2898 } 3059 }
2899 3060
@@ -2905,7 +3066,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2905 3066
2906 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block); 3067 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block);
2907 if (r) 3068 if (r)
2908 goto bad_thin_open; 3069 goto bad_target_max_io_len;
2909 3070
2910 ti->num_flush_bios = 1; 3071 ti->num_flush_bios = 1;
2911 ti->flush_supported = true; 3072 ti->flush_supported = true;
@@ -2926,6 +3087,8 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2926 3087
2927 return 0; 3088 return 0;
2928 3089
3090bad_target_max_io_len:
3091 dm_pool_close_thin_device(tc->td);
2929bad_thin_open: 3092bad_thin_open:
2930 __pool_dec(tc->pool); 3093 __pool_dec(tc->pool);
2931bad_pool_lookup: 3094bad_pool_lookup:
@@ -2986,10 +3149,23 @@ static int thin_endio(struct dm_target *ti, struct bio *bio, int err)
2986 return 0; 3149 return 0;
2987} 3150}
2988 3151
2989static void thin_postsuspend(struct dm_target *ti) 3152static void thin_presuspend(struct dm_target *ti)
2990{ 3153{
3154 struct thin_c *tc = ti->private;
3155
2991 if (dm_noflush_suspending(ti)) 3156 if (dm_noflush_suspending(ti))
2992 requeue_io((struct thin_c *)ti->private); 3157 noflush_work(tc, do_noflush_start);
3158}
3159
3160static void thin_postsuspend(struct dm_target *ti)
3161{
3162 struct thin_c *tc = ti->private;
3163
3164 /*
3165 * The dm_noflush_suspending flag has been cleared by now, so
3166 * unfortunately we must always run this.
3167 */
3168 noflush_work(tc, do_noflush_stop);
2993} 3169}
2994 3170
2995/* 3171/*
@@ -3074,12 +3250,13 @@ static int thin_iterate_devices(struct dm_target *ti,
3074 3250
3075static struct target_type thin_target = { 3251static struct target_type thin_target = {
3076 .name = "thin", 3252 .name = "thin",
3077 .version = {1, 10, 0}, 3253 .version = {1, 11, 0},
3078 .module = THIS_MODULE, 3254 .module = THIS_MODULE,
3079 .ctr = thin_ctr, 3255 .ctr = thin_ctr,
3080 .dtr = thin_dtr, 3256 .dtr = thin_dtr,
3081 .map = thin_map, 3257 .map = thin_map,
3082 .end_io = thin_endio, 3258 .end_io = thin_endio,
3259 .presuspend = thin_presuspend,
3083 .postsuspend = thin_postsuspend, 3260 .postsuspend = thin_postsuspend,
3084 .status = thin_status, 3261 .status = thin_status,
3085 .iterate_devices = thin_iterate_devices, 3262 .iterate_devices = thin_iterate_devices,
diff --git a/drivers/md/persistent-data/Kconfig b/drivers/md/persistent-data/Kconfig
index 19b268795415..0c2dec7aec20 100644
--- a/drivers/md/persistent-data/Kconfig
+++ b/drivers/md/persistent-data/Kconfig
@@ -6,3 +6,13 @@ config DM_PERSISTENT_DATA
6 ---help--- 6 ---help---
7 Library providing immutable on-disk data structure support for 7 Library providing immutable on-disk data structure support for
8 device-mapper targets such as the thin provisioning target. 8 device-mapper targets such as the thin provisioning target.
9
10config DM_DEBUG_BLOCK_STACK_TRACING
11 boolean "Keep stack trace of persistent data block lock holders"
12 depends on STACKTRACE_SUPPORT && DM_PERSISTENT_DATA
13 select STACKTRACE
14 ---help---
15 Enable this for messages that may help debug problems with the
16 block manager locking used by thin provisioning and caching.
17
18 If unsure, say N.
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
index 536782e3bcb7..786b689bdfc7 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -91,6 +91,69 @@ struct block_op {
91 dm_block_t block; 91 dm_block_t block;
92}; 92};
93 93
94struct bop_ring_buffer {
95 unsigned begin;
96 unsigned end;
97 struct block_op bops[MAX_RECURSIVE_ALLOCATIONS + 1];
98};
99
100static void brb_init(struct bop_ring_buffer *brb)
101{
102 brb->begin = 0;
103 brb->end = 0;
104}
105
106static bool brb_empty(struct bop_ring_buffer *brb)
107{
108 return brb->begin == brb->end;
109}
110
111static unsigned brb_next(struct bop_ring_buffer *brb, unsigned old)
112{
113 unsigned r = old + 1;
114 return (r >= (sizeof(brb->bops) / sizeof(*brb->bops))) ? 0 : r;
115}
116
117static int brb_push(struct bop_ring_buffer *brb,
118 enum block_op_type type, dm_block_t b)
119{
120 struct block_op *bop;
121 unsigned next = brb_next(brb, brb->end);
122
123 /*
124 * We don't allow the last bop to be filled, this way we can
125 * differentiate between full and empty.
126 */
127 if (next == brb->begin)
128 return -ENOMEM;
129
130 bop = brb->bops + brb->end;
131 bop->type = type;
132 bop->block = b;
133
134 brb->end = next;
135
136 return 0;
137}
138
139static int brb_pop(struct bop_ring_buffer *brb, struct block_op *result)
140{
141 struct block_op *bop;
142
143 if (brb_empty(brb))
144 return -ENODATA;
145
146 bop = brb->bops + brb->begin;
147 result->type = bop->type;
148 result->block = bop->block;
149
150 brb->begin = brb_next(brb, brb->begin);
151
152 return 0;
153}
154
155/*----------------------------------------------------------------*/
156
94struct sm_metadata { 157struct sm_metadata {
95 struct dm_space_map sm; 158 struct dm_space_map sm;
96 159
@@ -101,25 +164,20 @@ struct sm_metadata {
101 164
102 unsigned recursion_count; 165 unsigned recursion_count;
103 unsigned allocated_this_transaction; 166 unsigned allocated_this_transaction;
104 unsigned nr_uncommitted; 167 struct bop_ring_buffer uncommitted;
105 struct block_op uncommitted[MAX_RECURSIVE_ALLOCATIONS];
106 168
107 struct threshold threshold; 169 struct threshold threshold;
108}; 170};
109 171
110static int add_bop(struct sm_metadata *smm, enum block_op_type type, dm_block_t b) 172static int add_bop(struct sm_metadata *smm, enum block_op_type type, dm_block_t b)
111{ 173{
112 struct block_op *op; 174 int r = brb_push(&smm->uncommitted, type, b);
113 175
114 if (smm->nr_uncommitted == MAX_RECURSIVE_ALLOCATIONS) { 176 if (r) {
115 DMERR("too many recursive allocations"); 177 DMERR("too many recursive allocations");
116 return -ENOMEM; 178 return -ENOMEM;
117 } 179 }
118 180
119 op = smm->uncommitted + smm->nr_uncommitted++;
120 op->type = type;
121 op->block = b;
122
123 return 0; 181 return 0;
124} 182}
125 183
@@ -158,11 +216,17 @@ static int out(struct sm_metadata *smm)
158 return -ENOMEM; 216 return -ENOMEM;
159 } 217 }
160 218
161 if (smm->recursion_count == 1 && smm->nr_uncommitted) { 219 if (smm->recursion_count == 1) {
162 while (smm->nr_uncommitted && !r) { 220 while (!brb_empty(&smm->uncommitted)) {
163 smm->nr_uncommitted--; 221 struct block_op bop;
164 r = commit_bop(smm, smm->uncommitted + 222
165 smm->nr_uncommitted); 223 r = brb_pop(&smm->uncommitted, &bop);
224 if (r) {
225 DMERR("bug in bop ring buffer");
226 break;
227 }
228
229 r = commit_bop(smm, &bop);
166 if (r) 230 if (r)
167 break; 231 break;
168 } 232 }
@@ -217,7 +281,8 @@ static int sm_metadata_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
217static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b, 281static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b,
218 uint32_t *result) 282 uint32_t *result)
219{ 283{
220 int r, i; 284 int r;
285 unsigned i;
221 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm); 286 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
222 unsigned adjustment = 0; 287 unsigned adjustment = 0;
223 288
@@ -225,8 +290,10 @@ static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b,
225 * We may have some uncommitted adjustments to add. This list 290 * We may have some uncommitted adjustments to add. This list
226 * should always be really short. 291 * should always be really short.
227 */ 292 */
228 for (i = 0; i < smm->nr_uncommitted; i++) { 293 for (i = smm->uncommitted.begin;
229 struct block_op *op = smm->uncommitted + i; 294 i != smm->uncommitted.end;
295 i = brb_next(&smm->uncommitted, i)) {
296 struct block_op *op = smm->uncommitted.bops + i;
230 297
231 if (op->block != b) 298 if (op->block != b)
232 continue; 299 continue;
@@ -254,7 +321,8 @@ static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b,
254static int sm_metadata_count_is_more_than_one(struct dm_space_map *sm, 321static int sm_metadata_count_is_more_than_one(struct dm_space_map *sm,
255 dm_block_t b, int *result) 322 dm_block_t b, int *result)
256{ 323{
257 int r, i, adjustment = 0; 324 int r, adjustment = 0;
325 unsigned i;
258 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm); 326 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
259 uint32_t rc; 327 uint32_t rc;
260 328
@@ -262,8 +330,11 @@ static int sm_metadata_count_is_more_than_one(struct dm_space_map *sm,
262 * We may have some uncommitted adjustments to add. This list 330 * We may have some uncommitted adjustments to add. This list
263 * should always be really short. 331 * should always be really short.
264 */ 332 */
265 for (i = 0; i < smm->nr_uncommitted; i++) { 333 for (i = smm->uncommitted.begin;
266 struct block_op *op = smm->uncommitted + i; 334 i != smm->uncommitted.end;
335 i = brb_next(&smm->uncommitted, i)) {
336
337 struct block_op *op = smm->uncommitted.bops + i;
267 338
268 if (op->block != b) 339 if (op->block != b)
269 continue; 340 continue;
@@ -671,7 +742,7 @@ int dm_sm_metadata_create(struct dm_space_map *sm,
671 smm->begin = superblock + 1; 742 smm->begin = superblock + 1;
672 smm->recursion_count = 0; 743 smm->recursion_count = 0;
673 smm->allocated_this_transaction = 0; 744 smm->allocated_this_transaction = 0;
674 smm->nr_uncommitted = 0; 745 brb_init(&smm->uncommitted);
675 threshold_init(&smm->threshold); 746 threshold_init(&smm->threshold);
676 747
677 memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm)); 748 memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm));
@@ -680,6 +751,8 @@ int dm_sm_metadata_create(struct dm_space_map *sm,
680 if (r) 751 if (r)
681 return r; 752 return r;
682 753
754 if (nr_blocks > DM_SM_METADATA_MAX_BLOCKS)
755 nr_blocks = DM_SM_METADATA_MAX_BLOCKS;
683 r = sm_ll_extend(&smm->ll, nr_blocks); 756 r = sm_ll_extend(&smm->ll, nr_blocks);
684 if (r) 757 if (r)
685 return r; 758 return r;
@@ -713,7 +786,7 @@ int dm_sm_metadata_open(struct dm_space_map *sm,
713 smm->begin = 0; 786 smm->begin = 0;
714 smm->recursion_count = 0; 787 smm->recursion_count = 0;
715 smm->allocated_this_transaction = 0; 788 smm->allocated_this_transaction = 0;
716 smm->nr_uncommitted = 0; 789 brb_init(&smm->uncommitted);
717 threshold_init(&smm->threshold); 790 threshold_init(&smm->threshold);
718 791
719 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll)); 792 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll));
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.h b/drivers/md/persistent-data/dm-space-map-metadata.h
index 39bba0801cf2..64df923974d8 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.h
+++ b/drivers/md/persistent-data/dm-space-map-metadata.h
@@ -9,6 +9,17 @@
9 9
10#include "dm-transaction-manager.h" 10#include "dm-transaction-manager.h"
11 11
12#define DM_SM_METADATA_BLOCK_SIZE (4096 >> SECTOR_SHIFT)
13
14/*
15 * The metadata device is currently limited in size.
16 *
17 * We have one block of index, which can hold 255 index entries. Each
18 * index entry contains allocation info about ~16k metadata blocks.
19 */
20#define DM_SM_METADATA_MAX_BLOCKS (255 * ((1 << 14) - 64))
21#define DM_SM_METADATA_MAX_SECTORS (DM_SM_METADATA_MAX_BLOCKS * DM_SM_METADATA_BLOCK_SIZE)
22
12/* 23/*
13 * Unfortunately we have to use two-phase construction due to the cycle 24 * Unfortunately we have to use two-phase construction due to the cycle
14 * between the tm and sm. 25 * between the tm and sm.
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index fd3a2a14b587..4a6ca1cb2e78 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1953,11 +1953,15 @@ static int process_checks(struct r1bio *r1_bio)
1953 for (i = 0; i < conf->raid_disks * 2; i++) { 1953 for (i = 0; i < conf->raid_disks * 2; i++) {
1954 int j; 1954 int j;
1955 int size; 1955 int size;
1956 int uptodate;
1956 struct bio *b = r1_bio->bios[i]; 1957 struct bio *b = r1_bio->bios[i];
1957 if (b->bi_end_io != end_sync_read) 1958 if (b->bi_end_io != end_sync_read)
1958 continue; 1959 continue;
1959 /* fixup the bio for reuse */ 1960 /* fixup the bio for reuse, but preserve BIO_UPTODATE */
1961 uptodate = test_bit(BIO_UPTODATE, &b->bi_flags);
1960 bio_reset(b); 1962 bio_reset(b);
1963 if (!uptodate)
1964 clear_bit(BIO_UPTODATE, &b->bi_flags);
1961 b->bi_vcnt = vcnt; 1965 b->bi_vcnt = vcnt;
1962 b->bi_iter.bi_size = r1_bio->sectors << 9; 1966 b->bi_iter.bi_size = r1_bio->sectors << 9;
1963 b->bi_iter.bi_sector = r1_bio->sector + 1967 b->bi_iter.bi_sector = r1_bio->sector +
@@ -1990,11 +1994,14 @@ static int process_checks(struct r1bio *r1_bio)
1990 int j; 1994 int j;
1991 struct bio *pbio = r1_bio->bios[primary]; 1995 struct bio *pbio = r1_bio->bios[primary];
1992 struct bio *sbio = r1_bio->bios[i]; 1996 struct bio *sbio = r1_bio->bios[i];
1997 int uptodate = test_bit(BIO_UPTODATE, &sbio->bi_flags);
1993 1998
1994 if (sbio->bi_end_io != end_sync_read) 1999 if (sbio->bi_end_io != end_sync_read)
1995 continue; 2000 continue;
2001 /* Now we can 'fixup' the BIO_UPTODATE flag */
2002 set_bit(BIO_UPTODATE, &sbio->bi_flags);
1996 2003
1997 if (test_bit(BIO_UPTODATE, &sbio->bi_flags)) { 2004 if (uptodate) {
1998 for (j = vcnt; j-- ; ) { 2005 for (j = vcnt; j-- ; ) {
1999 struct page *p, *s; 2006 struct page *p, *s;
2000 p = pbio->bi_io_vec[j].bv_page; 2007 p = pbio->bi_io_vec[j].bv_page;
@@ -2009,7 +2016,7 @@ static int process_checks(struct r1bio *r1_bio)
2009 if (j >= 0) 2016 if (j >= 0)
2010 atomic64_add(r1_bio->sectors, &mddev->resync_mismatches); 2017 atomic64_add(r1_bio->sectors, &mddev->resync_mismatches);
2011 if (j < 0 || (test_bit(MD_RECOVERY_CHECK, &mddev->recovery) 2018 if (j < 0 || (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)
2012 && test_bit(BIO_UPTODATE, &sbio->bi_flags))) { 2019 && uptodate)) {
2013 /* No need to write to this device. */ 2020 /* No need to write to this device. */
2014 sbio->bi_end_io = NULL; 2021 sbio->bi_end_io = NULL;
2015 rdev_dec_pending(conf->mirrors[i].rdev, mddev); 2022 rdev_dec_pending(conf->mirrors[i].rdev, mddev);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index f1feadeb7bb2..16f5c21963db 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -5514,23 +5514,43 @@ raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks)
5514 return sectors * (raid_disks - conf->max_degraded); 5514 return sectors * (raid_disks - conf->max_degraded);
5515} 5515}
5516 5516
5517static void free_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu)
5518{
5519 safe_put_page(percpu->spare_page);
5520 kfree(percpu->scribble);
5521 percpu->spare_page = NULL;
5522 percpu->scribble = NULL;
5523}
5524
5525static int alloc_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu)
5526{
5527 if (conf->level == 6 && !percpu->spare_page)
5528 percpu->spare_page = alloc_page(GFP_KERNEL);
5529 if (!percpu->scribble)
5530 percpu->scribble = kmalloc(conf->scribble_len, GFP_KERNEL);
5531
5532 if (!percpu->scribble || (conf->level == 6 && !percpu->spare_page)) {
5533 free_scratch_buffer(conf, percpu);
5534 return -ENOMEM;
5535 }
5536
5537 return 0;
5538}
5539
5517static void raid5_free_percpu(struct r5conf *conf) 5540static void raid5_free_percpu(struct r5conf *conf)
5518{ 5541{
5519 struct raid5_percpu *percpu;
5520 unsigned long cpu; 5542 unsigned long cpu;
5521 5543
5522 if (!conf->percpu) 5544 if (!conf->percpu)
5523 return; 5545 return;
5524 5546
5525 get_online_cpus();
5526 for_each_possible_cpu(cpu) {
5527 percpu = per_cpu_ptr(conf->percpu, cpu);
5528 safe_put_page(percpu->spare_page);
5529 kfree(percpu->scribble);
5530 }
5531#ifdef CONFIG_HOTPLUG_CPU 5547#ifdef CONFIG_HOTPLUG_CPU
5532 unregister_cpu_notifier(&conf->cpu_notify); 5548 unregister_cpu_notifier(&conf->cpu_notify);
5533#endif 5549#endif
5550
5551 get_online_cpus();
5552 for_each_possible_cpu(cpu)
5553 free_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu));
5534 put_online_cpus(); 5554 put_online_cpus();
5535 5555
5536 free_percpu(conf->percpu); 5556 free_percpu(conf->percpu);
@@ -5557,15 +5577,7 @@ static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action,
5557 switch (action) { 5577 switch (action) {
5558 case CPU_UP_PREPARE: 5578 case CPU_UP_PREPARE:
5559 case CPU_UP_PREPARE_FROZEN: 5579 case CPU_UP_PREPARE_FROZEN:
5560 if (conf->level == 6 && !percpu->spare_page) 5580 if (alloc_scratch_buffer(conf, percpu)) {
5561 percpu->spare_page = alloc_page(GFP_KERNEL);
5562 if (!percpu->scribble)
5563 percpu->scribble = kmalloc(conf->scribble_len, GFP_KERNEL);
5564
5565 if (!percpu->scribble ||
5566 (conf->level == 6 && !percpu->spare_page)) {
5567 safe_put_page(percpu->spare_page);
5568 kfree(percpu->scribble);
5569 pr_err("%s: failed memory allocation for cpu%ld\n", 5581 pr_err("%s: failed memory allocation for cpu%ld\n",
5570 __func__, cpu); 5582 __func__, cpu);
5571 return notifier_from_errno(-ENOMEM); 5583 return notifier_from_errno(-ENOMEM);
@@ -5573,10 +5585,7 @@ static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action,
5573 break; 5585 break;
5574 case CPU_DEAD: 5586 case CPU_DEAD:
5575 case CPU_DEAD_FROZEN: 5587 case CPU_DEAD_FROZEN:
5576 safe_put_page(percpu->spare_page); 5588 free_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu));
5577 kfree(percpu->scribble);
5578 percpu->spare_page = NULL;
5579 percpu->scribble = NULL;
5580 break; 5589 break;
5581 default: 5590 default:
5582 break; 5591 break;
@@ -5588,40 +5597,29 @@ static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action,
5588static int raid5_alloc_percpu(struct r5conf *conf) 5597static int raid5_alloc_percpu(struct r5conf *conf)
5589{ 5598{
5590 unsigned long cpu; 5599 unsigned long cpu;
5591 struct page *spare_page; 5600 int err = 0;
5592 struct raid5_percpu __percpu *allcpus;
5593 void *scribble;
5594 int err;
5595 5601
5596 allcpus = alloc_percpu(struct raid5_percpu); 5602 conf->percpu = alloc_percpu(struct raid5_percpu);
5597 if (!allcpus) 5603 if (!conf->percpu)
5598 return -ENOMEM; 5604 return -ENOMEM;
5599 conf->percpu = allcpus; 5605
5606#ifdef CONFIG_HOTPLUG_CPU
5607 conf->cpu_notify.notifier_call = raid456_cpu_notify;
5608 conf->cpu_notify.priority = 0;
5609 err = register_cpu_notifier(&conf->cpu_notify);
5610 if (err)
5611 return err;
5612#endif
5600 5613
5601 get_online_cpus(); 5614 get_online_cpus();
5602 err = 0;
5603 for_each_present_cpu(cpu) { 5615 for_each_present_cpu(cpu) {
5604 if (conf->level == 6) { 5616 err = alloc_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu));
5605 spare_page = alloc_page(GFP_KERNEL); 5617 if (err) {
5606 if (!spare_page) { 5618 pr_err("%s: failed memory allocation for cpu%ld\n",
5607 err = -ENOMEM; 5619 __func__, cpu);
5608 break;
5609 }
5610 per_cpu_ptr(conf->percpu, cpu)->spare_page = spare_page;
5611 }
5612 scribble = kmalloc(conf->scribble_len, GFP_KERNEL);
5613 if (!scribble) {
5614 err = -ENOMEM;
5615 break; 5620 break;
5616 } 5621 }
5617 per_cpu_ptr(conf->percpu, cpu)->scribble = scribble;
5618 } 5622 }
5619#ifdef CONFIG_HOTPLUG_CPU
5620 conf->cpu_notify.notifier_call = raid456_cpu_notify;
5621 conf->cpu_notify.priority = 0;
5622 if (err == 0)
5623 err = register_cpu_notifier(&conf->cpu_notify);
5624#endif
5625 put_online_cpus(); 5623 put_online_cpus();
5626 5624
5627 return err; 5625 return err;
diff --git a/drivers/media/dvb-frontends/cx24117.c b/drivers/media/dvb-frontends/cx24117.c
index 68f768a5422d..a6c3c9e2e897 100644
--- a/drivers/media/dvb-frontends/cx24117.c
+++ b/drivers/media/dvb-frontends/cx24117.c
@@ -1176,7 +1176,7 @@ struct dvb_frontend *cx24117_attach(const struct cx24117_config *config,
1176 1176
1177 switch (demod) { 1177 switch (demod) {
1178 case 0: 1178 case 0:
1179 dev_err(&state->priv->i2c->dev, 1179 dev_err(&i2c->dev,
1180 "%s: Error attaching frontend %d\n", 1180 "%s: Error attaching frontend %d\n",
1181 KBUILD_MODNAME, demod); 1181 KBUILD_MODNAME, demod);
1182 goto error1; 1182 goto error1;
@@ -1200,12 +1200,6 @@ struct dvb_frontend *cx24117_attach(const struct cx24117_config *config,
1200 state->demod = demod - 1; 1200 state->demod = demod - 1;
1201 state->priv = priv; 1201 state->priv = priv;
1202 1202
1203 /* test i2c bus for ack */
1204 if (demod == 0) {
1205 if (cx24117_readreg(state, 0x00) < 0)
1206 goto error3;
1207 }
1208
1209 dev_info(&state->priv->i2c->dev, 1203 dev_info(&state->priv->i2c->dev,
1210 "%s: Attaching frontend %d\n", 1204 "%s: Attaching frontend %d\n",
1211 KBUILD_MODNAME, state->demod); 1205 KBUILD_MODNAME, state->demod);
@@ -1216,8 +1210,6 @@ struct dvb_frontend *cx24117_attach(const struct cx24117_config *config,
1216 state->frontend.demodulator_priv = state; 1210 state->frontend.demodulator_priv = state;
1217 return &state->frontend; 1211 return &state->frontend;
1218 1212
1219error3:
1220 kfree(state);
1221error2: 1213error2:
1222 cx24117_release_priv(priv); 1214 cx24117_release_priv(priv);
1223error1: 1215error1:
diff --git a/drivers/media/dvb-frontends/nxt200x.c b/drivers/media/dvb-frontends/nxt200x.c
index 4bf057544607..8a8e1ecb762d 100644
--- a/drivers/media/dvb-frontends/nxt200x.c
+++ b/drivers/media/dvb-frontends/nxt200x.c
@@ -2,7 +2,7 @@
2 * Support for NXT2002 and NXT2004 - VSB/QAM 2 * Support for NXT2002 and NXT2004 - VSB/QAM
3 * 3 *
4 * Copyright (C) 2005 Kirk Lapray <kirk.lapray@gmail.com> 4 * Copyright (C) 2005 Kirk Lapray <kirk.lapray@gmail.com>
5 * Copyright (C) 2006 Michael Krufky <mkrufky@m1k.net> 5 * Copyright (C) 2006-2014 Michael Krufky <mkrufky@linuxtv.org>
6 * based on nxt2002 by Taylor Jacob <rtjacob@earthlink.net> 6 * based on nxt2002 by Taylor Jacob <rtjacob@earthlink.net>
7 * and nxt2004 by Jean-Francois Thibert <jeanfrancois@sagetv.com> 7 * and nxt2004 by Jean-Francois Thibert <jeanfrancois@sagetv.com>
8 * 8 *
diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 1effc21e1cdd..9bbd6656fb8f 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -2554,7 +2554,7 @@ static int adv7842_core_init(struct v4l2_subdev *sd)
2554 sdp_write_and_or(sd, 0xdd, 0xf0, pdata->sdp_free_run_force | 2554 sdp_write_and_or(sd, 0xdd, 0xf0, pdata->sdp_free_run_force |
2555 (pdata->sdp_free_run_cbar_en << 1) | 2555 (pdata->sdp_free_run_cbar_en << 1) |
2556 (pdata->sdp_free_run_man_col_en << 2) | 2556 (pdata->sdp_free_run_man_col_en << 2) |
2557 (pdata->sdp_free_run_force << 3)); 2557 (pdata->sdp_free_run_auto << 3));
2558 2558
2559 /* TODO from platform data */ 2559 /* TODO from platform data */
2560 cp_write(sd, 0x69, 0x14); /* Enable CP CSC */ 2560 cp_write(sd, 0x69, 0x14); /* Enable CP CSC */
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 4b8381111cbd..77e10e0fd8d6 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -478,25 +478,33 @@ static void s5k5baf_write_arr_seq(struct s5k5baf *state, u16 addr,
478 u16 count, const u16 *seq) 478 u16 count, const u16 *seq)
479{ 479{
480 struct i2c_client *c = v4l2_get_subdevdata(&state->sd); 480 struct i2c_client *c = v4l2_get_subdevdata(&state->sd);
481 __be16 buf[count + 1]; 481 __be16 buf[65];
482 int ret, n;
483 482
484 s5k5baf_i2c_write(state, REG_CMDWR_ADDR, addr); 483 s5k5baf_i2c_write(state, REG_CMDWR_ADDR, addr);
485 if (state->error) 484 if (state->error)
486 return; 485 return;
487 486
487 v4l2_dbg(3, debug, c, "i2c_write_seq(count=%d): %*ph\n", count,
488 min(2 * count, 64), seq);
489
488 buf[0] = __constant_cpu_to_be16(REG_CMD_BUF); 490 buf[0] = __constant_cpu_to_be16(REG_CMD_BUF);
489 for (n = 1; n <= count; ++n)
490 buf[n] = cpu_to_be16(*seq++);
491 491
492 n *= 2; 492 while (count > 0) {
493 ret = i2c_master_send(c, (char *)buf, n); 493 int n = min_t(int, count, ARRAY_SIZE(buf) - 1);
494 v4l2_dbg(3, debug, c, "i2c_write_seq(count=%d): %*ph\n", count, 494 int ret, i;
495 min(2 * count, 64), seq - count);
496 495
497 if (ret != n) { 496 for (i = 1; i <= n; ++i)
498 v4l2_err(c, "i2c_write_seq: error during transfer (%d)\n", ret); 497 buf[i] = cpu_to_be16(*seq++);
499 state->error = ret; 498
499 i *= 2;
500 ret = i2c_master_send(c, (char *)buf, i);
501 if (ret != i) {
502 v4l2_err(c, "i2c_write_seq: error during transfer (%d)\n", ret);
503 state->error = ret;
504 break;
505 }
506
507 count -= n;
500 } 508 }
501} 509}
502 510
diff --git a/drivers/media/pci/bt8xx/bttv-cards.c b/drivers/media/pci/bt8xx/bttv-cards.c
index d85cb0ace4dc..6662b495b22c 100644
--- a/drivers/media/pci/bt8xx/bttv-cards.c
+++ b/drivers/media/pci/bt8xx/bttv-cards.c
@@ -2426,7 +2426,7 @@ struct tvcard bttv_tvcards[] = {
2426 }, 2426 },
2427 /* ---- card 0x87---------------------------------- */ 2427 /* ---- card 0x87---------------------------------- */
2428 [BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE] = { 2428 [BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE] = {
2429 /* Michael Krufky <mkrufky@m1k.net> */ 2429 /* Michael Krufky <mkrufky@linuxtv.org> */
2430 .name = "DViCO FusionHDTV 5 Lite", 2430 .name = "DViCO FusionHDTV 5 Lite",
2431 .tuner_type = TUNER_LG_TDVS_H06XF, /* TDVS-H064F */ 2431 .tuner_type = TUNER_LG_TDVS_H06XF, /* TDVS-H064F */
2432 .tuner_addr = ADDR_UNSET, 2432 .tuner_addr = ADDR_UNSET,
diff --git a/drivers/media/pci/bt8xx/bttv-gpio.c b/drivers/media/pci/bt8xx/bttv-gpio.c
index 922e8233fd0b..3f364b7062b9 100644
--- a/drivers/media/pci/bt8xx/bttv-gpio.c
+++ b/drivers/media/pci/bt8xx/bttv-gpio.c
@@ -98,7 +98,7 @@ int bttv_sub_add_device(struct bttv_core *core, char *name)
98 98
99 err = device_register(&sub->dev); 99 err = device_register(&sub->dev);
100 if (0 != err) { 100 if (0 != err) {
101 kfree(sub); 101 put_device(&sub->dev);
102 return err; 102 return err;
103 } 103 }
104 pr_info("%d: add subdevice \"%s\"\n", core->nr, dev_name(&sub->dev)); 104 pr_info("%d: add subdevice \"%s\"\n", core->nr, dev_name(&sub->dev));
diff --git a/drivers/media/pci/saa7134/saa7134-cards.c b/drivers/media/pci/saa7134/saa7134-cards.c
index d45e7f6ff332..c9b2350e92c8 100644
--- a/drivers/media/pci/saa7134/saa7134-cards.c
+++ b/drivers/media/pci/saa7134/saa7134-cards.c
@@ -2590,7 +2590,7 @@ struct saa7134_board saa7134_boards[] = {
2590 }}, 2590 }},
2591 }, 2591 },
2592 [SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180] = { 2592 [SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180] = {
2593 /* Michael Krufky <mkrufky@m1k.net> 2593 /* Michael Krufky <mkrufky@linuxtv.org>
2594 * Uses Alps Electric TDHU2, containing NXT2004 ATSC Decoder 2594 * Uses Alps Electric TDHU2, containing NXT2004 ATSC Decoder
2595 * AFAIK, there is no analog demod, thus, 2595 * AFAIK, there is no analog demod, thus,
2596 * no support for analog television. 2596 * no support for analog television.
diff --git a/drivers/media/platform/exynos4-is/fimc-core.c b/drivers/media/platform/exynos4-is/fimc-core.c
index a7dfd07e8389..da2fc86cc524 100644
--- a/drivers/media/platform/exynos4-is/fimc-core.c
+++ b/drivers/media/platform/exynos4-is/fimc-core.c
@@ -1027,7 +1027,8 @@ static int fimc_probe(struct platform_device *pdev)
1027 return 0; 1027 return 0;
1028 1028
1029err_gclk: 1029err_gclk:
1030 clk_disable(fimc->clock[CLK_GATE]); 1030 if (!pm_runtime_enabled(dev))
1031 clk_disable(fimc->clock[CLK_GATE]);
1031err_sd: 1032err_sd:
1032 fimc_unregister_capture_subdev(fimc); 1033 fimc_unregister_capture_subdev(fimc);
1033err_sclk: 1034err_sclk:
@@ -1036,6 +1037,7 @@ err_sclk:
1036 return ret; 1037 return ret;
1037} 1038}
1038 1039
1040#ifdef CONFIG_PM_RUNTIME
1039static int fimc_runtime_resume(struct device *dev) 1041static int fimc_runtime_resume(struct device *dev)
1040{ 1042{
1041 struct fimc_dev *fimc = dev_get_drvdata(dev); 1043 struct fimc_dev *fimc = dev_get_drvdata(dev);
@@ -1068,6 +1070,7 @@ static int fimc_runtime_suspend(struct device *dev)
1068 dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state); 1070 dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
1069 return ret; 1071 return ret;
1070} 1072}
1073#endif
1071 1074
1072#ifdef CONFIG_PM_SLEEP 1075#ifdef CONFIG_PM_SLEEP
1073static int fimc_resume(struct device *dev) 1076static int fimc_resume(struct device *dev)
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index 1234734bccf4..779ec3cd259d 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -1563,7 +1563,7 @@ static int fimc_lite_probe(struct platform_device *pdev)
1563 if (!pm_runtime_enabled(dev)) { 1563 if (!pm_runtime_enabled(dev)) {
1564 ret = clk_enable(fimc->clock); 1564 ret = clk_enable(fimc->clock);
1565 if (ret < 0) 1565 if (ret < 0)
1566 goto err_clk_put; 1566 goto err_sd;
1567 } 1567 }
1568 1568
1569 fimc->alloc_ctx = vb2_dma_contig_init_ctx(dev); 1569 fimc->alloc_ctx = vb2_dma_contig_init_ctx(dev);
@@ -1579,7 +1579,8 @@ static int fimc_lite_probe(struct platform_device *pdev)
1579 return 0; 1579 return 0;
1580 1580
1581err_clk_dis: 1581err_clk_dis:
1582 clk_disable(fimc->clock); 1582 if (!pm_runtime_enabled(dev))
1583 clk_disable(fimc->clock);
1583err_sd: 1584err_sd:
1584 fimc_lite_unregister_capture_subdev(fimc); 1585 fimc_lite_unregister_capture_subdev(fimc);
1585err_clk_put: 1586err_clk_put:
@@ -1587,6 +1588,7 @@ err_clk_put:
1587 return ret; 1588 return ret;
1588} 1589}
1589 1590
1591#ifdef CONFIG_PM_RUNTIME
1590static int fimc_lite_runtime_resume(struct device *dev) 1592static int fimc_lite_runtime_resume(struct device *dev)
1591{ 1593{
1592 struct fimc_lite *fimc = dev_get_drvdata(dev); 1594 struct fimc_lite *fimc = dev_get_drvdata(dev);
@@ -1602,6 +1604,7 @@ static int fimc_lite_runtime_suspend(struct device *dev)
1602 clk_disable(fimc->clock); 1604 clk_disable(fimc->clock);
1603 return 0; 1605 return 0;
1604} 1606}
1607#endif
1605 1608
1606#ifdef CONFIG_PM_SLEEP 1609#ifdef CONFIG_PM_SLEEP
1607static int fimc_lite_resume(struct device *dev) 1610static int fimc_lite_resume(struct device *dev)
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index a1c78c870b68..7d68d0b9966a 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -175,7 +175,7 @@ static struct s5p_jpeg_fmt sjpeg_formats[] = {
175 { 175 {
176 .name = "YUV 4:2:0 planar, Y/CbCr", 176 .name = "YUV 4:2:0 planar, Y/CbCr",
177 .fourcc = V4L2_PIX_FMT_NV12, 177 .fourcc = V4L2_PIX_FMT_NV12,
178 .depth = 16, 178 .depth = 12,
179 .colplanes = 2, 179 .colplanes = 2,
180 .h_align = 1, 180 .h_align = 1,
181 .v_align = 1, 181 .v_align = 1,
@@ -188,10 +188,10 @@ static struct s5p_jpeg_fmt sjpeg_formats[] = {
188 { 188 {
189 .name = "YUV 4:2:0 planar, Y/CbCr", 189 .name = "YUV 4:2:0 planar, Y/CbCr",
190 .fourcc = V4L2_PIX_FMT_NV12, 190 .fourcc = V4L2_PIX_FMT_NV12,
191 .depth = 16, 191 .depth = 12,
192 .colplanes = 4, 192 .colplanes = 2,
193 .h_align = 4, 193 .h_align = 4,
194 .v_align = 1, 194 .v_align = 4,
195 .flags = SJPEG_FMT_FLAG_ENC_OUTPUT | 195 .flags = SJPEG_FMT_FLAG_ENC_OUTPUT |
196 SJPEG_FMT_FLAG_DEC_CAPTURE | 196 SJPEG_FMT_FLAG_DEC_CAPTURE |
197 SJPEG_FMT_FLAG_S5P | 197 SJPEG_FMT_FLAG_S5P |
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index 8f9b2cea88f0..8ede8ea762e6 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -1539,6 +1539,8 @@ static const struct usb_device_id af9035_id_table[] = {
1539 &af9035_props, "TerraTec Cinergy T Stick Dual RC (rev. 2)", NULL) }, 1539 &af9035_props, "TerraTec Cinergy T Stick Dual RC (rev. 2)", NULL) },
1540 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a05, 1540 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a05,
1541 &af9035_props, "Leadtek WinFast DTV Dongle Dual", NULL) }, 1541 &af9035_props, "Leadtek WinFast DTV Dongle Dual", NULL) },
1542 { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xf900,
1543 &af9035_props, "Hauppauge WinTV-MiniStick 2", NULL) },
1542 { } 1544 { }
1543}; 1545};
1544MODULE_DEVICE_TABLE(usb, af9035_id_table); 1546MODULE_DEVICE_TABLE(usb, af9035_id_table);
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c
index d83df4bb72d3..0a98d04c53e4 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-demod.c - driver for the MaxLinear MXL111SF DVB-T demodulator 2 * mxl111sf-demod.c - driver for the MaxLinear MXL111SF DVB-T demodulator
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -601,7 +601,7 @@ struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state,
601EXPORT_SYMBOL_GPL(mxl111sf_demod_attach); 601EXPORT_SYMBOL_GPL(mxl111sf_demod_attach);
602 602
603MODULE_DESCRIPTION("MaxLinear MxL111SF DVB-T demodulator driver"); 603MODULE_DESCRIPTION("MaxLinear MxL111SF DVB-T demodulator driver");
604MODULE_AUTHOR("Michael Krufky <mkrufky@kernellabs.com>"); 604MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
605MODULE_LICENSE("GPL"); 605MODULE_LICENSE("GPL");
606MODULE_VERSION("0.1"); 606MODULE_VERSION("0.1");
607 607
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h
index 3f3f8bfd190b..2d4530f5be54 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-demod.h - driver for the MaxLinear MXL111SF DVB-T demodulator 2 * mxl111sf-demod.h - driver for the MaxLinear MXL111SF DVB-T demodulator
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c
index e4121cb8f5ef..a619410adde4 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-gpio.c - driver for the MaxLinear MXL111SF 2 * mxl111sf-gpio.c - driver for the MaxLinear MXL111SF
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h
index 0220f54299a5..b85a5772d771 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-gpio.h - driver for the MaxLinear MXL111SF 2 * mxl111sf-gpio.h - driver for the MaxLinear MXL111SF
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
index 34434557ef65..a101d06eb143 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-i2c.c - driver for the MaxLinear MXL111SF 2 * mxl111sf-i2c.c - driver for the MaxLinear MXL111SF
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h
index a57a45ffb9e4..465762145ad2 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-i2c.h - driver for the MaxLinear MXL111SF 2 * mxl111sf-i2c.h - driver for the MaxLinear MXL111SF
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c
index b741b3a7a325..f6b348024bec 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-phy.c - driver for the MaxLinear MXL111SF 2 * mxl111sf-phy.c - driver for the MaxLinear MXL111SF
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h
index f0756071d347..0643738de7de 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-phy.h - driver for the MaxLinear MXL111SF 2 * mxl111sf-phy.h - driver for the MaxLinear MXL111SF
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h
index 17831b0fb9db..89bf115e927e 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-reg.h - driver for the MaxLinear MXL111SF 2 * mxl111sf-reg.h - driver for the MaxLinear MXL111SF
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c
index 879c529640f7..a8d2c7053674 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-tuner.c - driver for the MaxLinear MXL111SF CMOS tuner 2 * mxl111sf-tuner.c - driver for the MaxLinear MXL111SF CMOS tuner
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -512,7 +512,7 @@ struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe,
512EXPORT_SYMBOL_GPL(mxl111sf_tuner_attach); 512EXPORT_SYMBOL_GPL(mxl111sf_tuner_attach);
513 513
514MODULE_DESCRIPTION("MaxLinear MxL111SF CMOS tuner driver"); 514MODULE_DESCRIPTION("MaxLinear MxL111SF CMOS tuner driver");
515MODULE_AUTHOR("Michael Krufky <mkrufky@kernellabs.com>"); 515MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
516MODULE_LICENSE("GPL"); 516MODULE_LICENSE("GPL");
517MODULE_VERSION("0.1"); 517MODULE_VERSION("0.1");
518 518
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h
index 90f583e5d6a6..2046db22519e 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl111sf-tuner.h - driver for the MaxLinear MXL111SF CMOS tuner 2 * mxl111sf-tuner.h - driver for the MaxLinear MXL111SF CMOS tuner
3 * 3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com> 4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -68,7 +68,7 @@ struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe,
68#else 68#else
69static inline 69static inline
70struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe, 70struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe,
71 struct mxl111sf_state *mxl_state 71 struct mxl111sf_state *mxl_state,
72 struct mxl111sf_tuner_config *cfg) 72 struct mxl111sf_tuner_config *cfg)
73{ 73{
74 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 74 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf.c b/drivers/media/usb/dvb-usb-v2/mxl111sf.c
index 08240e498451..c7304fa8ab73 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2010 Michael Krufky (mkrufky@kernellabs.com) 2 * Copyright (C) 2010-2014 Michael Krufky (mkrufky@linuxtv.org)
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free 5 * under the terms of the GNU General Public License as published by the Free
@@ -105,7 +105,7 @@ int mxl111sf_read_reg(struct mxl111sf_state *state, u8 addr, u8 *data)
105 ret = -EINVAL; 105 ret = -EINVAL;
106 } 106 }
107 107
108 pr_debug("R: (0x%02x, 0x%02x)\n", addr, *data); 108 pr_debug("R: (0x%02x, 0x%02x)\n", addr, buf[1]);
109fail: 109fail:
110 return ret; 110 return ret;
111} 111}
@@ -1421,7 +1421,7 @@ static struct usb_driver mxl111sf_usb_driver = {
1421 1421
1422module_usb_driver(mxl111sf_usb_driver); 1422module_usb_driver(mxl111sf_usb_driver);
1423 1423
1424MODULE_AUTHOR("Michael Krufky <mkrufky@kernellabs.com>"); 1424MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1425MODULE_DESCRIPTION("Driver for MaxLinear MxL111SF"); 1425MODULE_DESCRIPTION("Driver for MaxLinear MxL111SF");
1426MODULE_VERSION("1.0"); 1426MODULE_VERSION("1.0");
1427MODULE_LICENSE("GPL"); 1427MODULE_LICENSE("GPL");
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf.h b/drivers/media/usb/dvb-usb-v2/mxl111sf.h
index 9816de86e48c..8516c011b7cc 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2010 Michael Krufky (mkrufky@kernellabs.com) 2 * Copyright (C) 2010-2014 Michael Krufky (mkrufky@linuxtv.org)
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free 5 * under the terms of the GNU General Public License as published by the Free
diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c
index 2f0c89cbac76..c5638964c3f2 100644
--- a/drivers/media/usb/hdpvr/hdpvr-core.c
+++ b/drivers/media/usb/hdpvr/hdpvr-core.c
@@ -198,7 +198,6 @@ static int device_authorization(struct hdpvr_device *dev)
198 hex_dump_to_buffer(response, 8, 16, 1, print_buf, 5*buf_size+1, 0); 198 hex_dump_to_buffer(response, 8, 16, 1, print_buf, 5*buf_size+1, 0);
199 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, " response: %s\n", 199 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, " response: %s\n",
200 print_buf); 200 print_buf);
201 kfree(print_buf);
202#endif 201#endif
203 202
204 msleep(100); 203 msleep(100);
@@ -214,6 +213,9 @@ static int device_authorization(struct hdpvr_device *dev)
214 retval = ret != 8; 213 retval = ret != 8;
215unlock: 214unlock:
216 mutex_unlock(&dev->usbc_mutex); 215 mutex_unlock(&dev->usbc_mutex);
216#ifdef HDPVR_DEBUG
217 kfree(print_buf);
218#endif
217 return retval; 219 return retval;
218} 220}
219 221
diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c b/drivers/media/v4l2-core/v4l2-dv-timings.c
index ee52b9f4a944..f7902fe8a526 100644
--- a/drivers/media/v4l2-core/v4l2-dv-timings.c
+++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
@@ -515,6 +515,7 @@ bool v4l2_detect_gtf(unsigned frame_height,
515 aspect.denominator = 9; 515 aspect.denominator = 9;
516 } 516 }
517 image_width = ((image_height * aspect.numerator) / aspect.denominator); 517 image_width = ((image_height * aspect.numerator) / aspect.denominator);
518 image_width = (image_width + GTF_CELL_GRAN/2) & ~(GTF_CELL_GRAN - 1);
518 519
519 /* Horizontal */ 520 /* Horizontal */
520 if (default_gtf) 521 if (default_gtf)
diff --git a/drivers/media/v4l2-core/videobuf-dma-contig.c b/drivers/media/v4l2-core/videobuf-dma-contig.c
index 65411adcd0ea..7e6b209b7002 100644
--- a/drivers/media/v4l2-core/videobuf-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf-dma-contig.c
@@ -66,14 +66,11 @@ static void __videobuf_dc_free(struct device *dev,
66static void videobuf_vm_open(struct vm_area_struct *vma) 66static void videobuf_vm_open(struct vm_area_struct *vma)
67{ 67{
68 struct videobuf_mapping *map = vma->vm_private_data; 68 struct videobuf_mapping *map = vma->vm_private_data;
69 struct videobuf_queue *q = map->q;
70 69
71 dev_dbg(q->dev, "vm_open %p [count=%u,vma=%08lx-%08lx]\n", 70 dev_dbg(map->q->dev, "vm_open %p [count=%u,vma=%08lx-%08lx]\n",
72 map, map->count, vma->vm_start, vma->vm_end); 71 map, map->count, vma->vm_start, vma->vm_end);
73 72
74 videobuf_queue_lock(q);
75 map->count++; 73 map->count++;
76 videobuf_queue_unlock(q);
77} 74}
78 75
79static void videobuf_vm_close(struct vm_area_struct *vma) 76static void videobuf_vm_close(struct vm_area_struct *vma)
@@ -85,11 +82,12 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
85 dev_dbg(q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n", 82 dev_dbg(q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n",
86 map, map->count, vma->vm_start, vma->vm_end); 83 map, map->count, vma->vm_start, vma->vm_end);
87 84
88 videobuf_queue_lock(q); 85 map->count--;
89 if (!--map->count) { 86 if (0 == map->count) {
90 struct videobuf_dma_contig_memory *mem; 87 struct videobuf_dma_contig_memory *mem;
91 88
92 dev_dbg(q->dev, "munmap %p q=%p\n", map, q); 89 dev_dbg(q->dev, "munmap %p q=%p\n", map, q);
90 videobuf_queue_lock(q);
93 91
94 /* We need first to cancel streams, before unmapping */ 92 /* We need first to cancel streams, before unmapping */
95 if (q->streaming) 93 if (q->streaming)
@@ -128,8 +126,8 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
128 126
129 kfree(map); 127 kfree(map);
130 128
129 videobuf_queue_unlock(q);
131 } 130 }
132 videobuf_queue_unlock(q);
133} 131}
134 132
135static const struct vm_operations_struct videobuf_vm_ops = { 133static const struct vm_operations_struct videobuf_vm_ops = {
diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c
index 9db674ccdc68..828e7c10bd70 100644
--- a/drivers/media/v4l2-core/videobuf-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf-dma-sg.c
@@ -338,14 +338,11 @@ EXPORT_SYMBOL_GPL(videobuf_dma_free);
338static void videobuf_vm_open(struct vm_area_struct *vma) 338static void videobuf_vm_open(struct vm_area_struct *vma)
339{ 339{
340 struct videobuf_mapping *map = vma->vm_private_data; 340 struct videobuf_mapping *map = vma->vm_private_data;
341 struct videobuf_queue *q = map->q;
342 341
343 dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map, 342 dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map,
344 map->count, vma->vm_start, vma->vm_end); 343 map->count, vma->vm_start, vma->vm_end);
345 344
346 videobuf_queue_lock(q);
347 map->count++; 345 map->count++;
348 videobuf_queue_unlock(q);
349} 346}
350 347
351static void videobuf_vm_close(struct vm_area_struct *vma) 348static void videobuf_vm_close(struct vm_area_struct *vma)
@@ -358,9 +355,10 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
358 dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map, 355 dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map,
359 map->count, vma->vm_start, vma->vm_end); 356 map->count, vma->vm_start, vma->vm_end);
360 357
361 videobuf_queue_lock(q); 358 map->count--;
362 if (!--map->count) { 359 if (0 == map->count) {
363 dprintk(1, "munmap %p q=%p\n", map, q); 360 dprintk(1, "munmap %p q=%p\n", map, q);
361 videobuf_queue_lock(q);
364 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 362 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
365 if (NULL == q->bufs[i]) 363 if (NULL == q->bufs[i])
366 continue; 364 continue;
@@ -376,9 +374,9 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
376 q->bufs[i]->baddr = 0; 374 q->bufs[i]->baddr = 0;
377 q->ops->buf_release(q, q->bufs[i]); 375 q->ops->buf_release(q, q->bufs[i]);
378 } 376 }
377 videobuf_queue_unlock(q);
379 kfree(map); 378 kfree(map);
380 } 379 }
381 videobuf_queue_unlock(q);
382 return; 380 return;
383} 381}
384 382
diff --git a/drivers/media/v4l2-core/videobuf-vmalloc.c b/drivers/media/v4l2-core/videobuf-vmalloc.c
index 1365c651c177..2ff7fcc77b11 100644
--- a/drivers/media/v4l2-core/videobuf-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf-vmalloc.c
@@ -54,14 +54,11 @@ MODULE_LICENSE("GPL");
54static void videobuf_vm_open(struct vm_area_struct *vma) 54static void videobuf_vm_open(struct vm_area_struct *vma)
55{ 55{
56 struct videobuf_mapping *map = vma->vm_private_data; 56 struct videobuf_mapping *map = vma->vm_private_data;
57 struct videobuf_queue *q = map->q;
58 57
59 dprintk(2, "vm_open %p [count=%u,vma=%08lx-%08lx]\n", map, 58 dprintk(2, "vm_open %p [count=%u,vma=%08lx-%08lx]\n", map,
60 map->count, vma->vm_start, vma->vm_end); 59 map->count, vma->vm_start, vma->vm_end);
61 60
62 videobuf_queue_lock(q);
63 map->count++; 61 map->count++;
64 videobuf_queue_unlock(q);
65} 62}
66 63
67static void videobuf_vm_close(struct vm_area_struct *vma) 64static void videobuf_vm_close(struct vm_area_struct *vma)
@@ -73,11 +70,12 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
73 dprintk(2, "vm_close %p [count=%u,vma=%08lx-%08lx]\n", map, 70 dprintk(2, "vm_close %p [count=%u,vma=%08lx-%08lx]\n", map,
74 map->count, vma->vm_start, vma->vm_end); 71 map->count, vma->vm_start, vma->vm_end);
75 72
76 videobuf_queue_lock(q); 73 map->count--;
77 if (!--map->count) { 74 if (0 == map->count) {
78 struct videobuf_vmalloc_memory *mem; 75 struct videobuf_vmalloc_memory *mem;
79 76
80 dprintk(1, "munmap %p q=%p\n", map, q); 77 dprintk(1, "munmap %p q=%p\n", map, q);
78 videobuf_queue_lock(q);
81 79
82 /* We need first to cancel streams, before unmapping */ 80 /* We need first to cancel streams, before unmapping */
83 if (q->streaming) 81 if (q->streaming)
@@ -116,8 +114,8 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
116 114
117 kfree(map); 115 kfree(map);
118 116
117 videobuf_queue_unlock(q);
119 } 118 }
120 videobuf_queue_unlock(q);
121 119
122 return; 120 return;
123} 121}
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 5a5fb7f09b7b..a127925c9d61 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1776,6 +1776,11 @@ static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
1776 return 0; 1776 return 0;
1777 } 1777 }
1778 1778
1779 if (!q->num_buffers) {
1780 dprintk(1, "streamon: no buffers have been allocated\n");
1781 return -EINVAL;
1782 }
1783
1779 /* 1784 /*
1780 * If any buffers were queued before streamon, 1785 * If any buffers were queued before streamon,
1781 * we can now pass them to driver for processing. 1786 * we can now pass them to driver for processing.
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index a60c188c2bd9..04bd3b6de401 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -754,19 +754,19 @@ static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
754 unsigned long arg) 754 unsigned long arg)
755{ 755{
756 int ret; 756 int ret;
757 mutex_lock(&i2o_cfg_mutex);
758 switch (cmd) { 757 switch (cmd) {
759 case I2OGETIOPS: 758 case I2OGETIOPS:
760 ret = i2o_cfg_ioctl(file, cmd, arg); 759 ret = i2o_cfg_ioctl(file, cmd, arg);
761 break; 760 break;
762 case I2OPASSTHRU32: 761 case I2OPASSTHRU32:
762 mutex_lock(&i2o_cfg_mutex);
763 ret = i2o_cfg_passthru32(file, cmd, arg); 763 ret = i2o_cfg_passthru32(file, cmd, arg);
764 mutex_unlock(&i2o_cfg_mutex);
764 break; 765 break;
765 default: 766 default:
766 ret = -ENOIOCTLCMD; 767 ret = -ENOIOCTLCMD;
767 break; 768 break;
768 } 769 }
769 mutex_unlock(&i2o_cfg_mutex);
770 return ret; 770 return ret;
771} 771}
772 772
diff --git a/drivers/mfd/da9055-i2c.c b/drivers/mfd/da9055-i2c.c
index 13af7e50021e..8103e4362132 100644
--- a/drivers/mfd/da9055-i2c.c
+++ b/drivers/mfd/da9055-i2c.c
@@ -53,17 +53,25 @@ static int da9055_i2c_remove(struct i2c_client *i2c)
53 return 0; 53 return 0;
54} 54}
55 55
56/*
57 * DO NOT change the device Ids. The naming is intentionally specific as both
58 * the PMIC and CODEC parts of this chip are instantiated separately as I2C
59 * devices (both have configurable I2C addresses, and are to all intents and
60 * purposes separate). As a result there are specific DA9055 ids for PMIC
61 * and CODEC, which must be different to operate together.
62 */
56static struct i2c_device_id da9055_i2c_id[] = { 63static struct i2c_device_id da9055_i2c_id[] = {
57 {"da9055", 0}, 64 {"da9055-pmic", 0},
58 { } 65 { }
59}; 66};
67MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
60 68
61static struct i2c_driver da9055_i2c_driver = { 69static struct i2c_driver da9055_i2c_driver = {
62 .probe = da9055_i2c_probe, 70 .probe = da9055_i2c_probe,
63 .remove = da9055_i2c_remove, 71 .remove = da9055_i2c_remove,
64 .id_table = da9055_i2c_id, 72 .id_table = da9055_i2c_id,
65 .driver = { 73 .driver = {
66 .name = "da9055", 74 .name = "da9055-pmic",
67 .owner = THIS_MODULE, 75 .owner = THIS_MODULE,
68 }, 76 },
69}; 77};
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index ac514fb2b877..71aa14a6bfbb 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -173,6 +173,7 @@ static const struct i2c_device_id max14577_i2c_id[] = {
173}; 173};
174MODULE_DEVICE_TABLE(i2c, max14577_i2c_id); 174MODULE_DEVICE_TABLE(i2c, max14577_i2c_id);
175 175
176#ifdef CONFIG_PM_SLEEP
176static int max14577_suspend(struct device *dev) 177static int max14577_suspend(struct device *dev)
177{ 178{
178 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); 179 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
@@ -208,6 +209,7 @@ static int max14577_resume(struct device *dev)
208 209
209 return 0; 210 return 0;
210} 211}
212#endif /* CONFIG_PM_SLEEP */
211 213
212static struct of_device_id max14577_dt_match[] = { 214static struct of_device_id max14577_dt_match[] = {
213 { .compatible = "maxim,max14577", }, 215 { .compatible = "maxim,max14577", },
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
index be88a3bf7b85..5adede0fb04c 100644
--- a/drivers/mfd/max8997.c
+++ b/drivers/mfd/max8997.c
@@ -164,15 +164,15 @@ static struct max8997_platform_data *max8997_i2c_parse_dt_pdata(
164 return pd; 164 return pd;
165} 165}
166 166
167static inline int max8997_i2c_get_driver_data(struct i2c_client *i2c, 167static inline unsigned long max8997_i2c_get_driver_data(struct i2c_client *i2c,
168 const struct i2c_device_id *id) 168 const struct i2c_device_id *id)
169{ 169{
170 if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) { 170 if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
171 const struct of_device_id *match; 171 const struct of_device_id *match;
172 match = of_match_node(max8997_pmic_dt_match, i2c->dev.of_node); 172 match = of_match_node(max8997_pmic_dt_match, i2c->dev.of_node);
173 return (int)match->data; 173 return (unsigned long)match->data;
174 } 174 }
175 return (int)id->driver_data; 175 return id->driver_data;
176} 176}
177 177
178static int max8997_i2c_probe(struct i2c_client *i2c, 178static int max8997_i2c_probe(struct i2c_client *i2c,
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c
index 612ca404e150..5d5e186b5d8b 100644
--- a/drivers/mfd/max8998.c
+++ b/drivers/mfd/max8998.c
@@ -169,16 +169,16 @@ static struct max8998_platform_data *max8998_i2c_parse_dt_pdata(
169 return pd; 169 return pd;
170} 170}
171 171
172static inline int max8998_i2c_get_driver_data(struct i2c_client *i2c, 172static inline unsigned long max8998_i2c_get_driver_data(struct i2c_client *i2c,
173 const struct i2c_device_id *id) 173 const struct i2c_device_id *id)
174{ 174{
175 if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) { 175 if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
176 const struct of_device_id *match; 176 const struct of_device_id *match;
177 match = of_match_node(max8998_dt_match, i2c->dev.of_node); 177 match = of_match_node(max8998_dt_match, i2c->dev.of_node);
178 return (int)(long)match->data; 178 return (unsigned long)match->data;
179 } 179 }
180 180
181 return (int)id->driver_data; 181 return id->driver_data;
182} 182}
183 183
184static int max8998_i2c_probe(struct i2c_client *i2c, 184static int max8998_i2c_probe(struct i2c_client *i2c,
diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
index a139798b8065..714e2135210e 100644
--- a/drivers/mfd/sec-core.c
+++ b/drivers/mfd/sec-core.c
@@ -315,6 +315,7 @@ static int sec_pmic_remove(struct i2c_client *i2c)
315 return 0; 315 return 0;
316} 316}
317 317
318#ifdef CONFIG_PM_SLEEP
318static int sec_pmic_suspend(struct device *dev) 319static int sec_pmic_suspend(struct device *dev)
319{ 320{
320 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); 321 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
@@ -349,6 +350,7 @@ static int sec_pmic_resume(struct device *dev)
349 350
350 return 0; 351 return 0;
351} 352}
353#endif /* CONFIG_PM_SLEEP */
352 354
353static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume); 355static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume);
354 356
diff --git a/drivers/mfd/tps65217.c b/drivers/mfd/tps65217.c
index 966cf65c5c36..3cc4c7084b92 100644
--- a/drivers/mfd/tps65217.c
+++ b/drivers/mfd/tps65217.c
@@ -158,7 +158,7 @@ static int tps65217_probe(struct i2c_client *client,
158{ 158{
159 struct tps65217 *tps; 159 struct tps65217 *tps;
160 unsigned int version; 160 unsigned int version;
161 unsigned int chip_id = ids->driver_data; 161 unsigned long chip_id = ids->driver_data;
162 const struct of_device_id *match; 162 const struct of_device_id *match;
163 bool status_off = false; 163 bool status_off = false;
164 int ret; 164 int ret;
@@ -170,7 +170,7 @@ static int tps65217_probe(struct i2c_client *client,
170 "Failed to find matching dt id\n"); 170 "Failed to find matching dt id\n");
171 return -EINVAL; 171 return -EINVAL;
172 } 172 }
173 chip_id = (unsigned int)(unsigned long)match->data; 173 chip_id = (unsigned long)match->data;
174 status_off = of_property_read_bool(client->dev.of_node, 174 status_off = of_property_read_bool(client->dev.of_node,
175 "ti,pmic-shutdown-controller"); 175 "ti,pmic-shutdown-controller");
176 } 176 }
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index ba04f1bc70eb..e6fab94e2c8a 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -636,7 +636,7 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
636 if (i2c->dev.of_node) { 636 if (i2c->dev.of_node) {
637 of_id = of_match_device(wm8994_of_match, &i2c->dev); 637 of_id = of_match_device(wm8994_of_match, &i2c->dev);
638 if (of_id) 638 if (of_id)
639 wm8994->type = (int)of_id->data; 639 wm8994->type = (enum wm8994_type)of_id->data;
640 } else { 640 } else {
641 wm8994->type = id->driver_data; 641 wm8994->type = id->driver_data;
642 } 642 }
diff --git a/drivers/misc/genwqe/card_dev.c b/drivers/misc/genwqe/card_dev.c
index 8f8a6b327cdb..2c2c9cc75231 100644
--- a/drivers/misc/genwqe/card_dev.c
+++ b/drivers/misc/genwqe/card_dev.c
@@ -787,6 +787,7 @@ static int genwqe_pin_mem(struct genwqe_file *cfile, struct genwqe_mem *m)
787 if (rc != 0) { 787 if (rc != 0) {
788 dev_err(&pci_dev->dev, 788 dev_err(&pci_dev->dev,
789 "[%s] genwqe_user_vmap rc=%d\n", __func__, rc); 789 "[%s] genwqe_user_vmap rc=%d\n", __func__, rc);
790 kfree(dma_map);
790 return rc; 791 return rc;
791 } 792 }
792 793
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 1ee2b9492a82..89a557972d1b 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -666,7 +666,6 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
666 goto err; 666 goto err;
667 667
668 cb->fop_type = MEI_FOP_READ; 668 cb->fop_type = MEI_FOP_READ;
669 cl->read_cb = cb;
670 if (dev->hbuf_is_ready) { 669 if (dev->hbuf_is_ready) {
671 dev->hbuf_is_ready = false; 670 dev->hbuf_is_ready = false;
672 if (mei_hbm_cl_flow_control_req(dev, cl)) { 671 if (mei_hbm_cl_flow_control_req(dev, cl)) {
@@ -678,6 +677,9 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
678 } else { 677 } else {
679 list_add_tail(&cb->list, &dev->ctrl_wr_list.list); 678 list_add_tail(&cb->list, &dev->ctrl_wr_list.list);
680 } 679 }
680
681 cl->read_cb = cb;
682
681 return rets; 683 return rets;
682err: 684err:
683 mei_io_cb_free(cb); 685 mei_io_cb_free(cb);
@@ -908,7 +910,6 @@ void mei_cl_all_disconnect(struct mei_device *dev)
908 list_for_each_entry_safe(cl, next, &dev->file_list, link) { 910 list_for_each_entry_safe(cl, next, &dev->file_list, link) {
909 cl->state = MEI_FILE_DISCONNECTED; 911 cl->state = MEI_FILE_DISCONNECTED;
910 cl->mei_flow_ctrl_creds = 0; 912 cl->mei_flow_ctrl_creds = 0;
911 cl->read_cb = NULL;
912 cl->timer_count = 0; 913 cl->timer_count = 0;
913 } 914 }
914} 915}
@@ -942,8 +943,16 @@ void mei_cl_all_wakeup(struct mei_device *dev)
942void mei_cl_all_write_clear(struct mei_device *dev) 943void mei_cl_all_write_clear(struct mei_device *dev)
943{ 944{
944 struct mei_cl_cb *cb, *next; 945 struct mei_cl_cb *cb, *next;
946 struct list_head *list;
947
948 list = &dev->write_list.list;
949 list_for_each_entry_safe(cb, next, list, list) {
950 list_del(&cb->list);
951 mei_io_cb_free(cb);
952 }
945 953
946 list_for_each_entry_safe(cb, next, &dev->write_list.list, list) { 954 list = &dev->write_waiting_list.list;
955 list_for_each_entry_safe(cb, next, list, list) {
947 list_del(&cb->list); 956 list_del(&cb->list);
948 mei_io_cb_free(cb); 957 mei_io_cb_free(cb);
949 } 958 }
diff --git a/drivers/misc/mic/host/mic_virtio.c b/drivers/misc/mic/host/mic_virtio.c
index 752ff873f891..7e1ef0ebbb80 100644
--- a/drivers/misc/mic/host/mic_virtio.c
+++ b/drivers/misc/mic/host/mic_virtio.c
@@ -156,7 +156,8 @@ static int mic_vringh_copy(struct mic_vdev *mvdev, struct vringh_kiov *iov,
156static int _mic_virtio_copy(struct mic_vdev *mvdev, 156static int _mic_virtio_copy(struct mic_vdev *mvdev,
157 struct mic_copy_desc *copy) 157 struct mic_copy_desc *copy)
158{ 158{
159 int ret = 0, iovcnt = copy->iovcnt; 159 int ret = 0;
160 u32 iovcnt = copy->iovcnt;
160 struct iovec iov; 161 struct iovec iov;
161 struct iovec __user *u_iov = copy->iov; 162 struct iovec __user *u_iov = copy->iov;
162 void __user *ubuf = NULL; 163 void __user *ubuf = NULL;
diff --git a/drivers/misc/sgi-gru/grukdump.c b/drivers/misc/sgi-gru/grukdump.c
index 9b2062d17327..2bef3f76032a 100644
--- a/drivers/misc/sgi-gru/grukdump.c
+++ b/drivers/misc/sgi-gru/grukdump.c
@@ -139,8 +139,11 @@ static int gru_dump_context(struct gru_state *gru, int ctxnum,
139 139
140 ubuf += sizeof(hdr); 140 ubuf += sizeof(hdr);
141 ubufcch = ubuf; 141 ubufcch = ubuf;
142 if (gru_user_copy_handle(&ubuf, cch)) 142 if (gru_user_copy_handle(&ubuf, cch)) {
143 goto fail; 143 if (cch_locked)
144 unlock_cch_handle(cch);
145 return -EFAULT;
146 }
144 if (cch_locked) 147 if (cch_locked)
145 ubufcch->delresp = 0; 148 ubufcch->delresp = 0;
146 bytes = sizeof(hdr) + GRU_CACHE_LINE_BYTES; 149 bytes = sizeof(hdr) + GRU_CACHE_LINE_BYTES;
@@ -179,10 +182,6 @@ static int gru_dump_context(struct gru_state *gru, int ctxnum,
179 ret = -EFAULT; 182 ret = -EFAULT;
180 183
181 return ret ? ret : bytes; 184 return ret ? ret : bytes;
182
183fail:
184 unlock_cch_handle(cch);
185 return -EFAULT;
186} 185}
187 186
188int gru_dump_chiplet_request(unsigned long arg) 187int gru_dump_chiplet_request(unsigned long arg)
diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
index b9e2000969f0..95c894482fdd 100644
--- a/drivers/misc/sgi-xp/xpc_uv.c
+++ b/drivers/misc/sgi-xp/xpc_uv.c
@@ -240,7 +240,7 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name,
240 240
241 nid = cpu_to_node(cpu); 241 nid = cpu_to_node(cpu);
242 page = alloc_pages_exact_node(nid, 242 page = alloc_pages_exact_node(nid,
243 GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, 243 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
244 pg_order); 244 pg_order);
245 if (page == NULL) { 245 if (page == NULL) {
246 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d " 246 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d "
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 357bbc54fe4b..3e049c13429c 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -197,7 +197,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
197 struct mmc_queue_req *mqrq_prev = &mq->mqrq[1]; 197 struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
198 198
199 if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask) 199 if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
200 limit = dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT; 200 limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
201 201
202 mq->card = card; 202 mq->card = card;
203 mq->queue = blk_init_queue(mmc_request_fn, lock); 203 mq->queue = blk_init_queue(mmc_request_fn, lock);
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 55cd110a49c4..c204b7d1532c 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -2607,7 +2607,7 @@ int dw_mci_probe(struct dw_mci *host)
2607 2607
2608 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host); 2608 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
2609 host->card_workqueue = alloc_workqueue("dw-mci-card", 2609 host->card_workqueue = alloc_workqueue("dw-mci-card",
2610 WQ_MEM_RECLAIM | WQ_NON_REENTRANT, 1); 2610 WQ_MEM_RECLAIM, 1);
2611 if (!host->card_workqueue) { 2611 if (!host->card_workqueue) {
2612 ret = -ENOMEM; 2612 ret = -ENOMEM;
2613 goto err_dmaunmap; 2613 goto err_dmaunmap;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 59eba5d2c685..9715a7ba164a 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1584,7 +1584,7 @@ read_retry:
1584 } 1584 }
1585 1585
1586 if (mtd->ecc_stats.failed - ecc_failures) { 1586 if (mtd->ecc_stats.failed - ecc_failures) {
1587 if (retry_mode + 1 <= chip->read_retries) { 1587 if (retry_mode + 1 < chip->read_retries) {
1588 retry_mode++; 1588 retry_mode++;
1589 ret = nand_setup_read_retry(mtd, 1589 ret = nand_setup_read_retry(mtd,
1590 retry_mode); 1590 retry_mode);
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index ef4190a02b7b..bf642ceef681 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -1633,6 +1633,7 @@ static int omap_nand_probe(struct platform_device *pdev)
1633 int i; 1633 int i;
1634 dma_cap_mask_t mask; 1634 dma_cap_mask_t mask;
1635 unsigned sig; 1635 unsigned sig;
1636 unsigned oob_index;
1636 struct resource *res; 1637 struct resource *res;
1637 struct mtd_part_parser_data ppdata = {}; 1638 struct mtd_part_parser_data ppdata = {};
1638 1639
@@ -1826,11 +1827,14 @@ static int omap_nand_probe(struct platform_device *pdev)
1826 (mtd->writesize / 1827 (mtd->writesize /
1827 nand_chip->ecc.size); 1828 nand_chip->ecc.size);
1828 if (nand_chip->options & NAND_BUSWIDTH_16) 1829 if (nand_chip->options & NAND_BUSWIDTH_16)
1829 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1830 oob_index = BADBLOCK_MARKER_LENGTH;
1830 else 1831 else
1831 ecclayout->eccpos[0] = 1; 1832 oob_index = 1;
1832 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1833 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
1833 ecclayout->eccbytes; 1834 ecclayout->eccpos[i] = oob_index;
1835 /* no reserved-marker in ecclayout for this ecc-scheme */
1836 ecclayout->oobfree->offset =
1837 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1834 break; 1838 break;
1835 1839
1836 case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW: 1840 case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW:
@@ -1847,9 +1851,15 @@ static int omap_nand_probe(struct platform_device *pdev)
1847 ecclayout->eccbytes = nand_chip->ecc.bytes * 1851 ecclayout->eccbytes = nand_chip->ecc.bytes *
1848 (mtd->writesize / 1852 (mtd->writesize /
1849 nand_chip->ecc.size); 1853 nand_chip->ecc.size);
1850 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1854 oob_index = BADBLOCK_MARKER_LENGTH;
1851 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1855 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++) {
1852 ecclayout->eccbytes; 1856 ecclayout->eccpos[i] = oob_index;
1857 if (((i + 1) % nand_chip->ecc.bytes) == 0)
1858 oob_index++;
1859 }
1860 /* include reserved-marker in ecclayout->oobfree calculation */
1861 ecclayout->oobfree->offset = 1 +
1862 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1853 /* software bch library is used for locating errors */ 1863 /* software bch library is used for locating errors */
1854 nand_chip->ecc.priv = nand_bch_init(mtd, 1864 nand_chip->ecc.priv = nand_bch_init(mtd,
1855 nand_chip->ecc.size, 1865 nand_chip->ecc.size,
@@ -1883,9 +1893,12 @@ static int omap_nand_probe(struct platform_device *pdev)
1883 ecclayout->eccbytes = nand_chip->ecc.bytes * 1893 ecclayout->eccbytes = nand_chip->ecc.bytes *
1884 (mtd->writesize / 1894 (mtd->writesize /
1885 nand_chip->ecc.size); 1895 nand_chip->ecc.size);
1886 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1896 oob_index = BADBLOCK_MARKER_LENGTH;
1887 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1897 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
1888 ecclayout->eccbytes; 1898 ecclayout->eccpos[i] = oob_index;
1899 /* reserved marker already included in ecclayout->eccbytes */
1900 ecclayout->oobfree->offset =
1901 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1889 /* This ECC scheme requires ELM H/W block */ 1902 /* This ECC scheme requires ELM H/W block */
1890 if (is_elm_present(info, pdata->elm_of_node, BCH4_ECC) < 0) { 1903 if (is_elm_present(info, pdata->elm_of_node, BCH4_ECC) < 0) {
1891 pr_err("nand: error: could not initialize ELM\n"); 1904 pr_err("nand: error: could not initialize ELM\n");
@@ -1913,9 +1926,15 @@ static int omap_nand_probe(struct platform_device *pdev)
1913 ecclayout->eccbytes = nand_chip->ecc.bytes * 1926 ecclayout->eccbytes = nand_chip->ecc.bytes *
1914 (mtd->writesize / 1927 (mtd->writesize /
1915 nand_chip->ecc.size); 1928 nand_chip->ecc.size);
1916 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1929 oob_index = BADBLOCK_MARKER_LENGTH;
1917 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1930 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++) {
1918 ecclayout->eccbytes; 1931 ecclayout->eccpos[i] = oob_index;
1932 if (((i + 1) % nand_chip->ecc.bytes) == 0)
1933 oob_index++;
1934 }
1935 /* include reserved-marker in ecclayout->oobfree calculation */
1936 ecclayout->oobfree->offset = 1 +
1937 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1919 /* software bch library is used for locating errors */ 1938 /* software bch library is used for locating errors */
1920 nand_chip->ecc.priv = nand_bch_init(mtd, 1939 nand_chip->ecc.priv = nand_bch_init(mtd,
1921 nand_chip->ecc.size, 1940 nand_chip->ecc.size,
@@ -1956,9 +1975,12 @@ static int omap_nand_probe(struct platform_device *pdev)
1956 ecclayout->eccbytes = nand_chip->ecc.bytes * 1975 ecclayout->eccbytes = nand_chip->ecc.bytes *
1957 (mtd->writesize / 1976 (mtd->writesize /
1958 nand_chip->ecc.size); 1977 nand_chip->ecc.size);
1959 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1978 oob_index = BADBLOCK_MARKER_LENGTH;
1960 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1979 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
1961 ecclayout->eccbytes; 1980 ecclayout->eccpos[i] = oob_index;
1981 /* reserved marker already included in ecclayout->eccbytes */
1982 ecclayout->oobfree->offset =
1983 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1962 break; 1984 break;
1963#else 1985#else
1964 pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n"); 1986 pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n");
@@ -1972,11 +1994,8 @@ static int omap_nand_probe(struct platform_device *pdev)
1972 goto return_error; 1994 goto return_error;
1973 } 1995 }
1974 1996
1975 /* populate remaining ECC layout data */ 1997 /* all OOB bytes from oobfree->offset till end off OOB are free */
1976 ecclayout->oobfree->length = mtd->oobsize - (BADBLOCK_MARKER_LENGTH + 1998 ecclayout->oobfree->length = mtd->oobsize - ecclayout->oobfree->offset;
1977 ecclayout->eccbytes);
1978 for (i = 1; i < ecclayout->eccbytes; i++)
1979 ecclayout->eccpos[i] = ecclayout->eccpos[0] + i;
1980 /* check if NAND device's OOB is enough to store ECC signatures */ 1999 /* check if NAND device's OOB is enough to store ECC signatures */
1981 if (mtd->oobsize < (ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH)) { 2000 if (mtd->oobsize < (ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH)) {
1982 pr_err("not enough OOB bytes required = %d, available=%d\n", 2001 pr_err("not enough OOB bytes required = %d, available=%d\n",
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index ead861307b3c..c5dad652614d 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -463,8 +463,8 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
463 } 463 }
464 } 464 }
465 if (found_orphan) { 465 if (found_orphan) {
466 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
467 list_del(&tmp_aeb->u.list); 466 list_del(&tmp_aeb->u.list);
467 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
468 } 468 }
469 469
470 new_aeb = kmem_cache_alloc(ai->aeb_slab_cache, 470 new_aeb = kmem_cache_alloc(ai->aeb_slab_cache,
@@ -846,16 +846,16 @@ fail_bad:
846 ret = UBI_BAD_FASTMAP; 846 ret = UBI_BAD_FASTMAP;
847fail: 847fail:
848 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &used, u.list) { 848 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &used, u.list) {
849 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
850 list_del(&tmp_aeb->u.list); 849 list_del(&tmp_aeb->u.list);
850 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
851 } 851 }
852 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) { 852 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) {
853 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
854 list_del(&tmp_aeb->u.list); 853 list_del(&tmp_aeb->u.list);
854 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
855 } 855 }
856 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) { 856 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) {
857 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
858 list_del(&tmp_aeb->u.list); 857 list_del(&tmp_aeb->u.list);
858 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
859 } 859 }
860 860
861 return ret; 861 return ret;
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index f342278539d5..494b888a6568 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -139,7 +139,7 @@ config MACVTAP
139 This adds a specialized tap character device driver that is based 139 This adds a specialized tap character device driver that is based
140 on the MAC-VLAN network interface, called macvtap. A macvtap device 140 on the MAC-VLAN network interface, called macvtap. A macvtap device
141 can be added in the same way as a macvlan device, using 'type 141 can be added in the same way as a macvlan device, using 'type
142 macvlan', and then be accessed through the tap user space interface. 142 macvtap', and then be accessed through the tap user space interface.
143 143
144 To compile this driver as a module, choose M here: the module 144 To compile this driver as a module, choose M here: the module
145 will be called macvtap. 145 will be called macvtap.
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index cce1f1bf90b4..dcde56057fe1 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -181,7 +181,7 @@ static inline int __agg_has_partner(struct aggregator *agg)
181 */ 181 */
182static inline void __disable_port(struct port *port) 182static inline void __disable_port(struct port *port)
183{ 183{
184 bond_set_slave_inactive_flags(port->slave); 184 bond_set_slave_inactive_flags(port->slave, BOND_SLAVE_NOTIFY_LATER);
185} 185}
186 186
187/** 187/**
@@ -193,7 +193,7 @@ static inline void __enable_port(struct port *port)
193 struct slave *slave = port->slave; 193 struct slave *slave = port->slave;
194 194
195 if ((slave->link == BOND_LINK_UP) && IS_UP(slave->dev)) 195 if ((slave->link == BOND_LINK_UP) && IS_UP(slave->dev))
196 bond_set_slave_active_flags(slave); 196 bond_set_slave_active_flags(slave, BOND_SLAVE_NOTIFY_LATER);
197} 197}
198 198
199/** 199/**
@@ -1796,8 +1796,6 @@ void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout)
1796 BOND_AD_INFO(bond).agg_select_timer = timeout; 1796 BOND_AD_INFO(bond).agg_select_timer = timeout;
1797} 1797}
1798 1798
1799static u16 aggregator_identifier;
1800
1801/** 1799/**
1802 * bond_3ad_initialize - initialize a bond's 802.3ad parameters and structures 1800 * bond_3ad_initialize - initialize a bond's 802.3ad parameters and structures
1803 * @bond: bonding struct to work on 1801 * @bond: bonding struct to work on
@@ -1811,7 +1809,7 @@ void bond_3ad_initialize(struct bonding *bond, u16 tick_resolution)
1811 if (!MAC_ADDRESS_EQUAL(&(BOND_AD_INFO(bond).system.sys_mac_addr), 1809 if (!MAC_ADDRESS_EQUAL(&(BOND_AD_INFO(bond).system.sys_mac_addr),
1812 bond->dev->dev_addr)) { 1810 bond->dev->dev_addr)) {
1813 1811
1814 aggregator_identifier = 0; 1812 BOND_AD_INFO(bond).aggregator_identifier = 0;
1815 1813
1816 BOND_AD_INFO(bond).system.sys_priority = 0xFFFF; 1814 BOND_AD_INFO(bond).system.sys_priority = 0xFFFF;
1817 BOND_AD_INFO(bond).system.sys_mac_addr = *((struct mac_addr *)bond->dev->dev_addr); 1815 BOND_AD_INFO(bond).system.sys_mac_addr = *((struct mac_addr *)bond->dev->dev_addr);
@@ -1880,7 +1878,7 @@ void bond_3ad_bind_slave(struct slave *slave)
1880 ad_initialize_agg(aggregator); 1878 ad_initialize_agg(aggregator);
1881 1879
1882 aggregator->aggregator_mac_address = *((struct mac_addr *)bond->dev->dev_addr); 1880 aggregator->aggregator_mac_address = *((struct mac_addr *)bond->dev->dev_addr);
1883 aggregator->aggregator_identifier = (++aggregator_identifier); 1881 aggregator->aggregator_identifier = ++BOND_AD_INFO(bond).aggregator_identifier;
1884 aggregator->slave = slave; 1882 aggregator->slave = slave;
1885 aggregator->is_active = 0; 1883 aggregator->is_active = 0;
1886 aggregator->num_of_ports = 0; 1884 aggregator->num_of_ports = 0;
@@ -2064,6 +2062,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
2064 struct list_head *iter; 2062 struct list_head *iter;
2065 struct slave *slave; 2063 struct slave *slave;
2066 struct port *port; 2064 struct port *port;
2065 bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER;
2067 2066
2068 read_lock(&bond->lock); 2067 read_lock(&bond->lock);
2069 rcu_read_lock(); 2068 rcu_read_lock();
@@ -2121,8 +2120,19 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
2121 } 2120 }
2122 2121
2123re_arm: 2122re_arm:
2123 bond_for_each_slave_rcu(bond, slave, iter) {
2124 if (slave->should_notify) {
2125 should_notify_rtnl = BOND_SLAVE_NOTIFY_NOW;
2126 break;
2127 }
2128 }
2124 rcu_read_unlock(); 2129 rcu_read_unlock();
2125 read_unlock(&bond->lock); 2130 read_unlock(&bond->lock);
2131
2132 if (should_notify_rtnl && rtnl_trylock()) {
2133 bond_slave_state_notify(bond);
2134 rtnl_unlock();
2135 }
2126 queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks); 2136 queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
2127} 2137}
2128 2138
diff --git a/drivers/net/bonding/bond_3ad.h b/drivers/net/bonding/bond_3ad.h
index 13dc9d3c5e34..f4dd9592ac62 100644
--- a/drivers/net/bonding/bond_3ad.h
+++ b/drivers/net/bonding/bond_3ad.h
@@ -253,6 +253,7 @@ struct ad_system {
253struct ad_bond_info { 253struct ad_bond_info {
254 struct ad_system system; /* 802.3ad system structure */ 254 struct ad_system system; /* 802.3ad system structure */
255 u32 agg_select_timer; // Timer to select aggregator after all adapter's hand shakes 255 u32 agg_select_timer; // Timer to select aggregator after all adapter's hand shakes
256 u16 aggregator_identifier;
256}; 257};
257 258
258struct ad_slave_info { 259struct ad_slave_info {
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index a2c47476804d..e8f133e926aa 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -730,7 +730,7 @@ static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bon
730 client_info->ntt = 0; 730 client_info->ntt = 0;
731 } 731 }
732 732
733 if (!vlan_get_tag(skb, &client_info->vlan_id)) 733 if (vlan_get_tag(skb, &client_info->vlan_id))
734 client_info->vlan_id = 0; 734 client_info->vlan_id = 0;
735 735
736 if (!client_info->assigned) { 736 if (!client_info->assigned) {
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 4c08018d7333..e5628fc725c3 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -829,21 +829,25 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
829 if (bond_is_lb(bond)) { 829 if (bond_is_lb(bond)) {
830 bond_alb_handle_active_change(bond, new_active); 830 bond_alb_handle_active_change(bond, new_active);
831 if (old_active) 831 if (old_active)
832 bond_set_slave_inactive_flags(old_active); 832 bond_set_slave_inactive_flags(old_active,
833 BOND_SLAVE_NOTIFY_NOW);
833 if (new_active) 834 if (new_active)
834 bond_set_slave_active_flags(new_active); 835 bond_set_slave_active_flags(new_active,
836 BOND_SLAVE_NOTIFY_NOW);
835 } else { 837 } else {
836 rcu_assign_pointer(bond->curr_active_slave, new_active); 838 rcu_assign_pointer(bond->curr_active_slave, new_active);
837 } 839 }
838 840
839 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) { 841 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
840 if (old_active) 842 if (old_active)
841 bond_set_slave_inactive_flags(old_active); 843 bond_set_slave_inactive_flags(old_active,
844 BOND_SLAVE_NOTIFY_NOW);
842 845
843 if (new_active) { 846 if (new_active) {
844 bool should_notify_peers = false; 847 bool should_notify_peers = false;
845 848
846 bond_set_slave_active_flags(new_active); 849 bond_set_slave_active_flags(new_active,
850 BOND_SLAVE_NOTIFY_NOW);
847 851
848 if (bond->params.fail_over_mac) 852 if (bond->params.fail_over_mac)
849 bond_do_fail_over_mac(bond, new_active, 853 bond_do_fail_over_mac(bond, new_active,
@@ -1193,6 +1197,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1193 return -EBUSY; 1197 return -EBUSY;
1194 } 1198 }
1195 1199
1200 if (bond_dev == slave_dev) {
1201 pr_err("%s: cannot enslave bond to itself.\n", bond_dev->name);
1202 return -EPERM;
1203 }
1204
1196 /* vlan challenged mutual exclusion */ 1205 /* vlan challenged mutual exclusion */
1197 /* no need to lock since we're protected by rtnl_lock */ 1206 /* no need to lock since we're protected by rtnl_lock */
1198 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) { 1207 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
@@ -1270,9 +1279,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1270 1279
1271 if (slave_ops->ndo_set_mac_address == NULL) { 1280 if (slave_ops->ndo_set_mac_address == NULL) {
1272 if (!bond_has_slaves(bond)) { 1281 if (!bond_has_slaves(bond)) {
1273 pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.", 1282 pr_warn("%s: Warning: The first slave device specified does not support setting the MAC address.\n",
1274 bond_dev->name); 1283 bond_dev->name);
1275 bond->params.fail_over_mac = BOND_FOM_ACTIVE; 1284 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
1285 bond->params.fail_over_mac = BOND_FOM_ACTIVE;
1286 pr_warn("%s: Setting fail_over_mac to active for active-backup mode.\n",
1287 bond_dev->name);
1288 }
1276 } else if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) { 1289 } else if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
1277 pr_err("%s: Error: The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active.\n", 1290 pr_err("%s: Error: The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active.\n",
1278 bond_dev->name); 1291 bond_dev->name);
@@ -1315,7 +1328,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1315 */ 1328 */
1316 memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN); 1329 memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN);
1317 1330
1318 if (!bond->params.fail_over_mac) { 1331 if (!bond->params.fail_over_mac ||
1332 bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
1319 /* 1333 /*
1320 * Set slave to master's mac address. The application already 1334 * Set slave to master's mac address. The application already
1321 * set the master's mac address to that of the first slave 1335 * set the master's mac address to that of the first slave
@@ -1458,14 +1472,15 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1458 1472
1459 switch (bond->params.mode) { 1473 switch (bond->params.mode) {
1460 case BOND_MODE_ACTIVEBACKUP: 1474 case BOND_MODE_ACTIVEBACKUP:
1461 bond_set_slave_inactive_flags(new_slave); 1475 bond_set_slave_inactive_flags(new_slave,
1476 BOND_SLAVE_NOTIFY_NOW);
1462 break; 1477 break;
1463 case BOND_MODE_8023AD: 1478 case BOND_MODE_8023AD:
1464 /* in 802.3ad mode, the internal mechanism 1479 /* in 802.3ad mode, the internal mechanism
1465 * will activate the slaves in the selected 1480 * will activate the slaves in the selected
1466 * aggregator 1481 * aggregator
1467 */ 1482 */
1468 bond_set_slave_inactive_flags(new_slave); 1483 bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW);
1469 /* if this is the first slave */ 1484 /* if this is the first slave */
1470 if (!prev_slave) { 1485 if (!prev_slave) {
1471 SLAVE_AD_INFO(new_slave).id = 1; 1486 SLAVE_AD_INFO(new_slave).id = 1;
@@ -1483,7 +1498,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1483 case BOND_MODE_TLB: 1498 case BOND_MODE_TLB:
1484 case BOND_MODE_ALB: 1499 case BOND_MODE_ALB:
1485 bond_set_active_slave(new_slave); 1500 bond_set_active_slave(new_slave);
1486 bond_set_slave_inactive_flags(new_slave); 1501 bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW);
1487 break; 1502 break;
1488 default: 1503 default:
1489 pr_debug("This slave is always active in trunk mode\n"); 1504 pr_debug("This slave is always active in trunk mode\n");
@@ -1505,7 +1520,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1505 slave_dev->npinfo = bond->dev->npinfo; 1520 slave_dev->npinfo = bond->dev->npinfo;
1506 if (slave_dev->npinfo) { 1521 if (slave_dev->npinfo) {
1507 if (slave_enable_netpoll(new_slave)) { 1522 if (slave_enable_netpoll(new_slave)) {
1508 read_unlock(&bond->lock);
1509 pr_info("Error, %s: master_dev is using netpoll, " 1523 pr_info("Error, %s: master_dev is using netpoll, "
1510 "but new slave device does not support netpoll.\n", 1524 "but new slave device does not support netpoll.\n",
1511 bond_dev->name); 1525 bond_dev->name);
@@ -1539,9 +1553,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1539 bond_set_carrier(bond); 1553 bond_set_carrier(bond);
1540 1554
1541 if (USES_PRIMARY(bond->params.mode)) { 1555 if (USES_PRIMARY(bond->params.mode)) {
1556 block_netpoll_tx();
1542 write_lock_bh(&bond->curr_slave_lock); 1557 write_lock_bh(&bond->curr_slave_lock);
1543 bond_select_active_slave(bond); 1558 bond_select_active_slave(bond);
1544 write_unlock_bh(&bond->curr_slave_lock); 1559 write_unlock_bh(&bond->curr_slave_lock);
1560 unblock_netpoll_tx();
1545 } 1561 }
1546 1562
1547 pr_info("%s: enslaving %s as a%s interface with a%s link.\n", 1563 pr_info("%s: enslaving %s as a%s interface with a%s link.\n",
@@ -1567,10 +1583,12 @@ err_detach:
1567 if (bond->primary_slave == new_slave) 1583 if (bond->primary_slave == new_slave)
1568 bond->primary_slave = NULL; 1584 bond->primary_slave = NULL;
1569 if (bond->curr_active_slave == new_slave) { 1585 if (bond->curr_active_slave == new_slave) {
1586 block_netpoll_tx();
1570 write_lock_bh(&bond->curr_slave_lock); 1587 write_lock_bh(&bond->curr_slave_lock);
1571 bond_change_active_slave(bond, NULL); 1588 bond_change_active_slave(bond, NULL);
1572 bond_select_active_slave(bond); 1589 bond_select_active_slave(bond);
1573 write_unlock_bh(&bond->curr_slave_lock); 1590 write_unlock_bh(&bond->curr_slave_lock);
1591 unblock_netpoll_tx();
1574 } 1592 }
1575 slave_disable_netpoll(new_slave); 1593 slave_disable_netpoll(new_slave);
1576 1594
@@ -1579,7 +1597,8 @@ err_close:
1579 dev_close(slave_dev); 1597 dev_close(slave_dev);
1580 1598
1581err_restore_mac: 1599err_restore_mac:
1582 if (!bond->params.fail_over_mac) { 1600 if (!bond->params.fail_over_mac ||
1601 bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
1583 /* XXX TODO - fom follow mode needs to change master's 1602 /* XXX TODO - fom follow mode needs to change master's
1584 * MAC if this slave's MAC is in use by the bond, or at 1603 * MAC if this slave's MAC is in use by the bond, or at
1585 * least print a warning. 1604 * least print a warning.
@@ -1645,9 +1664,6 @@ static int __bond_release_one(struct net_device *bond_dev,
1645 return -EINVAL; 1664 return -EINVAL;
1646 } 1665 }
1647 1666
1648 /* release the slave from its bond */
1649 bond->slave_cnt--;
1650
1651 bond_sysfs_slave_del(slave); 1667 bond_sysfs_slave_del(slave);
1652 1668
1653 bond_upper_dev_unlink(bond_dev, slave_dev); 1669 bond_upper_dev_unlink(bond_dev, slave_dev);
@@ -1672,7 +1688,8 @@ static int __bond_release_one(struct net_device *bond_dev,
1672 1688
1673 bond->current_arp_slave = NULL; 1689 bond->current_arp_slave = NULL;
1674 1690
1675 if (!all && !bond->params.fail_over_mac) { 1691 if (!all && (!bond->params.fail_over_mac ||
1692 bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
1676 if (ether_addr_equal_64bits(bond_dev->dev_addr, slave->perm_hwaddr) && 1693 if (ether_addr_equal_64bits(bond_dev->dev_addr, slave->perm_hwaddr) &&
1677 bond_has_slaves(bond)) 1694 bond_has_slaves(bond))
1678 pr_warn("%s: Warning: the permanent HWaddr of %s - %pM - is still in use by %s. Set the HWaddr of %s to a different address to avoid conflicts.\n", 1695 pr_warn("%s: Warning: the permanent HWaddr of %s - %pM - is still in use by %s. Set the HWaddr of %s to a different address to avoid conflicts.\n",
@@ -1728,6 +1745,7 @@ static int __bond_release_one(struct net_device *bond_dev,
1728 1745
1729 unblock_netpoll_tx(); 1746 unblock_netpoll_tx();
1730 synchronize_rcu(); 1747 synchronize_rcu();
1748 bond->slave_cnt--;
1731 1749
1732 if (!bond_has_slaves(bond)) { 1750 if (!bond_has_slaves(bond)) {
1733 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev); 1751 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
@@ -1769,7 +1787,8 @@ static int __bond_release_one(struct net_device *bond_dev,
1769 /* close slave before restoring its mac address */ 1787 /* close slave before restoring its mac address */
1770 dev_close(slave_dev); 1788 dev_close(slave_dev);
1771 1789
1772 if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) { 1790 if (bond->params.fail_over_mac != BOND_FOM_ACTIVE ||
1791 bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
1773 /* restore original ("permanent") mac address */ 1792 /* restore original ("permanent") mac address */
1774 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN); 1793 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
1775 addr.sa_family = slave_dev->type; 1794 addr.sa_family = slave_dev->type;
@@ -2004,7 +2023,8 @@ static void bond_miimon_commit(struct bonding *bond)
2004 2023
2005 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP || 2024 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP ||
2006 bond->params.mode == BOND_MODE_8023AD) 2025 bond->params.mode == BOND_MODE_8023AD)
2007 bond_set_slave_inactive_flags(slave); 2026 bond_set_slave_inactive_flags(slave,
2027 BOND_SLAVE_NOTIFY_NOW);
2008 2028
2009 pr_info("%s: link status definitely down for interface %s, disabling it\n", 2029 pr_info("%s: link status definitely down for interface %s, disabling it\n",
2010 bond->dev->name, slave->dev->name); 2030 bond->dev->name, slave->dev->name);
@@ -2551,7 +2571,8 @@ static void bond_ab_arp_commit(struct bonding *bond)
2551 slave->link = BOND_LINK_UP; 2571 slave->link = BOND_LINK_UP;
2552 if (bond->current_arp_slave) { 2572 if (bond->current_arp_slave) {
2553 bond_set_slave_inactive_flags( 2573 bond_set_slave_inactive_flags(
2554 bond->current_arp_slave); 2574 bond->current_arp_slave,
2575 BOND_SLAVE_NOTIFY_NOW);
2555 bond->current_arp_slave = NULL; 2576 bond->current_arp_slave = NULL;
2556 } 2577 }
2557 2578
@@ -2571,7 +2592,8 @@ static void bond_ab_arp_commit(struct bonding *bond)
2571 slave->link_failure_count++; 2592 slave->link_failure_count++;
2572 2593
2573 slave->link = BOND_LINK_DOWN; 2594 slave->link = BOND_LINK_DOWN;
2574 bond_set_slave_inactive_flags(slave); 2595 bond_set_slave_inactive_flags(slave,
2596 BOND_SLAVE_NOTIFY_NOW);
2575 2597
2576 pr_info("%s: link status definitely down for interface %s, disabling it\n", 2598 pr_info("%s: link status definitely down for interface %s, disabling it\n",
2577 bond->dev->name, slave->dev->name); 2599 bond->dev->name, slave->dev->name);
@@ -2604,17 +2626,17 @@ do_failover:
2604 2626
2605/* 2627/*
2606 * Send ARP probes for active-backup mode ARP monitor. 2628 * Send ARP probes for active-backup mode ARP monitor.
2629 *
2630 * Called with rcu_read_lock hold.
2607 */ 2631 */
2608static bool bond_ab_arp_probe(struct bonding *bond) 2632static bool bond_ab_arp_probe(struct bonding *bond)
2609{ 2633{
2610 struct slave *slave, *before = NULL, *new_slave = NULL, 2634 struct slave *slave, *before = NULL, *new_slave = NULL,
2611 *curr_arp_slave, *curr_active_slave; 2635 *curr_arp_slave = rcu_dereference(bond->current_arp_slave),
2636 *curr_active_slave = rcu_dereference(bond->curr_active_slave);
2612 struct list_head *iter; 2637 struct list_head *iter;
2613 bool found = false; 2638 bool found = false;
2614 2639 bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER;
2615 rcu_read_lock();
2616 curr_arp_slave = rcu_dereference(bond->current_arp_slave);
2617 curr_active_slave = rcu_dereference(bond->curr_active_slave);
2618 2640
2619 if (curr_arp_slave && curr_active_slave) 2641 if (curr_arp_slave && curr_active_slave)
2620 pr_info("PROBE: c_arp %s && cas %s BAD\n", 2642 pr_info("PROBE: c_arp %s && cas %s BAD\n",
@@ -2623,32 +2645,23 @@ static bool bond_ab_arp_probe(struct bonding *bond)
2623 2645
2624 if (curr_active_slave) { 2646 if (curr_active_slave) {
2625 bond_arp_send_all(bond, curr_active_slave); 2647 bond_arp_send_all(bond, curr_active_slave);
2626 rcu_read_unlock(); 2648 return should_notify_rtnl;
2627 return true;
2628 } 2649 }
2629 rcu_read_unlock();
2630 2650
2631 /* if we don't have a curr_active_slave, search for the next available 2651 /* if we don't have a curr_active_slave, search for the next available
2632 * backup slave from the current_arp_slave and make it the candidate 2652 * backup slave from the current_arp_slave and make it the candidate
2633 * for becoming the curr_active_slave 2653 * for becoming the curr_active_slave
2634 */ 2654 */
2635 2655
2636 if (!rtnl_trylock())
2637 return false;
2638 /* curr_arp_slave might have gone away */
2639 curr_arp_slave = ACCESS_ONCE(bond->current_arp_slave);
2640
2641 if (!curr_arp_slave) { 2656 if (!curr_arp_slave) {
2642 curr_arp_slave = bond_first_slave(bond); 2657 curr_arp_slave = bond_first_slave_rcu(bond);
2643 if (!curr_arp_slave) { 2658 if (!curr_arp_slave)
2644 rtnl_unlock(); 2659 return should_notify_rtnl;
2645 return true;
2646 }
2647 } 2660 }
2648 2661
2649 bond_set_slave_inactive_flags(curr_arp_slave); 2662 bond_set_slave_inactive_flags(curr_arp_slave, BOND_SLAVE_NOTIFY_LATER);
2650 2663
2651 bond_for_each_slave(bond, slave, iter) { 2664 bond_for_each_slave_rcu(bond, slave, iter) {
2652 if (!found && !before && IS_UP(slave->dev)) 2665 if (!found && !before && IS_UP(slave->dev))
2653 before = slave; 2666 before = slave;
2654 2667
@@ -2666,7 +2679,8 @@ static bool bond_ab_arp_probe(struct bonding *bond)
2666 if (slave->link_failure_count < UINT_MAX) 2679 if (slave->link_failure_count < UINT_MAX)
2667 slave->link_failure_count++; 2680 slave->link_failure_count++;
2668 2681
2669 bond_set_slave_inactive_flags(slave); 2682 bond_set_slave_inactive_flags(slave,
2683 BOND_SLAVE_NOTIFY_LATER);
2670 2684
2671 pr_info("%s: backup interface %s is now down.\n", 2685 pr_info("%s: backup interface %s is now down.\n",
2672 bond->dev->name, slave->dev->name); 2686 bond->dev->name, slave->dev->name);
@@ -2678,26 +2692,31 @@ static bool bond_ab_arp_probe(struct bonding *bond)
2678 if (!new_slave && before) 2692 if (!new_slave && before)
2679 new_slave = before; 2693 new_slave = before;
2680 2694
2681 if (!new_slave) { 2695 if (!new_slave)
2682 rtnl_unlock(); 2696 goto check_state;
2683 return true;
2684 }
2685 2697
2686 new_slave->link = BOND_LINK_BACK; 2698 new_slave->link = BOND_LINK_BACK;
2687 bond_set_slave_active_flags(new_slave); 2699 bond_set_slave_active_flags(new_slave, BOND_SLAVE_NOTIFY_LATER);
2688 bond_arp_send_all(bond, new_slave); 2700 bond_arp_send_all(bond, new_slave);
2689 new_slave->jiffies = jiffies; 2701 new_slave->jiffies = jiffies;
2690 rcu_assign_pointer(bond->current_arp_slave, new_slave); 2702 rcu_assign_pointer(bond->current_arp_slave, new_slave);
2691 rtnl_unlock();
2692 2703
2693 return true; 2704check_state:
2705 bond_for_each_slave_rcu(bond, slave, iter) {
2706 if (slave->should_notify) {
2707 should_notify_rtnl = BOND_SLAVE_NOTIFY_NOW;
2708 break;
2709 }
2710 }
2711 return should_notify_rtnl;
2694} 2712}
2695 2713
2696static void bond_activebackup_arp_mon(struct work_struct *work) 2714static void bond_activebackup_arp_mon(struct work_struct *work)
2697{ 2715{
2698 struct bonding *bond = container_of(work, struct bonding, 2716 struct bonding *bond = container_of(work, struct bonding,
2699 arp_work.work); 2717 arp_work.work);
2700 bool should_notify_peers = false, should_commit = false; 2718 bool should_notify_peers = false;
2719 bool should_notify_rtnl = false;
2701 int delta_in_ticks; 2720 int delta_in_ticks;
2702 2721
2703 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); 2722 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
@@ -2706,11 +2725,12 @@ static void bond_activebackup_arp_mon(struct work_struct *work)
2706 goto re_arm; 2725 goto re_arm;
2707 2726
2708 rcu_read_lock(); 2727 rcu_read_lock();
2728
2709 should_notify_peers = bond_should_notify_peers(bond); 2729 should_notify_peers = bond_should_notify_peers(bond);
2710 should_commit = bond_ab_arp_inspect(bond);
2711 rcu_read_unlock();
2712 2730
2713 if (should_commit) { 2731 if (bond_ab_arp_inspect(bond)) {
2732 rcu_read_unlock();
2733
2714 /* Race avoidance with bond_close flush of workqueue */ 2734 /* Race avoidance with bond_close flush of workqueue */
2715 if (!rtnl_trylock()) { 2735 if (!rtnl_trylock()) {
2716 delta_in_ticks = 1; 2736 delta_in_ticks = 1;
@@ -2719,23 +2739,28 @@ static void bond_activebackup_arp_mon(struct work_struct *work)
2719 } 2739 }
2720 2740
2721 bond_ab_arp_commit(bond); 2741 bond_ab_arp_commit(bond);
2742
2722 rtnl_unlock(); 2743 rtnl_unlock();
2744 rcu_read_lock();
2723 } 2745 }
2724 2746
2725 if (!bond_ab_arp_probe(bond)) { 2747 should_notify_rtnl = bond_ab_arp_probe(bond);
2726 /* rtnl locking failed, re-arm */ 2748 rcu_read_unlock();
2727 delta_in_ticks = 1;
2728 should_notify_peers = false;
2729 }
2730 2749
2731re_arm: 2750re_arm:
2732 if (bond->params.arp_interval) 2751 if (bond->params.arp_interval)
2733 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks); 2752 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
2734 2753
2735 if (should_notify_peers) { 2754 if (should_notify_peers || should_notify_rtnl) {
2736 if (!rtnl_trylock()) 2755 if (!rtnl_trylock())
2737 return; 2756 return;
2738 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev); 2757
2758 if (should_notify_peers)
2759 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
2760 bond->dev);
2761 if (should_notify_rtnl)
2762 bond_slave_state_notify(bond);
2763
2739 rtnl_unlock(); 2764 rtnl_unlock();
2740 } 2765 }
2741} 2766}
@@ -2857,9 +2882,12 @@ static int bond_slave_netdev_event(unsigned long event,
2857 pr_info("%s: Primary slave changed to %s, reselecting active slave.\n", 2882 pr_info("%s: Primary slave changed to %s, reselecting active slave.\n",
2858 bond->dev->name, bond->primary_slave ? slave_dev->name : 2883 bond->dev->name, bond->primary_slave ? slave_dev->name :
2859 "none"); 2884 "none");
2885
2886 block_netpoll_tx();
2860 write_lock_bh(&bond->curr_slave_lock); 2887 write_lock_bh(&bond->curr_slave_lock);
2861 bond_select_active_slave(bond); 2888 bond_select_active_slave(bond);
2862 write_unlock_bh(&bond->curr_slave_lock); 2889 write_unlock_bh(&bond->curr_slave_lock);
2890 unblock_netpoll_tx();
2863 break; 2891 break;
2864 case NETDEV_FEAT_CHANGE: 2892 case NETDEV_FEAT_CHANGE:
2865 bond_compute_features(bond); 2893 bond_compute_features(bond);
@@ -3032,9 +3060,11 @@ static int bond_open(struct net_device *bond_dev)
3032 bond_for_each_slave(bond, slave, iter) { 3060 bond_for_each_slave(bond, slave, iter) {
3033 if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP) 3061 if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP)
3034 && (slave != bond->curr_active_slave)) { 3062 && (slave != bond->curr_active_slave)) {
3035 bond_set_slave_inactive_flags(slave); 3063 bond_set_slave_inactive_flags(slave,
3064 BOND_SLAVE_NOTIFY_NOW);
3036 } else { 3065 } else {
3037 bond_set_slave_active_flags(slave); 3066 bond_set_slave_active_flags(slave,
3067 BOND_SLAVE_NOTIFY_NOW);
3038 } 3068 }
3039 } 3069 }
3040 read_unlock(&bond->curr_slave_lock); 3070 read_unlock(&bond->curr_slave_lock);
@@ -3431,7 +3461,8 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
3431 /* If fail_over_mac is enabled, do nothing and return success. 3461 /* If fail_over_mac is enabled, do nothing and return success.
3432 * Returning an error causes ifenslave to fail. 3462 * Returning an error causes ifenslave to fail.
3433 */ 3463 */
3434 if (bond->params.fail_over_mac) 3464 if (bond->params.fail_over_mac &&
3465 bond->params.mode == BOND_MODE_ACTIVEBACKUP)
3435 return 0; 3466 return 0;
3436 3467
3437 if (!is_valid_ether_addr(sa->sa_data)) 3468 if (!is_valid_ether_addr(sa->sa_data))
@@ -3692,7 +3723,7 @@ static inline int bond_slave_override(struct bonding *bond,
3692 3723
3693 3724
3694static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb, 3725static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb,
3695 void *accel_priv) 3726 void *accel_priv, select_queue_fallback_t fallback)
3696{ 3727{
3697 /* 3728 /*
3698 * This helper function exists to help dev_pick_tx get the correct 3729 * This helper function exists to help dev_pick_tx get the correct
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 11cb943222d5..298c26509095 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -14,7 +14,7 @@
14#include <linux/errno.h> 14#include <linux/errno.h>
15#include <linux/if.h> 15#include <linux/if.h>
16#include <linux/netdevice.h> 16#include <linux/netdevice.h>
17#include <linux/rwlock.h> 17#include <linux/spinlock.h>
18#include <linux/rcupdate.h> 18#include <linux/rcupdate.h>
19#include <linux/ctype.h> 19#include <linux/ctype.h>
20#include <linux/inet.h> 20#include <linux/inet.h>
@@ -121,6 +121,7 @@ static struct bond_opt_value bond_resend_igmp_tbl[] = {
121static struct bond_opt_value bond_lp_interval_tbl[] = { 121static struct bond_opt_value bond_lp_interval_tbl[] = {
122 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT}, 122 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
123 { "maxval", INT_MAX, BOND_VALFLAG_MAX}, 123 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
124 { NULL, -1, 0},
124}; 125};
125 126
126static struct bond_option bond_opts[] = { 127static struct bond_option bond_opts[] = {
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 86ccfb9f71cc..2b0fdec695f7 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -195,7 +195,8 @@ struct slave {
195 s8 new_link; 195 s8 new_link;
196 u8 backup:1, /* indicates backup slave. Value corresponds with 196 u8 backup:1, /* indicates backup slave. Value corresponds with
197 BOND_STATE_ACTIVE and BOND_STATE_BACKUP */ 197 BOND_STATE_ACTIVE and BOND_STATE_BACKUP */
198 inactive:1; /* indicates inactive slave */ 198 inactive:1, /* indicates inactive slave */
199 should_notify:1; /* indicateds whether the state changed */
199 u8 duplex; 200 u8 duplex;
200 u32 original_mtu; 201 u32 original_mtu;
201 u32 link_failure_count; 202 u32 link_failure_count;
@@ -303,6 +304,24 @@ static inline void bond_set_backup_slave(struct slave *slave)
303 } 304 }
304} 305}
305 306
307static inline void bond_set_slave_state(struct slave *slave,
308 int slave_state, bool notify)
309{
310 if (slave->backup == slave_state)
311 return;
312
313 slave->backup = slave_state;
314 if (notify) {
315 rtmsg_ifinfo(RTM_NEWLINK, slave->dev, 0, GFP_KERNEL);
316 slave->should_notify = 0;
317 } else {
318 if (slave->should_notify)
319 slave->should_notify = 0;
320 else
321 slave->should_notify = 1;
322 }
323}
324
306static inline void bond_slave_state_change(struct bonding *bond) 325static inline void bond_slave_state_change(struct bonding *bond)
307{ 326{
308 struct list_head *iter; 327 struct list_head *iter;
@@ -316,6 +335,19 @@ static inline void bond_slave_state_change(struct bonding *bond)
316 } 335 }
317} 336}
318 337
338static inline void bond_slave_state_notify(struct bonding *bond)
339{
340 struct list_head *iter;
341 struct slave *tmp;
342
343 bond_for_each_slave(bond, tmp, iter) {
344 if (tmp->should_notify) {
345 rtmsg_ifinfo(RTM_NEWLINK, tmp->dev, 0, GFP_KERNEL);
346 tmp->should_notify = 0;
347 }
348 }
349}
350
319static inline int bond_slave_state(struct slave *slave) 351static inline int bond_slave_state(struct slave *slave)
320{ 352{
321 return slave->backup; 353 return slave->backup;
@@ -343,6 +375,9 @@ static inline bool bond_is_active_slave(struct slave *slave)
343#define BOND_ARP_VALIDATE_ALL (BOND_ARP_VALIDATE_ACTIVE | \ 375#define BOND_ARP_VALIDATE_ALL (BOND_ARP_VALIDATE_ACTIVE | \
344 BOND_ARP_VALIDATE_BACKUP) 376 BOND_ARP_VALIDATE_BACKUP)
345 377
378#define BOND_SLAVE_NOTIFY_NOW true
379#define BOND_SLAVE_NOTIFY_LATER false
380
346static inline int slave_do_arp_validate(struct bonding *bond, 381static inline int slave_do_arp_validate(struct bonding *bond,
347 struct slave *slave) 382 struct slave *slave)
348{ 383{
@@ -394,17 +429,19 @@ static inline void bond_netpoll_send_skb(const struct slave *slave,
394} 429}
395#endif 430#endif
396 431
397static inline void bond_set_slave_inactive_flags(struct slave *slave) 432static inline void bond_set_slave_inactive_flags(struct slave *slave,
433 bool notify)
398{ 434{
399 if (!bond_is_lb(slave->bond)) 435 if (!bond_is_lb(slave->bond))
400 bond_set_backup_slave(slave); 436 bond_set_slave_state(slave, BOND_STATE_BACKUP, notify);
401 if (!slave->bond->params.all_slaves_active) 437 if (!slave->bond->params.all_slaves_active)
402 slave->inactive = 1; 438 slave->inactive = 1;
403} 439}
404 440
405static inline void bond_set_slave_active_flags(struct slave *slave) 441static inline void bond_set_slave_active_flags(struct slave *slave,
442 bool notify)
406{ 443{
407 bond_set_active_slave(slave); 444 bond_set_slave_state(slave, BOND_STATE_ACTIVE, notify);
408 slave->inactive = 0; 445 slave->inactive = 0;
409} 446}
410 447
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index d447b881bbde..9e7d95dae2c7 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
104 104
105config CAN_FLEXCAN 105config CAN_FLEXCAN
106 tristate "Support for Freescale FLEXCAN based chips" 106 tristate "Support for Freescale FLEXCAN based chips"
107 depends on (ARM && CPU_LITTLE_ENDIAN) || PPC 107 depends on ARM || PPC
108 ---help--- 108 ---help---
109 Say Y here if you want to support for Freescale FlexCAN. 109 Say Y here if you want to support for Freescale FlexCAN.
110 110
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 13a909822e25..fc59bc6f040b 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -323,19 +323,10 @@ void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
323 } 323 }
324 324
325 if (!priv->echo_skb[idx]) { 325 if (!priv->echo_skb[idx]) {
326 struct sock *srcsk = skb->sk;
327 326
328 if (atomic_read(&skb->users) != 1) { 327 skb = can_create_echo_skb(skb);
329 struct sk_buff *old_skb = skb; 328 if (!skb)
330 329 return;
331 skb = skb_clone(old_skb, GFP_ATOMIC);
332 kfree_skb(old_skb);
333 if (!skb)
334 return;
335 } else
336 skb_orphan(skb);
337
338 skb->sk = srcsk;
339 330
340 /* make settings for echo to reduce code in irq context */ 331 /* make settings for echo to reduce code in irq context */
341 skb->protocol = htons(ETH_P_CAN); 332 skb->protocol = htons(ETH_P_CAN);
diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index aaed97bee471..61376abdab39 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -144,6 +144,8 @@
144 144
145#define FLEXCAN_MB_CODE_MASK (0xf0ffffff) 145#define FLEXCAN_MB_CODE_MASK (0xf0ffffff)
146 146
147#define FLEXCAN_TIMEOUT_US (50)
148
147/* 149/*
148 * FLEXCAN hardware feature flags 150 * FLEXCAN hardware feature flags
149 * 151 *
@@ -235,9 +237,12 @@ static const struct can_bittiming_const flexcan_bittiming_const = {
235}; 237};
236 238
237/* 239/*
238 * Abstract off the read/write for arm versus ppc. 240 * Abstract off the read/write for arm versus ppc. This
241 * assumes that PPC uses big-endian registers and everything
242 * else uses little-endian registers, independent of CPU
243 * endianess.
239 */ 244 */
240#if defined(__BIG_ENDIAN) 245#if defined(CONFIG_PPC)
241static inline u32 flexcan_read(void __iomem *addr) 246static inline u32 flexcan_read(void __iomem *addr)
242{ 247{
243 return in_be32(addr); 248 return in_be32(addr);
@@ -259,6 +264,22 @@ static inline void flexcan_write(u32 val, void __iomem *addr)
259} 264}
260#endif 265#endif
261 266
267static inline int flexcan_transceiver_enable(const struct flexcan_priv *priv)
268{
269 if (!priv->reg_xceiver)
270 return 0;
271
272 return regulator_enable(priv->reg_xceiver);
273}
274
275static inline int flexcan_transceiver_disable(const struct flexcan_priv *priv)
276{
277 if (!priv->reg_xceiver)
278 return 0;
279
280 return regulator_disable(priv->reg_xceiver);
281}
282
262static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv, 283static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv,
263 u32 reg_esr) 284 u32 reg_esr)
264{ 285{
@@ -266,26 +287,95 @@ static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv,
266 (reg_esr & FLEXCAN_ESR_ERR_BUS); 287 (reg_esr & FLEXCAN_ESR_ERR_BUS);
267} 288}
268 289
269static inline void flexcan_chip_enable(struct flexcan_priv *priv) 290static int flexcan_chip_enable(struct flexcan_priv *priv)
270{ 291{
271 struct flexcan_regs __iomem *regs = priv->base; 292 struct flexcan_regs __iomem *regs = priv->base;
293 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
272 u32 reg; 294 u32 reg;
273 295
274 reg = flexcan_read(&regs->mcr); 296 reg = flexcan_read(&regs->mcr);
275 reg &= ~FLEXCAN_MCR_MDIS; 297 reg &= ~FLEXCAN_MCR_MDIS;
276 flexcan_write(reg, &regs->mcr); 298 flexcan_write(reg, &regs->mcr);
277 299
278 udelay(10); 300 while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
301 usleep_range(10, 20);
302
303 if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK)
304 return -ETIMEDOUT;
305
306 return 0;
279} 307}
280 308
281static inline void flexcan_chip_disable(struct flexcan_priv *priv) 309static int flexcan_chip_disable(struct flexcan_priv *priv)
282{ 310{
283 struct flexcan_regs __iomem *regs = priv->base; 311 struct flexcan_regs __iomem *regs = priv->base;
312 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
284 u32 reg; 313 u32 reg;
285 314
286 reg = flexcan_read(&regs->mcr); 315 reg = flexcan_read(&regs->mcr);
287 reg |= FLEXCAN_MCR_MDIS; 316 reg |= FLEXCAN_MCR_MDIS;
288 flexcan_write(reg, &regs->mcr); 317 flexcan_write(reg, &regs->mcr);
318
319 while (timeout-- && !(flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
320 usleep_range(10, 20);
321
322 if (!(flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
323 return -ETIMEDOUT;
324
325 return 0;
326}
327
328static int flexcan_chip_freeze(struct flexcan_priv *priv)
329{
330 struct flexcan_regs __iomem *regs = priv->base;
331 unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
332 u32 reg;
333
334 reg = flexcan_read(&regs->mcr);
335 reg |= FLEXCAN_MCR_HALT;
336 flexcan_write(reg, &regs->mcr);
337
338 while (timeout-- && !(flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
339 usleep_range(100, 200);
340
341 if (!(flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
342 return -ETIMEDOUT;
343
344 return 0;
345}
346
347static int flexcan_chip_unfreeze(struct flexcan_priv *priv)
348{
349 struct flexcan_regs __iomem *regs = priv->base;
350 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
351 u32 reg;
352
353 reg = flexcan_read(&regs->mcr);
354 reg &= ~FLEXCAN_MCR_HALT;
355 flexcan_write(reg, &regs->mcr);
356
357 while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
358 usleep_range(10, 20);
359
360 if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK)
361 return -ETIMEDOUT;
362
363 return 0;
364}
365
366static int flexcan_chip_softreset(struct flexcan_priv *priv)
367{
368 struct flexcan_regs __iomem *regs = priv->base;
369 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
370
371 flexcan_write(FLEXCAN_MCR_SOFTRST, &regs->mcr);
372 while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_SOFTRST))
373 usleep_range(10, 20);
374
375 if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_SOFTRST)
376 return -ETIMEDOUT;
377
378 return 0;
289} 379}
290 380
291static int flexcan_get_berr_counter(const struct net_device *dev, 381static int flexcan_get_berr_counter(const struct net_device *dev,
@@ -706,19 +796,14 @@ static int flexcan_chip_start(struct net_device *dev)
706 u32 reg_mcr, reg_ctrl; 796 u32 reg_mcr, reg_ctrl;
707 797
708 /* enable module */ 798 /* enable module */
709 flexcan_chip_enable(priv); 799 err = flexcan_chip_enable(priv);
800 if (err)
801 return err;
710 802
711 /* soft reset */ 803 /* soft reset */
712 flexcan_write(FLEXCAN_MCR_SOFTRST, &regs->mcr); 804 err = flexcan_chip_softreset(priv);
713 udelay(10); 805 if (err)
714 806 goto out_chip_disable;
715 reg_mcr = flexcan_read(&regs->mcr);
716 if (reg_mcr & FLEXCAN_MCR_SOFTRST) {
717 netdev_err(dev, "Failed to softreset can module (mcr=0x%08x)\n",
718 reg_mcr);
719 err = -ENODEV;
720 goto out;
721 }
722 807
723 flexcan_set_bittiming(dev); 808 flexcan_set_bittiming(dev);
724 809
@@ -785,16 +870,14 @@ static int flexcan_chip_start(struct net_device *dev)
785 if (priv->devtype_data->features & FLEXCAN_HAS_V10_FEATURES) 870 if (priv->devtype_data->features & FLEXCAN_HAS_V10_FEATURES)
786 flexcan_write(0x0, &regs->rxfgmask); 871 flexcan_write(0x0, &regs->rxfgmask);
787 872
788 if (priv->reg_xceiver) { 873 err = flexcan_transceiver_enable(priv);
789 err = regulator_enable(priv->reg_xceiver); 874 if (err)
790 if (err) 875 goto out_chip_disable;
791 goto out;
792 }
793 876
794 /* synchronize with the can bus */ 877 /* synchronize with the can bus */
795 reg_mcr = flexcan_read(&regs->mcr); 878 err = flexcan_chip_unfreeze(priv);
796 reg_mcr &= ~FLEXCAN_MCR_HALT; 879 if (err)
797 flexcan_write(reg_mcr, &regs->mcr); 880 goto out_transceiver_disable;
798 881
799 priv->can.state = CAN_STATE_ERROR_ACTIVE; 882 priv->can.state = CAN_STATE_ERROR_ACTIVE;
800 883
@@ -807,7 +890,9 @@ static int flexcan_chip_start(struct net_device *dev)
807 890
808 return 0; 891 return 0;
809 892
810 out: 893 out_transceiver_disable:
894 flexcan_transceiver_disable(priv);
895 out_chip_disable:
811 flexcan_chip_disable(priv); 896 flexcan_chip_disable(priv);
812 return err; 897 return err;
813} 898}
@@ -822,18 +907,17 @@ static void flexcan_chip_stop(struct net_device *dev)
822{ 907{
823 struct flexcan_priv *priv = netdev_priv(dev); 908 struct flexcan_priv *priv = netdev_priv(dev);
824 struct flexcan_regs __iomem *regs = priv->base; 909 struct flexcan_regs __iomem *regs = priv->base;
825 u32 reg; 910
911 /* freeze + disable module */
912 flexcan_chip_freeze(priv);
913 flexcan_chip_disable(priv);
826 914
827 /* Disable all interrupts */ 915 /* Disable all interrupts */
828 flexcan_write(0, &regs->imask1); 916 flexcan_write(0, &regs->imask1);
917 flexcan_write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL,
918 &regs->ctrl);
829 919
830 /* Disable + halt module */ 920 flexcan_transceiver_disable(priv);
831 reg = flexcan_read(&regs->mcr);
832 reg |= FLEXCAN_MCR_MDIS | FLEXCAN_MCR_HALT;
833 flexcan_write(reg, &regs->mcr);
834
835 if (priv->reg_xceiver)
836 regulator_disable(priv->reg_xceiver);
837 priv->can.state = CAN_STATE_STOPPED; 921 priv->can.state = CAN_STATE_STOPPED;
838 922
839 return; 923 return;
@@ -863,7 +947,7 @@ static int flexcan_open(struct net_device *dev)
863 /* start chip and queuing */ 947 /* start chip and queuing */
864 err = flexcan_chip_start(dev); 948 err = flexcan_chip_start(dev);
865 if (err) 949 if (err)
866 goto out_close; 950 goto out_free_irq;
867 951
868 can_led_event(dev, CAN_LED_EVENT_OPEN); 952 can_led_event(dev, CAN_LED_EVENT_OPEN);
869 953
@@ -872,6 +956,8 @@ static int flexcan_open(struct net_device *dev)
872 956
873 return 0; 957 return 0;
874 958
959 out_free_irq:
960 free_irq(dev->irq, dev);
875 out_close: 961 out_close:
876 close_candev(dev); 962 close_candev(dev);
877 out_disable_per: 963 out_disable_per:
@@ -942,12 +1028,16 @@ static int register_flexcandev(struct net_device *dev)
942 goto out_disable_ipg; 1028 goto out_disable_ipg;
943 1029
944 /* select "bus clock", chip must be disabled */ 1030 /* select "bus clock", chip must be disabled */
945 flexcan_chip_disable(priv); 1031 err = flexcan_chip_disable(priv);
1032 if (err)
1033 goto out_disable_per;
946 reg = flexcan_read(&regs->ctrl); 1034 reg = flexcan_read(&regs->ctrl);
947 reg |= FLEXCAN_CTRL_CLK_SRC; 1035 reg |= FLEXCAN_CTRL_CLK_SRC;
948 flexcan_write(reg, &regs->ctrl); 1036 flexcan_write(reg, &regs->ctrl);
949 1037
950 flexcan_chip_enable(priv); 1038 err = flexcan_chip_enable(priv);
1039 if (err)
1040 goto out_chip_disable;
951 1041
952 /* set freeze, halt and activate FIFO, restrict register access */ 1042 /* set freeze, halt and activate FIFO, restrict register access */
953 reg = flexcan_read(&regs->mcr); 1043 reg = flexcan_read(&regs->mcr);
@@ -964,14 +1054,15 @@ static int register_flexcandev(struct net_device *dev)
964 if (!(reg & FLEXCAN_MCR_FEN)) { 1054 if (!(reg & FLEXCAN_MCR_FEN)) {
965 netdev_err(dev, "Could not enable RX FIFO, unsupported core\n"); 1055 netdev_err(dev, "Could not enable RX FIFO, unsupported core\n");
966 err = -ENODEV; 1056 err = -ENODEV;
967 goto out_disable_per; 1057 goto out_chip_disable;
968 } 1058 }
969 1059
970 err = register_candev(dev); 1060 err = register_candev(dev);
971 1061
972 out_disable_per:
973 /* disable core and turn off clocks */ 1062 /* disable core and turn off clocks */
1063 out_chip_disable:
974 flexcan_chip_disable(priv); 1064 flexcan_chip_disable(priv);
1065 out_disable_per:
975 clk_disable_unprepare(priv->clk_per); 1066 clk_disable_unprepare(priv->clk_per);
976 out_disable_ipg: 1067 out_disable_ipg:
977 clk_disable_unprepare(priv->clk_ipg); 1068 clk_disable_unprepare(priv->clk_ipg);
@@ -1101,9 +1192,10 @@ static int flexcan_probe(struct platform_device *pdev)
1101static int flexcan_remove(struct platform_device *pdev) 1192static int flexcan_remove(struct platform_device *pdev)
1102{ 1193{
1103 struct net_device *dev = platform_get_drvdata(pdev); 1194 struct net_device *dev = platform_get_drvdata(pdev);
1195 struct flexcan_priv *priv = netdev_priv(dev);
1104 1196
1105 unregister_flexcandev(dev); 1197 unregister_flexcandev(dev);
1106 1198 netif_napi_del(&priv->napi);
1107 free_candev(dev); 1199 free_candev(dev);
1108 1200
1109 return 0; 1201 return 0;
@@ -1114,8 +1206,11 @@ static int flexcan_suspend(struct device *device)
1114{ 1206{
1115 struct net_device *dev = dev_get_drvdata(device); 1207 struct net_device *dev = dev_get_drvdata(device);
1116 struct flexcan_priv *priv = netdev_priv(dev); 1208 struct flexcan_priv *priv = netdev_priv(dev);
1209 int err;
1117 1210
1118 flexcan_chip_disable(priv); 1211 err = flexcan_chip_disable(priv);
1212 if (err)
1213 return err;
1119 1214
1120 if (netif_running(dev)) { 1215 if (netif_running(dev)) {
1121 netif_stop_queue(dev); 1216 netif_stop_queue(dev);
@@ -1136,9 +1231,7 @@ static int flexcan_resume(struct device *device)
1136 netif_device_attach(dev); 1231 netif_device_attach(dev);
1137 netif_start_queue(dev); 1232 netif_start_queue(dev);
1138 } 1233 }
1139 flexcan_chip_enable(priv); 1234 return flexcan_chip_enable(priv);
1140
1141 return 0;
1142} 1235}
1143#endif /* CONFIG_PM_SLEEP */ 1236#endif /* CONFIG_PM_SLEEP */
1144 1237
diff --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c
index e24e6690d672..71594e5676fd 100644
--- a/drivers/net/can/janz-ican3.c
+++ b/drivers/net/can/janz-ican3.c
@@ -18,6 +18,7 @@
18#include <linux/netdevice.h> 18#include <linux/netdevice.h>
19#include <linux/can.h> 19#include <linux/can.h>
20#include <linux/can/dev.h> 20#include <linux/can/dev.h>
21#include <linux/can/skb.h>
21#include <linux/can/error.h> 22#include <linux/can/error.h>
22 23
23#include <linux/mfd/janz.h> 24#include <linux/mfd/janz.h>
@@ -1133,20 +1134,9 @@ static void ican3_handle_message(struct ican3_dev *mod, struct ican3_msg *msg)
1133 */ 1134 */
1134static void ican3_put_echo_skb(struct ican3_dev *mod, struct sk_buff *skb) 1135static void ican3_put_echo_skb(struct ican3_dev *mod, struct sk_buff *skb)
1135{ 1136{
1136 struct sock *srcsk = skb->sk; 1137 skb = can_create_echo_skb(skb);
1137 1138 if (!skb)
1138 if (atomic_read(&skb->users) != 1) { 1139 return;
1139 struct sk_buff *old_skb = skb;
1140
1141 skb = skb_clone(old_skb, GFP_ATOMIC);
1142 kfree_skb(old_skb);
1143 if (!skb)
1144 return;
1145 } else {
1146 skb_orphan(skb);
1147 }
1148
1149 skb->sk = srcsk;
1150 1140
1151 /* save this skb for tx interrupt echo handling */ 1141 /* save this skb for tx interrupt echo handling */
1152 skb_queue_tail(&mod->echoq, skb); 1142 skb_queue_tail(&mod->echoq, skb);
@@ -1322,7 +1312,7 @@ static int ican3_napi(struct napi_struct *napi, int budget)
1322 1312
1323 /* process all communication messages */ 1313 /* process all communication messages */
1324 while (true) { 1314 while (true) {
1325 struct ican3_msg msg; 1315 struct ican3_msg uninitialized_var(msg);
1326 ret = ican3_recv_msg(mod, &msg); 1316 ret = ican3_recv_msg(mod, &msg);
1327 if (ret) 1317 if (ret)
1328 break; 1318 break;
diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 6c859bba8b65..e77d11049747 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -473,6 +473,8 @@ static int kvaser_usb_get_card_info(struct kvaser_usb *dev)
473 return err; 473 return err;
474 474
475 dev->nchannels = msg.u.cardinfo.nchannels; 475 dev->nchannels = msg.u.cardinfo.nchannels;
476 if (dev->nchannels > MAX_NET_DEVICES)
477 return -EINVAL;
476 478
477 return 0; 479 return 0;
478} 480}
diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
index 0a2a5ee79a17..4e94057ef5cf 100644
--- a/drivers/net/can/vcan.c
+++ b/drivers/net/can/vcan.c
@@ -46,6 +46,7 @@
46#include <linux/if_ether.h> 46#include <linux/if_ether.h>
47#include <linux/can.h> 47#include <linux/can.h>
48#include <linux/can/dev.h> 48#include <linux/can/dev.h>
49#include <linux/can/skb.h>
49#include <linux/slab.h> 50#include <linux/slab.h>
50#include <net/rtnetlink.h> 51#include <net/rtnetlink.h>
51 52
@@ -109,25 +110,23 @@ static netdev_tx_t vcan_tx(struct sk_buff *skb, struct net_device *dev)
109 stats->rx_packets++; 110 stats->rx_packets++;
110 stats->rx_bytes += cfd->len; 111 stats->rx_bytes += cfd->len;
111 } 112 }
112 kfree_skb(skb); 113 consume_skb(skb);
113 return NETDEV_TX_OK; 114 return NETDEV_TX_OK;
114 } 115 }
115 116
116 /* perform standard echo handling for CAN network interfaces */ 117 /* perform standard echo handling for CAN network interfaces */
117 118
118 if (loop) { 119 if (loop) {
119 struct sock *srcsk = skb->sk;
120 120
121 skb = skb_share_check(skb, GFP_ATOMIC); 121 skb = can_create_echo_skb(skb);
122 if (!skb) 122 if (!skb)
123 return NETDEV_TX_OK; 123 return NETDEV_TX_OK;
124 124
125 /* receive with packet counting */ 125 /* receive with packet counting */
126 skb->sk = srcsk;
127 vcan_rx(skb, dev); 126 vcan_rx(skb, dev);
128 } else { 127 } else {
129 /* no looped packets => no counting */ 128 /* no looped packets => no counting */
130 kfree_skb(skb); 129 consume_skb(skb);
131 } 130 }
132 return NETDEV_TX_OK; 131 return NETDEV_TX_OK;
133} 132}
diff --git a/drivers/net/ethernet/3com/3c59x.c b/drivers/net/ethernet/3com/3c59x.c
index 0f4241c6e97e..238ccea965c8 100644
--- a/drivers/net/ethernet/3com/3c59x.c
+++ b/drivers/net/ethernet/3com/3c59x.c
@@ -3294,7 +3294,6 @@ static int __init vortex_init(void)
3294 3294
3295static void __exit vortex_eisa_cleanup(void) 3295static void __exit vortex_eisa_cleanup(void)
3296{ 3296{
3297 struct vortex_private *vp;
3298 void __iomem *ioaddr; 3297 void __iomem *ioaddr;
3299 3298
3300#ifdef CONFIG_EISA 3299#ifdef CONFIG_EISA
@@ -3303,7 +3302,6 @@ static void __exit vortex_eisa_cleanup(void)
3303#endif 3302#endif
3304 3303
3305 if (compaq_net_device) { 3304 if (compaq_net_device) {
3306 vp = netdev_priv(compaq_net_device);
3307 ioaddr = ioport_map(compaq_net_device->base_addr, 3305 ioaddr = ioport_map(compaq_net_device->base_addr,
3308 VORTEX_TOTAL_SIZE); 3306 VORTEX_TOTAL_SIZE);
3309 3307
diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c
index 0cc21437478c..511f6eecd58b 100644
--- a/drivers/net/ethernet/allwinner/sun4i-emac.c
+++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
@@ -929,6 +929,9 @@ static int emac_resume(struct platform_device *dev)
929} 929}
930 930
931static const struct of_device_id emac_of_match[] = { 931static const struct of_device_id emac_of_match[] = {
932 {.compatible = "allwinner,sun4i-a10-emac",},
933
934 /* Deprecated */
932 {.compatible = "allwinner,sun4i-emac",}, 935 {.compatible = "allwinner,sun4i-emac",},
933 {}, 936 {},
934}; 937};
diff --git a/drivers/net/ethernet/atheros/alx/main.c b/drivers/net/ethernet/atheros/alx/main.c
index e92ffd6e1c15..380d24922049 100644
--- a/drivers/net/ethernet/atheros/alx/main.c
+++ b/drivers/net/ethernet/atheros/alx/main.c
@@ -1248,19 +1248,13 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1248 * shared register for the high 32 bits, so only a single, aligned, 1248 * shared register for the high 32 bits, so only a single, aligned,
1249 * 4 GB physical address range can be used for descriptors. 1249 * 4 GB physical address range can be used for descriptors.
1250 */ 1250 */
1251 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && 1251 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
1252 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
1253 dev_dbg(&pdev->dev, "DMA to 64-BIT addresses\n"); 1252 dev_dbg(&pdev->dev, "DMA to 64-BIT addresses\n");
1254 } else { 1253 } else {
1255 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); 1254 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
1256 if (err) { 1255 if (err) {
1257 err = dma_set_coherent_mask(&pdev->dev, 1256 dev_err(&pdev->dev, "No usable DMA config, aborting\n");
1258 DMA_BIT_MASK(32)); 1257 goto out_pci_disable;
1259 if (err) {
1260 dev_err(&pdev->dev,
1261 "No usable DMA config, aborting\n");
1262 goto out_pci_disable;
1263 }
1264 } 1258 }
1265 } 1259 }
1266 1260
@@ -1292,6 +1286,7 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1292 alx = netdev_priv(netdev); 1286 alx = netdev_priv(netdev);
1293 spin_lock_init(&alx->hw.mdio_lock); 1287 spin_lock_init(&alx->hw.mdio_lock);
1294 spin_lock_init(&alx->irq_lock); 1288 spin_lock_init(&alx->irq_lock);
1289 spin_lock_init(&alx->stats_lock);
1295 alx->dev = netdev; 1290 alx->dev = netdev;
1296 alx->hw.pdev = pdev; 1291 alx->hw.pdev = pdev;
1297 alx->msg_enable = NETIF_MSG_LINK | NETIF_MSG_HW | NETIF_MSG_IFUP | 1292 alx->msg_enable = NETIF_MSG_LINK | NETIF_MSG_HW | NETIF_MSG_IFUP |
diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
index d5c2d3e912e5..422aab27ea1b 100644
--- a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
+++ b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
@@ -2436,7 +2436,7 @@ err_reset:
2436err_register: 2436err_register:
2437err_sw_init: 2437err_sw_init:
2438err_eeprom: 2438err_eeprom:
2439 iounmap(adapter->hw.hw_addr); 2439 pci_iounmap(pdev, adapter->hw.hw_addr);
2440err_init_netdev: 2440err_init_netdev:
2441err_ioremap: 2441err_ioremap:
2442 free_netdev(netdev); 2442 free_netdev(netdev);
@@ -2474,7 +2474,7 @@ static void atl1e_remove(struct pci_dev *pdev)
2474 unregister_netdev(netdev); 2474 unregister_netdev(netdev);
2475 atl1e_free_ring_resources(adapter); 2475 atl1e_free_ring_resources(adapter);
2476 atl1e_force_ps(&adapter->hw); 2476 atl1e_force_ps(&adapter->hw);
2477 iounmap(adapter->hw.hw_addr); 2477 pci_iounmap(pdev, adapter->hw.hw_addr);
2478 pci_release_regions(pdev); 2478 pci_release_regions(pdev);
2479 free_netdev(netdev); 2479 free_netdev(netdev);
2480 pci_disable_device(pdev); 2480 pci_disable_device(pdev);
diff --git a/drivers/net/ethernet/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c
index 1f7b5aa114fa..8a7bf7dad898 100644
--- a/drivers/net/ethernet/broadcom/b44.c
+++ b/drivers/net/ethernet/broadcom/b44.c
@@ -1484,6 +1484,10 @@ static int b44_open(struct net_device *dev)
1484 add_timer(&bp->timer); 1484 add_timer(&bp->timer);
1485 1485
1486 b44_enable_ints(bp); 1486 b44_enable_ints(bp);
1487
1488 if (bp->flags & B44_FLAG_EXTERNAL_PHY)
1489 phy_start(bp->phydev);
1490
1487 netif_start_queue(dev); 1491 netif_start_queue(dev);
1488out: 1492out:
1489 return err; 1493 return err;
@@ -1646,6 +1650,9 @@ static int b44_close(struct net_device *dev)
1646 1650
1647 netif_stop_queue(dev); 1651 netif_stop_queue(dev);
1648 1652
1653 if (bp->flags & B44_FLAG_EXTERNAL_PHY)
1654 phy_stop(bp->phydev);
1655
1649 napi_disable(&bp->napi); 1656 napi_disable(&bp->napi);
1650 1657
1651 del_timer_sync(&bp->timer); 1658 del_timer_sync(&bp->timer);
@@ -2222,7 +2229,12 @@ static void b44_adjust_link(struct net_device *dev)
2222 } 2229 }
2223 2230
2224 if (status_changed) { 2231 if (status_changed) {
2225 b44_check_phy(bp); 2232 u32 val = br32(bp, B44_TX_CTRL);
2233 if (bp->flags & B44_FLAG_FULL_DUPLEX)
2234 val |= TX_CTRL_DUPLEX;
2235 else
2236 val &= ~TX_CTRL_DUPLEX;
2237 bw32(bp, B44_TX_CTRL, val);
2226 phy_print_status(phydev); 2238 phy_print_status(phydev);
2227 } 2239 }
2228} 2240}
diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c
index 9d2dedadf2df..6c9e1c9bdeb8 100644
--- a/drivers/net/ethernet/broadcom/bnx2.c
+++ b/drivers/net/ethernet/broadcom/bnx2.c
@@ -85,7 +85,7 @@ MODULE_FIRMWARE(FW_RV2P_FILE_09_Ax);
85 85
86static int disable_msi = 0; 86static int disable_msi = 0;
87 87
88module_param(disable_msi, int, 0); 88module_param(disable_msi, int, S_IRUGO);
89MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)"); 89MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
90 90
91typedef enum { 91typedef enum {
@@ -2507,6 +2507,7 @@ bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int ack, int silent)
2507 2507
2508 bp->fw_wr_seq++; 2508 bp->fw_wr_seq++;
2509 msg_data |= bp->fw_wr_seq; 2509 msg_data |= bp->fw_wr_seq;
2510 bp->fw_last_msg = msg_data;
2510 2511
2511 bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data); 2512 bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data);
2512 2513
@@ -4000,8 +4001,23 @@ bnx2_setup_wol(struct bnx2 *bp)
4000 wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL; 4001 wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
4001 } 4002 }
4002 4003
4003 if (!(bp->flags & BNX2_FLAG_NO_WOL)) 4004 if (!(bp->flags & BNX2_FLAG_NO_WOL)) {
4004 bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg, 1, 0); 4005 u32 val;
4006
4007 wol_msg |= BNX2_DRV_MSG_DATA_WAIT3;
4008 if (bp->fw_last_msg || BNX2_CHIP(bp) != BNX2_CHIP_5709) {
4009 bnx2_fw_sync(bp, wol_msg, 1, 0);
4010 return;
4011 }
4012 /* Tell firmware not to power down the PHY yet, otherwise
4013 * the chip will take a long time to respond to MMIO reads.
4014 */
4015 val = bnx2_shmem_rd(bp, BNX2_PORT_FEATURE);
4016 bnx2_shmem_wr(bp, BNX2_PORT_FEATURE,
4017 val | BNX2_PORT_FEATURE_ASF_ENABLED);
4018 bnx2_fw_sync(bp, wol_msg, 1, 0);
4019 bnx2_shmem_wr(bp, BNX2_PORT_FEATURE, val);
4020 }
4005 4021
4006} 4022}
4007 4023
@@ -4033,9 +4049,22 @@ bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
4033 4049
4034 if (bp->wol) 4050 if (bp->wol)
4035 pci_set_power_state(bp->pdev, PCI_D3hot); 4051 pci_set_power_state(bp->pdev, PCI_D3hot);
4036 } else { 4052 break;
4037 pci_set_power_state(bp->pdev, PCI_D3hot); 4053
4054 }
4055 if (!bp->fw_last_msg && BNX2_CHIP(bp) == BNX2_CHIP_5709) {
4056 u32 val;
4057
4058 /* Tell firmware not to power down the PHY yet,
4059 * otherwise the other port may not respond to
4060 * MMIO reads.
4061 */
4062 val = bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION);
4063 val &= ~BNX2_CONDITION_PM_STATE_MASK;
4064 val |= BNX2_CONDITION_PM_STATE_UNPREP;
4065 bnx2_shmem_wr(bp, BNX2_BC_STATE_CONDITION, val);
4038 } 4066 }
4067 pci_set_power_state(bp->pdev, PCI_D3hot);
4039 4068
4040 /* No more memory access after this point until 4069 /* No more memory access after this point until
4041 * device is brought back to D0. 4070 * device is brought back to D0.
diff --git a/drivers/net/ethernet/broadcom/bnx2.h b/drivers/net/ethernet/broadcom/bnx2.h
index f1cf2c44e7ed..e341bc366fa5 100644
--- a/drivers/net/ethernet/broadcom/bnx2.h
+++ b/drivers/net/ethernet/broadcom/bnx2.h
@@ -6900,6 +6900,7 @@ struct bnx2 {
6900 6900
6901 u16 fw_wr_seq; 6901 u16 fw_wr_seq;
6902 u16 fw_drv_pulse_wr_seq; 6902 u16 fw_drv_pulse_wr_seq;
6903 u32 fw_last_msg;
6903 6904
6904 int rx_max_ring; 6905 int rx_max_ring;
6905 int rx_ring_size; 6906 int rx_ring_size;
@@ -7406,6 +7407,10 @@ struct bnx2_rv2p_fw_file {
7406#define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000 7407#define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000
7407#define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000 7408#define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000
7408#define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000 7409#define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000
7410#define BNX2_CONDITION_PM_STATE_MASK 0x00030000
7411#define BNX2_CONDITION_PM_STATE_FULL 0x00030000
7412#define BNX2_CONDITION_PM_STATE_PREP 0x00020000
7413#define BNX2_CONDITION_PM_STATE_UNPREP 0x00010000
7409 7414
7410#define BNX2_BC_STATE_DEBUG_CMD 0x1dc 7415#define BNX2_BC_STATE_DEBUG_CMD 0x1dc
7411#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000 7416#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 9d7419e0390b..dbcff509dc3f 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -1873,7 +1873,7 @@ void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
1873} 1873}
1874 1874
1875u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb, 1875u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb,
1876 void *accel_priv) 1876 void *accel_priv, select_queue_fallback_t fallback)
1877{ 1877{
1878 struct bnx2x *bp = netdev_priv(dev); 1878 struct bnx2x *bp = netdev_priv(dev);
1879 1879
@@ -1895,7 +1895,7 @@ u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb,
1895 } 1895 }
1896 1896
1897 /* select a non-FCoE queue */ 1897 /* select a non-FCoE queue */
1898 return __netdev_pick_tx(dev, skb) % BNX2X_NUM_ETH_QUEUES(bp); 1898 return fallback(dev, skb) % BNX2X_NUM_ETH_QUEUES(bp);
1899} 1899}
1900 1900
1901void bnx2x_set_num_queues(struct bnx2x *bp) 1901void bnx2x_set_num_queues(struct bnx2x *bp)
@@ -3875,7 +3875,9 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
3875 xmit_type); 3875 xmit_type);
3876 } 3876 }
3877 3877
3878 /* Add the macs to the parsing BD this is a vf */ 3878 /* Add the macs to the parsing BD if this is a vf or if
3879 * Tx Switching is enabled.
3880 */
3879 if (IS_VF(bp)) { 3881 if (IS_VF(bp)) {
3880 /* override GRE parameters in BD */ 3882 /* override GRE parameters in BD */
3881 bnx2x_set_fw_mac_addr(&pbd_e2->data.mac_addr.src_hi, 3883 bnx2x_set_fw_mac_addr(&pbd_e2->data.mac_addr.src_hi,
@@ -3887,6 +3889,11 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
3887 &pbd_e2->data.mac_addr.dst_mid, 3889 &pbd_e2->data.mac_addr.dst_mid,
3888 &pbd_e2->data.mac_addr.dst_lo, 3890 &pbd_e2->data.mac_addr.dst_lo,
3889 eth->h_dest); 3891 eth->h_dest);
3892 } else if (bp->flags & TX_SWITCHING) {
3893 bnx2x_set_fw_mac_addr(&pbd_e2->data.mac_addr.dst_hi,
3894 &pbd_e2->data.mac_addr.dst_mid,
3895 &pbd_e2->data.mac_addr.dst_lo,
3896 eth->h_dest);
3890 } 3897 }
3891 3898
3892 SET_FLAG(pbd_e2_parsing_data, 3899 SET_FLAG(pbd_e2_parsing_data,
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
index 17d1689aec6b..a89a40f88c25 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
@@ -496,7 +496,7 @@ int bnx2x_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos);
496 496
497/* select_queue callback */ 497/* select_queue callback */
498u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb, 498u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb,
499 void *accel_priv); 499 void *accel_priv, select_queue_fallback_t fallback);
500 500
501static inline void bnx2x_update_rx_prod(struct bnx2x *bp, 501static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
502 struct bnx2x_fastpath *fp, 502 struct bnx2x_fastpath *fp,
@@ -936,7 +936,7 @@ static inline int bnx2x_func_start(struct bnx2x *bp)
936 else /* CHIP_IS_E1X */ 936 else /* CHIP_IS_E1X */
937 start_params->network_cos_mode = FW_WRR; 937 start_params->network_cos_mode = FW_WRR;
938 938
939 start_params->gre_tunnel_mode = IPGRE_TUNNEL; 939 start_params->gre_tunnel_mode = L2GRE_TUNNEL;
940 start_params->gre_tunnel_rss = GRE_INNER_HEADERS_RSS; 940 start_params->gre_tunnel_rss = GRE_INNER_HEADERS_RSS;
941 941
942 return bnx2x_func_state_change(bp, &func_params); 942 return bnx2x_func_state_change(bp, &func_params);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index c9c445e7b4a5..7d4382286457 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -95,29 +95,29 @@ MODULE_FIRMWARE(FW_FILE_NAME_E1H);
95MODULE_FIRMWARE(FW_FILE_NAME_E2); 95MODULE_FIRMWARE(FW_FILE_NAME_E2);
96 96
97int bnx2x_num_queues; 97int bnx2x_num_queues;
98module_param_named(num_queues, bnx2x_num_queues, int, 0); 98module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
99MODULE_PARM_DESC(num_queues, 99MODULE_PARM_DESC(num_queues,
100 " Set number of queues (default is as a number of CPUs)"); 100 " Set number of queues (default is as a number of CPUs)");
101 101
102static int disable_tpa; 102static int disable_tpa;
103module_param(disable_tpa, int, 0); 103module_param(disable_tpa, int, S_IRUGO);
104MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature"); 104MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
105 105
106static int int_mode; 106static int int_mode;
107module_param(int_mode, int, 0); 107module_param(int_mode, int, S_IRUGO);
108MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X " 108MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
109 "(1 INT#x; 2 MSI)"); 109 "(1 INT#x; 2 MSI)");
110 110
111static int dropless_fc; 111static int dropless_fc;
112module_param(dropless_fc, int, 0); 112module_param(dropless_fc, int, S_IRUGO);
113MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring"); 113MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
114 114
115static int mrrs = -1; 115static int mrrs = -1;
116module_param(mrrs, int, 0); 116module_param(mrrs, int, S_IRUGO);
117MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)"); 117MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
118 118
119static int debug; 119static int debug;
120module_param(debug, int, 0); 120module_param(debug, int, S_IRUGO);
121MODULE_PARM_DESC(debug, " Default debug msglevel"); 121MODULE_PARM_DESC(debug, " Default debug msglevel");
122 122
123struct workqueue_struct *bnx2x_wq; 123struct workqueue_struct *bnx2x_wq;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
index aec5ef2ed7ce..e42f48df6e94 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
@@ -1446,12 +1446,12 @@ static void bnx2x_vf_igu_reset(struct bnx2x *bp, struct bnx2x_virtf *vf)
1446 if (vf->cfg_flags & VF_CFG_INT_SIMD) 1446 if (vf->cfg_flags & VF_CFG_INT_SIMD)
1447 val |= IGU_VF_CONF_SINGLE_ISR_EN; 1447 val |= IGU_VF_CONF_SINGLE_ISR_EN;
1448 val &= ~IGU_VF_CONF_PARENT_MASK; 1448 val &= ~IGU_VF_CONF_PARENT_MASK;
1449 val |= BP_FUNC(bp) << IGU_VF_CONF_PARENT_SHIFT; /* parent PF */ 1449 val |= (BP_ABS_FUNC(bp) >> 1) << IGU_VF_CONF_PARENT_SHIFT;
1450 REG_WR(bp, IGU_REG_VF_CONFIGURATION, val); 1450 REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
1451 1451
1452 DP(BNX2X_MSG_IOV, 1452 DP(BNX2X_MSG_IOV,
1453 "value in IGU_REG_VF_CONFIGURATION of vf %d after write %x\n", 1453 "value in IGU_REG_VF_CONFIGURATION of vf %d after write is 0x%08x\n",
1454 vf->abs_vfid, REG_RD(bp, IGU_REG_VF_CONFIGURATION)); 1454 vf->abs_vfid, val);
1455 1455
1456 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); 1456 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1457 1457
diff --git a/drivers/net/ethernet/broadcom/cnic.c b/drivers/net/ethernet/broadcom/cnic.c
index fcf9105a5476..09f3fefcbf9c 100644
--- a/drivers/net/ethernet/broadcom/cnic.c
+++ b/drivers/net/ethernet/broadcom/cnic.c
@@ -1,6 +1,6 @@
1/* cnic.c: Broadcom CNIC core network driver. 1/* cnic.c: Broadcom CNIC core network driver.
2 * 2 *
3 * Copyright (c) 2006-2013 Broadcom Corporation 3 * Copyright (c) 2006-2014 Broadcom Corporation
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -342,7 +342,7 @@ static int cnic_send_nlmsg(struct cnic_local *cp, u32 type,
342 while (retry < 3) { 342 while (retry < 3) {
343 rc = 0; 343 rc = 0;
344 rcu_read_lock(); 344 rcu_read_lock();
345 ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]); 345 ulp_ops = rcu_dereference(cp->ulp_ops[CNIC_ULP_ISCSI]);
346 if (ulp_ops) 346 if (ulp_ops)
347 rc = ulp_ops->iscsi_nl_send_msg( 347 rc = ulp_ops->iscsi_nl_send_msg(
348 cp->ulp_handle[CNIC_ULP_ISCSI], 348 cp->ulp_handle[CNIC_ULP_ISCSI],
@@ -726,7 +726,7 @@ static void cnic_free_dma(struct cnic_dev *dev, struct cnic_dma *dma)
726 726
727 for (i = 0; i < dma->num_pages; i++) { 727 for (i = 0; i < dma->num_pages; i++) {
728 if (dma->pg_arr[i]) { 728 if (dma->pg_arr[i]) {
729 dma_free_coherent(&dev->pcidev->dev, BNX2_PAGE_SIZE, 729 dma_free_coherent(&dev->pcidev->dev, CNIC_PAGE_SIZE,
730 dma->pg_arr[i], dma->pg_map_arr[i]); 730 dma->pg_arr[i], dma->pg_map_arr[i]);
731 dma->pg_arr[i] = NULL; 731 dma->pg_arr[i] = NULL;
732 } 732 }
@@ -785,7 +785,7 @@ static int cnic_alloc_dma(struct cnic_dev *dev, struct cnic_dma *dma,
785 785
786 for (i = 0; i < pages; i++) { 786 for (i = 0; i < pages; i++) {
787 dma->pg_arr[i] = dma_alloc_coherent(&dev->pcidev->dev, 787 dma->pg_arr[i] = dma_alloc_coherent(&dev->pcidev->dev,
788 BNX2_PAGE_SIZE, 788 CNIC_PAGE_SIZE,
789 &dma->pg_map_arr[i], 789 &dma->pg_map_arr[i],
790 GFP_ATOMIC); 790 GFP_ATOMIC);
791 if (dma->pg_arr[i] == NULL) 791 if (dma->pg_arr[i] == NULL)
@@ -794,8 +794,8 @@ static int cnic_alloc_dma(struct cnic_dev *dev, struct cnic_dma *dma,
794 if (!use_pg_tbl) 794 if (!use_pg_tbl)
795 return 0; 795 return 0;
796 796
797 dma->pgtbl_size = ((pages * 8) + BNX2_PAGE_SIZE - 1) & 797 dma->pgtbl_size = ((pages * 8) + CNIC_PAGE_SIZE - 1) &
798 ~(BNX2_PAGE_SIZE - 1); 798 ~(CNIC_PAGE_SIZE - 1);
799 dma->pgtbl = dma_alloc_coherent(&dev->pcidev->dev, dma->pgtbl_size, 799 dma->pgtbl = dma_alloc_coherent(&dev->pcidev->dev, dma->pgtbl_size,
800 &dma->pgtbl_map, GFP_ATOMIC); 800 &dma->pgtbl_map, GFP_ATOMIC);
801 if (dma->pgtbl == NULL) 801 if (dma->pgtbl == NULL)
@@ -900,8 +900,8 @@ static int cnic_alloc_context(struct cnic_dev *dev)
900 if (BNX2_CHIP(cp) == BNX2_CHIP_5709) { 900 if (BNX2_CHIP(cp) == BNX2_CHIP_5709) {
901 int i, k, arr_size; 901 int i, k, arr_size;
902 902
903 cp->ctx_blk_size = BNX2_PAGE_SIZE; 903 cp->ctx_blk_size = CNIC_PAGE_SIZE;
904 cp->cids_per_blk = BNX2_PAGE_SIZE / 128; 904 cp->cids_per_blk = CNIC_PAGE_SIZE / 128;
905 arr_size = BNX2_MAX_CID / cp->cids_per_blk * 905 arr_size = BNX2_MAX_CID / cp->cids_per_blk *
906 sizeof(struct cnic_ctx); 906 sizeof(struct cnic_ctx);
907 cp->ctx_arr = kzalloc(arr_size, GFP_KERNEL); 907 cp->ctx_arr = kzalloc(arr_size, GFP_KERNEL);
@@ -933,7 +933,7 @@ static int cnic_alloc_context(struct cnic_dev *dev)
933 for (i = 0; i < cp->ctx_blks; i++) { 933 for (i = 0; i < cp->ctx_blks; i++) {
934 cp->ctx_arr[i].ctx = 934 cp->ctx_arr[i].ctx =
935 dma_alloc_coherent(&dev->pcidev->dev, 935 dma_alloc_coherent(&dev->pcidev->dev,
936 BNX2_PAGE_SIZE, 936 CNIC_PAGE_SIZE,
937 &cp->ctx_arr[i].mapping, 937 &cp->ctx_arr[i].mapping,
938 GFP_KERNEL); 938 GFP_KERNEL);
939 if (cp->ctx_arr[i].ctx == NULL) 939 if (cp->ctx_arr[i].ctx == NULL)
@@ -1013,7 +1013,7 @@ static int __cnic_alloc_uio_rings(struct cnic_uio_dev *udev, int pages)
1013 if (udev->l2_ring) 1013 if (udev->l2_ring)
1014 return 0; 1014 return 0;
1015 1015
1016 udev->l2_ring_size = pages * BNX2_PAGE_SIZE; 1016 udev->l2_ring_size = pages * CNIC_PAGE_SIZE;
1017 udev->l2_ring = dma_alloc_coherent(&udev->pdev->dev, udev->l2_ring_size, 1017 udev->l2_ring = dma_alloc_coherent(&udev->pdev->dev, udev->l2_ring_size,
1018 &udev->l2_ring_map, 1018 &udev->l2_ring_map,
1019 GFP_KERNEL | __GFP_COMP); 1019 GFP_KERNEL | __GFP_COMP);
@@ -1021,7 +1021,7 @@ static int __cnic_alloc_uio_rings(struct cnic_uio_dev *udev, int pages)
1021 return -ENOMEM; 1021 return -ENOMEM;
1022 1022
1023 udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size; 1023 udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size;
1024 udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size); 1024 udev->l2_buf_size = CNIC_PAGE_ALIGN(udev->l2_buf_size);
1025 udev->l2_buf = dma_alloc_coherent(&udev->pdev->dev, udev->l2_buf_size, 1025 udev->l2_buf = dma_alloc_coherent(&udev->pdev->dev, udev->l2_buf_size,
1026 &udev->l2_buf_map, 1026 &udev->l2_buf_map,
1027 GFP_KERNEL | __GFP_COMP); 1027 GFP_KERNEL | __GFP_COMP);
@@ -1102,7 +1102,7 @@ static int cnic_init_uio(struct cnic_dev *dev)
1102 uinfo->mem[0].size = MB_GET_CID_ADDR(TX_TSS_CID + 1102 uinfo->mem[0].size = MB_GET_CID_ADDR(TX_TSS_CID +
1103 TX_MAX_TSS_RINGS + 1); 1103 TX_MAX_TSS_RINGS + 1);
1104 uinfo->mem[1].addr = (unsigned long) cp->status_blk.gen & 1104 uinfo->mem[1].addr = (unsigned long) cp->status_blk.gen &
1105 PAGE_MASK; 1105 CNIC_PAGE_MASK;
1106 if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) 1106 if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)
1107 uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9; 1107 uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9;
1108 else 1108 else
@@ -1113,7 +1113,7 @@ static int cnic_init_uio(struct cnic_dev *dev)
1113 uinfo->mem[0].size = pci_resource_len(dev->pcidev, 0); 1113 uinfo->mem[0].size = pci_resource_len(dev->pcidev, 0);
1114 1114
1115 uinfo->mem[1].addr = (unsigned long) cp->bnx2x_def_status_blk & 1115 uinfo->mem[1].addr = (unsigned long) cp->bnx2x_def_status_blk &
1116 PAGE_MASK; 1116 CNIC_PAGE_MASK;
1117 uinfo->mem[1].size = sizeof(*cp->bnx2x_def_status_blk); 1117 uinfo->mem[1].size = sizeof(*cp->bnx2x_def_status_blk);
1118 1118
1119 uinfo->name = "bnx2x_cnic"; 1119 uinfo->name = "bnx2x_cnic";
@@ -1267,14 +1267,14 @@ static int cnic_alloc_bnx2x_resc(struct cnic_dev *dev)
1267 for (i = MAX_ISCSI_TBL_SZ; i < cp->max_cid_space; i++) 1267 for (i = MAX_ISCSI_TBL_SZ; i < cp->max_cid_space; i++)
1268 cp->ctx_tbl[i].ulp_proto_id = CNIC_ULP_FCOE; 1268 cp->ctx_tbl[i].ulp_proto_id = CNIC_ULP_FCOE;
1269 1269
1270 pages = PAGE_ALIGN(cp->max_cid_space * CNIC_KWQ16_DATA_SIZE) / 1270 pages = CNIC_PAGE_ALIGN(cp->max_cid_space * CNIC_KWQ16_DATA_SIZE) /
1271 PAGE_SIZE; 1271 CNIC_PAGE_SIZE;
1272 1272
1273 ret = cnic_alloc_dma(dev, kwq_16_dma, pages, 0); 1273 ret = cnic_alloc_dma(dev, kwq_16_dma, pages, 0);
1274 if (ret) 1274 if (ret)
1275 return -ENOMEM; 1275 return -ENOMEM;
1276 1276
1277 n = PAGE_SIZE / CNIC_KWQ16_DATA_SIZE; 1277 n = CNIC_PAGE_SIZE / CNIC_KWQ16_DATA_SIZE;
1278 for (i = 0, j = 0; i < cp->max_cid_space; i++) { 1278 for (i = 0, j = 0; i < cp->max_cid_space; i++) {
1279 long off = CNIC_KWQ16_DATA_SIZE * (i % n); 1279 long off = CNIC_KWQ16_DATA_SIZE * (i % n);
1280 1280
@@ -1296,7 +1296,7 @@ static int cnic_alloc_bnx2x_resc(struct cnic_dev *dev)
1296 goto error; 1296 goto error;
1297 } 1297 }
1298 1298
1299 pages = PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE) / PAGE_SIZE; 1299 pages = CNIC_PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE) / CNIC_PAGE_SIZE;
1300 ret = cnic_alloc_dma(dev, &cp->gbl_buf_info, pages, 0); 1300 ret = cnic_alloc_dma(dev, &cp->gbl_buf_info, pages, 0);
1301 if (ret) 1301 if (ret)
1302 goto error; 1302 goto error;
@@ -1466,8 +1466,8 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1466 cp->r2tq_size = cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS * 1466 cp->r2tq_size = cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS *
1467 BNX2X_ISCSI_R2TQE_SIZE; 1467 BNX2X_ISCSI_R2TQE_SIZE;
1468 cp->hq_size = cp->num_ccells * BNX2X_ISCSI_HQ_BD_SIZE; 1468 cp->hq_size = cp->num_ccells * BNX2X_ISCSI_HQ_BD_SIZE;
1469 pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE; 1469 pages = CNIC_PAGE_ALIGN(cp->hq_size) / CNIC_PAGE_SIZE;
1470 hq_bds = pages * (PAGE_SIZE / BNX2X_ISCSI_HQ_BD_SIZE); 1470 hq_bds = pages * (CNIC_PAGE_SIZE / BNX2X_ISCSI_HQ_BD_SIZE);
1471 cp->num_cqs = req1->num_cqs; 1471 cp->num_cqs = req1->num_cqs;
1472 1472
1473 if (!dev->max_iscsi_conn) 1473 if (!dev->max_iscsi_conn)
@@ -1477,9 +1477,9 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1477 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid), 1477 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid),
1478 req1->rq_num_wqes); 1478 req1->rq_num_wqes);
1479 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), 1479 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
1480 PAGE_SIZE); 1480 CNIC_PAGE_SIZE);
1481 CNIC_WR8(dev, BAR_TSTRORM_INTMEM + 1481 CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
1482 TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); 1482 TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), CNIC_PAGE_BITS);
1483 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + 1483 CNIC_WR16(dev, BAR_TSTRORM_INTMEM +
1484 TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), 1484 TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
1485 req1->num_tasks_per_conn); 1485 req1->num_tasks_per_conn);
@@ -1489,9 +1489,9 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1489 USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid), 1489 USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid),
1490 req1->rq_buffer_size); 1490 req1->rq_buffer_size);
1491 CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), 1491 CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
1492 PAGE_SIZE); 1492 CNIC_PAGE_SIZE);
1493 CNIC_WR8(dev, BAR_USTRORM_INTMEM + 1493 CNIC_WR8(dev, BAR_USTRORM_INTMEM +
1494 USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); 1494 USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), CNIC_PAGE_BITS);
1495 CNIC_WR16(dev, BAR_USTRORM_INTMEM + 1495 CNIC_WR16(dev, BAR_USTRORM_INTMEM +
1496 USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), 1496 USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
1497 req1->num_tasks_per_conn); 1497 req1->num_tasks_per_conn);
@@ -1504,9 +1504,9 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1504 1504
1505 /* init Xstorm RAM */ 1505 /* init Xstorm RAM */
1506 CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), 1506 CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
1507 PAGE_SIZE); 1507 CNIC_PAGE_SIZE);
1508 CNIC_WR8(dev, BAR_XSTRORM_INTMEM + 1508 CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
1509 XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); 1509 XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), CNIC_PAGE_BITS);
1510 CNIC_WR16(dev, BAR_XSTRORM_INTMEM + 1510 CNIC_WR16(dev, BAR_XSTRORM_INTMEM +
1511 XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), 1511 XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
1512 req1->num_tasks_per_conn); 1512 req1->num_tasks_per_conn);
@@ -1519,9 +1519,9 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1519 1519
1520 /* init Cstorm RAM */ 1520 /* init Cstorm RAM */
1521 CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), 1521 CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
1522 PAGE_SIZE); 1522 CNIC_PAGE_SIZE);
1523 CNIC_WR8(dev, BAR_CSTRORM_INTMEM + 1523 CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
1524 CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); 1524 CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), CNIC_PAGE_BITS);
1525 CNIC_WR16(dev, BAR_CSTRORM_INTMEM + 1525 CNIC_WR16(dev, BAR_CSTRORM_INTMEM +
1526 CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), 1526 CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
1527 req1->num_tasks_per_conn); 1527 req1->num_tasks_per_conn);
@@ -1623,18 +1623,18 @@ static int cnic_alloc_bnx2x_conn_resc(struct cnic_dev *dev, u32 l5_cid)
1623 } 1623 }
1624 1624
1625 ctx->cid = cid; 1625 ctx->cid = cid;
1626 pages = PAGE_ALIGN(cp->task_array_size) / PAGE_SIZE; 1626 pages = CNIC_PAGE_ALIGN(cp->task_array_size) / CNIC_PAGE_SIZE;
1627 1627
1628 ret = cnic_alloc_dma(dev, &iscsi->task_array_info, pages, 1); 1628 ret = cnic_alloc_dma(dev, &iscsi->task_array_info, pages, 1);
1629 if (ret) 1629 if (ret)
1630 goto error; 1630 goto error;
1631 1631
1632 pages = PAGE_ALIGN(cp->r2tq_size) / PAGE_SIZE; 1632 pages = CNIC_PAGE_ALIGN(cp->r2tq_size) / CNIC_PAGE_SIZE;
1633 ret = cnic_alloc_dma(dev, &iscsi->r2tq_info, pages, 1); 1633 ret = cnic_alloc_dma(dev, &iscsi->r2tq_info, pages, 1);
1634 if (ret) 1634 if (ret)
1635 goto error; 1635 goto error;
1636 1636
1637 pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE; 1637 pages = CNIC_PAGE_ALIGN(cp->hq_size) / CNIC_PAGE_SIZE;
1638 ret = cnic_alloc_dma(dev, &iscsi->hq_info, pages, 1); 1638 ret = cnic_alloc_dma(dev, &iscsi->hq_info, pages, 1);
1639 if (ret) 1639 if (ret)
1640 goto error; 1640 goto error;
@@ -1760,7 +1760,7 @@ static int cnic_setup_bnx2x_ctx(struct cnic_dev *dev, struct kwqe *wqes[],
1760 ictx->tstorm_st_context.iscsi.hdr_bytes_2_fetch = ISCSI_HEADER_SIZE; 1760 ictx->tstorm_st_context.iscsi.hdr_bytes_2_fetch = ISCSI_HEADER_SIZE;
1761 /* TSTORM requires the base address of RQ DB & not PTE */ 1761 /* TSTORM requires the base address of RQ DB & not PTE */
1762 ictx->tstorm_st_context.iscsi.rq_db_phy_addr.lo = 1762 ictx->tstorm_st_context.iscsi.rq_db_phy_addr.lo =
1763 req2->rq_page_table_addr_lo & PAGE_MASK; 1763 req2->rq_page_table_addr_lo & CNIC_PAGE_MASK;
1764 ictx->tstorm_st_context.iscsi.rq_db_phy_addr.hi = 1764 ictx->tstorm_st_context.iscsi.rq_db_phy_addr.hi =
1765 req2->rq_page_table_addr_hi; 1765 req2->rq_page_table_addr_hi;
1766 ictx->tstorm_st_context.iscsi.iscsi_conn_id = req1->iscsi_conn_id; 1766 ictx->tstorm_st_context.iscsi.iscsi_conn_id = req1->iscsi_conn_id;
@@ -1842,7 +1842,7 @@ static int cnic_setup_bnx2x_ctx(struct cnic_dev *dev, struct kwqe *wqes[],
1842 /* CSTORM and USTORM initialization is different, CSTORM requires 1842 /* CSTORM and USTORM initialization is different, CSTORM requires
1843 * CQ DB base & not PTE addr */ 1843 * CQ DB base & not PTE addr */
1844 ictx->cstorm_st_context.cq_db_base.lo = 1844 ictx->cstorm_st_context.cq_db_base.lo =
1845 req1->cq_page_table_addr_lo & PAGE_MASK; 1845 req1->cq_page_table_addr_lo & CNIC_PAGE_MASK;
1846 ictx->cstorm_st_context.cq_db_base.hi = req1->cq_page_table_addr_hi; 1846 ictx->cstorm_st_context.cq_db_base.hi = req1->cq_page_table_addr_hi;
1847 ictx->cstorm_st_context.iscsi_conn_id = req1->iscsi_conn_id; 1847 ictx->cstorm_st_context.iscsi_conn_id = req1->iscsi_conn_id;
1848 ictx->cstorm_st_context.cq_proc_en_bit_map = (1 << cp->num_cqs) - 1; 1848 ictx->cstorm_st_context.cq_proc_en_bit_map = (1 << cp->num_cqs) - 1;
@@ -2911,7 +2911,7 @@ static int cnic_l2_completion(struct cnic_local *cp)
2911 u16 hw_cons, sw_cons; 2911 u16 hw_cons, sw_cons;
2912 struct cnic_uio_dev *udev = cp->udev; 2912 struct cnic_uio_dev *udev = cp->udev;
2913 union eth_rx_cqe *cqe, *cqe_ring = (union eth_rx_cqe *) 2913 union eth_rx_cqe *cqe, *cqe_ring = (union eth_rx_cqe *)
2914 (udev->l2_ring + (2 * BNX2_PAGE_SIZE)); 2914 (udev->l2_ring + (2 * CNIC_PAGE_SIZE));
2915 u32 cmd; 2915 u32 cmd;
2916 int comp = 0; 2916 int comp = 0;
2917 2917
@@ -3244,7 +3244,8 @@ static int cnic_copy_ulp_stats(struct cnic_dev *dev, int ulp_type)
3244 int rc; 3244 int rc;
3245 3245
3246 mutex_lock(&cnic_lock); 3246 mutex_lock(&cnic_lock);
3247 ulp_ops = cnic_ulp_tbl_prot(ulp_type); 3247 ulp_ops = rcu_dereference_protected(cp->ulp_ops[ulp_type],
3248 lockdep_is_held(&cnic_lock));
3248 if (ulp_ops && ulp_ops->cnic_get_stats) 3249 if (ulp_ops && ulp_ops->cnic_get_stats)
3249 rc = ulp_ops->cnic_get_stats(cp->ulp_handle[ulp_type]); 3250 rc = ulp_ops->cnic_get_stats(cp->ulp_handle[ulp_type]);
3250 else 3251 else
@@ -4384,7 +4385,7 @@ static int cnic_setup_5709_context(struct cnic_dev *dev, int valid)
4384 u32 idx = cp->ctx_arr[i].cid / cp->cids_per_blk; 4385 u32 idx = cp->ctx_arr[i].cid / cp->cids_per_blk;
4385 u32 val; 4386 u32 val;
4386 4387
4387 memset(cp->ctx_arr[i].ctx, 0, BNX2_PAGE_SIZE); 4388 memset(cp->ctx_arr[i].ctx, 0, CNIC_PAGE_SIZE);
4388 4389
4389 CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA0, 4390 CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA0,
4390 (cp->ctx_arr[i].mapping & 0xffffffff) | valid_bit); 4391 (cp->ctx_arr[i].mapping & 0xffffffff) | valid_bit);
@@ -4628,7 +4629,7 @@ static void cnic_init_bnx2_rx_ring(struct cnic_dev *dev)
4628 val = BNX2_L2CTX_L2_STATUSB_NUM(sb_id); 4629 val = BNX2_L2CTX_L2_STATUSB_NUM(sb_id);
4629 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val); 4630 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val);
4630 4631
4631 rxbd = udev->l2_ring + BNX2_PAGE_SIZE; 4632 rxbd = udev->l2_ring + CNIC_PAGE_SIZE;
4632 for (i = 0; i < BNX2_MAX_RX_DESC_CNT; i++, rxbd++) { 4633 for (i = 0; i < BNX2_MAX_RX_DESC_CNT; i++, rxbd++) {
4633 dma_addr_t buf_map; 4634 dma_addr_t buf_map;
4634 int n = (i % cp->l2_rx_ring_size) + 1; 4635 int n = (i % cp->l2_rx_ring_size) + 1;
@@ -4639,11 +4640,11 @@ static void cnic_init_bnx2_rx_ring(struct cnic_dev *dev)
4639 rxbd->rx_bd_haddr_hi = (u64) buf_map >> 32; 4640 rxbd->rx_bd_haddr_hi = (u64) buf_map >> 32;
4640 rxbd->rx_bd_haddr_lo = (u64) buf_map & 0xffffffff; 4641 rxbd->rx_bd_haddr_lo = (u64) buf_map & 0xffffffff;
4641 } 4642 }
4642 val = (u64) (ring_map + BNX2_PAGE_SIZE) >> 32; 4643 val = (u64) (ring_map + CNIC_PAGE_SIZE) >> 32;
4643 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val); 4644 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val);
4644 rxbd->rx_bd_haddr_hi = val; 4645 rxbd->rx_bd_haddr_hi = val;
4645 4646
4646 val = (u64) (ring_map + BNX2_PAGE_SIZE) & 0xffffffff; 4647 val = (u64) (ring_map + CNIC_PAGE_SIZE) & 0xffffffff;
4647 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val); 4648 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val);
4648 rxbd->rx_bd_haddr_lo = val; 4649 rxbd->rx_bd_haddr_lo = val;
4649 4650
@@ -4709,10 +4710,10 @@ static int cnic_start_bnx2_hw(struct cnic_dev *dev)
4709 4710
4710 val = CNIC_RD(dev, BNX2_MQ_CONFIG); 4711 val = CNIC_RD(dev, BNX2_MQ_CONFIG);
4711 val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE; 4712 val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
4712 if (BNX2_PAGE_BITS > 12) 4713 if (CNIC_PAGE_BITS > 12)
4713 val |= (12 - 8) << 4; 4714 val |= (12 - 8) << 4;
4714 else 4715 else
4715 val |= (BNX2_PAGE_BITS - 8) << 4; 4716 val |= (CNIC_PAGE_BITS - 8) << 4;
4716 4717
4717 CNIC_WR(dev, BNX2_MQ_CONFIG, val); 4718 CNIC_WR(dev, BNX2_MQ_CONFIG, val);
4718 4719
@@ -4742,13 +4743,13 @@ static int cnic_start_bnx2_hw(struct cnic_dev *dev)
4742 4743
4743 /* Initialize the kernel work queue context. */ 4744 /* Initialize the kernel work queue context. */
4744 val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE | 4745 val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
4745 (BNX2_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ; 4746 (CNIC_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
4746 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_TYPE, val); 4747 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_TYPE, val);
4747 4748
4748 val = (BNX2_PAGE_SIZE / sizeof(struct kwqe) - 1) << 16; 4749 val = (CNIC_PAGE_SIZE / sizeof(struct kwqe) - 1) << 16;
4749 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val); 4750 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
4750 4751
4751 val = ((BNX2_PAGE_SIZE / sizeof(struct kwqe)) << 16) | KWQ_PAGE_CNT; 4752 val = ((CNIC_PAGE_SIZE / sizeof(struct kwqe)) << 16) | KWQ_PAGE_CNT;
4752 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val); 4753 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
4753 4754
4754 val = (u32) ((u64) cp->kwq_info.pgtbl_map >> 32); 4755 val = (u32) ((u64) cp->kwq_info.pgtbl_map >> 32);
@@ -4768,13 +4769,13 @@ static int cnic_start_bnx2_hw(struct cnic_dev *dev)
4768 4769
4769 /* Initialize the kernel complete queue context. */ 4770 /* Initialize the kernel complete queue context. */
4770 val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE | 4771 val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
4771 (BNX2_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ; 4772 (CNIC_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
4772 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_TYPE, val); 4773 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_TYPE, val);
4773 4774
4774 val = (BNX2_PAGE_SIZE / sizeof(struct kcqe) - 1) << 16; 4775 val = (CNIC_PAGE_SIZE / sizeof(struct kcqe) - 1) << 16;
4775 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val); 4776 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
4776 4777
4777 val = ((BNX2_PAGE_SIZE / sizeof(struct kcqe)) << 16) | KCQ_PAGE_CNT; 4778 val = ((CNIC_PAGE_SIZE / sizeof(struct kcqe)) << 16) | KCQ_PAGE_CNT;
4778 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val); 4779 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
4779 4780
4780 val = (u32) ((u64) cp->kcq1.dma.pgtbl_map >> 32); 4781 val = (u32) ((u64) cp->kcq1.dma.pgtbl_map >> 32);
@@ -4918,7 +4919,7 @@ static void cnic_init_bnx2x_tx_ring(struct cnic_dev *dev,
4918 u32 cli = cp->ethdev->iscsi_l2_client_id; 4919 u32 cli = cp->ethdev->iscsi_l2_client_id;
4919 u32 val; 4920 u32 val;
4920 4921
4921 memset(txbd, 0, BNX2_PAGE_SIZE); 4922 memset(txbd, 0, CNIC_PAGE_SIZE);
4922 4923
4923 buf_map = udev->l2_buf_map; 4924 buf_map = udev->l2_buf_map;
4924 for (i = 0; i < BNX2_MAX_TX_DESC_CNT; i += 3, txbd += 3) { 4925 for (i = 0; i < BNX2_MAX_TX_DESC_CNT; i += 3, txbd += 3) {
@@ -4978,9 +4979,9 @@ static void cnic_init_bnx2x_rx_ring(struct cnic_dev *dev,
4978 struct bnx2x *bp = netdev_priv(dev->netdev); 4979 struct bnx2x *bp = netdev_priv(dev->netdev);
4979 struct cnic_uio_dev *udev = cp->udev; 4980 struct cnic_uio_dev *udev = cp->udev;
4980 struct eth_rx_bd *rxbd = (struct eth_rx_bd *) (udev->l2_ring + 4981 struct eth_rx_bd *rxbd = (struct eth_rx_bd *) (udev->l2_ring +
4981 BNX2_PAGE_SIZE); 4982 CNIC_PAGE_SIZE);
4982 struct eth_rx_cqe_next_page *rxcqe = (struct eth_rx_cqe_next_page *) 4983 struct eth_rx_cqe_next_page *rxcqe = (struct eth_rx_cqe_next_page *)
4983 (udev->l2_ring + (2 * BNX2_PAGE_SIZE)); 4984 (udev->l2_ring + (2 * CNIC_PAGE_SIZE));
4984 struct host_sp_status_block *sb = cp->bnx2x_def_status_blk; 4985 struct host_sp_status_block *sb = cp->bnx2x_def_status_blk;
4985 int i; 4986 int i;
4986 u32 cli = cp->ethdev->iscsi_l2_client_id; 4987 u32 cli = cp->ethdev->iscsi_l2_client_id;
@@ -5004,20 +5005,20 @@ static void cnic_init_bnx2x_rx_ring(struct cnic_dev *dev,
5004 rxbd->addr_lo = cpu_to_le32(buf_map & 0xffffffff); 5005 rxbd->addr_lo = cpu_to_le32(buf_map & 0xffffffff);
5005 } 5006 }
5006 5007
5007 val = (u64) (ring_map + BNX2_PAGE_SIZE) >> 32; 5008 val = (u64) (ring_map + CNIC_PAGE_SIZE) >> 32;
5008 rxbd->addr_hi = cpu_to_le32(val); 5009 rxbd->addr_hi = cpu_to_le32(val);
5009 data->rx.bd_page_base.hi = cpu_to_le32(val); 5010 data->rx.bd_page_base.hi = cpu_to_le32(val);
5010 5011
5011 val = (u64) (ring_map + BNX2_PAGE_SIZE) & 0xffffffff; 5012 val = (u64) (ring_map + CNIC_PAGE_SIZE) & 0xffffffff;
5012 rxbd->addr_lo = cpu_to_le32(val); 5013 rxbd->addr_lo = cpu_to_le32(val);
5013 data->rx.bd_page_base.lo = cpu_to_le32(val); 5014 data->rx.bd_page_base.lo = cpu_to_le32(val);
5014 5015
5015 rxcqe += BNX2X_MAX_RCQ_DESC_CNT; 5016 rxcqe += BNX2X_MAX_RCQ_DESC_CNT;
5016 val = (u64) (ring_map + (2 * BNX2_PAGE_SIZE)) >> 32; 5017 val = (u64) (ring_map + (2 * CNIC_PAGE_SIZE)) >> 32;
5017 rxcqe->addr_hi = cpu_to_le32(val); 5018 rxcqe->addr_hi = cpu_to_le32(val);
5018 data->rx.cqe_page_base.hi = cpu_to_le32(val); 5019 data->rx.cqe_page_base.hi = cpu_to_le32(val);
5019 5020
5020 val = (u64) (ring_map + (2 * BNX2_PAGE_SIZE)) & 0xffffffff; 5021 val = (u64) (ring_map + (2 * CNIC_PAGE_SIZE)) & 0xffffffff;
5021 rxcqe->addr_lo = cpu_to_le32(val); 5022 rxcqe->addr_lo = cpu_to_le32(val);
5022 data->rx.cqe_page_base.lo = cpu_to_le32(val); 5023 data->rx.cqe_page_base.lo = cpu_to_le32(val);
5023 5024
@@ -5265,8 +5266,8 @@ static void cnic_shutdown_rings(struct cnic_dev *dev)
5265 msleep(10); 5266 msleep(10);
5266 } 5267 }
5267 clear_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags); 5268 clear_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags);
5268 rx_ring = udev->l2_ring + BNX2_PAGE_SIZE; 5269 rx_ring = udev->l2_ring + CNIC_PAGE_SIZE;
5269 memset(rx_ring, 0, BNX2_PAGE_SIZE); 5270 memset(rx_ring, 0, CNIC_PAGE_SIZE);
5270} 5271}
5271 5272
5272static int cnic_register_netdev(struct cnic_dev *dev) 5273static int cnic_register_netdev(struct cnic_dev *dev)
diff --git a/drivers/net/ethernet/broadcom/cnic.h b/drivers/net/ethernet/broadcom/cnic.h
index 0d6b13f854d9..d535ae4228b4 100644
--- a/drivers/net/ethernet/broadcom/cnic.h
+++ b/drivers/net/ethernet/broadcom/cnic.h
@@ -1,6 +1,6 @@
1/* cnic.h: Broadcom CNIC core network driver. 1/* cnic.h: Broadcom CNIC core network driver.
2 * 2 *
3 * Copyright (c) 2006-2013 Broadcom Corporation 3 * Copyright (c) 2006-2014 Broadcom Corporation
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/net/ethernet/broadcom/cnic_defs.h b/drivers/net/ethernet/broadcom/cnic_defs.h
index 95a8e4b11c9f..dcbca6997e8f 100644
--- a/drivers/net/ethernet/broadcom/cnic_defs.h
+++ b/drivers/net/ethernet/broadcom/cnic_defs.h
@@ -1,7 +1,7 @@
1 1
2/* cnic.c: Broadcom CNIC core network driver. 2/* cnic.c: Broadcom CNIC core network driver.
3 * 3 *
4 * Copyright (c) 2006-2013 Broadcom Corporation 4 * Copyright (c) 2006-2014 Broadcom Corporation
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/net/ethernet/broadcom/cnic_if.h b/drivers/net/ethernet/broadcom/cnic_if.h
index 8cf6b1926069..5f4d5573a73d 100644
--- a/drivers/net/ethernet/broadcom/cnic_if.h
+++ b/drivers/net/ethernet/broadcom/cnic_if.h
@@ -1,6 +1,6 @@
1/* cnic_if.h: Broadcom CNIC core network driver. 1/* cnic_if.h: Broadcom CNIC core network driver.
2 * 2 *
3 * Copyright (c) 2006-2013 Broadcom Corporation 3 * Copyright (c) 2006-2014 Broadcom Corporation
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -14,8 +14,8 @@
14 14
15#include "bnx2x/bnx2x_mfw_req.h" 15#include "bnx2x/bnx2x_mfw_req.h"
16 16
17#define CNIC_MODULE_VERSION "2.5.19" 17#define CNIC_MODULE_VERSION "2.5.20"
18#define CNIC_MODULE_RELDATE "December 19, 2013" 18#define CNIC_MODULE_RELDATE "March 14, 2014"
19 19
20#define CNIC_ULP_RDMA 0 20#define CNIC_ULP_RDMA 0
21#define CNIC_ULP_ISCSI 1 21#define CNIC_ULP_ISCSI 1
@@ -24,6 +24,16 @@
24#define MAX_CNIC_ULP_TYPE_EXT 3 24#define MAX_CNIC_ULP_TYPE_EXT 3
25#define MAX_CNIC_ULP_TYPE 4 25#define MAX_CNIC_ULP_TYPE 4
26 26
27/* Use CPU native page size up to 16K for cnic ring sizes. */
28#if (PAGE_SHIFT > 14)
29#define CNIC_PAGE_BITS 14
30#else
31#define CNIC_PAGE_BITS PAGE_SHIFT
32#endif
33#define CNIC_PAGE_SIZE (1 << (CNIC_PAGE_BITS))
34#define CNIC_PAGE_ALIGN(addr) ALIGN(addr, CNIC_PAGE_SIZE)
35#define CNIC_PAGE_MASK (~((CNIC_PAGE_SIZE) - 1))
36
27struct kwqe { 37struct kwqe {
28 u32 kwqe_op_flag; 38 u32 kwqe_op_flag;
29 39
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index e2ca03e23dc1..70a225c8df5c 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -2609,13 +2609,14 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
2609 2609
2610 tg3_writephy(tp, MII_CTRL1000, phy9_orig); 2610 tg3_writephy(tp, MII_CTRL1000, phy9_orig);
2611 2611
2612 if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) { 2612 err = tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32);
2613 reg32 &= ~0x3000; 2613 if (err)
2614 tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); 2614 return err;
2615 } else if (!err)
2616 err = -EBUSY;
2617 2615
2618 return err; 2616 reg32 &= ~0x3000;
2617 tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
2618
2619 return 0;
2619} 2620}
2620 2621
2621static void tg3_carrier_off(struct tg3 *tp) 2622static void tg3_carrier_off(struct tg3 *tp)
@@ -6842,8 +6843,7 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
6842 6843
6843 work_mask |= opaque_key; 6844 work_mask |= opaque_key;
6844 6845
6845 if ((desc->err_vlan & RXD_ERR_MASK) != 0 && 6846 if (desc->err_vlan & RXD_ERR_MASK) {
6846 (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
6847 drop_it: 6847 drop_it:
6848 tg3_recycle_rx(tnapi, tpr, opaque_key, 6848 tg3_recycle_rx(tnapi, tpr, opaque_key,
6849 desc_idx, *post_ptr); 6849 desc_idx, *post_ptr);
@@ -14113,12 +14113,12 @@ static int tg3_change_mtu(struct net_device *dev, int new_mtu)
14113 14113
14114 tg3_netif_stop(tp); 14114 tg3_netif_stop(tp);
14115 14115
14116 tg3_set_mtu(dev, tp, new_mtu);
14117
14116 tg3_full_lock(tp, 1); 14118 tg3_full_lock(tp, 1);
14117 14119
14118 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); 14120 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
14119 14121
14120 tg3_set_mtu(dev, tp, new_mtu);
14121
14122 /* Reset PHY, otherwise the read DMA engine will be in a mode that 14122 /* Reset PHY, otherwise the read DMA engine will be in a mode that
14123 * breaks all requests to 256 bytes. 14123 * breaks all requests to 256 bytes.
14124 */ 14124 */
@@ -17649,8 +17649,6 @@ static int tg3_init_one(struct pci_dev *pdev,
17649 17649
17650 tg3_init_bufmgr_config(tp); 17650 tg3_init_bufmgr_config(tp);
17651 17651
17652 features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
17653
17654 /* 5700 B0 chips do not support checksumming correctly due 17652 /* 5700 B0 chips do not support checksumming correctly due
17655 * to hardware bugs. 17653 * to hardware bugs.
17656 */ 17654 */
@@ -17682,7 +17680,8 @@ static int tg3_init_one(struct pci_dev *pdev,
17682 features |= NETIF_F_TSO_ECN; 17680 features |= NETIF_F_TSO_ECN;
17683 } 17681 }
17684 17682
17685 dev->features |= features; 17683 dev->features |= features | NETIF_F_HW_VLAN_CTAG_TX |
17684 NETIF_F_HW_VLAN_CTAG_RX;
17686 dev->vlan_features |= features; 17685 dev->vlan_features |= features;
17687 17686
17688 /* 17687 /*
diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
index ef472385bce4..04321e5a356e 100644
--- a/drivers/net/ethernet/broadcom/tg3.h
+++ b/drivers/net/ethernet/broadcom/tg3.h
@@ -2608,7 +2608,11 @@ struct tg3_rx_buffer_desc {
2608#define RXD_ERR_TOO_SMALL 0x00400000 2608#define RXD_ERR_TOO_SMALL 0x00400000
2609#define RXD_ERR_NO_RESOURCES 0x00800000 2609#define RXD_ERR_NO_RESOURCES 0x00800000
2610#define RXD_ERR_HUGE_FRAME 0x01000000 2610#define RXD_ERR_HUGE_FRAME 0x01000000
2611#define RXD_ERR_MASK 0xffff0000 2611
2612#define RXD_ERR_MASK (RXD_ERR_BAD_CRC | RXD_ERR_COLLISION | \
2613 RXD_ERR_LINK_LOST | RXD_ERR_PHY_DECODE | \
2614 RXD_ERR_MAC_ABRT | RXD_ERR_TOO_SMALL | \
2615 RXD_ERR_NO_RESOURCES | RXD_ERR_HUGE_FRAME)
2612 2616
2613 u32 reserved; 2617 u32 reserved;
2614 u32 opaque; 2618 u32 opaque;
diff --git a/drivers/net/ethernet/brocade/bna/bfa_ioc.c b/drivers/net/ethernet/brocade/bna/bfa_ioc.c
index 1803c3959044..354ae9792bad 100644
--- a/drivers/net/ethernet/brocade/bna/bfa_ioc.c
+++ b/drivers/net/ethernet/brocade/bna/bfa_ioc.c
@@ -1704,7 +1704,7 @@ bfa_flash_sem_get(void __iomem *bar)
1704 while (!bfa_raw_sem_get(bar)) { 1704 while (!bfa_raw_sem_get(bar)) {
1705 if (--n <= 0) 1705 if (--n <= 0)
1706 return BFA_STATUS_BADFLASH; 1706 return BFA_STATUS_BADFLASH;
1707 udelay(10000); 1707 mdelay(10);
1708 } 1708 }
1709 return BFA_STATUS_OK; 1709 return BFA_STATUS_OK;
1710} 1710}
diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
index cf64f3d0b60d..4ad1187e82fb 100644
--- a/drivers/net/ethernet/brocade/bna/bnad.c
+++ b/drivers/net/ethernet/brocade/bna/bnad.c
@@ -707,7 +707,8 @@ bnad_cq_process(struct bnad *bnad, struct bna_ccb *ccb, int budget)
707 else 707 else
708 skb_checksum_none_assert(skb); 708 skb_checksum_none_assert(skb);
709 709
710 if (flags & BNA_CQ_EF_VLAN) 710 if ((flags & BNA_CQ_EF_VLAN) &&
711 (bnad->netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
711 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(cmpl->vlan_tag)); 712 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(cmpl->vlan_tag));
712 713
713 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q->type)) 714 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q->type))
@@ -2094,7 +2095,9 @@ bnad_init_rx_config(struct bnad *bnad, struct bna_rx_config *rx_config)
2094 rx_config->q1_buf_size = BFI_SMALL_RXBUF_SIZE; 2095 rx_config->q1_buf_size = BFI_SMALL_RXBUF_SIZE;
2095 } 2096 }
2096 2097
2097 rx_config->vlan_strip_status = BNA_STATUS_T_ENABLED; 2098 rx_config->vlan_strip_status =
2099 (bnad->netdev->features & NETIF_F_HW_VLAN_CTAG_RX) ?
2100 BNA_STATUS_T_ENABLED : BNA_STATUS_T_DISABLED;
2098} 2101}
2099 2102
2100static void 2103static void
@@ -3245,11 +3248,6 @@ bnad_set_rx_mode(struct net_device *netdev)
3245 BNA_RXMODE_ALLMULTI; 3248 BNA_RXMODE_ALLMULTI;
3246 bna_rx_mode_set(bnad->rx_info[0].rx, new_mode, mode_mask, NULL); 3249 bna_rx_mode_set(bnad->rx_info[0].rx, new_mode, mode_mask, NULL);
3247 3250
3248 if (bnad->cfg_flags & BNAD_CF_PROMISC)
3249 bna_rx_vlan_strip_disable(bnad->rx_info[0].rx);
3250 else
3251 bna_rx_vlan_strip_enable(bnad->rx_info[0].rx);
3252
3253 spin_unlock_irqrestore(&bnad->bna_lock, flags); 3251 spin_unlock_irqrestore(&bnad->bna_lock, flags);
3254} 3252}
3255 3253
@@ -3374,6 +3372,27 @@ bnad_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
3374 return 0; 3372 return 0;
3375} 3373}
3376 3374
3375static int bnad_set_features(struct net_device *dev, netdev_features_t features)
3376{
3377 struct bnad *bnad = netdev_priv(dev);
3378 netdev_features_t changed = features ^ dev->features;
3379
3380 if ((changed & NETIF_F_HW_VLAN_CTAG_RX) && netif_running(dev)) {
3381 unsigned long flags;
3382
3383 spin_lock_irqsave(&bnad->bna_lock, flags);
3384
3385 if (features & NETIF_F_HW_VLAN_CTAG_RX)
3386 bna_rx_vlan_strip_enable(bnad->rx_info[0].rx);
3387 else
3388 bna_rx_vlan_strip_disable(bnad->rx_info[0].rx);
3389
3390 spin_unlock_irqrestore(&bnad->bna_lock, flags);
3391 }
3392
3393 return 0;
3394}
3395
3377#ifdef CONFIG_NET_POLL_CONTROLLER 3396#ifdef CONFIG_NET_POLL_CONTROLLER
3378static void 3397static void
3379bnad_netpoll(struct net_device *netdev) 3398bnad_netpoll(struct net_device *netdev)
@@ -3421,6 +3440,7 @@ static const struct net_device_ops bnad_netdev_ops = {
3421 .ndo_change_mtu = bnad_change_mtu, 3440 .ndo_change_mtu = bnad_change_mtu,
3422 .ndo_vlan_rx_add_vid = bnad_vlan_rx_add_vid, 3441 .ndo_vlan_rx_add_vid = bnad_vlan_rx_add_vid,
3423 .ndo_vlan_rx_kill_vid = bnad_vlan_rx_kill_vid, 3442 .ndo_vlan_rx_kill_vid = bnad_vlan_rx_kill_vid,
3443 .ndo_set_features = bnad_set_features,
3424#ifdef CONFIG_NET_POLL_CONTROLLER 3444#ifdef CONFIG_NET_POLL_CONTROLLER
3425 .ndo_poll_controller = bnad_netpoll 3445 .ndo_poll_controller = bnad_netpoll
3426#endif 3446#endif
@@ -3433,14 +3453,14 @@ bnad_netdev_init(struct bnad *bnad, bool using_dac)
3433 3453
3434 netdev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM | 3454 netdev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM |
3435 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 3455 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3436 NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_HW_VLAN_CTAG_TX; 3456 NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_HW_VLAN_CTAG_TX |
3457 NETIF_F_HW_VLAN_CTAG_RX;
3437 3458
3438 netdev->vlan_features = NETIF_F_SG | NETIF_F_HIGHDMA | 3459 netdev->vlan_features = NETIF_F_SG | NETIF_F_HIGHDMA |
3439 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 3460 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3440 NETIF_F_TSO | NETIF_F_TSO6; 3461 NETIF_F_TSO | NETIF_F_TSO6;
3441 3462
3442 netdev->features |= netdev->hw_features | 3463 netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
3443 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;
3444 3464
3445 if (using_dac) 3465 if (using_dac)
3446 netdev->features |= NETIF_F_HIGHDMA; 3466 netdev->features |= NETIF_F_HIGHDMA;
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 3190d38e16fb..d0c38e01e99f 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -632,11 +632,16 @@ static void gem_rx_refill(struct macb *bp)
632 "Unable to allocate sk_buff\n"); 632 "Unable to allocate sk_buff\n");
633 break; 633 break;
634 } 634 }
635 bp->rx_skbuff[entry] = skb;
636 635
637 /* now fill corresponding descriptor entry */ 636 /* now fill corresponding descriptor entry */
638 paddr = dma_map_single(&bp->pdev->dev, skb->data, 637 paddr = dma_map_single(&bp->pdev->dev, skb->data,
639 bp->rx_buffer_size, DMA_FROM_DEVICE); 638 bp->rx_buffer_size, DMA_FROM_DEVICE);
639 if (dma_mapping_error(&bp->pdev->dev, paddr)) {
640 dev_kfree_skb(skb);
641 break;
642 }
643
644 bp->rx_skbuff[entry] = skb;
640 645
641 if (entry == RX_RING_SIZE - 1) 646 if (entry == RX_RING_SIZE - 1)
642 paddr |= MACB_BIT(RX_WRAP); 647 paddr |= MACB_BIT(RX_WRAP);
@@ -725,7 +730,7 @@ static int gem_rx(struct macb *bp, int budget)
725 skb_put(skb, len); 730 skb_put(skb, len);
726 addr = MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, addr)); 731 addr = MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, addr));
727 dma_unmap_single(&bp->pdev->dev, addr, 732 dma_unmap_single(&bp->pdev->dev, addr,
728 len, DMA_FROM_DEVICE); 733 bp->rx_buffer_size, DMA_FROM_DEVICE);
729 734
730 skb->protocol = eth_type_trans(skb, bp->dev); 735 skb->protocol = eth_type_trans(skb, bp->dev);
731 skb_checksum_none_assert(skb); 736 skb_checksum_none_assert(skb);
@@ -1036,11 +1041,15 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
1036 } 1041 }
1037 1042
1038 entry = macb_tx_ring_wrap(bp->tx_head); 1043 entry = macb_tx_ring_wrap(bp->tx_head);
1039 bp->tx_head++;
1040 netdev_vdbg(bp->dev, "Allocated ring entry %u\n", entry); 1044 netdev_vdbg(bp->dev, "Allocated ring entry %u\n", entry);
1041 mapping = dma_map_single(&bp->pdev->dev, skb->data, 1045 mapping = dma_map_single(&bp->pdev->dev, skb->data,
1042 len, DMA_TO_DEVICE); 1046 len, DMA_TO_DEVICE);
1047 if (dma_mapping_error(&bp->pdev->dev, mapping)) {
1048 kfree_skb(skb);
1049 goto unlock;
1050 }
1043 1051
1052 bp->tx_head++;
1044 tx_skb = &bp->tx_skb[entry]; 1053 tx_skb = &bp->tx_skb[entry];
1045 tx_skb->skb = skb; 1054 tx_skb->skb = skb;
1046 tx_skb->mapping = mapping; 1055 tx_skb->mapping = mapping;
@@ -1066,6 +1075,7 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
1066 if (CIRC_SPACE(bp->tx_head, bp->tx_tail, TX_RING_SIZE) < 1) 1075 if (CIRC_SPACE(bp->tx_head, bp->tx_tail, TX_RING_SIZE) < 1)
1067 netif_stop_queue(dev); 1076 netif_stop_queue(dev);
1068 1077
1078unlock:
1069 spin_unlock_irqrestore(&bp->lock, flags); 1079 spin_unlock_irqrestore(&bp->lock, flags);
1070 1080
1071 return NETDEV_TX_OK; 1081 return NETDEV_TX_OK;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 43ab35fea48d..34e2488767d9 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -6179,6 +6179,7 @@ static struct pci_driver cxgb4_driver = {
6179 .id_table = cxgb4_pci_tbl, 6179 .id_table = cxgb4_pci_tbl,
6180 .probe = init_one, 6180 .probe = init_one,
6181 .remove = remove_one, 6181 .remove = remove_one,
6182 .shutdown = remove_one,
6182 .err_handler = &cxgb4_eeh, 6183 .err_handler = &cxgb4_eeh,
6183}; 6184};
6184 6185
diff --git a/drivers/net/ethernet/dec/tulip/tulip_core.c b/drivers/net/ethernet/dec/tulip/tulip_core.c
index add05f14b38b..1642de78aac8 100644
--- a/drivers/net/ethernet/dec/tulip/tulip_core.c
+++ b/drivers/net/ethernet/dec/tulip/tulip_core.c
@@ -1939,6 +1939,7 @@ static void tulip_remove_one(struct pci_dev *pdev)
1939 pci_iounmap(pdev, tp->base_addr); 1939 pci_iounmap(pdev, tp->base_addr);
1940 free_netdev (dev); 1940 free_netdev (dev);
1941 pci_release_regions (pdev); 1941 pci_release_regions (pdev);
1942 pci_disable_device(pdev);
1942 1943
1943 /* pci_power_off (pdev, -1); */ 1944 /* pci_power_off (pdev, -1); */
1944} 1945}
diff --git a/drivers/net/ethernet/emulex/benet/be.h b/drivers/net/ethernet/emulex/benet/be.h
index 8d09615da585..05529e273050 100644
--- a/drivers/net/ethernet/emulex/benet/be.h
+++ b/drivers/net/ethernet/emulex/benet/be.h
@@ -350,11 +350,13 @@ struct be_drv_stats {
350 u32 roce_drops_crc; 350 u32 roce_drops_crc;
351}; 351};
352 352
353/* A vlan-id of 0xFFFF must be used to clear transparent vlan-tagging */
354#define BE_RESET_VLAN_TAG_ID 0xFFFF
355
353struct be_vf_cfg { 356struct be_vf_cfg {
354 unsigned char mac_addr[ETH_ALEN]; 357 unsigned char mac_addr[ETH_ALEN];
355 int if_handle; 358 int if_handle;
356 int pmac_id; 359 int pmac_id;
357 u16 def_vid;
358 u16 vlan_tag; 360 u16 vlan_tag;
359 u32 tx_rate; 361 u32 tx_rate;
360}; 362};
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index 04ac9c6a0d39..36c80612e21a 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -913,24 +913,14 @@ static int be_ipv6_tx_stall_chk(struct be_adapter *adapter,
913 return BE3_chip(adapter) && be_ipv6_exthdr_check(skb); 913 return BE3_chip(adapter) && be_ipv6_exthdr_check(skb);
914} 914}
915 915
916static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter, 916static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter,
917 struct sk_buff *skb, 917 struct sk_buff *skb,
918 bool *skip_hw_vlan) 918 bool *skip_hw_vlan)
919{ 919{
920 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; 920 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
921 unsigned int eth_hdr_len; 921 unsigned int eth_hdr_len;
922 struct iphdr *ip; 922 struct iphdr *ip;
923 923
924 /* Lancer, SH-R ASICs have a bug wherein Packets that are 32 bytes or less
925 * may cause a transmit stall on that port. So the work-around is to
926 * pad short packets (<= 32 bytes) to a 36-byte length.
927 */
928 if (unlikely(!BEx_chip(adapter) && skb->len <= 32)) {
929 if (skb_padto(skb, 36))
930 goto tx_drop;
931 skb->len = 36;
932 }
933
934 /* For padded packets, BE HW modifies tot_len field in IP header 924 /* For padded packets, BE HW modifies tot_len field in IP header
935 * incorrecly when VLAN tag is inserted by HW. 925 * incorrecly when VLAN tag is inserted by HW.
936 * For padded packets, Lancer computes incorrect checksum. 926 * For padded packets, Lancer computes incorrect checksum.
@@ -959,7 +949,7 @@ static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter,
959 vlan_tx_tag_present(skb)) { 949 vlan_tx_tag_present(skb)) {
960 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan); 950 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan);
961 if (unlikely(!skb)) 951 if (unlikely(!skb))
962 goto tx_drop; 952 goto err;
963 } 953 }
964 954
965 /* HW may lockup when VLAN HW tagging is requested on 955 /* HW may lockup when VLAN HW tagging is requested on
@@ -981,15 +971,39 @@ static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter,
981 be_vlan_tag_tx_chk(adapter, skb)) { 971 be_vlan_tag_tx_chk(adapter, skb)) {
982 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan); 972 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan);
983 if (unlikely(!skb)) 973 if (unlikely(!skb))
984 goto tx_drop; 974 goto err;
985 } 975 }
986 976
987 return skb; 977 return skb;
988tx_drop: 978tx_drop:
989 dev_kfree_skb_any(skb); 979 dev_kfree_skb_any(skb);
980err:
990 return NULL; 981 return NULL;
991} 982}
992 983
984static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter,
985 struct sk_buff *skb,
986 bool *skip_hw_vlan)
987{
988 /* Lancer, SH-R ASICs have a bug wherein Packets that are 32 bytes or
989 * less may cause a transmit stall on that port. So the work-around is
990 * to pad short packets (<= 32 bytes) to a 36-byte length.
991 */
992 if (unlikely(!BEx_chip(adapter) && skb->len <= 32)) {
993 if (skb_padto(skb, 36))
994 return NULL;
995 skb->len = 36;
996 }
997
998 if (BEx_chip(adapter) || lancer_chip(adapter)) {
999 skb = be_lancer_xmit_workarounds(adapter, skb, skip_hw_vlan);
1000 if (!skb)
1001 return NULL;
1002 }
1003
1004 return skb;
1005}
1006
993static netdev_tx_t be_xmit(struct sk_buff *skb, struct net_device *netdev) 1007static netdev_tx_t be_xmit(struct sk_buff *skb, struct net_device *netdev)
994{ 1008{
995 struct be_adapter *adapter = netdev_priv(netdev); 1009 struct be_adapter *adapter = netdev_priv(netdev);
@@ -1157,6 +1171,14 @@ ret:
1157 return status; 1171 return status;
1158} 1172}
1159 1173
1174static void be_clear_promisc(struct be_adapter *adapter)
1175{
1176 adapter->promiscuous = false;
1177 adapter->flags &= ~BE_FLAGS_VLAN_PROMISC;
1178
1179 be_cmd_rx_filter(adapter, IFF_PROMISC, OFF);
1180}
1181
1160static void be_set_rx_mode(struct net_device *netdev) 1182static void be_set_rx_mode(struct net_device *netdev)
1161{ 1183{
1162 struct be_adapter *adapter = netdev_priv(netdev); 1184 struct be_adapter *adapter = netdev_priv(netdev);
@@ -1170,9 +1192,7 @@ static void be_set_rx_mode(struct net_device *netdev)
1170 1192
1171 /* BE was previously in promiscuous mode; disable it */ 1193 /* BE was previously in promiscuous mode; disable it */
1172 if (adapter->promiscuous) { 1194 if (adapter->promiscuous) {
1173 adapter->promiscuous = false; 1195 be_clear_promisc(adapter);
1174 be_cmd_rx_filter(adapter, IFF_PROMISC, OFF);
1175
1176 if (adapter->vlans_added) 1196 if (adapter->vlans_added)
1177 be_vid_config(adapter); 1197 be_vid_config(adapter);
1178 } 1198 }
@@ -1287,24 +1307,20 @@ static int be_set_vf_vlan(struct net_device *netdev,
1287 1307
1288 if (vlan || qos) { 1308 if (vlan || qos) {
1289 vlan |= qos << VLAN_PRIO_SHIFT; 1309 vlan |= qos << VLAN_PRIO_SHIFT;
1290 if (vf_cfg->vlan_tag != vlan) { 1310 if (vf_cfg->vlan_tag != vlan)
1291 /* If this is new value, program it. Else skip. */
1292 vf_cfg->vlan_tag = vlan;
1293 status = be_cmd_set_hsw_config(adapter, vlan, vf + 1, 1311 status = be_cmd_set_hsw_config(adapter, vlan, vf + 1,
1294 vf_cfg->if_handle, 0); 1312 vf_cfg->if_handle, 0);
1295 }
1296 } else { 1313 } else {
1297 /* Reset Transparent Vlan Tagging. */ 1314 /* Reset Transparent Vlan Tagging. */
1298 vf_cfg->vlan_tag = 0; 1315 status = be_cmd_set_hsw_config(adapter, BE_RESET_VLAN_TAG_ID,
1299 vlan = vf_cfg->def_vid; 1316 vf + 1, vf_cfg->if_handle, 0);
1300 status = be_cmd_set_hsw_config(adapter, vlan, vf + 1,
1301 vf_cfg->if_handle, 0);
1302 } 1317 }
1303 1318
1304 1319 if (!status)
1305 if (status) 1320 vf_cfg->vlan_tag = vlan;
1321 else
1306 dev_info(&adapter->pdev->dev, 1322 dev_info(&adapter->pdev->dev,
1307 "VLAN %d config on VF %d failed\n", vlan, vf); 1323 "VLAN %d config on VF %d failed\n", vlan, vf);
1308 return status; 1324 return status;
1309} 1325}
1310 1326
@@ -3013,11 +3029,11 @@ static int be_vf_setup_init(struct be_adapter *adapter)
3013 3029
3014static int be_vf_setup(struct be_adapter *adapter) 3030static int be_vf_setup(struct be_adapter *adapter)
3015{ 3031{
3032 struct device *dev = &adapter->pdev->dev;
3016 struct be_vf_cfg *vf_cfg; 3033 struct be_vf_cfg *vf_cfg;
3017 u16 def_vlan, lnk_speed;
3018 int status, old_vfs, vf; 3034 int status, old_vfs, vf;
3019 struct device *dev = &adapter->pdev->dev;
3020 u32 privileges; 3035 u32 privileges;
3036 u16 lnk_speed;
3021 3037
3022 old_vfs = pci_num_vf(adapter->pdev); 3038 old_vfs = pci_num_vf(adapter->pdev);
3023 if (old_vfs) { 3039 if (old_vfs) {
@@ -3084,12 +3100,6 @@ static int be_vf_setup(struct be_adapter *adapter)
3084 if (!status) 3100 if (!status)
3085 vf_cfg->tx_rate = lnk_speed; 3101 vf_cfg->tx_rate = lnk_speed;
3086 3102
3087 status = be_cmd_get_hsw_config(adapter, &def_vlan,
3088 vf + 1, vf_cfg->if_handle, NULL);
3089 if (status)
3090 goto err;
3091 vf_cfg->def_vid = def_vlan;
3092
3093 if (!old_vfs) 3103 if (!old_vfs)
3094 be_cmd_enable_vf(adapter, vf + 1); 3104 be_cmd_enable_vf(adapter, vf + 1);
3095 } 3105 }
diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c
index 4de8cfd149cf..55e0fa03dc90 100644
--- a/drivers/net/ethernet/ethoc.c
+++ b/drivers/net/ethernet/ethoc.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/dma-mapping.h> 14#include <linux/dma-mapping.h>
15#include <linux/etherdevice.h> 15#include <linux/etherdevice.h>
16#include <linux/clk.h>
16#include <linux/crc32.h> 17#include <linux/crc32.h>
17#include <linux/interrupt.h> 18#include <linux/interrupt.h>
18#include <linux/io.h> 19#include <linux/io.h>
@@ -51,6 +52,7 @@ MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size");
51#define ETH_HASH0 0x48 52#define ETH_HASH0 0x48
52#define ETH_HASH1 0x4c 53#define ETH_HASH1 0x4c
53#define ETH_TXCTRL 0x50 54#define ETH_TXCTRL 0x50
55#define ETH_END 0x54
54 56
55/* mode register */ 57/* mode register */
56#define MODER_RXEN (1 << 0) /* receive enable */ 58#define MODER_RXEN (1 << 0) /* receive enable */
@@ -179,6 +181,7 @@ MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size");
179 * @membase: pointer to buffer memory region 181 * @membase: pointer to buffer memory region
180 * @dma_alloc: dma allocated buffer size 182 * @dma_alloc: dma allocated buffer size
181 * @io_region_size: I/O memory region size 183 * @io_region_size: I/O memory region size
184 * @num_bd: number of buffer descriptors
182 * @num_tx: number of send buffers 185 * @num_tx: number of send buffers
183 * @cur_tx: last send buffer written 186 * @cur_tx: last send buffer written
184 * @dty_tx: last buffer actually sent 187 * @dty_tx: last buffer actually sent
@@ -199,6 +202,7 @@ struct ethoc {
199 int dma_alloc; 202 int dma_alloc;
200 resource_size_t io_region_size; 203 resource_size_t io_region_size;
201 204
205 unsigned int num_bd;
202 unsigned int num_tx; 206 unsigned int num_tx;
203 unsigned int cur_tx; 207 unsigned int cur_tx;
204 unsigned int dty_tx; 208 unsigned int dty_tx;
@@ -216,6 +220,7 @@ struct ethoc {
216 220
217 struct phy_device *phy; 221 struct phy_device *phy;
218 struct mii_bus *mdio; 222 struct mii_bus *mdio;
223 struct clk *clk;
219 s8 phy_id; 224 s8 phy_id;
220}; 225};
221 226
@@ -688,6 +693,11 @@ static int ethoc_mdio_probe(struct net_device *dev)
688 } 693 }
689 694
690 priv->phy = phy; 695 priv->phy = phy;
696 phy->advertising &= ~(ADVERTISED_1000baseT_Full |
697 ADVERTISED_1000baseT_Half);
698 phy->supported &= ~(SUPPORTED_1000baseT_Full |
699 SUPPORTED_1000baseT_Half);
700
691 return 0; 701 return 0;
692} 702}
693 703
@@ -890,6 +900,102 @@ out:
890 return NETDEV_TX_OK; 900 return NETDEV_TX_OK;
891} 901}
892 902
903static int ethoc_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
904{
905 struct ethoc *priv = netdev_priv(dev);
906 struct phy_device *phydev = priv->phy;
907
908 if (!phydev)
909 return -EOPNOTSUPP;
910
911 return phy_ethtool_gset(phydev, cmd);
912}
913
914static int ethoc_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
915{
916 struct ethoc *priv = netdev_priv(dev);
917 struct phy_device *phydev = priv->phy;
918
919 if (!phydev)
920 return -EOPNOTSUPP;
921
922 return phy_ethtool_sset(phydev, cmd);
923}
924
925static int ethoc_get_regs_len(struct net_device *netdev)
926{
927 return ETH_END;
928}
929
930static void ethoc_get_regs(struct net_device *dev, struct ethtool_regs *regs,
931 void *p)
932{
933 struct ethoc *priv = netdev_priv(dev);
934 u32 *regs_buff = p;
935 unsigned i;
936
937 regs->version = 0;
938 for (i = 0; i < ETH_END / sizeof(u32); ++i)
939 regs_buff[i] = ethoc_read(priv, i * sizeof(u32));
940}
941
942static void ethoc_get_ringparam(struct net_device *dev,
943 struct ethtool_ringparam *ring)
944{
945 struct ethoc *priv = netdev_priv(dev);
946
947 ring->rx_max_pending = priv->num_bd - 1;
948 ring->rx_mini_max_pending = 0;
949 ring->rx_jumbo_max_pending = 0;
950 ring->tx_max_pending = priv->num_bd - 1;
951
952 ring->rx_pending = priv->num_rx;
953 ring->rx_mini_pending = 0;
954 ring->rx_jumbo_pending = 0;
955 ring->tx_pending = priv->num_tx;
956}
957
958static int ethoc_set_ringparam(struct net_device *dev,
959 struct ethtool_ringparam *ring)
960{
961 struct ethoc *priv = netdev_priv(dev);
962
963 if (ring->tx_pending < 1 || ring->rx_pending < 1 ||
964 ring->tx_pending + ring->rx_pending > priv->num_bd)
965 return -EINVAL;
966 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
967 return -EINVAL;
968
969 if (netif_running(dev)) {
970 netif_tx_disable(dev);
971 ethoc_disable_rx_and_tx(priv);
972 ethoc_disable_irq(priv, INT_MASK_TX | INT_MASK_RX);
973 synchronize_irq(dev->irq);
974 }
975
976 priv->num_tx = rounddown_pow_of_two(ring->tx_pending);
977 priv->num_rx = ring->rx_pending;
978 ethoc_init_ring(priv, dev->mem_start);
979
980 if (netif_running(dev)) {
981 ethoc_enable_irq(priv, INT_MASK_TX | INT_MASK_RX);
982 ethoc_enable_rx_and_tx(priv);
983 netif_wake_queue(dev);
984 }
985 return 0;
986}
987
988const struct ethtool_ops ethoc_ethtool_ops = {
989 .get_settings = ethoc_get_settings,
990 .set_settings = ethoc_set_settings,
991 .get_regs_len = ethoc_get_regs_len,
992 .get_regs = ethoc_get_regs,
993 .get_link = ethtool_op_get_link,
994 .get_ringparam = ethoc_get_ringparam,
995 .set_ringparam = ethoc_set_ringparam,
996 .get_ts_info = ethtool_op_get_ts_info,
997};
998
893static const struct net_device_ops ethoc_netdev_ops = { 999static const struct net_device_ops ethoc_netdev_ops = {
894 .ndo_open = ethoc_open, 1000 .ndo_open = ethoc_open,
895 .ndo_stop = ethoc_stop, 1001 .ndo_stop = ethoc_stop,
@@ -917,6 +1023,8 @@ static int ethoc_probe(struct platform_device *pdev)
917 int num_bd; 1023 int num_bd;
918 int ret = 0; 1024 int ret = 0;
919 bool random_mac = false; 1025 bool random_mac = false;
1026 struct ethoc_platform_data *pdata = dev_get_platdata(&pdev->dev);
1027 u32 eth_clkfreq = pdata ? pdata->eth_clkfreq : 0;
920 1028
921 /* allocate networking device */ 1029 /* allocate networking device */
922 netdev = alloc_etherdev(sizeof(struct ethoc)); 1030 netdev = alloc_etherdev(sizeof(struct ethoc));
@@ -1016,6 +1124,7 @@ static int ethoc_probe(struct platform_device *pdev)
1016 ret = -ENODEV; 1124 ret = -ENODEV;
1017 goto error; 1125 goto error;
1018 } 1126 }
1127 priv->num_bd = num_bd;
1019 /* num_tx must be a power of two */ 1128 /* num_tx must be a power of two */
1020 priv->num_tx = rounddown_pow_of_two(num_bd >> 1); 1129 priv->num_tx = rounddown_pow_of_two(num_bd >> 1);
1021 priv->num_rx = num_bd - priv->num_tx; 1130 priv->num_rx = num_bd - priv->num_tx;
@@ -1030,8 +1139,7 @@ static int ethoc_probe(struct platform_device *pdev)
1030 } 1139 }
1031 1140
1032 /* Allow the platform setup code to pass in a MAC address. */ 1141 /* Allow the platform setup code to pass in a MAC address. */
1033 if (dev_get_platdata(&pdev->dev)) { 1142 if (pdata) {
1034 struct ethoc_platform_data *pdata = dev_get_platdata(&pdev->dev);
1035 memcpy(netdev->dev_addr, pdata->hwaddr, IFHWADDRLEN); 1143 memcpy(netdev->dev_addr, pdata->hwaddr, IFHWADDRLEN);
1036 priv->phy_id = pdata->phy_id; 1144 priv->phy_id = pdata->phy_id;
1037 } else { 1145 } else {
@@ -1069,6 +1177,27 @@ static int ethoc_probe(struct platform_device *pdev)
1069 if (random_mac) 1177 if (random_mac)
1070 netdev->addr_assign_type = NET_ADDR_RANDOM; 1178 netdev->addr_assign_type = NET_ADDR_RANDOM;
1071 1179
1180 /* Allow the platform setup code to adjust MII management bus clock. */
1181 if (!eth_clkfreq) {
1182 struct clk *clk = devm_clk_get(&pdev->dev, NULL);
1183
1184 if (!IS_ERR(clk)) {
1185 priv->clk = clk;
1186 clk_prepare_enable(clk);
1187 eth_clkfreq = clk_get_rate(clk);
1188 }
1189 }
1190 if (eth_clkfreq) {
1191 u32 clkdiv = MIIMODER_CLKDIV(eth_clkfreq / 2500000 + 1);
1192
1193 if (!clkdiv)
1194 clkdiv = 2;
1195 dev_dbg(&pdev->dev, "setting MII clkdiv to %u\n", clkdiv);
1196 ethoc_write(priv, MIIMODER,
1197 (ethoc_read(priv, MIIMODER) & MIIMODER_NOPRE) |
1198 clkdiv);
1199 }
1200
1072 /* register MII bus */ 1201 /* register MII bus */
1073 priv->mdio = mdiobus_alloc(); 1202 priv->mdio = mdiobus_alloc();
1074 if (!priv->mdio) { 1203 if (!priv->mdio) {
@@ -1111,6 +1240,7 @@ static int ethoc_probe(struct platform_device *pdev)
1111 netdev->netdev_ops = &ethoc_netdev_ops; 1240 netdev->netdev_ops = &ethoc_netdev_ops;
1112 netdev->watchdog_timeo = ETHOC_TIMEOUT; 1241 netdev->watchdog_timeo = ETHOC_TIMEOUT;
1113 netdev->features |= 0; 1242 netdev->features |= 0;
1243 netdev->ethtool_ops = &ethoc_ethtool_ops;
1114 1244
1115 /* setup NAPI */ 1245 /* setup NAPI */
1116 netif_napi_add(netdev, &priv->napi, ethoc_poll, 64); 1246 netif_napi_add(netdev, &priv->napi, ethoc_poll, 64);
@@ -1133,6 +1263,8 @@ free_mdio:
1133 kfree(priv->mdio->irq); 1263 kfree(priv->mdio->irq);
1134 mdiobus_free(priv->mdio); 1264 mdiobus_free(priv->mdio);
1135free: 1265free:
1266 if (priv->clk)
1267 clk_disable_unprepare(priv->clk);
1136 free_netdev(netdev); 1268 free_netdev(netdev);
1137out: 1269out:
1138 return ret; 1270 return ret;
@@ -1157,6 +1289,8 @@ static int ethoc_remove(struct platform_device *pdev)
1157 kfree(priv->mdio->irq); 1289 kfree(priv->mdio->irq);
1158 mdiobus_free(priv->mdio); 1290 mdiobus_free(priv->mdio);
1159 } 1291 }
1292 if (priv->clk)
1293 clk_disable_unprepare(priv->clk);
1160 unregister_netdev(netdev); 1294 unregister_netdev(netdev);
1161 free_netdev(netdev); 1295 free_netdev(netdev);
1162 } 1296 }
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index d4782b42401b..03a351300013 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -389,12 +389,6 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
389 netdev_err(ndev, "Tx DMA memory map failed\n"); 389 netdev_err(ndev, "Tx DMA memory map failed\n");
390 return NETDEV_TX_OK; 390 return NETDEV_TX_OK;
391 } 391 }
392 /* Send it on its way. Tell FEC it's ready, interrupt when done,
393 * it's the last BD of the frame, and to put the CRC on the end.
394 */
395 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
396 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
397 bdp->cbd_sc = status;
398 392
399 if (fep->bufdesc_ex) { 393 if (fep->bufdesc_ex) {
400 394
@@ -416,6 +410,13 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
416 } 410 }
417 } 411 }
418 412
413 /* Send it on its way. Tell FEC it's ready, interrupt when done,
414 * it's the last BD of the frame, and to put the CRC on the end.
415 */
416 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
417 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
418 bdp->cbd_sc = status;
419
419 bdp_pre = fec_enet_get_prevdesc(bdp, fep); 420 bdp_pre = fec_enet_get_prevdesc(bdp, fep);
420 if ((id_entry->driver_data & FEC_QUIRK_ERR006358) && 421 if ((id_entry->driver_data & FEC_QUIRK_ERR006358) &&
421 !(bdp_pre->cbd_sc & BD_ENET_TX_READY)) { 422 !(bdp_pre->cbd_sc & BD_ENET_TX_READY)) {
@@ -527,13 +528,6 @@ fec_restart(struct net_device *ndev, int duplex)
527 /* Clear any outstanding interrupt. */ 528 /* Clear any outstanding interrupt. */
528 writel(0xffc00000, fep->hwp + FEC_IEVENT); 529 writel(0xffc00000, fep->hwp + FEC_IEVENT);
529 530
530 /* Setup multicast filter. */
531 set_multicast_list(ndev);
532#ifndef CONFIG_M5272
533 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
534 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
535#endif
536
537 /* Set maximum receive buffer size. */ 531 /* Set maximum receive buffer size. */
538 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE); 532 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
539 533
@@ -654,6 +648,13 @@ fec_restart(struct net_device *ndev, int duplex)
654 648
655 writel(rcntl, fep->hwp + FEC_R_CNTRL); 649 writel(rcntl, fep->hwp + FEC_R_CNTRL);
656 650
651 /* Setup multicast filter. */
652 set_multicast_list(ndev);
653#ifndef CONFIG_M5272
654 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
655 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
656#endif
657
657 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) { 658 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
658 /* enable ENET endian swap */ 659 /* enable ENET endian swap */
659 ecntl |= (1 << 8); 660 ecntl |= (1 << 8);
@@ -1778,8 +1779,6 @@ fec_enet_open(struct net_device *ndev)
1778 struct fec_enet_private *fep = netdev_priv(ndev); 1779 struct fec_enet_private *fep = netdev_priv(ndev);
1779 int ret; 1780 int ret;
1780 1781
1781 napi_enable(&fep->napi);
1782
1783 /* I should reset the ring buffers here, but I don't yet know 1782 /* I should reset the ring buffers here, but I don't yet know
1784 * a simple way to do that. 1783 * a simple way to do that.
1785 */ 1784 */
@@ -1794,6 +1793,8 @@ fec_enet_open(struct net_device *ndev)
1794 fec_enet_free_buffers(ndev); 1793 fec_enet_free_buffers(ndev);
1795 return ret; 1794 return ret;
1796 } 1795 }
1796
1797 napi_enable(&fep->napi);
1797 phy_start(fep->phy_dev); 1798 phy_start(fep->phy_dev);
1798 netif_start_queue(ndev); 1799 netif_start_queue(ndev);
1799 fep->opened = 1; 1800 fep->opened = 1;
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index 4be971590461..1fc8334fc181 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -522,10 +522,21 @@ retry:
522 return rc; 522 return rc;
523} 523}
524 524
525static u64 ibmveth_encode_mac_addr(u8 *mac)
526{
527 int i;
528 u64 encoded = 0;
529
530 for (i = 0; i < ETH_ALEN; i++)
531 encoded = (encoded << 8) | mac[i];
532
533 return encoded;
534}
535
525static int ibmveth_open(struct net_device *netdev) 536static int ibmveth_open(struct net_device *netdev)
526{ 537{
527 struct ibmveth_adapter *adapter = netdev_priv(netdev); 538 struct ibmveth_adapter *adapter = netdev_priv(netdev);
528 u64 mac_address = 0; 539 u64 mac_address;
529 int rxq_entries = 1; 540 int rxq_entries = 1;
530 unsigned long lpar_rc; 541 unsigned long lpar_rc;
531 int rc; 542 int rc;
@@ -579,8 +590,7 @@ static int ibmveth_open(struct net_device *netdev)
579 adapter->rx_queue.num_slots = rxq_entries; 590 adapter->rx_queue.num_slots = rxq_entries;
580 adapter->rx_queue.toggle = 1; 591 adapter->rx_queue.toggle = 1;
581 592
582 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len); 593 mac_address = ibmveth_encode_mac_addr(netdev->dev_addr);
583 mac_address = mac_address >> 16;
584 594
585 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | 595 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
586 adapter->rx_queue.queue_len; 596 adapter->rx_queue.queue_len;
@@ -1183,8 +1193,8 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
1183 /* add the addresses to the filter table */ 1193 /* add the addresses to the filter table */
1184 netdev_for_each_mc_addr(ha, netdev) { 1194 netdev_for_each_mc_addr(ha, netdev) {
1185 /* add the multicast address to the filter table */ 1195 /* add the multicast address to the filter table */
1186 unsigned long mcast_addr = 0; 1196 u64 mcast_addr;
1187 memcpy(((char *)&mcast_addr)+2, ha->addr, ETH_ALEN); 1197 mcast_addr = ibmveth_encode_mac_addr(ha->addr);
1188 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, 1198 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1189 IbmVethMcastAddFilter, 1199 IbmVethMcastAddFilter,
1190 mcast_addr); 1200 mcast_addr);
@@ -1372,9 +1382,6 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1372 1382
1373 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16); 1383 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
1374 1384
1375 adapter->mac_addr = 0;
1376 memcpy(&adapter->mac_addr, mac_addr_p, ETH_ALEN);
1377
1378 netdev->irq = dev->irq; 1385 netdev->irq = dev->irq;
1379 netdev->netdev_ops = &ibmveth_netdev_ops; 1386 netdev->netdev_ops = &ibmveth_netdev_ops;
1380 netdev->ethtool_ops = &netdev_ethtool_ops; 1387 netdev->ethtool_ops = &netdev_ethtool_ops;
@@ -1383,7 +1390,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1383 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; 1390 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1384 netdev->features |= netdev->hw_features; 1391 netdev->features |= netdev->hw_features;
1385 1392
1386 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len); 1393 memcpy(netdev->dev_addr, mac_addr_p, ETH_ALEN);
1387 1394
1388 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { 1395 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
1389 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; 1396 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h
index 451ba7949e15..1f37499d4398 100644
--- a/drivers/net/ethernet/ibm/ibmveth.h
+++ b/drivers/net/ethernet/ibm/ibmveth.h
@@ -138,7 +138,6 @@ struct ibmveth_adapter {
138 struct napi_struct napi; 138 struct napi_struct napi;
139 struct net_device_stats stats; 139 struct net_device_stats stats;
140 unsigned int mcastFilterSize; 140 unsigned int mcastFilterSize;
141 unsigned long mac_addr;
142 void * buffer_list_addr; 141 void * buffer_list_addr;
143 void * filter_list_addr; 142 void * filter_list_addr;
144 dma_addr_t buffer_list_dma; 143 dma_addr_t buffer_list_dma;
diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
index cbaba4442d4b..bf7a01ef9a57 100644
--- a/drivers/net/ethernet/intel/e100.c
+++ b/drivers/net/ethernet/intel/e100.c
@@ -3034,7 +3034,7 @@ static void __e100_shutdown(struct pci_dev *pdev, bool *enable_wake)
3034 *enable_wake = false; 3034 *enable_wake = false;
3035 } 3035 }
3036 3036
3037 pci_disable_device(pdev); 3037 pci_clear_master(pdev);
3038} 3038}
3039 3039
3040static int __e100_power_off(struct pci_dev *pdev, bool wake) 3040static int __e100_power_off(struct pci_dev *pdev, bool wake)
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 6d4ada72dfd0..18076c4178b4 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -6881,7 +6881,7 @@ static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6881} 6881}
6882 6882
6883static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb, 6883static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
6884 void *accel_priv) 6884 void *accel_priv, select_queue_fallback_t fallback)
6885{ 6885{
6886 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv; 6886 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
6887#ifdef IXGBE_FCOE 6887#ifdef IXGBE_FCOE
@@ -6907,7 +6907,7 @@ static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
6907 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) 6907 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
6908 break; 6908 break;
6909 default: 6909 default:
6910 return __netdev_pick_tx(dev, skb); 6910 return fallback(dev, skb);
6911 } 6911 }
6912 6912
6913 f = &adapter->ring_feature[RING_F_FCOE]; 6913 f = &adapter->ring_feature[RING_F_FCOE];
@@ -6920,7 +6920,7 @@ static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
6920 6920
6921 return txq + f->offset; 6921 return txq + f->offset;
6922#else 6922#else
6923 return __netdev_pick_tx(dev, skb); 6923 return fallback(dev, skb);
6924#endif 6924#endif
6925} 6925}
6926 6926
diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
index 8f9266c64c75..fd4b6aecf6ee 100644
--- a/drivers/net/ethernet/lantiq_etop.c
+++ b/drivers/net/ethernet/lantiq_etop.c
@@ -619,7 +619,7 @@ ltq_etop_set_multicast_list(struct net_device *dev)
619 619
620static u16 620static u16
621ltq_etop_select_queue(struct net_device *dev, struct sk_buff *skb, 621ltq_etop_select_queue(struct net_device *dev, struct sk_buff *skb,
622 void *accel_priv) 622 void *accel_priv, select_queue_fallback_t fallback)
623{ 623{
624 /* we are currently only using the first queue */ 624 /* we are currently only using the first queue */
625 return 0; 625 return 0;
diff --git a/drivers/net/ethernet/marvell/Kconfig b/drivers/net/ethernet/marvell/Kconfig
index 6300fd27f2db..68e6a6613e9a 100644
--- a/drivers/net/ethernet/marvell/Kconfig
+++ b/drivers/net/ethernet/marvell/Kconfig
@@ -43,12 +43,12 @@ config MVMDIO
43 This driver is used by the MV643XX_ETH and MVNETA drivers. 43 This driver is used by the MV643XX_ETH and MVNETA drivers.
44 44
45config MVNETA 45config MVNETA
46 tristate "Marvell Armada 370/XP network interface support" 46 tristate "Marvell Armada 370/38x/XP network interface support"
47 depends on MACH_ARMADA_370_XP 47 depends on PLAT_ORION
48 select MVMDIO 48 select MVMDIO
49 ---help--- 49 ---help---
50 This driver supports the network interface units in the 50 This driver supports the network interface units in the
51 Marvell ARMADA XP and ARMADA 370 SoC family. 51 Marvell ARMADA XP, ARMADA 370 and ARMADA 38x SoC family.
52 52
53 Note that this driver is distinct from the mv643xx_eth 53 Note that this driver is distinct from the mv643xx_eth
54 driver, which should be used for the older Marvell SoCs 54 driver, which should be used for the older Marvell SoCs
diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index f418f4f20f94..8d76fca7fde7 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -22,6 +22,7 @@
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <net/ip.h> 23#include <net/ip.h>
24#include <net/ipv6.h> 24#include <net/ipv6.h>
25#include <linux/io.h>
25#include <linux/of.h> 26#include <linux/of.h>
26#include <linux/of_irq.h> 27#include <linux/of_irq.h>
27#include <linux/of_mdio.h> 28#include <linux/of_mdio.h>
@@ -88,8 +89,9 @@
88#define MVNETA_TX_IN_PRGRS BIT(1) 89#define MVNETA_TX_IN_PRGRS BIT(1)
89#define MVNETA_TX_FIFO_EMPTY BIT(8) 90#define MVNETA_TX_FIFO_EMPTY BIT(8)
90#define MVNETA_RX_MIN_FRAME_SIZE 0x247c 91#define MVNETA_RX_MIN_FRAME_SIZE 0x247c
91#define MVNETA_SGMII_SERDES_CFG 0x24A0 92#define MVNETA_SERDES_CFG 0x24A0
92#define MVNETA_SGMII_SERDES_PROTO 0x0cc7 93#define MVNETA_SGMII_SERDES_PROTO 0x0cc7
94#define MVNETA_RGMII_SERDES_PROTO 0x0667
93#define MVNETA_TYPE_PRIO 0x24bc 95#define MVNETA_TYPE_PRIO 0x24bc
94#define MVNETA_FORCE_UNI BIT(21) 96#define MVNETA_FORCE_UNI BIT(21)
95#define MVNETA_TXQ_CMD_1 0x24e4 97#define MVNETA_TXQ_CMD_1 0x24e4
@@ -161,7 +163,7 @@
161#define MVNETA_GMAC_MAX_RX_SIZE_MASK 0x7ffc 163#define MVNETA_GMAC_MAX_RX_SIZE_MASK 0x7ffc
162#define MVNETA_GMAC0_PORT_ENABLE BIT(0) 164#define MVNETA_GMAC0_PORT_ENABLE BIT(0)
163#define MVNETA_GMAC_CTRL_2 0x2c08 165#define MVNETA_GMAC_CTRL_2 0x2c08
164#define MVNETA_GMAC2_PSC_ENABLE BIT(3) 166#define MVNETA_GMAC2_PCS_ENABLE BIT(3)
165#define MVNETA_GMAC2_PORT_RGMII BIT(4) 167#define MVNETA_GMAC2_PORT_RGMII BIT(4)
166#define MVNETA_GMAC2_PORT_RESET BIT(6) 168#define MVNETA_GMAC2_PORT_RESET BIT(6)
167#define MVNETA_GMAC_STATUS 0x2c10 169#define MVNETA_GMAC_STATUS 0x2c10
@@ -710,35 +712,6 @@ static void mvneta_rxq_bm_disable(struct mvneta_port *pp,
710 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val); 712 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
711} 713}
712 714
713
714
715/* Sets the RGMII Enable bit (RGMIIEn) in port MAC control register */
716static void mvneta_gmac_rgmii_set(struct mvneta_port *pp, int enable)
717{
718 u32 val;
719
720 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
721
722 if (enable)
723 val |= MVNETA_GMAC2_PORT_RGMII;
724 else
725 val &= ~MVNETA_GMAC2_PORT_RGMII;
726
727 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
728}
729
730/* Config SGMII port */
731static void mvneta_port_sgmii_config(struct mvneta_port *pp)
732{
733 u32 val;
734
735 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
736 val |= MVNETA_GMAC2_PSC_ENABLE;
737 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
738
739 mvreg_write(pp, MVNETA_SGMII_SERDES_CFG, MVNETA_SGMII_SERDES_PROTO);
740}
741
742/* Start the Ethernet port RX and TX activity */ 715/* Start the Ethernet port RX and TX activity */
743static void mvneta_port_up(struct mvneta_port *pp) 716static void mvneta_port_up(struct mvneta_port *pp)
744{ 717{
@@ -2756,12 +2729,15 @@ static void mvneta_port_power_up(struct mvneta_port *pp, int phy_mode)
2756 mvreg_write(pp, MVNETA_UNIT_INTR_CAUSE, 0); 2729 mvreg_write(pp, MVNETA_UNIT_INTR_CAUSE, 0);
2757 2730
2758 if (phy_mode == PHY_INTERFACE_MODE_SGMII) 2731 if (phy_mode == PHY_INTERFACE_MODE_SGMII)
2759 mvneta_port_sgmii_config(pp); 2732 mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_SGMII_SERDES_PROTO);
2733 else
2734 mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_RGMII_SERDES_PROTO);
2735
2736 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
2760 2737
2761 mvneta_gmac_rgmii_set(pp, 1); 2738 val |= MVNETA_GMAC2_PCS_ENABLE | MVNETA_GMAC2_PORT_RGMII;
2762 2739
2763 /* Cancel Port Reset */ 2740 /* Cancel Port Reset */
2764 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
2765 val &= ~MVNETA_GMAC2_PORT_RESET; 2741 val &= ~MVNETA_GMAC2_PORT_RESET;
2766 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val); 2742 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
2767 2743
@@ -2774,6 +2750,7 @@ static void mvneta_port_power_up(struct mvneta_port *pp, int phy_mode)
2774static int mvneta_probe(struct platform_device *pdev) 2750static int mvneta_probe(struct platform_device *pdev)
2775{ 2751{
2776 const struct mbus_dram_target_info *dram_target_info; 2752 const struct mbus_dram_target_info *dram_target_info;
2753 struct resource *res;
2777 struct device_node *dn = pdev->dev.of_node; 2754 struct device_node *dn = pdev->dev.of_node;
2778 struct device_node *phy_node; 2755 struct device_node *phy_node;
2779 u32 phy_addr; 2756 u32 phy_addr;
@@ -2838,9 +2815,15 @@ static int mvneta_probe(struct platform_device *pdev)
2838 2815
2839 clk_prepare_enable(pp->clk); 2816 clk_prepare_enable(pp->clk);
2840 2817
2841 pp->base = of_iomap(dn, 0); 2818 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2819 if (!res) {
2820 err = -ENODEV;
2821 goto err_clk;
2822 }
2823
2824 pp->base = devm_ioremap_resource(&pdev->dev, res);
2842 if (pp->base == NULL) { 2825 if (pp->base == NULL) {
2843 err = -ENOMEM; 2826 err = PTR_ERR(pp->base);
2844 goto err_clk; 2827 goto err_clk;
2845 } 2828 }
2846 2829
@@ -2848,7 +2831,7 @@ static int mvneta_probe(struct platform_device *pdev)
2848 pp->stats = alloc_percpu(struct mvneta_pcpu_stats); 2831 pp->stats = alloc_percpu(struct mvneta_pcpu_stats);
2849 if (!pp->stats) { 2832 if (!pp->stats) {
2850 err = -ENOMEM; 2833 err = -ENOMEM;
2851 goto err_unmap; 2834 goto err_clk;
2852 } 2835 }
2853 2836
2854 for_each_possible_cpu(cpu) { 2837 for_each_possible_cpu(cpu) {
@@ -2913,8 +2896,6 @@ err_deinit:
2913 mvneta_deinit(pp); 2896 mvneta_deinit(pp);
2914err_free_stats: 2897err_free_stats:
2915 free_percpu(pp->stats); 2898 free_percpu(pp->stats);
2916err_unmap:
2917 iounmap(pp->base);
2918err_clk: 2899err_clk:
2919 clk_disable_unprepare(pp->clk); 2900 clk_disable_unprepare(pp->clk);
2920err_free_irq: 2901err_free_irq:
@@ -2934,7 +2915,6 @@ static int mvneta_remove(struct platform_device *pdev)
2934 mvneta_deinit(pp); 2915 mvneta_deinit(pp);
2935 clk_disable_unprepare(pp->clk); 2916 clk_disable_unprepare(pp->clk);
2936 free_percpu(pp->stats); 2917 free_percpu(pp->stats);
2937 iounmap(pp->base);
2938 irq_dispose_mapping(dev->irq); 2918 irq_dispose_mapping(dev->irq);
2939 free_netdev(dev); 2919 free_netdev(dev);
2940 2920
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index fad45316200a..84a96f70dfb5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -742,6 +742,14 @@ static int mlx4_en_replace_mac(struct mlx4_en_priv *priv, int qpn,
742 err = mlx4_en_uc_steer_add(priv, new_mac, 742 err = mlx4_en_uc_steer_add(priv, new_mac,
743 &qpn, 743 &qpn,
744 &entry->reg_id); 744 &entry->reg_id);
745 if (err)
746 return err;
747 if (priv->tunnel_reg_id) {
748 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
749 priv->tunnel_reg_id = 0;
750 }
751 err = mlx4_en_tunnel_steer_add(priv, new_mac, qpn,
752 &priv->tunnel_reg_id);
745 return err; 753 return err;
746 } 754 }
747 } 755 }
@@ -1792,6 +1800,8 @@ void mlx4_en_stop_port(struct net_device *dev, int detach)
1792 mc_list[5] = priv->port; 1800 mc_list[5] = priv->port;
1793 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, 1801 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
1794 mc_list, MLX4_PROT_ETH, mclist->reg_id); 1802 mc_list, MLX4_PROT_ETH, mclist->reg_id);
1803 if (mclist->tunnel_reg_id)
1804 mlx4_flow_detach(mdev->dev, mclist->tunnel_reg_id);
1795 } 1805 }
1796 mlx4_en_clear_list(dev); 1806 mlx4_en_clear_list(dev);
1797 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { 1807 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index 8e8a7eb43a2c..13457032d15f 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -629,7 +629,7 @@ static void build_inline_wqe(struct mlx4_en_tx_desc *tx_desc, struct sk_buff *sk
629} 629}
630 630
631u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb, 631u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
632 void *accel_priv) 632 void *accel_priv, select_queue_fallback_t fallback)
633{ 633{
634 struct mlx4_en_priv *priv = netdev_priv(dev); 634 struct mlx4_en_priv *priv = netdev_priv(dev);
635 u16 rings_p_up = priv->num_tx_rings_p_up; 635 u16 rings_p_up = priv->num_tx_rings_p_up;
@@ -641,7 +641,7 @@ u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
641 if (vlan_tx_tag_present(skb)) 641 if (vlan_tx_tag_present(skb))
642 up = vlan_tx_tag_get(skb) >> VLAN_PRIO_SHIFT; 642 up = vlan_tx_tag_get(skb) >> VLAN_PRIO_SHIFT;
643 643
644 return __netdev_pick_tx(dev, skb) % rings_p_up + up * rings_p_up; 644 return fallback(dev, skb) % rings_p_up + up * rings_p_up;
645} 645}
646 646
647static void mlx4_bf_copy(void __iomem *dst, unsigned long *src, unsigned bytecnt) 647static void mlx4_bf_copy(void __iomem *dst, unsigned long *src, unsigned bytecnt)
diff --git a/drivers/net/ethernet/mellanox/mlx4/fw.c b/drivers/net/ethernet/mellanox/mlx4/fw.c
index 91b69ff4b4a2..7e2995ecea6f 100644
--- a/drivers/net/ethernet/mellanox/mlx4/fw.c
+++ b/drivers/net/ethernet/mellanox/mlx4/fw.c
@@ -129,13 +129,14 @@ static void dump_dev_cap_flags2(struct mlx4_dev *dev, u64 flags)
129 [0] = "RSS support", 129 [0] = "RSS support",
130 [1] = "RSS Toeplitz Hash Function support", 130 [1] = "RSS Toeplitz Hash Function support",
131 [2] = "RSS XOR Hash Function support", 131 [2] = "RSS XOR Hash Function support",
132 [3] = "Device manage flow steering support", 132 [3] = "Device managed flow steering support",
133 [4] = "Automatic MAC reassignment support", 133 [4] = "Automatic MAC reassignment support",
134 [5] = "Time stamping support", 134 [5] = "Time stamping support",
135 [6] = "VST (control vlan insertion/stripping) support", 135 [6] = "VST (control vlan insertion/stripping) support",
136 [7] = "FSM (MAC anti-spoofing) support", 136 [7] = "FSM (MAC anti-spoofing) support",
137 [8] = "Dynamic QP updates support", 137 [8] = "Dynamic QP updates support",
138 [9] = "TCP/IP offloads/flow-steering for VXLAN support" 138 [9] = "Device managed flow steering IPoIB support",
139 [10] = "TCP/IP offloads/flow-steering for VXLAN support"
139 }; 140 };
140 int i; 141 int i;
141 142
@@ -859,7 +860,7 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
859 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET); 860 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET);
860 861
861 /* For guests, disable vxlan tunneling */ 862 /* For guests, disable vxlan tunneling */
862 MLX4_GET(field, outbox, QUERY_DEV_CAP_VXLAN); 863 MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_VXLAN);
863 field &= 0xf7; 864 field &= 0xf7;
864 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VXLAN); 865 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VXLAN);
865 866
@@ -869,7 +870,7 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
869 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_BF_OFFSET); 870 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_BF_OFFSET);
870 871
871 /* For guests, disable mw type 2 */ 872 /* For guests, disable mw type 2 */
872 MLX4_GET(bmme_flags, outbox, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 873 MLX4_GET(bmme_flags, outbox->buf, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
873 bmme_flags &= ~MLX4_BMME_FLAG_TYPE_2_WIN; 874 bmme_flags &= ~MLX4_BMME_FLAG_TYPE_2_WIN;
874 MLX4_PUT(outbox->buf, bmme_flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 875 MLX4_PUT(outbox->buf, bmme_flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
875 876
@@ -883,7 +884,7 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
883 } 884 }
884 885
885 /* turn off ipoib managed steering for guests */ 886 /* turn off ipoib managed steering for guests */
886 MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET); 887 MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
887 field &= ~0x80; 888 field &= ~0x80;
888 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET); 889 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
889 890
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index d711158b0d4b..d413e60071d4 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -150,6 +150,8 @@ struct mlx4_port_config {
150 struct pci_dev *pdev; 150 struct pci_dev *pdev;
151}; 151};
152 152
153static atomic_t pf_loading = ATOMIC_INIT(0);
154
153int mlx4_check_port_params(struct mlx4_dev *dev, 155int mlx4_check_port_params(struct mlx4_dev *dev,
154 enum mlx4_port_type *port_type) 156 enum mlx4_port_type *port_type)
155{ 157{
@@ -749,7 +751,7 @@ static void mlx4_request_modules(struct mlx4_dev *dev)
749 has_eth_port = true; 751 has_eth_port = true;
750 } 752 }
751 753
752 if (has_ib_port) 754 if (has_ib_port || (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE))
753 request_module_nowait(IB_DRV_NAME); 755 request_module_nowait(IB_DRV_NAME);
754 if (has_eth_port) 756 if (has_eth_port)
755 request_module_nowait(EN_DRV_NAME); 757 request_module_nowait(EN_DRV_NAME);
@@ -1407,6 +1409,11 @@ static int mlx4_init_slave(struct mlx4_dev *dev)
1407 u32 slave_read; 1409 u32 slave_read;
1408 u32 cmd_channel_ver; 1410 u32 cmd_channel_ver;
1409 1411
1412 if (atomic_read(&pf_loading)) {
1413 mlx4_warn(dev, "PF is not ready. Deferring probe\n");
1414 return -EPROBE_DEFER;
1415 }
1416
1410 mutex_lock(&priv->cmd.slave_cmd_mutex); 1417 mutex_lock(&priv->cmd.slave_cmd_mutex);
1411 priv->cmd.max_cmds = 1; 1418 priv->cmd.max_cmds = 1;
1412 mlx4_warn(dev, "Sending reset\n"); 1419 mlx4_warn(dev, "Sending reset\n");
@@ -2319,7 +2326,11 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data)
2319 2326
2320 if (num_vfs) { 2327 if (num_vfs) {
2321 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", num_vfs); 2328 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", num_vfs);
2329
2330 atomic_inc(&pf_loading);
2322 err = pci_enable_sriov(pdev, num_vfs); 2331 err = pci_enable_sriov(pdev, num_vfs);
2332 atomic_dec(&pf_loading);
2333
2323 if (err) { 2334 if (err) {
2324 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n", 2335 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n",
2325 err); 2336 err);
@@ -2670,7 +2681,11 @@ static pci_ers_result_t mlx4_pci_err_detected(struct pci_dev *pdev,
2670 2681
2671static pci_ers_result_t mlx4_pci_slot_reset(struct pci_dev *pdev) 2682static pci_ers_result_t mlx4_pci_slot_reset(struct pci_dev *pdev)
2672{ 2683{
2673 int ret = __mlx4_init_one(pdev, 0); 2684 const struct pci_device_id *id;
2685 int ret;
2686
2687 id = pci_match_id(mlx4_pci_table, pdev);
2688 ret = __mlx4_init_one(pdev, id->driver_data);
2674 2689
2675 return ret ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED; 2690 return ret ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
2676} 2691}
@@ -2684,6 +2699,7 @@ static struct pci_driver mlx4_driver = {
2684 .name = DRV_NAME, 2699 .name = DRV_NAME,
2685 .id_table = mlx4_pci_table, 2700 .id_table = mlx4_pci_table,
2686 .probe = mlx4_init_one, 2701 .probe = mlx4_init_one,
2702 .shutdown = mlx4_remove_one,
2687 .remove = mlx4_remove_one, 2703 .remove = mlx4_remove_one,
2688 .err_handler = &mlx4_err_handler, 2704 .err_handler = &mlx4_err_handler,
2689}; 2705};
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
index 6b65f7795215..7aec6c833973 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
@@ -51,8 +51,8 @@
51 51
52#define DRV_NAME "mlx4_core" 52#define DRV_NAME "mlx4_core"
53#define PFX DRV_NAME ": " 53#define PFX DRV_NAME ": "
54#define DRV_VERSION "1.1" 54#define DRV_VERSION "2.2-1"
55#define DRV_RELDATE "Dec, 2011" 55#define DRV_RELDATE "Feb, 2014"
56 56
57#define MLX4_FS_UDP_UC_EN (1 << 1) 57#define MLX4_FS_UDP_UC_EN (1 << 1)
58#define MLX4_FS_TCP_UC_EN (1 << 2) 58#define MLX4_FS_TCP_UC_EN (1 << 2)
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
index 3af04c3f42ea..b57e8c87a34e 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
@@ -57,8 +57,8 @@
57#include "en_port.h" 57#include "en_port.h"
58 58
59#define DRV_NAME "mlx4_en" 59#define DRV_NAME "mlx4_en"
60#define DRV_VERSION "2.0" 60#define DRV_VERSION "2.2-1"
61#define DRV_RELDATE "Dec 2011" 61#define DRV_RELDATE "Feb 2014"
62 62
63#define MLX4_EN_MSG_LEVEL (NETIF_MSG_LINK | NETIF_MSG_IFDOWN) 63#define MLX4_EN_MSG_LEVEL (NETIF_MSG_LINK | NETIF_MSG_IFDOWN)
64 64
@@ -723,7 +723,7 @@ int mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
723 723
724void mlx4_en_tx_irq(struct mlx4_cq *mcq); 724void mlx4_en_tx_irq(struct mlx4_cq *mcq);
725u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb, 725u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
726 void *accel_priv); 726 void *accel_priv, select_queue_fallback_t fallback);
727netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev); 727netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev);
728 728
729int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv, 729int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Kconfig b/drivers/net/ethernet/mellanox/mlx5/core/Kconfig
index 157fe8df2c3e..8ff57e8e3e91 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/Kconfig
+++ b/drivers/net/ethernet/mellanox/mlx5/core/Kconfig
@@ -4,5 +4,5 @@
4 4
5config MLX5_CORE 5config MLX5_CORE
6 tristate 6 tristate
7 depends on PCI && X86 7 depends on PCI
8 default n 8 default n
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index a064f06e0cb8..23b7e2d35a93 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -46,8 +46,8 @@
46#include "mlx5_core.h" 46#include "mlx5_core.h"
47 47
48#define DRIVER_NAME "mlx5_core" 48#define DRIVER_NAME "mlx5_core"
49#define DRIVER_VERSION "1.0" 49#define DRIVER_VERSION "2.2-1"
50#define DRIVER_RELDATE "June 2013" 50#define DRIVER_RELDATE "Feb 2014"
51 51
52MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); 52MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
53MODULE_DESCRIPTION("Mellanox ConnectX-IB HCA core library"); 53MODULE_DESCRIPTION("Mellanox ConnectX-IB HCA core library");
diff --git a/drivers/net/ethernet/micrel/ks8851.c b/drivers/net/ethernet/micrel/ks8851.c
index 727b546a9eb8..e0c92e0e5e1d 100644
--- a/drivers/net/ethernet/micrel/ks8851.c
+++ b/drivers/net/ethernet/micrel/ks8851.c
@@ -23,6 +23,7 @@
23#include <linux/crc32.h> 23#include <linux/crc32.h>
24#include <linux/mii.h> 24#include <linux/mii.h>
25#include <linux/eeprom_93cx6.h> 25#include <linux/eeprom_93cx6.h>
26#include <linux/regulator/consumer.h>
26 27
27#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
28 29
@@ -83,6 +84,7 @@ union ks8851_tx_hdr {
83 * @rc_rxqcr: Cached copy of KS_RXQCR. 84 * @rc_rxqcr: Cached copy of KS_RXQCR.
84 * @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom 85 * @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom
85 * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM. 86 * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM.
87 * @vdd_reg: Optional regulator supplying the chip
86 * 88 *
87 * The @lock ensures that the chip is protected when certain operations are 89 * The @lock ensures that the chip is protected when certain operations are
88 * in progress. When the read or write packet transfer is in progress, most 90 * in progress. When the read or write packet transfer is in progress, most
@@ -130,6 +132,7 @@ struct ks8851_net {
130 struct spi_transfer spi_xfer2[2]; 132 struct spi_transfer spi_xfer2[2];
131 133
132 struct eeprom_93cx6 eeprom; 134 struct eeprom_93cx6 eeprom;
135 struct regulator *vdd_reg;
133}; 136};
134 137
135static int msg_enable; 138static int msg_enable;
@@ -1414,6 +1417,21 @@ static int ks8851_probe(struct spi_device *spi)
1414 ks->spidev = spi; 1417 ks->spidev = spi;
1415 ks->tx_space = 6144; 1418 ks->tx_space = 6144;
1416 1419
1420 ks->vdd_reg = regulator_get_optional(&spi->dev, "vdd");
1421 if (IS_ERR(ks->vdd_reg)) {
1422 ret = PTR_ERR(ks->vdd_reg);
1423 if (ret == -EPROBE_DEFER)
1424 goto err_reg;
1425 } else {
1426 ret = regulator_enable(ks->vdd_reg);
1427 if (ret) {
1428 dev_err(&spi->dev, "regulator enable fail: %d\n",
1429 ret);
1430 goto err_reg_en;
1431 }
1432 }
1433
1434
1417 mutex_init(&ks->lock); 1435 mutex_init(&ks->lock);
1418 spin_lock_init(&ks->statelock); 1436 spin_lock_init(&ks->statelock);
1419 1437
@@ -1508,8 +1526,14 @@ static int ks8851_probe(struct spi_device *spi)
1508err_netdev: 1526err_netdev:
1509 free_irq(ndev->irq, ks); 1527 free_irq(ndev->irq, ks);
1510 1528
1511err_id:
1512err_irq: 1529err_irq:
1530err_id:
1531 if (!IS_ERR(ks->vdd_reg))
1532 regulator_disable(ks->vdd_reg);
1533err_reg_en:
1534 if (!IS_ERR(ks->vdd_reg))
1535 regulator_put(ks->vdd_reg);
1536err_reg:
1513 free_netdev(ndev); 1537 free_netdev(ndev);
1514 return ret; 1538 return ret;
1515} 1539}
@@ -1523,6 +1547,10 @@ static int ks8851_remove(struct spi_device *spi)
1523 1547
1524 unregister_netdev(priv->netdev); 1548 unregister_netdev(priv->netdev);
1525 free_irq(spi->irq, priv); 1549 free_irq(spi->irq, priv);
1550 if (!IS_ERR(priv->vdd_reg)) {
1551 regulator_disable(priv->vdd_reg);
1552 regulator_put(priv->vdd_reg);
1553 }
1526 free_netdev(priv->netdev); 1554 free_netdev(priv->netdev);
1527 1555
1528 return 0; 1556 return 0;
diff --git a/drivers/net/ethernet/neterion/vxge/vxge-main.c b/drivers/net/ethernet/neterion/vxge/vxge-main.c
index 1ded50ca1600..e46e8698e630 100644
--- a/drivers/net/ethernet/neterion/vxge/vxge-main.c
+++ b/drivers/net/ethernet/neterion/vxge/vxge-main.c
@@ -726,9 +726,6 @@ static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
726 int vpath_idx = 0; 726 int vpath_idx = 0;
727 enum vxge_hw_status status = VXGE_HW_OK; 727 enum vxge_hw_status status = VXGE_HW_OK;
728 struct vxge_vpath *vpath = NULL; 728 struct vxge_vpath *vpath = NULL;
729 struct __vxge_hw_device *hldev;
730
731 hldev = pci_get_drvdata(vdev->pdev);
732 729
733 mac_address = (u8 *)&mac_addr; 730 mac_address = (u8 *)&mac_addr;
734 memcpy(mac_address, mac_header, ETH_ALEN); 731 memcpy(mac_address, mac_header, ETH_ALEN);
@@ -2443,9 +2440,6 @@ static void vxge_rem_msix_isr(struct vxgedev *vdev)
2443 2440
2444static void vxge_rem_isr(struct vxgedev *vdev) 2441static void vxge_rem_isr(struct vxgedev *vdev)
2445{ 2442{
2446 struct __vxge_hw_device *hldev;
2447 hldev = pci_get_drvdata(vdev->pdev);
2448
2449#ifdef CONFIG_PCI_MSI 2443#ifdef CONFIG_PCI_MSI
2450 if (vdev->config.intr_type == MSI_X) { 2444 if (vdev->config.intr_type == MSI_X) {
2451 vxge_rem_msix_isr(vdev); 2445 vxge_rem_msix_isr(vdev);
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
index 4146664d4d6a..27c4f131863b 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
@@ -340,6 +340,7 @@ int qlcnic_83xx_setup_intr(struct qlcnic_adapter *adapter)
340 if (qlcnic_sriov_vf_check(adapter)) 340 if (qlcnic_sriov_vf_check(adapter))
341 return -EINVAL; 341 return -EINVAL;
342 num_msix = 1; 342 num_msix = 1;
343 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
343 adapter->drv_tx_rings = QLCNIC_SINGLE_RING; 344 adapter->drv_tx_rings = QLCNIC_SINGLE_RING;
344 } 345 }
345 } 346 }
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
index 77f1bce432d2..7d4f54912bad 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
@@ -807,7 +807,7 @@ qlcnic_dcb_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, u8 *prio,
807 !type->tc_param_valid) 807 !type->tc_param_valid)
808 return; 808 return;
809 809
810 if (tc < 0 || (tc > QLC_DCB_MAX_TC)) 810 if (tc < 0 || (tc >= QLC_DCB_MAX_TC))
811 return; 811 return;
812 812
813 tc_cfg = &type->tc_cfg[tc]; 813 tc_cfg = &type->tc_cfg[tc];
@@ -843,7 +843,7 @@ static void qlcnic_dcb_get_pg_bwg_cfg_tx(struct net_device *netdev, int pgid,
843 !type->tc_param_valid) 843 !type->tc_param_valid)
844 return; 844 return;
845 845
846 if (pgid < 0 || pgid > QLC_DCB_MAX_PG) 846 if (pgid < 0 || pgid >= QLC_DCB_MAX_PG)
847 return; 847 return;
848 848
849 pgcfg = &type->pg_cfg[pgid]; 849 pgcfg = &type->pg_cfg[pgid];
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
index ba78c7481fa3..1222865cfb73 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
@@ -816,9 +816,10 @@ static int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter)
816 816
817 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) { 817 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) {
818 qlcnic_disable_multi_tx(adapter); 818 qlcnic_disable_multi_tx(adapter);
819 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
819 820
820 err = qlcnic_enable_msi_legacy(adapter); 821 err = qlcnic_enable_msi_legacy(adapter);
821 if (!err) 822 if (err)
822 return err; 823 return err;
823 } 824 }
824 } 825 }
@@ -3863,7 +3864,7 @@ int qlcnic_validate_rings(struct qlcnic_adapter *adapter, __u32 ring_cnt,
3863 strcpy(buf, "Tx"); 3864 strcpy(buf, "Tx");
3864 } 3865 }
3865 3866
3866 if (!qlcnic_use_msi_x && !qlcnic_use_msi) { 3867 if (!QLCNIC_IS_MSI_FAMILY(adapter)) {
3867 netdev_err(netdev, "No RSS/TSS support in INT-x mode\n"); 3868 netdev_err(netdev, "No RSS/TSS support in INT-x mode\n");
3868 return -EINVAL; 3869 return -EINVAL;
3869 } 3870 }
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
index 09acf15c3a56..e5277a632671 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
@@ -13,8 +13,6 @@
13#define QLC_VF_MIN_TX_RATE 100 13#define QLC_VF_MIN_TX_RATE 100
14#define QLC_VF_MAX_TX_RATE 9999 14#define QLC_VF_MAX_TX_RATE 9999
15#define QLC_MAC_OPCODE_MASK 0x7 15#define QLC_MAC_OPCODE_MASK 0x7
16#define QLC_MAC_STAR_ADD 6
17#define QLC_MAC_STAR_DEL 7
18#define QLC_VF_FLOOD_BIT BIT_16 16#define QLC_VF_FLOOD_BIT BIT_16
19#define QLC_FLOOD_MODE 0x5 17#define QLC_FLOOD_MODE 0x5
20 18
@@ -1206,13 +1204,6 @@ static int qlcnic_sriov_validate_cfg_macvlan(struct qlcnic_adapter *adapter,
1206 struct qlcnic_vport *vp = vf->vp; 1204 struct qlcnic_vport *vp = vf->vp;
1207 u8 op, new_op; 1205 u8 op, new_op;
1208 1206
1209 if (((cmd->req.arg[1] & QLC_MAC_OPCODE_MASK) == QLC_MAC_STAR_ADD) ||
1210 ((cmd->req.arg[1] & QLC_MAC_OPCODE_MASK) == QLC_MAC_STAR_DEL)) {
1211 netdev_err(adapter->netdev, "MAC + any VLAN filter not allowed from VF %d\n",
1212 vf->pci_func);
1213 return -EINVAL;
1214 }
1215
1216 if (!(cmd->req.arg[1] & BIT_8)) 1207 if (!(cmd->req.arg[1] & BIT_8))
1217 return -EINVAL; 1208 return -EINVAL;
1218 1209
diff --git a/drivers/net/ethernet/qlogic/qlge/qlge_main.c b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
index ce2cfddbed50..656c65ddadb4 100644
--- a/drivers/net/ethernet/qlogic/qlge/qlge_main.c
+++ b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
@@ -4765,7 +4765,9 @@ static int qlge_probe(struct pci_dev *pdev,
4765 ndev->features = ndev->hw_features; 4765 ndev->features = ndev->hw_features;
4766 ndev->vlan_features = ndev->hw_features; 4766 ndev->vlan_features = ndev->hw_features;
4767 /* vlan gets same features (except vlan filter) */ 4767 /* vlan gets same features (except vlan filter) */
4768 ndev->vlan_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; 4768 ndev->vlan_features &= ~(NETIF_F_HW_VLAN_CTAG_FILTER |
4769 NETIF_F_HW_VLAN_CTAG_TX |
4770 NETIF_F_HW_VLAN_CTAG_RX);
4769 4771
4770 if (test_bit(QL_DMA64, &qdev->flags)) 4772 if (test_bit(QL_DMA64, &qdev->flags))
4771 ndev->features |= NETIF_F_HIGHDMA; 4773 ndev->features |= NETIF_F_HIGHDMA;
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 91a67ae8f17b..3ff7bc3e7a23 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -209,7 +209,7 @@ static const struct {
209 [RTL_GIGA_MAC_VER_16] = 209 [RTL_GIGA_MAC_VER_16] =
210 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), 210 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true),
211 [RTL_GIGA_MAC_VER_17] = 211 [RTL_GIGA_MAC_VER_17] =
212 _R("RTL8168b/8111b", RTL_TD_1, NULL, JUMBO_4K, false), 212 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false),
213 [RTL_GIGA_MAC_VER_18] = 213 [RTL_GIGA_MAC_VER_18] =
214 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), 214 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false),
215 [RTL_GIGA_MAC_VER_19] = 215 [RTL_GIGA_MAC_VER_19] =
@@ -7118,6 +7118,8 @@ rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7118 } 7118 }
7119 7119
7120 mutex_init(&tp->wk.mutex); 7120 mutex_init(&tp->wk.mutex);
7121 u64_stats_init(&tp->rx_stats.syncp);
7122 u64_stats_init(&tp->tx_stats.syncp);
7121 7123
7122 /* Get MAC address */ 7124 /* Get MAC address */
7123 for (i = 0; i < ETH_ALEN; i++) 7125 for (i = 0; i < ETH_ALEN; i++)
diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
index eb75fbd11a01..d7a36829649a 100644
--- a/drivers/net/ethernet/sfc/ptp.c
+++ b/drivers/net/ethernet/sfc/ptp.c
@@ -1668,6 +1668,13 @@ void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev)
1668 struct efx_ptp_data *ptp = efx->ptp_data; 1668 struct efx_ptp_data *ptp = efx->ptp_data;
1669 int code = EFX_QWORD_FIELD(*ev, MCDI_EVENT_CODE); 1669 int code = EFX_QWORD_FIELD(*ev, MCDI_EVENT_CODE);
1670 1670
1671 if (!ptp) {
1672 if (net_ratelimit())
1673 netif_warn(efx, drv, efx->net_dev,
1674 "Received PTP event but PTP not set up\n");
1675 return;
1676 }
1677
1671 if (!ptp->enabled) 1678 if (!ptp->enabled)
1672 return; 1679 return;
1673 1680
diff --git a/drivers/net/ethernet/sfc/tx.c b/drivers/net/ethernet/sfc/tx.c
index c49d1fb16965..75d11fa4eb0a 100644
--- a/drivers/net/ethernet/sfc/tx.c
+++ b/drivers/net/ethernet/sfc/tx.c
@@ -429,7 +429,9 @@ netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
429 } 429 }
430 430
431 /* Transfer ownership of the skb to the final buffer */ 431 /* Transfer ownership of the skb to the final buffer */
432#ifdef EFX_USE_PIO
432finish_packet: 433finish_packet:
434#endif
433 buffer->skb = skb; 435 buffer->skb = skb;
434 buffer->flags = EFX_TX_BUF_SKB | dma_flags; 436 buffer->flags = EFX_TX_BUF_SKB | dma_flags;
435 437
diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index e2f202e3932f..f2d7c702c77f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -37,6 +37,17 @@ config DWMAC_SUNXI
37 stmmac device driver. This driver is used for A20/A31 37 stmmac device driver. This driver is used for A20/A31
38 GMAC ethernet controller. 38 GMAC ethernet controller.
39 39
40config DWMAC_STI
41 bool "STi GMAC support"
42 depends on STMMAC_PLATFORM && ARCH_STI
43 default y
44 ---help---
45 Support for ethernet controller on STi SOCs.
46
47 This selects STi SoC glue layer support for the stmmac
48 device driver. This driver is used on for the STi series
49 SOCs GMAC ethernet controller.
50
40config STMMAC_PCI 51config STMMAC_PCI
41 bool "STMMAC PCI bus support" 52 bool "STMMAC PCI bus support"
42 depends on STMMAC_ETH && PCI 53 depends on STMMAC_ETH && PCI
diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
index ecadecea79b2..dcef28775dad 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -2,6 +2,7 @@ obj-$(CONFIG_STMMAC_ETH) += stmmac.o
2stmmac-$(CONFIG_STMMAC_PLATFORM) += stmmac_platform.o 2stmmac-$(CONFIG_STMMAC_PLATFORM) += stmmac_platform.o
3stmmac-$(CONFIG_STMMAC_PCI) += stmmac_pci.o 3stmmac-$(CONFIG_STMMAC_PCI) += stmmac_pci.o
4stmmac-$(CONFIG_DWMAC_SUNXI) += dwmac-sunxi.o 4stmmac-$(CONFIG_DWMAC_SUNXI) += dwmac-sunxi.o
5stmmac-$(CONFIG_DWMAC_STI) += dwmac-sti.o
5stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o \ 6stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o \
6 chain_mode.o dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \ 7 chain_mode.o dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \
7 dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \ 8 dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \
diff --git a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
index 72d282bf33a5..c553f6b5a913 100644
--- a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
@@ -151,7 +151,7 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
151 sizeof(struct dma_desc))); 151 sizeof(struct dma_desc)));
152} 152}
153 153
154const struct stmmac_chain_mode_ops chain_mode_ops = { 154const struct stmmac_mode_ops chain_mode_ops = {
155 .init = stmmac_init_dma_chain, 155 .init = stmmac_init_dma_chain,
156 .is_jumbo_frm = stmmac_is_jumbo_frm, 156 .is_jumbo_frm = stmmac_is_jumbo_frm,
157 .jumbo_frm = stmmac_jumbo_frm, 157 .jumbo_frm = stmmac_jumbo_frm,
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index 7834a3993946..74610f3aca9e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -419,20 +419,13 @@ struct mii_regs {
419 unsigned int data; /* MII Data */ 419 unsigned int data; /* MII Data */
420}; 420};
421 421
422struct stmmac_ring_mode_ops { 422struct stmmac_mode_ops {
423 unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
424 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum);
425 void (*refill_desc3) (void *priv, struct dma_desc *p);
426 void (*init_desc3) (struct dma_desc *p);
427 void (*clean_desc3) (void *priv, struct dma_desc *p);
428 int (*set_16kib_bfsize) (int mtu);
429};
430
431struct stmmac_chain_mode_ops {
432 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size, 423 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
433 unsigned int extend_desc); 424 unsigned int extend_desc);
434 unsigned int (*is_jumbo_frm) (int len, int ehn_desc); 425 unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
435 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum); 426 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum);
427 int (*set_16kib_bfsize)(int mtu);
428 void (*init_desc3)(struct dma_desc *p);
436 void (*refill_desc3) (void *priv, struct dma_desc *p); 429 void (*refill_desc3) (void *priv, struct dma_desc *p);
437 void (*clean_desc3) (void *priv, struct dma_desc *p); 430 void (*clean_desc3) (void *priv, struct dma_desc *p);
438}; 431};
@@ -441,8 +434,7 @@ struct mac_device_info {
441 const struct stmmac_ops *mac; 434 const struct stmmac_ops *mac;
442 const struct stmmac_desc_ops *desc; 435 const struct stmmac_desc_ops *desc;
443 const struct stmmac_dma_ops *dma; 436 const struct stmmac_dma_ops *dma;
444 const struct stmmac_ring_mode_ops *ring; 437 const struct stmmac_mode_ops *mode;
445 const struct stmmac_chain_mode_ops *chain;
446 const struct stmmac_hwtimestamp *ptp; 438 const struct stmmac_hwtimestamp *ptp;
447 struct mii_regs mii; /* MII register Addresses */ 439 struct mii_regs mii; /* MII register Addresses */
448 struct mac_link link; 440 struct mac_link link;
@@ -460,7 +452,7 @@ void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
460void stmmac_set_mac(void __iomem *ioaddr, bool enable); 452void stmmac_set_mac(void __iomem *ioaddr, bool enable);
461 453
462void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr); 454void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr);
463extern const struct stmmac_ring_mode_ops ring_mode_ops; 455extern const struct stmmac_mode_ops ring_mode_ops;
464extern const struct stmmac_chain_mode_ops chain_mode_ops; 456extern const struct stmmac_mode_ops chain_mode_ops;
465 457
466#endif /* __COMMON_H__ */ 458#endif /* __COMMON_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
new file mode 100644
index 000000000000..552bbc17863c
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
@@ -0,0 +1,330 @@
1/**
2 * dwmac-sti.c - STMicroelectronics DWMAC Specific Glue layer
3 *
4 * Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
5 * Author: Srinivas Kandagatla <srinivas.kandagatla@st.com>
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/kernel.h>
15#include <linux/slab.h>
16#include <linux/platform_device.h>
17#include <linux/stmmac.h>
18#include <linux/phy.h>
19#include <linux/mfd/syscon.h>
20#include <linux/regmap.h>
21#include <linux/clk.h>
22#include <linux/of.h>
23#include <linux/of_net.h>
24
25/**
26 * STi GMAC glue logic.
27 * --------------------
28 *
29 * _
30 * | \
31 * --------|0 \ ETH_SEL_INTERNAL_NOTEXT_PHYCLK
32 * phyclk | |___________________________________________
33 * | | | (phyclk-in)
34 * --------|1 / |
35 * int-clk |_ / |
36 * | _
37 * | | \
38 * |_______|1 \ ETH_SEL_TX_RETIME_CLK
39 * | |___________________________
40 * | | (tx-retime-clk)
41 * _______|0 /
42 * | |_ /
43 * _ |
44 * | \ |
45 * --------|0 \ |
46 * clk_125 | |__|
47 * | | ETH_SEL_TXCLK_NOT_CLK125
48 * --------|1 /
49 * txclk |_ /
50 *
51 *
52 * ETH_SEL_INTERNAL_NOTEXT_PHYCLK is valid only for RMII where PHY can
53 * generate 50MHz clock or MAC can generate it.
54 * This bit is configured by "st,ext-phyclk" property.
55 *
56 * ETH_SEL_TXCLK_NOT_CLK125 is only valid for gigabit modes, where the 125Mhz
57 * clock either comes from clk-125 pin or txclk pin. This configuration is
58 * totally driven by the board wiring. This bit is configured by
59 * "st,tx-retime-src" property.
60 *
61 * TXCLK configuration is different for different phy interface modes
62 * and changes according to link speed in modes like RGMII.
63 *
64 * Below table summarizes the clock requirement and clock sources for
65 * supported phy interface modes with link speeds.
66 * ________________________________________________
67 *| PHY_MODE | 1000 Mbit Link | 100 Mbit Link |
68 * ------------------------------------------------
69 *| MII | n/a | 25Mhz |
70 *| | | txclk |
71 * ------------------------------------------------
72 *| GMII | 125Mhz | 25Mhz |
73 *| | clk-125/txclk | txclk |
74 * ------------------------------------------------
75 *| RGMII | 125Mhz | 25Mhz |
76 *| | clk-125/txclk | clkgen |
77 * ------------------------------------------------
78 *| RMII | n/a | 25Mhz |
79 *| | |clkgen/phyclk-in |
80 * ------------------------------------------------
81 *
82 * TX lines are always retimed with a clk, which can vary depending
83 * on the board configuration. Below is the table of these bits
84 * in eth configuration register depending on source of retime clk.
85 *
86 *---------------------------------------------------------------
87 * src | tx_rt_clk | int_not_ext_phyclk | txclk_n_clk125|
88 *---------------------------------------------------------------
89 * txclk | 0 | n/a | 1 |
90 *---------------------------------------------------------------
91 * ck_125| 0 | n/a | 0 |
92 *---------------------------------------------------------------
93 * phyclk| 1 | 0 | n/a |
94 *---------------------------------------------------------------
95 * clkgen| 1 | 1 | n/a |
96 *---------------------------------------------------------------
97 */
98
99 /* Register definition */
100
101 /* 3 bits [8:6]
102 * [6:6] ETH_SEL_TXCLK_NOT_CLK125
103 * [7:7] ETH_SEL_INTERNAL_NOTEXT_PHYCLK
104 * [8:8] ETH_SEL_TX_RETIME_CLK
105 *
106 */
107
108#define TX_RETIME_SRC_MASK GENMASK(8, 6)
109#define ETH_SEL_TX_RETIME_CLK BIT(8)
110#define ETH_SEL_INTERNAL_NOTEXT_PHYCLK BIT(7)
111#define ETH_SEL_TXCLK_NOT_CLK125 BIT(6)
112
113#define ENMII_MASK GENMASK(5, 5)
114#define ENMII BIT(5)
115
116/**
117 * 3 bits [4:2]
118 * 000-GMII/MII
119 * 001-RGMII
120 * 010-SGMII
121 * 100-RMII
122*/
123#define MII_PHY_SEL_MASK GENMASK(4, 2)
124#define ETH_PHY_SEL_RMII BIT(4)
125#define ETH_PHY_SEL_SGMII BIT(3)
126#define ETH_PHY_SEL_RGMII BIT(2)
127#define ETH_PHY_SEL_GMII 0x0
128#define ETH_PHY_SEL_MII 0x0
129
130#define IS_PHY_IF_MODE_RGMII(iface) (iface == PHY_INTERFACE_MODE_RGMII || \
131 iface == PHY_INTERFACE_MODE_RGMII_ID || \
132 iface == PHY_INTERFACE_MODE_RGMII_RXID || \
133 iface == PHY_INTERFACE_MODE_RGMII_TXID)
134
135#define IS_PHY_IF_MODE_GBIT(iface) (IS_PHY_IF_MODE_RGMII(iface) || \
136 iface == PHY_INTERFACE_MODE_GMII)
137
138struct sti_dwmac {
139 int interface;
140 bool ext_phyclk;
141 bool is_tx_retime_src_clk_125;
142 struct clk *clk;
143 int reg;
144 struct device *dev;
145 struct regmap *regmap;
146};
147
148static u32 phy_intf_sels[] = {
149 [PHY_INTERFACE_MODE_MII] = ETH_PHY_SEL_MII,
150 [PHY_INTERFACE_MODE_GMII] = ETH_PHY_SEL_GMII,
151 [PHY_INTERFACE_MODE_RGMII] = ETH_PHY_SEL_RGMII,
152 [PHY_INTERFACE_MODE_RGMII_ID] = ETH_PHY_SEL_RGMII,
153 [PHY_INTERFACE_MODE_SGMII] = ETH_PHY_SEL_SGMII,
154 [PHY_INTERFACE_MODE_RMII] = ETH_PHY_SEL_RMII,
155};
156
157enum {
158 TX_RETIME_SRC_NA = 0,
159 TX_RETIME_SRC_TXCLK = 1,
160 TX_RETIME_SRC_CLK_125,
161 TX_RETIME_SRC_PHYCLK,
162 TX_RETIME_SRC_CLKGEN,
163};
164
165static const char *const tx_retime_srcs[] = {
166 [TX_RETIME_SRC_NA] = "",
167 [TX_RETIME_SRC_TXCLK] = "txclk",
168 [TX_RETIME_SRC_CLK_125] = "clk_125",
169 [TX_RETIME_SRC_PHYCLK] = "phyclk",
170 [TX_RETIME_SRC_CLKGEN] = "clkgen",
171};
172
173static u32 tx_retime_val[] = {
174 [TX_RETIME_SRC_TXCLK] = ETH_SEL_TXCLK_NOT_CLK125,
175 [TX_RETIME_SRC_CLK_125] = 0x0,
176 [TX_RETIME_SRC_PHYCLK] = ETH_SEL_TX_RETIME_CLK,
177 [TX_RETIME_SRC_CLKGEN] = ETH_SEL_TX_RETIME_CLK |
178 ETH_SEL_INTERNAL_NOTEXT_PHYCLK,
179};
180
181static void setup_retime_src(struct sti_dwmac *dwmac, u32 spd)
182{
183 u32 src = 0, freq = 0;
184
185 if (spd == SPEED_100) {
186 if (dwmac->interface == PHY_INTERFACE_MODE_MII ||
187 dwmac->interface == PHY_INTERFACE_MODE_GMII) {
188 src = TX_RETIME_SRC_TXCLK;
189 } else if (dwmac->interface == PHY_INTERFACE_MODE_RMII) {
190 if (dwmac->ext_phyclk) {
191 src = TX_RETIME_SRC_PHYCLK;
192 } else {
193 src = TX_RETIME_SRC_CLKGEN;
194 freq = 50000000;
195 }
196
197 } else if (IS_PHY_IF_MODE_RGMII(dwmac->interface)) {
198 src = TX_RETIME_SRC_CLKGEN;
199 freq = 25000000;
200 }
201
202 if (src == TX_RETIME_SRC_CLKGEN && dwmac->clk)
203 clk_set_rate(dwmac->clk, freq);
204
205 } else if (spd == SPEED_1000) {
206 if (dwmac->is_tx_retime_src_clk_125)
207 src = TX_RETIME_SRC_CLK_125;
208 else
209 src = TX_RETIME_SRC_TXCLK;
210 }
211
212 regmap_update_bits(dwmac->regmap, dwmac->reg,
213 TX_RETIME_SRC_MASK, tx_retime_val[src]);
214}
215
216static void sti_dwmac_exit(struct platform_device *pdev, void *priv)
217{
218 struct sti_dwmac *dwmac = priv;
219
220 if (dwmac->clk)
221 clk_disable_unprepare(dwmac->clk);
222}
223
224static void sti_fix_mac_speed(void *priv, unsigned int spd)
225{
226 struct sti_dwmac *dwmac = priv;
227
228 setup_retime_src(dwmac, spd);
229
230 return;
231}
232
233static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
234 struct platform_device *pdev)
235{
236 struct resource *res;
237 struct device *dev = &pdev->dev;
238 struct device_node *np = dev->of_node;
239 struct regmap *regmap;
240 int err;
241
242 if (!np)
243 return -EINVAL;
244
245 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sti-ethconf");
246 if (!res)
247 return -ENODATA;
248
249 regmap = syscon_regmap_lookup_by_phandle(np, "st,syscon");
250 if (IS_ERR(regmap))
251 return PTR_ERR(regmap);
252
253 dwmac->dev = dev;
254 dwmac->interface = of_get_phy_mode(np);
255 dwmac->regmap = regmap;
256 dwmac->reg = res->start;
257 dwmac->ext_phyclk = of_property_read_bool(np, "st,ext-phyclk");
258 dwmac->is_tx_retime_src_clk_125 = false;
259
260 if (IS_PHY_IF_MODE_GBIT(dwmac->interface)) {
261 const char *rs;
262
263 err = of_property_read_string(np, "st,tx-retime-src", &rs);
264 if (err < 0) {
265 dev_err(dev, "st,tx-retime-src not specified\n");
266 return err;
267 }
268
269 if (!strcasecmp(rs, "clk_125"))
270 dwmac->is_tx_retime_src_clk_125 = true;
271 }
272
273 dwmac->clk = devm_clk_get(dev, "sti-ethclk");
274
275 if (IS_ERR(dwmac->clk))
276 dwmac->clk = NULL;
277
278 return 0;
279}
280
281static int sti_dwmac_init(struct platform_device *pdev, void *priv)
282{
283 struct sti_dwmac *dwmac = priv;
284 struct regmap *regmap = dwmac->regmap;
285 int iface = dwmac->interface;
286 u32 reg = dwmac->reg;
287 u32 val, spd;
288
289 if (dwmac->clk)
290 clk_prepare_enable(dwmac->clk);
291
292 regmap_update_bits(regmap, reg, MII_PHY_SEL_MASK, phy_intf_sels[iface]);
293
294 val = (iface == PHY_INTERFACE_MODE_REVMII) ? 0 : ENMII;
295 regmap_update_bits(regmap, reg, ENMII_MASK, val);
296
297 if (IS_PHY_IF_MODE_GBIT(iface))
298 spd = SPEED_1000;
299 else
300 spd = SPEED_100;
301
302 setup_retime_src(dwmac, spd);
303
304 return 0;
305}
306
307static void *sti_dwmac_setup(struct platform_device *pdev)
308{
309 struct sti_dwmac *dwmac;
310 int ret;
311
312 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
313 if (!dwmac)
314 return ERR_PTR(-ENOMEM);
315
316 ret = sti_dwmac_parse_data(dwmac, pdev);
317 if (ret) {
318 dev_err(&pdev->dev, "Unable to parse OF data\n");
319 return ERR_PTR(ret);
320 }
321
322 return dwmac;
323}
324
325const struct stmmac_of_data sti_gmac_data = {
326 .fix_mac_speed = sti_fix_mac_speed,
327 .setup = sti_dwmac_setup,
328 .init = sti_dwmac_init,
329 .exit = sti_dwmac_exit,
330};
diff --git a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
index a96c7c2f5f3f..650a4be6bce5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
@@ -100,10 +100,9 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
100{ 100{
101 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr; 101 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
102 102
103 if (unlikely(priv->plat->has_gmac)) 103 /* Fill DES3 in case of RING mode */
104 /* Fill DES3 in case of RING mode */ 104 if (priv->dma_buf_sz >= BUF_SIZE_8KiB)
105 if (priv->dma_buf_sz >= BUF_SIZE_8KiB) 105 p->des3 = p->des2 + BUF_SIZE_8KiB;
106 p->des3 = p->des2 + BUF_SIZE_8KiB;
107} 106}
108 107
109/* In ring mode we need to fill the desc3 because it is used as buffer */ 108/* In ring mode we need to fill the desc3 because it is used as buffer */
@@ -126,7 +125,7 @@ static int stmmac_set_16kib_bfsize(int mtu)
126 return ret; 125 return ret;
127} 126}
128 127
129const struct stmmac_ring_mode_ops ring_mode_ops = { 128const struct stmmac_mode_ops ring_mode_ops = {
130 .is_jumbo_frm = stmmac_is_jumbo_frm, 129 .is_jumbo_frm = stmmac_is_jumbo_frm,
131 .jumbo_frm = stmmac_jumbo_frm, 130 .jumbo_frm = stmmac_jumbo_frm,
132 .refill_desc3 = stmmac_refill_desc3, 131 .refill_desc3 = stmmac_refill_desc3,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index d9af26ed58ee..f9e60d7918c4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -133,6 +133,9 @@ bool stmmac_eee_init(struct stmmac_priv *priv);
133#ifdef CONFIG_DWMAC_SUNXI 133#ifdef CONFIG_DWMAC_SUNXI
134extern const struct stmmac_of_data sun7i_gmac_data; 134extern const struct stmmac_of_data sun7i_gmac_data;
135#endif 135#endif
136#ifdef CONFIG_DWMAC_STI
137extern const struct stmmac_of_data sti_gmac_data;
138#endif
136extern struct platform_driver stmmac_pltfr_driver; 139extern struct platform_driver stmmac_pltfr_driver;
137static inline int stmmac_register_platform(void) 140static inline int stmmac_register_platform(void)
138{ 141{
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a2e7d2c96e36..8543e1cfd55e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -92,8 +92,8 @@ static int tc = TC_DEFAULT;
92module_param(tc, int, S_IRUGO | S_IWUSR); 92module_param(tc, int, S_IRUGO | S_IWUSR);
93MODULE_PARM_DESC(tc, "DMA threshold control value"); 93MODULE_PARM_DESC(tc, "DMA threshold control value");
94 94
95#define DMA_BUFFER_SIZE BUF_SIZE_4KiB 95#define DEFAULT_BUFSIZE 1536
96static int buf_sz = DMA_BUFFER_SIZE; 96static int buf_sz = DEFAULT_BUFSIZE;
97module_param(buf_sz, int, S_IRUGO | S_IWUSR); 97module_param(buf_sz, int, S_IRUGO | S_IWUSR);
98MODULE_PARM_DESC(buf_sz, "DMA buffer size"); 98MODULE_PARM_DESC(buf_sz, "DMA buffer size");
99 99
@@ -136,8 +136,8 @@ static void stmmac_verify_args(void)
136 dma_rxsize = DMA_RX_SIZE; 136 dma_rxsize = DMA_RX_SIZE;
137 if (unlikely(dma_txsize < 0)) 137 if (unlikely(dma_txsize < 0))
138 dma_txsize = DMA_TX_SIZE; 138 dma_txsize = DMA_TX_SIZE;
139 if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB))) 139 if (unlikely((buf_sz < DEFAULT_BUFSIZE) || (buf_sz > BUF_SIZE_16KiB)))
140 buf_sz = DMA_BUFFER_SIZE; 140 buf_sz = DEFAULT_BUFSIZE;
141 if (unlikely(flow_ctrl > 1)) 141 if (unlikely(flow_ctrl > 1))
142 flow_ctrl = FLOW_AUTO; 142 flow_ctrl = FLOW_AUTO;
143 else if (likely(flow_ctrl < 0)) 143 else if (likely(flow_ctrl < 0))
@@ -286,10 +286,25 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
286 286
287 /* MAC core supports the EEE feature. */ 287 /* MAC core supports the EEE feature. */
288 if (priv->dma_cap.eee) { 288 if (priv->dma_cap.eee) {
289 int tx_lpi_timer = priv->tx_lpi_timer;
290
289 /* Check if the PHY supports EEE */ 291 /* Check if the PHY supports EEE */
290 if (phy_init_eee(priv->phydev, 1)) 292 if (phy_init_eee(priv->phydev, 1)) {
293 /* To manage at run-time if the EEE cannot be supported
294 * anymore (for example because the lp caps have been
295 * changed).
296 * In that case the driver disable own timers.
297 */
298 if (priv->eee_active) {
299 pr_debug("stmmac: disable EEE\n");
300 del_timer_sync(&priv->eee_ctrl_timer);
301 priv->hw->mac->set_eee_timer(priv->ioaddr, 0,
302 tx_lpi_timer);
303 }
304 priv->eee_active = 0;
291 goto out; 305 goto out;
292 306 }
307 /* Activate the EEE and start timers */
293 if (!priv->eee_active) { 308 if (!priv->eee_active) {
294 priv->eee_active = 1; 309 priv->eee_active = 1;
295 init_timer(&priv->eee_ctrl_timer); 310 init_timer(&priv->eee_ctrl_timer);
@@ -300,13 +315,13 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
300 315
301 priv->hw->mac->set_eee_timer(priv->ioaddr, 316 priv->hw->mac->set_eee_timer(priv->ioaddr,
302 STMMAC_DEFAULT_LIT_LS, 317 STMMAC_DEFAULT_LIT_LS,
303 priv->tx_lpi_timer); 318 tx_lpi_timer);
304 } else 319 } else
305 /* Set HW EEE according to the speed */ 320 /* Set HW EEE according to the speed */
306 priv->hw->mac->set_eee_pls(priv->ioaddr, 321 priv->hw->mac->set_eee_pls(priv->ioaddr,
307 priv->phydev->link); 322 priv->phydev->link);
308 323
309 pr_info("stmmac: Energy-Efficient Ethernet initialized\n"); 324 pr_debug("stmmac: Energy-Efficient Ethernet initialized\n");
310 325
311 ret = true; 326 ret = true;
312 } 327 }
@@ -886,10 +901,10 @@ static int stmmac_set_bfsize(int mtu, int bufsize)
886 ret = BUF_SIZE_8KiB; 901 ret = BUF_SIZE_8KiB;
887 else if (mtu >= BUF_SIZE_2KiB) 902 else if (mtu >= BUF_SIZE_2KiB)
888 ret = BUF_SIZE_4KiB; 903 ret = BUF_SIZE_4KiB;
889 else if (mtu >= DMA_BUFFER_SIZE) 904 else if (mtu > DEFAULT_BUFSIZE)
890 ret = BUF_SIZE_2KiB; 905 ret = BUF_SIZE_2KiB;
891 else 906 else
892 ret = DMA_BUFFER_SIZE; 907 ret = DEFAULT_BUFSIZE;
893 908
894 return ret; 909 return ret;
895} 910}
@@ -951,9 +966,9 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
951 966
952 p->des2 = priv->rx_skbuff_dma[i]; 967 p->des2 = priv->rx_skbuff_dma[i];
953 968
954 if ((priv->mode == STMMAC_RING_MODE) && 969 if ((priv->hw->mode->init_desc3) &&
955 (priv->dma_buf_sz == BUF_SIZE_16KiB)) 970 (priv->dma_buf_sz == BUF_SIZE_16KiB))
956 priv->hw->ring->init_desc3(p); 971 priv->hw->mode->init_desc3(p);
957 972
958 return 0; 973 return 0;
959} 974}
@@ -984,11 +999,8 @@ static int init_dma_desc_rings(struct net_device *dev)
984 unsigned int bfsize = 0; 999 unsigned int bfsize = 0;
985 int ret = -ENOMEM; 1000 int ret = -ENOMEM;
986 1001
987 /* Set the max buffer size according to the DESC mode 1002 if (priv->hw->mode->set_16kib_bfsize)
988 * and the MTU. Note that RING mode allows 16KiB bsize. 1003 bfsize = priv->hw->mode->set_16kib_bfsize(dev->mtu);
989 */
990 if (priv->mode == STMMAC_RING_MODE)
991 bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu);
992 1004
993 if (bfsize < BUF_SIZE_16KiB) 1005 if (bfsize < BUF_SIZE_16KiB)
994 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz); 1006 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
@@ -1029,15 +1041,15 @@ static int init_dma_desc_rings(struct net_device *dev)
1029 /* Setup the chained descriptor addresses */ 1041 /* Setup the chained descriptor addresses */
1030 if (priv->mode == STMMAC_CHAIN_MODE) { 1042 if (priv->mode == STMMAC_CHAIN_MODE) {
1031 if (priv->extend_desc) { 1043 if (priv->extend_desc) {
1032 priv->hw->chain->init(priv->dma_erx, priv->dma_rx_phy, 1044 priv->hw->mode->init(priv->dma_erx, priv->dma_rx_phy,
1033 rxsize, 1); 1045 rxsize, 1);
1034 priv->hw->chain->init(priv->dma_etx, priv->dma_tx_phy, 1046 priv->hw->mode->init(priv->dma_etx, priv->dma_tx_phy,
1035 txsize, 1); 1047 txsize, 1);
1036 } else { 1048 } else {
1037 priv->hw->chain->init(priv->dma_rx, priv->dma_rx_phy, 1049 priv->hw->mode->init(priv->dma_rx, priv->dma_rx_phy,
1038 rxsize, 0); 1050 rxsize, 0);
1039 priv->hw->chain->init(priv->dma_tx, priv->dma_tx_phy, 1051 priv->hw->mode->init(priv->dma_tx, priv->dma_tx_phy,
1040 txsize, 0); 1052 txsize, 0);
1041 } 1053 }
1042 } 1054 }
1043 1055
@@ -1288,7 +1300,7 @@ static void stmmac_tx_clean(struct stmmac_priv *priv)
1288 DMA_TO_DEVICE); 1300 DMA_TO_DEVICE);
1289 priv->tx_skbuff_dma[entry] = 0; 1301 priv->tx_skbuff_dma[entry] = 0;
1290 } 1302 }
1291 priv->hw->ring->clean_desc3(priv, p); 1303 priv->hw->mode->clean_desc3(priv, p);
1292 1304
1293 if (likely(skb != NULL)) { 1305 if (likely(skb != NULL)) {
1294 dev_kfree_skb(skb); 1306 dev_kfree_skb(skb);
@@ -1705,7 +1717,7 @@ static int stmmac_open(struct net_device *dev)
1705 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize); 1717 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
1706 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz); 1718 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
1707 1719
1708 alloc_dma_desc_resources(priv); 1720 ret = alloc_dma_desc_resources(priv);
1709 if (ret < 0) { 1721 if (ret < 0) {
1710 pr_err("%s: DMA descriptors allocation failed\n", __func__); 1722 pr_err("%s: DMA descriptors allocation failed\n", __func__);
1711 goto dma_desc_error; 1723 goto dma_desc_error;
@@ -1844,6 +1856,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1844 int nfrags = skb_shinfo(skb)->nr_frags; 1856 int nfrags = skb_shinfo(skb)->nr_frags;
1845 struct dma_desc *desc, *first; 1857 struct dma_desc *desc, *first;
1846 unsigned int nopaged_len = skb_headlen(skb); 1858 unsigned int nopaged_len = skb_headlen(skb);
1859 unsigned int enh_desc = priv->plat->enh_desc;
1847 1860
1848 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) { 1861 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1849 if (!netif_queue_stopped(dev)) { 1862 if (!netif_queue_stopped(dev)) {
@@ -1871,27 +1884,19 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1871 first = desc; 1884 first = desc;
1872 1885
1873 /* To program the descriptors according to the size of the frame */ 1886 /* To program the descriptors according to the size of the frame */
1874 if (priv->mode == STMMAC_RING_MODE) { 1887 if (enh_desc)
1875 is_jumbo = priv->hw->ring->is_jumbo_frm(skb->len, 1888 is_jumbo = priv->hw->mode->is_jumbo_frm(skb->len, enh_desc);
1876 priv->plat->enh_desc); 1889
1877 if (unlikely(is_jumbo))
1878 entry = priv->hw->ring->jumbo_frm(priv, skb,
1879 csum_insertion);
1880 } else {
1881 is_jumbo = priv->hw->chain->is_jumbo_frm(skb->len,
1882 priv->plat->enh_desc);
1883 if (unlikely(is_jumbo))
1884 entry = priv->hw->chain->jumbo_frm(priv, skb,
1885 csum_insertion);
1886 }
1887 if (likely(!is_jumbo)) { 1890 if (likely(!is_jumbo)) {
1888 desc->des2 = dma_map_single(priv->device, skb->data, 1891 desc->des2 = dma_map_single(priv->device, skb->data,
1889 nopaged_len, DMA_TO_DEVICE); 1892 nopaged_len, DMA_TO_DEVICE);
1890 priv->tx_skbuff_dma[entry] = desc->des2; 1893 priv->tx_skbuff_dma[entry] = desc->des2;
1891 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, 1894 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
1892 csum_insertion, priv->mode); 1895 csum_insertion, priv->mode);
1893 } else 1896 } else {
1894 desc = first; 1897 desc = first;
1898 entry = priv->hw->mode->jumbo_frm(priv, skb, csum_insertion);
1899 }
1895 1900
1896 for (i = 0; i < nfrags; i++) { 1901 for (i = 0; i < nfrags; i++) {
1897 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 1902 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
@@ -2029,7 +2034,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
2029 2034
2030 p->des2 = priv->rx_skbuff_dma[entry]; 2035 p->des2 = priv->rx_skbuff_dma[entry];
2031 2036
2032 priv->hw->ring->refill_desc3(priv, p); 2037 priv->hw->mode->refill_desc3(priv, p);
2033 2038
2034 if (netif_msg_rx_status(priv)) 2039 if (netif_msg_rx_status(priv))
2035 pr_debug("\trefill entry #%d\n", entry); 2040 pr_debug("\trefill entry #%d\n", entry);
@@ -2633,11 +2638,11 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
2633 2638
2634 /* To use the chained or ring mode */ 2639 /* To use the chained or ring mode */
2635 if (chain_mode) { 2640 if (chain_mode) {
2636 priv->hw->chain = &chain_mode_ops; 2641 priv->hw->mode = &chain_mode_ops;
2637 pr_info(" Chain mode enabled\n"); 2642 pr_info(" Chain mode enabled\n");
2638 priv->mode = STMMAC_CHAIN_MODE; 2643 priv->mode = STMMAC_CHAIN_MODE;
2639 } else { 2644 } else {
2640 priv->hw->ring = &ring_mode_ops; 2645 priv->hw->mode = &ring_mode_ops;
2641 pr_info(" Ring mode enabled\n"); 2646 pr_info(" Ring mode enabled\n");
2642 priv->mode = STMMAC_RING_MODE; 2647 priv->mode = STMMAC_RING_MODE;
2643 } 2648 }
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 5884a7d2063b..8fb32a80f1c1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -33,6 +33,11 @@ static const struct of_device_id stmmac_dt_ids[] = {
33#ifdef CONFIG_DWMAC_SUNXI 33#ifdef CONFIG_DWMAC_SUNXI
34 { .compatible = "allwinner,sun7i-a20-gmac", .data = &sun7i_gmac_data}, 34 { .compatible = "allwinner,sun7i-a20-gmac", .data = &sun7i_gmac_data},
35#endif 35#endif
36#ifdef CONFIG_DWMAC_STI
37 { .compatible = "st,stih415-dwmac", .data = &sti_gmac_data},
38 { .compatible = "st,stih416-dwmac", .data = &sti_gmac_data},
39 { .compatible = "st,stid127-dwmac", .data = &sti_gmac_data},
40#endif
36 /* SoC specific glue layers should come before generic bindings */ 41 /* SoC specific glue layers should come before generic bindings */
37 { .compatible = "st,spear600-gmac"}, 42 { .compatible = "st,spear600-gmac"},
38 { .compatible = "snps,dwmac-3.610"}, 43 { .compatible = "snps,dwmac-3.610"},
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index bde63e3af96f..7d6d8ec676c8 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -554,7 +554,7 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
554 * common for both the interface as the interface shares 554 * common for both the interface as the interface shares
555 * the same hardware resource. 555 * the same hardware resource.
556 */ 556 */
557 for (i = 0; i <= priv->data.slaves; i++) 557 for (i = 0; i < priv->data.slaves; i++)
558 if (priv->slaves[i].ndev->flags & IFF_PROMISC) 558 if (priv->slaves[i].ndev->flags & IFF_PROMISC)
559 flag = true; 559 flag = true;
560 560
@@ -578,7 +578,7 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
578 unsigned long timeout = jiffies + HZ; 578 unsigned long timeout = jiffies + HZ;
579 579
580 /* Disable Learn for all ports */ 580 /* Disable Learn for all ports */
581 for (i = 0; i <= priv->data.slaves; i++) { 581 for (i = 0; i < priv->data.slaves; i++) {
582 cpsw_ale_control_set(ale, i, 582 cpsw_ale_control_set(ale, i,
583 ALE_PORT_NOLEARN, 1); 583 ALE_PORT_NOLEARN, 1);
584 cpsw_ale_control_set(ale, i, 584 cpsw_ale_control_set(ale, i,
@@ -606,7 +606,7 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
606 cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 0); 606 cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 0);
607 607
608 /* Enable Learn for all ports */ 608 /* Enable Learn for all ports */
609 for (i = 0; i <= priv->data.slaves; i++) { 609 for (i = 0; i < priv->data.slaves; i++) {
610 cpsw_ale_control_set(ale, i, 610 cpsw_ale_control_set(ale, i,
611 ALE_PORT_NOLEARN, 0); 611 ALE_PORT_NOLEARN, 0);
612 cpsw_ale_control_set(ale, i, 612 cpsw_ale_control_set(ale, i,
@@ -1164,11 +1164,17 @@ static void cpsw_init_host_port(struct cpsw_priv *priv)
1164 1164
1165static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_priv *priv) 1165static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_priv *priv)
1166{ 1166{
1167 u32 slave_port;
1168
1169 slave_port = cpsw_get_slave_port(priv, slave->slave_num);
1170
1167 if (!slave->phy) 1171 if (!slave->phy)
1168 return; 1172 return;
1169 phy_stop(slave->phy); 1173 phy_stop(slave->phy);
1170 phy_disconnect(slave->phy); 1174 phy_disconnect(slave->phy);
1171 slave->phy = NULL; 1175 slave->phy = NULL;
1176 cpsw_ale_control_set(priv->ale, slave_port,
1177 ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
1172} 1178}
1173 1179
1174static int cpsw_ndo_open(struct net_device *ndev) 1180static int cpsw_ndo_open(struct net_device *ndev)
@@ -1878,14 +1884,29 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
1878 mdio_node = of_find_node_by_phandle(be32_to_cpup(parp)); 1884 mdio_node = of_find_node_by_phandle(be32_to_cpup(parp));
1879 phyid = be32_to_cpup(parp+1); 1885 phyid = be32_to_cpup(parp+1);
1880 mdio = of_find_device_by_node(mdio_node); 1886 mdio = of_find_device_by_node(mdio_node);
1881 snprintf(slave_data->phy_id, sizeof(slave_data->phy_id), 1887
1882 PHY_ID_FMT, mdio->name, phyid); 1888 if (strncmp(mdio->name, "gpio", 4) == 0) {
1889 /* GPIO bitbang MDIO driver attached */
1890 struct mii_bus *bus = dev_get_drvdata(&mdio->dev);
1891
1892 snprintf(slave_data->phy_id, sizeof(slave_data->phy_id),
1893 PHY_ID_FMT, bus->id, phyid);
1894 } else {
1895 /* davinci MDIO driver attached */
1896 snprintf(slave_data->phy_id, sizeof(slave_data->phy_id),
1897 PHY_ID_FMT, mdio->name, phyid);
1898 }
1883 1899
1884 mac_addr = of_get_mac_address(slave_node); 1900 mac_addr = of_get_mac_address(slave_node);
1885 if (mac_addr) 1901 if (mac_addr)
1886 memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN); 1902 memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN);
1887 1903
1888 slave_data->phy_if = of_get_phy_mode(slave_node); 1904 slave_data->phy_if = of_get_phy_mode(slave_node);
1905 if (slave_data->phy_if < 0) {
1906 pr_err("Missing or malformed slave[%d] phy-mode property\n",
1907 i);
1908 return slave_data->phy_if;
1909 }
1889 1910
1890 if (data->dual_emac) { 1911 if (data->dual_emac) {
1891 if (of_property_read_u32(slave_node, "dual_emac_res_vlan", 1912 if (of_property_read_u32(slave_node, "dual_emac_res_vlan",
@@ -2208,10 +2229,6 @@ static int cpsw_probe(struct platform_device *pdev)
2208 goto clean_ale_ret; 2229 goto clean_ale_ret;
2209 } 2230 }
2210 2231
2211 if (cpts_register(&pdev->dev, priv->cpts,
2212 data->cpts_clock_mult, data->cpts_clock_shift))
2213 dev_err(priv->dev, "error registering cpts device\n");
2214
2215 cpsw_notice(priv, probe, "initialized device (regs %pa, irq %d)\n", 2232 cpsw_notice(priv, probe, "initialized device (regs %pa, irq %d)\n",
2216 &ss_res->start, ndev->irq); 2233 &ss_res->start, ndev->irq);
2217 2234
diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c
index 364d0c7952c0..88ef27067bf2 100644
--- a/drivers/net/ethernet/ti/davinci_cpdma.c
+++ b/drivers/net/ethernet/ti/davinci_cpdma.c
@@ -355,7 +355,7 @@ int cpdma_ctlr_stop(struct cpdma_ctlr *ctlr)
355 int i; 355 int i;
356 356
357 spin_lock_irqsave(&ctlr->lock, flags); 357 spin_lock_irqsave(&ctlr->lock, flags);
358 if (ctlr->state != CPDMA_STATE_ACTIVE) { 358 if (ctlr->state == CPDMA_STATE_TEARDOWN) {
359 spin_unlock_irqrestore(&ctlr->lock, flags); 359 spin_unlock_irqrestore(&ctlr->lock, flags);
360 return -EINVAL; 360 return -EINVAL;
361 } 361 }
@@ -891,7 +891,7 @@ int cpdma_chan_stop(struct cpdma_chan *chan)
891 unsigned timeout; 891 unsigned timeout;
892 892
893 spin_lock_irqsave(&chan->lock, flags); 893 spin_lock_irqsave(&chan->lock, flags);
894 if (chan->state != CPDMA_STATE_ACTIVE) { 894 if (chan->state == CPDMA_STATE_TEARDOWN) {
895 spin_unlock_irqrestore(&chan->lock, flags); 895 spin_unlock_irqrestore(&chan->lock, flags);
896 return -EINVAL; 896 return -EINVAL;
897 } 897 }
diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index cd9b164a0434..8f0e69ce07ca 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1532,9 +1532,9 @@ static int emac_dev_open(struct net_device *ndev)
1532 struct device *emac_dev = &ndev->dev; 1532 struct device *emac_dev = &ndev->dev;
1533 u32 cnt; 1533 u32 cnt;
1534 struct resource *res; 1534 struct resource *res;
1535 int ret; 1535 int q, m, ret;
1536 int res_num = 0, irq_num = 0;
1536 int i = 0; 1537 int i = 0;
1537 int k = 0;
1538 struct emac_priv *priv = netdev_priv(ndev); 1538 struct emac_priv *priv = netdev_priv(ndev);
1539 1539
1540 pm_runtime_get(&priv->pdev->dev); 1540 pm_runtime_get(&priv->pdev->dev);
@@ -1564,15 +1564,24 @@ static int emac_dev_open(struct net_device *ndev)
1564 } 1564 }
1565 1565
1566 /* Request IRQ */ 1566 /* Request IRQ */
1567 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ,
1568 res_num))) {
1569 for (irq_num = res->start; irq_num <= res->end; irq_num++) {
1570 dev_err(emac_dev, "Request IRQ %d\n", irq_num);
1571 if (request_irq(irq_num, emac_irq, 0, ndev->name,
1572 ndev)) {
1573 dev_err(emac_dev,
1574 "DaVinci EMAC: request_irq() failed\n");
1575 ret = -EBUSY;
1567 1576
1568 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, k))) {
1569 for (i = res->start; i <= res->end; i++) {
1570 if (devm_request_irq(&priv->pdev->dev, i, emac_irq,
1571 0, ndev->name, ndev))
1572 goto rollback; 1577 goto rollback;
1578 }
1573 } 1579 }
1574 k++; 1580 res_num++;
1575 } 1581 }
1582 /* prepare counters for rollback in case of an error */
1583 res_num--;
1584 irq_num--;
1576 1585
1577 /* Start/Enable EMAC hardware */ 1586 /* Start/Enable EMAC hardware */
1578 emac_hw_enable(priv); 1587 emac_hw_enable(priv);
@@ -1639,11 +1648,23 @@ static int emac_dev_open(struct net_device *ndev)
1639 1648
1640 return 0; 1649 return 0;
1641 1650
1642rollback:
1643
1644 dev_err(emac_dev, "DaVinci EMAC: devm_request_irq() failed");
1645 ret = -EBUSY;
1646err: 1651err:
1652 emac_int_disable(priv);
1653 napi_disable(&priv->napi);
1654
1655rollback:
1656 for (q = res_num; q >= 0; q--) {
1657 res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, q);
1658 /* at the first iteration, irq_num is already set to the
1659 * right value
1660 */
1661 if (q != res_num)
1662 irq_num = res->end;
1663
1664 for (m = irq_num; m >= res->start; m--)
1665 free_irq(m, ndev);
1666 }
1667 cpdma_ctlr_stop(priv->dma);
1647 pm_runtime_put(&priv->pdev->dev); 1668 pm_runtime_put(&priv->pdev->dev);
1648 return ret; 1669 return ret;
1649} 1670}
@@ -1659,6 +1680,9 @@ err:
1659 */ 1680 */
1660static int emac_dev_stop(struct net_device *ndev) 1681static int emac_dev_stop(struct net_device *ndev)
1661{ 1682{
1683 struct resource *res;
1684 int i = 0;
1685 int irq_num;
1662 struct emac_priv *priv = netdev_priv(ndev); 1686 struct emac_priv *priv = netdev_priv(ndev);
1663 struct device *emac_dev = &ndev->dev; 1687 struct device *emac_dev = &ndev->dev;
1664 1688
@@ -1674,6 +1698,13 @@ static int emac_dev_stop(struct net_device *ndev)
1674 if (priv->phydev) 1698 if (priv->phydev)
1675 phy_disconnect(priv->phydev); 1699 phy_disconnect(priv->phydev);
1676 1700
1701 /* Free IRQ */
1702 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, i))) {
1703 for (irq_num = res->start; irq_num <= res->end; irq_num++)
1704 free_irq(irq_num, priv->ndev);
1705 i++;
1706 }
1707
1677 if (netif_msg_drv(priv)) 1708 if (netif_msg_drv(priv))
1678 dev_notice(emac_dev, "DaVinci EMAC: %s stopped\n", ndev->name); 1709 dev_notice(emac_dev, "DaVinci EMAC: %s stopped\n", ndev->name);
1679 1710
diff --git a/drivers/net/ethernet/tile/tilegx.c b/drivers/net/ethernet/tile/tilegx.c
index 023237a65720..17503da9f7a5 100644
--- a/drivers/net/ethernet/tile/tilegx.c
+++ b/drivers/net/ethernet/tile/tilegx.c
@@ -2071,7 +2071,7 @@ static int tile_net_tx(struct sk_buff *skb, struct net_device *dev)
2071 2071
2072/* Return subqueue id on this core (one per core). */ 2072/* Return subqueue id on this core (one per core). */
2073static u16 tile_net_select_queue(struct net_device *dev, struct sk_buff *skb, 2073static u16 tile_net_select_queue(struct net_device *dev, struct sk_buff *skb,
2074 void *accel_priv) 2074 void *accel_priv, select_queue_fallback_t fallback)
2075{ 2075{
2076 return smp_processor_id(); 2076 return smp_processor_id();
2077} 2077}
diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index ef312bc6b865..6ac20a6738f4 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -923,7 +923,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
923 if (rc) { 923 if (rc) {
924 dev_err(&pdev->dev, 924 dev_err(&pdev->dev,
925 "32-bit PCI DMA addresses not supported by the card!?\n"); 925 "32-bit PCI DMA addresses not supported by the card!?\n");
926 goto err_out; 926 goto err_out_pci_disable;
927 } 927 }
928 928
929 /* sanity check */ 929 /* sanity check */
@@ -931,7 +931,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
931 (pci_resource_len(pdev, 1) < io_size)) { 931 (pci_resource_len(pdev, 1) < io_size)) {
932 rc = -EIO; 932 rc = -EIO;
933 dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n"); 933 dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n");
934 goto err_out; 934 goto err_out_pci_disable;
935 } 935 }
936 936
937 pioaddr = pci_resource_start(pdev, 0); 937 pioaddr = pci_resource_start(pdev, 0);
@@ -942,7 +942,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
942 dev = alloc_etherdev(sizeof(struct rhine_private)); 942 dev = alloc_etherdev(sizeof(struct rhine_private));
943 if (!dev) { 943 if (!dev) {
944 rc = -ENOMEM; 944 rc = -ENOMEM;
945 goto err_out; 945 goto err_out_pci_disable;
946 } 946 }
947 SET_NETDEV_DEV(dev, &pdev->dev); 947 SET_NETDEV_DEV(dev, &pdev->dev);
948 948
@@ -1084,6 +1084,8 @@ err_out_free_res:
1084 pci_release_regions(pdev); 1084 pci_release_regions(pdev);
1085err_out_free_netdev: 1085err_out_free_netdev:
1086 free_netdev(dev); 1086 free_netdev(dev);
1087err_out_pci_disable:
1088 pci_disable_device(pdev);
1087err_out: 1089err_out:
1088 return rc; 1090 return rc;
1089} 1091}
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
index 1ec65feebb9e..4bfdf8c7ada0 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
@@ -26,6 +26,7 @@
26#include <linux/netdevice.h> 26#include <linux/netdevice.h>
27#include <linux/of_mdio.h> 27#include <linux/of_mdio.h>
28#include <linux/of_platform.h> 28#include <linux/of_platform.h>
29#include <linux/of_irq.h>
29#include <linux/of_address.h> 30#include <linux/of_address.h>
30#include <linux/skbuff.h> 31#include <linux/skbuff.h>
31#include <linux/spinlock.h> 32#include <linux/spinlock.h>
@@ -600,7 +601,8 @@ static void axienet_start_xmit_done(struct net_device *ndev)
600 size += status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK; 601 size += status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK;
601 packets++; 602 packets++;
602 603
603 lp->tx_bd_ci = ++lp->tx_bd_ci % TX_BD_NUM; 604 ++lp->tx_bd_ci;
605 lp->tx_bd_ci %= TX_BD_NUM;
604 cur_p = &lp->tx_bd_v[lp->tx_bd_ci]; 606 cur_p = &lp->tx_bd_v[lp->tx_bd_ci];
605 status = cur_p->status; 607 status = cur_p->status;
606 } 608 }
@@ -686,7 +688,8 @@ static int axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
686 skb_headlen(skb), DMA_TO_DEVICE); 688 skb_headlen(skb), DMA_TO_DEVICE);
687 689
688 for (ii = 0; ii < num_frag; ii++) { 690 for (ii = 0; ii < num_frag; ii++) {
689 lp->tx_bd_tail = ++lp->tx_bd_tail % TX_BD_NUM; 691 ++lp->tx_bd_tail;
692 lp->tx_bd_tail %= TX_BD_NUM;
690 cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; 693 cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
691 frag = &skb_shinfo(skb)->frags[ii]; 694 frag = &skb_shinfo(skb)->frags[ii];
692 cur_p->phys = dma_map_single(ndev->dev.parent, 695 cur_p->phys = dma_map_single(ndev->dev.parent,
@@ -702,7 +705,8 @@ static int axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
702 tail_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail; 705 tail_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail;
703 /* Start the transfer */ 706 /* Start the transfer */
704 axienet_dma_out32(lp, XAXIDMA_TX_TDESC_OFFSET, tail_p); 707 axienet_dma_out32(lp, XAXIDMA_TX_TDESC_OFFSET, tail_p);
705 lp->tx_bd_tail = ++lp->tx_bd_tail % TX_BD_NUM; 708 ++lp->tx_bd_tail;
709 lp->tx_bd_tail %= TX_BD_NUM;
706 710
707 return NETDEV_TX_OK; 711 return NETDEV_TX_OK;
708} 712}
@@ -774,7 +778,8 @@ static void axienet_recv(struct net_device *ndev)
774 cur_p->status = 0; 778 cur_p->status = 0;
775 cur_p->sw_id_offset = (u32) new_skb; 779 cur_p->sw_id_offset = (u32) new_skb;
776 780
777 lp->rx_bd_ci = ++lp->rx_bd_ci % RX_BD_NUM; 781 ++lp->rx_bd_ci;
782 lp->rx_bd_ci %= RX_BD_NUM;
778 cur_p = &lp->rx_bd_v[lp->rx_bd_ci]; 783 cur_p = &lp->rx_bd_v[lp->rx_bd_ci];
779 } 784 }
780 785
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 7756118c2f0a..d6fce9750b95 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -88,8 +88,12 @@ static int netvsc_open(struct net_device *net)
88{ 88{
89 struct net_device_context *net_device_ctx = netdev_priv(net); 89 struct net_device_context *net_device_ctx = netdev_priv(net);
90 struct hv_device *device_obj = net_device_ctx->device_ctx; 90 struct hv_device *device_obj = net_device_ctx->device_ctx;
91 struct netvsc_device *nvdev;
92 struct rndis_device *rdev;
91 int ret = 0; 93 int ret = 0;
92 94
95 netif_carrier_off(net);
96
93 /* Open up the device */ 97 /* Open up the device */
94 ret = rndis_filter_open(device_obj); 98 ret = rndis_filter_open(device_obj);
95 if (ret != 0) { 99 if (ret != 0) {
@@ -99,6 +103,11 @@ static int netvsc_open(struct net_device *net)
99 103
100 netif_start_queue(net); 104 netif_start_queue(net);
101 105
106 nvdev = hv_get_drvdata(device_obj);
107 rdev = nvdev->extension;
108 if (!rdev->link_state)
109 netif_carrier_on(net);
110
102 return ret; 111 return ret;
103} 112}
104 113
@@ -229,23 +238,24 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,
229 struct net_device *net; 238 struct net_device *net;
230 struct net_device_context *ndev_ctx; 239 struct net_device_context *ndev_ctx;
231 struct netvsc_device *net_device; 240 struct netvsc_device *net_device;
241 struct rndis_device *rdev;
232 242
233 net_device = hv_get_drvdata(device_obj); 243 net_device = hv_get_drvdata(device_obj);
244 rdev = net_device->extension;
245
246 rdev->link_state = status != 1;
247
234 net = net_device->ndev; 248 net = net_device->ndev;
235 249
236 if (!net) { 250 if (!net || net->reg_state != NETREG_REGISTERED)
237 netdev_err(net, "got link status but net device "
238 "not initialized yet\n");
239 return; 251 return;
240 }
241 252
253 ndev_ctx = netdev_priv(net);
242 if (status == 1) { 254 if (status == 1) {
243 netif_carrier_on(net);
244 ndev_ctx = netdev_priv(net);
245 schedule_delayed_work(&ndev_ctx->dwork, 0); 255 schedule_delayed_work(&ndev_ctx->dwork, 0);
246 schedule_delayed_work(&ndev_ctx->dwork, msecs_to_jiffies(20)); 256 schedule_delayed_work(&ndev_ctx->dwork, msecs_to_jiffies(20));
247 } else { 257 } else {
248 netif_carrier_off(net); 258 schedule_delayed_work(&ndev_ctx->dwork, 0);
249 } 259 }
250} 260}
251 261
@@ -388,17 +398,35 @@ static const struct net_device_ops device_ops = {
388 * current context when receiving RNDIS_STATUS_MEDIA_CONNECT event. So, add 398 * current context when receiving RNDIS_STATUS_MEDIA_CONNECT event. So, add
389 * another netif_notify_peers() into a delayed work, otherwise GARP packet 399 * another netif_notify_peers() into a delayed work, otherwise GARP packet
390 * will not be sent after quick migration, and cause network disconnection. 400 * will not be sent after quick migration, and cause network disconnection.
401 * Also, we update the carrier status here.
391 */ 402 */
392static void netvsc_send_garp(struct work_struct *w) 403static void netvsc_link_change(struct work_struct *w)
393{ 404{
394 struct net_device_context *ndev_ctx; 405 struct net_device_context *ndev_ctx;
395 struct net_device *net; 406 struct net_device *net;
396 struct netvsc_device *net_device; 407 struct netvsc_device *net_device;
408 struct rndis_device *rdev;
409 bool notify;
410
411 rtnl_lock();
397 412
398 ndev_ctx = container_of(w, struct net_device_context, dwork.work); 413 ndev_ctx = container_of(w, struct net_device_context, dwork.work);
399 net_device = hv_get_drvdata(ndev_ctx->device_ctx); 414 net_device = hv_get_drvdata(ndev_ctx->device_ctx);
415 rdev = net_device->extension;
400 net = net_device->ndev; 416 net = net_device->ndev;
401 netdev_notify_peers(net); 417
418 if (rdev->link_state) {
419 netif_carrier_off(net);
420 notify = false;
421 } else {
422 netif_carrier_on(net);
423 notify = true;
424 }
425
426 rtnl_unlock();
427
428 if (notify)
429 netdev_notify_peers(net);
402} 430}
403 431
404 432
@@ -414,13 +442,12 @@ static int netvsc_probe(struct hv_device *dev,
414 if (!net) 442 if (!net)
415 return -ENOMEM; 443 return -ENOMEM;
416 444
417 /* Set initial state */
418 netif_carrier_off(net); 445 netif_carrier_off(net);
419 446
420 net_device_ctx = netdev_priv(net); 447 net_device_ctx = netdev_priv(net);
421 net_device_ctx->device_ctx = dev; 448 net_device_ctx->device_ctx = dev;
422 hv_set_drvdata(dev, net); 449 hv_set_drvdata(dev, net);
423 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_send_garp); 450 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change);
424 INIT_WORK(&net_device_ctx->work, do_set_multicast); 451 INIT_WORK(&net_device_ctx->work, do_set_multicast);
425 452
426 net->netdev_ops = &device_ops; 453 net->netdev_ops = &device_ops;
@@ -443,13 +470,13 @@ static int netvsc_probe(struct hv_device *dev,
443 } 470 }
444 memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN); 471 memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
445 472
446 netif_carrier_on(net);
447
448 ret = register_netdev(net); 473 ret = register_netdev(net);
449 if (ret != 0) { 474 if (ret != 0) {
450 pr_err("Unable to register netdev.\n"); 475 pr_err("Unable to register netdev.\n");
451 rndis_filter_device_remove(dev); 476 rndis_filter_device_remove(dev);
452 free_netdev(net); 477 free_netdev(net);
478 } else {
479 schedule_delayed_work(&net_device_ctx->dwork, 0);
453 } 480 }
454 481
455 return ret; 482 return ret;
diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 1084e5de3ceb..b54fd257652b 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -243,6 +243,22 @@ static int rndis_filter_send_request(struct rndis_device *dev,
243 return ret; 243 return ret;
244} 244}
245 245
246static void rndis_set_link_state(struct rndis_device *rdev,
247 struct rndis_request *request)
248{
249 u32 link_status;
250 struct rndis_query_complete *query_complete;
251
252 query_complete = &request->response_msg.msg.query_complete;
253
254 if (query_complete->status == RNDIS_STATUS_SUCCESS &&
255 query_complete->info_buflen == sizeof(u32)) {
256 memcpy(&link_status, (void *)((unsigned long)query_complete +
257 query_complete->info_buf_offset), sizeof(u32));
258 rdev->link_state = link_status != 0;
259 }
260}
261
246static void rndis_filter_receive_response(struct rndis_device *dev, 262static void rndis_filter_receive_response(struct rndis_device *dev,
247 struct rndis_message *resp) 263 struct rndis_message *resp)
248{ 264{
@@ -272,6 +288,10 @@ static void rndis_filter_receive_response(struct rndis_device *dev,
272 sizeof(struct rndis_message) + RNDIS_EXT_LEN) { 288 sizeof(struct rndis_message) + RNDIS_EXT_LEN) {
273 memcpy(&request->response_msg, resp, 289 memcpy(&request->response_msg, resp,
274 resp->msg_len); 290 resp->msg_len);
291 if (request->request_msg.ndis_msg_type ==
292 RNDIS_MSG_QUERY && request->request_msg.msg.
293 query_req.oid == RNDIS_OID_GEN_MEDIA_CONNECT_STATUS)
294 rndis_set_link_state(dev, request);
275 } else { 295 } else {
276 netdev_err(ndev, 296 netdev_err(ndev,
277 "rndis response buffer overflow " 297 "rndis response buffer overflow "
@@ -620,7 +640,6 @@ static int rndis_filter_query_device_link_status(struct rndis_device *dev)
620 ret = rndis_filter_query_device(dev, 640 ret = rndis_filter_query_device(dev,
621 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, 641 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
622 &link_status, &size); 642 &link_status, &size);
623 dev->link_state = (link_status != 0) ? true : false;
624 643
625 return ret; 644 return ret;
626} 645}
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index ab31544bc254..a30258aad139 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -546,12 +546,12 @@ at86rf230_xmit(struct ieee802154_dev *dev, struct sk_buff *skb)
546 int rc; 546 int rc;
547 unsigned long flags; 547 unsigned long flags;
548 548
549 spin_lock(&lp->lock); 549 spin_lock_irqsave(&lp->lock, flags);
550 if (lp->irq_busy) { 550 if (lp->irq_busy) {
551 spin_unlock(&lp->lock); 551 spin_unlock_irqrestore(&lp->lock, flags);
552 return -EBUSY; 552 return -EBUSY;
553 } 553 }
554 spin_unlock(&lp->lock); 554 spin_unlock_irqrestore(&lp->lock, flags);
555 555
556 might_sleep(); 556 might_sleep();
557 557
@@ -725,10 +725,11 @@ static void at86rf230_irqwork_level(struct work_struct *work)
725static irqreturn_t at86rf230_isr(int irq, void *data) 725static irqreturn_t at86rf230_isr(int irq, void *data)
726{ 726{
727 struct at86rf230_local *lp = data; 727 struct at86rf230_local *lp = data;
728 unsigned long flags;
728 729
729 spin_lock(&lp->lock); 730 spin_lock_irqsave(&lp->lock, flags);
730 lp->irq_busy = 1; 731 lp->irq_busy = 1;
731 spin_unlock(&lp->lock); 732 spin_unlock_irqrestore(&lp->lock, flags);
732 733
733 schedule_work(&lp->irqwork); 734 schedule_work(&lp->irqwork);
734 735
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index c14d39bf32d0..d7b2e947184b 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -180,7 +180,8 @@ static void ifb_setup(struct net_device *dev)
180 dev->tx_queue_len = TX_Q_LIMIT; 180 dev->tx_queue_len = TX_Q_LIMIT;
181 181
182 dev->features |= IFB_FEATURES; 182 dev->features |= IFB_FEATURES;
183 dev->vlan_features |= IFB_FEATURES; 183 dev->vlan_features |= IFB_FEATURES & ~(NETIF_F_HW_VLAN_CTAG_TX |
184 NETIF_F_HW_VLAN_STAG_TX);
184 185
185 dev->flags |= IFF_NOARP; 186 dev->flags |= IFF_NOARP;
186 dev->flags &= ~IFF_MULTICAST; 187 dev->flags &= ~IFF_MULTICAST;
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index 2dc82f1d2e70..3da44d5d9149 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -210,13 +210,6 @@ config KINGSUN_DONGLE
210 To compile it as a module, choose M here: the module will be called 210 To compile it as a module, choose M here: the module will be called
211 kingsun-sir. 211 kingsun-sir.
212 212
213config EP7211_DONGLE
214 tristate "Cirrus Logic clps711x I/R support"
215 depends on IRTTY_SIR && ARCH_CLPS711X && IRDA
216 help
217 Say Y here if you want to build support for the Cirrus logic
218 EP7211 chipset's infrared module.
219
220config KSDAZZLE_DONGLE 213config KSDAZZLE_DONGLE
221 tristate "KingSun Dazzle IrDA-USB dongle" 214 tristate "KingSun Dazzle IrDA-USB dongle"
222 depends on IRDA && USB 215 depends on IRDA && USB
diff --git a/drivers/net/irda/Makefile b/drivers/net/irda/Makefile
index dfc64537f62f..be8ab5b9a4a2 100644
--- a/drivers/net/irda/Makefile
+++ b/drivers/net/irda/Makefile
@@ -35,7 +35,6 @@ obj-$(CONFIG_MCP2120_DONGLE) += mcp2120-sir.o
35obj-$(CONFIG_ACT200L_DONGLE) += act200l-sir.o 35obj-$(CONFIG_ACT200L_DONGLE) += act200l-sir.o
36obj-$(CONFIG_MA600_DONGLE) += ma600-sir.o 36obj-$(CONFIG_MA600_DONGLE) += ma600-sir.o
37obj-$(CONFIG_TOIM3232_DONGLE) += toim3232-sir.o 37obj-$(CONFIG_TOIM3232_DONGLE) += toim3232-sir.o
38obj-$(CONFIG_EP7211_DONGLE) += ep7211-sir.o
39obj-$(CONFIG_KINGSUN_DONGLE) += kingsun-sir.o 38obj-$(CONFIG_KINGSUN_DONGLE) += kingsun-sir.o
40obj-$(CONFIG_KSDAZZLE_DONGLE) += ksdazzle-sir.o 39obj-$(CONFIG_KSDAZZLE_DONGLE) += ksdazzle-sir.o
41obj-$(CONFIG_KS959_DONGLE) += ks959-sir.o 40obj-$(CONFIG_KS959_DONGLE) += ks959-sir.o
diff --git a/drivers/net/irda/ep7211-sir.c b/drivers/net/irda/ep7211-sir.c
deleted file mode 100644
index 5fe1f4dd3369..000000000000
--- a/drivers/net/irda/ep7211-sir.c
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 * IR port driver for the Cirrus Logic CLPS711X processors
3 *
4 * Copyright 2001, Blue Mug Inc. All rights reserved.
5 * Copyright 2007, Samuel Ortiz <samuel@sortiz.org>
6 */
7
8#include <linux/module.h>
9#include <linux/platform_device.h>
10
11#include <mach/hardware.h>
12
13#include "sir-dev.h"
14
15static int clps711x_dongle_open(struct sir_dev *dev)
16{
17 unsigned int syscon;
18
19 /* Turn on the SIR encoder. */
20 syscon = clps_readl(SYSCON1);
21 syscon |= SYSCON1_SIREN;
22 clps_writel(syscon, SYSCON1);
23
24 return 0;
25}
26
27static int clps711x_dongle_close(struct sir_dev *dev)
28{
29 unsigned int syscon;
30
31 /* Turn off the SIR encoder. */
32 syscon = clps_readl(SYSCON1);
33 syscon &= ~SYSCON1_SIREN;
34 clps_writel(syscon, SYSCON1);
35
36 return 0;
37}
38
39static struct dongle_driver clps711x_dongle = {
40 .owner = THIS_MODULE,
41 .driver_name = "EP7211 IR driver",
42 .type = IRDA_EP7211_DONGLE,
43 .open = clps711x_dongle_open,
44 .close = clps711x_dongle_close,
45};
46
47static int clps711x_sir_probe(struct platform_device *pdev)
48{
49 return irda_register_dongle(&clps711x_dongle);
50}
51
52static int clps711x_sir_remove(struct platform_device *pdev)
53{
54 return irda_unregister_dongle(&clps711x_dongle);
55}
56
57static struct platform_driver clps711x_sir_driver = {
58 .driver = {
59 .name = "sir-clps711x",
60 .owner = THIS_MODULE,
61 },
62 .probe = clps711x_sir_probe,
63 .remove = clps711x_sir_remove,
64};
65module_platform_driver(clps711x_sir_driver);
66
67MODULE_AUTHOR("Samuel Ortiz <samuel@sortiz.org>");
68MODULE_DESCRIPTION("EP7211 IR dongle driver");
69MODULE_LICENSE("GPL");
70MODULE_ALIAS("irda-dongle-13"); /* IRDA_EP7211_DONGLE */
diff --git a/drivers/net/irda/irtty-sir.c b/drivers/net/irda/irtty-sir.c
index 177441afeb96..24b6dddd7f2f 100644
--- a/drivers/net/irda/irtty-sir.c
+++ b/drivers/net/irda/irtty-sir.c
@@ -522,7 +522,6 @@ static void irtty_close(struct tty_struct *tty)
522 sirdev_put_instance(priv->dev); 522 sirdev_put_instance(priv->dev);
523 523
524 /* Stop tty */ 524 /* Stop tty */
525 irtty_stop_receiver(tty, TRUE);
526 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 525 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
527 if (tty->ops->stop) 526 if (tty->ops->stop)
528 tty->ops->stop(tty); 527 tty->ops->stop(tty);
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 8433de4509c7..1831fb7cd017 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -506,6 +506,9 @@ static int macvlan_change_mtu(struct net_device *dev, int new_mtu)
506static struct lock_class_key macvlan_netdev_xmit_lock_key; 506static struct lock_class_key macvlan_netdev_xmit_lock_key;
507static struct lock_class_key macvlan_netdev_addr_lock_key; 507static struct lock_class_key macvlan_netdev_addr_lock_key;
508 508
509#define ALWAYS_ON_FEATURES \
510 (NETIF_F_SG | NETIF_F_GEN_CSUM | NETIF_F_GSO_SOFTWARE | NETIF_F_LLTX)
511
509#define MACVLAN_FEATURES \ 512#define MACVLAN_FEATURES \
510 (NETIF_F_SG | NETIF_F_ALL_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \ 513 (NETIF_F_SG | NETIF_F_ALL_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \
511 NETIF_F_GSO | NETIF_F_TSO | NETIF_F_UFO | NETIF_F_GSO_ROBUST | \ 514 NETIF_F_GSO | NETIF_F_TSO | NETIF_F_UFO | NETIF_F_GSO_ROBUST | \
@@ -539,7 +542,7 @@ static int macvlan_init(struct net_device *dev)
539 dev->state = (dev->state & ~MACVLAN_STATE_MASK) | 542 dev->state = (dev->state & ~MACVLAN_STATE_MASK) |
540 (lowerdev->state & MACVLAN_STATE_MASK); 543 (lowerdev->state & MACVLAN_STATE_MASK);
541 dev->features = lowerdev->features & MACVLAN_FEATURES; 544 dev->features = lowerdev->features & MACVLAN_FEATURES;
542 dev->features |= NETIF_F_LLTX; 545 dev->features |= ALWAYS_ON_FEATURES;
543 dev->gso_max_size = lowerdev->gso_max_size; 546 dev->gso_max_size = lowerdev->gso_max_size;
544 dev->iflink = lowerdev->ifindex; 547 dev->iflink = lowerdev->ifindex;
545 dev->hard_header_len = lowerdev->hard_header_len; 548 dev->hard_header_len = lowerdev->hard_header_len;
@@ -699,7 +702,7 @@ static netdev_features_t macvlan_fix_features(struct net_device *dev,
699 features = netdev_increment_features(vlan->lowerdev->features, 702 features = netdev_increment_features(vlan->lowerdev->features,
700 features, 703 features,
701 mask); 704 mask);
702 features |= NETIF_F_LLTX; 705 features |= ALWAYS_ON_FEATURES;
703 706
704 return features; 707 return features;
705} 708}
@@ -879,14 +882,15 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
879 dev->priv_flags |= IFF_MACVLAN; 882 dev->priv_flags |= IFF_MACVLAN;
880 err = netdev_upper_dev_link(lowerdev, dev); 883 err = netdev_upper_dev_link(lowerdev, dev);
881 if (err) 884 if (err)
882 goto destroy_port; 885 goto unregister_netdev;
883
884 886
885 list_add_tail_rcu(&vlan->list, &port->vlans); 887 list_add_tail_rcu(&vlan->list, &port->vlans);
886 netif_stacked_transfer_operstate(lowerdev, dev); 888 netif_stacked_transfer_operstate(lowerdev, dev);
887 889
888 return 0; 890 return 0;
889 891
892unregister_netdev:
893 unregister_netdevice(dev);
890destroy_port: 894destroy_port:
891 port->count -= 1; 895 port->count -= 1;
892 if (!port->count) 896 if (!port->count)
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index 547725fa8671..98e7cbf720a5 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -437,7 +437,10 @@ static int ptp_dp83640_enable(struct ptp_clock_info *ptp,
437 if (on) { 437 if (on) {
438 gpio_num = gpio_tab[EXTTS0_GPIO + index]; 438 gpio_num = gpio_tab[EXTTS0_GPIO + index];
439 evnt |= (gpio_num & EVNT_GPIO_MASK) << EVNT_GPIO_SHIFT; 439 evnt |= (gpio_num & EVNT_GPIO_MASK) << EVNT_GPIO_SHIFT;
440 evnt |= EVNT_RISE; 440 if (rq->extts.flags & PTP_FALLING_EDGE)
441 evnt |= EVNT_FALL;
442 else
443 evnt |= EVNT_RISE;
441 } 444 }
442 ext_write(0, phydev, PAGE5, PTP_EVNT, evnt); 445 ext_write(0, phydev, PAGE5, PTP_EVNT, evnt);
443 return 0; 446 return 0;
@@ -1003,11 +1006,6 @@ static int dp83640_probe(struct phy_device *phydev)
1003 } else 1006 } else
1004 list_add_tail(&dp83640->list, &clock->phylist); 1007 list_add_tail(&dp83640->list, &clock->phylist);
1005 1008
1006 if (clock->chosen && !list_empty(&clock->phylist))
1007 recalibrate(clock);
1008 else
1009 enable_broadcast(dp83640->phydev, clock->page, 1);
1010
1011 dp83640_clock_put(clock); 1009 dp83640_clock_put(clock);
1012 return 0; 1010 return 0;
1013 1011
@@ -1058,6 +1056,21 @@ static void dp83640_remove(struct phy_device *phydev)
1058 kfree(dp83640); 1056 kfree(dp83640);
1059} 1057}
1060 1058
1059static int dp83640_config_init(struct phy_device *phydev)
1060{
1061 struct dp83640_private *dp83640 = phydev->priv;
1062 struct dp83640_clock *clock = dp83640->clock;
1063
1064 if (clock->chosen && !list_empty(&clock->phylist))
1065 recalibrate(clock);
1066 else
1067 enable_broadcast(phydev, clock->page, 1);
1068
1069 enable_status_frames(phydev, true);
1070 ext_write(0, phydev, PAGE4, PTP_CTL, PTP_ENABLE);
1071 return 0;
1072}
1073
1061static int dp83640_ack_interrupt(struct phy_device *phydev) 1074static int dp83640_ack_interrupt(struct phy_device *phydev)
1062{ 1075{
1063 int err = phy_read(phydev, MII_DP83640_MISR); 1076 int err = phy_read(phydev, MII_DP83640_MISR);
@@ -1195,11 +1208,6 @@ static int dp83640_hwtstamp(struct phy_device *phydev, struct ifreq *ifr)
1195 1208
1196 mutex_lock(&dp83640->clock->extreg_lock); 1209 mutex_lock(&dp83640->clock->extreg_lock);
1197 1210
1198 if (dp83640->hwts_tx_en || dp83640->hwts_rx_en) {
1199 enable_status_frames(phydev, true);
1200 ext_write(0, phydev, PAGE4, PTP_CTL, PTP_ENABLE);
1201 }
1202
1203 ext_write(0, phydev, PAGE5, PTP_TXCFG0, txcfg0); 1211 ext_write(0, phydev, PAGE5, PTP_TXCFG0, txcfg0);
1204 ext_write(0, phydev, PAGE5, PTP_RXCFG0, rxcfg0); 1212 ext_write(0, phydev, PAGE5, PTP_RXCFG0, rxcfg0);
1205 1213
@@ -1281,6 +1289,7 @@ static void dp83640_txtstamp(struct phy_device *phydev,
1281 } 1289 }
1282 /* fall through */ 1290 /* fall through */
1283 case HWTSTAMP_TX_ON: 1291 case HWTSTAMP_TX_ON:
1292 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
1284 skb_queue_tail(&dp83640->tx_queue, skb); 1293 skb_queue_tail(&dp83640->tx_queue, skb);
1285 schedule_work(&dp83640->ts_work); 1294 schedule_work(&dp83640->ts_work);
1286 break; 1295 break;
@@ -1330,6 +1339,7 @@ static struct phy_driver dp83640_driver = {
1330 .flags = PHY_HAS_INTERRUPT, 1339 .flags = PHY_HAS_INTERRUPT,
1331 .probe = dp83640_probe, 1340 .probe = dp83640_probe,
1332 .remove = dp83640_remove, 1341 .remove = dp83640_remove,
1342 .config_init = dp83640_config_init,
1333 .config_aneg = genphy_config_aneg, 1343 .config_aneg = genphy_config_aneg,
1334 .read_status = genphy_read_status, 1344 .read_status = genphy_read_status,
1335 .ack_interrupt = dp83640_ack_interrupt, 1345 .ack_interrupt = dp83640_ack_interrupt,
diff --git a/drivers/net/phy/mdio-sun4i.c b/drivers/net/phy/mdio-sun4i.c
index bb88bc7d81fb..9367acc84fbb 100644
--- a/drivers/net/phy/mdio-sun4i.c
+++ b/drivers/net/phy/mdio-sun4i.c
@@ -170,6 +170,9 @@ static int sun4i_mdio_remove(struct platform_device *pdev)
170} 170}
171 171
172static const struct of_device_id sun4i_mdio_dt_ids[] = { 172static const struct of_device_id sun4i_mdio_dt_ids[] = {
173 { .compatible = "allwinner,sun4i-a10-mdio" },
174
175 /* Deprecated */
173 { .compatible = "allwinner,sun4i-mdio" }, 176 { .compatible = "allwinner,sun4i-mdio" },
174 { } 177 { }
175}; 178};
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 19c9eca0ef26..76d96b9ebcdb 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -164,9 +164,9 @@ static const struct phy_setting settings[] = {
164 * of that setting. Returns the index of the last setting if 164 * of that setting. Returns the index of the last setting if
165 * none of the others match. 165 * none of the others match.
166 */ 166 */
167static inline int phy_find_setting(int speed, int duplex) 167static inline unsigned int phy_find_setting(int speed, int duplex)
168{ 168{
169 int idx = 0; 169 unsigned int idx = 0;
170 170
171 while (idx < ARRAY_SIZE(settings) && 171 while (idx < ARRAY_SIZE(settings) &&
172 (settings[idx].speed != speed || settings[idx].duplex != duplex)) 172 (settings[idx].speed != speed || settings[idx].duplex != duplex))
@@ -185,7 +185,7 @@ static inline int phy_find_setting(int speed, int duplex)
185 * the mask in features. Returns the index of the last setting 185 * the mask in features. Returns the index of the last setting
186 * if nothing else matches. 186 * if nothing else matches.
187 */ 187 */
188static inline int phy_find_valid(int idx, u32 features) 188static inline unsigned int phy_find_valid(unsigned int idx, u32 features)
189{ 189{
190 while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features)) 190 while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features))
191 idx++; 191 idx++;
@@ -204,7 +204,7 @@ static inline int phy_find_valid(int idx, u32 features)
204static void phy_sanitize_settings(struct phy_device *phydev) 204static void phy_sanitize_settings(struct phy_device *phydev)
205{ 205{
206 u32 features = phydev->supported; 206 u32 features = phydev->supported;
207 int idx; 207 unsigned int idx;
208 208
209 /* Sanitize settings based on PHY capabilities */ 209 /* Sanitize settings based on PHY capabilities */
210 if ((features & SUPPORTED_Autoneg) == 0) 210 if ((features & SUPPORTED_Autoneg) == 0)
@@ -954,7 +954,8 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
954 (phydev->interface == PHY_INTERFACE_MODE_RGMII))) { 954 (phydev->interface == PHY_INTERFACE_MODE_RGMII))) {
955 int eee_lp, eee_cap, eee_adv; 955 int eee_lp, eee_cap, eee_adv;
956 u32 lp, cap, adv; 956 u32 lp, cap, adv;
957 int idx, status; 957 int status;
958 unsigned int idx;
958 959
959 /* Read phy status to properly get the right settings */ 960 /* Read phy status to properly get the right settings */
960 status = phy_read_status(phydev); 961 status = phy_read_status(phydev);
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 4b03e63639b7..2f6989b1e0dc 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -683,10 +683,9 @@ EXPORT_SYMBOL(phy_detach);
683int phy_suspend(struct phy_device *phydev) 683int phy_suspend(struct phy_device *phydev)
684{ 684{
685 struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver); 685 struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver);
686 struct ethtool_wolinfo wol; 686 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
687 687
688 /* If the device has WOL enabled, we cannot suspend the PHY */ 688 /* If the device has WOL enabled, we cannot suspend the PHY */
689 wol.cmd = ETHTOOL_GWOL;
690 phy_ethtool_get_wol(phydev, &wol); 689 phy_ethtool_get_wol(phydev, &wol);
691 if (wol.wolopts) 690 if (wol.wolopts)
692 return -EBUSY; 691 return -EBUSY;
@@ -719,7 +718,7 @@ int phy_resume(struct phy_device *phydev)
719static int genphy_config_advert(struct phy_device *phydev) 718static int genphy_config_advert(struct phy_device *phydev)
720{ 719{
721 u32 advertise; 720 u32 advertise;
722 int oldadv, adv; 721 int oldadv, adv, bmsr;
723 int err, changed = 0; 722 int err, changed = 0;
724 723
725 /* Only allow advertising what this PHY supports */ 724 /* Only allow advertising what this PHY supports */
@@ -744,26 +743,36 @@ static int genphy_config_advert(struct phy_device *phydev)
744 changed = 1; 743 changed = 1;
745 } 744 }
746 745
746 bmsr = phy_read(phydev, MII_BMSR);
747 if (bmsr < 0)
748 return bmsr;
749
750 /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all
751 * 1000Mbits/sec capable PHYs shall have the BMSR_ESTATEN bit set to a
752 * logical 1.
753 */
754 if (!(bmsr & BMSR_ESTATEN))
755 return changed;
756
747 /* Configure gigabit if it's supported */ 757 /* Configure gigabit if it's supported */
758 adv = phy_read(phydev, MII_CTRL1000);
759 if (adv < 0)
760 return adv;
761
762 oldadv = adv;
763 adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
764
748 if (phydev->supported & (SUPPORTED_1000baseT_Half | 765 if (phydev->supported & (SUPPORTED_1000baseT_Half |
749 SUPPORTED_1000baseT_Full)) { 766 SUPPORTED_1000baseT_Full)) {
750 adv = phy_read(phydev, MII_CTRL1000);
751 if (adv < 0)
752 return adv;
753
754 oldadv = adv;
755 adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
756 adv |= ethtool_adv_to_mii_ctrl1000_t(advertise); 767 adv |= ethtool_adv_to_mii_ctrl1000_t(advertise);
757 768 if (adv != oldadv)
758 if (adv != oldadv) {
759 err = phy_write(phydev, MII_CTRL1000, adv);
760
761 if (err < 0)
762 return err;
763 changed = 1; 769 changed = 1;
764 }
765 } 770 }
766 771
772 err = phy_write(phydev, MII_CTRL1000, adv);
773 if (err < 0)
774 return err;
775
767 return changed; 776 return changed;
768} 777}
769 778
@@ -906,6 +915,8 @@ int genphy_read_status(struct phy_device *phydev)
906 int err; 915 int err;
907 int lpa; 916 int lpa;
908 int lpagb = 0; 917 int lpagb = 0;
918 int common_adv;
919 int common_adv_gb = 0;
909 920
910 /* Update the link, but return if there was an error */ 921 /* Update the link, but return if there was an error */
911 err = genphy_update_link(phydev); 922 err = genphy_update_link(phydev);
@@ -927,7 +938,7 @@ int genphy_read_status(struct phy_device *phydev)
927 938
928 phydev->lp_advertising = 939 phydev->lp_advertising =
929 mii_stat1000_to_ethtool_lpa_t(lpagb); 940 mii_stat1000_to_ethtool_lpa_t(lpagb);
930 lpagb &= adv << 2; 941 common_adv_gb = lpagb & adv << 2;
931 } 942 }
932 943
933 lpa = phy_read(phydev, MII_LPA); 944 lpa = phy_read(phydev, MII_LPA);
@@ -940,25 +951,25 @@ int genphy_read_status(struct phy_device *phydev)
940 if (adv < 0) 951 if (adv < 0)
941 return adv; 952 return adv;
942 953
943 lpa &= adv; 954 common_adv = lpa & adv;
944 955
945 phydev->speed = SPEED_10; 956 phydev->speed = SPEED_10;
946 phydev->duplex = DUPLEX_HALF; 957 phydev->duplex = DUPLEX_HALF;
947 phydev->pause = 0; 958 phydev->pause = 0;
948 phydev->asym_pause = 0; 959 phydev->asym_pause = 0;
949 960
950 if (lpagb & (LPA_1000FULL | LPA_1000HALF)) { 961 if (common_adv_gb & (LPA_1000FULL | LPA_1000HALF)) {
951 phydev->speed = SPEED_1000; 962 phydev->speed = SPEED_1000;
952 963
953 if (lpagb & LPA_1000FULL) 964 if (common_adv_gb & LPA_1000FULL)
954 phydev->duplex = DUPLEX_FULL; 965 phydev->duplex = DUPLEX_FULL;
955 } else if (lpa & (LPA_100FULL | LPA_100HALF)) { 966 } else if (common_adv & (LPA_100FULL | LPA_100HALF)) {
956 phydev->speed = SPEED_100; 967 phydev->speed = SPEED_100;
957 968
958 if (lpa & LPA_100FULL) 969 if (common_adv & LPA_100FULL)
959 phydev->duplex = DUPLEX_FULL; 970 phydev->duplex = DUPLEX_FULL;
960 } else 971 } else
961 if (lpa & LPA_10FULL) 972 if (common_adv & LPA_10FULL)
962 phydev->duplex = DUPLEX_FULL; 973 phydev->duplex = DUPLEX_FULL;
963 974
964 if (phydev->duplex == DUPLEX_FULL) { 975 if (phydev->duplex == DUPLEX_FULL) {
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 28407426fd6f..c8624a8235ab 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -1648,7 +1648,7 @@ static netdev_tx_t team_xmit(struct sk_buff *skb, struct net_device *dev)
1648} 1648}
1649 1649
1650static u16 team_select_queue(struct net_device *dev, struct sk_buff *skb, 1650static u16 team_select_queue(struct net_device *dev, struct sk_buff *skb,
1651 void *accel_priv) 1651 void *accel_priv, select_queue_fallback_t fallback)
1652{ 1652{
1653 /* 1653 /*
1654 * This helper function exists to help dev_pick_tx get the correct 1654 * This helper function exists to help dev_pick_tx get the correct
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 44c4db8450f0..26f8635b027d 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -366,7 +366,7 @@ static inline void tun_flow_save_rps_rxhash(struct tun_flow_entry *e, u32 hash)
366 * hope the rxq no. may help here. 366 * hope the rxq no. may help here.
367 */ 367 */
368static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb, 368static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb,
369 void *accel_priv) 369 void *accel_priv, select_queue_fallback_t fallback)
370{ 370{
371 struct tun_struct *tun = netdev_priv(dev); 371 struct tun_struct *tun = netdev_priv(dev);
372 struct tun_flow_entry *e; 372 struct tun_flow_entry *e;
@@ -1686,7 +1686,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1686 TUN_USER_FEATURES | NETIF_F_HW_VLAN_CTAG_TX | 1686 TUN_USER_FEATURES | NETIF_F_HW_VLAN_CTAG_TX |
1687 NETIF_F_HW_VLAN_STAG_TX; 1687 NETIF_F_HW_VLAN_STAG_TX;
1688 dev->features = dev->hw_features; 1688 dev->features = dev->hw_features;
1689 dev->vlan_features = dev->features; 1689 dev->vlan_features = dev->features &
1690 ~(NETIF_F_HW_VLAN_CTAG_TX |
1691 NETIF_F_HW_VLAN_STAG_TX);
1690 1692
1691 INIT_LIST_HEAD(&tun->disabled); 1693 INIT_LIST_HEAD(&tun->disabled);
1692 err = tun_attach(tun, file, false); 1694 err = tun_attach(tun, file, false);
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 6b638a066c1d..7e7269fd3707 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -292,6 +292,21 @@ config USB_NET_SR9700
292 This option adds support for CoreChip-sz SR9700 based USB 1.1 292 This option adds support for CoreChip-sz SR9700 based USB 1.1
293 10/100 Ethernet adapters. 293 10/100 Ethernet adapters.
294 294
295config USB_NET_SR9800
296 tristate "CoreChip-sz SR9800 based USB 2.0 10/100 ethernet devices"
297 depends on USB_USBNET
298 select CRC32
299 ---help---
300 Say Y if you want to use one of the following 100Mbps USB Ethernet
301 device based on the CoreChip-sz SR9800 chip.
302
303 This driver makes the adapter appear as a normal Ethernet interface,
304 typically on eth0, if it is the only ethernet device, or perhaps on
305 eth1, if you have a PCI or ISA ethernet card installed.
306
307 To compile this driver as a module, choose M here: the
308 module will be called sr9800.
309
295config USB_NET_SMSC75XX 310config USB_NET_SMSC75XX
296 tristate "SMSC LAN75XX based USB 2.0 gigabit ethernet devices" 311 tristate "SMSC LAN75XX based USB 2.0 gigabit ethernet devices"
297 depends on USB_USBNET 312 depends on USB_USBNET
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index b17b5e88bbaf..e2797f1e1b31 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -11,10 +11,11 @@ obj-$(CONFIG_USB_HSO) += hso.o
11obj-$(CONFIG_USB_NET_AX8817X) += asix.o 11obj-$(CONFIG_USB_NET_AX8817X) += asix.o
12asix-y := asix_devices.o asix_common.o ax88172a.o 12asix-y := asix_devices.o asix_common.o ax88172a.o
13obj-$(CONFIG_USB_NET_AX88179_178A) += ax88179_178a.o 13obj-$(CONFIG_USB_NET_AX88179_178A) += ax88179_178a.o
14obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o r815x.o 14obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o
15obj-$(CONFIG_USB_NET_CDC_EEM) += cdc_eem.o 15obj-$(CONFIG_USB_NET_CDC_EEM) += cdc_eem.o
16obj-$(CONFIG_USB_NET_DM9601) += dm9601.o 16obj-$(CONFIG_USB_NET_DM9601) += dm9601.o
17obj-$(CONFIG_USB_NET_SR9700) += sr9700.o 17obj-$(CONFIG_USB_NET_SR9700) += sr9700.o
18obj-$(CONFIG_USB_NET_SR9800) += sr9800.o
18obj-$(CONFIG_USB_NET_SMSC75XX) += smsc75xx.o 19obj-$(CONFIG_USB_NET_SMSC75XX) += smsc75xx.o
19obj-$(CONFIG_USB_NET_SMSC95XX) += smsc95xx.o 20obj-$(CONFIG_USB_NET_SMSC95XX) += smsc95xx.o
20obj-$(CONFIG_USB_NET_GL620A) += gl620a.o 21obj-$(CONFIG_USB_NET_GL620A) += gl620a.o
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 9765a7d4766d..5d194093f3e1 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -917,7 +917,8 @@ static const struct driver_info ax88178_info = {
917 .status = asix_status, 917 .status = asix_status,
918 .link_reset = ax88178_link_reset, 918 .link_reset = ax88178_link_reset,
919 .reset = ax88178_reset, 919 .reset = ax88178_reset,
920 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR, 920 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
921 FLAG_MULTI_PACKET,
921 .rx_fixup = asix_rx_fixup_common, 922 .rx_fixup = asix_rx_fixup_common,
922 .tx_fixup = asix_tx_fixup, 923 .tx_fixup = asix_tx_fixup,
923}; 924};
diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
index d6f64dad05bc..054e59ca6946 100644
--- a/drivers/net/usb/ax88179_178a.c
+++ b/drivers/net/usb/ax88179_178a.c
@@ -1029,20 +1029,12 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
1029 dev->mii.phy_id = 0x03; 1029 dev->mii.phy_id = 0x03;
1030 dev->mii.supports_gmii = 1; 1030 dev->mii.supports_gmii = 1;
1031 1031
1032 if (usb_device_no_sg_constraint(dev->udev))
1033 dev->can_dma_sg = 1;
1034
1035 dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 1032 dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1036 NETIF_F_RXCSUM; 1033 NETIF_F_RXCSUM;
1037 1034
1038 dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 1035 dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1039 NETIF_F_RXCSUM; 1036 NETIF_F_RXCSUM;
1040 1037
1041 if (dev->can_dma_sg) {
1042 dev->net->features |= NETIF_F_SG | NETIF_F_TSO;
1043 dev->net->hw_features |= NETIF_F_SG | NETIF_F_TSO;
1044 }
1045
1046 /* Enable checksum offload */ 1038 /* Enable checksum offload */
1047 *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 1039 *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
1048 AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 1040 AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
@@ -1118,6 +1110,10 @@ static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1118 u16 hdr_off; 1110 u16 hdr_off;
1119 u32 *pkt_hdr; 1111 u32 *pkt_hdr;
1120 1112
1113 /* This check is no longer done by usbnet */
1114 if (skb->len < dev->net->hard_header_len)
1115 return 0;
1116
1121 skb_trim(skb, skb->len - 4); 1117 skb_trim(skb, skb->len - 4);
1122 memcpy(&rx_hdr, skb_tail_pointer(skb), 4); 1118 memcpy(&rx_hdr, skb_tail_pointer(skb), 4);
1123 le32_to_cpus(&rx_hdr); 1119 le32_to_cpus(&rx_hdr);
@@ -1391,6 +1387,19 @@ static const struct driver_info ax88178a_info = {
1391 .tx_fixup = ax88179_tx_fixup, 1387 .tx_fixup = ax88179_tx_fixup,
1392}; 1388};
1393 1389
1390static const struct driver_info dlink_dub1312_info = {
1391 .description = "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter",
1392 .bind = ax88179_bind,
1393 .unbind = ax88179_unbind,
1394 .status = ax88179_status,
1395 .link_reset = ax88179_link_reset,
1396 .reset = ax88179_reset,
1397 .stop = ax88179_stop,
1398 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1399 .rx_fixup = ax88179_rx_fixup,
1400 .tx_fixup = ax88179_tx_fixup,
1401};
1402
1394static const struct driver_info sitecom_info = { 1403static const struct driver_info sitecom_info = {
1395 .description = "Sitecom USB 3.0 to Gigabit Adapter", 1404 .description = "Sitecom USB 3.0 to Gigabit Adapter",
1396 .bind = ax88179_bind, 1405 .bind = ax88179_bind,
@@ -1417,6 +1426,19 @@ static const struct driver_info samsung_info = {
1417 .tx_fixup = ax88179_tx_fixup, 1426 .tx_fixup = ax88179_tx_fixup,
1418}; 1427};
1419 1428
1429static const struct driver_info lenovo_info = {
1430 .description = "Lenovo OneLinkDock Gigabit LAN",
1431 .bind = ax88179_bind,
1432 .unbind = ax88179_unbind,
1433 .status = ax88179_status,
1434 .link_reset = ax88179_link_reset,
1435 .reset = ax88179_reset,
1436 .stop = ax88179_stop,
1437 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1438 .rx_fixup = ax88179_rx_fixup,
1439 .tx_fixup = ax88179_tx_fixup,
1440};
1441
1420static const struct usb_device_id products[] = { 1442static const struct usb_device_id products[] = {
1421{ 1443{
1422 /* ASIX AX88179 10/100/1000 */ 1444 /* ASIX AX88179 10/100/1000 */
@@ -1427,6 +1449,10 @@ static const struct usb_device_id products[] = {
1427 USB_DEVICE(0x0b95, 0x178a), 1449 USB_DEVICE(0x0b95, 0x178a),
1428 .driver_info = (unsigned long)&ax88178a_info, 1450 .driver_info = (unsigned long)&ax88178a_info,
1429}, { 1451}, {
1452 /* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */
1453 USB_DEVICE(0x2001, 0x4a00),
1454 .driver_info = (unsigned long)&dlink_dub1312_info,
1455}, {
1430 /* Sitecom USB 3.0 to Gigabit Adapter */ 1456 /* Sitecom USB 3.0 to Gigabit Adapter */
1431 USB_DEVICE(0x0df6, 0x0072), 1457 USB_DEVICE(0x0df6, 0x0072),
1432 .driver_info = (unsigned long)&sitecom_info, 1458 .driver_info = (unsigned long)&sitecom_info,
@@ -1434,6 +1460,10 @@ static const struct usb_device_id products[] = {
1434 /* Samsung USB Ethernet Adapter */ 1460 /* Samsung USB Ethernet Adapter */
1435 USB_DEVICE(0x04e8, 0xa100), 1461 USB_DEVICE(0x04e8, 0xa100),
1436 .driver_info = (unsigned long)&samsung_info, 1462 .driver_info = (unsigned long)&samsung_info,
1463}, {
1464 /* Lenovo OneLinkDock Gigabit LAN */
1465 USB_DEVICE(0x17ef, 0x304b),
1466 .driver_info = (unsigned long)&lenovo_info,
1437}, 1467},
1438 { }, 1468 { },
1439}; 1469};
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 42e176912c8e..bd363b27e854 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -652,6 +652,13 @@ static const struct usb_device_id products[] = {
652 .driver_info = 0, 652 .driver_info = 0,
653}, 653},
654 654
655/* Samsung USB Ethernet Adapters */
656{
657 USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, 0xa101, USB_CLASS_COMM,
658 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
659 .driver_info = 0,
660},
661
655/* WHITELIST!!! 662/* WHITELIST!!!
656 * 663 *
657 * CDC Ether uses two interfaces, not necessarily consecutive. 664 * CDC Ether uses two interfaces, not necessarily consecutive.
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index dbff290ed0e4..d350d2795e10 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -68,7 +68,6 @@ static struct usb_driver cdc_ncm_driver;
68static int cdc_ncm_setup(struct usbnet *dev) 68static int cdc_ncm_setup(struct usbnet *dev)
69{ 69{
70 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; 70 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
71 struct usb_cdc_ncm_ntb_parameters ncm_parm;
72 u32 val; 71 u32 val;
73 u8 flags; 72 u8 flags;
74 u8 iface_no; 73 u8 iface_no;
@@ -82,22 +81,22 @@ static int cdc_ncm_setup(struct usbnet *dev)
82 err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS, 81 err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS,
83 USB_TYPE_CLASS | USB_DIR_IN 82 USB_TYPE_CLASS | USB_DIR_IN
84 |USB_RECIP_INTERFACE, 83 |USB_RECIP_INTERFACE,
85 0, iface_no, &ncm_parm, 84 0, iface_no, &ctx->ncm_parm,
86 sizeof(ncm_parm)); 85 sizeof(ctx->ncm_parm));
87 if (err < 0) { 86 if (err < 0) {
88 dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n"); 87 dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n");
89 return err; /* GET_NTB_PARAMETERS is required */ 88 return err; /* GET_NTB_PARAMETERS is required */
90 } 89 }
91 90
92 /* read correct set of parameters according to device mode */ 91 /* read correct set of parameters according to device mode */
93 ctx->rx_max = le32_to_cpu(ncm_parm.dwNtbInMaxSize); 92 ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize);
94 ctx->tx_max = le32_to_cpu(ncm_parm.dwNtbOutMaxSize); 93 ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize);
95 ctx->tx_remainder = le16_to_cpu(ncm_parm.wNdpOutPayloadRemainder); 94 ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder);
96 ctx->tx_modulus = le16_to_cpu(ncm_parm.wNdpOutDivisor); 95 ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor);
97 ctx->tx_ndp_modulus = le16_to_cpu(ncm_parm.wNdpOutAlignment); 96 ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment);
98 /* devices prior to NCM Errata shall set this field to zero */ 97 /* devices prior to NCM Errata shall set this field to zero */
99 ctx->tx_max_datagrams = le16_to_cpu(ncm_parm.wNtbOutMaxDatagrams); 98 ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams);
100 ntb_fmt_supported = le16_to_cpu(ncm_parm.bmNtbFormatsSupported); 99 ntb_fmt_supported = le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported);
101 100
102 /* there are some minor differences in NCM and MBIM defaults */ 101 /* there are some minor differences in NCM and MBIM defaults */
103 if (cdc_ncm_comm_intf_is_mbim(ctx->control->cur_altsetting)) { 102 if (cdc_ncm_comm_intf_is_mbim(ctx->control->cur_altsetting)) {
@@ -146,7 +145,7 @@ static int cdc_ncm_setup(struct usbnet *dev)
146 } 145 }
147 146
148 /* inform device about NTB input size changes */ 147 /* inform device about NTB input size changes */
149 if (ctx->rx_max != le32_to_cpu(ncm_parm.dwNtbInMaxSize)) { 148 if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) {
150 __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max); 149 __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
151 150
152 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE, 151 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE,
@@ -162,14 +161,6 @@ static int cdc_ncm_setup(struct usbnet *dev)
162 dev_dbg(&dev->intf->dev, "Using default maximum transmit length=%d\n", 161 dev_dbg(&dev->intf->dev, "Using default maximum transmit length=%d\n",
163 CDC_NCM_NTB_MAX_SIZE_TX); 162 CDC_NCM_NTB_MAX_SIZE_TX);
164 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX; 163 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX;
165
166 /* Adding a pad byte here simplifies the handling in
167 * cdc_ncm_fill_tx_frame, by making tx_max always
168 * represent the real skb max size.
169 */
170 if (ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0)
171 ctx->tx_max++;
172
173 } 164 }
174 165
175 /* 166 /*
@@ -439,6 +430,10 @@ advance:
439 goto error2; 430 goto error2;
440 } 431 }
441 432
433 /* initialize data interface */
434 if (cdc_ncm_setup(dev))
435 goto error2;
436
442 /* configure data interface */ 437 /* configure data interface */
443 temp = usb_set_interface(dev->udev, iface_no, data_altsetting); 438 temp = usb_set_interface(dev->udev, iface_no, data_altsetting);
444 if (temp) { 439 if (temp) {
@@ -453,12 +448,6 @@ advance:
453 goto error2; 448 goto error2;
454 } 449 }
455 450
456 /* initialize data interface */
457 if (cdc_ncm_setup(dev)) {
458 dev_dbg(&intf->dev, "cdc_ncm_setup() failed\n");
459 goto error2;
460 }
461
462 usb_set_intfdata(ctx->data, dev); 451 usb_set_intfdata(ctx->data, dev);
463 usb_set_intfdata(ctx->control, dev); 452 usb_set_intfdata(ctx->control, dev);
464 453
@@ -475,6 +464,15 @@ advance:
475 dev->hard_mtu = ctx->tx_max; 464 dev->hard_mtu = ctx->tx_max;
476 dev->rx_urb_size = ctx->rx_max; 465 dev->rx_urb_size = ctx->rx_max;
477 466
467 /* cdc_ncm_setup will override dwNtbOutMaxSize if it is
468 * outside the sane range. Adding a pad byte here if necessary
469 * simplifies the handling in cdc_ncm_fill_tx_frame, making
470 * tx_max always represent the real skb max size.
471 */
472 if (ctx->tx_max != le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) &&
473 ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0)
474 ctx->tx_max++;
475
478 return 0; 476 return 0;
479 477
480error2: 478error2:
diff --git a/drivers/net/usb/gl620a.c b/drivers/net/usb/gl620a.c
index e4a8a93fbaf7..1cc24e6f23e2 100644
--- a/drivers/net/usb/gl620a.c
+++ b/drivers/net/usb/gl620a.c
@@ -84,6 +84,10 @@ static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
84 u32 size; 84 u32 size;
85 u32 count; 85 u32 count;
86 86
87 /* This check is no longer done by usbnet */
88 if (skb->len < dev->net->hard_header_len)
89 return 0;
90
87 header = (struct gl_header *) skb->data; 91 header = (struct gl_header *) skb->data;
88 92
89 // get the packet count of the received skb 93 // get the packet count of the received skb
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 1a482344b3f5..660bd5ea9fc0 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -1201,16 +1201,18 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
1201 struct hso_serial *serial = urb->context; 1201 struct hso_serial *serial = urb->context;
1202 int status = urb->status; 1202 int status = urb->status;
1203 1203
1204 D4("\n--- Got serial_read_bulk callback %02x ---", status);
1205
1204 /* sanity check */ 1206 /* sanity check */
1205 if (!serial) { 1207 if (!serial) {
1206 D1("serial == NULL"); 1208 D1("serial == NULL");
1207 return; 1209 return;
1208 } else if (status) { 1210 }
1211 if (status) {
1209 handle_usb_error(status, __func__, serial->parent); 1212 handle_usb_error(status, __func__, serial->parent);
1210 return; 1213 return;
1211 } 1214 }
1212 1215
1213 D4("\n--- Got serial_read_bulk callback %02x ---", status);
1214 D1("Actual length = %d\n", urb->actual_length); 1216 D1("Actual length = %d\n", urb->actual_length);
1215 DUMP1(urb->transfer_buffer, urb->actual_length); 1217 DUMP1(urb->transfer_buffer, urb->actual_length);
1216 1218
@@ -1218,25 +1220,13 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
1218 if (serial->port.count == 0) 1220 if (serial->port.count == 0)
1219 return; 1221 return;
1220 1222
1221 if (status == 0) { 1223 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
1222 if (serial->parent->port_spec & HSO_INFO_CRC_BUG) 1224 fix_crc_bug(urb, serial->in_endp->wMaxPacketSize);
1223 fix_crc_bug(urb, serial->in_endp->wMaxPacketSize); 1225 /* Valid data, handle RX data */
1224 /* Valid data, handle RX data */ 1226 spin_lock(&serial->serial_lock);
1225 spin_lock(&serial->serial_lock); 1227 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1;
1226 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1; 1228 put_rxbuf_data_and_resubmit_bulk_urb(serial);
1227 put_rxbuf_data_and_resubmit_bulk_urb(serial); 1229 spin_unlock(&serial->serial_lock);
1228 spin_unlock(&serial->serial_lock);
1229 } else if (status == -ENOENT || status == -ECONNRESET) {
1230 /* Unlinked - check for throttled port. */
1231 D2("Port %d, successfully unlinked urb", serial->minor);
1232 spin_lock(&serial->serial_lock);
1233 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0;
1234 hso_resubmit_rx_bulk_urb(serial, urb);
1235 spin_unlock(&serial->serial_lock);
1236 } else {
1237 D2("Port %d, status = %d for read urb", serial->minor, status);
1238 return;
1239 }
1240} 1230}
1241 1231
1242/* 1232/*
diff --git a/drivers/net/usb/mcs7830.c b/drivers/net/usb/mcs7830.c
index a305a7b2dae6..82d844a8ebd0 100644
--- a/drivers/net/usb/mcs7830.c
+++ b/drivers/net/usb/mcs7830.c
@@ -526,8 +526,9 @@ static int mcs7830_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
526{ 526{
527 u8 status; 527 u8 status;
528 528
529 if (skb->len == 0) { 529 /* This check is no longer done by usbnet */
530 dev_err(&dev->udev->dev, "unexpected empty rx frame\n"); 530 if (skb->len < dev->net->hard_header_len) {
531 dev_err(&dev->udev->dev, "unexpected tiny rx frame\n");
531 return 0; 532 return 0;
532 } 533 }
533 534
diff --git a/drivers/net/usb/net1080.c b/drivers/net/usb/net1080.c
index 0a85d9227775..4cbdb1307f3e 100644
--- a/drivers/net/usb/net1080.c
+++ b/drivers/net/usb/net1080.c
@@ -364,6 +364,10 @@ static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
364 struct nc_trailer *trailer; 364 struct nc_trailer *trailer;
365 u16 hdr_len, packet_len; 365 u16 hdr_len, packet_len;
366 366
367 /* This check is no longer done by usbnet */
368 if (skb->len < dev->net->hard_header_len)
369 return 0;
370
367 if (!(skb->len & 0x01)) { 371 if (!(skb->len & 0x01)) {
368 netdev_dbg(dev->net, "rx framesize %d range %d..%d mtu %d\n", 372 netdev_dbg(dev->net, "rx framesize %d range %d..%d mtu %d\n",
369 skb->len, dev->net->hard_header_len, dev->hard_mtu, 373 skb->len, dev->net->hard_header_len, dev->hard_mtu,
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 23bdd5b9274d..313cb6cd4848 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -80,10 +80,10 @@ static int qmi_wwan_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
80{ 80{
81 __be16 proto; 81 __be16 proto;
82 82
83 /* usbnet rx_complete guarantees that skb->len is at least 83 /* This check is no longer done by usbnet */
84 * hard_header_len, so we can inspect the dest address without 84 if (skb->len < dev->net->hard_header_len)
85 * checking skb->len 85 return 0;
86 */ 86
87 switch (skb->data[0] & 0xf0) { 87 switch (skb->data[0] & 0xf0) {
88 case 0x40: 88 case 0x40:
89 proto = htons(ETH_P_IP); 89 proto = htons(ETH_P_IP);
@@ -712,6 +712,7 @@ static const struct usb_device_id products[] = {
712 {QMI_FIXED_INTF(0x19d2, 0x1255, 3)}, 712 {QMI_FIXED_INTF(0x19d2, 0x1255, 3)},
713 {QMI_FIXED_INTF(0x19d2, 0x1255, 4)}, 713 {QMI_FIXED_INTF(0x19d2, 0x1255, 4)},
714 {QMI_FIXED_INTF(0x19d2, 0x1256, 4)}, 714 {QMI_FIXED_INTF(0x19d2, 0x1256, 4)},
715 {QMI_FIXED_INTF(0x19d2, 0x1270, 5)}, /* ZTE MF667 */
715 {QMI_FIXED_INTF(0x19d2, 0x1401, 2)}, 716 {QMI_FIXED_INTF(0x19d2, 0x1401, 2)},
716 {QMI_FIXED_INTF(0x19d2, 0x1402, 2)}, /* ZTE MF60 */ 717 {QMI_FIXED_INTF(0x19d2, 0x1402, 2)}, /* ZTE MF60 */
717 {QMI_FIXED_INTF(0x19d2, 0x1424, 2)}, 718 {QMI_FIXED_INTF(0x19d2, 0x1424, 2)},
@@ -723,6 +724,7 @@ static const struct usb_device_id products[] = {
723 {QMI_FIXED_INTF(0x1199, 0x68a2, 8)}, /* Sierra Wireless MC7710 in QMI mode */ 724 {QMI_FIXED_INTF(0x1199, 0x68a2, 8)}, /* Sierra Wireless MC7710 in QMI mode */
724 {QMI_FIXED_INTF(0x1199, 0x68a2, 19)}, /* Sierra Wireless MC7710 in QMI mode */ 725 {QMI_FIXED_INTF(0x1199, 0x68a2, 19)}, /* Sierra Wireless MC7710 in QMI mode */
725 {QMI_FIXED_INTF(0x1199, 0x901c, 8)}, /* Sierra Wireless EM7700 */ 726 {QMI_FIXED_INTF(0x1199, 0x901c, 8)}, /* Sierra Wireless EM7700 */
727 {QMI_FIXED_INTF(0x1199, 0x9051, 8)}, /* Netgear AirCard 340U */
726 {QMI_FIXED_INTF(0x1bbb, 0x011e, 4)}, /* Telekom Speedstick LTE II (Alcatel One Touch L100V LTE) */ 728 {QMI_FIXED_INTF(0x1bbb, 0x011e, 4)}, /* Telekom Speedstick LTE II (Alcatel One Touch L100V LTE) */
727 {QMI_FIXED_INTF(0x2357, 0x0201, 4)}, /* TP-LINK HSUPA Modem MA180 */ 729 {QMI_FIXED_INTF(0x2357, 0x0201, 4)}, /* TP-LINK HSUPA Modem MA180 */
728 {QMI_FIXED_INTF(0x2357, 0x9000, 4)}, /* TP-LINK MA260 */ 730 {QMI_FIXED_INTF(0x2357, 0x9000, 4)}, /* TP-LINK MA260 */
@@ -730,6 +732,7 @@ static const struct usb_device_id products[] = {
730 {QMI_FIXED_INTF(0x1bc7, 0x1201, 2)}, /* Telit LE920 */ 732 {QMI_FIXED_INTF(0x1bc7, 0x1201, 2)}, /* Telit LE920 */
731 {QMI_FIXED_INTF(0x0b3c, 0xc005, 6)}, /* Olivetti Olicard 200 */ 733 {QMI_FIXED_INTF(0x0b3c, 0xc005, 6)}, /* Olivetti Olicard 200 */
732 {QMI_FIXED_INTF(0x1e2d, 0x0060, 4)}, /* Cinterion PLxx */ 734 {QMI_FIXED_INTF(0x1e2d, 0x0060, 4)}, /* Cinterion PLxx */
735 {QMI_FIXED_INTF(0x1e2d, 0x0053, 4)}, /* Cinterion PHxx,PXxx */
733 736
734 /* 4. Gobi 1000 devices */ 737 /* 4. Gobi 1000 devices */
735 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */ 738 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index e8fac732c6f1..adb12f349a61 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -449,9 +449,6 @@ enum rtl8152_flags {
449#define MCU_TYPE_PLA 0x0100 449#define MCU_TYPE_PLA 0x0100
450#define MCU_TYPE_USB 0x0000 450#define MCU_TYPE_USB 0x0000
451 451
452#define REALTEK_USB_DEVICE(vend, prod) \
453 USB_DEVICE_INTERFACE_CLASS(vend, prod, USB_CLASS_VENDOR_SPEC)
454
455struct rx_desc { 452struct rx_desc {
456 __le32 opts1; 453 __le32 opts1;
457#define RX_LEN_MASK 0x7fff 454#define RX_LEN_MASK 0x7fff
@@ -2273,22 +2270,21 @@ static int rtl8152_open(struct net_device *netdev)
2273 struct r8152 *tp = netdev_priv(netdev); 2270 struct r8152 *tp = netdev_priv(netdev);
2274 int res = 0; 2271 int res = 0;
2275 2272
2273 rtl8152_set_speed(tp, AUTONEG_ENABLE,
2274 tp->mii.supports_gmii ? SPEED_1000 : SPEED_100,
2275 DUPLEX_FULL);
2276 tp->speed = 0;
2277 netif_carrier_off(netdev);
2278 netif_start_queue(netdev);
2279 set_bit(WORK_ENABLE, &tp->flags);
2276 res = usb_submit_urb(tp->intr_urb, GFP_KERNEL); 2280 res = usb_submit_urb(tp->intr_urb, GFP_KERNEL);
2277 if (res) { 2281 if (res) {
2278 if (res == -ENODEV) 2282 if (res == -ENODEV)
2279 netif_device_detach(tp->netdev); 2283 netif_device_detach(tp->netdev);
2280 netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n", 2284 netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n",
2281 res); 2285 res);
2282 return res;
2283 } 2286 }
2284 2287
2285 rtl8152_set_speed(tp, AUTONEG_ENABLE,
2286 tp->mii.supports_gmii ? SPEED_1000 : SPEED_100,
2287 DUPLEX_FULL);
2288 tp->speed = 0;
2289 netif_carrier_off(netdev);
2290 netif_start_queue(netdev);
2291 set_bit(WORK_ENABLE, &tp->flags);
2292 2288
2293 return res; 2289 return res;
2294} 2290}
@@ -2298,8 +2294,8 @@ static int rtl8152_close(struct net_device *netdev)
2298 struct r8152 *tp = netdev_priv(netdev); 2294 struct r8152 *tp = netdev_priv(netdev);
2299 int res = 0; 2295 int res = 0;
2300 2296
2301 usb_kill_urb(tp->intr_urb);
2302 clear_bit(WORK_ENABLE, &tp->flags); 2297 clear_bit(WORK_ENABLE, &tp->flags);
2298 usb_kill_urb(tp->intr_urb);
2303 cancel_delayed_work_sync(&tp->schedule); 2299 cancel_delayed_work_sync(&tp->schedule);
2304 netif_stop_queue(netdev); 2300 netif_stop_queue(netdev);
2305 tasklet_disable(&tp->tl); 2301 tasklet_disable(&tp->tl);
@@ -2740,6 +2736,12 @@ static int rtl8152_probe(struct usb_interface *intf,
2740 struct net_device *netdev; 2736 struct net_device *netdev;
2741 int ret; 2737 int ret;
2742 2738
2739 if (udev->actconfig->desc.bConfigurationValue != 1) {
2740 usb_driver_set_configuration(udev, 1);
2741 return -ENODEV;
2742 }
2743
2744 usb_reset_device(udev);
2743 netdev = alloc_etherdev(sizeof(struct r8152)); 2745 netdev = alloc_etherdev(sizeof(struct r8152));
2744 if (!netdev) { 2746 if (!netdev) {
2745 dev_err(&intf->dev, "Out of memory\n"); 2747 dev_err(&intf->dev, "Out of memory\n");
@@ -2820,9 +2822,9 @@ static void rtl8152_disconnect(struct usb_interface *intf)
2820 2822
2821/* table of devices that work with this driver */ 2823/* table of devices that work with this driver */
2822static struct usb_device_id rtl8152_table[] = { 2824static struct usb_device_id rtl8152_table[] = {
2823 {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8152)}, 2825 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8152)},
2824 {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8153)}, 2826 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8153)},
2825 {REALTEK_USB_DEVICE(VENDOR_ID_SAMSUNG, PRODUCT_ID_SAMSUNG)}, 2827 {USB_DEVICE(VENDOR_ID_SAMSUNG, PRODUCT_ID_SAMSUNG)},
2826 {} 2828 {}
2827}; 2829};
2828 2830
diff --git a/drivers/net/usb/r815x.c b/drivers/net/usb/r815x.c
deleted file mode 100644
index f0a8791b7636..000000000000
--- a/drivers/net/usb/r815x.c
+++ /dev/null
@@ -1,248 +0,0 @@
1#include <linux/module.h>
2#include <linux/netdevice.h>
3#include <linux/mii.h>
4#include <linux/usb.h>
5#include <linux/usb/cdc.h>
6#include <linux/usb/usbnet.h>
7
8#define RTL815x_REQT_READ 0xc0
9#define RTL815x_REQT_WRITE 0x40
10#define RTL815x_REQ_GET_REGS 0x05
11#define RTL815x_REQ_SET_REGS 0x05
12
13#define MCU_TYPE_PLA 0x0100
14#define OCP_BASE 0xe86c
15#define BASE_MII 0xa400
16
17#define BYTE_EN_DWORD 0xff
18#define BYTE_EN_WORD 0x33
19#define BYTE_EN_BYTE 0x11
20
21#define R815x_PHY_ID 32
22#define REALTEK_VENDOR_ID 0x0bda
23
24
25static int pla_read_word(struct usb_device *udev, u16 index)
26{
27 int ret;
28 u8 shift = index & 2;
29 __le32 *tmp;
30
31 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
32 if (!tmp)
33 return -ENOMEM;
34
35 index &= ~3;
36
37 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
38 RTL815x_REQ_GET_REGS, RTL815x_REQT_READ,
39 index, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500);
40 if (ret < 0)
41 goto out2;
42
43 ret = __le32_to_cpu(*tmp);
44 ret >>= (shift * 8);
45 ret &= 0xffff;
46
47out2:
48 kfree(tmp);
49 return ret;
50}
51
52static int pla_write_word(struct usb_device *udev, u16 index, u32 data)
53{
54 __le32 *tmp;
55 u32 mask = 0xffff;
56 u16 byen = BYTE_EN_WORD;
57 u8 shift = index & 2;
58 int ret;
59
60 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
61 if (!tmp)
62 return -ENOMEM;
63
64 data &= mask;
65
66 if (shift) {
67 byen <<= shift;
68 mask <<= (shift * 8);
69 data <<= (shift * 8);
70 index &= ~3;
71 }
72
73 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
74 RTL815x_REQ_GET_REGS, RTL815x_REQT_READ,
75 index, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500);
76 if (ret < 0)
77 goto out3;
78
79 data |= __le32_to_cpu(*tmp) & ~mask;
80 *tmp = __cpu_to_le32(data);
81
82 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
83 RTL815x_REQ_SET_REGS, RTL815x_REQT_WRITE,
84 index, MCU_TYPE_PLA | byen, tmp, sizeof(*tmp),
85 500);
86
87out3:
88 kfree(tmp);
89 return ret;
90}
91
92static int ocp_reg_read(struct usbnet *dev, u16 addr)
93{
94 u16 ocp_base, ocp_index;
95 int ret;
96
97 ocp_base = addr & 0xf000;
98 ret = pla_write_word(dev->udev, OCP_BASE, ocp_base);
99 if (ret < 0)
100 goto out;
101
102 ocp_index = (addr & 0x0fff) | 0xb000;
103 ret = pla_read_word(dev->udev, ocp_index);
104
105out:
106 return ret;
107}
108
109static int ocp_reg_write(struct usbnet *dev, u16 addr, u16 data)
110{
111 u16 ocp_base, ocp_index;
112 int ret;
113
114 ocp_base = addr & 0xf000;
115 ret = pla_write_word(dev->udev, OCP_BASE, ocp_base);
116 if (ret < 0)
117 goto out1;
118
119 ocp_index = (addr & 0x0fff) | 0xb000;
120 ret = pla_write_word(dev->udev, ocp_index, data);
121
122out1:
123 return ret;
124}
125
126static int r815x_mdio_read(struct net_device *netdev, int phy_id, int reg)
127{
128 struct usbnet *dev = netdev_priv(netdev);
129 int ret;
130
131 if (phy_id != R815x_PHY_ID)
132 return -EINVAL;
133
134 if (usb_autopm_get_interface(dev->intf) < 0)
135 return -ENODEV;
136
137 ret = ocp_reg_read(dev, BASE_MII + reg * 2);
138
139 usb_autopm_put_interface(dev->intf);
140 return ret;
141}
142
143static
144void r815x_mdio_write(struct net_device *netdev, int phy_id, int reg, int val)
145{
146 struct usbnet *dev = netdev_priv(netdev);
147
148 if (phy_id != R815x_PHY_ID)
149 return;
150
151 if (usb_autopm_get_interface(dev->intf) < 0)
152 return;
153
154 ocp_reg_write(dev, BASE_MII + reg * 2, val);
155
156 usb_autopm_put_interface(dev->intf);
157}
158
159static int r8153_bind(struct usbnet *dev, struct usb_interface *intf)
160{
161 int status;
162
163 status = usbnet_cdc_bind(dev, intf);
164 if (status < 0)
165 return status;
166
167 dev->mii.dev = dev->net;
168 dev->mii.mdio_read = r815x_mdio_read;
169 dev->mii.mdio_write = r815x_mdio_write;
170 dev->mii.phy_id_mask = 0x3f;
171 dev->mii.reg_num_mask = 0x1f;
172 dev->mii.phy_id = R815x_PHY_ID;
173 dev->mii.supports_gmii = 1;
174
175 return status;
176}
177
178static int r8152_bind(struct usbnet *dev, struct usb_interface *intf)
179{
180 int status;
181
182 status = usbnet_cdc_bind(dev, intf);
183 if (status < 0)
184 return status;
185
186 dev->mii.dev = dev->net;
187 dev->mii.mdio_read = r815x_mdio_read;
188 dev->mii.mdio_write = r815x_mdio_write;
189 dev->mii.phy_id_mask = 0x3f;
190 dev->mii.reg_num_mask = 0x1f;
191 dev->mii.phy_id = R815x_PHY_ID;
192 dev->mii.supports_gmii = 0;
193
194 return status;
195}
196
197static const struct driver_info r8152_info = {
198 .description = "RTL8152 ECM Device",
199 .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
200 .bind = r8152_bind,
201 .unbind = usbnet_cdc_unbind,
202 .status = usbnet_cdc_status,
203 .manage_power = usbnet_manage_power,
204};
205
206static const struct driver_info r8153_info = {
207 .description = "RTL8153 ECM Device",
208 .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
209 .bind = r8153_bind,
210 .unbind = usbnet_cdc_unbind,
211 .status = usbnet_cdc_status,
212 .manage_power = usbnet_manage_power,
213};
214
215static const struct usb_device_id products[] = {
216{
217 USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8152, USB_CLASS_COMM,
218 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
219 .driver_info = (unsigned long) &r8152_info,
220},
221
222{
223 USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8153, USB_CLASS_COMM,
224 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
225 .driver_info = (unsigned long) &r8153_info,
226},
227
228 { }, /* END */
229};
230MODULE_DEVICE_TABLE(usb, products);
231
232static struct usb_driver r815x_driver = {
233 .name = "r815x",
234 .id_table = products,
235 .probe = usbnet_probe,
236 .disconnect = usbnet_disconnect,
237 .suspend = usbnet_suspend,
238 .resume = usbnet_resume,
239 .reset_resume = usbnet_resume,
240 .supports_autosuspend = 1,
241 .disable_hub_initiated_lpm = 1,
242};
243
244module_usb_driver(r815x_driver);
245
246MODULE_AUTHOR("Hayes Wang");
247MODULE_DESCRIPTION("Realtek USB ECM device");
248MODULE_LICENSE("GPL");
diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c
index a48bc0f20c1a..524a47a28120 100644
--- a/drivers/net/usb/rndis_host.c
+++ b/drivers/net/usb/rndis_host.c
@@ -492,6 +492,10 @@ EXPORT_SYMBOL_GPL(rndis_unbind);
492 */ 492 */
493int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 493int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
494{ 494{
495 /* This check is no longer done by usbnet */
496 if (skb->len < dev->net->hard_header_len)
497 return 0;
498
495 /* peripheral may have batched packets to us... */ 499 /* peripheral may have batched packets to us... */
496 while (likely(skb->len)) { 500 while (likely(skb->len)) {
497 struct rndis_data_hdr *hdr = (void *)skb->data; 501 struct rndis_data_hdr *hdr = (void *)skb->data;
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index f17b9e02dd34..d9e7892262fa 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -2106,6 +2106,10 @@ static void smsc75xx_rx_csum_offload(struct usbnet *dev, struct sk_buff *skb,
2106 2106
2107static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 2107static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
2108{ 2108{
2109 /* This check is no longer done by usbnet */
2110 if (skb->len < dev->net->hard_header_len)
2111 return 0;
2112
2109 while (skb->len > 0) { 2113 while (skb->len > 0) {
2110 u32 rx_cmd_a, rx_cmd_b, align_count, size; 2114 u32 rx_cmd_a, rx_cmd_b, align_count, size;
2111 struct sk_buff *ax_skb; 2115 struct sk_buff *ax_skb;
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 8dd54a0f7b29..424db65e4396 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1723,6 +1723,10 @@ static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
1723 1723
1724static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 1724static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1725{ 1725{
1726 /* This check is no longer done by usbnet */
1727 if (skb->len < dev->net->hard_header_len)
1728 return 0;
1729
1726 while (skb->len > 0) { 1730 while (skb->len > 0) {
1727 u32 header, align_count; 1731 u32 header, align_count;
1728 struct sk_buff *ax_skb; 1732 struct sk_buff *ax_skb;
diff --git a/drivers/net/usb/sr9800.c b/drivers/net/usb/sr9800.c
new file mode 100644
index 000000000000..b94a0fbb8b3b
--- /dev/null
+++ b/drivers/net/usb/sr9800.c
@@ -0,0 +1,874 @@
1/* CoreChip-sz SR9800 one chip USB 2.0 Ethernet Devices
2 *
3 * Author : Liu Junliang <liujunliang_ljl@163.com>
4 *
5 * Based on asix_common.c, asix_devices.c
6 *
7 * This file is licensed under the terms of the GNU General Public License
8 * version 2. This program is licensed "as is" without any warranty of any
9 * kind, whether express or implied.*
10 */
11
12#include <linux/module.h>
13#include <linux/kmod.h>
14#include <linux/init.h>
15#include <linux/netdevice.h>
16#include <linux/etherdevice.h>
17#include <linux/ethtool.h>
18#include <linux/workqueue.h>
19#include <linux/mii.h>
20#include <linux/usb.h>
21#include <linux/crc32.h>
22#include <linux/usb/usbnet.h>
23#include <linux/slab.h>
24#include <linux/if_vlan.h>
25
26#include "sr9800.h"
27
28static int sr_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
29 u16 size, void *data)
30{
31 int err;
32
33 err = usbnet_read_cmd(dev, cmd, SR_REQ_RD_REG, value, index,
34 data, size);
35 if ((err != size) && (err >= 0))
36 err = -EINVAL;
37
38 return err;
39}
40
41static int sr_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
42 u16 size, void *data)
43{
44 int err;
45
46 err = usbnet_write_cmd(dev, cmd, SR_REQ_WR_REG, value, index,
47 data, size);
48 if ((err != size) && (err >= 0))
49 err = -EINVAL;
50
51 return err;
52}
53
54static void
55sr_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
56 u16 size, void *data)
57{
58 usbnet_write_cmd_async(dev, cmd, SR_REQ_WR_REG, value, index, data,
59 size);
60}
61
62static int sr_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
63{
64 int offset = 0;
65
66 /* This check is no longer done by usbnet */
67 if (skb->len < dev->net->hard_header_len)
68 return 0;
69
70 while (offset + sizeof(u32) < skb->len) {
71 struct sk_buff *sr_skb;
72 u16 size;
73 u32 header = get_unaligned_le32(skb->data + offset);
74
75 offset += sizeof(u32);
76 /* get the packet length */
77 size = (u16) (header & 0x7ff);
78 if (size != ((~header >> 16) & 0x07ff)) {
79 netdev_err(dev->net, "%s : Bad Header Length\n",
80 __func__);
81 return 0;
82 }
83
84 if ((size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) ||
85 (size + offset > skb->len)) {
86 netdev_err(dev->net, "%s : Bad RX Length %d\n",
87 __func__, size);
88 return 0;
89 }
90 sr_skb = netdev_alloc_skb_ip_align(dev->net, size);
91 if (!sr_skb)
92 return 0;
93
94 skb_put(sr_skb, size);
95 memcpy(sr_skb->data, skb->data + offset, size);
96 usbnet_skb_return(dev, sr_skb);
97
98 offset += (size + 1) & 0xfffe;
99 }
100
101 if (skb->len != offset) {
102 netdev_err(dev->net, "%s : Bad SKB Length %d\n", __func__,
103 skb->len);
104 return 0;
105 }
106
107 return 1;
108}
109
110static struct sk_buff *sr_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
111 gfp_t flags)
112{
113 int headroom = skb_headroom(skb);
114 int tailroom = skb_tailroom(skb);
115 u32 padbytes = 0xffff0000;
116 u32 packet_len;
117 int padlen;
118
119 padlen = ((skb->len + 4) % (dev->maxpacket - 1)) ? 0 : 4;
120
121 if ((!skb_cloned(skb)) && ((headroom + tailroom) >= (4 + padlen))) {
122 if ((headroom < 4) || (tailroom < padlen)) {
123 skb->data = memmove(skb->head + 4, skb->data,
124 skb->len);
125 skb_set_tail_pointer(skb, skb->len);
126 }
127 } else {
128 struct sk_buff *skb2;
129 skb2 = skb_copy_expand(skb, 4, padlen, flags);
130 dev_kfree_skb_any(skb);
131 skb = skb2;
132 if (!skb)
133 return NULL;
134 }
135
136 skb_push(skb, 4);
137 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
138 cpu_to_le32s(&packet_len);
139 skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
140
141 if (padlen) {
142 cpu_to_le32s(&padbytes);
143 memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
144 skb_put(skb, sizeof(padbytes));
145 }
146
147 return skb;
148}
149
150static void sr_status(struct usbnet *dev, struct urb *urb)
151{
152 struct sr9800_int_data *event;
153 int link;
154
155 if (urb->actual_length < 8)
156 return;
157
158 event = urb->transfer_buffer;
159 link = event->link & 0x01;
160 if (netif_carrier_ok(dev->net) != link) {
161 usbnet_link_change(dev, link, 1);
162 netdev_dbg(dev->net, "Link Status is: %d\n", link);
163 }
164
165 return;
166}
167
168static inline int sr_set_sw_mii(struct usbnet *dev)
169{
170 int ret;
171
172 ret = sr_write_cmd(dev, SR_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
173 if (ret < 0)
174 netdev_err(dev->net, "Failed to enable software MII access\n");
175 return ret;
176}
177
178static inline int sr_set_hw_mii(struct usbnet *dev)
179{
180 int ret;
181
182 ret = sr_write_cmd(dev, SR_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
183 if (ret < 0)
184 netdev_err(dev->net, "Failed to enable hardware MII access\n");
185 return ret;
186}
187
188static inline int sr_get_phy_addr(struct usbnet *dev)
189{
190 u8 buf[2];
191 int ret;
192
193 ret = sr_read_cmd(dev, SR_CMD_READ_PHY_ID, 0, 0, 2, buf);
194 if (ret < 0) {
195 netdev_err(dev->net, "%s : Error reading PHYID register:%02x\n",
196 __func__, ret);
197 goto out;
198 }
199 netdev_dbg(dev->net, "%s : returning 0x%04x\n", __func__,
200 *((__le16 *)buf));
201
202 ret = buf[1];
203
204out:
205 return ret;
206}
207
208static int sr_sw_reset(struct usbnet *dev, u8 flags)
209{
210 int ret;
211
212 ret = sr_write_cmd(dev, SR_CMD_SW_RESET, flags, 0, 0, NULL);
213 if (ret < 0)
214 netdev_err(dev->net, "Failed to send software reset:%02x\n",
215 ret);
216
217 return ret;
218}
219
220static u16 sr_read_rx_ctl(struct usbnet *dev)
221{
222 __le16 v;
223 int ret;
224
225 ret = sr_read_cmd(dev, SR_CMD_READ_RX_CTL, 0, 0, 2, &v);
226 if (ret < 0) {
227 netdev_err(dev->net, "Error reading RX_CTL register:%02x\n",
228 ret);
229 goto out;
230 }
231
232 ret = le16_to_cpu(v);
233out:
234 return ret;
235}
236
237static int sr_write_rx_ctl(struct usbnet *dev, u16 mode)
238{
239 int ret;
240
241 netdev_dbg(dev->net, "%s : mode = 0x%04x\n", __func__, mode);
242 ret = sr_write_cmd(dev, SR_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
243 if (ret < 0)
244 netdev_err(dev->net,
245 "Failed to write RX_CTL mode to 0x%04x:%02x\n",
246 mode, ret);
247
248 return ret;
249}
250
251static u16 sr_read_medium_status(struct usbnet *dev)
252{
253 __le16 v;
254 int ret;
255
256 ret = sr_read_cmd(dev, SR_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
257 if (ret < 0) {
258 netdev_err(dev->net,
259 "Error reading Medium Status register:%02x\n", ret);
260 return ret; /* TODO: callers not checking for error ret */
261 }
262
263 return le16_to_cpu(v);
264}
265
266static int sr_write_medium_mode(struct usbnet *dev, u16 mode)
267{
268 int ret;
269
270 netdev_dbg(dev->net, "%s : mode = 0x%04x\n", __func__, mode);
271 ret = sr_write_cmd(dev, SR_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
272 if (ret < 0)
273 netdev_err(dev->net,
274 "Failed to write Medium Mode mode to 0x%04x:%02x\n",
275 mode, ret);
276 return ret;
277}
278
279static int sr_write_gpio(struct usbnet *dev, u16 value, int sleep)
280{
281 int ret;
282
283 netdev_dbg(dev->net, "%s : value = 0x%04x\n", __func__, value);
284 ret = sr_write_cmd(dev, SR_CMD_WRITE_GPIOS, value, 0, 0, NULL);
285 if (ret < 0)
286 netdev_err(dev->net, "Failed to write GPIO value 0x%04x:%02x\n",
287 value, ret);
288 if (sleep)
289 msleep(sleep);
290
291 return ret;
292}
293
294/* SR9800 have a 16-bit RX_CTL value */
295static void sr_set_multicast(struct net_device *net)
296{
297 struct usbnet *dev = netdev_priv(net);
298 struct sr_data *data = (struct sr_data *)&dev->data;
299 u16 rx_ctl = SR_DEFAULT_RX_CTL;
300
301 if (net->flags & IFF_PROMISC) {
302 rx_ctl |= SR_RX_CTL_PRO;
303 } else if (net->flags & IFF_ALLMULTI ||
304 netdev_mc_count(net) > SR_MAX_MCAST) {
305 rx_ctl |= SR_RX_CTL_AMALL;
306 } else if (netdev_mc_empty(net)) {
307 /* just broadcast and directed */
308 } else {
309 /* We use the 20 byte dev->data
310 * for our 8 byte filter buffer
311 * to avoid allocating memory that
312 * is tricky to free later
313 */
314 struct netdev_hw_addr *ha;
315 u32 crc_bits;
316
317 memset(data->multi_filter, 0, SR_MCAST_FILTER_SIZE);
318
319 /* Build the multicast hash filter. */
320 netdev_for_each_mc_addr(ha, net) {
321 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
322 data->multi_filter[crc_bits >> 3] |=
323 1 << (crc_bits & 7);
324 }
325
326 sr_write_cmd_async(dev, SR_CMD_WRITE_MULTI_FILTER, 0, 0,
327 SR_MCAST_FILTER_SIZE, data->multi_filter);
328
329 rx_ctl |= SR_RX_CTL_AM;
330 }
331
332 sr_write_cmd_async(dev, SR_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
333}
334
335static int sr_mdio_read(struct net_device *net, int phy_id, int loc)
336{
337 struct usbnet *dev = netdev_priv(net);
338 __le16 res;
339
340 mutex_lock(&dev->phy_mutex);
341 sr_set_sw_mii(dev);
342 sr_read_cmd(dev, SR_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, &res);
343 sr_set_hw_mii(dev);
344 mutex_unlock(&dev->phy_mutex);
345
346 netdev_dbg(dev->net,
347 "%s : phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", __func__,
348 phy_id, loc, le16_to_cpu(res));
349
350 return le16_to_cpu(res);
351}
352
353static void
354sr_mdio_write(struct net_device *net, int phy_id, int loc, int val)
355{
356 struct usbnet *dev = netdev_priv(net);
357 __le16 res = cpu_to_le16(val);
358
359 netdev_dbg(dev->net,
360 "%s : phy_id=0x%02x, loc=0x%02x, val=0x%04x\n", __func__,
361 phy_id, loc, val);
362 mutex_lock(&dev->phy_mutex);
363 sr_set_sw_mii(dev);
364 sr_write_cmd(dev, SR_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
365 sr_set_hw_mii(dev);
366 mutex_unlock(&dev->phy_mutex);
367}
368
369/* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
370static u32 sr_get_phyid(struct usbnet *dev)
371{
372 int phy_reg;
373 u32 phy_id;
374 int i;
375
376 /* Poll for the rare case the FW or phy isn't ready yet. */
377 for (i = 0; i < 100; i++) {
378 phy_reg = sr_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
379 if (phy_reg != 0 && phy_reg != 0xFFFF)
380 break;
381 mdelay(1);
382 }
383
384 if (phy_reg <= 0 || phy_reg == 0xFFFF)
385 return 0;
386
387 phy_id = (phy_reg & 0xffff) << 16;
388
389 phy_reg = sr_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
390 if (phy_reg < 0)
391 return 0;
392
393 phy_id |= (phy_reg & 0xffff);
394
395 return phy_id;
396}
397
398static void
399sr_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
400{
401 struct usbnet *dev = netdev_priv(net);
402 u8 opt;
403
404 if (sr_read_cmd(dev, SR_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
405 wolinfo->supported = 0;
406 wolinfo->wolopts = 0;
407 return;
408 }
409 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
410 wolinfo->wolopts = 0;
411 if (opt & SR_MONITOR_LINK)
412 wolinfo->wolopts |= WAKE_PHY;
413 if (opt & SR_MONITOR_MAGIC)
414 wolinfo->wolopts |= WAKE_MAGIC;
415}
416
417static int
418sr_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
419{
420 struct usbnet *dev = netdev_priv(net);
421 u8 opt = 0;
422
423 if (wolinfo->wolopts & WAKE_PHY)
424 opt |= SR_MONITOR_LINK;
425 if (wolinfo->wolopts & WAKE_MAGIC)
426 opt |= SR_MONITOR_MAGIC;
427
428 if (sr_write_cmd(dev, SR_CMD_WRITE_MONITOR_MODE,
429 opt, 0, 0, NULL) < 0)
430 return -EINVAL;
431
432 return 0;
433}
434
435static int sr_get_eeprom_len(struct net_device *net)
436{
437 struct usbnet *dev = netdev_priv(net);
438 struct sr_data *data = (struct sr_data *)&dev->data;
439
440 return data->eeprom_len;
441}
442
443static int sr_get_eeprom(struct net_device *net,
444 struct ethtool_eeprom *eeprom, u8 *data)
445{
446 struct usbnet *dev = netdev_priv(net);
447 __le16 *ebuf = (__le16 *)data;
448 int ret;
449 int i;
450
451 /* Crude hack to ensure that we don't overwrite memory
452 * if an odd length is supplied
453 */
454 if (eeprom->len % 2)
455 return -EINVAL;
456
457 eeprom->magic = SR_EEPROM_MAGIC;
458
459 /* sr9800 returns 2 bytes from eeprom on read */
460 for (i = 0; i < eeprom->len / 2; i++) {
461 ret = sr_read_cmd(dev, SR_CMD_READ_EEPROM, eeprom->offset + i,
462 0, 2, &ebuf[i]);
463 if (ret < 0)
464 return -EINVAL;
465 }
466 return 0;
467}
468
469static void sr_get_drvinfo(struct net_device *net,
470 struct ethtool_drvinfo *info)
471{
472 struct usbnet *dev = netdev_priv(net);
473 struct sr_data *data = (struct sr_data *)&dev->data;
474
475 /* Inherit standard device info */
476 usbnet_get_drvinfo(net, info);
477 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver));
478 strncpy(info->version, DRIVER_VERSION, sizeof(info->version));
479 info->eedump_len = data->eeprom_len;
480}
481
482static u32 sr_get_link(struct net_device *net)
483{
484 struct usbnet *dev = netdev_priv(net);
485
486 return mii_link_ok(&dev->mii);
487}
488
489static int sr_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
490{
491 struct usbnet *dev = netdev_priv(net);
492
493 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
494}
495
496static int sr_set_mac_address(struct net_device *net, void *p)
497{
498 struct usbnet *dev = netdev_priv(net);
499 struct sr_data *data = (struct sr_data *)&dev->data;
500 struct sockaddr *addr = p;
501
502 if (netif_running(net))
503 return -EBUSY;
504 if (!is_valid_ether_addr(addr->sa_data))
505 return -EADDRNOTAVAIL;
506
507 memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
508
509 /* We use the 20 byte dev->data
510 * for our 6 byte mac buffer
511 * to avoid allocating memory that
512 * is tricky to free later
513 */
514 memcpy(data->mac_addr, addr->sa_data, ETH_ALEN);
515 sr_write_cmd_async(dev, SR_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
516 data->mac_addr);
517
518 return 0;
519}
520
521static const struct ethtool_ops sr9800_ethtool_ops = {
522 .get_drvinfo = sr_get_drvinfo,
523 .get_link = sr_get_link,
524 .get_msglevel = usbnet_get_msglevel,
525 .set_msglevel = usbnet_set_msglevel,
526 .get_wol = sr_get_wol,
527 .set_wol = sr_set_wol,
528 .get_eeprom_len = sr_get_eeprom_len,
529 .get_eeprom = sr_get_eeprom,
530 .get_settings = usbnet_get_settings,
531 .set_settings = usbnet_set_settings,
532 .nway_reset = usbnet_nway_reset,
533};
534
535static int sr9800_link_reset(struct usbnet *dev)
536{
537 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
538 u16 mode;
539
540 mii_check_media(&dev->mii, 1, 1);
541 mii_ethtool_gset(&dev->mii, &ecmd);
542 mode = SR9800_MEDIUM_DEFAULT;
543
544 if (ethtool_cmd_speed(&ecmd) != SPEED_100)
545 mode &= ~SR_MEDIUM_PS;
546
547 if (ecmd.duplex != DUPLEX_FULL)
548 mode &= ~SR_MEDIUM_FD;
549
550 netdev_dbg(dev->net, "%s : speed: %u duplex: %d mode: 0x%04x\n",
551 __func__, ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
552
553 sr_write_medium_mode(dev, mode);
554
555 return 0;
556}
557
558
559static int sr9800_set_default_mode(struct usbnet *dev)
560{
561 u16 rx_ctl;
562 int ret;
563
564 sr_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
565 sr_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
566 ADVERTISE_ALL | ADVERTISE_CSMA);
567 mii_nway_restart(&dev->mii);
568
569 ret = sr_write_medium_mode(dev, SR9800_MEDIUM_DEFAULT);
570 if (ret < 0)
571 goto out;
572
573 ret = sr_write_cmd(dev, SR_CMD_WRITE_IPG012,
574 SR9800_IPG0_DEFAULT | SR9800_IPG1_DEFAULT,
575 SR9800_IPG2_DEFAULT, 0, NULL);
576 if (ret < 0) {
577 netdev_dbg(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
578 goto out;
579 }
580
581 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
582 ret = sr_write_rx_ctl(dev, SR_DEFAULT_RX_CTL);
583 if (ret < 0)
584 goto out;
585
586 rx_ctl = sr_read_rx_ctl(dev);
587 netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
588 rx_ctl);
589
590 rx_ctl = sr_read_medium_status(dev);
591 netdev_dbg(dev->net, "Medium Status:0x%04x after all initializations\n",
592 rx_ctl);
593
594 return 0;
595out:
596 return ret;
597}
598
599static int sr9800_reset(struct usbnet *dev)
600{
601 struct sr_data *data = (struct sr_data *)&dev->data;
602 int ret, embd_phy;
603 u16 rx_ctl;
604
605 ret = sr_write_gpio(dev,
606 SR_GPIO_RSE | SR_GPIO_GPO_2 | SR_GPIO_GPO2EN, 5);
607 if (ret < 0)
608 goto out;
609
610 embd_phy = ((sr_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
611
612 ret = sr_write_cmd(dev, SR_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
613 if (ret < 0) {
614 netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
615 goto out;
616 }
617
618 ret = sr_sw_reset(dev, SR_SWRESET_IPPD | SR_SWRESET_PRL);
619 if (ret < 0)
620 goto out;
621
622 msleep(150);
623
624 ret = sr_sw_reset(dev, SR_SWRESET_CLEAR);
625 if (ret < 0)
626 goto out;
627
628 msleep(150);
629
630 if (embd_phy) {
631 ret = sr_sw_reset(dev, SR_SWRESET_IPRL);
632 if (ret < 0)
633 goto out;
634 } else {
635 ret = sr_sw_reset(dev, SR_SWRESET_PRTE);
636 if (ret < 0)
637 goto out;
638 }
639
640 msleep(150);
641 rx_ctl = sr_read_rx_ctl(dev);
642 netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
643 ret = sr_write_rx_ctl(dev, 0x0000);
644 if (ret < 0)
645 goto out;
646
647 rx_ctl = sr_read_rx_ctl(dev);
648 netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
649
650 ret = sr_sw_reset(dev, SR_SWRESET_PRL);
651 if (ret < 0)
652 goto out;
653
654 msleep(150);
655
656 ret = sr_sw_reset(dev, SR_SWRESET_IPRL | SR_SWRESET_PRL);
657 if (ret < 0)
658 goto out;
659
660 msleep(150);
661
662 ret = sr9800_set_default_mode(dev);
663 if (ret < 0)
664 goto out;
665
666 /* Rewrite MAC address */
667 memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
668 ret = sr_write_cmd(dev, SR_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
669 data->mac_addr);
670 if (ret < 0)
671 goto out;
672
673 return 0;
674
675out:
676 return ret;
677}
678
679static const struct net_device_ops sr9800_netdev_ops = {
680 .ndo_open = usbnet_open,
681 .ndo_stop = usbnet_stop,
682 .ndo_start_xmit = usbnet_start_xmit,
683 .ndo_tx_timeout = usbnet_tx_timeout,
684 .ndo_change_mtu = usbnet_change_mtu,
685 .ndo_set_mac_address = sr_set_mac_address,
686 .ndo_validate_addr = eth_validate_addr,
687 .ndo_do_ioctl = sr_ioctl,
688 .ndo_set_rx_mode = sr_set_multicast,
689};
690
691static int sr9800_phy_powerup(struct usbnet *dev)
692{
693 int ret;
694
695 /* set the embedded Ethernet PHY in power-down state */
696 ret = sr_sw_reset(dev, SR_SWRESET_IPPD | SR_SWRESET_IPRL);
697 if (ret < 0) {
698 netdev_err(dev->net, "Failed to power down PHY : %d\n", ret);
699 return ret;
700 }
701 msleep(20);
702
703 /* set the embedded Ethernet PHY in power-up state */
704 ret = sr_sw_reset(dev, SR_SWRESET_IPRL);
705 if (ret < 0) {
706 netdev_err(dev->net, "Failed to reset PHY: %d\n", ret);
707 return ret;
708 }
709 msleep(600);
710
711 /* set the embedded Ethernet PHY in reset state */
712 ret = sr_sw_reset(dev, SR_SWRESET_CLEAR);
713 if (ret < 0) {
714 netdev_err(dev->net, "Failed to power up PHY: %d\n", ret);
715 return ret;
716 }
717 msleep(20);
718
719 /* set the embedded Ethernet PHY in power-up state */
720 ret = sr_sw_reset(dev, SR_SWRESET_IPRL);
721 if (ret < 0) {
722 netdev_err(dev->net, "Failed to reset PHY: %d\n", ret);
723 return ret;
724 }
725
726 return 0;
727}
728
729static int sr9800_bind(struct usbnet *dev, struct usb_interface *intf)
730{
731 struct sr_data *data = (struct sr_data *)&dev->data;
732 u16 led01_mux, led23_mux;
733 int ret, embd_phy;
734 u32 phyid;
735 u16 rx_ctl;
736
737 data->eeprom_len = SR9800_EEPROM_LEN;
738
739 usbnet_get_endpoints(dev, intf);
740
741 /* LED Setting Rule :
742 * AABB:CCDD
743 * AA : MFA0(LED0)
744 * BB : MFA1(LED1)
745 * CC : MFA2(LED2), Reserved for SR9800
746 * DD : MFA3(LED3), Reserved for SR9800
747 */
748 led01_mux = (SR_LED_MUX_LINK_ACTIVE << 8) | SR_LED_MUX_LINK;
749 led23_mux = (SR_LED_MUX_LINK_ACTIVE << 8) | SR_LED_MUX_TX_ACTIVE;
750 ret = sr_write_cmd(dev, SR_CMD_LED_MUX, led01_mux, led23_mux, 0, NULL);
751 if (ret < 0) {
752 netdev_err(dev->net, "set LINK LED failed : %d\n", ret);
753 goto out;
754 }
755
756 /* Get the MAC address */
757 ret = sr_read_cmd(dev, SR_CMD_READ_NODE_ID, 0, 0, ETH_ALEN,
758 dev->net->dev_addr);
759 if (ret < 0) {
760 netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
761 return ret;
762 }
763 netdev_dbg(dev->net, "mac addr : %pM\n", dev->net->dev_addr);
764
765 /* Initialize MII structure */
766 dev->mii.dev = dev->net;
767 dev->mii.mdio_read = sr_mdio_read;
768 dev->mii.mdio_write = sr_mdio_write;
769 dev->mii.phy_id_mask = 0x1f;
770 dev->mii.reg_num_mask = 0x1f;
771 dev->mii.phy_id = sr_get_phy_addr(dev);
772
773 dev->net->netdev_ops = &sr9800_netdev_ops;
774 dev->net->ethtool_ops = &sr9800_ethtool_ops;
775
776 embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
777 /* Reset the PHY to normal operation mode */
778 ret = sr_write_cmd(dev, SR_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
779 if (ret < 0) {
780 netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
781 return ret;
782 }
783
784 /* Init PHY routine */
785 ret = sr9800_phy_powerup(dev);
786 if (ret < 0)
787 goto out;
788
789 rx_ctl = sr_read_rx_ctl(dev);
790 netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
791 ret = sr_write_rx_ctl(dev, 0x0000);
792 if (ret < 0)
793 goto out;
794
795 rx_ctl = sr_read_rx_ctl(dev);
796 netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
797
798 /* Read PHYID register *AFTER* the PHY was reset properly */
799 phyid = sr_get_phyid(dev);
800 netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
801
802 /* medium mode setting */
803 ret = sr9800_set_default_mode(dev);
804 if (ret < 0)
805 goto out;
806
807 if (dev->udev->speed == USB_SPEED_HIGH) {
808 ret = sr_write_cmd(dev, SR_CMD_BULKIN_SIZE,
809 SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_4K].byte_cnt,
810 SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_4K].threshold,
811 0, NULL);
812 if (ret < 0) {
813 netdev_err(dev->net, "Reset RX_CTL failed: %d\n", ret);
814 goto out;
815 }
816 dev->rx_urb_size =
817 SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_4K].size;
818 } else {
819 ret = sr_write_cmd(dev, SR_CMD_BULKIN_SIZE,
820 SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_2K].byte_cnt,
821 SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_2K].threshold,
822 0, NULL);
823 if (ret < 0) {
824 netdev_err(dev->net, "Reset RX_CTL failed: %d\n", ret);
825 goto out;
826 }
827 dev->rx_urb_size =
828 SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_2K].size;
829 }
830 netdev_dbg(dev->net, "%s : setting rx_urb_size with : %zu\n", __func__,
831 dev->rx_urb_size);
832 return 0;
833
834out:
835 return ret;
836}
837
838static const struct driver_info sr9800_driver_info = {
839 .description = "CoreChip SR9800 USB 2.0 Ethernet",
840 .bind = sr9800_bind,
841 .status = sr_status,
842 .link_reset = sr9800_link_reset,
843 .reset = sr9800_reset,
844 .flags = DRIVER_FLAG,
845 .rx_fixup = sr_rx_fixup,
846 .tx_fixup = sr_tx_fixup,
847};
848
849static const struct usb_device_id products[] = {
850 {
851 USB_DEVICE(0x0fe6, 0x9800), /* SR9800 Device */
852 .driver_info = (unsigned long) &sr9800_driver_info,
853 },
854 {}, /* END */
855};
856
857MODULE_DEVICE_TABLE(usb, products);
858
859static struct usb_driver sr_driver = {
860 .name = DRIVER_NAME,
861 .id_table = products,
862 .probe = usbnet_probe,
863 .suspend = usbnet_suspend,
864 .resume = usbnet_resume,
865 .disconnect = usbnet_disconnect,
866 .supports_autosuspend = 1,
867};
868
869module_usb_driver(sr_driver);
870
871MODULE_AUTHOR("Liu Junliang <liujunliang_ljl@163.com");
872MODULE_VERSION(DRIVER_VERSION);
873MODULE_DESCRIPTION("SR9800 USB 2.0 USB2NET Dev : http://www.corechip-sz.com");
874MODULE_LICENSE("GPL");
diff --git a/drivers/net/usb/sr9800.h b/drivers/net/usb/sr9800.h
new file mode 100644
index 000000000000..18f670251275
--- /dev/null
+++ b/drivers/net/usb/sr9800.h
@@ -0,0 +1,202 @@
1/* CoreChip-sz SR9800 one chip USB 2.0 Ethernet Devices
2 *
3 * Author : Liu Junliang <liujunliang_ljl@163.com>
4 *
5 * This file is licensed under the terms of the GNU General Public License
6 * version 2. This program is licensed "as is" without any warranty of any
7 * kind, whether express or implied.
8 */
9
10#ifndef _SR9800_H
11#define _SR9800_H
12
13/* SR9800 spec. command table on Linux Platform */
14
15/* command : Software Station Management Control Reg */
16#define SR_CMD_SET_SW_MII 0x06
17/* command : PHY Read Reg */
18#define SR_CMD_READ_MII_REG 0x07
19/* command : PHY Write Reg */
20#define SR_CMD_WRITE_MII_REG 0x08
21/* command : Hardware Station Management Control Reg */
22#define SR_CMD_SET_HW_MII 0x0a
23/* command : SROM Read Reg */
24#define SR_CMD_READ_EEPROM 0x0b
25/* command : SROM Write Reg */
26#define SR_CMD_WRITE_EEPROM 0x0c
27/* command : SROM Write Enable Reg */
28#define SR_CMD_WRITE_ENABLE 0x0d
29/* command : SROM Write Disable Reg */
30#define SR_CMD_WRITE_DISABLE 0x0e
31/* command : RX Control Read Reg */
32#define SR_CMD_READ_RX_CTL 0x0f
33#define SR_RX_CTL_PRO (1 << 0)
34#define SR_RX_CTL_AMALL (1 << 1)
35#define SR_RX_CTL_SEP (1 << 2)
36#define SR_RX_CTL_AB (1 << 3)
37#define SR_RX_CTL_AM (1 << 4)
38#define SR_RX_CTL_AP (1 << 5)
39#define SR_RX_CTL_ARP (1 << 6)
40#define SR_RX_CTL_SO (1 << 7)
41#define SR_RX_CTL_RH1M (1 << 8)
42#define SR_RX_CTL_RH2M (1 << 9)
43#define SR_RX_CTL_RH3M (1 << 10)
44/* command : RX Control Write Reg */
45#define SR_CMD_WRITE_RX_CTL 0x10
46/* command : IPG0/IPG1/IPG2 Control Read Reg */
47#define SR_CMD_READ_IPG012 0x11
48/* command : IPG0/IPG1/IPG2 Control Write Reg */
49#define SR_CMD_WRITE_IPG012 0x12
50/* command : Node ID Read Reg */
51#define SR_CMD_READ_NODE_ID 0x13
52/* command : Node ID Write Reg */
53#define SR_CMD_WRITE_NODE_ID 0x14
54/* command : Multicast Filter Array Read Reg */
55#define SR_CMD_READ_MULTI_FILTER 0x15
56/* command : Multicast Filter Array Write Reg */
57#define SR_CMD_WRITE_MULTI_FILTER 0x16
58/* command : Eth/HomePNA PHY Address Reg */
59#define SR_CMD_READ_PHY_ID 0x19
60/* command : Medium Status Read Reg */
61#define SR_CMD_READ_MEDIUM_STATUS 0x1a
62#define SR_MONITOR_LINK (1 << 1)
63#define SR_MONITOR_MAGIC (1 << 2)
64#define SR_MONITOR_HSFS (1 << 4)
65/* command : Medium Status Write Reg */
66#define SR_CMD_WRITE_MEDIUM_MODE 0x1b
67#define SR_MEDIUM_GM (1 << 0)
68#define SR_MEDIUM_FD (1 << 1)
69#define SR_MEDIUM_AC (1 << 2)
70#define SR_MEDIUM_ENCK (1 << 3)
71#define SR_MEDIUM_RFC (1 << 4)
72#define SR_MEDIUM_TFC (1 << 5)
73#define SR_MEDIUM_JFE (1 << 6)
74#define SR_MEDIUM_PF (1 << 7)
75#define SR_MEDIUM_RE (1 << 8)
76#define SR_MEDIUM_PS (1 << 9)
77#define SR_MEDIUM_RSV (1 << 10)
78#define SR_MEDIUM_SBP (1 << 11)
79#define SR_MEDIUM_SM (1 << 12)
80/* command : Monitor Mode Status Read Reg */
81#define SR_CMD_READ_MONITOR_MODE 0x1c
82/* command : Monitor Mode Status Write Reg */
83#define SR_CMD_WRITE_MONITOR_MODE 0x1d
84/* command : GPIO Status Read Reg */
85#define SR_CMD_READ_GPIOS 0x1e
86#define SR_GPIO_GPO0EN (1 << 0) /* GPIO0 Output enable */
87#define SR_GPIO_GPO_0 (1 << 1) /* GPIO0 Output value */
88#define SR_GPIO_GPO1EN (1 << 2) /* GPIO1 Output enable */
89#define SR_GPIO_GPO_1 (1 << 3) /* GPIO1 Output value */
90#define SR_GPIO_GPO2EN (1 << 4) /* GPIO2 Output enable */
91#define SR_GPIO_GPO_2 (1 << 5) /* GPIO2 Output value */
92#define SR_GPIO_RESERVED (1 << 6) /* Reserved */
93#define SR_GPIO_RSE (1 << 7) /* Reload serial EEPROM */
94/* command : GPIO Status Write Reg */
95#define SR_CMD_WRITE_GPIOS 0x1f
96/* command : Eth PHY Power and Reset Control Reg */
97#define SR_CMD_SW_RESET 0x20
98#define SR_SWRESET_CLEAR 0x00
99#define SR_SWRESET_RR (1 << 0)
100#define SR_SWRESET_RT (1 << 1)
101#define SR_SWRESET_PRTE (1 << 2)
102#define SR_SWRESET_PRL (1 << 3)
103#define SR_SWRESET_BZ (1 << 4)
104#define SR_SWRESET_IPRL (1 << 5)
105#define SR_SWRESET_IPPD (1 << 6)
106/* command : Software Interface Selection Status Read Reg */
107#define SR_CMD_SW_PHY_STATUS 0x21
108/* command : Software Interface Selection Status Write Reg */
109#define SR_CMD_SW_PHY_SELECT 0x22
110/* command : BULK in Buffer Size Reg */
111#define SR_CMD_BULKIN_SIZE 0x2A
112/* command : LED_MUX Control Reg */
113#define SR_CMD_LED_MUX 0x70
114#define SR_LED_MUX_TX_ACTIVE (1 << 0)
115#define SR_LED_MUX_RX_ACTIVE (1 << 1)
116#define SR_LED_MUX_COLLISION (1 << 2)
117#define SR_LED_MUX_DUP_COL (1 << 3)
118#define SR_LED_MUX_DUP (1 << 4)
119#define SR_LED_MUX_SPEED (1 << 5)
120#define SR_LED_MUX_LINK_ACTIVE (1 << 6)
121#define SR_LED_MUX_LINK (1 << 7)
122
123/* Register Access Flags */
124#define SR_REQ_RD_REG (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
125#define SR_REQ_WR_REG (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
126
127/* Multicast Filter Array size & Max Number */
128#define SR_MCAST_FILTER_SIZE 8
129#define SR_MAX_MCAST 64
130
131/* IPG0/1/2 Default Value */
132#define SR9800_IPG0_DEFAULT 0x15
133#define SR9800_IPG1_DEFAULT 0x0c
134#define SR9800_IPG2_DEFAULT 0x12
135
136/* Medium Status Default Mode */
137#define SR9800_MEDIUM_DEFAULT \
138 (SR_MEDIUM_FD | SR_MEDIUM_RFC | \
139 SR_MEDIUM_TFC | SR_MEDIUM_PS | \
140 SR_MEDIUM_AC | SR_MEDIUM_RE)
141
142/* RX Control Default Setting */
143#define SR_DEFAULT_RX_CTL \
144 (SR_RX_CTL_SO | SR_RX_CTL_AB | SR_RX_CTL_RH1M)
145
146/* EEPROM Magic Number & EEPROM Size */
147#define SR_EEPROM_MAGIC 0xdeadbeef
148#define SR9800_EEPROM_LEN 0xff
149
150/* SR9800 Driver Version and Driver Name */
151#define DRIVER_VERSION "11-Nov-2013"
152#define DRIVER_NAME "CoreChips"
153#define DRIVER_FLAG \
154 (FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET)
155
156/* SR9800 BULKIN Buffer Size */
157#define SR9800_MAX_BULKIN_2K 0
158#define SR9800_MAX_BULKIN_4K 1
159#define SR9800_MAX_BULKIN_6K 2
160#define SR9800_MAX_BULKIN_8K 3
161#define SR9800_MAX_BULKIN_16K 4
162#define SR9800_MAX_BULKIN_20K 5
163#define SR9800_MAX_BULKIN_24K 6
164#define SR9800_MAX_BULKIN_32K 7
165
166struct {unsigned short size, byte_cnt, threshold; } SR9800_BULKIN_SIZE[] = {
167 /* 2k */
168 {2048, 0x8000, 0x8001},
169 /* 4k */
170 {4096, 0x8100, 0x8147},
171 /* 6k */
172 {6144, 0x8200, 0x81EB},
173 /* 8k */
174 {8192, 0x8300, 0x83D7},
175 /* 16 */
176 {16384, 0x8400, 0x851E},
177 /* 20k */
178 {20480, 0x8500, 0x8666},
179 /* 24k */
180 {24576, 0x8600, 0x87AE},
181 /* 32k */
182 {32768, 0x8700, 0x8A3D},
183};
184
185/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
186struct sr_data {
187 u8 multi_filter[SR_MCAST_FILTER_SIZE];
188 u8 mac_addr[ETH_ALEN];
189 u8 phymode;
190 u8 ledmode;
191 u8 eeprom_len;
192};
193
194struct sr9800_int_data {
195 __le16 res1;
196 u8 link;
197 __le16 res2;
198 u8 status;
199 __le16 res3;
200} __packed;
201
202#endif /* _SR9800_H */
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 4671da755e7b..f9e96c427558 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -542,17 +542,19 @@ static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
542 } 542 }
543 // else network stack removes extra byte if we forced a short packet 543 // else network stack removes extra byte if we forced a short packet
544 544
545 if (skb->len) { 545 /* all data was already cloned from skb inside the driver */
546 /* all data was already cloned from skb inside the driver */ 546 if (dev->driver_info->flags & FLAG_MULTI_PACKET)
547 if (dev->driver_info->flags & FLAG_MULTI_PACKET) 547 goto done;
548 dev_kfree_skb_any(skb); 548
549 else 549 if (skb->len < ETH_HLEN) {
550 usbnet_skb_return(dev, skb); 550 dev->net->stats.rx_errors++;
551 dev->net->stats.rx_length_errors++;
552 netif_dbg(dev, rx_err, dev->net, "rx length %d\n", skb->len);
553 } else {
554 usbnet_skb_return(dev, skb);
551 return; 555 return;
552 } 556 }
553 557
554 netif_dbg(dev, rx_err, dev->net, "drop\n");
555 dev->net->stats.rx_errors++;
556done: 558done:
557 skb_queue_tail(&dev->done, skb); 559 skb_queue_tail(&dev->done, skb);
558} 560}
@@ -574,13 +576,6 @@ static void rx_complete (struct urb *urb)
574 switch (urb_status) { 576 switch (urb_status) {
575 /* success */ 577 /* success */
576 case 0: 578 case 0:
577 if (skb->len < dev->net->hard_header_len) {
578 state = rx_cleanup;
579 dev->net->stats.rx_errors++;
580 dev->net->stats.rx_length_errors++;
581 netif_dbg(dev, rx_err, dev->net,
582 "rx length %d\n", skb->len);
583 }
584 break; 579 break;
585 580
586 /* stalls need manual reset. this is rare ... except that 581 /* stalls need manual reset. this is rare ... except that
@@ -757,14 +752,12 @@ EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs);
757// precondition: never called in_interrupt 752// precondition: never called in_interrupt
758static void usbnet_terminate_urbs(struct usbnet *dev) 753static void usbnet_terminate_urbs(struct usbnet *dev)
759{ 754{
760 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(unlink_wakeup);
761 DECLARE_WAITQUEUE(wait, current); 755 DECLARE_WAITQUEUE(wait, current);
762 int temp; 756 int temp;
763 757
764 /* ensure there are no more active urbs */ 758 /* ensure there are no more active urbs */
765 add_wait_queue(&unlink_wakeup, &wait); 759 add_wait_queue(&dev->wait, &wait);
766 set_current_state(TASK_UNINTERRUPTIBLE); 760 set_current_state(TASK_UNINTERRUPTIBLE);
767 dev->wait = &unlink_wakeup;
768 temp = unlink_urbs(dev, &dev->txq) + 761 temp = unlink_urbs(dev, &dev->txq) +
769 unlink_urbs(dev, &dev->rxq); 762 unlink_urbs(dev, &dev->rxq);
770 763
@@ -778,15 +771,14 @@ static void usbnet_terminate_urbs(struct usbnet *dev)
778 "waited for %d urb completions\n", temp); 771 "waited for %d urb completions\n", temp);
779 } 772 }
780 set_current_state(TASK_RUNNING); 773 set_current_state(TASK_RUNNING);
781 dev->wait = NULL; 774 remove_wait_queue(&dev->wait, &wait);
782 remove_wait_queue(&unlink_wakeup, &wait);
783} 775}
784 776
785int usbnet_stop (struct net_device *net) 777int usbnet_stop (struct net_device *net)
786{ 778{
787 struct usbnet *dev = netdev_priv(net); 779 struct usbnet *dev = netdev_priv(net);
788 struct driver_info *info = dev->driver_info; 780 struct driver_info *info = dev->driver_info;
789 int retval; 781 int retval, pm;
790 782
791 clear_bit(EVENT_DEV_OPEN, &dev->flags); 783 clear_bit(EVENT_DEV_OPEN, &dev->flags);
792 netif_stop_queue (net); 784 netif_stop_queue (net);
@@ -796,6 +788,8 @@ int usbnet_stop (struct net_device *net)
796 net->stats.rx_packets, net->stats.tx_packets, 788 net->stats.rx_packets, net->stats.tx_packets,
797 net->stats.rx_errors, net->stats.tx_errors); 789 net->stats.rx_errors, net->stats.tx_errors);
798 790
791 /* to not race resume */
792 pm = usb_autopm_get_interface(dev->intf);
799 /* allow minidriver to stop correctly (wireless devices to turn off 793 /* allow minidriver to stop correctly (wireless devices to turn off
800 * radio etc) */ 794 * radio etc) */
801 if (info->stop) { 795 if (info->stop) {
@@ -822,6 +816,9 @@ int usbnet_stop (struct net_device *net)
822 dev->flags = 0; 816 dev->flags = 0;
823 del_timer_sync (&dev->delay); 817 del_timer_sync (&dev->delay);
824 tasklet_kill (&dev->bh); 818 tasklet_kill (&dev->bh);
819 if (!pm)
820 usb_autopm_put_interface(dev->intf);
821
825 if (info->manage_power && 822 if (info->manage_power &&
826 !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags)) 823 !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags))
827 info->manage_power(dev, 0); 824 info->manage_power(dev, 0);
@@ -1442,11 +1439,12 @@ static void usbnet_bh (unsigned long param)
1442 /* restart RX again after disabling due to high error rate */ 1439 /* restart RX again after disabling due to high error rate */
1443 clear_bit(EVENT_RX_KILL, &dev->flags); 1440 clear_bit(EVENT_RX_KILL, &dev->flags);
1444 1441
1445 // waiting for all pending urbs to complete? 1442 /* waiting for all pending urbs to complete?
1446 if (dev->wait) { 1443 * only then can we forgo submitting anew
1447 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) { 1444 */
1448 wake_up (dev->wait); 1445 if (waitqueue_active(&dev->wait)) {
1449 } 1446 if (dev->txq.qlen + dev->rxq.qlen + dev->done.qlen == 0)
1447 wake_up_all(&dev->wait);
1450 1448
1451 // or are we maybe short a few urbs? 1449 // or are we maybe short a few urbs?
1452 } else if (netif_running (dev->net) && 1450 } else if (netif_running (dev->net) &&
@@ -1585,6 +1583,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1585 dev->driver_name = name; 1583 dev->driver_name = name;
1586 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV 1584 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
1587 | NETIF_MSG_PROBE | NETIF_MSG_LINK); 1585 | NETIF_MSG_PROBE | NETIF_MSG_LINK);
1586 init_waitqueue_head(&dev->wait);
1588 skb_queue_head_init (&dev->rxq); 1587 skb_queue_head_init (&dev->rxq);
1589 skb_queue_head_init (&dev->txq); 1588 skb_queue_head_init (&dev->txq);
1590 skb_queue_head_init (&dev->done); 1589 skb_queue_head_init (&dev->done);
@@ -1796,9 +1795,10 @@ int usbnet_resume (struct usb_interface *intf)
1796 spin_unlock_irq(&dev->txq.lock); 1795 spin_unlock_irq(&dev->txq.lock);
1797 1796
1798 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) { 1797 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) {
1799 /* handle remote wakeup ASAP */ 1798 /* handle remote wakeup ASAP
1800 if (!dev->wait && 1799 * we cannot race against stop
1801 netif_device_present(dev->net) && 1800 */
1801 if (netif_device_present(dev->net) &&
1802 !timer_pending(&dev->delay) && 1802 !timer_pending(&dev->delay) &&
1803 !test_bit(EVENT_RX_HALT, &dev->flags)) 1803 !test_bit(EVENT_RX_HALT, &dev->flags))
1804 rx_alloc_submit(dev, GFP_NOIO); 1804 rx_alloc_submit(dev, GFP_NOIO);
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 2ec2041b62d4..c0e7c64765ab 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -285,7 +285,11 @@ static void veth_setup(struct net_device *dev)
285 dev->ethtool_ops = &veth_ethtool_ops; 285 dev->ethtool_ops = &veth_ethtool_ops;
286 dev->features |= NETIF_F_LLTX; 286 dev->features |= NETIF_F_LLTX;
287 dev->features |= VETH_FEATURES; 287 dev->features |= VETH_FEATURES;
288 dev->vlan_features = dev->features; 288 dev->vlan_features = dev->features &
289 ~(NETIF_F_HW_VLAN_CTAG_TX |
290 NETIF_F_HW_VLAN_STAG_TX |
291 NETIF_F_HW_VLAN_CTAG_RX |
292 NETIF_F_HW_VLAN_STAG_RX);
289 dev->destructor = veth_dev_free; 293 dev->destructor = veth_dev_free;
290 294
291 dev->hw_features = VETH_FEATURES; 295 dev->hw_features = VETH_FEATURES;
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index d75f8edf4fb3..841b60831df1 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -671,8 +671,7 @@ static bool try_fill_recv(struct receive_queue *rq, gfp_t gfp)
671 if (err) 671 if (err)
672 break; 672 break;
673 } while (rq->vq->num_free); 673 } while (rq->vq->num_free);
674 if (unlikely(!virtqueue_kick(rq->vq))) 674 virtqueue_kick(rq->vq);
675 return false;
676 return !oom; 675 return !oom;
677} 676}
678 677
@@ -877,7 +876,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
877 err = xmit_skb(sq, skb); 876 err = xmit_skb(sq, skb);
878 877
879 /* This should not happen! */ 878 /* This should not happen! */
880 if (unlikely(err) || unlikely(!virtqueue_kick(sq->vq))) { 879 if (unlikely(err)) {
881 dev->stats.tx_fifo_errors++; 880 dev->stats.tx_fifo_errors++;
882 if (net_ratelimit()) 881 if (net_ratelimit())
883 dev_warn(&dev->dev, 882 dev_warn(&dev->dev,
@@ -886,6 +885,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
886 kfree_skb(skb); 885 kfree_skb(skb);
887 return NETDEV_TX_OK; 886 return NETDEV_TX_OK;
888 } 887 }
888 virtqueue_kick(sq->vq);
889 889
890 /* Don't wait up for transmitted skbs to be freed. */ 890 /* Don't wait up for transmitted skbs to be freed. */
891 skb_orphan(skb); 891 skb_orphan(skb);
@@ -1711,7 +1711,8 @@ static int virtnet_probe(struct virtio_device *vdev)
1711 /* If we can receive ANY GSO packets, we must allocate large ones. */ 1711 /* If we can receive ANY GSO packets, we must allocate large ones. */
1712 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) || 1712 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
1713 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) || 1713 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) ||
1714 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN)) 1714 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN) ||
1715 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UFO))
1715 vi->big_packets = true; 1716 vi->big_packets = true;
1716 1717
1717 if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) 1718 if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index 3be786faaaec..0fa3b44f7342 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -1762,11 +1762,20 @@ vmxnet3_netpoll(struct net_device *netdev)
1762{ 1762{
1763 struct vmxnet3_adapter *adapter = netdev_priv(netdev); 1763 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1764 1764
1765 if (adapter->intr.mask_mode == VMXNET3_IMM_ACTIVE) 1765 switch (adapter->intr.type) {
1766 vmxnet3_disable_all_intrs(adapter); 1766#ifdef CONFIG_PCI_MSI
1767 1767 case VMXNET3_IT_MSIX: {
1768 vmxnet3_do_poll(adapter, adapter->rx_queue[0].rx_ring[0].size); 1768 int i;
1769 vmxnet3_enable_all_intrs(adapter); 1769 for (i = 0; i < adapter->num_rx_queues; i++)
1770 vmxnet3_msix_rx(0, &adapter->rx_queue[i]);
1771 break;
1772 }
1773#endif
1774 case VMXNET3_IT_MSI:
1775 default:
1776 vmxnet3_intr(0, adapter->netdev);
1777 break;
1778 }
1770 1779
1771} 1780}
1772#endif /* CONFIG_NET_POLL_CONTROLLER */ 1781#endif /* CONFIG_NET_POLL_CONTROLLER */
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 026a313c2d2d..1236812c7be6 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -469,7 +469,6 @@ static inline struct hlist_head *vxlan_fdb_head(struct vxlan_dev *vxlan,
469/* Look up Ethernet address in forwarding table */ 469/* Look up Ethernet address in forwarding table */
470static struct vxlan_fdb *__vxlan_find_mac(struct vxlan_dev *vxlan, 470static struct vxlan_fdb *__vxlan_find_mac(struct vxlan_dev *vxlan,
471 const u8 *mac) 471 const u8 *mac)
472
473{ 472{
474 struct hlist_head *head = vxlan_fdb_head(vxlan, mac); 473 struct hlist_head *head = vxlan_fdb_head(vxlan, mac);
475 struct vxlan_fdb *f; 474 struct vxlan_fdb *f;
@@ -596,10 +595,8 @@ static struct sk_buff **vxlan_gro_receive(struct sk_buff **head, struct sk_buff
596 NAPI_GRO_CB(p)->same_flow = 0; 595 NAPI_GRO_CB(p)->same_flow = 0;
597 continue; 596 continue;
598 } 597 }
599 goto found;
600 } 598 }
601 599
602found:
603 type = eh->h_proto; 600 type = eh->h_proto;
604 601
605 rcu_read_lock(); 602 rcu_read_lock();
@@ -1321,6 +1318,9 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb)
1321 1318
1322 neigh_release(n); 1319 neigh_release(n);
1323 1320
1321 if (reply == NULL)
1322 goto out;
1323
1324 skb_reset_mac_header(reply); 1324 skb_reset_mac_header(reply);
1325 __skb_pull(reply, skb_network_offset(reply)); 1325 __skb_pull(reply, skb_network_offset(reply));
1326 reply->ip_summed = CHECKSUM_UNNECESSARY; 1326 reply->ip_summed = CHECKSUM_UNNECESSARY;
@@ -1342,15 +1342,103 @@ out:
1342} 1342}
1343 1343
1344#if IS_ENABLED(CONFIG_IPV6) 1344#if IS_ENABLED(CONFIG_IPV6)
1345
1346static struct sk_buff *vxlan_na_create(struct sk_buff *request,
1347 struct neighbour *n, bool isrouter)
1348{
1349 struct net_device *dev = request->dev;
1350 struct sk_buff *reply;
1351 struct nd_msg *ns, *na;
1352 struct ipv6hdr *pip6;
1353 u8 *daddr;
1354 int na_olen = 8; /* opt hdr + ETH_ALEN for target */
1355 int ns_olen;
1356 int i, len;
1357
1358 if (dev == NULL)
1359 return NULL;
1360
1361 len = LL_RESERVED_SPACE(dev) + sizeof(struct ipv6hdr) +
1362 sizeof(*na) + na_olen + dev->needed_tailroom;
1363 reply = alloc_skb(len, GFP_ATOMIC);
1364 if (reply == NULL)
1365 return NULL;
1366
1367 reply->protocol = htons(ETH_P_IPV6);
1368 reply->dev = dev;
1369 skb_reserve(reply, LL_RESERVED_SPACE(request->dev));
1370 skb_push(reply, sizeof(struct ethhdr));
1371 skb_set_mac_header(reply, 0);
1372
1373 ns = (struct nd_msg *)skb_transport_header(request);
1374
1375 daddr = eth_hdr(request)->h_source;
1376 ns_olen = request->len - skb_transport_offset(request) - sizeof(*ns);
1377 for (i = 0; i < ns_olen-1; i += (ns->opt[i+1]<<3)) {
1378 if (ns->opt[i] == ND_OPT_SOURCE_LL_ADDR) {
1379 daddr = ns->opt + i + sizeof(struct nd_opt_hdr);
1380 break;
1381 }
1382 }
1383
1384 /* Ethernet header */
1385 ether_addr_copy(eth_hdr(reply)->h_dest, daddr);
1386 ether_addr_copy(eth_hdr(reply)->h_source, n->ha);
1387 eth_hdr(reply)->h_proto = htons(ETH_P_IPV6);
1388 reply->protocol = htons(ETH_P_IPV6);
1389
1390 skb_pull(reply, sizeof(struct ethhdr));
1391 skb_set_network_header(reply, 0);
1392 skb_put(reply, sizeof(struct ipv6hdr));
1393
1394 /* IPv6 header */
1395
1396 pip6 = ipv6_hdr(reply);
1397 memset(pip6, 0, sizeof(struct ipv6hdr));
1398 pip6->version = 6;
1399 pip6->priority = ipv6_hdr(request)->priority;
1400 pip6->nexthdr = IPPROTO_ICMPV6;
1401 pip6->hop_limit = 255;
1402 pip6->daddr = ipv6_hdr(request)->saddr;
1403 pip6->saddr = *(struct in6_addr *)n->primary_key;
1404
1405 skb_pull(reply, sizeof(struct ipv6hdr));
1406 skb_set_transport_header(reply, 0);
1407
1408 na = (struct nd_msg *)skb_put(reply, sizeof(*na) + na_olen);
1409
1410 /* Neighbor Advertisement */
1411 memset(na, 0, sizeof(*na)+na_olen);
1412 na->icmph.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
1413 na->icmph.icmp6_router = isrouter;
1414 na->icmph.icmp6_override = 1;
1415 na->icmph.icmp6_solicited = 1;
1416 na->target = ns->target;
1417 ether_addr_copy(&na->opt[2], n->ha);
1418 na->opt[0] = ND_OPT_TARGET_LL_ADDR;
1419 na->opt[1] = na_olen >> 3;
1420
1421 na->icmph.icmp6_cksum = csum_ipv6_magic(&pip6->saddr,
1422 &pip6->daddr, sizeof(*na)+na_olen, IPPROTO_ICMPV6,
1423 csum_partial(na, sizeof(*na)+na_olen, 0));
1424
1425 pip6->payload_len = htons(sizeof(*na)+na_olen);
1426
1427 skb_push(reply, sizeof(struct ipv6hdr));
1428
1429 reply->ip_summed = CHECKSUM_UNNECESSARY;
1430
1431 return reply;
1432}
1433
1345static int neigh_reduce(struct net_device *dev, struct sk_buff *skb) 1434static int neigh_reduce(struct net_device *dev, struct sk_buff *skb)
1346{ 1435{
1347 struct vxlan_dev *vxlan = netdev_priv(dev); 1436 struct vxlan_dev *vxlan = netdev_priv(dev);
1348 struct neighbour *n; 1437 struct nd_msg *msg;
1349 union vxlan_addr ipa;
1350 const struct ipv6hdr *iphdr; 1438 const struct ipv6hdr *iphdr;
1351 const struct in6_addr *saddr, *daddr; 1439 const struct in6_addr *saddr, *daddr;
1352 struct nd_msg *msg; 1440 struct neighbour *n;
1353 struct inet6_dev *in6_dev = NULL; 1441 struct inet6_dev *in6_dev;
1354 1442
1355 in6_dev = __in6_dev_get(dev); 1443 in6_dev = __in6_dev_get(dev);
1356 if (!in6_dev) 1444 if (!in6_dev)
@@ -1363,19 +1451,20 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb)
1363 saddr = &iphdr->saddr; 1451 saddr = &iphdr->saddr;
1364 daddr = &iphdr->daddr; 1452 daddr = &iphdr->daddr;
1365 1453
1366 if (ipv6_addr_loopback(daddr) ||
1367 ipv6_addr_is_multicast(daddr))
1368 goto out;
1369
1370 msg = (struct nd_msg *)skb_transport_header(skb); 1454 msg = (struct nd_msg *)skb_transport_header(skb);
1371 if (msg->icmph.icmp6_code != 0 || 1455 if (msg->icmph.icmp6_code != 0 ||
1372 msg->icmph.icmp6_type != NDISC_NEIGHBOUR_SOLICITATION) 1456 msg->icmph.icmp6_type != NDISC_NEIGHBOUR_SOLICITATION)
1373 goto out; 1457 goto out;
1374 1458
1375 n = neigh_lookup(ipv6_stub->nd_tbl, daddr, dev); 1459 if (ipv6_addr_loopback(daddr) ||
1460 ipv6_addr_is_multicast(&msg->target))
1461 goto out;
1462
1463 n = neigh_lookup(ipv6_stub->nd_tbl, &msg->target, dev);
1376 1464
1377 if (n) { 1465 if (n) {
1378 struct vxlan_fdb *f; 1466 struct vxlan_fdb *f;
1467 struct sk_buff *reply;
1379 1468
1380 if (!(n->nud_state & NUD_CONNECTED)) { 1469 if (!(n->nud_state & NUD_CONNECTED)) {
1381 neigh_release(n); 1470 neigh_release(n);
@@ -1389,13 +1478,23 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb)
1389 goto out; 1478 goto out;
1390 } 1479 }
1391 1480
1392 ipv6_stub->ndisc_send_na(dev, n, saddr, &msg->target, 1481 reply = vxlan_na_create(skb, n,
1393 !!in6_dev->cnf.forwarding, 1482 !!(f ? f->flags & NTF_ROUTER : 0));
1394 true, false, false); 1483
1395 neigh_release(n); 1484 neigh_release(n);
1485
1486 if (reply == NULL)
1487 goto out;
1488
1489 if (netif_rx_ni(reply) == NET_RX_DROP)
1490 dev->stats.rx_dropped++;
1491
1396 } else if (vxlan->flags & VXLAN_F_L3MISS) { 1492 } else if (vxlan->flags & VXLAN_F_L3MISS) {
1397 ipa.sin6.sin6_addr = *daddr; 1493 union vxlan_addr ipa = {
1398 ipa.sa.sa_family = AF_INET6; 1494 .sin6.sin6_addr = msg->target,
1495 .sa.sa_family = AF_INET6,
1496 };
1497
1399 vxlan_ip_miss(dev, &ipa); 1498 vxlan_ip_miss(dev, &ipa);
1400 } 1499 }
1401 1500
diff --git a/drivers/net/wan/dlci.c b/drivers/net/wan/dlci.c
index 0d1c7592efa0..19f7cb2cdef3 100644
--- a/drivers/net/wan/dlci.c
+++ b/drivers/net/wan/dlci.c
@@ -71,12 +71,9 @@ static int dlci_header(struct sk_buff *skb, struct net_device *dev,
71 const void *saddr, unsigned len) 71 const void *saddr, unsigned len)
72{ 72{
73 struct frhdr hdr; 73 struct frhdr hdr;
74 struct dlci_local *dlp;
75 unsigned int hlen; 74 unsigned int hlen;
76 char *dest; 75 char *dest;
77 76
78 dlp = netdev_priv(dev);
79
80 hdr.control = FRAD_I_UI; 77 hdr.control = FRAD_I_UI;
81 switch (type) 78 switch (type)
82 { 79 {
@@ -107,11 +104,9 @@ static int dlci_header(struct sk_buff *skb, struct net_device *dev,
107 104
108static void dlci_receive(struct sk_buff *skb, struct net_device *dev) 105static void dlci_receive(struct sk_buff *skb, struct net_device *dev)
109{ 106{
110 struct dlci_local *dlp;
111 struct frhdr *hdr; 107 struct frhdr *hdr;
112 int process, header; 108 int process, header;
113 109
114 dlp = netdev_priv(dev);
115 if (!pskb_may_pull(skb, sizeof(*hdr))) { 110 if (!pskb_may_pull(skb, sizeof(*hdr))) {
116 netdev_notice(dev, "invalid data no header\n"); 111 netdev_notice(dev, "invalid data no header\n");
117 dev->stats.rx_errors++; 112 dev->stats.rx_errors++;
diff --git a/drivers/net/wireless/ath/ar5523/ar5523.c b/drivers/net/wireless/ath/ar5523/ar5523.c
index 8aa20df55e50..507d9a9ee69a 100644
--- a/drivers/net/wireless/ath/ar5523/ar5523.c
+++ b/drivers/net/wireless/ath/ar5523/ar5523.c
@@ -1764,7 +1764,7 @@ static struct usb_device_id ar5523_id_table[] = {
1764 AR5523_DEVICE_UG(0x07d1, 0x3a07), /* D-Link / WUA-2340 rev A1 */ 1764 AR5523_DEVICE_UG(0x07d1, 0x3a07), /* D-Link / WUA-2340 rev A1 */
1765 AR5523_DEVICE_UG(0x1690, 0x0712), /* Gigaset / AR5523 */ 1765 AR5523_DEVICE_UG(0x1690, 0x0712), /* Gigaset / AR5523 */
1766 AR5523_DEVICE_UG(0x1690, 0x0710), /* Gigaset / SMCWUSBTG */ 1766 AR5523_DEVICE_UG(0x1690, 0x0710), /* Gigaset / SMCWUSBTG */
1767 AR5523_DEVICE_UG(0x129b, 0x160c), /* Gigaset / USB stick 108 1767 AR5523_DEVICE_UG(0x129b, 0x160b), /* Gigaset / USB stick 108
1768 (CyberTAN Technology) */ 1768 (CyberTAN Technology) */
1769 AR5523_DEVICE_UG(0x16ab, 0x7801), /* Globalsun / AR5523_1 */ 1769 AR5523_DEVICE_UG(0x16ab, 0x7801), /* Globalsun / AR5523_1 */
1770 AR5523_DEVICE_UX(0x16ab, 0x7811), /* Globalsun / AR5523_2 */ 1770 AR5523_DEVICE_UX(0x16ab, 0x7811), /* Globalsun / AR5523_2 */
diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c
index d6bc7cb61bfb..1a2973b7acf2 100644
--- a/drivers/net/wireless/ath/ath5k/phy.c
+++ b/drivers/net/wireless/ath/ath5k/phy.c
@@ -110,7 +110,7 @@ ath5k_hw_radio_revision(struct ath5k_hw *ah, enum ieee80211_band band)
110 ath5k_hw_reg_write(ah, 0x00010000, AR5K_PHY(0x20)); 110 ath5k_hw_reg_write(ah, 0x00010000, AR5K_PHY(0x20));
111 111
112 if (ah->ah_version == AR5K_AR5210) { 112 if (ah->ah_version == AR5K_AR5210) {
113 srev = ath5k_hw_reg_read(ah, AR5K_PHY(256) >> 28) & 0xf; 113 srev = (ath5k_hw_reg_read(ah, AR5K_PHY(256)) >> 28) & 0xf;
114 ret = (u16)ath5k_hw_bitswap(srev, 4) + 1; 114 ret = (u16)ath5k_hw_bitswap(srev, 4) + 1;
115 } else { 115 } else {
116 srev = (ath5k_hw_reg_read(ah, AR5K_PHY(0x100)) >> 24) & 0xff; 116 srev = (ath5k_hw_reg_read(ah, AR5K_PHY(0x100)) >> 24) & 0xff;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index 25243cbc07f0..b8daff78b9d1 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -5065,6 +5065,10 @@ static u16 ar9003_hw_get_max_edge_power(struct ar9300_eeprom *eep,
5065 break; 5065 break;
5066 } 5066 }
5067 } 5067 }
5068
5069 if (is2GHz && !twiceMaxEdgePower)
5070 twiceMaxEdgePower = 60;
5071
5068 return twiceMaxEdgePower; 5072 return twiceMaxEdgePower;
5069} 5073}
5070 5074
diff --git a/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h b/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
index 1cc13569b17b..1b6b4d0cfa97 100644
--- a/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
@@ -57,7 +57,7 @@ static const u32 ar9462_2p0_baseband_postamble[][5] = {
57 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3236605e, 0x32365a5e}, 57 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3236605e, 0x32365a5e},
58 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 58 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
59 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c}, 59 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c},
60 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce}, 60 {0x00009e20, 0x000003a5, 0x000003a5, 0x000003a5, 0x000003a5},
61 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021}, 61 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021},
62 {0x00009e3c, 0xcf946220, 0xcf946220, 0xcfd5c782, 0xcfd5c282}, 62 {0x00009e3c, 0xcf946220, 0xcf946220, 0xcfd5c782, 0xcfd5c282},
63 {0x00009e44, 0x62321e27, 0x62321e27, 0xfe291e27, 0xfe291e27}, 63 {0x00009e44, 0x62321e27, 0x62321e27, 0xfe291e27, 0xfe291e27},
@@ -96,7 +96,7 @@ static const u32 ar9462_2p0_baseband_postamble[][5] = {
96 {0x0000ae04, 0x001c0000, 0x001c0000, 0x001c0000, 0x00100000}, 96 {0x0000ae04, 0x001c0000, 0x001c0000, 0x001c0000, 0x00100000},
97 {0x0000ae18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 97 {0x0000ae18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
98 {0x0000ae1c, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c}, 98 {0x0000ae1c, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c},
99 {0x0000ae20, 0x000001b5, 0x000001b5, 0x000001ce, 0x000001ce}, 99 {0x0000ae20, 0x000001a6, 0x000001a6, 0x000001aa, 0x000001aa},
100 {0x0000b284, 0x00000000, 0x00000000, 0x00000550, 0x00000550}, 100 {0x0000b284, 0x00000000, 0x00000000, 0x00000550, 0x00000550},
101}; 101};
102 102
diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h
index 58da3468d1f0..99a203174f45 100644
--- a/drivers/net/wireless/ath/ath9k/htc.h
+++ b/drivers/net/wireless/ath/ath9k/htc.h
@@ -262,6 +262,8 @@ enum tid_aggr_state {
262struct ath9k_htc_sta { 262struct ath9k_htc_sta {
263 u8 index; 263 u8 index;
264 enum tid_aggr_state tid_state[ATH9K_HTC_MAX_TID]; 264 enum tid_aggr_state tid_state[ATH9K_HTC_MAX_TID];
265 struct work_struct rc_update_work;
266 struct ath9k_htc_priv *htc_priv;
265}; 267};
266 268
267#define ATH9K_HTC_RXBUF 256 269#define ATH9K_HTC_RXBUF 256
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_init.c b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
index f4e1de20d99c..c57d6b859c04 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
@@ -34,6 +34,10 @@ static int ath9k_htc_btcoex_enable;
34module_param_named(btcoex_enable, ath9k_htc_btcoex_enable, int, 0444); 34module_param_named(btcoex_enable, ath9k_htc_btcoex_enable, int, 0444);
35MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence"); 35MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
36 36
37static int ath9k_ps_enable;
38module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
39MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
40
37#define CHAN2G(_freq, _idx) { \ 41#define CHAN2G(_freq, _idx) { \
38 .center_freq = (_freq), \ 42 .center_freq = (_freq), \
39 .hw_value = (_idx), \ 43 .hw_value = (_idx), \
@@ -725,12 +729,14 @@ static void ath9k_set_hw_capab(struct ath9k_htc_priv *priv,
725 IEEE80211_HW_SPECTRUM_MGMT | 729 IEEE80211_HW_SPECTRUM_MGMT |
726 IEEE80211_HW_HAS_RATE_CONTROL | 730 IEEE80211_HW_HAS_RATE_CONTROL |
727 IEEE80211_HW_RX_INCLUDES_FCS | 731 IEEE80211_HW_RX_INCLUDES_FCS |
728 IEEE80211_HW_SUPPORTS_PS |
729 IEEE80211_HW_PS_NULLFUNC_STACK | 732 IEEE80211_HW_PS_NULLFUNC_STACK |
730 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 733 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
731 IEEE80211_HW_MFP_CAPABLE | 734 IEEE80211_HW_MFP_CAPABLE |
732 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING; 735 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
733 736
737 if (ath9k_ps_enable)
738 hw->flags |= IEEE80211_HW_SUPPORTS_PS;
739
734 hw->wiphy->interface_modes = 740 hw->wiphy->interface_modes =
735 BIT(NL80211_IFTYPE_STATION) | 741 BIT(NL80211_IFTYPE_STATION) |
736 BIT(NL80211_IFTYPE_ADHOC) | 742 BIT(NL80211_IFTYPE_ADHOC) |
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_main.c b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
index 608d739d1378..c9254a61ca52 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
@@ -1270,18 +1270,50 @@ static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1270 mutex_unlock(&priv->mutex); 1270 mutex_unlock(&priv->mutex);
1271} 1271}
1272 1272
1273static void ath9k_htc_sta_rc_update_work(struct work_struct *work)
1274{
1275 struct ath9k_htc_sta *ista =
1276 container_of(work, struct ath9k_htc_sta, rc_update_work);
1277 struct ieee80211_sta *sta =
1278 container_of((void *)ista, struct ieee80211_sta, drv_priv);
1279 struct ath9k_htc_priv *priv = ista->htc_priv;
1280 struct ath_common *common = ath9k_hw_common(priv->ah);
1281 struct ath9k_htc_target_rate trate;
1282
1283 mutex_lock(&priv->mutex);
1284 ath9k_htc_ps_wakeup(priv);
1285
1286 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
1287 ath9k_htc_setup_rate(priv, sta, &trate);
1288 if (!ath9k_htc_send_rate_cmd(priv, &trate))
1289 ath_dbg(common, CONFIG,
1290 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1291 sta->addr, be32_to_cpu(trate.capflags));
1292 else
1293 ath_dbg(common, CONFIG,
1294 "Unable to update supported rates for sta: %pM\n",
1295 sta->addr);
1296
1297 ath9k_htc_ps_restore(priv);
1298 mutex_unlock(&priv->mutex);
1299}
1300
1273static int ath9k_htc_sta_add(struct ieee80211_hw *hw, 1301static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1274 struct ieee80211_vif *vif, 1302 struct ieee80211_vif *vif,
1275 struct ieee80211_sta *sta) 1303 struct ieee80211_sta *sta)
1276{ 1304{
1277 struct ath9k_htc_priv *priv = hw->priv; 1305 struct ath9k_htc_priv *priv = hw->priv;
1306 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
1278 int ret; 1307 int ret;
1279 1308
1280 mutex_lock(&priv->mutex); 1309 mutex_lock(&priv->mutex);
1281 ath9k_htc_ps_wakeup(priv); 1310 ath9k_htc_ps_wakeup(priv);
1282 ret = ath9k_htc_add_station(priv, vif, sta); 1311 ret = ath9k_htc_add_station(priv, vif, sta);
1283 if (!ret) 1312 if (!ret) {
1313 INIT_WORK(&ista->rc_update_work, ath9k_htc_sta_rc_update_work);
1314 ista->htc_priv = priv;
1284 ath9k_htc_init_rate(priv, sta); 1315 ath9k_htc_init_rate(priv, sta);
1316 }
1285 ath9k_htc_ps_restore(priv); 1317 ath9k_htc_ps_restore(priv);
1286 mutex_unlock(&priv->mutex); 1318 mutex_unlock(&priv->mutex);
1287 1319
@@ -1293,12 +1325,13 @@ static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1293 struct ieee80211_sta *sta) 1325 struct ieee80211_sta *sta)
1294{ 1326{
1295 struct ath9k_htc_priv *priv = hw->priv; 1327 struct ath9k_htc_priv *priv = hw->priv;
1296 struct ath9k_htc_sta *ista; 1328 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
1297 int ret; 1329 int ret;
1298 1330
1331 cancel_work_sync(&ista->rc_update_work);
1332
1299 mutex_lock(&priv->mutex); 1333 mutex_lock(&priv->mutex);
1300 ath9k_htc_ps_wakeup(priv); 1334 ath9k_htc_ps_wakeup(priv);
1301 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1302 htc_sta_drain(priv->htc, ista->index); 1335 htc_sta_drain(priv->htc, ista->index);
1303 ret = ath9k_htc_remove_station(priv, vif, sta); 1336 ret = ath9k_htc_remove_station(priv, vif, sta);
1304 ath9k_htc_ps_restore(priv); 1337 ath9k_htc_ps_restore(priv);
@@ -1311,28 +1344,12 @@ static void ath9k_htc_sta_rc_update(struct ieee80211_hw *hw,
1311 struct ieee80211_vif *vif, 1344 struct ieee80211_vif *vif,
1312 struct ieee80211_sta *sta, u32 changed) 1345 struct ieee80211_sta *sta, u32 changed)
1313{ 1346{
1314 struct ath9k_htc_priv *priv = hw->priv; 1347 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
1315 struct ath_common *common = ath9k_hw_common(priv->ah);
1316 struct ath9k_htc_target_rate trate;
1317
1318 mutex_lock(&priv->mutex);
1319 ath9k_htc_ps_wakeup(priv);
1320 1348
1321 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { 1349 if (!(changed & IEEE80211_RC_SUPP_RATES_CHANGED))
1322 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate)); 1350 return;
1323 ath9k_htc_setup_rate(priv, sta, &trate);
1324 if (!ath9k_htc_send_rate_cmd(priv, &trate))
1325 ath_dbg(common, CONFIG,
1326 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1327 sta->addr, be32_to_cpu(trate.capflags));
1328 else
1329 ath_dbg(common, CONFIG,
1330 "Unable to update supported rates for sta: %pM\n",
1331 sta->addr);
1332 }
1333 1351
1334 ath9k_htc_ps_restore(priv); 1352 schedule_work(&ista->rc_update_work);
1335 mutex_unlock(&priv->mutex);
1336} 1353}
1337 1354
1338static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, 1355static int ath9k_htc_conf_tx(struct ieee80211_hw *hw,
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index fbf43c05713f..9078a6c5a74e 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -1316,7 +1316,7 @@ static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
1316 if (AR_SREV_9300_20_OR_LATER(ah)) 1316 if (AR_SREV_9300_20_OR_LATER(ah))
1317 udelay(50); 1317 udelay(50);
1318 else if (AR_SREV_9100(ah)) 1318 else if (AR_SREV_9100(ah))
1319 udelay(10000); 1319 mdelay(10);
1320 else 1320 else
1321 udelay(100); 1321 udelay(100);
1322 1322
@@ -1534,7 +1534,7 @@ EXPORT_SYMBOL(ath9k_hw_check_nav);
1534bool ath9k_hw_check_alive(struct ath_hw *ah) 1534bool ath9k_hw_check_alive(struct ath_hw *ah)
1535{ 1535{
1536 int count = 50; 1536 int count = 50;
1537 u32 reg; 1537 u32 reg, last_val;
1538 1538
1539 if (AR_SREV_9300(ah)) 1539 if (AR_SREV_9300(ah))
1540 return !ath9k_hw_detect_mac_hang(ah); 1540 return !ath9k_hw_detect_mac_hang(ah);
@@ -1542,9 +1542,14 @@ bool ath9k_hw_check_alive(struct ath_hw *ah)
1542 if (AR_SREV_9285_12_OR_LATER(ah)) 1542 if (AR_SREV_9285_12_OR_LATER(ah))
1543 return true; 1543 return true;
1544 1544
1545 last_val = REG_READ(ah, AR_OBS_BUS_1);
1545 do { 1546 do {
1546 reg = REG_READ(ah, AR_OBS_BUS_1); 1547 reg = REG_READ(ah, AR_OBS_BUS_1);
1548 if (reg != last_val)
1549 return true;
1547 1550
1551 udelay(1);
1552 last_val = reg;
1548 if ((reg & 0x7E7FFFEF) == 0x00702400) 1553 if ((reg & 0x7E7FFFEF) == 0x00702400)
1549 continue; 1554 continue;
1550 1555
@@ -2051,9 +2056,8 @@ static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
2051 2056
2052 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, 2057 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2053 AR_RTC_FORCE_WAKE_EN); 2058 AR_RTC_FORCE_WAKE_EN);
2054
2055 if (AR_SREV_9100(ah)) 2059 if (AR_SREV_9100(ah))
2056 udelay(10000); 2060 mdelay(10);
2057 else 2061 else
2058 udelay(50); 2062 udelay(50);
2059 2063
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index c36de303c8f3..1fc2e5a26b52 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -57,6 +57,10 @@ static int ath9k_bt_ant_diversity;
57module_param_named(bt_ant_diversity, ath9k_bt_ant_diversity, int, 0444); 57module_param_named(bt_ant_diversity, ath9k_bt_ant_diversity, int, 0444);
58MODULE_PARM_DESC(bt_ant_diversity, "Enable WLAN/BT RX antenna diversity"); 58MODULE_PARM_DESC(bt_ant_diversity, "Enable WLAN/BT RX antenna diversity");
59 59
60static int ath9k_ps_enable;
61module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
62MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
63
60bool is_ath9k_unloaded; 64bool is_ath9k_unloaded;
61/* We use the hw_value as an index into our private channel structure */ 65/* We use the hw_value as an index into our private channel structure */
62 66
@@ -903,13 +907,15 @@ static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
903 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | 907 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
904 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | 908 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
905 IEEE80211_HW_SIGNAL_DBM | 909 IEEE80211_HW_SIGNAL_DBM |
906 IEEE80211_HW_SUPPORTS_PS |
907 IEEE80211_HW_PS_NULLFUNC_STACK | 910 IEEE80211_HW_PS_NULLFUNC_STACK |
908 IEEE80211_HW_SPECTRUM_MGMT | 911 IEEE80211_HW_SPECTRUM_MGMT |
909 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 912 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
910 IEEE80211_HW_SUPPORTS_RC_TABLE | 913 IEEE80211_HW_SUPPORTS_RC_TABLE |
911 IEEE80211_HW_SUPPORTS_HT_CCK_RATES; 914 IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
912 915
916 if (ath9k_ps_enable)
917 hw->flags |= IEEE80211_HW_SUPPORTS_PS;
918
913 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) { 919 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
914 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION; 920 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
915 921
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index a0ebdd000fc2..82e340d3ec60 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -732,11 +732,18 @@ static struct ath_rxbuf *ath_get_next_rx_buf(struct ath_softc *sc,
732 return NULL; 732 return NULL;
733 733
734 /* 734 /*
735 * mark descriptor as zero-length and set the 'more' 735 * Re-check previous descriptor, in case it has been filled
736 * flag to ensure that both buffers get discarded 736 * in the mean time.
737 */ 737 */
738 rs->rs_datalen = 0; 738 ret = ath9k_hw_rxprocdesc(ah, ds, rs);
739 rs->rs_more = true; 739 if (ret == -EINPROGRESS) {
740 /*
741 * mark descriptor as zero-length and set the 'more'
742 * flag to ensure that both buffers get discarded
743 */
744 rs->rs_datalen = 0;
745 rs->rs_more = true;
746 }
740 } 747 }
741 748
742 list_del(&bf->list); 749 list_del(&bf->list);
@@ -985,32 +992,32 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
985 struct ath_common *common = ath9k_hw_common(ah); 992 struct ath_common *common = ath9k_hw_common(ah);
986 struct ieee80211_hdr *hdr; 993 struct ieee80211_hdr *hdr;
987 bool discard_current = sc->rx.discard_next; 994 bool discard_current = sc->rx.discard_next;
988 int ret = 0;
989 995
990 /* 996 /*
991 * Discard corrupt descriptors which are marked in 997 * Discard corrupt descriptors which are marked in
992 * ath_get_next_rx_buf(). 998 * ath_get_next_rx_buf().
993 */ 999 */
994 sc->rx.discard_next = rx_stats->rs_more;
995 if (discard_current) 1000 if (discard_current)
996 return -EINVAL; 1001 goto corrupt;
1002
1003 sc->rx.discard_next = false;
997 1004
998 /* 1005 /*
999 * Discard zero-length packets. 1006 * Discard zero-length packets.
1000 */ 1007 */
1001 if (!rx_stats->rs_datalen) { 1008 if (!rx_stats->rs_datalen) {
1002 RX_STAT_INC(rx_len_err); 1009 RX_STAT_INC(rx_len_err);
1003 return -EINVAL; 1010 goto corrupt;
1004 } 1011 }
1005 1012
1006 /* 1013 /*
1007 * rs_status follows rs_datalen so if rs_datalen is too large 1014 * rs_status follows rs_datalen so if rs_datalen is too large
1008 * we can take a hint that hardware corrupted it, so ignore 1015 * we can take a hint that hardware corrupted it, so ignore
1009 * those frames. 1016 * those frames.
1010 */ 1017 */
1011 if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) { 1018 if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) {
1012 RX_STAT_INC(rx_len_err); 1019 RX_STAT_INC(rx_len_err);
1013 return -EINVAL; 1020 goto corrupt;
1014 } 1021 }
1015 1022
1016 /* Only use status info from the last fragment */ 1023 /* Only use status info from the last fragment */
@@ -1024,10 +1031,8 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1024 * This is different from the other corrupt descriptor 1031 * This is different from the other corrupt descriptor
1025 * condition handled above. 1032 * condition handled above.
1026 */ 1033 */
1027 if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC) { 1034 if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC)
1028 ret = -EINVAL; 1035 goto corrupt;
1029 goto exit;
1030 }
1031 1036
1032 hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len); 1037 hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len);
1033 1038
@@ -1043,18 +1048,15 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1043 if (ath_process_fft(sc, hdr, rx_stats, rx_status->mactime)) 1048 if (ath_process_fft(sc, hdr, rx_stats, rx_status->mactime))
1044 RX_STAT_INC(rx_spectral); 1049 RX_STAT_INC(rx_spectral);
1045 1050
1046 ret = -EINVAL; 1051 return -EINVAL;
1047 goto exit;
1048 } 1052 }
1049 1053
1050 /* 1054 /*
1051 * everything but the rate is checked here, the rate check is done 1055 * everything but the rate is checked here, the rate check is done
1052 * separately to avoid doing two lookups for a rate for each frame. 1056 * separately to avoid doing two lookups for a rate for each frame.
1053 */ 1057 */
1054 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error)) { 1058 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
1055 ret = -EINVAL; 1059 return -EINVAL;
1056 goto exit;
1057 }
1058 1060
1059 if (ath_is_mybeacon(common, hdr)) { 1061 if (ath_is_mybeacon(common, hdr)) {
1060 RX_STAT_INC(rx_beacons); 1062 RX_STAT_INC(rx_beacons);
@@ -1064,15 +1066,11 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1064 /* 1066 /*
1065 * This shouldn't happen, but have a safety check anyway. 1067 * This shouldn't happen, but have a safety check anyway.
1066 */ 1068 */
1067 if (WARN_ON(!ah->curchan)) { 1069 if (WARN_ON(!ah->curchan))
1068 ret = -EINVAL; 1070 return -EINVAL;
1069 goto exit;
1070 }
1071 1071
1072 if (ath9k_process_rate(common, hw, rx_stats, rx_status)) { 1072 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
1073 ret =-EINVAL; 1073 return -EINVAL;
1074 goto exit;
1075 }
1076 1074
1077 ath9k_process_rssi(common, hw, rx_stats, rx_status); 1075 ath9k_process_rssi(common, hw, rx_stats, rx_status);
1078 1076
@@ -1087,9 +1085,11 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1087 sc->rx.num_pkts++; 1085 sc->rx.num_pkts++;
1088#endif 1086#endif
1089 1087
1090exit: 1088 return 0;
1091 sc->rx.discard_next = false; 1089
1092 return ret; 1090corrupt:
1091 sc->rx.discard_next = rx_stats->rs_more;
1092 return -EINVAL;
1093} 1093}
1094 1094
1095static void ath9k_rx_skb_postprocess(struct ath_common *common, 1095static void ath9k_rx_skb_postprocess(struct ath_common *common,
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 0a75e2f68c9d..55897d508a76 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -1444,14 +1444,16 @@ void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
1444 for (tidno = 0, tid = &an->tid[tidno]; 1444 for (tidno = 0, tid = &an->tid[tidno];
1445 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) { 1445 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1446 1446
1447 if (!tid->sched)
1448 continue;
1449
1450 ac = tid->ac; 1447 ac = tid->ac;
1451 txq = ac->txq; 1448 txq = ac->txq;
1452 1449
1453 ath_txq_lock(sc, txq); 1450 ath_txq_lock(sc, txq);
1454 1451
1452 if (!tid->sched) {
1453 ath_txq_unlock(sc, txq);
1454 continue;
1455 }
1456
1455 buffered = ath_tid_has_buffered(tid); 1457 buffered = ath_tid_has_buffered(tid);
1456 1458
1457 tid->sched = false; 1459 tid->sched = false;
@@ -2061,7 +2063,7 @@ static struct ath_buf *ath_tx_setup_buffer(struct ath_softc *sc,
2061 2063
2062 ATH_TXBUF_RESET(bf); 2064 ATH_TXBUF_RESET(bf);
2063 2065
2064 if (tid) { 2066 if (tid && ieee80211_is_data_present(hdr->frame_control)) {
2065 fragno = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG; 2067 fragno = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
2066 seqno = tid->seq_next; 2068 seqno = tid->seq_next;
2067 hdr->seq_ctrl = cpu_to_le16(tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT); 2069 hdr->seq_ctrl = cpu_to_le16(tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT);
@@ -2184,14 +2186,15 @@ int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
2184 txq->stopped = true; 2186 txq->stopped = true;
2185 } 2187 }
2186 2188
2189 if (txctl->an && ieee80211_is_data_present(hdr->frame_control))
2190 tid = ath_get_skb_tid(sc, txctl->an, skb);
2191
2187 if (info->flags & IEEE80211_TX_CTL_PS_RESPONSE) { 2192 if (info->flags & IEEE80211_TX_CTL_PS_RESPONSE) {
2188 ath_txq_unlock(sc, txq); 2193 ath_txq_unlock(sc, txq);
2189 txq = sc->tx.uapsdq; 2194 txq = sc->tx.uapsdq;
2190 ath_txq_lock(sc, txq); 2195 ath_txq_lock(sc, txq);
2191 } else if (txctl->an && 2196 } else if (txctl->an &&
2192 ieee80211_is_data_present(hdr->frame_control)) { 2197 ieee80211_is_data_present(hdr->frame_control)) {
2193 tid = ath_get_skb_tid(sc, txctl->an, skb);
2194
2195 WARN_ON(tid->ac->txq != txctl->txq); 2198 WARN_ON(tid->ac->txq != txctl->txq);
2196 2199
2197 if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) 2200 if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
index 3e991897d7ca..ddaa9efd053d 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
@@ -457,7 +457,6 @@ struct brcmf_sdio {
457 457
458 u8 tx_hdrlen; /* sdio bus header length for tx packet */ 458 u8 tx_hdrlen; /* sdio bus header length for tx packet */
459 bool txglom; /* host tx glomming enable flag */ 459 bool txglom; /* host tx glomming enable flag */
460 struct sk_buff *txglom_sgpad; /* scatter-gather padding buffer */
461 u16 head_align; /* buffer pointer alignment */ 460 u16 head_align; /* buffer pointer alignment */
462 u16 sgentry_align; /* scatter-gather buffer alignment */ 461 u16 sgentry_align; /* scatter-gather buffer alignment */
463}; 462};
@@ -1944,19 +1943,21 @@ static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus,
1944 if (lastfrm && chain_pad) 1943 if (lastfrm && chain_pad)
1945 tail_pad += blksize - chain_pad; 1944 tail_pad += blksize - chain_pad;
1946 if (skb_tailroom(pkt) < tail_pad && pkt->len > blksize) { 1945 if (skb_tailroom(pkt) < tail_pad && pkt->len > blksize) {
1947 pkt_pad = bus->txglom_sgpad; 1946 pkt_pad = brcmu_pkt_buf_get_skb(tail_pad + tail_chop +
1948 if (pkt_pad == NULL) 1947 bus->head_align);
1949 brcmu_pkt_buf_get_skb(tail_pad + tail_chop);
1950 if (pkt_pad == NULL) 1948 if (pkt_pad == NULL)
1951 return -ENOMEM; 1949 return -ENOMEM;
1952 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad); 1950 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad);
1953 if (unlikely(ret < 0)) 1951 if (unlikely(ret < 0)) {
1952 kfree_skb(pkt_pad);
1954 return ret; 1953 return ret;
1954 }
1955 memcpy(pkt_pad->data, 1955 memcpy(pkt_pad->data,
1956 pkt->data + pkt->len - tail_chop, 1956 pkt->data + pkt->len - tail_chop,
1957 tail_chop); 1957 tail_chop);
1958 *(u32 *)(pkt_pad->cb) = ALIGN_SKB_FLAG + tail_chop; 1958 *(u32 *)(pkt_pad->cb) = ALIGN_SKB_FLAG + tail_chop;
1959 skb_trim(pkt, pkt->len - tail_chop); 1959 skb_trim(pkt, pkt->len - tail_chop);
1960 skb_trim(pkt_pad, tail_pad + tail_chop);
1960 __skb_queue_after(pktq, pkt, pkt_pad); 1961 __skb_queue_after(pktq, pkt, pkt_pad);
1961 } else { 1962 } else {
1962 ntail = pkt->data_len + tail_pad - 1963 ntail = pkt->data_len + tail_pad -
@@ -2011,7 +2012,7 @@ brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq,
2011 return ret; 2012 return ret;
2012 head_pad = (u16)ret; 2013 head_pad = (u16)ret;
2013 if (head_pad) 2014 if (head_pad)
2014 memset(pkt_next->data, 0, head_pad + bus->tx_hdrlen); 2015 memset(pkt_next->data + bus->tx_hdrlen, 0, head_pad);
2015 2016
2016 total_len += pkt_next->len; 2017 total_len += pkt_next->len;
2017 2018
@@ -3486,10 +3487,6 @@ static int brcmf_sdio_bus_preinit(struct device *dev)
3486 bus->txglom = false; 3487 bus->txglom = false;
3487 value = 1; 3488 value = 1;
3488 pad_size = bus->sdiodev->func[2]->cur_blksize << 1; 3489 pad_size = bus->sdiodev->func[2]->cur_blksize << 1;
3489 bus->txglom_sgpad = brcmu_pkt_buf_get_skb(pad_size);
3490 if (!bus->txglom_sgpad)
3491 brcmf_err("allocating txglom padding skb failed, reduced performance\n");
3492
3493 err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom", 3490 err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom",
3494 &value, sizeof(u32)); 3491 &value, sizeof(u32));
3495 if (err < 0) { 3492 if (err < 0) {
@@ -4053,7 +4050,6 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus)
4053 brcmf_sdio_chip_detach(&bus->ci); 4050 brcmf_sdio_chip_detach(&bus->ci);
4054 } 4051 }
4055 4052
4056 brcmu_pkt_buf_free_skb(bus->txglom_sgpad);
4057 kfree(bus->rxbuf); 4053 kfree(bus->rxbuf);
4058 kfree(bus->hdrbuf); 4054 kfree(bus->hdrbuf);
4059 kfree(bus); 4055 kfree(bus);
diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c
index d36e252d2ccb..596525528f50 100644
--- a/drivers/net/wireless/hostap/hostap_ap.c
+++ b/drivers/net/wireless/hostap/hostap_ap.c
@@ -147,7 +147,7 @@ static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
147 147
148 if (!sta->ap && sta->u.sta.challenge) 148 if (!sta->ap && sta->u.sta.challenge)
149 kfree(sta->u.sta.challenge); 149 kfree(sta->u.sta.challenge);
150 del_timer(&sta->timer); 150 del_timer_sync(&sta->timer);
151#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 151#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
152 152
153 kfree(sta); 153 kfree(sta);
diff --git a/drivers/net/wireless/hostap/hostap_proc.c b/drivers/net/wireless/hostap/hostap_proc.c
index aa7ad3a7a69b..4e5c0f8c9496 100644
--- a/drivers/net/wireless/hostap/hostap_proc.c
+++ b/drivers/net/wireless/hostap/hostap_proc.c
@@ -496,7 +496,7 @@ void hostap_init_proc(local_info_t *local)
496 496
497void hostap_remove_proc(local_info_t *local) 497void hostap_remove_proc(local_info_t *local)
498{ 498{
499 remove_proc_subtree(local->ddev->name, hostap_proc); 499 proc_remove(local->proc);
500} 500}
501 501
502 502
diff --git a/drivers/net/wireless/iwlwifi/dvm/mac80211.c b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
index c24d1d3d55f6..73086c1629ca 100644
--- a/drivers/net/wireless/iwlwifi/dvm/mac80211.c
+++ b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
@@ -696,6 +696,24 @@ static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
696 return ret; 696 return ret;
697} 697}
698 698
699static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
700{
701 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
702 return false;
703 return true;
704}
705
706static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
707{
708 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
709 return false;
710 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
711 return true;
712
713 /* disabled by default */
714 return false;
715}
716
699static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw, 717static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
700 struct ieee80211_vif *vif, 718 struct ieee80211_vif *vif,
701 enum ieee80211_ampdu_mlme_action action, 719 enum ieee80211_ampdu_mlme_action action,
@@ -717,7 +735,7 @@ static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
717 735
718 switch (action) { 736 switch (action) {
719 case IEEE80211_AMPDU_RX_START: 737 case IEEE80211_AMPDU_RX_START:
720 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) 738 if (!iwl_enable_rx_ampdu(priv->cfg))
721 break; 739 break;
722 IWL_DEBUG_HT(priv, "start Rx\n"); 740 IWL_DEBUG_HT(priv, "start Rx\n");
723 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn); 741 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
@@ -729,7 +747,7 @@ static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
729 case IEEE80211_AMPDU_TX_START: 747 case IEEE80211_AMPDU_TX_START:
730 if (!priv->trans->ops->txq_enable) 748 if (!priv->trans->ops->txq_enable)
731 break; 749 break;
732 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) 750 if (!iwl_enable_tx_ampdu(priv->cfg))
733 break; 751 break;
734 IWL_DEBUG_HT(priv, "start Tx\n"); 752 IWL_DEBUG_HT(priv, "start Tx\n");
735 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn); 753 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
diff --git a/drivers/net/wireless/iwlwifi/dvm/sta.c b/drivers/net/wireless/iwlwifi/dvm/sta.c
index c0d070c5df5e..9cdd91cdf661 100644
--- a/drivers/net/wireless/iwlwifi/dvm/sta.c
+++ b/drivers/net/wireless/iwlwifi/dvm/sta.c
@@ -590,6 +590,7 @@ void iwl_deactivate_station(struct iwl_priv *priv, const u8 sta_id,
590 sizeof(priv->tid_data[sta_id][tid])); 590 sizeof(priv->tid_data[sta_id][tid]));
591 591
592 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; 592 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
593 priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
593 594
594 priv->num_stations--; 595 priv->num_stations--;
595 596
diff --git a/drivers/net/wireless/iwlwifi/dvm/tx.c b/drivers/net/wireless/iwlwifi/dvm/tx.c
index a6839dfcb82d..398dd096674c 100644
--- a/drivers/net/wireless/iwlwifi/dvm/tx.c
+++ b/drivers/net/wireless/iwlwifi/dvm/tx.c
@@ -1291,8 +1291,6 @@ int iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
1291 struct iwl_compressed_ba_resp *ba_resp = (void *)pkt->data; 1291 struct iwl_compressed_ba_resp *ba_resp = (void *)pkt->data;
1292 struct iwl_ht_agg *agg; 1292 struct iwl_ht_agg *agg;
1293 struct sk_buff_head reclaimed_skbs; 1293 struct sk_buff_head reclaimed_skbs;
1294 struct ieee80211_tx_info *info;
1295 struct ieee80211_hdr *hdr;
1296 struct sk_buff *skb; 1294 struct sk_buff *skb;
1297 int sta_id; 1295 int sta_id;
1298 int tid; 1296 int tid;
@@ -1379,22 +1377,28 @@ int iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
1379 freed = 0; 1377 freed = 0;
1380 1378
1381 skb_queue_walk(&reclaimed_skbs, skb) { 1379 skb_queue_walk(&reclaimed_skbs, skb) {
1382 hdr = (struct ieee80211_hdr *)skb->data; 1380 struct ieee80211_hdr *hdr = (void *)skb->data;
1381 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1383 1382
1384 if (ieee80211_is_data_qos(hdr->frame_control)) 1383 if (ieee80211_is_data_qos(hdr->frame_control))
1385 freed++; 1384 freed++;
1386 else 1385 else
1387 WARN_ON_ONCE(1); 1386 WARN_ON_ONCE(1);
1388 1387
1389 info = IEEE80211_SKB_CB(skb);
1390 iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]); 1388 iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
1391 1389
1390 memset(&info->status, 0, sizeof(info->status));
1391 /* Packet was transmitted successfully, failures come as single
1392 * frames because before failing a frame the firmware transmits
1393 * it without aggregation at least once.
1394 */
1395 info->flags |= IEEE80211_TX_STAT_ACK;
1396
1392 if (freed == 1) { 1397 if (freed == 1) {
1393 /* this is the first skb we deliver in this batch */ 1398 /* this is the first skb we deliver in this batch */
1394 /* put the rate scaling data there */ 1399 /* put the rate scaling data there */
1395 info = IEEE80211_SKB_CB(skb); 1400 info = IEEE80211_SKB_CB(skb);
1396 memset(&info->status, 0, sizeof(info->status)); 1401 memset(&info->status, 0, sizeof(info->status));
1397 info->flags |= IEEE80211_TX_STAT_ACK;
1398 info->flags |= IEEE80211_TX_STAT_AMPDU; 1402 info->flags |= IEEE80211_TX_STAT_AMPDU;
1399 info->status.ampdu_ack_len = ba_resp->txed_2_done; 1403 info->status.ampdu_ack_len = ba_resp->txed_2_done;
1400 info->status.ampdu_len = ba_resp->txed; 1404 info->status.ampdu_len = ba_resp->txed;
diff --git a/drivers/net/wireless/iwlwifi/iwl-drv.c b/drivers/net/wireless/iwlwifi/iwl-drv.c
index c3728163be46..75103554cd63 100644
--- a/drivers/net/wireless/iwlwifi/iwl-drv.c
+++ b/drivers/net/wireless/iwlwifi/iwl-drv.c
@@ -1286,7 +1286,7 @@ module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO);
1286MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])"); 1286MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
1287module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO); 1287module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO);
1288MODULE_PARM_DESC(11n_disable, 1288MODULE_PARM_DESC(11n_disable,
1289 "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX"); 1289 "disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX");
1290module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K, 1290module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K,
1291 int, S_IRUGO); 1291 int, S_IRUGO);
1292MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size (default 0)"); 1292MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size (default 0)");
diff --git a/drivers/net/wireless/iwlwifi/iwl-modparams.h b/drivers/net/wireless/iwlwifi/iwl-modparams.h
index 0a84ade7edac..b29075c3da8e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-modparams.h
+++ b/drivers/net/wireless/iwlwifi/iwl-modparams.h
@@ -79,9 +79,12 @@ enum iwl_power_level {
79 IWL_POWER_NUM 79 IWL_POWER_NUM
80}; 80};
81 81
82#define IWL_DISABLE_HT_ALL BIT(0) 82enum iwl_disable_11n {
83#define IWL_DISABLE_HT_TXAGG BIT(1) 83 IWL_DISABLE_HT_ALL = BIT(0),
84#define IWL_DISABLE_HT_RXAGG BIT(2) 84 IWL_DISABLE_HT_TXAGG = BIT(1),
85 IWL_DISABLE_HT_RXAGG = BIT(2),
86 IWL_ENABLE_HT_TXAGG = BIT(3),
87};
85 88
86/** 89/**
87 * struct iwl_mod_params 90 * struct iwl_mod_params
@@ -90,7 +93,7 @@ enum iwl_power_level {
90 * 93 *
91 * @sw_crypto: using hardware encryption, default = 0 94 * @sw_crypto: using hardware encryption, default = 0
92 * @disable_11n: disable 11n capabilities, default = 0, 95 * @disable_11n: disable 11n capabilities, default = 0,
93 * use IWL_DISABLE_HT_* constants 96 * use IWL_[DIS,EN]ABLE_HT_* constants
94 * @amsdu_size_8K: enable 8K amsdu size, default = 0 97 * @amsdu_size_8K: enable 8K amsdu size, default = 0
95 * @restart_fw: restart firmware, default = 1 98 * @restart_fw: restart firmware, default = 1
96 * @wd_disable: enable stuck queue check, default = 0 99 * @wd_disable: enable stuck queue check, default = 0
diff --git a/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
index f06f4cbe1317..725e954d8475 100644
--- a/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
+++ b/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
@@ -182,6 +182,11 @@ static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
182 182
183 for (ch_idx = 0; ch_idx < IWL_NUM_CHANNELS; ch_idx++) { 183 for (ch_idx = 0; ch_idx < IWL_NUM_CHANNELS; ch_idx++) {
184 ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx); 184 ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx);
185
186 if (ch_idx >= NUM_2GHZ_CHANNELS &&
187 !data->sku_cap_band_52GHz_enable)
188 ch_flags &= ~NVM_CHANNEL_VALID;
189
185 if (!(ch_flags & NVM_CHANNEL_VALID)) { 190 if (!(ch_flags & NVM_CHANNEL_VALID)) {
186 IWL_DEBUG_EEPROM(dev, 191 IWL_DEBUG_EEPROM(dev,
187 "Ch. %d Flags %x [%sGHz] - No traffic\n", 192 "Ch. %d Flags %x [%sGHz] - No traffic\n",
diff --git a/drivers/net/wireless/iwlwifi/mvm/bt-coex.c b/drivers/net/wireless/iwlwifi/mvm/bt-coex.c
index 76cde6ce6551..18a895a949d4 100644
--- a/drivers/net/wireless/iwlwifi/mvm/bt-coex.c
+++ b/drivers/net/wireless/iwlwifi/mvm/bt-coex.c
@@ -872,8 +872,11 @@ void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
872 872
873 lockdep_assert_held(&mvm->mutex); 873 lockdep_assert_held(&mvm->mutex);
874 874
875 /* Rssi update while not associated ?! */ 875 /*
876 if (WARN_ON_ONCE(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)) 876 * Rssi update while not associated - can happen since the statistics
877 * are handled asynchronously
878 */
879 if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
877 return; 880 return;
878 881
879 /* No BT - reports should be disabled */ 882 /* No BT - reports should be disabled */
diff --git a/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h b/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h
index 73cbba7424f2..9426905de6b2 100644
--- a/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h
+++ b/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h
@@ -504,6 +504,7 @@ struct iwl_scan_offload_profile {
504 * @match_notify: clients waiting for match found notification 504 * @match_notify: clients waiting for match found notification
505 * @pass_match: clients waiting for the results 505 * @pass_match: clients waiting for the results
506 * @active_clients: active clients bitmap - enum scan_framework_client 506 * @active_clients: active clients bitmap - enum scan_framework_client
507 * @any_beacon_notify: clients waiting for match notification without match
507 */ 508 */
508struct iwl_scan_offload_profile_cfg { 509struct iwl_scan_offload_profile_cfg {
509 struct iwl_scan_offload_profile profiles[IWL_SCAN_MAX_PROFILES]; 510 struct iwl_scan_offload_profile profiles[IWL_SCAN_MAX_PROFILES];
@@ -512,7 +513,8 @@ struct iwl_scan_offload_profile_cfg {
512 u8 match_notify; 513 u8 match_notify;
513 u8 pass_match; 514 u8 pass_match;
514 u8 active_clients; 515 u8 active_clients;
515 u8 reserved[3]; 516 u8 any_beacon_notify;
517 u8 reserved[2];
516} __packed; 518} __packed;
517 519
518/** 520/**
diff --git a/drivers/net/wireless/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
index c49b5073c251..c35b8661b395 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mac80211.c
+++ b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
@@ -246,7 +246,7 @@ int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
246 else 246 else
247 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 247 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
248 248
249 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) { 249 if (0 && mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
250 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; 250 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
251 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; 251 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
252 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES; 252 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
@@ -328,6 +328,24 @@ static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
328 ieee80211_free_txskb(hw, skb); 328 ieee80211_free_txskb(hw, skb);
329} 329}
330 330
331static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
332{
333 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
334 return false;
335 return true;
336}
337
338static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
339{
340 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
341 return false;
342 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
343 return true;
344
345 /* enabled by default */
346 return true;
347}
348
331static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, 349static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
332 struct ieee80211_vif *vif, 350 struct ieee80211_vif *vif,
333 enum ieee80211_ampdu_mlme_action action, 351 enum ieee80211_ampdu_mlme_action action,
@@ -347,7 +365,7 @@ static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
347 365
348 switch (action) { 366 switch (action) {
349 case IEEE80211_AMPDU_RX_START: 367 case IEEE80211_AMPDU_RX_START:
350 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) { 368 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
351 ret = -EINVAL; 369 ret = -EINVAL;
352 break; 370 break;
353 } 371 }
@@ -357,7 +375,7 @@ static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
357 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false); 375 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
358 break; 376 break;
359 case IEEE80211_AMPDU_TX_START: 377 case IEEE80211_AMPDU_TX_START:
360 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) { 378 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
361 ret = -EINVAL; 379 ret = -EINVAL;
362 break; 380 break;
363 } 381 }
diff --git a/drivers/net/wireless/iwlwifi/mvm/mvm.h b/drivers/net/wireless/iwlwifi/mvm/mvm.h
index e4ead86f06d6..2b0ba1fc3c82 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mvm.h
+++ b/drivers/net/wireless/iwlwifi/mvm/mvm.h
@@ -152,7 +152,7 @@ enum iwl_power_scheme {
152 IWL_POWER_SCHEME_LP 152 IWL_POWER_SCHEME_LP
153}; 153};
154 154
155#define IWL_CONN_MAX_LISTEN_INTERVAL 70 155#define IWL_CONN_MAX_LISTEN_INTERVAL 10
156#define IWL_UAPSD_AC_INFO (IEEE80211_WMM_IE_STA_QOSINFO_AC_VO |\ 156#define IWL_UAPSD_AC_INFO (IEEE80211_WMM_IE_STA_QOSINFO_AC_VO |\
157 IEEE80211_WMM_IE_STA_QOSINFO_AC_VI |\ 157 IEEE80211_WMM_IE_STA_QOSINFO_AC_VI |\
158 IEEE80211_WMM_IE_STA_QOSINFO_AC_BK |\ 158 IEEE80211_WMM_IE_STA_QOSINFO_AC_BK |\
diff --git a/drivers/net/wireless/iwlwifi/mvm/scan.c b/drivers/net/wireless/iwlwifi/mvm/scan.c
index 0e0007960612..742afc429c94 100644
--- a/drivers/net/wireless/iwlwifi/mvm/scan.c
+++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
@@ -344,7 +344,8 @@ int iwl_mvm_scan_request(struct iwl_mvm *mvm,
344 344
345 iwl_mvm_scan_fill_ssids(cmd, req, basic_ssid ? 1 : 0); 345 iwl_mvm_scan_fill_ssids(cmd, req, basic_ssid ? 1 : 0);
346 346
347 cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL); 347 cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
348 TX_CMD_FLG_BT_DIS);
348 cmd->tx_cmd.sta_id = mvm->aux_sta.sta_id; 349 cmd->tx_cmd.sta_id = mvm->aux_sta.sta_id;
349 cmd->tx_cmd.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); 350 cmd->tx_cmd.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
350 cmd->tx_cmd.rate_n_flags = 351 cmd->tx_cmd.rate_n_flags =
@@ -807,6 +808,8 @@ int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
807 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN; 808 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
808 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN; 809 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
809 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN; 810 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
811 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
812 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
810 813
811 for (i = 0; i < req->n_match_sets; i++) { 814 for (i = 0; i < req->n_match_sets; i++) {
812 profile = &profile_cfg->profiles[i]; 815 profile = &profile_cfg->profiles[i];
diff --git a/drivers/net/wireless/iwlwifi/mvm/sta.c b/drivers/net/wireless/iwlwifi/mvm/sta.c
index ec1812133235..3397f59cd4e4 100644
--- a/drivers/net/wireless/iwlwifi/mvm/sta.c
+++ b/drivers/net/wireless/iwlwifi/mvm/sta.c
@@ -652,7 +652,7 @@ int iwl_mvm_send_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
652{ 652{
653 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 653 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
654 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 654 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
655 static const u8 *baddr = _baddr; 655 const u8 *baddr = _baddr;
656 656
657 lockdep_assert_held(&mvm->mutex); 657 lockdep_assert_held(&mvm->mutex);
658 658
diff --git a/drivers/net/wireless/iwlwifi/mvm/tx.c b/drivers/net/wireless/iwlwifi/mvm/tx.c
index 90378c217bc7..76ee486039d7 100644
--- a/drivers/net/wireless/iwlwifi/mvm/tx.c
+++ b/drivers/net/wireless/iwlwifi/mvm/tx.c
@@ -659,8 +659,14 @@ static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm,
659 rcu_read_lock(); 659 rcu_read_lock();
660 660
661 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); 661 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
662 /*
663 * sta can't be NULL otherwise it'd mean that the sta has been freed in
664 * the firmware while we still have packets for it in the Tx queues.
665 */
666 if (WARN_ON_ONCE(!sta))
667 goto out;
662 668
663 if (!IS_ERR_OR_NULL(sta)) { 669 if (!IS_ERR(sta)) {
664 mvmsta = iwl_mvm_sta_from_mac80211(sta); 670 mvmsta = iwl_mvm_sta_from_mac80211(sta);
665 671
666 if (tid != IWL_TID_NON_QOS) { 672 if (tid != IWL_TID_NON_QOS) {
@@ -675,7 +681,6 @@ static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm,
675 spin_unlock_bh(&mvmsta->lock); 681 spin_unlock_bh(&mvmsta->lock);
676 } 682 }
677 } else { 683 } else {
678 sta = NULL;
679 mvmsta = NULL; 684 mvmsta = NULL;
680 } 685 }
681 686
@@ -683,42 +688,38 @@ static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm,
683 * If the txq is not an AMPDU queue, there is no chance we freed 688 * If the txq is not an AMPDU queue, there is no chance we freed
684 * several skbs. Check that out... 689 * several skbs. Check that out...
685 */ 690 */
686 if (txq_id < mvm->first_agg_queue && !WARN_ON(skb_freed > 1) && 691 if (txq_id >= mvm->first_agg_queue)
687 atomic_sub_and_test(skb_freed, &mvm->pending_frames[sta_id])) { 692 goto out;
688 if (mvmsta) { 693
689 /* 694 /* We can't free more than one frame at once on a shared queue */
690 * If there are no pending frames for this STA, notify 695 WARN_ON(skb_freed > 1);
691 * mac80211 that this station can go to sleep in its 696
692 * STA table. 697 /* If we have still frames from this STA nothing to do here */
693 */ 698 if (!atomic_sub_and_test(skb_freed, &mvm->pending_frames[sta_id]))
694 if (mvmsta->vif->type == NL80211_IFTYPE_AP) 699 goto out;
695 ieee80211_sta_block_awake(mvm->hw, sta, false); 700
696 /* 701 if (mvmsta && mvmsta->vif->type == NL80211_IFTYPE_AP) {
697 * We might very well have taken mvmsta pointer while 702 /*
698 * the station was being removed. The remove flow might 703 * If there are no pending frames for this STA, notify
699 * have seen a pending_frame (because we didn't take 704 * mac80211 that this station can go to sleep in its
700 * the lock) even if now the queues are drained. So make 705 * STA table.
701 * really sure now that this the station is not being 706 * If mvmsta is not NULL, sta is valid.
702 * removed. If it is, run the drain worker to remove it. 707 */
703 */ 708 ieee80211_sta_block_awake(mvm->hw, sta, false);
704 spin_lock_bh(&mvmsta->lock);
705 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
706 if (!sta || PTR_ERR(sta) == -EBUSY) {
707 /*
708 * Station disappeared in the meantime:
709 * so we are draining.
710 */
711 set_bit(sta_id, mvm->sta_drained);
712 schedule_work(&mvm->sta_drained_wk);
713 }
714 spin_unlock_bh(&mvmsta->lock);
715 } else if (!mvmsta && PTR_ERR(sta) == -EBUSY) {
716 /* Tx response without STA, so we are draining */
717 set_bit(sta_id, mvm->sta_drained);
718 schedule_work(&mvm->sta_drained_wk);
719 }
720 } 709 }
721 710
711 if (PTR_ERR(sta) == -EBUSY || PTR_ERR(sta) == -ENOENT) {
712 /*
713 * We are draining and this was the last packet - pre_rcu_remove
714 * has been called already. We might be after the
715 * synchronize_net already.
716 * Don't rely on iwl_mvm_rm_sta to see the empty Tx queues.
717 */
718 set_bit(sta_id, mvm->sta_drained);
719 schedule_work(&mvm->sta_drained_wk);
720 }
721
722out:
722 rcu_read_unlock(); 723 rcu_read_unlock();
723} 724}
724 725
@@ -821,16 +822,12 @@ int iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
821 struct iwl_mvm_ba_notif *ba_notif = (void *)pkt->data; 822 struct iwl_mvm_ba_notif *ba_notif = (void *)pkt->data;
822 struct sk_buff_head reclaimed_skbs; 823 struct sk_buff_head reclaimed_skbs;
823 struct iwl_mvm_tid_data *tid_data; 824 struct iwl_mvm_tid_data *tid_data;
824 struct ieee80211_tx_info *info;
825 struct ieee80211_sta *sta; 825 struct ieee80211_sta *sta;
826 struct iwl_mvm_sta *mvmsta; 826 struct iwl_mvm_sta *mvmsta;
827 struct ieee80211_hdr *hdr;
828 struct sk_buff *skb; 827 struct sk_buff *skb;
829 int sta_id, tid, freed; 828 int sta_id, tid, freed;
830
831 /* "flow" corresponds to Tx queue */ 829 /* "flow" corresponds to Tx queue */
832 u16 scd_flow = le16_to_cpu(ba_notif->scd_flow); 830 u16 scd_flow = le16_to_cpu(ba_notif->scd_flow);
833
834 /* "ssn" is start of block-ack Tx window, corresponds to index 831 /* "ssn" is start of block-ack Tx window, corresponds to index
835 * (in Tx queue's circular buffer) of first TFD/frame in window */ 832 * (in Tx queue's circular buffer) of first TFD/frame in window */
836 u16 ba_resp_scd_ssn = le16_to_cpu(ba_notif->scd_ssn); 833 u16 ba_resp_scd_ssn = le16_to_cpu(ba_notif->scd_ssn);
@@ -887,22 +884,26 @@ int iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
887 freed = 0; 884 freed = 0;
888 885
889 skb_queue_walk(&reclaimed_skbs, skb) { 886 skb_queue_walk(&reclaimed_skbs, skb) {
890 hdr = (struct ieee80211_hdr *)skb->data; 887 struct ieee80211_hdr *hdr = (void *)skb->data;
888 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
891 889
892 if (ieee80211_is_data_qos(hdr->frame_control)) 890 if (ieee80211_is_data_qos(hdr->frame_control))
893 freed++; 891 freed++;
894 else 892 else
895 WARN_ON_ONCE(1); 893 WARN_ON_ONCE(1);
896 894
897 info = IEEE80211_SKB_CB(skb);
898 iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]); 895 iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
899 896
897 memset(&info->status, 0, sizeof(info->status));
898 /* Packet was transmitted successfully, failures come as single
899 * frames because before failing a frame the firmware transmits
900 * it without aggregation at least once.
901 */
902 info->flags |= IEEE80211_TX_STAT_ACK;
903
900 if (freed == 1) { 904 if (freed == 1) {
901 /* this is the first skb we deliver in this batch */ 905 /* this is the first skb we deliver in this batch */
902 /* put the rate scaling data there */ 906 /* put the rate scaling data there */
903 info = IEEE80211_SKB_CB(skb);
904 memset(&info->status, 0, sizeof(info->status));
905 info->flags |= IEEE80211_TX_STAT_ACK;
906 info->flags |= IEEE80211_TX_STAT_AMPDU; 907 info->flags |= IEEE80211_TX_STAT_AMPDU;
907 info->status.ampdu_ack_len = ba_notif->txed_2_done; 908 info->status.ampdu_ack_len = ba_notif->txed_2_done;
908 info->status.ampdu_len = ba_notif->txed; 909 info->status.ampdu_len = ba_notif->txed;
diff --git a/drivers/net/wireless/iwlwifi/mvm/utils.c b/drivers/net/wireless/iwlwifi/mvm/utils.c
index a4a5e25623c3..86989df69356 100644
--- a/drivers/net/wireless/iwlwifi/mvm/utils.c
+++ b/drivers/net/wireless/iwlwifi/mvm/utils.c
@@ -411,6 +411,8 @@ void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
411 mvm->status, table.valid); 411 mvm->status, table.valid);
412 } 412 }
413 413
414 IWL_ERR(mvm, "Loaded firmware version: %s\n", mvm->fw->fw_version);
415
414 trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low, 416 trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
415 table.data1, table.data2, table.data3, 417 table.data1, table.data2, table.data3,
416 table.blink1, table.blink2, table.ilink1, 418 table.blink1, table.blink2, table.ilink1,
diff --git a/drivers/net/wireless/iwlwifi/pcie/drv.c b/drivers/net/wireless/iwlwifi/pcie/drv.c
index 3040924f5f3c..3872ead75488 100644
--- a/drivers/net/wireless/iwlwifi/pcie/drv.c
+++ b/drivers/net/wireless/iwlwifi/pcie/drv.c
@@ -359,20 +359,24 @@ static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
359/* 7265 Series */ 359/* 7265 Series */
360 {IWL_PCI_DEVICE(0x095A, 0x5010, iwl7265_2ac_cfg)}, 360 {IWL_PCI_DEVICE(0x095A, 0x5010, iwl7265_2ac_cfg)},
361 {IWL_PCI_DEVICE(0x095A, 0x5110, iwl7265_2ac_cfg)}, 361 {IWL_PCI_DEVICE(0x095A, 0x5110, iwl7265_2ac_cfg)},
362 {IWL_PCI_DEVICE(0x095A, 0x5100, iwl7265_2ac_cfg)},
362 {IWL_PCI_DEVICE(0x095B, 0x5310, iwl7265_2ac_cfg)}, 363 {IWL_PCI_DEVICE(0x095B, 0x5310, iwl7265_2ac_cfg)},
363 {IWL_PCI_DEVICE(0x095B, 0x5302, iwl7265_2ac_cfg)}, 364 {IWL_PCI_DEVICE(0x095B, 0x5302, iwl7265_n_cfg)},
364 {IWL_PCI_DEVICE(0x095B, 0x5210, iwl7265_2ac_cfg)}, 365 {IWL_PCI_DEVICE(0x095B, 0x5210, iwl7265_2ac_cfg)},
365 {IWL_PCI_DEVICE(0x095A, 0x5012, iwl7265_2ac_cfg)}, 366 {IWL_PCI_DEVICE(0x095A, 0x5012, iwl7265_2ac_cfg)},
366 {IWL_PCI_DEVICE(0x095A, 0x500A, iwl7265_2ac_cfg)}, 367 {IWL_PCI_DEVICE(0x095A, 0x5412, iwl7265_2ac_cfg)},
367 {IWL_PCI_DEVICE(0x095A, 0x5410, iwl7265_2ac_cfg)}, 368 {IWL_PCI_DEVICE(0x095A, 0x5410, iwl7265_2ac_cfg)},
368 {IWL_PCI_DEVICE(0x095A, 0x5400, iwl7265_2ac_cfg)}, 369 {IWL_PCI_DEVICE(0x095A, 0x5400, iwl7265_2ac_cfg)},
369 {IWL_PCI_DEVICE(0x095A, 0x1010, iwl7265_2ac_cfg)}, 370 {IWL_PCI_DEVICE(0x095A, 0x1010, iwl7265_2ac_cfg)},
370 {IWL_PCI_DEVICE(0x095A, 0x5000, iwl7265_2n_cfg)}, 371 {IWL_PCI_DEVICE(0x095A, 0x5000, iwl7265_2n_cfg)},
372 {IWL_PCI_DEVICE(0x095A, 0x500A, iwl7265_2n_cfg)},
371 {IWL_PCI_DEVICE(0x095B, 0x5200, iwl7265_2n_cfg)}, 373 {IWL_PCI_DEVICE(0x095B, 0x5200, iwl7265_2n_cfg)},
372 {IWL_PCI_DEVICE(0x095A, 0x5002, iwl7265_n_cfg)}, 374 {IWL_PCI_DEVICE(0x095A, 0x5002, iwl7265_n_cfg)},
373 {IWL_PCI_DEVICE(0x095B, 0x5202, iwl7265_n_cfg)}, 375 {IWL_PCI_DEVICE(0x095B, 0x5202, iwl7265_n_cfg)},
374 {IWL_PCI_DEVICE(0x095A, 0x9010, iwl7265_2ac_cfg)}, 376 {IWL_PCI_DEVICE(0x095A, 0x9010, iwl7265_2ac_cfg)},
377 {IWL_PCI_DEVICE(0x095A, 0x9012, iwl7265_2ac_cfg)},
375 {IWL_PCI_DEVICE(0x095A, 0x9110, iwl7265_2ac_cfg)}, 378 {IWL_PCI_DEVICE(0x095A, 0x9110, iwl7265_2ac_cfg)},
379 {IWL_PCI_DEVICE(0x095A, 0x9112, iwl7265_2ac_cfg)},
376 {IWL_PCI_DEVICE(0x095A, 0x9210, iwl7265_2ac_cfg)}, 380 {IWL_PCI_DEVICE(0x095A, 0x9210, iwl7265_2ac_cfg)},
377 {IWL_PCI_DEVICE(0x095A, 0x9510, iwl7265_2ac_cfg)}, 381 {IWL_PCI_DEVICE(0x095A, 0x9510, iwl7265_2ac_cfg)},
378 {IWL_PCI_DEVICE(0x095A, 0x9310, iwl7265_2ac_cfg)}, 382 {IWL_PCI_DEVICE(0x095A, 0x9310, iwl7265_2ac_cfg)},
diff --git a/drivers/net/wireless/libertas/cfg.c b/drivers/net/wireless/libertas/cfg.c
index 32f75007a825..cb6d189bc3e6 100644
--- a/drivers/net/wireless/libertas/cfg.c
+++ b/drivers/net/wireless/libertas/cfg.c
@@ -621,7 +621,7 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
621 id = *pos++; 621 id = *pos++;
622 elen = *pos++; 622 elen = *pos++;
623 left -= 2; 623 left -= 2;
624 if (elen > left || elen == 0) { 624 if (elen > left) {
625 lbs_deb_scan("scan response: invalid IE fmt\n"); 625 lbs_deb_scan("scan response: invalid IE fmt\n");
626 goto done; 626 goto done;
627 } 627 }
diff --git a/drivers/net/wireless/mwifiex/11ac.c b/drivers/net/wireless/mwifiex/11ac.c
index 5e0eec4d71c7..5d9a8084665d 100644
--- a/drivers/net/wireless/mwifiex/11ac.c
+++ b/drivers/net/wireless/mwifiex/11ac.c
@@ -189,8 +189,7 @@ int mwifiex_cmd_append_11ac_tlv(struct mwifiex_private *priv,
189 vht_cap->header.len = 189 vht_cap->header.len =
190 cpu_to_le16(sizeof(struct ieee80211_vht_cap)); 190 cpu_to_le16(sizeof(struct ieee80211_vht_cap));
191 memcpy((u8 *)vht_cap + sizeof(struct mwifiex_ie_types_header), 191 memcpy((u8 *)vht_cap + sizeof(struct mwifiex_ie_types_header),
192 (u8 *)bss_desc->bcn_vht_cap + 192 (u8 *)bss_desc->bcn_vht_cap,
193 sizeof(struct ieee_types_header),
194 le16_to_cpu(vht_cap->header.len)); 193 le16_to_cpu(vht_cap->header.len));
195 194
196 mwifiex_fill_vht_cap_tlv(priv, vht_cap, bss_desc->bss_band); 195 mwifiex_fill_vht_cap_tlv(priv, vht_cap, bss_desc->bss_band);
diff --git a/drivers/net/wireless/mwifiex/11n.c b/drivers/net/wireless/mwifiex/11n.c
index 6261f8c53d44..7db1a89fdd95 100644
--- a/drivers/net/wireless/mwifiex/11n.c
+++ b/drivers/net/wireless/mwifiex/11n.c
@@ -308,8 +308,7 @@ mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
308 ht_cap->header.len = 308 ht_cap->header.len =
309 cpu_to_le16(sizeof(struct ieee80211_ht_cap)); 309 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
310 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header), 310 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
311 (u8 *) bss_desc->bcn_ht_cap + 311 (u8 *)bss_desc->bcn_ht_cap,
312 sizeof(struct ieee_types_header),
313 le16_to_cpu(ht_cap->header.len)); 312 le16_to_cpu(ht_cap->header.len));
314 313
315 mwifiex_fill_cap_info(priv, radio_type, ht_cap); 314 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
diff --git a/drivers/net/wireless/mwifiex/main.c b/drivers/net/wireless/mwifiex/main.c
index 4d79761b9c87..9d3d2758ec35 100644
--- a/drivers/net/wireless/mwifiex/main.c
+++ b/drivers/net/wireless/mwifiex/main.c
@@ -748,7 +748,7 @@ static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
748 748
749static u16 749static u16
750mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb, 750mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
751 void *accel_priv) 751 void *accel_priv, select_queue_fallback_t fallback)
752{ 752{
753 skb->priority = cfg80211_classify8021d(skb, NULL); 753 skb->priority = cfg80211_classify8021d(skb, NULL);
754 return mwifiex_1d_to_wmm_queue[skb->priority]; 754 return mwifiex_1d_to_wmm_queue[skb->priority];
diff --git a/drivers/net/wireless/mwifiex/pcie.c b/drivers/net/wireless/mwifiex/pcie.c
index 03688aa14e8a..7fe7b53fb17a 100644
--- a/drivers/net/wireless/mwifiex/pcie.c
+++ b/drivers/net/wireless/mwifiex/pcie.c
@@ -1211,6 +1211,12 @@ static int mwifiex_pcie_process_recv_data(struct mwifiex_adapter *adapter)
1211 rd_index = card->rxbd_rdptr & reg->rx_mask; 1211 rd_index = card->rxbd_rdptr & reg->rx_mask;
1212 skb_data = card->rx_buf_list[rd_index]; 1212 skb_data = card->rx_buf_list[rd_index];
1213 1213
1214 /* If skb allocation was failed earlier for Rx packet,
1215 * rx_buf_list[rd_index] would have been left with a NULL.
1216 */
1217 if (!skb_data)
1218 return -ENOMEM;
1219
1214 MWIFIEX_SKB_PACB(skb_data, &buf_pa); 1220 MWIFIEX_SKB_PACB(skb_data, &buf_pa);
1215 pci_unmap_single(card->dev, buf_pa, MWIFIEX_RX_DATA_BUF_SIZE, 1221 pci_unmap_single(card->dev, buf_pa, MWIFIEX_RX_DATA_BUF_SIZE,
1216 PCI_DMA_FROMDEVICE); 1222 PCI_DMA_FROMDEVICE);
@@ -1525,6 +1531,14 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
1525 if (adapter->ps_state == PS_STATE_SLEEP_CFM) { 1531 if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
1526 mwifiex_process_sleep_confirm_resp(adapter, skb->data, 1532 mwifiex_process_sleep_confirm_resp(adapter, skb->data,
1527 skb->len); 1533 skb->len);
1534 mwifiex_pcie_enable_host_int(adapter);
1535 if (mwifiex_write_reg(adapter,
1536 PCIE_CPU_INT_EVENT,
1537 CPU_INTR_SLEEP_CFM_DONE)) {
1538 dev_warn(adapter->dev,
1539 "Write register failed\n");
1540 return -1;
1541 }
1528 while (reg->sleep_cookie && (count++ < 10) && 1542 while (reg->sleep_cookie && (count++ < 10) &&
1529 mwifiex_pcie_ok_to_access_hw(adapter)) 1543 mwifiex_pcie_ok_to_access_hw(adapter))
1530 usleep_range(50, 60); 1544 usleep_range(50, 60);
@@ -1993,23 +2007,9 @@ static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
1993 adapter->int_status |= pcie_ireg; 2007 adapter->int_status |= pcie_ireg;
1994 spin_unlock_irqrestore(&adapter->int_lock, flags); 2008 spin_unlock_irqrestore(&adapter->int_lock, flags);
1995 2009
1996 if (pcie_ireg & HOST_INTR_CMD_DONE) { 2010 if (!adapter->pps_uapsd_mode &&
1997 if ((adapter->ps_state == PS_STATE_SLEEP_CFM) || 2011 adapter->ps_state == PS_STATE_SLEEP &&
1998 (adapter->ps_state == PS_STATE_SLEEP)) { 2012 mwifiex_pcie_ok_to_access_hw(adapter)) {
1999 mwifiex_pcie_enable_host_int(adapter);
2000 if (mwifiex_write_reg(adapter,
2001 PCIE_CPU_INT_EVENT,
2002 CPU_INTR_SLEEP_CFM_DONE)
2003 ) {
2004 dev_warn(adapter->dev,
2005 "Write register failed\n");
2006 return;
2007
2008 }
2009 }
2010 } else if (!adapter->pps_uapsd_mode &&
2011 adapter->ps_state == PS_STATE_SLEEP &&
2012 mwifiex_pcie_ok_to_access_hw(adapter)) {
2013 /* Potentially for PCIe we could get other 2013 /* Potentially for PCIe we could get other
2014 * interrupts like shared. Don't change power 2014 * interrupts like shared. Don't change power
2015 * state until cookie is set */ 2015 * state until cookie is set */
diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index 0a8a26e10f01..668547c2de84 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -2101,12 +2101,12 @@ mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2101 curr_bss->ht_info_offset); 2101 curr_bss->ht_info_offset);
2102 2102
2103 if (curr_bss->bcn_vht_cap) 2103 if (curr_bss->bcn_vht_cap)
2104 curr_bss->bcn_ht_cap = (void *)(curr_bss->beacon_buf + 2104 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2105 curr_bss->vht_cap_offset); 2105 curr_bss->vht_cap_offset);
2106 2106
2107 if (curr_bss->bcn_vht_oper) 2107 if (curr_bss->bcn_vht_oper)
2108 curr_bss->bcn_ht_oper = (void *)(curr_bss->beacon_buf + 2108 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2109 curr_bss->vht_info_offset); 2109 curr_bss->vht_info_offset);
2110 2110
2111 if (curr_bss->bcn_bss_co_2040) 2111 if (curr_bss->bcn_bss_co_2040)
2112 curr_bss->bcn_bss_co_2040 = 2112 curr_bss->bcn_bss_co_2040 =
diff --git a/drivers/net/wireless/mwifiex/usb.c b/drivers/net/wireless/mwifiex/usb.c
index e8ebbd4bc3cd..208748804a55 100644
--- a/drivers/net/wireless/mwifiex/usb.c
+++ b/drivers/net/wireless/mwifiex/usb.c
@@ -22,8 +22,6 @@
22 22
23#define USB_VERSION "1.0" 23#define USB_VERSION "1.0"
24 24
25static const char usbdriver_name[] = "usb8xxx";
26
27static struct mwifiex_if_ops usb_ops; 25static struct mwifiex_if_ops usb_ops;
28static struct semaphore add_remove_card_sem; 26static struct semaphore add_remove_card_sem;
29static struct usb_card_rec *usb_card; 27static struct usb_card_rec *usb_card;
@@ -527,13 +525,6 @@ static int mwifiex_usb_resume(struct usb_interface *intf)
527 MWIFIEX_BSS_ROLE_ANY), 525 MWIFIEX_BSS_ROLE_ANY),
528 MWIFIEX_ASYNC_CMD); 526 MWIFIEX_ASYNC_CMD);
529 527
530#ifdef CONFIG_PM
531 /* Resume handler may be called due to remote wakeup,
532 * force to exit suspend anyway
533 */
534 usb_disable_autosuspend(card->udev);
535#endif /* CONFIG_PM */
536
537 return 0; 528 return 0;
538} 529}
539 530
@@ -567,13 +558,12 @@ static void mwifiex_usb_disconnect(struct usb_interface *intf)
567} 558}
568 559
569static struct usb_driver mwifiex_usb_driver = { 560static struct usb_driver mwifiex_usb_driver = {
570 .name = usbdriver_name, 561 .name = "mwifiex_usb",
571 .probe = mwifiex_usb_probe, 562 .probe = mwifiex_usb_probe,
572 .disconnect = mwifiex_usb_disconnect, 563 .disconnect = mwifiex_usb_disconnect,
573 .id_table = mwifiex_usb_table, 564 .id_table = mwifiex_usb_table,
574 .suspend = mwifiex_usb_suspend, 565 .suspend = mwifiex_usb_suspend,
575 .resume = mwifiex_usb_resume, 566 .resume = mwifiex_usb_resume,
576 .supports_autosuspend = 1,
577}; 567};
578 568
579static int mwifiex_usb_tx_init(struct mwifiex_adapter *adapter) 569static int mwifiex_usb_tx_init(struct mwifiex_adapter *adapter)
diff --git a/drivers/net/wireless/mwifiex/wmm.c b/drivers/net/wireless/mwifiex/wmm.c
index 13eaeed03898..981cf6e7c73b 100644
--- a/drivers/net/wireless/mwifiex/wmm.c
+++ b/drivers/net/wireless/mwifiex/wmm.c
@@ -559,7 +559,8 @@ mwifiex_clean_txrx(struct mwifiex_private *priv)
559 mwifiex_wmm_delete_all_ralist(priv); 559 mwifiex_wmm_delete_all_ralist(priv);
560 memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid)); 560 memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid));
561 561
562 if (priv->adapter->if_ops.clean_pcie_ring) 562 if (priv->adapter->if_ops.clean_pcie_ring &&
563 !priv->adapter->surprise_removed)
563 priv->adapter->if_ops.clean_pcie_ring(priv->adapter); 564 priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
564 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags); 565 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
565} 566}
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c
index abc5f56f29fe..2f1cd929c6f6 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.c
+++ b/drivers/net/wireless/rt2x00/rt2500pci.c
@@ -1877,6 +1877,11 @@ static int rt2500pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1877 EEPROM_MAC_ADDR_0)); 1877 EEPROM_MAC_ADDR_0));
1878 1878
1879 /* 1879 /*
1880 * Disable powersaving as default.
1881 */
1882 rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
1883
1884 /*
1880 * Initialize hw_mode information. 1885 * Initialize hw_mode information.
1881 */ 1886 */
1882 spec->supported_bands = SUPPORT_BAND_2GHZ; 1887 spec->supported_bands = SUPPORT_BAND_2GHZ;
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index 9f16824cd1bc..d849d590de25 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -1706,6 +1706,11 @@ static int rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1706 IEEE80211_HW_SUPPORTS_PS | 1706 IEEE80211_HW_SUPPORTS_PS |
1707 IEEE80211_HW_PS_NULLFUNC_STACK; 1707 IEEE80211_HW_PS_NULLFUNC_STACK;
1708 1708
1709 /*
1710 * Disable powersaving as default.
1711 */
1712 rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
1713
1709 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev); 1714 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
1710 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, 1715 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
1711 rt2x00_eeprom_addr(rt2x00dev, 1716 rt2x00_eeprom_addr(rt2x00dev,
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index b8f5b06006c4..41d4a8167dc3 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -5460,14 +5460,15 @@ static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev)
5460 5460
5461 rt2800_bbp_write(rt2x00dev, 68, 0x0b); 5461 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
5462 5462
5463 rt2800_bbp_write(rt2x00dev, 69, 0x0d); 5463 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5464 rt2800_bbp_write(rt2x00dev, 70, 0x06);
5465 rt2800_bbp_write(rt2x00dev, 73, 0x13); 5464 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5466 rt2800_bbp_write(rt2x00dev, 75, 0x46); 5465 rt2800_bbp_write(rt2x00dev, 75, 0x46);
5467 rt2800_bbp_write(rt2x00dev, 76, 0x28); 5466 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5468 5467
5469 rt2800_bbp_write(rt2x00dev, 77, 0x59); 5468 rt2800_bbp_write(rt2x00dev, 77, 0x59);
5470 5469
5470 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5471
5471 rt2800_bbp_write(rt2x00dev, 79, 0x13); 5472 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5472 rt2800_bbp_write(rt2x00dev, 80, 0x05); 5473 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5473 rt2800_bbp_write(rt2x00dev, 81, 0x33); 5474 rt2800_bbp_write(rt2x00dev, 81, 0x33);
@@ -5510,7 +5511,6 @@ static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev)
5510 if (rt2x00_rt(rt2x00dev, RT5392)) { 5511 if (rt2x00_rt(rt2x00dev, RT5392)) {
5511 rt2800_bbp_write(rt2x00dev, 134, 0xd0); 5512 rt2800_bbp_write(rt2x00dev, 134, 0xd0);
5512 rt2800_bbp_write(rt2x00dev, 135, 0xf6); 5513 rt2800_bbp_write(rt2x00dev, 135, 0xf6);
5513 rt2800_bbp_write(rt2x00dev, 148, 0x84);
5514 } 5514 }
5515 5515
5516 rt2800_disable_unused_dac_adc(rt2x00dev); 5516 rt2800_disable_unused_dac_adc(rt2x00dev);
@@ -7458,10 +7458,9 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
7458 u32 reg; 7458 u32 reg;
7459 7459
7460 /* 7460 /*
7461 * Disable powersaving as default on PCI devices. 7461 * Disable powersaving as default.
7462 */ 7462 */
7463 if (rt2x00_is_pci(rt2x00dev) || rt2x00_is_soc(rt2x00dev)) 7463 rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
7464 rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
7465 7464
7466 /* 7465 /*
7467 * Initialize all hw fields. 7466 * Initialize all hw fields.
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index caddc1b427a9..42a2e06512f2 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -764,7 +764,7 @@ static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
764 /* 764 /*
765 * Overwrite TX done handler 765 * Overwrite TX done handler
766 */ 766 */
767 PREPARE_WORK(&rt2x00dev->txdone_work, rt2800usb_work_txdone); 767 INIT_WORK(&rt2x00dev->txdone_work, rt2800usb_work_txdone);
768 768
769 return 0; 769 return 0;
770} 770}
diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c
index 8ec17aad0e52..3867d1470b36 100644
--- a/drivers/net/wireless/rtl818x/rtl8180/dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8180/dev.c
@@ -107,6 +107,7 @@ static void rtl8180_handle_rx(struct ieee80211_hw *dev)
107 struct rtl8180_priv *priv = dev->priv; 107 struct rtl8180_priv *priv = dev->priv;
108 unsigned int count = 32; 108 unsigned int count = 32;
109 u8 signal, agc, sq; 109 u8 signal, agc, sq;
110 dma_addr_t mapping;
110 111
111 while (count--) { 112 while (count--) {
112 struct rtl8180_rx_desc *entry = &priv->rx_ring[priv->rx_idx]; 113 struct rtl8180_rx_desc *entry = &priv->rx_ring[priv->rx_idx];
@@ -128,6 +129,17 @@ static void rtl8180_handle_rx(struct ieee80211_hw *dev)
128 if (unlikely(!new_skb)) 129 if (unlikely(!new_skb))
129 goto done; 130 goto done;
130 131
132 mapping = pci_map_single(priv->pdev,
133 skb_tail_pointer(new_skb),
134 MAX_RX_SIZE, PCI_DMA_FROMDEVICE);
135
136 if (pci_dma_mapping_error(priv->pdev, mapping)) {
137 kfree_skb(new_skb);
138 dev_err(&priv->pdev->dev, "RX DMA map error\n");
139
140 goto done;
141 }
142
131 pci_unmap_single(priv->pdev, 143 pci_unmap_single(priv->pdev,
132 *((dma_addr_t *)skb->cb), 144 *((dma_addr_t *)skb->cb),
133 MAX_RX_SIZE, PCI_DMA_FROMDEVICE); 145 MAX_RX_SIZE, PCI_DMA_FROMDEVICE);
@@ -158,9 +170,7 @@ static void rtl8180_handle_rx(struct ieee80211_hw *dev)
158 170
159 skb = new_skb; 171 skb = new_skb;
160 priv->rx_buf[priv->rx_idx] = skb; 172 priv->rx_buf[priv->rx_idx] = skb;
161 *((dma_addr_t *) skb->cb) = 173 *((dma_addr_t *) skb->cb) = mapping;
162 pci_map_single(priv->pdev, skb_tail_pointer(skb),
163 MAX_RX_SIZE, PCI_DMA_FROMDEVICE);
164 } 174 }
165 175
166 done: 176 done:
@@ -266,6 +276,13 @@ static void rtl8180_tx(struct ieee80211_hw *dev,
266 mapping = pci_map_single(priv->pdev, skb->data, 276 mapping = pci_map_single(priv->pdev, skb->data,
267 skb->len, PCI_DMA_TODEVICE); 277 skb->len, PCI_DMA_TODEVICE);
268 278
279 if (pci_dma_mapping_error(priv->pdev, mapping)) {
280 kfree_skb(skb);
281 dev_err(&priv->pdev->dev, "TX DMA mapping error\n");
282 return;
283
284 }
285
269 tx_flags = RTL818X_TX_DESC_FLAG_OWN | RTL818X_TX_DESC_FLAG_FS | 286 tx_flags = RTL818X_TX_DESC_FLAG_OWN | RTL818X_TX_DESC_FLAG_FS |
270 RTL818X_TX_DESC_FLAG_LS | 287 RTL818X_TX_DESC_FLAG_LS |
271 (ieee80211_get_tx_rate(dev, info)->hw_value << 24) | 288 (ieee80211_get_tx_rate(dev, info)->hw_value << 24) |
diff --git a/drivers/net/wireless/rtl818x/rtl8187/rtl8187.h b/drivers/net/wireless/rtl818x/rtl8187/rtl8187.h
index 56aee067f324..a6ad79f61bf9 100644
--- a/drivers/net/wireless/rtl818x/rtl8187/rtl8187.h
+++ b/drivers/net/wireless/rtl818x/rtl8187/rtl8187.h
@@ -15,6 +15,8 @@
15#ifndef RTL8187_H 15#ifndef RTL8187_H
16#define RTL8187_H 16#define RTL8187_H
17 17
18#include <linux/cache.h>
19
18#include "rtl818x.h" 20#include "rtl818x.h"
19#include "leds.h" 21#include "leds.h"
20 22
@@ -139,7 +141,10 @@ struct rtl8187_priv {
139 u8 aifsn[4]; 141 u8 aifsn[4];
140 u8 rfkill_mask; 142 u8 rfkill_mask;
141 struct { 143 struct {
142 __le64 buf; 144 union {
145 __le64 buf;
146 u8 dummy1[L1_CACHE_BYTES];
147 } ____cacheline_aligned;
143 struct sk_buff_head queue; 148 struct sk_buff_head queue;
144 } b_tx_status; /* This queue is used by both -b and non-b devices */ 149 } b_tx_status; /* This queue is used by both -b and non-b devices */
145 struct mutex io_mutex; 150 struct mutex io_mutex;
@@ -147,7 +152,8 @@ struct rtl8187_priv {
147 u8 bits8; 152 u8 bits8;
148 __le16 bits16; 153 __le16 bits16;
149 __le32 bits32; 154 __le32 bits32;
150 } *io_dmabuf; 155 u8 dummy2[L1_CACHE_BYTES];
156 } *io_dmabuf ____cacheline_aligned;
151 bool rfkill_off; 157 bool rfkill_off;
152 u16 seqno; 158 u16 seqno;
153}; 159};
diff --git a/drivers/net/wireless/rtlwifi/ps.c b/drivers/net/wireless/rtlwifi/ps.c
index deedae3c5449..d1c0191a195b 100644
--- a/drivers/net/wireless/rtlwifi/ps.c
+++ b/drivers/net/wireless/rtlwifi/ps.c
@@ -48,7 +48,7 @@ bool rtl_ps_enable_nic(struct ieee80211_hw *hw)
48 48
49 /*<2> Enable Adapter */ 49 /*<2> Enable Adapter */
50 if (rtlpriv->cfg->ops->hw_init(hw)) 50 if (rtlpriv->cfg->ops->hw_init(hw))
51 return 1; 51 return false;
52 RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); 52 RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
53 53
54 /*<3> Enable Interrupt */ 54 /*<3> Enable Interrupt */
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
index a82b30a1996c..2eb0b38384dd 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
@@ -937,14 +937,26 @@ int rtl92ce_hw_init(struct ieee80211_hw *hw)
937 bool is92c; 937 bool is92c;
938 int err; 938 int err;
939 u8 tmp_u1b; 939 u8 tmp_u1b;
940 unsigned long flags;
940 941
941 rtlpci->being_init_adapter = true; 942 rtlpci->being_init_adapter = true;
943
944 /* Since this function can take a very long time (up to 350 ms)
945 * and can be called with irqs disabled, reenable the irqs
946 * to let the other devices continue being serviced.
947 *
948 * It is safe doing so since our own interrupts will only be enabled
949 * in a subsequent step.
950 */
951 local_save_flags(flags);
952 local_irq_enable();
953
942 rtlpriv->intf_ops->disable_aspm(hw); 954 rtlpriv->intf_ops->disable_aspm(hw);
943 rtstatus = _rtl92ce_init_mac(hw); 955 rtstatus = _rtl92ce_init_mac(hw);
944 if (!rtstatus) { 956 if (!rtstatus) {
945 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Init MAC failed\n"); 957 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Init MAC failed\n");
946 err = 1; 958 err = 1;
947 return err; 959 goto exit;
948 } 960 }
949 961
950 err = rtl92c_download_fw(hw); 962 err = rtl92c_download_fw(hw);
@@ -952,7 +964,7 @@ int rtl92ce_hw_init(struct ieee80211_hw *hw)
952 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, 964 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
953 "Failed to download FW. Init HW without FW now..\n"); 965 "Failed to download FW. Init HW without FW now..\n");
954 err = 1; 966 err = 1;
955 return err; 967 goto exit;
956 } 968 }
957 969
958 rtlhal->last_hmeboxnum = 0; 970 rtlhal->last_hmeboxnum = 0;
@@ -1032,6 +1044,8 @@ int rtl92ce_hw_init(struct ieee80211_hw *hw)
1032 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "under 1.5V\n"); 1044 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "under 1.5V\n");
1033 } 1045 }
1034 rtl92c_dm_init(hw); 1046 rtl92c_dm_init(hw);
1047exit:
1048 local_irq_restore(flags);
1035 rtlpci->being_init_adapter = false; 1049 rtlpci->being_init_adapter = false;
1036 return err; 1050 return err;
1037} 1051}
diff --git a/drivers/net/wireless/ti/wl1251/rx.c b/drivers/net/wireless/ti/wl1251/rx.c
index 123c4bb50e0a..cde0eaf99714 100644
--- a/drivers/net/wireless/ti/wl1251/rx.c
+++ b/drivers/net/wireless/ti/wl1251/rx.c
@@ -180,7 +180,7 @@ static void wl1251_rx_body(struct wl1251 *wl,
180 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length); 180 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
181 181
182 /* The actual length doesn't include the target's alignment */ 182 /* The actual length doesn't include the target's alignment */
183 skb->len = desc->length - PLCP_HEADER_LENGTH; 183 skb_trim(skb, desc->length - PLCP_HEADER_LENGTH);
184 184
185 fc = (u16 *)skb->data; 185 fc = (u16 *)skb->data;
186 186
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 4c76bcb9a879..ae413a2cbee7 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -143,11 +143,7 @@ struct xenvif {
143 char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */ 143 char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
144 struct xen_netif_rx_back_ring rx; 144 struct xen_netif_rx_back_ring rx;
145 struct sk_buff_head rx_queue; 145 struct sk_buff_head rx_queue;
146 bool rx_queue_stopped; 146 RING_IDX rx_last_skb_slots;
147 /* Set when the RX interrupt is triggered by the frontend.
148 * The worker thread may need to wake the queue.
149 */
150 bool rx_event;
151 147
152 /* This array is allocated seperately as it is large */ 148 /* This array is allocated seperately as it is large */
153 struct gnttab_copy *grant_copy_op; 149 struct gnttab_copy *grant_copy_op;
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index b9de31ea7fc4..301cc037fda8 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -100,7 +100,6 @@ static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id)
100{ 100{
101 struct xenvif *vif = dev_id; 101 struct xenvif *vif = dev_id;
102 102
103 vif->rx_event = true;
104 xenvif_kick_thread(vif); 103 xenvif_kick_thread(vif);
105 104
106 return IRQ_HANDLED; 105 return IRQ_HANDLED;
@@ -133,8 +132,7 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
133 /* If the skb is GSO then we'll also need an extra slot for the 132 /* If the skb is GSO then we'll also need an extra slot for the
134 * metadata. 133 * metadata.
135 */ 134 */
136 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 || 135 if (skb_is_gso(skb))
137 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
138 min_slots_needed++; 136 min_slots_needed++;
139 137
140 /* If the skb can't possibly fit in the remaining slots 138 /* If the skb can't possibly fit in the remaining slots
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 6b62c3eb8e18..438d0c09b7e6 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -240,7 +240,7 @@ static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
240 struct gnttab_copy *copy_gop; 240 struct gnttab_copy *copy_gop;
241 struct xenvif_rx_meta *meta; 241 struct xenvif_rx_meta *meta;
242 unsigned long bytes; 242 unsigned long bytes;
243 int gso_type; 243 int gso_type = XEN_NETIF_GSO_TYPE_NONE;
244 244
245 /* Data must not cross a page boundary. */ 245 /* Data must not cross a page boundary. */
246 BUG_ON(size + offset > PAGE_SIZE<<compound_order(page)); 246 BUG_ON(size + offset > PAGE_SIZE<<compound_order(page));
@@ -299,12 +299,12 @@ static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
299 } 299 }
300 300
301 /* Leave a gap for the GSO descriptor. */ 301 /* Leave a gap for the GSO descriptor. */
302 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) 302 if (skb_is_gso(skb)) {
303 gso_type = XEN_NETIF_GSO_TYPE_TCPV4; 303 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
304 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) 304 gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
305 gso_type = XEN_NETIF_GSO_TYPE_TCPV6; 305 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
306 else 306 gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
307 gso_type = XEN_NETIF_GSO_TYPE_NONE; 307 }
308 308
309 if (*head && ((1 << gso_type) & vif->gso_mask)) 309 if (*head && ((1 << gso_type) & vif->gso_mask))
310 vif->rx.req_cons++; 310 vif->rx.req_cons++;
@@ -338,19 +338,15 @@ static int xenvif_gop_skb(struct sk_buff *skb,
338 int head = 1; 338 int head = 1;
339 int old_meta_prod; 339 int old_meta_prod;
340 int gso_type; 340 int gso_type;
341 int gso_size;
342 341
343 old_meta_prod = npo->meta_prod; 342 old_meta_prod = npo->meta_prod;
344 343
345 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) { 344 gso_type = XEN_NETIF_GSO_TYPE_NONE;
346 gso_type = XEN_NETIF_GSO_TYPE_TCPV4; 345 if (skb_is_gso(skb)) {
347 gso_size = skb_shinfo(skb)->gso_size; 346 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
348 } else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) { 347 gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
349 gso_type = XEN_NETIF_GSO_TYPE_TCPV6; 348 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
350 gso_size = skb_shinfo(skb)->gso_size; 349 gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
351 } else {
352 gso_type = XEN_NETIF_GSO_TYPE_NONE;
353 gso_size = 0;
354 } 350 }
355 351
356 /* Set up a GSO prefix descriptor, if necessary */ 352 /* Set up a GSO prefix descriptor, if necessary */
@@ -358,7 +354,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
358 req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++); 354 req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
359 meta = npo->meta + npo->meta_prod++; 355 meta = npo->meta + npo->meta_prod++;
360 meta->gso_type = gso_type; 356 meta->gso_type = gso_type;
361 meta->gso_size = gso_size; 357 meta->gso_size = skb_shinfo(skb)->gso_size;
362 meta->size = 0; 358 meta->size = 0;
363 meta->id = req->id; 359 meta->id = req->id;
364 } 360 }
@@ -368,7 +364,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
368 364
369 if ((1 << gso_type) & vif->gso_mask) { 365 if ((1 << gso_type) & vif->gso_mask) {
370 meta->gso_type = gso_type; 366 meta->gso_type = gso_type;
371 meta->gso_size = gso_size; 367 meta->gso_size = skb_shinfo(skb)->gso_size;
372 } else { 368 } else {
373 meta->gso_type = XEN_NETIF_GSO_TYPE_NONE; 369 meta->gso_type = XEN_NETIF_GSO_TYPE_NONE;
374 meta->gso_size = 0; 370 meta->gso_size = 0;
@@ -476,7 +472,6 @@ static void xenvif_rx_action(struct xenvif *vif)
476 unsigned long offset; 472 unsigned long offset;
477 struct skb_cb_overlay *sco; 473 struct skb_cb_overlay *sco;
478 bool need_to_notify = false; 474 bool need_to_notify = false;
479 bool ring_full = false;
480 475
481 struct netrx_pending_operations npo = { 476 struct netrx_pending_operations npo = {
482 .copy = vif->grant_copy_op, 477 .copy = vif->grant_copy_op,
@@ -486,7 +481,7 @@ static void xenvif_rx_action(struct xenvif *vif)
486 skb_queue_head_init(&rxq); 481 skb_queue_head_init(&rxq);
487 482
488 while ((skb = skb_dequeue(&vif->rx_queue)) != NULL) { 483 while ((skb = skb_dequeue(&vif->rx_queue)) != NULL) {
489 int max_slots_needed; 484 RING_IDX max_slots_needed;
490 int i; 485 int i;
491 486
492 /* We need a cheap worse case estimate for the number of 487 /* We need a cheap worse case estimate for the number of
@@ -501,17 +496,19 @@ static void xenvif_rx_action(struct xenvif *vif)
501 size = skb_frag_size(&skb_shinfo(skb)->frags[i]); 496 size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
502 max_slots_needed += DIV_ROUND_UP(size, PAGE_SIZE); 497 max_slots_needed += DIV_ROUND_UP(size, PAGE_SIZE);
503 } 498 }
504 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 || 499 if (skb_is_gso(skb) &&
505 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) 500 (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 ||
501 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6))
506 max_slots_needed++; 502 max_slots_needed++;
507 503
508 /* If the skb may not fit then bail out now */ 504 /* If the skb may not fit then bail out now */
509 if (!xenvif_rx_ring_slots_available(vif, max_slots_needed)) { 505 if (!xenvif_rx_ring_slots_available(vif, max_slots_needed)) {
510 skb_queue_head(&vif->rx_queue, skb); 506 skb_queue_head(&vif->rx_queue, skb);
511 need_to_notify = true; 507 need_to_notify = true;
512 ring_full = true; 508 vif->rx_last_skb_slots = max_slots_needed;
513 break; 509 break;
514 } 510 } else
511 vif->rx_last_skb_slots = 0;
515 512
516 sco = (struct skb_cb_overlay *)skb->cb; 513 sco = (struct skb_cb_overlay *)skb->cb;
517 sco->meta_slots_used = xenvif_gop_skb(skb, &npo); 514 sco->meta_slots_used = xenvif_gop_skb(skb, &npo);
@@ -522,8 +519,6 @@ static void xenvif_rx_action(struct xenvif *vif)
522 519
523 BUG_ON(npo.meta_prod > ARRAY_SIZE(vif->meta)); 520 BUG_ON(npo.meta_prod > ARRAY_SIZE(vif->meta));
524 521
525 vif->rx_queue_stopped = !npo.copy_prod && ring_full;
526
527 if (!npo.copy_prod) 522 if (!npo.copy_prod)
528 goto done; 523 goto done;
529 524
@@ -1473,8 +1468,8 @@ static struct xen_netif_rx_response *make_rx_response(struct xenvif *vif,
1473 1468
1474static inline int rx_work_todo(struct xenvif *vif) 1469static inline int rx_work_todo(struct xenvif *vif)
1475{ 1470{
1476 return (!skb_queue_empty(&vif->rx_queue) && !vif->rx_queue_stopped) || 1471 return !skb_queue_empty(&vif->rx_queue) &&
1477 vif->rx_event; 1472 xenvif_rx_ring_slots_available(vif, vif->rx_last_skb_slots);
1478} 1473}
1479 1474
1480static inline int tx_work_todo(struct xenvif *vif) 1475static inline int tx_work_todo(struct xenvif *vif)
@@ -1560,8 +1555,6 @@ int xenvif_kthread(void *data)
1560 if (!skb_queue_empty(&vif->rx_queue)) 1555 if (!skb_queue_empty(&vif->rx_queue))
1561 xenvif_rx_action(vif); 1556 xenvif_rx_action(vif);
1562 1557
1563 vif->rx_event = false;
1564
1565 if (skb_queue_empty(&vif->rx_queue) && 1558 if (skb_queue_empty(&vif->rx_queue) &&
1566 netif_queue_stopped(vif->dev)) 1559 netif_queue_stopped(vif->dev))
1567 xenvif_start_queue(vif); 1560 xenvif_start_queue(vif);
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index ff04d4f95baa..e30d80033cbc 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -907,6 +907,7 @@ static int handle_incoming_queue(struct net_device *dev,
907 907
908 /* Ethernet work: Delayed to here as it peeks the header. */ 908 /* Ethernet work: Delayed to here as it peeks the header. */
909 skb->protocol = eth_type_trans(skb, dev); 909 skb->protocol = eth_type_trans(skb, dev);
910 skb_reset_network_header(skb);
910 911
911 if (checksum_setup(dev, skb)) { 912 if (checksum_setup(dev, skb)) {
912 kfree_skb(skb); 913 kfree_skb(skb);
@@ -1832,7 +1833,6 @@ static void netback_changed(struct xenbus_device *dev,
1832 case XenbusStateReconfiguring: 1833 case XenbusStateReconfiguring:
1833 case XenbusStateReconfigured: 1834 case XenbusStateReconfigured:
1834 case XenbusStateUnknown: 1835 case XenbusStateUnknown:
1835 case XenbusStateClosed:
1836 break; 1836 break;
1837 1837
1838 case XenbusStateInitWait: 1838 case XenbusStateInitWait:
@@ -1847,6 +1847,10 @@ static void netback_changed(struct xenbus_device *dev,
1847 netdev_notify_peers(netdev); 1847 netdev_notify_peers(netdev);
1848 break; 1848 break;
1849 1849
1850 case XenbusStateClosed:
1851 if (dev->state == XenbusStateClosed)
1852 break;
1853 /* Missed the backend's CLOSING state -- fallthrough */
1850 case XenbusStateClosing: 1854 case XenbusStateClosing:
1851 xenbus_frontend_closed(dev); 1855 xenbus_frontend_closed(dev);
1852 break; 1856 break;
diff --git a/drivers/of/address.c b/drivers/of/address.c
index d3dd41c840f1..1a54f1ffaadb 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -99,11 +99,12 @@ static unsigned int of_bus_default_get_flags(const __be32 *addr)
99static int of_bus_pci_match(struct device_node *np) 99static int of_bus_pci_match(struct device_node *np)
100{ 100{
101 /* 101 /*
102 * "pciex" is PCI Express
102 * "vci" is for the /chaos bridge on 1st-gen PCI powermacs 103 * "vci" is for the /chaos bridge on 1st-gen PCI powermacs
103 * "ht" is hypertransport 104 * "ht" is hypertransport
104 */ 105 */
105 return !strcmp(np->type, "pci") || !strcmp(np->type, "vci") || 106 return !strcmp(np->type, "pci") || !strcmp(np->type, "pciex") ||
106 !strcmp(np->type, "ht"); 107 !strcmp(np->type, "vci") || !strcmp(np->type, "ht");
107} 108}
108 109
109static void of_bus_pci_count_cells(struct device_node *np, 110static void of_bus_pci_count_cells(struct device_node *np,
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ff85450d5683..89e888a78899 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -342,27 +342,72 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread)
342} 342}
343EXPORT_SYMBOL(of_get_cpu_node); 343EXPORT_SYMBOL(of_get_cpu_node);
344 344
345/** Checks if the given "compat" string matches one of the strings in 345/**
346 * the device's "compatible" property 346 * __of_device_is_compatible() - Check if the node matches given constraints
347 * @device: pointer to node
348 * @compat: required compatible string, NULL or "" for any match
349 * @type: required device_type value, NULL or "" for any match
350 * @name: required node name, NULL or "" for any match
351 *
352 * Checks if the given @compat, @type and @name strings match the
353 * properties of the given @device. A constraints can be skipped by
354 * passing NULL or an empty string as the constraint.
355 *
356 * Returns 0 for no match, and a positive integer on match. The return
357 * value is a relative score with larger values indicating better
358 * matches. The score is weighted for the most specific compatible value
359 * to get the highest score. Matching type is next, followed by matching
360 * name. Practically speaking, this results in the following priority
361 * order for matches:
362 *
363 * 1. specific compatible && type && name
364 * 2. specific compatible && type
365 * 3. specific compatible && name
366 * 4. specific compatible
367 * 5. general compatible && type && name
368 * 6. general compatible && type
369 * 7. general compatible && name
370 * 8. general compatible
371 * 9. type && name
372 * 10. type
373 * 11. name
347 */ 374 */
348static int __of_device_is_compatible(const struct device_node *device, 375static int __of_device_is_compatible(const struct device_node *device,
349 const char *compat) 376 const char *compat, const char *type, const char *name)
350{ 377{
351 const char* cp; 378 struct property *prop;
352 int cplen, l; 379 const char *cp;
380 int index = 0, score = 0;
381
382 /* Compatible match has highest priority */
383 if (compat && compat[0]) {
384 prop = __of_find_property(device, "compatible", NULL);
385 for (cp = of_prop_next_string(prop, NULL); cp;
386 cp = of_prop_next_string(prop, cp), index++) {
387 if (of_compat_cmp(cp, compat, strlen(compat)) == 0) {
388 score = INT_MAX/2 - (index << 2);
389 break;
390 }
391 }
392 if (!score)
393 return 0;
394 }
353 395
354 cp = __of_get_property(device, "compatible", &cplen); 396 /* Matching type is better than matching name */
355 if (cp == NULL) 397 if (type && type[0]) {
356 return 0; 398 if (!device->type || of_node_cmp(type, device->type))
357 while (cplen > 0) { 399 return 0;
358 if (of_compat_cmp(cp, compat, strlen(compat)) == 0) 400 score += 2;
359 return 1;
360 l = strlen(cp) + 1;
361 cp += l;
362 cplen -= l;
363 } 401 }
364 402
365 return 0; 403 /* Matching name is a bit better than not */
404 if (name && name[0]) {
405 if (!device->name || of_node_cmp(name, device->name))
406 return 0;
407 score++;
408 }
409
410 return score;
366} 411}
367 412
368/** Checks if the given "compat" string matches one of the strings in 413/** Checks if the given "compat" string matches one of the strings in
@@ -375,7 +420,7 @@ int of_device_is_compatible(const struct device_node *device,
375 int res; 420 int res;
376 421
377 raw_spin_lock_irqsave(&devtree_lock, flags); 422 raw_spin_lock_irqsave(&devtree_lock, flags);
378 res = __of_device_is_compatible(device, compat); 423 res = __of_device_is_compatible(device, compat, NULL, NULL);
379 raw_spin_unlock_irqrestore(&devtree_lock, flags); 424 raw_spin_unlock_irqrestore(&devtree_lock, flags);
380 return res; 425 return res;
381} 426}
@@ -681,10 +726,7 @@ struct device_node *of_find_compatible_node(struct device_node *from,
681 raw_spin_lock_irqsave(&devtree_lock, flags); 726 raw_spin_lock_irqsave(&devtree_lock, flags);
682 np = from ? from->allnext : of_allnodes; 727 np = from ? from->allnext : of_allnodes;
683 for (; np; np = np->allnext) { 728 for (; np; np = np->allnext) {
684 if (type 729 if (__of_device_is_compatible(np, compatible, type, NULL) &&
685 && !(np->type && (of_node_cmp(np->type, type) == 0)))
686 continue;
687 if (__of_device_is_compatible(np, compatible) &&
688 of_node_get(np)) 730 of_node_get(np))
689 break; 731 break;
690 } 732 }
@@ -734,43 +776,22 @@ static
734const struct of_device_id *__of_match_node(const struct of_device_id *matches, 776const struct of_device_id *__of_match_node(const struct of_device_id *matches,
735 const struct device_node *node) 777 const struct device_node *node)
736{ 778{
737 const char *cp; 779 const struct of_device_id *best_match = NULL;
738 int cplen, l; 780 int score, best_score = 0;
739 781
740 if (!matches) 782 if (!matches)
741 return NULL; 783 return NULL;
742 784
743 cp = __of_get_property(node, "compatible", &cplen); 785 for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) {
744 do { 786 score = __of_device_is_compatible(node, matches->compatible,
745 const struct of_device_id *m = matches; 787 matches->type, matches->name);
746 788 if (score > best_score) {
747 /* Check against matches with current compatible string */ 789 best_match = matches;
748 while (m->name[0] || m->type[0] || m->compatible[0]) { 790 best_score = score;
749 int match = 1;
750 if (m->name[0])
751 match &= node->name
752 && !strcmp(m->name, node->name);
753 if (m->type[0])
754 match &= node->type
755 && !strcmp(m->type, node->type);
756 if (m->compatible[0])
757 match &= cp
758 && !of_compat_cmp(m->compatible, cp,
759 strlen(m->compatible));
760 if (match)
761 return m;
762 m++;
763 }
764
765 /* Get node's next compatible string */
766 if (cp) {
767 l = strlen(cp) + 1;
768 cp += l;
769 cplen -= l;
770 } 791 }
771 } while (cp && (cplen > 0)); 792 }
772 793
773 return NULL; 794 return best_match;
774} 795}
775 796
776/** 797/**
@@ -778,10 +799,7 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches,
778 * @matches: array of of device match structures to search in 799 * @matches: array of of device match structures to search in
779 * @node: the of device structure to match against 800 * @node: the of device structure to match against
780 * 801 *
781 * Low level utility function used by device matching. Matching order 802 * Low level utility function used by device matching.
782 * is to compare each of the node's compatibles with all given matches
783 * first. This implies node's compatible is sorted from specific to
784 * generic while matches can be in any order.
785 */ 803 */
786const struct of_device_id *of_match_node(const struct of_device_id *matches, 804const struct of_device_id *of_match_node(const struct of_device_id *matches,
787 const struct device_node *node) 805 const struct device_node *node)
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 875b7b6f0d2a..5b3c24f3cde5 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -24,7 +24,11 @@ MODULE_LICENSE("GPL");
24 24
25static void of_set_phy_supported(struct phy_device *phydev, u32 max_speed) 25static void of_set_phy_supported(struct phy_device *phydev, u32 max_speed)
26{ 26{
27 phydev->supported |= PHY_DEFAULT_FEATURES; 27 /* The default values for phydev->supported are provided by the PHY
28 * driver "features" member, we want to reset to sane defaults fist
29 * before supporting higher speeds.
30 */
31 phydev->supported &= PHY_DEFAULT_FEATURES;
28 32
29 switch (max_speed) { 33 switch (max_speed) {
30 default: 34 default:
@@ -44,7 +48,7 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
44{ 48{
45 struct phy_device *phy; 49 struct phy_device *phy;
46 bool is_c45; 50 bool is_c45;
47 int rc, prev_irq; 51 int rc;
48 u32 max_speed = 0; 52 u32 max_speed = 0;
49 53
50 is_c45 = of_device_is_compatible(child, 54 is_c45 = of_device_is_compatible(child,
@@ -54,12 +58,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
54 if (!phy || IS_ERR(phy)) 58 if (!phy || IS_ERR(phy))
55 return 1; 59 return 1;
56 60
57 if (mdio->irq) { 61 rc = irq_of_parse_and_map(child, 0);
58 prev_irq = mdio->irq[addr]; 62 if (rc > 0) {
59 mdio->irq[addr] = 63 phy->irq = rc;
60 irq_of_parse_and_map(child, 0); 64 if (mdio->irq)
61 if (!mdio->irq[addr]) 65 mdio->irq[addr] = rc;
62 mdio->irq[addr] = prev_irq; 66 } else {
67 if (mdio->irq)
68 phy->irq = mdio->irq[addr];
63 } 69 }
64 70
65 /* Associate the OF node with the device structure so it 71 /* Associate the OF node with the device structure so it
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c
index e21012bde639..6643d1920985 100644
--- a/drivers/of/selftest.c
+++ b/drivers/of/selftest.c
@@ -300,6 +300,72 @@ static void __init of_selftest_parse_interrupts_extended(void)
300 of_node_put(np); 300 of_node_put(np);
301} 301}
302 302
303static struct of_device_id match_node_table[] = {
304 { .data = "A", .name = "name0", }, /* Name alone is lowest priority */
305 { .data = "B", .type = "type1", }, /* followed by type alone */
306
307 { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */
308 { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */
309 { .data = "Cc", .name = "name2", .type = "type2", },
310
311 { .data = "E", .compatible = "compat3" },
312 { .data = "G", .compatible = "compat2", },
313 { .data = "H", .compatible = "compat2", .name = "name5", },
314 { .data = "I", .compatible = "compat2", .type = "type1", },
315 { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", },
316 { .data = "K", .compatible = "compat2", .name = "name9", },
317 {}
318};
319
320static struct {
321 const char *path;
322 const char *data;
323} match_node_tests[] = {
324 { .path = "/testcase-data/match-node/name0", .data = "A", },
325 { .path = "/testcase-data/match-node/name1", .data = "B", },
326 { .path = "/testcase-data/match-node/a/name2", .data = "Ca", },
327 { .path = "/testcase-data/match-node/b/name2", .data = "Cb", },
328 { .path = "/testcase-data/match-node/c/name2", .data = "Cc", },
329 { .path = "/testcase-data/match-node/name3", .data = "E", },
330 { .path = "/testcase-data/match-node/name4", .data = "G", },
331 { .path = "/testcase-data/match-node/name5", .data = "H", },
332 { .path = "/testcase-data/match-node/name6", .data = "G", },
333 { .path = "/testcase-data/match-node/name7", .data = "I", },
334 { .path = "/testcase-data/match-node/name8", .data = "J", },
335 { .path = "/testcase-data/match-node/name9", .data = "K", },
336};
337
338static void __init of_selftest_match_node(void)
339{
340 struct device_node *np;
341 const struct of_device_id *match;
342 int i;
343
344 for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) {
345 np = of_find_node_by_path(match_node_tests[i].path);
346 if (!np) {
347 selftest(0, "missing testcase node %s\n",
348 match_node_tests[i].path);
349 continue;
350 }
351
352 match = of_match_node(match_node_table, np);
353 if (!match) {
354 selftest(0, "%s didn't match anything\n",
355 match_node_tests[i].path);
356 continue;
357 }
358
359 if (strcmp(match->data, match_node_tests[i].data) != 0) {
360 selftest(0, "%s got wrong match. expected %s, got %s\n",
361 match_node_tests[i].path, match_node_tests[i].data,
362 (const char *)match->data);
363 continue;
364 }
365 selftest(1, "passed");
366 }
367}
368
303static int __init of_selftest(void) 369static int __init of_selftest(void)
304{ 370{
305 struct device_node *np; 371 struct device_node *np;
@@ -316,6 +382,7 @@ static int __init of_selftest(void)
316 of_selftest_property_match_string(); 382 of_selftest_property_match_string();
317 of_selftest_parse_interrupts(); 383 of_selftest_parse_interrupts();
318 of_selftest_parse_interrupts_extended(); 384 of_selftest_parse_interrupts_extended();
385 of_selftest_match_node();
319 pr_info("end of selftest - %i passed, %i failed\n", 386 pr_info("end of selftest - %i passed, %i failed\n",
320 selftest_results.passed, selftest_results.failed); 387 selftest_results.passed, selftest_results.failed);
321 return 0; 388 return 0;
diff --git a/drivers/of/testcase-data/testcases.dtsi b/drivers/of/testcase-data/testcases.dtsi
new file mode 100644
index 000000000000..3a5b75a8e4d7
--- /dev/null
+++ b/drivers/of/testcase-data/testcases.dtsi
@@ -0,0 +1,3 @@
1#include "tests-phandle.dtsi"
2#include "tests-interrupts.dtsi"
3#include "tests-match.dtsi"
diff --git a/arch/arm/boot/dts/testcases/tests-interrupts.dtsi b/drivers/of/testcase-data/tests-interrupts.dtsi
index c843720bd3e5..c843720bd3e5 100644
--- a/arch/arm/boot/dts/testcases/tests-interrupts.dtsi
+++ b/drivers/of/testcase-data/tests-interrupts.dtsi
diff --git a/drivers/of/testcase-data/tests-match.dtsi b/drivers/of/testcase-data/tests-match.dtsi
new file mode 100644
index 000000000000..c9e541129534
--- /dev/null
+++ b/drivers/of/testcase-data/tests-match.dtsi
@@ -0,0 +1,19 @@
1
2/ {
3 testcase-data {
4 match-node {
5 name0 { };
6 name1 { device_type = "type1"; };
7 a { name2 { device_type = "type1"; }; };
8 b { name2 { }; };
9 c { name2 { device_type = "type2"; }; };
10 name3 { compatible = "compat3"; };
11 name4 { compatible = "compat2", "compat3"; };
12 name5 { compatible = "compat2", "compat3"; };
13 name6 { compatible = "compat1", "compat2", "compat3"; };
14 name7 { compatible = "compat2"; device_type = "type1"; };
15 name8 { compatible = "compat2"; device_type = "type1"; };
16 name9 { compatible = "compat2"; };
17 };
18 };
19};
diff --git a/arch/arm/boot/dts/testcases/tests-phandle.dtsi b/drivers/of/testcase-data/tests-phandle.dtsi
index 0007d3cd7dc2..0007d3cd7dc2 100644
--- a/arch/arm/boot/dts/testcases/tests-phandle.dtsi
+++ b/drivers/of/testcase-data/tests-phandle.dtsi
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 00660cc502c5..38901665c770 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -162,8 +162,6 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
162 162
163 avail = *r; 163 avail = *r;
164 pci_clip_resource_to_region(bus, &avail, region); 164 pci_clip_resource_to_region(bus, &avail, region);
165 if (!resource_size(&avail))
166 continue;
167 165
168 /* 166 /*
169 * "min" is typically PCIBIOS_MIN_IO or PCIBIOS_MIN_MEM to 167 * "min" is typically PCIBIOS_MIN_IO or PCIBIOS_MIN_MEM to
diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c
index 13478ecd4113..0e79665afd44 100644
--- a/drivers/pci/host/pci-mvebu.c
+++ b/drivers/pci/host/pci-mvebu.c
@@ -60,14 +60,6 @@
60#define PCIE_DEBUG_CTRL 0x1a60 60#define PCIE_DEBUG_CTRL 0x1a60
61#define PCIE_DEBUG_SOFT_RESET BIT(20) 61#define PCIE_DEBUG_SOFT_RESET BIT(20)
62 62
63/*
64 * This product ID is registered by Marvell, and used when the Marvell
65 * SoC is not the root complex, but an endpoint on the PCIe bus. It is
66 * therefore safe to re-use this PCI ID for our emulated PCI-to-PCI
67 * bridge.
68 */
69#define MARVELL_EMULATED_PCI_PCI_BRIDGE_ID 0x7846
70
71/* PCI configuration space of a PCI-to-PCI bridge */ 63/* PCI configuration space of a PCI-to-PCI bridge */
72struct mvebu_sw_pci_bridge { 64struct mvebu_sw_pci_bridge {
73 u16 vendor; 65 u16 vendor;
@@ -388,7 +380,8 @@ static void mvebu_sw_pci_bridge_init(struct mvebu_pcie_port *port)
388 380
389 bridge->class = PCI_CLASS_BRIDGE_PCI; 381 bridge->class = PCI_CLASS_BRIDGE_PCI;
390 bridge->vendor = PCI_VENDOR_ID_MARVELL; 382 bridge->vendor = PCI_VENDOR_ID_MARVELL;
391 bridge->device = MARVELL_EMULATED_PCI_PCI_BRIDGE_ID; 383 bridge->device = mvebu_readl(port, PCIE_DEV_ID_OFF) >> 16;
384 bridge->revision = mvebu_readl(port, PCIE_DEV_REV_OFF) & 0xff;
392 bridge->header_type = PCI_HEADER_TYPE_BRIDGE; 385 bridge->header_type = PCI_HEADER_TYPE_BRIDGE;
393 bridge->cache_line_size = 0x10; 386 bridge->cache_line_size = 0x10;
394 387
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index cd929aed3613..7c7a388c85ab 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -210,10 +210,29 @@ static void post_dock_fixups(acpi_handle not_used, u32 event, void *data)
210 } 210 }
211} 211}
212 212
213static void dock_event(acpi_handle handle, u32 type, void *data)
214{
215 struct acpiphp_context *context;
216
217 mutex_lock(&acpiphp_context_lock);
218 context = acpiphp_get_context(handle);
219 if (!context || WARN_ON(context->handle != handle)
220 || context->func.parent->is_going_away) {
221 mutex_unlock(&acpiphp_context_lock);
222 return;
223 }
224 get_bridge(context->func.parent);
225 acpiphp_put_context(context);
226 mutex_unlock(&acpiphp_context_lock);
227
228 hotplug_event(handle, type, data);
229
230 put_bridge(context->func.parent);
231}
213 232
214static const struct acpi_dock_ops acpiphp_dock_ops = { 233static const struct acpi_dock_ops acpiphp_dock_ops = {
215 .fixup = post_dock_fixups, 234 .fixup = post_dock_fixups,
216 .handler = hotplug_event, 235 .handler = dock_event,
217}; 236};
218 237
219/* Check whether the PCI device is managed by native PCIe hotplug driver */ 238/* Check whether the PCI device is managed by native PCIe hotplug driver */
@@ -441,7 +460,9 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge)
441 list_del(&bridge->list); 460 list_del(&bridge->list);
442 mutex_unlock(&bridge_mutex); 461 mutex_unlock(&bridge_mutex);
443 462
463 mutex_lock(&acpiphp_context_lock);
444 bridge->is_going_away = true; 464 bridge->is_going_away = true;
465 mutex_unlock(&acpiphp_context_lock);
445} 466}
446 467
447/** 468/**
@@ -709,6 +730,17 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
709 return (unsigned int)sta; 730 return (unsigned int)sta;
710} 731}
711 732
733static inline bool device_status_valid(unsigned int sta)
734{
735 /*
736 * ACPI spec says that _STA may return bit 0 clear with bit 3 set
737 * if the device is valid but does not require a device driver to be
738 * loaded (Section 6.3.7 of ACPI 5.0A).
739 */
740 unsigned int mask = ACPI_STA_DEVICE_ENABLED | ACPI_STA_DEVICE_FUNCTIONING;
741 return (sta & mask) == mask;
742}
743
712/** 744/**
713 * trim_stale_devices - remove PCI devices that are not responding. 745 * trim_stale_devices - remove PCI devices that are not responding.
714 * @dev: PCI device to start walking the hierarchy from. 746 * @dev: PCI device to start walking the hierarchy from.
@@ -724,7 +756,7 @@ static void trim_stale_devices(struct pci_dev *dev)
724 unsigned long long sta; 756 unsigned long long sta;
725 757
726 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 758 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
727 alive = (ACPI_SUCCESS(status) && sta == ACPI_STA_ALL) 759 alive = (ACPI_SUCCESS(status) && device_status_valid(sta))
728 || acpiphp_no_hotplug(handle); 760 || acpiphp_no_hotplug(handle);
729 } 761 }
730 if (!alive) { 762 if (!alive) {
@@ -742,7 +774,7 @@ static void trim_stale_devices(struct pci_dev *dev)
742 774
743 /* The device is a bridge. so check the bus below it. */ 775 /* The device is a bridge. so check the bus below it. */
744 pm_runtime_get_sync(&dev->dev); 776 pm_runtime_get_sync(&dev->dev);
745 list_for_each_entry_safe(child, tmp, &bus->devices, bus_list) 777 list_for_each_entry_safe_reverse(child, tmp, &bus->devices, bus_list)
746 trim_stale_devices(child); 778 trim_stale_devices(child);
747 779
748 pm_runtime_put(&dev->dev); 780 pm_runtime_put(&dev->dev);
@@ -771,10 +803,10 @@ static void acpiphp_check_bridge(struct acpiphp_bridge *bridge)
771 mutex_lock(&slot->crit_sect); 803 mutex_lock(&slot->crit_sect);
772 if (slot_no_hotplug(slot)) { 804 if (slot_no_hotplug(slot)) {
773 ; /* do nothing */ 805 ; /* do nothing */
774 } else if (get_slot_status(slot) == ACPI_STA_ALL) { 806 } else if (device_status_valid(get_slot_status(slot))) {
775 /* remove stale devices if any */ 807 /* remove stale devices if any */
776 list_for_each_entry_safe(dev, tmp, &bus->devices, 808 list_for_each_entry_safe_reverse(dev, tmp,
777 bus_list) 809 &bus->devices, bus_list)
778 if (PCI_SLOT(dev->devfn) == slot->device) 810 if (PCI_SLOT(dev->devfn) == slot->device)
779 trim_stale_devices(dev); 811 trim_stale_devices(dev);
780 812
@@ -805,7 +837,7 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus)
805 int i; 837 int i;
806 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM; 838 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
807 839
808 list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) { 840 list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
809 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) { 841 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
810 struct resource *res = &dev->resource[i]; 842 struct resource *res = &dev->resource[i];
811 if ((res->flags & type_mask) && !res->start && 843 if ((res->flags & type_mask) && !res->start &&
@@ -829,7 +861,11 @@ void acpiphp_check_host_bridge(acpi_handle handle)
829 861
830 bridge = acpiphp_handle_to_bridge(handle); 862 bridge = acpiphp_handle_to_bridge(handle);
831 if (bridge) { 863 if (bridge) {
864 pci_lock_rescan_remove();
865
832 acpiphp_check_bridge(bridge); 866 acpiphp_check_bridge(bridge);
867
868 pci_unlock_rescan_remove();
833 put_bridge(bridge); 869 put_bridge(bridge);
834 } 870 }
835} 871}
@@ -852,6 +888,7 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data)
852 888
853 mutex_unlock(&acpiphp_context_lock); 889 mutex_unlock(&acpiphp_context_lock);
854 890
891 pci_lock_rescan_remove();
855 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); 892 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
856 893
857 switch (type) { 894 switch (type) {
@@ -905,6 +942,7 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data)
905 break; 942 break;
906 } 943 }
907 944
945 pci_unlock_rescan_remove();
908 if (bridge) 946 if (bridge)
909 put_bridge(bridge); 947 put_bridge(bridge);
910} 948}
@@ -915,11 +953,9 @@ static void hotplug_event_work(void *data, u32 type)
915 acpi_handle handle = context->handle; 953 acpi_handle handle = context->handle;
916 954
917 acpi_scan_lock_acquire(); 955 acpi_scan_lock_acquire();
918 pci_lock_rescan_remove();
919 956
920 hotplug_event(handle, type, context); 957 hotplug_event(handle, type, context);
921 958
922 pci_unlock_rescan_remove();
923 acpi_scan_lock_release(); 959 acpi_scan_lock_release();
924 acpi_evaluate_hotplug_ost(handle, type, ACPI_OST_SC_SUCCESS, NULL); 960 acpi_evaluate_hotplug_ost(handle, type, ACPI_OST_SC_SUCCESS, NULL);
925 put_bridge(context->func.parent); 961 put_bridge(context->func.parent);
@@ -937,6 +973,7 @@ static void handle_hotplug_event(acpi_handle handle, u32 type, void *data)
937{ 973{
938 struct acpiphp_context *context; 974 struct acpiphp_context *context;
939 u32 ost_code = ACPI_OST_SC_SUCCESS; 975 u32 ost_code = ACPI_OST_SC_SUCCESS;
976 acpi_status status;
940 977
941 switch (type) { 978 switch (type) {
942 case ACPI_NOTIFY_BUS_CHECK: 979 case ACPI_NOTIFY_BUS_CHECK:
@@ -972,13 +1009,20 @@ static void handle_hotplug_event(acpi_handle handle, u32 type, void *data)
972 1009
973 mutex_lock(&acpiphp_context_lock); 1010 mutex_lock(&acpiphp_context_lock);
974 context = acpiphp_get_context(handle); 1011 context = acpiphp_get_context(handle);
975 if (context && !WARN_ON(context->handle != handle)) { 1012 if (!context || WARN_ON(context->handle != handle)
976 get_bridge(context->func.parent); 1013 || context->func.parent->is_going_away)
977 acpiphp_put_context(context); 1014 goto err_out;
978 acpi_hotplug_execute(hotplug_event_work, context, type); 1015
1016 get_bridge(context->func.parent);
1017 acpiphp_put_context(context);
1018 status = acpi_hotplug_execute(hotplug_event_work, context, type);
1019 if (ACPI_SUCCESS(status)) {
979 mutex_unlock(&acpiphp_context_lock); 1020 mutex_unlock(&acpiphp_context_lock);
980 return; 1021 return;
981 } 1022 }
1023 put_bridge(context->func.parent);
1024
1025 err_out:
982 mutex_unlock(&acpiphp_context_lock); 1026 mutex_unlock(&acpiphp_context_lock);
983 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; 1027 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
984 1028
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 7a0fec6ce571..955ab7990c5b 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -545,9 +545,15 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
545 return -ENOMEM; 545 return -ENOMEM;
546 list_for_each_entry(entry, &pdev->msi_list, list) { 546 list_for_each_entry(entry, &pdev->msi_list, list) {
547 char *name = kmalloc(20, GFP_KERNEL); 547 char *name = kmalloc(20, GFP_KERNEL);
548 if (!name)
549 goto error_attrs;
550
548 msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL); 551 msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL);
549 if (!msi_dev_attr) 552 if (!msi_dev_attr) {
553 kfree(name);
550 goto error_attrs; 554 goto error_attrs;
555 }
556
551 sprintf(name, "%d", entry->irq); 557 sprintf(name, "%d", entry->irq);
552 sysfs_attr_init(&msi_dev_attr->attr); 558 sysfs_attr_init(&msi_dev_attr->attr);
553 msi_dev_attr->attr.name = name; 559 msi_dev_attr->attr.name = name;
@@ -589,6 +595,7 @@ error_attrs:
589 ++count; 595 ++count;
590 msi_attr = msi_attrs[count]; 596 msi_attr = msi_attrs[count];
591 } 597 }
598 kfree(msi_attrs);
592 return ret; 599 return ret;
593} 600}
594 601
@@ -959,7 +966,6 @@ EXPORT_SYMBOL(pci_disable_msi);
959/** 966/**
960 * pci_msix_vec_count - return the number of device's MSI-X table entries 967 * pci_msix_vec_count - return the number of device's MSI-X table entries
961 * @dev: pointer to the pci_dev data structure of MSI-X device function 968 * @dev: pointer to the pci_dev data structure of MSI-X device function
962
963 * This function returns the number of device's MSI-X table entries and 969 * This function returns the number of device's MSI-X table entries and
964 * therefore the number of MSI-X vectors device is capable of sending. 970 * therefore the number of MSI-X vectors device is capable of sending.
965 * It returns a negative errno if the device is not capable of sending MSI-X 971 * It returns a negative errno if the device is not capable of sending MSI-X
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 1febe90831b4..fdbc294821e6 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1181,6 +1181,8 @@ EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state);
1181static int do_pci_enable_device(struct pci_dev *dev, int bars) 1181static int do_pci_enable_device(struct pci_dev *dev, int bars)
1182{ 1182{
1183 int err; 1183 int err;
1184 u16 cmd;
1185 u8 pin;
1184 1186
1185 err = pci_set_power_state(dev, PCI_D0); 1187 err = pci_set_power_state(dev, PCI_D0);
1186 if (err < 0 && err != -EIO) 1188 if (err < 0 && err != -EIO)
@@ -1190,6 +1192,17 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars)
1190 return err; 1192 return err;
1191 pci_fixup_device(pci_fixup_enable, dev); 1193 pci_fixup_device(pci_fixup_enable, dev);
1192 1194
1195 if (dev->msi_enabled || dev->msix_enabled)
1196 return 0;
1197
1198 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
1199 if (pin) {
1200 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1201 if (cmd & PCI_COMMAND_INTX_DISABLE)
1202 pci_write_config_word(dev, PCI_COMMAND,
1203 cmd & ~PCI_COMMAND_INTX_DISABLE);
1204 }
1205
1193 return 0; 1206 return 0;
1194} 1207}
1195 1208
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index afa2354f6600..c7a551c2d5f1 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -5,7 +5,7 @@
5menu "PHY Subsystem" 5menu "PHY Subsystem"
6 6
7config GENERIC_PHY 7config GENERIC_PHY
8 tristate "PHY Core" 8 bool "PHY Core"
9 help 9 help
10 Generic PHY support. 10 Generic PHY support.
11 11
@@ -61,6 +61,7 @@ config PHY_EXYNOS_DP_VIDEO
61config BCM_KONA_USB2_PHY 61config BCM_KONA_USB2_PHY
62 tristate "Broadcom Kona USB2 PHY Driver" 62 tristate "Broadcom Kona USB2 PHY Driver"
63 depends on GENERIC_PHY 63 depends on GENERIC_PHY
64 depends on HAS_IOMEM
64 help 65 help
65 Enable this to support the Broadcom Kona USB 2.0 PHY. 66 Enable this to support the Broadcom Kona USB 2.0 PHY.
66 67
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 645c867c1257..6c738376daff 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -162,6 +162,9 @@ int phy_init(struct phy *phy)
162{ 162{
163 int ret; 163 int ret;
164 164
165 if (!phy)
166 return 0;
167
165 ret = phy_pm_runtime_get_sync(phy); 168 ret = phy_pm_runtime_get_sync(phy);
166 if (ret < 0 && ret != -ENOTSUPP) 169 if (ret < 0 && ret != -ENOTSUPP)
167 return ret; 170 return ret;
@@ -173,6 +176,8 @@ int phy_init(struct phy *phy)
173 dev_err(&phy->dev, "phy init failed --> %d\n", ret); 176 dev_err(&phy->dev, "phy init failed --> %d\n", ret);
174 goto out; 177 goto out;
175 } 178 }
179 } else {
180 ret = 0; /* Override possible ret == -ENOTSUPP */
176 } 181 }
177 ++phy->init_count; 182 ++phy->init_count;
178 183
@@ -187,6 +192,9 @@ int phy_exit(struct phy *phy)
187{ 192{
188 int ret; 193 int ret;
189 194
195 if (!phy)
196 return 0;
197
190 ret = phy_pm_runtime_get_sync(phy); 198 ret = phy_pm_runtime_get_sync(phy);
191 if (ret < 0 && ret != -ENOTSUPP) 199 if (ret < 0 && ret != -ENOTSUPP)
192 return ret; 200 return ret;
@@ -212,6 +220,9 @@ int phy_power_on(struct phy *phy)
212{ 220{
213 int ret; 221 int ret;
214 222
223 if (!phy)
224 return 0;
225
215 ret = phy_pm_runtime_get_sync(phy); 226 ret = phy_pm_runtime_get_sync(phy);
216 if (ret < 0 && ret != -ENOTSUPP) 227 if (ret < 0 && ret != -ENOTSUPP)
217 return ret; 228 return ret;
@@ -223,6 +234,8 @@ int phy_power_on(struct phy *phy)
223 dev_err(&phy->dev, "phy poweron failed --> %d\n", ret); 234 dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
224 goto out; 235 goto out;
225 } 236 }
237 } else {
238 ret = 0; /* Override possible ret == -ENOTSUPP */
226 } 239 }
227 ++phy->power_count; 240 ++phy->power_count;
228 mutex_unlock(&phy->mutex); 241 mutex_unlock(&phy->mutex);
@@ -240,6 +253,9 @@ int phy_power_off(struct phy *phy)
240{ 253{
241 int ret; 254 int ret;
242 255
256 if (!phy)
257 return 0;
258
243 mutex_lock(&phy->mutex); 259 mutex_lock(&phy->mutex);
244 if (phy->power_count == 1 && phy->ops->power_off) { 260 if (phy->power_count == 1 && phy->ops->power_off) {
245 ret = phy->ops->power_off(phy); 261 ret = phy->ops->power_off(phy);
@@ -308,7 +324,7 @@ err0:
308 */ 324 */
309void phy_put(struct phy *phy) 325void phy_put(struct phy *phy)
310{ 326{
311 if (IS_ERR(phy)) 327 if (!phy || IS_ERR(phy))
312 return; 328 return;
313 329
314 module_put(phy->ops->owner); 330 module_put(phy->ops->owner);
@@ -328,6 +344,9 @@ void devm_phy_put(struct device *dev, struct phy *phy)
328{ 344{
329 int r; 345 int r;
330 346
347 if (!phy)
348 return;
349
331 r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy); 350 r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy);
332 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); 351 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
333} 352}
@@ -389,17 +408,11 @@ struct phy *phy_get(struct device *dev, const char *string)
389 index = of_property_match_string(dev->of_node, "phy-names", 408 index = of_property_match_string(dev->of_node, "phy-names",
390 string); 409 string);
391 phy = of_phy_get(dev, index); 410 phy = of_phy_get(dev, index);
392 if (IS_ERR(phy)) {
393 dev_err(dev, "unable to find phy\n");
394 return phy;
395 }
396 } else { 411 } else {
397 phy = phy_lookup(dev, string); 412 phy = phy_lookup(dev, string);
398 if (IS_ERR(phy)) {
399 dev_err(dev, "unable to find phy\n");
400 return phy;
401 }
402 } 413 }
414 if (IS_ERR(phy))
415 return phy;
403 416
404 if (!try_module_get(phy->ops->owner)) 417 if (!try_module_get(phy->ops->owner))
405 return ERR_PTR(-EPROBE_DEFER); 418 return ERR_PTR(-EPROBE_DEFER);
@@ -411,6 +424,27 @@ struct phy *phy_get(struct device *dev, const char *string)
411EXPORT_SYMBOL_GPL(phy_get); 424EXPORT_SYMBOL_GPL(phy_get);
412 425
413/** 426/**
427 * phy_optional_get() - lookup and obtain a reference to an optional phy.
428 * @dev: device that requests this phy
429 * @string: the phy name as given in the dt data or the name of the controller
430 * port for non-dt case
431 *
432 * Returns the phy driver, after getting a refcount to it; or
433 * NULL if there is no such phy. The caller is responsible for
434 * calling phy_put() to release that count.
435 */
436struct phy *phy_optional_get(struct device *dev, const char *string)
437{
438 struct phy *phy = phy_get(dev, string);
439
440 if (PTR_ERR(phy) == -ENODEV)
441 phy = NULL;
442
443 return phy;
444}
445EXPORT_SYMBOL_GPL(phy_optional_get);
446
447/**
414 * devm_phy_get() - lookup and obtain a reference to a phy. 448 * devm_phy_get() - lookup and obtain a reference to a phy.
415 * @dev: device that requests this phy 449 * @dev: device that requests this phy
416 * @string: the phy name as given in the dt data or phy device name 450 * @string: the phy name as given in the dt data or phy device name
@@ -441,6 +475,30 @@ struct phy *devm_phy_get(struct device *dev, const char *string)
441EXPORT_SYMBOL_GPL(devm_phy_get); 475EXPORT_SYMBOL_GPL(devm_phy_get);
442 476
443/** 477/**
478 * devm_phy_optional_get() - lookup and obtain a reference to an optional phy.
479 * @dev: device that requests this phy
480 * @string: the phy name as given in the dt data or phy device name
481 * for non-dt case
482 *
483 * Gets the phy using phy_get(), and associates a device with it using
484 * devres. On driver detach, release function is invoked on the devres
485 * data, then, devres data is freed. This differs to devm_phy_get() in
486 * that if the phy does not exist, it is not considered an error and
487 * -ENODEV will not be returned. Instead the NULL phy is returned,
488 * which can be passed to all other phy consumer calls.
489 */
490struct phy *devm_phy_optional_get(struct device *dev, const char *string)
491{
492 struct phy *phy = devm_phy_get(dev, string);
493
494 if (PTR_ERR(phy) == -ENODEV)
495 phy = NULL;
496
497 return phy;
498}
499EXPORT_SYMBOL_GPL(devm_phy_optional_get);
500
501/**
444 * phy_create() - create a new phy 502 * phy_create() - create a new phy
445 * @dev: device that is creating the new phy 503 * @dev: device that is creating the new phy
446 * @ops: function pointers for performing phy operations 504 * @ops: function pointers for performing phy operations
diff --git a/drivers/phy/phy-exynos-dp-video.c b/drivers/phy/phy-exynos-dp-video.c
index 1dbe6ce7b2ce..0786fef842e7 100644
--- a/drivers/phy/phy-exynos-dp-video.c
+++ b/drivers/phy/phy-exynos-dp-video.c
@@ -76,10 +76,6 @@ static int exynos_dp_video_phy_probe(struct platform_device *pdev)
76 if (IS_ERR(state->regs)) 76 if (IS_ERR(state->regs))
77 return PTR_ERR(state->regs); 77 return PTR_ERR(state->regs);
78 78
79 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
80 if (IS_ERR(phy_provider))
81 return PTR_ERR(phy_provider);
82
83 phy = devm_phy_create(dev, &exynos_dp_video_phy_ops, NULL); 79 phy = devm_phy_create(dev, &exynos_dp_video_phy_ops, NULL);
84 if (IS_ERR(phy)) { 80 if (IS_ERR(phy)) {
85 dev_err(dev, "failed to create Display Port PHY\n"); 81 dev_err(dev, "failed to create Display Port PHY\n");
@@ -87,6 +83,10 @@ static int exynos_dp_video_phy_probe(struct platform_device *pdev)
87 } 83 }
88 phy_set_drvdata(phy, state); 84 phy_set_drvdata(phy, state);
89 85
86 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
87 if (IS_ERR(phy_provider))
88 return PTR_ERR(phy_provider);
89
90 return 0; 90 return 0;
91} 91}
92 92
diff --git a/drivers/phy/phy-exynos-mipi-video.c b/drivers/phy/phy-exynos-mipi-video.c
index 0c5efab11af1..7f139326a642 100644
--- a/drivers/phy/phy-exynos-mipi-video.c
+++ b/drivers/phy/phy-exynos-mipi-video.c
@@ -134,11 +134,6 @@ static int exynos_mipi_video_phy_probe(struct platform_device *pdev)
134 dev_set_drvdata(dev, state); 134 dev_set_drvdata(dev, state);
135 spin_lock_init(&state->slock); 135 spin_lock_init(&state->slock);
136 136
137 phy_provider = devm_of_phy_provider_register(dev,
138 exynos_mipi_video_phy_xlate);
139 if (IS_ERR(phy_provider))
140 return PTR_ERR(phy_provider);
141
142 for (i = 0; i < EXYNOS_MIPI_PHYS_NUM; i++) { 137 for (i = 0; i < EXYNOS_MIPI_PHYS_NUM; i++) {
143 struct phy *phy = devm_phy_create(dev, 138 struct phy *phy = devm_phy_create(dev,
144 &exynos_mipi_video_phy_ops, NULL); 139 &exynos_mipi_video_phy_ops, NULL);
@@ -152,6 +147,11 @@ static int exynos_mipi_video_phy_probe(struct platform_device *pdev)
152 phy_set_drvdata(phy, &state->phys[i]); 147 phy_set_drvdata(phy, &state->phys[i]);
153 } 148 }
154 149
150 phy_provider = devm_of_phy_provider_register(dev,
151 exynos_mipi_video_phy_xlate);
152 if (IS_ERR(phy_provider))
153 return PTR_ERR(phy_provider);
154
155 return 0; 155 return 0;
156} 156}
157 157
diff --git a/drivers/phy/phy-mvebu-sata.c b/drivers/phy/phy-mvebu-sata.c
index d43786f62437..d70ecd6a1b3f 100644
--- a/drivers/phy/phy-mvebu-sata.c
+++ b/drivers/phy/phy-mvebu-sata.c
@@ -99,17 +99,17 @@ static int phy_mvebu_sata_probe(struct platform_device *pdev)
99 if (IS_ERR(priv->clk)) 99 if (IS_ERR(priv->clk))
100 return PTR_ERR(priv->clk); 100 return PTR_ERR(priv->clk);
101 101
102 phy_provider = devm_of_phy_provider_register(&pdev->dev,
103 of_phy_simple_xlate);
104 if (IS_ERR(phy_provider))
105 return PTR_ERR(phy_provider);
106
107 phy = devm_phy_create(&pdev->dev, &phy_mvebu_sata_ops, NULL); 102 phy = devm_phy_create(&pdev->dev, &phy_mvebu_sata_ops, NULL);
108 if (IS_ERR(phy)) 103 if (IS_ERR(phy))
109 return PTR_ERR(phy); 104 return PTR_ERR(phy);
110 105
111 phy_set_drvdata(phy, priv); 106 phy_set_drvdata(phy, priv);
112 107
108 phy_provider = devm_of_phy_provider_register(&pdev->dev,
109 of_phy_simple_xlate);
110 if (IS_ERR(phy_provider))
111 return PTR_ERR(phy_provider);
112
113 /* The boot loader may of left it on. Turn it off. */ 113 /* The boot loader may of left it on. Turn it off. */
114 phy_mvebu_sata_power_off(phy); 114 phy_mvebu_sata_power_off(phy);
115 115
diff --git a/drivers/phy/phy-omap-usb2.c b/drivers/phy/phy-omap-usb2.c
index bfc5c337f99a..7699752fba11 100644
--- a/drivers/phy/phy-omap-usb2.c
+++ b/drivers/phy/phy-omap-usb2.c
@@ -177,11 +177,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
177 phy->phy.otg = otg; 177 phy->phy.otg = otg;
178 phy->phy.type = USB_PHY_TYPE_USB2; 178 phy->phy.type = USB_PHY_TYPE_USB2;
179 179
180 phy_provider = devm_of_phy_provider_register(phy->dev,
181 of_phy_simple_xlate);
182 if (IS_ERR(phy_provider))
183 return PTR_ERR(phy_provider);
184
185 control_node = of_parse_phandle(node, "ctrl-module", 0); 180 control_node = of_parse_phandle(node, "ctrl-module", 0);
186 if (!control_node) { 181 if (!control_node) {
187 dev_err(&pdev->dev, "Failed to get control device phandle\n"); 182 dev_err(&pdev->dev, "Failed to get control device phandle\n");
@@ -214,6 +209,11 @@ static int omap_usb2_probe(struct platform_device *pdev)
214 209
215 phy_set_drvdata(generic_phy, phy); 210 phy_set_drvdata(generic_phy, phy);
216 211
212 phy_provider = devm_of_phy_provider_register(phy->dev,
213 of_phy_simple_xlate);
214 if (IS_ERR(phy_provider))
215 return PTR_ERR(phy_provider);
216
217 phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); 217 phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k");
218 if (IS_ERR(phy->wkupclk)) { 218 if (IS_ERR(phy->wkupclk)) {
219 dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n"); 219 dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n");
diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
index daf65e68aaab..c3ace1db8136 100644
--- a/drivers/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -695,11 +695,6 @@ static int twl4030_usb_probe(struct platform_device *pdev)
695 otg->set_host = twl4030_set_host; 695 otg->set_host = twl4030_set_host;
696 otg->set_peripheral = twl4030_set_peripheral; 696 otg->set_peripheral = twl4030_set_peripheral;
697 697
698 phy_provider = devm_of_phy_provider_register(twl->dev,
699 of_phy_simple_xlate);
700 if (IS_ERR(phy_provider))
701 return PTR_ERR(phy_provider);
702
703 phy = devm_phy_create(twl->dev, &ops, init_data); 698 phy = devm_phy_create(twl->dev, &ops, init_data);
704 if (IS_ERR(phy)) { 699 if (IS_ERR(phy)) {
705 dev_dbg(&pdev->dev, "Failed to create PHY\n"); 700 dev_dbg(&pdev->dev, "Failed to create PHY\n");
@@ -708,6 +703,11 @@ static int twl4030_usb_probe(struct platform_device *pdev)
708 703
709 phy_set_drvdata(phy, twl); 704 phy_set_drvdata(phy, twl);
710 705
706 phy_provider = devm_of_phy_provider_register(twl->dev,
707 of_phy_simple_xlate);
708 if (IS_ERR(phy_provider))
709 return PTR_ERR(phy_provider);
710
711 /* init spinlock for workqueue */ 711 /* init spinlock for workqueue */
712 spin_lock_init(&twl->lock); 712 spin_lock_init(&twl->lock);
713 713
diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index be361b7cd30f..1e4e69384baa 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -217,7 +217,7 @@ config PINCTRL_IMX28
217 select PINCTRL_MXS 217 select PINCTRL_MXS
218 218
219config PINCTRL_MSM 219config PINCTRL_MSM
220 tristate 220 bool
221 select PINMUX 221 select PINMUX
222 select PINCONF 222 select PINCONF
223 select GENERIC_PINCONF 223 select GENERIC_PINCONF
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 5ee61a470016..c0fe6091566a 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -851,7 +851,9 @@ static struct pinctrl *create_pinctrl(struct device *dev)
851 kref_init(&p->users); 851 kref_init(&p->users);
852 852
853 /* Add the pinctrl handle to the global list */ 853 /* Add the pinctrl handle to the global list */
854 mutex_lock(&pinctrl_list_mutex);
854 list_add_tail(&p->node, &pinctrl_list); 855 list_add_tail(&p->node, &pinctrl_list);
856 mutex_unlock(&pinctrl_list_mutex);
855 857
856 return p; 858 return p;
857} 859}
@@ -1642,8 +1644,10 @@ static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
1642 device_root, pctldev, &pinctrl_groups_ops); 1644 device_root, pctldev, &pinctrl_groups_ops);
1643 debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO, 1645 debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,
1644 device_root, pctldev, &pinctrl_gpioranges_ops); 1646 device_root, pctldev, &pinctrl_gpioranges_ops);
1645 pinmux_init_device_debugfs(device_root, pctldev); 1647 if (pctldev->desc->pmxops)
1646 pinconf_init_device_debugfs(device_root, pctldev); 1648 pinmux_init_device_debugfs(device_root, pctldev);
1649 if (pctldev->desc->confops)
1650 pinconf_init_device_debugfs(device_root, pctldev);
1647} 1651}
1648 1652
1649static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev) 1653static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 38c6f8b9790e..d990e33d8aa7 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -1286,22 +1286,22 @@ static int alt_gpio_irq_type(struct irq_data *d, unsigned type)
1286 1286
1287 switch (type) { 1287 switch (type) {
1288 case IRQ_TYPE_EDGE_RISING: 1288 case IRQ_TYPE_EDGE_RISING:
1289 irq_set_handler(d->irq, handle_simple_irq); 1289 __irq_set_handler_locked(d->irq, handle_simple_irq);
1290 writel_relaxed(mask, pio + PIO_ESR); 1290 writel_relaxed(mask, pio + PIO_ESR);
1291 writel_relaxed(mask, pio + PIO_REHLSR); 1291 writel_relaxed(mask, pio + PIO_REHLSR);
1292 break; 1292 break;
1293 case IRQ_TYPE_EDGE_FALLING: 1293 case IRQ_TYPE_EDGE_FALLING:
1294 irq_set_handler(d->irq, handle_simple_irq); 1294 __irq_set_handler_locked(d->irq, handle_simple_irq);
1295 writel_relaxed(mask, pio + PIO_ESR); 1295 writel_relaxed(mask, pio + PIO_ESR);
1296 writel_relaxed(mask, pio + PIO_FELLSR); 1296 writel_relaxed(mask, pio + PIO_FELLSR);
1297 break; 1297 break;
1298 case IRQ_TYPE_LEVEL_LOW: 1298 case IRQ_TYPE_LEVEL_LOW:
1299 irq_set_handler(d->irq, handle_level_irq); 1299 __irq_set_handler_locked(d->irq, handle_level_irq);
1300 writel_relaxed(mask, pio + PIO_LSR); 1300 writel_relaxed(mask, pio + PIO_LSR);
1301 writel_relaxed(mask, pio + PIO_FELLSR); 1301 writel_relaxed(mask, pio + PIO_FELLSR);
1302 break; 1302 break;
1303 case IRQ_TYPE_LEVEL_HIGH: 1303 case IRQ_TYPE_LEVEL_HIGH:
1304 irq_set_handler(d->irq, handle_level_irq); 1304 __irq_set_handler_locked(d->irq, handle_level_irq);
1305 writel_relaxed(mask, pio + PIO_LSR); 1305 writel_relaxed(mask, pio + PIO_LSR);
1306 writel_relaxed(mask, pio + PIO_REHLSR); 1306 writel_relaxed(mask, pio + PIO_REHLSR);
1307 break; 1307 break;
@@ -1310,7 +1310,7 @@ static int alt_gpio_irq_type(struct irq_data *d, unsigned type)
1310 * disable additional interrupt modes: 1310 * disable additional interrupt modes:
1311 * fall back to default behavior 1311 * fall back to default behavior
1312 */ 1312 */
1313 irq_set_handler(d->irq, handle_simple_irq); 1313 __irq_set_handler_locked(d->irq, handle_simple_irq);
1314 writel_relaxed(mask, pio + PIO_AIMDR); 1314 writel_relaxed(mask, pio + PIO_AIMDR);
1315 return 0; 1315 return 0;
1316 case IRQ_TYPE_NONE: 1316 case IRQ_TYPE_NONE:
diff --git a/drivers/pinctrl/pinctrl-capri.c b/drivers/pinctrl/pinctrl-capri.c
index 4669c53f99b0..eb2500212147 100644
--- a/drivers/pinctrl/pinctrl-capri.c
+++ b/drivers/pinctrl/pinctrl-capri.c
@@ -1435,7 +1435,7 @@ int __init capri_pinctrl_probe(struct platform_device *pdev)
1435} 1435}
1436 1436
1437static struct of_device_id capri_pinctrl_of_match[] = { 1437static struct of_device_id capri_pinctrl_of_match[] = {
1438 { .compatible = "brcm,capri-pinctrl", }, 1438 { .compatible = "brcm,bcm11351-pinctrl", },
1439 { }, 1439 { },
1440}; 1440};
1441 1441
diff --git a/drivers/pinctrl/pinctrl-imx1-core.c b/drivers/pinctrl/pinctrl-imx1-core.c
index 17aecde1b51d..815384b377b5 100644
--- a/drivers/pinctrl/pinctrl-imx1-core.c
+++ b/drivers/pinctrl/pinctrl-imx1-core.c
@@ -45,7 +45,7 @@ struct imx1_pinctrl {
45#define MX1_DDIR 0x00 45#define MX1_DDIR 0x00
46#define MX1_OCR 0x04 46#define MX1_OCR 0x04
47#define MX1_ICONFA 0x0c 47#define MX1_ICONFA 0x0c
48#define MX1_ICONFB 0x10 48#define MX1_ICONFB 0x14
49#define MX1_GIUS 0x20 49#define MX1_GIUS 0x20
50#define MX1_GPR 0x38 50#define MX1_GPR 0x38
51#define MX1_PUEN 0x40 51#define MX1_PUEN 0x40
@@ -97,13 +97,13 @@ static void imx1_write_2bit(struct imx1_pinctrl *ipctl, unsigned int pin_id,
97 u32 old_val; 97 u32 old_val;
98 u32 new_val; 98 u32 new_val;
99 99
100 dev_dbg(ipctl->dev, "write: register 0x%p offset %d value 0x%x\n",
101 reg, offset, value);
102
103 /* Use the next register if the pin's port pin number is >=16 */ 100 /* Use the next register if the pin's port pin number is >=16 */
104 if (pin_id % 32 >= 16) 101 if (pin_id % 32 >= 16)
105 reg += 0x04; 102 reg += 0x04;
106 103
104 dev_dbg(ipctl->dev, "write: register 0x%p offset %d value 0x%x\n",
105 reg, offset, value);
106
107 /* Get current state of pins */ 107 /* Get current state of pins */
108 old_val = readl(reg); 108 old_val = readl(reg);
109 old_val &= mask; 109 old_val &= mask;
@@ -139,7 +139,7 @@ static int imx1_read_2bit(struct imx1_pinctrl *ipctl, unsigned int pin_id,
139 u32 reg_offset) 139 u32 reg_offset)
140{ 140{
141 void __iomem *reg = imx1_mem(ipctl, pin_id) + reg_offset; 141 void __iomem *reg = imx1_mem(ipctl, pin_id) + reg_offset;
142 int offset = pin_id % 16; 142 int offset = (pin_id % 16) * 2;
143 143
144 /* Use the next register if the pin's port pin number is >=16 */ 144 /* Use the next register if the pin's port pin number is >=16 */
145 if (pin_id % 32 >= 16) 145 if (pin_id % 32 >= 16)
diff --git a/drivers/pinctrl/pinctrl-sunxi.c b/drivers/pinctrl/pinctrl-sunxi.c
index 9ccf681dad2f..f9fabe9bf47d 100644
--- a/drivers/pinctrl/pinctrl-sunxi.c
+++ b/drivers/pinctrl/pinctrl-sunxi.c
@@ -14,6 +14,7 @@
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/gpio.h> 15#include <linux/gpio.h>
16#include <linux/irqdomain.h> 16#include <linux/irqdomain.h>
17#include <linux/irqchip/chained_irq.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/of.h> 19#include <linux/of.h>
19#include <linux/of_address.h> 20#include <linux/of_address.h>
@@ -584,7 +585,7 @@ static int sunxi_pinctrl_irq_set_type(struct irq_data *d,
584 spin_lock_irqsave(&pctl->lock, flags); 585 spin_lock_irqsave(&pctl->lock, flags);
585 586
586 regval = readl(pctl->membase + reg); 587 regval = readl(pctl->membase + reg);
587 regval &= ~IRQ_CFG_IRQ_MASK; 588 regval &= ~(IRQ_CFG_IRQ_MASK << index);
588 writel(regval | (mode << index), pctl->membase + reg); 589 writel(regval | (mode << index), pctl->membase + reg);
589 590
590 spin_unlock_irqrestore(&pctl->lock, flags); 591 spin_unlock_irqrestore(&pctl->lock, flags);
@@ -665,6 +666,7 @@ static struct irq_chip sunxi_pinctrl_irq_chip = {
665 666
666static void sunxi_pinctrl_irq_handler(unsigned irq, struct irq_desc *desc) 667static void sunxi_pinctrl_irq_handler(unsigned irq, struct irq_desc *desc)
667{ 668{
669 struct irq_chip *chip = irq_get_chip(irq);
668 struct sunxi_pinctrl *pctl = irq_get_handler_data(irq); 670 struct sunxi_pinctrl *pctl = irq_get_handler_data(irq);
669 const unsigned long reg = readl(pctl->membase + IRQ_STATUS_REG); 671 const unsigned long reg = readl(pctl->membase + IRQ_STATUS_REG);
670 672
@@ -674,10 +676,12 @@ static void sunxi_pinctrl_irq_handler(unsigned irq, struct irq_desc *desc)
674 if (reg) { 676 if (reg) {
675 int irqoffset; 677 int irqoffset;
676 678
679 chained_irq_enter(chip, desc);
677 for_each_set_bit(irqoffset, &reg, SUNXI_IRQ_NUMBER) { 680 for_each_set_bit(irqoffset, &reg, SUNXI_IRQ_NUMBER) {
678 int pin_irq = irq_find_mapping(pctl->domain, irqoffset); 681 int pin_irq = irq_find_mapping(pctl->domain, irqoffset);
679 generic_handle_irq(pin_irq); 682 generic_handle_irq(pin_irq);
680 } 683 }
684 chained_irq_exit(chip, desc);
681 } 685 }
682} 686}
683 687
diff --git a/drivers/pinctrl/pinctrl-sunxi.h b/drivers/pinctrl/pinctrl-sunxi.h
index 01c494f8a14f..552b0e97077a 100644
--- a/drivers/pinctrl/pinctrl-sunxi.h
+++ b/drivers/pinctrl/pinctrl-sunxi.h
@@ -511,7 +511,7 @@ static inline u32 sunxi_pull_offset(u16 pin)
511 511
512static inline u32 sunxi_irq_cfg_reg(u16 irq) 512static inline u32 sunxi_irq_cfg_reg(u16 irq)
513{ 513{
514 u8 reg = irq / IRQ_CFG_IRQ_PER_REG; 514 u8 reg = irq / IRQ_CFG_IRQ_PER_REG * 0x04;
515 return reg + IRQ_CFG_REG; 515 return reg + IRQ_CFG_REG;
516} 516}
517 517
@@ -523,7 +523,7 @@ static inline u32 sunxi_irq_cfg_offset(u16 irq)
523 523
524static inline u32 sunxi_irq_ctrl_reg(u16 irq) 524static inline u32 sunxi_irq_ctrl_reg(u16 irq)
525{ 525{
526 u8 reg = irq / IRQ_CTRL_IRQ_PER_REG; 526 u8 reg = irq / IRQ_CTRL_IRQ_PER_REG * 0x04;
527 return reg + IRQ_CTRL_REG; 527 return reg + IRQ_CTRL_REG;
528} 528}
529 529
@@ -535,7 +535,7 @@ static inline u32 sunxi_irq_ctrl_offset(u16 irq)
535 535
536static inline u32 sunxi_irq_status_reg(u16 irq) 536static inline u32 sunxi_irq_status_reg(u16 irq)
537{ 537{
538 u8 reg = irq / IRQ_STATUS_IRQ_PER_REG; 538 u8 reg = irq / IRQ_STATUS_IRQ_PER_REG * 0x04;
539 return reg + IRQ_STATUS_REG; 539 return reg + IRQ_STATUS_REG;
540} 540}
541 541
diff --git a/drivers/pinctrl/pinctrl-tegra.c b/drivers/pinctrl/pinctrl-tegra.c
index a2e93a2b5ff4..e767355ab0ad 100644
--- a/drivers/pinctrl/pinctrl-tegra.c
+++ b/drivers/pinctrl/pinctrl-tegra.c
@@ -645,7 +645,7 @@ int tegra_pinctrl_probe(struct platform_device *pdev,
645 GFP_KERNEL); 645 GFP_KERNEL);
646 if (!pmx->regs) { 646 if (!pmx->regs) {
647 dev_err(&pdev->dev, "Can't alloc regs pointer\n"); 647 dev_err(&pdev->dev, "Can't alloc regs pointer\n");
648 return -ENODEV; 648 return -ENOMEM;
649 } 649 }
650 650
651 for (i = 0; i < pmx->nbanks; i++) { 651 for (i = 0; i < pmx->nbanks; i++) {
diff --git a/drivers/pinctrl/sh-pfc/pfc-r8a7791.c b/drivers/pinctrl/sh-pfc/pfc-r8a7791.c
index 77d103fe39d9..567d6918d50b 100644
--- a/drivers/pinctrl/sh-pfc/pfc-r8a7791.c
+++ b/drivers/pinctrl/sh-pfc/pfc-r8a7791.c
@@ -89,7 +89,8 @@ enum {
89 89
90 /* GPSR6 */ 90 /* GPSR6 */
91 FN_IP13_10, FN_IP13_11, FN_IP13_12, FN_IP13_13, FN_IP13_14, 91 FN_IP13_10, FN_IP13_11, FN_IP13_12, FN_IP13_13, FN_IP13_14,
92 FN_IP13_15, FN_IP13_18_16, FN_IP13_21_19, FN_IP13_22, FN_IP13_24_23, 92 FN_IP13_15, FN_IP13_18_16, FN_IP13_21_19,
93 FN_IP13_22, FN_IP13_24_23, FN_SD1_CLK,
93 FN_IP13_25, FN_IP13_26, FN_IP13_27, FN_IP13_30_28, FN_IP14_1_0, 94 FN_IP13_25, FN_IP13_26, FN_IP13_27, FN_IP13_30_28, FN_IP14_1_0,
94 FN_IP14_2, FN_IP14_3, FN_IP14_4, FN_IP14_5, FN_IP14_6, FN_IP14_7, 95 FN_IP14_2, FN_IP14_3, FN_IP14_4, FN_IP14_5, FN_IP14_6, FN_IP14_7,
95 FN_IP14_10_8, FN_IP14_13_11, FN_IP14_16_14, FN_IP14_19_17, 96 FN_IP14_10_8, FN_IP14_13_11, FN_IP14_16_14, FN_IP14_19_17,
@@ -788,6 +789,7 @@ static const u16 pinmux_data[] = {
788 PINMUX_DATA(USB1_PWEN_MARK, FN_USB1_PWEN), 789 PINMUX_DATA(USB1_PWEN_MARK, FN_USB1_PWEN),
789 PINMUX_DATA(USB1_OVC_MARK, FN_USB1_OVC), 790 PINMUX_DATA(USB1_OVC_MARK, FN_USB1_OVC),
790 PINMUX_DATA(DU0_DOTCLKIN_MARK, FN_DU0_DOTCLKIN), 791 PINMUX_DATA(DU0_DOTCLKIN_MARK, FN_DU0_DOTCLKIN),
792 PINMUX_DATA(SD1_CLK_MARK, FN_SD1_CLK),
791 793
792 /* IPSR0 */ 794 /* IPSR0 */
793 PINMUX_IPSR_DATA(IP0_0, D0), 795 PINMUX_IPSR_DATA(IP0_0, D0),
@@ -3825,7 +3827,7 @@ static const struct pinmux_cfg_reg pinmux_config_regs[] = {
3825 GP_6_11_FN, FN_IP13_25, 3827 GP_6_11_FN, FN_IP13_25,
3826 GP_6_10_FN, FN_IP13_24_23, 3828 GP_6_10_FN, FN_IP13_24_23,
3827 GP_6_9_FN, FN_IP13_22, 3829 GP_6_9_FN, FN_IP13_22,
3828 0, 0, 3830 GP_6_8_FN, FN_SD1_CLK,
3829 GP_6_7_FN, FN_IP13_21_19, 3831 GP_6_7_FN, FN_IP13_21_19,
3830 GP_6_6_FN, FN_IP13_18_16, 3832 GP_6_6_FN, FN_IP13_18_16,
3831 GP_6_5_FN, FN_IP13_15, 3833 GP_6_5_FN, FN_IP13_15,
diff --git a/drivers/pinctrl/sirf/pinctrl-prima2.c b/drivers/pinctrl/sirf/pinctrl-prima2.c
index 37b42651d76a..dde0285544d6 100644
--- a/drivers/pinctrl/sirf/pinctrl-prima2.c
+++ b/drivers/pinctrl/sirf/pinctrl-prima2.c
@@ -413,7 +413,7 @@ static const struct sirfsoc_padmux ac97_padmux = {
413 .funcval = 0, 413 .funcval = 0,
414}; 414};
415 415
416static const unsigned ac97_pins[] = { 33, 34, 35, 36 }; 416static const unsigned ac97_pins[] = { 43, 44, 45, 46 };
417 417
418static const struct sirfsoc_muxmask spi1_muxmask[] = { 418static const struct sirfsoc_muxmask spi1_muxmask[] = {
419 { 419 {
diff --git a/drivers/pinctrl/sirf/pinctrl-sirf.c b/drivers/pinctrl/sirf/pinctrl-sirf.c
index a0d6152701cd..617a4916b50f 100644
--- a/drivers/pinctrl/sirf/pinctrl-sirf.c
+++ b/drivers/pinctrl/sirf/pinctrl-sirf.c
@@ -598,7 +598,7 @@ static unsigned int sirfsoc_gpio_irq_startup(struct irq_data *d)
598{ 598{
599 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); 599 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
600 600
601 if (gpio_lock_as_irq(&bank->chip.gc, d->hwirq)) 601 if (gpio_lock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE))
602 dev_err(bank->chip.gc.dev, 602 dev_err(bank->chip.gc.dev,
603 "unable to lock HW IRQ %lu for IRQ\n", 603 "unable to lock HW IRQ %lu for IRQ\n",
604 d->hwirq); 604 d->hwirq);
@@ -611,7 +611,7 @@ static void sirfsoc_gpio_irq_shutdown(struct irq_data *d)
611 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); 611 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
612 612
613 sirfsoc_gpio_irq_mask(d); 613 sirfsoc_gpio_irq_mask(d);
614 gpio_unlock_as_irq(&bank->chip.gc, d->hwirq); 614 gpio_unlock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE);
615} 615}
616 616
617static struct irq_chip sirfsoc_irq_chip = { 617static struct irq_chip sirfsoc_irq_chip = {
diff --git a/drivers/pinctrl/vt8500/pinctrl-wmt.c b/drivers/pinctrl/vt8500/pinctrl-wmt.c
index b28d1af9c232..9802b67040cc 100644
--- a/drivers/pinctrl/vt8500/pinctrl-wmt.c
+++ b/drivers/pinctrl/vt8500/pinctrl-wmt.c
@@ -276,7 +276,20 @@ static int wmt_pctl_dt_node_to_map_pull(struct wmt_pinctrl_data *data,
276 if (!configs) 276 if (!configs)
277 return -ENOMEM; 277 return -ENOMEM;
278 278
279 configs[0] = pull; 279 switch (pull) {
280 case 0:
281 configs[0] = PIN_CONFIG_BIAS_DISABLE;
282 break;
283 case 1:
284 configs[0] = PIN_CONFIG_BIAS_PULL_DOWN;
285 break;
286 case 2:
287 configs[0] = PIN_CONFIG_BIAS_PULL_UP;
288 break;
289 default:
290 configs[0] = PIN_CONFIG_BIAS_DISABLE;
291 dev_err(data->dev, "invalid pull state %d - disabling\n", pull);
292 }
280 293
281 map->type = PIN_MAP_TYPE_CONFIGS_PIN; 294 map->type = PIN_MAP_TYPE_CONFIGS_PIN;
282 map->data.configs.group_or_pin = data->groups[group]; 295 map->data.configs.group_or_pin = data->groups[group];
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 167f3d00c916..66977ebf13b3 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -183,9 +183,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
183 struct resource r = {0}; 183 struct resource r = {0};
184 int i, flags; 184 int i, flags;
185 185
186 if (acpi_dev_resource_memory(res, &r) 186 if (acpi_dev_resource_address_space(res, &r)
187 || acpi_dev_resource_io(res, &r)
188 || acpi_dev_resource_address_space(res, &r)
189 || acpi_dev_resource_ext_address_space(res, &r)) { 187 || acpi_dev_resource_ext_address_space(res, &r)) {
190 pnp_add_resource(dev, &r); 188 pnp_add_resource(dev, &r);
191 return AE_OK; 189 return AE_OK;
@@ -217,6 +215,17 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
217 } 215 }
218 216
219 switch (res->type) { 217 switch (res->type) {
218 case ACPI_RESOURCE_TYPE_MEMORY24:
219 case ACPI_RESOURCE_TYPE_MEMORY32:
220 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
221 if (acpi_dev_resource_memory(res, &r))
222 pnp_add_resource(dev, &r);
223 break;
224 case ACPI_RESOURCE_TYPE_IO:
225 case ACPI_RESOURCE_TYPE_FIXED_IO:
226 if (acpi_dev_resource_io(res, &r))
227 pnp_add_resource(dev, &r);
228 break;
220 case ACPI_RESOURCE_TYPE_DMA: 229 case ACPI_RESOURCE_TYPE_DMA:
221 dma = &res->data.dma; 230 dma = &res->data.dma;
222 if (dma->channel_count > 0 && dma->channels[0] != (u8) -1) 231 if (dma->channel_count > 0 && dma->channels[0] != (u8) -1)
diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
index 769d265b221b..deb7f4bcdb7b 100644
--- a/drivers/pnp/pnpbios/bioscalls.c
+++ b/drivers/pnp/pnpbios/bioscalls.c
@@ -21,7 +21,7 @@
21 21
22#include "pnpbios.h" 22#include "pnpbios.h"
23 23
24static struct { 24__visible struct {
25 u16 offset; 25 u16 offset;
26 u16 segment; 26 u16 segment;
27} pnp_bios_callpoint; 27} pnp_bios_callpoint;
@@ -41,6 +41,7 @@ asmlinkage void pnp_bios_callfunc(void);
41 41
42__asm__(".text \n" 42__asm__(".text \n"
43 __ALIGN_STR "\n" 43 __ALIGN_STR "\n"
44 ".globl pnp_bios_callfunc\n"
44 "pnp_bios_callfunc:\n" 45 "pnp_bios_callfunc:\n"
45 " pushl %edx \n" 46 " pushl %edx \n"
46 " pushl %ecx \n" 47 " pushl %ecx \n"
@@ -66,9 +67,9 @@ static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
66 * after PnP BIOS oopses. 67 * after PnP BIOS oopses.
67 */ 68 */
68 69
69u32 pnp_bios_fault_esp; 70__visible u32 pnp_bios_fault_esp;
70u32 pnp_bios_fault_eip; 71__visible u32 pnp_bios_fault_eip;
71u32 pnp_bios_is_utter_crap = 0; 72__visible u32 pnp_bios_is_utter_crap = 0;
72 73
73static spinlock_t pnp_bios_lock; 74static spinlock_t pnp_bios_lock;
74 75
diff --git a/drivers/power/ds2782_battery.c b/drivers/power/ds2782_battery.c
index 563174891c90..041f9b638d28 100644
--- a/drivers/power/ds2782_battery.c
+++ b/drivers/power/ds2782_battery.c
@@ -192,7 +192,7 @@ static int ds2786_get_voltage(struct ds278x_info *info, int *voltage_uV)
192 192
193 /* 193 /*
194 * Voltage is measured in units of 1.22mV. The voltage is stored as 194 * Voltage is measured in units of 1.22mV. The voltage is stored as
195 * a 10-bit number plus sign, in the upper bits of a 16-bit register 195 * a 12-bit number plus sign, in the upper bits of a 16-bit register
196 */ 196 */
197 err = ds278x_read_reg16(info, DS278x_REG_VOLT_MSB, &raw); 197 err = ds278x_read_reg16(info, DS278x_REG_VOLT_MSB, &raw);
198 if (err) 198 if (err)
diff --git a/drivers/power/isp1704_charger.c b/drivers/power/isp1704_charger.c
index 80edb7d8cb54..0b4cf9d63291 100644
--- a/drivers/power/isp1704_charger.c
+++ b/drivers/power/isp1704_charger.c
@@ -444,8 +444,6 @@ static int isp1704_charger_probe(struct platform_device *pdev)
444 ret = PTR_ERR(isp->phy); 444 ret = PTR_ERR(isp->phy);
445 goto fail0; 445 goto fail0;
446 } 446 }
447 if (!isp->phy)
448 goto fail0;
449 447
450 isp->dev = &pdev->dev; 448 isp->dev = &pdev->dev;
451 platform_set_drvdata(pdev, isp); 449 platform_set_drvdata(pdev, isp);
diff --git a/drivers/power/max17040_battery.c b/drivers/power/max17040_battery.c
index c7ff6d67f158..0fbac861080d 100644
--- a/drivers/power/max17040_battery.c
+++ b/drivers/power/max17040_battery.c
@@ -148,7 +148,7 @@ static void max17040_get_online(struct i2c_client *client)
148{ 148{
149 struct max17040_chip *chip = i2c_get_clientdata(client); 149 struct max17040_chip *chip = i2c_get_clientdata(client);
150 150
151 if (chip->pdata->battery_online) 151 if (chip->pdata && chip->pdata->battery_online)
152 chip->online = chip->pdata->battery_online(); 152 chip->online = chip->pdata->battery_online();
153 else 153 else
154 chip->online = 1; 154 chip->online = 1;
@@ -158,7 +158,8 @@ static void max17040_get_status(struct i2c_client *client)
158{ 158{
159 struct max17040_chip *chip = i2c_get_clientdata(client); 159 struct max17040_chip *chip = i2c_get_clientdata(client);
160 160
161 if (!chip->pdata->charger_online || !chip->pdata->charger_enable) { 161 if (!chip->pdata || !chip->pdata->charger_online
162 || !chip->pdata->charger_enable) {
162 chip->status = POWER_SUPPLY_STATUS_UNKNOWN; 163 chip->status = POWER_SUPPLY_STATUS_UNKNOWN;
163 return; 164 return;
164 } 165 }
diff --git a/drivers/ps3/ps3-vuart.c b/drivers/ps3/ps3-vuart.c
index fb7300837fee..bc1e5139ba29 100644
--- a/drivers/ps3/ps3-vuart.c
+++ b/drivers/ps3/ps3-vuart.c
@@ -699,8 +699,6 @@ int ps3_vuart_read_async(struct ps3_system_bus_device *dev, unsigned int bytes)
699 699
700 BUG_ON(!bytes); 700 BUG_ON(!bytes);
701 701
702 PREPARE_WORK(&priv->rx_list.work.work, ps3_vuart_work);
703
704 spin_lock_irqsave(&priv->rx_list.lock, flags); 702 spin_lock_irqsave(&priv->rx_list.lock, flags);
705 if (priv->rx_list.bytes_held >= bytes) { 703 if (priv->rx_list.bytes_held >= bytes) {
706 dev_dbg(&dev->core, "%s:%d: schedule_work %xh bytes\n", 704 dev_dbg(&dev->core, "%s:%d: schedule_work %xh bytes\n",
@@ -1052,7 +1050,7 @@ static int ps3_vuart_probe(struct ps3_system_bus_device *dev)
1052 INIT_LIST_HEAD(&priv->rx_list.head); 1050 INIT_LIST_HEAD(&priv->rx_list.head);
1053 spin_lock_init(&priv->rx_list.lock); 1051 spin_lock_init(&priv->rx_list.lock);
1054 1052
1055 INIT_WORK(&priv->rx_list.work.work, NULL); 1053 INIT_WORK(&priv->rx_list.work.work, ps3_vuart_work);
1056 priv->rx_list.work.trigger = 0; 1054 priv->rx_list.work.trigger = 0;
1057 priv->rx_list.work.dev = dev; 1055 priv->rx_list.work.dev = dev;
1058 1056
diff --git a/drivers/pwm/pwm-lp3943.c b/drivers/pwm/pwm-lp3943.c
index 8a843a04c224..a40b9c34e9ff 100644
--- a/drivers/pwm/pwm-lp3943.c
+++ b/drivers/pwm/pwm-lp3943.c
@@ -52,8 +52,10 @@ lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm)
52 offset = pwm_map->output[i]; 52 offset = pwm_map->output[i];
53 53
54 /* Return an error if the pin is already assigned */ 54 /* Return an error if the pin is already assigned */
55 if (test_and_set_bit(offset, &lp3943->pin_used)) 55 if (test_and_set_bit(offset, &lp3943->pin_used)) {
56 kfree(pwm_map);
56 return ERR_PTR(-EBUSY); 57 return ERR_PTR(-EBUSY);
58 }
57 } 59 }
58 60
59 return pwm_map; 61 return pwm_map;
diff --git a/drivers/rapidio/devices/tsi721.h b/drivers/rapidio/devices/tsi721.h
index b4b0d83f9ef6..7061ac0ad428 100644
--- a/drivers/rapidio/devices/tsi721.h
+++ b/drivers/rapidio/devices/tsi721.h
@@ -678,6 +678,7 @@ struct tsi721_bdma_chan {
678 struct list_head free_list; 678 struct list_head free_list;
679 dma_cookie_t completed_cookie; 679 dma_cookie_t completed_cookie;
680 struct tasklet_struct tasklet; 680 struct tasklet_struct tasklet;
681 bool active;
681}; 682};
682 683
683#endif /* CONFIG_RAPIDIO_DMA_ENGINE */ 684#endif /* CONFIG_RAPIDIO_DMA_ENGINE */
diff --git a/drivers/rapidio/devices/tsi721_dma.c b/drivers/rapidio/devices/tsi721_dma.c
index 502663f5f7c6..91245f5dbe81 100644
--- a/drivers/rapidio/devices/tsi721_dma.c
+++ b/drivers/rapidio/devices/tsi721_dma.c
@@ -206,8 +206,8 @@ void tsi721_bdma_handler(struct tsi721_bdma_chan *bdma_chan)
206{ 206{
207 /* Disable BDMA channel interrupts */ 207 /* Disable BDMA channel interrupts */
208 iowrite32(0, bdma_chan->regs + TSI721_DMAC_INTE); 208 iowrite32(0, bdma_chan->regs + TSI721_DMAC_INTE);
209 209 if (bdma_chan->active)
210 tasklet_schedule(&bdma_chan->tasklet); 210 tasklet_schedule(&bdma_chan->tasklet);
211} 211}
212 212
213#ifdef CONFIG_PCI_MSI 213#ifdef CONFIG_PCI_MSI
@@ -562,7 +562,7 @@ static int tsi721_alloc_chan_resources(struct dma_chan *dchan)
562 } 562 }
563#endif /* CONFIG_PCI_MSI */ 563#endif /* CONFIG_PCI_MSI */
564 564
565 tasklet_enable(&bdma_chan->tasklet); 565 bdma_chan->active = true;
566 tsi721_bdma_interrupt_enable(bdma_chan, 1); 566 tsi721_bdma_interrupt_enable(bdma_chan, 1);
567 567
568 return bdma_chan->bd_num - 1; 568 return bdma_chan->bd_num - 1;
@@ -576,9 +576,7 @@ err_out:
576static void tsi721_free_chan_resources(struct dma_chan *dchan) 576static void tsi721_free_chan_resources(struct dma_chan *dchan)
577{ 577{
578 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan); 578 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan);
579#ifdef CONFIG_PCI_MSI
580 struct tsi721_device *priv = to_tsi721(dchan->device); 579 struct tsi721_device *priv = to_tsi721(dchan->device);
581#endif
582 LIST_HEAD(list); 580 LIST_HEAD(list);
583 581
584 dev_dbg(dchan->device->dev, "%s: Entry\n", __func__); 582 dev_dbg(dchan->device->dev, "%s: Entry\n", __func__);
@@ -589,14 +587,25 @@ static void tsi721_free_chan_resources(struct dma_chan *dchan)
589 BUG_ON(!list_empty(&bdma_chan->active_list)); 587 BUG_ON(!list_empty(&bdma_chan->active_list));
590 BUG_ON(!list_empty(&bdma_chan->queue)); 588 BUG_ON(!list_empty(&bdma_chan->queue));
591 589
592 tasklet_disable(&bdma_chan->tasklet); 590 tsi721_bdma_interrupt_enable(bdma_chan, 0);
591 bdma_chan->active = false;
592
593#ifdef CONFIG_PCI_MSI
594 if (priv->flags & TSI721_USING_MSIX) {
595 synchronize_irq(priv->msix[TSI721_VECT_DMA0_DONE +
596 bdma_chan->id].vector);
597 synchronize_irq(priv->msix[TSI721_VECT_DMA0_INT +
598 bdma_chan->id].vector);
599 } else
600#endif
601 synchronize_irq(priv->pdev->irq);
602
603 tasklet_kill(&bdma_chan->tasklet);
593 604
594 spin_lock_bh(&bdma_chan->lock); 605 spin_lock_bh(&bdma_chan->lock);
595 list_splice_init(&bdma_chan->free_list, &list); 606 list_splice_init(&bdma_chan->free_list, &list);
596 spin_unlock_bh(&bdma_chan->lock); 607 spin_unlock_bh(&bdma_chan->lock);
597 608
598 tsi721_bdma_interrupt_enable(bdma_chan, 0);
599
600#ifdef CONFIG_PCI_MSI 609#ifdef CONFIG_PCI_MSI
601 if (priv->flags & TSI721_USING_MSIX) { 610 if (priv->flags & TSI721_USING_MSIX) {
602 free_irq(priv->msix[TSI721_VECT_DMA0_DONE + 611 free_irq(priv->msix[TSI721_VECT_DMA0_DONE +
@@ -790,6 +799,7 @@ int tsi721_register_dma(struct tsi721_device *priv)
790 bdma_chan->dchan.cookie = 1; 799 bdma_chan->dchan.cookie = 1;
791 bdma_chan->dchan.chan_id = i; 800 bdma_chan->dchan.chan_id = i;
792 bdma_chan->id = i; 801 bdma_chan->id = i;
802 bdma_chan->active = false;
793 803
794 spin_lock_init(&bdma_chan->lock); 804 spin_lock_init(&bdma_chan->lock);
795 805
@@ -799,7 +809,6 @@ int tsi721_register_dma(struct tsi721_device *priv)
799 809
800 tasklet_init(&bdma_chan->tasklet, tsi721_dma_tasklet, 810 tasklet_init(&bdma_chan->tasklet, tsi721_dma_tasklet,
801 (unsigned long)bdma_chan); 811 (unsigned long)bdma_chan);
802 tasklet_disable(&bdma_chan->tasklet);
803 list_add_tail(&bdma_chan->dchan.device_node, 812 list_add_tail(&bdma_chan->dchan.device_node,
804 &mport->dma.channels); 813 &mport->dma.channels);
805 } 814 }
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index 77b46d0b37a6..e10febe9ec34 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -498,7 +498,7 @@ static int ab3100_regulator_register(struct platform_device *pdev,
498 struct ab3100_platform_data *plfdata, 498 struct ab3100_platform_data *plfdata,
499 struct regulator_init_data *init_data, 499 struct regulator_init_data *init_data,
500 struct device_node *np, 500 struct device_node *np,
501 int id) 501 unsigned long id)
502{ 502{
503 struct regulator_desc *desc; 503 struct regulator_desc *desc;
504 struct ab3100_regulator *reg; 504 struct ab3100_regulator *reg;
@@ -646,7 +646,7 @@ ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
646 err = ab3100_regulator_register( 646 err = ab3100_regulator_register(
647 pdev, NULL, ab3100_regulator_matches[i].init_data, 647 pdev, NULL, ab3100_regulator_matches[i].init_data,
648 ab3100_regulator_matches[i].of_node, 648 ab3100_regulator_matches[i].of_node,
649 (int) ab3100_regulator_matches[i].driver_data); 649 (unsigned long)ab3100_regulator_matches[i].driver_data);
650 if (err) { 650 if (err) {
651 ab3100_regulators_remove(pdev); 651 ab3100_regulators_remove(pdev);
652 return err; 652 return err;
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b38a6b669e8c..afca1bc24f26 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -953,6 +953,8 @@ static int machine_constraints_current(struct regulator_dev *rdev,
953 return 0; 953 return 0;
954} 954}
955 955
956static int _regulator_do_enable(struct regulator_dev *rdev);
957
956/** 958/**
957 * set_machine_constraints - sets regulator constraints 959 * set_machine_constraints - sets regulator constraints
958 * @rdev: regulator source 960 * @rdev: regulator source
@@ -1013,10 +1015,9 @@ static int set_machine_constraints(struct regulator_dev *rdev,
1013 /* If the constraints say the regulator should be on at this point 1015 /* If the constraints say the regulator should be on at this point
1014 * and we have control then make sure it is enabled. 1016 * and we have control then make sure it is enabled.
1015 */ 1017 */
1016 if ((rdev->constraints->always_on || rdev->constraints->boot_on) && 1018 if (rdev->constraints->always_on || rdev->constraints->boot_on) {
1017 ops->enable) { 1019 ret = _regulator_do_enable(rdev);
1018 ret = ops->enable(rdev); 1020 if (ret < 0 && ret != -EINVAL) {
1019 if (ret < 0) {
1020 rdev_err(rdev, "failed to enable\n"); 1021 rdev_err(rdev, "failed to enable\n");
1021 goto out; 1022 goto out;
1022 } 1023 }
@@ -1272,6 +1273,8 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
1272 if (r->dev.parent && 1273 if (r->dev.parent &&
1273 node == r->dev.of_node) 1274 node == r->dev.of_node)
1274 return r; 1275 return r;
1276 *ret = -EPROBE_DEFER;
1277 return NULL;
1275 } else { 1278 } else {
1276 /* 1279 /*
1277 * If we couldn't even get the node then it's 1280 * If we couldn't even get the node then it's
@@ -1312,7 +1315,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1312 struct regulator_dev *rdev; 1315 struct regulator_dev *rdev;
1313 struct regulator *regulator = ERR_PTR(-EPROBE_DEFER); 1316 struct regulator *regulator = ERR_PTR(-EPROBE_DEFER);
1314 const char *devname = NULL; 1317 const char *devname = NULL;
1315 int ret = -EPROBE_DEFER; 1318 int ret;
1316 1319
1317 if (id == NULL) { 1320 if (id == NULL) {
1318 pr_err("get() with no identifier\n"); 1321 pr_err("get() with no identifier\n");
@@ -1322,6 +1325,11 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1322 if (dev) 1325 if (dev)
1323 devname = dev_name(dev); 1326 devname = dev_name(dev);
1324 1327
1328 if (have_full_constraints())
1329 ret = -ENODEV;
1330 else
1331 ret = -EPROBE_DEFER;
1332
1325 mutex_lock(&regulator_list_mutex); 1333 mutex_lock(&regulator_list_mutex);
1326 1334
1327 rdev = regulator_dev_lookup(dev, id, &ret); 1335 rdev = regulator_dev_lookup(dev, id, &ret);
@@ -1352,7 +1360,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1352 goto found; 1360 goto found;
1353 /* Don't log an error when called from regulator_get_optional() */ 1361 /* Don't log an error when called from regulator_get_optional() */
1354 } else if (!have_full_constraints() || exclusive) { 1362 } else if (!have_full_constraints() || exclusive) {
1355 dev_err(dev, "dummy supplies not allowed\n"); 1363 dev_warn(dev, "dummy supplies not allowed\n");
1356 } 1364 }
1357 1365
1358 mutex_unlock(&regulator_list_mutex); 1366 mutex_unlock(&regulator_list_mutex);
@@ -1900,8 +1908,6 @@ static int _regulator_do_disable(struct regulator_dev *rdev)
1900 1908
1901 trace_regulator_disable_complete(rdev_get_name(rdev)); 1909 trace_regulator_disable_complete(rdev_get_name(rdev));
1902 1910
1903 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1904 NULL);
1905 return 0; 1911 return 0;
1906} 1912}
1907 1913
@@ -1925,6 +1931,8 @@ static int _regulator_disable(struct regulator_dev *rdev)
1925 rdev_err(rdev, "failed to disable\n"); 1931 rdev_err(rdev, "failed to disable\n");
1926 return ret; 1932 return ret;
1927 } 1933 }
1934 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1935 NULL);
1928 } 1936 }
1929 1937
1930 rdev->use_count = 0; 1938 rdev->use_count = 0;
@@ -1977,20 +1985,16 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
1977{ 1985{
1978 int ret = 0; 1986 int ret = 0;
1979 1987
1980 /* force disable */ 1988 ret = _regulator_do_disable(rdev);
1981 if (rdev->desc->ops->disable) { 1989 if (ret < 0) {
1982 /* ah well, who wants to live forever... */ 1990 rdev_err(rdev, "failed to force disable\n");
1983 ret = rdev->desc->ops->disable(rdev); 1991 return ret;
1984 if (ret < 0) {
1985 rdev_err(rdev, "failed to force disable\n");
1986 return ret;
1987 }
1988 /* notify other consumers that power has been forced off */
1989 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
1990 REGULATOR_EVENT_DISABLE, NULL);
1991 } 1992 }
1992 1993
1993 return ret; 1994 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
1995 REGULATOR_EVENT_DISABLE, NULL);
1996
1997 return 0;
1994} 1998}
1995 1999
1996/** 2000/**
@@ -3623,23 +3627,18 @@ int regulator_suspend_finish(void)
3623 3627
3624 mutex_lock(&regulator_list_mutex); 3628 mutex_lock(&regulator_list_mutex);
3625 list_for_each_entry(rdev, &regulator_list, list) { 3629 list_for_each_entry(rdev, &regulator_list, list) {
3626 struct regulator_ops *ops = rdev->desc->ops;
3627
3628 mutex_lock(&rdev->mutex); 3630 mutex_lock(&rdev->mutex);
3629 if ((rdev->use_count > 0 || rdev->constraints->always_on) && 3631 if (rdev->use_count > 0 || rdev->constraints->always_on) {
3630 ops->enable) { 3632 error = _regulator_do_enable(rdev);
3631 error = ops->enable(rdev);
3632 if (error) 3633 if (error)
3633 ret = error; 3634 ret = error;
3634 } else { 3635 } else {
3635 if (!have_full_constraints()) 3636 if (!have_full_constraints())
3636 goto unlock; 3637 goto unlock;
3637 if (!ops->disable)
3638 goto unlock;
3639 if (!_regulator_is_enabled(rdev)) 3638 if (!_regulator_is_enabled(rdev))
3640 goto unlock; 3639 goto unlock;
3641 3640
3642 error = ops->disable(rdev); 3641 error = _regulator_do_disable(rdev);
3643 if (error) 3642 if (error)
3644 ret = error; 3643 ret = error;
3645 } 3644 }
@@ -3813,7 +3812,7 @@ static int __init regulator_init_complete(void)
3813 ops = rdev->desc->ops; 3812 ops = rdev->desc->ops;
3814 c = rdev->constraints; 3813 c = rdev->constraints;
3815 3814
3816 if (!ops->disable || (c && c->always_on)) 3815 if (c && c->always_on)
3817 continue; 3816 continue;
3818 3817
3819 mutex_lock(&rdev->mutex); 3818 mutex_lock(&rdev->mutex);
@@ -3834,7 +3833,7 @@ static int __init regulator_init_complete(void)
3834 /* We log since this may kill the system if it 3833 /* We log since this may kill the system if it
3835 * goes wrong. */ 3834 * goes wrong. */
3836 rdev_info(rdev, "disabling\n"); 3835 rdev_info(rdev, "disabling\n");
3837 ret = ops->disable(rdev); 3836 ret = _regulator_do_disable(rdev);
3838 if (ret != 0) 3837 if (ret != 0)
3839 rdev_err(rdev, "couldn't disable: %d\n", ret); 3838 rdev_err(rdev, "couldn't disable: %d\n", ret);
3840 } else { 3839 } else {
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
index 7f340206d329..b14ebdad5dd2 100644
--- a/drivers/regulator/da9055-regulator.c
+++ b/drivers/regulator/da9055-regulator.c
@@ -576,7 +576,9 @@ static int da9055_regulator_probe(struct platform_device *pdev)
576 /* Only LDO 5 and 6 has got the over current interrupt */ 576 /* Only LDO 5 and 6 has got the over current interrupt */
577 if (pdev->id == DA9055_ID_LDO5 || pdev->id == DA9055_ID_LDO6) { 577 if (pdev->id == DA9055_ID_LDO5 || pdev->id == DA9055_ID_LDO6) {
578 irq = platform_get_irq_byname(pdev, "REGULATOR"); 578 irq = platform_get_irq_byname(pdev, "REGULATOR");
579 irq = regmap_irq_get_virq(da9055->irq_data, irq); 579 if (irq < 0)
580 return irq;
581
580 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 582 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
581 da9055_ldo5_6_oc_irq, 583 da9055_ldo5_6_oc_irq,
582 IRQF_TRIGGER_HIGH | 584 IRQF_TRIGGER_HIGH |
diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
index 56727eb745df..91e99a2c8dc1 100644
--- a/drivers/regulator/da9063-regulator.c
+++ b/drivers/regulator/da9063-regulator.c
@@ -1,3 +1,4 @@
1
1/* 2/*
2 * Regulator driver for DA9063 PMIC series 3 * Regulator driver for DA9063 PMIC series
3 * 4 *
@@ -60,7 +61,8 @@ struct da9063_regulator_info {
60 .desc.ops = &da9063_ldo_ops, \ 61 .desc.ops = &da9063_ldo_ops, \
61 .desc.min_uV = (min_mV) * 1000, \ 62 .desc.min_uV = (min_mV) * 1000, \
62 .desc.uV_step = (step_mV) * 1000, \ 63 .desc.uV_step = (step_mV) * 1000, \
63 .desc.n_voltages = (((max_mV) - (min_mV))/(step_mV) + 1), \ 64 .desc.n_voltages = (((max_mV) - (min_mV))/(step_mV) + 1 \
65 + (DA9063_V##regl_name##_BIAS)), \
64 .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \ 66 .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \
65 .desc.enable_mask = DA9063_LDO_EN, \ 67 .desc.enable_mask = DA9063_LDO_EN, \
66 .desc.vsel_reg = DA9063_REG_V##regl_name##_A, \ 68 .desc.vsel_reg = DA9063_REG_V##regl_name##_A, \
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
index b1078ba3f393..e0619526708c 100644
--- a/drivers/regulator/max14577.c
+++ b/drivers/regulator/max14577.c
@@ -166,12 +166,14 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
166 166
167 ret = of_regulator_match(&pdev->dev, np, max14577_regulator_matches, 167 ret = of_regulator_match(&pdev->dev, np, max14577_regulator_matches,
168 MAX14577_REG_MAX); 168 MAX14577_REG_MAX);
169 if (ret < 0) { 169 if (ret < 0)
170 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret); 170 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
171 return ret; 171 else
172 } 172 ret = 0;
173 173
174 return 0; 174 of_node_put(np);
175
176 return ret;
175} 177}
176 178
177static inline struct regulator_init_data *match_init_data(int index) 179static inline struct regulator_init_data *match_init_data(int index)
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index d9e557990577..cd0b9e35a56d 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -441,6 +441,7 @@ common_reg:
441 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) { 441 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) {
442 if (!reg_np) { 442 if (!reg_np) {
443 config.init_data = pdata->regulators[i].initdata; 443 config.init_data = pdata->regulators[i].initdata;
444 config.of_node = pdata->regulators[i].reg_node;
444 } else { 445 } else {
445 config.init_data = rdata[i].init_data; 446 config.init_data = rdata[i].init_data;
446 config.of_node = rdata[i].of_node; 447 config.of_node = rdata[i].of_node;
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index d7164bb75d3e..d958dfa05125 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -535,7 +535,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
535 return -ENODEV; 535 return -ENODEV;
536 } 536 }
537 537
538 regulators_np = of_find_node_by_name(pmic_np, "regulators"); 538 regulators_np = of_get_child_by_name(pmic_np, "regulators");
539 if (!regulators_np) { 539 if (!regulators_np) {
540 dev_err(iodev->dev, "could not find regulators sub-node\n"); 540 dev_err(iodev->dev, "could not find regulators sub-node\n");
541 return -EINVAL; 541 return -EINVAL;
@@ -591,6 +591,8 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
591 rmode++; 591 rmode++;
592 } 592 }
593 593
594 of_node_put(regulators_np);
595
594 if (of_get_property(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs", NULL)) { 596 if (of_get_property(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs", NULL)) {
595 pdata->buck2_gpiodvs = true; 597 pdata->buck2_gpiodvs = true;
596 598
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 7afd373b9595..c4cde9c08f1f 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -580,10 +580,12 @@ static int s3c_rtc_suspend(struct device *dev)
580 580
581 clk_enable(rtc_clk); 581 clk_enable(rtc_clk);
582 /* save TICNT for anyone using periodic interrupts */ 582 /* save TICNT for anyone using periodic interrupts */
583 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
584 if (s3c_rtc_cpu_type == TYPE_S3C64XX) { 583 if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
585 ticnt_en_save = readw(s3c_rtc_base + S3C2410_RTCCON); 584 ticnt_en_save = readw(s3c_rtc_base + S3C2410_RTCCON);
586 ticnt_en_save &= S3C64XX_RTCCON_TICEN; 585 ticnt_en_save &= S3C64XX_RTCCON_TICEN;
586 ticnt_save = readl(s3c_rtc_base + S3C2410_TICNT);
587 } else {
588 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
587 } 589 }
588 s3c_rtc_enable(pdev, 0); 590 s3c_rtc_enable(pdev, 0);
589 591
@@ -605,10 +607,15 @@ static int s3c_rtc_resume(struct device *dev)
605 607
606 clk_enable(rtc_clk); 608 clk_enable(rtc_clk);
607 s3c_rtc_enable(pdev, 1); 609 s3c_rtc_enable(pdev, 1);
608 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT); 610 if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
609 if (s3c_rtc_cpu_type == TYPE_S3C64XX && ticnt_en_save) { 611 writel(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
610 tmp = readw(s3c_rtc_base + S3C2410_RTCCON); 612 if (ticnt_en_save) {
611 writew(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON); 613 tmp = readw(s3c_rtc_base + S3C2410_RTCCON);
614 writew(tmp | ticnt_en_save,
615 s3c_rtc_base + S3C2410_RTCCON);
616 }
617 } else {
618 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
612 } 619 }
613 620
614 if (device_may_wakeup(dev) && wake_en) { 621 if (device_may_wakeup(dev) && wake_en) {
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index eb5d22795c47..5af7f0bd6125 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -922,7 +922,7 @@ static int __init con3215_init(void)
922 raw3215_freelist = req; 922 raw3215_freelist = req;
923 } 923 }
924 924
925 cdev = ccw_device_probe_console(); 925 cdev = ccw_device_create_console(&raw3215_ccw_driver);
926 if (IS_ERR(cdev)) 926 if (IS_ERR(cdev))
927 return -ENODEV; 927 return -ENODEV;
928 928
@@ -932,6 +932,12 @@ static int __init con3215_init(void)
932 cdev->handler = raw3215_irq; 932 cdev->handler = raw3215_irq;
933 933
934 raw->flags |= RAW3215_FIXED; 934 raw->flags |= RAW3215_FIXED;
935 if (ccw_device_enable_console(cdev)) {
936 ccw_device_destroy_console(cdev);
937 raw3215_free_info(raw);
938 raw3215[0] = NULL;
939 return -ENODEV;
940 }
935 941
936 /* Request the console irq */ 942 /* Request the console irq */
937 if (raw3215_startup(raw) != 0) { 943 if (raw3215_startup(raw) != 0) {
diff --git a/drivers/s390/char/con3270.c b/drivers/s390/char/con3270.c
index 699fd3e363df..75ffe9980c3e 100644
--- a/drivers/s390/char/con3270.c
+++ b/drivers/s390/char/con3270.c
@@ -7,6 +7,7 @@
7 * Copyright IBM Corp. 2003, 2009 7 * Copyright IBM Corp. 2003, 2009
8 */ 8 */
9 9
10#include <linux/module.h>
10#include <linux/console.h> 11#include <linux/console.h>
11#include <linux/init.h> 12#include <linux/init.h>
12#include <linux/interrupt.h> 13#include <linux/interrupt.h>
@@ -30,6 +31,9 @@
30 31
31static struct raw3270_fn con3270_fn; 32static struct raw3270_fn con3270_fn;
32 33
34static bool auto_update = 1;
35module_param(auto_update, bool, 0);
36
33/* 37/*
34 * Main 3270 console view data structure. 38 * Main 3270 console view data structure.
35 */ 39 */
@@ -204,6 +208,8 @@ con3270_update(struct con3270 *cp)
204 struct string *s, *n; 208 struct string *s, *n;
205 int rc; 209 int rc;
206 210
211 if (!auto_update && !raw3270_view_active(&cp->view))
212 return;
207 if (cp->view.dev) 213 if (cp->view.dev)
208 raw3270_activate_view(&cp->view); 214 raw3270_activate_view(&cp->view);
209 215
@@ -529,6 +535,7 @@ con3270_flush(void)
529 if (!cp->view.dev) 535 if (!cp->view.dev)
530 return; 536 return;
531 raw3270_pm_unfreeze(&cp->view); 537 raw3270_pm_unfreeze(&cp->view);
538 raw3270_activate_view(&cp->view);
532 spin_lock_irqsave(&cp->view.lock, flags); 539 spin_lock_irqsave(&cp->view.lock, flags);
533 con3270_wait_write(cp); 540 con3270_wait_write(cp);
534 cp->nr_up = 0; 541 cp->nr_up = 0;
@@ -576,7 +583,6 @@ static struct console con3270 = {
576static int __init 583static int __init
577con3270_init(void) 584con3270_init(void)
578{ 585{
579 struct ccw_device *cdev;
580 struct raw3270 *rp; 586 struct raw3270 *rp;
581 void *cbuf; 587 void *cbuf;
582 int i; 588 int i;
@@ -591,10 +597,7 @@ con3270_init(void)
591 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL); 597 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
592 } 598 }
593 599
594 cdev = ccw_device_probe_console(); 600 rp = raw3270_setup_console();
595 if (IS_ERR(cdev))
596 return -ENODEV;
597 rp = raw3270_setup_console(cdev);
598 if (IS_ERR(rp)) 601 if (IS_ERR(rp))
599 return PTR_ERR(rp); 602 return PTR_ERR(rp);
600 603
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index 2cdec21e8924..9f849df4381e 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -276,6 +276,15 @@ __raw3270_start(struct raw3270 *rp, struct raw3270_view *view,
276} 276}
277 277
278int 278int
279raw3270_view_active(struct raw3270_view *view)
280{
281 struct raw3270 *rp = view->dev;
282
283 return rp && rp->view == view &&
284 !test_bit(RAW3270_FLAGS_FROZEN, &rp->flags);
285}
286
287int
279raw3270_start(struct raw3270_view *view, struct raw3270_request *rq) 288raw3270_start(struct raw3270_view *view, struct raw3270_request *rq)
280{ 289{
281 unsigned long flags; 290 unsigned long flags;
@@ -776,22 +785,37 @@ raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
776} 785}
777 786
778#ifdef CONFIG_TN3270_CONSOLE 787#ifdef CONFIG_TN3270_CONSOLE
788/* Tentative definition - see below for actual definition. */
789static struct ccw_driver raw3270_ccw_driver;
790
779/* 791/*
780 * Setup 3270 device configured as console. 792 * Setup 3270 device configured as console.
781 */ 793 */
782struct raw3270 __init *raw3270_setup_console(struct ccw_device *cdev) 794struct raw3270 __init *raw3270_setup_console(void)
783{ 795{
796 struct ccw_device *cdev;
784 unsigned long flags; 797 unsigned long flags;
785 struct raw3270 *rp; 798 struct raw3270 *rp;
786 char *ascebc; 799 char *ascebc;
787 int rc; 800 int rc;
788 801
802 cdev = ccw_device_create_console(&raw3270_ccw_driver);
803 if (IS_ERR(cdev))
804 return ERR_CAST(cdev);
805
789 rp = kzalloc(sizeof(struct raw3270), GFP_KERNEL | GFP_DMA); 806 rp = kzalloc(sizeof(struct raw3270), GFP_KERNEL | GFP_DMA);
790 ascebc = kzalloc(256, GFP_KERNEL); 807 ascebc = kzalloc(256, GFP_KERNEL);
791 rc = raw3270_setup_device(cdev, rp, ascebc); 808 rc = raw3270_setup_device(cdev, rp, ascebc);
792 if (rc) 809 if (rc)
793 return ERR_PTR(rc); 810 return ERR_PTR(rc);
794 set_bit(RAW3270_FLAGS_CONSOLE, &rp->flags); 811 set_bit(RAW3270_FLAGS_CONSOLE, &rp->flags);
812
813 rc = ccw_device_enable_console(cdev);
814 if (rc) {
815 ccw_device_destroy_console(cdev);
816 return ERR_PTR(rc);
817 }
818
795 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags); 819 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
796 do { 820 do {
797 __raw3270_reset_device(rp); 821 __raw3270_reset_device(rp);
diff --git a/drivers/s390/char/raw3270.h b/drivers/s390/char/raw3270.h
index 7b73ff8c1bd7..e1e41c2861fb 100644
--- a/drivers/s390/char/raw3270.h
+++ b/drivers/s390/char/raw3270.h
@@ -173,6 +173,7 @@ int raw3270_start_locked(struct raw3270_view *, struct raw3270_request *);
173int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *); 173int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *);
174int raw3270_reset(struct raw3270_view *); 174int raw3270_reset(struct raw3270_view *);
175struct raw3270_view *raw3270_view(struct raw3270_view *); 175struct raw3270_view *raw3270_view(struct raw3270_view *);
176int raw3270_view_active(struct raw3270_view *);
176 177
177/* Reference count inliner for view structures. */ 178/* Reference count inliner for view structures. */
178static inline void 179static inline void
@@ -190,7 +191,7 @@ raw3270_put_view(struct raw3270_view *view)
190 wake_up(&raw3270_wait_queue); 191 wake_up(&raw3270_wait_queue);
191} 192}
192 193
193struct raw3270 *raw3270_setup_console(struct ccw_device *cdev); 194struct raw3270 *raw3270_setup_console(void);
194void raw3270_wait_cons_dev(struct raw3270 *); 195void raw3270_wait_cons_dev(struct raw3270 *);
195 196
196/* Notifier for device addition/removal */ 197/* Notifier for device addition/removal */
diff --git a/drivers/s390/char/sclp_early.c b/drivers/s390/char/sclp_early.c
index 82f2c389b4d1..14196ea0fdf3 100644
--- a/drivers/s390/char/sclp_early.c
+++ b/drivers/s390/char/sclp_early.c
@@ -20,7 +20,9 @@ struct read_info_sccb {
20 struct sccb_header header; /* 0-7 */ 20 struct sccb_header header; /* 0-7 */
21 u16 rnmax; /* 8-9 */ 21 u16 rnmax; /* 8-9 */
22 u8 rnsize; /* 10 */ 22 u8 rnsize; /* 10 */
23 u8 _reserved0[24 - 11]; /* 11-15 */ 23 u8 _reserved0[16 - 11]; /* 11-15 */
24 u16 ncpurl; /* 16-17 */
25 u8 _reserved7[24 - 18]; /* 18-23 */
24 u8 loadparm[8]; /* 24-31 */ 26 u8 loadparm[8]; /* 24-31 */
25 u8 _reserved1[48 - 32]; /* 32-47 */ 27 u8 _reserved1[48 - 32]; /* 32-47 */
26 u64 facilities; /* 48-55 */ 28 u64 facilities; /* 48-55 */
@@ -32,13 +34,16 @@ struct read_info_sccb {
32 u8 _reserved4[100 - 92]; /* 92-99 */ 34 u8 _reserved4[100 - 92]; /* 92-99 */
33 u32 rnsize2; /* 100-103 */ 35 u32 rnsize2; /* 100-103 */
34 u64 rnmax2; /* 104-111 */ 36 u64 rnmax2; /* 104-111 */
35 u8 _reserved5[4096 - 112]; /* 112-4095 */ 37 u8 _reserved5[120 - 112]; /* 112-119 */
38 u16 hcpua; /* 120-121 */
39 u8 _reserved6[4096 - 122]; /* 122-4095 */
36} __packed __aligned(PAGE_SIZE); 40} __packed __aligned(PAGE_SIZE);
37 41
38static char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE) __initdata; 42static char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE) __initdata;
39static unsigned int sclp_con_has_vt220 __initdata; 43static unsigned int sclp_con_has_vt220 __initdata;
40static unsigned int sclp_con_has_linemode __initdata; 44static unsigned int sclp_con_has_linemode __initdata;
41static unsigned long sclp_hsa_size; 45static unsigned long sclp_hsa_size;
46static unsigned int sclp_max_cpu;
42static struct sclp_ipl_info sclp_ipl_info; 47static struct sclp_ipl_info sclp_ipl_info;
43 48
44u64 sclp_facilities; 49u64 sclp_facilities;
@@ -102,6 +107,15 @@ static void __init sclp_facilities_detect(struct read_info_sccb *sccb)
102 sclp_rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2; 107 sclp_rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
103 sclp_rzm <<= 20; 108 sclp_rzm <<= 20;
104 109
110 if (!sccb->hcpua) {
111 if (MACHINE_IS_VM)
112 sclp_max_cpu = 64;
113 else
114 sclp_max_cpu = sccb->ncpurl;
115 } else {
116 sclp_max_cpu = sccb->hcpua + 1;
117 }
118
105 /* Save IPL information */ 119 /* Save IPL information */
106 sclp_ipl_info.is_valid = 1; 120 sclp_ipl_info.is_valid = 1;
107 if (sccb->flags & 0x2) 121 if (sccb->flags & 0x2)
@@ -129,6 +143,11 @@ unsigned long long sclp_get_rzm(void)
129 return sclp_rzm; 143 return sclp_rzm;
130} 144}
131 145
146unsigned int sclp_get_max_cpu(void)
147{
148 return sclp_max_cpu;
149}
150
132/* 151/*
133 * This function will be called after sclp_facilities_detect(), which gets 152 * This function will be called after sclp_facilities_detect(), which gets
134 * called from early.c code. The sclp_facilities_detect() function retrieves 153 * called from early.c code. The sclp_facilities_detect() function retrieves
@@ -184,9 +203,9 @@ static long __init sclp_hsa_size_init(struct sdias_sccb *sccb)
184 sccb_init_eq_size(sccb); 203 sccb_init_eq_size(sccb);
185 if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb)) 204 if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
186 return -EIO; 205 return -EIO;
187 if (sccb->evbuf.blk_cnt != 0) 206 if (sccb->evbuf.blk_cnt == 0)
188 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE; 207 return 0;
189 return 0; 208 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
190} 209}
191 210
192static long __init sclp_hsa_copy_wait(struct sccb_header *sccb) 211static long __init sclp_hsa_copy_wait(struct sccb_header *sccb)
@@ -195,6 +214,8 @@ static long __init sclp_hsa_copy_wait(struct sccb_header *sccb)
195 sccb->length = PAGE_SIZE; 214 sccb->length = PAGE_SIZE;
196 if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb)) 215 if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
197 return -EIO; 216 return -EIO;
217 if (((struct sdias_sccb *) sccb)->evbuf.blk_cnt == 0)
218 return 0;
198 return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE; 219 return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
199} 220}
200 221
diff --git a/drivers/s390/cio/airq.c b/drivers/s390/cio/airq.c
index f055df0b167f..445564c790f6 100644
--- a/drivers/s390/cio/airq.c
+++ b/drivers/s390/cio/airq.c
@@ -186,55 +186,71 @@ void airq_iv_release(struct airq_iv *iv)
186EXPORT_SYMBOL(airq_iv_release); 186EXPORT_SYMBOL(airq_iv_release);
187 187
188/** 188/**
189 * airq_iv_alloc_bit - allocate an irq bit from an interrupt vector 189 * airq_iv_alloc - allocate irq bits from an interrupt vector
190 * @iv: pointer to an interrupt vector structure 190 * @iv: pointer to an interrupt vector structure
191 * @num: number of consecutive irq bits to allocate
191 * 192 *
192 * Returns the bit number of the allocated irq, or -1UL if no bit 193 * Returns the bit number of the first irq in the allocated block of irqs,
193 * is available or the AIRQ_IV_ALLOC flag has not been specified 194 * or -1UL if no bit is available or the AIRQ_IV_ALLOC flag has not been
195 * specified
194 */ 196 */
195unsigned long airq_iv_alloc_bit(struct airq_iv *iv) 197unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num)
196{ 198{
197 unsigned long bit; 199 unsigned long bit, i;
198 200
199 if (!iv->avail) 201 if (!iv->avail || num == 0)
200 return -1UL; 202 return -1UL;
201 spin_lock(&iv->lock); 203 spin_lock(&iv->lock);
202 bit = find_first_bit_inv(iv->avail, iv->bits); 204 bit = find_first_bit_inv(iv->avail, iv->bits);
203 if (bit < iv->bits) { 205 while (bit + num <= iv->bits) {
204 clear_bit_inv(bit, iv->avail); 206 for (i = 1; i < num; i++)
205 if (bit >= iv->end) 207 if (!test_bit_inv(bit + i, iv->avail))
206 iv->end = bit + 1; 208 break;
207 } else 209 if (i >= num) {
210 /* Found a suitable block of irqs */
211 for (i = 0; i < num; i++)
212 clear_bit_inv(bit + i, iv->avail);
213 if (bit + num >= iv->end)
214 iv->end = bit + num + 1;
215 break;
216 }
217 bit = find_next_bit_inv(iv->avail, iv->bits, bit + i + 1);
218 }
219 if (bit + num > iv->bits)
208 bit = -1UL; 220 bit = -1UL;
209 spin_unlock(&iv->lock); 221 spin_unlock(&iv->lock);
210 return bit; 222 return bit;
211 223
212} 224}
213EXPORT_SYMBOL(airq_iv_alloc_bit); 225EXPORT_SYMBOL(airq_iv_alloc);
214 226
215/** 227/**
216 * airq_iv_free_bit - free an irq bit of an interrupt vector 228 * airq_iv_free - free irq bits of an interrupt vector
217 * @iv: pointer to interrupt vector structure 229 * @iv: pointer to interrupt vector structure
218 * @bit: number of the irq bit to free 230 * @bit: number of the first irq bit to free
231 * @num: number of consecutive irq bits to free
219 */ 232 */
220void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit) 233void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num)
221{ 234{
222 if (!iv->avail) 235 unsigned long i;
236
237 if (!iv->avail || num == 0)
223 return; 238 return;
224 spin_lock(&iv->lock); 239 spin_lock(&iv->lock);
225 /* Clear (possibly left over) interrupt bit */ 240 for (i = 0; i < num; i++) {
226 clear_bit_inv(bit, iv->vector); 241 /* Clear (possibly left over) interrupt bit */
227 /* Make the bit position available again */ 242 clear_bit_inv(bit + i, iv->vector);
228 set_bit_inv(bit, iv->avail); 243 /* Make the bit positions available again */
229 if (bit == iv->end - 1) { 244 set_bit_inv(bit + i, iv->avail);
245 }
246 if (bit + num >= iv->end) {
230 /* Find new end of bit-field */ 247 /* Find new end of bit-field */
231 while (--iv->end > 0) 248 while (iv->end > 0 && !test_bit_inv(iv->end - 1, iv->avail))
232 if (!test_bit_inv(iv->end - 1, iv->avail)) 249 iv->end--;
233 break;
234 } 250 }
235 spin_unlock(&iv->lock); 251 spin_unlock(&iv->lock);
236} 252}
237EXPORT_SYMBOL(airq_iv_free_bit); 253EXPORT_SYMBOL(airq_iv_free);
238 254
239/** 255/**
240 * airq_iv_scan - scan interrupt vector for non-zero bits 256 * airq_iv_scan - scan interrupt vector for non-zero bits
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index f6b9188c5af5..9f0ea6cb6922 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -610,6 +610,7 @@ void chsc_chp_online(struct chp_id chpid)
610 css_wait_for_slow_path(); 610 css_wait_for_slow_path();
611 for_each_subchannel_staged(__s390_process_res_acc, NULL, 611 for_each_subchannel_staged(__s390_process_res_acc, NULL,
612 &link); 612 &link);
613 css_schedule_reprobe();
613 } 614 }
614} 615}
615 616
diff --git a/drivers/s390/cio/chsc_sch.c b/drivers/s390/cio/chsc_sch.c
index 7b29d0be0ca3..1d3661af7bd8 100644
--- a/drivers/s390/cio/chsc_sch.c
+++ b/drivers/s390/cio/chsc_sch.c
@@ -173,8 +173,7 @@ static struct css_driver chsc_subchannel_driver = {
173 173
174static int __init chsc_init_dbfs(void) 174static int __init chsc_init_dbfs(void)
175{ 175{
176 chsc_debug_msg_id = debug_register("chsc_msg", 16, 1, 176 chsc_debug_msg_id = debug_register("chsc_msg", 8, 1, 4 * sizeof(long));
177 16 * sizeof(long));
178 if (!chsc_debug_msg_id) 177 if (!chsc_debug_msg_id)
179 goto out; 178 goto out;
180 debug_register_view(chsc_debug_msg_id, &debug_sprintf_view); 179 debug_register_view(chsc_debug_msg_id, &debug_sprintf_view);
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index 88e35d85d205..97c48b38d67d 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -54,7 +54,7 @@ debug_info_t *cio_debug_crw_id;
54 */ 54 */
55static int __init cio_debug_init(void) 55static int __init cio_debug_init(void)
56{ 56{
57 cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long)); 57 cio_debug_msg_id = debug_register("cio_msg", 16, 1, 11 * sizeof(long));
58 if (!cio_debug_msg_id) 58 if (!cio_debug_msg_id)
59 goto out_unregister; 59 goto out_unregister;
60 debug_register_view(cio_debug_msg_id, &debug_sprintf_view); 60 debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
@@ -64,7 +64,7 @@ static int __init cio_debug_init(void)
64 goto out_unregister; 64 goto out_unregister;
65 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view); 65 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
66 debug_set_level(cio_debug_trace_id, 2); 66 debug_set_level(cio_debug_trace_id, 2);
67 cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long)); 67 cio_debug_crw_id = debug_register("cio_crw", 8, 1, 8 * sizeof(long));
68 if (!cio_debug_crw_id) 68 if (!cio_debug_crw_id)
69 goto out_unregister; 69 goto out_unregister;
70 debug_register_view(cio_debug_crw_id, &debug_sprintf_view); 70 debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
@@ -342,8 +342,9 @@ static int cio_check_config(struct subchannel *sch, struct schib *schib)
342 */ 342 */
343int cio_commit_config(struct subchannel *sch) 343int cio_commit_config(struct subchannel *sch)
344{ 344{
345 struct schib schib;
346 int ccode, retry, ret = 0; 345 int ccode, retry, ret = 0;
346 struct schib schib;
347 struct irb irb;
347 348
348 if (stsch_err(sch->schid, &schib) || !css_sch_is_valid(&schib)) 349 if (stsch_err(sch->schid, &schib) || !css_sch_is_valid(&schib))
349 return -ENODEV; 350 return -ENODEV;
@@ -367,7 +368,10 @@ int cio_commit_config(struct subchannel *sch)
367 ret = -EAGAIN; 368 ret = -EAGAIN;
368 break; 369 break;
369 case 1: /* status pending */ 370 case 1: /* status pending */
370 return -EBUSY; 371 ret = -EBUSY;
372 if (tsch(sch->schid, &irb))
373 return ret;
374 break;
371 case 2: /* busy */ 375 case 2: /* busy */
372 udelay(100); /* allow for recovery */ 376 udelay(100); /* allow for recovery */
373 ret = -EBUSY; 377 ret = -EBUSY;
@@ -403,7 +407,6 @@ EXPORT_SYMBOL_GPL(cio_update_schib);
403 */ 407 */
404int cio_enable_subchannel(struct subchannel *sch, u32 intparm) 408int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
405{ 409{
406 int retry;
407 int ret; 410 int ret;
408 411
409 CIO_TRACE_EVENT(2, "ensch"); 412 CIO_TRACE_EVENT(2, "ensch");
@@ -418,20 +421,14 @@ int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
418 sch->config.isc = sch->isc; 421 sch->config.isc = sch->isc;
419 sch->config.intparm = intparm; 422 sch->config.intparm = intparm;
420 423
421 for (retry = 0; retry < 3; retry++) { 424 ret = cio_commit_config(sch);
425 if (ret == -EIO) {
426 /*
427 * Got a program check in msch. Try without
428 * the concurrent sense bit the next time.
429 */
430 sch->config.csense = 0;
422 ret = cio_commit_config(sch); 431 ret = cio_commit_config(sch);
423 if (ret == -EIO) {
424 /*
425 * Got a program check in msch. Try without
426 * the concurrent sense bit the next time.
427 */
428 sch->config.csense = 0;
429 } else if (ret == -EBUSY) {
430 struct irb irb;
431 if (tsch(sch->schid, &irb) != 0)
432 break;
433 } else
434 break;
435 } 432 }
436 CIO_HEX_EVENT(2, &ret, sizeof(ret)); 433 CIO_HEX_EVENT(2, &ret, sizeof(ret));
437 return ret; 434 return ret;
@@ -444,7 +441,6 @@ EXPORT_SYMBOL_GPL(cio_enable_subchannel);
444 */ 441 */
445int cio_disable_subchannel(struct subchannel *sch) 442int cio_disable_subchannel(struct subchannel *sch)
446{ 443{
447 int retry;
448 int ret; 444 int ret;
449 445
450 CIO_TRACE_EVENT(2, "dissch"); 446 CIO_TRACE_EVENT(2, "dissch");
@@ -456,16 +452,8 @@ int cio_disable_subchannel(struct subchannel *sch)
456 return -ENODEV; 452 return -ENODEV;
457 453
458 sch->config.ena = 0; 454 sch->config.ena = 0;
455 ret = cio_commit_config(sch);
459 456
460 for (retry = 0; retry < 3; retry++) {
461 ret = cio_commit_config(sch);
462 if (ret == -EBUSY) {
463 struct irb irb;
464 if (tsch(sch->schid, &irb) != 0)
465 break;
466 } else
467 break;
468 }
469 CIO_HEX_EVENT(2, &ret, sizeof(ret)); 457 CIO_HEX_EVENT(2, &ret, sizeof(ret));
470 return ret; 458 return ret;
471} 459}
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index e9d783563cbb..d8d9b5b5cc56 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -1571,12 +1571,27 @@ out:
1571 return rc; 1571 return rc;
1572} 1572}
1573 1573
1574static void ccw_device_set_int_class(struct ccw_device *cdev)
1575{
1576 struct ccw_driver *cdrv = cdev->drv;
1577
1578 /* Note: we interpret class 0 in this context as an uninitialized
1579 * field since it translates to a non-I/O interrupt class. */
1580 if (cdrv->int_class != 0)
1581 cdev->private->int_class = cdrv->int_class;
1582 else
1583 cdev->private->int_class = IRQIO_CIO;
1584}
1585
1574#ifdef CONFIG_CCW_CONSOLE 1586#ifdef CONFIG_CCW_CONSOLE
1575static int ccw_device_console_enable(struct ccw_device *cdev, 1587int __init ccw_device_enable_console(struct ccw_device *cdev)
1576 struct subchannel *sch)
1577{ 1588{
1589 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1578 int rc; 1590 int rc;
1579 1591
1592 if (!cdev->drv || !cdev->handler)
1593 return -EINVAL;
1594
1580 io_subchannel_init_fields(sch); 1595 io_subchannel_init_fields(sch);
1581 rc = cio_commit_config(sch); 1596 rc = cio_commit_config(sch);
1582 if (rc) 1597 if (rc)
@@ -1609,12 +1624,11 @@ out_unlock:
1609 return rc; 1624 return rc;
1610} 1625}
1611 1626
1612struct ccw_device *ccw_device_probe_console(void) 1627struct ccw_device * __init ccw_device_create_console(struct ccw_driver *drv)
1613{ 1628{
1614 struct io_subchannel_private *io_priv; 1629 struct io_subchannel_private *io_priv;
1615 struct ccw_device *cdev; 1630 struct ccw_device *cdev;
1616 struct subchannel *sch; 1631 struct subchannel *sch;
1617 int ret;
1618 1632
1619 sch = cio_probe_console(); 1633 sch = cio_probe_console();
1620 if (IS_ERR(sch)) 1634 if (IS_ERR(sch))
@@ -1631,18 +1645,23 @@ struct ccw_device *ccw_device_probe_console(void)
1631 kfree(io_priv); 1645 kfree(io_priv);
1632 return cdev; 1646 return cdev;
1633 } 1647 }
1648 cdev->drv = drv;
1634 set_io_private(sch, io_priv); 1649 set_io_private(sch, io_priv);
1635 ret = ccw_device_console_enable(cdev, sch); 1650 ccw_device_set_int_class(cdev);
1636 if (ret) {
1637 set_io_private(sch, NULL);
1638 put_device(&sch->dev);
1639 put_device(&cdev->dev);
1640 kfree(io_priv);
1641 return ERR_PTR(ret);
1642 }
1643 return cdev; 1651 return cdev;
1644} 1652}
1645 1653
1654void __init ccw_device_destroy_console(struct ccw_device *cdev)
1655{
1656 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1657 struct io_subchannel_private *io_priv = to_io_private(sch);
1658
1659 set_io_private(sch, NULL);
1660 put_device(&sch->dev);
1661 put_device(&cdev->dev);
1662 kfree(io_priv);
1663}
1664
1646/** 1665/**
1647 * ccw_device_wait_idle() - busy wait for device to become idle 1666 * ccw_device_wait_idle() - busy wait for device to become idle
1648 * @cdev: ccw device 1667 * @cdev: ccw device
@@ -1726,15 +1745,8 @@ ccw_device_probe (struct device *dev)
1726 int ret; 1745 int ret;
1727 1746
1728 cdev->drv = cdrv; /* to let the driver call _set_online */ 1747 cdev->drv = cdrv; /* to let the driver call _set_online */
1729 /* Note: we interpret class 0 in this context as an uninitialized 1748 ccw_device_set_int_class(cdev);
1730 * field since it translates to a non-I/O interrupt class. */
1731 if (cdrv->int_class != 0)
1732 cdev->private->int_class = cdrv->int_class;
1733 else
1734 cdev->private->int_class = IRQIO_CIO;
1735
1736 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV; 1749 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1737
1738 if (ret) { 1750 if (ret) {
1739 cdev->drv = NULL; 1751 cdev->drv = NULL;
1740 cdev->private->int_class = IRQIO_CIO; 1752 cdev->private->int_class = IRQIO_CIO;
diff --git a/drivers/s390/cio/qdio.h b/drivers/s390/cio/qdio.h
index 8acaae18bd11..a563e4c00590 100644
--- a/drivers/s390/cio/qdio.h
+++ b/drivers/s390/cio/qdio.h
@@ -359,14 +359,12 @@ static inline int multicast_outbound(struct qdio_q *q)
359#define need_siga_sync_out_after_pci(q) \ 359#define need_siga_sync_out_after_pci(q) \
360 (unlikely(q->irq_ptr->siga_flag.sync_out_after_pci)) 360 (unlikely(q->irq_ptr->siga_flag.sync_out_after_pci))
361 361
362#define for_each_input_queue(irq_ptr, q, i) \ 362#define for_each_input_queue(irq_ptr, q, i) \
363 for (i = 0, q = irq_ptr->input_qs[0]; \ 363 for (i = 0; i < irq_ptr->nr_input_qs && \
364 i < irq_ptr->nr_input_qs; \ 364 ({ q = irq_ptr->input_qs[i]; 1; }); i++)
365 q = irq_ptr->input_qs[++i]) 365#define for_each_output_queue(irq_ptr, q, i) \
366#define for_each_output_queue(irq_ptr, q, i) \ 366 for (i = 0; i < irq_ptr->nr_output_qs && \
367 for (i = 0, q = irq_ptr->output_qs[0]; \ 367 ({ q = irq_ptr->output_qs[i]; 1; }); i++)
368 i < irq_ptr->nr_output_qs; \
369 q = irq_ptr->output_qs[++i])
370 368
371#define prev_buf(bufnr) \ 369#define prev_buf(bufnr) \
372 ((bufnr + QDIO_MAX_BUFFERS_MASK) & QDIO_MAX_BUFFERS_MASK) 370 ((bufnr + QDIO_MAX_BUFFERS_MASK) & QDIO_MAX_BUFFERS_MASK)
diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c
index c883a085c059..77466c4faabb 100644
--- a/drivers/s390/cio/qdio_main.c
+++ b/drivers/s390/cio/qdio_main.c
@@ -996,7 +996,7 @@ static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
996 } 996 }
997 } 997 }
998 998
999 if (!pci_out_supported(q)) 999 if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED))
1000 return; 1000 return;
1001 1001
1002 for_each_output_queue(irq_ptr, q, i) { 1002 for_each_output_queue(irq_ptr, q, i) {
diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
index dc542e0a3055..0bc91e46395a 100644
--- a/drivers/s390/crypto/zcrypt_msgtype6.c
+++ b/drivers/s390/crypto/zcrypt_msgtype6.c
@@ -311,7 +311,7 @@ static int XCRB_msg_to_type6CPRB_msgX(struct zcrypt_device *zdev,
311 } __packed * msg = ap_msg->message; 311 } __packed * msg = ap_msg->message;
312 312
313 int rcblen = CEIL4(xcRB->request_control_blk_length); 313 int rcblen = CEIL4(xcRB->request_control_blk_length);
314 int replylen; 314 int replylen, req_sumlen, resp_sumlen;
315 char *req_data = ap_msg->message + sizeof(struct type6_hdr) + rcblen; 315 char *req_data = ap_msg->message + sizeof(struct type6_hdr) + rcblen;
316 char *function_code; 316 char *function_code;
317 317
@@ -321,12 +321,34 @@ static int XCRB_msg_to_type6CPRB_msgX(struct zcrypt_device *zdev,
321 xcRB->request_data_length; 321 xcRB->request_data_length;
322 if (ap_msg->length > MSGTYPE06_MAX_MSG_SIZE) 322 if (ap_msg->length > MSGTYPE06_MAX_MSG_SIZE)
323 return -EINVAL; 323 return -EINVAL;
324
325 /* Overflow check
326 sum must be greater (or equal) than the largest operand */
327 req_sumlen = CEIL4(xcRB->request_control_blk_length) +
328 xcRB->request_data_length;
329 if ((CEIL4(xcRB->request_control_blk_length) <=
330 xcRB->request_data_length) ?
331 (req_sumlen < xcRB->request_data_length) :
332 (req_sumlen < CEIL4(xcRB->request_control_blk_length))) {
333 return -EINVAL;
334 }
335
324 replylen = sizeof(struct type86_fmt2_msg) + 336 replylen = sizeof(struct type86_fmt2_msg) +
325 CEIL4(xcRB->reply_control_blk_length) + 337 CEIL4(xcRB->reply_control_blk_length) +
326 xcRB->reply_data_length; 338 xcRB->reply_data_length;
327 if (replylen > MSGTYPE06_MAX_MSG_SIZE) 339 if (replylen > MSGTYPE06_MAX_MSG_SIZE)
328 return -EINVAL; 340 return -EINVAL;
329 341
342 /* Overflow check
343 sum must be greater (or equal) than the largest operand */
344 resp_sumlen = CEIL4(xcRB->reply_control_blk_length) +
345 xcRB->reply_data_length;
346 if ((CEIL4(xcRB->reply_control_blk_length) <= xcRB->reply_data_length) ?
347 (resp_sumlen < xcRB->reply_data_length) :
348 (resp_sumlen < CEIL4(xcRB->reply_control_blk_length))) {
349 return -EINVAL;
350 }
351
330 /* prepare type6 header */ 352 /* prepare type6 header */
331 msg->hdr = static_type6_hdrX; 353 msg->hdr = static_type6_hdrX;
332 memcpy(msg->hdr.agent_id , &(xcRB->agent_ID), sizeof(xcRB->agent_ID)); 354 memcpy(msg->hdr.agent_id , &(xcRB->agent_ID), sizeof(xcRB->agent_ID));
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index c3a83df07894..a0aff2eb247c 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -33,8 +33,8 @@ struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
33 /* N P A M L V H */ 33 /* N P A M L V H */
34 [QETH_DBF_SETUP] = {"qeth_setup", 34 [QETH_DBF_SETUP] = {"qeth_setup",
35 8, 1, 8, 5, &debug_hex_ascii_view, NULL}, 35 8, 1, 8, 5, &debug_hex_ascii_view, NULL},
36 [QETH_DBF_MSG] = {"qeth_msg", 36 [QETH_DBF_MSG] = {"qeth_msg", 8, 1, 11 * sizeof(long), 3,
37 8, 1, 128, 3, &debug_sprintf_view, NULL}, 37 &debug_sprintf_view, NULL},
38 [QETH_DBF_CTRL] = {"qeth_control", 38 [QETH_DBF_CTRL] = {"qeth_control",
39 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL}, 39 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL},
40}; 40};
@@ -1660,7 +1660,6 @@ int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
1660 QDIO_FLAG_CLEANUP_USING_CLEAR); 1660 QDIO_FLAG_CLEANUP_USING_CLEAR);
1661 if (rc) 1661 if (rc)
1662 QETH_CARD_TEXT_(card, 3, "1err%d", rc); 1662 QETH_CARD_TEXT_(card, 3, "1err%d", rc);
1663 qdio_free(CARD_DDEV(card));
1664 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED); 1663 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
1665 break; 1664 break;
1666 case QETH_QDIO_CLEANING: 1665 case QETH_QDIO_CLEANING:
@@ -2605,6 +2604,7 @@ static int qeth_mpc_initialize(struct qeth_card *card)
2605 return 0; 2604 return 0;
2606out_qdio: 2605out_qdio:
2607 qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD); 2606 qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
2607 qdio_free(CARD_DDEV(card));
2608 return rc; 2608 return rc;
2609} 2609}
2610 2610
@@ -4906,9 +4906,11 @@ retry:
4906 if (retries < 3) 4906 if (retries < 3)
4907 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n", 4907 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
4908 dev_name(&card->gdev->dev)); 4908 dev_name(&card->gdev->dev));
4909 rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
4909 ccw_device_set_offline(CARD_DDEV(card)); 4910 ccw_device_set_offline(CARD_DDEV(card));
4910 ccw_device_set_offline(CARD_WDEV(card)); 4911 ccw_device_set_offline(CARD_WDEV(card));
4911 ccw_device_set_offline(CARD_RDEV(card)); 4912 ccw_device_set_offline(CARD_RDEV(card));
4913 qdio_free(CARD_DDEV(card));
4912 rc = ccw_device_set_online(CARD_RDEV(card)); 4914 rc = ccw_device_set_online(CARD_RDEV(card));
4913 if (rc) 4915 if (rc)
4914 goto retriable; 4916 goto retriable;
@@ -4918,7 +4920,6 @@ retry:
4918 rc = ccw_device_set_online(CARD_DDEV(card)); 4920 rc = ccw_device_set_online(CARD_DDEV(card));
4919 if (rc) 4921 if (rc)
4920 goto retriable; 4922 goto retriable;
4921 rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
4922retriable: 4923retriable:
4923 if (rc == -ERESTARTSYS) { 4924 if (rc == -ERESTARTSYS) {
4924 QETH_DBF_TEXT(SETUP, 2, "break1"); 4925 QETH_DBF_TEXT(SETUP, 2, "break1");
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 0710550093ce..908d82529ee9 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -1091,6 +1091,7 @@ out_remove:
1091 ccw_device_set_offline(CARD_DDEV(card)); 1091 ccw_device_set_offline(CARD_DDEV(card));
1092 ccw_device_set_offline(CARD_WDEV(card)); 1092 ccw_device_set_offline(CARD_WDEV(card));
1093 ccw_device_set_offline(CARD_RDEV(card)); 1093 ccw_device_set_offline(CARD_RDEV(card));
1094 qdio_free(CARD_DDEV(card));
1094 if (recover_flag == CARD_STATE_RECOVER) 1095 if (recover_flag == CARD_STATE_RECOVER)
1095 card->state = CARD_STATE_RECOVER; 1096 card->state = CARD_STATE_RECOVER;
1096 else 1097 else
@@ -1132,6 +1133,7 @@ static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1132 rc = (rc2) ? rc2 : rc3; 1133 rc = (rc2) ? rc2 : rc3;
1133 if (rc) 1134 if (rc)
1134 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); 1135 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1136 qdio_free(CARD_DDEV(card));
1135 if (recover_flag == CARD_STATE_UP) 1137 if (recover_flag == CARD_STATE_UP)
1136 card->state = CARD_STATE_RECOVER; 1138 card->state = CARD_STATE_RECOVER;
1137 /* let user_space know that device is offline */ 1139 /* let user_space know that device is offline */
@@ -1194,6 +1196,7 @@ static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1194 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 1196 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1195 qeth_qdio_clear_card(card, 0); 1197 qeth_qdio_clear_card(card, 0);
1196 qeth_clear_qdio_buffers(card); 1198 qeth_clear_qdio_buffers(card);
1199 qdio_free(CARD_DDEV(card));
1197} 1200}
1198 1201
1199static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev) 1202static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 0f430424c3b8..3524d34ff694 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -3447,6 +3447,7 @@ out_remove:
3447 ccw_device_set_offline(CARD_DDEV(card)); 3447 ccw_device_set_offline(CARD_DDEV(card));
3448 ccw_device_set_offline(CARD_WDEV(card)); 3448 ccw_device_set_offline(CARD_WDEV(card));
3449 ccw_device_set_offline(CARD_RDEV(card)); 3449 ccw_device_set_offline(CARD_RDEV(card));
3450 qdio_free(CARD_DDEV(card));
3450 if (recover_flag == CARD_STATE_RECOVER) 3451 if (recover_flag == CARD_STATE_RECOVER)
3451 card->state = CARD_STATE_RECOVER; 3452 card->state = CARD_STATE_RECOVER;
3452 else 3453 else
@@ -3493,6 +3494,7 @@ static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3493 rc = (rc2) ? rc2 : rc3; 3494 rc = (rc2) ? rc2 : rc3;
3494 if (rc) 3495 if (rc)
3495 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); 3496 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3497 qdio_free(CARD_DDEV(card));
3496 if (recover_flag == CARD_STATE_UP) 3498 if (recover_flag == CARD_STATE_UP)
3497 card->state = CARD_STATE_RECOVER; 3499 card->state = CARD_STATE_RECOVER;
3498 /* let user_space know that device is offline */ 3500 /* let user_space know that device is offline */
@@ -3545,6 +3547,7 @@ static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3545 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 3547 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3546 qeth_qdio_clear_card(card, 0); 3548 qeth_qdio_clear_card(card, 0);
3547 qeth_clear_qdio_buffers(card); 3549 qeth_clear_qdio_buffers(card);
3550 qdio_free(CARD_DDEV(card));
3548} 3551}
3549 3552
3550static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev) 3553static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
diff --git a/drivers/sbus/char/jsflash.c b/drivers/sbus/char/jsflash.c
index 6b4678a7900a..4ccb5d869389 100644
--- a/drivers/sbus/char/jsflash.c
+++ b/drivers/sbus/char/jsflash.c
@@ -507,7 +507,6 @@ static int jsflash_init(void)
507 } 507 }
508 508
509 /* Let us be really paranoid for modifications to probing code. */ 509 /* Let us be really paranoid for modifications to probing code. */
510 /* extern enum sparc_cpu sparc_cpu_model; */ /* in <asm/system.h> */
511 if (sparc_cpu_model != sun4m) { 510 if (sparc_cpu_model != sun4m) {
512 /* We must be on sun4m because we use MMU Bypass ASI. */ 511 /* We must be on sun4m because we use MMU Bypass ASI. */
513 return -ENXIO; 512 return -ENXIO;
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index a3e6c8a3ff0f..296c936cc03c 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -90,6 +90,7 @@
90#include <linux/init.h> 90#include <linux/init.h>
91#include <linux/nvram.h> 91#include <linux/nvram.h>
92#include <linux/bitops.h> 92#include <linux/bitops.h>
93#include <linux/wait.h>
93 94
94#include <asm/setup.h> 95#include <asm/setup.h>
95#include <asm/atarihw.h> 96#include <asm/atarihw.h>
@@ -549,8 +550,10 @@ static void falcon_get_lock(void)
549 550
550 local_irq_save(flags); 551 local_irq_save(flags);
551 552
552 while (!in_irq() && falcon_got_lock && stdma_others_waiting()) 553 wait_event_cmd(falcon_fairness_wait,
553 sleep_on(&falcon_fairness_wait); 554 in_interrupt() || !falcon_got_lock || !stdma_others_waiting(),
555 local_irq_restore(flags),
556 local_irq_save(flags));
554 557
555 while (!falcon_got_lock) { 558 while (!falcon_got_lock) {
556 if (in_irq()) 559 if (in_irq())
@@ -562,7 +565,10 @@ static void falcon_get_lock(void)
562 falcon_trying_lock = 0; 565 falcon_trying_lock = 0;
563 wake_up(&falcon_try_wait); 566 wake_up(&falcon_try_wait);
564 } else { 567 } else {
565 sleep_on(&falcon_try_wait); 568 wait_event_cmd(falcon_try_wait,
569 falcon_got_lock && !falcon_trying_lock,
570 local_irq_restore(flags),
571 local_irq_save(flags));
566 } 572 }
567 } 573 }
568 574
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 1f375051483a..5642a9b250c2 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -325,7 +325,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
325 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE) 325 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
326 continue; 326 continue;
327 327
328 if (abrt_task->sc->device->lun != abrt_task->sc->device->lun) 328 if (sc->device->lun != abrt_task->sc->device->lun)
329 continue; 329 continue;
330 330
331 /* Invalidate WRB Posted for this Task */ 331 /* Invalidate WRB Posted for this Task */
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index ed880891cb7c..e9279a8c1e1c 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -594,13 +594,13 @@ static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req)
594 mp_req->mp_resp_bd = NULL; 594 mp_req->mp_resp_bd = NULL;
595 } 595 }
596 if (mp_req->req_buf) { 596 if (mp_req->req_buf) {
597 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 597 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
598 mp_req->req_buf, 598 mp_req->req_buf,
599 mp_req->req_buf_dma); 599 mp_req->req_buf_dma);
600 mp_req->req_buf = NULL; 600 mp_req->req_buf = NULL;
601 } 601 }
602 if (mp_req->resp_buf) { 602 if (mp_req->resp_buf) {
603 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 603 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
604 mp_req->resp_buf, 604 mp_req->resp_buf,
605 mp_req->resp_buf_dma); 605 mp_req->resp_buf_dma);
606 mp_req->resp_buf = NULL; 606 mp_req->resp_buf = NULL;
@@ -622,7 +622,7 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
622 622
623 mp_req->req_len = sizeof(struct fcp_cmnd); 623 mp_req->req_len = sizeof(struct fcp_cmnd);
624 io_req->data_xfer_len = mp_req->req_len; 624 io_req->data_xfer_len = mp_req->req_len;
625 mp_req->req_buf = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 625 mp_req->req_buf = dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
626 &mp_req->req_buf_dma, 626 &mp_req->req_buf_dma,
627 GFP_ATOMIC); 627 GFP_ATOMIC);
628 if (!mp_req->req_buf) { 628 if (!mp_req->req_buf) {
@@ -631,7 +631,7 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
631 return FAILED; 631 return FAILED;
632 } 632 }
633 633
634 mp_req->resp_buf = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 634 mp_req->resp_buf = dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
635 &mp_req->resp_buf_dma, 635 &mp_req->resp_buf_dma,
636 GFP_ATOMIC); 636 GFP_ATOMIC);
637 if (!mp_req->resp_buf) { 637 if (!mp_req->resp_buf) {
@@ -639,8 +639,8 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
639 bnx2fc_free_mp_resc(io_req); 639 bnx2fc_free_mp_resc(io_req);
640 return FAILED; 640 return FAILED;
641 } 641 }
642 memset(mp_req->req_buf, 0, PAGE_SIZE); 642 memset(mp_req->req_buf, 0, CNIC_PAGE_SIZE);
643 memset(mp_req->resp_buf, 0, PAGE_SIZE); 643 memset(mp_req->resp_buf, 0, CNIC_PAGE_SIZE);
644 644
645 /* Allocate and map mp_req_bd and mp_resp_bd */ 645 /* Allocate and map mp_req_bd and mp_resp_bd */
646 sz = sizeof(struct fcoe_bd_ctx); 646 sz = sizeof(struct fcoe_bd_ctx);
@@ -665,7 +665,7 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
665 mp_req_bd = mp_req->mp_req_bd; 665 mp_req_bd = mp_req->mp_req_bd;
666 mp_req_bd->buf_addr_lo = (u32)addr & 0xffffffff; 666 mp_req_bd->buf_addr_lo = (u32)addr & 0xffffffff;
667 mp_req_bd->buf_addr_hi = (u32)((u64)addr >> 32); 667 mp_req_bd->buf_addr_hi = (u32)((u64)addr >> 32);
668 mp_req_bd->buf_len = PAGE_SIZE; 668 mp_req_bd->buf_len = CNIC_PAGE_SIZE;
669 mp_req_bd->flags = 0; 669 mp_req_bd->flags = 0;
670 670
671 /* 671 /*
@@ -677,7 +677,7 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
677 addr = mp_req->resp_buf_dma; 677 addr = mp_req->resp_buf_dma;
678 mp_resp_bd->buf_addr_lo = (u32)addr & 0xffffffff; 678 mp_resp_bd->buf_addr_lo = (u32)addr & 0xffffffff;
679 mp_resp_bd->buf_addr_hi = (u32)((u64)addr >> 32); 679 mp_resp_bd->buf_addr_hi = (u32)((u64)addr >> 32);
680 mp_resp_bd->buf_len = PAGE_SIZE; 680 mp_resp_bd->buf_len = CNIC_PAGE_SIZE;
681 mp_resp_bd->flags = 0; 681 mp_resp_bd->flags = 0;
682 682
683 return SUCCESS; 683 return SUCCESS;
diff --git a/drivers/scsi/bnx2fc/bnx2fc_tgt.c b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
index 4d93177dfb53..d9bae5672273 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_tgt.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
@@ -673,7 +673,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
673 673
674 /* Allocate and map SQ */ 674 /* Allocate and map SQ */
675 tgt->sq_mem_size = tgt->max_sqes * BNX2FC_SQ_WQE_SIZE; 675 tgt->sq_mem_size = tgt->max_sqes * BNX2FC_SQ_WQE_SIZE;
676 tgt->sq_mem_size = (tgt->sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 676 tgt->sq_mem_size = (tgt->sq_mem_size + (CNIC_PAGE_SIZE - 1)) &
677 CNIC_PAGE_MASK;
677 678
678 tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size, 679 tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
679 &tgt->sq_dma, GFP_KERNEL); 680 &tgt->sq_dma, GFP_KERNEL);
@@ -686,7 +687,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
686 687
687 /* Allocate and map CQ */ 688 /* Allocate and map CQ */
688 tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE; 689 tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE;
689 tgt->cq_mem_size = (tgt->cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 690 tgt->cq_mem_size = (tgt->cq_mem_size + (CNIC_PAGE_SIZE - 1)) &
691 CNIC_PAGE_MASK;
690 692
691 tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size, 693 tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
692 &tgt->cq_dma, GFP_KERNEL); 694 &tgt->cq_dma, GFP_KERNEL);
@@ -699,7 +701,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
699 701
700 /* Allocate and map RQ and RQ PBL */ 702 /* Allocate and map RQ and RQ PBL */
701 tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE; 703 tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE;
702 tgt->rq_mem_size = (tgt->rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 704 tgt->rq_mem_size = (tgt->rq_mem_size + (CNIC_PAGE_SIZE - 1)) &
705 CNIC_PAGE_MASK;
703 706
704 tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size, 707 tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
705 &tgt->rq_dma, GFP_KERNEL); 708 &tgt->rq_dma, GFP_KERNEL);
@@ -710,8 +713,9 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
710 } 713 }
711 memset(tgt->rq, 0, tgt->rq_mem_size); 714 memset(tgt->rq, 0, tgt->rq_mem_size);
712 715
713 tgt->rq_pbl_size = (tgt->rq_mem_size / PAGE_SIZE) * sizeof(void *); 716 tgt->rq_pbl_size = (tgt->rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
714 tgt->rq_pbl_size = (tgt->rq_pbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 717 tgt->rq_pbl_size = (tgt->rq_pbl_size + (CNIC_PAGE_SIZE - 1)) &
718 CNIC_PAGE_MASK;
715 719
716 tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size, 720 tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
717 &tgt->rq_pbl_dma, GFP_KERNEL); 721 &tgt->rq_pbl_dma, GFP_KERNEL);
@@ -722,7 +726,7 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
722 } 726 }
723 727
724 memset(tgt->rq_pbl, 0, tgt->rq_pbl_size); 728 memset(tgt->rq_pbl, 0, tgt->rq_pbl_size);
725 num_pages = tgt->rq_mem_size / PAGE_SIZE; 729 num_pages = tgt->rq_mem_size / CNIC_PAGE_SIZE;
726 page = tgt->rq_dma; 730 page = tgt->rq_dma;
727 pbl = (u32 *)tgt->rq_pbl; 731 pbl = (u32 *)tgt->rq_pbl;
728 732
@@ -731,13 +735,13 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
731 pbl++; 735 pbl++;
732 *pbl = (u32)((u64)page >> 32); 736 *pbl = (u32)((u64)page >> 32);
733 pbl++; 737 pbl++;
734 page += PAGE_SIZE; 738 page += CNIC_PAGE_SIZE;
735 } 739 }
736 740
737 /* Allocate and map XFERQ */ 741 /* Allocate and map XFERQ */
738 tgt->xferq_mem_size = tgt->max_sqes * BNX2FC_XFERQ_WQE_SIZE; 742 tgt->xferq_mem_size = tgt->max_sqes * BNX2FC_XFERQ_WQE_SIZE;
739 tgt->xferq_mem_size = (tgt->xferq_mem_size + (PAGE_SIZE - 1)) & 743 tgt->xferq_mem_size = (tgt->xferq_mem_size + (CNIC_PAGE_SIZE - 1)) &
740 PAGE_MASK; 744 CNIC_PAGE_MASK;
741 745
742 tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size, 746 tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
743 &tgt->xferq_dma, GFP_KERNEL); 747 &tgt->xferq_dma, GFP_KERNEL);
@@ -750,8 +754,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
750 754
751 /* Allocate and map CONFQ & CONFQ PBL */ 755 /* Allocate and map CONFQ & CONFQ PBL */
752 tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE; 756 tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE;
753 tgt->confq_mem_size = (tgt->confq_mem_size + (PAGE_SIZE - 1)) & 757 tgt->confq_mem_size = (tgt->confq_mem_size + (CNIC_PAGE_SIZE - 1)) &
754 PAGE_MASK; 758 CNIC_PAGE_MASK;
755 759
756 tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size, 760 tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
757 &tgt->confq_dma, GFP_KERNEL); 761 &tgt->confq_dma, GFP_KERNEL);
@@ -763,9 +767,9 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
763 memset(tgt->confq, 0, tgt->confq_mem_size); 767 memset(tgt->confq, 0, tgt->confq_mem_size);
764 768
765 tgt->confq_pbl_size = 769 tgt->confq_pbl_size =
766 (tgt->confq_mem_size / PAGE_SIZE) * sizeof(void *); 770 (tgt->confq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
767 tgt->confq_pbl_size = 771 tgt->confq_pbl_size =
768 (tgt->confq_pbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 772 (tgt->confq_pbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
769 773
770 tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev, 774 tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev,
771 tgt->confq_pbl_size, 775 tgt->confq_pbl_size,
@@ -777,7 +781,7 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
777 } 781 }
778 782
779 memset(tgt->confq_pbl, 0, tgt->confq_pbl_size); 783 memset(tgt->confq_pbl, 0, tgt->confq_pbl_size);
780 num_pages = tgt->confq_mem_size / PAGE_SIZE; 784 num_pages = tgt->confq_mem_size / CNIC_PAGE_SIZE;
781 page = tgt->confq_dma; 785 page = tgt->confq_dma;
782 pbl = (u32 *)tgt->confq_pbl; 786 pbl = (u32 *)tgt->confq_pbl;
783 787
@@ -786,7 +790,7 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
786 pbl++; 790 pbl++;
787 *pbl = (u32)((u64)page >> 32); 791 *pbl = (u32)((u64)page >> 32);
788 pbl++; 792 pbl++;
789 page += PAGE_SIZE; 793 page += CNIC_PAGE_SIZE;
790 } 794 }
791 795
792 /* Allocate and map ConnDB */ 796 /* Allocate and map ConnDB */
@@ -805,8 +809,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
805 809
806 /* Allocate and map LCQ */ 810 /* Allocate and map LCQ */
807 tgt->lcq_mem_size = (tgt->max_sqes + 8) * BNX2FC_SQ_WQE_SIZE; 811 tgt->lcq_mem_size = (tgt->max_sqes + 8) * BNX2FC_SQ_WQE_SIZE;
808 tgt->lcq_mem_size = (tgt->lcq_mem_size + (PAGE_SIZE - 1)) & 812 tgt->lcq_mem_size = (tgt->lcq_mem_size + (CNIC_PAGE_SIZE - 1)) &
809 PAGE_MASK; 813 CNIC_PAGE_MASK;
810 814
811 tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size, 815 tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
812 &tgt->lcq_dma, GFP_KERNEL); 816 &tgt->lcq_dma, GFP_KERNEL);
diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c
index e4cf23df4b4f..b87a1933f880 100644
--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
@@ -61,7 +61,7 @@ static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
61 * yield integral num of page buffers 61 * yield integral num of page buffers
62 */ 62 */
63 /* adjust SQ */ 63 /* adjust SQ */
64 num_elements_per_pg = PAGE_SIZE / BNX2I_SQ_WQE_SIZE; 64 num_elements_per_pg = CNIC_PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
65 if (hba->max_sqes < num_elements_per_pg) 65 if (hba->max_sqes < num_elements_per_pg)
66 hba->max_sqes = num_elements_per_pg; 66 hba->max_sqes = num_elements_per_pg;
67 else if (hba->max_sqes % num_elements_per_pg) 67 else if (hba->max_sqes % num_elements_per_pg)
@@ -69,7 +69,7 @@ static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
69 ~(num_elements_per_pg - 1); 69 ~(num_elements_per_pg - 1);
70 70
71 /* adjust CQ */ 71 /* adjust CQ */
72 num_elements_per_pg = PAGE_SIZE / BNX2I_CQE_SIZE; 72 num_elements_per_pg = CNIC_PAGE_SIZE / BNX2I_CQE_SIZE;
73 if (hba->max_cqes < num_elements_per_pg) 73 if (hba->max_cqes < num_elements_per_pg)
74 hba->max_cqes = num_elements_per_pg; 74 hba->max_cqes = num_elements_per_pg;
75 else if (hba->max_cqes % num_elements_per_pg) 75 else if (hba->max_cqes % num_elements_per_pg)
@@ -77,7 +77,7 @@ static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
77 ~(num_elements_per_pg - 1); 77 ~(num_elements_per_pg - 1);
78 78
79 /* adjust RQ */ 79 /* adjust RQ */
80 num_elements_per_pg = PAGE_SIZE / BNX2I_RQ_WQE_SIZE; 80 num_elements_per_pg = CNIC_PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
81 if (hba->max_rqes < num_elements_per_pg) 81 if (hba->max_rqes < num_elements_per_pg)
82 hba->max_rqes = num_elements_per_pg; 82 hba->max_rqes = num_elements_per_pg;
83 else if (hba->max_rqes % num_elements_per_pg) 83 else if (hba->max_rqes % num_elements_per_pg)
@@ -959,7 +959,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
959 959
960 /* SQ page table */ 960 /* SQ page table */
961 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size); 961 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
962 num_pages = ep->qp.sq_mem_size / PAGE_SIZE; 962 num_pages = ep->qp.sq_mem_size / CNIC_PAGE_SIZE;
963 page = ep->qp.sq_phys; 963 page = ep->qp.sq_phys;
964 964
965 if (cnic_dev_10g) 965 if (cnic_dev_10g)
@@ -973,7 +973,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
973 ptbl++; 973 ptbl++;
974 *ptbl = (u32) ((u64) page >> 32); 974 *ptbl = (u32) ((u64) page >> 32);
975 ptbl++; 975 ptbl++;
976 page += PAGE_SIZE; 976 page += CNIC_PAGE_SIZE;
977 } else { 977 } else {
978 /* PTE is written in big endian format for 978 /* PTE is written in big endian format for
979 * 5706/5708/5709 devices */ 979 * 5706/5708/5709 devices */
@@ -981,13 +981,13 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
981 ptbl++; 981 ptbl++;
982 *ptbl = (u32) page; 982 *ptbl = (u32) page;
983 ptbl++; 983 ptbl++;
984 page += PAGE_SIZE; 984 page += CNIC_PAGE_SIZE;
985 } 985 }
986 } 986 }
987 987
988 /* RQ page table */ 988 /* RQ page table */
989 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size); 989 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
990 num_pages = ep->qp.rq_mem_size / PAGE_SIZE; 990 num_pages = ep->qp.rq_mem_size / CNIC_PAGE_SIZE;
991 page = ep->qp.rq_phys; 991 page = ep->qp.rq_phys;
992 992
993 if (cnic_dev_10g) 993 if (cnic_dev_10g)
@@ -1001,7 +1001,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
1001 ptbl++; 1001 ptbl++;
1002 *ptbl = (u32) ((u64) page >> 32); 1002 *ptbl = (u32) ((u64) page >> 32);
1003 ptbl++; 1003 ptbl++;
1004 page += PAGE_SIZE; 1004 page += CNIC_PAGE_SIZE;
1005 } else { 1005 } else {
1006 /* PTE is written in big endian format for 1006 /* PTE is written in big endian format for
1007 * 5706/5708/5709 devices */ 1007 * 5706/5708/5709 devices */
@@ -1009,13 +1009,13 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
1009 ptbl++; 1009 ptbl++;
1010 *ptbl = (u32) page; 1010 *ptbl = (u32) page;
1011 ptbl++; 1011 ptbl++;
1012 page += PAGE_SIZE; 1012 page += CNIC_PAGE_SIZE;
1013 } 1013 }
1014 } 1014 }
1015 1015
1016 /* CQ page table */ 1016 /* CQ page table */
1017 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size); 1017 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
1018 num_pages = ep->qp.cq_mem_size / PAGE_SIZE; 1018 num_pages = ep->qp.cq_mem_size / CNIC_PAGE_SIZE;
1019 page = ep->qp.cq_phys; 1019 page = ep->qp.cq_phys;
1020 1020
1021 if (cnic_dev_10g) 1021 if (cnic_dev_10g)
@@ -1029,7 +1029,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
1029 ptbl++; 1029 ptbl++;
1030 *ptbl = (u32) ((u64) page >> 32); 1030 *ptbl = (u32) ((u64) page >> 32);
1031 ptbl++; 1031 ptbl++;
1032 page += PAGE_SIZE; 1032 page += CNIC_PAGE_SIZE;
1033 } else { 1033 } else {
1034 /* PTE is written in big endian format for 1034 /* PTE is written in big endian format for
1035 * 5706/5708/5709 devices */ 1035 * 5706/5708/5709 devices */
@@ -1037,7 +1037,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
1037 ptbl++; 1037 ptbl++;
1038 *ptbl = (u32) page; 1038 *ptbl = (u32) page;
1039 ptbl++; 1039 ptbl++;
1040 page += PAGE_SIZE; 1040 page += CNIC_PAGE_SIZE;
1041 } 1041 }
1042 } 1042 }
1043} 1043}
@@ -1064,11 +1064,11 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1064 /* Allocate page table memory for SQ which is page aligned */ 1064 /* Allocate page table memory for SQ which is page aligned */
1065 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE; 1065 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
1066 ep->qp.sq_mem_size = 1066 ep->qp.sq_mem_size =
1067 (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1067 (ep->qp.sq_mem_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1068 ep->qp.sq_pgtbl_size = 1068 ep->qp.sq_pgtbl_size =
1069 (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *); 1069 (ep->qp.sq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
1070 ep->qp.sq_pgtbl_size = 1070 ep->qp.sq_pgtbl_size =
1071 (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1071 (ep->qp.sq_pgtbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1072 1072
1073 ep->qp.sq_pgtbl_virt = 1073 ep->qp.sq_pgtbl_virt =
1074 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size, 1074 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
@@ -1101,11 +1101,11 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1101 /* Allocate page table memory for CQ which is page aligned */ 1101 /* Allocate page table memory for CQ which is page aligned */
1102 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE; 1102 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
1103 ep->qp.cq_mem_size = 1103 ep->qp.cq_mem_size =
1104 (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1104 (ep->qp.cq_mem_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1105 ep->qp.cq_pgtbl_size = 1105 ep->qp.cq_pgtbl_size =
1106 (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *); 1106 (ep->qp.cq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
1107 ep->qp.cq_pgtbl_size = 1107 ep->qp.cq_pgtbl_size =
1108 (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1108 (ep->qp.cq_pgtbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1109 1109
1110 ep->qp.cq_pgtbl_virt = 1110 ep->qp.cq_pgtbl_virt =
1111 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size, 1111 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
@@ -1144,11 +1144,11 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1144 /* Allocate page table memory for RQ which is page aligned */ 1144 /* Allocate page table memory for RQ which is page aligned */
1145 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE; 1145 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
1146 ep->qp.rq_mem_size = 1146 ep->qp.rq_mem_size =
1147 (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1147 (ep->qp.rq_mem_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1148 ep->qp.rq_pgtbl_size = 1148 ep->qp.rq_pgtbl_size =
1149 (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *); 1149 (ep->qp.rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
1150 ep->qp.rq_pgtbl_size = 1150 ep->qp.rq_pgtbl_size =
1151 (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1151 (ep->qp.rq_pgtbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1152 1152
1153 ep->qp.rq_pgtbl_virt = 1153 ep->qp.rq_pgtbl_virt =
1154 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size, 1154 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
@@ -1270,7 +1270,7 @@ int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1270 bnx2i_adjust_qp_size(hba); 1270 bnx2i_adjust_qp_size(hba);
1271 1271
1272 iscsi_init.flags = 1272 iscsi_init.flags =
1273 ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT; 1273 (CNIC_PAGE_BITS - 8) << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
1274 if (en_tcp_dack) 1274 if (en_tcp_dack)
1275 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE; 1275 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
1276 iscsi_init.reserved0 = 0; 1276 iscsi_init.reserved0 = 0;
@@ -1288,15 +1288,15 @@ int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1288 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16)); 1288 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
1289 iscsi_init.num_ccells_per_conn = hba->num_ccell; 1289 iscsi_init.num_ccells_per_conn = hba->num_ccell;
1290 iscsi_init.num_tasks_per_conn = hba->max_sqes; 1290 iscsi_init.num_tasks_per_conn = hba->max_sqes;
1291 iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE; 1291 iscsi_init.sq_wqes_per_page = CNIC_PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
1292 iscsi_init.sq_num_wqes = hba->max_sqes; 1292 iscsi_init.sq_num_wqes = hba->max_sqes;
1293 iscsi_init.cq_log_wqes_per_page = 1293 iscsi_init.cq_log_wqes_per_page =
1294 (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE); 1294 (u8) bnx2i_power_of2(CNIC_PAGE_SIZE / BNX2I_CQE_SIZE);
1295 iscsi_init.cq_num_wqes = hba->max_cqes; 1295 iscsi_init.cq_num_wqes = hba->max_cqes;
1296 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE + 1296 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
1297 (PAGE_SIZE - 1)) / PAGE_SIZE; 1297 (CNIC_PAGE_SIZE - 1)) / CNIC_PAGE_SIZE;
1298 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE + 1298 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
1299 (PAGE_SIZE - 1)) / PAGE_SIZE; 1299 (CNIC_PAGE_SIZE - 1)) / CNIC_PAGE_SIZE;
1300 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE; 1300 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
1301 iscsi_init.rq_num_wqes = hba->max_rqes; 1301 iscsi_init.rq_num_wqes = hba->max_rqes;
1302 1302
diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 854dad7d5b03..c8b0aff5bbd4 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -525,7 +525,7 @@ static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba)
525 struct iscsi_bd *mp_bdt; 525 struct iscsi_bd *mp_bdt;
526 u64 addr; 526 u64 addr;
527 527
528 hba->mp_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 528 hba->mp_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
529 &hba->mp_bd_dma, GFP_KERNEL); 529 &hba->mp_bd_dma, GFP_KERNEL);
530 if (!hba->mp_bd_tbl) { 530 if (!hba->mp_bd_tbl) {
531 printk(KERN_ERR "unable to allocate Middle Path BDT\n"); 531 printk(KERN_ERR "unable to allocate Middle Path BDT\n");
@@ -533,11 +533,12 @@ static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba)
533 goto out; 533 goto out;
534 } 534 }
535 535
536 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 536 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
537 CNIC_PAGE_SIZE,
537 &hba->dummy_buf_dma, GFP_KERNEL); 538 &hba->dummy_buf_dma, GFP_KERNEL);
538 if (!hba->dummy_buffer) { 539 if (!hba->dummy_buffer) {
539 printk(KERN_ERR "unable to alloc Middle Path Dummy Buffer\n"); 540 printk(KERN_ERR "unable to alloc Middle Path Dummy Buffer\n");
540 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 541 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
541 hba->mp_bd_tbl, hba->mp_bd_dma); 542 hba->mp_bd_tbl, hba->mp_bd_dma);
542 hba->mp_bd_tbl = NULL; 543 hba->mp_bd_tbl = NULL;
543 rc = -1; 544 rc = -1;
@@ -548,7 +549,7 @@ static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba)
548 addr = (unsigned long) hba->dummy_buf_dma; 549 addr = (unsigned long) hba->dummy_buf_dma;
549 mp_bdt->buffer_addr_lo = addr & 0xffffffff; 550 mp_bdt->buffer_addr_lo = addr & 0xffffffff;
550 mp_bdt->buffer_addr_hi = addr >> 32; 551 mp_bdt->buffer_addr_hi = addr >> 32;
551 mp_bdt->buffer_length = PAGE_SIZE; 552 mp_bdt->buffer_length = CNIC_PAGE_SIZE;
552 mp_bdt->flags = ISCSI_BD_LAST_IN_BD_CHAIN | 553 mp_bdt->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
553 ISCSI_BD_FIRST_IN_BD_CHAIN; 554 ISCSI_BD_FIRST_IN_BD_CHAIN;
554out: 555out:
@@ -565,12 +566,12 @@ out:
565static void bnx2i_free_mp_bdt(struct bnx2i_hba *hba) 566static void bnx2i_free_mp_bdt(struct bnx2i_hba *hba)
566{ 567{
567 if (hba->mp_bd_tbl) { 568 if (hba->mp_bd_tbl) {
568 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 569 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
569 hba->mp_bd_tbl, hba->mp_bd_dma); 570 hba->mp_bd_tbl, hba->mp_bd_dma);
570 hba->mp_bd_tbl = NULL; 571 hba->mp_bd_tbl = NULL;
571 } 572 }
572 if (hba->dummy_buffer) { 573 if (hba->dummy_buffer) {
573 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 574 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
574 hba->dummy_buffer, hba->dummy_buf_dma); 575 hba->dummy_buffer, hba->dummy_buf_dma);
575 hba->dummy_buffer = NULL; 576 hba->dummy_buffer = NULL;
576 } 577 }
@@ -934,14 +935,14 @@ static void bnx2i_conn_free_login_resources(struct bnx2i_hba *hba,
934 struct bnx2i_conn *bnx2i_conn) 935 struct bnx2i_conn *bnx2i_conn)
935{ 936{
936 if (bnx2i_conn->gen_pdu.resp_bd_tbl) { 937 if (bnx2i_conn->gen_pdu.resp_bd_tbl) {
937 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 938 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
938 bnx2i_conn->gen_pdu.resp_bd_tbl, 939 bnx2i_conn->gen_pdu.resp_bd_tbl,
939 bnx2i_conn->gen_pdu.resp_bd_dma); 940 bnx2i_conn->gen_pdu.resp_bd_dma);
940 bnx2i_conn->gen_pdu.resp_bd_tbl = NULL; 941 bnx2i_conn->gen_pdu.resp_bd_tbl = NULL;
941 } 942 }
942 943
943 if (bnx2i_conn->gen_pdu.req_bd_tbl) { 944 if (bnx2i_conn->gen_pdu.req_bd_tbl) {
944 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 945 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
945 bnx2i_conn->gen_pdu.req_bd_tbl, 946 bnx2i_conn->gen_pdu.req_bd_tbl,
946 bnx2i_conn->gen_pdu.req_bd_dma); 947 bnx2i_conn->gen_pdu.req_bd_dma);
947 bnx2i_conn->gen_pdu.req_bd_tbl = NULL; 948 bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
@@ -998,13 +999,13 @@ static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba *hba,
998 bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf; 999 bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf;
999 1000
1000 bnx2i_conn->gen_pdu.req_bd_tbl = 1001 bnx2i_conn->gen_pdu.req_bd_tbl =
1001 dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 1002 dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
1002 &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL); 1003 &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
1003 if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL) 1004 if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL)
1004 goto login_req_bd_tbl_failure; 1005 goto login_req_bd_tbl_failure;
1005 1006
1006 bnx2i_conn->gen_pdu.resp_bd_tbl = 1007 bnx2i_conn->gen_pdu.resp_bd_tbl =
1007 dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 1008 dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
1008 &bnx2i_conn->gen_pdu.resp_bd_dma, 1009 &bnx2i_conn->gen_pdu.resp_bd_dma,
1009 GFP_KERNEL); 1010 GFP_KERNEL);
1010 if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL) 1011 if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL)
@@ -1013,7 +1014,7 @@ static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba *hba,
1013 return 0; 1014 return 0;
1014 1015
1015login_resp_bd_tbl_failure: 1016login_resp_bd_tbl_failure:
1016 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1017 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
1017 bnx2i_conn->gen_pdu.req_bd_tbl, 1018 bnx2i_conn->gen_pdu.req_bd_tbl,
1018 bnx2i_conn->gen_pdu.req_bd_dma); 1019 bnx2i_conn->gen_pdu.req_bd_dma);
1019 bnx2i_conn->gen_pdu.req_bd_tbl = NULL; 1020 bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
diff --git a/drivers/scsi/isci/host.h b/drivers/scsi/isci/host.h
index 4911310a38f5..22a9bb1abae1 100644
--- a/drivers/scsi/isci/host.h
+++ b/drivers/scsi/isci/host.h
@@ -311,9 +311,8 @@ static inline struct Scsi_Host *to_shost(struct isci_host *ihost)
311} 311}
312 312
313#define for_each_isci_host(id, ihost, pdev) \ 313#define for_each_isci_host(id, ihost, pdev) \
314 for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \ 314 for (id = 0; id < SCI_MAX_CONTROLLERS && \
315 id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ 315 (ihost = to_pci_info(pdev)->hosts[id]); id++)
316 ihost = to_pci_info(pdev)->hosts[++id])
317 316
318static inline void wait_for_start(struct isci_host *ihost) 317static inline void wait_for_start(struct isci_host *ihost)
319{ 318{
diff --git a/drivers/scsi/isci/port_config.c b/drivers/scsi/isci/port_config.c
index 85c77f6b802b..ac879745ef80 100644
--- a/drivers/scsi/isci/port_config.c
+++ b/drivers/scsi/isci/port_config.c
@@ -615,13 +615,6 @@ static void sci_apc_agent_link_up(struct isci_host *ihost,
615 SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION); 615 SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION);
616 } else { 616 } else {
617 /* the phy is already the part of the port */ 617 /* the phy is already the part of the port */
618 u32 port_state = iport->sm.current_state_id;
619
620 /* if the PORT'S state is resetting then the link up is from
621 * port hard reset in this case, we need to tell the port
622 * that link up is recieved
623 */
624 BUG_ON(port_state != SCI_PORT_RESETTING);
625 port_agent->phy_ready_mask |= 1 << phy_index; 618 port_agent->phy_ready_mask |= 1 << phy_index;
626 sci_port_link_up(iport, iphy); 619 sci_port_link_up(iport, iphy);
627 } 620 }
diff --git a/drivers/scsi/isci/task.c b/drivers/scsi/isci/task.c
index 0d30ca849e8f..5d6fda72d659 100644
--- a/drivers/scsi/isci/task.c
+++ b/drivers/scsi/isci/task.c
@@ -801,7 +801,7 @@ int isci_task_I_T_nexus_reset(struct domain_device *dev)
801 /* XXX: need to cleanup any ireqs targeting this 801 /* XXX: need to cleanup any ireqs targeting this
802 * domain_device 802 * domain_device
803 */ 803 */
804 ret = TMF_RESP_FUNC_COMPLETE; 804 ret = -ENODEV;
805 goto out; 805 goto out;
806 } 806 }
807 807
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index e1fe95ef23e1..266724b6b899 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2996,8 +2996,7 @@ struct qla_hw_data {
2996 IS_QLA82XX(ha) || IS_QLA83XX(ha) || \ 2996 IS_QLA82XX(ha) || IS_QLA83XX(ha) || \
2997 IS_QLA8044(ha)) 2997 IS_QLA8044(ha))
2998#define IS_MSIX_NACK_CAPABLE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha)) 2998#define IS_MSIX_NACK_CAPABLE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha))
2999#define IS_NOPOLLING_TYPE(ha) ((IS_QLA25XX(ha) || IS_QLA81XX(ha) || \ 2999#define IS_NOPOLLING_TYPE(ha) (IS_QLA81XX(ha) && (ha)->flags.msix_enabled)
3000 IS_QLA83XX(ha)) && (ha)->flags.msix_enabled)
3001#define IS_FAC_REQUIRED(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha)) 3000#define IS_FAC_REQUIRED(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha))
3002#define IS_NOCACHE_VPD_TYPE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha)) 3001#define IS_NOCACHE_VPD_TYPE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha))
3003#define IS_ALOGIO_CAPABLE(ha) (IS_QLA23XX(ha) || IS_FWI2_CAPABLE(ha)) 3002#define IS_ALOGIO_CAPABLE(ha) (IS_QLA23XX(ha) || IS_FWI2_CAPABLE(ha))
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 9bc86b9e86b1..0a1dcb43d18b 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2880,6 +2880,7 @@ static int
2880qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp) 2880qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
2881{ 2881{
2882#define MIN_MSIX_COUNT 2 2882#define MIN_MSIX_COUNT 2
2883#define ATIO_VECTOR 2
2883 int i, ret; 2884 int i, ret;
2884 struct msix_entry *entries; 2885 struct msix_entry *entries;
2885 struct qla_msix_entry *qentry; 2886 struct qla_msix_entry *qentry;
@@ -2936,34 +2937,47 @@ msix_failed:
2936 } 2937 }
2937 2938
2938 /* Enable MSI-X vectors for the base queue */ 2939 /* Enable MSI-X vectors for the base queue */
2939 for (i = 0; i < ha->msix_count; i++) { 2940 for (i = 0; i < 2; i++) {
2940 qentry = &ha->msix_entries[i]; 2941 qentry = &ha->msix_entries[i];
2941 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) { 2942 if (IS_P3P_TYPE(ha))
2942 ret = request_irq(qentry->vector,
2943 qla83xx_msix_entries[i].handler,
2944 0, qla83xx_msix_entries[i].name, rsp);
2945 } else if (IS_P3P_TYPE(ha)) {
2946 ret = request_irq(qentry->vector, 2943 ret = request_irq(qentry->vector,
2947 qla82xx_msix_entries[i].handler, 2944 qla82xx_msix_entries[i].handler,
2948 0, qla82xx_msix_entries[i].name, rsp); 2945 0, qla82xx_msix_entries[i].name, rsp);
2949 } else { 2946 else
2950 ret = request_irq(qentry->vector, 2947 ret = request_irq(qentry->vector,
2951 msix_entries[i].handler, 2948 msix_entries[i].handler,
2952 0, msix_entries[i].name, rsp); 2949 0, msix_entries[i].name, rsp);
2953 } 2950 if (ret)
2954 if (ret) { 2951 goto msix_register_fail;
2955 ql_log(ql_log_fatal, vha, 0x00cb,
2956 "MSI-X: unable to register handler -- %x/%d.\n",
2957 qentry->vector, ret);
2958 qla24xx_disable_msix(ha);
2959 ha->mqenable = 0;
2960 goto msix_out;
2961 }
2962 qentry->have_irq = 1; 2952 qentry->have_irq = 1;
2963 qentry->rsp = rsp; 2953 qentry->rsp = rsp;
2964 rsp->msix = qentry; 2954 rsp->msix = qentry;
2965 } 2955 }
2966 2956
2957 /*
2958 * If target mode is enable, also request the vector for the ATIO
2959 * queue.
2960 */
2961 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
2962 qentry = &ha->msix_entries[ATIO_VECTOR];
2963 ret = request_irq(qentry->vector,
2964 qla83xx_msix_entries[ATIO_VECTOR].handler,
2965 0, qla83xx_msix_entries[ATIO_VECTOR].name, rsp);
2966 qentry->have_irq = 1;
2967 qentry->rsp = rsp;
2968 rsp->msix = qentry;
2969 }
2970
2971msix_register_fail:
2972 if (ret) {
2973 ql_log(ql_log_fatal, vha, 0x00cb,
2974 "MSI-X: unable to register handler -- %x/%d.\n",
2975 qentry->vector, ret);
2976 qla24xx_disable_msix(ha);
2977 ha->mqenable = 0;
2978 goto msix_out;
2979 }
2980
2967 /* Enable MSI-X vector for response queue update for queue 0 */ 2981 /* Enable MSI-X vector for response queue update for queue 0 */
2968 if (IS_QLA83XX(ha)) { 2982 if (IS_QLA83XX(ha)) {
2969 if (ha->msixbase && ha->mqiobase && 2983 if (ha->msixbase && ha->mqiobase &&
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 9e80d61e5a3a..0cb73074c199 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -790,17 +790,32 @@ static inline int test_tgt_sess_count(struct qla_tgt *tgt)
790} 790}
791 791
792/* Called by tcm_qla2xxx configfs code */ 792/* Called by tcm_qla2xxx configfs code */
793void qlt_stop_phase1(struct qla_tgt *tgt) 793int qlt_stop_phase1(struct qla_tgt *tgt)
794{ 794{
795 struct scsi_qla_host *vha = tgt->vha; 795 struct scsi_qla_host *vha = tgt->vha;
796 struct qla_hw_data *ha = tgt->ha; 796 struct qla_hw_data *ha = tgt->ha;
797 unsigned long flags; 797 unsigned long flags;
798 798
799 mutex_lock(&qla_tgt_mutex);
800 if (!vha->fc_vport) {
801 struct Scsi_Host *sh = vha->host;
802 struct fc_host_attrs *fc_host = shost_to_fc_host(sh);
803 bool npiv_vports;
804
805 spin_lock_irqsave(sh->host_lock, flags);
806 npiv_vports = (fc_host->npiv_vports_inuse);
807 spin_unlock_irqrestore(sh->host_lock, flags);
808
809 if (npiv_vports) {
810 mutex_unlock(&qla_tgt_mutex);
811 return -EPERM;
812 }
813 }
799 if (tgt->tgt_stop || tgt->tgt_stopped) { 814 if (tgt->tgt_stop || tgt->tgt_stopped) {
800 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, 815 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e,
801 "Already in tgt->tgt_stop or tgt_stopped state\n"); 816 "Already in tgt->tgt_stop or tgt_stopped state\n");
802 dump_stack(); 817 mutex_unlock(&qla_tgt_mutex);
803 return; 818 return -EPERM;
804 } 819 }
805 820
806 ql_dbg(ql_dbg_tgt, vha, 0xe003, "Stopping target for host %ld(%p)\n", 821 ql_dbg(ql_dbg_tgt, vha, 0xe003, "Stopping target for host %ld(%p)\n",
@@ -815,6 +830,7 @@ void qlt_stop_phase1(struct qla_tgt *tgt)
815 qlt_clear_tgt_db(tgt, true); 830 qlt_clear_tgt_db(tgt, true);
816 spin_unlock_irqrestore(&ha->hardware_lock, flags); 831 spin_unlock_irqrestore(&ha->hardware_lock, flags);
817 mutex_unlock(&vha->vha_tgt.tgt_mutex); 832 mutex_unlock(&vha->vha_tgt.tgt_mutex);
833 mutex_unlock(&qla_tgt_mutex);
818 834
819 flush_delayed_work(&tgt->sess_del_work); 835 flush_delayed_work(&tgt->sess_del_work);
820 836
@@ -841,6 +857,7 @@ void qlt_stop_phase1(struct qla_tgt *tgt)
841 857
842 /* Wait for sessions to clear out (just in case) */ 858 /* Wait for sessions to clear out (just in case) */
843 wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); 859 wait_event(tgt->waitQ, test_tgt_sess_count(tgt));
860 return 0;
844} 861}
845EXPORT_SYMBOL(qlt_stop_phase1); 862EXPORT_SYMBOL(qlt_stop_phase1);
846 863
@@ -2595,8 +2612,6 @@ static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha,
2595 return -ENOMEM; 2612 return -ENOMEM;
2596 } 2613 }
2597 2614
2598 INIT_LIST_HEAD(&cmd->cmd_list);
2599
2600 memcpy(&cmd->atio, atio, sizeof(*atio)); 2615 memcpy(&cmd->atio, atio, sizeof(*atio));
2601 cmd->state = QLA_TGT_STATE_NEW; 2616 cmd->state = QLA_TGT_STATE_NEW;
2602 cmd->tgt = vha->vha_tgt.qla_tgt; 2617 cmd->tgt = vha->vha_tgt.qla_tgt;
@@ -3187,7 +3202,8 @@ restart:
3187 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02c, 3202 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02c,
3188 "SRR cmd %p (se_cmd %p, tag %d, op %x), " 3203 "SRR cmd %p (se_cmd %p, tag %d, op %x), "
3189 "sg_cnt=%d, offset=%d", cmd, &cmd->se_cmd, cmd->tag, 3204 "sg_cnt=%d, offset=%d", cmd, &cmd->se_cmd, cmd->tag,
3190 se_cmd->t_task_cdb[0], cmd->sg_cnt, cmd->offset); 3205 se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0,
3206 cmd->sg_cnt, cmd->offset);
3191 3207
3192 qlt_handle_srr(vha, sctio, imm); 3208 qlt_handle_srr(vha, sctio, imm);
3193 3209
@@ -4183,6 +4199,9 @@ int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
4183 tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX; 4199 tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX;
4184 tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX; 4200 tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX;
4185 4201
4202 if (base_vha->fc_vport)
4203 return 0;
4204
4186 mutex_lock(&qla_tgt_mutex); 4205 mutex_lock(&qla_tgt_mutex);
4187 list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); 4206 list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist);
4188 mutex_unlock(&qla_tgt_mutex); 4207 mutex_unlock(&qla_tgt_mutex);
@@ -4196,6 +4215,10 @@ int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha)
4196 if (!vha->vha_tgt.qla_tgt) 4215 if (!vha->vha_tgt.qla_tgt)
4197 return 0; 4216 return 0;
4198 4217
4218 if (vha->fc_vport) {
4219 qlt_release(vha->vha_tgt.qla_tgt);
4220 return 0;
4221 }
4199 mutex_lock(&qla_tgt_mutex); 4222 mutex_lock(&qla_tgt_mutex);
4200 list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); 4223 list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
4201 mutex_unlock(&qla_tgt_mutex); 4224 mutex_unlock(&qla_tgt_mutex);
@@ -4267,6 +4290,12 @@ int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
4267 spin_unlock_irqrestore(&ha->hardware_lock, flags); 4290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4268 continue; 4291 continue;
4269 } 4292 }
4293 if (tgt->tgt_stop) {
4294 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
4295 host->host_no);
4296 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4297 continue;
4298 }
4270 spin_unlock_irqrestore(&ha->hardware_lock, flags); 4299 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4271 4300
4272 if (!scsi_host_get(host)) { 4301 if (!scsi_host_get(host)) {
@@ -4281,12 +4310,11 @@ int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
4281 scsi_host_put(host); 4310 scsi_host_put(host);
4282 continue; 4311 continue;
4283 } 4312 }
4284 mutex_unlock(&qla_tgt_mutex);
4285
4286 rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); 4313 rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn);
4287 if (rc != 0) 4314 if (rc != 0)
4288 scsi_host_put(host); 4315 scsi_host_put(host);
4289 4316
4317 mutex_unlock(&qla_tgt_mutex);
4290 return rc; 4318 return rc;
4291 } 4319 }
4292 mutex_unlock(&qla_tgt_mutex); 4320 mutex_unlock(&qla_tgt_mutex);
diff --git a/drivers/scsi/qla2xxx/qla_target.h b/drivers/scsi/qla2xxx/qla_target.h
index 1d10eecad499..ce33d8c26406 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -855,7 +855,6 @@ struct qla_tgt_cmd {
855 uint16_t loop_id; /* to save extra sess dereferences */ 855 uint16_t loop_id; /* to save extra sess dereferences */
856 struct qla_tgt *tgt; /* to save extra sess dereferences */ 856 struct qla_tgt *tgt; /* to save extra sess dereferences */
857 struct scsi_qla_host *vha; 857 struct scsi_qla_host *vha;
858 struct list_head cmd_list;
859 858
860 struct atio_from_isp atio; 859 struct atio_from_isp atio;
861}; 860};
@@ -1002,7 +1001,7 @@ extern void qlt_modify_vp_config(struct scsi_qla_host *,
1002extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *); 1001extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *);
1003extern int qlt_mem_alloc(struct qla_hw_data *); 1002extern int qlt_mem_alloc(struct qla_hw_data *);
1004extern void qlt_mem_free(struct qla_hw_data *); 1003extern void qlt_mem_free(struct qla_hw_data *);
1005extern void qlt_stop_phase1(struct qla_tgt *); 1004extern int qlt_stop_phase1(struct qla_tgt *);
1006extern void qlt_stop_phase2(struct qla_tgt *); 1005extern void qlt_stop_phase2(struct qla_tgt *);
1007extern irqreturn_t qla83xx_msix_atio_q(int, void *); 1006extern irqreturn_t qla83xx_msix_atio_q(int, void *);
1008extern void qlt_83xx_iospace_config(struct qla_hw_data *); 1007extern void qlt_83xx_iospace_config(struct qla_hw_data *);
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 75a141bbe74d..788c4fe2b0c9 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -182,20 +182,6 @@ static int tcm_qla2xxx_npiv_parse_wwn(
182 return 0; 182 return 0;
183} 183}
184 184
185static ssize_t tcm_qla2xxx_npiv_format_wwn(char *buf, size_t len,
186 u64 wwpn, u64 wwnn)
187{
188 u8 b[8], b2[8];
189
190 put_unaligned_be64(wwpn, b);
191 put_unaligned_be64(wwnn, b2);
192 return snprintf(buf, len,
193 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x,"
194 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
195 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
196 b2[0], b2[1], b2[2], b2[3], b2[4], b2[5], b2[6], b2[7]);
197}
198
199static char *tcm_qla2xxx_npiv_get_fabric_name(void) 185static char *tcm_qla2xxx_npiv_get_fabric_name(void)
200{ 186{
201 return "qla2xxx_npiv"; 187 return "qla2xxx_npiv";
@@ -227,15 +213,6 @@ static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group *se_tpg)
227 return lport->lport_naa_name; 213 return lport->lport_naa_name;
228} 214}
229 215
230static char *tcm_qla2xxx_npiv_get_fabric_wwn(struct se_portal_group *se_tpg)
231{
232 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
233 struct tcm_qla2xxx_tpg, se_tpg);
234 struct tcm_qla2xxx_lport *lport = tpg->lport;
235
236 return &lport->lport_npiv_name[0];
237}
238
239static u16 tcm_qla2xxx_get_tag(struct se_portal_group *se_tpg) 216static u16 tcm_qla2xxx_get_tag(struct se_portal_group *se_tpg)
240{ 217{
241 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 218 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
@@ -941,15 +918,41 @@ static ssize_t tcm_qla2xxx_tpg_show_enable(
941 atomic_read(&tpg->lport_tpg_enabled)); 918 atomic_read(&tpg->lport_tpg_enabled));
942} 919}
943 920
921static void tcm_qla2xxx_depend_tpg(struct work_struct *work)
922{
923 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
924 struct tcm_qla2xxx_tpg, tpg_base_work);
925 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
926 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
927
928 if (!configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys,
929 &se_tpg->tpg_group.cg_item)) {
930 atomic_set(&base_tpg->lport_tpg_enabled, 1);
931 qlt_enable_vha(base_vha);
932 }
933 complete(&base_tpg->tpg_base_comp);
934}
935
936static void tcm_qla2xxx_undepend_tpg(struct work_struct *work)
937{
938 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
939 struct tcm_qla2xxx_tpg, tpg_base_work);
940 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
941 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
942
943 if (!qlt_stop_phase1(base_vha->vha_tgt.qla_tgt)) {
944 atomic_set(&base_tpg->lport_tpg_enabled, 0);
945 configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys,
946 &se_tpg->tpg_group.cg_item);
947 }
948 complete(&base_tpg->tpg_base_comp);
949}
950
944static ssize_t tcm_qla2xxx_tpg_store_enable( 951static ssize_t tcm_qla2xxx_tpg_store_enable(
945 struct se_portal_group *se_tpg, 952 struct se_portal_group *se_tpg,
946 const char *page, 953 const char *page,
947 size_t count) 954 size_t count)
948{ 955{
949 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
950 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
951 struct tcm_qla2xxx_lport, lport_wwn);
952 struct scsi_qla_host *vha = lport->qla_vha;
953 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 956 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
954 struct tcm_qla2xxx_tpg, se_tpg); 957 struct tcm_qla2xxx_tpg, se_tpg);
955 unsigned long op; 958 unsigned long op;
@@ -964,19 +967,28 @@ static ssize_t tcm_qla2xxx_tpg_store_enable(
964 pr_err("Illegal value for tpg_enable: %lu\n", op); 967 pr_err("Illegal value for tpg_enable: %lu\n", op);
965 return -EINVAL; 968 return -EINVAL;
966 } 969 }
967
968 if (op) { 970 if (op) {
969 atomic_set(&tpg->lport_tpg_enabled, 1); 971 if (atomic_read(&tpg->lport_tpg_enabled))
970 qlt_enable_vha(vha); 972 return -EEXIST;
973
974 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_depend_tpg);
971 } else { 975 } else {
972 if (!vha->vha_tgt.qla_tgt) { 976 if (!atomic_read(&tpg->lport_tpg_enabled))
973 pr_err("struct qla_hw_data *vha->vha_tgt.qla_tgt is NULL\n"); 977 return count;
974 return -ENODEV; 978
975 } 979 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_undepend_tpg);
976 atomic_set(&tpg->lport_tpg_enabled, 0);
977 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
978 } 980 }
981 init_completion(&tpg->tpg_base_comp);
982 schedule_work(&tpg->tpg_base_work);
983 wait_for_completion(&tpg->tpg_base_comp);
979 984
985 if (op) {
986 if (!atomic_read(&tpg->lport_tpg_enabled))
987 return -ENODEV;
988 } else {
989 if (atomic_read(&tpg->lport_tpg_enabled))
990 return -EPERM;
991 }
980 return count; 992 return count;
981} 993}
982 994
@@ -1053,11 +1065,64 @@ static void tcm_qla2xxx_drop_tpg(struct se_portal_group *se_tpg)
1053 /* 1065 /*
1054 * Clear local TPG=1 pointer for non NPIV mode. 1066 * Clear local TPG=1 pointer for non NPIV mode.
1055 */ 1067 */
1056 lport->tpg_1 = NULL; 1068 lport->tpg_1 = NULL;
1057
1058 kfree(tpg); 1069 kfree(tpg);
1059} 1070}
1060 1071
1072static ssize_t tcm_qla2xxx_npiv_tpg_show_enable(
1073 struct se_portal_group *se_tpg,
1074 char *page)
1075{
1076 return tcm_qla2xxx_tpg_show_enable(se_tpg, page);
1077}
1078
1079static ssize_t tcm_qla2xxx_npiv_tpg_store_enable(
1080 struct se_portal_group *se_tpg,
1081 const char *page,
1082 size_t count)
1083{
1084 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
1085 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
1086 struct tcm_qla2xxx_lport, lport_wwn);
1087 struct scsi_qla_host *vha = lport->qla_vha;
1088 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1089 struct tcm_qla2xxx_tpg, se_tpg);
1090 unsigned long op;
1091 int rc;
1092
1093 rc = kstrtoul(page, 0, &op);
1094 if (rc < 0) {
1095 pr_err("kstrtoul() returned %d\n", rc);
1096 return -EINVAL;
1097 }
1098 if ((op != 1) && (op != 0)) {
1099 pr_err("Illegal value for tpg_enable: %lu\n", op);
1100 return -EINVAL;
1101 }
1102 if (op) {
1103 if (atomic_read(&tpg->lport_tpg_enabled))
1104 return -EEXIST;
1105
1106 atomic_set(&tpg->lport_tpg_enabled, 1);
1107 qlt_enable_vha(vha);
1108 } else {
1109 if (!atomic_read(&tpg->lport_tpg_enabled))
1110 return count;
1111
1112 atomic_set(&tpg->lport_tpg_enabled, 0);
1113 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
1114 }
1115
1116 return count;
1117}
1118
1119TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv, enable, S_IRUGO | S_IWUSR);
1120
1121static struct configfs_attribute *tcm_qla2xxx_npiv_tpg_attrs[] = {
1122 &tcm_qla2xxx_npiv_tpg_enable.attr,
1123 NULL,
1124};
1125
1061static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg( 1126static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg(
1062 struct se_wwn *wwn, 1127 struct se_wwn *wwn,
1063 struct config_group *group, 1128 struct config_group *group,
@@ -1650,6 +1715,9 @@ static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1650 struct scsi_qla_host *npiv_vha; 1715 struct scsi_qla_host *npiv_vha;
1651 struct tcm_qla2xxx_lport *lport = 1716 struct tcm_qla2xxx_lport *lport =
1652 (struct tcm_qla2xxx_lport *)target_lport_ptr; 1717 (struct tcm_qla2xxx_lport *)target_lport_ptr;
1718 struct tcm_qla2xxx_lport *base_lport =
1719 (struct tcm_qla2xxx_lport *)base_vha->vha_tgt.target_lport_ptr;
1720 struct tcm_qla2xxx_tpg *base_tpg;
1653 struct fc_vport_identifiers vport_id; 1721 struct fc_vport_identifiers vport_id;
1654 1722
1655 if (!qla_tgt_mode_enabled(base_vha)) { 1723 if (!qla_tgt_mode_enabled(base_vha)) {
@@ -1657,6 +1725,13 @@ static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1657 return -EPERM; 1725 return -EPERM;
1658 } 1726 }
1659 1727
1728 if (!base_lport || !base_lport->tpg_1 ||
1729 !atomic_read(&base_lport->tpg_1->lport_tpg_enabled)) {
1730 pr_err("qla2xxx base_lport or tpg_1 not available\n");
1731 return -EPERM;
1732 }
1733 base_tpg = base_lport->tpg_1;
1734
1660 memset(&vport_id, 0, sizeof(vport_id)); 1735 memset(&vport_id, 0, sizeof(vport_id));
1661 vport_id.port_name = npiv_wwpn; 1736 vport_id.port_name = npiv_wwpn;
1662 vport_id.node_name = npiv_wwnn; 1737 vport_id.node_name = npiv_wwnn;
@@ -1675,7 +1750,6 @@ static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1675 npiv_vha = (struct scsi_qla_host *)vport->dd_data; 1750 npiv_vha = (struct scsi_qla_host *)vport->dd_data;
1676 npiv_vha->vha_tgt.target_lport_ptr = target_lport_ptr; 1751 npiv_vha->vha_tgt.target_lport_ptr = target_lport_ptr;
1677 lport->qla_vha = npiv_vha; 1752 lport->qla_vha = npiv_vha;
1678
1679 scsi_host_get(npiv_vha->host); 1753 scsi_host_get(npiv_vha->host);
1680 return 0; 1754 return 0;
1681} 1755}
@@ -1714,8 +1788,6 @@ static struct se_wwn *tcm_qla2xxx_npiv_make_lport(
1714 } 1788 }
1715 lport->lport_npiv_wwpn = npiv_wwpn; 1789 lport->lport_npiv_wwpn = npiv_wwpn;
1716 lport->lport_npiv_wwnn = npiv_wwnn; 1790 lport->lport_npiv_wwnn = npiv_wwnn;
1717 tcm_qla2xxx_npiv_format_wwn(&lport->lport_npiv_name[0],
1718 TCM_QLA2XXX_NAMELEN, npiv_wwpn, npiv_wwnn);
1719 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn); 1791 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn);
1720 1792
1721 ret = tcm_qla2xxx_init_lport(lport); 1793 ret = tcm_qla2xxx_init_lport(lport);
@@ -1824,7 +1896,7 @@ static struct target_core_fabric_ops tcm_qla2xxx_ops = {
1824static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = { 1896static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
1825 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name, 1897 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name,
1826 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident, 1898 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident,
1827 .tpg_get_wwn = tcm_qla2xxx_npiv_get_fabric_wwn, 1899 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
1828 .tpg_get_tag = tcm_qla2xxx_get_tag, 1900 .tpg_get_tag = tcm_qla2xxx_get_tag,
1829 .tpg_get_default_depth = tcm_qla2xxx_get_default_depth, 1901 .tpg_get_default_depth = tcm_qla2xxx_get_default_depth,
1830 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id, 1902 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
@@ -1935,7 +2007,7 @@ static int tcm_qla2xxx_register_configfs(void)
1935 */ 2007 */
1936 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs; 2008 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs;
1937 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = 2009 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs =
1938 tcm_qla2xxx_tpg_attrs; 2010 tcm_qla2xxx_npiv_tpg_attrs;
1939 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL; 2011 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
1940 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; 2012 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
1941 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; 2013 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.h b/drivers/scsi/qla2xxx/tcm_qla2xxx.h
index 275d8b9a7a34..33aaac8c7d59 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.h
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.h
@@ -4,8 +4,6 @@
4#define TCM_QLA2XXX_VERSION "v0.1" 4#define TCM_QLA2XXX_VERSION "v0.1"
5/* length of ASCII WWPNs including pad */ 5/* length of ASCII WWPNs including pad */
6#define TCM_QLA2XXX_NAMELEN 32 6#define TCM_QLA2XXX_NAMELEN 32
7/* lenth of ASCII NPIV 'WWPN+WWNN' including pad */
8#define TCM_QLA2XXX_NPIV_NAMELEN 66
9 7
10#include "qla_target.h" 8#include "qla_target.h"
11 9
@@ -43,6 +41,9 @@ struct tcm_qla2xxx_tpg {
43 struct tcm_qla2xxx_tpg_attrib tpg_attrib; 41 struct tcm_qla2xxx_tpg_attrib tpg_attrib;
44 /* Returned by tcm_qla2xxx_make_tpg() */ 42 /* Returned by tcm_qla2xxx_make_tpg() */
45 struct se_portal_group se_tpg; 43 struct se_portal_group se_tpg;
44 /* Items for dealing with configfs_depend_item */
45 struct completion tpg_base_comp;
46 struct work_struct tpg_base_work;
46}; 47};
47 48
48struct tcm_qla2xxx_fc_loopid { 49struct tcm_qla2xxx_fc_loopid {
@@ -62,8 +63,6 @@ struct tcm_qla2xxx_lport {
62 char lport_name[TCM_QLA2XXX_NAMELEN]; 63 char lport_name[TCM_QLA2XXX_NAMELEN];
63 /* ASCII formatted naa WWPN for VPD page 83 etc */ 64 /* ASCII formatted naa WWPN for VPD page 83 etc */
64 char lport_naa_name[TCM_QLA2XXX_NAMELEN]; 65 char lport_naa_name[TCM_QLA2XXX_NAMELEN];
65 /* ASCII formatted WWPN+WWNN for NPIV FC Target Lport */
66 char lport_npiv_name[TCM_QLA2XXX_NPIV_NAMELEN];
67 /* map for fc_port pointers in 24-bit FC Port ID space */ 66 /* map for fc_port pointers in 24-bit FC Port ID space */
68 struct btree_head32 lport_fcport_map; 67 struct btree_head32 lport_fcport_map;
69 /* vmalloc-ed memory for fc_port pointers for 16-bit FC loop ID */ 68 /* vmalloc-ed memory for fc_port pointers for 16-bit FC loop ID */
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 7bd7f0d5f050..62ec84b42e31 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1684,7 +1684,7 @@ u64 scsi_calculate_bounce_limit(struct Scsi_Host *shost)
1684 1684
1685 host_dev = scsi_get_device(shost); 1685 host_dev = scsi_get_device(shost);
1686 if (host_dev && host_dev->dma_mask) 1686 if (host_dev && host_dev->dma_mask)
1687 bounce_limit = dma_max_pfn(host_dev) << PAGE_SHIFT; 1687 bounce_limit = (u64)dma_max_pfn(host_dev) << PAGE_SHIFT;
1688 1688
1689 return bounce_limit; 1689 return bounce_limit;
1690} 1690}
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 17d740427240..9969fa1ef7c4 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1419,6 +1419,9 @@ static void storvsc_device_destroy(struct scsi_device *sdevice)
1419{ 1419{
1420 struct stor_mem_pools *memp = sdevice->hostdata; 1420 struct stor_mem_pools *memp = sdevice->hostdata;
1421 1421
1422 if (!memp)
1423 return;
1424
1422 mempool_destroy(memp->request_mempool); 1425 mempool_destroy(memp->request_mempool);
1423 kmem_cache_destroy(memp->request_pool); 1426 kmem_cache_destroy(memp->request_pool);
1424 kfree(memp); 1427 kfree(memp);
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index ba9310bc9acb..581ee2a8856b 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -376,10 +376,10 @@ config SPI_PXA2XX_PCI
376 def_tristate SPI_PXA2XX && PCI 376 def_tristate SPI_PXA2XX && PCI
377 377
378config SPI_RSPI 378config SPI_RSPI
379 tristate "Renesas RSPI controller" 379 tristate "Renesas RSPI/QSPI controller"
380 depends on (SUPERH && SH_DMAE_BASE) || ARCH_SHMOBILE 380 depends on (SUPERH && SH_DMAE_BASE) || ARCH_SHMOBILE
381 help 381 help
382 SPI driver for Renesas RSPI blocks. 382 SPI driver for Renesas RSPI and QSPI blocks.
383 383
384config SPI_S3C24XX 384config SPI_S3C24XX
385 tristate "Samsung S3C24XX series SPI" 385 tristate "Samsung S3C24XX series SPI"
diff --git a/drivers/spi/spi-ath79.c b/drivers/spi/spi-ath79.c
index 31534b51715a..c3b2fb9b6713 100644
--- a/drivers/spi/spi-ath79.c
+++ b/drivers/spi/spi-ath79.c
@@ -132,9 +132,9 @@ static int ath79_spi_setup_cs(struct spi_device *spi)
132 132
133 flags = GPIOF_DIR_OUT; 133 flags = GPIOF_DIR_OUT;
134 if (spi->mode & SPI_CS_HIGH) 134 if (spi->mode & SPI_CS_HIGH)
135 flags |= GPIOF_INIT_HIGH;
136 else
137 flags |= GPIOF_INIT_LOW; 135 flags |= GPIOF_INIT_LOW;
136 else
137 flags |= GPIOF_INIT_HIGH;
138 138
139 status = gpio_request_one(cdata->gpio, flags, 139 status = gpio_request_one(cdata->gpio, flags,
140 dev_name(&spi->dev)); 140 dev_name(&spi->dev));
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index b0842f751016..5d7b07f08326 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -1455,6 +1455,14 @@ static int atmel_spi_suspend(struct device *dev)
1455{ 1455{
1456 struct spi_master *master = dev_get_drvdata(dev); 1456 struct spi_master *master = dev_get_drvdata(dev);
1457 struct atmel_spi *as = spi_master_get_devdata(master); 1457 struct atmel_spi *as = spi_master_get_devdata(master);
1458 int ret;
1459
1460 /* Stop the queue running */
1461 ret = spi_master_suspend(master);
1462 if (ret) {
1463 dev_warn(dev, "cannot suspend master\n");
1464 return ret;
1465 }
1458 1466
1459 clk_disable_unprepare(as->clk); 1467 clk_disable_unprepare(as->clk);
1460 return 0; 1468 return 0;
@@ -1464,9 +1472,16 @@ static int atmel_spi_resume(struct device *dev)
1464{ 1472{
1465 struct spi_master *master = dev_get_drvdata(dev); 1473 struct spi_master *master = dev_get_drvdata(dev);
1466 struct atmel_spi *as = spi_master_get_devdata(master); 1474 struct atmel_spi *as = spi_master_get_devdata(master);
1475 int ret;
1467 1476
1468 clk_prepare_enable(as->clk); 1477 clk_prepare_enable(as->clk);
1469 return 0; 1478
1479 /* Start the queue running */
1480 ret = spi_master_resume(master);
1481 if (ret)
1482 dev_err(dev, "problem starting queue (%d)\n", ret);
1483
1484 return ret;
1470} 1485}
1471 1486
1472static SIMPLE_DEV_PM_OPS(atmel_spi_pm_ops, atmel_spi_suspend, atmel_spi_resume); 1487static SIMPLE_DEV_PM_OPS(atmel_spi_pm_ops, atmel_spi_suspend, atmel_spi_resume);
diff --git a/drivers/spi/spi-coldfire-qspi.c b/drivers/spi/spi-coldfire-qspi.c
index cabed8f9119e..28ae470397a9 100644
--- a/drivers/spi/spi-coldfire-qspi.c
+++ b/drivers/spi/spi-coldfire-qspi.c
@@ -514,7 +514,8 @@ static int mcfqspi_resume(struct device *dev)
514#ifdef CONFIG_PM_RUNTIME 514#ifdef CONFIG_PM_RUNTIME
515static int mcfqspi_runtime_suspend(struct device *dev) 515static int mcfqspi_runtime_suspend(struct device *dev)
516{ 516{
517 struct mcfqspi *mcfqspi = dev_get_drvdata(dev); 517 struct spi_master *master = dev_get_drvdata(dev);
518 struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
518 519
519 clk_disable(mcfqspi->clk); 520 clk_disable(mcfqspi->clk);
520 521
@@ -523,7 +524,8 @@ static int mcfqspi_runtime_suspend(struct device *dev)
523 524
524static int mcfqspi_runtime_resume(struct device *dev) 525static int mcfqspi_runtime_resume(struct device *dev)
525{ 526{
526 struct mcfqspi *mcfqspi = dev_get_drvdata(dev); 527 struct spi_master *master = dev_get_drvdata(dev);
528 struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
527 529
528 clk_enable(mcfqspi->clk); 530 clk_enable(mcfqspi->clk);
529 531
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index ec79f726672a..a25392065d9b 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -420,7 +420,6 @@ static int dspi_suspend(struct device *dev)
420 420
421static int dspi_resume(struct device *dev) 421static int dspi_resume(struct device *dev)
422{ 422{
423
424 struct spi_master *master = dev_get_drvdata(dev); 423 struct spi_master *master = dev_get_drvdata(dev);
425 struct fsl_dspi *dspi = spi_master_get_devdata(master); 424 struct fsl_dspi *dspi = spi_master_get_devdata(master);
426 425
@@ -504,7 +503,7 @@ static int dspi_probe(struct platform_device *pdev)
504 clk_prepare_enable(dspi->clk); 503 clk_prepare_enable(dspi->clk);
505 504
506 init_waitqueue_head(&dspi->waitq); 505 init_waitqueue_head(&dspi->waitq);
507 platform_set_drvdata(pdev, dspi); 506 platform_set_drvdata(pdev, master);
508 507
509 ret = spi_bitbang_start(&dspi->bitbang); 508 ret = spi_bitbang_start(&dspi->bitbang);
510 if (ret != 0) { 509 if (ret != 0) {
@@ -525,7 +524,8 @@ out_master_put:
525 524
526static int dspi_remove(struct platform_device *pdev) 525static int dspi_remove(struct platform_device *pdev)
527{ 526{
528 struct fsl_dspi *dspi = platform_get_drvdata(pdev); 527 struct spi_master *master = platform_get_drvdata(pdev);
528 struct fsl_dspi *dspi = spi_master_get_devdata(master);
529 529
530 /* Disconnect from the SPI framework */ 530 /* Disconnect from the SPI framework */
531 spi_bitbang_stop(&dspi->bitbang); 531 spi_bitbang_stop(&dspi->bitbang);
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index a5474ef9d2a0..47f15d97e7fa 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -948,8 +948,8 @@ static int spi_imx_remove(struct platform_device *pdev)
948 spi_bitbang_stop(&spi_imx->bitbang); 948 spi_bitbang_stop(&spi_imx->bitbang);
949 949
950 writel(0, spi_imx->base + MXC_CSPICTRL); 950 writel(0, spi_imx->base + MXC_CSPICTRL);
951 clk_disable_unprepare(spi_imx->clk_ipg); 951 clk_unprepare(spi_imx->clk_ipg);
952 clk_disable_unprepare(spi_imx->clk_per); 952 clk_unprepare(spi_imx->clk_per);
953 spi_master_put(master); 953 spi_master_put(master);
954 954
955 return 0; 955 return 0;
diff --git a/drivers/spi/spi-nuc900.c b/drivers/spi/spi-nuc900.c
index 50406306bc20..bae97ffec4b9 100644
--- a/drivers/spi/spi-nuc900.c
+++ b/drivers/spi/spi-nuc900.c
@@ -361,6 +361,8 @@ static int nuc900_spi_probe(struct platform_device *pdev)
361 init_completion(&hw->done); 361 init_completion(&hw->done);
362 362
363 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 363 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
364 if (hw->pdata->lsb)
365 master->mode_bits |= SPI_LSB_FIRST;
364 master->num_chipselect = hw->pdata->num_cs; 366 master->num_chipselect = hw->pdata->num_cs;
365 master->bus_num = hw->pdata->bus_num; 367 master->bus_num = hw->pdata->bus_num;
366 hw->bitbang.master = hw->master; 368 hw->bitbang.master = hw->master;
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index 2e7f38c7a961..88eb57e858b3 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -915,7 +915,7 @@ static void pch_spi_request_dma(struct pch_spi_data *data, int bpw)
915 /* Set Tx DMA */ 915 /* Set Tx DMA */
916 param = &dma->param_tx; 916 param = &dma->param_tx;
917 param->dma_dev = &dma_dev->dev; 917 param->dma_dev = &dma_dev->dev;
918 param->chan_id = data->master->bus_num * 2; /* Tx = 0, 2 */ 918 param->chan_id = data->ch * 2; /* Tx = 0, 2 */;
919 param->tx_reg = data->io_base_addr + PCH_SPDWR; 919 param->tx_reg = data->io_base_addr + PCH_SPDWR;
920 param->width = width; 920 param->width = width;
921 chan = dma_request_channel(mask, pch_spi_filter, param); 921 chan = dma_request_channel(mask, pch_spi_filter, param);
@@ -930,7 +930,7 @@ static void pch_spi_request_dma(struct pch_spi_data *data, int bpw)
930 /* Set Rx DMA */ 930 /* Set Rx DMA */
931 param = &dma->param_rx; 931 param = &dma->param_rx;
932 param->dma_dev = &dma_dev->dev; 932 param->dma_dev = &dma_dev->dev;
933 param->chan_id = data->master->bus_num * 2 + 1; /* Rx = Tx + 1 */ 933 param->chan_id = data->ch * 2 + 1; /* Rx = Tx + 1 */;
934 param->rx_reg = data->io_base_addr + PCH_SPDRR; 934 param->rx_reg = data->io_base_addr + PCH_SPDRR;
935 param->width = width; 935 param->width = width;
936 chan = dma_request_channel(mask, pch_spi_filter, param); 936 chan = dma_request_channel(mask, pch_spi_filter, param);
@@ -1452,6 +1452,11 @@ static int pch_spi_pd_probe(struct platform_device *plat_dev)
1452 1452
1453 pch_spi_set_master_mode(master); 1453 pch_spi_set_master_mode(master);
1454 1454
1455 if (use_dma) {
1456 dev_info(&plat_dev->dev, "Use DMA for data transfers\n");
1457 pch_alloc_dma_buf(board_dat, data);
1458 }
1459
1455 ret = spi_register_master(master); 1460 ret = spi_register_master(master);
1456 if (ret != 0) { 1461 if (ret != 0) {
1457 dev_err(&plat_dev->dev, 1462 dev_err(&plat_dev->dev,
@@ -1459,14 +1464,10 @@ static int pch_spi_pd_probe(struct platform_device *plat_dev)
1459 goto err_spi_register_master; 1464 goto err_spi_register_master;
1460 } 1465 }
1461 1466
1462 if (use_dma) {
1463 dev_info(&plat_dev->dev, "Use DMA for data transfers\n");
1464 pch_alloc_dma_buf(board_dat, data);
1465 }
1466
1467 return 0; 1467 return 0;
1468 1468
1469err_spi_register_master: 1469err_spi_register_master:
1470 pch_free_dma_buf(board_dat, data);
1470 free_irq(board_dat->pdev->irq, data); 1471 free_irq(board_dat->pdev->irq, data);
1471err_request_irq: 1472err_request_irq:
1472 pch_spi_free_resources(board_dat, data); 1473 pch_spi_free_resources(board_dat, data);
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 23756b0f9036..d0b28bba38be 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -755,9 +755,7 @@ static void spi_pump_messages(struct kthread_work *work)
755 ret = master->transfer_one_message(master, master->cur_msg); 755 ret = master->transfer_one_message(master, master->cur_msg);
756 if (ret) { 756 if (ret) {
757 dev_err(&master->dev, 757 dev_err(&master->dev,
758 "failed to transfer one message from queue: %d\n", ret); 758 "failed to transfer one message from queue\n");
759 master->cur_msg->status = ret;
760 spi_finalize_current_message(master);
761 return; 759 return;
762 } 760 }
763} 761}
diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 23948f167012..713a97226787 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -295,21 +295,29 @@ static ssize_t ashmem_read(struct file *file, char __user *buf,
295 295
296 /* If size is not set, or set to 0, always return EOF. */ 296 /* If size is not set, or set to 0, always return EOF. */
297 if (asma->size == 0) 297 if (asma->size == 0)
298 goto out; 298 goto out_unlock;
299 299
300 if (!asma->file) { 300 if (!asma->file) {
301 ret = -EBADF; 301 ret = -EBADF;
302 goto out; 302 goto out_unlock;
303 } 303 }
304 304
305 ret = asma->file->f_op->read(asma->file, buf, len, pos); 305 mutex_unlock(&ashmem_mutex);
306 if (ret < 0)
307 goto out;
308 306
309 /** Update backing file pos, since f_ops->read() doesn't */ 307 /*
310 asma->file->f_pos = *pos; 308 * asma and asma->file are used outside the lock here. We assume
309 * once asma->file is set it will never be changed, and will not
310 * be destroyed until all references to the file are dropped and
311 * ashmem_release is called.
312 */
313 ret = asma->file->f_op->read(asma->file, buf, len, pos);
314 if (ret >= 0) {
315 /** Update backing file pos, since f_ops->read() doesn't */
316 asma->file->f_pos = *pos;
317 }
318 return ret;
311 319
312out: 320out_unlock:
313 mutex_unlock(&ashmem_mutex); 321 mutex_unlock(&ashmem_mutex);
314 return ret; 322 return ret;
315} 323}
@@ -498,6 +506,7 @@ out:
498 506
499static int set_name(struct ashmem_area *asma, void __user *name) 507static int set_name(struct ashmem_area *asma, void __user *name)
500{ 508{
509 int len;
501 int ret = 0; 510 int ret = 0;
502 char local_name[ASHMEM_NAME_LEN]; 511 char local_name[ASHMEM_NAME_LEN];
503 512
@@ -510,21 +519,19 @@ static int set_name(struct ashmem_area *asma, void __user *name)
510 * variable that does not need protection and later copy the local 519 * variable that does not need protection and later copy the local
511 * variable to the structure member with lock held. 520 * variable to the structure member with lock held.
512 */ 521 */
513 if (copy_from_user(local_name, name, ASHMEM_NAME_LEN)) 522 len = strncpy_from_user(local_name, name, ASHMEM_NAME_LEN);
514 return -EFAULT; 523 if (len < 0)
515 524 return len;
525 if (len == ASHMEM_NAME_LEN)
526 local_name[ASHMEM_NAME_LEN - 1] = '\0';
516 mutex_lock(&ashmem_mutex); 527 mutex_lock(&ashmem_mutex);
517 /* cannot change an existing mapping's name */ 528 /* cannot change an existing mapping's name */
518 if (unlikely(asma->file)) { 529 if (unlikely(asma->file))
519 ret = -EINVAL; 530 ret = -EINVAL;
520 goto out; 531 else
521 } 532 strcpy(asma->name + ASHMEM_NAME_PREFIX_LEN, local_name);
522 memcpy(asma->name + ASHMEM_NAME_PREFIX_LEN,
523 local_name, ASHMEM_NAME_LEN);
524 asma->name[ASHMEM_FULL_NAME_LEN-1] = '\0';
525out:
526 mutex_unlock(&ashmem_mutex);
527 533
534 mutex_unlock(&ashmem_mutex);
528 return ret; 535 return ret;
529} 536}
530 537
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
index eaec1dab7fe4..1432d956769c 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/staging/android/binder.c
@@ -2904,7 +2904,7 @@ static int binder_node_release(struct binder_node *node, int refs)
2904 refs++; 2904 refs++;
2905 2905
2906 if (!ref->death) 2906 if (!ref->death)
2907 goto out; 2907 continue;
2908 2908
2909 death++; 2909 death++;
2910 2910
@@ -2917,7 +2917,6 @@ static int binder_node_release(struct binder_node *node, int refs)
2917 BUG(); 2917 BUG();
2918 } 2918 }
2919 2919
2920out:
2921 binder_debug(BINDER_DEBUG_DEAD_BINDER, 2920 binder_debug(BINDER_DEBUG_DEAD_BINDER,
2922 "node %d now dead, refs %d, death %d\n", 2921 "node %d now dead, refs %d, death %d\n",
2923 node->debug_id, refs, death); 2922 node->debug_id, refs, death);
diff --git a/drivers/staging/android/ion/compat_ion.c b/drivers/staging/android/ion/compat_ion.c
index af6cd370b30f..ee3a7380e53b 100644
--- a/drivers/staging/android/ion/compat_ion.c
+++ b/drivers/staging/android/ion/compat_ion.c
@@ -35,9 +35,14 @@ struct compat_ion_custom_data {
35 compat_ulong_t arg; 35 compat_ulong_t arg;
36}; 36};
37 37
38struct compat_ion_handle_data {
39 compat_int_t handle;
40};
41
38#define COMPAT_ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ 42#define COMPAT_ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
39 struct compat_ion_allocation_data) 43 struct compat_ion_allocation_data)
40#define COMPAT_ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) 44#define COMPAT_ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, \
45 struct compat_ion_handle_data)
41#define COMPAT_ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, \ 46#define COMPAT_ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, \
42 struct compat_ion_custom_data) 47 struct compat_ion_custom_data)
43 48
@@ -64,6 +69,19 @@ static int compat_get_ion_allocation_data(
64 return err; 69 return err;
65} 70}
66 71
72static int compat_get_ion_handle_data(
73 struct compat_ion_handle_data __user *data32,
74 struct ion_handle_data __user *data)
75{
76 compat_int_t i;
77 int err;
78
79 err = get_user(i, &data32->handle);
80 err |= put_user(i, &data->handle);
81
82 return err;
83}
84
67static int compat_put_ion_allocation_data( 85static int compat_put_ion_allocation_data(
68 struct compat_ion_allocation_data __user *data32, 86 struct compat_ion_allocation_data __user *data32,
69 struct ion_allocation_data __user *data) 87 struct ion_allocation_data __user *data)
@@ -132,8 +150,8 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
132 } 150 }
133 case COMPAT_ION_IOC_FREE: 151 case COMPAT_ION_IOC_FREE:
134 { 152 {
135 struct compat_ion_allocation_data __user *data32; 153 struct compat_ion_handle_data __user *data32;
136 struct ion_allocation_data __user *data; 154 struct ion_handle_data __user *data;
137 int err; 155 int err;
138 156
139 data32 = compat_ptr(arg); 157 data32 = compat_ptr(arg);
@@ -141,7 +159,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
141 if (data == NULL) 159 if (data == NULL)
142 return -EFAULT; 160 return -EFAULT;
143 161
144 err = compat_get_ion_allocation_data(data32, data); 162 err = compat_get_ion_handle_data(data32, data);
145 if (err) 163 if (err)
146 return err; 164 return err;
147 165
diff --git a/drivers/staging/android/ion/ion_dummy_driver.c b/drivers/staging/android/ion/ion_dummy_driver.c
index 55b2002753f2..01cdc8aee898 100644
--- a/drivers/staging/android/ion/ion_dummy_driver.c
+++ b/drivers/staging/android/ion/ion_dummy_driver.c
@@ -17,9 +17,11 @@
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/init.h>
20#include <linux/bootmem.h> 21#include <linux/bootmem.h>
21#include <linux/memblock.h> 22#include <linux/memblock.h>
22#include <linux/sizes.h> 23#include <linux/sizes.h>
24#include <linux/io.h>
23#include "ion.h" 25#include "ion.h"
24#include "ion_priv.h" 26#include "ion_priv.h"
25 27
@@ -57,7 +59,7 @@ struct ion_platform_heap dummy_heaps[] = {
57}; 59};
58 60
59struct ion_platform_data dummy_ion_pdata = { 61struct ion_platform_data dummy_ion_pdata = {
60 .nr = 4, 62 .nr = ARRAY_SIZE(dummy_heaps),
61 .heaps = dummy_heaps, 63 .heaps = dummy_heaps,
62}; 64};
63 65
@@ -69,7 +71,7 @@ static int __init ion_dummy_init(void)
69 heaps = kzalloc(sizeof(struct ion_heap *) * dummy_ion_pdata.nr, 71 heaps = kzalloc(sizeof(struct ion_heap *) * dummy_ion_pdata.nr,
70 GFP_KERNEL); 72 GFP_KERNEL);
71 if (!heaps) 73 if (!heaps)
72 return PTR_ERR(heaps); 74 return -ENOMEM;
73 75
74 76
75 /* Allocate a dummy carveout heap */ 77 /* Allocate a dummy carveout heap */
@@ -128,6 +130,7 @@ err:
128 } 130 }
129 return err; 131 return err;
130} 132}
133device_initcall(ion_dummy_init);
131 134
132static void __exit ion_dummy_exit(void) 135static void __exit ion_dummy_exit(void)
133{ 136{
@@ -152,7 +155,4 @@ static void __exit ion_dummy_exit(void)
152 155
153 return; 156 return;
154} 157}
155 158__exitcall(ion_dummy_exit);
156module_init(ion_dummy_init);
157module_exit(ion_dummy_exit);
158
diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c
index 296c74f98dc0..37e64d51394c 100644
--- a/drivers/staging/android/ion/ion_heap.c
+++ b/drivers/staging/android/ion/ion_heap.c
@@ -243,12 +243,12 @@ int ion_heap_init_deferred_free(struct ion_heap *heap)
243 init_waitqueue_head(&heap->waitqueue); 243 init_waitqueue_head(&heap->waitqueue);
244 heap->task = kthread_run(ion_heap_deferred_free, heap, 244 heap->task = kthread_run(ion_heap_deferred_free, heap,
245 "%s", heap->name); 245 "%s", heap->name);
246 sched_setscheduler(heap->task, SCHED_IDLE, &param);
247 if (IS_ERR(heap->task)) { 246 if (IS_ERR(heap->task)) {
248 pr_err("%s: creating thread for deferred free failed\n", 247 pr_err("%s: creating thread for deferred free failed\n",
249 __func__); 248 __func__);
250 return PTR_RET(heap->task); 249 return PTR_RET(heap->task);
251 } 250 }
251 sched_setscheduler(heap->task, SCHED_IDLE, &param);
252 return 0; 252 return 0;
253} 253}
254 254
diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h
index d98673981cc4..fc2e4fccf69d 100644
--- a/drivers/staging/android/ion/ion_priv.h
+++ b/drivers/staging/android/ion/ion_priv.h
@@ -17,6 +17,7 @@
17#ifndef _ION_PRIV_H 17#ifndef _ION_PRIV_H
18#define _ION_PRIV_H 18#define _ION_PRIV_H
19 19
20#include <linux/device.h>
20#include <linux/dma-direction.h> 21#include <linux/dma-direction.h>
21#include <linux/kref.h> 22#include <linux/kref.h>
22#include <linux/mm_types.h> 23#include <linux/mm_types.h>
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index 7f0729130d65..9849f3963e75 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -124,6 +124,7 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap,
124 124
125 info->page = page; 125 info->page = page;
126 info->order = orders[i]; 126 info->order = orders[i];
127 INIT_LIST_HEAD(&info->list);
127 return info; 128 return info;
128 } 129 }
129 kfree(info); 130 kfree(info);
@@ -145,12 +146,15 @@ static int ion_system_heap_allocate(struct ion_heap *heap,
145 struct list_head pages; 146 struct list_head pages;
146 struct page_info *info, *tmp_info; 147 struct page_info *info, *tmp_info;
147 int i = 0; 148 int i = 0;
148 long size_remaining = PAGE_ALIGN(size); 149 unsigned long size_remaining = PAGE_ALIGN(size);
149 unsigned int max_order = orders[0]; 150 unsigned int max_order = orders[0];
150 151
151 if (align > PAGE_SIZE) 152 if (align > PAGE_SIZE)
152 return -EINVAL; 153 return -EINVAL;
153 154
155 if (size / PAGE_SIZE > totalram_pages / 2)
156 return -ENOMEM;
157
154 INIT_LIST_HEAD(&pages); 158 INIT_LIST_HEAD(&pages);
155 while (size_remaining > 0) { 159 while (size_remaining > 0) {
156 info = alloc_largest_available(sys_heap, buffer, size_remaining, 160 info = alloc_largest_available(sys_heap, buffer, size_remaining,
diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h
index 585040be5f18..5aaf71d6974b 100644
--- a/drivers/staging/android/sw_sync.h
+++ b/drivers/staging/android/sw_sync.h
@@ -35,10 +35,27 @@ struct sw_sync_pt {
35 u32 value; 35 u32 value;
36}; 36};
37 37
38#if IS_ENABLED(CONFIG_SW_SYNC)
38struct sw_sync_timeline *sw_sync_timeline_create(const char *name); 39struct sw_sync_timeline *sw_sync_timeline_create(const char *name);
39void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc); 40void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc);
40 41
41struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value); 42struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value);
43#else
44static inline struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
45{
46 return NULL;
47}
48
49static inline void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
50{
51}
52
53static inline struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj,
54 u32 value)
55{
56 return NULL;
57}
58#endif /* IS_ENABLED(CONFIG_SW_SYNC) */
42 59
43#endif /* __KERNEL __ */ 60#endif /* __KERNEL __ */
44 61
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 38e5d3b5ed9b..3d05f662110b 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -79,27 +79,27 @@ static void sync_timeline_free(struct kref *kref)
79 container_of(kref, struct sync_timeline, kref); 79 container_of(kref, struct sync_timeline, kref);
80 unsigned long flags; 80 unsigned long flags;
81 81
82 if (obj->ops->release_obj)
83 obj->ops->release_obj(obj);
84
85 spin_lock_irqsave(&sync_timeline_list_lock, flags); 82 spin_lock_irqsave(&sync_timeline_list_lock, flags);
86 list_del(&obj->sync_timeline_list); 83 list_del(&obj->sync_timeline_list);
87 spin_unlock_irqrestore(&sync_timeline_list_lock, flags); 84 spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
88 85
86 if (obj->ops->release_obj)
87 obj->ops->release_obj(obj);
88
89 kfree(obj); 89 kfree(obj);
90} 90}
91 91
92void sync_timeline_destroy(struct sync_timeline *obj) 92void sync_timeline_destroy(struct sync_timeline *obj)
93{ 93{
94 obj->destroyed = true; 94 obj->destroyed = true;
95 smp_wmb();
95 96
96 /* 97 /*
97 * If this is not the last reference, signal any children 98 * signal any children that their parent is going away.
98 * that their parent is going away.
99 */ 99 */
100 sync_timeline_signal(obj);
100 101
101 if (!kref_put(&obj->kref, sync_timeline_free)) 102 kref_put(&obj->kref, sync_timeline_free);
102 sync_timeline_signal(obj);
103} 103}
104EXPORT_SYMBOL(sync_timeline_destroy); 104EXPORT_SYMBOL(sync_timeline_destroy);
105 105
diff --git a/drivers/staging/bcm/Bcmnet.c b/drivers/staging/bcm/Bcmnet.c
index 8dfdd2732bdc..95a2358267ba 100644
--- a/drivers/staging/bcm/Bcmnet.c
+++ b/drivers/staging/bcm/Bcmnet.c
@@ -40,7 +40,7 @@ static INT bcm_close(struct net_device *dev)
40} 40}
41 41
42static u16 bcm_select_queue(struct net_device *dev, struct sk_buff *skb, 42static u16 bcm_select_queue(struct net_device *dev, struct sk_buff *skb,
43 void *accel_priv) 43 void *accel_priv, select_queue_fallback_t fallback)
44{ 44{
45 return ClassifyPacket(netdev_priv(dev), skb); 45 return ClassifyPacket(netdev_priv(dev), skb);
46} 46}
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 246080316c90..5b15033a94bf 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -616,8 +616,6 @@ int comedi_auto_config(struct device *hardware_device,
616 ret = driver->auto_attach(dev, context); 616 ret = driver->auto_attach(dev, context);
617 if (ret >= 0) 617 if (ret >= 0)
618 ret = comedi_device_postconfig(dev); 618 ret = comedi_device_postconfig(dev);
619 if (ret < 0)
620 comedi_device_detach(dev);
621 mutex_unlock(&dev->mutex); 619 mutex_unlock(&dev->mutex);
622 620
623 if (ret < 0) { 621 if (ret < 0) {
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index 593676cf706a..d9ad2c0fdda2 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -494,6 +494,7 @@ static int pci171x_insn_write_ao(struct comedi_device *dev,
494 struct comedi_insn *insn, unsigned int *data) 494 struct comedi_insn *insn, unsigned int *data)
495{ 495{
496 struct pci1710_private *devpriv = dev->private; 496 struct pci1710_private *devpriv = dev->private;
497 unsigned int val;
497 int n, chan, range, ofs; 498 int n, chan, range, ofs;
498 499
499 chan = CR_CHAN(insn->chanspec); 500 chan = CR_CHAN(insn->chanspec);
@@ -509,11 +510,14 @@ static int pci171x_insn_write_ao(struct comedi_device *dev,
509 outw(devpriv->da_ranges, dev->iobase + PCI171x_DAREF); 510 outw(devpriv->da_ranges, dev->iobase + PCI171x_DAREF);
510 ofs = PCI171x_DA1; 511 ofs = PCI171x_DA1;
511 } 512 }
513 val = devpriv->ao_data[chan];
512 514
513 for (n = 0; n < insn->n; n++) 515 for (n = 0; n < insn->n; n++) {
514 outw(data[n], dev->iobase + ofs); 516 val = data[n];
517 outw(val, dev->iobase + ofs);
518 }
515 519
516 devpriv->ao_data[chan] = data[n]; 520 devpriv->ao_data[chan] = val;
517 521
518 return n; 522 return n;
519 523
@@ -679,6 +683,7 @@ static int pci1720_insn_write_ao(struct comedi_device *dev,
679 struct comedi_insn *insn, unsigned int *data) 683 struct comedi_insn *insn, unsigned int *data)
680{ 684{
681 struct pci1710_private *devpriv = dev->private; 685 struct pci1710_private *devpriv = dev->private;
686 unsigned int val;
682 int n, rangereg, chan; 687 int n, rangereg, chan;
683 688
684 chan = CR_CHAN(insn->chanspec); 689 chan = CR_CHAN(insn->chanspec);
@@ -688,13 +693,15 @@ static int pci1720_insn_write_ao(struct comedi_device *dev,
688 outb(rangereg, dev->iobase + PCI1720_RANGE); 693 outb(rangereg, dev->iobase + PCI1720_RANGE);
689 devpriv->da_ranges = rangereg; 694 devpriv->da_ranges = rangereg;
690 } 695 }
696 val = devpriv->ao_data[chan];
691 697
692 for (n = 0; n < insn->n; n++) { 698 for (n = 0; n < insn->n; n++) {
693 outw(data[n], dev->iobase + PCI1720_DA0 + (chan << 1)); 699 val = data[n];
700 outw(val, dev->iobase + PCI1720_DA0 + (chan << 1));
694 outb(0, dev->iobase + PCI1720_SYNCOUT); /* update outputs */ 701 outb(0, dev->iobase + PCI1720_SYNCOUT); /* update outputs */
695 } 702 }
696 703
697 devpriv->ao_data[chan] = data[n]; 704 devpriv->ao_data[chan] = val;
698 705
699 return n; 706 return n;
700} 707}
diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c
index 3beeb1254152..88c60b6020c4 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -48,6 +48,7 @@
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/fcntl.h> 49#include <linux/fcntl.h>
50#include <linux/compiler.h> 50#include <linux/compiler.h>
51#include <asm/unaligned.h>
51 52
52#include "comedi_fc.h" 53#include "comedi_fc.h"
53#include "../comedidev.h" 54#include "../comedidev.h"
@@ -792,7 +793,8 @@ static int usbduxsigma_ai_insn_read(struct comedi_device *dev,
792 } 793 }
793 794
794 /* 32 bits big endian from the A/D converter */ 795 /* 32 bits big endian from the A/D converter */
795 val = be32_to_cpu(*((uint32_t *)((devpriv->insn_buf) + 1))); 796 val = be32_to_cpu(get_unaligned((uint32_t
797 *)(devpriv->insn_buf + 1)));
796 val &= 0x00ffffff; /* strip status byte */ 798 val &= 0x00ffffff; /* strip status byte */
797 val ^= 0x00800000; /* convert to unsigned */ 799 val ^= 0x00800000; /* convert to unsigned */
798 800
@@ -1357,7 +1359,7 @@ static int usbduxsigma_getstatusinfo(struct comedi_device *dev, int chan)
1357 return ret; 1359 return ret;
1358 1360
1359 /* 32 bits big endian from the A/D converter */ 1361 /* 32 bits big endian from the A/D converter */
1360 val = be32_to_cpu(*((uint32_t *)((devpriv->insn_buf)+1))); 1362 val = be32_to_cpu(get_unaligned((uint32_t *)(devpriv->insn_buf + 1)));
1361 val &= 0x00ffffff; /* strip status byte */ 1363 val &= 0x00ffffff; /* strip status byte */
1362 val ^= 0x00800000; /* convert to unsigned */ 1364 val ^= 0x00800000; /* convert to unsigned */
1363 1365
diff --git a/drivers/staging/cxt1e1/linux.c b/drivers/staging/cxt1e1/linux.c
index 4a08e16e42f7..79206cb3fb94 100644
--- a/drivers/staging/cxt1e1/linux.c
+++ b/drivers/staging/cxt1e1/linux.c
@@ -866,6 +866,8 @@ c4_ioctl (struct net_device *ndev, struct ifreq *ifr, int cmd)
866 _IOC_SIZE (iocmd)); 866 _IOC_SIZE (iocmd));
867#endif 867#endif
868 iolen = _IOC_SIZE (iocmd); 868 iolen = _IOC_SIZE (iocmd);
869 if (iolen > sizeof(arg))
870 return -EFAULT;
869 data = ifr->ifr_data + sizeof (iocmd); 871 data = ifr->ifr_data + sizeof (iocmd);
870 if (copy_from_user (&arg, data, iolen)) 872 if (copy_from_user (&arg, data, iolen))
871 return -EFAULT; 873 return -EFAULT;
diff --git a/drivers/staging/dgrp/dgrp_net_ops.c b/drivers/staging/dgrp/dgrp_net_ops.c
index 1f61b89eca44..33ac7fb88cbd 100644
--- a/drivers/staging/dgrp/dgrp_net_ops.c
+++ b/drivers/staging/dgrp/dgrp_net_ops.c
@@ -2232,177 +2232,6 @@ done:
2232 return rtn; 2232 return rtn;
2233} 2233}
2234 2234
2235/*
2236 * Common Packet Handling code
2237 */
2238
2239static void handle_data_in_packet(struct nd_struct *nd, struct ch_struct *ch,
2240 long dlen, long plen, int n1, u8 *dbuf)
2241{
2242 char *error;
2243 long n;
2244 long remain;
2245 u8 *buf;
2246 u8 *b;
2247
2248 remain = nd->nd_remain;
2249 nd->nd_tx_work = 1;
2250
2251 /*
2252 * Otherwise data should appear only when we are
2253 * in the CS_READY state.
2254 */
2255
2256 if (ch->ch_state < CS_READY) {
2257 error = "Data received before RWIN established";
2258 nd->nd_remain = 0;
2259 nd->nd_state = NS_SEND_ERROR;
2260 nd->nd_error = error;
2261 }
2262
2263 /*
2264 * Assure that the data received is within the
2265 * allowable window.
2266 */
2267
2268 n = (ch->ch_s_rwin - ch->ch_s_rin) & 0xffff;
2269
2270 if (dlen > n) {
2271 error = "Receive data overrun";
2272 nd->nd_remain = 0;
2273 nd->nd_state = NS_SEND_ERROR;
2274 nd->nd_error = error;
2275 }
2276
2277 /*
2278 * If we received 3 or less characters,
2279 * assume it is a human typing, and set RTIME
2280 * to 10 milliseconds.
2281 *
2282 * If we receive 10 or more characters,
2283 * assume its not a human typing, and set RTIME
2284 * to 100 milliseconds.
2285 */
2286
2287 if (ch->ch_edelay != DGRP_RTIME) {
2288 if (ch->ch_rtime != ch->ch_edelay) {
2289 ch->ch_rtime = ch->ch_edelay;
2290 ch->ch_flag |= CH_PARAM;
2291 }
2292 } else if (dlen <= 3) {
2293 if (ch->ch_rtime != 10) {
2294 ch->ch_rtime = 10;
2295 ch->ch_flag |= CH_PARAM;
2296 }
2297 } else {
2298 if (ch->ch_rtime != DGRP_RTIME) {
2299 ch->ch_rtime = DGRP_RTIME;
2300 ch->ch_flag |= CH_PARAM;
2301 }
2302 }
2303
2304 /*
2305 * If a portion of the packet is outside the
2306 * buffer, shorten the effective length of the
2307 * data packet to be the amount of data received.
2308 */
2309
2310 if (remain < plen)
2311 dlen -= plen - remain;
2312
2313 /*
2314 * Detect if receive flush is now complete.
2315 */
2316
2317 if ((ch->ch_flag & CH_RX_FLUSH) != 0 &&
2318 ((ch->ch_flush_seq - nd->nd_seq_out) & SEQ_MASK) >=
2319 ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) {
2320 ch->ch_flag &= ~CH_RX_FLUSH;
2321 }
2322
2323 /*
2324 * If we are ready to receive, move the data into
2325 * the receive buffer.
2326 */
2327
2328 ch->ch_s_rin = (ch->ch_s_rin + dlen) & 0xffff;
2329
2330 if (ch->ch_state == CS_READY &&
2331 (ch->ch_tun.un_open_count != 0) &&
2332 (ch->ch_tun.un_flag & UN_CLOSING) == 0 &&
2333 (ch->ch_cflag & CF_CREAD) != 0 &&
2334 (ch->ch_flag & (CH_BAUD0 | CH_RX_FLUSH)) == 0 &&
2335 (ch->ch_send & RR_RX_FLUSH) == 0) {
2336
2337 if (ch->ch_rin + dlen >= RBUF_MAX) {
2338 n = RBUF_MAX - ch->ch_rin;
2339
2340 memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, n);
2341
2342 ch->ch_rin = 0;
2343 dbuf += n;
2344 dlen -= n;
2345 }
2346
2347 memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, dlen);
2348
2349 ch->ch_rin += dlen;
2350
2351
2352 /*
2353 * If we are not in fastcook mode, or
2354 * if there is a fastcook thread
2355 * waiting for data, send the data to
2356 * the line discipline.
2357 */
2358
2359 if ((ch->ch_flag & CH_FAST_READ) == 0 ||
2360 ch->ch_inwait != 0) {
2361 dgrp_input(ch);
2362 }
2363
2364 /*
2365 * If there is a read thread waiting
2366 * in select, and we are in fastcook
2367 * mode, wake him up.
2368 */
2369
2370 if (waitqueue_active(&ch->ch_tun.un_tty->read_wait) &&
2371 (ch->ch_flag & CH_FAST_READ) != 0)
2372 wake_up_interruptible(&ch->ch_tun.un_tty->read_wait);
2373
2374 /*
2375 * Wake any thread waiting in the
2376 * fastcook loop.
2377 */
2378
2379 if ((ch->ch_flag & CH_INPUT) != 0) {
2380 ch->ch_flag &= ~CH_INPUT;
2381 wake_up_interruptible(&ch->ch_flag_wait);
2382 }
2383 }
2384
2385 /*
2386 * Fabricate and insert a data packet header to
2387 * preced the remaining data when it comes in.
2388 */
2389
2390 if (remain < plen) {
2391 dlen = plen - remain;
2392 b = buf;
2393
2394 b[0] = 0x90 + n1;
2395 put_unaligned_be16(dlen, b + 1);
2396
2397 remain = 3;
2398 if (remain > 0 && b != buf)
2399 memcpy(buf, b, remain);
2400
2401 nd->nd_remain = remain;
2402 return;
2403 }
2404}
2405
2406/** 2235/**
2407 * dgrp_receive() -- decode data packets received from the remote PortServer. 2236 * dgrp_receive() -- decode data packets received from the remote PortServer.
2408 * @nd: pointer to a node structure 2237 * @nd: pointer to a node structure
@@ -2477,8 +2306,7 @@ static void dgrp_receive(struct nd_struct *nd)
2477 plen = dlen + 1; 2306 plen = dlen + 1;
2478 2307
2479 dbuf = b + 1; 2308 dbuf = b + 1;
2480 handle_data_in_packet(nd, ch, dlen, plen, n1, dbuf); 2309 goto data;
2481 break;
2482 2310
2483 /* 2311 /*
2484 * Process 2-byte header data packet. 2312 * Process 2-byte header data packet.
@@ -2492,8 +2320,7 @@ static void dgrp_receive(struct nd_struct *nd)
2492 plen = dlen + 2; 2320 plen = dlen + 2;
2493 2321
2494 dbuf = b + 2; 2322 dbuf = b + 2;
2495 handle_data_in_packet(nd, ch, dlen, plen, n1, dbuf); 2323 goto data;
2496 break;
2497 2324
2498 /* 2325 /*
2499 * Process 3-byte header data packet. 2326 * Process 3-byte header data packet.
@@ -2508,6 +2335,159 @@ static void dgrp_receive(struct nd_struct *nd)
2508 2335
2509 dbuf = b + 3; 2336 dbuf = b + 3;
2510 2337
2338 /*
2339 * Common packet handling code.
2340 */
2341
2342data:
2343 nd->nd_tx_work = 1;
2344
2345 /*
2346 * Otherwise data should appear only when we are
2347 * in the CS_READY state.
2348 */
2349
2350 if (ch->ch_state < CS_READY) {
2351 error = "Data received before RWIN established";
2352 goto prot_error;
2353 }
2354
2355 /*
2356 * Assure that the data received is within the
2357 * allowable window.
2358 */
2359
2360 n = (ch->ch_s_rwin - ch->ch_s_rin) & 0xffff;
2361
2362 if (dlen > n) {
2363 error = "Receive data overrun";
2364 goto prot_error;
2365 }
2366
2367 /*
2368 * If we received 3 or less characters,
2369 * assume it is a human typing, and set RTIME
2370 * to 10 milliseconds.
2371 *
2372 * If we receive 10 or more characters,
2373 * assume its not a human typing, and set RTIME
2374 * to 100 milliseconds.
2375 */
2376
2377 if (ch->ch_edelay != DGRP_RTIME) {
2378 if (ch->ch_rtime != ch->ch_edelay) {
2379 ch->ch_rtime = ch->ch_edelay;
2380 ch->ch_flag |= CH_PARAM;
2381 }
2382 } else if (dlen <= 3) {
2383 if (ch->ch_rtime != 10) {
2384 ch->ch_rtime = 10;
2385 ch->ch_flag |= CH_PARAM;
2386 }
2387 } else {
2388 if (ch->ch_rtime != DGRP_RTIME) {
2389 ch->ch_rtime = DGRP_RTIME;
2390 ch->ch_flag |= CH_PARAM;
2391 }
2392 }
2393
2394 /*
2395 * If a portion of the packet is outside the
2396 * buffer, shorten the effective length of the
2397 * data packet to be the amount of data received.
2398 */
2399
2400 if (remain < plen)
2401 dlen -= plen - remain;
2402
2403 /*
2404 * Detect if receive flush is now complete.
2405 */
2406
2407 if ((ch->ch_flag & CH_RX_FLUSH) != 0 &&
2408 ((ch->ch_flush_seq - nd->nd_seq_out) & SEQ_MASK) >=
2409 ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) {
2410 ch->ch_flag &= ~CH_RX_FLUSH;
2411 }
2412
2413 /*
2414 * If we are ready to receive, move the data into
2415 * the receive buffer.
2416 */
2417
2418 ch->ch_s_rin = (ch->ch_s_rin + dlen) & 0xffff;
2419
2420 if (ch->ch_state == CS_READY &&
2421 (ch->ch_tun.un_open_count != 0) &&
2422 (ch->ch_tun.un_flag & UN_CLOSING) == 0 &&
2423 (ch->ch_cflag & CF_CREAD) != 0 &&
2424 (ch->ch_flag & (CH_BAUD0 | CH_RX_FLUSH)) == 0 &&
2425 (ch->ch_send & RR_RX_FLUSH) == 0) {
2426
2427 if (ch->ch_rin + dlen >= RBUF_MAX) {
2428 n = RBUF_MAX - ch->ch_rin;
2429
2430 memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, n);
2431
2432 ch->ch_rin = 0;
2433 dbuf += n;
2434 dlen -= n;
2435 }
2436
2437 memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, dlen);
2438
2439 ch->ch_rin += dlen;
2440
2441
2442 /*
2443 * If we are not in fastcook mode, or
2444 * if there is a fastcook thread
2445 * waiting for data, send the data to
2446 * the line discipline.
2447 */
2448
2449 if ((ch->ch_flag & CH_FAST_READ) == 0 ||
2450 ch->ch_inwait != 0) {
2451 dgrp_input(ch);
2452 }
2453
2454 /*
2455 * If there is a read thread waiting
2456 * in select, and we are in fastcook
2457 * mode, wake him up.
2458 */
2459
2460 if (waitqueue_active(&ch->ch_tun.un_tty->read_wait) &&
2461 (ch->ch_flag & CH_FAST_READ) != 0)
2462 wake_up_interruptible(&ch->ch_tun.un_tty->read_wait);
2463
2464 /*
2465 * Wake any thread waiting in the
2466 * fastcook loop.
2467 */
2468
2469 if ((ch->ch_flag & CH_INPUT) != 0) {
2470 ch->ch_flag &= ~CH_INPUT;
2471
2472 wake_up_interruptible(&ch->ch_flag_wait);
2473 }
2474 }
2475
2476 /*
2477 * Fabricate and insert a data packet header to
2478 * preced the remaining data when it comes in.
2479 */
2480
2481 if (remain < plen) {
2482 dlen = plen - remain;
2483 b = buf;
2484
2485 b[0] = 0x90 + n1;
2486 put_unaligned_be16(dlen, b + 1);
2487
2488 remain = 3;
2489 goto done;
2490 }
2511 break; 2491 break;
2512 2492
2513 /* 2493 /*
diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index 8af136e9c9dc..b22142ee5262 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -2036,6 +2036,13 @@ static void fwserial_auto_connect(struct work_struct *work)
2036 schedule_delayed_work(&peer->connect, CONNECT_RETRY_DELAY); 2036 schedule_delayed_work(&peer->connect, CONNECT_RETRY_DELAY);
2037} 2037}
2038 2038
2039static void fwserial_peer_workfn(struct work_struct *work)
2040{
2041 struct fwtty_peer *peer = to_peer(work, work);
2042
2043 peer->workfn(work);
2044}
2045
2039/** 2046/**
2040 * fwserial_add_peer - add a newly probed 'serial' unit device as a 'peer' 2047 * fwserial_add_peer - add a newly probed 'serial' unit device as a 'peer'
2041 * @serial: aggregate representing the specific fw_card to add the peer to 2048 * @serial: aggregate representing the specific fw_card to add the peer to
@@ -2100,7 +2107,7 @@ static int fwserial_add_peer(struct fw_serial *serial, struct fw_unit *unit)
2100 peer->port = NULL; 2107 peer->port = NULL;
2101 2108
2102 init_timer(&peer->timer); 2109 init_timer(&peer->timer);
2103 INIT_WORK(&peer->work, NULL); 2110 INIT_WORK(&peer->work, fwserial_peer_workfn);
2104 INIT_DELAYED_WORK(&peer->connect, fwserial_auto_connect); 2111 INIT_DELAYED_WORK(&peer->connect, fwserial_auto_connect);
2105 2112
2106 /* associate peer with specific fw_card */ 2113 /* associate peer with specific fw_card */
@@ -2702,7 +2709,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer,
2702 2709
2703 } else { 2710 } else {
2704 peer->work_params.plug_req = pkt->plug_req; 2711 peer->work_params.plug_req = pkt->plug_req;
2705 PREPARE_WORK(&peer->work, fwserial_handle_plug_req); 2712 peer->workfn = fwserial_handle_plug_req;
2706 queue_work(system_unbound_wq, &peer->work); 2713 queue_work(system_unbound_wq, &peer->work);
2707 } 2714 }
2708 break; 2715 break;
@@ -2731,7 +2738,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer,
2731 fwtty_err(&peer->unit, "unplug req: busy\n"); 2738 fwtty_err(&peer->unit, "unplug req: busy\n");
2732 rcode = RCODE_CONFLICT_ERROR; 2739 rcode = RCODE_CONFLICT_ERROR;
2733 } else { 2740 } else {
2734 PREPARE_WORK(&peer->work, fwserial_handle_unplug_req); 2741 peer->workfn = fwserial_handle_unplug_req;
2735 queue_work(system_unbound_wq, &peer->work); 2742 queue_work(system_unbound_wq, &peer->work);
2736 } 2743 }
2737 break; 2744 break;
diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h
index 54f7f9b9b212..98b853d4acbc 100644
--- a/drivers/staging/fwserial/fwserial.h
+++ b/drivers/staging/fwserial/fwserial.h
@@ -91,6 +91,7 @@ struct fwtty_peer {
91 struct rcu_head rcu; 91 struct rcu_head rcu;
92 92
93 spinlock_t lock; 93 spinlock_t lock;
94 work_func_t workfn;
94 struct work_struct work; 95 struct work_struct work;
95 struct peer_work_params work_params; 96 struct peer_work_params work_params;
96 struct timer_list timer; 97 struct timer_list timer;
diff --git a/drivers/staging/gdm72xx/gdm_usb.c b/drivers/staging/gdm72xx/gdm_usb.c
index f8788bf0a7d3..cdeffe75496b 100644
--- a/drivers/staging/gdm72xx/gdm_usb.c
+++ b/drivers/staging/gdm72xx/gdm_usb.c
@@ -635,11 +635,14 @@ static int gdm_usb_probe(struct usb_interface *intf,
635#endif /* CONFIG_WIMAX_GDM72XX_USB_PM */ 635#endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
636 636
637 ret = register_wimax_device(phy_dev, &intf->dev); 637 ret = register_wimax_device(phy_dev, &intf->dev);
638 if (ret)
639 release_usb(udev);
638 640
639out: 641out:
640 if (ret) { 642 if (ret) {
641 kfree(phy_dev); 643 kfree(phy_dev);
642 kfree(udev); 644 kfree(udev);
645 usb_put_dev(usbdev);
643 } else { 646 } else {
644 usb_set_intfdata(intf, phy_dev); 647 usb_set_intfdata(intf, phy_dev);
645 } 648 }
diff --git a/drivers/staging/iio/Documentation/iio_utils.h b/drivers/staging/iio/Documentation/iio_utils.h
index 35154d60faf6..c9fedb79e3a2 100644
--- a/drivers/staging/iio/Documentation/iio_utils.h
+++ b/drivers/staging/iio/Documentation/iio_utils.h
@@ -77,7 +77,6 @@ struct iio_channel_info {
77 uint64_t mask; 77 uint64_t mask;
78 unsigned be; 78 unsigned be;
79 unsigned is_signed; 79 unsigned is_signed;
80 unsigned enabled;
81 unsigned location; 80 unsigned location;
82}; 81};
83 82
@@ -335,6 +334,7 @@ inline int build_channel_array(const char *device_dir,
335 while (ent = readdir(dp), ent != NULL) { 334 while (ent = readdir(dp), ent != NULL) {
336 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), 335 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"),
337 "_en") == 0) { 336 "_en") == 0) {
337 int current_enabled = 0;
338 current = &(*ci_array)[count++]; 338 current = &(*ci_array)[count++];
339 ret = asprintf(&filename, 339 ret = asprintf(&filename,
340 "%s/%s", scan_el_dir, ent->d_name); 340 "%s/%s", scan_el_dir, ent->d_name);
@@ -350,10 +350,10 @@ inline int build_channel_array(const char *device_dir,
350 ret = -errno; 350 ret = -errno;
351 goto error_cleanup_array; 351 goto error_cleanup_array;
352 } 352 }
353 fscanf(sysfsfp, "%u", &current->enabled); 353 fscanf(sysfsfp, "%u", &current_enabled);
354 fclose(sysfsfp); 354 fclose(sysfsfp);
355 355
356 if (!current->enabled) { 356 if (!current_enabled) {
357 free(filename); 357 free(filename);
358 count--; 358 count--;
359 continue; 359 continue;
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 5ea36410f716..5708ffc62aec 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -393,7 +393,7 @@ static const struct iio_event_spec ad799x_events[] = {
393 }, { 393 }, {
394 .type = IIO_EV_TYPE_THRESH, 394 .type = IIO_EV_TYPE_THRESH,
395 .dir = IIO_EV_DIR_FALLING, 395 .dir = IIO_EV_DIR_FALLING,
396 .mask_separate = BIT(IIO_EV_INFO_VALUE), 396 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
397 BIT(IIO_EV_INFO_ENABLE), 397 BIT(IIO_EV_INFO_ENABLE),
398 }, { 398 }, {
399 .type = IIO_EV_TYPE_THRESH, 399 .type = IIO_EV_TYPE_THRESH,
@@ -409,7 +409,13 @@ static const struct iio_event_spec ad799x_events[] = {
409 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 409 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
410 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 410 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
411 .scan_index = (_index), \ 411 .scan_index = (_index), \
412 .scan_type = IIO_ST('u', _realbits, 16, 12 - (_realbits)), \ 412 .scan_type = { \
413 .sign = 'u', \
414 .realbits = (_realbits), \
415 .storagebits = 16, \
416 .shift = 12 - (_realbits), \
417 .endianness = IIO_BE, \
418 }, \
413 .event_spec = _ev_spec, \ 419 .event_spec = _ev_spec, \
414 .num_event_specs = _num_ev_spec, \ 420 .num_event_specs = _num_ev_spec, \
415} 421}
@@ -588,7 +594,8 @@ static int ad799x_probe(struct i2c_client *client,
588 return 0; 594 return 0;
589 595
590error_free_irq: 596error_free_irq:
591 free_irq(client->irq, indio_dev); 597 if (client->irq > 0)
598 free_irq(client->irq, indio_dev);
592error_cleanup_ring: 599error_cleanup_ring:
593 ad799x_ring_cleanup(indio_dev); 600 ad799x_ring_cleanup(indio_dev);
594error_disable_reg: 601error_disable_reg:
diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index df71669bb60e..514844efac75 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -757,6 +757,7 @@ static void mxs_lradc_finish_touch_event(struct mxs_lradc *lradc, bool valid)
757 } 757 }
758 758
759 /* if it is released, wait for the next touch via IRQ */ 759 /* if it is released, wait for the next touch via IRQ */
760 lradc->cur_plate = LRADC_TOUCH;
760 mxs_lradc_reg_clear(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ, LRADC_CTRL1); 761 mxs_lradc_reg_clear(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ, LRADC_CTRL1);
761 mxs_lradc_reg_set(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, LRADC_CTRL1); 762 mxs_lradc_reg_set(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, LRADC_CTRL1);
762} 763}
@@ -1035,8 +1036,6 @@ SHOW_SCALE_AVAILABLE_ATTR(4);
1035SHOW_SCALE_AVAILABLE_ATTR(5); 1036SHOW_SCALE_AVAILABLE_ATTR(5);
1036SHOW_SCALE_AVAILABLE_ATTR(6); 1037SHOW_SCALE_AVAILABLE_ATTR(6);
1037SHOW_SCALE_AVAILABLE_ATTR(7); 1038SHOW_SCALE_AVAILABLE_ATTR(7);
1038SHOW_SCALE_AVAILABLE_ATTR(8);
1039SHOW_SCALE_AVAILABLE_ATTR(9);
1040SHOW_SCALE_AVAILABLE_ATTR(10); 1039SHOW_SCALE_AVAILABLE_ATTR(10);
1041SHOW_SCALE_AVAILABLE_ATTR(11); 1040SHOW_SCALE_AVAILABLE_ATTR(11);
1042SHOW_SCALE_AVAILABLE_ATTR(12); 1041SHOW_SCALE_AVAILABLE_ATTR(12);
@@ -1053,8 +1052,6 @@ static struct attribute *mxs_lradc_attributes[] = {
1053 &iio_dev_attr_in_voltage5_scale_available.dev_attr.attr, 1052 &iio_dev_attr_in_voltage5_scale_available.dev_attr.attr,
1054 &iio_dev_attr_in_voltage6_scale_available.dev_attr.attr, 1053 &iio_dev_attr_in_voltage6_scale_available.dev_attr.attr,
1055 &iio_dev_attr_in_voltage7_scale_available.dev_attr.attr, 1054 &iio_dev_attr_in_voltage7_scale_available.dev_attr.attr,
1056 &iio_dev_attr_in_voltage8_scale_available.dev_attr.attr,
1057 &iio_dev_attr_in_voltage9_scale_available.dev_attr.attr,
1058 &iio_dev_attr_in_voltage10_scale_available.dev_attr.attr, 1055 &iio_dev_attr_in_voltage10_scale_available.dev_attr.attr,
1059 &iio_dev_attr_in_voltage11_scale_available.dev_attr.attr, 1056 &iio_dev_attr_in_voltage11_scale_available.dev_attr.attr,
1060 &iio_dev_attr_in_voltage12_scale_available.dev_attr.attr, 1057 &iio_dev_attr_in_voltage12_scale_available.dev_attr.attr,
@@ -1613,7 +1610,7 @@ static int mxs_lradc_probe(struct platform_device *pdev)
1613 * of the array. 1610 * of the array.
1614 */ 1611 */
1615 scale_uv = ((u64)lradc->vref_mv[i] * 100000000) >> 1612 scale_uv = ((u64)lradc->vref_mv[i] * 100000000) >>
1616 (iio->channels[i].scan_type.realbits - s); 1613 (LRADC_RESOLUTION - s);
1617 lradc->scale_avail[i][s].nano = 1614 lradc->scale_avail[i][s].nano =
1618 do_div(scale_uv, 100000000) * 10; 1615 do_div(scale_uv, 100000000) * 10;
1619 lradc->scale_avail[i][s].integer = scale_uv; 1616 lradc->scale_avail[i][s].integer = scale_uv;
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 0a4298b744e6..2b96665da8a2 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -629,7 +629,7 @@ static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
629 struct iio_buffer *buffer; 629 struct iio_buffer *buffer;
630 630
631 buffer = iio_kfifo_allocate(indio_dev); 631 buffer = iio_kfifo_allocate(indio_dev);
632 if (buffer) 632 if (!buffer)
633 return -ENOMEM; 633 return -ENOMEM;
634 634
635 iio_device_attach_buffer(indio_dev, buffer); 635 iio_device_attach_buffer(indio_dev, buffer);
diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
index 09ef5fb8bae6..236ed66f116a 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -88,9 +88,9 @@ static int imx_drm_driver_unload(struct drm_device *drm)
88 88
89 imx_drm_device_put(); 89 imx_drm_device_put();
90 90
91 drm_vblank_cleanup(imxdrm->drm); 91 drm_vblank_cleanup(drm);
92 drm_kms_helper_poll_fini(imxdrm->drm); 92 drm_kms_helper_poll_fini(drm);
93 drm_mode_config_cleanup(imxdrm->drm); 93 drm_mode_config_cleanup(drm);
94 94
95 return 0; 95 return 0;
96} 96}
@@ -142,19 +142,19 @@ EXPORT_SYMBOL_GPL(imx_drm_crtc_panel_format);
142 142
143int imx_drm_crtc_vblank_get(struct imx_drm_crtc *imx_drm_crtc) 143int imx_drm_crtc_vblank_get(struct imx_drm_crtc *imx_drm_crtc)
144{ 144{
145 return drm_vblank_get(imx_drm_crtc->imxdrm->drm, imx_drm_crtc->pipe); 145 return drm_vblank_get(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe);
146} 146}
147EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_get); 147EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_get);
148 148
149void imx_drm_crtc_vblank_put(struct imx_drm_crtc *imx_drm_crtc) 149void imx_drm_crtc_vblank_put(struct imx_drm_crtc *imx_drm_crtc)
150{ 150{
151 drm_vblank_put(imx_drm_crtc->imxdrm->drm, imx_drm_crtc->pipe); 151 drm_vblank_put(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe);
152} 152}
153EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_put); 153EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_put);
154 154
155void imx_drm_handle_vblank(struct imx_drm_crtc *imx_drm_crtc) 155void imx_drm_handle_vblank(struct imx_drm_crtc *imx_drm_crtc)
156{ 156{
157 drm_handle_vblank(imx_drm_crtc->imxdrm->drm, imx_drm_crtc->pipe); 157 drm_handle_vblank(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe);
158} 158}
159EXPORT_SYMBOL_GPL(imx_drm_handle_vblank); 159EXPORT_SYMBOL_GPL(imx_drm_handle_vblank);
160 160
@@ -370,29 +370,6 @@ static void imx_drm_connector_unregister(
370} 370}
371 371
372/* 372/*
373 * register a crtc to the drm core
374 */
375static int imx_drm_crtc_register(struct imx_drm_crtc *imx_drm_crtc)
376{
377 struct imx_drm_device *imxdrm = __imx_drm_device();
378 int ret;
379
380 ret = drm_mode_crtc_set_gamma_size(imx_drm_crtc->crtc, 256);
381 if (ret)
382 return ret;
383
384 drm_crtc_helper_add(imx_drm_crtc->crtc,
385 imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs);
386
387 drm_crtc_init(imxdrm->drm, imx_drm_crtc->crtc,
388 imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs);
389
390 drm_mode_group_reinit(imxdrm->drm);
391
392 return 0;
393}
394
395/*
396 * Called by the CRTC driver when all CRTCs are registered. This 373 * Called by the CRTC driver when all CRTCs are registered. This
397 * puts all the pieces together and initializes the driver. 374 * puts all the pieces together and initializes the driver.
398 * Once this is called no more CRTCs can be registered since 375 * Once this is called no more CRTCs can be registered since
@@ -424,15 +401,15 @@ static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags)
424 401
425 mutex_lock(&imxdrm->mutex); 402 mutex_lock(&imxdrm->mutex);
426 403
427 drm_kms_helper_poll_init(imxdrm->drm); 404 drm_kms_helper_poll_init(drm);
428 405
429 /* setup the grouping for the legacy output */ 406 /* setup the grouping for the legacy output */
430 ret = drm_mode_group_init_legacy_group(imxdrm->drm, 407 ret = drm_mode_group_init_legacy_group(drm,
431 &imxdrm->drm->primary->mode_group); 408 &drm->primary->mode_group);
432 if (ret) 409 if (ret)
433 goto err_kms; 410 goto err_kms;
434 411
435 ret = drm_vblank_init(imxdrm->drm, MAX_CRTC); 412 ret = drm_vblank_init(drm, MAX_CRTC);
436 if (ret) 413 if (ret)
437 goto err_kms; 414 goto err_kms;
438 415
@@ -441,7 +418,7 @@ static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags)
441 * by drm timer once a current process gives up ownership of 418 * by drm timer once a current process gives up ownership of
442 * vblank event.(after drm_vblank_put function is called) 419 * vblank event.(after drm_vblank_put function is called)
443 */ 420 */
444 imxdrm->drm->vblank_disable_allowed = true; 421 drm->vblank_disable_allowed = true;
445 422
446 if (!imx_drm_device_get()) { 423 if (!imx_drm_device_get()) {
447 ret = -EINVAL; 424 ret = -EINVAL;
@@ -536,10 +513,18 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
536 513
537 *new_crtc = imx_drm_crtc; 514 *new_crtc = imx_drm_crtc;
538 515
539 ret = imx_drm_crtc_register(imx_drm_crtc); 516 ret = drm_mode_crtc_set_gamma_size(imx_drm_crtc->crtc, 256);
540 if (ret) 517 if (ret)
541 goto err_register; 518 goto err_register;
542 519
520 drm_crtc_helper_add(crtc,
521 imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs);
522
523 drm_crtc_init(imxdrm->drm, crtc,
524 imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs);
525
526 drm_mode_group_reinit(imxdrm->drm);
527
543 imx_drm_update_possible_crtcs(); 528 imx_drm_update_possible_crtcs();
544 529
545 mutex_unlock(&imxdrm->mutex); 530 mutex_unlock(&imxdrm->mutex);
diff --git a/drivers/staging/imx-drm/imx-hdmi.c b/drivers/staging/imx-drm/imx-hdmi.c
index f3a1f5e2e492..62ce0e86f14b 100644
--- a/drivers/staging/imx-drm/imx-hdmi.c
+++ b/drivers/staging/imx-drm/imx-hdmi.c
@@ -16,6 +16,7 @@
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/clk.h> 18#include <linux/clk.h>
19#include <linux/hdmi.h>
19#include <linux/regmap.h> 20#include <linux/regmap.h>
20#include <linux/mfd/syscon.h> 21#include <linux/mfd/syscon.h>
21#include <linux/mfd/syscon/imx6q-iomuxc-gpr.h> 22#include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
@@ -52,11 +53,6 @@ enum hdmi_datamap {
52 YCbCr422_12B = 0x12, 53 YCbCr422_12B = 0x12,
53}; 54};
54 55
55enum hdmi_colorimetry {
56 ITU601,
57 ITU709,
58};
59
60enum imx_hdmi_devtype { 56enum imx_hdmi_devtype {
61 IMX6Q_HDMI, 57 IMX6Q_HDMI,
62 IMX6DL_HDMI, 58 IMX6DL_HDMI,
@@ -489,12 +485,12 @@ static void imx_hdmi_update_csc_coeffs(struct imx_hdmi *hdmi)
489 485
490 if (is_color_space_conversion(hdmi)) { 486 if (is_color_space_conversion(hdmi)) {
491 if (hdmi->hdmi_data.enc_out_format == RGB) { 487 if (hdmi->hdmi_data.enc_out_format == RGB) {
492 if (hdmi->hdmi_data.colorimetry == ITU601) 488 if (hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_601)
493 csc_coeff = &csc_coeff_rgb_out_eitu601; 489 csc_coeff = &csc_coeff_rgb_out_eitu601;
494 else 490 else
495 csc_coeff = &csc_coeff_rgb_out_eitu709; 491 csc_coeff = &csc_coeff_rgb_out_eitu709;
496 } else if (hdmi->hdmi_data.enc_in_format == RGB) { 492 } else if (hdmi->hdmi_data.enc_in_format == RGB) {
497 if (hdmi->hdmi_data.colorimetry == ITU601) 493 if (hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_601)
498 csc_coeff = &csc_coeff_rgb_in_eitu601; 494 csc_coeff = &csc_coeff_rgb_in_eitu601;
499 else 495 else
500 csc_coeff = &csc_coeff_rgb_in_eitu709; 496 csc_coeff = &csc_coeff_rgb_in_eitu709;
@@ -1140,16 +1136,16 @@ static void hdmi_config_AVI(struct imx_hdmi *hdmi)
1140 /* Set up colorimetry */ 1136 /* Set up colorimetry */
1141 if (hdmi->hdmi_data.enc_out_format == XVYCC444) { 1137 if (hdmi->hdmi_data.enc_out_format == XVYCC444) {
1142 colorimetry = HDMI_FC_AVICONF1_COLORIMETRY_EXTENDED_INFO; 1138 colorimetry = HDMI_FC_AVICONF1_COLORIMETRY_EXTENDED_INFO;
1143 if (hdmi->hdmi_data.colorimetry == ITU601) 1139 if (hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_601)
1144 ext_colorimetry = 1140 ext_colorimetry =
1145 HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC601; 1141 HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC601;
1146 else /* hdmi->hdmi_data.colorimetry == ITU709 */ 1142 else /*hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_709*/
1147 ext_colorimetry = 1143 ext_colorimetry =
1148 HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC709; 1144 HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC709;
1149 } else if (hdmi->hdmi_data.enc_out_format != RGB) { 1145 } else if (hdmi->hdmi_data.enc_out_format != RGB) {
1150 if (hdmi->hdmi_data.colorimetry == ITU601) 1146 if (hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_601)
1151 colorimetry = HDMI_FC_AVICONF1_COLORIMETRY_SMPTE; 1147 colorimetry = HDMI_FC_AVICONF1_COLORIMETRY_SMPTE;
1152 else /* hdmi->hdmi_data.colorimetry == ITU709 */ 1148 else /*hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_709*/
1153 colorimetry = HDMI_FC_AVICONF1_COLORIMETRY_ITUR; 1149 colorimetry = HDMI_FC_AVICONF1_COLORIMETRY_ITUR;
1154 ext_colorimetry = HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC601; 1150 ext_colorimetry = HDMI_FC_AVICONF2_EXT_COLORIMETRY_XVYCC601;
1155 } else { /* Carries no data */ 1151 } else { /* Carries no data */
@@ -1379,9 +1375,9 @@ static int imx_hdmi_setup(struct imx_hdmi *hdmi, struct drm_display_mode *mode)
1379 (hdmi->vic == 21) || (hdmi->vic == 22) || 1375 (hdmi->vic == 21) || (hdmi->vic == 22) ||
1380 (hdmi->vic == 2) || (hdmi->vic == 3) || 1376 (hdmi->vic == 2) || (hdmi->vic == 3) ||
1381 (hdmi->vic == 17) || (hdmi->vic == 18)) 1377 (hdmi->vic == 17) || (hdmi->vic == 18))
1382 hdmi->hdmi_data.colorimetry = ITU601; 1378 hdmi->hdmi_data.colorimetry = HDMI_COLORIMETRY_ITU_601;
1383 else 1379 else
1384 hdmi->hdmi_data.colorimetry = ITU709; 1380 hdmi->hdmi_data.colorimetry = HDMI_COLORIMETRY_ITU_709;
1385 1381
1386 if ((hdmi->vic == 10) || (hdmi->vic == 11) || 1382 if ((hdmi->vic == 10) || (hdmi->vic == 11) ||
1387 (hdmi->vic == 12) || (hdmi->vic == 13) || 1383 (hdmi->vic == 12) || (hdmi->vic == 13) ||
diff --git a/drivers/staging/lustre/TODO b/drivers/staging/lustre/TODO
index 22742d6d62a8..0a2b6cb3775e 100644
--- a/drivers/staging/lustre/TODO
+++ b/drivers/staging/lustre/TODO
@@ -9,5 +9,6 @@
9* Other minor misc cleanups... 9* Other minor misc cleanups...
10 10
11Please send any patches to Greg Kroah-Hartman <greg@kroah.com>, Andreas Dilger 11Please send any patches to Greg Kroah-Hartman <greg@kroah.com>, Andreas Dilger
12<andreas.dilger@intel.com> and Peng Tao <tao.peng@emc.com>. CCing 12<andreas.dilger@intel.com>, Oleg Drokin <oleg.drokin@intel.com> and
13hpdd-discuss <hpdd-discuss@lists.01.org> would be great too. 13Peng Tao <tao.peng@emc.com>. CCing hpdd-discuss <hpdd-discuss@lists.01.org>
14would be great too.
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h
index 596a15fc8996..037ae8a6d531 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_kernelcomm.h
@@ -61,6 +61,8 @@ struct kuc_hdr {
61 __u16 kuc_msglen; /* Including header */ 61 __u16 kuc_msglen; /* Including header */
62} __attribute__((aligned(sizeof(__u64)))); 62} __attribute__((aligned(sizeof(__u64))));
63 63
64#define KUC_CHANGELOG_MSG_MAXSIZE (sizeof(struct kuc_hdr)+CR_MAXSIZE)
65
64#define KUC_MAGIC 0x191C /*Lustre9etLinC */ 66#define KUC_MAGIC 0x191C /*Lustre9etLinC */
65#define KUC_FL_BLOCK 0x01 /* Wait for send */ 67#define KUC_FL_BLOCK 0x01 /* Wait for send */
66 68
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
index d0d942ced01a..dddccca120c9 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
@@ -120,7 +120,7 @@ do { \
120do { \ 120do { \
121 LASSERT(!in_interrupt() || \ 121 LASSERT(!in_interrupt() || \
122 ((size) <= LIBCFS_VMALLOC_SIZE && \ 122 ((size) <= LIBCFS_VMALLOC_SIZE && \
123 ((mask) & GFP_ATOMIC)) != 0); \ 123 ((mask) & __GFP_WAIT) == 0)); \
124} while (0) 124} while (0)
125 125
126#define LIBCFS_ALLOC_POST(ptr, size) \ 126#define LIBCFS_ALLOC_POST(ptr, size) \
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
index 93648632ba26..6f58ead20393 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
@@ -529,7 +529,7 @@ kiblnd_kvaddr_to_page (unsigned long vaddr)
529{ 529{
530 struct page *page; 530 struct page *page;
531 531
532 if (is_vmalloc_addr(vaddr)) { 532 if (is_vmalloc_addr((void *)vaddr)) {
533 page = vmalloc_to_page ((void *)vaddr); 533 page = vmalloc_to_page ((void *)vaddr);
534 LASSERT (page != NULL); 534 LASSERT (page != NULL);
535 return page; 535 return page;
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
index 68a4f52ec998..b7b53b579c85 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
@@ -924,7 +924,7 @@ ksocknal_launch_packet (lnet_ni_t *ni, ksock_tx_t *tx, lnet_process_id_t id)
924int 924int
925ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg) 925ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
926{ 926{
927 int mpflag = 0; 927 int mpflag = 1;
928 int type = lntmsg->msg_type; 928 int type = lntmsg->msg_type;
929 lnet_process_id_t target = lntmsg->msg_target; 929 lnet_process_id_t target = lntmsg->msg_target;
930 unsigned int payload_niov = lntmsg->msg_niov; 930 unsigned int payload_niov = lntmsg->msg_niov;
@@ -993,8 +993,9 @@ ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
993 993
994 /* The first fragment will be set later in pro_pack */ 994 /* The first fragment will be set later in pro_pack */
995 rc = ksocknal_launch_packet(ni, tx, target); 995 rc = ksocknal_launch_packet(ni, tx, target);
996 if (lntmsg->msg_vmflush) 996 if (!mpflag)
997 cfs_memory_pressure_restore(mpflag); 997 cfs_memory_pressure_restore(mpflag);
998
998 if (rc == 0) 999 if (rc == 0)
999 return (0); 1000 return (0);
1000 1001
diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
index 6b6c0240e824..7893d83e131f 100644
--- a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
+++ b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
@@ -760,7 +760,8 @@ static inline void hsm_set_cl_error(int *flags, int error)
760 *flags |= (error << CLF_HSM_ERR_L); 760 *flags |= (error << CLF_HSM_ERR_L);
761} 761}
762 762
763#define CR_MAXSIZE cfs_size_round(2*NAME_MAX + 1 + sizeof(struct changelog_rec)) 763#define CR_MAXSIZE cfs_size_round(2*NAME_MAX + 1 + \
764 sizeof(struct changelog_ext_rec))
764 765
765struct changelog_rec { 766struct changelog_rec {
766 __u16 cr_namelen; 767 __u16 cr_namelen;
diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
index 22d0acc95bc5..52b7731bcc38 100644
--- a/drivers/staging/lustre/lustre/llite/dir.c
+++ b/drivers/staging/lustre/lustre/llite/dir.c
@@ -1086,7 +1086,7 @@ static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
1086 break; 1086 break;
1087 case Q_GETQUOTA: 1087 case Q_GETQUOTA:
1088 if (((type == USRQUOTA && 1088 if (((type == USRQUOTA &&
1089 uid_eq(current_euid(), make_kuid(&init_user_ns, id))) || 1089 !uid_eq(current_euid(), make_kuid(&init_user_ns, id))) ||
1090 (type == GRPQUOTA && 1090 (type == GRPQUOTA &&
1091 !in_egroup_p(make_kgid(&init_user_ns, id)))) && 1091 !in_egroup_p(make_kgid(&init_user_ns, id)))) &&
1092 (!cfs_capable(CFS_CAP_SYS_ADMIN) || 1092 (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index d1ad91c34ddc..83013927e131 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -1430,7 +1430,7 @@ static struct kuc_hdr *changelog_kuc_hdr(char *buf, int len, int flags)
1430{ 1430{
1431 struct kuc_hdr *lh = (struct kuc_hdr *)buf; 1431 struct kuc_hdr *lh = (struct kuc_hdr *)buf;
1432 1432
1433 LASSERT(len <= CR_MAXSIZE); 1433 LASSERT(len <= KUC_CHANGELOG_MSG_MAXSIZE);
1434 1434
1435 lh->kuc_magic = KUC_MAGIC; 1435 lh->kuc_magic = KUC_MAGIC;
1436 lh->kuc_transport = KUC_TRANSPORT_CHANGELOG; 1436 lh->kuc_transport = KUC_TRANSPORT_CHANGELOG;
@@ -1503,7 +1503,7 @@ static int mdc_changelog_send_thread(void *csdata)
1503 CDEBUG(D_CHANGELOG, "changelog to fp=%p start "LPU64"\n", 1503 CDEBUG(D_CHANGELOG, "changelog to fp=%p start "LPU64"\n",
1504 cs->cs_fp, cs->cs_startrec); 1504 cs->cs_fp, cs->cs_startrec);
1505 1505
1506 OBD_ALLOC(cs->cs_buf, CR_MAXSIZE); 1506 OBD_ALLOC(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
1507 if (cs->cs_buf == NULL) 1507 if (cs->cs_buf == NULL)
1508 GOTO(out, rc = -ENOMEM); 1508 GOTO(out, rc = -ENOMEM);
1509 1509
@@ -1540,7 +1540,7 @@ out:
1540 if (ctxt) 1540 if (ctxt)
1541 llog_ctxt_put(ctxt); 1541 llog_ctxt_put(ctxt);
1542 if (cs->cs_buf) 1542 if (cs->cs_buf)
1543 OBD_FREE(cs->cs_buf, CR_MAXSIZE); 1543 OBD_FREE(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
1544 OBD_FREE_PTR(cs); 1544 OBD_FREE_PTR(cs);
1545 return rc; 1545 return rc;
1546} 1546}
diff --git a/drivers/staging/media/go7007/go7007-loader.c b/drivers/staging/media/go7007/go7007-loader.c
index 10bb41c2fb6d..eecb1f2a5574 100644
--- a/drivers/staging/media/go7007/go7007-loader.c
+++ b/drivers/staging/media/go7007/go7007-loader.c
@@ -59,7 +59,7 @@ static int go7007_loader_probe(struct usb_interface *interface,
59 59
60 if (usbdev->descriptor.bNumConfigurations != 1) { 60 if (usbdev->descriptor.bNumConfigurations != 1) {
61 dev_err(&interface->dev, "can't handle multiple config\n"); 61 dev_err(&interface->dev, "can't handle multiple config\n");
62 return -ENODEV; 62 goto failed2;
63 } 63 }
64 64
65 vendor = le16_to_cpu(usbdev->descriptor.idVendor); 65 vendor = le16_to_cpu(usbdev->descriptor.idVendor);
@@ -108,6 +108,7 @@ static int go7007_loader_probe(struct usb_interface *interface,
108 return 0; 108 return 0;
109 109
110failed2: 110failed2:
111 usb_put_dev(usbdev);
111 dev_err(&interface->dev, "probe failed\n"); 112 dev_err(&interface->dev, "probe failed\n");
112 return -ENODEV; 113 return -ENODEV;
113} 114}
@@ -115,6 +116,7 @@ failed2:
115static void go7007_loader_disconnect(struct usb_interface *interface) 116static void go7007_loader_disconnect(struct usb_interface *interface)
116{ 117{
117 dev_info(&interface->dev, "disconnect\n"); 118 dev_info(&interface->dev, "disconnect\n");
119 usb_put_dev(interface_to_usbdev(interface));
118 usb_set_intfdata(interface, NULL); 120 usb_set_intfdata(interface, NULL);
119} 121}
120 122
diff --git a/drivers/staging/netlogic/xlr_net.c b/drivers/staging/netlogic/xlr_net.c
index eedffed17e39..31b269a5fff7 100644
--- a/drivers/staging/netlogic/xlr_net.c
+++ b/drivers/staging/netlogic/xlr_net.c
@@ -307,7 +307,7 @@ static netdev_tx_t xlr_net_start_xmit(struct sk_buff *skb,
307} 307}
308 308
309static u16 xlr_net_select_queue(struct net_device *ndev, struct sk_buff *skb, 309static u16 xlr_net_select_queue(struct net_device *ndev, struct sk_buff *skb,
310 void *accel_priv) 310 void *accel_priv, select_queue_fallback_t fallback)
311{ 311{
312 return (u16)smp_processor_id(); 312 return (u16)smp_processor_id();
313} 313}
@@ -892,6 +892,11 @@ static int xlr_setup_mdio(struct xlr_net_priv *priv,
892 priv->mii_bus->write = xlr_mii_write; 892 priv->mii_bus->write = xlr_mii_write;
893 priv->mii_bus->parent = &pdev->dev; 893 priv->mii_bus->parent = &pdev->dev;
894 priv->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 894 priv->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
895 if (priv->mii_bus->irq == NULL) {
896 pr_err("irq alloc failed\n");
897 mdiobus_free(priv->mii_bus);
898 return -ENOMEM;
899 }
895 priv->mii_bus->irq[priv->phy_addr] = priv->ndev->irq; 900 priv->mii_bus->irq[priv->phy_addr] = priv->ndev->irq;
896 901
897 /* Scan only the enabled address */ 902 /* Scan only the enabled address */
diff --git a/drivers/staging/octeon-usb/octeon-hcd.c b/drivers/staging/octeon-usb/octeon-hcd.c
index 47e0a91238a1..5a001d9b4252 100644
--- a/drivers/staging/octeon-usb/octeon-hcd.c
+++ b/drivers/staging/octeon-usb/octeon-hcd.c
@@ -275,13 +275,6 @@ enum cvmx_usb_pipe_flags {
275 */ 275 */
276#define MAX_TRANSFER_PACKETS ((1<<10)-1) 276#define MAX_TRANSFER_PACKETS ((1<<10)-1)
277 277
278enum {
279 USB_CLOCK_TYPE_REF_12,
280 USB_CLOCK_TYPE_REF_24,
281 USB_CLOCK_TYPE_REF_48,
282 USB_CLOCK_TYPE_CRYSTAL_12,
283};
284
285/** 278/**
286 * Logical transactions may take numerous low level 279 * Logical transactions may take numerous low level
287 * transactions, especially when splits are concerned. This 280 * transactions, especially when splits are concerned. This
@@ -471,19 +464,6 @@ struct octeon_hcd {
471/* Returns the IO address to push/pop stuff data from the FIFOs */ 464/* Returns the IO address to push/pop stuff data from the FIFOs */
472#define USB_FIFO_ADDRESS(channel, usb_index) (CVMX_USBCX_GOTGCTL(usb_index) + ((channel)+1)*0x1000) 465#define USB_FIFO_ADDRESS(channel, usb_index) (CVMX_USBCX_GOTGCTL(usb_index) + ((channel)+1)*0x1000)
473 466
474static int octeon_usb_get_clock_type(void)
475{
476 switch (cvmx_sysinfo_get()->board_type) {
477 case CVMX_BOARD_TYPE_BBGW_REF:
478 case CVMX_BOARD_TYPE_LANAI2_A:
479 case CVMX_BOARD_TYPE_LANAI2_U:
480 case CVMX_BOARD_TYPE_LANAI2_G:
481 case CVMX_BOARD_TYPE_UBNT_E100:
482 return USB_CLOCK_TYPE_CRYSTAL_12;
483 }
484 return USB_CLOCK_TYPE_REF_48;
485}
486
487/** 467/**
488 * Read a USB 32bit CSR. It performs the necessary address swizzle 468 * Read a USB 32bit CSR. It performs the necessary address swizzle
489 * for 32bit CSRs and logs the value in a readable format if 469 * for 32bit CSRs and logs the value in a readable format if
@@ -582,37 +562,6 @@ static inline int __cvmx_usb_get_data_pid(struct cvmx_usb_pipe *pipe)
582 return 0; /* Data0 */ 562 return 0; /* Data0 */
583} 563}
584 564
585
586/**
587 * Return the number of USB ports supported by this Octeon
588 * chip. If the chip doesn't support USB, or is not supported
589 * by this API, a zero will be returned. Most Octeon chips
590 * support one usb port, but some support two ports.
591 * cvmx_usb_initialize() must be called on independent
592 * struct cvmx_usb_state.
593 *
594 * Returns: Number of port, zero if usb isn't supported
595 */
596static int cvmx_usb_get_num_ports(void)
597{
598 int arch_ports = 0;
599
600 if (OCTEON_IS_MODEL(OCTEON_CN56XX))
601 arch_ports = 1;
602 else if (OCTEON_IS_MODEL(OCTEON_CN52XX))
603 arch_ports = 2;
604 else if (OCTEON_IS_MODEL(OCTEON_CN50XX))
605 arch_ports = 1;
606 else if (OCTEON_IS_MODEL(OCTEON_CN31XX))
607 arch_ports = 1;
608 else if (OCTEON_IS_MODEL(OCTEON_CN30XX))
609 arch_ports = 1;
610 else
611 arch_ports = 0;
612
613 return arch_ports;
614}
615
616/** 565/**
617 * Initialize a USB port for use. This must be called before any 566 * Initialize a USB port for use. This must be called before any
618 * other access to the Octeon USB port is made. The port starts 567 * other access to the Octeon USB port is made. The port starts
@@ -628,41 +577,16 @@ static int cvmx_usb_get_num_ports(void)
628 * Returns: 0 or a negative error code. 577 * Returns: 0 or a negative error code.
629 */ 578 */
630static int cvmx_usb_initialize(struct cvmx_usb_state *usb, 579static int cvmx_usb_initialize(struct cvmx_usb_state *usb,
631 int usb_port_number) 580 int usb_port_number,
581 enum cvmx_usb_initialize_flags flags)
632{ 582{
633 union cvmx_usbnx_clk_ctl usbn_clk_ctl; 583 union cvmx_usbnx_clk_ctl usbn_clk_ctl;
634 union cvmx_usbnx_usbp_ctl_status usbn_usbp_ctl_status; 584 union cvmx_usbnx_usbp_ctl_status usbn_usbp_ctl_status;
635 enum cvmx_usb_initialize_flags flags = 0;
636 int i; 585 int i;
637 586
638 /* At first allow 0-1 for the usb port number */ 587 /* At first allow 0-1 for the usb port number */
639 if ((usb_port_number < 0) || (usb_port_number > 1)) 588 if ((usb_port_number < 0) || (usb_port_number > 1))
640 return -EINVAL; 589 return -EINVAL;
641 /* For all chips except 52XX there is only one port */
642 if (!OCTEON_IS_MODEL(OCTEON_CN52XX) && (usb_port_number > 0))
643 return -EINVAL;
644 /* Try to determine clock type automatically */
645 if (octeon_usb_get_clock_type() == USB_CLOCK_TYPE_CRYSTAL_12) {
646 /* Only 12 MHZ crystals are supported */
647 flags |= CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_XI;
648 } else {
649 flags |= CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_GND;
650
651 switch (octeon_usb_get_clock_type()) {
652 case USB_CLOCK_TYPE_REF_12:
653 flags |= CVMX_USB_INITIALIZE_FLAGS_CLOCK_12MHZ;
654 break;
655 case USB_CLOCK_TYPE_REF_24:
656 flags |= CVMX_USB_INITIALIZE_FLAGS_CLOCK_24MHZ;
657 break;
658 case USB_CLOCK_TYPE_REF_48:
659 flags |= CVMX_USB_INITIALIZE_FLAGS_CLOCK_48MHZ;
660 break;
661 default:
662 return -EINVAL;
663 break;
664 }
665 }
666 590
667 memset(usb, 0, sizeof(*usb)); 591 memset(usb, 0, sizeof(*usb));
668 usb->init_flags = flags; 592 usb->init_flags = flags;
@@ -3431,7 +3355,6 @@ static int octeon_usb_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
3431 return 0; 3355 return 0;
3432} 3356}
3433 3357
3434
3435static const struct hc_driver octeon_hc_driver = { 3358static const struct hc_driver octeon_hc_driver = {
3436 .description = "Octeon USB", 3359 .description = "Octeon USB",
3437 .product_desc = "Octeon Host Controller", 3360 .product_desc = "Octeon Host Controller",
@@ -3448,15 +3371,74 @@ static const struct hc_driver octeon_hc_driver = {
3448 .hub_control = octeon_usb_hub_control, 3371 .hub_control = octeon_usb_hub_control,
3449}; 3372};
3450 3373
3451 3374static int octeon_usb_probe(struct platform_device *pdev)
3452static int octeon_usb_driver_probe(struct device *dev)
3453{ 3375{
3454 int status; 3376 int status;
3455 int usb_num = to_platform_device(dev)->id; 3377 int initialize_flags;
3456 int irq = platform_get_irq(to_platform_device(dev), 0); 3378 int usb_num;
3379 struct resource *res_mem;
3380 struct device_node *usbn_node;
3381 int irq = platform_get_irq(pdev, 0);
3382 struct device *dev = &pdev->dev;
3457 struct octeon_hcd *priv; 3383 struct octeon_hcd *priv;
3458 struct usb_hcd *hcd; 3384 struct usb_hcd *hcd;
3459 unsigned long flags; 3385 unsigned long flags;
3386 u32 clock_rate = 48000000;
3387 bool is_crystal_clock = false;
3388 const char *clock_type;
3389 int i;
3390
3391 if (dev->of_node == NULL) {
3392 dev_err(dev, "Error: empty of_node\n");
3393 return -ENXIO;
3394 }
3395 usbn_node = dev->of_node->parent;
3396
3397 i = of_property_read_u32(usbn_node,
3398 "refclk-frequency", &clock_rate);
3399 if (i) {
3400 dev_err(dev, "No USBN \"refclk-frequency\"\n");
3401 return -ENXIO;
3402 }
3403 switch (clock_rate) {
3404 case 12000000:
3405 initialize_flags = CVMX_USB_INITIALIZE_FLAGS_CLOCK_12MHZ;
3406 break;
3407 case 24000000:
3408 initialize_flags = CVMX_USB_INITIALIZE_FLAGS_CLOCK_24MHZ;
3409 break;
3410 case 48000000:
3411 initialize_flags = CVMX_USB_INITIALIZE_FLAGS_CLOCK_48MHZ;
3412 break;
3413 default:
3414 dev_err(dev, "Illebal USBN \"refclk-frequency\" %u\n", clock_rate);
3415 return -ENXIO;
3416
3417 }
3418
3419 i = of_property_read_string(usbn_node,
3420 "refclk-type", &clock_type);
3421
3422 if (!i && strcmp("crystal", clock_type) == 0)
3423 is_crystal_clock = true;
3424
3425 if (is_crystal_clock)
3426 initialize_flags |= CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_XI;
3427 else
3428 initialize_flags |= CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_GND;
3429
3430 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3431 if (res_mem == NULL) {
3432 dev_err(dev, "found no memory resource\n");
3433 return -ENXIO;
3434 }
3435 usb_num = (res_mem->start >> 44) & 1;
3436
3437 if (irq < 0) {
3438 /* Defective device tree, but we know how to fix it. */
3439 irq_hw_number_t hwirq = usb_num ? (1 << 6) + 17 : 56;
3440 irq = irq_create_mapping(NULL, hwirq);
3441 }
3460 3442
3461 /* 3443 /*
3462 * Set the DMA mask to 64bits so we get buffers already translated for 3444 * Set the DMA mask to 64bits so we get buffers already translated for
@@ -3465,6 +3447,26 @@ static int octeon_usb_driver_probe(struct device *dev)
3465 dev->coherent_dma_mask = ~0; 3447 dev->coherent_dma_mask = ~0;
3466 dev->dma_mask = &dev->coherent_dma_mask; 3448 dev->dma_mask = &dev->coherent_dma_mask;
3467 3449
3450 /*
3451 * Only cn52XX and cn56XX have DWC_OTG USB hardware and the
3452 * IOB priority registers. Under heavy network load USB
3453 * hardware can be starved by the IOB causing a crash. Give
3454 * it a priority boost if it has been waiting more than 400
3455 * cycles to avoid this situation.
3456 *
3457 * Testing indicates that a cnt_val of 8192 is not sufficient,
3458 * but no failures are seen with 4096. We choose a value of
3459 * 400 to give a safety factor of 10.
3460 */
3461 if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN56XX)) {
3462 union cvmx_iob_n2c_l2c_pri_cnt pri_cnt;
3463
3464 pri_cnt.u64 = 0;
3465 pri_cnt.s.cnt_enb = 1;
3466 pri_cnt.s.cnt_val = 400;
3467 cvmx_write_csr(CVMX_IOB_N2C_L2C_PRI_CNT, pri_cnt.u64);
3468 }
3469
3468 hcd = usb_create_hcd(&octeon_hc_driver, dev, dev_name(dev)); 3470 hcd = usb_create_hcd(&octeon_hc_driver, dev, dev_name(dev));
3469 if (!hcd) { 3471 if (!hcd) {
3470 dev_dbg(dev, "Failed to allocate memory for HCD\n"); 3472 dev_dbg(dev, "Failed to allocate memory for HCD\n");
@@ -3478,7 +3480,7 @@ static int octeon_usb_driver_probe(struct device *dev)
3478 tasklet_init(&priv->dequeue_tasklet, octeon_usb_urb_dequeue_work, (unsigned long)priv); 3480 tasklet_init(&priv->dequeue_tasklet, octeon_usb_urb_dequeue_work, (unsigned long)priv);
3479 INIT_LIST_HEAD(&priv->dequeue_list); 3481 INIT_LIST_HEAD(&priv->dequeue_list);
3480 3482
3481 status = cvmx_usb_initialize(&priv->usb, usb_num); 3483 status = cvmx_usb_initialize(&priv->usb, usb_num, initialize_flags);
3482 if (status) { 3484 if (status) {
3483 dev_dbg(dev, "USB initialization failed with %d\n", status); 3485 dev_dbg(dev, "USB initialization failed with %d\n", status);
3484 kfree(hcd); 3486 kfree(hcd);
@@ -3492,7 +3494,7 @@ static int octeon_usb_driver_probe(struct device *dev)
3492 cvmx_usb_poll(&priv->usb); 3494 cvmx_usb_poll(&priv->usb);
3493 spin_unlock_irqrestore(&priv->lock, flags); 3495 spin_unlock_irqrestore(&priv->lock, flags);
3494 3496
3495 status = usb_add_hcd(hcd, irq, IRQF_SHARED); 3497 status = usb_add_hcd(hcd, irq, 0);
3496 if (status) { 3498 if (status) {
3497 dev_dbg(dev, "USB add HCD failed with %d\n", status); 3499 dev_dbg(dev, "USB add HCD failed with %d\n", status);
3498 kfree(hcd); 3500 kfree(hcd);
@@ -3500,14 +3502,15 @@ static int octeon_usb_driver_probe(struct device *dev)
3500 } 3502 }
3501 device_wakeup_enable(hcd->self.controller); 3503 device_wakeup_enable(hcd->self.controller);
3502 3504
3503 dev_dbg(dev, "Registered HCD for port %d on irq %d\n", usb_num, irq); 3505 dev_info(dev, "Registered HCD for port %d on irq %d\n", usb_num, irq);
3504 3506
3505 return 0; 3507 return 0;
3506} 3508}
3507 3509
3508static int octeon_usb_driver_remove(struct device *dev) 3510static int octeon_usb_remove(struct platform_device *pdev)
3509{ 3511{
3510 int status; 3512 int status;
3513 struct device *dev = &pdev->dev;
3511 struct usb_hcd *hcd = dev_get_drvdata(dev); 3514 struct usb_hcd *hcd = dev_get_drvdata(dev);
3512 struct octeon_hcd *priv = hcd_to_octeon(hcd); 3515 struct octeon_hcd *priv = hcd_to_octeon(hcd);
3513 unsigned long flags; 3516 unsigned long flags;
@@ -3525,85 +3528,41 @@ static int octeon_usb_driver_remove(struct device *dev)
3525 return 0; 3528 return 0;
3526} 3529}
3527 3530
3528static struct device_driver octeon_usb_driver = { 3531static struct of_device_id octeon_usb_match[] = {
3529 .name = "OcteonUSB", 3532 {
3530 .bus = &platform_bus_type, 3533 .compatible = "cavium,octeon-5750-usbc",
3531 .probe = octeon_usb_driver_probe, 3534 },
3532 .remove = octeon_usb_driver_remove, 3535 {},
3533}; 3536};
3534 3537
3538static struct platform_driver octeon_usb_driver = {
3539 .driver = {
3540 .name = "OcteonUSB",
3541 .owner = THIS_MODULE,
3542 .of_match_table = octeon_usb_match,
3543 },
3544 .probe = octeon_usb_probe,
3545 .remove = octeon_usb_remove,
3546};
3535 3547
3536#define MAX_USB_PORTS 10 3548static int __init octeon_usb_driver_init(void)
3537static struct platform_device *pdev_glob[MAX_USB_PORTS];
3538static int octeon_usb_registered;
3539static int __init octeon_usb_module_init(void)
3540{ 3549{
3541 int num_devices = cvmx_usb_get_num_ports(); 3550 if (usb_disabled())
3542 int device; 3551 return 0;
3543
3544 if (usb_disabled() || num_devices == 0)
3545 return -ENODEV;
3546
3547 if (driver_register(&octeon_usb_driver))
3548 return -ENOMEM;
3549
3550 octeon_usb_registered = 1;
3551
3552 /*
3553 * Only cn52XX and cn56XX have DWC_OTG USB hardware and the
3554 * IOB priority registers. Under heavy network load USB
3555 * hardware can be starved by the IOB causing a crash. Give
3556 * it a priority boost if it has been waiting more than 400
3557 * cycles to avoid this situation.
3558 *
3559 * Testing indicates that a cnt_val of 8192 is not sufficient,
3560 * but no failures are seen with 4096. We choose a value of
3561 * 400 to give a safety factor of 10.
3562 */
3563 if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN56XX)) {
3564 union cvmx_iob_n2c_l2c_pri_cnt pri_cnt;
3565
3566 pri_cnt.u64 = 0;
3567 pri_cnt.s.cnt_enb = 1;
3568 pri_cnt.s.cnt_val = 400;
3569 cvmx_write_csr(CVMX_IOB_N2C_L2C_PRI_CNT, pri_cnt.u64);
3570 }
3571
3572 for (device = 0; device < num_devices; device++) {
3573 struct resource irq_resource;
3574 struct platform_device *pdev;
3575 memset(&irq_resource, 0, sizeof(irq_resource));
3576 irq_resource.start = (device == 0) ? OCTEON_IRQ_USB0 : OCTEON_IRQ_USB1;
3577 irq_resource.end = irq_resource.start;
3578 irq_resource.flags = IORESOURCE_IRQ;
3579 pdev = platform_device_register_simple((char *)octeon_usb_driver. name, device, &irq_resource, 1);
3580 if (IS_ERR(pdev)) {
3581 driver_unregister(&octeon_usb_driver);
3582 octeon_usb_registered = 0;
3583 return PTR_ERR(pdev);
3584 }
3585 if (device < MAX_USB_PORTS)
3586 pdev_glob[device] = pdev;
3587 3552
3588 } 3553 return platform_driver_register(&octeon_usb_driver);
3589 return 0;
3590} 3554}
3555module_init(octeon_usb_driver_init);
3591 3556
3592static void __exit octeon_usb_module_cleanup(void) 3557static void __exit octeon_usb_driver_exit(void)
3593{ 3558{
3594 int i; 3559 if (usb_disabled())
3560 return;
3595 3561
3596 for (i = 0; i < MAX_USB_PORTS; i++) 3562 platform_driver_unregister(&octeon_usb_driver);
3597 if (pdev_glob[i]) {
3598 platform_device_unregister(pdev_glob[i]);
3599 pdev_glob[i] = NULL;
3600 }
3601 if (octeon_usb_registered)
3602 driver_unregister(&octeon_usb_driver);
3603} 3563}
3564module_exit(octeon_usb_driver_exit);
3604 3565
3605MODULE_LICENSE("GPL"); 3566MODULE_LICENSE("GPL");
3606MODULE_AUTHOR("Cavium Networks <support@caviumnetworks.com>"); 3567MODULE_AUTHOR("Cavium, Inc. <support@cavium.com>");
3607MODULE_DESCRIPTION("Cavium Networks Octeon USB Host driver."); 3568MODULE_DESCRIPTION("Cavium Inc. OCTEON USB Host driver.");
3608module_init(octeon_usb_module_init);
3609module_exit(octeon_usb_module_cleanup);
diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c
index cb060364dfe7..5d965cf06d59 100644
--- a/drivers/staging/ozwpan/ozproto.c
+++ b/drivers/staging/ozwpan/ozproto.c
@@ -668,8 +668,8 @@ void oz_binding_add(const char *net_dev)
668 if (binding) { 668 if (binding) {
669 binding->ptype.type = __constant_htons(OZ_ETHERTYPE); 669 binding->ptype.type = __constant_htons(OZ_ETHERTYPE);
670 binding->ptype.func = oz_pkt_recv; 670 binding->ptype.func = oz_pkt_recv;
671 memcpy(binding->name, net_dev, OZ_MAX_BINDING_LEN);
672 if (net_dev && *net_dev) { 671 if (net_dev && *net_dev) {
672 memcpy(binding->name, net_dev, OZ_MAX_BINDING_LEN);
673 oz_dbg(ON, "Adding binding: %s\n", net_dev); 673 oz_dbg(ON, "Adding binding: %s\n", net_dev);
674 binding->ptype.dev = 674 binding->ptype.dev =
675 dev_get_by_name(&init_net, net_dev); 675 dev_get_by_name(&init_net, net_dev);
@@ -680,6 +680,7 @@ void oz_binding_add(const char *net_dev)
680 } 680 }
681 } else { 681 } else {
682 oz_dbg(ON, "Binding to all netcards\n"); 682 oz_dbg(ON, "Binding to all netcards\n");
683 memset(binding->name, 0, OZ_MAX_BINDING_LEN);
683 binding->ptype.dev = NULL; 684 binding->ptype.dev = NULL;
684 } 685 }
685 if (binding) { 686 if (binding) {
diff --git a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
index 153ec61493ab..96df62f95b6b 100644
--- a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
@@ -912,12 +912,12 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
912 unsigned char *pbuf; 912 unsigned char *pbuf;
913 u32 wpa_ielen = 0; 913 u32 wpa_ielen = 0;
914 u8 *pbssid = GetAddr3Ptr(pframe); 914 u8 *pbssid = GetAddr3Ptr(pframe);
915 u32 hidden_ssid = 0;
916 struct HT_info_element *pht_info = NULL; 915 struct HT_info_element *pht_info = NULL;
917 struct rtw_ieee80211_ht_cap *pht_cap = NULL; 916 struct rtw_ieee80211_ht_cap *pht_cap = NULL;
918 u32 bcn_channel; 917 u32 bcn_channel;
919 unsigned short ht_cap_info; 918 unsigned short ht_cap_info;
920 unsigned char ht_info_infos_0; 919 unsigned char ht_info_infos_0;
920 int ssid_len;
921 921
922 if (is_client_associated_to_ap(Adapter) == false) 922 if (is_client_associated_to_ap(Adapter) == false)
923 return true; 923 return true;
@@ -999,21 +999,15 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
999 } 999 }
1000 1000
1001 /* checking SSID */ 1001 /* checking SSID */
1002 ssid_len = 0;
1002 p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _SSID_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_); 1003 p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _SSID_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
1003 if (p == NULL) { 1004 if (p) {
1004 DBG_88E("%s marc: cannot find SSID for survey event\n", __func__); 1005 ssid_len = *(p + 1);
1005 hidden_ssid = true; 1006 if (ssid_len > NDIS_802_11_LENGTH_SSID)
1006 } else { 1007 ssid_len = 0;
1007 hidden_ssid = false;
1008 }
1009
1010 if ((NULL != p) && (false == hidden_ssid && (*(p + 1)))) {
1011 memcpy(bssid->Ssid.Ssid, (p + 2), *(p + 1));
1012 bssid->Ssid.SsidLength = *(p + 1);
1013 } else {
1014 bssid->Ssid.SsidLength = 0;
1015 bssid->Ssid.Ssid[0] = '\0';
1016 } 1008 }
1009 memcpy(bssid->Ssid.Ssid, (p + 2), ssid_len);
1010 bssid->Ssid.SsidLength = ssid_len;
1017 1011
1018 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s bssid.Ssid.Ssid:%s bssid.Ssid.SsidLength:%d " 1012 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s bssid.Ssid.Ssid:%s bssid.Ssid.SsidLength:%d "
1019 "cur_network->network.Ssid.Ssid:%s len:%d\n", __func__, bssid->Ssid.Ssid, 1013 "cur_network->network.Ssid.Ssid:%s len:%d\n", __func__, bssid->Ssid.Ssid,
diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
index dec992569476..4ad80ae1067f 100644
--- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
@@ -2500,7 +2500,7 @@ static int rtw_mp_ioctl_hdl(struct net_device *dev, struct iw_request_info *info
2500 ("rtw_mp_ioctl_hdl: subcode [%d], len[%d], buffer_len[%d]\r\n", 2500 ("rtw_mp_ioctl_hdl: subcode [%d], len[%d], buffer_len[%d]\r\n",
2501 poidparam->subcode, poidparam->len, len)); 2501 poidparam->subcode, poidparam->len, len));
2502 2502
2503 if (poidparam->subcode >= MAX_MP_IOCTL_SUBCODE) { 2503 if (poidparam->subcode >= ARRAY_SIZE(mp_ioctl_hdl)) {
2504 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("no matching drvext subcodes\r\n")); 2504 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("no matching drvext subcodes\r\n"));
2505 ret = -EINVAL; 2505 ret = -EINVAL;
2506 goto _rtw_mp_ioctl_hdl_exit; 2506 goto _rtw_mp_ioctl_hdl_exit;
@@ -3164,9 +3164,7 @@ static int rtw_p2p_get_go_device_address(struct net_device *dev,
3164 u8 *p2pie; 3164 u8 *p2pie;
3165 uint p2pielen = 0, attr_contentlen = 0; 3165 uint p2pielen = 0, attr_contentlen = 0;
3166 u8 attr_content[100] = {0x00}; 3166 u8 attr_content[100] = {0x00};
3167 3167 u8 go_devadd_str[17 + 12] = {};
3168 u8 go_devadd_str[17 + 10] = {0x00};
3169 /* +10 is for the str "go_devadd =", we have to clear it at wrqu->data.pointer */
3170 3168
3171 /* Commented by Albert 20121209 */ 3169 /* Commented by Albert 20121209 */
3172 /* The input data is the GO's interface address which the application wants to know its device address. */ 3170 /* The input data is the GO's interface address which the application wants to know its device address. */
@@ -3223,12 +3221,12 @@ static int rtw_p2p_get_go_device_address(struct net_device *dev,
3223 spin_unlock_bh(&pmlmepriv->scanned_queue.lock); 3221 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
3224 3222
3225 if (!blnMatch) 3223 if (!blnMatch)
3226 sprintf(go_devadd_str, "\n\ndev_add = NULL"); 3224 snprintf(go_devadd_str, sizeof(go_devadd_str), "\n\ndev_add = NULL");
3227 else 3225 else
3228 sprintf(go_devadd_str, "\n\ndev_add =%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 3226 snprintf(go_devadd_str, sizeof(go_devadd_str), "\n\ndev_add =%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
3229 attr_content[0], attr_content[1], attr_content[2], attr_content[3], attr_content[4], attr_content[5]); 3227 attr_content[0], attr_content[1], attr_content[2], attr_content[3], attr_content[4], attr_content[5]);
3230 3228
3231 if (copy_to_user(wrqu->data.pointer, go_devadd_str, 10 + 17)) 3229 if (copy_to_user(wrqu->data.pointer, go_devadd_str, sizeof(go_devadd_str)))
3232 return -EFAULT; 3230 return -EFAULT;
3233 return ret; 3231 return ret;
3234} 3232}
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index 68f98fa114d2..7c9ee58f47bb 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -653,7 +653,7 @@ static unsigned int rtw_classify8021d(struct sk_buff *skb)
653} 653}
654 654
655static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb, 655static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb,
656 void *accel_priv) 656 void *accel_priv, select_queue_fallback_t fallback)
657{ 657{
658 struct adapter *padapter = rtw_netdev_priv(dev); 658 struct adapter *padapter = rtw_netdev_priv(dev);
659 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 659 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 0a341d6ec51f..2f40ff5901d6 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -53,8 +53,9 @@ static struct usb_device_id rtw_usb_id_tbl[] = {
53 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0179)}, /* 8188ETV */ 53 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0179)}, /* 8188ETV */
54 /*=== Customer ID ===*/ 54 /*=== Customer ID ===*/
55 /****** 8188EUS ********/ 55 /****** 8188EUS ********/
56 {USB_DEVICE(0x8179, 0x07B8)}, /* Abocom - Abocom */ 56 {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */
57 {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */ 57 {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */
58 {USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */
58 {} /* Terminating entry */ 59 {} /* Terminating entry */
59}; 60};
60 61
diff --git a/drivers/staging/rtl8821ae/Kconfig b/drivers/staging/rtl8821ae/Kconfig
index 2aa5dac2f1df..abccc9dabd65 100644
--- a/drivers/staging/rtl8821ae/Kconfig
+++ b/drivers/staging/rtl8821ae/Kconfig
@@ -1,6 +1,6 @@
1config R8821AE 1config R8821AE
2 tristate "RealTek RTL8821AE Wireless LAN NIC driver" 2 tristate "RealTek RTL8821AE Wireless LAN NIC driver"
3 depends on PCI && WLAN 3 depends on PCI && WLAN && MAC80211
4 depends on m 4 depends on m
5 select WIRELESS_EXT 5 select WIRELESS_EXT
6 select WEXT_PRIV 6 select WEXT_PRIV
diff --git a/drivers/staging/rtl8821ae/wifi.h b/drivers/staging/rtl8821ae/wifi.h
index cfe88a1efd55..76bef93ad70a 100644
--- a/drivers/staging/rtl8821ae/wifi.h
+++ b/drivers/staging/rtl8821ae/wifi.h
@@ -1414,7 +1414,7 @@ struct rtl_dm {
1414 1414
1415 1415
1416 /*88e tx power tracking*/ 1416 /*88e tx power tracking*/
1417 u8 bb_swing_idx_ofdm[2]; 1417 u8 bb_swing_idx_ofdm[MAX_RF_PATH];
1418 u8 bb_swing_idx_ofdm_current; 1418 u8 bb_swing_idx_ofdm_current;
1419 u8 bb_swing_idx_ofdm_base[MAX_RF_PATH]; 1419 u8 bb_swing_idx_ofdm_base[MAX_RF_PATH];
1420 bool bb_swing_flag_Ofdm; 1420 bool bb_swing_flag_Ofdm;
diff --git a/drivers/staging/usbip/userspace/libsrc/names.c b/drivers/staging/usbip/userspace/libsrc/names.c
index 3c8d28b771e0..81ff8522405c 100644
--- a/drivers/staging/usbip/userspace/libsrc/names.c
+++ b/drivers/staging/usbip/userspace/libsrc/names.c
@@ -169,14 +169,14 @@ static void *my_malloc(size_t size)
169 struct pool *p; 169 struct pool *p;
170 170
171 p = calloc(1, sizeof(struct pool)); 171 p = calloc(1, sizeof(struct pool));
172 if (!p) { 172 if (!p)
173 free(p);
174 return NULL; 173 return NULL;
175 }
176 174
177 p->mem = calloc(1, size); 175 p->mem = calloc(1, size);
178 if (!p->mem) 176 if (!p->mem) {
177 free(p);
179 return NULL; 178 return NULL;
179 }
180 180
181 p->next = pool_head; 181 p->next = pool_head;
182 pool_head = p; 182 pool_head = p;
diff --git a/drivers/staging/usbip/vhci_sysfs.c b/drivers/staging/usbip/vhci_sysfs.c
index 9b51586d11d9..0141bc34d5cc 100644
--- a/drivers/staging/usbip/vhci_sysfs.c
+++ b/drivers/staging/usbip/vhci_sysfs.c
@@ -149,7 +149,8 @@ static int valid_args(__u32 rhport, enum usb_device_speed speed)
149 case USB_SPEED_WIRELESS: 149 case USB_SPEED_WIRELESS:
150 break; 150 break;
151 default: 151 default:
152 pr_err("speed %d\n", speed); 152 pr_err("Failed attach request for unsupported USB speed: %s\n",
153 usb_speed_string(speed));
153 return -EINVAL; 154 return -EINVAL;
154 } 155 }
155 156
diff --git a/drivers/staging/wlags49_h2/wl_wext.c b/drivers/staging/wlags49_h2/wl_wext.c
index 4a1ddaf5e00f..187fc060de26 100644
--- a/drivers/staging/wlags49_h2/wl_wext.c
+++ b/drivers/staging/wlags49_h2/wl_wext.c
@@ -1061,7 +1061,7 @@ static int wireless_set_essid(struct net_device *dev, struct iw_request_info *in
1061 goto out; 1061 goto out;
1062 } 1062 }
1063 1063
1064 if (data->flags != 0 && data->length > HCF_MAX_NAME_LEN + 1) { 1064 if (data->flags != 0 && data->length > HCF_MAX_NAME_LEN) {
1065 ret = -EINVAL; 1065 ret = -EINVAL;
1066 goto out; 1066 goto out;
1067 } 1067 }
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 7f1a7ce4b771..b83ec378d04f 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -785,7 +785,7 @@ static void iscsit_ack_from_expstatsn(struct iscsi_conn *conn, u32 exp_statsn)
785 spin_unlock_bh(&conn->cmd_lock); 785 spin_unlock_bh(&conn->cmd_lock);
786 786
787 list_for_each_entry_safe(cmd, cmd_p, &ack_list, i_conn_node) { 787 list_for_each_entry_safe(cmd, cmd_p, &ack_list, i_conn_node) {
788 list_del(&cmd->i_conn_node); 788 list_del_init(&cmd->i_conn_node);
789 iscsit_free_cmd(cmd, false); 789 iscsit_free_cmd(cmd, false);
790 } 790 }
791} 791}
@@ -3708,7 +3708,7 @@ iscsit_immediate_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state
3708 break; 3708 break;
3709 case ISTATE_REMOVE: 3709 case ISTATE_REMOVE:
3710 spin_lock_bh(&conn->cmd_lock); 3710 spin_lock_bh(&conn->cmd_lock);
3711 list_del(&cmd->i_conn_node); 3711 list_del_init(&cmd->i_conn_node);
3712 spin_unlock_bh(&conn->cmd_lock); 3712 spin_unlock_bh(&conn->cmd_lock);
3713 3713
3714 iscsit_free_cmd(cmd, false); 3714 iscsit_free_cmd(cmd, false);
@@ -4151,7 +4151,7 @@ static void iscsit_release_commands_from_conn(struct iscsi_conn *conn)
4151 spin_lock_bh(&conn->cmd_lock); 4151 spin_lock_bh(&conn->cmd_lock);
4152 list_for_each_entry_safe(cmd, cmd_tmp, &conn->conn_cmd_list, i_conn_node) { 4152 list_for_each_entry_safe(cmd, cmd_tmp, &conn->conn_cmd_list, i_conn_node) {
4153 4153
4154 list_del(&cmd->i_conn_node); 4154 list_del_init(&cmd->i_conn_node);
4155 spin_unlock_bh(&conn->cmd_lock); 4155 spin_unlock_bh(&conn->cmd_lock);
4156 4156
4157 iscsit_increment_maxcmdsn(cmd, sess); 4157 iscsit_increment_maxcmdsn(cmd, sess);
@@ -4196,6 +4196,10 @@ int iscsit_close_connection(
4196 iscsit_stop_timers_for_cmds(conn); 4196 iscsit_stop_timers_for_cmds(conn);
4197 iscsit_stop_nopin_response_timer(conn); 4197 iscsit_stop_nopin_response_timer(conn);
4198 iscsit_stop_nopin_timer(conn); 4198 iscsit_stop_nopin_timer(conn);
4199
4200 if (conn->conn_transport->iscsit_wait_conn)
4201 conn->conn_transport->iscsit_wait_conn(conn);
4202
4199 iscsit_free_queue_reqs_for_conn(conn); 4203 iscsit_free_queue_reqs_for_conn(conn);
4200 4204
4201 /* 4205 /*
diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
index e048d6439f4a..cda4d80cfaef 100644
--- a/drivers/target/iscsi/iscsi_target_erl1.c
+++ b/drivers/target/iscsi/iscsi_target_erl1.c
@@ -507,7 +507,9 @@ int iscsit_handle_status_snack(
507 u32 last_statsn; 507 u32 last_statsn;
508 int found_cmd; 508 int found_cmd;
509 509
510 if (conn->exp_statsn > begrun) { 510 if (!begrun) {
511 begrun = conn->exp_statsn;
512 } else if (conn->exp_statsn > begrun) {
511 pr_err("Got Status SNACK Begrun: 0x%08x, RunLength:" 513 pr_err("Got Status SNACK Begrun: 0x%08x, RunLength:"
512 " 0x%08x but already got ExpStatSN: 0x%08x on CID:" 514 " 0x%08x but already got ExpStatSN: 0x%08x on CID:"
513 " %hu.\n", begrun, runlength, conn->exp_statsn, 515 " %hu.\n", begrun, runlength, conn->exp_statsn,
diff --git a/drivers/target/iscsi/iscsi_target_erl2.c b/drivers/target/iscsi/iscsi_target_erl2.c
index 33be1fb1df32..4ca8fd2a70db 100644
--- a/drivers/target/iscsi/iscsi_target_erl2.c
+++ b/drivers/target/iscsi/iscsi_target_erl2.c
@@ -138,7 +138,7 @@ void iscsit_free_connection_recovery_entires(struct iscsi_session *sess)
138 list_for_each_entry_safe(cmd, cmd_tmp, 138 list_for_each_entry_safe(cmd, cmd_tmp,
139 &cr->conn_recovery_cmd_list, i_conn_node) { 139 &cr->conn_recovery_cmd_list, i_conn_node) {
140 140
141 list_del(&cmd->i_conn_node); 141 list_del_init(&cmd->i_conn_node);
142 cmd->conn = NULL; 142 cmd->conn = NULL;
143 spin_unlock(&cr->conn_recovery_cmd_lock); 143 spin_unlock(&cr->conn_recovery_cmd_lock);
144 iscsit_free_cmd(cmd, true); 144 iscsit_free_cmd(cmd, true);
@@ -160,7 +160,7 @@ void iscsit_free_connection_recovery_entires(struct iscsi_session *sess)
160 list_for_each_entry_safe(cmd, cmd_tmp, 160 list_for_each_entry_safe(cmd, cmd_tmp,
161 &cr->conn_recovery_cmd_list, i_conn_node) { 161 &cr->conn_recovery_cmd_list, i_conn_node) {
162 162
163 list_del(&cmd->i_conn_node); 163 list_del_init(&cmd->i_conn_node);
164 cmd->conn = NULL; 164 cmd->conn = NULL;
165 spin_unlock(&cr->conn_recovery_cmd_lock); 165 spin_unlock(&cr->conn_recovery_cmd_lock);
166 iscsit_free_cmd(cmd, true); 166 iscsit_free_cmd(cmd, true);
@@ -216,7 +216,7 @@ int iscsit_remove_cmd_from_connection_recovery(
216 } 216 }
217 cr = cmd->cr; 217 cr = cmd->cr;
218 218
219 list_del(&cmd->i_conn_node); 219 list_del_init(&cmd->i_conn_node);
220 return --cr->cmd_count; 220 return --cr->cmd_count;
221} 221}
222 222
@@ -297,7 +297,7 @@ int iscsit_discard_unacknowledged_ooo_cmdsns_for_conn(struct iscsi_conn *conn)
297 if (!(cmd->cmd_flags & ICF_OOO_CMDSN)) 297 if (!(cmd->cmd_flags & ICF_OOO_CMDSN))
298 continue; 298 continue;
299 299
300 list_del(&cmd->i_conn_node); 300 list_del_init(&cmd->i_conn_node);
301 301
302 spin_unlock_bh(&conn->cmd_lock); 302 spin_unlock_bh(&conn->cmd_lock);
303 iscsit_free_cmd(cmd, true); 303 iscsit_free_cmd(cmd, true);
@@ -335,7 +335,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
335 /* 335 /*
336 * Only perform connection recovery on ISCSI_OP_SCSI_CMD or 336 * Only perform connection recovery on ISCSI_OP_SCSI_CMD or
337 * ISCSI_OP_NOOP_OUT opcodes. For all other opcodes call 337 * ISCSI_OP_NOOP_OUT opcodes. For all other opcodes call
338 * list_del(&cmd->i_conn_node); to release the command to the 338 * list_del_init(&cmd->i_conn_node); to release the command to the
339 * session pool and remove it from the connection's list. 339 * session pool and remove it from the connection's list.
340 * 340 *
341 * Also stop the DataOUT timer, which will be restarted after 341 * Also stop the DataOUT timer, which will be restarted after
@@ -351,7 +351,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
351 " CID: %hu\n", cmd->iscsi_opcode, 351 " CID: %hu\n", cmd->iscsi_opcode,
352 cmd->init_task_tag, cmd->cmd_sn, conn->cid); 352 cmd->init_task_tag, cmd->cmd_sn, conn->cid);
353 353
354 list_del(&cmd->i_conn_node); 354 list_del_init(&cmd->i_conn_node);
355 spin_unlock_bh(&conn->cmd_lock); 355 spin_unlock_bh(&conn->cmd_lock);
356 iscsit_free_cmd(cmd, true); 356 iscsit_free_cmd(cmd, true);
357 spin_lock_bh(&conn->cmd_lock); 357 spin_lock_bh(&conn->cmd_lock);
@@ -371,7 +371,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
371 */ 371 */
372 if (!(cmd->cmd_flags & ICF_OOO_CMDSN) && !cmd->immediate_cmd && 372 if (!(cmd->cmd_flags & ICF_OOO_CMDSN) && !cmd->immediate_cmd &&
373 iscsi_sna_gte(cmd->cmd_sn, conn->sess->exp_cmd_sn)) { 373 iscsi_sna_gte(cmd->cmd_sn, conn->sess->exp_cmd_sn)) {
374 list_del(&cmd->i_conn_node); 374 list_del_init(&cmd->i_conn_node);
375 spin_unlock_bh(&conn->cmd_lock); 375 spin_unlock_bh(&conn->cmd_lock);
376 iscsit_free_cmd(cmd, true); 376 iscsit_free_cmd(cmd, true);
377 spin_lock_bh(&conn->cmd_lock); 377 spin_lock_bh(&conn->cmd_lock);
@@ -393,7 +393,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
393 393
394 cmd->sess = conn->sess; 394 cmd->sess = conn->sess;
395 395
396 list_del(&cmd->i_conn_node); 396 list_del_init(&cmd->i_conn_node);
397 spin_unlock_bh(&conn->cmd_lock); 397 spin_unlock_bh(&conn->cmd_lock);
398 398
399 iscsit_free_all_datain_reqs(cmd); 399 iscsit_free_all_datain_reqs(cmd);
diff --git a/drivers/target/iscsi/iscsi_target_tpg.c b/drivers/target/iscsi/iscsi_target_tpg.c
index 39761837608d..44a5471de00f 100644
--- a/drivers/target/iscsi/iscsi_target_tpg.c
+++ b/drivers/target/iscsi/iscsi_target_tpg.c
@@ -137,7 +137,7 @@ struct iscsi_portal_group *iscsit_get_tpg_from_np(
137 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) { 137 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) {
138 138
139 spin_lock(&tpg->tpg_state_lock); 139 spin_lock(&tpg->tpg_state_lock);
140 if (tpg->tpg_state == TPG_STATE_FREE) { 140 if (tpg->tpg_state != TPG_STATE_ACTIVE) {
141 spin_unlock(&tpg->tpg_state_lock); 141 spin_unlock(&tpg->tpg_state_lock);
142 continue; 142 continue;
143 } 143 }
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index 12da9b386169..c3d9df6aaf5f 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -500,7 +500,7 @@ static inline int core_alua_state_lba_dependent(
500 500
501 if (segment_mult) { 501 if (segment_mult) {
502 u64 tmp = lba; 502 u64 tmp = lba;
503 start_lba = sector_div(tmp, segment_size * segment_mult); 503 start_lba = do_div(tmp, segment_size * segment_mult);
504 504
505 last_lba = first_lba + segment_size - 1; 505 last_lba = first_lba + segment_size - 1;
506 if (start_lba >= first_lba && 506 if (start_lba >= first_lba &&
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 2f5d77932c80..3013287a2aaa 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -2009,7 +2009,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
2009 struct t10_reservation *pr_tmpl = &dev->t10_pr; 2009 struct t10_reservation *pr_tmpl = &dev->t10_pr;
2010 unsigned char isid_buf[PR_REG_ISID_LEN], *isid_ptr = NULL; 2010 unsigned char isid_buf[PR_REG_ISID_LEN], *isid_ptr = NULL;
2011 sense_reason_t ret = TCM_NO_SENSE; 2011 sense_reason_t ret = TCM_NO_SENSE;
2012 int pr_holder = 0; 2012 int pr_holder = 0, type;
2013 2013
2014 if (!se_sess || !se_lun) { 2014 if (!se_sess || !se_lun) {
2015 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n"); 2015 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n");
@@ -2131,6 +2131,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
2131 ret = TCM_RESERVATION_CONFLICT; 2131 ret = TCM_RESERVATION_CONFLICT;
2132 goto out; 2132 goto out;
2133 } 2133 }
2134 type = pr_reg->pr_res_type;
2134 2135
2135 spin_lock(&pr_tmpl->registration_lock); 2136 spin_lock(&pr_tmpl->registration_lock);
2136 /* 2137 /*
@@ -2161,6 +2162,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
2161 * Release the calling I_T Nexus registration now.. 2162 * Release the calling I_T Nexus registration now..
2162 */ 2163 */
2163 __core_scsi3_free_registration(cmd->se_dev, pr_reg, NULL, 1); 2164 __core_scsi3_free_registration(cmd->se_dev, pr_reg, NULL, 1);
2165 pr_reg = NULL;
2164 2166
2165 /* 2167 /*
2166 * From spc4r17, section 5.7.11.3 Unregistering 2168 * From spc4r17, section 5.7.11.3 Unregistering
@@ -2174,8 +2176,8 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
2174 * RESERVATIONS RELEASED. 2176 * RESERVATIONS RELEASED.
2175 */ 2177 */
2176 if (pr_holder && 2178 if (pr_holder &&
2177 (pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY || 2179 (type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY ||
2178 pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY)) { 2180 type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY)) {
2179 list_for_each_entry(pr_reg_p, 2181 list_for_each_entry(pr_reg_p,
2180 &pr_tmpl->registration_list, 2182 &pr_tmpl->registration_list,
2181 pr_reg_list) { 2183 pr_reg_list) {
@@ -2194,7 +2196,8 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key,
2194 ret = core_scsi3_update_and_write_aptpl(dev, aptpl); 2196 ret = core_scsi3_update_and_write_aptpl(dev, aptpl);
2195 2197
2196out: 2198out:
2197 core_scsi3_put_pr_reg(pr_reg); 2199 if (pr_reg)
2200 core_scsi3_put_pr_reg(pr_reg);
2198 return ret; 2201 return ret;
2199} 2202}
2200 2203
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index fa3cae393e13..77e6531fb0a1 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -1074,23 +1074,36 @@ sbc_dif_copy_prot(struct se_cmd *cmd, unsigned int sectors, bool read,
1074 struct scatterlist *psg; 1074 struct scatterlist *psg;
1075 void *paddr, *addr; 1075 void *paddr, *addr;
1076 unsigned int i, len, left; 1076 unsigned int i, len, left;
1077 unsigned int offset = sg_off;
1077 1078
1078 left = sectors * dev->prot_length; 1079 left = sectors * dev->prot_length;
1079 1080
1080 for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) { 1081 for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) {
1082 unsigned int psg_len, copied = 0;
1081 1083
1082 len = min(psg->length, left);
1083 paddr = kmap_atomic(sg_page(psg)) + psg->offset; 1084 paddr = kmap_atomic(sg_page(psg)) + psg->offset;
1084 addr = kmap_atomic(sg_page(sg)) + sg_off; 1085 psg_len = min(left, psg->length);
1086 while (psg_len) {
1087 len = min(psg_len, sg->length - offset);
1088 addr = kmap_atomic(sg_page(sg)) + sg->offset + offset;
1085 1089
1086 if (read) 1090 if (read)
1087 memcpy(paddr, addr, len); 1091 memcpy(paddr + copied, addr, len);
1088 else 1092 else
1089 memcpy(addr, paddr, len); 1093 memcpy(addr, paddr + copied, len);
1090 1094
1091 left -= len; 1095 left -= len;
1096 offset += len;
1097 copied += len;
1098 psg_len -= len;
1099
1100 if (offset >= sg->length) {
1101 sg = sg_next(sg);
1102 offset = 0;
1103 }
1104 kunmap_atomic(addr);
1105 }
1092 kunmap_atomic(paddr); 1106 kunmap_atomic(paddr);
1093 kunmap_atomic(addr);
1094 } 1107 }
1095} 1108}
1096 1109
@@ -1155,7 +1168,7 @@ sbc_dif_verify_read(struct se_cmd *cmd, sector_t start, unsigned int sectors,
1155{ 1168{
1156 struct se_device *dev = cmd->se_dev; 1169 struct se_device *dev = cmd->se_dev;
1157 struct se_dif_v1_tuple *sdt; 1170 struct se_dif_v1_tuple *sdt;
1158 struct scatterlist *dsg; 1171 struct scatterlist *dsg, *psg = sg;
1159 sector_t sector = start; 1172 sector_t sector = start;
1160 void *daddr, *paddr; 1173 void *daddr, *paddr;
1161 int i, j, offset = sg_off; 1174 int i, j, offset = sg_off;
@@ -1163,14 +1176,14 @@ sbc_dif_verify_read(struct se_cmd *cmd, sector_t start, unsigned int sectors,
1163 1176
1164 for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) { 1177 for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) {
1165 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1178 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset;
1166 paddr = kmap_atomic(sg_page(sg)) + sg->offset; 1179 paddr = kmap_atomic(sg_page(psg)) + sg->offset;
1167 1180
1168 for (j = 0; j < dsg->length; j += dev->dev_attrib.block_size) { 1181 for (j = 0; j < dsg->length; j += dev->dev_attrib.block_size) {
1169 1182
1170 if (offset >= sg->length) { 1183 if (offset >= psg->length) {
1171 kunmap_atomic(paddr); 1184 kunmap_atomic(paddr);
1172 sg = sg_next(sg); 1185 psg = sg_next(psg);
1173 paddr = kmap_atomic(sg_page(sg)) + sg->offset; 1186 paddr = kmap_atomic(sg_page(psg)) + psg->offset;
1174 offset = 0; 1187 offset = 0;
1175 } 1188 }
1176 1189
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index 43c5ca9878bc..3bebc71ea033 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -440,8 +440,8 @@ check_scsi_name:
440 padding = ((-scsi_target_len) & 3); 440 padding = ((-scsi_target_len) & 3);
441 if (padding) 441 if (padding)
442 scsi_target_len += padding; 442 scsi_target_len += padding;
443 if (scsi_name_len > 256) 443 if (scsi_target_len > 256)
444 scsi_name_len = 256; 444 scsi_target_len = 256;
445 445
446 buf[off-1] = scsi_target_len; 446 buf[off-1] = scsi_target_len;
447 off += scsi_target_len; 447 off += scsi_target_len;
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index c50fd9f11aab..2956250b7225 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -669,9 +669,6 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
669 return; 669 return;
670 } 670 }
671 671
672 if (!success)
673 cmd->transport_state |= CMD_T_FAILED;
674
675 /* 672 /*
676 * Check for case where an explicit ABORT_TASK has been received 673 * Check for case where an explicit ABORT_TASK has been received
677 * and transport_wait_for_tasks() will be waiting for completion.. 674 * and transport_wait_for_tasks() will be waiting for completion..
@@ -681,7 +678,7 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
681 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 678 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
682 complete(&cmd->t_transport_stop_comp); 679 complete(&cmd->t_transport_stop_comp);
683 return; 680 return;
684 } else if (cmd->transport_state & CMD_T_FAILED) { 681 } else if (!success) {
685 INIT_WORK(&cmd->work, target_complete_failure_work); 682 INIT_WORK(&cmd->work, target_complete_failure_work);
686 } else { 683 } else {
687 INIT_WORK(&cmd->work, target_complete_ok_work); 684 INIT_WORK(&cmd->work, target_complete_ok_work);
@@ -1604,6 +1601,9 @@ void transport_generic_request_failure(struct se_cmd *cmd,
1604 case TCM_CHECK_CONDITION_ABORT_CMD: 1601 case TCM_CHECK_CONDITION_ABORT_CMD:
1605 case TCM_CHECK_CONDITION_UNIT_ATTENTION: 1602 case TCM_CHECK_CONDITION_UNIT_ATTENTION:
1606 case TCM_CHECK_CONDITION_NOT_READY: 1603 case TCM_CHECK_CONDITION_NOT_READY:
1604 case TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED:
1605 case TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED:
1606 case TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED:
1607 break; 1607 break;
1608 case TCM_OUT_OF_RESOURCES: 1608 case TCM_OUT_OF_RESOURCES:
1609 sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 1609 sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 35c066489a19..5f88d767671e 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -136,6 +136,7 @@ config SPEAR_THERMAL
136config RCAR_THERMAL 136config RCAR_THERMAL
137 tristate "Renesas R-Car thermal driver" 137 tristate "Renesas R-Car thermal driver"
138 depends on ARCH_SHMOBILE || COMPILE_TEST 138 depends on ARCH_SHMOBILE || COMPILE_TEST
139 depends on HAS_IOMEM
139 help 140 help
140 Enable this to plug the R-Car thermal sensor driver into the Linux 141 Enable this to plug the R-Car thermal sensor driver into the Linux
141 thermal framework. 142 thermal framework.
@@ -210,8 +211,16 @@ config ACPI_INT3403_THERMAL
210 tristate "ACPI INT3403 thermal driver" 211 tristate "ACPI INT3403 thermal driver"
211 depends on X86 && ACPI 212 depends on X86 && ACPI
212 help 213 help
213 This driver uses ACPI INT3403 device objects. If present, it will 214 Newer laptops and tablets that use ACPI may have thermal sensors
214 register each INT3403 thermal sensor as a thermal zone. 215 outside the core CPU/SOC for thermal safety reasons. These
216 temperature sensors are also exposed for the OS to use via the so
217 called INT3403 ACPI object. This driver will, on devices that have
218 such sensors, expose the temperature information from these sensors
219 to userspace via the normal thermal framework. This means that a wide
220 range of applications and GUI widgets can show this information to
221 the user or use this information for making decisions. For example,
222 the Intel Thermal Daemon can use this information to allow the user
223 to select his laptop to run without turning on the fans.
215 224
216menu "Texas Instruments thermal drivers" 225menu "Texas Instruments thermal drivers"
217source "drivers/thermal/ti-soc-thermal/Kconfig" 226source "drivers/thermal/ti-soc-thermal/Kconfig"
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 338a88bf6662..71b0ec0c370d 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -56,10 +56,15 @@ static LIST_HEAD(thermal_governor_list);
56static DEFINE_MUTEX(thermal_list_lock); 56static DEFINE_MUTEX(thermal_list_lock);
57static DEFINE_MUTEX(thermal_governor_lock); 57static DEFINE_MUTEX(thermal_governor_lock);
58 58
59static struct thermal_governor *def_governor;
60
59static struct thermal_governor *__find_governor(const char *name) 61static struct thermal_governor *__find_governor(const char *name)
60{ 62{
61 struct thermal_governor *pos; 63 struct thermal_governor *pos;
62 64
65 if (!name || !name[0])
66 return def_governor;
67
63 list_for_each_entry(pos, &thermal_governor_list, governor_list) 68 list_for_each_entry(pos, &thermal_governor_list, governor_list)
64 if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH)) 69 if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
65 return pos; 70 return pos;
@@ -82,17 +87,23 @@ int thermal_register_governor(struct thermal_governor *governor)
82 if (__find_governor(governor->name) == NULL) { 87 if (__find_governor(governor->name) == NULL) {
83 err = 0; 88 err = 0;
84 list_add(&governor->governor_list, &thermal_governor_list); 89 list_add(&governor->governor_list, &thermal_governor_list);
90 if (!def_governor && !strncmp(governor->name,
91 DEFAULT_THERMAL_GOVERNOR, THERMAL_NAME_LENGTH))
92 def_governor = governor;
85 } 93 }
86 94
87 mutex_lock(&thermal_list_lock); 95 mutex_lock(&thermal_list_lock);
88 96
89 list_for_each_entry(pos, &thermal_tz_list, node) { 97 list_for_each_entry(pos, &thermal_tz_list, node) {
98 /*
99 * only thermal zones with specified tz->tzp->governor_name
100 * may run with tz->govenor unset
101 */
90 if (pos->governor) 102 if (pos->governor)
91 continue; 103 continue;
92 if (pos->tzp) 104
93 name = pos->tzp->governor_name; 105 name = pos->tzp->governor_name;
94 else 106
95 name = DEFAULT_THERMAL_GOVERNOR;
96 if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH)) 107 if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
97 pos->governor = governor; 108 pos->governor = governor;
98 } 109 }
@@ -342,8 +353,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
342static void handle_non_critical_trips(struct thermal_zone_device *tz, 353static void handle_non_critical_trips(struct thermal_zone_device *tz,
343 int trip, enum thermal_trip_type trip_type) 354 int trip, enum thermal_trip_type trip_type)
344{ 355{
345 if (tz->governor) 356 tz->governor ? tz->governor->throttle(tz, trip) :
346 tz->governor->throttle(tz, trip); 357 def_governor->throttle(tz, trip);
347} 358}
348 359
349static void handle_critical_trips(struct thermal_zone_device *tz, 360static void handle_critical_trips(struct thermal_zone_device *tz,
@@ -1107,7 +1118,7 @@ __thermal_cooling_device_register(struct device_node *np,
1107 INIT_LIST_HEAD(&cdev->thermal_instances); 1118 INIT_LIST_HEAD(&cdev->thermal_instances);
1108 cdev->np = np; 1119 cdev->np = np;
1109 cdev->ops = ops; 1120 cdev->ops = ops;
1110 cdev->updated = true; 1121 cdev->updated = false;
1111 cdev->device.class = &thermal_class; 1122 cdev->device.class = &thermal_class;
1112 cdev->devdata = devdata; 1123 cdev->devdata = devdata;
1113 dev_set_name(&cdev->device, "cooling_device%d", cdev->id); 1124 dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
@@ -1533,7 +1544,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
1533 if (tz->tzp) 1544 if (tz->tzp)
1534 tz->governor = __find_governor(tz->tzp->governor_name); 1545 tz->governor = __find_governor(tz->tzp->governor_name);
1535 else 1546 else
1536 tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR); 1547 tz->governor = def_governor;
1537 1548
1538 mutex_unlock(&thermal_governor_lock); 1549 mutex_unlock(&thermal_governor_lock);
1539 1550
diff --git a/drivers/thermal/x86_pkg_temp_thermal.c b/drivers/thermal/x86_pkg_temp_thermal.c
index 972e1c73722a..081fd7e6a9f0 100644
--- a/drivers/thermal/x86_pkg_temp_thermal.c
+++ b/drivers/thermal/x86_pkg_temp_thermal.c
@@ -68,6 +68,10 @@ struct phy_dev_entry {
68 struct thermal_zone_device *tzone; 68 struct thermal_zone_device *tzone;
69}; 69};
70 70
71static const struct thermal_zone_params pkg_temp_tz_params = {
72 .no_hwmon = true,
73};
74
71/* List maintaining number of package instances */ 75/* List maintaining number of package instances */
72static LIST_HEAD(phy_dev_list); 76static LIST_HEAD(phy_dev_list);
73static DEFINE_MUTEX(phy_dev_list_mutex); 77static DEFINE_MUTEX(phy_dev_list_mutex);
@@ -394,7 +398,6 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
394 int err; 398 int err;
395 u32 tj_max; 399 u32 tj_max;
396 struct phy_dev_entry *phy_dev_entry; 400 struct phy_dev_entry *phy_dev_entry;
397 char buffer[30];
398 int thres_count; 401 int thres_count;
399 u32 eax, ebx, ecx, edx; 402 u32 eax, ebx, ecx, edx;
400 u8 *temp; 403 u8 *temp;
@@ -440,13 +443,11 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
440 phy_dev_entry->first_cpu = cpu; 443 phy_dev_entry->first_cpu = cpu;
441 phy_dev_entry->tj_max = tj_max; 444 phy_dev_entry->tj_max = tj_max;
442 phy_dev_entry->ref_cnt = 1; 445 phy_dev_entry->ref_cnt = 1;
443 snprintf(buffer, sizeof(buffer), "pkg-temp-%d\n", 446 phy_dev_entry->tzone = thermal_zone_device_register("x86_pkg_temp",
444 phy_dev_entry->phys_proc_id);
445 phy_dev_entry->tzone = thermal_zone_device_register(buffer,
446 thres_count, 447 thres_count,
447 (thres_count == MAX_NUMBER_OF_TRIPS) ? 448 (thres_count == MAX_NUMBER_OF_TRIPS) ?
448 0x03 : 0x01, 449 0x03 : 0x01,
449 phy_dev_entry, &tzone_ops, NULL, 0, 0); 450 phy_dev_entry, &tzone_ops, &pkg_temp_tz_params, 0, 0);
450 if (IS_ERR(phy_dev_entry->tzone)) { 451 if (IS_ERR(phy_dev_entry->tzone)) {
451 err = PTR_ERR(phy_dev_entry->tzone); 452 err = PTR_ERR(phy_dev_entry->tzone);
452 goto err_ret_free; 453 goto err_ret_free;
diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
index 6496872e2e47..b01659bd4f7c 100644
--- a/drivers/tty/hvc/hvc_opal.c
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -255,13 +255,7 @@ static int __init hvc_opal_init(void)
255 /* Register as a vio device to receive callbacks */ 255 /* Register as a vio device to receive callbacks */
256 return platform_driver_register(&hvc_opal_driver); 256 return platform_driver_register(&hvc_opal_driver);
257} 257}
258module_init(hvc_opal_init); 258device_initcall(hvc_opal_init);
259
260static void __exit hvc_opal_exit(void)
261{
262 platform_driver_unregister(&hvc_opal_driver);
263}
264module_exit(hvc_opal_exit);
265 259
266static void udbg_opal_putc(char c) 260static void udbg_opal_putc(char c)
267{ 261{
diff --git a/drivers/tty/hvc/hvc_rtas.c b/drivers/tty/hvc/hvc_rtas.c
index 0069bb86ba49..08c87920b74a 100644
--- a/drivers/tty/hvc/hvc_rtas.c
+++ b/drivers/tty/hvc/hvc_rtas.c
@@ -102,17 +102,7 @@ static int __init hvc_rtas_init(void)
102 102
103 return 0; 103 return 0;
104} 104}
105module_init(hvc_rtas_init); 105device_initcall(hvc_rtas_init);
106
107/* This will tear down the tty portion of the driver */
108static void __exit hvc_rtas_exit(void)
109{
110 /* Really the fun isn't over until the worker thread breaks down and
111 * the tty cleans up */
112 if (hvc_rtas_dev)
113 hvc_remove(hvc_rtas_dev);
114}
115module_exit(hvc_rtas_exit);
116 106
117/* This will happen prior to module init. There is no tty at this time? */ 107/* This will happen prior to module init. There is no tty at this time? */
118static int __init hvc_rtas_console_init(void) 108static int __init hvc_rtas_console_init(void)
diff --git a/drivers/tty/hvc/hvc_udbg.c b/drivers/tty/hvc/hvc_udbg.c
index 72228276fe31..9cf573d06a29 100644
--- a/drivers/tty/hvc/hvc_udbg.c
+++ b/drivers/tty/hvc/hvc_udbg.c
@@ -80,14 +80,7 @@ static int __init hvc_udbg_init(void)
80 80
81 return 0; 81 return 0;
82} 82}
83module_init(hvc_udbg_init); 83device_initcall(hvc_udbg_init);
84
85static void __exit hvc_udbg_exit(void)
86{
87 if (hvc_udbg_dev)
88 hvc_remove(hvc_udbg_dev);
89}
90module_exit(hvc_udbg_exit);
91 84
92static int __init hvc_udbg_console_init(void) 85static int __init hvc_udbg_console_init(void)
93{ 86{
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index 636c9baad7a5..2dc2831840ca 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -561,18 +561,7 @@ static int __init xen_hvc_init(void)
561#endif 561#endif
562 return r; 562 return r;
563} 563}
564 564device_initcall(xen_hvc_init);
565static void __exit xen_hvc_fini(void)
566{
567 struct xencons_info *entry, *next;
568
569 if (list_empty(&xenconsoles))
570 return;
571
572 list_for_each_entry_safe(entry, next, &xenconsoles, list) {
573 xen_console_remove(entry);
574 }
575}
576 565
577static int xen_cons_init(void) 566static int xen_cons_init(void)
578{ 567{
@@ -598,10 +587,6 @@ static int xen_cons_init(void)
598 hvc_instantiate(HVC_COOKIE, 0, ops); 587 hvc_instantiate(HVC_COOKIE, 0, ops);
599 return 0; 588 return 0;
600} 589}
601
602
603module_init(xen_hvc_init);
604module_exit(xen_hvc_fini);
605console_initcall(xen_cons_init); 590console_initcall(xen_cons_init);
606 591
607#ifdef CONFIG_EARLY_PRINTK 592#ifdef CONFIG_EARLY_PRINTK
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index f34461c5f14e..2ebe47b78a3e 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -1090,6 +1090,7 @@ static void gsm_control_modem(struct gsm_mux *gsm, u8 *data, int clen)
1090{ 1090{
1091 unsigned int addr = 0; 1091 unsigned int addr = 0;
1092 unsigned int modem = 0; 1092 unsigned int modem = 0;
1093 unsigned int brk = 0;
1093 struct gsm_dlci *dlci; 1094 struct gsm_dlci *dlci;
1094 int len = clen; 1095 int len = clen;
1095 u8 *dp = data; 1096 u8 *dp = data;
@@ -1116,6 +1117,16 @@ static void gsm_control_modem(struct gsm_mux *gsm, u8 *data, int clen)
1116 if (len == 0) 1117 if (len == 0)
1117 return; 1118 return;
1118 } 1119 }
1120 len--;
1121 if (len > 0) {
1122 while (gsm_read_ea(&brk, *dp++) == 0) {
1123 len--;
1124 if (len == 0)
1125 return;
1126 }
1127 modem <<= 7;
1128 modem |= (brk & 0x7f);
1129 }
1119 tty = tty_port_tty_get(&dlci->port); 1130 tty = tty_port_tty_get(&dlci->port);
1120 gsm_process_modem(tty, dlci, modem, clen); 1131 gsm_process_modem(tty, dlci, modem, clen);
1121 if (tty) { 1132 if (tty) {
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index cb8017aa4434..d15624c1b751 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -817,8 +817,7 @@ static void process_echoes(struct tty_struct *tty)
817 struct n_tty_data *ldata = tty->disc_data; 817 struct n_tty_data *ldata = tty->disc_data;
818 size_t echoed; 818 size_t echoed;
819 819
820 if ((!L_ECHO(tty) && !L_ECHONL(tty)) || 820 if (ldata->echo_mark == ldata->echo_tail)
821 ldata->echo_mark == ldata->echo_tail)
822 return; 821 return;
823 822
824 mutex_lock(&ldata->output_lock); 823 mutex_lock(&ldata->output_lock);
@@ -1244,7 +1243,8 @@ n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c)
1244 if (L_ECHO(tty)) { 1243 if (L_ECHO(tty)) {
1245 echo_char(c, tty); 1244 echo_char(c, tty);
1246 commit_echoes(tty); 1245 commit_echoes(tty);
1247 } 1246 } else
1247 process_echoes(tty);
1248 isig(signal, tty); 1248 isig(signal, tty);
1249 return; 1249 return;
1250} 1250}
@@ -1274,7 +1274,7 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
1274 if (I_IXON(tty)) { 1274 if (I_IXON(tty)) {
1275 if (c == START_CHAR(tty)) { 1275 if (c == START_CHAR(tty)) {
1276 start_tty(tty); 1276 start_tty(tty);
1277 commit_echoes(tty); 1277 process_echoes(tty);
1278 return 0; 1278 return 0;
1279 } 1279 }
1280 if (c == STOP_CHAR(tty)) { 1280 if (c == STOP_CHAR(tty)) {
@@ -1820,8 +1820,10 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1820 * Fix tty hang when I_IXON(tty) is cleared, but the tty 1820 * Fix tty hang when I_IXON(tty) is cleared, but the tty
1821 * been stopped by STOP_CHAR(tty) before it. 1821 * been stopped by STOP_CHAR(tty) before it.
1822 */ 1822 */
1823 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow_stopped) 1823 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow_stopped) {
1824 start_tty(tty); 1824 start_tty(tty);
1825 process_echoes(tty);
1826 }
1825 1827
1826 /* The termios change make the tty ready for I/O */ 1828 /* The termios change make the tty ready for I/O */
1827 if (waitqueue_active(&tty->write_wait)) 1829 if (waitqueue_active(&tty->write_wait))
@@ -1896,7 +1898,7 @@ err:
1896static inline int input_available_p(struct tty_struct *tty, int poll) 1898static inline int input_available_p(struct tty_struct *tty, int poll)
1897{ 1899{
1898 struct n_tty_data *ldata = tty->disc_data; 1900 struct n_tty_data *ldata = tty->disc_data;
1899 int amt = poll && !TIME_CHAR(tty) ? MIN_CHAR(tty) : 1; 1901 int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1;
1900 1902
1901 if (ldata->icanon && !L_EXTPROC(tty)) { 1903 if (ldata->icanon && !L_EXTPROC(tty)) {
1902 if (ldata->canon_head != ldata->read_tail) 1904 if (ldata->canon_head != ldata->read_tail)
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 61ecd709a722..69932b7556cf 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -2433,6 +2433,24 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2433 serial_dl_write(up, quot); 2433 serial_dl_write(up, quot);
2434 2434
2435 /* 2435 /*
2436 * XR17V35x UARTs have an extra fractional divisor register (DLD)
2437 *
2438 * We need to recalculate all of the registers, because DLM and DLL
2439 * are already rounded to a whole integer.
2440 *
2441 * When recalculating we use a 32x clock instead of a 16x clock to
2442 * allow 1-bit for rounding in the fractional part.
2443 */
2444 if (up->port.type == PORT_XR17V35X) {
2445 unsigned int baud_x32 = (port->uartclk * 2) / baud;
2446 u16 quot = baud_x32 / 32;
2447 u8 quot_frac = DIV_ROUND_CLOSEST(baud_x32 % 32, 2);
2448
2449 serial_dl_write(up, quot);
2450 serial_port_out(port, 0x2, quot_frac & 0xf);
2451 }
2452
2453 /*
2436 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR 2454 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
2437 * is written without DLAB set, this mode will be disabled. 2455 * is written without DLAB set, this mode will be disabled.
2438 */ 2456 */
diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index faa64e646100..ed3113576740 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -391,7 +391,7 @@ static int dw8250_remove(struct platform_device *pdev)
391 return 0; 391 return 0;
392} 392}
393 393
394#ifdef CONFIG_PM 394#ifdef CONFIG_PM_SLEEP
395static int dw8250_suspend(struct device *dev) 395static int dw8250_suspend(struct device *dev)
396{ 396{
397 struct dw8250_data *data = dev_get_drvdata(dev); 397 struct dw8250_data *data = dev_get_drvdata(dev);
@@ -409,7 +409,7 @@ static int dw8250_resume(struct device *dev)
409 409
410 return 0; 410 return 0;
411} 411}
412#endif /* CONFIG_PM */ 412#endif /* CONFIG_PM_SLEEP */
413 413
414#ifdef CONFIG_PM_RUNTIME 414#ifdef CONFIG_PM_RUNTIME
415static int dw8250_runtime_suspend(struct device *dev) 415static int dw8250_runtime_suspend(struct device *dev)
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 50228eed3b6f..0ff3e3624d4c 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -783,7 +783,8 @@ static int pci_netmos_9900_setup(struct serial_private *priv,
783{ 783{
784 unsigned int bar; 784 unsigned int bar;
785 785
786 if ((priv->dev->subsystem_device & 0xff00) == 0x3000) { 786 if ((priv->dev->device != PCI_DEVICE_ID_NETMOS_9865) &&
787 (priv->dev->subsystem_device & 0xff00) == 0x3000) {
787 /* netmos apparently orders BARs by datasheet layout, so serial 788 /* netmos apparently orders BARs by datasheet layout, so serial
788 * ports get BARs 0 and 3 (or 1 and 4 for memmapped) 789 * ports get BARs 0 and 3 (or 1 and 4 for memmapped)
789 */ 790 */
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index fa511ebab67c..77f035158d6c 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -738,9 +738,6 @@ static int serial_omap_startup(struct uart_port *port)
738 return retval; 738 return retval;
739 } 739 }
740 disable_irq(up->wakeirq); 740 disable_irq(up->wakeirq);
741 } else {
742 dev_info(up->port.dev, "no wakeirq for uart%d\n",
743 up->port.line);
744 } 741 }
745 742
746 dev_dbg(up->port.dev, "serial_omap_startup+%d\n", up->port.line); 743 dev_dbg(up->port.dev, "serial_omap_startup+%d\n", up->port.line);
@@ -1604,8 +1601,11 @@ static int serial_omap_probe_rs485(struct uart_omap_port *up,
1604 flags & SER_RS485_RTS_AFTER_SEND); 1601 flags & SER_RS485_RTS_AFTER_SEND);
1605 if (ret < 0) 1602 if (ret < 0)
1606 return ret; 1603 return ret;
1607 } else 1604 } else if (up->rts_gpio == -EPROBE_DEFER) {
1605 return -EPROBE_DEFER;
1606 } else {
1608 up->rts_gpio = -EINVAL; 1607 up->rts_gpio = -EINVAL;
1608 }
1609 1609
1610 if (of_property_read_u32_array(np, "rs485-rts-delay", 1610 if (of_property_read_u32_array(np, "rs485-rts-delay",
1611 rs485_delay, 2) == 0) { 1611 rs485_delay, 2) == 0) {
@@ -1687,6 +1687,9 @@ static int serial_omap_probe(struct platform_device *pdev)
1687 up->port.iotype = UPIO_MEM; 1687 up->port.iotype = UPIO_MEM;
1688 up->port.irq = uartirq; 1688 up->port.irq = uartirq;
1689 up->wakeirq = wakeirq; 1689 up->wakeirq = wakeirq;
1690 if (!up->wakeirq)
1691 dev_info(up->port.dev, "no wakeirq for uart%d\n",
1692 up->port.line);
1690 1693
1691 up->port.regshift = 2; 1694 up->port.regshift = 2;
1692 up->port.fifosize = 64; 1695 up->port.fifosize = 64;
diff --git a/drivers/tty/serial/sirfsoc_uart.c b/drivers/tty/serial/sirfsoc_uart.c
index 49a2ffd101a7..b7bfe24d4ebc 100644
--- a/drivers/tty/serial/sirfsoc_uart.c
+++ b/drivers/tty/serial/sirfsoc_uart.c
@@ -542,8 +542,10 @@ static void sirfsoc_rx_tmo_process_tl(unsigned long param)
542 wr_regl(port, ureg->sirfsoc_rx_dma_io_ctrl, 542 wr_regl(port, ureg->sirfsoc_rx_dma_io_ctrl,
543 rd_regl(port, ureg->sirfsoc_rx_dma_io_ctrl) | 543 rd_regl(port, ureg->sirfsoc_rx_dma_io_ctrl) |
544 SIRFUART_IO_MODE); 544 SIRFUART_IO_MODE);
545 sirfsoc_uart_pio_rx_chars(port, 4 - sirfport->rx_io_count);
546 spin_unlock_irqrestore(&sirfport->rx_lock, flags); 545 spin_unlock_irqrestore(&sirfport->rx_lock, flags);
546 spin_lock(&port->lock);
547 sirfsoc_uart_pio_rx_chars(port, 4 - sirfport->rx_io_count);
548 spin_unlock(&port->lock);
547 if (sirfport->rx_io_count == 4) { 549 if (sirfport->rx_io_count == 4) {
548 spin_lock_irqsave(&sirfport->rx_lock, flags); 550 spin_lock_irqsave(&sirfport->rx_lock, flags);
549 sirfport->rx_io_count = 0; 551 sirfport->rx_io_count = 0;
diff --git a/drivers/tty/serial/sunhv.c b/drivers/tty/serial/sunhv.c
index cf86e729532b..dc697cee248a 100644
--- a/drivers/tty/serial/sunhv.c
+++ b/drivers/tty/serial/sunhv.c
@@ -433,13 +433,10 @@ static void sunhv_console_write_paged(struct console *con, const char *s, unsign
433 unsigned long flags; 433 unsigned long flags;
434 int locked = 1; 434 int locked = 1;
435 435
436 local_irq_save(flags); 436 if (port->sysrq || oops_in_progress)
437 if (port->sysrq) { 437 locked = spin_trylock_irqsave(&port->lock, flags);
438 locked = 0; 438 else
439 } else if (oops_in_progress) { 439 spin_lock_irqsave(&port->lock, flags);
440 locked = spin_trylock(&port->lock);
441 } else
442 spin_lock(&port->lock);
443 440
444 while (n > 0) { 441 while (n > 0) {
445 unsigned long ra = __pa(con_write_page); 442 unsigned long ra = __pa(con_write_page);
@@ -470,8 +467,7 @@ static void sunhv_console_write_paged(struct console *con, const char *s, unsign
470 } 467 }
471 468
472 if (locked) 469 if (locked)
473 spin_unlock(&port->lock); 470 spin_unlock_irqrestore(&port->lock, flags);
474 local_irq_restore(flags);
475} 471}
476 472
477static inline void sunhv_console_putchar(struct uart_port *port, char c) 473static inline void sunhv_console_putchar(struct uart_port *port, char c)
@@ -492,7 +488,10 @@ static void sunhv_console_write_bychar(struct console *con, const char *s, unsig
492 unsigned long flags; 488 unsigned long flags;
493 int i, locked = 1; 489 int i, locked = 1;
494 490
495 local_irq_save(flags); 491 if (port->sysrq || oops_in_progress)
492 locked = spin_trylock_irqsave(&port->lock, flags);
493 else
494 spin_lock_irqsave(&port->lock, flags);
496 if (port->sysrq) { 495 if (port->sysrq) {
497 locked = 0; 496 locked = 0;
498 } else if (oops_in_progress) { 497 } else if (oops_in_progress) {
@@ -507,8 +506,7 @@ static void sunhv_console_write_bychar(struct console *con, const char *s, unsig
507 } 506 }
508 507
509 if (locked) 508 if (locked)
510 spin_unlock(&port->lock); 509 spin_unlock_irqrestore(&port->lock, flags);
511 local_irq_restore(flags);
512} 510}
513 511
514static struct console sunhv_console = { 512static struct console sunhv_console = {
diff --git a/drivers/tty/serial/sunsab.c b/drivers/tty/serial/sunsab.c
index 380fb5355cb2..5faa8e905e98 100644
--- a/drivers/tty/serial/sunsab.c
+++ b/drivers/tty/serial/sunsab.c
@@ -844,20 +844,16 @@ static void sunsab_console_write(struct console *con, const char *s, unsigned n)
844 unsigned long flags; 844 unsigned long flags;
845 int locked = 1; 845 int locked = 1;
846 846
847 local_irq_save(flags); 847 if (up->port.sysrq || oops_in_progress)
848 if (up->port.sysrq) { 848 locked = spin_trylock_irqsave(&up->port.lock, flags);
849 locked = 0; 849 else
850 } else if (oops_in_progress) { 850 spin_lock_irqsave(&up->port.lock, flags);
851 locked = spin_trylock(&up->port.lock);
852 } else
853 spin_lock(&up->port.lock);
854 851
855 uart_console_write(&up->port, s, n, sunsab_console_putchar); 852 uart_console_write(&up->port, s, n, sunsab_console_putchar);
856 sunsab_tec_wait(up); 853 sunsab_tec_wait(up);
857 854
858 if (locked) 855 if (locked)
859 spin_unlock(&up->port.lock); 856 spin_unlock_irqrestore(&up->port.lock, flags);
860 local_irq_restore(flags);
861} 857}
862 858
863static int sunsab_console_setup(struct console *con, char *options) 859static int sunsab_console_setup(struct console *con, char *options)
diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c
index db79b76f5c8e..9a0f24f83720 100644
--- a/drivers/tty/serial/sunsu.c
+++ b/drivers/tty/serial/sunsu.c
@@ -1295,13 +1295,10 @@ static void sunsu_console_write(struct console *co, const char *s,
1295 unsigned int ier; 1295 unsigned int ier;
1296 int locked = 1; 1296 int locked = 1;
1297 1297
1298 local_irq_save(flags); 1298 if (up->port.sysrq || oops_in_progress)
1299 if (up->port.sysrq) { 1299 locked = spin_trylock_irqsave(&up->port.lock, flags);
1300 locked = 0; 1300 else
1301 } else if (oops_in_progress) { 1301 spin_lock_irqsave(&up->port.lock, flags);
1302 locked = spin_trylock(&up->port.lock);
1303 } else
1304 spin_lock(&up->port.lock);
1305 1302
1306 /* 1303 /*
1307 * First save the UER then disable the interrupts 1304 * First save the UER then disable the interrupts
@@ -1319,8 +1316,7 @@ static void sunsu_console_write(struct console *co, const char *s,
1319 serial_out(up, UART_IER, ier); 1316 serial_out(up, UART_IER, ier);
1320 1317
1321 if (locked) 1318 if (locked)
1322 spin_unlock(&up->port.lock); 1319 spin_unlock_irqrestore(&up->port.lock, flags);
1323 local_irq_restore(flags);
1324} 1320}
1325 1321
1326/* 1322/*
diff --git a/drivers/tty/serial/sunzilog.c b/drivers/tty/serial/sunzilog.c
index 45a8c6aa5837..a2c40ed287d2 100644
--- a/drivers/tty/serial/sunzilog.c
+++ b/drivers/tty/serial/sunzilog.c
@@ -1195,20 +1195,16 @@ sunzilog_console_write(struct console *con, const char *s, unsigned int count)
1195 unsigned long flags; 1195 unsigned long flags;
1196 int locked = 1; 1196 int locked = 1;
1197 1197
1198 local_irq_save(flags); 1198 if (up->port.sysrq || oops_in_progress)
1199 if (up->port.sysrq) { 1199 locked = spin_trylock_irqsave(&up->port.lock, flags);
1200 locked = 0; 1200 else
1201 } else if (oops_in_progress) { 1201 spin_lock_irqsave(&up->port.lock, flags);
1202 locked = spin_trylock(&up->port.lock);
1203 } else
1204 spin_lock(&up->port.lock);
1205 1202
1206 uart_console_write(&up->port, s, count, sunzilog_putchar); 1203 uart_console_write(&up->port, s, count, sunzilog_putchar);
1207 udelay(2); 1204 udelay(2);
1208 1205
1209 if (locked) 1206 if (locked)
1210 spin_unlock(&up->port.lock); 1207 spin_unlock_irqrestore(&up->port.lock, flags);
1211 local_irq_restore(flags);
1212} 1208}
1213 1209
1214static int __init sunzilog_console_setup(struct console *con, char *options) 1210static int __init sunzilog_console_setup(struct console *con, char *options)
diff --git a/drivers/tty/tty_ldsem.c b/drivers/tty/tty_ldsem.c
index d8a55e87877f..0ffb0cbe2823 100644
--- a/drivers/tty/tty_ldsem.c
+++ b/drivers/tty/tty_ldsem.c
@@ -39,17 +39,10 @@
39 lock_acquire(&(l)->dep_map, s, t, r, c, n, i) 39 lock_acquire(&(l)->dep_map, s, t, r, c, n, i)
40# define __rel(l, n, i) \ 40# define __rel(l, n, i) \
41 lock_release(&(l)->dep_map, n, i) 41 lock_release(&(l)->dep_map, n, i)
42# ifdef CONFIG_PROVE_LOCKING 42#define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 1, NULL, i)
43# define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 2, NULL, i) 43#define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 1, n, i)
44# define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 2, n, i) 44#define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 1, NULL, i)
45# define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 2, NULL, i) 45#define lockdep_release(l, n, i) __rel(l, n, i)
46# define lockdep_release(l, n, i) __rel(l, n, i)
47# else
48# define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 1, NULL, i)
49# define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 1, n, i)
50# define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 1, NULL, i)
51# define lockdep_release(l, n, i) __rel(l, n, i)
52# endif
53#else 46#else
54# define lockdep_acquire(l, s, t, i) do { } while (0) 47# define lockdep_acquire(l, s, t, i) do { } while (0)
55# define lockdep_acquire_nest(l, s, t, n, i) do { } while (0) 48# define lockdep_acquire_nest(l, s, t, n, i) do { } while (0)
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 61b1137d7e56..23b5d32954bf 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -1164,6 +1164,8 @@ static void csi_J(struct vc_data *vc, int vpar)
1164 scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char, 1164 scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char,
1165 vc->vc_screenbuf_size >> 1); 1165 vc->vc_screenbuf_size >> 1);
1166 set_origin(vc); 1166 set_origin(vc);
1167 if (CON_IS_VISIBLE(vc))
1168 update_screen(vc);
1167 /* fall through */ 1169 /* fall through */
1168 case 2: /* erase whole display */ 1170 case 2: /* erase whole display */
1169 count = vc->vc_cols * vc->vc_rows; 1171 count = vc->vc_cols * vc->vc_rows;
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 80de2f88ed2c..4ab2cb62dfce 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -105,7 +105,7 @@ static int hw_ep_flush(struct ci_hdrc *ci, int num, int dir)
105 105
106 do { 106 do {
107 /* flush any pending transfer */ 107 /* flush any pending transfer */
108 hw_write(ci, OP_ENDPTFLUSH, BIT(n), BIT(n)); 108 hw_write(ci, OP_ENDPTFLUSH, ~0, BIT(n));
109 while (hw_read(ci, OP_ENDPTFLUSH, BIT(n))) 109 while (hw_read(ci, OP_ENDPTFLUSH, BIT(n)))
110 cpu_relax(); 110 cpu_relax();
111 } while (hw_read(ci, OP_ENDPTSTAT, BIT(n))); 111 } while (hw_read(ci, OP_ENDPTSTAT, BIT(n)));
@@ -205,7 +205,7 @@ static int hw_ep_prime(struct ci_hdrc *ci, int num, int dir, int is_ctrl)
205 if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num))) 205 if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num)))
206 return -EAGAIN; 206 return -EAGAIN;
207 207
208 hw_write(ci, OP_ENDPTPRIME, BIT(n), BIT(n)); 208 hw_write(ci, OP_ENDPTPRIME, ~0, BIT(n));
209 209
210 while (hw_read(ci, OP_ENDPTPRIME, BIT(n))) 210 while (hw_read(ci, OP_ENDPTPRIME, BIT(n)))
211 cpu_relax(); 211 cpu_relax();
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 8d72f0c65937..062967c90b2a 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -717,6 +717,10 @@ int usb_get_configuration(struct usb_device *dev)
717 result = -ENOMEM; 717 result = -ENOMEM;
718 goto err; 718 goto err;
719 } 719 }
720
721 if (dev->quirks & USB_QUIRK_DELAY_INIT)
722 msleep(100);
723
720 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, 724 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
721 bigbuffer, length); 725 bigbuffer, length);
722 if (result < 0) { 726 if (result < 0) {
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 5d01558cef66..ab90a0156828 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -63,8 +63,10 @@ ssize_t usb_store_new_id(struct usb_dynids *dynids,
63 dynid->id.idProduct = idProduct; 63 dynid->id.idProduct = idProduct;
64 dynid->id.match_flags = USB_DEVICE_ID_MATCH_DEVICE; 64 dynid->id.match_flags = USB_DEVICE_ID_MATCH_DEVICE;
65 if (fields > 2 && bInterfaceClass) { 65 if (fields > 2 && bInterfaceClass) {
66 if (bInterfaceClass > 255) 66 if (bInterfaceClass > 255) {
67 return -EINVAL; 67 retval = -EINVAL;
68 goto fail;
69 }
68 70
69 dynid->id.bInterfaceClass = (u8)bInterfaceClass; 71 dynid->id.bInterfaceClass = (u8)bInterfaceClass;
70 dynid->id.match_flags |= USB_DEVICE_ID_MATCH_INT_CLASS; 72 dynid->id.match_flags |= USB_DEVICE_ID_MATCH_INT_CLASS;
@@ -73,17 +75,21 @@ ssize_t usb_store_new_id(struct usb_dynids *dynids,
73 if (fields > 4) { 75 if (fields > 4) {
74 const struct usb_device_id *id = id_table; 76 const struct usb_device_id *id = id_table;
75 77
76 if (!id) 78 if (!id) {
77 return -ENODEV; 79 retval = -ENODEV;
80 goto fail;
81 }
78 82
79 for (; id->match_flags; id++) 83 for (; id->match_flags; id++)
80 if (id->idVendor == refVendor && id->idProduct == refProduct) 84 if (id->idVendor == refVendor && id->idProduct == refProduct)
81 break; 85 break;
82 86
83 if (id->match_flags) 87 if (id->match_flags) {
84 dynid->id.driver_info = id->driver_info; 88 dynid->id.driver_info = id->driver_info;
85 else 89 } else {
86 return -ENODEV; 90 retval = -ENODEV;
91 goto fail;
92 }
87 } 93 }
88 94
89 spin_lock(&dynids->lock); 95 spin_lock(&dynids->lock);
@@ -95,6 +101,10 @@ ssize_t usb_store_new_id(struct usb_dynids *dynids,
95 if (retval) 101 if (retval)
96 return retval; 102 return retval;
97 return count; 103 return count;
104
105fail:
106 kfree(dynid);
107 return retval;
98} 108}
99EXPORT_SYMBOL_GPL(usb_store_new_id); 109EXPORT_SYMBOL_GPL(usb_store_new_id);
100 110
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 199aaea6bfe0..2518c3250750 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1032,7 +1032,6 @@ static int register_root_hub(struct usb_hcd *hcd)
1032 dev_name(&usb_dev->dev), retval); 1032 dev_name(&usb_dev->dev), retval);
1033 return retval; 1033 return retval;
1034 } 1034 }
1035 usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev);
1036 } 1035 }
1037 1036
1038 retval = usb_new_device (usb_dev); 1037 retval = usb_new_device (usb_dev);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index babba885978d..5cbf78d0be25 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -128,7 +128,7 @@ struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev)
128 return usb_get_intfdata(hdev->actconfig->interface[0]); 128 return usb_get_intfdata(hdev->actconfig->interface[0]);
129} 129}
130 130
131int usb_device_supports_lpm(struct usb_device *udev) 131static int usb_device_supports_lpm(struct usb_device *udev)
132{ 132{
133 /* USB 2.1 (and greater) devices indicate LPM support through 133 /* USB 2.1 (and greater) devices indicate LPM support through
134 * their USB 2.0 Extended Capabilities BOS descriptor. 134 * their USB 2.0 Extended Capabilities BOS descriptor.
@@ -149,11 +149,6 @@ int usb_device_supports_lpm(struct usb_device *udev)
149 "Power management will be impacted.\n"); 149 "Power management will be impacted.\n");
150 return 0; 150 return 0;
151 } 151 }
152
153 /* udev is root hub */
154 if (!udev->parent)
155 return 1;
156
157 if (udev->parent->lpm_capable) 152 if (udev->parent->lpm_capable)
158 return 1; 153 return 1;
159 154
@@ -1045,7 +1040,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1045 */ 1040 */
1046 if (type == HUB_INIT) { 1041 if (type == HUB_INIT) {
1047 delay = hub_power_on(hub, false); 1042 delay = hub_power_on(hub, false);
1048 PREPARE_DELAYED_WORK(&hub->init_work, hub_init_func2); 1043 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2);
1049 schedule_delayed_work(&hub->init_work, 1044 schedule_delayed_work(&hub->init_work,
1050 msecs_to_jiffies(delay)); 1045 msecs_to_jiffies(delay));
1051 1046
@@ -1199,7 +1194,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1199 1194
1200 /* Don't do a long sleep inside a workqueue routine */ 1195 /* Don't do a long sleep inside a workqueue routine */
1201 if (type == HUB_INIT2) { 1196 if (type == HUB_INIT2) {
1202 PREPARE_DELAYED_WORK(&hub->init_work, hub_init_func3); 1197 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3);
1203 schedule_delayed_work(&hub->init_work, 1198 schedule_delayed_work(&hub->init_work,
1204 msecs_to_jiffies(delay)); 1199 msecs_to_jiffies(delay));
1205 return; /* Continues at init3: below */ 1200 return; /* Continues at init3: below */
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 8f37063c0a49..739ee8e8bdfd 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -47,6 +47,10 @@ static const struct usb_device_id usb_quirk_list[] = {
47 /* Microsoft LifeCam-VX700 v2.0 */ 47 /* Microsoft LifeCam-VX700 v2.0 */
48 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME }, 48 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME },
49 49
50 /* Logitech HD Pro Webcams C920 and C930e */
51 { USB_DEVICE(0x046d, 0x082d), .driver_info = USB_QUIRK_DELAY_INIT },
52 { USB_DEVICE(0x046d, 0x0843), .driver_info = USB_QUIRK_DELAY_INIT },
53
50 /* Logitech Quickcam Fusion */ 54 /* Logitech Quickcam Fusion */
51 { USB_DEVICE(0x046d, 0x08c1), .driver_info = USB_QUIRK_RESET_RESUME }, 55 { USB_DEVICE(0x046d, 0x08c1), .driver_info = USB_QUIRK_RESET_RESUME },
52 56
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index c49383669cd8..823857767a16 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -35,7 +35,6 @@ extern int usb_get_device_descriptor(struct usb_device *dev,
35 unsigned int size); 35 unsigned int size);
36extern int usb_get_bos_descriptor(struct usb_device *dev); 36extern int usb_get_bos_descriptor(struct usb_device *dev);
37extern void usb_release_bos_descriptor(struct usb_device *dev); 37extern void usb_release_bos_descriptor(struct usb_device *dev);
38extern int usb_device_supports_lpm(struct usb_device *udev);
39extern char *usb_cache_string(struct usb_device *udev, int index); 38extern char *usb_cache_string(struct usb_device *udev, int index);
40extern int usb_set_configuration(struct usb_device *dev, int configuration); 39extern int usb_set_configuration(struct usb_device *dev, int configuration);
41extern int usb_choose_configuration(struct usb_device *udev); 40extern int usb_choose_configuration(struct usb_device *udev);
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 8565d87f94b4..1d129884cc39 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -216,7 +216,7 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
216 int retval = 0; 216 int retval = 0;
217 217
218 if (!select_phy) 218 if (!select_phy)
219 return -ENODEV; 219 return 0;
220 220
221 usbcfg = readl(hsotg->regs + GUSBCFG); 221 usbcfg = readl(hsotg->regs + GUSBCFG);
222 222
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index f59484d43b35..4d918ed8d343 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -2565,25 +2565,14 @@ static void _dwc2_hcd_endpoint_reset(struct usb_hcd *hcd,
2565 struct usb_host_endpoint *ep) 2565 struct usb_host_endpoint *ep)
2566{ 2566{
2567 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); 2567 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
2568 int is_control = usb_endpoint_xfer_control(&ep->desc);
2569 int is_out = usb_endpoint_dir_out(&ep->desc);
2570 int epnum = usb_endpoint_num(&ep->desc);
2571 struct usb_device *udev;
2572 unsigned long flags; 2568 unsigned long flags;
2573 2569
2574 dev_dbg(hsotg->dev, 2570 dev_dbg(hsotg->dev,
2575 "DWC OTG HCD EP RESET: bEndpointAddress=0x%02x\n", 2571 "DWC OTG HCD EP RESET: bEndpointAddress=0x%02x\n",
2576 ep->desc.bEndpointAddress); 2572 ep->desc.bEndpointAddress);
2577 2573
2578 udev = to_usb_device(hsotg->dev);
2579
2580 spin_lock_irqsave(&hsotg->lock, flags); 2574 spin_lock_irqsave(&hsotg->lock, flags);
2581
2582 usb_settoggle(udev, epnum, is_out, 0);
2583 if (is_control)
2584 usb_settoggle(udev, epnum, !is_out, 0);
2585 dwc2_hcd_endpoint_reset(hsotg, ep); 2575 dwc2_hcd_endpoint_reset(hsotg, ep);
2586
2587 spin_unlock_irqrestore(&hsotg->lock, flags); 2576 spin_unlock_irqrestore(&hsotg->lock, flags);
2588} 2577}
2589 2578
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index d01d0d3f2cf0..eaba547ce26b 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -124,6 +124,9 @@ static int dwc2_driver_probe(struct platform_device *dev)
124 int retval; 124 int retval;
125 int irq; 125 int irq;
126 126
127 if (usb_disabled())
128 return -ENODEV;
129
127 match = of_match_device(dwc2_of_match_table, &dev->dev); 130 match = of_match_device(dwc2_of_match_table, &dev->dev);
128 if (match && match->data) { 131 if (match && match->data) {
129 params = match->data; 132 params = match->data;
diff --git a/drivers/usb/gadget/bcm63xx_udc.c b/drivers/usb/gadget/bcm63xx_udc.c
index 888fbb43b338..e969eb809a85 100644
--- a/drivers/usb/gadget/bcm63xx_udc.c
+++ b/drivers/usb/gadget/bcm63xx_udc.c
@@ -360,24 +360,30 @@ static inline void usb_dma_writel(struct bcm63xx_udc *udc, u32 val, u32 off)
360 bcm_writel(val, udc->iudma_regs + off); 360 bcm_writel(val, udc->iudma_regs + off);
361} 361}
362 362
363static inline u32 usb_dmac_readl(struct bcm63xx_udc *udc, u32 off) 363static inline u32 usb_dmac_readl(struct bcm63xx_udc *udc, u32 off, int chan)
364{ 364{
365 return bcm_readl(udc->iudma_regs + IUDMA_DMAC_OFFSET + off); 365 return bcm_readl(udc->iudma_regs + IUDMA_DMAC_OFFSET + off +
366 (ENETDMA_CHAN_WIDTH * chan));
366} 367}
367 368
368static inline void usb_dmac_writel(struct bcm63xx_udc *udc, u32 val, u32 off) 369static inline void usb_dmac_writel(struct bcm63xx_udc *udc, u32 val, u32 off,
370 int chan)
369{ 371{
370 bcm_writel(val, udc->iudma_regs + IUDMA_DMAC_OFFSET + off); 372 bcm_writel(val, udc->iudma_regs + IUDMA_DMAC_OFFSET + off +
373 (ENETDMA_CHAN_WIDTH * chan));
371} 374}
372 375
373static inline u32 usb_dmas_readl(struct bcm63xx_udc *udc, u32 off) 376static inline u32 usb_dmas_readl(struct bcm63xx_udc *udc, u32 off, int chan)
374{ 377{
375 return bcm_readl(udc->iudma_regs + IUDMA_DMAS_OFFSET + off); 378 return bcm_readl(udc->iudma_regs + IUDMA_DMAS_OFFSET + off +
379 (ENETDMA_CHAN_WIDTH * chan));
376} 380}
377 381
378static inline void usb_dmas_writel(struct bcm63xx_udc *udc, u32 val, u32 off) 382static inline void usb_dmas_writel(struct bcm63xx_udc *udc, u32 val, u32 off,
383 int chan)
379{ 384{
380 bcm_writel(val, udc->iudma_regs + IUDMA_DMAS_OFFSET + off); 385 bcm_writel(val, udc->iudma_regs + IUDMA_DMAS_OFFSET + off +
386 (ENETDMA_CHAN_WIDTH * chan));
381} 387}
382 388
383static inline void set_clocks(struct bcm63xx_udc *udc, bool is_enabled) 389static inline void set_clocks(struct bcm63xx_udc *udc, bool is_enabled)
@@ -638,7 +644,7 @@ static void iudma_write(struct bcm63xx_udc *udc, struct iudma_ch *iudma,
638 } while (!last_bd); 644 } while (!last_bd);
639 645
640 usb_dmac_writel(udc, ENETDMAC_CHANCFG_EN_MASK, 646 usb_dmac_writel(udc, ENETDMAC_CHANCFG_EN_MASK,
641 ENETDMAC_CHANCFG_REG(iudma->ch_idx)); 647 ENETDMAC_CHANCFG_REG, iudma->ch_idx);
642} 648}
643 649
644/** 650/**
@@ -694,9 +700,9 @@ static void iudma_reset_channel(struct bcm63xx_udc *udc, struct iudma_ch *iudma)
694 bcm63xx_fifo_reset_ep(udc, max(0, iudma->ep_num)); 700 bcm63xx_fifo_reset_ep(udc, max(0, iudma->ep_num));
695 701
696 /* stop DMA, then wait for the hardware to wrap up */ 702 /* stop DMA, then wait for the hardware to wrap up */
697 usb_dmac_writel(udc, 0, ENETDMAC_CHANCFG_REG(ch_idx)); 703 usb_dmac_writel(udc, 0, ENETDMAC_CHANCFG_REG, ch_idx);
698 704
699 while (usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG(ch_idx)) & 705 while (usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG, ch_idx) &
700 ENETDMAC_CHANCFG_EN_MASK) { 706 ENETDMAC_CHANCFG_EN_MASK) {
701 udelay(1); 707 udelay(1);
702 708
@@ -713,10 +719,10 @@ static void iudma_reset_channel(struct bcm63xx_udc *udc, struct iudma_ch *iudma)
713 dev_warn(udc->dev, "forcibly halting IUDMA channel %d\n", 719 dev_warn(udc->dev, "forcibly halting IUDMA channel %d\n",
714 ch_idx); 720 ch_idx);
715 usb_dmac_writel(udc, ENETDMAC_CHANCFG_BUFHALT_MASK, 721 usb_dmac_writel(udc, ENETDMAC_CHANCFG_BUFHALT_MASK,
716 ENETDMAC_CHANCFG_REG(ch_idx)); 722 ENETDMAC_CHANCFG_REG, ch_idx);
717 } 723 }
718 } 724 }
719 usb_dmac_writel(udc, ~0, ENETDMAC_IR_REG(ch_idx)); 725 usb_dmac_writel(udc, ~0, ENETDMAC_IR_REG, ch_idx);
720 726
721 /* don't leave "live" HW-owned entries for the next guy to step on */ 727 /* don't leave "live" HW-owned entries for the next guy to step on */
722 for (d = iudma->bd_ring; d <= iudma->end_bd; d++) 728 for (d = iudma->bd_ring; d <= iudma->end_bd; d++)
@@ -728,11 +734,11 @@ static void iudma_reset_channel(struct bcm63xx_udc *udc, struct iudma_ch *iudma)
728 734
729 /* set up IRQs, UBUS burst size, and BD base for this channel */ 735 /* set up IRQs, UBUS burst size, and BD base for this channel */
730 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK, 736 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK,
731 ENETDMAC_IRMASK_REG(ch_idx)); 737 ENETDMAC_IRMASK_REG, ch_idx);
732 usb_dmac_writel(udc, 8, ENETDMAC_MAXBURST_REG(ch_idx)); 738 usb_dmac_writel(udc, 8, ENETDMAC_MAXBURST_REG, ch_idx);
733 739
734 usb_dmas_writel(udc, iudma->bd_ring_dma, ENETDMAS_RSTART_REG(ch_idx)); 740 usb_dmas_writel(udc, iudma->bd_ring_dma, ENETDMAS_RSTART_REG, ch_idx);
735 usb_dmas_writel(udc, 0, ENETDMAS_SRAM2_REG(ch_idx)); 741 usb_dmas_writel(udc, 0, ENETDMAS_SRAM2_REG, ch_idx);
736} 742}
737 743
738/** 744/**
@@ -2035,7 +2041,7 @@ static irqreturn_t bcm63xx_udc_data_isr(int irq, void *dev_id)
2035 spin_lock(&udc->lock); 2041 spin_lock(&udc->lock);
2036 2042
2037 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK, 2043 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK,
2038 ENETDMAC_IR_REG(iudma->ch_idx)); 2044 ENETDMAC_IR_REG, iudma->ch_idx);
2039 bep = iudma->bep; 2045 bep = iudma->bep;
2040 rc = iudma_read(udc, iudma); 2046 rc = iudma_read(udc, iudma);
2041 2047
@@ -2175,18 +2181,18 @@ static int bcm63xx_iudma_dbg_show(struct seq_file *s, void *p)
2175 seq_printf(s, " [ep%d]:\n", 2181 seq_printf(s, " [ep%d]:\n",
2176 max_t(int, iudma_defaults[ch_idx].ep_num, 0)); 2182 max_t(int, iudma_defaults[ch_idx].ep_num, 0));
2177 seq_printf(s, " cfg: %08x; irqstat: %08x; irqmask: %08x; maxburst: %08x\n", 2183 seq_printf(s, " cfg: %08x; irqstat: %08x; irqmask: %08x; maxburst: %08x\n",
2178 usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG(ch_idx)), 2184 usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG, ch_idx),
2179 usb_dmac_readl(udc, ENETDMAC_IR_REG(ch_idx)), 2185 usb_dmac_readl(udc, ENETDMAC_IR_REG, ch_idx),
2180 usb_dmac_readl(udc, ENETDMAC_IRMASK_REG(ch_idx)), 2186 usb_dmac_readl(udc, ENETDMAC_IRMASK_REG, ch_idx),
2181 usb_dmac_readl(udc, ENETDMAC_MAXBURST_REG(ch_idx))); 2187 usb_dmac_readl(udc, ENETDMAC_MAXBURST_REG, ch_idx));
2182 2188
2183 sram2 = usb_dmas_readl(udc, ENETDMAS_SRAM2_REG(ch_idx)); 2189 sram2 = usb_dmas_readl(udc, ENETDMAS_SRAM2_REG, ch_idx);
2184 sram3 = usb_dmas_readl(udc, ENETDMAS_SRAM3_REG(ch_idx)); 2190 sram3 = usb_dmas_readl(udc, ENETDMAS_SRAM3_REG, ch_idx);
2185 seq_printf(s, " base: %08x; index: %04x_%04x; desc: %04x_%04x %08x\n", 2191 seq_printf(s, " base: %08x; index: %04x_%04x; desc: %04x_%04x %08x\n",
2186 usb_dmas_readl(udc, ENETDMAS_RSTART_REG(ch_idx)), 2192 usb_dmas_readl(udc, ENETDMAS_RSTART_REG, ch_idx),
2187 sram2 >> 16, sram2 & 0xffff, 2193 sram2 >> 16, sram2 & 0xffff,
2188 sram3 >> 16, sram3 & 0xffff, 2194 sram3 >> 16, sram3 & 0xffff,
2189 usb_dmas_readl(udc, ENETDMAS_SRAM4_REG(ch_idx))); 2195 usb_dmas_readl(udc, ENETDMAS_SRAM4_REG, ch_idx));
2190 seq_printf(s, " desc: %d/%d used", iudma->n_bds_used, 2196 seq_printf(s, " desc: %d/%d used", iudma->n_bds_used,
2191 iudma->n_bds); 2197 iudma->n_bds);
2192 2198
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 306a2b52125c..2b4334394076 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -585,7 +585,6 @@ static ssize_t ffs_epfile_io(struct file *file,
585 char __user *buf, size_t len, int read) 585 char __user *buf, size_t len, int read)
586{ 586{
587 struct ffs_epfile *epfile = file->private_data; 587 struct ffs_epfile *epfile = file->private_data;
588 struct usb_gadget *gadget = epfile->ffs->gadget;
589 struct ffs_ep *ep; 588 struct ffs_ep *ep;
590 char *data = NULL; 589 char *data = NULL;
591 ssize_t ret, data_len; 590 ssize_t ret, data_len;
@@ -622,6 +621,12 @@ static ssize_t ffs_epfile_io(struct file *file,
622 /* Allocate & copy */ 621 /* Allocate & copy */
623 if (!halt) { 622 if (!halt) {
624 /* 623 /*
624 * if we _do_ wait above, the epfile->ffs->gadget might be NULL
625 * before the waiting completes, so do not assign to 'gadget' earlier
626 */
627 struct usb_gadget *gadget = epfile->ffs->gadget;
628
629 /*
625 * Controller may require buffer size to be aligned to 630 * Controller may require buffer size to be aligned to
626 * maxpacketsize of an out endpoint. 631 * maxpacketsize of an out endpoint.
627 */ 632 */
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index bf7a56b6d48a..69b76efd11e9 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -1157,7 +1157,7 @@ static int __init printer_bind_config(struct usb_configuration *c)
1157 1157
1158 usb_gadget_set_selfpowered(gadget); 1158 usb_gadget_set_selfpowered(gadget);
1159 1159
1160 if (gadget->is_otg) { 1160 if (gadget_is_otg(gadget)) {
1161 otg_descriptor.bmAttributes |= USB_OTG_HNP; 1161 otg_descriptor.bmAttributes |= USB_OTG_HNP;
1162 printer_cfg_driver.descriptors = otg_desc; 1162 printer_cfg_driver.descriptors = otg_desc;
1163 printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1163 printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index f04b2c3154de..dd9678f85c58 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -1629,7 +1629,7 @@ static void s3c2410_udc_reinit(struct s3c2410_udc *dev)
1629 ep->ep.desc = NULL; 1629 ep->ep.desc = NULL;
1630 ep->halted = 0; 1630 ep->halted = 0;
1631 INIT_LIST_HEAD(&ep->queue); 1631 INIT_LIST_HEAD(&ep->queue);
1632 usb_ep_set_maxpacket_limit(&ep->ep, &ep->ep.maxpacket); 1632 usb_ep_set_maxpacket_limit(&ep->ep, ep->ep.maxpacket);
1633 } 1633 }
1634} 1634}
1635 1635
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 471142725ffe..81cda09b47e3 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -685,8 +685,15 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
685 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 685 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
686 u32 status, masked_status, pcd_status = 0, cmd; 686 u32 status, masked_status, pcd_status = 0, cmd;
687 int bh; 687 int bh;
688 unsigned long flags;
688 689
689 spin_lock (&ehci->lock); 690 /*
691 * For threadirqs option we use spin_lock_irqsave() variant to prevent
692 * deadlock with ehci hrtimer callback, because hrtimer callbacks run
693 * in interrupt context even when threadirqs is specified. We can go
694 * back to spin_lock() variant when hrtimer callbacks become threaded.
695 */
696 spin_lock_irqsave(&ehci->lock, flags);
690 697
691 status = ehci_readl(ehci, &ehci->regs->status); 698 status = ehci_readl(ehci, &ehci->regs->status);
692 699
@@ -704,7 +711,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
704 711
705 /* Shared IRQ? */ 712 /* Shared IRQ? */
706 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { 713 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
707 spin_unlock(&ehci->lock); 714 spin_unlock_irqrestore(&ehci->lock, flags);
708 return IRQ_NONE; 715 return IRQ_NONE;
709 } 716 }
710 717
@@ -815,7 +822,7 @@ dead:
815 822
816 if (bh) 823 if (bh)
817 ehci_work (ehci); 824 ehci_work (ehci);
818 spin_unlock (&ehci->lock); 825 spin_unlock_irqrestore(&ehci->lock, flags);
819 if (pcd_status) 826 if (pcd_status)
820 usb_hcd_poll_rh_status(hcd); 827 usb_hcd_poll_rh_status(hcd);
821 return IRQ_HANDLED; 828 return IRQ_HANDLED;
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 47b858fc50b2..7ae0c4d51741 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -238,6 +238,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
238 int port; 238 int port;
239 int mask; 239 int mask;
240 int changed; 240 int changed;
241 bool fs_idle_delay;
241 242
242 ehci_dbg(ehci, "suspend root hub\n"); 243 ehci_dbg(ehci, "suspend root hub\n");
243 244
@@ -272,6 +273,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
272 ehci->bus_suspended = 0; 273 ehci->bus_suspended = 0;
273 ehci->owned_ports = 0; 274 ehci->owned_ports = 0;
274 changed = 0; 275 changed = 0;
276 fs_idle_delay = false;
275 port = HCS_N_PORTS(ehci->hcs_params); 277 port = HCS_N_PORTS(ehci->hcs_params);
276 while (port--) { 278 while (port--) {
277 u32 __iomem *reg = &ehci->regs->port_status [port]; 279 u32 __iomem *reg = &ehci->regs->port_status [port];
@@ -300,16 +302,32 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
300 } 302 }
301 303
302 if (t1 != t2) { 304 if (t1 != t2) {
305 /*
306 * On some controllers, Wake-On-Disconnect will
307 * generate false wakeup signals until the bus
308 * switches over to full-speed idle. For their
309 * sake, add a delay if we need one.
310 */
311 if ((t2 & PORT_WKDISC_E) &&
312 ehci_port_speed(ehci, t2) ==
313 USB_PORT_STAT_HIGH_SPEED)
314 fs_idle_delay = true;
303 ehci_writel(ehci, t2, reg); 315 ehci_writel(ehci, t2, reg);
304 changed = 1; 316 changed = 1;
305 } 317 }
306 } 318 }
319 spin_unlock_irq(&ehci->lock);
320
321 if ((changed && ehci->has_tdi_phy_lpm) || fs_idle_delay) {
322 /*
323 * Wait for HCD to enter low-power mode or for the bus
324 * to switch to full-speed idle.
325 */
326 usleep_range(5000, 5500);
327 }
307 328
308 if (changed && ehci->has_tdi_phy_lpm) { 329 if (changed && ehci->has_tdi_phy_lpm) {
309 spin_unlock_irq(&ehci->lock);
310 msleep(5); /* 5 ms for HCD to enter low-power mode */
311 spin_lock_irq(&ehci->lock); 330 spin_lock_irq(&ehci->lock);
312
313 port = HCS_N_PORTS(ehci->hcs_params); 331 port = HCS_N_PORTS(ehci->hcs_params);
314 while (port--) { 332 while (port--) {
315 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port]; 333 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
@@ -322,8 +340,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
322 port, (t3 & HOSTPC_PHCD) ? 340 port, (t3 & HOSTPC_PHCD) ?
323 "succeeded" : "failed"); 341 "succeeded" : "failed");
324 } 342 }
343 spin_unlock_irq(&ehci->lock);
325 } 344 }
326 spin_unlock_irq(&ehci->lock);
327 345
328 /* Apparently some devices need a >= 1-uframe delay here */ 346 /* Apparently some devices need a >= 1-uframe delay here */
329 if (ehci->bus_suspended) 347 if (ehci->bus_suspended)
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index b016d38199f2..eb009a457fb5 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -203,12 +203,12 @@ void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num)
203 addr, (unsigned int)temp); 203 addr, (unsigned int)temp);
204 204
205 addr = &ir_set->erst_base; 205 addr = &ir_set->erst_base;
206 temp_64 = readq(addr); 206 temp_64 = xhci_read_64(xhci, addr);
207 xhci_dbg(xhci, " %p: ir_set.erst_base = @%08llx\n", 207 xhci_dbg(xhci, " %p: ir_set.erst_base = @%08llx\n",
208 addr, temp_64); 208 addr, temp_64);
209 209
210 addr = &ir_set->erst_dequeue; 210 addr = &ir_set->erst_dequeue;
211 temp_64 = readq(addr); 211 temp_64 = xhci_read_64(xhci, addr);
212 xhci_dbg(xhci, " %p: ir_set.erst_dequeue = @%08llx\n", 212 xhci_dbg(xhci, " %p: ir_set.erst_dequeue = @%08llx\n",
213 addr, temp_64); 213 addr, temp_64);
214} 214}
@@ -412,7 +412,7 @@ void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci)
412{ 412{
413 u64 val; 413 u64 val;
414 414
415 val = readq(&xhci->op_regs->cmd_ring); 415 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
416 xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = @%08x\n", 416 xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = @%08x\n",
417 lower_32_bits(val)); 417 lower_32_bits(val));
418 xhci_dbg(xhci, "// xHC command ring deq ptr high bits = @%08x\n", 418 xhci_dbg(xhci, "// xHC command ring deq ptr high bits = @%08x\n",
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 873c272b3ef5..bce4391a0e7d 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1958,7 +1958,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
1958 xhci_warn(xhci, "WARN something wrong with SW event ring " 1958 xhci_warn(xhci, "WARN something wrong with SW event ring "
1959 "dequeue ptr.\n"); 1959 "dequeue ptr.\n");
1960 /* Update HC event ring dequeue pointer */ 1960 /* Update HC event ring dequeue pointer */
1961 temp = readq(&xhci->ir_set->erst_dequeue); 1961 temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
1962 temp &= ERST_PTR_MASK; 1962 temp &= ERST_PTR_MASK;
1963 /* Don't clear the EHB bit (which is RW1C) because 1963 /* Don't clear the EHB bit (which is RW1C) because
1964 * there might be more events to service. 1964 * there might be more events to service.
@@ -1967,7 +1967,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
1967 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 1967 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1968 "// Write event ring dequeue pointer, " 1968 "// Write event ring dequeue pointer, "
1969 "preserving EHB bit"); 1969 "preserving EHB bit");
1970 writeq(((u64) deq & (u64) ~ERST_PTR_MASK) | temp, 1970 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
1971 &xhci->ir_set->erst_dequeue); 1971 &xhci->ir_set->erst_dequeue);
1972} 1972}
1973 1973
@@ -2269,7 +2269,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2269 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2269 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2270 "// Device context base array address = 0x%llx (DMA), %p (virt)", 2270 "// Device context base array address = 0x%llx (DMA), %p (virt)",
2271 (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa); 2271 (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa);
2272 writeq(dma, &xhci->op_regs->dcbaa_ptr); 2272 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr);
2273 2273
2274 /* 2274 /*
2275 * Initialize the ring segment pool. The ring must be a contiguous 2275 * Initialize the ring segment pool. The ring must be a contiguous
@@ -2312,13 +2312,13 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2312 (unsigned long long)xhci->cmd_ring->first_seg->dma); 2312 (unsigned long long)xhci->cmd_ring->first_seg->dma);
2313 2313
2314 /* Set the address in the Command Ring Control register */ 2314 /* Set the address in the Command Ring Control register */
2315 val_64 = readq(&xhci->op_regs->cmd_ring); 2315 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
2316 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | 2316 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
2317 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | 2317 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) |
2318 xhci->cmd_ring->cycle_state; 2318 xhci->cmd_ring->cycle_state;
2319 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2319 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2320 "// Setting command ring address to 0x%x", val); 2320 "// Setting command ring address to 0x%x", val);
2321 writeq(val_64, &xhci->op_regs->cmd_ring); 2321 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
2322 xhci_dbg_cmd_ptrs(xhci); 2322 xhci_dbg_cmd_ptrs(xhci);
2323 2323
2324 xhci->lpm_command = xhci_alloc_command(xhci, true, true, flags); 2324 xhci->lpm_command = xhci_alloc_command(xhci, true, true, flags);
@@ -2396,10 +2396,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2396 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2396 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2397 "// Set ERST base address for ir_set 0 = 0x%llx", 2397 "// Set ERST base address for ir_set 0 = 0x%llx",
2398 (unsigned long long)xhci->erst.erst_dma_addr); 2398 (unsigned long long)xhci->erst.erst_dma_addr);
2399 val_64 = readq(&xhci->ir_set->erst_base); 2399 val_64 = xhci_read_64(xhci, &xhci->ir_set->erst_base);
2400 val_64 &= ERST_PTR_MASK; 2400 val_64 &= ERST_PTR_MASK;
2401 val_64 |= (xhci->erst.erst_dma_addr & (u64) ~ERST_PTR_MASK); 2401 val_64 |= (xhci->erst.erst_dma_addr & (u64) ~ERST_PTR_MASK);
2402 writeq(val_64, &xhci->ir_set->erst_base); 2402 xhci_write_64(xhci, val_64, &xhci->ir_set->erst_base);
2403 2403
2404 /* Set the event ring dequeue address */ 2404 /* Set the event ring dequeue address */
2405 xhci_set_hc_event_deq(xhci); 2405 xhci_set_hc_event_deq(xhci);
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 3c898c12a06b..04f986d9234f 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -142,6 +142,11 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
142 "QUIRK: Resetting on resume"); 142 "QUIRK: Resetting on resume");
143 xhci->quirks |= XHCI_TRUST_TX_LENGTH; 143 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
144 } 144 }
145 if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
146 pdev->device == 0x0015 &&
147 pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG &&
148 pdev->subsystem_device == 0xc0cd)
149 xhci->quirks |= XHCI_RESET_ON_RESUME;
145 if (pdev->vendor == PCI_VENDOR_ID_VIA) 150 if (pdev->vendor == PCI_VENDOR_ID_VIA)
146 xhci->quirks |= XHCI_RESET_ON_RESUME; 151 xhci->quirks |= XHCI_RESET_ON_RESUME;
147} 152}
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index a0b248c34526..0ed64eb68e48 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -307,13 +307,14 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci)
307 return 0; 307 return 0;
308 } 308 }
309 309
310 temp_64 = readq(&xhci->op_regs->cmd_ring); 310 temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
311 if (!(temp_64 & CMD_RING_RUNNING)) { 311 if (!(temp_64 & CMD_RING_RUNNING)) {
312 xhci_dbg(xhci, "Command ring had been stopped\n"); 312 xhci_dbg(xhci, "Command ring had been stopped\n");
313 return 0; 313 return 0;
314 } 314 }
315 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; 315 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED;
316 writeq(temp_64 | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); 316 xhci_write_64(xhci, temp_64 | CMD_RING_ABORT,
317 &xhci->op_regs->cmd_ring);
317 318
318 /* Section 4.6.1.2 of xHCI 1.0 spec says software should 319 /* Section 4.6.1.2 of xHCI 1.0 spec says software should
319 * time the completion od all xHCI commands, including 320 * time the completion od all xHCI commands, including
@@ -2864,8 +2865,9 @@ hw_died:
2864 /* Clear the event handler busy flag (RW1C); 2865 /* Clear the event handler busy flag (RW1C);
2865 * the event ring should be empty. 2866 * the event ring should be empty.
2866 */ 2867 */
2867 temp_64 = readq(&xhci->ir_set->erst_dequeue); 2868 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2868 writeq(temp_64 | ERST_EHB, &xhci->ir_set->erst_dequeue); 2869 xhci_write_64(xhci, temp_64 | ERST_EHB,
2870 &xhci->ir_set->erst_dequeue);
2869 spin_unlock(&xhci->lock); 2871 spin_unlock(&xhci->lock);
2870 2872
2871 return IRQ_HANDLED; 2873 return IRQ_HANDLED;
@@ -2877,7 +2879,7 @@ hw_died:
2877 */ 2879 */
2878 while (xhci_handle_event(xhci) > 0) {} 2880 while (xhci_handle_event(xhci) > 0) {}
2879 2881
2880 temp_64 = readq(&xhci->ir_set->erst_dequeue); 2882 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2881 /* If necessary, update the HW's version of the event ring deq ptr. */ 2883 /* If necessary, update the HW's version of the event ring deq ptr. */
2882 if (event_ring_deq != xhci->event_ring->dequeue) { 2884 if (event_ring_deq != xhci->event_ring->dequeue) {
2883 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, 2885 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,
@@ -2892,7 +2894,7 @@ hw_died:
2892 2894
2893 /* Clear the event handler busy flag (RW1C); event ring is empty. */ 2895 /* Clear the event handler busy flag (RW1C); event ring is empty. */
2894 temp_64 |= ERST_EHB; 2896 temp_64 |= ERST_EHB;
2895 writeq(temp_64, &xhci->ir_set->erst_dequeue); 2897 xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue);
2896 2898
2897 spin_unlock(&xhci->lock); 2899 spin_unlock(&xhci->lock);
2898 2900
@@ -2965,58 +2967,8 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
2965 } 2967 }
2966 2968
2967 while (1) { 2969 while (1) {
2968 if (room_on_ring(xhci, ep_ring, num_trbs)) { 2970 if (room_on_ring(xhci, ep_ring, num_trbs))
2969 union xhci_trb *trb = ep_ring->enqueue; 2971 break;
2970 unsigned int usable = ep_ring->enq_seg->trbs +
2971 TRBS_PER_SEGMENT - 1 - trb;
2972 u32 nop_cmd;
2973
2974 /*
2975 * Section 4.11.7.1 TD Fragments states that a link
2976 * TRB must only occur at the boundary between
2977 * data bursts (eg 512 bytes for 480M).
2978 * While it is possible to split a large fragment
2979 * we don't know the size yet.
2980 * Simplest solution is to fill the trb before the
2981 * LINK with nop commands.
2982 */
2983 if (num_trbs == 1 || num_trbs <= usable || usable == 0)
2984 break;
2985
2986 if (ep_ring->type != TYPE_BULK)
2987 /*
2988 * While isoc transfers might have a buffer that
2989 * crosses a 64k boundary it is unlikely.
2990 * Since we can't add NOPs without generating
2991 * gaps in the traffic just hope it never
2992 * happens at the end of the ring.
2993 * This could be fixed by writing a LINK TRB
2994 * instead of the first NOP - however the
2995 * TRB_TYPE_LINK_LE32() calls would all need
2996 * changing to check the ring length.
2997 */
2998 break;
2999
3000 if (num_trbs >= TRBS_PER_SEGMENT) {
3001 xhci_err(xhci, "Too many fragments %d, max %d\n",
3002 num_trbs, TRBS_PER_SEGMENT - 1);
3003 return -EINVAL;
3004 }
3005
3006 nop_cmd = cpu_to_le32(TRB_TYPE(TRB_TR_NOOP) |
3007 ep_ring->cycle_state);
3008 ep_ring->num_trbs_free -= usable;
3009 do {
3010 trb->generic.field[0] = 0;
3011 trb->generic.field[1] = 0;
3012 trb->generic.field[2] = 0;
3013 trb->generic.field[3] = nop_cmd;
3014 trb++;
3015 } while (--usable);
3016 ep_ring->enqueue = trb;
3017 if (room_on_ring(xhci, ep_ring, num_trbs))
3018 break;
3019 }
3020 2972
3021 if (ep_ring == xhci->cmd_ring) { 2973 if (ep_ring == xhci->cmd_ring) {
3022 xhci_err(xhci, "Do not support expand command ring\n"); 2974 xhci_err(xhci, "Do not support expand command ring\n");
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ad364394885a..924a6ccdb622 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -611,7 +611,7 @@ int xhci_run(struct usb_hcd *hcd)
611 xhci_dbg(xhci, "Event ring:\n"); 611 xhci_dbg(xhci, "Event ring:\n");
612 xhci_debug_ring(xhci, xhci->event_ring); 612 xhci_debug_ring(xhci, xhci->event_ring);
613 xhci_dbg_ring_ptrs(xhci, xhci->event_ring); 613 xhci_dbg_ring_ptrs(xhci, xhci->event_ring);
614 temp_64 = readq(&xhci->ir_set->erst_dequeue); 614 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
615 temp_64 &= ~ERST_PTR_MASK; 615 temp_64 &= ~ERST_PTR_MASK;
616 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 616 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
617 "ERST deq = 64'h%0lx", (long unsigned int) temp_64); 617 "ERST deq = 64'h%0lx", (long unsigned int) temp_64);
@@ -756,11 +756,11 @@ static void xhci_save_registers(struct xhci_hcd *xhci)
756{ 756{
757 xhci->s3.command = readl(&xhci->op_regs->command); 757 xhci->s3.command = readl(&xhci->op_regs->command);
758 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); 758 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification);
759 xhci->s3.dcbaa_ptr = readq(&xhci->op_regs->dcbaa_ptr); 759 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
760 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); 760 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg);
761 xhci->s3.erst_size = readl(&xhci->ir_set->erst_size); 761 xhci->s3.erst_size = readl(&xhci->ir_set->erst_size);
762 xhci->s3.erst_base = readq(&xhci->ir_set->erst_base); 762 xhci->s3.erst_base = xhci_read_64(xhci, &xhci->ir_set->erst_base);
763 xhci->s3.erst_dequeue = readq(&xhci->ir_set->erst_dequeue); 763 xhci->s3.erst_dequeue = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
764 xhci->s3.irq_pending = readl(&xhci->ir_set->irq_pending); 764 xhci->s3.irq_pending = readl(&xhci->ir_set->irq_pending);
765 xhci->s3.irq_control = readl(&xhci->ir_set->irq_control); 765 xhci->s3.irq_control = readl(&xhci->ir_set->irq_control);
766} 766}
@@ -769,11 +769,11 @@ static void xhci_restore_registers(struct xhci_hcd *xhci)
769{ 769{
770 writel(xhci->s3.command, &xhci->op_regs->command); 770 writel(xhci->s3.command, &xhci->op_regs->command);
771 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); 771 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification);
772 writeq(xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); 772 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr);
773 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); 773 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg);
774 writel(xhci->s3.erst_size, &xhci->ir_set->erst_size); 774 writel(xhci->s3.erst_size, &xhci->ir_set->erst_size);
775 writeq(xhci->s3.erst_base, &xhci->ir_set->erst_base); 775 xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base);
776 writeq(xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue); 776 xhci_write_64(xhci, xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue);
777 writel(xhci->s3.irq_pending, &xhci->ir_set->irq_pending); 777 writel(xhci->s3.irq_pending, &xhci->ir_set->irq_pending);
778 writel(xhci->s3.irq_control, &xhci->ir_set->irq_control); 778 writel(xhci->s3.irq_control, &xhci->ir_set->irq_control);
779} 779}
@@ -783,7 +783,7 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
783 u64 val_64; 783 u64 val_64;
784 784
785 /* step 2: initialize command ring buffer */ 785 /* step 2: initialize command ring buffer */
786 val_64 = readq(&xhci->op_regs->cmd_ring); 786 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
787 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | 787 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
788 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, 788 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
789 xhci->cmd_ring->dequeue) & 789 xhci->cmd_ring->dequeue) &
@@ -792,7 +792,7 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
792 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 792 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
793 "// Setting command ring address to 0x%llx", 793 "// Setting command ring address to 0x%llx",
794 (long unsigned long) val_64); 794 (long unsigned long) val_64);
795 writeq(val_64, &xhci->op_regs->cmd_ring); 795 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
796} 796}
797 797
798/* 798/*
@@ -3842,7 +3842,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
3842 if (ret) { 3842 if (ret) {
3843 return ret; 3843 return ret;
3844 } 3844 }
3845 temp_64 = readq(&xhci->op_regs->dcbaa_ptr); 3845 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
3846 xhci_dbg_trace(xhci, trace_xhci_dbg_address, 3846 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3847 "Op regs DCBAA ptr = %#016llx", temp_64); 3847 "Op regs DCBAA ptr = %#016llx", temp_64);
3848 xhci_dbg_trace(xhci, trace_xhci_dbg_address, 3848 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
@@ -4730,8 +4730,8 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4730 struct device *dev = hcd->self.controller; 4730 struct device *dev = hcd->self.controller;
4731 int retval; 4731 int retval;
4732 4732
4733 /* Limit the block layer scatter-gather lists to half a segment. */ 4733 /* Accept arbitrarily long scatter-gather lists */
4734 hcd->self.sg_tablesize = TRBS_PER_SEGMENT / 2; 4734 hcd->self.sg_tablesize = ~0;
4735 4735
4736 /* support to build packet from discontinuous buffers */ 4736 /* support to build packet from discontinuous buffers */
4737 hcd->self.no_sg_constraint = 1; 4737 hcd->self.no_sg_constraint = 1;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index f8416639bf31..58ed9d088e63 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -28,17 +28,6 @@
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/usb/hcd.h> 29#include <linux/usb/hcd.h>
30 30
31/*
32 * Registers should always be accessed with double word or quad word accesses.
33 *
34 * Some xHCI implementations may support 64-bit address pointers. Registers
35 * with 64-bit address pointers should be written to with dword accesses by
36 * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second.
37 * xHCI implementations that do not support 64-bit address pointers will ignore
38 * the high dword, and write order is irrelevant.
39 */
40#include <asm-generic/io-64-nonatomic-lo-hi.h>
41
42/* Code sharing between pci-quirks and xhci hcd */ 31/* Code sharing between pci-quirks and xhci hcd */
43#include "xhci-ext-caps.h" 32#include "xhci-ext-caps.h"
44#include "pci-quirks.h" 33#include "pci-quirks.h"
@@ -1279,7 +1268,7 @@ union xhci_trb {
1279 * since the command ring is 64-byte aligned. 1268 * since the command ring is 64-byte aligned.
1280 * It must also be greater than 16. 1269 * It must also be greater than 16.
1281 */ 1270 */
1282#define TRBS_PER_SEGMENT 256 1271#define TRBS_PER_SEGMENT 64
1283/* Allow two commands + a link TRB, along with any reserved command TRBs */ 1272/* Allow two commands + a link TRB, along with any reserved command TRBs */
1284#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) 1273#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
1285#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16) 1274#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
@@ -1614,6 +1603,34 @@ static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1614#define xhci_warn_ratelimited(xhci, fmt, args...) \ 1603#define xhci_warn_ratelimited(xhci, fmt, args...) \
1615 dev_warn_ratelimited(xhci_to_hcd(xhci)->self.controller , fmt , ## args) 1604 dev_warn_ratelimited(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1616 1605
1606/*
1607 * Registers should always be accessed with double word or quad word accesses.
1608 *
1609 * Some xHCI implementations may support 64-bit address pointers. Registers
1610 * with 64-bit address pointers should be written to with dword accesses by
1611 * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second.
1612 * xHCI implementations that do not support 64-bit address pointers will ignore
1613 * the high dword, and write order is irrelevant.
1614 */
1615static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
1616 __le64 __iomem *regs)
1617{
1618 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1619 u64 val_lo = readl(ptr);
1620 u64 val_hi = readl(ptr + 1);
1621 return val_lo + (val_hi << 32);
1622}
1623static inline void xhci_write_64(struct xhci_hcd *xhci,
1624 const u64 val, __le64 __iomem *regs)
1625{
1626 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1627 u32 val_lo = lower_32_bits(val);
1628 u32 val_hi = upper_32_bits(val);
1629
1630 writel(val_lo, ptr);
1631 writel(val_hi, ptr + 1);
1632}
1633
1617static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) 1634static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
1618{ 1635{
1619 return xhci->quirks & XHCI_LINK_TRB_QUIRK; 1636 return xhci->quirks & XHCI_LINK_TRB_QUIRK;
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index fc192ad9cc6a..239ad0b1ceb6 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -477,8 +477,11 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
477 musb->port1_status |= 477 musb->port1_status |=
478 (USB_PORT_STAT_C_SUSPEND << 16) 478 (USB_PORT_STAT_C_SUSPEND << 16)
479 | MUSB_PORT_STAT_RESUME; 479 | MUSB_PORT_STAT_RESUME;
480 musb->rh_timer = jiffies
481 + msecs_to_jiffies(20);
480 schedule_delayed_work( 482 schedule_delayed_work(
481 &musb->finish_resume_work, 20); 483 &musb->finish_resume_work,
484 msecs_to_jiffies(20));
482 485
483 musb->xceiv->state = OTG_STATE_A_HOST; 486 musb->xceiv->state = OTG_STATE_A_HOST;
484 musb->is_active = 1; 487 musb->is_active = 1;
@@ -2157,11 +2160,19 @@ static void musb_restore_context(struct musb *musb)
2157 void __iomem *musb_base = musb->mregs; 2160 void __iomem *musb_base = musb->mregs;
2158 void __iomem *ep_target_regs; 2161 void __iomem *ep_target_regs;
2159 void __iomem *epio; 2162 void __iomem *epio;
2163 u8 power;
2160 2164
2161 musb_writew(musb_base, MUSB_FRAME, musb->context.frame); 2165 musb_writew(musb_base, MUSB_FRAME, musb->context.frame);
2162 musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode); 2166 musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode);
2163 musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl); 2167 musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
2164 musb_writeb(musb_base, MUSB_POWER, musb->context.power); 2168
2169 /* Don't affect SUSPENDM/RESUME bits in POWER reg */
2170 power = musb_readb(musb_base, MUSB_POWER);
2171 power &= MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME;
2172 musb->context.power &= ~(MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME);
2173 power |= musb->context.power;
2174 musb_writeb(musb_base, MUSB_POWER, power);
2175
2165 musb_writew(musb_base, MUSB_INTRTXE, musb->intrtxe); 2176 musb_writew(musb_base, MUSB_INTRTXE, musb->intrtxe);
2166 musb_writew(musb_base, MUSB_INTRRXE, musb->intrrxe); 2177 musb_writew(musb_base, MUSB_INTRRXE, musb->intrrxe);
2167 musb_writeb(musb_base, MUSB_INTRUSBE, musb->context.intrusbe); 2178 musb_writeb(musb_base, MUSB_INTRUSBE, musb->context.intrusbe);
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index ed455724017b..abb38c3833ef 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -1183,6 +1183,9 @@ irqreturn_t musb_h_ep0_irq(struct musb *musb)
1183 csr = MUSB_CSR0_H_STATUSPKT 1183 csr = MUSB_CSR0_H_STATUSPKT
1184 | MUSB_CSR0_TXPKTRDY; 1184 | MUSB_CSR0_TXPKTRDY;
1185 1185
1186 /* disable ping token in status phase */
1187 csr |= MUSB_CSR0_H_DIS_PING;
1188
1186 /* flag status stage */ 1189 /* flag status stage */
1187 musb->ep0_stage = MUSB_EP0_STATUS; 1190 musb->ep0_stage = MUSB_EP0_STATUS;
1188 1191
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index eb634433ef09..e2d2d8c9891b 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -135,7 +135,8 @@ void musb_port_suspend(struct musb *musb, bool do_suspend)
135 135
136 /* later, GetPortStatus will stop RESUME signaling */ 136 /* later, GetPortStatus will stop RESUME signaling */
137 musb->port1_status |= MUSB_PORT_STAT_RESUME; 137 musb->port1_status |= MUSB_PORT_STAT_RESUME;
138 schedule_delayed_work(&musb->finish_resume_work, 20); 138 schedule_delayed_work(&musb->finish_resume_work,
139 msecs_to_jiffies(20));
139 } 140 }
140} 141}
141 142
@@ -158,7 +159,6 @@ void musb_port_reset(struct musb *musb, bool do_reset)
158 */ 159 */
159 power = musb_readb(mbase, MUSB_POWER); 160 power = musb_readb(mbase, MUSB_POWER);
160 if (do_reset) { 161 if (do_reset) {
161
162 /* 162 /*
163 * If RESUME is set, we must make sure it stays minimum 20 ms. 163 * If RESUME is set, we must make sure it stays minimum 20 ms.
164 * Then we must clear RESUME and wait a bit to let musb start 164 * Then we must clear RESUME and wait a bit to let musb start
@@ -167,11 +167,22 @@ void musb_port_reset(struct musb *musb, bool do_reset)
167 * detected". 167 * detected".
168 */ 168 */
169 if (power & MUSB_POWER_RESUME) { 169 if (power & MUSB_POWER_RESUME) {
170 while (time_before(jiffies, musb->rh_timer)) 170 long remain = (unsigned long) musb->rh_timer - jiffies;
171 msleep(1); 171
172 if (musb->rh_timer > 0 && remain > 0) {
173 /* take into account the minimum delay after resume */
174 schedule_delayed_work(
175 &musb->deassert_reset_work, remain);
176 return;
177 }
178
172 musb_writeb(mbase, MUSB_POWER, 179 musb_writeb(mbase, MUSB_POWER,
173 power & ~MUSB_POWER_RESUME); 180 power & ~MUSB_POWER_RESUME);
174 msleep(1); 181
182 /* Give the core 1 ms to clear MUSB_POWER_RESUME */
183 schedule_delayed_work(&musb->deassert_reset_work,
184 msecs_to_jiffies(1));
185 return;
175 } 186 }
176 187
177 power &= 0xf0; 188 power &= 0xf0;
@@ -180,7 +191,8 @@ void musb_port_reset(struct musb *musb, bool do_reset)
180 191
181 musb->port1_status |= USB_PORT_STAT_RESET; 192 musb->port1_status |= USB_PORT_STAT_RESET;
182 musb->port1_status &= ~USB_PORT_STAT_ENABLE; 193 musb->port1_status &= ~USB_PORT_STAT_ENABLE;
183 schedule_delayed_work(&musb->deassert_reset_work, 50); 194 schedule_delayed_work(&musb->deassert_reset_work,
195 msecs_to_jiffies(50));
184 } else { 196 } else {
185 dev_dbg(musb->controller, "root port reset stopped\n"); 197 dev_dbg(musb->controller, "root port reset stopped\n");
186 musb_writeb(mbase, MUSB_POWER, 198 musb_writeb(mbase, MUSB_POWER,
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 2a408cdaf7b2..8aa59a2c5eb2 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -659,7 +659,6 @@ static int omap2430_runtime_suspend(struct device *dev)
659 OTG_INTERFSEL); 659 OTG_INTERFSEL);
660 660
661 omap2430_low_level_exit(musb); 661 omap2430_low_level_exit(musb);
662 phy_power_off(musb->phy);
663 } 662 }
664 663
665 return 0; 664 return 0;
@@ -674,7 +673,6 @@ static int omap2430_runtime_resume(struct device *dev)
674 omap2430_low_level_init(musb); 673 omap2430_low_level_init(musb);
675 musb_writel(musb->mregs, OTG_INTERFSEL, 674 musb_writel(musb->mregs, OTG_INTERFSEL,
676 musb->context.otg_interfsel); 675 musb->context.otg_interfsel);
677 phy_power_on(musb->phy);
678 } 676 }
679 677
680 return 0; 678 return 0;
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 8546c8dccd51..d204f745ed05 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -159,32 +159,6 @@ put_3p3:
159 return rc; 159 return rc;
160} 160}
161 161
162#ifdef CONFIG_PM_SLEEP
163#define USB_PHY_SUSP_DIG_VOL 500000
164static int msm_hsusb_config_vddcx(int high)
165{
166 int max_vol = USB_PHY_VDD_DIG_VOL_MAX;
167 int min_vol;
168 int ret;
169
170 if (high)
171 min_vol = USB_PHY_VDD_DIG_VOL_MIN;
172 else
173 min_vol = USB_PHY_SUSP_DIG_VOL;
174
175 ret = regulator_set_voltage(hsusb_vddcx, min_vol, max_vol);
176 if (ret) {
177 pr_err("%s: unable to set the voltage for regulator "
178 "HSUSB_VDDCX\n", __func__);
179 return ret;
180 }
181
182 pr_debug("%s: min_vol:%d max_vol:%d\n", __func__, min_vol, max_vol);
183
184 return ret;
185}
186#endif
187
188static int msm_hsusb_ldo_set_mode(int on) 162static int msm_hsusb_ldo_set_mode(int on)
189{ 163{
190 int ret = 0; 164 int ret = 0;
@@ -440,7 +414,32 @@ static int msm_otg_reset(struct usb_phy *phy)
440#define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) 414#define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000)
441#define PHY_RESUME_TIMEOUT_USEC (100 * 1000) 415#define PHY_RESUME_TIMEOUT_USEC (100 * 1000)
442 416
443#ifdef CONFIG_PM_SLEEP 417#ifdef CONFIG_PM
418
419#define USB_PHY_SUSP_DIG_VOL 500000
420static int msm_hsusb_config_vddcx(int high)
421{
422 int max_vol = USB_PHY_VDD_DIG_VOL_MAX;
423 int min_vol;
424 int ret;
425
426 if (high)
427 min_vol = USB_PHY_VDD_DIG_VOL_MIN;
428 else
429 min_vol = USB_PHY_SUSP_DIG_VOL;
430
431 ret = regulator_set_voltage(hsusb_vddcx, min_vol, max_vol);
432 if (ret) {
433 pr_err("%s: unable to set the voltage for regulator "
434 "HSUSB_VDDCX\n", __func__);
435 return ret;
436 }
437
438 pr_debug("%s: min_vol:%d max_vol:%d\n", __func__, min_vol, max_vol);
439
440 return ret;
441}
442
444static int msm_otg_suspend(struct msm_otg *motg) 443static int msm_otg_suspend(struct msm_otg *motg)
445{ 444{
446 struct usb_phy *phy = &motg->phy; 445 struct usb_phy *phy = &motg->phy;
@@ -1733,22 +1732,18 @@ static int msm_otg_pm_resume(struct device *dev)
1733} 1732}
1734#endif 1733#endif
1735 1734
1736#ifdef CONFIG_PM
1737static const struct dev_pm_ops msm_otg_dev_pm_ops = { 1735static const struct dev_pm_ops msm_otg_dev_pm_ops = {
1738 SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume) 1736 SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume)
1739 SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume, 1737 SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume,
1740 msm_otg_runtime_idle) 1738 msm_otg_runtime_idle)
1741}; 1739};
1742#endif
1743 1740
1744static struct platform_driver msm_otg_driver = { 1741static struct platform_driver msm_otg_driver = {
1745 .remove = msm_otg_remove, 1742 .remove = msm_otg_remove,
1746 .driver = { 1743 .driver = {
1747 .name = DRIVER_NAME, 1744 .name = DRIVER_NAME,
1748 .owner = THIS_MODULE, 1745 .owner = THIS_MODULE,
1749#ifdef CONFIG_PM
1750 .pm = &msm_otg_dev_pm_ops, 1746 .pm = &msm_otg_dev_pm_ops,
1751#endif
1752 }, 1747 },
1753}; 1748};
1754 1749
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c
index e6f61e4361df..8afa813d690b 100644
--- a/drivers/usb/phy/phy.c
+++ b/drivers/usb/phy/phy.c
@@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)
130 130
131 phy = __usb_find_phy(&phy_list, type); 131 phy = __usb_find_phy(&phy_list, type);
132 if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) { 132 if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
133 pr_err("unable to find transceiver of type %s\n", 133 pr_debug("PHY: unable to find transceiver of type %s\n",
134 usb_phy_type_string(type)); 134 usb_phy_type_string(type));
135 goto err0; 135 goto err0;
136 } 136 }
@@ -228,7 +228,7 @@ struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index)
228 228
229 phy = __usb_find_phy_dev(dev, &phy_bind_list, index); 229 phy = __usb_find_phy_dev(dev, &phy_bind_list, index);
230 if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) { 230 if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
231 pr_err("unable to find transceiver\n"); 231 dev_dbg(dev, "unable to find transceiver\n");
232 goto err0; 232 goto err0;
233 } 233 }
234 234
@@ -424,10 +424,8 @@ int usb_bind_phy(const char *dev_name, u8 index,
424 unsigned long flags; 424 unsigned long flags;
425 425
426 phy_bind = kzalloc(sizeof(*phy_bind), GFP_KERNEL); 426 phy_bind = kzalloc(sizeof(*phy_bind), GFP_KERNEL);
427 if (!phy_bind) { 427 if (!phy_bind)
428 pr_err("phy_bind(): No memory for phy_bind");
429 return -ENOMEM; 428 return -ENOMEM;
430 }
431 429
432 phy_bind->dev_name = dev_name; 430 phy_bind->dev_name = dev_name;
433 phy_bind->phy_dev_name = phy_dev_name; 431 phy_bind->phy_dev_name = phy_dev_name;
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index ce0d7b0db012..44ab12986805 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -152,6 +152,7 @@ static const struct usb_device_id id_table_combined[] = {
152 { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) }, 152 { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) },
153 { USB_DEVICE(FTDI_VID, FTDI_CANDAPTER_PID) }, 153 { USB_DEVICE(FTDI_VID, FTDI_CANDAPTER_PID) },
154 { USB_DEVICE(FTDI_VID, FTDI_NXTCAM_PID) }, 154 { USB_DEVICE(FTDI_VID, FTDI_NXTCAM_PID) },
155 { USB_DEVICE(FTDI_VID, FTDI_EV3CON_PID) },
155 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_0_PID) }, 156 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_0_PID) },
156 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_1_PID) }, 157 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_1_PID) },
157 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_2_PID) }, 158 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_2_PID) },
@@ -191,6 +192,8 @@ static const struct usb_device_id id_table_combined[] = {
191 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) }, 192 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
192 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) }, 193 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
193 { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) }, 194 { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) },
195 { USB_DEVICE(FTDI_VID, FTDI_TAGSYS_LP101_PID) },
196 { USB_DEVICE(FTDI_VID, FTDI_TAGSYS_P200X_PID) },
194 { USB_DEVICE(FTDI_VID, FTDI_LENZ_LIUSB_PID) }, 197 { USB_DEVICE(FTDI_VID, FTDI_LENZ_LIUSB_PID) },
195 { USB_DEVICE(FTDI_VID, FTDI_XF_632_PID) }, 198 { USB_DEVICE(FTDI_VID, FTDI_XF_632_PID) },
196 { USB_DEVICE(FTDI_VID, FTDI_XF_634_PID) }, 199 { USB_DEVICE(FTDI_VID, FTDI_XF_634_PID) },
@@ -904,6 +907,8 @@ static const struct usb_device_id id_table_combined[] = {
904 /* Crucible Devices */ 907 /* Crucible Devices */
905 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) }, 908 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) },
906 { USB_DEVICE(FTDI_VID, FTDI_Z3X_PID) }, 909 { USB_DEVICE(FTDI_VID, FTDI_Z3X_PID) },
910 /* Cressi Devices */
911 { USB_DEVICE(FTDI_VID, FTDI_CRESSI_PID) },
907 { } /* Terminating entry */ 912 { } /* Terminating entry */
908}; 913};
909 914
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index a7019d1e3058..e599fbfcde5f 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -50,6 +50,7 @@
50#define TI_XDS100V2_PID 0xa6d0 50#define TI_XDS100V2_PID 0xa6d0
51 51
52#define FTDI_NXTCAM_PID 0xABB8 /* NXTCam for Mindstorms NXT */ 52#define FTDI_NXTCAM_PID 0xABB8 /* NXTCam for Mindstorms NXT */
53#define FTDI_EV3CON_PID 0xABB9 /* Mindstorms EV3 Console Adapter */
53 54
54/* US Interface Navigator (http://www.usinterface.com/) */ 55/* US Interface Navigator (http://www.usinterface.com/) */
55#define FTDI_USINT_CAT_PID 0xb810 /* Navigator CAT and 2nd PTT lines */ 56#define FTDI_USINT_CAT_PID 0xb810 /* Navigator CAT and 2nd PTT lines */
@@ -363,6 +364,12 @@
363/* Sprog II (Andrew Crosland's SprogII DCC interface) */ 364/* Sprog II (Andrew Crosland's SprogII DCC interface) */
364#define FTDI_SPROG_II 0xF0C8 365#define FTDI_SPROG_II 0xF0C8
365 366
367/*
368 * Two of the Tagsys RFID Readers
369 */
370#define FTDI_TAGSYS_LP101_PID 0xF0E9 /* Tagsys L-P101 RFID*/
371#define FTDI_TAGSYS_P200X_PID 0xF0EE /* Tagsys Medio P200x RFID*/
372
366/* an infrared receiver for user access control with IR tags */ 373/* an infrared receiver for user access control with IR tags */
367#define FTDI_PIEGROUP_PID 0xF208 /* Product Id */ 374#define FTDI_PIEGROUP_PID 0xF208 /* Product Id */
368 375
@@ -1313,3 +1320,9 @@
1313 * Manufacturer: Smart GSM Team 1320 * Manufacturer: Smart GSM Team
1314 */ 1321 */
1315#define FTDI_Z3X_PID 0x0011 1322#define FTDI_Z3X_PID 0x0011
1323
1324/*
1325 * Product: Cressi PC Interface
1326 * Manufacturer: Cressi
1327 */
1328#define FTDI_CRESSI_PID 0x87d0
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 5c86f57e4afa..68fc9fe65936 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -1362,7 +1362,8 @@ static const struct usb_device_id option_ids[] = {
1362 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1267, 0xff, 0xff, 0xff) }, 1362 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1267, 0xff, 0xff, 0xff) },
1363 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1268, 0xff, 0xff, 0xff) }, 1363 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1268, 0xff, 0xff, 0xff) },
1364 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1269, 0xff, 0xff, 0xff) }, 1364 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1269, 0xff, 0xff, 0xff) },
1365 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1270, 0xff, 0xff, 0xff) }, 1365 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1270, 0xff, 0xff, 0xff),
1366 .driver_info = (kernel_ulong_t)&net_intf5_blacklist },
1366 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1271, 0xff, 0xff, 0xff) }, 1367 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1271, 0xff, 0xff, 0xff) },
1367 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1272, 0xff, 0xff, 0xff) }, 1368 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1272, 0xff, 0xff, 0xff) },
1368 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1273, 0xff, 0xff, 0xff) }, 1369 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1273, 0xff, 0xff, 0xff) },
@@ -1525,7 +1526,8 @@ static const struct usb_device_id option_ids[] = {
1525 /* Cinterion */ 1526 /* Cinterion */
1526 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_EU3_E) }, 1527 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_EU3_E) },
1527 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_EU3_P) }, 1528 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_EU3_P) },
1528 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_PH8) }, 1529 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_PH8),
1530 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1529 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX) }, 1531 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX) },
1530 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_PLXX), 1532 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_PLXX),
1531 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 1533 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c
index c65437cfd4a2..968a40201e5f 100644
--- a/drivers/usb/serial/qcserial.c
+++ b/drivers/usb/serial/qcserial.c
@@ -139,6 +139,9 @@ static const struct usb_device_id id_table[] = {
139 {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901c, 0)}, /* Sierra Wireless EM7700 Device Management */ 139 {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901c, 0)}, /* Sierra Wireless EM7700 Device Management */
140 {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901c, 2)}, /* Sierra Wireless EM7700 NMEA */ 140 {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901c, 2)}, /* Sierra Wireless EM7700 NMEA */
141 {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901c, 3)}, /* Sierra Wireless EM7700 Modem */ 141 {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901c, 3)}, /* Sierra Wireless EM7700 Modem */
142 {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x9051, 0)}, /* Netgear AirCard 340U Device Management */
143 {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x9051, 2)}, /* Netgear AirCard 340U NMEA */
144 {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x9051, 3)}, /* Netgear AirCard 340U Modem */
142 145
143 { } /* Terminating entry */ 146 { } /* Terminating entry */
144}; 147};
diff --git a/drivers/usb/serial/usb-serial-simple.c b/drivers/usb/serial/usb-serial-simple.c
index f112b079ddfc..fb79775447b0 100644
--- a/drivers/usb/serial/usb-serial-simple.c
+++ b/drivers/usb/serial/usb-serial-simple.c
@@ -71,7 +71,8 @@ DEVICE(hp4x, HP4X_IDS);
71 71
72/* Suunto ANT+ USB Driver */ 72/* Suunto ANT+ USB Driver */
73#define SUUNTO_IDS() \ 73#define SUUNTO_IDS() \
74 { USB_DEVICE(0x0fcf, 0x1008) } 74 { USB_DEVICE(0x0fcf, 0x1008) }, \
75 { USB_DEVICE(0x0fcf, 0x1009) } /* Dynastream ANT USB-m Stick */
75DEVICE(suunto, SUUNTO_IDS); 76DEVICE(suunto, SUUNTO_IDS);
76 77
77/* Siemens USB/MPI adapter */ 78/* Siemens USB/MPI adapter */
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index 8470e1b114f2..1dd0604d1911 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -18,7 +18,9 @@ config USB_STORAGE
18 18
19 This option depends on 'SCSI' support being enabled, but you 19 This option depends on 'SCSI' support being enabled, but you
20 probably also need 'SCSI device support: SCSI disk support' 20 probably also need 'SCSI device support: SCSI disk support'
21 (BLK_DEV_SD) for most USB storage devices. 21 (BLK_DEV_SD) for most USB storage devices. Some devices also
22 will require 'Probe all LUNs on each SCSI device'
23 (SCSI_MULTI_LUN).
22 24
23 To compile this driver as a module, choose M here: the 25 To compile this driver as a module, choose M here: the
24 module will be called usb-storage. 26 module will be called usb-storage.
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 18509e6c21ab..9d38ddc8da49 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -78,6 +78,8 @@ static const char* host_info(struct Scsi_Host *host)
78 78
79static int slave_alloc (struct scsi_device *sdev) 79static int slave_alloc (struct scsi_device *sdev)
80{ 80{
81 struct us_data *us = host_to_us(sdev->host);
82
81 /* 83 /*
82 * Set the INQUIRY transfer length to 36. We don't use any of 84 * Set the INQUIRY transfer length to 36. We don't use any of
83 * the extra data and many devices choke if asked for more or 85 * the extra data and many devices choke if asked for more or
@@ -102,6 +104,10 @@ static int slave_alloc (struct scsi_device *sdev)
102 */ 104 */
103 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1)); 105 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
104 106
107 /* Tell the SCSI layer if we know there is more than one LUN */
108 if (us->protocol == USB_PR_BULK && us->max_lun > 0)
109 sdev->sdev_bflags |= BLIST_FORCELUN;
110
105 return 0; 111 return 0;
106} 112}
107 113
diff --git a/drivers/usb/storage/unusual_cypress.h b/drivers/usb/storage/unusual_cypress.h
index 65a6a75066a8..82e8ed0324e3 100644
--- a/drivers/usb/storage/unusual_cypress.h
+++ b/drivers/usb/storage/unusual_cypress.h
@@ -31,7 +31,7 @@ UNUSUAL_DEV( 0x04b4, 0x6831, 0x0000, 0x9999,
31 "Cypress ISD-300LP", 31 "Cypress ISD-300LP",
32 USB_SC_CYP_ATACB, USB_PR_DEVICE, NULL, 0), 32 USB_SC_CYP_ATACB, USB_PR_DEVICE, NULL, 0),
33 33
34UNUSUAL_DEV( 0x14cd, 0x6116, 0x0000, 0x0219, 34UNUSUAL_DEV( 0x14cd, 0x6116, 0x0160, 0x0160,
35 "Super Top", 35 "Super Top",
36 "USB 2.0 SATA BRIDGE", 36 "USB 2.0 SATA BRIDGE",
37 USB_SC_CYP_ATACB, USB_PR_DEVICE, NULL, 0), 37 USB_SC_CYP_ATACB, USB_PR_DEVICE, NULL, 0),
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index ad06255c2ade..adbeb255616a 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1455,6 +1455,13 @@ UNUSUAL_DEV( 0x0f88, 0x042e, 0x0100, 0x0100,
1455 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 1455 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1456 US_FL_FIX_CAPACITY ), 1456 US_FL_FIX_CAPACITY ),
1457 1457
1458/* Reported by Moritz Moeller-Herrmann <moritz-kernel@moeller-herrmann.de> */
1459UNUSUAL_DEV( 0x0fca, 0x8004, 0x0201, 0x0201,
1460 "Research In Motion",
1461 "BlackBerry Bold 9000",
1462 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1463 US_FL_MAX_SECTORS_64 ),
1464
1458/* Reported by Michael Stattmann <michael@stattmann.com> */ 1465/* Reported by Michael Stattmann <michael@stattmann.com> */
1459UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000, 1466UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000,
1460 "Sony Ericsson", 1467 "Sony Ericsson",
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 4fb7a8f83c8a..54af4e933695 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -186,12 +186,12 @@ static bool is_invalid_reserved_pfn(unsigned long pfn)
186 if (pfn_valid(pfn)) { 186 if (pfn_valid(pfn)) {
187 bool reserved; 187 bool reserved;
188 struct page *tail = pfn_to_page(pfn); 188 struct page *tail = pfn_to_page(pfn);
189 struct page *head = compound_trans_head(tail); 189 struct page *head = compound_head(tail);
190 reserved = !!(PageReserved(head)); 190 reserved = !!(PageReserved(head));
191 if (head != tail) { 191 if (head != tail) {
192 /* 192 /*
193 * "head" is not a dangling pointer 193 * "head" is not a dangling pointer
194 * (compound_trans_head takes care of that) 194 * (compound_head takes care of that)
195 * but the hugepage may have been split 195 * but the hugepage may have been split
196 * from under us (and we may not hold a 196 * from under us (and we may not hold a
197 * reference count on the head page so it can 197 * reference count on the head page so it can
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 9a68409580d5..e1e22e0f01e8 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -70,7 +70,12 @@ enum {
70}; 70};
71 71
72struct vhost_net_ubuf_ref { 72struct vhost_net_ubuf_ref {
73 struct kref kref; 73 /* refcount follows semantics similar to kref:
74 * 0: object is released
75 * 1: no outstanding ubufs
76 * >1: outstanding ubufs
77 */
78 atomic_t refcount;
74 wait_queue_head_t wait; 79 wait_queue_head_t wait;
75 struct vhost_virtqueue *vq; 80 struct vhost_virtqueue *vq;
76}; 81};
@@ -116,14 +121,6 @@ static void vhost_net_enable_zcopy(int vq)
116 vhost_net_zcopy_mask |= 0x1 << vq; 121 vhost_net_zcopy_mask |= 0x1 << vq;
117} 122}
118 123
119static void vhost_net_zerocopy_done_signal(struct kref *kref)
120{
121 struct vhost_net_ubuf_ref *ubufs;
122
123 ubufs = container_of(kref, struct vhost_net_ubuf_ref, kref);
124 wake_up(&ubufs->wait);
125}
126
127static struct vhost_net_ubuf_ref * 124static struct vhost_net_ubuf_ref *
128vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool zcopy) 125vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool zcopy)
129{ 126{
@@ -134,21 +131,24 @@ vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool zcopy)
134 ubufs = kmalloc(sizeof(*ubufs), GFP_KERNEL); 131 ubufs = kmalloc(sizeof(*ubufs), GFP_KERNEL);
135 if (!ubufs) 132 if (!ubufs)
136 return ERR_PTR(-ENOMEM); 133 return ERR_PTR(-ENOMEM);
137 kref_init(&ubufs->kref); 134 atomic_set(&ubufs->refcount, 1);
138 init_waitqueue_head(&ubufs->wait); 135 init_waitqueue_head(&ubufs->wait);
139 ubufs->vq = vq; 136 ubufs->vq = vq;
140 return ubufs; 137 return ubufs;
141} 138}
142 139
143static void vhost_net_ubuf_put(struct vhost_net_ubuf_ref *ubufs) 140static int vhost_net_ubuf_put(struct vhost_net_ubuf_ref *ubufs)
144{ 141{
145 kref_put(&ubufs->kref, vhost_net_zerocopy_done_signal); 142 int r = atomic_sub_return(1, &ubufs->refcount);
143 if (unlikely(!r))
144 wake_up(&ubufs->wait);
145 return r;
146} 146}
147 147
148static void vhost_net_ubuf_put_and_wait(struct vhost_net_ubuf_ref *ubufs) 148static void vhost_net_ubuf_put_and_wait(struct vhost_net_ubuf_ref *ubufs)
149{ 149{
150 kref_put(&ubufs->kref, vhost_net_zerocopy_done_signal); 150 vhost_net_ubuf_put(ubufs);
151 wait_event(ubufs->wait, !atomic_read(&ubufs->kref.refcount)); 151 wait_event(ubufs->wait, !atomic_read(&ubufs->refcount));
152} 152}
153 153
154static void vhost_net_ubuf_put_wait_and_free(struct vhost_net_ubuf_ref *ubufs) 154static void vhost_net_ubuf_put_wait_and_free(struct vhost_net_ubuf_ref *ubufs)
@@ -306,23 +306,26 @@ static void vhost_zerocopy_callback(struct ubuf_info *ubuf, bool success)
306{ 306{
307 struct vhost_net_ubuf_ref *ubufs = ubuf->ctx; 307 struct vhost_net_ubuf_ref *ubufs = ubuf->ctx;
308 struct vhost_virtqueue *vq = ubufs->vq; 308 struct vhost_virtqueue *vq = ubufs->vq;
309 int cnt = atomic_read(&ubufs->kref.refcount); 309 int cnt;
310
311 rcu_read_lock_bh();
310 312
311 /* set len to mark this desc buffers done DMA */ 313 /* set len to mark this desc buffers done DMA */
312 vq->heads[ubuf->desc].len = success ? 314 vq->heads[ubuf->desc].len = success ?
313 VHOST_DMA_DONE_LEN : VHOST_DMA_FAILED_LEN; 315 VHOST_DMA_DONE_LEN : VHOST_DMA_FAILED_LEN;
314 vhost_net_ubuf_put(ubufs); 316 cnt = vhost_net_ubuf_put(ubufs);
315 317
316 /* 318 /*
317 * Trigger polling thread if guest stopped submitting new buffers: 319 * Trigger polling thread if guest stopped submitting new buffers:
318 * in this case, the refcount after decrement will eventually reach 1 320 * in this case, the refcount after decrement will eventually reach 1.
319 * so here it is 2.
320 * We also trigger polling periodically after each 16 packets 321 * We also trigger polling periodically after each 16 packets
321 * (the value 16 here is more or less arbitrary, it's tuned to trigger 322 * (the value 16 here is more or less arbitrary, it's tuned to trigger
322 * less than 10% of times). 323 * less than 10% of times).
323 */ 324 */
324 if (cnt <= 2 || !(cnt % 16)) 325 if (cnt <= 1 || !(cnt % 16))
325 vhost_poll_queue(&vq->poll); 326 vhost_poll_queue(&vq->poll);
327
328 rcu_read_unlock_bh();
326} 329}
327 330
328/* Expects to be always run from workqueue - which acts as 331/* Expects to be always run from workqueue - which acts as
@@ -420,7 +423,7 @@ static void handle_tx(struct vhost_net *net)
420 msg.msg_control = ubuf; 423 msg.msg_control = ubuf;
421 msg.msg_controllen = sizeof(ubuf); 424 msg.msg_controllen = sizeof(ubuf);
422 ubufs = nvq->ubufs; 425 ubufs = nvq->ubufs;
423 kref_get(&ubufs->kref); 426 atomic_inc(&ubufs->refcount);
424 nvq->upend_idx = (nvq->upend_idx + 1) % UIO_MAXIOV; 427 nvq->upend_idx = (nvq->upend_idx + 1) % UIO_MAXIOV;
425 } else { 428 } else {
426 msg.msg_control = NULL; 429 msg.msg_control = NULL;
@@ -502,9 +505,13 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
502 r = -ENOBUFS; 505 r = -ENOBUFS;
503 goto err; 506 goto err;
504 } 507 }
505 d = vhost_get_vq_desc(vq->dev, vq, vq->iov + seg, 508 r = vhost_get_vq_desc(vq->dev, vq, vq->iov + seg,
506 ARRAY_SIZE(vq->iov) - seg, &out, 509 ARRAY_SIZE(vq->iov) - seg, &out,
507 &in, log, log_num); 510 &in, log, log_num);
511 if (unlikely(r < 0))
512 goto err;
513
514 d = r;
508 if (d == vq->num) { 515 if (d == vq->num) {
509 r = 0; 516 r = 0;
510 goto err; 517 goto err;
@@ -529,6 +536,12 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
529 *iovcount = seg; 536 *iovcount = seg;
530 if (unlikely(log)) 537 if (unlikely(log))
531 *log_num = nlogs; 538 *log_num = nlogs;
539
540 /* Detect overrun */
541 if (unlikely(datalen > 0)) {
542 r = UIO_MAXIOV + 1;
543 goto err;
544 }
532 return headcount; 545 return headcount;
533err: 546err:
534 vhost_discard_vq_desc(vq, headcount); 547 vhost_discard_vq_desc(vq, headcount);
@@ -584,6 +597,14 @@ static void handle_rx(struct vhost_net *net)
584 /* On error, stop handling until the next kick. */ 597 /* On error, stop handling until the next kick. */
585 if (unlikely(headcount < 0)) 598 if (unlikely(headcount < 0))
586 break; 599 break;
600 /* On overrun, truncate and discard */
601 if (unlikely(headcount > UIO_MAXIOV)) {
602 msg.msg_iovlen = 1;
603 err = sock->ops->recvmsg(NULL, sock, &msg,
604 1, MSG_DONTWAIT | MSG_TRUNC);
605 pr_debug("Discarded rx packet: len %zd\n", sock_len);
606 continue;
607 }
587 /* OK, now we need to know about added descriptors. */ 608 /* OK, now we need to know about added descriptors. */
588 if (!headcount) { 609 if (!headcount) {
589 if (unlikely(vhost_enable_notify(&net->dev, vq))) { 610 if (unlikely(vhost_enable_notify(&net->dev, vq))) {
@@ -780,7 +801,7 @@ static void vhost_net_flush(struct vhost_net *n)
780 vhost_net_ubuf_put_and_wait(n->vqs[VHOST_NET_VQ_TX].ubufs); 801 vhost_net_ubuf_put_and_wait(n->vqs[VHOST_NET_VQ_TX].ubufs);
781 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); 802 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex);
782 n->tx_flush = false; 803 n->tx_flush = false;
783 kref_init(&n->vqs[VHOST_NET_VQ_TX].ubufs->kref); 804 atomic_set(&n->vqs[VHOST_NET_VQ_TX].ubufs->refcount, 1);
784 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); 805 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex);
785 } 806 }
786} 807}
@@ -800,6 +821,8 @@ static int vhost_net_release(struct inode *inode, struct file *f)
800 fput(tx_sock->file); 821 fput(tx_sock->file);
801 if (rx_sock) 822 if (rx_sock)
802 fput(rx_sock->file); 823 fput(rx_sock->file);
824 /* Make sure no callbacks are outstanding */
825 synchronize_rcu_bh();
803 /* We do an extra flush before freeing memory, 826 /* We do an extra flush before freeing memory,
804 * since jobs can re-queue themselves. */ 827 * since jobs can re-queue themselves. */
805 vhost_net_flush(n); 828 vhost_net_flush(n);
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 0a025b8e2a12..e48d4a672580 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1001,6 +1001,12 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1001 break; 1001 break;
1002 } 1002 }
1003 1003
1004 /* virtio-scsi spec requires byte 0 of the lun to be 1 */
1005 if (unlikely(v_req.lun[0] != 1)) {
1006 vhost_scsi_send_bad_target(vs, vq, head, out);
1007 continue;
1008 }
1009
1004 /* Extract the tpgt */ 1010 /* Extract the tpgt */
1005 target = v_req.lun[1]; 1011 target = v_req.lun[1];
1006 tpg = ACCESS_ONCE(vs_tpg[target]); 1012 tpg = ACCESS_ONCE(vs_tpg[target]);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 22262a3a0e2d..dade5b7699bc 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -364,7 +364,7 @@ config FB_SA1100
364 364
365config FB_IMX 365config FB_IMX
366 tristate "Freescale i.MX1/21/25/27 LCD support" 366 tristate "Freescale i.MX1/21/25/27 LCD support"
367 depends on FB && IMX_HAVE_PLATFORM_IMX_FB 367 depends on FB && ARCH_MXC
368 select FB_CFB_FILLRECT 368 select FB_CFB_FILLRECT
369 select FB_CFB_COPYAREA 369 select FB_CFB_COPYAREA
370 select FB_CFB_IMAGEBLIT 370 select FB_CFB_IMAGEBLIT
diff --git a/drivers/video/exynos/Kconfig b/drivers/video/exynos/Kconfig
index 1129d0e9e640..75c8a8e7efc0 100644
--- a/drivers/video/exynos/Kconfig
+++ b/drivers/video/exynos/Kconfig
@@ -22,7 +22,8 @@ config EXYNOS_MIPI_DSI
22 22
23config EXYNOS_LCD_S6E8AX0 23config EXYNOS_LCD_S6E8AX0
24 bool "S6E8AX0 MIPI AMOLED LCD Driver" 24 bool "S6E8AX0 MIPI AMOLED LCD Driver"
25 depends on (EXYNOS_MIPI_DSI && BACKLIGHT_CLASS_DEVICE && LCD_CLASS_DEVICE) 25 depends on EXYNOS_MIPI_DSI && BACKLIGHT_CLASS_DEVICE
26 depends on (LCD_CLASS_DEVICE = y)
26 default n 27 default n
27 help 28 help
28 If you have an S6E8AX0 MIPI AMOLED LCD Panel, say Y to enable its 29 If you have an S6E8AX0 MIPI AMOLED LCD Panel, say Y to enable its
diff --git a/drivers/video/omap2/dss/dispc.c b/drivers/video/omap2/dss/dispc.c
index bbeb8dd7f108..77d6221618f4 100644
--- a/drivers/video/omap2/dss/dispc.c
+++ b/drivers/video/omap2/dss/dispc.c
@@ -2160,8 +2160,8 @@ static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
2160 *five_taps = false; 2160 *five_taps = false;
2161 2161
2162 do { 2162 do {
2163 in_height = DIV_ROUND_UP(height, *decim_y); 2163 in_height = height / *decim_y;
2164 in_width = DIV_ROUND_UP(width, *decim_x); 2164 in_width = width / *decim_x;
2165 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, 2165 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
2166 in_height, out_width, out_height, mem_to_mem); 2166 in_height, out_width, out_height, mem_to_mem);
2167 error = (in_width > maxsinglelinewidth || !*core_clk || 2167 error = (in_width > maxsinglelinewidth || !*core_clk ||
@@ -2199,8 +2199,8 @@ static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
2199 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH); 2199 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2200 2200
2201 do { 2201 do {
2202 in_height = DIV_ROUND_UP(height, *decim_y); 2202 in_height = height / *decim_y;
2203 in_width = DIV_ROUND_UP(width, *decim_x); 2203 in_width = width / *decim_x;
2204 *five_taps = in_height > out_height; 2204 *five_taps = in_height > out_height;
2205 2205
2206 if (in_width > maxsinglelinewidth) 2206 if (in_width > maxsinglelinewidth)
@@ -2268,7 +2268,7 @@ static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
2268{ 2268{
2269 u16 in_width, in_width_max; 2269 u16 in_width, in_width_max;
2270 int decim_x_min = *decim_x; 2270 int decim_x_min = *decim_x;
2271 u16 in_height = DIV_ROUND_UP(height, *decim_y); 2271 u16 in_height = height / *decim_y;
2272 const int maxsinglelinewidth = 2272 const int maxsinglelinewidth =
2273 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH); 2273 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2274 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE); 2274 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
@@ -2287,7 +2287,7 @@ static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
2287 return -EINVAL; 2287 return -EINVAL;
2288 2288
2289 do { 2289 do {
2290 in_width = DIV_ROUND_UP(width, *decim_x); 2290 in_width = width / *decim_x;
2291 } while (*decim_x <= *x_predecim && 2291 } while (*decim_x <= *x_predecim &&
2292 in_width > maxsinglelinewidth && ++*decim_x); 2292 in_width > maxsinglelinewidth && ++*decim_x);
2293 2293
@@ -2466,8 +2466,8 @@ static int dispc_ovl_setup_common(enum omap_plane plane,
2466 if (r) 2466 if (r)
2467 return r; 2467 return r;
2468 2468
2469 in_width = DIV_ROUND_UP(in_width, x_predecim); 2469 in_width = in_width / x_predecim;
2470 in_height = DIV_ROUND_UP(in_height, y_predecim); 2470 in_height = in_height / y_predecim;
2471 2471
2472 if (color_mode == OMAP_DSS_COLOR_YUV2 || 2472 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2473 color_mode == OMAP_DSS_COLOR_UYVY || 2473 color_mode == OMAP_DSS_COLOR_UYVY ||
diff --git a/drivers/video/omap2/dss/dpi.c b/drivers/video/omap2/dss/dpi.c
index 7411f2674e16..23ef21ffc2c4 100644
--- a/drivers/video/omap2/dss/dpi.c
+++ b/drivers/video/omap2/dss/dpi.c
@@ -117,7 +117,7 @@ struct dpi_clk_calc_ctx {
117 /* outputs */ 117 /* outputs */
118 118
119 struct dsi_clock_info dsi_cinfo; 119 struct dsi_clock_info dsi_cinfo;
120 unsigned long long fck; 120 unsigned long fck;
121 struct dispc_clock_info dispc_cinfo; 121 struct dispc_clock_info dispc_cinfo;
122}; 122};
123 123
diff --git a/drivers/video/omap2/dss/sdi.c b/drivers/video/omap2/dss/sdi.c
index efb9ee9e3c96..ba806c9e7f54 100644
--- a/drivers/video/omap2/dss/sdi.c
+++ b/drivers/video/omap2/dss/sdi.c
@@ -46,7 +46,7 @@ static struct {
46struct sdi_clk_calc_ctx { 46struct sdi_clk_calc_ctx {
47 unsigned long pck_min, pck_max; 47 unsigned long pck_min, pck_max;
48 48
49 unsigned long long fck; 49 unsigned long fck;
50 struct dispc_clock_info dispc_cinfo; 50 struct dispc_clock_info dispc_cinfo;
51}; 51};
52 52
diff --git a/drivers/vme/bridges/vme_ca91cx42.c b/drivers/vme/bridges/vme_ca91cx42.c
index a06edbfa95ca..1b5d48c578e1 100644
--- a/drivers/vme/bridges/vme_ca91cx42.c
+++ b/drivers/vme/bridges/vme_ca91cx42.c
@@ -884,7 +884,7 @@ static ssize_t ca91cx42_master_read(struct vme_master_resource *image,
884 if (done == count) 884 if (done == count)
885 goto out; 885 goto out;
886 } 886 }
887 if ((uintptr_t)addr & 0x2) { 887 if ((uintptr_t)(addr + done) & 0x2) {
888 if ((count - done) < 2) { 888 if ((count - done) < 2) {
889 *(u8 *)(buf + done) = ioread8(addr + done); 889 *(u8 *)(buf + done) = ioread8(addr + done);
890 done += 1; 890 done += 1;
@@ -938,7 +938,7 @@ static ssize_t ca91cx42_master_write(struct vme_master_resource *image,
938 if (done == count) 938 if (done == count)
939 goto out; 939 goto out;
940 } 940 }
941 if ((uintptr_t)addr & 0x2) { 941 if ((uintptr_t)(addr + done) & 0x2) {
942 if ((count - done) < 2) { 942 if ((count - done) < 2) {
943 iowrite8(*(u8 *)(buf + done), addr + done); 943 iowrite8(*(u8 *)(buf + done), addr + done);
944 done += 1; 944 done += 1;
diff --git a/drivers/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c
index 16830d8b777c..9911cd5fddb5 100644
--- a/drivers/vme/bridges/vme_tsi148.c
+++ b/drivers/vme/bridges/vme_tsi148.c
@@ -1289,7 +1289,7 @@ static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf,
1289 if (done == count) 1289 if (done == count)
1290 goto out; 1290 goto out;
1291 } 1291 }
1292 if ((uintptr_t)addr & 0x2) { 1292 if ((uintptr_t)(addr + done) & 0x2) {
1293 if ((count - done) < 2) { 1293 if ((count - done) < 2) {
1294 *(u8 *)(buf + done) = ioread8(addr + done); 1294 *(u8 *)(buf + done) = ioread8(addr + done);
1295 done += 1; 1295 done += 1;
@@ -1371,7 +1371,7 @@ static ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf,
1371 if (done == count) 1371 if (done == count)
1372 goto out; 1372 goto out;
1373 } 1373 }
1374 if ((uintptr_t)addr & 0x2) { 1374 if ((uintptr_t)(addr + done) & 0x2) {
1375 if ((count - done) < 2) { 1375 if ((count - done) < 2) {
1376 iowrite8(*(u8 *)(buf + done), addr + done); 1376 iowrite8(*(u8 *)(buf + done), addr + done);
1377 done += 1; 1377 done += 1;
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 4c4c566c52a3..79d25894343a 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -223,6 +223,7 @@ config SA1100_WATCHDOG
223 223
224config DW_WATCHDOG 224config DW_WATCHDOG
225 tristate "Synopsys DesignWare watchdog" 225 tristate "Synopsys DesignWare watchdog"
226 depends on HAS_IOMEM
226 help 227 help
227 Say Y here if to include support for the Synopsys DesignWare 228 Say Y here if to include support for the Synopsys DesignWare
228 watchdog timer found in many chips. 229 watchdog timer found in many chips.
diff --git a/drivers/watchdog/w83697hf_wdt.c b/drivers/watchdog/w83697hf_wdt.c
index aaf2995d37f4..68b45fc9ba6a 100644
--- a/drivers/watchdog/w83697hf_wdt.c
+++ b/drivers/watchdog/w83697hf_wdt.c
@@ -402,7 +402,7 @@ static int __init wdt_init(void)
402 402
403 if (!found) { 403 if (!found) {
404 pr_err("No W83697HF/HG could be found\n"); 404 pr_err("No W83697HF/HG could be found\n");
405 ret = -EIO; 405 ret = -ENODEV;
406 goto out; 406 goto out;
407 } 407 }
408 408
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index d75c811bfa56..45e00afa7f2d 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -16,7 +16,6 @@ xen-pad-$(CONFIG_X86) += xen-acpi-pad.o
16dom0-$(CONFIG_X86) += pcpu.o 16dom0-$(CONFIG_X86) += pcpu.o
17obj-$(CONFIG_XEN_DOM0) += $(dom0-y) 17obj-$(CONFIG_XEN_DOM0) += $(dom0-y)
18obj-$(CONFIG_BLOCK) += biomerge.o 18obj-$(CONFIG_BLOCK) += biomerge.o
19obj-$(CONFIG_XEN_XENCOMM) += xencomm.o
20obj-$(CONFIG_XEN_BALLOON) += xen-balloon.o 19obj-$(CONFIG_XEN_BALLOON) += xen-balloon.o
21obj-$(CONFIG_XEN_SELFBALLOONING) += xen-selfballoon.o 20obj-$(CONFIG_XEN_SELFBALLOONING) += xen-selfballoon.o
22obj-$(CONFIG_XEN_DEV_EVTCHN) += xen-evtchn.o 21obj-$(CONFIG_XEN_DEV_EVTCHN) += xen-evtchn.o
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 37d06ea624aa..61a6ac8fa8fc 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -399,11 +399,25 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
399 state = BP_EAGAIN; 399 state = BP_EAGAIN;
400 break; 400 break;
401 } 401 }
402 scrub_page(page);
402 403
403 pfn = page_to_pfn(page); 404 frame_list[i] = page_to_pfn(page);
404 frame_list[i] = pfn_to_mfn(pfn); 405 }
405 406
406 scrub_page(page); 407 /*
408 * Ensure that ballooned highmem pages don't have kmaps.
409 *
410 * Do this before changing the p2m as kmap_flush_unused()
411 * reads PTEs to obtain pages (and hence needs the original
412 * p2m entry).
413 */
414 kmap_flush_unused();
415
416 /* Update direct mapping, invalidate P2M, and add to balloon. */
417 for (i = 0; i < nr_pages; i++) {
418 pfn = frame_list[i];
419 frame_list[i] = pfn_to_mfn(pfn);
420 page = pfn_to_page(pfn);
407 421
408#ifdef CONFIG_XEN_HAVE_PVMMU 422#ifdef CONFIG_XEN_HAVE_PVMMU
409 /* 423 /*
@@ -429,11 +443,9 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
429 } 443 }
430#endif 444#endif
431 445
432 balloon_append(pfn_to_page(pfn)); 446 balloon_append(page);
433 } 447 }
434 448
435 /* Ensure that ballooned highmem pages don't have kmaps. */
436 kmap_flush_unused();
437 flush_tlb_all(); 449 flush_tlb_all();
438 450
439 set_xen_guest_handle(reservation.extent_start, frame_list); 451 set_xen_guest_handle(reservation.extent_start, frame_list);
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 4672e003c0ad..f4a9e3311297 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -862,6 +862,8 @@ int bind_evtchn_to_irq(unsigned int evtchn)
862 irq = ret; 862 irq = ret;
863 goto out; 863 goto out;
864 } 864 }
865 /* New interdomain events are bound to VCPU 0. */
866 bind_evtchn_to_cpu(evtchn, 0);
865 } else { 867 } else {
866 struct irq_info *info = info_for_irq(irq); 868 struct irq_info *info = info_for_irq(irq);
867 WARN_ON(info == NULL || info->type != IRQT_EVTCHN); 869 WARN_ON(info == NULL || info->type != IRQT_EVTCHN);
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 34a2704fbc88..073b4a19a8b0 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -284,10 +284,8 @@ static int map_grant_pages(struct grant_map *map)
284 } 284 }
285 285
286 pr_debug("map %d+%d\n", map->index, map->count); 286 pr_debug("map %d+%d\n", map->index, map->count);
287 err = gnttab_map_refs_userspace(map->map_ops, 287 err = gnttab_map_refs(map->map_ops, use_ptemod ? map->kmap_ops : NULL,
288 use_ptemod ? map->kmap_ops : NULL, 288 map->pages, map->count);
289 map->pages,
290 map->count);
291 if (err) 289 if (err)
292 return err; 290 return err;
293 291
@@ -317,10 +315,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
317 } 315 }
318 } 316 }
319 317
320 err = gnttab_unmap_refs_userspace(map->unmap_ops + offset, 318 err = gnttab_unmap_refs(map->unmap_ops + offset,
321 use_ptemod ? map->kmap_ops + offset : NULL, 319 use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset,
322 map->pages + offset, 320 pages);
323 pages);
324 if (err) 321 if (err)
325 return err; 322 return err;
326 323
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 8ee13e2e45e2..b84e3ab839aa 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -928,17 +928,15 @@ void gnttab_batch_copy(struct gnttab_copy *batch, unsigned count)
928} 928}
929EXPORT_SYMBOL_GPL(gnttab_batch_copy); 929EXPORT_SYMBOL_GPL(gnttab_batch_copy);
930 930
931int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, 931int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
932 struct gnttab_map_grant_ref *kmap_ops, 932 struct gnttab_map_grant_ref *kmap_ops,
933 struct page **pages, unsigned int count, 933 struct page **pages, unsigned int count)
934 bool m2p_override)
935{ 934{
936 int i, ret; 935 int i, ret;
937 bool lazy = false; 936 bool lazy = false;
938 pte_t *pte; 937 pte_t *pte;
939 unsigned long mfn, pfn; 938 unsigned long mfn;
940 939
941 BUG_ON(kmap_ops && !m2p_override);
942 ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count); 940 ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count);
943 if (ret) 941 if (ret)
944 return ret; 942 return ret;
@@ -957,12 +955,10 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
957 set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT, 955 set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT,
958 map_ops[i].dev_bus_addr >> PAGE_SHIFT); 956 map_ops[i].dev_bus_addr >> PAGE_SHIFT);
959 } 957 }
960 return 0; 958 return ret;
961 } 959 }
962 960
963 if (m2p_override && 961 if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
964 !in_interrupt() &&
965 paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
966 arch_enter_lazy_mmu_mode(); 962 arch_enter_lazy_mmu_mode();
967 lazy = true; 963 lazy = true;
968 } 964 }
@@ -979,20 +975,8 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
979 } else { 975 } else {
980 mfn = PFN_DOWN(map_ops[i].dev_bus_addr); 976 mfn = PFN_DOWN(map_ops[i].dev_bus_addr);
981 } 977 }
982 pfn = page_to_pfn(pages[i]); 978 ret = m2p_add_override(mfn, pages[i], kmap_ops ?
983 979 &kmap_ops[i] : NULL);
984 WARN_ON(PagePrivate(pages[i]));
985 SetPagePrivate(pages[i]);
986 set_page_private(pages[i], mfn);
987
988 pages[i]->index = pfn_to_mfn(pfn);
989 if (unlikely(!set_phys_to_machine(pfn, FOREIGN_FRAME(mfn)))) {
990 ret = -ENOMEM;
991 goto out;
992 }
993 if (m2p_override)
994 ret = m2p_add_override(mfn, pages[i], kmap_ops ?
995 &kmap_ops[i] : NULL);
996 if (ret) 980 if (ret)
997 goto out; 981 goto out;
998 } 982 }
@@ -1003,32 +987,15 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
1003 987
1004 return ret; 988 return ret;
1005} 989}
1006
1007int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
1008 struct page **pages, unsigned int count)
1009{
1010 return __gnttab_map_refs(map_ops, NULL, pages, count, false);
1011}
1012EXPORT_SYMBOL_GPL(gnttab_map_refs); 990EXPORT_SYMBOL_GPL(gnttab_map_refs);
1013 991
1014int gnttab_map_refs_userspace(struct gnttab_map_grant_ref *map_ops, 992int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1015 struct gnttab_map_grant_ref *kmap_ops,
1016 struct page **pages, unsigned int count)
1017{
1018 return __gnttab_map_refs(map_ops, kmap_ops, pages, count, true);
1019}
1020EXPORT_SYMBOL_GPL(gnttab_map_refs_userspace);
1021
1022int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1023 struct gnttab_map_grant_ref *kmap_ops, 993 struct gnttab_map_grant_ref *kmap_ops,
1024 struct page **pages, unsigned int count, 994 struct page **pages, unsigned int count)
1025 bool m2p_override)
1026{ 995{
1027 int i, ret; 996 int i, ret;
1028 bool lazy = false; 997 bool lazy = false;
1029 unsigned long pfn, mfn;
1030 998
1031 BUG_ON(kmap_ops && !m2p_override);
1032 ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count); 999 ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count);
1033 if (ret) 1000 if (ret)
1034 return ret; 1001 return ret;
@@ -1039,33 +1006,17 @@ int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1039 set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT, 1006 set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT,
1040 INVALID_P2M_ENTRY); 1007 INVALID_P2M_ENTRY);
1041 } 1008 }
1042 return 0; 1009 return ret;
1043 } 1010 }
1044 1011
1045 if (m2p_override && 1012 if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
1046 !in_interrupt() &&
1047 paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
1048 arch_enter_lazy_mmu_mode(); 1013 arch_enter_lazy_mmu_mode();
1049 lazy = true; 1014 lazy = true;
1050 } 1015 }
1051 1016
1052 for (i = 0; i < count; i++) { 1017 for (i = 0; i < count; i++) {
1053 pfn = page_to_pfn(pages[i]); 1018 ret = m2p_remove_override(pages[i], kmap_ops ?
1054 mfn = get_phys_to_machine(pfn); 1019 &kmap_ops[i] : NULL);
1055 if (mfn == INVALID_P2M_ENTRY || !(mfn & FOREIGN_FRAME_BIT)) {
1056 ret = -EINVAL;
1057 goto out;
1058 }
1059
1060 set_page_private(pages[i], INVALID_P2M_ENTRY);
1061 WARN_ON(!PagePrivate(pages[i]));
1062 ClearPagePrivate(pages[i]);
1063 set_phys_to_machine(pfn, pages[i]->index);
1064 if (m2p_override)
1065 ret = m2p_remove_override(pages[i],
1066 kmap_ops ?
1067 &kmap_ops[i] : NULL,
1068 mfn);
1069 if (ret) 1020 if (ret)
1070 goto out; 1021 goto out;
1071 } 1022 }
@@ -1076,22 +1027,8 @@ int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1076 1027
1077 return ret; 1028 return ret;
1078} 1029}
1079
1080int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *map_ops,
1081 struct page **pages, unsigned int count)
1082{
1083 return __gnttab_unmap_refs(map_ops, NULL, pages, count, false);
1084}
1085EXPORT_SYMBOL_GPL(gnttab_unmap_refs); 1030EXPORT_SYMBOL_GPL(gnttab_unmap_refs);
1086 1031
1087int gnttab_unmap_refs_userspace(struct gnttab_unmap_grant_ref *map_ops,
1088 struct gnttab_map_grant_ref *kmap_ops,
1089 struct page **pages, unsigned int count)
1090{
1091 return __gnttab_unmap_refs(map_ops, kmap_ops, pages, count, true);
1092}
1093EXPORT_SYMBOL_GPL(gnttab_unmap_refs_userspace);
1094
1095static unsigned nr_status_frames(unsigned nr_grant_frames) 1032static unsigned nr_status_frames(unsigned nr_grant_frames)
1096{ 1033{
1097 BUG_ON(grefs_per_grant_frame == 0); 1034 BUG_ON(grefs_per_grant_frame == 0);
diff --git a/drivers/xen/xencomm.c b/drivers/xen/xencomm.c
deleted file mode 100644
index 4793fc594549..000000000000
--- a/drivers/xen/xencomm.c
+++ /dev/null
@@ -1,219 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Copyright (C) IBM Corp. 2006
17 *
18 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
19 */
20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
23#include <linux/mm.h>
24#include <linux/slab.h>
25#include <asm/page.h>
26#include <xen/xencomm.h>
27#include <xen/interface/xen.h>
28#include <asm/xen/xencomm.h> /* for xencomm_is_phys_contiguous() */
29
30static int xencomm_init(struct xencomm_desc *desc,
31 void *buffer, unsigned long bytes)
32{
33 unsigned long recorded = 0;
34 int i = 0;
35
36 while ((recorded < bytes) && (i < desc->nr_addrs)) {
37 unsigned long vaddr = (unsigned long)buffer + recorded;
38 unsigned long paddr;
39 int offset;
40 int chunksz;
41
42 offset = vaddr % PAGE_SIZE; /* handle partial pages */
43 chunksz = min(PAGE_SIZE - offset, bytes - recorded);
44
45 paddr = xencomm_vtop(vaddr);
46 if (paddr == ~0UL) {
47 printk(KERN_DEBUG "%s: couldn't translate vaddr %lx\n",
48 __func__, vaddr);
49 return -EINVAL;
50 }
51
52 desc->address[i++] = paddr;
53 recorded += chunksz;
54 }
55
56 if (recorded < bytes) {
57 printk(KERN_DEBUG
58 "%s: could only translate %ld of %ld bytes\n",
59 __func__, recorded, bytes);
60 return -ENOSPC;
61 }
62
63 /* mark remaining addresses invalid (just for safety) */
64 while (i < desc->nr_addrs)
65 desc->address[i++] = XENCOMM_INVALID;
66
67 desc->magic = XENCOMM_MAGIC;
68
69 return 0;
70}
71
72static struct xencomm_desc *xencomm_alloc(gfp_t gfp_mask,
73 void *buffer, unsigned long bytes)
74{
75 struct xencomm_desc *desc;
76 unsigned long buffer_ulong = (unsigned long)buffer;
77 unsigned long start = buffer_ulong & PAGE_MASK;
78 unsigned long end = (buffer_ulong + bytes) | ~PAGE_MASK;
79 unsigned long nr_addrs = (end - start + 1) >> PAGE_SHIFT;
80 unsigned long size = sizeof(*desc) +
81 sizeof(desc->address[0]) * nr_addrs;
82
83 /*
84 * slab allocator returns at least sizeof(void*) aligned pointer.
85 * When sizeof(*desc) > sizeof(void*), struct xencomm_desc might
86 * cross page boundary.
87 */
88 if (sizeof(*desc) > sizeof(void *)) {
89 unsigned long order = get_order(size);
90 desc = (struct xencomm_desc *)__get_free_pages(gfp_mask,
91 order);
92 if (desc == NULL)
93 return NULL;
94
95 desc->nr_addrs =
96 ((PAGE_SIZE << order) - sizeof(struct xencomm_desc)) /
97 sizeof(*desc->address);
98 } else {
99 desc = kmalloc(size, gfp_mask);
100 if (desc == NULL)
101 return NULL;
102
103 desc->nr_addrs = nr_addrs;
104 }
105 return desc;
106}
107
108void xencomm_free(struct xencomm_handle *desc)
109{
110 if (desc && !((ulong)desc & XENCOMM_INLINE_FLAG)) {
111 struct xencomm_desc *desc__ = (struct xencomm_desc *)desc;
112 if (sizeof(*desc__) > sizeof(void *)) {
113 unsigned long size = sizeof(*desc__) +
114 sizeof(desc__->address[0]) * desc__->nr_addrs;
115 unsigned long order = get_order(size);
116 free_pages((unsigned long)__va(desc), order);
117 } else
118 kfree(__va(desc));
119 }
120}
121
122static int xencomm_create(void *buffer, unsigned long bytes,
123 struct xencomm_desc **ret, gfp_t gfp_mask)
124{
125 struct xencomm_desc *desc;
126 int rc;
127
128 pr_debug("%s: %p[%ld]\n", __func__, buffer, bytes);
129
130 if (bytes == 0) {
131 /* don't create a descriptor; Xen recognizes NULL. */
132 BUG_ON(buffer != NULL);
133 *ret = NULL;
134 return 0;
135 }
136
137 BUG_ON(buffer == NULL); /* 'bytes' is non-zero */
138
139 desc = xencomm_alloc(gfp_mask, buffer, bytes);
140 if (!desc) {
141 printk(KERN_DEBUG "%s failure\n", "xencomm_alloc");
142 return -ENOMEM;
143 }
144
145 rc = xencomm_init(desc, buffer, bytes);
146 if (rc) {
147 printk(KERN_DEBUG "%s failure: %d\n", "xencomm_init", rc);
148 xencomm_free((struct xencomm_handle *)__pa(desc));
149 return rc;
150 }
151
152 *ret = desc;
153 return 0;
154}
155
156static struct xencomm_handle *xencomm_create_inline(void *ptr)
157{
158 unsigned long paddr;
159
160 BUG_ON(!xencomm_is_phys_contiguous((unsigned long)ptr));
161
162 paddr = (unsigned long)xencomm_pa(ptr);
163 BUG_ON(paddr & XENCOMM_INLINE_FLAG);
164 return (struct xencomm_handle *)(paddr | XENCOMM_INLINE_FLAG);
165}
166
167/* "mini" routine, for stack-based communications: */
168static int xencomm_create_mini(void *buffer,
169 unsigned long bytes, struct xencomm_mini *xc_desc,
170 struct xencomm_desc **ret)
171{
172 int rc = 0;
173 struct xencomm_desc *desc;
174 BUG_ON(((unsigned long)xc_desc) % sizeof(*xc_desc) != 0);
175
176 desc = (void *)xc_desc;
177
178 desc->nr_addrs = XENCOMM_MINI_ADDRS;
179
180 rc = xencomm_init(desc, buffer, bytes);
181 if (!rc)
182 *ret = desc;
183
184 return rc;
185}
186
187struct xencomm_handle *xencomm_map(void *ptr, unsigned long bytes)
188{
189 int rc;
190 struct xencomm_desc *desc;
191
192 if (xencomm_is_phys_contiguous((unsigned long)ptr))
193 return xencomm_create_inline(ptr);
194
195 rc = xencomm_create(ptr, bytes, &desc, GFP_KERNEL);
196
197 if (rc || desc == NULL)
198 return NULL;
199
200 return xencomm_pa(desc);
201}
202
203struct xencomm_handle *__xencomm_map_no_alloc(void *ptr, unsigned long bytes,
204 struct xencomm_mini *xc_desc)
205{
206 int rc;
207 struct xencomm_desc *desc = NULL;
208
209 if (xencomm_is_phys_contiguous((unsigned long)ptr))
210 return xencomm_create_inline(ptr);
211
212 rc = xencomm_create_mini(ptr, bytes, xc_desc,
213 &desc);
214
215 if (rc)
216 return NULL;
217
218 return xencomm_pa(desc);
219}
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 6621f8008122..be75b500005d 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -75,6 +75,7 @@ struct afs_call {
75 const struct afs_call_type *type; /* type of call */ 75 const struct afs_call_type *type; /* type of call */
76 const struct afs_wait_mode *wait_mode; /* completion wait mode */ 76 const struct afs_wait_mode *wait_mode; /* completion wait mode */
77 wait_queue_head_t waitq; /* processes awaiting completion */ 77 wait_queue_head_t waitq; /* processes awaiting completion */
78 work_func_t async_workfn;
78 struct work_struct async_work; /* asynchronous work processor */ 79 struct work_struct async_work; /* asynchronous work processor */
79 struct work_struct work; /* actual work processor */ 80 struct work_struct work; /* actual work processor */
80 struct sk_buff_head rx_queue; /* received packets */ 81 struct sk_buff_head rx_queue; /* received packets */
diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c
index 8ad8c2a0703a..ef943df73b8c 100644
--- a/fs/afs/rxrpc.c
+++ b/fs/afs/rxrpc.c
@@ -644,7 +644,7 @@ static void afs_process_async_call(struct work_struct *work)
644 644
645 /* we can't just delete the call because the work item may be 645 /* we can't just delete the call because the work item may be
646 * queued */ 646 * queued */
647 PREPARE_WORK(&call->async_work, afs_delete_async_call); 647 call->async_workfn = afs_delete_async_call;
648 queue_work(afs_async_calls, &call->async_work); 648 queue_work(afs_async_calls, &call->async_work);
649 } 649 }
650 650
@@ -663,6 +663,13 @@ void afs_transfer_reply(struct afs_call *call, struct sk_buff *skb)
663 call->reply_size += len; 663 call->reply_size += len;
664} 664}
665 665
666static void afs_async_workfn(struct work_struct *work)
667{
668 struct afs_call *call = container_of(work, struct afs_call, async_work);
669
670 call->async_workfn(work);
671}
672
666/* 673/*
667 * accept the backlog of incoming calls 674 * accept the backlog of incoming calls
668 */ 675 */
@@ -685,7 +692,8 @@ static void afs_collect_incoming_call(struct work_struct *work)
685 return; 692 return;
686 } 693 }
687 694
688 INIT_WORK(&call->async_work, afs_process_async_call); 695 call->async_workfn = afs_process_async_call;
696 INIT_WORK(&call->async_work, afs_async_workfn);
689 call->wait_mode = &afs_async_incoming_call; 697 call->wait_mode = &afs_async_incoming_call;
690 call->type = &afs_RXCMxxxx; 698 call->type = &afs_RXCMxxxx;
691 init_waitqueue_head(&call->waitq); 699 init_waitqueue_head(&call->waitq);
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 24084732b1d0..80ef38c73e5a 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -41,19 +41,8 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {
41static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type, 41static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
42 int flags, const char *dev_name, void *data) 42 int flags, const char *dev_name, void *data)
43{ 43{
44 struct dentry *root; 44 return mount_pseudo(fs_type, "anon_inode:", NULL,
45 root = mount_pseudo(fs_type, "anon_inode:", NULL,
46 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC); 45 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
47 if (!IS_ERR(root)) {
48 struct super_block *s = root->d_sb;
49 anon_inode_inode = alloc_anon_inode(s);
50 if (IS_ERR(anon_inode_inode)) {
51 dput(root);
52 deactivate_locked_super(s);
53 root = ERR_CAST(anon_inode_inode);
54 }
55 }
56 return root;
57} 46}
58 47
59static struct file_system_type anon_inode_fs_type = { 48static struct file_system_type anon_inode_fs_type = {
@@ -175,22 +164,15 @@ EXPORT_SYMBOL_GPL(anon_inode_getfd);
175 164
176static int __init anon_inode_init(void) 165static int __init anon_inode_init(void)
177{ 166{
178 int error;
179
180 error = register_filesystem(&anon_inode_fs_type);
181 if (error)
182 goto err_exit;
183 anon_inode_mnt = kern_mount(&anon_inode_fs_type); 167 anon_inode_mnt = kern_mount(&anon_inode_fs_type);
184 if (IS_ERR(anon_inode_mnt)) { 168 if (IS_ERR(anon_inode_mnt))
185 error = PTR_ERR(anon_inode_mnt); 169 panic("anon_inode_init() kernel mount failed (%ld)\n", PTR_ERR(anon_inode_mnt));
186 goto err_unregister_filesystem;
187 }
188 return 0;
189 170
190err_unregister_filesystem: 171 anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
191 unregister_filesystem(&anon_inode_fs_type); 172 if (IS_ERR(anon_inode_inode))
192err_exit: 173 panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode));
193 panic(KERN_ERR "anon_inode_init() failed (%d)\n", error); 174
175 return 0;
194} 176}
195 177
196fs_initcall(anon_inode_init); 178fs_initcall(anon_inode_init);
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index 0bad24ddc2e7..4f70f383132c 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -114,6 +114,14 @@ void bio_integrity_free(struct bio *bio)
114} 114}
115EXPORT_SYMBOL(bio_integrity_free); 115EXPORT_SYMBOL(bio_integrity_free);
116 116
117static inline unsigned int bip_integrity_vecs(struct bio_integrity_payload *bip)
118{
119 if (bip->bip_slab == BIO_POOL_NONE)
120 return BIP_INLINE_VECS;
121
122 return bvec_nr_vecs(bip->bip_slab);
123}
124
117/** 125/**
118 * bio_integrity_add_page - Attach integrity metadata 126 * bio_integrity_add_page - Attach integrity metadata
119 * @bio: bio to update 127 * @bio: bio to update
@@ -129,7 +137,7 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
129 struct bio_integrity_payload *bip = bio->bi_integrity; 137 struct bio_integrity_payload *bip = bio->bi_integrity;
130 struct bio_vec *iv; 138 struct bio_vec *iv;
131 139
132 if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) { 140 if (bip->bip_vcnt >= bip_integrity_vecs(bip)) {
133 printk(KERN_ERR "%s: bip_vec full\n", __func__); 141 printk(KERN_ERR "%s: bip_vec full\n", __func__);
134 return 0; 142 return 0;
135 } 143 }
@@ -226,7 +234,8 @@ unsigned int bio_integrity_tag_size(struct bio *bio)
226} 234}
227EXPORT_SYMBOL(bio_integrity_tag_size); 235EXPORT_SYMBOL(bio_integrity_tag_size);
228 236
229int bio_integrity_tag(struct bio *bio, void *tag_buf, unsigned int len, int set) 237static int bio_integrity_tag(struct bio *bio, void *tag_buf, unsigned int len,
238 int set)
230{ 239{
231 struct bio_integrity_payload *bip = bio->bi_integrity; 240 struct bio_integrity_payload *bip = bio->bi_integrity;
232 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev); 241 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
@@ -449,11 +458,10 @@ static int bio_integrity_verify(struct bio *bio)
449 struct blk_integrity_exchg bix; 458 struct blk_integrity_exchg bix;
450 struct bio_vec *bv; 459 struct bio_vec *bv;
451 sector_t sector = bio->bi_integrity->bip_iter.bi_sector; 460 sector_t sector = bio->bi_integrity->bip_iter.bi_sector;
452 unsigned int sectors, total, ret; 461 unsigned int sectors, ret = 0;
453 void *prot_buf = bio->bi_integrity->bip_buf; 462 void *prot_buf = bio->bi_integrity->bip_buf;
454 int i; 463 int i;
455 464
456 ret = total = 0;
457 bix.disk_name = bio->bi_bdev->bd_disk->disk_name; 465 bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
458 bix.sector_size = bi->sector_size; 466 bix.sector_size = bi->sector_size;
459 467
@@ -475,8 +483,6 @@ static int bio_integrity_verify(struct bio *bio)
475 sectors = bv->bv_len / bi->sector_size; 483 sectors = bv->bv_len / bi->sector_size;
476 sector += sectors; 484 sector += sectors;
477 prot_buf += sectors * bi->tuple_size; 485 prot_buf += sectors * bi->tuple_size;
478 total += sectors * bi->tuple_size;
479 BUG_ON(total > bio->bi_integrity->bip_iter.bi_size);
480 486
481 kunmap_atomic(kaddr); 487 kunmap_atomic(kaddr);
482 } 488 }
diff --git a/fs/bio.c b/fs/bio.c
index 75c49a382239..8754e7b6eb49 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -611,7 +611,6 @@ EXPORT_SYMBOL(bio_clone_fast);
611struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, 611struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,
612 struct bio_set *bs) 612 struct bio_set *bs)
613{ 613{
614 unsigned nr_iovecs = 0;
615 struct bvec_iter iter; 614 struct bvec_iter iter;
616 struct bio_vec bv; 615 struct bio_vec bv;
617 struct bio *bio; 616 struct bio *bio;
@@ -638,10 +637,7 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,
638 * __bio_clone_fast() anyways. 637 * __bio_clone_fast() anyways.
639 */ 638 */
640 639
641 bio_for_each_segment(bv, bio_src, iter) 640 bio = bio_alloc_bioset(gfp_mask, bio_segments(bio_src), bs);
642 nr_iovecs++;
643
644 bio = bio_alloc_bioset(gfp_mask, nr_iovecs, bs);
645 if (!bio) 641 if (!bio)
646 return NULL; 642 return NULL;
647 643
@@ -650,9 +646,18 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,
650 bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; 646 bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector;
651 bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; 647 bio->bi_iter.bi_size = bio_src->bi_iter.bi_size;
652 648
649 if (bio->bi_rw & REQ_DISCARD)
650 goto integrity_clone;
651
652 if (bio->bi_rw & REQ_WRITE_SAME) {
653 bio->bi_io_vec[bio->bi_vcnt++] = bio_src->bi_io_vec[0];
654 goto integrity_clone;
655 }
656
653 bio_for_each_segment(bv, bio_src, iter) 657 bio_for_each_segment(bv, bio_src, iter)
654 bio->bi_io_vec[bio->bi_vcnt++] = bv; 658 bio->bi_io_vec[bio->bi_vcnt++] = bv;
655 659
660integrity_clone:
656 if (bio_integrity(bio_src)) { 661 if (bio_integrity(bio_src)) {
657 int ret; 662 int ret;
658 663
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 49a62b4dda3b..0e8388e72d8d 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -92,11 +92,11 @@
92#include <linux/slab.h> 92#include <linux/slab.h>
93#include <linux/buffer_head.h> 93#include <linux/buffer_head.h>
94#include <linux/mutex.h> 94#include <linux/mutex.h>
95#include <linux/crc32c.h>
96#include <linux/genhd.h> 95#include <linux/genhd.h>
97#include <linux/blkdev.h> 96#include <linux/blkdev.h>
98#include "ctree.h" 97#include "ctree.h"
99#include "disk-io.h" 98#include "disk-io.h"
99#include "hash.h"
100#include "transaction.h" 100#include "transaction.h"
101#include "extent_io.h" 101#include "extent_io.h"
102#include "volumes.h" 102#include "volumes.h"
@@ -1823,7 +1823,7 @@ static int btrfsic_test_for_metadata(struct btrfsic_state *state,
1823 size_t sublen = i ? PAGE_CACHE_SIZE : 1823 size_t sublen = i ? PAGE_CACHE_SIZE :
1824 (PAGE_CACHE_SIZE - BTRFS_CSUM_SIZE); 1824 (PAGE_CACHE_SIZE - BTRFS_CSUM_SIZE);
1825 1825
1826 crc = crc32c(crc, data, sublen); 1826 crc = btrfs_crc32c(crc, data, sublen);
1827 } 1827 }
1828 btrfs_csum_final(crc, csum); 1828 btrfs_csum_final(crc, csum);
1829 if (memcmp(csum, h->csum, state->csum_size)) 1829 if (memcmp(csum, h->csum, state->csum_size))
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index e2600cdb6c25..b01fb6c527e3 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -1010,6 +1010,8 @@ int btrfs_decompress_buf2page(char *buf, unsigned long buf_start,
1010 bytes = min(bytes, working_bytes); 1010 bytes = min(bytes, working_bytes);
1011 kaddr = kmap_atomic(page_out); 1011 kaddr = kmap_atomic(page_out);
1012 memcpy(kaddr + *pg_offset, buf + buf_offset, bytes); 1012 memcpy(kaddr + *pg_offset, buf + buf_offset, bytes);
1013 if (*pg_index == (vcnt - 1) && *pg_offset == 0)
1014 memset(kaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1013 kunmap_atomic(kaddr); 1015 kunmap_atomic(kaddr);
1014 flush_dcache_page(page_out); 1016 flush_dcache_page(page_out);
1015 1017
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 0e69295d0031..81ea55314b1f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -26,7 +26,6 @@
26#include <linux/workqueue.h> 26#include <linux/workqueue.h>
27#include <linux/kthread.h> 27#include <linux/kthread.h>
28#include <linux/freezer.h> 28#include <linux/freezer.h>
29#include <linux/crc32c.h>
30#include <linux/slab.h> 29#include <linux/slab.h>
31#include <linux/migrate.h> 30#include <linux/migrate.h>
32#include <linux/ratelimit.h> 31#include <linux/ratelimit.h>
@@ -35,6 +34,7 @@
35#include <asm/unaligned.h> 34#include <asm/unaligned.h>
36#include "ctree.h" 35#include "ctree.h"
37#include "disk-io.h" 36#include "disk-io.h"
37#include "hash.h"
38#include "transaction.h" 38#include "transaction.h"
39#include "btrfs_inode.h" 39#include "btrfs_inode.h"
40#include "volumes.h" 40#include "volumes.h"
@@ -244,7 +244,7 @@ out:
244 244
245u32 btrfs_csum_data(char *data, u32 seed, size_t len) 245u32 btrfs_csum_data(char *data, u32 seed, size_t len)
246{ 246{
247 return crc32c(seed, data, len); 247 return btrfs_crc32c(seed, data, len);
248} 248}
249 249
250void btrfs_csum_final(u32 crc, char *result) 250void btrfs_csum_final(u32 crc, char *result)
@@ -3839,7 +3839,6 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
3839 rb_erase(&ref->rb_node, &head->ref_root); 3839 rb_erase(&ref->rb_node, &head->ref_root);
3840 atomic_dec(&delayed_refs->num_entries); 3840 atomic_dec(&delayed_refs->num_entries);
3841 btrfs_put_delayed_ref(ref); 3841 btrfs_put_delayed_ref(ref);
3842 cond_resched_lock(&head->lock);
3843 } 3842 }
3844 if (head->must_insert_reserved) 3843 if (head->must_insert_reserved)
3845 pin_bytes = true; 3844 pin_bytes = true;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 9c9ecc93ae2c..32312e09f0f5 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2385,6 +2385,7 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
2385 spin_unlock(&delayed_refs->lock); 2385 spin_unlock(&delayed_refs->lock);
2386 locked_ref = NULL; 2386 locked_ref = NULL;
2387 cond_resched(); 2387 cond_resched();
2388 count++;
2388 continue; 2389 continue;
2389 } 2390 }
2390 2391
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 5c4ab9c18940..d3d44486290b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2629,7 +2629,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
2629 EXTENT_DEFRAG, 1, cached_state); 2629 EXTENT_DEFRAG, 1, cached_state);
2630 if (ret) { 2630 if (ret) {
2631 u64 last_snapshot = btrfs_root_last_snapshot(&root->root_item); 2631 u64 last_snapshot = btrfs_root_last_snapshot(&root->root_item);
2632 if (last_snapshot >= BTRFS_I(inode)->generation) 2632 if (0 && last_snapshot >= BTRFS_I(inode)->generation)
2633 /* the inode is shared */ 2633 /* the inode is shared */
2634 new = record_old_file_extents(inode, ordered_extent); 2634 new = record_old_file_extents(inode, ordered_extent);
2635 2635
@@ -5154,7 +5154,7 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
5154 return ERR_CAST(inode); 5154 return ERR_CAST(inode);
5155 } 5155 }
5156 5156
5157 return d_splice_alias(inode, dentry); 5157 return d_materialise_unique(dentry, inode);
5158} 5158}
5159 5159
5160unsigned char btrfs_filetype_table[] = { 5160unsigned char btrfs_filetype_table[] = {
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index b0134892dc70..a6d8efa46bfe 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3537,20 +3537,6 @@ out:
3537 return ret; 3537 return ret;
3538} 3538}
3539 3539
3540static long btrfs_ioctl_global_rsv(struct btrfs_root *root, void __user *arg)
3541{
3542 struct btrfs_block_rsv *block_rsv = &root->fs_info->global_block_rsv;
3543 u64 reserved;
3544
3545 spin_lock(&block_rsv->lock);
3546 reserved = block_rsv->reserved;
3547 spin_unlock(&block_rsv->lock);
3548
3549 if (arg && copy_to_user(arg, &reserved, sizeof(reserved)))
3550 return -EFAULT;
3551 return 0;
3552}
3553
3554/* 3540/*
3555 * there are many ways the trans_start and trans_end ioctls can lead 3541 * there are many ways the trans_start and trans_end ioctls can lead
3556 * to deadlocks. They should only be used by applications that 3542 * to deadlocks. They should only be used by applications that
@@ -4525,7 +4511,7 @@ static int btrfs_ioctl_set_fslabel(struct file *file, void __user *arg)
4525 spin_lock(&root->fs_info->super_lock); 4511 spin_lock(&root->fs_info->super_lock);
4526 strcpy(super_block->label, label); 4512 strcpy(super_block->label, label);
4527 spin_unlock(&root->fs_info->super_lock); 4513 spin_unlock(&root->fs_info->super_lock);
4528 ret = btrfs_end_transaction(trans, root); 4514 ret = btrfs_commit_transaction(trans, root);
4529 4515
4530out_unlock: 4516out_unlock:
4531 mnt_drop_write_file(file); 4517 mnt_drop_write_file(file);
@@ -4668,7 +4654,7 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg)
4668 if (ret) 4654 if (ret)
4669 return ret; 4655 return ret;
4670 4656
4671 trans = btrfs_start_transaction(root, 1); 4657 trans = btrfs_start_transaction(root, 0);
4672 if (IS_ERR(trans)) 4658 if (IS_ERR(trans))
4673 return PTR_ERR(trans); 4659 return PTR_ERR(trans);
4674 4660
@@ -4689,7 +4675,7 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg)
4689 btrfs_set_super_incompat_flags(super_block, newflags); 4675 btrfs_set_super_incompat_flags(super_block, newflags);
4690 spin_unlock(&root->fs_info->super_lock); 4676 spin_unlock(&root->fs_info->super_lock);
4691 4677
4692 return btrfs_end_transaction(trans, root); 4678 return btrfs_commit_transaction(trans, root);
4693} 4679}
4694 4680
4695long btrfs_ioctl(struct file *file, unsigned int 4681long btrfs_ioctl(struct file *file, unsigned int
@@ -4757,8 +4743,6 @@ long btrfs_ioctl(struct file *file, unsigned int
4757 return btrfs_ioctl_logical_to_ino(root, argp); 4743 return btrfs_ioctl_logical_to_ino(root, argp);
4758 case BTRFS_IOC_SPACE_INFO: 4744 case BTRFS_IOC_SPACE_INFO:
4759 return btrfs_ioctl_space_info(root, argp); 4745 return btrfs_ioctl_space_info(root, argp);
4760 case BTRFS_IOC_GLOBAL_RSV:
4761 return btrfs_ioctl_global_rsv(root, argp);
4762 case BTRFS_IOC_SYNC: { 4746 case BTRFS_IOC_SYNC: {
4763 int ret; 4747 int ret;
4764 4748
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 730dce395858..9dde9717c1b9 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -24,12 +24,12 @@
24#include <linux/xattr.h> 24#include <linux/xattr.h>
25#include <linux/posix_acl_xattr.h> 25#include <linux/posix_acl_xattr.h>
26#include <linux/radix-tree.h> 26#include <linux/radix-tree.h>
27#include <linux/crc32c.h>
28#include <linux/vmalloc.h> 27#include <linux/vmalloc.h>
29#include <linux/string.h> 28#include <linux/string.h>
30 29
31#include "send.h" 30#include "send.h"
32#include "backref.h" 31#include "backref.h"
32#include "hash.h"
33#include "locking.h" 33#include "locking.h"
34#include "disk-io.h" 34#include "disk-io.h"
35#include "btrfs_inode.h" 35#include "btrfs_inode.h"
@@ -620,7 +620,7 @@ static int send_cmd(struct send_ctx *sctx)
620 hdr->len = cpu_to_le32(sctx->send_size - sizeof(*hdr)); 620 hdr->len = cpu_to_le32(sctx->send_size - sizeof(*hdr));
621 hdr->crc = 0; 621 hdr->crc = 0;
622 622
623 crc = crc32c(0, (unsigned char *)sctx->send_buf, sctx->send_size); 623 crc = btrfs_crc32c(0, (unsigned char *)sctx->send_buf, sctx->send_size);
624 hdr->crc = cpu_to_le32(crc); 624 hdr->crc = cpu_to_le32(crc);
625 625
626 ret = write_buf(sctx->send_filp, sctx->send_buf, sctx->send_size, 626 ret = write_buf(sctx->send_filp, sctx->send_buf, sctx->send_size,
@@ -1332,6 +1332,16 @@ verbose_printk(KERN_DEBUG "btrfs: find_extent_clone: data_offset=%llu, "
1332 } 1332 }
1333 1333
1334 if (cur_clone_root) { 1334 if (cur_clone_root) {
1335 if (compressed != BTRFS_COMPRESS_NONE) {
1336 /*
1337 * Offsets given by iterate_extent_inodes() are relative
1338 * to the start of the extent, we need to add logical
1339 * offset from the file extent item.
1340 * (See why at backref.c:check_extent_in_eb())
1341 */
1342 cur_clone_root->offset += btrfs_file_extent_offset(eb,
1343 fi);
1344 }
1335 *found = cur_clone_root; 1345 *found = cur_clone_root;
1336 ret = 0; 1346 ret = 0;
1337 } else { 1347 } else {
@@ -2774,8 +2784,6 @@ static int add_waiting_dir_move(struct send_ctx *sctx, u64 ino)
2774 return 0; 2784 return 0;
2775} 2785}
2776 2786
2777#ifdef CONFIG_BTRFS_ASSERT
2778
2779static int del_waiting_dir_move(struct send_ctx *sctx, u64 ino) 2787static int del_waiting_dir_move(struct send_ctx *sctx, u64 ino)
2780{ 2788{
2781 struct rb_node *n = sctx->waiting_dir_moves.rb_node; 2789 struct rb_node *n = sctx->waiting_dir_moves.rb_node;
@@ -2796,8 +2804,6 @@ static int del_waiting_dir_move(struct send_ctx *sctx, u64 ino)
2796 return -ENOENT; 2804 return -ENOENT;
2797} 2805}
2798 2806
2799#endif
2800
2801static int add_pending_dir_move(struct send_ctx *sctx, u64 parent_ino) 2807static int add_pending_dir_move(struct send_ctx *sctx, u64 parent_ino)
2802{ 2808{
2803 struct rb_node **p = &sctx->pending_dir_moves.rb_node; 2809 struct rb_node **p = &sctx->pending_dir_moves.rb_node;
@@ -2902,7 +2908,9 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
2902 } 2908 }
2903 2909
2904 sctx->send_progress = sctx->cur_ino + 1; 2910 sctx->send_progress = sctx->cur_ino + 1;
2905 ASSERT(del_waiting_dir_move(sctx, pm->ino) == 0); 2911 ret = del_waiting_dir_move(sctx, pm->ino);
2912 ASSERT(ret == 0);
2913
2906 ret = get_cur_path(sctx, pm->ino, pm->gen, to_path); 2914 ret = get_cur_path(sctx, pm->ino, pm->gen, to_path);
2907 if (ret < 0) 2915 if (ret < 0)
2908 goto out; 2916 goto out;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index c02f63356895..d04db817be5c 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -566,7 +566,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
566 kfree(num); 566 kfree(num);
567 567
568 if (info->max_inline) { 568 if (info->max_inline) {
569 info->max_inline = max_t(u64, 569 info->max_inline = min_t(u64,
570 info->max_inline, 570 info->max_inline,
571 root->sectorsize); 571 root->sectorsize);
572 } 572 }
@@ -855,6 +855,7 @@ static struct dentry *get_default_root(struct super_block *sb,
855 struct btrfs_path *path; 855 struct btrfs_path *path;
856 struct btrfs_key location; 856 struct btrfs_key location;
857 struct inode *inode; 857 struct inode *inode;
858 struct dentry *dentry;
858 u64 dir_id; 859 u64 dir_id;
859 int new = 0; 860 int new = 0;
860 861
@@ -925,7 +926,13 @@ setup_root:
925 return dget(sb->s_root); 926 return dget(sb->s_root);
926 } 927 }
927 928
928 return d_obtain_alias(inode); 929 dentry = d_obtain_alias(inode);
930 if (!IS_ERR(dentry)) {
931 spin_lock(&dentry->d_lock);
932 dentry->d_flags &= ~DCACHE_DISCONNECTED;
933 spin_unlock(&dentry->d_lock);
934 }
935 return dentry;
929} 936}
930 937
931static int btrfs_fill_super(struct super_block *sb, 938static int btrfs_fill_super(struct super_block *sb,
@@ -1996,7 +2003,7 @@ static void __exit exit_btrfs_fs(void)
1996 btrfs_hash_exit(); 2003 btrfs_hash_exit();
1997} 2004}
1998 2005
1999module_init(init_btrfs_fs) 2006late_initcall(init_btrfs_fs);
2000module_exit(exit_btrfs_fs) 2007module_exit(exit_btrfs_fs)
2001 2008
2002MODULE_LICENSE("GPL"); 2009MODULE_LICENSE("GPL");
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 782374d8fd19..865f4cf9a769 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -578,8 +578,14 @@ static int add_device_membership(struct btrfs_fs_info *fs_info)
578 return -ENOMEM; 578 return -ENOMEM;
579 579
580 list_for_each_entry(dev, &fs_devices->devices, dev_list) { 580 list_for_each_entry(dev, &fs_devices->devices, dev_list) {
581 struct hd_struct *disk = dev->bdev->bd_part; 581 struct hd_struct *disk;
582 struct kobject *disk_kobj = &part_to_dev(disk)->kobj; 582 struct kobject *disk_kobj;
583
584 if (!dev->bdev)
585 continue;
586
587 disk = dev->bdev->bd_part;
588 disk_kobj = &part_to_dev(disk)->kobj;
583 589
584 error = sysfs_create_link(fs_info->device_dir_kobj, 590 error = sysfs_create_link(fs_info->device_dir_kobj,
585 disk_kobj, disk_kobj->name); 591 disk_kobj, disk_kobj->name);
diff --git a/fs/buffer.c b/fs/buffer.c
index 651dba10b9c2..27265a8b43c1 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -654,14 +654,16 @@ EXPORT_SYMBOL(mark_buffer_dirty_inode);
654static void __set_page_dirty(struct page *page, 654static void __set_page_dirty(struct page *page,
655 struct address_space *mapping, int warn) 655 struct address_space *mapping, int warn)
656{ 656{
657 spin_lock_irq(&mapping->tree_lock); 657 unsigned long flags;
658
659 spin_lock_irqsave(&mapping->tree_lock, flags);
658 if (page->mapping) { /* Race with truncate? */ 660 if (page->mapping) { /* Race with truncate? */
659 WARN_ON_ONCE(warn && !PageUptodate(page)); 661 WARN_ON_ONCE(warn && !PageUptodate(page));
660 account_page_dirtied(page, mapping); 662 account_page_dirtied(page, mapping);
661 radix_tree_tag_set(&mapping->page_tree, 663 radix_tree_tag_set(&mapping->page_tree,
662 page_index(page), PAGECACHE_TAG_DIRTY); 664 page_index(page), PAGECACHE_TAG_DIRTY);
663 } 665 }
664 spin_unlock_irq(&mapping->tree_lock); 666 spin_unlock_irqrestore(&mapping->tree_lock, flags);
665 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); 667 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
666} 668}
667 669
diff --git a/fs/ceph/acl.c b/fs/ceph/acl.c
index 4c2d452c4bfc..21887d63dad5 100644
--- a/fs/ceph/acl.c
+++ b/fs/ceph/acl.c
@@ -54,11 +54,6 @@ static inline struct posix_acl *ceph_get_cached_acl(struct inode *inode,
54 return acl; 54 return acl;
55} 55}
56 56
57void ceph_forget_all_cached_acls(struct inode *inode)
58{
59 forget_all_cached_acls(inode);
60}
61
62struct posix_acl *ceph_get_acl(struct inode *inode, int type) 57struct posix_acl *ceph_get_acl(struct inode *inode, int type)
63{ 58{
64 int size; 59 int size;
@@ -160,11 +155,7 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)
160 goto out_dput; 155 goto out_dput;
161 } 156 }
162 157
163 if (value) 158 ret = __ceph_setxattr(dentry, name, value, size, 0);
164 ret = __ceph_setxattr(dentry, name, value, size, 0);
165 else
166 ret = __ceph_removexattr(dentry, name);
167
168 if (ret) { 159 if (ret) {
169 if (new_mode != old_mode) { 160 if (new_mode != old_mode) {
170 newattrs.ia_mode = old_mode; 161 newattrs.ia_mode = old_mode;
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 6da4df84ba30..45eda6d7a40c 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -100,6 +100,14 @@ static unsigned fpos_off(loff_t p)
100 return p & 0xffffffff; 100 return p & 0xffffffff;
101} 101}
102 102
103static int fpos_cmp(loff_t l, loff_t r)
104{
105 int v = ceph_frag_compare(fpos_frag(l), fpos_frag(r));
106 if (v)
107 return v;
108 return (int)(fpos_off(l) - fpos_off(r));
109}
110
103/* 111/*
104 * When possible, we try to satisfy a readdir by peeking at the 112 * When possible, we try to satisfy a readdir by peeking at the
105 * dcache. We make this work by carefully ordering dentries on 113 * dcache. We make this work by carefully ordering dentries on
@@ -156,7 +164,7 @@ more:
156 if (!d_unhashed(dentry) && dentry->d_inode && 164 if (!d_unhashed(dentry) && dentry->d_inode &&
157 ceph_snap(dentry->d_inode) != CEPH_SNAPDIR && 165 ceph_snap(dentry->d_inode) != CEPH_SNAPDIR &&
158 ceph_ino(dentry->d_inode) != CEPH_INO_CEPH && 166 ceph_ino(dentry->d_inode) != CEPH_INO_CEPH &&
159 ctx->pos <= di->offset) 167 fpos_cmp(ctx->pos, di->offset) <= 0)
160 break; 168 break;
161 dout(" skipping %p %.*s at %llu (%llu)%s%s\n", dentry, 169 dout(" skipping %p %.*s at %llu (%llu)%s%s\n", dentry,
162 dentry->d_name.len, dentry->d_name.name, di->offset, 170 dentry->d_name.len, dentry->d_name.name, di->offset,
@@ -695,9 +703,8 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,
695 ceph_mdsc_put_request(req); 703 ceph_mdsc_put_request(req);
696 704
697 if (!err) 705 if (!err)
698 err = ceph_init_acl(dentry, dentry->d_inode, dir); 706 ceph_init_acl(dentry, dentry->d_inode, dir);
699 707 else
700 if (err)
701 d_drop(dentry); 708 d_drop(dentry);
702 return err; 709 return err;
703} 710}
@@ -735,7 +742,9 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry,
735 if (!err && !req->r_reply_info.head->is_dentry) 742 if (!err && !req->r_reply_info.head->is_dentry)
736 err = ceph_handle_notrace_create(dir, dentry); 743 err = ceph_handle_notrace_create(dir, dentry);
737 ceph_mdsc_put_request(req); 744 ceph_mdsc_put_request(req);
738 if (err) 745 if (!err)
746 ceph_init_acl(dentry, dentry->d_inode, dir);
747 else
739 d_drop(dentry); 748 d_drop(dentry);
740 return err; 749 return err;
741} 750}
@@ -776,7 +785,9 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
776 err = ceph_handle_notrace_create(dir, dentry); 785 err = ceph_handle_notrace_create(dir, dentry);
777 ceph_mdsc_put_request(req); 786 ceph_mdsc_put_request(req);
778out: 787out:
779 if (err < 0) 788 if (!err)
789 ceph_init_acl(dentry, dentry->d_inode, dir);
790 else
780 d_drop(dentry); 791 d_drop(dentry);
781 return err; 792 return err;
782} 793}
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index dfd2ce3419f8..09c7afe32e49 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -286,6 +286,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
286 } else { 286 } else {
287 dout("atomic_open finish_open on dn %p\n", dn); 287 dout("atomic_open finish_open on dn %p\n", dn);
288 if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) { 288 if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
289 ceph_init_acl(dentry, dentry->d_inode, dir);
289 *opened |= FILE_CREATED; 290 *opened |= FILE_CREATED;
290 } 291 }
291 err = finish_open(file, dentry, ceph_open, opened); 292 err = finish_open(file, dentry, ceph_open, opened);
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 2df963f1cf5a..10a4ccbf38da 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -144,7 +144,11 @@ enum {
144 Opt_ino32, 144 Opt_ino32,
145 Opt_noino32, 145 Opt_noino32,
146 Opt_fscache, 146 Opt_fscache,
147 Opt_nofscache 147 Opt_nofscache,
148#ifdef CONFIG_CEPH_FS_POSIX_ACL
149 Opt_acl,
150#endif
151 Opt_noacl
148}; 152};
149 153
150static match_table_t fsopt_tokens = { 154static match_table_t fsopt_tokens = {
@@ -172,6 +176,10 @@ static match_table_t fsopt_tokens = {
172 {Opt_noino32, "noino32"}, 176 {Opt_noino32, "noino32"},
173 {Opt_fscache, "fsc"}, 177 {Opt_fscache, "fsc"},
174 {Opt_nofscache, "nofsc"}, 178 {Opt_nofscache, "nofsc"},
179#ifdef CONFIG_CEPH_FS_POSIX_ACL
180 {Opt_acl, "acl"},
181#endif
182 {Opt_noacl, "noacl"},
175 {-1, NULL} 183 {-1, NULL}
176}; 184};
177 185
@@ -271,6 +279,14 @@ static int parse_fsopt_token(char *c, void *private)
271 case Opt_nofscache: 279 case Opt_nofscache:
272 fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE; 280 fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE;
273 break; 281 break;
282#ifdef CONFIG_CEPH_FS_POSIX_ACL
283 case Opt_acl:
284 fsopt->sb_flags |= MS_POSIXACL;
285 break;
286#endif
287 case Opt_noacl:
288 fsopt->sb_flags &= ~MS_POSIXACL;
289 break;
274 default: 290 default:
275 BUG_ON(token); 291 BUG_ON(token);
276 } 292 }
@@ -438,6 +454,13 @@ static int ceph_show_options(struct seq_file *m, struct dentry *root)
438 else 454 else
439 seq_puts(m, ",nofsc"); 455 seq_puts(m, ",nofsc");
440 456
457#ifdef CONFIG_CEPH_FS_POSIX_ACL
458 if (fsopt->sb_flags & MS_POSIXACL)
459 seq_puts(m, ",acl");
460 else
461 seq_puts(m, ",noacl");
462#endif
463
441 if (fsopt->wsize) 464 if (fsopt->wsize)
442 seq_printf(m, ",wsize=%d", fsopt->wsize); 465 seq_printf(m, ",wsize=%d", fsopt->wsize);
443 if (fsopt->rsize != CEPH_RSIZE_DEFAULT) 466 if (fsopt->rsize != CEPH_RSIZE_DEFAULT)
@@ -819,9 +842,6 @@ static int ceph_set_super(struct super_block *s, void *data)
819 842
820 s->s_flags = fsc->mount_options->sb_flags; 843 s->s_flags = fsc->mount_options->sb_flags;
821 s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */ 844 s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */
822#ifdef CONFIG_CEPH_FS_POSIX_ACL
823 s->s_flags |= MS_POSIXACL;
824#endif
825 845
826 s->s_xattr = ceph_xattr_handlers; 846 s->s_xattr = ceph_xattr_handlers;
827 s->s_fs_info = fsc; 847 s->s_fs_info = fsc;
@@ -911,6 +931,10 @@ static struct dentry *ceph_mount(struct file_system_type *fs_type,
911 struct ceph_options *opt = NULL; 931 struct ceph_options *opt = NULL;
912 932
913 dout("ceph_mount\n"); 933 dout("ceph_mount\n");
934
935#ifdef CONFIG_CEPH_FS_POSIX_ACL
936 flags |= MS_POSIXACL;
937#endif
914 err = parse_mount_options(&fsopt, &opt, flags, data, dev_name, &path); 938 err = parse_mount_options(&fsopt, &opt, flags, data, dev_name, &path);
915 if (err < 0) { 939 if (err < 0) {
916 res = ERR_PTR(err); 940 res = ERR_PTR(err);
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 19793b56d0a7..d8801a95b685 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -13,6 +13,7 @@
13#include <linux/wait.h> 13#include <linux/wait.h>
14#include <linux/writeback.h> 14#include <linux/writeback.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/posix_acl.h>
16 17
17#include <linux/ceph/libceph.h> 18#include <linux/ceph/libceph.h>
18 19
@@ -743,7 +744,11 @@ extern const struct xattr_handler *ceph_xattr_handlers[];
743struct posix_acl *ceph_get_acl(struct inode *, int); 744struct posix_acl *ceph_get_acl(struct inode *, int);
744int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type); 745int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type);
745int ceph_init_acl(struct dentry *, struct inode *, struct inode *); 746int ceph_init_acl(struct dentry *, struct inode *, struct inode *);
746void ceph_forget_all_cached_acls(struct inode *inode); 747
748static inline void ceph_forget_all_cached_acls(struct inode *inode)
749{
750 forget_all_cached_acls(inode);
751}
747 752
748#else 753#else
749 754
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 898b6565ad3e..a55ec37378c6 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -12,6 +12,9 @@
12#define XATTR_CEPH_PREFIX "ceph." 12#define XATTR_CEPH_PREFIX "ceph."
13#define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1) 13#define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
14 14
15static int __remove_xattr(struct ceph_inode_info *ci,
16 struct ceph_inode_xattr *xattr);
17
15/* 18/*
16 * List of handlers for synthetic system.* attributes. Other 19 * List of handlers for synthetic system.* attributes. Other
17 * attributes are handled directly. 20 * attributes are handled directly.
@@ -319,8 +322,7 @@ static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
319static int __set_xattr(struct ceph_inode_info *ci, 322static int __set_xattr(struct ceph_inode_info *ci,
320 const char *name, int name_len, 323 const char *name, int name_len,
321 const char *val, int val_len, 324 const char *val, int val_len,
322 int dirty, 325 int flags, int update_xattr,
323 int should_free_name, int should_free_val,
324 struct ceph_inode_xattr **newxattr) 326 struct ceph_inode_xattr **newxattr)
325{ 327{
326 struct rb_node **p; 328 struct rb_node **p;
@@ -349,12 +351,31 @@ static int __set_xattr(struct ceph_inode_info *ci,
349 xattr = NULL; 351 xattr = NULL;
350 } 352 }
351 353
354 if (update_xattr) {
355 int err = 0;
356 if (xattr && (flags & XATTR_CREATE))
357 err = -EEXIST;
358 else if (!xattr && (flags & XATTR_REPLACE))
359 err = -ENODATA;
360 if (err) {
361 kfree(name);
362 kfree(val);
363 return err;
364 }
365 if (update_xattr < 0) {
366 if (xattr)
367 __remove_xattr(ci, xattr);
368 kfree(name);
369 return 0;
370 }
371 }
372
352 if (!xattr) { 373 if (!xattr) {
353 new = 1; 374 new = 1;
354 xattr = *newxattr; 375 xattr = *newxattr;
355 xattr->name = name; 376 xattr->name = name;
356 xattr->name_len = name_len; 377 xattr->name_len = name_len;
357 xattr->should_free_name = should_free_name; 378 xattr->should_free_name = update_xattr;
358 379
359 ci->i_xattrs.count++; 380 ci->i_xattrs.count++;
360 dout("__set_xattr count=%d\n", ci->i_xattrs.count); 381 dout("__set_xattr count=%d\n", ci->i_xattrs.count);
@@ -364,7 +385,7 @@ static int __set_xattr(struct ceph_inode_info *ci,
364 if (xattr->should_free_val) 385 if (xattr->should_free_val)
365 kfree((void *)xattr->val); 386 kfree((void *)xattr->val);
366 387
367 if (should_free_name) { 388 if (update_xattr) {
368 kfree((void *)name); 389 kfree((void *)name);
369 name = xattr->name; 390 name = xattr->name;
370 } 391 }
@@ -379,8 +400,8 @@ static int __set_xattr(struct ceph_inode_info *ci,
379 xattr->val = ""; 400 xattr->val = "";
380 401
381 xattr->val_len = val_len; 402 xattr->val_len = val_len;
382 xattr->dirty = dirty; 403 xattr->dirty = update_xattr;
383 xattr->should_free_val = (val && should_free_val); 404 xattr->should_free_val = (val && update_xattr);
384 405
385 if (new) { 406 if (new) {
386 rb_link_node(&xattr->node, parent, p); 407 rb_link_node(&xattr->node, parent, p);
@@ -442,7 +463,7 @@ static int __remove_xattr(struct ceph_inode_info *ci,
442 struct ceph_inode_xattr *xattr) 463 struct ceph_inode_xattr *xattr)
443{ 464{
444 if (!xattr) 465 if (!xattr)
445 return -EOPNOTSUPP; 466 return -ENODATA;
446 467
447 rb_erase(&xattr->node, &ci->i_xattrs.index); 468 rb_erase(&xattr->node, &ci->i_xattrs.index);
448 469
@@ -588,7 +609,7 @@ start:
588 p += len; 609 p += len;
589 610
590 err = __set_xattr(ci, name, namelen, val, len, 611 err = __set_xattr(ci, name, namelen, val, len,
591 0, 0, 0, &xattrs[numattr]); 612 0, 0, &xattrs[numattr]);
592 613
593 if (err < 0) 614 if (err < 0)
594 goto bad; 615 goto bad;
@@ -850,6 +871,9 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
850 871
851 dout("setxattr value=%.*s\n", (int)size, value); 872 dout("setxattr value=%.*s\n", (int)size, value);
852 873
874 if (!value)
875 flags |= CEPH_XATTR_REMOVE;
876
853 /* do request */ 877 /* do request */
854 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR, 878 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR,
855 USE_AUTH_MDS); 879 USE_AUTH_MDS);
@@ -892,7 +916,7 @@ int __ceph_setxattr(struct dentry *dentry, const char *name,
892 struct ceph_inode_info *ci = ceph_inode(inode); 916 struct ceph_inode_info *ci = ceph_inode(inode);
893 int issued; 917 int issued;
894 int err; 918 int err;
895 int dirty; 919 int dirty = 0;
896 int name_len = strlen(name); 920 int name_len = strlen(name);
897 int val_len = size; 921 int val_len = size;
898 char *newname = NULL; 922 char *newname = NULL;
@@ -953,12 +977,14 @@ retry:
953 goto retry; 977 goto retry;
954 } 978 }
955 979
956 err = __set_xattr(ci, newname, name_len, newval, 980 err = __set_xattr(ci, newname, name_len, newval, val_len,
957 val_len, 1, 1, 1, &xattr); 981 flags, value ? 1 : -1, &xattr);
958 982
959 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL); 983 if (!err) {
960 ci->i_xattrs.dirty = true; 984 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
961 inode->i_ctime = CURRENT_TIME; 985 ci->i_xattrs.dirty = true;
986 inode->i_ctime = CURRENT_TIME;
987 }
962 988
963 spin_unlock(&ci->i_ceph_lock); 989 spin_unlock(&ci->i_ceph_lock);
964 if (dirty) 990 if (dirty)
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index 8f9b4f710d4a..7ff866dbb89e 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -865,8 +865,8 @@ static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
865 return rc; 865 return rc;
866} 866}
867 867
868static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, 868struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
869 __u16 fid, u32 *pacllen) 869 const struct cifs_fid *cifsfid, u32 *pacllen)
870{ 870{
871 struct cifs_ntsd *pntsd = NULL; 871 struct cifs_ntsd *pntsd = NULL;
872 unsigned int xid; 872 unsigned int xid;
@@ -877,7 +877,8 @@ static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
877 return ERR_CAST(tlink); 877 return ERR_CAST(tlink);
878 878
879 xid = get_xid(); 879 xid = get_xid();
880 rc = CIFSSMBGetCIFSACL(xid, tlink_tcon(tlink), fid, &pntsd, pacllen); 880 rc = CIFSSMBGetCIFSACL(xid, tlink_tcon(tlink), cifsfid->netfid, &pntsd,
881 pacllen);
881 free_xid(xid); 882 free_xid(xid);
882 883
883 cifs_put_tlink(tlink); 884 cifs_put_tlink(tlink);
@@ -946,7 +947,7 @@ struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb,
946 if (!open_file) 947 if (!open_file)
947 return get_cifs_acl_by_path(cifs_sb, path, pacllen); 948 return get_cifs_acl_by_path(cifs_sb, path, pacllen);
948 949
949 pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->fid.netfid, pacllen); 950 pntsd = get_cifs_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
950 cifsFileInfo_put(open_file); 951 cifsFileInfo_put(open_file);
951 return pntsd; 952 return pntsd;
952} 953}
@@ -1006,19 +1007,31 @@ out:
1006/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */ 1007/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */
1007int 1008int
1008cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, 1009cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
1009 struct inode *inode, const char *path, const __u16 *pfid) 1010 struct inode *inode, const char *path,
1011 const struct cifs_fid *pfid)
1010{ 1012{
1011 struct cifs_ntsd *pntsd = NULL; 1013 struct cifs_ntsd *pntsd = NULL;
1012 u32 acllen = 0; 1014 u32 acllen = 0;
1013 int rc = 0; 1015 int rc = 0;
1016 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1017 struct cifs_tcon *tcon;
1014 1018
1015 cifs_dbg(NOISY, "converting ACL to mode for %s\n", path); 1019 cifs_dbg(NOISY, "converting ACL to mode for %s\n", path);
1016 1020
1017 if (pfid) 1021 if (IS_ERR(tlink))
1018 pntsd = get_cifs_acl_by_fid(cifs_sb, *pfid, &acllen); 1022 return PTR_ERR(tlink);
1019 else 1023 tcon = tlink_tcon(tlink);
1020 pntsd = get_cifs_acl(cifs_sb, inode, path, &acllen);
1021 1024
1025 if (pfid && (tcon->ses->server->ops->get_acl_by_fid))
1026 pntsd = tcon->ses->server->ops->get_acl_by_fid(cifs_sb, pfid,
1027 &acllen);
1028 else if (tcon->ses->server->ops->get_acl)
1029 pntsd = tcon->ses->server->ops->get_acl(cifs_sb, inode, path,
1030 &acllen);
1031 else {
1032 cifs_put_tlink(tlink);
1033 return -EOPNOTSUPP;
1034 }
1022 /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */ 1035 /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */
1023 if (IS_ERR(pntsd)) { 1036 if (IS_ERR(pntsd)) {
1024 rc = PTR_ERR(pntsd); 1037 rc = PTR_ERR(pntsd);
@@ -1030,6 +1043,8 @@ cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
1030 cifs_dbg(VFS, "parse sec desc failed rc = %d\n", rc); 1043 cifs_dbg(VFS, "parse sec desc failed rc = %d\n", rc);
1031 } 1044 }
1032 1045
1046 cifs_put_tlink(tlink);
1047
1033 return rc; 1048 return rc;
1034} 1049}
1035 1050
@@ -1043,15 +1058,30 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode,
1043 __u32 secdesclen = 0; 1058 __u32 secdesclen = 0;
1044 struct cifs_ntsd *pntsd = NULL; /* acl obtained from server */ 1059 struct cifs_ntsd *pntsd = NULL; /* acl obtained from server */
1045 struct cifs_ntsd *pnntsd = NULL; /* modified acl to be sent to server */ 1060 struct cifs_ntsd *pnntsd = NULL; /* modified acl to be sent to server */
1061 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1062 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1063 struct cifs_tcon *tcon;
1064
1065 if (IS_ERR(tlink))
1066 return PTR_ERR(tlink);
1067 tcon = tlink_tcon(tlink);
1046 1068
1047 cifs_dbg(NOISY, "set ACL from mode for %s\n", path); 1069 cifs_dbg(NOISY, "set ACL from mode for %s\n", path);
1048 1070
1049 /* Get the security descriptor */ 1071 /* Get the security descriptor */
1050 pntsd = get_cifs_acl(CIFS_SB(inode->i_sb), inode, path, &secdesclen); 1072
1073 if (tcon->ses->server->ops->get_acl == NULL) {
1074 cifs_put_tlink(tlink);
1075 return -EOPNOTSUPP;
1076 }
1077
1078 pntsd = tcon->ses->server->ops->get_acl(cifs_sb, inode, path,
1079 &secdesclen);
1051 if (IS_ERR(pntsd)) { 1080 if (IS_ERR(pntsd)) {
1052 rc = PTR_ERR(pntsd); 1081 rc = PTR_ERR(pntsd);
1053 cifs_dbg(VFS, "%s: error %d getting sec desc\n", __func__, rc); 1082 cifs_dbg(VFS, "%s: error %d getting sec desc\n", __func__, rc);
1054 goto out; 1083 cifs_put_tlink(tlink);
1084 return rc;
1055 } 1085 }
1056 1086
1057 /* 1087 /*
@@ -1064,6 +1094,7 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode,
1064 pnntsd = kmalloc(secdesclen, GFP_KERNEL); 1094 pnntsd = kmalloc(secdesclen, GFP_KERNEL);
1065 if (!pnntsd) { 1095 if (!pnntsd) {
1066 kfree(pntsd); 1096 kfree(pntsd);
1097 cifs_put_tlink(tlink);
1067 return -ENOMEM; 1098 return -ENOMEM;
1068 } 1099 }
1069 1100
@@ -1072,14 +1103,18 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode,
1072 1103
1073 cifs_dbg(NOISY, "build_sec_desc rc: %d\n", rc); 1104 cifs_dbg(NOISY, "build_sec_desc rc: %d\n", rc);
1074 1105
1106 if (tcon->ses->server->ops->set_acl == NULL)
1107 rc = -EOPNOTSUPP;
1108
1075 if (!rc) { 1109 if (!rc) {
1076 /* Set the security descriptor */ 1110 /* Set the security descriptor */
1077 rc = set_cifs_acl(pnntsd, secdesclen, inode, path, aclflag); 1111 rc = tcon->ses->server->ops->set_acl(pnntsd, secdesclen, inode,
1112 path, aclflag);
1078 cifs_dbg(NOISY, "set_cifs_acl rc: %d\n", rc); 1113 cifs_dbg(NOISY, "set_cifs_acl rc: %d\n", rc);
1079 } 1114 }
1115 cifs_put_tlink(tlink);
1080 1116
1081 kfree(pnntsd); 1117 kfree(pnntsd);
1082 kfree(pntsd); 1118 kfree(pntsd);
1083out:
1084 return rc; 1119 return rc;
1085} 1120}
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index a245d1809ed8..c0f3718b77a8 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -323,7 +323,8 @@ struct smb_version_operations {
323 /* async read from the server */ 323 /* async read from the server */
324 int (*async_readv)(struct cifs_readdata *); 324 int (*async_readv)(struct cifs_readdata *);
325 /* async write to the server */ 325 /* async write to the server */
326 int (*async_writev)(struct cifs_writedata *); 326 int (*async_writev)(struct cifs_writedata *,
327 void (*release)(struct kref *));
327 /* sync read from the server */ 328 /* sync read from the server */
328 int (*sync_read)(const unsigned int, struct cifsFileInfo *, 329 int (*sync_read)(const unsigned int, struct cifsFileInfo *,
329 struct cifs_io_parms *, unsigned int *, char **, 330 struct cifs_io_parms *, unsigned int *, char **,
@@ -395,6 +396,12 @@ struct smb_version_operations {
395 int (*set_EA)(const unsigned int, struct cifs_tcon *, const char *, 396 int (*set_EA)(const unsigned int, struct cifs_tcon *, const char *,
396 const char *, const void *, const __u16, 397 const char *, const void *, const __u16,
397 const struct nls_table *, int); 398 const struct nls_table *, int);
399 struct cifs_ntsd * (*get_acl)(struct cifs_sb_info *, struct inode *,
400 const char *, u32 *);
401 struct cifs_ntsd * (*get_acl_by_fid)(struct cifs_sb_info *,
402 const struct cifs_fid *, u32 *);
403 int (*set_acl)(struct cifs_ntsd *, __u32, struct inode *, const char *,
404 int);
398}; 405};
399 406
400struct smb_version_values { 407struct smb_version_values {
@@ -506,7 +513,7 @@ struct cifs_mnt_data {
506static inline unsigned int 513static inline unsigned int
507get_rfc1002_length(void *buf) 514get_rfc1002_length(void *buf)
508{ 515{
509 return be32_to_cpu(*((__be32 *)buf)); 516 return be32_to_cpu(*((__be32 *)buf)) & 0xffffff;
510} 517}
511 518
512static inline void 519static inline void
@@ -1064,7 +1071,7 @@ struct cifs_writedata {
1064 unsigned int pagesz; 1071 unsigned int pagesz;
1065 unsigned int tailsz; 1072 unsigned int tailsz;
1066 unsigned int nr_pages; 1073 unsigned int nr_pages;
1067 struct page *pages[1]; 1074 struct page *pages[];
1068}; 1075};
1069 1076
1070/* 1077/*
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 79e6e9a93a8c..acc4ee8ed075 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -151,7 +151,7 @@ extern struct inode *cifs_iget(struct super_block *sb,
151 151
152extern int cifs_get_inode_info(struct inode **inode, const char *full_path, 152extern int cifs_get_inode_info(struct inode **inode, const char *full_path,
153 FILE_ALL_INFO *data, struct super_block *sb, 153 FILE_ALL_INFO *data, struct super_block *sb,
154 int xid, const __u16 *fid); 154 int xid, const struct cifs_fid *fid);
155extern int cifs_get_inode_info_unix(struct inode **pinode, 155extern int cifs_get_inode_info_unix(struct inode **pinode,
156 const unsigned char *search_path, 156 const unsigned char *search_path,
157 struct super_block *sb, unsigned int xid); 157 struct super_block *sb, unsigned int xid);
@@ -162,11 +162,13 @@ extern int cifs_rename_pending_delete(const char *full_path,
162 const unsigned int xid); 162 const unsigned int xid);
163extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, 163extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb,
164 struct cifs_fattr *fattr, struct inode *inode, 164 struct cifs_fattr *fattr, struct inode *inode,
165 const char *path, const __u16 *pfid); 165 const char *path, const struct cifs_fid *pfid);
166extern int id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64, 166extern int id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64,
167 kuid_t, kgid_t); 167 kuid_t, kgid_t);
168extern struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *, struct inode *, 168extern struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *, struct inode *,
169 const char *, u32 *); 169 const char *, u32 *);
170extern struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *,
171 const struct cifs_fid *, u32 *);
170extern int set_cifs_acl(struct cifs_ntsd *, __u32, struct inode *, 172extern int set_cifs_acl(struct cifs_ntsd *, __u32, struct inode *,
171 const char *, int); 173 const char *, int);
172 174
@@ -488,7 +490,8 @@ void cifs_readdata_release(struct kref *refcount);
488int cifs_async_readv(struct cifs_readdata *rdata); 490int cifs_async_readv(struct cifs_readdata *rdata);
489int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid); 491int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid);
490 492
491int cifs_async_writev(struct cifs_writedata *wdata); 493int cifs_async_writev(struct cifs_writedata *wdata,
494 void (*release)(struct kref *kref));
492void cifs_writev_complete(struct work_struct *work); 495void cifs_writev_complete(struct work_struct *work);
493struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages, 496struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages,
494 work_func_t complete); 497 work_func_t complete);
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 4d881c35eeca..f3264bd7a83d 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -1910,7 +1910,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
1910 1910
1911 do { 1911 do {
1912 server = tlink_tcon(wdata->cfile->tlink)->ses->server; 1912 server = tlink_tcon(wdata->cfile->tlink)->ses->server;
1913 rc = server->ops->async_writev(wdata); 1913 rc = server->ops->async_writev(wdata, cifs_writedata_release);
1914 } while (rc == -EAGAIN); 1914 } while (rc == -EAGAIN);
1915 1915
1916 for (i = 0; i < wdata->nr_pages; i++) { 1916 for (i = 0; i < wdata->nr_pages; i++) {
@@ -1962,15 +1962,9 @@ cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
1962{ 1962{
1963 struct cifs_writedata *wdata; 1963 struct cifs_writedata *wdata;
1964 1964
1965 /* this would overflow */
1966 if (nr_pages == 0) {
1967 cifs_dbg(VFS, "%s: called with nr_pages == 0!\n", __func__);
1968 return NULL;
1969 }
1970
1971 /* writedata + number of page pointers */ 1965 /* writedata + number of page pointers */
1972 wdata = kzalloc(sizeof(*wdata) + 1966 wdata = kzalloc(sizeof(*wdata) +
1973 sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); 1967 sizeof(struct page *) * nr_pages, GFP_NOFS);
1974 if (wdata != NULL) { 1968 if (wdata != NULL) {
1975 kref_init(&wdata->refcount); 1969 kref_init(&wdata->refcount);
1976 INIT_LIST_HEAD(&wdata->list); 1970 INIT_LIST_HEAD(&wdata->list);
@@ -2031,7 +2025,8 @@ cifs_writev_callback(struct mid_q_entry *mid)
2031 2025
2032/* cifs_async_writev - send an async write, and set up mid to handle result */ 2026/* cifs_async_writev - send an async write, and set up mid to handle result */
2033int 2027int
2034cifs_async_writev(struct cifs_writedata *wdata) 2028cifs_async_writev(struct cifs_writedata *wdata,
2029 void (*release)(struct kref *kref))
2035{ 2030{
2036 int rc = -EACCES; 2031 int rc = -EACCES;
2037 WRITE_REQ *smb = NULL; 2032 WRITE_REQ *smb = NULL;
@@ -2105,7 +2100,7 @@ cifs_async_writev(struct cifs_writedata *wdata)
2105 if (rc == 0) 2100 if (rc == 0)
2106 cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); 2101 cifs_stats_inc(&tcon->stats.cifs_stats.num_writes);
2107 else 2102 else
2108 kref_put(&wdata->refcount, cifs_writedata_release); 2103 kref_put(&wdata->refcount, release);
2109 2104
2110async_writev_out: 2105async_writev_out:
2111 cifs_small_buf_release(smb); 2106 cifs_small_buf_release(smb);
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index d3a6796caa5a..3db0c5fd9a11 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -378,7 +378,7 @@ cifs_create_get_file_info:
378 xid); 378 xid);
379 else { 379 else {
380 rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb, 380 rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb,
381 xid, &fid->netfid); 381 xid, fid);
382 if (newinode) { 382 if (newinode) {
383 if (server->ops->set_lease_key) 383 if (server->ops->set_lease_key)
384 server->ops->set_lease_key(newinode, fid); 384 server->ops->set_lease_key(newinode, fid);
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 853d6d1cc822..834fce759d80 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -244,7 +244,7 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
244 xid); 244 xid);
245 else 245 else
246 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, 246 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
247 xid, &fid->netfid); 247 xid, fid);
248 248
249out: 249out:
250 kfree(buf); 250 kfree(buf);
@@ -2043,7 +2043,8 @@ retry:
2043 } 2043 }
2044 wdata->pid = wdata->cfile->pid; 2044 wdata->pid = wdata->cfile->pid;
2045 server = tlink_tcon(wdata->cfile->tlink)->ses->server; 2045 server = tlink_tcon(wdata->cfile->tlink)->ses->server;
2046 rc = server->ops->async_writev(wdata); 2046 rc = server->ops->async_writev(wdata,
2047 cifs_writedata_release);
2047 } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN); 2048 } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN);
2048 2049
2049 for (i = 0; i < nr_pages; ++i) 2050 for (i = 0; i < nr_pages; ++i)
@@ -2331,9 +2332,20 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
2331} 2332}
2332 2333
2333static void 2334static void
2334cifs_uncached_writev_complete(struct work_struct *work) 2335cifs_uncached_writedata_release(struct kref *refcount)
2335{ 2336{
2336 int i; 2337 int i;
2338 struct cifs_writedata *wdata = container_of(refcount,
2339 struct cifs_writedata, refcount);
2340
2341 for (i = 0; i < wdata->nr_pages; i++)
2342 put_page(wdata->pages[i]);
2343 cifs_writedata_release(refcount);
2344}
2345
2346static void
2347cifs_uncached_writev_complete(struct work_struct *work)
2348{
2337 struct cifs_writedata *wdata = container_of(work, 2349 struct cifs_writedata *wdata = container_of(work,
2338 struct cifs_writedata, work); 2350 struct cifs_writedata, work);
2339 struct inode *inode = wdata->cfile->dentry->d_inode; 2351 struct inode *inode = wdata->cfile->dentry->d_inode;
@@ -2347,12 +2359,7 @@ cifs_uncached_writev_complete(struct work_struct *work)
2347 2359
2348 complete(&wdata->done); 2360 complete(&wdata->done);
2349 2361
2350 if (wdata->result != -EAGAIN) { 2362 kref_put(&wdata->refcount, cifs_uncached_writedata_release);
2351 for (i = 0; i < wdata->nr_pages; i++)
2352 put_page(wdata->pages[i]);
2353 }
2354
2355 kref_put(&wdata->refcount, cifs_writedata_release);
2356} 2363}
2357 2364
2358/* attempt to send write to server, retry on any -EAGAIN errors */ 2365/* attempt to send write to server, retry on any -EAGAIN errors */
@@ -2370,7 +2377,8 @@ cifs_uncached_retry_writev(struct cifs_writedata *wdata)
2370 if (rc != 0) 2377 if (rc != 0)
2371 continue; 2378 continue;
2372 } 2379 }
2373 rc = server->ops->async_writev(wdata); 2380 rc = server->ops->async_writev(wdata,
2381 cifs_uncached_writedata_release);
2374 } while (rc == -EAGAIN); 2382 } while (rc == -EAGAIN);
2375 2383
2376 return rc; 2384 return rc;
@@ -2381,7 +2389,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
2381 unsigned long nr_segs, loff_t *poffset) 2389 unsigned long nr_segs, loff_t *poffset)
2382{ 2390{
2383 unsigned long nr_pages, i; 2391 unsigned long nr_pages, i;
2384 size_t copied, len, cur_len; 2392 size_t bytes, copied, len, cur_len;
2385 ssize_t total_written = 0; 2393 ssize_t total_written = 0;
2386 loff_t offset; 2394 loff_t offset;
2387 struct iov_iter it; 2395 struct iov_iter it;
@@ -2436,14 +2444,45 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
2436 2444
2437 save_len = cur_len; 2445 save_len = cur_len;
2438 for (i = 0; i < nr_pages; i++) { 2446 for (i = 0; i < nr_pages; i++) {
2439 copied = min_t(const size_t, cur_len, PAGE_SIZE); 2447 bytes = min_t(const size_t, cur_len, PAGE_SIZE);
2440 copied = iov_iter_copy_from_user(wdata->pages[i], &it, 2448 copied = iov_iter_copy_from_user(wdata->pages[i], &it,
2441 0, copied); 2449 0, bytes);
2442 cur_len -= copied; 2450 cur_len -= copied;
2443 iov_iter_advance(&it, copied); 2451 iov_iter_advance(&it, copied);
2452 /*
2453 * If we didn't copy as much as we expected, then that
2454 * may mean we trod into an unmapped area. Stop copying
2455 * at that point. On the next pass through the big
2456 * loop, we'll likely end up getting a zero-length
2457 * write and bailing out of it.
2458 */
2459 if (copied < bytes)
2460 break;
2444 } 2461 }
2445 cur_len = save_len - cur_len; 2462 cur_len = save_len - cur_len;
2446 2463
2464 /*
2465 * If we have no data to send, then that probably means that
2466 * the copy above failed altogether. That's most likely because
2467 * the address in the iovec was bogus. Set the rc to -EFAULT,
2468 * free anything we allocated and bail out.
2469 */
2470 if (!cur_len) {
2471 for (i = 0; i < nr_pages; i++)
2472 put_page(wdata->pages[i]);
2473 kfree(wdata);
2474 rc = -EFAULT;
2475 break;
2476 }
2477
2478 /*
2479 * i + 1 now represents the number of pages we actually used in
2480 * the copy phase above. Bring nr_pages down to that, and free
2481 * any pages that we didn't use.
2482 */
2483 for ( ; nr_pages > i + 1; nr_pages--)
2484 put_page(wdata->pages[nr_pages - 1]);
2485
2447 wdata->sync_mode = WB_SYNC_ALL; 2486 wdata->sync_mode = WB_SYNC_ALL;
2448 wdata->nr_pages = nr_pages; 2487 wdata->nr_pages = nr_pages;
2449 wdata->offset = (__u64)offset; 2488 wdata->offset = (__u64)offset;
@@ -2454,7 +2493,8 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
2454 wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE); 2493 wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE);
2455 rc = cifs_uncached_retry_writev(wdata); 2494 rc = cifs_uncached_retry_writev(wdata);
2456 if (rc) { 2495 if (rc) {
2457 kref_put(&wdata->refcount, cifs_writedata_release); 2496 kref_put(&wdata->refcount,
2497 cifs_uncached_writedata_release);
2458 break; 2498 break;
2459 } 2499 }
2460 2500
@@ -2496,7 +2536,7 @@ restart_loop:
2496 } 2536 }
2497 } 2537 }
2498 list_del_init(&wdata->list); 2538 list_del_init(&wdata->list);
2499 kref_put(&wdata->refcount, cifs_writedata_release); 2539 kref_put(&wdata->refcount, cifs_uncached_writedata_release);
2500 } 2540 }
2501 2541
2502 if (total_written > 0) 2542 if (total_written > 0)
@@ -2539,31 +2579,19 @@ cifs_writev(struct kiocb *iocb, const struct iovec *iov,
2539 struct cifsInodeInfo *cinode = CIFS_I(inode); 2579 struct cifsInodeInfo *cinode = CIFS_I(inode);
2540 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; 2580 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
2541 ssize_t rc = -EACCES; 2581 ssize_t rc = -EACCES;
2582 loff_t lock_pos = pos;
2542 2583
2543 BUG_ON(iocb->ki_pos != pos); 2584 if (file->f_flags & O_APPEND)
2544 2585 lock_pos = i_size_read(inode);
2545 /* 2586 /*
2546 * We need to hold the sem to be sure nobody modifies lock list 2587 * We need to hold the sem to be sure nobody modifies lock list
2547 * with a brlock that prevents writing. 2588 * with a brlock that prevents writing.
2548 */ 2589 */
2549 down_read(&cinode->lock_sem); 2590 down_read(&cinode->lock_sem);
2550 if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs), 2591 if (!cifs_find_lock_conflict(cfile, lock_pos, iov_length(iov, nr_segs),
2551 server->vals->exclusive_lock_type, NULL, 2592 server->vals->exclusive_lock_type, NULL,
2552 CIFS_WRITE_OP)) { 2593 CIFS_WRITE_OP))
2553 mutex_lock(&inode->i_mutex); 2594 rc = generic_file_aio_write(iocb, iov, nr_segs, pos);
2554 rc = __generic_file_aio_write(iocb, iov, nr_segs,
2555 &iocb->ki_pos);
2556 mutex_unlock(&inode->i_mutex);
2557 }
2558
2559 if (rc > 0) {
2560 ssize_t err;
2561
2562 err = generic_write_sync(file, pos, rc);
2563 if (err < 0 && rc > 0)
2564 rc = err;
2565 }
2566
2567 up_read(&cinode->lock_sem); 2595 up_read(&cinode->lock_sem);
2568 return rc; 2596 return rc;
2569} 2597}
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 9cb9679d7357..aadc2b68678b 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -527,10 +527,15 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path,
527 return PTR_ERR(tlink); 527 return PTR_ERR(tlink);
528 tcon = tlink_tcon(tlink); 528 tcon = tlink_tcon(tlink);
529 529
530 rc = CIFSSMBQAllEAs(xid, tcon, path, "SETFILEBITS", 530 if (tcon->ses->server->ops->query_all_EAs == NULL) {
531 ea_value, 4 /* size of buf */, cifs_sb->local_nls, 531 cifs_put_tlink(tlink);
532 cifs_sb->mnt_cifs_flags & 532 return -EOPNOTSUPP;
533 CIFS_MOUNT_MAP_SPECIAL_CHR); 533 }
534
535 rc = tcon->ses->server->ops->query_all_EAs(xid, tcon, path,
536 "SETFILEBITS", ea_value, 4 /* size of buf */,
537 cifs_sb->local_nls,
538 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
534 cifs_put_tlink(tlink); 539 cifs_put_tlink(tlink);
535 if (rc < 0) 540 if (rc < 0)
536 return (int)rc; 541 return (int)rc;
@@ -672,7 +677,7 @@ cgfi_exit:
672int 677int
673cifs_get_inode_info(struct inode **inode, const char *full_path, 678cifs_get_inode_info(struct inode **inode, const char *full_path,
674 FILE_ALL_INFO *data, struct super_block *sb, int xid, 679 FILE_ALL_INFO *data, struct super_block *sb, int xid,
675 const __u16 *fid) 680 const struct cifs_fid *fid)
676{ 681{
677 bool validinum = false; 682 bool validinum = false;
678 __u16 srchflgs; 683 __u16 srchflgs;
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
index 9ac5bfc9cc56..526fb89f9230 100644
--- a/fs/cifs/smb1ops.c
+++ b/fs/cifs/smb1ops.c
@@ -1067,6 +1067,15 @@ struct smb_version_operations smb1_operations = {
1067 .query_mf_symlink = cifs_query_mf_symlink, 1067 .query_mf_symlink = cifs_query_mf_symlink,
1068 .create_mf_symlink = cifs_create_mf_symlink, 1068 .create_mf_symlink = cifs_create_mf_symlink,
1069 .is_read_op = cifs_is_read_op, 1069 .is_read_op = cifs_is_read_op,
1070#ifdef CONFIG_CIFS_XATTR
1071 .query_all_EAs = CIFSSMBQAllEAs,
1072 .set_EA = CIFSSMBSetEA,
1073#endif /* CIFS_XATTR */
1074#ifdef CONFIG_CIFS_ACL
1075 .get_acl = get_cifs_acl,
1076 .get_acl_by_fid = get_cifs_acl_by_fid,
1077 .set_acl = set_cifs_acl,
1078#endif /* CIFS_ACL */
1070}; 1079};
1071 1080
1072struct smb_version_values smb1_values = { 1081struct smb_version_values smb1_values = {
diff --git a/fs/cifs/smb2glob.h b/fs/cifs/smb2glob.h
index c38350851b08..bc0bb9c34f72 100644
--- a/fs/cifs/smb2glob.h
+++ b/fs/cifs/smb2glob.h
@@ -57,4 +57,7 @@
57#define SMB2_CMACAES_SIZE (16) 57#define SMB2_CMACAES_SIZE (16)
58#define SMB3_SIGNKEY_SIZE (16) 58#define SMB3_SIGNKEY_SIZE (16)
59 59
60/* Maximum buffer size value we can send with 1 credit */
61#define SMB2_MAX_BUFFER_SIZE 65536
62
60#endif /* _SMB2_GLOB_H */ 63#endif /* _SMB2_GLOB_H */
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 757da3e54d3d..192f51a12cf1 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -182,11 +182,8 @@ smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
182 /* start with specified wsize, or default */ 182 /* start with specified wsize, or default */
183 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; 183 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
184 wsize = min_t(unsigned int, wsize, server->max_write); 184 wsize = min_t(unsigned int, wsize, server->max_write);
185 /* 185 /* set it to the maximum buffer size value we can send with 1 credit */
186 * limit write size to 2 ** 16, because we don't support multicredit 186 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
187 * requests now.
188 */
189 wsize = min_t(unsigned int, wsize, 2 << 15);
190 187
191 return wsize; 188 return wsize;
192} 189}
@@ -200,11 +197,8 @@ smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
200 /* start with specified rsize, or default */ 197 /* start with specified rsize, or default */
201 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; 198 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
202 rsize = min_t(unsigned int, rsize, server->max_read); 199 rsize = min_t(unsigned int, rsize, server->max_read);
203 /* 200 /* set it to the maximum buffer size value we can send with 1 credit */
204 * limit write size to 2 ** 16, because we don't support multicredit 201 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
205 * requests now.
206 */
207 rsize = min_t(unsigned int, rsize, 2 << 15);
208 202
209 return rsize; 203 return rsize;
210} 204}
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 2013234b73ad..860344701067 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -413,7 +413,9 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
413 413
414 /* SMB2 only has an extended negflavor */ 414 /* SMB2 only has an extended negflavor */
415 server->negflavor = CIFS_NEGFLAVOR_EXTENDED; 415 server->negflavor = CIFS_NEGFLAVOR_EXTENDED;
416 server->maxBuf = le32_to_cpu(rsp->MaxTransactSize); 416 /* set it to the maximum buffer size value we can send with 1 credit */
417 server->maxBuf = min_t(unsigned int, le32_to_cpu(rsp->MaxTransactSize),
418 SMB2_MAX_BUFFER_SIZE);
417 server->max_read = le32_to_cpu(rsp->MaxReadSize); 419 server->max_read = le32_to_cpu(rsp->MaxReadSize);
418 server->max_write = le32_to_cpu(rsp->MaxWriteSize); 420 server->max_write = le32_to_cpu(rsp->MaxWriteSize);
419 /* BB Do we need to validate the SecurityMode? */ 421 /* BB Do we need to validate the SecurityMode? */
@@ -1890,7 +1892,8 @@ smb2_writev_callback(struct mid_q_entry *mid)
1890 1892
1891/* smb2_async_writev - send an async write, and set up mid to handle result */ 1893/* smb2_async_writev - send an async write, and set up mid to handle result */
1892int 1894int
1893smb2_async_writev(struct cifs_writedata *wdata) 1895smb2_async_writev(struct cifs_writedata *wdata,
1896 void (*release)(struct kref *kref))
1894{ 1897{
1895 int rc = -EACCES; 1898 int rc = -EACCES;
1896 struct smb2_write_req *req = NULL; 1899 struct smb2_write_req *req = NULL;
@@ -1938,7 +1941,7 @@ smb2_async_writev(struct cifs_writedata *wdata)
1938 smb2_writev_callback, wdata, 0); 1941 smb2_writev_callback, wdata, 0);
1939 1942
1940 if (rc) { 1943 if (rc) {
1941 kref_put(&wdata->refcount, cifs_writedata_release); 1944 kref_put(&wdata->refcount, release);
1942 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); 1945 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
1943 } 1946 }
1944 1947
diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h
index 93adc64666f3..0ce48db20a65 100644
--- a/fs/cifs/smb2proto.h
+++ b/fs/cifs/smb2proto.h
@@ -123,7 +123,8 @@ extern int SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon,
123extern int smb2_async_readv(struct cifs_readdata *rdata); 123extern int smb2_async_readv(struct cifs_readdata *rdata);
124extern int SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, 124extern int SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
125 unsigned int *nbytes, char **buf, int *buf_type); 125 unsigned int *nbytes, char **buf, int *buf_type);
126extern int smb2_async_writev(struct cifs_writedata *wdata); 126extern int smb2_async_writev(struct cifs_writedata *wdata,
127 void (*release)(struct kref *kref));
127extern int SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms, 128extern int SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
128 unsigned int *nbytes, struct kvec *iov, int n_vec); 129 unsigned int *nbytes, struct kvec *iov, int n_vec);
129extern int SMB2_echo(struct TCP_Server_Info *server); 130extern int SMB2_echo(struct TCP_Server_Info *server);
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index b37570952846..18cd5650a5fc 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -270,6 +270,26 @@ cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx,
270 iov->iov_len = rqst->rq_pagesz; 270 iov->iov_len = rqst->rq_pagesz;
271} 271}
272 272
273static unsigned long
274rqst_len(struct smb_rqst *rqst)
275{
276 unsigned int i;
277 struct kvec *iov = rqst->rq_iov;
278 unsigned long buflen = 0;
279
280 /* total up iov array first */
281 for (i = 0; i < rqst->rq_nvec; i++)
282 buflen += iov[i].iov_len;
283
284 /* add in the page array if there is one */
285 if (rqst->rq_npages) {
286 buflen += rqst->rq_pagesz * (rqst->rq_npages - 1);
287 buflen += rqst->rq_tailsz;
288 }
289
290 return buflen;
291}
292
273static int 293static int
274smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) 294smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
275{ 295{
@@ -277,6 +297,7 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
277 struct kvec *iov = rqst->rq_iov; 297 struct kvec *iov = rqst->rq_iov;
278 int n_vec = rqst->rq_nvec; 298 int n_vec = rqst->rq_nvec;
279 unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base); 299 unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base);
300 unsigned long send_length;
280 unsigned int i; 301 unsigned int i;
281 size_t total_len = 0, sent; 302 size_t total_len = 0, sent;
282 struct socket *ssocket = server->ssocket; 303 struct socket *ssocket = server->ssocket;
@@ -285,6 +306,14 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
285 if (ssocket == NULL) 306 if (ssocket == NULL)
286 return -ENOTSOCK; 307 return -ENOTSOCK;
287 308
309 /* sanity check send length */
310 send_length = rqst_len(rqst);
311 if (send_length != smb_buf_length + 4) {
312 WARN(1, "Send length mismatch(send_length=%lu smb_buf_length=%u)\n",
313 send_length, smb_buf_length);
314 return -EIO;
315 }
316
288 cifs_dbg(FYI, "Sending smb: smb_len=%u\n", smb_buf_length); 317 cifs_dbg(FYI, "Sending smb: smb_len=%u\n", smb_buf_length);
289 dump_smb(iov[0].iov_base, iov[0].iov_len); 318 dump_smb(iov[0].iov_base, iov[0].iov_len);
290 319
diff --git a/fs/cifs/xattr.c b/fs/cifs/xattr.c
index 95c43bb20335..5ac836a86b18 100644
--- a/fs/cifs/xattr.c
+++ b/fs/cifs/xattr.c
@@ -176,8 +176,12 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
176 rc = -ENOMEM; 176 rc = -ENOMEM;
177 } else { 177 } else {
178 memcpy(pacl, ea_value, value_size); 178 memcpy(pacl, ea_value, value_size);
179 rc = set_cifs_acl(pacl, value_size, 179 if (pTcon->ses->server->ops->set_acl)
180 direntry->d_inode, full_path, CIFS_ACL_DACL); 180 rc = pTcon->ses->server->ops->set_acl(pacl,
181 value_size, direntry->d_inode,
182 full_path, CIFS_ACL_DACL);
183 else
184 rc = -EOPNOTSUPP;
181 if (rc == 0) /* force revalidate of the inode */ 185 if (rc == 0) /* force revalidate of the inode */
182 CIFS_I(direntry->d_inode)->time = 0; 186 CIFS_I(direntry->d_inode)->time = 0;
183 kfree(pacl); 187 kfree(pacl);
@@ -323,8 +327,11 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
323 u32 acllen; 327 u32 acllen;
324 struct cifs_ntsd *pacl; 328 struct cifs_ntsd *pacl;
325 329
326 pacl = get_cifs_acl(cifs_sb, direntry->d_inode, 330 if (pTcon->ses->server->ops->get_acl == NULL)
327 full_path, &acllen); 331 goto get_ea_exit; /* rc already EOPNOTSUPP */
332
333 pacl = pTcon->ses->server->ops->get_acl(cifs_sb,
334 direntry->d_inode, full_path, &acllen);
328 if (IS_ERR(pacl)) { 335 if (IS_ERR(pacl)) {
329 rc = PTR_ERR(pacl); 336 rc = PTR_ERR(pacl);
330 cifs_dbg(VFS, "%s: error %zd getting sec desc\n", 337 cifs_dbg(VFS, "%s: error %zd getting sec desc\n",
diff --git a/fs/compat.c b/fs/compat.c
index 6af20de2c1a3..19252b97f0cc 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -72,8 +72,8 @@ int compat_printk(const char *fmt, ...)
72 * Not all architectures have sys_utime, so implement this in terms 72 * Not all architectures have sys_utime, so implement this in terms
73 * of sys_utimes. 73 * of sys_utimes.
74 */ 74 */
75asmlinkage long compat_sys_utime(const char __user *filename, 75COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename,
76 struct compat_utimbuf __user *t) 76 struct compat_utimbuf __user *, t)
77{ 77{
78 struct timespec tv[2]; 78 struct timespec tv[2];
79 79
@@ -87,7 +87,7 @@ asmlinkage long compat_sys_utime(const char __user *filename,
87 return do_utimes(AT_FDCWD, filename, t ? tv : NULL, 0); 87 return do_utimes(AT_FDCWD, filename, t ? tv : NULL, 0);
88} 88}
89 89
90asmlinkage long compat_sys_utimensat(unsigned int dfd, const char __user *filename, struct compat_timespec __user *t, int flags) 90COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct compat_timespec __user *, t, int, flags)
91{ 91{
92 struct timespec tv[2]; 92 struct timespec tv[2];
93 93
@@ -102,7 +102,7 @@ asmlinkage long compat_sys_utimensat(unsigned int dfd, const char __user *filena
102 return do_utimes(dfd, filename, t ? tv : NULL, flags); 102 return do_utimes(dfd, filename, t ? tv : NULL, flags);
103} 103}
104 104
105asmlinkage long compat_sys_futimesat(unsigned int dfd, const char __user *filename, struct compat_timeval __user *t) 105COMPAT_SYSCALL_DEFINE3(futimesat, unsigned int, dfd, const char __user *, filename, struct compat_timeval __user *, t)
106{ 106{
107 struct timespec tv[2]; 107 struct timespec tv[2];
108 108
@@ -121,7 +121,7 @@ asmlinkage long compat_sys_futimesat(unsigned int dfd, const char __user *filena
121 return do_utimes(dfd, filename, t ? tv : NULL, 0); 121 return do_utimes(dfd, filename, t ? tv : NULL, 0);
122} 122}
123 123
124asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_timeval __user *t) 124COMPAT_SYSCALL_DEFINE2(utimes, const char __user *, filename, struct compat_timeval __user *, t)
125{ 125{
126 return compat_sys_futimesat(AT_FDCWD, filename, t); 126 return compat_sys_futimesat(AT_FDCWD, filename, t);
127} 127}
@@ -159,8 +159,8 @@ static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
159 return copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0; 159 return copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0;
160} 160}
161 161
162asmlinkage long compat_sys_newstat(const char __user * filename, 162COMPAT_SYSCALL_DEFINE2(newstat, const char __user *, filename,
163 struct compat_stat __user *statbuf) 163 struct compat_stat __user *, statbuf)
164{ 164{
165 struct kstat stat; 165 struct kstat stat;
166 int error; 166 int error;
@@ -171,8 +171,8 @@ asmlinkage long compat_sys_newstat(const char __user * filename,
171 return cp_compat_stat(&stat, statbuf); 171 return cp_compat_stat(&stat, statbuf);
172} 172}
173 173
174asmlinkage long compat_sys_newlstat(const char __user * filename, 174COMPAT_SYSCALL_DEFINE2(newlstat, const char __user *, filename,
175 struct compat_stat __user *statbuf) 175 struct compat_stat __user *, statbuf)
176{ 176{
177 struct kstat stat; 177 struct kstat stat;
178 int error; 178 int error;
@@ -184,9 +184,9 @@ asmlinkage long compat_sys_newlstat(const char __user * filename,
184} 184}
185 185
186#ifndef __ARCH_WANT_STAT64 186#ifndef __ARCH_WANT_STAT64
187asmlinkage long compat_sys_newfstatat(unsigned int dfd, 187COMPAT_SYSCALL_DEFINE4(newfstatat, unsigned int, dfd,
188 const char __user *filename, 188 const char __user *, filename,
189 struct compat_stat __user *statbuf, int flag) 189 struct compat_stat __user *, statbuf, int, flag)
190{ 190{
191 struct kstat stat; 191 struct kstat stat;
192 int error; 192 int error;
@@ -198,8 +198,8 @@ asmlinkage long compat_sys_newfstatat(unsigned int dfd,
198} 198}
199#endif 199#endif
200 200
201asmlinkage long compat_sys_newfstat(unsigned int fd, 201COMPAT_SYSCALL_DEFINE2(newfstat, unsigned int, fd,
202 struct compat_stat __user * statbuf) 202 struct compat_stat __user *, statbuf)
203{ 203{
204 struct kstat stat; 204 struct kstat stat;
205 int error = vfs_fstat(fd, &stat); 205 int error = vfs_fstat(fd, &stat);
@@ -247,7 +247,7 @@ static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *
247 * The following statfs calls are copies of code from fs/statfs.c and 247 * The following statfs calls are copies of code from fs/statfs.c and
248 * should be checked against those from time to time 248 * should be checked against those from time to time
249 */ 249 */
250asmlinkage long compat_sys_statfs(const char __user *pathname, struct compat_statfs __user *buf) 250COMPAT_SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct compat_statfs __user *, buf)
251{ 251{
252 struct kstatfs tmp; 252 struct kstatfs tmp;
253 int error = user_statfs(pathname, &tmp); 253 int error = user_statfs(pathname, &tmp);
@@ -256,7 +256,7 @@ asmlinkage long compat_sys_statfs(const char __user *pathname, struct compat_sta
256 return error; 256 return error;
257} 257}
258 258
259asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs __user *buf) 259COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *, buf)
260{ 260{
261 struct kstatfs tmp; 261 struct kstatfs tmp;
262 int error = fd_statfs(fd, &tmp); 262 int error = fd_statfs(fd, &tmp);
@@ -298,7 +298,7 @@ static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstat
298 return 0; 298 return 0;
299} 299}
300 300
301asmlinkage long compat_sys_statfs64(const char __user *pathname, compat_size_t sz, struct compat_statfs64 __user *buf) 301COMPAT_SYSCALL_DEFINE3(statfs64, const char __user *, pathname, compat_size_t, sz, struct compat_statfs64 __user *, buf)
302{ 302{
303 struct kstatfs tmp; 303 struct kstatfs tmp;
304 int error; 304 int error;
@@ -312,7 +312,7 @@ asmlinkage long compat_sys_statfs64(const char __user *pathname, compat_size_t s
312 return error; 312 return error;
313} 313}
314 314
315asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user *buf) 315COMPAT_SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, compat_size_t, sz, struct compat_statfs64 __user *, buf)
316{ 316{
317 struct kstatfs tmp; 317 struct kstatfs tmp;
318 int error; 318 int error;
@@ -331,7 +331,7 @@ asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct c
331 * Given how simple this syscall is that apporach is more maintainable 331 * Given how simple this syscall is that apporach is more maintainable
332 * than the various conversion hacks. 332 * than the various conversion hacks.
333 */ 333 */
334asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u) 334COMPAT_SYSCALL_DEFINE2(ustat, unsigned, dev, struct compat_ustat __user *, u)
335{ 335{
336 struct compat_ustat tmp; 336 struct compat_ustat tmp;
337 struct kstatfs sbuf; 337 struct kstatfs sbuf;
@@ -399,8 +399,8 @@ static int put_compat_flock64(struct flock *kfl, struct compat_flock64 __user *u
399} 399}
400#endif 400#endif
401 401
402asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd, 402COMPAT_SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
403 unsigned long arg) 403 compat_ulong_t, arg)
404{ 404{
405 mm_segment_t old_fs; 405 mm_segment_t old_fs;
406 struct flock f; 406 struct flock f;
@@ -468,16 +468,15 @@ asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
468 return ret; 468 return ret;
469} 469}
470 470
471asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd, 471COMPAT_SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd,
472 unsigned long arg) 472 compat_ulong_t, arg)
473{ 473{
474 if ((cmd == F_GETLK64) || (cmd == F_SETLK64) || (cmd == F_SETLKW64)) 474 if ((cmd == F_GETLK64) || (cmd == F_SETLK64) || (cmd == F_SETLKW64))
475 return -EINVAL; 475 return -EINVAL;
476 return compat_sys_fcntl64(fd, cmd, arg); 476 return compat_sys_fcntl64(fd, cmd, arg);
477} 477}
478 478
479asmlinkage long 479COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
480compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
481{ 480{
482 long ret; 481 long ret;
483 aio_context_t ctx64; 482 aio_context_t ctx64;
@@ -496,32 +495,24 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
496 return ret; 495 return ret;
497} 496}
498 497
499asmlinkage long 498COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id,
500compat_sys_io_getevents(aio_context_t ctx_id, 499 compat_long_t, min_nr,
501 unsigned long min_nr, 500 compat_long_t, nr,
502 unsigned long nr, 501 struct io_event __user *, events,
503 struct io_event __user *events, 502 struct compat_timespec __user *, timeout)
504 struct compat_timespec __user *timeout)
505{ 503{
506 long ret;
507 struct timespec t; 504 struct timespec t;
508 struct timespec __user *ut = NULL; 505 struct timespec __user *ut = NULL;
509 506
510 ret = -EFAULT;
511 if (unlikely(!access_ok(VERIFY_WRITE, events,
512 nr * sizeof(struct io_event))))
513 goto out;
514 if (timeout) { 507 if (timeout) {
515 if (get_compat_timespec(&t, timeout)) 508 if (get_compat_timespec(&t, timeout))
516 goto out; 509 return -EFAULT;
517 510
518 ut = compat_alloc_user_space(sizeof(*ut)); 511 ut = compat_alloc_user_space(sizeof(*ut));
519 if (copy_to_user(ut, &t, sizeof(t)) ) 512 if (copy_to_user(ut, &t, sizeof(t)) )
520 goto out; 513 return -EFAULT;
521 } 514 }
522 ret = sys_io_getevents(ctx_id, min_nr, nr, events, ut); 515 return sys_io_getevents(ctx_id, min_nr, nr, events, ut);
523out:
524 return ret;
525} 516}
526 517
527/* A write operation does a read from user space and vice versa */ 518/* A write operation does a read from user space and vice versa */
@@ -617,8 +608,8 @@ copy_iocb(long nr, u32 __user *ptr32, struct iocb __user * __user *ptr64)
617 608
618#define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *)) 609#define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
619 610
620asmlinkage long 611COMPAT_SYSCALL_DEFINE3(io_submit, compat_aio_context_t, ctx_id,
621compat_sys_io_submit(aio_context_t ctx_id, int nr, u32 __user *iocb) 612 int, nr, u32 __user *, iocb)
622{ 613{
623 struct iocb __user * __user *iocb64; 614 struct iocb __user * __user *iocb64;
624 long ret; 615 long ret;
@@ -770,10 +761,10 @@ static int do_nfs4_super_data_conv(void *raw_data)
770#define NCPFS_NAME "ncpfs" 761#define NCPFS_NAME "ncpfs"
771#define NFS4_NAME "nfs4" 762#define NFS4_NAME "nfs4"
772 763
773asmlinkage long compat_sys_mount(const char __user * dev_name, 764COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
774 const char __user * dir_name, 765 const char __user *, dir_name,
775 const char __user * type, unsigned long flags, 766 const char __user *, type, compat_ulong_t, flags,
776 const void __user * data) 767 const void __user *, data)
777{ 768{
778 char *kernel_type; 769 char *kernel_type;
779 unsigned long data_page; 770 unsigned long data_page;
@@ -869,8 +860,8 @@ efault:
869 return -EFAULT; 860 return -EFAULT;
870} 861}
871 862
872asmlinkage long compat_sys_old_readdir(unsigned int fd, 863COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
873 struct compat_old_linux_dirent __user *dirent, unsigned int count) 864 struct compat_old_linux_dirent __user *, dirent, unsigned int, count)
874{ 865{
875 int error; 866 int error;
876 struct fd f = fdget(fd); 867 struct fd f = fdget(fd);
@@ -948,8 +939,8 @@ efault:
948 return -EFAULT; 939 return -EFAULT;
949} 940}
950 941
951asmlinkage long compat_sys_getdents(unsigned int fd, 942COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
952 struct compat_linux_dirent __user *dirent, unsigned int count) 943 struct compat_linux_dirent __user *, dirent, unsigned int, count)
953{ 944{
954 struct fd f; 945 struct fd f;
955 struct compat_linux_dirent __user * lastdirent; 946 struct compat_linux_dirent __user * lastdirent;
@@ -981,7 +972,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
981 return error; 972 return error;
982} 973}
983 974
984#ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64 975#ifdef __ARCH_WANT_COMPAT_SYS_GETDENTS64
985 976
986struct compat_getdents_callback64 { 977struct compat_getdents_callback64 {
987 struct dir_context ctx; 978 struct dir_context ctx;
@@ -1033,8 +1024,8 @@ efault:
1033 return -EFAULT; 1024 return -EFAULT;
1034} 1025}
1035 1026
1036asmlinkage long compat_sys_getdents64(unsigned int fd, 1027COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
1037 struct linux_dirent64 __user * dirent, unsigned int count) 1028 struct linux_dirent64 __user *, dirent, unsigned int, count)
1038{ 1029{
1039 struct fd f; 1030 struct fd f;
1040 struct linux_dirent64 __user * lastdirent; 1031 struct linux_dirent64 __user * lastdirent;
@@ -1066,7 +1057,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
1066 fdput(f); 1057 fdput(f);
1067 return error; 1058 return error;
1068} 1059}
1069#endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */ 1060#endif /* __ARCH_WANT_COMPAT_SYS_GETDENTS64 */
1070 1061
1071/* 1062/*
1072 * Exactly like fs/open.c:sys_open(), except that it doesn't set the 1063 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
@@ -1287,9 +1278,9 @@ out_nofds:
1287 return ret; 1278 return ret;
1288} 1279}
1289 1280
1290asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp, 1281COMPAT_SYSCALL_DEFINE5(select, int, n, compat_ulong_t __user *, inp,
1291 compat_ulong_t __user *outp, compat_ulong_t __user *exp, 1282 compat_ulong_t __user *, outp, compat_ulong_t __user *, exp,
1292 struct compat_timeval __user *tvp) 1283 struct compat_timeval __user *, tvp)
1293{ 1284{
1294 struct timespec end_time, *to = NULL; 1285 struct timespec end_time, *to = NULL;
1295 struct compat_timeval tv; 1286 struct compat_timeval tv;
@@ -1320,7 +1311,7 @@ struct compat_sel_arg_struct {
1320 compat_uptr_t tvp; 1311 compat_uptr_t tvp;
1321}; 1312};
1322 1313
1323asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg) 1314COMPAT_SYSCALL_DEFINE1(old_select, struct compat_sel_arg_struct __user *, arg)
1324{ 1315{
1325 struct compat_sel_arg_struct a; 1316 struct compat_sel_arg_struct a;
1326 1317
@@ -1381,9 +1372,9 @@ static long do_compat_pselect(int n, compat_ulong_t __user *inp,
1381 return ret; 1372 return ret;
1382} 1373}
1383 1374
1384asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp, 1375COMPAT_SYSCALL_DEFINE6(pselect6, int, n, compat_ulong_t __user *, inp,
1385 compat_ulong_t __user *outp, compat_ulong_t __user *exp, 1376 compat_ulong_t __user *, outp, compat_ulong_t __user *, exp,
1386 struct compat_timespec __user *tsp, void __user *sig) 1377 struct compat_timespec __user *, tsp, void __user *, sig)
1387{ 1378{
1388 compat_size_t sigsetsize = 0; 1379 compat_size_t sigsetsize = 0;
1389 compat_uptr_t up = 0; 1380 compat_uptr_t up = 0;
@@ -1400,9 +1391,9 @@ asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp,
1400 sigsetsize); 1391 sigsetsize);
1401} 1392}
1402 1393
1403asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds, 1394COMPAT_SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds,
1404 unsigned int nfds, struct compat_timespec __user *tsp, 1395 unsigned int, nfds, struct compat_timespec __user *, tsp,
1405 const compat_sigset_t __user *sigmask, compat_size_t sigsetsize) 1396 const compat_sigset_t __user *, sigmask, compat_size_t, sigsetsize)
1406{ 1397{
1407 compat_sigset_t ss32; 1398 compat_sigset_t ss32;
1408 sigset_t ksigmask, sigsaved; 1399 sigset_t ksigmask, sigsaved;
diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
index a81147e2e4ef..4d24d17bcfc1 100644
--- a/fs/compat_binfmt_elf.c
+++ b/fs/compat_binfmt_elf.c
@@ -88,6 +88,11 @@ static void cputime_to_compat_timeval(const cputime_t cputime,
88#define ELF_HWCAP COMPAT_ELF_HWCAP 88#define ELF_HWCAP COMPAT_ELF_HWCAP
89#endif 89#endif
90 90
91#ifdef COMPAT_ELF_HWCAP2
92#undef ELF_HWCAP2
93#define ELF_HWCAP2 COMPAT_ELF_HWCAP2
94#endif
95
91#ifdef COMPAT_ARCH_DLINFO 96#ifdef COMPAT_ARCH_DLINFO
92#undef ARCH_DLINFO 97#undef ARCH_DLINFO
93#define ARCH_DLINFO COMPAT_ARCH_DLINFO 98#define ARCH_DLINFO COMPAT_ARCH_DLINFO
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 3881610b6438..e82289047272 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -1538,9 +1538,10 @@ static int compat_ioctl_check_table(unsigned int xcmd)
1538 return ioctl_pointer[i] == xcmd; 1538 return ioctl_pointer[i] == xcmd;
1539} 1539}
1540 1540
1541asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, 1541COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
1542 unsigned long arg) 1542 compat_ulong_t, arg32)
1543{ 1543{
1544 unsigned long arg = arg32;
1544 struct fd f = fdget(fd); 1545 struct fd f = fdget(fd);
1545 int error = -EBADF; 1546 int error = -EBADF;
1546 if (!f.file) 1547 if (!f.file)
diff --git a/fs/dcache.c b/fs/dcache.c
index 265e0ce9769c..ca02c13a84aa 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2833,9 +2833,9 @@ static int prepend_name(char **buffer, int *buflen, struct qstr *name)
2833 u32 dlen = ACCESS_ONCE(name->len); 2833 u32 dlen = ACCESS_ONCE(name->len);
2834 char *p; 2834 char *p;
2835 2835
2836 if (*buflen < dlen + 1)
2837 return -ENAMETOOLONG;
2838 *buflen -= dlen + 1; 2836 *buflen -= dlen + 1;
2837 if (*buflen < 0)
2838 return -ENAMETOOLONG;
2839 p = *buffer -= dlen + 1; 2839 p = *buffer -= dlen + 1;
2840 *p++ = '/'; 2840 *p++ = '/';
2841 while (dlen--) { 2841 while (dlen--) {
diff --git a/fs/efivarfs/file.c b/fs/efivarfs/file.c
index 8dd524f32284..cdb2971192a5 100644
--- a/fs/efivarfs/file.c
+++ b/fs/efivarfs/file.c
@@ -21,7 +21,7 @@ static ssize_t efivarfs_file_write(struct file *file,
21 u32 attributes; 21 u32 attributes;
22 struct inode *inode = file->f_mapping->host; 22 struct inode *inode = file->f_mapping->host;
23 unsigned long datasize = count - sizeof(attributes); 23 unsigned long datasize = count - sizeof(attributes);
24 ssize_t bytes = 0; 24 ssize_t bytes;
25 bool set = false; 25 bool set = false;
26 26
27 if (count < sizeof(attributes)) 27 if (count < sizeof(attributes))
@@ -33,14 +33,9 @@ static ssize_t efivarfs_file_write(struct file *file,
33 if (attributes & ~(EFI_VARIABLE_MASK)) 33 if (attributes & ~(EFI_VARIABLE_MASK))
34 return -EINVAL; 34 return -EINVAL;
35 35
36 data = kmalloc(datasize, GFP_KERNEL); 36 data = memdup_user(userbuf + sizeof(attributes), datasize);
37 if (!data) 37 if (IS_ERR(data))
38 return -ENOMEM; 38 return PTR_ERR(data);
39
40 if (copy_from_user(data, userbuf + sizeof(attributes), datasize)) {
41 bytes = -EFAULT;
42 goto out;
43 }
44 39
45 bytes = efivar_entry_set_get_size(var, attributes, &datasize, 40 bytes = efivar_entry_set_get_size(var, attributes, &datasize,
46 data, &set); 41 data, &set);
diff --git a/fs/exec.c b/fs/exec.c
index e1529b4c79b1..4f59402fdda5 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -748,11 +748,10 @@ EXPORT_SYMBOL(setup_arg_pages);
748 748
749#endif /* CONFIG_MMU */ 749#endif /* CONFIG_MMU */
750 750
751struct file *open_exec(const char *name) 751static struct file *do_open_exec(struct filename *name)
752{ 752{
753 struct file *file; 753 struct file *file;
754 int err; 754 int err;
755 struct filename tmp = { .name = name };
756 static const struct open_flags open_exec_flags = { 755 static const struct open_flags open_exec_flags = {
757 .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC, 756 .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
758 .acc_mode = MAY_EXEC | MAY_OPEN, 757 .acc_mode = MAY_EXEC | MAY_OPEN,
@@ -760,7 +759,7 @@ struct file *open_exec(const char *name)
760 .lookup_flags = LOOKUP_FOLLOW, 759 .lookup_flags = LOOKUP_FOLLOW,
761 }; 760 };
762 761
763 file = do_filp_open(AT_FDCWD, &tmp, &open_exec_flags); 762 file = do_filp_open(AT_FDCWD, name, &open_exec_flags);
764 if (IS_ERR(file)) 763 if (IS_ERR(file))
765 goto out; 764 goto out;
766 765
@@ -784,6 +783,12 @@ exit:
784 fput(file); 783 fput(file);
785 return ERR_PTR(err); 784 return ERR_PTR(err);
786} 785}
786
787struct file *open_exec(const char *name)
788{
789 struct filename tmp = { .name = name };
790 return do_open_exec(&tmp);
791}
787EXPORT_SYMBOL(open_exec); 792EXPORT_SYMBOL(open_exec);
788 793
789int kernel_read(struct file *file, loff_t offset, 794int kernel_read(struct file *file, loff_t offset,
@@ -1162,7 +1167,7 @@ int prepare_bprm_creds(struct linux_binprm *bprm)
1162 return -ENOMEM; 1167 return -ENOMEM;
1163} 1168}
1164 1169
1165void free_bprm(struct linux_binprm *bprm) 1170static void free_bprm(struct linux_binprm *bprm)
1166{ 1171{
1167 free_arg_pages(bprm); 1172 free_arg_pages(bprm);
1168 if (bprm->cred) { 1173 if (bprm->cred) {
@@ -1432,7 +1437,7 @@ static int exec_binprm(struct linux_binprm *bprm)
1432/* 1437/*
1433 * sys_execve() executes a new program. 1438 * sys_execve() executes a new program.
1434 */ 1439 */
1435static int do_execve_common(const char *filename, 1440static int do_execve_common(struct filename *filename,
1436 struct user_arg_ptr argv, 1441 struct user_arg_ptr argv,
1437 struct user_arg_ptr envp) 1442 struct user_arg_ptr envp)
1438{ 1443{
@@ -1441,6 +1446,9 @@ static int do_execve_common(const char *filename,
1441 struct files_struct *displaced; 1446 struct files_struct *displaced;
1442 int retval; 1447 int retval;
1443 1448
1449 if (IS_ERR(filename))
1450 return PTR_ERR(filename);
1451
1444 /* 1452 /*
1445 * We move the actual failure in case of RLIMIT_NPROC excess from 1453 * We move the actual failure in case of RLIMIT_NPROC excess from
1446 * set*uid() to execve() because too many poorly written programs 1454 * set*uid() to execve() because too many poorly written programs
@@ -1473,7 +1481,7 @@ static int do_execve_common(const char *filename,
1473 check_unsafe_exec(bprm); 1481 check_unsafe_exec(bprm);
1474 current->in_execve = 1; 1482 current->in_execve = 1;
1475 1483
1476 file = open_exec(filename); 1484 file = do_open_exec(filename);
1477 retval = PTR_ERR(file); 1485 retval = PTR_ERR(file);
1478 if (IS_ERR(file)) 1486 if (IS_ERR(file))
1479 goto out_unmark; 1487 goto out_unmark;
@@ -1481,8 +1489,7 @@ static int do_execve_common(const char *filename,
1481 sched_exec(); 1489 sched_exec();
1482 1490
1483 bprm->file = file; 1491 bprm->file = file;
1484 bprm->filename = filename; 1492 bprm->filename = bprm->interp = filename->name;
1485 bprm->interp = filename;
1486 1493
1487 retval = bprm_mm_init(bprm); 1494 retval = bprm_mm_init(bprm);
1488 if (retval) 1495 if (retval)
@@ -1523,6 +1530,7 @@ static int do_execve_common(const char *filename,
1523 acct_update_integrals(current); 1530 acct_update_integrals(current);
1524 task_numa_free(current); 1531 task_numa_free(current);
1525 free_bprm(bprm); 1532 free_bprm(bprm);
1533 putname(filename);
1526 if (displaced) 1534 if (displaced)
1527 put_files_struct(displaced); 1535 put_files_struct(displaced);
1528 return retval; 1536 return retval;
@@ -1544,10 +1552,11 @@ out_files:
1544 if (displaced) 1552 if (displaced)
1545 reset_files_struct(displaced); 1553 reset_files_struct(displaced);
1546out_ret: 1554out_ret:
1555 putname(filename);
1547 return retval; 1556 return retval;
1548} 1557}
1549 1558
1550int do_execve(const char *filename, 1559int do_execve(struct filename *filename,
1551 const char __user *const __user *__argv, 1560 const char __user *const __user *__argv,
1552 const char __user *const __user *__envp) 1561 const char __user *const __user *__envp)
1553{ 1562{
@@ -1557,7 +1566,7 @@ int do_execve(const char *filename,
1557} 1566}
1558 1567
1559#ifdef CONFIG_COMPAT 1568#ifdef CONFIG_COMPAT
1560static int compat_do_execve(const char *filename, 1569static int compat_do_execve(struct filename *filename,
1561 const compat_uptr_t __user *__argv, 1570 const compat_uptr_t __user *__argv,
1562 const compat_uptr_t __user *__envp) 1571 const compat_uptr_t __user *__envp)
1563{ 1572{
@@ -1607,25 +1616,13 @@ SYSCALL_DEFINE3(execve,
1607 const char __user *const __user *, argv, 1616 const char __user *const __user *, argv,
1608 const char __user *const __user *, envp) 1617 const char __user *const __user *, envp)
1609{ 1618{
1610 struct filename *path = getname(filename); 1619 return do_execve(getname(filename), argv, envp);
1611 int error = PTR_ERR(path);
1612 if (!IS_ERR(path)) {
1613 error = do_execve(path->name, argv, envp);
1614 putname(path);
1615 }
1616 return error;
1617} 1620}
1618#ifdef CONFIG_COMPAT 1621#ifdef CONFIG_COMPAT
1619asmlinkage long compat_sys_execve(const char __user * filename, 1622COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
1620 const compat_uptr_t __user * argv, 1623 const compat_uptr_t __user *, argv,
1621 const compat_uptr_t __user * envp) 1624 const compat_uptr_t __user *, envp)
1622{ 1625{
1623 struct filename *path = getname(filename); 1626 return compat_do_execve(getname(filename), argv, envp);
1624 int error = PTR_ERR(path);
1625 if (!IS_ERR(path)) {
1626 error = compat_do_execve(path->name, argv, envp);
1627 putname(path);
1628 }
1629 return error;
1630} 1627}
1631#endif 1628#endif
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index ece55565b9cd..d3a534fdc5ff 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -771,6 +771,8 @@ do { \
771 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 771 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
772 (einode)->xtime.tv_sec = \ 772 (einode)->xtime.tv_sec = \
773 (signed)le32_to_cpu((raw_inode)->xtime); \ 773 (signed)le32_to_cpu((raw_inode)->xtime); \
774 else \
775 (einode)->xtime.tv_sec = 0; \
774 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 776 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
775 ext4_decode_extra_time(&(einode)->xtime, \ 777 ext4_decode_extra_time(&(einode)->xtime, \
776 raw_inode->xtime ## _extra); \ 778 raw_inode->xtime ## _extra); \
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 10cff4736b11..74bc2d549c58 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3906,6 +3906,7 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,
3906 } else 3906 } else
3907 err = ret; 3907 err = ret;
3908 map->m_flags |= EXT4_MAP_MAPPED; 3908 map->m_flags |= EXT4_MAP_MAPPED;
3909 map->m_pblk = newblock;
3909 if (allocated > map->m_len) 3910 if (allocated > map->m_len)
3910 allocated = map->m_len; 3911 allocated = map->m_len;
3911 map->m_len = allocated; 3912 map->m_len = allocated;
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 43e64f6022eb..1a5073959f32 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -152,7 +152,7 @@ ext4_file_dio_write(struct kiocb *iocb, const struct iovec *iov,
152 if (ret > 0) { 152 if (ret > 0) {
153 ssize_t err; 153 ssize_t err;
154 154
155 err = generic_write_sync(file, pos, ret); 155 err = generic_write_sync(file, iocb->ki_pos - ret, ret);
156 if (err < 0 && ret > 0) 156 if (err < 0 && ret > 0)
157 ret = err; 157 ret = err;
158 } 158 }
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 6e39895a91b8..24bfd7ff3049 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -38,6 +38,7 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/ratelimit.h> 39#include <linux/ratelimit.h>
40#include <linux/aio.h> 40#include <linux/aio.h>
41#include <linux/bitops.h>
41 42
42#include "ext4_jbd2.h" 43#include "ext4_jbd2.h"
43#include "xattr.h" 44#include "xattr.h"
@@ -3921,18 +3922,20 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
3921void ext4_set_inode_flags(struct inode *inode) 3922void ext4_set_inode_flags(struct inode *inode)
3922{ 3923{
3923 unsigned int flags = EXT4_I(inode)->i_flags; 3924 unsigned int flags = EXT4_I(inode)->i_flags;
3925 unsigned int new_fl = 0;
3924 3926
3925 inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3926 if (flags & EXT4_SYNC_FL) 3927 if (flags & EXT4_SYNC_FL)
3927 inode->i_flags |= S_SYNC; 3928 new_fl |= S_SYNC;
3928 if (flags & EXT4_APPEND_FL) 3929 if (flags & EXT4_APPEND_FL)
3929 inode->i_flags |= S_APPEND; 3930 new_fl |= S_APPEND;
3930 if (flags & EXT4_IMMUTABLE_FL) 3931 if (flags & EXT4_IMMUTABLE_FL)
3931 inode->i_flags |= S_IMMUTABLE; 3932 new_fl |= S_IMMUTABLE;
3932 if (flags & EXT4_NOATIME_FL) 3933 if (flags & EXT4_NOATIME_FL)
3933 inode->i_flags |= S_NOATIME; 3934 new_fl |= S_NOATIME;
3934 if (flags & EXT4_DIRSYNC_FL) 3935 if (flags & EXT4_DIRSYNC_FL)
3935 inode->i_flags |= S_DIRSYNC; 3936 new_fl |= S_DIRSYNC;
3937 set_mask_bits(&inode->i_flags,
3938 S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl);
3936} 3939}
3937 3940
3938/* Propagate flags from i_flags to EXT4_I(inode)->i_flags */ 3941/* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 6bea80614d77..a2a837f00407 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -140,7 +140,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
140 handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2); 140 handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2);
141 if (IS_ERR(handle)) { 141 if (IS_ERR(handle)) {
142 err = -EINVAL; 142 err = -EINVAL;
143 goto swap_boot_out; 143 goto journal_err_out;
144 } 144 }
145 145
146 /* Protect extent tree against block allocations via delalloc */ 146 /* Protect extent tree against block allocations via delalloc */
@@ -198,6 +198,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
198 198
199 ext4_double_up_write_data_sem(inode, inode_bl); 199 ext4_double_up_write_data_sem(inode, inode_bl);
200 200
201journal_err_out:
201 ext4_inode_resume_unlocked_dio(inode); 202 ext4_inode_resume_unlocked_dio(inode);
202 ext4_inode_resume_unlocked_dio(inode_bl); 203 ext4_inode_resume_unlocked_dio(inode_bl);
203 204
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index c5adbb318a90..f3b84cd9de56 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -243,6 +243,7 @@ static int ext4_alloc_group_tables(struct super_block *sb,
243 ext4_group_t group; 243 ext4_group_t group;
244 ext4_group_t last_group; 244 ext4_group_t last_group;
245 unsigned overhead; 245 unsigned overhead;
246 __u16 uninit_mask = (flexbg_size > 1) ? ~EXT4_BG_BLOCK_UNINIT : ~0;
246 247
247 BUG_ON(flex_gd->count == 0 || group_data == NULL); 248 BUG_ON(flex_gd->count == 0 || group_data == NULL);
248 249
@@ -266,7 +267,7 @@ next_group:
266 src_group++; 267 src_group++;
267 for (; src_group <= last_group; src_group++) { 268 for (; src_group <= last_group; src_group++) {
268 overhead = ext4_group_overhead_blocks(sb, src_group); 269 overhead = ext4_group_overhead_blocks(sb, src_group);
269 if (overhead != 0) 270 if (overhead == 0)
270 last_blk += group_data[src_group - group].blocks_count; 271 last_blk += group_data[src_group - group].blocks_count;
271 else 272 else
272 break; 273 break;
@@ -280,8 +281,7 @@ next_group:
280 group = ext4_get_group_number(sb, start_blk - 1); 281 group = ext4_get_group_number(sb, start_blk - 1);
281 group -= group_data[0].group; 282 group -= group_data[0].group;
282 group_data[group].free_blocks_count--; 283 group_data[group].free_blocks_count--;
283 if (flexbg_size > 1) 284 flex_gd->bg_flags[group] &= uninit_mask;
284 flex_gd->bg_flags[group] &= ~EXT4_BG_BLOCK_UNINIT;
285 } 285 }
286 286
287 /* Allocate inode bitmaps */ 287 /* Allocate inode bitmaps */
@@ -292,22 +292,30 @@ next_group:
292 group = ext4_get_group_number(sb, start_blk - 1); 292 group = ext4_get_group_number(sb, start_blk - 1);
293 group -= group_data[0].group; 293 group -= group_data[0].group;
294 group_data[group].free_blocks_count--; 294 group_data[group].free_blocks_count--;
295 if (flexbg_size > 1) 295 flex_gd->bg_flags[group] &= uninit_mask;
296 flex_gd->bg_flags[group] &= ~EXT4_BG_BLOCK_UNINIT;
297 } 296 }
298 297
299 /* Allocate inode tables */ 298 /* Allocate inode tables */
300 for (; it_index < flex_gd->count; it_index++) { 299 for (; it_index < flex_gd->count; it_index++) {
301 if (start_blk + EXT4_SB(sb)->s_itb_per_group > last_blk) 300 unsigned int itb = EXT4_SB(sb)->s_itb_per_group;
301 ext4_fsblk_t next_group_start;
302
303 if (start_blk + itb > last_blk)
302 goto next_group; 304 goto next_group;
303 group_data[it_index].inode_table = start_blk; 305 group_data[it_index].inode_table = start_blk;
304 group = ext4_get_group_number(sb, start_blk - 1); 306 group = ext4_get_group_number(sb, start_blk);
307 next_group_start = ext4_group_first_block_no(sb, group + 1);
305 group -= group_data[0].group; 308 group -= group_data[0].group;
306 group_data[group].free_blocks_count -=
307 EXT4_SB(sb)->s_itb_per_group;
308 if (flexbg_size > 1)
309 flex_gd->bg_flags[group] &= ~EXT4_BG_BLOCK_UNINIT;
310 309
310 if (start_blk + itb > next_group_start) {
311 flex_gd->bg_flags[group + 1] &= uninit_mask;
312 overhead = start_blk + itb - next_group_start;
313 group_data[group + 1].free_blocks_count -= overhead;
314 itb -= overhead;
315 }
316
317 group_data[group].free_blocks_count -= itb;
318 flex_gd->bg_flags[group] &= uninit_mask;
311 start_blk += EXT4_SB(sb)->s_itb_per_group; 319 start_blk += EXT4_SB(sb)->s_itb_per_group;
312 } 320 }
313 321
@@ -401,7 +409,7 @@ static int set_flexbg_block_bitmap(struct super_block *sb, handle_t *handle,
401 start = ext4_group_first_block_no(sb, group); 409 start = ext4_group_first_block_no(sb, group);
402 group -= flex_gd->groups[0].group; 410 group -= flex_gd->groups[0].group;
403 411
404 count2 = sb->s_blocksize * 8 - (block - start); 412 count2 = EXT4_BLOCKS_PER_GROUP(sb) - (block - start);
405 if (count2 > count) 413 if (count2 > count)
406 count2 = count; 414 count2 = count;
407 415
@@ -620,7 +628,7 @@ handle_ib:
620 if (err) 628 if (err)
621 goto out; 629 goto out;
622 count = group_table_count[j]; 630 count = group_table_count[j];
623 start = group_data[i].block_bitmap; 631 start = (&group_data[i].block_bitmap)[j];
624 block = start; 632 block = start;
625 } 633 }
626 634
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 1f7784de05b6..710fed2377d4 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3695,16 +3695,22 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3695 for (i = 0; i < 4; i++) 3695 for (i = 0; i < 4; i++)
3696 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); 3696 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
3697 sbi->s_def_hash_version = es->s_def_hash_version; 3697 sbi->s_def_hash_version = es->s_def_hash_version;
3698 i = le32_to_cpu(es->s_flags); 3698 if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) {
3699 if (i & EXT2_FLAGS_UNSIGNED_HASH) 3699 i = le32_to_cpu(es->s_flags);
3700 sbi->s_hash_unsigned = 3; 3700 if (i & EXT2_FLAGS_UNSIGNED_HASH)
3701 else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) { 3701 sbi->s_hash_unsigned = 3;
3702 else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {
3702#ifdef __CHAR_UNSIGNED__ 3703#ifdef __CHAR_UNSIGNED__
3703 es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH); 3704 if (!(sb->s_flags & MS_RDONLY))
3704 sbi->s_hash_unsigned = 3; 3705 es->s_flags |=
3706 cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);
3707 sbi->s_hash_unsigned = 3;
3705#else 3708#else
3706 es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH); 3709 if (!(sb->s_flags & MS_RDONLY))
3710 es->s_flags |=
3711 cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
3707#endif 3712#endif
3713 }
3708 } 3714 }
3709 3715
3710 /* Handle clustersize */ 3716 /* Handle clustersize */
diff --git a/fs/file.c b/fs/file.c
index 771578b33fb6..b61293badfb1 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -34,7 +34,7 @@ static void *alloc_fdmem(size_t size)
34 * vmalloc() if the allocation size will be considered "large" by the VM. 34 * vmalloc() if the allocation size will be considered "large" by the VM.
35 */ 35 */
36 if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) { 36 if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
37 void *data = kmalloc(size, GFP_KERNEL|__GFP_NOWARN); 37 void *data = kmalloc(size, GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY);
38 if (data != NULL) 38 if (data != NULL)
39 return data; 39 return data;
40 } 40 }
@@ -497,7 +497,7 @@ repeat:
497 error = fd; 497 error = fd;
498#if 1 498#if 1
499 /* Sanity check */ 499 /* Sanity check */
500 if (rcu_dereference_raw(fdt->fd[fd]) != NULL) { 500 if (rcu_access_pointer(fdt->fd[fd]) != NULL) {
501 printk(KERN_WARNING "alloc_fd: slot %d not NULL!\n", fd); 501 printk(KERN_WARNING "alloc_fd: slot %d not NULL!\n", fd);
502 rcu_assign_pointer(fdt->fd[fd], NULL); 502 rcu_assign_pointer(fdt->fd[fd], NULL);
503 } 503 }
@@ -683,35 +683,54 @@ EXPORT_SYMBOL(fget_raw);
683 * The fput_needed flag returned by fget_light should be passed to the 683 * The fput_needed flag returned by fget_light should be passed to the
684 * corresponding fput_light. 684 * corresponding fput_light.
685 */ 685 */
686struct file *__fget_light(unsigned int fd, fmode_t mask, int *fput_needed) 686static unsigned long __fget_light(unsigned int fd, fmode_t mask)
687{ 687{
688 struct files_struct *files = current->files; 688 struct files_struct *files = current->files;
689 struct file *file; 689 struct file *file;
690 690
691 *fput_needed = 0;
692 if (atomic_read(&files->count) == 1) { 691 if (atomic_read(&files->count) == 1) {
693 file = __fcheck_files(files, fd); 692 file = __fcheck_files(files, fd);
694 if (file && (file->f_mode & mask)) 693 if (!file || unlikely(file->f_mode & mask))
695 file = NULL; 694 return 0;
695 return (unsigned long)file;
696 } else { 696 } else {
697 file = __fget(fd, mask); 697 file = __fget(fd, mask);
698 if (file) 698 if (!file)
699 *fput_needed = 1; 699 return 0;
700 return FDPUT_FPUT | (unsigned long)file;
700 } 701 }
701
702 return file;
703} 702}
704struct file *fget_light(unsigned int fd, int *fput_needed) 703unsigned long __fdget(unsigned int fd)
705{ 704{
706 return __fget_light(fd, FMODE_PATH, fput_needed); 705 return __fget_light(fd, FMODE_PATH);
707} 706}
708EXPORT_SYMBOL(fget_light); 707EXPORT_SYMBOL(__fdget);
709 708
710struct file *fget_raw_light(unsigned int fd, int *fput_needed) 709unsigned long __fdget_raw(unsigned int fd)
711{ 710{
712 return __fget_light(fd, 0, fput_needed); 711 return __fget_light(fd, 0);
713} 712}
714 713
714unsigned long __fdget_pos(unsigned int fd)
715{
716 unsigned long v = __fdget(fd);
717 struct file *file = (struct file *)(v & ~3);
718
719 if (file && (file->f_mode & FMODE_ATOMIC_POS)) {
720 if (file_count(file) > 1) {
721 v |= FDPUT_POS_UNLOCK;
722 mutex_lock(&file->f_pos_lock);
723 }
724 }
725 return v;
726}
727
728/*
729 * We only lock f_pos if we have threads or if the file might be
730 * shared with another process. In both cases we'll have an elevated
731 * file count (done either by fdget() or by fork()).
732 */
733
715void set_close_on_exec(unsigned int fd, int flag) 734void set_close_on_exec(unsigned int fd, int flag)
716{ 735{
717 struct files_struct *files = current->files; 736 struct files_struct *files = current->files;
diff --git a/fs/file_table.c b/fs/file_table.c
index 5fff9030be34..5b24008ea4f6 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -135,6 +135,7 @@ struct file *get_empty_filp(void)
135 atomic_long_set(&f->f_count, 1); 135 atomic_long_set(&f->f_count, 1);
136 rwlock_init(&f->f_owner.lock); 136 rwlock_init(&f->f_owner.lock);
137 spin_lock_init(&f->f_lock); 137 spin_lock_init(&f->f_lock);
138 mutex_init(&f->f_pos_lock);
138 eventpoll_init_file(f); 139 eventpoll_init_file(f);
139 /* f->f_version: 0 */ 140 /* f->f_version: 0 */
140 return f; 141 return f;
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index e0259a163f98..d754e3cf99a8 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -40,18 +40,13 @@
40struct wb_writeback_work { 40struct wb_writeback_work {
41 long nr_pages; 41 long nr_pages;
42 struct super_block *sb; 42 struct super_block *sb;
43 /* 43 unsigned long *older_than_this;
44 * Write only inodes dirtied before this time. Don't forget to set
45 * older_than_this_is_set when you set this.
46 */
47 unsigned long older_than_this;
48 enum writeback_sync_modes sync_mode; 44 enum writeback_sync_modes sync_mode;
49 unsigned int tagged_writepages:1; 45 unsigned int tagged_writepages:1;
50 unsigned int for_kupdate:1; 46 unsigned int for_kupdate:1;
51 unsigned int range_cyclic:1; 47 unsigned int range_cyclic:1;
52 unsigned int for_background:1; 48 unsigned int for_background:1;
53 unsigned int for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ 49 unsigned int for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
54 unsigned int older_than_this_is_set:1;
55 enum wb_reason reason; /* why was writeback initiated? */ 50 enum wb_reason reason; /* why was writeback initiated? */
56 51
57 struct list_head list; /* pending work list */ 52 struct list_head list; /* pending work list */
@@ -252,10 +247,10 @@ static int move_expired_inodes(struct list_head *delaying_queue,
252 int do_sb_sort = 0; 247 int do_sb_sort = 0;
253 int moved = 0; 248 int moved = 0;
254 249
255 WARN_ON_ONCE(!work->older_than_this_is_set);
256 while (!list_empty(delaying_queue)) { 250 while (!list_empty(delaying_queue)) {
257 inode = wb_inode(delaying_queue->prev); 251 inode = wb_inode(delaying_queue->prev);
258 if (inode_dirtied_after(inode, work->older_than_this)) 252 if (work->older_than_this &&
253 inode_dirtied_after(inode, *work->older_than_this))
259 break; 254 break;
260 list_move(&inode->i_wb_list, &tmp); 255 list_move(&inode->i_wb_list, &tmp);
261 moved++; 256 moved++;
@@ -742,8 +737,6 @@ static long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages,
742 .sync_mode = WB_SYNC_NONE, 737 .sync_mode = WB_SYNC_NONE,
743 .range_cyclic = 1, 738 .range_cyclic = 1,
744 .reason = reason, 739 .reason = reason,
745 .older_than_this = jiffies,
746 .older_than_this_is_set = 1,
747 }; 740 };
748 741
749 spin_lock(&wb->list_lock); 742 spin_lock(&wb->list_lock);
@@ -802,13 +795,12 @@ static long wb_writeback(struct bdi_writeback *wb,
802{ 795{
803 unsigned long wb_start = jiffies; 796 unsigned long wb_start = jiffies;
804 long nr_pages = work->nr_pages; 797 long nr_pages = work->nr_pages;
798 unsigned long oldest_jif;
805 struct inode *inode; 799 struct inode *inode;
806 long progress; 800 long progress;
807 801
808 if (!work->older_than_this_is_set) { 802 oldest_jif = jiffies;
809 work->older_than_this = jiffies; 803 work->older_than_this = &oldest_jif;
810 work->older_than_this_is_set = 1;
811 }
812 804
813 spin_lock(&wb->list_lock); 805 spin_lock(&wb->list_lock);
814 for (;;) { 806 for (;;) {
@@ -842,10 +834,10 @@ static long wb_writeback(struct bdi_writeback *wb,
842 * safe. 834 * safe.
843 */ 835 */
844 if (work->for_kupdate) { 836 if (work->for_kupdate) {
845 work->older_than_this = jiffies - 837 oldest_jif = jiffies -
846 msecs_to_jiffies(dirty_expire_interval * 10); 838 msecs_to_jiffies(dirty_expire_interval * 10);
847 } else if (work->for_background) 839 } else if (work->for_background)
848 work->older_than_this = jiffies; 840 oldest_jif = jiffies;
849 841
850 trace_writeback_start(wb->bdi, work); 842 trace_writeback_start(wb->bdi, work);
851 if (list_empty(&wb->b_io)) 843 if (list_empty(&wb->b_io))
@@ -1357,21 +1349,18 @@ EXPORT_SYMBOL(try_to_writeback_inodes_sb);
1357 1349
1358/** 1350/**
1359 * sync_inodes_sb - sync sb inode pages 1351 * sync_inodes_sb - sync sb inode pages
1360 * @sb: the superblock 1352 * @sb: the superblock
1361 * @older_than_this: timestamp
1362 * 1353 *
1363 * This function writes and waits on any dirty inode belonging to this 1354 * This function writes and waits on any dirty inode belonging to this
1364 * superblock that has been dirtied before given timestamp. 1355 * super_block.
1365 */ 1356 */
1366void sync_inodes_sb(struct super_block *sb, unsigned long older_than_this) 1357void sync_inodes_sb(struct super_block *sb)
1367{ 1358{
1368 DECLARE_COMPLETION_ONSTACK(done); 1359 DECLARE_COMPLETION_ONSTACK(done);
1369 struct wb_writeback_work work = { 1360 struct wb_writeback_work work = {
1370 .sb = sb, 1361 .sb = sb,
1371 .sync_mode = WB_SYNC_ALL, 1362 .sync_mode = WB_SYNC_ALL,
1372 .nr_pages = LONG_MAX, 1363 .nr_pages = LONG_MAX,
1373 .older_than_this = older_than_this,
1374 .older_than_this_is_set = 1,
1375 .range_cyclic = 0, 1364 .range_cyclic = 0,
1376 .done = &done, 1365 .done = &done,
1377 .reason = WB_REASON_SYNC, 1366 .reason = WB_REASON_SYNC,
diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
index e1959efad64f..b5ebc2d7d80d 100644
--- a/fs/fscache/object-list.c
+++ b/fs/fscache/object-list.c
@@ -50,6 +50,8 @@ void fscache_objlist_add(struct fscache_object *obj)
50 struct fscache_object *xobj; 50 struct fscache_object *xobj;
51 struct rb_node **p = &fscache_object_list.rb_node, *parent = NULL; 51 struct rb_node **p = &fscache_object_list.rb_node, *parent = NULL;
52 52
53 ASSERT(RB_EMPTY_NODE(&obj->objlist_link));
54
53 write_lock(&fscache_object_list_lock); 55 write_lock(&fscache_object_list_lock);
54 56
55 while (*p) { 57 while (*p) {
@@ -75,6 +77,9 @@ void fscache_objlist_add(struct fscache_object *obj)
75 */ 77 */
76void fscache_objlist_remove(struct fscache_object *obj) 78void fscache_objlist_remove(struct fscache_object *obj)
77{ 79{
80 if (RB_EMPTY_NODE(&obj->objlist_link))
81 return;
82
78 write_lock(&fscache_object_list_lock); 83 write_lock(&fscache_object_list_lock);
79 84
80 BUG_ON(RB_EMPTY_ROOT(&fscache_object_list)); 85 BUG_ON(RB_EMPTY_ROOT(&fscache_object_list));
diff --git a/fs/fscache/object.c b/fs/fscache/object.c
index 53d35c504240..d3b4539f1651 100644
--- a/fs/fscache/object.c
+++ b/fs/fscache/object.c
@@ -314,6 +314,9 @@ void fscache_object_init(struct fscache_object *object,
314 object->cache = cache; 314 object->cache = cache;
315 object->cookie = cookie; 315 object->cookie = cookie;
316 object->parent = NULL; 316 object->parent = NULL;
317#ifdef CONFIG_FSCACHE_OBJECT_LIST
318 RB_CLEAR_NODE(&object->objlist_link);
319#endif
317 320
318 object->oob_event_mask = 0; 321 object->oob_event_mask = 0;
319 for (t = object->oob_table; t->events; t++) 322 for (t = object->oob_table; t->events; t++)
diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
index 968ce411db53..32602c667b4a 100644
--- a/fs/hfsplus/catalog.c
+++ b/fs/hfsplus/catalog.c
@@ -103,6 +103,8 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
103 folder = &entry->folder; 103 folder = &entry->folder;
104 memset(folder, 0, sizeof(*folder)); 104 memset(folder, 0, sizeof(*folder));
105 folder->type = cpu_to_be16(HFSPLUS_FOLDER); 105 folder->type = cpu_to_be16(HFSPLUS_FOLDER);
106 if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags))
107 folder->flags |= cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT);
106 folder->id = cpu_to_be32(inode->i_ino); 108 folder->id = cpu_to_be32(inode->i_ino);
107 HFSPLUS_I(inode)->create_date = 109 HFSPLUS_I(inode)->create_date =
108 folder->create_date = 110 folder->create_date =
@@ -203,6 +205,36 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
203 return hfs_brec_find(fd, hfs_find_rec_by_key); 205 return hfs_brec_find(fd, hfs_find_rec_by_key);
204} 206}
205 207
208static void hfsplus_subfolders_inc(struct inode *dir)
209{
210 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
211
212 if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags)) {
213 /*
214 * Increment subfolder count. Note, the value is only meaningful
215 * for folders with HFSPLUS_HAS_FOLDER_COUNT flag set.
216 */
217 HFSPLUS_I(dir)->subfolders++;
218 }
219}
220
221static void hfsplus_subfolders_dec(struct inode *dir)
222{
223 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
224
225 if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags)) {
226 /*
227 * Decrement subfolder count. Note, the value is only meaningful
228 * for folders with HFSPLUS_HAS_FOLDER_COUNT flag set.
229 *
230 * Check for zero. Some subfolders may have been created
231 * by an implementation ignorant of this counter.
232 */
233 if (HFSPLUS_I(dir)->subfolders)
234 HFSPLUS_I(dir)->subfolders--;
235 }
236}
237
206int hfsplus_create_cat(u32 cnid, struct inode *dir, 238int hfsplus_create_cat(u32 cnid, struct inode *dir,
207 struct qstr *str, struct inode *inode) 239 struct qstr *str, struct inode *inode)
208{ 240{
@@ -247,6 +279,8 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
247 goto err1; 279 goto err1;
248 280
249 dir->i_size++; 281 dir->i_size++;
282 if (S_ISDIR(inode->i_mode))
283 hfsplus_subfolders_inc(dir);
250 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; 284 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
251 hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY); 285 hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY);
252 286
@@ -336,6 +370,8 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str)
336 goto out; 370 goto out;
337 371
338 dir->i_size--; 372 dir->i_size--;
373 if (type == HFSPLUS_FOLDER)
374 hfsplus_subfolders_dec(dir);
339 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; 375 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
340 hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY); 376 hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY);
341 377
@@ -380,6 +416,7 @@ int hfsplus_rename_cat(u32 cnid,
380 416
381 hfs_bnode_read(src_fd.bnode, &entry, src_fd.entryoffset, 417 hfs_bnode_read(src_fd.bnode, &entry, src_fd.entryoffset,
382 src_fd.entrylength); 418 src_fd.entrylength);
419 type = be16_to_cpu(entry.type);
383 420
384 /* create new dir entry with the data from the old entry */ 421 /* create new dir entry with the data from the old entry */
385 hfsplus_cat_build_key(sb, dst_fd.search_key, dst_dir->i_ino, dst_name); 422 hfsplus_cat_build_key(sb, dst_fd.search_key, dst_dir->i_ino, dst_name);
@@ -394,6 +431,8 @@ int hfsplus_rename_cat(u32 cnid,
394 if (err) 431 if (err)
395 goto out; 432 goto out;
396 dst_dir->i_size++; 433 dst_dir->i_size++;
434 if (type == HFSPLUS_FOLDER)
435 hfsplus_subfolders_inc(dst_dir);
397 dst_dir->i_mtime = dst_dir->i_ctime = CURRENT_TIME_SEC; 436 dst_dir->i_mtime = dst_dir->i_ctime = CURRENT_TIME_SEC;
398 437
399 /* finally remove the old entry */ 438 /* finally remove the old entry */
@@ -405,6 +444,8 @@ int hfsplus_rename_cat(u32 cnid,
405 if (err) 444 if (err)
406 goto out; 445 goto out;
407 src_dir->i_size--; 446 src_dir->i_size--;
447 if (type == HFSPLUS_FOLDER)
448 hfsplus_subfolders_dec(src_dir);
408 src_dir->i_mtime = src_dir->i_ctime = CURRENT_TIME_SEC; 449 src_dir->i_mtime = src_dir->i_ctime = CURRENT_TIME_SEC;
409 450
410 /* remove old thread entry */ 451 /* remove old thread entry */
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 08846425b67f..62d571eb69ba 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -242,6 +242,7 @@ struct hfsplus_inode_info {
242 */ 242 */
243 sector_t fs_blocks; 243 sector_t fs_blocks;
244 u8 userflags; /* BSD user file flags */ 244 u8 userflags; /* BSD user file flags */
245 u32 subfolders; /* Subfolder count (HFSX only) */
245 struct list_head open_dir_list; 246 struct list_head open_dir_list;
246 loff_t phys_size; 247 loff_t phys_size;
247 248
diff --git a/fs/hfsplus/hfsplus_raw.h b/fs/hfsplus/hfsplus_raw.h
index 8ffb3a8ffe75..5a126828d85e 100644
--- a/fs/hfsplus/hfsplus_raw.h
+++ b/fs/hfsplus/hfsplus_raw.h
@@ -261,7 +261,7 @@ struct hfsplus_cat_folder {
261 struct DInfo user_info; 261 struct DInfo user_info;
262 struct DXInfo finder_info; 262 struct DXInfo finder_info;
263 __be32 text_encoding; 263 __be32 text_encoding;
264 u32 reserved; 264 __be32 subfolders; /* Subfolder count in HFSX. Reserved in HFS+. */
265} __packed; 265} __packed;
266 266
267/* HFS file info (stolen from hfs.h) */ 267/* HFS file info (stolen from hfs.h) */
@@ -301,11 +301,13 @@ struct hfsplus_cat_file {
301 struct hfsplus_fork_raw rsrc_fork; 301 struct hfsplus_fork_raw rsrc_fork;
302} __packed; 302} __packed;
303 303
304/* File attribute bits */ 304/* File and folder flag bits */
305#define HFSPLUS_FILE_LOCKED 0x0001 305#define HFSPLUS_FILE_LOCKED 0x0001
306#define HFSPLUS_FILE_THREAD_EXISTS 0x0002 306#define HFSPLUS_FILE_THREAD_EXISTS 0x0002
307#define HFSPLUS_XATTR_EXISTS 0x0004 307#define HFSPLUS_XATTR_EXISTS 0x0004
308#define HFSPLUS_ACL_EXISTS 0x0008 308#define HFSPLUS_ACL_EXISTS 0x0008
309#define HFSPLUS_HAS_FOLDER_COUNT 0x0010 /* Folder has subfolder count
310 * (HFSX only) */
309 311
310/* HFS+ catalog thread (part of a cat_entry) */ 312/* HFS+ catalog thread (part of a cat_entry) */
311struct hfsplus_cat_thread { 313struct hfsplus_cat_thread {
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index fa929f325f87..a4f45bd88a63 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -375,6 +375,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, umode_t mode)
375 hip->extent_state = 0; 375 hip->extent_state = 0;
376 hip->flags = 0; 376 hip->flags = 0;
377 hip->userflags = 0; 377 hip->userflags = 0;
378 hip->subfolders = 0;
378 memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec)); 379 memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec));
379 memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec)); 380 memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
380 hip->alloc_blocks = 0; 381 hip->alloc_blocks = 0;
@@ -494,6 +495,10 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
494 inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date); 495 inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date);
495 HFSPLUS_I(inode)->create_date = folder->create_date; 496 HFSPLUS_I(inode)->create_date = folder->create_date;
496 HFSPLUS_I(inode)->fs_blocks = 0; 497 HFSPLUS_I(inode)->fs_blocks = 0;
498 if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
499 HFSPLUS_I(inode)->subfolders =
500 be32_to_cpu(folder->subfolders);
501 }
497 inode->i_op = &hfsplus_dir_inode_operations; 502 inode->i_op = &hfsplus_dir_inode_operations;
498 inode->i_fop = &hfsplus_dir_operations; 503 inode->i_fop = &hfsplus_dir_operations;
499 } else if (type == HFSPLUS_FILE) { 504 } else if (type == HFSPLUS_FILE) {
@@ -566,6 +571,10 @@ int hfsplus_cat_write_inode(struct inode *inode)
566 folder->content_mod_date = hfsp_ut2mt(inode->i_mtime); 571 folder->content_mod_date = hfsp_ut2mt(inode->i_mtime);
567 folder->attribute_mod_date = hfsp_ut2mt(inode->i_ctime); 572 folder->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
568 folder->valence = cpu_to_be32(inode->i_size - 2); 573 folder->valence = cpu_to_be32(inode->i_size - 2);
574 if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
575 folder->subfolders =
576 cpu_to_be32(HFSPLUS_I(inode)->subfolders);
577 }
569 hfs_bnode_write(fd.bnode, &entry, fd.entryoffset, 578 hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
570 sizeof(struct hfsplus_cat_folder)); 579 sizeof(struct hfsplus_cat_folder));
571 } else if (HFSPLUS_IS_RSRC(inode)) { 580 } else if (HFSPLUS_IS_RSRC(inode)) {
diff --git a/fs/hfsplus/options.c b/fs/hfsplus/options.c
index 968eab5bc1f5..68537e8b7a09 100644
--- a/fs/hfsplus/options.c
+++ b/fs/hfsplus/options.c
@@ -75,7 +75,7 @@ int hfsplus_parse_options_remount(char *input, int *force)
75 int token; 75 int token;
76 76
77 if (!input) 77 if (!input)
78 return 0; 78 return 1;
79 79
80 while ((p = strsep(&input, ",")) != NULL) { 80 while ((p = strsep(&input, ",")) != NULL) {
81 if (!*p) 81 if (!*p)
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 8360674c85bc..60bb365f54a5 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -514,11 +514,13 @@ int jbd2_journal_start_reserved(handle_t *handle, unsigned int type,
514 * similarly constrained call sites 514 * similarly constrained call sites
515 */ 515 */
516 ret = start_this_handle(journal, handle, GFP_NOFS); 516 ret = start_this_handle(journal, handle, GFP_NOFS);
517 if (ret < 0) 517 if (ret < 0) {
518 jbd2_journal_free_reserved(handle); 518 jbd2_journal_free_reserved(handle);
519 return ret;
520 }
519 handle->h_type = type; 521 handle->h_type = type;
520 handle->h_line_no = line_no; 522 handle->h_line_no = line_no;
521 return ret; 523 return 0;
522} 524}
523EXPORT_SYMBOL(jbd2_journal_start_reserved); 525EXPORT_SYMBOL(jbd2_journal_start_reserved);
524 526
diff --git a/fs/jfs/acl.c b/fs/jfs/acl.c
index e973b85d6afd..5a8ea16eedbc 100644
--- a/fs/jfs/acl.c
+++ b/fs/jfs/acl.c
@@ -86,6 +86,8 @@ static int __jfs_set_acl(tid_t tid, struct inode *inode, int type,
86 rc = posix_acl_equiv_mode(acl, &inode->i_mode); 86 rc = posix_acl_equiv_mode(acl, &inode->i_mode);
87 if (rc < 0) 87 if (rc < 0)
88 return rc; 88 return rc;
89 inode->i_ctime = CURRENT_TIME;
90 mark_inode_dirty(inode);
89 if (rc == 0) 91 if (rc == 0)
90 acl = NULL; 92 acl = NULL;
91 break; 93 break;
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index 3bd5ee45f7b3..46325d5c34fc 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -854,9 +854,6 @@ int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
854 int rc; 854 int rc;
855 tid_t tid; 855 tid_t tid;
856 856
857 if ((rc = can_set_xattr(inode, name, value, value_len)))
858 return rc;
859
860 /* 857 /*
861 * If this is a request for a synthetic attribute in the system.* 858 * If this is a request for a synthetic attribute in the system.*
862 * namespace use the generic infrastructure to resolve a handler 859 * namespace use the generic infrastructure to resolve a handler
@@ -865,6 +862,9 @@ int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
865 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) 862 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
866 return generic_setxattr(dentry, name, value, value_len, flags); 863 return generic_setxattr(dentry, name, value, value_len, flags);
867 864
865 if ((rc = can_set_xattr(inode, name, value, value_len)))
866 return rc;
867
868 if (value == NULL) { /* empty EA, do not remove */ 868 if (value == NULL) { /* empty EA, do not remove */
869 value = ""; 869 value = "";
870 value_len = 0; 870 value_len = 0;
@@ -1034,9 +1034,6 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
1034 int rc; 1034 int rc;
1035 tid_t tid; 1035 tid_t tid;
1036 1036
1037 if ((rc = can_set_xattr(inode, name, NULL, 0)))
1038 return rc;
1039
1040 /* 1037 /*
1041 * If this is a request for a synthetic attribute in the system.* 1038 * If this is a request for a synthetic attribute in the system.*
1042 * namespace use the generic infrastructure to resolve a handler 1039 * namespace use the generic infrastructure to resolve a handler
@@ -1045,6 +1042,9 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
1045 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) 1042 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
1046 return generic_removexattr(dentry, name); 1043 return generic_removexattr(dentry, name);
1047 1044
1045 if ((rc = can_set_xattr(inode, name, NULL, 0)))
1046 return rc;
1047
1048 tid = txBegin(inode->i_sb, 0); 1048 tid = txBegin(inode->i_sb, 0);
1049 mutex_lock(&ji->commit_mutex); 1049 mutex_lock(&ji->commit_mutex);
1050 rc = __jfs_setxattr(tid, dentry->d_inode, name, NULL, 0, XATTR_REPLACE); 1050 rc = __jfs_setxattr(tid, dentry->d_inode, name, NULL, 0, XATTR_REPLACE);
@@ -1061,7 +1061,7 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
1061 * attributes are handled directly. 1061 * attributes are handled directly.
1062 */ 1062 */
1063const struct xattr_handler *jfs_xattr_handlers[] = { 1063const struct xattr_handler *jfs_xattr_handlers[] = {
1064#ifdef JFS_POSIX_ACL 1064#ifdef CONFIG_JFS_POSIX_ACL
1065 &posix_acl_access_xattr_handler, 1065 &posix_acl_access_xattr_handler,
1066 &posix_acl_default_xattr_handler, 1066 &posix_acl_default_xattr_handler,
1067#endif 1067#endif
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 5104cf5d25c5..bd6e18be6e1a 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -187,19 +187,23 @@ static void kernfs_deactivate(struct kernfs_node *kn)
187 187
188 kn->u.completion = (void *)&wait; 188 kn->u.completion = (void *)&wait;
189 189
190 rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_); 190 if (kn->flags & KERNFS_LOCKDEP)
191 rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_);
191 /* atomic_add_return() is a mb(), put_active() will always see 192 /* atomic_add_return() is a mb(), put_active() will always see
192 * the updated kn->u.completion. 193 * the updated kn->u.completion.
193 */ 194 */
194 v = atomic_add_return(KN_DEACTIVATED_BIAS, &kn->active); 195 v = atomic_add_return(KN_DEACTIVATED_BIAS, &kn->active);
195 196
196 if (v != KN_DEACTIVATED_BIAS) { 197 if (v != KN_DEACTIVATED_BIAS) {
197 lock_contended(&kn->dep_map, _RET_IP_); 198 if (kn->flags & KERNFS_LOCKDEP)
199 lock_contended(&kn->dep_map, _RET_IP_);
198 wait_for_completion(&wait); 200 wait_for_completion(&wait);
199 } 201 }
200 202
201 lock_acquired(&kn->dep_map, _RET_IP_); 203 if (kn->flags & KERNFS_LOCKDEP) {
202 rwsem_release(&kn->dep_map, 1, _RET_IP_); 204 lock_acquired(&kn->dep_map, _RET_IP_);
205 rwsem_release(&kn->dep_map, 1, _RET_IP_);
206 }
203} 207}
204 208
205/** 209/**
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 0d6ce895a9ee..0f4152defe7b 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -94,6 +94,7 @@ const void *kernfs_super_ns(struct super_block *sb)
94 * @fs_type: file_system_type of the fs being mounted 94 * @fs_type: file_system_type of the fs being mounted
95 * @flags: mount flags specified for the mount 95 * @flags: mount flags specified for the mount
96 * @root: kernfs_root of the hierarchy being mounted 96 * @root: kernfs_root of the hierarchy being mounted
97 * @new_sb_created: tell the caller if we allocated a new superblock
97 * @ns: optional namespace tag of the mount 98 * @ns: optional namespace tag of the mount
98 * 99 *
99 * This is to be called from each kernfs user's file_system_type->mount() 100 * This is to be called from each kernfs user's file_system_type->mount()
@@ -104,7 +105,8 @@ const void *kernfs_super_ns(struct super_block *sb)
104 * The return value can be passed to the vfs layer verbatim. 105 * The return value can be passed to the vfs layer verbatim.
105 */ 106 */
106struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags, 107struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
107 struct kernfs_root *root, const void *ns) 108 struct kernfs_root *root, bool *new_sb_created,
109 const void *ns)
108{ 110{
109 struct super_block *sb; 111 struct super_block *sb;
110 struct kernfs_super_info *info; 112 struct kernfs_super_info *info;
@@ -122,6 +124,10 @@ struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
122 kfree(info); 124 kfree(info);
123 if (IS_ERR(sb)) 125 if (IS_ERR(sb))
124 return ERR_CAST(sb); 126 return ERR_CAST(sb);
127
128 if (new_sb_created)
129 *new_sb_created = !sb->s_root;
130
125 if (!sb->s_root) { 131 if (!sb->s_root) {
126 error = kernfs_fill_super(sb); 132 error = kernfs_fill_super(sb);
127 if (error) { 133 if (error) {
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index e066a3902973..ab798a88ec1d 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -779,6 +779,7 @@ nlmsvc_grant_blocked(struct nlm_block *block)
779 struct nlm_file *file = block->b_file; 779 struct nlm_file *file = block->b_file;
780 struct nlm_lock *lock = &block->b_call->a_args.lock; 780 struct nlm_lock *lock = &block->b_call->a_args.lock;
781 int error; 781 int error;
782 loff_t fl_start, fl_end;
782 783
783 dprintk("lockd: grant blocked lock %p\n", block); 784 dprintk("lockd: grant blocked lock %p\n", block);
784 785
@@ -796,9 +797,16 @@ nlmsvc_grant_blocked(struct nlm_block *block)
796 } 797 }
797 798
798 /* Try the lock operation again */ 799 /* Try the lock operation again */
800 /* vfs_lock_file() can mangle fl_start and fl_end, but we need
801 * them unchanged for the GRANT_MSG
802 */
799 lock->fl.fl_flags |= FL_SLEEP; 803 lock->fl.fl_flags |= FL_SLEEP;
804 fl_start = lock->fl.fl_start;
805 fl_end = lock->fl.fl_end;
800 error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL); 806 error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL);
801 lock->fl.fl_flags &= ~FL_SLEEP; 807 lock->fl.fl_flags &= ~FL_SLEEP;
808 lock->fl.fl_start = fl_start;
809 lock->fl.fl_end = fl_end;
802 810
803 switch (error) { 811 switch (error) {
804 case 0: 812 case 0:
diff --git a/fs/mount.h b/fs/mount.h
index a17458ca6f29..b29e42f05f34 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -19,13 +19,13 @@ struct mnt_pcp {
19}; 19};
20 20
21struct mountpoint { 21struct mountpoint {
22 struct list_head m_hash; 22 struct hlist_node m_hash;
23 struct dentry *m_dentry; 23 struct dentry *m_dentry;
24 int m_count; 24 int m_count;
25}; 25};
26 26
27struct mount { 27struct mount {
28 struct list_head mnt_hash; 28 struct hlist_node mnt_hash;
29 struct mount *mnt_parent; 29 struct mount *mnt_parent;
30 struct dentry *mnt_mountpoint; 30 struct dentry *mnt_mountpoint;
31 struct vfsmount mnt; 31 struct vfsmount mnt;
diff --git a/fs/namei.c b/fs/namei.c
index d580df2e6804..4b491b431990 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -196,6 +196,7 @@ recopy:
196 goto error; 196 goto error;
197 197
198 result->uptr = filename; 198 result->uptr = filename;
199 result->aname = NULL;
199 audit_getname(result); 200 audit_getname(result);
200 return result; 201 return result;
201 202
@@ -210,6 +211,35 @@ getname(const char __user * filename)
210 return getname_flags(filename, 0, NULL); 211 return getname_flags(filename, 0, NULL);
211} 212}
212 213
214/*
215 * The "getname_kernel()" interface doesn't do pathnames longer
216 * than EMBEDDED_NAME_MAX. Deal with it - you're a kernel user.
217 */
218struct filename *
219getname_kernel(const char * filename)
220{
221 struct filename *result;
222 char *kname;
223 int len;
224
225 len = strlen(filename);
226 if (len >= EMBEDDED_NAME_MAX)
227 return ERR_PTR(-ENAMETOOLONG);
228
229 result = __getname();
230 if (unlikely(!result))
231 return ERR_PTR(-ENOMEM);
232
233 kname = (char *)result + sizeof(*result);
234 result->name = kname;
235 result->uptr = NULL;
236 result->aname = NULL;
237 result->separate = false;
238
239 strlcpy(kname, filename, EMBEDDED_NAME_MAX);
240 return result;
241}
242
213#ifdef CONFIG_AUDITSYSCALL 243#ifdef CONFIG_AUDITSYSCALL
214void putname(struct filename *name) 244void putname(struct filename *name)
215{ 245{
@@ -1079,7 +1109,7 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
1079 return false; 1109 return false;
1080 1110
1081 if (!d_mountpoint(path->dentry)) 1111 if (!d_mountpoint(path->dentry))
1082 break; 1112 return true;
1083 1113
1084 mounted = __lookup_mnt(path->mnt, path->dentry); 1114 mounted = __lookup_mnt(path->mnt, path->dentry);
1085 if (!mounted) 1115 if (!mounted)
@@ -1095,20 +1125,7 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
1095 */ 1125 */
1096 *inode = path->dentry->d_inode; 1126 *inode = path->dentry->d_inode;
1097 } 1127 }
1098 return true; 1128 return read_seqretry(&mount_lock, nd->m_seq);
1099}
1100
1101static void follow_mount_rcu(struct nameidata *nd)
1102{
1103 while (d_mountpoint(nd->path.dentry)) {
1104 struct mount *mounted;
1105 mounted = __lookup_mnt(nd->path.mnt, nd->path.dentry);
1106 if (!mounted)
1107 break;
1108 nd->path.mnt = &mounted->mnt;
1109 nd->path.dentry = mounted->mnt.mnt_root;
1110 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
1111 }
1112} 1129}
1113 1130
1114static int follow_dotdot_rcu(struct nameidata *nd) 1131static int follow_dotdot_rcu(struct nameidata *nd)
@@ -1136,7 +1153,17 @@ static int follow_dotdot_rcu(struct nameidata *nd)
1136 break; 1153 break;
1137 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); 1154 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
1138 } 1155 }
1139 follow_mount_rcu(nd); 1156 while (d_mountpoint(nd->path.dentry)) {
1157 struct mount *mounted;
1158 mounted = __lookup_mnt(nd->path.mnt, nd->path.dentry);
1159 if (!mounted)
1160 break;
1161 nd->path.mnt = &mounted->mnt;
1162 nd->path.dentry = mounted->mnt.mnt_root;
1163 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
1164 if (!read_seqretry(&mount_lock, nd->m_seq))
1165 goto failed;
1166 }
1140 nd->inode = nd->path.dentry->d_inode; 1167 nd->inode = nd->path.dentry->d_inode;
1141 return 0; 1168 return 0;
1142 1169
@@ -1854,7 +1881,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
1854 1881
1855 nd->path = f.file->f_path; 1882 nd->path = f.file->f_path;
1856 if (flags & LOOKUP_RCU) { 1883 if (flags & LOOKUP_RCU) {
1857 if (f.need_put) 1884 if (f.flags & FDPUT_FPUT)
1858 *fp = f.file; 1885 *fp = f.file;
1859 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); 1886 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
1860 rcu_read_lock(); 1887 rcu_read_lock();
diff --git a/fs/namespace.c b/fs/namespace.c
index 22e536705c45..2ffc5a2905d4 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -23,11 +23,34 @@
23#include <linux/uaccess.h> 23#include <linux/uaccess.h>
24#include <linux/proc_ns.h> 24#include <linux/proc_ns.h>
25#include <linux/magic.h> 25#include <linux/magic.h>
26#include <linux/bootmem.h>
26#include "pnode.h" 27#include "pnode.h"
27#include "internal.h" 28#include "internal.h"
28 29
29#define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head)) 30static unsigned int m_hash_mask __read_mostly;
30#define HASH_SIZE (1UL << HASH_SHIFT) 31static unsigned int m_hash_shift __read_mostly;
32static unsigned int mp_hash_mask __read_mostly;
33static unsigned int mp_hash_shift __read_mostly;
34
35static __initdata unsigned long mhash_entries;
36static int __init set_mhash_entries(char *str)
37{
38 if (!str)
39 return 0;
40 mhash_entries = simple_strtoul(str, &str, 0);
41 return 1;
42}
43__setup("mhash_entries=", set_mhash_entries);
44
45static __initdata unsigned long mphash_entries;
46static int __init set_mphash_entries(char *str)
47{
48 if (!str)
49 return 0;
50 mphash_entries = simple_strtoul(str, &str, 0);
51 return 1;
52}
53__setup("mphash_entries=", set_mphash_entries);
31 54
32static int event; 55static int event;
33static DEFINE_IDA(mnt_id_ida); 56static DEFINE_IDA(mnt_id_ida);
@@ -36,8 +59,8 @@ static DEFINE_SPINLOCK(mnt_id_lock);
36static int mnt_id_start = 0; 59static int mnt_id_start = 0;
37static int mnt_group_start = 1; 60static int mnt_group_start = 1;
38 61
39static struct list_head *mount_hashtable __read_mostly; 62static struct hlist_head *mount_hashtable __read_mostly;
40static struct list_head *mountpoint_hashtable __read_mostly; 63static struct hlist_head *mountpoint_hashtable __read_mostly;
41static struct kmem_cache *mnt_cache __read_mostly; 64static struct kmem_cache *mnt_cache __read_mostly;
42static DECLARE_RWSEM(namespace_sem); 65static DECLARE_RWSEM(namespace_sem);
43 66
@@ -55,12 +78,19 @@ EXPORT_SYMBOL_GPL(fs_kobj);
55 */ 78 */
56__cacheline_aligned_in_smp DEFINE_SEQLOCK(mount_lock); 79__cacheline_aligned_in_smp DEFINE_SEQLOCK(mount_lock);
57 80
58static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry) 81static inline struct hlist_head *m_hash(struct vfsmount *mnt, struct dentry *dentry)
59{ 82{
60 unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES); 83 unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES);
61 tmp += ((unsigned long)dentry / L1_CACHE_BYTES); 84 tmp += ((unsigned long)dentry / L1_CACHE_BYTES);
62 tmp = tmp + (tmp >> HASH_SHIFT); 85 tmp = tmp + (tmp >> m_hash_shift);
63 return tmp & (HASH_SIZE - 1); 86 return &mount_hashtable[tmp & m_hash_mask];
87}
88
89static inline struct hlist_head *mp_hash(struct dentry *dentry)
90{
91 unsigned long tmp = ((unsigned long)dentry / L1_CACHE_BYTES);
92 tmp = tmp + (tmp >> mp_hash_shift);
93 return &mountpoint_hashtable[tmp & mp_hash_mask];
64} 94}
65 95
66/* 96/*
@@ -187,7 +217,7 @@ static struct mount *alloc_vfsmnt(const char *name)
187 mnt->mnt_writers = 0; 217 mnt->mnt_writers = 0;
188#endif 218#endif
189 219
190 INIT_LIST_HEAD(&mnt->mnt_hash); 220 INIT_HLIST_NODE(&mnt->mnt_hash);
191 INIT_LIST_HEAD(&mnt->mnt_child); 221 INIT_LIST_HEAD(&mnt->mnt_child);
192 INIT_LIST_HEAD(&mnt->mnt_mounts); 222 INIT_LIST_HEAD(&mnt->mnt_mounts);
193 INIT_LIST_HEAD(&mnt->mnt_list); 223 INIT_LIST_HEAD(&mnt->mnt_list);
@@ -575,10 +605,10 @@ bool legitimize_mnt(struct vfsmount *bastard, unsigned seq)
575 */ 605 */
576struct mount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry) 606struct mount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
577{ 607{
578 struct list_head *head = mount_hashtable + hash(mnt, dentry); 608 struct hlist_head *head = m_hash(mnt, dentry);
579 struct mount *p; 609 struct mount *p;
580 610
581 list_for_each_entry_rcu(p, head, mnt_hash) 611 hlist_for_each_entry_rcu(p, head, mnt_hash)
582 if (&p->mnt_parent->mnt == mnt && p->mnt_mountpoint == dentry) 612 if (&p->mnt_parent->mnt == mnt && p->mnt_mountpoint == dentry)
583 return p; 613 return p;
584 return NULL; 614 return NULL;
@@ -590,13 +620,17 @@ struct mount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
590 */ 620 */
591struct mount *__lookup_mnt_last(struct vfsmount *mnt, struct dentry *dentry) 621struct mount *__lookup_mnt_last(struct vfsmount *mnt, struct dentry *dentry)
592{ 622{
593 struct list_head *head = mount_hashtable + hash(mnt, dentry); 623 struct mount *p, *res;
594 struct mount *p; 624 res = p = __lookup_mnt(mnt, dentry);
595 625 if (!p)
596 list_for_each_entry_reverse(p, head, mnt_hash) 626 goto out;
597 if (&p->mnt_parent->mnt == mnt && p->mnt_mountpoint == dentry) 627 hlist_for_each_entry_continue(p, mnt_hash) {
598 return p; 628 if (&p->mnt_parent->mnt != mnt || p->mnt_mountpoint != dentry)
599 return NULL; 629 break;
630 res = p;
631 }
632out:
633 return res;
600} 634}
601 635
602/* 636/*
@@ -633,11 +667,11 @@ struct vfsmount *lookup_mnt(struct path *path)
633 667
634static struct mountpoint *new_mountpoint(struct dentry *dentry) 668static struct mountpoint *new_mountpoint(struct dentry *dentry)
635{ 669{
636 struct list_head *chain = mountpoint_hashtable + hash(NULL, dentry); 670 struct hlist_head *chain = mp_hash(dentry);
637 struct mountpoint *mp; 671 struct mountpoint *mp;
638 int ret; 672 int ret;
639 673
640 list_for_each_entry(mp, chain, m_hash) { 674 hlist_for_each_entry(mp, chain, m_hash) {
641 if (mp->m_dentry == dentry) { 675 if (mp->m_dentry == dentry) {
642 /* might be worth a WARN_ON() */ 676 /* might be worth a WARN_ON() */
643 if (d_unlinked(dentry)) 677 if (d_unlinked(dentry))
@@ -659,7 +693,7 @@ static struct mountpoint *new_mountpoint(struct dentry *dentry)
659 693
660 mp->m_dentry = dentry; 694 mp->m_dentry = dentry;
661 mp->m_count = 1; 695 mp->m_count = 1;
662 list_add(&mp->m_hash, chain); 696 hlist_add_head(&mp->m_hash, chain);
663 return mp; 697 return mp;
664} 698}
665 699
@@ -670,7 +704,7 @@ static void put_mountpoint(struct mountpoint *mp)
670 spin_lock(&dentry->d_lock); 704 spin_lock(&dentry->d_lock);
671 dentry->d_flags &= ~DCACHE_MOUNTED; 705 dentry->d_flags &= ~DCACHE_MOUNTED;
672 spin_unlock(&dentry->d_lock); 706 spin_unlock(&dentry->d_lock);
673 list_del(&mp->m_hash); 707 hlist_del(&mp->m_hash);
674 kfree(mp); 708 kfree(mp);
675 } 709 }
676} 710}
@@ -712,7 +746,7 @@ static void detach_mnt(struct mount *mnt, struct path *old_path)
712 mnt->mnt_parent = mnt; 746 mnt->mnt_parent = mnt;
713 mnt->mnt_mountpoint = mnt->mnt.mnt_root; 747 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
714 list_del_init(&mnt->mnt_child); 748 list_del_init(&mnt->mnt_child);
715 list_del_init(&mnt->mnt_hash); 749 hlist_del_init_rcu(&mnt->mnt_hash);
716 put_mountpoint(mnt->mnt_mp); 750 put_mountpoint(mnt->mnt_mp);
717 mnt->mnt_mp = NULL; 751 mnt->mnt_mp = NULL;
718} 752}
@@ -739,15 +773,14 @@ static void attach_mnt(struct mount *mnt,
739 struct mountpoint *mp) 773 struct mountpoint *mp)
740{ 774{
741 mnt_set_mountpoint(parent, mp, mnt); 775 mnt_set_mountpoint(parent, mp, mnt);
742 list_add_tail(&mnt->mnt_hash, mount_hashtable + 776 hlist_add_head_rcu(&mnt->mnt_hash, m_hash(&parent->mnt, mp->m_dentry));
743 hash(&parent->mnt, mp->m_dentry));
744 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts); 777 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts);
745} 778}
746 779
747/* 780/*
748 * vfsmount lock must be held for write 781 * vfsmount lock must be held for write
749 */ 782 */
750static void commit_tree(struct mount *mnt) 783static void commit_tree(struct mount *mnt, struct mount *shadows)
751{ 784{
752 struct mount *parent = mnt->mnt_parent; 785 struct mount *parent = mnt->mnt_parent;
753 struct mount *m; 786 struct mount *m;
@@ -762,8 +795,11 @@ static void commit_tree(struct mount *mnt)
762 795
763 list_splice(&head, n->list.prev); 796 list_splice(&head, n->list.prev);
764 797
765 list_add_tail(&mnt->mnt_hash, mount_hashtable + 798 if (shadows)
766 hash(&parent->mnt, mnt->mnt_mountpoint)); 799 hlist_add_after_rcu(&shadows->mnt_hash, &mnt->mnt_hash);
800 else
801 hlist_add_head_rcu(&mnt->mnt_hash,
802 m_hash(&parent->mnt, mnt->mnt_mountpoint));
767 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts); 803 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts);
768 touch_mnt_namespace(n); 804 touch_mnt_namespace(n);
769} 805}
@@ -1153,26 +1189,28 @@ int may_umount(struct vfsmount *mnt)
1153 1189
1154EXPORT_SYMBOL(may_umount); 1190EXPORT_SYMBOL(may_umount);
1155 1191
1156static LIST_HEAD(unmounted); /* protected by namespace_sem */ 1192static HLIST_HEAD(unmounted); /* protected by namespace_sem */
1157 1193
1158static void namespace_unlock(void) 1194static void namespace_unlock(void)
1159{ 1195{
1160 struct mount *mnt; 1196 struct mount *mnt;
1161 LIST_HEAD(head); 1197 struct hlist_head head = unmounted;
1162 1198
1163 if (likely(list_empty(&unmounted))) { 1199 if (likely(hlist_empty(&head))) {
1164 up_write(&namespace_sem); 1200 up_write(&namespace_sem);
1165 return; 1201 return;
1166 } 1202 }
1167 1203
1168 list_splice_init(&unmounted, &head); 1204 head.first->pprev = &head.first;
1205 INIT_HLIST_HEAD(&unmounted);
1206
1169 up_write(&namespace_sem); 1207 up_write(&namespace_sem);
1170 1208
1171 synchronize_rcu(); 1209 synchronize_rcu();
1172 1210
1173 while (!list_empty(&head)) { 1211 while (!hlist_empty(&head)) {
1174 mnt = list_first_entry(&head, struct mount, mnt_hash); 1212 mnt = hlist_entry(head.first, struct mount, mnt_hash);
1175 list_del_init(&mnt->mnt_hash); 1213 hlist_del_init(&mnt->mnt_hash);
1176 if (mnt->mnt_ex_mountpoint.mnt) 1214 if (mnt->mnt_ex_mountpoint.mnt)
1177 path_put(&mnt->mnt_ex_mountpoint); 1215 path_put(&mnt->mnt_ex_mountpoint);
1178 mntput(&mnt->mnt); 1216 mntput(&mnt->mnt);
@@ -1193,16 +1231,19 @@ static inline void namespace_lock(void)
1193 */ 1231 */
1194void umount_tree(struct mount *mnt, int how) 1232void umount_tree(struct mount *mnt, int how)
1195{ 1233{
1196 LIST_HEAD(tmp_list); 1234 HLIST_HEAD(tmp_list);
1197 struct mount *p; 1235 struct mount *p;
1236 struct mount *last = NULL;
1198 1237
1199 for (p = mnt; p; p = next_mnt(p, mnt)) 1238 for (p = mnt; p; p = next_mnt(p, mnt)) {
1200 list_move(&p->mnt_hash, &tmp_list); 1239 hlist_del_init_rcu(&p->mnt_hash);
1240 hlist_add_head(&p->mnt_hash, &tmp_list);
1241 }
1201 1242
1202 if (how) 1243 if (how)
1203 propagate_umount(&tmp_list); 1244 propagate_umount(&tmp_list);
1204 1245
1205 list_for_each_entry(p, &tmp_list, mnt_hash) { 1246 hlist_for_each_entry(p, &tmp_list, mnt_hash) {
1206 list_del_init(&p->mnt_expire); 1247 list_del_init(&p->mnt_expire);
1207 list_del_init(&p->mnt_list); 1248 list_del_init(&p->mnt_list);
1208 __touch_mnt_namespace(p->mnt_ns); 1249 __touch_mnt_namespace(p->mnt_ns);
@@ -1220,8 +1261,13 @@ void umount_tree(struct mount *mnt, int how)
1220 p->mnt_mp = NULL; 1261 p->mnt_mp = NULL;
1221 } 1262 }
1222 change_mnt_propagation(p, MS_PRIVATE); 1263 change_mnt_propagation(p, MS_PRIVATE);
1264 last = p;
1265 }
1266 if (last) {
1267 last->mnt_hash.next = unmounted.first;
1268 unmounted.first = tmp_list.first;
1269 unmounted.first->pprev = &unmounted.first;
1223 } 1270 }
1224 list_splice(&tmp_list, &unmounted);
1225} 1271}
1226 1272
1227static void shrink_submounts(struct mount *mnt); 1273static void shrink_submounts(struct mount *mnt);
@@ -1605,24 +1651,23 @@ static int attach_recursive_mnt(struct mount *source_mnt,
1605 struct mountpoint *dest_mp, 1651 struct mountpoint *dest_mp,
1606 struct path *parent_path) 1652 struct path *parent_path)
1607{ 1653{
1608 LIST_HEAD(tree_list); 1654 HLIST_HEAD(tree_list);
1609 struct mount *child, *p; 1655 struct mount *child, *p;
1656 struct hlist_node *n;
1610 int err; 1657 int err;
1611 1658
1612 if (IS_MNT_SHARED(dest_mnt)) { 1659 if (IS_MNT_SHARED(dest_mnt)) {
1613 err = invent_group_ids(source_mnt, true); 1660 err = invent_group_ids(source_mnt, true);
1614 if (err) 1661 if (err)
1615 goto out; 1662 goto out;
1616 } 1663 err = propagate_mnt(dest_mnt, dest_mp, source_mnt, &tree_list);
1617 err = propagate_mnt(dest_mnt, dest_mp, source_mnt, &tree_list); 1664 if (err)
1618 if (err) 1665 goto out_cleanup_ids;
1619 goto out_cleanup_ids; 1666 lock_mount_hash();
1620
1621 lock_mount_hash();
1622
1623 if (IS_MNT_SHARED(dest_mnt)) {
1624 for (p = source_mnt; p; p = next_mnt(p, source_mnt)) 1667 for (p = source_mnt; p; p = next_mnt(p, source_mnt))
1625 set_mnt_shared(p); 1668 set_mnt_shared(p);
1669 } else {
1670 lock_mount_hash();
1626 } 1671 }
1627 if (parent_path) { 1672 if (parent_path) {
1628 detach_mnt(source_mnt, parent_path); 1673 detach_mnt(source_mnt, parent_path);
@@ -1630,20 +1675,22 @@ static int attach_recursive_mnt(struct mount *source_mnt,
1630 touch_mnt_namespace(source_mnt->mnt_ns); 1675 touch_mnt_namespace(source_mnt->mnt_ns);
1631 } else { 1676 } else {
1632 mnt_set_mountpoint(dest_mnt, dest_mp, source_mnt); 1677 mnt_set_mountpoint(dest_mnt, dest_mp, source_mnt);
1633 commit_tree(source_mnt); 1678 commit_tree(source_mnt, NULL);
1634 } 1679 }
1635 1680
1636 list_for_each_entry_safe(child, p, &tree_list, mnt_hash) { 1681 hlist_for_each_entry_safe(child, n, &tree_list, mnt_hash) {
1637 list_del_init(&child->mnt_hash); 1682 struct mount *q;
1638 commit_tree(child); 1683 hlist_del_init(&child->mnt_hash);
1684 q = __lookup_mnt_last(&child->mnt_parent->mnt,
1685 child->mnt_mountpoint);
1686 commit_tree(child, q);
1639 } 1687 }
1640 unlock_mount_hash(); 1688 unlock_mount_hash();
1641 1689
1642 return 0; 1690 return 0;
1643 1691
1644 out_cleanup_ids: 1692 out_cleanup_ids:
1645 if (IS_MNT_SHARED(dest_mnt)) 1693 cleanup_group_ids(source_mnt, NULL);
1646 cleanup_group_ids(source_mnt, NULL);
1647 out: 1694 out:
1648 return err; 1695 return err;
1649} 1696}
@@ -2777,18 +2824,24 @@ void __init mnt_init(void)
2777 mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct mount), 2824 mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct mount),
2778 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); 2825 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
2779 2826
2780 mount_hashtable = (struct list_head *)__get_free_page(GFP_ATOMIC); 2827 mount_hashtable = alloc_large_system_hash("Mount-cache",
2781 mountpoint_hashtable = (struct list_head *)__get_free_page(GFP_ATOMIC); 2828 sizeof(struct hlist_head),
2829 mhash_entries, 19,
2830 0,
2831 &m_hash_shift, &m_hash_mask, 0, 0);
2832 mountpoint_hashtable = alloc_large_system_hash("Mountpoint-cache",
2833 sizeof(struct hlist_head),
2834 mphash_entries, 19,
2835 0,
2836 &mp_hash_shift, &mp_hash_mask, 0, 0);
2782 2837
2783 if (!mount_hashtable || !mountpoint_hashtable) 2838 if (!mount_hashtable || !mountpoint_hashtable)
2784 panic("Failed to allocate mount hash table\n"); 2839 panic("Failed to allocate mount hash table\n");
2785 2840
2786 printk(KERN_INFO "Mount-cache hash table entries: %lu\n", HASH_SIZE); 2841 for (u = 0; u <= m_hash_mask; u++)
2787 2842 INIT_HLIST_HEAD(&mount_hashtable[u]);
2788 for (u = 0; u < HASH_SIZE; u++) 2843 for (u = 0; u <= mp_hash_mask; u++)
2789 INIT_LIST_HEAD(&mount_hashtable[u]); 2844 INIT_HLIST_HEAD(&mountpoint_hashtable[u]);
2790 for (u = 0; u < HASH_SIZE; u++)
2791 INIT_LIST_HEAD(&mountpoint_hashtable[u]);
2792 2845
2793 kernfs_init(); 2846 kernfs_init();
2794 2847
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index ef792f29f831..5d8ccecf5f5c 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -659,16 +659,19 @@ int nfs_async_inode_return_delegation(struct inode *inode,
659 659
660 rcu_read_lock(); 660 rcu_read_lock();
661 delegation = rcu_dereference(NFS_I(inode)->delegation); 661 delegation = rcu_dereference(NFS_I(inode)->delegation);
662 if (delegation == NULL)
663 goto out_enoent;
662 664
663 if (!clp->cl_mvops->match_stateid(&delegation->stateid, stateid)) { 665 if (!clp->cl_mvops->match_stateid(&delegation->stateid, stateid))
664 rcu_read_unlock(); 666 goto out_enoent;
665 return -ENOENT;
666 }
667 nfs_mark_return_delegation(server, delegation); 667 nfs_mark_return_delegation(server, delegation);
668 rcu_read_unlock(); 668 rcu_read_unlock();
669 669
670 nfs_delegation_run_state_manager(clp); 670 nfs_delegation_run_state_manager(clp);
671 return 0; 671 return 0;
672out_enoent:
673 rcu_read_unlock();
674 return -ENOENT;
672} 675}
673 676
674static struct inode * 677static struct inode *
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index be38b573495a..4a48fe4b84b6 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1846,6 +1846,11 @@ int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1846 GFP_KERNEL)) { 1846 GFP_KERNEL)) {
1847 SetPageUptodate(page); 1847 SetPageUptodate(page);
1848 unlock_page(page); 1848 unlock_page(page);
1849 /*
1850 * add_to_page_cache_lru() grabs an extra page refcount.
1851 * Drop it here to avoid leaking this page later.
1852 */
1853 page_cache_release(page);
1849 } else 1854 } else
1850 __free_page(page); 1855 __free_page(page);
1851 1856
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 28a0a3cbd3b7..360114ae8b82 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -164,17 +164,16 @@ static void nfs_zap_caches_locked(struct inode *inode)
164 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) { 164 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) {
165 nfs_fscache_invalidate(inode); 165 nfs_fscache_invalidate(inode);
166 nfsi->cache_validity |= NFS_INO_INVALID_ATTR 166 nfsi->cache_validity |= NFS_INO_INVALID_ATTR
167 | NFS_INO_INVALID_LABEL
168 | NFS_INO_INVALID_DATA 167 | NFS_INO_INVALID_DATA
169 | NFS_INO_INVALID_ACCESS 168 | NFS_INO_INVALID_ACCESS
170 | NFS_INO_INVALID_ACL 169 | NFS_INO_INVALID_ACL
171 | NFS_INO_REVAL_PAGECACHE; 170 | NFS_INO_REVAL_PAGECACHE;
172 } else 171 } else
173 nfsi->cache_validity |= NFS_INO_INVALID_ATTR 172 nfsi->cache_validity |= NFS_INO_INVALID_ATTR
174 | NFS_INO_INVALID_LABEL
175 | NFS_INO_INVALID_ACCESS 173 | NFS_INO_INVALID_ACCESS
176 | NFS_INO_INVALID_ACL 174 | NFS_INO_INVALID_ACL
177 | NFS_INO_REVAL_PAGECACHE; 175 | NFS_INO_REVAL_PAGECACHE;
176 nfs_zap_label_cache_locked(nfsi);
178} 177}
179 178
180void nfs_zap_caches(struct inode *inode) 179void nfs_zap_caches(struct inode *inode)
@@ -266,6 +265,13 @@ nfs_init_locked(struct inode *inode, void *opaque)
266} 265}
267 266
268#ifdef CONFIG_NFS_V4_SECURITY_LABEL 267#ifdef CONFIG_NFS_V4_SECURITY_LABEL
268static void nfs_clear_label_invalid(struct inode *inode)
269{
270 spin_lock(&inode->i_lock);
271 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_LABEL;
272 spin_unlock(&inode->i_lock);
273}
274
269void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr, 275void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
270 struct nfs4_label *label) 276 struct nfs4_label *label)
271{ 277{
@@ -283,6 +289,7 @@ void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
283 __func__, 289 __func__,
284 (char *)label->label, 290 (char *)label->label,
285 label->len, error); 291 label->len, error);
292 nfs_clear_label_invalid(inode);
286 } 293 }
287} 294}
288 295
@@ -1648,7 +1655,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1648 inode->i_blocks = fattr->du.nfs2.blocks; 1655 inode->i_blocks = fattr->du.nfs2.blocks;
1649 1656
1650 /* Update attrtimeo value if we're out of the unstable period */ 1657 /* Update attrtimeo value if we're out of the unstable period */
1651 if (invalid & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_LABEL)) { 1658 if (invalid & NFS_INO_INVALID_ATTR) {
1652 nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE); 1659 nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
1653 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); 1660 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
1654 nfsi->attrtimeo_timestamp = now; 1661 nfsi->attrtimeo_timestamp = now;
@@ -1661,7 +1668,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1661 } 1668 }
1662 } 1669 }
1663 invalid &= ~NFS_INO_INVALID_ATTR; 1670 invalid &= ~NFS_INO_INVALID_ATTR;
1664 invalid &= ~NFS_INO_INVALID_LABEL;
1665 /* Don't invalidate the data if we were to blame */ 1671 /* Don't invalidate the data if we were to blame */
1666 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) 1672 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
1667 || S_ISLNK(inode->i_mode))) 1673 || S_ISLNK(inode->i_mode)))
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 8b5cc04a8611..b46cf5a67329 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -176,7 +176,8 @@ extern struct nfs_server *nfs4_create_server(
176extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, 176extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
177 struct nfs_fh *); 177 struct nfs_fh *);
178extern int nfs4_update_server(struct nfs_server *server, const char *hostname, 178extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
179 struct sockaddr *sap, size_t salen); 179 struct sockaddr *sap, size_t salen,
180 struct net *net);
180extern void nfs_free_server(struct nfs_server *server); 181extern void nfs_free_server(struct nfs_server *server);
181extern struct nfs_server *nfs_clone_server(struct nfs_server *, 182extern struct nfs_server *nfs_clone_server(struct nfs_server *,
182 struct nfs_fh *, 183 struct nfs_fh *,
@@ -279,9 +280,18 @@ static inline void nfs4_label_free(struct nfs4_label *label)
279 } 280 }
280 return; 281 return;
281} 282}
283
284static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
285{
286 if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
287 nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
288}
282#else 289#else
283static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; } 290static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
284static inline void nfs4_label_free(void *label) {} 291static inline void nfs4_label_free(void *label) {}
292static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
293{
294}
285#endif /* CONFIG_NFS_V4_SECURITY_LABEL */ 295#endif /* CONFIG_NFS_V4_SECURITY_LABEL */
286 296
287/* proc.c */ 297/* proc.c */
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index 9a5ca03fa539..871d6eda8dba 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -80,7 +80,7 @@ struct posix_acl *nfs3_get_acl(struct inode *inode, int type)
80 } 80 }
81 81
82 if (res.acl_access != NULL) { 82 if (res.acl_access != NULL) {
83 if (posix_acl_equiv_mode(res.acl_access, NULL) || 83 if ((posix_acl_equiv_mode(res.acl_access, NULL) == 0) ||
84 res.acl_access->a_count == 0) { 84 res.acl_access->a_count == 0) {
85 posix_acl_release(res.acl_access); 85 posix_acl_release(res.acl_access);
86 res.acl_access = NULL; 86 res.acl_access = NULL;
@@ -113,7 +113,7 @@ getout:
113 return ERR_PTR(status); 113 return ERR_PTR(status);
114} 114}
115 115
116int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl, 116static int __nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
117 struct posix_acl *dfacl) 117 struct posix_acl *dfacl)
118{ 118{
119 struct nfs_server *server = NFS_SERVER(inode); 119 struct nfs_server *server = NFS_SERVER(inode);
@@ -198,6 +198,15 @@ out:
198 return status; 198 return status;
199} 199}
200 200
201int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
202 struct posix_acl *dfacl)
203{
204 int ret;
205 ret = __nfs3_proc_setacls(inode, acl, dfacl);
206 return (ret == -EOPNOTSUPP) ? 0 : ret;
207
208}
209
201int nfs3_set_acl(struct inode *inode, struct posix_acl *acl, int type) 210int nfs3_set_acl(struct inode *inode, struct posix_acl *acl, int type)
202{ 211{
203 struct posix_acl *alloc = NULL, *dfacl = NULL; 212 struct posix_acl *alloc = NULL, *dfacl = NULL;
@@ -225,7 +234,7 @@ int nfs3_set_acl(struct inode *inode, struct posix_acl *acl, int type)
225 if (IS_ERR(alloc)) 234 if (IS_ERR(alloc))
226 goto fail; 235 goto fail;
227 } 236 }
228 status = nfs3_proc_setacls(inode, acl, dfacl); 237 status = __nfs3_proc_setacls(inode, acl, dfacl);
229 posix_acl_release(alloc); 238 posix_acl_release(alloc);
230 return status; 239 return status;
231 240
@@ -233,25 +242,6 @@ fail:
233 return PTR_ERR(alloc); 242 return PTR_ERR(alloc);
234} 243}
235 244
236int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode,
237 umode_t mode)
238{
239 struct posix_acl *default_acl, *acl;
240 int error;
241
242 error = posix_acl_create(dir, &mode, &default_acl, &acl);
243 if (error)
244 return (error == -EOPNOTSUPP) ? 0 : error;
245
246 error = nfs3_proc_setacls(inode, acl, default_acl);
247
248 if (acl)
249 posix_acl_release(acl);
250 if (default_acl)
251 posix_acl_release(default_acl);
252 return error;
253}
254
255const struct xattr_handler *nfs3_xattr_handlers[] = { 245const struct xattr_handler *nfs3_xattr_handlers[] = {
256 &posix_acl_access_xattr_handler, 246 &posix_acl_access_xattr_handler,
257 &posix_acl_default_xattr_handler, 247 &posix_acl_default_xattr_handler,
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index aa9bc973f36a..a462ef0fb5d6 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -18,6 +18,7 @@
18#include <linux/lockd/bind.h> 18#include <linux/lockd/bind.h>
19#include <linux/nfs_mount.h> 19#include <linux/nfs_mount.h>
20#include <linux/freezer.h> 20#include <linux/freezer.h>
21#include <linux/xattr.h>
21 22
22#include "iostat.h" 23#include "iostat.h"
23#include "internal.h" 24#include "internal.h"
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
index dbb3e1f30c68..0e46d3d1b6cc 100644
--- a/fs/nfs/nfs4client.c
+++ b/fs/nfs/nfs4client.c
@@ -170,7 +170,7 @@ void nfs41_shutdown_client(struct nfs_client *clp)
170void nfs40_shutdown_client(struct nfs_client *clp) 170void nfs40_shutdown_client(struct nfs_client *clp)
171{ 171{
172 if (clp->cl_slot_tbl) { 172 if (clp->cl_slot_tbl) {
173 nfs4_release_slot_table(clp->cl_slot_tbl); 173 nfs4_shutdown_slot_table(clp->cl_slot_tbl);
174 kfree(clp->cl_slot_tbl); 174 kfree(clp->cl_slot_tbl);
175 } 175 }
176} 176}
@@ -1135,6 +1135,7 @@ static int nfs_probe_destination(struct nfs_server *server)
1135 * @hostname: new end-point's hostname 1135 * @hostname: new end-point's hostname
1136 * @sap: new end-point's socket address 1136 * @sap: new end-point's socket address
1137 * @salen: size of "sap" 1137 * @salen: size of "sap"
1138 * @net: net namespace
1138 * 1139 *
1139 * The nfs_server must be quiescent before this function is invoked. 1140 * The nfs_server must be quiescent before this function is invoked.
1140 * Either its session is drained (NFSv4.1+), or its transport is 1141 * Either its session is drained (NFSv4.1+), or its transport is
@@ -1143,13 +1144,13 @@ static int nfs_probe_destination(struct nfs_server *server)
1143 * Returns zero on success, or a negative errno value. 1144 * Returns zero on success, or a negative errno value.
1144 */ 1145 */
1145int nfs4_update_server(struct nfs_server *server, const char *hostname, 1146int nfs4_update_server(struct nfs_server *server, const char *hostname,
1146 struct sockaddr *sap, size_t salen) 1147 struct sockaddr *sap, size_t salen, struct net *net)
1147{ 1148{
1148 struct nfs_client *clp = server->nfs_client; 1149 struct nfs_client *clp = server->nfs_client;
1149 struct rpc_clnt *clnt = server->client; 1150 struct rpc_clnt *clnt = server->client;
1150 struct xprt_create xargs = { 1151 struct xprt_create xargs = {
1151 .ident = clp->cl_proto, 1152 .ident = clp->cl_proto,
1152 .net = &init_net, 1153 .net = net,
1153 .dstaddr = sap, 1154 .dstaddr = sap,
1154 .addrlen = salen, 1155 .addrlen = salen,
1155 .servername = hostname, 1156 .servername = hostname,
@@ -1189,7 +1190,7 @@ int nfs4_update_server(struct nfs_server *server, const char *hostname,
1189 error = nfs4_set_client(server, hostname, sap, salen, buf, 1190 error = nfs4_set_client(server, hostname, sap, salen, buf,
1190 clp->cl_rpcclient->cl_auth->au_flavor, 1191 clp->cl_rpcclient->cl_auth->au_flavor,
1191 clp->cl_proto, clnt->cl_timeout, 1192 clp->cl_proto, clnt->cl_timeout,
1192 clp->cl_minorversion, clp->cl_net); 1193 clp->cl_minorversion, net);
1193 nfs_put_client(clp); 1194 nfs_put_client(clp);
1194 if (error != 0) { 1195 if (error != 0) {
1195 nfs_server_insert_lists(server); 1196 nfs_server_insert_lists(server);
diff --git a/fs/nfs/nfs4filelayout.c b/fs/nfs/nfs4filelayout.c
index 12c8132ad408..b9a35c05b60f 100644
--- a/fs/nfs/nfs4filelayout.c
+++ b/fs/nfs/nfs4filelayout.c
@@ -324,8 +324,9 @@ static void filelayout_read_prepare(struct rpc_task *task, void *data)
324 &rdata->res.seq_res, 324 &rdata->res.seq_res,
325 task)) 325 task))
326 return; 326 return;
327 nfs4_set_rw_stateid(&rdata->args.stateid, rdata->args.context, 327 if (nfs4_set_rw_stateid(&rdata->args.stateid, rdata->args.context,
328 rdata->args.lock_context, FMODE_READ); 328 rdata->args.lock_context, FMODE_READ) == -EIO)
329 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
329} 330}
330 331
331static void filelayout_read_call_done(struct rpc_task *task, void *data) 332static void filelayout_read_call_done(struct rpc_task *task, void *data)
@@ -435,8 +436,9 @@ static void filelayout_write_prepare(struct rpc_task *task, void *data)
435 &wdata->res.seq_res, 436 &wdata->res.seq_res,
436 task)) 437 task))
437 return; 438 return;
438 nfs4_set_rw_stateid(&wdata->args.stateid, wdata->args.context, 439 if (nfs4_set_rw_stateid(&wdata->args.stateid, wdata->args.context,
439 wdata->args.lock_context, FMODE_WRITE); 440 wdata->args.lock_context, FMODE_WRITE) == -EIO)
441 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
440} 442}
441 443
442static void filelayout_write_call_done(struct rpc_task *task, void *data) 444static void filelayout_write_call_done(struct rpc_task *task, void *data)
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 4e7f05d3e9db..3d5dbf80d46a 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -121,9 +121,8 @@ static int nfs4_validate_fspath(struct dentry *dentry,
121} 121}
122 122
123static size_t nfs_parse_server_name(char *string, size_t len, 123static size_t nfs_parse_server_name(char *string, size_t len,
124 struct sockaddr *sa, size_t salen, struct nfs_server *server) 124 struct sockaddr *sa, size_t salen, struct net *net)
125{ 125{
126 struct net *net = rpc_net_ns(server->client);
127 ssize_t ret; 126 ssize_t ret;
128 127
129 ret = rpc_pton(net, string, len, sa, salen); 128 ret = rpc_pton(net, string, len, sa, salen);
@@ -223,6 +222,7 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
223 const struct nfs4_fs_location *location) 222 const struct nfs4_fs_location *location)
224{ 223{
225 const size_t addr_bufsize = sizeof(struct sockaddr_storage); 224 const size_t addr_bufsize = sizeof(struct sockaddr_storage);
225 struct net *net = rpc_net_ns(NFS_SB(mountdata->sb)->client);
226 struct vfsmount *mnt = ERR_PTR(-ENOENT); 226 struct vfsmount *mnt = ERR_PTR(-ENOENT);
227 char *mnt_path; 227 char *mnt_path;
228 unsigned int maxbuflen; 228 unsigned int maxbuflen;
@@ -248,8 +248,7 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
248 continue; 248 continue;
249 249
250 mountdata->addrlen = nfs_parse_server_name(buf->data, buf->len, 250 mountdata->addrlen = nfs_parse_server_name(buf->data, buf->len,
251 mountdata->addr, addr_bufsize, 251 mountdata->addr, addr_bufsize, net);
252 NFS_SB(mountdata->sb));
253 if (mountdata->addrlen == 0) 252 if (mountdata->addrlen == 0)
254 continue; 253 continue;
255 254
@@ -419,6 +418,7 @@ static int nfs4_try_replacing_one_location(struct nfs_server *server,
419 const struct nfs4_fs_location *location) 418 const struct nfs4_fs_location *location)
420{ 419{
421 const size_t addr_bufsize = sizeof(struct sockaddr_storage); 420 const size_t addr_bufsize = sizeof(struct sockaddr_storage);
421 struct net *net = rpc_net_ns(server->client);
422 struct sockaddr *sap; 422 struct sockaddr *sap;
423 unsigned int s; 423 unsigned int s;
424 size_t salen; 424 size_t salen;
@@ -440,7 +440,7 @@ static int nfs4_try_replacing_one_location(struct nfs_server *server,
440 continue; 440 continue;
441 441
442 salen = nfs_parse_server_name(buf->data, buf->len, 442 salen = nfs_parse_server_name(buf->data, buf->len,
443 sap, addr_bufsize, server); 443 sap, addr_bufsize, net);
444 if (salen == 0) 444 if (salen == 0)
445 continue; 445 continue;
446 rpc_set_port(sap, NFS_PORT); 446 rpc_set_port(sap, NFS_PORT);
@@ -450,7 +450,7 @@ static int nfs4_try_replacing_one_location(struct nfs_server *server,
450 if (hostname == NULL) 450 if (hostname == NULL)
451 break; 451 break;
452 452
453 error = nfs4_update_server(server, hostname, sap, salen); 453 error = nfs4_update_server(server, hostname, sap, salen, net);
454 kfree(hostname); 454 kfree(hostname);
455 if (error == 0) 455 if (error == 0)
456 break; 456 break;
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 42da6af77587..450bfedbe2f4 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1620,15 +1620,15 @@ static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata)
1620{ 1620{
1621 struct nfs4_opendata *data = calldata; 1621 struct nfs4_opendata *data = calldata;
1622 1622
1623 nfs40_setup_sequence(data->o_arg.server, &data->o_arg.seq_args, 1623 nfs40_setup_sequence(data->o_arg.server, &data->c_arg.seq_args,
1624 &data->o_res.seq_res, task); 1624 &data->c_res.seq_res, task);
1625} 1625}
1626 1626
1627static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) 1627static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1628{ 1628{
1629 struct nfs4_opendata *data = calldata; 1629 struct nfs4_opendata *data = calldata;
1630 1630
1631 nfs40_sequence_done(task, &data->o_res.seq_res); 1631 nfs40_sequence_done(task, &data->c_res.seq_res);
1632 1632
1633 data->rpc_status = task->tk_status; 1633 data->rpc_status = task->tk_status;
1634 if (data->rpc_status == 0) { 1634 if (data->rpc_status == 0) {
@@ -1686,7 +1686,7 @@ static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1686 }; 1686 };
1687 int status; 1687 int status;
1688 1688
1689 nfs4_init_sequence(&data->o_arg.seq_args, &data->o_res.seq_res, 1); 1689 nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1);
1690 kref_get(&data->kref); 1690 kref_get(&data->kref);
1691 data->rpc_done = 0; 1691 data->rpc_done = 0;
1692 data->rpc_status = 0; 1692 data->rpc_status = 0;
@@ -2398,13 +2398,16 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2398 2398
2399 if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { 2399 if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) {
2400 /* Use that stateid */ 2400 /* Use that stateid */
2401 } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { 2401 } else if (truncate && state != NULL) {
2402 struct nfs_lockowner lockowner = { 2402 struct nfs_lockowner lockowner = {
2403 .l_owner = current->files, 2403 .l_owner = current->files,
2404 .l_pid = current->tgid, 2404 .l_pid = current->tgid,
2405 }; 2405 };
2406 nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, 2406 if (!nfs4_valid_open_stateid(state))
2407 &lockowner); 2407 return -EBADF;
2408 if (nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
2409 &lockowner) == -EIO)
2410 return -EBADF;
2408 } else 2411 } else
2409 nfs4_stateid_copy(&arg.stateid, &zero_stateid); 2412 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
2410 2413
@@ -4011,8 +4014,9 @@ static bool nfs4_stateid_is_current(nfs4_stateid *stateid,
4011{ 4014{
4012 nfs4_stateid current_stateid; 4015 nfs4_stateid current_stateid;
4013 4016
4014 if (nfs4_set_rw_stateid(&current_stateid, ctx, l_ctx, fmode)) 4017 /* If the current stateid represents a lost lock, then exit */
4015 return false; 4018 if (nfs4_set_rw_stateid(&current_stateid, ctx, l_ctx, fmode) == -EIO)
4019 return true;
4016 return nfs4_stateid_match(stateid, &current_stateid); 4020 return nfs4_stateid_match(stateid, &current_stateid);
4017} 4021}
4018 4022
@@ -5828,8 +5832,7 @@ struct nfs_release_lockowner_data {
5828 struct nfs4_lock_state *lsp; 5832 struct nfs4_lock_state *lsp;
5829 struct nfs_server *server; 5833 struct nfs_server *server;
5830 struct nfs_release_lockowner_args args; 5834 struct nfs_release_lockowner_args args;
5831 struct nfs4_sequence_args seq_args; 5835 struct nfs_release_lockowner_res res;
5832 struct nfs4_sequence_res seq_res;
5833 unsigned long timestamp; 5836 unsigned long timestamp;
5834}; 5837};
5835 5838
@@ -5837,7 +5840,7 @@ static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata
5837{ 5840{
5838 struct nfs_release_lockowner_data *data = calldata; 5841 struct nfs_release_lockowner_data *data = calldata;
5839 nfs40_setup_sequence(data->server, 5842 nfs40_setup_sequence(data->server,
5840 &data->seq_args, &data->seq_res, task); 5843 &data->args.seq_args, &data->res.seq_res, task);
5841 data->timestamp = jiffies; 5844 data->timestamp = jiffies;
5842} 5845}
5843 5846
@@ -5846,7 +5849,7 @@ static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata)
5846 struct nfs_release_lockowner_data *data = calldata; 5849 struct nfs_release_lockowner_data *data = calldata;
5847 struct nfs_server *server = data->server; 5850 struct nfs_server *server = data->server;
5848 5851
5849 nfs40_sequence_done(task, &data->seq_res); 5852 nfs40_sequence_done(task, &data->res.seq_res);
5850 5853
5851 switch (task->tk_status) { 5854 switch (task->tk_status) {
5852 case 0: 5855 case 0:
@@ -5887,7 +5890,6 @@ static int nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_st
5887 data = kmalloc(sizeof(*data), GFP_NOFS); 5890 data = kmalloc(sizeof(*data), GFP_NOFS);
5888 if (!data) 5891 if (!data)
5889 return -ENOMEM; 5892 return -ENOMEM;
5890 nfs4_init_sequence(&data->seq_args, &data->seq_res, 0);
5891 data->lsp = lsp; 5893 data->lsp = lsp;
5892 data->server = server; 5894 data->server = server;
5893 data->args.lock_owner.clientid = server->nfs_client->cl_clientid; 5895 data->args.lock_owner.clientid = server->nfs_client->cl_clientid;
@@ -5895,6 +5897,8 @@ static int nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_st
5895 data->args.lock_owner.s_dev = server->s_dev; 5897 data->args.lock_owner.s_dev = server->s_dev;
5896 5898
5897 msg.rpc_argp = &data->args; 5899 msg.rpc_argp = &data->args;
5900 msg.rpc_resp = &data->res;
5901 nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
5898 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); 5902 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data);
5899 return 0; 5903 return 0;
5900} 5904}
diff --git a/fs/nfs/nfs4session.c b/fs/nfs/nfs4session.c
index cf883c7ae053..e799dc3c3b1d 100644
--- a/fs/nfs/nfs4session.c
+++ b/fs/nfs/nfs4session.c
@@ -231,14 +231,23 @@ out:
231 return ret; 231 return ret;
232} 232}
233 233
234/*
235 * nfs4_release_slot_table - release all slot table entries
236 */
237static void nfs4_release_slot_table(struct nfs4_slot_table *tbl)
238{
239 nfs4_shrink_slot_table(tbl, 0);
240}
241
234/** 242/**
235 * nfs4_release_slot_table - release resources attached to a slot table 243 * nfs4_shutdown_slot_table - release resources attached to a slot table
236 * @tbl: slot table to shut down 244 * @tbl: slot table to shut down
237 * 245 *
238 */ 246 */
239void nfs4_release_slot_table(struct nfs4_slot_table *tbl) 247void nfs4_shutdown_slot_table(struct nfs4_slot_table *tbl)
240{ 248{
241 nfs4_shrink_slot_table(tbl, 0); 249 nfs4_release_slot_table(tbl);
250 rpc_destroy_wait_queue(&tbl->slot_tbl_waitq);
242} 251}
243 252
244/** 253/**
@@ -422,7 +431,7 @@ void nfs41_update_target_slotid(struct nfs4_slot_table *tbl,
422 spin_unlock(&tbl->slot_tbl_lock); 431 spin_unlock(&tbl->slot_tbl_lock);
423} 432}
424 433
425static void nfs4_destroy_session_slot_tables(struct nfs4_session *session) 434static void nfs4_release_session_slot_tables(struct nfs4_session *session)
426{ 435{
427 nfs4_release_slot_table(&session->fc_slot_table); 436 nfs4_release_slot_table(&session->fc_slot_table);
428 nfs4_release_slot_table(&session->bc_slot_table); 437 nfs4_release_slot_table(&session->bc_slot_table);
@@ -450,7 +459,7 @@ int nfs4_setup_session_slot_tables(struct nfs4_session *ses)
450 if (status && tbl->slots == NULL) 459 if (status && tbl->slots == NULL)
451 /* Fore and back channel share a connection so get 460 /* Fore and back channel share a connection so get
452 * both slot tables or neither */ 461 * both slot tables or neither */
453 nfs4_destroy_session_slot_tables(ses); 462 nfs4_release_session_slot_tables(ses);
454 return status; 463 return status;
455} 464}
456 465
@@ -470,6 +479,12 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
470 return session; 479 return session;
471} 480}
472 481
482static void nfs4_destroy_session_slot_tables(struct nfs4_session *session)
483{
484 nfs4_shutdown_slot_table(&session->fc_slot_table);
485 nfs4_shutdown_slot_table(&session->bc_slot_table);
486}
487
473void nfs4_destroy_session(struct nfs4_session *session) 488void nfs4_destroy_session(struct nfs4_session *session)
474{ 489{
475 struct rpc_xprt *xprt; 490 struct rpc_xprt *xprt;
diff --git a/fs/nfs/nfs4session.h b/fs/nfs/nfs4session.h
index 232306100651..b34ada9bc6a2 100644
--- a/fs/nfs/nfs4session.h
+++ b/fs/nfs/nfs4session.h
@@ -74,7 +74,7 @@ enum nfs4_session_state {
74 74
75extern int nfs4_setup_slot_table(struct nfs4_slot_table *tbl, 75extern int nfs4_setup_slot_table(struct nfs4_slot_table *tbl,
76 unsigned int max_reqs, const char *queue); 76 unsigned int max_reqs, const char *queue);
77extern void nfs4_release_slot_table(struct nfs4_slot_table *tbl); 77extern void nfs4_shutdown_slot_table(struct nfs4_slot_table *tbl);
78extern struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl); 78extern struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl);
79extern void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot); 79extern void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot);
80extern void nfs4_slot_tbl_drain_complete(struct nfs4_slot_table *tbl); 80extern void nfs4_slot_tbl_drain_complete(struct nfs4_slot_table *tbl);
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index e5be72518bd7..0deb32105ccf 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -974,9 +974,6 @@ static int nfs4_copy_lock_stateid(nfs4_stateid *dst,
974 else if (lsp != NULL && test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) { 974 else if (lsp != NULL && test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) {
975 nfs4_stateid_copy(dst, &lsp->ls_stateid); 975 nfs4_stateid_copy(dst, &lsp->ls_stateid);
976 ret = 0; 976 ret = 0;
977 smp_rmb();
978 if (!list_empty(&lsp->ls_seqid.list))
979 ret = -EWOULDBLOCK;
980 } 977 }
981 spin_unlock(&state->state_lock); 978 spin_unlock(&state->state_lock);
982 nfs4_put_lock_state(lsp); 979 nfs4_put_lock_state(lsp);
@@ -984,10 +981,9 @@ out:
984 return ret; 981 return ret;
985} 982}
986 983
987static int nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) 984static void nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
988{ 985{
989 const nfs4_stateid *src; 986 const nfs4_stateid *src;
990 int ret;
991 int seq; 987 int seq;
992 988
993 do { 989 do {
@@ -996,12 +992,7 @@ static int nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
996 if (test_bit(NFS_OPEN_STATE, &state->flags)) 992 if (test_bit(NFS_OPEN_STATE, &state->flags))
997 src = &state->open_stateid; 993 src = &state->open_stateid;
998 nfs4_stateid_copy(dst, src); 994 nfs4_stateid_copy(dst, src);
999 ret = 0;
1000 smp_rmb();
1001 if (!list_empty(&state->owner->so_seqid.list))
1002 ret = -EWOULDBLOCK;
1003 } while (read_seqretry(&state->seqlock, seq)); 995 } while (read_seqretry(&state->seqlock, seq));
1004 return ret;
1005} 996}
1006 997
1007/* 998/*
@@ -1015,15 +1006,19 @@ int nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state,
1015 if (ret == -EIO) 1006 if (ret == -EIO)
1016 /* A lost lock - don't even consider delegations */ 1007 /* A lost lock - don't even consider delegations */
1017 goto out; 1008 goto out;
1018 if (nfs4_copy_delegation_stateid(dst, state->inode, fmode)) 1009 /* returns true if delegation stateid found and copied */
1010 if (nfs4_copy_delegation_stateid(dst, state->inode, fmode)) {
1011 ret = 0;
1019 goto out; 1012 goto out;
1013 }
1020 if (ret != -ENOENT) 1014 if (ret != -ENOENT)
1021 /* nfs4_copy_delegation_stateid() didn't over-write 1015 /* nfs4_copy_delegation_stateid() didn't over-write
1022 * dst, so it still has the lock stateid which we now 1016 * dst, so it still has the lock stateid which we now
1023 * choose to use. 1017 * choose to use.
1024 */ 1018 */
1025 goto out; 1019 goto out;
1026 ret = nfs4_copy_open_stateid(dst, state); 1020 nfs4_copy_open_stateid(dst, state);
1021 ret = 0;
1027out: 1022out:
1028 if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41)) 1023 if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41))
1029 dst->seqid = 0; 1024 dst->seqid = 0;
diff --git a/fs/nfsd/nfs4acl.c b/fs/nfsd/nfs4acl.c
index d3a587144222..d190e33d0ec2 100644
--- a/fs/nfsd/nfs4acl.c
+++ b/fs/nfsd/nfs4acl.c
@@ -151,17 +151,15 @@ nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry,
151 pacl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL); 151 pacl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
152 if (IS_ERR(pacl)) 152 if (IS_ERR(pacl))
153 return PTR_ERR(pacl); 153 return PTR_ERR(pacl);
154 /* allocate for worst case: one (deny, allow) pair each: */
155 size += 2 * pacl->a_count;
156 } 154 }
155 /* allocate for worst case: one (deny, allow) pair each: */
156 size += 2 * pacl->a_count;
157 157
158 if (S_ISDIR(inode->i_mode)) { 158 if (S_ISDIR(inode->i_mode)) {
159 flags = NFS4_ACL_DIR; 159 flags = NFS4_ACL_DIR;
160 dpacl = get_acl(inode, ACL_TYPE_DEFAULT); 160 dpacl = get_acl(inode, ACL_TYPE_DEFAULT);
161 if (dpacl) 161 if (dpacl)
162 size += 2 * dpacl->a_count; 162 size += 2 * dpacl->a_count;
163 } else {
164 dpacl = NULL;
165 } 163 }
166 164
167 *acl = nfs4_acl_new(size); 165 *acl = nfs4_acl_new(size);
@@ -170,8 +168,7 @@ nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry,
170 goto out; 168 goto out;
171 } 169 }
172 170
173 if (pacl) 171 _posix_to_nfsv4_one(pacl, *acl, flags & ~NFS4_ACL_TYPE_DEFAULT);
174 _posix_to_nfsv4_one(pacl, *acl, flags & ~NFS4_ACL_TYPE_DEFAULT);
175 172
176 if (dpacl) 173 if (dpacl)
177 _posix_to_nfsv4_one(dpacl, *acl, flags | NFS4_ACL_TYPE_DEFAULT); 174 _posix_to_nfsv4_one(dpacl, *acl, flags | NFS4_ACL_TYPE_DEFAULT);
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 017d3cb5e99b..6d7be3f80356 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -449,6 +449,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
449 fh_lock(fhp); 449 fh_lock(fhp);
450 host_err = notify_change(dentry, iap, NULL); 450 host_err = notify_change(dentry, iap, NULL);
451 fh_unlock(fhp); 451 fh_unlock(fhp);
452 err = nfserrno(host_err);
452 453
453out_put_write_access: 454out_put_write_access:
454 if (size_change) 455 if (size_change)
diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
index 0b9ff4395e6a..abc8cbcfe90e 100644
--- a/fs/notify/dnotify/dnotify.c
+++ b/fs/notify/dnotify/dnotify.c
@@ -86,7 +86,7 @@ static int dnotify_handle_event(struct fsnotify_group *group,
86 struct fsnotify_mark *inode_mark, 86 struct fsnotify_mark *inode_mark,
87 struct fsnotify_mark *vfsmount_mark, 87 struct fsnotify_mark *vfsmount_mark,
88 u32 mask, void *data, int data_type, 88 u32 mask, void *data, int data_type,
89 const unsigned char *file_name) 89 const unsigned char *file_name, u32 cookie)
90{ 90{
91 struct dnotify_mark *dn_mark; 91 struct dnotify_mark *dn_mark;
92 struct dnotify_struct *dn; 92 struct dnotify_struct *dn;
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 0e792f5e3147..dc638f786d5c 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -147,7 +147,7 @@ static int fanotify_handle_event(struct fsnotify_group *group,
147 struct fsnotify_mark *inode_mark, 147 struct fsnotify_mark *inode_mark,
148 struct fsnotify_mark *fanotify_mark, 148 struct fsnotify_mark *fanotify_mark,
149 u32 mask, void *data, int data_type, 149 u32 mask, void *data, int data_type,
150 const unsigned char *file_name) 150 const unsigned char *file_name, u32 cookie)
151{ 151{
152 int ret = 0; 152 int ret = 0;
153 struct fanotify_event_info *event; 153 struct fanotify_event_info *event;
@@ -192,10 +192,12 @@ static int fanotify_handle_event(struct fsnotify_group *group,
192 192
193 ret = fsnotify_add_notify_event(group, fsn_event, fanotify_merge); 193 ret = fsnotify_add_notify_event(group, fsn_event, fanotify_merge);
194 if (ret) { 194 if (ret) {
195 BUG_ON(mask & FAN_ALL_PERM_EVENTS); 195 /* Permission events shouldn't be merged */
196 BUG_ON(ret == 1 && mask & FAN_ALL_PERM_EVENTS);
196 /* Our event wasn't used in the end. Free it. */ 197 /* Our event wasn't used in the end. Free it. */
197 fsnotify_destroy_event(group, fsn_event); 198 fsnotify_destroy_event(group, fsn_event);
198 ret = 0; 199
200 return 0;
199 } 201 }
200 202
201#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS 203#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index b6175fa11bf8..287a22c04149 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -698,6 +698,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
698 struct fsnotify_group *group; 698 struct fsnotify_group *group;
699 int f_flags, fd; 699 int f_flags, fd;
700 struct user_struct *user; 700 struct user_struct *user;
701 struct fanotify_event_info *oevent;
701 702
702 pr_debug("%s: flags=%d event_f_flags=%d\n", 703 pr_debug("%s: flags=%d event_f_flags=%d\n",
703 __func__, flags, event_f_flags); 704 __func__, flags, event_f_flags);
@@ -730,8 +731,20 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
730 group->fanotify_data.user = user; 731 group->fanotify_data.user = user;
731 atomic_inc(&user->fanotify_listeners); 732 atomic_inc(&user->fanotify_listeners);
732 733
734 oevent = kmem_cache_alloc(fanotify_event_cachep, GFP_KERNEL);
735 if (unlikely(!oevent)) {
736 fd = -ENOMEM;
737 goto out_destroy_group;
738 }
739 group->overflow_event = &oevent->fse;
740 fsnotify_init_event(group->overflow_event, NULL, FS_Q_OVERFLOW);
741 oevent->tgid = get_pid(task_tgid(current));
742 oevent->path.mnt = NULL;
743 oevent->path.dentry = NULL;
744
733 group->fanotify_data.f_flags = event_f_flags; 745 group->fanotify_data.f_flags = event_f_flags;
734#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS 746#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
747 oevent->response = 0;
735 mutex_init(&group->fanotify_data.access_mutex); 748 mutex_init(&group->fanotify_data.access_mutex);
736 init_waitqueue_head(&group->fanotify_data.access_waitq); 749 init_waitqueue_head(&group->fanotify_data.access_waitq);
737 INIT_LIST_HEAD(&group->fanotify_data.access_list); 750 INIT_LIST_HEAD(&group->fanotify_data.access_list);
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 1d4e1ea2f37c..9d3e9c50066a 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -179,7 +179,7 @@ static int send_to_group(struct inode *to_tell,
179 179
180 return group->ops->handle_event(group, to_tell, inode_mark, 180 return group->ops->handle_event(group, to_tell, inode_mark,
181 vfsmount_mark, mask, data, data_is, 181 vfsmount_mark, mask, data, data_is,
182 file_name); 182 file_name, cookie);
183} 183}
184 184
185/* 185/*
diff --git a/fs/notify/group.c b/fs/notify/group.c
index ee674fe2cec7..ad1995980456 100644
--- a/fs/notify/group.c
+++ b/fs/notify/group.c
@@ -55,6 +55,13 @@ void fsnotify_destroy_group(struct fsnotify_group *group)
55 /* clear the notification queue of all events */ 55 /* clear the notification queue of all events */
56 fsnotify_flush_notify(group); 56 fsnotify_flush_notify(group);
57 57
58 /*
59 * Destroy overflow event (we cannot use fsnotify_destroy_event() as
60 * that deliberately ignores overflow events.
61 */
62 if (group->overflow_event)
63 group->ops->free_event(group->overflow_event);
64
58 fsnotify_put_group(group); 65 fsnotify_put_group(group);
59} 66}
60 67
@@ -99,7 +106,6 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
99 INIT_LIST_HEAD(&group->marks_list); 106 INIT_LIST_HEAD(&group->marks_list);
100 107
101 group->ops = ops; 108 group->ops = ops;
102 fsnotify_init_event(&group->overflow_event, NULL, FS_Q_OVERFLOW);
103 109
104 return group; 110 return group;
105} 111}
diff --git a/fs/notify/inotify/inotify.h b/fs/notify/inotify/inotify.h
index 485eef3f4407..ed855ef6f077 100644
--- a/fs/notify/inotify/inotify.h
+++ b/fs/notify/inotify/inotify.h
@@ -27,6 +27,6 @@ extern int inotify_handle_event(struct fsnotify_group *group,
27 struct fsnotify_mark *inode_mark, 27 struct fsnotify_mark *inode_mark,
28 struct fsnotify_mark *vfsmount_mark, 28 struct fsnotify_mark *vfsmount_mark,
29 u32 mask, void *data, int data_type, 29 u32 mask, void *data, int data_type,
30 const unsigned char *file_name); 30 const unsigned char *file_name, u32 cookie);
31 31
32extern const struct fsnotify_ops inotify_fsnotify_ops; 32extern const struct fsnotify_ops inotify_fsnotify_ops;
diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index d5ee56348bb8..43ab1e1a07a2 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -67,7 +67,7 @@ int inotify_handle_event(struct fsnotify_group *group,
67 struct fsnotify_mark *inode_mark, 67 struct fsnotify_mark *inode_mark,
68 struct fsnotify_mark *vfsmount_mark, 68 struct fsnotify_mark *vfsmount_mark,
69 u32 mask, void *data, int data_type, 69 u32 mask, void *data, int data_type,
70 const unsigned char *file_name) 70 const unsigned char *file_name, u32 cookie)
71{ 71{
72 struct inotify_inode_mark *i_mark; 72 struct inotify_inode_mark *i_mark;
73 struct inotify_event_info *event; 73 struct inotify_event_info *event;
@@ -103,6 +103,7 @@ int inotify_handle_event(struct fsnotify_group *group,
103 fsn_event = &event->fse; 103 fsn_event = &event->fse;
104 fsnotify_init_event(fsn_event, inode, mask); 104 fsnotify_init_event(fsn_event, inode, mask);
105 event->wd = i_mark->wd; 105 event->wd = i_mark->wd;
106 event->sync_cookie = cookie;
106 event->name_len = len; 107 event->name_len = len;
107 if (len) 108 if (len)
108 strcpy(event->name, file_name); 109 strcpy(event->name, file_name);
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index 497395c8274b..78a2ca3966c3 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -495,7 +495,7 @@ void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
495 495
496 /* Queue ignore event for the watch */ 496 /* Queue ignore event for the watch */
497 inotify_handle_event(group, NULL, fsn_mark, NULL, FS_IN_IGNORED, 497 inotify_handle_event(group, NULL, fsn_mark, NULL, FS_IN_IGNORED,
498 NULL, FSNOTIFY_EVENT_NONE, NULL); 498 NULL, FSNOTIFY_EVENT_NONE, NULL, 0);
499 499
500 i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark); 500 i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);
501 /* remove this mark from the idr */ 501 /* remove this mark from the idr */
@@ -633,11 +633,23 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod
633static struct fsnotify_group *inotify_new_group(unsigned int max_events) 633static struct fsnotify_group *inotify_new_group(unsigned int max_events)
634{ 634{
635 struct fsnotify_group *group; 635 struct fsnotify_group *group;
636 struct inotify_event_info *oevent;
636 637
637 group = fsnotify_alloc_group(&inotify_fsnotify_ops); 638 group = fsnotify_alloc_group(&inotify_fsnotify_ops);
638 if (IS_ERR(group)) 639 if (IS_ERR(group))
639 return group; 640 return group;
640 641
642 oevent = kmalloc(sizeof(struct inotify_event_info), GFP_KERNEL);
643 if (unlikely(!oevent)) {
644 fsnotify_destroy_group(group);
645 return ERR_PTR(-ENOMEM);
646 }
647 group->overflow_event = &oevent->fse;
648 fsnotify_init_event(group->overflow_event, NULL, FS_Q_OVERFLOW);
649 oevent->wd = -1;
650 oevent->sync_cookie = 0;
651 oevent->name_len = 0;
652
641 group->max_events = max_events; 653 group->max_events = max_events;
642 654
643 spin_lock_init(&group->inotify_data.idr_lock); 655 spin_lock_init(&group->inotify_data.idr_lock);
diff --git a/fs/notify/notification.c b/fs/notify/notification.c
index 18b3c4427dca..1e58402171a5 100644
--- a/fs/notify/notification.c
+++ b/fs/notify/notification.c
@@ -80,7 +80,8 @@ void fsnotify_destroy_event(struct fsnotify_group *group,
80/* 80/*
81 * Add an event to the group notification queue. The group can later pull this 81 * Add an event to the group notification queue. The group can later pull this
82 * event off the queue to deal with. The function returns 0 if the event was 82 * event off the queue to deal with. The function returns 0 if the event was
83 * added to the queue, 1 if the event was merged with some other queued event. 83 * added to the queue, 1 if the event was merged with some other queued event,
84 * 2 if the queue of events has overflown.
84 */ 85 */
85int fsnotify_add_notify_event(struct fsnotify_group *group, 86int fsnotify_add_notify_event(struct fsnotify_group *group,
86 struct fsnotify_event *event, 87 struct fsnotify_event *event,
@@ -95,10 +96,14 @@ int fsnotify_add_notify_event(struct fsnotify_group *group,
95 mutex_lock(&group->notification_mutex); 96 mutex_lock(&group->notification_mutex);
96 97
97 if (group->q_len >= group->max_events) { 98 if (group->q_len >= group->max_events) {
99 ret = 2;
98 /* Queue overflow event only if it isn't already queued */ 100 /* Queue overflow event only if it isn't already queued */
99 if (list_empty(&group->overflow_event.list)) 101 if (!list_empty(&group->overflow_event->list)) {
100 event = &group->overflow_event; 102 mutex_unlock(&group->notification_mutex);
101 ret = 1; 103 return ret;
104 }
105 event = group->overflow_event;
106 goto queue;
102 } 107 }
103 108
104 if (!list_empty(list) && merge) { 109 if (!list_empty(list) && merge) {
@@ -109,6 +114,7 @@ int fsnotify_add_notify_event(struct fsnotify_group *group,
109 } 114 }
110 } 115 }
111 116
117queue:
112 group->q_len++; 118 group->q_len++;
113 list_add_tail(&event->list, list); 119 list_add_tail(&event->list, list);
114 mutex_unlock(&group->notification_mutex); 120 mutex_unlock(&group->notification_mutex);
@@ -132,7 +138,11 @@ struct fsnotify_event *fsnotify_remove_notify_event(struct fsnotify_group *group
132 138
133 event = list_first_entry(&group->notification_list, 139 event = list_first_entry(&group->notification_list,
134 struct fsnotify_event, list); 140 struct fsnotify_event, list);
135 list_del(&event->list); 141 /*
142 * We need to init list head for the case of overflow event so that
143 * check in fsnotify_add_notify_events() works
144 */
145 list_del_init(&event->list);
136 group->q_len--; 146 group->q_len--;
137 147
138 return event; 148 return event;
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index ea4ba9daeb47..db9bd8a31725 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -2134,7 +2134,7 @@ static ssize_t ntfs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
2134 ret = ntfs_file_aio_write_nolock(iocb, iov, nr_segs, &iocb->ki_pos); 2134 ret = ntfs_file_aio_write_nolock(iocb, iov, nr_segs, &iocb->ki_pos);
2135 mutex_unlock(&inode->i_mutex); 2135 mutex_unlock(&inode->i_mutex);
2136 if (ret > 0) { 2136 if (ret > 0) {
2137 int err = generic_write_sync(file, pos, ret); 2137 int err = generic_write_sync(file, iocb->ki_pos - ret, ret);
2138 if (err < 0) 2138 if (err < 0)
2139 ret = err; 2139 ret = err;
2140 } 2140 }
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 8750ae1b8636..e2edff38be52 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -4742,6 +4742,7 @@ int ocfs2_add_clusters_in_btree(handle_t *handle,
4742 enum ocfs2_alloc_restarted *reason_ret) 4742 enum ocfs2_alloc_restarted *reason_ret)
4743{ 4743{
4744 int status = 0, err = 0; 4744 int status = 0, err = 0;
4745 int need_free = 0;
4745 int free_extents; 4746 int free_extents;
4746 enum ocfs2_alloc_restarted reason = RESTART_NONE; 4747 enum ocfs2_alloc_restarted reason = RESTART_NONE;
4747 u32 bit_off, num_bits; 4748 u32 bit_off, num_bits;
@@ -4796,7 +4797,8 @@ int ocfs2_add_clusters_in_btree(handle_t *handle,
4796 OCFS2_JOURNAL_ACCESS_WRITE); 4797 OCFS2_JOURNAL_ACCESS_WRITE);
4797 if (status < 0) { 4798 if (status < 0) {
4798 mlog_errno(status); 4799 mlog_errno(status);
4799 goto leave; 4800 need_free = 1;
4801 goto bail;
4800 } 4802 }
4801 4803
4802 block = ocfs2_clusters_to_blocks(osb->sb, bit_off); 4804 block = ocfs2_clusters_to_blocks(osb->sb, bit_off);
@@ -4807,7 +4809,8 @@ int ocfs2_add_clusters_in_btree(handle_t *handle,
4807 num_bits, flags, meta_ac); 4809 num_bits, flags, meta_ac);
4808 if (status < 0) { 4810 if (status < 0) {
4809 mlog_errno(status); 4811 mlog_errno(status);
4810 goto leave; 4812 need_free = 1;
4813 goto bail;
4811 } 4814 }
4812 4815
4813 ocfs2_journal_dirty(handle, et->et_root_bh); 4816 ocfs2_journal_dirty(handle, et->et_root_bh);
@@ -4821,6 +4824,19 @@ int ocfs2_add_clusters_in_btree(handle_t *handle,
4821 reason = RESTART_TRANS; 4824 reason = RESTART_TRANS;
4822 } 4825 }
4823 4826
4827bail:
4828 if (need_free) {
4829 if (data_ac->ac_which == OCFS2_AC_USE_LOCAL)
4830 ocfs2_free_local_alloc_bits(osb, handle, data_ac,
4831 bit_off, num_bits);
4832 else
4833 ocfs2_free_clusters(handle,
4834 data_ac->ac_inode,
4835 data_ac->ac_bh,
4836 ocfs2_clusters_to_blocks(osb->sb, bit_off),
4837 num_bits);
4838 }
4839
4824leave: 4840leave:
4825 if (reason_ret) 4841 if (reason_ret)
4826 *reason_ret = reason; 4842 *reason_ret = reason;
@@ -6805,6 +6821,8 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
6805 struct buffer_head *di_bh) 6821 struct buffer_head *di_bh)
6806{ 6822{
6807 int ret, i, has_data, num_pages = 0; 6823 int ret, i, has_data, num_pages = 0;
6824 int need_free = 0;
6825 u32 bit_off, num;
6808 handle_t *handle; 6826 handle_t *handle;
6809 u64 uninitialized_var(block); 6827 u64 uninitialized_var(block);
6810 struct ocfs2_inode_info *oi = OCFS2_I(inode); 6828 struct ocfs2_inode_info *oi = OCFS2_I(inode);
@@ -6850,7 +6868,6 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
6850 } 6868 }
6851 6869
6852 if (has_data) { 6870 if (has_data) {
6853 u32 bit_off, num;
6854 unsigned int page_end; 6871 unsigned int page_end;
6855 u64 phys; 6872 u64 phys;
6856 6873
@@ -6886,6 +6903,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
6886 ret = ocfs2_grab_eof_pages(inode, 0, end, pages, &num_pages); 6903 ret = ocfs2_grab_eof_pages(inode, 0, end, pages, &num_pages);
6887 if (ret) { 6904 if (ret) {
6888 mlog_errno(ret); 6905 mlog_errno(ret);
6906 need_free = 1;
6889 goto out_commit; 6907 goto out_commit;
6890 } 6908 }
6891 6909
@@ -6896,6 +6914,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
6896 ret = ocfs2_read_inline_data(inode, pages[0], di_bh); 6914 ret = ocfs2_read_inline_data(inode, pages[0], di_bh);
6897 if (ret) { 6915 if (ret) {
6898 mlog_errno(ret); 6916 mlog_errno(ret);
6917 need_free = 1;
6899 goto out_commit; 6918 goto out_commit;
6900 } 6919 }
6901 6920
@@ -6927,6 +6946,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
6927 ret = ocfs2_insert_extent(handle, &et, 0, block, 1, 0, NULL); 6946 ret = ocfs2_insert_extent(handle, &et, 0, block, 1, 0, NULL);
6928 if (ret) { 6947 if (ret) {
6929 mlog_errno(ret); 6948 mlog_errno(ret);
6949 need_free = 1;
6930 goto out_commit; 6950 goto out_commit;
6931 } 6951 }
6932 6952
@@ -6938,6 +6958,18 @@ out_commit:
6938 dquot_free_space_nodirty(inode, 6958 dquot_free_space_nodirty(inode,
6939 ocfs2_clusters_to_bytes(osb->sb, 1)); 6959 ocfs2_clusters_to_bytes(osb->sb, 1));
6940 6960
6961 if (need_free) {
6962 if (data_ac->ac_which == OCFS2_AC_USE_LOCAL)
6963 ocfs2_free_local_alloc_bits(osb, handle, data_ac,
6964 bit_off, num);
6965 else
6966 ocfs2_free_clusters(handle,
6967 data_ac->ac_inode,
6968 data_ac->ac_bh,
6969 ocfs2_clusters_to_blocks(osb->sb, bit_off),
6970 num);
6971 }
6972
6941 ocfs2_commit_trans(osb, handle); 6973 ocfs2_commit_trans(osb, handle);
6942 6974
6943out_unlock: 6975out_unlock:
@@ -7126,7 +7158,7 @@ int ocfs2_truncate_inline(struct inode *inode, struct buffer_head *di_bh,
7126 if (end > i_size_read(inode)) 7158 if (end > i_size_read(inode))
7127 end = i_size_read(inode); 7159 end = i_size_read(inode);
7128 7160
7129 BUG_ON(start >= end); 7161 BUG_ON(start > end);
7130 7162
7131 if (!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) || 7163 if (!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) ||
7132 !(le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_DATA_FL) || 7164 !(le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_DATA_FL) ||
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index d77d71ead8d1..51632c40e896 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -185,6 +185,9 @@ static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end,
185 file->f_path.dentry->d_name.name, 185 file->f_path.dentry->d_name.name,
186 (unsigned long long)datasync); 186 (unsigned long long)datasync);
187 187
188 if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
189 return -EROFS;
190
188 err = filemap_write_and_wait_range(inode->i_mapping, start, end); 191 err = filemap_write_and_wait_range(inode->i_mapping, start, end);
189 if (err) 192 if (err)
190 return err; 193 return err;
@@ -474,11 +477,6 @@ static int ocfs2_truncate_file(struct inode *inode,
474 goto bail; 477 goto bail;
475 } 478 }
476 479
477 /* lets handle the simple truncate cases before doing any more
478 * cluster locking. */
479 if (new_i_size == le64_to_cpu(fe->i_size))
480 goto bail;
481
482 down_write(&OCFS2_I(inode)->ip_alloc_sem); 480 down_write(&OCFS2_I(inode)->ip_alloc_sem);
483 481
484 ocfs2_resv_discard(&osb->osb_la_resmap, 482 ocfs2_resv_discard(&osb->osb_la_resmap,
@@ -718,7 +716,8 @@ leave:
718 * While a write will already be ordering the data, a truncate will not. 716 * While a write will already be ordering the data, a truncate will not.
719 * Thus, we need to explicitly order the zeroed pages. 717 * Thus, we need to explicitly order the zeroed pages.
720 */ 718 */
721static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode) 719static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode,
720 struct buffer_head *di_bh)
722{ 721{
723 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 722 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
724 handle_t *handle = NULL; 723 handle_t *handle = NULL;
@@ -735,7 +734,14 @@ static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode)
735 } 734 }
736 735
737 ret = ocfs2_jbd2_file_inode(handle, inode); 736 ret = ocfs2_jbd2_file_inode(handle, inode);
738 if (ret < 0) 737 if (ret < 0) {
738 mlog_errno(ret);
739 goto out;
740 }
741
742 ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
743 OCFS2_JOURNAL_ACCESS_WRITE);
744 if (ret)
739 mlog_errno(ret); 745 mlog_errno(ret);
740 746
741out: 747out:
@@ -751,7 +757,7 @@ out:
751 * to be too fragile to do exactly what we need without us having to 757 * to be too fragile to do exactly what we need without us having to
752 * worry about recursive locking in ->write_begin() and ->write_end(). */ 758 * worry about recursive locking in ->write_begin() and ->write_end(). */
753static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from, 759static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
754 u64 abs_to) 760 u64 abs_to, struct buffer_head *di_bh)
755{ 761{
756 struct address_space *mapping = inode->i_mapping; 762 struct address_space *mapping = inode->i_mapping;
757 struct page *page; 763 struct page *page;
@@ -759,6 +765,7 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
759 handle_t *handle = NULL; 765 handle_t *handle = NULL;
760 int ret = 0; 766 int ret = 0;
761 unsigned zero_from, zero_to, block_start, block_end; 767 unsigned zero_from, zero_to, block_start, block_end;
768 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
762 769
763 BUG_ON(abs_from >= abs_to); 770 BUG_ON(abs_from >= abs_to);
764 BUG_ON(abs_to > (((u64)index + 1) << PAGE_CACHE_SHIFT)); 771 BUG_ON(abs_to > (((u64)index + 1) << PAGE_CACHE_SHIFT));
@@ -801,7 +808,8 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
801 } 808 }
802 809
803 if (!handle) { 810 if (!handle) {
804 handle = ocfs2_zero_start_ordered_transaction(inode); 811 handle = ocfs2_zero_start_ordered_transaction(inode,
812 di_bh);
805 if (IS_ERR(handle)) { 813 if (IS_ERR(handle)) {
806 ret = PTR_ERR(handle); 814 ret = PTR_ERR(handle);
807 handle = NULL; 815 handle = NULL;
@@ -818,8 +826,22 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
818 ret = 0; 826 ret = 0;
819 } 827 }
820 828
821 if (handle) 829 if (handle) {
830 /*
831 * fs-writeback will release the dirty pages without page lock
832 * whose offset are over inode size, the release happens at
833 * block_write_full_page_endio().
834 */
835 i_size_write(inode, abs_to);
836 inode->i_blocks = ocfs2_inode_sector_count(inode);
837 di->i_size = cpu_to_le64((u64)i_size_read(inode));
838 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
839 di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
840 di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
841 di->i_mtime_nsec = di->i_ctime_nsec;
842 ocfs2_journal_dirty(handle, di_bh);
822 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); 843 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
844 }
823 845
824out_unlock: 846out_unlock:
825 unlock_page(page); 847 unlock_page(page);
@@ -915,7 +937,7 @@ out:
915 * has made sure that the entire range needs zeroing. 937 * has made sure that the entire range needs zeroing.
916 */ 938 */
917static int ocfs2_zero_extend_range(struct inode *inode, u64 range_start, 939static int ocfs2_zero_extend_range(struct inode *inode, u64 range_start,
918 u64 range_end) 940 u64 range_end, struct buffer_head *di_bh)
919{ 941{
920 int rc = 0; 942 int rc = 0;
921 u64 next_pos; 943 u64 next_pos;
@@ -931,7 +953,7 @@ static int ocfs2_zero_extend_range(struct inode *inode, u64 range_start,
931 next_pos = (zero_pos & PAGE_CACHE_MASK) + PAGE_CACHE_SIZE; 953 next_pos = (zero_pos & PAGE_CACHE_MASK) + PAGE_CACHE_SIZE;
932 if (next_pos > range_end) 954 if (next_pos > range_end)
933 next_pos = range_end; 955 next_pos = range_end;
934 rc = ocfs2_write_zero_page(inode, zero_pos, next_pos); 956 rc = ocfs2_write_zero_page(inode, zero_pos, next_pos, di_bh);
935 if (rc < 0) { 957 if (rc < 0) {
936 mlog_errno(rc); 958 mlog_errno(rc);
937 break; 959 break;
@@ -977,7 +999,7 @@ int ocfs2_zero_extend(struct inode *inode, struct buffer_head *di_bh,
977 range_end = zero_to_size; 999 range_end = zero_to_size;
978 1000
979 ret = ocfs2_zero_extend_range(inode, range_start, 1001 ret = ocfs2_zero_extend_range(inode, range_start,
980 range_end); 1002 range_end, di_bh);
981 if (ret) { 1003 if (ret) {
982 mlog_errno(ret); 1004 mlog_errno(ret);
983 break; 1005 break;
@@ -1145,14 +1167,14 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1145 goto bail_unlock_rw; 1167 goto bail_unlock_rw;
1146 } 1168 }
1147 1169
1148 if (size_change && attr->ia_size != i_size_read(inode)) { 1170 if (size_change) {
1149 status = inode_newsize_ok(inode, attr->ia_size); 1171 status = inode_newsize_ok(inode, attr->ia_size);
1150 if (status) 1172 if (status)
1151 goto bail_unlock; 1173 goto bail_unlock;
1152 1174
1153 inode_dio_wait(inode); 1175 inode_dio_wait(inode);
1154 1176
1155 if (i_size_read(inode) > attr->ia_size) { 1177 if (i_size_read(inode) >= attr->ia_size) {
1156 if (ocfs2_should_order_data(inode)) { 1178 if (ocfs2_should_order_data(inode)) {
1157 status = ocfs2_begin_ordered_truncate(inode, 1179 status = ocfs2_begin_ordered_truncate(inode,
1158 attr->ia_size); 1180 attr->ia_size);
@@ -2371,8 +2393,8 @@ out_dio:
2371 2393
2372 if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) || 2394 if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) ||
2373 ((file->f_flags & O_DIRECT) && !direct_io)) { 2395 ((file->f_flags & O_DIRECT) && !direct_io)) {
2374 ret = filemap_fdatawrite_range(file->f_mapping, pos, 2396 ret = filemap_fdatawrite_range(file->f_mapping, *ppos,
2375 pos + count - 1); 2397 *ppos + count - 1);
2376 if (ret < 0) 2398 if (ret < 0)
2377 written = ret; 2399 written = ret;
2378 2400
@@ -2385,8 +2407,8 @@ out_dio:
2385 } 2407 }
2386 2408
2387 if (!ret) 2409 if (!ret)
2388 ret = filemap_fdatawait_range(file->f_mapping, pos, 2410 ret = filemap_fdatawait_range(file->f_mapping, *ppos,
2389 pos + count - 1); 2411 *ppos + count - 1);
2390 } 2412 }
2391 2413
2392 /* 2414 /*
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index cd5496b7a0a3..044013455621 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -781,6 +781,48 @@ bail:
781 return status; 781 return status;
782} 782}
783 783
784int ocfs2_free_local_alloc_bits(struct ocfs2_super *osb,
785 handle_t *handle,
786 struct ocfs2_alloc_context *ac,
787 u32 bit_off,
788 u32 num_bits)
789{
790 int status, start;
791 u32 clear_bits;
792 struct inode *local_alloc_inode;
793 void *bitmap;
794 struct ocfs2_dinode *alloc;
795 struct ocfs2_local_alloc *la;
796
797 BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL);
798
799 local_alloc_inode = ac->ac_inode;
800 alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
801 la = OCFS2_LOCAL_ALLOC(alloc);
802
803 bitmap = la->la_bitmap;
804 start = bit_off - le32_to_cpu(la->la_bm_off);
805 clear_bits = num_bits;
806
807 status = ocfs2_journal_access_di(handle,
808 INODE_CACHE(local_alloc_inode),
809 osb->local_alloc_bh,
810 OCFS2_JOURNAL_ACCESS_WRITE);
811 if (status < 0) {
812 mlog_errno(status);
813 goto bail;
814 }
815
816 while (clear_bits--)
817 ocfs2_clear_bit(start++, bitmap);
818
819 le32_add_cpu(&alloc->id1.bitmap1.i_used, -num_bits);
820 ocfs2_journal_dirty(handle, osb->local_alloc_bh);
821
822bail:
823 return status;
824}
825
784static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc) 826static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc)
785{ 827{
786 u32 count; 828 u32 count;
diff --git a/fs/ocfs2/localalloc.h b/fs/ocfs2/localalloc.h
index 1be9b5864460..44a7d1fb2dec 100644
--- a/fs/ocfs2/localalloc.h
+++ b/fs/ocfs2/localalloc.h
@@ -55,6 +55,12 @@ int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
55 u32 *bit_off, 55 u32 *bit_off,
56 u32 *num_bits); 56 u32 *num_bits);
57 57
58int ocfs2_free_local_alloc_bits(struct ocfs2_super *osb,
59 handle_t *handle,
60 struct ocfs2_alloc_context *ac,
61 u32 bit_off,
62 u32 num_bits);
63
58void ocfs2_local_alloc_seen_free_bits(struct ocfs2_super *osb, 64void ocfs2_local_alloc_seen_free_bits(struct ocfs2_super *osb,
59 unsigned int num_clusters); 65 unsigned int num_clusters);
60void ocfs2_la_enable_worker(struct work_struct *work); 66void ocfs2_la_enable_worker(struct work_struct *work);
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index f4d609be9400..3683643f3f0e 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -664,6 +664,7 @@ static int ocfs2_link(struct dentry *old_dentry,
664 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); 664 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
665 struct ocfs2_dir_lookup_result lookup = { NULL, }; 665 struct ocfs2_dir_lookup_result lookup = { NULL, };
666 sigset_t oldset; 666 sigset_t oldset;
667 u64 old_de_ino;
667 668
668 trace_ocfs2_link((unsigned long long)OCFS2_I(inode)->ip_blkno, 669 trace_ocfs2_link((unsigned long long)OCFS2_I(inode)->ip_blkno,
669 old_dentry->d_name.len, old_dentry->d_name.name, 670 old_dentry->d_name.len, old_dentry->d_name.name,
@@ -686,6 +687,22 @@ static int ocfs2_link(struct dentry *old_dentry,
686 goto out; 687 goto out;
687 } 688 }
688 689
690 err = ocfs2_lookup_ino_from_name(dir, old_dentry->d_name.name,
691 old_dentry->d_name.len, &old_de_ino);
692 if (err) {
693 err = -ENOENT;
694 goto out;
695 }
696
697 /*
698 * Check whether another node removed the source inode while we
699 * were in the vfs.
700 */
701 if (old_de_ino != OCFS2_I(inode)->ip_blkno) {
702 err = -ENOENT;
703 goto out;
704 }
705
689 err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name, 706 err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
690 dentry->d_name.len); 707 dentry->d_name.len);
691 if (err) 708 if (err)
diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c
index aaa50611ec66..d7b5108789e2 100644
--- a/fs/ocfs2/quota_global.c
+++ b/fs/ocfs2/quota_global.c
@@ -717,6 +717,12 @@ static int ocfs2_release_dquot(struct dquot *dquot)
717 */ 717 */
718 if (status < 0) 718 if (status < 0)
719 mlog_errno(status); 719 mlog_errno(status);
720 /*
721 * Clear dq_off so that we search for the structure in quota file next
722 * time we acquire it. The structure might be deleted and reallocated
723 * elsewhere by another node while our dquot structure is on freelist.
724 */
725 dquot->dq_off = 0;
720 clear_bit(DQ_ACTIVE_B, &dquot->dq_flags); 726 clear_bit(DQ_ACTIVE_B, &dquot->dq_flags);
721out_trans: 727out_trans:
722 ocfs2_commit_trans(osb, handle); 728 ocfs2_commit_trans(osb, handle);
@@ -756,16 +762,17 @@ static int ocfs2_acquire_dquot(struct dquot *dquot)
756 status = ocfs2_lock_global_qf(info, 1); 762 status = ocfs2_lock_global_qf(info, 1);
757 if (status < 0) 763 if (status < 0)
758 goto out; 764 goto out;
759 if (!test_bit(DQ_READ_B, &dquot->dq_flags)) { 765 status = ocfs2_qinfo_lock(info, 0);
760 status = ocfs2_qinfo_lock(info, 0); 766 if (status < 0)
761 if (status < 0) 767 goto out_dq;
762 goto out_dq; 768 /*
763 status = qtree_read_dquot(&info->dqi_gi, dquot); 769 * We always want to read dquot structure from disk because we don't
764 ocfs2_qinfo_unlock(info, 0); 770 * know what happened with it while it was on freelist.
765 if (status < 0) 771 */
766 goto out_dq; 772 status = qtree_read_dquot(&info->dqi_gi, dquot);
767 } 773 ocfs2_qinfo_unlock(info, 0);
768 set_bit(DQ_READ_B, &dquot->dq_flags); 774 if (status < 0)
775 goto out_dq;
769 776
770 OCFS2_DQUOT(dquot)->dq_use_count++; 777 OCFS2_DQUOT(dquot)->dq_use_count++;
771 OCFS2_DQUOT(dquot)->dq_origspace = dquot->dq_dqb.dqb_curspace; 778 OCFS2_DQUOT(dquot)->dq_origspace = dquot->dq_dqb.dqb_curspace;
diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
index 2e4344be3b96..2001862bf2b1 100644
--- a/fs/ocfs2/quota_local.c
+++ b/fs/ocfs2/quota_local.c
@@ -1303,10 +1303,6 @@ int ocfs2_local_release_dquot(handle_t *handle, struct dquot *dquot)
1303 ocfs2_journal_dirty(handle, od->dq_chunk->qc_headerbh); 1303 ocfs2_journal_dirty(handle, od->dq_chunk->qc_headerbh);
1304 1304
1305out: 1305out:
1306 /* Clear the read bit so that next time someone uses this
1307 * dquot he reads fresh info from disk and allocates local
1308 * dquot structure */
1309 clear_bit(DQ_READ_B, &dquot->dq_flags);
1310 return status; 1306 return status;
1311} 1307}
1312 1308
diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c
index 1324e6600e57..ca5ce14cbddc 100644
--- a/fs/ocfs2/stackglue.c
+++ b/fs/ocfs2/stackglue.c
@@ -346,7 +346,9 @@ int ocfs2_cluster_connect(const char *stack_name,
346 346
347 strlcpy(new_conn->cc_name, group, GROUP_NAME_MAX + 1); 347 strlcpy(new_conn->cc_name, group, GROUP_NAME_MAX + 1);
348 new_conn->cc_namelen = grouplen; 348 new_conn->cc_namelen = grouplen;
349 strlcpy(new_conn->cc_cluster_name, cluster_name, CLUSTER_NAME_MAX + 1); 349 if (cluster_name_len)
350 strlcpy(new_conn->cc_cluster_name, cluster_name,
351 CLUSTER_NAME_MAX + 1);
350 new_conn->cc_cluster_name_len = cluster_name_len; 352 new_conn->cc_cluster_name_len = cluster_name_len;
351 new_conn->cc_recovery_handler = recovery_handler; 353 new_conn->cc_recovery_handler = recovery_handler;
352 new_conn->cc_recovery_data = recovery_data; 354 new_conn->cc_recovery_data = recovery_data;
diff --git a/fs/open.c b/fs/open.c
index 4b3e1edf2fe4..b9ed8b25c108 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -705,6 +705,10 @@ static int do_dentry_open(struct file *f,
705 return 0; 705 return 0;
706 } 706 }
707 707
708 /* POSIX.1-2008/SUSv4 Section XSI 2.9.7 */
709 if (S_ISREG(inode->i_mode))
710 f->f_mode |= FMODE_ATOMIC_POS;
711
708 f->f_op = fops_get(inode->i_fop); 712 f->f_op = fops_get(inode->i_fop);
709 if (unlikely(WARN_ON(!f->f_op))) { 713 if (unlikely(WARN_ON(!f->f_op))) {
710 error = -ENODEV; 714 error = -ENODEV;
diff --git a/fs/pnode.c b/fs/pnode.c
index c7221bb19801..88396df725b4 100644
--- a/fs/pnode.c
+++ b/fs/pnode.c
@@ -220,14 +220,14 @@ static struct mount *get_source(struct mount *dest,
220 * @tree_list : list of heads of trees to be attached. 220 * @tree_list : list of heads of trees to be attached.
221 */ 221 */
222int propagate_mnt(struct mount *dest_mnt, struct mountpoint *dest_mp, 222int propagate_mnt(struct mount *dest_mnt, struct mountpoint *dest_mp,
223 struct mount *source_mnt, struct list_head *tree_list) 223 struct mount *source_mnt, struct hlist_head *tree_list)
224{ 224{
225 struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns; 225 struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
226 struct mount *m, *child; 226 struct mount *m, *child;
227 int ret = 0; 227 int ret = 0;
228 struct mount *prev_dest_mnt = dest_mnt; 228 struct mount *prev_dest_mnt = dest_mnt;
229 struct mount *prev_src_mnt = source_mnt; 229 struct mount *prev_src_mnt = source_mnt;
230 LIST_HEAD(tmp_list); 230 HLIST_HEAD(tmp_list);
231 231
232 for (m = propagation_next(dest_mnt, dest_mnt); m; 232 for (m = propagation_next(dest_mnt, dest_mnt); m;
233 m = propagation_next(m, dest_mnt)) { 233 m = propagation_next(m, dest_mnt)) {
@@ -246,27 +246,29 @@ int propagate_mnt(struct mount *dest_mnt, struct mountpoint *dest_mp,
246 child = copy_tree(source, source->mnt.mnt_root, type); 246 child = copy_tree(source, source->mnt.mnt_root, type);
247 if (IS_ERR(child)) { 247 if (IS_ERR(child)) {
248 ret = PTR_ERR(child); 248 ret = PTR_ERR(child);
249 list_splice(tree_list, tmp_list.prev); 249 tmp_list = *tree_list;
250 tmp_list.first->pprev = &tmp_list.first;
251 INIT_HLIST_HEAD(tree_list);
250 goto out; 252 goto out;
251 } 253 }
252 254
253 if (is_subdir(dest_mp->m_dentry, m->mnt.mnt_root)) { 255 if (is_subdir(dest_mp->m_dentry, m->mnt.mnt_root)) {
254 mnt_set_mountpoint(m, dest_mp, child); 256 mnt_set_mountpoint(m, dest_mp, child);
255 list_add_tail(&child->mnt_hash, tree_list); 257 hlist_add_head(&child->mnt_hash, tree_list);
256 } else { 258 } else {
257 /* 259 /*
258 * This can happen if the parent mount was bind mounted 260 * This can happen if the parent mount was bind mounted
259 * on some subdirectory of a shared/slave mount. 261 * on some subdirectory of a shared/slave mount.
260 */ 262 */
261 list_add_tail(&child->mnt_hash, &tmp_list); 263 hlist_add_head(&child->mnt_hash, &tmp_list);
262 } 264 }
263 prev_dest_mnt = m; 265 prev_dest_mnt = m;
264 prev_src_mnt = child; 266 prev_src_mnt = child;
265 } 267 }
266out: 268out:
267 lock_mount_hash(); 269 lock_mount_hash();
268 while (!list_empty(&tmp_list)) { 270 while (!hlist_empty(&tmp_list)) {
269 child = list_first_entry(&tmp_list, struct mount, mnt_hash); 271 child = hlist_entry(tmp_list.first, struct mount, mnt_hash);
270 umount_tree(child, 0); 272 umount_tree(child, 0);
271 } 273 }
272 unlock_mount_hash(); 274 unlock_mount_hash();
@@ -338,8 +340,10 @@ static void __propagate_umount(struct mount *mnt)
338 * umount the child only if the child has no 340 * umount the child only if the child has no
339 * other children 341 * other children
340 */ 342 */
341 if (child && list_empty(&child->mnt_mounts)) 343 if (child && list_empty(&child->mnt_mounts)) {
342 list_move_tail(&child->mnt_hash, &mnt->mnt_hash); 344 hlist_del_init_rcu(&child->mnt_hash);
345 hlist_add_before_rcu(&child->mnt_hash, &mnt->mnt_hash);
346 }
343 } 347 }
344} 348}
345 349
@@ -350,11 +354,11 @@ static void __propagate_umount(struct mount *mnt)
350 * 354 *
351 * vfsmount lock must be held for write 355 * vfsmount lock must be held for write
352 */ 356 */
353int propagate_umount(struct list_head *list) 357int propagate_umount(struct hlist_head *list)
354{ 358{
355 struct mount *mnt; 359 struct mount *mnt;
356 360
357 list_for_each_entry(mnt, list, mnt_hash) 361 hlist_for_each_entry(mnt, list, mnt_hash)
358 __propagate_umount(mnt); 362 __propagate_umount(mnt);
359 return 0; 363 return 0;
360} 364}
diff --git a/fs/pnode.h b/fs/pnode.h
index 59e7eda1851e..fc28a27fa892 100644
--- a/fs/pnode.h
+++ b/fs/pnode.h
@@ -36,8 +36,8 @@ static inline void set_mnt_shared(struct mount *mnt)
36 36
37void change_mnt_propagation(struct mount *, int); 37void change_mnt_propagation(struct mount *, int);
38int propagate_mnt(struct mount *, struct mountpoint *, struct mount *, 38int propagate_mnt(struct mount *, struct mountpoint *, struct mount *,
39 struct list_head *); 39 struct hlist_head *);
40int propagate_umount(struct list_head *); 40int propagate_umount(struct hlist_head *);
41int propagate_mount_busy(struct mount *, int); 41int propagate_mount_busy(struct mount *, int);
42void mnt_release_group_id(struct mount *); 42void mnt_release_group_id(struct mount *);
43int get_dominating_id(struct mount *mnt, const struct path *root); 43int get_dominating_id(struct mount *mnt, const struct path *root);
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 38bae5a0ea25..11c54fd51e16 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -521,8 +521,11 @@ posix_acl_chmod(struct inode *inode, umode_t mode)
521 return -EOPNOTSUPP; 521 return -EOPNOTSUPP;
522 522
523 acl = get_acl(inode, ACL_TYPE_ACCESS); 523 acl = get_acl(inode, ACL_TYPE_ACCESS);
524 if (IS_ERR_OR_NULL(acl)) 524 if (IS_ERR_OR_NULL(acl)) {
525 if (acl == ERR_PTR(-EOPNOTSUPP))
526 return 0;
525 return PTR_ERR(acl); 527 return PTR_ERR(acl);
528 }
526 529
527 ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode); 530 ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
528 if (ret) 531 if (ret)
@@ -544,14 +547,15 @@ posix_acl_create(struct inode *dir, umode_t *mode,
544 goto no_acl; 547 goto no_acl;
545 548
546 p = get_acl(dir, ACL_TYPE_DEFAULT); 549 p = get_acl(dir, ACL_TYPE_DEFAULT);
547 if (IS_ERR(p)) 550 if (IS_ERR(p)) {
551 if (p == ERR_PTR(-EOPNOTSUPP))
552 goto apply_umask;
548 return PTR_ERR(p); 553 return PTR_ERR(p);
549
550 if (!p) {
551 *mode &= ~current_umask();
552 goto no_acl;
553 } 554 }
554 555
556 if (!p)
557 goto apply_umask;
558
555 *acl = posix_acl_clone(p, GFP_NOFS); 559 *acl = posix_acl_clone(p, GFP_NOFS);
556 if (!*acl) 560 if (!*acl)
557 return -ENOMEM; 561 return -ENOMEM;
@@ -575,6 +579,8 @@ posix_acl_create(struct inode *dir, umode_t *mode,
575 } 579 }
576 return 0; 580 return 0;
577 581
582apply_umask:
583 *mode &= ~current_umask();
578no_acl: 584no_acl:
579 *default_acl = NULL; 585 *default_acl = NULL;
580 *acl = NULL; 586 *acl = NULL;
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 51507065263b..b9760628e1fd 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1824,6 +1824,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
1824 if (rc) 1824 if (rc)
1825 goto out_mmput; 1825 goto out_mmput;
1826 1826
1827 rc = -ENOENT;
1827 down_read(&mm->mmap_sem); 1828 down_read(&mm->mmap_sem);
1828 vma = find_exact_vma(mm, vm_start, vm_end); 1829 vma = find_exact_vma(mm, vm_start, vm_end);
1829 if (vma && vma->vm_file) { 1830 if (vma && vma->vm_file) {
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 02174a610315..e647c55275d9 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -121,9 +121,8 @@ u64 stable_page_flags(struct page *page)
121 * just checks PG_head/PG_tail, so we need to check PageLRU/PageAnon 121 * just checks PG_head/PG_tail, so we need to check PageLRU/PageAnon
122 * to make sure a given page is a thp, not a non-huge compound page. 122 * to make sure a given page is a thp, not a non-huge compound page.
123 */ 123 */
124 else if (PageTransCompound(page) && 124 else if (PageTransCompound(page) && (PageLRU(compound_head(page)) ||
125 (PageLRU(compound_trans_head(page)) || 125 PageAnon(compound_head(page))))
126 PageAnon(compound_trans_head(page))))
127 u |= 1 << KPF_THP; 126 u |= 1 << KPF_THP;
128 127
129 /* 128 /*
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 2ca7ba047f04..88d4585b30f1 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -468,17 +468,24 @@ static int __init update_note_header_size_elf64(const Elf64_Ehdr *ehdr_ptr)
468 return rc; 468 return rc;
469 } 469 }
470 nhdr_ptr = notes_section; 470 nhdr_ptr = notes_section;
471 while (real_sz < max_sz) { 471 while (nhdr_ptr->n_namesz != 0) {
472 if (nhdr_ptr->n_namesz == 0)
473 break;
474 sz = sizeof(Elf64_Nhdr) + 472 sz = sizeof(Elf64_Nhdr) +
475 ((nhdr_ptr->n_namesz + 3) & ~3) + 473 ((nhdr_ptr->n_namesz + 3) & ~3) +
476 ((nhdr_ptr->n_descsz + 3) & ~3); 474 ((nhdr_ptr->n_descsz + 3) & ~3);
475 if ((real_sz + sz) > max_sz) {
476 pr_warn("Warning: Exceeded p_memsz, dropping PT_NOTE entry n_namesz=0x%x, n_descsz=0x%x\n",
477 nhdr_ptr->n_namesz, nhdr_ptr->n_descsz);
478 break;
479 }
477 real_sz += sz; 480 real_sz += sz;
478 nhdr_ptr = (Elf64_Nhdr*)((char*)nhdr_ptr + sz); 481 nhdr_ptr = (Elf64_Nhdr*)((char*)nhdr_ptr + sz);
479 } 482 }
480 kfree(notes_section); 483 kfree(notes_section);
481 phdr_ptr->p_memsz = real_sz; 484 phdr_ptr->p_memsz = real_sz;
485 if (real_sz == 0) {
486 pr_warn("Warning: Zero PT_NOTE entries found\n");
487 return -EINVAL;
488 }
482 } 489 }
483 490
484 return 0; 491 return 0;
@@ -648,17 +655,24 @@ static int __init update_note_header_size_elf32(const Elf32_Ehdr *ehdr_ptr)
648 return rc; 655 return rc;
649 } 656 }
650 nhdr_ptr = notes_section; 657 nhdr_ptr = notes_section;
651 while (real_sz < max_sz) { 658 while (nhdr_ptr->n_namesz != 0) {
652 if (nhdr_ptr->n_namesz == 0)
653 break;
654 sz = sizeof(Elf32_Nhdr) + 659 sz = sizeof(Elf32_Nhdr) +
655 ((nhdr_ptr->n_namesz + 3) & ~3) + 660 ((nhdr_ptr->n_namesz + 3) & ~3) +
656 ((nhdr_ptr->n_descsz + 3) & ~3); 661 ((nhdr_ptr->n_descsz + 3) & ~3);
662 if ((real_sz + sz) > max_sz) {
663 pr_warn("Warning: Exceeded p_memsz, dropping PT_NOTE entry n_namesz=0x%x, n_descsz=0x%x\n",
664 nhdr_ptr->n_namesz, nhdr_ptr->n_descsz);
665 break;
666 }
657 real_sz += sz; 667 real_sz += sz;
658 nhdr_ptr = (Elf32_Nhdr*)((char*)nhdr_ptr + sz); 668 nhdr_ptr = (Elf32_Nhdr*)((char*)nhdr_ptr + sz);
659 } 669 }
660 kfree(notes_section); 670 kfree(notes_section);
661 phdr_ptr->p_memsz = real_sz; 671 phdr_ptr->p_memsz = real_sz;
672 if (real_sz == 0) {
673 pr_warn("Warning: Zero PT_NOTE entries found\n");
674 return -EINVAL;
675 }
662 } 676 }
663 677
664 return 0; 678 return 0;
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 831d49a4111f..cfc8dcc16043 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -581,9 +581,17 @@ int dquot_scan_active(struct super_block *sb,
581 dqstats_inc(DQST_LOOKUPS); 581 dqstats_inc(DQST_LOOKUPS);
582 dqput(old_dquot); 582 dqput(old_dquot);
583 old_dquot = dquot; 583 old_dquot = dquot;
584 ret = fn(dquot, priv); 584 /*
585 if (ret < 0) 585 * ->release_dquot() can be racing with us. Our reference
586 goto out; 586 * protects us from new calls to it so just wait for any
587 * outstanding call and recheck the DQ_ACTIVE_B after that.
588 */
589 wait_on_dquot(dquot);
590 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
591 ret = fn(dquot, priv);
592 if (ret < 0)
593 goto out;
594 }
587 spin_lock(&dq_list_lock); 595 spin_lock(&dq_list_lock);
588 /* We are safe to continue now because our dquot could not 596 /* We are safe to continue now because our dquot could not
589 * be moved out of the inuse list while we hold the reference */ 597 * be moved out of the inuse list while we hold the reference */
diff --git a/fs/read_write.c b/fs/read_write.c
index edc5746a902a..31c6efa43183 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -264,10 +264,22 @@ loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
264} 264}
265EXPORT_SYMBOL(vfs_llseek); 265EXPORT_SYMBOL(vfs_llseek);
266 266
267static inline struct fd fdget_pos(int fd)
268{
269 return __to_fd(__fdget_pos(fd));
270}
271
272static inline void fdput_pos(struct fd f)
273{
274 if (f.flags & FDPUT_POS_UNLOCK)
275 mutex_unlock(&f.file->f_pos_lock);
276 fdput(f);
277}
278
267SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence) 279SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence)
268{ 280{
269 off_t retval; 281 off_t retval;
270 struct fd f = fdget(fd); 282 struct fd f = fdget_pos(fd);
271 if (!f.file) 283 if (!f.file)
272 return -EBADF; 284 return -EBADF;
273 285
@@ -278,7 +290,7 @@ SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence)
278 if (res != (loff_t)retval) 290 if (res != (loff_t)retval)
279 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */ 291 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
280 } 292 }
281 fdput(f); 293 fdput_pos(f);
282 return retval; 294 return retval;
283} 295}
284 296
@@ -295,7 +307,7 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
295 unsigned int, whence) 307 unsigned int, whence)
296{ 308{
297 int retval; 309 int retval;
298 struct fd f = fdget(fd); 310 struct fd f = fdget_pos(fd);
299 loff_t offset; 311 loff_t offset;
300 312
301 if (!f.file) 313 if (!f.file)
@@ -315,7 +327,7 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
315 retval = 0; 327 retval = 0;
316 } 328 }
317out_putf: 329out_putf:
318 fdput(f); 330 fdput_pos(f);
319 return retval; 331 return retval;
320} 332}
321#endif 333#endif
@@ -498,7 +510,7 @@ static inline void file_pos_write(struct file *file, loff_t pos)
498 510
499SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count) 511SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
500{ 512{
501 struct fd f = fdget(fd); 513 struct fd f = fdget_pos(fd);
502 ssize_t ret = -EBADF; 514 ssize_t ret = -EBADF;
503 515
504 if (f.file) { 516 if (f.file) {
@@ -506,7 +518,7 @@ SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
506 ret = vfs_read(f.file, buf, count, &pos); 518 ret = vfs_read(f.file, buf, count, &pos);
507 if (ret >= 0) 519 if (ret >= 0)
508 file_pos_write(f.file, pos); 520 file_pos_write(f.file, pos);
509 fdput(f); 521 fdput_pos(f);
510 } 522 }
511 return ret; 523 return ret;
512} 524}
@@ -514,7 +526,7 @@ SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
514SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, 526SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
515 size_t, count) 527 size_t, count)
516{ 528{
517 struct fd f = fdget(fd); 529 struct fd f = fdget_pos(fd);
518 ssize_t ret = -EBADF; 530 ssize_t ret = -EBADF;
519 531
520 if (f.file) { 532 if (f.file) {
@@ -522,7 +534,7 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
522 ret = vfs_write(f.file, buf, count, &pos); 534 ret = vfs_write(f.file, buf, count, &pos);
523 if (ret >= 0) 535 if (ret >= 0)
524 file_pos_write(f.file, pos); 536 file_pos_write(f.file, pos);
525 fdput(f); 537 fdput_pos(f);
526 } 538 }
527 539
528 return ret; 540 return ret;
@@ -797,7 +809,7 @@ EXPORT_SYMBOL(vfs_writev);
797SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec, 809SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
798 unsigned long, vlen) 810 unsigned long, vlen)
799{ 811{
800 struct fd f = fdget(fd); 812 struct fd f = fdget_pos(fd);
801 ssize_t ret = -EBADF; 813 ssize_t ret = -EBADF;
802 814
803 if (f.file) { 815 if (f.file) {
@@ -805,7 +817,7 @@ SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
805 ret = vfs_readv(f.file, vec, vlen, &pos); 817 ret = vfs_readv(f.file, vec, vlen, &pos);
806 if (ret >= 0) 818 if (ret >= 0)
807 file_pos_write(f.file, pos); 819 file_pos_write(f.file, pos);
808 fdput(f); 820 fdput_pos(f);
809 } 821 }
810 822
811 if (ret > 0) 823 if (ret > 0)
@@ -817,7 +829,7 @@ SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
817SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec, 829SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
818 unsigned long, vlen) 830 unsigned long, vlen)
819{ 831{
820 struct fd f = fdget(fd); 832 struct fd f = fdget_pos(fd);
821 ssize_t ret = -EBADF; 833 ssize_t ret = -EBADF;
822 834
823 if (f.file) { 835 if (f.file) {
@@ -825,7 +837,7 @@ SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
825 ret = vfs_writev(f.file, vec, vlen, &pos); 837 ret = vfs_writev(f.file, vec, vlen, &pos);
826 if (ret >= 0) 838 if (ret >= 0)
827 file_pos_write(f.file, pos); 839 file_pos_write(f.file, pos);
828 fdput(f); 840 fdput_pos(f);
829 } 841 }
830 842
831 if (ret > 0) 843 if (ret > 0)
@@ -968,7 +980,7 @@ COMPAT_SYSCALL_DEFINE3(readv, compat_ulong_t, fd,
968 const struct compat_iovec __user *,vec, 980 const struct compat_iovec __user *,vec,
969 compat_ulong_t, vlen) 981 compat_ulong_t, vlen)
970{ 982{
971 struct fd f = fdget(fd); 983 struct fd f = fdget_pos(fd);
972 ssize_t ret; 984 ssize_t ret;
973 loff_t pos; 985 loff_t pos;
974 986
@@ -978,13 +990,13 @@ COMPAT_SYSCALL_DEFINE3(readv, compat_ulong_t, fd,
978 ret = compat_readv(f.file, vec, vlen, &pos); 990 ret = compat_readv(f.file, vec, vlen, &pos);
979 if (ret >= 0) 991 if (ret >= 0)
980 f.file->f_pos = pos; 992 f.file->f_pos = pos;
981 fdput(f); 993 fdput_pos(f);
982 return ret; 994 return ret;
983} 995}
984 996
985COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd, 997static long __compat_sys_preadv64(unsigned long fd,
986 const struct compat_iovec __user *,vec, 998 const struct compat_iovec __user *vec,
987 unsigned long, vlen, loff_t, pos) 999 unsigned long vlen, loff_t pos)
988{ 1000{
989 struct fd f; 1001 struct fd f;
990 ssize_t ret; 1002 ssize_t ret;
@@ -1001,12 +1013,22 @@ COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd,
1001 return ret; 1013 return ret;
1002} 1014}
1003 1015
1016#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64
1017COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd,
1018 const struct compat_iovec __user *,vec,
1019 unsigned long, vlen, loff_t, pos)
1020{
1021 return __compat_sys_preadv64(fd, vec, vlen, pos);
1022}
1023#endif
1024
1004COMPAT_SYSCALL_DEFINE5(preadv, compat_ulong_t, fd, 1025COMPAT_SYSCALL_DEFINE5(preadv, compat_ulong_t, fd,
1005 const struct compat_iovec __user *,vec, 1026 const struct compat_iovec __user *,vec,
1006 compat_ulong_t, vlen, u32, pos_low, u32, pos_high) 1027 compat_ulong_t, vlen, u32, pos_low, u32, pos_high)
1007{ 1028{
1008 loff_t pos = ((loff_t)pos_high << 32) | pos_low; 1029 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1009 return compat_sys_preadv64(fd, vec, vlen, pos); 1030
1031 return __compat_sys_preadv64(fd, vec, vlen, pos);
1010} 1032}
1011 1033
1012static size_t compat_writev(struct file *file, 1034static size_t compat_writev(struct file *file,
@@ -1035,7 +1057,7 @@ COMPAT_SYSCALL_DEFINE3(writev, compat_ulong_t, fd,
1035 const struct compat_iovec __user *, vec, 1057 const struct compat_iovec __user *, vec,
1036 compat_ulong_t, vlen) 1058 compat_ulong_t, vlen)
1037{ 1059{
1038 struct fd f = fdget(fd); 1060 struct fd f = fdget_pos(fd);
1039 ssize_t ret; 1061 ssize_t ret;
1040 loff_t pos; 1062 loff_t pos;
1041 1063
@@ -1045,13 +1067,13 @@ COMPAT_SYSCALL_DEFINE3(writev, compat_ulong_t, fd,
1045 ret = compat_writev(f.file, vec, vlen, &pos); 1067 ret = compat_writev(f.file, vec, vlen, &pos);
1046 if (ret >= 0) 1068 if (ret >= 0)
1047 f.file->f_pos = pos; 1069 f.file->f_pos = pos;
1048 fdput(f); 1070 fdput_pos(f);
1049 return ret; 1071 return ret;
1050} 1072}
1051 1073
1052COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd, 1074static long __compat_sys_pwritev64(unsigned long fd,
1053 const struct compat_iovec __user *,vec, 1075 const struct compat_iovec __user *vec,
1054 unsigned long, vlen, loff_t, pos) 1076 unsigned long vlen, loff_t pos)
1055{ 1077{
1056 struct fd f; 1078 struct fd f;
1057 ssize_t ret; 1079 ssize_t ret;
@@ -1068,12 +1090,22 @@ COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd,
1068 return ret; 1090 return ret;
1069} 1091}
1070 1092
1093#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64
1094COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd,
1095 const struct compat_iovec __user *,vec,
1096 unsigned long, vlen, loff_t, pos)
1097{
1098 return __compat_sys_pwritev64(fd, vec, vlen, pos);
1099}
1100#endif
1101
1071COMPAT_SYSCALL_DEFINE5(pwritev, compat_ulong_t, fd, 1102COMPAT_SYSCALL_DEFINE5(pwritev, compat_ulong_t, fd,
1072 const struct compat_iovec __user *,vec, 1103 const struct compat_iovec __user *,vec,
1073 compat_ulong_t, vlen, u32, pos_low, u32, pos_high) 1104 compat_ulong_t, vlen, u32, pos_low, u32, pos_high)
1074{ 1105{
1075 loff_t pos = ((loff_t)pos_high << 32) | pos_low; 1106 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1076 return compat_sys_pwritev64(fd, vec, vlen, pos); 1107
1108 return __compat_sys_pwritev64(fd, vec, vlen, pos);
1077} 1109}
1078#endif 1110#endif
1079 1111
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 2b7882b508db..9a3c68cf6026 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -324,23 +324,17 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
324 switch (flag) { 324 switch (flag) {
325 case M_INSERT: /* insert item into L[0] */ 325 case M_INSERT: /* insert item into L[0] */
326 326
327 if (item_pos == tb->lnum[0] - 1 327 if (item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) {
328 && tb->lbytes != -1) {
329 /* part of new item falls into L[0] */ 328 /* part of new item falls into L[0] */
330 int new_item_len; 329 int new_item_len;
331 int version; 330 int version;
332 331
333 ret_val = 332 ret_val = leaf_shift_left(tb, tb->lnum[0] - 1, -1);
334 leaf_shift_left(tb, tb->lnum[0] - 1,
335 -1);
336 333
337 /* Calculate item length to insert to S[0] */ 334 /* Calculate item length to insert to S[0] */
338 new_item_len = 335 new_item_len = ih_item_len(ih) - tb->lbytes;
339 ih_item_len(ih) - tb->lbytes;
340 /* Calculate and check item length to insert to L[0] */ 336 /* Calculate and check item length to insert to L[0] */
341 put_ih_item_len(ih, 337 put_ih_item_len(ih, ih_item_len(ih) - new_item_len);
342 ih_item_len(ih) -
343 new_item_len);
344 338
345 RFALSE(ih_item_len(ih) <= 0, 339 RFALSE(ih_item_len(ih) <= 0,
346 "PAP-12080: there is nothing to insert into L[0]: ih_item_len=%d", 340 "PAP-12080: there is nothing to insert into L[0]: ih_item_len=%d",
@@ -349,30 +343,18 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
349 /* Insert new item into L[0] */ 343 /* Insert new item into L[0] */
350 buffer_info_init_left(tb, &bi); 344 buffer_info_init_left(tb, &bi);
351 leaf_insert_into_buf(&bi, 345 leaf_insert_into_buf(&bi,
352 n + item_pos - 346 n + item_pos - ret_val, ih, body,
353 ret_val, ih, body, 347 zeros_num > ih_item_len(ih) ? ih_item_len(ih) : zeros_num);
354 zeros_num >
355 ih_item_len(ih) ?
356 ih_item_len(ih) :
357 zeros_num);
358 348
359 version = ih_version(ih); 349 version = ih_version(ih);
360 350
361 /* Calculate key component, item length and body to insert into S[0] */ 351 /* Calculate key component, item length and body to insert into S[0] */
362 set_le_ih_k_offset(ih, 352 set_le_ih_k_offset(ih, le_ih_k_offset(ih) +
363 le_ih_k_offset(ih) + 353 (tb-> lbytes << (is_indirect_le_ih(ih) ? tb->tb_sb-> s_blocksize_bits - UNFM_P_SHIFT : 0)));
364 (tb->
365 lbytes <<
366 (is_indirect_le_ih
367 (ih) ? tb->tb_sb->
368 s_blocksize_bits -
369 UNFM_P_SHIFT :
370 0)));
371 354
372 put_ih_item_len(ih, new_item_len); 355 put_ih_item_len(ih, new_item_len);
373 if (tb->lbytes > zeros_num) { 356 if (tb->lbytes > zeros_num) {
374 body += 357 body += (tb->lbytes - zeros_num);
375 (tb->lbytes - zeros_num);
376 zeros_num = 0; 358 zeros_num = 0;
377 } else 359 } else
378 zeros_num -= tb->lbytes; 360 zeros_num -= tb->lbytes;
@@ -383,15 +365,10 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
383 } else { 365 } else {
384 /* new item in whole falls into L[0] */ 366 /* new item in whole falls into L[0] */
385 /* Shift lnum[0]-1 items to L[0] */ 367 /* Shift lnum[0]-1 items to L[0] */
386 ret_val = 368 ret_val = leaf_shift_left(tb, tb->lnum[0] - 1, tb->lbytes);
387 leaf_shift_left(tb, tb->lnum[0] - 1,
388 tb->lbytes);
389 /* Insert new item into L[0] */ 369 /* Insert new item into L[0] */
390 buffer_info_init_left(tb, &bi); 370 buffer_info_init_left(tb, &bi);
391 leaf_insert_into_buf(&bi, 371 leaf_insert_into_buf(&bi, n + item_pos - ret_val, ih, body, zeros_num);
392 n + item_pos -
393 ret_val, ih, body,
394 zeros_num);
395 tb->insert_size[0] = 0; 372 tb->insert_size[0] = 0;
396 zeros_num = 0; 373 zeros_num = 0;
397 } 374 }
@@ -399,264 +376,117 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
399 376
400 case M_PASTE: /* append item in L[0] */ 377 case M_PASTE: /* append item in L[0] */
401 378
402 if (item_pos == tb->lnum[0] - 1 379 if (item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) {
403 && tb->lbytes != -1) {
404 /* we must shift the part of the appended item */ 380 /* we must shift the part of the appended item */
405 if (is_direntry_le_ih 381 if (is_direntry_le_ih(B_N_PITEM_HEAD(tbS0, item_pos))) {
406 (B_N_PITEM_HEAD(tbS0, item_pos))) {
407 382
408 RFALSE(zeros_num, 383 RFALSE(zeros_num,
409 "PAP-12090: invalid parameter in case of a directory"); 384 "PAP-12090: invalid parameter in case of a directory");
410 /* directory item */ 385 /* directory item */
411 if (tb->lbytes > pos_in_item) { 386 if (tb->lbytes > pos_in_item) {
412 /* new directory entry falls into L[0] */ 387 /* new directory entry falls into L[0] */
413 struct item_head 388 struct item_head *pasted;
414 *pasted; 389 int l_pos_in_item = pos_in_item;
415 int l_pos_in_item =
416 pos_in_item;
417 390
418 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 entries from given directory item */ 391 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 entries from given directory item */
419 ret_val = 392 ret_val = leaf_shift_left(tb, tb->lnum[0], tb->lbytes-1);
420 leaf_shift_left(tb, 393 if (ret_val && !item_pos) {
421 tb-> 394 pasted = B_N_PITEM_HEAD(tb->L[0], B_NR_ITEMS(tb->L[0]) - 1);
422 lnum 395 l_pos_in_item += I_ENTRY_COUNT(pasted) - (tb->lbytes -1);
423 [0],
424 tb->
425 lbytes
426 -
427 1);
428 if (ret_val
429 && !item_pos) {
430 pasted =
431 B_N_PITEM_HEAD
432 (tb->L[0],
433 B_NR_ITEMS
434 (tb->
435 L[0]) -
436 1);
437 l_pos_in_item +=
438 I_ENTRY_COUNT
439 (pasted) -
440 (tb->
441 lbytes -
442 1);
443 } 396 }
444 397
445 /* Append given directory entry to directory item */ 398 /* Append given directory entry to directory item */
446 buffer_info_init_left(tb, &bi); 399 buffer_info_init_left(tb, &bi);
447 leaf_paste_in_buffer 400 leaf_paste_in_buffer(&bi, n + item_pos - ret_val, l_pos_in_item, tb->insert_size[0], body, zeros_num);
448 (&bi,
449 n + item_pos -
450 ret_val,
451 l_pos_in_item,
452 tb->insert_size[0],
453 body, zeros_num);
454 401
455 /* previous string prepared space for pasting new entry, following string pastes this entry */ 402 /* previous string prepared space for pasting new entry, following string pastes this entry */
456 403
457 /* when we have merge directory item, pos_in_item has been changed too */ 404 /* when we have merge directory item, pos_in_item has been changed too */
458 405
459 /* paste new directory entry. 1 is entry number */ 406 /* paste new directory entry. 1 is entry number */
460 leaf_paste_entries(&bi, 407 leaf_paste_entries(&bi, n + item_pos - ret_val, l_pos_in_item,
461 n + 408 1, (struct reiserfs_de_head *) body,
462 item_pos 409 body + DEH_SIZE, tb->insert_size[0]);
463 -
464 ret_val,
465 l_pos_in_item,
466 1,
467 (struct
468 reiserfs_de_head
469 *)
470 body,
471 body
472 +
473 DEH_SIZE,
474 tb->
475 insert_size
476 [0]
477 );
478 tb->insert_size[0] = 0; 410 tb->insert_size[0] = 0;
479 } else { 411 } else {
480 /* new directory item doesn't fall into L[0] */ 412 /* new directory item doesn't fall into L[0] */
481 /* Shift lnum[0]-1 items in whole. Shift lbytes directory entries from directory item number lnum[0] */ 413 /* Shift lnum[0]-1 items in whole. Shift lbytes directory entries from directory item number lnum[0] */
482 leaf_shift_left(tb, 414 leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
483 tb->
484 lnum[0],
485 tb->
486 lbytes);
487 } 415 }
488 /* Calculate new position to append in item body */ 416 /* Calculate new position to append in item body */
489 pos_in_item -= tb->lbytes; 417 pos_in_item -= tb->lbytes;
490 } else { 418 } else {
491 /* regular object */ 419 /* regular object */
492 RFALSE(tb->lbytes <= 0, 420 RFALSE(tb->lbytes <= 0, "PAP-12095: there is nothing to shift to L[0]. lbytes=%d", tb->lbytes);
493 "PAP-12095: there is nothing to shift to L[0]. lbytes=%d", 421 RFALSE(pos_in_item != ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)),
494 tb->lbytes);
495 RFALSE(pos_in_item !=
496 ih_item_len
497 (B_N_PITEM_HEAD
498 (tbS0, item_pos)),
499 "PAP-12100: incorrect position to paste: item_len=%d, pos_in_item=%d", 422 "PAP-12100: incorrect position to paste: item_len=%d, pos_in_item=%d",
500 ih_item_len 423 ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)),pos_in_item);
501 (B_N_PITEM_HEAD
502 (tbS0, item_pos)),
503 pos_in_item);
504 424
505 if (tb->lbytes >= pos_in_item) { 425 if (tb->lbytes >= pos_in_item) {
506 /* appended item will be in L[0] in whole */ 426 /* appended item will be in L[0] in whole */
507 int l_n; 427 int l_n;
508 428
509 /* this bytes number must be appended to the last item of L[h] */ 429 /* this bytes number must be appended to the last item of L[h] */
510 l_n = 430 l_n = tb->lbytes - pos_in_item;
511 tb->lbytes -
512 pos_in_item;
513 431
514 /* Calculate new insert_size[0] */ 432 /* Calculate new insert_size[0] */
515 tb->insert_size[0] -= 433 tb->insert_size[0] -= l_n;
516 l_n;
517 434
518 RFALSE(tb-> 435 RFALSE(tb->insert_size[0] <= 0,
519 insert_size[0] <=
520 0,
521 "PAP-12105: there is nothing to paste into L[0]. insert_size=%d", 436 "PAP-12105: there is nothing to paste into L[0]. insert_size=%d",
522 tb-> 437 tb->insert_size[0]);
523 insert_size[0]); 438 ret_val = leaf_shift_left(tb, tb->lnum[0], ih_item_len
524 ret_val = 439 (B_N_PITEM_HEAD(tbS0, item_pos)));
525 leaf_shift_left(tb,
526 tb->
527 lnum
528 [0],
529 ih_item_len
530 (B_N_PITEM_HEAD
531 (tbS0,
532 item_pos)));
533 /* Append to body of item in L[0] */ 440 /* Append to body of item in L[0] */
534 buffer_info_init_left(tb, &bi); 441 buffer_info_init_left(tb, &bi);
535 leaf_paste_in_buffer 442 leaf_paste_in_buffer
536 (&bi, 443 (&bi, n + item_pos - ret_val, ih_item_len
537 n + item_pos - 444 (B_N_PITEM_HEAD(tb->L[0], n + item_pos - ret_val)),
538 ret_val, 445 l_n, body,
539 ih_item_len 446 zeros_num > l_n ? l_n : zeros_num);
540 (B_N_PITEM_HEAD
541 (tb->L[0],
542 n + item_pos -
543 ret_val)), l_n,
544 body,
545 zeros_num >
546 l_n ? l_n :
547 zeros_num);
548 /* 0-th item in S0 can be only of DIRECT type when l_n != 0 */ 447 /* 0-th item in S0 can be only of DIRECT type when l_n != 0 */
549 { 448 {
550 int version; 449 int version;
551 int temp_l = 450 int temp_l = l_n;
552 l_n; 451
553 452 RFALSE(ih_item_len(B_N_PITEM_HEAD(tbS0, 0)),
554 RFALSE
555 (ih_item_len
556 (B_N_PITEM_HEAD
557 (tbS0,
558 0)),
559 "PAP-12106: item length must be 0"); 453 "PAP-12106: item length must be 0");
560 RFALSE 454 RFALSE(comp_short_le_keys(B_N_PKEY(tbS0, 0), B_N_PKEY
561 (comp_short_le_keys 455 (tb->L[0], n + item_pos - ret_val)),
562 (B_N_PKEY
563 (tbS0, 0),
564 B_N_PKEY
565 (tb->L[0],
566 n +
567 item_pos
568 -
569 ret_val)),
570 "PAP-12107: items must be of the same file"); 456 "PAP-12107: items must be of the same file");
571 if (is_indirect_le_ih(B_N_PITEM_HEAD(tb->L[0], n + item_pos - ret_val))) { 457 if (is_indirect_le_ih(B_N_PITEM_HEAD(tb->L[0], n + item_pos - ret_val))) {
572 temp_l = 458 temp_l = l_n << (tb->tb_sb-> s_blocksize_bits - UNFM_P_SHIFT);
573 l_n
574 <<
575 (tb->
576 tb_sb->
577 s_blocksize_bits
578 -
579 UNFM_P_SHIFT);
580 } 459 }
581 /* update key of first item in S0 */ 460 /* update key of first item in S0 */
582 version = 461 version = ih_version(B_N_PITEM_HEAD(tbS0, 0));
583 ih_version 462 set_le_key_k_offset(version, B_N_PKEY(tbS0, 0),
584 (B_N_PITEM_HEAD 463 le_key_k_offset(version,B_N_PKEY(tbS0, 0)) + temp_l);
585 (tbS0, 0));
586 set_le_key_k_offset
587 (version,
588 B_N_PKEY
589 (tbS0, 0),
590 le_key_k_offset
591 (version,
592 B_N_PKEY
593 (tbS0,
594 0)) +
595 temp_l);
596 /* update left delimiting key */ 464 /* update left delimiting key */
597 set_le_key_k_offset 465 set_le_key_k_offset(version, B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0]),
598 (version, 466 le_key_k_offset(version, B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0])) + temp_l);
599 B_N_PDELIM_KEY
600 (tb->
601 CFL[0],
602 tb->
603 lkey[0]),
604 le_key_k_offset
605 (version,
606 B_N_PDELIM_KEY
607 (tb->
608 CFL[0],
609 tb->
610 lkey[0]))
611 + temp_l);
612 } 467 }
613 468
614 /* Calculate new body, position in item and insert_size[0] */ 469 /* Calculate new body, position in item and insert_size[0] */
615 if (l_n > zeros_num) { 470 if (l_n > zeros_num) {
616 body += 471 body += (l_n - zeros_num);
617 (l_n -
618 zeros_num);
619 zeros_num = 0; 472 zeros_num = 0;
620 } else 473 } else
621 zeros_num -= 474 zeros_num -= l_n;
622 l_n;
623 pos_in_item = 0; 475 pos_in_item = 0;
624 476
625 RFALSE 477 RFALSE(comp_short_le_keys(B_N_PKEY(tbS0, 0), B_N_PKEY(tb->L[0], B_NR_ITEMS(tb->L[0]) - 1))
626 (comp_short_le_keys 478 || !op_is_left_mergeable(B_N_PKEY(tbS0, 0), tbS0->b_size)
627 (B_N_PKEY(tbS0, 0), 479 || !op_is_left_mergeable(B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0]), tbS0->b_size),
628 B_N_PKEY(tb->L[0],
629 B_NR_ITEMS
630 (tb->
631 L[0]) -
632 1))
633 ||
634 !op_is_left_mergeable
635 (B_N_PKEY(tbS0, 0),
636 tbS0->b_size)
637 ||
638 !op_is_left_mergeable
639 (B_N_PDELIM_KEY
640 (tb->CFL[0],
641 tb->lkey[0]),
642 tbS0->b_size),
643 "PAP-12120: item must be merge-able with left neighboring item"); 480 "PAP-12120: item must be merge-able with left neighboring item");
644 } else { /* only part of the appended item will be in L[0] */ 481 } else { /* only part of the appended item will be in L[0] */
645 482
646 /* Calculate position in item for append in S[0] */ 483 /* Calculate position in item for append in S[0] */
647 pos_in_item -= 484 pos_in_item -= tb->lbytes;
648 tb->lbytes;
649 485
650 RFALSE(pos_in_item <= 0, 486 RFALSE(pos_in_item <= 0, "PAP-12125: no place for paste. pos_in_item=%d", pos_in_item);
651 "PAP-12125: no place for paste. pos_in_item=%d",
652 pos_in_item);
653 487
654 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */ 488 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */
655 leaf_shift_left(tb, 489 leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
656 tb->
657 lnum[0],
658 tb->
659 lbytes);
660 } 490 }
661 } 491 }
662 } else { /* appended item will be in L[0] in whole */ 492 } else { /* appended item will be in L[0] in whole */
@@ -665,52 +495,30 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
665 495
666 if (!item_pos && op_is_left_mergeable(B_N_PKEY(tbS0, 0), tbS0->b_size)) { /* if we paste into first item of S[0] and it is left mergable */ 496 if (!item_pos && op_is_left_mergeable(B_N_PKEY(tbS0, 0), tbS0->b_size)) { /* if we paste into first item of S[0] and it is left mergable */
667 /* then increment pos_in_item by the size of the last item in L[0] */ 497 /* then increment pos_in_item by the size of the last item in L[0] */
668 pasted = 498 pasted = B_N_PITEM_HEAD(tb->L[0], n - 1);
669 B_N_PITEM_HEAD(tb->L[0],
670 n - 1);
671 if (is_direntry_le_ih(pasted)) 499 if (is_direntry_le_ih(pasted))
672 pos_in_item += 500 pos_in_item += ih_entry_count(pasted);
673 ih_entry_count
674 (pasted);
675 else 501 else
676 pos_in_item += 502 pos_in_item += ih_item_len(pasted);
677 ih_item_len(pasted);
678 } 503 }
679 504
680 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */ 505 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */
681 ret_val = 506 ret_val = leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
682 leaf_shift_left(tb, tb->lnum[0],
683 tb->lbytes);
684 /* Append to body of item in L[0] */ 507 /* Append to body of item in L[0] */
685 buffer_info_init_left(tb, &bi); 508 buffer_info_init_left(tb, &bi);
686 leaf_paste_in_buffer(&bi, 509 leaf_paste_in_buffer(&bi, n + item_pos - ret_val,
687 n + item_pos -
688 ret_val,
689 pos_in_item, 510 pos_in_item,
690 tb->insert_size[0], 511 tb->insert_size[0],
691 body, zeros_num); 512 body, zeros_num);
692 513
693 /* if appended item is directory, paste entry */ 514 /* if appended item is directory, paste entry */
694 pasted = 515 pasted = B_N_PITEM_HEAD(tb->L[0], n + item_pos - ret_val);
695 B_N_PITEM_HEAD(tb->L[0],
696 n + item_pos -
697 ret_val);
698 if (is_direntry_le_ih(pasted)) 516 if (is_direntry_le_ih(pasted))
699 leaf_paste_entries(&bi, 517 leaf_paste_entries(&bi, n + item_pos - ret_val,
700 n + 518 pos_in_item, 1,
701 item_pos - 519 (struct reiserfs_de_head *) body,
702 ret_val, 520 body + DEH_SIZE,
703 pos_in_item, 521 tb->insert_size[0]);
704 1,
705 (struct
706 reiserfs_de_head
707 *)body,
708 body +
709 DEH_SIZE,
710 tb->
711 insert_size
712 [0]
713 );
714 /* if appended item is indirect item, put unformatted node into un list */ 522 /* if appended item is indirect item, put unformatted node into un list */
715 if (is_indirect_le_ih(pasted)) 523 if (is_indirect_le_ih(pasted))
716 set_ih_free_space(pasted, 0); 524 set_ih_free_space(pasted, 0);
@@ -722,13 +530,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
722 reiserfs_panic(tb->tb_sb, "PAP-12130", 530 reiserfs_panic(tb->tb_sb, "PAP-12130",
723 "lnum > 0: unexpected mode: " 531 "lnum > 0: unexpected mode: "
724 " %s(%d)", 532 " %s(%d)",
725 (flag == 533 (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
726 M_DELETE) ? "DELETE" : ((flag ==
727 M_CUT)
728 ? "CUT"
729 :
730 "UNKNOWN"),
731 flag);
732 } 534 }
733 } else { 535 } else {
734 /* new item doesn't fall into L[0] */ 536 /* new item doesn't fall into L[0] */
@@ -748,14 +550,12 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
748 case M_INSERT: /* insert item */ 550 case M_INSERT: /* insert item */
749 if (n - tb->rnum[0] < item_pos) { /* new item or its part falls to R[0] */ 551 if (n - tb->rnum[0] < item_pos) { /* new item or its part falls to R[0] */
750 if (item_pos == n - tb->rnum[0] + 1 && tb->rbytes != -1) { /* part of new item falls into R[0] */ 552 if (item_pos == n - tb->rnum[0] + 1 && tb->rbytes != -1) { /* part of new item falls into R[0] */
751 loff_t old_key_comp, old_len, 553 loff_t old_key_comp, old_len, r_zeros_number;
752 r_zeros_number;
753 const char *r_body; 554 const char *r_body;
754 int version; 555 int version;
755 loff_t offset; 556 loff_t offset;
756 557
757 leaf_shift_right(tb, tb->rnum[0] - 1, 558 leaf_shift_right(tb, tb->rnum[0] - 1, -1);
758 -1);
759 559
760 version = ih_version(ih); 560 version = ih_version(ih);
761 /* Remember key component and item length */ 561 /* Remember key component and item length */
@@ -763,29 +563,17 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
763 old_len = ih_item_len(ih); 563 old_len = ih_item_len(ih);
764 564
765 /* Calculate key component and item length to insert into R[0] */ 565 /* Calculate key component and item length to insert into R[0] */
766 offset = 566 offset = le_ih_k_offset(ih) + ((old_len - tb->rbytes) << (is_indirect_le_ih(ih) ? tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT : 0));
767 le_ih_k_offset(ih) +
768 ((old_len -
769 tb->
770 rbytes) << (is_indirect_le_ih(ih)
771 ? tb->tb_sb->
772 s_blocksize_bits -
773 UNFM_P_SHIFT : 0));
774 set_le_ih_k_offset(ih, offset); 567 set_le_ih_k_offset(ih, offset);
775 put_ih_item_len(ih, tb->rbytes); 568 put_ih_item_len(ih, tb->rbytes);
776 /* Insert part of the item into R[0] */ 569 /* Insert part of the item into R[0] */
777 buffer_info_init_right(tb, &bi); 570 buffer_info_init_right(tb, &bi);
778 if ((old_len - tb->rbytes) > zeros_num) { 571 if ((old_len - tb->rbytes) > zeros_num) {
779 r_zeros_number = 0; 572 r_zeros_number = 0;
780 r_body = 573 r_body = body + (old_len - tb->rbytes) - zeros_num;
781 body + (old_len -
782 tb->rbytes) -
783 zeros_num;
784 } else { 574 } else {
785 r_body = body; 575 r_body = body;
786 r_zeros_number = 576 r_zeros_number = zeros_num - (old_len - tb->rbytes);
787 zeros_num - (old_len -
788 tb->rbytes);
789 zeros_num -= r_zeros_number; 577 zeros_num -= r_zeros_number;
790 } 578 }
791 579
@@ -798,25 +586,18 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
798 586
799 /* Calculate key component and item length to insert into S[0] */ 587 /* Calculate key component and item length to insert into S[0] */
800 set_le_ih_k_offset(ih, old_key_comp); 588 set_le_ih_k_offset(ih, old_key_comp);
801 put_ih_item_len(ih, 589 put_ih_item_len(ih, old_len - tb->rbytes);
802 old_len - tb->rbytes);
803 590
804 tb->insert_size[0] -= tb->rbytes; 591 tb->insert_size[0] -= tb->rbytes;
805 592
806 } else { /* whole new item falls into R[0] */ 593 } else { /* whole new item falls into R[0] */
807 594
808 /* Shift rnum[0]-1 items to R[0] */ 595 /* Shift rnum[0]-1 items to R[0] */
809 ret_val = 596 ret_val = leaf_shift_right(tb, tb->rnum[0] - 1, tb->rbytes);
810 leaf_shift_right(tb,
811 tb->rnum[0] - 1,
812 tb->rbytes);
813 /* Insert new item into R[0] */ 597 /* Insert new item into R[0] */
814 buffer_info_init_right(tb, &bi); 598 buffer_info_init_right(tb, &bi);
815 leaf_insert_into_buf(&bi, 599 leaf_insert_into_buf(&bi, item_pos - n + tb->rnum[0] - 1,
816 item_pos - n + 600 ih, body, zeros_num);
817 tb->rnum[0] - 1,
818 ih, body,
819 zeros_num);
820 601
821 if (item_pos - n + tb->rnum[0] - 1 == 0) { 602 if (item_pos - n + tb->rnum[0] - 1 == 0) {
822 replace_key(tb, tb->CFR[0], 603 replace_key(tb, tb->CFR[0],
@@ -841,200 +622,97 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
841 622
842 RFALSE(zeros_num, 623 RFALSE(zeros_num,
843 "PAP-12145: invalid parameter in case of a directory"); 624 "PAP-12145: invalid parameter in case of a directory");
844 entry_count = 625 entry_count = I_ENTRY_COUNT(B_N_PITEM_HEAD
845 I_ENTRY_COUNT(B_N_PITEM_HEAD 626 (tbS0, item_pos));
846 (tbS0,
847 item_pos));
848 if (entry_count - tb->rbytes < 627 if (entry_count - tb->rbytes <
849 pos_in_item) 628 pos_in_item)
850 /* new directory entry falls into R[0] */ 629 /* new directory entry falls into R[0] */
851 { 630 {
852 int paste_entry_position; 631 int paste_entry_position;
853 632
854 RFALSE(tb->rbytes - 1 >= 633 RFALSE(tb->rbytes - 1 >= entry_count || !tb-> insert_size[0],
855 entry_count
856 || !tb->
857 insert_size[0],
858 "PAP-12150: no enough of entries to shift to R[0]: rbytes=%d, entry_count=%d", 634 "PAP-12150: no enough of entries to shift to R[0]: rbytes=%d, entry_count=%d",
859 tb->rbytes, 635 tb->rbytes, entry_count);
860 entry_count);
861 /* Shift rnum[0]-1 items in whole. Shift rbytes-1 directory entries from directory item number rnum[0] */ 636 /* Shift rnum[0]-1 items in whole. Shift rbytes-1 directory entries from directory item number rnum[0] */
862 leaf_shift_right(tb, 637 leaf_shift_right(tb, tb->rnum[0], tb->rbytes - 1);
863 tb->
864 rnum
865 [0],
866 tb->
867 rbytes
868 - 1);
869 /* Paste given directory entry to directory item */ 638 /* Paste given directory entry to directory item */
870 paste_entry_position = 639 paste_entry_position = pos_in_item - entry_count + tb->rbytes - 1;
871 pos_in_item -
872 entry_count +
873 tb->rbytes - 1;
874 buffer_info_init_right(tb, &bi); 640 buffer_info_init_right(tb, &bi);
875 leaf_paste_in_buffer 641 leaf_paste_in_buffer(&bi, 0, paste_entry_position, tb->insert_size[0], body, zeros_num);
876 (&bi, 0,
877 paste_entry_position,
878 tb->insert_size[0],
879 body, zeros_num);
880 /* paste entry */ 642 /* paste entry */
881 leaf_paste_entries(&bi, 643 leaf_paste_entries(&bi, 0, paste_entry_position, 1,
882 0, 644 (struct reiserfs_de_head *) body,
883 paste_entry_position, 645 body + DEH_SIZE, tb->insert_size[0]);
884 1, 646
885 (struct 647 if (paste_entry_position == 0) {
886 reiserfs_de_head
887 *)
888 body,
889 body
890 +
891 DEH_SIZE,
892 tb->
893 insert_size
894 [0]
895 );
896
897 if (paste_entry_position
898 == 0) {
899 /* change delimiting keys */ 648 /* change delimiting keys */
900 replace_key(tb, 649 replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0],0);
901 tb->
902 CFR
903 [0],
904 tb->
905 rkey
906 [0],
907 tb->
908 R
909 [0],
910 0);
911 } 650 }
912 651
913 tb->insert_size[0] = 0; 652 tb->insert_size[0] = 0;
914 pos_in_item++; 653 pos_in_item++;
915 } else { /* new directory entry doesn't fall into R[0] */ 654 } else { /* new directory entry doesn't fall into R[0] */
916 655
917 leaf_shift_right(tb, 656 leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
918 tb->
919 rnum
920 [0],
921 tb->
922 rbytes);
923 } 657 }
924 } else { /* regular object */ 658 } else { /* regular object */
925 659
926 int n_shift, n_rem, 660 int n_shift, n_rem, r_zeros_number;
927 r_zeros_number;
928 const char *r_body; 661 const char *r_body;
929 662
930 /* Calculate number of bytes which must be shifted from appended item */ 663 /* Calculate number of bytes which must be shifted from appended item */
931 if ((n_shift = 664 if ((n_shift = tb->rbytes - tb->insert_size[0]) < 0)
932 tb->rbytes -
933 tb->insert_size[0]) < 0)
934 n_shift = 0; 665 n_shift = 0;
935 666
936 RFALSE(pos_in_item != 667 RFALSE(pos_in_item != ih_item_len
937 ih_item_len 668 (B_N_PITEM_HEAD(tbS0, item_pos)),
938 (B_N_PITEM_HEAD
939 (tbS0, item_pos)),
940 "PAP-12155: invalid position to paste. ih_item_len=%d, pos_in_item=%d", 669 "PAP-12155: invalid position to paste. ih_item_len=%d, pos_in_item=%d",
941 pos_in_item, 670 pos_in_item, ih_item_len
942 ih_item_len 671 (B_N_PITEM_HEAD(tbS0, item_pos)));
943 (B_N_PITEM_HEAD 672
944 (tbS0, item_pos))); 673 leaf_shift_right(tb, tb->rnum[0], n_shift);
945
946 leaf_shift_right(tb,
947 tb->rnum[0],
948 n_shift);
949 /* Calculate number of bytes which must remain in body after appending to R[0] */ 674 /* Calculate number of bytes which must remain in body after appending to R[0] */
950 if ((n_rem = 675 if ((n_rem = tb->insert_size[0] - tb->rbytes) < 0)
951 tb->insert_size[0] -
952 tb->rbytes) < 0)
953 n_rem = 0; 676 n_rem = 0;
954 677
955 { 678 {
956 int version; 679 int version;
957 unsigned long temp_rem = 680 unsigned long temp_rem = n_rem;
958 n_rem; 681
959 682 version = ih_version(B_N_PITEM_HEAD(tb->R[0], 0));
960 version = 683 if (is_indirect_le_key(version, B_N_PKEY(tb->R[0], 0))) {
961 ih_version 684 temp_rem = n_rem << (tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT);
962 (B_N_PITEM_HEAD
963 (tb->R[0], 0));
964 if (is_indirect_le_key
965 (version,
966 B_N_PKEY(tb->R[0],
967 0))) {
968 temp_rem =
969 n_rem <<
970 (tb->tb_sb->
971 s_blocksize_bits
972 -
973 UNFM_P_SHIFT);
974 } 685 }
975 set_le_key_k_offset 686 set_le_key_k_offset(version, B_N_PKEY(tb->R[0], 0),
976 (version, 687 le_key_k_offset(version, B_N_PKEY(tb->R[0], 0)) + temp_rem);
977 B_N_PKEY(tb->R[0], 688 set_le_key_k_offset(version, B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]),
978 0), 689 le_key_k_offset(version, B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0])) + temp_rem);
979 le_key_k_offset
980 (version,
981 B_N_PKEY(tb->R[0],
982 0)) +
983 temp_rem);
984 set_le_key_k_offset
985 (version,
986 B_N_PDELIM_KEY(tb->
987 CFR
988 [0],
989 tb->
990 rkey
991 [0]),
992 le_key_k_offset
993 (version,
994 B_N_PDELIM_KEY
995 (tb->CFR[0],
996 tb->rkey[0])) +
997 temp_rem);
998 } 690 }
999/* k_offset (B_N_PKEY(tb->R[0],0)) += n_rem; 691/* k_offset (B_N_PKEY(tb->R[0],0)) += n_rem;
1000 k_offset (B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0])) += n_rem;*/ 692 k_offset (B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0])) += n_rem;*/
1001 do_balance_mark_internal_dirty 693 do_balance_mark_internal_dirty(tb, tb->CFR[0], 0);
1002 (tb, tb->CFR[0], 0);
1003 694
1004 /* Append part of body into R[0] */ 695 /* Append part of body into R[0] */
1005 buffer_info_init_right(tb, &bi); 696 buffer_info_init_right(tb, &bi);
1006 if (n_rem > zeros_num) { 697 if (n_rem > zeros_num) {
1007 r_zeros_number = 0; 698 r_zeros_number = 0;
1008 r_body = 699 r_body = body + n_rem - zeros_num;
1009 body + n_rem -
1010 zeros_num;
1011 } else { 700 } else {
1012 r_body = body; 701 r_body = body;
1013 r_zeros_number = 702 r_zeros_number = zeros_num - n_rem;
1014 zeros_num - n_rem; 703 zeros_num -= r_zeros_number;
1015 zeros_num -=
1016 r_zeros_number;
1017 } 704 }
1018 705
1019 leaf_paste_in_buffer(&bi, 0, 706 leaf_paste_in_buffer(&bi, 0, n_shift,
1020 n_shift, 707 tb->insert_size[0] - n_rem,
1021 tb-> 708 r_body, r_zeros_number);
1022 insert_size 709
1023 [0] - 710 if (is_indirect_le_ih(B_N_PITEM_HEAD(tb->R[0], 0))) {
1024 n_rem,
1025 r_body,
1026 r_zeros_number);
1027
1028 if (is_indirect_le_ih
1029 (B_N_PITEM_HEAD
1030 (tb->R[0], 0))) {
1031#if 0 711#if 0
1032 RFALSE(n_rem, 712 RFALSE(n_rem,
1033 "PAP-12160: paste more than one unformatted node pointer"); 713 "PAP-12160: paste more than one unformatted node pointer");
1034#endif 714#endif
1035 set_ih_free_space 715 set_ih_free_space(B_N_PITEM_HEAD(tb->R[0], 0), 0);
1036 (B_N_PITEM_HEAD
1037 (tb->R[0], 0), 0);
1038 } 716 }
1039 tb->insert_size[0] = n_rem; 717 tb->insert_size[0] = n_rem;
1040 if (!n_rem) 718 if (!n_rem)
@@ -1044,58 +722,28 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1044 722
1045 struct item_head *pasted; 723 struct item_head *pasted;
1046 724
1047 ret_val = 725 ret_val = leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
1048 leaf_shift_right(tb, tb->rnum[0],
1049 tb->rbytes);
1050 /* append item in R[0] */ 726 /* append item in R[0] */
1051 if (pos_in_item >= 0) { 727 if (pos_in_item >= 0) {
1052 buffer_info_init_right(tb, &bi); 728 buffer_info_init_right(tb, &bi);
1053 leaf_paste_in_buffer(&bi, 729 leaf_paste_in_buffer(&bi, item_pos - n + tb->rnum[0], pos_in_item,
1054 item_pos - 730 tb->insert_size[0], body, zeros_num);
1055 n +
1056 tb->
1057 rnum[0],
1058 pos_in_item,
1059 tb->
1060 insert_size
1061 [0], body,
1062 zeros_num);
1063 } 731 }
1064 732
1065 /* paste new entry, if item is directory item */ 733 /* paste new entry, if item is directory item */
1066 pasted = 734 pasted = B_N_PITEM_HEAD(tb->R[0], item_pos - n + tb->rnum[0]);
1067 B_N_PITEM_HEAD(tb->R[0], 735 if (is_direntry_le_ih(pasted) && pos_in_item >= 0) {
1068 item_pos - n + 736 leaf_paste_entries(&bi, item_pos - n + tb->rnum[0],
1069 tb->rnum[0]); 737 pos_in_item, 1,
1070 if (is_direntry_le_ih(pasted) 738 (struct reiserfs_de_head *) body,
1071 && pos_in_item >= 0) { 739 body + DEH_SIZE, tb->insert_size[0]);
1072 leaf_paste_entries(&bi,
1073 item_pos -
1074 n +
1075 tb->rnum[0],
1076 pos_in_item,
1077 1,
1078 (struct
1079 reiserfs_de_head
1080 *)body,
1081 body +
1082 DEH_SIZE,
1083 tb->
1084 insert_size
1085 [0]
1086 );
1087 if (!pos_in_item) { 740 if (!pos_in_item) {
1088 741
1089 RFALSE(item_pos - n + 742 RFALSE(item_pos - n + tb->rnum[0],
1090 tb->rnum[0],
1091 "PAP-12165: directory item must be first item of node when pasting is in 0th position"); 743 "PAP-12165: directory item must be first item of node when pasting is in 0th position");
1092 744
1093 /* update delimiting keys */ 745 /* update delimiting keys */
1094 replace_key(tb, 746 replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
1095 tb->CFR[0],
1096 tb->rkey[0],
1097 tb->R[0],
1098 0);
1099 } 747 }
1100 } 748 }
1101 749
@@ -1111,22 +759,16 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1111 default: /* cases d and t */ 759 default: /* cases d and t */
1112 reiserfs_panic(tb->tb_sb, "PAP-12175", 760 reiserfs_panic(tb->tb_sb, "PAP-12175",
1113 "rnum > 0: unexpected mode: %s(%d)", 761 "rnum > 0: unexpected mode: %s(%d)",
1114 (flag == 762 (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
1115 M_DELETE) ? "DELETE" : ((flag ==
1116 M_CUT) ? "CUT"
1117 : "UNKNOWN"),
1118 flag);
1119 } 763 }
1120 764
1121 } 765 }
1122 766
1123 /* tb->rnum[0] > 0 */ 767 /* tb->rnum[0] > 0 */
1124 RFALSE(tb->blknum[0] > 3, 768 RFALSE(tb->blknum[0] > 3,
1125 "PAP-12180: blknum can not be %d. It must be <= 3", 769 "PAP-12180: blknum can not be %d. It must be <= 3", tb->blknum[0]);
1126 tb->blknum[0]);
1127 RFALSE(tb->blknum[0] < 0, 770 RFALSE(tb->blknum[0] < 0,
1128 "PAP-12185: blknum can not be %d. It must be >= 0", 771 "PAP-12185: blknum can not be %d. It must be >= 0", tb->blknum[0]);
1129 tb->blknum[0]);
1130 772
1131 /* if while adding to a node we discover that it is possible to split 773 /* if while adding to a node we discover that it is possible to split
1132 it in two, and merge the left part into the left neighbor and the 774 it in two, and merge the left part into the left neighbor and the
@@ -1177,8 +819,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1177 819
1178 if (n - snum[i] < item_pos) { /* new item or it's part falls to first new node S_new[i] */ 820 if (n - snum[i] < item_pos) { /* new item or it's part falls to first new node S_new[i] */
1179 if (item_pos == n - snum[i] + 1 && sbytes[i] != -1) { /* part of new item falls into S_new[i] */ 821 if (item_pos == n - snum[i] + 1 && sbytes[i] != -1) { /* part of new item falls into S_new[i] */
1180 int old_key_comp, old_len, 822 int old_key_comp, old_len, r_zeros_number;
1181 r_zeros_number;
1182 const char *r_body; 823 const char *r_body;
1183 int version; 824 int version;
1184 825
@@ -1192,15 +833,8 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1192 old_len = ih_item_len(ih); 833 old_len = ih_item_len(ih);
1193 834
1194 /* Calculate key component and item length to insert into S_new[i] */ 835 /* Calculate key component and item length to insert into S_new[i] */
1195 set_le_ih_k_offset(ih, 836 set_le_ih_k_offset(ih, le_ih_k_offset(ih) +
1196 le_ih_k_offset(ih) + 837 ((old_len - sbytes[i]) << (is_indirect_le_ih(ih) ? tb->tb_sb-> s_blocksize_bits - UNFM_P_SHIFT : 0)));
1197 ((old_len -
1198 sbytes[i]) <<
1199 (is_indirect_le_ih
1200 (ih) ? tb->tb_sb->
1201 s_blocksize_bits -
1202 UNFM_P_SHIFT :
1203 0)));
1204 838
1205 put_ih_item_len(ih, sbytes[i]); 839 put_ih_item_len(ih, sbytes[i]);
1206 840
@@ -1209,39 +843,29 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1209 843
1210 if ((old_len - sbytes[i]) > zeros_num) { 844 if ((old_len - sbytes[i]) > zeros_num) {
1211 r_zeros_number = 0; 845 r_zeros_number = 0;
1212 r_body = 846 r_body = body + (old_len - sbytes[i]) - zeros_num;
1213 body + (old_len -
1214 sbytes[i]) -
1215 zeros_num;
1216 } else { 847 } else {
1217 r_body = body; 848 r_body = body;
1218 r_zeros_number = 849 r_zeros_number = zeros_num - (old_len - sbytes[i]);
1219 zeros_num - (old_len -
1220 sbytes[i]);
1221 zeros_num -= r_zeros_number; 850 zeros_num -= r_zeros_number;
1222 } 851 }
1223 852
1224 leaf_insert_into_buf(&bi, 0, ih, r_body, 853 leaf_insert_into_buf(&bi, 0, ih, r_body, r_zeros_number);
1225 r_zeros_number);
1226 854
1227 /* Calculate key component and item length to insert into S[i] */ 855 /* Calculate key component and item length to insert into S[i] */
1228 set_le_ih_k_offset(ih, old_key_comp); 856 set_le_ih_k_offset(ih, old_key_comp);
1229 put_ih_item_len(ih, 857 put_ih_item_len(ih, old_len - sbytes[i]);
1230 old_len - sbytes[i]);
1231 tb->insert_size[0] -= sbytes[i]; 858 tb->insert_size[0] -= sbytes[i];
1232 } else { /* whole new item falls into S_new[i] */ 859 } else { /* whole new item falls into S_new[i] */
1233 860
1234 /* Shift snum[0] - 1 items to S_new[i] (sbytes[i] of split item) */ 861 /* Shift snum[0] - 1 items to S_new[i] (sbytes[i] of split item) */
1235 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, 862 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
1236 snum[i] - 1, sbytes[i], 863 snum[i] - 1, sbytes[i], S_new[i]);
1237 S_new[i]);
1238 864
1239 /* Insert new item into S_new[i] */ 865 /* Insert new item into S_new[i] */
1240 buffer_info_init_bh(tb, &bi, S_new[i]); 866 buffer_info_init_bh(tb, &bi, S_new[i]);
1241 leaf_insert_into_buf(&bi, 867 leaf_insert_into_buf(&bi, item_pos - n + snum[i] - 1,
1242 item_pos - n + 868 ih, body, zeros_num);
1243 snum[i] - 1, ih,
1244 body, zeros_num);
1245 869
1246 zeros_num = tb->insert_size[0] = 0; 870 zeros_num = tb->insert_size[0] = 0;
1247 } 871 }
@@ -1268,150 +892,73 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1268 892
1269 int entry_count; 893 int entry_count;
1270 894
1271 entry_count = 895 entry_count = ih_entry_count(aux_ih);
1272 ih_entry_count(aux_ih);
1273 896
1274 if (entry_count - sbytes[i] < 897 if (entry_count - sbytes[i] < pos_in_item && pos_in_item <= entry_count) {
1275 pos_in_item
1276 && pos_in_item <=
1277 entry_count) {
1278 /* new directory entry falls into S_new[i] */ 898 /* new directory entry falls into S_new[i] */
1279 899
1280 RFALSE(!tb-> 900 RFALSE(!tb->insert_size[0], "PAP-12215: insert_size is already 0");
1281 insert_size[0], 901 RFALSE(sbytes[i] - 1 >= entry_count,
1282 "PAP-12215: insert_size is already 0");
1283 RFALSE(sbytes[i] - 1 >=
1284 entry_count,
1285 "PAP-12220: there are no so much entries (%d), only %d", 902 "PAP-12220: there are no so much entries (%d), only %d",
1286 sbytes[i] - 1, 903 sbytes[i] - 1, entry_count);
1287 entry_count);
1288 904
1289 /* Shift snum[i]-1 items in whole. Shift sbytes[i] directory entries from directory item number snum[i] */ 905 /* Shift snum[i]-1 items in whole. Shift sbytes[i] directory entries from directory item number snum[i] */
1290 leaf_move_items 906 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i] - 1, S_new[i]);
1291 (LEAF_FROM_S_TO_SNEW,
1292 tb, snum[i],
1293 sbytes[i] - 1,
1294 S_new[i]);
1295 /* Paste given directory entry to directory item */ 907 /* Paste given directory entry to directory item */
1296 buffer_info_init_bh(tb, &bi, S_new[i]); 908 buffer_info_init_bh(tb, &bi, S_new[i]);
1297 leaf_paste_in_buffer 909 leaf_paste_in_buffer(&bi, 0, pos_in_item - entry_count + sbytes[i] - 1,
1298 (&bi, 0, 910 tb->insert_size[0], body, zeros_num);
1299 pos_in_item -
1300 entry_count +
1301 sbytes[i] - 1,
1302 tb->insert_size[0],
1303 body, zeros_num);
1304 /* paste new directory entry */ 911 /* paste new directory entry */
1305 leaf_paste_entries(&bi, 912 leaf_paste_entries(&bi, 0, pos_in_item - entry_count + sbytes[i] - 1, 1,
1306 0, 913 (struct reiserfs_de_head *) body,
1307 pos_in_item 914 body + DEH_SIZE, tb->insert_size[0]);
1308 -
1309 entry_count
1310 +
1311 sbytes
1312 [i] -
1313 1, 1,
1314 (struct
1315 reiserfs_de_head
1316 *)
1317 body,
1318 body
1319 +
1320 DEH_SIZE,
1321 tb->
1322 insert_size
1323 [0]
1324 );
1325 tb->insert_size[0] = 0; 915 tb->insert_size[0] = 0;
1326 pos_in_item++; 916 pos_in_item++;
1327 } else { /* new directory entry doesn't fall into S_new[i] */ 917 } else { /* new directory entry doesn't fall into S_new[i] */
1328 leaf_move_items 918 leaf_move_items(LEAF_FROM_S_TO_SNEW,tb, snum[i], sbytes[i], S_new[i]);
1329 (LEAF_FROM_S_TO_SNEW,
1330 tb, snum[i],
1331 sbytes[i],
1332 S_new[i]);
1333 } 919 }
1334 } else { /* regular object */ 920 } else { /* regular object */
1335 921
1336 int n_shift, n_rem, 922 int n_shift, n_rem, r_zeros_number;
1337 r_zeros_number;
1338 const char *r_body; 923 const char *r_body;
1339 924
1340 RFALSE(pos_in_item != 925 RFALSE(pos_in_item != ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)) || tb->insert_size[0] <= 0,
1341 ih_item_len
1342 (B_N_PITEM_HEAD
1343 (tbS0, item_pos))
1344 || tb->insert_size[0] <=
1345 0,
1346 "PAP-12225: item too short or insert_size <= 0"); 926 "PAP-12225: item too short or insert_size <= 0");
1347 927
1348 /* Calculate number of bytes which must be shifted from appended item */ 928 /* Calculate number of bytes which must be shifted from appended item */
1349 n_shift = 929 n_shift = sbytes[i] - tb->insert_size[0];
1350 sbytes[i] -
1351 tb->insert_size[0];
1352 if (n_shift < 0) 930 if (n_shift < 0)
1353 n_shift = 0; 931 n_shift = 0;
1354 leaf_move_items 932 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, snum[i], n_shift, S_new[i]);
1355 (LEAF_FROM_S_TO_SNEW, tb,
1356 snum[i], n_shift,
1357 S_new[i]);
1358 933
1359 /* Calculate number of bytes which must remain in body after append to S_new[i] */ 934 /* Calculate number of bytes which must remain in body after append to S_new[i] */
1360 n_rem = 935 n_rem = tb->insert_size[0] - sbytes[i];
1361 tb->insert_size[0] -
1362 sbytes[i];
1363 if (n_rem < 0) 936 if (n_rem < 0)
1364 n_rem = 0; 937 n_rem = 0;
1365 /* Append part of body into S_new[0] */ 938 /* Append part of body into S_new[0] */
1366 buffer_info_init_bh(tb, &bi, S_new[i]); 939 buffer_info_init_bh(tb, &bi, S_new[i]);
1367 if (n_rem > zeros_num) { 940 if (n_rem > zeros_num) {
1368 r_zeros_number = 0; 941 r_zeros_number = 0;
1369 r_body = 942 r_body = body + n_rem - zeros_num;
1370 body + n_rem -
1371 zeros_num;
1372 } else { 943 } else {
1373 r_body = body; 944 r_body = body;
1374 r_zeros_number = 945 r_zeros_number = zeros_num - n_rem;
1375 zeros_num - n_rem; 946 zeros_num -= r_zeros_number;
1376 zeros_num -=
1377 r_zeros_number;
1378 } 947 }
1379 948
1380 leaf_paste_in_buffer(&bi, 0, 949 leaf_paste_in_buffer(&bi, 0, n_shift,
1381 n_shift, 950 tb->insert_size[0] - n_rem,
1382 tb-> 951 r_body, r_zeros_number);
1383 insert_size
1384 [0] -
1385 n_rem,
1386 r_body,
1387 r_zeros_number);
1388 { 952 {
1389 struct item_head *tmp; 953 struct item_head *tmp;
1390 954
1391 tmp = 955 tmp = B_N_PITEM_HEAD(S_new[i], 0);
1392 B_N_PITEM_HEAD(S_new
1393 [i],
1394 0);
1395 if (is_indirect_le_ih 956 if (is_indirect_le_ih
1396 (tmp)) { 957 (tmp)) {
1397 set_ih_free_space 958 set_ih_free_space(tmp, 0);
1398 (tmp, 0); 959 set_le_ih_k_offset(tmp, le_ih_k_offset(tmp) + (n_rem << (tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT)));
1399 set_le_ih_k_offset
1400 (tmp,
1401 le_ih_k_offset
1402 (tmp) +
1403 (n_rem <<
1404 (tb->
1405 tb_sb->
1406 s_blocksize_bits
1407 -
1408 UNFM_P_SHIFT)));
1409 } else { 960 } else {
1410 set_le_ih_k_offset 961 set_le_ih_k_offset(tmp, le_ih_k_offset(tmp) + n_rem);
1411 (tmp,
1412 le_ih_k_offset
1413 (tmp) +
1414 n_rem);
1415 } 962 }
1416 } 963 }
1417 964
@@ -1426,8 +973,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1426 struct item_head *pasted; 973 struct item_head *pasted;
1427 974
1428#ifdef CONFIG_REISERFS_CHECK 975#ifdef CONFIG_REISERFS_CHECK
1429 struct item_head *ih_check = 976 struct item_head *ih_check = B_N_PITEM_HEAD(tbS0, item_pos);
1430 B_N_PITEM_HEAD(tbS0, item_pos);
1431 977
1432 if (!is_direntry_le_ih(ih_check) 978 if (!is_direntry_le_ih(ih_check)
1433 && (pos_in_item != ih_item_len(ih_check) 979 && (pos_in_item != ih_item_len(ih_check)
@@ -1439,8 +985,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1439 "to ih_item_len"); 985 "to ih_item_len");
1440#endif /* CONFIG_REISERFS_CHECK */ 986#endif /* CONFIG_REISERFS_CHECK */
1441 987
1442 leaf_mi = 988 leaf_mi = leaf_move_items(LEAF_FROM_S_TO_SNEW,
1443 leaf_move_items(LEAF_FROM_S_TO_SNEW,
1444 tb, snum[i], 989 tb, snum[i],
1445 sbytes[i], 990 sbytes[i],
1446 S_new[i]); 991 S_new[i]);
@@ -1452,30 +997,19 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1452 /* paste into item */ 997 /* paste into item */
1453 buffer_info_init_bh(tb, &bi, S_new[i]); 998 buffer_info_init_bh(tb, &bi, S_new[i]);
1454 leaf_paste_in_buffer(&bi, 999 leaf_paste_in_buffer(&bi,
1455 item_pos - n + 1000 item_pos - n + snum[i],
1456 snum[i],
1457 pos_in_item, 1001 pos_in_item,
1458 tb->insert_size[0], 1002 tb->insert_size[0],
1459 body, zeros_num); 1003 body, zeros_num);
1460 1004
1461 pasted = 1005 pasted = B_N_PITEM_HEAD(S_new[i], item_pos - n + snum[i]);
1462 B_N_PITEM_HEAD(S_new[i],
1463 item_pos - n +
1464 snum[i]);
1465 if (is_direntry_le_ih(pasted)) { 1006 if (is_direntry_le_ih(pasted)) {
1466 leaf_paste_entries(&bi, 1007 leaf_paste_entries(&bi,
1467 item_pos - 1008 item_pos - n + snum[i],
1468 n + snum[i], 1009 pos_in_item, 1,
1469 pos_in_item, 1010 (struct reiserfs_de_head *)body,
1470 1, 1011 body + DEH_SIZE,
1471 (struct 1012 tb->insert_size[0]
1472 reiserfs_de_head
1473 *)body,
1474 body +
1475 DEH_SIZE,
1476 tb->
1477 insert_size
1478 [0]
1479 ); 1013 );
1480 } 1014 }
1481 1015
@@ -1495,11 +1029,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1495 default: /* cases d and t */ 1029 default: /* cases d and t */
1496 reiserfs_panic(tb->tb_sb, "PAP-12245", 1030 reiserfs_panic(tb->tb_sb, "PAP-12245",
1497 "blknum > 2: unexpected mode: %s(%d)", 1031 "blknum > 2: unexpected mode: %s(%d)",
1498 (flag == 1032 (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
1499 M_DELETE) ? "DELETE" : ((flag ==
1500 M_CUT) ? "CUT"
1501 : "UNKNOWN"),
1502 flag);
1503 } 1033 }
1504 1034
1505 memcpy(insert_key + i, B_N_PKEY(S_new[i], 0), KEY_SIZE); 1035 memcpy(insert_key + i, B_N_PKEY(S_new[i], 0), KEY_SIZE);
@@ -1524,9 +1054,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1524 /* If we insert the first key change the delimiting key */ 1054 /* If we insert the first key change the delimiting key */
1525 if (item_pos == 0) { 1055 if (item_pos == 0) {
1526 if (tb->CFL[0]) /* can be 0 in reiserfsck */ 1056 if (tb->CFL[0]) /* can be 0 in reiserfsck */
1527 replace_key(tb, tb->CFL[0], tb->lkey[0], 1057 replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0);
1528 tbS0, 0);
1529
1530 } 1058 }
1531 break; 1059 break;
1532 1060
@@ -1536,53 +1064,27 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1536 pasted = B_N_PITEM_HEAD(tbS0, item_pos); 1064 pasted = B_N_PITEM_HEAD(tbS0, item_pos);
1537 /* when directory, may be new entry already pasted */ 1065 /* when directory, may be new entry already pasted */
1538 if (is_direntry_le_ih(pasted)) { 1066 if (is_direntry_le_ih(pasted)) {
1539 if (pos_in_item >= 0 && 1067 if (pos_in_item >= 0 && pos_in_item <= ih_entry_count(pasted)) {
1540 pos_in_item <=
1541 ih_entry_count(pasted)) {
1542 1068
1543 RFALSE(!tb->insert_size[0], 1069 RFALSE(!tb->insert_size[0],
1544 "PAP-12260: insert_size is 0 already"); 1070 "PAP-12260: insert_size is 0 already");
1545 1071
1546 /* prepare space */ 1072 /* prepare space */
1547 buffer_info_init_tbS0(tb, &bi); 1073 buffer_info_init_tbS0(tb, &bi);
1548 leaf_paste_in_buffer(&bi, 1074 leaf_paste_in_buffer(&bi, item_pos, pos_in_item,
1549 item_pos, 1075 tb->insert_size[0], body,
1550 pos_in_item,
1551 tb->
1552 insert_size
1553 [0], body,
1554 zeros_num); 1076 zeros_num);
1555 1077
1556 /* paste entry */ 1078 /* paste entry */
1557 leaf_paste_entries(&bi, 1079 leaf_paste_entries(&bi, item_pos, pos_in_item, 1,
1558 item_pos, 1080 (struct reiserfs_de_head *)body,
1559 pos_in_item, 1081 body + DEH_SIZE,
1560 1, 1082 tb->insert_size[0]);
1561 (struct
1562 reiserfs_de_head
1563 *)body,
1564 body +
1565 DEH_SIZE,
1566 tb->
1567 insert_size
1568 [0]
1569 );
1570 if (!item_pos && !pos_in_item) { 1083 if (!item_pos && !pos_in_item) {
1571 RFALSE(!tb->CFL[0] 1084 RFALSE(!tb->CFL[0] || !tb->L[0],
1572 || !tb->L[0],
1573 "PAP-12270: CFL[0]/L[0] must be specified"); 1085 "PAP-12270: CFL[0]/L[0] must be specified");
1574 if (tb->CFL[0]) { 1086 if (tb->CFL[0])
1575 replace_key(tb, 1087 replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0);
1576 tb->
1577 CFL
1578 [0],
1579 tb->
1580 lkey
1581 [0],
1582 tbS0,
1583 0);
1584
1585 }
1586 } 1088 }
1587 tb->insert_size[0] = 0; 1089 tb->insert_size[0] = 0;
1588 } 1090 }
@@ -1593,13 +1095,8 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1593 "PAP-12275: insert size must not be %d", 1095 "PAP-12275: insert size must not be %d",
1594 tb->insert_size[0]); 1096 tb->insert_size[0]);
1595 buffer_info_init_tbS0(tb, &bi); 1097 buffer_info_init_tbS0(tb, &bi);
1596 leaf_paste_in_buffer(&bi, 1098 leaf_paste_in_buffer(&bi, item_pos, pos_in_item,
1597 item_pos, 1099 tb->insert_size[0], body, zeros_num);
1598 pos_in_item,
1599 tb->
1600 insert_size
1601 [0], body,
1602 zeros_num);
1603 1100
1604 if (is_indirect_le_ih(pasted)) { 1101 if (is_indirect_le_ih(pasted)) {
1605#if 0 1102#if 0
@@ -1611,8 +1108,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1611 tb-> 1108 tb->
1612 insert_size[0]); 1109 insert_size[0]);
1613#endif 1110#endif
1614 set_ih_free_space 1111 set_ih_free_space(pasted, 0);
1615 (pasted, 0);
1616 } 1112 }
1617 tb->insert_size[0] = 0; 1113 tb->insert_size[0] = 0;
1618 } 1114 }
@@ -1620,8 +1116,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1620 else { 1116 else {
1621 if (tb->insert_size[0]) { 1117 if (tb->insert_size[0]) {
1622 print_cur_tb("12285"); 1118 print_cur_tb("12285");
1623 reiserfs_panic(tb-> 1119 reiserfs_panic(tb->tb_sb,
1624 tb_sb,
1625 "PAP-12285", 1120 "PAP-12285",
1626 "insert_size " 1121 "insert_size "
1627 "must be 0 " 1122 "must be 0 "
diff --git a/fs/sync.c b/fs/sync.c
index f15537452231..b28d1dd10e8b 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -27,11 +27,10 @@
27 * wait == 1 case since in that case write_inode() functions do 27 * wait == 1 case since in that case write_inode() functions do
28 * sync_dirty_buffer() and thus effectively write one block at a time. 28 * sync_dirty_buffer() and thus effectively write one block at a time.
29 */ 29 */
30static int __sync_filesystem(struct super_block *sb, int wait, 30static int __sync_filesystem(struct super_block *sb, int wait)
31 unsigned long start)
32{ 31{
33 if (wait) 32 if (wait)
34 sync_inodes_sb(sb, start); 33 sync_inodes_sb(sb);
35 else 34 else
36 writeback_inodes_sb(sb, WB_REASON_SYNC); 35 writeback_inodes_sb(sb, WB_REASON_SYNC);
37 36
@@ -48,7 +47,6 @@ static int __sync_filesystem(struct super_block *sb, int wait,
48int sync_filesystem(struct super_block *sb) 47int sync_filesystem(struct super_block *sb)
49{ 48{
50 int ret; 49 int ret;
51 unsigned long start = jiffies;
52 50
53 /* 51 /*
54 * We need to be protected against the filesystem going from 52 * We need to be protected against the filesystem going from
@@ -62,17 +60,17 @@ int sync_filesystem(struct super_block *sb)
62 if (sb->s_flags & MS_RDONLY) 60 if (sb->s_flags & MS_RDONLY)
63 return 0; 61 return 0;
64 62
65 ret = __sync_filesystem(sb, 0, start); 63 ret = __sync_filesystem(sb, 0);
66 if (ret < 0) 64 if (ret < 0)
67 return ret; 65 return ret;
68 return __sync_filesystem(sb, 1, start); 66 return __sync_filesystem(sb, 1);
69} 67}
70EXPORT_SYMBOL_GPL(sync_filesystem); 68EXPORT_SYMBOL_GPL(sync_filesystem);
71 69
72static void sync_inodes_one_sb(struct super_block *sb, void *arg) 70static void sync_inodes_one_sb(struct super_block *sb, void *arg)
73{ 71{
74 if (!(sb->s_flags & MS_RDONLY)) 72 if (!(sb->s_flags & MS_RDONLY))
75 sync_inodes_sb(sb, *((unsigned long *)arg)); 73 sync_inodes_sb(sb);
76} 74}
77 75
78static void sync_fs_one_sb(struct super_block *sb, void *arg) 76static void sync_fs_one_sb(struct super_block *sb, void *arg)
@@ -104,10 +102,9 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
104SYSCALL_DEFINE0(sync) 102SYSCALL_DEFINE0(sync)
105{ 103{
106 int nowait = 0, wait = 1; 104 int nowait = 0, wait = 1;
107 unsigned long start = jiffies;
108 105
109 wakeup_flusher_threads(0, WB_REASON_SYNC); 106 wakeup_flusher_threads(0, WB_REASON_SYNC);
110 iterate_supers(sync_inodes_one_sb, &start); 107 iterate_supers(sync_inodes_one_sb, NULL);
111 iterate_supers(sync_fs_one_sb, &nowait); 108 iterate_supers(sync_fs_one_sb, &nowait);
112 iterate_supers(sync_fs_one_sb, &wait); 109 iterate_supers(sync_fs_one_sb, &wait);
113 iterate_bdevs(fdatawrite_one_bdev, NULL); 110 iterate_bdevs(fdatawrite_one_bdev, NULL);
@@ -222,23 +219,6 @@ SYSCALL_DEFINE1(fdatasync, unsigned int, fd)
222 return do_fsync(fd, 1); 219 return do_fsync(fd, 1);
223} 220}
224 221
225/**
226 * generic_write_sync - perform syncing after a write if file / inode is sync
227 * @file: file to which the write happened
228 * @pos: offset where the write started
229 * @count: length of the write
230 *
231 * This is just a simple wrapper about our general syncing function.
232 */
233int generic_write_sync(struct file *file, loff_t pos, loff_t count)
234{
235 if (!(file->f_flags & O_DSYNC) && !IS_SYNC(file->f_mapping->host))
236 return 0;
237 return vfs_fsync_range(file, pos, pos + count - 1,
238 (file->f_flags & __O_SYNC) ? 0 : 1);
239}
240EXPORT_SYMBOL(generic_write_sync);
241
242/* 222/*
243 * sys_sync_file_range() permits finely controlled syncing over a segment of 223 * sys_sync_file_range() permits finely controlled syncing over a segment of
244 * a file in the range offset .. (offset+nbytes-1) inclusive. If nbytes is 224 * a file in the range offset .. (offset+nbytes-1) inclusive. If nbytes is
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 6211230814fd..3eaf5c6622eb 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -27,6 +27,7 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type,
27{ 27{
28 struct dentry *root; 28 struct dentry *root;
29 void *ns; 29 void *ns;
30 bool new_sb;
30 31
31 if (!(flags & MS_KERNMOUNT)) { 32 if (!(flags & MS_KERNMOUNT)) {
32 if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type)) 33 if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type))
@@ -37,8 +38,8 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type,
37 } 38 }
38 39
39 ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET); 40 ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
40 root = kernfs_mount_ns(fs_type, flags, sysfs_root, ns); 41 root = kernfs_mount_ns(fs_type, flags, sysfs_root, &new_sb, ns);
41 if (IS_ERR(root)) 42 if (IS_ERR(root) || !new_sb)
42 kobj_ns_drop(KOBJ_NS_TYPE_NET, ns); 43 kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
43 return root; 44 return root;
44} 45}
diff --git a/fs/udf/file.c b/fs/udf/file.c
index c02a27a19c6d..1037637957c7 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -144,6 +144,7 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
144 size_t count = iocb->ki_nbytes; 144 size_t count = iocb->ki_nbytes;
145 struct udf_inode_info *iinfo = UDF_I(inode); 145 struct udf_inode_info *iinfo = UDF_I(inode);
146 146
147 mutex_lock(&inode->i_mutex);
147 down_write(&iinfo->i_data_sem); 148 down_write(&iinfo->i_data_sem);
148 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { 149 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
149 if (file->f_flags & O_APPEND) 150 if (file->f_flags & O_APPEND)
@@ -156,6 +157,7 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
156 pos + count)) { 157 pos + count)) {
157 err = udf_expand_file_adinicb(inode); 158 err = udf_expand_file_adinicb(inode);
158 if (err) { 159 if (err) {
160 mutex_unlock(&inode->i_mutex);
159 udf_debug("udf_expand_adinicb: err=%d\n", err); 161 udf_debug("udf_expand_adinicb: err=%d\n", err);
160 return err; 162 return err;
161 } 163 }
@@ -169,9 +171,17 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
169 } else 171 } else
170 up_write(&iinfo->i_data_sem); 172 up_write(&iinfo->i_data_sem);
171 173
172 retval = generic_file_aio_write(iocb, iov, nr_segs, ppos); 174 retval = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos);
173 if (retval > 0) 175 mutex_unlock(&inode->i_mutex);
176
177 if (retval > 0) {
178 ssize_t err;
179
174 mark_inode_dirty(inode); 180 mark_inode_dirty(inode);
181 err = generic_write_sync(file, iocb->ki_pos - retval, retval);
182 if (err < 0)
183 retval = err;
184 }
175 185
176 return retval; 186 return retval;
177} 187}
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 062b7925bca0..982ce05c87ed 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -265,6 +265,7 @@ int udf_expand_file_adinicb(struct inode *inode)
265 .nr_to_write = 1, 265 .nr_to_write = 1,
266 }; 266 };
267 267
268 WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
268 if (!iinfo->i_lenAlloc) { 269 if (!iinfo->i_lenAlloc) {
269 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) 270 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
270 iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT; 271 iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 2e7989e3a2d6..64b48eade91d 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -799,7 +799,7 @@ xfs_file_aio_write(
799 XFS_STATS_ADD(xs_write_bytes, ret); 799 XFS_STATS_ADD(xs_write_bytes, ret);
800 800
801 /* Handle various SYNC-type writes */ 801 /* Handle various SYNC-type writes */
802 err = generic_write_sync(file, pos, ret); 802 err = generic_write_sync(file, iocb->ki_pos - ret, ret);
803 if (err < 0) 803 if (err < 0)
804 ret = err; 804 ret = err;
805 } 805 }
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index f35d5c953ff9..9ddfb8190ca1 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -705,7 +705,6 @@ xfs_setattr_size(
705{ 705{
706 struct xfs_mount *mp = ip->i_mount; 706 struct xfs_mount *mp = ip->i_mount;
707 struct inode *inode = VFS_I(ip); 707 struct inode *inode = VFS_I(ip);
708 int mask = iattr->ia_valid;
709 xfs_off_t oldsize, newsize; 708 xfs_off_t oldsize, newsize;
710 struct xfs_trans *tp; 709 struct xfs_trans *tp;
711 int error; 710 int error;
@@ -726,8 +725,8 @@ xfs_setattr_size(
726 725
727 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); 726 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
728 ASSERT(S_ISREG(ip->i_d.di_mode)); 727 ASSERT(S_ISREG(ip->i_d.di_mode));
729 ASSERT((mask & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET| 728 ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
730 ATTR_MTIME_SET|ATTR_KILL_PRIV|ATTR_TIMES_SET)) == 0); 729 ATTR_MTIME_SET|ATTR_KILL_PRIV|ATTR_TIMES_SET)) == 0);
731 730
732 oldsize = inode->i_size; 731 oldsize = inode->i_size;
733 newsize = iattr->ia_size; 732 newsize = iattr->ia_size;
@@ -736,7 +735,7 @@ xfs_setattr_size(
736 * Short circuit the truncate case for zero length files. 735 * Short circuit the truncate case for zero length files.
737 */ 736 */
738 if (newsize == 0 && oldsize == 0 && ip->i_d.di_nextents == 0) { 737 if (newsize == 0 && oldsize == 0 && ip->i_d.di_nextents == 0) {
739 if (!(mask & (ATTR_CTIME|ATTR_MTIME))) 738 if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME)))
740 return 0; 739 return 0;
741 740
742 /* 741 /*
@@ -824,10 +823,11 @@ xfs_setattr_size(
824 * these flags set. For all other operations the VFS set these flags 823 * these flags set. For all other operations the VFS set these flags
825 * explicitly if it wants a timestamp update. 824 * explicitly if it wants a timestamp update.
826 */ 825 */
827 if (newsize != oldsize && (!(mask & (ATTR_CTIME | ATTR_MTIME)))) { 826 if (newsize != oldsize &&
827 !(iattr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) {
828 iattr->ia_ctime = iattr->ia_mtime = 828 iattr->ia_ctime = iattr->ia_mtime =
829 current_fs_time(inode->i_sb); 829 current_fs_time(inode->i_sb);
830 mask |= ATTR_CTIME | ATTR_MTIME; 830 iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
831 } 831 }
832 832
833 /* 833 /*
@@ -863,9 +863,9 @@ xfs_setattr_size(
863 xfs_inode_clear_eofblocks_tag(ip); 863 xfs_inode_clear_eofblocks_tag(ip);
864 } 864 }
865 865
866 if (mask & ATTR_MODE) 866 if (iattr->ia_valid & ATTR_MODE)
867 xfs_setattr_mode(ip, iattr); 867 xfs_setattr_mode(ip, iattr);
868 if (mask & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME)) 868 if (iattr->ia_valid & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME))
869 xfs_setattr_time(ip, iattr); 869 xfs_setattr_time(ip, iattr);
870 870
871 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); 871 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
diff --git a/fs/xfs/xfs_log_cil.c b/fs/xfs/xfs_log_cil.c
index cdebd832c3db..4ef6fdbced78 100644
--- a/fs/xfs/xfs_log_cil.c
+++ b/fs/xfs/xfs_log_cil.c
@@ -205,16 +205,25 @@ xlog_cil_insert_format_items(
205 /* 205 /*
206 * We 64-bit align the length of each iovec so that the start 206 * We 64-bit align the length of each iovec so that the start
207 * of the next one is naturally aligned. We'll need to 207 * of the next one is naturally aligned. We'll need to
208 * account for that slack space here. 208 * account for that slack space here. Then round nbytes up
209 * to 64-bit alignment so that the initial buffer alignment is
210 * easy to calculate and verify.
209 */ 211 */
210 nbytes += niovecs * sizeof(uint64_t); 212 nbytes += niovecs * sizeof(uint64_t);
213 nbytes = round_up(nbytes, sizeof(uint64_t));
211 214
212 /* grab the old item if it exists for reservation accounting */ 215 /* grab the old item if it exists for reservation accounting */
213 old_lv = lip->li_lv; 216 old_lv = lip->li_lv;
214 217
215 /* calc buffer size */ 218 /*
216 buf_size = sizeof(struct xfs_log_vec) + nbytes + 219 * The data buffer needs to start 64-bit aligned, so round up
217 niovecs * sizeof(struct xfs_log_iovec); 220 * that space to ensure we can align it appropriately and not
221 * overrun the buffer.
222 */
223 buf_size = nbytes +
224 round_up((sizeof(struct xfs_log_vec) +
225 niovecs * sizeof(struct xfs_log_iovec)),
226 sizeof(uint64_t));
218 227
219 /* compare to existing item size */ 228 /* compare to existing item size */
220 if (lip->li_lv && buf_size <= lip->li_lv->lv_size) { 229 if (lip->li_lv && buf_size <= lip->li_lv->lv_size) {
@@ -251,6 +260,8 @@ xlog_cil_insert_format_items(
251 /* The allocated data region lies beyond the iovec region */ 260 /* The allocated data region lies beyond the iovec region */
252 lv->lv_buf_len = 0; 261 lv->lv_buf_len = 0;
253 lv->lv_buf = (char *)lv + buf_size - nbytes; 262 lv->lv_buf = (char *)lv + buf_size - nbytes;
263 ASSERT(IS_ALIGNED((unsigned long)lv->lv_buf, sizeof(uint64_t)));
264
254 lip->li_ops->iop_format(lip, lv); 265 lip->li_ops->iop_format(lip, lv);
255insert: 266insert:
256 ASSERT(lv->lv_buf_len <= nbytes); 267 ASSERT(lv->lv_buf_len <= nbytes);
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 02df7b408a26..f96c05669a9e 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -282,22 +282,29 @@ xfs_readsb(
282 struct xfs_sb *sbp = &mp->m_sb; 282 struct xfs_sb *sbp = &mp->m_sb;
283 int error; 283 int error;
284 int loud = !(flags & XFS_MFSI_QUIET); 284 int loud = !(flags & XFS_MFSI_QUIET);
285 const struct xfs_buf_ops *buf_ops;
285 286
286 ASSERT(mp->m_sb_bp == NULL); 287 ASSERT(mp->m_sb_bp == NULL);
287 ASSERT(mp->m_ddev_targp != NULL); 288 ASSERT(mp->m_ddev_targp != NULL);
288 289
289 /* 290 /*
291 * For the initial read, we must guess at the sector
292 * size based on the block device. It's enough to
293 * get the sb_sectsize out of the superblock and
294 * then reread with the proper length.
295 * We don't verify it yet, because it may not be complete.
296 */
297 sector_size = xfs_getsize_buftarg(mp->m_ddev_targp);
298 buf_ops = NULL;
299
300 /*
290 * Allocate a (locked) buffer to hold the superblock. 301 * Allocate a (locked) buffer to hold the superblock.
291 * This will be kept around at all times to optimize 302 * This will be kept around at all times to optimize
292 * access to the superblock. 303 * access to the superblock.
293 */ 304 */
294 sector_size = xfs_getsize_buftarg(mp->m_ddev_targp);
295
296reread: 305reread:
297 bp = xfs_buf_read_uncached(mp->m_ddev_targp, XFS_SB_DADDR, 306 bp = xfs_buf_read_uncached(mp->m_ddev_targp, XFS_SB_DADDR,
298 BTOBB(sector_size), 0, 307 BTOBB(sector_size), 0, buf_ops);
299 loud ? &xfs_sb_buf_ops
300 : &xfs_sb_quiet_buf_ops);
301 if (!bp) { 308 if (!bp) {
302 if (loud) 309 if (loud)
303 xfs_warn(mp, "SB buffer read failed"); 310 xfs_warn(mp, "SB buffer read failed");
@@ -328,12 +335,13 @@ reread:
328 } 335 }
329 336
330 /* 337 /*
331 * If device sector size is smaller than the superblock size, 338 * Re-read the superblock so the buffer is correctly sized,
332 * re-read the superblock so the buffer is correctly sized. 339 * and properly verified.
333 */ 340 */
334 if (sector_size < sbp->sb_sectsize) { 341 if (buf_ops == NULL) {
335 xfs_buf_relse(bp); 342 xfs_buf_relse(bp);
336 sector_size = sbp->sb_sectsize; 343 sector_size = sbp->sb_sectsize;
344 buf_ops = loud ? &xfs_sb_buf_ops : &xfs_sb_quiet_buf_ops;
337 goto reread; 345 goto reread;
338 } 346 }
339 347
diff --git a/fs/xfs/xfs_sb.c b/fs/xfs/xfs_sb.c
index b7c9aea77f8f..1e116794bb66 100644
--- a/fs/xfs/xfs_sb.c
+++ b/fs/xfs/xfs_sb.c
@@ -295,8 +295,7 @@ xfs_mount_validate_sb(
295 sbp->sb_dblocks == 0 || 295 sbp->sb_dblocks == 0 ||
296 sbp->sb_dblocks > XFS_MAX_DBLOCKS(sbp) || 296 sbp->sb_dblocks > XFS_MAX_DBLOCKS(sbp) ||
297 sbp->sb_dblocks < XFS_MIN_DBLOCKS(sbp))) { 297 sbp->sb_dblocks < XFS_MIN_DBLOCKS(sbp))) {
298 XFS_CORRUPTION_ERROR("SB sanity check failed", 298 xfs_notice(mp, "SB sanity check failed");
299 XFS_ERRLEVEL_LOW, mp, sbp);
300 return XFS_ERROR(EFSCORRUPTED); 299 return XFS_ERROR(EFSCORRUPTED);
301 } 300 }
302 301
@@ -611,10 +610,10 @@ xfs_sb_read_verify(
611 XFS_SB_VERSION_5) || 610 XFS_SB_VERSION_5) ||
612 dsb->sb_crc != 0)) { 611 dsb->sb_crc != 0)) {
613 612
614 if (!xfs_verify_cksum(bp->b_addr, be16_to_cpu(dsb->sb_sectsize), 613 if (!xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length),
615 offsetof(struct xfs_sb, sb_crc))) { 614 offsetof(struct xfs_sb, sb_crc))) {
616 /* Only fail bad secondaries on a known V5 filesystem */ 615 /* Only fail bad secondaries on a known V5 filesystem */
617 if (bp->b_bn != XFS_SB_DADDR && 616 if (bp->b_bn == XFS_SB_DADDR ||
618 xfs_sb_version_hascrc(&mp->m_sb)) { 617 xfs_sb_version_hascrc(&mp->m_sb)) {
619 error = EFSCORRUPTED; 618 error = EFSCORRUPTED;
620 goto out_error; 619 goto out_error;
@@ -625,7 +624,7 @@ xfs_sb_read_verify(
625 624
626out_error: 625out_error:
627 if (error) { 626 if (error) {
628 if (error != EWRONGFS) 627 if (error == EFSCORRUPTED)
629 XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, 628 XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW,
630 mp, bp->b_addr); 629 mp, bp->b_addr);
631 xfs_buf_ioerror(bp, error); 630 xfs_buf_ioerror(bp, error);
@@ -644,7 +643,6 @@ xfs_sb_quiet_read_verify(
644{ 643{
645 struct xfs_dsb *dsb = XFS_BUF_TO_SBP(bp); 644 struct xfs_dsb *dsb = XFS_BUF_TO_SBP(bp);
646 645
647
648 if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC)) { 646 if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC)) {
649 /* XFS filesystem, verify noisily! */ 647 /* XFS filesystem, verify noisily! */
650 xfs_sb_read_verify(bp); 648 xfs_sb_read_verify(bp);
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index f317488263dd..d971f4932b5d 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -913,7 +913,7 @@ xfs_flush_inodes(
913 struct super_block *sb = mp->m_super; 913 struct super_block *sb = mp->m_super;
914 914
915 if (down_read_trylock(&sb->s_umount)) { 915 if (down_read_trylock(&sb->s_umount)) {
916 sync_inodes_sb(sb, jiffies); 916 sync_inodes_sb(sb);
917 up_read(&sb->s_umount); 917 up_read(&sb->s_umount);
918 } 918 }
919} 919}
diff --git a/include/asm-generic/bitops/const_hweight.h b/include/asm-generic/bitops/const_hweight.h
index fa2a50b7ee66..0a7e06623470 100644
--- a/include/asm-generic/bitops/const_hweight.h
+++ b/include/asm-generic/bitops/const_hweight.h
@@ -5,14 +5,15 @@
5 * Compile time versions of __arch_hweightN() 5 * Compile time versions of __arch_hweightN()
6 */ 6 */
7#define __const_hweight8(w) \ 7#define __const_hweight8(w) \
8 ( (!!((w) & (1ULL << 0))) + \ 8 ((unsigned int) \
9 (!!((w) & (1ULL << 1))) + \ 9 ((!!((w) & (1ULL << 0))) + \
10 (!!((w) & (1ULL << 2))) + \ 10 (!!((w) & (1ULL << 1))) + \
11 (!!((w) & (1ULL << 3))) + \ 11 (!!((w) & (1ULL << 2))) + \
12 (!!((w) & (1ULL << 4))) + \ 12 (!!((w) & (1ULL << 3))) + \
13 (!!((w) & (1ULL << 5))) + \ 13 (!!((w) & (1ULL << 4))) + \
14 (!!((w) & (1ULL << 6))) + \ 14 (!!((w) & (1ULL << 5))) + \
15 (!!((w) & (1ULL << 7))) ) 15 (!!((w) & (1ULL << 6))) + \
16 (!!((w) & (1ULL << 7)))))
16 17
17#define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8 )) 18#define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8 ))
18#define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16)) 19#define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))
diff --git a/include/asm-generic/mcs_spinlock.h b/include/asm-generic/mcs_spinlock.h
new file mode 100644
index 000000000000..10cd4ffc6ba2
--- /dev/null
+++ b/include/asm-generic/mcs_spinlock.h
@@ -0,0 +1,13 @@
1#ifndef __ASM_MCS_SPINLOCK_H
2#define __ASM_MCS_SPINLOCK_H
3
4/*
5 * Architectures can define their own:
6 *
7 * arch_mcs_spin_lock_contended(l)
8 * arch_mcs_spin_unlock_contended(l)
9 *
10 * See kernel/locking/mcs_spinlock.c.
11 */
12
13#endif /* __ASM_MCS_SPINLOCK_H */
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 8e4f41d9af4d..1ec08c198b66 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -193,6 +193,19 @@ static inline int pte_same(pte_t pte_a, pte_t pte_b)
193} 193}
194#endif 194#endif
195 195
196#ifndef __HAVE_ARCH_PTE_UNUSED
197/*
198 * Some architectures provide facilities to virtualization guests
199 * so that they can flag allocated pages as unused. This allows the
200 * host to transparently reclaim unused pages. This function returns
201 * whether the pte's page is unused.
202 */
203static inline int pte_unused(pte_t pte)
204{
205 return 0;
206}
207#endif
208
196#ifndef __HAVE_ARCH_PMD_SAME 209#ifndef __HAVE_ARCH_PMD_SAME
197#ifdef CONFIG_TRANSPARENT_HUGEPAGE 210#ifdef CONFIG_TRANSPARENT_HUGEPAGE
198static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b) 211static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b)
@@ -701,6 +714,18 @@ static inline pte_t pte_mknuma(pte_t pte)
701} 714}
702#endif 715#endif
703 716
717#ifndef ptep_set_numa
718static inline void ptep_set_numa(struct mm_struct *mm, unsigned long addr,
719 pte_t *ptep)
720{
721 pte_t ptent = *ptep;
722
723 ptent = pte_mknuma(ptent);
724 set_pte_at(mm, addr, ptep, ptent);
725 return;
726}
727#endif
728
704#ifndef pmd_mknuma 729#ifndef pmd_mknuma
705static inline pmd_t pmd_mknuma(pmd_t pmd) 730static inline pmd_t pmd_mknuma(pmd_t pmd)
706{ 731{
@@ -708,6 +733,18 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
708 return pmd_clear_flags(pmd, _PAGE_PRESENT); 733 return pmd_clear_flags(pmd, _PAGE_PRESENT);
709} 734}
710#endif 735#endif
736
737#ifndef pmdp_set_numa
738static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
739 pmd_t *pmdp)
740{
741 pmd_t pmd = *pmdp;
742
743 pmd = pmd_mknuma(pmd);
744 set_pmd_at(mm, addr, pmdp, pmd);
745 return;
746}
747#endif
711#else 748#else
712extern int pte_numa(pte_t pte); 749extern int pte_numa(pte_t pte);
713extern int pmd_numa(pmd_t pmd); 750extern int pmd_numa(pmd_t pmd);
@@ -715,6 +752,8 @@ extern pte_t pte_mknonnuma(pte_t pte);
715extern pmd_t pmd_mknonnuma(pmd_t pmd); 752extern pmd_t pmd_mknonnuma(pmd_t pmd);
716extern pte_t pte_mknuma(pte_t pte); 753extern pte_t pte_mknuma(pte_t pte);
717extern pmd_t pmd_mknuma(pmd_t pmd); 754extern pmd_t pmd_mknuma(pmd_t pmd);
755extern void ptep_set_numa(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
756extern void pmdp_set_numa(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp);
718#endif /* CONFIG_ARCH_USES_NUMA_PROT_NONE */ 757#endif /* CONFIG_ARCH_USES_NUMA_PROT_NONE */
719#else 758#else
720static inline int pmd_numa(pmd_t pmd) 759static inline int pmd_numa(pmd_t pmd)
@@ -742,10 +781,23 @@ static inline pte_t pte_mknuma(pte_t pte)
742 return pte; 781 return pte;
743} 782}
744 783
784static inline void ptep_set_numa(struct mm_struct *mm, unsigned long addr,
785 pte_t *ptep)
786{
787 return;
788}
789
790
745static inline pmd_t pmd_mknuma(pmd_t pmd) 791static inline pmd_t pmd_mknuma(pmd_t pmd)
746{ 792{
747 return pmd; 793 return pmd;
748} 794}
795
796static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
797 pmd_t *pmdp)
798{
799 return ;
800}
749#endif /* CONFIG_NUMA_BALANCING */ 801#endif /* CONFIG_NUMA_BALANCING */
750 802
751#endif /* CONFIG_MMU */ 803#endif /* CONFIG_MMU */
diff --git a/include/asm-generic/rwsem.h b/include/asm-generic/rwsem.h
index bb1e2cdeb9bf..d48bf5a95cc1 100644
--- a/include/asm-generic/rwsem.h
+++ b/include/asm-generic/rwsem.h
@@ -1,5 +1,5 @@
1#ifndef _ASM_POWERPC_RWSEM_H 1#ifndef _ASM_GENERIC_RWSEM_H
2#define _ASM_POWERPC_RWSEM_H 2#define _ASM_GENERIC_RWSEM_H
3 3
4#ifndef _LINUX_RWSEM_H 4#ifndef _LINUX_RWSEM_H
5#error "Please don't include <asm/rwsem.h> directly, use <linux/rwsem.h> instead." 5#error "Please don't include <asm/rwsem.h> directly, use <linux/rwsem.h> instead."
@@ -8,7 +8,7 @@
8#ifdef __KERNEL__ 8#ifdef __KERNEL__
9 9
10/* 10/*
11 * R/W semaphores for PPC using the stuff in lib/rwsem.c. 11 * R/W semaphores originally for PPC using the stuff in lib/rwsem.c.
12 * Adapted largely from include/asm-i386/rwsem.h 12 * Adapted largely from include/asm-i386/rwsem.h
13 * by Paul Mackerras <paulus@samba.org>. 13 * by Paul Mackerras <paulus@samba.org>.
14 */ 14 */
@@ -16,7 +16,7 @@
16/* 16/*
17 * the semaphore definition 17 * the semaphore definition
18 */ 18 */
19#ifdef CONFIG_PPC64 19#ifdef CONFIG_64BIT
20# define RWSEM_ACTIVE_MASK 0xffffffffL 20# define RWSEM_ACTIVE_MASK 0xffffffffL
21#else 21#else
22# define RWSEM_ACTIVE_MASK 0x0000ffffL 22# define RWSEM_ACTIVE_MASK 0x0000ffffL
@@ -129,4 +129,4 @@ static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
129} 129}
130 130
131#endif /* __KERNEL__ */ 131#endif /* __KERNEL__ */
132#endif /* _ASM_POWERPC_RWSEM_H */ 132#endif /* _ASM_GENERIC_RWSEM_H */
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 04086c5be930..04a7f31301f8 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -199,6 +199,9 @@ int drm_err(const char *func, const char *format, ...);
199#define DRM_INFO(fmt, ...) \ 199#define DRM_INFO(fmt, ...) \
200 printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__) 200 printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
201 201
202#define DRM_INFO_ONCE(fmt, ...) \
203 printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
204
202/** 205/**
203 * Debug output. 206 * Debug output.
204 * 207 *
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 71727b6210ae..8f3dee097579 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -907,6 +907,9 @@ struct drm_mode_config {
907 907
908 /* whether async page flip is supported or not */ 908 /* whether async page flip is supported or not */
909 bool async_page_flip; 909 bool async_page_flip;
910
911 /* cursor size */
912 uint32_t cursor_width, cursor_height;
910}; 913};
911 914
912#define obj_to_crtc(x) container_of(x, struct drm_crtc, base) 915#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
index d1f61bfe0ebe..49a828425fa2 100644
--- a/include/drm/ttm/ttm_page_alloc.h
+++ b/include/drm/ttm/ttm_page_alloc.h
@@ -29,6 +29,8 @@
29#include <drm/ttm/ttm_bo_driver.h> 29#include <drm/ttm/ttm_bo_driver.h>
30#include <drm/ttm/ttm_memory.h> 30#include <drm/ttm/ttm_memory.h>
31 31
32struct device;
33
32/** 34/**
33 * Initialize pool allocator. 35 * Initialize pool allocator.
34 */ 36 */
diff --git a/include/dt-bindings/clock/tegra124-car.h b/include/dt-bindings/clock/tegra124-car.h
index a1116a3b54ef..8c1603b10665 100644
--- a/include/dt-bindings/clock/tegra124-car.h
+++ b/include/dt-bindings/clock/tegra124-car.h
@@ -36,10 +36,10 @@
36#define TEGRA124_CLK_PWM 17 36#define TEGRA124_CLK_PWM 17
37#define TEGRA124_CLK_I2S2 18 37#define TEGRA124_CLK_I2S2 18
38/* 20 (register bit affects vi and vi_sensor) */ 38/* 20 (register bit affects vi and vi_sensor) */
39#define TEGRA124_CLK_GR_2D 21 39/* 21 */
40#define TEGRA124_CLK_USBD 22 40#define TEGRA124_CLK_USBD 22
41#define TEGRA124_CLK_ISP 23 41#define TEGRA124_CLK_ISP 23
42#define TEGRA124_CLK_GR_3D 24 42/* 26 */
43/* 25 */ 43/* 25 */
44#define TEGRA124_CLK_DISP2 26 44#define TEGRA124_CLK_DISP2 26
45#define TEGRA124_CLK_DISP1 27 45#define TEGRA124_CLK_DISP1 27
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index be85127bfed3..f27000f55a83 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -171,6 +171,11 @@ static inline int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 add
171 return 0; 171 return 0;
172} 172}
173 173
174static inline int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
175{
176 return -ENXIO;
177}
178
174static inline int kvm_vgic_init(struct kvm *kvm) 179static inline int kvm_vgic_init(struct kvm *kvm)
175{ 180{
176 return 0; 181 return 0;
diff --git a/include/linux/audit.h b/include/linux/audit.h
index aa865a9a4c4f..ec1464df4c60 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -43,6 +43,7 @@ struct mq_attr;
43struct mqstat; 43struct mqstat;
44struct audit_watch; 44struct audit_watch;
45struct audit_tree; 45struct audit_tree;
46struct sk_buff;
46 47
47struct audit_krule { 48struct audit_krule {
48 int vers_ops; 49 int vers_ops;
@@ -463,7 +464,7 @@ extern int audit_filter_user(int type);
463extern int audit_filter_type(int type); 464extern int audit_filter_type(int type);
464extern int audit_rule_change(int type, __u32 portid, int seq, 465extern int audit_rule_change(int type, __u32 portid, int seq,
465 void *data, size_t datasz); 466 void *data, size_t datasz);
466extern int audit_list_rules_send(__u32 portid, int seq); 467extern int audit_list_rules_send(struct sk_buff *request_skb, int seq);
467 468
468extern u32 audit_enabled; 469extern u32 audit_enabled;
469#else /* CONFIG_AUDIT */ 470#else /* CONFIG_AUDIT */
diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
index fd8bf3219ef7..b4a745d7d9a9 100644
--- a/include/linux/binfmts.h
+++ b/include/linux/binfmts.h
@@ -115,7 +115,6 @@ extern int copy_strings_kernel(int argc, const char *const *argv,
115extern int prepare_bprm_creds(struct linux_binprm *bprm); 115extern int prepare_bprm_creds(struct linux_binprm *bprm);
116extern void install_exec_creds(struct linux_binprm *bprm); 116extern void install_exec_creds(struct linux_binprm *bprm);
117extern void set_binfmt(struct linux_binfmt *new); 117extern void set_binfmt(struct linux_binfmt *new);
118extern void free_bprm(struct linux_binprm *);
119extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t); 118extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);
120 119
121#endif /* _LINUX_BINFMTS_H */ 120#endif /* _LINUX_BINFMTS_H */
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 70654521dab6..5a4d39b4686b 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -250,6 +250,17 @@ static inline unsigned bio_segments(struct bio *bio)
250 struct bio_vec bv; 250 struct bio_vec bv;
251 struct bvec_iter iter; 251 struct bvec_iter iter;
252 252
253 /*
254 * We special case discard/write same, because they interpret bi_size
255 * differently:
256 */
257
258 if (bio->bi_rw & REQ_DISCARD)
259 return 1;
260
261 if (bio->bi_rw & REQ_WRITE_SAME)
262 return 1;
263
253 bio_for_each_segment(bv, bio, iter) 264 bio_for_each_segment(bv, bio, iter)
254 segs++; 265 segs++;
255 266
@@ -332,6 +343,7 @@ extern struct bio *bio_clone_fast(struct bio *, gfp_t, struct bio_set *);
332extern struct bio *bio_clone_bioset(struct bio *, gfp_t, struct bio_set *bs); 343extern struct bio *bio_clone_bioset(struct bio *, gfp_t, struct bio_set *bs);
333 344
334extern struct bio_set *fs_bio_set; 345extern struct bio_set *fs_bio_set;
346unsigned int bio_integrity_tag_size(struct bio *bio);
335 347
336static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs) 348static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs)
337{ 349{
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index abc9ca778456..be5fd38bd5a0 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -196,6 +196,21 @@ static inline unsigned long __ffs64(u64 word)
196 196
197#ifdef __KERNEL__ 197#ifdef __KERNEL__
198 198
199#ifndef set_mask_bits
200#define set_mask_bits(ptr, _mask, _bits) \
201({ \
202 const typeof(*ptr) mask = (_mask), bits = (_bits); \
203 typeof(*ptr) old, new; \
204 \
205 do { \
206 old = ACCESS_ONCE(*ptr); \
207 new = (old & ~mask) | bits; \
208 } while (cmpxchg(ptr, old, new) != old); \
209 \
210 new; \
211})
212#endif
213
199#ifndef find_last_bit 214#ifndef find_last_bit
200/** 215/**
201 * find_last_bit - find the last set bit in a memory region 216 * find_last_bit - find the last set bit in a memory region
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 161b23105b1e..2ff2e8d982be 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -83,6 +83,8 @@ struct blk_mq_ops {
83 */ 83 */
84 rq_timed_out_fn *timeout; 84 rq_timed_out_fn *timeout;
85 85
86 softirq_done_fn *complete;
87
86 /* 88 /*
87 * Override for hctx allocations (should probably go) 89 * Override for hctx allocations (should probably go)
88 */ 90 */
@@ -119,11 +121,11 @@ void blk_mq_init_commands(struct request_queue *, void (*init)(void *data, struc
119 121
120void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule); 122void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule);
121 123
122void blk_mq_insert_request(struct request_queue *, struct request *, bool); 124void blk_mq_insert_request(struct request *, bool, bool, bool);
123void blk_mq_run_queues(struct request_queue *q, bool async); 125void blk_mq_run_queues(struct request_queue *q, bool async);
124void blk_mq_free_request(struct request *rq); 126void blk_mq_free_request(struct request *rq);
125bool blk_mq_can_queue(struct blk_mq_hw_ctx *); 127bool blk_mq_can_queue(struct blk_mq_hw_ctx *);
126struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp, bool reserved); 128struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp);
127struct request *blk_mq_alloc_reserved_request(struct request_queue *q, int rw, gfp_t gfp); 129struct request *blk_mq_alloc_reserved_request(struct request_queue *q, int rw, gfp_t gfp);
128struct request *blk_mq_rq_from_tag(struct request_queue *q, unsigned int tag); 130struct request *blk_mq_rq_from_tag(struct request_queue *q, unsigned int tag);
129 131
@@ -131,7 +133,15 @@ struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_ind
131struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_reg *, unsigned int); 133struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_reg *, unsigned int);
132void blk_mq_free_single_hw_queue(struct blk_mq_hw_ctx *, unsigned int); 134void blk_mq_free_single_hw_queue(struct blk_mq_hw_ctx *, unsigned int);
133 135
134void blk_mq_end_io(struct request *rq, int error); 136bool blk_mq_end_io_partial(struct request *rq, int error,
137 unsigned int nr_bytes);
138static inline void blk_mq_end_io(struct request *rq, int error)
139{
140 bool done = !blk_mq_end_io_partial(rq, error, blk_rq_bytes(rq));
141 BUG_ON(!done);
142}
143
144void blk_mq_complete_request(struct request *rq);
135 145
136void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx); 146void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx);
137void blk_mq_start_hw_queue(struct blk_mq_hw_ctx *hctx); 147void blk_mq_start_hw_queue(struct blk_mq_hw_ctx *hctx);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 8678c4322b44..4afa4f8f6090 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -98,7 +98,7 @@ struct request {
98 struct list_head queuelist; 98 struct list_head queuelist;
99 union { 99 union {
100 struct call_single_data csd; 100 struct call_single_data csd;
101 struct work_struct mq_flush_data; 101 struct work_struct mq_flush_work;
102 }; 102 };
103 103
104 struct request_queue *q; 104 struct request_queue *q;
@@ -448,13 +448,8 @@ struct request_queue {
448 unsigned long flush_pending_since; 448 unsigned long flush_pending_since;
449 struct list_head flush_queue[2]; 449 struct list_head flush_queue[2];
450 struct list_head flush_data_in_flight; 450 struct list_head flush_data_in_flight;
451 union { 451 struct request *flush_rq;
452 struct request flush_rq; 452 spinlock_t mq_flush_lock;
453 struct {
454 spinlock_t mq_flush_lock;
455 struct work_struct mq_flush_work;
456 };
457 };
458 453
459 struct mutex sysfs_lock; 454 struct mutex sysfs_lock;
460 455
diff --git a/include/linux/can/skb.h b/include/linux/can/skb.h
index 2f0543f7510c..f9bbbb472663 100644
--- a/include/linux/can/skb.h
+++ b/include/linux/can/skb.h
@@ -11,7 +11,9 @@
11#define CAN_SKB_H 11#define CAN_SKB_H
12 12
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/skbuff.h>
14#include <linux/can.h> 15#include <linux/can.h>
16#include <net/sock.h>
15 17
16/* 18/*
17 * The struct can_skb_priv is used to transport additional information along 19 * The struct can_skb_priv is used to transport additional information along
@@ -42,4 +44,40 @@ static inline void can_skb_reserve(struct sk_buff *skb)
42 skb_reserve(skb, sizeof(struct can_skb_priv)); 44 skb_reserve(skb, sizeof(struct can_skb_priv));
43} 45}
44 46
47static inline void can_skb_destructor(struct sk_buff *skb)
48{
49 sock_put(skb->sk);
50}
51
52static inline void can_skb_set_owner(struct sk_buff *skb, struct sock *sk)
53{
54 if (sk) {
55 sock_hold(sk);
56 skb->destructor = can_skb_destructor;
57 skb->sk = sk;
58 }
59}
60
61/*
62 * returns an unshared skb owned by the original sock to be echo'ed back
63 */
64static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb)
65{
66 if (skb_shared(skb)) {
67 struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
68
69 if (likely(nskb)) {
70 can_skb_set_owner(nskb, skb->sk);
71 consume_skb(skb);
72 return nskb;
73 } else {
74 kfree_skb(skb);
75 return NULL;
76 }
77 }
78
79 /* we can assume to have an unshared skb with proper owner */
80 return skb;
81}
82
45#endif /* CAN_SKB_H */ 83#endif /* CAN_SKB_H */
diff --git a/include/linux/ceph/ceph_fs.h b/include/linux/ceph/ceph_fs.h
index 2623cffc73a1..25bfb0eff772 100644
--- a/include/linux/ceph/ceph_fs.h
+++ b/include/linux/ceph/ceph_fs.h
@@ -373,8 +373,9 @@ extern const char *ceph_mds_op_name(int op);
373/* 373/*
374 * Ceph setxattr request flags. 374 * Ceph setxattr request flags.
375 */ 375 */
376#define CEPH_XATTR_CREATE 1 376#define CEPH_XATTR_CREATE (1 << 0)
377#define CEPH_XATTR_REPLACE 2 377#define CEPH_XATTR_REPLACE (1 << 1)
378#define CEPH_XATTR_REMOVE (1 << 31)
378 379
379union ceph_mds_request_args { 380union ceph_mds_request_args {
380 struct { 381 struct {
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 5c097596104b..9450f025fe0c 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -166,6 +166,8 @@ struct cgroup {
166 * 166 *
167 * The ID of the root cgroup is always 0, and a new cgroup 167 * The ID of the root cgroup is always 0, and a new cgroup
168 * will be assigned with a smallest available ID. 168 * will be assigned with a smallest available ID.
169 *
170 * Allocating/Removing ID must be protected by cgroup_mutex.
169 */ 171 */
170 int id; 172 int id;
171 173
diff --git a/include/linux/clk/ti.h b/include/linux/clk/ti.h
index 092b64168d7f..4a21a872dbbd 100644
--- a/include/linux/clk/ti.h
+++ b/include/linux/clk/ti.h
@@ -245,6 +245,10 @@ long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate,
245void omap2_init_clk_clkdm(struct clk_hw *clk); 245void omap2_init_clk_clkdm(struct clk_hw *clk);
246unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw, 246unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
247 unsigned long parent_rate); 247 unsigned long parent_rate);
248int omap3_clkoutx2_set_rate(struct clk_hw *hw, unsigned long rate,
249 unsigned long parent_rate);
250long omap3_clkoutx2_round_rate(struct clk_hw *hw, unsigned long rate,
251 unsigned long *prate);
248int omap2_clkops_enable_clkdm(struct clk_hw *hw); 252int omap2_clkops_enable_clkdm(struct clk_hw *hw);
249void omap2_clkops_disable_clkdm(struct clk_hw *hw); 253void omap2_clkops_disable_clkdm(struct clk_hw *hw);
250int omap2_clk_disable_autoidle_all(void); 254int omap2_clk_disable_autoidle_all(void);
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 3f448c65511b..01c0aa57ccec 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -14,6 +14,7 @@
14#include <linux/if.h> 14#include <linux/if.h>
15#include <linux/fs.h> 15#include <linux/fs.h>
16#include <linux/aio_abi.h> /* for aio_context_t */ 16#include <linux/aio_abi.h> /* for aio_context_t */
17#include <linux/unistd.h>
17 18
18#include <asm/compat.h> 19#include <asm/compat.h>
19#include <asm/siginfo.h> 20#include <asm/siginfo.h>
@@ -27,6 +28,9 @@
27#define __SC_DELOUSE(t,v) ((t)(unsigned long)(v)) 28#define __SC_DELOUSE(t,v) ((t)(unsigned long)(v))
28#endif 29#endif
29 30
31#define COMPAT_SYSCALL_DEFINE0(name) \
32 asmlinkage long compat_sys_##name(void)
33
30#define COMPAT_SYSCALL_DEFINE1(name, ...) \ 34#define COMPAT_SYSCALL_DEFINE1(name, ...) \
31 COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__) 35 COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
32#define COMPAT_SYSCALL_DEFINE2(name, ...) \ 36#define COMPAT_SYSCALL_DEFINE2(name, ...) \
@@ -68,6 +72,8 @@ typedef struct compat_sigaltstack {
68typedef __compat_uid32_t compat_uid_t; 72typedef __compat_uid32_t compat_uid_t;
69typedef __compat_gid32_t compat_gid_t; 73typedef __compat_gid32_t compat_gid_t;
70 74
75typedef compat_ulong_t compat_aio_context_t;
76
71struct compat_sel_arg_struct; 77struct compat_sel_arg_struct;
72struct rusage; 78struct rusage;
73 79
@@ -318,7 +324,7 @@ asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
318asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp, 324asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
319 compat_ssize_t msgsz, int msgflg); 325 compat_ssize_t msgsz, int msgflg);
320asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp, 326asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp,
321 compat_ssize_t msgsz, long msgtyp, int msgflg); 327 compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);
322long compat_sys_msgctl(int first, int second, void __user *uptr); 328long compat_sys_msgctl(int first, int second, void __user *uptr);
323long compat_sys_shmctl(int first, int second, void __user *uptr); 329long compat_sys_shmctl(int first, int second, void __user *uptr);
324long compat_sys_semtimedop(int semid, struct sembuf __user *tsems, 330long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
@@ -337,6 +343,19 @@ asmlinkage ssize_t compat_sys_preadv(compat_ulong_t fd,
337asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd, 343asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd,
338 const struct compat_iovec __user *vec, 344 const struct compat_iovec __user *vec,
339 compat_ulong_t vlen, u32 pos_low, u32 pos_high); 345 compat_ulong_t vlen, u32 pos_low, u32 pos_high);
346
347#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64
348asmlinkage long compat_sys_preadv64(unsigned long fd,
349 const struct compat_iovec __user *vec,
350 unsigned long vlen, loff_t pos);
351#endif
352
353#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64
354asmlinkage long compat_sys_pwritev64(unsigned long fd,
355 const struct compat_iovec __user *vec,
356 unsigned long vlen, loff_t pos);
357#endif
358
340asmlinkage long compat_sys_lseek(unsigned int, compat_off_t, unsigned int); 359asmlinkage long compat_sys_lseek(unsigned int, compat_off_t, unsigned int);
341 360
342asmlinkage long compat_sys_execve(const char __user *filename, const compat_uptr_t __user *argv, 361asmlinkage long compat_sys_execve(const char __user *filename, const compat_uptr_t __user *argv,
@@ -451,7 +470,7 @@ asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
451asmlinkage long compat_sys_timerfd_gettime(int ufd, 470asmlinkage long compat_sys_timerfd_gettime(int ufd,
452 struct compat_itimerspec __user *otmr); 471 struct compat_itimerspec __user *otmr);
453 472
454asmlinkage long compat_sys_move_pages(pid_t pid, unsigned long nr_page, 473asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages,
455 __u32 __user *pages, 474 __u32 __user *pages,
456 const int __user *nodes, 475 const int __user *nodes,
457 int __user *status, 476 int __user *status,
@@ -481,20 +500,20 @@ asmlinkage long compat_sys_statfs64(const char __user *pathname,
481asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, 500asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
482 struct compat_statfs64 __user *buf); 501 struct compat_statfs64 __user *buf);
483asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd, 502asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
484 unsigned long arg); 503 compat_ulong_t arg);
485asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd, 504asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
486 unsigned long arg); 505 compat_ulong_t arg);
487asmlinkage long compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p); 506asmlinkage long compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p);
488asmlinkage long compat_sys_io_getevents(aio_context_t ctx_id, 507asmlinkage long compat_sys_io_getevents(compat_aio_context_t ctx_id,
489 unsigned long min_nr, 508 compat_long_t min_nr,
490 unsigned long nr, 509 compat_long_t nr,
491 struct io_event __user *events, 510 struct io_event __user *events,
492 struct compat_timespec __user *timeout); 511 struct compat_timespec __user *timeout);
493asmlinkage long compat_sys_io_submit(aio_context_t ctx_id, int nr, 512asmlinkage long compat_sys_io_submit(compat_aio_context_t ctx_id, int nr,
494 u32 __user *iocb); 513 u32 __user *iocb);
495asmlinkage long compat_sys_mount(const char __user *dev_name, 514asmlinkage long compat_sys_mount(const char __user *dev_name,
496 const char __user *dir_name, 515 const char __user *dir_name,
497 const char __user *type, unsigned long flags, 516 const char __user *type, compat_ulong_t flags,
498 const void __user *data); 517 const void __user *data);
499asmlinkage long compat_sys_old_readdir(unsigned int fd, 518asmlinkage long compat_sys_old_readdir(unsigned int fd,
500 struct compat_old_linux_dirent __user *, 519 struct compat_old_linux_dirent __user *,
@@ -502,9 +521,11 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
502asmlinkage long compat_sys_getdents(unsigned int fd, 521asmlinkage long compat_sys_getdents(unsigned int fd,
503 struct compat_linux_dirent __user *dirent, 522 struct compat_linux_dirent __user *dirent,
504 unsigned int count); 523 unsigned int count);
524#ifdef __ARCH_WANT_COMPAT_SYS_GETDENTS64
505asmlinkage long compat_sys_getdents64(unsigned int fd, 525asmlinkage long compat_sys_getdents64(unsigned int fd,
506 struct linux_dirent64 __user *dirent, 526 struct linux_dirent64 __user *dirent,
507 unsigned int count); 527 unsigned int count);
528#endif
508asmlinkage long compat_sys_vmsplice(int fd, const struct compat_iovec __user *, 529asmlinkage long compat_sys_vmsplice(int fd, const struct compat_iovec __user *,
509 unsigned int nr_segs, unsigned int flags); 530 unsigned int nr_segs, unsigned int flags);
510asmlinkage long compat_sys_open(const char __user *filename, int flags, 531asmlinkage long compat_sys_open(const char __user *filename, int flags,
@@ -549,9 +570,9 @@ asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
549 unsigned vlen, unsigned int flags); 570 unsigned vlen, unsigned int flags);
550asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg, 571asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg,
551 unsigned int flags); 572 unsigned int flags);
552asmlinkage long compat_sys_recv(int fd, void __user *buf, size_t len, 573asmlinkage long compat_sys_recv(int fd, void __user *buf, compat_size_t len,
553 unsigned flags); 574 unsigned flags);
554asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, size_t len, 575asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, compat_size_t len,
555 unsigned flags, struct sockaddr __user *addr, 576 unsigned flags, struct sockaddr __user *addr,
556 int __user *addrlen); 577 int __user *addrlen);
557asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg, 578asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
@@ -615,16 +636,16 @@ asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig,
615 struct compat_siginfo __user *uinfo); 636 struct compat_siginfo __user *uinfo);
616asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info); 637asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
617asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, 638asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
618 unsigned long arg); 639 compat_ulong_t arg);
619asmlinkage long compat_sys_futex(u32 __user *uaddr, int op, u32 val, 640asmlinkage long compat_sys_futex(u32 __user *uaddr, int op, u32 val,
620 struct compat_timespec __user *utime, u32 __user *uaddr2, 641 struct compat_timespec __user *utime, u32 __user *uaddr2,
621 u32 val3); 642 u32 val3);
622asmlinkage long compat_sys_getsockopt(int fd, int level, int optname, 643asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
623 char __user *optval, int __user *optlen); 644 char __user *optval, int __user *optlen);
624asmlinkage long compat_sys_kexec_load(unsigned long entry, 645asmlinkage long compat_sys_kexec_load(compat_ulong_t entry,
625 unsigned long nr_segments, 646 compat_ulong_t nr_segments,
626 struct compat_kexec_segment __user *, 647 struct compat_kexec_segment __user *,
627 unsigned long flags); 648 compat_ulong_t flags);
628asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes, 649asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
629 const struct compat_mq_attr __user *u_mqstat, 650 const struct compat_mq_attr __user *u_mqstat,
630 struct compat_mq_attr __user *u_omqstat); 651 struct compat_mq_attr __user *u_omqstat);
@@ -635,11 +656,11 @@ asmlinkage long compat_sys_mq_open(const char __user *u_name,
635 struct compat_mq_attr __user *u_attr); 656 struct compat_mq_attr __user *u_attr);
636asmlinkage long compat_sys_mq_timedsend(mqd_t mqdes, 657asmlinkage long compat_sys_mq_timedsend(mqd_t mqdes,
637 const char __user *u_msg_ptr, 658 const char __user *u_msg_ptr,
638 size_t msg_len, unsigned int msg_prio, 659 compat_size_t msg_len, unsigned int msg_prio,
639 const struct compat_timespec __user *u_abs_timeout); 660 const struct compat_timespec __user *u_abs_timeout);
640asmlinkage ssize_t compat_sys_mq_timedreceive(mqd_t mqdes, 661asmlinkage ssize_t compat_sys_mq_timedreceive(mqd_t mqdes,
641 char __user *u_msg_ptr, 662 char __user *u_msg_ptr,
642 size_t msg_len, unsigned int __user *u_msg_prio, 663 compat_size_t msg_len, unsigned int __user *u_msg_prio,
643 const struct compat_timespec __user *u_abs_timeout); 664 const struct compat_timespec __user *u_abs_timeout);
644asmlinkage long compat_sys_socketcall(int call, u32 __user *args); 665asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
645asmlinkage long compat_sys_sysctl(struct compat_sysctl_args __user *args); 666asmlinkage long compat_sys_sysctl(struct compat_sysctl_args __user *args);
@@ -654,12 +675,12 @@ extern void __user *compat_alloc_user_space(unsigned long len);
654 675
655asmlinkage ssize_t compat_sys_process_vm_readv(compat_pid_t pid, 676asmlinkage ssize_t compat_sys_process_vm_readv(compat_pid_t pid,
656 const struct compat_iovec __user *lvec, 677 const struct compat_iovec __user *lvec,
657 unsigned long liovcnt, const struct compat_iovec __user *rvec, 678 compat_ulong_t liovcnt, const struct compat_iovec __user *rvec,
658 unsigned long riovcnt, unsigned long flags); 679 compat_ulong_t riovcnt, compat_ulong_t flags);
659asmlinkage ssize_t compat_sys_process_vm_writev(compat_pid_t pid, 680asmlinkage ssize_t compat_sys_process_vm_writev(compat_pid_t pid,
660 const struct compat_iovec __user *lvec, 681 const struct compat_iovec __user *lvec,
661 unsigned long liovcnt, const struct compat_iovec __user *rvec, 682 compat_ulong_t liovcnt, const struct compat_iovec __user *rvec,
662 unsigned long riovcnt, unsigned long flags); 683 compat_ulong_t riovcnt, compat_ulong_t flags);
663 684
664asmlinkage long compat_sys_sendfile(int out_fd, int in_fd, 685asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
665 compat_off_t __user *offset, compat_size_t count); 686 compat_off_t __user *offset, compat_size_t count);
diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
index ded429966c1f..2507fd2a1eb4 100644
--- a/include/linux/compiler-gcc4.h
+++ b/include/linux/compiler-gcc4.h
@@ -75,11 +75,7 @@
75 * 75 *
76 * (asm goto is automatically volatile - the naming reflects this.) 76 * (asm goto is automatically volatile - the naming reflects this.)
77 */ 77 */
78#if GCC_VERSION <= 40801 78#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
79# define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
80#else
81# define asm_volatile_goto(x...) do { asm goto(x); } while (0)
82#endif
83 79
84#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP 80#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
85#if GCC_VERSION >= 40400 81#if GCC_VERSION >= 40400
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index dfac5ed31120..f886985a28b2 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -171,7 +171,7 @@ struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops,
171 size_t size, int flags, const char *); 171 size_t size, int flags, const char *);
172 172
173#define dma_buf_export(priv, ops, size, flags) \ 173#define dma_buf_export(priv, ops, size, flags) \
174 dma_buf_export_named(priv, ops, size, flags, __FILE__) 174 dma_buf_export_named(priv, ops, size, flags, KBUILD_MODNAME)
175 175
176int dma_buf_fd(struct dma_buf *dmabuf, int flags); 176int dma_buf_fd(struct dma_buf *dmabuf, int flags);
177struct dma_buf *dma_buf_get(int fd); 177struct dma_buf *dma_buf_get(int fd);
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 0a819e7a60c9..6c100ff0cae4 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -153,6 +153,102 @@ typedef struct {
153 u8 sets_to_zero; 153 u8 sets_to_zero;
154} efi_time_cap_t; 154} efi_time_cap_t;
155 155
156typedef struct {
157 efi_table_hdr_t hdr;
158 u32 raise_tpl;
159 u32 restore_tpl;
160 u32 allocate_pages;
161 u32 free_pages;
162 u32 get_memory_map;
163 u32 allocate_pool;
164 u32 free_pool;
165 u32 create_event;
166 u32 set_timer;
167 u32 wait_for_event;
168 u32 signal_event;
169 u32 close_event;
170 u32 check_event;
171 u32 install_protocol_interface;
172 u32 reinstall_protocol_interface;
173 u32 uninstall_protocol_interface;
174 u32 handle_protocol;
175 u32 __reserved;
176 u32 register_protocol_notify;
177 u32 locate_handle;
178 u32 locate_device_path;
179 u32 install_configuration_table;
180 u32 load_image;
181 u32 start_image;
182 u32 exit;
183 u32 unload_image;
184 u32 exit_boot_services;
185 u32 get_next_monotonic_count;
186 u32 stall;
187 u32 set_watchdog_timer;
188 u32 connect_controller;
189 u32 disconnect_controller;
190 u32 open_protocol;
191 u32 close_protocol;
192 u32 open_protocol_information;
193 u32 protocols_per_handle;
194 u32 locate_handle_buffer;
195 u32 locate_protocol;
196 u32 install_multiple_protocol_interfaces;
197 u32 uninstall_multiple_protocol_interfaces;
198 u32 calculate_crc32;
199 u32 copy_mem;
200 u32 set_mem;
201 u32 create_event_ex;
202} __packed efi_boot_services_32_t;
203
204typedef struct {
205 efi_table_hdr_t hdr;
206 u64 raise_tpl;
207 u64 restore_tpl;
208 u64 allocate_pages;
209 u64 free_pages;
210 u64 get_memory_map;
211 u64 allocate_pool;
212 u64 free_pool;
213 u64 create_event;
214 u64 set_timer;
215 u64 wait_for_event;
216 u64 signal_event;
217 u64 close_event;
218 u64 check_event;
219 u64 install_protocol_interface;
220 u64 reinstall_protocol_interface;
221 u64 uninstall_protocol_interface;
222 u64 handle_protocol;
223 u64 __reserved;
224 u64 register_protocol_notify;
225 u64 locate_handle;
226 u64 locate_device_path;
227 u64 install_configuration_table;
228 u64 load_image;
229 u64 start_image;
230 u64 exit;
231 u64 unload_image;
232 u64 exit_boot_services;
233 u64 get_next_monotonic_count;
234 u64 stall;
235 u64 set_watchdog_timer;
236 u64 connect_controller;
237 u64 disconnect_controller;
238 u64 open_protocol;
239 u64 close_protocol;
240 u64 open_protocol_information;
241 u64 protocols_per_handle;
242 u64 locate_handle_buffer;
243 u64 locate_protocol;
244 u64 install_multiple_protocol_interfaces;
245 u64 uninstall_multiple_protocol_interfaces;
246 u64 calculate_crc32;
247 u64 copy_mem;
248 u64 set_mem;
249 u64 create_event_ex;
250} __packed efi_boot_services_64_t;
251
156/* 252/*
157 * EFI Boot Services table 253 * EFI Boot Services table
158 */ 254 */
@@ -231,6 +327,15 @@ typedef enum {
231 EfiPciIoAttributeOperationMaximum 327 EfiPciIoAttributeOperationMaximum
232} EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION; 328} EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
233 329
330typedef struct {
331 u32 read;
332 u32 write;
333} efi_pci_io_protocol_access_32_t;
334
335typedef struct {
336 u64 read;
337 u64 write;
338} efi_pci_io_protocol_access_64_t;
234 339
235typedef struct { 340typedef struct {
236 void *read; 341 void *read;
@@ -238,6 +343,46 @@ typedef struct {
238} efi_pci_io_protocol_access_t; 343} efi_pci_io_protocol_access_t;
239 344
240typedef struct { 345typedef struct {
346 u32 poll_mem;
347 u32 poll_io;
348 efi_pci_io_protocol_access_32_t mem;
349 efi_pci_io_protocol_access_32_t io;
350 efi_pci_io_protocol_access_32_t pci;
351 u32 copy_mem;
352 u32 map;
353 u32 unmap;
354 u32 allocate_buffer;
355 u32 free_buffer;
356 u32 flush;
357 u32 get_location;
358 u32 attributes;
359 u32 get_bar_attributes;
360 u32 set_bar_attributes;
361 uint64_t romsize;
362 void *romimage;
363} efi_pci_io_protocol_32;
364
365typedef struct {
366 u64 poll_mem;
367 u64 poll_io;
368 efi_pci_io_protocol_access_64_t mem;
369 efi_pci_io_protocol_access_64_t io;
370 efi_pci_io_protocol_access_64_t pci;
371 u64 copy_mem;
372 u64 map;
373 u64 unmap;
374 u64 allocate_buffer;
375 u64 free_buffer;
376 u64 flush;
377 u64 get_location;
378 u64 attributes;
379 u64 get_bar_attributes;
380 u64 set_bar_attributes;
381 uint64_t romsize;
382 void *romimage;
383} efi_pci_io_protocol_64;
384
385typedef struct {
241 void *poll_mem; 386 void *poll_mem;
242 void *poll_io; 387 void *poll_io;
243 efi_pci_io_protocol_access_t mem; 388 efi_pci_io_protocol_access_t mem;
@@ -292,6 +437,42 @@ typedef struct {
292 437
293typedef struct { 438typedef struct {
294 efi_table_hdr_t hdr; 439 efi_table_hdr_t hdr;
440 u32 get_time;
441 u32 set_time;
442 u32 get_wakeup_time;
443 u32 set_wakeup_time;
444 u32 set_virtual_address_map;
445 u32 convert_pointer;
446 u32 get_variable;
447 u32 get_next_variable;
448 u32 set_variable;
449 u32 get_next_high_mono_count;
450 u32 reset_system;
451 u32 update_capsule;
452 u32 query_capsule_caps;
453 u32 query_variable_info;
454} efi_runtime_services_32_t;
455
456typedef struct {
457 efi_table_hdr_t hdr;
458 u64 get_time;
459 u64 set_time;
460 u64 get_wakeup_time;
461 u64 set_wakeup_time;
462 u64 set_virtual_address_map;
463 u64 convert_pointer;
464 u64 get_variable;
465 u64 get_next_variable;
466 u64 set_variable;
467 u64 get_next_high_mono_count;
468 u64 reset_system;
469 u64 update_capsule;
470 u64 query_capsule_caps;
471 u64 query_variable_info;
472} efi_runtime_services_64_t;
473
474typedef struct {
475 efi_table_hdr_t hdr;
295 void *get_time; 476 void *get_time;
296 void *set_time; 477 void *set_time;
297 void *get_wakeup_time; 478 void *get_wakeup_time;
@@ -485,6 +666,38 @@ struct efi_memory_map {
485 666
486typedef struct { 667typedef struct {
487 u32 revision; 668 u32 revision;
669 u32 parent_handle;
670 u32 system_table;
671 u32 device_handle;
672 u32 file_path;
673 u32 reserved;
674 u32 load_options_size;
675 u32 load_options;
676 u32 image_base;
677 __aligned_u64 image_size;
678 unsigned int image_code_type;
679 unsigned int image_data_type;
680 unsigned long unload;
681} efi_loaded_image_32_t;
682
683typedef struct {
684 u32 revision;
685 u64 parent_handle;
686 u64 system_table;
687 u64 device_handle;
688 u64 file_path;
689 u64 reserved;
690 u32 load_options_size;
691 u64 load_options;
692 u64 image_base;
693 __aligned_u64 image_size;
694 unsigned int image_code_type;
695 unsigned int image_data_type;
696 unsigned long unload;
697} efi_loaded_image_64_t;
698
699typedef struct {
700 u32 revision;
488 void *parent_handle; 701 void *parent_handle;
489 efi_system_table_t *system_table; 702 efi_system_table_t *system_table;
490 void *device_handle; 703 void *device_handle;
@@ -511,6 +724,34 @@ typedef struct {
511 efi_char16_t filename[1]; 724 efi_char16_t filename[1];
512} efi_file_info_t; 725} efi_file_info_t;
513 726
727typedef struct {
728 u64 revision;
729 u32 open;
730 u32 close;
731 u32 delete;
732 u32 read;
733 u32 write;
734 u32 get_position;
735 u32 set_position;
736 u32 get_info;
737 u32 set_info;
738 u32 flush;
739} efi_file_handle_32_t;
740
741typedef struct {
742 u64 revision;
743 u64 open;
744 u64 close;
745 u64 delete;
746 u64 read;
747 u64 write;
748 u64 get_position;
749 u64 set_position;
750 u64 get_info;
751 u64 set_info;
752 u64 flush;
753} efi_file_handle_64_t;
754
514typedef struct _efi_file_handle { 755typedef struct _efi_file_handle {
515 u64 revision; 756 u64 revision;
516 efi_status_t (*open)(struct _efi_file_handle *, 757 efi_status_t (*open)(struct _efi_file_handle *,
@@ -573,6 +814,7 @@ extern struct efi {
573 efi_reset_system_t *reset_system; 814 efi_reset_system_t *reset_system;
574 efi_set_virtual_address_map_t *set_virtual_address_map; 815 efi_set_virtual_address_map_t *set_virtual_address_map;
575 struct efi_memory_map *memmap; 816 struct efi_memory_map *memmap;
817 unsigned long flags;
576} efi; 818} efi;
577 819
578static inline int 820static inline int
@@ -659,18 +901,17 @@ extern int __init efi_setup_pcdp_console(char *);
659#define EFI_ARCH_1 6 /* First arch-specific bit */ 901#define EFI_ARCH_1 6 /* First arch-specific bit */
660 902
661#ifdef CONFIG_EFI 903#ifdef CONFIG_EFI
662# ifdef CONFIG_X86 904/*
663extern int efi_enabled(int facility); 905 * Test whether the above EFI_* bits are enabled.
664# else 906 */
665static inline int efi_enabled(int facility) 907static inline bool efi_enabled(int feature)
666{ 908{
667 return 1; 909 return test_bit(feature, &efi.flags) != 0;
668} 910}
669# endif
670#else 911#else
671static inline int efi_enabled(int facility) 912static inline bool efi_enabled(int feature)
672{ 913{
673 return 0; 914 return false;
674} 915}
675#endif 916#endif
676 917
@@ -809,6 +1050,17 @@ struct efivar_entry {
809 bool deleting; 1050 bool deleting;
810}; 1051};
811 1052
1053struct efi_simple_text_output_protocol_32 {
1054 u32 reset;
1055 u32 output_string;
1056 u32 test_string;
1057};
1058
1059struct efi_simple_text_output_protocol_64 {
1060 u64 reset;
1061 u64 output_string;
1062 u64 test_string;
1063};
812 1064
813struct efi_simple_text_output_protocol { 1065struct efi_simple_text_output_protocol {
814 void *reset; 1066 void *reset;
diff --git a/include/linux/file.h b/include/linux/file.h
index cbacf4faf447..4d69123377a2 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -28,33 +28,36 @@ static inline void fput_light(struct file *file, int fput_needed)
28 28
29struct fd { 29struct fd {
30 struct file *file; 30 struct file *file;
31 int need_put; 31 unsigned int flags;
32}; 32};
33#define FDPUT_FPUT 1
34#define FDPUT_POS_UNLOCK 2
33 35
34static inline void fdput(struct fd fd) 36static inline void fdput(struct fd fd)
35{ 37{
36 if (fd.need_put) 38 if (fd.flags & FDPUT_FPUT)
37 fput(fd.file); 39 fput(fd.file);
38} 40}
39 41
40extern struct file *fget(unsigned int fd); 42extern struct file *fget(unsigned int fd);
41extern struct file *fget_light(unsigned int fd, int *fput_needed); 43extern struct file *fget_raw(unsigned int fd);
44extern unsigned long __fdget(unsigned int fd);
45extern unsigned long __fdget_raw(unsigned int fd);
46extern unsigned long __fdget_pos(unsigned int fd);
42 47
43static inline struct fd fdget(unsigned int fd) 48static inline struct fd __to_fd(unsigned long v)
44{ 49{
45 int b; 50 return (struct fd){(struct file *)(v & ~3),v & 3};
46 struct file *f = fget_light(fd, &b);
47 return (struct fd){f,b};
48} 51}
49 52
50extern struct file *fget_raw(unsigned int fd); 53static inline struct fd fdget(unsigned int fd)
51extern struct file *fget_raw_light(unsigned int fd, int *fput_needed); 54{
55 return __to_fd(__fdget(fd));
56}
52 57
53static inline struct fd fdget_raw(unsigned int fd) 58static inline struct fd fdget_raw(unsigned int fd)
54{ 59{
55 int b; 60 return __to_fd(__fdget_raw(fd));
56 struct file *f = fget_raw_light(fd, &b);
57 return (struct fd){f,b};
58} 61}
59 62
60extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); 63extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
diff --git a/include/linux/firewire.h b/include/linux/firewire.h
index 5d7782e42b8f..c3683bdf28fe 100644
--- a/include/linux/firewire.h
+++ b/include/linux/firewire.h
@@ -200,6 +200,7 @@ struct fw_device {
200 unsigned irmc:1; 200 unsigned irmc:1;
201 unsigned bc_implemented:2; 201 unsigned bc_implemented:2;
202 202
203 work_func_t workfn;
203 struct delayed_work work; 204 struct delayed_work work;
204 struct fw_attribute_group attribute_group; 205 struct fw_attribute_group attribute_group;
205}; 206};
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 09f553c59813..23b2a35d712e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -123,6 +123,9 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
123/* File is opened with O_PATH; almost nothing can be done with it */ 123/* File is opened with O_PATH; almost nothing can be done with it */
124#define FMODE_PATH ((__force fmode_t)0x4000) 124#define FMODE_PATH ((__force fmode_t)0x4000)
125 125
126/* File needs atomic accesses to f_pos */
127#define FMODE_ATOMIC_POS ((__force fmode_t)0x8000)
128
126/* File was opened by fanotify and shouldn't generate fanotify events */ 129/* File was opened by fanotify and shouldn't generate fanotify events */
127#define FMODE_NONOTIFY ((__force fmode_t)0x1000000) 130#define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
128 131
@@ -780,13 +783,14 @@ struct file {
780 const struct file_operations *f_op; 783 const struct file_operations *f_op;
781 784
782 /* 785 /*
783 * Protects f_ep_links, f_flags, f_pos vs i_size in lseek SEEK_CUR. 786 * Protects f_ep_links, f_flags.
784 * Must not be taken from IRQ context. 787 * Must not be taken from IRQ context.
785 */ 788 */
786 spinlock_t f_lock; 789 spinlock_t f_lock;
787 atomic_long_t f_count; 790 atomic_long_t f_count;
788 unsigned int f_flags; 791 unsigned int f_flags;
789 fmode_t f_mode; 792 fmode_t f_mode;
793 struct mutex f_pos_lock;
790 loff_t f_pos; 794 loff_t f_pos;
791 struct fown_struct f_owner; 795 struct fown_struct f_owner;
792 const struct cred *f_cred; 796 const struct cred *f_cred;
@@ -808,7 +812,7 @@ struct file {
808#ifdef CONFIG_DEBUG_WRITECOUNT 812#ifdef CONFIG_DEBUG_WRITECOUNT
809 unsigned long f_mnt_write_state; 813 unsigned long f_mnt_write_state;
810#endif 814#endif
811}; 815} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
812 816
813struct file_handle { 817struct file_handle {
814 __u32 handle_bytes; 818 __u32 handle_bytes;
@@ -2079,6 +2083,7 @@ extern struct file * dentry_open(const struct path *, int, const struct cred *);
2079extern int filp_close(struct file *, fl_owner_t id); 2083extern int filp_close(struct file *, fl_owner_t id);
2080 2084
2081extern struct filename *getname(const char __user *); 2085extern struct filename *getname(const char __user *);
2086extern struct filename *getname_kernel(const char *);
2082 2087
2083enum { 2088enum {
2084 FILE_CREATED = 1, 2089 FILE_CREATED = 1,
@@ -2273,7 +2278,13 @@ extern int filemap_fdatawrite_range(struct address_space *mapping,
2273extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end, 2278extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end,
2274 int datasync); 2279 int datasync);
2275extern int vfs_fsync(struct file *file, int datasync); 2280extern int vfs_fsync(struct file *file, int datasync);
2276extern int generic_write_sync(struct file *file, loff_t pos, loff_t count); 2281static inline int generic_write_sync(struct file *file, loff_t pos, loff_t count)
2282{
2283 if (!(file->f_flags & O_DSYNC) && !IS_SYNC(file->f_mapping->host))
2284 return 0;
2285 return vfs_fsync_range(file, pos, pos + count - 1,
2286 (file->f_flags & __O_SYNC) ? 0 : 1);
2287}
2277extern void emergency_sync(void); 2288extern void emergency_sync(void);
2278extern void emergency_remount(void); 2289extern void emergency_remount(void);
2279#ifdef CONFIG_BLOCK 2290#ifdef CONFIG_BLOCK
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 3d286ff49ab0..64cf3ef50696 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -99,7 +99,7 @@ struct fsnotify_ops {
99 struct fsnotify_mark *inode_mark, 99 struct fsnotify_mark *inode_mark,
100 struct fsnotify_mark *vfsmount_mark, 100 struct fsnotify_mark *vfsmount_mark,
101 u32 mask, void *data, int data_type, 101 u32 mask, void *data, int data_type,
102 const unsigned char *file_name); 102 const unsigned char *file_name, u32 cookie);
103 void (*free_group_priv)(struct fsnotify_group *group); 103 void (*free_group_priv)(struct fsnotify_group *group);
104 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group); 104 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
105 void (*free_event)(struct fsnotify_event *event); 105 void (*free_event)(struct fsnotify_event *event);
@@ -160,7 +160,7 @@ struct fsnotify_group {
160 160
161 struct fasync_struct *fsn_fa; /* async notification */ 161 struct fasync_struct *fsn_fa; /* async notification */
162 162
163 struct fsnotify_event overflow_event; /* Event we queue when the 163 struct fsnotify_event *overflow_event; /* Event we queue when the
164 * notification list is too 164 * notification list is too
165 * full */ 165 * full */
166 166
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 4e4cc28623ad..4cdb3a17bcb5 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -495,10 +495,6 @@ enum {
495 FILTER_TRACE_FN, 495 FILTER_TRACE_FN,
496}; 496};
497 497
498#define EVENT_STORAGE_SIZE 128
499extern struct mutex event_storage_mutex;
500extern char event_storage[EVENT_STORAGE_SIZE];
501
502extern int trace_event_raw_init(struct ftrace_event_call *call); 498extern int trace_event_raw_init(struct ftrace_event_call *call);
503extern int trace_define_field(struct ftrace_event_call *call, const char *type, 499extern int trace_define_field(struct ftrace_event_call *call, const char *type,
504 const char *name, int offset, int size, 500 const char *name, int offset, int size,
diff --git a/include/linux/futex.h b/include/linux/futex.h
index b0d95cac826e..6435f46d6e13 100644
--- a/include/linux/futex.h
+++ b/include/linux/futex.h
@@ -55,7 +55,11 @@ union futex_key {
55#ifdef CONFIG_FUTEX 55#ifdef CONFIG_FUTEX
56extern void exit_robust_list(struct task_struct *curr); 56extern void exit_robust_list(struct task_struct *curr);
57extern void exit_pi_state_list(struct task_struct *curr); 57extern void exit_pi_state_list(struct task_struct *curr);
58#ifdef CONFIG_HAVE_FUTEX_CMPXCHG
59#define futex_cmpxchg_enabled 1
60#else
58extern int futex_cmpxchg_enabled; 61extern int futex_cmpxchg_enabled;
62#endif
59#else 63#else
60static inline void exit_robust_list(struct task_struct *curr) 64static inline void exit_robust_list(struct task_struct *curr)
61{ 65{
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 0437439bc047..39b81dc7d01a 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -123,6 +123,10 @@ struct vm_area_struct;
123 __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | \ 123 __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | \
124 __GFP_NO_KSWAPD) 124 __GFP_NO_KSWAPD)
125 125
126/*
127 * GFP_THISNODE does not perform any reclaim, you most likely want to
128 * use __GFP_THISNODE to allocate from a given node without fallback!
129 */
126#ifdef CONFIG_NUMA 130#ifdef CONFIG_NUMA
127#define GFP_THISNODE (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY) 131#define GFP_THISNODE (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY)
128#else 132#else
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 4d34dbbbad4d..7a8144fef406 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -4,8 +4,6 @@
4#include <linux/err.h> 4#include <linux/err.h>
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6 6
7#ifdef CONFIG_GPIOLIB
8
9struct device; 7struct device;
10struct gpio_chip; 8struct gpio_chip;
11 9
@@ -18,6 +16,8 @@ struct gpio_chip;
18 */ 16 */
19struct gpio_desc; 17struct gpio_desc;
20 18
19#ifdef CONFIG_GPIOLIB
20
21/* Acquire and dispose GPIOs */ 21/* Acquire and dispose GPIOs */
22struct gpio_desc *__must_check gpiod_get(struct device *dev, 22struct gpio_desc *__must_check gpiod_get(struct device *dev,
23 const char *con_id); 23 const char *con_id);
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index db512014e061..b826239bdce0 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -157,46 +157,6 @@ static inline int hpage_nr_pages(struct page *page)
157 return HPAGE_PMD_NR; 157 return HPAGE_PMD_NR;
158 return 1; 158 return 1;
159} 159}
160/*
161 * compound_trans_head() should be used instead of compound_head(),
162 * whenever the "page" passed as parameter could be the tail of a
163 * transparent hugepage that could be undergoing a
164 * __split_huge_page_refcount(). The page structure layout often
165 * changes across releases and it makes extensive use of unions. So if
166 * the page structure layout will change in a way that
167 * page->first_page gets clobbered by __split_huge_page_refcount, the
168 * implementation making use of smp_rmb() will be required.
169 *
170 * Currently we define compound_trans_head as compound_head, because
171 * page->private is in the same union with page->first_page, and
172 * page->private isn't clobbered. However this also means we're
173 * currently leaving dirt into the page->private field of anonymous
174 * pages resulting from a THP split, instead of setting page->private
175 * to zero like for every other page that has PG_private not set. But
176 * anonymous pages don't use page->private so this is not a problem.
177 */
178#if 0
179/* This will be needed if page->private will be clobbered in split_huge_page */
180static inline struct page *compound_trans_head(struct page *page)
181{
182 if (PageTail(page)) {
183 struct page *head;
184 head = page->first_page;
185 smp_rmb();
186 /*
187 * head may be a dangling pointer.
188 * __split_huge_page_refcount clears PageTail before
189 * overwriting first_page, so if PageTail is still
190 * there it means the head pointer isn't dangling.
191 */
192 if (PageTail(page))
193 return head;
194 }
195 return page;
196}
197#else
198#define compound_trans_head(page) compound_head(page)
199#endif
200 160
201extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, 161extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
202 unsigned long addr, pmd_t pmd, pmd_t *pmdp); 162 unsigned long addr, pmd_t pmd, pmd_t *pmdp);
@@ -226,7 +186,6 @@ static inline int split_huge_page(struct page *page)
226 do { } while (0) 186 do { } while (0)
227#define split_huge_page_pmd_mm(__mm, __address, __pmd) \ 187#define split_huge_page_pmd_mm(__mm, __address, __pmd) \
228 do { } while (0) 188 do { } while (0)
229#define compound_trans_head(page) compound_head(page)
230static inline int hugepage_madvise(struct vm_area_struct *vma, 189static inline int hugepage_madvise(struct vm_area_struct *vma,
231 unsigned long *vm_flags, int advice) 190 unsigned long *vm_flags, int advice)
232{ 191{
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 15da677478dd..344883dce584 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -875,7 +875,7 @@ struct vmbus_channel_relid_released {
875struct vmbus_channel_initiate_contact { 875struct vmbus_channel_initiate_contact {
876 struct vmbus_channel_message_header header; 876 struct vmbus_channel_message_header header;
877 u32 vmbus_version_requested; 877 u32 vmbus_version_requested;
878 u32 padding2; 878 u32 target_vcpu; /* The VCPU the host should respond to */
879 u64 interrupt_page; 879 u64 interrupt_page;
880 u64 monitor_page1; 880 u64 monitor_page1;
881 u64 monitor_page2; 881 u64 monitor_page2;
diff --git a/include/linux/init.h b/include/linux/init.h
index e1688802964f..a3ba27076342 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -163,6 +163,23 @@ extern bool initcall_debug;
163 163
164#ifndef __ASSEMBLY__ 164#ifndef __ASSEMBLY__
165 165
166#ifdef CONFIG_LTO
167/* Work around a LTO gcc problem: when there is no reference to a variable
168 * in a module it will be moved to the end of the program. This causes
169 * reordering of initcalls which the kernel does not like.
170 * Add a dummy reference function to avoid this. The function is
171 * deleted by the linker.
172 */
173#define LTO_REFERENCE_INITCALL(x) \
174 ; /* yes this is needed */ \
175 static __used __exit void *reference_##x(void) \
176 { \
177 return &x; \
178 }
179#else
180#define LTO_REFERENCE_INITCALL(x)
181#endif
182
166/* initcalls are now grouped by functionality into separate 183/* initcalls are now grouped by functionality into separate
167 * subsections. Ordering inside the subsections is determined 184 * subsections. Ordering inside the subsections is determined
168 * by link order. 185 * by link order.
@@ -175,7 +192,8 @@ extern bool initcall_debug;
175 192
176#define __define_initcall(fn, id) \ 193#define __define_initcall(fn, id) \
177 static initcall_t __initcall_##fn##id __used \ 194 static initcall_t __initcall_##fn##id __used \
178 __attribute__((__section__(".initcall" #id ".init"))) = fn 195 __attribute__((__section__(".initcall" #id ".init"))) = fn; \
196 LTO_REFERENCE_INITCALL(__initcall_##fn##id)
179 197
180/* 198/*
181 * Early initcalls run before initializing SMP. 199 * Early initcalls run before initializing SMP.
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 0053adde0ed9..a2678d35b5a2 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -158,6 +158,11 @@ devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
158 devname, dev_id); 158 devname, dev_id);
159} 159}
160 160
161extern int __must_check
162devm_request_any_context_irq(struct device *dev, unsigned int irq,
163 irq_handler_t handler, unsigned long irqflags,
164 const char *devname, void *dev_id);
165
161extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id); 166extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
162 167
163/* 168/*
diff --git a/include/linux/io.h b/include/linux/io.h
index f4f42faec686..8a18e75600cc 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -24,7 +24,7 @@
24 24
25struct device; 25struct device;
26 26
27void __iowrite32_copy(void __iomem *to, const void *from, size_t count); 27__visible void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
28void __iowrite64_copy(void __iomem *to, const void *from, size_t count); 28void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
29 29
30#ifdef CONFIG_MMU 30#ifdef CONFIG_MMU
diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index e7831d203737..35e7eca4e33b 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -118,9 +118,7 @@ extern int mq_init_ns(struct ipc_namespace *ns);
118 * the new maximum will handle anyone else. I may have to revisit this 118 * the new maximum will handle anyone else. I may have to revisit this
119 * in the future. 119 * in the future.
120 */ 120 */
121#define MIN_QUEUESMAX 1
122#define DFLT_QUEUESMAX 256 121#define DFLT_QUEUESMAX 256
123#define HARD_QUEUESMAX 1024
124#define MIN_MSGMAX 1 122#define MIN_MSGMAX 1
125#define DFLT_MSG 10U 123#define DFLT_MSG 10U
126#define DFLT_MSGMAX 10 124#define DFLT_MSGMAX 10
diff --git a/include/linux/irq_work.h b/include/linux/irq_work.h
index 66017028dcb3..19ae05d4b8ec 100644
--- a/include/linux/irq_work.h
+++ b/include/linux/irq_work.h
@@ -30,7 +30,9 @@ void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
30 work->func = func; 30 work->func = func;
31} 31}
32 32
33void irq_work_queue(struct irq_work *work); 33#define DEFINE_IRQ_WORK(name, _f) struct irq_work name = { .func = (_f), }
34
35bool irq_work_queue(struct irq_work *work);
34void irq_work_run(void); 36void irq_work_run(void);
35void irq_work_sync(struct irq_work *work); 37void irq_work_sync(struct irq_work *work);
36 38
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 196d1ea86df0..08fb02477641 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -458,7 +458,7 @@ extern enum system_states {
458 458
459#define TAINT_PROPRIETARY_MODULE 0 459#define TAINT_PROPRIETARY_MODULE 0
460#define TAINT_FORCED_MODULE 1 460#define TAINT_FORCED_MODULE 1
461#define TAINT_UNSAFE_SMP 2 461#define TAINT_CPU_OUT_OF_SPEC 2
462#define TAINT_FORCED_RMMOD 3 462#define TAINT_FORCED_RMMOD 3
463#define TAINT_MACHINE_CHECK 4 463#define TAINT_MACHINE_CHECK 4
464#define TAINT_BAD_PAGE 5 464#define TAINT_BAD_PAGE 5
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index 5be9f0228a3b..d267623c28cf 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -249,7 +249,8 @@ void kernfs_notify(struct kernfs_node *kn);
249 249
250const void *kernfs_super_ns(struct super_block *sb); 250const void *kernfs_super_ns(struct super_block *sb);
251struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags, 251struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
252 struct kernfs_root *root, const void *ns); 252 struct kernfs_root *root, bool *new_sb_created,
253 const void *ns);
253void kernfs_kill_sb(struct super_block *sb); 254void kernfs_kill_sb(struct super_block *sb);
254 255
255void kernfs_init(void); 256void kernfs_init(void);
@@ -317,7 +318,7 @@ static inline const void *kernfs_super_ns(struct super_block *sb)
317 318
318static inline struct dentry * 319static inline struct dentry *
319kernfs_mount_ns(struct file_system_type *fs_type, int flags, 320kernfs_mount_ns(struct file_system_type *fs_type, int flags,
320 struct kernfs_root *root, const void *ns) 321 struct kernfs_root *root, bool *new_sb_created, const void *ns)
321{ return ERR_PTR(-ENOSYS); } 322{ return ERR_PTR(-ENOSYS); }
322 323
323static inline void kernfs_kill_sb(struct super_block *sb) { } 324static inline void kernfs_kill_sb(struct super_block *sb) { }
@@ -368,9 +369,9 @@ static inline int kernfs_remove_by_name(struct kernfs_node *parent,
368 369
369static inline struct dentry * 370static inline struct dentry *
370kernfs_mount(struct file_system_type *fs_type, int flags, 371kernfs_mount(struct file_system_type *fs_type, int flags,
371 struct kernfs_root *root) 372 struct kernfs_root *root, bool *new_sb_created)
372{ 373{
373 return kernfs_mount_ns(fs_type, flags, root, NULL); 374 return kernfs_mount_ns(fs_type, flags, root, new_sb_created, NULL);
374} 375}
375 376
376#endif /* __LINUX_KERNFS_H */ 377#endif /* __LINUX_KERNFS_H */
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 6d4066cdb5b5..a75641930049 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -127,12 +127,6 @@ extern asmlinkage long sys_kexec_load(unsigned long entry,
127 struct kexec_segment __user *segments, 127 struct kexec_segment __user *segments,
128 unsigned long flags); 128 unsigned long flags);
129extern int kernel_kexec(void); 129extern int kernel_kexec(void);
130#ifdef CONFIG_COMPAT
131extern asmlinkage long compat_sys_kexec_load(unsigned long entry,
132 unsigned long nr_segments,
133 struct compat_kexec_segment __user *segments,
134 unsigned long flags);
135#endif
136extern struct page *kimage_alloc_control_pages(struct kimage *image, 130extern struct page *kimage_alloc_control_pages(struct kimage *image,
137 unsigned int order); 131 unsigned int order);
138extern void crash_kexec(struct pt_regs *); 132extern void crash_kexec(struct pt_regs *);
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index a6a42dd02466..34a513a2727b 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -12,9 +12,9 @@
12#endif 12#endif
13 13
14#ifdef __cplusplus 14#ifdef __cplusplus
15#define CPP_ASMLINKAGE extern "C" 15#define CPP_ASMLINKAGE extern "C" __visible
16#else 16#else
17#define CPP_ASMLINKAGE 17#define CPP_ASMLINKAGE __visible
18#endif 18#endif
19 19
20#ifndef asmlinkage 20#ifndef asmlinkage
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 92b1bfc5da60..008388f920d7 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -252,9 +252,9 @@ struct held_lock {
252 unsigned int trylock:1; /* 16 bits */ 252 unsigned int trylock:1; /* 16 bits */
253 253
254 unsigned int read:2; /* see lock_acquire() comment */ 254 unsigned int read:2; /* see lock_acquire() comment */
255 unsigned int check:2; /* see lock_acquire() comment */ 255 unsigned int check:1; /* see lock_acquire() comment */
256 unsigned int hardirqs_off:1; 256 unsigned int hardirqs_off:1;
257 unsigned int references:11; /* 32 bits */ 257 unsigned int references:12; /* 32 bits */
258}; 258};
259 259
260/* 260/*
@@ -265,7 +265,7 @@ extern void lockdep_info(void);
265extern void lockdep_reset(void); 265extern void lockdep_reset(void);
266extern void lockdep_reset_lock(struct lockdep_map *lock); 266extern void lockdep_reset_lock(struct lockdep_map *lock);
267extern void lockdep_free_key_range(void *start, unsigned long size); 267extern void lockdep_free_key_range(void *start, unsigned long size);
268extern void lockdep_sys_exit(void); 268extern asmlinkage void lockdep_sys_exit(void);
269 269
270extern void lockdep_off(void); 270extern void lockdep_off(void);
271extern void lockdep_on(void); 271extern void lockdep_on(void);
@@ -303,7 +303,7 @@ extern void lockdep_init_map(struct lockdep_map *lock, const char *name,
303 (lock)->dep_map.key, sub) 303 (lock)->dep_map.key, sub)
304 304
305#define lockdep_set_novalidate_class(lock) \ 305#define lockdep_set_novalidate_class(lock) \
306 lockdep_set_class(lock, &__lockdep_no_validate__) 306 lockdep_set_class_and_name(lock, &__lockdep_no_validate__, #lock)
307/* 307/*
308 * Compare locking classes 308 * Compare locking classes
309 */ 309 */
@@ -326,9 +326,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
326 * 326 *
327 * Values for check: 327 * Values for check:
328 * 328 *
329 * 0: disabled 329 * 0: simple checks (freeing, held-at-exit-time, etc.)
330 * 1: simple checks (freeing, held-at-exit-time, etc.) 330 * 1: full validation
331 * 2: full validation
332 */ 331 */
333extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass, 332extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
334 int trylock, int read, int check, 333 int trylock, int read, int check,
@@ -479,15 +478,9 @@ static inline void print_irqtrace_events(struct task_struct *curr)
479 * on the per lock-class debug mode: 478 * on the per lock-class debug mode:
480 */ 479 */
481 480
482#ifdef CONFIG_PROVE_LOCKING 481#define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i)
483 #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 2, n, i) 482#define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i)
484 #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 2, n, i) 483#define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i)
485 #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 2, n, i)
486#else
487 #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i)
488 #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i)
489 #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i)
490#endif
491 484
492#define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) 485#define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
493#define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) 486#define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
@@ -518,13 +511,13 @@ static inline void print_irqtrace_events(struct task_struct *curr)
518# define might_lock(lock) \ 511# define might_lock(lock) \
519do { \ 512do { \
520 typecheck(struct lockdep_map *, &(lock)->dep_map); \ 513 typecheck(struct lockdep_map *, &(lock)->dep_map); \
521 lock_acquire(&(lock)->dep_map, 0, 0, 0, 2, NULL, _THIS_IP_); \ 514 lock_acquire(&(lock)->dep_map, 0, 0, 0, 1, NULL, _THIS_IP_); \
522 lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ 515 lock_release(&(lock)->dep_map, 0, _THIS_IP_); \
523} while (0) 516} while (0)
524# define might_lock_read(lock) \ 517# define might_lock_read(lock) \
525do { \ 518do { \
526 typecheck(struct lockdep_map *, &(lock)->dep_map); \ 519 typecheck(struct lockdep_map *, &(lock)->dep_map); \
527 lock_acquire(&(lock)->dep_map, 0, 0, 1, 2, NULL, _THIS_IP_); \ 520 lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_); \
528 lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ 521 lock_release(&(lock)->dep_map, 0, _THIS_IP_); \
529} while (0) 522} while (0)
530#else 523#else
diff --git a/include/linux/mfd/max8997-private.h b/include/linux/mfd/max8997-private.h
index ad1ae7f345ad..78c76cd4d37b 100644
--- a/include/linux/mfd/max8997-private.h
+++ b/include/linux/mfd/max8997-private.h
@@ -387,7 +387,7 @@ struct max8997_dev {
387 struct i2c_client *muic; /* slave addr 0x4a */ 387 struct i2c_client *muic; /* slave addr 0x4a */
388 struct mutex iolock; 388 struct mutex iolock;
389 389
390 int type; 390 unsigned long type;
391 struct platform_device *battery; /* battery control (not fuel gauge) */ 391 struct platform_device *battery; /* battery control (not fuel gauge) */
392 392
393 int irq; 393 int irq;
diff --git a/include/linux/mfd/max8998-private.h b/include/linux/mfd/max8998-private.h
index 4ecb24b4b863..d68ada502ff3 100644
--- a/include/linux/mfd/max8998-private.h
+++ b/include/linux/mfd/max8998-private.h
@@ -163,7 +163,7 @@ struct max8998_dev {
163 int ono; 163 int ono;
164 u8 irq_masks_cur[MAX8998_NUM_IRQ_REGS]; 164 u8 irq_masks_cur[MAX8998_NUM_IRQ_REGS];
165 u8 irq_masks_cache[MAX8998_NUM_IRQ_REGS]; 165 u8 irq_masks_cache[MAX8998_NUM_IRQ_REGS];
166 int type; 166 unsigned long type;
167 bool wakeup; 167 bool wakeup;
168}; 168};
169 169
diff --git a/include/linux/mfd/tps65217.h b/include/linux/mfd/tps65217.h
index a5a7f0130e96..54b5458ec084 100644
--- a/include/linux/mfd/tps65217.h
+++ b/include/linux/mfd/tps65217.h
@@ -252,7 +252,7 @@ struct tps65217_board {
252struct tps65217 { 252struct tps65217 {
253 struct device *dev; 253 struct device *dev;
254 struct tps65217_board *pdata; 254 struct tps65217_board *pdata;
255 unsigned int id; 255 unsigned long id;
256 struct regulator_desc desc[TPS65217_NUM_REGULATOR]; 256 struct regulator_desc desc[TPS65217_NUM_REGULATOR];
257 struct regulator_dev *rdev[TPS65217_NUM_REGULATOR]; 257 struct regulator_dev *rdev[TPS65217_NUM_REGULATOR];
258 struct regmap *regmap; 258 struct regmap *regmap;
@@ -263,7 +263,7 @@ static inline struct tps65217 *dev_to_tps65217(struct device *dev)
263 return dev_get_drvdata(dev); 263 return dev_get_drvdata(dev);
264} 264}
265 265
266static inline int tps65217_chip_id(struct tps65217 *tps65217) 266static inline unsigned long tps65217_chip_id(struct tps65217 *tps65217)
267{ 267{
268 return tps65217->id; 268 return tps65217->id;
269} 269}
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 554548cd3dd4..130bc8d77fa5 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -38,8 +38,10 @@
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/spinlock_types.h> 39#include <linux/spinlock_types.h>
40#include <linux/semaphore.h> 40#include <linux/semaphore.h>
41#include <linux/slab.h>
41#include <linux/vmalloc.h> 42#include <linux/vmalloc.h>
42#include <linux/radix-tree.h> 43#include <linux/radix-tree.h>
44
43#include <linux/mlx5/device.h> 45#include <linux/mlx5/device.h>
44#include <linux/mlx5/doorbell.h> 46#include <linux/mlx5/doorbell.h>
45 47
@@ -227,6 +229,7 @@ struct mlx5_uuar_info {
227 * protect uuar allocation data structs 229 * protect uuar allocation data structs
228 */ 230 */
229 struct mutex lock; 231 struct mutex lock;
232 u32 ver;
230}; 233};
231 234
232struct mlx5_bf { 235struct mlx5_bf {
diff --git a/include/linux/mm.h b/include/linux/mm.h
index f28f46eade6a..a0df4295e171 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -175,7 +175,7 @@ extern unsigned int kobjsize(const void *objp);
175 * Special vmas that are non-mergable, non-mlock()able. 175 * Special vmas that are non-mergable, non-mlock()able.
176 * Note: mm/huge_memory.c VM_NO_THP depends on this definition. 176 * Note: mm/huge_memory.c VM_NO_THP depends on this definition.
177 */ 177 */
178#define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP) 178#define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP)
179 179
180/* 180/*
181 * mapping from the currently active vm_flags protection bits (the 181 * mapping from the currently active vm_flags protection bits (the
@@ -399,8 +399,18 @@ static inline void compound_unlock_irqrestore(struct page *page,
399 399
400static inline struct page *compound_head(struct page *page) 400static inline struct page *compound_head(struct page *page)
401{ 401{
402 if (unlikely(PageTail(page))) 402 if (unlikely(PageTail(page))) {
403 return page->first_page; 403 struct page *head = page->first_page;
404
405 /*
406 * page->first_page may be a dangling pointer to an old
407 * compound page, so recheck that it is still a tail
408 * page before returning.
409 */
410 smp_rmb();
411 if (likely(PageTail(page)))
412 return head;
413 }
404 return page; 414 return page;
405} 415}
406 416
@@ -757,7 +767,7 @@ static inline bool __cpupid_match_pid(pid_t task_pid, int cpupid)
757#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS 767#ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
758static inline int page_cpupid_xchg_last(struct page *page, int cpupid) 768static inline int page_cpupid_xchg_last(struct page *page, int cpupid)
759{ 769{
760 return xchg(&page->_last_cpupid, cpupid); 770 return xchg(&page->_last_cpupid, cpupid & LAST_CPUPID_MASK);
761} 771}
762 772
763static inline int page_cpupid_last(struct page *page) 773static inline int page_cpupid_last(struct page *page)
@@ -766,7 +776,7 @@ static inline int page_cpupid_last(struct page *page)
766} 776}
767static inline void page_cpupid_reset_last(struct page *page) 777static inline void page_cpupid_reset_last(struct page *page)
768{ 778{
769 page->_last_cpupid = -1; 779 page->_last_cpupid = -1 & LAST_CPUPID_MASK;
770} 780}
771#else 781#else
772static inline int page_cpupid_last(struct page *page) 782static inline int page_cpupid_last(struct page *page)
@@ -1477,9 +1487,15 @@ static inline void pgtable_page_dtor(struct page *page)
1477 1487
1478#if USE_SPLIT_PMD_PTLOCKS 1488#if USE_SPLIT_PMD_PTLOCKS
1479 1489
1490static struct page *pmd_to_page(pmd_t *pmd)
1491{
1492 unsigned long mask = ~(PTRS_PER_PMD * sizeof(pmd_t) - 1);
1493 return virt_to_page((void *)((unsigned long) pmd & mask));
1494}
1495
1480static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd) 1496static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd)
1481{ 1497{
1482 return ptlock_ptr(virt_to_page(pmd)); 1498 return ptlock_ptr(pmd_to_page(pmd));
1483} 1499}
1484 1500
1485static inline bool pgtable_pmd_page_ctor(struct page *page) 1501static inline bool pgtable_pmd_page_ctor(struct page *page)
@@ -1498,7 +1514,7 @@ static inline void pgtable_pmd_page_dtor(struct page *page)
1498 ptlock_free(page); 1514 ptlock_free(page);
1499} 1515}
1500 1516
1501#define pmd_huge_pte(mm, pmd) (virt_to_page(pmd)->pmd_huge_pte) 1517#define pmd_huge_pte(mm, pmd) (pmd_to_page(pmd)->pmd_huge_pte)
1502 1518
1503#else 1519#else
1504 1520
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 5f2052c83154..9b61b9bf81ac 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -590,10 +590,10 @@ static inline bool zone_is_empty(struct zone *zone)
590 590
591/* 591/*
592 * The NUMA zonelists are doubled because we need zonelists that restrict the 592 * The NUMA zonelists are doubled because we need zonelists that restrict the
593 * allocations to a single node for GFP_THISNODE. 593 * allocations to a single node for __GFP_THISNODE.
594 * 594 *
595 * [0] : Zonelist with fallback 595 * [0] : Zonelist with fallback
596 * [1] : No fallback (GFP_THISNODE) 596 * [1] : No fallback (__GFP_THISNODE)
597 */ 597 */
598#define MAX_ZONELISTS 2 598#define MAX_ZONELISTS 2
599 599
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index d3181936c138..11692dea18aa 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -46,6 +46,7 @@
46 * - detects multi-task circular deadlocks and prints out all affected 46 * - detects multi-task circular deadlocks and prints out all affected
47 * locks and tasks (and only those tasks) 47 * locks and tasks (and only those tasks)
48 */ 48 */
49struct optimistic_spin_queue;
49struct mutex { 50struct mutex {
50 /* 1: unlocked, 0: locked, negative: locked, possible waiters */ 51 /* 1: unlocked, 0: locked, negative: locked, possible waiters */
51 atomic_t count; 52 atomic_t count;
@@ -55,7 +56,7 @@ struct mutex {
55 struct task_struct *owner; 56 struct task_struct *owner;
56#endif 57#endif
57#ifdef CONFIG_MUTEX_SPIN_ON_OWNER 58#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
58 void *spin_mlock; /* Spinner MCS lock */ 59 struct optimistic_spin_queue *osq; /* Spinner MCS lock */
59#endif 60#endif
60#ifdef CONFIG_DEBUG_MUTEXES 61#ifdef CONFIG_DEBUG_MUTEXES
61 const char *name; 62 const char *name;
@@ -179,4 +180,4 @@ extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
179# define arch_mutex_cpu_relax() cpu_relax() 180# define arch_mutex_cpu_relax() cpu_relax()
180#endif 181#endif
181 182
182#endif 183#endif /* __LINUX_MUTEX_H */
diff --git a/include/linux/netdev_features.h b/include/linux/netdev_features.h
index 1005ebf17575..5a09a48f2658 100644
--- a/include/linux/netdev_features.h
+++ b/include/linux/netdev_features.h
@@ -163,4 +163,11 @@ enum {
163/* changeable features with no special hardware requirements */ 163/* changeable features with no special hardware requirements */
164#define NETIF_F_SOFT_FEATURES (NETIF_F_GSO | NETIF_F_GRO) 164#define NETIF_F_SOFT_FEATURES (NETIF_F_GSO | NETIF_F_GRO)
165 165
166#define NETIF_F_VLAN_FEATURES (NETIF_F_HW_VLAN_CTAG_FILTER | \
167 NETIF_F_HW_VLAN_CTAG_RX | \
168 NETIF_F_HW_VLAN_CTAG_TX | \
169 NETIF_F_HW_VLAN_STAG_FILTER | \
170 NETIF_F_HW_VLAN_STAG_RX | \
171 NETIF_F_HW_VLAN_STAG_TX)
172
166#endif /* _LINUX_NETDEV_FEATURES_H */ 173#endif /* _LINUX_NETDEV_FEATURES_H */
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 440a02ee6f92..daafd9561cbc 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -752,6 +752,9 @@ struct netdev_phys_port_id {
752 unsigned char id_len; 752 unsigned char id_len;
753}; 753};
754 754
755typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
756 struct sk_buff *skb);
757
755/* 758/*
756 * This structure defines the management hooks for network devices. 759 * This structure defines the management hooks for network devices.
757 * The following hooks can be defined; unless noted otherwise, they are 760 * The following hooks can be defined; unless noted otherwise, they are
@@ -783,7 +786,7 @@ struct netdev_phys_port_id {
783 * Required can not be NULL. 786 * Required can not be NULL.
784 * 787 *
785 * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb, 788 * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb,
786 * void *accel_priv); 789 * void *accel_priv, select_queue_fallback_t fallback);
787 * Called to decide which queue to when device supports multiple 790 * Called to decide which queue to when device supports multiple
788 * transmit queues. 791 * transmit queues.
789 * 792 *
@@ -1005,7 +1008,8 @@ struct net_device_ops {
1005 struct net_device *dev); 1008 struct net_device *dev);
1006 u16 (*ndo_select_queue)(struct net_device *dev, 1009 u16 (*ndo_select_queue)(struct net_device *dev,
1007 struct sk_buff *skb, 1010 struct sk_buff *skb,
1008 void *accel_priv); 1011 void *accel_priv,
1012 select_queue_fallback_t fallback);
1009 void (*ndo_change_rx_flags)(struct net_device *dev, 1013 void (*ndo_change_rx_flags)(struct net_device *dev,
1010 int flags); 1014 int flags);
1011 void (*ndo_set_rx_mode)(struct net_device *dev); 1015 void (*ndo_set_rx_mode)(struct net_device *dev);
@@ -1551,7 +1555,6 @@ static inline void netdev_for_each_tx_queue(struct net_device *dev,
1551struct netdev_queue *netdev_pick_tx(struct net_device *dev, 1555struct netdev_queue *netdev_pick_tx(struct net_device *dev,
1552 struct sk_buff *skb, 1556 struct sk_buff *skb,
1553 void *accel_priv); 1557 void *accel_priv);
1554u16 __netdev_pick_tx(struct net_device *dev, struct sk_buff *skb);
1555 1558
1556/* 1559/*
1557 * Net namespace inlines 1560 * Net namespace inlines
@@ -2276,6 +2279,26 @@ static inline void netdev_reset_queue(struct net_device *dev_queue)
2276} 2279}
2277 2280
2278/** 2281/**
2282 * netdev_cap_txqueue - check if selected tx queue exceeds device queues
2283 * @dev: network device
2284 * @queue_index: given tx queue index
2285 *
2286 * Returns 0 if given tx queue index >= number of device tx queues,
2287 * otherwise returns the originally passed tx queue index.
2288 */
2289static inline u16 netdev_cap_txqueue(struct net_device *dev, u16 queue_index)
2290{
2291 if (unlikely(queue_index >= dev->real_num_tx_queues)) {
2292 net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
2293 dev->name, queue_index,
2294 dev->real_num_tx_queues);
2295 return 0;
2296 }
2297
2298 return queue_index;
2299}
2300
2301/**
2279 * netif_running - test if up 2302 * netif_running - test if up
2280 * @dev: network device 2303 * @dev: network device
2281 * 2304 *
@@ -2991,7 +3014,7 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb, netdev_features_t features)
2991{ 3014{
2992 return __skb_gso_segment(skb, features, true); 3015 return __skb_gso_segment(skb, features, true);
2993} 3016}
2994__be16 skb_network_protocol(struct sk_buff *skb); 3017__be16 skb_network_protocol(struct sk_buff *skb, int *depth);
2995 3018
2996static inline bool can_checksum_protocol(netdev_features_t features, 3019static inline bool can_checksum_protocol(netdev_features_t features,
2997 __be16 protocol) 3020 __be16 protocol)
@@ -3068,7 +3091,12 @@ void netdev_change_features(struct net_device *dev);
3068void netif_stacked_transfer_operstate(const struct net_device *rootdev, 3091void netif_stacked_transfer_operstate(const struct net_device *rootdev,
3069 struct net_device *dev); 3092 struct net_device *dev);
3070 3093
3071netdev_features_t netif_skb_features(struct sk_buff *skb); 3094netdev_features_t netif_skb_dev_features(struct sk_buff *skb,
3095 const struct net_device *dev);
3096static inline netdev_features_t netif_skb_features(struct sk_buff *skb)
3097{
3098 return netif_skb_dev_features(skb, skb->dev);
3099}
3072 3100
3073static inline bool net_gso_ok(netdev_features_t features, int gso_type) 3101static inline bool net_gso_ok(netdev_features_t features, int gso_type)
3074{ 3102{
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index 3ccfcecf8999..5624e4e2763c 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -379,12 +379,14 @@ struct nfs_openres {
379 * Arguments to the open_confirm call. 379 * Arguments to the open_confirm call.
380 */ 380 */
381struct nfs_open_confirmargs { 381struct nfs_open_confirmargs {
382 struct nfs4_sequence_args seq_args;
382 const struct nfs_fh * fh; 383 const struct nfs_fh * fh;
383 nfs4_stateid * stateid; 384 nfs4_stateid * stateid;
384 struct nfs_seqid * seqid; 385 struct nfs_seqid * seqid;
385}; 386};
386 387
387struct nfs_open_confirmres { 388struct nfs_open_confirmres {
389 struct nfs4_sequence_res seq_res;
388 nfs4_stateid stateid; 390 nfs4_stateid stateid;
389 struct nfs_seqid * seqid; 391 struct nfs_seqid * seqid;
390}; 392};
@@ -465,9 +467,14 @@ struct nfs_lockt_res {
465}; 467};
466 468
467struct nfs_release_lockowner_args { 469struct nfs_release_lockowner_args {
470 struct nfs4_sequence_args seq_args;
468 struct nfs_lowner lock_owner; 471 struct nfs_lowner lock_owner;
469}; 472};
470 473
474struct nfs_release_lockowner_res {
475 struct nfs4_sequence_res seq_res;
476};
477
471struct nfs4_delegreturnargs { 478struct nfs4_delegreturnargs {
472 struct nfs4_sequence_args seq_args; 479 struct nfs4_sequence_args seq_args;
473 const struct nfs_fh *fhandle; 480 const struct nfs_fh *fhandle;
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 26ebcf41c213..6b9aafed225f 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -80,13 +80,15 @@ struct nvme_dev {
80 struct dma_pool *prp_small_pool; 80 struct dma_pool *prp_small_pool;
81 int instance; 81 int instance;
82 int queue_count; 82 int queue_count;
83 int db_stride; 83 u32 db_stride;
84 u32 ctrl_config; 84 u32 ctrl_config;
85 struct msix_entry *entry; 85 struct msix_entry *entry;
86 struct nvme_bar __iomem *bar; 86 struct nvme_bar __iomem *bar;
87 struct list_head namespaces; 87 struct list_head namespaces;
88 struct kref kref; 88 struct kref kref;
89 struct miscdevice miscdev; 89 struct miscdevice miscdev;
90 work_func_t reset_workfn;
91 struct work_struct reset_work;
90 char name[12]; 92 char name[12];
91 char serial[20]; 93 char serial[20];
92 char model[40]; 94 char model[40];
@@ -94,6 +96,8 @@ struct nvme_dev {
94 u32 max_hw_sectors; 96 u32 max_hw_sectors;
95 u32 stripe_size; 97 u32 stripe_size;
96 u16 oncs; 98 u16 oncs;
99 u16 abort_limit;
100 u8 initialized;
97}; 101};
98 102
99/* 103/*
@@ -165,6 +169,7 @@ int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
165struct sg_io_hdr; 169struct sg_io_hdr;
166 170
167int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr); 171int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr);
172int nvme_sg_io32(struct nvme_ns *ns, unsigned long arg);
168int nvme_sg_get_version_num(int __user *ip); 173int nvme_sg_get_version_num(int __user *ip);
169 174
170#endif /* _LINUX_NVME_H */ 175#endif /* _LINUX_NVME_H */
diff --git a/include/linux/of.h b/include/linux/of.h
index 70c64ba17fa5..435cb995904d 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -169,35 +169,15 @@ static inline const char *of_node_full_name(const struct device_node *np)
169 169
170extern struct device_node *of_find_node_by_name(struct device_node *from, 170extern struct device_node *of_find_node_by_name(struct device_node *from,
171 const char *name); 171 const char *name);
172#define for_each_node_by_name(dn, name) \
173 for (dn = of_find_node_by_name(NULL, name); dn; \
174 dn = of_find_node_by_name(dn, name))
175extern struct device_node *of_find_node_by_type(struct device_node *from, 172extern struct device_node *of_find_node_by_type(struct device_node *from,
176 const char *type); 173 const char *type);
177#define for_each_node_by_type(dn, type) \
178 for (dn = of_find_node_by_type(NULL, type); dn; \
179 dn = of_find_node_by_type(dn, type))
180extern struct device_node *of_find_compatible_node(struct device_node *from, 174extern struct device_node *of_find_compatible_node(struct device_node *from,
181 const char *type, const char *compat); 175 const char *type, const char *compat);
182#define for_each_compatible_node(dn, type, compatible) \
183 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
184 dn = of_find_compatible_node(dn, type, compatible))
185extern struct device_node *of_find_matching_node_and_match( 176extern struct device_node *of_find_matching_node_and_match(
186 struct device_node *from, 177 struct device_node *from,
187 const struct of_device_id *matches, 178 const struct of_device_id *matches,
188 const struct of_device_id **match); 179 const struct of_device_id **match);
189static inline struct device_node *of_find_matching_node( 180
190 struct device_node *from,
191 const struct of_device_id *matches)
192{
193 return of_find_matching_node_and_match(from, matches, NULL);
194}
195#define for_each_matching_node(dn, matches) \
196 for (dn = of_find_matching_node(NULL, matches); dn; \
197 dn = of_find_matching_node(dn, matches))
198#define for_each_matching_node_and_match(dn, matches, match) \
199 for (dn = of_find_matching_node_and_match(NULL, matches, match); \
200 dn; dn = of_find_matching_node_and_match(dn, matches, match))
201extern struct device_node *of_find_node_by_path(const char *path); 181extern struct device_node *of_find_node_by_path(const char *path);
202extern struct device_node *of_find_node_by_phandle(phandle handle); 182extern struct device_node *of_find_node_by_phandle(phandle handle);
203extern struct device_node *of_get_parent(const struct device_node *node); 183extern struct device_node *of_get_parent(const struct device_node *node);
@@ -209,43 +189,11 @@ extern struct device_node *of_get_next_available_child(
209 189
210extern struct device_node *of_get_child_by_name(const struct device_node *node, 190extern struct device_node *of_get_child_by_name(const struct device_node *node,
211 const char *name); 191 const char *name);
212#define for_each_child_of_node(parent, child) \
213 for (child = of_get_next_child(parent, NULL); child != NULL; \
214 child = of_get_next_child(parent, child))
215
216#define for_each_available_child_of_node(parent, child) \
217 for (child = of_get_next_available_child(parent, NULL); child != NULL; \
218 child = of_get_next_available_child(parent, child))
219
220static inline int of_get_child_count(const struct device_node *np)
221{
222 struct device_node *child;
223 int num = 0;
224
225 for_each_child_of_node(np, child)
226 num++;
227
228 return num;
229}
230
231static inline int of_get_available_child_count(const struct device_node *np)
232{
233 struct device_node *child;
234 int num = 0;
235
236 for_each_available_child_of_node(np, child)
237 num++;
238
239 return num;
240}
241 192
242/* cache lookup */ 193/* cache lookup */
243extern struct device_node *of_find_next_cache_node(const struct device_node *); 194extern struct device_node *of_find_next_cache_node(const struct device_node *);
244extern struct device_node *of_find_node_with_property( 195extern struct device_node *of_find_node_with_property(
245 struct device_node *from, const char *prop_name); 196 struct device_node *from, const char *prop_name);
246#define for_each_node_with_property(dn, prop_name) \
247 for (dn = of_find_node_with_property(NULL, prop_name); dn; \
248 dn = of_find_node_with_property(dn, prop_name))
249 197
250extern struct property *of_find_property(const struct device_node *np, 198extern struct property *of_find_property(const struct device_node *np,
251 const char *name, 199 const char *name,
@@ -367,42 +315,53 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
367 return NULL; 315 return NULL;
368} 316}
369 317
370static inline struct device_node *of_get_parent(const struct device_node *node) 318static inline struct device_node *of_find_node_by_type(struct device_node *from,
319 const char *type)
371{ 320{
372 return NULL; 321 return NULL;
373} 322}
374 323
375static inline bool of_have_populated_dt(void) 324static inline struct device_node *of_find_matching_node_and_match(
325 struct device_node *from,
326 const struct of_device_id *matches,
327 const struct of_device_id **match)
376{ 328{
377 return false; 329 return NULL;
378} 330}
379 331
380/* Kill an unused variable warning on a device_node pointer */ 332static inline struct device_node *of_get_parent(const struct device_node *node)
381static inline void __of_use_dn(const struct device_node *np)
382{ 333{
334 return NULL;
383} 335}
384 336
385#define for_each_child_of_node(parent, child) \ 337static inline struct device_node *of_get_next_child(
386 while (__of_use_dn(parent), __of_use_dn(child), 0) 338 const struct device_node *node, struct device_node *prev)
339{
340 return NULL;
341}
387 342
388#define for_each_available_child_of_node(parent, child) \ 343static inline struct device_node *of_get_next_available_child(
389 while (0) 344 const struct device_node *node, struct device_node *prev)
345{
346 return NULL;
347}
390 348
391static inline struct device_node *of_get_child_by_name( 349static inline struct device_node *of_find_node_with_property(
392 const struct device_node *node, 350 struct device_node *from, const char *prop_name)
393 const char *name)
394{ 351{
395 return NULL; 352 return NULL;
396} 353}
397 354
398static inline int of_get_child_count(const struct device_node *np) 355static inline bool of_have_populated_dt(void)
399{ 356{
400 return 0; 357 return false;
401} 358}
402 359
403static inline int of_get_available_child_count(const struct device_node *np) 360static inline struct device_node *of_get_child_by_name(
361 const struct device_node *node,
362 const char *name)
404{ 363{
405 return 0; 364 return NULL;
406} 365}
407 366
408static inline int of_device_is_compatible(const struct device_node *device, 367static inline int of_device_is_compatible(const struct device_node *device,
@@ -569,6 +528,13 @@ extern int of_node_to_nid(struct device_node *np);
569static inline int of_node_to_nid(struct device_node *device) { return 0; } 528static inline int of_node_to_nid(struct device_node *device) { return 0; }
570#endif 529#endif
571 530
531static inline struct device_node *of_find_matching_node(
532 struct device_node *from,
533 const struct of_device_id *matches)
534{
535 return of_find_matching_node_and_match(from, matches, NULL);
536}
537
572/** 538/**
573 * of_property_read_bool - Findfrom a property 539 * of_property_read_bool - Findfrom a property
574 * @np: device node from which the property value is to be read. 540 * @np: device node from which the property value is to be read.
@@ -618,6 +584,55 @@ static inline int of_property_read_u32(const struct device_node *np,
618 s; \ 584 s; \
619 s = of_prop_next_string(prop, s)) 585 s = of_prop_next_string(prop, s))
620 586
587#define for_each_node_by_name(dn, name) \
588 for (dn = of_find_node_by_name(NULL, name); dn; \
589 dn = of_find_node_by_name(dn, name))
590#define for_each_node_by_type(dn, type) \
591 for (dn = of_find_node_by_type(NULL, type); dn; \
592 dn = of_find_node_by_type(dn, type))
593#define for_each_compatible_node(dn, type, compatible) \
594 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
595 dn = of_find_compatible_node(dn, type, compatible))
596#define for_each_matching_node(dn, matches) \
597 for (dn = of_find_matching_node(NULL, matches); dn; \
598 dn = of_find_matching_node(dn, matches))
599#define for_each_matching_node_and_match(dn, matches, match) \
600 for (dn = of_find_matching_node_and_match(NULL, matches, match); \
601 dn; dn = of_find_matching_node_and_match(dn, matches, match))
602
603#define for_each_child_of_node(parent, child) \
604 for (child = of_get_next_child(parent, NULL); child != NULL; \
605 child = of_get_next_child(parent, child))
606#define for_each_available_child_of_node(parent, child) \
607 for (child = of_get_next_available_child(parent, NULL); child != NULL; \
608 child = of_get_next_available_child(parent, child))
609
610#define for_each_node_with_property(dn, prop_name) \
611 for (dn = of_find_node_with_property(NULL, prop_name); dn; \
612 dn = of_find_node_with_property(dn, prop_name))
613
614static inline int of_get_child_count(const struct device_node *np)
615{
616 struct device_node *child;
617 int num = 0;
618
619 for_each_child_of_node(np, child)
620 num++;
621
622 return num;
623}
624
625static inline int of_get_available_child_count(const struct device_node *np)
626{
627 struct device_node *child;
628 int num = 0;
629
630 for_each_available_child_of_node(np, child)
631 num++;
632
633 return num;
634}
635
621#if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE) 636#if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE)
622extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *); 637extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
623extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop); 638extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 8d7dd6768cb7..ef370210ffb2 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -78,11 +78,13 @@ static inline int of_device_uevent_modalias(struct device *dev,
78 78
79static inline void of_device_node_put(struct device *dev) { } 79static inline void of_device_node_put(struct device *dev) { }
80 80
81static inline const struct of_device_id *of_match_device( 81static inline const struct of_device_id *__of_match_device(
82 const struct of_device_id *matches, const struct device *dev) 82 const struct of_device_id *matches, const struct device *dev)
83{ 83{
84 return NULL; 84 return NULL;
85} 85}
86#define of_match_device(matches, dev) \
87 __of_match_device(of_match_ptr(matches), (dev))
86 88
87static inline struct device_node *of_cpu_device_node_get(int cpu) 89static inline struct device_node *of_cpu_device_node_get(int cpu)
88{ 90{
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index e464b4e987e8..d1fe1a761047 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -228,9 +228,9 @@ PAGEFLAG(OwnerPriv1, owner_priv_1) TESTCLEARFLAG(OwnerPriv1, owner_priv_1)
228TESTPAGEFLAG(Writeback, writeback) TESTSCFLAG(Writeback, writeback) 228TESTPAGEFLAG(Writeback, writeback) TESTSCFLAG(Writeback, writeback)
229PAGEFLAG(MappedToDisk, mappedtodisk) 229PAGEFLAG(MappedToDisk, mappedtodisk)
230 230
231/* PG_readahead is only used for file reads; PG_reclaim is only for writes */ 231/* PG_readahead is only used for reads; PG_reclaim is only for writes */
232PAGEFLAG(Reclaim, reclaim) TESTCLEARFLAG(Reclaim, reclaim) 232PAGEFLAG(Reclaim, reclaim) TESTCLEARFLAG(Reclaim, reclaim)
233PAGEFLAG(Readahead, reclaim) /* Reminder to do async read-ahead */ 233PAGEFLAG(Readahead, reclaim) TESTCLEARFLAG(Readahead, reclaim)
234 234
235#ifdef CONFIG_HIGHMEM 235#ifdef CONFIG_HIGHMEM
236/* 236/*
diff --git a/include/linux/pci.h b/include/linux/pci.h
index fb57c892b214..33aa2caf0f0c 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1169,8 +1169,23 @@ void msi_remove_pci_irq_vectors(struct pci_dev *dev);
1169void pci_restore_msi_state(struct pci_dev *dev); 1169void pci_restore_msi_state(struct pci_dev *dev);
1170int pci_msi_enabled(void); 1170int pci_msi_enabled(void);
1171int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec); 1171int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec);
1172static inline int pci_enable_msi_exact(struct pci_dev *dev, int nvec)
1173{
1174 int rc = pci_enable_msi_range(dev, nvec, nvec);
1175 if (rc < 0)
1176 return rc;
1177 return 0;
1178}
1172int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, 1179int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
1173 int minvec, int maxvec); 1180 int minvec, int maxvec);
1181static inline int pci_enable_msix_exact(struct pci_dev *dev,
1182 struct msix_entry *entries, int nvec)
1183{
1184 int rc = pci_enable_msix_range(dev, entries, nvec, nvec);
1185 if (rc < 0)
1186 return rc;
1187 return 0;
1188}
1174#else 1189#else
1175static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; } 1190static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
1176static inline int pci_enable_msi_block(struct pci_dev *dev, int nvec) 1191static inline int pci_enable_msi_block(struct pci_dev *dev, int nvec)
@@ -1189,9 +1204,14 @@ static inline int pci_msi_enabled(void) { return 0; }
1189static inline int pci_enable_msi_range(struct pci_dev *dev, int minvec, 1204static inline int pci_enable_msi_range(struct pci_dev *dev, int minvec,
1190 int maxvec) 1205 int maxvec)
1191{ return -ENOSYS; } 1206{ return -ENOSYS; }
1207static inline int pci_enable_msi_exact(struct pci_dev *dev, int nvec)
1208{ return -ENOSYS; }
1192static inline int pci_enable_msix_range(struct pci_dev *dev, 1209static inline int pci_enable_msix_range(struct pci_dev *dev,
1193 struct msix_entry *entries, int minvec, int maxvec) 1210 struct msix_entry *entries, int minvec, int maxvec)
1194{ return -ENOSYS; } 1211{ return -ENOSYS; }
1212static inline int pci_enable_msix_exact(struct pci_dev *dev,
1213 struct msix_entry *entries, int nvec)
1214{ return -ENOSYS; }
1195#endif 1215#endif
1196 1216
1197#ifdef CONFIG_PCIEPORTBUS 1217#ifdef CONFIG_PCIEPORTBUS
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 97fbecdd7a40..7399e6a3e9a0 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -2531,6 +2531,9 @@
2531 2531
2532#define PCI_VENDOR_ID_INTEL 0x8086 2532#define PCI_VENDOR_ID_INTEL 0x8086
2533#define PCI_DEVICE_ID_INTEL_EESSC 0x0008 2533#define PCI_DEVICE_ID_INTEL_EESSC 0x0008
2534#define PCI_DEVICE_ID_INTEL_SNB_IMC 0x0100
2535#define PCI_DEVICE_ID_INTEL_IVB_IMC 0x0154
2536#define PCI_DEVICE_ID_INTEL_HSW_IMC 0x0c00
2534#define PCI_DEVICE_ID_INTEL_PXHD_0 0x0320 2537#define PCI_DEVICE_ID_INTEL_PXHD_0 0x0320
2535#define PCI_DEVICE_ID_INTEL_PXHD_1 0x0321 2538#define PCI_DEVICE_ID_INTEL_PXHD_1 0x0321
2536#define PCI_DEVICE_ID_INTEL_PXH_0 0x0329 2539#define PCI_DEVICE_ID_INTEL_PXH_0 0x0329
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index e273e5ac19c9..3f83459dbb20 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -146,7 +146,9 @@ static inline void phy_set_bus_width(struct phy *phy, int bus_width)
146 phy->attrs.bus_width = bus_width; 146 phy->attrs.bus_width = bus_width;
147} 147}
148struct phy *phy_get(struct device *dev, const char *string); 148struct phy *phy_get(struct device *dev, const char *string);
149struct phy *phy_optional_get(struct device *dev, const char *string);
149struct phy *devm_phy_get(struct device *dev, const char *string); 150struct phy *devm_phy_get(struct device *dev, const char *string);
151struct phy *devm_phy_optional_get(struct device *dev, const char *string);
150void phy_put(struct phy *phy); 152void phy_put(struct phy *phy);
151void devm_phy_put(struct device *dev, struct phy *phy); 153void devm_phy_put(struct device *dev, struct phy *phy);
152struct phy *of_phy_simple_xlate(struct device *dev, 154struct phy *of_phy_simple_xlate(struct device *dev,
@@ -232,11 +234,23 @@ static inline struct phy *phy_get(struct device *dev, const char *string)
232 return ERR_PTR(-ENOSYS); 234 return ERR_PTR(-ENOSYS);
233} 235}
234 236
237static inline struct phy *phy_optional_get(struct device *dev,
238 const char *string)
239{
240 return ERR_PTR(-ENOSYS);
241}
242
235static inline struct phy *devm_phy_get(struct device *dev, const char *string) 243static inline struct phy *devm_phy_get(struct device *dev, const char *string)
236{ 244{
237 return ERR_PTR(-ENOSYS); 245 return ERR_PTR(-ENOSYS);
238} 246}
239 247
248static inline struct phy *devm_phy_optional_get(struct device *dev,
249 const char *string)
250{
251 return ERR_PTR(-ENOSYS);
252}
253
240static inline void phy_put(struct phy *phy) 254static inline void phy_put(struct phy *phy)
241{ 255{
242} 256}
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index dbaf99084112..8183b46fbaa2 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -247,9 +247,10 @@ static inline void list_splice_init_rcu(struct list_head *list,
247 * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). 247 * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
248 */ 248 */
249#define list_entry_rcu(ptr, type, member) \ 249#define list_entry_rcu(ptr, type, member) \
250 ({typeof (*ptr) __rcu *__ptr = (typeof (*ptr) __rcu __force *)ptr; \ 250({ \
251 container_of((typeof(ptr))rcu_dereference_raw(__ptr), type, member); \ 251 typeof(*ptr) __rcu *__ptr = (typeof(*ptr) __rcu __force *)ptr; \
252 }) 252 container_of((typeof(ptr))rcu_dereference_raw(__ptr), type, member); \
253})
253 254
254/** 255/**
255 * Where are list_empty_rcu() and list_first_entry_rcu()? 256 * Where are list_empty_rcu() and list_first_entry_rcu()?
@@ -285,11 +286,11 @@ static inline void list_splice_init_rcu(struct list_head *list,
285 * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). 286 * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
286 */ 287 */
287#define list_first_or_null_rcu(ptr, type, member) \ 288#define list_first_or_null_rcu(ptr, type, member) \
288 ({struct list_head *__ptr = (ptr); \ 289({ \
289 struct list_head *__next = ACCESS_ONCE(__ptr->next); \ 290 struct list_head *__ptr = (ptr); \
290 likely(__ptr != __next) ? \ 291 struct list_head *__next = ACCESS_ONCE(__ptr->next); \
291 list_entry_rcu(__next, type, member) : NULL; \ 292 likely(__ptr != __next) ? list_entry_rcu(__next, type, member) : NULL; \
292 }) 293})
293 294
294/** 295/**
295 * list_for_each_entry_rcu - iterate over rcu list of given type 296 * list_for_each_entry_rcu - iterate over rcu list of given type
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 72bf3a01a4ee..00a7fd61b3c6 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright IBM Corporation, 2001 18 * Copyright IBM Corporation, 2001
19 * 19 *
@@ -44,7 +44,9 @@
44#include <linux/debugobjects.h> 44#include <linux/debugobjects.h>
45#include <linux/bug.h> 45#include <linux/bug.h>
46#include <linux/compiler.h> 46#include <linux/compiler.h>
47#include <asm/barrier.h>
47 48
49extern int rcu_expedited; /* for sysctl */
48#ifdef CONFIG_RCU_TORTURE_TEST 50#ifdef CONFIG_RCU_TORTURE_TEST
49extern int rcutorture_runnable; /* for sysctl */ 51extern int rcutorture_runnable; /* for sysctl */
50#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ 52#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
@@ -314,7 +316,7 @@ static inline bool rcu_lockdep_current_cpu_online(void)
314 316
315static inline void rcu_lock_acquire(struct lockdep_map *map) 317static inline void rcu_lock_acquire(struct lockdep_map *map)
316{ 318{
317 lock_acquire(map, 0, 0, 2, 1, NULL, _THIS_IP_); 319 lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_);
318} 320}
319 321
320static inline void rcu_lock_release(struct lockdep_map *map) 322static inline void rcu_lock_release(struct lockdep_map *map)
@@ -479,11 +481,9 @@ static inline void rcu_preempt_sleep_check(void)
479 do { \ 481 do { \
480 rcu_preempt_sleep_check(); \ 482 rcu_preempt_sleep_check(); \
481 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map), \ 483 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map), \
482 "Illegal context switch in RCU-bh" \ 484 "Illegal context switch in RCU-bh read-side critical section"); \
483 " read-side critical section"); \
484 rcu_lockdep_assert(!lock_is_held(&rcu_sched_lock_map), \ 485 rcu_lockdep_assert(!lock_is_held(&rcu_sched_lock_map), \
485 "Illegal context switch in RCU-sched"\ 486 "Illegal context switch in RCU-sched read-side critical section"); \
486 " read-side critical section"); \
487 } while (0) 487 } while (0)
488 488
489#else /* #ifdef CONFIG_PROVE_RCU */ 489#else /* #ifdef CONFIG_PROVE_RCU */
@@ -510,43 +510,40 @@ static inline void rcu_preempt_sleep_check(void)
510#endif /* #else #ifdef __CHECKER__ */ 510#endif /* #else #ifdef __CHECKER__ */
511 511
512#define __rcu_access_pointer(p, space) \ 512#define __rcu_access_pointer(p, space) \
513 ({ \ 513({ \
514 typeof(*p) *_________p1 = (typeof(*p)*__force )ACCESS_ONCE(p); \ 514 typeof(*p) *_________p1 = (typeof(*p) *__force)ACCESS_ONCE(p); \
515 rcu_dereference_sparse(p, space); \ 515 rcu_dereference_sparse(p, space); \
516 ((typeof(*p) __force __kernel *)(_________p1)); \ 516 ((typeof(*p) __force __kernel *)(_________p1)); \
517 }) 517})
518#define __rcu_dereference_check(p, c, space) \ 518#define __rcu_dereference_check(p, c, space) \
519 ({ \ 519({ \
520 typeof(*p) *_________p1 = (typeof(*p)*__force )ACCESS_ONCE(p); \ 520 typeof(*p) *_________p1 = (typeof(*p) *__force)ACCESS_ONCE(p); \
521 rcu_lockdep_assert(c, "suspicious rcu_dereference_check()" \ 521 rcu_lockdep_assert(c, "suspicious rcu_dereference_check() usage"); \
522 " usage"); \ 522 rcu_dereference_sparse(p, space); \
523 rcu_dereference_sparse(p, space); \ 523 smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
524 smp_read_barrier_depends(); \ 524 ((typeof(*p) __force __kernel *)(_________p1)); \
525 ((typeof(*p) __force __kernel *)(_________p1)); \ 525})
526 })
527#define __rcu_dereference_protected(p, c, space) \ 526#define __rcu_dereference_protected(p, c, space) \
528 ({ \ 527({ \
529 rcu_lockdep_assert(c, "suspicious rcu_dereference_protected()" \ 528 rcu_lockdep_assert(c, "suspicious rcu_dereference_protected() usage"); \
530 " usage"); \ 529 rcu_dereference_sparse(p, space); \
531 rcu_dereference_sparse(p, space); \ 530 ((typeof(*p) __force __kernel *)(p)); \
532 ((typeof(*p) __force __kernel *)(p)); \ 531})
533 })
534 532
535#define __rcu_access_index(p, space) \ 533#define __rcu_access_index(p, space) \
536 ({ \ 534({ \
537 typeof(p) _________p1 = ACCESS_ONCE(p); \ 535 typeof(p) _________p1 = ACCESS_ONCE(p); \
538 rcu_dereference_sparse(p, space); \ 536 rcu_dereference_sparse(p, space); \
539 (_________p1); \ 537 (_________p1); \
540 }) 538})
541#define __rcu_dereference_index_check(p, c) \ 539#define __rcu_dereference_index_check(p, c) \
542 ({ \ 540({ \
543 typeof(p) _________p1 = ACCESS_ONCE(p); \ 541 typeof(p) _________p1 = ACCESS_ONCE(p); \
544 rcu_lockdep_assert(c, \ 542 rcu_lockdep_assert(c, \
545 "suspicious rcu_dereference_index_check()" \ 543 "suspicious rcu_dereference_index_check() usage"); \
546 " usage"); \ 544 smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
547 smp_read_barrier_depends(); \ 545 (_________p1); \
548 (_________p1); \ 546})
549 })
550 547
551/** 548/**
552 * RCU_INITIALIZER() - statically initialize an RCU-protected global variable 549 * RCU_INITIALIZER() - statically initialize an RCU-protected global variable
@@ -585,12 +582,7 @@ static inline void rcu_preempt_sleep_check(void)
585 * please be careful when making changes to rcu_assign_pointer() and the 582 * please be careful when making changes to rcu_assign_pointer() and the
586 * other macros that it invokes. 583 * other macros that it invokes.
587 */ 584 */
588#define rcu_assign_pointer(p, v) \ 585#define rcu_assign_pointer(p, v) smp_store_release(&p, RCU_INITIALIZER(v))
589 do { \
590 smp_wmb(); \
591 ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
592 } while (0)
593
594 586
595/** 587/**
596 * rcu_access_pointer() - fetch RCU pointer with no dereferencing 588 * rcu_access_pointer() - fetch RCU pointer with no dereferencing
@@ -1015,11 +1007,21 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
1015#define kfree_rcu(ptr, rcu_head) \ 1007#define kfree_rcu(ptr, rcu_head) \
1016 __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head)) 1008 __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))
1017 1009
1018#ifdef CONFIG_RCU_NOCB_CPU 1010#if defined(CONFIG_TINY_RCU) || defined(CONFIG_RCU_NOCB_CPU_ALL)
1011static inline int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
1012{
1013 *delta_jiffies = ULONG_MAX;
1014 return 0;
1015}
1016#endif /* #if defined(CONFIG_TINY_RCU) || defined(CONFIG_RCU_NOCB_CPU_ALL) */
1017
1018#if defined(CONFIG_RCU_NOCB_CPU_ALL)
1019static inline bool rcu_is_nocb_cpu(int cpu) { return true; }
1020#elif defined(CONFIG_RCU_NOCB_CPU)
1019bool rcu_is_nocb_cpu(int cpu); 1021bool rcu_is_nocb_cpu(int cpu);
1020#else 1022#else
1021static inline bool rcu_is_nocb_cpu(int cpu) { return false; } 1023static inline bool rcu_is_nocb_cpu(int cpu) { return false; }
1022#endif /* #else #ifdef CONFIG_RCU_NOCB_CPU */ 1024#endif
1023 1025
1024 1026
1025/* Only for use by adaptive-ticks code. */ 1027/* Only for use by adaptive-ticks code. */
diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h
index 6f01771b571c..425c659d54e5 100644
--- a/include/linux/rcutiny.h
+++ b/include/linux/rcutiny.h
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright IBM Corporation, 2008 18 * Copyright IBM Corporation, 2008
19 * 19 *
@@ -27,6 +27,16 @@
27 27
28#include <linux/cache.h> 28#include <linux/cache.h>
29 29
30static inline unsigned long get_state_synchronize_rcu(void)
31{
32 return 0;
33}
34
35static inline void cond_synchronize_rcu(unsigned long oldstate)
36{
37 might_sleep();
38}
39
30static inline void rcu_barrier_bh(void) 40static inline void rcu_barrier_bh(void)
31{ 41{
32 wait_rcu_gp(call_rcu_bh); 42 wait_rcu_gp(call_rcu_bh);
@@ -68,12 +78,6 @@ static inline void kfree_call_rcu(struct rcu_head *head,
68 call_rcu(head, func); 78 call_rcu(head, func);
69} 79}
70 80
71static inline int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
72{
73 *delta_jiffies = ULONG_MAX;
74 return 0;
75}
76
77static inline void rcu_note_context_switch(int cpu) 81static inline void rcu_note_context_switch(int cpu)
78{ 82{
79 rcu_sched_qs(cpu); 83 rcu_sched_qs(cpu);
diff --git a/include/linux/rcutree.h b/include/linux/rcutree.h
index 72137ee8c603..a59ca05fd4e3 100644
--- a/include/linux/rcutree.h
+++ b/include/linux/rcutree.h
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright IBM Corporation, 2008 18 * Copyright IBM Corporation, 2008
19 * 19 *
@@ -31,7 +31,9 @@
31#define __LINUX_RCUTREE_H 31#define __LINUX_RCUTREE_H
32 32
33void rcu_note_context_switch(int cpu); 33void rcu_note_context_switch(int cpu);
34#ifndef CONFIG_RCU_NOCB_CPU_ALL
34int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies); 35int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies);
36#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
35void rcu_cpu_stall_reset(void); 37void rcu_cpu_stall_reset(void);
36 38
37/* 39/*
@@ -74,6 +76,8 @@ static inline void synchronize_rcu_bh_expedited(void)
74void rcu_barrier(void); 76void rcu_barrier(void);
75void rcu_barrier_bh(void); 77void rcu_barrier_bh(void);
76void rcu_barrier_sched(void); 78void rcu_barrier_sched(void);
79unsigned long get_state_synchronize_rcu(void);
80void cond_synchronize_rcu(unsigned long oldstate);
77 81
78extern unsigned long rcutorture_testseq; 82extern unsigned long rcutorture_testseq;
79extern unsigned long rcutorture_vernum; 83extern unsigned long rcutorture_vernum;
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 1da693d51255..b66c2110cb1f 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -250,8 +250,7 @@ struct rmap_walk_control {
250 int (*rmap_one)(struct page *page, struct vm_area_struct *vma, 250 int (*rmap_one)(struct page *page, struct vm_area_struct *vma,
251 unsigned long addr, void *arg); 251 unsigned long addr, void *arg);
252 int (*done)(struct page *page); 252 int (*done)(struct page *page);
253 int (*file_nonlinear)(struct page *, struct address_space *, 253 int (*file_nonlinear)(struct page *, struct address_space *, void *arg);
254 struct vm_area_struct *vma);
255 struct anon_vma *(*anon_lock)(struct page *page); 254 struct anon_vma *(*anon_lock)(struct page *page);
256 bool (*invalid_vma)(struct vm_area_struct *vma, void *arg); 255 bool (*invalid_vma)(struct vm_area_struct *vma, void *arg);
257}; 256};
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 68a0e84463a0..825ed838d4b9 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -3,6 +3,8 @@
3 3
4#include <uapi/linux/sched.h> 4#include <uapi/linux/sched.h>
5 5
6#include <linux/sched/prio.h>
7
6 8
7struct sched_param { 9struct sched_param {
8 int sched_priority; 10 int sched_priority;
@@ -128,6 +130,7 @@ struct bio_list;
128struct fs_struct; 130struct fs_struct;
129struct perf_event_context; 131struct perf_event_context;
130struct blk_plug; 132struct blk_plug;
133struct filename;
131 134
132/* 135/*
133 * List of flags we want to share for kernel threads, 136 * List of flags we want to share for kernel threads,
@@ -1076,6 +1079,7 @@ struct sched_entity {
1076#endif 1079#endif
1077 1080
1078#ifdef CONFIG_FAIR_GROUP_SCHED 1081#ifdef CONFIG_FAIR_GROUP_SCHED
1082 int depth;
1079 struct sched_entity *parent; 1083 struct sched_entity *parent;
1080 /* rq on which this entity is (to be) queued: */ 1084 /* rq on which this entity is (to be) queued: */
1081 struct cfs_rq *cfs_rq; 1085 struct cfs_rq *cfs_rq;
@@ -1459,6 +1463,9 @@ struct task_struct {
1459 struct mutex perf_event_mutex; 1463 struct mutex perf_event_mutex;
1460 struct list_head perf_event_list; 1464 struct list_head perf_event_list;
1461#endif 1465#endif
1466#ifdef CONFIG_DEBUG_PREEMPT
1467 unsigned long preempt_disable_ip;
1468#endif
1462#ifdef CONFIG_NUMA 1469#ifdef CONFIG_NUMA
1463 struct mempolicy *mempolicy; /* Protected by alloc_lock */ 1470 struct mempolicy *mempolicy; /* Protected by alloc_lock */
1464 short il_next; 1471 short il_next;
@@ -1469,9 +1476,10 @@ struct task_struct {
1469 unsigned int numa_scan_period; 1476 unsigned int numa_scan_period;
1470 unsigned int numa_scan_period_max; 1477 unsigned int numa_scan_period_max;
1471 int numa_preferred_nid; 1478 int numa_preferred_nid;
1472 int numa_migrate_deferred;
1473 unsigned long numa_migrate_retry; 1479 unsigned long numa_migrate_retry;
1474 u64 node_stamp; /* migration stamp */ 1480 u64 node_stamp; /* migration stamp */
1481 u64 last_task_numa_placement;
1482 u64 last_sum_exec_runtime;
1475 struct callback_head numa_work; 1483 struct callback_head numa_work;
1476 1484
1477 struct list_head numa_entry; 1485 struct list_head numa_entry;
@@ -1482,15 +1490,22 @@ struct task_struct {
1482 * Scheduling placement decisions are made based on the these counts. 1490 * Scheduling placement decisions are made based on the these counts.
1483 * The values remain static for the duration of a PTE scan 1491 * The values remain static for the duration of a PTE scan
1484 */ 1492 */
1485 unsigned long *numa_faults; 1493 unsigned long *numa_faults_memory;
1486 unsigned long total_numa_faults; 1494 unsigned long total_numa_faults;
1487 1495
1488 /* 1496 /*
1489 * numa_faults_buffer records faults per node during the current 1497 * numa_faults_buffer records faults per node during the current
1490 * scan window. When the scan completes, the counts in numa_faults 1498 * scan window. When the scan completes, the counts in
1491 * decay and these values are copied. 1499 * numa_faults_memory decay and these values are copied.
1500 */
1501 unsigned long *numa_faults_buffer_memory;
1502
1503 /*
1504 * Track the nodes the process was running on when a NUMA hinting
1505 * fault was incurred.
1492 */ 1506 */
1493 unsigned long *numa_faults_buffer; 1507 unsigned long *numa_faults_cpu;
1508 unsigned long *numa_faults_buffer_cpu;
1494 1509
1495 /* 1510 /*
1496 * numa_faults_locality tracks if faults recorded during the last 1511 * numa_faults_locality tracks if faults recorded during the last
@@ -1595,8 +1610,8 @@ extern void task_numa_fault(int last_node, int node, int pages, int flags);
1595extern pid_t task_numa_group_id(struct task_struct *p); 1610extern pid_t task_numa_group_id(struct task_struct *p);
1596extern void set_numabalancing_state(bool enabled); 1611extern void set_numabalancing_state(bool enabled);
1597extern void task_numa_free(struct task_struct *p); 1612extern void task_numa_free(struct task_struct *p);
1598 1613extern bool should_numa_migrate_memory(struct task_struct *p, struct page *page,
1599extern unsigned int sysctl_numa_balancing_migrate_deferred; 1614 int src_nid, int dst_cpu);
1600#else 1615#else
1601static inline void task_numa_fault(int last_node, int node, int pages, 1616static inline void task_numa_fault(int last_node, int node, int pages,
1602 int flags) 1617 int flags)
@@ -1612,6 +1627,11 @@ static inline void set_numabalancing_state(bool enabled)
1612static inline void task_numa_free(struct task_struct *p) 1627static inline void task_numa_free(struct task_struct *p)
1613{ 1628{
1614} 1629}
1630static inline bool should_numa_migrate_memory(struct task_struct *p,
1631 struct page *page, int src_nid, int dst_cpu)
1632{
1633 return true;
1634}
1615#endif 1635#endif
1616 1636
1617static inline struct pid *task_pid(struct task_struct *task) 1637static inline struct pid *task_pid(struct task_struct *task)
@@ -2079,7 +2099,16 @@ static inline void sched_autogroup_exit(struct signal_struct *sig) { }
2079extern bool yield_to(struct task_struct *p, bool preempt); 2099extern bool yield_to(struct task_struct *p, bool preempt);
2080extern void set_user_nice(struct task_struct *p, long nice); 2100extern void set_user_nice(struct task_struct *p, long nice);
2081extern int task_prio(const struct task_struct *p); 2101extern int task_prio(const struct task_struct *p);
2082extern int task_nice(const struct task_struct *p); 2102/**
2103 * task_nice - return the nice value of a given task.
2104 * @p: the task in question.
2105 *
2106 * Return: The nice value [ -20 ... 0 ... 19 ].
2107 */
2108static inline int task_nice(const struct task_struct *p)
2109{
2110 return PRIO_TO_NICE((p)->static_prio);
2111}
2083extern int can_nice(const struct task_struct *p, const int nice); 2112extern int can_nice(const struct task_struct *p, const int nice);
2084extern int task_curr(const struct task_struct *p); 2113extern int task_curr(const struct task_struct *p);
2085extern int idle_cpu(int cpu); 2114extern int idle_cpu(int cpu);
@@ -2311,7 +2340,7 @@ extern void do_group_exit(int);
2311extern int allow_signal(int); 2340extern int allow_signal(int);
2312extern int disallow_signal(int); 2341extern int disallow_signal(int);
2313 2342
2314extern int do_execve(const char *, 2343extern int do_execve(struct filename *,
2315 const char __user * const __user *, 2344 const char __user * const __user *,
2316 const char __user * const __user *); 2345 const char __user * const __user *);
2317extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *); 2346extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *);
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
new file mode 100644
index 000000000000..ac322583c820
--- /dev/null
+++ b/include/linux/sched/prio.h
@@ -0,0 +1,44 @@
1#ifndef _SCHED_PRIO_H
2#define _SCHED_PRIO_H
3
4#define MAX_NICE 19
5#define MIN_NICE -20
6#define NICE_WIDTH (MAX_NICE - MIN_NICE + 1)
7
8/*
9 * Priority of a process goes from 0..MAX_PRIO-1, valid RT
10 * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
11 * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
12 * values are inverted: lower p->prio value means higher priority.
13 *
14 * The MAX_USER_RT_PRIO value allows the actual maximum
15 * RT priority to be separate from the value exported to
16 * user-space. This allows kernel threads to set their
17 * priority to a value higher than any user task. Note:
18 * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
19 */
20
21#define MAX_USER_RT_PRIO 100
22#define MAX_RT_PRIO MAX_USER_RT_PRIO
23
24#define MAX_PRIO (MAX_RT_PRIO + NICE_WIDTH)
25#define DEFAULT_PRIO (MAX_RT_PRIO + NICE_WIDTH / 2)
26
27/*
28 * Convert user-nice values [ -20 ... 0 ... 19 ]
29 * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
30 * and back.
31 */
32#define NICE_TO_PRIO(nice) ((nice) + DEFAULT_PRIO)
33#define PRIO_TO_NICE(prio) ((prio) - DEFAULT_PRIO)
34
35/*
36 * 'User priority' is the nice value converted to something we
37 * can work with better when scaling various scheduler parameters,
38 * it's a [ 0 ... 39 ] range.
39 */
40#define USER_PRIO(p) ((p)-MAX_RT_PRIO)
41#define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio)
42#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO))
43
44#endif /* _SCHED_PRIO_H */
diff --git a/include/linux/sched/rt.h b/include/linux/sched/rt.h
index 34e4ebea8fce..6341f5be6e24 100644
--- a/include/linux/sched/rt.h
+++ b/include/linux/sched/rt.h
@@ -1,24 +1,7 @@
1#ifndef _SCHED_RT_H 1#ifndef _SCHED_RT_H
2#define _SCHED_RT_H 2#define _SCHED_RT_H
3 3
4/* 4#include <linux/sched/prio.h>
5 * Priority of a process goes from 0..MAX_PRIO-1, valid RT
6 * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
7 * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
8 * values are inverted: lower p->prio value means higher priority.
9 *
10 * The MAX_USER_RT_PRIO value allows the actual maximum
11 * RT priority to be separate from the value exported to
12 * user-space. This allows kernel threads to set their
13 * priority to a value higher than any user task. Note:
14 * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
15 */
16
17#define MAX_USER_RT_PRIO 100
18#define MAX_RT_PRIO MAX_USER_RT_PRIO
19
20#define MAX_PRIO (MAX_RT_PRIO + 40)
21#define DEFAULT_PRIO (MAX_RT_PRIO + 20)
22 5
23static inline int rt_prio(int prio) 6static inline int rt_prio(int prio)
24{ 7{
@@ -35,6 +18,7 @@ static inline int rt_task(struct task_struct *p)
35#ifdef CONFIG_RT_MUTEXES 18#ifdef CONFIG_RT_MUTEXES
36extern int rt_mutex_getprio(struct task_struct *p); 19extern int rt_mutex_getprio(struct task_struct *p);
37extern void rt_mutex_setprio(struct task_struct *p, int prio); 20extern void rt_mutex_setprio(struct task_struct *p, int prio);
21extern int rt_mutex_check_prio(struct task_struct *task, int newprio);
38extern struct task_struct *rt_mutex_get_top_task(struct task_struct *task); 22extern struct task_struct *rt_mutex_get_top_task(struct task_struct *task);
39extern void rt_mutex_adjust_pi(struct task_struct *p); 23extern void rt_mutex_adjust_pi(struct task_struct *p);
40static inline bool tsk_is_pi_blocked(struct task_struct *tsk) 24static inline bool tsk_is_pi_blocked(struct task_struct *tsk)
@@ -46,6 +30,12 @@ static inline int rt_mutex_getprio(struct task_struct *p)
46{ 30{
47 return p->normal_prio; 31 return p->normal_prio;
48} 32}
33
34static inline int rt_mutex_check_prio(struct task_struct *task, int newprio)
35{
36 return 0;
37}
38
49static inline struct task_struct *rt_mutex_get_top_task(struct task_struct *task) 39static inline struct task_struct *rt_mutex_get_top_task(struct task_struct *task)
50{ 40{
51 return NULL; 41 return NULL;
diff --git a/include/linux/security.h b/include/linux/security.h
index 5623a7f965b7..2fc42d191f79 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -1040,6 +1040,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
1040 * Allocate a security structure to the xp->security field; the security 1040 * Allocate a security structure to the xp->security field; the security
1041 * field is initialized to NULL when the xfrm_policy is allocated. 1041 * field is initialized to NULL when the xfrm_policy is allocated.
1042 * Return 0 if operation was successful (memory to allocate, legal context) 1042 * Return 0 if operation was successful (memory to allocate, legal context)
1043 * @gfp is to specify the context for the allocation
1043 * @xfrm_policy_clone_security: 1044 * @xfrm_policy_clone_security:
1044 * @old_ctx contains an existing xfrm_sec_ctx. 1045 * @old_ctx contains an existing xfrm_sec_ctx.
1045 * @new_ctxp contains a new xfrm_sec_ctx being cloned from old. 1046 * @new_ctxp contains a new xfrm_sec_ctx being cloned from old.
@@ -1683,7 +1684,7 @@ struct security_operations {
1683 1684
1684#ifdef CONFIG_SECURITY_NETWORK_XFRM 1685#ifdef CONFIG_SECURITY_NETWORK_XFRM
1685 int (*xfrm_policy_alloc_security) (struct xfrm_sec_ctx **ctxp, 1686 int (*xfrm_policy_alloc_security) (struct xfrm_sec_ctx **ctxp,
1686 struct xfrm_user_sec_ctx *sec_ctx); 1687 struct xfrm_user_sec_ctx *sec_ctx, gfp_t gfp);
1687 int (*xfrm_policy_clone_security) (struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctx); 1688 int (*xfrm_policy_clone_security) (struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctx);
1688 void (*xfrm_policy_free_security) (struct xfrm_sec_ctx *ctx); 1689 void (*xfrm_policy_free_security) (struct xfrm_sec_ctx *ctx);
1689 int (*xfrm_policy_delete_security) (struct xfrm_sec_ctx *ctx); 1690 int (*xfrm_policy_delete_security) (struct xfrm_sec_ctx *ctx);
@@ -2859,7 +2860,8 @@ static inline void security_skb_owned_by(struct sk_buff *skb, struct sock *sk)
2859 2860
2860#ifdef CONFIG_SECURITY_NETWORK_XFRM 2861#ifdef CONFIG_SECURITY_NETWORK_XFRM
2861 2862
2862int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx); 2863int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
2864 struct xfrm_user_sec_ctx *sec_ctx, gfp_t gfp);
2863int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctxp); 2865int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctxp);
2864void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx); 2866void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
2865int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx); 2867int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
@@ -2877,7 +2879,9 @@ void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl);
2877 2879
2878#else /* CONFIG_SECURITY_NETWORK_XFRM */ 2880#else /* CONFIG_SECURITY_NETWORK_XFRM */
2879 2881
2880static inline int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx) 2882static inline int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
2883 struct xfrm_user_sec_ctx *sec_ctx,
2884 gfp_t gfp)
2881{ 2885{
2882 return 0; 2886 return 0;
2883} 2887}
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index f589c9af8cbf..15ede6a823a6 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2451,8 +2451,8 @@ int skb_splice_bits(struct sk_buff *skb, unsigned int offset,
2451 unsigned int flags); 2451 unsigned int flags);
2452void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to); 2452void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to);
2453unsigned int skb_zerocopy_headlen(const struct sk_buff *from); 2453unsigned int skb_zerocopy_headlen(const struct sk_buff *from);
2454void skb_zerocopy(struct sk_buff *to, const struct sk_buff *from, 2454int skb_zerocopy(struct sk_buff *to, struct sk_buff *from,
2455 int len, int hlen); 2455 int len, int hlen);
2456void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len); 2456void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len);
2457int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen); 2457int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen);
2458void skb_scrub_packet(struct sk_buff *skb, bool xnet); 2458void skb_scrub_packet(struct sk_buff *skb, bool xnet);
@@ -2725,7 +2725,7 @@ static inline void nf_reset(struct sk_buff *skb)
2725 2725
2726static inline void nf_reset_trace(struct sk_buff *skb) 2726static inline void nf_reset_trace(struct sk_buff *skb)
2727{ 2727{
2728#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE) 2728#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE) || defined(CONFIG_NF_TABLES)
2729 skb->nf_trace = 0; 2729 skb->nf_trace = 0;
2730#endif 2730#endif
2731} 2731}
@@ -2742,6 +2742,9 @@ static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src)
2742 dst->nf_bridge = src->nf_bridge; 2742 dst->nf_bridge = src->nf_bridge;
2743 nf_bridge_get(src->nf_bridge); 2743 nf_bridge_get(src->nf_bridge);
2744#endif 2744#endif
2745#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE) || defined(CONFIG_NF_TABLES)
2746 dst->nf_trace = src->nf_trace;
2747#endif
2745} 2748}
2746 2749
2747static inline void nf_copy(struct sk_buff *dst, const struct sk_buff *src) 2750static inline void nf_copy(struct sk_buff *dst, const struct sk_buff *src)
@@ -2916,5 +2919,22 @@ static inline bool skb_head_is_locked(const struct sk_buff *skb)
2916{ 2919{
2917 return !skb->head_frag || skb_cloned(skb); 2920 return !skb->head_frag || skb_cloned(skb);
2918} 2921}
2922
2923/**
2924 * skb_gso_network_seglen - Return length of individual segments of a gso packet
2925 *
2926 * @skb: GSO skb
2927 *
2928 * skb_gso_network_seglen is used to determine the real size of the
2929 * individual segments, including Layer3 (IP, IPv6) and L4 headers (TCP/UDP).
2930 *
2931 * The MAC/L2 header is not accounted for.
2932 */
2933static inline unsigned int skb_gso_network_seglen(const struct sk_buff *skb)
2934{
2935 unsigned int hdr_len = skb_transport_header(skb) -
2936 skb_network_header(skb);
2937 return hdr_len + skb_gso_transport_seglen(skb);
2938}
2919#endif /* __KERNEL__ */ 2939#endif /* __KERNEL__ */
2920#endif /* _LINUX_SKBUFF_H */ 2940#endif /* _LINUX_SKBUFF_H */
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 9260abdd67df..b5b2df60299e 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -410,7 +410,7 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
410 * 410 *
411 * %GFP_NOWAIT - Allocation will not sleep. 411 * %GFP_NOWAIT - Allocation will not sleep.
412 * 412 *
413 * %GFP_THISNODE - Allocate node-local memory only. 413 * %__GFP_THISNODE - Allocate node-local memory only.
414 * 414 *
415 * %GFP_DMA - Allocation suitable for DMA. 415 * %GFP_DMA - Allocation suitable for DMA.
416 * Should only be used for kmalloc() caches. Otherwise, use a 416 * Should only be used for kmalloc() caches. Otherwise, use a
diff --git a/include/linux/smp.h b/include/linux/smp.h
index 3834f43f9993..6ae004e437ea 100644
--- a/include/linux/smp.h
+++ b/include/linux/smp.h
@@ -188,6 +188,9 @@ static inline void kick_all_cpus_sync(void) { }
188 */ 188 */
189extern void arch_disable_smp_support(void); 189extern void arch_disable_smp_support(void);
190 190
191extern void arch_enable_nonboot_cpus_begin(void);
192extern void arch_enable_nonboot_cpus_end(void);
193
191void smp_setup_processor_id(void); 194void smp_setup_processor_id(void);
192 195
193#endif /* __LINUX_SMP_H */ 196#endif /* __LINUX_SMP_H */
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index a1d4ca290862..4203c66d8803 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -273,7 +273,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
273 * message while queuing transfers that arrive in the meantime. When the 273 * message while queuing transfers that arrive in the meantime. When the
274 * driver is finished with this message, it must call 274 * driver is finished with this message, it must call
275 * spi_finalize_current_message() so the subsystem can issue the next 275 * spi_finalize_current_message() so the subsystem can issue the next
276 * transfer 276 * message
277 * @unprepare_transfer_hardware: there are currently no more messages on the 277 * @unprepare_transfer_hardware: there are currently no more messages on the
278 * queue so the subsystem notifies the driver that it may relax the 278 * queue so the subsystem notifies the driver that it may relax the
279 * hardware by issuing this call 279 * hardware by issuing this call
@@ -287,7 +287,10 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
287 * - return 1 if the transfer is still in progress. When 287 * - return 1 if the transfer is still in progress. When
288 * the driver is finished with this transfer it must 288 * the driver is finished with this transfer it must
289 * call spi_finalize_current_transfer() so the subsystem 289 * call spi_finalize_current_transfer() so the subsystem
290 * can issue the next transfer 290 * can issue the next transfer. Note: transfer_one and
291 * transfer_one_message are mutually exclusive; when both
292 * are set, the generic subsystem does not call your
293 * transfer_one callback.
291 * @unprepare_message: undo any work done by prepare_message(). 294 * @unprepare_message: undo any work done by prepare_message().
292 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS 295 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
293 * number. Any individual value may be -ENOENT for CS lines that 296 * number. Any individual value may be -ENOENT for CS lines that
diff --git a/include/linux/srcu.h b/include/linux/srcu.h
index 9b058eecd403..a2783cb5d275 100644
--- a/include/linux/srcu.h
+++ b/include/linux/srcu.h
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright (C) IBM Corporation, 2006 18 * Copyright (C) IBM Corporation, 2006
19 * Copyright (C) Fujitsu, 2012 19 * Copyright (C) Fujitsu, 2012
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 40ed9e9a77e5..1e67b7a5968c 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -98,6 +98,8 @@ struct sigaltstack;
98#define __MAP(n,...) __MAP##n(__VA_ARGS__) 98#define __MAP(n,...) __MAP##n(__VA_ARGS__)
99 99
100#define __SC_DECL(t, a) t a 100#define __SC_DECL(t, a) t a
101#define __TYPE_IS_L(t) (__same_type((t)0, 0L))
102#define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
101#define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL)) 103#define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
102#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a 104#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
103#define __SC_CAST(t, a) (t) a 105#define __SC_CAST(t, a) (t) a
@@ -281,13 +283,15 @@ asmlinkage long sys_sched_setscheduler(pid_t pid, int policy,
281asmlinkage long sys_sched_setparam(pid_t pid, 283asmlinkage long sys_sched_setparam(pid_t pid,
282 struct sched_param __user *param); 284 struct sched_param __user *param);
283asmlinkage long sys_sched_setattr(pid_t pid, 285asmlinkage long sys_sched_setattr(pid_t pid,
284 struct sched_attr __user *attr); 286 struct sched_attr __user *attr,
287 unsigned int flags);
285asmlinkage long sys_sched_getscheduler(pid_t pid); 288asmlinkage long sys_sched_getscheduler(pid_t pid);
286asmlinkage long sys_sched_getparam(pid_t pid, 289asmlinkage long sys_sched_getparam(pid_t pid,
287 struct sched_param __user *param); 290 struct sched_param __user *param);
288asmlinkage long sys_sched_getattr(pid_t pid, 291asmlinkage long sys_sched_getattr(pid_t pid,
289 struct sched_attr __user *attr, 292 struct sched_attr __user *attr,
290 unsigned int size); 293 unsigned int size,
294 unsigned int flags);
291asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len, 295asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
292 unsigned long __user *user_mask_ptr); 296 unsigned long __user *user_mask_ptr);
293asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len, 297asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,
diff --git a/include/linux/torture.h b/include/linux/torture.h
new file mode 100644
index 000000000000..b2e2b468e511
--- /dev/null
+++ b/include/linux/torture.h
@@ -0,0 +1,100 @@
1/*
2 * Common functions for in-kernel torture tests.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 *
18 * Copyright IBM Corporation, 2014
19 *
20 * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
21 */
22
23#ifndef __LINUX_TORTURE_H
24#define __LINUX_TORTURE_H
25
26#include <linux/types.h>
27#include <linux/cache.h>
28#include <linux/spinlock.h>
29#include <linux/threads.h>
30#include <linux/cpumask.h>
31#include <linux/seqlock.h>
32#include <linux/lockdep.h>
33#include <linux/completion.h>
34#include <linux/debugobjects.h>
35#include <linux/bug.h>
36#include <linux/compiler.h>
37
38/* Definitions for a non-string torture-test module parameter. */
39#define torture_param(type, name, init, msg) \
40 static type name = init; \
41 module_param(name, type, 0444); \
42 MODULE_PARM_DESC(name, msg);
43
44#define TORTURE_FLAG "-torture:"
45#define TOROUT_STRING(s) \
46 pr_alert("%s" TORTURE_FLAG s "\n", torture_type)
47#define VERBOSE_TOROUT_STRING(s) \
48 do { if (verbose) pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); } while (0)
49#define VERBOSE_TOROUT_ERRSTRING(s) \
50 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); } while (0)
51
52/* Definitions for a non-string torture-test module parameter. */
53#define torture_parm(type, name, init, msg) \
54 static type name = init; \
55 module_param(name, type, 0444); \
56 MODULE_PARM_DESC(name, msg);
57
58/* Definitions for online/offline exerciser. */
59int torture_onoff_init(long ooholdoff, long oointerval);
60char *torture_onoff_stats(char *page);
61bool torture_onoff_failures(void);
62
63/* Low-rider random number generator. */
64struct torture_random_state {
65 unsigned long trs_state;
66 long trs_count;
67};
68#define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 }
69unsigned long torture_random(struct torture_random_state *trsp);
70
71/* Task shuffler, which causes CPUs to occasionally go idle. */
72void torture_shuffle_task_register(struct task_struct *tp);
73int torture_shuffle_init(long shuffint);
74
75/* Test auto-shutdown handling. */
76void torture_shutdown_absorb(const char *title);
77int torture_shutdown_init(int ssecs, void (*cleanup)(void));
78
79/* Task stuttering, which forces load/no-load transitions. */
80void stutter_wait(const char *title);
81int torture_stutter_init(int s);
82
83/* Initialization and cleanup. */
84void torture_init_begin(char *ttype, bool v, int *runnable);
85void torture_init_end(void);
86bool torture_cleanup(void);
87bool torture_must_stop(void);
88bool torture_must_stop_irq(void);
89void torture_kthread_stopping(char *title);
90int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
91 char *f, struct task_struct **tp);
92void _torture_stop_kthread(char *m, struct task_struct **tp);
93
94#define torture_create_kthread(n, arg, tp) \
95 _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \
96 "Failed to create " #n, &(tp))
97#define torture_stop_kthread(n, tp) \
98 _torture_stop_kthread("Stopping " #n " task", &(tp))
99
100#endif /* __LINUX_TORTURE_H */
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index accc497f8d72..7159a0a933df 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -60,6 +60,12 @@ struct tp_module {
60 unsigned int num_tracepoints; 60 unsigned int num_tracepoints;
61 struct tracepoint * const *tracepoints_ptrs; 61 struct tracepoint * const *tracepoints_ptrs;
62}; 62};
63bool trace_module_has_bad_taint(struct module *mod);
64#else
65static inline bool trace_module_has_bad_taint(struct module *mod)
66{
67 return false;
68}
63#endif /* CONFIG_MODULES */ 69#endif /* CONFIG_MODULES */
64 70
65struct tracepoint_iter { 71struct tracepoint_iter {
diff --git a/include/linux/usb.h b/include/linux/usb.h
index c716da18c668..7f6eb859873e 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -1265,8 +1265,6 @@ typedef void (*usb_complete_t)(struct urb *);
1265 * @sg: scatter gather buffer list, the buffer size of each element in 1265 * @sg: scatter gather buffer list, the buffer size of each element in
1266 * the list (except the last) must be divisible by the endpoint's 1266 * the list (except the last) must be divisible by the endpoint's
1267 * max packet size if no_sg_constraint isn't set in 'struct usb_bus' 1267 * max packet size if no_sg_constraint isn't set in 'struct usb_bus'
1268 * (FIXME: scatter-gather under xHCI is broken for periodic transfers.
1269 * Do not use urb->sg for interrupt endpoints for now, only bulk.)
1270 * @num_mapped_sgs: (internal) number of mapped sg entries 1268 * @num_mapped_sgs: (internal) number of mapped sg entries
1271 * @num_sgs: number of entries in the sg list 1269 * @num_sgs: number of entries in the sg list
1272 * @transfer_buffer_length: How big is transfer_buffer. The transfer may 1270 * @transfer_buffer_length: How big is transfer_buffer. The transfer may
diff --git a/include/linux/usb/cdc_ncm.h b/include/linux/usb/cdc_ncm.h
index c3fa80745996..2c14d9cdd57a 100644
--- a/include/linux/usb/cdc_ncm.h
+++ b/include/linux/usb/cdc_ncm.h
@@ -88,6 +88,7 @@
88#define cdc_ncm_data_intf_is_mbim(x) ((x)->desc.bInterfaceProtocol == USB_CDC_MBIM_PROTO_NTB) 88#define cdc_ncm_data_intf_is_mbim(x) ((x)->desc.bInterfaceProtocol == USB_CDC_MBIM_PROTO_NTB)
89 89
90struct cdc_ncm_ctx { 90struct cdc_ncm_ctx {
91 struct usb_cdc_ncm_ntb_parameters ncm_parm;
91 struct hrtimer tx_timer; 92 struct hrtimer tx_timer;
92 struct tasklet_struct bh; 93 struct tasklet_struct bh;
93 94
diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
index e303eef94dd5..0662e98fef72 100644
--- a/include/linux/usb/usbnet.h
+++ b/include/linux/usb/usbnet.h
@@ -30,7 +30,7 @@ struct usbnet {
30 struct driver_info *driver_info; 30 struct driver_info *driver_info;
31 const char *driver_name; 31 const char *driver_name;
32 void *driver_priv; 32 void *driver_priv;
33 wait_queue_head_t *wait; 33 wait_queue_head_t wait;
34 struct mutex phy_mutex; 34 struct mutex phy_mutex;
35 unsigned char suspend_count; 35 unsigned char suspend_count;
36 unsigned char pkt_cnt, pkt_err; 36 unsigned char pkt_cnt, pkt_err;
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index c557c6d096de..3a712e2e7d76 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -71,12 +71,14 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
71 THP_ZERO_PAGE_ALLOC, 71 THP_ZERO_PAGE_ALLOC,
72 THP_ZERO_PAGE_ALLOC_FAILED, 72 THP_ZERO_PAGE_ALLOC_FAILED,
73#endif 73#endif
74#ifdef CONFIG_DEBUG_TLBFLUSH
74#ifdef CONFIG_SMP 75#ifdef CONFIG_SMP
75 NR_TLB_REMOTE_FLUSH, /* cpu tried to flush others' tlbs */ 76 NR_TLB_REMOTE_FLUSH, /* cpu tried to flush others' tlbs */
76 NR_TLB_REMOTE_FLUSH_RECEIVED,/* cpu received ipi for flush */ 77 NR_TLB_REMOTE_FLUSH_RECEIVED,/* cpu received ipi for flush */
77#endif 78#endif /* CONFIG_SMP */
78 NR_TLB_LOCAL_FLUSH_ALL, 79 NR_TLB_LOCAL_FLUSH_ALL,
79 NR_TLB_LOCAL_FLUSH_ONE, 80 NR_TLB_LOCAL_FLUSH_ONE,
81#endif /* CONFIG_DEBUG_TLBFLUSH */
80 NR_VM_EVENT_ITEMS 82 NR_VM_EVENT_ITEMS
81}; 83};
82 84
diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index a67b38415768..67ce70c8279b 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -83,6 +83,14 @@ static inline void vm_events_fold_cpu(int cpu)
83#define count_vm_numa_events(x, y) do { (void)(y); } while (0) 83#define count_vm_numa_events(x, y) do { (void)(y); } while (0)
84#endif /* CONFIG_NUMA_BALANCING */ 84#endif /* CONFIG_NUMA_BALANCING */
85 85
86#ifdef CONFIG_DEBUG_TLBFLUSH
87#define count_vm_tlb_event(x) count_vm_event(x)
88#define count_vm_tlb_events(x, y) count_vm_events(x, y)
89#else
90#define count_vm_tlb_event(x) do {} while (0)
91#define count_vm_tlb_events(x, y) do { (void)(y); } while (0)
92#endif
93
86#define __count_zone_vm_events(item, zone, delta) \ 94#define __count_zone_vm_events(item, zone, delta) \
87 __count_vm_events(item##_NORMAL - ZONE_NORMAL + \ 95 __count_vm_events(item##_NORMAL - ZONE_NORMAL + \
88 zone_idx(zone), delta) 96 zone_idx(zone), delta)
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 594521ba0d43..532994651684 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -177,17 +177,6 @@ struct execute_work {
177#define DECLARE_DEFERRABLE_WORK(n, f) \ 177#define DECLARE_DEFERRABLE_WORK(n, f) \
178 struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, TIMER_DEFERRABLE) 178 struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, TIMER_DEFERRABLE)
179 179
180/*
181 * initialize a work item's function pointer
182 */
183#define PREPARE_WORK(_work, _func) \
184 do { \
185 (_work)->func = (_func); \
186 } while (0)
187
188#define PREPARE_DELAYED_WORK(_work, _func) \
189 PREPARE_WORK(&(_work)->work, (_func))
190
191#ifdef CONFIG_DEBUG_OBJECTS_WORK 180#ifdef CONFIG_DEBUG_OBJECTS_WORK
192extern void __init_work(struct work_struct *work, int onstack); 181extern void __init_work(struct work_struct *work, int onstack);
193extern void destroy_work_on_stack(struct work_struct *work); 182extern void destroy_work_on_stack(struct work_struct *work);
@@ -217,7 +206,7 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
217 (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \ 206 (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
218 lockdep_init_map(&(_work)->lockdep_map, #_work, &__key, 0); \ 207 lockdep_init_map(&(_work)->lockdep_map, #_work, &__key, 0); \
219 INIT_LIST_HEAD(&(_work)->entry); \ 208 INIT_LIST_HEAD(&(_work)->entry); \
220 PREPARE_WORK((_work), (_func)); \ 209 (_work)->func = (_func); \
221 } while (0) 210 } while (0)
222#else 211#else
223#define __INIT_WORK(_work, _func, _onstack) \ 212#define __INIT_WORK(_work, _func, _onstack) \
@@ -225,7 +214,7 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
225 __init_work((_work), _onstack); \ 214 __init_work((_work), _onstack); \
226 (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \ 215 (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
227 INIT_LIST_HEAD(&(_work)->entry); \ 216 INIT_LIST_HEAD(&(_work)->entry); \
228 PREPARE_WORK((_work), (_func)); \ 217 (_work)->func = (_func); \
229 } while (0) 218 } while (0)
230#endif 219#endif
231 220
@@ -295,17 +284,11 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
295 * Documentation/workqueue.txt. 284 * Documentation/workqueue.txt.
296 */ 285 */
297enum { 286enum {
298 /*
299 * All wqs are now non-reentrant making the following flag
300 * meaningless. Will be removed.
301 */
302 WQ_NON_REENTRANT = 1 << 0, /* DEPRECATED */
303
304 WQ_UNBOUND = 1 << 1, /* not bound to any cpu */ 287 WQ_UNBOUND = 1 << 1, /* not bound to any cpu */
305 WQ_FREEZABLE = 1 << 2, /* freeze during suspend */ 288 WQ_FREEZABLE = 1 << 2, /* freeze during suspend */
306 WQ_MEM_RECLAIM = 1 << 3, /* may be used for memory reclaim */ 289 WQ_MEM_RECLAIM = 1 << 3, /* may be used for memory reclaim */
307 WQ_HIGHPRI = 1 << 4, /* high priority */ 290 WQ_HIGHPRI = 1 << 4, /* high priority */
308 WQ_CPU_INTENSIVE = 1 << 5, /* cpu instensive workqueue */ 291 WQ_CPU_INTENSIVE = 1 << 5, /* cpu intensive workqueue */
309 WQ_SYSFS = 1 << 6, /* visible in sysfs, see wq_sysfs_register() */ 292 WQ_SYSFS = 1 << 6, /* visible in sysfs, see wq_sysfs_register() */
310 293
311 /* 294 /*
@@ -419,10 +402,7 @@ __alloc_workqueue_key(const char *fmt, unsigned int flags, int max_active,
419 static struct lock_class_key __key; \ 402 static struct lock_class_key __key; \
420 const char *__lock_name; \ 403 const char *__lock_name; \
421 \ 404 \
422 if (__builtin_constant_p(fmt)) \ 405 __lock_name = #fmt#args; \
423 __lock_name = (fmt); \
424 else \
425 __lock_name = #fmt; \
426 \ 406 \
427 __alloc_workqueue_key((fmt), (flags), (max_active), \ 407 __alloc_workqueue_key((fmt), (flags), (max_active), \
428 &__key, __lock_name, ##args); \ 408 &__key, __lock_name, ##args); \
@@ -605,21 +585,6 @@ static inline bool keventd_up(void)
605 return system_wq != NULL; 585 return system_wq != NULL;
606} 586}
607 587
608/*
609 * Like above, but uses del_timer() instead of del_timer_sync(). This means,
610 * if it returns 0 the timer function may be running and the queueing is in
611 * progress.
612 */
613static inline bool __deprecated __cancel_delayed_work(struct delayed_work *work)
614{
615 bool ret;
616
617 ret = del_timer(&work->timer);
618 if (ret)
619 work_clear_pending(&work->work);
620 return ret;
621}
622
623/* used to be different but now identical to flush_work(), deprecated */ 588/* used to be different but now identical to flush_work(), deprecated */
624static inline bool __deprecated flush_work_sync(struct work_struct *work) 589static inline bool __deprecated flush_work_sync(struct work_struct *work)
625{ 590{
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index fc0e4320aa6d..021b8a319b9e 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -97,7 +97,7 @@ void writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
97int try_to_writeback_inodes_sb(struct super_block *, enum wb_reason reason); 97int try_to_writeback_inodes_sb(struct super_block *, enum wb_reason reason);
98int try_to_writeback_inodes_sb_nr(struct super_block *, unsigned long nr, 98int try_to_writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
99 enum wb_reason reason); 99 enum wb_reason reason);
100void sync_inodes_sb(struct super_block *sb, unsigned long older_than_this); 100void sync_inodes_sb(struct super_block *);
101void wakeup_flusher_threads(long nr_pages, enum wb_reason reason); 101void wakeup_flusher_threads(long nr_pages, enum wb_reason reason);
102void inode_wait_for_writeback(struct inode *inode); 102void inode_wait_for_writeback(struct inode *inode);
103 103
diff --git a/include/net/datalink.h b/include/net/datalink.h
index deb7ca75db48..93cb18f729b5 100644
--- a/include/net/datalink.h
+++ b/include/net/datalink.h
@@ -15,4 +15,6 @@ struct datalink_proto {
15 struct list_head node; 15 struct list_head node;
16}; 16};
17 17
18struct datalink_proto *make_EII_client(void);
19void destroy_EII_client(struct datalink_proto *dl);
18#endif 20#endif
diff --git a/include/net/dn.h b/include/net/dn.h
index ccc15588d108..913b73d239f5 100644
--- a/include/net/dn.h
+++ b/include/net/dn.h
@@ -200,6 +200,8 @@ static inline void dn_sk_ports_copy(struct flowidn *fld, struct dn_scp *scp)
200} 200}
201 201
202unsigned int dn_mss_from_pmtu(struct net_device *dev, int mtu); 202unsigned int dn_mss_from_pmtu(struct net_device *dev, int mtu);
203void dn_register_sysctl(void);
204void dn_unregister_sysctl(void);
203 205
204#define DN_MENUVER_ACC 0x01 206#define DN_MENUVER_ACC 0x01
205#define DN_MENUVER_USR 0x02 207#define DN_MENUVER_USR 0x02
diff --git a/include/net/dn_route.h b/include/net/dn_route.h
index b409ad6b8d7a..55df9939bca2 100644
--- a/include/net/dn_route.h
+++ b/include/net/dn_route.h
@@ -20,6 +20,8 @@ int dn_route_output_sock(struct dst_entry __rcu **pprt, struct flowidn *,
20 struct sock *sk, int flags); 20 struct sock *sk, int flags);
21int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb); 21int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb);
22void dn_rt_cache_flush(int delay); 22void dn_rt_cache_flush(int delay);
23int dn_route_rcv(struct sk_buff *skb, struct net_device *dev,
24 struct packet_type *pt, struct net_device *orig_dev);
23 25
24/* Masks for flags field */ 26/* Masks for flags field */
25#define DN_RT_F_PID 0x07 /* Mask for packet type */ 27#define DN_RT_F_PID 0x07 /* Mask for packet type */
diff --git a/include/net/ethoc.h b/include/net/ethoc.h
index 96f3789b27bc..2a2d6bb34eb8 100644
--- a/include/net/ethoc.h
+++ b/include/net/ethoc.h
@@ -16,6 +16,7 @@
16struct ethoc_platform_data { 16struct ethoc_platform_data {
17 u8 hwaddr[IFHWADDRLEN]; 17 u8 hwaddr[IFHWADDRLEN];
18 s8 phy_id; 18 s8 phy_id;
19 u32 eth_clkfreq;
19}; 20};
20 21
21#endif /* !LINUX_NET_ETHOC_H */ 22#endif /* !LINUX_NET_ETHOC_H */
diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
index 9650a3ffd2d2..b4956a5fcc3f 100644
--- a/include/net/if_inet6.h
+++ b/include/net/if_inet6.h
@@ -31,8 +31,10 @@
31#define IF_PREFIX_AUTOCONF 0x02 31#define IF_PREFIX_AUTOCONF 0x02
32 32
33enum { 33enum {
34 INET6_IFADDR_STATE_PREDAD,
34 INET6_IFADDR_STATE_DAD, 35 INET6_IFADDR_STATE_DAD,
35 INET6_IFADDR_STATE_POSTDAD, 36 INET6_IFADDR_STATE_POSTDAD,
37 INET6_IFADDR_STATE_ERRDAD,
36 INET6_IFADDR_STATE_UP, 38 INET6_IFADDR_STATE_UP,
37 INET6_IFADDR_STATE_DEAD, 39 INET6_IFADDR_STATE_DEAD,
38}; 40};
@@ -58,7 +60,7 @@ struct inet6_ifaddr {
58 unsigned long cstamp; /* created timestamp */ 60 unsigned long cstamp; /* created timestamp */
59 unsigned long tstamp; /* updated timestamp */ 61 unsigned long tstamp; /* updated timestamp */
60 62
61 struct timer_list dad_timer; 63 struct delayed_work dad_work;
62 64
63 struct inet6_dev *idev; 65 struct inet6_dev *idev;
64 struct rt6_info *rt; 66 struct rt6_info *rt;
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 48ed75c21260..e77c10405d51 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -129,6 +129,7 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[],
129int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], 129int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
130 struct ip_tunnel_parm *p); 130 struct ip_tunnel_parm *p);
131void ip_tunnel_setup(struct net_device *dev, int net_id); 131void ip_tunnel_setup(struct net_device *dev, int net_id);
132void ip_tunnel_dst_reset_all(struct ip_tunnel *t);
132 133
133/* Extract dsfield from inner protocol */ 134/* Extract dsfield from inner protocol */
134static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph, 135static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph,
diff --git a/include/net/ipx.h b/include/net/ipx.h
index 9e9e35465baf..0143180fecc9 100644
--- a/include/net/ipx.h
+++ b/include/net/ipx.h
@@ -140,6 +140,17 @@ static __inline__ void ipxitf_hold(struct ipx_interface *intrfc)
140} 140}
141 141
142void ipxitf_down(struct ipx_interface *intrfc); 142void ipxitf_down(struct ipx_interface *intrfc);
143struct ipx_interface *ipxitf_find_using_net(__be32 net);
144int ipxitf_send(struct ipx_interface *intrfc, struct sk_buff *skb, char *node);
145__be16 ipx_cksum(struct ipxhdr *packet, int length);
146int ipxrtr_add_route(__be32 network, struct ipx_interface *intrfc,
147 unsigned char *node);
148void ipxrtr_del_routes(struct ipx_interface *intrfc);
149int ipxrtr_route_packet(struct sock *sk, struct sockaddr_ipx *usipx,
150 struct iovec *iov, size_t len, int noblock);
151int ipxrtr_route_skb(struct sk_buff *skb);
152struct ipx_route *ipxrtr_lookup(__be32 net);
153int ipxrtr_ioctl(unsigned int cmd, void __user *arg);
143 154
144static __inline__ void ipxitf_put(struct ipx_interface *intrfc) 155static __inline__ void ipxitf_put(struct ipx_interface *intrfc)
145{ 156{
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index da68c9a90ac5..991dcd94cbbf 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -162,6 +162,14 @@ extern struct list_head net_namespace_list;
162struct net *get_net_ns_by_pid(pid_t pid); 162struct net *get_net_ns_by_pid(pid_t pid);
163struct net *get_net_ns_by_fd(int pid); 163struct net *get_net_ns_by_fd(int pid);
164 164
165#ifdef CONFIG_SYSCTL
166void ipx_register_sysctl(void);
167void ipx_unregister_sysctl(void);
168#else
169#define ipx_register_sysctl()
170#define ipx_unregister_sysctl()
171#endif
172
165#ifdef CONFIG_NET_NS 173#ifdef CONFIG_NET_NS
166void __put_net(struct net *net); 174void __put_net(struct net *net);
167 175
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index 01ea6eed1bb1..b2ac6246b7e0 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -284,6 +284,8 @@ extern unsigned int nf_conntrack_max;
284extern unsigned int nf_conntrack_hash_rnd; 284extern unsigned int nf_conntrack_hash_rnd;
285void init_nf_conntrack_hash_rnd(void); 285void init_nf_conntrack_hash_rnd(void);
286 286
287void nf_conntrack_tmpl_insert(struct net *net, struct nf_conn *tmpl);
288
287#define NF_CT_STAT_INC(net, count) __this_cpu_inc((net)->ct.stat->count) 289#define NF_CT_STAT_INC(net, count) __this_cpu_inc((net)->ct.stat->count)
288#define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count) 290#define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count)
289 291
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index 57c8ff7955df..e7e14ffe0f6a 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -252,6 +252,7 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
252 * @owner: module reference 252 * @owner: module reference
253 * @policy: netlink attribute policy 253 * @policy: netlink attribute policy
254 * @maxattr: highest netlink attribute number 254 * @maxattr: highest netlink attribute number
255 * @family: address family for AF-specific types
255 */ 256 */
256struct nft_expr_type { 257struct nft_expr_type {
257 const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *, 258 const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *,
@@ -262,6 +263,7 @@ struct nft_expr_type {
262 struct module *owner; 263 struct module *owner;
263 const struct nla_policy *policy; 264 const struct nla_policy *policy;
264 unsigned int maxattr; 265 unsigned int maxattr;
266 u8 family;
265}; 267};
266 268
267/** 269/**
@@ -320,7 +322,6 @@ static inline void *nft_expr_priv(const struct nft_expr *expr)
320 * struct nft_rule - nf_tables rule 322 * struct nft_rule - nf_tables rule
321 * 323 *
322 * @list: used internally 324 * @list: used internally
323 * @rcu_head: used internally for rcu
324 * @handle: rule handle 325 * @handle: rule handle
325 * @genmask: generation mask 326 * @genmask: generation mask
326 * @dlen: length of expression data 327 * @dlen: length of expression data
@@ -328,7 +329,6 @@ static inline void *nft_expr_priv(const struct nft_expr *expr)
328 */ 329 */
329struct nft_rule { 330struct nft_rule {
330 struct list_head list; 331 struct list_head list;
331 struct rcu_head rcu_head;
332 u64 handle:46, 332 u64 handle:46,
333 genmask:2, 333 genmask:2,
334 dlen:16; 334 dlen:16;
@@ -389,7 +389,6 @@ enum nft_chain_flags {
389 * 389 *
390 * @rules: list of rules in the chain 390 * @rules: list of rules in the chain
391 * @list: used internally 391 * @list: used internally
392 * @rcu_head: used internally
393 * @net: net namespace that this chain belongs to 392 * @net: net namespace that this chain belongs to
394 * @table: table that this chain belongs to 393 * @table: table that this chain belongs to
395 * @handle: chain handle 394 * @handle: chain handle
@@ -401,7 +400,6 @@ enum nft_chain_flags {
401struct nft_chain { 400struct nft_chain {
402 struct list_head rules; 401 struct list_head rules;
403 struct list_head list; 402 struct list_head list;
404 struct rcu_head rcu_head;
405 struct net *net; 403 struct net *net;
406 struct nft_table *table; 404 struct nft_table *table;
407 u64 handle; 405 u64 handle;
@@ -529,6 +527,9 @@ void nft_unregister_expr(struct nft_expr_type *);
529#define MODULE_ALIAS_NFT_CHAIN(family, name) \ 527#define MODULE_ALIAS_NFT_CHAIN(family, name) \
530 MODULE_ALIAS("nft-chain-" __stringify(family) "-" name) 528 MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
531 529
530#define MODULE_ALIAS_NFT_AF_EXPR(family, name) \
531 MODULE_ALIAS("nft-expr-" __stringify(family) "-" name)
532
532#define MODULE_ALIAS_NFT_EXPR(name) \ 533#define MODULE_ALIAS_NFT_EXPR(name) \
533 MODULE_ALIAS("nft-expr-" name) 534 MODULE_ALIAS("nft-expr-" name)
534 535
diff --git a/include/net/netfilter/nft_reject.h b/include/net/netfilter/nft_reject.h
new file mode 100644
index 000000000000..36b0da2d55bb
--- /dev/null
+++ b/include/net/netfilter/nft_reject.h
@@ -0,0 +1,25 @@
1#ifndef _NFT_REJECT_H_
2#define _NFT_REJECT_H_
3
4struct nft_reject {
5 enum nft_reject_types type:8;
6 u8 icmp_code;
7};
8
9extern const struct nla_policy nft_reject_policy[];
10
11int nft_reject_init(const struct nft_ctx *ctx,
12 const struct nft_expr *expr,
13 const struct nlattr * const tb[]);
14
15int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr);
16
17void nft_reject_ipv4_eval(const struct nft_expr *expr,
18 struct nft_data data[NFT_REG_MAX + 1],
19 const struct nft_pktinfo *pkt);
20
21void nft_reject_ipv6_eval(const struct nft_expr *expr,
22 struct nft_data data[NFT_REG_MAX + 1],
23 const struct nft_pktinfo *pkt);
24
25#endif
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index d992ca3145fe..6ee76c804893 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1653,17 +1653,6 @@ struct sctp_association {
1653 /* This is the last advertised value of rwnd over a SACK chunk. */ 1653 /* This is the last advertised value of rwnd over a SACK chunk. */
1654 __u32 a_rwnd; 1654 __u32 a_rwnd;
1655 1655
1656 /* Number of bytes by which the rwnd has slopped. The rwnd is allowed
1657 * to slop over a maximum of the association's frag_point.
1658 */
1659 __u32 rwnd_over;
1660
1661 /* Keeps treack of rwnd pressure. This happens when we have
1662 * a window, but not recevie buffer (i.e small packets). This one
1663 * is releases slowly (1 PMTU at a time ).
1664 */
1665 __u32 rwnd_press;
1666
1667 /* This is the sndbuf size in use for the association. 1656 /* This is the sndbuf size in use for the association.
1668 * This corresponds to the sndbuf size for the association, 1657 * This corresponds to the sndbuf size for the association,
1669 * as specified in the sk->sndbuf. 1658 * as specified in the sk->sndbuf.
@@ -1892,8 +1881,7 @@ void sctp_assoc_update(struct sctp_association *old,
1892__u32 sctp_association_get_next_tsn(struct sctp_association *); 1881__u32 sctp_association_get_next_tsn(struct sctp_association *);
1893 1882
1894void sctp_assoc_sync_pmtu(struct sock *, struct sctp_association *); 1883void sctp_assoc_sync_pmtu(struct sock *, struct sctp_association *);
1895void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned int); 1884void sctp_assoc_rwnd_update(struct sctp_association *, bool);
1896void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned int);
1897void sctp_assoc_set_primary(struct sctp_association *, 1885void sctp_assoc_set_primary(struct sctp_association *,
1898 struct sctp_transport *); 1886 struct sctp_transport *);
1899void sctp_assoc_del_nonprimary_peers(struct sctp_association *, 1887void sctp_assoc_del_nonprimary_peers(struct sctp_association *,
diff --git a/include/net/sock.h b/include/net/sock.h
index 5c3f7c3624aa..b9586a137cad 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1488,6 +1488,11 @@ static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb)
1488 */ 1488 */
1489#define sock_owned_by_user(sk) ((sk)->sk_lock.owned) 1489#define sock_owned_by_user(sk) ((sk)->sk_lock.owned)
1490 1490
1491static inline void sock_release_ownership(struct sock *sk)
1492{
1493 sk->sk_lock.owned = 0;
1494}
1495
1491/* 1496/*
1492 * Macro so as to not evaluate some arguments when 1497 * Macro so as to not evaluate some arguments when
1493 * lockdep is not enabled. 1498 * lockdep is not enabled.
@@ -2186,7 +2191,6 @@ static inline void sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,
2186{ 2191{
2187#define FLAGS_TS_OR_DROPS ((1UL << SOCK_RXQ_OVFL) | \ 2192#define FLAGS_TS_OR_DROPS ((1UL << SOCK_RXQ_OVFL) | \
2188 (1UL << SOCK_RCVTSTAMP) | \ 2193 (1UL << SOCK_RCVTSTAMP) | \
2189 (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE) | \
2190 (1UL << SOCK_TIMESTAMPING_SOFTWARE) | \ 2194 (1UL << SOCK_TIMESTAMPING_SOFTWARE) | \
2191 (1UL << SOCK_TIMESTAMPING_RAW_HARDWARE) | \ 2195 (1UL << SOCK_TIMESTAMPING_RAW_HARDWARE) | \
2192 (1UL << SOCK_TIMESTAMPING_SYS_HARDWARE)) 2196 (1UL << SOCK_TIMESTAMPING_SYS_HARDWARE))
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 56fc366da6d5..743accec6c76 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -480,20 +480,21 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
480#ifdef CONFIG_SYN_COOKIES 480#ifdef CONFIG_SYN_COOKIES
481#include <linux/ktime.h> 481#include <linux/ktime.h>
482 482
483/* Syncookies use a monotonic timer which increments every 64 seconds. 483/* Syncookies use a monotonic timer which increments every 60 seconds.
484 * This counter is used both as a hash input and partially encoded into 484 * This counter is used both as a hash input and partially encoded into
485 * the cookie value. A cookie is only validated further if the delta 485 * the cookie value. A cookie is only validated further if the delta
486 * between the current counter value and the encoded one is less than this, 486 * between the current counter value and the encoded one is less than this,
487 * i.e. a sent cookie is valid only at most for 128 seconds (or less if 487 * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if
488 * the counter advances immediately after a cookie is generated). 488 * the counter advances immediately after a cookie is generated).
489 */ 489 */
490#define MAX_SYNCOOKIE_AGE 2 490#define MAX_SYNCOOKIE_AGE 2
491 491
492static inline u32 tcp_cookie_time(void) 492static inline u32 tcp_cookie_time(void)
493{ 493{
494 struct timespec now; 494 u64 val = get_jiffies_64();
495 getnstimeofday(&now); 495
496 return now.tv_sec >> 6; /* 64 seconds granularity */ 496 do_div(val, 60 * HZ);
497 return val;
497} 498}
498 499
499u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th, 500u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
@@ -1303,7 +1304,8 @@ struct tcp_fastopen_request {
1303 /* Fast Open cookie. Size 0 means a cookie request */ 1304 /* Fast Open cookie. Size 0 means a cookie request */
1304 struct tcp_fastopen_cookie cookie; 1305 struct tcp_fastopen_cookie cookie;
1305 struct msghdr *data; /* data in MSG_FASTOPEN */ 1306 struct msghdr *data; /* data in MSG_FASTOPEN */
1306 u16 copied; /* queued in tcp_connect() */ 1307 size_t size;
1308 int copied; /* queued in tcp_connect() */
1307}; 1309};
1308void tcp_free_fastopen_req(struct tcp_sock *tp); 1310void tcp_free_fastopen_req(struct tcp_sock *tp);
1309 1311
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index afa5730fb3bd..fb5654a8ca3c 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -1648,6 +1648,11 @@ static inline int xfrm_aevent_is_on(struct net *net)
1648} 1648}
1649#endif 1649#endif
1650 1650
1651static inline int aead_len(struct xfrm_algo_aead *alg)
1652{
1653 return sizeof(*alg) + ((alg->alg_key_len + 7) / 8);
1654}
1655
1651static inline int xfrm_alg_len(const struct xfrm_algo *alg) 1656static inline int xfrm_alg_len(const struct xfrm_algo *alg)
1652{ 1657{
1653 return sizeof(*alg) + ((alg->alg_key_len + 7) / 8); 1658 return sizeof(*alg) + ((alg->alg_key_len + 7) / 8);
@@ -1686,6 +1691,12 @@ static inline int xfrm_replay_clone(struct xfrm_state *x,
1686 return 0; 1691 return 0;
1687} 1692}
1688 1693
1694static inline struct xfrm_algo_aead *xfrm_algo_aead_clone(struct xfrm_algo_aead *orig)
1695{
1696 return kmemdup(orig, aead_len(orig), GFP_KERNEL);
1697}
1698
1699
1689static inline struct xfrm_algo *xfrm_algo_clone(struct xfrm_algo *orig) 1700static inline struct xfrm_algo *xfrm_algo_clone(struct xfrm_algo *orig)
1690{ 1701{
1691 return kmemdup(orig, xfrm_alg_len(orig), GFP_KERNEL); 1702 return kmemdup(orig, xfrm_alg_len(orig), GFP_KERNEL);
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 8d4a1c06f7e4..6793f32ccb58 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -226,7 +226,8 @@ enum ib_port_cap_flags {
226 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22, 226 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
227 IB_PORT_BOOT_MGMT_SUP = 1 << 23, 227 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
228 IB_PORT_LINK_LATENCY_SUP = 1 << 24, 228 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
229 IB_PORT_CLIENT_REG_SUP = 1 << 25 229 IB_PORT_CLIENT_REG_SUP = 1 << 25,
230 IB_PORT_IP_BASED_GIDS = 1 << 26
230}; 231};
231 232
232enum ib_port_width { 233enum ib_port_width {
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 68d92e36facd..6e89ef6c11c1 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -449,14 +449,22 @@ void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
449/* dapm audio pin control and status */ 449/* dapm audio pin control and status */
450int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, 450int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm,
451 const char *pin); 451 const char *pin);
452int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
453 const char *pin);
452int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, 454int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
453 const char *pin); 455 const char *pin);
456int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context *dapm,
457 const char *pin);
454int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin); 458int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin);
459int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context *dapm,
460 const char *pin);
455int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, 461int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
456 const char *pin); 462 const char *pin);
457int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm); 463int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm);
458int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, 464int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
459 const char *pin); 465 const char *pin);
466int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
467 const char *pin);
460int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, 468int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
461 const char *pin); 469 const char *pin);
462void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec); 470void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec);
diff --git a/include/target/iscsi/iscsi_transport.h b/include/target/iscsi/iscsi_transport.h
index ae5a17111968..4483fadfa68d 100644
--- a/include/target/iscsi/iscsi_transport.h
+++ b/include/target/iscsi/iscsi_transport.h
@@ -12,6 +12,7 @@ struct iscsit_transport {
12 int (*iscsit_setup_np)(struct iscsi_np *, struct __kernel_sockaddr_storage *); 12 int (*iscsit_setup_np)(struct iscsi_np *, struct __kernel_sockaddr_storage *);
13 int (*iscsit_accept_np)(struct iscsi_np *, struct iscsi_conn *); 13 int (*iscsit_accept_np)(struct iscsi_np *, struct iscsi_conn *);
14 void (*iscsit_free_np)(struct iscsi_np *); 14 void (*iscsit_free_np)(struct iscsi_np *);
15 void (*iscsit_wait_conn)(struct iscsi_conn *);
15 void (*iscsit_free_conn)(struct iscsi_conn *); 16 void (*iscsit_free_conn)(struct iscsi_conn *);
16 int (*iscsit_get_login_rx)(struct iscsi_conn *, struct iscsi_login *); 17 int (*iscsit_get_login_rx)(struct iscsi_conn *, struct iscsi_login *);
17 int (*iscsit_put_login_tx)(struct iscsi_conn *, struct iscsi_login *, u32); 18 int (*iscsit_put_login_tx)(struct iscsi_conn *, struct iscsi_login *, u32);
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index c9c791209cd1..1772fadcff62 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -525,7 +525,6 @@ struct se_cmd {
525#define CMD_T_COMPLETE (1 << 2) 525#define CMD_T_COMPLETE (1 << 2)
526#define CMD_T_SENT (1 << 4) 526#define CMD_T_SENT (1 << 4)
527#define CMD_T_STOP (1 << 5) 527#define CMD_T_STOP (1 << 5)
528#define CMD_T_FAILED (1 << 6)
529#define CMD_T_DEV_ACTIVE (1 << 7) 528#define CMD_T_DEV_ACTIVE (1 << 7)
530#define CMD_T_REQUEST_STOP (1 << 8) 529#define CMD_T_REQUEST_STOP (1 << 8)
531#define CMD_T_BUSY (1 << 9) 530#define CMD_T_BUSY (1 << 9)
diff --git a/include/trace/events/power.h b/include/trace/events/power.h
index 9e9475c85de5..e5bf9a76f169 100644
--- a/include/trace/events/power.h
+++ b/include/trace/events/power.h
@@ -42,7 +42,6 @@ TRACE_EVENT(pstate_sample,
42 u32 state, 42 u32 state,
43 u64 mperf, 43 u64 mperf,
44 u64 aperf, 44 u64 aperf,
45 u32 energy,
46 u32 freq 45 u32 freq
47 ), 46 ),
48 47
@@ -51,7 +50,6 @@ TRACE_EVENT(pstate_sample,
51 state, 50 state,
52 mperf, 51 mperf,
53 aperf, 52 aperf,
54 energy,
55 freq 53 freq
56 ), 54 ),
57 55
@@ -61,7 +59,6 @@ TRACE_EVENT(pstate_sample,
61 __field(u32, state) 59 __field(u32, state)
62 __field(u64, mperf) 60 __field(u64, mperf)
63 __field(u64, aperf) 61 __field(u64, aperf)
64 __field(u32, energy)
65 __field(u32, freq) 62 __field(u32, freq)
66 63
67 ), 64 ),
@@ -72,17 +69,15 @@ TRACE_EVENT(pstate_sample,
72 __entry->state = state; 69 __entry->state = state;
73 __entry->mperf = mperf; 70 __entry->mperf = mperf;
74 __entry->aperf = aperf; 71 __entry->aperf = aperf;
75 __entry->energy = energy;
76 __entry->freq = freq; 72 __entry->freq = freq;
77 ), 73 ),
78 74
79 TP_printk("core_busy=%lu scaled=%lu state=%lu mperf=%llu aperf=%llu energy=%lu freq=%lu ", 75 TP_printk("core_busy=%lu scaled=%lu state=%lu mperf=%llu aperf=%llu freq=%lu ",
80 (unsigned long)__entry->core_busy, 76 (unsigned long)__entry->core_busy,
81 (unsigned long)__entry->scaled_busy, 77 (unsigned long)__entry->scaled_busy,
82 (unsigned long)__entry->state, 78 (unsigned long)__entry->state,
83 (unsigned long long)__entry->mperf, 79 (unsigned long long)__entry->mperf,
84 (unsigned long long)__entry->aperf, 80 (unsigned long long)__entry->aperf,
85 (unsigned long)__entry->energy,
86 (unsigned long)__entry->freq 81 (unsigned long)__entry->freq
87 ) 82 )
88 83
diff --git a/include/trace/events/sunrpc.h b/include/trace/events/sunrpc.h
index ddc179b7a105..1fef3e6e9436 100644
--- a/include/trace/events/sunrpc.h
+++ b/include/trace/events/sunrpc.h
@@ -83,7 +83,7 @@ DECLARE_EVENT_CLASS(rpc_task_running,
83 ), 83 ),
84 84
85 TP_fast_assign( 85 TP_fast_assign(
86 __entry->client_id = clnt->cl_clid; 86 __entry->client_id = clnt ? clnt->cl_clid : -1;
87 __entry->task_id = task->tk_pid; 87 __entry->task_id = task->tk_pid;
88 __entry->action = action; 88 __entry->action = action;
89 __entry->runstate = task->tk_runstate; 89 __entry->runstate = task->tk_runstate;
@@ -91,7 +91,7 @@ DECLARE_EVENT_CLASS(rpc_task_running,
91 __entry->flags = task->tk_flags; 91 __entry->flags = task->tk_flags;
92 ), 92 ),
93 93
94 TP_printk("task:%u@%u flags=%4.4x state=%4.4lx status=%d action=%pf", 94 TP_printk("task:%u@%d flags=%4.4x state=%4.4lx status=%d action=%pf",
95 __entry->task_id, __entry->client_id, 95 __entry->task_id, __entry->client_id,
96 __entry->flags, 96 __entry->flags,
97 __entry->runstate, 97 __entry->runstate,
diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index c7bbbe794e65..464ea82e10db 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -287,11 +287,11 @@ TRACE_EVENT(writeback_queue_io,
287 __field(int, reason) 287 __field(int, reason)
288 ), 288 ),
289 TP_fast_assign( 289 TP_fast_assign(
290 unsigned long older_than_this = work->older_than_this; 290 unsigned long *older_than_this = work->older_than_this;
291 strncpy(__entry->name, dev_name(wb->bdi->dev), 32); 291 strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
292 __entry->older = older_than_this; 292 __entry->older = older_than_this ? *older_than_this : 0;
293 __entry->age = older_than_this ? 293 __entry->age = older_than_this ?
294 (jiffies - older_than_this) * 1000 / HZ : -1; 294 (jiffies - *older_than_this) * 1000 / HZ : -1;
295 __entry->moved = moved; 295 __entry->moved = moved;
296 __entry->reason = work->reason; 296 __entry->reason = work->reason;
297 ), 297 ),
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index 1a8b28db3775..1ee19a24cc5f 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -310,15 +310,12 @@ static struct trace_event_functions ftrace_event_type_funcs_##call = { \
310#undef __array 310#undef __array
311#define __array(type, item, len) \ 311#define __array(type, item, len) \
312 do { \ 312 do { \
313 mutex_lock(&event_storage_mutex); \ 313 char *type_str = #type"["__stringify(len)"]"; \
314 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ 314 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
315 snprintf(event_storage, sizeof(event_storage), \ 315 ret = trace_define_field(event_call, type_str, #item, \
316 "%s[%d]", #type, len); \
317 ret = trace_define_field(event_call, event_storage, #item, \
318 offsetof(typeof(field), item), \ 316 offsetof(typeof(field), item), \
319 sizeof(field.item), \ 317 sizeof(field.item), \
320 is_signed_type(type), FILTER_OTHER); \ 318 is_signed_type(type), FILTER_OTHER); \
321 mutex_unlock(&event_storage_mutex); \
322 if (ret) \ 319 if (ret) \
323 return ret; \ 320 return ret; \
324 } while (0); 321 } while (0);
diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
index a20a9b4d3871..6db66783d268 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -191,6 +191,7 @@ __SYSCALL(__NR_quotactl, sys_quotactl)
191 191
192/* fs/readdir.c */ 192/* fs/readdir.c */
193#define __NR_getdents64 61 193#define __NR_getdents64 61
194#define __ARCH_WANT_COMPAT_SYS_GETDENTS64
194__SC_COMP(__NR_getdents64, sys_getdents64, compat_sys_getdents64) 195__SC_COMP(__NR_getdents64, sys_getdents64, compat_sys_getdents64)
195 196
196/* fs/read_write.c */ 197/* fs/read_write.c */
@@ -692,9 +693,13 @@ __SC_COMP(__NR_process_vm_writev, sys_process_vm_writev, \
692__SYSCALL(__NR_kcmp, sys_kcmp) 693__SYSCALL(__NR_kcmp, sys_kcmp)
693#define __NR_finit_module 273 694#define __NR_finit_module 273
694__SYSCALL(__NR_finit_module, sys_finit_module) 695__SYSCALL(__NR_finit_module, sys_finit_module)
696#define __NR_sched_setattr 274
697__SYSCALL(__NR_sched_setattr, sys_sched_setattr)
698#define __NR_sched_getattr 275
699__SYSCALL(__NR_sched_getattr, sys_sched_getattr)
695 700
696#undef __NR_syscalls 701#undef __NR_syscalls
697#define __NR_syscalls 274 702#define __NR_syscalls 276
698 703
699/* 704/*
700 * All syscalls below here should go away really, 705 * All syscalls below here should go away really,
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 3c9a833992e8..b06c8ed68707 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -619,6 +619,8 @@ struct drm_gem_open {
619#define DRM_PRIME_CAP_EXPORT 0x2 619#define DRM_PRIME_CAP_EXPORT 0x2
620#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6 620#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
621#define DRM_CAP_ASYNC_PAGE_FLIP 0x7 621#define DRM_CAP_ASYNC_PAGE_FLIP 0x7
622#define DRM_CAP_CURSOR_WIDTH 0x8
623#define DRM_CAP_CURSOR_HEIGHT 0x9
622 624
623/** DRM_IOCTL_GET_CAP ioctl argument type */ 625/** DRM_IOCTL_GET_CAP ioctl argument type */
624struct drm_get_cap { 626struct drm_get_cap {
diff --git a/include/uapi/drm/vmwgfx_drm.h b/include/uapi/drm/vmwgfx_drm.h
index 9971c560ed9a..87792a5fee3b 100644
--- a/include/uapi/drm/vmwgfx_drm.h
+++ b/include/uapi/drm/vmwgfx_drm.h
@@ -87,6 +87,7 @@
87#define DRM_VMW_PARAM_MAX_SURF_MEMORY 7 87#define DRM_VMW_PARAM_MAX_SURF_MEMORY 7
88#define DRM_VMW_PARAM_3D_CAPS_SIZE 8 88#define DRM_VMW_PARAM_3D_CAPS_SIZE 8
89#define DRM_VMW_PARAM_MAX_MOB_MEMORY 9 89#define DRM_VMW_PARAM_MAX_MOB_MEMORY 9
90#define DRM_VMW_PARAM_MAX_MOB_SIZE 10
90 91
91/** 92/**
92 * struct drm_vmw_getparam_arg 93 * struct drm_vmw_getparam_arg
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index 1b8a0f4c9590..b4d69092fbdb 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -558,7 +558,6 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
558#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64) 558#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
559#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ 559#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
560 struct btrfs_ioctl_space_args) 560 struct btrfs_ioctl_space_args)
561#define BTRFS_IOC_GLOBAL_RSV _IOR(BTRFS_IOCTL_MAGIC, 20, __u64)
562#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64) 561#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
563#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64) 562#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
564#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \ 563#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
diff --git a/include/uapi/linux/in6.h b/include/uapi/linux/in6.h
index 633b93cac1ed..e9a1d2d973b6 100644
--- a/include/uapi/linux/in6.h
+++ b/include/uapi/linux/in6.h
@@ -128,22 +128,13 @@ struct in6_flowlabel_req {
128 * IPV6 extension headers 128 * IPV6 extension headers
129 */ 129 */
130#if __UAPI_DEF_IPPROTO_V6 130#if __UAPI_DEF_IPPROTO_V6
131enum { 131#define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options */
132 IPPROTO_HOPOPTS = 0, /* IPv6 hop-by-hop options */ 132#define IPPROTO_ROUTING 43 /* IPv6 routing header */
133#define IPPROTO_HOPOPTS IPPROTO_HOPOPTS 133#define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */
134 IPPROTO_ROUTING = 43, /* IPv6 routing header */ 134#define IPPROTO_ICMPV6 58 /* ICMPv6 */
135#define IPPROTO_ROUTING IPPROTO_ROUTING 135#define IPPROTO_NONE 59 /* IPv6 no next header */
136 IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header */ 136#define IPPROTO_DSTOPTS 60 /* IPv6 destination options */
137#define IPPROTO_FRAGMENT IPPROTO_FRAGMENT 137#define IPPROTO_MH 135 /* IPv6 mobility header */
138 IPPROTO_ICMPV6 = 58, /* ICMPv6 */
139#define IPPROTO_ICMPV6 IPPROTO_ICMPV6
140 IPPROTO_NONE = 59, /* IPv6 no next header */
141#define IPPROTO_NONE IPPROTO_NONE
142 IPPROTO_DSTOPTS = 60, /* IPv6 destination options */
143#define IPPROTO_DSTOPTS IPPROTO_DSTOPTS
144 IPPROTO_MH = 135, /* IPv6 mobility header */
145#define IPPROTO_MH IPPROTO_MH
146};
147#endif /* __UAPI_DEF_IPPROTO_V6 */ 138#endif /* __UAPI_DEF_IPPROTO_V6 */
148 139
149/* 140/*
diff --git a/include/uapi/linux/mic_ioctl.h b/include/uapi/linux/mic_ioctl.h
index 7fabba5059cf..feb0b4c0814c 100644
--- a/include/uapi/linux/mic_ioctl.h
+++ b/include/uapi/linux/mic_ioctl.h
@@ -39,7 +39,7 @@ struct mic_copy_desc {
39#else 39#else
40 struct iovec *iov; 40 struct iovec *iov;
41#endif 41#endif
42 int iovcnt; 42 __u32 iovcnt;
43 __u8 vr_idx; 43 __u8 vr_idx;
44 __u8 update_used; 44 __u8 update_used;
45 __u32 out_len; 45 __u32 out_len;
diff --git a/include/uapi/linux/nvme.h b/include/uapi/linux/nvme.h
index 989c04e0c563..e5ab62201119 100644
--- a/include/uapi/linux/nvme.h
+++ b/include/uapi/linux/nvme.h
@@ -350,6 +350,16 @@ struct nvme_delete_queue {
350 __u32 rsvd11[5]; 350 __u32 rsvd11[5];
351}; 351};
352 352
353struct nvme_abort_cmd {
354 __u8 opcode;
355 __u8 flags;
356 __u16 command_id;
357 __u32 rsvd1[9];
358 __le16 sqid;
359 __u16 cid;
360 __u32 rsvd11[5];
361};
362
353struct nvme_download_firmware { 363struct nvme_download_firmware {
354 __u8 opcode; 364 __u8 opcode;
355 __u8 flags; 365 __u8 flags;
@@ -384,6 +394,7 @@ struct nvme_command {
384 struct nvme_download_firmware dlfw; 394 struct nvme_download_firmware dlfw;
385 struct nvme_format_cmd format; 395 struct nvme_format_cmd format;
386 struct nvme_dsm_cmd dsm; 396 struct nvme_dsm_cmd dsm;
397 struct nvme_abort_cmd abort;
387 }; 398 };
388}; 399};
389 400
diff --git a/include/uapi/xen/Kbuild b/include/uapi/xen/Kbuild
index 61257cb14653..5c459628e8c7 100644
--- a/include/uapi/xen/Kbuild
+++ b/include/uapi/xen/Kbuild
@@ -1,3 +1,5 @@
1# UAPI Header export list 1# UAPI Header export list
2header-y += evtchn.h 2header-y += evtchn.h
3header-y += gntalloc.h
4header-y += gntdev.h
3header-y += privcmd.h 5header-y += privcmd.h
diff --git a/include/xen/gntalloc.h b/include/uapi/xen/gntalloc.h
index 76bd58065f4f..76bd58065f4f 100644
--- a/include/xen/gntalloc.h
+++ b/include/uapi/xen/gntalloc.h
diff --git a/include/xen/gntdev.h b/include/uapi/xen/gntdev.h
index 5304bd3c84c5..5304bd3c84c5 100644
--- a/include/xen/gntdev.h
+++ b/include/uapi/xen/gntdev.h
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 7ad033dbc845..a5af2a26d94f 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -191,15 +191,11 @@ void gnttab_free_auto_xlat_frames(void);
191#define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr)) 191#define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr))
192 192
193int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, 193int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
194 struct gnttab_map_grant_ref *kmap_ops,
194 struct page **pages, unsigned int count); 195 struct page **pages, unsigned int count);
195int gnttab_map_refs_userspace(struct gnttab_map_grant_ref *map_ops,
196 struct gnttab_map_grant_ref *kmap_ops,
197 struct page **pages, unsigned int count);
198int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, 196int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
197 struct gnttab_map_grant_ref *kunmap_ops,
199 struct page **pages, unsigned int count); 198 struct page **pages, unsigned int count);
200int gnttab_unmap_refs_userspace(struct gnttab_unmap_grant_ref *unmap_ops,
201 struct gnttab_map_grant_ref *kunmap_ops,
202 struct page **pages, unsigned int count);
203 199
204/* Perform a batch of grant map/copy operations. Retry every batch slot 200/* Perform a batch of grant map/copy operations. Retry every batch slot
205 * for which the hypervisor returns GNTST_eagain. This is typically due 201 * for which the hypervisor returns GNTST_eagain. This is typically due
diff --git a/include/xen/interface/io/blkif.h b/include/xen/interface/io/blkif.h
index ae665ac59c36..32ec05a6572f 100644
--- a/include/xen/interface/io/blkif.h
+++ b/include/xen/interface/io/blkif.h
@@ -113,13 +113,13 @@ typedef uint64_t blkif_sector_t;
113 * it's less than the number provided by the backend. The indirect_grefs field 113 * it's less than the number provided by the backend. The indirect_grefs field
114 * in blkif_request_indirect should be filled by the frontend with the 114 * in blkif_request_indirect should be filled by the frontend with the
115 * grant references of the pages that are holding the indirect segments. 115 * grant references of the pages that are holding the indirect segments.
116 * This pages are filled with an array of blkif_request_segment_aligned 116 * These pages are filled with an array of blkif_request_segment that hold the
117 * that hold the information about the segments. The number of indirect 117 * information about the segments. The number of indirect pages to use is
118 * pages to use is determined by the maximum number of segments 118 * determined by the number of segments an indirect request contains. Every
119 * a indirect request contains. Every indirect page can contain a maximum 119 * indirect page can contain a maximum of
120 * of 512 segments (PAGE_SIZE/sizeof(blkif_request_segment_aligned)), 120 * (PAGE_SIZE / sizeof(struct blkif_request_segment)) segments, so to
121 * so to calculate the number of indirect pages to use we have to do 121 * calculate the number of indirect pages to use we have to do
122 * ceil(indirect_segments/512). 122 * ceil(indirect_segments / (PAGE_SIZE / sizeof(struct blkif_request_segment))).
123 * 123 *
124 * If a backend does not recognize BLKIF_OP_INDIRECT, it should *not* 124 * If a backend does not recognize BLKIF_OP_INDIRECT, it should *not*
125 * create the "feature-max-indirect-segments" node! 125 * create the "feature-max-indirect-segments" node!
@@ -135,13 +135,12 @@ typedef uint64_t blkif_sector_t;
135 135
136#define BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST 8 136#define BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST 8
137 137
138struct blkif_request_segment_aligned { 138struct blkif_request_segment {
139 grant_ref_t gref; /* reference to I/O buffer frame */ 139 grant_ref_t gref; /* reference to I/O buffer frame */
140 /* @first_sect: first sector in frame to transfer (inclusive). */ 140 /* @first_sect: first sector in frame to transfer (inclusive). */
141 /* @last_sect: last sector in frame to transfer (inclusive). */ 141 /* @last_sect: last sector in frame to transfer (inclusive). */
142 uint8_t first_sect, last_sect; 142 uint8_t first_sect, last_sect;
143 uint16_t _pad; /* padding to make it 8 bytes, so it's cache-aligned */ 143};
144} __attribute__((__packed__));
145 144
146struct blkif_request_rw { 145struct blkif_request_rw {
147 uint8_t nr_segments; /* number of segments */ 146 uint8_t nr_segments; /* number of segments */
@@ -151,12 +150,7 @@ struct blkif_request_rw {
151#endif 150#endif
152 uint64_t id; /* private guest value, echoed in resp */ 151 uint64_t id; /* private guest value, echoed in resp */
153 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 152 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
154 struct blkif_request_segment { 153 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
155 grant_ref_t gref; /* reference to I/O buffer frame */
156 /* @first_sect: first sector in frame to transfer (inclusive). */
157 /* @last_sect: last sector in frame to transfer (inclusive). */
158 uint8_t first_sect, last_sect;
159 } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
160} __attribute__((__packed__)); 154} __attribute__((__packed__));
161 155
162struct blkif_request_discard { 156struct blkif_request_discard {
diff --git a/include/xen/interface/xencomm.h b/include/xen/interface/xencomm.h
deleted file mode 100644
index ac45e0712afa..000000000000
--- a/include/xen/interface/xencomm.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Permission is hereby granted, free of charge, to any person obtaining a copy
3 * of this software and associated documentation files (the "Software"), to
4 * deal in the Software without restriction, including without limitation the
5 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6 * sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 * DEALINGS IN THE SOFTWARE.
19 *
20 * Copyright (C) IBM Corp. 2006
21 */
22
23#ifndef _XEN_XENCOMM_H_
24#define _XEN_XENCOMM_H_
25
26/* A xencomm descriptor is a scatter/gather list containing physical
27 * addresses corresponding to a virtually contiguous memory area. The
28 * hypervisor translates these physical addresses to machine addresses to copy
29 * to and from the virtually contiguous area.
30 */
31
32#define XENCOMM_MAGIC 0x58434F4D /* 'XCOM' */
33#define XENCOMM_INVALID (~0UL)
34
35struct xencomm_desc {
36 uint32_t magic;
37 uint32_t nr_addrs; /* the number of entries in address[] */
38 uint64_t address[0];
39};
40
41#endif /* _XEN_XENCOMM_H_ */
diff --git a/include/xen/xencomm.h b/include/xen/xencomm.h
deleted file mode 100644
index e43b039be112..000000000000
--- a/include/xen/xencomm.h
+++ /dev/null
@@ -1,77 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Copyright (C) IBM Corp. 2006
17 *
18 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
19 * Jerone Young <jyoung5@us.ibm.com>
20 */
21
22#ifndef _LINUX_XENCOMM_H_
23#define _LINUX_XENCOMM_H_
24
25#include <xen/interface/xencomm.h>
26
27#define XENCOMM_MINI_ADDRS 3
28struct xencomm_mini {
29 struct xencomm_desc _desc;
30 uint64_t address[XENCOMM_MINI_ADDRS];
31};
32
33/* To avoid additionnal virt to phys conversion, an opaque structure is
34 presented. */
35struct xencomm_handle;
36
37extern void xencomm_free(struct xencomm_handle *desc);
38extern struct xencomm_handle *xencomm_map(void *ptr, unsigned long bytes);
39extern struct xencomm_handle *__xencomm_map_no_alloc(void *ptr,
40 unsigned long bytes, struct xencomm_mini *xc_area);
41
42#if 0
43#define XENCOMM_MINI_ALIGNED(xc_desc, n) \
44 struct xencomm_mini xc_desc ## _base[(n)] \
45 __attribute__((__aligned__(sizeof(struct xencomm_mini)))); \
46 struct xencomm_mini *xc_desc = &xc_desc ## _base[0];
47#else
48/*
49 * gcc bug workaround:
50 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16660
51 * gcc doesn't handle properly stack variable with
52 * __attribute__((__align__(sizeof(struct xencomm_mini))))
53 */
54#define XENCOMM_MINI_ALIGNED(xc_desc, n) \
55 unsigned char xc_desc ## _base[((n) + 1 ) * \
56 sizeof(struct xencomm_mini)]; \
57 struct xencomm_mini *xc_desc = (struct xencomm_mini *) \
58 ((unsigned long)xc_desc ## _base + \
59 (sizeof(struct xencomm_mini) - \
60 ((unsigned long)xc_desc ## _base) % \
61 sizeof(struct xencomm_mini)));
62#endif
63#define xencomm_map_no_alloc(ptr, bytes) \
64 ({ XENCOMM_MINI_ALIGNED(xc_desc, 1); \
65 __xencomm_map_no_alloc(ptr, bytes, xc_desc); })
66
67/* provided by architecture code: */
68extern unsigned long xencomm_vtop(unsigned long vaddr);
69
70static inline void *xencomm_pa(void *ptr)
71{
72 return (void *)xencomm_vtop((unsigned long)ptr);
73}
74
75#define xen_guest_handle(hnd) ((hnd).p)
76
77#endif /* _LINUX_XENCOMM_H_ */
diff --git a/init/Kconfig b/init/Kconfig
index 009a797dd242..d56cb03c1b49 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1387,6 +1387,13 @@ config FUTEX
1387 support for "fast userspace mutexes". The resulting kernel may not 1387 support for "fast userspace mutexes". The resulting kernel may not
1388 run glibc-based applications correctly. 1388 run glibc-based applications correctly.
1389 1389
1390config HAVE_FUTEX_CMPXCHG
1391 bool
1392 help
1393 Architectures should select this if futex_atomic_cmpxchg_inatomic()
1394 is implemented and always working. This removes a couple of runtime
1395 checks.
1396
1390config EPOLL 1397config EPOLL
1391 bool "Enable eventpoll support" if EXPERT 1398 bool "Enable eventpoll support" if EXPERT
1392 default y 1399 default y
diff --git a/init/main.c b/init/main.c
index 2fd9cef70ee8..9c7fd4c9249f 100644
--- a/init/main.c
+++ b/init/main.c
@@ -561,7 +561,6 @@ asmlinkage void __init start_kernel(void)
561 init_timers(); 561 init_timers();
562 hrtimers_init(); 562 hrtimers_init();
563 softirq_init(); 563 softirq_init();
564 acpi_early_init();
565 timekeeping_init(); 564 timekeeping_init();
566 time_init(); 565 time_init();
567 sched_clock_postinit(); 566 sched_clock_postinit();
@@ -613,6 +612,7 @@ asmlinkage void __init start_kernel(void)
613 calibrate_delay(); 612 calibrate_delay();
614 pidmap_init(); 613 pidmap_init();
615 anon_vma_init(); 614 anon_vma_init();
615 acpi_early_init();
616#ifdef CONFIG_X86 616#ifdef CONFIG_X86
617 if (efi_enabled(EFI_RUNTIME_SERVICES)) 617 if (efi_enabled(EFI_RUNTIME_SERVICES))
618 efi_enter_virtual_mode(); 618 efi_enter_virtual_mode();
@@ -812,7 +812,7 @@ void __init load_default_modules(void)
812static int run_init_process(const char *init_filename) 812static int run_init_process(const char *init_filename)
813{ 813{
814 argv_init[0] = init_filename; 814 argv_init[0] = init_filename;
815 return do_execve(init_filename, 815 return do_execve(getname_kernel(init_filename),
816 (const char __user *const __user *)argv_init, 816 (const char __user *const __user *)argv_init,
817 (const char __user *const __user *)envp_init); 817 (const char __user *const __user *)envp_init);
818} 818}
diff --git a/ipc/compat.c b/ipc/compat.c
index f486b0096a67..98b9016cab6c 100644
--- a/ipc/compat.c
+++ b/ipc/compat.c
@@ -430,9 +430,9 @@ COMPAT_SYSCALL_DEFINE4(msgsnd, int, msqid, compat_uptr_t, msgp,
430} 430}
431 431
432COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp, 432COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp,
433 compat_ssize_t, msgsz, long, msgtyp, int, msgflg) 433 compat_ssize_t, msgsz, compat_long_t, msgtyp, int, msgflg)
434{ 434{
435 return do_msgrcv(msqid, compat_ptr(msgp), (ssize_t)msgsz, msgtyp, 435 return do_msgrcv(msqid, compat_ptr(msgp), (ssize_t)msgsz, (long)msgtyp,
436 msgflg, compat_do_msg_fill); 436 msgflg, compat_do_msg_fill);
437} 437}
438 438
@@ -498,7 +498,7 @@ static inline int put_compat_msqid_ds(struct msqid64_ds *m,
498 return err; 498 return err;
499} 499}
500 500
501long compat_sys_msgctl(int first, int second, void __user *uptr) 501COMPAT_SYSCALL_DEFINE3(msgctl, int, first, int, second, void __user *, uptr)
502{ 502{
503 int err, err2; 503 int err, err2;
504 struct msqid64_ds m64; 504 struct msqid64_ds m64;
@@ -668,7 +668,7 @@ static inline int put_compat_shm_info(struct shm_info __user *ip,
668 return err; 668 return err;
669} 669}
670 670
671long compat_sys_shmctl(int first, int second, void __user *uptr) 671COMPAT_SYSCALL_DEFINE3(shmctl, int, first, int, second, void __user *, uptr)
672{ 672{
673 void __user *p; 673 void __user *p;
674 struct shmid64_ds s64; 674 struct shmid64_ds s64;
@@ -749,8 +749,9 @@ long compat_sys_shmctl(int first, int second, void __user *uptr)
749 return err; 749 return err;
750} 750}
751 751
752long compat_sys_semtimedop(int semid, struct sembuf __user *tsems, 752COMPAT_SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsems,
753 unsigned nsops, const struct compat_timespec __user *timeout) 753 unsigned, nsops,
754 const struct compat_timespec __user *, timeout)
754{ 755{
755 struct timespec __user *ts64 = NULL; 756 struct timespec __user *ts64 = NULL;
756 if (timeout) { 757 if (timeout) {
diff --git a/ipc/compat_mq.c b/ipc/compat_mq.c
index 63d7c6de335b..d58747293772 100644
--- a/ipc/compat_mq.c
+++ b/ipc/compat_mq.c
@@ -46,9 +46,9 @@ static inline int put_compat_mq_attr(const struct mq_attr *attr,
46 | __put_user(attr->mq_curmsgs, &uattr->mq_curmsgs); 46 | __put_user(attr->mq_curmsgs, &uattr->mq_curmsgs);
47} 47}
48 48
49asmlinkage long compat_sys_mq_open(const char __user *u_name, 49COMPAT_SYSCALL_DEFINE4(mq_open, const char __user *, u_name,
50 int oflag, compat_mode_t mode, 50 int, oflag, compat_mode_t, mode,
51 struct compat_mq_attr __user *u_attr) 51 struct compat_mq_attr __user *, u_attr)
52{ 52{
53 void __user *p = NULL; 53 void __user *p = NULL;
54 if (u_attr && oflag & O_CREAT) { 54 if (u_attr && oflag & O_CREAT) {
@@ -78,10 +78,10 @@ static int compat_prepare_timeout(struct timespec __user **p,
78 return 0; 78 return 0;
79} 79}
80 80
81asmlinkage long compat_sys_mq_timedsend(mqd_t mqdes, 81COMPAT_SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes,
82 const char __user *u_msg_ptr, 82 const char __user *, u_msg_ptr,
83 size_t msg_len, unsigned int msg_prio, 83 compat_size_t, msg_len, unsigned int, msg_prio,
84 const struct compat_timespec __user *u_abs_timeout) 84 const struct compat_timespec __user *, u_abs_timeout)
85{ 85{
86 struct timespec __user *u_ts; 86 struct timespec __user *u_ts;
87 87
@@ -92,10 +92,10 @@ asmlinkage long compat_sys_mq_timedsend(mqd_t mqdes,
92 msg_prio, u_ts); 92 msg_prio, u_ts);
93} 93}
94 94
95asmlinkage ssize_t compat_sys_mq_timedreceive(mqd_t mqdes, 95COMPAT_SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes,
96 char __user *u_msg_ptr, 96 char __user *, u_msg_ptr,
97 size_t msg_len, unsigned int __user *u_msg_prio, 97 compat_size_t, msg_len, unsigned int __user *, u_msg_prio,
98 const struct compat_timespec __user *u_abs_timeout) 98 const struct compat_timespec __user *, u_abs_timeout)
99{ 99{
100 struct timespec __user *u_ts; 100 struct timespec __user *u_ts;
101 if (compat_prepare_timeout(&u_ts, u_abs_timeout)) 101 if (compat_prepare_timeout(&u_ts, u_abs_timeout))
@@ -105,8 +105,8 @@ asmlinkage ssize_t compat_sys_mq_timedreceive(mqd_t mqdes,
105 u_msg_prio, u_ts); 105 u_msg_prio, u_ts);
106} 106}
107 107
108asmlinkage long compat_sys_mq_notify(mqd_t mqdes, 108COMPAT_SYSCALL_DEFINE2(mq_notify, mqd_t, mqdes,
109 const struct compat_sigevent __user *u_notification) 109 const struct compat_sigevent __user *, u_notification)
110{ 110{
111 struct sigevent __user *p = NULL; 111 struct sigevent __user *p = NULL;
112 if (u_notification) { 112 if (u_notification) {
@@ -122,9 +122,9 @@ asmlinkage long compat_sys_mq_notify(mqd_t mqdes,
122 return sys_mq_notify(mqdes, p); 122 return sys_mq_notify(mqdes, p);
123} 123}
124 124
125asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes, 125COMPAT_SYSCALL_DEFINE3(mq_getsetattr, mqd_t, mqdes,
126 const struct compat_mq_attr __user *u_mqstat, 126 const struct compat_mq_attr __user *, u_mqstat,
127 struct compat_mq_attr __user *u_omqstat) 127 struct compat_mq_attr __user *, u_omqstat)
128{ 128{
129 struct mq_attr mqstat; 129 struct mq_attr mqstat;
130 struct mq_attr __user *p = compat_alloc_user_space(2 * sizeof(*p)); 130 struct mq_attr __user *p = compat_alloc_user_space(2 * sizeof(*p));
diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
index 383d638340b8..5bb8bfe67149 100644
--- a/ipc/mq_sysctl.c
+++ b/ipc/mq_sysctl.c
@@ -22,6 +22,16 @@ static void *get_mq(ctl_table *table)
22 return which; 22 return which;
23} 23}
24 24
25static int proc_mq_dointvec(ctl_table *table, int write,
26 void __user *buffer, size_t *lenp, loff_t *ppos)
27{
28 struct ctl_table mq_table;
29 memcpy(&mq_table, table, sizeof(mq_table));
30 mq_table.data = get_mq(table);
31
32 return proc_dointvec(&mq_table, write, buffer, lenp, ppos);
33}
34
25static int proc_mq_dointvec_minmax(ctl_table *table, int write, 35static int proc_mq_dointvec_minmax(ctl_table *table, int write,
26 void __user *buffer, size_t *lenp, loff_t *ppos) 36 void __user *buffer, size_t *lenp, loff_t *ppos)
27{ 37{
@@ -33,12 +43,10 @@ static int proc_mq_dointvec_minmax(ctl_table *table, int write,
33 lenp, ppos); 43 lenp, ppos);
34} 44}
35#else 45#else
46#define proc_mq_dointvec NULL
36#define proc_mq_dointvec_minmax NULL 47#define proc_mq_dointvec_minmax NULL
37#endif 48#endif
38 49
39static int msg_queues_limit_min = MIN_QUEUESMAX;
40static int msg_queues_limit_max = HARD_QUEUESMAX;
41
42static int msg_max_limit_min = MIN_MSGMAX; 50static int msg_max_limit_min = MIN_MSGMAX;
43static int msg_max_limit_max = HARD_MSGMAX; 51static int msg_max_limit_max = HARD_MSGMAX;
44 52
@@ -51,9 +59,7 @@ static ctl_table mq_sysctls[] = {
51 .data = &init_ipc_ns.mq_queues_max, 59 .data = &init_ipc_ns.mq_queues_max,
52 .maxlen = sizeof(int), 60 .maxlen = sizeof(int),
53 .mode = 0644, 61 .mode = 0644,
54 .proc_handler = proc_mq_dointvec_minmax, 62 .proc_handler = proc_mq_dointvec,
55 .extra1 = &msg_queues_limit_min,
56 .extra2 = &msg_queues_limit_max,
57 }, 63 },
58 { 64 {
59 .procname = "msg_max", 65 .procname = "msg_max",
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index ccf1f9fd263a..c3b31179122c 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -433,9 +433,9 @@ static int mqueue_create(struct inode *dir, struct dentry *dentry,
433 error = -EACCES; 433 error = -EACCES;
434 goto out_unlock; 434 goto out_unlock;
435 } 435 }
436 if (ipc_ns->mq_queues_count >= HARD_QUEUESMAX || 436
437 (ipc_ns->mq_queues_count >= ipc_ns->mq_queues_max && 437 if (ipc_ns->mq_queues_count >= ipc_ns->mq_queues_max &&
438 !capable(CAP_SYS_RESOURCE))) { 438 !capable(CAP_SYS_RESOURCE)) {
439 error = -ENOSPC; 439 error = -ENOSPC;
440 goto out_unlock; 440 goto out_unlock;
441 } 441 }
diff --git a/ipc/msg.c b/ipc/msg.c
index 245db1140ad6..649853105a5d 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -901,6 +901,8 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp, int msgfl
901 return -EINVAL; 901 return -EINVAL;
902 902
903 if (msgflg & MSG_COPY) { 903 if (msgflg & MSG_COPY) {
904 if ((msgflg & MSG_EXCEPT) || !(msgflg & IPC_NOWAIT))
905 return -EINVAL;
904 copy = prepare_copy(buf, min_t(size_t, bufsz, ns->msg_ctlmax)); 906 copy = prepare_copy(buf, min_t(size_t, bufsz, ns->msg_ctlmax));
905 if (IS_ERR(copy)) 907 if (IS_ERR(copy))
906 return PTR_ERR(copy); 908 return PTR_ERR(copy);
diff --git a/kernel/Makefile b/kernel/Makefile
index bc010ee272b6..f2a8b6246ce9 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -18,11 +18,13 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
18CFLAGS_REMOVE_irq_work.o = -pg 18CFLAGS_REMOVE_irq_work.o = -pg
19endif 19endif
20 20
21# cond_syscall is currently not LTO compatible
22CFLAGS_sys_ni.o = $(DISABLE_LTO)
23
21obj-y += sched/ 24obj-y += sched/
22obj-y += locking/ 25obj-y += locking/
23obj-y += power/ 26obj-y += power/
24obj-y += printk/ 27obj-y += printk/
25obj-y += cpu/
26obj-y += irq/ 28obj-y += irq/
27obj-y += rcu/ 29obj-y += rcu/
28 30
@@ -93,6 +95,7 @@ obj-$(CONFIG_PADATA) += padata.o
93obj-$(CONFIG_CRASH_DUMP) += crash_dump.o 95obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
94obj-$(CONFIG_JUMP_LABEL) += jump_label.o 96obj-$(CONFIG_JUMP_LABEL) += jump_label.o
95obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o 97obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o
98obj-$(CONFIG_TORTURE_TEST) += torture.o
96 99
97$(obj)/configs.o: $(obj)/config_data.h 100$(obj)/configs.o: $(obj)/config_data.h
98 101
diff --git a/kernel/audit.c b/kernel/audit.c
index 34c5a2310fbf..95a20f3f52f1 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -182,7 +182,7 @@ struct audit_buffer {
182 182
183struct audit_reply { 183struct audit_reply {
184 __u32 portid; 184 __u32 portid;
185 pid_t pid; 185 struct net *net;
186 struct sk_buff *skb; 186 struct sk_buff *skb;
187}; 187};
188 188
@@ -500,7 +500,7 @@ int audit_send_list(void *_dest)
500{ 500{
501 struct audit_netlink_list *dest = _dest; 501 struct audit_netlink_list *dest = _dest;
502 struct sk_buff *skb; 502 struct sk_buff *skb;
503 struct net *net = get_net_ns_by_pid(dest->pid); 503 struct net *net = dest->net;
504 struct audit_net *aunet = net_generic(net, audit_net_id); 504 struct audit_net *aunet = net_generic(net, audit_net_id);
505 505
506 /* wait for parent to finish and send an ACK */ 506 /* wait for parent to finish and send an ACK */
@@ -510,6 +510,7 @@ int audit_send_list(void *_dest)
510 while ((skb = __skb_dequeue(&dest->q)) != NULL) 510 while ((skb = __skb_dequeue(&dest->q)) != NULL)
511 netlink_unicast(aunet->nlsk, skb, dest->portid, 0); 511 netlink_unicast(aunet->nlsk, skb, dest->portid, 0);
512 512
513 put_net(net);
513 kfree(dest); 514 kfree(dest);
514 515
515 return 0; 516 return 0;
@@ -543,7 +544,7 @@ out_kfree_skb:
543static int audit_send_reply_thread(void *arg) 544static int audit_send_reply_thread(void *arg)
544{ 545{
545 struct audit_reply *reply = (struct audit_reply *)arg; 546 struct audit_reply *reply = (struct audit_reply *)arg;
546 struct net *net = get_net_ns_by_pid(reply->pid); 547 struct net *net = reply->net;
547 struct audit_net *aunet = net_generic(net, audit_net_id); 548 struct audit_net *aunet = net_generic(net, audit_net_id);
548 549
549 mutex_lock(&audit_cmd_mutex); 550 mutex_lock(&audit_cmd_mutex);
@@ -552,12 +553,13 @@ static int audit_send_reply_thread(void *arg)
552 /* Ignore failure. It'll only happen if the sender goes away, 553 /* Ignore failure. It'll only happen if the sender goes away,
553 because our timeout is set to infinite. */ 554 because our timeout is set to infinite. */
554 netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0); 555 netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0);
556 put_net(net);
555 kfree(reply); 557 kfree(reply);
556 return 0; 558 return 0;
557} 559}
558/** 560/**
559 * audit_send_reply - send an audit reply message via netlink 561 * audit_send_reply - send an audit reply message via netlink
560 * @portid: netlink port to which to send reply 562 * @request_skb: skb of request we are replying to (used to target the reply)
561 * @seq: sequence number 563 * @seq: sequence number
562 * @type: audit message type 564 * @type: audit message type
563 * @done: done (last) flag 565 * @done: done (last) flag
@@ -568,9 +570,11 @@ static int audit_send_reply_thread(void *arg)
568 * Allocates an skb, builds the netlink message, and sends it to the port id. 570 * Allocates an skb, builds the netlink message, and sends it to the port id.
569 * No failure notifications. 571 * No failure notifications.
570 */ 572 */
571static void audit_send_reply(__u32 portid, int seq, int type, int done, 573static void audit_send_reply(struct sk_buff *request_skb, int seq, int type, int done,
572 int multi, const void *payload, int size) 574 int multi, const void *payload, int size)
573{ 575{
576 u32 portid = NETLINK_CB(request_skb).portid;
577 struct net *net = sock_net(NETLINK_CB(request_skb).sk);
574 struct sk_buff *skb; 578 struct sk_buff *skb;
575 struct task_struct *tsk; 579 struct task_struct *tsk;
576 struct audit_reply *reply = kmalloc(sizeof(struct audit_reply), 580 struct audit_reply *reply = kmalloc(sizeof(struct audit_reply),
@@ -583,8 +587,8 @@ static void audit_send_reply(__u32 portid, int seq, int type, int done,
583 if (!skb) 587 if (!skb)
584 goto out; 588 goto out;
585 589
590 reply->net = get_net(net);
586 reply->portid = portid; 591 reply->portid = portid;
587 reply->pid = task_pid_vnr(current);
588 reply->skb = skb; 592 reply->skb = skb;
589 593
590 tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); 594 tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply");
@@ -604,9 +608,19 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)
604 int err = 0; 608 int err = 0;
605 609
606 /* Only support the initial namespaces for now. */ 610 /* Only support the initial namespaces for now. */
611 /*
612 * We return ECONNREFUSED because it tricks userspace into thinking
613 * that audit was not configured into the kernel. Lots of users
614 * configure their PAM stack (because that's what the distro does)
615 * to reject login if unable to send messages to audit. If we return
616 * ECONNREFUSED the PAM stack thinks the kernel does not have audit
617 * configured in and will let login proceed. If we return EPERM
618 * userspace will reject all logins. This should be removed when we
619 * support non init namespaces!!
620 */
607 if ((current_user_ns() != &init_user_ns) || 621 if ((current_user_ns() != &init_user_ns) ||
608 (task_active_pid_ns(current) != &init_pid_ns)) 622 (task_active_pid_ns(current) != &init_pid_ns))
609 return -EPERM; 623 return -ECONNREFUSED;
610 624
611 switch (msg_type) { 625 switch (msg_type) {
612 case AUDIT_LIST: 626 case AUDIT_LIST:
@@ -673,8 +687,7 @@ static int audit_get_feature(struct sk_buff *skb)
673 687
674 seq = nlmsg_hdr(skb)->nlmsg_seq; 688 seq = nlmsg_hdr(skb)->nlmsg_seq;
675 689
676 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0, 690 audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &af, sizeof(af));
677 &af, sizeof(af));
678 691
679 return 0; 692 return 0;
680} 693}
@@ -794,8 +807,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
794 s.backlog = skb_queue_len(&audit_skb_queue); 807 s.backlog = skb_queue_len(&audit_skb_queue);
795 s.version = AUDIT_VERSION_LATEST; 808 s.version = AUDIT_VERSION_LATEST;
796 s.backlog_wait_time = audit_backlog_wait_time; 809 s.backlog_wait_time = audit_backlog_wait_time;
797 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0, 810 audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &s, sizeof(s));
798 &s, sizeof(s));
799 break; 811 break;
800 } 812 }
801 case AUDIT_SET: { 813 case AUDIT_SET: {
@@ -905,7 +917,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
905 seq, data, nlmsg_len(nlh)); 917 seq, data, nlmsg_len(nlh));
906 break; 918 break;
907 case AUDIT_LIST_RULES: 919 case AUDIT_LIST_RULES:
908 err = audit_list_rules_send(NETLINK_CB(skb).portid, seq); 920 err = audit_list_rules_send(skb, seq);
909 break; 921 break;
910 case AUDIT_TRIM: 922 case AUDIT_TRIM:
911 audit_trim_trees(); 923 audit_trim_trees();
@@ -970,8 +982,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
970 memcpy(sig_data->ctx, ctx, len); 982 memcpy(sig_data->ctx, ctx, len);
971 security_release_secctx(ctx, len); 983 security_release_secctx(ctx, len);
972 } 984 }
973 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_SIGNAL_INFO, 985 audit_send_reply(skb, seq, AUDIT_SIGNAL_INFO, 0, 0,
974 0, 0, sig_data, sizeof(*sig_data) + len); 986 sig_data, sizeof(*sig_data) + len);
975 kfree(sig_data); 987 kfree(sig_data);
976 break; 988 break;
977 case AUDIT_TTY_GET: { 989 case AUDIT_TTY_GET: {
@@ -983,8 +995,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
983 s.log_passwd = tsk->signal->audit_tty_log_passwd; 995 s.log_passwd = tsk->signal->audit_tty_log_passwd;
984 spin_unlock(&tsk->sighand->siglock); 996 spin_unlock(&tsk->sighand->siglock);
985 997
986 audit_send_reply(NETLINK_CB(skb).portid, seq, 998 audit_send_reply(skb, seq, AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
987 AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
988 break; 999 break;
989 } 1000 }
990 case AUDIT_TTY_SET: { 1001 case AUDIT_TTY_SET: {
diff --git a/kernel/audit.h b/kernel/audit.h
index 57cc64d67718..8df132214606 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -247,7 +247,7 @@ extern void audit_panic(const char *message);
247 247
248struct audit_netlink_list { 248struct audit_netlink_list {
249 __u32 portid; 249 __u32 portid;
250 pid_t pid; 250 struct net *net;
251 struct sk_buff_head q; 251 struct sk_buff_head q;
252}; 252};
253 253
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
index 67ccf0e7cca9..135944a7b28a 100644
--- a/kernel/audit_tree.c
+++ b/kernel/audit_tree.c
@@ -916,7 +916,7 @@ static int audit_tree_handle_event(struct fsnotify_group *group,
916 struct fsnotify_mark *inode_mark, 916 struct fsnotify_mark *inode_mark,
917 struct fsnotify_mark *vfsmount_mark, 917 struct fsnotify_mark *vfsmount_mark,
918 u32 mask, void *data, int data_type, 918 u32 mask, void *data, int data_type,
919 const unsigned char *file_name) 919 const unsigned char *file_name, u32 cookie)
920{ 920{
921 return 0; 921 return 0;
922} 922}
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index 2596fac5dcb4..70b4554d2fbe 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -471,7 +471,7 @@ static int audit_watch_handle_event(struct fsnotify_group *group,
471 struct fsnotify_mark *inode_mark, 471 struct fsnotify_mark *inode_mark,
472 struct fsnotify_mark *vfsmount_mark, 472 struct fsnotify_mark *vfsmount_mark,
473 u32 mask, void *data, int data_type, 473 u32 mask, void *data, int data_type,
474 const unsigned char *dname) 474 const unsigned char *dname, u32 cookie)
475{ 475{
476 struct inode *inode; 476 struct inode *inode;
477 struct audit_parent *parent; 477 struct audit_parent *parent;
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index 14a78cca384e..92062fd6cc8c 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -29,6 +29,8 @@
29#include <linux/sched.h> 29#include <linux/sched.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/security.h> 31#include <linux/security.h>
32#include <net/net_namespace.h>
33#include <net/sock.h>
32#include "audit.h" 34#include "audit.h"
33 35
34/* 36/*
@@ -1065,11 +1067,13 @@ int audit_rule_change(int type, __u32 portid, int seq, void *data,
1065 1067
1066/** 1068/**
1067 * audit_list_rules_send - list the audit rules 1069 * audit_list_rules_send - list the audit rules
1068 * @portid: target portid for netlink audit messages 1070 * @request_skb: skb of request we are replying to (used to target the reply)
1069 * @seq: netlink audit message sequence (serial) number 1071 * @seq: netlink audit message sequence (serial) number
1070 */ 1072 */
1071int audit_list_rules_send(__u32 portid, int seq) 1073int audit_list_rules_send(struct sk_buff *request_skb, int seq)
1072{ 1074{
1075 u32 portid = NETLINK_CB(request_skb).portid;
1076 struct net *net = sock_net(NETLINK_CB(request_skb).sk);
1073 struct task_struct *tsk; 1077 struct task_struct *tsk;
1074 struct audit_netlink_list *dest; 1078 struct audit_netlink_list *dest;
1075 int err = 0; 1079 int err = 0;
@@ -1083,8 +1087,8 @@ int audit_list_rules_send(__u32 portid, int seq)
1083 dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL); 1087 dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL);
1084 if (!dest) 1088 if (!dest)
1085 return -ENOMEM; 1089 return -ENOMEM;
1090 dest->net = get_net(net);
1086 dest->portid = portid; 1091 dest->portid = portid;
1087 dest->pid = task_pid_vnr(current);
1088 skb_queue_head_init(&dest->q); 1092 skb_queue_head_init(&dest->q);
1089 1093
1090 mutex_lock(&audit_filter_mutex); 1094 mutex_lock(&audit_filter_mutex);
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 10176cd5956a..7aef2f4b6c64 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1719,7 +1719,7 @@ void audit_putname(struct filename *name)
1719 struct audit_context *context = current->audit_context; 1719 struct audit_context *context = current->audit_context;
1720 1720
1721 BUG_ON(!context); 1721 BUG_ON(!context);
1722 if (!context->in_syscall) { 1722 if (!name->aname || !context->in_syscall) {
1723#if AUDIT_DEBUG == 2 1723#if AUDIT_DEBUG == 2
1724 printk(KERN_ERR "%s:%d(:%d): final_putname(%p)\n", 1724 printk(KERN_ERR "%s:%d(:%d): final_putname(%p)\n",
1725 __FILE__, __LINE__, context->serial, name); 1725 __FILE__, __LINE__, context->serial, name);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index e2f46ba37f72..0c753ddd223b 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -886,7 +886,9 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
886 * per-subsystem and moved to css->id so that lookups are 886 * per-subsystem and moved to css->id so that lookups are
887 * successful until the target css is released. 887 * successful until the target css is released.
888 */ 888 */
889 mutex_lock(&cgroup_mutex);
889 idr_remove(&cgrp->root->cgroup_idr, cgrp->id); 890 idr_remove(&cgrp->root->cgroup_idr, cgrp->id);
891 mutex_unlock(&cgroup_mutex);
890 cgrp->id = -1; 892 cgrp->id = -1;
891 893
892 call_rcu(&cgrp->rcu_head, cgroup_free_rcu); 894 call_rcu(&cgrp->rcu_head, cgroup_free_rcu);
@@ -1566,10 +1568,10 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
1566 mutex_lock(&cgroup_mutex); 1568 mutex_lock(&cgroup_mutex);
1567 mutex_lock(&cgroup_root_mutex); 1569 mutex_lock(&cgroup_root_mutex);
1568 1570
1569 root_cgrp->id = idr_alloc(&root->cgroup_idr, root_cgrp, 1571 ret = idr_alloc(&root->cgroup_idr, root_cgrp, 0, 1, GFP_KERNEL);
1570 0, 1, GFP_KERNEL); 1572 if (ret < 0)
1571 if (root_cgrp->id < 0)
1572 goto unlock_drop; 1573 goto unlock_drop;
1574 root_cgrp->id = ret;
1573 1575
1574 /* Check for name clashes with existing mounts */ 1576 /* Check for name clashes with existing mounts */
1575 ret = -EBUSY; 1577 ret = -EBUSY;
@@ -2763,10 +2765,7 @@ static int cgroup_cfts_commit(struct cftype *cfts, bool is_add)
2763 */ 2765 */
2764 update_before = cgroup_serial_nr_next; 2766 update_before = cgroup_serial_nr_next;
2765 2767
2766 mutex_unlock(&cgroup_mutex);
2767
2768 /* add/rm files for all cgroups created before */ 2768 /* add/rm files for all cgroups created before */
2769 rcu_read_lock();
2770 css_for_each_descendant_pre(css, cgroup_css(root, ss)) { 2769 css_for_each_descendant_pre(css, cgroup_css(root, ss)) {
2771 struct cgroup *cgrp = css->cgroup; 2770 struct cgroup *cgrp = css->cgroup;
2772 2771
@@ -2775,23 +2774,19 @@ static int cgroup_cfts_commit(struct cftype *cfts, bool is_add)
2775 2774
2776 inode = cgrp->dentry->d_inode; 2775 inode = cgrp->dentry->d_inode;
2777 dget(cgrp->dentry); 2776 dget(cgrp->dentry);
2778 rcu_read_unlock();
2779
2780 dput(prev); 2777 dput(prev);
2781 prev = cgrp->dentry; 2778 prev = cgrp->dentry;
2782 2779
2780 mutex_unlock(&cgroup_mutex);
2783 mutex_lock(&inode->i_mutex); 2781 mutex_lock(&inode->i_mutex);
2784 mutex_lock(&cgroup_mutex); 2782 mutex_lock(&cgroup_mutex);
2785 if (cgrp->serial_nr < update_before && !cgroup_is_dead(cgrp)) 2783 if (cgrp->serial_nr < update_before && !cgroup_is_dead(cgrp))
2786 ret = cgroup_addrm_files(cgrp, cfts, is_add); 2784 ret = cgroup_addrm_files(cgrp, cfts, is_add);
2787 mutex_unlock(&cgroup_mutex);
2788 mutex_unlock(&inode->i_mutex); 2785 mutex_unlock(&inode->i_mutex);
2789
2790 rcu_read_lock();
2791 if (ret) 2786 if (ret)
2792 break; 2787 break;
2793 } 2788 }
2794 rcu_read_unlock(); 2789 mutex_unlock(&cgroup_mutex);
2795 dput(prev); 2790 dput(prev);
2796 deactivate_super(sb); 2791 deactivate_super(sb);
2797 return ret; 2792 return ret;
@@ -2910,9 +2905,14 @@ static void cgroup_enable_task_cg_lists(void)
2910 * We should check if the process is exiting, otherwise 2905 * We should check if the process is exiting, otherwise
2911 * it will race with cgroup_exit() in that the list 2906 * it will race with cgroup_exit() in that the list
2912 * entry won't be deleted though the process has exited. 2907 * entry won't be deleted though the process has exited.
2908 * Do it while holding siglock so that we don't end up
2909 * racing against cgroup_exit().
2913 */ 2910 */
2911 spin_lock_irq(&p->sighand->siglock);
2914 if (!(p->flags & PF_EXITING) && list_empty(&p->cg_list)) 2912 if (!(p->flags & PF_EXITING) && list_empty(&p->cg_list))
2915 list_add(&p->cg_list, &task_css_set(p)->tasks); 2913 list_add(&p->cg_list, &task_css_set(p)->tasks);
2914 spin_unlock_irq(&p->sighand->siglock);
2915
2916 task_unlock(p); 2916 task_unlock(p);
2917 } while_each_thread(g, p); 2917 } while_each_thread(g, p);
2918 read_unlock(&tasklist_lock); 2918 read_unlock(&tasklist_lock);
@@ -4112,17 +4112,17 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
4112 4112
4113 err = percpu_ref_init(&css->refcnt, css_release); 4113 err = percpu_ref_init(&css->refcnt, css_release);
4114 if (err) 4114 if (err)
4115 goto err_free; 4115 goto err_free_css;
4116 4116
4117 init_css(css, ss, cgrp); 4117 init_css(css, ss, cgrp);
4118 4118
4119 err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id); 4119 err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id);
4120 if (err) 4120 if (err)
4121 goto err_free; 4121 goto err_free_percpu_ref;
4122 4122
4123 err = online_css(css); 4123 err = online_css(css);
4124 if (err) 4124 if (err)
4125 goto err_free; 4125 goto err_clear_dir;
4126 4126
4127 dget(cgrp->dentry); 4127 dget(cgrp->dentry);
4128 css_get(css->parent); 4128 css_get(css->parent);
@@ -4138,8 +4138,11 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
4138 4138
4139 return 0; 4139 return 0;
4140 4140
4141err_free: 4141err_clear_dir:
4142 cgroup_clear_dir(css->cgroup, 1 << css->ss->subsys_id);
4143err_free_percpu_ref:
4142 percpu_ref_cancel_init(&css->refcnt); 4144 percpu_ref_cancel_init(&css->refcnt);
4145err_free_css:
4143 ss->css_free(css); 4146 ss->css_free(css);
4144 return err; 4147 return err;
4145} 4148}
@@ -4158,7 +4161,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4158 struct cgroup *cgrp; 4161 struct cgroup *cgrp;
4159 struct cgroup_name *name; 4162 struct cgroup_name *name;
4160 struct cgroupfs_root *root = parent->root; 4163 struct cgroupfs_root *root = parent->root;
4161 int ssid, err = 0; 4164 int ssid, err;
4162 struct cgroup_subsys *ss; 4165 struct cgroup_subsys *ss;
4163 struct super_block *sb = root->sb; 4166 struct super_block *sb = root->sb;
4164 4167
@@ -4168,19 +4171,13 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4168 return -ENOMEM; 4171 return -ENOMEM;
4169 4172
4170 name = cgroup_alloc_name(dentry); 4173 name = cgroup_alloc_name(dentry);
4171 if (!name) 4174 if (!name) {
4175 err = -ENOMEM;
4172 goto err_free_cgrp; 4176 goto err_free_cgrp;
4177 }
4173 rcu_assign_pointer(cgrp->name, name); 4178 rcu_assign_pointer(cgrp->name, name);
4174 4179
4175 /* 4180 /*
4176 * Temporarily set the pointer to NULL, so idr_find() won't return
4177 * a half-baked cgroup.
4178 */
4179 cgrp->id = idr_alloc(&root->cgroup_idr, NULL, 1, 0, GFP_KERNEL);
4180 if (cgrp->id < 0)
4181 goto err_free_name;
4182
4183 /*
4184 * Only live parents can have children. Note that the liveliness 4181 * Only live parents can have children. Note that the liveliness
4185 * check isn't strictly necessary because cgroup_mkdir() and 4182 * check isn't strictly necessary because cgroup_mkdir() and
4186 * cgroup_rmdir() are fully synchronized by i_mutex; however, do it 4183 * cgroup_rmdir() are fully synchronized by i_mutex; however, do it
@@ -4189,7 +4186,17 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4189 */ 4186 */
4190 if (!cgroup_lock_live_group(parent)) { 4187 if (!cgroup_lock_live_group(parent)) {
4191 err = -ENODEV; 4188 err = -ENODEV;
4192 goto err_free_id; 4189 goto err_free_name;
4190 }
4191
4192 /*
4193 * Temporarily set the pointer to NULL, so idr_find() won't return
4194 * a half-baked cgroup.
4195 */
4196 cgrp->id = idr_alloc(&root->cgroup_idr, NULL, 1, 0, GFP_KERNEL);
4197 if (cgrp->id < 0) {
4198 err = -ENOMEM;
4199 goto err_unlock;
4193 } 4200 }
4194 4201
4195 /* Grab a reference on the superblock so the hierarchy doesn't 4202 /* Grab a reference on the superblock so the hierarchy doesn't
@@ -4221,7 +4228,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4221 */ 4228 */
4222 err = cgroup_create_file(dentry, S_IFDIR | mode, sb); 4229 err = cgroup_create_file(dentry, S_IFDIR | mode, sb);
4223 if (err < 0) 4230 if (err < 0)
4224 goto err_unlock; 4231 goto err_free_id;
4225 lockdep_assert_held(&dentry->d_inode->i_mutex); 4232 lockdep_assert_held(&dentry->d_inode->i_mutex);
4226 4233
4227 cgrp->serial_nr = cgroup_serial_nr_next++; 4234 cgrp->serial_nr = cgroup_serial_nr_next++;
@@ -4257,12 +4264,12 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4257 4264
4258 return 0; 4265 return 0;
4259 4266
4260err_unlock:
4261 mutex_unlock(&cgroup_mutex);
4262 /* Release the reference count that we took on the superblock */
4263 deactivate_super(sb);
4264err_free_id: 4267err_free_id:
4265 idr_remove(&root->cgroup_idr, cgrp->id); 4268 idr_remove(&root->cgroup_idr, cgrp->id);
4269 /* Release the reference count that we took on the superblock */
4270 deactivate_super(sb);
4271err_unlock:
4272 mutex_unlock(&cgroup_mutex);
4266err_free_name: 4273err_free_name:
4267 kfree(rcu_dereference_raw(cgrp->name)); 4274 kfree(rcu_dereference_raw(cgrp->name));
4268err_free_cgrp: 4275err_free_cgrp:
diff --git a/kernel/compat.c b/kernel/compat.c
index 0a09e481b70b..488ff8c4cf48 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -110,8 +110,8 @@ static int compat_put_timex(struct compat_timex __user *utp, struct timex *txc)
110 return 0; 110 return 0;
111} 111}
112 112
113asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, 113COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv,
114 struct timezone __user *tz) 114 struct timezone __user *, tz)
115{ 115{
116 if (tv) { 116 if (tv) {
117 struct timeval ktv; 117 struct timeval ktv;
@@ -127,8 +127,8 @@ asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
127 return 0; 127 return 0;
128} 128}
129 129
130asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, 130COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval __user *, tv,
131 struct timezone __user *tz) 131 struct timezone __user *, tz)
132{ 132{
133 struct timespec kts; 133 struct timespec kts;
134 struct timezone ktz; 134 struct timezone ktz;
@@ -236,8 +236,8 @@ static long compat_nanosleep_restart(struct restart_block *restart)
236 return ret; 236 return ret;
237} 237}
238 238
239asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp, 239COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
240 struct compat_timespec __user *rmtp) 240 struct compat_timespec __user *, rmtp)
241{ 241{
242 struct timespec tu, rmt; 242 struct timespec tu, rmt;
243 mm_segment_t oldfs; 243 mm_segment_t oldfs;
@@ -328,7 +328,7 @@ static compat_clock_t clock_t_to_compat_clock_t(clock_t x)
328 return compat_jiffies_to_clock_t(clock_t_to_jiffies(x)); 328 return compat_jiffies_to_clock_t(clock_t_to_jiffies(x));
329} 329}
330 330
331asmlinkage long compat_sys_times(struct compat_tms __user *tbuf) 331COMPAT_SYSCALL_DEFINE1(times, struct compat_tms __user *, tbuf)
332{ 332{
333 if (tbuf) { 333 if (tbuf) {
334 struct tms tms; 334 struct tms tms;
@@ -354,7 +354,7 @@ asmlinkage long compat_sys_times(struct compat_tms __user *tbuf)
354 * types that can be passed to put_user()/get_user(). 354 * types that can be passed to put_user()/get_user().
355 */ 355 */
356 356
357asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set) 357COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
358{ 358{
359 old_sigset_t s; 359 old_sigset_t s;
360 long ret; 360 long ret;
@@ -424,8 +424,8 @@ COMPAT_SYSCALL_DEFINE3(sigprocmask, int, how,
424 424
425#endif 425#endif
426 426
427asmlinkage long compat_sys_setrlimit(unsigned int resource, 427COMPAT_SYSCALL_DEFINE2(setrlimit, unsigned int, resource,
428 struct compat_rlimit __user *rlim) 428 struct compat_rlimit __user *, rlim)
429{ 429{
430 struct rlimit r; 430 struct rlimit r;
431 431
@@ -443,8 +443,8 @@ asmlinkage long compat_sys_setrlimit(unsigned int resource,
443 443
444#ifdef COMPAT_RLIM_OLD_INFINITY 444#ifdef COMPAT_RLIM_OLD_INFINITY
445 445
446asmlinkage long compat_sys_old_getrlimit(unsigned int resource, 446COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
447 struct compat_rlimit __user *rlim) 447 struct compat_rlimit __user *, rlim)
448{ 448{
449 struct rlimit r; 449 struct rlimit r;
450 int ret; 450 int ret;
@@ -470,8 +470,8 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
470 470
471#endif 471#endif
472 472
473asmlinkage long compat_sys_getrlimit(unsigned int resource, 473COMPAT_SYSCALL_DEFINE2(getrlimit, unsigned int, resource,
474 struct compat_rlimit __user *rlim) 474 struct compat_rlimit __user *, rlim)
475{ 475{
476 struct rlimit r; 476 struct rlimit r;
477 int ret; 477 int ret;
@@ -596,9 +596,9 @@ static int compat_get_user_cpu_mask(compat_ulong_t __user *user_mask_ptr,
596 return compat_get_bitmap(k, user_mask_ptr, len * 8); 596 return compat_get_bitmap(k, user_mask_ptr, len * 8);
597} 597}
598 598
599asmlinkage long compat_sys_sched_setaffinity(compat_pid_t pid, 599COMPAT_SYSCALL_DEFINE3(sched_setaffinity, compat_pid_t, pid,
600 unsigned int len, 600 unsigned int, len,
601 compat_ulong_t __user *user_mask_ptr) 601 compat_ulong_t __user *, user_mask_ptr)
602{ 602{
603 cpumask_var_t new_mask; 603 cpumask_var_t new_mask;
604 int retval; 604 int retval;
@@ -616,8 +616,8 @@ out:
616 return retval; 616 return retval;
617} 617}
618 618
619asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid, unsigned int len, 619COMPAT_SYSCALL_DEFINE3(sched_getaffinity, compat_pid_t, pid, unsigned int, len,
620 compat_ulong_t __user *user_mask_ptr) 620 compat_ulong_t __user *, user_mask_ptr)
621{ 621{
622 int ret; 622 int ret;
623 cpumask_var_t mask; 623 cpumask_var_t mask;
@@ -662,9 +662,9 @@ int put_compat_itimerspec(struct compat_itimerspec __user *dst,
662 return 0; 662 return 0;
663} 663}
664 664
665long compat_sys_timer_create(clockid_t which_clock, 665COMPAT_SYSCALL_DEFINE3(timer_create, clockid_t, which_clock,
666 struct compat_sigevent __user *timer_event_spec, 666 struct compat_sigevent __user *, timer_event_spec,
667 timer_t __user *created_timer_id) 667 timer_t __user *, created_timer_id)
668{ 668{
669 struct sigevent __user *event = NULL; 669 struct sigevent __user *event = NULL;
670 670
@@ -680,9 +680,9 @@ long compat_sys_timer_create(clockid_t which_clock,
680 return sys_timer_create(which_clock, event, created_timer_id); 680 return sys_timer_create(which_clock, event, created_timer_id);
681} 681}
682 682
683long compat_sys_timer_settime(timer_t timer_id, int flags, 683COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
684 struct compat_itimerspec __user *new, 684 struct compat_itimerspec __user *, new,
685 struct compat_itimerspec __user *old) 685 struct compat_itimerspec __user *, old)
686{ 686{
687 long err; 687 long err;
688 mm_segment_t oldfs; 688 mm_segment_t oldfs;
@@ -703,8 +703,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
703 return err; 703 return err;
704} 704}
705 705
706long compat_sys_timer_gettime(timer_t timer_id, 706COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
707 struct compat_itimerspec __user *setting) 707 struct compat_itimerspec __user *, setting)
708{ 708{
709 long err; 709 long err;
710 mm_segment_t oldfs; 710 mm_segment_t oldfs;
@@ -720,8 +720,8 @@ long compat_sys_timer_gettime(timer_t timer_id,
720 return err; 720 return err;
721} 721}
722 722
723long compat_sys_clock_settime(clockid_t which_clock, 723COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
724 struct compat_timespec __user *tp) 724 struct compat_timespec __user *, tp)
725{ 725{
726 long err; 726 long err;
727 mm_segment_t oldfs; 727 mm_segment_t oldfs;
@@ -737,8 +737,8 @@ long compat_sys_clock_settime(clockid_t which_clock,
737 return err; 737 return err;
738} 738}
739 739
740long compat_sys_clock_gettime(clockid_t which_clock, 740COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
741 struct compat_timespec __user *tp) 741 struct compat_timespec __user *, tp)
742{ 742{
743 long err; 743 long err;
744 mm_segment_t oldfs; 744 mm_segment_t oldfs;
@@ -754,8 +754,8 @@ long compat_sys_clock_gettime(clockid_t which_clock,
754 return err; 754 return err;
755} 755}
756 756
757long compat_sys_clock_adjtime(clockid_t which_clock, 757COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
758 struct compat_timex __user *utp) 758 struct compat_timex __user *, utp)
759{ 759{
760 struct timex txc; 760 struct timex txc;
761 mm_segment_t oldfs; 761 mm_segment_t oldfs;
@@ -777,8 +777,8 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
777 return ret; 777 return ret;
778} 778}
779 779
780long compat_sys_clock_getres(clockid_t which_clock, 780COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
781 struct compat_timespec __user *tp) 781 struct compat_timespec __user *, tp)
782{ 782{
783 long err; 783 long err;
784 mm_segment_t oldfs; 784 mm_segment_t oldfs;
@@ -818,9 +818,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
818 return err; 818 return err;
819} 819}
820 820
821long compat_sys_clock_nanosleep(clockid_t which_clock, int flags, 821COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
822 struct compat_timespec __user *rqtp, 822 struct compat_timespec __user *, rqtp,
823 struct compat_timespec __user *rmtp) 823 struct compat_timespec __user *, rmtp)
824{ 824{
825 long err; 825 long err;
826 mm_segment_t oldfs; 826 mm_segment_t oldfs;
@@ -1010,7 +1010,7 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese,
1010 1010
1011/* compat_time_t is a 32 bit "long" and needs to get converted. */ 1011/* compat_time_t is a 32 bit "long" and needs to get converted. */
1012 1012
1013asmlinkage long compat_sys_time(compat_time_t __user * tloc) 1013COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc)
1014{ 1014{
1015 compat_time_t i; 1015 compat_time_t i;
1016 struct timeval tv; 1016 struct timeval tv;
@@ -1026,7 +1026,7 @@ asmlinkage long compat_sys_time(compat_time_t __user * tloc)
1026 return i; 1026 return i;
1027} 1027}
1028 1028
1029asmlinkage long compat_sys_stime(compat_time_t __user *tptr) 1029COMPAT_SYSCALL_DEFINE1(stime, compat_time_t __user *, tptr)
1030{ 1030{
1031 struct timespec tv; 1031 struct timespec tv;
1032 int err; 1032 int err;
@@ -1046,7 +1046,7 @@ asmlinkage long compat_sys_stime(compat_time_t __user *tptr)
1046 1046
1047#endif /* __ARCH_WANT_COMPAT_SYS_TIME */ 1047#endif /* __ARCH_WANT_COMPAT_SYS_TIME */
1048 1048
1049asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp) 1049COMPAT_SYSCALL_DEFINE1(adjtimex, struct compat_timex __user *, utp)
1050{ 1050{
1051 struct timex txc; 1051 struct timex txc;
1052 int err, ret; 1052 int err, ret;
@@ -1065,11 +1065,11 @@ asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp)
1065} 1065}
1066 1066
1067#ifdef CONFIG_NUMA 1067#ifdef CONFIG_NUMA
1068asmlinkage long compat_sys_move_pages(pid_t pid, unsigned long nr_pages, 1068COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages,
1069 compat_uptr_t __user *pages32, 1069 compat_uptr_t __user *, pages32,
1070 const int __user *nodes, 1070 const int __user *, nodes,
1071 int __user *status, 1071 int __user *, status,
1072 int flags) 1072 int, flags)
1073{ 1073{
1074 const void __user * __user *pages; 1074 const void __user * __user *pages;
1075 int i; 1075 int i;
@@ -1085,10 +1085,10 @@ asmlinkage long compat_sys_move_pages(pid_t pid, unsigned long nr_pages,
1085 return sys_move_pages(pid, nr_pages, pages, nodes, status, flags); 1085 return sys_move_pages(pid, nr_pages, pages, nodes, status, flags);
1086} 1086}
1087 1087
1088asmlinkage long compat_sys_migrate_pages(compat_pid_t pid, 1088COMPAT_SYSCALL_DEFINE4(migrate_pages, compat_pid_t, pid,
1089 compat_ulong_t maxnode, 1089 compat_ulong_t, maxnode,
1090 const compat_ulong_t __user *old_nodes, 1090 const compat_ulong_t __user *, old_nodes,
1091 const compat_ulong_t __user *new_nodes) 1091 const compat_ulong_t __user *, new_nodes)
1092{ 1092{
1093 unsigned long __user *old = NULL; 1093 unsigned long __user *old = NULL;
1094 unsigned long __user *new = NULL; 1094 unsigned long __user *new = NULL;
diff --git a/kernel/cpu/Makefile b/kernel/cpu/Makefile
deleted file mode 100644
index 59ab052ef7a0..000000000000
--- a/kernel/cpu/Makefile
+++ /dev/null
@@ -1 +0,0 @@
1obj-y = idle.o
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 4410ac6a55f1..e6b1b66afe52 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -974,12 +974,6 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
974 * Temporarilly set tasks mems_allowed to target nodes of migration, 974 * Temporarilly set tasks mems_allowed to target nodes of migration,
975 * so that the migration code can allocate pages on these nodes. 975 * so that the migration code can allocate pages on these nodes.
976 * 976 *
977 * Call holding cpuset_mutex, so current's cpuset won't change
978 * during this call, as manage_mutex holds off any cpuset_attach()
979 * calls. Therefore we don't need to take task_lock around the
980 * call to guarantee_online_mems(), as we know no one is changing
981 * our task's cpuset.
982 *
983 * While the mm_struct we are migrating is typically from some 977 * While the mm_struct we are migrating is typically from some
984 * other task, the task_struct mems_allowed that we are hacking 978 * other task, the task_struct mems_allowed that we are hacking
985 * is for our current task, which must allocate new pages for that 979 * is for our current task, which must allocate new pages for that
@@ -996,8 +990,10 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from,
996 990
997 do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL); 991 do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL);
998 992
993 rcu_read_lock();
999 mems_cs = effective_nodemask_cpuset(task_cs(tsk)); 994 mems_cs = effective_nodemask_cpuset(task_cs(tsk));
1000 guarantee_online_mems(mems_cs, &tsk->mems_allowed); 995 guarantee_online_mems(mems_cs, &tsk->mems_allowed);
996 rcu_read_unlock();
1001} 997}
1002 998
1003/* 999/*
@@ -2486,9 +2482,9 @@ int __cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
2486 2482
2487 task_lock(current); 2483 task_lock(current);
2488 cs = nearest_hardwall_ancestor(task_cs(current)); 2484 cs = nearest_hardwall_ancestor(task_cs(current));
2485 allowed = node_isset(node, cs->mems_allowed);
2489 task_unlock(current); 2486 task_unlock(current);
2490 2487
2491 allowed = node_isset(node, cs->mems_allowed);
2492 mutex_unlock(&callback_mutex); 2488 mutex_unlock(&callback_mutex);
2493 return allowed; 2489 return allowed;
2494} 2490}
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 334b3980ffc1..99982a70ddad 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -1035,7 +1035,7 @@ int dbg_io_get_char(void)
1035 * otherwise as a quick means to stop program execution and "break" into 1035 * otherwise as a quick means to stop program execution and "break" into
1036 * the debugger. 1036 * the debugger.
1037 */ 1037 */
1038void kgdb_breakpoint(void) 1038noinline void kgdb_breakpoint(void)
1039{ 1039{
1040 atomic_inc(&kgdb_setting_breakpoint); 1040 atomic_inc(&kgdb_setting_breakpoint);
1041 wmb(); /* Sync point before breakpoint */ 1041 wmb(); /* Sync point before breakpoint */
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 56003c6edfd3..661951ab8ae7 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -231,11 +231,29 @@ int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
231#define NR_ACCUMULATED_SAMPLES 128 231#define NR_ACCUMULATED_SAMPLES 128
232static DEFINE_PER_CPU(u64, running_sample_length); 232static DEFINE_PER_CPU(u64, running_sample_length);
233 233
234void perf_sample_event_took(u64 sample_len_ns) 234static void perf_duration_warn(struct irq_work *w)
235{ 235{
236 u64 allowed_ns = ACCESS_ONCE(perf_sample_allowed_ns);
236 u64 avg_local_sample_len; 237 u64 avg_local_sample_len;
237 u64 local_samples_len; 238 u64 local_samples_len;
239
240 local_samples_len = __get_cpu_var(running_sample_length);
241 avg_local_sample_len = local_samples_len/NR_ACCUMULATED_SAMPLES;
242
243 printk_ratelimited(KERN_WARNING
244 "perf interrupt took too long (%lld > %lld), lowering "
245 "kernel.perf_event_max_sample_rate to %d\n",
246 avg_local_sample_len, allowed_ns >> 1,
247 sysctl_perf_event_sample_rate);
248}
249
250static DEFINE_IRQ_WORK(perf_duration_work, perf_duration_warn);
251
252void perf_sample_event_took(u64 sample_len_ns)
253{
238 u64 allowed_ns = ACCESS_ONCE(perf_sample_allowed_ns); 254 u64 allowed_ns = ACCESS_ONCE(perf_sample_allowed_ns);
255 u64 avg_local_sample_len;
256 u64 local_samples_len;
239 257
240 if (allowed_ns == 0) 258 if (allowed_ns == 0)
241 return; 259 return;
@@ -263,13 +281,14 @@ void perf_sample_event_took(u64 sample_len_ns)
263 sysctl_perf_event_sample_rate = max_samples_per_tick * HZ; 281 sysctl_perf_event_sample_rate = max_samples_per_tick * HZ;
264 perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate; 282 perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate;
265 283
266 printk_ratelimited(KERN_WARNING
267 "perf samples too long (%lld > %lld), lowering "
268 "kernel.perf_event_max_sample_rate to %d\n",
269 avg_local_sample_len, allowed_ns,
270 sysctl_perf_event_sample_rate);
271
272 update_perf_cpu_limits(); 284 update_perf_cpu_limits();
285
286 if (!irq_work_queue(&perf_duration_work)) {
287 early_printk("perf interrupt took too long (%lld > %lld), lowering "
288 "kernel.perf_event_max_sample_rate to %d\n",
289 avg_local_sample_len, allowed_ns >> 1,
290 sysctl_perf_event_sample_rate);
291 }
273} 292}
274 293
275static atomic64_t perf_event_id; 294static atomic64_t perf_event_id;
@@ -1714,7 +1733,7 @@ group_sched_in(struct perf_event *group_event,
1714 struct perf_event_context *ctx) 1733 struct perf_event_context *ctx)
1715{ 1734{
1716 struct perf_event *event, *partial_group = NULL; 1735 struct perf_event *event, *partial_group = NULL;
1717 struct pmu *pmu = group_event->pmu; 1736 struct pmu *pmu = ctx->pmu;
1718 u64 now = ctx->time; 1737 u64 now = ctx->time;
1719 bool simulate = false; 1738 bool simulate = false;
1720 1739
@@ -2563,8 +2582,6 @@ static void perf_branch_stack_sched_in(struct task_struct *prev,
2563 if (cpuctx->ctx.nr_branch_stack > 0 2582 if (cpuctx->ctx.nr_branch_stack > 0
2564 && pmu->flush_branch_stack) { 2583 && pmu->flush_branch_stack) {
2565 2584
2566 pmu = cpuctx->ctx.pmu;
2567
2568 perf_ctx_lock(cpuctx, cpuctx->task_ctx); 2585 perf_ctx_lock(cpuctx, cpuctx->task_ctx);
2569 2586
2570 perf_pmu_disable(pmu); 2587 perf_pmu_disable(pmu);
@@ -6294,7 +6311,7 @@ static int perf_event_idx_default(struct perf_event *event)
6294 * Ensures all contexts with the same task_ctx_nr have the same 6311 * Ensures all contexts with the same task_ctx_nr have the same
6295 * pmu_cpu_context too. 6312 * pmu_cpu_context too.
6296 */ 6313 */
6297static void *find_pmu_context(int ctxn) 6314static struct perf_cpu_context __percpu *find_pmu_context(int ctxn)
6298{ 6315{
6299 struct pmu *pmu; 6316 struct pmu *pmu;
6300 6317
@@ -7856,14 +7873,14 @@ static void perf_pmu_rotate_stop(struct pmu *pmu)
7856static void __perf_event_exit_context(void *__info) 7873static void __perf_event_exit_context(void *__info)
7857{ 7874{
7858 struct perf_event_context *ctx = __info; 7875 struct perf_event_context *ctx = __info;
7859 struct perf_event *event, *tmp; 7876 struct perf_event *event;
7860 7877
7861 perf_pmu_rotate_stop(ctx->pmu); 7878 perf_pmu_rotate_stop(ctx->pmu);
7862 7879
7863 list_for_each_entry_safe(event, tmp, &ctx->pinned_groups, group_entry) 7880 rcu_read_lock();
7864 __perf_remove_from_context(event); 7881 list_for_each_entry_rcu(event, &ctx->event_list, event_entry)
7865 list_for_each_entry_safe(event, tmp, &ctx->flexible_groups, group_entry)
7866 __perf_remove_from_context(event); 7882 __perf_remove_from_context(event);
7883 rcu_read_unlock();
7867} 7884}
7868 7885
7869static void perf_event_exit_cpu_context(int cpu) 7886static void perf_event_exit_cpu_context(int cpu)
@@ -7887,11 +7904,11 @@ static void perf_event_exit_cpu(int cpu)
7887{ 7904{
7888 struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu); 7905 struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
7889 7906
7907 perf_event_exit_cpu_context(cpu);
7908
7890 mutex_lock(&swhash->hlist_mutex); 7909 mutex_lock(&swhash->hlist_mutex);
7891 swevent_hlist_release(swhash); 7910 swevent_hlist_release(swhash);
7892 mutex_unlock(&swhash->hlist_mutex); 7911 mutex_unlock(&swhash->hlist_mutex);
7893
7894 perf_event_exit_cpu_context(cpu);
7895} 7912}
7896#else 7913#else
7897static inline void perf_event_exit_cpu(int cpu) { } 7914static inline void perf_event_exit_cpu(int cpu) { }
diff --git a/kernel/extable.c b/kernel/extable.c
index 763faf037ec1..d8a6446adbcb 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -36,7 +36,7 @@ extern struct exception_table_entry __start___ex_table[];
36extern struct exception_table_entry __stop___ex_table[]; 36extern struct exception_table_entry __stop___ex_table[];
37 37
38/* Cleared by build time tools if the table is already sorted. */ 38/* Cleared by build time tools if the table is already sorted. */
39u32 __initdata main_extable_sort_needed = 1; 39u32 __initdata __visible main_extable_sort_needed = 1;
40 40
41/* Sort the kernel's built-in exception table */ 41/* Sort the kernel's built-in exception table */
42void __init sort_main_extable(void) 42void __init sort_main_extable(void)
diff --git a/kernel/fork.c b/kernel/fork.c
index a17621c6cd42..332688e5e7b4 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -237,6 +237,7 @@ void __put_task_struct(struct task_struct *tsk)
237 WARN_ON(atomic_read(&tsk->usage)); 237 WARN_ON(atomic_read(&tsk->usage));
238 WARN_ON(tsk == current); 238 WARN_ON(tsk == current);
239 239
240 task_numa_free(tsk);
240 security_task_free(tsk); 241 security_task_free(tsk);
241 exit_creds(tsk); 242 exit_creds(tsk);
242 delayacct_tsk_free(tsk); 243 delayacct_tsk_free(tsk);
diff --git a/kernel/futex.c b/kernel/futex.c
index 44a1261cb9ff..67dacaf93e56 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -157,7 +157,9 @@
157 * enqueue. 157 * enqueue.
158 */ 158 */
159 159
160#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
160int __read_mostly futex_cmpxchg_enabled; 161int __read_mostly futex_cmpxchg_enabled;
162#endif
161 163
162/* 164/*
163 * Futex flags used to encode options to functions and preserve them across 165 * Futex flags used to encode options to functions and preserve them across
@@ -234,6 +236,7 @@ static const struct futex_q futex_q_init = {
234 * waiting on a futex. 236 * waiting on a futex.
235 */ 237 */
236struct futex_hash_bucket { 238struct futex_hash_bucket {
239 atomic_t waiters;
237 spinlock_t lock; 240 spinlock_t lock;
238 struct plist_head chain; 241 struct plist_head chain;
239} ____cacheline_aligned_in_smp; 242} ____cacheline_aligned_in_smp;
@@ -253,22 +256,37 @@ static inline void futex_get_mm(union futex_key *key)
253 smp_mb__after_atomic_inc(); 256 smp_mb__after_atomic_inc();
254} 257}
255 258
256static inline bool hb_waiters_pending(struct futex_hash_bucket *hb) 259/*
260 * Reflects a new waiter being added to the waitqueue.
261 */
262static inline void hb_waiters_inc(struct futex_hash_bucket *hb)
257{ 263{
258#ifdef CONFIG_SMP 264#ifdef CONFIG_SMP
265 atomic_inc(&hb->waiters);
259 /* 266 /*
260 * Tasks trying to enter the critical region are most likely 267 * Full barrier (A), see the ordering comment above.
261 * potential waiters that will be added to the plist. Ensure
262 * that wakers won't miss to-be-slept tasks in the window between
263 * the wait call and the actual plist_add.
264 */ 268 */
265 if (spin_is_locked(&hb->lock)) 269 smp_mb__after_atomic_inc();
266 return true; 270#endif
267 smp_rmb(); /* Make sure we check the lock state first */ 271}
272
273/*
274 * Reflects a waiter being removed from the waitqueue by wakeup
275 * paths.
276 */
277static inline void hb_waiters_dec(struct futex_hash_bucket *hb)
278{
279#ifdef CONFIG_SMP
280 atomic_dec(&hb->waiters);
281#endif
282}
268 283
269 return !plist_head_empty(&hb->chain); 284static inline int hb_waiters_pending(struct futex_hash_bucket *hb)
285{
286#ifdef CONFIG_SMP
287 return atomic_read(&hb->waiters);
270#else 288#else
271 return true; 289 return 1;
272#endif 290#endif
273} 291}
274 292
@@ -954,6 +972,7 @@ static void __unqueue_futex(struct futex_q *q)
954 972
955 hb = container_of(q->lock_ptr, struct futex_hash_bucket, lock); 973 hb = container_of(q->lock_ptr, struct futex_hash_bucket, lock);
956 plist_del(&q->list, &hb->chain); 974 plist_del(&q->list, &hb->chain);
975 hb_waiters_dec(hb);
957} 976}
958 977
959/* 978/*
@@ -1257,7 +1276,9 @@ void requeue_futex(struct futex_q *q, struct futex_hash_bucket *hb1,
1257 */ 1276 */
1258 if (likely(&hb1->chain != &hb2->chain)) { 1277 if (likely(&hb1->chain != &hb2->chain)) {
1259 plist_del(&q->list, &hb1->chain); 1278 plist_del(&q->list, &hb1->chain);
1279 hb_waiters_dec(hb1);
1260 plist_add(&q->list, &hb2->chain); 1280 plist_add(&q->list, &hb2->chain);
1281 hb_waiters_inc(hb2);
1261 q->lock_ptr = &hb2->lock; 1282 q->lock_ptr = &hb2->lock;
1262 } 1283 }
1263 get_futex_key_refs(key2); 1284 get_futex_key_refs(key2);
@@ -1600,6 +1621,17 @@ static inline struct futex_hash_bucket *queue_lock(struct futex_q *q)
1600 struct futex_hash_bucket *hb; 1621 struct futex_hash_bucket *hb;
1601 1622
1602 hb = hash_futex(&q->key); 1623 hb = hash_futex(&q->key);
1624
1625 /*
1626 * Increment the counter before taking the lock so that
1627 * a potential waker won't miss a to-be-slept task that is
1628 * waiting for the spinlock. This is safe as all queue_lock()
1629 * users end up calling queue_me(). Similarly, for housekeeping,
1630 * decrement the counter at queue_unlock() when some error has
1631 * occurred and we don't end up adding the task to the list.
1632 */
1633 hb_waiters_inc(hb);
1634
1603 q->lock_ptr = &hb->lock; 1635 q->lock_ptr = &hb->lock;
1604 1636
1605 spin_lock(&hb->lock); /* implies MB (A) */ 1637 spin_lock(&hb->lock); /* implies MB (A) */
@@ -1611,6 +1643,7 @@ queue_unlock(struct futex_hash_bucket *hb)
1611 __releases(&hb->lock) 1643 __releases(&hb->lock)
1612{ 1644{
1613 spin_unlock(&hb->lock); 1645 spin_unlock(&hb->lock);
1646 hb_waiters_dec(hb);
1614} 1647}
1615 1648
1616/** 1649/**
@@ -2342,6 +2375,7 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,
2342 * Unqueue the futex_q and determine which it was. 2375 * Unqueue the futex_q and determine which it was.
2343 */ 2376 */
2344 plist_del(&q->list, &hb->chain); 2377 plist_del(&q->list, &hb->chain);
2378 hb_waiters_dec(hb);
2345 2379
2346 /* Handle spurious wakeups gracefully */ 2380 /* Handle spurious wakeups gracefully */
2347 ret = -EWOULDBLOCK; 2381 ret = -EWOULDBLOCK;
@@ -2843,9 +2877,28 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
2843 return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); 2877 return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
2844} 2878}
2845 2879
2846static int __init futex_init(void) 2880static void __init futex_detect_cmpxchg(void)
2847{ 2881{
2882#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
2848 u32 curval; 2883 u32 curval;
2884
2885 /*
2886 * This will fail and we want it. Some arch implementations do
2887 * runtime detection of the futex_atomic_cmpxchg_inatomic()
2888 * functionality. We want to know that before we call in any
2889 * of the complex code paths. Also we want to prevent
2890 * registration of robust lists in that case. NULL is
2891 * guaranteed to fault and we get -EFAULT on functional
2892 * implementation, the non-functional ones will return
2893 * -ENOSYS.
2894 */
2895 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
2896 futex_cmpxchg_enabled = 1;
2897#endif
2898}
2899
2900static int __init futex_init(void)
2901{
2849 unsigned int futex_shift; 2902 unsigned int futex_shift;
2850 unsigned long i; 2903 unsigned long i;
2851 2904
@@ -2861,20 +2914,11 @@ static int __init futex_init(void)
2861 &futex_shift, NULL, 2914 &futex_shift, NULL,
2862 futex_hashsize, futex_hashsize); 2915 futex_hashsize, futex_hashsize);
2863 futex_hashsize = 1UL << futex_shift; 2916 futex_hashsize = 1UL << futex_shift;
2864 /* 2917
2865 * This will fail and we want it. Some arch implementations do 2918 futex_detect_cmpxchg();
2866 * runtime detection of the futex_atomic_cmpxchg_inatomic()
2867 * functionality. We want to know that before we call in any
2868 * of the complex code paths. Also we want to prevent
2869 * registration of robust lists in that case. NULL is
2870 * guaranteed to fault and we get -EFAULT on functional
2871 * implementation, the non-functional ones will return
2872 * -ENOSYS.
2873 */
2874 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
2875 futex_cmpxchg_enabled = 1;
2876 2919
2877 for (i = 0; i < futex_hashsize; i++) { 2920 for (i = 0; i < futex_hashsize; i++) {
2921 atomic_set(&futex_queues[i].waiters, 0);
2878 plist_head_init(&futex_queues[i].chain); 2922 plist_head_init(&futex_queues[i].chain);
2879 spin_lock_init(&futex_queues[i].lock); 2923 spin_lock_init(&futex_queues[i].lock);
2880 } 2924 }
diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig
index 4a1fef09f658..07cbdfea9ae2 100644
--- a/kernel/irq/Kconfig
+++ b/kernel/irq/Kconfig
@@ -40,6 +40,7 @@ config IRQ_EDGE_EOI_HANDLER
40# Generic configurable interrupt chip implementation 40# Generic configurable interrupt chip implementation
41config GENERIC_IRQ_CHIP 41config GENERIC_IRQ_CHIP
42 bool 42 bool
43 select IRQ_DOMAIN
43 44
44# Generic irq_domain hw <--> linux irq number translation 45# Generic irq_domain hw <--> linux irq number translation
45config IRQ_DOMAIN 46config IRQ_DOMAIN
diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
index bd8e788d71e0..1ef0606797c9 100644
--- a/kernel/irq/devres.c
+++ b/kernel/irq/devres.c
@@ -73,6 +73,51 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
73EXPORT_SYMBOL(devm_request_threaded_irq); 73EXPORT_SYMBOL(devm_request_threaded_irq);
74 74
75/** 75/**
76 * devm_request_any_context_irq - allocate an interrupt line for a managed device
77 * @dev: device to request interrupt for
78 * @irq: Interrupt line to allocate
79 * @handler: Function to be called when the IRQ occurs
80 * @thread_fn: function to be called in a threaded interrupt context. NULL
81 * for devices which handle everything in @handler
82 * @irqflags: Interrupt type flags
83 * @devname: An ascii name for the claiming device
84 * @dev_id: A cookie passed back to the handler function
85 *
86 * Except for the extra @dev argument, this function takes the
87 * same arguments and performs the same function as
88 * request_any_context_irq(). IRQs requested with this function will be
89 * automatically freed on driver detach.
90 *
91 * If an IRQ allocated with this function needs to be freed
92 * separately, devm_free_irq() must be used.
93 */
94int devm_request_any_context_irq(struct device *dev, unsigned int irq,
95 irq_handler_t handler, unsigned long irqflags,
96 const char *devname, void *dev_id)
97{
98 struct irq_devres *dr;
99 int rc;
100
101 dr = devres_alloc(devm_irq_release, sizeof(struct irq_devres),
102 GFP_KERNEL);
103 if (!dr)
104 return -ENOMEM;
105
106 rc = request_any_context_irq(irq, handler, irqflags, devname, dev_id);
107 if (rc) {
108 devres_free(dr);
109 return rc;
110 }
111
112 dr->irq = irq;
113 dr->dev_id = dev_id;
114 devres_add(dev, dr);
115
116 return 0;
117}
118EXPORT_SYMBOL(devm_request_any_context_irq);
119
120/**
76 * devm_free_irq - free an interrupt 121 * devm_free_irq - free an interrupt
77 * @dev: device to free interrupt for 122 * @dev: device to free interrupt for
78 * @irq: Interrupt line to free 123 * @irq: Interrupt line to free
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 192a302d6cfd..8ab8e9390297 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -274,6 +274,7 @@ struct irq_desc *irq_to_desc(unsigned int irq)
274{ 274{
275 return (irq < NR_IRQS) ? irq_desc + irq : NULL; 275 return (irq < NR_IRQS) ? irq_desc + irq : NULL;
276} 276}
277EXPORT_SYMBOL(irq_to_desc);
277 278
278static void free_desc(unsigned int irq) 279static void free_desc(unsigned int irq)
279{ 280{
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index cf68bb36fe58..f14033700c25 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -10,6 +10,7 @@
10#include <linux/mutex.h> 10#include <linux/mutex.h>
11#include <linux/of.h> 11#include <linux/of.h>
12#include <linux/of_address.h> 12#include <linux/of_address.h>
13#include <linux/of_irq.h>
13#include <linux/topology.h> 14#include <linux/topology.h>
14#include <linux/seq_file.h> 15#include <linux/seq_file.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 481a13c43b17..d3bf660cb57f 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -802,8 +802,7 @@ static irqreturn_t irq_thread_fn(struct irq_desc *desc,
802 802
803static void wake_threads_waitq(struct irq_desc *desc) 803static void wake_threads_waitq(struct irq_desc *desc)
804{ 804{
805 if (atomic_dec_and_test(&desc->threads_active) && 805 if (atomic_dec_and_test(&desc->threads_active))
806 waitqueue_active(&desc->wait_for_threads))
807 wake_up(&desc->wait_for_threads); 806 wake_up(&desc->wait_for_threads);
808} 807}
809 808
diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index 55fcce6065cf..a82170e2fa78 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -61,11 +61,11 @@ void __weak arch_irq_work_raise(void)
61 * 61 *
62 * Can be re-enqueued while the callback is still in progress. 62 * Can be re-enqueued while the callback is still in progress.
63 */ 63 */
64void irq_work_queue(struct irq_work *work) 64bool irq_work_queue(struct irq_work *work)
65{ 65{
66 /* Only queue if not already pending */ 66 /* Only queue if not already pending */
67 if (!irq_work_claim(work)) 67 if (!irq_work_claim(work))
68 return; 68 return false;
69 69
70 /* Queue the entry and raise the IPI if needed. */ 70 /* Queue the entry and raise the IPI if needed. */
71 preempt_disable(); 71 preempt_disable();
@@ -83,6 +83,8 @@ void irq_work_queue(struct irq_work *work)
83 } 83 }
84 84
85 preempt_enable(); 85 preempt_enable();
86
87 return true;
86} 88}
87EXPORT_SYMBOL_GPL(irq_work_queue); 89EXPORT_SYMBOL_GPL(irq_work_queue);
88 90
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 60bafbed06ab..45601cf41bee 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -1039,10 +1039,10 @@ void __weak crash_unmap_reserved_pages(void)
1039{} 1039{}
1040 1040
1041#ifdef CONFIG_COMPAT 1041#ifdef CONFIG_COMPAT
1042asmlinkage long compat_sys_kexec_load(unsigned long entry, 1042COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
1043 unsigned long nr_segments, 1043 compat_ulong_t, nr_segments,
1044 struct compat_kexec_segment __user *segments, 1044 struct compat_kexec_segment __user *, segments,
1045 unsigned long flags) 1045 compat_ulong_t, flags)
1046{ 1046{
1047 struct compat_kexec_segment in; 1047 struct compat_kexec_segment in;
1048 struct kexec_segment out, __user *ksegments; 1048 struct kexec_segment out, __user *ksegments;
diff --git a/kernel/kmod.c b/kernel/kmod.c
index b086006c59e7..6b375af4958d 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -239,7 +239,7 @@ static int ____call_usermodehelper(void *data)
239 239
240 commit_creds(new); 240 commit_creds(new);
241 241
242 retval = do_execve(sub_info->path, 242 retval = do_execve(getname_kernel(sub_info->path),
243 (const char __user *const __user *)sub_info->argv, 243 (const char __user *const __user *)sub_info->argv,
244 (const char __user *const __user *)sub_info->envp); 244 (const char __user *const __user *)sub_info->envp);
245 if (!retval) 245 if (!retval)
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index d945a949760f..e660964086e2 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -19,6 +19,8 @@
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/capability.h> 20#include <linux/capability.h>
21 21
22#include <linux/rcupdate.h> /* rcu_expedited */
23
22#define KERNEL_ATTR_RO(_name) \ 24#define KERNEL_ATTR_RO(_name) \
23static struct kobj_attribute _name##_attr = __ATTR_RO(_name) 25static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
24 26
diff --git a/kernel/locking/Makefile b/kernel/locking/Makefile
index baab8e5e7f66..306a76b51e0f 100644
--- a/kernel/locking/Makefile
+++ b/kernel/locking/Makefile
@@ -1,5 +1,5 @@
1 1
2obj-y += mutex.o semaphore.o rwsem.o lglock.o 2obj-y += mutex.o semaphore.o rwsem.o lglock.o mcs_spinlock.o
3 3
4ifdef CONFIG_FUNCTION_TRACER 4ifdef CONFIG_FUNCTION_TRACER
5CFLAGS_REMOVE_lockdep.o = -pg 5CFLAGS_REMOVE_lockdep.o = -pg
@@ -23,3 +23,4 @@ obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
23obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o 23obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
24obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o 24obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o
25obj-$(CONFIG_PERCPU_RWSEM) += percpu-rwsem.o 25obj-$(CONFIG_PERCPU_RWSEM) += percpu-rwsem.o
26obj-$(CONFIG_LOCK_TORTURE_TEST) += locktorture.o
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index eb8a54783fa0..b0e9467922e1 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1936,12 +1936,12 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next)
1936 1936
1937 for (;;) { 1937 for (;;) {
1938 int distance = curr->lockdep_depth - depth + 1; 1938 int distance = curr->lockdep_depth - depth + 1;
1939 hlock = curr->held_locks + depth-1; 1939 hlock = curr->held_locks + depth - 1;
1940 /* 1940 /*
1941 * Only non-recursive-read entries get new dependencies 1941 * Only non-recursive-read entries get new dependencies
1942 * added: 1942 * added:
1943 */ 1943 */
1944 if (hlock->read != 2) { 1944 if (hlock->read != 2 && hlock->check) {
1945 if (!check_prev_add(curr, hlock, next, 1945 if (!check_prev_add(curr, hlock, next,
1946 distance, trylock_loop)) 1946 distance, trylock_loop))
1947 return 0; 1947 return 0;
@@ -2098,7 +2098,7 @@ static int validate_chain(struct task_struct *curr, struct lockdep_map *lock,
2098 * (If lookup_chain_cache() returns with 1 it acquires 2098 * (If lookup_chain_cache() returns with 1 it acquires
2099 * graph_lock for us) 2099 * graph_lock for us)
2100 */ 2100 */
2101 if (!hlock->trylock && (hlock->check == 2) && 2101 if (!hlock->trylock && hlock->check &&
2102 lookup_chain_cache(curr, hlock, chain_key)) { 2102 lookup_chain_cache(curr, hlock, chain_key)) {
2103 /* 2103 /*
2104 * Check whether last held lock: 2104 * Check whether last held lock:
@@ -2517,7 +2517,7 @@ mark_held_locks(struct task_struct *curr, enum mark_type mark)
2517 2517
2518 BUG_ON(usage_bit >= LOCK_USAGE_STATES); 2518 BUG_ON(usage_bit >= LOCK_USAGE_STATES);
2519 2519
2520 if (hlock_class(hlock)->key == __lockdep_no_validate__.subkeys) 2520 if (!hlock->check)
2521 continue; 2521 continue;
2522 2522
2523 if (!mark_lock(curr, hlock, usage_bit)) 2523 if (!mark_lock(curr, hlock, usage_bit))
@@ -2557,7 +2557,7 @@ static void __trace_hardirqs_on_caller(unsigned long ip)
2557 debug_atomic_inc(hardirqs_on_events); 2557 debug_atomic_inc(hardirqs_on_events);
2558} 2558}
2559 2559
2560void trace_hardirqs_on_caller(unsigned long ip) 2560__visible void trace_hardirqs_on_caller(unsigned long ip)
2561{ 2561{
2562 time_hardirqs_on(CALLER_ADDR0, ip); 2562 time_hardirqs_on(CALLER_ADDR0, ip);
2563 2563
@@ -2610,7 +2610,7 @@ EXPORT_SYMBOL(trace_hardirqs_on);
2610/* 2610/*
2611 * Hardirqs were disabled: 2611 * Hardirqs were disabled:
2612 */ 2612 */
2613void trace_hardirqs_off_caller(unsigned long ip) 2613__visible void trace_hardirqs_off_caller(unsigned long ip)
2614{ 2614{
2615 struct task_struct *curr = current; 2615 struct task_struct *curr = current;
2616 2616
@@ -3055,9 +3055,6 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
3055 int class_idx; 3055 int class_idx;
3056 u64 chain_key; 3056 u64 chain_key;
3057 3057
3058 if (!prove_locking)
3059 check = 1;
3060
3061 if (unlikely(!debug_locks)) 3058 if (unlikely(!debug_locks))
3062 return 0; 3059 return 0;
3063 3060
@@ -3069,8 +3066,8 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
3069 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) 3066 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
3070 return 0; 3067 return 0;
3071 3068
3072 if (lock->key == &__lockdep_no_validate__) 3069 if (!prove_locking || lock->key == &__lockdep_no_validate__)
3073 check = 1; 3070 check = 0;
3074 3071
3075 if (subclass < NR_LOCKDEP_CACHING_CLASSES) 3072 if (subclass < NR_LOCKDEP_CACHING_CLASSES)
3076 class = lock->class_cache[subclass]; 3073 class = lock->class_cache[subclass];
@@ -3138,7 +3135,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
3138 hlock->holdtime_stamp = lockstat_clock(); 3135 hlock->holdtime_stamp = lockstat_clock();
3139#endif 3136#endif
3140 3137
3141 if (check == 2 && !mark_irqflags(curr, hlock)) 3138 if (check && !mark_irqflags(curr, hlock))
3142 return 0; 3139 return 0;
3143 3140
3144 /* mark it as used: */ 3141 /* mark it as used: */
@@ -4191,7 +4188,7 @@ void debug_show_held_locks(struct task_struct *task)
4191} 4188}
4192EXPORT_SYMBOL_GPL(debug_show_held_locks); 4189EXPORT_SYMBOL_GPL(debug_show_held_locks);
4193 4190
4194void lockdep_sys_exit(void) 4191asmlinkage void lockdep_sys_exit(void)
4195{ 4192{
4196 struct task_struct *curr = current; 4193 struct task_struct *curr = current;
4197 4194
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
new file mode 100644
index 000000000000..f26b1a18e34e
--- /dev/null
+++ b/kernel/locking/locktorture.c
@@ -0,0 +1,452 @@
1/*
2 * Module-based torture test facility for locking
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 *
18 * Copyright (C) IBM Corporation, 2014
19 *
20 * Author: Paul E. McKenney <paulmck@us.ibm.com>
21 * Based on kernel/rcu/torture.c.
22 */
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/kthread.h>
28#include <linux/err.h>
29#include <linux/spinlock.h>
30#include <linux/smp.h>
31#include <linux/interrupt.h>
32#include <linux/sched.h>
33#include <linux/atomic.h>
34#include <linux/bitops.h>
35#include <linux/completion.h>
36#include <linux/moduleparam.h>
37#include <linux/percpu.h>
38#include <linux/notifier.h>
39#include <linux/reboot.h>
40#include <linux/freezer.h>
41#include <linux/cpu.h>
42#include <linux/delay.h>
43#include <linux/stat.h>
44#include <linux/slab.h>
45#include <linux/trace_clock.h>
46#include <asm/byteorder.h>
47#include <linux/torture.h>
48
49MODULE_LICENSE("GPL");
50MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>");
51
52torture_param(int, nwriters_stress, -1,
53 "Number of write-locking stress-test threads");
54torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
55torture_param(int, onoff_interval, 0,
56 "Time between CPU hotplugs (s), 0=disable");
57torture_param(int, shuffle_interval, 3,
58 "Number of jiffies between shuffles, 0=disable");
59torture_param(int, shutdown_secs, 0, "Shutdown time (j), <= zero to disable.");
60torture_param(int, stat_interval, 60,
61 "Number of seconds between stats printk()s");
62torture_param(int, stutter, 5, "Number of jiffies to run/halt test, 0=disable");
63torture_param(bool, verbose, true,
64 "Enable verbose debugging printk()s");
65
66static char *torture_type = "spin_lock";
67module_param(torture_type, charp, 0444);
68MODULE_PARM_DESC(torture_type,
69 "Type of lock to torture (spin_lock, spin_lock_irq, ...)");
70
71static atomic_t n_lock_torture_errors;
72
73static struct task_struct *stats_task;
74static struct task_struct **writer_tasks;
75
76static int nrealwriters_stress;
77static bool lock_is_write_held;
78
79struct lock_writer_stress_stats {
80 long n_write_lock_fail;
81 long n_write_lock_acquired;
82};
83static struct lock_writer_stress_stats *lwsa;
84
85#if defined(MODULE) || defined(CONFIG_LOCK_TORTURE_TEST_RUNNABLE)
86#define LOCKTORTURE_RUNNABLE_INIT 1
87#else
88#define LOCKTORTURE_RUNNABLE_INIT 0
89#endif
90int locktorture_runnable = LOCKTORTURE_RUNNABLE_INIT;
91module_param(locktorture_runnable, int, 0444);
92MODULE_PARM_DESC(locktorture_runnable, "Start locktorture at boot");
93
94/* Forward reference. */
95static void lock_torture_cleanup(void);
96
97/*
98 * Operations vector for selecting different types of tests.
99 */
100struct lock_torture_ops {
101 void (*init)(void);
102 int (*writelock)(void);
103 void (*write_delay)(struct torture_random_state *trsp);
104 void (*writeunlock)(void);
105 unsigned long flags;
106 const char *name;
107};
108
109static struct lock_torture_ops *cur_ops;
110
111/*
112 * Definitions for lock torture testing.
113 */
114
115static int torture_lock_busted_write_lock(void)
116{
117 return 0; /* BUGGY, do not use in real life!!! */
118}
119
120static void torture_lock_busted_write_delay(struct torture_random_state *trsp)
121{
122 const unsigned long longdelay_us = 100;
123
124 /* We want a long delay occasionally to force massive contention. */
125 if (!(torture_random(trsp) %
126 (nrealwriters_stress * 2000 * longdelay_us)))
127 mdelay(longdelay_us);
128#ifdef CONFIG_PREEMPT
129 if (!(torture_random(trsp) % (nrealwriters_stress * 20000)))
130 preempt_schedule(); /* Allow test to be preempted. */
131#endif
132}
133
134static void torture_lock_busted_write_unlock(void)
135{
136 /* BUGGY, do not use in real life!!! */
137}
138
139static struct lock_torture_ops lock_busted_ops = {
140 .writelock = torture_lock_busted_write_lock,
141 .write_delay = torture_lock_busted_write_delay,
142 .writeunlock = torture_lock_busted_write_unlock,
143 .name = "lock_busted"
144};
145
146static DEFINE_SPINLOCK(torture_spinlock);
147
148static int torture_spin_lock_write_lock(void) __acquires(torture_spinlock)
149{
150 spin_lock(&torture_spinlock);
151 return 0;
152}
153
154static void torture_spin_lock_write_delay(struct torture_random_state *trsp)
155{
156 const unsigned long shortdelay_us = 2;
157 const unsigned long longdelay_us = 100;
158
159 /* We want a short delay mostly to emulate likely code, and
160 * we want a long delay occasionally to force massive contention.
161 */
162 if (!(torture_random(trsp) %
163 (nrealwriters_stress * 2000 * longdelay_us)))
164 mdelay(longdelay_us);
165 if (!(torture_random(trsp) %
166 (nrealwriters_stress * 2 * shortdelay_us)))
167 udelay(shortdelay_us);
168#ifdef CONFIG_PREEMPT
169 if (!(torture_random(trsp) % (nrealwriters_stress * 20000)))
170 preempt_schedule(); /* Allow test to be preempted. */
171#endif
172}
173
174static void torture_spin_lock_write_unlock(void) __releases(torture_spinlock)
175{
176 spin_unlock(&torture_spinlock);
177}
178
179static struct lock_torture_ops spin_lock_ops = {
180 .writelock = torture_spin_lock_write_lock,
181 .write_delay = torture_spin_lock_write_delay,
182 .writeunlock = torture_spin_lock_write_unlock,
183 .name = "spin_lock"
184};
185
186static int torture_spin_lock_write_lock_irq(void)
187__acquires(torture_spinlock_irq)
188{
189 unsigned long flags;
190
191 spin_lock_irqsave(&torture_spinlock, flags);
192 cur_ops->flags = flags;
193 return 0;
194}
195
196static void torture_lock_spin_write_unlock_irq(void)
197__releases(torture_spinlock)
198{
199 spin_unlock_irqrestore(&torture_spinlock, cur_ops->flags);
200}
201
202static struct lock_torture_ops spin_lock_irq_ops = {
203 .writelock = torture_spin_lock_write_lock_irq,
204 .write_delay = torture_spin_lock_write_delay,
205 .writeunlock = torture_lock_spin_write_unlock_irq,
206 .name = "spin_lock_irq"
207};
208
209/*
210 * Lock torture writer kthread. Repeatedly acquires and releases
211 * the lock, checking for duplicate acquisitions.
212 */
213static int lock_torture_writer(void *arg)
214{
215 struct lock_writer_stress_stats *lwsp = arg;
216 static DEFINE_TORTURE_RANDOM(rand);
217
218 VERBOSE_TOROUT_STRING("lock_torture_writer task started");
219 set_user_nice(current, 19);
220
221 do {
222 schedule_timeout_uninterruptible(1);
223 cur_ops->writelock();
224 if (WARN_ON_ONCE(lock_is_write_held))
225 lwsp->n_write_lock_fail++;
226 lock_is_write_held = 1;
227 lwsp->n_write_lock_acquired++;
228 cur_ops->write_delay(&rand);
229 lock_is_write_held = 0;
230 cur_ops->writeunlock();
231 stutter_wait("lock_torture_writer");
232 } while (!torture_must_stop());
233 torture_kthread_stopping("lock_torture_writer");
234 return 0;
235}
236
237/*
238 * Create an lock-torture-statistics message in the specified buffer.
239 */
240static void lock_torture_printk(char *page)
241{
242 bool fail = 0;
243 int i;
244 long max = 0;
245 long min = lwsa[0].n_write_lock_acquired;
246 long long sum = 0;
247
248 for (i = 0; i < nrealwriters_stress; i++) {
249 if (lwsa[i].n_write_lock_fail)
250 fail = true;
251 sum += lwsa[i].n_write_lock_acquired;
252 if (max < lwsa[i].n_write_lock_fail)
253 max = lwsa[i].n_write_lock_fail;
254 if (min > lwsa[i].n_write_lock_fail)
255 min = lwsa[i].n_write_lock_fail;
256 }
257 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
258 page += sprintf(page,
259 "Writes: Total: %lld Max/Min: %ld/%ld %s Fail: %d %s\n",
260 sum, max, min, max / 2 > min ? "???" : "",
261 fail, fail ? "!!!" : "");
262 if (fail)
263 atomic_inc(&n_lock_torture_errors);
264}
265
266/*
267 * Print torture statistics. Caller must ensure that there is only one
268 * call to this function at a given time!!! This is normally accomplished
269 * by relying on the module system to only have one copy of the module
270 * loaded, and then by giving the lock_torture_stats kthread full control
271 * (or the init/cleanup functions when lock_torture_stats thread is not
272 * running).
273 */
274static void lock_torture_stats_print(void)
275{
276 int size = nrealwriters_stress * 200 + 8192;
277 char *buf;
278
279 buf = kmalloc(size, GFP_KERNEL);
280 if (!buf) {
281 pr_err("lock_torture_stats_print: Out of memory, need: %d",
282 size);
283 return;
284 }
285 lock_torture_printk(buf);
286 pr_alert("%s", buf);
287 kfree(buf);
288}
289
290/*
291 * Periodically prints torture statistics, if periodic statistics printing
292 * was specified via the stat_interval module parameter.
293 *
294 * No need to worry about fullstop here, since this one doesn't reference
295 * volatile state or register callbacks.
296 */
297static int lock_torture_stats(void *arg)
298{
299 VERBOSE_TOROUT_STRING("lock_torture_stats task started");
300 do {
301 schedule_timeout_interruptible(stat_interval * HZ);
302 lock_torture_stats_print();
303 torture_shutdown_absorb("lock_torture_stats");
304 } while (!torture_must_stop());
305 torture_kthread_stopping("lock_torture_stats");
306 return 0;
307}
308
309static inline void
310lock_torture_print_module_parms(struct lock_torture_ops *cur_ops,
311 const char *tag)
312{
313 pr_alert("%s" TORTURE_FLAG
314 "--- %s: nwriters_stress=%d stat_interval=%d verbose=%d shuffle_interval=%d stutter=%d shutdown_secs=%d onoff_interval=%d onoff_holdoff=%d\n",
315 torture_type, tag, nrealwriters_stress, stat_interval, verbose,
316 shuffle_interval, stutter, shutdown_secs,
317 onoff_interval, onoff_holdoff);
318}
319
320static void lock_torture_cleanup(void)
321{
322 int i;
323
324 if (torture_cleanup())
325 return;
326
327 if (writer_tasks) {
328 for (i = 0; i < nrealwriters_stress; i++)
329 torture_stop_kthread(lock_torture_writer,
330 writer_tasks[i]);
331 kfree(writer_tasks);
332 writer_tasks = NULL;
333 }
334
335 torture_stop_kthread(lock_torture_stats, stats_task);
336 lock_torture_stats_print(); /* -After- the stats thread is stopped! */
337
338 if (atomic_read(&n_lock_torture_errors))
339 lock_torture_print_module_parms(cur_ops,
340 "End of test: FAILURE");
341 else if (torture_onoff_failures())
342 lock_torture_print_module_parms(cur_ops,
343 "End of test: LOCK_HOTPLUG");
344 else
345 lock_torture_print_module_parms(cur_ops,
346 "End of test: SUCCESS");
347}
348
349static int __init lock_torture_init(void)
350{
351 int i;
352 int firsterr = 0;
353 static struct lock_torture_ops *torture_ops[] = {
354 &lock_busted_ops, &spin_lock_ops, &spin_lock_irq_ops,
355 };
356
357 torture_init_begin(torture_type, verbose, &locktorture_runnable);
358
359 /* Process args and tell the world that the torturer is on the job. */
360 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
361 cur_ops = torture_ops[i];
362 if (strcmp(torture_type, cur_ops->name) == 0)
363 break;
364 }
365 if (i == ARRAY_SIZE(torture_ops)) {
366 pr_alert("lock-torture: invalid torture type: \"%s\"\n",
367 torture_type);
368 pr_alert("lock-torture types:");
369 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
370 pr_alert(" %s", torture_ops[i]->name);
371 pr_alert("\n");
372 torture_init_end();
373 return -EINVAL;
374 }
375 if (cur_ops->init)
376 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
377
378 if (nwriters_stress >= 0)
379 nrealwriters_stress = nwriters_stress;
380 else
381 nrealwriters_stress = 2 * num_online_cpus();
382 lock_torture_print_module_parms(cur_ops, "Start of test");
383
384 /* Initialize the statistics so that each run gets its own numbers. */
385
386 lock_is_write_held = 0;
387 lwsa = kmalloc(sizeof(*lwsa) * nrealwriters_stress, GFP_KERNEL);
388 if (lwsa == NULL) {
389 VERBOSE_TOROUT_STRING("lwsa: Out of memory");
390 firsterr = -ENOMEM;
391 goto unwind;
392 }
393 for (i = 0; i < nrealwriters_stress; i++) {
394 lwsa[i].n_write_lock_fail = 0;
395 lwsa[i].n_write_lock_acquired = 0;
396 }
397
398 /* Start up the kthreads. */
399
400 if (onoff_interval > 0) {
401 firsterr = torture_onoff_init(onoff_holdoff * HZ,
402 onoff_interval * HZ);
403 if (firsterr)
404 goto unwind;
405 }
406 if (shuffle_interval > 0) {
407 firsterr = torture_shuffle_init(shuffle_interval);
408 if (firsterr)
409 goto unwind;
410 }
411 if (shutdown_secs > 0) {
412 firsterr = torture_shutdown_init(shutdown_secs,
413 lock_torture_cleanup);
414 if (firsterr)
415 goto unwind;
416 }
417 if (stutter > 0) {
418 firsterr = torture_stutter_init(stutter);
419 if (firsterr)
420 goto unwind;
421 }
422
423 writer_tasks = kzalloc(nrealwriters_stress * sizeof(writer_tasks[0]),
424 GFP_KERNEL);
425 if (writer_tasks == NULL) {
426 VERBOSE_TOROUT_ERRSTRING("writer_tasks: Out of memory");
427 firsterr = -ENOMEM;
428 goto unwind;
429 }
430 for (i = 0; i < nrealwriters_stress; i++) {
431 firsterr = torture_create_kthread(lock_torture_writer, &lwsa[i],
432 writer_tasks[i]);
433 if (firsterr)
434 goto unwind;
435 }
436 if (stat_interval > 0) {
437 firsterr = torture_create_kthread(lock_torture_stats, NULL,
438 stats_task);
439 if (firsterr)
440 goto unwind;
441 }
442 torture_init_end();
443 return 0;
444
445unwind:
446 torture_init_end();
447 lock_torture_cleanup();
448 return firsterr;
449}
450
451module_init(lock_torture_init);
452module_exit(lock_torture_cleanup);
diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
new file mode 100644
index 000000000000..838dc9e00669
--- /dev/null
+++ b/kernel/locking/mcs_spinlock.c
@@ -0,0 +1,178 @@
1
2#include <linux/percpu.h>
3#include <linux/mutex.h>
4#include <linux/sched.h>
5#include "mcs_spinlock.h"
6
7#ifdef CONFIG_SMP
8
9/*
10 * An MCS like lock especially tailored for optimistic spinning for sleeping
11 * lock implementations (mutex, rwsem, etc).
12 *
13 * Using a single mcs node per CPU is safe because sleeping locks should not be
14 * called from interrupt context and we have preemption disabled while
15 * spinning.
16 */
17static DEFINE_PER_CPU_SHARED_ALIGNED(struct optimistic_spin_queue, osq_node);
18
19/*
20 * Get a stable @node->next pointer, either for unlock() or unqueue() purposes.
21 * Can return NULL in case we were the last queued and we updated @lock instead.
22 */
23static inline struct optimistic_spin_queue *
24osq_wait_next(struct optimistic_spin_queue **lock,
25 struct optimistic_spin_queue *node,
26 struct optimistic_spin_queue *prev)
27{
28 struct optimistic_spin_queue *next = NULL;
29
30 for (;;) {
31 if (*lock == node && cmpxchg(lock, node, prev) == node) {
32 /*
33 * We were the last queued, we moved @lock back. @prev
34 * will now observe @lock and will complete its
35 * unlock()/unqueue().
36 */
37 break;
38 }
39
40 /*
41 * We must xchg() the @node->next value, because if we were to
42 * leave it in, a concurrent unlock()/unqueue() from
43 * @node->next might complete Step-A and think its @prev is
44 * still valid.
45 *
46 * If the concurrent unlock()/unqueue() wins the race, we'll
47 * wait for either @lock to point to us, through its Step-B, or
48 * wait for a new @node->next from its Step-C.
49 */
50 if (node->next) {
51 next = xchg(&node->next, NULL);
52 if (next)
53 break;
54 }
55
56 arch_mutex_cpu_relax();
57 }
58
59 return next;
60}
61
62bool osq_lock(struct optimistic_spin_queue **lock)
63{
64 struct optimistic_spin_queue *node = this_cpu_ptr(&osq_node);
65 struct optimistic_spin_queue *prev, *next;
66
67 node->locked = 0;
68 node->next = NULL;
69
70 node->prev = prev = xchg(lock, node);
71 if (likely(prev == NULL))
72 return true;
73
74 ACCESS_ONCE(prev->next) = node;
75
76 /*
77 * Normally @prev is untouchable after the above store; because at that
78 * moment unlock can proceed and wipe the node element from stack.
79 *
80 * However, since our nodes are static per-cpu storage, we're
81 * guaranteed their existence -- this allows us to apply
82 * cmpxchg in an attempt to undo our queueing.
83 */
84
85 while (!smp_load_acquire(&node->locked)) {
86 /*
87 * If we need to reschedule bail... so we can block.
88 */
89 if (need_resched())
90 goto unqueue;
91
92 arch_mutex_cpu_relax();
93 }
94 return true;
95
96unqueue:
97 /*
98 * Step - A -- stabilize @prev
99 *
100 * Undo our @prev->next assignment; this will make @prev's
101 * unlock()/unqueue() wait for a next pointer since @lock points to us
102 * (or later).
103 */
104
105 for (;;) {
106 if (prev->next == node &&
107 cmpxchg(&prev->next, node, NULL) == node)
108 break;
109
110 /*
111 * We can only fail the cmpxchg() racing against an unlock(),
112 * in which case we should observe @node->locked becomming
113 * true.
114 */
115 if (smp_load_acquire(&node->locked))
116 return true;
117
118 arch_mutex_cpu_relax();
119
120 /*
121 * Or we race against a concurrent unqueue()'s step-B, in which
122 * case its step-C will write us a new @node->prev pointer.
123 */
124 prev = ACCESS_ONCE(node->prev);
125 }
126
127 /*
128 * Step - B -- stabilize @next
129 *
130 * Similar to unlock(), wait for @node->next or move @lock from @node
131 * back to @prev.
132 */
133
134 next = osq_wait_next(lock, node, prev);
135 if (!next)
136 return false;
137
138 /*
139 * Step - C -- unlink
140 *
141 * @prev is stable because its still waiting for a new @prev->next
142 * pointer, @next is stable because our @node->next pointer is NULL and
143 * it will wait in Step-A.
144 */
145
146 ACCESS_ONCE(next->prev) = prev;
147 ACCESS_ONCE(prev->next) = next;
148
149 return false;
150}
151
152void osq_unlock(struct optimistic_spin_queue **lock)
153{
154 struct optimistic_spin_queue *node = this_cpu_ptr(&osq_node);
155 struct optimistic_spin_queue *next;
156
157 /*
158 * Fast path for the uncontended case.
159 */
160 if (likely(cmpxchg(lock, node, NULL) == node))
161 return;
162
163 /*
164 * Second most likely case.
165 */
166 next = xchg(&node->next, NULL);
167 if (next) {
168 ACCESS_ONCE(next->locked) = 1;
169 return;
170 }
171
172 next = osq_wait_next(lock, node, NULL);
173 if (next)
174 ACCESS_ONCE(next->locked) = 1;
175}
176
177#endif
178
diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
new file mode 100644
index 000000000000..a2dbac4aca6b
--- /dev/null
+++ b/kernel/locking/mcs_spinlock.h
@@ -0,0 +1,129 @@
1/*
2 * MCS lock defines
3 *
4 * This file contains the main data structure and API definitions of MCS lock.
5 *
6 * The MCS lock (proposed by Mellor-Crummey and Scott) is a simple spin-lock
7 * with the desirable properties of being fair, and with each cpu trying
8 * to acquire the lock spinning on a local variable.
9 * It avoids expensive cache bouncings that common test-and-set spin-lock
10 * implementations incur.
11 */
12#ifndef __LINUX_MCS_SPINLOCK_H
13#define __LINUX_MCS_SPINLOCK_H
14
15#include <asm/mcs_spinlock.h>
16
17struct mcs_spinlock {
18 struct mcs_spinlock *next;
19 int locked; /* 1 if lock acquired */
20};
21
22#ifndef arch_mcs_spin_lock_contended
23/*
24 * Using smp_load_acquire() provides a memory barrier that ensures
25 * subsequent operations happen after the lock is acquired.
26 */
27#define arch_mcs_spin_lock_contended(l) \
28do { \
29 while (!(smp_load_acquire(l))) \
30 arch_mutex_cpu_relax(); \
31} while (0)
32#endif
33
34#ifndef arch_mcs_spin_unlock_contended
35/*
36 * smp_store_release() provides a memory barrier to ensure all
37 * operations in the critical section has been completed before
38 * unlocking.
39 */
40#define arch_mcs_spin_unlock_contended(l) \
41 smp_store_release((l), 1)
42#endif
43
44/*
45 * Note: the smp_load_acquire/smp_store_release pair is not
46 * sufficient to form a full memory barrier across
47 * cpus for many architectures (except x86) for mcs_unlock and mcs_lock.
48 * For applications that need a full barrier across multiple cpus
49 * with mcs_unlock and mcs_lock pair, smp_mb__after_unlock_lock() should be
50 * used after mcs_lock.
51 */
52
53/*
54 * In order to acquire the lock, the caller should declare a local node and
55 * pass a reference of the node to this function in addition to the lock.
56 * If the lock has already been acquired, then this will proceed to spin
57 * on this node->locked until the previous lock holder sets the node->locked
58 * in mcs_spin_unlock().
59 *
60 * We don't inline mcs_spin_lock() so that perf can correctly account for the
61 * time spent in this lock function.
62 */
63static inline
64void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
65{
66 struct mcs_spinlock *prev;
67
68 /* Init node */
69 node->locked = 0;
70 node->next = NULL;
71
72 prev = xchg(lock, node);
73 if (likely(prev == NULL)) {
74 /*
75 * Lock acquired, don't need to set node->locked to 1. Threads
76 * only spin on its own node->locked value for lock acquisition.
77 * However, since this thread can immediately acquire the lock
78 * and does not proceed to spin on its own node->locked, this
79 * value won't be used. If a debug mode is needed to
80 * audit lock status, then set node->locked value here.
81 */
82 return;
83 }
84 ACCESS_ONCE(prev->next) = node;
85
86 /* Wait until the lock holder passes the lock down. */
87 arch_mcs_spin_lock_contended(&node->locked);
88}
89
90/*
91 * Releases the lock. The caller should pass in the corresponding node that
92 * was used to acquire the lock.
93 */
94static inline
95void mcs_spin_unlock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
96{
97 struct mcs_spinlock *next = ACCESS_ONCE(node->next);
98
99 if (likely(!next)) {
100 /*
101 * Release the lock by setting it to NULL
102 */
103 if (likely(cmpxchg(lock, node, NULL) == node))
104 return;
105 /* Wait until the next pointer is set */
106 while (!(next = ACCESS_ONCE(node->next)))
107 arch_mutex_cpu_relax();
108 }
109
110 /* Pass lock to next waiter. */
111 arch_mcs_spin_unlock_contended(&next->locked);
112}
113
114/*
115 * Cancellable version of the MCS lock above.
116 *
117 * Intended for adaptive spinning of sleeping locks:
118 * mutex_lock()/rwsem_down_{read,write}() etc.
119 */
120
121struct optimistic_spin_queue {
122 struct optimistic_spin_queue *next, *prev;
123 int locked; /* 1 if lock acquired */
124};
125
126extern bool osq_lock(struct optimistic_spin_queue **lock);
127extern void osq_unlock(struct optimistic_spin_queue **lock);
128
129#endif /* __LINUX_MCS_SPINLOCK_H */
diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
index faf6f5b53e77..e1191c996c59 100644
--- a/kernel/locking/mutex-debug.c
+++ b/kernel/locking/mutex-debug.c
@@ -83,6 +83,12 @@ void debug_mutex_unlock(struct mutex *lock)
83 83
84 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next); 84 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
85 mutex_clear_owner(lock); 85 mutex_clear_owner(lock);
86
87 /*
88 * __mutex_slowpath_needs_to_unlock() is explicitly 0 for debug
89 * mutexes so that we can do it here after we've verified state.
90 */
91 atomic_set(&lock->count, 1);
86} 92}
87 93
88void debug_mutex_init(struct mutex *lock, const char *name, 94void debug_mutex_init(struct mutex *lock, const char *name,
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index 4dd6e4c219de..bc73d33c6760 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -25,6 +25,7 @@
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/debug_locks.h> 27#include <linux/debug_locks.h>
28#include "mcs_spinlock.h"
28 29
29/* 30/*
30 * In the DEBUG case we are using the "NULL fastpath" for mutexes, 31 * In the DEBUG case we are using the "NULL fastpath" for mutexes,
@@ -33,6 +34,13 @@
33#ifdef CONFIG_DEBUG_MUTEXES 34#ifdef CONFIG_DEBUG_MUTEXES
34# include "mutex-debug.h" 35# include "mutex-debug.h"
35# include <asm-generic/mutex-null.h> 36# include <asm-generic/mutex-null.h>
37/*
38 * Must be 0 for the debug case so we do not do the unlock outside of the
39 * wait_lock region. debug_mutex_unlock() will do the actual unlock in this
40 * case.
41 */
42# undef __mutex_slowpath_needs_to_unlock
43# define __mutex_slowpath_needs_to_unlock() 0
36#else 44#else
37# include "mutex.h" 45# include "mutex.h"
38# include <asm/mutex.h> 46# include <asm/mutex.h>
@@ -52,7 +60,7 @@ __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
52 INIT_LIST_HEAD(&lock->wait_list); 60 INIT_LIST_HEAD(&lock->wait_list);
53 mutex_clear_owner(lock); 61 mutex_clear_owner(lock);
54#ifdef CONFIG_MUTEX_SPIN_ON_OWNER 62#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
55 lock->spin_mlock = NULL; 63 lock->osq = NULL;
56#endif 64#endif
57 65
58 debug_mutex_init(lock, name, key); 66 debug_mutex_init(lock, name, key);
@@ -67,8 +75,7 @@ EXPORT_SYMBOL(__mutex_init);
67 * We also put the fastpath first in the kernel image, to make sure the 75 * We also put the fastpath first in the kernel image, to make sure the
68 * branch is predicted by the CPU as default-untaken. 76 * branch is predicted by the CPU as default-untaken.
69 */ 77 */
70static __used noinline void __sched 78__visible void __sched __mutex_lock_slowpath(atomic_t *lock_count);
71__mutex_lock_slowpath(atomic_t *lock_count);
72 79
73/** 80/**
74 * mutex_lock - acquire the mutex 81 * mutex_lock - acquire the mutex
@@ -111,54 +118,7 @@ EXPORT_SYMBOL(mutex_lock);
111 * more or less simultaneously, the spinners need to acquire a MCS lock 118 * more or less simultaneously, the spinners need to acquire a MCS lock
112 * first before spinning on the owner field. 119 * first before spinning on the owner field.
113 * 120 *
114 * We don't inline mspin_lock() so that perf can correctly account for the
115 * time spent in this lock function.
116 */ 121 */
117struct mspin_node {
118 struct mspin_node *next ;
119 int locked; /* 1 if lock acquired */
120};
121#define MLOCK(mutex) ((struct mspin_node **)&((mutex)->spin_mlock))
122
123static noinline
124void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
125{
126 struct mspin_node *prev;
127
128 /* Init node */
129 node->locked = 0;
130 node->next = NULL;
131
132 prev = xchg(lock, node);
133 if (likely(prev == NULL)) {
134 /* Lock acquired */
135 node->locked = 1;
136 return;
137 }
138 ACCESS_ONCE(prev->next) = node;
139 smp_wmb();
140 /* Wait until the lock holder passes the lock down */
141 while (!ACCESS_ONCE(node->locked))
142 arch_mutex_cpu_relax();
143}
144
145static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
146{
147 struct mspin_node *next = ACCESS_ONCE(node->next);
148
149 if (likely(!next)) {
150 /*
151 * Release the lock by setting it to NULL
152 */
153 if (cmpxchg(lock, node, NULL) == node)
154 return;
155 /* Wait until the next pointer is set */
156 while (!(next = ACCESS_ONCE(node->next)))
157 arch_mutex_cpu_relax();
158 }
159 ACCESS_ONCE(next->locked) = 1;
160 smp_wmb();
161}
162 122
163/* 123/*
164 * Mutex spinning code migrated from kernel/sched/core.c 124 * Mutex spinning code migrated from kernel/sched/core.c
@@ -212,6 +172,9 @@ static inline int mutex_can_spin_on_owner(struct mutex *lock)
212 struct task_struct *owner; 172 struct task_struct *owner;
213 int retval = 1; 173 int retval = 1;
214 174
175 if (need_resched())
176 return 0;
177
215 rcu_read_lock(); 178 rcu_read_lock();
216 owner = ACCESS_ONCE(lock->owner); 179 owner = ACCESS_ONCE(lock->owner);
217 if (owner) 180 if (owner)
@@ -225,7 +188,8 @@ static inline int mutex_can_spin_on_owner(struct mutex *lock)
225} 188}
226#endif 189#endif
227 190
228static __used noinline void __sched __mutex_unlock_slowpath(atomic_t *lock_count); 191__visible __used noinline
192void __sched __mutex_unlock_slowpath(atomic_t *lock_count);
229 193
230/** 194/**
231 * mutex_unlock - release the mutex 195 * mutex_unlock - release the mutex
@@ -446,9 +410,11 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
446 if (!mutex_can_spin_on_owner(lock)) 410 if (!mutex_can_spin_on_owner(lock))
447 goto slowpath; 411 goto slowpath;
448 412
413 if (!osq_lock(&lock->osq))
414 goto slowpath;
415
449 for (;;) { 416 for (;;) {
450 struct task_struct *owner; 417 struct task_struct *owner;
451 struct mspin_node node;
452 418
453 if (use_ww_ctx && ww_ctx->acquired > 0) { 419 if (use_ww_ctx && ww_ctx->acquired > 0) {
454 struct ww_mutex *ww; 420 struct ww_mutex *ww;
@@ -463,19 +429,16 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
463 * performed the optimistic spinning cannot be done. 429 * performed the optimistic spinning cannot be done.
464 */ 430 */
465 if (ACCESS_ONCE(ww->ctx)) 431 if (ACCESS_ONCE(ww->ctx))
466 goto slowpath; 432 break;
467 } 433 }
468 434
469 /* 435 /*
470 * If there's an owner, wait for it to either 436 * If there's an owner, wait for it to either
471 * release the lock or go to sleep. 437 * release the lock or go to sleep.
472 */ 438 */
473 mspin_lock(MLOCK(lock), &node);
474 owner = ACCESS_ONCE(lock->owner); 439 owner = ACCESS_ONCE(lock->owner);
475 if (owner && !mutex_spin_on_owner(lock, owner)) { 440 if (owner && !mutex_spin_on_owner(lock, owner))
476 mspin_unlock(MLOCK(lock), &node); 441 break;
477 goto slowpath;
478 }
479 442
480 if ((atomic_read(&lock->count) == 1) && 443 if ((atomic_read(&lock->count) == 1) &&
481 (atomic_cmpxchg(&lock->count, 1, 0) == 1)) { 444 (atomic_cmpxchg(&lock->count, 1, 0) == 1)) {
@@ -488,11 +451,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
488 } 451 }
489 452
490 mutex_set_owner(lock); 453 mutex_set_owner(lock);
491 mspin_unlock(MLOCK(lock), &node); 454 osq_unlock(&lock->osq);
492 preempt_enable(); 455 preempt_enable();
493 return 0; 456 return 0;
494 } 457 }
495 mspin_unlock(MLOCK(lock), &node);
496 458
497 /* 459 /*
498 * When there's no owner, we might have preempted between the 460 * When there's no owner, we might have preempted between the
@@ -501,7 +463,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
501 * the owner complete. 463 * the owner complete.
502 */ 464 */
503 if (!owner && (need_resched() || rt_task(task))) 465 if (!owner && (need_resched() || rt_task(task)))
504 goto slowpath; 466 break;
505 467
506 /* 468 /*
507 * The cpu_relax() call is a compiler barrier which forces 469 * The cpu_relax() call is a compiler barrier which forces
@@ -511,7 +473,15 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
511 */ 473 */
512 arch_mutex_cpu_relax(); 474 arch_mutex_cpu_relax();
513 } 475 }
476 osq_unlock(&lock->osq);
514slowpath: 477slowpath:
478 /*
479 * If we fell out of the spin path because of need_resched(),
480 * reschedule now, before we try-lock the mutex. This avoids getting
481 * scheduled out right after we obtained the mutex.
482 */
483 if (need_resched())
484 schedule_preempt_disabled();
515#endif 485#endif
516 spin_lock_mutex(&lock->wait_lock, flags); 486 spin_lock_mutex(&lock->wait_lock, flags);
517 487
@@ -717,10 +687,6 @@ __mutex_unlock_common_slowpath(atomic_t *lock_count, int nested)
717 struct mutex *lock = container_of(lock_count, struct mutex, count); 687 struct mutex *lock = container_of(lock_count, struct mutex, count);
718 unsigned long flags; 688 unsigned long flags;
719 689
720 spin_lock_mutex(&lock->wait_lock, flags);
721 mutex_release(&lock->dep_map, nested, _RET_IP_);
722 debug_mutex_unlock(lock);
723
724 /* 690 /*
725 * some architectures leave the lock unlocked in the fastpath failure 691 * some architectures leave the lock unlocked in the fastpath failure
726 * case, others need to leave it locked. In the later case we have to 692 * case, others need to leave it locked. In the later case we have to
@@ -729,6 +695,10 @@ __mutex_unlock_common_slowpath(atomic_t *lock_count, int nested)
729 if (__mutex_slowpath_needs_to_unlock()) 695 if (__mutex_slowpath_needs_to_unlock())
730 atomic_set(&lock->count, 1); 696 atomic_set(&lock->count, 1);
731 697
698 spin_lock_mutex(&lock->wait_lock, flags);
699 mutex_release(&lock->dep_map, nested, _RET_IP_);
700 debug_mutex_unlock(lock);
701
732 if (!list_empty(&lock->wait_list)) { 702 if (!list_empty(&lock->wait_list)) {
733 /* get the first entry from the wait-list: */ 703 /* get the first entry from the wait-list: */
734 struct mutex_waiter *waiter = 704 struct mutex_waiter *waiter =
@@ -746,7 +716,7 @@ __mutex_unlock_common_slowpath(atomic_t *lock_count, int nested)
746/* 716/*
747 * Release the lock, slowpath: 717 * Release the lock, slowpath:
748 */ 718 */
749static __used noinline void 719__visible void
750__mutex_unlock_slowpath(atomic_t *lock_count) 720__mutex_unlock_slowpath(atomic_t *lock_count)
751{ 721{
752 __mutex_unlock_common_slowpath(lock_count, 1); 722 __mutex_unlock_common_slowpath(lock_count, 1);
@@ -803,7 +773,7 @@ int __sched mutex_lock_killable(struct mutex *lock)
803} 773}
804EXPORT_SYMBOL(mutex_lock_killable); 774EXPORT_SYMBOL(mutex_lock_killable);
805 775
806static __used noinline void __sched 776__visible void __sched
807__mutex_lock_slowpath(atomic_t *lock_count) 777__mutex_lock_slowpath(atomic_t *lock_count)
808{ 778{
809 struct mutex *lock = container_of(lock_count, struct mutex, count); 779 struct mutex *lock = container_of(lock_count, struct mutex, count);
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 2e960a2bab81..aa4dff04b594 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -213,6 +213,18 @@ struct task_struct *rt_mutex_get_top_task(struct task_struct *task)
213} 213}
214 214
215/* 215/*
216 * Called by sched_setscheduler() to check whether the priority change
217 * is overruled by a possible priority boosting.
218 */
219int rt_mutex_check_prio(struct task_struct *task, int newprio)
220{
221 if (!task_has_pi_waiters(task))
222 return 0;
223
224 return task_top_pi_waiter(task)->task->prio <= newprio;
225}
226
227/*
216 * Adjust the priority of a task, after its pi_waiters got modified. 228 * Adjust the priority of a task, after its pi_waiters got modified.
217 * 229 *
218 * This can be both boosting and unboosting. task->pi_lock must be held. 230 * This can be both boosting and unboosting. task->pi_lock must be held.
diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index 19c5fa95e0b4..1d66e08e897d 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -143,6 +143,7 @@ __rwsem_do_wake(struct rw_semaphore *sem, enum rwsem_wake_type wake_type)
143/* 143/*
144 * wait for the read lock to be granted 144 * wait for the read lock to be granted
145 */ 145 */
146__visible
146struct rw_semaphore __sched *rwsem_down_read_failed(struct rw_semaphore *sem) 147struct rw_semaphore __sched *rwsem_down_read_failed(struct rw_semaphore *sem)
147{ 148{
148 long count, adjustment = -RWSEM_ACTIVE_READ_BIAS; 149 long count, adjustment = -RWSEM_ACTIVE_READ_BIAS;
@@ -190,6 +191,7 @@ struct rw_semaphore __sched *rwsem_down_read_failed(struct rw_semaphore *sem)
190/* 191/*
191 * wait until we successfully acquire the write lock 192 * wait until we successfully acquire the write lock
192 */ 193 */
194__visible
193struct rw_semaphore __sched *rwsem_down_write_failed(struct rw_semaphore *sem) 195struct rw_semaphore __sched *rwsem_down_write_failed(struct rw_semaphore *sem)
194{ 196{
195 long count, adjustment = -RWSEM_ACTIVE_WRITE_BIAS; 197 long count, adjustment = -RWSEM_ACTIVE_WRITE_BIAS;
@@ -252,6 +254,7 @@ struct rw_semaphore __sched *rwsem_down_write_failed(struct rw_semaphore *sem)
252 * handle waking up a waiter on the semaphore 254 * handle waking up a waiter on the semaphore
253 * - up_read/up_write has decremented the active part of count if we come here 255 * - up_read/up_write has decremented the active part of count if we come here
254 */ 256 */
257__visible
255struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem) 258struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem)
256{ 259{
257 unsigned long flags; 260 unsigned long flags;
@@ -272,6 +275,7 @@ struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem)
272 * - caller incremented waiting part of count and discovered it still negative 275 * - caller incremented waiting part of count and discovered it still negative
273 * - just wake up any readers at the front of the queue 276 * - just wake up any readers at the front of the queue
274 */ 277 */
278__visible
275struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem) 279struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem)
276{ 280{
277 unsigned long flags; 281 unsigned long flags;
diff --git a/kernel/module.c b/kernel/module.c
index d24fcf29cb64..8dc7f5e80dd8 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1015,7 +1015,7 @@ static size_t module_flags_taint(struct module *mod, char *buf)
1015 buf[l++] = 'C'; 1015 buf[l++] = 'C';
1016 /* 1016 /*
1017 * TAINT_FORCED_RMMOD: could be added. 1017 * TAINT_FORCED_RMMOD: could be added.
1018 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't 1018 * TAINT_CPU_OUT_OF_SPEC, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
1019 * apply to modules. 1019 * apply to modules.
1020 */ 1020 */
1021 return l; 1021 return l;
@@ -1948,6 +1948,10 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
1948 1948
1949 switch (sym[i].st_shndx) { 1949 switch (sym[i].st_shndx) {
1950 case SHN_COMMON: 1950 case SHN_COMMON:
1951 /* Ignore common symbols */
1952 if (!strncmp(name, "__gnu_lto", 9))
1953 break;
1954
1951 /* We compiled with -fno-common. These are not 1955 /* We compiled with -fno-common. These are not
1952 supposed to happen. */ 1956 supposed to happen. */
1953 pr_debug("Common symbol: %s\n", name); 1957 pr_debug("Common symbol: %s\n", name);
diff --git a/kernel/notifier.c b/kernel/notifier.c
index 2d5cc4ccff7f..db4c8b08a50c 100644
--- a/kernel/notifier.c
+++ b/kernel/notifier.c
@@ -309,7 +309,7 @@ int __blocking_notifier_call_chain(struct blocking_notifier_head *nh,
309 * racy then it does not matter what the result of the test 309 * racy then it does not matter what the result of the test
310 * is, we re-check the list after having taken the lock anyway: 310 * is, we re-check the list after having taken the lock anyway:
311 */ 311 */
312 if (rcu_dereference_raw(nh->head)) { 312 if (rcu_access_pointer(nh->head)) {
313 down_read(&nh->rwsem); 313 down_read(&nh->rwsem);
314 ret = notifier_call_chain(&nh->head, val, v, nr_to_call, 314 ret = notifier_call_chain(&nh->head, val, v, nr_to_call,
315 nr_calls); 315 nr_calls);
diff --git a/kernel/panic.c b/kernel/panic.c
index 6d6300375090..cca8a913ae7c 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -199,7 +199,7 @@ struct tnt {
199static const struct tnt tnts[] = { 199static const struct tnt tnts[] = {
200 { TAINT_PROPRIETARY_MODULE, 'P', 'G' }, 200 { TAINT_PROPRIETARY_MODULE, 'P', 'G' },
201 { TAINT_FORCED_MODULE, 'F', ' ' }, 201 { TAINT_FORCED_MODULE, 'F', ' ' },
202 { TAINT_UNSAFE_SMP, 'S', ' ' }, 202 { TAINT_CPU_OUT_OF_SPEC, 'S', ' ' },
203 { TAINT_FORCED_RMMOD, 'R', ' ' }, 203 { TAINT_FORCED_RMMOD, 'R', ' ' },
204 { TAINT_MACHINE_CHECK, 'M', ' ' }, 204 { TAINT_MACHINE_CHECK, 'M', ' ' },
205 { TAINT_BAD_PAGE, 'B', ' ' }, 205 { TAINT_BAD_PAGE, 'B', ' ' },
@@ -459,7 +459,7 @@ EXPORT_SYMBOL(warn_slowpath_null);
459 * Called when gcc's -fstack-protector feature is used, and 459 * Called when gcc's -fstack-protector feature is used, and
460 * gcc detects corruption of the on-stack canary value 460 * gcc detects corruption of the on-stack canary value
461 */ 461 */
462void __stack_chk_fail(void) 462__visible void __stack_chk_fail(void)
463{ 463{
464 panic("stack-protector: Kernel stack is corrupted in: %p\n", 464 panic("stack-protector: Kernel stack is corrupted in: %p\n",
465 __builtin_return_address(0)); 465 __builtin_return_address(0));
diff --git a/kernel/power/console.c b/kernel/power/console.c
index eacb8bd8cab4..aba9c545a0e3 100644
--- a/kernel/power/console.c
+++ b/kernel/power/console.c
@@ -9,6 +9,7 @@
9#include <linux/kbd_kern.h> 9#include <linux/kbd_kern.h>
10#include <linux/vt.h> 10#include <linux/vt.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/slab.h>
12#include "power.h" 13#include "power.h"
13 14
14#define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1) 15#define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index b1d255f04135..4dae9cbe9259 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1076,7 +1076,6 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
1076 next_seq = log_next_seq; 1076 next_seq = log_next_seq;
1077 1077
1078 len = 0; 1078 len = 0;
1079 prev = 0;
1080 while (len >= 0 && seq < next_seq) { 1079 while (len >= 0 && seq < next_seq) {
1081 struct printk_log *msg = log_from_idx(idx); 1080 struct printk_log *msg = log_from_idx(idx);
1082 int textlen; 1081 int textlen;
@@ -2788,7 +2787,6 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
2788 next_idx = idx; 2787 next_idx = idx;
2789 2788
2790 l = 0; 2789 l = 0;
2791 prev = 0;
2792 while (seq < dumper->next_seq) { 2790 while (seq < dumper->next_seq) {
2793 struct printk_log *msg = log_from_idx(idx); 2791 struct printk_log *msg = log_from_idx(idx);
2794 2792
diff --git a/kernel/profile.c b/kernel/profile.c
index 6631e1ef55ab..ebdd9c1a86b4 100644
--- a/kernel/profile.c
+++ b/kernel/profile.c
@@ -549,14 +549,14 @@ static int create_hash_tables(void)
549 struct page *page; 549 struct page *page;
550 550
551 page = alloc_pages_exact_node(node, 551 page = alloc_pages_exact_node(node,
552 GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, 552 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
553 0); 553 0);
554 if (!page) 554 if (!page)
555 goto out_cleanup; 555 goto out_cleanup;
556 per_cpu(cpu_profile_hits, cpu)[1] 556 per_cpu(cpu_profile_hits, cpu)[1]
557 = (struct profile_hit *)page_address(page); 557 = (struct profile_hit *)page_address(page);
558 page = alloc_pages_exact_node(node, 558 page = alloc_pages_exact_node(node,
559 GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, 559 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
560 0); 560 0);
561 if (!page) 561 if (!page)
562 goto out_cleanup; 562 goto out_cleanup;
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 1f4bcb3cc21c..adf98622cb32 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -1180,8 +1180,8 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
1180 return ret; 1180 return ret;
1181} 1181}
1182 1182
1183asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, 1183COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
1184 compat_long_t addr, compat_long_t data) 1184 compat_long_t, addr, compat_long_t, data)
1185{ 1185{
1186 struct task_struct *child; 1186 struct task_struct *child;
1187 long ret; 1187 long ret;
diff --git a/kernel/rcu/Makefile b/kernel/rcu/Makefile
index 01e9ec37a3e3..807ccfbf69b3 100644
--- a/kernel/rcu/Makefile
+++ b/kernel/rcu/Makefile
@@ -1,5 +1,5 @@
1obj-y += update.o srcu.o 1obj-y += update.o srcu.o
2obj-$(CONFIG_RCU_TORTURE_TEST) += torture.o 2obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
3obj-$(CONFIG_TREE_RCU) += tree.o 3obj-$(CONFIG_TREE_RCU) += tree.o
4obj-$(CONFIG_TREE_PREEMPT_RCU) += tree.o 4obj-$(CONFIG_TREE_PREEMPT_RCU) += tree.o
5obj-$(CONFIG_TREE_RCU_TRACE) += tree_trace.o 5obj-$(CONFIG_TREE_RCU_TRACE) += tree_trace.o
diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h
index 79c3877e9c5b..bfda2726ca45 100644
--- a/kernel/rcu/rcu.h
+++ b/kernel/rcu/rcu.h
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright IBM Corporation, 2011 18 * Copyright IBM Corporation, 2011
19 * 19 *
@@ -23,6 +23,7 @@
23#ifndef __LINUX_RCU_H 23#ifndef __LINUX_RCU_H
24#define __LINUX_RCU_H 24#define __LINUX_RCU_H
25 25
26#include <trace/events/rcu.h>
26#ifdef CONFIG_RCU_TRACE 27#ifdef CONFIG_RCU_TRACE
27#define RCU_TRACE(stmt) stmt 28#define RCU_TRACE(stmt) stmt
28#else /* #ifdef CONFIG_RCU_TRACE */ 29#else /* #ifdef CONFIG_RCU_TRACE */
@@ -116,8 +117,6 @@ static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head)
116 } 117 }
117} 118}
118 119
119extern int rcu_expedited;
120
121#ifdef CONFIG_RCU_STALL_COMMON 120#ifdef CONFIG_RCU_STALL_COMMON
122 121
123extern int rcu_cpu_stall_suppress; 122extern int rcu_cpu_stall_suppress;
diff --git a/kernel/rcu/torture.c b/kernel/rcu/rcutorture.c
index 732f8ae3086a..bd30bc61bc05 100644
--- a/kernel/rcu/torture.c
+++ b/kernel/rcu/rcutorture.c
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright (C) IBM Corporation, 2005, 2006 18 * Copyright (C) IBM Corporation, 2005, 2006
19 * 19 *
@@ -48,110 +48,58 @@
48#include <linux/slab.h> 48#include <linux/slab.h>
49#include <linux/trace_clock.h> 49#include <linux/trace_clock.h>
50#include <asm/byteorder.h> 50#include <asm/byteorder.h>
51#include <linux/torture.h>
51 52
52MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
53MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>"); 54MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>");
54 55
55MODULE_ALIAS("rcutorture"); 56
56#ifdef MODULE_PARAM_PREFIX 57torture_param(int, fqs_duration, 0,
57#undef MODULE_PARAM_PREFIX 58 "Duration of fqs bursts (us), 0 to disable");
58#endif 59torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)");
59#define MODULE_PARAM_PREFIX "rcutorture." 60torture_param(int, fqs_stutter, 3, "Wait time between fqs bursts (s)");
60 61torture_param(bool, gp_exp, false, "Use expedited GP wait primitives");
61static int fqs_duration; 62torture_param(bool, gp_normal, false,
62module_param(fqs_duration, int, 0444); 63 "Use normal (non-expedited) GP wait primitives");
63MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us), 0 to disable"); 64torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
64static int fqs_holdoff; 65torture_param(int, n_barrier_cbs, 0,
65module_param(fqs_holdoff, int, 0444); 66 "# of callbacks/kthreads for barrier testing");
66MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)"); 67torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads");
67static int fqs_stutter = 3; 68torture_param(int, nreaders, -1, "Number of RCU reader threads");
68module_param(fqs_stutter, int, 0444); 69torture_param(int, object_debug, 0,
69MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)"); 70 "Enable debug-object double call_rcu() testing");
70static bool gp_exp; 71torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
71module_param(gp_exp, bool, 0444); 72torture_param(int, onoff_interval, 0,
72MODULE_PARM_DESC(gp_exp, "Use expedited GP wait primitives"); 73 "Time between CPU hotplugs (s), 0=disable");
73static bool gp_normal; 74torture_param(int, shuffle_interval, 3, "Number of seconds between shuffles");
74module_param(gp_normal, bool, 0444); 75torture_param(int, shutdown_secs, 0, "Shutdown time (s), <= zero to disable.");
75MODULE_PARM_DESC(gp_normal, "Use normal (non-expedited) GP wait primitives"); 76torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable.");
76static int irqreader = 1; 77torture_param(int, stall_cpu_holdoff, 10,
77module_param(irqreader, int, 0444); 78 "Time to wait before starting stall (s).");
78MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers"); 79torture_param(int, stat_interval, 60,
79static int n_barrier_cbs; 80 "Number of seconds between stats printk()s");
80module_param(n_barrier_cbs, int, 0444); 81torture_param(int, stutter, 5, "Number of seconds to run/halt test");
81MODULE_PARM_DESC(n_barrier_cbs, "# of callbacks/kthreads for barrier testing"); 82torture_param(int, test_boost, 1, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
82static int nfakewriters = 4; 83torture_param(int, test_boost_duration, 4,
83module_param(nfakewriters, int, 0444); 84 "Duration of each boost test, seconds.");
84MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads"); 85torture_param(int, test_boost_interval, 7,
85static int nreaders = -1; 86 "Interval between boost tests, seconds.");
86module_param(nreaders, int, 0444); 87torture_param(bool, test_no_idle_hz, true,
87MODULE_PARM_DESC(nreaders, "Number of RCU reader threads"); 88 "Test support for tickless idle CPUs");
88static int object_debug; 89torture_param(bool, verbose, true,
89module_param(object_debug, int, 0444); 90 "Enable verbose debugging printk()s");
90MODULE_PARM_DESC(object_debug, "Enable debug-object double call_rcu() testing"); 91
91static int onoff_holdoff;
92module_param(onoff_holdoff, int, 0444);
93MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)");
94static int onoff_interval;
95module_param(onoff_interval, int, 0444);
96MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
97static int shuffle_interval = 3;
98module_param(shuffle_interval, int, 0444);
99MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
100static int shutdown_secs;
101module_param(shutdown_secs, int, 0444);
102MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), <= zero to disable.");
103static int stall_cpu;
104module_param(stall_cpu, int, 0444);
105MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable.");
106static int stall_cpu_holdoff = 10;
107module_param(stall_cpu_holdoff, int, 0444);
108MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s).");
109static int stat_interval = 60;
110module_param(stat_interval, int, 0644);
111MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
112static int stutter = 5;
113module_param(stutter, int, 0444);
114MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
115static int test_boost = 1;
116module_param(test_boost, int, 0444);
117MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
118static int test_boost_duration = 4;
119module_param(test_boost_duration, int, 0444);
120MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
121static int test_boost_interval = 7;
122module_param(test_boost_interval, int, 0444);
123MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
124static bool test_no_idle_hz = true;
125module_param(test_no_idle_hz, bool, 0444);
126MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
127static char *torture_type = "rcu"; 92static char *torture_type = "rcu";
128module_param(torture_type, charp, 0444); 93module_param(torture_type, charp, 0444);
129MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)"); 94MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
130static bool verbose;
131module_param(verbose, bool, 0444);
132MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
133
134#define TORTURE_FLAG "-torture:"
135#define PRINTK_STRING(s) \
136 do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
137#define VERBOSE_PRINTK_STRING(s) \
138 do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
139#define VERBOSE_PRINTK_ERRSTRING(s) \
140 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
141 95
142static int nrealreaders; 96static int nrealreaders;
143static struct task_struct *writer_task; 97static struct task_struct *writer_task;
144static struct task_struct **fakewriter_tasks; 98static struct task_struct **fakewriter_tasks;
145static struct task_struct **reader_tasks; 99static struct task_struct **reader_tasks;
146static struct task_struct *stats_task; 100static struct task_struct *stats_task;
147static struct task_struct *shuffler_task;
148static struct task_struct *stutter_task;
149static struct task_struct *fqs_task; 101static struct task_struct *fqs_task;
150static struct task_struct *boost_tasks[NR_CPUS]; 102static struct task_struct *boost_tasks[NR_CPUS];
151static struct task_struct *shutdown_task;
152#ifdef CONFIG_HOTPLUG_CPU
153static struct task_struct *onoff_task;
154#endif /* #ifdef CONFIG_HOTPLUG_CPU */
155static struct task_struct *stall_task; 103static struct task_struct *stall_task;
156static struct task_struct **barrier_cbs_tasks; 104static struct task_struct **barrier_cbs_tasks;
157static struct task_struct *barrier_task; 105static struct task_struct *barrier_task;
@@ -170,10 +118,10 @@ static struct rcu_torture __rcu *rcu_torture_current;
170static unsigned long rcu_torture_current_version; 118static unsigned long rcu_torture_current_version;
171static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; 119static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
172static DEFINE_SPINLOCK(rcu_torture_lock); 120static DEFINE_SPINLOCK(rcu_torture_lock);
173static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) = 121static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
174 { 0 }; 122 rcu_torture_count) = { 0 };
175static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) = 123static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
176 { 0 }; 124 rcu_torture_batch) = { 0 };
177static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; 125static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
178static atomic_t n_rcu_torture_alloc; 126static atomic_t n_rcu_torture_alloc;
179static atomic_t n_rcu_torture_alloc_fail; 127static atomic_t n_rcu_torture_alloc_fail;
@@ -186,22 +134,9 @@ static long n_rcu_torture_boost_rterror;
186static long n_rcu_torture_boost_failure; 134static long n_rcu_torture_boost_failure;
187static long n_rcu_torture_boosts; 135static long n_rcu_torture_boosts;
188static long n_rcu_torture_timers; 136static long n_rcu_torture_timers;
189static long n_offline_attempts;
190static long n_offline_successes;
191static unsigned long sum_offline;
192static int min_offline = -1;
193static int max_offline;
194static long n_online_attempts;
195static long n_online_successes;
196static unsigned long sum_online;
197static int min_online = -1;
198static int max_online;
199static long n_barrier_attempts; 137static long n_barrier_attempts;
200static long n_barrier_successes; 138static long n_barrier_successes;
201static struct list_head rcu_torture_removed; 139static struct list_head rcu_torture_removed;
202static cpumask_var_t shuffle_tmp_mask;
203
204static int stutter_pause_test;
205 140
206#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE) 141#if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
207#define RCUTORTURE_RUNNABLE_INIT 1 142#define RCUTORTURE_RUNNABLE_INIT 1
@@ -232,7 +167,6 @@ static u64 notrace rcu_trace_clock_local(void)
232} 167}
233#endif /* #else #ifdef CONFIG_RCU_TRACE */ 168#endif /* #else #ifdef CONFIG_RCU_TRACE */
234 169
235static unsigned long shutdown_time; /* jiffies to system shutdown. */
236static unsigned long boost_starttime; /* jiffies of next boost test start. */ 170static unsigned long boost_starttime; /* jiffies of next boost test start. */
237DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */ 171DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
238 /* and boost task create/destroy. */ 172 /* and boost task create/destroy. */
@@ -242,51 +176,6 @@ static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
242static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */ 176static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
243static DECLARE_WAIT_QUEUE_HEAD(barrier_wq); 177static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
244 178
245/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
246
247#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
248#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
249#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
250static int fullstop = FULLSTOP_RMMOD;
251/*
252 * Protect fullstop transitions and spawning of kthreads.
253 */
254static DEFINE_MUTEX(fullstop_mutex);
255
256/* Forward reference. */
257static void rcu_torture_cleanup(void);
258
259/*
260 * Detect and respond to a system shutdown.
261 */
262static int
263rcutorture_shutdown_notify(struct notifier_block *unused1,
264 unsigned long unused2, void *unused3)
265{
266 mutex_lock(&fullstop_mutex);
267 if (fullstop == FULLSTOP_DONTSTOP)
268 fullstop = FULLSTOP_SHUTDOWN;
269 else
270 pr_warn(/* but going down anyway, so... */
271 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
272 mutex_unlock(&fullstop_mutex);
273 return NOTIFY_DONE;
274}
275
276/*
277 * Absorb kthreads into a kernel function that won't return, so that
278 * they won't ever access module text or data again.
279 */
280static void rcutorture_shutdown_absorb(const char *title)
281{
282 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
283 pr_notice(
284 "rcutorture thread %s parking due to system shutdown\n",
285 title);
286 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
287 }
288}
289
290/* 179/*
291 * Allocate an element from the rcu_tortures pool. 180 * Allocate an element from the rcu_tortures pool.
292 */ 181 */
@@ -320,44 +209,6 @@ rcu_torture_free(struct rcu_torture *p)
320 spin_unlock_bh(&rcu_torture_lock); 209 spin_unlock_bh(&rcu_torture_lock);
321} 210}
322 211
323struct rcu_random_state {
324 unsigned long rrs_state;
325 long rrs_count;
326};
327
328#define RCU_RANDOM_MULT 39916801 /* prime */
329#define RCU_RANDOM_ADD 479001701 /* prime */
330#define RCU_RANDOM_REFRESH 10000
331
332#define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
333
334/*
335 * Crude but fast random-number generator. Uses a linear congruential
336 * generator, with occasional help from cpu_clock().
337 */
338static unsigned long
339rcu_random(struct rcu_random_state *rrsp)
340{
341 if (--rrsp->rrs_count < 0) {
342 rrsp->rrs_state += (unsigned long)local_clock();
343 rrsp->rrs_count = RCU_RANDOM_REFRESH;
344 }
345 rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
346 return swahw32(rrsp->rrs_state);
347}
348
349static void
350rcu_stutter_wait(const char *title)
351{
352 while (stutter_pause_test || !rcutorture_runnable) {
353 if (rcutorture_runnable)
354 schedule_timeout_interruptible(1);
355 else
356 schedule_timeout_interruptible(round_jiffies_relative(HZ));
357 rcutorture_shutdown_absorb(title);
358 }
359}
360
361/* 212/*
362 * Operations vector for selecting different types of tests. 213 * Operations vector for selecting different types of tests.
363 */ 214 */
@@ -365,7 +216,7 @@ rcu_stutter_wait(const char *title)
365struct rcu_torture_ops { 216struct rcu_torture_ops {
366 void (*init)(void); 217 void (*init)(void);
367 int (*readlock)(void); 218 int (*readlock)(void);
368 void (*read_delay)(struct rcu_random_state *rrsp); 219 void (*read_delay)(struct torture_random_state *rrsp);
369 void (*readunlock)(int idx); 220 void (*readunlock)(int idx);
370 int (*completed)(void); 221 int (*completed)(void);
371 void (*deferred_free)(struct rcu_torture *p); 222 void (*deferred_free)(struct rcu_torture *p);
@@ -392,7 +243,7 @@ static int rcu_torture_read_lock(void) __acquires(RCU)
392 return 0; 243 return 0;
393} 244}
394 245
395static void rcu_read_delay(struct rcu_random_state *rrsp) 246static void rcu_read_delay(struct torture_random_state *rrsp)
396{ 247{
397 const unsigned long shortdelay_us = 200; 248 const unsigned long shortdelay_us = 200;
398 const unsigned long longdelay_ms = 50; 249 const unsigned long longdelay_ms = 50;
@@ -401,12 +252,13 @@ static void rcu_read_delay(struct rcu_random_state *rrsp)
401 * period, and we want a long delay occasionally to trigger 252 * period, and we want a long delay occasionally to trigger
402 * force_quiescent_state. */ 253 * force_quiescent_state. */
403 254
404 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms))) 255 if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
405 mdelay(longdelay_ms); 256 mdelay(longdelay_ms);
406 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us))) 257 if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
407 udelay(shortdelay_us); 258 udelay(shortdelay_us);
408#ifdef CONFIG_PREEMPT 259#ifdef CONFIG_PREEMPT
409 if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000))) 260 if (!preempt_count() &&
261 !(torture_random(rrsp) % (nrealreaders * 20000)))
410 preempt_schedule(); /* No QS if preempt_disable() in effect */ 262 preempt_schedule(); /* No QS if preempt_disable() in effect */
411#endif 263#endif
412} 264}
@@ -427,7 +279,7 @@ rcu_torture_cb(struct rcu_head *p)
427 int i; 279 int i;
428 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); 280 struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
429 281
430 if (fullstop != FULLSTOP_DONTSTOP) { 282 if (torture_must_stop_irq()) {
431 /* Test is ending, just drop callbacks on the floor. */ 283 /* Test is ending, just drop callbacks on the floor. */
432 /* The next initialization will pick up the pieces. */ 284 /* The next initialization will pick up the pieces. */
433 return; 285 return;
@@ -520,6 +372,48 @@ static struct rcu_torture_ops rcu_bh_ops = {
520}; 372};
521 373
522/* 374/*
375 * Don't even think about trying any of these in real life!!!
376 * The names includes "busted", and they really means it!
377 * The only purpose of these functions is to provide a buggy RCU
378 * implementation to make sure that rcutorture correctly emits
379 * buggy-RCU error messages.
380 */
381static void rcu_busted_torture_deferred_free(struct rcu_torture *p)
382{
383 /* This is a deliberate bug for testing purposes only! */
384 rcu_torture_cb(&p->rtort_rcu);
385}
386
387static void synchronize_rcu_busted(void)
388{
389 /* This is a deliberate bug for testing purposes only! */
390}
391
392static void
393call_rcu_busted(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
394{
395 /* This is a deliberate bug for testing purposes only! */
396 func(head);
397}
398
399static struct rcu_torture_ops rcu_busted_ops = {
400 .init = rcu_sync_torture_init,
401 .readlock = rcu_torture_read_lock,
402 .read_delay = rcu_read_delay, /* just reuse rcu's version. */
403 .readunlock = rcu_torture_read_unlock,
404 .completed = rcu_no_completed,
405 .deferred_free = rcu_busted_torture_deferred_free,
406 .sync = synchronize_rcu_busted,
407 .exp_sync = synchronize_rcu_busted,
408 .call = call_rcu_busted,
409 .cb_barrier = NULL,
410 .fqs = NULL,
411 .stats = NULL,
412 .irq_capable = 1,
413 .name = "rcu_busted"
414};
415
416/*
523 * Definitions for srcu torture testing. 417 * Definitions for srcu torture testing.
524 */ 418 */
525 419
@@ -530,7 +424,7 @@ static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
530 return srcu_read_lock(&srcu_ctl); 424 return srcu_read_lock(&srcu_ctl);
531} 425}
532 426
533static void srcu_read_delay(struct rcu_random_state *rrsp) 427static void srcu_read_delay(struct torture_random_state *rrsp)
534{ 428{
535 long delay; 429 long delay;
536 const long uspertick = 1000000 / HZ; 430 const long uspertick = 1000000 / HZ;
@@ -538,7 +432,8 @@ static void srcu_read_delay(struct rcu_random_state *rrsp)
538 432
539 /* We want there to be long-running readers, but not all the time. */ 433 /* We want there to be long-running readers, but not all the time. */
540 434
541 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); 435 delay = torture_random(rrsp) %
436 (nrealreaders * 2 * longdelay * uspertick);
542 if (!delay) 437 if (!delay)
543 schedule_timeout_interruptible(longdelay); 438 schedule_timeout_interruptible(longdelay);
544 else 439 else
@@ -677,12 +572,12 @@ static int rcu_torture_boost(void *arg)
677 struct rcu_boost_inflight rbi = { .inflight = 0 }; 572 struct rcu_boost_inflight rbi = { .inflight = 0 };
678 struct sched_param sp; 573 struct sched_param sp;
679 574
680 VERBOSE_PRINTK_STRING("rcu_torture_boost started"); 575 VERBOSE_TOROUT_STRING("rcu_torture_boost started");
681 576
682 /* Set real-time priority. */ 577 /* Set real-time priority. */
683 sp.sched_priority = 1; 578 sp.sched_priority = 1;
684 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) { 579 if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
685 VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!"); 580 VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!");
686 n_rcu_torture_boost_rterror++; 581 n_rcu_torture_boost_rterror++;
687 } 582 }
688 583
@@ -693,9 +588,8 @@ static int rcu_torture_boost(void *arg)
693 oldstarttime = boost_starttime; 588 oldstarttime = boost_starttime;
694 while (ULONG_CMP_LT(jiffies, oldstarttime)) { 589 while (ULONG_CMP_LT(jiffies, oldstarttime)) {
695 schedule_timeout_interruptible(oldstarttime - jiffies); 590 schedule_timeout_interruptible(oldstarttime - jiffies);
696 rcu_stutter_wait("rcu_torture_boost"); 591 stutter_wait("rcu_torture_boost");
697 if (kthread_should_stop() || 592 if (torture_must_stop())
698 fullstop != FULLSTOP_DONTSTOP)
699 goto checkwait; 593 goto checkwait;
700 } 594 }
701 595
@@ -710,15 +604,14 @@ static int rcu_torture_boost(void *arg)
710 call_rcu(&rbi.rcu, rcu_torture_boost_cb); 604 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
711 if (jiffies - call_rcu_time > 605 if (jiffies - call_rcu_time >
712 test_boost_duration * HZ - HZ / 2) { 606 test_boost_duration * HZ - HZ / 2) {
713 VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed"); 607 VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed");
714 n_rcu_torture_boost_failure++; 608 n_rcu_torture_boost_failure++;
715 } 609 }
716 call_rcu_time = jiffies; 610 call_rcu_time = jiffies;
717 } 611 }
718 cond_resched(); 612 cond_resched();
719 rcu_stutter_wait("rcu_torture_boost"); 613 stutter_wait("rcu_torture_boost");
720 if (kthread_should_stop() || 614 if (torture_must_stop())
721 fullstop != FULLSTOP_DONTSTOP)
722 goto checkwait; 615 goto checkwait;
723 } 616 }
724 617
@@ -742,16 +635,17 @@ static int rcu_torture_boost(void *arg)
742 } 635 }
743 636
744 /* Go do the stutter. */ 637 /* Go do the stutter. */
745checkwait: rcu_stutter_wait("rcu_torture_boost"); 638checkwait: stutter_wait("rcu_torture_boost");
746 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); 639 } while (!torture_must_stop());
747 640
748 /* Clean up and exit. */ 641 /* Clean up and exit. */
749 VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping"); 642 while (!kthread_should_stop() || rbi.inflight) {
750 rcutorture_shutdown_absorb("rcu_torture_boost"); 643 torture_shutdown_absorb("rcu_torture_boost");
751 while (!kthread_should_stop() || rbi.inflight)
752 schedule_timeout_uninterruptible(1); 644 schedule_timeout_uninterruptible(1);
645 }
753 smp_mb(); /* order accesses to ->inflight before stack-frame death. */ 646 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
754 destroy_rcu_head_on_stack(&rbi.rcu); 647 destroy_rcu_head_on_stack(&rbi.rcu);
648 torture_kthread_stopping("rcu_torture_boost");
755 return 0; 649 return 0;
756} 650}
757 651
@@ -766,7 +660,7 @@ rcu_torture_fqs(void *arg)
766 unsigned long fqs_resume_time; 660 unsigned long fqs_resume_time;
767 int fqs_burst_remaining; 661 int fqs_burst_remaining;
768 662
769 VERBOSE_PRINTK_STRING("rcu_torture_fqs task started"); 663 VERBOSE_TOROUT_STRING("rcu_torture_fqs task started");
770 do { 664 do {
771 fqs_resume_time = jiffies + fqs_stutter * HZ; 665 fqs_resume_time = jiffies + fqs_stutter * HZ;
772 while (ULONG_CMP_LT(jiffies, fqs_resume_time) && 666 while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
@@ -780,12 +674,9 @@ rcu_torture_fqs(void *arg)
780 udelay(fqs_holdoff); 674 udelay(fqs_holdoff);
781 fqs_burst_remaining -= fqs_holdoff; 675 fqs_burst_remaining -= fqs_holdoff;
782 } 676 }
783 rcu_stutter_wait("rcu_torture_fqs"); 677 stutter_wait("rcu_torture_fqs");
784 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); 678 } while (!torture_must_stop());
785 VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping"); 679 torture_kthread_stopping("rcu_torture_fqs");
786 rcutorture_shutdown_absorb("rcu_torture_fqs");
787 while (!kthread_should_stop())
788 schedule_timeout_uninterruptible(1);
789 return 0; 680 return 0;
790} 681}
791 682
@@ -802,10 +693,10 @@ rcu_torture_writer(void *arg)
802 struct rcu_torture *rp; 693 struct rcu_torture *rp;
803 struct rcu_torture *rp1; 694 struct rcu_torture *rp1;
804 struct rcu_torture *old_rp; 695 struct rcu_torture *old_rp;
805 static DEFINE_RCU_RANDOM(rand); 696 static DEFINE_TORTURE_RANDOM(rand);
806 697
807 VERBOSE_PRINTK_STRING("rcu_torture_writer task started"); 698 VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
808 set_user_nice(current, 19); 699 set_user_nice(current, MAX_NICE);
809 700
810 do { 701 do {
811 schedule_timeout_uninterruptible(1); 702 schedule_timeout_uninterruptible(1);
@@ -813,7 +704,7 @@ rcu_torture_writer(void *arg)
813 if (rp == NULL) 704 if (rp == NULL)
814 continue; 705 continue;
815 rp->rtort_pipe_count = 0; 706 rp->rtort_pipe_count = 0;
816 udelay(rcu_random(&rand) & 0x3ff); 707 udelay(torture_random(&rand) & 0x3ff);
817 old_rp = rcu_dereference_check(rcu_torture_current, 708 old_rp = rcu_dereference_check(rcu_torture_current,
818 current == writer_task); 709 current == writer_task);
819 rp->rtort_mbtest = 1; 710 rp->rtort_mbtest = 1;
@@ -826,7 +717,7 @@ rcu_torture_writer(void *arg)
826 atomic_inc(&rcu_torture_wcount[i]); 717 atomic_inc(&rcu_torture_wcount[i]);
827 old_rp->rtort_pipe_count++; 718 old_rp->rtort_pipe_count++;
828 if (gp_normal == gp_exp) 719 if (gp_normal == gp_exp)
829 exp = !!(rcu_random(&rand) & 0x80); 720 exp = !!(torture_random(&rand) & 0x80);
830 else 721 else
831 exp = gp_exp; 722 exp = gp_exp;
832 if (!exp) { 723 if (!exp) {
@@ -852,12 +743,9 @@ rcu_torture_writer(void *arg)
852 } 743 }
853 } 744 }
854 rcutorture_record_progress(++rcu_torture_current_version); 745 rcutorture_record_progress(++rcu_torture_current_version);
855 rcu_stutter_wait("rcu_torture_writer"); 746 stutter_wait("rcu_torture_writer");
856 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); 747 } while (!torture_must_stop());
857 VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping"); 748 torture_kthread_stopping("rcu_torture_writer");
858 rcutorture_shutdown_absorb("rcu_torture_writer");
859 while (!kthread_should_stop())
860 schedule_timeout_uninterruptible(1);
861 return 0; 749 return 0;
862} 750}
863 751
@@ -868,19 +756,19 @@ rcu_torture_writer(void *arg)
868static int 756static int
869rcu_torture_fakewriter(void *arg) 757rcu_torture_fakewriter(void *arg)
870{ 758{
871 DEFINE_RCU_RANDOM(rand); 759 DEFINE_TORTURE_RANDOM(rand);
872 760
873 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started"); 761 VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
874 set_user_nice(current, 19); 762 set_user_nice(current, MAX_NICE);
875 763
876 do { 764 do {
877 schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10); 765 schedule_timeout_uninterruptible(1 + torture_random(&rand)%10);
878 udelay(rcu_random(&rand) & 0x3ff); 766 udelay(torture_random(&rand) & 0x3ff);
879 if (cur_ops->cb_barrier != NULL && 767 if (cur_ops->cb_barrier != NULL &&
880 rcu_random(&rand) % (nfakewriters * 8) == 0) { 768 torture_random(&rand) % (nfakewriters * 8) == 0) {
881 cur_ops->cb_barrier(); 769 cur_ops->cb_barrier();
882 } else if (gp_normal == gp_exp) { 770 } else if (gp_normal == gp_exp) {
883 if (rcu_random(&rand) & 0x80) 771 if (torture_random(&rand) & 0x80)
884 cur_ops->sync(); 772 cur_ops->sync();
885 else 773 else
886 cur_ops->exp_sync(); 774 cur_ops->exp_sync();
@@ -889,13 +777,10 @@ rcu_torture_fakewriter(void *arg)
889 } else { 777 } else {
890 cur_ops->exp_sync(); 778 cur_ops->exp_sync();
891 } 779 }
892 rcu_stutter_wait("rcu_torture_fakewriter"); 780 stutter_wait("rcu_torture_fakewriter");
893 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); 781 } while (!torture_must_stop());
894 782
895 VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping"); 783 torture_kthread_stopping("rcu_torture_fakewriter");
896 rcutorture_shutdown_absorb("rcu_torture_fakewriter");
897 while (!kthread_should_stop())
898 schedule_timeout_uninterruptible(1);
899 return 0; 784 return 0;
900} 785}
901 786
@@ -921,7 +806,7 @@ static void rcu_torture_timer(unsigned long unused)
921 int idx; 806 int idx;
922 int completed; 807 int completed;
923 int completed_end; 808 int completed_end;
924 static DEFINE_RCU_RANDOM(rand); 809 static DEFINE_TORTURE_RANDOM(rand);
925 static DEFINE_SPINLOCK(rand_lock); 810 static DEFINE_SPINLOCK(rand_lock);
926 struct rcu_torture *p; 811 struct rcu_torture *p;
927 int pipe_count; 812 int pipe_count;
@@ -980,14 +865,14 @@ rcu_torture_reader(void *arg)
980 int completed; 865 int completed;
981 int completed_end; 866 int completed_end;
982 int idx; 867 int idx;
983 DEFINE_RCU_RANDOM(rand); 868 DEFINE_TORTURE_RANDOM(rand);
984 struct rcu_torture *p; 869 struct rcu_torture *p;
985 int pipe_count; 870 int pipe_count;
986 struct timer_list t; 871 struct timer_list t;
987 unsigned long long ts; 872 unsigned long long ts;
988 873
989 VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); 874 VERBOSE_TOROUT_STRING("rcu_torture_reader task started");
990 set_user_nice(current, 19); 875 set_user_nice(current, MAX_NICE);
991 if (irqreader && cur_ops->irq_capable) 876 if (irqreader && cur_ops->irq_capable)
992 setup_timer_on_stack(&t, rcu_torture_timer, 0); 877 setup_timer_on_stack(&t, rcu_torture_timer, 0);
993 878
@@ -1034,14 +919,11 @@ rcu_torture_reader(void *arg)
1034 preempt_enable(); 919 preempt_enable();
1035 cur_ops->readunlock(idx); 920 cur_ops->readunlock(idx);
1036 schedule(); 921 schedule();
1037 rcu_stutter_wait("rcu_torture_reader"); 922 stutter_wait("rcu_torture_reader");
1038 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); 923 } while (!torture_must_stop());
1039 VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
1040 rcutorture_shutdown_absorb("rcu_torture_reader");
1041 if (irqreader && cur_ops->irq_capable) 924 if (irqreader && cur_ops->irq_capable)
1042 del_timer_sync(&t); 925 del_timer_sync(&t);
1043 while (!kthread_should_stop()) 926 torture_kthread_stopping("rcu_torture_reader");
1044 schedule_timeout_uninterruptible(1);
1045 return 0; 927 return 0;
1046} 928}
1047 929
@@ -1083,13 +965,7 @@ rcu_torture_printk(char *page)
1083 n_rcu_torture_boost_failure, 965 n_rcu_torture_boost_failure,
1084 n_rcu_torture_boosts, 966 n_rcu_torture_boosts,
1085 n_rcu_torture_timers); 967 n_rcu_torture_timers);
1086 page += sprintf(page, 968 page = torture_onoff_stats(page);
1087 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1088 n_online_successes, n_online_attempts,
1089 n_offline_successes, n_offline_attempts,
1090 min_online, max_online,
1091 min_offline, max_offline,
1092 sum_online, sum_offline, HZ);
1093 page += sprintf(page, "barrier: %ld/%ld:%ld", 969 page += sprintf(page, "barrier: %ld/%ld:%ld",
1094 n_barrier_successes, 970 n_barrier_successes,
1095 n_barrier_attempts, 971 n_barrier_attempts,
@@ -1150,123 +1026,17 @@ rcu_torture_stats_print(void)
1150/* 1026/*
1151 * Periodically prints torture statistics, if periodic statistics printing 1027 * Periodically prints torture statistics, if periodic statistics printing
1152 * was specified via the stat_interval module parameter. 1028 * was specified via the stat_interval module parameter.
1153 *
1154 * No need to worry about fullstop here, since this one doesn't reference
1155 * volatile state or register callbacks.
1156 */ 1029 */
1157static int 1030static int
1158rcu_torture_stats(void *arg) 1031rcu_torture_stats(void *arg)
1159{ 1032{
1160 VERBOSE_PRINTK_STRING("rcu_torture_stats task started"); 1033 VERBOSE_TOROUT_STRING("rcu_torture_stats task started");
1161 do { 1034 do {
1162 schedule_timeout_interruptible(stat_interval * HZ); 1035 schedule_timeout_interruptible(stat_interval * HZ);
1163 rcu_torture_stats_print(); 1036 rcu_torture_stats_print();
1164 rcutorture_shutdown_absorb("rcu_torture_stats"); 1037 torture_shutdown_absorb("rcu_torture_stats");
1165 } while (!kthread_should_stop()); 1038 } while (!torture_must_stop());
1166 VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping"); 1039 torture_kthread_stopping("rcu_torture_stats");
1167 return 0;
1168}
1169
1170static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
1171
1172/* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
1173 * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
1174 */
1175static void rcu_torture_shuffle_tasks(void)
1176{
1177 int i;
1178
1179 cpumask_setall(shuffle_tmp_mask);
1180 get_online_cpus();
1181
1182 /* No point in shuffling if there is only one online CPU (ex: UP) */
1183 if (num_online_cpus() == 1) {
1184 put_online_cpus();
1185 return;
1186 }
1187
1188 if (rcu_idle_cpu != -1)
1189 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
1190
1191 set_cpus_allowed_ptr(current, shuffle_tmp_mask);
1192
1193 if (reader_tasks) {
1194 for (i = 0; i < nrealreaders; i++)
1195 if (reader_tasks[i])
1196 set_cpus_allowed_ptr(reader_tasks[i],
1197 shuffle_tmp_mask);
1198 }
1199 if (fakewriter_tasks) {
1200 for (i = 0; i < nfakewriters; i++)
1201 if (fakewriter_tasks[i])
1202 set_cpus_allowed_ptr(fakewriter_tasks[i],
1203 shuffle_tmp_mask);
1204 }
1205 if (writer_task)
1206 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
1207 if (stats_task)
1208 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
1209 if (stutter_task)
1210 set_cpus_allowed_ptr(stutter_task, shuffle_tmp_mask);
1211 if (fqs_task)
1212 set_cpus_allowed_ptr(fqs_task, shuffle_tmp_mask);
1213 if (shutdown_task)
1214 set_cpus_allowed_ptr(shutdown_task, shuffle_tmp_mask);
1215#ifdef CONFIG_HOTPLUG_CPU
1216 if (onoff_task)
1217 set_cpus_allowed_ptr(onoff_task, shuffle_tmp_mask);
1218#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1219 if (stall_task)
1220 set_cpus_allowed_ptr(stall_task, shuffle_tmp_mask);
1221 if (barrier_cbs_tasks)
1222 for (i = 0; i < n_barrier_cbs; i++)
1223 if (barrier_cbs_tasks[i])
1224 set_cpus_allowed_ptr(barrier_cbs_tasks[i],
1225 shuffle_tmp_mask);
1226 if (barrier_task)
1227 set_cpus_allowed_ptr(barrier_task, shuffle_tmp_mask);
1228
1229 if (rcu_idle_cpu == -1)
1230 rcu_idle_cpu = num_online_cpus() - 1;
1231 else
1232 rcu_idle_cpu--;
1233
1234 put_online_cpus();
1235}
1236
1237/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
1238 * system to become idle at a time and cut off its timer ticks. This is meant
1239 * to test the support for such tickless idle CPU in RCU.
1240 */
1241static int
1242rcu_torture_shuffle(void *arg)
1243{
1244 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
1245 do {
1246 schedule_timeout_interruptible(shuffle_interval * HZ);
1247 rcu_torture_shuffle_tasks();
1248 rcutorture_shutdown_absorb("rcu_torture_shuffle");
1249 } while (!kthread_should_stop());
1250 VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
1251 return 0;
1252}
1253
1254/* Cause the rcutorture test to "stutter", starting and stopping all
1255 * threads periodically.
1256 */
1257static int
1258rcu_torture_stutter(void *arg)
1259{
1260 VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
1261 do {
1262 schedule_timeout_interruptible(stutter * HZ);
1263 stutter_pause_test = 1;
1264 if (!kthread_should_stop())
1265 schedule_timeout_interruptible(stutter * HZ);
1266 stutter_pause_test = 0;
1267 rcutorture_shutdown_absorb("rcu_torture_stutter");
1268 } while (!kthread_should_stop());
1269 VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
1270 return 0; 1040 return 0;
1271} 1041}
1272 1042
@@ -1293,10 +1063,6 @@ rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
1293 onoff_interval, onoff_holdoff); 1063 onoff_interval, onoff_holdoff);
1294} 1064}
1295 1065
1296static struct notifier_block rcutorture_shutdown_nb = {
1297 .notifier_call = rcutorture_shutdown_notify,
1298};
1299
1300static void rcutorture_booster_cleanup(int cpu) 1066static void rcutorture_booster_cleanup(int cpu)
1301{ 1067{
1302 struct task_struct *t; 1068 struct task_struct *t;
@@ -1304,14 +1070,12 @@ static void rcutorture_booster_cleanup(int cpu)
1304 if (boost_tasks[cpu] == NULL) 1070 if (boost_tasks[cpu] == NULL)
1305 return; 1071 return;
1306 mutex_lock(&boost_mutex); 1072 mutex_lock(&boost_mutex);
1307 VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
1308 t = boost_tasks[cpu]; 1073 t = boost_tasks[cpu];
1309 boost_tasks[cpu] = NULL; 1074 boost_tasks[cpu] = NULL;
1310 mutex_unlock(&boost_mutex); 1075 mutex_unlock(&boost_mutex);
1311 1076
1312 /* This must be outside of the mutex, otherwise deadlock! */ 1077 /* This must be outside of the mutex, otherwise deadlock! */
1313 kthread_stop(t); 1078 torture_stop_kthread(rcu_torture_boost, t);
1314 boost_tasks[cpu] = NULL;
1315} 1079}
1316 1080
1317static int rcutorture_booster_init(int cpu) 1081static int rcutorture_booster_init(int cpu)
@@ -1323,13 +1087,13 @@ static int rcutorture_booster_init(int cpu)
1323 1087
1324 /* Don't allow time recalculation while creating a new task. */ 1088 /* Don't allow time recalculation while creating a new task. */
1325 mutex_lock(&boost_mutex); 1089 mutex_lock(&boost_mutex);
1326 VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task"); 1090 VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task");
1327 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL, 1091 boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
1328 cpu_to_node(cpu), 1092 cpu_to_node(cpu),
1329 "rcu_torture_boost"); 1093 "rcu_torture_boost");
1330 if (IS_ERR(boost_tasks[cpu])) { 1094 if (IS_ERR(boost_tasks[cpu])) {
1331 retval = PTR_ERR(boost_tasks[cpu]); 1095 retval = PTR_ERR(boost_tasks[cpu]);
1332 VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed"); 1096 VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed");
1333 n_rcu_torture_boost_ktrerror++; 1097 n_rcu_torture_boost_ktrerror++;
1334 boost_tasks[cpu] = NULL; 1098 boost_tasks[cpu] = NULL;
1335 mutex_unlock(&boost_mutex); 1099 mutex_unlock(&boost_mutex);
@@ -1342,175 +1106,6 @@ static int rcutorture_booster_init(int cpu)
1342} 1106}
1343 1107
1344/* 1108/*
1345 * Cause the rcutorture test to shutdown the system after the test has
1346 * run for the time specified by the shutdown_secs module parameter.
1347 */
1348static int
1349rcu_torture_shutdown(void *arg)
1350{
1351 long delta;
1352 unsigned long jiffies_snap;
1353
1354 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
1355 jiffies_snap = ACCESS_ONCE(jiffies);
1356 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
1357 !kthread_should_stop()) {
1358 delta = shutdown_time - jiffies_snap;
1359 if (verbose)
1360 pr_alert("%s" TORTURE_FLAG
1361 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1362 torture_type, delta);
1363 schedule_timeout_interruptible(delta);
1364 jiffies_snap = ACCESS_ONCE(jiffies);
1365 }
1366 if (kthread_should_stop()) {
1367 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
1368 return 0;
1369 }
1370
1371 /* OK, shut down the system. */
1372
1373 VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
1374 shutdown_task = NULL; /* Avoid self-kill deadlock. */
1375 rcu_torture_cleanup(); /* Get the success/failure message. */
1376 kernel_power_off(); /* Shut down the system. */
1377 return 0;
1378}
1379
1380#ifdef CONFIG_HOTPLUG_CPU
1381
1382/*
1383 * Execute random CPU-hotplug operations at the interval specified
1384 * by the onoff_interval.
1385 */
1386static int
1387rcu_torture_onoff(void *arg)
1388{
1389 int cpu;
1390 unsigned long delta;
1391 int maxcpu = -1;
1392 DEFINE_RCU_RANDOM(rand);
1393 int ret;
1394 unsigned long starttime;
1395
1396 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1397 for_each_online_cpu(cpu)
1398 maxcpu = cpu;
1399 WARN_ON(maxcpu < 0);
1400 if (onoff_holdoff > 0) {
1401 VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff");
1402 schedule_timeout_interruptible(onoff_holdoff * HZ);
1403 VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff");
1404 }
1405 while (!kthread_should_stop()) {
1406 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
1407 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
1408 if (verbose)
1409 pr_alert("%s" TORTURE_FLAG
1410 "rcu_torture_onoff task: offlining %d\n",
1411 torture_type, cpu);
1412 starttime = jiffies;
1413 n_offline_attempts++;
1414 ret = cpu_down(cpu);
1415 if (ret) {
1416 if (verbose)
1417 pr_alert("%s" TORTURE_FLAG
1418 "rcu_torture_onoff task: offline %d failed: errno %d\n",
1419 torture_type, cpu, ret);
1420 } else {
1421 if (verbose)
1422 pr_alert("%s" TORTURE_FLAG
1423 "rcu_torture_onoff task: offlined %d\n",
1424 torture_type, cpu);
1425 n_offline_successes++;
1426 delta = jiffies - starttime;
1427 sum_offline += delta;
1428 if (min_offline < 0) {
1429 min_offline = delta;
1430 max_offline = delta;
1431 }
1432 if (min_offline > delta)
1433 min_offline = delta;
1434 if (max_offline < delta)
1435 max_offline = delta;
1436 }
1437 } else if (cpu_is_hotpluggable(cpu)) {
1438 if (verbose)
1439 pr_alert("%s" TORTURE_FLAG
1440 "rcu_torture_onoff task: onlining %d\n",
1441 torture_type, cpu);
1442 starttime = jiffies;
1443 n_online_attempts++;
1444 ret = cpu_up(cpu);
1445 if (ret) {
1446 if (verbose)
1447 pr_alert("%s" TORTURE_FLAG
1448 "rcu_torture_onoff task: online %d failed: errno %d\n",
1449 torture_type, cpu, ret);
1450 } else {
1451 if (verbose)
1452 pr_alert("%s" TORTURE_FLAG
1453 "rcu_torture_onoff task: onlined %d\n",
1454 torture_type, cpu);
1455 n_online_successes++;
1456 delta = jiffies - starttime;
1457 sum_online += delta;
1458 if (min_online < 0) {
1459 min_online = delta;
1460 max_online = delta;
1461 }
1462 if (min_online > delta)
1463 min_online = delta;
1464 if (max_online < delta)
1465 max_online = delta;
1466 }
1467 }
1468 schedule_timeout_interruptible(onoff_interval * HZ);
1469 }
1470 VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1471 return 0;
1472}
1473
1474static int
1475rcu_torture_onoff_init(void)
1476{
1477 int ret;
1478
1479 if (onoff_interval <= 0)
1480 return 0;
1481 onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1482 if (IS_ERR(onoff_task)) {
1483 ret = PTR_ERR(onoff_task);
1484 onoff_task = NULL;
1485 return ret;
1486 }
1487 return 0;
1488}
1489
1490static void rcu_torture_onoff_cleanup(void)
1491{
1492 if (onoff_task == NULL)
1493 return;
1494 VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1495 kthread_stop(onoff_task);
1496 onoff_task = NULL;
1497}
1498
1499#else /* #ifdef CONFIG_HOTPLUG_CPU */
1500
1501static int
1502rcu_torture_onoff_init(void)
1503{
1504 return 0;
1505}
1506
1507static void rcu_torture_onoff_cleanup(void)
1508{
1509}
1510
1511#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1512
1513/*
1514 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then 1109 * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
1515 * induces a CPU stall for the time specified by stall_cpu. 1110 * induces a CPU stall for the time specified by stall_cpu.
1516 */ 1111 */
@@ -1518,11 +1113,11 @@ static int rcu_torture_stall(void *args)
1518{ 1113{
1519 unsigned long stop_at; 1114 unsigned long stop_at;
1520 1115
1521 VERBOSE_PRINTK_STRING("rcu_torture_stall task started"); 1116 VERBOSE_TOROUT_STRING("rcu_torture_stall task started");
1522 if (stall_cpu_holdoff > 0) { 1117 if (stall_cpu_holdoff > 0) {
1523 VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff"); 1118 VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff");
1524 schedule_timeout_interruptible(stall_cpu_holdoff * HZ); 1119 schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
1525 VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff"); 1120 VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff");
1526 } 1121 }
1527 if (!kthread_should_stop()) { 1122 if (!kthread_should_stop()) {
1528 stop_at = get_seconds() + stall_cpu; 1123 stop_at = get_seconds() + stall_cpu;
@@ -1536,7 +1131,7 @@ static int rcu_torture_stall(void *args)
1536 rcu_read_unlock(); 1131 rcu_read_unlock();
1537 pr_alert("rcu_torture_stall end.\n"); 1132 pr_alert("rcu_torture_stall end.\n");
1538 } 1133 }
1539 rcutorture_shutdown_absorb("rcu_torture_stall"); 1134 torture_shutdown_absorb("rcu_torture_stall");
1540 while (!kthread_should_stop()) 1135 while (!kthread_should_stop())
1541 schedule_timeout_interruptible(10 * HZ); 1136 schedule_timeout_interruptible(10 * HZ);
1542 return 0; 1137 return 0;
@@ -1545,27 +1140,9 @@ static int rcu_torture_stall(void *args)
1545/* Spawn CPU-stall kthread, if stall_cpu specified. */ 1140/* Spawn CPU-stall kthread, if stall_cpu specified. */
1546static int __init rcu_torture_stall_init(void) 1141static int __init rcu_torture_stall_init(void)
1547{ 1142{
1548 int ret;
1549
1550 if (stall_cpu <= 0) 1143 if (stall_cpu <= 0)
1551 return 0; 1144 return 0;
1552 stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall"); 1145 return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
1553 if (IS_ERR(stall_task)) {
1554 ret = PTR_ERR(stall_task);
1555 stall_task = NULL;
1556 return ret;
1557 }
1558 return 0;
1559}
1560
1561/* Clean up after the CPU-stall kthread, if one was spawned. */
1562static void rcu_torture_stall_cleanup(void)
1563{
1564 if (stall_task == NULL)
1565 return;
1566 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task.");
1567 kthread_stop(stall_task);
1568 stall_task = NULL;
1569} 1146}
1570 1147
1571/* Callback function for RCU barrier testing. */ 1148/* Callback function for RCU barrier testing. */
@@ -1583,28 +1160,24 @@ static int rcu_torture_barrier_cbs(void *arg)
1583 struct rcu_head rcu; 1160 struct rcu_head rcu;
1584 1161
1585 init_rcu_head_on_stack(&rcu); 1162 init_rcu_head_on_stack(&rcu);
1586 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started"); 1163 VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started");
1587 set_user_nice(current, 19); 1164 set_user_nice(current, MAX_NICE);
1588 do { 1165 do {
1589 wait_event(barrier_cbs_wq[myid], 1166 wait_event(barrier_cbs_wq[myid],
1590 (newphase = 1167 (newphase =
1591 ACCESS_ONCE(barrier_phase)) != lastphase || 1168 ACCESS_ONCE(barrier_phase)) != lastphase ||
1592 kthread_should_stop() || 1169 torture_must_stop());
1593 fullstop != FULLSTOP_DONTSTOP);
1594 lastphase = newphase; 1170 lastphase = newphase;
1595 smp_mb(); /* ensure barrier_phase load before ->call(). */ 1171 smp_mb(); /* ensure barrier_phase load before ->call(). */
1596 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP) 1172 if (torture_must_stop())
1597 break; 1173 break;
1598 cur_ops->call(&rcu, rcu_torture_barrier_cbf); 1174 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1599 if (atomic_dec_and_test(&barrier_cbs_count)) 1175 if (atomic_dec_and_test(&barrier_cbs_count))
1600 wake_up(&barrier_wq); 1176 wake_up(&barrier_wq);
1601 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); 1177 } while (!torture_must_stop());
1602 VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping");
1603 rcutorture_shutdown_absorb("rcu_torture_barrier_cbs");
1604 while (!kthread_should_stop())
1605 schedule_timeout_interruptible(1);
1606 cur_ops->cb_barrier(); 1178 cur_ops->cb_barrier();
1607 destroy_rcu_head_on_stack(&rcu); 1179 destroy_rcu_head_on_stack(&rcu);
1180 torture_kthread_stopping("rcu_torture_barrier_cbs");
1608 return 0; 1181 return 0;
1609} 1182}
1610 1183
@@ -1613,7 +1186,7 @@ static int rcu_torture_barrier(void *arg)
1613{ 1186{
1614 int i; 1187 int i;
1615 1188
1616 VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting"); 1189 VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting");
1617 do { 1190 do {
1618 atomic_set(&barrier_cbs_invoked, 0); 1191 atomic_set(&barrier_cbs_invoked, 0);
1619 atomic_set(&barrier_cbs_count, n_barrier_cbs); 1192 atomic_set(&barrier_cbs_count, n_barrier_cbs);
@@ -1623,9 +1196,8 @@ static int rcu_torture_barrier(void *arg)
1623 wake_up(&barrier_cbs_wq[i]); 1196 wake_up(&barrier_cbs_wq[i]);
1624 wait_event(barrier_wq, 1197 wait_event(barrier_wq,
1625 atomic_read(&barrier_cbs_count) == 0 || 1198 atomic_read(&barrier_cbs_count) == 0 ||
1626 kthread_should_stop() || 1199 torture_must_stop());
1627 fullstop != FULLSTOP_DONTSTOP); 1200 if (torture_must_stop())
1628 if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP)
1629 break; 1201 break;
1630 n_barrier_attempts++; 1202 n_barrier_attempts++;
1631 cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */ 1203 cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */
@@ -1635,11 +1207,8 @@ static int rcu_torture_barrier(void *arg)
1635 } 1207 }
1636 n_barrier_successes++; 1208 n_barrier_successes++;
1637 schedule_timeout_interruptible(HZ / 10); 1209 schedule_timeout_interruptible(HZ / 10);
1638 } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); 1210 } while (!torture_must_stop());
1639 VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping"); 1211 torture_kthread_stopping("rcu_torture_barrier");
1640 rcutorture_shutdown_absorb("rcu_torture_barrier");
1641 while (!kthread_should_stop())
1642 schedule_timeout_interruptible(1);
1643 return 0; 1212 return 0;
1644} 1213}
1645 1214
@@ -1672,24 +1241,13 @@ static int rcu_torture_barrier_init(void)
1672 return -ENOMEM; 1241 return -ENOMEM;
1673 for (i = 0; i < n_barrier_cbs; i++) { 1242 for (i = 0; i < n_barrier_cbs; i++) {
1674 init_waitqueue_head(&barrier_cbs_wq[i]); 1243 init_waitqueue_head(&barrier_cbs_wq[i]);
1675 barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs, 1244 ret = torture_create_kthread(rcu_torture_barrier_cbs,
1676 (void *)(long)i, 1245 (void *)(long)i,
1677 "rcu_torture_barrier_cbs"); 1246 barrier_cbs_tasks[i]);
1678 if (IS_ERR(barrier_cbs_tasks[i])) { 1247 if (ret)
1679 ret = PTR_ERR(barrier_cbs_tasks[i]);
1680 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs");
1681 barrier_cbs_tasks[i] = NULL;
1682 return ret; 1248 return ret;
1683 }
1684 } 1249 }
1685 barrier_task = kthread_run(rcu_torture_barrier, NULL, 1250 return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task);
1686 "rcu_torture_barrier");
1687 if (IS_ERR(barrier_task)) {
1688 ret = PTR_ERR(barrier_task);
1689 VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier");
1690 barrier_task = NULL;
1691 }
1692 return 0;
1693} 1251}
1694 1252
1695/* Clean up after RCU barrier testing. */ 1253/* Clean up after RCU barrier testing. */
@@ -1697,19 +1255,11 @@ static void rcu_torture_barrier_cleanup(void)
1697{ 1255{
1698 int i; 1256 int i;
1699 1257
1700 if (barrier_task != NULL) { 1258 torture_stop_kthread(rcu_torture_barrier, barrier_task);
1701 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task");
1702 kthread_stop(barrier_task);
1703 barrier_task = NULL;
1704 }
1705 if (barrier_cbs_tasks != NULL) { 1259 if (barrier_cbs_tasks != NULL) {
1706 for (i = 0; i < n_barrier_cbs; i++) { 1260 for (i = 0; i < n_barrier_cbs; i++)
1707 if (barrier_cbs_tasks[i] != NULL) { 1261 torture_stop_kthread(rcu_torture_barrier_cbs,
1708 VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task"); 1262 barrier_cbs_tasks[i]);
1709 kthread_stop(barrier_cbs_tasks[i]);
1710 barrier_cbs_tasks[i] = NULL;
1711 }
1712 }
1713 kfree(barrier_cbs_tasks); 1263 kfree(barrier_cbs_tasks);
1714 barrier_cbs_tasks = NULL; 1264 barrier_cbs_tasks = NULL;
1715 } 1265 }
@@ -1747,90 +1297,42 @@ rcu_torture_cleanup(void)
1747{ 1297{
1748 int i; 1298 int i;
1749 1299
1750 mutex_lock(&fullstop_mutex);
1751 rcutorture_record_test_transition(); 1300 rcutorture_record_test_transition();
1752 if (fullstop == FULLSTOP_SHUTDOWN) { 1301 if (torture_cleanup()) {
1753 pr_warn(/* but going down anyway, so... */
1754 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1755 mutex_unlock(&fullstop_mutex);
1756 schedule_timeout_uninterruptible(10);
1757 if (cur_ops->cb_barrier != NULL) 1302 if (cur_ops->cb_barrier != NULL)
1758 cur_ops->cb_barrier(); 1303 cur_ops->cb_barrier();
1759 return; 1304 return;
1760 } 1305 }
1761 fullstop = FULLSTOP_RMMOD;
1762 mutex_unlock(&fullstop_mutex);
1763 unregister_reboot_notifier(&rcutorture_shutdown_nb);
1764 rcu_torture_barrier_cleanup();
1765 rcu_torture_stall_cleanup();
1766 if (stutter_task) {
1767 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
1768 kthread_stop(stutter_task);
1769 }
1770 stutter_task = NULL;
1771 if (shuffler_task) {
1772 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
1773 kthread_stop(shuffler_task);
1774 free_cpumask_var(shuffle_tmp_mask);
1775 }
1776 shuffler_task = NULL;
1777 1306
1778 if (writer_task) { 1307 rcu_torture_barrier_cleanup();
1779 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task"); 1308 torture_stop_kthread(rcu_torture_stall, stall_task);
1780 kthread_stop(writer_task); 1309 torture_stop_kthread(rcu_torture_writer, writer_task);
1781 }
1782 writer_task = NULL;
1783 1310
1784 if (reader_tasks) { 1311 if (reader_tasks) {
1785 for (i = 0; i < nrealreaders; i++) { 1312 for (i = 0; i < nrealreaders; i++)
1786 if (reader_tasks[i]) { 1313 torture_stop_kthread(rcu_torture_reader,
1787 VERBOSE_PRINTK_STRING( 1314 reader_tasks[i]);
1788 "Stopping rcu_torture_reader task");
1789 kthread_stop(reader_tasks[i]);
1790 }
1791 reader_tasks[i] = NULL;
1792 }
1793 kfree(reader_tasks); 1315 kfree(reader_tasks);
1794 reader_tasks = NULL;
1795 } 1316 }
1796 rcu_torture_current = NULL; 1317 rcu_torture_current = NULL;
1797 1318
1798 if (fakewriter_tasks) { 1319 if (fakewriter_tasks) {
1799 for (i = 0; i < nfakewriters; i++) { 1320 for (i = 0; i < nfakewriters; i++) {
1800 if (fakewriter_tasks[i]) { 1321 torture_stop_kthread(rcu_torture_fakewriter,
1801 VERBOSE_PRINTK_STRING( 1322 fakewriter_tasks[i]);
1802 "Stopping rcu_torture_fakewriter task");
1803 kthread_stop(fakewriter_tasks[i]);
1804 }
1805 fakewriter_tasks[i] = NULL;
1806 } 1323 }
1807 kfree(fakewriter_tasks); 1324 kfree(fakewriter_tasks);
1808 fakewriter_tasks = NULL; 1325 fakewriter_tasks = NULL;
1809 } 1326 }
1810 1327
1811 if (stats_task) { 1328 torture_stop_kthread(rcu_torture_stats, stats_task);
1812 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task"); 1329 torture_stop_kthread(rcu_torture_fqs, fqs_task);
1813 kthread_stop(stats_task);
1814 }
1815 stats_task = NULL;
1816
1817 if (fqs_task) {
1818 VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1819 kthread_stop(fqs_task);
1820 }
1821 fqs_task = NULL;
1822 if ((test_boost == 1 && cur_ops->can_boost) || 1330 if ((test_boost == 1 && cur_ops->can_boost) ||
1823 test_boost == 2) { 1331 test_boost == 2) {
1824 unregister_cpu_notifier(&rcutorture_cpu_nb); 1332 unregister_cpu_notifier(&rcutorture_cpu_nb);
1825 for_each_possible_cpu(i) 1333 for_each_possible_cpu(i)
1826 rcutorture_booster_cleanup(i); 1334 rcutorture_booster_cleanup(i);
1827 } 1335 }
1828 if (shutdown_task != NULL) {
1829 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
1830 kthread_stop(shutdown_task);
1831 }
1832 shutdown_task = NULL;
1833 rcu_torture_onoff_cleanup();
1834 1336
1835 /* Wait for all RCU callbacks to fire. */ 1337 /* Wait for all RCU callbacks to fire. */
1836 1338
@@ -1841,8 +1343,7 @@ rcu_torture_cleanup(void)
1841 1343
1842 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error) 1344 if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
1843 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE"); 1345 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
1844 else if (n_online_successes != n_online_attempts || 1346 else if (torture_onoff_failures())
1845 n_offline_successes != n_offline_attempts)
1846 rcu_torture_print_module_parms(cur_ops, 1347 rcu_torture_print_module_parms(cur_ops,
1847 "End of test: RCU_HOTPLUG"); 1348 "End of test: RCU_HOTPLUG");
1848 else 1349 else
@@ -1911,12 +1412,11 @@ rcu_torture_init(void)
1911 int i; 1412 int i;
1912 int cpu; 1413 int cpu;
1913 int firsterr = 0; 1414 int firsterr = 0;
1914 int retval;
1915 static struct rcu_torture_ops *torture_ops[] = { 1415 static struct rcu_torture_ops *torture_ops[] = {
1916 &rcu_ops, &rcu_bh_ops, &srcu_ops, &sched_ops, 1416 &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &sched_ops,
1917 }; 1417 };
1918 1418
1919 mutex_lock(&fullstop_mutex); 1419 torture_init_begin(torture_type, verbose, &rcutorture_runnable);
1920 1420
1921 /* Process args and tell the world that the torturer is on the job. */ 1421 /* Process args and tell the world that the torturer is on the job. */
1922 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { 1422 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
@@ -1931,7 +1431,7 @@ rcu_torture_init(void)
1931 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) 1431 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1932 pr_alert(" %s", torture_ops[i]->name); 1432 pr_alert(" %s", torture_ops[i]->name);
1933 pr_alert("\n"); 1433 pr_alert("\n");
1934 mutex_unlock(&fullstop_mutex); 1434 torture_init_end();
1935 return -EINVAL; 1435 return -EINVAL;
1936 } 1436 }
1937 if (cur_ops->fqs == NULL && fqs_duration != 0) { 1437 if (cur_ops->fqs == NULL && fqs_duration != 0) {
@@ -1946,7 +1446,6 @@ rcu_torture_init(void)
1946 else 1446 else
1947 nrealreaders = 2 * num_online_cpus(); 1447 nrealreaders = 2 * num_online_cpus();
1948 rcu_torture_print_module_parms(cur_ops, "Start of test"); 1448 rcu_torture_print_module_parms(cur_ops, "Start of test");
1949 fullstop = FULLSTOP_DONTSTOP;
1950 1449
1951 /* Set up the freelist. */ 1450 /* Set up the freelist. */
1952 1451
@@ -1982,108 +1481,61 @@ rcu_torture_init(void)
1982 1481
1983 /* Start up the kthreads. */ 1482 /* Start up the kthreads. */
1984 1483
1985 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); 1484 firsterr = torture_create_kthread(rcu_torture_writer, NULL,
1986 writer_task = kthread_create(rcu_torture_writer, NULL, 1485 writer_task);
1987 "rcu_torture_writer"); 1486 if (firsterr)
1988 if (IS_ERR(writer_task)) {
1989 firsterr = PTR_ERR(writer_task);
1990 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
1991 writer_task = NULL;
1992 goto unwind; 1487 goto unwind;
1993 }
1994 wake_up_process(writer_task);
1995 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), 1488 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
1996 GFP_KERNEL); 1489 GFP_KERNEL);
1997 if (fakewriter_tasks == NULL) { 1490 if (fakewriter_tasks == NULL) {
1998 VERBOSE_PRINTK_ERRSTRING("out of memory"); 1491 VERBOSE_TOROUT_ERRSTRING("out of memory");
1999 firsterr = -ENOMEM; 1492 firsterr = -ENOMEM;
2000 goto unwind; 1493 goto unwind;
2001 } 1494 }
2002 for (i = 0; i < nfakewriters; i++) { 1495 for (i = 0; i < nfakewriters; i++) {
2003 VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task"); 1496 firsterr = torture_create_kthread(rcu_torture_fakewriter,
2004 fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL, 1497 NULL, fakewriter_tasks[i]);
2005 "rcu_torture_fakewriter"); 1498 if (firsterr)
2006 if (IS_ERR(fakewriter_tasks[i])) {
2007 firsterr = PTR_ERR(fakewriter_tasks[i]);
2008 VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
2009 fakewriter_tasks[i] = NULL;
2010 goto unwind; 1499 goto unwind;
2011 }
2012 } 1500 }
2013 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), 1501 reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
2014 GFP_KERNEL); 1502 GFP_KERNEL);
2015 if (reader_tasks == NULL) { 1503 if (reader_tasks == NULL) {
2016 VERBOSE_PRINTK_ERRSTRING("out of memory"); 1504 VERBOSE_TOROUT_ERRSTRING("out of memory");
2017 firsterr = -ENOMEM; 1505 firsterr = -ENOMEM;
2018 goto unwind; 1506 goto unwind;
2019 } 1507 }
2020 for (i = 0; i < nrealreaders; i++) { 1508 for (i = 0; i < nrealreaders; i++) {
2021 VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task"); 1509 firsterr = torture_create_kthread(rcu_torture_reader, NULL,
2022 reader_tasks[i] = kthread_run(rcu_torture_reader, NULL, 1510 reader_tasks[i]);
2023 "rcu_torture_reader"); 1511 if (firsterr)
2024 if (IS_ERR(reader_tasks[i])) {
2025 firsterr = PTR_ERR(reader_tasks[i]);
2026 VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
2027 reader_tasks[i] = NULL;
2028 goto unwind; 1512 goto unwind;
2029 }
2030 } 1513 }
2031 if (stat_interval > 0) { 1514 if (stat_interval > 0) {
2032 VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task"); 1515 firsterr = torture_create_kthread(rcu_torture_stats, NULL,
2033 stats_task = kthread_run(rcu_torture_stats, NULL, 1516 stats_task);
2034 "rcu_torture_stats"); 1517 if (firsterr)
2035 if (IS_ERR(stats_task)) {
2036 firsterr = PTR_ERR(stats_task);
2037 VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
2038 stats_task = NULL;
2039 goto unwind; 1518 goto unwind;
2040 }
2041 } 1519 }
2042 if (test_no_idle_hz) { 1520 if (test_no_idle_hz) {
2043 rcu_idle_cpu = num_online_cpus() - 1; 1521 firsterr = torture_shuffle_init(shuffle_interval * HZ);
2044 1522 if (firsterr)
2045 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
2046 firsterr = -ENOMEM;
2047 VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
2048 goto unwind;
2049 }
2050
2051 /* Create the shuffler thread */
2052 shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
2053 "rcu_torture_shuffle");
2054 if (IS_ERR(shuffler_task)) {
2055 free_cpumask_var(shuffle_tmp_mask);
2056 firsterr = PTR_ERR(shuffler_task);
2057 VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
2058 shuffler_task = NULL;
2059 goto unwind; 1523 goto unwind;
2060 }
2061 } 1524 }
2062 if (stutter < 0) 1525 if (stutter < 0)
2063 stutter = 0; 1526 stutter = 0;
2064 if (stutter) { 1527 if (stutter) {
2065 /* Create the stutter thread */ 1528 firsterr = torture_stutter_init(stutter * HZ);
2066 stutter_task = kthread_run(rcu_torture_stutter, NULL, 1529 if (firsterr)
2067 "rcu_torture_stutter");
2068 if (IS_ERR(stutter_task)) {
2069 firsterr = PTR_ERR(stutter_task);
2070 VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
2071 stutter_task = NULL;
2072 goto unwind; 1530 goto unwind;
2073 }
2074 } 1531 }
2075 if (fqs_duration < 0) 1532 if (fqs_duration < 0)
2076 fqs_duration = 0; 1533 fqs_duration = 0;
2077 if (fqs_duration) { 1534 if (fqs_duration) {
2078 /* Create the stutter thread */ 1535 /* Create the fqs thread */
2079 fqs_task = kthread_run(rcu_torture_fqs, NULL, 1536 torture_create_kthread(rcu_torture_fqs, NULL, fqs_task);
2080 "rcu_torture_fqs"); 1537 if (firsterr)
2081 if (IS_ERR(fqs_task)) {
2082 firsterr = PTR_ERR(fqs_task);
2083 VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
2084 fqs_task = NULL;
2085 goto unwind; 1538 goto unwind;
2086 }
2087 } 1539 }
2088 if (test_boost_interval < 1) 1540 if (test_boost_interval < 1)
2089 test_boost_interval = 1; 1541 test_boost_interval = 1;
@@ -2097,49 +1549,31 @@ rcu_torture_init(void)
2097 for_each_possible_cpu(i) { 1549 for_each_possible_cpu(i) {
2098 if (cpu_is_offline(i)) 1550 if (cpu_is_offline(i))
2099 continue; /* Heuristic: CPU can go offline. */ 1551 continue; /* Heuristic: CPU can go offline. */
2100 retval = rcutorture_booster_init(i); 1552 firsterr = rcutorture_booster_init(i);
2101 if (retval < 0) { 1553 if (firsterr)
2102 firsterr = retval;
2103 goto unwind; 1554 goto unwind;
2104 }
2105 } 1555 }
2106 } 1556 }
2107 if (shutdown_secs > 0) { 1557 firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup);
2108 shutdown_time = jiffies + shutdown_secs * HZ; 1558 if (firsterr)
2109 shutdown_task = kthread_create(rcu_torture_shutdown, NULL,
2110 "rcu_torture_shutdown");
2111 if (IS_ERR(shutdown_task)) {
2112 firsterr = PTR_ERR(shutdown_task);
2113 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2114 shutdown_task = NULL;
2115 goto unwind;
2116 }
2117 wake_up_process(shutdown_task);
2118 }
2119 i = rcu_torture_onoff_init();
2120 if (i != 0) {
2121 firsterr = i;
2122 goto unwind; 1559 goto unwind;
2123 } 1560 firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ);
2124 register_reboot_notifier(&rcutorture_shutdown_nb); 1561 if (firsterr)
2125 i = rcu_torture_stall_init();
2126 if (i != 0) {
2127 firsterr = i;
2128 goto unwind; 1562 goto unwind;
2129 } 1563 firsterr = rcu_torture_stall_init();
2130 retval = rcu_torture_barrier_init(); 1564 if (firsterr)
2131 if (retval != 0) { 1565 goto unwind;
2132 firsterr = retval; 1566 firsterr = rcu_torture_barrier_init();
1567 if (firsterr)
2133 goto unwind; 1568 goto unwind;
2134 }
2135 if (object_debug) 1569 if (object_debug)
2136 rcu_test_debug_objects(); 1570 rcu_test_debug_objects();
2137 rcutorture_record_test_transition(); 1571 rcutorture_record_test_transition();
2138 mutex_unlock(&fullstop_mutex); 1572 torture_init_end();
2139 return 0; 1573 return 0;
2140 1574
2141unwind: 1575unwind:
2142 mutex_unlock(&fullstop_mutex); 1576 torture_init_end();
2143 rcu_torture_cleanup(); 1577 rcu_torture_cleanup();
2144 return firsterr; 1578 return firsterr;
2145} 1579}
diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
index 3318d8284384..c639556f3fa0 100644
--- a/kernel/rcu/srcu.c
+++ b/kernel/rcu/srcu.c
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright (C) IBM Corporation, 2006 18 * Copyright (C) IBM Corporation, 2006
19 * Copyright (C) Fujitsu, 2012 19 * Copyright (C) Fujitsu, 2012
@@ -36,8 +36,6 @@
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/srcu.h> 37#include <linux/srcu.h>
38 38
39#include <trace/events/rcu.h>
40
41#include "rcu.h" 39#include "rcu.h"
42 40
43/* 41/*
@@ -398,7 +396,7 @@ void call_srcu(struct srcu_struct *sp, struct rcu_head *head,
398 rcu_batch_queue(&sp->batch_queue, head); 396 rcu_batch_queue(&sp->batch_queue, head);
399 if (!sp->running) { 397 if (!sp->running) {
400 sp->running = true; 398 sp->running = true;
401 schedule_delayed_work(&sp->work, 0); 399 queue_delayed_work(system_power_efficient_wq, &sp->work, 0);
402 } 400 }
403 spin_unlock_irqrestore(&sp->queue_lock, flags); 401 spin_unlock_irqrestore(&sp->queue_lock, flags);
404} 402}
@@ -674,7 +672,8 @@ static void srcu_reschedule(struct srcu_struct *sp)
674 } 672 }
675 673
676 if (pending) 674 if (pending)
677 schedule_delayed_work(&sp->work, SRCU_INTERVAL); 675 queue_delayed_work(system_power_efficient_wq,
676 &sp->work, SRCU_INTERVAL);
678} 677}
679 678
680/* 679/*
diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
index 1254f312d024..d9efcc13008c 100644
--- a/kernel/rcu/tiny.c
+++ b/kernel/rcu/tiny.c
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright IBM Corporation, 2008 18 * Copyright IBM Corporation, 2008
19 * 19 *
@@ -37,10 +37,6 @@
37#include <linux/prefetch.h> 37#include <linux/prefetch.h>
38#include <linux/ftrace_event.h> 38#include <linux/ftrace_event.h>
39 39
40#ifdef CONFIG_RCU_TRACE
41#include <trace/events/rcu.h>
42#endif /* #else #ifdef CONFIG_RCU_TRACE */
43
44#include "rcu.h" 40#include "rcu.h"
45 41
46/* Forward declarations for tiny_plugin.h. */ 42/* Forward declarations for tiny_plugin.h. */
diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
index 280d06cae352..431528520562 100644
--- a/kernel/rcu/tiny_plugin.h
+++ b/kernel/rcu/tiny_plugin.h
@@ -14,8 +14,8 @@
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, you can access it online at
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * http://www.gnu.org/licenses/gpl-2.0.html.
19 * 19 *
20 * Copyright (c) 2010 Linaro 20 * Copyright (c) 2010 Linaro
21 * 21 *
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index b3d116cd072d..0c47e300210a 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright IBM Corporation, 2008 18 * Copyright IBM Corporation, 2008
19 * 19 *
@@ -58,8 +58,6 @@
58#include <linux/suspend.h> 58#include <linux/suspend.h>
59 59
60#include "tree.h" 60#include "tree.h"
61#include <trace/events/rcu.h>
62
63#include "rcu.h" 61#include "rcu.h"
64 62
65MODULE_ALIAS("rcutree"); 63MODULE_ALIAS("rcutree");
@@ -837,7 +835,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
837 * to the next. Only do this for the primary flavor of RCU. 835 * to the next. Only do this for the primary flavor of RCU.
838 */ 836 */
839 if (rdp->rsp == rcu_state && 837 if (rdp->rsp == rcu_state &&
840 ULONG_CMP_GE(ACCESS_ONCE(jiffies), rdp->rsp->jiffies_resched)) { 838 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
841 rdp->rsp->jiffies_resched += 5; 839 rdp->rsp->jiffies_resched += 5;
842 resched_cpu(rdp->cpu); 840 resched_cpu(rdp->cpu);
843 } 841 }
@@ -847,7 +845,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
847 845
848static void record_gp_stall_check_time(struct rcu_state *rsp) 846static void record_gp_stall_check_time(struct rcu_state *rsp)
849{ 847{
850 unsigned long j = ACCESS_ONCE(jiffies); 848 unsigned long j = jiffies;
851 unsigned long j1; 849 unsigned long j1;
852 850
853 rsp->gp_start = j; 851 rsp->gp_start = j;
@@ -1005,7 +1003,7 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
1005 1003
1006 if (rcu_cpu_stall_suppress || !rcu_gp_in_progress(rsp)) 1004 if (rcu_cpu_stall_suppress || !rcu_gp_in_progress(rsp))
1007 return; 1005 return;
1008 j = ACCESS_ONCE(jiffies); 1006 j = jiffies;
1009 1007
1010 /* 1008 /*
1011 * Lots of memory barriers to reject false positives. 1009 * Lots of memory barriers to reject false positives.
@@ -1423,13 +1421,14 @@ static int rcu_gp_init(struct rcu_state *rsp)
1423 1421
1424 /* Advance to a new grace period and initialize state. */ 1422 /* Advance to a new grace period and initialize state. */
1425 record_gp_stall_check_time(rsp); 1423 record_gp_stall_check_time(rsp);
1426 smp_wmb(); /* Record GP times before starting GP. */ 1424 /* Record GP times before starting GP, hence smp_store_release(). */
1427 rsp->gpnum++; 1425 smp_store_release(&rsp->gpnum, rsp->gpnum + 1);
1428 trace_rcu_grace_period(rsp->name, rsp->gpnum, TPS("start")); 1426 trace_rcu_grace_period(rsp->name, rsp->gpnum, TPS("start"));
1429 raw_spin_unlock_irq(&rnp->lock); 1427 raw_spin_unlock_irq(&rnp->lock);
1430 1428
1431 /* Exclude any concurrent CPU-hotplug operations. */ 1429 /* Exclude any concurrent CPU-hotplug operations. */
1432 mutex_lock(&rsp->onoff_mutex); 1430 mutex_lock(&rsp->onoff_mutex);
1431 smp_mb__after_unlock_lock(); /* ->gpnum increment before GP! */
1433 1432
1434 /* 1433 /*
1435 * Set the quiescent-state-needed bits in all the rcu_node 1434 * Set the quiescent-state-needed bits in all the rcu_node
@@ -1557,10 +1556,11 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
1557 } 1556 }
1558 rnp = rcu_get_root(rsp); 1557 rnp = rcu_get_root(rsp);
1559 raw_spin_lock_irq(&rnp->lock); 1558 raw_spin_lock_irq(&rnp->lock);
1560 smp_mb__after_unlock_lock(); 1559 smp_mb__after_unlock_lock(); /* Order GP before ->completed update. */
1561 rcu_nocb_gp_set(rnp, nocb); 1560 rcu_nocb_gp_set(rnp, nocb);
1562 1561
1563 rsp->completed = rsp->gpnum; /* Declare grace period done. */ 1562 /* Declare grace period done. */
1563 ACCESS_ONCE(rsp->completed) = rsp->gpnum;
1564 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end")); 1564 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
1565 rsp->fqs_state = RCU_GP_IDLE; 1565 rsp->fqs_state = RCU_GP_IDLE;
1566 rdp = this_cpu_ptr(rsp->rda); 1566 rdp = this_cpu_ptr(rsp->rda);
@@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
2304 if (rnp_old != NULL) 2304 if (rnp_old != NULL)
2305 raw_spin_unlock(&rnp_old->fqslock); 2305 raw_spin_unlock(&rnp_old->fqslock);
2306 if (ret) { 2306 if (ret) {
2307 rsp->n_force_qs_lh++; 2307 ACCESS_ONCE(rsp->n_force_qs_lh)++;
2308 return; 2308 return;
2309 } 2309 }
2310 rnp_old = rnp; 2310 rnp_old = rnp;
@@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
2316 smp_mb__after_unlock_lock(); 2316 smp_mb__after_unlock_lock();
2317 raw_spin_unlock(&rnp_old->fqslock); 2317 raw_spin_unlock(&rnp_old->fqslock);
2318 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) { 2318 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
2319 rsp->n_force_qs_lh++; 2319 ACCESS_ONCE(rsp->n_force_qs_lh)++;
2320 raw_spin_unlock_irqrestore(&rnp_old->lock, flags); 2320 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
2321 return; /* Someone beat us to it. */ 2321 return; /* Someone beat us to it. */
2322 } 2322 }
@@ -2639,6 +2639,58 @@ void synchronize_rcu_bh(void)
2639} 2639}
2640EXPORT_SYMBOL_GPL(synchronize_rcu_bh); 2640EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
2641 2641
2642/**
2643 * get_state_synchronize_rcu - Snapshot current RCU state
2644 *
2645 * Returns a cookie that is used by a later call to cond_synchronize_rcu()
2646 * to determine whether or not a full grace period has elapsed in the
2647 * meantime.
2648 */
2649unsigned long get_state_synchronize_rcu(void)
2650{
2651 /*
2652 * Any prior manipulation of RCU-protected data must happen
2653 * before the load from ->gpnum.
2654 */
2655 smp_mb(); /* ^^^ */
2656
2657 /*
2658 * Make sure this load happens before the purportedly
2659 * time-consuming work between get_state_synchronize_rcu()
2660 * and cond_synchronize_rcu().
2661 */
2662 return smp_load_acquire(&rcu_state->gpnum);
2663}
2664EXPORT_SYMBOL_GPL(get_state_synchronize_rcu);
2665
2666/**
2667 * cond_synchronize_rcu - Conditionally wait for an RCU grace period
2668 *
2669 * @oldstate: return value from earlier call to get_state_synchronize_rcu()
2670 *
2671 * If a full RCU grace period has elapsed since the earlier call to
2672 * get_state_synchronize_rcu(), just return. Otherwise, invoke
2673 * synchronize_rcu() to wait for a full grace period.
2674 *
2675 * Yes, this function does not take counter wrap into account. But
2676 * counter wrap is harmless. If the counter wraps, we have waited for
2677 * more than 2 billion grace periods (and way more on a 64-bit system!),
2678 * so waiting for one additional grace period should be just fine.
2679 */
2680void cond_synchronize_rcu(unsigned long oldstate)
2681{
2682 unsigned long newstate;
2683
2684 /*
2685 * Ensure that this load happens before any RCU-destructive
2686 * actions the caller might carry out after we return.
2687 */
2688 newstate = smp_load_acquire(&rcu_state->completed);
2689 if (ULONG_CMP_GE(oldstate, newstate))
2690 synchronize_rcu();
2691}
2692EXPORT_SYMBOL_GPL(cond_synchronize_rcu);
2693
2642static int synchronize_sched_expedited_cpu_stop(void *data) 2694static int synchronize_sched_expedited_cpu_stop(void *data)
2643{ 2695{
2644 /* 2696 /*
@@ -2880,7 +2932,7 @@ static int rcu_pending(int cpu)
2880 * non-NULL, store an indication of whether all callbacks are lazy. 2932 * non-NULL, store an indication of whether all callbacks are lazy.
2881 * (If there are no callbacks, all of them are deemed to be lazy.) 2933 * (If there are no callbacks, all of them are deemed to be lazy.)
2882 */ 2934 */
2883static int rcu_cpu_has_callbacks(int cpu, bool *all_lazy) 2935static int __maybe_unused rcu_cpu_has_callbacks(int cpu, bool *all_lazy)
2884{ 2936{
2885 bool al = true; 2937 bool al = true;
2886 bool hc = false; 2938 bool hc = false;
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index 8c19873f1ac9..75dc3c39a02a 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -13,8 +13,8 @@
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, you can access it online at
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * http://www.gnu.org/licenses/gpl-2.0.html.
18 * 18 *
19 * Copyright IBM Corporation, 2008 19 * Copyright IBM Corporation, 2008
20 * 20 *
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 6e2ef4b2b920..962d1d589929 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -14,8 +14,8 @@
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, you can access it online at
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * http://www.gnu.org/licenses/gpl-2.0.html.
19 * 19 *
20 * Copyright Red Hat, 2009 20 * Copyright Red Hat, 2009
21 * Copyright IBM Corporation, 2009 21 * Copyright IBM Corporation, 2009
@@ -1586,11 +1586,13 @@ static void rcu_prepare_kthreads(int cpu)
1586 * Because we not have RCU_FAST_NO_HZ, just check whether this CPU needs 1586 * Because we not have RCU_FAST_NO_HZ, just check whether this CPU needs
1587 * any flavor of RCU. 1587 * any flavor of RCU.
1588 */ 1588 */
1589#ifndef CONFIG_RCU_NOCB_CPU_ALL
1589int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies) 1590int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
1590{ 1591{
1591 *delta_jiffies = ULONG_MAX; 1592 *delta_jiffies = ULONG_MAX;
1592 return rcu_cpu_has_callbacks(cpu, NULL); 1593 return rcu_cpu_has_callbacks(cpu, NULL);
1593} 1594}
1595#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
1594 1596
1595/* 1597/*
1596 * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up 1598 * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up
@@ -1656,7 +1658,7 @@ extern int tick_nohz_active;
1656 * only if it has been awhile since the last time we did so. Afterwards, 1658 * only if it has been awhile since the last time we did so. Afterwards,
1657 * if there are any callbacks ready for immediate invocation, return true. 1659 * if there are any callbacks ready for immediate invocation, return true.
1658 */ 1660 */
1659static bool rcu_try_advance_all_cbs(void) 1661static bool __maybe_unused rcu_try_advance_all_cbs(void)
1660{ 1662{
1661 bool cbs_ready = false; 1663 bool cbs_ready = false;
1662 struct rcu_data *rdp; 1664 struct rcu_data *rdp;
@@ -1696,6 +1698,7 @@ static bool rcu_try_advance_all_cbs(void)
1696 * 1698 *
1697 * The caller must have disabled interrupts. 1699 * The caller must have disabled interrupts.
1698 */ 1700 */
1701#ifndef CONFIG_RCU_NOCB_CPU_ALL
1699int rcu_needs_cpu(int cpu, unsigned long *dj) 1702int rcu_needs_cpu(int cpu, unsigned long *dj)
1700{ 1703{
1701 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu); 1704 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
@@ -1726,6 +1729,7 @@ int rcu_needs_cpu(int cpu, unsigned long *dj)
1726 } 1729 }
1727 return 0; 1730 return 0;
1728} 1731}
1732#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
1729 1733
1730/* 1734/*
1731 * Prepare a CPU for idle from an RCU perspective. The first major task 1735 * Prepare a CPU for idle from an RCU perspective. The first major task
@@ -1739,6 +1743,7 @@ int rcu_needs_cpu(int cpu, unsigned long *dj)
1739 */ 1743 */
1740static void rcu_prepare_for_idle(int cpu) 1744static void rcu_prepare_for_idle(int cpu)
1741{ 1745{
1746#ifndef CONFIG_RCU_NOCB_CPU_ALL
1742 struct rcu_data *rdp; 1747 struct rcu_data *rdp;
1743 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu); 1748 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
1744 struct rcu_node *rnp; 1749 struct rcu_node *rnp;
@@ -1790,6 +1795,7 @@ static void rcu_prepare_for_idle(int cpu)
1790 rcu_accelerate_cbs(rsp, rnp, rdp); 1795 rcu_accelerate_cbs(rsp, rnp, rdp);
1791 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ 1796 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
1792 } 1797 }
1798#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
1793} 1799}
1794 1800
1795/* 1801/*
@@ -1799,11 +1805,12 @@ static void rcu_prepare_for_idle(int cpu)
1799 */ 1805 */
1800static void rcu_cleanup_after_idle(int cpu) 1806static void rcu_cleanup_after_idle(int cpu)
1801{ 1807{
1802 1808#ifndef CONFIG_RCU_NOCB_CPU_ALL
1803 if (rcu_is_nocb_cpu(cpu)) 1809 if (rcu_is_nocb_cpu(cpu))
1804 return; 1810 return;
1805 if (rcu_try_advance_all_cbs()) 1811 if (rcu_try_advance_all_cbs())
1806 invoke_rcu_core(); 1812 invoke_rcu_core();
1813#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
1807} 1814}
1808 1815
1809/* 1816/*
@@ -2101,6 +2108,7 @@ static void rcu_init_one_nocb(struct rcu_node *rnp)
2101 init_waitqueue_head(&rnp->nocb_gp_wq[1]); 2108 init_waitqueue_head(&rnp->nocb_gp_wq[1]);
2102} 2109}
2103 2110
2111#ifndef CONFIG_RCU_NOCB_CPU_ALL
2104/* Is the specified CPU a no-CPUs CPU? */ 2112/* Is the specified CPU a no-CPUs CPU? */
2105bool rcu_is_nocb_cpu(int cpu) 2113bool rcu_is_nocb_cpu(int cpu)
2106{ 2114{
@@ -2108,6 +2116,7 @@ bool rcu_is_nocb_cpu(int cpu)
2108 return cpumask_test_cpu(cpu, rcu_nocb_mask); 2116 return cpumask_test_cpu(cpu, rcu_nocb_mask);
2109 return false; 2117 return false;
2110} 2118}
2119#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
2111 2120
2112/* 2121/*
2113 * Enqueue the specified string of rcu_head structures onto the specified 2122 * Enqueue the specified string of rcu_head structures onto the specified
@@ -2893,7 +2902,7 @@ static void rcu_sysidle_init_percpu_data(struct rcu_dynticks *rdtp)
2893 * CPU unless the grace period has extended for too long. 2902 * CPU unless the grace period has extended for too long.
2894 * 2903 *
2895 * This code relies on the fact that all NO_HZ_FULL CPUs are also 2904 * This code relies on the fact that all NO_HZ_FULL CPUs are also
2896 * CONFIG_RCU_NOCB_CPUs. 2905 * CONFIG_RCU_NOCB_CPU CPUs.
2897 */ 2906 */
2898static bool rcu_nohz_full_cpu(struct rcu_state *rsp) 2907static bool rcu_nohz_full_cpu(struct rcu_state *rsp)
2899{ 2908{
diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
index 4def475336d4..5cdc62e1beeb 100644
--- a/kernel/rcu/tree_trace.c
+++ b/kernel/rcu/tree_trace.c
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright IBM Corporation, 2008 18 * Copyright IBM Corporation, 2008
19 * 19 *
@@ -273,7 +273,7 @@ static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
273 seq_printf(m, "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld/%ld\n", 273 seq_printf(m, "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld/%ld\n",
274 rsp->n_force_qs, rsp->n_force_qs_ngp, 274 rsp->n_force_qs, rsp->n_force_qs_ngp,
275 rsp->n_force_qs - rsp->n_force_qs_ngp, 275 rsp->n_force_qs - rsp->n_force_qs_ngp,
276 rsp->n_force_qs_lh, rsp->qlen_lazy, rsp->qlen); 276 ACCESS_ONCE(rsp->n_force_qs_lh), rsp->qlen_lazy, rsp->qlen);
277 for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < rcu_num_nodes; rnp++) { 277 for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < rcu_num_nodes; rnp++) {
278 if (rnp->level != level) { 278 if (rnp->level != level) {
279 seq_puts(m, "\n"); 279 seq_puts(m, "\n");
diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
index c54609faf233..4c0a9b0af469 100644
--- a/kernel/rcu/update.c
+++ b/kernel/rcu/update.c
@@ -12,8 +12,8 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, you can access it online at
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 * 17 *
18 * Copyright IBM Corporation, 2001 18 * Copyright IBM Corporation, 2001
19 * 19 *
@@ -49,7 +49,6 @@
49#include <linux/module.h> 49#include <linux/module.h>
50 50
51#define CREATE_TRACE_POINTS 51#define CREATE_TRACE_POINTS
52#include <trace/events/rcu.h>
53 52
54#include "rcu.h" 53#include "rcu.h"
55 54
diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile
index 9a95c8c2af2a..ab32b7b0db5c 100644
--- a/kernel/sched/Makefile
+++ b/kernel/sched/Makefile
@@ -13,7 +13,7 @@ endif
13 13
14obj-y += core.o proc.o clock.o cputime.o 14obj-y += core.o proc.o clock.o cputime.o
15obj-y += idle_task.o fair.o rt.o deadline.o stop_task.o 15obj-y += idle_task.o fair.o rt.o deadline.o stop_task.o
16obj-y += wait.o completion.o 16obj-y += wait.o completion.o idle.o
17obj-$(CONFIG_SMP) += cpupri.o cpudeadline.o 17obj-$(CONFIG_SMP) += cpupri.o cpudeadline.o
18obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o 18obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
19obj-$(CONFIG_SCHEDSTATS) += stats.o 19obj-$(CONFIG_SCHEDSTATS) += stats.o
diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
index 4a073539c58e..e73efba98301 100644
--- a/kernel/sched/auto_group.c
+++ b/kernel/sched/auto_group.c
@@ -203,7 +203,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
203 struct autogroup *ag; 203 struct autogroup *ag;
204 int err; 204 int err;
205 205
206 if (nice < -20 || nice > 19) 206 if (nice < MIN_NICE || nice > MAX_NICE)
207 return -EINVAL; 207 return -EINVAL;
208 208
209 err = security_task_setnice(current, nice); 209 err = security_task_setnice(current, nice);
diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index 43c2bcc35761..b30a2924ef14 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -301,14 +301,14 @@ u64 sched_clock_cpu(int cpu)
301 if (unlikely(!sched_clock_running)) 301 if (unlikely(!sched_clock_running))
302 return 0ull; 302 return 0ull;
303 303
304 preempt_disable(); 304 preempt_disable_notrace();
305 scd = cpu_sdc(cpu); 305 scd = cpu_sdc(cpu);
306 306
307 if (cpu != smp_processor_id()) 307 if (cpu != smp_processor_id())
308 clock = sched_clock_remote(scd); 308 clock = sched_clock_remote(scd);
309 else 309 else
310 clock = sched_clock_local(scd); 310 clock = sched_clock_local(scd);
311 preempt_enable(); 311 preempt_enable_notrace();
312 312
313 return clock; 313 return clock;
314} 314}
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b46131ef6aab..a47902c687ae 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1745,8 +1745,10 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
1745 p->numa_scan_seq = p->mm ? p->mm->numa_scan_seq : 0; 1745 p->numa_scan_seq = p->mm ? p->mm->numa_scan_seq : 0;
1746 p->numa_scan_period = sysctl_numa_balancing_scan_delay; 1746 p->numa_scan_period = sysctl_numa_balancing_scan_delay;
1747 p->numa_work.next = &p->numa_work; 1747 p->numa_work.next = &p->numa_work;
1748 p->numa_faults = NULL; 1748 p->numa_faults_memory = NULL;
1749 p->numa_faults_buffer = NULL; 1749 p->numa_faults_buffer_memory = NULL;
1750 p->last_task_numa_placement = 0;
1751 p->last_sum_exec_runtime = 0;
1750 1752
1751 INIT_LIST_HEAD(&p->numa_entry); 1753 INIT_LIST_HEAD(&p->numa_entry);
1752 p->numa_group = NULL; 1754 p->numa_group = NULL;
@@ -1952,7 +1954,7 @@ static int dl_overflow(struct task_struct *p, int policy,
1952{ 1954{
1953 1955
1954 struct dl_bw *dl_b = dl_bw_of(task_cpu(p)); 1956 struct dl_bw *dl_b = dl_bw_of(task_cpu(p));
1955 u64 period = attr->sched_period; 1957 u64 period = attr->sched_period ?: attr->sched_deadline;
1956 u64 runtime = attr->sched_runtime; 1958 u64 runtime = attr->sched_runtime;
1957 u64 new_bw = dl_policy(policy) ? to_ratio(period, runtime) : 0; 1959 u64 new_bw = dl_policy(policy) ? to_ratio(period, runtime) : 0;
1958 int cpus, err = -1; 1960 int cpus, err = -1;
@@ -2149,8 +2151,6 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
2149 if (mm) 2151 if (mm)
2150 mmdrop(mm); 2152 mmdrop(mm);
2151 if (unlikely(prev_state == TASK_DEAD)) { 2153 if (unlikely(prev_state == TASK_DEAD)) {
2152 task_numa_free(prev);
2153
2154 if (prev->sched_class->task_dead) 2154 if (prev->sched_class->task_dead)
2155 prev->sched_class->task_dead(prev); 2155 prev->sched_class->task_dead(prev);
2156 2156
@@ -2167,13 +2167,6 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
2167 2167
2168#ifdef CONFIG_SMP 2168#ifdef CONFIG_SMP
2169 2169
2170/* assumes rq->lock is held */
2171static inline void pre_schedule(struct rq *rq, struct task_struct *prev)
2172{
2173 if (prev->sched_class->pre_schedule)
2174 prev->sched_class->pre_schedule(rq, prev);
2175}
2176
2177/* rq->lock is NOT held, but preemption is disabled */ 2170/* rq->lock is NOT held, but preemption is disabled */
2178static inline void post_schedule(struct rq *rq) 2171static inline void post_schedule(struct rq *rq)
2179{ 2172{
@@ -2191,10 +2184,6 @@ static inline void post_schedule(struct rq *rq)
2191 2184
2192#else 2185#else
2193 2186
2194static inline void pre_schedule(struct rq *rq, struct task_struct *p)
2195{
2196}
2197
2198static inline void post_schedule(struct rq *rq) 2187static inline void post_schedule(struct rq *rq)
2199{ 2188{
2200} 2189}
@@ -2510,8 +2499,13 @@ void __kprobes preempt_count_add(int val)
2510 DEBUG_LOCKS_WARN_ON((preempt_count() & PREEMPT_MASK) >= 2499 DEBUG_LOCKS_WARN_ON((preempt_count() & PREEMPT_MASK) >=
2511 PREEMPT_MASK - 10); 2500 PREEMPT_MASK - 10);
2512#endif 2501#endif
2513 if (preempt_count() == val) 2502 if (preempt_count() == val) {
2514 trace_preempt_off(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1)); 2503 unsigned long ip = get_parent_ip(CALLER_ADDR1);
2504#ifdef CONFIG_DEBUG_PREEMPT
2505 current->preempt_disable_ip = ip;
2506#endif
2507 trace_preempt_off(CALLER_ADDR0, ip);
2508 }
2515} 2509}
2516EXPORT_SYMBOL(preempt_count_add); 2510EXPORT_SYMBOL(preempt_count_add);
2517 2511
@@ -2554,6 +2548,13 @@ static noinline void __schedule_bug(struct task_struct *prev)
2554 print_modules(); 2548 print_modules();
2555 if (irqs_disabled()) 2549 if (irqs_disabled())
2556 print_irqtrace_events(prev); 2550 print_irqtrace_events(prev);
2551#ifdef CONFIG_DEBUG_PREEMPT
2552 if (in_atomic_preempt_off()) {
2553 pr_err("Preemption disabled at:");
2554 print_ip_sym(current->preempt_disable_ip);
2555 pr_cont("\n");
2556 }
2557#endif
2557 dump_stack(); 2558 dump_stack();
2558 add_taint(TAINT_WARN, LOCKDEP_STILL_OK); 2559 add_taint(TAINT_WARN, LOCKDEP_STILL_OK);
2559} 2560}
@@ -2577,36 +2578,34 @@ static inline void schedule_debug(struct task_struct *prev)
2577 schedstat_inc(this_rq(), sched_count); 2578 schedstat_inc(this_rq(), sched_count);
2578} 2579}
2579 2580
2580static void put_prev_task(struct rq *rq, struct task_struct *prev)
2581{
2582 if (prev->on_rq || rq->skip_clock_update < 0)
2583 update_rq_clock(rq);
2584 prev->sched_class->put_prev_task(rq, prev);
2585}
2586
2587/* 2581/*
2588 * Pick up the highest-prio task: 2582 * Pick up the highest-prio task:
2589 */ 2583 */
2590static inline struct task_struct * 2584static inline struct task_struct *
2591pick_next_task(struct rq *rq) 2585pick_next_task(struct rq *rq, struct task_struct *prev)
2592{ 2586{
2593 const struct sched_class *class; 2587 const struct sched_class *class = &fair_sched_class;
2594 struct task_struct *p; 2588 struct task_struct *p;
2595 2589
2596 /* 2590 /*
2597 * Optimization: we know that if all tasks are in 2591 * Optimization: we know that if all tasks are in
2598 * the fair class we can call that function directly: 2592 * the fair class we can call that function directly:
2599 */ 2593 */
2600 if (likely(rq->nr_running == rq->cfs.h_nr_running)) { 2594 if (likely(prev->sched_class == class &&
2601 p = fair_sched_class.pick_next_task(rq); 2595 rq->nr_running == rq->cfs.h_nr_running)) {
2602 if (likely(p)) 2596 p = fair_sched_class.pick_next_task(rq, prev);
2597 if (likely(p && p != RETRY_TASK))
2603 return p; 2598 return p;
2604 } 2599 }
2605 2600
2601again:
2606 for_each_class(class) { 2602 for_each_class(class) {
2607 p = class->pick_next_task(rq); 2603 p = class->pick_next_task(rq, prev);
2608 if (p) 2604 if (p) {
2605 if (unlikely(p == RETRY_TASK))
2606 goto again;
2609 return p; 2607 return p;
2608 }
2610 } 2609 }
2611 2610
2612 BUG(); /* the idle class will always have a runnable task */ 2611 BUG(); /* the idle class will always have a runnable task */
@@ -2700,13 +2699,10 @@ need_resched:
2700 switch_count = &prev->nvcsw; 2699 switch_count = &prev->nvcsw;
2701 } 2700 }
2702 2701
2703 pre_schedule(rq, prev); 2702 if (prev->on_rq || rq->skip_clock_update < 0)
2704 2703 update_rq_clock(rq);
2705 if (unlikely(!rq->nr_running))
2706 idle_balance(cpu, rq);
2707 2704
2708 put_prev_task(rq, prev); 2705 next = pick_next_task(rq, prev);
2709 next = pick_next_task(rq);
2710 clear_tsk_need_resched(prev); 2706 clear_tsk_need_resched(prev);
2711 clear_preempt_need_resched(); 2707 clear_preempt_need_resched();
2712 rq->skip_clock_update = 0; 2708 rq->skip_clock_update = 0;
@@ -2908,7 +2904,8 @@ EXPORT_SYMBOL(sleep_on_timeout);
2908 * This function changes the 'effective' priority of a task. It does 2904 * This function changes the 'effective' priority of a task. It does
2909 * not touch ->normal_prio like __setscheduler(). 2905 * not touch ->normal_prio like __setscheduler().
2910 * 2906 *
2911 * Used by the rt_mutex code to implement priority inheritance logic. 2907 * Used by the rt_mutex code to implement priority inheritance
2908 * logic. Call site only calls if the priority of the task changed.
2912 */ 2909 */
2913void rt_mutex_setprio(struct task_struct *p, int prio) 2910void rt_mutex_setprio(struct task_struct *p, int prio)
2914{ 2911{
@@ -2998,7 +2995,7 @@ void set_user_nice(struct task_struct *p, long nice)
2998 unsigned long flags; 2995 unsigned long flags;
2999 struct rq *rq; 2996 struct rq *rq;
3000 2997
3001 if (TASK_NICE(p) == nice || nice < -20 || nice > 19) 2998 if (task_nice(p) == nice || nice < MIN_NICE || nice > MAX_NICE)
3002 return; 2999 return;
3003 /* 3000 /*
3004 * We have to be careful, if called from sys_setpriority(), 3001 * We have to be careful, if called from sys_setpriority(),
@@ -3076,11 +3073,11 @@ SYSCALL_DEFINE1(nice, int, increment)
3076 if (increment > 40) 3073 if (increment > 40)
3077 increment = 40; 3074 increment = 40;
3078 3075
3079 nice = TASK_NICE(current) + increment; 3076 nice = task_nice(current) + increment;
3080 if (nice < -20) 3077 if (nice < MIN_NICE)
3081 nice = -20; 3078 nice = MIN_NICE;
3082 if (nice > 19) 3079 if (nice > MAX_NICE)
3083 nice = 19; 3080 nice = MAX_NICE;
3084 3081
3085 if (increment < 0 && !can_nice(current, nice)) 3082 if (increment < 0 && !can_nice(current, nice))
3086 return -EPERM; 3083 return -EPERM;
@@ -3109,18 +3106,6 @@ int task_prio(const struct task_struct *p)
3109} 3106}
3110 3107
3111/** 3108/**
3112 * task_nice - return the nice value of a given task.
3113 * @p: the task in question.
3114 *
3115 * Return: The nice value [ -20 ... 0 ... 19 ].
3116 */
3117int task_nice(const struct task_struct *p)
3118{
3119 return TASK_NICE(p);
3120}
3121EXPORT_SYMBOL(task_nice);
3122
3123/**
3124 * idle_cpu - is a given cpu idle currently? 3109 * idle_cpu - is a given cpu idle currently?
3125 * @cpu: the processor in question. 3110 * @cpu: the processor in question.
3126 * 3111 *
@@ -3189,9 +3174,8 @@ __setparam_dl(struct task_struct *p, const struct sched_attr *attr)
3189 dl_se->dl_new = 1; 3174 dl_se->dl_new = 1;
3190} 3175}
3191 3176
3192/* Actually do priority change: must hold pi & rq lock. */ 3177static void __setscheduler_params(struct task_struct *p,
3193static void __setscheduler(struct rq *rq, struct task_struct *p, 3178 const struct sched_attr *attr)
3194 const struct sched_attr *attr)
3195{ 3179{
3196 int policy = attr->sched_policy; 3180 int policy = attr->sched_policy;
3197 3181
@@ -3211,9 +3195,21 @@ static void __setscheduler(struct rq *rq, struct task_struct *p,
3211 * getparam()/getattr() don't report silly values for !rt tasks. 3195 * getparam()/getattr() don't report silly values for !rt tasks.
3212 */ 3196 */
3213 p->rt_priority = attr->sched_priority; 3197 p->rt_priority = attr->sched_priority;
3214
3215 p->normal_prio = normal_prio(p); 3198 p->normal_prio = normal_prio(p);
3216 p->prio = rt_mutex_getprio(p); 3199 set_load_weight(p);
3200}
3201
3202/* Actually do priority change: must hold pi & rq lock. */
3203static void __setscheduler(struct rq *rq, struct task_struct *p,
3204 const struct sched_attr *attr)
3205{
3206 __setscheduler_params(p, attr);
3207
3208 /*
3209 * If we get here, there was no pi waiters boosting the
3210 * task. It is safe to use the normal prio.
3211 */
3212 p->prio = normal_prio(p);
3217 3213
3218 if (dl_prio(p->prio)) 3214 if (dl_prio(p->prio))
3219 p->sched_class = &dl_sched_class; 3215 p->sched_class = &dl_sched_class;
@@ -3221,8 +3217,6 @@ static void __setscheduler(struct rq *rq, struct task_struct *p,
3221 p->sched_class = &rt_sched_class; 3217 p->sched_class = &rt_sched_class;
3222 else 3218 else
3223 p->sched_class = &fair_sched_class; 3219 p->sched_class = &fair_sched_class;
3224
3225 set_load_weight(p);
3226} 3220}
3227 3221
3228static void 3222static void
@@ -3275,6 +3269,8 @@ static int __sched_setscheduler(struct task_struct *p,
3275 const struct sched_attr *attr, 3269 const struct sched_attr *attr,
3276 bool user) 3270 bool user)
3277{ 3271{
3272 int newprio = dl_policy(attr->sched_policy) ? MAX_DL_PRIO - 1 :
3273 MAX_RT_PRIO - 1 - attr->sched_priority;
3278 int retval, oldprio, oldpolicy = -1, on_rq, running; 3274 int retval, oldprio, oldpolicy = -1, on_rq, running;
3279 int policy = attr->sched_policy; 3275 int policy = attr->sched_policy;
3280 unsigned long flags; 3276 unsigned long flags;
@@ -3319,7 +3315,7 @@ recheck:
3319 */ 3315 */
3320 if (user && !capable(CAP_SYS_NICE)) { 3316 if (user && !capable(CAP_SYS_NICE)) {
3321 if (fair_policy(policy)) { 3317 if (fair_policy(policy)) {
3322 if (attr->sched_nice < TASK_NICE(p) && 3318 if (attr->sched_nice < task_nice(p) &&
3323 !can_nice(p, attr->sched_nice)) 3319 !can_nice(p, attr->sched_nice))
3324 return -EPERM; 3320 return -EPERM;
3325 } 3321 }
@@ -3338,12 +3334,21 @@ recheck:
3338 return -EPERM; 3334 return -EPERM;
3339 } 3335 }
3340 3336
3337 /*
3338 * Can't set/change SCHED_DEADLINE policy at all for now
3339 * (safest behavior); in the future we would like to allow
3340 * unprivileged DL tasks to increase their relative deadline
3341 * or reduce their runtime (both ways reducing utilization)
3342 */
3343 if (dl_policy(policy))
3344 return -EPERM;
3345
3341 /* 3346 /*
3342 * Treat SCHED_IDLE as nice 20. Only allow a switch to 3347 * Treat SCHED_IDLE as nice 20. Only allow a switch to
3343 * SCHED_NORMAL if the RLIMIT_NICE would normally permit it. 3348 * SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
3344 */ 3349 */
3345 if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) { 3350 if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) {
3346 if (!can_nice(p, TASK_NICE(p))) 3351 if (!can_nice(p, task_nice(p)))
3347 return -EPERM; 3352 return -EPERM;
3348 } 3353 }
3349 3354
@@ -3380,16 +3385,18 @@ recheck:
3380 } 3385 }
3381 3386
3382 /* 3387 /*
3383 * If not changing anything there's no need to proceed further: 3388 * If not changing anything there's no need to proceed further,
3389 * but store a possible modification of reset_on_fork.
3384 */ 3390 */
3385 if (unlikely(policy == p->policy)) { 3391 if (unlikely(policy == p->policy)) {
3386 if (fair_policy(policy) && attr->sched_nice != TASK_NICE(p)) 3392 if (fair_policy(policy) && attr->sched_nice != task_nice(p))
3387 goto change; 3393 goto change;
3388 if (rt_policy(policy) && attr->sched_priority != p->rt_priority) 3394 if (rt_policy(policy) && attr->sched_priority != p->rt_priority)
3389 goto change; 3395 goto change;
3390 if (dl_policy(policy)) 3396 if (dl_policy(policy))
3391 goto change; 3397 goto change;
3392 3398
3399 p->sched_reset_on_fork = reset_on_fork;
3393 task_rq_unlock(rq, p, &flags); 3400 task_rq_unlock(rq, p, &flags);
3394 return 0; 3401 return 0;
3395 } 3402 }
@@ -3443,6 +3450,24 @@ change:
3443 return -EBUSY; 3450 return -EBUSY;
3444 } 3451 }
3445 3452
3453 p->sched_reset_on_fork = reset_on_fork;
3454 oldprio = p->prio;
3455
3456 /*
3457 * Special case for priority boosted tasks.
3458 *
3459 * If the new priority is lower or equal (user space view)
3460 * than the current (boosted) priority, we just store the new
3461 * normal parameters and do not touch the scheduler class and
3462 * the runqueue. This will be done when the task deboost
3463 * itself.
3464 */
3465 if (rt_mutex_check_prio(p, newprio)) {
3466 __setscheduler_params(p, attr);
3467 task_rq_unlock(rq, p, &flags);
3468 return 0;
3469 }
3470
3446 on_rq = p->on_rq; 3471 on_rq = p->on_rq;
3447 running = task_current(rq, p); 3472 running = task_current(rq, p);
3448 if (on_rq) 3473 if (on_rq)
@@ -3450,16 +3475,18 @@ change:
3450 if (running) 3475 if (running)
3451 p->sched_class->put_prev_task(rq, p); 3476 p->sched_class->put_prev_task(rq, p);
3452 3477
3453 p->sched_reset_on_fork = reset_on_fork;
3454
3455 oldprio = p->prio;
3456 prev_class = p->sched_class; 3478 prev_class = p->sched_class;
3457 __setscheduler(rq, p, attr); 3479 __setscheduler(rq, p, attr);
3458 3480
3459 if (running) 3481 if (running)
3460 p->sched_class->set_curr_task(rq); 3482 p->sched_class->set_curr_task(rq);
3461 if (on_rq) 3483 if (on_rq) {
3462 enqueue_task(rq, p, 0); 3484 /*
3485 * We enqueue to tail when the priority of a task is
3486 * increased (user space view).
3487 */
3488 enqueue_task(rq, p, oldprio <= p->prio ? ENQUEUE_HEAD : 0);
3489 }
3463 3490
3464 check_class_changed(rq, p, prev_class, oldprio); 3491 check_class_changed(rq, p, prev_class, oldprio);
3465 task_rq_unlock(rq, p, &flags); 3492 task_rq_unlock(rq, p, &flags);
@@ -3615,7 +3642,7 @@ static int sched_copy_attr(struct sched_attr __user *uattr,
3615 * XXX: do we want to be lenient like existing syscalls; or do we want 3642 * XXX: do we want to be lenient like existing syscalls; or do we want
3616 * to be strict and return an error on out-of-bounds values? 3643 * to be strict and return an error on out-of-bounds values?
3617 */ 3644 */
3618 attr->sched_nice = clamp(attr->sched_nice, -20, 19); 3645 attr->sched_nice = clamp(attr->sched_nice, MIN_NICE, MAX_NICE);
3619 3646
3620out: 3647out:
3621 return ret; 3648 return ret;
@@ -3661,13 +3688,14 @@ SYSCALL_DEFINE2(sched_setparam, pid_t, pid, struct sched_param __user *, param)
3661 * @pid: the pid in question. 3688 * @pid: the pid in question.
3662 * @uattr: structure containing the extended parameters. 3689 * @uattr: structure containing the extended parameters.
3663 */ 3690 */
3664SYSCALL_DEFINE2(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr) 3691SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr,
3692 unsigned int, flags)
3665{ 3693{
3666 struct sched_attr attr; 3694 struct sched_attr attr;
3667 struct task_struct *p; 3695 struct task_struct *p;
3668 int retval; 3696 int retval;
3669 3697
3670 if (!uattr || pid < 0) 3698 if (!uattr || pid < 0 || flags)
3671 return -EINVAL; 3699 return -EINVAL;
3672 3700
3673 if (sched_copy_attr(uattr, &attr)) 3701 if (sched_copy_attr(uattr, &attr))
@@ -3786,7 +3814,7 @@ static int sched_read_attr(struct sched_attr __user *uattr,
3786 attr->size = usize; 3814 attr->size = usize;
3787 } 3815 }
3788 3816
3789 ret = copy_to_user(uattr, attr, usize); 3817 ret = copy_to_user(uattr, attr, attr->size);
3790 if (ret) 3818 if (ret)
3791 return -EFAULT; 3819 return -EFAULT;
3792 3820
@@ -3804,8 +3832,8 @@ err_size:
3804 * @uattr: structure containing the extended parameters. 3832 * @uattr: structure containing the extended parameters.
3805 * @size: sizeof(attr) for fwd/bwd comp. 3833 * @size: sizeof(attr) for fwd/bwd comp.
3806 */ 3834 */
3807SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, 3835SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
3808 unsigned int, size) 3836 unsigned int, size, unsigned int, flags)
3809{ 3837{
3810 struct sched_attr attr = { 3838 struct sched_attr attr = {
3811 .size = sizeof(struct sched_attr), 3839 .size = sizeof(struct sched_attr),
@@ -3814,7 +3842,7 @@ SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
3814 int retval; 3842 int retval;
3815 3843
3816 if (!uattr || pid < 0 || size > PAGE_SIZE || 3844 if (!uattr || pid < 0 || size > PAGE_SIZE ||
3817 size < SCHED_ATTR_SIZE_VER0) 3845 size < SCHED_ATTR_SIZE_VER0 || flags)
3818 return -EINVAL; 3846 return -EINVAL;
3819 3847
3820 rcu_read_lock(); 3848 rcu_read_lock();
@@ -3835,7 +3863,7 @@ SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
3835 else if (task_has_rt_policy(p)) 3863 else if (task_has_rt_policy(p))
3836 attr.sched_priority = p->rt_priority; 3864 attr.sched_priority = p->rt_priority;
3837 else 3865 else
3838 attr.sched_nice = TASK_NICE(p); 3866 attr.sched_nice = task_nice(p);
3839 3867
3840 rcu_read_unlock(); 3868 rcu_read_unlock();
3841 3869
@@ -4473,6 +4501,7 @@ void init_idle(struct task_struct *idle, int cpu)
4473 rcu_read_unlock(); 4501 rcu_read_unlock();
4474 4502
4475 rq->curr = rq->idle = idle; 4503 rq->curr = rq->idle = idle;
4504 idle->on_rq = 1;
4476#if defined(CONFIG_SMP) 4505#if defined(CONFIG_SMP)
4477 idle->on_cpu = 1; 4506 idle->on_cpu = 1;
4478#endif 4507#endif
@@ -4692,8 +4721,10 @@ void idle_task_exit(void)
4692 4721
4693 BUG_ON(cpu_online(smp_processor_id())); 4722 BUG_ON(cpu_online(smp_processor_id()));
4694 4723
4695 if (mm != &init_mm) 4724 if (mm != &init_mm) {
4696 switch_mm(mm, &init_mm, current); 4725 switch_mm(mm, &init_mm, current);
4726 finish_arch_post_lock_switch();
4727 }
4697 mmdrop(mm); 4728 mmdrop(mm);
4698} 4729}
4699 4730
@@ -4711,6 +4742,22 @@ static void calc_load_migrate(struct rq *rq)
4711 atomic_long_add(delta, &calc_load_tasks); 4742 atomic_long_add(delta, &calc_load_tasks);
4712} 4743}
4713 4744
4745static void put_prev_task_fake(struct rq *rq, struct task_struct *prev)
4746{
4747}
4748
4749static const struct sched_class fake_sched_class = {
4750 .put_prev_task = put_prev_task_fake,
4751};
4752
4753static struct task_struct fake_task = {
4754 /*
4755 * Avoid pull_{rt,dl}_task()
4756 */
4757 .prio = MAX_PRIO + 1,
4758 .sched_class = &fake_sched_class,
4759};
4760
4714/* 4761/*
4715 * Migrate all tasks from the rq, sleeping tasks will be migrated by 4762 * Migrate all tasks from the rq, sleeping tasks will be migrated by
4716 * try_to_wake_up()->select_task_rq(). 4763 * try_to_wake_up()->select_task_rq().
@@ -4751,7 +4798,7 @@ static void migrate_tasks(unsigned int dead_cpu)
4751 if (rq->nr_running == 1) 4798 if (rq->nr_running == 1)
4752 break; 4799 break;
4753 4800
4754 next = pick_next_task(rq); 4801 next = pick_next_task(rq, &fake_task);
4755 BUG_ON(!next); 4802 BUG_ON(!next);
4756 next->sched_class->put_prev_task(rq, next); 4803 next->sched_class->put_prev_task(rq, next);
4757 4804
@@ -4841,7 +4888,7 @@ set_table_entry(struct ctl_table *entry,
4841static struct ctl_table * 4888static struct ctl_table *
4842sd_alloc_ctl_domain_table(struct sched_domain *sd) 4889sd_alloc_ctl_domain_table(struct sched_domain *sd)
4843{ 4890{
4844 struct ctl_table *table = sd_alloc_ctl_entry(13); 4891 struct ctl_table *table = sd_alloc_ctl_entry(14);
4845 4892
4846 if (table == NULL) 4893 if (table == NULL)
4847 return NULL; 4894 return NULL;
@@ -4869,9 +4916,12 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
4869 sizeof(int), 0644, proc_dointvec_minmax, false); 4916 sizeof(int), 0644, proc_dointvec_minmax, false);
4870 set_table_entry(&table[10], "flags", &sd->flags, 4917 set_table_entry(&table[10], "flags", &sd->flags,
4871 sizeof(int), 0644, proc_dointvec_minmax, false); 4918 sizeof(int), 0644, proc_dointvec_minmax, false);
4872 set_table_entry(&table[11], "name", sd->name, 4919 set_table_entry(&table[11], "max_newidle_lb_cost",
4920 &sd->max_newidle_lb_cost,
4921 sizeof(long), 0644, proc_doulongvec_minmax, false);
4922 set_table_entry(&table[12], "name", sd->name,
4873 CORENAME_MAX_SIZE, 0444, proc_dostring, false); 4923 CORENAME_MAX_SIZE, 0444, proc_dostring, false);
4874 /* &table[12] is terminator */ 4924 /* &table[13] is terminator */
4875 4925
4876 return table; 4926 return table;
4877} 4927}
@@ -6848,7 +6898,6 @@ void __init sched_init(void)
6848 6898
6849 rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime; 6899 rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime;
6850#ifdef CONFIG_RT_GROUP_SCHED 6900#ifdef CONFIG_RT_GROUP_SCHED
6851 INIT_LIST_HEAD(&rq->leaf_rt_rq_list);
6852 init_tg_rt_entry(&root_task_group, &rq->rt, NULL, i, NULL); 6901 init_tg_rt_entry(&root_task_group, &rq->rt, NULL, i, NULL);
6853#endif 6902#endif
6854 6903
@@ -6937,7 +6986,8 @@ void __might_sleep(const char *file, int line, int preempt_offset)
6937 static unsigned long prev_jiffy; /* ratelimiting */ 6986 static unsigned long prev_jiffy; /* ratelimiting */
6938 6987
6939 rcu_sleep_check(); /* WARN_ON_ONCE() by default, no rate limit reqd. */ 6988 rcu_sleep_check(); /* WARN_ON_ONCE() by default, no rate limit reqd. */
6940 if ((preempt_count_equals(preempt_offset) && !irqs_disabled()) || 6989 if ((preempt_count_equals(preempt_offset) && !irqs_disabled() &&
6990 !is_idle_task(current)) ||
6941 system_state != SYSTEM_RUNNING || oops_in_progress) 6991 system_state != SYSTEM_RUNNING || oops_in_progress)
6942 return; 6992 return;
6943 if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) 6993 if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
@@ -6955,6 +7005,13 @@ void __might_sleep(const char *file, int line, int preempt_offset)
6955 debug_show_held_locks(current); 7005 debug_show_held_locks(current);
6956 if (irqs_disabled()) 7006 if (irqs_disabled())
6957 print_irqtrace_events(current); 7007 print_irqtrace_events(current);
7008#ifdef CONFIG_DEBUG_PREEMPT
7009 if (!preempt_count_equals(preempt_offset)) {
7010 pr_err("Preemption disabled at:");
7011 print_ip_sym(current->preempt_disable_ip);
7012 pr_cont("\n");
7013 }
7014#endif
6958 dump_stack(); 7015 dump_stack();
6959} 7016}
6960EXPORT_SYMBOL(__might_sleep); 7017EXPORT_SYMBOL(__might_sleep);
@@ -7008,7 +7065,7 @@ void normalize_rt_tasks(void)
7008 * Renice negative nice level userspace 7065 * Renice negative nice level userspace
7009 * tasks back to 0: 7066 * tasks back to 0:
7010 */ 7067 */
7011 if (TASK_NICE(p) < 0 && p->mm) 7068 if (task_nice(p) < 0 && p->mm)
7012 set_user_nice(p, 0); 7069 set_user_nice(p, 0);
7013 continue; 7070 continue;
7014 } 7071 }
@@ -7422,6 +7479,7 @@ static int sched_dl_global_constraints(void)
7422 u64 period = global_rt_period(); 7479 u64 period = global_rt_period();
7423 u64 new_bw = to_ratio(period, runtime); 7480 u64 new_bw = to_ratio(period, runtime);
7424 int cpu, ret = 0; 7481 int cpu, ret = 0;
7482 unsigned long flags;
7425 7483
7426 /* 7484 /*
7427 * Here we want to check the bandwidth not being set to some 7485 * Here we want to check the bandwidth not being set to some
@@ -7435,10 +7493,10 @@ static int sched_dl_global_constraints(void)
7435 for_each_possible_cpu(cpu) { 7493 for_each_possible_cpu(cpu) {
7436 struct dl_bw *dl_b = dl_bw_of(cpu); 7494 struct dl_bw *dl_b = dl_bw_of(cpu);
7437 7495
7438 raw_spin_lock(&dl_b->lock); 7496 raw_spin_lock_irqsave(&dl_b->lock, flags);
7439 if (new_bw < dl_b->total_bw) 7497 if (new_bw < dl_b->total_bw)
7440 ret = -EBUSY; 7498 ret = -EBUSY;
7441 raw_spin_unlock(&dl_b->lock); 7499 raw_spin_unlock_irqrestore(&dl_b->lock, flags);
7442 7500
7443 if (ret) 7501 if (ret)
7444 break; 7502 break;
@@ -7451,6 +7509,7 @@ static void sched_dl_do_global(void)
7451{ 7509{
7452 u64 new_bw = -1; 7510 u64 new_bw = -1;
7453 int cpu; 7511 int cpu;
7512 unsigned long flags;
7454 7513
7455 def_dl_bandwidth.dl_period = global_rt_period(); 7514 def_dl_bandwidth.dl_period = global_rt_period();
7456 def_dl_bandwidth.dl_runtime = global_rt_runtime(); 7515 def_dl_bandwidth.dl_runtime = global_rt_runtime();
@@ -7464,9 +7523,9 @@ static void sched_dl_do_global(void)
7464 for_each_possible_cpu(cpu) { 7523 for_each_possible_cpu(cpu) {
7465 struct dl_bw *dl_b = dl_bw_of(cpu); 7524 struct dl_bw *dl_b = dl_bw_of(cpu);
7466 7525
7467 raw_spin_lock(&dl_b->lock); 7526 raw_spin_lock_irqsave(&dl_b->lock, flags);
7468 dl_b->bw = new_bw; 7527 dl_b->bw = new_bw;
7469 raw_spin_unlock(&dl_b->lock); 7528 raw_spin_unlock_irqrestore(&dl_b->lock, flags);
7470 } 7529 }
7471} 7530}
7472 7531
@@ -7475,7 +7534,8 @@ static int sched_rt_global_validate(void)
7475 if (sysctl_sched_rt_period <= 0) 7534 if (sysctl_sched_rt_period <= 0)
7476 return -EINVAL; 7535 return -EINVAL;
7477 7536
7478 if (sysctl_sched_rt_runtime > sysctl_sched_rt_period) 7537 if ((sysctl_sched_rt_runtime != RUNTIME_INF) &&
7538 (sysctl_sched_rt_runtime > sysctl_sched_rt_period))
7479 return -EINVAL; 7539 return -EINVAL;
7480 7540
7481 return 0; 7541 return 0;
diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index 045fc74e3f09..5b9bb42b2d47 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -70,7 +70,7 @@ static void cpudl_heapify(struct cpudl *cp, int idx)
70 70
71static void cpudl_change_key(struct cpudl *cp, int idx, u64 new_dl) 71static void cpudl_change_key(struct cpudl *cp, int idx, u64 new_dl)
72{ 72{
73 WARN_ON(idx > num_present_cpus() || idx == IDX_INVALID); 73 WARN_ON(idx == IDX_INVALID || !cpu_present(idx));
74 74
75 if (dl_time_before(new_dl, cp->elements[idx].dl)) { 75 if (dl_time_before(new_dl, cp->elements[idx].dl)) {
76 cp->elements[idx].dl = new_dl; 76 cp->elements[idx].dl = new_dl;
@@ -117,7 +117,7 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
117 } 117 }
118 118
119out: 119out:
120 WARN_ON(best_cpu > num_present_cpus() && best_cpu != -1); 120 WARN_ON(best_cpu != -1 && !cpu_present(best_cpu));
121 121
122 return best_cpu; 122 return best_cpu;
123} 123}
@@ -137,7 +137,7 @@ void cpudl_set(struct cpudl *cp, int cpu, u64 dl, int is_valid)
137 int old_idx, new_cpu; 137 int old_idx, new_cpu;
138 unsigned long flags; 138 unsigned long flags;
139 139
140 WARN_ON(cpu > num_present_cpus()); 140 WARN_ON(!cpu_present(cpu));
141 141
142 raw_spin_lock_irqsave(&cp->lock, flags); 142 raw_spin_lock_irqsave(&cp->lock, flags);
143 old_idx = cp->cpu_to_idx[cpu]; 143 old_idx = cp->cpu_to_idx[cpu];
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 99947919e30b..58624a65f124 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -142,7 +142,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime,
142 p->utimescaled += cputime_scaled; 142 p->utimescaled += cputime_scaled;
143 account_group_user_time(p, cputime); 143 account_group_user_time(p, cputime);
144 144
145 index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER; 145 index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
146 146
147 /* Add user time to cpustat. */ 147 /* Add user time to cpustat. */
148 task_group_account_field(p, index, (__force u64) cputime); 148 task_group_account_field(p, index, (__force u64) cputime);
@@ -169,7 +169,7 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime,
169 p->gtime += cputime; 169 p->gtime += cputime;
170 170
171 /* Add guest time to cpustat. */ 171 /* Add guest time to cpustat. */
172 if (TASK_NICE(p) > 0) { 172 if (task_nice(p) > 0) {
173 cpustat[CPUTIME_NICE] += (__force u64) cputime; 173 cpustat[CPUTIME_NICE] += (__force u64) cputime;
174 cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime; 174 cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime;
175 } else { 175 } else {
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 0dd5e0971a07..27ef40925525 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -121,7 +121,7 @@ static inline void dl_clear_overload(struct rq *rq)
121 121
122static void update_dl_migration(struct dl_rq *dl_rq) 122static void update_dl_migration(struct dl_rq *dl_rq)
123{ 123{
124 if (dl_rq->dl_nr_migratory && dl_rq->dl_nr_total > 1) { 124 if (dl_rq->dl_nr_migratory && dl_rq->dl_nr_running > 1) {
125 if (!dl_rq->overloaded) { 125 if (!dl_rq->overloaded) {
126 dl_set_overload(rq_of_dl_rq(dl_rq)); 126 dl_set_overload(rq_of_dl_rq(dl_rq));
127 dl_rq->overloaded = 1; 127 dl_rq->overloaded = 1;
@@ -135,9 +135,7 @@ static void update_dl_migration(struct dl_rq *dl_rq)
135static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) 135static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
136{ 136{
137 struct task_struct *p = dl_task_of(dl_se); 137 struct task_struct *p = dl_task_of(dl_se);
138 dl_rq = &rq_of_dl_rq(dl_rq)->dl;
139 138
140 dl_rq->dl_nr_total++;
141 if (p->nr_cpus_allowed > 1) 139 if (p->nr_cpus_allowed > 1)
142 dl_rq->dl_nr_migratory++; 140 dl_rq->dl_nr_migratory++;
143 141
@@ -147,9 +145,7 @@ static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
147static void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) 145static void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
148{ 146{
149 struct task_struct *p = dl_task_of(dl_se); 147 struct task_struct *p = dl_task_of(dl_se);
150 dl_rq = &rq_of_dl_rq(dl_rq)->dl;
151 148
152 dl_rq->dl_nr_total--;
153 if (p->nr_cpus_allowed > 1) 149 if (p->nr_cpus_allowed > 1)
154 dl_rq->dl_nr_migratory--; 150 dl_rq->dl_nr_migratory--;
155 151
@@ -214,6 +210,16 @@ static inline int has_pushable_dl_tasks(struct rq *rq)
214 210
215static int push_dl_task(struct rq *rq); 211static int push_dl_task(struct rq *rq);
216 212
213static inline bool need_pull_dl_task(struct rq *rq, struct task_struct *prev)
214{
215 return dl_task(prev);
216}
217
218static inline void set_post_schedule(struct rq *rq)
219{
220 rq->post_schedule = has_pushable_dl_tasks(rq);
221}
222
217#else 223#else
218 224
219static inline 225static inline
@@ -236,6 +242,19 @@ void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
236{ 242{
237} 243}
238 244
245static inline bool need_pull_dl_task(struct rq *rq, struct task_struct *prev)
246{
247 return false;
248}
249
250static inline int pull_dl_task(struct rq *rq)
251{
252 return 0;
253}
254
255static inline void set_post_schedule(struct rq *rq)
256{
257}
239#endif /* CONFIG_SMP */ 258#endif /* CONFIG_SMP */
240 259
241static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags); 260static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags);
@@ -566,6 +585,8 @@ int dl_runtime_exceeded(struct rq *rq, struct sched_dl_entity *dl_se)
566 return 1; 585 return 1;
567} 586}
568 587
588extern bool sched_rt_bandwidth_account(struct rt_rq *rt_rq);
589
569/* 590/*
570 * Update the current task's runtime statistics (provided it is still 591 * Update the current task's runtime statistics (provided it is still
571 * a -deadline task and has not been removed from the dl_rq). 592 * a -deadline task and has not been removed from the dl_rq).
@@ -588,8 +609,8 @@ static void update_curr_dl(struct rq *rq)
588 * approach need further study. 609 * approach need further study.
589 */ 610 */
590 delta_exec = rq_clock_task(rq) - curr->se.exec_start; 611 delta_exec = rq_clock_task(rq) - curr->se.exec_start;
591 if (unlikely((s64)delta_exec < 0)) 612 if (unlikely((s64)delta_exec <= 0))
592 delta_exec = 0; 613 return;
593 614
594 schedstat_set(curr->se.statistics.exec_max, 615 schedstat_set(curr->se.statistics.exec_max,
595 max(curr->se.statistics.exec_max, delta_exec)); 616 max(curr->se.statistics.exec_max, delta_exec));
@@ -629,11 +650,13 @@ static void update_curr_dl(struct rq *rq)
629 struct rt_rq *rt_rq = &rq->rt; 650 struct rt_rq *rt_rq = &rq->rt;
630 651
631 raw_spin_lock(&rt_rq->rt_runtime_lock); 652 raw_spin_lock(&rt_rq->rt_runtime_lock);
632 rt_rq->rt_time += delta_exec;
633 /* 653 /*
634 * We'll let actual RT tasks worry about the overflow here, we 654 * We'll let actual RT tasks worry about the overflow here, we
635 * have our own CBS to keep us inline -- see above. 655 * have our own CBS to keep us inline; only account when RT
656 * bandwidth is relevant.
636 */ 657 */
658 if (sched_rt_bandwidth_account(rt_rq))
659 rt_rq->rt_time += delta_exec;
637 raw_spin_unlock(&rt_rq->rt_runtime_lock); 660 raw_spin_unlock(&rt_rq->rt_runtime_lock);
638 } 661 }
639} 662}
@@ -717,6 +740,7 @@ void inc_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
717 740
718 WARN_ON(!dl_prio(prio)); 741 WARN_ON(!dl_prio(prio));
719 dl_rq->dl_nr_running++; 742 dl_rq->dl_nr_running++;
743 inc_nr_running(rq_of_dl_rq(dl_rq));
720 744
721 inc_dl_deadline(dl_rq, deadline); 745 inc_dl_deadline(dl_rq, deadline);
722 inc_dl_migration(dl_se, dl_rq); 746 inc_dl_migration(dl_se, dl_rq);
@@ -730,6 +754,7 @@ void dec_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
730 WARN_ON(!dl_prio(prio)); 754 WARN_ON(!dl_prio(prio));
731 WARN_ON(!dl_rq->dl_nr_running); 755 WARN_ON(!dl_rq->dl_nr_running);
732 dl_rq->dl_nr_running--; 756 dl_rq->dl_nr_running--;
757 dec_nr_running(rq_of_dl_rq(dl_rq));
733 758
734 dec_dl_deadline(dl_rq, dl_se->deadline); 759 dec_dl_deadline(dl_rq, dl_se->deadline);
735 dec_dl_migration(dl_se, dl_rq); 760 dec_dl_migration(dl_se, dl_rq);
@@ -836,8 +861,6 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
836 861
837 if (!task_current(rq, p) && p->nr_cpus_allowed > 1) 862 if (!task_current(rq, p) && p->nr_cpus_allowed > 1)
838 enqueue_pushable_dl_task(rq, p); 863 enqueue_pushable_dl_task(rq, p);
839
840 inc_nr_running(rq);
841} 864}
842 865
843static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) 866static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
@@ -850,8 +873,6 @@ static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
850{ 873{
851 update_curr_dl(rq); 874 update_curr_dl(rq);
852 __dequeue_task_dl(rq, p, flags); 875 __dequeue_task_dl(rq, p, flags);
853
854 dec_nr_running(rq);
855} 876}
856 877
857/* 878/*
@@ -944,6 +965,8 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
944 resched_task(rq->curr); 965 resched_task(rq->curr);
945} 966}
946 967
968static int pull_dl_task(struct rq *this_rq);
969
947#endif /* CONFIG_SMP */ 970#endif /* CONFIG_SMP */
948 971
949/* 972/*
@@ -990,7 +1013,7 @@ static struct sched_dl_entity *pick_next_dl_entity(struct rq *rq,
990 return rb_entry(left, struct sched_dl_entity, rb_node); 1013 return rb_entry(left, struct sched_dl_entity, rb_node);
991} 1014}
992 1015
993struct task_struct *pick_next_task_dl(struct rq *rq) 1016struct task_struct *pick_next_task_dl(struct rq *rq, struct task_struct *prev)
994{ 1017{
995 struct sched_dl_entity *dl_se; 1018 struct sched_dl_entity *dl_se;
996 struct task_struct *p; 1019 struct task_struct *p;
@@ -998,9 +1021,20 @@ struct task_struct *pick_next_task_dl(struct rq *rq)
998 1021
999 dl_rq = &rq->dl; 1022 dl_rq = &rq->dl;
1000 1023
1024 if (need_pull_dl_task(rq, prev))
1025 pull_dl_task(rq);
1026 /*
1027 * When prev is DL, we may throttle it in put_prev_task().
1028 * So, we update time before we check for dl_nr_running.
1029 */
1030 if (prev->sched_class == &dl_sched_class)
1031 update_curr_dl(rq);
1032
1001 if (unlikely(!dl_rq->dl_nr_running)) 1033 if (unlikely(!dl_rq->dl_nr_running))
1002 return NULL; 1034 return NULL;
1003 1035
1036 put_prev_task(rq, prev);
1037
1004 dl_se = pick_next_dl_entity(rq, dl_rq); 1038 dl_se = pick_next_dl_entity(rq, dl_rq);
1005 BUG_ON(!dl_se); 1039 BUG_ON(!dl_se);
1006 1040
@@ -1015,9 +1049,7 @@ struct task_struct *pick_next_task_dl(struct rq *rq)
1015 start_hrtick_dl(rq, p); 1049 start_hrtick_dl(rq, p);
1016#endif 1050#endif
1017 1051
1018#ifdef CONFIG_SMP 1052 set_post_schedule(rq);
1019 rq->post_schedule = has_pushable_dl_tasks(rq);
1020#endif /* CONFIG_SMP */
1021 1053
1022 return p; 1054 return p;
1023} 1055}
@@ -1426,13 +1458,6 @@ skip:
1426 return ret; 1458 return ret;
1427} 1459}
1428 1460
1429static void pre_schedule_dl(struct rq *rq, struct task_struct *prev)
1430{
1431 /* Try to pull other tasks here */
1432 if (dl_task(prev))
1433 pull_dl_task(rq);
1434}
1435
1436static void post_schedule_dl(struct rq *rq) 1461static void post_schedule_dl(struct rq *rq)
1437{ 1462{
1438 push_dl_tasks(rq); 1463 push_dl_tasks(rq);
@@ -1560,7 +1585,7 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
1560 if (unlikely(p->dl.dl_throttled)) 1585 if (unlikely(p->dl.dl_throttled))
1561 return; 1586 return;
1562 1587
1563 if (p->on_rq || rq->curr != p) { 1588 if (p->on_rq && rq->curr != p) {
1564#ifdef CONFIG_SMP 1589#ifdef CONFIG_SMP
1565 if (rq->dl.overloaded && push_dl_task(rq) && rq != task_rq(p)) 1590 if (rq->dl.overloaded && push_dl_task(rq) && rq != task_rq(p))
1566 /* Only reschedule if pushing failed */ 1591 /* Only reschedule if pushing failed */
@@ -1625,7 +1650,6 @@ const struct sched_class dl_sched_class = {
1625 .set_cpus_allowed = set_cpus_allowed_dl, 1650 .set_cpus_allowed = set_cpus_allowed_dl,
1626 .rq_online = rq_online_dl, 1651 .rq_online = rq_online_dl,
1627 .rq_offline = rq_offline_dl, 1652 .rq_offline = rq_offline_dl,
1628 .pre_schedule = pre_schedule_dl,
1629 .post_schedule = post_schedule_dl, 1653 .post_schedule = post_schedule_dl,
1630 .task_woken = task_woken_dl, 1654 .task_woken = task_woken_dl,
1631#endif 1655#endif
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index dd52e7ffb10e..f3344c31632a 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -321,6 +321,7 @@ do { \
321 P(sched_goidle); 321 P(sched_goidle);
322#ifdef CONFIG_SMP 322#ifdef CONFIG_SMP
323 P64(avg_idle); 323 P64(avg_idle);
324 P64(max_idle_balance_cost);
324#endif 325#endif
325 326
326 P(ttwu_count); 327 P(ttwu_count);
@@ -533,15 +534,15 @@ static void sched_show_numa(struct task_struct *p, struct seq_file *m)
533 unsigned long nr_faults = -1; 534 unsigned long nr_faults = -1;
534 int cpu_current, home_node; 535 int cpu_current, home_node;
535 536
536 if (p->numa_faults) 537 if (p->numa_faults_memory)
537 nr_faults = p->numa_faults[2*node + i]; 538 nr_faults = p->numa_faults_memory[2*node + i];
538 539
539 cpu_current = !i ? (task_node(p) == node) : 540 cpu_current = !i ? (task_node(p) == node) :
540 (pol && node_isset(node, pol->v.nodes)); 541 (pol && node_isset(node, pol->v.nodes));
541 542
542 home_node = (p->numa_preferred_nid == node); 543 home_node = (p->numa_preferred_nid == node);
543 544
544 SEQ_printf(m, "numa_faults, %d, %d, %d, %d, %ld\n", 545 SEQ_printf(m, "numa_faults_memory, %d, %d, %d, %d, %ld\n",
545 i, node, cpu_current, home_node, nr_faults); 546 i, node, cpu_current, home_node, nr_faults);
546 } 547 }
547 } 548 }
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 966cc2bfcb77..7e9bd0b1fa9e 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -322,13 +322,13 @@ static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq)
322 list_for_each_entry_rcu(cfs_rq, &rq->leaf_cfs_rq_list, leaf_cfs_rq_list) 322 list_for_each_entry_rcu(cfs_rq, &rq->leaf_cfs_rq_list, leaf_cfs_rq_list)
323 323
324/* Do the two (enqueued) entities belong to the same group ? */ 324/* Do the two (enqueued) entities belong to the same group ? */
325static inline int 325static inline struct cfs_rq *
326is_same_group(struct sched_entity *se, struct sched_entity *pse) 326is_same_group(struct sched_entity *se, struct sched_entity *pse)
327{ 327{
328 if (se->cfs_rq == pse->cfs_rq) 328 if (se->cfs_rq == pse->cfs_rq)
329 return 1; 329 return se->cfs_rq;
330 330
331 return 0; 331 return NULL;
332} 332}
333 333
334static inline struct sched_entity *parent_entity(struct sched_entity *se) 334static inline struct sched_entity *parent_entity(struct sched_entity *se)
@@ -336,17 +336,6 @@ static inline struct sched_entity *parent_entity(struct sched_entity *se)
336 return se->parent; 336 return se->parent;
337} 337}
338 338
339/* return depth at which a sched entity is present in the hierarchy */
340static inline int depth_se(struct sched_entity *se)
341{
342 int depth = 0;
343
344 for_each_sched_entity(se)
345 depth++;
346
347 return depth;
348}
349
350static void 339static void
351find_matching_se(struct sched_entity **se, struct sched_entity **pse) 340find_matching_se(struct sched_entity **se, struct sched_entity **pse)
352{ 341{
@@ -360,8 +349,8 @@ find_matching_se(struct sched_entity **se, struct sched_entity **pse)
360 */ 349 */
361 350
362 /* First walk up until both entities are at same depth */ 351 /* First walk up until both entities are at same depth */
363 se_depth = depth_se(*se); 352 se_depth = (*se)->depth;
364 pse_depth = depth_se(*pse); 353 pse_depth = (*pse)->depth;
365 354
366 while (se_depth > pse_depth) { 355 while (se_depth > pse_depth) {
367 se_depth--; 356 se_depth--;
@@ -426,12 +415,6 @@ static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq)
426#define for_each_leaf_cfs_rq(rq, cfs_rq) \ 415#define for_each_leaf_cfs_rq(rq, cfs_rq) \
427 for (cfs_rq = &rq->cfs; cfs_rq; cfs_rq = NULL) 416 for (cfs_rq = &rq->cfs; cfs_rq; cfs_rq = NULL)
428 417
429static inline int
430is_same_group(struct sched_entity *se, struct sched_entity *pse)
431{
432 return 1;
433}
434
435static inline struct sched_entity *parent_entity(struct sched_entity *se) 418static inline struct sched_entity *parent_entity(struct sched_entity *se)
436{ 419{
437 return NULL; 420 return NULL;
@@ -819,14 +802,6 @@ unsigned int sysctl_numa_balancing_scan_size = 256;
819/* Scan @scan_size MB every @scan_period after an initial @scan_delay in ms */ 802/* Scan @scan_size MB every @scan_period after an initial @scan_delay in ms */
820unsigned int sysctl_numa_balancing_scan_delay = 1000; 803unsigned int sysctl_numa_balancing_scan_delay = 1000;
821 804
822/*
823 * After skipping a page migration on a shared page, skip N more numa page
824 * migrations unconditionally. This reduces the number of NUMA migrations
825 * in shared memory workloads, and has the effect of pulling tasks towards
826 * where their memory lives, over pulling the memory towards the task.
827 */
828unsigned int sysctl_numa_balancing_migrate_deferred = 16;
829
830static unsigned int task_nr_scan_windows(struct task_struct *p) 805static unsigned int task_nr_scan_windows(struct task_struct *p)
831{ 806{
832 unsigned long rss = 0; 807 unsigned long rss = 0;
@@ -893,10 +868,26 @@ struct numa_group {
893 struct list_head task_list; 868 struct list_head task_list;
894 869
895 struct rcu_head rcu; 870 struct rcu_head rcu;
871 nodemask_t active_nodes;
896 unsigned long total_faults; 872 unsigned long total_faults;
873 /*
874 * Faults_cpu is used to decide whether memory should move
875 * towards the CPU. As a consequence, these stats are weighted
876 * more by CPU use than by memory faults.
877 */
878 unsigned long *faults_cpu;
897 unsigned long faults[0]; 879 unsigned long faults[0];
898}; 880};
899 881
882/* Shared or private faults. */
883#define NR_NUMA_HINT_FAULT_TYPES 2
884
885/* Memory and CPU locality */
886#define NR_NUMA_HINT_FAULT_STATS (NR_NUMA_HINT_FAULT_TYPES * 2)
887
888/* Averaged statistics, and temporary buffers. */
889#define NR_NUMA_HINT_FAULT_BUCKETS (NR_NUMA_HINT_FAULT_STATS * 2)
890
900pid_t task_numa_group_id(struct task_struct *p) 891pid_t task_numa_group_id(struct task_struct *p)
901{ 892{
902 return p->numa_group ? p->numa_group->gid : 0; 893 return p->numa_group ? p->numa_group->gid : 0;
@@ -904,16 +895,16 @@ pid_t task_numa_group_id(struct task_struct *p)
904 895
905static inline int task_faults_idx(int nid, int priv) 896static inline int task_faults_idx(int nid, int priv)
906{ 897{
907 return 2 * nid + priv; 898 return NR_NUMA_HINT_FAULT_TYPES * nid + priv;
908} 899}
909 900
910static inline unsigned long task_faults(struct task_struct *p, int nid) 901static inline unsigned long task_faults(struct task_struct *p, int nid)
911{ 902{
912 if (!p->numa_faults) 903 if (!p->numa_faults_memory)
913 return 0; 904 return 0;
914 905
915 return p->numa_faults[task_faults_idx(nid, 0)] + 906 return p->numa_faults_memory[task_faults_idx(nid, 0)] +
916 p->numa_faults[task_faults_idx(nid, 1)]; 907 p->numa_faults_memory[task_faults_idx(nid, 1)];
917} 908}
918 909
919static inline unsigned long group_faults(struct task_struct *p, int nid) 910static inline unsigned long group_faults(struct task_struct *p, int nid)
@@ -925,6 +916,12 @@ static inline unsigned long group_faults(struct task_struct *p, int nid)
925 p->numa_group->faults[task_faults_idx(nid, 1)]; 916 p->numa_group->faults[task_faults_idx(nid, 1)];
926} 917}
927 918
919static inline unsigned long group_faults_cpu(struct numa_group *group, int nid)
920{
921 return group->faults_cpu[task_faults_idx(nid, 0)] +
922 group->faults_cpu[task_faults_idx(nid, 1)];
923}
924
928/* 925/*
929 * These return the fraction of accesses done by a particular task, or 926 * These return the fraction of accesses done by a particular task, or
930 * task group, on a particular numa node. The group weight is given a 927 * task group, on a particular numa node. The group weight is given a
@@ -935,7 +932,7 @@ static inline unsigned long task_weight(struct task_struct *p, int nid)
935{ 932{
936 unsigned long total_faults; 933 unsigned long total_faults;
937 934
938 if (!p->numa_faults) 935 if (!p->numa_faults_memory)
939 return 0; 936 return 0;
940 937
941 total_faults = p->total_numa_faults; 938 total_faults = p->total_numa_faults;
@@ -954,6 +951,69 @@ static inline unsigned long group_weight(struct task_struct *p, int nid)
954 return 1000 * group_faults(p, nid) / p->numa_group->total_faults; 951 return 1000 * group_faults(p, nid) / p->numa_group->total_faults;
955} 952}
956 953
954bool should_numa_migrate_memory(struct task_struct *p, struct page * page,
955 int src_nid, int dst_cpu)
956{
957 struct numa_group *ng = p->numa_group;
958 int dst_nid = cpu_to_node(dst_cpu);
959 int last_cpupid, this_cpupid;
960
961 this_cpupid = cpu_pid_to_cpupid(dst_cpu, current->pid);
962
963 /*
964 * Multi-stage node selection is used in conjunction with a periodic
965 * migration fault to build a temporal task<->page relation. By using
966 * a two-stage filter we remove short/unlikely relations.
967 *
968 * Using P(p) ~ n_p / n_t as per frequentist probability, we can equate
969 * a task's usage of a particular page (n_p) per total usage of this
970 * page (n_t) (in a given time-span) to a probability.
971 *
972 * Our periodic faults will sample this probability and getting the
973 * same result twice in a row, given these samples are fully
974 * independent, is then given by P(n)^2, provided our sample period
975 * is sufficiently short compared to the usage pattern.
976 *
977 * This quadric squishes small probabilities, making it less likely we
978 * act on an unlikely task<->page relation.
979 */
980 last_cpupid = page_cpupid_xchg_last(page, this_cpupid);
981 if (!cpupid_pid_unset(last_cpupid) &&
982 cpupid_to_nid(last_cpupid) != dst_nid)
983 return false;
984
985 /* Always allow migrate on private faults */
986 if (cpupid_match_pid(p, last_cpupid))
987 return true;
988
989 /* A shared fault, but p->numa_group has not been set up yet. */
990 if (!ng)
991 return true;
992
993 /*
994 * Do not migrate if the destination is not a node that
995 * is actively used by this numa group.
996 */
997 if (!node_isset(dst_nid, ng->active_nodes))
998 return false;
999
1000 /*
1001 * Source is a node that is not actively used by this
1002 * numa group, while the destination is. Migrate.
1003 */
1004 if (!node_isset(src_nid, ng->active_nodes))
1005 return true;
1006
1007 /*
1008 * Both source and destination are nodes in active
1009 * use by this numa group. Maximize memory bandwidth
1010 * by migrating from more heavily used groups, to less
1011 * heavily used ones, spreading the load around.
1012 * Use a 1/4 hysteresis to avoid spurious page movement.
1013 */
1014 return group_faults(p, dst_nid) < (group_faults(p, src_nid) * 3 / 4);
1015}
1016
957static unsigned long weighted_cpuload(const int cpu); 1017static unsigned long weighted_cpuload(const int cpu);
958static unsigned long source_load(int cpu, int type); 1018static unsigned long source_load(int cpu, int type);
959static unsigned long target_load(int cpu, int type); 1019static unsigned long target_load(int cpu, int type);
@@ -1267,7 +1327,7 @@ static int task_numa_migrate(struct task_struct *p)
1267static void numa_migrate_preferred(struct task_struct *p) 1327static void numa_migrate_preferred(struct task_struct *p)
1268{ 1328{
1269 /* This task has no NUMA fault statistics yet */ 1329 /* This task has no NUMA fault statistics yet */
1270 if (unlikely(p->numa_preferred_nid == -1 || !p->numa_faults)) 1330 if (unlikely(p->numa_preferred_nid == -1 || !p->numa_faults_memory))
1271 return; 1331 return;
1272 1332
1273 /* Periodically retry migrating the task to the preferred node */ 1333 /* Periodically retry migrating the task to the preferred node */
@@ -1282,6 +1342,38 @@ static void numa_migrate_preferred(struct task_struct *p)
1282} 1342}
1283 1343
1284/* 1344/*
1345 * Find the nodes on which the workload is actively running. We do this by
1346 * tracking the nodes from which NUMA hinting faults are triggered. This can
1347 * be different from the set of nodes where the workload's memory is currently
1348 * located.
1349 *
1350 * The bitmask is used to make smarter decisions on when to do NUMA page
1351 * migrations, To prevent flip-flopping, and excessive page migrations, nodes
1352 * are added when they cause over 6/16 of the maximum number of faults, but
1353 * only removed when they drop below 3/16.
1354 */
1355static void update_numa_active_node_mask(struct numa_group *numa_group)
1356{
1357 unsigned long faults, max_faults = 0;
1358 int nid;
1359
1360 for_each_online_node(nid) {
1361 faults = group_faults_cpu(numa_group, nid);
1362 if (faults > max_faults)
1363 max_faults = faults;
1364 }
1365
1366 for_each_online_node(nid) {
1367 faults = group_faults_cpu(numa_group, nid);
1368 if (!node_isset(nid, numa_group->active_nodes)) {
1369 if (faults > max_faults * 6 / 16)
1370 node_set(nid, numa_group->active_nodes);
1371 } else if (faults < max_faults * 3 / 16)
1372 node_clear(nid, numa_group->active_nodes);
1373 }
1374}
1375
1376/*
1285 * When adapting the scan rate, the period is divided into NUMA_PERIOD_SLOTS 1377 * When adapting the scan rate, the period is divided into NUMA_PERIOD_SLOTS
1286 * increments. The more local the fault statistics are, the higher the scan 1378 * increments. The more local the fault statistics are, the higher the scan
1287 * period will be for the next scan window. If local/remote ratio is below 1379 * period will be for the next scan window. If local/remote ratio is below
@@ -1355,11 +1447,41 @@ static void update_task_scan_period(struct task_struct *p,
1355 memset(p->numa_faults_locality, 0, sizeof(p->numa_faults_locality)); 1447 memset(p->numa_faults_locality, 0, sizeof(p->numa_faults_locality));
1356} 1448}
1357 1449
1450/*
1451 * Get the fraction of time the task has been running since the last
1452 * NUMA placement cycle. The scheduler keeps similar statistics, but
1453 * decays those on a 32ms period, which is orders of magnitude off
1454 * from the dozens-of-seconds NUMA balancing period. Use the scheduler
1455 * stats only if the task is so new there are no NUMA statistics yet.
1456 */
1457static u64 numa_get_avg_runtime(struct task_struct *p, u64 *period)
1458{
1459 u64 runtime, delta, now;
1460 /* Use the start of this time slice to avoid calculations. */
1461 now = p->se.exec_start;
1462 runtime = p->se.sum_exec_runtime;
1463
1464 if (p->last_task_numa_placement) {
1465 delta = runtime - p->last_sum_exec_runtime;
1466 *period = now - p->last_task_numa_placement;
1467 } else {
1468 delta = p->se.avg.runnable_avg_sum;
1469 *period = p->se.avg.runnable_avg_period;
1470 }
1471
1472 p->last_sum_exec_runtime = runtime;
1473 p->last_task_numa_placement = now;
1474
1475 return delta;
1476}
1477
1358static void task_numa_placement(struct task_struct *p) 1478static void task_numa_placement(struct task_struct *p)
1359{ 1479{
1360 int seq, nid, max_nid = -1, max_group_nid = -1; 1480 int seq, nid, max_nid = -1, max_group_nid = -1;
1361 unsigned long max_faults = 0, max_group_faults = 0; 1481 unsigned long max_faults = 0, max_group_faults = 0;
1362 unsigned long fault_types[2] = { 0, 0 }; 1482 unsigned long fault_types[2] = { 0, 0 };
1483 unsigned long total_faults;
1484 u64 runtime, period;
1363 spinlock_t *group_lock = NULL; 1485 spinlock_t *group_lock = NULL;
1364 1486
1365 seq = ACCESS_ONCE(p->mm->numa_scan_seq); 1487 seq = ACCESS_ONCE(p->mm->numa_scan_seq);
@@ -1368,6 +1490,10 @@ static void task_numa_placement(struct task_struct *p)
1368 p->numa_scan_seq = seq; 1490 p->numa_scan_seq = seq;
1369 p->numa_scan_period_max = task_scan_max(p); 1491 p->numa_scan_period_max = task_scan_max(p);
1370 1492
1493 total_faults = p->numa_faults_locality[0] +
1494 p->numa_faults_locality[1];
1495 runtime = numa_get_avg_runtime(p, &period);
1496
1371 /* If the task is part of a group prevent parallel updates to group stats */ 1497 /* If the task is part of a group prevent parallel updates to group stats */
1372 if (p->numa_group) { 1498 if (p->numa_group) {
1373 group_lock = &p->numa_group->lock; 1499 group_lock = &p->numa_group->lock;
@@ -1379,24 +1505,37 @@ static void task_numa_placement(struct task_struct *p)
1379 unsigned long faults = 0, group_faults = 0; 1505 unsigned long faults = 0, group_faults = 0;
1380 int priv, i; 1506 int priv, i;
1381 1507
1382 for (priv = 0; priv < 2; priv++) { 1508 for (priv = 0; priv < NR_NUMA_HINT_FAULT_TYPES; priv++) {
1383 long diff; 1509 long diff, f_diff, f_weight;
1384 1510
1385 i = task_faults_idx(nid, priv); 1511 i = task_faults_idx(nid, priv);
1386 diff = -p->numa_faults[i];
1387 1512
1388 /* Decay existing window, copy faults since last scan */ 1513 /* Decay existing window, copy faults since last scan */
1389 p->numa_faults[i] >>= 1; 1514 diff = p->numa_faults_buffer_memory[i] - p->numa_faults_memory[i] / 2;
1390 p->numa_faults[i] += p->numa_faults_buffer[i]; 1515 fault_types[priv] += p->numa_faults_buffer_memory[i];
1391 fault_types[priv] += p->numa_faults_buffer[i]; 1516 p->numa_faults_buffer_memory[i] = 0;
1392 p->numa_faults_buffer[i] = 0;
1393 1517
1394 faults += p->numa_faults[i]; 1518 /*
1395 diff += p->numa_faults[i]; 1519 * Normalize the faults_from, so all tasks in a group
1520 * count according to CPU use, instead of by the raw
1521 * number of faults. Tasks with little runtime have
1522 * little over-all impact on throughput, and thus their
1523 * faults are less important.
1524 */
1525 f_weight = div64_u64(runtime << 16, period + 1);
1526 f_weight = (f_weight * p->numa_faults_buffer_cpu[i]) /
1527 (total_faults + 1);
1528 f_diff = f_weight - p->numa_faults_cpu[i] / 2;
1529 p->numa_faults_buffer_cpu[i] = 0;
1530
1531 p->numa_faults_memory[i] += diff;
1532 p->numa_faults_cpu[i] += f_diff;
1533 faults += p->numa_faults_memory[i];
1396 p->total_numa_faults += diff; 1534 p->total_numa_faults += diff;
1397 if (p->numa_group) { 1535 if (p->numa_group) {
1398 /* safe because we can only change our own group */ 1536 /* safe because we can only change our own group */
1399 p->numa_group->faults[i] += diff; 1537 p->numa_group->faults[i] += diff;
1538 p->numa_group->faults_cpu[i] += f_diff;
1400 p->numa_group->total_faults += diff; 1539 p->numa_group->total_faults += diff;
1401 group_faults += p->numa_group->faults[i]; 1540 group_faults += p->numa_group->faults[i];
1402 } 1541 }
@@ -1416,6 +1555,7 @@ static void task_numa_placement(struct task_struct *p)
1416 update_task_scan_period(p, fault_types[0], fault_types[1]); 1555 update_task_scan_period(p, fault_types[0], fault_types[1]);
1417 1556
1418 if (p->numa_group) { 1557 if (p->numa_group) {
1558 update_numa_active_node_mask(p->numa_group);
1419 /* 1559 /*
1420 * If the preferred task and group nids are different, 1560 * If the preferred task and group nids are different,
1421 * iterate over the nodes again to find the best place. 1561 * iterate over the nodes again to find the best place.
@@ -1465,7 +1605,7 @@ static void task_numa_group(struct task_struct *p, int cpupid, int flags,
1465 1605
1466 if (unlikely(!p->numa_group)) { 1606 if (unlikely(!p->numa_group)) {
1467 unsigned int size = sizeof(struct numa_group) + 1607 unsigned int size = sizeof(struct numa_group) +
1468 2*nr_node_ids*sizeof(unsigned long); 1608 4*nr_node_ids*sizeof(unsigned long);
1469 1609
1470 grp = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); 1610 grp = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
1471 if (!grp) 1611 if (!grp)
@@ -1475,9 +1615,14 @@ static void task_numa_group(struct task_struct *p, int cpupid, int flags,
1475 spin_lock_init(&grp->lock); 1615 spin_lock_init(&grp->lock);
1476 INIT_LIST_HEAD(&grp->task_list); 1616 INIT_LIST_HEAD(&grp->task_list);
1477 grp->gid = p->pid; 1617 grp->gid = p->pid;
1618 /* Second half of the array tracks nids where faults happen */
1619 grp->faults_cpu = grp->faults + NR_NUMA_HINT_FAULT_TYPES *
1620 nr_node_ids;
1621
1622 node_set(task_node(current), grp->active_nodes);
1478 1623
1479 for (i = 0; i < 2*nr_node_ids; i++) 1624 for (i = 0; i < NR_NUMA_HINT_FAULT_STATS * nr_node_ids; i++)
1480 grp->faults[i] = p->numa_faults[i]; 1625 grp->faults[i] = p->numa_faults_memory[i];
1481 1626
1482 grp->total_faults = p->total_numa_faults; 1627 grp->total_faults = p->total_numa_faults;
1483 1628
@@ -1534,9 +1679,9 @@ static void task_numa_group(struct task_struct *p, int cpupid, int flags,
1534 1679
1535 double_lock(&my_grp->lock, &grp->lock); 1680 double_lock(&my_grp->lock, &grp->lock);
1536 1681
1537 for (i = 0; i < 2*nr_node_ids; i++) { 1682 for (i = 0; i < NR_NUMA_HINT_FAULT_STATS * nr_node_ids; i++) {
1538 my_grp->faults[i] -= p->numa_faults[i]; 1683 my_grp->faults[i] -= p->numa_faults_memory[i];
1539 grp->faults[i] += p->numa_faults[i]; 1684 grp->faults[i] += p->numa_faults_memory[i];
1540 } 1685 }
1541 my_grp->total_faults -= p->total_numa_faults; 1686 my_grp->total_faults -= p->total_numa_faults;
1542 grp->total_faults += p->total_numa_faults; 1687 grp->total_faults += p->total_numa_faults;
@@ -1562,12 +1707,12 @@ void task_numa_free(struct task_struct *p)
1562{ 1707{
1563 struct numa_group *grp = p->numa_group; 1708 struct numa_group *grp = p->numa_group;
1564 int i; 1709 int i;
1565 void *numa_faults = p->numa_faults; 1710 void *numa_faults = p->numa_faults_memory;
1566 1711
1567 if (grp) { 1712 if (grp) {
1568 spin_lock(&grp->lock); 1713 spin_lock(&grp->lock);
1569 for (i = 0; i < 2*nr_node_ids; i++) 1714 for (i = 0; i < NR_NUMA_HINT_FAULT_STATS * nr_node_ids; i++)
1570 grp->faults[i] -= p->numa_faults[i]; 1715 grp->faults[i] -= p->numa_faults_memory[i];
1571 grp->total_faults -= p->total_numa_faults; 1716 grp->total_faults -= p->total_numa_faults;
1572 1717
1573 list_del(&p->numa_entry); 1718 list_del(&p->numa_entry);
@@ -1577,18 +1722,21 @@ void task_numa_free(struct task_struct *p)
1577 put_numa_group(grp); 1722 put_numa_group(grp);
1578 } 1723 }
1579 1724
1580 p->numa_faults = NULL; 1725 p->numa_faults_memory = NULL;
1581 p->numa_faults_buffer = NULL; 1726 p->numa_faults_buffer_memory = NULL;
1727 p->numa_faults_cpu= NULL;
1728 p->numa_faults_buffer_cpu = NULL;
1582 kfree(numa_faults); 1729 kfree(numa_faults);
1583} 1730}
1584 1731
1585/* 1732/*
1586 * Got a PROT_NONE fault for a page on @node. 1733 * Got a PROT_NONE fault for a page on @node.
1587 */ 1734 */
1588void task_numa_fault(int last_cpupid, int node, int pages, int flags) 1735void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
1589{ 1736{
1590 struct task_struct *p = current; 1737 struct task_struct *p = current;
1591 bool migrated = flags & TNF_MIGRATED; 1738 bool migrated = flags & TNF_MIGRATED;
1739 int cpu_node = task_node(current);
1592 int priv; 1740 int priv;
1593 1741
1594 if (!numabalancing_enabled) 1742 if (!numabalancing_enabled)
@@ -1603,16 +1751,24 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
1603 return; 1751 return;
1604 1752
1605 /* Allocate buffer to track faults on a per-node basis */ 1753 /* Allocate buffer to track faults on a per-node basis */
1606 if (unlikely(!p->numa_faults)) { 1754 if (unlikely(!p->numa_faults_memory)) {
1607 int size = sizeof(*p->numa_faults) * 2 * nr_node_ids; 1755 int size = sizeof(*p->numa_faults_memory) *
1756 NR_NUMA_HINT_FAULT_BUCKETS * nr_node_ids;
1608 1757
1609 /* numa_faults and numa_faults_buffer share the allocation */ 1758 p->numa_faults_memory = kzalloc(size, GFP_KERNEL|__GFP_NOWARN);
1610 p->numa_faults = kzalloc(size * 2, GFP_KERNEL|__GFP_NOWARN); 1759 if (!p->numa_faults_memory)
1611 if (!p->numa_faults)
1612 return; 1760 return;
1613 1761
1614 BUG_ON(p->numa_faults_buffer); 1762 BUG_ON(p->numa_faults_buffer_memory);
1615 p->numa_faults_buffer = p->numa_faults + (2 * nr_node_ids); 1763 /*
1764 * The averaged statistics, shared & private, memory & cpu,
1765 * occupy the first half of the array. The second half of the
1766 * array is for current counters, which are averaged into the
1767 * first set by task_numa_placement.
1768 */
1769 p->numa_faults_cpu = p->numa_faults_memory + (2 * nr_node_ids);
1770 p->numa_faults_buffer_memory = p->numa_faults_memory + (4 * nr_node_ids);
1771 p->numa_faults_buffer_cpu = p->numa_faults_memory + (6 * nr_node_ids);
1616 p->total_numa_faults = 0; 1772 p->total_numa_faults = 0;
1617 memset(p->numa_faults_locality, 0, sizeof(p->numa_faults_locality)); 1773 memset(p->numa_faults_locality, 0, sizeof(p->numa_faults_locality));
1618 } 1774 }
@@ -1641,7 +1797,8 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
1641 if (migrated) 1797 if (migrated)
1642 p->numa_pages_migrated += pages; 1798 p->numa_pages_migrated += pages;
1643 1799
1644 p->numa_faults_buffer[task_faults_idx(node, priv)] += pages; 1800 p->numa_faults_buffer_memory[task_faults_idx(mem_node, priv)] += pages;
1801 p->numa_faults_buffer_cpu[task_faults_idx(cpu_node, priv)] += pages;
1645 p->numa_faults_locality[!!(flags & TNF_FAULT_LOCAL)] += pages; 1802 p->numa_faults_locality[!!(flags & TNF_FAULT_LOCAL)] += pages;
1646} 1803}
1647 1804
@@ -1757,6 +1914,8 @@ void task_numa_work(struct callback_head *work)
1757 start = end; 1914 start = end;
1758 if (pages <= 0) 1915 if (pages <= 0)
1759 goto out; 1916 goto out;
1917
1918 cond_resched();
1760 } while (end != vma->vm_end); 1919 } while (end != vma->vm_end);
1761 } 1920 }
1762 1921
@@ -2217,13 +2376,20 @@ static inline void __update_group_entity_contrib(struct sched_entity *se)
2217 se->avg.load_avg_contrib >>= NICE_0_SHIFT; 2376 se->avg.load_avg_contrib >>= NICE_0_SHIFT;
2218 } 2377 }
2219} 2378}
2220#else 2379
2380static inline void update_rq_runnable_avg(struct rq *rq, int runnable)
2381{
2382 __update_entity_runnable_avg(rq_clock_task(rq), &rq->avg, runnable);
2383 __update_tg_runnable_avg(&rq->avg, &rq->cfs);
2384}
2385#else /* CONFIG_FAIR_GROUP_SCHED */
2221static inline void __update_cfs_rq_tg_load_contrib(struct cfs_rq *cfs_rq, 2386static inline void __update_cfs_rq_tg_load_contrib(struct cfs_rq *cfs_rq,
2222 int force_update) {} 2387 int force_update) {}
2223static inline void __update_tg_runnable_avg(struct sched_avg *sa, 2388static inline void __update_tg_runnable_avg(struct sched_avg *sa,
2224 struct cfs_rq *cfs_rq) {} 2389 struct cfs_rq *cfs_rq) {}
2225static inline void __update_group_entity_contrib(struct sched_entity *se) {} 2390static inline void __update_group_entity_contrib(struct sched_entity *se) {}
2226#endif 2391static inline void update_rq_runnable_avg(struct rq *rq, int runnable) {}
2392#endif /* CONFIG_FAIR_GROUP_SCHED */
2227 2393
2228static inline void __update_task_entity_contrib(struct sched_entity *se) 2394static inline void __update_task_entity_contrib(struct sched_entity *se)
2229{ 2395{
@@ -2321,12 +2487,6 @@ static void update_cfs_rq_blocked_load(struct cfs_rq *cfs_rq, int force_update)
2321 __update_cfs_rq_tg_load_contrib(cfs_rq, force_update); 2487 __update_cfs_rq_tg_load_contrib(cfs_rq, force_update);
2322} 2488}
2323 2489
2324static inline void update_rq_runnable_avg(struct rq *rq, int runnable)
2325{
2326 __update_entity_runnable_avg(rq_clock_task(rq), &rq->avg, runnable);
2327 __update_tg_runnable_avg(&rq->avg, &rq->cfs);
2328}
2329
2330/* Add the load generated by se into cfs_rq's child load-average */ 2490/* Add the load generated by se into cfs_rq's child load-average */
2331static inline void enqueue_entity_load_avg(struct cfs_rq *cfs_rq, 2491static inline void enqueue_entity_load_avg(struct cfs_rq *cfs_rq,
2332 struct sched_entity *se, 2492 struct sched_entity *se,
@@ -2414,7 +2574,10 @@ void idle_exit_fair(struct rq *this_rq)
2414 update_rq_runnable_avg(this_rq, 0); 2574 update_rq_runnable_avg(this_rq, 0);
2415} 2575}
2416 2576
2417#else 2577static int idle_balance(struct rq *this_rq);
2578
2579#else /* CONFIG_SMP */
2580
2418static inline void update_entity_load_avg(struct sched_entity *se, 2581static inline void update_entity_load_avg(struct sched_entity *se,
2419 int update_cfs_rq) {} 2582 int update_cfs_rq) {}
2420static inline void update_rq_runnable_avg(struct rq *rq, int runnable) {} 2583static inline void update_rq_runnable_avg(struct rq *rq, int runnable) {}
@@ -2426,7 +2589,13 @@ static inline void dequeue_entity_load_avg(struct cfs_rq *cfs_rq,
2426 int sleep) {} 2589 int sleep) {}
2427static inline void update_cfs_rq_blocked_load(struct cfs_rq *cfs_rq, 2590static inline void update_cfs_rq_blocked_load(struct cfs_rq *cfs_rq,
2428 int force_update) {} 2591 int force_update) {}
2429#endif 2592
2593static inline int idle_balance(struct rq *rq)
2594{
2595 return 0;
2596}
2597
2598#endif /* CONFIG_SMP */
2430 2599
2431static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) 2600static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
2432{ 2601{
@@ -2576,10 +2745,10 @@ static void __clear_buddies_last(struct sched_entity *se)
2576{ 2745{
2577 for_each_sched_entity(se) { 2746 for_each_sched_entity(se) {
2578 struct cfs_rq *cfs_rq = cfs_rq_of(se); 2747 struct cfs_rq *cfs_rq = cfs_rq_of(se);
2579 if (cfs_rq->last == se) 2748 if (cfs_rq->last != se)
2580 cfs_rq->last = NULL;
2581 else
2582 break; 2749 break;
2750
2751 cfs_rq->last = NULL;
2583 } 2752 }
2584} 2753}
2585 2754
@@ -2587,10 +2756,10 @@ static void __clear_buddies_next(struct sched_entity *se)
2587{ 2756{
2588 for_each_sched_entity(se) { 2757 for_each_sched_entity(se) {
2589 struct cfs_rq *cfs_rq = cfs_rq_of(se); 2758 struct cfs_rq *cfs_rq = cfs_rq_of(se);
2590 if (cfs_rq->next == se) 2759 if (cfs_rq->next != se)
2591 cfs_rq->next = NULL;
2592 else
2593 break; 2760 break;
2761
2762 cfs_rq->next = NULL;
2594 } 2763 }
2595} 2764}
2596 2765
@@ -2598,10 +2767,10 @@ static void __clear_buddies_skip(struct sched_entity *se)
2598{ 2767{
2599 for_each_sched_entity(se) { 2768 for_each_sched_entity(se) {
2600 struct cfs_rq *cfs_rq = cfs_rq_of(se); 2769 struct cfs_rq *cfs_rq = cfs_rq_of(se);
2601 if (cfs_rq->skip == se) 2770 if (cfs_rq->skip != se)
2602 cfs_rq->skip = NULL;
2603 else
2604 break; 2771 break;
2772
2773 cfs_rq->skip = NULL;
2605 } 2774 }
2606} 2775}
2607 2776
@@ -2744,17 +2913,36 @@ wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se);
2744 * 3) pick the "last" process, for cache locality 2913 * 3) pick the "last" process, for cache locality
2745 * 4) do not run the "skip" process, if something else is available 2914 * 4) do not run the "skip" process, if something else is available
2746 */ 2915 */
2747static struct sched_entity *pick_next_entity(struct cfs_rq *cfs_rq) 2916static struct sched_entity *
2917pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr)
2748{ 2918{
2749 struct sched_entity *se = __pick_first_entity(cfs_rq); 2919 struct sched_entity *left = __pick_first_entity(cfs_rq);
2750 struct sched_entity *left = se; 2920 struct sched_entity *se;
2921
2922 /*
2923 * If curr is set we have to see if its left of the leftmost entity
2924 * still in the tree, provided there was anything in the tree at all.
2925 */
2926 if (!left || (curr && entity_before(curr, left)))
2927 left = curr;
2928
2929 se = left; /* ideally we run the leftmost entity */
2751 2930
2752 /* 2931 /*
2753 * Avoid running the skip buddy, if running something else can 2932 * Avoid running the skip buddy, if running something else can
2754 * be done without getting too unfair. 2933 * be done without getting too unfair.
2755 */ 2934 */
2756 if (cfs_rq->skip == se) { 2935 if (cfs_rq->skip == se) {
2757 struct sched_entity *second = __pick_next_entity(se); 2936 struct sched_entity *second;
2937
2938 if (se == curr) {
2939 second = __pick_first_entity(cfs_rq);
2940 } else {
2941 second = __pick_next_entity(se);
2942 if (!second || (curr && entity_before(curr, second)))
2943 second = curr;
2944 }
2945
2758 if (second && wakeup_preempt_entity(second, left) < 1) 2946 if (second && wakeup_preempt_entity(second, left) < 1)
2759 se = second; 2947 se = second;
2760 } 2948 }
@@ -2776,7 +2964,7 @@ static struct sched_entity *pick_next_entity(struct cfs_rq *cfs_rq)
2776 return se; 2964 return se;
2777} 2965}
2778 2966
2779static void check_cfs_rq_runtime(struct cfs_rq *cfs_rq); 2967static bool check_cfs_rq_runtime(struct cfs_rq *cfs_rq);
2780 2968
2781static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev) 2969static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
2782{ 2970{
@@ -3431,22 +3619,23 @@ static void check_enqueue_throttle(struct cfs_rq *cfs_rq)
3431} 3619}
3432 3620
3433/* conditionally throttle active cfs_rq's from put_prev_entity() */ 3621/* conditionally throttle active cfs_rq's from put_prev_entity() */
3434static void check_cfs_rq_runtime(struct cfs_rq *cfs_rq) 3622static bool check_cfs_rq_runtime(struct cfs_rq *cfs_rq)
3435{ 3623{
3436 if (!cfs_bandwidth_used()) 3624 if (!cfs_bandwidth_used())
3437 return; 3625 return false;
3438 3626
3439 if (likely(!cfs_rq->runtime_enabled || cfs_rq->runtime_remaining > 0)) 3627 if (likely(!cfs_rq->runtime_enabled || cfs_rq->runtime_remaining > 0))
3440 return; 3628 return false;
3441 3629
3442 /* 3630 /*
3443 * it's possible for a throttled entity to be forced into a running 3631 * it's possible for a throttled entity to be forced into a running
3444 * state (e.g. set_curr_task), in this case we're finished. 3632 * state (e.g. set_curr_task), in this case we're finished.
3445 */ 3633 */
3446 if (cfs_rq_throttled(cfs_rq)) 3634 if (cfs_rq_throttled(cfs_rq))
3447 return; 3635 return true;
3448 3636
3449 throttle_cfs_rq(cfs_rq); 3637 throttle_cfs_rq(cfs_rq);
3638 return true;
3450} 3639}
3451 3640
3452static enum hrtimer_restart sched_cfs_slack_timer(struct hrtimer *timer) 3641static enum hrtimer_restart sched_cfs_slack_timer(struct hrtimer *timer)
@@ -3556,7 +3745,7 @@ static inline u64 cfs_rq_clock_task(struct cfs_rq *cfs_rq)
3556} 3745}
3557 3746
3558static void account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec) {} 3747static void account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec) {}
3559static void check_cfs_rq_runtime(struct cfs_rq *cfs_rq) {} 3748static bool check_cfs_rq_runtime(struct cfs_rq *cfs_rq) { return false; }
3560static void check_enqueue_throttle(struct cfs_rq *cfs_rq) {} 3749static void check_enqueue_throttle(struct cfs_rq *cfs_rq) {}
3561static __always_inline void return_cfs_rq_runtime(struct cfs_rq *cfs_rq) {} 3750static __always_inline void return_cfs_rq_runtime(struct cfs_rq *cfs_rq) {}
3562 3751
@@ -4211,13 +4400,14 @@ done:
4211} 4400}
4212 4401
4213/* 4402/*
4214 * sched_balance_self: balance the current task (running on cpu) in domains 4403 * select_task_rq_fair: Select target runqueue for the waking task in domains
4215 * that have the 'flag' flag set. In practice, this is SD_BALANCE_FORK and 4404 * that have the 'sd_flag' flag set. In practice, this is SD_BALANCE_WAKE,
4216 * SD_BALANCE_EXEC. 4405 * SD_BALANCE_FORK, or SD_BALANCE_EXEC.
4217 * 4406 *
4218 * Balance, ie. select the least loaded group. 4407 * Balances load by selecting the idlest cpu in the idlest group, or under
4408 * certain conditions an idle sibling cpu if the domain has SD_WAKE_AFFINE set.
4219 * 4409 *
4220 * Returns the target CPU number, or the same CPU if no balancing is needed. 4410 * Returns the target cpu number.
4221 * 4411 *
4222 * preempt must be disabled. 4412 * preempt must be disabled.
4223 */ 4413 */
@@ -4492,26 +4682,124 @@ preempt:
4492 set_last_buddy(se); 4682 set_last_buddy(se);
4493} 4683}
4494 4684
4495static struct task_struct *pick_next_task_fair(struct rq *rq) 4685static struct task_struct *
4686pick_next_task_fair(struct rq *rq, struct task_struct *prev)
4496{ 4687{
4497 struct task_struct *p;
4498 struct cfs_rq *cfs_rq = &rq->cfs; 4688 struct cfs_rq *cfs_rq = &rq->cfs;
4499 struct sched_entity *se; 4689 struct sched_entity *se;
4690 struct task_struct *p;
4691 int new_tasks;
4500 4692
4693again:
4694#ifdef CONFIG_FAIR_GROUP_SCHED
4501 if (!cfs_rq->nr_running) 4695 if (!cfs_rq->nr_running)
4502 return NULL; 4696 goto idle;
4697
4698 if (prev->sched_class != &fair_sched_class)
4699 goto simple;
4700
4701 /*
4702 * Because of the set_next_buddy() in dequeue_task_fair() it is rather
4703 * likely that a next task is from the same cgroup as the current.
4704 *
4705 * Therefore attempt to avoid putting and setting the entire cgroup
4706 * hierarchy, only change the part that actually changes.
4707 */
4503 4708
4504 do { 4709 do {
4505 se = pick_next_entity(cfs_rq); 4710 struct sched_entity *curr = cfs_rq->curr;
4711
4712 /*
4713 * Since we got here without doing put_prev_entity() we also
4714 * have to consider cfs_rq->curr. If it is still a runnable
4715 * entity, update_curr() will update its vruntime, otherwise
4716 * forget we've ever seen it.
4717 */
4718 if (curr && curr->on_rq)
4719 update_curr(cfs_rq);
4720 else
4721 curr = NULL;
4722
4723 /*
4724 * This call to check_cfs_rq_runtime() will do the throttle and
4725 * dequeue its entity in the parent(s). Therefore the 'simple'
4726 * nr_running test will indeed be correct.
4727 */
4728 if (unlikely(check_cfs_rq_runtime(cfs_rq)))
4729 goto simple;
4730
4731 se = pick_next_entity(cfs_rq, curr);
4732 cfs_rq = group_cfs_rq(se);
4733 } while (cfs_rq);
4734
4735 p = task_of(se);
4736
4737 /*
4738 * Since we haven't yet done put_prev_entity and if the selected task
4739 * is a different task than we started out with, try and touch the
4740 * least amount of cfs_rqs.
4741 */
4742 if (prev != p) {
4743 struct sched_entity *pse = &prev->se;
4744
4745 while (!(cfs_rq = is_same_group(se, pse))) {
4746 int se_depth = se->depth;
4747 int pse_depth = pse->depth;
4748
4749 if (se_depth <= pse_depth) {
4750 put_prev_entity(cfs_rq_of(pse), pse);
4751 pse = parent_entity(pse);
4752 }
4753 if (se_depth >= pse_depth) {
4754 set_next_entity(cfs_rq_of(se), se);
4755 se = parent_entity(se);
4756 }
4757 }
4758
4759 put_prev_entity(cfs_rq, pse);
4760 set_next_entity(cfs_rq, se);
4761 }
4762
4763 if (hrtick_enabled(rq))
4764 hrtick_start_fair(rq, p);
4765
4766 return p;
4767simple:
4768 cfs_rq = &rq->cfs;
4769#endif
4770
4771 if (!cfs_rq->nr_running)
4772 goto idle;
4773
4774 put_prev_task(rq, prev);
4775
4776 do {
4777 se = pick_next_entity(cfs_rq, NULL);
4506 set_next_entity(cfs_rq, se); 4778 set_next_entity(cfs_rq, se);
4507 cfs_rq = group_cfs_rq(se); 4779 cfs_rq = group_cfs_rq(se);
4508 } while (cfs_rq); 4780 } while (cfs_rq);
4509 4781
4510 p = task_of(se); 4782 p = task_of(se);
4783
4511 if (hrtick_enabled(rq)) 4784 if (hrtick_enabled(rq))
4512 hrtick_start_fair(rq, p); 4785 hrtick_start_fair(rq, p);
4513 4786
4514 return p; 4787 return p;
4788
4789idle:
4790 new_tasks = idle_balance(rq);
4791 /*
4792 * Because idle_balance() releases (and re-acquires) rq->lock, it is
4793 * possible for any higher priority task to appear. In that case we
4794 * must re-start the pick_next_entity() loop.
4795 */
4796 if (new_tasks < 0)
4797 return RETRY_TASK;
4798
4799 if (new_tasks > 0)
4800 goto again;
4801
4802 return NULL;
4515} 4803}
4516 4804
4517/* 4805/*
@@ -4749,7 +5037,7 @@ static void move_task(struct task_struct *p, struct lb_env *env)
4749 * Is this task likely cache-hot: 5037 * Is this task likely cache-hot:
4750 */ 5038 */
4751static int 5039static int
4752task_hot(struct task_struct *p, u64 now, struct sched_domain *sd) 5040task_hot(struct task_struct *p, u64 now)
4753{ 5041{
4754 s64 delta; 5042 s64 delta;
4755 5043
@@ -4783,7 +5071,7 @@ static bool migrate_improves_locality(struct task_struct *p, struct lb_env *env)
4783{ 5071{
4784 int src_nid, dst_nid; 5072 int src_nid, dst_nid;
4785 5073
4786 if (!sched_feat(NUMA_FAVOUR_HIGHER) || !p->numa_faults || 5074 if (!sched_feat(NUMA_FAVOUR_HIGHER) || !p->numa_faults_memory ||
4787 !(env->sd->flags & SD_NUMA)) { 5075 !(env->sd->flags & SD_NUMA)) {
4788 return false; 5076 return false;
4789 } 5077 }
@@ -4814,7 +5102,7 @@ static bool migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
4814 if (!sched_feat(NUMA) || !sched_feat(NUMA_RESIST_LOWER)) 5102 if (!sched_feat(NUMA) || !sched_feat(NUMA_RESIST_LOWER))
4815 return false; 5103 return false;
4816 5104
4817 if (!p->numa_faults || !(env->sd->flags & SD_NUMA)) 5105 if (!p->numa_faults_memory || !(env->sd->flags & SD_NUMA))
4818 return false; 5106 return false;
4819 5107
4820 src_nid = cpu_to_node(env->src_cpu); 5108 src_nid = cpu_to_node(env->src_cpu);
@@ -4910,7 +5198,7 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
4910 * 2) task is cache cold, or 5198 * 2) task is cache cold, or
4911 * 3) too many balance attempts have failed. 5199 * 3) too many balance attempts have failed.
4912 */ 5200 */
4913 tsk_cache_hot = task_hot(p, rq_clock_task(env->src_rq), env->sd); 5201 tsk_cache_hot = task_hot(p, rq_clock_task(env->src_rq));
4914 if (!tsk_cache_hot) 5202 if (!tsk_cache_hot)
4915 tsk_cache_hot = migrate_degrades_locality(p, env); 5203 tsk_cache_hot = migrate_degrades_locality(p, env);
4916 5204
@@ -5773,12 +6061,10 @@ void fix_small_imbalance(struct lb_env *env, struct sd_lb_stats *sds)
5773 pwr_now /= SCHED_POWER_SCALE; 6061 pwr_now /= SCHED_POWER_SCALE;
5774 6062
5775 /* Amount of load we'd subtract */ 6063 /* Amount of load we'd subtract */
5776 tmp = (busiest->load_per_task * SCHED_POWER_SCALE) / 6064 if (busiest->avg_load > scaled_busy_load_per_task) {
5777 busiest->group_power;
5778 if (busiest->avg_load > tmp) {
5779 pwr_move += busiest->group_power * 6065 pwr_move += busiest->group_power *
5780 min(busiest->load_per_task, 6066 min(busiest->load_per_task,
5781 busiest->avg_load - tmp); 6067 busiest->avg_load - scaled_busy_load_per_task);
5782 } 6068 }
5783 6069
5784 /* Amount of load we'd add */ 6070 /* Amount of load we'd add */
@@ -6357,17 +6643,23 @@ out:
6357 * idle_balance is called by schedule() if this_cpu is about to become 6643 * idle_balance is called by schedule() if this_cpu is about to become
6358 * idle. Attempts to pull tasks from other CPUs. 6644 * idle. Attempts to pull tasks from other CPUs.
6359 */ 6645 */
6360void idle_balance(int this_cpu, struct rq *this_rq) 6646static int idle_balance(struct rq *this_rq)
6361{ 6647{
6362 struct sched_domain *sd; 6648 struct sched_domain *sd;
6363 int pulled_task = 0; 6649 int pulled_task = 0;
6364 unsigned long next_balance = jiffies + HZ; 6650 unsigned long next_balance = jiffies + HZ;
6365 u64 curr_cost = 0; 6651 u64 curr_cost = 0;
6652 int this_cpu = this_rq->cpu;
6366 6653
6654 idle_enter_fair(this_rq);
6655 /*
6656 * We must set idle_stamp _before_ calling idle_balance(), such that we
6657 * measure the duration of idle_balance() as idle time.
6658 */
6367 this_rq->idle_stamp = rq_clock(this_rq); 6659 this_rq->idle_stamp = rq_clock(this_rq);
6368 6660
6369 if (this_rq->avg_idle < sysctl_sched_migration_cost) 6661 if (this_rq->avg_idle < sysctl_sched_migration_cost)
6370 return; 6662 goto out;
6371 6663
6372 /* 6664 /*
6373 * Drop the rq->lock, but keep IRQ/preempt disabled. 6665 * Drop the rq->lock, but keep IRQ/preempt disabled.
@@ -6405,15 +6697,22 @@ void idle_balance(int this_cpu, struct rq *this_rq)
6405 interval = msecs_to_jiffies(sd->balance_interval); 6697 interval = msecs_to_jiffies(sd->balance_interval);
6406 if (time_after(next_balance, sd->last_balance + interval)) 6698 if (time_after(next_balance, sd->last_balance + interval))
6407 next_balance = sd->last_balance + interval; 6699 next_balance = sd->last_balance + interval;
6408 if (pulled_task) { 6700 if (pulled_task)
6409 this_rq->idle_stamp = 0;
6410 break; 6701 break;
6411 }
6412 } 6702 }
6413 rcu_read_unlock(); 6703 rcu_read_unlock();
6414 6704
6415 raw_spin_lock(&this_rq->lock); 6705 raw_spin_lock(&this_rq->lock);
6416 6706
6707 /*
6708 * While browsing the domains, we released the rq lock.
6709 * A task could have be enqueued in the meantime
6710 */
6711 if (this_rq->cfs.h_nr_running && !pulled_task) {
6712 pulled_task = 1;
6713 goto out;
6714 }
6715
6417 if (pulled_task || time_after(jiffies, this_rq->next_balance)) { 6716 if (pulled_task || time_after(jiffies, this_rq->next_balance)) {
6418 /* 6717 /*
6419 * We are going idle. next_balance may be set based on 6718 * We are going idle. next_balance may be set based on
@@ -6424,6 +6723,20 @@ void idle_balance(int this_cpu, struct rq *this_rq)
6424 6723
6425 if (curr_cost > this_rq->max_idle_balance_cost) 6724 if (curr_cost > this_rq->max_idle_balance_cost)
6426 this_rq->max_idle_balance_cost = curr_cost; 6725 this_rq->max_idle_balance_cost = curr_cost;
6726
6727out:
6728 /* Is there a task of a high priority class? */
6729 if (this_rq->nr_running != this_rq->cfs.h_nr_running &&
6730 (this_rq->dl.dl_nr_running ||
6731 (this_rq->rt.rt_nr_running && !rt_rq_throttled(&this_rq->rt))))
6732 pulled_task = -1;
6733
6734 if (pulled_task) {
6735 idle_exit_fair(this_rq);
6736 this_rq->idle_stamp = 0;
6737 }
6738
6739 return pulled_task;
6427} 6740}
6428 6741
6429/* 6742/*
@@ -6494,6 +6807,11 @@ out_unlock:
6494 return 0; 6807 return 0;
6495} 6808}
6496 6809
6810static inline int on_null_domain(struct rq *rq)
6811{
6812 return unlikely(!rcu_dereference_sched(rq->sd));
6813}
6814
6497#ifdef CONFIG_NO_HZ_COMMON 6815#ifdef CONFIG_NO_HZ_COMMON
6498/* 6816/*
6499 * idle load balancing details 6817 * idle load balancing details
@@ -6548,8 +6866,13 @@ static void nohz_balancer_kick(void)
6548static inline void nohz_balance_exit_idle(int cpu) 6866static inline void nohz_balance_exit_idle(int cpu)
6549{ 6867{
6550 if (unlikely(test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)))) { 6868 if (unlikely(test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)))) {
6551 cpumask_clear_cpu(cpu, nohz.idle_cpus_mask); 6869 /*
6552 atomic_dec(&nohz.nr_cpus); 6870 * Completely isolated CPUs don't ever set, so we must test.
6871 */
6872 if (likely(cpumask_test_cpu(cpu, nohz.idle_cpus_mask))) {
6873 cpumask_clear_cpu(cpu, nohz.idle_cpus_mask);
6874 atomic_dec(&nohz.nr_cpus);
6875 }
6553 clear_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)); 6876 clear_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu));
6554 } 6877 }
6555} 6878}
@@ -6603,6 +6926,12 @@ void nohz_balance_enter_idle(int cpu)
6603 if (test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu))) 6926 if (test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)))
6604 return; 6927 return;
6605 6928
6929 /*
6930 * If we're a completely isolated CPU, we don't play.
6931 */
6932 if (on_null_domain(cpu_rq(cpu)))
6933 return;
6934
6606 cpumask_set_cpu(cpu, nohz.idle_cpus_mask); 6935 cpumask_set_cpu(cpu, nohz.idle_cpus_mask);
6607 atomic_inc(&nohz.nr_cpus); 6936 atomic_inc(&nohz.nr_cpus);
6608 set_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)); 6937 set_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu));
@@ -6865,11 +7194,6 @@ static void run_rebalance_domains(struct softirq_action *h)
6865 nohz_idle_balance(this_rq, idle); 7194 nohz_idle_balance(this_rq, idle);
6866} 7195}
6867 7196
6868static inline int on_null_domain(struct rq *rq)
6869{
6870 return !rcu_dereference_sched(rq->sd);
6871}
6872
6873/* 7197/*
6874 * Trigger the SCHED_SOFTIRQ if it is time to do periodic load balancing. 7198 * Trigger the SCHED_SOFTIRQ if it is time to do periodic load balancing.
6875 */ 7199 */
@@ -6999,15 +7323,15 @@ static void switched_from_fair(struct rq *rq, struct task_struct *p)
6999 struct cfs_rq *cfs_rq = cfs_rq_of(se); 7323 struct cfs_rq *cfs_rq = cfs_rq_of(se);
7000 7324
7001 /* 7325 /*
7002 * Ensure the task's vruntime is normalized, so that when its 7326 * Ensure the task's vruntime is normalized, so that when it's
7003 * switched back to the fair class the enqueue_entity(.flags=0) will 7327 * switched back to the fair class the enqueue_entity(.flags=0) will
7004 * do the right thing. 7328 * do the right thing.
7005 * 7329 *
7006 * If it was on_rq, then the dequeue_entity(.flags=0) will already 7330 * If it's on_rq, then the dequeue_entity(.flags=0) will already
7007 * have normalized the vruntime, if it was !on_rq, then only when 7331 * have normalized the vruntime, if it's !on_rq, then only when
7008 * the task is sleeping will it still have non-normalized vruntime. 7332 * the task is sleeping will it still have non-normalized vruntime.
7009 */ 7333 */
7010 if (!se->on_rq && p->state != TASK_RUNNING) { 7334 if (!p->on_rq && p->state != TASK_RUNNING) {
7011 /* 7335 /*
7012 * Fix up our vruntime so that the current sleep doesn't 7336 * Fix up our vruntime so that the current sleep doesn't
7013 * cause 'unlimited' sleep bonus. 7337 * cause 'unlimited' sleep bonus.
@@ -7034,7 +7358,15 @@ static void switched_from_fair(struct rq *rq, struct task_struct *p)
7034 */ 7358 */
7035static void switched_to_fair(struct rq *rq, struct task_struct *p) 7359static void switched_to_fair(struct rq *rq, struct task_struct *p)
7036{ 7360{
7037 if (!p->se.on_rq) 7361 struct sched_entity *se = &p->se;
7362#ifdef CONFIG_FAIR_GROUP_SCHED
7363 /*
7364 * Since the real-depth could have been changed (only FAIR
7365 * class maintain depth value), reset depth properly.
7366 */
7367 se->depth = se->parent ? se->parent->depth + 1 : 0;
7368#endif
7369 if (!se->on_rq)
7038 return; 7370 return;
7039 7371
7040 /* 7372 /*
@@ -7082,7 +7414,9 @@ void init_cfs_rq(struct cfs_rq *cfs_rq)
7082#ifdef CONFIG_FAIR_GROUP_SCHED 7414#ifdef CONFIG_FAIR_GROUP_SCHED
7083static void task_move_group_fair(struct task_struct *p, int on_rq) 7415static void task_move_group_fair(struct task_struct *p, int on_rq)
7084{ 7416{
7417 struct sched_entity *se = &p->se;
7085 struct cfs_rq *cfs_rq; 7418 struct cfs_rq *cfs_rq;
7419
7086 /* 7420 /*
7087 * If the task was not on the rq at the time of this cgroup movement 7421 * If the task was not on the rq at the time of this cgroup movement
7088 * it must have been asleep, sleeping tasks keep their ->vruntime 7422 * it must have been asleep, sleeping tasks keep their ->vruntime
@@ -7108,23 +7442,24 @@ static void task_move_group_fair(struct task_struct *p, int on_rq)
7108 * To prevent boost or penalty in the new cfs_rq caused by delta 7442 * To prevent boost or penalty in the new cfs_rq caused by delta
7109 * min_vruntime between the two cfs_rqs, we skip vruntime adjustment. 7443 * min_vruntime between the two cfs_rqs, we skip vruntime adjustment.
7110 */ 7444 */
7111 if (!on_rq && (!p->se.sum_exec_runtime || p->state == TASK_WAKING)) 7445 if (!on_rq && (!se->sum_exec_runtime || p->state == TASK_WAKING))
7112 on_rq = 1; 7446 on_rq = 1;
7113 7447
7114 if (!on_rq) 7448 if (!on_rq)
7115 p->se.vruntime -= cfs_rq_of(&p->se)->min_vruntime; 7449 se->vruntime -= cfs_rq_of(se)->min_vruntime;
7116 set_task_rq(p, task_cpu(p)); 7450 set_task_rq(p, task_cpu(p));
7451 se->depth = se->parent ? se->parent->depth + 1 : 0;
7117 if (!on_rq) { 7452 if (!on_rq) {
7118 cfs_rq = cfs_rq_of(&p->se); 7453 cfs_rq = cfs_rq_of(se);
7119 p->se.vruntime += cfs_rq->min_vruntime; 7454 se->vruntime += cfs_rq->min_vruntime;
7120#ifdef CONFIG_SMP 7455#ifdef CONFIG_SMP
7121 /* 7456 /*
7122 * migrate_task_rq_fair() will have removed our previous 7457 * migrate_task_rq_fair() will have removed our previous
7123 * contribution, but we must synchronize for ongoing future 7458 * contribution, but we must synchronize for ongoing future
7124 * decay. 7459 * decay.
7125 */ 7460 */
7126 p->se.avg.decay_count = atomic64_read(&cfs_rq->decay_counter); 7461 se->avg.decay_count = atomic64_read(&cfs_rq->decay_counter);
7127 cfs_rq->blocked_load_avg += p->se.avg.load_avg_contrib; 7462 cfs_rq->blocked_load_avg += se->avg.load_avg_contrib;
7128#endif 7463#endif
7129 } 7464 }
7130} 7465}
@@ -7220,10 +7555,13 @@ void init_tg_cfs_entry(struct task_group *tg, struct cfs_rq *cfs_rq,
7220 if (!se) 7555 if (!se)
7221 return; 7556 return;
7222 7557
7223 if (!parent) 7558 if (!parent) {
7224 se->cfs_rq = &rq->cfs; 7559 se->cfs_rq = &rq->cfs;
7225 else 7560 se->depth = 0;
7561 } else {
7226 se->cfs_rq = parent->my_q; 7562 se->cfs_rq = parent->my_q;
7563 se->depth = parent->depth + 1;
7564 }
7227 7565
7228 se->my_q = cfs_rq; 7566 se->my_q = cfs_rq;
7229 /* guarantee group entities always have weight */ 7567 /* guarantee group entities always have weight */
diff --git a/kernel/cpu/idle.c b/kernel/sched/idle.c
index 277f494c2a9a..b7976a127178 100644
--- a/kernel/cpu/idle.c
+++ b/kernel/sched/idle.c
@@ -3,6 +3,7 @@
3 */ 3 */
4#include <linux/sched.h> 4#include <linux/sched.h>
5#include <linux/cpu.h> 5#include <linux/cpu.h>
6#include <linux/cpuidle.h>
6#include <linux/tick.h> 7#include <linux/tick.h>
7#include <linux/mm.h> 8#include <linux/mm.h>
8#include <linux/stackprotector.h> 9#include <linux/stackprotector.h>
@@ -95,8 +96,10 @@ static void cpu_idle_loop(void)
95 if (!current_clr_polling_and_test()) { 96 if (!current_clr_polling_and_test()) {
96 stop_critical_timings(); 97 stop_critical_timings();
97 rcu_idle_enter(); 98 rcu_idle_enter();
98 arch_cpu_idle(); 99 if (cpuidle_idle_call())
99 WARN_ON_ONCE(irqs_disabled()); 100 arch_cpu_idle();
101 if (WARN_ON_ONCE(irqs_disabled()))
102 local_irq_enable();
100 rcu_idle_exit(); 103 rcu_idle_exit();
101 start_critical_timings(); 104 start_critical_timings();
102 } else { 105 } else {
diff --git a/kernel/sched/idle_task.c b/kernel/sched/idle_task.c
index 516c3d9ceea1..879f2b75266a 100644
--- a/kernel/sched/idle_task.c
+++ b/kernel/sched/idle_task.c
@@ -13,18 +13,8 @@ select_task_rq_idle(struct task_struct *p, int cpu, int sd_flag, int flags)
13{ 13{
14 return task_cpu(p); /* IDLE tasks as never migrated */ 14 return task_cpu(p); /* IDLE tasks as never migrated */
15} 15}
16
17static void pre_schedule_idle(struct rq *rq, struct task_struct *prev)
18{
19 idle_exit_fair(rq);
20 rq_last_tick_reset(rq);
21}
22
23static void post_schedule_idle(struct rq *rq)
24{
25 idle_enter_fair(rq);
26}
27#endif /* CONFIG_SMP */ 16#endif /* CONFIG_SMP */
17
28/* 18/*
29 * Idle tasks are unconditionally rescheduled: 19 * Idle tasks are unconditionally rescheduled:
30 */ 20 */
@@ -33,13 +23,12 @@ static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int fl
33 resched_task(rq->idle); 23 resched_task(rq->idle);
34} 24}
35 25
36static struct task_struct *pick_next_task_idle(struct rq *rq) 26static struct task_struct *
27pick_next_task_idle(struct rq *rq, struct task_struct *prev)
37{ 28{
29 put_prev_task(rq, prev);
30
38 schedstat_inc(rq, sched_goidle); 31 schedstat_inc(rq, sched_goidle);
39#ifdef CONFIG_SMP
40 /* Trigger the post schedule to do an idle_enter for CFS */
41 rq->post_schedule = 1;
42#endif
43 return rq->idle; 32 return rq->idle;
44} 33}
45 34
@@ -58,6 +47,8 @@ dequeue_task_idle(struct rq *rq, struct task_struct *p, int flags)
58 47
59static void put_prev_task_idle(struct rq *rq, struct task_struct *prev) 48static void put_prev_task_idle(struct rq *rq, struct task_struct *prev)
60{ 49{
50 idle_exit_fair(rq);
51 rq_last_tick_reset(rq);
61} 52}
62 53
63static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued) 54static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued)
@@ -101,8 +92,6 @@ const struct sched_class idle_sched_class = {
101 92
102#ifdef CONFIG_SMP 93#ifdef CONFIG_SMP
103 .select_task_rq = select_task_rq_idle, 94 .select_task_rq = select_task_rq_idle,
104 .pre_schedule = pre_schedule_idle,
105 .post_schedule = post_schedule_idle,
106#endif 95#endif
107 96
108 .set_curr_task = set_curr_task_idle, 97 .set_curr_task = set_curr_task_idle,
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index a2740b775b45..d8cdf1618551 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -229,6 +229,14 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
229 229
230#ifdef CONFIG_SMP 230#ifdef CONFIG_SMP
231 231
232static int pull_rt_task(struct rq *this_rq);
233
234static inline bool need_pull_rt_task(struct rq *rq, struct task_struct *prev)
235{
236 /* Try to pull RT tasks here if we lower this rq's prio */
237 return rq->rt.highest_prio.curr > prev->prio;
238}
239
232static inline int rt_overloaded(struct rq *rq) 240static inline int rt_overloaded(struct rq *rq)
233{ 241{
234 return atomic_read(&rq->rd->rto_count); 242 return atomic_read(&rq->rd->rto_count);
@@ -315,6 +323,15 @@ static inline int has_pushable_tasks(struct rq *rq)
315 return !plist_head_empty(&rq->rt.pushable_tasks); 323 return !plist_head_empty(&rq->rt.pushable_tasks);
316} 324}
317 325
326static inline void set_post_schedule(struct rq *rq)
327{
328 /*
329 * We detect this state here so that we can avoid taking the RQ
330 * lock again later if there is no need to push
331 */
332 rq->post_schedule = has_pushable_tasks(rq);
333}
334
318static void enqueue_pushable_task(struct rq *rq, struct task_struct *p) 335static void enqueue_pushable_task(struct rq *rq, struct task_struct *p)
319{ 336{
320 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); 337 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks);
@@ -359,6 +376,19 @@ void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
359{ 376{
360} 377}
361 378
379static inline bool need_pull_rt_task(struct rq *rq, struct task_struct *prev)
380{
381 return false;
382}
383
384static inline int pull_rt_task(struct rq *this_rq)
385{
386 return 0;
387}
388
389static inline void set_post_schedule(struct rq *rq)
390{
391}
362#endif /* CONFIG_SMP */ 392#endif /* CONFIG_SMP */
363 393
364static inline int on_rt_rq(struct sched_rt_entity *rt_se) 394static inline int on_rt_rq(struct sched_rt_entity *rt_se)
@@ -440,11 +470,6 @@ static void sched_rt_rq_dequeue(struct rt_rq *rt_rq)
440 dequeue_rt_entity(rt_se); 470 dequeue_rt_entity(rt_se);
441} 471}
442 472
443static inline int rt_rq_throttled(struct rt_rq *rt_rq)
444{
445 return rt_rq->rt_throttled && !rt_rq->rt_nr_boosted;
446}
447
448static int rt_se_boosted(struct sched_rt_entity *rt_se) 473static int rt_se_boosted(struct sched_rt_entity *rt_se)
449{ 474{
450 struct rt_rq *rt_rq = group_rt_rq(rt_se); 475 struct rt_rq *rt_rq = group_rt_rq(rt_se);
@@ -515,11 +540,6 @@ static inline void sched_rt_rq_dequeue(struct rt_rq *rt_rq)
515{ 540{
516} 541}
517 542
518static inline int rt_rq_throttled(struct rt_rq *rt_rq)
519{
520 return rt_rq->rt_throttled;
521}
522
523static inline const struct cpumask *sched_rt_period_mask(void) 543static inline const struct cpumask *sched_rt_period_mask(void)
524{ 544{
525 return cpu_online_mask; 545 return cpu_online_mask;
@@ -538,6 +558,14 @@ static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
538 558
539#endif /* CONFIG_RT_GROUP_SCHED */ 559#endif /* CONFIG_RT_GROUP_SCHED */
540 560
561bool sched_rt_bandwidth_account(struct rt_rq *rt_rq)
562{
563 struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
564
565 return (hrtimer_active(&rt_b->rt_period_timer) ||
566 rt_rq->rt_time < rt_b->rt_runtime);
567}
568
541#ifdef CONFIG_SMP 569#ifdef CONFIG_SMP
542/* 570/*
543 * We ran out of runtime, see if we can borrow some from our neighbours. 571 * We ran out of runtime, see if we can borrow some from our neighbours.
@@ -1310,15 +1338,7 @@ static struct task_struct *_pick_next_task_rt(struct rq *rq)
1310{ 1338{
1311 struct sched_rt_entity *rt_se; 1339 struct sched_rt_entity *rt_se;
1312 struct task_struct *p; 1340 struct task_struct *p;
1313 struct rt_rq *rt_rq; 1341 struct rt_rq *rt_rq = &rq->rt;
1314
1315 rt_rq = &rq->rt;
1316
1317 if (!rt_rq->rt_nr_running)
1318 return NULL;
1319
1320 if (rt_rq_throttled(rt_rq))
1321 return NULL;
1322 1342
1323 do { 1343 do {
1324 rt_se = pick_next_rt_entity(rq, rt_rq); 1344 rt_se = pick_next_rt_entity(rq, rt_rq);
@@ -1332,21 +1352,45 @@ static struct task_struct *_pick_next_task_rt(struct rq *rq)
1332 return p; 1352 return p;
1333} 1353}
1334 1354
1335static struct task_struct *pick_next_task_rt(struct rq *rq) 1355static struct task_struct *
1356pick_next_task_rt(struct rq *rq, struct task_struct *prev)
1336{ 1357{
1337 struct task_struct *p = _pick_next_task_rt(rq); 1358 struct task_struct *p;
1359 struct rt_rq *rt_rq = &rq->rt;
1360
1361 if (need_pull_rt_task(rq, prev)) {
1362 pull_rt_task(rq);
1363 /*
1364 * pull_rt_task() can drop (and re-acquire) rq->lock; this
1365 * means a dl task can slip in, in which case we need to
1366 * re-start task selection.
1367 */
1368 if (unlikely(rq->dl.dl_nr_running))
1369 return RETRY_TASK;
1370 }
1371
1372 /*
1373 * We may dequeue prev's rt_rq in put_prev_task().
1374 * So, we update time before rt_nr_running check.
1375 */
1376 if (prev->sched_class == &rt_sched_class)
1377 update_curr_rt(rq);
1378
1379 if (!rt_rq->rt_nr_running)
1380 return NULL;
1381
1382 if (rt_rq_throttled(rt_rq))
1383 return NULL;
1384
1385 put_prev_task(rq, prev);
1386
1387 p = _pick_next_task_rt(rq);
1338 1388
1339 /* The running task is never eligible for pushing */ 1389 /* The running task is never eligible for pushing */
1340 if (p) 1390 if (p)
1341 dequeue_pushable_task(rq, p); 1391 dequeue_pushable_task(rq, p);
1342 1392
1343#ifdef CONFIG_SMP 1393 set_post_schedule(rq);
1344 /*
1345 * We detect this state here so that we can avoid taking the RQ
1346 * lock again later if there is no need to push
1347 */
1348 rq->post_schedule = has_pushable_tasks(rq);
1349#endif
1350 1394
1351 return p; 1395 return p;
1352} 1396}
@@ -1716,13 +1760,6 @@ skip:
1716 return ret; 1760 return ret;
1717} 1761}
1718 1762
1719static void pre_schedule_rt(struct rq *rq, struct task_struct *prev)
1720{
1721 /* Try to pull RT tasks here if we lower this rq's prio */
1722 if (rq->rt.highest_prio.curr > prev->prio)
1723 pull_rt_task(rq);
1724}
1725
1726static void post_schedule_rt(struct rq *rq) 1763static void post_schedule_rt(struct rq *rq)
1727{ 1764{
1728 push_rt_tasks(rq); 1765 push_rt_tasks(rq);
@@ -1825,7 +1862,7 @@ static void switched_from_rt(struct rq *rq, struct task_struct *p)
1825 resched_task(rq->curr); 1862 resched_task(rq->curr);
1826} 1863}
1827 1864
1828void init_sched_rt_class(void) 1865void __init init_sched_rt_class(void)
1829{ 1866{
1830 unsigned int i; 1867 unsigned int i;
1831 1868
@@ -1999,7 +2036,6 @@ const struct sched_class rt_sched_class = {
1999 .set_cpus_allowed = set_cpus_allowed_rt, 2036 .set_cpus_allowed = set_cpus_allowed_rt,
2000 .rq_online = rq_online_rt, 2037 .rq_online = rq_online_rt,
2001 .rq_offline = rq_offline_rt, 2038 .rq_offline = rq_offline_rt,
2002 .pre_schedule = pre_schedule_rt,
2003 .post_schedule = post_schedule_rt, 2039 .post_schedule = post_schedule_rt,
2004 .task_woken = task_woken_rt, 2040 .task_woken = task_woken_rt,
2005 .switched_from = switched_from_rt, 2041 .switched_from = switched_from_rt,
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index c2119fd20f8b..f2de7a175620 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -24,24 +24,6 @@ extern long calc_load_fold_active(struct rq *this_rq);
24extern void update_cpu_load_active(struct rq *this_rq); 24extern void update_cpu_load_active(struct rq *this_rq);
25 25
26/* 26/*
27 * Convert user-nice values [ -20 ... 0 ... 19 ]
28 * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
29 * and back.
30 */
31#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
32#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
33#define TASK_NICE(p) PRIO_TO_NICE((p)->static_prio)
34
35/*
36 * 'User priority' is the nice value converted to something we
37 * can work with better when scaling various scheduler parameters,
38 * it's a [ 0 ... 39 ] range.
39 */
40#define USER_PRIO(p) ((p)-MAX_RT_PRIO)
41#define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio)
42#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO))
43
44/*
45 * Helpers for converting nanosecond timing to jiffy resolution 27 * Helpers for converting nanosecond timing to jiffy resolution
46 */ 28 */
47#define NS_TO_JIFFIES(TIME) ((unsigned long)(TIME) / (NSEC_PER_SEC / HZ)) 29#define NS_TO_JIFFIES(TIME) ((unsigned long)(TIME) / (NSEC_PER_SEC / HZ))
@@ -441,6 +423,18 @@ struct rt_rq {
441#endif 423#endif
442}; 424};
443 425
426#ifdef CONFIG_RT_GROUP_SCHED
427static inline int rt_rq_throttled(struct rt_rq *rt_rq)
428{
429 return rt_rq->rt_throttled && !rt_rq->rt_nr_boosted;
430}
431#else
432static inline int rt_rq_throttled(struct rt_rq *rt_rq)
433{
434 return rt_rq->rt_throttled;
435}
436#endif
437
444/* Deadline class' related fields in a runqueue */ 438/* Deadline class' related fields in a runqueue */
445struct dl_rq { 439struct dl_rq {
446 /* runqueue is an rbtree, ordered by deadline */ 440 /* runqueue is an rbtree, ordered by deadline */
@@ -462,7 +456,6 @@ struct dl_rq {
462 } earliest_dl; 456 } earliest_dl;
463 457
464 unsigned long dl_nr_migratory; 458 unsigned long dl_nr_migratory;
465 unsigned long dl_nr_total;
466 int overloaded; 459 int overloaded;
467 460
468 /* 461 /*
@@ -559,11 +552,9 @@ struct rq {
559#ifdef CONFIG_FAIR_GROUP_SCHED 552#ifdef CONFIG_FAIR_GROUP_SCHED
560 /* list of leaf cfs_rq on this cpu: */ 553 /* list of leaf cfs_rq on this cpu: */
561 struct list_head leaf_cfs_rq_list; 554 struct list_head leaf_cfs_rq_list;
562#endif /* CONFIG_FAIR_GROUP_SCHED */
563 555
564#ifdef CONFIG_RT_GROUP_SCHED 556 struct sched_avg avg;
565 struct list_head leaf_rt_rq_list; 557#endif /* CONFIG_FAIR_GROUP_SCHED */
566#endif
567 558
568 /* 559 /*
569 * This is part of a global counter where only the total sum 560 * This is part of a global counter where only the total sum
@@ -652,8 +643,6 @@ struct rq {
652#ifdef CONFIG_SMP 643#ifdef CONFIG_SMP
653 struct llist_head wake_list; 644 struct llist_head wake_list;
654#endif 645#endif
655
656 struct sched_avg avg;
657}; 646};
658 647
659static inline int cpu_of(struct rq *rq) 648static inline int cpu_of(struct rq *rq)
@@ -1113,6 +1102,8 @@ static const u32 prio_to_wmult[40] = {
1113 1102
1114#define DEQUEUE_SLEEP 1 1103#define DEQUEUE_SLEEP 1
1115 1104
1105#define RETRY_TASK ((void *)-1UL)
1106
1116struct sched_class { 1107struct sched_class {
1117 const struct sched_class *next; 1108 const struct sched_class *next;
1118 1109
@@ -1123,14 +1114,22 @@ struct sched_class {
1123 1114
1124 void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags); 1115 void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
1125 1116
1126 struct task_struct * (*pick_next_task) (struct rq *rq); 1117 /*
1118 * It is the responsibility of the pick_next_task() method that will
1119 * return the next task to call put_prev_task() on the @prev task or
1120 * something equivalent.
1121 *
1122 * May return RETRY_TASK when it finds a higher prio class has runnable
1123 * tasks.
1124 */
1125 struct task_struct * (*pick_next_task) (struct rq *rq,
1126 struct task_struct *prev);
1127 void (*put_prev_task) (struct rq *rq, struct task_struct *p); 1127 void (*put_prev_task) (struct rq *rq, struct task_struct *p);
1128 1128
1129#ifdef CONFIG_SMP 1129#ifdef CONFIG_SMP
1130 int (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags); 1130 int (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);
1131 void (*migrate_task_rq)(struct task_struct *p, int next_cpu); 1131 void (*migrate_task_rq)(struct task_struct *p, int next_cpu);
1132 1132
1133 void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
1134 void (*post_schedule) (struct rq *this_rq); 1133 void (*post_schedule) (struct rq *this_rq);
1135 void (*task_waking) (struct task_struct *task); 1134 void (*task_waking) (struct task_struct *task);
1136 void (*task_woken) (struct rq *this_rq, struct task_struct *task); 1135 void (*task_woken) (struct rq *this_rq, struct task_struct *task);
@@ -1160,6 +1159,11 @@ struct sched_class {
1160#endif 1159#endif
1161}; 1160};
1162 1161
1162static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
1163{
1164 prev->sched_class->put_prev_task(rq, prev);
1165}
1166
1163#define sched_class_highest (&stop_sched_class) 1167#define sched_class_highest (&stop_sched_class)
1164#define for_each_class(class) \ 1168#define for_each_class(class) \
1165 for (class = sched_class_highest; class; class = class->next) 1169 for (class = sched_class_highest; class; class = class->next)
@@ -1176,16 +1180,14 @@ extern const struct sched_class idle_sched_class;
1176extern void update_group_power(struct sched_domain *sd, int cpu); 1180extern void update_group_power(struct sched_domain *sd, int cpu);
1177 1181
1178extern void trigger_load_balance(struct rq *rq); 1182extern void trigger_load_balance(struct rq *rq);
1179extern void idle_balance(int this_cpu, struct rq *this_rq);
1180 1183
1181extern void idle_enter_fair(struct rq *this_rq); 1184extern void idle_enter_fair(struct rq *this_rq);
1182extern void idle_exit_fair(struct rq *this_rq); 1185extern void idle_exit_fair(struct rq *this_rq);
1183 1186
1184#else /* CONFIG_SMP */ 1187#else
1185 1188
1186static inline void idle_balance(int cpu, struct rq *rq) 1189static inline void idle_enter_fair(struct rq *rq) { }
1187{ 1190static inline void idle_exit_fair(struct rq *rq) { }
1188}
1189 1191
1190#endif 1192#endif
1191 1193
diff --git a/kernel/sched/stop_task.c b/kernel/sched/stop_task.c
index fdb6bb0b3356..d6ce65dde541 100644
--- a/kernel/sched/stop_task.c
+++ b/kernel/sched/stop_task.c
@@ -23,16 +23,19 @@ check_preempt_curr_stop(struct rq *rq, struct task_struct *p, int flags)
23 /* we're never preempted */ 23 /* we're never preempted */
24} 24}
25 25
26static struct task_struct *pick_next_task_stop(struct rq *rq) 26static struct task_struct *
27pick_next_task_stop(struct rq *rq, struct task_struct *prev)
27{ 28{
28 struct task_struct *stop = rq->stop; 29 struct task_struct *stop = rq->stop;
29 30
30 if (stop && stop->on_rq) { 31 if (!stop || !stop->on_rq)
31 stop->se.exec_start = rq_clock_task(rq); 32 return NULL;
32 return stop;
33 }
34 33
35 return NULL; 34 put_prev_task(rq, prev);
35
36 stop->se.exec_start = rq_clock_task(rq);
37
38 return stop;
36} 39}
37 40
38static void 41static void
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index 84571e09c907..01fbae5b97b7 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -293,7 +293,7 @@ int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void *
293 */ 293 */
294 smp_call_function_single(min(cpu1, cpu2), 294 smp_call_function_single(min(cpu1, cpu2),
295 &irq_cpu_stop_queue_work, 295 &irq_cpu_stop_queue_work,
296 &call_args, 0); 296 &call_args, 1);
297 lg_local_unlock(&stop_cpus_lock); 297 lg_local_unlock(&stop_cpus_lock);
298 preempt_enable(); 298 preempt_enable();
299 299
diff --git a/kernel/sys.c b/kernel/sys.c
index c0a58be780a4..adaeab6f7a87 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -174,10 +174,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
174 174
175 /* normalize: avoid signed division (rounding problems) */ 175 /* normalize: avoid signed division (rounding problems) */
176 error = -ESRCH; 176 error = -ESRCH;
177 if (niceval < -20) 177 if (niceval < MIN_NICE)
178 niceval = -20; 178 niceval = MIN_NICE;
179 if (niceval > 19) 179 if (niceval > MAX_NICE)
180 niceval = 19; 180 niceval = MAX_NICE;
181 181
182 rcu_read_lock(); 182 rcu_read_lock();
183 read_lock(&tasklist_lock); 183 read_lock(&tasklist_lock);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 49e13e1f8fe6..7754ff16f334 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -386,13 +386,6 @@ static struct ctl_table kern_table[] = {
386 .proc_handler = proc_dointvec, 386 .proc_handler = proc_dointvec,
387 }, 387 },
388 { 388 {
389 .procname = "numa_balancing_migrate_deferred",
390 .data = &sysctl_numa_balancing_migrate_deferred,
391 .maxlen = sizeof(unsigned int),
392 .mode = 0644,
393 .proc_handler = proc_dointvec,
394 },
395 {
396 .procname = "numa_balancing", 389 .procname = "numa_balancing",
397 .data = NULL, /* filled in by handler */ 390 .data = NULL, /* filled in by handler */
398 .maxlen = sizeof(unsigned int), 391 .maxlen = sizeof(unsigned int),
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index 7a925ba456fb..a6a5bf53e86d 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -51,7 +51,13 @@
51 * HZ shrinks, so values greater than 8 overflow 32bits when 51 * HZ shrinks, so values greater than 8 overflow 32bits when
52 * HZ=100. 52 * HZ=100.
53 */ 53 */
54#if HZ < 34
55#define JIFFIES_SHIFT 6
56#elif HZ < 67
57#define JIFFIES_SHIFT 7
58#else
54#define JIFFIES_SHIFT 8 59#define JIFFIES_SHIFT 8
60#endif
55 61
56static cycle_t jiffies_read(struct clocksource *cs) 62static cycle_t jiffies_read(struct clocksource *cs)
57{ 63{
diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
index 0abb36464281..4d23dc4d8139 100644
--- a/kernel/time/sched_clock.c
+++ b/kernel/time/sched_clock.c
@@ -116,20 +116,42 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt)
116void __init sched_clock_register(u64 (*read)(void), int bits, 116void __init sched_clock_register(u64 (*read)(void), int bits,
117 unsigned long rate) 117 unsigned long rate)
118{ 118{
119 u64 res, wrap, new_mask, new_epoch, cyc, ns;
120 u32 new_mult, new_shift;
121 ktime_t new_wrap_kt;
119 unsigned long r; 122 unsigned long r;
120 u64 res, wrap;
121 char r_unit; 123 char r_unit;
122 124
123 if (cd.rate > rate) 125 if (cd.rate > rate)
124 return; 126 return;
125 127
126 WARN_ON(!irqs_disabled()); 128 WARN_ON(!irqs_disabled());
127 read_sched_clock = read;
128 sched_clock_mask = CLOCKSOURCE_MASK(bits);
129 cd.rate = rate;
130 129
131 /* calculate the mult/shift to convert counter ticks to ns. */ 130 /* calculate the mult/shift to convert counter ticks to ns. */
132 clocks_calc_mult_shift(&cd.mult, &cd.shift, rate, NSEC_PER_SEC, 3600); 131 clocks_calc_mult_shift(&new_mult, &new_shift, rate, NSEC_PER_SEC, 3600);
132
133 new_mask = CLOCKSOURCE_MASK(bits);
134
135 /* calculate how many ns until we wrap */
136 wrap = clocks_calc_max_nsecs(new_mult, new_shift, 0, new_mask);
137 new_wrap_kt = ns_to_ktime(wrap - (wrap >> 3));
138
139 /* update epoch for new counter and update epoch_ns from old counter*/
140 new_epoch = read();
141 cyc = read_sched_clock();
142 ns = cd.epoch_ns + cyc_to_ns((cyc - cd.epoch_cyc) & sched_clock_mask,
143 cd.mult, cd.shift);
144
145 raw_write_seqcount_begin(&cd.seq);
146 read_sched_clock = read;
147 sched_clock_mask = new_mask;
148 cd.rate = rate;
149 cd.wrap_kt = new_wrap_kt;
150 cd.mult = new_mult;
151 cd.shift = new_shift;
152 cd.epoch_cyc = new_epoch;
153 cd.epoch_ns = ns;
154 raw_write_seqcount_end(&cd.seq);
133 155
134 r = rate; 156 r = rate;
135 if (r >= 4000000) { 157 if (r >= 4000000) {
@@ -141,22 +163,12 @@ void __init sched_clock_register(u64 (*read)(void), int bits,
141 } else 163 } else
142 r_unit = ' '; 164 r_unit = ' ';
143 165
144 /* calculate how many ns until we wrap */
145 wrap = clocks_calc_max_nsecs(cd.mult, cd.shift, 0, sched_clock_mask);
146 cd.wrap_kt = ns_to_ktime(wrap - (wrap >> 3));
147
148 /* calculate the ns resolution of this counter */ 166 /* calculate the ns resolution of this counter */
149 res = cyc_to_ns(1ULL, cd.mult, cd.shift); 167 res = cyc_to_ns(1ULL, new_mult, new_shift);
168
150 pr_info("sched_clock: %u bits at %lu%cHz, resolution %lluns, wraps every %lluns\n", 169 pr_info("sched_clock: %u bits at %lu%cHz, resolution %lluns, wraps every %lluns\n",
151 bits, r, r_unit, res, wrap); 170 bits, r, r_unit, res, wrap);
152 171
153 update_sched_clock();
154
155 /*
156 * Ensure that sched_clock() starts off at 0ns
157 */
158 cd.epoch_ns = 0;
159
160 /* Enable IRQ time accounting if we have a fast enough sched_clock */ 172 /* Enable IRQ time accounting if we have a fast enough sched_clock */
161 if (irqtime > 0 || (irqtime == -1 && rate >= 1000000)) 173 if (irqtime > 0 || (irqtime == -1 && rate >= 1000000))
162 enable_sched_clock_irqtime(); 174 enable_sched_clock_irqtime();
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
index 43780ab5e279..98977a57ac72 100644
--- a/kernel/time/tick-broadcast.c
+++ b/kernel/time/tick-broadcast.c
@@ -756,6 +756,7 @@ out:
756static void tick_broadcast_clear_oneshot(int cpu) 756static void tick_broadcast_clear_oneshot(int cpu)
757{ 757{
758 cpumask_clear_cpu(cpu, tick_broadcast_oneshot_mask); 758 cpumask_clear_cpu(cpu, tick_broadcast_oneshot_mask);
759 cpumask_clear_cpu(cpu, tick_broadcast_pending_mask);
759} 760}
760 761
761static void tick_broadcast_init_next_event(struct cpumask *mask, 762static void tick_broadcast_init_next_event(struct cpumask *mask,
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 0aa4ce81bc16..5b40279ecd71 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1435,7 +1435,8 @@ void update_wall_time(void)
1435out: 1435out:
1436 raw_spin_unlock_irqrestore(&timekeeper_lock, flags); 1436 raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
1437 if (clock_set) 1437 if (clock_set)
1438 clock_was_set(); 1438 /* Have to call _delayed version, since in irq context*/
1439 clock_was_set_delayed();
1439} 1440}
1440 1441
1441/** 1442/**
diff --git a/kernel/timer.c b/kernel/timer.c
index accfd241b9e5..d78de047599b 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -52,7 +52,7 @@
52#define CREATE_TRACE_POINTS 52#define CREATE_TRACE_POINTS
53#include <trace/events/timer.h> 53#include <trace/events/timer.h>
54 54
55u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES; 55__visible u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES;
56 56
57EXPORT_SYMBOL(jiffies_64); 57EXPORT_SYMBOL(jiffies_64);
58 58
diff --git a/kernel/torture.c b/kernel/torture.c
new file mode 100644
index 000000000000..acc9afc2f26e
--- /dev/null
+++ b/kernel/torture.c
@@ -0,0 +1,719 @@
1/*
2 * Common functions for in-kernel torture tests.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 *
18 * Copyright (C) IBM Corporation, 2014
19 *
20 * Author: Paul E. McKenney <paulmck@us.ibm.com>
21 * Based on kernel/rcu/torture.c.
22 */
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/kthread.h>
28#include <linux/err.h>
29#include <linux/spinlock.h>
30#include <linux/smp.h>
31#include <linux/interrupt.h>
32#include <linux/sched.h>
33#include <linux/atomic.h>
34#include <linux/bitops.h>
35#include <linux/completion.h>
36#include <linux/moduleparam.h>
37#include <linux/percpu.h>
38#include <linux/notifier.h>
39#include <linux/reboot.h>
40#include <linux/freezer.h>
41#include <linux/cpu.h>
42#include <linux/delay.h>
43#include <linux/stat.h>
44#include <linux/slab.h>
45#include <linux/trace_clock.h>
46#include <asm/byteorder.h>
47#include <linux/torture.h>
48
49MODULE_LICENSE("GPL");
50MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>");
51
52static char *torture_type;
53static bool verbose;
54
55/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
56#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
57#define FULLSTOP_SHUTDOWN 1 /* System shutdown with torture running. */
58#define FULLSTOP_RMMOD 2 /* Normal rmmod of torture. */
59static int fullstop = FULLSTOP_RMMOD;
60static DEFINE_MUTEX(fullstop_mutex);
61static int *torture_runnable;
62
63#ifdef CONFIG_HOTPLUG_CPU
64
65/*
66 * Variables for online-offline handling. Only present if CPU hotplug
67 * is enabled, otherwise does nothing.
68 */
69
70static struct task_struct *onoff_task;
71static long onoff_holdoff;
72static long onoff_interval;
73static long n_offline_attempts;
74static long n_offline_successes;
75static unsigned long sum_offline;
76static int min_offline = -1;
77static int max_offline;
78static long n_online_attempts;
79static long n_online_successes;
80static unsigned long sum_online;
81static int min_online = -1;
82static int max_online;
83
84/*
85 * Execute random CPU-hotplug operations at the interval specified
86 * by the onoff_interval.
87 */
88static int
89torture_onoff(void *arg)
90{
91 int cpu;
92 unsigned long delta;
93 int maxcpu = -1;
94 DEFINE_TORTURE_RANDOM(rand);
95 int ret;
96 unsigned long starttime;
97
98 VERBOSE_TOROUT_STRING("torture_onoff task started");
99 for_each_online_cpu(cpu)
100 maxcpu = cpu;
101 WARN_ON(maxcpu < 0);
102 if (onoff_holdoff > 0) {
103 VERBOSE_TOROUT_STRING("torture_onoff begin holdoff");
104 schedule_timeout_interruptible(onoff_holdoff);
105 VERBOSE_TOROUT_STRING("torture_onoff end holdoff");
106 }
107 while (!torture_must_stop()) {
108 cpu = (torture_random(&rand) >> 4) % (maxcpu + 1);
109 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
110 if (verbose)
111 pr_alert("%s" TORTURE_FLAG
112 "torture_onoff task: offlining %d\n",
113 torture_type, cpu);
114 starttime = jiffies;
115 n_offline_attempts++;
116 ret = cpu_down(cpu);
117 if (ret) {
118 if (verbose)
119 pr_alert("%s" TORTURE_FLAG
120 "torture_onoff task: offline %d failed: errno %d\n",
121 torture_type, cpu, ret);
122 } else {
123 if (verbose)
124 pr_alert("%s" TORTURE_FLAG
125 "torture_onoff task: offlined %d\n",
126 torture_type, cpu);
127 n_offline_successes++;
128 delta = jiffies - starttime;
129 sum_offline += delta;
130 if (min_offline < 0) {
131 min_offline = delta;
132 max_offline = delta;
133 }
134 if (min_offline > delta)
135 min_offline = delta;
136 if (max_offline < delta)
137 max_offline = delta;
138 }
139 } else if (cpu_is_hotpluggable(cpu)) {
140 if (verbose)
141 pr_alert("%s" TORTURE_FLAG
142 "torture_onoff task: onlining %d\n",
143 torture_type, cpu);
144 starttime = jiffies;
145 n_online_attempts++;
146 ret = cpu_up(cpu);
147 if (ret) {
148 if (verbose)
149 pr_alert("%s" TORTURE_FLAG
150 "torture_onoff task: online %d failed: errno %d\n",
151 torture_type, cpu, ret);
152 } else {
153 if (verbose)
154 pr_alert("%s" TORTURE_FLAG
155 "torture_onoff task: onlined %d\n",
156 torture_type, cpu);
157 n_online_successes++;
158 delta = jiffies - starttime;
159 sum_online += delta;
160 if (min_online < 0) {
161 min_online = delta;
162 max_online = delta;
163 }
164 if (min_online > delta)
165 min_online = delta;
166 if (max_online < delta)
167 max_online = delta;
168 }
169 }
170 schedule_timeout_interruptible(onoff_interval);
171 }
172 torture_kthread_stopping("torture_onoff");
173 return 0;
174}
175
176#endif /* #ifdef CONFIG_HOTPLUG_CPU */
177
178/*
179 * Initiate online-offline handling.
180 */
181int torture_onoff_init(long ooholdoff, long oointerval)
182{
183 int ret = 0;
184
185#ifdef CONFIG_HOTPLUG_CPU
186 onoff_holdoff = ooholdoff;
187 onoff_interval = oointerval;
188 if (onoff_interval <= 0)
189 return 0;
190 ret = torture_create_kthread(torture_onoff, NULL, onoff_task);
191#endif /* #ifdef CONFIG_HOTPLUG_CPU */
192 return ret;
193}
194EXPORT_SYMBOL_GPL(torture_onoff_init);
195
196/*
197 * Clean up after online/offline testing.
198 */
199static void torture_onoff_cleanup(void)
200{
201#ifdef CONFIG_HOTPLUG_CPU
202 if (onoff_task == NULL)
203 return;
204 VERBOSE_TOROUT_STRING("Stopping torture_onoff task");
205 kthread_stop(onoff_task);
206 onoff_task = NULL;
207#endif /* #ifdef CONFIG_HOTPLUG_CPU */
208}
209EXPORT_SYMBOL_GPL(torture_onoff_cleanup);
210
211/*
212 * Print online/offline testing statistics.
213 */
214char *torture_onoff_stats(char *page)
215{
216#ifdef CONFIG_HOTPLUG_CPU
217 page += sprintf(page,
218 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
219 n_online_successes, n_online_attempts,
220 n_offline_successes, n_offline_attempts,
221 min_online, max_online,
222 min_offline, max_offline,
223 sum_online, sum_offline, HZ);
224#endif /* #ifdef CONFIG_HOTPLUG_CPU */
225 return page;
226}
227EXPORT_SYMBOL_GPL(torture_onoff_stats);
228
229/*
230 * Were all the online/offline operations successful?
231 */
232bool torture_onoff_failures(void)
233{
234#ifdef CONFIG_HOTPLUG_CPU
235 return n_online_successes != n_online_attempts ||
236 n_offline_successes != n_offline_attempts;
237#else /* #ifdef CONFIG_HOTPLUG_CPU */
238 return false;
239#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
240}
241EXPORT_SYMBOL_GPL(torture_onoff_failures);
242
243#define TORTURE_RANDOM_MULT 39916801 /* prime */
244#define TORTURE_RANDOM_ADD 479001701 /* prime */
245#define TORTURE_RANDOM_REFRESH 10000
246
247/*
248 * Crude but fast random-number generator. Uses a linear congruential
249 * generator, with occasional help from cpu_clock().
250 */
251unsigned long
252torture_random(struct torture_random_state *trsp)
253{
254 if (--trsp->trs_count < 0) {
255 trsp->trs_state += (unsigned long)local_clock();
256 trsp->trs_count = TORTURE_RANDOM_REFRESH;
257 }
258 trsp->trs_state = trsp->trs_state * TORTURE_RANDOM_MULT +
259 TORTURE_RANDOM_ADD;
260 return swahw32(trsp->trs_state);
261}
262EXPORT_SYMBOL_GPL(torture_random);
263
264/*
265 * Variables for shuffling. The idea is to ensure that each CPU stays
266 * idle for an extended period to test interactions with dyntick idle,
267 * as well as interactions with any per-CPU varibles.
268 */
269struct shuffle_task {
270 struct list_head st_l;
271 struct task_struct *st_t;
272};
273
274static long shuffle_interval; /* In jiffies. */
275static struct task_struct *shuffler_task;
276static cpumask_var_t shuffle_tmp_mask;
277static int shuffle_idle_cpu; /* Force all torture tasks off this CPU */
278static struct list_head shuffle_task_list = LIST_HEAD_INIT(shuffle_task_list);
279static DEFINE_MUTEX(shuffle_task_mutex);
280
281/*
282 * Register a task to be shuffled. If there is no memory, just splat
283 * and don't bother registering.
284 */
285void torture_shuffle_task_register(struct task_struct *tp)
286{
287 struct shuffle_task *stp;
288
289 if (WARN_ON_ONCE(tp == NULL))
290 return;
291 stp = kmalloc(sizeof(*stp), GFP_KERNEL);
292 if (WARN_ON_ONCE(stp == NULL))
293 return;
294 stp->st_t = tp;
295 mutex_lock(&shuffle_task_mutex);
296 list_add(&stp->st_l, &shuffle_task_list);
297 mutex_unlock(&shuffle_task_mutex);
298}
299EXPORT_SYMBOL_GPL(torture_shuffle_task_register);
300
301/*
302 * Unregister all tasks, for example, at the end of the torture run.
303 */
304static void torture_shuffle_task_unregister_all(void)
305{
306 struct shuffle_task *stp;
307 struct shuffle_task *p;
308
309 mutex_lock(&shuffle_task_mutex);
310 list_for_each_entry_safe(stp, p, &shuffle_task_list, st_l) {
311 list_del(&stp->st_l);
312 kfree(stp);
313 }
314 mutex_unlock(&shuffle_task_mutex);
315}
316
317/* Shuffle tasks such that we allow shuffle_idle_cpu to become idle.
318 * A special case is when shuffle_idle_cpu = -1, in which case we allow
319 * the tasks to run on all CPUs.
320 */
321static void torture_shuffle_tasks(void)
322{
323 struct shuffle_task *stp;
324
325 cpumask_setall(shuffle_tmp_mask);
326 get_online_cpus();
327
328 /* No point in shuffling if there is only one online CPU (ex: UP) */
329 if (num_online_cpus() == 1) {
330 put_online_cpus();
331 return;
332 }
333
334 /* Advance to the next CPU. Upon overflow, don't idle any CPUs. */
335 shuffle_idle_cpu = cpumask_next(shuffle_idle_cpu, shuffle_tmp_mask);
336 if (shuffle_idle_cpu >= nr_cpu_ids)
337 shuffle_idle_cpu = -1;
338 if (shuffle_idle_cpu != -1) {
339 cpumask_clear_cpu(shuffle_idle_cpu, shuffle_tmp_mask);
340 if (cpumask_empty(shuffle_tmp_mask)) {
341 put_online_cpus();
342 return;
343 }
344 }
345
346 mutex_lock(&shuffle_task_mutex);
347 list_for_each_entry(stp, &shuffle_task_list, st_l)
348 set_cpus_allowed_ptr(stp->st_t, shuffle_tmp_mask);
349 mutex_unlock(&shuffle_task_mutex);
350
351 put_online_cpus();
352}
353
354/* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
355 * system to become idle at a time and cut off its timer ticks. This is meant
356 * to test the support for such tickless idle CPU in RCU.
357 */
358static int torture_shuffle(void *arg)
359{
360 VERBOSE_TOROUT_STRING("torture_shuffle task started");
361 do {
362 schedule_timeout_interruptible(shuffle_interval);
363 torture_shuffle_tasks();
364 torture_shutdown_absorb("torture_shuffle");
365 } while (!torture_must_stop());
366 torture_kthread_stopping("torture_shuffle");
367 return 0;
368}
369
370/*
371 * Start the shuffler, with shuffint in jiffies.
372 */
373int torture_shuffle_init(long shuffint)
374{
375 shuffle_interval = shuffint;
376
377 shuffle_idle_cpu = -1;
378
379 if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
380 VERBOSE_TOROUT_ERRSTRING("Failed to alloc mask");
381 return -ENOMEM;
382 }
383
384 /* Create the shuffler thread */
385 return torture_create_kthread(torture_shuffle, NULL, shuffler_task);
386}
387EXPORT_SYMBOL_GPL(torture_shuffle_init);
388
389/*
390 * Stop the shuffling.
391 */
392static void torture_shuffle_cleanup(void)
393{
394 torture_shuffle_task_unregister_all();
395 if (shuffler_task) {
396 VERBOSE_TOROUT_STRING("Stopping torture_shuffle task");
397 kthread_stop(shuffler_task);
398 free_cpumask_var(shuffle_tmp_mask);
399 }
400 shuffler_task = NULL;
401}
402EXPORT_SYMBOL_GPL(torture_shuffle_cleanup);
403
404/*
405 * Variables for auto-shutdown. This allows "lights out" torture runs
406 * to be fully scripted.
407 */
408static int shutdown_secs; /* desired test duration in seconds. */
409static struct task_struct *shutdown_task;
410static unsigned long shutdown_time; /* jiffies to system shutdown. */
411static void (*torture_shutdown_hook)(void);
412
413/*
414 * Absorb kthreads into a kernel function that won't return, so that
415 * they won't ever access module text or data again.
416 */
417void torture_shutdown_absorb(const char *title)
418{
419 while (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
420 pr_notice("torture thread %s parking due to system shutdown\n",
421 title);
422 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
423 }
424}
425EXPORT_SYMBOL_GPL(torture_shutdown_absorb);
426
427/*
428 * Cause the torture test to shutdown the system after the test has
429 * run for the time specified by the shutdown_secs parameter.
430 */
431static int torture_shutdown(void *arg)
432{
433 long delta;
434 unsigned long jiffies_snap;
435
436 VERBOSE_TOROUT_STRING("torture_shutdown task started");
437 jiffies_snap = jiffies;
438 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
439 !torture_must_stop()) {
440 delta = shutdown_time - jiffies_snap;
441 if (verbose)
442 pr_alert("%s" TORTURE_FLAG
443 "torture_shutdown task: %lu jiffies remaining\n",
444 torture_type, delta);
445 schedule_timeout_interruptible(delta);
446 jiffies_snap = jiffies;
447 }
448 if (torture_must_stop()) {
449 torture_kthread_stopping("torture_shutdown");
450 return 0;
451 }
452
453 /* OK, shut down the system. */
454
455 VERBOSE_TOROUT_STRING("torture_shutdown task shutting down system");
456 shutdown_task = NULL; /* Avoid self-kill deadlock. */
457 if (torture_shutdown_hook)
458 torture_shutdown_hook();
459 else
460 VERBOSE_TOROUT_STRING("No torture_shutdown_hook(), skipping.");
461 kernel_power_off(); /* Shut down the system. */
462 return 0;
463}
464
465/*
466 * Start up the shutdown task.
467 */
468int torture_shutdown_init(int ssecs, void (*cleanup)(void))
469{
470 int ret = 0;
471
472 shutdown_secs = ssecs;
473 torture_shutdown_hook = cleanup;
474 if (shutdown_secs > 0) {
475 shutdown_time = jiffies + shutdown_secs * HZ;
476 ret = torture_create_kthread(torture_shutdown, NULL,
477 shutdown_task);
478 }
479 return ret;
480}
481EXPORT_SYMBOL_GPL(torture_shutdown_init);
482
483/*
484 * Detect and respond to a system shutdown.
485 */
486static int torture_shutdown_notify(struct notifier_block *unused1,
487 unsigned long unused2, void *unused3)
488{
489 mutex_lock(&fullstop_mutex);
490 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
491 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
492 ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
493 } else {
494 pr_warn("Concurrent rmmod and shutdown illegal!\n");
495 }
496 mutex_unlock(&fullstop_mutex);
497 return NOTIFY_DONE;
498}
499
500static struct notifier_block torture_shutdown_nb = {
501 .notifier_call = torture_shutdown_notify,
502};
503
504/*
505 * Shut down the shutdown task. Say what??? Heh! This can happen if
506 * the torture module gets an rmmod before the shutdown time arrives. ;-)
507 */
508static void torture_shutdown_cleanup(void)
509{
510 unregister_reboot_notifier(&torture_shutdown_nb);
511 if (shutdown_task != NULL) {
512 VERBOSE_TOROUT_STRING("Stopping torture_shutdown task");
513 kthread_stop(shutdown_task);
514 }
515 shutdown_task = NULL;
516}
517
518/*
519 * Variables for stuttering, which means to periodically pause and
520 * restart testing in order to catch bugs that appear when load is
521 * suddenly applied to or removed from the system.
522 */
523static struct task_struct *stutter_task;
524static int stutter_pause_test;
525static int stutter;
526
527/*
528 * Block until the stutter interval ends. This must be called periodically
529 * by all running kthreads that need to be subject to stuttering.
530 */
531void stutter_wait(const char *title)
532{
533 while (ACCESS_ONCE(stutter_pause_test) ||
534 (torture_runnable && !ACCESS_ONCE(*torture_runnable))) {
535 if (stutter_pause_test)
536 schedule_timeout_interruptible(1);
537 else
538 schedule_timeout_interruptible(round_jiffies_relative(HZ));
539 torture_shutdown_absorb(title);
540 }
541}
542EXPORT_SYMBOL_GPL(stutter_wait);
543
544/*
545 * Cause the torture test to "stutter", starting and stopping all
546 * threads periodically.
547 */
548static int torture_stutter(void *arg)
549{
550 VERBOSE_TOROUT_STRING("torture_stutter task started");
551 do {
552 if (!torture_must_stop()) {
553 schedule_timeout_interruptible(stutter);
554 ACCESS_ONCE(stutter_pause_test) = 1;
555 }
556 if (!torture_must_stop())
557 schedule_timeout_interruptible(stutter);
558 ACCESS_ONCE(stutter_pause_test) = 0;
559 torture_shutdown_absorb("torture_stutter");
560 } while (!torture_must_stop());
561 torture_kthread_stopping("torture_stutter");
562 return 0;
563}
564
565/*
566 * Initialize and kick off the torture_stutter kthread.
567 */
568int torture_stutter_init(int s)
569{
570 int ret;
571
572 stutter = s;
573 ret = torture_create_kthread(torture_stutter, NULL, stutter_task);
574 return ret;
575}
576EXPORT_SYMBOL_GPL(torture_stutter_init);
577
578/*
579 * Cleanup after the torture_stutter kthread.
580 */
581static void torture_stutter_cleanup(void)
582{
583 if (!stutter_task)
584 return;
585 VERBOSE_TOROUT_STRING("Stopping torture_stutter task");
586 kthread_stop(stutter_task);
587 stutter_task = NULL;
588}
589
590/*
591 * Initialize torture module. Please note that this is -not- invoked via
592 * the usual module_init() mechanism, but rather by an explicit call from
593 * the client torture module. This call must be paired with a later
594 * torture_init_end().
595 *
596 * The runnable parameter points to a flag that controls whether or not
597 * the test is currently runnable. If there is no such flag, pass in NULL.
598 */
599void __init torture_init_begin(char *ttype, bool v, int *runnable)
600{
601 mutex_lock(&fullstop_mutex);
602 torture_type = ttype;
603 verbose = v;
604 torture_runnable = runnable;
605 fullstop = FULLSTOP_DONTSTOP;
606
607}
608EXPORT_SYMBOL_GPL(torture_init_begin);
609
610/*
611 * Tell the torture module that initialization is complete.
612 */
613void __init torture_init_end(void)
614{
615 mutex_unlock(&fullstop_mutex);
616 register_reboot_notifier(&torture_shutdown_nb);
617}
618EXPORT_SYMBOL_GPL(torture_init_end);
619
620/*
621 * Clean up torture module. Please note that this is -not- invoked via
622 * the usual module_exit() mechanism, but rather by an explicit call from
623 * the client torture module. Returns true if a race with system shutdown
624 * is detected, otherwise, all kthreads started by functions in this file
625 * will be shut down.
626 *
627 * This must be called before the caller starts shutting down its own
628 * kthreads.
629 */
630bool torture_cleanup(void)
631{
632 mutex_lock(&fullstop_mutex);
633 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
634 pr_warn("Concurrent rmmod and shutdown illegal!\n");
635 mutex_unlock(&fullstop_mutex);
636 schedule_timeout_uninterruptible(10);
637 return true;
638 }
639 ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
640 mutex_unlock(&fullstop_mutex);
641 torture_shutdown_cleanup();
642 torture_shuffle_cleanup();
643 torture_stutter_cleanup();
644 torture_onoff_cleanup();
645 return false;
646}
647EXPORT_SYMBOL_GPL(torture_cleanup);
648
649/*
650 * Is it time for the current torture test to stop?
651 */
652bool torture_must_stop(void)
653{
654 return torture_must_stop_irq() || kthread_should_stop();
655}
656EXPORT_SYMBOL_GPL(torture_must_stop);
657
658/*
659 * Is it time for the current torture test to stop? This is the irq-safe
660 * version, hence no check for kthread_should_stop().
661 */
662bool torture_must_stop_irq(void)
663{
664 return ACCESS_ONCE(fullstop) != FULLSTOP_DONTSTOP;
665}
666EXPORT_SYMBOL_GPL(torture_must_stop_irq);
667
668/*
669 * Each kthread must wait for kthread_should_stop() before returning from
670 * its top-level function, otherwise segfaults ensue. This function
671 * prints a "stopping" message and waits for kthread_should_stop(), and
672 * should be called from all torture kthreads immediately prior to
673 * returning.
674 */
675void torture_kthread_stopping(char *title)
676{
677 if (verbose)
678 VERBOSE_TOROUT_STRING(title);
679 while (!kthread_should_stop()) {
680 torture_shutdown_absorb(title);
681 schedule_timeout_uninterruptible(1);
682 }
683}
684EXPORT_SYMBOL_GPL(torture_kthread_stopping);
685
686/*
687 * Create a generic torture kthread that is immediately runnable. If you
688 * need the kthread to be stopped so that you can do something to it before
689 * it starts, you will need to open-code your own.
690 */
691int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m,
692 char *f, struct task_struct **tp)
693{
694 int ret = 0;
695
696 VERBOSE_TOROUT_STRING(m);
697 *tp = kthread_run(fn, arg, s);
698 if (IS_ERR(*tp)) {
699 ret = PTR_ERR(*tp);
700 VERBOSE_TOROUT_ERRSTRING(f);
701 *tp = NULL;
702 }
703 torture_shuffle_task_register(*tp);
704 return ret;
705}
706EXPORT_SYMBOL_GPL(_torture_create_kthread);
707
708/*
709 * Stop a generic kthread, emitting a message.
710 */
711void _torture_stop_kthread(char *m, struct task_struct **tp)
712{
713 if (*tp == NULL)
714 return;
715 VERBOSE_TOROUT_STRING(m);
716 kthread_stop(*tp);
717 *tp = NULL;
718}
719EXPORT_SYMBOL_GPL(_torture_stop_kthread);
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 294b8a271a04..fc4da2d97f9b 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -2397,6 +2397,13 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
2397 write &= RB_WRITE_MASK; 2397 write &= RB_WRITE_MASK;
2398 tail = write - length; 2398 tail = write - length;
2399 2399
2400 /*
2401 * If this is the first commit on the page, then it has the same
2402 * timestamp as the page itself.
2403 */
2404 if (!tail)
2405 delta = 0;
2406
2400 /* See if we shot pass the end of this buffer page */ 2407 /* See if we shot pass the end of this buffer page */
2401 if (unlikely(write > BUF_PAGE_SIZE)) 2408 if (unlikely(write > BUF_PAGE_SIZE))
2402 return rb_move_tail(cpu_buffer, length, tail, 2409 return rb_move_tail(cpu_buffer, length, tail,
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index a5457d577b98..0434ff1b808e 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -40,8 +40,8 @@ static int write_iteration = 50;
40module_param(write_iteration, uint, 0644); 40module_param(write_iteration, uint, 0644);
41MODULE_PARM_DESC(write_iteration, "# of writes between timestamp readings"); 41MODULE_PARM_DESC(write_iteration, "# of writes between timestamp readings");
42 42
43static int producer_nice = 19; 43static int producer_nice = MAX_NICE;
44static int consumer_nice = 19; 44static int consumer_nice = MAX_NICE;
45 45
46static int producer_fifo = -1; 46static int producer_fifo = -1;
47static int consumer_fifo = -1; 47static int consumer_fifo = -1;
@@ -308,7 +308,7 @@ static void ring_buffer_producer(void)
308 308
309 /* Let the user know that the test is running at low priority */ 309 /* Let the user know that the test is running at low priority */
310 if (producer_fifo < 0 && consumer_fifo < 0 && 310 if (producer_fifo < 0 && consumer_fifo < 0 &&
311 producer_nice == 19 && consumer_nice == 19) 311 producer_nice == MAX_NICE && consumer_nice == MAX_NICE)
312 trace_printk("WARNING!!! This test is running at lowest priority.\n"); 312 trace_printk("WARNING!!! This test is running at lowest priority.\n");
313 313
314 trace_printk("Time: %lld (usecs)\n", time); 314 trace_printk("Time: %lld (usecs)\n", time);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 815c878f409b..24c1f2382557 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1600,15 +1600,31 @@ void trace_buffer_unlock_commit(struct ring_buffer *buffer,
1600} 1600}
1601EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); 1601EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit);
1602 1602
1603static struct ring_buffer *temp_buffer;
1604
1603struct ring_buffer_event * 1605struct ring_buffer_event *
1604trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, 1606trace_event_buffer_lock_reserve(struct ring_buffer **current_rb,
1605 struct ftrace_event_file *ftrace_file, 1607 struct ftrace_event_file *ftrace_file,
1606 int type, unsigned long len, 1608 int type, unsigned long len,
1607 unsigned long flags, int pc) 1609 unsigned long flags, int pc)
1608{ 1610{
1611 struct ring_buffer_event *entry;
1612
1609 *current_rb = ftrace_file->tr->trace_buffer.buffer; 1613 *current_rb = ftrace_file->tr->trace_buffer.buffer;
1610 return trace_buffer_lock_reserve(*current_rb, 1614 entry = trace_buffer_lock_reserve(*current_rb,
1611 type, len, flags, pc); 1615 type, len, flags, pc);
1616 /*
1617 * If tracing is off, but we have triggers enabled
1618 * we still need to look at the event data. Use the temp_buffer
1619 * to store the trace event for the tigger to use. It's recusive
1620 * safe and will not be recorded anywhere.
1621 */
1622 if (!entry && ftrace_file->flags & FTRACE_EVENT_FL_TRIGGER_COND) {
1623 *current_rb = temp_buffer;
1624 entry = trace_buffer_lock_reserve(*current_rb,
1625 type, len, flags, pc);
1626 }
1627 return entry;
1612} 1628}
1613EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); 1629EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve);
1614 1630
@@ -6494,11 +6510,16 @@ __init static int tracer_alloc_buffers(void)
6494 6510
6495 raw_spin_lock_init(&global_trace.start_lock); 6511 raw_spin_lock_init(&global_trace.start_lock);
6496 6512
6513 /* Used for event triggers */
6514 temp_buffer = ring_buffer_alloc(PAGE_SIZE, RB_FL_OVERWRITE);
6515 if (!temp_buffer)
6516 goto out_free_cpumask;
6517
6497 /* TODO: make the number of buffers hot pluggable with CPUS */ 6518 /* TODO: make the number of buffers hot pluggable with CPUS */
6498 if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { 6519 if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) {
6499 printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); 6520 printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
6500 WARN_ON(1); 6521 WARN_ON(1);
6501 goto out_free_cpumask; 6522 goto out_free_temp_buffer;
6502 } 6523 }
6503 6524
6504 if (global_trace.buffer_disabled) 6525 if (global_trace.buffer_disabled)
@@ -6540,6 +6561,8 @@ __init static int tracer_alloc_buffers(void)
6540 6561
6541 return 0; 6562 return 0;
6542 6563
6564out_free_temp_buffer:
6565 ring_buffer_free(temp_buffer);
6543out_free_cpumask: 6566out_free_cpumask:
6544 free_percpu(global_trace.trace_buffer.data); 6567 free_percpu(global_trace.trace_buffer.data);
6545#ifdef CONFIG_TRACER_MAX_TRACE 6568#ifdef CONFIG_TRACER_MAX_TRACE
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index e854f420e033..c894614de14d 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -31,9 +31,25 @@ static int perf_trace_event_perm(struct ftrace_event_call *tp_event,
31 } 31 }
32 32
33 /* The ftrace function trace is allowed only for root. */ 33 /* The ftrace function trace is allowed only for root. */
34 if (ftrace_event_is_function(tp_event) && 34 if (ftrace_event_is_function(tp_event)) {
35 perf_paranoid_tracepoint_raw() && !capable(CAP_SYS_ADMIN)) 35 if (perf_paranoid_tracepoint_raw() && !capable(CAP_SYS_ADMIN))
36 return -EPERM; 36 return -EPERM;
37
38 /*
39 * We don't allow user space callchains for function trace
40 * event, due to issues with page faults while tracing page
41 * fault handler and its overall trickiness nature.
42 */
43 if (!p_event->attr.exclude_callchain_user)
44 return -EINVAL;
45
46 /*
47 * Same reason to disable user stack dump as for user space
48 * callchains above.
49 */
50 if (p_event->attr.sample_type & PERF_SAMPLE_STACK_USER)
51 return -EINVAL;
52 }
37 53
38 /* No tracing, just counting, so no obvious leak */ 54 /* No tracing, just counting, so no obvious leak */
39 if (!(p_event->attr.sample_type & PERF_SAMPLE_RAW)) 55 if (!(p_event->attr.sample_type & PERF_SAMPLE_RAW))
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index e71ffd4eccb5..7b16d40bd64d 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -27,12 +27,6 @@
27 27
28DEFINE_MUTEX(event_mutex); 28DEFINE_MUTEX(event_mutex);
29 29
30DEFINE_MUTEX(event_storage_mutex);
31EXPORT_SYMBOL_GPL(event_storage_mutex);
32
33char event_storage[EVENT_STORAGE_SIZE];
34EXPORT_SYMBOL_GPL(event_storage);
35
36LIST_HEAD(ftrace_events); 30LIST_HEAD(ftrace_events);
37static LIST_HEAD(ftrace_common_fields); 31static LIST_HEAD(ftrace_common_fields);
38 32
@@ -1777,6 +1771,16 @@ static void trace_module_add_events(struct module *mod)
1777{ 1771{
1778 struct ftrace_event_call **call, **start, **end; 1772 struct ftrace_event_call **call, **start, **end;
1779 1773
1774 if (!mod->num_trace_events)
1775 return;
1776
1777 /* Don't add infrastructure for mods without tracepoints */
1778 if (trace_module_has_bad_taint(mod)) {
1779 pr_err("%s: module has bad taint, not creating trace events\n",
1780 mod->name);
1781 return;
1782 }
1783
1780 start = mod->trace_events; 1784 start = mod->trace_events;
1781 end = mod->trace_events + mod->num_trace_events; 1785 end = mod->trace_events + mod->num_trace_events;
1782 1786
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c
index 7c3e3e72e2b6..ee0a5098ac43 100644
--- a/kernel/trace/trace_export.c
+++ b/kernel/trace/trace_export.c
@@ -95,15 +95,12 @@ static void __always_unused ____ftrace_check_##name(void) \
95#undef __array 95#undef __array
96#define __array(type, item, len) \ 96#define __array(type, item, len) \
97 do { \ 97 do { \
98 char *type_str = #type"["__stringify(len)"]"; \
98 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ 99 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
99 mutex_lock(&event_storage_mutex); \ 100 ret = trace_define_field(event_call, type_str, #item, \
100 snprintf(event_storage, sizeof(event_storage), \
101 "%s[%d]", #type, len); \
102 ret = trace_define_field(event_call, event_storage, #item, \
103 offsetof(typeof(field), item), \ 101 offsetof(typeof(field), item), \
104 sizeof(field.item), \ 102 sizeof(field.item), \
105 is_signed_type(type), filter_type); \ 103 is_signed_type(type), filter_type); \
106 mutex_unlock(&event_storage_mutex); \
107 if (ret) \ 104 if (ret) \
108 return ret; \ 105 return ret; \
109 } while (0); 106 } while (0);
diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c
index 2aefbee93a6d..887ef88b0bc7 100644
--- a/kernel/trace/trace_irqsoff.c
+++ b/kernel/trace/trace_irqsoff.c
@@ -498,14 +498,14 @@ void trace_hardirqs_off(void)
498} 498}
499EXPORT_SYMBOL(trace_hardirqs_off); 499EXPORT_SYMBOL(trace_hardirqs_off);
500 500
501void trace_hardirqs_on_caller(unsigned long caller_addr) 501__visible void trace_hardirqs_on_caller(unsigned long caller_addr)
502{ 502{
503 if (!preempt_trace() && irq_trace()) 503 if (!preempt_trace() && irq_trace())
504 stop_critical_timing(CALLER_ADDR0, caller_addr); 504 stop_critical_timing(CALLER_ADDR0, caller_addr);
505} 505}
506EXPORT_SYMBOL(trace_hardirqs_on_caller); 506EXPORT_SYMBOL(trace_hardirqs_on_caller);
507 507
508void trace_hardirqs_off_caller(unsigned long caller_addr) 508__visible void trace_hardirqs_off_caller(unsigned long caller_addr)
509{ 509{
510 if (!preempt_trace() && irq_trace()) 510 if (!preempt_trace() && irq_trace())
511 start_critical_timing(CALLER_ADDR0, caller_addr); 511 start_critical_timing(CALLER_ADDR0, caller_addr);
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 29f26540e9c9..031cc5655a51 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -631,6 +631,11 @@ void tracepoint_iter_reset(struct tracepoint_iter *iter)
631EXPORT_SYMBOL_GPL(tracepoint_iter_reset); 631EXPORT_SYMBOL_GPL(tracepoint_iter_reset);
632 632
633#ifdef CONFIG_MODULES 633#ifdef CONFIG_MODULES
634bool trace_module_has_bad_taint(struct module *mod)
635{
636 return mod->taints & ~((1 << TAINT_OOT_MODULE) | (1 << TAINT_CRAP));
637}
638
634static int tracepoint_module_coming(struct module *mod) 639static int tracepoint_module_coming(struct module *mod)
635{ 640{
636 struct tp_module *tp_mod, *iter; 641 struct tp_module *tp_mod, *iter;
@@ -641,7 +646,7 @@ static int tracepoint_module_coming(struct module *mod)
641 * module headers (for forced load), to make sure we don't cause a crash. 646 * module headers (for forced load), to make sure we don't cause a crash.
642 * Staging and out-of-tree GPL modules are fine. 647 * Staging and out-of-tree GPL modules are fine.
643 */ 648 */
644 if (mod->taints & ~((1 << TAINT_OOT_MODULE) | (1 << TAINT_CRAP))) 649 if (trace_module_has_bad_taint(mod))
645 return 0; 650 return 0;
646 mutex_lock(&tracepoints_mutex); 651 mutex_lock(&tracepoints_mutex);
647 tp_mod = kmalloc(sizeof(struct tp_module), GFP_KERNEL); 652 tp_mod = kmalloc(sizeof(struct tp_module), GFP_KERNEL);
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 240fb62cf394..dd06439b9c84 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -225,7 +225,7 @@ static u32 map_id_up(struct uid_gid_map *map, u32 id)
225 * 225 *
226 * When there is no mapping defined for the user-namespace uid 226 * When there is no mapping defined for the user-namespace uid
227 * pair INVALID_UID is returned. Callers are expected to test 227 * pair INVALID_UID is returned. Callers are expected to test
228 * for and handle handle INVALID_UID being returned. INVALID_UID 228 * for and handle INVALID_UID being returned. INVALID_UID
229 * may be tested for using uid_valid(). 229 * may be tested for using uid_valid().
230 */ 230 */
231kuid_t make_kuid(struct user_namespace *ns, uid_t uid) 231kuid_t make_kuid(struct user_namespace *ns, uid_t uid)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 82ef9f3b7473..3fa5b8f3aae3 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1851,6 +1851,12 @@ static void destroy_worker(struct worker *worker)
1851 if (worker->flags & WORKER_IDLE) 1851 if (worker->flags & WORKER_IDLE)
1852 pool->nr_idle--; 1852 pool->nr_idle--;
1853 1853
1854 /*
1855 * Once WORKER_DIE is set, the kworker may destroy itself at any
1856 * point. Pin to ensure the task stays until we're done with it.
1857 */
1858 get_task_struct(worker->task);
1859
1854 list_del_init(&worker->entry); 1860 list_del_init(&worker->entry);
1855 worker->flags |= WORKER_DIE; 1861 worker->flags |= WORKER_DIE;
1856 1862
@@ -1859,6 +1865,7 @@ static void destroy_worker(struct worker *worker)
1859 spin_unlock_irq(&pool->lock); 1865 spin_unlock_irq(&pool->lock);
1860 1866
1861 kthread_stop(worker->task); 1867 kthread_stop(worker->task);
1868 put_task_struct(worker->task);
1862 kfree(worker); 1869 kfree(worker);
1863 1870
1864 spin_lock_irq(&pool->lock); 1871 spin_lock_irq(&pool->lock);
@@ -3218,7 +3225,7 @@ static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr,
3218 return -ENOMEM; 3225 return -ENOMEM;
3219 3226
3220 if (sscanf(buf, "%d", &attrs->nice) == 1 && 3227 if (sscanf(buf, "%d", &attrs->nice) == 1 &&
3221 attrs->nice >= -20 && attrs->nice <= 19) 3228 attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE)
3222 ret = apply_workqueue_attrs(wq, attrs); 3229 ret = apply_workqueue_attrs(wq, attrs);
3223 else 3230 else
3224 ret = -EINVAL; 3231 ret = -EINVAL;
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index dbf94a7d25a8..dd7f8858188a 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -119,7 +119,7 @@ menu "Compile-time checks and compiler options"
119 119
120config DEBUG_INFO 120config DEBUG_INFO
121 bool "Compile the kernel with debug info" 121 bool "Compile the kernel with debug info"
122 depends on DEBUG_KERNEL 122 depends on DEBUG_KERNEL && !COMPILE_TEST
123 help 123 help
124 If you say Y here the resulting kernel image will include 124 If you say Y here the resulting kernel image will include
125 debugging info resulting in a larger kernel image. 125 debugging info resulting in a larger kernel image.
@@ -980,6 +980,21 @@ config DEBUG_LOCKING_API_SELFTESTS
980 The following locking APIs are covered: spinlocks, rwlocks, 980 The following locking APIs are covered: spinlocks, rwlocks,
981 mutexes and rwsems. 981 mutexes and rwsems.
982 982
983config LOCK_TORTURE_TEST
984 tristate "torture tests for locking"
985 depends on DEBUG_KERNEL
986 select TORTURE_TEST
987 default n
988 help
989 This option provides a kernel module that runs torture tests
990 on kernel locking primitives. The kernel module may be built
991 after the fact on the running kernel to be tested, if desired.
992
993 Say Y here if you want kernel locking-primitive torture tests
994 to be built into the kernel.
995 Say M if you want these torture tests to build as a module.
996 Say N if you are unsure.
997
983endmenu # lock debugging 998endmenu # lock debugging
984 999
985config TRACE_IRQFLAGS 1000config TRACE_IRQFLAGS
@@ -1141,9 +1156,14 @@ config SPARSE_RCU_POINTER
1141 1156
1142 Say N if you are unsure. 1157 Say N if you are unsure.
1143 1158
1159config TORTURE_TEST
1160 tristate
1161 default n
1162
1144config RCU_TORTURE_TEST 1163config RCU_TORTURE_TEST
1145 tristate "torture tests for RCU" 1164 tristate "torture tests for RCU"
1146 depends on DEBUG_KERNEL 1165 depends on DEBUG_KERNEL
1166 select TORTURE_TEST
1147 default n 1167 default n
1148 help 1168 help
1149 This option provides a kernel module that runs torture tests 1169 This option provides a kernel module that runs torture tests
diff --git a/lib/Makefile b/lib/Makefile
index 126b34f2eb16..48140e3ba73f 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o
45obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o 45obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o
46obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o 46obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o
47 47
48GCOV_PROFILE_hweight.o := n
48CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) 49CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
49obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o 50obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
50 51
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 2defd1308b04..98f2d7e91a91 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -424,111 +424,134 @@ void debug_dma_dump_mappings(struct device *dev)
424EXPORT_SYMBOL(debug_dma_dump_mappings); 424EXPORT_SYMBOL(debug_dma_dump_mappings);
425 425
426/* 426/*
427 * For each page mapped (initial page in the case of 427 * For each mapping (initial cacheline in the case of
428 * dma_alloc_coherent/dma_map_{single|page}, or each page in a 428 * dma_alloc_coherent/dma_map_page, initial cacheline in each page of a
429 * scatterlist) insert into this tree using the pfn as the key. At 429 * scatterlist, or the cacheline specified in dma_map_single) insert
430 * into this tree using the cacheline as the key. At
430 * dma_unmap_{single|sg|page} or dma_free_coherent delete the entry. If 431 * dma_unmap_{single|sg|page} or dma_free_coherent delete the entry. If
431 * the pfn already exists at insertion time add a tag as a reference 432 * the entry already exists at insertion time add a tag as a reference
432 * count for the overlapping mappings. For now, the overlap tracking 433 * count for the overlapping mappings. For now, the overlap tracking
433 * just ensures that 'unmaps' balance 'maps' before marking the pfn 434 * just ensures that 'unmaps' balance 'maps' before marking the
434 * idle, but we should also be flagging overlaps as an API violation. 435 * cacheline idle, but we should also be flagging overlaps as an API
436 * violation.
435 * 437 *
436 * Memory usage is mostly constrained by the maximum number of available 438 * Memory usage is mostly constrained by the maximum number of available
437 * dma-debug entries in that we need a free dma_debug_entry before 439 * dma-debug entries in that we need a free dma_debug_entry before
438 * inserting into the tree. In the case of dma_map_{single|page} and 440 * inserting into the tree. In the case of dma_map_page and
439 * dma_alloc_coherent there is only one dma_debug_entry and one pfn to 441 * dma_alloc_coherent there is only one dma_debug_entry and one
440 * track per event. dma_map_sg(), on the other hand, 442 * dma_active_cacheline entry to track per event. dma_map_sg(), on the
441 * consumes a single dma_debug_entry, but inserts 'nents' entries into 443 * other hand, consumes a single dma_debug_entry, but inserts 'nents'
442 * the tree. 444 * entries into the tree.
443 * 445 *
444 * At any time debug_dma_assert_idle() can be called to trigger a 446 * At any time debug_dma_assert_idle() can be called to trigger a
445 * warning if the given page is in the active set. 447 * warning if any cachelines in the given page are in the active set.
446 */ 448 */
447static RADIX_TREE(dma_active_pfn, GFP_NOWAIT); 449static RADIX_TREE(dma_active_cacheline, GFP_NOWAIT);
448static DEFINE_SPINLOCK(radix_lock); 450static DEFINE_SPINLOCK(radix_lock);
449#define ACTIVE_PFN_MAX_OVERLAP ((1 << RADIX_TREE_MAX_TAGS) - 1) 451#define ACTIVE_CACHELINE_MAX_OVERLAP ((1 << RADIX_TREE_MAX_TAGS) - 1)
452#define CACHELINE_PER_PAGE_SHIFT (PAGE_SHIFT - L1_CACHE_SHIFT)
453#define CACHELINES_PER_PAGE (1 << CACHELINE_PER_PAGE_SHIFT)
450 454
451static int active_pfn_read_overlap(unsigned long pfn) 455static phys_addr_t to_cacheline_number(struct dma_debug_entry *entry)
456{
457 return (entry->pfn << CACHELINE_PER_PAGE_SHIFT) +
458 (entry->offset >> L1_CACHE_SHIFT);
459}
460
461static int active_cacheline_read_overlap(phys_addr_t cln)
452{ 462{
453 int overlap = 0, i; 463 int overlap = 0, i;
454 464
455 for (i = RADIX_TREE_MAX_TAGS - 1; i >= 0; i--) 465 for (i = RADIX_TREE_MAX_TAGS - 1; i >= 0; i--)
456 if (radix_tree_tag_get(&dma_active_pfn, pfn, i)) 466 if (radix_tree_tag_get(&dma_active_cacheline, cln, i))
457 overlap |= 1 << i; 467 overlap |= 1 << i;
458 return overlap; 468 return overlap;
459} 469}
460 470
461static int active_pfn_set_overlap(unsigned long pfn, int overlap) 471static int active_cacheline_set_overlap(phys_addr_t cln, int overlap)
462{ 472{
463 int i; 473 int i;
464 474
465 if (overlap > ACTIVE_PFN_MAX_OVERLAP || overlap < 0) 475 if (overlap > ACTIVE_CACHELINE_MAX_OVERLAP || overlap < 0)
466 return overlap; 476 return overlap;
467 477
468 for (i = RADIX_TREE_MAX_TAGS - 1; i >= 0; i--) 478 for (i = RADIX_TREE_MAX_TAGS - 1; i >= 0; i--)
469 if (overlap & 1 << i) 479 if (overlap & 1 << i)
470 radix_tree_tag_set(&dma_active_pfn, pfn, i); 480 radix_tree_tag_set(&dma_active_cacheline, cln, i);
471 else 481 else
472 radix_tree_tag_clear(&dma_active_pfn, pfn, i); 482 radix_tree_tag_clear(&dma_active_cacheline, cln, i);
473 483
474 return overlap; 484 return overlap;
475} 485}
476 486
477static void active_pfn_inc_overlap(unsigned long pfn) 487static void active_cacheline_inc_overlap(phys_addr_t cln)
478{ 488{
479 int overlap = active_pfn_read_overlap(pfn); 489 int overlap = active_cacheline_read_overlap(cln);
480 490
481 overlap = active_pfn_set_overlap(pfn, ++overlap); 491 overlap = active_cacheline_set_overlap(cln, ++overlap);
482 492
483 /* If we overflowed the overlap counter then we're potentially 493 /* If we overflowed the overlap counter then we're potentially
484 * leaking dma-mappings. Otherwise, if maps and unmaps are 494 * leaking dma-mappings. Otherwise, if maps and unmaps are
485 * balanced then this overflow may cause false negatives in 495 * balanced then this overflow may cause false negatives in
486 * debug_dma_assert_idle() as the pfn may be marked idle 496 * debug_dma_assert_idle() as the cacheline may be marked idle
487 * prematurely. 497 * prematurely.
488 */ 498 */
489 WARN_ONCE(overlap > ACTIVE_PFN_MAX_OVERLAP, 499 WARN_ONCE(overlap > ACTIVE_CACHELINE_MAX_OVERLAP,
490 "DMA-API: exceeded %d overlapping mappings of pfn %lx\n", 500 "DMA-API: exceeded %d overlapping mappings of cacheline %pa\n",
491 ACTIVE_PFN_MAX_OVERLAP, pfn); 501 ACTIVE_CACHELINE_MAX_OVERLAP, &cln);
492} 502}
493 503
494static int active_pfn_dec_overlap(unsigned long pfn) 504static int active_cacheline_dec_overlap(phys_addr_t cln)
495{ 505{
496 int overlap = active_pfn_read_overlap(pfn); 506 int overlap = active_cacheline_read_overlap(cln);
497 507
498 return active_pfn_set_overlap(pfn, --overlap); 508 return active_cacheline_set_overlap(cln, --overlap);
499} 509}
500 510
501static int active_pfn_insert(struct dma_debug_entry *entry) 511static int active_cacheline_insert(struct dma_debug_entry *entry)
502{ 512{
513 phys_addr_t cln = to_cacheline_number(entry);
503 unsigned long flags; 514 unsigned long flags;
504 int rc; 515 int rc;
505 516
517 /* If the device is not writing memory then we don't have any
518 * concerns about the cpu consuming stale data. This mitigates
519 * legitimate usages of overlapping mappings.
520 */
521 if (entry->direction == DMA_TO_DEVICE)
522 return 0;
523
506 spin_lock_irqsave(&radix_lock, flags); 524 spin_lock_irqsave(&radix_lock, flags);
507 rc = radix_tree_insert(&dma_active_pfn, entry->pfn, entry); 525 rc = radix_tree_insert(&dma_active_cacheline, cln, entry);
508 if (rc == -EEXIST) 526 if (rc == -EEXIST)
509 active_pfn_inc_overlap(entry->pfn); 527 active_cacheline_inc_overlap(cln);
510 spin_unlock_irqrestore(&radix_lock, flags); 528 spin_unlock_irqrestore(&radix_lock, flags);
511 529
512 return rc; 530 return rc;
513} 531}
514 532
515static void active_pfn_remove(struct dma_debug_entry *entry) 533static void active_cacheline_remove(struct dma_debug_entry *entry)
516{ 534{
535 phys_addr_t cln = to_cacheline_number(entry);
517 unsigned long flags; 536 unsigned long flags;
518 537
538 /* ...mirror the insert case */
539 if (entry->direction == DMA_TO_DEVICE)
540 return;
541
519 spin_lock_irqsave(&radix_lock, flags); 542 spin_lock_irqsave(&radix_lock, flags);
520 /* since we are counting overlaps the final put of the 543 /* since we are counting overlaps the final put of the
521 * entry->pfn will occur when the overlap count is 0. 544 * cacheline will occur when the overlap count is 0.
522 * active_pfn_dec_overlap() returns -1 in that case 545 * active_cacheline_dec_overlap() returns -1 in that case
523 */ 546 */
524 if (active_pfn_dec_overlap(entry->pfn) < 0) 547 if (active_cacheline_dec_overlap(cln) < 0)
525 radix_tree_delete(&dma_active_pfn, entry->pfn); 548 radix_tree_delete(&dma_active_cacheline, cln);
526 spin_unlock_irqrestore(&radix_lock, flags); 549 spin_unlock_irqrestore(&radix_lock, flags);
527} 550}
528 551
529/** 552/**
530 * debug_dma_assert_idle() - assert that a page is not undergoing dma 553 * debug_dma_assert_idle() - assert that a page is not undergoing dma
531 * @page: page to lookup in the dma_active_pfn tree 554 * @page: page to lookup in the dma_active_cacheline tree
532 * 555 *
533 * Place a call to this routine in cases where the cpu touching the page 556 * Place a call to this routine in cases where the cpu touching the page
534 * before the dma completes (page is dma_unmapped) will lead to data 557 * before the dma completes (page is dma_unmapped) will lead to data
@@ -536,22 +559,38 @@ static void active_pfn_remove(struct dma_debug_entry *entry)
536 */ 559 */
537void debug_dma_assert_idle(struct page *page) 560void debug_dma_assert_idle(struct page *page)
538{ 561{
562 static struct dma_debug_entry *ents[CACHELINES_PER_PAGE];
563 struct dma_debug_entry *entry = NULL;
564 void **results = (void **) &ents;
565 unsigned int nents, i;
539 unsigned long flags; 566 unsigned long flags;
540 struct dma_debug_entry *entry; 567 phys_addr_t cln;
541 568
542 if (!page) 569 if (!page)
543 return; 570 return;
544 571
572 cln = (phys_addr_t) page_to_pfn(page) << CACHELINE_PER_PAGE_SHIFT;
545 spin_lock_irqsave(&radix_lock, flags); 573 spin_lock_irqsave(&radix_lock, flags);
546 entry = radix_tree_lookup(&dma_active_pfn, page_to_pfn(page)); 574 nents = radix_tree_gang_lookup(&dma_active_cacheline, results, cln,
575 CACHELINES_PER_PAGE);
576 for (i = 0; i < nents; i++) {
577 phys_addr_t ent_cln = to_cacheline_number(ents[i]);
578
579 if (ent_cln == cln) {
580 entry = ents[i];
581 break;
582 } else if (ent_cln >= cln + CACHELINES_PER_PAGE)
583 break;
584 }
547 spin_unlock_irqrestore(&radix_lock, flags); 585 spin_unlock_irqrestore(&radix_lock, flags);
548 586
549 if (!entry) 587 if (!entry)
550 return; 588 return;
551 589
590 cln = to_cacheline_number(entry);
552 err_printk(entry->dev, entry, 591 err_printk(entry->dev, entry,
553 "DMA-API: cpu touching an active dma mapped page " 592 "DMA-API: cpu touching an active dma mapped cacheline [cln=%pa]\n",
554 "[pfn=0x%lx]\n", entry->pfn); 593 &cln);
555} 594}
556 595
557/* 596/*
@@ -568,9 +607,9 @@ static void add_dma_entry(struct dma_debug_entry *entry)
568 hash_bucket_add(bucket, entry); 607 hash_bucket_add(bucket, entry);
569 put_hash_bucket(bucket, &flags); 608 put_hash_bucket(bucket, &flags);
570 609
571 rc = active_pfn_insert(entry); 610 rc = active_cacheline_insert(entry);
572 if (rc == -ENOMEM) { 611 if (rc == -ENOMEM) {
573 pr_err("DMA-API: pfn tracking ENOMEM, dma-debug disabled\n"); 612 pr_err("DMA-API: cacheline tracking ENOMEM, dma-debug disabled\n");
574 global_disable = true; 613 global_disable = true;
575 } 614 }
576 615
@@ -631,7 +670,7 @@ static void dma_entry_free(struct dma_debug_entry *entry)
631{ 670{
632 unsigned long flags; 671 unsigned long flags;
633 672
634 active_pfn_remove(entry); 673 active_cacheline_remove(entry);
635 674
636 /* 675 /*
637 * add to beginning of the list - this way the entries are 676 * add to beginning of the list - this way the entries are
diff --git a/lib/fonts/Kconfig b/lib/fonts/Kconfig
index 4dc1b990aa23..34fd931b54b5 100644
--- a/lib/fonts/Kconfig
+++ b/lib/fonts/Kconfig
@@ -9,7 +9,7 @@ if FONT_SUPPORT
9 9
10config FONTS 10config FONTS
11 bool "Select compiled-in fonts" 11 bool "Select compiled-in fonts"
12 depends on FRAMEBUFFER_CONSOLE 12 depends on FRAMEBUFFER_CONSOLE || STI_CONSOLE
13 help 13 help
14 Say Y here if you would like to use fonts other than the default 14 Say Y here if you would like to use fonts other than the default
15 your frame buffer console usually use. 15 your frame buffer console usually use.
@@ -22,7 +22,7 @@ config FONTS
22 22
23config FONT_8x8 23config FONT_8x8
24 bool "VGA 8x8 font" if FONTS 24 bool "VGA 8x8 font" if FONTS
25 depends on FRAMEBUFFER_CONSOLE 25 depends on FRAMEBUFFER_CONSOLE || STI_CONSOLE
26 default y if !SPARC && !FONTS 26 default y if !SPARC && !FONTS
27 help 27 help
28 This is the "high resolution" font for the VGA frame buffer (the one 28 This is the "high resolution" font for the VGA frame buffer (the one
@@ -45,7 +45,7 @@ config FONT_8x16
45 45
46config FONT_6x11 46config FONT_6x11
47 bool "Mac console 6x11 font (not supported by all drivers)" if FONTS 47 bool "Mac console 6x11 font (not supported by all drivers)" if FONTS
48 depends on FRAMEBUFFER_CONSOLE 48 depends on FRAMEBUFFER_CONSOLE || STI_CONSOLE
49 default y if !SPARC && !FONTS && MAC 49 default y if !SPARC && !FONTS && MAC
50 help 50 help
51 Small console font with Macintosh-style high-half glyphs. Some Mac 51 Small console font with Macintosh-style high-half glyphs. Some Mac
diff --git a/lib/percpu_ida.c b/lib/percpu_ida.c
index 7be235f1a70b..93d145e5539c 100644
--- a/lib/percpu_ida.c
+++ b/lib/percpu_ida.c
@@ -54,9 +54,7 @@ static inline void move_tags(unsigned *dst, unsigned *dst_nr,
54/* 54/*
55 * Try to steal tags from a remote cpu's percpu freelist. 55 * Try to steal tags from a remote cpu's percpu freelist.
56 * 56 *
57 * We first check how many percpu freelists have tags - we don't steal tags 57 * We first check how many percpu freelists have tags
58 * unless enough percpu freelists have tags on them that it's possible more than
59 * half the total tags could be stuck on remote percpu freelists.
60 * 58 *
61 * Then we iterate through the cpus until we find some tags - we don't attempt 59 * Then we iterate through the cpus until we find some tags - we don't attempt
62 * to find the "best" cpu to steal from, to keep cacheline bouncing to a 60 * to find the "best" cpu to steal from, to keep cacheline bouncing to a
@@ -69,8 +67,7 @@ static inline void steal_tags(struct percpu_ida *pool,
69 struct percpu_ida_cpu *remote; 67 struct percpu_ida_cpu *remote;
70 68
71 for (cpus_have_tags = cpumask_weight(&pool->cpus_have_tags); 69 for (cpus_have_tags = cpumask_weight(&pool->cpus_have_tags);
72 cpus_have_tags * pool->percpu_max_size > pool->nr_tags / 2; 70 cpus_have_tags; cpus_have_tags--) {
73 cpus_have_tags--) {
74 cpu = cpumask_next(cpu, &pool->cpus_have_tags); 71 cpu = cpumask_next(cpu, &pool->cpus_have_tags);
75 72
76 if (cpu >= nr_cpu_ids) { 73 if (cpu >= nr_cpu_ids) {
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 7811ed3b4e70..bd4a8dfdf0b8 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1253,8 +1253,10 @@ unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item)
1253 1253
1254 node = indirect_to_ptr(node); 1254 node = indirect_to_ptr(node);
1255 max_index = radix_tree_maxindex(node->height); 1255 max_index = radix_tree_maxindex(node->height);
1256 if (cur_index > max_index) 1256 if (cur_index > max_index) {
1257 rcu_read_unlock();
1257 break; 1258 break;
1259 }
1258 1260
1259 cur_index = __locate(node, item, cur_index, &found_index); 1261 cur_index = __locate(node, item, cur_index, &found_index);
1260 rcu_read_unlock(); 1262 rcu_read_unlock();
diff --git a/lib/random32.c b/lib/random32.c
index 1e5b2df44291..614896778700 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -244,8 +244,19 @@ static void __prandom_reseed(bool late)
244 static bool latch = false; 244 static bool latch = false;
245 static DEFINE_SPINLOCK(lock); 245 static DEFINE_SPINLOCK(lock);
246 246
247 /* Asking for random bytes might result in bytes getting
248 * moved into the nonblocking pool and thus marking it
249 * as initialized. In this case we would double back into
250 * this function and attempt to do a late reseed.
251 * Ignore the pointless attempt to reseed again if we're
252 * already waiting for bytes when the nonblocking pool
253 * got initialized.
254 */
255
247 /* only allow initial seeding (late == false) once */ 256 /* only allow initial seeding (late == false) once */
248 spin_lock_irqsave(&lock, flags); 257 if (!spin_trylock_irqsave(&lock, flags))
258 return;
259
249 if (latch && !late) 260 if (latch && !late)
250 goto out; 261 goto out;
251 latch = true; 262 latch = true;
diff --git a/lib/string.c b/lib/string.c
index e5878de4f101..9b1f9062a202 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -648,7 +648,7 @@ EXPORT_SYMBOL(memmove);
648 * @count: The size of the area. 648 * @count: The size of the area.
649 */ 649 */
650#undef memcmp 650#undef memcmp
651int memcmp(const void *cs, const void *ct, size_t count) 651__visible int memcmp(const void *cs, const void *ct, size_t count)
652{ 652{
653 const unsigned char *su1, *su2; 653 const unsigned char *su1, *su2;
654 int res = 0; 654 int res = 0;
diff --git a/mm/Kconfig b/mm/Kconfig
index 2d9f1504d75e..2888024e0b0a 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -575,5 +575,5 @@ config PGTABLE_MAPPING
575 then you should select this. This causes zsmalloc to use page table 575 then you should select this. This causes zsmalloc to use page table
576 mapping rather than copying for object mapping. 576 mapping rather than copying for object mapping.
577 577
578 You can check speed with zsmalloc benchmark[1]. 578 You can check speed with zsmalloc benchmark:
579 [1] https://github.com/spartacus06/zsmalloc 579 https://github.com/spartacus06/zsmapbench
diff --git a/mm/compaction.c b/mm/compaction.c
index b48c5259ea33..918577595ea8 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -251,7 +251,6 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
251{ 251{
252 int nr_scanned = 0, total_isolated = 0; 252 int nr_scanned = 0, total_isolated = 0;
253 struct page *cursor, *valid_page = NULL; 253 struct page *cursor, *valid_page = NULL;
254 unsigned long nr_strict_required = end_pfn - blockpfn;
255 unsigned long flags; 254 unsigned long flags;
256 bool locked = false; 255 bool locked = false;
257 256
@@ -264,11 +263,12 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
264 263
265 nr_scanned++; 264 nr_scanned++;
266 if (!pfn_valid_within(blockpfn)) 265 if (!pfn_valid_within(blockpfn))
267 continue; 266 goto isolate_fail;
267
268 if (!valid_page) 268 if (!valid_page)
269 valid_page = page; 269 valid_page = page;
270 if (!PageBuddy(page)) 270 if (!PageBuddy(page))
271 continue; 271 goto isolate_fail;
272 272
273 /* 273 /*
274 * The zone lock must be held to isolate freepages. 274 * The zone lock must be held to isolate freepages.
@@ -289,12 +289,10 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
289 289
290 /* Recheck this is a buddy page under lock */ 290 /* Recheck this is a buddy page under lock */
291 if (!PageBuddy(page)) 291 if (!PageBuddy(page))
292 continue; 292 goto isolate_fail;
293 293
294 /* Found a free page, break it into order-0 pages */ 294 /* Found a free page, break it into order-0 pages */
295 isolated = split_free_page(page); 295 isolated = split_free_page(page);
296 if (!isolated && strict)
297 break;
298 total_isolated += isolated; 296 total_isolated += isolated;
299 for (i = 0; i < isolated; i++) { 297 for (i = 0; i < isolated; i++) {
300 list_add(&page->lru, freelist); 298 list_add(&page->lru, freelist);
@@ -305,7 +303,15 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
305 if (isolated) { 303 if (isolated) {
306 blockpfn += isolated - 1; 304 blockpfn += isolated - 1;
307 cursor += isolated - 1; 305 cursor += isolated - 1;
306 continue;
308 } 307 }
308
309isolate_fail:
310 if (strict)
311 break;
312 else
313 continue;
314
309 } 315 }
310 316
311 trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated); 317 trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated);
@@ -315,7 +321,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
315 * pages requested were isolated. If there were any failures, 0 is 321 * pages requested were isolated. If there were any failures, 0 is
316 * returned and CMA will fail. 322 * returned and CMA will fail.
317 */ 323 */
318 if (strict && nr_strict_required > total_isolated) 324 if (strict && blockpfn < end_pfn)
319 total_isolated = 0; 325 total_isolated = 0;
320 326
321 if (locked) 327 if (locked)
diff --git a/mm/filemap.c b/mm/filemap.c
index d56d3c145b9f..7a13f6ac5421 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2553,8 +2553,8 @@ ssize_t generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
2553 if (ret > 0) { 2553 if (ret > 0) {
2554 ssize_t err; 2554 ssize_t err;
2555 2555
2556 err = generic_write_sync(file, pos, ret); 2556 err = generic_write_sync(file, iocb->ki_pos - ret, ret);
2557 if (err < 0 && ret > 0) 2557 if (err < 0)
2558 ret = err; 2558 ret = err;
2559 } 2559 }
2560 return ret; 2560 return ret;
diff --git a/mm/fremap.c b/mm/fremap.c
index bbc4d660221a..34feba60a17e 100644
--- a/mm/fremap.c
+++ b/mm/fremap.c
@@ -23,28 +23,44 @@
23 23
24#include "internal.h" 24#include "internal.h"
25 25
26static int mm_counter(struct page *page)
27{
28 return PageAnon(page) ? MM_ANONPAGES : MM_FILEPAGES;
29}
30
26static void zap_pte(struct mm_struct *mm, struct vm_area_struct *vma, 31static void zap_pte(struct mm_struct *mm, struct vm_area_struct *vma,
27 unsigned long addr, pte_t *ptep) 32 unsigned long addr, pte_t *ptep)
28{ 33{
29 pte_t pte = *ptep; 34 pte_t pte = *ptep;
35 struct page *page;
36 swp_entry_t entry;
30 37
31 if (pte_present(pte)) { 38 if (pte_present(pte)) {
32 struct page *page;
33
34 flush_cache_page(vma, addr, pte_pfn(pte)); 39 flush_cache_page(vma, addr, pte_pfn(pte));
35 pte = ptep_clear_flush(vma, addr, ptep); 40 pte = ptep_clear_flush(vma, addr, ptep);
36 page = vm_normal_page(vma, addr, pte); 41 page = vm_normal_page(vma, addr, pte);
37 if (page) { 42 if (page) {
38 if (pte_dirty(pte)) 43 if (pte_dirty(pte))
39 set_page_dirty(page); 44 set_page_dirty(page);
45 update_hiwater_rss(mm);
46 dec_mm_counter(mm, mm_counter(page));
40 page_remove_rmap(page); 47 page_remove_rmap(page);
41 page_cache_release(page); 48 page_cache_release(page);
49 }
50 } else { /* zap_pte() is not called when pte_none() */
51 if (!pte_file(pte)) {
42 update_hiwater_rss(mm); 52 update_hiwater_rss(mm);
43 dec_mm_counter(mm, MM_FILEPAGES); 53 entry = pte_to_swp_entry(pte);
54 if (non_swap_entry(entry)) {
55 if (is_migration_entry(entry)) {
56 page = migration_entry_to_page(entry);
57 dec_mm_counter(mm, mm_counter(page));
58 }
59 } else {
60 free_swap_and_cache(entry);
61 dec_mm_counter(mm, MM_SWAPENTS);
62 }
44 } 63 }
45 } else {
46 if (!pte_file(pte))
47 free_swap_and_cache(pte_to_swp_entry(pte));
48 pte_clear_not_present_full(mm, addr, ptep, 0); 64 pte_clear_not_present_full(mm, addr, ptep, 0);
49 } 65 }
50} 66}
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 82166bf974e1..1546655a2d78 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1166,8 +1166,10 @@ alloc:
1166 } else { 1166 } else {
1167 ret = do_huge_pmd_wp_page_fallback(mm, vma, address, 1167 ret = do_huge_pmd_wp_page_fallback(mm, vma, address,
1168 pmd, orig_pmd, page, haddr); 1168 pmd, orig_pmd, page, haddr);
1169 if (ret & VM_FAULT_OOM) 1169 if (ret & VM_FAULT_OOM) {
1170 split_huge_page(page); 1170 split_huge_page(page);
1171 ret |= VM_FAULT_FALLBACK;
1172 }
1171 put_page(page); 1173 put_page(page);
1172 } 1174 }
1173 count_vm_event(THP_FAULT_FALLBACK); 1175 count_vm_event(THP_FAULT_FALLBACK);
@@ -1179,9 +1181,10 @@ alloc:
1179 if (page) { 1181 if (page) {
1180 split_huge_page(page); 1182 split_huge_page(page);
1181 put_page(page); 1183 put_page(page);
1182 } 1184 } else
1185 split_huge_page_pmd(vma, address, pmd);
1186 ret |= VM_FAULT_FALLBACK;
1183 count_vm_event(THP_FAULT_FALLBACK); 1187 count_vm_event(THP_FAULT_FALLBACK);
1184 ret |= VM_FAULT_OOM;
1185 goto out; 1188 goto out;
1186 } 1189 }
1187 1190
@@ -1545,6 +1548,7 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
1545 entry = pmd_mknonnuma(entry); 1548 entry = pmd_mknonnuma(entry);
1546 entry = pmd_modify(entry, newprot); 1549 entry = pmd_modify(entry, newprot);
1547 ret = HPAGE_PMD_NR; 1550 ret = HPAGE_PMD_NR;
1551 set_pmd_at(mm, addr, pmd, entry);
1548 BUG_ON(pmd_write(entry)); 1552 BUG_ON(pmd_write(entry));
1549 } else { 1553 } else {
1550 struct page *page = pmd_page(*pmd); 1554 struct page *page = pmd_page(*pmd);
@@ -1557,16 +1561,10 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
1557 */ 1561 */
1558 if (!is_huge_zero_page(page) && 1562 if (!is_huge_zero_page(page) &&
1559 !pmd_numa(*pmd)) { 1563 !pmd_numa(*pmd)) {
1560 entry = *pmd; 1564 pmdp_set_numa(mm, addr, pmd);
1561 entry = pmd_mknuma(entry);
1562 ret = HPAGE_PMD_NR; 1565 ret = HPAGE_PMD_NR;
1563 } 1566 }
1564 } 1567 }
1565
1566 /* Set PMD if cleared earlier */
1567 if (ret == HPAGE_PMD_NR)
1568 set_pmd_at(mm, addr, pmd, entry);
1569
1570 spin_unlock(ptl); 1568 spin_unlock(ptl);
1571 } 1569 }
1572 1570
@@ -1963,7 +1961,7 @@ out:
1963 return ret; 1961 return ret;
1964} 1962}
1965 1963
1966#define VM_NO_THP (VM_SPECIAL|VM_MIXEDMAP|VM_HUGETLB|VM_SHARED|VM_MAYSHARE) 1964#define VM_NO_THP (VM_SPECIAL | VM_HUGETLB | VM_SHARED | VM_MAYSHARE)
1967 1965
1968int hugepage_madvise(struct vm_area_struct *vma, 1966int hugepage_madvise(struct vm_area_struct *vma,
1969 unsigned long *vm_flags, int advice) 1967 unsigned long *vm_flags, int advice)
diff --git a/mm/ksm.c b/mm/ksm.c
index aa4c7c7250c1..68710e80994a 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -444,7 +444,7 @@ static void break_cow(struct rmap_item *rmap_item)
444static struct page *page_trans_compound_anon(struct page *page) 444static struct page *page_trans_compound_anon(struct page *page)
445{ 445{
446 if (PageTransCompound(page)) { 446 if (PageTransCompound(page)) {
447 struct page *head = compound_trans_head(page); 447 struct page *head = compound_head(page);
448 /* 448 /*
449 * head may actually be splitted and freed from under 449 * head may actually be splitted and freed from under
450 * us but it's ok here. 450 * us but it's ok here.
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 53385cd4e6f0..5b6b0039f725 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1127,8 +1127,8 @@ skip_node:
1127 * skipping css reference should be safe. 1127 * skipping css reference should be safe.
1128 */ 1128 */
1129 if (next_css) { 1129 if (next_css) {
1130 if ((next_css->flags & CSS_ONLINE) && 1130 if ((next_css == &root->css) ||
1131 (next_css == &root->css || css_tryget(next_css))) 1131 ((next_css->flags & CSS_ONLINE) && css_tryget(next_css)))
1132 return mem_cgroup_from_css(next_css); 1132 return mem_cgroup_from_css(next_css);
1133 1133
1134 prev_css = next_css; 1134 prev_css = next_css;
@@ -1687,7 +1687,7 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
1687 * protects memcg_name and makes sure that parallel ooms do not 1687 * protects memcg_name and makes sure that parallel ooms do not
1688 * interleave 1688 * interleave
1689 */ 1689 */
1690 static DEFINE_SPINLOCK(oom_info_lock); 1690 static DEFINE_MUTEX(oom_info_lock);
1691 struct cgroup *task_cgrp; 1691 struct cgroup *task_cgrp;
1692 struct cgroup *mem_cgrp; 1692 struct cgroup *mem_cgrp;
1693 static char memcg_name[PATH_MAX]; 1693 static char memcg_name[PATH_MAX];
@@ -1698,7 +1698,7 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
1698 if (!p) 1698 if (!p)
1699 return; 1699 return;
1700 1700
1701 spin_lock(&oom_info_lock); 1701 mutex_lock(&oom_info_lock);
1702 rcu_read_lock(); 1702 rcu_read_lock();
1703 1703
1704 mem_cgrp = memcg->css.cgroup; 1704 mem_cgrp = memcg->css.cgroup;
@@ -1767,7 +1767,7 @@ done:
1767 1767
1768 pr_cont("\n"); 1768 pr_cont("\n");
1769 } 1769 }
1770 spin_unlock(&oom_info_lock); 1770 mutex_unlock(&oom_info_lock);
1771} 1771}
1772 1772
1773/* 1773/*
@@ -6595,6 +6595,7 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
6595{ 6595{
6596 struct mem_cgroup *memcg = mem_cgroup_from_css(css); 6596 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
6597 struct mem_cgroup_event *event, *tmp; 6597 struct mem_cgroup_event *event, *tmp;
6598 struct cgroup_subsys_state *iter;
6598 6599
6599 /* 6600 /*
6600 * Unregister events and notify userspace. 6601 * Unregister events and notify userspace.
@@ -6611,7 +6612,14 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
6611 kmem_cgroup_css_offline(memcg); 6612 kmem_cgroup_css_offline(memcg);
6612 6613
6613 mem_cgroup_invalidate_reclaim_iterators(memcg); 6614 mem_cgroup_invalidate_reclaim_iterators(memcg);
6614 mem_cgroup_reparent_charges(memcg); 6615
6616 /*
6617 * This requires that offlining is serialized. Right now that is
6618 * guaranteed because css_killed_work_fn() holds the cgroup_mutex.
6619 */
6620 css_for_each_descendant_post(iter, css)
6621 mem_cgroup_reparent_charges(mem_cgroup_from_css(iter));
6622
6615 mem_cgroup_destroy_all_caches(memcg); 6623 mem_cgroup_destroy_all_caches(memcg);
6616 vmpressure_cleanup(&memcg->vmpressure); 6624 vmpressure_cleanup(&memcg->vmpressure);
6617} 6625}
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 4f08a2d61487..90002ea43638 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -945,8 +945,10 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn,
945 * to it. Similarly, page lock is shifted. 945 * to it. Similarly, page lock is shifted.
946 */ 946 */
947 if (hpage != p) { 947 if (hpage != p) {
948 put_page(hpage); 948 if (!(flags & MF_COUNT_INCREASED)) {
949 get_page(p); 949 put_page(hpage);
950 get_page(p);
951 }
950 lock_page(p); 952 lock_page(p);
951 unlock_page(hpage); 953 unlock_page(hpage);
952 *hpagep = p; 954 *hpagep = p;
@@ -1649,7 +1651,7 @@ int soft_offline_page(struct page *page, int flags)
1649{ 1651{
1650 int ret; 1652 int ret;
1651 unsigned long pfn = page_to_pfn(page); 1653 unsigned long pfn = page_to_pfn(page);
1652 struct page *hpage = compound_trans_head(page); 1654 struct page *hpage = compound_head(page);
1653 1655
1654 if (PageHWPoison(page)) { 1656 if (PageHWPoison(page)) {
1655 pr_info("soft offline: %#lx page already poisoned\n", pfn); 1657 pr_info("soft offline: %#lx page already poisoned\n", pfn);
diff --git a/mm/memory.c b/mm/memory.c
index be6a0c0d4ae0..22dfa617bddb 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3348,6 +3348,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
3348 if (ret & VM_FAULT_LOCKED) 3348 if (ret & VM_FAULT_LOCKED)
3349 unlock_page(vmf.page); 3349 unlock_page(vmf.page);
3350 ret = VM_FAULT_HWPOISON; 3350 ret = VM_FAULT_HWPOISON;
3351 page_cache_release(vmf.page);
3351 goto uncharge_out; 3352 goto uncharge_out;
3352 } 3353 }
3353 3354
@@ -3703,7 +3704,6 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
3703 if (unlikely(is_vm_hugetlb_page(vma))) 3704 if (unlikely(is_vm_hugetlb_page(vma)))
3704 return hugetlb_fault(mm, vma, address, flags); 3705 return hugetlb_fault(mm, vma, address, flags);
3705 3706
3706retry:
3707 pgd = pgd_offset(mm, address); 3707 pgd = pgd_offset(mm, address);
3708 pud = pud_alloc(mm, pgd, address); 3708 pud = pud_alloc(mm, pgd, address);
3709 if (!pud) 3709 if (!pud)
@@ -3741,20 +3741,13 @@ retry:
3741 if (dirty && !pmd_write(orig_pmd)) { 3741 if (dirty && !pmd_write(orig_pmd)) {
3742 ret = do_huge_pmd_wp_page(mm, vma, address, pmd, 3742 ret = do_huge_pmd_wp_page(mm, vma, address, pmd,
3743 orig_pmd); 3743 orig_pmd);
3744 /* 3744 if (!(ret & VM_FAULT_FALLBACK))
3745 * If COW results in an oom, the huge pmd will 3745 return ret;
3746 * have been split, so retry the fault on the
3747 * pte for a smaller charge.
3748 */
3749 if (unlikely(ret & VM_FAULT_OOM))
3750 goto retry;
3751 return ret;
3752 } else { 3746 } else {
3753 huge_pmd_set_accessed(mm, vma, address, pmd, 3747 huge_pmd_set_accessed(mm, vma, address, pmd,
3754 orig_pmd, dirty); 3748 orig_pmd, dirty);
3749 return 0;
3755 } 3750 }
3756
3757 return 0;
3758 } 3751 }
3759 } 3752 }
3760 3753
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index ae3c8f3595d4..4755c8576942 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1556,10 +1556,10 @@ SYSCALL_DEFINE5(get_mempolicy, int __user *, policy,
1556 1556
1557#ifdef CONFIG_COMPAT 1557#ifdef CONFIG_COMPAT
1558 1558
1559asmlinkage long compat_sys_get_mempolicy(int __user *policy, 1559COMPAT_SYSCALL_DEFINE5(get_mempolicy, int __user *, policy,
1560 compat_ulong_t __user *nmask, 1560 compat_ulong_t __user *, nmask,
1561 compat_ulong_t maxnode, 1561 compat_ulong_t, maxnode,
1562 compat_ulong_t addr, compat_ulong_t flags) 1562 compat_ulong_t, addr, compat_ulong_t, flags)
1563{ 1563{
1564 long err; 1564 long err;
1565 unsigned long __user *nm = NULL; 1565 unsigned long __user *nm = NULL;
@@ -1586,8 +1586,8 @@ asmlinkage long compat_sys_get_mempolicy(int __user *policy,
1586 return err; 1586 return err;
1587} 1587}
1588 1588
1589asmlinkage long compat_sys_set_mempolicy(int mode, compat_ulong_t __user *nmask, 1589COMPAT_SYSCALL_DEFINE3(set_mempolicy, int, mode, compat_ulong_t __user *, nmask,
1590 compat_ulong_t maxnode) 1590 compat_ulong_t, maxnode)
1591{ 1591{
1592 long err = 0; 1592 long err = 0;
1593 unsigned long __user *nm = NULL; 1593 unsigned long __user *nm = NULL;
@@ -1609,9 +1609,9 @@ asmlinkage long compat_sys_set_mempolicy(int mode, compat_ulong_t __user *nmask,
1609 return sys_set_mempolicy(mode, nm, nr_bits+1); 1609 return sys_set_mempolicy(mode, nm, nr_bits+1);
1610} 1610}
1611 1611
1612asmlinkage long compat_sys_mbind(compat_ulong_t start, compat_ulong_t len, 1612COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,
1613 compat_ulong_t mode, compat_ulong_t __user *nmask, 1613 compat_ulong_t, mode, compat_ulong_t __user *, nmask,
1614 compat_ulong_t maxnode, compat_ulong_t flags) 1614 compat_ulong_t, maxnode, compat_ulong_t, flags)
1615{ 1615{
1616 long err = 0; 1616 long err = 0;
1617 unsigned long __user *nm = NULL; 1617 unsigned long __user *nm = NULL;
@@ -2301,35 +2301,6 @@ static void sp_free(struct sp_node *n)
2301 kmem_cache_free(sn_cache, n); 2301 kmem_cache_free(sn_cache, n);
2302} 2302}
2303 2303
2304#ifdef CONFIG_NUMA_BALANCING
2305static bool numa_migrate_deferred(struct task_struct *p, int last_cpupid)
2306{
2307 /* Never defer a private fault */
2308 if (cpupid_match_pid(p, last_cpupid))
2309 return false;
2310
2311 if (p->numa_migrate_deferred) {
2312 p->numa_migrate_deferred--;
2313 return true;
2314 }
2315 return false;
2316}
2317
2318static inline void defer_numa_migrate(struct task_struct *p)
2319{
2320 p->numa_migrate_deferred = sysctl_numa_balancing_migrate_deferred;
2321}
2322#else
2323static inline bool numa_migrate_deferred(struct task_struct *p, int last_cpupid)
2324{
2325 return false;
2326}
2327
2328static inline void defer_numa_migrate(struct task_struct *p)
2329{
2330}
2331#endif /* CONFIG_NUMA_BALANCING */
2332
2333/** 2304/**
2334 * mpol_misplaced - check whether current page node is valid in policy 2305 * mpol_misplaced - check whether current page node is valid in policy
2335 * 2306 *
@@ -2403,52 +2374,9 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long
2403 2374
2404 /* Migrate the page towards the node whose CPU is referencing it */ 2375 /* Migrate the page towards the node whose CPU is referencing it */
2405 if (pol->flags & MPOL_F_MORON) { 2376 if (pol->flags & MPOL_F_MORON) {
2406 int last_cpupid;
2407 int this_cpupid;
2408
2409 polnid = thisnid; 2377 polnid = thisnid;
2410 this_cpupid = cpu_pid_to_cpupid(thiscpu, current->pid);
2411
2412 /*
2413 * Multi-stage node selection is used in conjunction
2414 * with a periodic migration fault to build a temporal
2415 * task<->page relation. By using a two-stage filter we
2416 * remove short/unlikely relations.
2417 *
2418 * Using P(p) ~ n_p / n_t as per frequentist
2419 * probability, we can equate a task's usage of a
2420 * particular page (n_p) per total usage of this
2421 * page (n_t) (in a given time-span) to a probability.
2422 *
2423 * Our periodic faults will sample this probability and
2424 * getting the same result twice in a row, given these
2425 * samples are fully independent, is then given by
2426 * P(n)^2, provided our sample period is sufficiently
2427 * short compared to the usage pattern.
2428 *
2429 * This quadric squishes small probabilities, making
2430 * it less likely we act on an unlikely task<->page
2431 * relation.
2432 */
2433 last_cpupid = page_cpupid_xchg_last(page, this_cpupid);
2434 if (!cpupid_pid_unset(last_cpupid) && cpupid_to_nid(last_cpupid) != thisnid) {
2435 2378
2436 /* See sysctl_numa_balancing_migrate_deferred comment */ 2379 if (!should_numa_migrate_memory(current, page, curnid, thiscpu))
2437 if (!cpupid_match_pid(current, last_cpupid))
2438 defer_numa_migrate(current);
2439
2440 goto out;
2441 }
2442
2443 /*
2444 * The quadratic filter above reduces extraneous migration
2445 * of shared pages somewhat. This code reduces it even more,
2446 * reducing the overhead of page migrations of shared pages.
2447 * This makes workloads with shared pages rely more on
2448 * "move task near its memory", and less on "move memory
2449 * towards its task", which is exactly what we want.
2450 */
2451 if (numa_migrate_deferred(current, last_cpupid))
2452 goto out; 2380 goto out;
2453 } 2381 }
2454 2382
diff --git a/mm/migrate.c b/mm/migrate.c
index 482a33d89134..bed48809e5d0 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -178,6 +178,37 @@ out:
178} 178}
179 179
180/* 180/*
181 * Congratulations to trinity for discovering this bug.
182 * mm/fremap.c's remap_file_pages() accepts any range within a single vma to
183 * convert that vma to VM_NONLINEAR; and generic_file_remap_pages() will then
184 * replace the specified range by file ptes throughout (maybe populated after).
185 * If page migration finds a page within that range, while it's still located
186 * by vma_interval_tree rather than lost to i_mmap_nonlinear list, no problem:
187 * zap_pte() clears the temporary migration entry before mmap_sem is dropped.
188 * But if the migrating page is in a part of the vma outside the range to be
189 * remapped, then it will not be cleared, and remove_migration_ptes() needs to
190 * deal with it. Fortunately, this part of the vma is of course still linear,
191 * so we just need to use linear location on the nonlinear list.
192 */
193static int remove_linear_migration_ptes_from_nonlinear(struct page *page,
194 struct address_space *mapping, void *arg)
195{
196 struct vm_area_struct *vma;
197 /* hugetlbfs does not support remap_pages, so no huge pgoff worries */
198 pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
199 unsigned long addr;
200
201 list_for_each_entry(vma,
202 &mapping->i_mmap_nonlinear, shared.nonlinear) {
203
204 addr = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
205 if (addr >= vma->vm_start && addr < vma->vm_end)
206 remove_migration_pte(page, vma, addr, arg);
207 }
208 return SWAP_AGAIN;
209}
210
211/*
181 * Get rid of all migration entries and replace them by 212 * Get rid of all migration entries and replace them by
182 * references to the indicated page. 213 * references to the indicated page.
183 */ 214 */
@@ -186,6 +217,7 @@ static void remove_migration_ptes(struct page *old, struct page *new)
186 struct rmap_walk_control rwc = { 217 struct rmap_walk_control rwc = {
187 .rmap_one = remove_migration_pte, 218 .rmap_one = remove_migration_pte,
188 .arg = old, 219 .arg = old,
220 .file_nonlinear = remove_linear_migration_ptes_from_nonlinear,
189 }; 221 };
190 222
191 rmap_walk(new, &rwc); 223 rmap_walk(new, &rwc);
@@ -1158,7 +1190,7 @@ static struct page *new_page_node(struct page *p, unsigned long private,
1158 pm->node); 1190 pm->node);
1159 else 1191 else
1160 return alloc_pages_exact_node(pm->node, 1192 return alloc_pages_exact_node(pm->node,
1161 GFP_HIGHUSER_MOVABLE | GFP_THISNODE, 0); 1193 GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, 0);
1162} 1194}
1163 1195
1164/* 1196/*
@@ -1544,9 +1576,9 @@ static struct page *alloc_misplaced_dst_page(struct page *page,
1544 struct page *newpage; 1576 struct page *newpage;
1545 1577
1546 newpage = alloc_pages_exact_node(nid, 1578 newpage = alloc_pages_exact_node(nid,
1547 (GFP_HIGHUSER_MOVABLE | GFP_THISNODE | 1579 (GFP_HIGHUSER_MOVABLE |
1548 __GFP_NOMEMALLOC | __GFP_NORETRY | 1580 __GFP_THISNODE | __GFP_NOMEMALLOC |
1549 __GFP_NOWARN) & 1581 __GFP_NORETRY | __GFP_NOWARN) &
1550 ~GFP_IOFS, 0); 1582 ~GFP_IOFS, 0);
1551 1583
1552 return newpage; 1584 return newpage;
@@ -1747,7 +1779,8 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
1747 goto out_dropref; 1779 goto out_dropref;
1748 1780
1749 new_page = alloc_pages_node(node, 1781 new_page = alloc_pages_node(node,
1750 (GFP_TRANSHUGE | GFP_THISNODE) & ~__GFP_WAIT, HPAGE_PMD_ORDER); 1782 (GFP_TRANSHUGE | __GFP_THISNODE) & ~__GFP_WAIT,
1783 HPAGE_PMD_ORDER);
1751 if (!new_page) 1784 if (!new_page)
1752 goto out_fail; 1785 goto out_fail;
1753 1786
diff --git a/mm/mmu_context.c b/mm/mmu_context.c
index 8a8cd0265e52..f802c2d216a7 100644
--- a/mm/mmu_context.c
+++ b/mm/mmu_context.c
@@ -31,6 +31,9 @@ void use_mm(struct mm_struct *mm)
31 tsk->mm = mm; 31 tsk->mm = mm;
32 switch_mm(active_mm, mm, tsk); 32 switch_mm(active_mm, mm, tsk);
33 task_unlock(tsk); 33 task_unlock(tsk);
34#ifdef finish_arch_post_lock_switch
35 finish_arch_post_lock_switch();
36#endif
34 37
35 if (active_mm != mm) 38 if (active_mm != mm)
36 mmdrop(active_mm); 39 mmdrop(active_mm);
diff --git a/mm/mprotect.c b/mm/mprotect.c
index 7332c1785744..769a67a15803 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -58,36 +58,27 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
58 if (pte_numa(ptent)) 58 if (pte_numa(ptent))
59 ptent = pte_mknonnuma(ptent); 59 ptent = pte_mknonnuma(ptent);
60 ptent = pte_modify(ptent, newprot); 60 ptent = pte_modify(ptent, newprot);
61 /*
62 * Avoid taking write faults for pages we
63 * know to be dirty.
64 */
65 if (dirty_accountable && pte_dirty(ptent))
66 ptent = pte_mkwrite(ptent);
67 ptep_modify_prot_commit(mm, addr, pte, ptent);
61 updated = true; 68 updated = true;
62 } else { 69 } else {
63 struct page *page; 70 struct page *page;
64 71
65 ptent = *pte;
66 page = vm_normal_page(vma, addr, oldpte); 72 page = vm_normal_page(vma, addr, oldpte);
67 if (page && !PageKsm(page)) { 73 if (page && !PageKsm(page)) {
68 if (!pte_numa(oldpte)) { 74 if (!pte_numa(oldpte)) {
69 ptent = pte_mknuma(ptent); 75 ptep_set_numa(mm, addr, pte);
70 set_pte_at(mm, addr, pte, ptent);
71 updated = true; 76 updated = true;
72 } 77 }
73 } 78 }
74 } 79 }
75
76 /*
77 * Avoid taking write faults for pages we know to be
78 * dirty.
79 */
80 if (dirty_accountable && pte_dirty(ptent)) {
81 ptent = pte_mkwrite(ptent);
82 updated = true;
83 }
84
85 if (updated) 80 if (updated)
86 pages++; 81 pages++;
87
88 /* Only !prot_numa always clears the pte */
89 if (!prot_numa)
90 ptep_modify_prot_commit(mm, addr, pte, ptent);
91 } else if (IS_ENABLED(CONFIG_MIGRATION) && !pte_file(oldpte)) { 82 } else if (IS_ENABLED(CONFIG_MIGRATION) && !pte_file(oldpte)) {
92 swp_entry_t entry = pte_to_swp_entry(oldpte); 83 swp_entry_t entry = pte_to_swp_entry(oldpte);
93 84
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 2d30e2cfe804..7106cb1aca8e 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2173,11 +2173,12 @@ int __set_page_dirty_nobuffers(struct page *page)
2173 if (!TestSetPageDirty(page)) { 2173 if (!TestSetPageDirty(page)) {
2174 struct address_space *mapping = page_mapping(page); 2174 struct address_space *mapping = page_mapping(page);
2175 struct address_space *mapping2; 2175 struct address_space *mapping2;
2176 unsigned long flags;
2176 2177
2177 if (!mapping) 2178 if (!mapping)
2178 return 1; 2179 return 1;
2179 2180
2180 spin_lock_irq(&mapping->tree_lock); 2181 spin_lock_irqsave(&mapping->tree_lock, flags);
2181 mapping2 = page_mapping(page); 2182 mapping2 = page_mapping(page);
2182 if (mapping2) { /* Race with truncate? */ 2183 if (mapping2) { /* Race with truncate? */
2183 BUG_ON(mapping2 != mapping); 2184 BUG_ON(mapping2 != mapping);
@@ -2186,7 +2187,7 @@ int __set_page_dirty_nobuffers(struct page *page)
2186 radix_tree_tag_set(&mapping->page_tree, 2187 radix_tree_tag_set(&mapping->page_tree,
2187 page_index(page), PAGECACHE_TAG_DIRTY); 2188 page_index(page), PAGECACHE_TAG_DIRTY);
2188 } 2189 }
2189 spin_unlock_irq(&mapping->tree_lock); 2190 spin_unlock_irqrestore(&mapping->tree_lock, flags);
2190 if (mapping->host) { 2191 if (mapping->host) {
2191 /* !PageAnon && !swapper_space */ 2192 /* !PageAnon && !swapper_space */
2192 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); 2193 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e3758a09a009..3bac76ae4b30 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -369,9 +369,11 @@ void prep_compound_page(struct page *page, unsigned long order)
369 __SetPageHead(page); 369 __SetPageHead(page);
370 for (i = 1; i < nr_pages; i++) { 370 for (i = 1; i < nr_pages; i++) {
371 struct page *p = page + i; 371 struct page *p = page + i;
372 __SetPageTail(p);
373 set_page_count(p, 0); 372 set_page_count(p, 0);
374 p->first_page = page; 373 p->first_page = page;
374 /* Make sure p->first_page is always valid for PageTail() */
375 smp_wmb();
376 __SetPageTail(p);
375 } 377 }
376} 378}
377 379
@@ -1236,6 +1238,15 @@ void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
1236 } 1238 }
1237 local_irq_restore(flags); 1239 local_irq_restore(flags);
1238} 1240}
1241static bool gfp_thisnode_allocation(gfp_t gfp_mask)
1242{
1243 return (gfp_mask & GFP_THISNODE) == GFP_THISNODE;
1244}
1245#else
1246static bool gfp_thisnode_allocation(gfp_t gfp_mask)
1247{
1248 return false;
1249}
1239#endif 1250#endif
1240 1251
1241/* 1252/*
@@ -1572,7 +1583,13 @@ again:
1572 get_pageblock_migratetype(page)); 1583 get_pageblock_migratetype(page));
1573 } 1584 }
1574 1585
1575 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order)); 1586 /*
1587 * NOTE: GFP_THISNODE allocations do not partake in the kswapd
1588 * aging protocol, so they can't be fair.
1589 */
1590 if (!gfp_thisnode_allocation(gfp_flags))
1591 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
1592
1576 __count_zone_vm_events(PGALLOC, zone, 1 << order); 1593 __count_zone_vm_events(PGALLOC, zone, 1 << order);
1577 zone_statistics(preferred_zone, zone, gfp_flags); 1594 zone_statistics(preferred_zone, zone, gfp_flags);
1578 local_irq_restore(flags); 1595 local_irq_restore(flags);
@@ -1944,8 +1961,12 @@ zonelist_scan:
1944 * ultimately fall back to remote zones that do not 1961 * ultimately fall back to remote zones that do not
1945 * partake in the fairness round-robin cycle of this 1962 * partake in the fairness round-robin cycle of this
1946 * zonelist. 1963 * zonelist.
1964 *
1965 * NOTE: GFP_THISNODE allocations do not partake in
1966 * the kswapd aging protocol, so they can't be fair.
1947 */ 1967 */
1948 if (alloc_flags & ALLOC_WMARK_LOW) { 1968 if ((alloc_flags & ALLOC_WMARK_LOW) &&
1969 !gfp_thisnode_allocation(gfp_mask)) {
1949 if (zone_page_state(zone, NR_ALLOC_BATCH) <= 0) 1970 if (zone_page_state(zone, NR_ALLOC_BATCH) <= 0)
1950 continue; 1971 continue;
1951 if (!zone_local(preferred_zone, zone)) 1972 if (!zone_local(preferred_zone, zone))
@@ -2501,8 +2522,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
2501 * allowed per node queues are empty and that nodes are 2522 * allowed per node queues are empty and that nodes are
2502 * over allocated. 2523 * over allocated.
2503 */ 2524 */
2504 if (IS_ENABLED(CONFIG_NUMA) && 2525 if (gfp_thisnode_allocation(gfp_mask))
2505 (gfp_mask & GFP_THISNODE) == GFP_THISNODE)
2506 goto nopage; 2526 goto nopage;
2507 2527
2508restart: 2528restart:
diff --git a/mm/percpu.c b/mm/percpu.c
index 036cfe07050f..63e24fb4387b 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -102,10 +102,11 @@ struct pcpu_chunk {
102 int free_size; /* free bytes in the chunk */ 102 int free_size; /* free bytes in the chunk */
103 int contig_hint; /* max contiguous size hint */ 103 int contig_hint; /* max contiguous size hint */
104 void *base_addr; /* base address of this chunk */ 104 void *base_addr; /* base address of this chunk */
105 int map_used; /* # of map entries used */ 105 int map_used; /* # of map entries used before the sentry */
106 int map_alloc; /* # of map entries allocated */ 106 int map_alloc; /* # of map entries allocated */
107 int *map; /* allocation map */ 107 int *map; /* allocation map */
108 void *data; /* chunk data */ 108 void *data; /* chunk data */
109 int first_free; /* no free below this */
109 bool immutable; /* no [de]population allowed */ 110 bool immutable; /* no [de]population allowed */
110 unsigned long populated[]; /* populated bitmap */ 111 unsigned long populated[]; /* populated bitmap */
111}; 112};
@@ -356,11 +357,11 @@ static int pcpu_need_to_extend(struct pcpu_chunk *chunk)
356{ 357{
357 int new_alloc; 358 int new_alloc;
358 359
359 if (chunk->map_alloc >= chunk->map_used + 2) 360 if (chunk->map_alloc >= chunk->map_used + 3)
360 return 0; 361 return 0;
361 362
362 new_alloc = PCPU_DFL_MAP_ALLOC; 363 new_alloc = PCPU_DFL_MAP_ALLOC;
363 while (new_alloc < chunk->map_used + 2) 364 while (new_alloc < chunk->map_used + 3)
364 new_alloc *= 2; 365 new_alloc *= 2;
365 366
366 return new_alloc; 367 return new_alloc;
@@ -418,48 +419,6 @@ out_unlock:
418} 419}
419 420
420/** 421/**
421 * pcpu_split_block - split a map block
422 * @chunk: chunk of interest
423 * @i: index of map block to split
424 * @head: head size in bytes (can be 0)
425 * @tail: tail size in bytes (can be 0)
426 *
427 * Split the @i'th map block into two or three blocks. If @head is
428 * non-zero, @head bytes block is inserted before block @i moving it
429 * to @i+1 and reducing its size by @head bytes.
430 *
431 * If @tail is non-zero, the target block, which can be @i or @i+1
432 * depending on @head, is reduced by @tail bytes and @tail byte block
433 * is inserted after the target block.
434 *
435 * @chunk->map must have enough free slots to accommodate the split.
436 *
437 * CONTEXT:
438 * pcpu_lock.
439 */
440static void pcpu_split_block(struct pcpu_chunk *chunk, int i,
441 int head, int tail)
442{
443 int nr_extra = !!head + !!tail;
444
445 BUG_ON(chunk->map_alloc < chunk->map_used + nr_extra);
446
447 /* insert new subblocks */
448 memmove(&chunk->map[i + nr_extra], &chunk->map[i],
449 sizeof(chunk->map[0]) * (chunk->map_used - i));
450 chunk->map_used += nr_extra;
451
452 if (head) {
453 chunk->map[i + 1] = chunk->map[i] - head;
454 chunk->map[i++] = head;
455 }
456 if (tail) {
457 chunk->map[i++] -= tail;
458 chunk->map[i] = tail;
459 }
460}
461
462/**
463 * pcpu_alloc_area - allocate area from a pcpu_chunk 422 * pcpu_alloc_area - allocate area from a pcpu_chunk
464 * @chunk: chunk of interest 423 * @chunk: chunk of interest
465 * @size: wanted size in bytes 424 * @size: wanted size in bytes
@@ -483,19 +442,27 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int size, int align)
483 int oslot = pcpu_chunk_slot(chunk); 442 int oslot = pcpu_chunk_slot(chunk);
484 int max_contig = 0; 443 int max_contig = 0;
485 int i, off; 444 int i, off;
445 bool seen_free = false;
446 int *p;
486 447
487 for (i = 0, off = 0; i < chunk->map_used; off += abs(chunk->map[i++])) { 448 for (i = chunk->first_free, p = chunk->map + i; i < chunk->map_used; i++, p++) {
488 bool is_last = i + 1 == chunk->map_used;
489 int head, tail; 449 int head, tail;
450 int this_size;
451
452 off = *p;
453 if (off & 1)
454 continue;
490 455
491 /* extra for alignment requirement */ 456 /* extra for alignment requirement */
492 head = ALIGN(off, align) - off; 457 head = ALIGN(off, align) - off;
493 BUG_ON(i == 0 && head != 0);
494 458
495 if (chunk->map[i] < 0) 459 this_size = (p[1] & ~1) - off;
496 continue; 460 if (this_size < head + size) {
497 if (chunk->map[i] < head + size) { 461 if (!seen_free) {
498 max_contig = max(chunk->map[i], max_contig); 462 chunk->first_free = i;
463 seen_free = true;
464 }
465 max_contig = max(this_size, max_contig);
499 continue; 466 continue;
500 } 467 }
501 468
@@ -505,44 +472,59 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int size, int align)
505 * than sizeof(int), which is very small but isn't too 472 * than sizeof(int), which is very small but isn't too
506 * uncommon for percpu allocations. 473 * uncommon for percpu allocations.
507 */ 474 */
508 if (head && (head < sizeof(int) || chunk->map[i - 1] > 0)) { 475 if (head && (head < sizeof(int) || !(p[-1] & 1))) {
509 if (chunk->map[i - 1] > 0) 476 *p = off += head;
510 chunk->map[i - 1] += head; 477 if (p[-1] & 1)
511 else {
512 chunk->map[i - 1] -= head;
513 chunk->free_size -= head; 478 chunk->free_size -= head;
514 } 479 else
515 chunk->map[i] -= head; 480 max_contig = max(*p - p[-1], max_contig);
516 off += head; 481 this_size -= head;
517 head = 0; 482 head = 0;
518 } 483 }
519 484
520 /* if tail is small, just keep it around */ 485 /* if tail is small, just keep it around */
521 tail = chunk->map[i] - head - size; 486 tail = this_size - head - size;
522 if (tail < sizeof(int)) 487 if (tail < sizeof(int)) {
523 tail = 0; 488 tail = 0;
489 size = this_size - head;
490 }
524 491
525 /* split if warranted */ 492 /* split if warranted */
526 if (head || tail) { 493 if (head || tail) {
527 pcpu_split_block(chunk, i, head, tail); 494 int nr_extra = !!head + !!tail;
495
496 /* insert new subblocks */
497 memmove(p + nr_extra + 1, p + 1,
498 sizeof(chunk->map[0]) * (chunk->map_used - i));
499 chunk->map_used += nr_extra;
500
528 if (head) { 501 if (head) {
529 i++; 502 if (!seen_free) {
530 off += head; 503 chunk->first_free = i;
531 max_contig = max(chunk->map[i - 1], max_contig); 504 seen_free = true;
505 }
506 *++p = off += head;
507 ++i;
508 max_contig = max(head, max_contig);
509 }
510 if (tail) {
511 p[1] = off + size;
512 max_contig = max(tail, max_contig);
532 } 513 }
533 if (tail)
534 max_contig = max(chunk->map[i + 1], max_contig);
535 } 514 }
536 515
516 if (!seen_free)
517 chunk->first_free = i + 1;
518
537 /* update hint and mark allocated */ 519 /* update hint and mark allocated */
538 if (is_last) 520 if (i + 1 == chunk->map_used)
539 chunk->contig_hint = max_contig; /* fully scanned */ 521 chunk->contig_hint = max_contig; /* fully scanned */
540 else 522 else
541 chunk->contig_hint = max(chunk->contig_hint, 523 chunk->contig_hint = max(chunk->contig_hint,
542 max_contig); 524 max_contig);
543 525
544 chunk->free_size -= chunk->map[i]; 526 chunk->free_size -= size;
545 chunk->map[i] = -chunk->map[i]; 527 *p |= 1;
546 528
547 pcpu_chunk_relocate(chunk, oslot); 529 pcpu_chunk_relocate(chunk, oslot);
548 return off; 530 return off;
@@ -570,34 +552,50 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int size, int align)
570static void pcpu_free_area(struct pcpu_chunk *chunk, int freeme) 552static void pcpu_free_area(struct pcpu_chunk *chunk, int freeme)
571{ 553{
572 int oslot = pcpu_chunk_slot(chunk); 554 int oslot = pcpu_chunk_slot(chunk);
573 int i, off; 555 int off = 0;
574 556 unsigned i, j;
575 for (i = 0, off = 0; i < chunk->map_used; off += abs(chunk->map[i++])) 557 int to_free = 0;
576 if (off == freeme) 558 int *p;
577 break; 559
560 freeme |= 1; /* we are searching for <given offset, in use> pair */
561
562 i = 0;
563 j = chunk->map_used;
564 while (i != j) {
565 unsigned k = (i + j) / 2;
566 off = chunk->map[k];
567 if (off < freeme)
568 i = k + 1;
569 else if (off > freeme)
570 j = k;
571 else
572 i = j = k;
573 }
578 BUG_ON(off != freeme); 574 BUG_ON(off != freeme);
579 BUG_ON(chunk->map[i] > 0);
580 575
581 chunk->map[i] = -chunk->map[i]; 576 if (i < chunk->first_free)
582 chunk->free_size += chunk->map[i]; 577 chunk->first_free = i;
583 578
579 p = chunk->map + i;
580 *p = off &= ~1;
581 chunk->free_size += (p[1] & ~1) - off;
582
583 /* merge with next? */
584 if (!(p[1] & 1))
585 to_free++;
584 /* merge with previous? */ 586 /* merge with previous? */
585 if (i > 0 && chunk->map[i - 1] >= 0) { 587 if (i > 0 && !(p[-1] & 1)) {
586 chunk->map[i - 1] += chunk->map[i]; 588 to_free++;
587 chunk->map_used--;
588 memmove(&chunk->map[i], &chunk->map[i + 1],
589 (chunk->map_used - i) * sizeof(chunk->map[0]));
590 i--; 589 i--;
590 p--;
591 } 591 }
592 /* merge with next? */ 592 if (to_free) {
593 if (i + 1 < chunk->map_used && chunk->map[i + 1] >= 0) { 593 chunk->map_used -= to_free;
594 chunk->map[i] += chunk->map[i + 1]; 594 memmove(p + 1, p + 1 + to_free,
595 chunk->map_used--; 595 (chunk->map_used - i) * sizeof(chunk->map[0]));
596 memmove(&chunk->map[i + 1], &chunk->map[i + 2],
597 (chunk->map_used - (i + 1)) * sizeof(chunk->map[0]));
598 } 596 }
599 597
600 chunk->contig_hint = max(chunk->map[i], chunk->contig_hint); 598 chunk->contig_hint = max(chunk->map[i + 1] - chunk->map[i] - 1, chunk->contig_hint);
601 pcpu_chunk_relocate(chunk, oslot); 599 pcpu_chunk_relocate(chunk, oslot);
602} 600}
603 601
@@ -617,7 +615,9 @@ static struct pcpu_chunk *pcpu_alloc_chunk(void)
617 } 615 }
618 616
619 chunk->map_alloc = PCPU_DFL_MAP_ALLOC; 617 chunk->map_alloc = PCPU_DFL_MAP_ALLOC;
620 chunk->map[chunk->map_used++] = pcpu_unit_size; 618 chunk->map[0] = 0;
619 chunk->map[1] = pcpu_unit_size | 1;
620 chunk->map_used = 1;
621 621
622 INIT_LIST_HEAD(&chunk->list); 622 INIT_LIST_HEAD(&chunk->list);
623 chunk->free_size = pcpu_unit_size; 623 chunk->free_size = pcpu_unit_size;
@@ -713,6 +713,16 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved)
713 unsigned long flags; 713 unsigned long flags;
714 void __percpu *ptr; 714 void __percpu *ptr;
715 715
716 /*
717 * We want the lowest bit of offset available for in-use/free
718 * indicator, so force >= 16bit alignment and make size even.
719 */
720 if (unlikely(align < 2))
721 align = 2;
722
723 if (unlikely(size & 1))
724 size++;
725
716 if (unlikely(!size || size > PCPU_MIN_UNIT_SIZE || align > PAGE_SIZE)) { 726 if (unlikely(!size || size > PCPU_MIN_UNIT_SIZE || align > PAGE_SIZE)) {
717 WARN(true, "illegal size (%zu) or align (%zu) for " 727 WARN(true, "illegal size (%zu) or align (%zu) for "
718 "percpu allocation\n", size, align); 728 "percpu allocation\n", size, align);
@@ -1343,9 +1353,13 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
1343 } 1353 }
1344 schunk->contig_hint = schunk->free_size; 1354 schunk->contig_hint = schunk->free_size;
1345 1355
1346 schunk->map[schunk->map_used++] = -ai->static_size; 1356 schunk->map[0] = 1;
1357 schunk->map[1] = ai->static_size;
1358 schunk->map_used = 1;
1347 if (schunk->free_size) 1359 if (schunk->free_size)
1348 schunk->map[schunk->map_used++] = schunk->free_size; 1360 schunk->map[++schunk->map_used] = 1 | (ai->static_size + schunk->free_size);
1361 else
1362 schunk->map[1] |= 1;
1349 1363
1350 /* init dynamic chunk if necessary */ 1364 /* init dynamic chunk if necessary */
1351 if (dyn_size) { 1365 if (dyn_size) {
@@ -1358,8 +1372,10 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
1358 bitmap_fill(dchunk->populated, pcpu_unit_pages); 1372 bitmap_fill(dchunk->populated, pcpu_unit_pages);
1359 1373
1360 dchunk->contig_hint = dchunk->free_size = dyn_size; 1374 dchunk->contig_hint = dchunk->free_size = dyn_size;
1361 dchunk->map[dchunk->map_used++] = -pcpu_reserved_chunk_limit; 1375 dchunk->map[0] = 1;
1362 dchunk->map[dchunk->map_used++] = dchunk->free_size; 1376 dchunk->map[1] = pcpu_reserved_chunk_limit;
1377 dchunk->map[2] = (pcpu_reserved_chunk_limit + dchunk->free_size) | 1;
1378 dchunk->map_used = 2;
1363 } 1379 }
1364 1380
1365 /* link the first chunk in */ 1381 /* link the first chunk in */
diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
index fd26d0433509..3c5cf68566ec 100644
--- a/mm/process_vm_access.c
+++ b/mm/process_vm_access.c
@@ -456,25 +456,23 @@ free_iovecs:
456 return rc; 456 return rc;
457} 457}
458 458
459asmlinkage ssize_t 459COMPAT_SYSCALL_DEFINE6(process_vm_readv, compat_pid_t, pid,
460compat_sys_process_vm_readv(compat_pid_t pid, 460 const struct compat_iovec __user *, lvec,
461 const struct compat_iovec __user *lvec, 461 compat_ulong_t, liovcnt,
462 unsigned long liovcnt, 462 const struct compat_iovec __user *, rvec,
463 const struct compat_iovec __user *rvec, 463 compat_ulong_t, riovcnt,
464 unsigned long riovcnt, 464 compat_ulong_t, flags)
465 unsigned long flags)
466{ 465{
467 return compat_process_vm_rw(pid, lvec, liovcnt, rvec, 466 return compat_process_vm_rw(pid, lvec, liovcnt, rvec,
468 riovcnt, flags, 0); 467 riovcnt, flags, 0);
469} 468}
470 469
471asmlinkage ssize_t 470COMPAT_SYSCALL_DEFINE6(process_vm_writev, compat_pid_t, pid,
472compat_sys_process_vm_writev(compat_pid_t pid, 471 const struct compat_iovec __user *, lvec,
473 const struct compat_iovec __user *lvec, 472 compat_ulong_t, liovcnt,
474 unsigned long liovcnt, 473 const struct compat_iovec __user *, rvec,
475 const struct compat_iovec __user *rvec, 474 compat_ulong_t, riovcnt,
476 unsigned long riovcnt, 475 compat_ulong_t, flags)
477 unsigned long flags)
478{ 476{
479 return compat_process_vm_rw(pid, lvec, liovcnt, rvec, 477 return compat_process_vm_rw(pid, lvec, liovcnt, rvec,
480 riovcnt, flags, 1); 478 riovcnt, flags, 1);
diff --git a/mm/rmap.c b/mm/rmap.c
index d9d42316a99a..11cf322f8133 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1165,6 +1165,16 @@ int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
1165 } 1165 }
1166 set_pte_at(mm, address, pte, 1166 set_pte_at(mm, address, pte,
1167 swp_entry_to_pte(make_hwpoison_entry(page))); 1167 swp_entry_to_pte(make_hwpoison_entry(page)));
1168 } else if (pte_unused(pteval)) {
1169 /*
1170 * The guest indicated that the page content is of no
1171 * interest anymore. Simply discard the pte, vmscan
1172 * will take care of the rest.
1173 */
1174 if (PageAnon(page))
1175 dec_mm_counter(mm, MM_ANONPAGES);
1176 else
1177 dec_mm_counter(mm, MM_FILEPAGES);
1168 } else if (PageAnon(page)) { 1178 } else if (PageAnon(page)) {
1169 swp_entry_t entry = { .val = page_private(page) }; 1179 swp_entry_t entry = { .val = page_private(page) };
1170 pte_t swp_pte; 1180 pte_t swp_pte;
@@ -1360,8 +1370,9 @@ static int try_to_unmap_cluster(unsigned long cursor, unsigned int *mapcount,
1360} 1370}
1361 1371
1362static int try_to_unmap_nonlinear(struct page *page, 1372static int try_to_unmap_nonlinear(struct page *page,
1363 struct address_space *mapping, struct vm_area_struct *vma) 1373 struct address_space *mapping, void *arg)
1364{ 1374{
1375 struct vm_area_struct *vma;
1365 int ret = SWAP_AGAIN; 1376 int ret = SWAP_AGAIN;
1366 unsigned long cursor; 1377 unsigned long cursor;
1367 unsigned long max_nl_cursor = 0; 1378 unsigned long max_nl_cursor = 0;
@@ -1663,7 +1674,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc)
1663 if (list_empty(&mapping->i_mmap_nonlinear)) 1674 if (list_empty(&mapping->i_mmap_nonlinear))
1664 goto done; 1675 goto done;
1665 1676
1666 ret = rwc->file_nonlinear(page, mapping, vma); 1677 ret = rwc->file_nonlinear(page, mapping, rwc->arg);
1667 1678
1668done: 1679done:
1669 mutex_unlock(&mapping->i_mmap_mutex); 1680 mutex_unlock(&mapping->i_mmap_mutex);
diff --git a/mm/slub.c b/mm/slub.c
index 7e3e0458bce4..25f14ad8f817 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1004,21 +1004,19 @@ static inline void slab_free_hook(struct kmem_cache *s, void *x)
1004static void add_full(struct kmem_cache *s, 1004static void add_full(struct kmem_cache *s,
1005 struct kmem_cache_node *n, struct page *page) 1005 struct kmem_cache_node *n, struct page *page)
1006{ 1006{
1007 lockdep_assert_held(&n->list_lock);
1008
1009 if (!(s->flags & SLAB_STORE_USER)) 1007 if (!(s->flags & SLAB_STORE_USER))
1010 return; 1008 return;
1011 1009
1010 lockdep_assert_held(&n->list_lock);
1012 list_add(&page->lru, &n->full); 1011 list_add(&page->lru, &n->full);
1013} 1012}
1014 1013
1015static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct page *page) 1014static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct page *page)
1016{ 1015{
1017 lockdep_assert_held(&n->list_lock);
1018
1019 if (!(s->flags & SLAB_STORE_USER)) 1016 if (!(s->flags & SLAB_STORE_USER))
1020 return; 1017 return;
1021 1018
1019 lockdep_assert_held(&n->list_lock);
1022 list_del(&page->lru); 1020 list_del(&page->lru);
1023} 1021}
1024 1022
@@ -1520,11 +1518,9 @@ static void discard_slab(struct kmem_cache *s, struct page *page)
1520/* 1518/*
1521 * Management of partially allocated slabs. 1519 * Management of partially allocated slabs.
1522 */ 1520 */
1523static inline void add_partial(struct kmem_cache_node *n, 1521static inline void
1524 struct page *page, int tail) 1522__add_partial(struct kmem_cache_node *n, struct page *page, int tail)
1525{ 1523{
1526 lockdep_assert_held(&n->list_lock);
1527
1528 n->nr_partial++; 1524 n->nr_partial++;
1529 if (tail == DEACTIVATE_TO_TAIL) 1525 if (tail == DEACTIVATE_TO_TAIL)
1530 list_add_tail(&page->lru, &n->partial); 1526 list_add_tail(&page->lru, &n->partial);
@@ -1532,15 +1528,27 @@ static inline void add_partial(struct kmem_cache_node *n,
1532 list_add(&page->lru, &n->partial); 1528 list_add(&page->lru, &n->partial);
1533} 1529}
1534 1530
1535static inline void remove_partial(struct kmem_cache_node *n, 1531static inline void add_partial(struct kmem_cache_node *n,
1536 struct page *page) 1532 struct page *page, int tail)
1537{ 1533{
1538 lockdep_assert_held(&n->list_lock); 1534 lockdep_assert_held(&n->list_lock);
1535 __add_partial(n, page, tail);
1536}
1539 1537
1538static inline void
1539__remove_partial(struct kmem_cache_node *n, struct page *page)
1540{
1540 list_del(&page->lru); 1541 list_del(&page->lru);
1541 n->nr_partial--; 1542 n->nr_partial--;
1542} 1543}
1543 1544
1545static inline void remove_partial(struct kmem_cache_node *n,
1546 struct page *page)
1547{
1548 lockdep_assert_held(&n->list_lock);
1549 __remove_partial(n, page);
1550}
1551
1544/* 1552/*
1545 * Remove slab from the partial list, freeze it and 1553 * Remove slab from the partial list, freeze it and
1546 * return the pointer to the freelist. 1554 * return the pointer to the freelist.
@@ -2906,12 +2914,10 @@ static void early_kmem_cache_node_alloc(int node)
2906 inc_slabs_node(kmem_cache_node, node, page->objects); 2914 inc_slabs_node(kmem_cache_node, node, page->objects);
2907 2915
2908 /* 2916 /*
2909 * the lock is for lockdep's sake, not for any actual 2917 * No locks need to be taken here as it has just been
2910 * race protection 2918 * initialized and there is no concurrent access.
2911 */ 2919 */
2912 spin_lock(&n->list_lock); 2920 __add_partial(n, page, DEACTIVATE_TO_HEAD);
2913 add_partial(n, page, DEACTIVATE_TO_HEAD);
2914 spin_unlock(&n->list_lock);
2915} 2921}
2916 2922
2917static void free_kmem_cache_nodes(struct kmem_cache *s) 2923static void free_kmem_cache_nodes(struct kmem_cache *s)
@@ -3197,7 +3203,7 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
3197 3203
3198 list_for_each_entry_safe(page, h, &n->partial, lru) { 3204 list_for_each_entry_safe(page, h, &n->partial, lru) {
3199 if (!page->inuse) { 3205 if (!page->inuse) {
3200 remove_partial(n, page); 3206 __remove_partial(n, page);
3201 discard_slab(s, page); 3207 discard_slab(s, page);
3202 } else { 3208 } else {
3203 list_slab_objects(s, page, 3209 list_slab_objects(s, page,
diff --git a/mm/swap.c b/mm/swap.c
index b31ba67d440a..0092097b3f4c 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -98,7 +98,7 @@ static void put_compound_page(struct page *page)
98 } 98 }
99 99
100 /* __split_huge_page_refcount can run under us */ 100 /* __split_huge_page_refcount can run under us */
101 page_head = compound_trans_head(page); 101 page_head = compound_head(page);
102 102
103 /* 103 /*
104 * THP can not break up slab pages so avoid taking 104 * THP can not break up slab pages so avoid taking
@@ -253,7 +253,7 @@ bool __get_page_tail(struct page *page)
253 */ 253 */
254 unsigned long flags; 254 unsigned long flags;
255 bool got; 255 bool got;
256 struct page *page_head = compound_trans_head(page); 256 struct page *page_head = compound_head(page);
257 257
258 /* Ref to put_compound_page() comment. */ 258 /* Ref to put_compound_page() comment. */
259 if (!__compound_tail_refcounted(page_head)) { 259 if (!__compound_tail_refcounted(page_head)) {
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 98e85e9c2b2d..e76ace30d436 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -63,6 +63,8 @@ unsigned long total_swapcache_pages(void)
63 return ret; 63 return ret;
64} 64}
65 65
66static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);
67
66void show_swap_cache_info(void) 68void show_swap_cache_info(void)
67{ 69{
68 printk("%lu pages in swap cache\n", total_swapcache_pages()); 70 printk("%lu pages in swap cache\n", total_swapcache_pages());
@@ -286,8 +288,11 @@ struct page * lookup_swap_cache(swp_entry_t entry)
286 288
287 page = find_get_page(swap_address_space(entry), entry.val); 289 page = find_get_page(swap_address_space(entry), entry.val);
288 290
289 if (page) 291 if (page) {
290 INC_CACHE_INFO(find_success); 292 INC_CACHE_INFO(find_success);
293 if (TestClearPageReadahead(page))
294 atomic_inc(&swapin_readahead_hits);
295 }
291 296
292 INC_CACHE_INFO(find_total); 297 INC_CACHE_INFO(find_total);
293 return page; 298 return page;
@@ -389,6 +394,50 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
389 return found_page; 394 return found_page;
390} 395}
391 396
397static unsigned long swapin_nr_pages(unsigned long offset)
398{
399 static unsigned long prev_offset;
400 unsigned int pages, max_pages, last_ra;
401 static atomic_t last_readahead_pages;
402
403 max_pages = 1 << ACCESS_ONCE(page_cluster);
404 if (max_pages <= 1)
405 return 1;
406
407 /*
408 * This heuristic has been found to work well on both sequential and
409 * random loads, swapping to hard disk or to SSD: please don't ask
410 * what the "+ 2" means, it just happens to work well, that's all.
411 */
412 pages = atomic_xchg(&swapin_readahead_hits, 0) + 2;
413 if (pages == 2) {
414 /*
415 * We can have no readahead hits to judge by: but must not get
416 * stuck here forever, so check for an adjacent offset instead
417 * (and don't even bother to check whether swap type is same).
418 */
419 if (offset != prev_offset + 1 && offset != prev_offset - 1)
420 pages = 1;
421 prev_offset = offset;
422 } else {
423 unsigned int roundup = 4;
424 while (roundup < pages)
425 roundup <<= 1;
426 pages = roundup;
427 }
428
429 if (pages > max_pages)
430 pages = max_pages;
431
432 /* Don't shrink readahead too fast */
433 last_ra = atomic_read(&last_readahead_pages) / 2;
434 if (pages < last_ra)
435 pages = last_ra;
436 atomic_set(&last_readahead_pages, pages);
437
438 return pages;
439}
440
392/** 441/**
393 * swapin_readahead - swap in pages in hope we need them soon 442 * swapin_readahead - swap in pages in hope we need them soon
394 * @entry: swap entry of this memory 443 * @entry: swap entry of this memory
@@ -412,11 +461,16 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask,
412 struct vm_area_struct *vma, unsigned long addr) 461 struct vm_area_struct *vma, unsigned long addr)
413{ 462{
414 struct page *page; 463 struct page *page;
415 unsigned long offset = swp_offset(entry); 464 unsigned long entry_offset = swp_offset(entry);
465 unsigned long offset = entry_offset;
416 unsigned long start_offset, end_offset; 466 unsigned long start_offset, end_offset;
417 unsigned long mask = (1UL << page_cluster) - 1; 467 unsigned long mask;
418 struct blk_plug plug; 468 struct blk_plug plug;
419 469
470 mask = swapin_nr_pages(offset) - 1;
471 if (!mask)
472 goto skip;
473
420 /* Read a page_cluster sized and aligned cluster around offset. */ 474 /* Read a page_cluster sized and aligned cluster around offset. */
421 start_offset = offset & ~mask; 475 start_offset = offset & ~mask;
422 end_offset = offset | mask; 476 end_offset = offset | mask;
@@ -430,10 +484,13 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask,
430 gfp_mask, vma, addr); 484 gfp_mask, vma, addr);
431 if (!page) 485 if (!page)
432 continue; 486 continue;
487 if (offset != entry_offset)
488 SetPageReadahead(page);
433 page_cache_release(page); 489 page_cache_release(page);
434 } 490 }
435 blk_finish_plug(&plug); 491 blk_finish_plug(&plug);
436 492
437 lru_add_drain(); /* Push any new pages onto the LRU now */ 493 lru_add_drain(); /* Push any new pages onto the LRU now */
494skip:
438 return read_swap_cache_async(entry, gfp_mask, vma, addr); 495 return read_swap_cache_async(entry, gfp_mask, vma, addr);
439} 496}
diff --git a/mm/swapfile.c b/mm/swapfile.c
index c6c13b050a58..4a7f7e6992b6 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1923,7 +1923,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
1923 p->swap_map = NULL; 1923 p->swap_map = NULL;
1924 cluster_info = p->cluster_info; 1924 cluster_info = p->cluster_info;
1925 p->cluster_info = NULL; 1925 p->cluster_info = NULL;
1926 p->flags = 0;
1927 frontswap_map = frontswap_map_get(p); 1926 frontswap_map = frontswap_map_get(p);
1928 spin_unlock(&p->lock); 1927 spin_unlock(&p->lock);
1929 spin_unlock(&swap_lock); 1928 spin_unlock(&swap_lock);
@@ -1949,6 +1948,16 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
1949 mutex_unlock(&inode->i_mutex); 1948 mutex_unlock(&inode->i_mutex);
1950 } 1949 }
1951 filp_close(swap_file, NULL); 1950 filp_close(swap_file, NULL);
1951
1952 /*
1953 * Clear the SWP_USED flag after all resources are freed so that swapon
1954 * can reuse this swap_info in alloc_swap_info() safely. It is ok to
1955 * not hold p->lock after we cleared its SWP_WRITEOK.
1956 */
1957 spin_lock(&swap_lock);
1958 p->flags = 0;
1959 spin_unlock(&swap_lock);
1960
1952 err = 0; 1961 err = 0;
1953 atomic_inc(&proc_poll_event); 1962 atomic_inc(&proc_poll_event);
1954 wake_up_interruptible(&proc_poll_wait); 1963 wake_up_interruptible(&proc_poll_wait);
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 196970a4541f..d4042e75f7c7 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -19,6 +19,7 @@
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <linux/vmstat.h> 20#include <linux/vmstat.h>
21#include <linux/eventfd.h> 21#include <linux/eventfd.h>
22#include <linux/slab.h>
22#include <linux/swap.h> 23#include <linux/swap.h>
23#include <linux/printk.h> 24#include <linux/printk.h>
24#include <linux/vmpressure.h> 25#include <linux/vmpressure.h>
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 72496140ac08..def5dd2fbe61 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -851,12 +851,14 @@ const char * const vmstat_text[] = {
851 "thp_zero_page_alloc", 851 "thp_zero_page_alloc",
852 "thp_zero_page_alloc_failed", 852 "thp_zero_page_alloc_failed",
853#endif 853#endif
854#ifdef CONFIG_DEBUG_TLBFLUSH
854#ifdef CONFIG_SMP 855#ifdef CONFIG_SMP
855 "nr_tlb_remote_flush", 856 "nr_tlb_remote_flush",
856 "nr_tlb_remote_flush_received", 857 "nr_tlb_remote_flush_received",
857#endif 858#endif /* CONFIG_SMP */
858 "nr_tlb_local_flush_all", 859 "nr_tlb_local_flush_all",
859 "nr_tlb_local_flush_one", 860 "nr_tlb_local_flush_one",
861#endif /* CONFIG_DEBUG_TLBFLUSH */
860 862
861#endif /* CONFIG_VM_EVENTS_COUNTERS */ 863#endif /* CONFIG_VM_EVENTS_COUNTERS */
862}; 864};
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index ec9909935fb6..175273f38cb1 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -307,9 +307,11 @@ static void vlan_sync_address(struct net_device *dev,
307static void vlan_transfer_features(struct net_device *dev, 307static void vlan_transfer_features(struct net_device *dev,
308 struct net_device *vlandev) 308 struct net_device *vlandev)
309{ 309{
310 struct vlan_dev_priv *vlan = vlan_dev_priv(vlandev);
311
310 vlandev->gso_max_size = dev->gso_max_size; 312 vlandev->gso_max_size = dev->gso_max_size;
311 313
312 if (dev->features & NETIF_F_HW_VLAN_CTAG_TX) 314 if (vlan_hw_offload_capable(dev->features, vlan->vlan_proto))
313 vlandev->hard_header_len = dev->hard_header_len; 315 vlandev->hard_header_len = dev->hard_header_len;
314 else 316 else
315 vlandev->hard_header_len = dev->hard_header_len + VLAN_HLEN; 317 vlandev->hard_header_len = dev->hard_header_len + VLAN_HLEN;
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index de51c48c4393..27bfe2f8e2de 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -538,6 +538,9 @@ static int vlan_passthru_hard_header(struct sk_buff *skb, struct net_device *dev
538 struct vlan_dev_priv *vlan = vlan_dev_priv(dev); 538 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
539 struct net_device *real_dev = vlan->real_dev; 539 struct net_device *real_dev = vlan->real_dev;
540 540
541 if (saddr == NULL)
542 saddr = dev->dev_addr;
543
541 return dev_hard_header(skb, real_dev, type, daddr, saddr, len); 544 return dev_hard_header(skb, real_dev, type, daddr, saddr, len);
542} 545}
543 546
@@ -575,6 +578,9 @@ static int vlan_dev_init(struct net_device *dev)
575 578
576 dev->features |= real_dev->vlan_features | NETIF_F_LLTX; 579 dev->features |= real_dev->vlan_features | NETIF_F_LLTX;
577 dev->gso_max_size = real_dev->gso_max_size; 580 dev->gso_max_size = real_dev->gso_max_size;
581 if (dev->features & NETIF_F_VLAN_FEATURES)
582 netdev_warn(real_dev, "VLAN features are set incorrectly. Q-in-Q configurations may not work correctly.\n");
583
578 584
579 /* ipv6 shared card related stuff */ 585 /* ipv6 shared card related stuff */
580 dev->dev_id = real_dev->dev_id; 586 dev->dev_id = real_dev->dev_id;
@@ -589,7 +595,8 @@ static int vlan_dev_init(struct net_device *dev)
589#endif 595#endif
590 596
591 dev->needed_headroom = real_dev->needed_headroom; 597 dev->needed_headroom = real_dev->needed_headroom;
592 if (real_dev->features & NETIF_F_HW_VLAN_CTAG_TX) { 598 if (vlan_hw_offload_capable(real_dev->features,
599 vlan_dev_priv(dev)->vlan_proto)) {
593 dev->header_ops = &vlan_passthru_header_ops; 600 dev->header_ops = &vlan_passthru_header_ops;
594 dev->hard_header_len = real_dev->hard_header_len; 601 dev->hard_header_len = real_dev->hard_header_len;
595 } else { 602 } else {
diff --git a/net/9p/client.c b/net/9p/client.c
index a5e4d2dcb03e..9186550d77a6 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -204,7 +204,7 @@ free_and_return:
204 return ret; 204 return ret;
205} 205}
206 206
207struct p9_fcall *p9_fcall_alloc(int alloc_msize) 207static struct p9_fcall *p9_fcall_alloc(int alloc_msize)
208{ 208{
209 struct p9_fcall *fc; 209 struct p9_fcall *fc;
210 fc = kmalloc(sizeof(struct p9_fcall) + alloc_msize, GFP_NOFS); 210 fc = kmalloc(sizeof(struct p9_fcall) + alloc_msize, GFP_NOFS);
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index cd1e1ede73a4..ac2666c1d011 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -340,7 +340,10 @@ static int p9_get_mapped_pages(struct virtio_chan *chan,
340 int count = nr_pages; 340 int count = nr_pages;
341 while (nr_pages) { 341 while (nr_pages) {
342 s = rest_of_page(data); 342 s = rest_of_page(data);
343 pages[index++] = kmap_to_page(data); 343 if (is_vmalloc_addr(data))
344 pages[index++] = vmalloc_to_page(data);
345 else
346 pages[index++] = kmap_to_page(data);
344 data += s; 347 data += s;
345 nr_pages--; 348 nr_pages--;
346 } 349 }
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 512159bf607f..8323bced8e5b 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -241,19 +241,19 @@ batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const uint8_t *addr)
241 size = bat_priv->num_ifaces * sizeof(uint8_t); 241 size = bat_priv->num_ifaces * sizeof(uint8_t);
242 orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC); 242 orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC);
243 if (!orig_node->bat_iv.bcast_own_sum) 243 if (!orig_node->bat_iv.bcast_own_sum)
244 goto free_bcast_own; 244 goto free_orig_node;
245 245
246 hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig, 246 hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
247 batadv_choose_orig, orig_node, 247 batadv_choose_orig, orig_node,
248 &orig_node->hash_entry); 248 &orig_node->hash_entry);
249 if (hash_added != 0) 249 if (hash_added != 0)
250 goto free_bcast_own; 250 goto free_orig_node;
251 251
252 return orig_node; 252 return orig_node;
253 253
254free_bcast_own:
255 kfree(orig_node->bat_iv.bcast_own);
256free_orig_node: 254free_orig_node:
255 /* free twice, as batadv_orig_node_new sets refcount to 2 */
256 batadv_orig_node_free_ref(orig_node);
257 batadv_orig_node_free_ref(orig_node); 257 batadv_orig_node_free_ref(orig_node);
258 258
259 return NULL; 259 return NULL;
@@ -266,7 +266,7 @@ batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
266 struct batadv_orig_node *orig_neigh) 266 struct batadv_orig_node *orig_neigh)
267{ 267{
268 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 268 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
269 struct batadv_neigh_node *neigh_node; 269 struct batadv_neigh_node *neigh_node, *tmp_neigh_node;
270 270
271 neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr, orig_node); 271 neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr, orig_node);
272 if (!neigh_node) 272 if (!neigh_node)
@@ -281,14 +281,24 @@ batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
281 neigh_node->orig_node = orig_neigh; 281 neigh_node->orig_node = orig_neigh;
282 neigh_node->if_incoming = hard_iface; 282 neigh_node->if_incoming = hard_iface;
283 283
284 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
285 "Creating new neighbor %pM for orig_node %pM on interface %s\n",
286 neigh_addr, orig_node->orig, hard_iface->net_dev->name);
287
288 spin_lock_bh(&orig_node->neigh_list_lock); 284 spin_lock_bh(&orig_node->neigh_list_lock);
289 hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list); 285 tmp_neigh_node = batadv_neigh_node_get(orig_node, hard_iface,
286 neigh_addr);
287 if (!tmp_neigh_node) {
288 hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
289 } else {
290 kfree(neigh_node);
291 batadv_hardif_free_ref(hard_iface);
292 neigh_node = tmp_neigh_node;
293 }
290 spin_unlock_bh(&orig_node->neigh_list_lock); 294 spin_unlock_bh(&orig_node->neigh_list_lock);
291 295
296 if (!tmp_neigh_node)
297 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
298 "Creating new neighbor %pM for orig_node %pM on interface %s\n",
299 neigh_addr, orig_node->orig,
300 hard_iface->net_dev->name);
301
292out: 302out:
293 return neigh_node; 303 return neigh_node;
294} 304}
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 3d417d3641c6..b851cc580853 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -241,7 +241,7 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface)
241{ 241{
242 struct batadv_priv *bat_priv = netdev_priv(soft_iface); 242 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
243 const struct batadv_hard_iface *hard_iface; 243 const struct batadv_hard_iface *hard_iface;
244 int min_mtu = ETH_DATA_LEN; 244 int min_mtu = INT_MAX;
245 245
246 rcu_read_lock(); 246 rcu_read_lock();
247 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { 247 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
@@ -256,8 +256,6 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface)
256 } 256 }
257 rcu_read_unlock(); 257 rcu_read_unlock();
258 258
259 atomic_set(&bat_priv->packet_size_max, min_mtu);
260
261 if (atomic_read(&bat_priv->fragmentation) == 0) 259 if (atomic_read(&bat_priv->fragmentation) == 0)
262 goto out; 260 goto out;
263 261
@@ -268,13 +266,21 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface)
268 min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE); 266 min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE);
269 min_mtu -= sizeof(struct batadv_frag_packet); 267 min_mtu -= sizeof(struct batadv_frag_packet);
270 min_mtu *= BATADV_FRAG_MAX_FRAGMENTS; 268 min_mtu *= BATADV_FRAG_MAX_FRAGMENTS;
271 atomic_set(&bat_priv->packet_size_max, min_mtu);
272
273 /* with fragmentation enabled we can fragment external packets easily */
274 min_mtu = min_t(int, min_mtu, ETH_DATA_LEN);
275 269
276out: 270out:
277 return min_mtu - batadv_max_header_len(); 271 /* report to the other components the maximum amount of bytes that
272 * batman-adv can send over the wire (without considering the payload
273 * overhead). For example, this value is used by TT to compute the
274 * maximum local table table size
275 */
276 atomic_set(&bat_priv->packet_size_max, min_mtu);
277
278 /* the real soft-interface MTU is computed by removing the payload
279 * overhead from the maximum amount of bytes that was just computed.
280 *
281 * However batman-adv does not support MTUs bigger than ETH_DATA_LEN
282 */
283 return min_t(int, min_mtu - batadv_max_header_len(), ETH_DATA_LEN);
278} 284}
279 285
280/* adjusts the MTU if a new interface with a smaller MTU appeared. */ 286/* adjusts the MTU if a new interface with a smaller MTU appeared. */
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 6df12a2e3605..853941629dc1 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -458,6 +458,42 @@ out:
458} 458}
459 459
460/** 460/**
461 * batadv_neigh_node_get - retrieve a neighbour from the list
462 * @orig_node: originator which the neighbour belongs to
463 * @hard_iface: the interface where this neighbour is connected to
464 * @addr: the address of the neighbour
465 *
466 * Looks for and possibly returns a neighbour belonging to this originator list
467 * which is connected through the provided hard interface.
468 * Returns NULL if the neighbour is not found.
469 */
470struct batadv_neigh_node *
471batadv_neigh_node_get(const struct batadv_orig_node *orig_node,
472 const struct batadv_hard_iface *hard_iface,
473 const uint8_t *addr)
474{
475 struct batadv_neigh_node *tmp_neigh_node, *res = NULL;
476
477 rcu_read_lock();
478 hlist_for_each_entry_rcu(tmp_neigh_node, &orig_node->neigh_list, list) {
479 if (!batadv_compare_eth(tmp_neigh_node->addr, addr))
480 continue;
481
482 if (tmp_neigh_node->if_incoming != hard_iface)
483 continue;
484
485 if (!atomic_inc_not_zero(&tmp_neigh_node->refcount))
486 continue;
487
488 res = tmp_neigh_node;
489 break;
490 }
491 rcu_read_unlock();
492
493 return res;
494}
495
496/**
461 * batadv_orig_ifinfo_free_rcu - free the orig_ifinfo object 497 * batadv_orig_ifinfo_free_rcu - free the orig_ifinfo object
462 * @rcu: rcu pointer of the orig_ifinfo object 498 * @rcu: rcu pointer of the orig_ifinfo object
463 */ 499 */
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index 37be290f63f6..db3a9ed734cb 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -29,6 +29,10 @@ void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node);
29struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv, 29struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
30 const uint8_t *addr); 30 const uint8_t *addr);
31struct batadv_neigh_node * 31struct batadv_neigh_node *
32batadv_neigh_node_get(const struct batadv_orig_node *orig_node,
33 const struct batadv_hard_iface *hard_iface,
34 const uint8_t *addr);
35struct batadv_neigh_node *
32batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, 36batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
33 const uint8_t *neigh_addr, 37 const uint8_t *neigh_addr,
34 struct batadv_orig_node *orig_node); 38 struct batadv_orig_node *orig_node);
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 1ed9f7c9ecea..a953d5b196a3 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -688,7 +688,7 @@ static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
688 int is_old_ttvn; 688 int is_old_ttvn;
689 689
690 /* check if there is enough data before accessing it */ 690 /* check if there is enough data before accessing it */
691 if (pskb_may_pull(skb, hdr_len + ETH_HLEN) < 0) 691 if (!pskb_may_pull(skb, hdr_len + ETH_HLEN))
692 return 0; 692 return 0;
693 693
694 /* create a copy of the skb (in case of for re-routing) to modify it. */ 694 /* create a copy of the skb (in case of for re-routing) to modify it. */
@@ -918,6 +918,8 @@ int batadv_recv_unicast_tvlv(struct sk_buff *skb,
918 918
919 if (ret != NET_RX_SUCCESS) 919 if (ret != NET_RX_SUCCESS)
920 ret = batadv_route_unicast_packet(skb, recv_if); 920 ret = batadv_route_unicast_packet(skb, recv_if);
921 else
922 consume_skb(skb);
921 923
922 return ret; 924 return ret;
923} 925}
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 579f5f00a385..843febd1e519 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -254,9 +254,9 @@ static int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
254 struct batadv_orig_node *orig_node, 254 struct batadv_orig_node *orig_node,
255 unsigned short vid) 255 unsigned short vid)
256{ 256{
257 struct ethhdr *ethhdr = (struct ethhdr *)skb->data; 257 struct ethhdr *ethhdr;
258 struct batadv_unicast_packet *unicast_packet; 258 struct batadv_unicast_packet *unicast_packet;
259 int ret = NET_XMIT_DROP; 259 int ret = NET_XMIT_DROP, hdr_size;
260 260
261 if (!orig_node) 261 if (!orig_node)
262 goto out; 262 goto out;
@@ -265,12 +265,16 @@ static int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
265 case BATADV_UNICAST: 265 case BATADV_UNICAST:
266 if (!batadv_send_skb_prepare_unicast(skb, orig_node)) 266 if (!batadv_send_skb_prepare_unicast(skb, orig_node))
267 goto out; 267 goto out;
268
269 hdr_size = sizeof(*unicast_packet);
268 break; 270 break;
269 case BATADV_UNICAST_4ADDR: 271 case BATADV_UNICAST_4ADDR:
270 if (!batadv_send_skb_prepare_unicast_4addr(bat_priv, skb, 272 if (!batadv_send_skb_prepare_unicast_4addr(bat_priv, skb,
271 orig_node, 273 orig_node,
272 packet_subtype)) 274 packet_subtype))
273 goto out; 275 goto out;
276
277 hdr_size = sizeof(struct batadv_unicast_4addr_packet);
274 break; 278 break;
275 default: 279 default:
276 /* this function supports UNICAST and UNICAST_4ADDR only. It 280 /* this function supports UNICAST and UNICAST_4ADDR only. It
@@ -279,6 +283,7 @@ static int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
279 goto out; 283 goto out;
280 } 284 }
281 285
286 ethhdr = (struct ethhdr *)(skb->data + hdr_size);
282 unicast_packet = (struct batadv_unicast_packet *)skb->data; 287 unicast_packet = (struct batadv_unicast_packet *)skb->data;
283 288
284 /* inform the destination node that we are still missing a correct route 289 /* inform the destination node that we are still missing a correct route
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index b6071f675a3e..959dde721c46 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1975,6 +1975,7 @@ static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
1975 struct hlist_head *head; 1975 struct hlist_head *head;
1976 uint32_t i, crc_tmp, crc = 0; 1976 uint32_t i, crc_tmp, crc = 0;
1977 uint8_t flags; 1977 uint8_t flags;
1978 __be16 tmp_vid;
1978 1979
1979 for (i = 0; i < hash->size; i++) { 1980 for (i = 0; i < hash->size; i++) {
1980 head = &hash->table[i]; 1981 head = &hash->table[i];
@@ -2011,8 +2012,11 @@ static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
2011 orig_node)) 2012 orig_node))
2012 continue; 2013 continue;
2013 2014
2014 crc_tmp = crc32c(0, &tt_common->vid, 2015 /* use network order to read the VID: this ensures that
2015 sizeof(tt_common->vid)); 2016 * every node reads the bytes in the same order.
2017 */
2018 tmp_vid = htons(tt_common->vid);
2019 crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
2016 2020
2017 /* compute the CRC on flags that have to be kept in sync 2021 /* compute the CRC on flags that have to be kept in sync
2018 * among nodes 2022 * among nodes
@@ -2046,6 +2050,7 @@ static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv,
2046 struct hlist_head *head; 2050 struct hlist_head *head;
2047 uint32_t i, crc_tmp, crc = 0; 2051 uint32_t i, crc_tmp, crc = 0;
2048 uint8_t flags; 2052 uint8_t flags;
2053 __be16 tmp_vid;
2049 2054
2050 for (i = 0; i < hash->size; i++) { 2055 for (i = 0; i < hash->size; i++) {
2051 head = &hash->table[i]; 2056 head = &hash->table[i];
@@ -2064,8 +2069,11 @@ static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv,
2064 if (tt_common->flags & BATADV_TT_CLIENT_NEW) 2069 if (tt_common->flags & BATADV_TT_CLIENT_NEW)
2065 continue; 2070 continue;
2066 2071
2067 crc_tmp = crc32c(0, &tt_common->vid, 2072 /* use network order to read the VID: this ensures that
2068 sizeof(tt_common->vid)); 2073 * every node reads the bytes in the same order.
2074 */
2075 tmp_vid = htons(tt_common->vid);
2076 crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
2069 2077
2070 /* compute the CRC on flags that have to be kept in sync 2078 /* compute the CRC on flags that have to be kept in sync
2071 * among nodes 2079 * among nodes
@@ -2262,6 +2270,7 @@ static bool batadv_tt_global_check_crc(struct batadv_orig_node *orig_node,
2262{ 2270{
2263 struct batadv_tvlv_tt_vlan_data *tt_vlan_tmp; 2271 struct batadv_tvlv_tt_vlan_data *tt_vlan_tmp;
2264 struct batadv_orig_node_vlan *vlan; 2272 struct batadv_orig_node_vlan *vlan;
2273 uint32_t crc;
2265 int i; 2274 int i;
2266 2275
2267 /* check if each received CRC matches the locally stored one */ 2276 /* check if each received CRC matches the locally stored one */
@@ -2281,7 +2290,10 @@ static bool batadv_tt_global_check_crc(struct batadv_orig_node *orig_node,
2281 if (!vlan) 2290 if (!vlan)
2282 return false; 2291 return false;
2283 2292
2284 if (vlan->tt.crc != ntohl(tt_vlan_tmp->crc)) 2293 crc = vlan->tt.crc;
2294 batadv_orig_node_vlan_free_ref(vlan);
2295
2296 if (crc != ntohl(tt_vlan_tmp->crc))
2285 return false; 2297 return false;
2286 } 2298 }
2287 2299
@@ -3218,7 +3230,6 @@ static void batadv_tt_update_orig(struct batadv_priv *bat_priv,
3218 3230
3219 spin_lock_bh(&orig_node->tt_lock); 3231 spin_lock_bh(&orig_node->tt_lock);
3220 3232
3221 tt_change = (struct batadv_tvlv_tt_change *)tt_buff;
3222 batadv_tt_update_changes(bat_priv, orig_node, tt_num_changes, 3233 batadv_tt_update_changes(bat_priv, orig_node, tt_num_changes,
3223 ttvn, tt_change); 3234 ttvn, tt_change);
3224 3235
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 292e619db896..d9fb93451442 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -430,6 +430,16 @@ static void hidp_del_timer(struct hidp_session *session)
430 del_timer(&session->timer); 430 del_timer(&session->timer);
431} 431}
432 432
433static void hidp_process_report(struct hidp_session *session,
434 int type, const u8 *data, int len, int intr)
435{
436 if (len > HID_MAX_BUFFER_SIZE)
437 len = HID_MAX_BUFFER_SIZE;
438
439 memcpy(session->input_buf, data, len);
440 hid_input_report(session->hid, type, session->input_buf, len, intr);
441}
442
433static void hidp_process_handshake(struct hidp_session *session, 443static void hidp_process_handshake(struct hidp_session *session,
434 unsigned char param) 444 unsigned char param)
435{ 445{
@@ -502,7 +512,8 @@ static int hidp_process_data(struct hidp_session *session, struct sk_buff *skb,
502 hidp_input_report(session, skb); 512 hidp_input_report(session, skb);
503 513
504 if (session->hid) 514 if (session->hid)
505 hid_input_report(session->hid, HID_INPUT_REPORT, skb->data, skb->len, 0); 515 hidp_process_report(session, HID_INPUT_REPORT,
516 skb->data, skb->len, 0);
506 break; 517 break;
507 518
508 case HIDP_DATA_RTYPE_OTHER: 519 case HIDP_DATA_RTYPE_OTHER:
@@ -584,7 +595,8 @@ static void hidp_recv_intr_frame(struct hidp_session *session,
584 hidp_input_report(session, skb); 595 hidp_input_report(session, skb);
585 596
586 if (session->hid) { 597 if (session->hid) {
587 hid_input_report(session->hid, HID_INPUT_REPORT, skb->data, skb->len, 1); 598 hidp_process_report(session, HID_INPUT_REPORT,
599 skb->data, skb->len, 1);
588 BT_DBG("report len %d", skb->len); 600 BT_DBG("report len %d", skb->len);
589 } 601 }
590 } else { 602 } else {
diff --git a/net/bluetooth/hidp/hidp.h b/net/bluetooth/hidp/hidp.h
index ab5241400cf7..8798492a6e99 100644
--- a/net/bluetooth/hidp/hidp.h
+++ b/net/bluetooth/hidp/hidp.h
@@ -24,6 +24,7 @@
24#define __HIDP_H 24#define __HIDP_H
25 25
26#include <linux/types.h> 26#include <linux/types.h>
27#include <linux/hid.h>
27#include <linux/kref.h> 28#include <linux/kref.h>
28#include <net/bluetooth/bluetooth.h> 29#include <net/bluetooth/bluetooth.h>
29#include <net/bluetooth/l2cap.h> 30#include <net/bluetooth/l2cap.h>
@@ -179,6 +180,9 @@ struct hidp_session {
179 180
180 /* Used in hidp_output_raw_report() */ 181 /* Used in hidp_output_raw_report() */
181 int output_report_success; /* boolean */ 182 int output_report_success; /* boolean */
183
184 /* temporary input buffer */
185 u8 input_buf[HID_MAX_BUFFER_SIZE];
182}; 186};
183 187
184/* HIDP init defines */ 188/* HIDP init defines */
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index e4401a531afb..8fe8b71b487a 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -49,14 +49,14 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
49 brstats->tx_bytes += skb->len; 49 brstats->tx_bytes += skb->len;
50 u64_stats_update_end(&brstats->syncp); 50 u64_stats_update_end(&brstats->syncp);
51 51
52 if (!br_allowed_ingress(br, br_get_vlan_info(br), skb, &vid))
53 goto out;
54
55 BR_INPUT_SKB_CB(skb)->brdev = dev; 52 BR_INPUT_SKB_CB(skb)->brdev = dev;
56 53
57 skb_reset_mac_header(skb); 54 skb_reset_mac_header(skb);
58 skb_pull(skb, ETH_HLEN); 55 skb_pull(skb, ETH_HLEN);
59 56
57 if (!br_allowed_ingress(br, br_get_vlan_info(br), skb, &vid))
58 goto out;
59
60 if (is_broadcast_ether_addr(dest)) 60 if (is_broadcast_ether_addr(dest))
61 br_flood_deliver(br, skb, false); 61 br_flood_deliver(br, skb, false);
62 else if (is_multicast_ether_addr(dest)) { 62 else if (is_multicast_ether_addr(dest)) {
@@ -187,8 +187,7 @@ static int br_set_mac_address(struct net_device *dev, void *p)
187 187
188 spin_lock_bh(&br->lock); 188 spin_lock_bh(&br->lock);
189 if (!ether_addr_equal(dev->dev_addr, addr->sa_data)) { 189 if (!ether_addr_equal(dev->dev_addr, addr->sa_data)) {
190 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); 190 /* Mac address will be changed in br_stp_change_bridge_id(). */
191 br_fdb_change_mac_address(br, addr->sa_data);
192 br_stp_change_bridge_id(br, addr->sa_data); 191 br_stp_change_bridge_id(br, addr->sa_data);
193 } 192 }
194 spin_unlock_bh(&br->lock); 193 spin_unlock_bh(&br->lock);
@@ -226,6 +225,33 @@ static void br_netpoll_cleanup(struct net_device *dev)
226 br_netpoll_disable(p); 225 br_netpoll_disable(p);
227} 226}
228 227
228static int __br_netpoll_enable(struct net_bridge_port *p, gfp_t gfp)
229{
230 struct netpoll *np;
231 int err;
232
233 np = kzalloc(sizeof(*p->np), gfp);
234 if (!np)
235 return -ENOMEM;
236
237 err = __netpoll_setup(np, p->dev, gfp);
238 if (err) {
239 kfree(np);
240 return err;
241 }
242
243 p->np = np;
244 return err;
245}
246
247int br_netpoll_enable(struct net_bridge_port *p, gfp_t gfp)
248{
249 if (!p->br->dev->npinfo)
250 return 0;
251
252 return __br_netpoll_enable(p, gfp);
253}
254
229static int br_netpoll_setup(struct net_device *dev, struct netpoll_info *ni, 255static int br_netpoll_setup(struct net_device *dev, struct netpoll_info *ni,
230 gfp_t gfp) 256 gfp_t gfp)
231{ 257{
@@ -236,7 +262,7 @@ static int br_netpoll_setup(struct net_device *dev, struct netpoll_info *ni,
236 list_for_each_entry(p, &br->port_list, list) { 262 list_for_each_entry(p, &br->port_list, list) {
237 if (!p->dev) 263 if (!p->dev)
238 continue; 264 continue;
239 err = br_netpoll_enable(p, gfp); 265 err = __br_netpoll_enable(p, gfp);
240 if (err) 266 if (err)
241 goto fail; 267 goto fail;
242 } 268 }
@@ -249,28 +275,6 @@ fail:
249 goto out; 275 goto out;
250} 276}
251 277
252int br_netpoll_enable(struct net_bridge_port *p, gfp_t gfp)
253{
254 struct netpoll *np;
255 int err;
256
257 if (!p->br->dev->npinfo)
258 return 0;
259
260 np = kzalloc(sizeof(*p->np), gfp);
261 if (!np)
262 return -ENOMEM;
263
264 err = __netpoll_setup(np, p->dev, gfp);
265 if (err) {
266 kfree(np);
267 return err;
268 }
269
270 p->np = np;
271 return err;
272}
273
274void br_netpoll_disable(struct net_bridge_port *p) 278void br_netpoll_disable(struct net_bridge_port *p)
275{ 279{
276 struct netpoll *np = p->np; 280 struct netpoll *np = p->np;
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index c5f5a4a933f4..9203d5a1943f 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -27,6 +27,9 @@
27#include "br_private.h" 27#include "br_private.h"
28 28
29static struct kmem_cache *br_fdb_cache __read_mostly; 29static struct kmem_cache *br_fdb_cache __read_mostly;
30static struct net_bridge_fdb_entry *fdb_find(struct hlist_head *head,
31 const unsigned char *addr,
32 __u16 vid);
30static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source, 33static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
31 const unsigned char *addr, u16 vid); 34 const unsigned char *addr, u16 vid);
32static void fdb_notify(struct net_bridge *br, 35static void fdb_notify(struct net_bridge *br,
@@ -89,11 +92,57 @@ static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f)
89 call_rcu(&f->rcu, fdb_rcu_free); 92 call_rcu(&f->rcu, fdb_rcu_free);
90} 93}
91 94
95/* Delete a local entry if no other port had the same address. */
96static void fdb_delete_local(struct net_bridge *br,
97 const struct net_bridge_port *p,
98 struct net_bridge_fdb_entry *f)
99{
100 const unsigned char *addr = f->addr.addr;
101 u16 vid = f->vlan_id;
102 struct net_bridge_port *op;
103
104 /* Maybe another port has same hw addr? */
105 list_for_each_entry(op, &br->port_list, list) {
106 if (op != p && ether_addr_equal(op->dev->dev_addr, addr) &&
107 (!vid || nbp_vlan_find(op, vid))) {
108 f->dst = op;
109 f->added_by_user = 0;
110 return;
111 }
112 }
113
114 /* Maybe bridge device has same hw addr? */
115 if (p && ether_addr_equal(br->dev->dev_addr, addr) &&
116 (!vid || br_vlan_find(br, vid))) {
117 f->dst = NULL;
118 f->added_by_user = 0;
119 return;
120 }
121
122 fdb_delete(br, f);
123}
124
125void br_fdb_find_delete_local(struct net_bridge *br,
126 const struct net_bridge_port *p,
127 const unsigned char *addr, u16 vid)
128{
129 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
130 struct net_bridge_fdb_entry *f;
131
132 spin_lock_bh(&br->hash_lock);
133 f = fdb_find(head, addr, vid);
134 if (f && f->is_local && !f->added_by_user && f->dst == p)
135 fdb_delete_local(br, p, f);
136 spin_unlock_bh(&br->hash_lock);
137}
138
92void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr) 139void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
93{ 140{
94 struct net_bridge *br = p->br; 141 struct net_bridge *br = p->br;
95 bool no_vlan = (nbp_get_vlan_info(p) == NULL) ? true : false; 142 struct net_port_vlans *pv = nbp_get_vlan_info(p);
143 bool no_vlan = !pv;
96 int i; 144 int i;
145 u16 vid;
97 146
98 spin_lock_bh(&br->hash_lock); 147 spin_lock_bh(&br->hash_lock);
99 148
@@ -104,38 +153,34 @@ void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
104 struct net_bridge_fdb_entry *f; 153 struct net_bridge_fdb_entry *f;
105 154
106 f = hlist_entry(h, struct net_bridge_fdb_entry, hlist); 155 f = hlist_entry(h, struct net_bridge_fdb_entry, hlist);
107 if (f->dst == p && f->is_local) { 156 if (f->dst == p && f->is_local && !f->added_by_user) {
108 /* maybe another port has same hw addr? */
109 struct net_bridge_port *op;
110 u16 vid = f->vlan_id;
111 list_for_each_entry(op, &br->port_list, list) {
112 if (op != p &&
113 ether_addr_equal(op->dev->dev_addr,
114 f->addr.addr) &&
115 nbp_vlan_find(op, vid)) {
116 f->dst = op;
117 goto insert;
118 }
119 }
120
121 /* delete old one */ 157 /* delete old one */
122 fdb_delete(br, f); 158 fdb_delete_local(br, p, f);
123insert:
124 /* insert new address, may fail if invalid
125 * address or dup.
126 */
127 fdb_insert(br, p, newaddr, vid);
128 159
129 /* if this port has no vlan information 160 /* if this port has no vlan information
130 * configured, we can safely be done at 161 * configured, we can safely be done at
131 * this point. 162 * this point.
132 */ 163 */
133 if (no_vlan) 164 if (no_vlan)
134 goto done; 165 goto insert;
135 } 166 }
136 } 167 }
137 } 168 }
138 169
170insert:
171 /* insert new address, may fail if invalid address or dup. */
172 fdb_insert(br, p, newaddr, 0);
173
174 if (no_vlan)
175 goto done;
176
177 /* Now add entries for every VLAN configured on the port.
178 * This function runs under RTNL so the bitmap will not change
179 * from under us.
180 */
181 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID)
182 fdb_insert(br, p, newaddr, vid);
183
139done: 184done:
140 spin_unlock_bh(&br->hash_lock); 185 spin_unlock_bh(&br->hash_lock);
141} 186}
@@ -146,10 +191,12 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
146 struct net_port_vlans *pv; 191 struct net_port_vlans *pv;
147 u16 vid = 0; 192 u16 vid = 0;
148 193
194 spin_lock_bh(&br->hash_lock);
195
149 /* If old entry was unassociated with any port, then delete it. */ 196 /* If old entry was unassociated with any port, then delete it. */
150 f = __br_fdb_get(br, br->dev->dev_addr, 0); 197 f = __br_fdb_get(br, br->dev->dev_addr, 0);
151 if (f && f->is_local && !f->dst) 198 if (f && f->is_local && !f->dst)
152 fdb_delete(br, f); 199 fdb_delete_local(br, NULL, f);
153 200
154 fdb_insert(br, NULL, newaddr, 0); 201 fdb_insert(br, NULL, newaddr, 0);
155 202
@@ -159,14 +206,16 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
159 */ 206 */
160 pv = br_get_vlan_info(br); 207 pv = br_get_vlan_info(br);
161 if (!pv) 208 if (!pv)
162 return; 209 goto out;
163 210
164 for_each_set_bit_from(vid, pv->vlan_bitmap, VLAN_N_VID) { 211 for_each_set_bit_from(vid, pv->vlan_bitmap, VLAN_N_VID) {
165 f = __br_fdb_get(br, br->dev->dev_addr, vid); 212 f = __br_fdb_get(br, br->dev->dev_addr, vid);
166 if (f && f->is_local && !f->dst) 213 if (f && f->is_local && !f->dst)
167 fdb_delete(br, f); 214 fdb_delete_local(br, NULL, f);
168 fdb_insert(br, NULL, newaddr, vid); 215 fdb_insert(br, NULL, newaddr, vid);
169 } 216 }
217out:
218 spin_unlock_bh(&br->hash_lock);
170} 219}
171 220
172void br_fdb_cleanup(unsigned long _data) 221void br_fdb_cleanup(unsigned long _data)
@@ -235,25 +284,11 @@ void br_fdb_delete_by_port(struct net_bridge *br,
235 284
236 if (f->is_static && !do_all) 285 if (f->is_static && !do_all)
237 continue; 286 continue;
238 /*
239 * if multiple ports all have the same device address
240 * then when one port is deleted, assign
241 * the local entry to other port
242 */
243 if (f->is_local) {
244 struct net_bridge_port *op;
245 list_for_each_entry(op, &br->port_list, list) {
246 if (op != p &&
247 ether_addr_equal(op->dev->dev_addr,
248 f->addr.addr)) {
249 f->dst = op;
250 goto skip_delete;
251 }
252 }
253 }
254 287
255 fdb_delete(br, f); 288 if (f->is_local)
256 skip_delete: ; 289 fdb_delete_local(br, p, f);
290 else
291 fdb_delete(br, f);
257 } 292 }
258 } 293 }
259 spin_unlock_bh(&br->hash_lock); 294 spin_unlock_bh(&br->hash_lock);
@@ -397,6 +432,7 @@ static struct net_bridge_fdb_entry *fdb_create(struct hlist_head *head,
397 fdb->vlan_id = vid; 432 fdb->vlan_id = vid;
398 fdb->is_local = 0; 433 fdb->is_local = 0;
399 fdb->is_static = 0; 434 fdb->is_static = 0;
435 fdb->added_by_user = 0;
400 fdb->updated = fdb->used = jiffies; 436 fdb->updated = fdb->used = jiffies;
401 hlist_add_head_rcu(&fdb->hlist, head); 437 hlist_add_head_rcu(&fdb->hlist, head);
402 } 438 }
@@ -447,7 +483,7 @@ int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
447} 483}
448 484
449void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, 485void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
450 const unsigned char *addr, u16 vid) 486 const unsigned char *addr, u16 vid, bool added_by_user)
451{ 487{
452 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)]; 488 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
453 struct net_bridge_fdb_entry *fdb; 489 struct net_bridge_fdb_entry *fdb;
@@ -473,13 +509,18 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
473 /* fastpath: update of existing entry */ 509 /* fastpath: update of existing entry */
474 fdb->dst = source; 510 fdb->dst = source;
475 fdb->updated = jiffies; 511 fdb->updated = jiffies;
512 if (unlikely(added_by_user))
513 fdb->added_by_user = 1;
476 } 514 }
477 } else { 515 } else {
478 spin_lock(&br->hash_lock); 516 spin_lock(&br->hash_lock);
479 if (likely(!fdb_find(head, addr, vid))) { 517 if (likely(!fdb_find(head, addr, vid))) {
480 fdb = fdb_create(head, source, addr, vid); 518 fdb = fdb_create(head, source, addr, vid);
481 if (fdb) 519 if (fdb) {
520 if (unlikely(added_by_user))
521 fdb->added_by_user = 1;
482 fdb_notify(br, fdb, RTM_NEWNEIGH); 522 fdb_notify(br, fdb, RTM_NEWNEIGH);
523 }
483 } 524 }
484 /* else we lose race and someone else inserts 525 /* else we lose race and someone else inserts
485 * it first, don't bother updating 526 * it first, don't bother updating
@@ -647,6 +688,7 @@ static int fdb_add_entry(struct net_bridge_port *source, const __u8 *addr,
647 688
648 modified = true; 689 modified = true;
649 } 690 }
691 fdb->added_by_user = 1;
650 692
651 fdb->used = jiffies; 693 fdb->used = jiffies;
652 if (modified) { 694 if (modified) {
@@ -664,7 +706,7 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge_port *p,
664 706
665 if (ndm->ndm_flags & NTF_USE) { 707 if (ndm->ndm_flags & NTF_USE) {
666 rcu_read_lock(); 708 rcu_read_lock();
667 br_fdb_update(p->br, p, addr, vid); 709 br_fdb_update(p->br, p, addr, vid, true);
668 rcu_read_unlock(); 710 rcu_read_unlock();
669 } else { 711 } else {
670 spin_lock_bh(&p->br->hash_lock); 712 spin_lock_bh(&p->br->hash_lock);
@@ -749,8 +791,7 @@ out:
749 return err; 791 return err;
750} 792}
751 793
752int fdb_delete_by_addr(struct net_bridge *br, const u8 *addr, 794static int fdb_delete_by_addr(struct net_bridge *br, const u8 *addr, u16 vlan)
753 u16 vlan)
754{ 795{
755 struct hlist_head *head = &br->hash[br_mac_hash(addr, vlan)]; 796 struct hlist_head *head = &br->hash[br_mac_hash(addr, vlan)];
756 struct net_bridge_fdb_entry *fdb; 797 struct net_bridge_fdb_entry *fdb;
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index cffe1d666ba1..54d207d3a31c 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -389,6 +389,9 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
389 if (br->dev->needed_headroom < dev->needed_headroom) 389 if (br->dev->needed_headroom < dev->needed_headroom)
390 br->dev->needed_headroom = dev->needed_headroom; 390 br->dev->needed_headroom = dev->needed_headroom;
391 391
392 if (br_fdb_insert(br, p, dev->dev_addr, 0))
393 netdev_err(dev, "failed insert local address bridge forwarding table\n");
394
392 spin_lock_bh(&br->lock); 395 spin_lock_bh(&br->lock);
393 changed_addr = br_stp_recalculate_bridge_id(br); 396 changed_addr = br_stp_recalculate_bridge_id(br);
394 397
@@ -404,9 +407,6 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
404 407
405 dev_set_mtu(br->dev, br_min_mtu(br)); 408 dev_set_mtu(br->dev, br_min_mtu(br));
406 409
407 if (br_fdb_insert(br, p, dev->dev_addr, 0))
408 netdev_err(dev, "failed insert local address bridge forwarding table\n");
409
410 kobject_uevent(&p->kobj, KOBJ_ADD); 410 kobject_uevent(&p->kobj, KOBJ_ADD);
411 411
412 return 0; 412 return 0;
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index bf8dc7d308d6..d0cca3c65f01 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -29,6 +29,7 @@ static int br_pass_frame_up(struct sk_buff *skb)
29 struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev; 29 struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev;
30 struct net_bridge *br = netdev_priv(brdev); 30 struct net_bridge *br = netdev_priv(brdev);
31 struct pcpu_sw_netstats *brstats = this_cpu_ptr(br->stats); 31 struct pcpu_sw_netstats *brstats = this_cpu_ptr(br->stats);
32 struct net_port_vlans *pv;
32 33
33 u64_stats_update_begin(&brstats->syncp); 34 u64_stats_update_begin(&brstats->syncp);
34 brstats->rx_packets++; 35 brstats->rx_packets++;
@@ -39,18 +40,18 @@ static int br_pass_frame_up(struct sk_buff *skb)
39 * packet is allowed except in promisc modue when someone 40 * packet is allowed except in promisc modue when someone
40 * may be running packet capture. 41 * may be running packet capture.
41 */ 42 */
43 pv = br_get_vlan_info(br);
42 if (!(brdev->flags & IFF_PROMISC) && 44 if (!(brdev->flags & IFF_PROMISC) &&
43 !br_allowed_egress(br, br_get_vlan_info(br), skb)) { 45 !br_allowed_egress(br, pv, skb)) {
44 kfree_skb(skb); 46 kfree_skb(skb);
45 return NET_RX_DROP; 47 return NET_RX_DROP;
46 } 48 }
47 49
48 skb = br_handle_vlan(br, br_get_vlan_info(br), skb);
49 if (!skb)
50 return NET_RX_DROP;
51
52 indev = skb->dev; 50 indev = skb->dev;
53 skb->dev = brdev; 51 skb->dev = brdev;
52 skb = br_handle_vlan(br, pv, skb);
53 if (!skb)
54 return NET_RX_DROP;
54 55
55 return NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL, 56 return NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
56 netif_receive_skb); 57 netif_receive_skb);
@@ -77,7 +78,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
77 /* insert into forwarding database after filtering to avoid spoofing */ 78 /* insert into forwarding database after filtering to avoid spoofing */
78 br = p->br; 79 br = p->br;
79 if (p->flags & BR_LEARNING) 80 if (p->flags & BR_LEARNING)
80 br_fdb_update(br, p, eth_hdr(skb)->h_source, vid); 81 br_fdb_update(br, p, eth_hdr(skb)->h_source, vid, false);
81 82
82 if (!is_broadcast_ether_addr(dest) && is_multicast_ether_addr(dest) && 83 if (!is_broadcast_ether_addr(dest) && is_multicast_ether_addr(dest) &&
83 br_multicast_rcv(br, p, skb, vid)) 84 br_multicast_rcv(br, p, skb, vid))
@@ -148,7 +149,7 @@ static int br_handle_local_finish(struct sk_buff *skb)
148 149
149 br_vlan_get_tag(skb, &vid); 150 br_vlan_get_tag(skb, &vid);
150 if (p->flags & BR_LEARNING) 151 if (p->flags & BR_LEARNING)
151 br_fdb_update(p->br, p, eth_hdr(skb)->h_source, vid); 152 br_fdb_update(p->br, p, eth_hdr(skb)->h_source, vid, false);
152 return 0; /* process further */ 153 return 0; /* process further */
153} 154}
154 155
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index ef66365b7354..93067ecdb9a2 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -1127,9 +1127,10 @@ static void br_multicast_query_received(struct net_bridge *br,
1127 struct net_bridge_port *port, 1127 struct net_bridge_port *port,
1128 struct bridge_mcast_querier *querier, 1128 struct bridge_mcast_querier *querier,
1129 int saddr, 1129 int saddr,
1130 bool is_general_query,
1130 unsigned long max_delay) 1131 unsigned long max_delay)
1131{ 1132{
1132 if (saddr) 1133 if (saddr && is_general_query)
1133 br_multicast_update_querier_timer(br, querier, max_delay); 1134 br_multicast_update_querier_timer(br, querier, max_delay);
1134 else if (timer_pending(&querier->timer)) 1135 else if (timer_pending(&querier->timer))
1135 return; 1136 return;
@@ -1181,8 +1182,16 @@ static int br_ip4_multicast_query(struct net_bridge *br,
1181 IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1; 1182 IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1;
1182 } 1183 }
1183 1184
1185 /* RFC2236+RFC3376 (IGMPv2+IGMPv3) require the multicast link layer
1186 * all-systems destination addresses (224.0.0.1) for general queries
1187 */
1188 if (!group && iph->daddr != htonl(INADDR_ALLHOSTS_GROUP)) {
1189 err = -EINVAL;
1190 goto out;
1191 }
1192
1184 br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr, 1193 br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr,
1185 max_delay); 1194 !group, max_delay);
1186 1195
1187 if (!group) 1196 if (!group)
1188 goto out; 1197 goto out;
@@ -1228,6 +1237,7 @@ static int br_ip6_multicast_query(struct net_bridge *br,
1228 unsigned long max_delay; 1237 unsigned long max_delay;
1229 unsigned long now = jiffies; 1238 unsigned long now = jiffies;
1230 const struct in6_addr *group = NULL; 1239 const struct in6_addr *group = NULL;
1240 bool is_general_query;
1231 int err = 0; 1241 int err = 0;
1232 1242
1233 spin_lock(&br->multicast_lock); 1243 spin_lock(&br->multicast_lock);
@@ -1235,6 +1245,12 @@ static int br_ip6_multicast_query(struct net_bridge *br,
1235 (port && port->state == BR_STATE_DISABLED)) 1245 (port && port->state == BR_STATE_DISABLED))
1236 goto out; 1246 goto out;
1237 1247
1248 /* RFC2710+RFC3810 (MLDv1+MLDv2) require link-local source addresses */
1249 if (!(ipv6_addr_type(&ip6h->saddr) & IPV6_ADDR_LINKLOCAL)) {
1250 err = -EINVAL;
1251 goto out;
1252 }
1253
1238 if (skb->len == sizeof(*mld)) { 1254 if (skb->len == sizeof(*mld)) {
1239 if (!pskb_may_pull(skb, sizeof(*mld))) { 1255 if (!pskb_may_pull(skb, sizeof(*mld))) {
1240 err = -EINVAL; 1256 err = -EINVAL;
@@ -1256,8 +1272,19 @@ static int br_ip6_multicast_query(struct net_bridge *br,
1256 max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL); 1272 max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL);
1257 } 1273 }
1258 1274
1275 is_general_query = group && ipv6_addr_any(group);
1276
1277 /* RFC2710+RFC3810 (MLDv1+MLDv2) require the multicast link layer
1278 * all-nodes destination address (ff02::1) for general queries
1279 */
1280 if (is_general_query && !ipv6_addr_is_ll_all_nodes(&ip6h->daddr)) {
1281 err = -EINVAL;
1282 goto out;
1283 }
1284
1259 br_multicast_query_received(br, port, &br->ip6_querier, 1285 br_multicast_query_received(br, port, &br->ip6_querier,
1260 !ipv6_addr_any(&ip6h->saddr), max_delay); 1286 !ipv6_addr_any(&ip6h->saddr),
1287 is_general_query, max_delay);
1261 1288
1262 if (!group) 1289 if (!group)
1263 goto out; 1290 goto out;
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index fcd12333c59b..3ba11bc99b65 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -104,6 +104,7 @@ struct net_bridge_fdb_entry
104 mac_addr addr; 104 mac_addr addr;
105 unsigned char is_local; 105 unsigned char is_local;
106 unsigned char is_static; 106 unsigned char is_static;
107 unsigned char added_by_user;
107 __u16 vlan_id; 108 __u16 vlan_id;
108}; 109};
109 110
@@ -370,6 +371,9 @@ static inline void br_netpoll_disable(struct net_bridge_port *p)
370int br_fdb_init(void); 371int br_fdb_init(void);
371void br_fdb_fini(void); 372void br_fdb_fini(void);
372void br_fdb_flush(struct net_bridge *br); 373void br_fdb_flush(struct net_bridge *br);
374void br_fdb_find_delete_local(struct net_bridge *br,
375 const struct net_bridge_port *p,
376 const unsigned char *addr, u16 vid);
373void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr); 377void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
374void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr); 378void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
375void br_fdb_cleanup(unsigned long arg); 379void br_fdb_cleanup(unsigned long arg);
@@ -383,8 +387,7 @@ int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
383int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source, 387int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
384 const unsigned char *addr, u16 vid); 388 const unsigned char *addr, u16 vid);
385void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, 389void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
386 const unsigned char *addr, u16 vid); 390 const unsigned char *addr, u16 vid, bool added_by_user);
387int fdb_delete_by_addr(struct net_bridge *br, const u8 *addr, u16 vid);
388 391
389int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], 392int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
390 struct net_device *dev, const unsigned char *addr); 393 struct net_device *dev, const unsigned char *addr);
@@ -584,6 +587,7 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
584int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags); 587int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags);
585int br_vlan_delete(struct net_bridge *br, u16 vid); 588int br_vlan_delete(struct net_bridge *br, u16 vid);
586void br_vlan_flush(struct net_bridge *br); 589void br_vlan_flush(struct net_bridge *br);
590bool br_vlan_find(struct net_bridge *br, u16 vid);
587int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); 591int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
588int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags); 592int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags);
589int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); 593int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
@@ -665,6 +669,11 @@ static inline void br_vlan_flush(struct net_bridge *br)
665{ 669{
666} 670}
667 671
672static inline bool br_vlan_find(struct net_bridge *br, u16 vid)
673{
674 return false;
675}
676
668static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags) 677static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
669{ 678{
670 return -EOPNOTSUPP; 679 return -EOPNOTSUPP;
diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
index 656a6f3e40de..189ba1e7d851 100644
--- a/net/bridge/br_stp_if.c
+++ b/net/bridge/br_stp_if.c
@@ -194,6 +194,8 @@ void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *addr)
194 194
195 wasroot = br_is_root_bridge(br); 195 wasroot = br_is_root_bridge(br);
196 196
197 br_fdb_change_mac_address(br, addr);
198
197 memcpy(oldaddr, br->bridge_id.addr, ETH_ALEN); 199 memcpy(oldaddr, br->bridge_id.addr, ETH_ALEN);
198 memcpy(br->bridge_id.addr, addr, ETH_ALEN); 200 memcpy(br->bridge_id.addr, addr, ETH_ALEN);
199 memcpy(br->dev->dev_addr, addr, ETH_ALEN); 201 memcpy(br->dev->dev_addr, addr, ETH_ALEN);
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 4ca4d0a0151c..f23c74b3a953 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -119,22 +119,6 @@ static void __vlan_flush(struct net_port_vlans *v)
119 kfree_rcu(v, rcu); 119 kfree_rcu(v, rcu);
120} 120}
121 121
122/* Strip the tag from the packet. Will return skb with tci set 0. */
123static struct sk_buff *br_vlan_untag(struct sk_buff *skb)
124{
125 if (skb->protocol != htons(ETH_P_8021Q)) {
126 skb->vlan_tci = 0;
127 return skb;
128 }
129
130 skb->vlan_tci = 0;
131 skb = vlan_untag(skb);
132 if (skb)
133 skb->vlan_tci = 0;
134
135 return skb;
136}
137
138struct sk_buff *br_handle_vlan(struct net_bridge *br, 122struct sk_buff *br_handle_vlan(struct net_bridge *br,
139 const struct net_port_vlans *pv, 123 const struct net_port_vlans *pv,
140 struct sk_buff *skb) 124 struct sk_buff *skb)
@@ -144,13 +128,27 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
144 if (!br->vlan_enabled) 128 if (!br->vlan_enabled)
145 goto out; 129 goto out;
146 130
131 /* Vlan filter table must be configured at this point. The
132 * only exception is the bridge is set in promisc mode and the
133 * packet is destined for the bridge device. In this case
134 * pass the packet as is.
135 */
136 if (!pv) {
137 if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev) {
138 goto out;
139 } else {
140 kfree_skb(skb);
141 return NULL;
142 }
143 }
144
147 /* At this point, we know that the frame was filtered and contains 145 /* At this point, we know that the frame was filtered and contains
148 * a valid vlan id. If the vlan id is set in the untagged bitmap, 146 * a valid vlan id. If the vlan id is set in the untagged bitmap,
149 * send untagged; otherwise, send tagged. 147 * send untagged; otherwise, send tagged.
150 */ 148 */
151 br_vlan_get_tag(skb, &vid); 149 br_vlan_get_tag(skb, &vid);
152 if (test_bit(vid, pv->untagged_bitmap)) 150 if (test_bit(vid, pv->untagged_bitmap))
153 skb = br_vlan_untag(skb); 151 skb->vlan_tci = 0;
154 152
155out: 153out:
156 return skb; 154 return skb;
@@ -174,6 +172,18 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
174 if (!v) 172 if (!v)
175 return false; 173 return false;
176 174
175 /* If vlan tx offload is disabled on bridge device and frame was
176 * sent from vlan device on the bridge device, it does not have
177 * HW accelerated vlan tag.
178 */
179 if (unlikely(!vlan_tx_tag_present(skb) &&
180 (skb->protocol == htons(ETH_P_8021Q) ||
181 skb->protocol == htons(ETH_P_8021AD)))) {
182 skb = vlan_untag(skb);
183 if (unlikely(!skb))
184 return false;
185 }
186
177 err = br_vlan_get_tag(skb, vid); 187 err = br_vlan_get_tag(skb, vid);
178 if (!*vid) { 188 if (!*vid) {
179 u16 pvid = br_get_pvid(v); 189 u16 pvid = br_get_pvid(v);
@@ -275,9 +285,7 @@ int br_vlan_delete(struct net_bridge *br, u16 vid)
275 if (!pv) 285 if (!pv)
276 return -EINVAL; 286 return -EINVAL;
277 287
278 spin_lock_bh(&br->hash_lock); 288 br_fdb_find_delete_local(br, NULL, br->dev->dev_addr, vid);
279 fdb_delete_by_addr(br, br->dev->dev_addr, vid);
280 spin_unlock_bh(&br->hash_lock);
281 289
282 __vlan_del(pv, vid); 290 __vlan_del(pv, vid);
283 return 0; 291 return 0;
@@ -295,6 +303,25 @@ void br_vlan_flush(struct net_bridge *br)
295 __vlan_flush(pv); 303 __vlan_flush(pv);
296} 304}
297 305
306bool br_vlan_find(struct net_bridge *br, u16 vid)
307{
308 struct net_port_vlans *pv;
309 bool found = false;
310
311 rcu_read_lock();
312 pv = rcu_dereference(br->vlan_info);
313
314 if (!pv)
315 goto out;
316
317 if (test_bit(vid, pv->vlan_bitmap))
318 found = true;
319
320out:
321 rcu_read_unlock();
322 return found;
323}
324
298int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val) 325int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
299{ 326{
300 if (!rtnl_trylock()) 327 if (!rtnl_trylock())
@@ -359,9 +386,7 @@ int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
359 if (!pv) 386 if (!pv)
360 return -EINVAL; 387 return -EINVAL;
361 388
362 spin_lock_bh(&port->br->hash_lock); 389 br_fdb_find_delete_local(port->br, port, port->dev->dev_addr, vid);
363 fdb_delete_by_addr(port->br, port->dev->dev_addr, vid);
364 spin_unlock_bh(&port->br->hash_lock);
365 390
366 return __vlan_del(pv, vid); 391 return __vlan_del(pv, vid);
367} 392}
diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c
index 4dca159435cf..edbca468fa73 100644
--- a/net/caif/caif_dev.c
+++ b/net/caif/caif_dev.c
@@ -22,6 +22,7 @@
22#include <net/pkt_sched.h> 22#include <net/pkt_sched.h>
23#include <net/caif/caif_device.h> 23#include <net/caif/caif_device.h>
24#include <net/caif/caif_layer.h> 24#include <net/caif/caif_layer.h>
25#include <net/caif/caif_dev.h>
25#include <net/caif/cfpkt.h> 26#include <net/caif/cfpkt.h>
26#include <net/caif/cfcnfg.h> 27#include <net/caif/cfcnfg.h>
27#include <net/caif/cfserl.h> 28#include <net/caif/cfserl.h>
diff --git a/net/caif/cfsrvl.c b/net/caif/cfsrvl.c
index 353f793d1b3b..a6e115463052 100644
--- a/net/caif/cfsrvl.c
+++ b/net/caif/cfsrvl.c
@@ -15,6 +15,7 @@
15#include <net/caif/caif_layer.h> 15#include <net/caif/caif_layer.h>
16#include <net/caif/cfsrvl.h> 16#include <net/caif/cfsrvl.h>
17#include <net/caif/cfpkt.h> 17#include <net/caif/cfpkt.h>
18#include <net/caif/caif_dev.h>
18 19
19#define SRVL_CTRL_PKT_SIZE 1 20#define SRVL_CTRL_PKT_SIZE 1
20#define SRVL_FLOW_OFF 0x81 21#define SRVL_FLOW_OFF 0x81
diff --git a/net/can/af_can.c b/net/can/af_can.c
index d249874a366d..a27f8aad9e99 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -57,6 +57,7 @@
57#include <linux/skbuff.h> 57#include <linux/skbuff.h>
58#include <linux/can.h> 58#include <linux/can.h>
59#include <linux/can/core.h> 59#include <linux/can/core.h>
60#include <linux/can/skb.h>
60#include <linux/ratelimit.h> 61#include <linux/ratelimit.h>
61#include <net/net_namespace.h> 62#include <net/net_namespace.h>
62#include <net/sock.h> 63#include <net/sock.h>
@@ -290,7 +291,7 @@ int can_send(struct sk_buff *skb, int loop)
290 return -ENOMEM; 291 return -ENOMEM;
291 } 292 }
292 293
293 newskb->sk = skb->sk; 294 can_skb_set_owner(newskb, skb->sk);
294 newskb->ip_summed = CHECKSUM_UNNECESSARY; 295 newskb->ip_summed = CHECKSUM_UNNECESSARY;
295 newskb->pkt_type = PACKET_BROADCAST; 296 newskb->pkt_type = PACKET_BROADCAST;
296 } 297 }
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 3fc737b214c7..dcb75c0e66c1 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -268,7 +268,7 @@ static void bcm_can_tx(struct bcm_op *op)
268 268
269 /* send with loopback */ 269 /* send with loopback */
270 skb->dev = dev; 270 skb->dev = dev;
271 skb->sk = op->sk; 271 can_skb_set_owner(skb, op->sk);
272 can_send(skb, 1); 272 can_send(skb, 1);
273 273
274 /* update statistics */ 274 /* update statistics */
@@ -1223,7 +1223,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk)
1223 1223
1224 can_skb_prv(skb)->ifindex = dev->ifindex; 1224 can_skb_prv(skb)->ifindex = dev->ifindex;
1225 skb->dev = dev; 1225 skb->dev = dev;
1226 skb->sk = sk; 1226 can_skb_set_owner(skb, sk);
1227 err = can_send(skb, 1); /* send with loopback */ 1227 err = can_send(skb, 1); /* send with loopback */
1228 dev_put(dev); 1228 dev_put(dev);
1229 1229
diff --git a/net/can/raw.c b/net/can/raw.c
index 07d72d852324..081e81fd017f 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -121,13 +121,9 @@ static void raw_rcv(struct sk_buff *oskb, void *data)
121 if (!ro->recv_own_msgs && oskb->sk == sk) 121 if (!ro->recv_own_msgs && oskb->sk == sk)
122 return; 122 return;
123 123
124 /* do not pass frames with DLC > 8 to a legacy socket */ 124 /* do not pass non-CAN2.0 frames to a legacy socket */
125 if (!ro->fd_frames) { 125 if (!ro->fd_frames && oskb->len != CAN_MTU)
126 struct canfd_frame *cfd = (struct canfd_frame *)oskb->data; 126 return;
127
128 if (unlikely(cfd->len > CAN_MAX_DLEN))
129 return;
130 }
131 127
132 /* clone the given skb to be able to enqueue it into the rcv queue */ 128 /* clone the given skb to be able to enqueue it into the rcv queue */
133 skb = skb_clone(oskb, GFP_ATOMIC); 129 skb = skb_clone(oskb, GFP_ATOMIC);
@@ -715,6 +711,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct socket *sock,
715 711
716 skb->dev = dev; 712 skb->dev = dev;
717 skb->sk = sk; 713 skb->sk = sk;
714 skb->priority = sk->sk_priority;
718 715
719 err = can_send(skb, ro->loopback); 716 err = can_send(skb, ro->loopback);
720 717
@@ -737,9 +734,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
737 struct msghdr *msg, size_t size, int flags) 734 struct msghdr *msg, size_t size, int flags)
738{ 735{
739 struct sock *sk = sock->sk; 736 struct sock *sk = sock->sk;
740 struct raw_sock *ro = raw_sk(sk);
741 struct sk_buff *skb; 737 struct sk_buff *skb;
742 int rxmtu;
743 int err = 0; 738 int err = 0;
744 int noblock; 739 int noblock;
745 740
@@ -750,20 +745,10 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
750 if (!skb) 745 if (!skb)
751 return err; 746 return err;
752 747
753 /* 748 if (size < skb->len)
754 * when serving a legacy socket the DLC <= 8 is already checked inside
755 * raw_rcv(). Now check if we need to pass a canfd_frame to a legacy
756 * socket and cut the possible CANFD_MTU/CAN_MTU length to CAN_MTU
757 */
758 if (!ro->fd_frames)
759 rxmtu = CAN_MTU;
760 else
761 rxmtu = skb->len;
762
763 if (size < rxmtu)
764 msg->msg_flags |= MSG_TRUNC; 749 msg->msg_flags |= MSG_TRUNC;
765 else 750 else
766 size = rxmtu; 751 size = skb->len;
767 752
768 err = memcpy_toiovec(msg->msg_iov, skb->data, size); 753 err = memcpy_toiovec(msg->msg_iov, skb->data, size);
769 if (err < 0) { 754 if (err < 0) {
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 0e478a0f4204..30efc5c18622 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -840,9 +840,13 @@ static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor,
840 840
841 if (!cursor->bvec_iter.bi_size) { 841 if (!cursor->bvec_iter.bi_size) {
842 bio = bio->bi_next; 842 bio = bio->bi_next;
843 cursor->bvec_iter = bio->bi_iter; 843 cursor->bio = bio;
844 if (bio)
845 cursor->bvec_iter = bio->bi_iter;
846 else
847 memset(&cursor->bvec_iter, 0,
848 sizeof(cursor->bvec_iter));
844 } 849 }
845 cursor->bio = bio;
846 850
847 if (!cursor->last_piece) { 851 if (!cursor->last_piece) {
848 BUG_ON(!cursor->resid); 852 BUG_ON(!cursor->resid);
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 010ff3bd58ad..0676f2b199d6 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1427,6 +1427,40 @@ static void __send_queued(struct ceph_osd_client *osdc)
1427} 1427}
1428 1428
1429/* 1429/*
1430 * Caller should hold map_sem for read and request_mutex.
1431 */
1432static int __ceph_osdc_start_request(struct ceph_osd_client *osdc,
1433 struct ceph_osd_request *req,
1434 bool nofail)
1435{
1436 int rc;
1437
1438 __register_request(osdc, req);
1439 req->r_sent = 0;
1440 req->r_got_reply = 0;
1441 rc = __map_request(osdc, req, 0);
1442 if (rc < 0) {
1443 if (nofail) {
1444 dout("osdc_start_request failed map, "
1445 " will retry %lld\n", req->r_tid);
1446 rc = 0;
1447 } else {
1448 __unregister_request(osdc, req);
1449 }
1450 return rc;
1451 }
1452
1453 if (req->r_osd == NULL) {
1454 dout("send_request %p no up osds in pg\n", req);
1455 ceph_monc_request_next_osdmap(&osdc->client->monc);
1456 } else {
1457 __send_queued(osdc);
1458 }
1459
1460 return 0;
1461}
1462
1463/*
1430 * Timeout callback, called every N seconds when 1 or more osd 1464 * Timeout callback, called every N seconds when 1 or more osd
1431 * requests has been active for more than N seconds. When this 1465 * requests has been active for more than N seconds. When this
1432 * happens, we ping all OSDs with requests who have timed out to 1466 * happens, we ping all OSDs with requests who have timed out to
@@ -1653,6 +1687,7 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
1653 osdmap_epoch = ceph_decode_32(&p); 1687 osdmap_epoch = ceph_decode_32(&p);
1654 1688
1655 /* lookup */ 1689 /* lookup */
1690 down_read(&osdc->map_sem);
1656 mutex_lock(&osdc->request_mutex); 1691 mutex_lock(&osdc->request_mutex);
1657 req = __lookup_request(osdc, tid); 1692 req = __lookup_request(osdc, tid);
1658 if (req == NULL) { 1693 if (req == NULL) {
@@ -1709,7 +1744,6 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
1709 dout("redirect pool %lld\n", redir.oloc.pool); 1744 dout("redirect pool %lld\n", redir.oloc.pool);
1710 1745
1711 __unregister_request(osdc, req); 1746 __unregister_request(osdc, req);
1712 mutex_unlock(&osdc->request_mutex);
1713 1747
1714 req->r_target_oloc = redir.oloc; /* struct */ 1748 req->r_target_oloc = redir.oloc; /* struct */
1715 1749
@@ -1721,10 +1755,10 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
1721 * successfully. In the future we might want to follow 1755 * successfully. In the future we might want to follow
1722 * original request's nofail setting here. 1756 * original request's nofail setting here.
1723 */ 1757 */
1724 err = ceph_osdc_start_request(osdc, req, true); 1758 err = __ceph_osdc_start_request(osdc, req, true);
1725 BUG_ON(err); 1759 BUG_ON(err);
1726 1760
1727 goto done; 1761 goto out_unlock;
1728 } 1762 }
1729 1763
1730 already_completed = req->r_got_reply; 1764 already_completed = req->r_got_reply;
@@ -1742,8 +1776,7 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
1742 req->r_got_reply = 1; 1776 req->r_got_reply = 1;
1743 } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) { 1777 } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) {
1744 dout("handle_reply tid %llu dup ack\n", tid); 1778 dout("handle_reply tid %llu dup ack\n", tid);
1745 mutex_unlock(&osdc->request_mutex); 1779 goto out_unlock;
1746 goto done;
1747 } 1780 }
1748 1781
1749 dout("handle_reply tid %llu flags %d\n", tid, flags); 1782 dout("handle_reply tid %llu flags %d\n", tid, flags);
@@ -1758,6 +1791,7 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
1758 __unregister_request(osdc, req); 1791 __unregister_request(osdc, req);
1759 1792
1760 mutex_unlock(&osdc->request_mutex); 1793 mutex_unlock(&osdc->request_mutex);
1794 up_read(&osdc->map_sem);
1761 1795
1762 if (!already_completed) { 1796 if (!already_completed) {
1763 if (req->r_unsafe_callback && 1797 if (req->r_unsafe_callback &&
@@ -1775,10 +1809,14 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
1775 complete_request(req); 1809 complete_request(req);
1776 } 1810 }
1777 1811
1778done: 1812out:
1779 dout("req=%p req->r_linger=%d\n", req, req->r_linger); 1813 dout("req=%p req->r_linger=%d\n", req, req->r_linger);
1780 ceph_osdc_put_request(req); 1814 ceph_osdc_put_request(req);
1781 return; 1815 return;
1816out_unlock:
1817 mutex_unlock(&osdc->request_mutex);
1818 up_read(&osdc->map_sem);
1819 goto out;
1782 1820
1783bad_put: 1821bad_put:
1784 req->r_result = -EIO; 1822 req->r_result = -EIO;
@@ -1791,6 +1829,7 @@ bad_put:
1791 ceph_osdc_put_request(req); 1829 ceph_osdc_put_request(req);
1792bad_mutex: 1830bad_mutex:
1793 mutex_unlock(&osdc->request_mutex); 1831 mutex_unlock(&osdc->request_mutex);
1832 up_read(&osdc->map_sem);
1794bad: 1833bad:
1795 pr_err("corrupt osd_op_reply got %d %d\n", 1834 pr_err("corrupt osd_op_reply got %d %d\n",
1796 (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len)); 1835 (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len));
@@ -2351,34 +2390,16 @@ int ceph_osdc_start_request(struct ceph_osd_client *osdc,
2351 struct ceph_osd_request *req, 2390 struct ceph_osd_request *req,
2352 bool nofail) 2391 bool nofail)
2353{ 2392{
2354 int rc = 0; 2393 int rc;
2355 2394
2356 down_read(&osdc->map_sem); 2395 down_read(&osdc->map_sem);
2357 mutex_lock(&osdc->request_mutex); 2396 mutex_lock(&osdc->request_mutex);
2358 __register_request(osdc, req); 2397
2359 req->r_sent = 0; 2398 rc = __ceph_osdc_start_request(osdc, req, nofail);
2360 req->r_got_reply = 0; 2399
2361 rc = __map_request(osdc, req, 0);
2362 if (rc < 0) {
2363 if (nofail) {
2364 dout("osdc_start_request failed map, "
2365 " will retry %lld\n", req->r_tid);
2366 rc = 0;
2367 } else {
2368 __unregister_request(osdc, req);
2369 }
2370 goto out_unlock;
2371 }
2372 if (req->r_osd == NULL) {
2373 dout("send_request %p no up osds in pg\n", req);
2374 ceph_monc_request_next_osdmap(&osdc->client->monc);
2375 } else {
2376 __send_queued(osdc);
2377 }
2378 rc = 0;
2379out_unlock:
2380 mutex_unlock(&osdc->request_mutex); 2400 mutex_unlock(&osdc->request_mutex);
2381 up_read(&osdc->map_sem); 2401 up_read(&osdc->map_sem);
2402
2382 return rc; 2403 return rc;
2383} 2404}
2384EXPORT_SYMBOL(ceph_osdc_start_request); 2405EXPORT_SYMBOL(ceph_osdc_start_request);
@@ -2504,9 +2525,12 @@ int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
2504 err = -ENOMEM; 2525 err = -ENOMEM;
2505 osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify"); 2526 osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify");
2506 if (!osdc->notify_wq) 2527 if (!osdc->notify_wq)
2507 goto out_msgpool; 2528 goto out_msgpool_reply;
2529
2508 return 0; 2530 return 0;
2509 2531
2532out_msgpool_reply:
2533 ceph_msgpool_destroy(&osdc->msgpool_op_reply);
2510out_msgpool: 2534out_msgpool:
2511 ceph_msgpool_destroy(&osdc->msgpool_op); 2535 ceph_msgpool_destroy(&osdc->msgpool_op);
2512out_mempool: 2536out_mempool:
diff --git a/net/compat.c b/net/compat.c
index f50161fb812e..9a76eaf63184 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -384,8 +384,8 @@ static int compat_sock_setsockopt(struct socket *sock, int level, int optname,
384 return sock_setsockopt(sock, level, optname, optval, optlen); 384 return sock_setsockopt(sock, level, optname, optval, optlen);
385} 385}
386 386
387asmlinkage long compat_sys_setsockopt(int fd, int level, int optname, 387COMPAT_SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname,
388 char __user *optval, unsigned int optlen) 388 char __user *, optval, unsigned int, optlen)
389{ 389{
390 int err; 390 int err;
391 struct socket *sock = sockfd_lookup(fd, &err); 391 struct socket *sock = sockfd_lookup(fd, &err);
@@ -504,8 +504,8 @@ int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *usersta
504} 504}
505EXPORT_SYMBOL(compat_sock_get_timestampns); 505EXPORT_SYMBOL(compat_sock_get_timestampns);
506 506
507asmlinkage long compat_sys_getsockopt(int fd, int level, int optname, 507COMPAT_SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname,
508 char __user *optval, int __user *optlen) 508 char __user *, optval, int __user *, optlen)
509{ 509{
510 int err; 510 int err;
511 struct socket *sock = sockfd_lookup(fd, &err); 511 struct socket *sock = sockfd_lookup(fd, &err);
@@ -735,15 +735,15 @@ static unsigned char nas[21] = {
735}; 735};
736#undef AL 736#undef AL
737 737
738asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned int flags) 738COMPAT_SYSCALL_DEFINE3(sendmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
739{ 739{
740 if (flags & MSG_CMSG_COMPAT) 740 if (flags & MSG_CMSG_COMPAT)
741 return -EINVAL; 741 return -EINVAL;
742 return __sys_sendmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT); 742 return __sys_sendmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
743} 743}
744 744
745asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg, 745COMPAT_SYSCALL_DEFINE4(sendmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
746 unsigned int vlen, unsigned int flags) 746 unsigned int, vlen, unsigned int, flags)
747{ 747{
748 if (flags & MSG_CMSG_COMPAT) 748 if (flags & MSG_CMSG_COMPAT)
749 return -EINVAL; 749 return -EINVAL;
@@ -751,28 +751,28 @@ asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
751 flags | MSG_CMSG_COMPAT); 751 flags | MSG_CMSG_COMPAT);
752} 752}
753 753
754asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg, unsigned int flags) 754COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
755{ 755{
756 if (flags & MSG_CMSG_COMPAT) 756 if (flags & MSG_CMSG_COMPAT)
757 return -EINVAL; 757 return -EINVAL;
758 return __sys_recvmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT); 758 return __sys_recvmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
759} 759}
760 760
761asmlinkage long compat_sys_recv(int fd, void __user *buf, size_t len, unsigned int flags) 761COMPAT_SYSCALL_DEFINE4(recv, int, fd, void __user *, buf, compat_size_t, len, unsigned int, flags)
762{ 762{
763 return sys_recv(fd, buf, len, flags | MSG_CMSG_COMPAT); 763 return sys_recv(fd, buf, len, flags | MSG_CMSG_COMPAT);
764} 764}
765 765
766asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, size_t len, 766COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, len,
767 unsigned int flags, struct sockaddr __user *addr, 767 unsigned int, flags, struct sockaddr __user *, addr,
768 int __user *addrlen) 768 int __user *, addrlen)
769{ 769{
770 return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen); 770 return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen);
771} 771}
772 772
773asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg, 773COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
774 unsigned int vlen, unsigned int flags, 774 unsigned int, vlen, unsigned int, flags,
775 struct compat_timespec __user *timeout) 775 struct compat_timespec __user *, timeout)
776{ 776{
777 int datagrams; 777 int datagrams;
778 struct timespec ktspec; 778 struct timespec ktspec;
@@ -795,7 +795,7 @@ asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
795 return datagrams; 795 return datagrams;
796} 796}
797 797
798asmlinkage long compat_sys_socketcall(int call, u32 __user *args) 798COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
799{ 799{
800 int ret; 800 int ret;
801 u32 a[6]; 801 u32 a[6];
diff --git a/net/core/dev.c b/net/core/dev.c
index 3721db716350..45fa2f11f84d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2286,7 +2286,7 @@ out:
2286} 2286}
2287EXPORT_SYMBOL(skb_checksum_help); 2287EXPORT_SYMBOL(skb_checksum_help);
2288 2288
2289__be16 skb_network_protocol(struct sk_buff *skb) 2289__be16 skb_network_protocol(struct sk_buff *skb, int *depth)
2290{ 2290{
2291 __be16 type = skb->protocol; 2291 __be16 type = skb->protocol;
2292 int vlan_depth = ETH_HLEN; 2292 int vlan_depth = ETH_HLEN;
@@ -2313,6 +2313,8 @@ __be16 skb_network_protocol(struct sk_buff *skb)
2313 vlan_depth += VLAN_HLEN; 2313 vlan_depth += VLAN_HLEN;
2314 } 2314 }
2315 2315
2316 *depth = vlan_depth;
2317
2316 return type; 2318 return type;
2317} 2319}
2318 2320
@@ -2326,12 +2328,13 @@ struct sk_buff *skb_mac_gso_segment(struct sk_buff *skb,
2326{ 2328{
2327 struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT); 2329 struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT);
2328 struct packet_offload *ptype; 2330 struct packet_offload *ptype;
2329 __be16 type = skb_network_protocol(skb); 2331 int vlan_depth = skb->mac_len;
2332 __be16 type = skb_network_protocol(skb, &vlan_depth);
2330 2333
2331 if (unlikely(!type)) 2334 if (unlikely(!type))
2332 return ERR_PTR(-EINVAL); 2335 return ERR_PTR(-EINVAL);
2333 2336
2334 __skb_pull(skb, skb->mac_len); 2337 __skb_pull(skb, vlan_depth);
2335 2338
2336 rcu_read_lock(); 2339 rcu_read_lock();
2337 list_for_each_entry_rcu(ptype, &offload_base, list) { 2340 list_for_each_entry_rcu(ptype, &offload_base, list) {
@@ -2420,7 +2423,7 @@ EXPORT_SYMBOL(netdev_rx_csum_fault);
2420 * 2. No high memory really exists on this machine. 2423 * 2. No high memory really exists on this machine.
2421 */ 2424 */
2422 2425
2423static int illegal_highdma(struct net_device *dev, struct sk_buff *skb) 2426static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
2424{ 2427{
2425#ifdef CONFIG_HIGHMEM 2428#ifdef CONFIG_HIGHMEM
2426 int i; 2429 int i;
@@ -2495,34 +2498,38 @@ static int dev_gso_segment(struct sk_buff *skb, netdev_features_t features)
2495} 2498}
2496 2499
2497static netdev_features_t harmonize_features(struct sk_buff *skb, 2500static netdev_features_t harmonize_features(struct sk_buff *skb,
2498 netdev_features_t features) 2501 const struct net_device *dev,
2502 netdev_features_t features)
2499{ 2503{
2504 int tmp;
2505
2500 if (skb->ip_summed != CHECKSUM_NONE && 2506 if (skb->ip_summed != CHECKSUM_NONE &&
2501 !can_checksum_protocol(features, skb_network_protocol(skb))) { 2507 !can_checksum_protocol(features, skb_network_protocol(skb, &tmp))) {
2502 features &= ~NETIF_F_ALL_CSUM; 2508 features &= ~NETIF_F_ALL_CSUM;
2503 } else if (illegal_highdma(skb->dev, skb)) { 2509 } else if (illegal_highdma(dev, skb)) {
2504 features &= ~NETIF_F_SG; 2510 features &= ~NETIF_F_SG;
2505 } 2511 }
2506 2512
2507 return features; 2513 return features;
2508} 2514}
2509 2515
2510netdev_features_t netif_skb_features(struct sk_buff *skb) 2516netdev_features_t netif_skb_dev_features(struct sk_buff *skb,
2517 const struct net_device *dev)
2511{ 2518{
2512 __be16 protocol = skb->protocol; 2519 __be16 protocol = skb->protocol;
2513 netdev_features_t features = skb->dev->features; 2520 netdev_features_t features = dev->features;
2514 2521
2515 if (skb_shinfo(skb)->gso_segs > skb->dev->gso_max_segs) 2522 if (skb_shinfo(skb)->gso_segs > dev->gso_max_segs)
2516 features &= ~NETIF_F_GSO_MASK; 2523 features &= ~NETIF_F_GSO_MASK;
2517 2524
2518 if (protocol == htons(ETH_P_8021Q) || protocol == htons(ETH_P_8021AD)) { 2525 if (protocol == htons(ETH_P_8021Q) || protocol == htons(ETH_P_8021AD)) {
2519 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; 2526 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
2520 protocol = veh->h_vlan_encapsulated_proto; 2527 protocol = veh->h_vlan_encapsulated_proto;
2521 } else if (!vlan_tx_tag_present(skb)) { 2528 } else if (!vlan_tx_tag_present(skb)) {
2522 return harmonize_features(skb, features); 2529 return harmonize_features(skb, dev, features);
2523 } 2530 }
2524 2531
2525 features &= (skb->dev->vlan_features | NETIF_F_HW_VLAN_CTAG_TX | 2532 features &= (dev->vlan_features | NETIF_F_HW_VLAN_CTAG_TX |
2526 NETIF_F_HW_VLAN_STAG_TX); 2533 NETIF_F_HW_VLAN_STAG_TX);
2527 2534
2528 if (protocol == htons(ETH_P_8021Q) || protocol == htons(ETH_P_8021AD)) 2535 if (protocol == htons(ETH_P_8021Q) || protocol == htons(ETH_P_8021AD))
@@ -2530,9 +2537,9 @@ netdev_features_t netif_skb_features(struct sk_buff *skb)
2530 NETIF_F_GEN_CSUM | NETIF_F_HW_VLAN_CTAG_TX | 2537 NETIF_F_GEN_CSUM | NETIF_F_HW_VLAN_CTAG_TX |
2531 NETIF_F_HW_VLAN_STAG_TX; 2538 NETIF_F_HW_VLAN_STAG_TX;
2532 2539
2533 return harmonize_features(skb, features); 2540 return harmonize_features(skb, dev, features);
2534} 2541}
2535EXPORT_SYMBOL(netif_skb_features); 2542EXPORT_SYMBOL(netif_skb_dev_features);
2536 2543
2537int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, 2544int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
2538 struct netdev_queue *txq) 2545 struct netdev_queue *txq)
@@ -2803,7 +2810,7 @@ EXPORT_SYMBOL(dev_loopback_xmit);
2803 * the BH enable code must have IRQs enabled so that it will not deadlock. 2810 * the BH enable code must have IRQs enabled so that it will not deadlock.
2804 * --BLG 2811 * --BLG
2805 */ 2812 */
2806int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv) 2813static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)
2807{ 2814{
2808 struct net_device *dev = skb->dev; 2815 struct net_device *dev = skb->dev;
2809 struct netdev_queue *txq; 2816 struct netdev_queue *txq;
@@ -4637,7 +4644,7 @@ struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev)
4637} 4644}
4638EXPORT_SYMBOL(netdev_master_upper_dev_get_rcu); 4645EXPORT_SYMBOL(netdev_master_upper_dev_get_rcu);
4639 4646
4640int netdev_adjacent_sysfs_add(struct net_device *dev, 4647static int netdev_adjacent_sysfs_add(struct net_device *dev,
4641 struct net_device *adj_dev, 4648 struct net_device *adj_dev,
4642 struct list_head *dev_list) 4649 struct list_head *dev_list)
4643{ 4650{
@@ -4647,7 +4654,7 @@ int netdev_adjacent_sysfs_add(struct net_device *dev,
4647 return sysfs_create_link(&(dev->dev.kobj), &(adj_dev->dev.kobj), 4654 return sysfs_create_link(&(dev->dev.kobj), &(adj_dev->dev.kobj),
4648 linkname); 4655 linkname);
4649} 4656}
4650void netdev_adjacent_sysfs_del(struct net_device *dev, 4657static void netdev_adjacent_sysfs_del(struct net_device *dev,
4651 char *name, 4658 char *name,
4652 struct list_head *dev_list) 4659 struct list_head *dev_list)
4653{ 4660{
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index f409e0bd35c0..185c341fafbd 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -745,6 +745,13 @@ static int fib_rules_event(struct notifier_block *this, unsigned long event,
745 attach_rules(&ops->rules_list, dev); 745 attach_rules(&ops->rules_list, dev);
746 break; 746 break;
747 747
748 case NETDEV_CHANGENAME:
749 list_for_each_entry(ops, &net->rules_ops, list) {
750 detach_rules(&ops->rules_list, dev);
751 attach_rules(&ops->rules_list, dev);
752 }
753 break;
754
748 case NETDEV_UNREGISTER: 755 case NETDEV_UNREGISTER:
749 list_for_each_entry(ops, &net->rules_ops, list) 756 list_for_each_entry(ops, &net->rules_ops, list)
750 detach_rules(&ops->rules_list, dev); 757 detach_rules(&ops->rules_list, dev);
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 87577d447554..e29e810663d7 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -323,17 +323,6 @@ u32 __skb_get_poff(const struct sk_buff *skb)
323 return poff; 323 return poff;
324} 324}
325 325
326static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index)
327{
328 if (unlikely(queue_index >= dev->real_num_tx_queues)) {
329 net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
330 dev->name, queue_index,
331 dev->real_num_tx_queues);
332 return 0;
333 }
334 return queue_index;
335}
336
337static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb) 326static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb)
338{ 327{
339#ifdef CONFIG_XPS 328#ifdef CONFIG_XPS
@@ -372,7 +361,7 @@ static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb)
372#endif 361#endif
373} 362}
374 363
375u16 __netdev_pick_tx(struct net_device *dev, struct sk_buff *skb) 364static u16 __netdev_pick_tx(struct net_device *dev, struct sk_buff *skb)
376{ 365{
377 struct sock *sk = skb->sk; 366 struct sock *sk = skb->sk;
378 int queue_index = sk_tx_queue_get(sk); 367 int queue_index = sk_tx_queue_get(sk);
@@ -392,7 +381,6 @@ u16 __netdev_pick_tx(struct net_device *dev, struct sk_buff *skb)
392 381
393 return queue_index; 382 return queue_index;
394} 383}
395EXPORT_SYMBOL(__netdev_pick_tx);
396 384
397struct netdev_queue *netdev_pick_tx(struct net_device *dev, 385struct netdev_queue *netdev_pick_tx(struct net_device *dev,
398 struct sk_buff *skb, 386 struct sk_buff *skb,
@@ -403,13 +391,13 @@ struct netdev_queue *netdev_pick_tx(struct net_device *dev,
403 if (dev->real_num_tx_queues != 1) { 391 if (dev->real_num_tx_queues != 1) {
404 const struct net_device_ops *ops = dev->netdev_ops; 392 const struct net_device_ops *ops = dev->netdev_ops;
405 if (ops->ndo_select_queue) 393 if (ops->ndo_select_queue)
406 queue_index = ops->ndo_select_queue(dev, skb, 394 queue_index = ops->ndo_select_queue(dev, skb, accel_priv,
407 accel_priv); 395 __netdev_pick_tx);
408 else 396 else
409 queue_index = __netdev_pick_tx(dev, skb); 397 queue_index = __netdev_pick_tx(dev, skb);
410 398
411 if (!accel_priv) 399 if (!accel_priv)
412 queue_index = dev_cap_txqueue(dev, queue_index); 400 queue_index = netdev_cap_txqueue(dev, queue_index);
413 } 401 }
414 402
415 skb_set_queue_mapping(skb, queue_index); 403 skb_set_queue_mapping(skb, queue_index);
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index b9e9e0d38672..e16129019c66 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -766,9 +766,6 @@ static void neigh_periodic_work(struct work_struct *work)
766 nht = rcu_dereference_protected(tbl->nht, 766 nht = rcu_dereference_protected(tbl->nht,
767 lockdep_is_held(&tbl->lock)); 767 lockdep_is_held(&tbl->lock));
768 768
769 if (atomic_read(&tbl->entries) < tbl->gc_thresh1)
770 goto out;
771
772 /* 769 /*
773 * periodically recompute ReachableTime from random function 770 * periodically recompute ReachableTime from random function
774 */ 771 */
@@ -781,6 +778,9 @@ static void neigh_periodic_work(struct work_struct *work)
781 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME)); 778 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
782 } 779 }
783 780
781 if (atomic_read(&tbl->entries) < tbl->gc_thresh1)
782 goto out;
783
784 for (i = 0 ; i < (1 << nht->hash_shift); i++) { 784 for (i = 0 ; i < (1 << nht->hash_shift); i++) {
785 np = &nht->hash_buckets[i]; 785 np = &nht->hash_buckets[i];
786 786
@@ -3046,7 +3046,7 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
3046 if (!t) 3046 if (!t)
3047 goto err; 3047 goto err;
3048 3048
3049 for (i = 0; i < ARRAY_SIZE(t->neigh_vars); i++) { 3049 for (i = 0; i < NEIGH_VAR_GC_INTERVAL; i++) {
3050 t->neigh_vars[i].data += (long) p; 3050 t->neigh_vars[i].data += (long) p;
3051 t->neigh_vars[i].extra1 = dev; 3051 t->neigh_vars[i].extra1 = dev;
3052 t->neigh_vars[i].extra2 = p; 3052 t->neigh_vars[i].extra2 = p;
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index c03f3dec4763..df9e6b1a9759 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -742,7 +742,7 @@ static bool pkt_is_ns(struct sk_buff *skb)
742 struct nd_msg *msg; 742 struct nd_msg *msg;
743 struct ipv6hdr *hdr; 743 struct ipv6hdr *hdr;
744 744
745 if (skb->protocol != htons(ETH_P_ARP)) 745 if (skb->protocol != htons(ETH_P_IPV6))
746 return false; 746 return false;
747 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct nd_msg))) 747 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct nd_msg)))
748 return false; 748 return false;
@@ -948,6 +948,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
948{ 948{
949 char *cur=opt, *delim; 949 char *cur=opt, *delim;
950 int ipv6; 950 int ipv6;
951 bool ipversion_set = false;
951 952
952 if (*cur != '@') { 953 if (*cur != '@') {
953 if ((delim = strchr(cur, '@')) == NULL) 954 if ((delim = strchr(cur, '@')) == NULL)
@@ -960,6 +961,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
960 cur++; 961 cur++;
961 962
962 if (*cur != '/') { 963 if (*cur != '/') {
964 ipversion_set = true;
963 if ((delim = strchr(cur, '/')) == NULL) 965 if ((delim = strchr(cur, '/')) == NULL)
964 goto parse_failed; 966 goto parse_failed;
965 *delim = 0; 967 *delim = 0;
@@ -1002,7 +1004,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
1002 ipv6 = netpoll_parse_ip_addr(cur, &np->remote_ip); 1004 ipv6 = netpoll_parse_ip_addr(cur, &np->remote_ip);
1003 if (ipv6 < 0) 1005 if (ipv6 < 0)
1004 goto parse_failed; 1006 goto parse_failed;
1005 else if (np->ipv6 != (bool)ipv6) 1007 else if (ipversion_set && np->ipv6 != (bool)ipv6)
1006 goto parse_failed; 1008 goto parse_failed;
1007 else 1009 else
1008 np->ipv6 = (bool)ipv6; 1010 np->ipv6 = (bool)ipv6;
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 393b1bc9a618..120eecc0f5a4 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -374,7 +374,7 @@ static size_t rtnl_link_get_slave_info_data_size(const struct net_device *dev)
374 if (!master_dev) 374 if (!master_dev)
375 return 0; 375 return 0;
376 ops = master_dev->rtnl_link_ops; 376 ops = master_dev->rtnl_link_ops;
377 if (!ops->get_slave_size) 377 if (!ops || !ops->get_slave_size)
378 return 0; 378 return 0;
379 /* IFLA_INFO_SLAVE_DATA + nested data */ 379 /* IFLA_INFO_SLAVE_DATA + nested data */
380 return nla_total_size(sizeof(struct nlattr)) + 380 return nla_total_size(sizeof(struct nlattr)) +
@@ -1963,16 +1963,21 @@ replay:
1963 1963
1964 dev->ifindex = ifm->ifi_index; 1964 dev->ifindex = ifm->ifi_index;
1965 1965
1966 if (ops->newlink) 1966 if (ops->newlink) {
1967 err = ops->newlink(net, dev, tb, data); 1967 err = ops->newlink(net, dev, tb, data);
1968 else 1968 /* Drivers should call free_netdev() in ->destructor
1969 * and unregister it on failure so that device could be
1970 * finally freed in rtnl_unlock.
1971 */
1972 if (err < 0)
1973 goto out;
1974 } else {
1969 err = register_netdevice(dev); 1975 err = register_netdevice(dev);
1970 1976 if (err < 0) {
1971 if (err < 0) { 1977 free_netdev(dev);
1972 free_netdev(dev); 1978 goto out;
1973 goto out; 1979 }
1974 } 1980 }
1975
1976 err = rtnl_configure_link(dev, ifm); 1981 err = rtnl_configure_link(dev, ifm);
1977 if (err < 0) 1982 if (err < 0)
1978 unregister_netdevice(dev); 1983 unregister_netdevice(dev);
@@ -2116,12 +2121,13 @@ EXPORT_SYMBOL(rtmsg_ifinfo);
2116static int nlmsg_populate_fdb_fill(struct sk_buff *skb, 2121static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
2117 struct net_device *dev, 2122 struct net_device *dev,
2118 u8 *addr, u32 pid, u32 seq, 2123 u8 *addr, u32 pid, u32 seq,
2119 int type, unsigned int flags) 2124 int type, unsigned int flags,
2125 int nlflags)
2120{ 2126{
2121 struct nlmsghdr *nlh; 2127 struct nlmsghdr *nlh;
2122 struct ndmsg *ndm; 2128 struct ndmsg *ndm;
2123 2129
2124 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), NLM_F_MULTI); 2130 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), nlflags);
2125 if (!nlh) 2131 if (!nlh)
2126 return -EMSGSIZE; 2132 return -EMSGSIZE;
2127 2133
@@ -2159,7 +2165,7 @@ static void rtnl_fdb_notify(struct net_device *dev, u8 *addr, int type)
2159 if (!skb) 2165 if (!skb)
2160 goto errout; 2166 goto errout;
2161 2167
2162 err = nlmsg_populate_fdb_fill(skb, dev, addr, 0, 0, type, NTF_SELF); 2168 err = nlmsg_populate_fdb_fill(skb, dev, addr, 0, 0, type, NTF_SELF, 0);
2163 if (err < 0) { 2169 if (err < 0) {
2164 kfree_skb(skb); 2170 kfree_skb(skb);
2165 goto errout; 2171 goto errout;
@@ -2384,7 +2390,8 @@ static int nlmsg_populate_fdb(struct sk_buff *skb,
2384 2390
2385 err = nlmsg_populate_fdb_fill(skb, dev, ha->addr, 2391 err = nlmsg_populate_fdb_fill(skb, dev, ha->addr,
2386 portid, seq, 2392 portid, seq,
2387 RTM_NEWNEIGH, NTF_SELF); 2393 RTM_NEWNEIGH, NTF_SELF,
2394 NLM_F_MULTI);
2388 if (err < 0) 2395 if (err < 0)
2389 return err; 2396 return err;
2390skip: 2397skip:
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 5976ef0846bd..90b96a11b974 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -707,9 +707,6 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
707 new->mark = old->mark; 707 new->mark = old->mark;
708 new->skb_iif = old->skb_iif; 708 new->skb_iif = old->skb_iif;
709 __nf_copy(new, old); 709 __nf_copy(new, old);
710#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
711 new->nf_trace = old->nf_trace;
712#endif
713#ifdef CONFIG_NET_SCHED 710#ifdef CONFIG_NET_SCHED
714 new->tc_index = old->tc_index; 711 new->tc_index = old->tc_index;
715#ifdef CONFIG_NET_CLS_ACT 712#ifdef CONFIG_NET_CLS_ACT
@@ -2130,25 +2127,31 @@ EXPORT_SYMBOL_GPL(skb_zerocopy_headlen);
2130 * 2127 *
2131 * The `hlen` as calculated by skb_zerocopy_headlen() specifies the 2128 * The `hlen` as calculated by skb_zerocopy_headlen() specifies the
2132 * headroom in the `to` buffer. 2129 * headroom in the `to` buffer.
2130 *
2131 * Return value:
2132 * 0: everything is OK
2133 * -ENOMEM: couldn't orphan frags of @from due to lack of memory
2134 * -EFAULT: skb_copy_bits() found some problem with skb geometry
2133 */ 2135 */
2134void 2136int
2135skb_zerocopy(struct sk_buff *to, const struct sk_buff *from, int len, int hlen) 2137skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)
2136{ 2138{
2137 int i, j = 0; 2139 int i, j = 0;
2138 int plen = 0; /* length of skb->head fragment */ 2140 int plen = 0; /* length of skb->head fragment */
2141 int ret;
2139 struct page *page; 2142 struct page *page;
2140 unsigned int offset; 2143 unsigned int offset;
2141 2144
2142 BUG_ON(!from->head_frag && !hlen); 2145 BUG_ON(!from->head_frag && !hlen);
2143 2146
2144 /* dont bother with small payloads */ 2147 /* dont bother with small payloads */
2145 if (len <= skb_tailroom(to)) { 2148 if (len <= skb_tailroom(to))
2146 skb_copy_bits(from, 0, skb_put(to, len), len); 2149 return skb_copy_bits(from, 0, skb_put(to, len), len);
2147 return;
2148 }
2149 2150
2150 if (hlen) { 2151 if (hlen) {
2151 skb_copy_bits(from, 0, skb_put(to, hlen), hlen); 2152 ret = skb_copy_bits(from, 0, skb_put(to, hlen), hlen);
2153 if (unlikely(ret))
2154 return ret;
2152 len -= hlen; 2155 len -= hlen;
2153 } else { 2156 } else {
2154 plen = min_t(int, skb_headlen(from), len); 2157 plen = min_t(int, skb_headlen(from), len);
@@ -2166,6 +2169,11 @@ skb_zerocopy(struct sk_buff *to, const struct sk_buff *from, int len, int hlen)
2166 to->len += len + plen; 2169 to->len += len + plen;
2167 to->data_len += len + plen; 2170 to->data_len += len + plen;
2168 2171
2172 if (unlikely(skb_orphan_frags(from, GFP_ATOMIC))) {
2173 skb_tx_error(from);
2174 return -ENOMEM;
2175 }
2176
2169 for (i = 0; i < skb_shinfo(from)->nr_frags; i++) { 2177 for (i = 0; i < skb_shinfo(from)->nr_frags; i++) {
2170 if (!len) 2178 if (!len)
2171 break; 2179 break;
@@ -2176,6 +2184,8 @@ skb_zerocopy(struct sk_buff *to, const struct sk_buff *from, int len, int hlen)
2176 j++; 2184 j++;
2177 } 2185 }
2178 skb_shinfo(to)->nr_frags = j; 2186 skb_shinfo(to)->nr_frags = j;
2187
2188 return 0;
2179} 2189}
2180EXPORT_SYMBOL_GPL(skb_zerocopy); 2190EXPORT_SYMBOL_GPL(skb_zerocopy);
2181 2191
@@ -2841,81 +2851,85 @@ EXPORT_SYMBOL_GPL(skb_pull_rcsum);
2841 2851
2842/** 2852/**
2843 * skb_segment - Perform protocol segmentation on skb. 2853 * skb_segment - Perform protocol segmentation on skb.
2844 * @skb: buffer to segment 2854 * @head_skb: buffer to segment
2845 * @features: features for the output path (see dev->features) 2855 * @features: features for the output path (see dev->features)
2846 * 2856 *
2847 * This function performs segmentation on the given skb. It returns 2857 * This function performs segmentation on the given skb. It returns
2848 * a pointer to the first in a list of new skbs for the segments. 2858 * a pointer to the first in a list of new skbs for the segments.
2849 * In case of error it returns ERR_PTR(err). 2859 * In case of error it returns ERR_PTR(err).
2850 */ 2860 */
2851struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features) 2861struct sk_buff *skb_segment(struct sk_buff *head_skb,
2862 netdev_features_t features)
2852{ 2863{
2853 struct sk_buff *segs = NULL; 2864 struct sk_buff *segs = NULL;
2854 struct sk_buff *tail = NULL; 2865 struct sk_buff *tail = NULL;
2855 struct sk_buff *fskb = skb_shinfo(skb)->frag_list; 2866 struct sk_buff *list_skb = skb_shinfo(head_skb)->frag_list;
2856 skb_frag_t *skb_frag = skb_shinfo(skb)->frags; 2867 skb_frag_t *frag = skb_shinfo(head_skb)->frags;
2857 unsigned int mss = skb_shinfo(skb)->gso_size; 2868 unsigned int mss = skb_shinfo(head_skb)->gso_size;
2858 unsigned int doffset = skb->data - skb_mac_header(skb); 2869 unsigned int doffset = head_skb->data - skb_mac_header(head_skb);
2870 struct sk_buff *frag_skb = head_skb;
2859 unsigned int offset = doffset; 2871 unsigned int offset = doffset;
2860 unsigned int tnl_hlen = skb_tnl_header_len(skb); 2872 unsigned int tnl_hlen = skb_tnl_header_len(head_skb);
2861 unsigned int headroom; 2873 unsigned int headroom;
2862 unsigned int len; 2874 unsigned int len;
2863 __be16 proto; 2875 __be16 proto;
2864 bool csum; 2876 bool csum;
2865 int sg = !!(features & NETIF_F_SG); 2877 int sg = !!(features & NETIF_F_SG);
2866 int nfrags = skb_shinfo(skb)->nr_frags; 2878 int nfrags = skb_shinfo(head_skb)->nr_frags;
2867 int err = -ENOMEM; 2879 int err = -ENOMEM;
2868 int i = 0; 2880 int i = 0;
2869 int pos; 2881 int pos;
2882 int dummy;
2870 2883
2871 proto = skb_network_protocol(skb); 2884 proto = skb_network_protocol(head_skb, &dummy);
2872 if (unlikely(!proto)) 2885 if (unlikely(!proto))
2873 return ERR_PTR(-EINVAL); 2886 return ERR_PTR(-EINVAL);
2874 2887
2875 csum = !!can_checksum_protocol(features, proto); 2888 csum = !!can_checksum_protocol(features, proto);
2876 __skb_push(skb, doffset); 2889 __skb_push(head_skb, doffset);
2877 headroom = skb_headroom(skb); 2890 headroom = skb_headroom(head_skb);
2878 pos = skb_headlen(skb); 2891 pos = skb_headlen(head_skb);
2879 2892
2880 do { 2893 do {
2881 struct sk_buff *nskb; 2894 struct sk_buff *nskb;
2882 skb_frag_t *frag; 2895 skb_frag_t *nskb_frag;
2883 int hsize; 2896 int hsize;
2884 int size; 2897 int size;
2885 2898
2886 len = skb->len - offset; 2899 len = head_skb->len - offset;
2887 if (len > mss) 2900 if (len > mss)
2888 len = mss; 2901 len = mss;
2889 2902
2890 hsize = skb_headlen(skb) - offset; 2903 hsize = skb_headlen(head_skb) - offset;
2891 if (hsize < 0) 2904 if (hsize < 0)
2892 hsize = 0; 2905 hsize = 0;
2893 if (hsize > len || !sg) 2906 if (hsize > len || !sg)
2894 hsize = len; 2907 hsize = len;
2895 2908
2896 if (!hsize && i >= nfrags && skb_headlen(fskb) && 2909 if (!hsize && i >= nfrags && skb_headlen(list_skb) &&
2897 (skb_headlen(fskb) == len || sg)) { 2910 (skb_headlen(list_skb) == len || sg)) {
2898 BUG_ON(skb_headlen(fskb) > len); 2911 BUG_ON(skb_headlen(list_skb) > len);
2899 2912
2900 i = 0; 2913 i = 0;
2901 nfrags = skb_shinfo(fskb)->nr_frags; 2914 nfrags = skb_shinfo(list_skb)->nr_frags;
2902 skb_frag = skb_shinfo(fskb)->frags; 2915 frag = skb_shinfo(list_skb)->frags;
2903 pos += skb_headlen(fskb); 2916 frag_skb = list_skb;
2917 pos += skb_headlen(list_skb);
2904 2918
2905 while (pos < offset + len) { 2919 while (pos < offset + len) {
2906 BUG_ON(i >= nfrags); 2920 BUG_ON(i >= nfrags);
2907 2921
2908 size = skb_frag_size(skb_frag); 2922 size = skb_frag_size(frag);
2909 if (pos + size > offset + len) 2923 if (pos + size > offset + len)
2910 break; 2924 break;
2911 2925
2912 i++; 2926 i++;
2913 pos += size; 2927 pos += size;
2914 skb_frag++; 2928 frag++;
2915 } 2929 }
2916 2930
2917 nskb = skb_clone(fskb, GFP_ATOMIC); 2931 nskb = skb_clone(list_skb, GFP_ATOMIC);
2918 fskb = fskb->next; 2932 list_skb = list_skb->next;
2919 2933
2920 if (unlikely(!nskb)) 2934 if (unlikely(!nskb))
2921 goto err; 2935 goto err;
@@ -2936,7 +2950,7 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
2936 __skb_push(nskb, doffset); 2950 __skb_push(nskb, doffset);
2937 } else { 2951 } else {
2938 nskb = __alloc_skb(hsize + doffset + headroom, 2952 nskb = __alloc_skb(hsize + doffset + headroom,
2939 GFP_ATOMIC, skb_alloc_rx_flag(skb), 2953 GFP_ATOMIC, skb_alloc_rx_flag(head_skb),
2940 NUMA_NO_NODE); 2954 NUMA_NO_NODE);
2941 2955
2942 if (unlikely(!nskb)) 2956 if (unlikely(!nskb))
@@ -2952,12 +2966,12 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
2952 segs = nskb; 2966 segs = nskb;
2953 tail = nskb; 2967 tail = nskb;
2954 2968
2955 __copy_skb_header(nskb, skb); 2969 __copy_skb_header(nskb, head_skb);
2956 nskb->mac_len = skb->mac_len; 2970 nskb->mac_len = head_skb->mac_len;
2957 2971
2958 skb_headers_offset_update(nskb, skb_headroom(nskb) - headroom); 2972 skb_headers_offset_update(nskb, skb_headroom(nskb) - headroom);
2959 2973
2960 skb_copy_from_linear_data_offset(skb, -tnl_hlen, 2974 skb_copy_from_linear_data_offset(head_skb, -tnl_hlen,
2961 nskb->data - tnl_hlen, 2975 nskb->data - tnl_hlen,
2962 doffset + tnl_hlen); 2976 doffset + tnl_hlen);
2963 2977
@@ -2966,30 +2980,32 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
2966 2980
2967 if (!sg) { 2981 if (!sg) {
2968 nskb->ip_summed = CHECKSUM_NONE; 2982 nskb->ip_summed = CHECKSUM_NONE;
2969 nskb->csum = skb_copy_and_csum_bits(skb, offset, 2983 nskb->csum = skb_copy_and_csum_bits(head_skb, offset,
2970 skb_put(nskb, len), 2984 skb_put(nskb, len),
2971 len, 0); 2985 len, 0);
2972 continue; 2986 continue;
2973 } 2987 }
2974 2988
2975 frag = skb_shinfo(nskb)->frags; 2989 nskb_frag = skb_shinfo(nskb)->frags;
2976 2990
2977 skb_copy_from_linear_data_offset(skb, offset, 2991 skb_copy_from_linear_data_offset(head_skb, offset,
2978 skb_put(nskb, hsize), hsize); 2992 skb_put(nskb, hsize), hsize);
2979 2993
2980 skb_shinfo(nskb)->tx_flags = skb_shinfo(skb)->tx_flags & SKBTX_SHARED_FRAG; 2994 skb_shinfo(nskb)->tx_flags = skb_shinfo(head_skb)->tx_flags &
2995 SKBTX_SHARED_FRAG;
2981 2996
2982 while (pos < offset + len) { 2997 while (pos < offset + len) {
2983 if (i >= nfrags) { 2998 if (i >= nfrags) {
2984 BUG_ON(skb_headlen(fskb)); 2999 BUG_ON(skb_headlen(list_skb));
2985 3000
2986 i = 0; 3001 i = 0;
2987 nfrags = skb_shinfo(fskb)->nr_frags; 3002 nfrags = skb_shinfo(list_skb)->nr_frags;
2988 skb_frag = skb_shinfo(fskb)->frags; 3003 frag = skb_shinfo(list_skb)->frags;
3004 frag_skb = list_skb;
2989 3005
2990 BUG_ON(!nfrags); 3006 BUG_ON(!nfrags);
2991 3007
2992 fskb = fskb->next; 3008 list_skb = list_skb->next;
2993 } 3009 }
2994 3010
2995 if (unlikely(skb_shinfo(nskb)->nr_frags >= 3011 if (unlikely(skb_shinfo(nskb)->nr_frags >=
@@ -3000,27 +3016,30 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
3000 goto err; 3016 goto err;
3001 } 3017 }
3002 3018
3003 *frag = *skb_frag; 3019 if (unlikely(skb_orphan_frags(frag_skb, GFP_ATOMIC)))
3004 __skb_frag_ref(frag); 3020 goto err;
3005 size = skb_frag_size(frag); 3021
3022 *nskb_frag = *frag;
3023 __skb_frag_ref(nskb_frag);
3024 size = skb_frag_size(nskb_frag);
3006 3025
3007 if (pos < offset) { 3026 if (pos < offset) {
3008 frag->page_offset += offset - pos; 3027 nskb_frag->page_offset += offset - pos;
3009 skb_frag_size_sub(frag, offset - pos); 3028 skb_frag_size_sub(nskb_frag, offset - pos);
3010 } 3029 }
3011 3030
3012 skb_shinfo(nskb)->nr_frags++; 3031 skb_shinfo(nskb)->nr_frags++;
3013 3032
3014 if (pos + size <= offset + len) { 3033 if (pos + size <= offset + len) {
3015 i++; 3034 i++;
3016 skb_frag++; 3035 frag++;
3017 pos += size; 3036 pos += size;
3018 } else { 3037 } else {
3019 skb_frag_size_sub(frag, pos + size - (offset + len)); 3038 skb_frag_size_sub(nskb_frag, pos + size - (offset + len));
3020 goto skip_fraglist; 3039 goto skip_fraglist;
3021 } 3040 }
3022 3041
3023 frag++; 3042 nskb_frag++;
3024 } 3043 }
3025 3044
3026skip_fraglist: 3045skip_fraglist:
@@ -3034,7 +3053,7 @@ perform_csum_check:
3034 nskb->len - doffset, 0); 3053 nskb->len - doffset, 0);
3035 nskb->ip_summed = CHECKSUM_NONE; 3054 nskb->ip_summed = CHECKSUM_NONE;
3036 } 3055 }
3037 } while ((offset += len) < skb->len); 3056 } while ((offset += len) < head_skb->len);
3038 3057
3039 return segs; 3058 return segs;
3040 3059
diff --git a/net/core/sock.c b/net/core/sock.c
index 0c127dcdf6a8..c0fc6bdad1e3 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1775,7 +1775,9 @@ struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,
1775 while (order) { 1775 while (order) {
1776 if (npages >= 1 << order) { 1776 if (npages >= 1 << order) {
1777 page = alloc_pages(sk->sk_allocation | 1777 page = alloc_pages(sk->sk_allocation |
1778 __GFP_COMP | __GFP_NOWARN, 1778 __GFP_COMP |
1779 __GFP_NOWARN |
1780 __GFP_NORETRY,
1779 order); 1781 order);
1780 if (page) 1782 if (page)
1781 goto fill_page; 1783 goto fill_page;
@@ -1845,7 +1847,7 @@ bool skb_page_frag_refill(unsigned int sz, struct page_frag *pfrag, gfp_t prio)
1845 gfp_t gfp = prio; 1847 gfp_t gfp = prio;
1846 1848
1847 if (order) 1849 if (order)
1848 gfp |= __GFP_COMP | __GFP_NOWARN; 1850 gfp |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY;
1849 pfrag->page = alloc_pages(gfp, order); 1851 pfrag->page = alloc_pages(gfp, order);
1850 if (likely(pfrag->page)) { 1852 if (likely(pfrag->page)) {
1851 pfrag->offset = 0; 1853 pfrag->offset = 0;
@@ -2355,10 +2357,13 @@ void release_sock(struct sock *sk)
2355 if (sk->sk_backlog.tail) 2357 if (sk->sk_backlog.tail)
2356 __release_sock(sk); 2358 __release_sock(sk);
2357 2359
2360 /* Warning : release_cb() might need to release sk ownership,
2361 * ie call sock_release_ownership(sk) before us.
2362 */
2358 if (sk->sk_prot->release_cb) 2363 if (sk->sk_prot->release_cb)
2359 sk->sk_prot->release_cb(sk); 2364 sk->sk_prot->release_cb(sk);
2360 2365
2361 sk->sk_lock.owned = 0; 2366 sock_release_ownership(sk);
2362 if (waitqueue_active(&sk->sk_lock.wq)) 2367 if (waitqueue_active(&sk->sk_lock.wq))
2363 wake_up(&sk->sk_lock.wq); 2368 wake_up(&sk->sk_lock.wq);
2364 spin_unlock_bh(&sk->sk_lock.slock); 2369 spin_unlock_bh(&sk->sk_lock.slock);
diff --git a/net/dccp/ccids/lib/tfrc.c b/net/dccp/ccids/lib/tfrc.c
index c073b81a1f3e..62b5828acde0 100644
--- a/net/dccp/ccids/lib/tfrc.c
+++ b/net/dccp/ccids/lib/tfrc.c
@@ -8,7 +8,7 @@
8#include "tfrc.h" 8#include "tfrc.h"
9 9
10#ifdef CONFIG_IP_DCCP_TFRC_DEBUG 10#ifdef CONFIG_IP_DCCP_TFRC_DEBUG
11static bool tfrc_debug; 11bool tfrc_debug;
12module_param(tfrc_debug, bool, 0644); 12module_param(tfrc_debug, bool, 0644);
13MODULE_PARM_DESC(tfrc_debug, "Enable TFRC debug messages"); 13MODULE_PARM_DESC(tfrc_debug, "Enable TFRC debug messages");
14#endif 14#endif
diff --git a/net/dccp/ccids/lib/tfrc.h b/net/dccp/ccids/lib/tfrc.h
index a3d8f7c76ae0..40ee7d62b652 100644
--- a/net/dccp/ccids/lib/tfrc.h
+++ b/net/dccp/ccids/lib/tfrc.h
@@ -21,6 +21,7 @@
21#include "packet_history.h" 21#include "packet_history.h"
22 22
23#ifdef CONFIG_IP_DCCP_TFRC_DEBUG 23#ifdef CONFIG_IP_DCCP_TFRC_DEBUG
24extern bool tfrc_debug;
24#define tfrc_pr_debug(format, a...) DCCP_PR_DEBUG(tfrc_debug, format, ##a) 25#define tfrc_pr_debug(format, a...) DCCP_PR_DEBUG(tfrc_debug, format, ##a)
25#else 26#else
26#define tfrc_pr_debug(format, a...) 27#define tfrc_pr_debug(format, a...)
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 2954dcbca832..4c04848953bd 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -2104,8 +2104,6 @@ static struct notifier_block dn_dev_notifier = {
2104 .notifier_call = dn_device_event, 2104 .notifier_call = dn_device_event,
2105}; 2105};
2106 2106
2107extern int dn_route_rcv(struct sk_buff *, struct net_device *, struct packet_type *, struct net_device *);
2108
2109static struct packet_type dn_dix_packet_type __read_mostly = { 2107static struct packet_type dn_dix_packet_type __read_mostly = {
2110 .type = cpu_to_be16(ETH_P_DNA_RT), 2108 .type = cpu_to_be16(ETH_P_DNA_RT),
2111 .func = dn_route_rcv, 2109 .func = dn_route_rcv,
@@ -2353,9 +2351,6 @@ static const struct proto_ops dn_proto_ops = {
2353 .sendpage = sock_no_sendpage, 2351 .sendpage = sock_no_sendpage,
2354}; 2352};
2355 2353
2356void dn_register_sysctl(void);
2357void dn_unregister_sysctl(void);
2358
2359MODULE_DESCRIPTION("The Linux DECnet Network Protocol"); 2354MODULE_DESCRIPTION("The Linux DECnet Network Protocol");
2360MODULE_AUTHOR("Linux DECnet Project Team"); 2355MODULE_AUTHOR("Linux DECnet Project Team");
2361MODULE_LICENSE("GPL"); 2356MODULE_LICENSE("GPL");
diff --git a/net/hsr/hsr_framereg.c b/net/hsr/hsr_framereg.c
index 327060c6c874..7ae0d7f6dbd0 100644
--- a/net/hsr/hsr_framereg.c
+++ b/net/hsr/hsr_framereg.c
@@ -297,7 +297,7 @@ static bool seq_nr_after(u16 a, u16 b)
297 297
298void hsr_register_frame_in(struct node_entry *node, enum hsr_dev_idx dev_idx) 298void hsr_register_frame_in(struct node_entry *node, enum hsr_dev_idx dev_idx)
299{ 299{
300 if ((dev_idx < 0) || (dev_idx >= HSR_MAX_DEV)) { 300 if ((dev_idx < 0) || (dev_idx >= HSR_MAX_SLAVE)) {
301 WARN_ONCE(1, "%s: Invalid dev_idx (%d)\n", __func__, dev_idx); 301 WARN_ONCE(1, "%s: Invalid dev_idx (%d)\n", __func__, dev_idx);
302 return; 302 return;
303 } 303 }
diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index 48b25c0af4d0..8edfea5da572 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -106,7 +106,6 @@ static int lowpan_header_create(struct sk_buff *skb,
106 unsigned short type, const void *_daddr, 106 unsigned short type, const void *_daddr,
107 const void *_saddr, unsigned int len) 107 const void *_saddr, unsigned int len)
108{ 108{
109 struct ipv6hdr *hdr;
110 const u8 *saddr = _saddr; 109 const u8 *saddr = _saddr;
111 const u8 *daddr = _daddr; 110 const u8 *daddr = _daddr;
112 struct ieee802154_addr sa, da; 111 struct ieee802154_addr sa, da;
@@ -117,8 +116,6 @@ static int lowpan_header_create(struct sk_buff *skb,
117 if (type != ETH_P_IPV6) 116 if (type != ETH_P_IPV6)
118 return 0; 117 return 0;
119 118
120 hdr = ipv6_hdr(skb);
121
122 if (!saddr) 119 if (!saddr)
123 saddr = dev->dev_addr; 120 saddr = dev->dev_addr;
124 121
@@ -533,7 +530,27 @@ static struct header_ops lowpan_header_ops = {
533 .create = lowpan_header_create, 530 .create = lowpan_header_create,
534}; 531};
535 532
533static struct lock_class_key lowpan_tx_busylock;
534static struct lock_class_key lowpan_netdev_xmit_lock_key;
535
536static void lowpan_set_lockdep_class_one(struct net_device *dev,
537 struct netdev_queue *txq,
538 void *_unused)
539{
540 lockdep_set_class(&txq->_xmit_lock,
541 &lowpan_netdev_xmit_lock_key);
542}
543
544
545static int lowpan_dev_init(struct net_device *dev)
546{
547 netdev_for_each_tx_queue(dev, lowpan_set_lockdep_class_one, NULL);
548 dev->qdisc_tx_busylock = &lowpan_tx_busylock;
549 return 0;
550}
551
536static const struct net_device_ops lowpan_netdev_ops = { 552static const struct net_device_ops lowpan_netdev_ops = {
553 .ndo_init = lowpan_dev_init,
537 .ndo_start_xmit = lowpan_xmit, 554 .ndo_start_xmit = lowpan_xmit,
538 .ndo_set_mac_address = lowpan_set_address, 555 .ndo_set_mac_address = lowpan_set_address,
539}; 556};
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index ecd2c3f245ce..19ab78aca547 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1296,8 +1296,11 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb,
1296 1296
1297 segs = ERR_PTR(-EPROTONOSUPPORT); 1297 segs = ERR_PTR(-EPROTONOSUPPORT);
1298 1298
1299 /* Note : following gso_segment() might change skb->encapsulation */ 1299 if (skb->encapsulation &&
1300 udpfrag = !skb->encapsulation && proto == IPPROTO_UDP; 1300 skb_shinfo(skb)->gso_type & (SKB_GSO_SIT|SKB_GSO_IPIP))
1301 udpfrag = proto == IPPROTO_UDP && encap;
1302 else
1303 udpfrag = proto == IPPROTO_UDP && !skb->encapsulation;
1301 1304
1302 ops = rcu_dereference(inet_offloads[proto]); 1305 ops = rcu_dereference(inet_offloads[proto]);
1303 if (likely(ops && ops->callbacks.gso_segment)) 1306 if (likely(ops && ops->callbacks.gso_segment))
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index ac2dff3c2c1c..bdbf68bb2e2d 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1443,7 +1443,8 @@ static size_t inet_nlmsg_size(void)
1443 + nla_total_size(4) /* IFA_LOCAL */ 1443 + nla_total_size(4) /* IFA_LOCAL */
1444 + nla_total_size(4) /* IFA_BROADCAST */ 1444 + nla_total_size(4) /* IFA_BROADCAST */
1445 + nla_total_size(IFNAMSIZ) /* IFA_LABEL */ 1445 + nla_total_size(IFNAMSIZ) /* IFA_LABEL */
1446 + nla_total_size(4); /* IFA_FLAGS */ 1446 + nla_total_size(4) /* IFA_FLAGS */
1447 + nla_total_size(sizeof(struct ifa_cacheinfo)); /* IFA_CACHEINFO */
1447} 1448}
1448 1449
1449static inline u32 cstamp_delta(unsigned long cstamp) 1450static inline u32 cstamp_delta(unsigned long cstamp)
diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c
index 1863422fb7d5..250be7421ab3 100644
--- a/net/ipv4/gre_demux.c
+++ b/net/ipv4/gre_demux.c
@@ -182,6 +182,14 @@ static int gre_cisco_rcv(struct sk_buff *skb)
182 int i; 182 int i;
183 bool csum_err = false; 183 bool csum_err = false;
184 184
185#ifdef CONFIG_NET_IPGRE_BROADCAST
186 if (ipv4_is_multicast(ip_hdr(skb)->daddr)) {
187 /* Looped back packet, drop it! */
188 if (rt_is_output_route(skb_rtable(skb)))
189 goto drop;
190 }
191#endif
192
185 if (parse_gre_header(skb, &tpi, &csum_err) < 0) 193 if (parse_gre_header(skb, &tpi, &csum_err) < 0)
186 goto drop; 194 goto drop;
187 195
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index bb075fc9a14f..3b01959bf4bb 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -208,7 +208,7 @@ int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f, bool force)
208 } 208 }
209 209
210 work = frag_mem_limit(nf) - nf->low_thresh; 210 work = frag_mem_limit(nf) - nf->low_thresh;
211 while (work > 0) { 211 while (work > 0 || force) {
212 spin_lock(&nf->lru_lock); 212 spin_lock(&nf->lru_lock);
213 213
214 if (list_empty(&nf->lru_list)) { 214 if (list_empty(&nf->lru_list)) {
@@ -278,9 +278,10 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
278 278
279 atomic_inc(&qp->refcnt); 279 atomic_inc(&qp->refcnt);
280 hlist_add_head(&qp->list, &hb->chain); 280 hlist_add_head(&qp->list, &hb->chain);
281 inet_frag_lru_add(nf, qp);
281 spin_unlock(&hb->chain_lock); 282 spin_unlock(&hb->chain_lock);
282 read_unlock(&f->lock); 283 read_unlock(&f->lock);
283 inet_frag_lru_add(nf, qp); 284
284 return qp; 285 return qp;
285} 286}
286 287
diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
index e9f1217a8afd..f3869c186d97 100644
--- a/net/ipv4/ip_forward.c
+++ b/net/ipv4/ip_forward.c
@@ -39,6 +39,71 @@
39#include <net/route.h> 39#include <net/route.h>
40#include <net/xfrm.h> 40#include <net/xfrm.h>
41 41
42static bool ip_may_fragment(const struct sk_buff *skb)
43{
44 return unlikely((ip_hdr(skb)->frag_off & htons(IP_DF)) == 0) ||
45 !skb->local_df;
46}
47
48static bool ip_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
49{
50 if (skb->len <= mtu || skb->local_df)
51 return false;
52
53 if (skb_is_gso(skb) && skb_gso_network_seglen(skb) <= mtu)
54 return false;
55
56 return true;
57}
58
59static bool ip_gso_exceeds_dst_mtu(const struct sk_buff *skb)
60{
61 unsigned int mtu;
62
63 if (skb->local_df || !skb_is_gso(skb))
64 return false;
65
66 mtu = ip_dst_mtu_maybe_forward(skb_dst(skb), true);
67
68 /* if seglen > mtu, do software segmentation for IP fragmentation on
69 * output. DF bit cannot be set since ip_forward would have sent
70 * icmp error.
71 */
72 return skb_gso_network_seglen(skb) > mtu;
73}
74
75/* called if GSO skb needs to be fragmented on forward */
76static int ip_forward_finish_gso(struct sk_buff *skb)
77{
78 struct dst_entry *dst = skb_dst(skb);
79 netdev_features_t features;
80 struct sk_buff *segs;
81 int ret = 0;
82
83 features = netif_skb_dev_features(skb, dst->dev);
84 segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
85 if (IS_ERR(segs)) {
86 kfree_skb(skb);
87 return -ENOMEM;
88 }
89
90 consume_skb(skb);
91
92 do {
93 struct sk_buff *nskb = segs->next;
94 int err;
95
96 segs->next = NULL;
97 err = dst_output(segs);
98
99 if (err && ret == 0)
100 ret = err;
101 segs = nskb;
102 } while (segs);
103
104 return ret;
105}
106
42static int ip_forward_finish(struct sk_buff *skb) 107static int ip_forward_finish(struct sk_buff *skb)
43{ 108{
44 struct ip_options *opt = &(IPCB(skb)->opt); 109 struct ip_options *opt = &(IPCB(skb)->opt);
@@ -49,6 +114,9 @@ static int ip_forward_finish(struct sk_buff *skb)
49 if (unlikely(opt->optlen)) 114 if (unlikely(opt->optlen))
50 ip_forward_options(skb); 115 ip_forward_options(skb);
51 116
117 if (ip_gso_exceeds_dst_mtu(skb))
118 return ip_forward_finish_gso(skb);
119
52 return dst_output(skb); 120 return dst_output(skb);
53} 121}
54 122
@@ -91,8 +159,7 @@ int ip_forward(struct sk_buff *skb)
91 159
92 IPCB(skb)->flags |= IPSKB_FORWARDED; 160 IPCB(skb)->flags |= IPSKB_FORWARDED;
93 mtu = ip_dst_mtu_maybe_forward(&rt->dst, true); 161 mtu = ip_dst_mtu_maybe_forward(&rt->dst, true);
94 if (unlikely(skb->len > mtu && !skb_is_gso(skb) && 162 if (!ip_may_fragment(skb) && ip_exceeds_mtu(skb, mtu)) {
95 (ip_hdr(skb)->frag_off & htons(IP_DF))) && !skb->local_df) {
96 IP_INC_STATS(dev_net(rt->dst.dev), IPSTATS_MIB_FRAGFAILS); 163 IP_INC_STATS(dev_net(rt->dst.dev), IPSTATS_MIB_FRAGFAILS);
97 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, 164 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
98 htonl(mtu)); 165 htonl(mtu));
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 8971780aec7c..73c6b63bba74 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -422,9 +422,6 @@ static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from)
422 to->tc_index = from->tc_index; 422 to->tc_index = from->tc_index;
423#endif 423#endif
424 nf_copy(to, from); 424 nf_copy(to, from);
425#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
426 to->nf_trace = from->nf_trace;
427#endif
428#if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE) 425#if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
429 to->ipvs_property = from->ipvs_property; 426 to->ipvs_property = from->ipvs_property;
430#endif 427#endif
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index bd28f386bd02..a82a22d8f77f 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -93,83 +93,32 @@ static void tunnel_dst_reset(struct ip_tunnel *t)
93 tunnel_dst_set(t, NULL); 93 tunnel_dst_set(t, NULL);
94} 94}
95 95
96static void tunnel_dst_reset_all(struct ip_tunnel *t) 96void ip_tunnel_dst_reset_all(struct ip_tunnel *t)
97{ 97{
98 int i; 98 int i;
99 99
100 for_each_possible_cpu(i) 100 for_each_possible_cpu(i)
101 __tunnel_dst_set(per_cpu_ptr(t->dst_cache, i), NULL); 101 __tunnel_dst_set(per_cpu_ptr(t->dst_cache, i), NULL);
102} 102}
103EXPORT_SYMBOL(ip_tunnel_dst_reset_all);
103 104
104static struct dst_entry *tunnel_dst_get(struct ip_tunnel *t) 105static struct rtable *tunnel_rtable_get(struct ip_tunnel *t, u32 cookie)
105{ 106{
106 struct dst_entry *dst; 107 struct dst_entry *dst;
107 108
108 rcu_read_lock(); 109 rcu_read_lock();
109 dst = rcu_dereference(this_cpu_ptr(t->dst_cache)->dst); 110 dst = rcu_dereference(this_cpu_ptr(t->dst_cache)->dst);
110 if (dst) 111 if (dst) {
112 if (dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
113 rcu_read_unlock();
114 tunnel_dst_reset(t);
115 return NULL;
116 }
111 dst_hold(dst); 117 dst_hold(dst);
112 rcu_read_unlock();
113 return dst;
114}
115
116static struct dst_entry *tunnel_dst_check(struct ip_tunnel *t, u32 cookie)
117{
118 struct dst_entry *dst = tunnel_dst_get(t);
119
120 if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
121 tunnel_dst_reset(t);
122 return NULL;
123 } 118 }
124 119 rcu_read_unlock();
125 return dst; 120 return (struct rtable *)dst;
126}
127
128/* Often modified stats are per cpu, other are shared (netdev->stats) */
129struct rtnl_link_stats64 *ip_tunnel_get_stats64(struct net_device *dev,
130 struct rtnl_link_stats64 *tot)
131{
132 int i;
133
134 for_each_possible_cpu(i) {
135 const struct pcpu_sw_netstats *tstats =
136 per_cpu_ptr(dev->tstats, i);
137 u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
138 unsigned int start;
139
140 do {
141 start = u64_stats_fetch_begin_bh(&tstats->syncp);
142 rx_packets = tstats->rx_packets;
143 tx_packets = tstats->tx_packets;
144 rx_bytes = tstats->rx_bytes;
145 tx_bytes = tstats->tx_bytes;
146 } while (u64_stats_fetch_retry_bh(&tstats->syncp, start));
147
148 tot->rx_packets += rx_packets;
149 tot->tx_packets += tx_packets;
150 tot->rx_bytes += rx_bytes;
151 tot->tx_bytes += tx_bytes;
152 }
153
154 tot->multicast = dev->stats.multicast;
155
156 tot->rx_crc_errors = dev->stats.rx_crc_errors;
157 tot->rx_fifo_errors = dev->stats.rx_fifo_errors;
158 tot->rx_length_errors = dev->stats.rx_length_errors;
159 tot->rx_frame_errors = dev->stats.rx_frame_errors;
160 tot->rx_errors = dev->stats.rx_errors;
161
162 tot->tx_fifo_errors = dev->stats.tx_fifo_errors;
163 tot->tx_carrier_errors = dev->stats.tx_carrier_errors;
164 tot->tx_dropped = dev->stats.tx_dropped;
165 tot->tx_aborted_errors = dev->stats.tx_aborted_errors;
166 tot->tx_errors = dev->stats.tx_errors;
167
168 tot->collisions = dev->stats.collisions;
169
170 return tot;
171} 121}
172EXPORT_SYMBOL_GPL(ip_tunnel_get_stats64);
173 122
174static bool ip_tunnel_key_match(const struct ip_tunnel_parm *p, 123static bool ip_tunnel_key_match(const struct ip_tunnel_parm *p,
175 __be16 flags, __be32 key) 124 __be16 flags, __be32 key)
@@ -467,9 +416,6 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
467 416
468#ifdef CONFIG_NET_IPGRE_BROADCAST 417#ifdef CONFIG_NET_IPGRE_BROADCAST
469 if (ipv4_is_multicast(iph->daddr)) { 418 if (ipv4_is_multicast(iph->daddr)) {
470 /* Looped back packet, drop it! */
471 if (rt_is_output_route(skb_rtable(skb)))
472 goto drop;
473 tunnel->dev->stats.multicast++; 419 tunnel->dev->stats.multicast++;
474 skb->pkt_type = PACKET_BROADCAST; 420 skb->pkt_type = PACKET_BROADCAST;
475 } 421 }
@@ -584,7 +530,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
584 struct flowi4 fl4; 530 struct flowi4 fl4;
585 u8 tos, ttl; 531 u8 tos, ttl;
586 __be16 df; 532 __be16 df;
587 struct rtable *rt = NULL; /* Route to the other host */ 533 struct rtable *rt; /* Route to the other host */
588 unsigned int max_headroom; /* The extra header space needed */ 534 unsigned int max_headroom; /* The extra header space needed */
589 __be32 dst; 535 __be32 dst;
590 int err; 536 int err;
@@ -657,8 +603,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
657 init_tunnel_flow(&fl4, protocol, dst, tnl_params->saddr, 603 init_tunnel_flow(&fl4, protocol, dst, tnl_params->saddr,
658 tunnel->parms.o_key, RT_TOS(tos), tunnel->parms.link); 604 tunnel->parms.o_key, RT_TOS(tos), tunnel->parms.link);
659 605
660 if (connected) 606 rt = connected ? tunnel_rtable_get(tunnel, 0) : NULL;
661 rt = (struct rtable *)tunnel_dst_check(tunnel, 0);
662 607
663 if (!rt) { 608 if (!rt) {
664 rt = ip_route_output_key(tunnel->net, &fl4); 609 rt = ip_route_output_key(tunnel->net, &fl4);
@@ -766,7 +711,7 @@ static void ip_tunnel_update(struct ip_tunnel_net *itn,
766 if (set_mtu) 711 if (set_mtu)
767 dev->mtu = mtu; 712 dev->mtu = mtu;
768 } 713 }
769 tunnel_dst_reset_all(t); 714 ip_tunnel_dst_reset_all(t);
770 netdev_state_change(dev); 715 netdev_state_change(dev);
771} 716}
772 717
@@ -1095,7 +1040,7 @@ void ip_tunnel_uninit(struct net_device *dev)
1095 if (itn->fb_tunnel_dev != dev) 1040 if (itn->fb_tunnel_dev != dev)
1096 ip_tunnel_del(netdev_priv(dev)); 1041 ip_tunnel_del(netdev_priv(dev));
1097 1042
1098 tunnel_dst_reset_all(tunnel); 1043 ip_tunnel_dst_reset_all(tunnel);
1099} 1044}
1100EXPORT_SYMBOL_GPL(ip_tunnel_uninit); 1045EXPORT_SYMBOL_GPL(ip_tunnel_uninit);
1101 1046
diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index 6156f4ef5e91..8d69626f2206 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -148,3 +148,49 @@ error:
148 return ERR_PTR(err); 148 return ERR_PTR(err);
149} 149}
150EXPORT_SYMBOL_GPL(iptunnel_handle_offloads); 150EXPORT_SYMBOL_GPL(iptunnel_handle_offloads);
151
152/* Often modified stats are per cpu, other are shared (netdev->stats) */
153struct rtnl_link_stats64 *ip_tunnel_get_stats64(struct net_device *dev,
154 struct rtnl_link_stats64 *tot)
155{
156 int i;
157
158 for_each_possible_cpu(i) {
159 const struct pcpu_sw_netstats *tstats =
160 per_cpu_ptr(dev->tstats, i);
161 u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
162 unsigned int start;
163
164 do {
165 start = u64_stats_fetch_begin_bh(&tstats->syncp);
166 rx_packets = tstats->rx_packets;
167 tx_packets = tstats->tx_packets;
168 rx_bytes = tstats->rx_bytes;
169 tx_bytes = tstats->tx_bytes;
170 } while (u64_stats_fetch_retry_bh(&tstats->syncp, start));
171
172 tot->rx_packets += rx_packets;
173 tot->tx_packets += tx_packets;
174 tot->rx_bytes += rx_bytes;
175 tot->tx_bytes += tx_bytes;
176 }
177
178 tot->multicast = dev->stats.multicast;
179
180 tot->rx_crc_errors = dev->stats.rx_crc_errors;
181 tot->rx_fifo_errors = dev->stats.rx_fifo_errors;
182 tot->rx_length_errors = dev->stats.rx_length_errors;
183 tot->rx_frame_errors = dev->stats.rx_frame_errors;
184 tot->rx_errors = dev->stats.rx_errors;
185
186 tot->tx_fifo_errors = dev->stats.tx_fifo_errors;
187 tot->tx_carrier_errors = dev->stats.tx_carrier_errors;
188 tot->tx_dropped = dev->stats.tx_dropped;
189 tot->tx_aborted_errors = dev->stats.tx_aborted_errors;
190 tot->tx_errors = dev->stats.tx_errors;
191
192 tot->collisions = dev->stats.collisions;
193
194 return tot;
195}
196EXPORT_SYMBOL_GPL(ip_tunnel_get_stats64);
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index efa1138fa523..b3e86ea7b71b 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -273,7 +273,7 @@ static int __init ic_open_devs(void)
273 273
274 msleep(1); 274 msleep(1);
275 275
276 if time_before(jiffies, next_msg) 276 if (time_before(jiffies, next_msg))
277 continue; 277 continue;
278 278
279 elapsed = jiffies_to_msecs(jiffies - start); 279 elapsed = jiffies_to_msecs(jiffies - start);
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index b9b3472975ba..28863570dd60 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -2255,13 +2255,14 @@ int ipmr_get_route(struct net *net, struct sk_buff *skb,
2255} 2255}
2256 2256
2257static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, 2257static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
2258 u32 portid, u32 seq, struct mfc_cache *c, int cmd) 2258 u32 portid, u32 seq, struct mfc_cache *c, int cmd,
2259 int flags)
2259{ 2260{
2260 struct nlmsghdr *nlh; 2261 struct nlmsghdr *nlh;
2261 struct rtmsg *rtm; 2262 struct rtmsg *rtm;
2262 int err; 2263 int err;
2263 2264
2264 nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), NLM_F_MULTI); 2265 nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags);
2265 if (nlh == NULL) 2266 if (nlh == NULL)
2266 return -EMSGSIZE; 2267 return -EMSGSIZE;
2267 2268
@@ -2329,7 +2330,7 @@ static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc,
2329 if (skb == NULL) 2330 if (skb == NULL)
2330 goto errout; 2331 goto errout;
2331 2332
2332 err = ipmr_fill_mroute(mrt, skb, 0, 0, mfc, cmd); 2333 err = ipmr_fill_mroute(mrt, skb, 0, 0, mfc, cmd, 0);
2333 if (err < 0) 2334 if (err < 0)
2334 goto errout; 2335 goto errout;
2335 2336
@@ -2368,7 +2369,8 @@ static int ipmr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
2368 if (ipmr_fill_mroute(mrt, skb, 2369 if (ipmr_fill_mroute(mrt, skb,
2369 NETLINK_CB(cb->skb).portid, 2370 NETLINK_CB(cb->skb).portid,
2370 cb->nlh->nlmsg_seq, 2371 cb->nlh->nlmsg_seq,
2371 mfc, RTM_NEWROUTE) < 0) 2372 mfc, RTM_NEWROUTE,
2373 NLM_F_MULTI) < 0)
2372 goto done; 2374 goto done;
2373next_entry: 2375next_entry:
2374 e++; 2376 e++;
@@ -2382,7 +2384,8 @@ next_entry:
2382 if (ipmr_fill_mroute(mrt, skb, 2384 if (ipmr_fill_mroute(mrt, skb,
2383 NETLINK_CB(cb->skb).portid, 2385 NETLINK_CB(cb->skb).portid,
2384 cb->nlh->nlmsg_seq, 2386 cb->nlh->nlmsg_seq,
2385 mfc, RTM_NEWROUTE) < 0) { 2387 mfc, RTM_NEWROUTE,
2388 NLM_F_MULTI) < 0) {
2386 spin_unlock_bh(&mfc_unres_lock); 2389 spin_unlock_bh(&mfc_unres_lock);
2387 goto done; 2390 goto done;
2388 } 2391 }
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index 81c6910cfa92..a26ce035e3fa 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -61,6 +61,11 @@ config NFT_CHAIN_NAT_IPV4
61 packet transformations such as the source, destination address and 61 packet transformations such as the source, destination address and
62 source and destination ports. 62 source and destination ports.
63 63
64config NFT_REJECT_IPV4
65 depends on NF_TABLES_IPV4
66 default NFT_REJECT
67 tristate
68
64config NF_TABLES_ARP 69config NF_TABLES_ARP
65 depends on NF_TABLES 70 depends on NF_TABLES
66 tristate "ARP nf_tables support" 71 tristate "ARP nf_tables support"
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile
index c16be9d58420..90b82405331e 100644
--- a/net/ipv4/netfilter/Makefile
+++ b/net/ipv4/netfilter/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o
30obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o 30obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o
31obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o 31obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o
32obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o 32obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o
33obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o
33obj-$(CONFIG_NF_TABLES_ARP) += nf_tables_arp.o 34obj-$(CONFIG_NF_TABLES_ARP) += nf_tables_arp.o
34 35
35# generic IP tables 36# generic IP tables
diff --git a/net/ipv4/netfilter/nf_nat_h323.c b/net/ipv4/netfilter/nf_nat_h323.c
index 9eea059dd621..574f7ebba0b6 100644
--- a/net/ipv4/netfilter/nf_nat_h323.c
+++ b/net/ipv4/netfilter/nf_nat_h323.c
@@ -229,7 +229,10 @@ static int nat_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,
229 ret = nf_ct_expect_related(rtcp_exp); 229 ret = nf_ct_expect_related(rtcp_exp);
230 if (ret == 0) 230 if (ret == 0)
231 break; 231 break;
232 else if (ret != -EBUSY) { 232 else if (ret == -EBUSY) {
233 nf_ct_unexpect_related(rtp_exp);
234 continue;
235 } else if (ret < 0) {
233 nf_ct_unexpect_related(rtp_exp); 236 nf_ct_unexpect_related(rtp_exp);
234 nated_port = 0; 237 nated_port = 0;
235 break; 238 break;
diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
index d551e31b416e..7c676671329d 100644
--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
@@ -1198,8 +1198,8 @@ static int snmp_translate(struct nf_conn *ct,
1198 map.to = NOCT1(&ct->tuplehash[!dir].tuple.dst.u3.ip); 1198 map.to = NOCT1(&ct->tuplehash[!dir].tuple.dst.u3.ip);
1199 } else { 1199 } else {
1200 /* DNAT replies */ 1200 /* DNAT replies */
1201 map.from = NOCT1(&ct->tuplehash[dir].tuple.src.u3.ip); 1201 map.from = NOCT1(&ct->tuplehash[!dir].tuple.src.u3.ip);
1202 map.to = NOCT1(&ct->tuplehash[!dir].tuple.dst.u3.ip); 1202 map.to = NOCT1(&ct->tuplehash[dir].tuple.dst.u3.ip);
1203 } 1203 }
1204 1204
1205 if (map.from == map.to) 1205 if (map.from == map.to)
diff --git a/net/ipv4/netfilter/nft_reject_ipv4.c b/net/ipv4/netfilter/nft_reject_ipv4.c
new file mode 100644
index 000000000000..e79718a382f2
--- /dev/null
+++ b/net/ipv4/netfilter/nft_reject_ipv4.c
@@ -0,0 +1,75 @@
1/*
2 * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2013 Eric Leblond <eric@regit.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Development of this code funded by Astaro AG (http://www.astaro.com/)
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/netlink.h>
16#include <linux/netfilter.h>
17#include <linux/netfilter/nf_tables.h>
18#include <net/netfilter/nf_tables.h>
19#include <net/icmp.h>
20#include <net/netfilter/ipv4/nf_reject.h>
21#include <net/netfilter/nft_reject.h>
22
23void nft_reject_ipv4_eval(const struct nft_expr *expr,
24 struct nft_data data[NFT_REG_MAX + 1],
25 const struct nft_pktinfo *pkt)
26{
27 struct nft_reject *priv = nft_expr_priv(expr);
28
29 switch (priv->type) {
30 case NFT_REJECT_ICMP_UNREACH:
31 nf_send_unreach(pkt->skb, priv->icmp_code);
32 break;
33 case NFT_REJECT_TCP_RST:
34 nf_send_reset(pkt->skb, pkt->ops->hooknum);
35 break;
36 }
37
38 data[NFT_REG_VERDICT].verdict = NF_DROP;
39}
40EXPORT_SYMBOL_GPL(nft_reject_ipv4_eval);
41
42static struct nft_expr_type nft_reject_ipv4_type;
43static const struct nft_expr_ops nft_reject_ipv4_ops = {
44 .type = &nft_reject_ipv4_type,
45 .size = NFT_EXPR_SIZE(sizeof(struct nft_reject)),
46 .eval = nft_reject_ipv4_eval,
47 .init = nft_reject_init,
48 .dump = nft_reject_dump,
49};
50
51static struct nft_expr_type nft_reject_ipv4_type __read_mostly = {
52 .family = NFPROTO_IPV4,
53 .name = "reject",
54 .ops = &nft_reject_ipv4_ops,
55 .policy = nft_reject_policy,
56 .maxattr = NFTA_REJECT_MAX,
57 .owner = THIS_MODULE,
58};
59
60static int __init nft_reject_ipv4_module_init(void)
61{
62 return nft_register_expr(&nft_reject_ipv4_type);
63}
64
65static void __exit nft_reject_ipv4_module_exit(void)
66{
67 nft_unregister_expr(&nft_reject_ipv4_type);
68}
69
70module_init(nft_reject_ipv4_module_init);
71module_exit(nft_reject_ipv4_module_exit);
72
73MODULE_LICENSE("GPL");
74MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
75MODULE_ALIAS_NFT_AF_EXPR(AF_INET, "reject");
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 25071b48921c..4c011ec69ed4 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1597,6 +1597,7 @@ static int __mkroute_input(struct sk_buff *skb,
1597 rth->rt_gateway = 0; 1597 rth->rt_gateway = 0;
1598 rth->rt_uses_gateway = 0; 1598 rth->rt_uses_gateway = 0;
1599 INIT_LIST_HEAD(&rth->rt_uncached); 1599 INIT_LIST_HEAD(&rth->rt_uncached);
1600 RT_CACHE_STAT_INC(in_slow_tot);
1600 1601
1601 rth->dst.input = ip_forward; 1602 rth->dst.input = ip_forward;
1602 rth->dst.output = ip_output; 1603 rth->dst.output = ip_output;
@@ -1695,10 +1696,11 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1695 fl4.daddr = daddr; 1696 fl4.daddr = daddr;
1696 fl4.saddr = saddr; 1697 fl4.saddr = saddr;
1697 err = fib_lookup(net, &fl4, &res); 1698 err = fib_lookup(net, &fl4, &res);
1698 if (err != 0) 1699 if (err != 0) {
1700 if (!IN_DEV_FORWARD(in_dev))
1701 err = -EHOSTUNREACH;
1699 goto no_route; 1702 goto no_route;
1700 1703 }
1701 RT_CACHE_STAT_INC(in_slow_tot);
1702 1704
1703 if (res.type == RTN_BROADCAST) 1705 if (res.type == RTN_BROADCAST)
1704 goto brd_input; 1706 goto brd_input;
@@ -1712,8 +1714,10 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1712 goto local_input; 1714 goto local_input;
1713 } 1715 }
1714 1716
1715 if (!IN_DEV_FORWARD(in_dev)) 1717 if (!IN_DEV_FORWARD(in_dev)) {
1718 err = -EHOSTUNREACH;
1716 goto no_route; 1719 goto no_route;
1720 }
1717 if (res.type != RTN_UNICAST) 1721 if (res.type != RTN_UNICAST)
1718 goto martian_destination; 1722 goto martian_destination;
1719 1723
@@ -1768,6 +1772,7 @@ local_input:
1768 rth->rt_gateway = 0; 1772 rth->rt_gateway = 0;
1769 rth->rt_uses_gateway = 0; 1773 rth->rt_uses_gateway = 0;
1770 INIT_LIST_HEAD(&rth->rt_uncached); 1774 INIT_LIST_HEAD(&rth->rt_uncached);
1775 RT_CACHE_STAT_INC(in_slow_tot);
1771 if (res.type == RTN_UNREACHABLE) { 1776 if (res.type == RTN_UNREACHABLE) {
1772 rth->dst.input= ip_error; 1777 rth->dst.input= ip_error;
1773 rth->dst.error= -err; 1778 rth->dst.error= -err;
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 4475b3bb494d..97c8f5620c43 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1044,7 +1044,8 @@ void tcp_free_fastopen_req(struct tcp_sock *tp)
1044 } 1044 }
1045} 1045}
1046 1046
1047static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *size) 1047static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
1048 int *copied, size_t size)
1048{ 1049{
1049 struct tcp_sock *tp = tcp_sk(sk); 1050 struct tcp_sock *tp = tcp_sk(sk);
1050 int err, flags; 1051 int err, flags;
@@ -1059,11 +1060,12 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *size)
1059 if (unlikely(tp->fastopen_req == NULL)) 1060 if (unlikely(tp->fastopen_req == NULL))
1060 return -ENOBUFS; 1061 return -ENOBUFS;
1061 tp->fastopen_req->data = msg; 1062 tp->fastopen_req->data = msg;
1063 tp->fastopen_req->size = size;
1062 1064
1063 flags = (msg->msg_flags & MSG_DONTWAIT) ? O_NONBLOCK : 0; 1065 flags = (msg->msg_flags & MSG_DONTWAIT) ? O_NONBLOCK : 0;
1064 err = __inet_stream_connect(sk->sk_socket, msg->msg_name, 1066 err = __inet_stream_connect(sk->sk_socket, msg->msg_name,
1065 msg->msg_namelen, flags); 1067 msg->msg_namelen, flags);
1066 *size = tp->fastopen_req->copied; 1068 *copied = tp->fastopen_req->copied;
1067 tcp_free_fastopen_req(tp); 1069 tcp_free_fastopen_req(tp);
1068 return err; 1070 return err;
1069} 1071}
@@ -1083,7 +1085,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
1083 1085
1084 flags = msg->msg_flags; 1086 flags = msg->msg_flags;
1085 if (flags & MSG_FASTOPEN) { 1087 if (flags & MSG_FASTOPEN) {
1086 err = tcp_sendmsg_fastopen(sk, msg, &copied_syn); 1088 err = tcp_sendmsg_fastopen(sk, msg, &copied_syn, size);
1087 if (err == -EINPROGRESS && copied_syn > 0) 1089 if (err == -EINPROGRESS && copied_syn > 0)
1088 goto out; 1090 goto out;
1089 else if (err) 1091 else if (err)
@@ -2229,7 +2231,7 @@ adjudge_to_death:
2229 /* This is a (useful) BSD violating of the RFC. There is a 2231 /* This is a (useful) BSD violating of the RFC. There is a
2230 * problem with TCP as specified in that the other end could 2232 * problem with TCP as specified in that the other end could
2231 * keep a socket open forever with no application left this end. 2233 * keep a socket open forever with no application left this end.
2232 * We use a 3 minute timeout (about the same as BSD) then kill 2234 * We use a 1 minute timeout (about the same as BSD) then kill
2233 * our end. If they send after that then tough - BUT: long enough 2235 * our end. If they send after that then tough - BUT: long enough
2234 * that we won't make the old 4*rto = almost no time - whoops 2236 * that we won't make the old 4*rto = almost no time - whoops
2235 * reset mistake. 2237 * reset mistake.
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index ad37bf18ae4b..2388275adb9b 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -290,8 +290,7 @@ bool tcp_is_cwnd_limited(const struct sock *sk, u32 in_flight)
290 left = tp->snd_cwnd - in_flight; 290 left = tp->snd_cwnd - in_flight;
291 if (sk_can_gso(sk) && 291 if (sk_can_gso(sk) &&
292 left * sysctl_tcp_tso_win_divisor < tp->snd_cwnd && 292 left * sysctl_tcp_tso_win_divisor < tp->snd_cwnd &&
293 left * tp->mss_cache < sk->sk_gso_max_size && 293 left < tp->xmit_size_goal_segs)
294 left < sk->sk_gso_max_segs)
295 return true; 294 return true;
296 return left <= tcp_max_tso_deferred_mss(tp); 295 return left <= tcp_max_tso_deferred_mss(tp);
297} 296}
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 65cf90e063d5..eeaac399420d 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -671,6 +671,7 @@ static void tcp_rtt_estimator(struct sock *sk, const __u32 mrtt)
671{ 671{
672 struct tcp_sock *tp = tcp_sk(sk); 672 struct tcp_sock *tp = tcp_sk(sk);
673 long m = mrtt; /* RTT */ 673 long m = mrtt; /* RTT */
674 u32 srtt = tp->srtt;
674 675
675 /* The following amusing code comes from Jacobson's 676 /* The following amusing code comes from Jacobson's
676 * article in SIGCOMM '88. Note that rtt and mdev 677 * article in SIGCOMM '88. Note that rtt and mdev
@@ -688,11 +689,9 @@ static void tcp_rtt_estimator(struct sock *sk, const __u32 mrtt)
688 * does not matter how to _calculate_ it. Seems, it was trap 689 * does not matter how to _calculate_ it. Seems, it was trap
689 * that VJ failed to avoid. 8) 690 * that VJ failed to avoid. 8)
690 */ 691 */
691 if (m == 0) 692 if (srtt != 0) {
692 m = 1; 693 m -= (srtt >> 3); /* m is now error in rtt est */
693 if (tp->srtt != 0) { 694 srtt += m; /* rtt = 7/8 rtt + 1/8 new */
694 m -= (tp->srtt >> 3); /* m is now error in rtt est */
695 tp->srtt += m; /* rtt = 7/8 rtt + 1/8 new */
696 if (m < 0) { 695 if (m < 0) {
697 m = -m; /* m is now abs(error) */ 696 m = -m; /* m is now abs(error) */
698 m -= (tp->mdev >> 2); /* similar update on mdev */ 697 m -= (tp->mdev >> 2); /* similar update on mdev */
@@ -723,11 +722,12 @@ static void tcp_rtt_estimator(struct sock *sk, const __u32 mrtt)
723 } 722 }
724 } else { 723 } else {
725 /* no previous measure. */ 724 /* no previous measure. */
726 tp->srtt = m << 3; /* take the measured time to be rtt */ 725 srtt = m << 3; /* take the measured time to be rtt */
727 tp->mdev = m << 1; /* make sure rto = 3*rtt */ 726 tp->mdev = m << 1; /* make sure rto = 3*rtt */
728 tp->mdev_max = tp->rttvar = max(tp->mdev, tcp_rto_min(sk)); 727 tp->mdev_max = tp->rttvar = max(tp->mdev, tcp_rto_min(sk));
729 tp->rtt_seq = tp->snd_nxt; 728 tp->rtt_seq = tp->snd_nxt;
730 } 729 }
730 tp->srtt = max(1U, srtt);
731} 731}
732 732
733/* Set the sk_pacing_rate to allow proper sizing of TSO packets. 733/* Set the sk_pacing_rate to allow proper sizing of TSO packets.
@@ -746,8 +746,10 @@ static void tcp_update_pacing_rate(struct sock *sk)
746 746
747 rate *= max(tp->snd_cwnd, tp->packets_out); 747 rate *= max(tp->snd_cwnd, tp->packets_out);
748 748
749 /* Correction for small srtt : minimum srtt being 8 (1 jiffy << 3), 749 /* Correction for small srtt and scheduling constraints.
750 * be conservative and assume srtt = 1 (125 us instead of 1.25 ms) 750 * For small rtt, consider noise is too high, and use
751 * the minimal value (srtt = 1 -> 125 us for HZ=1000)
752 *
751 * We probably need usec resolution in the future. 753 * We probably need usec resolution in the future.
752 * Note: This also takes care of possible srtt=0 case, 754 * Note: This also takes care of possible srtt=0 case,
753 * when tcp_rtt_estimator() was not yet called. 755 * when tcp_rtt_estimator() was not yet called.
@@ -1943,8 +1945,9 @@ void tcp_enter_loss(struct sock *sk, int how)
1943 if (skb == tcp_send_head(sk)) 1945 if (skb == tcp_send_head(sk))
1944 break; 1946 break;
1945 1947
1946 if (TCP_SKB_CB(skb)->sacked & TCPCB_RETRANS) 1948 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS)
1947 tp->undo_marker = 0; 1949 tp->undo_marker = 0;
1950
1948 TCP_SKB_CB(skb)->sacked &= (~TCPCB_TAGBITS)|TCPCB_SACKED_ACKED; 1951 TCP_SKB_CB(skb)->sacked &= (~TCPCB_TAGBITS)|TCPCB_SACKED_ACKED;
1949 if (!(TCP_SKB_CB(skb)->sacked&TCPCB_SACKED_ACKED) || how) { 1952 if (!(TCP_SKB_CB(skb)->sacked&TCPCB_SACKED_ACKED) || how) {
1950 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_ACKED; 1953 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_ACKED;
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 3cf976510497..1e4eac779f51 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2628,7 +2628,7 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
2628{ 2628{
2629 __be32 dest, src; 2629 __be32 dest, src;
2630 __u16 destp, srcp; 2630 __u16 destp, srcp;
2631 long delta = tw->tw_ttd - jiffies; 2631 s32 delta = tw->tw_ttd - inet_tw_time_stamp();
2632 2632
2633 dest = tw->tw_daddr; 2633 dest = tw->tw_daddr;
2634 src = tw->tw_rcv_saddr; 2634 src = tw->tw_rcv_saddr;
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 03d26b85eab8..17a11e65e57f 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -698,7 +698,8 @@ static void tcp_tsq_handler(struct sock *sk)
698 if ((1 << sk->sk_state) & 698 if ((1 << sk->sk_state) &
699 (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_CLOSING | 699 (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_CLOSING |
700 TCPF_CLOSE_WAIT | TCPF_LAST_ACK)) 700 TCPF_CLOSE_WAIT | TCPF_LAST_ACK))
701 tcp_write_xmit(sk, tcp_current_mss(sk), 0, 0, GFP_ATOMIC); 701 tcp_write_xmit(sk, tcp_current_mss(sk), tcp_sk(sk)->nonagle,
702 0, GFP_ATOMIC);
702} 703}
703/* 704/*
704 * One tasklet per cpu tries to send more skbs. 705 * One tasklet per cpu tries to send more skbs.
@@ -766,6 +767,17 @@ void tcp_release_cb(struct sock *sk)
766 if (flags & (1UL << TCP_TSQ_DEFERRED)) 767 if (flags & (1UL << TCP_TSQ_DEFERRED))
767 tcp_tsq_handler(sk); 768 tcp_tsq_handler(sk);
768 769
770 /* Here begins the tricky part :
771 * We are called from release_sock() with :
772 * 1) BH disabled
773 * 2) sk_lock.slock spinlock held
774 * 3) socket owned by us (sk->sk_lock.owned == 1)
775 *
776 * But following code is meant to be called from BH handlers,
777 * so we should keep BH disabled, but early release socket ownership
778 */
779 sock_release_ownership(sk);
780
769 if (flags & (1UL << TCP_WRITE_TIMER_DEFERRED)) { 781 if (flags & (1UL << TCP_WRITE_TIMER_DEFERRED)) {
770 tcp_write_timer_handler(sk); 782 tcp_write_timer_handler(sk);
771 __sock_put(sk); 783 __sock_put(sk);
@@ -863,8 +875,8 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
863 875
864 if (unlikely(skb->fclone == SKB_FCLONE_ORIG && 876 if (unlikely(skb->fclone == SKB_FCLONE_ORIG &&
865 fclone->fclone == SKB_FCLONE_CLONE)) 877 fclone->fclone == SKB_FCLONE_CLONE))
866 NET_INC_STATS_BH(sock_net(sk), 878 NET_INC_STATS(sock_net(sk),
867 LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES); 879 LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES);
868 880
869 if (unlikely(skb_cloned(skb))) 881 if (unlikely(skb_cloned(skb)))
870 skb = pskb_copy(skb, gfp_mask); 882 skb = pskb_copy(skb, gfp_mask);
@@ -1904,7 +1916,15 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
1904 1916
1905 if (atomic_read(&sk->sk_wmem_alloc) > limit) { 1917 if (atomic_read(&sk->sk_wmem_alloc) > limit) {
1906 set_bit(TSQ_THROTTLED, &tp->tsq_flags); 1918 set_bit(TSQ_THROTTLED, &tp->tsq_flags);
1907 break; 1919 /* It is possible TX completion already happened
1920 * before we set TSQ_THROTTLED, so we must
1921 * test again the condition.
1922 * We abuse smp_mb__after_clear_bit() because
1923 * there is no smp_mb__after_set_bit() yet
1924 */
1925 smp_mb__after_clear_bit();
1926 if (atomic_read(&sk->sk_wmem_alloc) > limit)
1927 break;
1908 } 1928 }
1909 1929
1910 limit = mss_now; 1930 limit = mss_now;
@@ -1977,7 +1997,7 @@ bool tcp_schedule_loss_probe(struct sock *sk)
1977 /* Schedule a loss probe in 2*RTT for SACK capable connections 1997 /* Schedule a loss probe in 2*RTT for SACK capable connections
1978 * in Open state, that are either limited by cwnd or application. 1998 * in Open state, that are either limited by cwnd or application.
1979 */ 1999 */
1980 if (sysctl_tcp_early_retrans < 3 || !rtt || !tp->packets_out || 2000 if (sysctl_tcp_early_retrans < 3 || !tp->srtt || !tp->packets_out ||
1981 !tcp_is_sack(tp) || inet_csk(sk)->icsk_ca_state != TCP_CA_Open) 2001 !tcp_is_sack(tp) || inet_csk(sk)->icsk_ca_state != TCP_CA_Open)
1982 return false; 2002 return false;
1983 2003
@@ -2328,6 +2348,7 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
2328 struct tcp_sock *tp = tcp_sk(sk); 2348 struct tcp_sock *tp = tcp_sk(sk);
2329 struct inet_connection_sock *icsk = inet_csk(sk); 2349 struct inet_connection_sock *icsk = inet_csk(sk);
2330 unsigned int cur_mss; 2350 unsigned int cur_mss;
2351 int err;
2331 2352
2332 /* Inconslusive MTU probe */ 2353 /* Inconslusive MTU probe */
2333 if (icsk->icsk_mtup.probe_size) { 2354 if (icsk->icsk_mtup.probe_size) {
@@ -2391,11 +2412,15 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
2391 skb_headroom(skb) >= 0xFFFF)) { 2412 skb_headroom(skb) >= 0xFFFF)) {
2392 struct sk_buff *nskb = __pskb_copy(skb, MAX_TCP_HEADER, 2413 struct sk_buff *nskb = __pskb_copy(skb, MAX_TCP_HEADER,
2393 GFP_ATOMIC); 2414 GFP_ATOMIC);
2394 return nskb ? tcp_transmit_skb(sk, nskb, 0, GFP_ATOMIC) : 2415 err = nskb ? tcp_transmit_skb(sk, nskb, 0, GFP_ATOMIC) :
2395 -ENOBUFS; 2416 -ENOBUFS;
2396 } else { 2417 } else {
2397 return tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC); 2418 err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
2398 } 2419 }
2420
2421 if (likely(!err))
2422 TCP_SKB_CB(skb)->sacked |= TCPCB_EVER_RETRANS;
2423 return err;
2399} 2424}
2400 2425
2401int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb) 2426int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
@@ -2899,7 +2924,12 @@ static int tcp_send_syn_data(struct sock *sk, struct sk_buff *syn)
2899 space = __tcp_mtu_to_mss(sk, inet_csk(sk)->icsk_pmtu_cookie) - 2924 space = __tcp_mtu_to_mss(sk, inet_csk(sk)->icsk_pmtu_cookie) -
2900 MAX_TCP_OPTION_SPACE; 2925 MAX_TCP_OPTION_SPACE;
2901 2926
2902 syn_data = skb_copy_expand(syn, skb_headroom(syn), space, 2927 space = min_t(size_t, space, fo->size);
2928
2929 /* limit to order-0 allocations */
2930 space = min_t(size_t, space, SKB_MAX_HEAD(MAX_TCP_HEADER));
2931
2932 syn_data = skb_copy_expand(syn, MAX_TCP_HEADER, space,
2903 sk->sk_allocation); 2933 sk->sk_allocation);
2904 if (syn_data == NULL) 2934 if (syn_data == NULL)
2905 goto fallback; 2935 goto fallback;
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index 25f5cee3a08a..88b4023ecfcf 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -17,6 +17,8 @@
17static DEFINE_SPINLOCK(udp_offload_lock); 17static DEFINE_SPINLOCK(udp_offload_lock);
18static struct udp_offload_priv __rcu *udp_offload_base __read_mostly; 18static struct udp_offload_priv __rcu *udp_offload_base __read_mostly;
19 19
20#define udp_deref_protected(X) rcu_dereference_protected(X, lockdep_is_held(&udp_offload_lock))
21
20struct udp_offload_priv { 22struct udp_offload_priv {
21 struct udp_offload *offload; 23 struct udp_offload *offload;
22 struct rcu_head rcu; 24 struct rcu_head rcu;
@@ -100,8 +102,7 @@ out:
100 102
101int udp_add_offload(struct udp_offload *uo) 103int udp_add_offload(struct udp_offload *uo)
102{ 104{
103 struct udp_offload_priv __rcu **head = &udp_offload_base; 105 struct udp_offload_priv *new_offload = kzalloc(sizeof(*new_offload), GFP_ATOMIC);
104 struct udp_offload_priv *new_offload = kzalloc(sizeof(*new_offload), GFP_KERNEL);
105 106
106 if (!new_offload) 107 if (!new_offload)
107 return -ENOMEM; 108 return -ENOMEM;
@@ -109,8 +110,8 @@ int udp_add_offload(struct udp_offload *uo)
109 new_offload->offload = uo; 110 new_offload->offload = uo;
110 111
111 spin_lock(&udp_offload_lock); 112 spin_lock(&udp_offload_lock);
112 rcu_assign_pointer(new_offload->next, rcu_dereference(*head)); 113 new_offload->next = udp_offload_base;
113 rcu_assign_pointer(*head, new_offload); 114 rcu_assign_pointer(udp_offload_base, new_offload);
114 spin_unlock(&udp_offload_lock); 115 spin_unlock(&udp_offload_lock);
115 116
116 return 0; 117 return 0;
@@ -130,12 +131,12 @@ void udp_del_offload(struct udp_offload *uo)
130 131
131 spin_lock(&udp_offload_lock); 132 spin_lock(&udp_offload_lock);
132 133
133 uo_priv = rcu_dereference(*head); 134 uo_priv = udp_deref_protected(*head);
134 for (; uo_priv != NULL; 135 for (; uo_priv != NULL;
135 uo_priv = rcu_dereference(*head)) { 136 uo_priv = udp_deref_protected(*head)) {
136
137 if (uo_priv->offload == uo) { 137 if (uo_priv->offload == uo) {
138 rcu_assign_pointer(*head, rcu_dereference(uo_priv->next)); 138 rcu_assign_pointer(*head,
139 udp_deref_protected(uo_priv->next));
139 goto unlock; 140 goto unlock;
140 } 141 }
141 head = &uo_priv->next; 142 head = &uo_priv->next;
diff --git a/net/ipv6/Kconfig b/net/ipv6/Kconfig
index d92e5586783e..438a73aa777c 100644
--- a/net/ipv6/Kconfig
+++ b/net/ipv6/Kconfig
@@ -138,6 +138,7 @@ config INET6_XFRM_MODE_ROUTEOPTIMIZATION
138config IPV6_VTI 138config IPV6_VTI
139tristate "Virtual (secure) IPv6: tunneling" 139tristate "Virtual (secure) IPv6: tunneling"
140 select IPV6_TUNNEL 140 select IPV6_TUNNEL
141 select NET_IP_TUNNEL
141 depends on INET6_XFRM_MODE_TUNNEL 142 depends on INET6_XFRM_MODE_TUNNEL
142 ---help--- 143 ---help---
143 Tunneling means encapsulating data of one protocol type within 144 Tunneling means encapsulating data of one protocol type within
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index ad235690684c..6c7fa0853fc7 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -133,10 +133,12 @@ static int ipv6_count_addresses(struct inet6_dev *idev);
133static struct hlist_head inet6_addr_lst[IN6_ADDR_HSIZE]; 133static struct hlist_head inet6_addr_lst[IN6_ADDR_HSIZE];
134static DEFINE_SPINLOCK(addrconf_hash_lock); 134static DEFINE_SPINLOCK(addrconf_hash_lock);
135 135
136static void addrconf_verify(unsigned long); 136static void addrconf_verify(void);
137static void addrconf_verify_rtnl(void);
138static void addrconf_verify_work(struct work_struct *);
137 139
138static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0); 140static struct workqueue_struct *addrconf_wq;
139static DEFINE_SPINLOCK(addrconf_verify_lock); 141static DECLARE_DELAYED_WORK(addr_chk_work, addrconf_verify_work);
140 142
141static void addrconf_join_anycast(struct inet6_ifaddr *ifp); 143static void addrconf_join_anycast(struct inet6_ifaddr *ifp);
142static void addrconf_leave_anycast(struct inet6_ifaddr *ifp); 144static void addrconf_leave_anycast(struct inet6_ifaddr *ifp);
@@ -151,7 +153,7 @@ static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
151 u32 flags, u32 noflags); 153 u32 flags, u32 noflags);
152 154
153static void addrconf_dad_start(struct inet6_ifaddr *ifp); 155static void addrconf_dad_start(struct inet6_ifaddr *ifp);
154static void addrconf_dad_timer(unsigned long data); 156static void addrconf_dad_work(struct work_struct *w);
155static void addrconf_dad_completed(struct inet6_ifaddr *ifp); 157static void addrconf_dad_completed(struct inet6_ifaddr *ifp);
156static void addrconf_dad_run(struct inet6_dev *idev); 158static void addrconf_dad_run(struct inet6_dev *idev);
157static void addrconf_rs_timer(unsigned long data); 159static void addrconf_rs_timer(unsigned long data);
@@ -247,9 +249,9 @@ static void addrconf_del_rs_timer(struct inet6_dev *idev)
247 __in6_dev_put(idev); 249 __in6_dev_put(idev);
248} 250}
249 251
250static void addrconf_del_dad_timer(struct inet6_ifaddr *ifp) 252static void addrconf_del_dad_work(struct inet6_ifaddr *ifp)
251{ 253{
252 if (del_timer(&ifp->dad_timer)) 254 if (cancel_delayed_work(&ifp->dad_work))
253 __in6_ifa_put(ifp); 255 __in6_ifa_put(ifp);
254} 256}
255 257
@@ -261,12 +263,12 @@ static void addrconf_mod_rs_timer(struct inet6_dev *idev,
261 mod_timer(&idev->rs_timer, jiffies + when); 263 mod_timer(&idev->rs_timer, jiffies + when);
262} 264}
263 265
264static void addrconf_mod_dad_timer(struct inet6_ifaddr *ifp, 266static void addrconf_mod_dad_work(struct inet6_ifaddr *ifp,
265 unsigned long when) 267 unsigned long delay)
266{ 268{
267 if (!timer_pending(&ifp->dad_timer)) 269 if (!delayed_work_pending(&ifp->dad_work))
268 in6_ifa_hold(ifp); 270 in6_ifa_hold(ifp);
269 mod_timer(&ifp->dad_timer, jiffies + when); 271 mod_delayed_work(addrconf_wq, &ifp->dad_work, delay);
270} 272}
271 273
272static int snmp6_alloc_dev(struct inet6_dev *idev) 274static int snmp6_alloc_dev(struct inet6_dev *idev)
@@ -751,8 +753,9 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
751 753
752 in6_dev_put(ifp->idev); 754 in6_dev_put(ifp->idev);
753 755
754 if (del_timer(&ifp->dad_timer)) 756 if (cancel_delayed_work(&ifp->dad_work))
755 pr_notice("Timer is still running, when freeing ifa=%p\n", ifp); 757 pr_notice("delayed DAD work was pending while freeing ifa=%p\n",
758 ifp);
756 759
757 if (ifp->state != INET6_IFADDR_STATE_DEAD) { 760 if (ifp->state != INET6_IFADDR_STATE_DEAD) {
758 pr_warn("Freeing alive inet6 address %p\n", ifp); 761 pr_warn("Freeing alive inet6 address %p\n", ifp);
@@ -849,8 +852,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
849 852
850 spin_lock_init(&ifa->lock); 853 spin_lock_init(&ifa->lock);
851 spin_lock_init(&ifa->state_lock); 854 spin_lock_init(&ifa->state_lock);
852 setup_timer(&ifa->dad_timer, addrconf_dad_timer, 855 INIT_DELAYED_WORK(&ifa->dad_work, addrconf_dad_work);
853 (unsigned long)ifa);
854 INIT_HLIST_NODE(&ifa->addr_lst); 856 INIT_HLIST_NODE(&ifa->addr_lst);
855 ifa->scope = scope; 857 ifa->scope = scope;
856 ifa->prefix_len = pfxlen; 858 ifa->prefix_len = pfxlen;
@@ -990,6 +992,8 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
990 enum cleanup_prefix_rt_t action = CLEANUP_PREFIX_RT_NOP; 992 enum cleanup_prefix_rt_t action = CLEANUP_PREFIX_RT_NOP;
991 unsigned long expires; 993 unsigned long expires;
992 994
995 ASSERT_RTNL();
996
993 spin_lock_bh(&ifp->state_lock); 997 spin_lock_bh(&ifp->state_lock);
994 state = ifp->state; 998 state = ifp->state;
995 ifp->state = INET6_IFADDR_STATE_DEAD; 999 ifp->state = INET6_IFADDR_STATE_DEAD;
@@ -1021,7 +1025,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
1021 1025
1022 write_unlock_bh(&ifp->idev->lock); 1026 write_unlock_bh(&ifp->idev->lock);
1023 1027
1024 addrconf_del_dad_timer(ifp); 1028 addrconf_del_dad_work(ifp);
1025 1029
1026 ipv6_ifa_notify(RTM_DELADDR, ifp); 1030 ipv6_ifa_notify(RTM_DELADDR, ifp);
1027 1031
@@ -1103,8 +1107,11 @@ retry:
1103 * Lifetime is greater than REGEN_ADVANCE time units. In particular, 1107 * Lifetime is greater than REGEN_ADVANCE time units. In particular,
1104 * an implementation must not create a temporary address with a zero 1108 * an implementation must not create a temporary address with a zero
1105 * Preferred Lifetime. 1109 * Preferred Lifetime.
1110 * Use age calculation as in addrconf_verify to avoid unnecessary
1111 * temporary addresses being generated.
1106 */ 1112 */
1107 if (tmp_prefered_lft <= regen_advance) { 1113 age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ;
1114 if (tmp_prefered_lft <= regen_advance + age) {
1108 in6_ifa_put(ifp); 1115 in6_ifa_put(ifp);
1109 in6_dev_put(idev); 1116 in6_dev_put(idev);
1110 ret = -1; 1117 ret = -1;
@@ -1601,7 +1608,7 @@ static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed)
1601{ 1608{
1602 if (ifp->flags&IFA_F_PERMANENT) { 1609 if (ifp->flags&IFA_F_PERMANENT) {
1603 spin_lock_bh(&ifp->lock); 1610 spin_lock_bh(&ifp->lock);
1604 addrconf_del_dad_timer(ifp); 1611 addrconf_del_dad_work(ifp);
1605 ifp->flags |= IFA_F_TENTATIVE; 1612 ifp->flags |= IFA_F_TENTATIVE;
1606 if (dad_failed) 1613 if (dad_failed)
1607 ifp->flags |= IFA_F_DADFAILED; 1614 ifp->flags |= IFA_F_DADFAILED;
@@ -1622,20 +1629,21 @@ static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed)
1622 spin_unlock_bh(&ifp->lock); 1629 spin_unlock_bh(&ifp->lock);
1623 } 1630 }
1624 ipv6_del_addr(ifp); 1631 ipv6_del_addr(ifp);
1625 } else 1632 } else {
1626 ipv6_del_addr(ifp); 1633 ipv6_del_addr(ifp);
1634 }
1627} 1635}
1628 1636
1629static int addrconf_dad_end(struct inet6_ifaddr *ifp) 1637static int addrconf_dad_end(struct inet6_ifaddr *ifp)
1630{ 1638{
1631 int err = -ENOENT; 1639 int err = -ENOENT;
1632 1640
1633 spin_lock(&ifp->state_lock); 1641 spin_lock_bh(&ifp->state_lock);
1634 if (ifp->state == INET6_IFADDR_STATE_DAD) { 1642 if (ifp->state == INET6_IFADDR_STATE_DAD) {
1635 ifp->state = INET6_IFADDR_STATE_POSTDAD; 1643 ifp->state = INET6_IFADDR_STATE_POSTDAD;
1636 err = 0; 1644 err = 0;
1637 } 1645 }
1638 spin_unlock(&ifp->state_lock); 1646 spin_unlock_bh(&ifp->state_lock);
1639 1647
1640 return err; 1648 return err;
1641} 1649}
@@ -1668,7 +1676,12 @@ void addrconf_dad_failure(struct inet6_ifaddr *ifp)
1668 } 1676 }
1669 } 1677 }
1670 1678
1671 addrconf_dad_stop(ifp, 1); 1679 spin_lock_bh(&ifp->state_lock);
1680 /* transition from _POSTDAD to _ERRDAD */
1681 ifp->state = INET6_IFADDR_STATE_ERRDAD;
1682 spin_unlock_bh(&ifp->state_lock);
1683
1684 addrconf_mod_dad_work(ifp, 0);
1672} 1685}
1673 1686
1674/* Join to solicited addr multicast group. */ 1687/* Join to solicited addr multicast group. */
@@ -1677,6 +1690,8 @@ void addrconf_join_solict(struct net_device *dev, const struct in6_addr *addr)
1677{ 1690{
1678 struct in6_addr maddr; 1691 struct in6_addr maddr;
1679 1692
1693 ASSERT_RTNL();
1694
1680 if (dev->flags&(IFF_LOOPBACK|IFF_NOARP)) 1695 if (dev->flags&(IFF_LOOPBACK|IFF_NOARP))
1681 return; 1696 return;
1682 1697
@@ -1688,6 +1703,8 @@ void addrconf_leave_solict(struct inet6_dev *idev, const struct in6_addr *addr)
1688{ 1703{
1689 struct in6_addr maddr; 1704 struct in6_addr maddr;
1690 1705
1706 ASSERT_RTNL();
1707
1691 if (idev->dev->flags&(IFF_LOOPBACK|IFF_NOARP)) 1708 if (idev->dev->flags&(IFF_LOOPBACK|IFF_NOARP))
1692 return; 1709 return;
1693 1710
@@ -1698,6 +1715,9 @@ void addrconf_leave_solict(struct inet6_dev *idev, const struct in6_addr *addr)
1698static void addrconf_join_anycast(struct inet6_ifaddr *ifp) 1715static void addrconf_join_anycast(struct inet6_ifaddr *ifp)
1699{ 1716{
1700 struct in6_addr addr; 1717 struct in6_addr addr;
1718
1719 ASSERT_RTNL();
1720
1701 if (ifp->prefix_len >= 127) /* RFC 6164 */ 1721 if (ifp->prefix_len >= 127) /* RFC 6164 */
1702 return; 1722 return;
1703 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); 1723 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len);
@@ -1709,6 +1729,9 @@ static void addrconf_join_anycast(struct inet6_ifaddr *ifp)
1709static void addrconf_leave_anycast(struct inet6_ifaddr *ifp) 1729static void addrconf_leave_anycast(struct inet6_ifaddr *ifp)
1710{ 1730{
1711 struct in6_addr addr; 1731 struct in6_addr addr;
1732
1733 ASSERT_RTNL();
1734
1712 if (ifp->prefix_len >= 127) /* RFC 6164 */ 1735 if (ifp->prefix_len >= 127) /* RFC 6164 */
1713 return; 1736 return;
1714 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); 1737 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len);
@@ -2268,11 +2291,13 @@ ok:
2268 return; 2291 return;
2269 } 2292 }
2270 2293
2271 ifp->flags |= IFA_F_MANAGETEMPADDR;
2272 update_lft = 0; 2294 update_lft = 0;
2273 create = 1; 2295 create = 1;
2296 spin_lock_bh(&ifp->lock);
2297 ifp->flags |= IFA_F_MANAGETEMPADDR;
2274 ifp->cstamp = jiffies; 2298 ifp->cstamp = jiffies;
2275 ifp->tokenized = tokenized; 2299 ifp->tokenized = tokenized;
2300 spin_unlock_bh(&ifp->lock);
2276 addrconf_dad_start(ifp); 2301 addrconf_dad_start(ifp);
2277 } 2302 }
2278 2303
@@ -2323,7 +2348,7 @@ ok:
2323 create, now); 2348 create, now);
2324 2349
2325 in6_ifa_put(ifp); 2350 in6_ifa_put(ifp);
2326 addrconf_verify(0); 2351 addrconf_verify();
2327 } 2352 }
2328 } 2353 }
2329 inet6_prefix_notify(RTM_NEWPREFIX, in6_dev, pinfo); 2354 inet6_prefix_notify(RTM_NEWPREFIX, in6_dev, pinfo);
@@ -2472,7 +2497,7 @@ static int inet6_addr_add(struct net *net, int ifindex,
2472 manage_tempaddrs(idev, ifp, valid_lft, prefered_lft, 2497 manage_tempaddrs(idev, ifp, valid_lft, prefered_lft,
2473 true, jiffies); 2498 true, jiffies);
2474 in6_ifa_put(ifp); 2499 in6_ifa_put(ifp);
2475 addrconf_verify(0); 2500 addrconf_verify_rtnl();
2476 return 0; 2501 return 0;
2477 } 2502 }
2478 2503
@@ -2783,6 +2808,8 @@ static void addrconf_gre_config(struct net_device *dev)
2783 ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0); 2808 ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
2784 if (!ipv6_generate_eui64(addr.s6_addr + 8, dev)) 2809 if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
2785 addrconf_add_linklocal(idev, &addr); 2810 addrconf_add_linklocal(idev, &addr);
2811 else
2812 addrconf_prefix_route(&addr, 64, dev, 0, 0);
2786} 2813}
2787#endif 2814#endif
2788 2815
@@ -3006,7 +3033,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
3006 hlist_for_each_entry_rcu(ifa, h, addr_lst) { 3033 hlist_for_each_entry_rcu(ifa, h, addr_lst) {
3007 if (ifa->idev == idev) { 3034 if (ifa->idev == idev) {
3008 hlist_del_init_rcu(&ifa->addr_lst); 3035 hlist_del_init_rcu(&ifa->addr_lst);
3009 addrconf_del_dad_timer(ifa); 3036 addrconf_del_dad_work(ifa);
3010 goto restart; 3037 goto restart;
3011 } 3038 }
3012 } 3039 }
@@ -3044,7 +3071,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
3044 while (!list_empty(&idev->addr_list)) { 3071 while (!list_empty(&idev->addr_list)) {
3045 ifa = list_first_entry(&idev->addr_list, 3072 ifa = list_first_entry(&idev->addr_list,
3046 struct inet6_ifaddr, if_list); 3073 struct inet6_ifaddr, if_list);
3047 addrconf_del_dad_timer(ifa); 3074 addrconf_del_dad_work(ifa);
3048 3075
3049 list_del(&ifa->if_list); 3076 list_del(&ifa->if_list);
3050 3077
@@ -3143,10 +3170,10 @@ static void addrconf_dad_kick(struct inet6_ifaddr *ifp)
3143 rand_num = prandom_u32() % (idev->cnf.rtr_solicit_delay ? : 1); 3170 rand_num = prandom_u32() % (idev->cnf.rtr_solicit_delay ? : 1);
3144 3171
3145 ifp->dad_probes = idev->cnf.dad_transmits; 3172 ifp->dad_probes = idev->cnf.dad_transmits;
3146 addrconf_mod_dad_timer(ifp, rand_num); 3173 addrconf_mod_dad_work(ifp, rand_num);
3147} 3174}
3148 3175
3149static void addrconf_dad_start(struct inet6_ifaddr *ifp) 3176static void addrconf_dad_begin(struct inet6_ifaddr *ifp)
3150{ 3177{
3151 struct inet6_dev *idev = ifp->idev; 3178 struct inet6_dev *idev = ifp->idev;
3152 struct net_device *dev = idev->dev; 3179 struct net_device *dev = idev->dev;
@@ -3198,25 +3225,68 @@ out:
3198 read_unlock_bh(&idev->lock); 3225 read_unlock_bh(&idev->lock);
3199} 3226}
3200 3227
3201static void addrconf_dad_timer(unsigned long data) 3228static void addrconf_dad_start(struct inet6_ifaddr *ifp)
3229{
3230 bool begin_dad = false;
3231
3232 spin_lock_bh(&ifp->state_lock);
3233 if (ifp->state != INET6_IFADDR_STATE_DEAD) {
3234 ifp->state = INET6_IFADDR_STATE_PREDAD;
3235 begin_dad = true;
3236 }
3237 spin_unlock_bh(&ifp->state_lock);
3238
3239 if (begin_dad)
3240 addrconf_mod_dad_work(ifp, 0);
3241}
3242
3243static void addrconf_dad_work(struct work_struct *w)
3202{ 3244{
3203 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data; 3245 struct inet6_ifaddr *ifp = container_of(to_delayed_work(w),
3246 struct inet6_ifaddr,
3247 dad_work);
3204 struct inet6_dev *idev = ifp->idev; 3248 struct inet6_dev *idev = ifp->idev;
3205 struct in6_addr mcaddr; 3249 struct in6_addr mcaddr;
3206 3250
3251 enum {
3252 DAD_PROCESS,
3253 DAD_BEGIN,
3254 DAD_ABORT,
3255 } action = DAD_PROCESS;
3256
3257 rtnl_lock();
3258
3259 spin_lock_bh(&ifp->state_lock);
3260 if (ifp->state == INET6_IFADDR_STATE_PREDAD) {
3261 action = DAD_BEGIN;
3262 ifp->state = INET6_IFADDR_STATE_DAD;
3263 } else if (ifp->state == INET6_IFADDR_STATE_ERRDAD) {
3264 action = DAD_ABORT;
3265 ifp->state = INET6_IFADDR_STATE_POSTDAD;
3266 }
3267 spin_unlock_bh(&ifp->state_lock);
3268
3269 if (action == DAD_BEGIN) {
3270 addrconf_dad_begin(ifp);
3271 goto out;
3272 } else if (action == DAD_ABORT) {
3273 addrconf_dad_stop(ifp, 1);
3274 goto out;
3275 }
3276
3207 if (!ifp->dad_probes && addrconf_dad_end(ifp)) 3277 if (!ifp->dad_probes && addrconf_dad_end(ifp))
3208 goto out; 3278 goto out;
3209 3279
3210 write_lock(&idev->lock); 3280 write_lock_bh(&idev->lock);
3211 if (idev->dead || !(idev->if_flags & IF_READY)) { 3281 if (idev->dead || !(idev->if_flags & IF_READY)) {
3212 write_unlock(&idev->lock); 3282 write_unlock_bh(&idev->lock);
3213 goto out; 3283 goto out;
3214 } 3284 }
3215 3285
3216 spin_lock(&ifp->lock); 3286 spin_lock(&ifp->lock);
3217 if (ifp->state == INET6_IFADDR_STATE_DEAD) { 3287 if (ifp->state == INET6_IFADDR_STATE_DEAD) {
3218 spin_unlock(&ifp->lock); 3288 spin_unlock(&ifp->lock);
3219 write_unlock(&idev->lock); 3289 write_unlock_bh(&idev->lock);
3220 goto out; 3290 goto out;
3221 } 3291 }
3222 3292
@@ -3227,7 +3297,7 @@ static void addrconf_dad_timer(unsigned long data)
3227 3297
3228 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); 3298 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED);
3229 spin_unlock(&ifp->lock); 3299 spin_unlock(&ifp->lock);
3230 write_unlock(&idev->lock); 3300 write_unlock_bh(&idev->lock);
3231 3301
3232 addrconf_dad_completed(ifp); 3302 addrconf_dad_completed(ifp);
3233 3303
@@ -3235,16 +3305,17 @@ static void addrconf_dad_timer(unsigned long data)
3235 } 3305 }
3236 3306
3237 ifp->dad_probes--; 3307 ifp->dad_probes--;
3238 addrconf_mod_dad_timer(ifp, 3308 addrconf_mod_dad_work(ifp,
3239 NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME)); 3309 NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME));
3240 spin_unlock(&ifp->lock); 3310 spin_unlock(&ifp->lock);
3241 write_unlock(&idev->lock); 3311 write_unlock_bh(&idev->lock);
3242 3312
3243 /* send a neighbour solicitation for our addr */ 3313 /* send a neighbour solicitation for our addr */
3244 addrconf_addr_solict_mult(&ifp->addr, &mcaddr); 3314 addrconf_addr_solict_mult(&ifp->addr, &mcaddr);
3245 ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &in6addr_any); 3315 ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &in6addr_any);
3246out: 3316out:
3247 in6_ifa_put(ifp); 3317 in6_ifa_put(ifp);
3318 rtnl_unlock();
3248} 3319}
3249 3320
3250/* ifp->idev must be at least read locked */ 3321/* ifp->idev must be at least read locked */
@@ -3271,7 +3342,7 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
3271 struct in6_addr lladdr; 3342 struct in6_addr lladdr;
3272 bool send_rs, send_mld; 3343 bool send_rs, send_mld;
3273 3344
3274 addrconf_del_dad_timer(ifp); 3345 addrconf_del_dad_work(ifp);
3275 3346
3276 /* 3347 /*
3277 * Configure the address for reception. Now it is valid. 3348 * Configure the address for reception. Now it is valid.
@@ -3512,23 +3583,23 @@ int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr)
3512 * Periodic address status verification 3583 * Periodic address status verification
3513 */ 3584 */
3514 3585
3515static void addrconf_verify(unsigned long foo) 3586static void addrconf_verify_rtnl(void)
3516{ 3587{
3517 unsigned long now, next, next_sec, next_sched; 3588 unsigned long now, next, next_sec, next_sched;
3518 struct inet6_ifaddr *ifp; 3589 struct inet6_ifaddr *ifp;
3519 int i; 3590 int i;
3520 3591
3592 ASSERT_RTNL();
3593
3521 rcu_read_lock_bh(); 3594 rcu_read_lock_bh();
3522 spin_lock(&addrconf_verify_lock);
3523 now = jiffies; 3595 now = jiffies;
3524 next = round_jiffies_up(now + ADDR_CHECK_FREQUENCY); 3596 next = round_jiffies_up(now + ADDR_CHECK_FREQUENCY);
3525 3597
3526 del_timer(&addr_chk_timer); 3598 cancel_delayed_work(&addr_chk_work);
3527 3599
3528 for (i = 0; i < IN6_ADDR_HSIZE; i++) { 3600 for (i = 0; i < IN6_ADDR_HSIZE; i++) {
3529restart: 3601restart:
3530 hlist_for_each_entry_rcu_bh(ifp, 3602 hlist_for_each_entry_rcu_bh(ifp, &inet6_addr_lst[i], addr_lst) {
3531 &inet6_addr_lst[i], addr_lst) {
3532 unsigned long age; 3603 unsigned long age;
3533 3604
3534 /* When setting preferred_lft to a value not zero or 3605 /* When setting preferred_lft to a value not zero or
@@ -3623,13 +3694,22 @@ restart:
3623 3694
3624 ADBG(KERN_DEBUG "now = %lu, schedule = %lu, rounded schedule = %lu => %lu\n", 3695 ADBG(KERN_DEBUG "now = %lu, schedule = %lu, rounded schedule = %lu => %lu\n",
3625 now, next, next_sec, next_sched); 3696 now, next, next_sec, next_sched);
3626 3697 mod_delayed_work(addrconf_wq, &addr_chk_work, next_sched - now);
3627 addr_chk_timer.expires = next_sched;
3628 add_timer(&addr_chk_timer);
3629 spin_unlock(&addrconf_verify_lock);
3630 rcu_read_unlock_bh(); 3698 rcu_read_unlock_bh();
3631} 3699}
3632 3700
3701static void addrconf_verify_work(struct work_struct *w)
3702{
3703 rtnl_lock();
3704 addrconf_verify_rtnl();
3705 rtnl_unlock();
3706}
3707
3708static void addrconf_verify(void)
3709{
3710 mod_delayed_work(addrconf_wq, &addr_chk_work, 0);
3711}
3712
3633static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local, 3713static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local,
3634 struct in6_addr **peer_pfx) 3714 struct in6_addr **peer_pfx)
3635{ 3715{
@@ -3686,6 +3766,8 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags,
3686 bool was_managetempaddr; 3766 bool was_managetempaddr;
3687 bool had_prefixroute; 3767 bool had_prefixroute;
3688 3768
3769 ASSERT_RTNL();
3770
3689 if (!valid_lft || (prefered_lft > valid_lft)) 3771 if (!valid_lft || (prefered_lft > valid_lft))
3690 return -EINVAL; 3772 return -EINVAL;
3691 3773
@@ -3751,7 +3833,7 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags,
3751 !was_managetempaddr, jiffies); 3833 !was_managetempaddr, jiffies);
3752 } 3834 }
3753 3835
3754 addrconf_verify(0); 3836 addrconf_verify_rtnl();
3755 3837
3756 return 0; 3838 return 0;
3757} 3839}
@@ -4381,6 +4463,8 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token)
4381 bool update_rs = false; 4463 bool update_rs = false;
4382 struct in6_addr ll_addr; 4464 struct in6_addr ll_addr;
4383 4465
4466 ASSERT_RTNL();
4467
4384 if (token == NULL) 4468 if (token == NULL)
4385 return -EINVAL; 4469 return -EINVAL;
4386 if (ipv6_addr_any(token)) 4470 if (ipv6_addr_any(token))
@@ -4429,7 +4513,7 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token)
4429 } 4513 }
4430 4514
4431 write_unlock_bh(&idev->lock); 4515 write_unlock_bh(&idev->lock);
4432 addrconf_verify(0); 4516 addrconf_verify_rtnl();
4433 return 0; 4517 return 0;
4434} 4518}
4435 4519
@@ -4631,6 +4715,9 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
4631{ 4715{
4632 struct net *net = dev_net(ifp->idev->dev); 4716 struct net *net = dev_net(ifp->idev->dev);
4633 4717
4718 if (event)
4719 ASSERT_RTNL();
4720
4634 inet6_ifa_notify(event ? : RTM_NEWADDR, ifp); 4721 inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
4635 4722
4636 switch (event) { 4723 switch (event) {
@@ -5239,6 +5326,12 @@ int __init addrconf_init(void)
5239 if (err < 0) 5326 if (err < 0)
5240 goto out_addrlabel; 5327 goto out_addrlabel;
5241 5328
5329 addrconf_wq = create_workqueue("ipv6_addrconf");
5330 if (!addrconf_wq) {
5331 err = -ENOMEM;
5332 goto out_nowq;
5333 }
5334
5242 /* The addrconf netdev notifier requires that loopback_dev 5335 /* The addrconf netdev notifier requires that loopback_dev
5243 * has it's ipv6 private information allocated and setup 5336 * has it's ipv6 private information allocated and setup
5244 * before it can bring up and give link-local addresses 5337 * before it can bring up and give link-local addresses
@@ -5269,7 +5362,7 @@ int __init addrconf_init(void)
5269 5362
5270 register_netdevice_notifier(&ipv6_dev_notf); 5363 register_netdevice_notifier(&ipv6_dev_notf);
5271 5364
5272 addrconf_verify(0); 5365 addrconf_verify();
5273 5366
5274 rtnl_af_register(&inet6_ops); 5367 rtnl_af_register(&inet6_ops);
5275 5368
@@ -5297,6 +5390,8 @@ errout:
5297 rtnl_af_unregister(&inet6_ops); 5390 rtnl_af_unregister(&inet6_ops);
5298 unregister_netdevice_notifier(&ipv6_dev_notf); 5391 unregister_netdevice_notifier(&ipv6_dev_notf);
5299errlo: 5392errlo:
5393 destroy_workqueue(addrconf_wq);
5394out_nowq:
5300 unregister_pernet_subsys(&addrconf_ops); 5395 unregister_pernet_subsys(&addrconf_ops);
5301out_addrlabel: 5396out_addrlabel:
5302 ipv6_addr_label_cleanup(); 5397 ipv6_addr_label_cleanup();
@@ -5332,7 +5427,8 @@ void addrconf_cleanup(void)
5332 for (i = 0; i < IN6_ADDR_HSIZE; i++) 5427 for (i = 0; i < IN6_ADDR_HSIZE; i++)
5333 WARN_ON(!hlist_empty(&inet6_addr_lst[i])); 5428 WARN_ON(!hlist_empty(&inet6_addr_lst[i]));
5334 spin_unlock_bh(&addrconf_hash_lock); 5429 spin_unlock_bh(&addrconf_hash_lock);
5335 5430 cancel_delayed_work(&addr_chk_work);
5336 del_timer(&addr_chk_timer);
5337 rtnl_unlock(); 5431 rtnl_unlock();
5432
5433 destroy_workqueue(addrconf_wq);
5338} 5434}
diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c
index 140748debc4a..8af3eb57f438 100644
--- a/net/ipv6/exthdrs_core.c
+++ b/net/ipv6/exthdrs_core.c
@@ -212,7 +212,7 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
212 found = (nexthdr == target); 212 found = (nexthdr == target);
213 213
214 if ((!ipv6_ext_hdr(nexthdr)) || nexthdr == NEXTHDR_NONE) { 214 if ((!ipv6_ext_hdr(nexthdr)) || nexthdr == NEXTHDR_NONE) {
215 if (target < 0) 215 if (target < 0 || found)
216 break; 216 break;
217 return -ENOENT; 217 return -ENOENT;
218 } 218 }
diff --git a/net/ipv6/exthdrs_offload.c b/net/ipv6/exthdrs_offload.c
index cf77f3abfd06..447a7fbd1bb6 100644
--- a/net/ipv6/exthdrs_offload.c
+++ b/net/ipv6/exthdrs_offload.c
@@ -25,11 +25,11 @@ int __init ipv6_exthdrs_offload_init(void)
25 int ret; 25 int ret;
26 26
27 ret = inet6_add_offload(&rthdr_offload, IPPROTO_ROUTING); 27 ret = inet6_add_offload(&rthdr_offload, IPPROTO_ROUTING);
28 if (!ret) 28 if (ret)
29 goto out; 29 goto out;
30 30
31 ret = inet6_add_offload(&dstopt_offload, IPPROTO_DSTOPTS); 31 ret = inet6_add_offload(&dstopt_offload, IPPROTO_DSTOPTS);
32 if (!ret) 32 if (ret)
33 goto out_rt; 33 goto out_rt;
34 34
35out: 35out:
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index f81f59686f21..f2610e157660 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -414,7 +414,7 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
414 addr_type = ipv6_addr_type(&hdr->daddr); 414 addr_type = ipv6_addr_type(&hdr->daddr);
415 415
416 if (ipv6_chk_addr(net, &hdr->daddr, skb->dev, 0) || 416 if (ipv6_chk_addr(net, &hdr->daddr, skb->dev, 0) ||
417 ipv6_anycast_destination(skb)) 417 ipv6_chk_acast_addr_src(net, skb->dev, &hdr->daddr))
418 saddr = &hdr->daddr; 418 saddr = &hdr->daddr;
419 419
420 /* 420 /*
diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
index 1e8683b135bb..59f95affceb0 100644
--- a/net/ipv6/ip6_offload.c
+++ b/net/ipv6/ip6_offload.c
@@ -89,7 +89,7 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
89 unsigned int unfrag_ip6hlen; 89 unsigned int unfrag_ip6hlen;
90 u8 *prevhdr; 90 u8 *prevhdr;
91 int offset = 0; 91 int offset = 0;
92 bool tunnel; 92 bool encap, udpfrag;
93 int nhoff; 93 int nhoff;
94 94
95 if (unlikely(skb_shinfo(skb)->gso_type & 95 if (unlikely(skb_shinfo(skb)->gso_type &
@@ -110,8 +110,8 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
110 if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) 110 if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
111 goto out; 111 goto out;
112 112
113 tunnel = SKB_GSO_CB(skb)->encap_level > 0; 113 encap = SKB_GSO_CB(skb)->encap_level > 0;
114 if (tunnel) 114 if (encap)
115 features = skb->dev->hw_enc_features & netif_skb_features(skb); 115 features = skb->dev->hw_enc_features & netif_skb_features(skb);
116 SKB_GSO_CB(skb)->encap_level += sizeof(*ipv6h); 116 SKB_GSO_CB(skb)->encap_level += sizeof(*ipv6h);
117 117
@@ -121,6 +121,12 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
121 121
122 proto = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); 122 proto = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr);
123 123
124 if (skb->encapsulation &&
125 skb_shinfo(skb)->gso_type & (SKB_GSO_SIT|SKB_GSO_IPIP))
126 udpfrag = proto == IPPROTO_UDP && encap;
127 else
128 udpfrag = proto == IPPROTO_UDP && !skb->encapsulation;
129
124 ops = rcu_dereference(inet6_offloads[proto]); 130 ops = rcu_dereference(inet6_offloads[proto]);
125 if (likely(ops && ops->callbacks.gso_segment)) { 131 if (likely(ops && ops->callbacks.gso_segment)) {
126 skb_reset_transport_header(skb); 132 skb_reset_transport_header(skb);
@@ -133,13 +139,9 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
133 for (skb = segs; skb; skb = skb->next) { 139 for (skb = segs; skb; skb = skb->next) {
134 ipv6h = (struct ipv6hdr *)(skb_mac_header(skb) + nhoff); 140 ipv6h = (struct ipv6hdr *)(skb_mac_header(skb) + nhoff);
135 ipv6h->payload_len = htons(skb->len - nhoff - sizeof(*ipv6h)); 141 ipv6h->payload_len = htons(skb->len - nhoff - sizeof(*ipv6h));
136 if (tunnel) {
137 skb_reset_inner_headers(skb);
138 skb->encapsulation = 1;
139 }
140 skb->network_header = (u8 *)ipv6h - skb->head; 142 skb->network_header = (u8 *)ipv6h - skb->head;
141 143
142 if (!tunnel && proto == IPPROTO_UDP) { 144 if (udpfrag) {
143 unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr); 145 unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr);
144 fptr = (struct frag_hdr *)((u8 *)ipv6h + unfrag_ip6hlen); 146 fptr = (struct frag_hdr *)((u8 *)ipv6h + unfrag_ip6hlen);
145 fptr->frag_off = htons(offset); 147 fptr->frag_off = htons(offset);
@@ -148,6 +150,8 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
148 offset += (ntohs(ipv6h->payload_len) - 150 offset += (ntohs(ipv6h->payload_len) -
149 sizeof(struct frag_hdr)); 151 sizeof(struct frag_hdr));
150 } 152 }
153 if (encap)
154 skb_reset_inner_headers(skb);
151 } 155 }
152 156
153out: 157out:
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index ef02b26ccf81..64d6073731d3 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -342,6 +342,20 @@ static unsigned int ip6_dst_mtu_forward(const struct dst_entry *dst)
342 return mtu; 342 return mtu;
343} 343}
344 344
345static bool ip6_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)
346{
347 if (skb->len <= mtu || skb->local_df)
348 return false;
349
350 if (IP6CB(skb)->frag_max_size && IP6CB(skb)->frag_max_size > mtu)
351 return true;
352
353 if (skb_is_gso(skb) && skb_gso_network_seglen(skb) <= mtu)
354 return false;
355
356 return true;
357}
358
345int ip6_forward(struct sk_buff *skb) 359int ip6_forward(struct sk_buff *skb)
346{ 360{
347 struct dst_entry *dst = skb_dst(skb); 361 struct dst_entry *dst = skb_dst(skb);
@@ -466,8 +480,7 @@ int ip6_forward(struct sk_buff *skb)
466 if (mtu < IPV6_MIN_MTU) 480 if (mtu < IPV6_MIN_MTU)
467 mtu = IPV6_MIN_MTU; 481 mtu = IPV6_MIN_MTU;
468 482
469 if ((!skb->local_df && skb->len > mtu && !skb_is_gso(skb)) || 483 if (ip6_pkt_too_big(skb, mtu)) {
470 (IP6CB(skb)->frag_max_size && IP6CB(skb)->frag_max_size > mtu)) {
471 /* Again, force OUTPUT device used as source address */ 484 /* Again, force OUTPUT device used as source address */
472 skb->dev = dst->dev; 485 skb->dev = dst->dev;
473 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); 486 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
@@ -517,9 +530,6 @@ static void ip6_copy_metadata(struct sk_buff *to, struct sk_buff *from)
517 to->tc_index = from->tc_index; 530 to->tc_index = from->tc_index;
518#endif 531#endif
519 nf_copy(to, from); 532 nf_copy(to, from);
520#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
521 to->nf_trace = from->nf_trace;
522#endif
523 skb_copy_secmark(to, from); 533 skb_copy_secmark(to, from);
524} 534}
525 535
@@ -1091,21 +1101,19 @@ static void ip6_append_data_mtu(unsigned int *mtu,
1091 unsigned int fragheaderlen, 1101 unsigned int fragheaderlen,
1092 struct sk_buff *skb, 1102 struct sk_buff *skb,
1093 struct rt6_info *rt, 1103 struct rt6_info *rt,
1094 bool pmtuprobe) 1104 unsigned int orig_mtu)
1095{ 1105{
1096 if (!(rt->dst.flags & DST_XFRM_TUNNEL)) { 1106 if (!(rt->dst.flags & DST_XFRM_TUNNEL)) {
1097 if (skb == NULL) { 1107 if (skb == NULL) {
1098 /* first fragment, reserve header_len */ 1108 /* first fragment, reserve header_len */
1099 *mtu = *mtu - rt->dst.header_len; 1109 *mtu = orig_mtu - rt->dst.header_len;
1100 1110
1101 } else { 1111 } else {
1102 /* 1112 /*
1103 * this fragment is not first, the headers 1113 * this fragment is not first, the headers
1104 * space is regarded as data space. 1114 * space is regarded as data space.
1105 */ 1115 */
1106 *mtu = min(*mtu, pmtuprobe ? 1116 *mtu = orig_mtu;
1107 rt->dst.dev->mtu :
1108 dst_mtu(rt->dst.path));
1109 } 1117 }
1110 *maxfraglen = ((*mtu - fragheaderlen) & ~7) 1118 *maxfraglen = ((*mtu - fragheaderlen) & ~7)
1111 + fragheaderlen - sizeof(struct frag_hdr); 1119 + fragheaderlen - sizeof(struct frag_hdr);
@@ -1122,7 +1130,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
1122 struct ipv6_pinfo *np = inet6_sk(sk); 1130 struct ipv6_pinfo *np = inet6_sk(sk);
1123 struct inet_cork *cork; 1131 struct inet_cork *cork;
1124 struct sk_buff *skb, *skb_prev = NULL; 1132 struct sk_buff *skb, *skb_prev = NULL;
1125 unsigned int maxfraglen, fragheaderlen, mtu; 1133 unsigned int maxfraglen, fragheaderlen, mtu, orig_mtu;
1126 int exthdrlen; 1134 int exthdrlen;
1127 int dst_exthdrlen; 1135 int dst_exthdrlen;
1128 int hh_len; 1136 int hh_len;
@@ -1204,6 +1212,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
1204 dst_exthdrlen = 0; 1212 dst_exthdrlen = 0;
1205 mtu = cork->fragsize; 1213 mtu = cork->fragsize;
1206 } 1214 }
1215 orig_mtu = mtu;
1207 1216
1208 hh_len = LL_RESERVED_SPACE(rt->dst.dev); 1217 hh_len = LL_RESERVED_SPACE(rt->dst.dev);
1209 1218
@@ -1301,8 +1310,7 @@ alloc_new_skb:
1301 if (skb == NULL || skb_prev == NULL) 1310 if (skb == NULL || skb_prev == NULL)
1302 ip6_append_data_mtu(&mtu, &maxfraglen, 1311 ip6_append_data_mtu(&mtu, &maxfraglen,
1303 fragheaderlen, skb, rt, 1312 fragheaderlen, skb, rt,
1304 np->pmtudisc >= 1313 orig_mtu);
1305 IPV6_PMTUDISC_PROBE);
1306 1314
1307 skb_prev = skb; 1315 skb_prev = skb;
1308 1316
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 0eb4038a4d63..8737400af0a0 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -2349,13 +2349,14 @@ int ip6mr_get_route(struct net *net,
2349} 2349}
2350 2350
2351static int ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb, 2351static int ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
2352 u32 portid, u32 seq, struct mfc6_cache *c, int cmd) 2352 u32 portid, u32 seq, struct mfc6_cache *c, int cmd,
2353 int flags)
2353{ 2354{
2354 struct nlmsghdr *nlh; 2355 struct nlmsghdr *nlh;
2355 struct rtmsg *rtm; 2356 struct rtmsg *rtm;
2356 int err; 2357 int err;
2357 2358
2358 nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), NLM_F_MULTI); 2359 nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags);
2359 if (nlh == NULL) 2360 if (nlh == NULL)
2360 return -EMSGSIZE; 2361 return -EMSGSIZE;
2361 2362
@@ -2423,7 +2424,7 @@ static void mr6_netlink_event(struct mr6_table *mrt, struct mfc6_cache *mfc,
2423 if (skb == NULL) 2424 if (skb == NULL)
2424 goto errout; 2425 goto errout;
2425 2426
2426 err = ip6mr_fill_mroute(mrt, skb, 0, 0, mfc, cmd); 2427 err = ip6mr_fill_mroute(mrt, skb, 0, 0, mfc, cmd, 0);
2427 if (err < 0) 2428 if (err < 0)
2428 goto errout; 2429 goto errout;
2429 2430
@@ -2462,7 +2463,8 @@ static int ip6mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
2462 if (ip6mr_fill_mroute(mrt, skb, 2463 if (ip6mr_fill_mroute(mrt, skb,
2463 NETLINK_CB(cb->skb).portid, 2464 NETLINK_CB(cb->skb).portid,
2464 cb->nlh->nlmsg_seq, 2465 cb->nlh->nlmsg_seq,
2465 mfc, RTM_NEWROUTE) < 0) 2466 mfc, RTM_NEWROUTE,
2467 NLM_F_MULTI) < 0)
2466 goto done; 2468 goto done;
2467next_entry: 2469next_entry:
2468 e++; 2470 e++;
@@ -2476,7 +2478,8 @@ next_entry:
2476 if (ip6mr_fill_mroute(mrt, skb, 2478 if (ip6mr_fill_mroute(mrt, skb,
2477 NETLINK_CB(cb->skb).portid, 2479 NETLINK_CB(cb->skb).portid,
2478 cb->nlh->nlmsg_seq, 2480 cb->nlh->nlmsg_seq,
2479 mfc, RTM_NEWROUTE) < 0) { 2481 mfc, RTM_NEWROUTE,
2482 NLM_F_MULTI) < 0) {
2480 spin_unlock_bh(&mfc_unres_lock); 2483 spin_unlock_bh(&mfc_unres_lock);
2481 goto done; 2484 goto done;
2482 } 2485 }
diff --git a/net/ipv6/netfilter/Kconfig b/net/ipv6/netfilter/Kconfig
index 35750df744dc..4bff1f297e39 100644
--- a/net/ipv6/netfilter/Kconfig
+++ b/net/ipv6/netfilter/Kconfig
@@ -50,6 +50,11 @@ config NFT_CHAIN_NAT_IPV6
50 packet transformations such as the source, destination address and 50 packet transformations such as the source, destination address and
51 source and destination ports. 51 source and destination ports.
52 52
53config NFT_REJECT_IPV6
54 depends on NF_TABLES_IPV6
55 default NFT_REJECT
56 tristate
57
53config IP6_NF_IPTABLES 58config IP6_NF_IPTABLES
54 tristate "IP6 tables support (required for filtering)" 59 tristate "IP6 tables support (required for filtering)"
55 depends on INET && IPV6 60 depends on INET && IPV6
diff --git a/net/ipv6/netfilter/Makefile b/net/ipv6/netfilter/Makefile
index d1b4928f34f7..70d3dd66f2cd 100644
--- a/net/ipv6/netfilter/Makefile
+++ b/net/ipv6/netfilter/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o
27obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o 27obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o
28obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o 28obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o
29obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o 29obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o
30obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o
30 31
31# matches 32# matches
32obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o 33obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
diff --git a/net/ipv6/netfilter/nft_reject_ipv6.c b/net/ipv6/netfilter/nft_reject_ipv6.c
new file mode 100644
index 000000000000..0bc19fa87821
--- /dev/null
+++ b/net/ipv6/netfilter/nft_reject_ipv6.c
@@ -0,0 +1,76 @@
1/*
2 * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2013 Eric Leblond <eric@regit.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Development of this code funded by Astaro AG (http://www.astaro.com/)
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/netlink.h>
16#include <linux/netfilter.h>
17#include <linux/netfilter/nf_tables.h>
18#include <net/netfilter/nf_tables.h>
19#include <net/netfilter/nft_reject.h>
20#include <net/netfilter/ipv6/nf_reject.h>
21
22void nft_reject_ipv6_eval(const struct nft_expr *expr,
23 struct nft_data data[NFT_REG_MAX + 1],
24 const struct nft_pktinfo *pkt)
25{
26 struct nft_reject *priv = nft_expr_priv(expr);
27 struct net *net = dev_net((pkt->in != NULL) ? pkt->in : pkt->out);
28
29 switch (priv->type) {
30 case NFT_REJECT_ICMP_UNREACH:
31 nf_send_unreach6(net, pkt->skb, priv->icmp_code,
32 pkt->ops->hooknum);
33 break;
34 case NFT_REJECT_TCP_RST:
35 nf_send_reset6(net, pkt->skb, pkt->ops->hooknum);
36 break;
37 }
38
39 data[NFT_REG_VERDICT].verdict = NF_DROP;
40}
41EXPORT_SYMBOL_GPL(nft_reject_ipv6_eval);
42
43static struct nft_expr_type nft_reject_ipv6_type;
44static const struct nft_expr_ops nft_reject_ipv6_ops = {
45 .type = &nft_reject_ipv6_type,
46 .size = NFT_EXPR_SIZE(sizeof(struct nft_reject)),
47 .eval = nft_reject_ipv6_eval,
48 .init = nft_reject_init,
49 .dump = nft_reject_dump,
50};
51
52static struct nft_expr_type nft_reject_ipv6_type __read_mostly = {
53 .family = NFPROTO_IPV6,
54 .name = "reject",
55 .ops = &nft_reject_ipv6_ops,
56 .policy = nft_reject_policy,
57 .maxattr = NFTA_REJECT_MAX,
58 .owner = THIS_MODULE,
59};
60
61static int __init nft_reject_ipv6_module_init(void)
62{
63 return nft_register_expr(&nft_reject_ipv6_type);
64}
65
66static void __exit nft_reject_ipv6_module_exit(void)
67{
68 nft_unregister_expr(&nft_reject_ipv6_type);
69}
70
71module_init(nft_reject_ipv6_module_init);
72module_exit(nft_reject_ipv6_module_exit);
73
74MODULE_LICENSE("GPL");
75MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
76MODULE_ALIAS_NFT_AF_EXPR(AF_INET6, "reject");
diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
index fb9beb78f00b..587bbdcb22b4 100644
--- a/net/ipv6/ping.c
+++ b/net/ipv6/ping.c
@@ -135,6 +135,7 @@ int ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
135 fl6.flowi6_proto = IPPROTO_ICMPV6; 135 fl6.flowi6_proto = IPPROTO_ICMPV6;
136 fl6.saddr = np->saddr; 136 fl6.saddr = np->saddr;
137 fl6.daddr = *daddr; 137 fl6.daddr = *daddr;
138 fl6.flowi6_mark = sk->sk_mark;
138 fl6.fl6_icmp_type = user_icmph.icmp6_type; 139 fl6.fl6_icmp_type = user_icmph.icmp6_type;
139 fl6.fl6_icmp_code = user_icmph.icmp6_code; 140 fl6.fl6_icmp_code = user_icmph.icmp6_code;
140 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); 141 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 11dac21e6586..fba54a407bb2 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1513,7 +1513,7 @@ int ip6_route_add(struct fib6_config *cfg)
1513 if (!table) 1513 if (!table)
1514 goto out; 1514 goto out;
1515 1515
1516 rt = ip6_dst_alloc(net, NULL, DST_NOCOUNT, table); 1516 rt = ip6_dst_alloc(net, NULL, (cfg->fc_flags & RTF_ADDRCONF) ? 0 : DST_NOCOUNT, table);
1517 1517
1518 if (!rt) { 1518 if (!rt) {
1519 err = -ENOMEM; 1519 err = -ENOMEM;
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 3dfbcf1dcb1c..b4d74c86586c 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -475,6 +475,7 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
475 ipip6_tunnel_unlink(sitn, tunnel); 475 ipip6_tunnel_unlink(sitn, tunnel);
476 ipip6_tunnel_del_prl(tunnel, NULL); 476 ipip6_tunnel_del_prl(tunnel, NULL);
477 } 477 }
478 ip_tunnel_dst_reset_all(tunnel);
478 dev_put(dev); 479 dev_put(dev);
479} 480}
480 481
@@ -1082,6 +1083,7 @@ static void ipip6_tunnel_update(struct ip_tunnel *t, struct ip_tunnel_parm *p)
1082 t->parms.link = p->link; 1083 t->parms.link = p->link;
1083 ipip6_tunnel_bind_dev(t->dev); 1084 ipip6_tunnel_bind_dev(t->dev);
1084 } 1085 }
1086 ip_tunnel_dst_reset_all(t);
1085 netdev_state_change(t->dev); 1087 netdev_state_change(t->dev);
1086} 1088}
1087 1089
@@ -1112,6 +1114,7 @@ static int ipip6_tunnel_update_6rd(struct ip_tunnel *t,
1112 t->ip6rd.relay_prefix = relay_prefix; 1114 t->ip6rd.relay_prefix = relay_prefix;
1113 t->ip6rd.prefixlen = ip6rd->prefixlen; 1115 t->ip6rd.prefixlen = ip6rd->prefixlen;
1114 t->ip6rd.relay_prefixlen = ip6rd->relay_prefixlen; 1116 t->ip6rd.relay_prefixlen = ip6rd->relay_prefixlen;
1117 ip_tunnel_dst_reset_all(t);
1115 netdev_state_change(t->dev); 1118 netdev_state_change(t->dev);
1116 return 0; 1119 return 0;
1117} 1120}
@@ -1271,6 +1274,7 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
1271 err = ipip6_tunnel_add_prl(t, &prl, cmd == SIOCCHGPRL); 1274 err = ipip6_tunnel_add_prl(t, &prl, cmd == SIOCCHGPRL);
1272 break; 1275 break;
1273 } 1276 }
1277 ip_tunnel_dst_reset_all(t);
1274 netdev_state_change(dev); 1278 netdev_state_change(dev);
1275 break; 1279 break;
1276 1280
@@ -1326,6 +1330,9 @@ static const struct net_device_ops ipip6_netdev_ops = {
1326 1330
1327static void ipip6_dev_free(struct net_device *dev) 1331static void ipip6_dev_free(struct net_device *dev)
1328{ 1332{
1333 struct ip_tunnel *tunnel = netdev_priv(dev);
1334
1335 free_percpu(tunnel->dst_cache);
1329 free_percpu(dev->tstats); 1336 free_percpu(dev->tstats);
1330 free_netdev(dev); 1337 free_netdev(dev);
1331} 1338}
@@ -1375,6 +1382,12 @@ static int ipip6_tunnel_init(struct net_device *dev)
1375 u64_stats_init(&ipip6_tunnel_stats->syncp); 1382 u64_stats_init(&ipip6_tunnel_stats->syncp);
1376 } 1383 }
1377 1384
1385 tunnel->dst_cache = alloc_percpu(struct ip_tunnel_dst);
1386 if (!tunnel->dst_cache) {
1387 free_percpu(dev->tstats);
1388 return -ENOMEM;
1389 }
1390
1378 return 0; 1391 return 0;
1379} 1392}
1380 1393
@@ -1405,6 +1418,12 @@ static int __net_init ipip6_fb_tunnel_init(struct net_device *dev)
1405 u64_stats_init(&ipip6_fb_stats->syncp); 1418 u64_stats_init(&ipip6_fb_stats->syncp);
1406 } 1419 }
1407 1420
1421 tunnel->dst_cache = alloc_percpu(struct ip_tunnel_dst);
1422 if (!tunnel->dst_cache) {
1423 free_percpu(dev->tstats);
1424 return -ENOMEM;
1425 }
1426
1408 dev_hold(dev); 1427 dev_hold(dev);
1409 rcu_assign_pointer(sitn->tunnels_wc[0], tunnel); 1428 rcu_assign_pointer(sitn->tunnels_wc[0], tunnel);
1410 return 0; 1429 return 0;
diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c
index e7359f9eaa8d..b261ee8b83fc 100644
--- a/net/ipv6/udp_offload.c
+++ b/net/ipv6/udp_offload.c
@@ -113,7 +113,7 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb,
113 fptr = (struct frag_hdr *)(skb_network_header(skb) + unfrag_ip6hlen); 113 fptr = (struct frag_hdr *)(skb_network_header(skb) + unfrag_ip6hlen);
114 fptr->nexthdr = nexthdr; 114 fptr->nexthdr = nexthdr;
115 fptr->reserved = 0; 115 fptr->reserved = 0;
116 ipv6_select_ident(fptr, (struct rt6_info *)skb_dst(skb)); 116 fptr->identification = skb_shinfo(skb)->ip6_frag_id;
117 117
118 /* Fragment the skb. ipv6 header and the remaining fields of the 118 /* Fragment the skb. ipv6 header and the remaining fields of the
119 * fragment header are updated in ipv6_gso_segment() 119 * fragment header are updated in ipv6_gso_segment()
diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c
index 994e28bfb32e..00b2a6d1c009 100644
--- a/net/ipx/af_ipx.c
+++ b/net/ipx/af_ipx.c
@@ -52,18 +52,12 @@
52#include <net/p8022.h> 52#include <net/p8022.h>
53#include <net/psnap.h> 53#include <net/psnap.h>
54#include <net/sock.h> 54#include <net/sock.h>
55#include <net/datalink.h>
55#include <net/tcp_states.h> 56#include <net/tcp_states.h>
57#include <net/net_namespace.h>
56 58
57#include <asm/uaccess.h> 59#include <asm/uaccess.h>
58 60
59#ifdef CONFIG_SYSCTL
60extern void ipx_register_sysctl(void);
61extern void ipx_unregister_sysctl(void);
62#else
63#define ipx_register_sysctl()
64#define ipx_unregister_sysctl()
65#endif
66
67/* Configuration Variables */ 61/* Configuration Variables */
68static unsigned char ipxcfg_max_hops = 16; 62static unsigned char ipxcfg_max_hops = 16;
69static char ipxcfg_auto_select_primary; 63static char ipxcfg_auto_select_primary;
@@ -84,15 +78,6 @@ DEFINE_SPINLOCK(ipx_interfaces_lock);
84struct ipx_interface *ipx_primary_net; 78struct ipx_interface *ipx_primary_net;
85struct ipx_interface *ipx_internal_net; 79struct ipx_interface *ipx_internal_net;
86 80
87extern int ipxrtr_add_route(__be32 network, struct ipx_interface *intrfc,
88 unsigned char *node);
89extern void ipxrtr_del_routes(struct ipx_interface *intrfc);
90extern int ipxrtr_route_packet(struct sock *sk, struct sockaddr_ipx *usipx,
91 struct iovec *iov, size_t len, int noblock);
92extern int ipxrtr_route_skb(struct sk_buff *skb);
93extern struct ipx_route *ipxrtr_lookup(__be32 net);
94extern int ipxrtr_ioctl(unsigned int cmd, void __user *arg);
95
96struct ipx_interface *ipx_interfaces_head(void) 81struct ipx_interface *ipx_interfaces_head(void)
97{ 82{
98 struct ipx_interface *rc = NULL; 83 struct ipx_interface *rc = NULL;
@@ -1986,9 +1971,6 @@ static struct notifier_block ipx_dev_notifier = {
1986 .notifier_call = ipxitf_device_event, 1971 .notifier_call = ipxitf_device_event,
1987}; 1972};
1988 1973
1989extern struct datalink_proto *make_EII_client(void);
1990extern void destroy_EII_client(struct datalink_proto *);
1991
1992static const unsigned char ipx_8022_type = 0xE0; 1974static const unsigned char ipx_8022_type = 0xE0;
1993static const unsigned char ipx_snap_id[5] = { 0x0, 0x0, 0x0, 0x81, 0x37 }; 1975static const unsigned char ipx_snap_id[5] = { 0x0, 0x0, 0x0, 0x81, 0x37 };
1994static const char ipx_EII_err_msg[] __initconst = 1976static const char ipx_EII_err_msg[] __initconst =
diff --git a/net/ipx/ipx_route.c b/net/ipx/ipx_route.c
index 30f4519b092f..c1f03185c5e1 100644
--- a/net/ipx/ipx_route.c
+++ b/net/ipx/ipx_route.c
@@ -20,15 +20,11 @@ DEFINE_RWLOCK(ipx_routes_lock);
20 20
21extern struct ipx_interface *ipx_internal_net; 21extern struct ipx_interface *ipx_internal_net;
22 22
23extern __be16 ipx_cksum(struct ipxhdr *packet, int length);
24extern struct ipx_interface *ipxitf_find_using_net(__be32 net); 23extern struct ipx_interface *ipxitf_find_using_net(__be32 net);
25extern int ipxitf_demux_socket(struct ipx_interface *intrfc, 24extern int ipxitf_demux_socket(struct ipx_interface *intrfc,
26 struct sk_buff *skb, int copy); 25 struct sk_buff *skb, int copy);
27extern int ipxitf_demux_socket(struct ipx_interface *intrfc, 26extern int ipxitf_demux_socket(struct ipx_interface *intrfc,
28 struct sk_buff *skb, int copy); 27 struct sk_buff *skb, int copy);
29extern int ipxitf_send(struct ipx_interface *intrfc, struct sk_buff *skb,
30 char *node);
31extern struct ipx_interface *ipxitf_find_using_net(__be32 net);
32 28
33struct ipx_route *ipxrtr_lookup(__be32 net) 29struct ipx_route *ipxrtr_lookup(__be32 net)
34{ 30{
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 1a04c1329362..79326978517a 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -433,12 +433,13 @@ static inline int verify_sec_ctx_len(const void *p)
433 return 0; 433 return 0;
434} 434}
435 435
436static inline struct xfrm_user_sec_ctx *pfkey_sadb2xfrm_user_sec_ctx(const struct sadb_x_sec_ctx *sec_ctx) 436static inline struct xfrm_user_sec_ctx *pfkey_sadb2xfrm_user_sec_ctx(const struct sadb_x_sec_ctx *sec_ctx,
437 gfp_t gfp)
437{ 438{
438 struct xfrm_user_sec_ctx *uctx = NULL; 439 struct xfrm_user_sec_ctx *uctx = NULL;
439 int ctx_size = sec_ctx->sadb_x_ctx_len; 440 int ctx_size = sec_ctx->sadb_x_ctx_len;
440 441
441 uctx = kmalloc((sizeof(*uctx)+ctx_size), GFP_KERNEL); 442 uctx = kmalloc((sizeof(*uctx)+ctx_size), gfp);
442 443
443 if (!uctx) 444 if (!uctx)
444 return NULL; 445 return NULL;
@@ -1124,7 +1125,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
1124 1125
1125 sec_ctx = ext_hdrs[SADB_X_EXT_SEC_CTX - 1]; 1126 sec_ctx = ext_hdrs[SADB_X_EXT_SEC_CTX - 1];
1126 if (sec_ctx != NULL) { 1127 if (sec_ctx != NULL) {
1127 struct xfrm_user_sec_ctx *uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx); 1128 struct xfrm_user_sec_ctx *uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx, GFP_KERNEL);
1128 1129
1129 if (!uctx) 1130 if (!uctx)
1130 goto out; 1131 goto out;
@@ -2231,14 +2232,14 @@ static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, const struct sadb_
2231 2232
2232 sec_ctx = ext_hdrs[SADB_X_EXT_SEC_CTX - 1]; 2233 sec_ctx = ext_hdrs[SADB_X_EXT_SEC_CTX - 1];
2233 if (sec_ctx != NULL) { 2234 if (sec_ctx != NULL) {
2234 struct xfrm_user_sec_ctx *uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx); 2235 struct xfrm_user_sec_ctx *uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx, GFP_KERNEL);
2235 2236
2236 if (!uctx) { 2237 if (!uctx) {
2237 err = -ENOBUFS; 2238 err = -ENOBUFS;
2238 goto out; 2239 goto out;
2239 } 2240 }
2240 2241
2241 err = security_xfrm_policy_alloc(&xp->security, uctx); 2242 err = security_xfrm_policy_alloc(&xp->security, uctx, GFP_KERNEL);
2242 kfree(uctx); 2243 kfree(uctx);
2243 2244
2244 if (err) 2245 if (err)
@@ -2335,12 +2336,12 @@ static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, const struct sa
2335 2336
2336 sec_ctx = ext_hdrs[SADB_X_EXT_SEC_CTX - 1]; 2337 sec_ctx = ext_hdrs[SADB_X_EXT_SEC_CTX - 1];
2337 if (sec_ctx != NULL) { 2338 if (sec_ctx != NULL) {
2338 struct xfrm_user_sec_ctx *uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx); 2339 struct xfrm_user_sec_ctx *uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx, GFP_KERNEL);
2339 2340
2340 if (!uctx) 2341 if (!uctx)
2341 return -ENOMEM; 2342 return -ENOMEM;
2342 2343
2343 err = security_xfrm_policy_alloc(&pol_ctx, uctx); 2344 err = security_xfrm_policy_alloc(&pol_ctx, uctx, GFP_KERNEL);
2344 kfree(uctx); 2345 kfree(uctx);
2345 if (err) 2346 if (err)
2346 return err; 2347 return err;
@@ -3239,8 +3240,8 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt,
3239 } 3240 }
3240 if ((*dir = verify_sec_ctx_len(p))) 3241 if ((*dir = verify_sec_ctx_len(p)))
3241 goto out; 3242 goto out;
3242 uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx); 3243 uctx = pfkey_sadb2xfrm_user_sec_ctx(sec_ctx, GFP_ATOMIC);
3243 *dir = security_xfrm_policy_alloc(&xp->security, uctx); 3244 *dir = security_xfrm_policy_alloc(&xp->security, uctx, GFP_ATOMIC);
3244 kfree(uctx); 3245 kfree(uctx);
3245 3246
3246 if (*dir) 3247 if (*dir)
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 735d0f60c83a..c83827e7c324 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -112,7 +112,6 @@ struct l2tp_net {
112 spinlock_t l2tp_session_hlist_lock; 112 spinlock_t l2tp_session_hlist_lock;
113}; 113};
114 114
115static void l2tp_session_set_header_len(struct l2tp_session *session, int version);
116static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel); 115static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel);
117 116
118static inline struct l2tp_tunnel *l2tp_tunnel(struct sock *sk) 117static inline struct l2tp_tunnel *l2tp_tunnel(struct sock *sk)
@@ -1863,7 +1862,7 @@ EXPORT_SYMBOL_GPL(l2tp_session_delete);
1863/* We come here whenever a session's send_seq, cookie_len or 1862/* We come here whenever a session's send_seq, cookie_len or
1864 * l2specific_len parameters are set. 1863 * l2specific_len parameters are set.
1865 */ 1864 */
1866static void l2tp_session_set_header_len(struct l2tp_session *session, int version) 1865void l2tp_session_set_header_len(struct l2tp_session *session, int version)
1867{ 1866{
1868 if (version == L2TP_HDR_VER_2) { 1867 if (version == L2TP_HDR_VER_2) {
1869 session->hdr_len = 6; 1868 session->hdr_len = 6;
@@ -1876,6 +1875,7 @@ static void l2tp_session_set_header_len(struct l2tp_session *session, int versio
1876 } 1875 }
1877 1876
1878} 1877}
1878EXPORT_SYMBOL_GPL(l2tp_session_set_header_len);
1879 1879
1880struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg) 1880struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg)
1881{ 1881{
@@ -2016,7 +2016,7 @@ static int __init l2tp_init(void)
2016 if (rc) 2016 if (rc)
2017 goto out; 2017 goto out;
2018 2018
2019 l2tp_wq = alloc_workqueue("l2tp", WQ_NON_REENTRANT | WQ_UNBOUND, 0); 2019 l2tp_wq = alloc_workqueue("l2tp", WQ_UNBOUND, 0);
2020 if (!l2tp_wq) { 2020 if (!l2tp_wq) {
2021 pr_err("alloc_workqueue failed\n"); 2021 pr_err("alloc_workqueue failed\n");
2022 rc = -ENOMEM; 2022 rc = -ENOMEM;
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
index 1f01ba3435bc..3f93ccd6ba97 100644
--- a/net/l2tp/l2tp_core.h
+++ b/net/l2tp/l2tp_core.h
@@ -263,6 +263,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
263 int length, int (*payload_hook)(struct sk_buff *skb)); 263 int length, int (*payload_hook)(struct sk_buff *skb));
264int l2tp_session_queue_purge(struct l2tp_session *session); 264int l2tp_session_queue_purge(struct l2tp_session *session);
265int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb); 265int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb);
266void l2tp_session_set_header_len(struct l2tp_session *session, int version);
266 267
267int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, 268int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb,
268 int hdr_len); 269 int hdr_len);
diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c
index 4cfd722e9153..bd7387adea9e 100644
--- a/net/l2tp/l2tp_netlink.c
+++ b/net/l2tp/l2tp_netlink.c
@@ -578,8 +578,10 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *inf
578 if (info->attrs[L2TP_ATTR_RECV_SEQ]) 578 if (info->attrs[L2TP_ATTR_RECV_SEQ])
579 session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]); 579 session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]);
580 580
581 if (info->attrs[L2TP_ATTR_SEND_SEQ]) 581 if (info->attrs[L2TP_ATTR_SEND_SEQ]) {
582 session->send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]); 582 session->send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]);
583 l2tp_session_set_header_len(session, session->tunnel->version);
584 }
583 585
584 if (info->attrs[L2TP_ATTR_LNS_MODE]) 586 if (info->attrs[L2TP_ATTR_LNS_MODE])
585 session->lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]); 587 session->lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]);
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index be5fadf34739..5990919356a5 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -254,12 +254,14 @@ static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int
254 po = pppox_sk(sk); 254 po = pppox_sk(sk);
255 ppp_input(&po->chan, skb); 255 ppp_input(&po->chan, skb);
256 } else { 256 } else {
257 l2tp_info(session, PPPOL2TP_MSG_DATA, "%s: socket not bound\n", 257 l2tp_dbg(session, PPPOL2TP_MSG_DATA,
258 session->name); 258 "%s: recv %d byte data frame, passing to L2TP socket\n",
259 session->name, data_len);
259 260
260 /* Not bound. Nothing we can do, so discard. */ 261 if (sock_queue_rcv_skb(sk, skb) < 0) {
261 atomic_long_inc(&session->stats.rx_errors); 262 atomic_long_inc(&session->stats.rx_errors);
262 kfree_skb(skb); 263 kfree_skb(skb);
264 }
263 } 265 }
264 266
265 return; 267 return;
@@ -1312,6 +1314,7 @@ static int pppol2tp_session_setsockopt(struct sock *sk,
1312 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ : 1314 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
1313 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ; 1315 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1314 } 1316 }
1317 l2tp_session_set_header_len(session, session->tunnel->version);
1315 l2tp_info(session, PPPOL2TP_MSG_CONTROL, 1318 l2tp_info(session, PPPOL2TP_MSG_CONTROL,
1316 "%s: set send_seq=%d\n", 1319 "%s: set send_seq=%d\n",
1317 session->name, session->send_seq); 1320 session->name, session->send_seq);
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index f9ae9b85d4c1..453e974287d1 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -1021,8 +1021,10 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1021 IEEE80211_P2P_OPPPS_ENABLE_BIT; 1021 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1022 1022
1023 err = ieee80211_assign_beacon(sdata, &params->beacon); 1023 err = ieee80211_assign_beacon(sdata, &params->beacon);
1024 if (err < 0) 1024 if (err < 0) {
1025 ieee80211_vif_release_channel(sdata);
1025 return err; 1026 return err;
1027 }
1026 changed |= err; 1028 changed |= err;
1027 1029
1028 err = drv_start_ap(sdata->local, sdata); 1030 err = drv_start_ap(sdata->local, sdata);
@@ -1032,6 +1034,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1032 if (old) 1034 if (old)
1033 kfree_rcu(old, rcu_head); 1035 kfree_rcu(old, rcu_head);
1034 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL); 1036 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1037 ieee80211_vif_release_channel(sdata);
1035 return err; 1038 return err;
1036 } 1039 }
1037 1040
@@ -1090,8 +1093,6 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1090 kfree(sdata->u.ap.next_beacon); 1093 kfree(sdata->u.ap.next_beacon);
1091 sdata->u.ap.next_beacon = NULL; 1094 sdata->u.ap.next_beacon = NULL;
1092 1095
1093 cancel_work_sync(&sdata->u.ap.request_smps_work);
1094
1095 /* turn off carrier for this interface and dependent VLANs */ 1096 /* turn off carrier for this interface and dependent VLANs */
1096 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) 1097 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1097 netif_carrier_off(vlan->dev); 1098 netif_carrier_off(vlan->dev);
@@ -1103,6 +1104,7 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1103 kfree_rcu(old_beacon, rcu_head); 1104 kfree_rcu(old_beacon, rcu_head);
1104 if (old_probe_resp) 1105 if (old_probe_resp)
1105 kfree_rcu(old_probe_resp, rcu_head); 1106 kfree_rcu(old_probe_resp, rcu_head);
1107 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
1106 1108
1107 __sta_info_flush(sdata, true); 1109 __sta_info_flush(sdata, true);
1108 ieee80211_free_keys(sdata, true); 1110 ieee80211_free_keys(sdata, true);
@@ -2638,6 +2640,24 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2638 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work); 2640 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2639 INIT_LIST_HEAD(&roc->dependents); 2641 INIT_LIST_HEAD(&roc->dependents);
2640 2642
2643 /*
2644 * cookie is either the roc cookie (for normal roc)
2645 * or the SKB (for mgmt TX)
2646 */
2647 if (!txskb) {
2648 /* local->mtx protects this */
2649 local->roc_cookie_counter++;
2650 roc->cookie = local->roc_cookie_counter;
2651 /* wow, you wrapped 64 bits ... more likely a bug */
2652 if (WARN_ON(roc->cookie == 0)) {
2653 roc->cookie = 1;
2654 local->roc_cookie_counter++;
2655 }
2656 *cookie = roc->cookie;
2657 } else {
2658 *cookie = (unsigned long)txskb;
2659 }
2660
2641 /* if there's one pending or we're scanning, queue this one */ 2661 /* if there's one pending or we're scanning, queue this one */
2642 if (!list_empty(&local->roc_list) || 2662 if (!list_empty(&local->roc_list) ||
2643 local->scanning || local->radar_detect_enabled) 2663 local->scanning || local->radar_detect_enabled)
@@ -2772,24 +2792,6 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2772 if (!queued) 2792 if (!queued)
2773 list_add_tail(&roc->list, &local->roc_list); 2793 list_add_tail(&roc->list, &local->roc_list);
2774 2794
2775 /*
2776 * cookie is either the roc cookie (for normal roc)
2777 * or the SKB (for mgmt TX)
2778 */
2779 if (!txskb) {
2780 /* local->mtx protects this */
2781 local->roc_cookie_counter++;
2782 roc->cookie = local->roc_cookie_counter;
2783 /* wow, you wrapped 64 bits ... more likely a bug */
2784 if (WARN_ON(roc->cookie == 0)) {
2785 roc->cookie = 1;
2786 local->roc_cookie_counter++;
2787 }
2788 *cookie = roc->cookie;
2789 } else {
2790 *cookie = (unsigned long)txskb;
2791 }
2792
2793 return 0; 2795 return 0;
2794} 2796}
2795 2797
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index f43613a97dd6..0c1ecfdf9a12 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -100,6 +100,12 @@ ieee80211_get_chanctx_max_required_bw(struct ieee80211_local *local,
100 } 100 }
101 max_bw = max(max_bw, width); 101 max_bw = max(max_bw, width);
102 } 102 }
103
104 /* use the configured bandwidth in case of monitor interface */
105 sdata = rcu_dereference(local->monitor_sdata);
106 if (sdata && rcu_access_pointer(sdata->vif.chanctx_conf) == conf)
107 max_bw = max(max_bw, conf->def.width);
108
103 rcu_read_unlock(); 109 rcu_read_unlock();
104 110
105 return max_bw; 111 return max_bw;
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index fab7b91923e0..70dd013de836 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -466,7 +466,9 @@ void ieee80211_request_smps_ap_work(struct work_struct *work)
466 u.ap.request_smps_work); 466 u.ap.request_smps_work);
467 467
468 sdata_lock(sdata); 468 sdata_lock(sdata);
469 __ieee80211_request_smps_ap(sdata, sdata->u.ap.driver_smps_mode); 469 if (sdata_dereference(sdata->u.ap.beacon, sdata))
470 __ieee80211_request_smps_ap(sdata,
471 sdata->u.ap.driver_smps_mode);
470 sdata_unlock(sdata); 472 sdata_unlock(sdata);
471} 473}
472 474
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 771080ec7212..2796a198728f 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -695,12 +695,9 @@ static void ieee80211_ibss_disconnect(struct ieee80211_sub_if_data *sdata)
695 struct cfg80211_bss *cbss; 695 struct cfg80211_bss *cbss;
696 struct beacon_data *presp; 696 struct beacon_data *presp;
697 struct sta_info *sta; 697 struct sta_info *sta;
698 int active_ibss;
699 u16 capability; 698 u16 capability;
700 699
701 active_ibss = ieee80211_sta_active_ibss(sdata); 700 if (!is_zero_ether_addr(ifibss->bssid)) {
702
703 if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) {
704 capability = WLAN_CAPABILITY_IBSS; 701 capability = WLAN_CAPABILITY_IBSS;
705 702
706 if (ifibss->privacy) 703 if (ifibss->privacy)
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 3701930c6649..5e44e3179e02 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1692,14 +1692,8 @@ void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
1692void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue); 1692void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue);
1693void ieee80211_add_pending_skb(struct ieee80211_local *local, 1693void ieee80211_add_pending_skb(struct ieee80211_local *local,
1694 struct sk_buff *skb); 1694 struct sk_buff *skb);
1695void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local, 1695void ieee80211_add_pending_skbs(struct ieee80211_local *local,
1696 struct sk_buff_head *skbs, 1696 struct sk_buff_head *skbs);
1697 void (*fn)(void *data), void *data);
1698static inline void ieee80211_add_pending_skbs(struct ieee80211_local *local,
1699 struct sk_buff_head *skbs)
1700{
1701 ieee80211_add_pending_skbs_fn(local, skbs, NULL, NULL);
1702}
1703void ieee80211_flush_queues(struct ieee80211_local *local, 1697void ieee80211_flush_queues(struct ieee80211_local *local,
1704 struct ieee80211_sub_if_data *sdata); 1698 struct ieee80211_sub_if_data *sdata);
1705 1699
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 3dfd20a453ab..ce1c44370610 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -418,20 +418,24 @@ int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
418 return ret; 418 return ret;
419 } 419 }
420 420
421 mutex_lock(&local->iflist_mtx);
422 rcu_assign_pointer(local->monitor_sdata, sdata);
423 mutex_unlock(&local->iflist_mtx);
424
421 mutex_lock(&local->mtx); 425 mutex_lock(&local->mtx);
422 ret = ieee80211_vif_use_channel(sdata, &local->monitor_chandef, 426 ret = ieee80211_vif_use_channel(sdata, &local->monitor_chandef,
423 IEEE80211_CHANCTX_EXCLUSIVE); 427 IEEE80211_CHANCTX_EXCLUSIVE);
424 mutex_unlock(&local->mtx); 428 mutex_unlock(&local->mtx);
425 if (ret) { 429 if (ret) {
430 mutex_lock(&local->iflist_mtx);
431 rcu_assign_pointer(local->monitor_sdata, NULL);
432 mutex_unlock(&local->iflist_mtx);
433 synchronize_net();
426 drv_remove_interface(local, sdata); 434 drv_remove_interface(local, sdata);
427 kfree(sdata); 435 kfree(sdata);
428 return ret; 436 return ret;
429 } 437 }
430 438
431 mutex_lock(&local->iflist_mtx);
432 rcu_assign_pointer(local->monitor_sdata, sdata);
433 mutex_unlock(&local->iflist_mtx);
434
435 return 0; 439 return 0;
436} 440}
437 441
@@ -770,12 +774,19 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
770 774
771 ieee80211_roc_purge(local, sdata); 775 ieee80211_roc_purge(local, sdata);
772 776
773 if (sdata->vif.type == NL80211_IFTYPE_STATION) 777 switch (sdata->vif.type) {
778 case NL80211_IFTYPE_STATION:
774 ieee80211_mgd_stop(sdata); 779 ieee80211_mgd_stop(sdata);
775 780 break;
776 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 781 case NL80211_IFTYPE_ADHOC:
777 ieee80211_ibss_stop(sdata); 782 ieee80211_ibss_stop(sdata);
778 783 break;
784 case NL80211_IFTYPE_AP:
785 cancel_work_sync(&sdata->u.ap.request_smps_work);
786 break;
787 default:
788 break;
789 }
779 790
780 /* 791 /*
781 * Remove all stations associated with this interface. 792 * Remove all stations associated with this interface.
@@ -1046,7 +1057,8 @@ static void ieee80211_uninit(struct net_device *dev)
1046 1057
1047static u16 ieee80211_netdev_select_queue(struct net_device *dev, 1058static u16 ieee80211_netdev_select_queue(struct net_device *dev,
1048 struct sk_buff *skb, 1059 struct sk_buff *skb,
1049 void *accel_priv) 1060 void *accel_priv,
1061 select_queue_fallback_t fallback)
1050{ 1062{
1051 return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb); 1063 return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
1052} 1064}
@@ -1064,7 +1076,8 @@ static const struct net_device_ops ieee80211_dataif_ops = {
1064 1076
1065static u16 ieee80211_monitor_select_queue(struct net_device *dev, 1077static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1066 struct sk_buff *skb, 1078 struct sk_buff *skb,
1067 void *accel_priv) 1079 void *accel_priv,
1080 select_queue_fallback_t fallback)
1068{ 1081{
1069 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1082 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1070 struct ieee80211_local *local = sdata->local; 1083 struct ieee80211_local *local = sdata->local;
diff --git a/net/mac80211/mesh_ps.c b/net/mac80211/mesh_ps.c
index 2802f9d9279d..ad8b377b4b9f 100644
--- a/net/mac80211/mesh_ps.c
+++ b/net/mac80211/mesh_ps.c
@@ -36,6 +36,7 @@ static struct sk_buff *mps_qos_null_get(struct sta_info *sta)
36 sdata->vif.addr); 36 sdata->vif.addr);
37 nullfunc->frame_control = fc; 37 nullfunc->frame_control = fc;
38 nullfunc->duration_id = 0; 38 nullfunc->duration_id = 0;
39 nullfunc->seq_ctrl = 0;
39 /* no address resolution for this frame -> set addr 1 immediately */ 40 /* no address resolution for this frame -> set addr 1 immediately */
40 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); 41 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
41 memset(skb_put(skb, 2), 0, 2); /* append QoS control field */ 42 memset(skb_put(skb, 2), 0, 2); /* append QoS control field */
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index fc1d82465b3c..245dce969b31 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -222,6 +222,7 @@ ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
222 switch (vht_oper->chan_width) { 222 switch (vht_oper->chan_width) {
223 case IEEE80211_VHT_CHANWIDTH_USE_HT: 223 case IEEE80211_VHT_CHANWIDTH_USE_HT:
224 vht_chandef.width = chandef->width; 224 vht_chandef.width = chandef->width;
225 vht_chandef.center_freq1 = chandef->center_freq1;
225 break; 226 break;
226 case IEEE80211_VHT_CHANWIDTH_80MHZ: 227 case IEEE80211_VHT_CHANWIDTH_80MHZ:
227 vht_chandef.width = NL80211_CHAN_WIDTH_80; 228 vht_chandef.width = NL80211_CHAN_WIDTH_80;
@@ -271,6 +272,28 @@ ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
271 ret = 0; 272 ret = 0;
272 273
273out: 274out:
275 /*
276 * When tracking the current AP, don't do any further checks if the
277 * new chandef is identical to the one we're currently using for the
278 * connection. This keeps us from playing ping-pong with regulatory,
279 * without it the following can happen (for example):
280 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
281 * - AP advertises regdom US
282 * - CRDA loads regdom US with 80 MHz prohibited (old database)
283 * - the code below detects an unsupported channel, downgrades, and
284 * we disconnect from the AP in the caller
285 * - disconnect causes CRDA to reload world regdomain and the game
286 * starts anew.
287 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
288 *
289 * It seems possible that there are still scenarios with CSA or real
290 * bandwidth changes where a this could happen, but those cases are
291 * less common and wouldn't completely prevent using the AP.
292 */
293 if (tracking &&
294 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
295 return ret;
296
274 /* don't print the message below for VHT mismatch if VHT is disabled */ 297 /* don't print the message below for VHT mismatch if VHT is disabled */
275 if (ret & IEEE80211_STA_DISABLE_VHT) 298 if (ret & IEEE80211_STA_DISABLE_VHT)
276 vht_chandef = *chandef; 299 vht_chandef = *chandef;
@@ -3753,6 +3776,7 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3753 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); 3776 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3754 if (WARN_ON(!chanctx_conf)) { 3777 if (WARN_ON(!chanctx_conf)) {
3755 rcu_read_unlock(); 3778 rcu_read_unlock();
3779 sta_info_free(local, new_sta);
3756 return -EINVAL; 3780 return -EINVAL;
3757 } 3781 }
3758 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def); 3782 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index c24ca0d0f469..3e57f96c9666 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1128,6 +1128,13 @@ static void sta_ps_end(struct sta_info *sta)
1128 sta->sta.addr, sta->sta.aid); 1128 sta->sta.addr, sta->sta.aid);
1129 1129
1130 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) { 1130 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1131 /*
1132 * Clear the flag only if the other one is still set
1133 * so that the TX path won't start TX'ing new frames
1134 * directly ... In the case that the driver flag isn't
1135 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1136 */
1137 clear_sta_flag(sta, WLAN_STA_PS_STA);
1131 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n", 1138 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1132 sta->sta.addr, sta->sta.aid); 1139 sta->sta.addr, sta->sta.aid);
1133 return; 1140 return;
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index decd30c1e290..137a192e64bc 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -91,7 +91,7 @@ static int sta_info_hash_del(struct ieee80211_local *local,
91 return -ENOENT; 91 return -ENOENT;
92} 92}
93 93
94static void cleanup_single_sta(struct sta_info *sta) 94static void __cleanup_single_sta(struct sta_info *sta)
95{ 95{
96 int ac, i; 96 int ac, i;
97 struct tid_ampdu_tx *tid_tx; 97 struct tid_ampdu_tx *tid_tx;
@@ -99,7 +99,8 @@ static void cleanup_single_sta(struct sta_info *sta)
99 struct ieee80211_local *local = sdata->local; 99 struct ieee80211_local *local = sdata->local;
100 struct ps_data *ps; 100 struct ps_data *ps;
101 101
102 if (test_sta_flag(sta, WLAN_STA_PS_STA)) { 102 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
103 test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
103 if (sta->sdata->vif.type == NL80211_IFTYPE_AP || 104 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
104 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 105 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
105 ps = &sdata->bss->ps; 106 ps = &sdata->bss->ps;
@@ -109,6 +110,7 @@ static void cleanup_single_sta(struct sta_info *sta)
109 return; 110 return;
110 111
111 clear_sta_flag(sta, WLAN_STA_PS_STA); 112 clear_sta_flag(sta, WLAN_STA_PS_STA);
113 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
112 114
113 atomic_dec(&ps->num_sta_ps); 115 atomic_dec(&ps->num_sta_ps);
114 sta_info_recalc_tim(sta); 116 sta_info_recalc_tim(sta);
@@ -139,7 +141,14 @@ static void cleanup_single_sta(struct sta_info *sta)
139 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending); 141 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
140 kfree(tid_tx); 142 kfree(tid_tx);
141 } 143 }
144}
142 145
146static void cleanup_single_sta(struct sta_info *sta)
147{
148 struct ieee80211_sub_if_data *sdata = sta->sdata;
149 struct ieee80211_local *local = sdata->local;
150
151 __cleanup_single_sta(sta);
143 sta_info_free(local, sta); 152 sta_info_free(local, sta);
144} 153}
145 154
@@ -330,6 +339,7 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
330 rcu_read_unlock(); 339 rcu_read_unlock();
331 340
332 spin_lock_init(&sta->lock); 341 spin_lock_init(&sta->lock);
342 spin_lock_init(&sta->ps_lock);
333 INIT_WORK(&sta->drv_unblock_wk, sta_unblock); 343 INIT_WORK(&sta->drv_unblock_wk, sta_unblock);
334 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work); 344 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
335 mutex_init(&sta->ampdu_mlme.mtx); 345 mutex_init(&sta->ampdu_mlme.mtx);
@@ -487,21 +497,26 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
487 goto out_err; 497 goto out_err;
488 } 498 }
489 499
490 /* notify driver */
491 err = sta_info_insert_drv_state(local, sdata, sta);
492 if (err)
493 goto out_err;
494
495 local->num_sta++; 500 local->num_sta++;
496 local->sta_generation++; 501 local->sta_generation++;
497 smp_mb(); 502 smp_mb();
498 503
504 /* simplify things and don't accept BA sessions yet */
505 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
506
499 /* make the station visible */ 507 /* make the station visible */
500 sta_info_hash_add(local, sta); 508 sta_info_hash_add(local, sta);
501 509
502 list_add_rcu(&sta->list, &local->sta_list); 510 list_add_rcu(&sta->list, &local->sta_list);
503 511
512 /* notify driver */
513 err = sta_info_insert_drv_state(local, sdata, sta);
514 if (err)
515 goto out_remove;
516
504 set_sta_flag(sta, WLAN_STA_INSERTED); 517 set_sta_flag(sta, WLAN_STA_INSERTED);
518 /* accept BA sessions now */
519 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
505 520
506 ieee80211_recalc_min_chandef(sdata); 521 ieee80211_recalc_min_chandef(sdata);
507 ieee80211_sta_debugfs_add(sta); 522 ieee80211_sta_debugfs_add(sta);
@@ -522,6 +537,12 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
522 mesh_accept_plinks_update(sdata); 537 mesh_accept_plinks_update(sdata);
523 538
524 return 0; 539 return 0;
540 out_remove:
541 sta_info_hash_del(local, sta);
542 list_del_rcu(&sta->list);
543 local->num_sta--;
544 synchronize_net();
545 __cleanup_single_sta(sta);
525 out_err: 546 out_err:
526 mutex_unlock(&local->sta_mtx); 547 mutex_unlock(&local->sta_mtx);
527 rcu_read_lock(); 548 rcu_read_lock();
@@ -1071,10 +1092,14 @@ struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
1071} 1092}
1072EXPORT_SYMBOL(ieee80211_find_sta); 1093EXPORT_SYMBOL(ieee80211_find_sta);
1073 1094
1074static void clear_sta_ps_flags(void *_sta) 1095/* powersave support code */
1096void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
1075{ 1097{
1076 struct sta_info *sta = _sta;
1077 struct ieee80211_sub_if_data *sdata = sta->sdata; 1098 struct ieee80211_sub_if_data *sdata = sta->sdata;
1099 struct ieee80211_local *local = sdata->local;
1100 struct sk_buff_head pending;
1101 int filtered = 0, buffered = 0, ac;
1102 unsigned long flags;
1078 struct ps_data *ps; 1103 struct ps_data *ps;
1079 1104
1080 if (sdata->vif.type == NL80211_IFTYPE_AP || 1105 if (sdata->vif.type == NL80211_IFTYPE_AP ||
@@ -1085,20 +1110,6 @@ static void clear_sta_ps_flags(void *_sta)
1085 else 1110 else
1086 return; 1111 return;
1087 1112
1088 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1089 if (test_and_clear_sta_flag(sta, WLAN_STA_PS_STA))
1090 atomic_dec(&ps->num_sta_ps);
1091}
1092
1093/* powersave support code */
1094void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
1095{
1096 struct ieee80211_sub_if_data *sdata = sta->sdata;
1097 struct ieee80211_local *local = sdata->local;
1098 struct sk_buff_head pending;
1099 int filtered = 0, buffered = 0, ac;
1100 unsigned long flags;
1101
1102 clear_sta_flag(sta, WLAN_STA_SP); 1113 clear_sta_flag(sta, WLAN_STA_SP);
1103 1114
1104 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1); 1115 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
@@ -1109,6 +1120,8 @@ void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
1109 1120
1110 skb_queue_head_init(&pending); 1121 skb_queue_head_init(&pending);
1111 1122
1123 /* sync with ieee80211_tx_h_unicast_ps_buf */
1124 spin_lock(&sta->ps_lock);
1112 /* Send all buffered frames to the station */ 1125 /* Send all buffered frames to the station */
1113 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 1126 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1114 int count = skb_queue_len(&pending), tmp; 1127 int count = skb_queue_len(&pending), tmp;
@@ -1127,7 +1140,12 @@ void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
1127 buffered += tmp - count; 1140 buffered += tmp - count;
1128 } 1141 }
1129 1142
1130 ieee80211_add_pending_skbs_fn(local, &pending, clear_sta_ps_flags, sta); 1143 ieee80211_add_pending_skbs(local, &pending);
1144 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1145 clear_sta_flag(sta, WLAN_STA_PS_STA);
1146 spin_unlock(&sta->ps_lock);
1147
1148 atomic_dec(&ps->num_sta_ps);
1131 1149
1132 /* This station just woke up and isn't aware of our SMPS state */ 1150 /* This station just woke up and isn't aware of our SMPS state */
1133 if (!ieee80211_smps_is_restrictive(sta->known_smps_mode, 1151 if (!ieee80211_smps_is_restrictive(sta->known_smps_mode,
@@ -1188,6 +1206,7 @@ static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata,
1188 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); 1206 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1189 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); 1207 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1190 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); 1208 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
1209 nullfunc->seq_ctrl = 0;
1191 1210
1192 skb->priority = tid; 1211 skb->priority = tid;
1193 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]); 1212 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index d77ff7090630..d3a6d8208f2f 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -267,6 +267,7 @@ struct ieee80211_tx_latency_stat {
267 * @drv_unblock_wk: used for driver PS unblocking 267 * @drv_unblock_wk: used for driver PS unblocking
268 * @listen_interval: listen interval of this station, when we're acting as AP 268 * @listen_interval: listen interval of this station, when we're acting as AP
269 * @_flags: STA flags, see &enum ieee80211_sta_info_flags, do not use directly 269 * @_flags: STA flags, see &enum ieee80211_sta_info_flags, do not use directly
270 * @ps_lock: used for powersave (when mac80211 is the AP) related locking
270 * @ps_tx_buf: buffers (per AC) of frames to transmit to this station 271 * @ps_tx_buf: buffers (per AC) of frames to transmit to this station
271 * when it leaves power saving state or polls 272 * when it leaves power saving state or polls
272 * @tx_filtered: buffers (per AC) of frames we already tried to 273 * @tx_filtered: buffers (per AC) of frames we already tried to
@@ -356,10 +357,8 @@ struct sta_info {
356 /* use the accessors defined below */ 357 /* use the accessors defined below */
357 unsigned long _flags; 358 unsigned long _flags;
358 359
359 /* 360 /* STA powersave lock and frame queues */
360 * STA powersave frame queues, no more than the internal 361 spinlock_t ps_lock;
361 * locking required.
362 */
363 struct sk_buff_head ps_tx_buf[IEEE80211_NUM_ACS]; 362 struct sk_buff_head ps_tx_buf[IEEE80211_NUM_ACS];
364 struct sk_buff_head tx_filtered[IEEE80211_NUM_ACS]; 363 struct sk_buff_head tx_filtered[IEEE80211_NUM_ACS];
365 unsigned long driver_buffered_tids; 364 unsigned long driver_buffered_tids;
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 27c990bf2320..4080c615636f 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -478,6 +478,20 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
478 sta->sta.addr, sta->sta.aid, ac); 478 sta->sta.addr, sta->sta.aid, ac);
479 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 479 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
480 purge_old_ps_buffers(tx->local); 480 purge_old_ps_buffers(tx->local);
481
482 /* sync with ieee80211_sta_ps_deliver_wakeup */
483 spin_lock(&sta->ps_lock);
484 /*
485 * STA woke up the meantime and all the frames on ps_tx_buf have
486 * been queued to pending queue. No reordering can happen, go
487 * ahead and Tx the packet.
488 */
489 if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
490 !test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
491 spin_unlock(&sta->ps_lock);
492 return TX_CONTINUE;
493 }
494
481 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) { 495 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
482 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]); 496 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
483 ps_dbg(tx->sdata, 497 ps_dbg(tx->sdata,
@@ -492,6 +506,7 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
492 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; 506 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
493 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS; 507 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
494 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb); 508 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
509 spin_unlock(&sta->ps_lock);
495 510
496 if (!timer_pending(&local->sta_cleanup)) 511 if (!timer_pending(&local->sta_cleanup))
497 mod_timer(&local->sta_cleanup, 512 mod_timer(&local->sta_cleanup,
@@ -878,7 +893,7 @@ static int ieee80211_fragment(struct ieee80211_tx_data *tx,
878 } 893 }
879 894
880 /* adjust first fragment's length */ 895 /* adjust first fragment's length */
881 skb->len = hdrlen + per_fragm; 896 skb_trim(skb, hdrlen + per_fragm);
882 return 0; 897 return 0;
883} 898}
884 899
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 676dc0967f37..b8700d417a9c 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -435,9 +435,8 @@ void ieee80211_add_pending_skb(struct ieee80211_local *local,
435 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 435 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
436} 436}
437 437
438void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local, 438void ieee80211_add_pending_skbs(struct ieee80211_local *local,
439 struct sk_buff_head *skbs, 439 struct sk_buff_head *skbs)
440 void (*fn)(void *data), void *data)
441{ 440{
442 struct ieee80211_hw *hw = &local->hw; 441 struct ieee80211_hw *hw = &local->hw;
443 struct sk_buff *skb; 442 struct sk_buff *skb;
@@ -461,9 +460,6 @@ void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local,
461 __skb_queue_tail(&local->pending[queue], skb); 460 __skb_queue_tail(&local->pending[queue], skb);
462 } 461 }
463 462
464 if (fn)
465 fn(data);
466
467 for (i = 0; i < hw->queues; i++) 463 for (i = 0; i < hw->queues; i++)
468 __ieee80211_wake_queue(hw, i, 464 __ieee80211_wake_queue(hw, i,
469 IEEE80211_QUEUE_STOP_REASON_SKB_ADD); 465 IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
@@ -1741,6 +1737,26 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1741 IEEE80211_QUEUE_STOP_REASON_SUSPEND); 1737 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
1742 1738
1743 /* 1739 /*
1740 * Reconfigure sched scan if it was interrupted by FW restart or
1741 * suspend.
1742 */
1743 mutex_lock(&local->mtx);
1744 sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata,
1745 lockdep_is_held(&local->mtx));
1746 if (sched_scan_sdata && local->sched_scan_req)
1747 /*
1748 * Sched scan stopped, but we don't want to report it. Instead,
1749 * we're trying to reschedule.
1750 */
1751 if (__ieee80211_request_sched_scan_start(sched_scan_sdata,
1752 local->sched_scan_req))
1753 sched_scan_stopped = true;
1754 mutex_unlock(&local->mtx);
1755
1756 if (sched_scan_stopped)
1757 cfg80211_sched_scan_stopped(local->hw.wiphy);
1758
1759 /*
1744 * If this is for hw restart things are still running. 1760 * If this is for hw restart things are still running.
1745 * We may want to change that later, however. 1761 * We may want to change that later, however.
1746 */ 1762 */
@@ -1768,26 +1784,6 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1768 WARN_ON(1); 1784 WARN_ON(1);
1769#endif 1785#endif
1770 1786
1771 /*
1772 * Reconfigure sched scan if it was interrupted by FW restart or
1773 * suspend.
1774 */
1775 mutex_lock(&local->mtx);
1776 sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata,
1777 lockdep_is_held(&local->mtx));
1778 if (sched_scan_sdata && local->sched_scan_req)
1779 /*
1780 * Sched scan stopped, but we don't want to report it. Instead,
1781 * we're trying to reschedule.
1782 */
1783 if (__ieee80211_request_sched_scan_start(sched_scan_sdata,
1784 local->sched_scan_req))
1785 sched_scan_stopped = true;
1786 mutex_unlock(&local->mtx);
1787
1788 if (sched_scan_stopped)
1789 cfg80211_sched_scan_stopped(local->hw.wiphy);
1790
1791 return 0; 1787 return 0;
1792} 1788}
1793 1789
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 21211c60ca98..d51422c778de 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -154,6 +154,11 @@ u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
154 return IEEE80211_AC_BE; 154 return IEEE80211_AC_BE;
155 } 155 }
156 156
157 if (skb->protocol == sdata->control_port_protocol) {
158 skb->priority = 7;
159 return ieee80211_downgrade_queue(sdata, skb);
160 }
161
157 /* use the data classifier to determine what 802.1d tag the 162 /* use the data classifier to determine what 802.1d tag the
158 * data frame has */ 163 * data frame has */
159 rcu_read_lock(); 164 rcu_read_lock();
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index c37467562fd0..e9410d17619d 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -513,7 +513,6 @@ config NFT_QUEUE
513 513
514config NFT_REJECT 514config NFT_REJECT
515 depends on NF_TABLES 515 depends on NF_TABLES
516 depends on NF_TABLES_IPV6 || !NF_TABLES_IPV6
517 default m if NETFILTER_ADVANCED=n 516 default m if NETFILTER_ADVANCED=n
518 tristate "Netfilter nf_tables reject support" 517 tristate "Netfilter nf_tables reject support"
519 help 518 help
@@ -521,6 +520,11 @@ config NFT_REJECT
521 explicitly deny and notify via TCP reset/ICMP informational errors 520 explicitly deny and notify via TCP reset/ICMP informational errors
522 unallowed traffic. 521 unallowed traffic.
523 522
523config NFT_REJECT_INET
524 depends on NF_TABLES_INET
525 default NFT_REJECT
526 tristate
527
524config NFT_COMPAT 528config NFT_COMPAT
525 depends on NF_TABLES 529 depends on NF_TABLES
526 depends on NETFILTER_XTABLES 530 depends on NETFILTER_XTABLES
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index ee9c4de5f8ed..bffdad774da7 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -79,6 +79,7 @@ obj-$(CONFIG_NFT_LIMIT) += nft_limit.o
79obj-$(CONFIG_NFT_NAT) += nft_nat.o 79obj-$(CONFIG_NFT_NAT) += nft_nat.o
80obj-$(CONFIG_NFT_QUEUE) += nft_queue.o 80obj-$(CONFIG_NFT_QUEUE) += nft_queue.o
81obj-$(CONFIG_NFT_REJECT) += nft_reject.o 81obj-$(CONFIG_NFT_REJECT) += nft_reject.o
82obj-$(CONFIG_NFT_REJECT_INET) += nft_reject_inet.o
82obj-$(CONFIG_NFT_RBTREE) += nft_rbtree.o 83obj-$(CONFIG_NFT_RBTREE) += nft_rbtree.o
83obj-$(CONFIG_NFT_HASH) += nft_hash.o 84obj-$(CONFIG_NFT_HASH) += nft_hash.o
84obj-$(CONFIG_NFT_COUNTER) += nft_counter.o 85obj-$(CONFIG_NFT_COUNTER) += nft_counter.o
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 59a1a85bcb3e..a8eb0a89326a 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -871,11 +871,11 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
871 cp->protocol = p->protocol; 871 cp->protocol = p->protocol;
872 ip_vs_addr_set(p->af, &cp->caddr, p->caddr); 872 ip_vs_addr_set(p->af, &cp->caddr, p->caddr);
873 cp->cport = p->cport; 873 cp->cport = p->cport;
874 ip_vs_addr_set(p->af, &cp->vaddr, p->vaddr); 874 /* proto should only be IPPROTO_IP if p->vaddr is a fwmark */
875 cp->vport = p->vport;
876 /* proto should only be IPPROTO_IP if d_addr is a fwmark */
877 ip_vs_addr_set(p->protocol == IPPROTO_IP ? AF_UNSPEC : p->af, 875 ip_vs_addr_set(p->protocol == IPPROTO_IP ? AF_UNSPEC : p->af,
878 &cp->daddr, daddr); 876 &cp->vaddr, p->vaddr);
877 cp->vport = p->vport;
878 ip_vs_addr_set(p->af, &cp->daddr, daddr);
879 cp->dport = dport; 879 cp->dport = dport;
880 cp->flags = flags; 880 cp->flags = flags;
881 cp->fwmark = fwmark; 881 cp->fwmark = fwmark;
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 8824ed0ccc9c..356bef519fe5 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -312,6 +312,21 @@ static void death_by_timeout(unsigned long ul_conntrack)
312 nf_ct_delete((struct nf_conn *)ul_conntrack, 0, 0); 312 nf_ct_delete((struct nf_conn *)ul_conntrack, 0, 0);
313} 313}
314 314
315static inline bool
316nf_ct_key_equal(struct nf_conntrack_tuple_hash *h,
317 const struct nf_conntrack_tuple *tuple,
318 u16 zone)
319{
320 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h);
321
322 /* A conntrack can be recreated with the equal tuple,
323 * so we need to check that the conntrack is confirmed
324 */
325 return nf_ct_tuple_equal(tuple, &h->tuple) &&
326 nf_ct_zone(ct) == zone &&
327 nf_ct_is_confirmed(ct);
328}
329
315/* 330/*
316 * Warning : 331 * Warning :
317 * - Caller must take a reference on returned object 332 * - Caller must take a reference on returned object
@@ -333,8 +348,7 @@ ____nf_conntrack_find(struct net *net, u16 zone,
333 local_bh_disable(); 348 local_bh_disable();
334begin: 349begin:
335 hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[bucket], hnnode) { 350 hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[bucket], hnnode) {
336 if (nf_ct_tuple_equal(tuple, &h->tuple) && 351 if (nf_ct_key_equal(h, tuple, zone)) {
337 nf_ct_zone(nf_ct_tuplehash_to_ctrack(h)) == zone) {
338 NF_CT_STAT_INC(net, found); 352 NF_CT_STAT_INC(net, found);
339 local_bh_enable(); 353 local_bh_enable();
340 return h; 354 return h;
@@ -372,8 +386,7 @@ begin:
372 !atomic_inc_not_zero(&ct->ct_general.use))) 386 !atomic_inc_not_zero(&ct->ct_general.use)))
373 h = NULL; 387 h = NULL;
374 else { 388 else {
375 if (unlikely(!nf_ct_tuple_equal(tuple, &h->tuple) || 389 if (unlikely(!nf_ct_key_equal(h, tuple, zone))) {
376 nf_ct_zone(ct) != zone)) {
377 nf_ct_put(ct); 390 nf_ct_put(ct);
378 goto begin; 391 goto begin;
379 } 392 }
@@ -435,7 +448,9 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct)
435 goto out; 448 goto out;
436 449
437 add_timer(&ct->timeout); 450 add_timer(&ct->timeout);
438 nf_conntrack_get(&ct->ct_general); 451 smp_wmb();
452 /* The caller holds a reference to this object */
453 atomic_set(&ct->ct_general.use, 2);
439 __nf_conntrack_hash_insert(ct, hash, repl_hash); 454 __nf_conntrack_hash_insert(ct, hash, repl_hash);
440 NF_CT_STAT_INC(net, insert); 455 NF_CT_STAT_INC(net, insert);
441 spin_unlock_bh(&nf_conntrack_lock); 456 spin_unlock_bh(&nf_conntrack_lock);
@@ -449,6 +464,21 @@ out:
449} 464}
450EXPORT_SYMBOL_GPL(nf_conntrack_hash_check_insert); 465EXPORT_SYMBOL_GPL(nf_conntrack_hash_check_insert);
451 466
467/* deletion from this larval template list happens via nf_ct_put() */
468void nf_conntrack_tmpl_insert(struct net *net, struct nf_conn *tmpl)
469{
470 __set_bit(IPS_TEMPLATE_BIT, &tmpl->status);
471 __set_bit(IPS_CONFIRMED_BIT, &tmpl->status);
472 nf_conntrack_get(&tmpl->ct_general);
473
474 spin_lock_bh(&nf_conntrack_lock);
475 /* Overload tuple linked list to put us in template list. */
476 hlist_nulls_add_head_rcu(&tmpl->tuplehash[IP_CT_DIR_ORIGINAL].hnnode,
477 &net->ct.tmpl);
478 spin_unlock_bh(&nf_conntrack_lock);
479}
480EXPORT_SYMBOL_GPL(nf_conntrack_tmpl_insert);
481
452/* Confirm a connection given skb; places it in hash table */ 482/* Confirm a connection given skb; places it in hash table */
453int 483int
454__nf_conntrack_confirm(struct sk_buff *skb) 484__nf_conntrack_confirm(struct sk_buff *skb)
@@ -720,11 +750,10 @@ __nf_conntrack_alloc(struct net *net, u16 zone,
720 nf_ct_zone->id = zone; 750 nf_ct_zone->id = zone;
721 } 751 }
722#endif 752#endif
723 /* 753 /* Because we use RCU lookups, we set ct_general.use to zero before
724 * changes to lookup keys must be done before setting refcnt to 1 754 * this is inserted in any list.
725 */ 755 */
726 smp_wmb(); 756 atomic_set(&ct->ct_general.use, 0);
727 atomic_set(&ct->ct_general.use, 1);
728 return ct; 757 return ct;
729 758
730#ifdef CONFIG_NF_CONNTRACK_ZONES 759#ifdef CONFIG_NF_CONNTRACK_ZONES
@@ -748,6 +777,11 @@ void nf_conntrack_free(struct nf_conn *ct)
748{ 777{
749 struct net *net = nf_ct_net(ct); 778 struct net *net = nf_ct_net(ct);
750 779
780 /* A freed object has refcnt == 0, that's
781 * the golden rule for SLAB_DESTROY_BY_RCU
782 */
783 NF_CT_ASSERT(atomic_read(&ct->ct_general.use) == 0);
784
751 nf_ct_ext_destroy(ct); 785 nf_ct_ext_destroy(ct);
752 nf_ct_ext_free(ct); 786 nf_ct_ext_free(ct);
753 kmem_cache_free(net->ct.nf_conntrack_cachep, ct); 787 kmem_cache_free(net->ct.nf_conntrack_cachep, ct);
@@ -843,6 +877,9 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
843 NF_CT_STAT_INC(net, new); 877 NF_CT_STAT_INC(net, new);
844 } 878 }
845 879
880 /* Now it is inserted into the unconfirmed list, bump refcount */
881 nf_conntrack_get(&ct->ct_general);
882
846 /* Overload tuple linked list to put us in unconfirmed list. */ 883 /* Overload tuple linked list to put us in unconfirmed list. */
847 hlist_nulls_add_head_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode, 884 hlist_nulls_add_head_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode,
848 &net->ct.unconfirmed); 885 &net->ct.unconfirmed);
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index bb322d0beb48..b9f0e0374322 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -1310,27 +1310,22 @@ ctnetlink_change_status(struct nf_conn *ct, const struct nlattr * const cda[])
1310} 1310}
1311 1311
1312static int 1312static int
1313ctnetlink_change_nat(struct nf_conn *ct, const struct nlattr * const cda[]) 1313ctnetlink_setup_nat(struct nf_conn *ct, const struct nlattr * const cda[])
1314{ 1314{
1315#ifdef CONFIG_NF_NAT_NEEDED 1315#ifdef CONFIG_NF_NAT_NEEDED
1316 int ret; 1316 int ret;
1317 1317
1318 if (cda[CTA_NAT_DST]) { 1318 ret = ctnetlink_parse_nat_setup(ct, NF_NAT_MANIP_DST,
1319 ret = ctnetlink_parse_nat_setup(ct, 1319 cda[CTA_NAT_DST]);
1320 NF_NAT_MANIP_DST, 1320 if (ret < 0)
1321 cda[CTA_NAT_DST]); 1321 return ret;
1322 if (ret < 0) 1322
1323 return ret; 1323 ret = ctnetlink_parse_nat_setup(ct, NF_NAT_MANIP_SRC,
1324 } 1324 cda[CTA_NAT_SRC]);
1325 if (cda[CTA_NAT_SRC]) { 1325 return ret;
1326 ret = ctnetlink_parse_nat_setup(ct,
1327 NF_NAT_MANIP_SRC,
1328 cda[CTA_NAT_SRC]);
1329 if (ret < 0)
1330 return ret;
1331 }
1332 return 0;
1333#else 1326#else
1327 if (!cda[CTA_NAT_DST] && !cda[CTA_NAT_SRC])
1328 return 0;
1334 return -EOPNOTSUPP; 1329 return -EOPNOTSUPP;
1335#endif 1330#endif
1336} 1331}
@@ -1659,11 +1654,9 @@ ctnetlink_create_conntrack(struct net *net, u16 zone,
1659 goto err2; 1654 goto err2;
1660 } 1655 }
1661 1656
1662 if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) { 1657 err = ctnetlink_setup_nat(ct, cda);
1663 err = ctnetlink_change_nat(ct, cda); 1658 if (err < 0)
1664 if (err < 0) 1659 goto err2;
1665 goto err2;
1666 }
1667 1660
1668 nf_ct_acct_ext_add(ct, GFP_ATOMIC); 1661 nf_ct_acct_ext_add(ct, GFP_ATOMIC);
1669 nf_ct_tstamp_ext_add(ct, GFP_ATOMIC); 1662 nf_ct_tstamp_ext_add(ct, GFP_ATOMIC);
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index d3f5cd6dd962..52ca952b802c 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -432,15 +432,15 @@ nf_nat_setup_info(struct nf_conn *ct,
432} 432}
433EXPORT_SYMBOL(nf_nat_setup_info); 433EXPORT_SYMBOL(nf_nat_setup_info);
434 434
435unsigned int 435static unsigned int
436nf_nat_alloc_null_binding(struct nf_conn *ct, unsigned int hooknum) 436__nf_nat_alloc_null_binding(struct nf_conn *ct, enum nf_nat_manip_type manip)
437{ 437{
438 /* Force range to this IP; let proto decide mapping for 438 /* Force range to this IP; let proto decide mapping for
439 * per-proto parts (hence not IP_NAT_RANGE_PROTO_SPECIFIED). 439 * per-proto parts (hence not IP_NAT_RANGE_PROTO_SPECIFIED).
440 * Use reply in case it's already been mangled (eg local packet). 440 * Use reply in case it's already been mangled (eg local packet).
441 */ 441 */
442 union nf_inet_addr ip = 442 union nf_inet_addr ip =
443 (HOOK2MANIP(hooknum) == NF_NAT_MANIP_SRC ? 443 (manip == NF_NAT_MANIP_SRC ?
444 ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3 : 444 ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3 :
445 ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3); 445 ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3);
446 struct nf_nat_range range = { 446 struct nf_nat_range range = {
@@ -448,7 +448,13 @@ nf_nat_alloc_null_binding(struct nf_conn *ct, unsigned int hooknum)
448 .min_addr = ip, 448 .min_addr = ip,
449 .max_addr = ip, 449 .max_addr = ip,
450 }; 450 };
451 return nf_nat_setup_info(ct, &range, HOOK2MANIP(hooknum)); 451 return nf_nat_setup_info(ct, &range, manip);
452}
453
454unsigned int
455nf_nat_alloc_null_binding(struct nf_conn *ct, unsigned int hooknum)
456{
457 return __nf_nat_alloc_null_binding(ct, HOOK2MANIP(hooknum));
452} 458}
453EXPORT_SYMBOL_GPL(nf_nat_alloc_null_binding); 459EXPORT_SYMBOL_GPL(nf_nat_alloc_null_binding);
454 460
@@ -702,9 +708,9 @@ static const struct nla_policy nat_nla_policy[CTA_NAT_MAX+1] = {
702 708
703static int 709static int
704nfnetlink_parse_nat(const struct nlattr *nat, 710nfnetlink_parse_nat(const struct nlattr *nat,
705 const struct nf_conn *ct, struct nf_nat_range *range) 711 const struct nf_conn *ct, struct nf_nat_range *range,
712 const struct nf_nat_l3proto *l3proto)
706{ 713{
707 const struct nf_nat_l3proto *l3proto;
708 struct nlattr *tb[CTA_NAT_MAX+1]; 714 struct nlattr *tb[CTA_NAT_MAX+1];
709 int err; 715 int err;
710 716
@@ -714,38 +720,46 @@ nfnetlink_parse_nat(const struct nlattr *nat,
714 if (err < 0) 720 if (err < 0)
715 return err; 721 return err;
716 722
717 rcu_read_lock();
718 l3proto = __nf_nat_l3proto_find(nf_ct_l3num(ct));
719 if (l3proto == NULL) {
720 err = -EAGAIN;
721 goto out;
722 }
723 err = l3proto->nlattr_to_range(tb, range); 723 err = l3proto->nlattr_to_range(tb, range);
724 if (err < 0) 724 if (err < 0)
725 goto out; 725 return err;
726 726
727 if (!tb[CTA_NAT_PROTO]) 727 if (!tb[CTA_NAT_PROTO])
728 goto out; 728 return 0;
729 729
730 err = nfnetlink_parse_nat_proto(tb[CTA_NAT_PROTO], ct, range); 730 return nfnetlink_parse_nat_proto(tb[CTA_NAT_PROTO], ct, range);
731out:
732 rcu_read_unlock();
733 return err;
734} 731}
735 732
733/* This function is called under rcu_read_lock() */
736static int 734static int
737nfnetlink_parse_nat_setup(struct nf_conn *ct, 735nfnetlink_parse_nat_setup(struct nf_conn *ct,
738 enum nf_nat_manip_type manip, 736 enum nf_nat_manip_type manip,
739 const struct nlattr *attr) 737 const struct nlattr *attr)
740{ 738{
741 struct nf_nat_range range; 739 struct nf_nat_range range;
740 const struct nf_nat_l3proto *l3proto;
742 int err; 741 int err;
743 742
744 err = nfnetlink_parse_nat(attr, ct, &range); 743 /* Should not happen, restricted to creating new conntracks
744 * via ctnetlink.
745 */
746 if (WARN_ON_ONCE(nf_nat_initialized(ct, manip)))
747 return -EEXIST;
748
749 /* Make sure that L3 NAT is there by when we call nf_nat_setup_info to
750 * attach the null binding, otherwise this may oops.
751 */
752 l3proto = __nf_nat_l3proto_find(nf_ct_l3num(ct));
753 if (l3proto == NULL)
754 return -EAGAIN;
755
756 /* No NAT information has been passed, allocate the null-binding */
757 if (attr == NULL)
758 return __nf_nat_alloc_null_binding(ct, manip);
759
760 err = nfnetlink_parse_nat(attr, ct, &range, l3proto);
745 if (err < 0) 761 if (err < 0)
746 return err; 762 return err;
747 if (nf_nat_initialized(ct, manip))
748 return -EEXIST;
749 763
750 return nf_nat_setup_info(ct, &range, manip); 764 return nf_nat_setup_info(ct, &range, manip);
751} 765}
diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c
index 9858e3e51a3a..52e20c9a46a5 100644
--- a/net/netfilter/nf_synproxy_core.c
+++ b/net/netfilter/nf_synproxy_core.c
@@ -363,9 +363,8 @@ static int __net_init synproxy_net_init(struct net *net)
363 goto err2; 363 goto err2;
364 if (!nfct_synproxy_ext_add(ct)) 364 if (!nfct_synproxy_ext_add(ct))
365 goto err2; 365 goto err2;
366 __set_bit(IPS_TEMPLATE_BIT, &ct->status);
367 __set_bit(IPS_CONFIRMED_BIT, &ct->status);
368 366
367 nf_conntrack_tmpl_insert(net, ct);
369 snet->tmpl = ct; 368 snet->tmpl = ct;
370 369
371 snet->stats = alloc_percpu(struct synproxy_stats); 370 snet->stats = alloc_percpu(struct synproxy_stats);
@@ -390,7 +389,7 @@ static void __net_exit synproxy_net_exit(struct net *net)
390{ 389{
391 struct synproxy_net *snet = synproxy_pernet(net); 390 struct synproxy_net *snet = synproxy_pernet(net);
392 391
393 nf_conntrack_free(snet->tmpl); 392 nf_ct_put(snet->tmpl);
394 synproxy_proc_exit(net); 393 synproxy_proc_exit(net);
395 free_percpu(snet->stats); 394 free_percpu(snet->stats);
396} 395}
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 117bbaaddde6..adce01e8bb57 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -1008,10 +1008,8 @@ notify:
1008 return 0; 1008 return 0;
1009} 1009}
1010 1010
1011static void nf_tables_rcu_chain_destroy(struct rcu_head *head) 1011static void nf_tables_chain_destroy(struct nft_chain *chain)
1012{ 1012{
1013 struct nft_chain *chain = container_of(head, struct nft_chain, rcu_head);
1014
1015 BUG_ON(chain->use > 0); 1013 BUG_ON(chain->use > 0);
1016 1014
1017 if (chain->flags & NFT_BASE_CHAIN) { 1015 if (chain->flags & NFT_BASE_CHAIN) {
@@ -1045,7 +1043,7 @@ static int nf_tables_delchain(struct sock *nlsk, struct sk_buff *skb,
1045 if (IS_ERR(chain)) 1043 if (IS_ERR(chain))
1046 return PTR_ERR(chain); 1044 return PTR_ERR(chain);
1047 1045
1048 if (!list_empty(&chain->rules)) 1046 if (!list_empty(&chain->rules) || chain->use > 0)
1049 return -EBUSY; 1047 return -EBUSY;
1050 1048
1051 list_del(&chain->list); 1049 list_del(&chain->list);
@@ -1059,7 +1057,9 @@ static int nf_tables_delchain(struct sock *nlsk, struct sk_buff *skb,
1059 family); 1057 family);
1060 1058
1061 /* Make sure all rule references are gone before this is released */ 1059 /* Make sure all rule references are gone before this is released */
1062 call_rcu(&chain->rcu_head, nf_tables_rcu_chain_destroy); 1060 synchronize_rcu();
1061
1062 nf_tables_chain_destroy(chain);
1063 return 0; 1063 return 0;
1064} 1064}
1065 1065
@@ -1114,35 +1114,45 @@ void nft_unregister_expr(struct nft_expr_type *type)
1114} 1114}
1115EXPORT_SYMBOL_GPL(nft_unregister_expr); 1115EXPORT_SYMBOL_GPL(nft_unregister_expr);
1116 1116
1117static const struct nft_expr_type *__nft_expr_type_get(struct nlattr *nla) 1117static const struct nft_expr_type *__nft_expr_type_get(u8 family,
1118 struct nlattr *nla)
1118{ 1119{
1119 const struct nft_expr_type *type; 1120 const struct nft_expr_type *type;
1120 1121
1121 list_for_each_entry(type, &nf_tables_expressions, list) { 1122 list_for_each_entry(type, &nf_tables_expressions, list) {
1122 if (!nla_strcmp(nla, type->name)) 1123 if (!nla_strcmp(nla, type->name) &&
1124 (!type->family || type->family == family))
1123 return type; 1125 return type;
1124 } 1126 }
1125 return NULL; 1127 return NULL;
1126} 1128}
1127 1129
1128static const struct nft_expr_type *nft_expr_type_get(struct nlattr *nla) 1130static const struct nft_expr_type *nft_expr_type_get(u8 family,
1131 struct nlattr *nla)
1129{ 1132{
1130 const struct nft_expr_type *type; 1133 const struct nft_expr_type *type;
1131 1134
1132 if (nla == NULL) 1135 if (nla == NULL)
1133 return ERR_PTR(-EINVAL); 1136 return ERR_PTR(-EINVAL);
1134 1137
1135 type = __nft_expr_type_get(nla); 1138 type = __nft_expr_type_get(family, nla);
1136 if (type != NULL && try_module_get(type->owner)) 1139 if (type != NULL && try_module_get(type->owner))
1137 return type; 1140 return type;
1138 1141
1139#ifdef CONFIG_MODULES 1142#ifdef CONFIG_MODULES
1140 if (type == NULL) { 1143 if (type == NULL) {
1141 nfnl_unlock(NFNL_SUBSYS_NFTABLES); 1144 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
1145 request_module("nft-expr-%u-%.*s", family,
1146 nla_len(nla), (char *)nla_data(nla));
1147 nfnl_lock(NFNL_SUBSYS_NFTABLES);
1148 if (__nft_expr_type_get(family, nla))
1149 return ERR_PTR(-EAGAIN);
1150
1151 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
1142 request_module("nft-expr-%.*s", 1152 request_module("nft-expr-%.*s",
1143 nla_len(nla), (char *)nla_data(nla)); 1153 nla_len(nla), (char *)nla_data(nla));
1144 nfnl_lock(NFNL_SUBSYS_NFTABLES); 1154 nfnl_lock(NFNL_SUBSYS_NFTABLES);
1145 if (__nft_expr_type_get(nla)) 1155 if (__nft_expr_type_get(family, nla))
1146 return ERR_PTR(-EAGAIN); 1156 return ERR_PTR(-EAGAIN);
1147 } 1157 }
1148#endif 1158#endif
@@ -1193,7 +1203,7 @@ static int nf_tables_expr_parse(const struct nft_ctx *ctx,
1193 if (err < 0) 1203 if (err < 0)
1194 return err; 1204 return err;
1195 1205
1196 type = nft_expr_type_get(tb[NFTA_EXPR_NAME]); 1206 type = nft_expr_type_get(ctx->afi->family, tb[NFTA_EXPR_NAME]);
1197 if (IS_ERR(type)) 1207 if (IS_ERR(type))
1198 return PTR_ERR(type); 1208 return PTR_ERR(type);
1199 1209
@@ -1521,9 +1531,8 @@ err:
1521 return err; 1531 return err;
1522} 1532}
1523 1533
1524static void nf_tables_rcu_rule_destroy(struct rcu_head *head) 1534static void nf_tables_rule_destroy(struct nft_rule *rule)
1525{ 1535{
1526 struct nft_rule *rule = container_of(head, struct nft_rule, rcu_head);
1527 struct nft_expr *expr; 1536 struct nft_expr *expr;
1528 1537
1529 /* 1538 /*
@@ -1538,11 +1547,6 @@ static void nf_tables_rcu_rule_destroy(struct rcu_head *head)
1538 kfree(rule); 1547 kfree(rule);
1539} 1548}
1540 1549
1541static void nf_tables_rule_destroy(struct nft_rule *rule)
1542{
1543 call_rcu(&rule->rcu_head, nf_tables_rcu_rule_destroy);
1544}
1545
1546#define NFT_RULE_MAXEXPRS 128 1550#define NFT_RULE_MAXEXPRS 128
1547 1551
1548static struct nft_expr_info *info; 1552static struct nft_expr_info *info;
@@ -1809,9 +1813,6 @@ static int nf_tables_commit(struct sk_buff *skb)
1809 synchronize_rcu(); 1813 synchronize_rcu();
1810 1814
1811 list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) { 1815 list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
1812 /* Delete this rule from the dirty list */
1813 list_del(&rupd->list);
1814
1815 /* This rule was inactive in the past and just became active. 1816 /* This rule was inactive in the past and just became active.
1816 * Clear the next bit of the genmask since its meaning has 1817 * Clear the next bit of the genmask since its meaning has
1817 * changed, now it is the future. 1818 * changed, now it is the future.
@@ -1822,6 +1823,7 @@ static int nf_tables_commit(struct sk_buff *skb)
1822 rupd->chain, rupd->rule, 1823 rupd->chain, rupd->rule,
1823 NFT_MSG_NEWRULE, 0, 1824 NFT_MSG_NEWRULE, 0,
1824 rupd->family); 1825 rupd->family);
1826 list_del(&rupd->list);
1825 kfree(rupd); 1827 kfree(rupd);
1826 continue; 1828 continue;
1827 } 1829 }
@@ -1831,7 +1833,15 @@ static int nf_tables_commit(struct sk_buff *skb)
1831 nf_tables_rule_notify(skb, rupd->nlh, rupd->table, rupd->chain, 1833 nf_tables_rule_notify(skb, rupd->nlh, rupd->table, rupd->chain,
1832 rupd->rule, NFT_MSG_DELRULE, 0, 1834 rupd->rule, NFT_MSG_DELRULE, 0,
1833 rupd->family); 1835 rupd->family);
1836 }
1837
1838 /* Make sure we don't see any packet traversing old rules */
1839 synchronize_rcu();
1840
1841 /* Now we can safely release unused old rules */
1842 list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
1834 nf_tables_rule_destroy(rupd->rule); 1843 nf_tables_rule_destroy(rupd->rule);
1844 list_del(&rupd->list);
1835 kfree(rupd); 1845 kfree(rupd);
1836 } 1846 }
1837 1847
@@ -1844,20 +1854,26 @@ static int nf_tables_abort(struct sk_buff *skb)
1844 struct nft_rule_trans *rupd, *tmp; 1854 struct nft_rule_trans *rupd, *tmp;
1845 1855
1846 list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) { 1856 list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
1847 /* Delete all rules from the dirty list */
1848 list_del(&rupd->list);
1849
1850 if (!nft_rule_is_active_next(net, rupd->rule)) { 1857 if (!nft_rule_is_active_next(net, rupd->rule)) {
1851 nft_rule_clear(net, rupd->rule); 1858 nft_rule_clear(net, rupd->rule);
1859 list_del(&rupd->list);
1852 kfree(rupd); 1860 kfree(rupd);
1853 continue; 1861 continue;
1854 } 1862 }
1855 1863
1856 /* This rule is inactive, get rid of it */ 1864 /* This rule is inactive, get rid of it */
1857 list_del_rcu(&rupd->rule->list); 1865 list_del_rcu(&rupd->rule->list);
1866 }
1867
1868 /* Make sure we don't see any packet accessing aborted rules */
1869 synchronize_rcu();
1870
1871 list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
1858 nf_tables_rule_destroy(rupd->rule); 1872 nf_tables_rule_destroy(rupd->rule);
1873 list_del(&rupd->list);
1859 kfree(rupd); 1874 kfree(rupd);
1860 } 1875 }
1876
1861 return 0; 1877 return 0;
1862} 1878}
1863 1879
@@ -1943,6 +1959,9 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx,
1943 } 1959 }
1944 1960
1945 if (nla[NFTA_SET_TABLE] != NULL) { 1961 if (nla[NFTA_SET_TABLE] != NULL) {
1962 if (afi == NULL)
1963 return -EAFNOSUPPORT;
1964
1946 table = nf_tables_table_lookup(afi, nla[NFTA_SET_TABLE]); 1965 table = nf_tables_table_lookup(afi, nla[NFTA_SET_TABLE]);
1947 if (IS_ERR(table)) 1966 if (IS_ERR(table))
1948 return PTR_ERR(table); 1967 return PTR_ERR(table);
@@ -1989,13 +2008,13 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
1989 2008
1990 if (!sscanf(i->name, name, &tmp)) 2009 if (!sscanf(i->name, name, &tmp))
1991 continue; 2010 continue;
1992 if (tmp < 0 || tmp > BITS_PER_LONG * PAGE_SIZE) 2011 if (tmp < 0 || tmp >= BITS_PER_BYTE * PAGE_SIZE)
1993 continue; 2012 continue;
1994 2013
1995 set_bit(tmp, inuse); 2014 set_bit(tmp, inuse);
1996 } 2015 }
1997 2016
1998 n = find_first_zero_bit(inuse, BITS_PER_LONG * PAGE_SIZE); 2017 n = find_first_zero_bit(inuse, BITS_PER_BYTE * PAGE_SIZE);
1999 free_page((unsigned long)inuse); 2018 free_page((unsigned long)inuse);
2000 } 2019 }
2001 2020
@@ -2428,6 +2447,8 @@ static int nf_tables_delset(struct sock *nlsk, struct sk_buff *skb,
2428 struct nft_ctx ctx; 2447 struct nft_ctx ctx;
2429 int err; 2448 int err;
2430 2449
2450 if (nfmsg->nfgen_family == NFPROTO_UNSPEC)
2451 return -EAFNOSUPPORT;
2431 if (nla[NFTA_SET_TABLE] == NULL) 2452 if (nla[NFTA_SET_TABLE] == NULL)
2432 return -EINVAL; 2453 return -EINVAL;
2433 2454
@@ -2435,9 +2456,6 @@ static int nf_tables_delset(struct sock *nlsk, struct sk_buff *skb,
2435 if (err < 0) 2456 if (err < 0)
2436 return err; 2457 return err;
2437 2458
2438 if (nfmsg->nfgen_family == NFPROTO_UNSPEC)
2439 return -EAFNOSUPPORT;
2440
2441 set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_NAME]); 2459 set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_NAME]);
2442 if (IS_ERR(set)) 2460 if (IS_ERR(set))
2443 return PTR_ERR(set); 2461 return PTR_ERR(set);
@@ -2723,6 +2741,9 @@ static int nft_add_set_elem(const struct nft_ctx *ctx, struct nft_set *set,
2723 if (nla[NFTA_SET_ELEM_DATA] == NULL && 2741 if (nla[NFTA_SET_ELEM_DATA] == NULL &&
2724 !(elem.flags & NFT_SET_ELEM_INTERVAL_END)) 2742 !(elem.flags & NFT_SET_ELEM_INTERVAL_END))
2725 return -EINVAL; 2743 return -EINVAL;
2744 if (nla[NFTA_SET_ELEM_DATA] != NULL &&
2745 elem.flags & NFT_SET_ELEM_INTERVAL_END)
2746 return -EINVAL;
2726 } else { 2747 } else {
2727 if (nla[NFTA_SET_ELEM_DATA] != NULL) 2748 if (nla[NFTA_SET_ELEM_DATA] != NULL)
2728 return -EINVAL; 2749 return -EINVAL;
@@ -2977,6 +2998,9 @@ static int nf_tables_loop_check_setelem(const struct nft_ctx *ctx,
2977 const struct nft_set_iter *iter, 2998 const struct nft_set_iter *iter,
2978 const struct nft_set_elem *elem) 2999 const struct nft_set_elem *elem)
2979{ 3000{
3001 if (elem->flags & NFT_SET_ELEM_INTERVAL_END)
3002 return 0;
3003
2980 switch (elem->data.verdict) { 3004 switch (elem->data.verdict) {
2981 case NFT_JUMP: 3005 case NFT_JUMP:
2982 case NFT_GOTO: 3006 case NFT_GOTO:
diff --git a/net/netfilter/nf_tables_core.c b/net/netfilter/nf_tables_core.c
index 0d879fcb8763..90998a6ff8b9 100644
--- a/net/netfilter/nf_tables_core.c
+++ b/net/netfilter/nf_tables_core.c
@@ -103,9 +103,9 @@ static struct nf_loginfo trace_loginfo = {
103 }, 103 },
104}; 104};
105 105
106static inline void nft_trace_packet(const struct nft_pktinfo *pkt, 106static void nft_trace_packet(const struct nft_pktinfo *pkt,
107 const struct nft_chain *chain, 107 const struct nft_chain *chain,
108 int rulenum, enum nft_trace type) 108 int rulenum, enum nft_trace type)
109{ 109{
110 struct net *net = dev_net(pkt->in ? pkt->in : pkt->out); 110 struct net *net = dev_net(pkt->in ? pkt->in : pkt->out);
111 111
diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
index f072fe803510..108120f216b1 100644
--- a/net/netfilter/nfnetlink_queue_core.c
+++ b/net/netfilter/nfnetlink_queue_core.c
@@ -354,13 +354,16 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
354 354
355 skb = nfnetlink_alloc_skb(net, size, queue->peer_portid, 355 skb = nfnetlink_alloc_skb(net, size, queue->peer_portid,
356 GFP_ATOMIC); 356 GFP_ATOMIC);
357 if (!skb) 357 if (!skb) {
358 skb_tx_error(entskb);
358 return NULL; 359 return NULL;
360 }
359 361
360 nlh = nlmsg_put(skb, 0, 0, 362 nlh = nlmsg_put(skb, 0, 0,
361 NFNL_SUBSYS_QUEUE << 8 | NFQNL_MSG_PACKET, 363 NFNL_SUBSYS_QUEUE << 8 | NFQNL_MSG_PACKET,
362 sizeof(struct nfgenmsg), 0); 364 sizeof(struct nfgenmsg), 0);
363 if (!nlh) { 365 if (!nlh) {
366 skb_tx_error(entskb);
364 kfree_skb(skb); 367 kfree_skb(skb);
365 return NULL; 368 return NULL;
366 } 369 }
@@ -488,13 +491,15 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
488 nla->nla_type = NFQA_PAYLOAD; 491 nla->nla_type = NFQA_PAYLOAD;
489 nla->nla_len = nla_attr_size(data_len); 492 nla->nla_len = nla_attr_size(data_len);
490 493
491 skb_zerocopy(skb, entskb, data_len, hlen); 494 if (skb_zerocopy(skb, entskb, data_len, hlen))
495 goto nla_put_failure;
492 } 496 }
493 497
494 nlh->nlmsg_len = skb->len; 498 nlh->nlmsg_len = skb->len;
495 return skb; 499 return skb;
496 500
497nla_put_failure: 501nla_put_failure:
502 skb_tx_error(entskb);
498 kfree_skb(skb); 503 kfree_skb(skb);
499 net_err_ratelimited("nf_queue: error creating packet message\n"); 504 net_err_ratelimited("nf_queue: error creating packet message\n");
500 return NULL; 505 return NULL;
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index 917052e20602..46e275403838 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -226,6 +226,7 @@ static int nft_ct_init_validate_get(const struct nft_expr *expr,
226 if (tb[NFTA_CT_DIRECTION] != NULL) 226 if (tb[NFTA_CT_DIRECTION] != NULL)
227 return -EINVAL; 227 return -EINVAL;
228 break; 228 break;
229 case NFT_CT_L3PROTOCOL:
229 case NFT_CT_PROTOCOL: 230 case NFT_CT_PROTOCOL:
230 case NFT_CT_SRC: 231 case NFT_CT_SRC:
231 case NFT_CT_DST: 232 case NFT_CT_DST:
@@ -311,8 +312,19 @@ static int nft_ct_get_dump(struct sk_buff *skb, const struct nft_expr *expr)
311 goto nla_put_failure; 312 goto nla_put_failure;
312 if (nla_put_be32(skb, NFTA_CT_KEY, htonl(priv->key))) 313 if (nla_put_be32(skb, NFTA_CT_KEY, htonl(priv->key)))
313 goto nla_put_failure; 314 goto nla_put_failure;
314 if (nla_put_u8(skb, NFTA_CT_DIRECTION, priv->dir)) 315
315 goto nla_put_failure; 316 switch (priv->key) {
317 case NFT_CT_PROTOCOL:
318 case NFT_CT_SRC:
319 case NFT_CT_DST:
320 case NFT_CT_PROTO_SRC:
321 case NFT_CT_PROTO_DST:
322 if (nla_put_u8(skb, NFTA_CT_DIRECTION, priv->dir))
323 goto nla_put_failure;
324 default:
325 break;
326 }
327
316 return 0; 328 return 0;
317 329
318nla_put_failure: 330nla_put_failure:
diff --git a/net/netfilter/nft_log.c b/net/netfilter/nft_log.c
index 5af790123ad8..26c5154e05f3 100644
--- a/net/netfilter/nft_log.c
+++ b/net/netfilter/nft_log.c
@@ -23,7 +23,6 @@ static const char *nft_log_null_prefix = "";
23struct nft_log { 23struct nft_log {
24 struct nf_loginfo loginfo; 24 struct nf_loginfo loginfo;
25 char *prefix; 25 char *prefix;
26 int family;
27}; 26};
28 27
29static void nft_log_eval(const struct nft_expr *expr, 28static void nft_log_eval(const struct nft_expr *expr,
@@ -33,7 +32,7 @@ static void nft_log_eval(const struct nft_expr *expr,
33 const struct nft_log *priv = nft_expr_priv(expr); 32 const struct nft_log *priv = nft_expr_priv(expr);
34 struct net *net = dev_net(pkt->in ? pkt->in : pkt->out); 33 struct net *net = dev_net(pkt->in ? pkt->in : pkt->out);
35 34
36 nf_log_packet(net, priv->family, pkt->ops->hooknum, pkt->skb, pkt->in, 35 nf_log_packet(net, pkt->ops->pf, pkt->ops->hooknum, pkt->skb, pkt->in,
37 pkt->out, &priv->loginfo, "%s", priv->prefix); 36 pkt->out, &priv->loginfo, "%s", priv->prefix);
38} 37}
39 38
@@ -52,8 +51,6 @@ static int nft_log_init(const struct nft_ctx *ctx,
52 struct nf_loginfo *li = &priv->loginfo; 51 struct nf_loginfo *li = &priv->loginfo;
53 const struct nlattr *nla; 52 const struct nlattr *nla;
54 53
55 priv->family = ctx->afi->family;
56
57 nla = tb[NFTA_LOG_PREFIX]; 54 nla = tb[NFTA_LOG_PREFIX];
58 if (nla != NULL) { 55 if (nla != NULL) {
59 priv->prefix = kmalloc(nla_len(nla) + 1, GFP_KERNEL); 56 priv->prefix = kmalloc(nla_len(nla) + 1, GFP_KERNEL);
diff --git a/net/netfilter/nft_lookup.c b/net/netfilter/nft_lookup.c
index 8a6116b75b5a..bb4ef4cccb6e 100644
--- a/net/netfilter/nft_lookup.c
+++ b/net/netfilter/nft_lookup.c
@@ -16,6 +16,7 @@
16#include <linux/netfilter.h> 16#include <linux/netfilter.h>
17#include <linux/netfilter/nf_tables.h> 17#include <linux/netfilter/nf_tables.h>
18#include <net/netfilter/nf_tables.h> 18#include <net/netfilter/nf_tables.h>
19#include <net/netfilter/nf_tables_core.h>
19 20
20struct nft_lookup { 21struct nft_lookup {
21 struct nft_set *set; 22 struct nft_set *set;
diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index e8254ad2e5a9..425cf39af890 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -116,7 +116,7 @@ static void nft_meta_get_eval(const struct nft_expr *expr,
116 skb->sk->sk_socket->file->f_cred->fsgid); 116 skb->sk->sk_socket->file->f_cred->fsgid);
117 read_unlock_bh(&skb->sk->sk_callback_lock); 117 read_unlock_bh(&skb->sk->sk_callback_lock);
118 break; 118 break;
119#ifdef CONFIG_NET_CLS_ROUTE 119#ifdef CONFIG_IP_ROUTE_CLASSID
120 case NFT_META_RTCLASSID: { 120 case NFT_META_RTCLASSID: {
121 const struct dst_entry *dst = skb_dst(skb); 121 const struct dst_entry *dst = skb_dst(skb);
122 122
@@ -199,7 +199,7 @@ static int nft_meta_init_validate_get(uint32_t key)
199 case NFT_META_OIFTYPE: 199 case NFT_META_OIFTYPE:
200 case NFT_META_SKUID: 200 case NFT_META_SKUID:
201 case NFT_META_SKGID: 201 case NFT_META_SKGID:
202#ifdef CONFIG_NET_CLS_ROUTE 202#ifdef CONFIG_IP_ROUTE_CLASSID
203 case NFT_META_RTCLASSID: 203 case NFT_META_RTCLASSID:
204#endif 204#endif
205#ifdef CONFIG_NETWORK_SECMARK 205#ifdef CONFIG_NETWORK_SECMARK
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index a2aeb318678f..85daa84bfdfe 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -135,7 +135,8 @@ nft_payload_select_ops(const struct nft_ctx *ctx,
135 if (len == 0 || len > FIELD_SIZEOF(struct nft_data, data)) 135 if (len == 0 || len > FIELD_SIZEOF(struct nft_data, data))
136 return ERR_PTR(-EINVAL); 136 return ERR_PTR(-EINVAL);
137 137
138 if (len <= 4 && IS_ALIGNED(offset, len) && base != NFT_PAYLOAD_LL_HEADER) 138 if (len <= 4 && is_power_of_2(len) && IS_ALIGNED(offset, len) &&
139 base != NFT_PAYLOAD_LL_HEADER)
139 return &nft_payload_fast_ops; 140 return &nft_payload_fast_ops;
140 else 141 else
141 return &nft_payload_ops; 142 return &nft_payload_ops;
diff --git a/net/netfilter/nft_queue.c b/net/netfilter/nft_queue.c
index cbea473d69e9..e8ae2f6bf232 100644
--- a/net/netfilter/nft_queue.c
+++ b/net/netfilter/nft_queue.c
@@ -25,7 +25,6 @@ struct nft_queue {
25 u16 queuenum; 25 u16 queuenum;
26 u16 queues_total; 26 u16 queues_total;
27 u16 flags; 27 u16 flags;
28 u8 family;
29}; 28};
30 29
31static void nft_queue_eval(const struct nft_expr *expr, 30static void nft_queue_eval(const struct nft_expr *expr,
@@ -43,7 +42,7 @@ static void nft_queue_eval(const struct nft_expr *expr,
43 queue = priv->queuenum + cpu % priv->queues_total; 42 queue = priv->queuenum + cpu % priv->queues_total;
44 } else { 43 } else {
45 queue = nfqueue_hash(pkt->skb, queue, 44 queue = nfqueue_hash(pkt->skb, queue,
46 priv->queues_total, priv->family, 45 priv->queues_total, pkt->ops->pf,
47 jhash_initval); 46 jhash_initval);
48 } 47 }
49 } 48 }
@@ -71,7 +70,6 @@ static int nft_queue_init(const struct nft_ctx *ctx,
71 return -EINVAL; 70 return -EINVAL;
72 71
73 init_hashrandom(&jhash_initval); 72 init_hashrandom(&jhash_initval);
74 priv->family = ctx->afi->family;
75 priv->queuenum = ntohs(nla_get_be16(tb[NFTA_QUEUE_NUM])); 73 priv->queuenum = ntohs(nla_get_be16(tb[NFTA_QUEUE_NUM]));
76 74
77 if (tb[NFTA_QUEUE_TOTAL] != NULL) 75 if (tb[NFTA_QUEUE_TOTAL] != NULL)
diff --git a/net/netfilter/nft_rbtree.c b/net/netfilter/nft_rbtree.c
index ca0c1b231bfe..e21d69d13506 100644
--- a/net/netfilter/nft_rbtree.c
+++ b/net/netfilter/nft_rbtree.c
@@ -69,8 +69,10 @@ static void nft_rbtree_elem_destroy(const struct nft_set *set,
69 struct nft_rbtree_elem *rbe) 69 struct nft_rbtree_elem *rbe)
70{ 70{
71 nft_data_uninit(&rbe->key, NFT_DATA_VALUE); 71 nft_data_uninit(&rbe->key, NFT_DATA_VALUE);
72 if (set->flags & NFT_SET_MAP) 72 if (set->flags & NFT_SET_MAP &&
73 !(rbe->flags & NFT_SET_ELEM_INTERVAL_END))
73 nft_data_uninit(rbe->data, set->dtype); 74 nft_data_uninit(rbe->data, set->dtype);
75
74 kfree(rbe); 76 kfree(rbe);
75} 77}
76 78
@@ -108,7 +110,8 @@ static int nft_rbtree_insert(const struct nft_set *set,
108 int err; 110 int err;
109 111
110 size = sizeof(*rbe); 112 size = sizeof(*rbe);
111 if (set->flags & NFT_SET_MAP) 113 if (set->flags & NFT_SET_MAP &&
114 !(elem->flags & NFT_SET_ELEM_INTERVAL_END))
112 size += sizeof(rbe->data[0]); 115 size += sizeof(rbe->data[0]);
113 116
114 rbe = kzalloc(size, GFP_KERNEL); 117 rbe = kzalloc(size, GFP_KERNEL);
@@ -117,7 +120,8 @@ static int nft_rbtree_insert(const struct nft_set *set,
117 120
118 rbe->flags = elem->flags; 121 rbe->flags = elem->flags;
119 nft_data_copy(&rbe->key, &elem->key); 122 nft_data_copy(&rbe->key, &elem->key);
120 if (set->flags & NFT_SET_MAP) 123 if (set->flags & NFT_SET_MAP &&
124 !(rbe->flags & NFT_SET_ELEM_INTERVAL_END))
121 nft_data_copy(rbe->data, &elem->data); 125 nft_data_copy(rbe->data, &elem->data);
122 126
123 err = __nft_rbtree_insert(set, rbe); 127 err = __nft_rbtree_insert(set, rbe);
@@ -153,7 +157,8 @@ static int nft_rbtree_get(const struct nft_set *set, struct nft_set_elem *elem)
153 parent = parent->rb_right; 157 parent = parent->rb_right;
154 else { 158 else {
155 elem->cookie = rbe; 159 elem->cookie = rbe;
156 if (set->flags & NFT_SET_MAP) 160 if (set->flags & NFT_SET_MAP &&
161 !(rbe->flags & NFT_SET_ELEM_INTERVAL_END))
157 nft_data_copy(&elem->data, rbe->data); 162 nft_data_copy(&elem->data, rbe->data);
158 elem->flags = rbe->flags; 163 elem->flags = rbe->flags;
159 return 0; 164 return 0;
@@ -177,7 +182,8 @@ static void nft_rbtree_walk(const struct nft_ctx *ctx,
177 182
178 rbe = rb_entry(node, struct nft_rbtree_elem, node); 183 rbe = rb_entry(node, struct nft_rbtree_elem, node);
179 nft_data_copy(&elem.key, &rbe->key); 184 nft_data_copy(&elem.key, &rbe->key);
180 if (set->flags & NFT_SET_MAP) 185 if (set->flags & NFT_SET_MAP &&
186 !(rbe->flags & NFT_SET_ELEM_INTERVAL_END))
181 nft_data_copy(&elem.data, rbe->data); 187 nft_data_copy(&elem.data, rbe->data);
182 elem.flags = rbe->flags; 188 elem.flags = rbe->flags;
183 189
diff --git a/net/netfilter/nft_reject.c b/net/netfilter/nft_reject.c
index 5e204711d704..f3448c296446 100644
--- a/net/netfilter/nft_reject.c
+++ b/net/netfilter/nft_reject.c
@@ -16,65 +16,23 @@
16#include <linux/netfilter.h> 16#include <linux/netfilter.h>
17#include <linux/netfilter/nf_tables.h> 17#include <linux/netfilter/nf_tables.h>
18#include <net/netfilter/nf_tables.h> 18#include <net/netfilter/nf_tables.h>
19#include <net/icmp.h> 19#include <net/netfilter/nft_reject.h>
20#include <net/netfilter/ipv4/nf_reject.h>
21 20
22#if IS_ENABLED(CONFIG_NF_TABLES_IPV6) 21const struct nla_policy nft_reject_policy[NFTA_REJECT_MAX + 1] = {
23#include <net/netfilter/ipv6/nf_reject.h>
24#endif
25
26struct nft_reject {
27 enum nft_reject_types type:8;
28 u8 icmp_code;
29 u8 family;
30};
31
32static void nft_reject_eval(const struct nft_expr *expr,
33 struct nft_data data[NFT_REG_MAX + 1],
34 const struct nft_pktinfo *pkt)
35{
36 struct nft_reject *priv = nft_expr_priv(expr);
37#if IS_ENABLED(CONFIG_NF_TABLES_IPV6)
38 struct net *net = dev_net((pkt->in != NULL) ? pkt->in : pkt->out);
39#endif
40 switch (priv->type) {
41 case NFT_REJECT_ICMP_UNREACH:
42 if (priv->family == NFPROTO_IPV4)
43 nf_send_unreach(pkt->skb, priv->icmp_code);
44#if IS_ENABLED(CONFIG_NF_TABLES_IPV6)
45 else if (priv->family == NFPROTO_IPV6)
46 nf_send_unreach6(net, pkt->skb, priv->icmp_code,
47 pkt->ops->hooknum);
48#endif
49 break;
50 case NFT_REJECT_TCP_RST:
51 if (priv->family == NFPROTO_IPV4)
52 nf_send_reset(pkt->skb, pkt->ops->hooknum);
53#if IS_ENABLED(CONFIG_NF_TABLES_IPV6)
54 else if (priv->family == NFPROTO_IPV6)
55 nf_send_reset6(net, pkt->skb, pkt->ops->hooknum);
56#endif
57 break;
58 }
59
60 data[NFT_REG_VERDICT].verdict = NF_DROP;
61}
62
63static const struct nla_policy nft_reject_policy[NFTA_REJECT_MAX + 1] = {
64 [NFTA_REJECT_TYPE] = { .type = NLA_U32 }, 22 [NFTA_REJECT_TYPE] = { .type = NLA_U32 },
65 [NFTA_REJECT_ICMP_CODE] = { .type = NLA_U8 }, 23 [NFTA_REJECT_ICMP_CODE] = { .type = NLA_U8 },
66}; 24};
25EXPORT_SYMBOL_GPL(nft_reject_policy);
67 26
68static int nft_reject_init(const struct nft_ctx *ctx, 27int nft_reject_init(const struct nft_ctx *ctx,
69 const struct nft_expr *expr, 28 const struct nft_expr *expr,
70 const struct nlattr * const tb[]) 29 const struct nlattr * const tb[])
71{ 30{
72 struct nft_reject *priv = nft_expr_priv(expr); 31 struct nft_reject *priv = nft_expr_priv(expr);
73 32
74 if (tb[NFTA_REJECT_TYPE] == NULL) 33 if (tb[NFTA_REJECT_TYPE] == NULL)
75 return -EINVAL; 34 return -EINVAL;
76 35
77 priv->family = ctx->afi->family;
78 priv->type = ntohl(nla_get_be32(tb[NFTA_REJECT_TYPE])); 36 priv->type = ntohl(nla_get_be32(tb[NFTA_REJECT_TYPE]));
79 switch (priv->type) { 37 switch (priv->type) {
80 case NFT_REJECT_ICMP_UNREACH: 38 case NFT_REJECT_ICMP_UNREACH:
@@ -89,8 +47,9 @@ static int nft_reject_init(const struct nft_ctx *ctx,
89 47
90 return 0; 48 return 0;
91} 49}
50EXPORT_SYMBOL_GPL(nft_reject_init);
92 51
93static int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr) 52int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
94{ 53{
95 const struct nft_reject *priv = nft_expr_priv(expr); 54 const struct nft_reject *priv = nft_expr_priv(expr);
96 55
@@ -109,37 +68,7 @@ static int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
109nla_put_failure: 68nla_put_failure:
110 return -1; 69 return -1;
111} 70}
112 71EXPORT_SYMBOL_GPL(nft_reject_dump);
113static struct nft_expr_type nft_reject_type;
114static const struct nft_expr_ops nft_reject_ops = {
115 .type = &nft_reject_type,
116 .size = NFT_EXPR_SIZE(sizeof(struct nft_reject)),
117 .eval = nft_reject_eval,
118 .init = nft_reject_init,
119 .dump = nft_reject_dump,
120};
121
122static struct nft_expr_type nft_reject_type __read_mostly = {
123 .name = "reject",
124 .ops = &nft_reject_ops,
125 .policy = nft_reject_policy,
126 .maxattr = NFTA_REJECT_MAX,
127 .owner = THIS_MODULE,
128};
129
130static int __init nft_reject_module_init(void)
131{
132 return nft_register_expr(&nft_reject_type);
133}
134
135static void __exit nft_reject_module_exit(void)
136{
137 nft_unregister_expr(&nft_reject_type);
138}
139
140module_init(nft_reject_module_init);
141module_exit(nft_reject_module_exit);
142 72
143MODULE_LICENSE("GPL"); 73MODULE_LICENSE("GPL");
144MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); 74MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
145MODULE_ALIAS_NFT_EXPR("reject");
diff --git a/net/netfilter/nft_reject_inet.c b/net/netfilter/nft_reject_inet.c
new file mode 100644
index 000000000000..b718a52a4654
--- /dev/null
+++ b/net/netfilter/nft_reject_inet.c
@@ -0,0 +1,63 @@
1/*
2 * Copyright (c) 2014 Patrick McHardy <kaber@trash.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/kernel.h>
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/netlink.h>
13#include <linux/netfilter.h>
14#include <linux/netfilter/nf_tables.h>
15#include <net/netfilter/nf_tables.h>
16#include <net/netfilter/nft_reject.h>
17
18static void nft_reject_inet_eval(const struct nft_expr *expr,
19 struct nft_data data[NFT_REG_MAX + 1],
20 const struct nft_pktinfo *pkt)
21{
22 switch (pkt->ops->pf) {
23 case NFPROTO_IPV4:
24 return nft_reject_ipv4_eval(expr, data, pkt);
25 case NFPROTO_IPV6:
26 return nft_reject_ipv6_eval(expr, data, pkt);
27 }
28}
29
30static struct nft_expr_type nft_reject_inet_type;
31static const struct nft_expr_ops nft_reject_inet_ops = {
32 .type = &nft_reject_inet_type,
33 .size = NFT_EXPR_SIZE(sizeof(struct nft_reject)),
34 .eval = nft_reject_inet_eval,
35 .init = nft_reject_init,
36 .dump = nft_reject_dump,
37};
38
39static struct nft_expr_type nft_reject_inet_type __read_mostly = {
40 .family = NFPROTO_INET,
41 .name = "reject",
42 .ops = &nft_reject_inet_ops,
43 .policy = nft_reject_policy,
44 .maxattr = NFTA_REJECT_MAX,
45 .owner = THIS_MODULE,
46};
47
48static int __init nft_reject_inet_module_init(void)
49{
50 return nft_register_expr(&nft_reject_inet_type);
51}
52
53static void __exit nft_reject_inet_module_exit(void)
54{
55 nft_unregister_expr(&nft_reject_inet_type);
56}
57
58module_init(nft_reject_inet_module_init);
59module_exit(nft_reject_inet_module_exit);
60
61MODULE_LICENSE("GPL");
62MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
63MODULE_ALIAS_NFT_AF_EXPR(1, "reject");
diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c
index 5929be622c5c..75747aecdebe 100644
--- a/net/netfilter/xt_CT.c
+++ b/net/netfilter/xt_CT.c
@@ -228,12 +228,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par,
228 goto err3; 228 goto err3;
229 } 229 }
230 230
231 __set_bit(IPS_TEMPLATE_BIT, &ct->status); 231 nf_conntrack_tmpl_insert(par->net, ct);
232 __set_bit(IPS_CONFIRMED_BIT, &ct->status);
233
234 /* Overload tuple linked list to put us in template list. */
235 hlist_nulls_add_head_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode,
236 &par->net->ct.tmpl);
237out: 232out:
238 info->ct = ct; 233 info->ct = ct;
239 return 0; 234 return 0;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index fdf51353cf78..04748ab649c2 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1489,8 +1489,8 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
1489 if (addr->sa_family != AF_NETLINK) 1489 if (addr->sa_family != AF_NETLINK)
1490 return -EINVAL; 1490 return -EINVAL;
1491 1491
1492 /* Only superuser is allowed to send multicasts */ 1492 if ((nladdr->nl_groups || nladdr->nl_pid) &&
1493 if (nladdr->nl_groups && !netlink_capable(sock, NL_CFG_F_NONROOT_SEND)) 1493 !netlink_capable(sock, NL_CFG_F_NONROOT_SEND))
1494 return -EPERM; 1494 return -EPERM;
1495 1495
1496 if (!nlk->portid) 1496 if (!nlk->portid)
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 46bda010bf11..56db888b1cd5 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -301,7 +301,7 @@ static int nci_open_device(struct nci_dev *ndev)
301 rc = __nci_request(ndev, nci_reset_req, 0, 301 rc = __nci_request(ndev, nci_reset_req, 0,
302 msecs_to_jiffies(NCI_RESET_TIMEOUT)); 302 msecs_to_jiffies(NCI_RESET_TIMEOUT));
303 303
304 if (ndev->ops->setup(ndev)) 304 if (ndev->ops->setup)
305 ndev->ops->setup(ndev); 305 ndev->ops->setup(ndev);
306 306
307 if (!rc) { 307 if (!rc) {
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index df4692826ead..270b77dfac30 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -55,6 +55,7 @@
55 55
56#include "datapath.h" 56#include "datapath.h"
57#include "flow.h" 57#include "flow.h"
58#include "flow_table.h"
58#include "flow_netlink.h" 59#include "flow_netlink.h"
59#include "vport-internal_dev.h" 60#include "vport-internal_dev.h"
60#include "vport-netdev.h" 61#include "vport-netdev.h"
@@ -160,7 +161,6 @@ static void destroy_dp_rcu(struct rcu_head *rcu)
160{ 161{
161 struct datapath *dp = container_of(rcu, struct datapath, rcu); 162 struct datapath *dp = container_of(rcu, struct datapath, rcu);
162 163
163 ovs_flow_tbl_destroy(&dp->table);
164 free_percpu(dp->stats_percpu); 164 free_percpu(dp->stats_percpu);
165 release_net(ovs_dp_get_net(dp)); 165 release_net(ovs_dp_get_net(dp));
166 kfree(dp->ports); 166 kfree(dp->ports);
@@ -464,12 +464,24 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
464 } 464 }
465 nla->nla_len = nla_attr_size(skb->len); 465 nla->nla_len = nla_attr_size(skb->len);
466 466
467 skb_zerocopy(user_skb, skb, skb->len, hlen); 467 err = skb_zerocopy(user_skb, skb, skb->len, hlen);
468 if (err)
469 goto out;
470
471 /* Pad OVS_PACKET_ATTR_PACKET if linear copy was performed */
472 if (!(dp->user_features & OVS_DP_F_UNALIGNED)) {
473 size_t plen = NLA_ALIGN(user_skb->len) - user_skb->len;
474
475 if (plen > 0)
476 memset(skb_put(user_skb, plen), 0, plen);
477 }
468 478
469 ((struct nlmsghdr *) user_skb->data)->nlmsg_len = user_skb->len; 479 ((struct nlmsghdr *) user_skb->data)->nlmsg_len = user_skb->len;
470 480
471 err = genlmsg_unicast(ovs_dp_get_net(dp), user_skb, upcall_info->portid); 481 err = genlmsg_unicast(ovs_dp_get_net(dp), user_skb, upcall_info->portid);
472out: 482out:
483 if (err)
484 skb_tx_error(skb);
473 kfree_skb(nskb); 485 kfree_skb(nskb);
474 return err; 486 return err;
475} 487}
@@ -852,11 +864,8 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info)
852 goto err_unlock_ovs; 864 goto err_unlock_ovs;
853 865
854 /* The unmasked key has to be the same for flow updates. */ 866 /* The unmasked key has to be the same for flow updates. */
855 error = -EINVAL; 867 if (!ovs_flow_cmp_unmasked_key(flow, &match))
856 if (!ovs_flow_cmp_unmasked_key(flow, &match)) {
857 OVS_NLERR("Flow modification message rejected, unmasked key does not match.\n");
858 goto err_unlock_ovs; 868 goto err_unlock_ovs;
859 }
860 869
861 /* Update actions. */ 870 /* Update actions. */
862 old_acts = ovsl_dereference(flow->sf_acts); 871 old_acts = ovsl_dereference(flow->sf_acts);
@@ -1079,6 +1088,7 @@ static size_t ovs_dp_cmd_msg_size(void)
1079 msgsize += nla_total_size(IFNAMSIZ); 1088 msgsize += nla_total_size(IFNAMSIZ);
1080 msgsize += nla_total_size(sizeof(struct ovs_dp_stats)); 1089 msgsize += nla_total_size(sizeof(struct ovs_dp_stats));
1081 msgsize += nla_total_size(sizeof(struct ovs_dp_megaflow_stats)); 1090 msgsize += nla_total_size(sizeof(struct ovs_dp_megaflow_stats));
1091 msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_USER_FEATURES */
1082 1092
1083 return msgsize; 1093 return msgsize;
1084} 1094}
@@ -1168,7 +1178,7 @@ static void ovs_dp_reset_user_features(struct sk_buff *skb, struct genl_info *in
1168 struct datapath *dp; 1178 struct datapath *dp;
1169 1179
1170 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs); 1180 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1171 if (!dp) 1181 if (IS_ERR(dp))
1172 return; 1182 return;
1173 1183
1174 WARN(dp->user_features, "Dropping previously announced user features\n"); 1184 WARN(dp->user_features, "Dropping previously announced user features\n");
@@ -1279,7 +1289,7 @@ err_destroy_ports_array:
1279err_destroy_percpu: 1289err_destroy_percpu:
1280 free_percpu(dp->stats_percpu); 1290 free_percpu(dp->stats_percpu);
1281err_destroy_table: 1291err_destroy_table:
1282 ovs_flow_tbl_destroy(&dp->table); 1292 ovs_flow_tbl_destroy(&dp->table, false);
1283err_free_dp: 1293err_free_dp:
1284 release_net(ovs_dp_get_net(dp)); 1294 release_net(ovs_dp_get_net(dp));
1285 kfree(dp); 1295 kfree(dp);
@@ -1306,10 +1316,13 @@ static void __dp_destroy(struct datapath *dp)
1306 list_del_rcu(&dp->list_node); 1316 list_del_rcu(&dp->list_node);
1307 1317
1308 /* OVSP_LOCAL is datapath internal port. We need to make sure that 1318 /* OVSP_LOCAL is datapath internal port. We need to make sure that
1309 * all port in datapath are destroyed first before freeing datapath. 1319 * all ports in datapath are destroyed first before freeing datapath.
1310 */ 1320 */
1311 ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL)); 1321 ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL));
1312 1322
1323 /* RCU destroy the flow table */
1324 ovs_flow_tbl_destroy(&dp->table, true);
1325
1313 call_rcu(&dp->rcu, destroy_dp_rcu); 1326 call_rcu(&dp->rcu, destroy_dp_rcu);
1314} 1327}
1315 1328
@@ -1753,11 +1766,12 @@ static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1753 int bucket = cb->args[0], skip = cb->args[1]; 1766 int bucket = cb->args[0], skip = cb->args[1];
1754 int i, j = 0; 1767 int i, j = 0;
1755 1768
1769 rcu_read_lock();
1756 dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex); 1770 dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
1757 if (!dp) 1771 if (!dp) {
1772 rcu_read_unlock();
1758 return -ENODEV; 1773 return -ENODEV;
1759 1774 }
1760 rcu_read_lock();
1761 for (i = bucket; i < DP_VPORT_HASH_BUCKETS; i++) { 1775 for (i = bucket; i < DP_VPORT_HASH_BUCKETS; i++) {
1762 struct vport *vport; 1776 struct vport *vport;
1763 1777
diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index 16f4b46161d4..2998989e76db 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -73,6 +73,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, struct sk_buff *skb)
73 73
74 if ((flow->key.eth.type == htons(ETH_P_IP) || 74 if ((flow->key.eth.type == htons(ETH_P_IP) ||
75 flow->key.eth.type == htons(ETH_P_IPV6)) && 75 flow->key.eth.type == htons(ETH_P_IPV6)) &&
76 flow->key.ip.frag != OVS_FRAG_TYPE_LATER &&
76 flow->key.ip.proto == IPPROTO_TCP && 77 flow->key.ip.proto == IPPROTO_TCP &&
77 likely(skb->len >= skb_transport_offset(skb) + sizeof(struct tcphdr))) { 78 likely(skb->len >= skb_transport_offset(skb) + sizeof(struct tcphdr))) {
78 tcp_flags = TCP_FLAGS_BE16(tcp_hdr(skb)); 79 tcp_flags = TCP_FLAGS_BE16(tcp_hdr(skb));
@@ -91,7 +92,7 @@ static void stats_read(struct flow_stats *stats,
91 unsigned long *used, __be16 *tcp_flags) 92 unsigned long *used, __be16 *tcp_flags)
92{ 93{
93 spin_lock(&stats->lock); 94 spin_lock(&stats->lock);
94 if (time_after(stats->used, *used)) 95 if (!*used || time_after(stats->used, *used))
95 *used = stats->used; 96 *used = stats->used;
96 *tcp_flags |= stats->tcp_flags; 97 *tcp_flags |= stats->tcp_flags;
97 ovs_stats->n_packets += stats->packet_count; 98 ovs_stats->n_packets += stats->packet_count;
@@ -102,30 +103,24 @@ static void stats_read(struct flow_stats *stats,
102void ovs_flow_stats_get(struct sw_flow *flow, struct ovs_flow_stats *ovs_stats, 103void ovs_flow_stats_get(struct sw_flow *flow, struct ovs_flow_stats *ovs_stats,
103 unsigned long *used, __be16 *tcp_flags) 104 unsigned long *used, __be16 *tcp_flags)
104{ 105{
105 int cpu, cur_cpu; 106 int cpu;
106 107
107 *used = 0; 108 *used = 0;
108 *tcp_flags = 0; 109 *tcp_flags = 0;
109 memset(ovs_stats, 0, sizeof(*ovs_stats)); 110 memset(ovs_stats, 0, sizeof(*ovs_stats));
110 111
112 local_bh_disable();
111 if (!flow->stats.is_percpu) { 113 if (!flow->stats.is_percpu) {
112 stats_read(flow->stats.stat, ovs_stats, used, tcp_flags); 114 stats_read(flow->stats.stat, ovs_stats, used, tcp_flags);
113 } else { 115 } else {
114 cur_cpu = get_cpu();
115 for_each_possible_cpu(cpu) { 116 for_each_possible_cpu(cpu) {
116 struct flow_stats *stats; 117 struct flow_stats *stats;
117 118
118 if (cpu == cur_cpu)
119 local_bh_disable();
120
121 stats = per_cpu_ptr(flow->stats.cpu_stats, cpu); 119 stats = per_cpu_ptr(flow->stats.cpu_stats, cpu);
122 stats_read(stats, ovs_stats, used, tcp_flags); 120 stats_read(stats, ovs_stats, used, tcp_flags);
123
124 if (cpu == cur_cpu)
125 local_bh_enable();
126 } 121 }
127 put_cpu();
128 } 122 }
123 local_bh_enable();
129} 124}
130 125
131static void stats_reset(struct flow_stats *stats) 126static void stats_reset(struct flow_stats *stats)
@@ -140,25 +135,17 @@ static void stats_reset(struct flow_stats *stats)
140 135
141void ovs_flow_stats_clear(struct sw_flow *flow) 136void ovs_flow_stats_clear(struct sw_flow *flow)
142{ 137{
143 int cpu, cur_cpu; 138 int cpu;
144 139
140 local_bh_disable();
145 if (!flow->stats.is_percpu) { 141 if (!flow->stats.is_percpu) {
146 stats_reset(flow->stats.stat); 142 stats_reset(flow->stats.stat);
147 } else { 143 } else {
148 cur_cpu = get_cpu();
149
150 for_each_possible_cpu(cpu) { 144 for_each_possible_cpu(cpu) {
151
152 if (cpu == cur_cpu)
153 local_bh_disable();
154
155 stats_reset(per_cpu_ptr(flow->stats.cpu_stats, cpu)); 145 stats_reset(per_cpu_ptr(flow->stats.cpu_stats, cpu));
156
157 if (cpu == cur_cpu)
158 local_bh_enable();
159 } 146 }
160 put_cpu();
161 } 147 }
148 local_bh_enable();
162} 149}
163 150
164static int check_header(struct sk_buff *skb, int len) 151static int check_header(struct sk_buff *skb, int len)
diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
index c58a0fe3c889..3c268b3d71c3 100644
--- a/net/openvswitch/flow_table.c
+++ b/net/openvswitch/flow_table.c
@@ -153,29 +153,29 @@ static void rcu_free_flow_callback(struct rcu_head *rcu)
153 flow_free(flow); 153 flow_free(flow);
154} 154}
155 155
156static void flow_mask_del_ref(struct sw_flow_mask *mask, bool deferred)
157{
158 if (!mask)
159 return;
160
161 BUG_ON(!mask->ref_count);
162 mask->ref_count--;
163
164 if (!mask->ref_count) {
165 list_del_rcu(&mask->list);
166 if (deferred)
167 kfree_rcu(mask, rcu);
168 else
169 kfree(mask);
170 }
171}
172
173void ovs_flow_free(struct sw_flow *flow, bool deferred) 156void ovs_flow_free(struct sw_flow *flow, bool deferred)
174{ 157{
175 if (!flow) 158 if (!flow)
176 return; 159 return;
177 160
178 flow_mask_del_ref(flow->mask, deferred); 161 if (flow->mask) {
162 struct sw_flow_mask *mask = flow->mask;
163
164 /* ovs-lock is required to protect mask-refcount and
165 * mask list.
166 */
167 ASSERT_OVSL();
168 BUG_ON(!mask->ref_count);
169 mask->ref_count--;
170
171 if (!mask->ref_count) {
172 list_del_rcu(&mask->list);
173 if (deferred)
174 kfree_rcu(mask, rcu);
175 else
176 kfree(mask);
177 }
178 }
179 179
180 if (deferred) 180 if (deferred)
181 call_rcu(&flow->rcu, rcu_free_flow_callback); 181 call_rcu(&flow->rcu, rcu_free_flow_callback);
@@ -188,26 +188,9 @@ static void free_buckets(struct flex_array *buckets)
188 flex_array_free(buckets); 188 flex_array_free(buckets);
189} 189}
190 190
191
191static void __table_instance_destroy(struct table_instance *ti) 192static void __table_instance_destroy(struct table_instance *ti)
192{ 193{
193 int i;
194
195 if (ti->keep_flows)
196 goto skip_flows;
197
198 for (i = 0; i < ti->n_buckets; i++) {
199 struct sw_flow *flow;
200 struct hlist_head *head = flex_array_get(ti->buckets, i);
201 struct hlist_node *n;
202 int ver = ti->node_ver;
203
204 hlist_for_each_entry_safe(flow, n, head, hash_node[ver]) {
205 hlist_del(&flow->hash_node[ver]);
206 ovs_flow_free(flow, false);
207 }
208 }
209
210skip_flows:
211 free_buckets(ti->buckets); 194 free_buckets(ti->buckets);
212 kfree(ti); 195 kfree(ti);
213} 196}
@@ -258,20 +241,38 @@ static void flow_tbl_destroy_rcu_cb(struct rcu_head *rcu)
258 241
259static void table_instance_destroy(struct table_instance *ti, bool deferred) 242static void table_instance_destroy(struct table_instance *ti, bool deferred)
260{ 243{
244 int i;
245
261 if (!ti) 246 if (!ti)
262 return; 247 return;
263 248
249 if (ti->keep_flows)
250 goto skip_flows;
251
252 for (i = 0; i < ti->n_buckets; i++) {
253 struct sw_flow *flow;
254 struct hlist_head *head = flex_array_get(ti->buckets, i);
255 struct hlist_node *n;
256 int ver = ti->node_ver;
257
258 hlist_for_each_entry_safe(flow, n, head, hash_node[ver]) {
259 hlist_del_rcu(&flow->hash_node[ver]);
260 ovs_flow_free(flow, deferred);
261 }
262 }
263
264skip_flows:
264 if (deferred) 265 if (deferred)
265 call_rcu(&ti->rcu, flow_tbl_destroy_rcu_cb); 266 call_rcu(&ti->rcu, flow_tbl_destroy_rcu_cb);
266 else 267 else
267 __table_instance_destroy(ti); 268 __table_instance_destroy(ti);
268} 269}
269 270
270void ovs_flow_tbl_destroy(struct flow_table *table) 271void ovs_flow_tbl_destroy(struct flow_table *table, bool deferred)
271{ 272{
272 struct table_instance *ti = ovsl_dereference(table->ti); 273 struct table_instance *ti = ovsl_dereference(table->ti);
273 274
274 table_instance_destroy(ti, false); 275 table_instance_destroy(ti, deferred);
275} 276}
276 277
277struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *ti, 278struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *ti,
@@ -504,16 +505,11 @@ static struct sw_flow_mask *mask_alloc(void)
504 505
505 mask = kmalloc(sizeof(*mask), GFP_KERNEL); 506 mask = kmalloc(sizeof(*mask), GFP_KERNEL);
506 if (mask) 507 if (mask)
507 mask->ref_count = 0; 508 mask->ref_count = 1;
508 509
509 return mask; 510 return mask;
510} 511}
511 512
512static void mask_add_ref(struct sw_flow_mask *mask)
513{
514 mask->ref_count++;
515}
516
517static bool mask_equal(const struct sw_flow_mask *a, 513static bool mask_equal(const struct sw_flow_mask *a,
518 const struct sw_flow_mask *b) 514 const struct sw_flow_mask *b)
519{ 515{
@@ -554,9 +550,11 @@ static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow,
554 mask->key = new->key; 550 mask->key = new->key;
555 mask->range = new->range; 551 mask->range = new->range;
556 list_add_rcu(&mask->list, &tbl->mask_list); 552 list_add_rcu(&mask->list, &tbl->mask_list);
553 } else {
554 BUG_ON(!mask->ref_count);
555 mask->ref_count++;
557 } 556 }
558 557
559 mask_add_ref(mask);
560 flow->mask = mask; 558 flow->mask = mask;
561 return 0; 559 return 0;
562} 560}
diff --git a/net/openvswitch/flow_table.h b/net/openvswitch/flow_table.h
index 1996e34c0fd8..baaeb101924d 100644
--- a/net/openvswitch/flow_table.h
+++ b/net/openvswitch/flow_table.h
@@ -60,7 +60,7 @@ void ovs_flow_free(struct sw_flow *, bool deferred);
60 60
61int ovs_flow_tbl_init(struct flow_table *); 61int ovs_flow_tbl_init(struct flow_table *);
62int ovs_flow_tbl_count(struct flow_table *table); 62int ovs_flow_tbl_count(struct flow_table *table);
63void ovs_flow_tbl_destroy(struct flow_table *table); 63void ovs_flow_tbl_destroy(struct flow_table *table, bool deferred);
64int ovs_flow_tbl_flush(struct flow_table *flow_table); 64int ovs_flow_tbl_flush(struct flow_table *flow_table);
65 65
66int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow, 66int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 6a2bb37506c5..48a6a93db296 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -308,11 +308,27 @@ static bool packet_use_direct_xmit(const struct packet_sock *po)
308 return po->xmit == packet_direct_xmit; 308 return po->xmit == packet_direct_xmit;
309} 309}
310 310
311static u16 packet_pick_tx_queue(struct net_device *dev) 311static u16 __packet_pick_tx_queue(struct net_device *dev, struct sk_buff *skb)
312{ 312{
313 return (u16) raw_smp_processor_id() % dev->real_num_tx_queues; 313 return (u16) raw_smp_processor_id() % dev->real_num_tx_queues;
314} 314}
315 315
316static void packet_pick_tx_queue(struct net_device *dev, struct sk_buff *skb)
317{
318 const struct net_device_ops *ops = dev->netdev_ops;
319 u16 queue_index;
320
321 if (ops->ndo_select_queue) {
322 queue_index = ops->ndo_select_queue(dev, skb, NULL,
323 __packet_pick_tx_queue);
324 queue_index = netdev_cap_txqueue(dev, queue_index);
325 } else {
326 queue_index = __packet_pick_tx_queue(dev, skb);
327 }
328
329 skb_set_queue_mapping(skb, queue_index);
330}
331
316/* register_prot_hook must be invoked with the po->bind_lock held, 332/* register_prot_hook must be invoked with the po->bind_lock held,
317 * or from a context in which asynchronous accesses to the packet 333 * or from a context in which asynchronous accesses to the packet
318 * socket is not possible (packet_create()). 334 * socket is not possible (packet_create()).
@@ -2285,7 +2301,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2285 } 2301 }
2286 } 2302 }
2287 2303
2288 skb_set_queue_mapping(skb, packet_pick_tx_queue(dev)); 2304 packet_pick_tx_queue(dev, skb);
2305
2289 skb->destructor = tpacket_destruct_skb; 2306 skb->destructor = tpacket_destruct_skb;
2290 __packet_set_status(po, ph, TP_STATUS_SENDING); 2307 __packet_set_status(po, ph, TP_STATUS_SENDING);
2291 packet_inc_pending(&po->tx_ring); 2308 packet_inc_pending(&po->tx_ring);
@@ -2499,7 +2516,8 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
2499 skb->dev = dev; 2516 skb->dev = dev;
2500 skb->priority = sk->sk_priority; 2517 skb->priority = sk->sk_priority;
2501 skb->mark = sk->sk_mark; 2518 skb->mark = sk->sk_mark;
2502 skb_set_queue_mapping(skb, packet_pick_tx_queue(dev)); 2519
2520 packet_pick_tx_queue(dev, skb);
2503 2521
2504 if (po->has_vnet_hdr) { 2522 if (po->has_vnet_hdr) {
2505 if (vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { 2523 if (vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
@@ -3786,7 +3804,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
3786 */ 3804 */
3787 if (!tx_ring) 3805 if (!tx_ring)
3788 init_prb_bdqc(po, rb, pg_vec, req_u, tx_ring); 3806 init_prb_bdqc(po, rb, pg_vec, req_u, tx_ring);
3789 break; 3807 break;
3790 default: 3808 default:
3791 break; 3809 break;
3792 } 3810 }
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 1313145e3b86..a07d55e75698 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -273,11 +273,12 @@ static struct Qdisc *qdisc_match_from_root(struct Qdisc *root, u32 handle)
273 273
274void qdisc_list_add(struct Qdisc *q) 274void qdisc_list_add(struct Qdisc *q)
275{ 275{
276 struct Qdisc *root = qdisc_dev(q)->qdisc; 276 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS)) {
277 struct Qdisc *root = qdisc_dev(q)->qdisc;
277 278
278 WARN_ON_ONCE(root == &noop_qdisc); 279 WARN_ON_ONCE(root == &noop_qdisc);
279 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS))
280 list_add_tail(&q->list, &root->list); 280 list_add_tail(&q->list, &root->list);
281 }
281} 282}
282EXPORT_SYMBOL(qdisc_list_add); 283EXPORT_SYMBOL(qdisc_list_add);
283 284
diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c
index 08ef7a42c0e4..21e251766eb1 100644
--- a/net/sched/sch_fq.c
+++ b/net/sched/sch_fq.c
@@ -601,6 +601,7 @@ static int fq_resize(struct Qdisc *sch, u32 log)
601{ 601{
602 struct fq_sched_data *q = qdisc_priv(sch); 602 struct fq_sched_data *q = qdisc_priv(sch);
603 struct rb_root *array; 603 struct rb_root *array;
604 void *old_fq_root;
604 u32 idx; 605 u32 idx;
605 606
606 if (q->fq_root && log == q->fq_trees_log) 607 if (q->fq_root && log == q->fq_trees_log)
@@ -615,13 +616,19 @@ static int fq_resize(struct Qdisc *sch, u32 log)
615 for (idx = 0; idx < (1U << log); idx++) 616 for (idx = 0; idx < (1U << log); idx++)
616 array[idx] = RB_ROOT; 617 array[idx] = RB_ROOT;
617 618
618 if (q->fq_root) { 619 sch_tree_lock(sch);
619 fq_rehash(q, q->fq_root, q->fq_trees_log, array, log); 620
620 fq_free(q->fq_root); 621 old_fq_root = q->fq_root;
621 } 622 if (old_fq_root)
623 fq_rehash(q, old_fq_root, q->fq_trees_log, array, log);
624
622 q->fq_root = array; 625 q->fq_root = array;
623 q->fq_trees_log = log; 626 q->fq_trees_log = log;
624 627
628 sch_tree_unlock(sch);
629
630 fq_free(old_fq_root);
631
625 return 0; 632 return 0;
626} 633}
627 634
@@ -697,9 +704,11 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt)
697 q->flow_refill_delay = usecs_to_jiffies(usecs_delay); 704 q->flow_refill_delay = usecs_to_jiffies(usecs_delay);
698 } 705 }
699 706
700 if (!err) 707 if (!err) {
708 sch_tree_unlock(sch);
701 err = fq_resize(sch, fq_log); 709 err = fq_resize(sch, fq_log);
702 710 sch_tree_lock(sch);
711 }
703 while (sch->q.qlen > sch->limit) { 712 while (sch->q.qlen > sch->limit) {
704 struct sk_buff *skb = fq_dequeue(sch); 713 struct sk_buff *skb = fq_dequeue(sch);
705 714
diff --git a/net/sched/sch_pie.c b/net/sched/sch_pie.c
index a255d0200a59..fefeeb73f15f 100644
--- a/net/sched/sch_pie.c
+++ b/net/sched/sch_pie.c
@@ -15,6 +15,11 @@
15 * 15 *
16 * ECN support is added by Naeem Khademi <naeemk@ifi.uio.no> 16 * ECN support is added by Naeem Khademi <naeemk@ifi.uio.no>
17 * University of Oslo, Norway. 17 * University of Oslo, Norway.
18 *
19 * References:
20 * IETF draft submission: http://tools.ietf.org/html/draft-pan-aqm-pie-00
21 * IEEE Conference on High Performance Switching and Routing 2013 :
22 * "PIE: A * Lightweight Control Scheme to Address the Bufferbloat Problem"
18 */ 23 */
19 24
20#include <linux/module.h> 25#include <linux/module.h>
@@ -36,7 +41,7 @@ struct pie_params {
36 psched_time_t target; /* user specified target delay in pschedtime */ 41 psched_time_t target; /* user specified target delay in pschedtime */
37 u32 tupdate; /* timer frequency (in jiffies) */ 42 u32 tupdate; /* timer frequency (in jiffies) */
38 u32 limit; /* number of packets that can be enqueued */ 43 u32 limit; /* number of packets that can be enqueued */
39 u32 alpha; /* alpha and beta are between -4 and 4 */ 44 u32 alpha; /* alpha and beta are between 0 and 32 */
40 u32 beta; /* and are used for shift relative to 1 */ 45 u32 beta; /* and are used for shift relative to 1 */
41 bool ecn; /* true if ecn is enabled */ 46 bool ecn; /* true if ecn is enabled */
42 bool bytemode; /* to scale drop early prob based on pkt size */ 47 bool bytemode; /* to scale drop early prob based on pkt size */
@@ -326,10 +331,16 @@ static void calculate_probability(struct Qdisc *sch)
326 if (qdelay == 0 && qlen != 0) 331 if (qdelay == 0 && qlen != 0)
327 update_prob = false; 332 update_prob = false;
328 333
329 /* Add ranges for alpha and beta, more aggressive for high dropping 334 /* In the algorithm, alpha and beta are between 0 and 2 with typical
330 * mode and gentle steps for light dropping mode 335 * value for alpha as 0.125. In this implementation, we use values 0-32
331 * In light dropping mode, take gentle steps; in medium dropping mode, 336 * passed from user space to represent this. Also, alpha and beta have
332 * take medium steps; in high dropping mode, take big steps. 337 * unit of HZ and need to be scaled before they can used to update
338 * probability. alpha/beta are updated locally below by 1) scaling them
339 * appropriately 2) scaling down by 16 to come to 0-2 range.
340 * Please see paper for details.
341 *
342 * We scale alpha and beta differently depending on whether we are in
343 * light, medium or high dropping mode.
333 */ 344 */
334 if (q->vars.prob < MAX_PROB / 100) { 345 if (q->vars.prob < MAX_PROB / 100) {
335 alpha = 346 alpha =
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index 1cb413fead89..4f505a006896 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -334,18 +334,6 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
334 qdisc_put_rtab(qdisc_get_rtab(&qopt->peakrate, 334 qdisc_put_rtab(qdisc_get_rtab(&qopt->peakrate,
335 tb[TCA_TBF_PTAB])); 335 tb[TCA_TBF_PTAB]));
336 336
337 if (q->qdisc != &noop_qdisc) {
338 err = fifo_set_limit(q->qdisc, qopt->limit);
339 if (err)
340 goto done;
341 } else if (qopt->limit > 0) {
342 child = fifo_create_dflt(sch, &bfifo_qdisc_ops, qopt->limit);
343 if (IS_ERR(child)) {
344 err = PTR_ERR(child);
345 goto done;
346 }
347 }
348
349 buffer = min_t(u64, PSCHED_TICKS2NS(qopt->buffer), ~0U); 337 buffer = min_t(u64, PSCHED_TICKS2NS(qopt->buffer), ~0U);
350 mtu = min_t(u64, PSCHED_TICKS2NS(qopt->mtu), ~0U); 338 mtu = min_t(u64, PSCHED_TICKS2NS(qopt->mtu), ~0U);
351 339
@@ -390,6 +378,18 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
390 goto done; 378 goto done;
391 } 379 }
392 380
381 if (q->qdisc != &noop_qdisc) {
382 err = fifo_set_limit(q->qdisc, qopt->limit);
383 if (err)
384 goto done;
385 } else if (qopt->limit > 0) {
386 child = fifo_create_dflt(sch, &bfifo_qdisc_ops, qopt->limit);
387 if (IS_ERR(child)) {
388 err = PTR_ERR(child);
389 goto done;
390 }
391 }
392
393 sch_tree_lock(sch); 393 sch_tree_lock(sch);
394 if (child) { 394 if (child) {
395 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen); 395 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen);
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 5ae609200674..ee13d28d39d1 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -1239,78 +1239,107 @@ void sctp_assoc_update(struct sctp_association *asoc,
1239} 1239}
1240 1240
1241/* Update the retran path for sending a retransmitted packet. 1241/* Update the retran path for sending a retransmitted packet.
1242 * Round-robin through the active transports, else round-robin 1242 * See also RFC4960, 6.4. Multi-Homed SCTP Endpoints:
1243 * through the inactive transports as this is the next best thing 1243 *
1244 * we can try. 1244 * When there is outbound data to send and the primary path
1245 * becomes inactive (e.g., due to failures), or where the
1246 * SCTP user explicitly requests to send data to an
1247 * inactive destination transport address, before reporting
1248 * an error to its ULP, the SCTP endpoint should try to send
1249 * the data to an alternate active destination transport
1250 * address if one exists.
1251 *
1252 * When retransmitting data that timed out, if the endpoint
1253 * is multihomed, it should consider each source-destination
1254 * address pair in its retransmission selection policy.
1255 * When retransmitting timed-out data, the endpoint should
1256 * attempt to pick the most divergent source-destination
1257 * pair from the original source-destination pair to which
1258 * the packet was transmitted.
1259 *
1260 * Note: Rules for picking the most divergent source-destination
1261 * pair are an implementation decision and are not specified
1262 * within this document.
1263 *
1264 * Our basic strategy is to round-robin transports in priorities
1265 * according to sctp_state_prio_map[] e.g., if no such
1266 * transport with state SCTP_ACTIVE exists, round-robin through
1267 * SCTP_UNKNOWN, etc. You get the picture.
1245 */ 1268 */
1246void sctp_assoc_update_retran_path(struct sctp_association *asoc) 1269static const u8 sctp_trans_state_to_prio_map[] = {
1270 [SCTP_ACTIVE] = 3, /* best case */
1271 [SCTP_UNKNOWN] = 2,
1272 [SCTP_PF] = 1,
1273 [SCTP_INACTIVE] = 0, /* worst case */
1274};
1275
1276static u8 sctp_trans_score(const struct sctp_transport *trans)
1247{ 1277{
1248 struct sctp_transport *t, *next; 1278 return sctp_trans_state_to_prio_map[trans->state];
1249 struct list_head *head = &asoc->peer.transport_addr_list; 1279}
1250 struct list_head *pos;
1251 1280
1252 if (asoc->peer.transport_count == 1) 1281static struct sctp_transport *sctp_trans_elect_best(struct sctp_transport *curr,
1253 return; 1282 struct sctp_transport *best)
1283{
1284 if (best == NULL)
1285 return curr;
1254 1286
1255 /* Find the next transport in a round-robin fashion. */ 1287 return sctp_trans_score(curr) > sctp_trans_score(best) ? curr : best;
1256 t = asoc->peer.retran_path; 1288}
1257 pos = &t->transports;
1258 next = NULL;
1259 1289
1260 while (1) { 1290void sctp_assoc_update_retran_path(struct sctp_association *asoc)
1261 /* Skip the head. */ 1291{
1262 if (pos->next == head) 1292 struct sctp_transport *trans = asoc->peer.retran_path;
1263 pos = head->next; 1293 struct sctp_transport *trans_next = NULL;
1264 else
1265 pos = pos->next;
1266 1294
1267 t = list_entry(pos, struct sctp_transport, transports); 1295 /* We're done as we only have the one and only path. */
1296 if (asoc->peer.transport_count == 1)
1297 return;
1298 /* If active_path and retran_path are the same and active,
1299 * then this is the only active path. Use it.
1300 */
1301 if (asoc->peer.active_path == asoc->peer.retran_path &&
1302 asoc->peer.active_path->state == SCTP_ACTIVE)
1303 return;
1268 1304
1269 /* We have exhausted the list, but didn't find any 1305 /* Iterate from retran_path's successor back to retran_path. */
1270 * other active transports. If so, use the next 1306 for (trans = list_next_entry(trans, transports); 1;
1271 * transport. 1307 trans = list_next_entry(trans, transports)) {
1272 */ 1308 /* Manually skip the head element. */
1273 if (t == asoc->peer.retran_path) { 1309 if (&trans->transports == &asoc->peer.transport_addr_list)
1274 t = next; 1310 continue;
1311 if (trans->state == SCTP_UNCONFIRMED)
1312 continue;
1313 trans_next = sctp_trans_elect_best(trans, trans_next);
1314 /* Active is good enough for immediate return. */
1315 if (trans_next->state == SCTP_ACTIVE)
1275 break; 1316 break;
1276 } 1317 /* We've reached the end, time to update path. */
1277 1318 if (trans == asoc->peer.retran_path)
1278 /* Try to find an active transport. */
1279
1280 if ((t->state == SCTP_ACTIVE) ||
1281 (t->state == SCTP_UNKNOWN)) {
1282 break; 1319 break;
1283 } else {
1284 /* Keep track of the next transport in case
1285 * we don't find any active transport.
1286 */
1287 if (t->state != SCTP_UNCONFIRMED && !next)
1288 next = t;
1289 }
1290 } 1320 }
1291 1321
1292 if (t) 1322 if (trans_next != NULL)
1293 asoc->peer.retran_path = t; 1323 asoc->peer.retran_path = trans_next;
1294 else
1295 t = asoc->peer.retran_path;
1296 1324
1297 pr_debug("%s: association:%p addr:%pISpc\n", __func__, asoc, 1325 pr_debug("%s: association:%p updated new path to addr:%pISpc\n",
1298 &t->ipaddr.sa); 1326 __func__, asoc, &asoc->peer.retran_path->ipaddr.sa);
1299} 1327}
1300 1328
1301/* Choose the transport for sending retransmit packet. */ 1329struct sctp_transport *
1302struct sctp_transport *sctp_assoc_choose_alter_transport( 1330sctp_assoc_choose_alter_transport(struct sctp_association *asoc,
1303 struct sctp_association *asoc, struct sctp_transport *last_sent_to) 1331 struct sctp_transport *last_sent_to)
1304{ 1332{
1305 /* If this is the first time packet is sent, use the active path, 1333 /* If this is the first time packet is sent, use the active path,
1306 * else use the retran path. If the last packet was sent over the 1334 * else use the retran path. If the last packet was sent over the
1307 * retran path, update the retran path and use it. 1335 * retran path, update the retran path and use it.
1308 */ 1336 */
1309 if (!last_sent_to) 1337 if (last_sent_to == NULL) {
1310 return asoc->peer.active_path; 1338 return asoc->peer.active_path;
1311 else { 1339 } else {
1312 if (last_sent_to == asoc->peer.retran_path) 1340 if (last_sent_to == asoc->peer.retran_path)
1313 sctp_assoc_update_retran_path(asoc); 1341 sctp_assoc_update_retran_path(asoc);
1342
1314 return asoc->peer.retran_path; 1343 return asoc->peer.retran_path;
1315 } 1344 }
1316} 1345}
@@ -1367,44 +1396,35 @@ static inline bool sctp_peer_needs_update(struct sctp_association *asoc)
1367 return false; 1396 return false;
1368} 1397}
1369 1398
1370/* Increase asoc's rwnd by len and send any window update SACK if needed. */ 1399/* Update asoc's rwnd for the approximated state in the buffer,
1371void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsigned int len) 1400 * and check whether SACK needs to be sent.
1401 */
1402void sctp_assoc_rwnd_update(struct sctp_association *asoc, bool update_peer)
1372{ 1403{
1404 int rx_count;
1373 struct sctp_chunk *sack; 1405 struct sctp_chunk *sack;
1374 struct timer_list *timer; 1406 struct timer_list *timer;
1375 1407
1376 if (asoc->rwnd_over) { 1408 if (asoc->ep->rcvbuf_policy)
1377 if (asoc->rwnd_over >= len) { 1409 rx_count = atomic_read(&asoc->rmem_alloc);
1378 asoc->rwnd_over -= len; 1410 else
1379 } else { 1411 rx_count = atomic_read(&asoc->base.sk->sk_rmem_alloc);
1380 asoc->rwnd += (len - asoc->rwnd_over);
1381 asoc->rwnd_over = 0;
1382 }
1383 } else {
1384 asoc->rwnd += len;
1385 }
1386 1412
1387 /* If we had window pressure, start recovering it 1413 if ((asoc->base.sk->sk_rcvbuf - rx_count) > 0)
1388 * once our rwnd had reached the accumulated pressure 1414 asoc->rwnd = (asoc->base.sk->sk_rcvbuf - rx_count) >> 1;
1389 * threshold. The idea is to recover slowly, but up 1415 else
1390 * to the initial advertised window. 1416 asoc->rwnd = 0;
1391 */
1392 if (asoc->rwnd_press && asoc->rwnd >= asoc->rwnd_press) {
1393 int change = min(asoc->pathmtu, asoc->rwnd_press);
1394 asoc->rwnd += change;
1395 asoc->rwnd_press -= change;
1396 }
1397 1417
1398 pr_debug("%s: asoc:%p rwnd increased by %d to (%u, %u) - %u\n", 1418 pr_debug("%s: asoc:%p rwnd=%u, rx_count=%d, sk_rcvbuf=%d\n",
1399 __func__, asoc, len, asoc->rwnd, asoc->rwnd_over, 1419 __func__, asoc, asoc->rwnd, rx_count,
1400 asoc->a_rwnd); 1420 asoc->base.sk->sk_rcvbuf);
1401 1421
1402 /* Send a window update SACK if the rwnd has increased by at least the 1422 /* Send a window update SACK if the rwnd has increased by at least the
1403 * minimum of the association's PMTU and half of the receive buffer. 1423 * minimum of the association's PMTU and half of the receive buffer.
1404 * The algorithm used is similar to the one described in 1424 * The algorithm used is similar to the one described in
1405 * Section 4.2.3.3 of RFC 1122. 1425 * Section 4.2.3.3 of RFC 1122.
1406 */ 1426 */
1407 if (sctp_peer_needs_update(asoc)) { 1427 if (update_peer && sctp_peer_needs_update(asoc)) {
1408 asoc->a_rwnd = asoc->rwnd; 1428 asoc->a_rwnd = asoc->rwnd;
1409 1429
1410 pr_debug("%s: sending window update SACK- asoc:%p rwnd:%u " 1430 pr_debug("%s: sending window update SACK- asoc:%p rwnd:%u "
@@ -1426,45 +1446,6 @@ void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsigned int len)
1426 } 1446 }
1427} 1447}
1428 1448
1429/* Decrease asoc's rwnd by len. */
1430void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned int len)
1431{
1432 int rx_count;
1433 int over = 0;
1434
1435 if (unlikely(!asoc->rwnd || asoc->rwnd_over))
1436 pr_debug("%s: association:%p has asoc->rwnd:%u, "
1437 "asoc->rwnd_over:%u!\n", __func__, asoc,
1438 asoc->rwnd, asoc->rwnd_over);
1439
1440 if (asoc->ep->rcvbuf_policy)
1441 rx_count = atomic_read(&asoc->rmem_alloc);
1442 else
1443 rx_count = atomic_read(&asoc->base.sk->sk_rmem_alloc);
1444
1445 /* If we've reached or overflowed our receive buffer, announce
1446 * a 0 rwnd if rwnd would still be positive. Store the
1447 * the potential pressure overflow so that the window can be restored
1448 * back to original value.
1449 */
1450 if (rx_count >= asoc->base.sk->sk_rcvbuf)
1451 over = 1;
1452
1453 if (asoc->rwnd >= len) {
1454 asoc->rwnd -= len;
1455 if (over) {
1456 asoc->rwnd_press += asoc->rwnd;
1457 asoc->rwnd = 0;
1458 }
1459 } else {
1460 asoc->rwnd_over = len - asoc->rwnd;
1461 asoc->rwnd = 0;
1462 }
1463
1464 pr_debug("%s: asoc:%p rwnd decreased by %d to (%u, %u, %u)\n",
1465 __func__, asoc, len, asoc->rwnd, asoc->rwnd_over,
1466 asoc->rwnd_press);
1467}
1468 1449
1469/* Build the bind address list for the association based on info from the 1450/* Build the bind address list for the association based on info from the
1470 * local endpoint and the remote peer. 1451 * local endpoint and the remote peer.
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 0f6259a6a932..2b1738ef9394 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -662,6 +662,8 @@ static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
662 */ 662 */
663 sctp_v6_to_sk_daddr(&asoc->peer.primary_addr, newsk); 663 sctp_v6_to_sk_daddr(&asoc->peer.primary_addr, newsk);
664 664
665 newsk->sk_v6_rcv_saddr = sk->sk_v6_rcv_saddr;
666
665 sk_refcnt_debug_inc(newsk); 667 sk_refcnt_debug_inc(newsk);
666 668
667 if (newsk->sk_prot->init(newsk)) { 669 if (newsk->sk_prot->init(newsk)) {
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 632090b961c3..3a1767ef3201 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1421,8 +1421,8 @@ static void sctp_chunk_destroy(struct sctp_chunk *chunk)
1421 BUG_ON(!list_empty(&chunk->list)); 1421 BUG_ON(!list_empty(&chunk->list));
1422 list_del_init(&chunk->transmitted_list); 1422 list_del_init(&chunk->transmitted_list);
1423 1423
1424 /* Free the chunk skb data and the SCTP_chunk stub itself. */ 1424 consume_skb(chunk->skb);
1425 dev_kfree_skb(chunk->skb); 1425 consume_skb(chunk->auth_chunk);
1426 1426
1427 SCTP_DBG_OBJCNT_DEC(chunk); 1427 SCTP_DBG_OBJCNT_DEC(chunk);
1428 kmem_cache_free(sctp_chunk_cachep, chunk); 1428 kmem_cache_free(sctp_chunk_cachep, chunk);
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index bd859154000e..5d6883ff00c3 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -495,11 +495,12 @@ static void sctp_do_8_2_transport_strike(sctp_cmd_seq_t *commands,
495 } 495 }
496 496
497 /* If the transport error count is greater than the pf_retrans 497 /* If the transport error count is greater than the pf_retrans
498 * threshold, and less than pathmaxrtx, then mark this transport 498 * threshold, and less than pathmaxrtx, and if the current state
499 * as Partially Failed, ee SCTP Quick Failover Draft, secon 5.1, 499 * is not SCTP_UNCONFIRMED, then mark this transport as Partially
500 * point 1 500 * Failed, see SCTP Quick Failover Draft, section 5.1
501 */ 501 */
502 if ((transport->state != SCTP_PF) && 502 if ((transport->state != SCTP_PF) &&
503 (transport->state != SCTP_UNCONFIRMED) &&
503 (asoc->pf_retrans < transport->pathmaxrxt) && 504 (asoc->pf_retrans < transport->pathmaxrxt) &&
504 (transport->error_count > asoc->pf_retrans)) { 505 (transport->error_count > asoc->pf_retrans)) {
505 506
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 483dcd71b3c5..01e002430c85 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -758,6 +758,12 @@ sctp_disposition_t sctp_sf_do_5_1D_ce(struct net *net,
758 struct sctp_chunk auth; 758 struct sctp_chunk auth;
759 sctp_ierror_t ret; 759 sctp_ierror_t ret;
760 760
761 /* Make sure that we and the peer are AUTH capable */
762 if (!net->sctp.auth_enable || !new_asoc->peer.auth_capable) {
763 sctp_association_free(new_asoc);
764 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
765 }
766
761 /* set-up our fake chunk so that we can process it */ 767 /* set-up our fake chunk so that we can process it */
762 auth.skb = chunk->auth_chunk; 768 auth.skb = chunk->auth_chunk;
763 auth.asoc = chunk->asoc; 769 auth.asoc = chunk->asoc;
@@ -768,10 +774,6 @@ sctp_disposition_t sctp_sf_do_5_1D_ce(struct net *net,
768 auth.transport = chunk->transport; 774 auth.transport = chunk->transport;
769 775
770 ret = sctp_sf_authenticate(net, ep, new_asoc, type, &auth); 776 ret = sctp_sf_authenticate(net, ep, new_asoc, type, &auth);
771
772 /* We can now safely free the auth_chunk clone */
773 kfree_skb(chunk->auth_chunk);
774
775 if (ret != SCTP_IERROR_NO_ERROR) { 777 if (ret != SCTP_IERROR_NO_ERROR) {
776 sctp_association_free(new_asoc); 778 sctp_association_free(new_asoc);
777 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); 779 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
@@ -6176,7 +6178,7 @@ static int sctp_eat_data(const struct sctp_association *asoc,
6176 * PMTU. In cases, such as loopback, this might be a rather 6178 * PMTU. In cases, such as loopback, this might be a rather
6177 * large spill over. 6179 * large spill over.
6178 */ 6180 */
6179 if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over || 6181 if ((!chunk->data_accepted) && (!asoc->rwnd ||
6180 (datalen > asoc->rwnd + asoc->frag_point))) { 6182 (datalen > asoc->rwnd + asoc->frag_point))) {
6181 6183
6182 /* If this is the next TSN, consider reneging to make 6184 /* If this is the next TSN, consider reneging to make
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 9e91d6e5df63..981aaf8b6ace 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -64,6 +64,7 @@
64#include <linux/crypto.h> 64#include <linux/crypto.h>
65#include <linux/slab.h> 65#include <linux/slab.h>
66#include <linux/file.h> 66#include <linux/file.h>
67#include <linux/compat.h>
67 68
68#include <net/ip.h> 69#include <net/ip.h>
69#include <net/icmp.h> 70#include <net/icmp.h>
@@ -1368,11 +1369,19 @@ static int sctp_setsockopt_connectx(struct sock *sk,
1368/* 1369/*
1369 * New (hopefully final) interface for the API. 1370 * New (hopefully final) interface for the API.
1370 * We use the sctp_getaddrs_old structure so that use-space library 1371 * We use the sctp_getaddrs_old structure so that use-space library
1371 * can avoid any unnecessary allocations. The only defferent part 1372 * can avoid any unnecessary allocations. The only different part
1372 * is that we store the actual length of the address buffer into the 1373 * is that we store the actual length of the address buffer into the
1373 * addrs_num structure member. That way we can re-use the existing 1374 * addrs_num structure member. That way we can re-use the existing
1374 * code. 1375 * code.
1375 */ 1376 */
1377#ifdef CONFIG_COMPAT
1378struct compat_sctp_getaddrs_old {
1379 sctp_assoc_t assoc_id;
1380 s32 addr_num;
1381 compat_uptr_t addrs; /* struct sockaddr * */
1382};
1383#endif
1384
1376static int sctp_getsockopt_connectx3(struct sock *sk, int len, 1385static int sctp_getsockopt_connectx3(struct sock *sk, int len,
1377 char __user *optval, 1386 char __user *optval,
1378 int __user *optlen) 1387 int __user *optlen)
@@ -1381,16 +1390,30 @@ static int sctp_getsockopt_connectx3(struct sock *sk, int len,
1381 sctp_assoc_t assoc_id = 0; 1390 sctp_assoc_t assoc_id = 0;
1382 int err = 0; 1391 int err = 0;
1383 1392
1384 if (len < sizeof(param)) 1393#ifdef CONFIG_COMPAT
1385 return -EINVAL; 1394 if (is_compat_task()) {
1395 struct compat_sctp_getaddrs_old param32;
1386 1396
1387 if (copy_from_user(&param, optval, sizeof(param))) 1397 if (len < sizeof(param32))
1388 return -EFAULT; 1398 return -EINVAL;
1399 if (copy_from_user(&param32, optval, sizeof(param32)))
1400 return -EFAULT;
1389 1401
1390 err = __sctp_setsockopt_connectx(sk, 1402 param.assoc_id = param32.assoc_id;
1391 (struct sockaddr __user *)param.addrs, 1403 param.addr_num = param32.addr_num;
1392 param.addr_num, &assoc_id); 1404 param.addrs = compat_ptr(param32.addrs);
1405 } else
1406#endif
1407 {
1408 if (len < sizeof(param))
1409 return -EINVAL;
1410 if (copy_from_user(&param, optval, sizeof(param)))
1411 return -EFAULT;
1412 }
1393 1413
1414 err = __sctp_setsockopt_connectx(sk, (struct sockaddr __user *)
1415 param.addrs, param.addr_num,
1416 &assoc_id);
1394 if (err == 0 || err == -EINPROGRESS) { 1417 if (err == 0 || err == -EINPROGRESS) {
1395 if (copy_to_user(optval, &assoc_id, sizeof(assoc_id))) 1418 if (copy_to_user(optval, &assoc_id, sizeof(assoc_id)))
1396 return -EFAULT; 1419 return -EFAULT;
@@ -2092,12 +2115,6 @@ static int sctp_recvmsg(struct kiocb *iocb, struct sock *sk,
2092 sctp_skb_pull(skb, copied); 2115 sctp_skb_pull(skb, copied);
2093 skb_queue_head(&sk->sk_receive_queue, skb); 2116 skb_queue_head(&sk->sk_receive_queue, skb);
2094 2117
2095 /* When only partial message is copied to the user, increase
2096 * rwnd by that amount. If all the data in the skb is read,
2097 * rwnd is updated when the event is freed.
2098 */
2099 if (!sctp_ulpevent_is_notification(event))
2100 sctp_assoc_rwnd_increase(event->asoc, copied);
2101 goto out; 2118 goto out;
2102 } else if ((event->msg_flags & MSG_NOTIFICATION) || 2119 } else if ((event->msg_flags & MSG_NOTIFICATION) ||
2103 (event->msg_flags & MSG_EOR)) 2120 (event->msg_flags & MSG_EOR))
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 7135e617ab0f..35c8923b5554 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -151,6 +151,7 @@ static struct ctl_table sctp_net_table[] = {
151 }, 151 },
152 { 152 {
153 .procname = "cookie_hmac_alg", 153 .procname = "cookie_hmac_alg",
154 .data = &init_net.sctp.sctp_hmac_alg,
154 .maxlen = 8, 155 .maxlen = 8,
155 .mode = 0644, 156 .mode = 0644,
156 .proc_handler = proc_sctp_do_hmac_alg, 157 .proc_handler = proc_sctp_do_hmac_alg,
@@ -401,15 +402,18 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
401 402
402int sctp_sysctl_net_register(struct net *net) 403int sctp_sysctl_net_register(struct net *net)
403{ 404{
404 struct ctl_table *table; 405 struct ctl_table *table = sctp_net_table;
405 int i; 406
407 if (!net_eq(net, &init_net)) {
408 int i;
406 409
407 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL); 410 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
408 if (!table) 411 if (!table)
409 return -ENOMEM; 412 return -ENOMEM;
410 413
411 for (i = 0; table[i].data; i++) 414 for (i = 0; table[i].data; i++)
412 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp; 415 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
416 }
413 417
414 net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table); 418 net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
415 return 0; 419 return 0;
diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
index 85c64658bd0b..8d198ae03606 100644
--- a/net/sctp/ulpevent.c
+++ b/net/sctp/ulpevent.c
@@ -989,7 +989,7 @@ static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
989 skb = sctp_event2skb(event); 989 skb = sctp_event2skb(event);
990 /* Set the owner and charge rwnd for bytes received. */ 990 /* Set the owner and charge rwnd for bytes received. */
991 sctp_ulpevent_set_owner(event, asoc); 991 sctp_ulpevent_set_owner(event, asoc);
992 sctp_assoc_rwnd_decrease(asoc, skb_headlen(skb)); 992 sctp_assoc_rwnd_update(asoc, false);
993 993
994 if (!skb->data_len) 994 if (!skb->data_len)
995 return; 995 return;
@@ -1011,6 +1011,7 @@ static void sctp_ulpevent_release_data(struct sctp_ulpevent *event)
1011{ 1011{
1012 struct sk_buff *skb, *frag; 1012 struct sk_buff *skb, *frag;
1013 unsigned int len; 1013 unsigned int len;
1014 struct sctp_association *asoc;
1014 1015
1015 /* Current stack structures assume that the rcv buffer is 1016 /* Current stack structures assume that the rcv buffer is
1016 * per socket. For UDP style sockets this is not true as 1017 * per socket. For UDP style sockets this is not true as
@@ -1035,8 +1036,11 @@ static void sctp_ulpevent_release_data(struct sctp_ulpevent *event)
1035 } 1036 }
1036 1037
1037done: 1038done:
1038 sctp_assoc_rwnd_increase(event->asoc, len); 1039 asoc = event->asoc;
1040 sctp_association_hold(asoc);
1039 sctp_ulpevent_release_owner(event); 1041 sctp_ulpevent_release_owner(event);
1042 sctp_assoc_rwnd_update(asoc, true);
1043 sctp_association_put(asoc);
1040} 1044}
1041 1045
1042static void sctp_ulpevent_release_frag_data(struct sctp_ulpevent *event) 1046static void sctp_ulpevent_release_frag_data(struct sctp_ulpevent *event)
diff --git a/net/socket.c b/net/socket.c
index 879933aaed4c..a19ae1968d37 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -450,16 +450,17 @@ EXPORT_SYMBOL(sockfd_lookup);
450 450
451static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) 451static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
452{ 452{
453 struct file *file; 453 struct fd f = fdget(fd);
454 struct socket *sock; 454 struct socket *sock;
455 455
456 *err = -EBADF; 456 *err = -EBADF;
457 file = fget_light(fd, fput_needed); 457 if (f.file) {
458 if (file) { 458 sock = sock_from_file(f.file, err);
459 sock = sock_from_file(file, err); 459 if (likely(sock)) {
460 if (sock) 460 *fput_needed = f.flags;
461 return sock; 461 return sock;
462 fput_light(file, *fput_needed); 462 }
463 fdput(f);
463 } 464 }
464 return NULL; 465 return NULL;
465} 466}
@@ -1985,6 +1986,10 @@ static int copy_msghdr_from_user(struct msghdr *kmsg,
1985{ 1986{
1986 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr))) 1987 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
1987 return -EFAULT; 1988 return -EFAULT;
1989
1990 if (kmsg->msg_namelen < 0)
1991 return -EINVAL;
1992
1988 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage)) 1993 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
1989 kmsg->msg_namelen = sizeof(struct sockaddr_storage); 1994 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
1990 return 0; 1995 return 0;
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 6c0513a7f992..36e431ee1c90 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -108,6 +108,7 @@ struct gss_auth {
108static DEFINE_SPINLOCK(pipe_version_lock); 108static DEFINE_SPINLOCK(pipe_version_lock);
109static struct rpc_wait_queue pipe_version_rpc_waitqueue; 109static struct rpc_wait_queue pipe_version_rpc_waitqueue;
110static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue); 110static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue);
111static void gss_put_auth(struct gss_auth *gss_auth);
111 112
112static void gss_free_ctx(struct gss_cl_ctx *); 113static void gss_free_ctx(struct gss_cl_ctx *);
113static const struct rpc_pipe_ops gss_upcall_ops_v0; 114static const struct rpc_pipe_ops gss_upcall_ops_v0;
@@ -320,6 +321,7 @@ gss_release_msg(struct gss_upcall_msg *gss_msg)
320 if (gss_msg->ctx != NULL) 321 if (gss_msg->ctx != NULL)
321 gss_put_ctx(gss_msg->ctx); 322 gss_put_ctx(gss_msg->ctx);
322 rpc_destroy_wait_queue(&gss_msg->rpc_waitqueue); 323 rpc_destroy_wait_queue(&gss_msg->rpc_waitqueue);
324 gss_put_auth(gss_msg->auth);
323 kfree(gss_msg); 325 kfree(gss_msg);
324} 326}
325 327
@@ -498,9 +500,12 @@ gss_alloc_msg(struct gss_auth *gss_auth,
498 default: 500 default:
499 err = gss_encode_v1_msg(gss_msg, service_name, gss_auth->target_name); 501 err = gss_encode_v1_msg(gss_msg, service_name, gss_auth->target_name);
500 if (err) 502 if (err)
501 goto err_free_msg; 503 goto err_put_pipe_version;
502 }; 504 };
505 kref_get(&gss_auth->kref);
503 return gss_msg; 506 return gss_msg;
507err_put_pipe_version:
508 put_pipe_version(gss_auth->net);
504err_free_msg: 509err_free_msg:
505 kfree(gss_msg); 510 kfree(gss_msg);
506err: 511err:
@@ -991,6 +996,8 @@ gss_create_new(struct rpc_auth_create_args *args, struct rpc_clnt *clnt)
991 gss_auth->service = gss_pseudoflavor_to_service(gss_auth->mech, flavor); 996 gss_auth->service = gss_pseudoflavor_to_service(gss_auth->mech, flavor);
992 if (gss_auth->service == 0) 997 if (gss_auth->service == 0)
993 goto err_put_mech; 998 goto err_put_mech;
999 if (!gssd_running(gss_auth->net))
1000 goto err_put_mech;
994 auth = &gss_auth->rpc_auth; 1001 auth = &gss_auth->rpc_auth;
995 auth->au_cslack = GSS_CRED_SLACK >> 2; 1002 auth->au_cslack = GSS_CRED_SLACK >> 2;
996 auth->au_rslack = GSS_VERF_SLACK >> 2; 1003 auth->au_rslack = GSS_VERF_SLACK >> 2;
@@ -1062,6 +1069,12 @@ gss_free_callback(struct kref *kref)
1062} 1069}
1063 1070
1064static void 1071static void
1072gss_put_auth(struct gss_auth *gss_auth)
1073{
1074 kref_put(&gss_auth->kref, gss_free_callback);
1075}
1076
1077static void
1065gss_destroy(struct rpc_auth *auth) 1078gss_destroy(struct rpc_auth *auth)
1066{ 1079{
1067 struct gss_auth *gss_auth = container_of(auth, 1080 struct gss_auth *gss_auth = container_of(auth,
@@ -1082,7 +1095,7 @@ gss_destroy(struct rpc_auth *auth)
1082 gss_auth->gss_pipe[1] = NULL; 1095 gss_auth->gss_pipe[1] = NULL;
1083 rpcauth_destroy_credcache(auth); 1096 rpcauth_destroy_credcache(auth);
1084 1097
1085 kref_put(&gss_auth->kref, gss_free_callback); 1098 gss_put_auth(gss_auth);
1086} 1099}
1087 1100
1088/* 1101/*
@@ -1253,7 +1266,7 @@ gss_destroy_nullcred(struct rpc_cred *cred)
1253 call_rcu(&cred->cr_rcu, gss_free_cred_callback); 1266 call_rcu(&cred->cr_rcu, gss_free_cred_callback);
1254 if (ctx) 1267 if (ctx)
1255 gss_put_ctx(ctx); 1268 gss_put_ctx(ctx);
1256 kref_put(&gss_auth->kref, gss_free_callback); 1269 gss_put_auth(gss_auth);
1257} 1270}
1258 1271
1259static void 1272static void
diff --git a/net/sunrpc/backchannel_rqst.c b/net/sunrpc/backchannel_rqst.c
index 890a29912d5a..e860d4f7ed2a 100644
--- a/net/sunrpc/backchannel_rqst.c
+++ b/net/sunrpc/backchannel_rqst.c
@@ -64,7 +64,6 @@ static void xprt_free_allocation(struct rpc_rqst *req)
64 free_page((unsigned long)xbufp->head[0].iov_base); 64 free_page((unsigned long)xbufp->head[0].iov_base);
65 xbufp = &req->rq_snd_buf; 65 xbufp = &req->rq_snd_buf;
66 free_page((unsigned long)xbufp->head[0].iov_base); 66 free_page((unsigned long)xbufp->head[0].iov_base);
67 list_del(&req->rq_bc_pa_list);
68 kfree(req); 67 kfree(req);
69} 68}
70 69
@@ -168,8 +167,10 @@ out_free:
168 /* 167 /*
169 * Memory allocation failed, free the temporary list 168 * Memory allocation failed, free the temporary list
170 */ 169 */
171 list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list) 170 list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list) {
171 list_del(&req->rq_bc_pa_list);
172 xprt_free_allocation(req); 172 xprt_free_allocation(req);
173 }
173 174
174 dprintk("RPC: setup backchannel transport failed\n"); 175 dprintk("RPC: setup backchannel transport failed\n");
175 return -ENOMEM; 176 return -ENOMEM;
@@ -198,6 +199,7 @@ void xprt_destroy_backchannel(struct rpc_xprt *xprt, unsigned int max_reqs)
198 xprt_dec_alloc_count(xprt, max_reqs); 199 xprt_dec_alloc_count(xprt, max_reqs);
199 list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) { 200 list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) {
200 dprintk("RPC: req=%p\n", req); 201 dprintk("RPC: req=%p\n", req);
202 list_del(&req->rq_bc_pa_list);
201 xprt_free_allocation(req); 203 xprt_free_allocation(req);
202 if (--max_reqs == 0) 204 if (--max_reqs == 0)
203 break; 205 break;
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index 80a6640f329b..06c6ff0cb911 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -571,7 +571,7 @@ static void svc_check_conn_limits(struct svc_serv *serv)
571 } 571 }
572} 572}
573 573
574int svc_alloc_arg(struct svc_rqst *rqstp) 574static int svc_alloc_arg(struct svc_rqst *rqstp)
575{ 575{
576 struct svc_serv *serv = rqstp->rq_server; 576 struct svc_serv *serv = rqstp->rq_server;
577 struct xdr_buf *arg; 577 struct xdr_buf *arg;
@@ -612,7 +612,7 @@ int svc_alloc_arg(struct svc_rqst *rqstp)
612 return 0; 612 return 0;
613} 613}
614 614
615struct svc_xprt *svc_get_next_xprt(struct svc_rqst *rqstp, long timeout) 615static struct svc_xprt *svc_get_next_xprt(struct svc_rqst *rqstp, long timeout)
616{ 616{
617 struct svc_xprt *xprt; 617 struct svc_xprt *xprt;
618 struct svc_pool *pool = rqstp->rq_pool; 618 struct svc_pool *pool = rqstp->rq_pool;
@@ -691,7 +691,7 @@ struct svc_xprt *svc_get_next_xprt(struct svc_rqst *rqstp, long timeout)
691 return xprt; 691 return xprt;
692} 692}
693 693
694void svc_add_new_temp_xprt(struct svc_serv *serv, struct svc_xprt *newxpt) 694static void svc_add_new_temp_xprt(struct svc_serv *serv, struct svc_xprt *newxpt)
695{ 695{
696 spin_lock_bh(&serv->sv_lock); 696 spin_lock_bh(&serv->sv_lock);
697 set_bit(XPT_TEMP, &newxpt->xpt_flags); 697 set_bit(XPT_TEMP, &newxpt->xpt_flags);
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 817a1e523969..0addefca8e77 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -510,6 +510,7 @@ static int xs_nospace(struct rpc_task *task)
510 struct rpc_rqst *req = task->tk_rqstp; 510 struct rpc_rqst *req = task->tk_rqstp;
511 struct rpc_xprt *xprt = req->rq_xprt; 511 struct rpc_xprt *xprt = req->rq_xprt;
512 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); 512 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
513 struct sock *sk = transport->inet;
513 int ret = -EAGAIN; 514 int ret = -EAGAIN;
514 515
515 dprintk("RPC: %5u xmit incomplete (%u left of %u)\n", 516 dprintk("RPC: %5u xmit incomplete (%u left of %u)\n",
@@ -527,7 +528,7 @@ static int xs_nospace(struct rpc_task *task)
527 * window size 528 * window size
528 */ 529 */
529 set_bit(SOCK_NOSPACE, &transport->sock->flags); 530 set_bit(SOCK_NOSPACE, &transport->sock->flags);
530 transport->inet->sk_write_pending++; 531 sk->sk_write_pending++;
531 /* ...and wait for more buffer space */ 532 /* ...and wait for more buffer space */
532 xprt_wait_for_buffer_space(task, xs_nospace_callback); 533 xprt_wait_for_buffer_space(task, xs_nospace_callback);
533 } 534 }
@@ -537,6 +538,9 @@ static int xs_nospace(struct rpc_task *task)
537 } 538 }
538 539
539 spin_unlock_bh(&xprt->transport_lock); 540 spin_unlock_bh(&xprt->transport_lock);
541
542 /* Race breaker in case memory is freed before above code is called */
543 sk->sk_write_space(sk);
540 return ret; 544 return ret;
541} 545}
542 546
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index a38c89969c68..574b86193b15 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -610,8 +610,13 @@ static struct notifier_block notifier = {
610 610
611int tipc_bearer_setup(void) 611int tipc_bearer_setup(void)
612{ 612{
613 int err;
614
615 err = register_netdevice_notifier(&notifier);
616 if (err)
617 return err;
613 dev_add_pack(&tipc_packet_type); 618 dev_add_pack(&tipc_packet_type);
614 return register_netdevice_notifier(&notifier); 619 return 0;
615} 620}
616 621
617void tipc_bearer_cleanup(void) 622void tipc_bearer_cleanup(void)
diff --git a/net/tipc/config.c b/net/tipc/config.c
index c301a9a592d8..e6d721692ae0 100644
--- a/net/tipc/config.c
+++ b/net/tipc/config.c
@@ -181,7 +181,7 @@ static struct sk_buff *cfg_set_own_addr(void)
181 if (tipc_own_addr) 181 if (tipc_own_addr)
182 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED 182 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
183 " (cannot change node address once assigned)"); 183 " (cannot change node address once assigned)");
184 tipc_core_start_net(addr); 184 tipc_net_start(addr);
185 return tipc_cfg_reply_none(); 185 return tipc_cfg_reply_none();
186} 186}
187 187
@@ -376,7 +376,6 @@ static void cfg_conn_msg_event(int conid, struct sockaddr_tipc *addr,
376 struct tipc_cfg_msg_hdr *req_hdr; 376 struct tipc_cfg_msg_hdr *req_hdr;
377 struct tipc_cfg_msg_hdr *rep_hdr; 377 struct tipc_cfg_msg_hdr *rep_hdr;
378 struct sk_buff *rep_buf; 378 struct sk_buff *rep_buf;
379 int ret;
380 379
381 /* Validate configuration message header (ignore invalid message) */ 380 /* Validate configuration message header (ignore invalid message) */
382 req_hdr = (struct tipc_cfg_msg_hdr *)buf; 381 req_hdr = (struct tipc_cfg_msg_hdr *)buf;
@@ -398,12 +397,8 @@ static void cfg_conn_msg_event(int conid, struct sockaddr_tipc *addr,
398 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr)); 397 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
399 rep_hdr->tcm_len = htonl(rep_buf->len); 398 rep_hdr->tcm_len = htonl(rep_buf->len);
400 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST); 399 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
401 400 tipc_conn_sendmsg(&cfgsrv, conid, addr, rep_buf->data,
402 ret = tipc_conn_sendmsg(&cfgsrv, conid, addr, rep_buf->data, 401 rep_buf->len);
403 rep_buf->len);
404 if (ret < 0)
405 pr_err("Sending cfg reply message failed, no memory\n");
406
407 kfree_skb(rep_buf); 402 kfree_skb(rep_buf);
408 } 403 }
409} 404}
diff --git a/net/tipc/core.c b/net/tipc/core.c
index f9e88d8b04ca..80c20647b3d2 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -77,37 +77,13 @@ struct sk_buff *tipc_buf_acquire(u32 size)
77} 77}
78 78
79/** 79/**
80 * tipc_core_stop_net - shut down TIPC networking sub-systems
81 */
82static void tipc_core_stop_net(void)
83{
84 tipc_net_stop();
85 tipc_bearer_cleanup();
86}
87
88/**
89 * start_net - start TIPC networking sub-systems
90 */
91int tipc_core_start_net(unsigned long addr)
92{
93 int res;
94
95 tipc_net_start(addr);
96 res = tipc_bearer_setup();
97 if (res < 0)
98 goto err;
99 return res;
100
101err:
102 tipc_core_stop_net();
103 return res;
104}
105
106/**
107 * tipc_core_stop - switch TIPC from SINGLE NODE to NOT RUNNING mode 80 * tipc_core_stop - switch TIPC from SINGLE NODE to NOT RUNNING mode
108 */ 81 */
109static void tipc_core_stop(void) 82static void tipc_core_stop(void)
110{ 83{
84 tipc_handler_stop();
85 tipc_net_stop();
86 tipc_bearer_cleanup();
111 tipc_netlink_stop(); 87 tipc_netlink_stop();
112 tipc_cfg_stop(); 88 tipc_cfg_stop();
113 tipc_subscr_stop(); 89 tipc_subscr_stop();
@@ -122,30 +98,65 @@ static void tipc_core_stop(void)
122 */ 98 */
123static int tipc_core_start(void) 99static int tipc_core_start(void)
124{ 100{
125 int res; 101 int err;
126 102
127 get_random_bytes(&tipc_random, sizeof(tipc_random)); 103 get_random_bytes(&tipc_random, sizeof(tipc_random));
128 104
129 res = tipc_handler_start(); 105 err = tipc_handler_start();
130 if (!res) 106 if (err)
131 res = tipc_ref_table_init(tipc_max_ports, tipc_random); 107 goto out_handler;
132 if (!res) 108
133 res = tipc_nametbl_init(); 109 err = tipc_ref_table_init(tipc_max_ports, tipc_random);
134 if (!res) 110 if (err)
135 res = tipc_netlink_start(); 111 goto out_reftbl;
136 if (!res) 112
137 res = tipc_socket_init(); 113 err = tipc_nametbl_init();
138 if (!res) 114 if (err)
139 res = tipc_register_sysctl(); 115 goto out_nametbl;
140 if (!res) 116
141 res = tipc_subscr_start(); 117 err = tipc_netlink_start();
142 if (!res) 118 if (err)
143 res = tipc_cfg_init(); 119 goto out_netlink;
144 if (res) { 120
145 tipc_handler_stop(); 121 err = tipc_socket_init();
146 tipc_core_stop(); 122 if (err)
147 } 123 goto out_socket;
148 return res; 124
125 err = tipc_register_sysctl();
126 if (err)
127 goto out_sysctl;
128
129 err = tipc_subscr_start();
130 if (err)
131 goto out_subscr;
132
133 err = tipc_cfg_init();
134 if (err)
135 goto out_cfg;
136
137 err = tipc_bearer_setup();
138 if (err)
139 goto out_bearer;
140
141 return 0;
142out_bearer:
143 tipc_cfg_stop();
144out_cfg:
145 tipc_subscr_stop();
146out_subscr:
147 tipc_unregister_sysctl();
148out_sysctl:
149 tipc_socket_stop();
150out_socket:
151 tipc_netlink_stop();
152out_netlink:
153 tipc_nametbl_stop();
154out_nametbl:
155 tipc_ref_table_stop();
156out_reftbl:
157 tipc_handler_stop();
158out_handler:
159 return err;
149} 160}
150 161
151static int __init tipc_init(void) 162static int __init tipc_init(void)
@@ -174,8 +185,6 @@ static int __init tipc_init(void)
174 185
175static void __exit tipc_exit(void) 186static void __exit tipc_exit(void)
176{ 187{
177 tipc_handler_stop();
178 tipc_core_stop_net();
179 tipc_core_stop(); 188 tipc_core_stop();
180 pr_info("Deactivated\n"); 189 pr_info("Deactivated\n");
181} 190}
diff --git a/net/tipc/core.h b/net/tipc/core.h
index 1ff477b0450d..4dfe137587bb 100644
--- a/net/tipc/core.h
+++ b/net/tipc/core.h
@@ -90,7 +90,6 @@ extern int tipc_random __read_mostly;
90/* 90/*
91 * Routines available to privileged subsystems 91 * Routines available to privileged subsystems
92 */ 92 */
93int tipc_core_start_net(unsigned long);
94int tipc_handler_start(void); 93int tipc_handler_start(void);
95void tipc_handler_stop(void); 94void tipc_handler_stop(void);
96int tipc_netlink_start(void); 95int tipc_netlink_start(void);
@@ -192,6 +191,7 @@ static inline void k_term_timer(struct timer_list *timer)
192 191
193struct tipc_skb_cb { 192struct tipc_skb_cb {
194 void *handle; 193 void *handle;
194 bool deferred;
195}; 195};
196 196
197#define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0])) 197#define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0]))
diff --git a/net/tipc/handler.c b/net/tipc/handler.c
index e4bc8a296744..1fabf160501f 100644
--- a/net/tipc/handler.c
+++ b/net/tipc/handler.c
@@ -58,7 +58,6 @@ unsigned int tipc_k_signal(Handler routine, unsigned long argument)
58 58
59 spin_lock_bh(&qitem_lock); 59 spin_lock_bh(&qitem_lock);
60 if (!handler_enabled) { 60 if (!handler_enabled) {
61 pr_err("Signal request ignored by handler\n");
62 spin_unlock_bh(&qitem_lock); 61 spin_unlock_bh(&qitem_lock);
63 return -ENOPROTOOPT; 62 return -ENOPROTOOPT;
64 } 63 }
diff --git a/net/tipc/link.c b/net/tipc/link.c
index d4b5de41b682..da6018beb6eb 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -1391,6 +1391,12 @@ static int link_recv_buf_validate(struct sk_buff *buf)
1391 u32 hdr_size; 1391 u32 hdr_size;
1392 u32 min_hdr_size; 1392 u32 min_hdr_size;
1393 1393
1394 /* If this packet comes from the defer queue, the skb has already
1395 * been validated
1396 */
1397 if (unlikely(TIPC_SKB_CB(buf)->deferred))
1398 return 1;
1399
1394 if (unlikely(buf->len < MIN_H_SIZE)) 1400 if (unlikely(buf->len < MIN_H_SIZE))
1395 return 0; 1401 return 0;
1396 1402
@@ -1703,6 +1709,7 @@ static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
1703 &l_ptr->newest_deferred_in, buf)) { 1709 &l_ptr->newest_deferred_in, buf)) {
1704 l_ptr->deferred_inqueue_sz++; 1710 l_ptr->deferred_inqueue_sz++;
1705 l_ptr->stats.deferred_recv++; 1711 l_ptr->stats.deferred_recv++;
1712 TIPC_SKB_CB(buf)->deferred = true;
1706 if ((l_ptr->deferred_inqueue_sz % 16) == 1) 1713 if ((l_ptr->deferred_inqueue_sz % 16) == 1)
1707 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); 1714 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
1708 } else 1715 } else
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 92a1533af4e0..042e8e3cabc0 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -941,20 +941,48 @@ int tipc_nametbl_init(void)
941 return 0; 941 return 0;
942} 942}
943 943
944void tipc_nametbl_stop(void) 944/**
945 * tipc_purge_publications - remove all publications for a given type
946 *
947 * tipc_nametbl_lock must be held when calling this function
948 */
949static void tipc_purge_publications(struct name_seq *seq)
945{ 950{
946 u32 i; 951 struct publication *publ, *safe;
952 struct sub_seq *sseq;
953 struct name_info *info;
947 954
948 if (!table.types) 955 if (!seq->sseqs) {
956 nameseq_delete_empty(seq);
949 return; 957 return;
958 }
959 sseq = seq->sseqs;
960 info = sseq->info;
961 list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) {
962 tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node,
963 publ->ref, publ->key);
964 }
965}
966
967void tipc_nametbl_stop(void)
968{
969 u32 i;
970 struct name_seq *seq;
971 struct hlist_head *seq_head;
972 struct hlist_node *safe;
950 973
951 /* Verify name table is empty, then release it */ 974 /* Verify name table is empty and purge any lingering
975 * publications, then release the name table
976 */
952 write_lock_bh(&tipc_nametbl_lock); 977 write_lock_bh(&tipc_nametbl_lock);
953 for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { 978 for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
954 if (hlist_empty(&table.types[i])) 979 if (hlist_empty(&table.types[i]))
955 continue; 980 continue;
956 pr_err("nametbl_stop(): orphaned hash chain detected\n"); 981 seq_head = &table.types[i];
957 break; 982 hlist_for_each_entry_safe(seq, safe, seq_head, ns_list) {
983 tipc_purge_publications(seq);
984 }
985 continue;
958 } 986 }
959 kfree(table.types); 987 kfree(table.types);
960 table.types = NULL; 988 table.types = NULL;
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index 9f72a6376362..3aaf73de9e2d 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -83,8 +83,6 @@ static struct genl_ops tipc_genl_ops[] = {
83 }, 83 },
84}; 84};
85 85
86static int tipc_genl_family_registered;
87
88int tipc_netlink_start(void) 86int tipc_netlink_start(void)
89{ 87{
90 int res; 88 int res;
@@ -94,16 +92,10 @@ int tipc_netlink_start(void)
94 pr_err("Failed to register netlink interface\n"); 92 pr_err("Failed to register netlink interface\n");
95 return res; 93 return res;
96 } 94 }
97
98 tipc_genl_family_registered = 1;
99 return 0; 95 return 0;
100} 96}
101 97
102void tipc_netlink_stop(void) 98void tipc_netlink_stop(void)
103{ 99{
104 if (!tipc_genl_family_registered)
105 return;
106
107 genl_unregister_family(&tipc_genl_family); 100 genl_unregister_family(&tipc_genl_family);
108 tipc_genl_family_registered = 0;
109} 101}
diff --git a/net/tipc/ref.c b/net/tipc/ref.c
index 2a2a938dc22c..de3d593e2fee 100644
--- a/net/tipc/ref.c
+++ b/net/tipc/ref.c
@@ -126,9 +126,6 @@ int tipc_ref_table_init(u32 requested_size, u32 start)
126 */ 126 */
127void tipc_ref_table_stop(void) 127void tipc_ref_table_stop(void)
128{ 128{
129 if (!tipc_ref_table.entries)
130 return;
131
132 vfree(tipc_ref_table.entries); 129 vfree(tipc_ref_table.entries);
133 tipc_ref_table.entries = NULL; 130 tipc_ref_table.entries = NULL;
134} 131}
diff --git a/net/tipc/server.c b/net/tipc/server.c
index b635ca347a87..646a930eefbf 100644
--- a/net/tipc/server.c
+++ b/net/tipc/server.c
@@ -87,7 +87,6 @@ static void tipc_clean_outqueues(struct tipc_conn *con);
87static void tipc_conn_kref_release(struct kref *kref) 87static void tipc_conn_kref_release(struct kref *kref)
88{ 88{
89 struct tipc_conn *con = container_of(kref, struct tipc_conn, kref); 89 struct tipc_conn *con = container_of(kref, struct tipc_conn, kref);
90 struct tipc_server *s = con->server;
91 90
92 if (con->sock) { 91 if (con->sock) {
93 tipc_sock_release_local(con->sock); 92 tipc_sock_release_local(con->sock);
@@ -95,10 +94,6 @@ static void tipc_conn_kref_release(struct kref *kref)
95 } 94 }
96 95
97 tipc_clean_outqueues(con); 96 tipc_clean_outqueues(con);
98
99 if (con->conid)
100 s->tipc_conn_shutdown(con->conid, con->usr_data);
101
102 kfree(con); 97 kfree(con);
103} 98}
104 99
@@ -181,6 +176,9 @@ static void tipc_close_conn(struct tipc_conn *con)
181 struct tipc_server *s = con->server; 176 struct tipc_server *s = con->server;
182 177
183 if (test_and_clear_bit(CF_CONNECTED, &con->flags)) { 178 if (test_and_clear_bit(CF_CONNECTED, &con->flags)) {
179 if (con->conid)
180 s->tipc_conn_shutdown(con->conid, con->usr_data);
181
184 spin_lock_bh(&s->idr_lock); 182 spin_lock_bh(&s->idr_lock);
185 idr_remove(&s->conn_idr, con->conid); 183 idr_remove(&s->conn_idr, con->conid);
186 s->idr_in_use--; 184 s->idr_in_use--;
@@ -429,10 +427,12 @@ int tipc_conn_sendmsg(struct tipc_server *s, int conid,
429 list_add_tail(&e->list, &con->outqueue); 427 list_add_tail(&e->list, &con->outqueue);
430 spin_unlock_bh(&con->outqueue_lock); 428 spin_unlock_bh(&con->outqueue_lock);
431 429
432 if (test_bit(CF_CONNECTED, &con->flags)) 430 if (test_bit(CF_CONNECTED, &con->flags)) {
433 if (!queue_work(s->send_wq, &con->swork)) 431 if (!queue_work(s->send_wq, &con->swork))
434 conn_put(con); 432 conn_put(con);
435 433 } else {
434 conn_put(con);
435 }
436 return 0; 436 return 0;
437} 437}
438 438
@@ -573,7 +573,6 @@ int tipc_server_start(struct tipc_server *s)
573 kmem_cache_destroy(s->rcvbuf_cache); 573 kmem_cache_destroy(s->rcvbuf_cache);
574 return ret; 574 return ret;
575 } 575 }
576 s->enabled = 1;
577 return ret; 576 return ret;
578} 577}
579 578
@@ -583,10 +582,6 @@ void tipc_server_stop(struct tipc_server *s)
583 int total = 0; 582 int total = 0;
584 int id; 583 int id;
585 584
586 if (!s->enabled)
587 return;
588
589 s->enabled = 0;
590 spin_lock_bh(&s->idr_lock); 585 spin_lock_bh(&s->idr_lock);
591 for (id = 0; total < s->idr_in_use; id++) { 586 for (id = 0; total < s->idr_in_use; id++) {
592 con = idr_find(&s->conn_idr, id); 587 con = idr_find(&s->conn_idr, id);
diff --git a/net/tipc/server.h b/net/tipc/server.h
index 98b23f20bc0f..be817b0b547e 100644
--- a/net/tipc/server.h
+++ b/net/tipc/server.h
@@ -56,7 +56,6 @@
56 * @name: server name 56 * @name: server name
57 * @imp: message importance 57 * @imp: message importance
58 * @type: socket type 58 * @type: socket type
59 * @enabled: identify whether server is launched or not
60 */ 59 */
61struct tipc_server { 60struct tipc_server {
62 struct idr conn_idr; 61 struct idr conn_idr;
@@ -74,7 +73,6 @@ struct tipc_server {
74 const char name[TIPC_SERVER_NAME_LEN]; 73 const char name[TIPC_SERVER_NAME_LEN];
75 int imp; 74 int imp;
76 int type; 75 int type;
77 int enabled;
78}; 76};
79 77
80int tipc_conn_sendmsg(struct tipc_server *s, int conid, 78int tipc_conn_sendmsg(struct tipc_server *s, int conid,
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index aab4948f0aff..0ed0eaa62f29 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -70,8 +70,6 @@ static const struct proto_ops msg_ops;
70static struct proto tipc_proto; 70static struct proto tipc_proto;
71static struct proto tipc_proto_kern; 71static struct proto tipc_proto_kern;
72 72
73static int sockets_enabled;
74
75/* 73/*
76 * Revised TIPC socket locking policy: 74 * Revised TIPC socket locking policy:
77 * 75 *
@@ -999,7 +997,7 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo)
999 997
1000 for (;;) { 998 for (;;) {
1001 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 999 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
1002 if (skb_queue_empty(&sk->sk_receive_queue)) { 1000 if (timeo && skb_queue_empty(&sk->sk_receive_queue)) {
1003 if (sock->state == SS_DISCONNECTING) { 1001 if (sock->state == SS_DISCONNECTING) {
1004 err = -ENOTCONN; 1002 err = -ENOTCONN;
1005 break; 1003 break;
@@ -1625,7 +1623,7 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo)
1625 for (;;) { 1623 for (;;) {
1626 prepare_to_wait_exclusive(sk_sleep(sk), &wait, 1624 prepare_to_wait_exclusive(sk_sleep(sk), &wait,
1627 TASK_INTERRUPTIBLE); 1625 TASK_INTERRUPTIBLE);
1628 if (skb_queue_empty(&sk->sk_receive_queue)) { 1626 if (timeo && skb_queue_empty(&sk->sk_receive_queue)) {
1629 release_sock(sk); 1627 release_sock(sk);
1630 timeo = schedule_timeout(timeo); 1628 timeo = schedule_timeout(timeo);
1631 lock_sock(sk); 1629 lock_sock(sk);
@@ -2027,8 +2025,6 @@ int tipc_socket_init(void)
2027 proto_unregister(&tipc_proto); 2025 proto_unregister(&tipc_proto);
2028 goto out; 2026 goto out;
2029 } 2027 }
2030
2031 sockets_enabled = 1;
2032 out: 2028 out:
2033 return res; 2029 return res;
2034} 2030}
@@ -2038,10 +2034,6 @@ int tipc_socket_init(void)
2038 */ 2034 */
2039void tipc_socket_stop(void) 2035void tipc_socket_stop(void)
2040{ 2036{
2041 if (!sockets_enabled)
2042 return;
2043
2044 sockets_enabled = 0;
2045 sock_unregister(tipc_family_ops.family); 2037 sock_unregister(tipc_family_ops.family);
2046 proto_unregister(&tipc_proto); 2038 proto_unregister(&tipc_proto);
2047} 2039}
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index 7cb0bd5b1176..642437231ad5 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -96,20 +96,16 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
96{ 96{
97 struct tipc_subscriber *subscriber = sub->subscriber; 97 struct tipc_subscriber *subscriber = sub->subscriber;
98 struct kvec msg_sect; 98 struct kvec msg_sect;
99 int ret;
100 99
101 msg_sect.iov_base = (void *)&sub->evt; 100 msg_sect.iov_base = (void *)&sub->evt;
102 msg_sect.iov_len = sizeof(struct tipc_event); 101 msg_sect.iov_len = sizeof(struct tipc_event);
103
104 sub->evt.event = htohl(event, sub->swap); 102 sub->evt.event = htohl(event, sub->swap);
105 sub->evt.found_lower = htohl(found_lower, sub->swap); 103 sub->evt.found_lower = htohl(found_lower, sub->swap);
106 sub->evt.found_upper = htohl(found_upper, sub->swap); 104 sub->evt.found_upper = htohl(found_upper, sub->swap);
107 sub->evt.port.ref = htohl(port_ref, sub->swap); 105 sub->evt.port.ref = htohl(port_ref, sub->swap);
108 sub->evt.port.node = htohl(node, sub->swap); 106 sub->evt.port.node = htohl(node, sub->swap);
109 ret = tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL, 107 tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL, msg_sect.iov_base,
110 msg_sect.iov_base, msg_sect.iov_len); 108 msg_sect.iov_len);
111 if (ret < 0)
112 pr_err("Sending subscription event failed, no memory\n");
113} 109}
114 110
115/** 111/**
@@ -153,14 +149,6 @@ static void subscr_timeout(struct tipc_subscription *sub)
153 /* The spin lock per subscriber is used to protect its members */ 149 /* The spin lock per subscriber is used to protect its members */
154 spin_lock_bh(&subscriber->lock); 150 spin_lock_bh(&subscriber->lock);
155 151
156 /* Validate if the connection related to the subscriber is
157 * closed (in case subscriber is terminating)
158 */
159 if (subscriber->conid == 0) {
160 spin_unlock_bh(&subscriber->lock);
161 return;
162 }
163
164 /* Validate timeout (in case subscription is being cancelled) */ 152 /* Validate timeout (in case subscription is being cancelled) */
165 if (sub->timeout == TIPC_WAIT_FOREVER) { 153 if (sub->timeout == TIPC_WAIT_FOREVER) {
166 spin_unlock_bh(&subscriber->lock); 154 spin_unlock_bh(&subscriber->lock);
@@ -215,9 +203,6 @@ static void subscr_release(struct tipc_subscriber *subscriber)
215 203
216 spin_lock_bh(&subscriber->lock); 204 spin_lock_bh(&subscriber->lock);
217 205
218 /* Invalidate subscriber reference */
219 subscriber->conid = 0;
220
221 /* Destroy any existing subscriptions for subscriber */ 206 /* Destroy any existing subscriptions for subscriber */
222 list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, 207 list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
223 subscription_list) { 208 subscription_list) {
@@ -278,9 +263,9 @@ static void subscr_cancel(struct tipc_subscr *s,
278 * 263 *
279 * Called with subscriber lock held. 264 * Called with subscriber lock held.
280 */ 265 */
281static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s, 266static int subscr_subscribe(struct tipc_subscr *s,
282 struct tipc_subscriber *subscriber) 267 struct tipc_subscriber *subscriber,
283{ 268 struct tipc_subscription **sub_p) {
284 struct tipc_subscription *sub; 269 struct tipc_subscription *sub;
285 int swap; 270 int swap;
286 271
@@ -291,23 +276,21 @@ static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s,
291 if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) { 276 if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) {
292 s->filter &= ~htohl(TIPC_SUB_CANCEL, swap); 277 s->filter &= ~htohl(TIPC_SUB_CANCEL, swap);
293 subscr_cancel(s, subscriber); 278 subscr_cancel(s, subscriber);
294 return NULL; 279 return 0;
295 } 280 }
296 281
297 /* Refuse subscription if global limit exceeded */ 282 /* Refuse subscription if global limit exceeded */
298 if (atomic_read(&subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) { 283 if (atomic_read(&subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) {
299 pr_warn("Subscription rejected, limit reached (%u)\n", 284 pr_warn("Subscription rejected, limit reached (%u)\n",
300 TIPC_MAX_SUBSCRIPTIONS); 285 TIPC_MAX_SUBSCRIPTIONS);
301 subscr_terminate(subscriber); 286 return -EINVAL;
302 return NULL;
303 } 287 }
304 288
305 /* Allocate subscription object */ 289 /* Allocate subscription object */
306 sub = kmalloc(sizeof(*sub), GFP_ATOMIC); 290 sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
307 if (!sub) { 291 if (!sub) {
308 pr_warn("Subscription rejected, no memory\n"); 292 pr_warn("Subscription rejected, no memory\n");
309 subscr_terminate(subscriber); 293 return -ENOMEM;
310 return NULL;
311 } 294 }
312 295
313 /* Initialize subscription object */ 296 /* Initialize subscription object */
@@ -321,8 +304,7 @@ static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s,
321 (sub->seq.lower > sub->seq.upper)) { 304 (sub->seq.lower > sub->seq.upper)) {
322 pr_warn("Subscription rejected, illegal request\n"); 305 pr_warn("Subscription rejected, illegal request\n");
323 kfree(sub); 306 kfree(sub);
324 subscr_terminate(subscriber); 307 return -EINVAL;
325 return NULL;
326 } 308 }
327 INIT_LIST_HEAD(&sub->nameseq_list); 309 INIT_LIST_HEAD(&sub->nameseq_list);
328 list_add(&sub->subscription_list, &subscriber->subscription_list); 310 list_add(&sub->subscription_list, &subscriber->subscription_list);
@@ -335,8 +317,8 @@ static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s,
335 (Handler)subscr_timeout, (unsigned long)sub); 317 (Handler)subscr_timeout, (unsigned long)sub);
336 k_start_timer(&sub->timer, sub->timeout); 318 k_start_timer(&sub->timer, sub->timeout);
337 } 319 }
338 320 *sub_p = sub;
339 return sub; 321 return 0;
340} 322}
341 323
342/* Handle one termination request for the subscriber */ 324/* Handle one termination request for the subscriber */
@@ -350,10 +332,14 @@ static void subscr_conn_msg_event(int conid, struct sockaddr_tipc *addr,
350 void *usr_data, void *buf, size_t len) 332 void *usr_data, void *buf, size_t len)
351{ 333{
352 struct tipc_subscriber *subscriber = usr_data; 334 struct tipc_subscriber *subscriber = usr_data;
353 struct tipc_subscription *sub; 335 struct tipc_subscription *sub = NULL;
354 336
355 spin_lock_bh(&subscriber->lock); 337 spin_lock_bh(&subscriber->lock);
356 sub = subscr_subscribe((struct tipc_subscr *)buf, subscriber); 338 if (subscr_subscribe((struct tipc_subscr *)buf, subscriber, &sub) < 0) {
339 spin_unlock_bh(&subscriber->lock);
340 subscr_terminate(subscriber);
341 return;
342 }
357 if (sub) 343 if (sub)
358 tipc_nametbl_subscribe(sub); 344 tipc_nametbl_subscribe(sub);
359 spin_unlock_bh(&subscriber->lock); 345 spin_unlock_bh(&subscriber->lock);
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 29fc8bee9702..94404f19f9de 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -163,9 +163,8 @@ static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb)
163 163
164static inline unsigned int unix_hash_fold(__wsum n) 164static inline unsigned int unix_hash_fold(__wsum n)
165{ 165{
166 unsigned int hash = (__force unsigned int)n; 166 unsigned int hash = (__force unsigned int)csum_fold(n);
167 167
168 hash ^= hash>>16;
169 hash ^= hash>>8; 168 hash ^= hash>>8;
170 return hash&(UNIX_HASH_SIZE-1); 169 return hash&(UNIX_HASH_SIZE-1);
171} 170}
@@ -1788,8 +1787,11 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1788 goto out; 1787 goto out;
1789 1788
1790 err = mutex_lock_interruptible(&u->readlock); 1789 err = mutex_lock_interruptible(&u->readlock);
1791 if (err) { 1790 if (unlikely(err)) {
1792 err = sock_intr_errno(sock_rcvtimeo(sk, noblock)); 1791 /* recvmsg() in non blocking mode is supposed to return -EAGAIN
1792 * sk_rcvtimeo is not honored by mutex_lock_interruptible()
1793 */
1794 err = noblock ? -EAGAIN : -ERESTARTSYS;
1793 goto out; 1795 goto out;
1794 } 1796 }
1795 1797
@@ -1914,6 +1916,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1914 struct unix_sock *u = unix_sk(sk); 1916 struct unix_sock *u = unix_sk(sk);
1915 DECLARE_SOCKADDR(struct sockaddr_un *, sunaddr, msg->msg_name); 1917 DECLARE_SOCKADDR(struct sockaddr_un *, sunaddr, msg->msg_name);
1916 int copied = 0; 1918 int copied = 0;
1919 int noblock = flags & MSG_DONTWAIT;
1917 int check_creds = 0; 1920 int check_creds = 0;
1918 int target; 1921 int target;
1919 int err = 0; 1922 int err = 0;
@@ -1929,7 +1932,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1929 goto out; 1932 goto out;
1930 1933
1931 target = sock_rcvlowat(sk, flags&MSG_WAITALL, size); 1934 target = sock_rcvlowat(sk, flags&MSG_WAITALL, size);
1932 timeo = sock_rcvtimeo(sk, flags&MSG_DONTWAIT); 1935 timeo = sock_rcvtimeo(sk, noblock);
1933 1936
1934 /* Lock the socket to prevent queue disordering 1937 /* Lock the socket to prevent queue disordering
1935 * while sleeps in memcpy_tomsg 1938 * while sleeps in memcpy_tomsg
@@ -1941,8 +1944,11 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1941 } 1944 }
1942 1945
1943 err = mutex_lock_interruptible(&u->readlock); 1946 err = mutex_lock_interruptible(&u->readlock);
1944 if (err) { 1947 if (unlikely(err)) {
1945 err = sock_intr_errno(timeo); 1948 /* recvmsg() in non blocking mode is supposed to return -EAGAIN
1949 * sk_rcvtimeo is not honored by mutex_lock_interruptible()
1950 */
1951 err = noblock ? -EAGAIN : -ERESTARTSYS;
1946 goto out; 1952 goto out;
1947 } 1953 }
1948 1954
diff --git a/net/wireless/core.c b/net/wireless/core.c
index d89dee2259b5..a3bf18d11609 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -203,8 +203,11 @@ void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev,
203 203
204 rdev->opencount--; 204 rdev->opencount--;
205 205
206 WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev && 206 if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
207 !rdev->scan_req->notified); 207 if (WARN_ON(!rdev->scan_req->notified))
208 rdev->scan_req->aborted = true;
209 ___cfg80211_scan_done(rdev, false);
210 }
208} 211}
209 212
210static int cfg80211_rfkill_set_block(void *data, bool blocked) 213static int cfg80211_rfkill_set_block(void *data, bool blocked)
@@ -440,9 +443,6 @@ int wiphy_register(struct wiphy *wiphy)
440 int i; 443 int i;
441 u16 ifmodes = wiphy->interface_modes; 444 u16 ifmodes = wiphy->interface_modes;
442 445
443 /* support for 5/10 MHz is broken due to nl80211 API mess - disable */
444 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_5_10_MHZ;
445
446 /* 446 /*
447 * There are major locking problems in nl80211/mac80211 for CSA, 447 * There are major locking problems in nl80211/mac80211 for CSA,
448 * disable for all drivers until this has been reworked. 448 * disable for all drivers until this has been reworked.
@@ -788,8 +788,6 @@ void cfg80211_leave(struct cfg80211_registered_device *rdev,
788 default: 788 default:
789 break; 789 break;
790 } 790 }
791
792 wdev->beacon_interval = 0;
793} 791}
794 792
795static int cfg80211_netdev_notifier_call(struct notifier_block *nb, 793static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
@@ -859,8 +857,11 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
859 break; 857 break;
860 case NETDEV_DOWN: 858 case NETDEV_DOWN:
861 cfg80211_update_iface_num(rdev, wdev->iftype, -1); 859 cfg80211_update_iface_num(rdev, wdev->iftype, -1);
862 WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev && 860 if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
863 !rdev->scan_req->notified); 861 if (WARN_ON(!rdev->scan_req->notified))
862 rdev->scan_req->aborted = true;
863 ___cfg80211_scan_done(rdev, false);
864 }
864 865
865 if (WARN_ON(rdev->sched_scan_req && 866 if (WARN_ON(rdev->sched_scan_req &&
866 rdev->sched_scan_req->dev == wdev->netdev)) { 867 rdev->sched_scan_req->dev == wdev->netdev)) {
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 37ec16d7bb1a..f1d193b557b6 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -62,6 +62,7 @@ struct cfg80211_registered_device {
62 struct rb_root bss_tree; 62 struct rb_root bss_tree;
63 u32 bss_generation; 63 u32 bss_generation;
64 struct cfg80211_scan_request *scan_req; /* protected by RTNL */ 64 struct cfg80211_scan_request *scan_req; /* protected by RTNL */
65 struct sk_buff *scan_msg;
65 struct cfg80211_sched_scan_request *sched_scan_req; 66 struct cfg80211_sched_scan_request *sched_scan_req;
66 unsigned long suspend_at; 67 unsigned long suspend_at;
67 struct work_struct scan_done_wk; 68 struct work_struct scan_done_wk;
@@ -361,7 +362,8 @@ int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
361 struct key_params *params, int key_idx, 362 struct key_params *params, int key_idx,
362 bool pairwise, const u8 *mac_addr); 363 bool pairwise, const u8 *mac_addr);
363void __cfg80211_scan_done(struct work_struct *wk); 364void __cfg80211_scan_done(struct work_struct *wk);
364void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev); 365void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
366 bool send_message);
365void __cfg80211_sched_scan_results(struct work_struct *wk); 367void __cfg80211_sched_scan_results(struct work_struct *wk);
366int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev, 368int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
367 bool driver_initiated); 369 bool driver_initiated);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 7a742594916e..4fe2e6e2bc76 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -1719,9 +1719,10 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1719 * We can then retry with the larger buffer. 1719 * We can then retry with the larger buffer.
1720 */ 1720 */
1721 if ((ret == -ENOBUFS || ret == -EMSGSIZE) && 1721 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1722 !skb->len && 1722 !skb->len && !state->split &&
1723 cb->min_dump_alloc < 4096) { 1723 cb->min_dump_alloc < 4096) {
1724 cb->min_dump_alloc = 4096; 1724 cb->min_dump_alloc = 4096;
1725 state->split_start = 0;
1725 rtnl_unlock(); 1726 rtnl_unlock();
1726 return 1; 1727 return 1;
1727 } 1728 }
@@ -5244,7 +5245,7 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5244 if (!rdev->ops->scan) 5245 if (!rdev->ops->scan)
5245 return -EOPNOTSUPP; 5246 return -EOPNOTSUPP;
5246 5247
5247 if (rdev->scan_req) { 5248 if (rdev->scan_req || rdev->scan_msg) {
5248 err = -EBUSY; 5249 err = -EBUSY;
5249 goto unlock; 5250 goto unlock;
5250 } 5251 }
@@ -10011,40 +10012,31 @@ void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
10011 NL80211_MCGRP_SCAN, GFP_KERNEL); 10012 NL80211_MCGRP_SCAN, GFP_KERNEL);
10012} 10013}
10013 10014
10014void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, 10015struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10015 struct wireless_dev *wdev) 10016 struct wireless_dev *wdev, bool aborted)
10016{ 10017{
10017 struct sk_buff *msg; 10018 struct sk_buff *msg;
10018 10019
10019 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 10020 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10020 if (!msg) 10021 if (!msg)
10021 return; 10022 return NULL;
10022 10023
10023 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, 10024 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
10024 NL80211_CMD_NEW_SCAN_RESULTS) < 0) { 10025 aborted ? NL80211_CMD_SCAN_ABORTED :
10026 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
10025 nlmsg_free(msg); 10027 nlmsg_free(msg);
10026 return; 10028 return NULL;
10027 } 10029 }
10028 10030
10029 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 10031 return msg;
10030 NL80211_MCGRP_SCAN, GFP_KERNEL);
10031} 10032}
10032 10033
10033void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, 10034void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10034 struct wireless_dev *wdev) 10035 struct sk_buff *msg)
10035{ 10036{
10036 struct sk_buff *msg;
10037
10038 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10039 if (!msg) 10037 if (!msg)
10040 return; 10038 return;
10041 10039
10042 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
10043 NL80211_CMD_SCAN_ABORTED) < 0) {
10044 nlmsg_free(msg);
10045 return;
10046 }
10047
10048 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 10040 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
10049 NL80211_MCGRP_SCAN, GFP_KERNEL); 10041 NL80211_MCGRP_SCAN, GFP_KERNEL);
10050} 10042}
diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h
index b1b231324e10..75799746d845 100644
--- a/net/wireless/nl80211.h
+++ b/net/wireless/nl80211.h
@@ -8,10 +8,10 @@ void nl80211_exit(void);
8void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev); 8void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev);
9void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, 9void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
10 struct wireless_dev *wdev); 10 struct wireless_dev *wdev);
11void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, 11struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
12 struct wireless_dev *wdev); 12 struct wireless_dev *wdev, bool aborted);
13void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, 13void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
14 struct wireless_dev *wdev); 14 struct sk_buff *msg);
15void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, 15void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
16 struct net_device *netdev, u32 cmd); 16 struct net_device *netdev, u32 cmd);
17void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, 17void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 9b897fca7487..f0541370e68e 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1700,7 +1700,7 @@ static void reg_process_hint(struct regulatory_request *reg_request)
1700 return; 1700 return;
1701 case NL80211_REGDOM_SET_BY_USER: 1701 case NL80211_REGDOM_SET_BY_USER:
1702 treatment = reg_process_hint_user(reg_request); 1702 treatment = reg_process_hint_user(reg_request);
1703 if (treatment == REG_REQ_OK || 1703 if (treatment == REG_REQ_IGNORE ||
1704 treatment == REG_REQ_ALREADY_SET) 1704 treatment == REG_REQ_ALREADY_SET)
1705 return; 1705 return;
1706 schedule_delayed_work(&reg_timeout, msecs_to_jiffies(3142)); 1706 schedule_delayed_work(&reg_timeout, msecs_to_jiffies(3142));
@@ -2373,6 +2373,7 @@ static int reg_set_rd_country_ie(const struct ieee80211_regdomain *rd,
2373int set_regdom(const struct ieee80211_regdomain *rd) 2373int set_regdom(const struct ieee80211_regdomain *rd)
2374{ 2374{
2375 struct regulatory_request *lr; 2375 struct regulatory_request *lr;
2376 bool user_reset = false;
2376 int r; 2377 int r;
2377 2378
2378 if (!reg_is_valid_request(rd->alpha2)) { 2379 if (!reg_is_valid_request(rd->alpha2)) {
@@ -2389,6 +2390,7 @@ int set_regdom(const struct ieee80211_regdomain *rd)
2389 break; 2390 break;
2390 case NL80211_REGDOM_SET_BY_USER: 2391 case NL80211_REGDOM_SET_BY_USER:
2391 r = reg_set_rd_user(rd, lr); 2392 r = reg_set_rd_user(rd, lr);
2393 user_reset = true;
2392 break; 2394 break;
2393 case NL80211_REGDOM_SET_BY_DRIVER: 2395 case NL80211_REGDOM_SET_BY_DRIVER:
2394 r = reg_set_rd_driver(rd, lr); 2396 r = reg_set_rd_driver(rd, lr);
@@ -2402,8 +2404,14 @@ int set_regdom(const struct ieee80211_regdomain *rd)
2402 } 2404 }
2403 2405
2404 if (r) { 2406 if (r) {
2405 if (r == -EALREADY) 2407 switch (r) {
2408 case -EALREADY:
2406 reg_set_request_processed(); 2409 reg_set_request_processed();
2410 break;
2411 default:
2412 /* Back to world regulatory in case of errors */
2413 restore_regulatory_settings(user_reset);
2414 }
2407 2415
2408 kfree(rd); 2416 kfree(rd);
2409 return r; 2417 return r;
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index b528e31da2cf..d1ed4aebbbb7 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -161,18 +161,25 @@ static void __cfg80211_bss_expire(struct cfg80211_registered_device *dev,
161 dev->bss_generation++; 161 dev->bss_generation++;
162} 162}
163 163
164void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev) 164void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
165 bool send_message)
165{ 166{
166 struct cfg80211_scan_request *request; 167 struct cfg80211_scan_request *request;
167 struct wireless_dev *wdev; 168 struct wireless_dev *wdev;
169 struct sk_buff *msg;
168#ifdef CONFIG_CFG80211_WEXT 170#ifdef CONFIG_CFG80211_WEXT
169 union iwreq_data wrqu; 171 union iwreq_data wrqu;
170#endif 172#endif
171 173
172 ASSERT_RTNL(); 174 ASSERT_RTNL();
173 175
174 request = rdev->scan_req; 176 if (rdev->scan_msg) {
177 nl80211_send_scan_result(rdev, rdev->scan_msg);
178 rdev->scan_msg = NULL;
179 return;
180 }
175 181
182 request = rdev->scan_req;
176 if (!request) 183 if (!request)
177 return; 184 return;
178 185
@@ -186,18 +193,16 @@ void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev)
186 if (wdev->netdev) 193 if (wdev->netdev)
187 cfg80211_sme_scan_done(wdev->netdev); 194 cfg80211_sme_scan_done(wdev->netdev);
188 195
189 if (request->aborted) { 196 if (!request->aborted &&
190 nl80211_send_scan_aborted(rdev, wdev); 197 request->flags & NL80211_SCAN_FLAG_FLUSH) {
191 } else { 198 /* flush entries from previous scans */
192 if (request->flags & NL80211_SCAN_FLAG_FLUSH) { 199 spin_lock_bh(&rdev->bss_lock);
193 /* flush entries from previous scans */ 200 __cfg80211_bss_expire(rdev, request->scan_start);
194 spin_lock_bh(&rdev->bss_lock); 201 spin_unlock_bh(&rdev->bss_lock);
195 __cfg80211_bss_expire(rdev, request->scan_start);
196 spin_unlock_bh(&rdev->bss_lock);
197 }
198 nl80211_send_scan_done(rdev, wdev);
199 } 202 }
200 203
204 msg = nl80211_build_scan_msg(rdev, wdev, request->aborted);
205
201#ifdef CONFIG_CFG80211_WEXT 206#ifdef CONFIG_CFG80211_WEXT
202 if (wdev->netdev && !request->aborted) { 207 if (wdev->netdev && !request->aborted) {
203 memset(&wrqu, 0, sizeof(wrqu)); 208 memset(&wrqu, 0, sizeof(wrqu));
@@ -211,6 +216,11 @@ void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev)
211 216
212 rdev->scan_req = NULL; 217 rdev->scan_req = NULL;
213 kfree(request); 218 kfree(request);
219
220 if (!send_message)
221 rdev->scan_msg = msg;
222 else
223 nl80211_send_scan_result(rdev, msg);
214} 224}
215 225
216void __cfg80211_scan_done(struct work_struct *wk) 226void __cfg80211_scan_done(struct work_struct *wk)
@@ -221,7 +231,7 @@ void __cfg80211_scan_done(struct work_struct *wk)
221 scan_done_wk); 231 scan_done_wk);
222 232
223 rtnl_lock(); 233 rtnl_lock();
224 ___cfg80211_scan_done(rdev); 234 ___cfg80211_scan_done(rdev, true);
225 rtnl_unlock(); 235 rtnl_unlock();
226} 236}
227 237
@@ -1079,7 +1089,7 @@ int cfg80211_wext_siwscan(struct net_device *dev,
1079 if (IS_ERR(rdev)) 1089 if (IS_ERR(rdev))
1080 return PTR_ERR(rdev); 1090 return PTR_ERR(rdev);
1081 1091
1082 if (rdev->scan_req) { 1092 if (rdev->scan_req || rdev->scan_msg) {
1083 err = -EBUSY; 1093 err = -EBUSY;
1084 goto out; 1094 goto out;
1085 } 1095 }
@@ -1481,7 +1491,7 @@ int cfg80211_wext_giwscan(struct net_device *dev,
1481 if (IS_ERR(rdev)) 1491 if (IS_ERR(rdev))
1482 return PTR_ERR(rdev); 1492 return PTR_ERR(rdev);
1483 1493
1484 if (rdev->scan_req) 1494 if (rdev->scan_req || rdev->scan_msg)
1485 return -EAGAIN; 1495 return -EAGAIN;
1486 1496
1487 res = ieee80211_scan_results(rdev, info, extra, data->length); 1497 res = ieee80211_scan_results(rdev, info, extra, data->length);
diff --git a/net/wireless/sme.c b/net/wireless/sme.c
index a63509118508..f04d4c32e96e 100644
--- a/net/wireless/sme.c
+++ b/net/wireless/sme.c
@@ -67,7 +67,7 @@ static int cfg80211_conn_scan(struct wireless_dev *wdev)
67 ASSERT_RDEV_LOCK(rdev); 67 ASSERT_RDEV_LOCK(rdev);
68 ASSERT_WDEV_LOCK(wdev); 68 ASSERT_WDEV_LOCK(wdev);
69 69
70 if (rdev->scan_req) 70 if (rdev->scan_req || rdev->scan_msg)
71 return -EBUSY; 71 return -EBUSY;
72 72
73 if (wdev->conn->params.channel) 73 if (wdev->conn->params.channel)
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 4b98b25793c5..1d5c7bf29938 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1158,7 +1158,7 @@ static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol,
1158 if (hlist_unhashed(&pol->bydst)) 1158 if (hlist_unhashed(&pol->bydst))
1159 return NULL; 1159 return NULL;
1160 1160
1161 hlist_del(&pol->bydst); 1161 hlist_del_init(&pol->bydst);
1162 hlist_del(&pol->byidx); 1162 hlist_del(&pol->byidx);
1163 list_del(&pol->walk.all); 1163 list_del(&pol->walk.all);
1164 net->xfrm.policy_count[dir]--; 1164 net->xfrm.policy_count[dir]--;
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index a26b7aa79475..40f1b3e92e78 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -1159,6 +1159,11 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
1159 } 1159 }
1160 x->props.aalgo = orig->props.aalgo; 1160 x->props.aalgo = orig->props.aalgo;
1161 1161
1162 if (orig->aead) {
1163 x->aead = xfrm_algo_aead_clone(orig->aead);
1164 if (!x->aead)
1165 goto error;
1166 }
1162 if (orig->ealg) { 1167 if (orig->ealg) {
1163 x->ealg = xfrm_algo_clone(orig->ealg); 1168 x->ealg = xfrm_algo_clone(orig->ealg);
1164 if (!x->ealg) 1169 if (!x->ealg)
@@ -1201,6 +1206,9 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
1201 x->props.flags = orig->props.flags; 1206 x->props.flags = orig->props.flags;
1202 x->props.extra_flags = orig->props.extra_flags; 1207 x->props.extra_flags = orig->props.extra_flags;
1203 1208
1209 x->tfcpad = orig->tfcpad;
1210 x->replay_maxdiff = orig->replay_maxdiff;
1211 x->replay_maxage = orig->replay_maxage;
1204 x->curlft.add_time = orig->curlft.add_time; 1212 x->curlft.add_time = orig->curlft.add_time;
1205 x->km.state = orig->km.state; 1213 x->km.state = orig->km.state;
1206 x->km.seq = orig->km.seq; 1214 x->km.seq = orig->km.seq;
@@ -1215,11 +1223,12 @@ out:
1215 return NULL; 1223 return NULL;
1216} 1224}
1217 1225
1218/* net->xfrm.xfrm_state_lock is held */
1219struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *net) 1226struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *net)
1220{ 1227{
1221 unsigned int h; 1228 unsigned int h;
1222 struct xfrm_state *x; 1229 struct xfrm_state *x = NULL;
1230
1231 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1223 1232
1224 if (m->reqid) { 1233 if (m->reqid) {
1225 h = xfrm_dst_hash(net, &m->old_daddr, &m->old_saddr, 1234 h = xfrm_dst_hash(net, &m->old_daddr, &m->old_saddr,
@@ -1236,7 +1245,7 @@ struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *n
1236 m->old_family)) 1245 m->old_family))
1237 continue; 1246 continue;
1238 xfrm_state_hold(x); 1247 xfrm_state_hold(x);
1239 return x; 1248 break;
1240 } 1249 }
1241 } else { 1250 } else {
1242 h = xfrm_src_hash(net, &m->old_daddr, &m->old_saddr, 1251 h = xfrm_src_hash(net, &m->old_daddr, &m->old_saddr,
@@ -1251,11 +1260,13 @@ struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *n
1251 m->old_family)) 1260 m->old_family))
1252 continue; 1261 continue;
1253 xfrm_state_hold(x); 1262 xfrm_state_hold(x);
1254 return x; 1263 break;
1255 } 1264 }
1256 } 1265 }
1257 1266
1258 return NULL; 1267 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1268
1269 return x;
1259} 1270}
1260EXPORT_SYMBOL(xfrm_migrate_state_find); 1271EXPORT_SYMBOL(xfrm_migrate_state_find);
1261 1272
@@ -1451,7 +1462,7 @@ xfrm_state_sort(struct xfrm_state **dst, struct xfrm_state **src, int n,
1451{ 1462{
1452 int err = 0; 1463 int err = 0;
1453 struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family); 1464 struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family);
1454 struct net *net = xs_net(*dst); 1465 struct net *net = xs_net(*src);
1455 1466
1456 if (!afinfo) 1467 if (!afinfo)
1457 return -EAFNOSUPPORT; 1468 return -EAFNOSUPPORT;
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 1ae3ec7c18b0..2f7ddc3a59b4 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -32,11 +32,6 @@
32#include <linux/in6.h> 32#include <linux/in6.h>
33#endif 33#endif
34 34
35static inline int aead_len(struct xfrm_algo_aead *alg)
36{
37 return sizeof(*alg) + ((alg->alg_key_len + 7) / 8);
38}
39
40static int verify_one_alg(struct nlattr **attrs, enum xfrm_attr_type_t type) 35static int verify_one_alg(struct nlattr **attrs, enum xfrm_attr_type_t type)
41{ 36{
42 struct nlattr *rt = attrs[type]; 37 struct nlattr *rt = attrs[type];
@@ -1226,7 +1221,7 @@ static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct nlattr **attrs
1226 return 0; 1221 return 0;
1227 1222
1228 uctx = nla_data(rt); 1223 uctx = nla_data(rt);
1229 return security_xfrm_policy_alloc(&pol->security, uctx); 1224 return security_xfrm_policy_alloc(&pol->security, uctx, GFP_KERNEL);
1230} 1225}
1231 1226
1232static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut, 1227static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut,
@@ -1631,7 +1626,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1631 if (rt) { 1626 if (rt) {
1632 struct xfrm_user_sec_ctx *uctx = nla_data(rt); 1627 struct xfrm_user_sec_ctx *uctx = nla_data(rt);
1633 1628
1634 err = security_xfrm_policy_alloc(&ctx, uctx); 1629 err = security_xfrm_policy_alloc(&ctx, uctx, GFP_KERNEL);
1635 if (err) 1630 if (err)
1636 return err; 1631 return err;
1637 } 1632 }
@@ -1933,7 +1928,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1933 if (rt) { 1928 if (rt) {
1934 struct xfrm_user_sec_ctx *uctx = nla_data(rt); 1929 struct xfrm_user_sec_ctx *uctx = nla_data(rt);
1935 1930
1936 err = security_xfrm_policy_alloc(&ctx, uctx); 1931 err = security_xfrm_policy_alloc(&ctx, uctx, GFP_KERNEL);
1937 if (err) 1932 if (err)
1938 return err; 1933 return err;
1939 } 1934 }
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 547e15daf03d..93a0da26582b 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -155,6 +155,15 @@ ld-option = $(call try-run,\
155# Important: no spaces around options 155# Important: no spaces around options
156ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) 156ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2))
157 157
158# ld-version
159# Usage: $(call ld-version)
160# Note this is mainly for HJ Lu's 3 number binutil versions
161ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh)
162
163# ld-ifversion
164# Usage: $(call ld-ifversion, -ge, 22252, y)
165ld-ifversion = $(shell [ $(call ld-version) $(1) $(2) ] && echo $(3))
166
158###### 167######
159 168
160### 169###
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index d5d859c80729..9f0ee22b914f 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -198,7 +198,7 @@ $(multi-objs-y:.o=.s) : modname = $(modname-multi)
198$(multi-objs-y:.o=.lst) : modname = $(modname-multi) 198$(multi-objs-y:.o=.lst) : modname = $(modname-multi)
199 199
200quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ 200quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
201cmd_cc_s_c = $(CC) $(c_flags) -fverbose-asm -S -o $@ $< 201cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
202 202
203$(obj)/%.s: $(src)/%.c FORCE 203$(obj)/%.s: $(src)/%.c FORCE
204 $(call if_changed_dep,cc_s_c) 204 $(call if_changed_dep,cc_s_c)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 49392ecbef17..79c059e70860 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -152,6 +152,7 @@ ld_flags = $(LDFLAGS) $(ldflags-y)
152dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ 152dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
153 -I$(srctree)/arch/$(SRCARCH)/boot/dts \ 153 -I$(srctree)/arch/$(SRCARCH)/boot/dts \
154 -I$(srctree)/arch/$(SRCARCH)/boot/dts/include \ 154 -I$(srctree)/arch/$(SRCARCH)/boot/dts/include \
155 -I$(srctree)/drivers/of/testcase-data \
155 -undef -D__DTS__ 156 -undef -D__DTS__
156 157
157# Finds the multi-part object the current object will be linked into 158# Finds the multi-part object the current object will be linked into
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0ea2a1e24ade..464dcef79b35 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -471,7 +471,7 @@ sub seed_camelcase_includes {
471 471
472 $camelcase_seeded = 1; 472 $camelcase_seeded = 1;
473 473
474 if (-d ".git") { 474 if (-e ".git") {
475 my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`; 475 my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`;
476 chomp $git_last_include_commit; 476 chomp $git_last_include_commit;
477 $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit"; 477 $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
@@ -499,7 +499,7 @@ sub seed_camelcase_includes {
499 return; 499 return;
500 } 500 }
501 501
502 if (-d ".git") { 502 if (-e ".git") {
503 $files = `git ls-files "include/*.h"`; 503 $files = `git ls-files "include/*.h"`;
504 @include_files = split('\n', $files); 504 @include_files = split('\n', $files);
505 } 505 }
diff --git a/scripts/gcc-ld b/scripts/gcc-ld
new file mode 100644
index 000000000000..cadab9a13ed7
--- /dev/null
+++ b/scripts/gcc-ld
@@ -0,0 +1,29 @@
1#!/bin/sh
2# run gcc with ld options
3# used as a wrapper to execute link time optimizations
4# yes virginia, this is not pretty
5
6ARGS="-nostdlib"
7
8while [ "$1" != "" ] ; do
9 case "$1" in
10 -save-temps|-m32|-m64) N="$1" ;;
11 -r) N="$1" ;;
12 -[Wg]*) N="$1" ;;
13 -[olv]|-[Ofd]*|-nostdlib) N="$1" ;;
14 --end-group|--start-group)
15 N="-Wl,$1" ;;
16 -[RTFGhIezcbyYu]*|\
17--script|--defsym|-init|-Map|--oformat|-rpath|\
18-rpath-link|--sort-section|--section-start|-Tbss|-Tdata|-Ttext|\
19--version-script|--dynamic-list|--version-exports-symbol|--wrap|-m)
20 A="$1" ; shift ; N="-Wl,$A,$1" ;;
21 -[m]*) N="$1" ;;
22 -*) N="-Wl,$1" ;;
23 *) N="$1" ;;
24 esac
25 ARGS="$ARGS $N"
26 shift
27done
28
29exec $CC $ARGS
diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh
index ef474098d9f1..17fa901418ae 100644
--- a/scripts/gen_initramfs_list.sh
+++ b/scripts/gen_initramfs_list.sh
@@ -257,7 +257,7 @@ case "$arg" in
257 && compr="lzop -9 -f" 257 && compr="lzop -9 -f"
258 echo "$output_file" | grep -q "\.lz4$" \ 258 echo "$output_file" | grep -q "\.lz4$" \
259 && [ -x "`which lz4 2> /dev/null`" ] \ 259 && [ -x "`which lz4 2> /dev/null`" ] \
260 && compr="lz4 -9 -f" 260 && compr="lz4 -l -9 -f"
261 echo "$output_file" | grep -q "\.cpio$" && compr="cat" 261 echo "$output_file" | grep -q "\.cpio$" && compr="cat"
262 shift 262 shift
263 ;; 263 ;;
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 9c3986f4140c..41987885bd31 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -95,7 +95,7 @@ my %VCS_cmds;
95 95
96my %VCS_cmds_git = ( 96my %VCS_cmds_git = (
97 "execute_cmd" => \&git_execute_cmd, 97 "execute_cmd" => \&git_execute_cmd,
98 "available" => '(which("git") ne "") && (-d ".git")', 98 "available" => '(which("git") ne "") && (-e ".git")',
99 "find_signers_cmd" => 99 "find_signers_cmd" =>
100 "git log --no-color --follow --since=\$email_git_since " . 100 "git log --no-color --follow --since=\$email_git_since " .
101 '--numstat --no-merges ' . 101 '--numstat --no-merges ' .
diff --git a/scripts/ld-version.sh b/scripts/ld-version.sh
new file mode 100755
index 000000000000..198580d245e0
--- /dev/null
+++ b/scripts/ld-version.sh
@@ -0,0 +1,8 @@
1#!/usr/bin/awk -f
2# extract linker version number from stdin and turn into single number
3 {
4 gsub(".*)", "");
5 split($1,a, ".");
6 print a[1]*10000000 + a[2]*100000 + a[3]*10000 + a[4]*100 + a[5];
7 exit
8 }
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 23708636b05c..25e5cb0aaef6 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -210,8 +210,8 @@ static void do_usb_entry(void *symval,
210 range_lo < 0x9 ? "[%X-9" : "[%X", 210 range_lo < 0x9 ? "[%X-9" : "[%X",
211 range_lo); 211 range_lo);
212 sprintf(alias + strlen(alias), 212 sprintf(alias + strlen(alias),
213 range_hi > 0xA ? "a-%X]" : "%X]", 213 range_hi > 0xA ? "A-%X]" : "%X]",
214 range_lo); 214 range_hi);
215 } 215 }
216 } 216 }
217 if (bcdDevice_initial_digits < (sizeof(bcdDevice_lo) * 2 - 1)) 217 if (bcdDevice_initial_digits < (sizeof(bcdDevice_lo) * 2 - 1))
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 40610984a1b5..066355673930 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -623,7 +623,10 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
623 623
624 switch (sym->st_shndx) { 624 switch (sym->st_shndx) {
625 case SHN_COMMON: 625 case SHN_COMMON:
626 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); 626 if (!strncmp(symname, "__gnu_lto_", sizeof("__gnu_lto_")-1)) {
627 /* Should warn here, but modpost runs before the linker */
628 } else
629 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name);
627 break; 630 break;
628 case SHN_UNDEF: 631 case SHN_UNDEF:
629 /* undefined symbol */ 632 /* undefined symbol */
@@ -849,6 +852,7 @@ static const char *section_white_list[] =
849 ".xt.lit", /* xtensa */ 852 ".xt.lit", /* xtensa */
850 ".arcextmap*", /* arc */ 853 ".arcextmap*", /* arc */
851 ".gnu.linkonce.arcext*", /* arc : modules */ 854 ".gnu.linkonce.arcext*", /* arc : modules */
855 ".gnu.lto*",
852 NULL 856 NULL
853}; 857};
854 858
@@ -1455,6 +1459,10 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf,
1455 to = find_elf_symbol(elf, r->r_addend, sym); 1459 to = find_elf_symbol(elf, r->r_addend, sym);
1456 tosym = sym_name(elf, to); 1460 tosym = sym_name(elf, to);
1457 1461
1462 if (!strncmp(fromsym, "reference___initcall",
1463 sizeof("reference___initcall")-1))
1464 return;
1465
1458 /* check whitelist - we may ignore it */ 1466 /* check whitelist - we may ignore it */
1459 if (secref_whitelist(mismatch, 1467 if (secref_whitelist(mismatch,
1460 fromsec, fromsym, tosec, tosym)) { 1468 fromsec, fromsym, tosec, tosym)) {
@@ -1502,6 +1510,16 @@ static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1502#define R_ARM_JUMP24 29 1510#define R_ARM_JUMP24 29
1503#endif 1511#endif
1504 1512
1513#ifndef R_ARM_THM_CALL
1514#define R_ARM_THM_CALL 10
1515#endif
1516#ifndef R_ARM_THM_JUMP24
1517#define R_ARM_THM_JUMP24 30
1518#endif
1519#ifndef R_ARM_THM_JUMP19
1520#define R_ARM_THM_JUMP19 51
1521#endif
1522
1505static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) 1523static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1506{ 1524{
1507 unsigned int r_typ = ELF_R_TYPE(r->r_info); 1525 unsigned int r_typ = ELF_R_TYPE(r->r_info);
@@ -1515,6 +1533,9 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1515 case R_ARM_PC24: 1533 case R_ARM_PC24:
1516 case R_ARM_CALL: 1534 case R_ARM_CALL:
1517 case R_ARM_JUMP24: 1535 case R_ARM_JUMP24:
1536 case R_ARM_THM_CALL:
1537 case R_ARM_THM_JUMP24:
1538 case R_ARM_THM_JUMP19:
1518 /* From ARM ABI: ((S + A) | T) - P */ 1539 /* From ARM ABI: ((S + A) | T) - P */
1519 r->r_addend = (int)(long)(elf->hdr + 1540 r->r_addend = (int)(long)(elf->hdr +
1520 sechdr->sh_offset + 1541 sechdr->sh_offset +
@@ -1680,6 +1701,19 @@ static void check_sec_ref(struct module *mod, const char *modname,
1680 } 1701 }
1681} 1702}
1682 1703
1704static char *remove_dot(char *s)
1705{
1706 char *end;
1707 int n = strcspn(s, ".");
1708
1709 if (n > 0 && s[n] != 0) {
1710 strtoul(s + n + 1, &end, 10);
1711 if (end > s + n + 1 && (*end == '.' || *end == 0))
1712 s[n] = 0;
1713 }
1714 return s;
1715}
1716
1683static void read_symbols(char *modname) 1717static void read_symbols(char *modname)
1684{ 1718{
1685 const char *symname; 1719 const char *symname;
@@ -1718,7 +1752,7 @@ static void read_symbols(char *modname)
1718 } 1752 }
1719 1753
1720 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) { 1754 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
1721 symname = info.strtab + sym->st_name; 1755 symname = remove_dot(info.strtab + sym->st_name);
1722 1756
1723 handle_modversions(mod, &info, sym, symname); 1757 handle_modversions(mod, &info, sym, symname);
1724 handle_moddevtable(mod, &info, sym, symname); 1758 handle_moddevtable(mod, &info, sym, symname);
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 51207e4d5f8b..168b43dc0a59 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -127,7 +127,7 @@ struct elf_info {
127 Elf_Section export_gpl_sec; 127 Elf_Section export_gpl_sec;
128 Elf_Section export_unused_gpl_sec; 128 Elf_Section export_unused_gpl_sec;
129 Elf_Section export_gpl_future_sec; 129 Elf_Section export_gpl_future_sec;
130 const char *strtab; 130 char *strtab;
131 char *modinfo; 131 char *modinfo;
132 unsigned int modinfo_len; 132 unsigned int modinfo_len;
133 133
diff --git a/security/Kconfig b/security/Kconfig
index e9c6ac724fef..beb86b500adf 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -103,7 +103,7 @@ config INTEL_TXT
103config LSM_MMAP_MIN_ADDR 103config LSM_MMAP_MIN_ADDR
104 int "Low address space for LSM to protect from user allocation" 104 int "Low address space for LSM to protect from user allocation"
105 depends on SECURITY && SECURITY_SELINUX 105 depends on SECURITY && SECURITY_SELINUX
106 default 32768 if ARM 106 default 32768 if ARM || (ARM64 && COMPAT)
107 default 65536 107 default 65536
108 help 108 help
109 This is the portion of low virtual memory which should be protected 109 This is the portion of low virtual memory which should be protected
diff --git a/security/capability.c b/security/capability.c
index 8b4f24ae4338..21e2b9cae685 100644
--- a/security/capability.c
+++ b/security/capability.c
@@ -757,7 +757,8 @@ static void cap_skb_owned_by(struct sk_buff *skb, struct sock *sk)
757 757
758#ifdef CONFIG_SECURITY_NETWORK_XFRM 758#ifdef CONFIG_SECURITY_NETWORK_XFRM
759static int cap_xfrm_policy_alloc_security(struct xfrm_sec_ctx **ctxp, 759static int cap_xfrm_policy_alloc_security(struct xfrm_sec_ctx **ctxp,
760 struct xfrm_user_sec_ctx *sec_ctx) 760 struct xfrm_user_sec_ctx *sec_ctx,
761 gfp_t gfp)
761{ 762{
762 return 0; 763 return 0;
763} 764}
diff --git a/security/keys/compat.c b/security/keys/compat.c
index bbd32c729dbb..347896548ad3 100644
--- a/security/keys/compat.c
+++ b/security/keys/compat.c
@@ -65,8 +65,8 @@ no_payload:
65 * taking a 32-bit syscall are zero. If you can, you should call sys_keyctl() 65 * taking a 32-bit syscall are zero. If you can, you should call sys_keyctl()
66 * directly. 66 * directly.
67 */ 67 */
68asmlinkage long compat_sys_keyctl(u32 option, 68COMPAT_SYSCALL_DEFINE5(keyctl, u32, option,
69 u32 arg2, u32 arg3, u32 arg4, u32 arg5) 69 u32, arg2, u32, arg3, u32, arg4, u32, arg5)
70{ 70{
71 switch (option) { 71 switch (option) {
72 case KEYCTL_GET_KEYRING_ID: 72 case KEYCTL_GET_KEYRING_ID:
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index d46cbc5e335e..2fb2576dc644 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -1000,7 +1000,11 @@ static int keyring_detect_cycle_iterator(const void *object,
1000 1000
1001 kenter("{%d}", key->serial); 1001 kenter("{%d}", key->serial);
1002 1002
1003 BUG_ON(key != ctx->match_data); 1003 /* We might get a keyring with matching index-key that is nonetheless a
1004 * different keyring. */
1005 if (key != ctx->match_data)
1006 return 0;
1007
1004 ctx->result = ERR_PTR(-EDEADLK); 1008 ctx->result = ERR_PTR(-EDEADLK);
1005 return 1; 1009 return 1;
1006} 1010}
diff --git a/security/security.c b/security/security.c
index 15b6928592ef..919cad93ac82 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1317,9 +1317,11 @@ void security_skb_owned_by(struct sk_buff *skb, struct sock *sk)
1317 1317
1318#ifdef CONFIG_SECURITY_NETWORK_XFRM 1318#ifdef CONFIG_SECURITY_NETWORK_XFRM
1319 1319
1320int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx) 1320int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
1321 struct xfrm_user_sec_ctx *sec_ctx,
1322 gfp_t gfp)
1321{ 1323{
1322 return security_ops->xfrm_policy_alloc_security(ctxp, sec_ctx); 1324 return security_ops->xfrm_policy_alloc_security(ctxp, sec_ctx, gfp);
1323} 1325}
1324EXPORT_SYMBOL(security_xfrm_policy_alloc); 1326EXPORT_SYMBOL(security_xfrm_policy_alloc);
1325 1327
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 4b34847208cc..b332e2cc0954 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -668,7 +668,7 @@ static int selinux_set_mnt_opts(struct super_block *sb,
668 if (flags[i] == SBLABEL_MNT) 668 if (flags[i] == SBLABEL_MNT)
669 continue; 669 continue;
670 rc = security_context_to_sid(mount_options[i], 670 rc = security_context_to_sid(mount_options[i],
671 strlen(mount_options[i]), &sid); 671 strlen(mount_options[i]), &sid, GFP_KERNEL);
672 if (rc) { 672 if (rc) {
673 printk(KERN_WARNING "SELinux: security_context_to_sid" 673 printk(KERN_WARNING "SELinux: security_context_to_sid"
674 "(%s) failed for (dev %s, type %s) errno=%d\n", 674 "(%s) failed for (dev %s, type %s) errno=%d\n",
@@ -2489,7 +2489,8 @@ static int selinux_sb_remount(struct super_block *sb, void *data)
2489 if (flags[i] == SBLABEL_MNT) 2489 if (flags[i] == SBLABEL_MNT)
2490 continue; 2490 continue;
2491 len = strlen(mount_options[i]); 2491 len = strlen(mount_options[i]);
2492 rc = security_context_to_sid(mount_options[i], len, &sid); 2492 rc = security_context_to_sid(mount_options[i], len, &sid,
2493 GFP_KERNEL);
2493 if (rc) { 2494 if (rc) {
2494 printk(KERN_WARNING "SELinux: security_context_to_sid" 2495 printk(KERN_WARNING "SELinux: security_context_to_sid"
2495 "(%s) failed for (dev %s, type %s) errno=%d\n", 2496 "(%s) failed for (dev %s, type %s) errno=%d\n",
@@ -2893,7 +2894,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2893 if (rc) 2894 if (rc)
2894 return rc; 2895 return rc;
2895 2896
2896 rc = security_context_to_sid(value, size, &newsid); 2897 rc = security_context_to_sid(value, size, &newsid, GFP_KERNEL);
2897 if (rc == -EINVAL) { 2898 if (rc == -EINVAL) {
2898 if (!capable(CAP_MAC_ADMIN)) { 2899 if (!capable(CAP_MAC_ADMIN)) {
2899 struct audit_buffer *ab; 2900 struct audit_buffer *ab;
@@ -3050,7 +3051,7 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,
3050 if (!value || !size) 3051 if (!value || !size)
3051 return -EACCES; 3052 return -EACCES;
3052 3053
3053 rc = security_context_to_sid((void *)value, size, &newsid); 3054 rc = security_context_to_sid((void *)value, size, &newsid, GFP_KERNEL);
3054 if (rc) 3055 if (rc)
3055 return rc; 3056 return rc;
3056 3057
@@ -5529,7 +5530,7 @@ static int selinux_setprocattr(struct task_struct *p,
5529 str[size-1] = 0; 5530 str[size-1] = 0;
5530 size--; 5531 size--;
5531 } 5532 }
5532 error = security_context_to_sid(value, size, &sid); 5533 error = security_context_to_sid(value, size, &sid, GFP_KERNEL);
5533 if (error == -EINVAL && !strcmp(name, "fscreate")) { 5534 if (error == -EINVAL && !strcmp(name, "fscreate")) {
5534 if (!capable(CAP_MAC_ADMIN)) { 5535 if (!capable(CAP_MAC_ADMIN)) {
5535 struct audit_buffer *ab; 5536 struct audit_buffer *ab;
@@ -5638,7 +5639,7 @@ static int selinux_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
5638 5639
5639static int selinux_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) 5640static int selinux_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
5640{ 5641{
5641 return security_context_to_sid(secdata, seclen, secid); 5642 return security_context_to_sid(secdata, seclen, secid, GFP_KERNEL);
5642} 5643}
5643 5644
5644static void selinux_release_secctx(char *secdata, u32 seclen) 5645static void selinux_release_secctx(char *secdata, u32 seclen)
diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
index 8ed8daf7f1ee..ce7852cf526b 100644
--- a/security/selinux/include/security.h
+++ b/security/selinux/include/security.h
@@ -134,7 +134,7 @@ int security_sid_to_context(u32 sid, char **scontext,
134int security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len); 134int security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len);
135 135
136int security_context_to_sid(const char *scontext, u32 scontext_len, 136int security_context_to_sid(const char *scontext, u32 scontext_len,
137 u32 *out_sid); 137 u32 *out_sid, gfp_t gfp);
138 138
139int security_context_to_sid_default(const char *scontext, u32 scontext_len, 139int security_context_to_sid_default(const char *scontext, u32 scontext_len,
140 u32 *out_sid, u32 def_sid, gfp_t gfp_flags); 140 u32 *out_sid, u32 def_sid, gfp_t gfp_flags);
diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
index 48c3cc94c168..9f0584710c85 100644
--- a/security/selinux/include/xfrm.h
+++ b/security/selinux/include/xfrm.h
@@ -10,7 +10,8 @@
10#include <net/flow.h> 10#include <net/flow.h>
11 11
12int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, 12int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
13 struct xfrm_user_sec_ctx *uctx); 13 struct xfrm_user_sec_ctx *uctx,
14 gfp_t gfp);
14int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, 15int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
15 struct xfrm_sec_ctx **new_ctxp); 16 struct xfrm_sec_ctx **new_ctxp);
16void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx); 17void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c
index 332ac8a80cf5..2df7b900e259 100644
--- a/security/selinux/nlmsgtab.c
+++ b/security/selinux/nlmsgtab.c
@@ -17,6 +17,7 @@
17#include <linux/inet_diag.h> 17#include <linux/inet_diag.h>
18#include <linux/xfrm.h> 18#include <linux/xfrm.h>
19#include <linux/audit.h> 19#include <linux/audit.h>
20#include <linux/sock_diag.h>
20 21
21#include "flask.h" 22#include "flask.h"
22#include "av_permissions.h" 23#include "av_permissions.h"
@@ -78,6 +79,7 @@ static struct nlmsg_perm nlmsg_tcpdiag_perms[] =
78{ 79{
79 { TCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, 80 { TCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ },
80 { DCCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, 81 { DCCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ },
82 { SOCK_DIAG_BY_FAMILY, NETLINK_TCPDIAG_SOCKET__NLMSG_READ },
81}; 83};
82 84
83static struct nlmsg_perm nlmsg_xfrm_perms[] = 85static struct nlmsg_perm nlmsg_xfrm_perms[] =
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 5122affe06a8..d60c0ee66387 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -576,7 +576,7 @@ static ssize_t sel_write_context(struct file *file, char *buf, size_t size)
576 if (length) 576 if (length)
577 goto out; 577 goto out;
578 578
579 length = security_context_to_sid(buf, size, &sid); 579 length = security_context_to_sid(buf, size, &sid, GFP_KERNEL);
580 if (length) 580 if (length)
581 goto out; 581 goto out;
582 582
@@ -731,11 +731,13 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)
731 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) 731 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
732 goto out; 732 goto out;
733 733
734 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid); 734 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid,
735 GFP_KERNEL);
735 if (length) 736 if (length)
736 goto out; 737 goto out;
737 738
738 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid); 739 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid,
740 GFP_KERNEL);
739 if (length) 741 if (length)
740 goto out; 742 goto out;
741 743
@@ -817,11 +819,13 @@ static ssize_t sel_write_create(struct file *file, char *buf, size_t size)
817 objname = namebuf; 819 objname = namebuf;
818 } 820 }
819 821
820 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid); 822 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid,
823 GFP_KERNEL);
821 if (length) 824 if (length)
822 goto out; 825 goto out;
823 826
824 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid); 827 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid,
828 GFP_KERNEL);
825 if (length) 829 if (length)
826 goto out; 830 goto out;
827 831
@@ -878,11 +882,13 @@ static ssize_t sel_write_relabel(struct file *file, char *buf, size_t size)
878 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) 882 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
879 goto out; 883 goto out;
880 884
881 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid); 885 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid,
886 GFP_KERNEL);
882 if (length) 887 if (length)
883 goto out; 888 goto out;
884 889
885 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid); 890 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid,
891 GFP_KERNEL);
886 if (length) 892 if (length)
887 goto out; 893 goto out;
888 894
@@ -934,7 +940,7 @@ static ssize_t sel_write_user(struct file *file, char *buf, size_t size)
934 if (sscanf(buf, "%s %s", con, user) != 2) 940 if (sscanf(buf, "%s %s", con, user) != 2)
935 goto out; 941 goto out;
936 942
937 length = security_context_to_sid(con, strlen(con) + 1, &sid); 943 length = security_context_to_sid(con, strlen(con) + 1, &sid, GFP_KERNEL);
938 if (length) 944 if (length)
939 goto out; 945 goto out;
940 946
@@ -994,11 +1000,13 @@ static ssize_t sel_write_member(struct file *file, char *buf, size_t size)
994 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) 1000 if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
995 goto out; 1001 goto out;
996 1002
997 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid); 1003 length = security_context_to_sid(scon, strlen(scon) + 1, &ssid,
1004 GFP_KERNEL);
998 if (length) 1005 if (length)
999 goto out; 1006 goto out;
1000 1007
1001 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid); 1008 length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid,
1009 GFP_KERNEL);
1002 if (length) 1010 if (length)
1003 goto out; 1011 goto out;
1004 1012
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index c0f498842129..9c5cdc2caaef 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -3338,10 +3338,10 @@ static int filename_write_helper(void *key, void *data, void *ptr)
3338 if (rc) 3338 if (rc)
3339 return rc; 3339 return rc;
3340 3340
3341 buf[0] = ft->stype; 3341 buf[0] = cpu_to_le32(ft->stype);
3342 buf[1] = ft->ttype; 3342 buf[1] = cpu_to_le32(ft->ttype);
3343 buf[2] = ft->tclass; 3343 buf[2] = cpu_to_le32(ft->tclass);
3344 buf[3] = otype->otype; 3344 buf[3] = cpu_to_le32(otype->otype);
3345 3345
3346 rc = put_entry(buf, sizeof(u32), 4, fp); 3346 rc = put_entry(buf, sizeof(u32), 4, fp);
3347 if (rc) 3347 if (rc)
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index c93c21127f0c..4bca49414a40 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1232,6 +1232,10 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
1232 struct context context; 1232 struct context context;
1233 int rc = 0; 1233 int rc = 0;
1234 1234
1235 /* An empty security context is never valid. */
1236 if (!scontext_len)
1237 return -EINVAL;
1238
1235 if (!ss_initialized) { 1239 if (!ss_initialized) {
1236 int i; 1240 int i;
1237 1241
@@ -1285,16 +1289,18 @@ out:
1285 * @scontext: security context 1289 * @scontext: security context
1286 * @scontext_len: length in bytes 1290 * @scontext_len: length in bytes
1287 * @sid: security identifier, SID 1291 * @sid: security identifier, SID
1292 * @gfp: context for the allocation
1288 * 1293 *
1289 * Obtains a SID associated with the security context that 1294 * Obtains a SID associated with the security context that
1290 * has the string representation specified by @scontext. 1295 * has the string representation specified by @scontext.
1291 * Returns -%EINVAL if the context is invalid, -%ENOMEM if insufficient 1296 * Returns -%EINVAL if the context is invalid, -%ENOMEM if insufficient
1292 * memory is available, or 0 on success. 1297 * memory is available, or 0 on success.
1293 */ 1298 */
1294int security_context_to_sid(const char *scontext, u32 scontext_len, u32 *sid) 1299int security_context_to_sid(const char *scontext, u32 scontext_len, u32 *sid,
1300 gfp_t gfp)
1295{ 1301{
1296 return security_context_to_sid_core(scontext, scontext_len, 1302 return security_context_to_sid_core(scontext, scontext_len,
1297 sid, SECSID_NULL, GFP_KERNEL, 0); 1303 sid, SECSID_NULL, gfp, 0);
1298} 1304}
1299 1305
1300/** 1306/**
diff --git a/security/selinux/xfrm.c b/security/selinux/xfrm.c
index 0462cb3ff0a7..98b042630a9e 100644
--- a/security/selinux/xfrm.c
+++ b/security/selinux/xfrm.c
@@ -78,7 +78,8 @@ static inline int selinux_authorizable_xfrm(struct xfrm_state *x)
78 * xfrm_user_sec_ctx context. 78 * xfrm_user_sec_ctx context.
79 */ 79 */
80static int selinux_xfrm_alloc_user(struct xfrm_sec_ctx **ctxp, 80static int selinux_xfrm_alloc_user(struct xfrm_sec_ctx **ctxp,
81 struct xfrm_user_sec_ctx *uctx) 81 struct xfrm_user_sec_ctx *uctx,
82 gfp_t gfp)
82{ 83{
83 int rc; 84 int rc;
84 const struct task_security_struct *tsec = current_security(); 85 const struct task_security_struct *tsec = current_security();
@@ -94,7 +95,7 @@ static int selinux_xfrm_alloc_user(struct xfrm_sec_ctx **ctxp,
94 if (str_len >= PAGE_SIZE) 95 if (str_len >= PAGE_SIZE)
95 return -ENOMEM; 96 return -ENOMEM;
96 97
97 ctx = kmalloc(sizeof(*ctx) + str_len + 1, GFP_KERNEL); 98 ctx = kmalloc(sizeof(*ctx) + str_len + 1, gfp);
98 if (!ctx) 99 if (!ctx)
99 return -ENOMEM; 100 return -ENOMEM;
100 101
@@ -103,7 +104,7 @@ static int selinux_xfrm_alloc_user(struct xfrm_sec_ctx **ctxp,
103 ctx->ctx_len = str_len; 104 ctx->ctx_len = str_len;
104 memcpy(ctx->ctx_str, &uctx[1], str_len); 105 memcpy(ctx->ctx_str, &uctx[1], str_len);
105 ctx->ctx_str[str_len] = '\0'; 106 ctx->ctx_str[str_len] = '\0';
106 rc = security_context_to_sid(ctx->ctx_str, str_len, &ctx->ctx_sid); 107 rc = security_context_to_sid(ctx->ctx_str, str_len, &ctx->ctx_sid, gfp);
107 if (rc) 108 if (rc)
108 goto err; 109 goto err;
109 110
@@ -282,9 +283,10 @@ int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid)
282 * LSM hook implementation that allocs and transfers uctx spec to xfrm_policy. 283 * LSM hook implementation that allocs and transfers uctx spec to xfrm_policy.
283 */ 284 */
284int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, 285int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
285 struct xfrm_user_sec_ctx *uctx) 286 struct xfrm_user_sec_ctx *uctx,
287 gfp_t gfp)
286{ 288{
287 return selinux_xfrm_alloc_user(ctxp, uctx); 289 return selinux_xfrm_alloc_user(ctxp, uctx, gfp);
288} 290}
289 291
290/* 292/*
@@ -332,7 +334,7 @@ int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
332int selinux_xfrm_state_alloc(struct xfrm_state *x, 334int selinux_xfrm_state_alloc(struct xfrm_state *x,
333 struct xfrm_user_sec_ctx *uctx) 335 struct xfrm_user_sec_ctx *uctx)
334{ 336{
335 return selinux_xfrm_alloc_user(&x->security, uctx); 337 return selinux_xfrm_alloc_user(&x->security, uctx, GFP_KERNEL);
336} 338}
337 339
338/* 340/*
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 7a20897d33db..7403f348ed14 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -133,7 +133,7 @@ static int snd_compr_open(struct inode *inode, struct file *f)
133 kfree(data); 133 kfree(data);
134 } 134 }
135 snd_card_unref(compr->card); 135 snd_card_unref(compr->card);
136 return 0; 136 return ret;
137} 137}
138 138
139static int snd_compr_free(struct inode *inode, struct file *f) 139static int snd_compr_free(struct inode *inode, struct file *f)
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index ec4536c8d8d4..dafcf82139e2 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -932,7 +932,7 @@ int snd_hda_bus_new(struct snd_card *card,
932} 932}
933EXPORT_SYMBOL_GPL(snd_hda_bus_new); 933EXPORT_SYMBOL_GPL(snd_hda_bus_new);
934 934
935#ifdef CONFIG_SND_HDA_GENERIC 935#if IS_ENABLED(CONFIG_SND_HDA_GENERIC)
936#define is_generic_config(codec) \ 936#define is_generic_config(codec) \
937 (codec->modelname && !strcmp(codec->modelname, "generic")) 937 (codec->modelname && !strcmp(codec->modelname, "generic"))
938#else 938#else
@@ -1339,23 +1339,15 @@ get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid)
1339/* 1339/*
1340 * Dynamic symbol binding for the codec parsers 1340 * Dynamic symbol binding for the codec parsers
1341 */ 1341 */
1342#ifdef MODULE
1343#define load_parser_sym(sym) ((int (*)(struct hda_codec *))symbol_request(sym))
1344#define unload_parser_addr(addr) symbol_put_addr(addr)
1345#else
1346#define load_parser_sym(sym) (sym)
1347#define unload_parser_addr(addr) do {} while (0)
1348#endif
1349 1342
1350#define load_parser(codec, sym) \ 1343#define load_parser(codec, sym) \
1351 ((codec)->parser = load_parser_sym(sym)) 1344 ((codec)->parser = (int (*)(struct hda_codec *))symbol_request(sym))
1352 1345
1353static void unload_parser(struct hda_codec *codec) 1346static void unload_parser(struct hda_codec *codec)
1354{ 1347{
1355 if (codec->parser) { 1348 if (codec->parser)
1356 unload_parser_addr(codec->parser); 1349 symbol_put_addr(codec->parser);
1357 codec->parser = NULL; 1350 codec->parser = NULL;
1358 }
1359} 1351}
1360 1352
1361/* 1353/*
@@ -1570,7 +1562,7 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec)
1570EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets); 1562EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets);
1571 1563
1572 1564
1573#ifdef CONFIG_SND_HDA_CODEC_HDMI 1565#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
1574/* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */ 1566/* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */
1575static bool is_likely_hdmi_codec(struct hda_codec *codec) 1567static bool is_likely_hdmi_codec(struct hda_codec *codec)
1576{ 1568{
@@ -1620,12 +1612,20 @@ int snd_hda_codec_configure(struct hda_codec *codec)
1620 patch = codec->preset->patch; 1612 patch = codec->preset->patch;
1621 if (!patch) { 1613 if (!patch) {
1622 unload_parser(codec); /* to be sure */ 1614 unload_parser(codec); /* to be sure */
1623 if (is_likely_hdmi_codec(codec)) 1615 if (is_likely_hdmi_codec(codec)) {
1616#if IS_MODULE(CONFIG_SND_HDA_CODEC_HDMI)
1624 patch = load_parser(codec, snd_hda_parse_hdmi_codec); 1617 patch = load_parser(codec, snd_hda_parse_hdmi_codec);
1625#ifdef CONFIG_SND_HDA_GENERIC 1618#elif IS_BUILTIN(CONFIG_SND_HDA_CODEC_HDMI)
1626 if (!patch) 1619 patch = snd_hda_parse_hdmi_codec;
1620#endif
1621 }
1622 if (!patch) {
1623#if IS_MODULE(CONFIG_SND_HDA_GENERIC)
1627 patch = load_parser(codec, snd_hda_parse_generic_codec); 1624 patch = load_parser(codec, snd_hda_parse_generic_codec);
1625#elif IS_BUILTIN(CONFIG_SND_HDA_GENERIC)
1626 patch = snd_hda_parse_generic_codec;
1628#endif 1627#endif
1628 }
1629 if (!patch) { 1629 if (!patch) {
1630 printk(KERN_ERR "hda-codec: No codec parser is available\n"); 1630 printk(KERN_ERR "hda-codec: No codec parser is available\n");
1631 return -ENODEV; 1631 return -ENODEV;
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 8321a97d5c05..d9a09bdd09db 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -3269,7 +3269,7 @@ static int cap_put_caller(struct snd_kcontrol *kcontrol,
3269 mutex_unlock(&codec->control_mutex); 3269 mutex_unlock(&codec->control_mutex);
3270 snd_hda_codec_flush_cache(codec); /* flush the updates */ 3270 snd_hda_codec_flush_cache(codec); /* flush the updates */
3271 if (err >= 0 && spec->cap_sync_hook) 3271 if (err >= 0 && spec->cap_sync_hook)
3272 spec->cap_sync_hook(codec, ucontrol); 3272 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3273 return err; 3273 return err;
3274} 3274}
3275 3275
@@ -3390,7 +3390,7 @@ static int cap_single_sw_put(struct snd_kcontrol *kcontrol,
3390 return ret; 3390 return ret;
3391 3391
3392 if (spec->cap_sync_hook) 3392 if (spec->cap_sync_hook)
3393 spec->cap_sync_hook(codec, ucontrol); 3393 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3394 3394
3395 return ret; 3395 return ret;
3396} 3396}
@@ -3795,7 +3795,7 @@ static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3795 return 0; 3795 return 0;
3796 snd_hda_activate_path(codec, path, true, false); 3796 snd_hda_activate_path(codec, path, true, false);
3797 if (spec->cap_sync_hook) 3797 if (spec->cap_sync_hook)
3798 spec->cap_sync_hook(codec, NULL); 3798 spec->cap_sync_hook(codec, NULL, NULL);
3799 path_power_down_sync(codec, old_path); 3799 path_power_down_sync(codec, old_path);
3800 return 1; 3800 return 1;
3801} 3801}
@@ -5270,7 +5270,7 @@ static void init_input_src(struct hda_codec *codec)
5270 } 5270 }
5271 5271
5272 if (spec->cap_sync_hook) 5272 if (spec->cap_sync_hook)
5273 spec->cap_sync_hook(codec, NULL); 5273 spec->cap_sync_hook(codec, NULL, NULL);
5274} 5274}
5275 5275
5276/* set right pin controls for digital I/O */ 5276/* set right pin controls for digital I/O */
diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h
index 07f767231c9f..c908afbe4d94 100644
--- a/sound/pci/hda/hda_generic.h
+++ b/sound/pci/hda/hda_generic.h
@@ -274,6 +274,7 @@ struct hda_gen_spec {
274 void (*init_hook)(struct hda_codec *codec); 274 void (*init_hook)(struct hda_codec *codec);
275 void (*automute_hook)(struct hda_codec *codec); 275 void (*automute_hook)(struct hda_codec *codec);
276 void (*cap_sync_hook)(struct hda_codec *codec, 276 void (*cap_sync_hook)(struct hda_codec *codec,
277 struct snd_kcontrol *kcontrol,
277 struct snd_ctl_elem_value *ucontrol); 278 struct snd_ctl_elem_value *ucontrol);
278 279
279 /* PCM hooks */ 280 /* PCM hooks */
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index fa2879a21a50..e354ab1ec20f 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -198,7 +198,7 @@ MODULE_DESCRIPTION("Intel HDA driver");
198#endif 198#endif
199 199
200#if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO) 200#if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO)
201#ifdef CONFIG_SND_HDA_CODEC_HDMI 201#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
202#define SUPPORT_VGA_SWITCHEROO 202#define SUPPORT_VGA_SWITCHEROO
203#endif 203#endif
204#endif 204#endif
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 7a426ed491f2..8ed0bcc01386 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -244,6 +244,19 @@ static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
244 } 244 }
245} 245}
246 246
247/* Toshiba Satellite L40 implements EAPD in a standard way unlike others */
248static void ad1986a_fixup_eapd(struct hda_codec *codec,
249 const struct hda_fixup *fix, int action)
250{
251 struct ad198x_spec *spec = codec->spec;
252
253 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
254 codec->inv_eapd = 0;
255 spec->gen.keep_eapd_on = 1;
256 spec->eapd_nid = 0x1b;
257 }
258}
259
247enum { 260enum {
248 AD1986A_FIXUP_INV_JACK_DETECT, 261 AD1986A_FIXUP_INV_JACK_DETECT,
249 AD1986A_FIXUP_ULTRA, 262 AD1986A_FIXUP_ULTRA,
@@ -251,6 +264,7 @@ enum {
251 AD1986A_FIXUP_3STACK, 264 AD1986A_FIXUP_3STACK,
252 AD1986A_FIXUP_LAPTOP, 265 AD1986A_FIXUP_LAPTOP,
253 AD1986A_FIXUP_LAPTOP_IMIC, 266 AD1986A_FIXUP_LAPTOP_IMIC,
267 AD1986A_FIXUP_EAPD,
254}; 268};
255 269
256static const struct hda_fixup ad1986a_fixups[] = { 270static const struct hda_fixup ad1986a_fixups[] = {
@@ -311,6 +325,10 @@ static const struct hda_fixup ad1986a_fixups[] = {
311 .chained_before = 1, 325 .chained_before = 1,
312 .chain_id = AD1986A_FIXUP_LAPTOP, 326 .chain_id = AD1986A_FIXUP_LAPTOP,
313 }, 327 },
328 [AD1986A_FIXUP_EAPD] = {
329 .type = HDA_FIXUP_FUNC,
330 .v.func = ad1986a_fixup_eapd,
331 },
314}; 332};
315 333
316static const struct snd_pci_quirk ad1986a_fixup_tbl[] = { 334static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
@@ -318,6 +336,7 @@ static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
318 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK), 336 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
319 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK), 337 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
320 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK), 338 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
339 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD),
321 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP), 340 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
322 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG), 341 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
323 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA), 342 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
@@ -472,6 +491,8 @@ static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
472static int patch_ad1983(struct hda_codec *codec) 491static int patch_ad1983(struct hda_codec *codec)
473{ 492{
474 struct ad198x_spec *spec; 493 struct ad198x_spec *spec;
494 static hda_nid_t conn_0c[] = { 0x08 };
495 static hda_nid_t conn_0d[] = { 0x09 };
475 int err; 496 int err;
476 497
477 err = alloc_ad_spec(codec); 498 err = alloc_ad_spec(codec);
@@ -479,8 +500,14 @@ static int patch_ad1983(struct hda_codec *codec)
479 return err; 500 return err;
480 spec = codec->spec; 501 spec = codec->spec;
481 502
503 spec->gen.mixer_nid = 0x0e;
482 spec->gen.beep_nid = 0x10; 504 spec->gen.beep_nid = 0x10;
483 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 505 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
506
507 /* limit the loopback routes not to confuse the parser */
508 snd_hda_override_conn_list(codec, 0x0c, ARRAY_SIZE(conn_0c), conn_0c);
509 snd_hda_override_conn_list(codec, 0x0d, ARRAY_SIZE(conn_0d), conn_0d);
510
484 err = ad198x_parse_auto_config(codec, false); 511 err = ad198x_parse_auto_config(codec, false);
485 if (err < 0) 512 if (err < 0)
486 goto error; 513 goto error;
@@ -999,6 +1026,9 @@ static void ad1884_fixup_thinkpad(struct hda_codec *codec,
999 spec->gen.keep_eapd_on = 1; 1026 spec->gen.keep_eapd_on = 1;
1000 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook; 1027 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1001 spec->eapd_nid = 0x12; 1028 spec->eapd_nid = 0x12;
1029 /* Analog PC Beeper - allow firmware/ACPI beeps */
1030 spec->beep_amp = HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT);
1031 spec->gen.beep_nid = 0; /* no digital beep */
1002 } 1032 }
1003} 1033}
1004 1034
@@ -1065,6 +1095,7 @@ static int patch_ad1884(struct hda_codec *codec)
1065 spec = codec->spec; 1095 spec = codec->spec;
1066 1096
1067 spec->gen.mixer_nid = 0x20; 1097 spec->gen.mixer_nid = 0x20;
1098 spec->gen.mixer_merge_nid = 0x21;
1068 spec->gen.beep_nid = 0x10; 1099 spec->gen.beep_nid = 0x10;
1069 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 1100 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1070 1101
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 54d14793725a..46ecdbb9053f 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -2662,60 +2662,6 @@ static bool dspload_wait_loaded(struct hda_codec *codec)
2662} 2662}
2663 2663
2664/* 2664/*
2665 * PCM stuffs
2666 */
2667static void ca0132_setup_stream(struct hda_codec *codec, hda_nid_t nid,
2668 u32 stream_tag,
2669 int channel_id, int format)
2670{
2671 unsigned int oldval, newval;
2672
2673 if (!nid)
2674 return;
2675
2676 snd_printdd(
2677 "ca0132_setup_stream: NID=0x%x, stream=0x%x, "
2678 "channel=%d, format=0x%x\n",
2679 nid, stream_tag, channel_id, format);
2680
2681 /* update the format-id if changed */
2682 oldval = snd_hda_codec_read(codec, nid, 0,
2683 AC_VERB_GET_STREAM_FORMAT,
2684 0);
2685 if (oldval != format) {
2686 msleep(20);
2687 snd_hda_codec_write(codec, nid, 0,
2688 AC_VERB_SET_STREAM_FORMAT,
2689 format);
2690 }
2691
2692 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
2693 newval = (stream_tag << 4) | channel_id;
2694 if (oldval != newval) {
2695 snd_hda_codec_write(codec, nid, 0,
2696 AC_VERB_SET_CHANNEL_STREAMID,
2697 newval);
2698 }
2699}
2700
2701static void ca0132_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
2702{
2703 unsigned int val;
2704
2705 if (!nid)
2706 return;
2707
2708 snd_printdd(KERN_INFO "ca0132_cleanup_stream: NID=0x%x\n", nid);
2709
2710 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
2711 if (!val)
2712 return;
2713
2714 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
2715 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2716}
2717
2718/*
2719 * PCM callbacks 2665 * PCM callbacks
2720 */ 2666 */
2721static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2667static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -2726,7 +2672,7 @@ static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2726{ 2672{
2727 struct ca0132_spec *spec = codec->spec; 2673 struct ca0132_spec *spec = codec->spec;
2728 2674
2729 ca0132_setup_stream(codec, spec->dacs[0], stream_tag, 0, format); 2675 snd_hda_codec_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
2730 2676
2731 return 0; 2677 return 0;
2732} 2678}
@@ -2745,7 +2691,7 @@ static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2745 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]) 2691 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
2746 msleep(50); 2692 msleep(50);
2747 2693
2748 ca0132_cleanup_stream(codec, spec->dacs[0]); 2694 snd_hda_codec_cleanup_stream(codec, spec->dacs[0]);
2749 2695
2750 return 0; 2696 return 0;
2751} 2697}
@@ -2822,10 +2768,8 @@ static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2822 unsigned int format, 2768 unsigned int format,
2823 struct snd_pcm_substream *substream) 2769 struct snd_pcm_substream *substream)
2824{ 2770{
2825 struct ca0132_spec *spec = codec->spec; 2771 snd_hda_codec_setup_stream(codec, hinfo->nid,
2826 2772 stream_tag, 0, format);
2827 ca0132_setup_stream(codec, spec->adcs[substream->number],
2828 stream_tag, 0, format);
2829 2773
2830 return 0; 2774 return 0;
2831} 2775}
@@ -2839,7 +2783,7 @@ static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2839 if (spec->dsp_state == DSP_DOWNLOADING) 2783 if (spec->dsp_state == DSP_DOWNLOADING)
2840 return 0; 2784 return 0;
2841 2785
2842 ca0132_cleanup_stream(codec, hinfo->nid); 2786 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2843 return 0; 2787 return 0;
2844} 2788}
2845 2789
@@ -4742,6 +4686,8 @@ static int patch_ca0132(struct hda_codec *codec)
4742 return err; 4686 return err;
4743 4687
4744 codec->patch_ops = ca0132_patch_ops; 4688 codec->patch_ops = ca0132_patch_ops;
4689 codec->pcm_format_first = 1;
4690 codec->no_sticky_stream = 1;
4745 4691
4746 return 0; 4692 return 0;
4747} 4693}
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 4e0ec146553d..bcf91bea3317 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -3291,7 +3291,8 @@ static void cxt_update_headset_mode(struct hda_codec *codec)
3291} 3291}
3292 3292
3293static void cxt_update_headset_mode_hook(struct hda_codec *codec, 3293static void cxt_update_headset_mode_hook(struct hda_codec *codec,
3294 struct snd_ctl_elem_value *ucontrol) 3294 struct snd_kcontrol *kcontrol,
3295 struct snd_ctl_elem_value *ucontrol)
3295{ 3296{
3296 cxt_update_headset_mode(codec); 3297 cxt_update_headset_mode(codec);
3297} 3298}
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 56a8f1876603..8d0a84436674 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -708,7 +708,8 @@ static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
708} 708}
709 709
710static void alc_inv_dmic_hook(struct hda_codec *codec, 710static void alc_inv_dmic_hook(struct hda_codec *codec,
711 struct snd_ctl_elem_value *ucontrol) 711 struct snd_kcontrol *kcontrol,
712 struct snd_ctl_elem_value *ucontrol)
712{ 713{
713 alc_inv_dmic_sync(codec, false); 714 alc_inv_dmic_sync(codec, false);
714} 715}
@@ -1821,6 +1822,7 @@ enum {
1821 ALC889_FIXUP_IMAC91_VREF, 1822 ALC889_FIXUP_IMAC91_VREF,
1822 ALC889_FIXUP_MBA11_VREF, 1823 ALC889_FIXUP_MBA11_VREF,
1823 ALC889_FIXUP_MBA21_VREF, 1824 ALC889_FIXUP_MBA21_VREF,
1825 ALC889_FIXUP_MP11_VREF,
1824 ALC882_FIXUP_INV_DMIC, 1826 ALC882_FIXUP_INV_DMIC,
1825 ALC882_FIXUP_NO_PRIMARY_HP, 1827 ALC882_FIXUP_NO_PRIMARY_HP,
1826 ALC887_FIXUP_ASUS_BASS, 1828 ALC887_FIXUP_ASUS_BASS,
@@ -2190,6 +2192,12 @@ static const struct hda_fixup alc882_fixups[] = {
2190 .chained = true, 2192 .chained = true,
2191 .chain_id = ALC889_FIXUP_MBP_VREF, 2193 .chain_id = ALC889_FIXUP_MBP_VREF,
2192 }, 2194 },
2195 [ALC889_FIXUP_MP11_VREF] = {
2196 .type = HDA_FIXUP_FUNC,
2197 .v.func = alc889_fixup_mba11_vref,
2198 .chained = true,
2199 .chain_id = ALC885_FIXUP_MACPRO_GPIO,
2200 },
2193 [ALC882_FIXUP_INV_DMIC] = { 2201 [ALC882_FIXUP_INV_DMIC] = {
2194 .type = HDA_FIXUP_FUNC, 2202 .type = HDA_FIXUP_FUNC,
2195 .v.func = alc_fixup_inv_dmic_0x12, 2203 .v.func = alc_fixup_inv_dmic_0x12,
@@ -2253,7 +2261,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
2253 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF), 2261 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
2254 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF), 2262 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
2255 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF), 2263 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
2256 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO), 2264 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC889_FIXUP_MP11_VREF),
2257 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO), 2265 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
2258 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO), 2266 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
2259 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF), 2267 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
@@ -3211,7 +3219,8 @@ static void alc269_fixup_hp_gpio_mute_hook(void *private_data, int enabled)
3211 3219
3212/* turn on/off mic-mute LED per capture hook */ 3220/* turn on/off mic-mute LED per capture hook */
3213static void alc269_fixup_hp_gpio_mic_mute_hook(struct hda_codec *codec, 3221static void alc269_fixup_hp_gpio_mic_mute_hook(struct hda_codec *codec,
3214 struct snd_ctl_elem_value *ucontrol) 3222 struct snd_kcontrol *kcontrol,
3223 struct snd_ctl_elem_value *ucontrol)
3215{ 3224{
3216 struct alc_spec *spec = codec->spec; 3225 struct alc_spec *spec = codec->spec;
3217 unsigned int oldval = spec->gpio_led; 3226 unsigned int oldval = spec->gpio_led;
@@ -3521,7 +3530,8 @@ static void alc_update_headset_mode(struct hda_codec *codec)
3521} 3530}
3522 3531
3523static void alc_update_headset_mode_hook(struct hda_codec *codec, 3532static void alc_update_headset_mode_hook(struct hda_codec *codec,
3524 struct snd_ctl_elem_value *ucontrol) 3533 struct snd_kcontrol *kcontrol,
3534 struct snd_ctl_elem_value *ucontrol)
3525{ 3535{
3526 alc_update_headset_mode(codec); 3536 alc_update_headset_mode(codec);
3527} 3537}
@@ -3606,6 +3616,19 @@ static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec,
3606 } 3616 }
3607} 3617}
3608 3618
3619static void alc_no_shutup(struct hda_codec *codec)
3620{
3621}
3622
3623static void alc_fixup_no_shutup(struct hda_codec *codec,
3624 const struct hda_fixup *fix, int action)
3625{
3626 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3627 struct alc_spec *spec = codec->spec;
3628 spec->shutup = alc_no_shutup;
3629 }
3630}
3631
3609static void alc_fixup_headset_mode_alc668(struct hda_codec *codec, 3632static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
3610 const struct hda_fixup *fix, int action) 3633 const struct hda_fixup *fix, int action)
3611{ 3634{
@@ -3834,6 +3857,7 @@ enum {
3834 ALC269_FIXUP_HP_GPIO_LED, 3857 ALC269_FIXUP_HP_GPIO_LED,
3835 ALC269_FIXUP_INV_DMIC, 3858 ALC269_FIXUP_INV_DMIC,
3836 ALC269_FIXUP_LENOVO_DOCK, 3859 ALC269_FIXUP_LENOVO_DOCK,
3860 ALC269_FIXUP_NO_SHUTUP,
3837 ALC286_FIXUP_SONY_MIC_NO_PRESENCE, 3861 ALC286_FIXUP_SONY_MIC_NO_PRESENCE,
3838 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT, 3862 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
3839 ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, 3863 ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
@@ -4010,6 +4034,10 @@ static const struct hda_fixup alc269_fixups[] = {
4010 .type = HDA_FIXUP_FUNC, 4034 .type = HDA_FIXUP_FUNC,
4011 .v.func = alc_fixup_inv_dmic_0x12, 4035 .v.func = alc_fixup_inv_dmic_0x12,
4012 }, 4036 },
4037 [ALC269_FIXUP_NO_SHUTUP] = {
4038 .type = HDA_FIXUP_FUNC,
4039 .v.func = alc_fixup_no_shutup,
4040 },
4013 [ALC269_FIXUP_LENOVO_DOCK] = { 4041 [ALC269_FIXUP_LENOVO_DOCK] = {
4014 .type = HDA_FIXUP_PINS, 4042 .type = HDA_FIXUP_PINS,
4015 .v.pins = (const struct hda_pintbl[]) { 4043 .v.pins = (const struct hda_pintbl[]) {
@@ -4243,6 +4271,7 @@ static const struct hda_fixup alc269_fixups[] = {
4243}; 4271};
4244 4272
4245static const struct snd_pci_quirk alc269_fixup_tbl[] = { 4273static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4274 SND_PCI_QUIRK(0x1025, 0x0283, "Acer TravelMate 8371", ALC269_FIXUP_INV_DMIC),
4246 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC), 4275 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
4247 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC), 4276 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
4248 SND_PCI_QUIRK(0x1025, 0x047c, "Acer AC700", ALC269_FIXUP_ACER_AC700), 4277 SND_PCI_QUIRK(0x1025, 0x047c, "Acer AC700", ALC269_FIXUP_ACER_AC700),
@@ -4298,7 +4327,9 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4298 SND_PCI_QUIRK(0x1028, 0x0651, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE), 4327 SND_PCI_QUIRK(0x1028, 0x0651, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4299 SND_PCI_QUIRK(0x1028, 0x0652, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE), 4328 SND_PCI_QUIRK(0x1028, 0x0652, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4300 SND_PCI_QUIRK(0x1028, 0x0653, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE), 4329 SND_PCI_QUIRK(0x1028, 0x0653, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4330 SND_PCI_QUIRK(0x1028, 0x0657, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4301 SND_PCI_QUIRK(0x1028, 0x0658, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4331 SND_PCI_QUIRK(0x1028, 0x0658, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4332 SND_PCI_QUIRK(0x1028, 0x065f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4302 SND_PCI_QUIRK(0x1028, 0x0662, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE), 4333 SND_PCI_QUIRK(0x1028, 0x0662, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4303 SND_PCI_QUIRK(0x1028, 0x15cc, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE), 4334 SND_PCI_QUIRK(0x1028, 0x15cc, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
4304 SND_PCI_QUIRK(0x1028, 0x15cd, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE), 4335 SND_PCI_QUIRK(0x1028, 0x15cd, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
@@ -4307,6 +4338,54 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4307 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4338 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4308 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4339 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4309 SND_PCI_QUIRK(0x103c, 0x218b, "HP", ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED), 4340 SND_PCI_QUIRK(0x103c, 0x218b, "HP", ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED),
4341 /* ALC282 */
4342 SND_PCI_QUIRK(0x103c, 0x220f, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4343 SND_PCI_QUIRK(0x103c, 0x2213, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4344 SND_PCI_QUIRK(0x103c, 0x2266, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4345 SND_PCI_QUIRK(0x103c, 0x2267, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4346 SND_PCI_QUIRK(0x103c, 0x2268, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4347 SND_PCI_QUIRK(0x103c, 0x2269, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4348 SND_PCI_QUIRK(0x103c, 0x226a, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4349 SND_PCI_QUIRK(0x103c, 0x226b, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4350 SND_PCI_QUIRK(0x103c, 0x227a, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4351 SND_PCI_QUIRK(0x103c, 0x227b, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4352 SND_PCI_QUIRK(0x103c, 0x229e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4353 SND_PCI_QUIRK(0x103c, 0x22a0, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4354 SND_PCI_QUIRK(0x103c, 0x22b2, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4355 SND_PCI_QUIRK(0x103c, 0x22b7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4356 SND_PCI_QUIRK(0x103c, 0x22bf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4357 SND_PCI_QUIRK(0x103c, 0x22c0, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4358 SND_PCI_QUIRK(0x103c, 0x22c1, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4359 SND_PCI_QUIRK(0x103c, 0x22c2, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4360 SND_PCI_QUIRK(0x103c, 0x22cd, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4361 SND_PCI_QUIRK(0x103c, 0x22ce, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4362 SND_PCI_QUIRK(0x103c, 0x22cf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4363 SND_PCI_QUIRK(0x103c, 0x22d0, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4364 /* ALC290 */
4365 SND_PCI_QUIRK(0x103c, 0x2260, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4366 SND_PCI_QUIRK(0x103c, 0x2261, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4367 SND_PCI_QUIRK(0x103c, 0x2262, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4368 SND_PCI_QUIRK(0x103c, 0x2263, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4369 SND_PCI_QUIRK(0x103c, 0x2264, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4370 SND_PCI_QUIRK(0x103c, 0x2265, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4371 SND_PCI_QUIRK(0x103c, 0x227d, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4372 SND_PCI_QUIRK(0x103c, 0x227e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4373 SND_PCI_QUIRK(0x103c, 0x227f, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4374 SND_PCI_QUIRK(0x103c, 0x2280, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4375 SND_PCI_QUIRK(0x103c, 0x2281, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4376 SND_PCI_QUIRK(0x103c, 0x2282, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4377 SND_PCI_QUIRK(0x103c, 0x2289, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4378 SND_PCI_QUIRK(0x103c, 0x228a, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4379 SND_PCI_QUIRK(0x103c, 0x228b, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4380 SND_PCI_QUIRK(0x103c, 0x228c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4381 SND_PCI_QUIRK(0x103c, 0x228d, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4382 SND_PCI_QUIRK(0x103c, 0x228e, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4383 SND_PCI_QUIRK(0x103c, 0x22c5, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4384 SND_PCI_QUIRK(0x103c, 0x22c6, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4385 SND_PCI_QUIRK(0x103c, 0x22c7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4386 SND_PCI_QUIRK(0x103c, 0x22c8, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4387 SND_PCI_QUIRK(0x103c, 0x22c3, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4388 SND_PCI_QUIRK(0x103c, 0x22c4, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4310 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED), 4389 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
4311 SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300), 4390 SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300),
4312 SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4391 SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
@@ -4322,6 +4401,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4322 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), 4401 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4323 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), 4402 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4324 SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101), 4403 SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101),
4404 SND_PCI_QUIRK(0x104d, 0x90b5, "Sony VAIO Pro 11", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
4325 SND_PCI_QUIRK(0x104d, 0x90b6, "Sony VAIO Pro 13", ALC286_FIXUP_SONY_MIC_NO_PRESENCE), 4405 SND_PCI_QUIRK(0x104d, 0x90b6, "Sony VAIO Pro 13", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
4326 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), 4406 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4327 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), 4407 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
@@ -4343,6 +4423,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4343 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4423 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4344 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4424 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4345 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4425 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4426 SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP),
4346 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4427 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4347 SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC), 4428 SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC),
4348 SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4429 SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
@@ -5096,12 +5177,13 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5096 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), 5177 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5097 SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 5178 SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5098 SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 5179 SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5180 SND_PCI_QUIRK(0x1028, 0x060a, "Dell XPS 13", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5099 SND_PCI_QUIRK(0x1028, 0x0623, "Dell", ALC668_FIXUP_AUTO_MUTE), 5181 SND_PCI_QUIRK(0x1028, 0x0623, "Dell", ALC668_FIXUP_AUTO_MUTE),
5100 SND_PCI_QUIRK(0x1028, 0x0624, "Dell", ALC668_FIXUP_AUTO_MUTE), 5182 SND_PCI_QUIRK(0x1028, 0x0624, "Dell", ALC668_FIXUP_AUTO_MUTE),
5101 SND_PCI_QUIRK(0x1028, 0x0625, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 5183 SND_PCI_QUIRK(0x1028, 0x0625, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5102 SND_PCI_QUIRK(0x1028, 0x0626, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 5184 SND_PCI_QUIRK(0x1028, 0x0626, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
5103 SND_PCI_QUIRK(0x1028, 0x0628, "Dell", ALC668_FIXUP_AUTO_MUTE), 5185 SND_PCI_QUIRK(0x1028, 0x0628, "Dell", ALC668_FIXUP_AUTO_MUTE),
5104 SND_PCI_QUIRK(0x1028, 0x064e, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 5186 SND_PCI_QUIRK(0x1028, 0x064e, "Dell", ALC668_FIXUP_AUTO_MUTE),
5105 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), 5187 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5106 SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_BASS_1A_CHMAP), 5188 SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_BASS_1A_CHMAP),
5107 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_CHMAP), 5189 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_CHMAP),
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 6998cf29b9bc..3bc29c9b2529 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -83,6 +83,7 @@ enum {
83 STAC_DELL_M6_BOTH, 83 STAC_DELL_M6_BOTH,
84 STAC_DELL_EQ, 84 STAC_DELL_EQ,
85 STAC_ALIENWARE_M17X, 85 STAC_ALIENWARE_M17X,
86 STAC_92HD89XX_HP_FRONT_JACK,
86 STAC_92HD73XX_MODELS 87 STAC_92HD73XX_MODELS
87}; 88};
88 89
@@ -97,6 +98,7 @@ enum {
97 STAC_92HD83XXX_HP_LED, 98 STAC_92HD83XXX_HP_LED,
98 STAC_92HD83XXX_HP_INV_LED, 99 STAC_92HD83XXX_HP_INV_LED,
99 STAC_92HD83XXX_HP_MIC_LED, 100 STAC_92HD83XXX_HP_MIC_LED,
101 STAC_HP_LED_GPIO10,
100 STAC_92HD83XXX_HEADSET_JACK, 102 STAC_92HD83XXX_HEADSET_JACK,
101 STAC_92HD83XXX_HP, 103 STAC_92HD83XXX_HP,
102 STAC_HP_ENVY_BASS, 104 STAC_HP_ENVY_BASS,
@@ -194,7 +196,7 @@ struct sigmatel_spec {
194 int default_polarity; 196 int default_polarity;
195 197
196 unsigned int mic_mute_led_gpio; /* capture mute LED GPIO */ 198 unsigned int mic_mute_led_gpio; /* capture mute LED GPIO */
197 bool mic_mute_led_on; /* current mic mute state */ 199 unsigned int mic_enabled; /* current mic mute state (bitmask) */
198 200
199 /* stream */ 201 /* stream */
200 unsigned int stream_delay; 202 unsigned int stream_delay;
@@ -324,19 +326,26 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
324 326
325/* hook for controlling mic-mute LED GPIO */ 327/* hook for controlling mic-mute LED GPIO */
326static void stac_capture_led_hook(struct hda_codec *codec, 328static void stac_capture_led_hook(struct hda_codec *codec,
327 struct snd_ctl_elem_value *ucontrol) 329 struct snd_kcontrol *kcontrol,
330 struct snd_ctl_elem_value *ucontrol)
328{ 331{
329 struct sigmatel_spec *spec = codec->spec; 332 struct sigmatel_spec *spec = codec->spec;
330 bool mute; 333 unsigned int mask;
334 bool cur_mute, prev_mute;
331 335
332 if (!ucontrol) 336 if (!kcontrol || !ucontrol)
333 return; 337 return;
334 338
335 mute = !(ucontrol->value.integer.value[0] || 339 mask = 1U << snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
336 ucontrol->value.integer.value[1]); 340 prev_mute = !spec->mic_enabled;
337 if (spec->mic_mute_led_on != mute) { 341 if (ucontrol->value.integer.value[0] ||
338 spec->mic_mute_led_on = mute; 342 ucontrol->value.integer.value[1])
339 if (mute) 343 spec->mic_enabled |= mask;
344 else
345 spec->mic_enabled &= ~mask;
346 cur_mute = !spec->mic_enabled;
347 if (cur_mute != prev_mute) {
348 if (cur_mute)
340 spec->gpio_data |= spec->mic_mute_led_gpio; 349 spec->gpio_data |= spec->mic_mute_led_gpio;
341 else 350 else
342 spec->gpio_data &= ~spec->mic_mute_led_gpio; 351 spec->gpio_data &= ~spec->mic_mute_led_gpio;
@@ -1788,6 +1797,12 @@ static const struct hda_pintbl intel_dg45id_pin_configs[] = {
1788 {} 1797 {}
1789}; 1798};
1790 1799
1800static const struct hda_pintbl stac92hd89xx_hp_front_jack_pin_configs[] = {
1801 { 0x0a, 0x02214030 },
1802 { 0x0b, 0x02A19010 },
1803 {}
1804};
1805
1791static void stac92hd73xx_fixup_ref(struct hda_codec *codec, 1806static void stac92hd73xx_fixup_ref(struct hda_codec *codec,
1792 const struct hda_fixup *fix, int action) 1807 const struct hda_fixup *fix, int action)
1793{ 1808{
@@ -1906,6 +1921,10 @@ static const struct hda_fixup stac92hd73xx_fixups[] = {
1906 [STAC_92HD73XX_NO_JD] = { 1921 [STAC_92HD73XX_NO_JD] = {
1907 .type = HDA_FIXUP_FUNC, 1922 .type = HDA_FIXUP_FUNC,
1908 .v.func = stac92hd73xx_fixup_no_jd, 1923 .v.func = stac92hd73xx_fixup_no_jd,
1924 },
1925 [STAC_92HD89XX_HP_FRONT_JACK] = {
1926 .type = HDA_FIXUP_PINS,
1927 .v.pins = stac92hd89xx_hp_front_jack_pin_configs,
1909 } 1928 }
1910}; 1929};
1911 1930
@@ -1966,6 +1985,8 @@ static const struct snd_pci_quirk stac92hd73xx_fixup_tbl[] = {
1966 "Alienware M17x", STAC_ALIENWARE_M17X), 1985 "Alienware M17x", STAC_ALIENWARE_M17X),
1967 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490, 1986 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
1968 "Alienware M17x R3", STAC_DELL_EQ), 1987 "Alienware M17x R3", STAC_DELL_EQ),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2b17,
1989 "unknown HP", STAC_92HD89XX_HP_FRONT_JACK),
1969 {} /* terminator */ 1990 {} /* terminator */
1970}; 1991};
1971 1992
@@ -2110,6 +2131,17 @@ static void stac92hd83xxx_fixup_hp_mic_led(struct hda_codec *codec,
2110 } 2131 }
2111} 2132}
2112 2133
2134static void stac92hd83xxx_fixup_hp_led_gpio10(struct hda_codec *codec,
2135 const struct hda_fixup *fix, int action)
2136{
2137 struct sigmatel_spec *spec = codec->spec;
2138
2139 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2140 spec->gpio_led = 0x10; /* GPIO4 */
2141 spec->default_polarity = 0;
2142 }
2143}
2144
2113static void stac92hd83xxx_fixup_headset_jack(struct hda_codec *codec, 2145static void stac92hd83xxx_fixup_headset_jack(struct hda_codec *codec,
2114 const struct hda_fixup *fix, int action) 2146 const struct hda_fixup *fix, int action)
2115{ 2147{
@@ -2604,6 +2636,12 @@ static const struct hda_fixup stac92hd83xxx_fixups[] = {
2604 .chained = true, 2636 .chained = true,
2605 .chain_id = STAC_92HD83XXX_HP, 2637 .chain_id = STAC_92HD83XXX_HP,
2606 }, 2638 },
2639 [STAC_HP_LED_GPIO10] = {
2640 .type = HDA_FIXUP_FUNC,
2641 .v.func = stac92hd83xxx_fixup_hp_led_gpio10,
2642 .chained = true,
2643 .chain_id = STAC_92HD83XXX_HP,
2644 },
2607 [STAC_92HD83XXX_HEADSET_JACK] = { 2645 [STAC_92HD83XXX_HEADSET_JACK] = {
2608 .type = HDA_FIXUP_FUNC, 2646 .type = HDA_FIXUP_FUNC,
2609 .v.func = stac92hd83xxx_fixup_headset_jack, 2647 .v.func = stac92hd83xxx_fixup_headset_jack,
@@ -2682,6 +2720,8 @@ static const struct snd_pci_quirk stac92hd83xxx_fixup_tbl[] = {
2682 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD), 2720 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2683 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1888, 2721 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1888,
2684 "HP Envy Spectre", STAC_HP_ENVY_BASS), 2722 "HP Envy Spectre", STAC_HP_ENVY_BASS),
2723 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1899,
2724 "HP Folio 13", STAC_HP_LED_GPIO10),
2685 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df, 2725 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df,
2686 "HP Folio", STAC_HP_BNB13_EQ), 2726 "HP Folio", STAC_HP_BNB13_EQ),
2687 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18F8, 2727 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18F8,
@@ -4462,7 +4502,7 @@ static void stac_setup_gpio(struct hda_codec *codec)
4462 if (spec->mic_mute_led_gpio) { 4502 if (spec->mic_mute_led_gpio) {
4463 spec->gpio_mask |= spec->mic_mute_led_gpio; 4503 spec->gpio_mask |= spec->mic_mute_led_gpio;
4464 spec->gpio_dir |= spec->mic_mute_led_gpio; 4504 spec->gpio_dir |= spec->mic_mute_led_gpio;
4465 spec->mic_mute_led_on = true; 4505 spec->mic_enabled = 0;
4466 spec->gpio_data |= spec->mic_mute_led_gpio; 4506 spec->gpio_data |= spec->mic_mute_led_gpio;
4467 4507
4468 spec->gen.cap_sync_hook = stac_capture_led_hook; 4508 spec->gen.cap_sync_hook = stac_capture_led_hook;
diff --git a/sound/pci/hda/thinkpad_helper.c b/sound/pci/hda/thinkpad_helper.c
index 5799fbc24c28..8fe3b8c18ed4 100644
--- a/sound/pci/hda/thinkpad_helper.c
+++ b/sound/pci/hda/thinkpad_helper.c
@@ -39,6 +39,7 @@ static void update_tpacpi_mute_led(void *private_data, int enabled)
39} 39}
40 40
41static void update_tpacpi_micmute_led(struct hda_codec *codec, 41static void update_tpacpi_micmute_led(struct hda_codec *codec,
42 struct snd_kcontrol *kcontrol,
42 struct snd_ctl_elem_value *ucontrol) 43 struct snd_ctl_elem_value *ucontrol)
43{ 44{
44 if (!ucontrol || !led_set_func) 45 if (!ucontrol || !led_set_func)
diff --git a/sound/pci/oxygen/xonar_dg.c b/sound/pci/oxygen/xonar_dg.c
index ed6f199f8a38..4cf3200e988b 100644
--- a/sound/pci/oxygen/xonar_dg.c
+++ b/sound/pci/oxygen/xonar_dg.c
@@ -238,11 +238,21 @@ void set_cs4245_adc_params(struct oxygen *chip,
238 cs4245_write_spi(chip, CS4245_MCLK_FREQ); 238 cs4245_write_spi(chip, CS4245_MCLK_FREQ);
239} 239}
240 240
241static inline unsigned int shift_bits(unsigned int value,
242 unsigned int shift_from,
243 unsigned int shift_to,
244 unsigned int mask)
245{
246 if (shift_from < shift_to)
247 return (value << (shift_to - shift_from)) & mask;
248 else
249 return (value >> (shift_from - shift_to)) & mask;
250}
251
241unsigned int adjust_dg_dac_routing(struct oxygen *chip, 252unsigned int adjust_dg_dac_routing(struct oxygen *chip,
242 unsigned int play_routing) 253 unsigned int play_routing)
243{ 254{
244 struct dg *data = chip->model_data; 255 struct dg *data = chip->model_data;
245 unsigned int routing = 0;
246 256
247 switch (data->output_sel) { 257 switch (data->output_sel) {
248 case PLAYBACK_DST_HP: 258 case PLAYBACK_DST_HP:
@@ -252,15 +262,23 @@ unsigned int adjust_dg_dac_routing(struct oxygen *chip,
252 OXYGEN_PLAY_MUTE67, OXYGEN_PLAY_MUTE_MASK); 262 OXYGEN_PLAY_MUTE67, OXYGEN_PLAY_MUTE_MASK);
253 break; 263 break;
254 case PLAYBACK_DST_MULTICH: 264 case PLAYBACK_DST_MULTICH:
255 routing = (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
256 (2 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
257 (1 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
258 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT);
259 oxygen_write8_masked(chip, OXYGEN_PLAY_ROUTING, 265 oxygen_write8_masked(chip, OXYGEN_PLAY_ROUTING,
260 OXYGEN_PLAY_MUTE01, OXYGEN_PLAY_MUTE_MASK); 266 OXYGEN_PLAY_MUTE01, OXYGEN_PLAY_MUTE_MASK);
261 break; 267 break;
262 } 268 }
263 return routing; 269 return (play_routing & OXYGEN_PLAY_DAC0_SOURCE_MASK) |
270 shift_bits(play_routing,
271 OXYGEN_PLAY_DAC2_SOURCE_SHIFT,
272 OXYGEN_PLAY_DAC1_SOURCE_SHIFT,
273 OXYGEN_PLAY_DAC1_SOURCE_MASK) |
274 shift_bits(play_routing,
275 OXYGEN_PLAY_DAC1_SOURCE_SHIFT,
276 OXYGEN_PLAY_DAC2_SOURCE_SHIFT,
277 OXYGEN_PLAY_DAC2_SOURCE_MASK) |
278 shift_bits(play_routing,
279 OXYGEN_PLAY_DAC0_SOURCE_SHIFT,
280 OXYGEN_PLAY_DAC3_SOURCE_SHIFT,
281 OXYGEN_PLAY_DAC3_SOURCE_MASK);
264} 282}
265 283
266void dump_cs4245_registers(struct oxygen *chip, 284void dump_cs4245_registers(struct oxygen *chip,
diff --git a/sound/soc/blackfin/Kconfig b/sound/soc/blackfin/Kconfig
index 54f74f8cbb75..4544d8eb1452 100644
--- a/sound/soc/blackfin/Kconfig
+++ b/sound/soc/blackfin/Kconfig
@@ -11,7 +11,7 @@ config SND_BF5XX_I2S
11 11
12config SND_BF5XX_SOC_SSM2602 12config SND_BF5XX_SOC_SSM2602
13 tristate "SoC SSM2602 Audio Codec Add-On Card support" 13 tristate "SoC SSM2602 Audio Codec Add-On Card support"
14 depends on SND_BF5XX_I2S && (SPI_MASTER || I2C) 14 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI
15 select SND_BF5XX_SOC_I2S if !BF60x 15 select SND_BF5XX_SOC_I2S if !BF60x
16 select SND_BF6XX_SOC_I2S if BF60x 16 select SND_BF6XX_SOC_I2S if BF60x
17 select SND_SOC_SSM2602 17 select SND_SOC_SSM2602
@@ -21,10 +21,9 @@ config SND_BF5XX_SOC_SSM2602
21 21
22config SND_SOC_BFIN_EVAL_ADAU1701 22config SND_SOC_BFIN_EVAL_ADAU1701
23 tristate "Support for the EVAL-ADAU1701MINIZ board on Blackfin eval boards" 23 tristate "Support for the EVAL-ADAU1701MINIZ board on Blackfin eval boards"
24 depends on SND_BF5XX_I2S 24 depends on SND_BF5XX_I2S && I2C
25 select SND_BF5XX_SOC_I2S 25 select SND_BF5XX_SOC_I2S
26 select SND_SOC_ADAU1701 26 select SND_SOC_ADAU1701
27 select I2C
28 help 27 help
29 Say Y if you want to add support for the Analog Devices EVAL-ADAU1701MINIZ 28 Say Y if you want to add support for the Analog Devices EVAL-ADAU1701MINIZ
30 board connected to one of the Blackfin evaluation boards like the 29 board connected to one of the Blackfin evaluation boards like the
@@ -45,7 +44,7 @@ config SND_SOC_BFIN_EVAL_ADAU1373
45 44
46config SND_SOC_BFIN_EVAL_ADAV80X 45config SND_SOC_BFIN_EVAL_ADAV80X
47 tristate "Support for the EVAL-ADAV80X boards on Blackfin eval boards" 46 tristate "Support for the EVAL-ADAV80X boards on Blackfin eval boards"
48 depends on SND_BF5XX_I2S && (SPI_MASTER || I2C) 47 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI
49 select SND_BF5XX_SOC_I2S 48 select SND_BF5XX_SOC_I2S
50 select SND_SOC_ADAV80X 49 select SND_SOC_ADAV80X
51 help 50 help
@@ -58,7 +57,7 @@ config SND_SOC_BFIN_EVAL_ADAV80X
58 57
59config SND_BF5XX_SOC_AD1836 58config SND_BF5XX_SOC_AD1836
60 tristate "SoC AD1836 Audio support for BF5xx" 59 tristate "SoC AD1836 Audio support for BF5xx"
61 depends on SND_BF5XX_I2S 60 depends on SND_BF5XX_I2S && SPI_MASTER
62 select SND_BF5XX_SOC_I2S 61 select SND_BF5XX_SOC_I2S
63 select SND_SOC_AD1836 62 select SND_SOC_AD1836
64 help 63 help
@@ -66,7 +65,7 @@ config SND_BF5XX_SOC_AD1836
66 65
67config SND_BF5XX_SOC_AD193X 66config SND_BF5XX_SOC_AD193X
68 tristate "SoC AD193X Audio support for Blackfin" 67 tristate "SoC AD193X Audio support for Blackfin"
69 depends on SND_BF5XX_I2S 68 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI
70 select SND_BF5XX_SOC_I2S 69 select SND_BF5XX_SOC_I2S
71 select SND_SOC_AD193X 70 select SND_SOC_AD193X
72 help 71 help
diff --git a/sound/soc/codecs/88pm860x-codec.c b/sound/soc/codecs/88pm860x-codec.c
index 75d0ad5d2dcb..647a72cda005 100644
--- a/sound/soc/codecs/88pm860x-codec.c
+++ b/sound/soc/codecs/88pm860x-codec.c
@@ -1328,6 +1328,9 @@ static int pm860x_probe(struct snd_soc_codec *codec)
1328 pm860x->codec = codec; 1328 pm860x->codec = codec;
1329 1329
1330 codec->control_data = pm860x->regmap; 1330 codec->control_data = pm860x->regmap;
1331 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
1332 if (ret)
1333 return ret;
1331 1334
1332 for (i = 0; i < 4; i++) { 1335 for (i = 0; i < 4; i++) {
1333 ret = request_threaded_irq(pm860x->irq[i], NULL, 1336 ret = request_threaded_irq(pm860x->irq[i], NULL,
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c
index 7257a8885f42..34d965a4a040 100644
--- a/sound/soc/codecs/ad1980.c
+++ b/sound/soc/codecs/ad1980.c
@@ -57,8 +57,8 @@ static const u16 ad1980_reg[] = {
57static const char *ad1980_rec_sel[] = {"Mic", "CD", "NC", "AUX", "Line", 57static const char *ad1980_rec_sel[] = {"Mic", "CD", "NC", "AUX", "Line",
58 "Stereo Mix", "Mono Mix", "Phone"}; 58 "Stereo Mix", "Mono Mix", "Phone"};
59 59
60static const struct soc_enum ad1980_cap_src = 60static SOC_ENUM_DOUBLE_DECL(ad1980_cap_src,
61 SOC_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 7, ad1980_rec_sel); 61 AC97_REC_SEL, 8, 0, ad1980_rec_sel);
62 62
63static const struct snd_kcontrol_new ad1980_snd_ac97_controls[] = { 63static const struct snd_kcontrol_new ad1980_snd_ac97_controls[] = {
64SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1), 64SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1),
diff --git a/sound/soc/codecs/da732x.c b/sound/soc/codecs/da732x.c
index f295b6569910..f4d965ebc29e 100644
--- a/sound/soc/codecs/da732x.c
+++ b/sound/soc/codecs/da732x.c
@@ -1268,11 +1268,23 @@ static struct snd_soc_dai_driver da732x_dai[] = {
1268 }, 1268 },
1269}; 1269};
1270 1270
1271static bool da732x_volatile(struct device *dev, unsigned int reg)
1272{
1273 switch (reg) {
1274 case DA732X_REG_HPL_DAC_OFF_CNTL:
1275 case DA732X_REG_HPR_DAC_OFF_CNTL:
1276 return true;
1277 default:
1278 return false;
1279 }
1280}
1281
1271static const struct regmap_config da732x_regmap = { 1282static const struct regmap_config da732x_regmap = {
1272 .reg_bits = 8, 1283 .reg_bits = 8,
1273 .val_bits = 8, 1284 .val_bits = 8,
1274 1285
1275 .max_register = DA732X_MAX_REG, 1286 .max_register = DA732X_MAX_REG,
1287 .volatile_reg = da732x_volatile,
1276 .reg_defaults = da732x_reg_cache, 1288 .reg_defaults = da732x_reg_cache,
1277 .num_reg_defaults = ARRAY_SIZE(da732x_reg_cache), 1289 .num_reg_defaults = ARRAY_SIZE(da732x_reg_cache),
1278 .cache_type = REGCACHE_RBTREE, 1290 .cache_type = REGCACHE_RBTREE,
diff --git a/sound/soc/codecs/da9055.c b/sound/soc/codecs/da9055.c
index 52b79a487ac7..422812613a28 100644
--- a/sound/soc/codecs/da9055.c
+++ b/sound/soc/codecs/da9055.c
@@ -1523,8 +1523,15 @@ static int da9055_remove(struct i2c_client *client)
1523 return 0; 1523 return 0;
1524} 1524}
1525 1525
1526/*
1527 * DO NOT change the device Ids. The naming is intentionally specific as both
1528 * the CODEC and PMIC parts of this chip are instantiated separately as I2C
1529 * devices (both have configurable I2C addresses, and are to all intents and
1530 * purposes separate). As a result there are specific DA9055 Ids for CODEC
1531 * and PMIC, which must be different to operate together.
1532 */
1526static const struct i2c_device_id da9055_i2c_id[] = { 1533static const struct i2c_device_id da9055_i2c_id[] = {
1527 { "da9055", 0 }, 1534 { "da9055-codec", 0 },
1528 { } 1535 { }
1529}; 1536};
1530MODULE_DEVICE_TABLE(i2c, da9055_i2c_id); 1537MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
@@ -1532,7 +1539,7 @@ MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
1532/* I2C codec control layer */ 1539/* I2C codec control layer */
1533static struct i2c_driver da9055_i2c_driver = { 1540static struct i2c_driver da9055_i2c_driver = {
1534 .driver = { 1541 .driver = {
1535 .name = "da9055", 1542 .name = "da9055-codec",
1536 .owner = THIS_MODULE, 1543 .owner = THIS_MODULE,
1537 }, 1544 },
1538 .probe = da9055_i2c_probe, 1545 .probe = da9055_i2c_probe,
diff --git a/sound/soc/codecs/isabelle.c b/sound/soc/codecs/isabelle.c
index 5839048ec467..cb736ddc446d 100644
--- a/sound/soc/codecs/isabelle.c
+++ b/sound/soc/codecs/isabelle.c
@@ -140,13 +140,17 @@ static const char *isabelle_rx1_texts[] = {"VRX1", "ARX1"};
140static const char *isabelle_rx2_texts[] = {"VRX2", "ARX2"}; 140static const char *isabelle_rx2_texts[] = {"VRX2", "ARX2"};
141 141
142static const struct soc_enum isabelle_rx1_enum[] = { 142static const struct soc_enum isabelle_rx1_enum[] = {
143 SOC_ENUM_SINGLE(ISABELLE_VOICE_HPF_CFG_REG, 3, 1, isabelle_rx1_texts), 143 SOC_ENUM_SINGLE(ISABELLE_VOICE_HPF_CFG_REG, 3,
144 SOC_ENUM_SINGLE(ISABELLE_AUDIO_HPF_CFG_REG, 5, 1, isabelle_rx1_texts), 144 ARRAY_SIZE(isabelle_rx1_texts), isabelle_rx1_texts),
145 SOC_ENUM_SINGLE(ISABELLE_AUDIO_HPF_CFG_REG, 5,
146 ARRAY_SIZE(isabelle_rx1_texts), isabelle_rx1_texts),
145}; 147};
146 148
147static const struct soc_enum isabelle_rx2_enum[] = { 149static const struct soc_enum isabelle_rx2_enum[] = {
148 SOC_ENUM_SINGLE(ISABELLE_VOICE_HPF_CFG_REG, 2, 1, isabelle_rx2_texts), 150 SOC_ENUM_SINGLE(ISABELLE_VOICE_HPF_CFG_REG, 2,
149 SOC_ENUM_SINGLE(ISABELLE_AUDIO_HPF_CFG_REG, 4, 1, isabelle_rx2_texts), 151 ARRAY_SIZE(isabelle_rx2_texts), isabelle_rx2_texts),
152 SOC_ENUM_SINGLE(ISABELLE_AUDIO_HPF_CFG_REG, 4,
153 ARRAY_SIZE(isabelle_rx2_texts), isabelle_rx2_texts),
150}; 154};
151 155
152/* Headset DAC playback switches */ 156/* Headset DAC playback switches */
@@ -161,13 +165,17 @@ static const char *isabelle_atx_texts[] = {"AMIC1", "DMIC"};
161static const char *isabelle_vtx_texts[] = {"AMIC2", "DMIC"}; 165static const char *isabelle_vtx_texts[] = {"AMIC2", "DMIC"};
162 166
163static const struct soc_enum isabelle_atx_enum[] = { 167static const struct soc_enum isabelle_atx_enum[] = {
164 SOC_ENUM_SINGLE(ISABELLE_AMIC_CFG_REG, 7, 1, isabelle_atx_texts), 168 SOC_ENUM_SINGLE(ISABELLE_AMIC_CFG_REG, 7,
165 SOC_ENUM_SINGLE(ISABELLE_DMIC_CFG_REG, 0, 1, isabelle_atx_texts), 169 ARRAY_SIZE(isabelle_atx_texts), isabelle_atx_texts),
170 SOC_ENUM_SINGLE(ISABELLE_DMIC_CFG_REG, 0,
171 ARRAY_SIZE(isabelle_atx_texts), isabelle_atx_texts),
166}; 172};
167 173
168static const struct soc_enum isabelle_vtx_enum[] = { 174static const struct soc_enum isabelle_vtx_enum[] = {
169 SOC_ENUM_SINGLE(ISABELLE_AMIC_CFG_REG, 6, 1, isabelle_vtx_texts), 175 SOC_ENUM_SINGLE(ISABELLE_AMIC_CFG_REG, 6,
170 SOC_ENUM_SINGLE(ISABELLE_DMIC_CFG_REG, 0, 1, isabelle_vtx_texts), 176 ARRAY_SIZE(isabelle_vtx_texts), isabelle_vtx_texts),
177 SOC_ENUM_SINGLE(ISABELLE_DMIC_CFG_REG, 0,
178 ARRAY_SIZE(isabelle_vtx_texts), isabelle_vtx_texts),
171}; 179};
172 180
173static const struct snd_kcontrol_new atx_mux_controls = 181static const struct snd_kcontrol_new atx_mux_controls =
@@ -183,17 +191,13 @@ static const char *isabelle_amic1_texts[] = {
183/* Left analog microphone selection */ 191/* Left analog microphone selection */
184static const char *isabelle_amic2_texts[] = {"Sub Mic", "Aux/FM Right"}; 192static const char *isabelle_amic2_texts[] = {"Sub Mic", "Aux/FM Right"};
185 193
186static const struct soc_enum isabelle_amic1_enum[] = { 194static SOC_ENUM_SINGLE_DECL(isabelle_amic1_enum,
187 SOC_ENUM_SINGLE(ISABELLE_AMIC_CFG_REG, 5, 195 ISABELLE_AMIC_CFG_REG, 5,
188 ARRAY_SIZE(isabelle_amic1_texts), 196 isabelle_amic1_texts);
189 isabelle_amic1_texts),
190};
191 197
192static const struct soc_enum isabelle_amic2_enum[] = { 198static SOC_ENUM_SINGLE_DECL(isabelle_amic2_enum,
193 SOC_ENUM_SINGLE(ISABELLE_AMIC_CFG_REG, 4, 199 ISABELLE_AMIC_CFG_REG, 4,
194 ARRAY_SIZE(isabelle_amic2_texts), 200 isabelle_amic2_texts);
195 isabelle_amic2_texts),
196};
197 201
198static const struct snd_kcontrol_new amic1_control = 202static const struct snd_kcontrol_new amic1_control =
199 SOC_DAPM_ENUM("Route", isabelle_amic1_enum); 203 SOC_DAPM_ENUM("Route", isabelle_amic1_enum);
@@ -206,16 +210,20 @@ static const char *isabelle_st_audio_texts[] = {"ATX1", "ATX2"};
206static const char *isabelle_st_voice_texts[] = {"VTX1", "VTX2"}; 210static const char *isabelle_st_voice_texts[] = {"VTX1", "VTX2"};
207 211
208static const struct soc_enum isabelle_st_audio_enum[] = { 212static const struct soc_enum isabelle_st_audio_enum[] = {
209 SOC_ENUM_SINGLE(ISABELLE_ATX_STPGA1_CFG_REG, 7, 1, 213 SOC_ENUM_SINGLE(ISABELLE_ATX_STPGA1_CFG_REG, 7,
214 ARRAY_SIZE(isabelle_st_audio_texts),
210 isabelle_st_audio_texts), 215 isabelle_st_audio_texts),
211 SOC_ENUM_SINGLE(ISABELLE_ATX_STPGA2_CFG_REG, 7, 1, 216 SOC_ENUM_SINGLE(ISABELLE_ATX_STPGA2_CFG_REG, 7,
217 ARRAY_SIZE(isabelle_st_audio_texts),
212 isabelle_st_audio_texts), 218 isabelle_st_audio_texts),
213}; 219};
214 220
215static const struct soc_enum isabelle_st_voice_enum[] = { 221static const struct soc_enum isabelle_st_voice_enum[] = {
216 SOC_ENUM_SINGLE(ISABELLE_VTX_STPGA1_CFG_REG, 7, 1, 222 SOC_ENUM_SINGLE(ISABELLE_VTX_STPGA1_CFG_REG, 7,
223 ARRAY_SIZE(isabelle_st_voice_texts),
217 isabelle_st_voice_texts), 224 isabelle_st_voice_texts),
218 SOC_ENUM_SINGLE(ISABELLE_VTX2_STPGA2_CFG_REG, 7, 1, 225 SOC_ENUM_SINGLE(ISABELLE_VTX2_STPGA2_CFG_REG, 7,
226 ARRAY_SIZE(isabelle_st_voice_texts),
219 isabelle_st_voice_texts), 227 isabelle_st_voice_texts),
220}; 228};
221 229
diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c
index 51f9b3d16b41..9f714ea86613 100644
--- a/sound/soc/codecs/max98090.c
+++ b/sound/soc/codecs/max98090.c
@@ -336,6 +336,7 @@ static bool max98090_readable_register(struct device *dev, unsigned int reg)
336 case M98090_REG_RECORD_TDM_SLOT: 336 case M98090_REG_RECORD_TDM_SLOT:
337 case M98090_REG_SAMPLE_RATE: 337 case M98090_REG_SAMPLE_RATE:
338 case M98090_REG_DMIC34_BIQUAD_BASE ... M98090_REG_DMIC34_BIQUAD_BASE + 0x0E: 338 case M98090_REG_DMIC34_BIQUAD_BASE ... M98090_REG_DMIC34_BIQUAD_BASE + 0x0E:
339 case M98090_REG_REVISION_ID:
339 return true; 340 return true;
340 default: 341 default:
341 return false; 342 return false;
@@ -1769,16 +1770,6 @@ static int max98090_set_bias_level(struct snd_soc_codec *codec,
1769 1770
1770 switch (level) { 1771 switch (level) {
1771 case SND_SOC_BIAS_ON: 1772 case SND_SOC_BIAS_ON:
1772 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1773 ret = regcache_sync(max98090->regmap);
1774
1775 if (ret != 0) {
1776 dev_err(codec->dev,
1777 "Failed to sync cache: %d\n", ret);
1778 return ret;
1779 }
1780 }
1781
1782 if (max98090->jack_state == M98090_JACK_STATE_HEADSET) { 1773 if (max98090->jack_state == M98090_JACK_STATE_HEADSET) {
1783 /* 1774 /*
1784 * Set to normal bias level. 1775 * Set to normal bias level.
@@ -1792,6 +1783,16 @@ static int max98090_set_bias_level(struct snd_soc_codec *codec,
1792 break; 1783 break;
1793 1784
1794 case SND_SOC_BIAS_STANDBY: 1785 case SND_SOC_BIAS_STANDBY:
1786 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1787 ret = regcache_sync(max98090->regmap);
1788 if (ret != 0) {
1789 dev_err(codec->dev,
1790 "Failed to sync cache: %d\n", ret);
1791 return ret;
1792 }
1793 }
1794 break;
1795
1795 case SND_SOC_BIAS_OFF: 1796 case SND_SOC_BIAS_OFF:
1796 /* Set internal pull-up to lowest power mode */ 1797 /* Set internal pull-up to lowest power mode */
1797 snd_soc_update_bits(codec, M98090_REG_JACK_DETECT, 1798 snd_soc_update_bits(codec, M98090_REG_JACK_DETECT,
diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index a3fb41179636..886924934aa5 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -2093,6 +2093,7 @@ MODULE_DEVICE_TABLE(i2c, rt5640_i2c_id);
2093#ifdef CONFIG_ACPI 2093#ifdef CONFIG_ACPI
2094static struct acpi_device_id rt5640_acpi_match[] = { 2094static struct acpi_device_id rt5640_acpi_match[] = {
2095 { "INT33CA", 0 }, 2095 { "INT33CA", 0 },
2096 { "10EC5640", 0 },
2096 { }, 2097 { },
2097}; 2098};
2098MODULE_DEVICE_TABLE(acpi, rt5640_acpi_match); 2099MODULE_DEVICE_TABLE(acpi, rt5640_acpi_match);
diff --git a/sound/soc/codecs/si476x.c b/sound/soc/codecs/si476x.c
index 52e7cb08434b..fa2b8e07f420 100644
--- a/sound/soc/codecs/si476x.c
+++ b/sound/soc/codecs/si476x.c
@@ -210,7 +210,7 @@ out:
210static int si476x_codec_probe(struct snd_soc_codec *codec) 210static int si476x_codec_probe(struct snd_soc_codec *codec)
211{ 211{
212 codec->control_data = dev_get_regmap(codec->dev->parent, NULL); 212 codec->control_data = dev_get_regmap(codec->dev->parent, NULL);
213 return 0; 213 return snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
214} 214}
215 215
216static struct snd_soc_dai_ops si476x_dai_ops = { 216static struct snd_soc_dai_ops si476x_dai_ops = {
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 06edb396e733..2735361a4c3c 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -187,42 +187,42 @@ static const unsigned int sta32x_limiter_drc_release_tlv[] = {
187 13, 16, TLV_DB_SCALE_ITEM(-1500, 300, 0), 187 13, 16, TLV_DB_SCALE_ITEM(-1500, 300, 0),
188}; 188};
189 189
190static const struct soc_enum sta32x_drc_ac_enum = 190static SOC_ENUM_SINGLE_DECL(sta32x_drc_ac_enum,
191 SOC_ENUM_SINGLE(STA32X_CONFD, STA32X_CONFD_DRC_SHIFT, 191 STA32X_CONFD, STA32X_CONFD_DRC_SHIFT,
192 2, sta32x_drc_ac); 192 sta32x_drc_ac);
193static const struct soc_enum sta32x_auto_eq_enum = 193static SOC_ENUM_SINGLE_DECL(sta32x_auto_eq_enum,
194 SOC_ENUM_SINGLE(STA32X_AUTO1, STA32X_AUTO1_AMEQ_SHIFT, 194 STA32X_AUTO1, STA32X_AUTO1_AMEQ_SHIFT,
195 3, sta32x_auto_eq_mode); 195 sta32x_auto_eq_mode);
196static const struct soc_enum sta32x_auto_gc_enum = 196static SOC_ENUM_SINGLE_DECL(sta32x_auto_gc_enum,
197 SOC_ENUM_SINGLE(STA32X_AUTO1, STA32X_AUTO1_AMGC_SHIFT, 197 STA32X_AUTO1, STA32X_AUTO1_AMGC_SHIFT,
198 4, sta32x_auto_gc_mode); 198 sta32x_auto_gc_mode);
199static const struct soc_enum sta32x_auto_xo_enum = 199static SOC_ENUM_SINGLE_DECL(sta32x_auto_xo_enum,
200 SOC_ENUM_SINGLE(STA32X_AUTO2, STA32X_AUTO2_XO_SHIFT, 200 STA32X_AUTO2, STA32X_AUTO2_XO_SHIFT,
201 16, sta32x_auto_xo_mode); 201 sta32x_auto_xo_mode);
202static const struct soc_enum sta32x_preset_eq_enum = 202static SOC_ENUM_SINGLE_DECL(sta32x_preset_eq_enum,
203 SOC_ENUM_SINGLE(STA32X_AUTO3, STA32X_AUTO3_PEQ_SHIFT, 203 STA32X_AUTO3, STA32X_AUTO3_PEQ_SHIFT,
204 32, sta32x_preset_eq_mode); 204 sta32x_preset_eq_mode);
205static const struct soc_enum sta32x_limiter_ch1_enum = 205static SOC_ENUM_SINGLE_DECL(sta32x_limiter_ch1_enum,
206 SOC_ENUM_SINGLE(STA32X_C1CFG, STA32X_CxCFG_LS_SHIFT, 206 STA32X_C1CFG, STA32X_CxCFG_LS_SHIFT,
207 3, sta32x_limiter_select); 207 sta32x_limiter_select);
208static const struct soc_enum sta32x_limiter_ch2_enum = 208static SOC_ENUM_SINGLE_DECL(sta32x_limiter_ch2_enum,
209 SOC_ENUM_SINGLE(STA32X_C2CFG, STA32X_CxCFG_LS_SHIFT, 209 STA32X_C2CFG, STA32X_CxCFG_LS_SHIFT,
210 3, sta32x_limiter_select); 210 sta32x_limiter_select);
211static const struct soc_enum sta32x_limiter_ch3_enum = 211static SOC_ENUM_SINGLE_DECL(sta32x_limiter_ch3_enum,
212 SOC_ENUM_SINGLE(STA32X_C3CFG, STA32X_CxCFG_LS_SHIFT, 212 STA32X_C3CFG, STA32X_CxCFG_LS_SHIFT,
213 3, sta32x_limiter_select); 213 sta32x_limiter_select);
214static const struct soc_enum sta32x_limiter1_attack_rate_enum = 214static SOC_ENUM_SINGLE_DECL(sta32x_limiter1_attack_rate_enum,
215 SOC_ENUM_SINGLE(STA32X_L1AR, STA32X_LxA_SHIFT, 215 STA32X_L1AR, STA32X_LxA_SHIFT,
216 16, sta32x_limiter_attack_rate); 216 sta32x_limiter_attack_rate);
217static const struct soc_enum sta32x_limiter2_attack_rate_enum = 217static SOC_ENUM_SINGLE_DECL(sta32x_limiter2_attack_rate_enum,
218 SOC_ENUM_SINGLE(STA32X_L2AR, STA32X_LxA_SHIFT, 218 STA32X_L2AR, STA32X_LxA_SHIFT,
219 16, sta32x_limiter_attack_rate); 219 sta32x_limiter_attack_rate);
220static const struct soc_enum sta32x_limiter1_release_rate_enum = 220static SOC_ENUM_SINGLE_DECL(sta32x_limiter1_release_rate_enum,
221 SOC_ENUM_SINGLE(STA32X_L1AR, STA32X_LxR_SHIFT, 221 STA32X_L1AR, STA32X_LxR_SHIFT,
222 16, sta32x_limiter_release_rate); 222 sta32x_limiter_release_rate);
223static const struct soc_enum sta32x_limiter2_release_rate_enum = 223static SOC_ENUM_SINGLE_DECL(sta32x_limiter2_release_rate_enum,
224 SOC_ENUM_SINGLE(STA32X_L2AR, STA32X_LxR_SHIFT, 224 STA32X_L2AR, STA32X_LxR_SHIFT,
225 16, sta32x_limiter_release_rate); 225 sta32x_limiter_release_rate);
226 226
227/* byte array controls for setting biquad, mixer, scaling coefficients; 227/* byte array controls for setting biquad, mixer, scaling coefficients;
228 * for biquads all five coefficients need to be set in one go, 228 * for biquads all five coefficients need to be set in one go,
@@ -331,7 +331,7 @@ static int sta32x_sync_coef_shadow(struct snd_soc_codec *codec)
331 331
332static int sta32x_cache_sync(struct snd_soc_codec *codec) 332static int sta32x_cache_sync(struct snd_soc_codec *codec)
333{ 333{
334 struct sta32x_priv *sta32x = codec->control_data; 334 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
335 unsigned int mute; 335 unsigned int mute;
336 int rc; 336 int rc;
337 337
@@ -434,7 +434,7 @@ SOC_SINGLE_TLV("Treble Tone Control", STA32X_TONE, STA32X_TONE_TTC_SHIFT, 15, 0,
434SOC_ENUM("Limiter1 Attack Rate (dB/ms)", sta32x_limiter1_attack_rate_enum), 434SOC_ENUM("Limiter1 Attack Rate (dB/ms)", sta32x_limiter1_attack_rate_enum),
435SOC_ENUM("Limiter2 Attack Rate (dB/ms)", sta32x_limiter2_attack_rate_enum), 435SOC_ENUM("Limiter2 Attack Rate (dB/ms)", sta32x_limiter2_attack_rate_enum),
436SOC_ENUM("Limiter1 Release Rate (dB/ms)", sta32x_limiter1_release_rate_enum), 436SOC_ENUM("Limiter1 Release Rate (dB/ms)", sta32x_limiter1_release_rate_enum),
437SOC_ENUM("Limiter2 Release Rate (dB/ms)", sta32x_limiter1_release_rate_enum), 437SOC_ENUM("Limiter2 Release Rate (dB/ms)", sta32x_limiter2_release_rate_enum),
438 438
439/* depending on mode, the attack/release thresholds have 439/* depending on mode, the attack/release thresholds have
440 * two different enum definitions; provide both 440 * two different enum definitions; provide both
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
index 48dc7d2fee36..6d684d934f4d 100644
--- a/sound/soc/codecs/wm8400.c
+++ b/sound/soc/codecs/wm8400.c
@@ -117,19 +117,23 @@ static int wm8400_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol,
117static const char *wm8400_digital_sidetone[] = 117static const char *wm8400_digital_sidetone[] =
118 {"None", "Left ADC", "Right ADC", "Reserved"}; 118 {"None", "Left ADC", "Right ADC", "Reserved"};
119 119
120static const struct soc_enum wm8400_left_digital_sidetone_enum = 120static SOC_ENUM_SINGLE_DECL(wm8400_left_digital_sidetone_enum,
121SOC_ENUM_SINGLE(WM8400_DIGITAL_SIDE_TONE, 121 WM8400_DIGITAL_SIDE_TONE,
122 WM8400_ADC_TO_DACL_SHIFT, 2, wm8400_digital_sidetone); 122 WM8400_ADC_TO_DACL_SHIFT,
123 wm8400_digital_sidetone);
123 124
124static const struct soc_enum wm8400_right_digital_sidetone_enum = 125static SOC_ENUM_SINGLE_DECL(wm8400_right_digital_sidetone_enum,
125SOC_ENUM_SINGLE(WM8400_DIGITAL_SIDE_TONE, 126 WM8400_DIGITAL_SIDE_TONE,
126 WM8400_ADC_TO_DACR_SHIFT, 2, wm8400_digital_sidetone); 127 WM8400_ADC_TO_DACR_SHIFT,
128 wm8400_digital_sidetone);
127 129
128static const char *wm8400_adcmode[] = 130static const char *wm8400_adcmode[] =
129 {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"}; 131 {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"};
130 132
131static const struct soc_enum wm8400_right_adcmode_enum = 133static SOC_ENUM_SINGLE_DECL(wm8400_right_adcmode_enum,
132SOC_ENUM_SINGLE(WM8400_ADC_CTRL, WM8400_ADC_HPF_CUT_SHIFT, 3, wm8400_adcmode); 134 WM8400_ADC_CTRL,
135 WM8400_ADC_HPF_CUT_SHIFT,
136 wm8400_adcmode);
133 137
134static const struct snd_kcontrol_new wm8400_snd_controls[] = { 138static const struct snd_kcontrol_new wm8400_snd_controls[] = {
135/* INMIXL */ 139/* INMIXL */
@@ -422,9 +426,10 @@ SOC_DAPM_SINGLE("RINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT,
422static const char *wm8400_ainlmux[] = 426static const char *wm8400_ainlmux[] =
423 {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"}; 427 {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"};
424 428
425static const struct soc_enum wm8400_ainlmux_enum = 429static SOC_ENUM_SINGLE_DECL(wm8400_ainlmux_enum,
426SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINLMODE_SHIFT, 430 WM8400_INPUT_MIXER1,
427 ARRAY_SIZE(wm8400_ainlmux), wm8400_ainlmux); 431 WM8400_AINLMODE_SHIFT,
432 wm8400_ainlmux);
428 433
429static const struct snd_kcontrol_new wm8400_dapm_ainlmux_controls = 434static const struct snd_kcontrol_new wm8400_dapm_ainlmux_controls =
430SOC_DAPM_ENUM("Route", wm8400_ainlmux_enum); 435SOC_DAPM_ENUM("Route", wm8400_ainlmux_enum);
@@ -435,9 +440,10 @@ SOC_DAPM_ENUM("Route", wm8400_ainlmux_enum);
435static const char *wm8400_ainrmux[] = 440static const char *wm8400_ainrmux[] =
436 {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"}; 441 {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"};
437 442
438static const struct soc_enum wm8400_ainrmux_enum = 443static SOC_ENUM_SINGLE_DECL(wm8400_ainrmux_enum,
439SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINRMODE_SHIFT, 444 WM8400_INPUT_MIXER1,
440 ARRAY_SIZE(wm8400_ainrmux), wm8400_ainrmux); 445 WM8400_AINRMODE_SHIFT,
446 wm8400_ainrmux);
441 447
442static const struct snd_kcontrol_new wm8400_dapm_ainrmux_controls = 448static const struct snd_kcontrol_new wm8400_dapm_ainrmux_controls =
443SOC_DAPM_ENUM("Route", wm8400_ainrmux_enum); 449SOC_DAPM_ENUM("Route", wm8400_ainrmux_enum);
diff --git a/sound/soc/codecs/wm8770.c b/sound/soc/codecs/wm8770.c
index 89a18d82f303..5bce21013485 100644
--- a/sound/soc/codecs/wm8770.c
+++ b/sound/soc/codecs/wm8770.c
@@ -196,8 +196,8 @@ static const char *ain_text[] = {
196 "AIN5", "AIN6", "AIN7", "AIN8" 196 "AIN5", "AIN6", "AIN7", "AIN8"
197}; 197};
198 198
199static const struct soc_enum ain_enum = 199static SOC_ENUM_DOUBLE_DECL(ain_enum,
200 SOC_ENUM_DOUBLE(WM8770_ADCMUX, 0, 4, 8, ain_text); 200 WM8770_ADCMUX, 0, 4, ain_text);
201 201
202static const struct snd_kcontrol_new ain_mux = 202static const struct snd_kcontrol_new ain_mux =
203 SOC_DAPM_ENUM("Capture Mux", ain_enum); 203 SOC_DAPM_ENUM("Capture Mux", ain_enum);
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index e98bc7038a08..43c2201cb901 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -304,53 +304,53 @@ static const DECLARE_TLV_DB_SCALE(adc_tlv, -7200, 75, 1);
304 304
305static const char *mic_bias_level_txt[] = { "0.9*AVDD", "0.65*AVDD" }; 305static const char *mic_bias_level_txt[] = { "0.9*AVDD", "0.65*AVDD" };
306 306
307static const struct soc_enum mic_bias_level = 307static SOC_ENUM_SINGLE_DECL(mic_bias_level,
308SOC_ENUM_SINGLE(WM8900_REG_INCTL, 8, 2, mic_bias_level_txt); 308 WM8900_REG_INCTL, 8, mic_bias_level_txt);
309 309
310static const char *dac_mute_rate_txt[] = { "Fast", "Slow" }; 310static const char *dac_mute_rate_txt[] = { "Fast", "Slow" };
311 311
312static const struct soc_enum dac_mute_rate = 312static SOC_ENUM_SINGLE_DECL(dac_mute_rate,
313SOC_ENUM_SINGLE(WM8900_REG_DACCTRL, 7, 2, dac_mute_rate_txt); 313 WM8900_REG_DACCTRL, 7, dac_mute_rate_txt);
314 314
315static const char *dac_deemphasis_txt[] = { 315static const char *dac_deemphasis_txt[] = {
316 "Disabled", "32kHz", "44.1kHz", "48kHz" 316 "Disabled", "32kHz", "44.1kHz", "48kHz"
317}; 317};
318 318
319static const struct soc_enum dac_deemphasis = 319static SOC_ENUM_SINGLE_DECL(dac_deemphasis,
320SOC_ENUM_SINGLE(WM8900_REG_DACCTRL, 4, 4, dac_deemphasis_txt); 320 WM8900_REG_DACCTRL, 4, dac_deemphasis_txt);
321 321
322static const char *adc_hpf_cut_txt[] = { 322static const char *adc_hpf_cut_txt[] = {
323 "Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3" 323 "Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"
324}; 324};
325 325
326static const struct soc_enum adc_hpf_cut = 326static SOC_ENUM_SINGLE_DECL(adc_hpf_cut,
327SOC_ENUM_SINGLE(WM8900_REG_ADCCTRL, 5, 4, adc_hpf_cut_txt); 327 WM8900_REG_ADCCTRL, 5, adc_hpf_cut_txt);
328 328
329static const char *lr_txt[] = { 329static const char *lr_txt[] = {
330 "Left", "Right" 330 "Left", "Right"
331}; 331};
332 332
333static const struct soc_enum aifl_src = 333static SOC_ENUM_SINGLE_DECL(aifl_src,
334SOC_ENUM_SINGLE(WM8900_REG_AUDIO1, 15, 2, lr_txt); 334 WM8900_REG_AUDIO1, 15, lr_txt);
335 335
336static const struct soc_enum aifr_src = 336static SOC_ENUM_SINGLE_DECL(aifr_src,
337SOC_ENUM_SINGLE(WM8900_REG_AUDIO1, 14, 2, lr_txt); 337 WM8900_REG_AUDIO1, 14, lr_txt);
338 338
339static const struct soc_enum dacl_src = 339static SOC_ENUM_SINGLE_DECL(dacl_src,
340SOC_ENUM_SINGLE(WM8900_REG_AUDIO2, 15, 2, lr_txt); 340 WM8900_REG_AUDIO2, 15, lr_txt);
341 341
342static const struct soc_enum dacr_src = 342static SOC_ENUM_SINGLE_DECL(dacr_src,
343SOC_ENUM_SINGLE(WM8900_REG_AUDIO2, 14, 2, lr_txt); 343 WM8900_REG_AUDIO2, 14, lr_txt);
344 344
345static const char *sidetone_txt[] = { 345static const char *sidetone_txt[] = {
346 "Disabled", "Left ADC", "Right ADC" 346 "Disabled", "Left ADC", "Right ADC"
347}; 347};
348 348
349static const struct soc_enum dacl_sidetone = 349static SOC_ENUM_SINGLE_DECL(dacl_sidetone,
350SOC_ENUM_SINGLE(WM8900_REG_SIDETONE, 2, 3, sidetone_txt); 350 WM8900_REG_SIDETONE, 2, sidetone_txt);
351 351
352static const struct soc_enum dacr_sidetone = 352static SOC_ENUM_SINGLE_DECL(dacr_sidetone,
353SOC_ENUM_SINGLE(WM8900_REG_SIDETONE, 0, 3, sidetone_txt); 353 WM8900_REG_SIDETONE, 0, sidetone_txt);
354 354
355static const struct snd_kcontrol_new wm8900_snd_controls[] = { 355static const struct snd_kcontrol_new wm8900_snd_controls[] = {
356SOC_ENUM("Mic Bias Level", mic_bias_level), 356SOC_ENUM("Mic Bias Level", mic_bias_level),
@@ -496,8 +496,8 @@ SOC_DAPM_SINGLE("RINPUT3 Switch", WM8900_REG_INCTL, 0, 1, 0),
496 496
497static const char *wm8900_lp_mux[] = { "Disabled", "Enabled" }; 497static const char *wm8900_lp_mux[] = { "Disabled", "Enabled" };
498 498
499static const struct soc_enum wm8900_lineout2_lp_mux = 499static SOC_ENUM_SINGLE_DECL(wm8900_lineout2_lp_mux,
500SOC_ENUM_SINGLE(WM8900_REG_LOUTMIXCTL1, 1, 2, wm8900_lp_mux); 500 WM8900_REG_LOUTMIXCTL1, 1, wm8900_lp_mux);
501 501
502static const struct snd_kcontrol_new wm8900_lineout2_lp = 502static const struct snd_kcontrol_new wm8900_lineout2_lp =
503SOC_DAPM_ENUM("Route", wm8900_lineout2_lp_mux); 503SOC_DAPM_ENUM("Route", wm8900_lineout2_lp_mux);
diff --git a/sound/soc/codecs/wm8958-dsp2.c b/sound/soc/codecs/wm8958-dsp2.c
index b7488f190d2b..d4248e00160e 100644
--- a/sound/soc/codecs/wm8958-dsp2.c
+++ b/sound/soc/codecs/wm8958-dsp2.c
@@ -153,7 +153,7 @@ static int wm8958_dsp2_fw(struct snd_soc_codec *codec, const char *name,
153 153
154 data32 &= 0xffffff; 154 data32 &= 0xffffff;
155 155
156 wm8994_bulk_write(codec->control_data, 156 wm8994_bulk_write(wm8994->wm8994,
157 data32 & 0xffffff, 157 data32 & 0xffffff,
158 block_len / 2, 158 block_len / 2,
159 (void *)(data + 8)); 159 (void *)(data + 8));
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index 433d59a0f3ef..2ee23a39622c 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -1562,7 +1562,6 @@ static int wm8993_remove(struct snd_soc_codec *codec)
1562 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); 1562 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1563 1563
1564 wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF); 1564 wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF);
1565 regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies);
1566 return 0; 1565 return 0;
1567} 1566}
1568 1567
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index b9be9cbc4603..adb72063d44e 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -265,21 +265,21 @@ static const char *sidetone_hpf_text[] = {
265 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz" 265 "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
266}; 266};
267 267
268static const struct soc_enum sidetone_hpf = 268static SOC_ENUM_SINGLE_DECL(sidetone_hpf,
269 SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text); 269 WM8994_SIDETONE, 7, sidetone_hpf_text);
270 270
271static const char *adc_hpf_text[] = { 271static const char *adc_hpf_text[] = {
272 "HiFi", "Voice 1", "Voice 2", "Voice 3" 272 "HiFi", "Voice 1", "Voice 2", "Voice 3"
273}; 273};
274 274
275static const struct soc_enum aif1adc1_hpf = 275static SOC_ENUM_SINGLE_DECL(aif1adc1_hpf,
276 SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text); 276 WM8994_AIF1_ADC1_FILTERS, 13, adc_hpf_text);
277 277
278static const struct soc_enum aif1adc2_hpf = 278static SOC_ENUM_SINGLE_DECL(aif1adc2_hpf,
279 SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text); 279 WM8994_AIF1_ADC2_FILTERS, 13, adc_hpf_text);
280 280
281static const struct soc_enum aif2adc_hpf = 281static SOC_ENUM_SINGLE_DECL(aif2adc_hpf,
282 SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text); 282 WM8994_AIF2_ADC_FILTERS, 13, adc_hpf_text);
283 283
284static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0); 284static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
285static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1); 285static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
@@ -501,39 +501,39 @@ static const char *aif_chan_src_text[] = {
501 "Left", "Right" 501 "Left", "Right"
502}; 502};
503 503
504static const struct soc_enum aif1adcl_src = 504static SOC_ENUM_SINGLE_DECL(aif1adcl_src,
505 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text); 505 WM8994_AIF1_CONTROL_1, 15, aif_chan_src_text);
506 506
507static const struct soc_enum aif1adcr_src = 507static SOC_ENUM_SINGLE_DECL(aif1adcr_src,
508 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text); 508 WM8994_AIF1_CONTROL_1, 14, aif_chan_src_text);
509 509
510static const struct soc_enum aif2adcl_src = 510static SOC_ENUM_SINGLE_DECL(aif2adcl_src,
511 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text); 511 WM8994_AIF2_CONTROL_1, 15, aif_chan_src_text);
512 512
513static const struct soc_enum aif2adcr_src = 513static SOC_ENUM_SINGLE_DECL(aif2adcr_src,
514 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text); 514 WM8994_AIF2_CONTROL_1, 14, aif_chan_src_text);
515 515
516static const struct soc_enum aif1dacl_src = 516static SOC_ENUM_SINGLE_DECL(aif1dacl_src,
517 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text); 517 WM8994_AIF1_CONTROL_2, 15, aif_chan_src_text);
518 518
519static const struct soc_enum aif1dacr_src = 519static SOC_ENUM_SINGLE_DECL(aif1dacr_src,
520 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text); 520 WM8994_AIF1_CONTROL_2, 14, aif_chan_src_text);
521 521
522static const struct soc_enum aif2dacl_src = 522static SOC_ENUM_SINGLE_DECL(aif2dacl_src,
523 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text); 523 WM8994_AIF2_CONTROL_2, 15, aif_chan_src_text);
524 524
525static const struct soc_enum aif2dacr_src = 525static SOC_ENUM_SINGLE_DECL(aif2dacr_src,
526 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text); 526 WM8994_AIF2_CONTROL_2, 14, aif_chan_src_text);
527 527
528static const char *osr_text[] = { 528static const char *osr_text[] = {
529 "Low Power", "High Performance", 529 "Low Power", "High Performance",
530}; 530};
531 531
532static const struct soc_enum dac_osr = 532static SOC_ENUM_SINGLE_DECL(dac_osr,
533 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text); 533 WM8994_OVERSAMPLING, 0, osr_text);
534 534
535static const struct soc_enum adc_osr = 535static SOC_ENUM_SINGLE_DECL(adc_osr,
536 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text); 536 WM8994_OVERSAMPLING, 1, osr_text);
537 537
538static const struct snd_kcontrol_new wm8994_snd_controls[] = { 538static const struct snd_kcontrol_new wm8994_snd_controls[] = {
539SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME, 539SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
@@ -690,17 +690,20 @@ static const char *wm8958_ng_text[] = {
690 "30ms", "125ms", "250ms", "500ms", 690 "30ms", "125ms", "250ms", "500ms",
691}; 691};
692 692
693static const struct soc_enum wm8958_aif1dac1_ng_hold = 693static SOC_ENUM_SINGLE_DECL(wm8958_aif1dac1_ng_hold,
694 SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE, 694 WM8958_AIF1_DAC1_NOISE_GATE,
695 WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text); 695 WM8958_AIF1DAC1_NG_THR_SHIFT,
696 wm8958_ng_text);
696 697
697static const struct soc_enum wm8958_aif1dac2_ng_hold = 698static SOC_ENUM_SINGLE_DECL(wm8958_aif1dac2_ng_hold,
698 SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE, 699 WM8958_AIF1_DAC2_NOISE_GATE,
699 WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text); 700 WM8958_AIF1DAC2_NG_THR_SHIFT,
701 wm8958_ng_text);
700 702
701static const struct soc_enum wm8958_aif2dac_ng_hold = 703static SOC_ENUM_SINGLE_DECL(wm8958_aif2dac_ng_hold,
702 SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE, 704 WM8958_AIF2_DAC_NOISE_GATE,
703 WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text); 705 WM8958_AIF2DAC_NG_THR_SHIFT,
706 wm8958_ng_text);
704 707
705static const struct snd_kcontrol_new wm8958_snd_controls[] = { 708static const struct snd_kcontrol_new wm8958_snd_controls[] = {
706SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv), 709SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
@@ -1341,8 +1344,8 @@ static const char *adc_mux_text[] = {
1341 "DMIC", 1344 "DMIC",
1342}; 1345};
1343 1346
1344static const struct soc_enum adc_enum = 1347static SOC_ENUM_SINGLE_DECL(adc_enum,
1345 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text); 1348 0, 0, adc_mux_text);
1346 1349
1347static const struct snd_kcontrol_new adcl_mux = 1350static const struct snd_kcontrol_new adcl_mux =
1348 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum); 1351 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
@@ -1478,14 +1481,14 @@ static const char *sidetone_text[] = {
1478 "ADC/DMIC1", "DMIC2", 1481 "ADC/DMIC1", "DMIC2",
1479}; 1482};
1480 1483
1481static const struct soc_enum sidetone1_enum = 1484static SOC_ENUM_SINGLE_DECL(sidetone1_enum,
1482 SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text); 1485 WM8994_SIDETONE, 0, sidetone_text);
1483 1486
1484static const struct snd_kcontrol_new sidetone1_mux = 1487static const struct snd_kcontrol_new sidetone1_mux =
1485 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum); 1488 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
1486 1489
1487static const struct soc_enum sidetone2_enum = 1490static SOC_ENUM_SINGLE_DECL(sidetone2_enum,
1488 SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text); 1491 WM8994_SIDETONE, 1, sidetone_text);
1489 1492
1490static const struct snd_kcontrol_new sidetone2_mux = 1493static const struct snd_kcontrol_new sidetone2_mux =
1491 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum); 1494 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
@@ -1498,22 +1501,24 @@ static const char *loopback_text[] = {
1498 "None", "ADCDAT", 1501 "None", "ADCDAT",
1499}; 1502};
1500 1503
1501static const struct soc_enum aif1_loopback_enum = 1504static SOC_ENUM_SINGLE_DECL(aif1_loopback_enum,
1502 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, WM8994_AIF1_LOOPBACK_SHIFT, 2, 1505 WM8994_AIF1_CONTROL_2,
1503 loopback_text); 1506 WM8994_AIF1_LOOPBACK_SHIFT,
1507 loopback_text);
1504 1508
1505static const struct snd_kcontrol_new aif1_loopback = 1509static const struct snd_kcontrol_new aif1_loopback =
1506 SOC_DAPM_ENUM("AIF1 Loopback", aif1_loopback_enum); 1510 SOC_DAPM_ENUM("AIF1 Loopback", aif1_loopback_enum);
1507 1511
1508static const struct soc_enum aif2_loopback_enum = 1512static SOC_ENUM_SINGLE_DECL(aif2_loopback_enum,
1509 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, WM8994_AIF2_LOOPBACK_SHIFT, 2, 1513 WM8994_AIF2_CONTROL_2,
1510 loopback_text); 1514 WM8994_AIF2_LOOPBACK_SHIFT,
1515 loopback_text);
1511 1516
1512static const struct snd_kcontrol_new aif2_loopback = 1517static const struct snd_kcontrol_new aif2_loopback =
1513 SOC_DAPM_ENUM("AIF2 Loopback", aif2_loopback_enum); 1518 SOC_DAPM_ENUM("AIF2 Loopback", aif2_loopback_enum);
1514 1519
1515static const struct soc_enum aif1dac_enum = 1520static SOC_ENUM_SINGLE_DECL(aif1dac_enum,
1516 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text); 1521 WM8994_POWER_MANAGEMENT_6, 0, aif1dac_text);
1517 1522
1518static const struct snd_kcontrol_new aif1dac_mux = 1523static const struct snd_kcontrol_new aif1dac_mux =
1519 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum); 1524 SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
@@ -1522,8 +1527,8 @@ static const char *aif2dac_text[] = {
1522 "AIF2DACDAT", "AIF3DACDAT", 1527 "AIF2DACDAT", "AIF3DACDAT",
1523}; 1528};
1524 1529
1525static const struct soc_enum aif2dac_enum = 1530static SOC_ENUM_SINGLE_DECL(aif2dac_enum,
1526 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text); 1531 WM8994_POWER_MANAGEMENT_6, 1, aif2dac_text);
1527 1532
1528static const struct snd_kcontrol_new aif2dac_mux = 1533static const struct snd_kcontrol_new aif2dac_mux =
1529 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum); 1534 SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
@@ -1532,8 +1537,8 @@ static const char *aif2adc_text[] = {
1532 "AIF2ADCDAT", "AIF3DACDAT", 1537 "AIF2ADCDAT", "AIF3DACDAT",
1533}; 1538};
1534 1539
1535static const struct soc_enum aif2adc_enum = 1540static SOC_ENUM_SINGLE_DECL(aif2adc_enum,
1536 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text); 1541 WM8994_POWER_MANAGEMENT_6, 2, aif2adc_text);
1537 1542
1538static const struct snd_kcontrol_new aif2adc_mux = 1543static const struct snd_kcontrol_new aif2adc_mux =
1539 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum); 1544 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
@@ -1542,14 +1547,14 @@ static const char *aif3adc_text[] = {
1542 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM", 1547 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
1543}; 1548};
1544 1549
1545static const struct soc_enum wm8994_aif3adc_enum = 1550static SOC_ENUM_SINGLE_DECL(wm8994_aif3adc_enum,
1546 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text); 1551 WM8994_POWER_MANAGEMENT_6, 3, aif3adc_text);
1547 1552
1548static const struct snd_kcontrol_new wm8994_aif3adc_mux = 1553static const struct snd_kcontrol_new wm8994_aif3adc_mux =
1549 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum); 1554 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1550 1555
1551static const struct soc_enum wm8958_aif3adc_enum = 1556static SOC_ENUM_SINGLE_DECL(wm8958_aif3adc_enum,
1552 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text); 1557 WM8994_POWER_MANAGEMENT_6, 3, aif3adc_text);
1553 1558
1554static const struct snd_kcontrol_new wm8958_aif3adc_mux = 1559static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1555 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum); 1560 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
@@ -1558,8 +1563,8 @@ static const char *mono_pcm_out_text[] = {
1558 "None", "AIF2ADCL", "AIF2ADCR", 1563 "None", "AIF2ADCL", "AIF2ADCR",
1559}; 1564};
1560 1565
1561static const struct soc_enum mono_pcm_out_enum = 1566static SOC_ENUM_SINGLE_DECL(mono_pcm_out_enum,
1562 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text); 1567 WM8994_POWER_MANAGEMENT_6, 9, mono_pcm_out_text);
1563 1568
1564static const struct snd_kcontrol_new mono_pcm_out_mux = 1569static const struct snd_kcontrol_new mono_pcm_out_mux =
1565 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum); 1570 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
@@ -1569,14 +1574,14 @@ static const char *aif2dac_src_text[] = {
1569}; 1574};
1570 1575
1571/* Note that these two control shouldn't be simultaneously switched to AIF3 */ 1576/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1572static const struct soc_enum aif2dacl_src_enum = 1577static SOC_ENUM_SINGLE_DECL(aif2dacl_src_enum,
1573 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text); 1578 WM8994_POWER_MANAGEMENT_6, 7, aif2dac_src_text);
1574 1579
1575static const struct snd_kcontrol_new aif2dacl_src_mux = 1580static const struct snd_kcontrol_new aif2dacl_src_mux =
1576 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum); 1581 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1577 1582
1578static const struct soc_enum aif2dacr_src_enum = 1583static SOC_ENUM_SINGLE_DECL(aif2dacr_src_enum,
1579 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text); 1584 WM8994_POWER_MANAGEMENT_6, 8, aif2dac_src_text);
1580 1585
1581static const struct snd_kcontrol_new aif2dacr_src_mux = 1586static const struct snd_kcontrol_new aif2dacr_src_mux =
1582 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum); 1587 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index 70ff3772079f..5e3bc3c6801a 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -399,6 +399,7 @@ static struct platform_driver davinci_evm_driver = {
399 .driver = { 399 .driver = {
400 .name = "davinci_evm", 400 .name = "davinci_evm",
401 .owner = THIS_MODULE, 401 .owner = THIS_MODULE,
402 .pm = &snd_soc_pm_ops,
402 .of_match_table = of_match_ptr(davinci_evm_dt_ids), 403 .of_match_table = of_match_ptr(davinci_evm_dt_ids),
403 }, 404 },
404}; 405};
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index b7858bfa0295..670afa29e30d 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -263,7 +263,9 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
263 unsigned int fmt) 263 unsigned int fmt)
264{ 264{
265 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai); 265 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
266 int ret = 0;
266 267
268 pm_runtime_get_sync(mcasp->dev);
267 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 269 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
268 case SND_SOC_DAIFMT_DSP_B: 270 case SND_SOC_DAIFMT_DSP_B:
269 case SND_SOC_DAIFMT_AC97: 271 case SND_SOC_DAIFMT_AC97:
@@ -317,7 +319,8 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
317 break; 319 break;
318 320
319 default: 321 default:
320 return -EINVAL; 322 ret = -EINVAL;
323 goto out;
321 } 324 }
322 325
323 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 326 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
@@ -354,10 +357,12 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
354 break; 357 break;
355 358
356 default: 359 default:
357 return -EINVAL; 360 ret = -EINVAL;
361 break;
358 } 362 }
359 363out:
360 return 0; 364 pm_runtime_put_sync(mcasp->dev);
365 return ret;
361} 366}
362 367
363static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div) 368static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div)
@@ -448,7 +453,7 @@ static int davinci_config_channel_size(struct davinci_mcasp *mcasp,
448 return 0; 453 return 0;
449} 454}
450 455
451static int davinci_hw_common_param(struct davinci_mcasp *mcasp, int stream, 456static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream,
452 int channels) 457 int channels)
453{ 458{
454 int i; 459 int i;
@@ -524,12 +529,18 @@ static int davinci_hw_common_param(struct davinci_mcasp *mcasp, int stream,
524 return 0; 529 return 0;
525} 530}
526 531
527static void davinci_hw_param(struct davinci_mcasp *mcasp, int stream) 532static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream)
528{ 533{
529 int i, active_slots; 534 int i, active_slots;
530 u32 mask = 0; 535 u32 mask = 0;
531 u32 busel = 0; 536 u32 busel = 0;
532 537
538 if ((mcasp->tdm_slots < 2) || (mcasp->tdm_slots > 32)) {
539 dev_err(mcasp->dev, "tdm slot %d not supported\n",
540 mcasp->tdm_slots);
541 return -EINVAL;
542 }
543
533 active_slots = (mcasp->tdm_slots > 31) ? 32 : mcasp->tdm_slots; 544 active_slots = (mcasp->tdm_slots > 31) ? 32 : mcasp->tdm_slots;
534 for (i = 0; i < active_slots; i++) 545 for (i = 0; i < active_slots; i++)
535 mask |= (1 << i); 546 mask |= (1 << i);
@@ -539,35 +550,21 @@ static void davinci_hw_param(struct davinci_mcasp *mcasp, int stream)
539 if (!mcasp->dat_port) 550 if (!mcasp->dat_port)
540 busel = TXSEL; 551 busel = TXSEL;
541 552
542 if (stream == SNDRV_PCM_STREAM_PLAYBACK) { 553 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask);
543 /* bit stream is MSB first with no delay */ 554 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD);
544 /* DSP_B mode */ 555 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG,
545 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask); 556 FSXMOD(mcasp->tdm_slots), FSXMOD(0x1FF));
546 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD); 557
547 558 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask);
548 if ((mcasp->tdm_slots >= 2) && (mcasp->tdm_slots <= 32)) 559 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD);
549 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, 560 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG,
550 FSXMOD(mcasp->tdm_slots), FSXMOD(0x1FF)); 561 FSRMOD(mcasp->tdm_slots), FSRMOD(0x1FF));
551 else 562
552 printk(KERN_ERR "playback tdm slot %d not supported\n", 563 return 0;
553 mcasp->tdm_slots);
554 } else {
555 /* bit stream is MSB first with no delay */
556 /* DSP_B mode */
557 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD);
558 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask);
559
560 if ((mcasp->tdm_slots >= 2) && (mcasp->tdm_slots <= 32))
561 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG,
562 FSRMOD(mcasp->tdm_slots), FSRMOD(0x1FF));
563 else
564 printk(KERN_ERR "capture tdm slot %d not supported\n",
565 mcasp->tdm_slots);
566 }
567} 564}
568 565
569/* S/PDIF */ 566/* S/PDIF */
570static void davinci_hw_dit_param(struct davinci_mcasp *mcasp) 567static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp)
571{ 568{
572 /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0 569 /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0
573 and LSB first */ 570 and LSB first */
@@ -589,6 +586,8 @@ static void davinci_hw_dit_param(struct davinci_mcasp *mcasp)
589 586
590 /* Enable the DIT */ 587 /* Enable the DIT */
591 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXDITCTL_REG, DITEN); 588 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXDITCTL_REG, DITEN);
589
590 return 0;
592} 591}
593 592
594static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, 593static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
@@ -605,13 +604,14 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
605 u8 slots = mcasp->tdm_slots; 604 u8 slots = mcasp->tdm_slots;
606 u8 active_serializers; 605 u8 active_serializers;
607 int channels; 606 int channels;
607 int ret;
608 struct snd_interval *pcm_channels = hw_param_interval(params, 608 struct snd_interval *pcm_channels = hw_param_interval(params,
609 SNDRV_PCM_HW_PARAM_CHANNELS); 609 SNDRV_PCM_HW_PARAM_CHANNELS);
610 channels = pcm_channels->min; 610 channels = pcm_channels->min;
611 611
612 active_serializers = (channels + slots - 1) / slots; 612 active_serializers = (channels + slots - 1) / slots;
613 613
614 if (davinci_hw_common_param(mcasp, substream->stream, channels) == -EINVAL) 614 if (mcasp_common_hw_param(mcasp, substream->stream, channels) == -EINVAL)
615 return -EINVAL; 615 return -EINVAL;
616 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 616 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
617 fifo_level = mcasp->txnumevt * active_serializers; 617 fifo_level = mcasp->txnumevt * active_serializers;
@@ -619,9 +619,12 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
619 fifo_level = mcasp->rxnumevt * active_serializers; 619 fifo_level = mcasp->rxnumevt * active_serializers;
620 620
621 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE) 621 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
622 davinci_hw_dit_param(mcasp); 622 ret = mcasp_dit_hw_param(mcasp);
623 else 623 else
624 davinci_hw_param(mcasp, substream->stream); 624 ret = mcasp_i2s_hw_param(mcasp, substream->stream);
625
626 if (ret)
627 return ret;
625 628
626 switch (params_format(params)) { 629 switch (params_format(params)) {
627 case SNDRV_PCM_FORMAT_U8: 630 case SNDRV_PCM_FORMAT_U8:
@@ -678,19 +681,9 @@ static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
678 case SNDRV_PCM_TRIGGER_RESUME: 681 case SNDRV_PCM_TRIGGER_RESUME:
679 case SNDRV_PCM_TRIGGER_START: 682 case SNDRV_PCM_TRIGGER_START:
680 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 683 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
681 ret = pm_runtime_get_sync(mcasp->dev);
682 if (IS_ERR_VALUE(ret))
683 dev_err(mcasp->dev, "pm_runtime_get_sync() failed\n");
684 davinci_mcasp_start(mcasp, substream->stream); 684 davinci_mcasp_start(mcasp, substream->stream);
685 break; 685 break;
686
687 case SNDRV_PCM_TRIGGER_SUSPEND: 686 case SNDRV_PCM_TRIGGER_SUSPEND:
688 davinci_mcasp_stop(mcasp, substream->stream);
689 ret = pm_runtime_put_sync(mcasp->dev);
690 if (IS_ERR_VALUE(ret))
691 dev_err(mcasp->dev, "pm_runtime_put_sync() failed\n");
692 break;
693
694 case SNDRV_PCM_TRIGGER_STOP: 687 case SNDRV_PCM_TRIGGER_STOP:
695 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 688 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
696 davinci_mcasp_stop(mcasp, substream->stream); 689 davinci_mcasp_stop(mcasp, substream->stream);
diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
index d0c72ed261e7..c84026c99134 100644
--- a/sound/soc/fsl/fsl_esai.c
+++ b/sound/soc/fsl/fsl_esai.c
@@ -326,7 +326,7 @@ static int fsl_esai_set_dai_tdm_slot(struct snd_soc_dai *dai, u32 tx_mask,
326 regmap_update_bits(esai_priv->regmap, REG_ESAI_TSMA, 326 regmap_update_bits(esai_priv->regmap, REG_ESAI_TSMA,
327 ESAI_xSMA_xS_MASK, ESAI_xSMA_xS(tx_mask)); 327 ESAI_xSMA_xS_MASK, ESAI_xSMA_xS(tx_mask));
328 regmap_update_bits(esai_priv->regmap, REG_ESAI_TSMB, 328 regmap_update_bits(esai_priv->regmap, REG_ESAI_TSMB,
329 ESAI_xSMA_xS_MASK, ESAI_xSMB_xS(tx_mask)); 329 ESAI_xSMB_xS_MASK, ESAI_xSMB_xS(tx_mask));
330 330
331 regmap_update_bits(esai_priv->regmap, REG_ESAI_RCCR, 331 regmap_update_bits(esai_priv->regmap, REG_ESAI_RCCR,
332 ESAI_xCCR_xDC_MASK, ESAI_xCCR_xDC(slots)); 332 ESAI_xCCR_xDC_MASK, ESAI_xCCR_xDC(slots));
@@ -334,7 +334,7 @@ static int fsl_esai_set_dai_tdm_slot(struct snd_soc_dai *dai, u32 tx_mask,
334 regmap_update_bits(esai_priv->regmap, REG_ESAI_RSMA, 334 regmap_update_bits(esai_priv->regmap, REG_ESAI_RSMA,
335 ESAI_xSMA_xS_MASK, ESAI_xSMA_xS(rx_mask)); 335 ESAI_xSMA_xS_MASK, ESAI_xSMA_xS(rx_mask));
336 regmap_update_bits(esai_priv->regmap, REG_ESAI_RSMB, 336 regmap_update_bits(esai_priv->regmap, REG_ESAI_RSMB,
337 ESAI_xSMA_xS_MASK, ESAI_xSMB_xS(rx_mask)); 337 ESAI_xSMB_xS_MASK, ESAI_xSMB_xS(rx_mask));
338 338
339 esai_priv->slot_width = slot_width; 339 esai_priv->slot_width = slot_width;
340 340
diff --git a/sound/soc/fsl/fsl_esai.h b/sound/soc/fsl/fsl_esai.h
index 9c9f957fcae1..75e14033e8d8 100644
--- a/sound/soc/fsl/fsl_esai.h
+++ b/sound/soc/fsl/fsl_esai.h
@@ -322,7 +322,7 @@
322#define ESAI_xSMB_xS_SHIFT 0 322#define ESAI_xSMB_xS_SHIFT 0
323#define ESAI_xSMB_xS_WIDTH 16 323#define ESAI_xSMB_xS_WIDTH 16
324#define ESAI_xSMB_xS_MASK (((1 << ESAI_xSMB_xS_WIDTH) - 1) << ESAI_xSMB_xS_SHIFT) 324#define ESAI_xSMB_xS_MASK (((1 << ESAI_xSMB_xS_WIDTH) - 1) << ESAI_xSMB_xS_SHIFT)
325#define ESAI_xSMB_xS(v) (((v) >> ESAI_xSMA_xS_WIDTH) & ESAI_xSMA_xS_MASK) 325#define ESAI_xSMB_xS(v) (((v) >> ESAI_xSMA_xS_WIDTH) & ESAI_xSMB_xS_MASK)
326 326
327/* Port C Direction Register -- REG_ESAI_PRRC 0xF8 */ 327/* Port C Direction Register -- REG_ESAI_PRRC 0xF8 */
328#define ESAI_PRRC_PDC_SHIFT 0 328#define ESAI_PRRC_PDC_SHIFT 0
diff --git a/sound/soc/fsl/imx-mc13783.c b/sound/soc/fsl/imx-mc13783.c
index 79cee782dbbf..a2fd7321b5a9 100644
--- a/sound/soc/fsl/imx-mc13783.c
+++ b/sound/soc/fsl/imx-mc13783.c
@@ -160,7 +160,6 @@ static struct platform_driver imx_mc13783_audio_driver = {
160 .driver = { 160 .driver = {
161 .name = "imx_mc13783", 161 .name = "imx_mc13783",
162 .owner = THIS_MODULE, 162 .owner = THIS_MODULE,
163 .pm = &snd_soc_pm_ops,
164 }, 163 },
165 .probe = imx_mc13783_probe, 164 .probe = imx_mc13783_probe,
166 .remove = imx_mc13783_remove 165 .remove = imx_mc13783_remove
diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c
index f2beae78969f..1cb22dd034eb 100644
--- a/sound/soc/fsl/imx-sgtl5000.c
+++ b/sound/soc/fsl/imx-sgtl5000.c
@@ -33,8 +33,7 @@ struct imx_sgtl5000_data {
33 33
34static int imx_sgtl5000_dai_init(struct snd_soc_pcm_runtime *rtd) 34static int imx_sgtl5000_dai_init(struct snd_soc_pcm_runtime *rtd)
35{ 35{
36 struct imx_sgtl5000_data *data = container_of(rtd->card, 36 struct imx_sgtl5000_data *data = snd_soc_card_get_drvdata(rtd->card);
37 struct imx_sgtl5000_data, card);
38 struct device *dev = rtd->card->dev; 37 struct device *dev = rtd->card->dev;
39 int ret; 38 int ret;
40 39
@@ -159,13 +158,15 @@ static int imx_sgtl5000_probe(struct platform_device *pdev)
159 data->card.dapm_widgets = imx_sgtl5000_dapm_widgets; 158 data->card.dapm_widgets = imx_sgtl5000_dapm_widgets;
160 data->card.num_dapm_widgets = ARRAY_SIZE(imx_sgtl5000_dapm_widgets); 159 data->card.num_dapm_widgets = ARRAY_SIZE(imx_sgtl5000_dapm_widgets);
161 160
161 platform_set_drvdata(pdev, &data->card);
162 snd_soc_card_set_drvdata(&data->card, data);
163
162 ret = devm_snd_soc_register_card(&pdev->dev, &data->card); 164 ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
163 if (ret) { 165 if (ret) {
164 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); 166 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
165 goto fail; 167 goto fail;
166 } 168 }
167 169
168 platform_set_drvdata(pdev, data);
169 of_node_put(ssi_np); 170 of_node_put(ssi_np);
170 of_node_put(codec_np); 171 of_node_put(codec_np);
171 172
@@ -184,7 +185,8 @@ fail:
184 185
185static int imx_sgtl5000_remove(struct platform_device *pdev) 186static int imx_sgtl5000_remove(struct platform_device *pdev)
186{ 187{
187 struct imx_sgtl5000_data *data = platform_get_drvdata(pdev); 188 struct snd_soc_card *card = platform_get_drvdata(pdev);
189 struct imx_sgtl5000_data *data = snd_soc_card_get_drvdata(card);
188 190
189 clk_put(data->codec_clk); 191 clk_put(data->codec_clk);
190 192
diff --git a/sound/soc/fsl/imx-wm8962.c b/sound/soc/fsl/imx-wm8962.c
index 3fd76bc391de..3a3d17ce6ba4 100644
--- a/sound/soc/fsl/imx-wm8962.c
+++ b/sound/soc/fsl/imx-wm8962.c
@@ -71,7 +71,7 @@ static int imx_wm8962_set_bias_level(struct snd_soc_card *card,
71{ 71{
72 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; 72 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
73 struct imx_priv *priv = &card_priv; 73 struct imx_priv *priv = &card_priv;
74 struct imx_wm8962_data *data = platform_get_drvdata(priv->pdev); 74 struct imx_wm8962_data *data = snd_soc_card_get_drvdata(card);
75 struct device *dev = &priv->pdev->dev; 75 struct device *dev = &priv->pdev->dev;
76 unsigned int pll_out; 76 unsigned int pll_out;
77 int ret; 77 int ret;
@@ -137,7 +137,7 @@ static int imx_wm8962_late_probe(struct snd_soc_card *card)
137{ 137{
138 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; 138 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
139 struct imx_priv *priv = &card_priv; 139 struct imx_priv *priv = &card_priv;
140 struct imx_wm8962_data *data = platform_get_drvdata(priv->pdev); 140 struct imx_wm8962_data *data = snd_soc_card_get_drvdata(card);
141 struct device *dev = &priv->pdev->dev; 141 struct device *dev = &priv->pdev->dev;
142 int ret; 142 int ret;
143 143
@@ -264,13 +264,15 @@ static int imx_wm8962_probe(struct platform_device *pdev)
264 data->card.late_probe = imx_wm8962_late_probe; 264 data->card.late_probe = imx_wm8962_late_probe;
265 data->card.set_bias_level = imx_wm8962_set_bias_level; 265 data->card.set_bias_level = imx_wm8962_set_bias_level;
266 266
267 platform_set_drvdata(pdev, &data->card);
268 snd_soc_card_set_drvdata(&data->card, data);
269
267 ret = devm_snd_soc_register_card(&pdev->dev, &data->card); 270 ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
268 if (ret) { 271 if (ret) {
269 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); 272 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
270 goto clk_fail; 273 goto clk_fail;
271 } 274 }
272 275
273 platform_set_drvdata(pdev, data);
274 of_node_put(ssi_np); 276 of_node_put(ssi_np);
275 of_node_put(codec_np); 277 of_node_put(codec_np);
276 278
@@ -289,7 +291,8 @@ fail:
289 291
290static int imx_wm8962_remove(struct platform_device *pdev) 292static int imx_wm8962_remove(struct platform_device *pdev)
291{ 293{
292 struct imx_wm8962_data *data = platform_get_drvdata(pdev); 294 struct snd_soc_card *card = platform_get_drvdata(pdev);
295 struct imx_wm8962_data *data = snd_soc_card_get_drvdata(card);
293 296
294 if (!IS_ERR(data->codec_clk)) 297 if (!IS_ERR(data->codec_clk))
295 clk_disable_unprepare(data->codec_clk); 298 clk_disable_unprepare(data->codec_clk);
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c
index 3fde9e402710..d163e18d85d4 100644
--- a/sound/soc/omap/n810.c
+++ b/sound/soc/omap/n810.c
@@ -305,7 +305,9 @@ static int __init n810_soc_init(void)
305 int err; 305 int err;
306 struct device *dev; 306 struct device *dev;
307 307
308 if (!(machine_is_nokia_n810() || machine_is_nokia_n810_wimax())) 308 if (!of_have_populated_dt() ||
309 (!of_machine_is_compatible("nokia,n810") &&
310 !of_machine_is_compatible("nokia,n810-wimax")))
309 return -ENODEV; 311 return -ENODEV;
310 312
311 n810_snd_device = platform_device_alloc("soc-audio", -1); 313 n810_snd_device = platform_device_alloc("soc-audio", -1);
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig
index 454f41cfc828..350757400391 100644
--- a/sound/soc/samsung/Kconfig
+++ b/sound/soc/samsung/Kconfig
@@ -59,7 +59,7 @@ config SND_SOC_SAMSUNG_JIVE_WM8750
59 select SND_SOC_WM8750 59 select SND_SOC_WM8750
60 select SND_S3C2412_SOC_I2S 60 select SND_S3C2412_SOC_I2S
61 help 61 help
62 Sat Y if you want to add support for SoC audio on the Jive. 62 Say Y if you want to add support for SoC audio on the Jive.
63 63
64config SND_SOC_SAMSUNG_SMDK_WM8580 64config SND_SOC_SAMSUNG_SMDK_WM8580
65 tristate "SoC I2S Audio support for WM8580 on SMDK" 65 tristate "SoC I2S Audio support for WM8580 on SMDK"
@@ -145,11 +145,11 @@ config SND_SOC_SAMSUNG_RX1950_UDA1380
145 145
146config SND_SOC_SAMSUNG_SMDK_WM9713 146config SND_SOC_SAMSUNG_SMDK_WM9713
147 tristate "SoC AC97 Audio support for SMDK with WM9713" 147 tristate "SoC AC97 Audio support for SMDK with WM9713"
148 depends on SND_SOC_SAMSUNG && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || MACH_SMDKC110 || MACH_SMDKV310 || MACH_SMDKC210) 148 depends on SND_SOC_SAMSUNG && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || MACH_SMDKC110)
149 select SND_SOC_WM9713 149 select SND_SOC_WM9713
150 select SND_SAMSUNG_AC97 150 select SND_SAMSUNG_AC97
151 help 151 help
152 Sat Y if you want to add support for SoC audio on the SMDK. 152 Say Y if you want to add support for SoC audio on the SMDK.
153 153
154config SND_SOC_SMARTQ 154config SND_SOC_SMARTQ
155 tristate "SoC I2S Audio support for SmartQ board" 155 tristate "SoC I2S Audio support for SmartQ board"
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index dc8ff13187f7..b9dc6acbba8c 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -1218,7 +1218,7 @@ int dapm_regulator_event(struct snd_soc_dapm_widget *w,
1218 ret = regulator_allow_bypass(w->regulator, false); 1218 ret = regulator_allow_bypass(w->regulator, false);
1219 if (ret != 0) 1219 if (ret != 0)
1220 dev_warn(w->dapm->dev, 1220 dev_warn(w->dapm->dev,
1221 "ASoC: Failed to bypass %s: %d\n", 1221 "ASoC: Failed to unbypass %s: %d\n",
1222 w->name, ret); 1222 w->name, ret);
1223 } 1223 }
1224 1224
@@ -1228,7 +1228,7 @@ int dapm_regulator_event(struct snd_soc_dapm_widget *w,
1228 ret = regulator_allow_bypass(w->regulator, true); 1228 ret = regulator_allow_bypass(w->regulator, true);
1229 if (ret != 0) 1229 if (ret != 0)
1230 dev_warn(w->dapm->dev, 1230 dev_warn(w->dapm->dev,
1231 "ASoC: Failed to unbypass %s: %d\n", 1231 "ASoC: Failed to bypass %s: %d\n",
1232 w->name, ret); 1232 w->name, ret);
1233 } 1233 }
1234 1234
@@ -3210,15 +3210,11 @@ int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
3210 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); 3210 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
3211 const char *pin = (const char *)kcontrol->private_value; 3211 const char *pin = (const char *)kcontrol->private_value;
3212 3212
3213 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3214
3215 if (ucontrol->value.integer.value[0]) 3213 if (ucontrol->value.integer.value[0])
3216 snd_soc_dapm_enable_pin(&card->dapm, pin); 3214 snd_soc_dapm_enable_pin(&card->dapm, pin);
3217 else 3215 else
3218 snd_soc_dapm_disable_pin(&card->dapm, pin); 3216 snd_soc_dapm_disable_pin(&card->dapm, pin);
3219 3217
3220 mutex_unlock(&card->dapm_mutex);
3221
3222 snd_soc_dapm_sync(&card->dapm); 3218 snd_soc_dapm_sync(&card->dapm);
3223 return 0; 3219 return 0;
3224} 3220}
@@ -3248,7 +3244,7 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3248 ret = regulator_allow_bypass(w->regulator, true); 3244 ret = regulator_allow_bypass(w->regulator, true);
3249 if (ret != 0) 3245 if (ret != 0)
3250 dev_warn(w->dapm->dev, 3246 dev_warn(w->dapm->dev,
3251 "ASoC: Failed to unbypass %s: %d\n", 3247 "ASoC: Failed to bypass %s: %d\n",
3252 w->name, ret); 3248 w->name, ret);
3253 } 3249 }
3254 break; 3250 break;
@@ -3767,23 +3763,52 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3767} 3763}
3768 3764
3769/** 3765/**
3766 * snd_soc_dapm_enable_pin_unlocked - enable pin.
3767 * @dapm: DAPM context
3768 * @pin: pin name
3769 *
3770 * Enables input/output pin and its parents or children widgets iff there is
3771 * a valid audio route and active audio stream.
3772 *
3773 * Requires external locking.
3774 *
3775 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3776 * do any widget power switching.
3777 */
3778int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
3779 const char *pin)
3780{
3781 return snd_soc_dapm_set_pin(dapm, pin, 1);
3782}
3783EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin_unlocked);
3784
3785/**
3770 * snd_soc_dapm_enable_pin - enable pin. 3786 * snd_soc_dapm_enable_pin - enable pin.
3771 * @dapm: DAPM context 3787 * @dapm: DAPM context
3772 * @pin: pin name 3788 * @pin: pin name
3773 * 3789 *
3774 * Enables input/output pin and its parents or children widgets iff there is 3790 * Enables input/output pin and its parents or children widgets iff there is
3775 * a valid audio route and active audio stream. 3791 * a valid audio route and active audio stream.
3792 *
3776 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 3793 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3777 * do any widget power switching. 3794 * do any widget power switching.
3778 */ 3795 */
3779int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin) 3796int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3780{ 3797{
3781 return snd_soc_dapm_set_pin(dapm, pin, 1); 3798 int ret;
3799
3800 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3801
3802 ret = snd_soc_dapm_set_pin(dapm, pin, 1);
3803
3804 mutex_unlock(&dapm->card->dapm_mutex);
3805
3806 return ret;
3782} 3807}
3783EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); 3808EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
3784 3809
3785/** 3810/**
3786 * snd_soc_dapm_force_enable_pin - force a pin to be enabled 3811 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
3787 * @dapm: DAPM context 3812 * @dapm: DAPM context
3788 * @pin: pin name 3813 * @pin: pin name
3789 * 3814 *
@@ -3791,11 +3816,13 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
3791 * intended for use with microphone bias supplies used in microphone 3816 * intended for use with microphone bias supplies used in microphone
3792 * jack detection. 3817 * jack detection.
3793 * 3818 *
3819 * Requires external locking.
3820 *
3794 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 3821 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3795 * do any widget power switching. 3822 * do any widget power switching.
3796 */ 3823 */
3797int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, 3824int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
3798 const char *pin) 3825 const char *pin)
3799{ 3826{
3800 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); 3827 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3801 3828
@@ -3811,25 +3838,103 @@ int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
3811 3838
3812 return 0; 3839 return 0;
3813} 3840}
3841EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin_unlocked);
3842
3843/**
3844 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3845 * @dapm: DAPM context
3846 * @pin: pin name
3847 *
3848 * Enables input/output pin regardless of any other state. This is
3849 * intended for use with microphone bias supplies used in microphone
3850 * jack detection.
3851 *
3852 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3853 * do any widget power switching.
3854 */
3855int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
3856 const char *pin)
3857{
3858 int ret;
3859
3860 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3861
3862 ret = snd_soc_dapm_force_enable_pin_unlocked(dapm, pin);
3863
3864 mutex_unlock(&dapm->card->dapm_mutex);
3865
3866 return ret;
3867}
3814EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); 3868EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
3815 3869
3816/** 3870/**
3871 * snd_soc_dapm_disable_pin_unlocked - disable pin.
3872 * @dapm: DAPM context
3873 * @pin: pin name
3874 *
3875 * Disables input/output pin and its parents or children widgets.
3876 *
3877 * Requires external locking.
3878 *
3879 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3880 * do any widget power switching.
3881 */
3882int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context *dapm,
3883 const char *pin)
3884{
3885 return snd_soc_dapm_set_pin(dapm, pin, 0);
3886}
3887EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin_unlocked);
3888
3889/**
3817 * snd_soc_dapm_disable_pin - disable pin. 3890 * snd_soc_dapm_disable_pin - disable pin.
3818 * @dapm: DAPM context 3891 * @dapm: DAPM context
3819 * @pin: pin name 3892 * @pin: pin name
3820 * 3893 *
3821 * Disables input/output pin and its parents or children widgets. 3894 * Disables input/output pin and its parents or children widgets.
3895 *
3822 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 3896 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3823 * do any widget power switching. 3897 * do any widget power switching.
3824 */ 3898 */
3825int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, 3899int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
3826 const char *pin) 3900 const char *pin)
3827{ 3901{
3828 return snd_soc_dapm_set_pin(dapm, pin, 0); 3902 int ret;
3903
3904 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3905
3906 ret = snd_soc_dapm_set_pin(dapm, pin, 0);
3907
3908 mutex_unlock(&dapm->card->dapm_mutex);
3909
3910 return ret;
3829} 3911}
3830EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); 3912EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
3831 3913
3832/** 3914/**
3915 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
3916 * @dapm: DAPM context
3917 * @pin: pin name
3918 *
3919 * Marks the specified pin as being not connected, disabling it along
3920 * any parent or child widgets. At present this is identical to
3921 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3922 * additional things such as disabling controls which only affect
3923 * paths through the pin.
3924 *
3925 * Requires external locking.
3926 *
3927 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3928 * do any widget power switching.
3929 */
3930int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context *dapm,
3931 const char *pin)
3932{
3933 return snd_soc_dapm_set_pin(dapm, pin, 0);
3934}
3935EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin_unlocked);
3936
3937/**
3833 * snd_soc_dapm_nc_pin - permanently disable pin. 3938 * snd_soc_dapm_nc_pin - permanently disable pin.
3834 * @dapm: DAPM context 3939 * @dapm: DAPM context
3835 * @pin: pin name 3940 * @pin: pin name
@@ -3845,7 +3950,15 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
3845 */ 3950 */
3846int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin) 3951int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3847{ 3952{
3848 return snd_soc_dapm_set_pin(dapm, pin, 0); 3953 int ret;
3954
3955 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3956
3957 ret = snd_soc_dapm_set_pin(dapm, pin, 0);
3958
3959 mutex_unlock(&dapm->card->dapm_mutex);
3960
3961 return ret;
3849} 3962}
3850EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); 3963EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
3851 3964
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 47e1ce771e65..28522bd03b8e 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1989,6 +1989,7 @@ int soc_dpcm_runtime_update(struct snd_soc_card *card)
1989 1989
1990 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list); 1990 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list);
1991 if (paths < 0) { 1991 if (paths < 0) {
1992 dpcm_path_put(&list);
1992 dev_warn(fe->dev, "ASoC: %s no valid %s path\n", 1993 dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
1993 fe->dai_link->name, "playback"); 1994 fe->dai_link->name, "playback");
1994 mutex_unlock(&card->mutex); 1995 mutex_unlock(&card->mutex);
@@ -2018,6 +2019,7 @@ capture:
2018 2019
2019 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list); 2020 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list);
2020 if (paths < 0) { 2021 if (paths < 0) {
2022 dpcm_path_put(&list);
2021 dev_warn(fe->dev, "ASoC: %s no valid %s path\n", 2023 dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
2022 fe->dai_link->name, "capture"); 2024 fe->dai_link->name, "capture");
2023 mutex_unlock(&card->mutex); 2025 mutex_unlock(&card->mutex);
@@ -2082,6 +2084,7 @@ static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
2082 fe->dpcm[stream].runtime = fe_substream->runtime; 2084 fe->dpcm[stream].runtime = fe_substream->runtime;
2083 2085
2084 if (dpcm_path_get(fe, stream, &list) <= 0) { 2086 if (dpcm_path_get(fe, stream, &list) <= 0) {
2087 dpcm_path_put(&list);
2085 dev_dbg(fe->dev, "ASoC: %s no valid %s route\n", 2088 dev_dbg(fe->dev, "ASoC: %s no valid %s route\n",
2086 fe->dai_link->name, stream ? "capture" : "playback"); 2089 fe->dai_link->name, stream ? "capture" : "playback");
2087 } 2090 }
diff --git a/sound/soc/txx9/txx9aclc-ac97.c b/sound/soc/txx9/txx9aclc-ac97.c
index e0305a148568..9edd68db9f48 100644
--- a/sound/soc/txx9/txx9aclc-ac97.c
+++ b/sound/soc/txx9/txx9aclc-ac97.c
@@ -183,14 +183,16 @@ static int txx9aclc_ac97_dev_probe(struct platform_device *pdev)
183 irq = platform_get_irq(pdev, 0); 183 irq = platform_get_irq(pdev, 0);
184 if (irq < 0) 184 if (irq < 0)
185 return irq; 185 return irq;
186
187 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
188 if (!drvdata)
189 return -ENOMEM;
190
186 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 191 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
187 drvdata->base = devm_ioremap_resource(&pdev->dev, r); 192 drvdata->base = devm_ioremap_resource(&pdev->dev, r);
188 if (IS_ERR(drvdata->base)) 193 if (IS_ERR(drvdata->base))
189 return PTR_ERR(drvdata->base); 194 return PTR_ERR(drvdata->base);
190 195
191 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
192 if (!drvdata)
193 return -ENOMEM;
194 platform_set_drvdata(pdev, drvdata); 196 platform_set_drvdata(pdev, drvdata);
195 drvdata->physbase = r->start; 197 drvdata->physbase = r->start;
196 if (sizeof(drvdata->physbase) > sizeof(r->start) && 198 if (sizeof(drvdata->physbase) > sizeof(r->start) &&
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index de9408b83f75..e05a86b7c0da 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -14,6 +14,7 @@ config SND_USB_AUDIO
14 select SND_HWDEP 14 select SND_HWDEP
15 select SND_RAWMIDI 15 select SND_RAWMIDI
16 select SND_PCM 16 select SND_PCM
17 select BITREVERSE
17 help 18 help
18 Say Y here to include support for USB audio and USB MIDI 19 Say Y here to include support for USB audio and USB MIDI
19 devices. 20 devices.
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 44b0ba4feab3..1bed780e21d9 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -883,6 +883,7 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval,
883 } 883 }
884 break; 884 break;
885 885
886 case USB_ID(0x046d, 0x0807): /* Logitech Webcam C500 */
886 case USB_ID(0x046d, 0x0808): 887 case USB_ID(0x046d, 0x0808):
887 case USB_ID(0x046d, 0x0809): 888 case USB_ID(0x046d, 0x0809):
888 case USB_ID(0x046d, 0x081b): /* HD Webcam c310 */ 889 case USB_ID(0x046d, 0x081b): /* HD Webcam c310 */
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
index 32af6b741ef5..d1d72ff50347 100644
--- a/sound/usb/mixer_maps.c
+++ b/sound/usb/mixer_maps.c
@@ -328,6 +328,11 @@ static struct usbmix_name_map gamecom780_map[] = {
328 {} 328 {}
329}; 329};
330 330
331static const struct usbmix_name_map kef_x300a_map[] = {
332 { 10, NULL }, /* firmware locks up (?) when we try to access this FU */
333 { 0 }
334};
335
331/* 336/*
332 * Control map entries 337 * Control map entries
333 */ 338 */
@@ -419,6 +424,10 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
419 .id = USB_ID(0x200c, 0x1018), 424 .id = USB_ID(0x200c, 0x1018),
420 .map = ebox44_map, 425 .map = ebox44_map,
421 }, 426 },
427 {
428 .id = USB_ID(0x27ac, 0x1000),
429 .map = kef_x300a_map,
430 },
422 { 0 } /* terminator */ 431 { 0 } /* terminator */
423}; 432};
424 433
diff --git a/tools/include/linux/hash.h b/tools/include/linux/hash.h
new file mode 100644
index 000000000000..d026c6573018
--- /dev/null
+++ b/tools/include/linux/hash.h
@@ -0,0 +1,5 @@
1#include "../../../include/linux/hash.h"
2
3#ifndef _TOOLS_LINUX_HASH_H
4#define _TOOLS_LINUX_HASH_H
5#endif
diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
index ed2f51e11b80..ce00f7ee6455 100644
--- a/tools/lib/api/Makefile
+++ b/tools/lib/api/Makefile
@@ -9,8 +9,10 @@ LIB_H=
9LIB_OBJS= 9LIB_OBJS=
10 10
11LIB_H += fs/debugfs.h 11LIB_H += fs/debugfs.h
12LIB_H += fs/fs.h
12 13
13LIB_OBJS += $(OUTPUT)fs/debugfs.o 14LIB_OBJS += $(OUTPUT)fs/debugfs.o
15LIB_OBJS += $(OUTPUT)fs/fs.o
14 16
15LIBFILE = libapikfs.a 17LIBFILE = libapikfs.a
16 18
diff --git a/tools/perf/util/fs.c b/tools/lib/api/fs/fs.c
index f5be1f26e724..5b5eb788996e 100644
--- a/tools/perf/util/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -1,8 +1,13 @@
1/* TODO merge/factor in debugfs.c here */
1 2
2/* TODO merge/factor into tools/lib/lk/debugfs.c */ 3#include <errno.h>
4#include <stdbool.h>
5#include <stdio.h>
6#include <string.h>
7#include <sys/vfs.h>
3 8
4#include "util.h" 9#include "debugfs.h"
5#include "util/fs.h" 10#include "fs.h"
6 11
7static const char * const sysfs__fs_known_mountpoints[] = { 12static const char * const sysfs__fs_known_mountpoints[] = {
8 "/sys", 13 "/sys",
diff --git a/tools/perf/util/include/linux/magic.h b/tools/lib/api/fs/fs.h
index 07d63cf3e0f6..cb7049551f33 100644
--- a/tools/perf/util/include/linux/magic.h
+++ b/tools/lib/api/fs/fs.h
@@ -1,9 +1,5 @@
1#ifndef _PERF_LINUX_MAGIC_H_ 1#ifndef __API_FS__
2#define _PERF_LINUX_MAGIC_H_ 2#define __API_FS__
3
4#ifndef DEBUGFS_MAGIC
5#define DEBUGFS_MAGIC 0x64626720
6#endif
7 3
8#ifndef SYSFS_MAGIC 4#ifndef SYSFS_MAGIC
9#define SYSFS_MAGIC 0x62656572 5#define SYSFS_MAGIC 0x62656572
@@ -13,4 +9,6 @@
13#define PROC_SUPER_MAGIC 0x9fa0 9#define PROC_SUPER_MAGIC 0x9fa0
14#endif 10#endif
15 11
16#endif 12const char *sysfs__mountpoint(void);
13const char *procfs__mountpoint(void);
14#endif /* __API_FS__ */
diff --git a/tools/lib/lockdep/Makefile b/tools/lib/lockdep/Makefile
index da8b7aa3d351..07b0b7542511 100644
--- a/tools/lib/lockdep/Makefile
+++ b/tools/lib/lockdep/Makefile
@@ -87,8 +87,8 @@ endif # BUILD_SRC
87# We process the rest of the Makefile if this is the final invocation of make 87# We process the rest of the Makefile if this is the final invocation of make
88ifeq ($(skip-makefile),) 88ifeq ($(skip-makefile),)
89 89
90srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR)) 90srctree := $(realpath $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR)))
91objtree := $(CURDIR) 91objtree := $(realpath $(CURDIR))
92src := $(srctree) 92src := $(srctree)
93obj := $(objtree) 93obj := $(objtree)
94 94
@@ -112,7 +112,7 @@ export Q VERBOSE
112 112
113LIBLOCKDEP_VERSION = $(LL_VERSION).$(LL_PATCHLEVEL).$(LL_EXTRAVERSION) 113LIBLOCKDEP_VERSION = $(LL_VERSION).$(LL_PATCHLEVEL).$(LL_EXTRAVERSION)
114 114
115INCLUDES = -I. -I/usr/local/include -I./uinclude $(CONFIG_INCLUDES) 115INCLUDES = -I. -I/usr/local/include -I./uinclude -I./include $(CONFIG_INCLUDES)
116 116
117# Set compile option CFLAGS if not set elsewhere 117# Set compile option CFLAGS if not set elsewhere
118CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g 118CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
diff --git a/tools/lib/lockdep/preload.c b/tools/lib/lockdep/preload.c
index f8465a811aa5..23bd69cb5ade 100644
--- a/tools/lib/lockdep/preload.c
+++ b/tools/lib/lockdep/preload.c
@@ -418,7 +418,7 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
418 418
419__attribute__((constructor)) static void init_preload(void) 419__attribute__((constructor)) static void init_preload(void)
420{ 420{
421 if (__init_state != done) 421 if (__init_state == done)
422 return; 422 return;
423 423
424#ifndef __GLIBC__ 424#ifndef __GLIBC__
diff --git a/tools/lib/lockdep/run_tests.sh b/tools/lib/lockdep/run_tests.sh
index 5334ad9d39b7..5334ad9d39b7 100644..100755
--- a/tools/lib/lockdep/run_tests.sh
+++ b/tools/lib/lockdep/run_tests.sh
diff --git a/tools/lib/lockdep/uinclude/asm/hash.h b/tools/lib/lockdep/uinclude/asm/hash.h
new file mode 100644
index 000000000000..d82b170bb216
--- /dev/null
+++ b/tools/lib/lockdep/uinclude/asm/hash.h
@@ -0,0 +1,6 @@
1#ifndef __ASM_GENERIC_HASH_H
2#define __ASM_GENERIC_HASH_H
3
4/* Stub */
5
6#endif /* __ASM_GENERIC_HASH_H */
diff --git a/tools/lib/lockdep/uinclude/linux/rcu.h b/tools/lib/lockdep/uinclude/linux/rcu.h
index 4c99fcb5da27..042ee8e463c9 100644
--- a/tools/lib/lockdep/uinclude/linux/rcu.h
+++ b/tools/lib/lockdep/uinclude/linux/rcu.h
@@ -13,4 +13,9 @@ static inline int rcu_is_cpu_idle(void)
13 return 1; 13 return 1;
14} 14}
15 15
16static inline bool rcu_is_watching(void)
17{
18 return false;
19}
20
16#endif 21#endif
diff --git a/tools/net/Makefile b/tools/net/Makefile
index 004cd74734b6..ee577ea03ba5 100644
--- a/tools/net/Makefile
+++ b/tools/net/Makefile
@@ -12,7 +12,7 @@ YACC = bison
12 12
13all : bpf_jit_disasm bpf_dbg bpf_asm 13all : bpf_jit_disasm bpf_dbg bpf_asm
14 14
15bpf_jit_disasm : CFLAGS = -Wall -O2 15bpf_jit_disasm : CFLAGS = -Wall -O2 -DPACKAGE='bpf_jit_disasm'
16bpf_jit_disasm : LDLIBS = -lopcodes -lbfd -ldl 16bpf_jit_disasm : LDLIBS = -lopcodes -lbfd -ldl
17bpf_jit_disasm : bpf_jit_disasm.o 17bpf_jit_disasm : bpf_jit_disasm.o
18 18
diff --git a/tools/perf/Documentation/perf-mem.txt b/tools/perf/Documentation/perf-mem.txt
index 888d51137fbe..1d78a4064da4 100644
--- a/tools/perf/Documentation/perf-mem.txt
+++ b/tools/perf/Documentation/perf-mem.txt
@@ -18,6 +18,10 @@ from it, into perf.data. Perf record options are accepted and are passed through
18"perf mem -t <TYPE> report" displays the result. It invokes perf report with the 18"perf mem -t <TYPE> report" displays the result. It invokes perf report with the
19right set of options to display a memory access profile. 19right set of options to display a memory access profile.
20 20
21Note that on Intel systems the memory latency reported is the use-latency,
22not the pure load (or store latency). Use latency includes any pipeline
23queueing delays in addition to the memory subsystem latency.
24
21OPTIONS 25OPTIONS
22------- 26-------
23<command>...:: 27<command>...::
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index b715cb71592b..1513935c399b 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -136,6 +136,8 @@ Each probe argument follows below syntax.
136'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.) 136'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
137'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type. 137'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
138 138
139On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
140
139LINE SYNTAX 141LINE SYNTAX
140----------- 142-----------
141Line range is described by following syntax. 143Line range is described by following syntax.
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index f41572d0dd76..c0c87c87b60f 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -6,6 +6,7 @@ tools/lib/symbol/kallsyms.c
6tools/lib/symbol/kallsyms.h 6tools/lib/symbol/kallsyms.h
7tools/include/asm/bug.h 7tools/include/asm/bug.h
8tools/include/linux/compiler.h 8tools/include/linux/compiler.h
9tools/include/linux/hash.h
9include/linux/const.h 10include/linux/const.h
10include/linux/perf_event.h 11include/linux/perf_event.h
11include/linux/rbtree.h 12include/linux/rbtree.h
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 7257e7e9e38a..50d875d970c4 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -7,6 +7,8 @@ include config/utilities.mak
7 7
8# Define V to have a more verbose compile. 8# Define V to have a more verbose compile.
9# 9#
10# Define VF to have a more verbose feature check output.
11#
10# Define O to save output files in a separate directory. 12# Define O to save output files in a separate directory.
11# 13#
12# Define ARCH as name of target architecture if you want cross-builds. 14# Define ARCH as name of target architecture if you want cross-builds.
@@ -55,6 +57,9 @@ include config/utilities.mak
55# Define NO_LIBAUDIT if you do not want libaudit support 57# Define NO_LIBAUDIT if you do not want libaudit support
56# 58#
57# Define NO_LIBBIONIC if you do not want bionic support 59# Define NO_LIBBIONIC if you do not want bionic support
60#
61# Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support
62# for dwarf backtrace post unwind.
58 63
59ifeq ($(srctree),) 64ifeq ($(srctree),)
60srctree := $(patsubst %/,%,$(dir $(shell pwd))) 65srctree := $(patsubst %/,%,$(dir $(shell pwd)))
@@ -208,7 +213,7 @@ LIB_H += ../../include/uapi/linux/perf_event.h
208LIB_H += ../../include/linux/rbtree.h 213LIB_H += ../../include/linux/rbtree.h
209LIB_H += ../../include/linux/list.h 214LIB_H += ../../include/linux/list.h
210LIB_H += ../../include/uapi/linux/const.h 215LIB_H += ../../include/uapi/linux/const.h
211LIB_H += ../../include/linux/hash.h 216LIB_H += ../include/linux/hash.h
212LIB_H += ../../include/linux/stringify.h 217LIB_H += ../../include/linux/stringify.h
213LIB_H += util/include/linux/bitmap.h 218LIB_H += util/include/linux/bitmap.h
214LIB_H += util/include/linux/bitops.h 219LIB_H += util/include/linux/bitops.h
@@ -218,9 +223,7 @@ LIB_H += util/include/linux/ctype.h
218LIB_H += util/include/linux/kernel.h 223LIB_H += util/include/linux/kernel.h
219LIB_H += util/include/linux/list.h 224LIB_H += util/include/linux/list.h
220LIB_H += util/include/linux/export.h 225LIB_H += util/include/linux/export.h
221LIB_H += util/include/linux/magic.h
222LIB_H += util/include/linux/poison.h 226LIB_H += util/include/linux/poison.h
223LIB_H += util/include/linux/prefetch.h
224LIB_H += util/include/linux/rbtree.h 227LIB_H += util/include/linux/rbtree.h
225LIB_H += util/include/linux/rbtree_augmented.h 228LIB_H += util/include/linux/rbtree_augmented.h
226LIB_H += util/include/linux/string.h 229LIB_H += util/include/linux/string.h
@@ -244,7 +247,6 @@ LIB_H += util/cache.h
244LIB_H += util/callchain.h 247LIB_H += util/callchain.h
245LIB_H += util/build-id.h 248LIB_H += util/build-id.h
246LIB_H += util/debug.h 249LIB_H += util/debug.h
247LIB_H += util/fs.h
248LIB_H += util/pmu.h 250LIB_H += util/pmu.h
249LIB_H += util/event.h 251LIB_H += util/event.h
250LIB_H += util/evsel.h 252LIB_H += util/evsel.h
@@ -306,7 +308,6 @@ LIB_OBJS += $(OUTPUT)util/annotate.o
306LIB_OBJS += $(OUTPUT)util/build-id.o 308LIB_OBJS += $(OUTPUT)util/build-id.o
307LIB_OBJS += $(OUTPUT)util/config.o 309LIB_OBJS += $(OUTPUT)util/config.o
308LIB_OBJS += $(OUTPUT)util/ctype.o 310LIB_OBJS += $(OUTPUT)util/ctype.o
309LIB_OBJS += $(OUTPUT)util/fs.o
310LIB_OBJS += $(OUTPUT)util/pmu.o 311LIB_OBJS += $(OUTPUT)util/pmu.o
311LIB_OBJS += $(OUTPUT)util/environment.o 312LIB_OBJS += $(OUTPUT)util/environment.o
312LIB_OBJS += $(OUTPUT)util/event.o 313LIB_OBJS += $(OUTPUT)util/event.o
@@ -408,6 +409,11 @@ endif
408LIB_OBJS += $(OUTPUT)tests/code-reading.o 409LIB_OBJS += $(OUTPUT)tests/code-reading.o
409LIB_OBJS += $(OUTPUT)tests/sample-parsing.o 410LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
410LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o 411LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o
412ifndef NO_DWARF_UNWIND
413ifeq ($(ARCH),x86)
414LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o
415endif
416endif
411 417
412BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o 418BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
413BUILTIN_OBJS += $(OUTPUT)builtin-bench.o 419BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
@@ -420,6 +426,9 @@ BUILTIN_OBJS += $(OUTPUT)bench/mem-memset-x86-64-asm.o
420endif 426endif
421BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o 427BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
422BUILTIN_OBJS += $(OUTPUT)bench/mem-memset.o 428BUILTIN_OBJS += $(OUTPUT)bench/mem-memset.o
429BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o
430BUILTIN_OBJS += $(OUTPUT)bench/futex-wake.o
431BUILTIN_OBJS += $(OUTPUT)bench/futex-requeue.o
423 432
424BUILTIN_OBJS += $(OUTPUT)builtin-diff.o 433BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
425BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o 434BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
@@ -475,8 +484,13 @@ ifndef NO_DWARF
475endif # NO_DWARF 484endif # NO_DWARF
476endif # NO_LIBELF 485endif # NO_LIBELF
477 486
487ifndef NO_LIBDW_DWARF_UNWIND
488 LIB_OBJS += $(OUTPUT)util/unwind-libdw.o
489 LIB_H += util/unwind-libdw.h
490endif
491
478ifndef NO_LIBUNWIND 492ifndef NO_LIBUNWIND
479 LIB_OBJS += $(OUTPUT)util/unwind.o 493 LIB_OBJS += $(OUTPUT)util/unwind-libunwind.o
480endif 494endif
481LIB_OBJS += $(OUTPUT)tests/keep-tracking.o 495LIB_OBJS += $(OUTPUT)tests/keep-tracking.o
482 496
@@ -533,6 +547,7 @@ ifeq ($(NO_PERF_REGS),0)
533 ifeq ($(ARCH),x86) 547 ifeq ($(ARCH),x86)
534 LIB_H += arch/x86/include/perf_regs.h 548 LIB_H += arch/x86/include/perf_regs.h
535 endif 549 endif
550 LIB_OBJS += $(OUTPUT)util/perf_regs.o
536endif 551endif
537 552
538ifndef NO_LIBNUMA 553ifndef NO_LIBNUMA
@@ -655,6 +670,9 @@ $(OUTPUT)tests/python-use.o: tests/python-use.c $(OUTPUT)PERF-CFLAGS
655 -DPYTHON='"$(PYTHON_WORD)"' \ 670 -DPYTHON='"$(PYTHON_WORD)"' \
656 $< 671 $<
657 672
673$(OUTPUT)tests/dwarf-unwind.o: tests/dwarf-unwind.c
674 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -fno-optimize-sibling-calls $<
675
658$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS 676$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
659 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< 677 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
660 678
@@ -707,9 +725,15 @@ $(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
707# we depend the various files onto their directories. 725# we depend the various files onto their directories.
708DIRECTORY_DEPS = $(LIB_OBJS) $(BUILTIN_OBJS) $(GTK_OBJS) 726DIRECTORY_DEPS = $(LIB_OBJS) $(BUILTIN_OBJS) $(GTK_OBJS)
709DIRECTORY_DEPS += $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h 727DIRECTORY_DEPS += $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h
710$(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS))) 728# no need to add flex objects, because they depend on bison ones
729DIRECTORY_DEPS += $(OUTPUT)util/parse-events-bison.c
730DIRECTORY_DEPS += $(OUTPUT)util/pmu-bison.c
731
732OUTPUT_DIRECTORIES := $(sort $(dir $(DIRECTORY_DEPS)))
733
734$(DIRECTORY_DEPS): | $(OUTPUT_DIRECTORIES)
711# In the second step, we make a rule to actually create these directories 735# In the second step, we make a rule to actually create these directories
712$(sort $(dir $(DIRECTORY_DEPS))): 736$(OUTPUT_DIRECTORIES):
713 $(QUIET_MKDIR)$(MKDIR) -p $@ 2>/dev/null 737 $(QUIET_MKDIR)$(MKDIR) -p $@ 2>/dev/null
714 738
715$(LIB_FILE): $(LIB_OBJS) 739$(LIB_FILE): $(LIB_OBJS)
@@ -886,7 +910,7 @@ config-clean:
886clean: $(LIBTRACEEVENT)-clean $(LIBAPIKFS)-clean config-clean 910clean: $(LIBTRACEEVENT)-clean $(LIBAPIKFS)-clean config-clean
887 $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf.o $(LANG_BINDINGS) $(GTK_OBJS) 911 $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf.o $(LANG_BINDINGS) $(GTK_OBJS)
888 $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf 912 $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf
889 $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* 913 $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)PERF-FEATURES $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex*
890 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean 914 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
891 $(python-clean) 915 $(python-clean)
892 916
diff --git a/tools/perf/arch/arm/Makefile b/tools/perf/arch/arm/Makefile
index fe9b61e322a5..67e9b3d38e89 100644
--- a/tools/perf/arch/arm/Makefile
+++ b/tools/perf/arch/arm/Makefile
@@ -3,5 +3,5 @@ PERF_HAVE_DWARF_REGS := 1
3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o 3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
4endif 4endif
5ifndef NO_LIBUNWIND 5ifndef NO_LIBUNWIND
6LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind.o 6LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libunwind.o
7endif 7endif
diff --git a/tools/perf/arch/arm/util/unwind.c b/tools/perf/arch/arm/util/unwind-libunwind.c
index da3dc950550c..729ed69a6664 100644
--- a/tools/perf/arch/arm/util/unwind.c
+++ b/tools/perf/arch/arm/util/unwind-libunwind.c
@@ -4,7 +4,7 @@
4#include "perf_regs.h" 4#include "perf_regs.h"
5#include "../../util/unwind.h" 5#include "../../util/unwind.h"
6 6
7int unwind__arch_reg_id(int regnum) 7int libunwind__arch_reg_id(int regnum)
8{ 8{
9 switch (regnum) { 9 switch (regnum) {
10 case UNW_ARM_R0: 10 case UNW_ARM_R0:
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index 8801fe02f206..1641542e3636 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -3,7 +3,14 @@ PERF_HAVE_DWARF_REGS := 1
3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o 3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
4endif 4endif
5ifndef NO_LIBUNWIND 5ifndef NO_LIBUNWIND
6LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind.o 6LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libunwind.o
7endif
8ifndef NO_LIBDW_DWARF_UNWIND
9LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libdw.o
10endif
11ifndef NO_DWARF_UNWIND
12LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/regs_load.o
13LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/dwarf-unwind.o
7endif 14endif
8LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o 15LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
9LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/tsc.o 16LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/tsc.o
diff --git a/tools/perf/arch/x86/include/perf_regs.h b/tools/perf/arch/x86/include/perf_regs.h
index e84ca76aae77..fc819ca34a7e 100644
--- a/tools/perf/arch/x86/include/perf_regs.h
+++ b/tools/perf/arch/x86/include/perf_regs.h
@@ -5,14 +5,20 @@
5#include "../../util/types.h" 5#include "../../util/types.h"
6#include <asm/perf_regs.h> 6#include <asm/perf_regs.h>
7 7
8void perf_regs_load(u64 *regs);
9
8#ifndef HAVE_ARCH_X86_64_SUPPORT 10#ifndef HAVE_ARCH_X86_64_SUPPORT
9#define PERF_REGS_MASK ((1ULL << PERF_REG_X86_32_MAX) - 1) 11#define PERF_REGS_MASK ((1ULL << PERF_REG_X86_32_MAX) - 1)
12#define PERF_REGS_MAX PERF_REG_X86_32_MAX
13#define PERF_SAMPLE_REGS_ABI PERF_SAMPLE_REGS_ABI_32
10#else 14#else
11#define REG_NOSUPPORT ((1ULL << PERF_REG_X86_DS) | \ 15#define REG_NOSUPPORT ((1ULL << PERF_REG_X86_DS) | \
12 (1ULL << PERF_REG_X86_ES) | \ 16 (1ULL << PERF_REG_X86_ES) | \
13 (1ULL << PERF_REG_X86_FS) | \ 17 (1ULL << PERF_REG_X86_FS) | \
14 (1ULL << PERF_REG_X86_GS)) 18 (1ULL << PERF_REG_X86_GS))
15#define PERF_REGS_MASK (((1ULL << PERF_REG_X86_64_MAX) - 1) & ~REG_NOSUPPORT) 19#define PERF_REGS_MASK (((1ULL << PERF_REG_X86_64_MAX) - 1) & ~REG_NOSUPPORT)
20#define PERF_REGS_MAX PERF_REG_X86_64_MAX
21#define PERF_SAMPLE_REGS_ABI PERF_SAMPLE_REGS_ABI_64
16#endif 22#endif
17#define PERF_REG_IP PERF_REG_X86_IP 23#define PERF_REG_IP PERF_REG_X86_IP
18#define PERF_REG_SP PERF_REG_X86_SP 24#define PERF_REG_SP PERF_REG_X86_SP
diff --git a/tools/perf/arch/x86/tests/dwarf-unwind.c b/tools/perf/arch/x86/tests/dwarf-unwind.c
new file mode 100644
index 000000000000..b602ad93ce63
--- /dev/null
+++ b/tools/perf/arch/x86/tests/dwarf-unwind.c
@@ -0,0 +1,59 @@
1#include <string.h>
2#include "perf_regs.h"
3#include "thread.h"
4#include "map.h"
5#include "event.h"
6#include "tests/tests.h"
7
8#define STACK_SIZE 8192
9
10static int sample_ustack(struct perf_sample *sample,
11 struct thread *thread, u64 *regs)
12{
13 struct stack_dump *stack = &sample->user_stack;
14 struct map *map;
15 unsigned long sp;
16 u64 stack_size, *buf;
17
18 buf = malloc(STACK_SIZE);
19 if (!buf) {
20 pr_debug("failed to allocate sample uregs data\n");
21 return -1;
22 }
23
24 sp = (unsigned long) regs[PERF_REG_X86_SP];
25
26 map = map_groups__find(&thread->mg, MAP__FUNCTION, (u64) sp);
27 if (!map) {
28 pr_debug("failed to get stack map\n");
29 return -1;
30 }
31
32 stack_size = map->end - sp;
33 stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size;
34
35 memcpy(buf, (void *) sp, stack_size);
36 stack->data = (char *) buf;
37 stack->size = stack_size;
38 return 0;
39}
40
41int test__arch_unwind_sample(struct perf_sample *sample,
42 struct thread *thread)
43{
44 struct regs_dump *regs = &sample->user_regs;
45 u64 *buf;
46
47 buf = malloc(sizeof(u64) * PERF_REGS_MAX);
48 if (!buf) {
49 pr_debug("failed to allocate sample uregs data\n");
50 return -1;
51 }
52
53 perf_regs_load(buf);
54 regs->abi = PERF_SAMPLE_REGS_ABI;
55 regs->regs = buf;
56 regs->mask = PERF_REGS_MASK;
57
58 return sample_ustack(sample, thread, buf);
59}
diff --git a/tools/perf/arch/x86/tests/regs_load.S b/tools/perf/arch/x86/tests/regs_load.S
new file mode 100644
index 000000000000..99167bf644ea
--- /dev/null
+++ b/tools/perf/arch/x86/tests/regs_load.S
@@ -0,0 +1,92 @@
1
2#include <linux/linkage.h>
3
4#define AX 0
5#define BX 1 * 8
6#define CX 2 * 8
7#define DX 3 * 8
8#define SI 4 * 8
9#define DI 5 * 8
10#define BP 6 * 8
11#define SP 7 * 8
12#define IP 8 * 8
13#define FLAGS 9 * 8
14#define CS 10 * 8
15#define SS 11 * 8
16#define DS 12 * 8
17#define ES 13 * 8
18#define FS 14 * 8
19#define GS 15 * 8
20#define R8 16 * 8
21#define R9 17 * 8
22#define R10 18 * 8
23#define R11 19 * 8
24#define R12 20 * 8
25#define R13 21 * 8
26#define R14 22 * 8
27#define R15 23 * 8
28
29.text
30#ifdef HAVE_ARCH_X86_64_SUPPORT
31ENTRY(perf_regs_load)
32 movq %rax, AX(%rdi)
33 movq %rbx, BX(%rdi)
34 movq %rcx, CX(%rdi)
35 movq %rdx, DX(%rdi)
36 movq %rsi, SI(%rdi)
37 movq %rdi, DI(%rdi)
38 movq %rbp, BP(%rdi)
39
40 leaq 8(%rsp), %rax /* exclude this call. */
41 movq %rax, SP(%rdi)
42
43 movq 0(%rsp), %rax
44 movq %rax, IP(%rdi)
45
46 movq $0, FLAGS(%rdi)
47 movq $0, CS(%rdi)
48 movq $0, SS(%rdi)
49 movq $0, DS(%rdi)
50 movq $0, ES(%rdi)
51 movq $0, FS(%rdi)
52 movq $0, GS(%rdi)
53
54 movq %r8, R8(%rdi)
55 movq %r9, R9(%rdi)
56 movq %r10, R10(%rdi)
57 movq %r11, R11(%rdi)
58 movq %r12, R12(%rdi)
59 movq %r13, R13(%rdi)
60 movq %r14, R14(%rdi)
61 movq %r15, R15(%rdi)
62 ret
63ENDPROC(perf_regs_load)
64#else
65ENTRY(perf_regs_load)
66 push %edi
67 movl 8(%esp), %edi
68 movl %eax, AX(%edi)
69 movl %ebx, BX(%edi)
70 movl %ecx, CX(%edi)
71 movl %edx, DX(%edi)
72 movl %esi, SI(%edi)
73 pop %eax
74 movl %eax, DI(%edi)
75 movl %ebp, BP(%edi)
76
77 leal 4(%esp), %eax /* exclude this call. */
78 movl %eax, SP(%edi)
79
80 movl 0(%esp), %eax
81 movl %eax, IP(%edi)
82
83 movl $0, FLAGS(%edi)
84 movl $0, CS(%edi)
85 movl $0, SS(%edi)
86 movl $0, DS(%edi)
87 movl $0, ES(%edi)
88 movl $0, FS(%edi)
89 movl $0, GS(%edi)
90 ret
91ENDPROC(perf_regs_load)
92#endif
diff --git a/tools/perf/arch/x86/util/unwind-libdw.c b/tools/perf/arch/x86/util/unwind-libdw.c
new file mode 100644
index 000000000000..c4b72176ca83
--- /dev/null
+++ b/tools/perf/arch/x86/util/unwind-libdw.c
@@ -0,0 +1,51 @@
1#include <elfutils/libdwfl.h>
2#include "../../util/unwind-libdw.h"
3#include "../../util/perf_regs.h"
4
5bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
6{
7 struct unwind_info *ui = arg;
8 struct regs_dump *user_regs = &ui->sample->user_regs;
9 Dwarf_Word dwarf_regs[17];
10 unsigned nregs;
11
12#define REG(r) ({ \
13 Dwarf_Word val = 0; \
14 perf_reg_value(&val, user_regs, PERF_REG_X86_##r); \
15 val; \
16})
17
18 if (user_regs->abi == PERF_SAMPLE_REGS_ABI_32) {
19 dwarf_regs[0] = REG(AX);
20 dwarf_regs[1] = REG(CX);
21 dwarf_regs[2] = REG(DX);
22 dwarf_regs[3] = REG(BX);
23 dwarf_regs[4] = REG(SP);
24 dwarf_regs[5] = REG(BP);
25 dwarf_regs[6] = REG(SI);
26 dwarf_regs[7] = REG(DI);
27 dwarf_regs[8] = REG(IP);
28 nregs = 9;
29 } else {
30 dwarf_regs[0] = REG(AX);
31 dwarf_regs[1] = REG(DX);
32 dwarf_regs[2] = REG(CX);
33 dwarf_regs[3] = REG(BX);
34 dwarf_regs[4] = REG(SI);
35 dwarf_regs[5] = REG(DI);
36 dwarf_regs[6] = REG(BP);
37 dwarf_regs[7] = REG(SP);
38 dwarf_regs[8] = REG(R8);
39 dwarf_regs[9] = REG(R9);
40 dwarf_regs[10] = REG(R10);
41 dwarf_regs[11] = REG(R11);
42 dwarf_regs[12] = REG(R12);
43 dwarf_regs[13] = REG(R13);
44 dwarf_regs[14] = REG(R14);
45 dwarf_regs[15] = REG(R15);
46 dwarf_regs[16] = REG(IP);
47 nregs = 17;
48 }
49
50 return dwfl_thread_state_registers(thread, 0, nregs, dwarf_regs);
51}
diff --git a/tools/perf/arch/x86/util/unwind.c b/tools/perf/arch/x86/util/unwind-libunwind.c
index 456a88cf5b37..3261f68c6a7c 100644
--- a/tools/perf/arch/x86/util/unwind.c
+++ b/tools/perf/arch/x86/util/unwind-libunwind.c
@@ -5,7 +5,7 @@
5#include "../../util/unwind.h" 5#include "../../util/unwind.h"
6 6
7#ifdef HAVE_ARCH_X86_64_SUPPORT 7#ifdef HAVE_ARCH_X86_64_SUPPORT
8int unwind__arch_reg_id(int regnum) 8int libunwind__arch_reg_id(int regnum)
9{ 9{
10 int id; 10 int id;
11 11
@@ -69,7 +69,7 @@ int unwind__arch_reg_id(int regnum)
69 return id; 69 return id;
70} 70}
71#else 71#else
72int unwind__arch_reg_id(int regnum) 72int libunwind__arch_reg_id(int regnum)
73{ 73{
74 int id; 74 int id;
75 75
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index 0fdc85269c4d..eba46709b279 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -31,6 +31,9 @@ extern int bench_sched_pipe(int argc, const char **argv, const char *prefix);
31extern int bench_mem_memcpy(int argc, const char **argv, 31extern int bench_mem_memcpy(int argc, const char **argv,
32 const char *prefix __maybe_unused); 32 const char *prefix __maybe_unused);
33extern int bench_mem_memset(int argc, const char **argv, const char *prefix); 33extern int bench_mem_memset(int argc, const char **argv, const char *prefix);
34extern int bench_futex_hash(int argc, const char **argv, const char *prefix);
35extern int bench_futex_wake(int argc, const char **argv, const char *prefix);
36extern int bench_futex_requeue(int argc, const char **argv, const char *prefix);
34 37
35#define BENCH_FORMAT_DEFAULT_STR "default" 38#define BENCH_FORMAT_DEFAULT_STR "default"
36#define BENCH_FORMAT_DEFAULT 0 39#define BENCH_FORMAT_DEFAULT 0
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
new file mode 100644
index 000000000000..a84206e9c4aa
--- /dev/null
+++ b/tools/perf/bench/futex-hash.c
@@ -0,0 +1,212 @@
1/*
2 * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com>
3 *
4 * futex-hash: Stress the hell out of the Linux kernel futex uaddr hashing.
5 *
6 * This program is particularly useful for measuring the kernel's futex hash
7 * table/function implementation. In order for it to make sense, use with as
8 * many threads and futexes as possible.
9 */
10
11#include "../perf.h"
12#include "../util/util.h"
13#include "../util/stat.h"
14#include "../util/parse-options.h"
15#include "../util/header.h"
16#include "bench.h"
17#include "futex.h"
18
19#include <err.h>
20#include <stdlib.h>
21#include <sys/time.h>
22#include <pthread.h>
23
24static unsigned int nthreads = 0;
25static unsigned int nsecs = 10;
26/* amount of futexes per thread */
27static unsigned int nfutexes = 1024;
28static bool fshared = false, done = false, silent = false;
29
30struct timeval start, end, runtime;
31static pthread_mutex_t thread_lock;
32static unsigned int threads_starting;
33static struct stats throughput_stats;
34static pthread_cond_t thread_parent, thread_worker;
35
36struct worker {
37 int tid;
38 u_int32_t *futex;
39 pthread_t thread;
40 unsigned long ops;
41};
42
43static const struct option options[] = {
44 OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
45 OPT_UINTEGER('r', "runtime", &nsecs, "Specify runtime (in seconds)"),
46 OPT_UINTEGER('f', "futexes", &nfutexes, "Specify amount of futexes per threads"),
47 OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"),
48 OPT_BOOLEAN( 'S', "shared", &fshared, "Use shared futexes instead of private ones"),
49 OPT_END()
50};
51
52static const char * const bench_futex_hash_usage[] = {
53 "perf bench futex hash <options>",
54 NULL
55};
56
57static void *workerfn(void *arg)
58{
59 int ret;
60 unsigned int i;
61 struct worker *w = (struct worker *) arg;
62
63 pthread_mutex_lock(&thread_lock);
64 threads_starting--;
65 if (!threads_starting)
66 pthread_cond_signal(&thread_parent);
67 pthread_cond_wait(&thread_worker, &thread_lock);
68 pthread_mutex_unlock(&thread_lock);
69
70 do {
71 for (i = 0; i < nfutexes; i++, w->ops++) {
72 /*
73 * We want the futex calls to fail in order to stress
74 * the hashing of uaddr and not measure other steps,
75 * such as internal waitqueue handling, thus enlarging
76 * the critical region protected by hb->lock.
77 */
78 ret = futex_wait(&w->futex[i], 1234, NULL,
79 fshared ? 0 : FUTEX_PRIVATE_FLAG);
80 if (!silent &&
81 (!ret || errno != EAGAIN || errno != EWOULDBLOCK))
82 warn("Non-expected futex return call");
83 }
84 } while (!done);
85
86 return NULL;
87}
88
89static void toggle_done(int sig __maybe_unused,
90 siginfo_t *info __maybe_unused,
91 void *uc __maybe_unused)
92{
93 /* inform all threads that we're done for the day */
94 done = true;
95 gettimeofday(&end, NULL);
96 timersub(&end, &start, &runtime);
97}
98
99static void print_summary(void)
100{
101 unsigned long avg = avg_stats(&throughput_stats);
102 double stddev = stddev_stats(&throughput_stats);
103
104 printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
105 !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg),
106 (int) runtime.tv_sec);
107}
108
109int bench_futex_hash(int argc, const char **argv,
110 const char *prefix __maybe_unused)
111{
112 int ret = 0;
113 cpu_set_t cpu;
114 struct sigaction act;
115 unsigned int i, ncpus;
116 pthread_attr_t thread_attr;
117 struct worker *worker = NULL;
118
119 argc = parse_options(argc, argv, options, bench_futex_hash_usage, 0);
120 if (argc) {
121 usage_with_options(bench_futex_hash_usage, options);
122 exit(EXIT_FAILURE);
123 }
124
125 ncpus = sysconf(_SC_NPROCESSORS_ONLN);
126
127 sigfillset(&act.sa_mask);
128 act.sa_sigaction = toggle_done;
129 sigaction(SIGINT, &act, NULL);
130
131 if (!nthreads) /* default to the number of CPUs */
132 nthreads = ncpus;
133
134 worker = calloc(nthreads, sizeof(*worker));
135 if (!worker)
136 goto errmem;
137
138 printf("Run summary [PID %d]: %d threads, each operating on %d [%s] futexes for %d secs.\n\n",
139 getpid(), nthreads, nfutexes, fshared ? "shared":"private", nsecs);
140
141 init_stats(&throughput_stats);
142 pthread_mutex_init(&thread_lock, NULL);
143 pthread_cond_init(&thread_parent, NULL);
144 pthread_cond_init(&thread_worker, NULL);
145
146 threads_starting = nthreads;
147 pthread_attr_init(&thread_attr);
148 gettimeofday(&start, NULL);
149 for (i = 0; i < nthreads; i++) {
150 worker[i].tid = i;
151 worker[i].futex = calloc(nfutexes, sizeof(*worker[i].futex));
152 if (!worker[i].futex)
153 goto errmem;
154
155 CPU_ZERO(&cpu);
156 CPU_SET(i % ncpus, &cpu);
157
158 ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu);
159 if (ret)
160 err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
161
162 ret = pthread_create(&worker[i].thread, &thread_attr, workerfn,
163 (void *)(struct worker *) &worker[i]);
164 if (ret)
165 err(EXIT_FAILURE, "pthread_create");
166
167 }
168 pthread_attr_destroy(&thread_attr);
169
170 pthread_mutex_lock(&thread_lock);
171 while (threads_starting)
172 pthread_cond_wait(&thread_parent, &thread_lock);
173 pthread_cond_broadcast(&thread_worker);
174 pthread_mutex_unlock(&thread_lock);
175
176 sleep(nsecs);
177 toggle_done(0, NULL, NULL);
178
179 for (i = 0; i < nthreads; i++) {
180 ret = pthread_join(worker[i].thread, NULL);
181 if (ret)
182 err(EXIT_FAILURE, "pthread_join");
183 }
184
185 /* cleanup & report results */
186 pthread_cond_destroy(&thread_parent);
187 pthread_cond_destroy(&thread_worker);
188 pthread_mutex_destroy(&thread_lock);
189
190 for (i = 0; i < nthreads; i++) {
191 unsigned long t = worker[i].ops/runtime.tv_sec;
192 update_stats(&throughput_stats, t);
193 if (!silent) {
194 if (nfutexes == 1)
195 printf("[thread %2d] futex: %p [ %ld ops/sec ]\n",
196 worker[i].tid, &worker[i].futex[0], t);
197 else
198 printf("[thread %2d] futexes: %p ... %p [ %ld ops/sec ]\n",
199 worker[i].tid, &worker[i].futex[0],
200 &worker[i].futex[nfutexes-1], t);
201 }
202
203 free(worker[i].futex);
204 }
205
206 print_summary();
207
208 free(worker);
209 return ret;
210errmem:
211 err(EXIT_FAILURE, "calloc");
212}
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
new file mode 100644
index 000000000000..a16255876f1d
--- /dev/null
+++ b/tools/perf/bench/futex-requeue.c
@@ -0,0 +1,211 @@
1/*
2 * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com>
3 *
4 * futex-requeue: Block a bunch of threads on futex1 and requeue them
5 * on futex2, N at a time.
6 *
7 * This program is particularly useful to measure the latency of nthread
8 * requeues without waking up any tasks -- thus mimicking a regular futex_wait.
9 */
10
11#include "../perf.h"
12#include "../util/util.h"
13#include "../util/stat.h"
14#include "../util/parse-options.h"
15#include "../util/header.h"
16#include "bench.h"
17#include "futex.h"
18
19#include <err.h>
20#include <stdlib.h>
21#include <sys/time.h>
22#include <pthread.h>
23
24static u_int32_t futex1 = 0, futex2 = 0;
25
26/*
27 * How many tasks to requeue at a time.
28 * Default to 1 in order to make the kernel work more.
29 */
30static unsigned int nrequeue = 1;
31
32/*
33 * There can be significant variance from run to run,
34 * the more repeats, the more exact the overall avg and
35 * the better idea of the futex latency.
36 */
37static unsigned int repeat = 10;
38
39static pthread_t *worker;
40static bool done = 0, silent = 0;
41static pthread_mutex_t thread_lock;
42static pthread_cond_t thread_parent, thread_worker;
43static struct stats requeuetime_stats, requeued_stats;
44static unsigned int ncpus, threads_starting, nthreads = 0;
45
46static const struct option options[] = {
47 OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
48 OPT_UINTEGER('q', "nrequeue", &nrequeue, "Specify amount of threads to requeue at once"),
49 OPT_UINTEGER('r', "repeat", &repeat, "Specify amount of times to repeat the run"),
50 OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"),
51 OPT_END()
52};
53
54static const char * const bench_futex_requeue_usage[] = {
55 "perf bench futex requeue <options>",
56 NULL
57};
58
59static void print_summary(void)
60{
61 double requeuetime_avg = avg_stats(&requeuetime_stats);
62 double requeuetime_stddev = stddev_stats(&requeuetime_stats);
63 unsigned int requeued_avg = avg_stats(&requeued_stats);
64
65 printf("Requeued %d of %d threads in %.4f ms (+-%.2f%%)\n",
66 requeued_avg,
67 nthreads,
68 requeuetime_avg/1e3,
69 rel_stddev_stats(requeuetime_stddev, requeuetime_avg));
70}
71
72static void *workerfn(void *arg __maybe_unused)
73{
74 pthread_mutex_lock(&thread_lock);
75 threads_starting--;
76 if (!threads_starting)
77 pthread_cond_signal(&thread_parent);
78 pthread_cond_wait(&thread_worker, &thread_lock);
79 pthread_mutex_unlock(&thread_lock);
80
81 futex_wait(&futex1, 0, NULL, FUTEX_PRIVATE_FLAG);
82 return NULL;
83}
84
85static void block_threads(pthread_t *w,
86 pthread_attr_t thread_attr)
87{
88 cpu_set_t cpu;
89 unsigned int i;
90
91 threads_starting = nthreads;
92
93 /* create and block all threads */
94 for (i = 0; i < nthreads; i++) {
95 CPU_ZERO(&cpu);
96 CPU_SET(i % ncpus, &cpu);
97
98 if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu))
99 err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
100
101 if (pthread_create(&w[i], &thread_attr, workerfn, NULL))
102 err(EXIT_FAILURE, "pthread_create");
103 }
104}
105
106static void toggle_done(int sig __maybe_unused,
107 siginfo_t *info __maybe_unused,
108 void *uc __maybe_unused)
109{
110 done = true;
111}
112
113int bench_futex_requeue(int argc, const char **argv,
114 const char *prefix __maybe_unused)
115{
116 int ret = 0;
117 unsigned int i, j;
118 struct sigaction act;
119 pthread_attr_t thread_attr;
120
121 argc = parse_options(argc, argv, options, bench_futex_requeue_usage, 0);
122 if (argc)
123 goto err;
124
125 ncpus = sysconf(_SC_NPROCESSORS_ONLN);
126
127 sigfillset(&act.sa_mask);
128 act.sa_sigaction = toggle_done;
129 sigaction(SIGINT, &act, NULL);
130
131 if (!nthreads)
132 nthreads = ncpus;
133
134 worker = calloc(nthreads, sizeof(*worker));
135 if (!worker)
136 err(EXIT_FAILURE, "calloc");
137
138 printf("Run summary [PID %d]: Requeuing %d threads (from %p to %p), "
139 "%d at a time.\n\n",
140 getpid(), nthreads, &futex1, &futex2, nrequeue);
141
142 init_stats(&requeued_stats);
143 init_stats(&requeuetime_stats);
144 pthread_attr_init(&thread_attr);
145 pthread_mutex_init(&thread_lock, NULL);
146 pthread_cond_init(&thread_parent, NULL);
147 pthread_cond_init(&thread_worker, NULL);
148
149 for (j = 0; j < repeat && !done; j++) {
150 unsigned int nrequeued = 0;
151 struct timeval start, end, runtime;
152
153 /* create, launch & block all threads */
154 block_threads(worker, thread_attr);
155
156 /* make sure all threads are already blocked */
157 pthread_mutex_lock(&thread_lock);
158 while (threads_starting)
159 pthread_cond_wait(&thread_parent, &thread_lock);
160 pthread_cond_broadcast(&thread_worker);
161 pthread_mutex_unlock(&thread_lock);
162
163 usleep(100000);
164
165 /* Ok, all threads are patiently blocked, start requeueing */
166 gettimeofday(&start, NULL);
167 for (nrequeued = 0; nrequeued < nthreads; nrequeued += nrequeue)
168 /*
169 * Do not wakeup any tasks blocked on futex1, allowing
170 * us to really measure futex_wait functionality.
171 */
172 futex_cmp_requeue(&futex1, 0, &futex2, 0, nrequeue,
173 FUTEX_PRIVATE_FLAG);
174 gettimeofday(&end, NULL);
175 timersub(&end, &start, &runtime);
176
177 update_stats(&requeued_stats, nrequeued);
178 update_stats(&requeuetime_stats, runtime.tv_usec);
179
180 if (!silent) {
181 printf("[Run %d]: Requeued %d of %d threads in %.4f ms\n",
182 j + 1, nrequeued, nthreads, runtime.tv_usec/1e3);
183 }
184
185 /* everybody should be blocked on futex2, wake'em up */
186 nrequeued = futex_wake(&futex2, nthreads, FUTEX_PRIVATE_FLAG);
187 if (nthreads != nrequeued)
188 warnx("couldn't wakeup all tasks (%d/%d)", nrequeued, nthreads);
189
190 for (i = 0; i < nthreads; i++) {
191 ret = pthread_join(worker[i], NULL);
192 if (ret)
193 err(EXIT_FAILURE, "pthread_join");
194 }
195
196 }
197
198 /* cleanup & report results */
199 pthread_cond_destroy(&thread_parent);
200 pthread_cond_destroy(&thread_worker);
201 pthread_mutex_destroy(&thread_lock);
202 pthread_attr_destroy(&thread_attr);
203
204 print_summary();
205
206 free(worker);
207 return ret;
208err:
209 usage_with_options(bench_futex_requeue_usage, options);
210 exit(EXIT_FAILURE);
211}
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
new file mode 100644
index 000000000000..d096169b161e
--- /dev/null
+++ b/tools/perf/bench/futex-wake.c
@@ -0,0 +1,201 @@
1/*
2 * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com>
3 *
4 * futex-wake: Block a bunch of threads on a futex and wake'em up, N at a time.
5 *
6 * This program is particularly useful to measure the latency of nthread wakeups
7 * in non-error situations: all waiters are queued and all wake calls wakeup
8 * one or more tasks, and thus the waitqueue is never empty.
9 */
10
11#include "../perf.h"
12#include "../util/util.h"
13#include "../util/stat.h"
14#include "../util/parse-options.h"
15#include "../util/header.h"
16#include "bench.h"
17#include "futex.h"
18
19#include <err.h>
20#include <stdlib.h>
21#include <sys/time.h>
22#include <pthread.h>
23
24/* all threads will block on the same futex */
25static u_int32_t futex1 = 0;
26
27/*
28 * How many wakeups to do at a time.
29 * Default to 1 in order to make the kernel work more.
30 */
31static unsigned int nwakes = 1;
32
33/*
34 * There can be significant variance from run to run,
35 * the more repeats, the more exact the overall avg and
36 * the better idea of the futex latency.
37 */
38static unsigned int repeat = 10;
39
40pthread_t *worker;
41static bool done = 0, silent = 0;
42static pthread_mutex_t thread_lock;
43static pthread_cond_t thread_parent, thread_worker;
44static struct stats waketime_stats, wakeup_stats;
45static unsigned int ncpus, threads_starting, nthreads = 0;
46
47static const struct option options[] = {
48 OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
49 OPT_UINTEGER('w', "nwakes", &nwakes, "Specify amount of threads to wake at once"),
50 OPT_UINTEGER('r', "repeat", &repeat, "Specify amount of times to repeat the run"),
51 OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"),
52 OPT_END()
53};
54
55static const char * const bench_futex_wake_usage[] = {
56 "perf bench futex wake <options>",
57 NULL
58};
59
60static void *workerfn(void *arg __maybe_unused)
61{
62 pthread_mutex_lock(&thread_lock);
63 threads_starting--;
64 if (!threads_starting)
65 pthread_cond_signal(&thread_parent);
66 pthread_cond_wait(&thread_worker, &thread_lock);
67 pthread_mutex_unlock(&thread_lock);
68
69 futex_wait(&futex1, 0, NULL, FUTEX_PRIVATE_FLAG);
70 return NULL;
71}
72
73static void print_summary(void)
74{
75 double waketime_avg = avg_stats(&waketime_stats);
76 double waketime_stddev = stddev_stats(&waketime_stats);
77 unsigned int wakeup_avg = avg_stats(&wakeup_stats);
78
79 printf("Wokeup %d of %d threads in %.4f ms (+-%.2f%%)\n",
80 wakeup_avg,
81 nthreads,
82 waketime_avg/1e3,
83 rel_stddev_stats(waketime_stddev, waketime_avg));
84}
85
86static void block_threads(pthread_t *w,
87 pthread_attr_t thread_attr)
88{
89 cpu_set_t cpu;
90 unsigned int i;
91
92 threads_starting = nthreads;
93
94 /* create and block all threads */
95 for (i = 0; i < nthreads; i++) {
96 CPU_ZERO(&cpu);
97 CPU_SET(i % ncpus, &cpu);
98
99 if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu))
100 err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
101
102 if (pthread_create(&w[i], &thread_attr, workerfn, NULL))
103 err(EXIT_FAILURE, "pthread_create");
104 }
105}
106
107static void toggle_done(int sig __maybe_unused,
108 siginfo_t *info __maybe_unused,
109 void *uc __maybe_unused)
110{
111 done = true;
112}
113
114int bench_futex_wake(int argc, const char **argv,
115 const char *prefix __maybe_unused)
116{
117 int ret = 0;
118 unsigned int i, j;
119 struct sigaction act;
120 pthread_attr_t thread_attr;
121
122 argc = parse_options(argc, argv, options, bench_futex_wake_usage, 0);
123 if (argc) {
124 usage_with_options(bench_futex_wake_usage, options);
125 exit(EXIT_FAILURE);
126 }
127
128 ncpus = sysconf(_SC_NPROCESSORS_ONLN);
129
130 sigfillset(&act.sa_mask);
131 act.sa_sigaction = toggle_done;
132 sigaction(SIGINT, &act, NULL);
133
134 if (!nthreads)
135 nthreads = ncpus;
136
137 worker = calloc(nthreads, sizeof(*worker));
138 if (!worker)
139 err(EXIT_FAILURE, "calloc");
140
141 printf("Run summary [PID %d]: blocking on %d threads (at futex %p), "
142 "waking up %d at a time.\n\n",
143 getpid(), nthreads, &futex1, nwakes);
144
145 init_stats(&wakeup_stats);
146 init_stats(&waketime_stats);
147 pthread_attr_init(&thread_attr);
148 pthread_mutex_init(&thread_lock, NULL);
149 pthread_cond_init(&thread_parent, NULL);
150 pthread_cond_init(&thread_worker, NULL);
151
152 for (j = 0; j < repeat && !done; j++) {
153 unsigned int nwoken = 0;
154 struct timeval start, end, runtime;
155
156 /* create, launch & block all threads */
157 block_threads(worker, thread_attr);
158
159 /* make sure all threads are already blocked */
160 pthread_mutex_lock(&thread_lock);
161 while (threads_starting)
162 pthread_cond_wait(&thread_parent, &thread_lock);
163 pthread_cond_broadcast(&thread_worker);
164 pthread_mutex_unlock(&thread_lock);
165
166 usleep(100000);
167
168 /* Ok, all threads are patiently blocked, start waking folks up */
169 gettimeofday(&start, NULL);
170 while (nwoken != nthreads)
171 nwoken += futex_wake(&futex1, nwakes, FUTEX_PRIVATE_FLAG);
172 gettimeofday(&end, NULL);
173 timersub(&end, &start, &runtime);
174
175 update_stats(&wakeup_stats, nwoken);
176 update_stats(&waketime_stats, runtime.tv_usec);
177
178 if (!silent) {
179 printf("[Run %d]: Wokeup %d of %d threads in %.4f ms\n",
180 j + 1, nwoken, nthreads, runtime.tv_usec/1e3);
181 }
182
183 for (i = 0; i < nthreads; i++) {
184 ret = pthread_join(worker[i], NULL);
185 if (ret)
186 err(EXIT_FAILURE, "pthread_join");
187 }
188
189 }
190
191 /* cleanup & report results */
192 pthread_cond_destroy(&thread_parent);
193 pthread_cond_destroy(&thread_worker);
194 pthread_mutex_destroy(&thread_lock);
195 pthread_attr_destroy(&thread_attr);
196
197 print_summary();
198
199 free(worker);
200 return ret;
201}
diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h
new file mode 100644
index 000000000000..71f2844cf97f
--- /dev/null
+++ b/tools/perf/bench/futex.h
@@ -0,0 +1,71 @@
1/*
2 * Glibc independent futex library for testing kernel functionality.
3 * Shamelessly stolen from Darren Hart <dvhltc@us.ibm.com>
4 * http://git.kernel.org/cgit/linux/kernel/git/dvhart/futextest.git/
5 */
6
7#ifndef _FUTEX_H
8#define _FUTEX_H
9
10#include <unistd.h>
11#include <sys/syscall.h>
12#include <sys/types.h>
13#include <linux/futex.h>
14
15/**
16 * futex() - SYS_futex syscall wrapper
17 * @uaddr: address of first futex
18 * @op: futex op code
19 * @val: typically expected value of uaddr, but varies by op
20 * @timeout: typically an absolute struct timespec (except where noted
21 * otherwise). Overloaded by some ops
22 * @uaddr2: address of second futex for some ops\
23 * @val3: varies by op
24 * @opflags: flags to be bitwise OR'd with op, such as FUTEX_PRIVATE_FLAG
25 *
26 * futex() is used by all the following futex op wrappers. It can also be
27 * used for misuse and abuse testing. Generally, the specific op wrappers
28 * should be used instead. It is a macro instead of an static inline function as
29 * some of the types over overloaded (timeout is used for nr_requeue for
30 * example).
31 *
32 * These argument descriptions are the defaults for all
33 * like-named arguments in the following wrappers except where noted below.
34 */
35#define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \
36 syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3)
37
38/**
39 * futex_wait() - block on uaddr with optional timeout
40 * @timeout: relative timeout
41 */
42static inline int
43futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec *timeout, int opflags)
44{
45 return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags);
46}
47
48/**
49 * futex_wake() - wake one or more tasks blocked on uaddr
50 * @nr_wake: wake up to this many tasks
51 */
52static inline int
53futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)
54{
55 return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags);
56}
57
58/**
59* futex_cmp_requeue() - requeue tasks from uaddr to uaddr2
60* @nr_wake: wake up to this many tasks
61* @nr_requeue: requeue up to this many tasks
62*/
63static inline int
64futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wake,
65 int nr_requeue, int opflags)
66{
67 return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2,
68 val, opflags);
69}
70
71#endif /* _FUTEX_H */
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index d4c83c60b9b2..97d86d828190 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -1593,6 +1593,7 @@ static void init_params(struct params *p, const char *name, int argc, const char
1593 p->data_rand_walk = true; 1593 p->data_rand_walk = true;
1594 p->nr_loops = -1; 1594 p->nr_loops = -1;
1595 p->init_random = true; 1595 p->init_random = true;
1596 p->run_all = argc == 1;
1596} 1597}
1597 1598
1598static int run_bench_numa(const char *name, const char **argv) 1599static int run_bench_numa(const char *name, const char **argv)
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index e47f90cc7b98..1e6e77710545 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -12,6 +12,7 @@
12 * sched ... scheduler and IPC performance 12 * sched ... scheduler and IPC performance
13 * mem ... memory access performance 13 * mem ... memory access performance
14 * numa ... NUMA scheduling and MM performance 14 * numa ... NUMA scheduling and MM performance
15 * futex ... Futex performance
15 */ 16 */
16#include "perf.h" 17#include "perf.h"
17#include "util/util.h" 18#include "util/util.h"
@@ -54,6 +55,14 @@ static struct bench mem_benchmarks[] = {
54 { NULL, NULL, NULL } 55 { NULL, NULL, NULL }
55}; 56};
56 57
58static struct bench futex_benchmarks[] = {
59 { "hash", "Benchmark for futex hash table", bench_futex_hash },
60 { "wake", "Benchmark for futex wake calls", bench_futex_wake },
61 { "requeue", "Benchmark for futex requeue calls", bench_futex_requeue },
62 { "all", "Test all futex benchmarks", NULL },
63 { NULL, NULL, NULL }
64};
65
57struct collection { 66struct collection {
58 const char *name; 67 const char *name;
59 const char *summary; 68 const char *summary;
@@ -61,11 +70,12 @@ struct collection {
61}; 70};
62 71
63static struct collection collections[] = { 72static struct collection collections[] = {
64 { "sched", "Scheduler and IPC benchmarks", sched_benchmarks }, 73 { "sched", "Scheduler and IPC benchmarks", sched_benchmarks },
65 { "mem", "Memory access benchmarks", mem_benchmarks }, 74 { "mem", "Memory access benchmarks", mem_benchmarks },
66#ifdef HAVE_LIBNUMA_SUPPORT 75#ifdef HAVE_LIBNUMA_SUPPORT
67 { "numa", "NUMA scheduling and MM benchmarks", numa_benchmarks }, 76 { "numa", "NUMA scheduling and MM benchmarks", numa_benchmarks },
68#endif 77#endif
78 {"futex", "Futex stressing benchmarks", futex_benchmarks },
69 { "all", "All benchmarks", NULL }, 79 { "all", "All benchmarks", NULL },
70 { NULL, NULL, NULL } 80 { NULL, NULL, NULL }
71}; 81};
@@ -76,7 +86,7 @@ static struct collection collections[] = {
76 86
77/* Iterate over all benchmarks within a collection: */ 87/* Iterate over all benchmarks within a collection: */
78#define for_each_bench(coll, bench) \ 88#define for_each_bench(coll, bench) \
79 for (bench = coll->benchmarks; bench->name; bench++) 89 for (bench = coll->benchmarks; bench && bench->name; bench++)
80 90
81static void dump_benchmarks(struct collection *coll) 91static void dump_benchmarks(struct collection *coll)
82{ 92{
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index cfede86161d8..b22dbb16f877 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -63,11 +63,35 @@ static int build_id_cache__kcore_dir(char *dir, size_t sz)
63 return 0; 63 return 0;
64} 64}
65 65
66static bool same_kallsyms_reloc(const char *from_dir, char *to_dir)
67{
68 char from[PATH_MAX];
69 char to[PATH_MAX];
70 const char *name;
71 u64 addr1 = 0, addr2 = 0;
72 int i;
73
74 scnprintf(from, sizeof(from), "%s/kallsyms", from_dir);
75 scnprintf(to, sizeof(to), "%s/kallsyms", to_dir);
76
77 for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
78 addr1 = kallsyms__get_function_start(from, name);
79 if (addr1)
80 break;
81 }
82
83 if (name)
84 addr2 = kallsyms__get_function_start(to, name);
85
86 return addr1 == addr2;
87}
88
66static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir, 89static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir,
67 size_t to_dir_sz) 90 size_t to_dir_sz)
68{ 91{
69 char from[PATH_MAX]; 92 char from[PATH_MAX];
70 char to[PATH_MAX]; 93 char to[PATH_MAX];
94 char to_subdir[PATH_MAX];
71 struct dirent *dent; 95 struct dirent *dent;
72 int ret = -1; 96 int ret = -1;
73 DIR *d; 97 DIR *d;
@@ -86,10 +110,11 @@ static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir,
86 continue; 110 continue;
87 scnprintf(to, sizeof(to), "%s/%s/modules", to_dir, 111 scnprintf(to, sizeof(to), "%s/%s/modules", to_dir,
88 dent->d_name); 112 dent->d_name);
89 if (!compare_proc_modules(from, to)) { 113 scnprintf(to_subdir, sizeof(to_subdir), "%s/%s",
90 scnprintf(to, sizeof(to), "%s/%s", to_dir, 114 to_dir, dent->d_name);
91 dent->d_name); 115 if (!compare_proc_modules(from, to) &&
92 strlcpy(to_dir, to, to_dir_sz); 116 same_kallsyms_reloc(from_dir, to_subdir)) {
117 strlcpy(to_dir, to_subdir, to_dir_sz);
93 ret = 0; 118 ret = 0;
94 break; 119 break;
95 } 120 }
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index a77e31246c00..204fffe22532 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -952,8 +952,8 @@ static int hpp__entry_global(struct perf_hpp_fmt *_fmt, struct perf_hpp *hpp,
952 dfmt->header_width, buf); 952 dfmt->header_width, buf);
953} 953}
954 954
955static int hpp__header(struct perf_hpp_fmt *fmt, 955static int hpp__header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
956 struct perf_hpp *hpp) 956 struct perf_evsel *evsel __maybe_unused)
957{ 957{
958 struct diff_hpp_fmt *dfmt = 958 struct diff_hpp_fmt *dfmt =
959 container_of(fmt, struct diff_hpp_fmt, fmt); 959 container_of(fmt, struct diff_hpp_fmt, fmt);
@@ -963,7 +963,8 @@ static int hpp__header(struct perf_hpp_fmt *fmt,
963} 963}
964 964
965static int hpp__width(struct perf_hpp_fmt *fmt, 965static int hpp__width(struct perf_hpp_fmt *fmt,
966 struct perf_hpp *hpp __maybe_unused) 966 struct perf_hpp *hpp __maybe_unused,
967 struct perf_evsel *evsel __maybe_unused)
967{ 968{
968 struct diff_hpp_fmt *dfmt = 969 struct diff_hpp_fmt *dfmt =
969 container_of(fmt, struct diff_hpp_fmt, fmt); 970 container_of(fmt, struct diff_hpp_fmt, fmt);
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index b3466018bbd7..3a7387551369 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -312,7 +312,6 @@ found:
312 sample_sw.period = sample->period; 312 sample_sw.period = sample->period;
313 sample_sw.time = sample->time; 313 sample_sw.time = sample->time;
314 perf_event__synthesize_sample(event_sw, evsel->attr.sample_type, 314 perf_event__synthesize_sample(event_sw, evsel->attr.sample_type,
315 evsel->attr.sample_regs_user,
316 evsel->attr.read_format, &sample_sw, 315 evsel->attr.read_format, &sample_sw,
317 false); 316 false);
318 build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); 317 build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine);
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index a7350519c63f..21c164b8f9db 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1691,17 +1691,15 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
1691 OPT_END() 1691 OPT_END()
1692 }; 1692 };
1693 1693
1694 1694 const char *const kvm_subcommands[] = { "top", "record", "report", "diff",
1695 const char * const kvm_usage[] = { 1695 "buildid-list", "stat", NULL };
1696 "perf kvm [<options>] {top|record|report|diff|buildid-list|stat}", 1696 const char *kvm_usage[] = { NULL, NULL };
1697 NULL
1698 };
1699 1697
1700 perf_host = 0; 1698 perf_host = 0;
1701 perf_guest = 1; 1699 perf_guest = 1;
1702 1700
1703 argc = parse_options(argc, argv, kvm_options, kvm_usage, 1701 argc = parse_options_subcommand(argc, argv, kvm_options, kvm_subcommands, kvm_usage,
1704 PARSE_OPT_STOP_AT_NON_OPTION); 1702 PARSE_OPT_STOP_AT_NON_OPTION);
1705 if (!argc) 1703 if (!argc)
1706 usage_with_options(kvm_usage, kvm_options); 1704 usage_with_options(kvm_usage, kvm_options);
1707 1705
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 78948882e3de..cdcd4eb3a57d 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -268,9 +268,9 @@ static int opt_set_filter(const struct option *opt __maybe_unused,
268 return 0; 268 return 0;
269} 269}
270 270
271static void init_params(void) 271static int init_params(void)
272{ 272{
273 line_range__init(&params.line_range); 273 return line_range__init(&params.line_range);
274} 274}
275 275
276static void cleanup_params(void) 276static void cleanup_params(void)
@@ -515,9 +515,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix)
515{ 515{
516 int ret; 516 int ret;
517 517
518 init_params(); 518 ret = init_params();
519 ret = __cmd_probe(argc, argv, prefix); 519 if (!ret) {
520 cleanup_params(); 520 ret = __cmd_probe(argc, argv, prefix);
521 cleanup_params();
522 }
521 523
522 return ret; 524 return ret;
523} 525}
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3c394bf16fa8..eb524f91bffe 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -287,10 +287,7 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data)
287 * have no _text sometimes. 287 * have no _text sometimes.
288 */ 288 */
289 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event, 289 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
290 machine, "_text"); 290 machine);
291 if (err < 0)
292 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
293 machine, "_stext");
294 if (err < 0) 291 if (err < 0)
295 pr_err("Couldn't record guest kernel [%d]'s reference" 292 pr_err("Couldn't record guest kernel [%d]'s reference"
296 " relocation symbol.\n", machine->pid); 293 " relocation symbol.\n", machine->pid);
@@ -457,10 +454,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
457 } 454 }
458 455
459 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event, 456 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
460 machine, "_text"); 457 machine);
461 if (err < 0)
462 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
463 machine, "_stext");
464 if (err < 0) 458 if (err < 0)
465 pr_err("Couldn't record kernel reference relocation symbol\n" 459 pr_err("Couldn't record kernel reference relocation symbol\n"
466 "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n" 460 "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
@@ -655,7 +649,7 @@ error:
655 return ret; 649 return ret;
656} 650}
657 651
658#ifdef HAVE_LIBUNWIND_SUPPORT 652#ifdef HAVE_DWARF_UNWIND_SUPPORT
659static int get_stack_size(char *str, unsigned long *_size) 653static int get_stack_size(char *str, unsigned long *_size)
660{ 654{
661 char *endptr; 655 char *endptr;
@@ -681,7 +675,7 @@ static int get_stack_size(char *str, unsigned long *_size)
681 max_size, str); 675 max_size, str);
682 return -1; 676 return -1;
683} 677}
684#endif /* HAVE_LIBUNWIND_SUPPORT */ 678#endif /* HAVE_DWARF_UNWIND_SUPPORT */
685 679
686int record_parse_callchain(const char *arg, struct record_opts *opts) 680int record_parse_callchain(const char *arg, struct record_opts *opts)
687{ 681{
@@ -710,7 +704,7 @@ int record_parse_callchain(const char *arg, struct record_opts *opts)
710 "needed for -g fp\n"); 704 "needed for -g fp\n");
711 break; 705 break;
712 706
713#ifdef HAVE_LIBUNWIND_SUPPORT 707#ifdef HAVE_DWARF_UNWIND_SUPPORT
714 /* Dwarf style */ 708 /* Dwarf style */
715 } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { 709 } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) {
716 const unsigned long default_stack_dump_size = 8192; 710 const unsigned long default_stack_dump_size = 8192;
@@ -726,7 +720,7 @@ int record_parse_callchain(const char *arg, struct record_opts *opts)
726 ret = get_stack_size(tok, &size); 720 ret = get_stack_size(tok, &size);
727 opts->stack_dump_size = size; 721 opts->stack_dump_size = size;
728 } 722 }
729#endif /* HAVE_LIBUNWIND_SUPPORT */ 723#endif /* HAVE_DWARF_UNWIND_SUPPORT */
730 } else { 724 } else {
731 pr_err("callchain: Unknown --call-graph option " 725 pr_err("callchain: Unknown --call-graph option "
732 "value: %s\n", arg); 726 "value: %s\n", arg);
@@ -741,7 +735,9 @@ int record_parse_callchain(const char *arg, struct record_opts *opts)
741 735
742static void callchain_debug(struct record_opts *opts) 736static void callchain_debug(struct record_opts *opts)
743{ 737{
744 pr_debug("callchain: type %d\n", opts->call_graph); 738 static const char *str[CALLCHAIN_MAX] = { "NONE", "FP", "DWARF" };
739
740 pr_debug("callchain: type %s\n", str[opts->call_graph]);
745 741
746 if (opts->call_graph == CALLCHAIN_DWARF) 742 if (opts->call_graph == CALLCHAIN_DWARF)
747 pr_debug("callchain: stack dump size %d\n", 743 pr_debug("callchain: stack dump size %d\n",
@@ -755,6 +751,8 @@ int record_parse_callchain_opt(const struct option *opt,
755 struct record_opts *opts = opt->value; 751 struct record_opts *opts = opt->value;
756 int ret; 752 int ret;
757 753
754 opts->call_graph_enabled = !unset;
755
758 /* --no-call-graph */ 756 /* --no-call-graph */
759 if (unset) { 757 if (unset) {
760 opts->call_graph = CALLCHAIN_NONE; 758 opts->call_graph = CALLCHAIN_NONE;
@@ -775,6 +773,8 @@ int record_callchain_opt(const struct option *opt,
775{ 773{
776 struct record_opts *opts = opt->value; 774 struct record_opts *opts = opt->value;
777 775
776 opts->call_graph_enabled = !unset;
777
778 if (opts->call_graph == CALLCHAIN_NONE) 778 if (opts->call_graph == CALLCHAIN_NONE)
779 opts->call_graph = CALLCHAIN_FP; 779 opts->call_graph = CALLCHAIN_FP;
780 780
@@ -782,6 +782,16 @@ int record_callchain_opt(const struct option *opt,
782 return 0; 782 return 0;
783} 783}
784 784
785static int perf_record_config(const char *var, const char *value, void *cb)
786{
787 struct record *rec = cb;
788
789 if (!strcmp(var, "record.call-graph"))
790 return record_parse_callchain(value, &rec->opts);
791
792 return perf_default_config(var, value, cb);
793}
794
785static const char * const record_usage[] = { 795static const char * const record_usage[] = {
786 "perf record [<options>] [<command>]", 796 "perf record [<options>] [<command>]",
787 "perf record [<options>] -- <command> [<options>]", 797 "perf record [<options>] -- <command> [<options>]",
@@ -813,7 +823,7 @@ static struct record record = {
813 823
814#define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace) recording: " 824#define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace) recording: "
815 825
816#ifdef HAVE_LIBUNWIND_SUPPORT 826#ifdef HAVE_DWARF_UNWIND_SUPPORT
817const char record_callchain_help[] = CALLCHAIN_HELP "fp dwarf"; 827const char record_callchain_help[] = CALLCHAIN_HELP "fp dwarf";
818#else 828#else
819const char record_callchain_help[] = CALLCHAIN_HELP "fp"; 829const char record_callchain_help[] = CALLCHAIN_HELP "fp";
@@ -913,6 +923,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
913 if (rec->evlist == NULL) 923 if (rec->evlist == NULL)
914 return -ENOMEM; 924 return -ENOMEM;
915 925
926 perf_config(perf_record_config, rec);
927
916 argc = parse_options(argc, argv, record_options, record_usage, 928 argc = parse_options(argc, argv, record_options, record_usage,
917 PARSE_OPT_STOP_AT_NON_OPTION); 929 PARSE_OPT_STOP_AT_NON_OPTION);
918 if (!argc && target__none(&rec->opts.target)) 930 if (!argc && target__none(&rec->opts.target))
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 3c53ec268fbc..c8f21137dfd8 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -75,13 +75,10 @@ static int report__config(const char *var, const char *value, void *cb)
75 return perf_default_config(var, value, cb); 75 return perf_default_config(var, value, cb);
76} 76}
77 77
78static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_location *al, 78static int report__add_mem_hist_entry(struct report *rep, struct addr_location *al,
79 struct perf_sample *sample, struct perf_evsel *evsel, 79 struct perf_sample *sample, struct perf_evsel *evsel)
80 union perf_event *event)
81{ 80{
82 struct report *rep = container_of(tool, struct report, tool);
83 struct symbol *parent = NULL; 81 struct symbol *parent = NULL;
84 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
85 struct hist_entry *he; 82 struct hist_entry *he;
86 struct mem_info *mi, *mx; 83 struct mem_info *mi, *mx;
87 uint64_t cost; 84 uint64_t cost;
@@ -90,7 +87,7 @@ static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_locati
90 if (err) 87 if (err)
91 return err; 88 return err;
92 89
93 mi = machine__resolve_mem(al->machine, al->thread, sample, cpumode); 90 mi = sample__resolve_mem(sample, al);
94 if (!mi) 91 if (!mi)
95 return -ENOMEM; 92 return -ENOMEM;
96 93
@@ -113,14 +110,16 @@ static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_locati
113 if (!he) 110 if (!he)
114 return -ENOMEM; 111 return -ENOMEM;
115 112
116 err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); 113 if (ui__has_annotation()) {
117 if (err) 114 err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
118 goto out; 115 if (err)
116 goto out;
119 117
120 mx = he->mem_info; 118 mx = he->mem_info;
121 err = addr_map_symbol__inc_samples(&mx->daddr, evsel->idx); 119 err = addr_map_symbol__inc_samples(&mx->daddr, evsel->idx);
122 if (err) 120 if (err)
123 goto out; 121 goto out;
122 }
124 123
125 evsel->hists.stats.total_period += cost; 124 evsel->hists.stats.total_period += cost;
126 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); 125 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
@@ -129,10 +128,9 @@ out:
129 return err; 128 return err;
130} 129}
131 130
132static int report__add_branch_hist_entry(struct perf_tool *tool, struct addr_location *al, 131static int report__add_branch_hist_entry(struct report *rep, struct addr_location *al,
133 struct perf_sample *sample, struct perf_evsel *evsel) 132 struct perf_sample *sample, struct perf_evsel *evsel)
134{ 133{
135 struct report *rep = container_of(tool, struct report, tool);
136 struct symbol *parent = NULL; 134 struct symbol *parent = NULL;
137 unsigned i; 135 unsigned i;
138 struct hist_entry *he; 136 struct hist_entry *he;
@@ -142,8 +140,7 @@ static int report__add_branch_hist_entry(struct perf_tool *tool, struct addr_loc
142 if (err) 140 if (err)
143 return err; 141 return err;
144 142
145 bi = machine__resolve_bstack(al->machine, al->thread, 143 bi = sample__resolve_bstack(sample, al);
146 sample->branch_stack);
147 if (!bi) 144 if (!bi)
148 return -ENOMEM; 145 return -ENOMEM;
149 146
@@ -164,14 +161,18 @@ static int report__add_branch_hist_entry(struct perf_tool *tool, struct addr_loc
164 he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL, 161 he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL,
165 1, 1, 0); 162 1, 1, 0);
166 if (he) { 163 if (he) {
167 bx = he->branch_info; 164 if (ui__has_annotation()) {
168 err = addr_map_symbol__inc_samples(&bx->from, evsel->idx); 165 bx = he->branch_info;
169 if (err) 166 err = addr_map_symbol__inc_samples(&bx->from,
170 goto out; 167 evsel->idx);
171 168 if (err)
172 err = addr_map_symbol__inc_samples(&bx->to, evsel->idx); 169 goto out;
173 if (err) 170
174 goto out; 171 err = addr_map_symbol__inc_samples(&bx->to,
172 evsel->idx);
173 if (err)
174 goto out;
175 }
175 176
176 evsel->hists.stats.total_period += 1; 177 evsel->hists.stats.total_period += 1;
177 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); 178 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
@@ -184,10 +185,9 @@ out:
184 return err; 185 return err;
185} 186}
186 187
187static int report__add_hist_entry(struct perf_tool *tool, struct perf_evsel *evsel, 188static int report__add_hist_entry(struct report *rep, struct perf_evsel *evsel,
188 struct addr_location *al, struct perf_sample *sample) 189 struct addr_location *al, struct perf_sample *sample)
189{ 190{
190 struct report *rep = container_of(tool, struct report, tool);
191 struct symbol *parent = NULL; 191 struct symbol *parent = NULL;
192 struct hist_entry *he; 192 struct hist_entry *he;
193 int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack); 193 int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack);
@@ -205,7 +205,9 @@ static int report__add_hist_entry(struct perf_tool *tool, struct perf_evsel *evs
205 if (err) 205 if (err)
206 goto out; 206 goto out;
207 207
208 err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); 208 if (ui__has_annotation())
209 err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
210
209 evsel->hists.stats.total_period += sample->period; 211 evsel->hists.stats.total_period += sample->period;
210 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); 212 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
211out: 213out:
@@ -229,25 +231,25 @@ static int process_sample_event(struct perf_tool *tool,
229 return -1; 231 return -1;
230 } 232 }
231 233
232 if (al.filtered || (rep->hide_unresolved && al.sym == NULL)) 234 if (rep->hide_unresolved && al.sym == NULL)
233 return 0; 235 return 0;
234 236
235 if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap)) 237 if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
236 return 0; 238 return 0;
237 239
238 if (sort__mode == SORT_MODE__BRANCH) { 240 if (sort__mode == SORT_MODE__BRANCH) {
239 ret = report__add_branch_hist_entry(tool, &al, sample, evsel); 241 ret = report__add_branch_hist_entry(rep, &al, sample, evsel);
240 if (ret < 0) 242 if (ret < 0)
241 pr_debug("problem adding lbr entry, skipping event\n"); 243 pr_debug("problem adding lbr entry, skipping event\n");
242 } else if (rep->mem_mode == 1) { 244 } else if (rep->mem_mode == 1) {
243 ret = report__add_mem_hist_entry(tool, &al, sample, evsel, event); 245 ret = report__add_mem_hist_entry(rep, &al, sample, evsel);
244 if (ret < 0) 246 if (ret < 0)
245 pr_debug("problem adding mem entry, skipping event\n"); 247 pr_debug("problem adding mem entry, skipping event\n");
246 } else { 248 } else {
247 if (al.map != NULL) 249 if (al.map != NULL)
248 al.map->dso->hit = 1; 250 al.map->dso->hit = 1;
249 251
250 ret = report__add_hist_entry(tool, evsel, &al, sample); 252 ret = report__add_hist_entry(rep, evsel, &al, sample);
251 if (ret < 0) 253 if (ret < 0)
252 pr_debug("problem incrementing symbol period, skipping event\n"); 254 pr_debug("problem incrementing symbol period, skipping event\n");
253 } 255 }
@@ -926,7 +928,7 @@ repeat:
926 * so don't allocate extra space that won't be used in the stdio 928 * so don't allocate extra space that won't be used in the stdio
927 * implementation. 929 * implementation.
928 */ 930 */
929 if (use_browser == 1 && sort__has_sym) { 931 if (ui__has_annotation()) {
930 symbol_conf.priv_size = sizeof(struct annotation); 932 symbol_conf.priv_size = sizeof(struct annotation);
931 machines__set_symbol_filter(&session->machines, 933 machines__set_symbol_filter(&session->machines,
932 symbol__annotate_init); 934 symbol__annotate_init);
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 6a76a07b6789..9ac0a495c954 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1124,7 +1124,7 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_
1124 1124
1125 avg = work_list->total_lat / work_list->nb_atoms; 1125 avg = work_list->total_lat / work_list->nb_atoms;
1126 1126
1127 printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max at: %9.6f s\n", 1127 printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max at: %13.6f s\n",
1128 (double)work_list->total_runtime / 1e6, 1128 (double)work_list->total_runtime / 1e6,
1129 work_list->nb_atoms, (double)avg / 1e6, 1129 work_list->nb_atoms, (double)avg / 1e6,
1130 (double)work_list->max_lat / 1e6, 1130 (double)work_list->max_lat / 1e6,
@@ -1527,9 +1527,9 @@ static int perf_sched__lat(struct perf_sched *sched)
1527 1527
1528 perf_sched__sort_lat(sched); 1528 perf_sched__sort_lat(sched);
1529 1529
1530 printf("\n ---------------------------------------------------------------------------------------------------------------\n"); 1530 printf("\n -----------------------------------------------------------------------------------------------------------------\n");
1531 printf(" Task | Runtime ms | Switches | Average delay ms | Maximum delay ms | Maximum delay at |\n"); 1531 printf(" Task | Runtime ms | Switches | Average delay ms | Maximum delay ms | Maximum delay at |\n");
1532 printf(" ---------------------------------------------------------------------------------------------------------------\n"); 1532 printf(" -----------------------------------------------------------------------------------------------------------------\n");
1533 1533
1534 next = rb_first(&sched->sorted_atom_root); 1534 next = rb_first(&sched->sorted_atom_root);
1535 1535
@@ -1541,7 +1541,7 @@ static int perf_sched__lat(struct perf_sched *sched)
1541 next = rb_next(next); 1541 next = rb_next(next);
1542 } 1542 }
1543 1543
1544 printf(" -----------------------------------------------------------------------------------------\n"); 1544 printf(" -----------------------------------------------------------------------------------------------------------------\n");
1545 printf(" TOTAL: |%11.3f ms |%9" PRIu64 " |\n", 1545 printf(" TOTAL: |%11.3f ms |%9" PRIu64 " |\n",
1546 (double)sched->all_runtime / 1e6, sched->all_count); 1546 (double)sched->all_runtime / 1e6, sched->all_count);
1547 1547
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 25526d6eae59..74db2568b867 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -494,7 +494,7 @@ static const char *cat_backtrace(union perf_event *event,
494 continue; 494 continue;
495 } 495 }
496 496
497 tal.filtered = false; 497 tal.filtered = 0;
498 thread__find_addr_location(al.thread, machine, cpumode, 498 thread__find_addr_location(al.thread, machine, cpumode,
499 MAP__FUNCTION, ip, &tal); 499 MAP__FUNCTION, ip, &tal);
500 500
@@ -1238,7 +1238,7 @@ static int timechart__record(struct timechart *tchart, int argc, const char **ar
1238 for (i = 0; i < old_power_args_nr; i++) 1238 for (i = 0; i < old_power_args_nr; i++)
1239 *p++ = strdup(old_power_args[i]); 1239 *p++ = strdup(old_power_args[i]);
1240 1240
1241 for (j = 1; j < (unsigned int)argc; j++) 1241 for (j = 0; j < (unsigned int)argc; j++)
1242 *p++ = argv[j]; 1242 *p++ = argv[j];
1243 1243
1244 return cmd_record(rec_argc, rec_argv, NULL); 1244 return cmd_record(rec_argc, rec_argv, NULL);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 76cd510d34d0..65aaa5bbf7ec 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -176,7 +176,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,
176{ 176{
177 struct annotation *notes; 177 struct annotation *notes;
178 struct symbol *sym; 178 struct symbol *sym;
179 int err; 179 int err = 0;
180 180
181 if (he == NULL || he->ms.sym == NULL || 181 if (he == NULL || he->ms.sym == NULL ||
182 ((top->sym_filter_entry == NULL || 182 ((top->sym_filter_entry == NULL ||
@@ -190,7 +190,9 @@ static void perf_top__record_precise_ip(struct perf_top *top,
190 return; 190 return;
191 191
192 ip = he->ms.map->map_ip(he->ms.map, ip); 192 ip = he->ms.map->map_ip(he->ms.map, ip);
193 err = hist_entry__inc_addr_samples(he, counter, ip); 193
194 if (ui__has_annotation())
195 err = hist_entry__inc_addr_samples(he, counter, ip);
194 196
195 pthread_mutex_unlock(&notes->lock); 197 pthread_mutex_unlock(&notes->lock);
196 198
@@ -991,6 +993,16 @@ parse_callchain_opt(const struct option *opt, const char *arg, int unset)
991 return record_parse_callchain_opt(opt, arg, unset); 993 return record_parse_callchain_opt(opt, arg, unset);
992} 994}
993 995
996static int perf_top_config(const char *var, const char *value, void *cb)
997{
998 struct perf_top *top = cb;
999
1000 if (!strcmp(var, "top.call-graph"))
1001 return record_parse_callchain(value, &top->record_opts);
1002
1003 return perf_default_config(var, value, cb);
1004}
1005
994static int 1006static int
995parse_percent_limit(const struct option *opt, const char *arg, 1007parse_percent_limit(const struct option *opt, const char *arg,
996 int unset __maybe_unused) 1008 int unset __maybe_unused)
@@ -1115,6 +1127,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1115 if (top.evlist == NULL) 1127 if (top.evlist == NULL)
1116 return -ENOMEM; 1128 return -ENOMEM;
1117 1129
1130 perf_config(perf_top_config, &top);
1131
1118 argc = parse_options(argc, argv, options, top_usage, 0); 1132 argc = parse_options(argc, argv, options, top_usage, 0);
1119 if (argc) 1133 if (argc)
1120 usage_with_options(top_usage, options); 1134 usage_with_options(top_usage, options);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 896f27047ed6..f954c26de231 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -37,6 +37,10 @@
37# define MADV_UNMERGEABLE 13 37# define MADV_UNMERGEABLE 13
38#endif 38#endif
39 39
40#ifndef EFD_SEMAPHORE
41# define EFD_SEMAPHORE 1
42#endif
43
40struct tp_field { 44struct tp_field {
41 int offset; 45 int offset;
42 union { 46 union {
@@ -279,6 +283,11 @@ static size_t syscall_arg__scnprintf_strarray(char *bf, size_t size,
279 283
280#define SCA_STRARRAY syscall_arg__scnprintf_strarray 284#define SCA_STRARRAY syscall_arg__scnprintf_strarray
281 285
286#if defined(__i386__) || defined(__x86_64__)
287/*
288 * FIXME: Make this available to all arches as soon as the ioctl beautifier
289 * gets rewritten to support all arches.
290 */
282static size_t syscall_arg__scnprintf_strhexarray(char *bf, size_t size, 291static size_t syscall_arg__scnprintf_strhexarray(char *bf, size_t size,
283 struct syscall_arg *arg) 292 struct syscall_arg *arg)
284{ 293{
@@ -286,6 +295,7 @@ static size_t syscall_arg__scnprintf_strhexarray(char *bf, size_t size,
286} 295}
287 296
288#define SCA_STRHEXARRAY syscall_arg__scnprintf_strhexarray 297#define SCA_STRHEXARRAY syscall_arg__scnprintf_strhexarray
298#endif /* defined(__i386__) || defined(__x86_64__) */
289 299
290static size_t syscall_arg__scnprintf_fd(char *bf, size_t size, 300static size_t syscall_arg__scnprintf_fd(char *bf, size_t size,
291 struct syscall_arg *arg); 301 struct syscall_arg *arg);
@@ -815,7 +825,6 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscal
815 P_SIGNUM(PIPE); 825 P_SIGNUM(PIPE);
816 P_SIGNUM(ALRM); 826 P_SIGNUM(ALRM);
817 P_SIGNUM(TERM); 827 P_SIGNUM(TERM);
818 P_SIGNUM(STKFLT);
819 P_SIGNUM(CHLD); 828 P_SIGNUM(CHLD);
820 P_SIGNUM(CONT); 829 P_SIGNUM(CONT);
821 P_SIGNUM(STOP); 830 P_SIGNUM(STOP);
@@ -831,6 +840,15 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscal
831 P_SIGNUM(IO); 840 P_SIGNUM(IO);
832 P_SIGNUM(PWR); 841 P_SIGNUM(PWR);
833 P_SIGNUM(SYS); 842 P_SIGNUM(SYS);
843#ifdef SIGEMT
844 P_SIGNUM(EMT);
845#endif
846#ifdef SIGSTKFLT
847 P_SIGNUM(STKFLT);
848#endif
849#ifdef SIGSWI
850 P_SIGNUM(SWI);
851#endif
834 default: break; 852 default: break;
835 } 853 }
836 854
@@ -839,6 +857,10 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscal
839 857
840#define SCA_SIGNUM syscall_arg__scnprintf_signum 858#define SCA_SIGNUM syscall_arg__scnprintf_signum
841 859
860#if defined(__i386__) || defined(__x86_64__)
861/*
862 * FIXME: Make this available to all arches.
863 */
842#define TCGETS 0x5401 864#define TCGETS 0x5401
843 865
844static const char *tioctls[] = { 866static const char *tioctls[] = {
@@ -860,6 +882,7 @@ static const char *tioctls[] = {
860}; 882};
861 883
862static DEFINE_STRARRAY_OFFSET(tioctls, 0x5401); 884static DEFINE_STRARRAY_OFFSET(tioctls, 0x5401);
885#endif /* defined(__i386__) || defined(__x86_64__) */
863 886
864#define STRARRAY(arg, name, array) \ 887#define STRARRAY(arg, name, array) \
865 .arg_scnprintf = { [arg] = SCA_STRARRAY, }, \ 888 .arg_scnprintf = { [arg] = SCA_STRARRAY, }, \
@@ -941,9 +964,16 @@ static struct syscall_fmt {
941 { .name = "getrlimit", .errmsg = true, STRARRAY(0, resource, rlimit_resources), }, 964 { .name = "getrlimit", .errmsg = true, STRARRAY(0, resource, rlimit_resources), },
942 { .name = "ioctl", .errmsg = true, 965 { .name = "ioctl", .errmsg = true,
943 .arg_scnprintf = { [0] = SCA_FD, /* fd */ 966 .arg_scnprintf = { [0] = SCA_FD, /* fd */
967#if defined(__i386__) || defined(__x86_64__)
968/*
969 * FIXME: Make this available to all arches.
970 */
944 [1] = SCA_STRHEXARRAY, /* cmd */ 971 [1] = SCA_STRHEXARRAY, /* cmd */
945 [2] = SCA_HEX, /* arg */ }, 972 [2] = SCA_HEX, /* arg */ },
946 .arg_parm = { [1] = &strarray__tioctls, /* cmd */ }, }, 973 .arg_parm = { [1] = &strarray__tioctls, /* cmd */ }, },
974#else
975 [2] = SCA_HEX, /* arg */ }, },
976#endif
947 { .name = "kill", .errmsg = true, 977 { .name = "kill", .errmsg = true,
948 .arg_scnprintf = { [1] = SCA_SIGNUM, /* sig */ }, }, 978 .arg_scnprintf = { [1] = SCA_SIGNUM, /* sig */ }, },
949 { .name = "linkat", .errmsg = true, 979 { .name = "linkat", .errmsg = true,
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index c48d44958172..c23418225c2c 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -59,6 +59,18 @@ ifeq ($(NO_PERF_REGS),0)
59 CFLAGS += -DHAVE_PERF_REGS_SUPPORT 59 CFLAGS += -DHAVE_PERF_REGS_SUPPORT
60endif 60endif
61 61
62ifndef NO_LIBELF
63 # for linking with debug library, run like:
64 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
65 ifdef LIBDW_DIR
66 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
67 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
68
69 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
70 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) -ldw
71 endif
72endif
73
62# include ARCH specific config 74# include ARCH specific config
63-include $(src-perf)/arch/$(ARCH)/Makefile 75-include $(src-perf)/arch/$(ARCH)/Makefile
64 76
@@ -147,7 +159,35 @@ CORE_FEATURE_TESTS = \
147 libunwind \ 159 libunwind \
148 on-exit \ 160 on-exit \
149 stackprotector-all \ 161 stackprotector-all \
150 timerfd 162 timerfd \
163 libdw-dwarf-unwind
164
165LIB_FEATURE_TESTS = \
166 dwarf \
167 glibc \
168 gtk2 \
169 libaudit \
170 libbfd \
171 libelf \
172 libnuma \
173 libperl \
174 libpython \
175 libslang \
176 libunwind \
177 libdw-dwarf-unwind
178
179VF_FEATURE_TESTS = \
180 backtrace \
181 fortify-source \
182 gtk2-infobar \
183 libelf-getphdrnum \
184 libelf-mmap \
185 libpython-version \
186 on-exit \
187 stackprotector-all \
188 timerfd \
189 libunwind-debug-frame \
190 bionic
151 191
152# Set FEATURE_CHECK_(C|LD)FLAGS-all for all CORE_FEATURE_TESTS features. 192# Set FEATURE_CHECK_(C|LD)FLAGS-all for all CORE_FEATURE_TESTS features.
153# If in the future we need per-feature checks/flags for features not 193# If in the future we need per-feature checks/flags for features not
@@ -161,17 +201,6 @@ endef
161$(foreach feat,$(CORE_FEATURE_TESTS),$(call set_test_all_flags,$(feat))) 201$(foreach feat,$(CORE_FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
162 202
163# 203#
164# So here we detect whether test-all was rebuilt, to be able
165# to skip the print-out of the long features list if the file
166# existed before and after it was built:
167#
168ifeq ($(wildcard $(OUTPUT)config/feature-checks/test-all.bin),)
169 test-all-failed := 1
170else
171 test-all-failed := 0
172endif
173
174#
175# Special fast-path for the 'all features are available' case: 204# Special fast-path for the 'all features are available' case:
176# 205#
177$(call feature_check,all,$(MSG)) 206$(call feature_check,all,$(MSG))
@@ -180,15 +209,6 @@ $(call feature_check,all,$(MSG))
180# Just in case the build freshly failed, make sure we print the 209# Just in case the build freshly failed, make sure we print the
181# feature matrix: 210# feature matrix:
182# 211#
183ifeq ($(feature-all), 0)
184 test-all-failed := 1
185endif
186
187ifeq ($(test-all-failed),1)
188 $(info )
189 $(info Auto-detecting system features:)
190endif
191
192ifeq ($(feature-all), 1) 212ifeq ($(feature-all), 1)
193 # 213 #
194 # test-all.c passed - just set all the core feature flags to 1: 214 # test-all.c passed - just set all the core feature flags to 1:
@@ -199,27 +219,6 @@ else
199 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat))) 219 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
200endif 220endif
201 221
202#
203# Print the result of the feature test:
204#
205feature_print = $(eval $(feature_print_code)) $(info $(MSG))
206
207define feature_print_code
208 ifeq ($(feature-$(1)), 1)
209 MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
210 else
211 MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
212 endif
213endef
214
215#
216# Only print out our features if we rebuilt the testcases or if a test failed:
217#
218ifeq ($(test-all-failed), 1)
219 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_print,$(feat)))
220 $(info )
221endif
222
223ifeq ($(feature-stackprotector-all), 1) 222ifeq ($(feature-stackprotector-all), 1)
224 CFLAGS += -fstack-protector-all 223 CFLAGS += -fstack-protector-all
225endif 224endif
@@ -264,6 +263,7 @@ ifdef NO_LIBELF
264 NO_DWARF := 1 263 NO_DWARF := 1
265 NO_DEMANGLE := 1 264 NO_DEMANGLE := 1
266 NO_LIBUNWIND := 1 265 NO_LIBUNWIND := 1
266 NO_LIBDW_DWARF_UNWIND := 1
267else 267else
268 ifeq ($(feature-libelf), 0) 268 ifeq ($(feature-libelf), 0)
269 ifeq ($(feature-glibc), 1) 269 ifeq ($(feature-glibc), 1)
@@ -282,13 +282,12 @@ else
282 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static); 282 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
283 endif 283 endif
284 else 284 else
285 # for linking with debug library, run like: 285 ifndef NO_LIBDW_DWARF_UNWIND
286 # make DEBUG=1 LIBDW_DIR=/opt/libdw/ 286 ifneq ($(feature-libdw-dwarf-unwind),1)
287 ifdef LIBDW_DIR 287 NO_LIBDW_DWARF_UNWIND := 1
288 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include 288 msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
289 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib 289 endif
290 endif 290 endif
291
292 ifneq ($(feature-dwarf), 1) 291 ifneq ($(feature-dwarf), 1)
293 msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev); 292 msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
294 NO_DWARF := 1 293 NO_DWARF := 1
@@ -324,25 +323,51 @@ endif # NO_LIBELF
324 323
325ifndef NO_LIBUNWIND 324ifndef NO_LIBUNWIND
326 ifneq ($(feature-libunwind), 1) 325 ifneq ($(feature-libunwind), 1)
327 msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 1.1); 326 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
328 NO_LIBUNWIND := 1 327 NO_LIBUNWIND := 1
328 endif
329endif
330
331dwarf-post-unwind := 1
332dwarf-post-unwind-text := BUG
333
334# setup DWARF post unwinder
335ifdef NO_LIBUNWIND
336 ifdef NO_LIBDW_DWARF_UNWIND
337 msg := $(warning Disabling post unwind, no support found.);
338 dwarf-post-unwind := 0
329 else 339 else
330 ifeq ($(ARCH),arm) 340 dwarf-post-unwind-text := libdw
331 $(call feature_check,libunwind-debug-frame) 341 endif
332 ifneq ($(feature-libunwind-debug-frame), 1) 342else
333 msg := $(warning No debug_frame support found in libunwind); 343 dwarf-post-unwind-text := libunwind
334 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 344 # Enable libunwind support by default.
335 endif 345 ifndef NO_LIBDW_DWARF_UNWIND
336 else 346 NO_LIBDW_DWARF_UNWIND := 1
337 # non-ARM has no dwarf_find_debug_frame() function: 347 endif
348endif
349
350ifeq ($(dwarf-post-unwind),1)
351 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
352else
353 NO_DWARF_UNWIND := 1
354endif
355
356ifndef NO_LIBUNWIND
357 ifeq ($(ARCH),arm)
358 $(call feature_check,libunwind-debug-frame)
359 ifneq ($(feature-libunwind-debug-frame), 1)
360 msg := $(warning No debug_frame support found in libunwind);
338 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 361 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
339 endif 362 endif
340 363 else
341 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT 364 # non-ARM has no dwarf_find_debug_frame() function:
342 EXTLIBS += $(LIBUNWIND_LIBS) 365 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
343 CFLAGS += $(LIBUNWIND_CFLAGS) 366 endif
344 LDFLAGS += $(LIBUNWIND_LDFLAGS) 367 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
345 endif # ifneq ($(feature-libunwind), 1) 368 EXTLIBS += $(LIBUNWIND_LIBS)
369 CFLAGS += $(LIBUNWIND_CFLAGS)
370 LDFLAGS += $(LIBUNWIND_LDFLAGS)
346endif 371endif
347 372
348ifndef NO_LIBAUDIT 373ifndef NO_LIBAUDIT
@@ -478,7 +503,7 @@ else
478endif 503endif
479 504
480ifeq ($(feature-libbfd), 1) 505ifeq ($(feature-libbfd), 1)
481 EXTLIBS += -lbfd 506 EXTLIBS += -lbfd -lz -liberty
482endif 507endif
483 508
484ifdef NO_DEMANGLE 509ifdef NO_DEMANGLE
@@ -602,3 +627,84 @@ ifdef DESTDIR
602plugindir=$(libdir)/traceevent/plugins 627plugindir=$(libdir)/traceevent/plugins
603plugindir_SQ= $(subst ','\'',$(plugindir)) 628plugindir_SQ= $(subst ','\'',$(plugindir))
604endif 629endif
630
631#
632# Print the result of the feature test:
633#
634feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
635
636define feature_print_status_code
637 ifeq ($(feature-$(1)), 1)
638 MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
639 else
640 MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
641 endif
642endef
643
644feature_print_var = $(eval $(feature_print_var_code)) $(info $(MSG))
645define feature_print_var_code
646 MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
647endef
648
649feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
650define feature_print_text_code
651 MSG = $(shell printf '...%30s: %s' $(1) $(2))
652endef
653
654PERF_FEATURES := $(foreach feat,$(LIB_FEATURE_TESTS),feature-$(feat)($(feature-$(feat))))
655PERF_FEATURES_FILE := $(shell touch $(OUTPUT)PERF-FEATURES; cat $(OUTPUT)PERF-FEATURES)
656
657ifeq ($(dwarf-post-unwind),1)
658 PERF_FEATURES += dwarf-post-unwind($(dwarf-post-unwind-text))
659endif
660
661# The $(display_lib) controls the default detection message
662# output. It's set if:
663# - detected features differes from stored features from
664# last build (in PERF-FEATURES file)
665# - one of the $(LIB_FEATURE_TESTS) is not detected
666# - VF is enabled
667
668ifneq ("$(PERF_FEATURES)","$(PERF_FEATURES_FILE)")
669 $(shell echo "$(PERF_FEATURES)" > $(OUTPUT)PERF-FEATURES)
670 display_lib := 1
671endif
672
673feature_check = $(eval $(feature_check_code))
674define feature_check_code
675 ifneq ($(feature-$(1)), 1)
676 display_lib := 1
677 endif
678endef
679
680$(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_check,$(feat)))
681
682ifeq ($(VF),1)
683 display_lib := 1
684 display_vf := 1
685endif
686
687ifeq ($(display_lib),1)
688 $(info )
689 $(info Auto-detecting system features:)
690 $(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_print_status,$(feat),))
691
692 ifeq ($(dwarf-post-unwind),1)
693 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
694 endif
695endif
696
697ifeq ($(display_vf),1)
698 $(foreach feat,$(VF_FEATURE_TESTS),$(call feature_print_status,$(feat),))
699 $(info )
700 $(call feature_print_var,prefix)
701 $(call feature_print_var,bindir)
702 $(call feature_print_var,libdir)
703 $(call feature_print_var,sysconfdir)
704 $(call feature_print_var,LIBUNWIND_DIR)
705 $(call feature_print_var,LIBDW_DIR)
706endif
707
708ifeq ($(display_lib),1)
709 $(info )
710endif
diff --git a/tools/perf/config/feature-checks/Makefile b/tools/perf/config/feature-checks/Makefile
index 12e551346fa6..2da103c53f89 100644
--- a/tools/perf/config/feature-checks/Makefile
+++ b/tools/perf/config/feature-checks/Makefile
@@ -26,7 +26,8 @@ FILES= \
26 test-libunwind-debug-frame.bin \ 26 test-libunwind-debug-frame.bin \
27 test-on-exit.bin \ 27 test-on-exit.bin \
28 test-stackprotector-all.bin \ 28 test-stackprotector-all.bin \
29 test-timerfd.bin 29 test-timerfd.bin \
30 test-libdw-dwarf-unwind.bin
30 31
31CC := $(CROSS_COMPILE)gcc -MD 32CC := $(CROSS_COMPILE)gcc -MD
32PKG_CONFIG := $(CROSS_COMPILE)pkg-config 33PKG_CONFIG := $(CROSS_COMPILE)pkg-config
@@ -121,7 +122,7 @@ test-libpython-version.bin:
121 $(BUILD) $(FLAGS_PYTHON_EMBED) 122 $(BUILD) $(FLAGS_PYTHON_EMBED)
122 123
123test-libbfd.bin: 124test-libbfd.bin:
124 $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl 125 $(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
125 126
126test-liberty.bin: 127test-liberty.bin:
127 $(CC) -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' -lbfd -ldl -liberty 128 $(CC) -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' -lbfd -ldl -liberty
@@ -141,6 +142,9 @@ test-backtrace.bin:
141test-timerfd.bin: 142test-timerfd.bin:
142 $(BUILD) 143 $(BUILD)
143 144
145test-libdw-dwarf-unwind.bin:
146 $(BUILD)
147
144-include *.d 148-include *.d
145 149
146############################### 150###############################
diff --git a/tools/perf/config/feature-checks/test-all.c b/tools/perf/config/feature-checks/test-all.c
index 9b8a544155bb..fc37eb3ca17b 100644
--- a/tools/perf/config/feature-checks/test-all.c
+++ b/tools/perf/config/feature-checks/test-all.c
@@ -89,6 +89,10 @@
89# include "test-stackprotector-all.c" 89# include "test-stackprotector-all.c"
90#undef main 90#undef main
91 91
92#define main main_test_libdw_dwarf_unwind
93# include "test-libdw-dwarf-unwind.c"
94#undef main
95
92int main(int argc, char *argv[]) 96int main(int argc, char *argv[])
93{ 97{
94 main_test_libpython(); 98 main_test_libpython();
@@ -111,6 +115,7 @@ int main(int argc, char *argv[])
111 main_test_libnuma(); 115 main_test_libnuma();
112 main_test_timerfd(); 116 main_test_timerfd();
113 main_test_stackprotector_all(); 117 main_test_stackprotector_all();
118 main_test_libdw_dwarf_unwind();
114 119
115 return 0; 120 return 0;
116} 121}
diff --git a/tools/perf/config/feature-checks/test-libdw-dwarf-unwind.c b/tools/perf/config/feature-checks/test-libdw-dwarf-unwind.c
new file mode 100644
index 000000000000..f676a3ff442a
--- /dev/null
+++ b/tools/perf/config/feature-checks/test-libdw-dwarf-unwind.c
@@ -0,0 +1,13 @@
1
2#include <elfutils/libdwfl.h>
3
4int main(void)
5{
6 /*
7 * This function is guarded via: __nonnull_attribute__ (1, 2).
8 * Passing '1' as arguments value. This code is never executed,
9 * only compiled.
10 */
11 dwfl_thread_getframes((void *) 1, (void *) 1, NULL);
12 return 0;
13}
diff --git a/tools/perf/design.txt b/tools/perf/design.txt
index 67e5d0cace85..a28dca2582aa 100644
--- a/tools/perf/design.txt
+++ b/tools/perf/design.txt
@@ -18,7 +18,7 @@ underlying hardware counters.
18Performance counters are accessed via special file descriptors. 18Performance counters are accessed via special file descriptors.
19There's one file descriptor per virtual counter used. 19There's one file descriptor per virtual counter used.
20 20
21The special file descriptor is opened via the perf_event_open() 21The special file descriptor is opened via the sys_perf_event_open()
22system call: 22system call:
23 23
24 int sys_perf_event_open(struct perf_event_attr *hw_event_uptr, 24 int sys_perf_event_open(struct perf_event_attr *hw_event_uptr,
@@ -82,7 +82,7 @@ machine-specific.
82If 'raw_type' is 0, then the 'type' field says what kind of counter 82If 'raw_type' is 0, then the 'type' field says what kind of counter
83this is, with the following encoding: 83this is, with the following encoding:
84 84
85enum perf_event_types { 85enum perf_type_id {
86 PERF_TYPE_HARDWARE = 0, 86 PERF_TYPE_HARDWARE = 0,
87 PERF_TYPE_SOFTWARE = 1, 87 PERF_TYPE_SOFTWARE = 1,
88 PERF_TYPE_TRACEPOINT = 2, 88 PERF_TYPE_TRACEPOINT = 2,
@@ -95,7 +95,7 @@ specified by 'event_id':
95 * Generalized performance counter event types, used by the hw_event.event_id 95 * Generalized performance counter event types, used by the hw_event.event_id
96 * parameter of the sys_perf_event_open() syscall: 96 * parameter of the sys_perf_event_open() syscall:
97 */ 97 */
98enum hw_event_ids { 98enum perf_hw_id {
99 /* 99 /*
100 * Common hardware events, generalized by the kernel: 100 * Common hardware events, generalized by the kernel:
101 */ 101 */
@@ -129,7 +129,7 @@ software events, selected by 'event_id':
129 * physical and sw events of the kernel (and allow the profiling of them as 129 * physical and sw events of the kernel (and allow the profiling of them as
130 * well): 130 * well):
131 */ 131 */
132enum sw_event_ids { 132enum perf_sw_ids {
133 PERF_COUNT_SW_CPU_CLOCK = 0, 133 PERF_COUNT_SW_CPU_CLOCK = 0,
134 PERF_COUNT_SW_TASK_CLOCK = 1, 134 PERF_COUNT_SW_TASK_CLOCK = 1,
135 PERF_COUNT_SW_PAGE_FAULTS = 2, 135 PERF_COUNT_SW_PAGE_FAULTS = 2,
@@ -230,7 +230,7 @@ these events are recorded in the ring-buffer (see below).
230The 'comm' bit allows tracking of process comm data on process creation. 230The 'comm' bit allows tracking of process comm data on process creation.
231This too is recorded in the ring-buffer (see below). 231This too is recorded in the ring-buffer (see below).
232 232
233The 'pid' parameter to the perf_event_open() system call allows the 233The 'pid' parameter to the sys_perf_event_open() system call allows the
234counter to be specific to a task: 234counter to be specific to a task:
235 235
236 pid == 0: if the pid parameter is zero, the counter is attached to the 236 pid == 0: if the pid parameter is zero, the counter is attached to the
@@ -260,7 +260,7 @@ The 'flags' parameter is currently unused and must be zero.
260 260
261The 'group_fd' parameter allows counter "groups" to be set up. A 261The 'group_fd' parameter allows counter "groups" to be set up. A
262counter group has one counter which is the group "leader". The leader 262counter group has one counter which is the group "leader". The leader
263is created first, with group_fd = -1 in the perf_event_open call 263is created first, with group_fd = -1 in the sys_perf_event_open call
264that creates it. The rest of the group members are created 264that creates it. The rest of the group members are created
265subsequently, with group_fd giving the fd of the group leader. 265subsequently, with group_fd giving the fd of the group leader.
266(A single counter on its own is created with group_fd = -1 and is 266(A single counter on its own is created with group_fd = -1 and is
@@ -454,7 +454,6 @@ So to start with, in order to add HAVE_PERF_EVENTS to your Kconfig, you
454will need at least this: 454will need at least this:
455 - asm/perf_event.h - a basic stub will suffice at first 455 - asm/perf_event.h - a basic stub will suffice at first
456 - support for atomic64 types (and associated helper functions) 456 - support for atomic64 types (and associated helper functions)
457 - set_perf_event_pending() implemented
458 457
459If your architecture does have hardware capabilities, you can override the 458If your architecture does have hardware capabilities, you can override the
460weak stub hw_perf_event_init() to register hardware counters. 459weak stub hw_perf_event_init() to register hardware counters.
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 496e2abb5482..ae3a57694b6b 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -123,7 +123,7 @@ __perf_main ()
123 __perfcomp_colon "$evts" "$cur" 123 __perfcomp_colon "$evts" "$cur"
124 # List subcommands for 'perf kvm' 124 # List subcommands for 'perf kvm'
125 elif [[ $prev == "kvm" ]]; then 125 elif [[ $prev == "kvm" ]]; then
126 subcmds="top record report diff buildid-list stat" 126 subcmds=$($cmd $prev --list-cmds)
127 __perfcomp_colon "$subcmds" "$cur" 127 __perfcomp_colon "$subcmds" "$cur"
128 # List long option names 128 # List long option names
129 elif [[ $cur == --* ]]; then 129 elif [[ $cur == --* ]]; then
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 7daa806d9050..e18a8b5e6953 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -12,6 +12,9 @@
12#ifndef __NR_perf_event_open 12#ifndef __NR_perf_event_open
13# define __NR_perf_event_open 336 13# define __NR_perf_event_open 336
14#endif 14#endif
15#ifndef __NR_futex
16# define __NR_futex 240
17#endif
15#endif 18#endif
16 19
17#if defined(__x86_64__) 20#if defined(__x86_64__)
@@ -23,6 +26,9 @@
23#ifndef __NR_perf_event_open 26#ifndef __NR_perf_event_open
24# define __NR_perf_event_open 298 27# define __NR_perf_event_open 298
25#endif 28#endif
29#ifndef __NR_futex
30# define __NR_futex 202
31#endif
26#endif 32#endif
27 33
28#ifdef __powerpc__ 34#ifdef __powerpc__
@@ -100,8 +106,8 @@
100 106
101#ifdef __aarch64__ 107#ifdef __aarch64__
102#define mb() asm volatile("dmb ish" ::: "memory") 108#define mb() asm volatile("dmb ish" ::: "memory")
103#define wmb() asm volatile("dmb ishld" ::: "memory") 109#define wmb() asm volatile("dmb ishst" ::: "memory")
104#define rmb() asm volatile("dmb ishst" ::: "memory") 110#define rmb() asm volatile("dmb ishld" ::: "memory")
105#define cpu_relax() asm volatile("yield" ::: "memory") 111#define cpu_relax() asm volatile("yield" ::: "memory")
106#endif 112#endif
107 113
@@ -251,12 +257,14 @@ void pthread__unblock_sigwinch(void);
251enum perf_call_graph_mode { 257enum perf_call_graph_mode {
252 CALLCHAIN_NONE, 258 CALLCHAIN_NONE,
253 CALLCHAIN_FP, 259 CALLCHAIN_FP,
254 CALLCHAIN_DWARF 260 CALLCHAIN_DWARF,
261 CALLCHAIN_MAX
255}; 262};
256 263
257struct record_opts { 264struct record_opts {
258 struct target target; 265 struct target target;
259 int call_graph; 266 int call_graph;
267 bool call_graph_enabled;
260 bool group; 268 bool group;
261 bool inherit_stat; 269 bool inherit_stat;
262 bool no_buffering; 270 bool no_buffering;
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 1e67437fb4ca..b11bf8a08430 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -115,6 +115,14 @@ static struct test {
115 .desc = "Test parsing with no sample_id_all bit set", 115 .desc = "Test parsing with no sample_id_all bit set",
116 .func = test__parse_no_sample_id_all, 116 .func = test__parse_no_sample_id_all,
117 }, 117 },
118#if defined(__x86_64__) || defined(__i386__)
119#ifdef HAVE_DWARF_UNWIND_SUPPORT
120 {
121 .desc = "Test dwarf unwind",
122 .func = test__dwarf_unwind,
123 },
124#endif
125#endif
118 { 126 {
119 .func = NULL, 127 .func = NULL,
120 }, 128 },
diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
new file mode 100644
index 000000000000..c059ee81c038
--- /dev/null
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -0,0 +1,144 @@
1#include <linux/compiler.h>
2#include <sys/types.h>
3#include <unistd.h>
4#include "tests.h"
5#include "debug.h"
6#include "machine.h"
7#include "event.h"
8#include "unwind.h"
9#include "perf_regs.h"
10#include "map.h"
11#include "thread.h"
12
13static int mmap_handler(struct perf_tool *tool __maybe_unused,
14 union perf_event *event,
15 struct perf_sample *sample __maybe_unused,
16 struct machine *machine)
17{
18 return machine__process_mmap_event(machine, event, NULL);
19}
20
21static int init_live_machine(struct machine *machine)
22{
23 union perf_event event;
24 pid_t pid = getpid();
25
26 return perf_event__synthesize_mmap_events(NULL, &event, pid, pid,
27 mmap_handler, machine, true);
28}
29
30#define MAX_STACK 6
31
32static int unwind_entry(struct unwind_entry *entry, void *arg)
33{
34 unsigned long *cnt = (unsigned long *) arg;
35 char *symbol = entry->sym ? entry->sym->name : NULL;
36 static const char *funcs[MAX_STACK] = {
37 "test__arch_unwind_sample",
38 "unwind_thread",
39 "krava_3",
40 "krava_2",
41 "krava_1",
42 "test__dwarf_unwind"
43 };
44
45 if (*cnt >= MAX_STACK) {
46 pr_debug("failed: crossed the max stack value %d\n", MAX_STACK);
47 return -1;
48 }
49
50 if (!symbol) {
51 pr_debug("failed: got unresolved address 0x%" PRIx64 "\n",
52 entry->ip);
53 return -1;
54 }
55
56 pr_debug("got: %s 0x%" PRIx64 "\n", symbol, entry->ip);
57 return strcmp((const char *) symbol, funcs[(*cnt)++]);
58}
59
60__attribute__ ((noinline))
61static int unwind_thread(struct thread *thread, struct machine *machine)
62{
63 struct perf_sample sample;
64 unsigned long cnt = 0;
65 int err = -1;
66
67 memset(&sample, 0, sizeof(sample));
68
69 if (test__arch_unwind_sample(&sample, thread)) {
70 pr_debug("failed to get unwind sample\n");
71 goto out;
72 }
73
74 err = unwind__get_entries(unwind_entry, &cnt, machine, thread,
75 &sample, MAX_STACK);
76 if (err)
77 pr_debug("unwind failed\n");
78 else if (cnt != MAX_STACK) {
79 pr_debug("got wrong number of stack entries %lu != %d\n",
80 cnt, MAX_STACK);
81 err = -1;
82 }
83
84 out:
85 free(sample.user_stack.data);
86 free(sample.user_regs.regs);
87 return err;
88}
89
90__attribute__ ((noinline))
91static int krava_3(struct thread *thread, struct machine *machine)
92{
93 return unwind_thread(thread, machine);
94}
95
96__attribute__ ((noinline))
97static int krava_2(struct thread *thread, struct machine *machine)
98{
99 return krava_3(thread, machine);
100}
101
102__attribute__ ((noinline))
103static int krava_1(struct thread *thread, struct machine *machine)
104{
105 return krava_2(thread, machine);
106}
107
108int test__dwarf_unwind(void)
109{
110 struct machines machines;
111 struct machine *machine;
112 struct thread *thread;
113 int err = -1;
114
115 machines__init(&machines);
116
117 machine = machines__find(&machines, HOST_KERNEL_ID);
118 if (!machine) {
119 pr_err("Could not get machine\n");
120 return -1;
121 }
122
123 if (init_live_machine(machine)) {
124 pr_err("Could not init machine\n");
125 goto out;
126 }
127
128 if (verbose > 1)
129 machine__fprintf(machine, stderr);
130
131 thread = machine__find_thread(machine, getpid(), getpid());
132 if (!thread) {
133 pr_err("Could not get thread\n");
134 goto out;
135 }
136
137 err = krava_1(thread, machine);
138
139 out:
140 machine__delete_threads(machine);
141 machine__exit(machine);
142 machines__exit(&machines);
143 return err;
144}
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 2b6519e0e36f..7ccbc7b6ae77 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -101,6 +101,7 @@ static struct machine *setup_fake_machine(struct machines *machines)
101 .mmap = { 101 .mmap = {
102 .header = { .misc = PERF_RECORD_MISC_USER, }, 102 .header = { .misc = PERF_RECORD_MISC_USER, },
103 .pid = fake_mmap_info[i].pid, 103 .pid = fake_mmap_info[i].pid,
104 .tid = fake_mmap_info[i].pid,
104 .start = fake_mmap_info[i].start, 105 .start = fake_mmap_info[i].start,
105 .len = 0x1000ULL, 106 .len = 0x1000ULL,
106 .pgoff = 0ULL, 107 .pgoff = 0ULL,
diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index 00544b8b644b..5daeae1cb4c0 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -27,6 +27,7 @@ make_no_ui := NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
27make_no_demangle := NO_DEMANGLE=1 27make_no_demangle := NO_DEMANGLE=1
28make_no_libelf := NO_LIBELF=1 28make_no_libelf := NO_LIBELF=1
29make_no_libunwind := NO_LIBUNWIND=1 29make_no_libunwind := NO_LIBUNWIND=1
30make_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1
30make_no_backtrace := NO_BACKTRACE=1 31make_no_backtrace := NO_BACKTRACE=1
31make_no_libnuma := NO_LIBNUMA=1 32make_no_libnuma := NO_LIBNUMA=1
32make_no_libaudit := NO_LIBAUDIT=1 33make_no_libaudit := NO_LIBAUDIT=1
@@ -35,8 +36,9 @@ make_tags := tags
35make_cscope := cscope 36make_cscope := cscope
36make_help := help 37make_help := help
37make_doc := doc 38make_doc := doc
38make_perf_o := perf.o 39make_perf_o := perf.o
39make_util_map_o := util/map.o 40make_util_map_o := util/map.o
41make_util_pmu_bison_o := util/pmu-bison.o
40make_install := install 42make_install := install
41make_install_bin := install-bin 43make_install_bin := install-bin
42make_install_doc := install-doc 44make_install_doc := install-doc
@@ -49,6 +51,7 @@ make_install_pdf := install-pdf
49make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 51make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1
50make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 52make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
51make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 53make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
54make_minimal += NO_LIBDW_DWARF_UNWIND=1
52 55
53# $(run) contains all available tests 56# $(run) contains all available tests
54run := make_pure 57run := make_pure
@@ -65,6 +68,7 @@ run += make_no_ui
65run += make_no_demangle 68run += make_no_demangle
66run += make_no_libelf 69run += make_no_libelf
67run += make_no_libunwind 70run += make_no_libunwind
71run += make_no_libdw_dwarf_unwind
68run += make_no_backtrace 72run += make_no_backtrace
69run += make_no_libnuma 73run += make_no_libnuma
70run += make_no_libaudit 74run += make_no_libaudit
@@ -73,6 +77,7 @@ run += make_help
73run += make_doc 77run += make_doc
74run += make_perf_o 78run += make_perf_o
75run += make_util_map_o 79run += make_util_map_o
80run += make_util_pmu_bison_o
76run += make_install 81run += make_install
77run += make_install_bin 82run += make_install_bin
78# FIXME 'install-*' commented out till they're fixed 83# FIXME 'install-*' commented out till they're fixed
@@ -113,8 +118,9 @@ test_make_doc_O := $(test_ok)
113 118
114test_make_python_perf_so := test -f $(PERF)/python/perf.so 119test_make_python_perf_so := test -f $(PERF)/python/perf.so
115 120
116test_make_perf_o := test -f $(PERF)/perf.o 121test_make_perf_o := test -f $(PERF)/perf.o
117test_make_util_map_o := test -f $(PERF)/util/map.o 122test_make_util_map_o := test -f $(PERF)/util/map.o
123test_make_util_pmu_bison_o := test -f $(PERF)/util/pmu-bison.o
118 124
119define test_dest_files 125define test_dest_files
120 for file in $(1); do \ 126 for file in $(1); do \
@@ -167,13 +173,10 @@ test_make_install_info_O := $(test_ok)
167test_make_install_pdf := $(test_ok) 173test_make_install_pdf := $(test_ok)
168test_make_install_pdf_O := $(test_ok) 174test_make_install_pdf_O := $(test_ok)
169 175
170# Kbuild tests only 176test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so
171#test_make_python_perf_so_O := test -f $$TMP/tools/perf/python/perf.so 177test_make_perf_o_O := test -f $$TMP_O/perf.o
172#test_make_perf_o_O := test -f $$TMP/tools/perf/perf.o 178test_make_util_map_o_O := test -f $$TMP_O/util/map.o
173#test_make_util_map_o_O := test -f $$TMP/tools/perf/util/map.o 179test_make_util_pmu_bison_o_O := test -f $$TMP_O/util/pmu-bison.o
174
175test_make_perf_o_O := true
176test_make_util_map_o_O := true
177 180
178test_default = test -x $(PERF)/perf 181test_default = test -x $(PERF)/perf
179test = $(if $(test_$1),$(test_$1),$(test_default)) 182test = $(if $(test_$1),$(test_$1),$(test_default))
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 4db0ae617d70..8605ff5572ae 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -2,7 +2,7 @@
2#include "parse-events.h" 2#include "parse-events.h"
3#include "evsel.h" 3#include "evsel.h"
4#include "evlist.h" 4#include "evlist.h"
5#include "fs.h" 5#include <api/fs/fs.h>
6#include <api/fs/debugfs.h> 6#include <api/fs/debugfs.h>
7#include "tests.h" 7#include "tests.h"
8#include <linux/hw_breakpoint.h> 8#include <linux/hw_breakpoint.h>
diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-parsing.c
index 1b677202638d..0014d3c8c21c 100644
--- a/tools/perf/tests/sample-parsing.c
+++ b/tools/perf/tests/sample-parsing.c
@@ -22,8 +22,8 @@
22} while (0) 22} while (0)
23 23
24static bool samples_same(const struct perf_sample *s1, 24static bool samples_same(const struct perf_sample *s1,
25 const struct perf_sample *s2, u64 type, u64 regs_user, 25 const struct perf_sample *s2,
26 u64 read_format) 26 u64 type, u64 read_format)
27{ 27{
28 size_t i; 28 size_t i;
29 29
@@ -95,8 +95,9 @@ static bool samples_same(const struct perf_sample *s1,
95 } 95 }
96 96
97 if (type & PERF_SAMPLE_REGS_USER) { 97 if (type & PERF_SAMPLE_REGS_USER) {
98 size_t sz = hweight_long(regs_user) * sizeof(u64); 98 size_t sz = hweight_long(s1->user_regs.mask) * sizeof(u64);
99 99
100 COMP(user_regs.mask);
100 COMP(user_regs.abi); 101 COMP(user_regs.abi);
101 if (s1->user_regs.abi && 102 if (s1->user_regs.abi &&
102 (!s1->user_regs.regs || !s2->user_regs.regs || 103 (!s1->user_regs.regs || !s2->user_regs.regs ||
@@ -174,6 +175,7 @@ static int do_test(u64 sample_type, u64 sample_regs_user, u64 read_format)
174 .branch_stack = &branch_stack.branch_stack, 175 .branch_stack = &branch_stack.branch_stack,
175 .user_regs = { 176 .user_regs = {
176 .abi = PERF_SAMPLE_REGS_ABI_64, 177 .abi = PERF_SAMPLE_REGS_ABI_64,
178 .mask = sample_regs_user,
177 .regs = user_regs, 179 .regs = user_regs,
178 }, 180 },
179 .user_stack = { 181 .user_stack = {
@@ -201,8 +203,7 @@ static int do_test(u64 sample_type, u64 sample_regs_user, u64 read_format)
201 sample.read.one.id = 99; 203 sample.read.one.id = 99;
202 } 204 }
203 205
204 sz = perf_event__sample_event_size(&sample, sample_type, 206 sz = perf_event__sample_event_size(&sample, sample_type, read_format);
205 sample_regs_user, read_format);
206 bufsz = sz + 4096; /* Add a bit for overrun checking */ 207 bufsz = sz + 4096; /* Add a bit for overrun checking */
207 event = malloc(bufsz); 208 event = malloc(bufsz);
208 if (!event) { 209 if (!event) {
@@ -215,8 +216,7 @@ static int do_test(u64 sample_type, u64 sample_regs_user, u64 read_format)
215 event->header.misc = 0; 216 event->header.misc = 0;
216 event->header.size = sz; 217 event->header.size = sz;
217 218
218 err = perf_event__synthesize_sample(event, sample_type, 219 err = perf_event__synthesize_sample(event, sample_type, read_format,
219 sample_regs_user, read_format,
220 &sample, false); 220 &sample, false);
221 if (err) { 221 if (err) {
222 pr_debug("%s failed for sample_type %#"PRIx64", error %d\n", 222 pr_debug("%s failed for sample_type %#"PRIx64", error %d\n",
@@ -244,8 +244,7 @@ static int do_test(u64 sample_type, u64 sample_regs_user, u64 read_format)
244 goto out_free; 244 goto out_free;
245 } 245 }
246 246
247 if (!samples_same(&sample, &sample_out, sample_type, 247 if (!samples_same(&sample, &sample_out, sample_type, read_format)) {
248 sample_regs_user, read_format)) {
249 pr_debug("parsing failed for sample_type %#"PRIx64"\n", 248 pr_debug("parsing failed for sample_type %#"PRIx64"\n",
250 sample_type); 249 sample_type);
251 goto out_free; 250 goto out_free;
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index e0ac713857ba..a24795ca002d 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -40,5 +40,14 @@ int test__code_reading(void);
40int test__sample_parsing(void); 40int test__sample_parsing(void);
41int test__keep_tracking(void); 41int test__keep_tracking(void);
42int test__parse_no_sample_id_all(void); 42int test__parse_no_sample_id_all(void);
43int test__dwarf_unwind(void);
43 44
45#if defined(__x86_64__) || defined(__i386__)
46#ifdef HAVE_DWARF_UNWIND_SUPPORT
47struct thread;
48struct perf_sample;
49int test__arch_unwind_sample(struct perf_sample *sample,
50 struct thread *thread);
51#endif
52#endif
44#endif /* TESTS_H */ 53#endif /* TESTS_H */
diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c
index 2bd13edcbc17..3d9088003a5b 100644
--- a/tools/perf/tests/vmlinux-kallsyms.c
+++ b/tools/perf/tests/vmlinux-kallsyms.c
@@ -26,7 +26,6 @@ int test__vmlinux_matches_kallsyms(void)
26 struct map *kallsyms_map, *vmlinux_map; 26 struct map *kallsyms_map, *vmlinux_map;
27 struct machine kallsyms, vmlinux; 27 struct machine kallsyms, vmlinux;
28 enum map_type type = MAP__FUNCTION; 28 enum map_type type = MAP__FUNCTION;
29 struct ref_reloc_sym ref_reloc_sym = { .name = "_stext", };
30 u64 mem_start, mem_end; 29 u64 mem_start, mem_end;
31 30
32 /* 31 /*
@@ -70,14 +69,6 @@ int test__vmlinux_matches_kallsyms(void)
70 */ 69 */
71 kallsyms_map = machine__kernel_map(&kallsyms, type); 70 kallsyms_map = machine__kernel_map(&kallsyms, type);
72 71
73 sym = map__find_symbol_by_name(kallsyms_map, ref_reloc_sym.name, NULL);
74 if (sym == NULL) {
75 pr_debug("dso__find_symbol_by_name ");
76 goto out;
77 }
78
79 ref_reloc_sym.addr = UM(sym->start);
80
81 /* 72 /*
82 * Step 5: 73 * Step 5:
83 * 74 *
@@ -89,7 +80,6 @@ int test__vmlinux_matches_kallsyms(void)
89 } 80 }
90 81
91 vmlinux_map = machine__kernel_map(&vmlinux, type); 82 vmlinux_map = machine__kernel_map(&vmlinux, type);
92 map__kmap(vmlinux_map)->ref_reloc_sym = &ref_reloc_sym;
93 83
94 /* 84 /*
95 * Step 6: 85 * Step 6:
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index b720b92eba6e..7ec871af3f6f 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -587,95 +587,52 @@ struct hpp_arg {
587 bool current_entry; 587 bool current_entry;
588}; 588};
589 589
590static int __hpp__color_callchain(struct hpp_arg *arg) 590static int __hpp__overhead_callback(struct perf_hpp *hpp, bool front)
591{ 591{
592 if (!symbol_conf.use_callchain)
593 return 0;
594
595 slsmg_printf("%c ", arg->folded_sign);
596 return 2;
597}
598
599static int __hpp__color_fmt(struct perf_hpp *hpp, struct hist_entry *he,
600 u64 (*get_field)(struct hist_entry *),
601 int (*callchain_cb)(struct hpp_arg *))
602{
603 int ret = 0;
604 double percent = 0.0;
605 struct hists *hists = he->hists;
606 struct hpp_arg *arg = hpp->ptr; 592 struct hpp_arg *arg = hpp->ptr;
607 593
608 if (hists->stats.total_period) 594 if (arg->current_entry && arg->b->navkeypressed)
609 percent = 100.0 * get_field(he) / hists->stats.total_period; 595 ui_browser__set_color(arg->b, HE_COLORSET_SELECTED);
610 596 else
611 ui_browser__set_percent_color(arg->b, percent, arg->current_entry); 597 ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
612
613 if (callchain_cb)
614 ret += callchain_cb(arg);
615
616 ret += scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
617 slsmg_printf("%s", hpp->buf);
618
619 if (symbol_conf.event_group) {
620 int prev_idx, idx_delta;
621 struct perf_evsel *evsel = hists_to_evsel(hists);
622 struct hist_entry *pair;
623 int nr_members = evsel->nr_members;
624
625 if (nr_members <= 1)
626 goto out;
627 598
628 prev_idx = perf_evsel__group_idx(evsel); 599 if (front) {
600 if (!symbol_conf.use_callchain)
601 return 0;
629 602
630 list_for_each_entry(pair, &he->pairs.head, pairs.node) { 603 slsmg_printf("%c ", arg->folded_sign);
631 u64 period = get_field(pair); 604 return 2;
632 u64 total = pair->hists->stats.total_period; 605 }
633 606
634 if (!total) 607 return 0;
635 continue; 608}
636 609
637 evsel = hists_to_evsel(pair->hists); 610static int __hpp__color_callback(struct perf_hpp *hpp, bool front __maybe_unused)
638 idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1; 611{
612 struct hpp_arg *arg = hpp->ptr;
639 613
640 while (idx_delta--) { 614 if (!arg->current_entry || !arg->b->navkeypressed)
641 /* 615 ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
642 * zero-fill group members in the middle which 616 return 0;
643 * have no sample 617}
644 */
645 ui_browser__set_percent_color(arg->b, 0.0,
646 arg->current_entry);
647 ret += scnprintf(hpp->buf, hpp->size,
648 " %6.2f%%", 0.0);
649 slsmg_printf("%s", hpp->buf);
650 }
651 618
652 percent = 100.0 * period / total; 619static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...)
653 ui_browser__set_percent_color(arg->b, percent, 620{
654 arg->current_entry); 621 struct hpp_arg *arg = hpp->ptr;
655 ret += scnprintf(hpp->buf, hpp->size, 622 int ret;
656 " %6.2f%%", percent); 623 va_list args;
657 slsmg_printf("%s", hpp->buf); 624 double percent;
658 625
659 prev_idx = perf_evsel__group_idx(evsel); 626 va_start(args, fmt);
660 } 627 percent = va_arg(args, double);
628 va_end(args);
661 629
662 idx_delta = nr_members - prev_idx - 1; 630 ui_browser__set_percent_color(arg->b, percent, arg->current_entry);
663 631
664 while (idx_delta--) { 632 ret = scnprintf(hpp->buf, hpp->size, fmt, percent);
665 /* 633 slsmg_printf("%s", hpp->buf);
666 * zero-fill group members at last which have no sample
667 */
668 ui_browser__set_percent_color(arg->b, 0.0,
669 arg->current_entry);
670 ret += scnprintf(hpp->buf, hpp->size,
671 " %6.2f%%", 0.0);
672 slsmg_printf("%s", hpp->buf);
673 }
674 }
675out:
676 if (!arg->current_entry || !arg->b->navkeypressed)
677 ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
678 634
635 advance_hpp(hpp, ret);
679 return ret; 636 return ret;
680} 637}
681 638
@@ -690,14 +647,15 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\
690 struct perf_hpp *hpp, \ 647 struct perf_hpp *hpp, \
691 struct hist_entry *he) \ 648 struct hist_entry *he) \
692{ \ 649{ \
693 return __hpp__color_fmt(hpp, he, __hpp_get_##_field, _cb); \ 650 return __hpp__fmt(hpp, he, __hpp_get_##_field, _cb, " %6.2f%%", \
651 __hpp__slsmg_color_printf, true); \
694} 652}
695 653
696__HPP_COLOR_PERCENT_FN(overhead, period, __hpp__color_callchain) 654__HPP_COLOR_PERCENT_FN(overhead, period, __hpp__overhead_callback)
697__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys, NULL) 655__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys, __hpp__color_callback)
698__HPP_COLOR_PERCENT_FN(overhead_us, period_us, NULL) 656__HPP_COLOR_PERCENT_FN(overhead_us, period_us, __hpp__color_callback)
699__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys, NULL) 657__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys, __hpp__color_callback)
700__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us, NULL) 658__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us, __hpp__color_callback)
701 659
702#undef __HPP_COLOR_PERCENT_FN 660#undef __HPP_COLOR_PERCENT_FN
703 661
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 5b95c44f3435..e395ef9b0ae0 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -8,16 +8,24 @@
8 8
9#define MAX_COLUMNS 32 9#define MAX_COLUMNS 32
10 10
11static int __percent_color_snprintf(char *buf, size_t size, double percent) 11static int __percent_color_snprintf(struct perf_hpp *hpp, const char *fmt, ...)
12{ 12{
13 int ret = 0; 13 int ret = 0;
14 va_list args;
15 double percent;
14 const char *markup; 16 const char *markup;
17 char *buf = hpp->buf;
18 size_t size = hpp->size;
19
20 va_start(args, fmt);
21 percent = va_arg(args, double);
22 va_end(args);
15 23
16 markup = perf_gtk__get_percent_color(percent); 24 markup = perf_gtk__get_percent_color(percent);
17 if (markup) 25 if (markup)
18 ret += scnprintf(buf, size, markup); 26 ret += scnprintf(buf, size, markup);
19 27
20 ret += scnprintf(buf + ret, size - ret, " %6.2f%%", percent); 28 ret += scnprintf(buf + ret, size - ret, fmt, percent);
21 29
22 if (markup) 30 if (markup)
23 ret += scnprintf(buf + ret, size - ret, "</span>"); 31 ret += scnprintf(buf + ret, size - ret, "</span>");
@@ -25,66 +33,6 @@ static int __percent_color_snprintf(char *buf, size_t size, double percent)
25 return ret; 33 return ret;
26} 34}
27 35
28
29static int __hpp__color_fmt(struct perf_hpp *hpp, struct hist_entry *he,
30 u64 (*get_field)(struct hist_entry *))
31{
32 int ret;
33 double percent = 0.0;
34 struct hists *hists = he->hists;
35 struct perf_evsel *evsel = hists_to_evsel(hists);
36
37 if (hists->stats.total_period)
38 percent = 100.0 * get_field(he) / hists->stats.total_period;
39
40 ret = __percent_color_snprintf(hpp->buf, hpp->size, percent);
41
42 if (perf_evsel__is_group_event(evsel)) {
43 int prev_idx, idx_delta;
44 struct hist_entry *pair;
45 int nr_members = evsel->nr_members;
46
47 prev_idx = perf_evsel__group_idx(evsel);
48
49 list_for_each_entry(pair, &he->pairs.head, pairs.node) {
50 u64 period = get_field(pair);
51 u64 total = pair->hists->stats.total_period;
52
53 evsel = hists_to_evsel(pair->hists);
54 idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1;
55
56 while (idx_delta--) {
57 /*
58 * zero-fill group members in the middle which
59 * have no sample
60 */
61 ret += __percent_color_snprintf(hpp->buf + ret,
62 hpp->size - ret,
63 0.0);
64 }
65
66 percent = 100.0 * period / total;
67 ret += __percent_color_snprintf(hpp->buf + ret,
68 hpp->size - ret,
69 percent);
70
71 prev_idx = perf_evsel__group_idx(evsel);
72 }
73
74 idx_delta = nr_members - prev_idx - 1;
75
76 while (idx_delta--) {
77 /*
78 * zero-fill group members at last which have no sample
79 */
80 ret += __percent_color_snprintf(hpp->buf + ret,
81 hpp->size - ret,
82 0.0);
83 }
84 }
85 return ret;
86}
87
88#define __HPP_COLOR_PERCENT_FN(_type, _field) \ 36#define __HPP_COLOR_PERCENT_FN(_type, _field) \
89static u64 he_get_##_field(struct hist_entry *he) \ 37static u64 he_get_##_field(struct hist_entry *he) \
90{ \ 38{ \
@@ -95,7 +43,8 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,
95 struct perf_hpp *hpp, \ 43 struct perf_hpp *hpp, \
96 struct hist_entry *he) \ 44 struct hist_entry *he) \
97{ \ 45{ \
98 return __hpp__color_fmt(hpp, he, he_get_##_field); \ 46 return __hpp__fmt(hpp, he, he_get_##_field, NULL, " %6.2f%%", \
47 __percent_color_snprintf, true); \
99} 48}
100 49
101__HPP_COLOR_PERCENT_FN(overhead, period) 50__HPP_COLOR_PERCENT_FN(overhead, period)
@@ -216,7 +165,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
216 struct perf_hpp hpp = { 165 struct perf_hpp hpp = {
217 .buf = s, 166 .buf = s,
218 .size = sizeof(s), 167 .size = sizeof(s),
219 .ptr = hists_to_evsel(hists),
220 }; 168 };
221 169
222 nr_cols = 0; 170 nr_cols = 0;
@@ -243,7 +191,7 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
243 col_idx = 0; 191 col_idx = 0;
244 192
245 perf_hpp__for_each_format(fmt) { 193 perf_hpp__for_each_format(fmt) {
246 fmt->header(fmt, &hpp); 194 fmt->header(fmt, &hpp, hists_to_evsel(hists));
247 195
248 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), 196 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
249 -1, ltrim(s), 197 -1, ltrim(s),
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 78f4c92e9b73..0f403b83e9d1 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -8,16 +8,27 @@
8 8
9/* hist period print (hpp) functions */ 9/* hist period print (hpp) functions */
10 10
11typedef int (*hpp_snprint_fn)(char *buf, size_t size, const char *fmt, ...); 11#define hpp__call_print_fn(hpp, fn, fmt, ...) \
12 12({ \
13static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, 13 int __ret = fn(hpp, fmt, ##__VA_ARGS__); \
14 u64 (*get_field)(struct hist_entry *), 14 advance_hpp(hpp, __ret); \
15 const char *fmt, hpp_snprint_fn print_fn, 15 __ret; \
16 bool fmt_percent) 16})
17
18int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
19 hpp_field_fn get_field, hpp_callback_fn callback,
20 const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent)
17{ 21{
18 int ret; 22 int ret = 0;
19 struct hists *hists = he->hists; 23 struct hists *hists = he->hists;
20 struct perf_evsel *evsel = hists_to_evsel(hists); 24 struct perf_evsel *evsel = hists_to_evsel(hists);
25 char *buf = hpp->buf;
26 size_t size = hpp->size;
27
28 if (callback) {
29 ret = callback(hpp, true);
30 advance_hpp(hpp, ret);
31 }
21 32
22 if (fmt_percent) { 33 if (fmt_percent) {
23 double percent = 0.0; 34 double percent = 0.0;
@@ -26,9 +37,9 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
26 percent = 100.0 * get_field(he) / 37 percent = 100.0 * get_field(he) /
27 hists->stats.total_period; 38 hists->stats.total_period;
28 39
29 ret = print_fn(hpp->buf, hpp->size, fmt, percent); 40 ret += hpp__call_print_fn(hpp, print_fn, fmt, percent);
30 } else 41 } else
31 ret = print_fn(hpp->buf, hpp->size, fmt, get_field(he)); 42 ret += hpp__call_print_fn(hpp, print_fn, fmt, get_field(he));
32 43
33 if (perf_evsel__is_group_event(evsel)) { 44 if (perf_evsel__is_group_event(evsel)) {
34 int prev_idx, idx_delta; 45 int prev_idx, idx_delta;
@@ -52,16 +63,22 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
52 * zero-fill group members in the middle which 63 * zero-fill group members in the middle which
53 * have no sample 64 * have no sample
54 */ 65 */
55 ret += print_fn(hpp->buf + ret, hpp->size - ret, 66 if (fmt_percent) {
56 fmt, 0); 67 ret += hpp__call_print_fn(hpp, print_fn,
68 fmt, 0.0);
69 } else {
70 ret += hpp__call_print_fn(hpp, print_fn,
71 fmt, 0ULL);
72 }
57 } 73 }
58 74
59 if (fmt_percent) 75 if (fmt_percent) {
60 ret += print_fn(hpp->buf + ret, hpp->size - ret, 76 ret += hpp__call_print_fn(hpp, print_fn, fmt,
61 fmt, 100.0 * period / total); 77 100.0 * period / total);
62 else 78 } else {
63 ret += print_fn(hpp->buf + ret, hpp->size - ret, 79 ret += hpp__call_print_fn(hpp, print_fn, fmt,
64 fmt, period); 80 period);
81 }
65 82
66 prev_idx = perf_evsel__group_idx(evsel); 83 prev_idx = perf_evsel__group_idx(evsel);
67 } 84 }
@@ -72,41 +89,87 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
72 /* 89 /*
73 * zero-fill group members at last which have no sample 90 * zero-fill group members at last which have no sample
74 */ 91 */
75 ret += print_fn(hpp->buf + ret, hpp->size - ret, 92 if (fmt_percent) {
76 fmt, 0); 93 ret += hpp__call_print_fn(hpp, print_fn,
94 fmt, 0.0);
95 } else {
96 ret += hpp__call_print_fn(hpp, print_fn,
97 fmt, 0ULL);
98 }
77 } 99 }
78 } 100 }
101
102 if (callback) {
103 int __ret = callback(hpp, false);
104
105 advance_hpp(hpp, __ret);
106 ret += __ret;
107 }
108
109 /*
110 * Restore original buf and size as it's where caller expects
111 * the result will be saved.
112 */
113 hpp->buf = buf;
114 hpp->size = size;
115
79 return ret; 116 return ret;
80} 117}
81 118
82#define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ 119#define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
83static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 120static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
84 struct perf_hpp *hpp) \ 121 struct perf_hpp *hpp, \
122 struct perf_evsel *evsel) \
85{ \ 123{ \
86 int len = _min_width; \ 124 int len = _min_width; \
87 \ 125 \
88 if (symbol_conf.event_group) { \ 126 if (symbol_conf.event_group) \
89 struct perf_evsel *evsel = hpp->ptr; \
90 \
91 len = max(len, evsel->nr_members * _unit_width); \ 127 len = max(len, evsel->nr_members * _unit_width); \
92 } \ 128 \
93 return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \ 129 return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
94} 130}
95 131
96#define __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ 132#define __HPP_WIDTH_FN(_type, _min_width, _unit_width) \
97static int hpp__width_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 133static int hpp__width_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
98 struct perf_hpp *hpp __maybe_unused) \ 134 struct perf_hpp *hpp __maybe_unused, \
135 struct perf_evsel *evsel) \
99{ \ 136{ \
100 int len = _min_width; \ 137 int len = _min_width; \
101 \ 138 \
102 if (symbol_conf.event_group) { \ 139 if (symbol_conf.event_group) \
103 struct perf_evsel *evsel = hpp->ptr; \
104 \
105 len = max(len, evsel->nr_members * _unit_width); \ 140 len = max(len, evsel->nr_members * _unit_width); \
106 } \ 141 \
107 return len; \ 142 return len; \
108} 143}
109 144
145static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
146{
147 va_list args;
148 ssize_t ssize = hpp->size;
149 double percent;
150 int ret;
151
152 va_start(args, fmt);
153 percent = va_arg(args, double);
154 ret = value_color_snprintf(hpp->buf, hpp->size, fmt, percent);
155 va_end(args);
156
157 return (ret >= ssize) ? (ssize - 1) : ret;
158}
159
160static int hpp_entry_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
161{
162 va_list args;
163 ssize_t ssize = hpp->size;
164 int ret;
165
166 va_start(args, fmt);
167 ret = vsnprintf(hpp->buf, hpp->size, fmt, args);
168 va_end(args);
169
170 return (ret >= ssize) ? (ssize - 1) : ret;
171}
172
110#define __HPP_COLOR_PERCENT_FN(_type, _field) \ 173#define __HPP_COLOR_PERCENT_FN(_type, _field) \
111static u64 he_get_##_field(struct hist_entry *he) \ 174static u64 he_get_##_field(struct hist_entry *he) \
112{ \ 175{ \
@@ -116,8 +179,8 @@ static u64 he_get_##_field(struct hist_entry *he) \
116static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 179static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
117 struct perf_hpp *hpp, struct hist_entry *he) \ 180 struct perf_hpp *hpp, struct hist_entry *he) \
118{ \ 181{ \
119 return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ 182 return __hpp__fmt(hpp, he, he_get_##_field, NULL, " %6.2f%%", \
120 percent_color_snprintf, true); \ 183 hpp_color_scnprintf, true); \
121} 184}
122 185
123#define __HPP_ENTRY_PERCENT_FN(_type, _field) \ 186#define __HPP_ENTRY_PERCENT_FN(_type, _field) \
@@ -125,8 +188,8 @@ static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
125 struct perf_hpp *hpp, struct hist_entry *he) \ 188 struct perf_hpp *hpp, struct hist_entry *he) \
126{ \ 189{ \
127 const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ 190 const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \
128 return __hpp__fmt(hpp, he, he_get_##_field, fmt, \ 191 return __hpp__fmt(hpp, he, he_get_##_field, NULL, fmt, \
129 scnprintf, true); \ 192 hpp_entry_scnprintf, true); \
130} 193}
131 194
132#define __HPP_ENTRY_RAW_FN(_type, _field) \ 195#define __HPP_ENTRY_RAW_FN(_type, _field) \
@@ -139,7 +202,8 @@ static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
139 struct perf_hpp *hpp, struct hist_entry *he) \ 202 struct perf_hpp *hpp, struct hist_entry *he) \
140{ \ 203{ \
141 const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \ 204 const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \
142 return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, scnprintf, false); \ 205 return __hpp__fmt(hpp, he, he_get_raw_##_field, NULL, fmt, \
206 hpp_entry_scnprintf, false); \
143} 207}
144 208
145#define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \ 209#define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \
@@ -263,15 +327,13 @@ unsigned int hists__sort_list_width(struct hists *hists)
263 struct perf_hpp_fmt *fmt; 327 struct perf_hpp_fmt *fmt;
264 struct sort_entry *se; 328 struct sort_entry *se;
265 int i = 0, ret = 0; 329 int i = 0, ret = 0;
266 struct perf_hpp dummy_hpp = { 330 struct perf_hpp dummy_hpp;
267 .ptr = hists_to_evsel(hists),
268 };
269 331
270 perf_hpp__for_each_format(fmt) { 332 perf_hpp__for_each_format(fmt) {
271 if (i) 333 if (i)
272 ret += 2; 334 ret += 2;
273 335
274 ret += fmt->width(fmt, &dummy_hpp); 336 ret += fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists));
275 } 337 }
276 338
277 list_for_each_entry(se, &hist_entry__sort_list, list) 339 list_for_each_entry(se, &hist_entry__sort_list, list)
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 831fbb77d1ff..d59893edf031 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -306,12 +306,6 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he,
306 return hist_entry_callchain__fprintf(he, total_period, left_margin, fp); 306 return hist_entry_callchain__fprintf(he, total_period, left_margin, fp);
307} 307}
308 308
309static inline void advance_hpp(struct perf_hpp *hpp, int inc)
310{
311 hpp->buf += inc;
312 hpp->size -= inc;
313}
314
315static int hist_entry__period_snprintf(struct perf_hpp *hpp, 309static int hist_entry__period_snprintf(struct perf_hpp *hpp,
316 struct hist_entry *he) 310 struct hist_entry *he)
317{ 311{
@@ -385,7 +379,6 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
385 struct perf_hpp dummy_hpp = { 379 struct perf_hpp dummy_hpp = {
386 .buf = bf, 380 .buf = bf,
387 .size = sizeof(bf), 381 .size = sizeof(bf),
388 .ptr = hists_to_evsel(hists),
389 }; 382 };
390 bool first = true; 383 bool first = true;
391 size_t linesz; 384 size_t linesz;
@@ -404,7 +397,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
404 else 397 else
405 first = false; 398 first = false;
406 399
407 fmt->header(fmt, &dummy_hpp); 400 fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
408 fprintf(fp, "%s", bf); 401 fprintf(fp, "%s", bf);
409 } 402 }
410 403
@@ -449,7 +442,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
449 else 442 else
450 first = false; 443 first = false;
451 444
452 width = fmt->width(fmt, &dummy_hpp); 445 width = fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists));
453 for (i = 0; i < width; i++) 446 for (i = 0; i < width; i++)
454 fprintf(fp, "."); 447 fprintf(fp, ".");
455 } 448 }
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 469eb679fb9d..809b4c50beae 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -8,6 +8,8 @@
8 */ 8 */
9 9
10#include "util.h" 10#include "util.h"
11#include "ui/ui.h"
12#include "sort.h"
11#include "build-id.h" 13#include "build-id.h"
12#include "color.h" 14#include "color.h"
13#include "cache.h" 15#include "cache.h"
@@ -489,7 +491,7 @@ static int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
489{ 491{
490 struct annotation *notes; 492 struct annotation *notes;
491 493
492 if (sym == NULL || use_browser != 1 || !sort__has_sym) 494 if (sym == NULL)
493 return 0; 495 return 0;
494 496
495 notes = symbol__annotation(sym); 497 notes = symbol__annotation(sym);
@@ -1234,6 +1236,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
1234 struct dso *dso = map->dso; 1236 struct dso *dso = map->dso;
1235 char *filename; 1237 char *filename;
1236 const char *d_filename; 1238 const char *d_filename;
1239 const char *evsel_name = perf_evsel__name(evsel);
1237 struct annotation *notes = symbol__annotation(sym); 1240 struct annotation *notes = symbol__annotation(sym);
1238 struct disasm_line *pos, *queue = NULL; 1241 struct disasm_line *pos, *queue = NULL;
1239 u64 start = map__rip_2objdump(map, sym->start); 1242 u64 start = map__rip_2objdump(map, sym->start);
@@ -1241,7 +1244,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
1241 int more = 0; 1244 int more = 0;
1242 u64 len; 1245 u64 len;
1243 int width = 8; 1246 int width = 8;
1244 int namelen; 1247 int namelen, evsel_name_len, graph_dotted_len;
1245 1248
1246 filename = strdup(dso->long_name); 1249 filename = strdup(dso->long_name);
1247 if (!filename) 1250 if (!filename)
@@ -1254,14 +1257,17 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
1254 1257
1255 len = symbol__size(sym); 1258 len = symbol__size(sym);
1256 namelen = strlen(d_filename); 1259 namelen = strlen(d_filename);
1260 evsel_name_len = strlen(evsel_name);
1257 1261
1258 if (perf_evsel__is_group_event(evsel)) 1262 if (perf_evsel__is_group_event(evsel))
1259 width *= evsel->nr_members; 1263 width *= evsel->nr_members;
1260 1264
1261 printf(" %-*.*s| Source code & Disassembly of %s\n", 1265 printf(" %-*.*s| Source code & Disassembly of %s for %s\n",
1262 width, width, "Percent", d_filename); 1266 width, width, "Percent", d_filename, evsel_name);
1263 printf("-%-*.*s-------------------------------------\n", 1267
1264 width+namelen, width+namelen, graph_dotted_line); 1268 graph_dotted_len = width + namelen + evsel_name_len;
1269 printf("-%-*.*s-----------------------------------------\n",
1270 graph_dotted_len, graph_dotted_len, graph_dotted_line);
1265 1271
1266 if (verbose) 1272 if (verbose)
1267 symbol__annotate_hits(sym, evsel); 1273 symbol__annotate_hits(sym, evsel);
@@ -1399,3 +1405,8 @@ int hist_entry__annotate(struct hist_entry *he, size_t privsize)
1399{ 1405{
1400 return symbol__annotate(he->ms.sym, he->ms.map, privsize); 1406 return symbol__annotate(he->ms.sym, he->ms.map, privsize);
1401} 1407}
1408
1409bool ui__has_annotation(void)
1410{
1411 return use_browser == 1 && sort__has_sym;
1412}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index b2aef59d6bb2..56ad4f5287de 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -151,6 +151,8 @@ void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
151void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); 151void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
152void disasm__purge(struct list_head *head); 152void disasm__purge(struct list_head *head);
153 153
154bool ui__has_annotation(void);
155
154int symbol__tty_annotate(struct symbol *sym, struct map *map, 156int symbol__tty_annotate(struct symbol *sym, struct map *map,
155 struct perf_evsel *evsel, bool print_lines, 157 struct perf_evsel *evsel, bool print_lines,
156 bool full_paths, int min_pcnt, int max_lines); 158 bool full_paths, int min_pcnt, int max_lines);
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index a9b48c42e81e..7fe4994eeb63 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -1,5 +1,5 @@
1#include "util.h" 1#include "util.h"
2#include "fs.h" 2#include <api/fs/fs.h>
3#include "../perf.h" 3#include "../perf.h"
4#include "cpumap.h" 4#include "cpumap.h"
5#include <assert.h> 5#include <assert.h>
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 4045d086d9d9..64453d63b971 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -45,8 +45,8 @@ int dso__read_binary_type_filename(const struct dso *dso,
45 debuglink--; 45 debuglink--;
46 if (*debuglink == '/') 46 if (*debuglink == '/')
47 debuglink++; 47 debuglink++;
48 filename__read_debuglink(dso->long_name, debuglink, 48 ret = filename__read_debuglink(dso->long_name, debuglink,
49 size - (debuglink - filename)); 49 size - (debuglink - filename));
50 } 50 }
51 break; 51 break;
52 case DSO_BINARY_TYPE__BUILD_ID_CACHE: 52 case DSO_BINARY_TYPE__BUILD_ID_CACHE:
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index cd7d6f078cdd..ab06f1c03655 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -102,6 +102,16 @@ struct dso {
102 char name[0]; 102 char name[0];
103}; 103};
104 104
105/* dso__for_each_symbol - iterate over the symbols of given type
106 *
107 * @dso: the 'struct dso *' in which symbols itereated
108 * @pos: the 'struct symbol *' to use as a loop cursor
109 * @n: the 'struct rb_node *' to use as a temporary storage
110 * @type: the 'enum map_type' type of symbols
111 */
112#define dso__for_each_symbol(dso, pos, n, type) \
113 symbols__for_each_entry(&(dso)->symbols[(type)], pos, n)
114
105static inline void dso__set_loaded(struct dso *dso, enum map_type type) 115static inline void dso__set_loaded(struct dso *dso, enum map_type type)
106{ 116{
107 dso->loaded |= (1 << type); 117 dso->loaded |= (1 << type);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 1fc1c2f04772..9d12aa6dd485 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1,6 +1,7 @@
1#include <linux/types.h> 1#include <linux/types.h>
2#include "event.h" 2#include "event.h"
3#include "debug.h" 3#include "debug.h"
4#include "hist.h"
4#include "machine.h" 5#include "machine.h"
5#include "sort.h" 6#include "sort.h"
6#include "string.h" 7#include "string.h"
@@ -94,14 +95,10 @@ static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len)
94 95
95static pid_t perf_event__synthesize_comm(struct perf_tool *tool, 96static pid_t perf_event__synthesize_comm(struct perf_tool *tool,
96 union perf_event *event, pid_t pid, 97 union perf_event *event, pid_t pid,
97 int full,
98 perf_event__handler_t process, 98 perf_event__handler_t process,
99 struct machine *machine) 99 struct machine *machine)
100{ 100{
101 char filename[PATH_MAX];
102 size_t size; 101 size_t size;
103 DIR *tasks;
104 struct dirent dirent, *next;
105 pid_t tgid; 102 pid_t tgid;
106 103
107 memset(&event->comm, 0, sizeof(event->comm)); 104 memset(&event->comm, 0, sizeof(event->comm));
@@ -124,55 +121,35 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool,
124 event->comm.header.size = (sizeof(event->comm) - 121 event->comm.header.size = (sizeof(event->comm) -
125 (sizeof(event->comm.comm) - size) + 122 (sizeof(event->comm.comm) - size) +
126 machine->id_hdr_size); 123 machine->id_hdr_size);
127 if (!full) { 124 event->comm.tid = pid;
128 event->comm.tid = pid;
129
130 if (process(tool, event, &synth_sample, machine) != 0)
131 return -1;
132
133 goto out;
134 }
135 125
136 if (machine__is_default_guest(machine)) 126 if (process(tool, event, &synth_sample, machine) != 0)
137 return 0; 127 return -1;
138
139 snprintf(filename, sizeof(filename), "%s/proc/%d/task",
140 machine->root_dir, pid);
141
142 tasks = opendir(filename);
143 if (tasks == NULL) {
144 pr_debug("couldn't open %s\n", filename);
145 return 0;
146 }
147 128
148 while (!readdir_r(tasks, &dirent, &next) && next) { 129out:
149 char *end; 130 return tgid;
150 pid = strtol(dirent.d_name, &end, 10); 131}
151 if (*end)
152 continue;
153 132
154 /* already have tgid; jut want to update the comm */ 133static int perf_event__synthesize_fork(struct perf_tool *tool,
155 (void) perf_event__get_comm_tgid(pid, event->comm.comm, 134 union perf_event *event, pid_t pid,
156 sizeof(event->comm.comm)); 135 pid_t tgid, perf_event__handler_t process,
136 struct machine *machine)
137{
138 memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size);
157 139
158 size = strlen(event->comm.comm) + 1; 140 /* this is really a clone event but we use fork to synthesize it */
159 size = PERF_ALIGN(size, sizeof(u64)); 141 event->fork.ppid = tgid;
160 memset(event->comm.comm + size, 0, machine->id_hdr_size); 142 event->fork.ptid = tgid;
161 event->comm.header.size = (sizeof(event->comm) - 143 event->fork.pid = tgid;
162 (sizeof(event->comm.comm) - size) + 144 event->fork.tid = pid;
163 machine->id_hdr_size); 145 event->fork.header.type = PERF_RECORD_FORK;
164 146
165 event->comm.tid = pid; 147 event->fork.header.size = (sizeof(event->fork) + machine->id_hdr_size);
166 148
167 if (process(tool, event, &synth_sample, machine) != 0) { 149 if (process(tool, event, &synth_sample, machine) != 0)
168 tgid = -1; 150 return -1;
169 break;
170 }
171 }
172 151
173 closedir(tasks); 152 return 0;
174out:
175 return tgid;
176} 153}
177 154
178int perf_event__synthesize_mmap_events(struct perf_tool *tool, 155int perf_event__synthesize_mmap_events(struct perf_tool *tool,
@@ -324,17 +301,71 @@ int perf_event__synthesize_modules(struct perf_tool *tool,
324 301
325static int __event__synthesize_thread(union perf_event *comm_event, 302static int __event__synthesize_thread(union perf_event *comm_event,
326 union perf_event *mmap_event, 303 union perf_event *mmap_event,
304 union perf_event *fork_event,
327 pid_t pid, int full, 305 pid_t pid, int full,
328 perf_event__handler_t process, 306 perf_event__handler_t process,
329 struct perf_tool *tool, 307 struct perf_tool *tool,
330 struct machine *machine, bool mmap_data) 308 struct machine *machine, bool mmap_data)
331{ 309{
332 pid_t tgid = perf_event__synthesize_comm(tool, comm_event, pid, full, 310 char filename[PATH_MAX];
311 DIR *tasks;
312 struct dirent dirent, *next;
313 pid_t tgid;
314
315 /* special case: only send one comm event using passed in pid */
316 if (!full) {
317 tgid = perf_event__synthesize_comm(tool, comm_event, pid,
318 process, machine);
319
320 if (tgid == -1)
321 return -1;
322
323 return perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
324 process, machine, mmap_data);
325 }
326
327 if (machine__is_default_guest(machine))
328 return 0;
329
330 snprintf(filename, sizeof(filename), "%s/proc/%d/task",
331 machine->root_dir, pid);
332
333 tasks = opendir(filename);
334 if (tasks == NULL) {
335 pr_debug("couldn't open %s\n", filename);
336 return 0;
337 }
338
339 while (!readdir_r(tasks, &dirent, &next) && next) {
340 char *end;
341 int rc = 0;
342 pid_t _pid;
343
344 _pid = strtol(dirent.d_name, &end, 10);
345 if (*end)
346 continue;
347
348 tgid = perf_event__synthesize_comm(tool, comm_event, _pid,
349 process, machine);
350 if (tgid == -1)
351 return -1;
352
353 if (_pid == pid) {
354 /* process the parent's maps too */
355 rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
356 process, machine, mmap_data);
357 } else {
358 /* only fork the tid's map, to save time */
359 rc = perf_event__synthesize_fork(tool, fork_event, _pid, tgid,
333 process, machine); 360 process, machine);
334 if (tgid == -1) 361 }
335 return -1; 362
336 return perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid, 363 if (rc)
337 process, machine, mmap_data); 364 return rc;
365 }
366
367 closedir(tasks);
368 return 0;
338} 369}
339 370
340int perf_event__synthesize_thread_map(struct perf_tool *tool, 371int perf_event__synthesize_thread_map(struct perf_tool *tool,
@@ -343,7 +374,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
343 struct machine *machine, 374 struct machine *machine,
344 bool mmap_data) 375 bool mmap_data)
345{ 376{
346 union perf_event *comm_event, *mmap_event; 377 union perf_event *comm_event, *mmap_event, *fork_event;
347 int err = -1, thread, j; 378 int err = -1, thread, j;
348 379
349 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size); 380 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
@@ -354,9 +385,14 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
354 if (mmap_event == NULL) 385 if (mmap_event == NULL)
355 goto out_free_comm; 386 goto out_free_comm;
356 387
388 fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
389 if (fork_event == NULL)
390 goto out_free_mmap;
391
357 err = 0; 392 err = 0;
358 for (thread = 0; thread < threads->nr; ++thread) { 393 for (thread = 0; thread < threads->nr; ++thread) {
359 if (__event__synthesize_thread(comm_event, mmap_event, 394 if (__event__synthesize_thread(comm_event, mmap_event,
395 fork_event,
360 threads->map[thread], 0, 396 threads->map[thread], 0,
361 process, tool, machine, 397 process, tool, machine,
362 mmap_data)) { 398 mmap_data)) {
@@ -382,6 +418,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
382 /* if not, generate events for it */ 418 /* if not, generate events for it */
383 if (need_leader && 419 if (need_leader &&
384 __event__synthesize_thread(comm_event, mmap_event, 420 __event__synthesize_thread(comm_event, mmap_event,
421 fork_event,
385 comm_event->comm.pid, 0, 422 comm_event->comm.pid, 0,
386 process, tool, machine, 423 process, tool, machine,
387 mmap_data)) { 424 mmap_data)) {
@@ -390,6 +427,8 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
390 } 427 }
391 } 428 }
392 } 429 }
430 free(fork_event);
431out_free_mmap:
393 free(mmap_event); 432 free(mmap_event);
394out_free_comm: 433out_free_comm:
395 free(comm_event); 434 free(comm_event);
@@ -404,9 +443,12 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
404 DIR *proc; 443 DIR *proc;
405 char proc_path[PATH_MAX]; 444 char proc_path[PATH_MAX];
406 struct dirent dirent, *next; 445 struct dirent dirent, *next;
407 union perf_event *comm_event, *mmap_event; 446 union perf_event *comm_event, *mmap_event, *fork_event;
408 int err = -1; 447 int err = -1;
409 448
449 if (machine__is_default_guest(machine))
450 return 0;
451
410 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size); 452 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
411 if (comm_event == NULL) 453 if (comm_event == NULL)
412 goto out; 454 goto out;
@@ -415,14 +457,15 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
415 if (mmap_event == NULL) 457 if (mmap_event == NULL)
416 goto out_free_comm; 458 goto out_free_comm;
417 459
418 if (machine__is_default_guest(machine)) 460 fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
419 return 0; 461 if (fork_event == NULL)
462 goto out_free_mmap;
420 463
421 snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir); 464 snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
422 proc = opendir(proc_path); 465 proc = opendir(proc_path);
423 466
424 if (proc == NULL) 467 if (proc == NULL)
425 goto out_free_mmap; 468 goto out_free_fork;
426 469
427 while (!readdir_r(proc, &dirent, &next) && next) { 470 while (!readdir_r(proc, &dirent, &next) && next) {
428 char *end; 471 char *end;
@@ -434,12 +477,14 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
434 * We may race with exiting thread, so don't stop just because 477 * We may race with exiting thread, so don't stop just because
435 * one thread couldn't be synthesized. 478 * one thread couldn't be synthesized.
436 */ 479 */
437 __event__synthesize_thread(comm_event, mmap_event, pid, 1, 480 __event__synthesize_thread(comm_event, mmap_event, fork_event, pid,
438 process, tool, machine, mmap_data); 481 1, process, tool, machine, mmap_data);
439 } 482 }
440 483
441 err = 0; 484 err = 0;
442 closedir(proc); 485 closedir(proc);
486out_free_fork:
487 free(fork_event);
443out_free_mmap: 488out_free_mmap:
444 free(mmap_event); 489 free(mmap_event);
445out_free_comm: 490out_free_comm:
@@ -470,23 +515,32 @@ static int find_symbol_cb(void *arg, const char *name, char type,
470 return 1; 515 return 1;
471} 516}
472 517
518u64 kallsyms__get_function_start(const char *kallsyms_filename,
519 const char *symbol_name)
520{
521 struct process_symbol_args args = { .name = symbol_name, };
522
523 if (kallsyms__parse(kallsyms_filename, &args, find_symbol_cb) <= 0)
524 return 0;
525
526 return args.start;
527}
528
473int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, 529int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
474 perf_event__handler_t process, 530 perf_event__handler_t process,
475 struct machine *machine, 531 struct machine *machine)
476 const char *symbol_name)
477{ 532{
478 size_t size; 533 size_t size;
479 const char *filename, *mmap_name; 534 const char *mmap_name;
480 char path[PATH_MAX];
481 char name_buff[PATH_MAX]; 535 char name_buff[PATH_MAX];
482 struct map *map; 536 struct map *map;
537 struct kmap *kmap;
483 int err; 538 int err;
484 /* 539 /*
485 * We should get this from /sys/kernel/sections/.text, but till that is 540 * We should get this from /sys/kernel/sections/.text, but till that is
486 * available use this, and after it is use this as a fallback for older 541 * available use this, and after it is use this as a fallback for older
487 * kernels. 542 * kernels.
488 */ 543 */
489 struct process_symbol_args args = { .name = symbol_name, };
490 union perf_event *event = zalloc((sizeof(event->mmap) + 544 union perf_event *event = zalloc((sizeof(event->mmap) +
491 machine->id_hdr_size)); 545 machine->id_hdr_size));
492 if (event == NULL) { 546 if (event == NULL) {
@@ -502,30 +556,19 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
502 * see kernel/perf_event.c __perf_event_mmap 556 * see kernel/perf_event.c __perf_event_mmap
503 */ 557 */
504 event->header.misc = PERF_RECORD_MISC_KERNEL; 558 event->header.misc = PERF_RECORD_MISC_KERNEL;
505 filename = "/proc/kallsyms";
506 } else { 559 } else {
507 event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL; 560 event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
508 if (machine__is_default_guest(machine))
509 filename = (char *) symbol_conf.default_guest_kallsyms;
510 else {
511 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
512 filename = path;
513 }
514 }
515
516 if (kallsyms__parse(filename, &args, find_symbol_cb) <= 0) {
517 free(event);
518 return -ENOENT;
519 } 561 }
520 562
521 map = machine->vmlinux_maps[MAP__FUNCTION]; 563 map = machine->vmlinux_maps[MAP__FUNCTION];
564 kmap = map__kmap(map);
522 size = snprintf(event->mmap.filename, sizeof(event->mmap.filename), 565 size = snprintf(event->mmap.filename, sizeof(event->mmap.filename),
523 "%s%s", mmap_name, symbol_name) + 1; 566 "%s%s", mmap_name, kmap->ref_reloc_sym->name) + 1;
524 size = PERF_ALIGN(size, sizeof(u64)); 567 size = PERF_ALIGN(size, sizeof(u64));
525 event->mmap.header.type = PERF_RECORD_MMAP; 568 event->mmap.header.type = PERF_RECORD_MMAP;
526 event->mmap.header.size = (sizeof(event->mmap) - 569 event->mmap.header.size = (sizeof(event->mmap) -
527 (sizeof(event->mmap.filename) - size) + machine->id_hdr_size); 570 (sizeof(event->mmap.filename) - size) + machine->id_hdr_size);
528 event->mmap.pgoff = args.start; 571 event->mmap.pgoff = kmap->ref_reloc_sym->addr;
529 event->mmap.start = map->start; 572 event->mmap.start = map->start;
530 event->mmap.len = map->end - event->mmap.start; 573 event->mmap.len = map->end - event->mmap.start;
531 event->mmap.pid = machine->pid; 574 event->mmap.pid = machine->pid;
@@ -663,7 +706,7 @@ void thread__find_addr_map(struct thread *thread,
663 al->thread = thread; 706 al->thread = thread;
664 al->addr = addr; 707 al->addr = addr;
665 al->cpumode = cpumode; 708 al->cpumode = cpumode;
666 al->filtered = false; 709 al->filtered = 0;
667 710
668 if (machine == NULL) { 711 if (machine == NULL) {
669 al->map = NULL; 712 al->map = NULL;
@@ -689,11 +732,11 @@ void thread__find_addr_map(struct thread *thread,
689 if ((cpumode == PERF_RECORD_MISC_GUEST_USER || 732 if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
690 cpumode == PERF_RECORD_MISC_GUEST_KERNEL) && 733 cpumode == PERF_RECORD_MISC_GUEST_KERNEL) &&
691 !perf_guest) 734 !perf_guest)
692 al->filtered = true; 735 al->filtered |= (1 << HIST_FILTER__GUEST);
693 if ((cpumode == PERF_RECORD_MISC_USER || 736 if ((cpumode == PERF_RECORD_MISC_USER ||
694 cpumode == PERF_RECORD_MISC_KERNEL) && 737 cpumode == PERF_RECORD_MISC_KERNEL) &&
695 !perf_host) 738 !perf_host)
696 al->filtered = true; 739 al->filtered |= (1 << HIST_FILTER__HOST);
697 740
698 return; 741 return;
699 } 742 }
@@ -750,9 +793,6 @@ int perf_event__preprocess_sample(const union perf_event *event,
750 if (thread == NULL) 793 if (thread == NULL)
751 return -1; 794 return -1;
752 795
753 if (thread__is_filtered(thread))
754 goto out_filtered;
755
756 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); 796 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
757 /* 797 /*
758 * Have we already created the kernel maps for this machine? 798 * Have we already created the kernel maps for this machine?
@@ -770,6 +810,10 @@ int perf_event__preprocess_sample(const union perf_event *event,
770 dump_printf(" ...... dso: %s\n", 810 dump_printf(" ...... dso: %s\n",
771 al->map ? al->map->dso->long_name : 811 al->map ? al->map->dso->long_name :
772 al->level == 'H' ? "[hypervisor]" : "<not found>"); 812 al->level == 'H' ? "[hypervisor]" : "<not found>");
813
814 if (thread__is_filtered(thread))
815 al->filtered |= (1 << HIST_FILTER__THREAD);
816
773 al->sym = NULL; 817 al->sym = NULL;
774 al->cpu = sample->cpu; 818 al->cpu = sample->cpu;
775 819
@@ -781,8 +825,9 @@ int perf_event__preprocess_sample(const union perf_event *event,
781 dso->short_name) || 825 dso->short_name) ||
782 (dso->short_name != dso->long_name && 826 (dso->short_name != dso->long_name &&
783 strlist__has_entry(symbol_conf.dso_list, 827 strlist__has_entry(symbol_conf.dso_list,
784 dso->long_name))))) 828 dso->long_name))))) {
785 goto out_filtered; 829 al->filtered |= (1 << HIST_FILTER__DSO);
830 }
786 831
787 al->sym = map__find_symbol(al->map, al->addr, 832 al->sym = map__find_symbol(al->map, al->addr,
788 machine->symbol_filter); 833 machine->symbol_filter);
@@ -790,12 +835,9 @@ int perf_event__preprocess_sample(const union perf_event *event,
790 835
791 if (symbol_conf.sym_list && 836 if (symbol_conf.sym_list &&
792 (!al->sym || !strlist__has_entry(symbol_conf.sym_list, 837 (!al->sym || !strlist__has_entry(symbol_conf.sym_list,
793 al->sym->name))) 838 al->sym->name))) {
794 goto out_filtered; 839 al->filtered |= (1 << HIST_FILTER__SYMBOL);
795 840 }
796 return 0;
797 841
798out_filtered:
799 al->filtered = true;
800 return 0; 842 return 0;
801} 843}
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index faf6e219be21..38457d447a13 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -85,6 +85,7 @@ struct sample_event {
85 85
86struct regs_dump { 86struct regs_dump {
87 u64 abi; 87 u64 abi;
88 u64 mask;
88 u64 *regs; 89 u64 *regs;
89}; 90};
90 91
@@ -214,8 +215,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
214 struct machine *machine, bool mmap_data); 215 struct machine *machine, bool mmap_data);
215int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, 216int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
216 perf_event__handler_t process, 217 perf_event__handler_t process,
217 struct machine *machine, 218 struct machine *machine);
218 const char *symbol_name);
219 219
220int perf_event__synthesize_modules(struct perf_tool *tool, 220int perf_event__synthesize_modules(struct perf_tool *tool,
221 perf_event__handler_t process, 221 perf_event__handler_t process,
@@ -260,9 +260,9 @@ int perf_event__preprocess_sample(const union perf_event *event,
260const char *perf_event__name(unsigned int id); 260const char *perf_event__name(unsigned int id);
261 261
262size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, 262size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
263 u64 sample_regs_user, u64 read_format); 263 u64 read_format);
264int perf_event__synthesize_sample(union perf_event *event, u64 type, 264int perf_event__synthesize_sample(union perf_event *event, u64 type,
265 u64 sample_regs_user, u64 read_format, 265 u64 read_format,
266 const struct perf_sample *sample, 266 const struct perf_sample *sample,
267 bool swapped); 267 bool swapped);
268 268
@@ -279,4 +279,7 @@ size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
279size_t perf_event__fprintf_task(union perf_event *event, FILE *fp); 279size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
280size_t perf_event__fprintf(union perf_event *event, FILE *fp); 280size_t perf_event__fprintf(union perf_event *event, FILE *fp);
281 281
282u64 kallsyms__get_function_start(const char *kallsyms_filename,
283 const char *symbol_name);
284
282#endif /* __PERF_RECORD_H */ 285#endif /* __PERF_RECORD_H */
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 55407c594b87..5c28d82b76c4 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -500,6 +500,34 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)
500 return ret; 500 return ret;
501} 501}
502 502
503static void
504perf_evsel__config_callgraph(struct perf_evsel *evsel,
505 struct record_opts *opts)
506{
507 bool function = perf_evsel__is_function_event(evsel);
508 struct perf_event_attr *attr = &evsel->attr;
509
510 perf_evsel__set_sample_bit(evsel, CALLCHAIN);
511
512 if (opts->call_graph == CALLCHAIN_DWARF) {
513 if (!function) {
514 perf_evsel__set_sample_bit(evsel, REGS_USER);
515 perf_evsel__set_sample_bit(evsel, STACK_USER);
516 attr->sample_regs_user = PERF_REGS_MASK;
517 attr->sample_stack_user = opts->stack_dump_size;
518 attr->exclude_callchain_user = 1;
519 } else {
520 pr_info("Cannot use DWARF unwind for function trace event,"
521 " falling back to framepointers.\n");
522 }
523 }
524
525 if (function) {
526 pr_info("Disabling user space callchains for function trace event.\n");
527 attr->exclude_callchain_user = 1;
528 }
529}
530
503/* 531/*
504 * The enable_on_exec/disabled value strategy: 532 * The enable_on_exec/disabled value strategy:
505 * 533 *
@@ -595,17 +623,8 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)
595 attr->mmap_data = track; 623 attr->mmap_data = track;
596 } 624 }
597 625
598 if (opts->call_graph) { 626 if (opts->call_graph_enabled)
599 perf_evsel__set_sample_bit(evsel, CALLCHAIN); 627 perf_evsel__config_callgraph(evsel, opts);
600
601 if (opts->call_graph == CALLCHAIN_DWARF) {
602 perf_evsel__set_sample_bit(evsel, REGS_USER);
603 perf_evsel__set_sample_bit(evsel, STACK_USER);
604 attr->sample_regs_user = PERF_REGS_MASK;
605 attr->sample_stack_user = opts->stack_dump_size;
606 attr->exclude_callchain_user = 1;
607 }
608 }
609 628
610 if (target__has_cpu(&opts->target)) 629 if (target__has_cpu(&opts->target))
611 perf_evsel__set_sample_bit(evsel, CPU); 630 perf_evsel__set_sample_bit(evsel, CPU);
@@ -1004,7 +1023,7 @@ retry_sample_id:
1004 1023
1005 group_fd = get_group_fd(evsel, cpu, thread); 1024 group_fd = get_group_fd(evsel, cpu, thread);
1006retry_open: 1025retry_open:
1007 pr_debug2("perf_event_open: pid %d cpu %d group_fd %d flags %#lx\n", 1026 pr_debug2("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx\n",
1008 pid, cpus->map[cpu], group_fd, flags); 1027 pid, cpus->map[cpu], group_fd, flags);
1009 1028
1010 FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr, 1029 FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr,
@@ -1013,7 +1032,7 @@ retry_open:
1013 group_fd, flags); 1032 group_fd, flags);
1014 if (FD(evsel, cpu, thread) < 0) { 1033 if (FD(evsel, cpu, thread) < 0) {
1015 err = -errno; 1034 err = -errno;
1016 pr_debug2("perf_event_open failed, error %d\n", 1035 pr_debug2("sys_perf_event_open failed, error %d\n",
1017 err); 1036 err);
1018 goto try_fallback; 1037 goto try_fallback;
1019 } 1038 }
@@ -1220,7 +1239,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
1220 memset(data, 0, sizeof(*data)); 1239 memset(data, 0, sizeof(*data));
1221 data->cpu = data->pid = data->tid = -1; 1240 data->cpu = data->pid = data->tid = -1;
1222 data->stream_id = data->id = data->time = -1ULL; 1241 data->stream_id = data->id = data->time = -1ULL;
1223 data->period = 1; 1242 data->period = evsel->attr.sample_period;
1224 data->weight = 0; 1243 data->weight = 0;
1225 1244
1226 if (event->header.type != PERF_RECORD_SAMPLE) { 1245 if (event->header.type != PERF_RECORD_SAMPLE) {
@@ -1396,10 +1415,11 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
1396 array++; 1415 array++;
1397 1416
1398 if (data->user_regs.abi) { 1417 if (data->user_regs.abi) {
1399 u64 regs_user = evsel->attr.sample_regs_user; 1418 u64 mask = evsel->attr.sample_regs_user;
1400 1419
1401 sz = hweight_long(regs_user) * sizeof(u64); 1420 sz = hweight_long(mask) * sizeof(u64);
1402 OVERFLOW_CHECK(array, sz, max_size); 1421 OVERFLOW_CHECK(array, sz, max_size);
1422 data->user_regs.mask = mask;
1403 data->user_regs.regs = (u64 *)array; 1423 data->user_regs.regs = (u64 *)array;
1404 array = (void *)array + sz; 1424 array = (void *)array + sz;
1405 } 1425 }
@@ -1451,7 +1471,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
1451} 1471}
1452 1472
1453size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, 1473size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
1454 u64 sample_regs_user, u64 read_format) 1474 u64 read_format)
1455{ 1475{
1456 size_t sz, result = sizeof(struct sample_event); 1476 size_t sz, result = sizeof(struct sample_event);
1457 1477
@@ -1517,7 +1537,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
1517 if (type & PERF_SAMPLE_REGS_USER) { 1537 if (type & PERF_SAMPLE_REGS_USER) {
1518 if (sample->user_regs.abi) { 1538 if (sample->user_regs.abi) {
1519 result += sizeof(u64); 1539 result += sizeof(u64);
1520 sz = hweight_long(sample_regs_user) * sizeof(u64); 1540 sz = hweight_long(sample->user_regs.mask) * sizeof(u64);
1521 result += sz; 1541 result += sz;
1522 } else { 1542 } else {
1523 result += sizeof(u64); 1543 result += sizeof(u64);
@@ -1546,7 +1566,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
1546} 1566}
1547 1567
1548int perf_event__synthesize_sample(union perf_event *event, u64 type, 1568int perf_event__synthesize_sample(union perf_event *event, u64 type,
1549 u64 sample_regs_user, u64 read_format, 1569 u64 read_format,
1550 const struct perf_sample *sample, 1570 const struct perf_sample *sample,
1551 bool swapped) 1571 bool swapped)
1552{ 1572{
@@ -1687,7 +1707,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
1687 if (type & PERF_SAMPLE_REGS_USER) { 1707 if (type & PERF_SAMPLE_REGS_USER) {
1688 if (sample->user_regs.abi) { 1708 if (sample->user_regs.abi) {
1689 *array++ = sample->user_regs.abi; 1709 *array++ = sample->user_regs.abi;
1690 sz = hweight_long(sample_regs_user) * sizeof(u64); 1710 sz = hweight_long(sample->user_regs.mask) * sizeof(u64);
1691 memcpy(array, sample->user_regs.regs, sz); 1711 memcpy(array, sample->user_regs.regs, sz);
1692 array = (void *)array + sz; 1712 array = (void *)array + sz;
1693 } else { 1713 } else {
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index f1b325665aae..0c9926cfb292 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -315,6 +315,24 @@ static inline bool perf_evsel__is_group_event(struct perf_evsel *evsel)
315 return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1; 315 return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1;
316} 316}
317 317
318/**
319 * perf_evsel__is_function_event - Return whether given evsel is a function
320 * trace event
321 *
322 * @evsel - evsel selector to be tested
323 *
324 * Return %true if event is function trace event
325 */
326static inline bool perf_evsel__is_function_event(struct perf_evsel *evsel)
327{
328#define FUNCTION_EVENT "ftrace:function"
329
330 return evsel->name &&
331 !strncmp(FUNCTION_EVENT, evsel->name, sizeof(FUNCTION_EVENT));
332
333#undef FUNCTION_EVENT
334}
335
318struct perf_attr_details { 336struct perf_attr_details {
319 bool freq; 337 bool freq;
320 bool verbose; 338 bool verbose;
diff --git a/tools/perf/util/fs.h b/tools/perf/util/fs.h
deleted file mode 100644
index 5e09ce1bab0e..000000000000
--- a/tools/perf/util/fs.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef __PERF_FS
2#define __PERF_FS
3
4const char *sysfs__mountpoint(void);
5const char *procfs__mountpoint(void);
6
7#endif /* __PERF_FS */
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index e4e6249b87d4..f38590d7561b 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -13,13 +13,6 @@ static bool hists__filter_entry_by_thread(struct hists *hists,
13static bool hists__filter_entry_by_symbol(struct hists *hists, 13static bool hists__filter_entry_by_symbol(struct hists *hists,
14 struct hist_entry *he); 14 struct hist_entry *he);
15 15
16enum hist_filter {
17 HIST_FILTER__DSO,
18 HIST_FILTER__THREAD,
19 HIST_FILTER__PARENT,
20 HIST_FILTER__SYMBOL,
21};
22
23struct callchain_param callchain_param = { 16struct callchain_param callchain_param = {
24 .mode = CHAIN_GRAPH_REL, 17 .mode = CHAIN_GRAPH_REL,
25 .min_percent = 0.5, 18 .min_percent = 0.5,
@@ -290,7 +283,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)
290 if (he->branch_info) { 283 if (he->branch_info) {
291 /* 284 /*
292 * This branch info is (a part of) allocated from 285 * This branch info is (a part of) allocated from
293 * machine__resolve_bstack() and will be freed after 286 * sample__resolve_bstack() and will be freed after
294 * adding new entries. So we need to save a copy. 287 * adding new entries. So we need to save a copy.
295 */ 288 */
296 he->branch_info = malloc(sizeof(*he->branch_info)); 289 he->branch_info = malloc(sizeof(*he->branch_info));
@@ -369,7 +362,7 @@ static struct hist_entry *add_hist_entry(struct hists *hists,
369 he_stat__add_period(&he->stat, period, weight); 362 he_stat__add_period(&he->stat, period, weight);
370 363
371 /* 364 /*
372 * This mem info was allocated from machine__resolve_mem 365 * This mem info was allocated from sample__resolve_mem
373 * and will not be used anymore. 366 * and will not be used anymore.
374 */ 367 */
375 zfree(&entry->mem_info); 368 zfree(&entry->mem_info);
@@ -429,7 +422,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists,
429 .weight = weight, 422 .weight = weight,
430 }, 423 },
431 .parent = sym_parent, 424 .parent = sym_parent,
432 .filtered = symbol__parent_filter(sym_parent), 425 .filtered = symbol__parent_filter(sym_parent) | al->filtered,
433 .hists = hists, 426 .hists = hists,
434 .branch_info = bi, 427 .branch_info = bi,
435 .mem_info = mi, 428 .mem_info = mi,
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index a59743fa3ef7..1f1f513dfe7f 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -14,6 +14,15 @@ struct hist_entry;
14struct addr_location; 14struct addr_location;
15struct symbol; 15struct symbol;
16 16
17enum hist_filter {
18 HIST_FILTER__DSO,
19 HIST_FILTER__THREAD,
20 HIST_FILTER__PARENT,
21 HIST_FILTER__SYMBOL,
22 HIST_FILTER__GUEST,
23 HIST_FILTER__HOST,
24};
25
17/* 26/*
18 * The kernel collects the number of events it couldn't send in a stretch and 27 * The kernel collects the number of events it couldn't send in a stretch and
19 * when possible sends this number in a PERF_RECORD_LOST event. The number of 28 * when possible sends this number in a PERF_RECORD_LOST event. The number of
@@ -132,8 +141,10 @@ struct perf_hpp {
132}; 141};
133 142
134struct perf_hpp_fmt { 143struct perf_hpp_fmt {
135 int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp); 144 int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
136 int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp); 145 struct perf_evsel *evsel);
146 int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
147 struct perf_evsel *evsel);
137 int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 148 int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
138 struct hist_entry *he); 149 struct hist_entry *he);
139 int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 150 int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
@@ -166,6 +177,20 @@ void perf_hpp__init(void);
166void perf_hpp__column_register(struct perf_hpp_fmt *format); 177void perf_hpp__column_register(struct perf_hpp_fmt *format);
167void perf_hpp__column_enable(unsigned col); 178void perf_hpp__column_enable(unsigned col);
168 179
180typedef u64 (*hpp_field_fn)(struct hist_entry *he);
181typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
182typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
183
184int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
185 hpp_field_fn get_field, hpp_callback_fn callback,
186 const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent);
187
188static inline void advance_hpp(struct perf_hpp *hpp, int inc)
189{
190 hpp->buf += inc;
191 hpp->size -= inc;
192}
193
169static inline size_t perf_hpp__use_color(void) 194static inline size_t perf_hpp__use_color(void)
170{ 195{
171 return !symbol_conf.field_sep; 196 return !symbol_conf.field_sep;
diff --git a/tools/perf/util/include/asm/hash.h b/tools/perf/util/include/asm/hash.h
new file mode 100644
index 000000000000..d82b170bb216
--- /dev/null
+++ b/tools/perf/util/include/asm/hash.h
@@ -0,0 +1,6 @@
1#ifndef __ASM_GENERIC_HASH_H
2#define __ASM_GENERIC_HASH_H
3
4/* Stub */
5
6#endif /* __ASM_GENERIC_HASH_H */
diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h
index 45cf10a562bd..dadfa7e54287 100644
--- a/tools/perf/util/include/linux/bitops.h
+++ b/tools/perf/util/include/linux/bitops.h
@@ -87,13 +87,15 @@ static __always_inline unsigned long __ffs(unsigned long word)
87 return num; 87 return num;
88} 88}
89 89
90typedef const unsigned long __attribute__((__may_alias__)) long_alias_t;
91
90/* 92/*
91 * Find the first set bit in a memory region. 93 * Find the first set bit in a memory region.
92 */ 94 */
93static inline unsigned long 95static inline unsigned long
94find_first_bit(const unsigned long *addr, unsigned long size) 96find_first_bit(const unsigned long *addr, unsigned long size)
95{ 97{
96 const unsigned long *p = addr; 98 long_alias_t *p = (long_alias_t *) addr;
97 unsigned long result = 0; 99 unsigned long result = 0;
98 unsigned long tmp; 100 unsigned long tmp;
99 101
diff --git a/tools/perf/util/include/linux/hash.h b/tools/perf/util/include/linux/hash.h
deleted file mode 100644
index 201f57397997..000000000000
--- a/tools/perf/util/include/linux/hash.h
+++ /dev/null
@@ -1,5 +0,0 @@
1#include "../../../../include/linux/hash.h"
2
3#ifndef PERF_HASH_H
4#define PERF_HASH_H
5#endif
diff --git a/tools/perf/util/include/linux/kernel.h b/tools/perf/util/include/linux/kernel.h
index d8c927c868ee..9844c31b7c2b 100644
--- a/tools/perf/util/include/linux/kernel.h
+++ b/tools/perf/util/include/linux/kernel.h
@@ -94,12 +94,6 @@ static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
94 return (i >= ssize) ? (ssize - 1) : i; 94 return (i >= ssize) ? (ssize - 1) : i;
95} 95}
96 96
97static inline unsigned long
98simple_strtoul(const char *nptr, char **endptr, int base)
99{
100 return strtoul(nptr, endptr, base);
101}
102
103int eprintf(int level, 97int eprintf(int level,
104 const char *fmt, ...) __attribute__((format(printf, 2, 3))); 98 const char *fmt, ...) __attribute__((format(printf, 2, 3)));
105 99
diff --git a/tools/perf/util/include/linux/list.h b/tools/perf/util/include/linux/list.h
index 1d928a0ce997..bfe0a2afd0d2 100644
--- a/tools/perf/util/include/linux/list.h
+++ b/tools/perf/util/include/linux/list.h
@@ -1,5 +1,4 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/prefetch.h>
3 2
4#include "../../../../include/linux/list.h" 3#include "../../../../include/linux/list.h"
5 4
diff --git a/tools/perf/util/include/linux/prefetch.h b/tools/perf/util/include/linux/prefetch.h
deleted file mode 100644
index 7841e485d8c3..000000000000
--- a/tools/perf/util/include/linux/prefetch.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef PERF_LINUX_PREFETCH_H
2#define PERF_LINUX_PREFETCH_H
3
4static inline void prefetch(void *a __attribute__((unused))) { }
5
6#endif
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index ded74590b92f..a53cd0b8c151 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -327,9 +327,10 @@ struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,
327 return __machine__findnew_thread(machine, pid, tid, true); 327 return __machine__findnew_thread(machine, pid, tid, true);
328} 328}
329 329
330struct thread *machine__find_thread(struct machine *machine, pid_t tid) 330struct thread *machine__find_thread(struct machine *machine, pid_t pid,
331 pid_t tid)
331{ 332{
332 return __machine__findnew_thread(machine, 0, tid, false); 333 return __machine__findnew_thread(machine, pid, tid, false);
333} 334}
334 335
335int machine__process_comm_event(struct machine *machine, union perf_event *event, 336int machine__process_comm_event(struct machine *machine, union perf_event *event,
@@ -496,19 +497,22 @@ static int symbol__in_kernel(void *arg, const char *name,
496 return 1; 497 return 1;
497} 498}
498 499
500static void machine__get_kallsyms_filename(struct machine *machine, char *buf,
501 size_t bufsz)
502{
503 if (machine__is_default_guest(machine))
504 scnprintf(buf, bufsz, "%s", symbol_conf.default_guest_kallsyms);
505 else
506 scnprintf(buf, bufsz, "%s/proc/kallsyms", machine->root_dir);
507}
508
499/* Figure out the start address of kernel map from /proc/kallsyms */ 509/* Figure out the start address of kernel map from /proc/kallsyms */
500static u64 machine__get_kernel_start_addr(struct machine *machine) 510static u64 machine__get_kernel_start_addr(struct machine *machine)
501{ 511{
502 const char *filename; 512 char filename[PATH_MAX];
503 char path[PATH_MAX];
504 struct process_args args; 513 struct process_args args;
505 514
506 if (machine__is_default_guest(machine)) 515 machine__get_kallsyms_filename(machine, filename, PATH_MAX);
507 filename = (char *)symbol_conf.default_guest_kallsyms;
508 else {
509 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
510 filename = path;
511 }
512 516
513 if (symbol__restricted_filename(filename, "/proc/kallsyms")) 517 if (symbol__restricted_filename(filename, "/proc/kallsyms"))
514 return 0; 518 return 0;
@@ -829,9 +833,25 @@ static int machine__create_modules(struct machine *machine)
829 return 0; 833 return 0;
830} 834}
831 835
836const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
837
832int machine__create_kernel_maps(struct machine *machine) 838int machine__create_kernel_maps(struct machine *machine)
833{ 839{
834 struct dso *kernel = machine__get_kernel(machine); 840 struct dso *kernel = machine__get_kernel(machine);
841 char filename[PATH_MAX];
842 const char *name;
843 u64 addr = 0;
844 int i;
845
846 machine__get_kallsyms_filename(machine, filename, PATH_MAX);
847
848 for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
849 addr = kallsyms__get_function_start(filename, name);
850 if (addr)
851 break;
852 }
853 if (!addr)
854 return -1;
835 855
836 if (kernel == NULL || 856 if (kernel == NULL ||
837 __machine__create_kernel_maps(machine, kernel) < 0) 857 __machine__create_kernel_maps(machine, kernel) < 0)
@@ -850,6 +870,13 @@ int machine__create_kernel_maps(struct machine *machine)
850 * Now that we have all the maps created, just set the ->end of them: 870 * Now that we have all the maps created, just set the ->end of them:
851 */ 871 */
852 map_groups__fixup_end(&machine->kmaps); 872 map_groups__fixup_end(&machine->kmaps);
873
874 if (maps__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps, name,
875 addr)) {
876 machine__destroy_kernel_maps(machine);
877 return -1;
878 }
879
853 return 0; 880 return 0;
854} 881}
855 882
@@ -1000,7 +1027,7 @@ int machine__process_mmap2_event(struct machine *machine,
1000 } 1027 }
1001 1028
1002 thread = machine__findnew_thread(machine, event->mmap2.pid, 1029 thread = machine__findnew_thread(machine, event->mmap2.pid,
1003 event->mmap2.pid); 1030 event->mmap2.tid);
1004 if (thread == NULL) 1031 if (thread == NULL)
1005 goto out_problem; 1032 goto out_problem;
1006 1033
@@ -1048,7 +1075,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
1048 } 1075 }
1049 1076
1050 thread = machine__findnew_thread(machine, event->mmap.pid, 1077 thread = machine__findnew_thread(machine, event->mmap.pid,
1051 event->mmap.pid); 1078 event->mmap.tid);
1052 if (thread == NULL) 1079 if (thread == NULL)
1053 goto out_problem; 1080 goto out_problem;
1054 1081
@@ -1088,7 +1115,9 @@ static void machine__remove_thread(struct machine *machine, struct thread *th)
1088int machine__process_fork_event(struct machine *machine, union perf_event *event, 1115int machine__process_fork_event(struct machine *machine, union perf_event *event,
1089 struct perf_sample *sample) 1116 struct perf_sample *sample)
1090{ 1117{
1091 struct thread *thread = machine__find_thread(machine, event->fork.tid); 1118 struct thread *thread = machine__find_thread(machine,
1119 event->fork.pid,
1120 event->fork.tid);
1092 struct thread *parent = machine__findnew_thread(machine, 1121 struct thread *parent = machine__findnew_thread(machine,
1093 event->fork.ppid, 1122 event->fork.ppid,
1094 event->fork.ptid); 1123 event->fork.ptid);
@@ -1114,7 +1143,9 @@ int machine__process_fork_event(struct machine *machine, union perf_event *event
1114int machine__process_exit_event(struct machine *machine, union perf_event *event, 1143int machine__process_exit_event(struct machine *machine, union perf_event *event,
1115 struct perf_sample *sample __maybe_unused) 1144 struct perf_sample *sample __maybe_unused)
1116{ 1145{
1117 struct thread *thread = machine__find_thread(machine, event->fork.tid); 1146 struct thread *thread = machine__find_thread(machine,
1147 event->fork.pid,
1148 event->fork.tid);
1118 1149
1119 if (dump_trace) 1150 if (dump_trace)
1120 perf_event__fprintf_task(event, stdout); 1151 perf_event__fprintf_task(event, stdout);
@@ -1158,39 +1189,22 @@ static bool symbol__match_regex(struct symbol *sym, regex_t *regex)
1158 return 0; 1189 return 0;
1159} 1190}
1160 1191
1161static const u8 cpumodes[] = {
1162 PERF_RECORD_MISC_USER,
1163 PERF_RECORD_MISC_KERNEL,
1164 PERF_RECORD_MISC_GUEST_USER,
1165 PERF_RECORD_MISC_GUEST_KERNEL
1166};
1167#define NCPUMODES (sizeof(cpumodes)/sizeof(u8))
1168
1169static void ip__resolve_ams(struct machine *machine, struct thread *thread, 1192static void ip__resolve_ams(struct machine *machine, struct thread *thread,
1170 struct addr_map_symbol *ams, 1193 struct addr_map_symbol *ams,
1171 u64 ip) 1194 u64 ip)
1172{ 1195{
1173 struct addr_location al; 1196 struct addr_location al;
1174 size_t i;
1175 u8 m;
1176 1197
1177 memset(&al, 0, sizeof(al)); 1198 memset(&al, 0, sizeof(al));
1199 /*
1200 * We cannot use the header.misc hint to determine whether a
1201 * branch stack address is user, kernel, guest, hypervisor.
1202 * Branches may straddle the kernel/user/hypervisor boundaries.
1203 * Thus, we have to try consecutively until we find a match
1204 * or else, the symbol is unknown
1205 */
1206 thread__find_cpumode_addr_location(thread, machine, MAP__FUNCTION, ip, &al);
1178 1207
1179 for (i = 0; i < NCPUMODES; i++) {
1180 m = cpumodes[i];
1181 /*
1182 * We cannot use the header.misc hint to determine whether a
1183 * branch stack address is user, kernel, guest, hypervisor.
1184 * Branches may straddle the kernel/user/hypervisor boundaries.
1185 * Thus, we have to try consecutively until we find a match
1186 * or else, the symbol is unknown
1187 */
1188 thread__find_addr_location(thread, machine, m, MAP__FUNCTION,
1189 ip, &al);
1190 if (al.sym)
1191 goto found;
1192 }
1193found:
1194 ams->addr = ip; 1208 ams->addr = ip;
1195 ams->al_addr = al.addr; 1209 ams->al_addr = al.addr;
1196 ams->sym = al.sym; 1210 ams->sym = al.sym;
@@ -1212,37 +1226,35 @@ static void ip__resolve_data(struct machine *machine, struct thread *thread,
1212 ams->map = al.map; 1226 ams->map = al.map;
1213} 1227}
1214 1228
1215struct mem_info *machine__resolve_mem(struct machine *machine, 1229struct mem_info *sample__resolve_mem(struct perf_sample *sample,
1216 struct thread *thr, 1230 struct addr_location *al)
1217 struct perf_sample *sample,
1218 u8 cpumode)
1219{ 1231{
1220 struct mem_info *mi = zalloc(sizeof(*mi)); 1232 struct mem_info *mi = zalloc(sizeof(*mi));
1221 1233
1222 if (!mi) 1234 if (!mi)
1223 return NULL; 1235 return NULL;
1224 1236
1225 ip__resolve_ams(machine, thr, &mi->iaddr, sample->ip); 1237 ip__resolve_ams(al->machine, al->thread, &mi->iaddr, sample->ip);
1226 ip__resolve_data(machine, thr, cpumode, &mi->daddr, sample->addr); 1238 ip__resolve_data(al->machine, al->thread, al->cpumode,
1239 &mi->daddr, sample->addr);
1227 mi->data_src.val = sample->data_src; 1240 mi->data_src.val = sample->data_src;
1228 1241
1229 return mi; 1242 return mi;
1230} 1243}
1231 1244
1232struct branch_info *machine__resolve_bstack(struct machine *machine, 1245struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
1233 struct thread *thr, 1246 struct addr_location *al)
1234 struct branch_stack *bs)
1235{ 1247{
1236 struct branch_info *bi;
1237 unsigned int i; 1248 unsigned int i;
1249 const struct branch_stack *bs = sample->branch_stack;
1250 struct branch_info *bi = calloc(bs->nr, sizeof(struct branch_info));
1238 1251
1239 bi = calloc(bs->nr, sizeof(struct branch_info));
1240 if (!bi) 1252 if (!bi)
1241 return NULL; 1253 return NULL;
1242 1254
1243 for (i = 0; i < bs->nr; i++) { 1255 for (i = 0; i < bs->nr; i++) {
1244 ip__resolve_ams(machine, thr, &bi[i].to, bs->entries[i].to); 1256 ip__resolve_ams(al->machine, al->thread, &bi[i].to, bs->entries[i].to);
1245 ip__resolve_ams(machine, thr, &bi[i].from, bs->entries[i].from); 1257 ip__resolve_ams(al->machine, al->thread, &bi[i].from, bs->entries[i].from);
1246 bi[i].flags = bs->entries[i].flags; 1258 bi[i].flags = bs->entries[i].flags;
1247 } 1259 }
1248 return bi; 1260 return bi;
@@ -1300,7 +1312,7 @@ static int machine__resolve_callchain_sample(struct machine *machine,
1300 continue; 1312 continue;
1301 } 1313 }
1302 1314
1303 al.filtered = false; 1315 al.filtered = 0;
1304 thread__find_addr_location(thread, machine, cpumode, 1316 thread__find_addr_location(thread, machine, cpumode,
1305 MAP__FUNCTION, ip, &al); 1317 MAP__FUNCTION, ip, &al);
1306 if (al.sym != NULL) { 1318 if (al.sym != NULL) {
@@ -1359,8 +1371,7 @@ int machine__resolve_callchain(struct machine *machine,
1359 return 0; 1371 return 0;
1360 1372
1361 return unwind__get_entries(unwind_entry, &callchain_cursor, machine, 1373 return unwind__get_entries(unwind_entry, &callchain_cursor, machine,
1362 thread, evsel->attr.sample_regs_user, 1374 thread, sample, max_stack);
1363 sample, max_stack);
1364 1375
1365} 1376}
1366 1377
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 477133015440..c8c74a119398 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -18,6 +18,8 @@ union perf_event;
18#define HOST_KERNEL_ID (-1) 18#define HOST_KERNEL_ID (-1)
19#define DEFAULT_GUEST_KERNEL_ID (0) 19#define DEFAULT_GUEST_KERNEL_ID (0)
20 20
21extern const char *ref_reloc_sym_names[];
22
21struct machine { 23struct machine {
22 struct rb_node rb_node; 24 struct rb_node rb_node;
23 pid_t pid; 25 pid_t pid;
@@ -39,7 +41,8 @@ struct map *machine__kernel_map(struct machine *machine, enum map_type type)
39 return machine->vmlinux_maps[type]; 41 return machine->vmlinux_maps[type];
40} 42}
41 43
42struct thread *machine__find_thread(struct machine *machine, pid_t tid); 44struct thread *machine__find_thread(struct machine *machine, pid_t pid,
45 pid_t tid);
43 46
44int machine__process_comm_event(struct machine *machine, union perf_event *event, 47int machine__process_comm_event(struct machine *machine, union perf_event *event,
45 struct perf_sample *sample); 48 struct perf_sample *sample);
@@ -89,12 +92,10 @@ void machine__delete_dead_threads(struct machine *machine);
89void machine__delete_threads(struct machine *machine); 92void machine__delete_threads(struct machine *machine);
90void machine__delete(struct machine *machine); 93void machine__delete(struct machine *machine);
91 94
92struct branch_info *machine__resolve_bstack(struct machine *machine, 95struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
93 struct thread *thread, 96 struct addr_location *al);
94 struct branch_stack *bs); 97struct mem_info *sample__resolve_mem(struct perf_sample *sample,
95struct mem_info *machine__resolve_mem(struct machine *machine, 98 struct addr_location *al);
96 struct thread *thread,
97 struct perf_sample *sample, u8 cpumode);
98int machine__resolve_callchain(struct machine *machine, 99int machine__resolve_callchain(struct machine *machine,
99 struct perf_evsel *evsel, 100 struct perf_evsel *evsel,
100 struct thread *thread, 101 struct thread *thread,
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 3b97513f0e77..39cd2d0faff6 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -39,6 +39,7 @@ void map__init(struct map *map, enum map_type type,
39 map->start = start; 39 map->start = start;
40 map->end = end; 40 map->end = end;
41 map->pgoff = pgoff; 41 map->pgoff = pgoff;
42 map->reloc = 0;
42 map->dso = dso; 43 map->dso = dso;
43 map->map_ip = map__map_ip; 44 map->map_ip = map__map_ip;
44 map->unmap_ip = map__unmap_ip; 45 map->unmap_ip = map__unmap_ip;
@@ -288,7 +289,7 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
288 if (map->dso->rel) 289 if (map->dso->rel)
289 return rip - map->pgoff; 290 return rip - map->pgoff;
290 291
291 return map->unmap_ip(map, rip); 292 return map->unmap_ip(map, rip) - map->reloc;
292} 293}
293 294
294/** 295/**
@@ -311,7 +312,7 @@ u64 map__objdump_2mem(struct map *map, u64 ip)
311 if (map->dso->rel) 312 if (map->dso->rel)
312 return map->unmap_ip(map, ip + map->pgoff); 313 return map->unmap_ip(map, ip + map->pgoff);
313 314
314 return ip; 315 return ip + map->reloc;
315} 316}
316 317
317void map_groups__init(struct map_groups *mg) 318void map_groups__init(struct map_groups *mg)
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 18068c6b71c1..f00f058afb3b 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -36,6 +36,7 @@ struct map {
36 bool erange_warned; 36 bool erange_warned;
37 u32 priv; 37 u32 priv;
38 u64 pgoff; 38 u64 pgoff;
39 u64 reloc;
39 u32 maj, min; /* only valid for MMAP2 record */ 40 u32 maj, min; /* only valid for MMAP2 record */
40 u64 ino; /* only valid for MMAP2 record */ 41 u64 ino; /* only valid for MMAP2 record */
41 u64 ino_generation;/* only valid for MMAP2 record */ 42 u64 ino_generation;/* only valid for MMAP2 record */
@@ -89,6 +90,16 @@ u64 map__objdump_2mem(struct map *map, u64 ip);
89 90
90struct symbol; 91struct symbol;
91 92
93/* map__for_each_symbol - iterate over the symbols in the given map
94 *
95 * @map: the 'struct map *' in which symbols itereated
96 * @pos: the 'struct symbol *' to use as a loop cursor
97 * @n: the 'struct rb_node *' to use as a temporary storage
98 * Note: caller must ensure map->dso is not NULL (map is loaded).
99 */
100#define map__for_each_symbol(map, pos, n) \
101 dso__for_each_symbol(map->dso, pos, n, map->type)
102
92typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); 103typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
93 104
94void map__init(struct map *map, enum map_type type, 105void map__init(struct map *map, enum map_type type,
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index d248fca6d7ed..1e15df10a88c 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1091,12 +1091,12 @@ int is_valid_tracepoint(const char *event_string)
1091static bool is_event_supported(u8 type, unsigned config) 1091static bool is_event_supported(u8 type, unsigned config)
1092{ 1092{
1093 bool ret = true; 1093 bool ret = true;
1094 int open_return;
1094 struct perf_evsel *evsel; 1095 struct perf_evsel *evsel;
1095 struct perf_event_attr attr = { 1096 struct perf_event_attr attr = {
1096 .type = type, 1097 .type = type,
1097 .config = config, 1098 .config = config,
1098 .disabled = 1, 1099 .disabled = 1,
1099 .exclude_kernel = 1,
1100 }; 1100 };
1101 struct { 1101 struct {
1102 struct thread_map map; 1102 struct thread_map map;
@@ -1108,7 +1108,20 @@ static bool is_event_supported(u8 type, unsigned config)
1108 1108
1109 evsel = perf_evsel__new(&attr); 1109 evsel = perf_evsel__new(&attr);
1110 if (evsel) { 1110 if (evsel) {
1111 ret = perf_evsel__open(evsel, NULL, &tmap.map) >= 0; 1111 open_return = perf_evsel__open(evsel, NULL, &tmap.map);
1112 ret = open_return >= 0;
1113
1114 if (open_return == -EACCES) {
1115 /*
1116 * This happens if the paranoid value
1117 * /proc/sys/kernel/perf_event_paranoid is set to 2
1118 * Re-run with exclude_kernel set; we don't do that
1119 * by default as some ARM machines do not support it.
1120 *
1121 */
1122 evsel->attr.exclude_kernel = 1;
1123 ret = perf_evsel__open(evsel, NULL, &tmap.map) >= 0;
1124 }
1112 perf_evsel__delete(evsel); 1125 perf_evsel__delete(evsel);
1113 } 1126 }
1114 1127
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index d22e3f8017dc..bf48092983c6 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -407,7 +407,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
407 if (internal_help && !strcmp(arg + 2, "help")) 407 if (internal_help && !strcmp(arg + 2, "help"))
408 return usage_with_options_internal(usagestr, options, 0); 408 return usage_with_options_internal(usagestr, options, 0);
409 if (!strcmp(arg + 2, "list-opts")) 409 if (!strcmp(arg + 2, "list-opts"))
410 return PARSE_OPT_LIST; 410 return PARSE_OPT_LIST_OPTS;
411 if (!strcmp(arg + 2, "list-cmds"))
412 return PARSE_OPT_LIST_SUBCMDS;
411 switch (parse_long_opt(ctx, arg + 2, options)) { 413 switch (parse_long_opt(ctx, arg + 2, options)) {
412 case -1: 414 case -1:
413 return parse_options_usage(usagestr, options, arg + 2, 0); 415 return parse_options_usage(usagestr, options, arg + 2, 0);
@@ -433,25 +435,45 @@ int parse_options_end(struct parse_opt_ctx_t *ctx)
433 return ctx->cpidx + ctx->argc; 435 return ctx->cpidx + ctx->argc;
434} 436}
435 437
436int parse_options(int argc, const char **argv, const struct option *options, 438int parse_options_subcommand(int argc, const char **argv, const struct option *options,
437 const char * const usagestr[], int flags) 439 const char *const subcommands[], const char *usagestr[], int flags)
438{ 440{
439 struct parse_opt_ctx_t ctx; 441 struct parse_opt_ctx_t ctx;
440 442
441 perf_header__set_cmdline(argc, argv); 443 perf_header__set_cmdline(argc, argv);
442 444
445 /* build usage string if it's not provided */
446 if (subcommands && !usagestr[0]) {
447 struct strbuf buf = STRBUF_INIT;
448
449 strbuf_addf(&buf, "perf %s [<options>] {", argv[0]);
450 for (int i = 0; subcommands[i]; i++) {
451 if (i)
452 strbuf_addstr(&buf, "|");
453 strbuf_addstr(&buf, subcommands[i]);
454 }
455 strbuf_addstr(&buf, "}");
456
457 usagestr[0] = strdup(buf.buf);
458 strbuf_release(&buf);
459 }
460
443 parse_options_start(&ctx, argc, argv, flags); 461 parse_options_start(&ctx, argc, argv, flags);
444 switch (parse_options_step(&ctx, options, usagestr)) { 462 switch (parse_options_step(&ctx, options, usagestr)) {
445 case PARSE_OPT_HELP: 463 case PARSE_OPT_HELP:
446 exit(129); 464 exit(129);
447 case PARSE_OPT_DONE: 465 case PARSE_OPT_DONE:
448 break; 466 break;
449 case PARSE_OPT_LIST: 467 case PARSE_OPT_LIST_OPTS:
450 while (options->type != OPTION_END) { 468 while (options->type != OPTION_END) {
451 printf("--%s ", options->long_name); 469 printf("--%s ", options->long_name);
452 options++; 470 options++;
453 } 471 }
454 exit(130); 472 exit(130);
473 case PARSE_OPT_LIST_SUBCMDS:
474 for (int i = 0; subcommands[i]; i++)
475 printf("%s ", subcommands[i]);
476 exit(130);
455 default: /* PARSE_OPT_UNKNOWN */ 477 default: /* PARSE_OPT_UNKNOWN */
456 if (ctx.argv[0][1] == '-') { 478 if (ctx.argv[0][1] == '-') {
457 error("unknown option `%s'", ctx.argv[0] + 2); 479 error("unknown option `%s'", ctx.argv[0] + 2);
@@ -464,6 +486,13 @@ int parse_options(int argc, const char **argv, const struct option *options,
464 return parse_options_end(&ctx); 486 return parse_options_end(&ctx);
465} 487}
466 488
489int parse_options(int argc, const char **argv, const struct option *options,
490 const char * const usagestr[], int flags)
491{
492 return parse_options_subcommand(argc, argv, options, NULL,
493 (const char **) usagestr, flags);
494}
495
467#define USAGE_OPTS_WIDTH 24 496#define USAGE_OPTS_WIDTH 24
468#define USAGE_GAP 2 497#define USAGE_GAP 2
469 498
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index cbf0149cf221..d8dac8ac5f37 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -140,6 +140,11 @@ extern int parse_options(int argc, const char **argv,
140 const struct option *options, 140 const struct option *options,
141 const char * const usagestr[], int flags); 141 const char * const usagestr[], int flags);
142 142
143extern int parse_options_subcommand(int argc, const char **argv,
144 const struct option *options,
145 const char *const subcommands[],
146 const char *usagestr[], int flags);
147
143extern NORETURN void usage_with_options(const char * const *usagestr, 148extern NORETURN void usage_with_options(const char * const *usagestr,
144 const struct option *options); 149 const struct option *options);
145 150
@@ -148,7 +153,8 @@ extern NORETURN void usage_with_options(const char * const *usagestr,
148enum { 153enum {
149 PARSE_OPT_HELP = -1, 154 PARSE_OPT_HELP = -1,
150 PARSE_OPT_DONE, 155 PARSE_OPT_DONE,
151 PARSE_OPT_LIST, 156 PARSE_OPT_LIST_OPTS,
157 PARSE_OPT_LIST_SUBCMDS,
152 PARSE_OPT_UNKNOWN, 158 PARSE_OPT_UNKNOWN,
153}; 159};
154 160
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
new file mode 100644
index 000000000000..a3539ef30b15
--- /dev/null
+++ b/tools/perf/util/perf_regs.c
@@ -0,0 +1,19 @@
1#include <errno.h>
2#include "perf_regs.h"
3
4int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
5{
6 int i, idx = 0;
7 u64 mask = regs->mask;
8
9 if (!(mask & (1 << id)))
10 return -EINVAL;
11
12 for (i = 0; i < id; i++) {
13 if (mask & (1 << i))
14 idx++;
15 }
16
17 *valp = regs->regs[idx];
18 return 0;
19}
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index a3d42cd74919..d6e8b6a8d7f3 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -1,8 +1,14 @@
1#ifndef __PERF_REGS_H 1#ifndef __PERF_REGS_H
2#define __PERF_REGS_H 2#define __PERF_REGS_H
3 3
4#include "types.h"
5#include "event.h"
6
4#ifdef HAVE_PERF_REGS_SUPPORT 7#ifdef HAVE_PERF_REGS_SUPPORT
5#include <perf_regs.h> 8#include <perf_regs.h>
9
10int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
11
6#else 12#else
7#define PERF_REGS_MASK 0 13#define PERF_REGS_MASK 0
8 14
@@ -10,5 +16,12 @@ static inline const char *perf_reg_name(int id __maybe_unused)
10{ 16{
11 return NULL; 17 return NULL;
12} 18}
19
20static inline int perf_reg_value(u64 *valp __maybe_unused,
21 struct regs_dump *regs __maybe_unused,
22 int id __maybe_unused)
23{
24 return 0;
25}
13#endif /* HAVE_PERF_REGS_SUPPORT */ 26#endif /* HAVE_PERF_REGS_SUPPORT */
14#endif /* __PERF_REGS_H */ 27#endif /* __PERF_REGS_H */
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index b752ecb40d86..00a7dcb2f55c 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -3,7 +3,7 @@
3#include <unistd.h> 3#include <unistd.h>
4#include <stdio.h> 4#include <stdio.h>
5#include <dirent.h> 5#include <dirent.h>
6#include "fs.h" 6#include <api/fs/fs.h>
7#include <locale.h> 7#include <locale.h>
8#include "util.h" 8#include "util.h"
9#include "pmu.h" 9#include "pmu.h"
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index a8a9b6cd93a8..0d1542f33d87 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -70,34 +70,32 @@ static int e_snprintf(char *str, size_t size, const char *format, ...)
70} 70}
71 71
72static char *synthesize_perf_probe_point(struct perf_probe_point *pp); 72static char *synthesize_perf_probe_point(struct perf_probe_point *pp);
73static int convert_name_to_addr(struct perf_probe_event *pev,
74 const char *exec);
75static void clear_probe_trace_event(struct probe_trace_event *tev); 73static void clear_probe_trace_event(struct probe_trace_event *tev);
76static struct machine machine; 74static struct machine *host_machine;
77 75
78/* Initialize symbol maps and path of vmlinux/modules */ 76/* Initialize symbol maps and path of vmlinux/modules */
79static int init_vmlinux(void) 77static int init_symbol_maps(bool user_only)
80{ 78{
81 int ret; 79 int ret;
82 80
83 symbol_conf.sort_by_name = true; 81 symbol_conf.sort_by_name = true;
84 if (symbol_conf.vmlinux_name == NULL)
85 symbol_conf.try_vmlinux_path = true;
86 else
87 pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name);
88 ret = symbol__init(); 82 ret = symbol__init();
89 if (ret < 0) { 83 if (ret < 0) {
90 pr_debug("Failed to init symbol map.\n"); 84 pr_debug("Failed to init symbol map.\n");
91 goto out; 85 goto out;
92 } 86 }
93 87
94 ret = machine__init(&machine, "", HOST_KERNEL_ID); 88 if (host_machine || user_only) /* already initialized */
95 if (ret < 0) 89 return 0;
96 goto out;
97 90
98 if (machine__create_kernel_maps(&machine) < 0) { 91 if (symbol_conf.vmlinux_name)
99 pr_debug("machine__create_kernel_maps() failed.\n"); 92 pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name);
100 goto out; 93
94 host_machine = machine__new_host();
95 if (!host_machine) {
96 pr_debug("machine__new_host() failed.\n");
97 symbol__exit();
98 ret = -1;
101 } 99 }
102out: 100out:
103 if (ret < 0) 101 if (ret < 0)
@@ -105,21 +103,66 @@ out:
105 return ret; 103 return ret;
106} 104}
107 105
106static void exit_symbol_maps(void)
107{
108 if (host_machine) {
109 machine__delete(host_machine);
110 host_machine = NULL;
111 }
112 symbol__exit();
113}
114
108static struct symbol *__find_kernel_function_by_name(const char *name, 115static struct symbol *__find_kernel_function_by_name(const char *name,
109 struct map **mapp) 116 struct map **mapp)
110{ 117{
111 return machine__find_kernel_function_by_name(&machine, name, mapp, 118 return machine__find_kernel_function_by_name(host_machine, name, mapp,
112 NULL); 119 NULL);
113} 120}
114 121
122static struct symbol *__find_kernel_function(u64 addr, struct map **mapp)
123{
124 return machine__find_kernel_function(host_machine, addr, mapp, NULL);
125}
126
127static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void)
128{
129 /* kmap->ref_reloc_sym should be set if host_machine is initialized */
130 struct kmap *kmap;
131
132 if (map__load(host_machine->vmlinux_maps[MAP__FUNCTION], NULL) < 0)
133 return NULL;
134
135 kmap = map__kmap(host_machine->vmlinux_maps[MAP__FUNCTION]);
136 return kmap->ref_reloc_sym;
137}
138
139static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc)
140{
141 struct ref_reloc_sym *reloc_sym;
142 struct symbol *sym;
143 struct map *map;
144
145 /* ref_reloc_sym is just a label. Need a special fix*/
146 reloc_sym = kernel_get_ref_reloc_sym();
147 if (reloc_sym && strcmp(name, reloc_sym->name) == 0)
148 return (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr;
149 else {
150 sym = __find_kernel_function_by_name(name, &map);
151 if (sym)
152 return map->unmap_ip(map, sym->start) -
153 (reloc) ? 0 : map->reloc;
154 }
155 return 0;
156}
157
115static struct map *kernel_get_module_map(const char *module) 158static struct map *kernel_get_module_map(const char *module)
116{ 159{
117 struct rb_node *nd; 160 struct rb_node *nd;
118 struct map_groups *grp = &machine.kmaps; 161 struct map_groups *grp = &host_machine->kmaps;
119 162
120 /* A file path -- this is an offline module */ 163 /* A file path -- this is an offline module */
121 if (module && strchr(module, '/')) 164 if (module && strchr(module, '/'))
122 return machine__new_module(&machine, 0, module); 165 return machine__new_module(host_machine, 0, module);
123 166
124 if (!module) 167 if (!module)
125 module = "kernel"; 168 module = "kernel";
@@ -141,7 +184,7 @@ static struct dso *kernel_get_module_dso(const char *module)
141 const char *vmlinux_name; 184 const char *vmlinux_name;
142 185
143 if (module) { 186 if (module) {
144 list_for_each_entry(dso, &machine.kernel_dsos, node) { 187 list_for_each_entry(dso, &host_machine->kernel_dsos, node) {
145 if (strncmp(dso->short_name + 1, module, 188 if (strncmp(dso->short_name + 1, module,
146 dso->short_name_len - 2) == 0) 189 dso->short_name_len - 2) == 0)
147 goto found; 190 goto found;
@@ -150,7 +193,7 @@ static struct dso *kernel_get_module_dso(const char *module)
150 return NULL; 193 return NULL;
151 } 194 }
152 195
153 map = machine.vmlinux_maps[MAP__FUNCTION]; 196 map = host_machine->vmlinux_maps[MAP__FUNCTION];
154 dso = map->dso; 197 dso = map->dso;
155 198
156 vmlinux_name = symbol_conf.vmlinux_name; 199 vmlinux_name = symbol_conf.vmlinux_name;
@@ -173,20 +216,6 @@ const char *kernel_get_module_path(const char *module)
173 return (dso) ? dso->long_name : NULL; 216 return (dso) ? dso->long_name : NULL;
174} 217}
175 218
176static int init_user_exec(void)
177{
178 int ret = 0;
179
180 symbol_conf.try_vmlinux_path = false;
181 symbol_conf.sort_by_name = true;
182 ret = symbol__init();
183
184 if (ret < 0)
185 pr_debug("Failed to init symbol map.\n");
186
187 return ret;
188}
189
190static int convert_exec_to_group(const char *exec, char **result) 219static int convert_exec_to_group(const char *exec, char **result)
191{ 220{
192 char *ptr1, *ptr2, *exec_copy; 221 char *ptr1, *ptr2, *exec_copy;
@@ -218,32 +247,23 @@ out:
218 return ret; 247 return ret;
219} 248}
220 249
221static int convert_to_perf_probe_point(struct probe_trace_point *tp, 250static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs)
222 struct perf_probe_point *pp)
223{ 251{
224 pp->function = strdup(tp->symbol); 252 int i;
225
226 if (pp->function == NULL)
227 return -ENOMEM;
228
229 pp->offset = tp->offset;
230 pp->retprobe = tp->retprobe;
231 253
232 return 0; 254 for (i = 0; i < ntevs; i++)
255 clear_probe_trace_event(tevs + i);
233} 256}
234 257
235#ifdef HAVE_DWARF_SUPPORT 258#ifdef HAVE_DWARF_SUPPORT
259
236/* Open new debuginfo of given module */ 260/* Open new debuginfo of given module */
237static struct debuginfo *open_debuginfo(const char *module) 261static struct debuginfo *open_debuginfo(const char *module)
238{ 262{
239 const char *path; 263 const char *path = module;
240 264
241 /* A file path -- this is an offline module */ 265 if (!module || !strchr(module, '/')) {
242 if (module && strchr(module, '/'))
243 path = module;
244 else {
245 path = kernel_get_module_path(module); 266 path = kernel_get_module_path(module);
246
247 if (!path) { 267 if (!path) {
248 pr_err("Failed to find path of %s module.\n", 268 pr_err("Failed to find path of %s module.\n",
249 module ?: "kernel"); 269 module ?: "kernel");
@@ -253,46 +273,6 @@ static struct debuginfo *open_debuginfo(const char *module)
253 return debuginfo__new(path); 273 return debuginfo__new(path);
254} 274}
255 275
256/*
257 * Convert trace point to probe point with debuginfo
258 * Currently only handles kprobes.
259 */
260static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
261 struct perf_probe_point *pp)
262{
263 struct symbol *sym;
264 struct map *map;
265 u64 addr;
266 int ret = -ENOENT;
267 struct debuginfo *dinfo;
268
269 sym = __find_kernel_function_by_name(tp->symbol, &map);
270 if (sym) {
271 addr = map->unmap_ip(map, sym->start + tp->offset);
272 pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol,
273 tp->offset, addr);
274
275 dinfo = debuginfo__new_online_kernel(addr);
276 if (dinfo) {
277 ret = debuginfo__find_probe_point(dinfo,
278 (unsigned long)addr, pp);
279 debuginfo__delete(dinfo);
280 } else {
281 pr_debug("Failed to open debuginfo at 0x%" PRIx64 "\n",
282 addr);
283 ret = -ENOENT;
284 }
285 }
286 if (ret <= 0) {
287 pr_debug("Failed to find corresponding probes from "
288 "debuginfo. Use kprobe event information.\n");
289 return convert_to_perf_probe_point(tp, pp);
290 }
291 pp->retprobe = tp->retprobe;
292
293 return 0;
294}
295
296static int get_text_start_address(const char *exec, unsigned long *address) 276static int get_text_start_address(const char *exec, unsigned long *address)
297{ 277{
298 Elf *elf; 278 Elf *elf;
@@ -321,12 +301,62 @@ out:
321 return ret; 301 return ret;
322} 302}
323 303
304/*
305 * Convert trace point to probe point with debuginfo
306 */
307static int find_perf_probe_point_from_dwarf(struct probe_trace_point *tp,
308 struct perf_probe_point *pp,
309 bool is_kprobe)
310{
311 struct debuginfo *dinfo = NULL;
312 unsigned long stext = 0;
313 u64 addr = tp->address;
314 int ret = -ENOENT;
315
316 /* convert the address to dwarf address */
317 if (!is_kprobe) {
318 if (!addr) {
319 ret = -EINVAL;
320 goto error;
321 }
322 ret = get_text_start_address(tp->module, &stext);
323 if (ret < 0)
324 goto error;
325 addr += stext;
326 } else {
327 addr = kernel_get_symbol_address_by_name(tp->symbol, false);
328 if (addr == 0)
329 goto error;
330 addr += tp->offset;
331 }
332
333 pr_debug("try to find information at %" PRIx64 " in %s\n", addr,
334 tp->module ? : "kernel");
335
336 dinfo = open_debuginfo(tp->module);
337 if (dinfo) {
338 ret = debuginfo__find_probe_point(dinfo,
339 (unsigned long)addr, pp);
340 debuginfo__delete(dinfo);
341 } else {
342 pr_debug("Failed to open debuginfo at 0x%" PRIx64 "\n", addr);
343 ret = -ENOENT;
344 }
345
346 if (ret > 0) {
347 pp->retprobe = tp->retprobe;
348 return 0;
349 }
350error:
351 pr_debug("Failed to find corresponding probes from debuginfo.\n");
352 return ret ? : -ENOENT;
353}
354
324static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs, 355static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
325 int ntevs, const char *exec) 356 int ntevs, const char *exec)
326{ 357{
327 int i, ret = 0; 358 int i, ret = 0;
328 unsigned long offset, stext = 0; 359 unsigned long stext = 0;
329 char buf[32];
330 360
331 if (!exec) 361 if (!exec)
332 return 0; 362 return 0;
@@ -336,16 +366,10 @@ static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
336 return ret; 366 return ret;
337 367
338 for (i = 0; i < ntevs && ret >= 0; i++) { 368 for (i = 0; i < ntevs && ret >= 0; i++) {
339 offset = tevs[i].point.address - stext; 369 /* point.address is the addres of point.symbol + point.offset */
340 offset += tevs[i].point.offset; 370 tevs[i].point.address -= stext;
341 tevs[i].point.offset = 0;
342 zfree(&tevs[i].point.symbol);
343 ret = e_snprintf(buf, 32, "0x%lx", offset);
344 if (ret < 0)
345 break;
346 tevs[i].point.module = strdup(exec); 371 tevs[i].point.module = strdup(exec);
347 tevs[i].point.symbol = strdup(buf); 372 if (!tevs[i].point.module) {
348 if (!tevs[i].point.symbol || !tevs[i].point.module) {
349 ret = -ENOMEM; 373 ret = -ENOMEM;
350 break; 374 break;
351 } 375 }
@@ -388,12 +412,40 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
388 return ret; 412 return ret;
389} 413}
390 414
391static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs) 415/* Post processing the probe events */
416static int post_process_probe_trace_events(struct probe_trace_event *tevs,
417 int ntevs, const char *module,
418 bool uprobe)
392{ 419{
420 struct ref_reloc_sym *reloc_sym;
421 char *tmp;
393 int i; 422 int i;
394 423
395 for (i = 0; i < ntevs; i++) 424 if (uprobe)
396 clear_probe_trace_event(tevs + i); 425 return add_exec_to_probe_trace_events(tevs, ntevs, module);
426
427 /* Note that currently ref_reloc_sym based probe is not for drivers */
428 if (module)
429 return add_module_to_probe_trace_events(tevs, ntevs, module);
430
431 reloc_sym = kernel_get_ref_reloc_sym();
432 if (!reloc_sym) {
433 pr_warning("Relocated base symbol is not found!\n");
434 return -EINVAL;
435 }
436
437 for (i = 0; i < ntevs; i++) {
438 if (tevs[i].point.address) {
439 tmp = strdup(reloc_sym->name);
440 if (!tmp)
441 return -ENOMEM;
442 free(tevs[i].point.symbol);
443 tevs[i].point.symbol = tmp;
444 tevs[i].point.offset = tevs[i].point.address -
445 reloc_sym->unrelocated_addr;
446 }
447 }
448 return 0;
397} 449}
398 450
399/* Try to find perf_probe_event with debuginfo */ 451/* Try to find perf_probe_event with debuginfo */
@@ -416,21 +468,16 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
416 return 0; 468 return 0;
417 } 469 }
418 470
471 pr_debug("Try to find probe point from debuginfo.\n");
419 /* Searching trace events corresponding to a probe event */ 472 /* Searching trace events corresponding to a probe event */
420 ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs); 473 ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs);
421 474
422 debuginfo__delete(dinfo); 475 debuginfo__delete(dinfo);
423 476
424 if (ntevs > 0) { /* Succeeded to find trace events */ 477 if (ntevs > 0) { /* Succeeded to find trace events */
425 pr_debug("find %d probe_trace_events.\n", ntevs); 478 pr_debug("Found %d probe_trace_events.\n", ntevs);
426 if (target) { 479 ret = post_process_probe_trace_events(*tevs, ntevs,
427 if (pev->uprobes) 480 target, pev->uprobes);
428 ret = add_exec_to_probe_trace_events(*tevs,
429 ntevs, target);
430 else
431 ret = add_module_to_probe_trace_events(*tevs,
432 ntevs, target);
433 }
434 if (ret < 0) { 481 if (ret < 0) {
435 clear_probe_trace_events(*tevs, ntevs); 482 clear_probe_trace_events(*tevs, ntevs);
436 zfree(tevs); 483 zfree(tevs);
@@ -563,20 +610,16 @@ static int _show_one_line(FILE *fp, int l, bool skip, bool show_num)
563 * Show line-range always requires debuginfo to find source file and 610 * Show line-range always requires debuginfo to find source file and
564 * line number. 611 * line number.
565 */ 612 */
566int show_line_range(struct line_range *lr, const char *module) 613static int __show_line_range(struct line_range *lr, const char *module)
567{ 614{
568 int l = 1; 615 int l = 1;
569 struct line_node *ln; 616 struct int_node *ln;
570 struct debuginfo *dinfo; 617 struct debuginfo *dinfo;
571 FILE *fp; 618 FILE *fp;
572 int ret; 619 int ret;
573 char *tmp; 620 char *tmp;
574 621
575 /* Search a line range */ 622 /* Search a line range */
576 ret = init_vmlinux();
577 if (ret < 0)
578 return ret;
579
580 dinfo = open_debuginfo(module); 623 dinfo = open_debuginfo(module);
581 if (!dinfo) { 624 if (!dinfo) {
582 pr_warning("Failed to open debuginfo file.\n"); 625 pr_warning("Failed to open debuginfo file.\n");
@@ -623,8 +666,8 @@ int show_line_range(struct line_range *lr, const char *module)
623 goto end; 666 goto end;
624 } 667 }
625 668
626 list_for_each_entry(ln, &lr->line_list, list) { 669 intlist__for_each(ln, lr->line_list) {
627 for (; ln->line > l; l++) { 670 for (; ln->i > l; l++) {
628 ret = show_one_line(fp, l - lr->offset); 671 ret = show_one_line(fp, l - lr->offset);
629 if (ret < 0) 672 if (ret < 0)
630 goto end; 673 goto end;
@@ -646,6 +689,19 @@ end:
646 return ret; 689 return ret;
647} 690}
648 691
692int show_line_range(struct line_range *lr, const char *module)
693{
694 int ret;
695
696 ret = init_symbol_maps(false);
697 if (ret < 0)
698 return ret;
699 ret = __show_line_range(lr, module);
700 exit_symbol_maps();
701
702 return ret;
703}
704
649static int show_available_vars_at(struct debuginfo *dinfo, 705static int show_available_vars_at(struct debuginfo *dinfo,
650 struct perf_probe_event *pev, 706 struct perf_probe_event *pev,
651 int max_vls, struct strfilter *_filter, 707 int max_vls, struct strfilter *_filter,
@@ -707,14 +763,15 @@ int show_available_vars(struct perf_probe_event *pevs, int npevs,
707 int i, ret = 0; 763 int i, ret = 0;
708 struct debuginfo *dinfo; 764 struct debuginfo *dinfo;
709 765
710 ret = init_vmlinux(); 766 ret = init_symbol_maps(false);
711 if (ret < 0) 767 if (ret < 0)
712 return ret; 768 return ret;
713 769
714 dinfo = open_debuginfo(module); 770 dinfo = open_debuginfo(module);
715 if (!dinfo) { 771 if (!dinfo) {
716 pr_warning("Failed to open debuginfo file.\n"); 772 pr_warning("Failed to open debuginfo file.\n");
717 return -ENOENT; 773 ret = -ENOENT;
774 goto out;
718 } 775 }
719 776
720 setup_pager(); 777 setup_pager();
@@ -724,23 +781,19 @@ int show_available_vars(struct perf_probe_event *pevs, int npevs,
724 externs); 781 externs);
725 782
726 debuginfo__delete(dinfo); 783 debuginfo__delete(dinfo);
784out:
785 exit_symbol_maps();
727 return ret; 786 return ret;
728} 787}
729 788
730#else /* !HAVE_DWARF_SUPPORT */ 789#else /* !HAVE_DWARF_SUPPORT */
731 790
732static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, 791static int
733 struct perf_probe_point *pp) 792find_perf_probe_point_from_dwarf(struct probe_trace_point *tp __maybe_unused,
793 struct perf_probe_point *pp __maybe_unused,
794 bool is_kprobe __maybe_unused)
734{ 795{
735 struct symbol *sym; 796 return -ENOSYS;
736
737 sym = __find_kernel_function_by_name(tp->symbol, NULL);
738 if (!sym) {
739 pr_err("Failed to find symbol %s in kernel.\n", tp->symbol);
740 return -ENOENT;
741 }
742
743 return convert_to_perf_probe_point(tp, pp);
744} 797}
745 798
746static int try_to_find_probe_trace_events(struct perf_probe_event *pev, 799static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
@@ -776,24 +829,22 @@ int show_available_vars(struct perf_probe_event *pevs __maybe_unused,
776 829
777void line_range__clear(struct line_range *lr) 830void line_range__clear(struct line_range *lr)
778{ 831{
779 struct line_node *ln;
780
781 free(lr->function); 832 free(lr->function);
782 free(lr->file); 833 free(lr->file);
783 free(lr->path); 834 free(lr->path);
784 free(lr->comp_dir); 835 free(lr->comp_dir);
785 while (!list_empty(&lr->line_list)) { 836 intlist__delete(lr->line_list);
786 ln = list_first_entry(&lr->line_list, struct line_node, list);
787 list_del(&ln->list);
788 free(ln);
789 }
790 memset(lr, 0, sizeof(*lr)); 837 memset(lr, 0, sizeof(*lr));
791} 838}
792 839
793void line_range__init(struct line_range *lr) 840int line_range__init(struct line_range *lr)
794{ 841{
795 memset(lr, 0, sizeof(*lr)); 842 memset(lr, 0, sizeof(*lr));
796 INIT_LIST_HEAD(&lr->line_list); 843 lr->line_list = intlist__new(NULL);
844 if (!lr->line_list)
845 return -ENOMEM;
846 else
847 return 0;
797} 848}
798 849
799static int parse_line_num(char **ptr, int *val, const char *what) 850static int parse_line_num(char **ptr, int *val, const char *what)
@@ -1267,16 +1318,21 @@ static int parse_probe_trace_command(const char *cmd,
1267 } else 1318 } else
1268 p = argv[1]; 1319 p = argv[1];
1269 fmt1_str = strtok_r(p, "+", &fmt); 1320 fmt1_str = strtok_r(p, "+", &fmt);
1270 tp->symbol = strdup(fmt1_str); 1321 if (fmt1_str[0] == '0') /* only the address started with 0x */
1271 if (tp->symbol == NULL) { 1322 tp->address = strtoul(fmt1_str, NULL, 0);
1272 ret = -ENOMEM; 1323 else {
1273 goto out; 1324 /* Only the symbol-based probe has offset */
1325 tp->symbol = strdup(fmt1_str);
1326 if (tp->symbol == NULL) {
1327 ret = -ENOMEM;
1328 goto out;
1329 }
1330 fmt2_str = strtok_r(NULL, "", &fmt);
1331 if (fmt2_str == NULL)
1332 tp->offset = 0;
1333 else
1334 tp->offset = strtoul(fmt2_str, NULL, 10);
1274 } 1335 }
1275 fmt2_str = strtok_r(NULL, "", &fmt);
1276 if (fmt2_str == NULL)
1277 tp->offset = 0;
1278 else
1279 tp->offset = strtoul(fmt2_str, NULL, 10);
1280 1336
1281 tev->nargs = argc - 2; 1337 tev->nargs = argc - 2;
1282 tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); 1338 tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
@@ -1518,20 +1574,27 @@ char *synthesize_probe_trace_command(struct probe_trace_event *tev)
1518 if (buf == NULL) 1574 if (buf == NULL)
1519 return NULL; 1575 return NULL;
1520 1576
1577 len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
1578 tev->group, tev->event);
1579 if (len <= 0)
1580 goto error;
1581
1582 /* Uprobes must have tp->address and tp->module */
1583 if (tev->uprobes && (!tp->address || !tp->module))
1584 goto error;
1585
1586 /* Use the tp->address for uprobes */
1521 if (tev->uprobes) 1587 if (tev->uprobes)
1522 len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s:%s", 1588 ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s:0x%lx",
1523 tp->retprobe ? 'r' : 'p', 1589 tp->module, tp->address);
1524 tev->group, tev->event,
1525 tp->module, tp->symbol);
1526 else 1590 else
1527 len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s%s%s+%lu", 1591 ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s%s%s+%lu",
1528 tp->retprobe ? 'r' : 'p',
1529 tev->group, tev->event,
1530 tp->module ?: "", tp->module ? ":" : "", 1592 tp->module ?: "", tp->module ? ":" : "",
1531 tp->symbol, tp->offset); 1593 tp->symbol, tp->offset);
1532 1594
1533 if (len <= 0) 1595 if (ret <= 0)
1534 goto error; 1596 goto error;
1597 len += ret;
1535 1598
1536 for (i = 0; i < tev->nargs; i++) { 1599 for (i = 0; i < tev->nargs; i++) {
1537 ret = synthesize_probe_trace_arg(&tev->args[i], buf + len, 1600 ret = synthesize_probe_trace_arg(&tev->args[i], buf + len,
@@ -1547,6 +1610,79 @@ error:
1547 return NULL; 1610 return NULL;
1548} 1611}
1549 1612
1613static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
1614 struct perf_probe_point *pp,
1615 bool is_kprobe)
1616{
1617 struct symbol *sym = NULL;
1618 struct map *map;
1619 u64 addr;
1620 int ret = -ENOENT;
1621
1622 if (!is_kprobe) {
1623 map = dso__new_map(tp->module);
1624 if (!map)
1625 goto out;
1626 addr = tp->address;
1627 sym = map__find_symbol(map, addr, NULL);
1628 } else {
1629 addr = kernel_get_symbol_address_by_name(tp->symbol, true);
1630 if (addr) {
1631 addr += tp->offset;
1632 sym = __find_kernel_function(addr, &map);
1633 }
1634 }
1635 if (!sym)
1636 goto out;
1637
1638 pp->retprobe = tp->retprobe;
1639 pp->offset = addr - map->unmap_ip(map, sym->start);
1640 pp->function = strdup(sym->name);
1641 ret = pp->function ? 0 : -ENOMEM;
1642
1643out:
1644 if (map && !is_kprobe) {
1645 dso__delete(map->dso);
1646 map__delete(map);
1647 }
1648
1649 return ret;
1650}
1651
1652static int convert_to_perf_probe_point(struct probe_trace_point *tp,
1653 struct perf_probe_point *pp,
1654 bool is_kprobe)
1655{
1656 char buf[128];
1657 int ret;
1658
1659 ret = find_perf_probe_point_from_dwarf(tp, pp, is_kprobe);
1660 if (!ret)
1661 return 0;
1662 ret = find_perf_probe_point_from_map(tp, pp, is_kprobe);
1663 if (!ret)
1664 return 0;
1665
1666 pr_debug("Failed to find probe point from both of dwarf and map.\n");
1667
1668 if (tp->symbol) {
1669 pp->function = strdup(tp->symbol);
1670 pp->offset = tp->offset;
1671 } else if (!tp->module && !is_kprobe) {
1672 ret = e_snprintf(buf, 128, "0x%" PRIx64, (u64)tp->address);
1673 if (ret < 0)
1674 return ret;
1675 pp->function = strdup(buf);
1676 pp->offset = 0;
1677 }
1678 if (pp->function == NULL)
1679 return -ENOMEM;
1680
1681 pp->retprobe = tp->retprobe;
1682
1683 return 0;
1684}
1685
1550static int convert_to_perf_probe_event(struct probe_trace_event *tev, 1686static int convert_to_perf_probe_event(struct probe_trace_event *tev,
1551 struct perf_probe_event *pev, bool is_kprobe) 1687 struct perf_probe_event *pev, bool is_kprobe)
1552{ 1688{
@@ -1560,11 +1696,7 @@ static int convert_to_perf_probe_event(struct probe_trace_event *tev,
1560 return -ENOMEM; 1696 return -ENOMEM;
1561 1697
1562 /* Convert trace_point to probe_point */ 1698 /* Convert trace_point to probe_point */
1563 if (is_kprobe) 1699 ret = convert_to_perf_probe_point(&tev->point, &pev->point, is_kprobe);
1564 ret = kprobe_convert_to_perf_probe(&tev->point, &pev->point);
1565 else
1566 ret = convert_to_perf_probe_point(&tev->point, &pev->point);
1567
1568 if (ret < 0) 1700 if (ret < 0)
1569 return ret; 1701 return ret;
1570 1702
@@ -1731,7 +1863,8 @@ static struct strlist *get_probe_trace_command_rawlist(int fd)
1731} 1863}
1732 1864
1733/* Show an event */ 1865/* Show an event */
1734static int show_perf_probe_event(struct perf_probe_event *pev) 1866static int show_perf_probe_event(struct perf_probe_event *pev,
1867 const char *module)
1735{ 1868{
1736 int i, ret; 1869 int i, ret;
1737 char buf[128]; 1870 char buf[128];
@@ -1747,6 +1880,8 @@ static int show_perf_probe_event(struct perf_probe_event *pev)
1747 return ret; 1880 return ret;
1748 1881
1749 printf(" %-20s (on %s", buf, place); 1882 printf(" %-20s (on %s", buf, place);
1883 if (module)
1884 printf(" in %s", module);
1750 1885
1751 if (pev->nargs > 0) { 1886 if (pev->nargs > 0) {
1752 printf(" with"); 1887 printf(" with");
@@ -1784,7 +1919,8 @@ static int __show_perf_probe_events(int fd, bool is_kprobe)
1784 ret = convert_to_perf_probe_event(&tev, &pev, 1919 ret = convert_to_perf_probe_event(&tev, &pev,
1785 is_kprobe); 1920 is_kprobe);
1786 if (ret >= 0) 1921 if (ret >= 0)
1787 ret = show_perf_probe_event(&pev); 1922 ret = show_perf_probe_event(&pev,
1923 tev.point.module);
1788 } 1924 }
1789 clear_perf_probe_event(&pev); 1925 clear_perf_probe_event(&pev);
1790 clear_probe_trace_event(&tev); 1926 clear_probe_trace_event(&tev);
@@ -1807,7 +1943,7 @@ int show_perf_probe_events(void)
1807 if (fd < 0) 1943 if (fd < 0)
1808 return fd; 1944 return fd;
1809 1945
1810 ret = init_vmlinux(); 1946 ret = init_symbol_maps(false);
1811 if (ret < 0) 1947 if (ret < 0)
1812 return ret; 1948 return ret;
1813 1949
@@ -1820,6 +1956,7 @@ int show_perf_probe_events(void)
1820 close(fd); 1956 close(fd);
1821 } 1957 }
1822 1958
1959 exit_symbol_maps();
1823 return ret; 1960 return ret;
1824} 1961}
1825 1962
@@ -1982,7 +2119,7 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
1982 group = pev->group; 2119 group = pev->group;
1983 pev->event = tev->event; 2120 pev->event = tev->event;
1984 pev->group = tev->group; 2121 pev->group = tev->group;
1985 show_perf_probe_event(pev); 2122 show_perf_probe_event(pev, tev->point.module);
1986 /* Trick here - restore current event/group */ 2123 /* Trick here - restore current event/group */
1987 pev->event = (char *)event; 2124 pev->event = (char *)event;
1988 pev->group = (char *)group; 2125 pev->group = (char *)group;
@@ -2008,113 +2145,175 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
2008 return ret; 2145 return ret;
2009} 2146}
2010 2147
2011static int convert_to_probe_trace_events(struct perf_probe_event *pev, 2148static char *looking_function_name;
2012 struct probe_trace_event **tevs, 2149static int num_matched_functions;
2013 int max_tevs, const char *target) 2150
2151static int probe_function_filter(struct map *map __maybe_unused,
2152 struct symbol *sym)
2014{ 2153{
2154 if ((sym->binding == STB_GLOBAL || sym->binding == STB_LOCAL) &&
2155 strcmp(looking_function_name, sym->name) == 0) {
2156 num_matched_functions++;
2157 return 0;
2158 }
2159 return 1;
2160}
2161
2162#define strdup_or_goto(str, label) \
2163 ({ char *__p = strdup(str); if (!__p) goto label; __p; })
2164
2165/*
2166 * Find probe function addresses from map.
2167 * Return an error or the number of found probe_trace_event
2168 */
2169static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
2170 struct probe_trace_event **tevs,
2171 int max_tevs, const char *target)
2172{
2173 struct map *map = NULL;
2174 struct kmap *kmap = NULL;
2175 struct ref_reloc_sym *reloc_sym = NULL;
2015 struct symbol *sym; 2176 struct symbol *sym;
2016 int ret, i; 2177 struct rb_node *nd;
2017 struct probe_trace_event *tev; 2178 struct probe_trace_event *tev;
2179 struct perf_probe_point *pp = &pev->point;
2180 struct probe_trace_point *tp;
2181 int ret, i;
2018 2182
2019 if (pev->uprobes && !pev->group) { 2183 /* Init maps of given executable or kernel */
2020 /* Replace group name if not given */ 2184 if (pev->uprobes)
2021 ret = convert_exec_to_group(target, &pev->group); 2185 map = dso__new_map(target);
2022 if (ret != 0) { 2186 else
2023 pr_warning("Failed to make a group name.\n"); 2187 map = kernel_get_module_map(target);
2024 return ret; 2188 if (!map) {
2025 } 2189 ret = -EINVAL;
2190 goto out;
2026 } 2191 }
2027 2192
2028 /* Convert perf_probe_event with debuginfo */ 2193 /*
2029 ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, target); 2194 * Load matched symbols: Since the different local symbols may have
2030 if (ret != 0) 2195 * same name but different addresses, this lists all the symbols.
2031 return ret; /* Found in debuginfo or got an error */ 2196 */
2032 2197 num_matched_functions = 0;
2033 if (pev->uprobes) { 2198 looking_function_name = pp->function;
2034 ret = convert_name_to_addr(pev, target); 2199 ret = map__load(map, probe_function_filter);
2035 if (ret < 0) 2200 if (ret || num_matched_functions == 0) {
2036 return ret; 2201 pr_err("Failed to find symbol %s in %s\n", pp->function,
2202 target ? : "kernel");
2203 ret = -ENOENT;
2204 goto out;
2205 } else if (num_matched_functions > max_tevs) {
2206 pr_err("Too many functions matched in %s\n",
2207 target ? : "kernel");
2208 ret = -E2BIG;
2209 goto out;
2037 } 2210 }
2038 2211
2039 /* Allocate trace event buffer */ 2212 if (!pev->uprobes) {
2040 tev = *tevs = zalloc(sizeof(struct probe_trace_event)); 2213 kmap = map__kmap(map);
2041 if (tev == NULL) 2214 reloc_sym = kmap->ref_reloc_sym;
2042 return -ENOMEM; 2215 if (!reloc_sym) {
2216 pr_warning("Relocated base symbol is not found!\n");
2217 ret = -EINVAL;
2218 goto out;
2219 }
2220 }
2043 2221
2044 /* Copy parameters */ 2222 /* Setup result trace-probe-events */
2045 tev->point.symbol = strdup(pev->point.function); 2223 *tevs = zalloc(sizeof(*tev) * num_matched_functions);
2046 if (tev->point.symbol == NULL) { 2224 if (!*tevs) {
2047 ret = -ENOMEM; 2225 ret = -ENOMEM;
2048 goto error; 2226 goto out;
2049 } 2227 }
2050 2228
2051 if (target) { 2229 ret = 0;
2052 tev->point.module = strdup(target); 2230 map__for_each_symbol(map, sym, nd) {
2053 if (tev->point.module == NULL) { 2231 tev = (*tevs) + ret;
2054 ret = -ENOMEM; 2232 tp = &tev->point;
2055 goto error; 2233 if (ret == num_matched_functions) {
2234 pr_warning("Too many symbols are listed. Skip it.\n");
2235 break;
2056 } 2236 }
2057 } 2237 ret++;
2058
2059 tev->point.offset = pev->point.offset;
2060 tev->point.retprobe = pev->point.retprobe;
2061 tev->nargs = pev->nargs;
2062 tev->uprobes = pev->uprobes;
2063 2238
2064 if (tev->nargs) { 2239 if (pp->offset > sym->end - sym->start) {
2065 tev->args = zalloc(sizeof(struct probe_trace_arg) 2240 pr_warning("Offset %ld is bigger than the size of %s\n",
2066 * tev->nargs); 2241 pp->offset, sym->name);
2067 if (tev->args == NULL) { 2242 ret = -ENOENT;
2068 ret = -ENOMEM; 2243 goto err_out;
2069 goto error; 2244 }
2245 /* Add one probe point */
2246 tp->address = map->unmap_ip(map, sym->start) + pp->offset;
2247 if (reloc_sym) {
2248 tp->symbol = strdup_or_goto(reloc_sym->name, nomem_out);
2249 tp->offset = tp->address - reloc_sym->addr;
2250 } else {
2251 tp->symbol = strdup_or_goto(sym->name, nomem_out);
2252 tp->offset = pp->offset;
2253 }
2254 tp->retprobe = pp->retprobe;
2255 if (target)
2256 tev->point.module = strdup_or_goto(target, nomem_out);
2257 tev->uprobes = pev->uprobes;
2258 tev->nargs = pev->nargs;
2259 if (tev->nargs) {
2260 tev->args = zalloc(sizeof(struct probe_trace_arg) *
2261 tev->nargs);
2262 if (tev->args == NULL)
2263 goto nomem_out;
2070 } 2264 }
2071 for (i = 0; i < tev->nargs; i++) { 2265 for (i = 0; i < tev->nargs; i++) {
2072 if (pev->args[i].name) { 2266 if (pev->args[i].name)
2073 tev->args[i].name = strdup(pev->args[i].name); 2267 tev->args[i].name =
2074 if (tev->args[i].name == NULL) { 2268 strdup_or_goto(pev->args[i].name,
2075 ret = -ENOMEM; 2269 nomem_out);
2076 goto error; 2270
2077 } 2271 tev->args[i].value = strdup_or_goto(pev->args[i].var,
2078 } 2272 nomem_out);
2079 tev->args[i].value = strdup(pev->args[i].var); 2273 if (pev->args[i].type)
2080 if (tev->args[i].value == NULL) { 2274 tev->args[i].type =
2081 ret = -ENOMEM; 2275 strdup_or_goto(pev->args[i].type,
2082 goto error; 2276 nomem_out);
2083 }
2084 if (pev->args[i].type) {
2085 tev->args[i].type = strdup(pev->args[i].type);
2086 if (tev->args[i].type == NULL) {
2087 ret = -ENOMEM;
2088 goto error;
2089 }
2090 }
2091 } 2277 }
2092 } 2278 }
2093 2279
2094 if (pev->uprobes) 2280out:
2095 return 1; 2281 if (map && pev->uprobes) {
2282 /* Only when using uprobe(exec) map needs to be released */
2283 dso__delete(map->dso);
2284 map__delete(map);
2285 }
2286 return ret;
2096 2287
2097 /* Currently just checking function name from symbol map */ 2288nomem_out:
2098 sym = __find_kernel_function_by_name(tev->point.symbol, NULL); 2289 ret = -ENOMEM;
2099 if (!sym) { 2290err_out:
2100 pr_warning("Kernel symbol \'%s\' not found.\n", 2291 clear_probe_trace_events(*tevs, num_matched_functions);
2101 tev->point.symbol); 2292 zfree(tevs);
2102 ret = -ENOENT; 2293 goto out;
2103 goto error; 2294}
2104 } else if (tev->point.offset > sym->end - sym->start) { 2295
2105 pr_warning("Offset specified is greater than size of %s\n", 2296static int convert_to_probe_trace_events(struct perf_probe_event *pev,
2106 tev->point.symbol); 2297 struct probe_trace_event **tevs,
2107 ret = -ENOENT; 2298 int max_tevs, const char *target)
2108 goto error; 2299{
2300 int ret;
2109 2301
2302 if (pev->uprobes && !pev->group) {
2303 /* Replace group name if not given */
2304 ret = convert_exec_to_group(target, &pev->group);
2305 if (ret != 0) {
2306 pr_warning("Failed to make a group name.\n");
2307 return ret;
2308 }
2110 } 2309 }
2111 2310
2112 return 1; 2311 /* Convert perf_probe_event with debuginfo */
2113error: 2312 ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, target);
2114 clear_probe_trace_event(tev); 2313 if (ret != 0)
2115 free(tev); 2314 return ret; /* Found in debuginfo or got an error */
2116 *tevs = NULL; 2315
2117 return ret; 2316 return find_probe_trace_events_from_map(pev, tevs, max_tevs, target);
2118} 2317}
2119 2318
2120struct __event_package { 2319struct __event_package {
@@ -2135,12 +2334,7 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
2135 if (pkgs == NULL) 2334 if (pkgs == NULL)
2136 return -ENOMEM; 2335 return -ENOMEM;
2137 2336
2138 if (!pevs->uprobes) 2337 ret = init_symbol_maps(pevs->uprobes);
2139 /* Init vmlinux path */
2140 ret = init_vmlinux();
2141 else
2142 ret = init_user_exec();
2143
2144 if (ret < 0) { 2338 if (ret < 0) {
2145 free(pkgs); 2339 free(pkgs);
2146 return ret; 2340 return ret;
@@ -2174,6 +2368,7 @@ end:
2174 zfree(&pkgs[i].tevs); 2368 zfree(&pkgs[i].tevs);
2175 } 2369 }
2176 free(pkgs); 2370 free(pkgs);
2371 exit_symbol_maps();
2177 2372
2178 return ret; 2373 return ret;
2179} 2374}
@@ -2323,159 +2518,51 @@ static struct strfilter *available_func_filter;
2323static int filter_available_functions(struct map *map __maybe_unused, 2518static int filter_available_functions(struct map *map __maybe_unused,
2324 struct symbol *sym) 2519 struct symbol *sym)
2325{ 2520{
2326 if (sym->binding == STB_GLOBAL && 2521 if ((sym->binding == STB_GLOBAL || sym->binding == STB_LOCAL) &&
2327 strfilter__compare(available_func_filter, sym->name)) 2522 strfilter__compare(available_func_filter, sym->name))
2328 return 0; 2523 return 0;
2329 return 1; 2524 return 1;
2330} 2525}
2331 2526
2332static int __show_available_funcs(struct map *map) 2527int show_available_funcs(const char *target, struct strfilter *_filter,
2333{ 2528 bool user)
2334 if (map__load(map, filter_available_functions)) {
2335 pr_err("Failed to load map.\n");
2336 return -EINVAL;
2337 }
2338 if (!dso__sorted_by_name(map->dso, map->type))
2339 dso__sort_by_name(map->dso, map->type);
2340
2341 dso__fprintf_symbols_by_name(map->dso, map->type, stdout);
2342 return 0;
2343}
2344
2345static int available_kernel_funcs(const char *module)
2346{ 2529{
2347 struct map *map; 2530 struct map *map;
2348 int ret; 2531 int ret;
2349 2532
2350 ret = init_vmlinux(); 2533 ret = init_symbol_maps(user);
2351 if (ret < 0) 2534 if (ret < 0)
2352 return ret; 2535 return ret;
2353 2536
2354 map = kernel_get_module_map(module); 2537 /* Get a symbol map */
2538 if (user)
2539 map = dso__new_map(target);
2540 else
2541 map = kernel_get_module_map(target);
2355 if (!map) { 2542 if (!map) {
2356 pr_err("Failed to find %s map.\n", (module) ? : "kernel"); 2543 pr_err("Failed to get a map for %s\n", (target) ? : "kernel");
2357 return -EINVAL; 2544 return -EINVAL;
2358 } 2545 }
2359 return __show_available_funcs(map);
2360}
2361
2362static int available_user_funcs(const char *target)
2363{
2364 struct map *map;
2365 int ret;
2366
2367 ret = init_user_exec();
2368 if (ret < 0)
2369 return ret;
2370
2371 map = dso__new_map(target);
2372 ret = __show_available_funcs(map);
2373 dso__delete(map->dso);
2374 map__delete(map);
2375 return ret;
2376}
2377 2546
2378int show_available_funcs(const char *target, struct strfilter *_filter, 2547 /* Load symbols with given filter */
2379 bool user)
2380{
2381 setup_pager();
2382 available_func_filter = _filter; 2548 available_func_filter = _filter;
2383
2384 if (!user)
2385 return available_kernel_funcs(target);
2386
2387 return available_user_funcs(target);
2388}
2389
2390/*
2391 * uprobe_events only accepts address:
2392 * Convert function and any offset to address
2393 */
2394static int convert_name_to_addr(struct perf_probe_event *pev, const char *exec)
2395{
2396 struct perf_probe_point *pp = &pev->point;
2397 struct symbol *sym;
2398 struct map *map = NULL;
2399 char *function = NULL;
2400 int ret = -EINVAL;
2401 unsigned long long vaddr = 0;
2402
2403 if (!pp->function) {
2404 pr_warning("No function specified for uprobes");
2405 goto out;
2406 }
2407
2408 function = strdup(pp->function);
2409 if (!function) {
2410 pr_warning("Failed to allocate memory by strdup.\n");
2411 ret = -ENOMEM;
2412 goto out;
2413 }
2414
2415 map = dso__new_map(exec);
2416 if (!map) {
2417 pr_warning("Cannot find appropriate DSO for %s.\n", exec);
2418 goto out;
2419 }
2420 available_func_filter = strfilter__new(function, NULL);
2421 if (map__load(map, filter_available_functions)) { 2549 if (map__load(map, filter_available_functions)) {
2422 pr_err("Failed to load map.\n"); 2550 pr_err("Failed to load symbols in %s\n", (target) ? : "kernel");
2423 goto out; 2551 goto end;
2424 }
2425
2426 sym = map__find_symbol_by_name(map, function, NULL);
2427 if (!sym) {
2428 pr_warning("Cannot find %s in DSO %s\n", function, exec);
2429 goto out;
2430 }
2431
2432 if (map->start > sym->start)
2433 vaddr = map->start;
2434 vaddr += sym->start + pp->offset + map->pgoff;
2435 pp->offset = 0;
2436
2437 if (!pev->event) {
2438 pev->event = function;
2439 function = NULL;
2440 }
2441 if (!pev->group) {
2442 char *ptr1, *ptr2, *exec_copy;
2443
2444 pev->group = zalloc(sizeof(char *) * 64);
2445 exec_copy = strdup(exec);
2446 if (!exec_copy) {
2447 ret = -ENOMEM;
2448 pr_warning("Failed to copy exec string.\n");
2449 goto out;
2450 }
2451
2452 ptr1 = strdup(basename(exec_copy));
2453 if (ptr1) {
2454 ptr2 = strpbrk(ptr1, "-._");
2455 if (ptr2)
2456 *ptr2 = '\0';
2457 e_snprintf(pev->group, 64, "%s_%s", PERFPROBE_GROUP,
2458 ptr1);
2459 free(ptr1);
2460 }
2461 free(exec_copy);
2462 }
2463 free(pp->function);
2464 pp->function = zalloc(sizeof(char *) * MAX_PROBE_ARGS);
2465 if (!pp->function) {
2466 ret = -ENOMEM;
2467 pr_warning("Failed to allocate memory by zalloc.\n");
2468 goto out;
2469 } 2552 }
2470 e_snprintf(pp->function, MAX_PROBE_ARGS, "0x%llx", vaddr); 2553 if (!dso__sorted_by_name(map->dso, map->type))
2471 ret = 0; 2554 dso__sort_by_name(map->dso, map->type);
2472 2555
2473out: 2556 /* Show all (filtered) symbols */
2474 if (map) { 2557 setup_pager();
2558 dso__fprintf_symbols_by_name(map->dso, map->type, stdout);
2559end:
2560 if (user) {
2475 dso__delete(map->dso); 2561 dso__delete(map->dso);
2476 map__delete(map); 2562 map__delete(map);
2477 } 2563 }
2478 if (function) 2564 exit_symbol_maps();
2479 free(function); 2565
2480 return ret; 2566 return ret;
2481} 2567}
2568
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index fcaf7273e85a..776c9347a3b6 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -2,6 +2,7 @@
2#define _PROBE_EVENT_H 2#define _PROBE_EVENT_H
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include "intlist.h"
5#include "strlist.h" 6#include "strlist.h"
6#include "strfilter.h" 7#include "strfilter.h"
7 8
@@ -76,13 +77,6 @@ struct perf_probe_event {
76 struct perf_probe_arg *args; /* Arguments */ 77 struct perf_probe_arg *args; /* Arguments */
77}; 78};
78 79
79
80/* Line number container */
81struct line_node {
82 struct list_head list;
83 int line;
84};
85
86/* Line range */ 80/* Line range */
87struct line_range { 81struct line_range {
88 char *file; /* File name */ 82 char *file; /* File name */
@@ -92,7 +86,7 @@ struct line_range {
92 int offset; /* Start line offset */ 86 int offset; /* Start line offset */
93 char *path; /* Real path name */ 87 char *path; /* Real path name */
94 char *comp_dir; /* Compile directory */ 88 char *comp_dir; /* Compile directory */
95 struct list_head line_list; /* Visible lines */ 89 struct intlist *line_list; /* Visible lines */
96}; 90};
97 91
98/* List of variables */ 92/* List of variables */
@@ -124,7 +118,7 @@ extern int parse_line_range_desc(const char *cmd, struct line_range *lr);
124extern void line_range__clear(struct line_range *lr); 118extern void line_range__clear(struct line_range *lr);
125 119
126/* Initialize line range */ 120/* Initialize line range */
127extern void line_range__init(struct line_range *lr); 121extern int line_range__init(struct line_range *lr);
128 122
129/* Internal use: Return kernel/module path */ 123/* Internal use: Return kernel/module path */
130extern const char *kernel_get_module_path(const char *module); 124extern const char *kernel_get_module_path(const char *module);
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 061edb162b5b..df0238654698 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -34,7 +34,9 @@
34 34
35#include <linux/bitops.h> 35#include <linux/bitops.h>
36#include "event.h" 36#include "event.h"
37#include "dso.h"
37#include "debug.h" 38#include "debug.h"
39#include "intlist.h"
38#include "util.h" 40#include "util.h"
39#include "symbol.h" 41#include "symbol.h"
40#include "probe-finder.h" 42#include "probe-finder.h"
@@ -42,65 +44,6 @@
42/* Kprobe tracer basic type is up to u64 */ 44/* Kprobe tracer basic type is up to u64 */
43#define MAX_BASIC_TYPE_BITS 64 45#define MAX_BASIC_TYPE_BITS 64
44 46
45/* Line number list operations */
46
47/* Add a line to line number list */
48static int line_list__add_line(struct list_head *head, int line)
49{
50 struct line_node *ln;
51 struct list_head *p;
52
53 /* Reverse search, because new line will be the last one */
54 list_for_each_entry_reverse(ln, head, list) {
55 if (ln->line < line) {
56 p = &ln->list;
57 goto found;
58 } else if (ln->line == line) /* Already exist */
59 return 1;
60 }
61 /* List is empty, or the smallest entry */
62 p = head;
63found:
64 pr_debug("line list: add a line %u\n", line);
65 ln = zalloc(sizeof(struct line_node));
66 if (ln == NULL)
67 return -ENOMEM;
68 ln->line = line;
69 INIT_LIST_HEAD(&ln->list);
70 list_add(&ln->list, p);
71 return 0;
72}
73
74/* Check if the line in line number list */
75static int line_list__has_line(struct list_head *head, int line)
76{
77 struct line_node *ln;
78
79 /* Reverse search, because new line will be the last one */
80 list_for_each_entry(ln, head, list)
81 if (ln->line == line)
82 return 1;
83
84 return 0;
85}
86
87/* Init line number list */
88static void line_list__init(struct list_head *head)
89{
90 INIT_LIST_HEAD(head);
91}
92
93/* Free line number list */
94static void line_list__free(struct list_head *head)
95{
96 struct line_node *ln;
97 while (!list_empty(head)) {
98 ln = list_first_entry(head, struct line_node, list);
99 list_del(&ln->list);
100 free(ln);
101 }
102}
103
104/* Dwarf FL wrappers */ 47/* Dwarf FL wrappers */
105static char *debuginfo_path; /* Currently dummy */ 48static char *debuginfo_path; /* Currently dummy */
106 49
@@ -147,80 +90,7 @@ error:
147 return -ENOENT; 90 return -ENOENT;
148} 91}
149 92
150#if _ELFUTILS_PREREQ(0, 148) 93static struct debuginfo *__debuginfo__new(const char *path)
151/* This method is buggy if elfutils is older than 0.148 */
152static int __linux_kernel_find_elf(Dwfl_Module *mod,
153 void **userdata,
154 const char *module_name,
155 Dwarf_Addr base,
156 char **file_name, Elf **elfp)
157{
158 int fd;
159 const char *path = kernel_get_module_path(module_name);
160
161 pr_debug2("Use file %s for %s\n", path, module_name);
162 if (path) {
163 fd = open(path, O_RDONLY);
164 if (fd >= 0) {
165 *file_name = strdup(path);
166 return fd;
167 }
168 }
169 /* If failed, try to call standard method */
170 return dwfl_linux_kernel_find_elf(mod, userdata, module_name, base,
171 file_name, elfp);
172}
173
174static const Dwfl_Callbacks kernel_callbacks = {
175 .find_debuginfo = dwfl_standard_find_debuginfo,
176 .debuginfo_path = &debuginfo_path,
177
178 .find_elf = __linux_kernel_find_elf,
179 .section_address = dwfl_linux_kernel_module_section_address,
180};
181
182/* Get a Dwarf from live kernel image */
183static int debuginfo__init_online_kernel_dwarf(struct debuginfo *dbg,
184 Dwarf_Addr addr)
185{
186 dbg->dwfl = dwfl_begin(&kernel_callbacks);
187 if (!dbg->dwfl)
188 return -EINVAL;
189
190 /* Load the kernel dwarves: Don't care the result here */
191 dwfl_linux_kernel_report_kernel(dbg->dwfl);
192 dwfl_linux_kernel_report_modules(dbg->dwfl);
193
194 dbg->dbg = dwfl_addrdwarf(dbg->dwfl, addr, &dbg->bias);
195 /* Here, check whether we could get a real dwarf */
196 if (!dbg->dbg) {
197 pr_debug("Failed to find kernel dwarf at %lx\n",
198 (unsigned long)addr);
199 dwfl_end(dbg->dwfl);
200 memset(dbg, 0, sizeof(*dbg));
201 return -ENOENT;
202 }
203
204 return 0;
205}
206#else
207/* With older elfutils, this just support kernel module... */
208static int debuginfo__init_online_kernel_dwarf(struct debuginfo *dbg,
209 Dwarf_Addr addr __maybe_unused)
210{
211 const char *path = kernel_get_module_path("kernel");
212
213 if (!path) {
214 pr_err("Failed to find vmlinux path\n");
215 return -ENOENT;
216 }
217
218 pr_debug2("Use file %s for debuginfo\n", path);
219 return debuginfo__init_offline_dwarf(dbg, path);
220}
221#endif
222
223struct debuginfo *debuginfo__new(const char *path)
224{ 94{
225 struct debuginfo *dbg = zalloc(sizeof(*dbg)); 95 struct debuginfo *dbg = zalloc(sizeof(*dbg));
226 if (!dbg) 96 if (!dbg)
@@ -228,21 +98,44 @@ struct debuginfo *debuginfo__new(const char *path)
228 98
229 if (debuginfo__init_offline_dwarf(dbg, path) < 0) 99 if (debuginfo__init_offline_dwarf(dbg, path) < 0)
230 zfree(&dbg); 100 zfree(&dbg);
231 101 if (dbg)
102 pr_debug("Open Debuginfo file: %s\n", path);
232 return dbg; 103 return dbg;
233} 104}
234 105
235struct debuginfo *debuginfo__new_online_kernel(unsigned long addr) 106enum dso_binary_type distro_dwarf_types[] = {
236{ 107 DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
237 struct debuginfo *dbg = zalloc(sizeof(*dbg)); 108 DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
109 DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
110 DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
111 DSO_BINARY_TYPE__NOT_FOUND,
112};
238 113
239 if (!dbg) 114struct debuginfo *debuginfo__new(const char *path)
240 return NULL; 115{
116 enum dso_binary_type *type;
117 char buf[PATH_MAX], nil = '\0';
118 struct dso *dso;
119 struct debuginfo *dinfo = NULL;
120
121 /* Try to open distro debuginfo files */
122 dso = dso__new(path);
123 if (!dso)
124 goto out;
241 125
242 if (debuginfo__init_online_kernel_dwarf(dbg, (Dwarf_Addr)addr) < 0) 126 for (type = distro_dwarf_types;
243 zfree(&dbg); 127 !dinfo && *type != DSO_BINARY_TYPE__NOT_FOUND;
128 type++) {
129 if (dso__read_binary_type_filename(dso, *type, &nil,
130 buf, PATH_MAX) < 0)
131 continue;
132 dinfo = __debuginfo__new(buf);
133 }
134 dso__delete(dso);
244 135
245 return dbg; 136out:
137 /* if failed to open all distro debuginfo, open given binary */
138 return dinfo ? : __debuginfo__new(path);
246} 139}
247 140
248void debuginfo__delete(struct debuginfo *dbg) 141void debuginfo__delete(struct debuginfo *dbg)
@@ -880,7 +773,7 @@ static int find_probe_point_by_line(struct probe_finder *pf)
880} 773}
881 774
882/* Find lines which match lazy pattern */ 775/* Find lines which match lazy pattern */
883static int find_lazy_match_lines(struct list_head *head, 776static int find_lazy_match_lines(struct intlist *list,
884 const char *fname, const char *pat) 777 const char *fname, const char *pat)
885{ 778{
886 FILE *fp; 779 FILE *fp;
@@ -901,7 +794,7 @@ static int find_lazy_match_lines(struct list_head *head,
901 line[len - 1] = '\0'; 794 line[len - 1] = '\0';
902 795
903 if (strlazymatch(line, pat)) { 796 if (strlazymatch(line, pat)) {
904 line_list__add_line(head, linenum); 797 intlist__add(list, linenum);
905 count++; 798 count++;
906 } 799 }
907 linenum++; 800 linenum++;
@@ -924,7 +817,7 @@ static int probe_point_lazy_walker(const char *fname, int lineno,
924 Dwarf_Die *sc_die, die_mem; 817 Dwarf_Die *sc_die, die_mem;
925 int ret; 818 int ret;
926 819
927 if (!line_list__has_line(&pf->lcache, lineno) || 820 if (!intlist__has_entry(pf->lcache, lineno) ||
928 strtailcmp(fname, pf->fname) != 0) 821 strtailcmp(fname, pf->fname) != 0)
929 return 0; 822 return 0;
930 823
@@ -952,9 +845,9 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
952{ 845{
953 int ret = 0; 846 int ret = 0;
954 847
955 if (list_empty(&pf->lcache)) { 848 if (intlist__empty(pf->lcache)) {
956 /* Matching lazy line pattern */ 849 /* Matching lazy line pattern */
957 ret = find_lazy_match_lines(&pf->lcache, pf->fname, 850 ret = find_lazy_match_lines(pf->lcache, pf->fname,
958 pf->pev->point.lazy_line); 851 pf->pev->point.lazy_line);
959 if (ret <= 0) 852 if (ret <= 0)
960 return ret; 853 return ret;
@@ -1096,7 +989,9 @@ static int debuginfo__find_probes(struct debuginfo *dbg,
1096#endif 989#endif
1097 990
1098 off = 0; 991 off = 0;
1099 line_list__init(&pf->lcache); 992 pf->lcache = intlist__new(NULL);
993 if (!pf->lcache)
994 return -ENOMEM;
1100 995
1101 /* Fastpath: lookup by function name from .debug_pubnames section */ 996 /* Fastpath: lookup by function name from .debug_pubnames section */
1102 if (pp->function) { 997 if (pp->function) {
@@ -1149,7 +1044,8 @@ static int debuginfo__find_probes(struct debuginfo *dbg,
1149 } 1044 }
1150 1045
1151found: 1046found:
1152 line_list__free(&pf->lcache); 1047 intlist__delete(pf->lcache);
1048 pf->lcache = NULL;
1153 1049
1154 return ret; 1050 return ret;
1155} 1051}
@@ -1537,7 +1433,7 @@ static int line_range_add_line(const char *src, unsigned int lineno,
1537 if (lr->path == NULL) 1433 if (lr->path == NULL)
1538 return -ENOMEM; 1434 return -ENOMEM;
1539 } 1435 }
1540 return line_list__add_line(&lr->line_list, lineno); 1436 return intlist__add(lr->line_list, lineno);
1541} 1437}
1542 1438
1543static int line_range_walk_cb(const char *fname, int lineno, 1439static int line_range_walk_cb(const char *fname, int lineno,
@@ -1565,7 +1461,7 @@ static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
1565 1461
1566 /* Update status */ 1462 /* Update status */
1567 if (ret >= 0) 1463 if (ret >= 0)
1568 if (!list_empty(&lf->lr->line_list)) 1464 if (!intlist__empty(lf->lr->line_list))
1569 ret = lf->found = 1; 1465 ret = lf->found = 1;
1570 else 1466 else
1571 ret = 0; /* Lines are not found */ 1467 ret = 0; /* Lines are not found */
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index ffc33cdd25cc..92590b2c7e1c 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -3,6 +3,7 @@
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include "util.h" 5#include "util.h"
6#include "intlist.h"
6#include "probe-event.h" 7#include "probe-event.h"
7 8
8#define MAX_PROBE_BUFFER 1024 9#define MAX_PROBE_BUFFER 1024
@@ -29,8 +30,8 @@ struct debuginfo {
29 Dwarf_Addr bias; 30 Dwarf_Addr bias;
30}; 31};
31 32
33/* This also tries to open distro debuginfo */
32extern struct debuginfo *debuginfo__new(const char *path); 34extern struct debuginfo *debuginfo__new(const char *path);
33extern struct debuginfo *debuginfo__new_online_kernel(unsigned long addr);
34extern void debuginfo__delete(struct debuginfo *dbg); 35extern void debuginfo__delete(struct debuginfo *dbg);
35 36
36/* Find probe_trace_events specified by perf_probe_event from debuginfo */ 37/* Find probe_trace_events specified by perf_probe_event from debuginfo */
@@ -66,7 +67,7 @@ struct probe_finder {
66 const char *fname; /* Real file name */ 67 const char *fname; /* Real file name */
67 Dwarf_Die cu_die; /* Current CU */ 68 Dwarf_Die cu_die; /* Current CU */
68 Dwarf_Die sp_die; 69 Dwarf_Die sp_die;
69 struct list_head lcache; /* Line cache for lazy match */ 70 struct intlist *lcache; /* Line cache for lazy match */
70 71
71 /* For variable searching */ 72 /* For variable searching */
72#if _ELFUTILS_PREREQ(0, 142) 73#if _ELFUTILS_PREREQ(0, 142)
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 595bfc73d2ed..16a475a7d492 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -17,6 +17,6 @@ util/xyarray.c
17util/cgroup.c 17util/cgroup.c
18util/rblist.c 18util/rblist.c
19util/strlist.c 19util/strlist.c
20util/fs.c 20../lib/api/fs/fs.c
21util/trace-event.c 21util/trace-event.c
22../../lib/rbtree.c 22../../lib/rbtree.c
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 373762501dad..049e0a09ccd3 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -2,7 +2,7 @@
2#include "evsel.h" 2#include "evsel.h"
3#include "cpumap.h" 3#include "cpumap.h"
4#include "parse-events.h" 4#include "parse-events.h"
5#include "fs.h" 5#include <api/fs/fs.h>
6#include "util.h" 6#include "util.h"
7 7
8typedef void (*setup_probe_fn_t)(struct perf_evsel *evsel); 8typedef void (*setup_probe_fn_t)(struct perf_evsel *evsel);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 0b39a48e5110..55960f22233c 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -702,11 +702,12 @@ static void regs_dump__printf(u64 mask, u64 *regs)
702 } 702 }
703} 703}
704 704
705static void regs_user__printf(struct perf_sample *sample, u64 mask) 705static void regs_user__printf(struct perf_sample *sample)
706{ 706{
707 struct regs_dump *user_regs = &sample->user_regs; 707 struct regs_dump *user_regs = &sample->user_regs;
708 708
709 if (user_regs->regs) { 709 if (user_regs->regs) {
710 u64 mask = user_regs->mask;
710 printf("... user regs: mask 0x%" PRIx64 "\n", mask); 711 printf("... user regs: mask 0x%" PRIx64 "\n", mask);
711 regs_dump__printf(mask, user_regs->regs); 712 regs_dump__printf(mask, user_regs->regs);
712 } 713 }
@@ -793,7 +794,7 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event,
793 if (!dump_trace) 794 if (!dump_trace)
794 return; 795 return;
795 796
796 printf("(IP, %d): %d/%d: %#" PRIx64 " period: %" PRIu64 " addr: %#" PRIx64 "\n", 797 printf("(IP, 0x%x): %d/%d: %#" PRIx64 " period: %" PRIu64 " addr: %#" PRIx64 "\n",
797 event->header.misc, sample->pid, sample->tid, sample->ip, 798 event->header.misc, sample->pid, sample->tid, sample->ip,
798 sample->period, sample->addr); 799 sample->period, sample->addr);
799 800
@@ -806,7 +807,7 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event,
806 branch_stack__printf(sample); 807 branch_stack__printf(sample);
807 808
808 if (sample_type & PERF_SAMPLE_REGS_USER) 809 if (sample_type & PERF_SAMPLE_REGS_USER)
809 regs_user__printf(sample, evsel->attr.sample_regs_user); 810 regs_user__printf(sample);
810 811
811 if (sample_type & PERF_SAMPLE_STACK_USER) 812 if (sample_type & PERF_SAMPLE_STACK_USER)
812 stack_user__printf(&sample->user_stack); 813 stack_user__printf(&sample->user_stack);
@@ -1008,6 +1009,12 @@ static int perf_session__process_user_event(struct perf_session *session, union
1008 if (err == 0) 1009 if (err == 0)
1009 perf_session__set_id_hdr_size(session); 1010 perf_session__set_id_hdr_size(session);
1010 return err; 1011 return err;
1012 case PERF_RECORD_HEADER_EVENT_TYPE:
1013 /*
1014 * Depreceated, but we need to handle it for sake
1015 * of old data files create in pipe mode.
1016 */
1017 return 0;
1011 case PERF_RECORD_HEADER_TRACING_DATA: 1018 case PERF_RECORD_HEADER_TRACING_DATA:
1012 /* setup for reading amidst mmap */ 1019 /* setup for reading amidst mmap */
1013 lseek(fd, file_offset, SEEK_SET); 1020 lseek(fd, file_offset, SEEK_SET);
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 759456728703..3b7dbf51d4a9 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -151,15 +151,15 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
151 151
152 gelf_getshdr(sec, shp); 152 gelf_getshdr(sec, shp);
153 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); 153 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
154 if (!strcmp(name, str)) { 154 if (str && !strcmp(name, str)) {
155 if (idx) 155 if (idx)
156 *idx = cnt; 156 *idx = cnt;
157 break; 157 return sec;
158 } 158 }
159 ++cnt; 159 ++cnt;
160 } 160 }
161 161
162 return sec; 162 return NULL;
163} 163}
164 164
165#define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \ 165#define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \
@@ -506,6 +506,8 @@ int filename__read_debuglink(const char *filename, char *debuglink,
506 /* the start of this section is a zero-terminated string */ 506 /* the start of this section is a zero-terminated string */
507 strncpy(debuglink, data->d_buf, size); 507 strncpy(debuglink, data->d_buf, size);
508 508
509 err = 0;
510
509out_elf_end: 511out_elf_end:
510 elf_end(elf); 512 elf_end(elf);
511out_close: 513out_close:
@@ -751,6 +753,8 @@ int dso__load_sym(struct dso *dso, struct map *map,
751 if (strcmp(elf_name, kmap->ref_reloc_sym->name)) 753 if (strcmp(elf_name, kmap->ref_reloc_sym->name))
752 continue; 754 continue;
753 kmap->ref_reloc_sym->unrelocated_addr = sym.st_value; 755 kmap->ref_reloc_sym->unrelocated_addr = sym.st_value;
756 map->reloc = kmap->ref_reloc_sym->addr -
757 kmap->ref_reloc_sym->unrelocated_addr;
754 break; 758 break;
755 } 759 }
756 } 760 }
@@ -922,6 +926,7 @@ int dso__load_sym(struct dso *dso, struct map *map,
922 (u64)shdr.sh_offset); 926 (u64)shdr.sh_offset);
923 sym.st_value -= shdr.sh_addr - shdr.sh_offset; 927 sym.st_value -= shdr.sh_addr - shdr.sh_offset;
924 } 928 }
929new_symbol:
925 /* 930 /*
926 * We need to figure out if the object was created from C++ sources 931 * We need to figure out if the object was created from C++ sources
927 * DWARF DW_compile_unit has this, but we don't always have access 932 * DWARF DW_compile_unit has this, but we don't always have access
@@ -933,7 +938,6 @@ int dso__load_sym(struct dso *dso, struct map *map,
933 if (demangled != NULL) 938 if (demangled != NULL)
934 elf_name = demangled; 939 elf_name = demangled;
935 } 940 }
936new_symbol:
937 f = symbol__new(sym.st_value, sym.st_size, 941 f = symbol__new(sym.st_value, sym.st_size,
938 GELF_ST_BIND(sym.st_info), elf_name); 942 GELF_ST_BIND(sym.st_info), elf_name);
939 free(demangled); 943 free(demangled);
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 39ce9adbaaf0..95e249779931 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -410,7 +410,7 @@ struct symbol *dso__find_symbol(struct dso *dso,
410 return symbols__find(&dso->symbols[type], addr); 410 return symbols__find(&dso->symbols[type], addr);
411} 411}
412 412
413struct symbol *dso__first_symbol(struct dso *dso, enum map_type type) 413static struct symbol *dso__first_symbol(struct dso *dso, enum map_type type)
414{ 414{
415 return symbols__first(&dso->symbols[type]); 415 return symbols__first(&dso->symbols[type]);
416} 416}
@@ -627,7 +627,7 @@ static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map,
627 * kernel range is broken in several maps, named [kernel].N, as we don't have 627 * kernel range is broken in several maps, named [kernel].N, as we don't have
628 * the original ELF section names vmlinux have. 628 * the original ELF section names vmlinux have.
629 */ 629 */
630static int dso__split_kallsyms(struct dso *dso, struct map *map, 630static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta,
631 symbol_filter_t filter) 631 symbol_filter_t filter)
632{ 632{
633 struct map_groups *kmaps = map__kmap(map)->kmaps; 633 struct map_groups *kmaps = map__kmap(map)->kmaps;
@@ -692,6 +692,12 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map,
692 char dso_name[PATH_MAX]; 692 char dso_name[PATH_MAX];
693 struct dso *ndso; 693 struct dso *ndso;
694 694
695 if (delta) {
696 /* Kernel was relocated at boot time */
697 pos->start -= delta;
698 pos->end -= delta;
699 }
700
695 if (count == 0) { 701 if (count == 0) {
696 curr_map = map; 702 curr_map = map;
697 goto filter_symbol; 703 goto filter_symbol;
@@ -721,6 +727,10 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map,
721 curr_map->map_ip = curr_map->unmap_ip = identity__map_ip; 727 curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
722 map_groups__insert(kmaps, curr_map); 728 map_groups__insert(kmaps, curr_map);
723 ++kernel_range; 729 ++kernel_range;
730 } else if (delta) {
731 /* Kernel was relocated at boot time */
732 pos->start -= delta;
733 pos->end -= delta;
724 } 734 }
725filter_symbol: 735filter_symbol:
726 if (filter && filter(curr_map, pos)) { 736 if (filter && filter(curr_map, pos)) {
@@ -976,6 +986,23 @@ static int validate_kcore_modules(const char *kallsyms_filename,
976 return 0; 986 return 0;
977} 987}
978 988
989static int validate_kcore_addresses(const char *kallsyms_filename,
990 struct map *map)
991{
992 struct kmap *kmap = map__kmap(map);
993
994 if (kmap->ref_reloc_sym && kmap->ref_reloc_sym->name) {
995 u64 start;
996
997 start = kallsyms__get_function_start(kallsyms_filename,
998 kmap->ref_reloc_sym->name);
999 if (start != kmap->ref_reloc_sym->addr)
1000 return -EINVAL;
1001 }
1002
1003 return validate_kcore_modules(kallsyms_filename, map);
1004}
1005
979struct kcore_mapfn_data { 1006struct kcore_mapfn_data {
980 struct dso *dso; 1007 struct dso *dso;
981 enum map_type type; 1008 enum map_type type;
@@ -1019,8 +1046,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
1019 kallsyms_filename)) 1046 kallsyms_filename))
1020 return -EINVAL; 1047 return -EINVAL;
1021 1048
1022 /* All modules must be present at their original addresses */ 1049 /* Modules and kernel must be present at their original addresses */
1023 if (validate_kcore_modules(kallsyms_filename, map)) 1050 if (validate_kcore_addresses(kallsyms_filename, map))
1024 return -EINVAL; 1051 return -EINVAL;
1025 1052
1026 md.dso = dso; 1053 md.dso = dso;
@@ -1113,15 +1140,41 @@ out_err:
1113 return -EINVAL; 1140 return -EINVAL;
1114} 1141}
1115 1142
1143/*
1144 * If the kernel is relocated at boot time, kallsyms won't match. Compute the
1145 * delta based on the relocation reference symbol.
1146 */
1147static int kallsyms__delta(struct map *map, const char *filename, u64 *delta)
1148{
1149 struct kmap *kmap = map__kmap(map);
1150 u64 addr;
1151
1152 if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->name)
1153 return 0;
1154
1155 addr = kallsyms__get_function_start(filename,
1156 kmap->ref_reloc_sym->name);
1157 if (!addr)
1158 return -1;
1159
1160 *delta = addr - kmap->ref_reloc_sym->addr;
1161 return 0;
1162}
1163
1116int dso__load_kallsyms(struct dso *dso, const char *filename, 1164int dso__load_kallsyms(struct dso *dso, const char *filename,
1117 struct map *map, symbol_filter_t filter) 1165 struct map *map, symbol_filter_t filter)
1118{ 1166{
1167 u64 delta = 0;
1168
1119 if (symbol__restricted_filename(filename, "/proc/kallsyms")) 1169 if (symbol__restricted_filename(filename, "/proc/kallsyms"))
1120 return -1; 1170 return -1;
1121 1171
1122 if (dso__load_all_kallsyms(dso, filename, map) < 0) 1172 if (dso__load_all_kallsyms(dso, filename, map) < 0)
1123 return -1; 1173 return -1;
1124 1174
1175 if (kallsyms__delta(map, filename, &delta))
1176 return -1;
1177
1125 symbols__fixup_duplicate(&dso->symbols[map->type]); 1178 symbols__fixup_duplicate(&dso->symbols[map->type]);
1126 symbols__fixup_end(&dso->symbols[map->type]); 1179 symbols__fixup_end(&dso->symbols[map->type]);
1127 1180
@@ -1133,7 +1186,7 @@ int dso__load_kallsyms(struct dso *dso, const char *filename,
1133 if (!dso__load_kcore(dso, map, filename)) 1186 if (!dso__load_kcore(dso, map, filename))
1134 return dso__split_kallsyms_for_kcore(dso, map, filter); 1187 return dso__split_kallsyms_for_kcore(dso, map, filter);
1135 else 1188 else
1136 return dso__split_kallsyms(dso, map, filter); 1189 return dso__split_kallsyms(dso, map, delta, filter);
1137} 1190}
1138 1191
1139static int dso__load_perf_map(struct dso *dso, struct map *map, 1192static int dso__load_perf_map(struct dso *dso, struct map *map,
@@ -1198,6 +1251,46 @@ out_failure:
1198 return -1; 1251 return -1;
1199} 1252}
1200 1253
1254static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
1255 enum dso_binary_type type)
1256{
1257 switch (type) {
1258 case DSO_BINARY_TYPE__JAVA_JIT:
1259 case DSO_BINARY_TYPE__DEBUGLINK:
1260 case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
1261 case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
1262 case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
1263 case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
1264 case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
1265 return !kmod && dso->kernel == DSO_TYPE_USER;
1266
1267 case DSO_BINARY_TYPE__KALLSYMS:
1268 case DSO_BINARY_TYPE__VMLINUX:
1269 case DSO_BINARY_TYPE__KCORE:
1270 return dso->kernel == DSO_TYPE_KERNEL;
1271
1272 case DSO_BINARY_TYPE__GUEST_KALLSYMS:
1273 case DSO_BINARY_TYPE__GUEST_VMLINUX:
1274 case DSO_BINARY_TYPE__GUEST_KCORE:
1275 return dso->kernel == DSO_TYPE_GUEST_KERNEL;
1276
1277 case DSO_BINARY_TYPE__GUEST_KMODULE:
1278 case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
1279 /*
1280 * kernel modules know their symtab type - it's set when
1281 * creating a module dso in machine__new_module().
1282 */
1283 return kmod && dso->symtab_type == type;
1284
1285 case DSO_BINARY_TYPE__BUILD_ID_CACHE:
1286 return true;
1287
1288 case DSO_BINARY_TYPE__NOT_FOUND:
1289 default:
1290 return false;
1291 }
1292}
1293
1201int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) 1294int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
1202{ 1295{
1203 char *name; 1296 char *name;
@@ -1208,6 +1301,7 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
1208 int ss_pos = 0; 1301 int ss_pos = 0;
1209 struct symsrc ss_[2]; 1302 struct symsrc ss_[2];
1210 struct symsrc *syms_ss = NULL, *runtime_ss = NULL; 1303 struct symsrc *syms_ss = NULL, *runtime_ss = NULL;
1304 bool kmod;
1211 1305
1212 dso__set_loaded(dso, map->type); 1306 dso__set_loaded(dso, map->type);
1213 1307
@@ -1248,7 +1342,11 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
1248 if (!name) 1342 if (!name)
1249 return -1; 1343 return -1;
1250 1344
1251 /* Iterate over candidate debug images. 1345 kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
1346 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE;
1347
1348 /*
1349 * Iterate over candidate debug images.
1252 * Keep track of "interesting" ones (those which have a symtab, dynsym, 1350 * Keep track of "interesting" ones (those which have a symtab, dynsym,
1253 * and/or opd section) for processing. 1351 * and/or opd section) for processing.
1254 */ 1352 */
@@ -1258,6 +1356,9 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
1258 1356
1259 enum dso_binary_type symtab_type = binary_type_symtab[i]; 1357 enum dso_binary_type symtab_type = binary_type_symtab[i];
1260 1358
1359 if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
1360 continue;
1361
1261 if (dso__read_binary_type_filename(dso, symtab_type, 1362 if (dso__read_binary_type_filename(dso, symtab_type,
1262 root_dir, name, PATH_MAX)) 1363 root_dir, name, PATH_MAX))
1263 continue; 1364 continue;
@@ -1283,6 +1384,8 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
1283 1384
1284 if (syms_ss && runtime_ss) 1385 if (syms_ss && runtime_ss)
1285 break; 1386 break;
1387 } else {
1388 symsrc__destroy(ss);
1286 } 1389 }
1287 1390
1288 } 1391 }
@@ -1298,15 +1401,10 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
1298 if (!runtime_ss && syms_ss) 1401 if (!runtime_ss && syms_ss)
1299 runtime_ss = syms_ss; 1402 runtime_ss = syms_ss;
1300 1403
1301 if (syms_ss) { 1404 if (syms_ss)
1302 int km; 1405 ret = dso__load_sym(dso, map, syms_ss, runtime_ss, filter, kmod);
1303 1406 else
1304 km = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
1305 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE;
1306 ret = dso__load_sym(dso, map, syms_ss, runtime_ss, filter, km);
1307 } else {
1308 ret = -1; 1407 ret = -1;
1309 }
1310 1408
1311 if (ret > 0) { 1409 if (ret > 0) {
1312 int nr_plt; 1410 int nr_plt;
@@ -1424,7 +1522,7 @@ static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
1424 continue; 1522 continue;
1425 scnprintf(kallsyms_filename, sizeof(kallsyms_filename), 1523 scnprintf(kallsyms_filename, sizeof(kallsyms_filename),
1426 "%s/%s/kallsyms", dir, dent->d_name); 1524 "%s/%s/kallsyms", dir, dent->d_name);
1427 if (!validate_kcore_modules(kallsyms_filename, map)) { 1525 if (!validate_kcore_addresses(kallsyms_filename, map)) {
1428 strlcpy(dir, kallsyms_filename, dir_sz); 1526 strlcpy(dir, kallsyms_filename, dir_sz);
1429 ret = 0; 1527 ret = 0;
1430 break; 1528 break;
@@ -1479,7 +1577,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
1479 if (fd != -1) { 1577 if (fd != -1) {
1480 close(fd); 1578 close(fd);
1481 /* If module maps match go with /proc/kallsyms */ 1579 /* If module maps match go with /proc/kallsyms */
1482 if (!validate_kcore_modules("/proc/kallsyms", map)) 1580 if (!validate_kcore_addresses("/proc/kallsyms", map))
1483 goto proc_kallsyms; 1581 goto proc_kallsyms;
1484 } 1582 }
1485 1583
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index fffe2888a1c7..501e4e722e8e 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -79,6 +79,17 @@ struct symbol {
79void symbol__delete(struct symbol *sym); 79void symbol__delete(struct symbol *sym);
80void symbols__delete(struct rb_root *symbols); 80void symbols__delete(struct rb_root *symbols);
81 81
82/* symbols__for_each_entry - iterate over symbols (rb_root)
83 *
84 * @symbols: the rb_root of symbols
85 * @pos: the 'struct symbol *' to use as a loop cursor
86 * @nd: the 'struct rb_node *' to use as a temporary storage
87 */
88#define symbols__for_each_entry(symbols, pos, nd) \
89 for (nd = rb_first(symbols); \
90 nd && (pos = rb_entry(nd, struct symbol, rb_node)); \
91 nd = rb_next(nd))
92
82static inline size_t symbol__size(const struct symbol *sym) 93static inline size_t symbol__size(const struct symbol *sym)
83{ 94{
84 return sym->end - sym->start + 1; 95 return sym->end - sym->start + 1;
@@ -175,7 +186,7 @@ struct addr_location {
175 struct symbol *sym; 186 struct symbol *sym;
176 u64 addr; 187 u64 addr;
177 char level; 188 char level;
178 bool filtered; 189 u8 filtered;
179 u8 cpumode; 190 u8 cpumode;
180 s32 cpu; 191 s32 cpu;
181}; 192};
@@ -223,7 +234,6 @@ struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
223 u64 addr); 234 u64 addr);
224struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, 235struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
225 const char *name); 236 const char *name);
226struct symbol *dso__first_symbol(struct dso *dso, enum map_type type);
227 237
228int filename__read_build_id(const char *filename, void *bf, size_t size); 238int filename__read_build_id(const char *filename, void *bf, size_t size);
229int sysfs__read_build_id(const char *filename, void *bf, size_t size); 239int sysfs__read_build_id(const char *filename, void *bf, size_t size);
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 0358882c8910..3ce0498bdae6 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -142,3 +142,24 @@ int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp)
142 142
143 return 0; 143 return 0;
144} 144}
145
146void thread__find_cpumode_addr_location(struct thread *thread,
147 struct machine *machine,
148 enum map_type type, u64 addr,
149 struct addr_location *al)
150{
151 size_t i;
152 const u8 const cpumodes[] = {
153 PERF_RECORD_MISC_USER,
154 PERF_RECORD_MISC_KERNEL,
155 PERF_RECORD_MISC_GUEST_USER,
156 PERF_RECORD_MISC_GUEST_KERNEL
157 };
158
159 for (i = 0; i < ARRAY_SIZE(cpumodes); i++) {
160 thread__find_addr_location(thread, machine, cpumodes[i], type,
161 addr, al);
162 if (al->map)
163 break;
164 }
165}
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 5b856bf942e1..9b29f085aede 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -44,12 +44,6 @@ void thread__insert_map(struct thread *thread, struct map *map);
44int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp); 44int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
45size_t thread__fprintf(struct thread *thread, FILE *fp); 45size_t thread__fprintf(struct thread *thread, FILE *fp);
46 46
47static inline struct map *thread__find_map(struct thread *thread,
48 enum map_type type, u64 addr)
49{
50 return thread ? map_groups__find(&thread->mg, type, addr) : NULL;
51}
52
53void thread__find_addr_map(struct thread *thread, struct machine *machine, 47void thread__find_addr_map(struct thread *thread, struct machine *machine,
54 u8 cpumode, enum map_type type, u64 addr, 48 u8 cpumode, enum map_type type, u64 addr,
55 struct addr_location *al); 49 struct addr_location *al);
@@ -58,6 +52,11 @@ void thread__find_addr_location(struct thread *thread, struct machine *machine,
58 u8 cpumode, enum map_type type, u64 addr, 52 u8 cpumode, enum map_type type, u64 addr,
59 struct addr_location *al); 53 struct addr_location *al);
60 54
55void thread__find_cpumode_addr_location(struct thread *thread,
56 struct machine *machine,
57 enum map_type type, u64 addr,
58 struct addr_location *al);
59
61static inline void *thread__priv(struct thread *thread) 60static inline void *thread__priv(struct thread *thread)
62{ 61{
63 return thread->priv; 62 return thread->priv;
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index e0d6d07f6848..c36636fd825b 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -126,6 +126,7 @@ void event_format__print(struct event_format *event,
126 trace_seq_init(&s); 126 trace_seq_init(&s);
127 pevent_event_info(&s, event, &record); 127 pevent_event_info(&s, event, &record);
128 trace_seq_do_printf(&s); 128 trace_seq_do_printf(&s);
129 trace_seq_destroy(&s);
129} 130}
130 131
131void parse_proc_kallsyms(struct pevent *pevent, 132void parse_proc_kallsyms(struct pevent *pevent,
diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
new file mode 100644
index 000000000000..67db73ec3dab
--- /dev/null
+++ b/tools/perf/util/unwind-libdw.c
@@ -0,0 +1,210 @@
1#include <linux/compiler.h>
2#include <elfutils/libdw.h>
3#include <elfutils/libdwfl.h>
4#include <inttypes.h>
5#include <errno.h>
6#include "unwind.h"
7#include "unwind-libdw.h"
8#include "machine.h"
9#include "thread.h"
10#include "types.h"
11#include "event.h"
12#include "perf_regs.h"
13
14static char *debuginfo_path;
15
16static const Dwfl_Callbacks offline_callbacks = {
17 .find_debuginfo = dwfl_standard_find_debuginfo,
18 .debuginfo_path = &debuginfo_path,
19 .section_address = dwfl_offline_section_address,
20};
21
22static int __report_module(struct addr_location *al, u64 ip,
23 struct unwind_info *ui)
24{
25 Dwfl_Module *mod;
26 struct dso *dso = NULL;
27
28 thread__find_addr_location(ui->thread, ui->machine,
29 PERF_RECORD_MISC_USER,
30 MAP__FUNCTION, ip, al);
31
32 if (al->map)
33 dso = al->map->dso;
34
35 if (!dso)
36 return 0;
37
38 mod = dwfl_addrmodule(ui->dwfl, ip);
39 if (!mod)
40 mod = dwfl_report_elf(ui->dwfl, dso->short_name,
41 dso->long_name, -1, al->map->start,
42 false);
43
44 return mod && dwfl_addrmodule(ui->dwfl, ip) == mod ? 0 : -1;
45}
46
47static int report_module(u64 ip, struct unwind_info *ui)
48{
49 struct addr_location al;
50
51 return __report_module(&al, ip, ui);
52}
53
54static int entry(u64 ip, struct unwind_info *ui)
55
56{
57 struct unwind_entry e;
58 struct addr_location al;
59
60 if (__report_module(&al, ip, ui))
61 return -1;
62
63 e.ip = ip;
64 e.map = al.map;
65 e.sym = al.sym;
66
67 pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
68 al.sym ? al.sym->name : "''",
69 ip,
70 al.map ? al.map->map_ip(al.map, ip) : (u64) 0);
71
72 return ui->cb(&e, ui->arg);
73}
74
75static pid_t next_thread(Dwfl *dwfl, void *arg, void **thread_argp)
76{
77 /* We want only single thread to be processed. */
78 if (*thread_argp != NULL)
79 return 0;
80
81 *thread_argp = arg;
82 return dwfl_pid(dwfl);
83}
84
85static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr,
86 Dwarf_Word *data)
87{
88 struct addr_location al;
89 ssize_t size;
90
91 thread__find_addr_map(ui->thread, ui->machine, PERF_RECORD_MISC_USER,
92 MAP__FUNCTION, addr, &al);
93 if (!al.map) {
94 pr_debug("unwind: no map for %lx\n", (unsigned long)addr);
95 return -1;
96 }
97
98 if (!al.map->dso)
99 return -1;
100
101 size = dso__data_read_addr(al.map->dso, al.map, ui->machine,
102 addr, (u8 *) data, sizeof(*data));
103
104 return !(size == sizeof(*data));
105}
106
107static bool memory_read(Dwfl *dwfl __maybe_unused, Dwarf_Addr addr, Dwarf_Word *result,
108 void *arg)
109{
110 struct unwind_info *ui = arg;
111 struct stack_dump *stack = &ui->sample->user_stack;
112 u64 start, end;
113 int offset;
114 int ret;
115
116 ret = perf_reg_value(&start, &ui->sample->user_regs, PERF_REG_SP);
117 if (ret)
118 return false;
119
120 end = start + stack->size;
121
122 /* Check overflow. */
123 if (addr + sizeof(Dwarf_Word) < addr)
124 return false;
125
126 if (addr < start || addr + sizeof(Dwarf_Word) > end) {
127 ret = access_dso_mem(ui, addr, result);
128 if (ret) {
129 pr_debug("unwind: access_mem 0x%" PRIx64 " not inside range"
130 " 0x%" PRIx64 "-0x%" PRIx64 "\n",
131 addr, start, end);
132 return false;
133 }
134 return true;
135 }
136
137 offset = addr - start;
138 *result = *(Dwarf_Word *)&stack->data[offset];
139 pr_debug("unwind: access_mem addr 0x%" PRIx64 ", val %lx, offset %d\n",
140 addr, (unsigned long)*result, offset);
141 return true;
142}
143
144static const Dwfl_Thread_Callbacks callbacks = {
145 .next_thread = next_thread,
146 .memory_read = memory_read,
147 .set_initial_registers = libdw__arch_set_initial_registers,
148};
149
150static int
151frame_callback(Dwfl_Frame *state, void *arg)
152{
153 struct unwind_info *ui = arg;
154 Dwarf_Addr pc;
155
156 if (!dwfl_frame_pc(state, &pc, NULL)) {
157 pr_err("%s", dwfl_errmsg(-1));
158 return DWARF_CB_ABORT;
159 }
160
161 return entry(pc, ui) || !(--ui->max_stack) ?
162 DWARF_CB_ABORT : DWARF_CB_OK;
163}
164
165int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
166 struct machine *machine, struct thread *thread,
167 struct perf_sample *data,
168 int max_stack)
169{
170 struct unwind_info ui = {
171 .sample = data,
172 .thread = thread,
173 .machine = machine,
174 .cb = cb,
175 .arg = arg,
176 .max_stack = max_stack,
177 };
178 Dwarf_Word ip;
179 int err = -EINVAL;
180
181 if (!data->user_regs.regs)
182 return -EINVAL;
183
184 ui.dwfl = dwfl_begin(&offline_callbacks);
185 if (!ui.dwfl)
186 goto out;
187
188 err = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP);
189 if (err)
190 goto out;
191
192 err = report_module(ip, &ui);
193 if (err)
194 goto out;
195
196 if (!dwfl_attach_state(ui.dwfl, EM_NONE, thread->tid, &callbacks, &ui))
197 goto out;
198
199 err = dwfl_getthread_frames(ui.dwfl, thread->tid, frame_callback, &ui);
200
201 if (err && !ui.max_stack)
202 err = 0;
203
204 out:
205 if (err)
206 pr_debug("unwind: failed with '%s'\n", dwfl_errmsg(-1));
207
208 dwfl_end(ui.dwfl);
209 return 0;
210}
diff --git a/tools/perf/util/unwind-libdw.h b/tools/perf/util/unwind-libdw.h
new file mode 100644
index 000000000000..417a1426f3ad
--- /dev/null
+++ b/tools/perf/util/unwind-libdw.h
@@ -0,0 +1,21 @@
1#ifndef __PERF_UNWIND_LIBDW_H
2#define __PERF_UNWIND_LIBDW_H
3
4#include <elfutils/libdwfl.h>
5#include "event.h"
6#include "thread.h"
7#include "unwind.h"
8
9bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg);
10
11struct unwind_info {
12 Dwfl *dwfl;
13 struct perf_sample *sample;
14 struct machine *machine;
15 struct thread *thread;
16 unwind_entry_cb_t cb;
17 void *arg;
18 int max_stack;
19};
20
21#endif /* __PERF_UNWIND_LIBDW_H */
diff --git a/tools/perf/util/unwind.c b/tools/perf/util/unwind-libunwind.c
index 742f23bf35ff..bd5768d74f01 100644
--- a/tools/perf/util/unwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -86,7 +86,6 @@ struct unwind_info {
86 struct perf_sample *sample; 86 struct perf_sample *sample;
87 struct machine *machine; 87 struct machine *machine;
88 struct thread *thread; 88 struct thread *thread;
89 u64 sample_uregs;
90}; 89};
91 90
92#define dw_read(ptr, type, end) ({ \ 91#define dw_read(ptr, type, end) ({ \
@@ -391,30 +390,13 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
391 return !(size == sizeof(*data)); 390 return !(size == sizeof(*data));
392} 391}
393 392
394static int reg_value(unw_word_t *valp, struct regs_dump *regs, int id,
395 u64 sample_regs)
396{
397 int i, idx = 0;
398
399 if (!(sample_regs & (1 << id)))
400 return -EINVAL;
401
402 for (i = 0; i < id; i++) {
403 if (sample_regs & (1 << i))
404 idx++;
405 }
406
407 *valp = regs->regs[idx];
408 return 0;
409}
410
411static int access_mem(unw_addr_space_t __maybe_unused as, 393static int access_mem(unw_addr_space_t __maybe_unused as,
412 unw_word_t addr, unw_word_t *valp, 394 unw_word_t addr, unw_word_t *valp,
413 int __write, void *arg) 395 int __write, void *arg)
414{ 396{
415 struct unwind_info *ui = arg; 397 struct unwind_info *ui = arg;
416 struct stack_dump *stack = &ui->sample->user_stack; 398 struct stack_dump *stack = &ui->sample->user_stack;
417 unw_word_t start, end; 399 u64 start, end;
418 int offset; 400 int offset;
419 int ret; 401 int ret;
420 402
@@ -424,8 +406,7 @@ static int access_mem(unw_addr_space_t __maybe_unused as,
424 return 0; 406 return 0;
425 } 407 }
426 408
427 ret = reg_value(&start, &ui->sample->user_regs, PERF_REG_SP, 409 ret = perf_reg_value(&start, &ui->sample->user_regs, PERF_REG_SP);
428 ui->sample_uregs);
429 if (ret) 410 if (ret)
430 return ret; 411 return ret;
431 412
@@ -438,8 +419,9 @@ static int access_mem(unw_addr_space_t __maybe_unused as,
438 if (addr < start || addr + sizeof(unw_word_t) >= end) { 419 if (addr < start || addr + sizeof(unw_word_t) >= end) {
439 ret = access_dso_mem(ui, addr, valp); 420 ret = access_dso_mem(ui, addr, valp);
440 if (ret) { 421 if (ret) {
441 pr_debug("unwind: access_mem %p not inside range %p-%p\n", 422 pr_debug("unwind: access_mem %p not inside range"
442 (void *)addr, (void *)start, (void *)end); 423 " 0x%" PRIx64 "-0x%" PRIx64 "\n",
424 (void *) addr, start, end);
443 *valp = 0; 425 *valp = 0;
444 return ret; 426 return ret;
445 } 427 }
@@ -448,8 +430,8 @@ static int access_mem(unw_addr_space_t __maybe_unused as,
448 430
449 offset = addr - start; 431 offset = addr - start;
450 *valp = *(unw_word_t *)&stack->data[offset]; 432 *valp = *(unw_word_t *)&stack->data[offset];
451 pr_debug("unwind: access_mem addr %p, val %lx, offset %d\n", 433 pr_debug("unwind: access_mem addr %p val %lx, offset %d\n",
452 (void *)addr, (unsigned long)*valp, offset); 434 (void *) addr, (unsigned long)*valp, offset);
453 return 0; 435 return 0;
454} 436}
455 437
@@ -459,6 +441,7 @@ static int access_reg(unw_addr_space_t __maybe_unused as,
459{ 441{
460 struct unwind_info *ui = arg; 442 struct unwind_info *ui = arg;
461 int id, ret; 443 int id, ret;
444 u64 val;
462 445
463 /* Don't support write, I suspect we don't need it. */ 446 /* Don't support write, I suspect we don't need it. */
464 if (__write) { 447 if (__write) {
@@ -471,16 +454,17 @@ static int access_reg(unw_addr_space_t __maybe_unused as,
471 return 0; 454 return 0;
472 } 455 }
473 456
474 id = unwind__arch_reg_id(regnum); 457 id = libunwind__arch_reg_id(regnum);
475 if (id < 0) 458 if (id < 0)
476 return -EINVAL; 459 return -EINVAL;
477 460
478 ret = reg_value(valp, &ui->sample->user_regs, id, ui->sample_uregs); 461 ret = perf_reg_value(&val, &ui->sample->user_regs, id);
479 if (ret) { 462 if (ret) {
480 pr_err("unwind: can't read reg %d\n", regnum); 463 pr_err("unwind: can't read reg %d\n", regnum);
481 return ret; 464 return ret;
482 } 465 }
483 466
467 *valp = (unw_word_t) val;
484 pr_debug("unwind: reg %d, val %lx\n", regnum, (unsigned long)*valp); 468 pr_debug("unwind: reg %d, val %lx\n", regnum, (unsigned long)*valp);
485 return 0; 469 return 0;
486} 470}
@@ -563,7 +547,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
563 unw_word_t ip; 547 unw_word_t ip;
564 548
565 unw_get_reg(&c, UNW_REG_IP, &ip); 549 unw_get_reg(&c, UNW_REG_IP, &ip);
566 ret = entry(ip, ui->thread, ui->machine, cb, arg); 550 ret = ip ? entry(ip, ui->thread, ui->machine, cb, arg) : 0;
567 } 551 }
568 552
569 unw_destroy_addr_space(addr_space); 553 unw_destroy_addr_space(addr_space);
@@ -572,13 +556,11 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
572 556
573int unwind__get_entries(unwind_entry_cb_t cb, void *arg, 557int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
574 struct machine *machine, struct thread *thread, 558 struct machine *machine, struct thread *thread,
575 u64 sample_uregs, struct perf_sample *data, 559 struct perf_sample *data, int max_stack)
576 int max_stack)
577{ 560{
578 unw_word_t ip; 561 u64 ip;
579 struct unwind_info ui = { 562 struct unwind_info ui = {
580 .sample = data, 563 .sample = data,
581 .sample_uregs = sample_uregs,
582 .thread = thread, 564 .thread = thread,
583 .machine = machine, 565 .machine = machine,
584 }; 566 };
@@ -587,7 +569,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
587 if (!data->user_regs.regs) 569 if (!data->user_regs.regs)
588 return -EINVAL; 570 return -EINVAL;
589 571
590 ret = reg_value(&ip, &data->user_regs, PERF_REG_IP, sample_uregs); 572 ret = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP);
591 if (ret) 573 if (ret)
592 return ret; 574 return ret;
593 575
@@ -595,5 +577,5 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
595 if (ret) 577 if (ret)
596 return -ENOMEM; 578 return -ENOMEM;
597 579
598 return get_entries(&ui, cb, arg, max_stack); 580 return --max_stack > 0 ? get_entries(&ui, cb, arg, max_stack) : 0;
599} 581}
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index d5966f49e22c..b031316f221a 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -13,24 +13,25 @@ struct unwind_entry {
13 13
14typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg); 14typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
15 15
16#ifdef HAVE_LIBUNWIND_SUPPORT 16#ifdef HAVE_DWARF_UNWIND_SUPPORT
17int unwind__get_entries(unwind_entry_cb_t cb, void *arg, 17int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
18 struct machine *machine, 18 struct machine *machine,
19 struct thread *thread, 19 struct thread *thread,
20 u64 sample_uregs,
21 struct perf_sample *data, int max_stack); 20 struct perf_sample *data, int max_stack);
22int unwind__arch_reg_id(int regnum); 21/* libunwind specific */
22#ifdef HAVE_LIBUNWIND_SUPPORT
23int libunwind__arch_reg_id(int regnum);
24#endif
23#else 25#else
24static inline int 26static inline int
25unwind__get_entries(unwind_entry_cb_t cb __maybe_unused, 27unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
26 void *arg __maybe_unused, 28 void *arg __maybe_unused,
27 struct machine *machine __maybe_unused, 29 struct machine *machine __maybe_unused,
28 struct thread *thread __maybe_unused, 30 struct thread *thread __maybe_unused,
29 u64 sample_uregs __maybe_unused,
30 struct perf_sample *data __maybe_unused, 31 struct perf_sample *data __maybe_unused,
31 int max_stack __maybe_unused) 32 int max_stack __maybe_unused)
32{ 33{
33 return 0; 34 return 0;
34} 35}
35#endif /* HAVE_LIBUNWIND_SUPPORT */ 36#endif /* HAVE_DWARF_UNWIND_SUPPORT */
36#endif /* __UNWIND_H */ 37#endif /* __UNWIND_H */
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 42ad667bb317..9f66549562bd 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -1,6 +1,6 @@
1#include "../perf.h" 1#include "../perf.h"
2#include "util.h" 2#include "util.h"
3#include "fs.h" 3#include <api/fs/fs.h>
4#include <sys/mman.h> 4#include <sys/mman.h>
5#ifdef HAVE_BACKTRACE_SUPPORT 5#ifdef HAVE_BACKTRACE_SUPPORT
6#include <execinfo.h> 6#include <execinfo.h>
diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
index d66418237d21..aa290c0de6f5 100644
--- a/tools/testing/selftests/ipc/msgque.c
+++ b/tools/testing/selftests/ipc/msgque.c
@@ -201,6 +201,7 @@ int main(int argc, char **argv)
201 201
202 msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666); 202 msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666);
203 if (msgque.msq_id == -1) { 203 if (msgque.msq_id == -1) {
204 err = -errno;
204 printf("Can't create queue\n"); 205 printf("Can't create queue\n");
205 goto err_out; 206 goto err_out;
206 } 207 }
diff --git a/tools/testing/selftests/rcutorture/bin/functions.sh b/tools/testing/selftests/rcutorture/bin/functions.sh
index 587561d7c035..9b17e810ddc3 100644
--- a/tools/testing/selftests/rcutorture/bin/functions.sh
+++ b/tools/testing/selftests/rcutorture/bin/functions.sh
@@ -96,6 +96,7 @@ identify_qemu () {
96 echo qemu-system-ppc64 96 echo qemu-system-ppc64
97 else 97 else
98 echo Cannot figure out what qemu command to use! 1>&2 98 echo Cannot figure out what qemu command to use! 1>&2
99 echo file $1 output: $u
99 # Usually this will be one of /usr/bin/qemu-system-* 100 # Usually this will be one of /usr/bin/qemu-system-*
100 # Use RCU_QEMU_CMD environment variable or appropriate 101 # Use RCU_QEMU_CMD environment variable or appropriate
101 # argument to top-level script. 102 # argument to top-level script.
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck-lock.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck-lock.sh
new file mode 100755
index 000000000000..829186e19eb1
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck-lock.sh
@@ -0,0 +1,51 @@
1#!/bin/bash
2#
3# Analyze a given results directory for locktorture progress.
4#
5# Usage: sh kvm-recheck-lock.sh resdir
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, you can access it online at
19# http://www.gnu.org/licenses/gpl-2.0.html.
20#
21# Copyright (C) IBM Corporation, 2014
22#
23# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
24
25i="$1"
26if test -d $i
27then
28 :
29else
30 echo Unreadable results directory: $i
31 exit 1
32fi
33
34configfile=`echo $i | sed -e 's/^.*\///'`
35ncs=`grep "Writes: Total:" $i/console.log 2> /dev/null | tail -1 | sed -e 's/^.* Total: //' -e 's/ .*$//'`
36if test -z "$ncs"
37then
38 echo $configfile
39else
40 title="$configfile ------- $ncs acquisitions/releases"
41 dur=`sed -e 's/^.* locktorture.shutdown_secs=//' -e 's/ .*$//' < $i/qemu-cmd 2> /dev/null`
42 if test -z "$dur"
43 then
44 :
45 else
46 ncsps=`awk -v ncs=$ncs -v dur=$dur '
47 BEGIN { print ncs / dur }' < /dev/null`
48 title="$title ($ncsps per second)"
49 fi
50 echo $title
51fi
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck-rcu.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck-rcu.sh
new file mode 100755
index 000000000000..d75b1dc5ae53
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck-rcu.sh
@@ -0,0 +1,51 @@
1#!/bin/bash
2#
3# Analyze a given results directory for rcutorture progress.
4#
5# Usage: sh kvm-recheck-rcu.sh resdir
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, you can access it online at
19# http://www.gnu.org/licenses/gpl-2.0.html.
20#
21# Copyright (C) IBM Corporation, 2014
22#
23# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
24
25i="$1"
26if test -d $i
27then
28 :
29else
30 echo Unreadable results directory: $i
31 exit 1
32fi
33
34configfile=`echo $i | sed -e 's/^.*\///'`
35ngps=`grep ver: $i/console.log 2> /dev/null | tail -1 | sed -e 's/^.* ver: //' -e 's/ .*$//'`
36if test -z "$ngps"
37then
38 echo $configfile
39else
40 title="$configfile ------- $ngps grace periods"
41 dur=`sed -e 's/^.* rcutorture.shutdown_secs=//' -e 's/ .*$//' < $i/qemu-cmd 2> /dev/null`
42 if test -z "$dur"
43 then
44 :
45 else
46 ngpsps=`awk -v ngps=$ngps -v dur=$dur '
47 BEGIN { print ngps / dur }' < /dev/null`
48 title="$title ($ngpsps per second)"
49 fi
50 echo $title
51fi
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
index baef09f3469b..a44daaa259a9 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
@@ -1,6 +1,6 @@
1#!/bin/bash 1#!/bin/bash
2# 2#
3# Given the results directories for previous KVM runs of rcutorture, 3# Given the results directories for previous KVM-based torture runs,
4# check the build and console output for errors. Given a directory 4# check the build and console output for errors. Given a directory
5# containing results directories, this recursively checks them all. 5# containing results directories, this recursively checks them all.
6# 6#
@@ -27,11 +27,18 @@
27PATH=`pwd`/tools/testing/selftests/rcutorture/bin:$PATH; export PATH 27PATH=`pwd`/tools/testing/selftests/rcutorture/bin:$PATH; export PATH
28for rd in "$@" 28for rd in "$@"
29do 29do
30 firsttime=1
30 dirs=`find $rd -name Make.defconfig.out -print | sort | sed -e 's,/[^/]*$,,' | sort -u` 31 dirs=`find $rd -name Make.defconfig.out -print | sort | sed -e 's,/[^/]*$,,' | sort -u`
31 for i in $dirs 32 for i in $dirs
32 do 33 do
33 configfile=`echo $i | sed -e 's/^.*\///'` 34 if test -n "$firsttime"
34 echo $configfile 35 then
36 firsttime=""
37 resdir=`echo $i | sed -e 's,/$,,' -e 's,/[^/]*$,,'`
38 head -1 $resdir/log
39 fi
40 TORTURE_SUITE="`cat $i/../TORTURE_SUITE`"
41 kvm-recheck-${TORTURE_SUITE}.sh $i
35 configcheck.sh $i/.config $i/ConfigFragment 42 configcheck.sh $i/.config $i/ConfigFragment
36 parse-build.sh $i/Make.out $configfile 43 parse-build.sh $i/Make.out $configfile
37 parse-rcutorture.sh $i/console.log $configfile 44 parse-rcutorture.sh $i/console.log $configfile
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-rcu.sh b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index 151b23788935..94b28bb37d36 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-rcu.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -6,15 +6,15 @@
6# Execute this in the source tree. Do not run it as a background task 6# Execute this in the source tree. Do not run it as a background task
7# because qemu does not seem to like that much. 7# because qemu does not seem to like that much.
8# 8#
9# Usage: sh kvm-test-1-rcu.sh config builddir resdir minutes qemu-args bootargs 9# Usage: sh kvm-test-1-run.sh config builddir resdir minutes qemu-args boot_args
10# 10#
11# qemu-args defaults to "" -- you will want "-nographic" if running headless. 11# qemu-args defaults to "-nographic", along with arguments specifying the
12# bootargs defaults to "root=/dev/sda noapic selinux=0 console=ttyS0" 12# number of CPUs and other options generated from
13# "initcall_debug debug rcutorture.stat_interval=15" 13# the underlying CPU architecture.
14# "rcutorture.shutdown_secs=$((minutes * 60))" 14# boot_args defaults to value returned by the per_version_boot_params
15# "rcutorture.rcutorture_runnable=1" 15# shell function.
16# 16#
17# Anything you specify for either qemu-args or bootargs is appended to 17# Anything you specify for either qemu-args or boot_args is appended to
18# the default values. The "-smp" value is deduced from the contents of 18# the default values. The "-smp" value is deduced from the contents of
19# the config fragment. 19# the config fragment.
20# 20#
@@ -40,32 +40,34 @@
40 40
41grace=120 41grace=120
42 42
43T=/tmp/kvm-test-1-rcu.sh.$$ 43T=/tmp/kvm-test-1-run.sh.$$
44trap 'rm -rf $T' 0 44trap 'rm -rf $T' 0
45 45
46. $KVM/bin/functions.sh 46. $KVM/bin/functions.sh
47. $KVPATH/ver_functions.sh 47. $KVPATH/ver_functions.sh
48 48
49config_template=${1} 49config_template=${1}
50config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
50title=`echo $config_template | sed -e 's/^.*\///'` 51title=`echo $config_template | sed -e 's/^.*\///'`
51builddir=${2} 52builddir=${2}
52if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir" 53if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir"
53then 54then
54 echo "kvm-test-1-rcu.sh :$builddir: Not a writable directory, cannot build into it" 55 echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it"
55 exit 1 56 exit 1
56fi 57fi
57resdir=${3} 58resdir=${3}
58if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir" 59if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
59then 60then
60 echo "kvm-test-1-rcu.sh :$resdir: Not a writable directory, cannot build into it" 61 echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
61 exit 1 62 exit 1
62fi 63fi
63cp $config_template $resdir/ConfigFragment 64cp $config_template $resdir/ConfigFragment
64echo ' ---' `date`: Starting build 65echo ' ---' `date`: Starting build
65echo ' ---' Kconfig fragment at: $config_template >> $resdir/log 66echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
66cat << '___EOF___' >> $T 67if test -r "$config_dir/CFcommon"
67CONFIG_RCU_TORTURE_TEST=y 68then
68___EOF___ 69 cat < $config_dir/CFcommon >> $T
70fi
69# Optimizations below this point 71# Optimizations below this point
70# CONFIG_USB=n 72# CONFIG_USB=n
71# CONFIG_SECURITY=n 73# CONFIG_SECURITY=n
@@ -96,11 +98,23 @@ then
96 cp $builddir/.config $resdir 98 cp $builddir/.config $resdir
97 cp $builddir/arch/x86/boot/bzImage $resdir 99 cp $builddir/arch/x86/boot/bzImage $resdir
98 parse-build.sh $resdir/Make.out $title 100 parse-build.sh $resdir/Make.out $title
101 if test -f $builddir.wait
102 then
103 mv $builddir.wait $builddir.ready
104 fi
99else 105else
100 cp $builddir/Make*.out $resdir 106 cp $builddir/Make*.out $resdir
101 echo Build failed, not running KVM, see $resdir. 107 echo Build failed, not running KVM, see $resdir.
108 if test -f $builddir.wait
109 then
110 mv $builddir.wait $builddir.ready
111 fi
102 exit 1 112 exit 1
103fi 113fi
114while test -f $builddir.ready
115do
116 sleep 1
117done
104minutes=$4 118minutes=$4
105seconds=$(($minutes * 60)) 119seconds=$(($minutes * 60))
106qemu_args=$5 120qemu_args=$5
@@ -111,9 +125,10 @@ kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
111echo ' ---' `date`: Starting kernel 125echo ' ---' `date`: Starting kernel
112 126
113# Determine the appropriate flavor of qemu command. 127# Determine the appropriate flavor of qemu command.
114QEMU="`identify_qemu $builddir/vmlinux.o`" 128QEMU="`identify_qemu $builddir/vmlinux`"
115 129
116# Generate -smp qemu argument. 130# Generate -smp qemu argument.
131qemu_args="-nographic $qemu_args"
117cpu_count=`configNR_CPUS.sh $config_template` 132cpu_count=`configNR_CPUS.sh $config_template`
118vcpus=`identify_qemu_vcpus` 133vcpus=`identify_qemu_vcpus`
119if test $cpu_count -gt $vcpus 134if test $cpu_count -gt $vcpus
@@ -133,12 +148,8 @@ qemu_append="`identify_qemu_append "$QEMU"`"
133 148
134# Pull in Kconfig-fragment boot parameters 149# Pull in Kconfig-fragment boot parameters
135boot_args="`configfrag_boot_params "$boot_args" "$config_template"`" 150boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
136# Generate CPU-hotplug boot parameters 151# Generate kernel-version-specific boot parameters
137boot_args="`rcutorture_param_onoff "$boot_args" $builddir/.config`" 152boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`"
138# Generate rcu_barrier() boot parameter
139boot_args="`rcutorture_param_n_barrier_cbs "$boot_args"`"
140# Pull in standard rcutorture boot arguments
141boot_args="$boot_args rcutorture.stat_interval=15 rcutorture.shutdown_secs=$seconds rcutorture.rcutorture_runnable=1"
142 153
143echo $QEMU $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd 154echo $QEMU $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
144if test -n "$RCU_BUILDONLY" 155if test -n "$RCU_BUILDONLY"
@@ -188,5 +199,5 @@ then
188fi 199fi
189 200
190cp $builddir/console.log $resdir 201cp $builddir/console.log $resdir
191parse-rcutorture.sh $resdir/console.log $title 202parse-${TORTURE_SUITE}torture.sh $resdir/console.log $title
192parse-console.sh $resdir/console.log $title 203parse-console.sh $resdir/console.log $title
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 1b7923bf6a70..5a78cbf55f06 100644
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -30,14 +30,21 @@
30scriptname=$0 30scriptname=$0
31args="$*" 31args="$*"
32 32
33T=/tmp/kvm.sh.$$
34trap 'rm -rf $T' 0
35mkdir $T
36
33dur=30 37dur=30
38dryrun=""
34KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM 39KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
35PATH=${KVM}/bin:$PATH; export PATH 40PATH=${KVM}/bin:$PATH; export PATH
36builddir="${KVM}/b1" 41builddir="${KVM}/b1"
37RCU_INITRD="$KVM/initrd"; export RCU_INITRD 42RCU_INITRD="$KVM/initrd"; export RCU_INITRD
38RCU_KMAKE_ARG=""; export RCU_KMAKE_ARG 43RCU_KMAKE_ARG=""; export RCU_KMAKE_ARG
44TORTURE_SUITE=rcu
39resdir="" 45resdir=""
40configs="" 46configs=""
47cpus=0
41ds=`date +%Y.%m.%d-%H:%M:%S` 48ds=`date +%Y.%m.%d-%H:%M:%S`
42kversion="" 49kversion=""
43 50
@@ -49,7 +56,9 @@ usage () {
49 echo " --builddir absolute-pathname" 56 echo " --builddir absolute-pathname"
50 echo " --buildonly" 57 echo " --buildonly"
51 echo " --configs \"config-file list\"" 58 echo " --configs \"config-file list\""
59 echo " --cpus N"
52 echo " --datestamp string" 60 echo " --datestamp string"
61 echo " --dryrun sched|script"
53 echo " --duration minutes" 62 echo " --duration minutes"
54 echo " --interactive" 63 echo " --interactive"
55 echo " --kmake-arg kernel-make-arguments" 64 echo " --kmake-arg kernel-make-arguments"
@@ -58,8 +67,9 @@ usage () {
58 echo " --no-initrd" 67 echo " --no-initrd"
59 echo " --qemu-args qemu-system-..." 68 echo " --qemu-args qemu-system-..."
60 echo " --qemu-cmd qemu-system-..." 69 echo " --qemu-cmd qemu-system-..."
61 echo " --results absolute-pathname"
62 echo " --relbuilddir relative-pathname" 70 echo " --relbuilddir relative-pathname"
71 echo " --results absolute-pathname"
72 echo " --torture rcu"
63 exit 1 73 exit 1
64} 74}
65 75
@@ -85,11 +95,21 @@ do
85 configs="$2" 95 configs="$2"
86 shift 96 shift
87 ;; 97 ;;
98 --cpus)
99 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
100 cpus=$2
101 shift
102 ;;
88 --datestamp) 103 --datestamp)
89 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--' 104 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
90 ds=$2 105 ds=$2
91 shift 106 shift
92 ;; 107 ;;
108 --dryrun)
109 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
110 dryrun=$2
111 shift
112 ;;
93 --duration) 113 --duration)
94 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error' 114 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
95 dur=$2 115 dur=$2
@@ -138,6 +158,11 @@ do
138 resdir=$2 158 resdir=$2
139 shift 159 shift
140 ;; 160 ;;
161 --torture)
162 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--'
163 TORTURE_SUITE=$2
164 shift
165 ;;
141 *) 166 *)
142 echo Unknown argument $1 167 echo Unknown argument $1
143 usage 168 usage
@@ -146,7 +171,7 @@ do
146 shift 171 shift
147done 172done
148 173
149CONFIGFRAG=${KVM}/configs; export CONFIGFRAG 174CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
150KVPATH=${CONFIGFRAG}/$kversion; export KVPATH 175KVPATH=${CONFIGFRAG}/$kversion; export KVPATH
151 176
152if test -z "$configs" 177if test -z "$configs"
@@ -157,54 +182,231 @@ fi
157if test -z "$resdir" 182if test -z "$resdir"
158then 183then
159 resdir=$KVM/res 184 resdir=$KVM/res
160 if ! test -e $resdir 185fi
161 then 186
162 mkdir $resdir || : 187if test "$dryrun" = ""
163 fi 188then
164else
165 if ! test -e $resdir 189 if ! test -e $resdir
166 then 190 then
167 mkdir -p "$resdir" || : 191 mkdir -p "$resdir" || :
168 fi 192 fi
169fi 193 mkdir $resdir/$ds
170mkdir $resdir/$ds
171touch $resdir/$ds/log
172echo $scriptname $args >> $resdir/$ds/log
173 194
174pwd > $resdir/$ds/testid.txt 195 # Be noisy only if running the script.
175if test -d .git 196 echo Results directory: $resdir/$ds
176then 197 echo $scriptname $args
177 git status >> $resdir/$ds/testid.txt 198
178 git rev-parse HEAD >> $resdir/$ds/testid.txt 199 touch $resdir/$ds/log
179fi 200 echo $scriptname $args >> $resdir/$ds/log
180builddir=$KVM/b1 201 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
181if ! test -e $builddir 202
182then 203 pwd > $resdir/$ds/testid.txt
183 mkdir $builddir || : 204 if test -d .git
205 then
206 git status >> $resdir/$ds/testid.txt
207 git rev-parse HEAD >> $resdir/$ds/testid.txt
208 fi
184fi 209fi
185 210
211# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
212touch $T/cfgcpu
186for CF in $configs 213for CF in $configs
187do 214do
188 # Running TREE01 multiple times creates TREE01, TREE01.2, TREE01.3, ... 215 if test -f "$CONFIGFRAG/$kversion/$CF"
189 rd=$resdir/$ds/$CF
190 if test -d "${rd}"
191 then 216 then
192 n="`ls -d "${rd}"* | grep '\.[0-9]\+$' | 217 echo $CF `configNR_CPUS.sh $CONFIGFRAG/$kversion/$CF` >> $T/cfgcpu
193 sed -e 's/^.*\.\([0-9]\+\)/\1/' | 218 else
194 sort -k1n | tail -1`" 219 echo "The --configs file $CF does not exist, terminating."
195 if test -z "$n" 220 exit 1
196 then
197 rd="${rd}.2"
198 else
199 n="`expr $n + 1`"
200 rd="${rd}.${n}"
201 fi
202 fi 221 fi
203 mkdir "${rd}"
204 echo Results directory: $rd
205 kvm-test-1-rcu.sh $CONFIGFRAG/$kversion/$CF $builddir $rd $dur "-nographic $RCU_QEMU_ARG" "rcutorture.test_no_idle_hz=1 rcutorture.verbose=1 $RCU_BOOTARGS"
206done 222done
223sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
224
225# Use a greedy bin-packing algorithm, sorting the list accordingly.
226awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
227BEGIN {
228 njobs = 0;
229}
230
231{
232 # Read file of tests and corresponding required numbers of CPUs.
233 cf[njobs] = $1;
234 cpus[njobs] = $2;
235 njobs++;
236}
237
238END {
239 alldone = 0;
240 batch = 0;
241 nc = -1;
242
243 # Each pass through the following loop creates on test batch
244 # that can be executed concurrently given ncpus. Note that a
245 # given test that requires more than the available CPUs will run in
246 # their own batch. Such tests just have to make do with what
247 # is available.
248 while (nc != ncpus) {
249 batch++;
250 nc = ncpus;
251
252 # Each pass through the following loop considers one
253 # test for inclusion in the current batch.
254 for (i = 0; i < njobs; i++) {
255 if (done[i])
256 continue; # Already part of a batch.
257 if (nc >= cpus[i] || nc == ncpus) {
258
259 # This test fits into the current batch.
260 done[i] = batch;
261 nc -= cpus[i];
262 if (nc <= 0)
263 break; # Too-big test in its own batch.
264 }
265 }
266 }
267
268 # Dump out the tests in batch order.
269 for (b = 1; b <= batch; b++)
270 for (i = 0; i < njobs; i++)
271 if (done[i] == b)
272 print cf[i], cpus[i];
273}'
274
275# Generate a script to execute the tests in appropriate batches.
276cat << ___EOF___ > $T/script
277TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
278___EOF___
279awk < $T/cfgcpu.pack \
280 -v CONFIGDIR="$CONFIGFRAG/$kversion/" \
281 -v KVM="$KVM" \
282 -v ncpus=$cpus \
283 -v rd=$resdir/$ds/ \
284 -v dur=$dur \
285 -v RCU_QEMU_ARG=$RCU_QEMU_ARG \
286 -v RCU_BOOTARGS=$RCU_BOOTARGS \
287'BEGIN {
288 i = 0;
289}
290
291{
292 cf[i] = $1;
293 cpus[i] = $2;
294 i++;
295}
296
297# Dump out the scripting required to run one test batch.
298function dump(first, pastlast)
299{
300 print "echo ----Start batch: `date`";
301 print "echo ----Start batch: `date` >> " rd "/log";
302 jn=1
303 for (j = first; j < pastlast; j++) {
304 builddir=KVM "/b" jn
305 cpusr[jn] = cpus[j];
306 if (cfrep[cf[j]] == "") {
307 cfr[jn] = cf[j];
308 cfrep[cf[j]] = 1;
309 } else {
310 cfrep[cf[j]]++;
311 cfr[jn] = cf[j] "." cfrep[cf[j]];
312 }
313 if (cpusr[jn] > ncpus && ncpus != 0)
314 ovf = "(!)";
315 else
316 ovf = "";
317 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
318 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
319 print "rm -f " builddir ".*";
320 print "touch " builddir ".wait";
321 print "mkdir " builddir " > /dev/null 2>&1 || :";
322 print "mkdir " rd cfr[jn] " || :";
323 print "kvm-test-1-run.sh " CONFIGDIR cf[j], builddir, rd cfr[jn], dur " \"" RCU_QEMU_ARG "\" \"" RCU_BOOTARGS "\" > " rd cfr[jn] "/kvm-test-1-run.sh.out 2>&1 &"
324 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
325 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
326 print "while test -f " builddir ".wait"
327 print "do"
328 print "\tsleep 1"
329 print "done"
330 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
331 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
332 jn++;
333 }
334 for (j = 1; j < jn; j++) {
335 builddir=KVM "/b" j
336 print "rm -f " builddir ".ready"
337 print "echo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
338 print "echo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
339 }
340 print "wait"
341 print "echo ---- All kernel runs complete. `date`";
342 print "echo ---- All kernel runs complete. `date` >> " rd "/log";
343 for (j = 1; j < jn; j++) {
344 builddir=KVM "/b" j
345 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
346 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
347 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
348 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
349 }
350}
351
352END {
353 njobs = i;
354 nc = ncpus;
355 first = 0;
356
357 # Each pass through the following loop considers one test.
358 for (i = 0; i < njobs; i++) {
359 if (ncpus == 0) {
360 # Sequential test specified, each test its own batch.
361 dump(i, i + 1);
362 first = i;
363 } else if (nc < cpus[i] && i != 0) {
364 # Out of CPUs, dump out a batch.
365 dump(first, i);
366 first = i;
367 nc = ncpus;
368 }
369 # Account for the CPUs needed by the current test.
370 nc -= cpus[i];
371 }
372 # Dump the last batch.
373 if (ncpus != 0)
374 dump(first, i);
375}' >> $T/script
376
377if test "$dryrun" = script
378then
379 # Dump out the script, but define the environment variables that
380 # it needs to run standalone.
381 echo CONFIGFRAG="$CONFIGFRAG; export CONFIGFRAG"
382 echo KVM="$KVM; export KVM"
383 echo KVPATH="$KVPATH; export KVPATH"
384 echo PATH="$PATH; export PATH"
385 echo RCU_BUILDONLY="$RCU_BUILDONLY; export RCU_BUILDONLY"
386 echo RCU_INITRD="$RCU_INITRD; export RCU_INITRD"
387 echo RCU_KMAKE_ARG="$RCU_KMAKE_ARG; export RCU_KMAKE_ARG"
388 echo RCU_QEMU_CMD="$RCU_QEMU_CMD; export RCU_QEMU_CMD"
389 echo RCU_QEMU_INTERACTIVE="$RCU_QEMU_INTERACTIVE; export RCU_QEMU_INTERACTIVE"
390 echo RCU_QEMU_MAC="$RCU_QEMU_MAC; export RCU_QEMU_MAC"
391 echo "mkdir -p "$resdir" || :"
392 echo "mkdir $resdir/$ds"
393 cat $T/script
394 exit 0
395elif test "$dryrun" = sched
396then
397 # Extract the test run schedule from the script.
398 egrep 'start batch|Starting build\.' $T/script |
399 sed -e 's/:.*$//' -e 's/^echo //'
400 exit 0
401else
402 # Not a dryru, so run the script.
403 sh $T/script
404fi
405
207# Tracing: trace_event=rcu:rcu_grace_period,rcu:rcu_future_grace_period,rcu:rcu_grace_period_init,rcu:rcu_nocb_wake,rcu:rcu_preempt_task,rcu:rcu_unlock_preempted_task,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_kfree_callback,rcu:rcu_batch_start,rcu:rcu_invoke_callback,rcu:rcu_invoke_kfree_callback,rcu:rcu_batch_end,rcu:rcu_torture_read,rcu:rcu_barrier 406# Tracing: trace_event=rcu:rcu_grace_period,rcu:rcu_future_grace_period,rcu:rcu_grace_period_init,rcu:rcu_nocb_wake,rcu:rcu_preempt_task,rcu:rcu_unlock_preempted_task,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_kfree_callback,rcu:rcu_batch_start,rcu:rcu_invoke_callback,rcu:rcu_invoke_kfree_callback,rcu:rcu_batch_end,rcu:rcu_torture_read,rcu:rcu_barrier
208 407
408echo
409echo
209echo " --- `date` Test summary:" 410echo " --- `date` Test summary:"
411echo Results directory: $resdir/$ds
210kvm-recheck.sh $resdir/$ds 412kvm-recheck.sh $resdir/$ds
diff --git a/tools/testing/selftests/rcutorture/configs/lock/BUSTED b/tools/testing/selftests/rcutorture/configs/lock/BUSTED
new file mode 100644
index 000000000000..1d1da1477fc3
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/lock/BUSTED
@@ -0,0 +1,6 @@
1CONFIG_SMP=y
2CONFIG_NR_CPUS=4
3CONFIG_HOTPLUG_CPU=y
4CONFIG_PREEMPT_NONE=n
5CONFIG_PREEMPT_VOLUNTARY=n
6CONFIG_PREEMPT=y
diff --git a/tools/testing/selftests/rcutorture/configs/lock/BUSTED.boot b/tools/testing/selftests/rcutorture/configs/lock/BUSTED.boot
new file mode 100644
index 000000000000..6386c15e9770
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/lock/BUSTED.boot
@@ -0,0 +1 @@
locktorture.torture_type=lock_busted
diff --git a/tools/testing/selftests/rcutorture/configs/lock/CFLIST b/tools/testing/selftests/rcutorture/configs/lock/CFLIST
new file mode 100644
index 000000000000..a061b22d1892
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/lock/CFLIST
@@ -0,0 +1 @@
LOCK01
diff --git a/tools/testing/selftests/rcutorture/configs/lock/CFcommon b/tools/testing/selftests/rcutorture/configs/lock/CFcommon
new file mode 100644
index 000000000000..e372dc269254
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/lock/CFcommon
@@ -0,0 +1,2 @@
1CONFIG_LOCK_TORTURE_TEST=y
2CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/lock/LOCK01 b/tools/testing/selftests/rcutorture/configs/lock/LOCK01
new file mode 100644
index 000000000000..a9625e3d6cd9
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK01
@@ -0,0 +1,6 @@
1CONFIG_SMP=y
2CONFIG_NR_CPUS=8
3CONFIG_HOTPLUG_CPU=y
4CONFIG_PREEMPT_NONE=n
5CONFIG_PREEMPT_VOLUNTARY=n
6CONFIG_PREEMPT=y
diff --git a/tools/testing/selftests/rcutorture/configs/lock/ver_functions.sh b/tools/testing/selftests/rcutorture/configs/lock/ver_functions.sh
new file mode 100644
index 000000000000..9746ea1cd6c7
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/lock/ver_functions.sh
@@ -0,0 +1,43 @@
1#!/bin/bash
2#
3# Kernel-version-dependent shell functions for the rest of the scripts.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, you can access it online at
17# http://www.gnu.org/licenses/gpl-2.0.html.
18#
19# Copyright (C) IBM Corporation, 2014
20#
21# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
22
23# locktorture_param_onoff bootparam-string config-file
24#
25# Adds onoff locktorture module parameters to kernels having it.
26locktorture_param_onoff () {
27 if ! bootparam_hotplug_cpu "$1" && configfrag_hotplug_cpu "$2"
28 then
29 echo CPU-hotplug kernel, adding locktorture onoff. 1>&2
30 echo locktorture.onoff_interval=3 locktorture.onoff_holdoff=30
31 fi
32}
33
34# per_version_boot_params bootparam-string config-file seconds
35#
36# Adds per-version torture-module parameters to kernels supporting them.
37per_version_boot_params () {
38 echo $1 `locktorture_param_onoff "$1" "$2"` \
39 locktorture.stat_interval=15 \
40 locktorture.shutdown_secs=$3 \
41 locktorture.locktorture_runnable=1 \
42 locktorture.verbose=1
43}
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/BUSTED b/tools/testing/selftests/rcutorture/configs/rcu/BUSTED
new file mode 100644
index 000000000000..48d8a245c7fa
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/rcu/BUSTED
@@ -0,0 +1,7 @@
1CONFIG_RCU_TRACE=n
2CONFIG_SMP=y
3CONFIG_NR_CPUS=4
4CONFIG_HOTPLUG_CPU=y
5CONFIG_PREEMPT_NONE=n
6CONFIG_PREEMPT_VOLUNTARY=n
7CONFIG_PREEMPT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/BUSTED.boot b/tools/testing/selftests/rcutorture/configs/rcu/BUSTED.boot
new file mode 100644
index 000000000000..6804f9dcfc1b
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/rcu/BUSTED.boot
@@ -0,0 +1 @@
rcutorture.torture_type=rcu_busted
diff --git a/tools/testing/selftests/rcutorture/configs/CFLIST b/tools/testing/selftests/rcutorture/configs/rcu/CFLIST
index cd3d29cb0a47..cd3d29cb0a47 100644
--- a/tools/testing/selftests/rcutorture/configs/CFLIST
+++ b/tools/testing/selftests/rcutorture/configs/rcu/CFLIST
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/CFcommon b/tools/testing/selftests/rcutorture/configs/rcu/CFcommon
new file mode 100644
index 000000000000..d2d2a86139db
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/rcu/CFcommon
@@ -0,0 +1,2 @@
1CONFIG_RCU_TORTURE_TEST=y
2CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/SRCU-N b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N
index 10a0e27f4c75..9fbb41b9b314 100644
--- a/tools/testing/selftests/rcutorture/configs/SRCU-N
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N
@@ -1,8 +1,7 @@
1CONFIG_RCU_TRACE=n 1CONFIG_RCU_TRACE=n
2CONFIG_SMP=y 2CONFIG_SMP=y
3CONFIG_NR_CPUS=8 3CONFIG_NR_CPUS=4
4CONFIG_HOTPLUG_CPU=y 4CONFIG_HOTPLUG_CPU=y
5CONFIG_PREEMPT_NONE=y 5CONFIG_PREEMPT_NONE=y
6CONFIG_PREEMPT_VOLUNTARY=n 6CONFIG_PREEMPT_VOLUNTARY=n
7CONFIG_PREEMPT=n 7CONFIG_PREEMPT=n
8CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/SRCU-N.boot b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N.boot
index 238bfe3bd0cc..238bfe3bd0cc 100644
--- a/tools/testing/selftests/rcutorture/configs/SRCU-N.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N.boot
diff --git a/tools/testing/selftests/rcutorture/configs/SRCU-P b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P
index 6650e00c6d91..4b6f272dba27 100644
--- a/tools/testing/selftests/rcutorture/configs/SRCU-P
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P
@@ -5,4 +5,3 @@ CONFIG_HOTPLUG_CPU=y
5CONFIG_PREEMPT_NONE=n 5CONFIG_PREEMPT_NONE=n
6CONFIG_PREEMPT_VOLUNTARY=n 6CONFIG_PREEMPT_VOLUNTARY=n
7CONFIG_PREEMPT=y 7CONFIG_PREEMPT=y
8CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/SRCU-P.boot b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P.boot
index 238bfe3bd0cc..238bfe3bd0cc 100644
--- a/tools/testing/selftests/rcutorture/configs/SRCU-P.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P.boot
diff --git a/tools/testing/selftests/rcutorture/configs/TINY01 b/tools/testing/selftests/rcutorture/configs/rcu/TINY01
index 0c2823f21712..0a63e073a00c 100644
--- a/tools/testing/selftests/rcutorture/configs/TINY01
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TINY01
@@ -10,4 +10,3 @@ CONFIG_RCU_TRACE=n
10CONFIG_DEBUG_LOCK_ALLOC=n 10CONFIG_DEBUG_LOCK_ALLOC=n
11CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 11CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
12CONFIG_PREEMPT_COUNT=n 12CONFIG_PREEMPT_COUNT=n
13CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TINY02 b/tools/testing/selftests/rcutorture/configs/rcu/TINY02
index e5072d7528b6..f4feaee40776 100644
--- a/tools/testing/selftests/rcutorture/configs/TINY02
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TINY02
@@ -10,4 +10,3 @@ CONFIG_RCU_TRACE=y
10CONFIG_DEBUG_LOCK_ALLOC=y 10CONFIG_DEBUG_LOCK_ALLOC=y
11CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 11CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
12CONFIG_PREEMPT_COUNT=y 12CONFIG_PREEMPT_COUNT=y
13CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE01 b/tools/testing/selftests/rcutorture/configs/rcu/TREE01
index 141119a00044..9c827ec59a97 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE01
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE01
@@ -20,4 +20,3 @@ CONFIG_RCU_CPU_STALL_INFO=n
20CONFIG_RCU_CPU_STALL_VERBOSE=n 20CONFIG_RCU_CPU_STALL_VERBOSE=n
21CONFIG_RCU_BOOST=n 21CONFIG_RCU_BOOST=n
22CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 22CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
23CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE01.boot b/tools/testing/selftests/rcutorture/configs/rcu/TREE01.boot
index 0fc8a3428938..0fc8a3428938 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE01.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE01.boot
diff --git a/tools/testing/selftests/rcutorture/configs/TREE02 b/tools/testing/selftests/rcutorture/configs/rcu/TREE02
index 2d4d09608528..1a777b5f68b5 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE02
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE02
@@ -7,7 +7,7 @@ CONFIG_PREEMPT=y
7CONFIG_HZ_PERIODIC=n 7CONFIG_HZ_PERIODIC=n
8CONFIG_NO_HZ_IDLE=y 8CONFIG_NO_HZ_IDLE=y
9CONFIG_NO_HZ_FULL=n 9CONFIG_NO_HZ_FULL=n
10CONFIG_RCU_FAST_NO_HZ=n 10CONFIG_RCU_FAST_NO_HZ=n
11CONFIG_RCU_TRACE=n 11CONFIG_RCU_TRACE=n
12CONFIG_HOTPLUG_CPU=n 12CONFIG_HOTPLUG_CPU=n
13CONFIG_SUSPEND=n 13CONFIG_SUSPEND=n
@@ -23,4 +23,3 @@ CONFIG_RCU_CPU_STALL_INFO=n
23CONFIG_RCU_CPU_STALL_VERBOSE=y 23CONFIG_RCU_CPU_STALL_VERBOSE=y
24CONFIG_RCU_BOOST=n 24CONFIG_RCU_BOOST=n
25CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 25CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
26CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE03 b/tools/testing/selftests/rcutorture/configs/rcu/TREE03
index a47de5be8a04..c1f111c1561b 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE03
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE03
@@ -20,4 +20,3 @@ CONFIG_RCU_CPU_STALL_VERBOSE=n
20CONFIG_RCU_BOOST=y 20CONFIG_RCU_BOOST=y
21CONFIG_RCU_BOOST_PRIO=2 21CONFIG_RCU_BOOST_PRIO=2
22CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 22CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
23CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE04 b/tools/testing/selftests/rcutorture/configs/rcu/TREE04
index 8d839b86a1d5..7dbd27ce17a4 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE04
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE04
@@ -22,4 +22,3 @@ CONFIG_PROVE_RCU_DELAY=n
22CONFIG_RCU_CPU_STALL_INFO=y 22CONFIG_RCU_CPU_STALL_INFO=y
23CONFIG_RCU_CPU_STALL_VERBOSE=y 23CONFIG_RCU_CPU_STALL_VERBOSE=y
24CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 24CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
25CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE04.boot b/tools/testing/selftests/rcutorture/configs/rcu/TREE04.boot
index 0fc8a3428938..0fc8a3428938 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE04.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE04.boot
diff --git a/tools/testing/selftests/rcutorture/configs/TREE05 b/tools/testing/selftests/rcutorture/configs/rcu/TREE05
index b5ba72ea25cb..d0f32e574743 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE05
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE05
@@ -22,4 +22,3 @@ CONFIG_PROVE_RCU_DELAY=y
22CONFIG_RCU_CPU_STALL_INFO=n 22CONFIG_RCU_CPU_STALL_INFO=n
23CONFIG_RCU_CPU_STALL_VERBOSE=n 23CONFIG_RCU_CPU_STALL_VERBOSE=n
24CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 24CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
25CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE05.boot b/tools/testing/selftests/rcutorture/configs/rcu/TREE05.boot
index 3b42b8b033cd..3b42b8b033cd 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE05.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE05.boot
diff --git a/tools/testing/selftests/rcutorture/configs/TREE06 b/tools/testing/selftests/rcutorture/configs/rcu/TREE06
index 7c95ab48d29f..2e477dfb9c57 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE06
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE06
@@ -23,4 +23,3 @@ CONFIG_PROVE_RCU_DELAY=n
23CONFIG_RCU_CPU_STALL_INFO=n 23CONFIG_RCU_CPU_STALL_INFO=n
24CONFIG_RCU_CPU_STALL_VERBOSE=n 24CONFIG_RCU_CPU_STALL_VERBOSE=n
25CONFIG_DEBUG_OBJECTS_RCU_HEAD=y 25CONFIG_DEBUG_OBJECTS_RCU_HEAD=y
26CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE07 b/tools/testing/selftests/rcutorture/configs/rcu/TREE07
index 1467404bdec1..042f86ef362a 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE07
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE07
@@ -21,4 +21,3 @@ CONFIG_PROVE_RCU_DELAY=n
21CONFIG_RCU_CPU_STALL_INFO=y 21CONFIG_RCU_CPU_STALL_INFO=y
22CONFIG_RCU_CPU_STALL_VERBOSE=n 22CONFIG_RCU_CPU_STALL_VERBOSE=n
23CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 23CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
24CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE08 b/tools/testing/selftests/rcutorture/configs/rcu/TREE08
index 7d097a61ac2a..3438cee1e3c5 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE08
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE08
@@ -23,4 +23,3 @@ CONFIG_RCU_CPU_STALL_INFO=n
23CONFIG_RCU_CPU_STALL_VERBOSE=n 23CONFIG_RCU_CPU_STALL_VERBOSE=n
24CONFIG_RCU_BOOST=n 24CONFIG_RCU_BOOST=n
25CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 25CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
26CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE08-T b/tools/testing/selftests/rcutorture/configs/rcu/TREE08-T
index 442c4e450ab3..bf4523d3e44c 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE08-T
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE08-T
@@ -23,4 +23,3 @@ CONFIG_RCU_CPU_STALL_INFO=n
23CONFIG_RCU_CPU_STALL_VERBOSE=n 23CONFIG_RCU_CPU_STALL_VERBOSE=n
24CONFIG_RCU_BOOST=n 24CONFIG_RCU_BOOST=n
25CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 25CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
26CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/TREE09 b/tools/testing/selftests/rcutorture/configs/rcu/TREE09
index 0d1ec0d3dfee..81e4f7c0bf0b 100644
--- a/tools/testing/selftests/rcutorture/configs/TREE09
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE09
@@ -18,4 +18,3 @@ CONFIG_RCU_CPU_STALL_INFO=n
18CONFIG_RCU_CPU_STALL_VERBOSE=n 18CONFIG_RCU_CPU_STALL_VERBOSE=n
19CONFIG_RCU_BOOST=n 19CONFIG_RCU_BOOST=n
20CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 20CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
21CONFIG_PRINTK_TIME=y
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/CFLIST b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/CFLIST
index 18223947bbcb..18223947bbcb 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/CFLIST
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/CFLIST
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/N1-S-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N1-S-T-NH-SD-SMP-HP
index d3ef873eb6e7..d3ef873eb6e7 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/N1-S-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N1-S-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/N2-2-t-nh-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N2-2-t-nh-sd-SMP-hp
index 02e418572b1b..02e418572b1b 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/N2-2-t-nh-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N2-2-t-nh-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/N3-3-T-nh-SD-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N3-3-T-nh-SD-SMP-hp
index b3100f69c8cf..b3100f69c8cf 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/N3-3-T-nh-SD-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N3-3-T-nh-SD-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/N4-A-t-NH-sd-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N4-A-t-NH-sd-SMP-HP
index c56b44530725..c56b44530725 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/N4-A-t-NH-sd-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N4-A-t-NH-sd-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/N5-U-T-NH-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N5-U-T-NH-sd-SMP-hp
index 90d924fea9e9..90d924fea9e9 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/N5-U-T-NH-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/N5-U-T-NH-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/NT1-nh b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT1-nh
index 023f312a931c..023f312a931c 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/NT1-nh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT1-nh
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/NT3-NH b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT3-NH
index 6fd0235dae73..6fd0235dae73 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/NT3-NH
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/NT3-NH
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/P1-S-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P1-S-T-NH-SD-SMP-HP
index f72402d7c13d..f72402d7c13d 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/P1-S-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P1-S-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/P2-2-t-nh-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P2-2-t-nh-sd-SMP-hp
index 0f3b667d2a9f..0f3b667d2a9f 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/P2-2-t-nh-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P2-2-t-nh-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/P3-3-T-nh-SD-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P3-3-T-nh-SD-SMP-hp
index b035e141bf2a..b035e141bf2a 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/P3-3-T-nh-SD-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P3-3-T-nh-SD-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/P4-A-t-NH-sd-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P4-A-t-NH-sd-SMP-HP
index 3ccf6a9447f5..3ccf6a9447f5 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/P4-A-t-NH-sd-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P4-A-t-NH-sd-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/P5-U-T-NH-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P5-U-T-NH-sd-SMP-hp
index ef624ce73d8e..ef624ce73d8e 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/P5-U-T-NH-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/P5-U-T-NH-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/PT1-nh b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT1-nh
index e3361c3894a1..e3361c3894a1 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/PT1-nh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT1-nh
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/PT2-NH b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT2-NH
index 64abfc3b4d94..64abfc3b4d94 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/PT2-NH
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/PT2-NH
diff --git a/tools/testing/selftests/rcutorture/configs/v0.0/ver_functions.sh b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/ver_functions.sh
index e8052539af54..5ace37a89780 100644
--- a/tools/testing/selftests/rcutorture/configs/v0.0/ver_functions.sh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v0.0/ver_functions.sh
@@ -20,16 +20,14 @@
20# 20#
21# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com> 21# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
22 22
23# rcutorture_param_n_barrier_cbs bootparam-string 23# per_version_boot_params bootparam-string config-file seconds
24# 24#
25# Adds n_barrier_cbs rcutorture module parameter to kernels having it. 25# Adds per-version torture-module parameters to kernels supporting them.
26rcutorture_param_n_barrier_cbs () { 26# Which old kernels do not.
27 echo $1 27per_version_boot_params () {
28} 28 echo rcutorture.stat_interval=15 \
29 29 rcutorture.shutdown_secs=$3 \
30# rcutorture_param_onoff bootparam-string config-file 30 rcutorture.rcutorture_runnable=1 \
31# 31 rcutorture.test_no_idle_hz=1 \
32# Adds onoff rcutorture module parameters to kernels having it. 32 rcutorture.verbose=1
33rcutorture_param_onoff () {
34 echo $1
35} 33}
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/CFLIST b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/CFLIST
index da4cbc668f2a..da4cbc668f2a 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/CFLIST
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/CFLIST
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/N1-S-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N1-S-T-NH-SD-SMP-HP
index d81e11d280aa..d81e11d280aa 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/N1-S-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N1-S-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/N2-2-t-nh-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N2-2-t-nh-sd-SMP-hp
index 02e418572b1b..02e418572b1b 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/N2-2-t-nh-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N2-2-t-nh-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/N3-3-T-nh-SD-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N3-3-T-nh-SD-SMP-hp
index b3100f69c8cf..b3100f69c8cf 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/N3-3-T-nh-SD-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N3-3-T-nh-SD-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/N4-A-t-NH-sd-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N4-A-t-NH-sd-SMP-HP
index c56b44530725..c56b44530725 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/N4-A-t-NH-sd-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N4-A-t-NH-sd-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/N5-U-T-NH-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N5-U-T-NH-sd-SMP-hp
index 90d924fea9e9..90d924fea9e9 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/N5-U-T-NH-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N5-U-T-NH-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/N6---t-nh-SD-smp-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N6---t-nh-SD-smp-hp
index 0ccc36d72738..0ccc36d72738 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/N6---t-nh-SD-smp-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N6---t-nh-SD-smp-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/N7-4-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N7-4-T-NH-SD-SMP-HP
index 3f640cf84973..3f640cf84973 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/N7-4-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N7-4-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/N8-2-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N8-2-T-NH-SD-SMP-HP
index 285da2dd8ac3..285da2dd8ac3 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/N8-2-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/N8-2-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/NT1-nh b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT1-nh
index 023f312a931c..023f312a931c 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/NT1-nh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT1-nh
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/NT3-NH b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT3-NH
index 6fd0235dae73..6fd0235dae73 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/NT3-NH
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/NT3-NH
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P1-S-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P1-S-T-NH-SD-SMP-HP
index 9647c44cf4b7..9647c44cf4b7 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P1-S-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P1-S-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P2-2-t-nh-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P2-2-t-nh-sd-SMP-hp
index 0f3b667d2a9f..0f3b667d2a9f 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P2-2-t-nh-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P2-2-t-nh-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P3-3-T-nh-SD-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P3-3-T-nh-SD-SMP-hp
index b035e141bf2a..b035e141bf2a 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P3-3-T-nh-SD-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P3-3-T-nh-SD-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P4-A-t-NH-sd-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P4-A-t-NH-sd-SMP-HP
index 3ccf6a9447f5..3ccf6a9447f5 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P4-A-t-NH-sd-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P4-A-t-NH-sd-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P5-U-T-NH-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P5-U-T-NH-sd-SMP-hp
index ef624ce73d8e..ef624ce73d8e 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P5-U-T-NH-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P5-U-T-NH-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P6---t-nh-SD-smp-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P6---t-nh-SD-smp-hp
index f4c9175828bf..f4c9175828bf 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P6---t-nh-SD-smp-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P6---t-nh-SD-smp-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP
index 77a8c5b75763..77a8c5b75763 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-HP-all b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-all
index 0eecebc6e95f..0eecebc6e95f 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-HP-all
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-all
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-HP-none b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-none
index 0eecebc6e95f..0eecebc6e95f 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-HP-none
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-HP-none
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-hp
index 588bc70420cd..588bc70420cd 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/P7-4-T-NH-SD-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/P7-4-T-NH-SD-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/PT1-nh b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT1-nh
index e3361c3894a1..e3361c3894a1 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/PT1-nh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT1-nh
diff --git a/tools/testing/selftests/rcutorture/configs/v3.12/PT2-NH b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT2-NH
index 64abfc3b4d94..64abfc3b4d94 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.12/PT2-NH
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.12/PT2-NH
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/CFLIST b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/CFLIST
index 18223947bbcb..18223947bbcb 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/CFLIST
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/CFLIST
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/N1-S-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N1-S-T-NH-SD-SMP-HP
index d81e11d280aa..d81e11d280aa 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/N1-S-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N1-S-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/N2-2-t-nh-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N2-2-t-nh-sd-SMP-hp
index 02e418572b1b..02e418572b1b 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/N2-2-t-nh-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N2-2-t-nh-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/N3-3-T-nh-SD-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N3-3-T-nh-SD-SMP-hp
index b3100f69c8cf..b3100f69c8cf 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/N3-3-T-nh-SD-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N3-3-T-nh-SD-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/N4-A-t-NH-sd-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N4-A-t-NH-sd-SMP-HP
index c56b44530725..c56b44530725 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/N4-A-t-NH-sd-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N4-A-t-NH-sd-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/N5-U-T-NH-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N5-U-T-NH-sd-SMP-hp
index 90d924fea9e9..90d924fea9e9 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/N5-U-T-NH-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/N5-U-T-NH-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/NT1-nh b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/NT1-nh
index 023f312a931c..023f312a931c 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/NT1-nh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/NT1-nh
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/NT3-NH b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/NT3-NH
index 6fd0235dae73..6fd0235dae73 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/NT3-NH
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/NT3-NH
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/P1-S-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P1-S-T-NH-SD-SMP-HP
index 9647c44cf4b7..9647c44cf4b7 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/P1-S-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P1-S-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/P2-2-t-nh-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P2-2-t-nh-sd-SMP-hp
index 0f3b667d2a9f..0f3b667d2a9f 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/P2-2-t-nh-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P2-2-t-nh-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/P3-3-T-nh-SD-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P3-3-T-nh-SD-SMP-hp
index b035e141bf2a..b035e141bf2a 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/P3-3-T-nh-SD-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P3-3-T-nh-SD-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/P4-A-t-NH-sd-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P4-A-t-NH-sd-SMP-HP
index 3ccf6a9447f5..3ccf6a9447f5 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/P4-A-t-NH-sd-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P4-A-t-NH-sd-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/P5-U-T-NH-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P5-U-T-NH-sd-SMP-hp
index ef624ce73d8e..ef624ce73d8e 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/P5-U-T-NH-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/P5-U-T-NH-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/PT1-nh b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/PT1-nh
index e3361c3894a1..e3361c3894a1 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/PT1-nh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/PT1-nh
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/PT2-NH b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/PT2-NH
index 64abfc3b4d94..64abfc3b4d94 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/PT2-NH
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/PT2-NH
diff --git a/tools/testing/selftests/rcutorture/configs/ver_functions.sh b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/ver_functions.sh
index 5e40eadea777..bae55692ce6e 100644
--- a/tools/testing/selftests/rcutorture/configs/ver_functions.sh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.3/ver_functions.sh
@@ -20,18 +20,6 @@
20# 20#
21# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com> 21# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
22 22
23# rcutorture_param_n_barrier_cbs bootparam-string
24#
25# Adds n_barrier_cbs rcutorture module parameter to kernels having it.
26rcutorture_param_n_barrier_cbs () {
27 if echo $1 | grep -q "rcutorture\.n_barrier_cbs"
28 then
29 echo $1
30 else
31 echo $1 rcutorture.n_barrier_cbs=4
32 fi
33}
34
35# rcutorture_param_onoff bootparam-string config-file 23# rcutorture_param_onoff bootparam-string config-file
36# 24#
37# Adds onoff rcutorture module parameters to kernels having it. 25# Adds onoff rcutorture module parameters to kernels having it.
@@ -39,8 +27,18 @@ rcutorture_param_onoff () {
39 if ! bootparam_hotplug_cpu "$1" && configfrag_hotplug_cpu "$2" 27 if ! bootparam_hotplug_cpu "$1" && configfrag_hotplug_cpu "$2"
40 then 28 then
41 echo CPU-hotplug kernel, adding rcutorture onoff. 1>&2 29 echo CPU-hotplug kernel, adding rcutorture onoff. 1>&2
42 echo $1 rcutorture.onoff_interval=3 rcutorture.onoff_holdoff=30 30 echo rcutorture.onoff_interval=3 rcutorture.onoff_holdoff=30
43 else
44 echo $1
45 fi 31 fi
46} 32}
33
34# per_version_boot_params bootparam-string config-file seconds
35#
36# Adds per-version torture-module parameters to kernels supporting them.
37per_version_boot_params () {
38 echo $1 `rcutorture_param_onoff "$1" "$2"` \
39 rcutorture.stat_interval=15 \
40 rcutorture.shutdown_secs=$3 \
41 rcutorture.rcutorture_runnable=1 \
42 rcutorture.test_no_idle_hz=1 \
43 rcutorture.verbose=1
44}
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/CFLIST b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/CFLIST
index 18223947bbcb..18223947bbcb 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/CFLIST
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/CFLIST
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/N1-S-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N1-S-T-NH-SD-SMP-HP
index d81e11d280aa..d81e11d280aa 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/N1-S-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N1-S-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/N2-2-t-nh-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N2-2-t-nh-sd-SMP-hp
index 02e418572b1b..02e418572b1b 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/N2-2-t-nh-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N2-2-t-nh-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/N3-3-T-nh-SD-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N3-3-T-nh-SD-SMP-hp
index b3100f69c8cf..b3100f69c8cf 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/N3-3-T-nh-SD-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N3-3-T-nh-SD-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/N4-A-t-NH-sd-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N4-A-t-NH-sd-SMP-HP
index c56b44530725..c56b44530725 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/N4-A-t-NH-sd-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N4-A-t-NH-sd-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/N5-U-T-NH-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N5-U-T-NH-sd-SMP-hp
index 90d924fea9e9..90d924fea9e9 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/N5-U-T-NH-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/N5-U-T-NH-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/NT1-nh b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/NT1-nh
index 023f312a931c..023f312a931c 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/NT1-nh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/NT1-nh
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/NT3-NH b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/NT3-NH
index 6fd0235dae73..6fd0235dae73 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/NT3-NH
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/NT3-NH
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/P1-S-T-NH-SD-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P1-S-T-NH-SD-SMP-HP
index 9647c44cf4b7..9647c44cf4b7 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/P1-S-T-NH-SD-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P1-S-T-NH-SD-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/P2-2-t-nh-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P2-2-t-nh-sd-SMP-hp
index 0f3b667d2a9f..0f3b667d2a9f 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/P2-2-t-nh-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P2-2-t-nh-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/P3-3-T-nh-SD-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P3-3-T-nh-SD-SMP-hp
index b035e141bf2a..b035e141bf2a 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/P3-3-T-nh-SD-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P3-3-T-nh-SD-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/P4-A-t-NH-sd-SMP-HP b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P4-A-t-NH-sd-SMP-HP
index 3ccf6a9447f5..3ccf6a9447f5 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/P4-A-t-NH-sd-SMP-HP
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P4-A-t-NH-sd-SMP-HP
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/P5-U-T-NH-sd-SMP-hp b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P5-U-T-NH-sd-SMP-hp
index ef624ce73d8e..ef624ce73d8e 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/P5-U-T-NH-sd-SMP-hp
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/P5-U-T-NH-sd-SMP-hp
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/PT1-nh b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/PT1-nh
index e3361c3894a1..e3361c3894a1 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/PT1-nh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/PT1-nh
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/PT2-NH b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/PT2-NH
index 64abfc3b4d94..64abfc3b4d94 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/PT2-NH
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/PT2-NH
diff --git a/tools/testing/selftests/rcutorture/configs/v3.5/ver_functions.sh b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/ver_functions.sh
index 6a5f13aab44d..8977d8d31b19 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.5/ver_functions.sh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/v3.5/ver_functions.sh
@@ -26,9 +26,9 @@
26rcutorture_param_n_barrier_cbs () { 26rcutorture_param_n_barrier_cbs () {
27 if echo $1 | grep -q "rcutorture\.n_barrier_cbs" 27 if echo $1 | grep -q "rcutorture\.n_barrier_cbs"
28 then 28 then
29 echo $1 29 :
30 else 30 else
31 echo $1 rcutorture.n_barrier_cbs=4 31 echo rcutorture.n_barrier_cbs=4
32 fi 32 fi
33} 33}
34 34
@@ -38,9 +38,20 @@ rcutorture_param_n_barrier_cbs () {
38rcutorture_param_onoff () { 38rcutorture_param_onoff () {
39 if ! bootparam_hotplug_cpu "$1" && configfrag_hotplug_cpu "$2" 39 if ! bootparam_hotplug_cpu "$1" && configfrag_hotplug_cpu "$2"
40 then 40 then
41 echo CPU-hotplug kernel, adding rcutorture onoff. 41 echo CPU-hotplug kernel, adding rcutorture onoff. 1>&2
42 echo $1 rcutorture.onoff_interval=3 rcutorture.onoff_holdoff=30 42 echo rcutorture.onoff_interval=3 rcutorture.onoff_holdoff=30
43 else
44 echo $1
45 fi 43 fi
46} 44}
45
46# per_version_boot_params bootparam-string config-file seconds
47#
48# Adds per-version torture-module parameters to kernels supporting them.
49per_version_boot_params () {
50 echo $1 `rcutorture_param_onoff "$1" "$2"` \
51 `rcutorture_param_n_barrier_cbs "$1"` \
52 rcutorture.stat_interval=15 \
53 rcutorture.shutdown_secs=$3 \
54 rcutorture.rcutorture_runnable=1 \
55 rcutorture.test_no_idle_hz=1 \
56 rcutorture.verbose=1
57}
diff --git a/tools/testing/selftests/rcutorture/configs/v3.3/ver_functions.sh b/tools/testing/selftests/rcutorture/configs/rcu/ver_functions.sh
index c37432f3572c..8977d8d31b19 100644
--- a/tools/testing/selftests/rcutorture/configs/v3.3/ver_functions.sh
+++ b/tools/testing/selftests/rcutorture/configs/rcu/ver_functions.sh
@@ -24,7 +24,12 @@
24# 24#
25# Adds n_barrier_cbs rcutorture module parameter to kernels having it. 25# Adds n_barrier_cbs rcutorture module parameter to kernels having it.
26rcutorture_param_n_barrier_cbs () { 26rcutorture_param_n_barrier_cbs () {
27 echo $1 27 if echo $1 | grep -q "rcutorture\.n_barrier_cbs"
28 then
29 :
30 else
31 echo rcutorture.n_barrier_cbs=4
32 fi
28} 33}
29 34
30# rcutorture_param_onoff bootparam-string config-file 35# rcutorture_param_onoff bootparam-string config-file
@@ -33,9 +38,20 @@ rcutorture_param_n_barrier_cbs () {
33rcutorture_param_onoff () { 38rcutorture_param_onoff () {
34 if ! bootparam_hotplug_cpu "$1" && configfrag_hotplug_cpu "$2" 39 if ! bootparam_hotplug_cpu "$1" && configfrag_hotplug_cpu "$2"
35 then 40 then
36 echo CPU-hotplug kernel, adding rcutorture onoff. 41 echo CPU-hotplug kernel, adding rcutorture onoff. 1>&2
37 echo $1 rcutorture.onoff_interval=3 rcutorture.onoff_holdoff=30 42 echo rcutorture.onoff_interval=3 rcutorture.onoff_holdoff=30
38 else
39 echo $1
40 fi 43 fi
41} 44}
45
46# per_version_boot_params bootparam-string config-file seconds
47#
48# Adds per-version torture-module parameters to kernels supporting them.
49per_version_boot_params () {
50 echo $1 `rcutorture_param_onoff "$1" "$2"` \
51 `rcutorture_param_n_barrier_cbs "$1"` \
52 rcutorture.stat_interval=15 \
53 rcutorture.shutdown_secs=$3 \
54 rcutorture.rcutorture_runnable=1 \
55 rcutorture.test_no_idle_hz=1 \
56 rcutorture.verbose=1
57}
diff --git a/tools/testing/selftests/rcutorture/doc/TREE_RCU-Kconfig.txt b/tools/testing/selftests/rcutorture/doc/TREE_RCU-kconfig.txt
index adbb76cffb49..adbb76cffb49 100644
--- a/tools/testing/selftests/rcutorture/doc/TREE_RCU-Kconfig.txt
+++ b/tools/testing/selftests/rcutorture/doc/TREE_RCU-kconfig.txt
diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index be456ce264d0..8ca405cd7c1a 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -24,6 +24,7 @@
24#include <linux/of.h> 24#include <linux/of.h>
25#include <linux/of_address.h> 25#include <linux/of_address.h>
26#include <linux/of_irq.h> 26#include <linux/of_irq.h>
27#include <linux/uaccess.h>
27 28
28#include <linux/irqchip/arm-gic.h> 29#include <linux/irqchip/arm-gic.h>
29 30
diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
index 88b2fe3ddf42..00d86427af0f 100644
--- a/virt/kvm/coalesced_mmio.c
+++ b/virt/kvm/coalesced_mmio.c
@@ -154,17 +154,13 @@ int kvm_vm_ioctl_register_coalesced_mmio(struct kvm *kvm,
154 list_add_tail(&dev->list, &kvm->coalesced_zones); 154 list_add_tail(&dev->list, &kvm->coalesced_zones);
155 mutex_unlock(&kvm->slots_lock); 155 mutex_unlock(&kvm->slots_lock);
156 156
157 return ret; 157 return 0;
158 158
159out_free_dev: 159out_free_dev:
160 mutex_unlock(&kvm->slots_lock); 160 mutex_unlock(&kvm->slots_lock);
161
162 kfree(dev); 161 kfree(dev);
163 162
164 if (dev == NULL) 163 return ret;
165 return -ENXIO;
166
167 return 0;
168} 164}
169 165
170int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm, 166int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm,
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 03a0381b1cb7..b5ec7fb986f6 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -102,7 +102,7 @@ static void kvm_release_pfn_dirty(pfn_t pfn);
102static void mark_page_dirty_in_slot(struct kvm *kvm, 102static void mark_page_dirty_in_slot(struct kvm *kvm,
103 struct kvm_memory_slot *memslot, gfn_t gfn); 103 struct kvm_memory_slot *memslot, gfn_t gfn);
104 104
105bool kvm_rebooting; 105__visible bool kvm_rebooting;
106EXPORT_SYMBOL_GPL(kvm_rebooting); 106EXPORT_SYMBOL_GPL(kvm_rebooting);
107 107
108static bool largepages_enabled = true; 108static bool largepages_enabled = true;