aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS5
-rw-r--r--Documentation/device-mapper/dm-raid.txt1
-rw-r--r--Documentation/devicetree/bindings/clock/uniphier-clock.txt16
-rw-r--r--Documentation/devicetree/bindings/usb/dwc2.txt5
-rw-r--r--Documentation/gpio/board.txt11
-rw-r--r--MAINTAINERS1
-rw-r--r--arch/arc/Kconfig27
-rw-r--r--arch/arc/Makefile3
-rw-r--r--arch/arc/boot/Makefile16
-rw-r--r--arch/arc/include/asm/arcregs.h3
-rw-r--r--arch/arc/include/asm/cache.h2
-rw-r--r--arch/arc/include/asm/elf.h2
-rw-r--r--arch/arc/include/asm/mcip.h16
-rw-r--r--arch/arc/include/asm/module.h1
-rw-r--r--arch/arc/include/asm/setup.h6
-rw-r--r--arch/arc/include/asm/syscalls.h1
-rw-r--r--arch/arc/include/uapi/asm/unistd.h9
-rw-r--r--arch/arc/kernel/mcip.c31
-rw-r--r--arch/arc/kernel/module.c53
-rw-r--r--arch/arc/kernel/process.c33
-rw-r--r--arch/arc/kernel/setup.c113
-rw-r--r--arch/arc/kernel/troubleshoot.c110
-rw-r--r--arch/arc/mm/cache.c19
-rw-r--r--arch/arc/mm/dma.c4
-rw-r--r--arch/arc/mm/tlb.c6
-rw-r--r--arch/arc/mm/tlbex.S21
-rw-r--r--arch/arm64/include/asm/memory.h2
-rw-r--r--arch/arm64/mm/numa.c9
-rw-r--r--arch/cris/arch-v32/drivers/cryptocop.c2
-rw-r--r--arch/h8300/include/asm/thread_info.h4
-rw-r--r--arch/h8300/kernel/signal.c2
-rw-r--r--arch/powerpc/include/asm/cpuidle.h2
-rw-r--r--arch/powerpc/include/asm/exception-64s.h16
-rw-r--r--arch/powerpc/include/asm/tlb.h12
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S50
-rw-r--r--arch/powerpc/kernel/hw_breakpoint.c2
-rw-r--r--arch/powerpc/kernel/idle_book3s.S35
-rw-r--r--arch/powerpc/kernel/process.c2
-rw-r--r--arch/powerpc/kvm/book3s_hv_rm_xics.c1
-rw-r--r--arch/powerpc/mm/tlb-radix.c8
-rw-r--r--arch/s390/include/asm/ftrace.h4
-rw-r--r--arch/s390/include/asm/processor.h2
-rw-r--r--arch/s390/include/asm/unistd.h3
-rw-r--r--arch/s390/kernel/dis.c4
-rw-r--r--arch/s390/kernel/dumpstack.c63
-rw-r--r--arch/s390/kernel/perf_event.c2
-rw-r--r--arch/s390/kernel/stacktrace.c4
-rw-r--r--arch/s390/mm/hugetlbpage.c1
-rw-r--r--arch/s390/mm/init.c38
-rw-r--r--arch/s390/oprofile/init.c2
-rw-r--r--arch/x86/entry/Makefile4
-rw-r--r--arch/x86/events/intel/core.c10
-rw-r--r--arch/x86/events/intel/cstate.c30
-rw-r--r--arch/x86/include/asm/io.h6
-rw-r--r--arch/x86/kernel/acpi/boot.c1
-rw-r--r--arch/x86/kernel/cpu/microcode/amd.c2
-rw-r--r--arch/x86/kernel/mcount_64.S3
-rw-r--r--arch/x86/kernel/quirks.c3
-rw-r--r--arch/x86/kernel/unwind_guess.c9
-rw-r--r--arch/x86/mm/kaslr.c6
-rw-r--r--arch/x86/mm/pat.c14
-rw-r--r--arch/x86/xen/enlighten.c2
-rw-r--r--block/badblocks.c23
-rw-r--r--block/blk-flush.c28
-rw-r--r--block/blk-mq.c6
-rw-r--r--drivers/acpi/acpica/dsinit.c11
-rw-r--r--drivers/acpi/acpica/dsmethod.c50
-rw-r--r--drivers/acpi/acpica/dswload2.c2
-rw-r--r--drivers/acpi/acpica/evrgnini.c3
-rw-r--r--drivers/acpi/acpica/nsload.c2
-rw-r--r--drivers/acpi/apei/ghes.c2
-rw-r--r--drivers/acpi/pci_link.c38
-rw-r--r--drivers/ata/ahci.c41
-rw-r--r--drivers/block/DAC960.c4
-rw-r--r--drivers/block/nbd.c2
-rw-r--r--drivers/char/hw_random/core.c6
-rw-r--r--drivers/clk/at91/clk-programmable.c2
-rw-r--r--drivers/clk/bcm/clk-bcm2835.c11
-rw-r--r--drivers/clk/clk-max77686.c1
-rw-r--r--drivers/clk/hisilicon/clk-hi6220.c4
-rw-r--r--drivers/clk/mediatek/Kconfig2
-rw-r--r--drivers/clk/mvebu/armada-37xx-periph.c11
-rw-r--r--drivers/clk/samsung/clk-exynos-audss.c1
-rw-r--r--drivers/clk/uniphier/clk-uniphier-core.c20
-rw-r--r--drivers/clk/uniphier/clk-uniphier-mio.c2
-rw-r--r--drivers/clk/uniphier/clk-uniphier-mux.c2
-rw-r--r--drivers/clk/uniphier/clk-uniphier.h2
-rw-r--r--drivers/cpufreq/intel_pstate.c38
-rw-r--r--drivers/dax/Kconfig2
-rw-r--r--drivers/dax/pmem.c2
-rw-r--r--drivers/gpio/Kconfig2
-rw-r--r--drivers/gpio/gpio-ath79.c1
-rw-r--r--drivers/gpio/gpio-mpc8xxx.c2
-rw-r--r--drivers/gpio/gpio-mxs.c8
-rw-r--r--drivers/gpio/gpio-stmpe.c2
-rw-r--r--drivers/gpio/gpio-ts4800.c1
-rw-r--r--drivers/gpio/gpiolib-acpi.c7
-rw-r--r--drivers/gpio/gpiolib.c42
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_object.c5
-rw-r--r--drivers/gpu/drm/ast/ast_ttm.c6
-rw-r--r--drivers/gpu/drm/cirrus/cirrus_ttm.c7
-rw-r--r--drivers/gpu/drm/mgag200/mgag200_ttm.c7
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_ttm.c8
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c5
-rw-r--r--drivers/i2c/busses/Kconfig12
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c17
-rw-r--r--drivers/i2c/busses/i2c-digicolor.c1
-rw-r--r--drivers/i2c/busses/i2c-i801.c16
-rw-r--r--drivers/i2c/busses/i2c-imx.c11
-rw-r--r--drivers/i2c/busses/i2c-jz4780.c1
-rw-r--r--drivers/i2c/busses/i2c-rk3x.c2
-rw-r--r--drivers/i2c/busses/i2c-xgene-slimpro.c2
-rw-r--r--drivers/i2c/busses/i2c-xlp9xx.c1
-rw-r--r--drivers/i2c/busses/i2c-xlr.c1
-rw-r--r--drivers/i2c/i2c-core.c11
-rw-r--r--drivers/ipack/ipack.c2
-rw-r--r--drivers/md/dm-raid.c15
-rw-r--r--drivers/md/dm-raid1.c22
-rw-r--r--drivers/md/dm-rq.c7
-rw-r--r--drivers/md/dm-table.c24
-rw-r--r--drivers/md/dm.c4
-rw-r--r--drivers/misc/cxl/api.c2
-rw-r--r--drivers/misc/cxl/file.c22
-rw-r--r--drivers/misc/sgi-gru/grumain.c2
-rw-r--r--drivers/nvdimm/Kconfig2
-rw-r--r--drivers/nvdimm/namespace_devs.c14
-rw-r--r--drivers/nvdimm/pmem.c8
-rw-r--r--drivers/pci/msi.c2
-rw-r--r--drivers/s390/block/dasd_eckd.c4
-rw-r--r--drivers/s390/cio/chp.c6
-rw-r--r--drivers/scsi/NCR5380.c6
-rw-r--r--drivers/scsi/be2iscsi/be_main.c37
-rw-r--r--drivers/scsi/libiscsi.c4
-rw-r--r--drivers/thermal/intel_pch_thermal.c60
-rw-r--r--drivers/thermal/intel_powerclamp.c14
-rw-r--r--drivers/usb/chipidea/host.c2
-rw-r--r--drivers/usb/dwc2/core.c11
-rw-r--r--drivers/usb/dwc2/core.h7
-rw-r--r--drivers/usb/dwc2/gadget.c53
-rw-r--r--drivers/usb/dwc3/gadget.c26
-rw-r--r--drivers/usb/gadget/function/f_fs.c107
-rw-r--r--drivers/usb/gadget/function/u_ether.c5
-rw-r--r--drivers/usb/gadget/udc/atmel_usba_udc.c2
-rw-r--r--drivers/usb/host/ehci-platform.c2
-rw-r--r--drivers/usb/host/ohci-at91.c9
-rw-r--r--drivers/usb/host/ohci-hcd.c2
-rw-r--r--drivers/usb/host/xhci-hub.c41
-rw-r--r--drivers/usb/host/xhci-pci.c10
-rw-r--r--drivers/usb/host/xhci.h3
-rw-r--r--drivers/usb/musb/musb_gadget.c4
-rw-r--r--drivers/usb/musb/omap2430.c7
-rw-r--r--drivers/usb/renesas_usbhs/rcar3.c8
-rw-r--r--drivers/usb/serial/cp210x.c4
-rw-r--r--drivers/usb/serial/ftdi_sio.c3
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h5
-rw-r--r--drivers/usb/serial/usb-serial.c3
-rw-r--r--drivers/usb/wusbcore/crypto.c61
-rw-r--r--drivers/xen/manage.c45
-rw-r--r--drivers/xen/xenbus/xenbus_dev_frontend.c4
-rw-r--r--drivers/xen/xenbus/xenbus_probe_frontend.c4
-rw-r--r--fs/btrfs/send.c58
-rw-r--r--fs/btrfs/tree-log.c20
-rw-r--r--fs/exofs/dir.c2
-rw-r--r--fs/iomap.c5
-rw-r--r--fs/orangefs/dcache.c5
-rw-r--r--fs/orangefs/file.c14
-rw-r--r--fs/orangefs/namei.c8
-rw-r--r--fs/orangefs/orangefs-kernel.h7
-rw-r--r--fs/proc/base.c21
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c418
-rw-r--r--fs/xfs/libxfs/xfs_bmap.h8
-rw-r--r--fs/xfs/libxfs/xfs_btree.c2
-rw-r--r--fs/xfs/libxfs/xfs_dquot_buf.c3
-rw-r--r--fs/xfs/libxfs/xfs_format.h1
-rw-r--r--fs/xfs/libxfs/xfs_inode_buf.c13
-rw-r--r--fs/xfs/libxfs/xfs_inode_buf.h2
-rw-r--r--fs/xfs/xfs_file.c232
-rw-r--r--fs/xfs/xfs_icache.c8
-rw-r--r--fs/xfs/xfs_iomap.c57
-rw-r--r--fs/xfs/xfs_mount.c1
-rw-r--r--fs/xfs/xfs_reflink.c499
-rw-r--r--fs/xfs/xfs_reflink.h11
-rw-r--r--fs/xfs/xfs_sysfs.c4
-rw-r--r--fs/xfs/xfs_trace.h4
-rw-r--r--include/asm-generic/export.h2
-rw-r--r--include/linux/acpi.h1
-rw-r--r--include/linux/clk-provider.h2
-rw-r--r--include/linux/io.h22
-rw-r--r--include/linux/iomap.h17
-rw-r--r--include/linux/kconfig.h5
-rw-r--r--include/linux/mm.h4
-rw-r--r--include/linux/mmzone.h30
-rw-r--r--include/linux/perf_event.h1
-rw-r--r--ipc/msgutil.c4
-rw-r--r--kernel/events/core.c23
-rw-r--r--kernel/kcov.c9
-rw-r--r--kernel/power/suspend.c4
-rw-r--r--kernel/sched/core.c16
-rw-r--r--kernel/sched/fair.c3
-rw-r--r--kernel/sched/wait.c10
-rw-r--r--kernel/softirq.c2
-rw-r--r--kernel/time/timer.c74
-rw-r--r--lib/Kconfig.debug1
-rw-r--r--lib/genalloc.c3
-rw-r--r--lib/stackdepot.c2
-rw-r--r--mm/Kconfig2
-rw-r--r--mm/filemap.c4
-rw-r--r--mm/gup.c3
-rw-r--r--mm/kmemleak.c7
-rw-r--r--mm/list_lru.c2
-rw-r--r--mm/memcontrol.c9
-rw-r--r--mm/memory_hotplug.c29
-rw-r--r--mm/nommu.c2
-rw-r--r--mm/page_alloc.c131
-rw-r--r--mm/slab.c45
-rw-r--r--mm/slab.h1
-rw-r--r--mm/vmscan.c2
-rw-r--r--security/keys/Kconfig2
-rw-r--r--security/keys/big_key.c59
-rw-r--r--security/keys/proc.c2
-rw-r--r--sound/core/seq/seq_timer.c4
-rw-r--r--sound/pci/asihpi/hpioctl.c2
-rw-r--r--sound/pci/hda/hda_intel.c7
-rw-r--r--sound/pci/hda/patch_realtek.c30
-rw-r--r--sound/usb/quirks-table.h17
-rw-r--r--tools/objtool/builtin-check.c2
-rw-r--r--virt/kvm/kvm_main.c10
227 files changed, 2308 insertions, 1758 deletions
diff --git a/CREDITS b/CREDITS
index 513aaa3546bf..837367624e45 100644
--- a/CREDITS
+++ b/CREDITS
@@ -1864,10 +1864,11 @@ S: The Netherlands
1864 1864
1865N: Martin Kepplinger 1865N: Martin Kepplinger
1866E: martink@posteo.de 1866E: martink@posteo.de
1867E: martin.kepplinger@theobroma-systems.com 1867E: martin.kepplinger@ginzinger.com
1868W: http://www.martinkepplinger.com 1868W: http://www.martinkepplinger.com
1869D: mma8452 accelerators iio driver 1869D: mma8452 accelerators iio driver
1870D: Kernel cleanups 1870D: pegasus_notetaker input driver
1871D: Kernel fixes and cleanups
1871S: Garnisonstraße 26 1872S: Garnisonstraße 26
1872S: 4020 Linz 1873S: 4020 Linz
1873S: Austria 1874S: Austria
diff --git a/Documentation/device-mapper/dm-raid.txt b/Documentation/device-mapper/dm-raid.txt
index e5b6497116f4..c75b64a85859 100644
--- a/Documentation/device-mapper/dm-raid.txt
+++ b/Documentation/device-mapper/dm-raid.txt
@@ -309,3 +309,4 @@ Version History
309 with a reshape in progress. 309 with a reshape in progress.
3101.9.0 Add support for RAID level takeover/reshape/region size 3101.9.0 Add support for RAID level takeover/reshape/region size
311 and set size reduction. 311 and set size reduction.
3121.9.1 Fix activation of existing RAID 4/10 mapped devices
diff --git a/Documentation/devicetree/bindings/clock/uniphier-clock.txt b/Documentation/devicetree/bindings/clock/uniphier-clock.txt
index c7179d3b5c33..812163060fa3 100644
--- a/Documentation/devicetree/bindings/clock/uniphier-clock.txt
+++ b/Documentation/devicetree/bindings/clock/uniphier-clock.txt
@@ -24,7 +24,7 @@ Example:
24 reg = <0x61840000 0x4000>; 24 reg = <0x61840000 0x4000>;
25 25
26 clock { 26 clock {
27 compatible = "socionext,uniphier-ld20-clock"; 27 compatible = "socionext,uniphier-ld11-clock";
28 #clock-cells = <1>; 28 #clock-cells = <1>;
29 }; 29 };
30 30
@@ -43,8 +43,8 @@ Provided clocks:
4321: USB3 ch1 PHY1 4321: USB3 ch1 PHY1
44 44
45 45
46Media I/O (MIO) clock 46Media I/O (MIO) clock, SD clock
47--------------------- 47-------------------------------
48 48
49Required properties: 49Required properties:
50- compatible: should be one of the following: 50- compatible: should be one of the following:
@@ -52,10 +52,10 @@ Required properties:
52 "socionext,uniphier-ld4-mio-clock" - for LD4 SoC. 52 "socionext,uniphier-ld4-mio-clock" - for LD4 SoC.
53 "socionext,uniphier-pro4-mio-clock" - for Pro4 SoC. 53 "socionext,uniphier-pro4-mio-clock" - for Pro4 SoC.
54 "socionext,uniphier-sld8-mio-clock" - for sLD8 SoC. 54 "socionext,uniphier-sld8-mio-clock" - for sLD8 SoC.
55 "socionext,uniphier-pro5-mio-clock" - for Pro5 SoC. 55 "socionext,uniphier-pro5-sd-clock" - for Pro5 SoC.
56 "socionext,uniphier-pxs2-mio-clock" - for PXs2/LD6b SoC. 56 "socionext,uniphier-pxs2-sd-clock" - for PXs2/LD6b SoC.
57 "socionext,uniphier-ld11-mio-clock" - for LD11 SoC. 57 "socionext,uniphier-ld11-mio-clock" - for LD11 SoC.
58 "socionext,uniphier-ld20-mio-clock" - for LD20 SoC. 58 "socionext,uniphier-ld20-sd-clock" - for LD20 SoC.
59- #clock-cells: should be 1. 59- #clock-cells: should be 1.
60 60
61Example: 61Example:
@@ -66,7 +66,7 @@ Example:
66 reg = <0x59810000 0x800>; 66 reg = <0x59810000 0x800>;
67 67
68 clock { 68 clock {
69 compatible = "socionext,uniphier-ld20-mio-clock"; 69 compatible = "socionext,uniphier-ld11-mio-clock";
70 #clock-cells = <1>; 70 #clock-cells = <1>;
71 }; 71 };
72 72
@@ -112,7 +112,7 @@ Example:
112 reg = <0x59820000 0x200>; 112 reg = <0x59820000 0x200>;
113 113
114 clock { 114 clock {
115 compatible = "socionext,uniphier-ld20-peri-clock"; 115 compatible = "socionext,uniphier-ld11-peri-clock";
116 #clock-cells = <1>; 116 #clock-cells = <1>;
117 }; 117 };
118 118
diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt b/Documentation/devicetree/bindings/usb/dwc2.txt
index 455f2c310a1b..2c30a5479069 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -28,10 +28,7 @@ Refer to phy/phy-bindings.txt for generic phy consumer properties
28- g-use-dma: enable dma usage in gadget driver. 28- g-use-dma: enable dma usage in gadget driver.
29- g-rx-fifo-size: size of rx fifo size in gadget mode. 29- g-rx-fifo-size: size of rx fifo size in gadget mode.
30- g-np-tx-fifo-size: size of non-periodic tx fifo size in gadget mode. 30- g-np-tx-fifo-size: size of non-periodic tx fifo size in gadget mode.
31 31- g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0) in gadget mode.
32Deprecated properties:
33- g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0)
34 in gadget mode.
35 32
36Example: 33Example:
37 34
diff --git a/Documentation/gpio/board.txt b/Documentation/gpio/board.txt
index 40884c4fe40c..a0f61898d493 100644
--- a/Documentation/gpio/board.txt
+++ b/Documentation/gpio/board.txt
@@ -6,7 +6,7 @@ Note that it only applies to the new descriptor-based interface. For a
6description of the deprecated integer-based GPIO interface please refer to 6description of the deprecated integer-based GPIO interface please refer to
7gpio-legacy.txt (actually, there is no real mapping possible with the old 7gpio-legacy.txt (actually, there is no real mapping possible with the old
8interface; you just fetch an integer from somewhere and request the 8interface; you just fetch an integer from somewhere and request the
9corresponding GPIO. 9corresponding GPIO).
10 10
11All platforms can enable the GPIO library, but if the platform strictly 11All platforms can enable the GPIO library, but if the platform strictly
12requires GPIO functionality to be present, it needs to select GPIOLIB from its 12requires GPIO functionality to be present, it needs to select GPIOLIB from its
@@ -162,6 +162,9 @@ The driver controlling "foo.0" will then be able to obtain its GPIOs as follows:
162 162
163Since the "led" GPIOs are mapped as active-high, this example will switch their 163Since the "led" GPIOs are mapped as active-high, this example will switch their
164signals to 1, i.e. enabling the LEDs. And for the "power" GPIO, which is mapped 164signals to 1, i.e. enabling the LEDs. And for the "power" GPIO, which is mapped
165as active-low, its actual signal will be 0 after this code. Contrary to the legacy 165as active-low, its actual signal will be 0 after this code. Contrary to the
166integer GPIO interface, the active-low property is handled during mapping and is 166legacy integer GPIO interface, the active-low property is handled during
167thus transparent to GPIO consumers. 167mapping and is thus transparent to GPIO consumers.
168
169A set of functions such as gpiod_set_value() is available to work with
170the new descriptor-oriented interface.
diff --git a/MAINTAINERS b/MAINTAINERS
index c44795306342..f30b8ea700fd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8100,6 +8100,7 @@ S: Maintained
8100F: drivers/media/dvb-frontends/mn88473* 8100F: drivers/media/dvb-frontends/mn88473*
8101 8101
8102MODULE SUPPORT 8102MODULE SUPPORT
8103M: Jessica Yu <jeyu@redhat.com>
8103M: Rusty Russell <rusty@rustcorp.com.au> 8104M: Rusty Russell <rusty@rustcorp.com.au>
8104S: Maintained 8105S: Maintained
8105F: include/linux/module.h 8106F: include/linux/module.h
diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index ecd12379e2cd..bd204bfa29ed 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -41,6 +41,8 @@ config ARC
41 select PERF_USE_VMALLOC 41 select PERF_USE_VMALLOC
42 select HAVE_DEBUG_STACKOVERFLOW 42 select HAVE_DEBUG_STACKOVERFLOW
43 select HAVE_GENERIC_DMA_COHERENT 43 select HAVE_GENERIC_DMA_COHERENT
44 select HAVE_KERNEL_GZIP
45 select HAVE_KERNEL_LZMA
44 46
45config MIGHT_HAVE_PCI 47config MIGHT_HAVE_PCI
46 bool 48 bool
@@ -186,14 +188,6 @@ if SMP
186config ARC_HAS_COH_CACHES 188config ARC_HAS_COH_CACHES
187 def_bool n 189 def_bool n
188 190
189config ARC_MCIP
190 bool "ARConnect Multicore IP (MCIP) Support "
191 depends on ISA_ARCV2
192 help
193 This IP block enables SMP in ARC-HS38 cores.
194 It provides for cross-core interrupts, multi-core debug
195 hardware semaphores, shared memory,....
196
197config NR_CPUS 191config NR_CPUS
198 int "Maximum number of CPUs (2-4096)" 192 int "Maximum number of CPUs (2-4096)"
199 range 2 4096 193 range 2 4096
@@ -211,6 +205,15 @@ config ARC_SMP_HALT_ON_RESET
211 205
212endif #SMP 206endif #SMP
213 207
208config ARC_MCIP
209 bool "ARConnect Multicore IP (MCIP) Support "
210 depends on ISA_ARCV2
211 default y if SMP
212 help
213 This IP block enables SMP in ARC-HS38 cores.
214 It provides for cross-core interrupts, multi-core debug
215 hardware semaphores, shared memory,....
216
214menuconfig ARC_CACHE 217menuconfig ARC_CACHE
215 bool "Enable Cache Support" 218 bool "Enable Cache Support"
216 default y 219 default y
@@ -537,14 +540,6 @@ config ARC_DBG_TLB_PARANOIA
537 bool "Paranoia Checks in Low Level TLB Handlers" 540 bool "Paranoia Checks in Low Level TLB Handlers"
538 default n 541 default n
539 542
540config ARC_DBG_TLB_MISS_COUNT
541 bool "Profile TLB Misses"
542 default n
543 select DEBUG_FS
544 help
545 Counts number of I and D TLB Misses and exports them via Debugfs
546 The counters can be cleared via Debugfs as well
547
548endif 543endif
549 544
550config ARC_UBOOT_SUPPORT 545config ARC_UBOOT_SUPPORT
diff --git a/arch/arc/Makefile b/arch/arc/Makefile
index aa82d13d4213..864adad52280 100644
--- a/arch/arc/Makefile
+++ b/arch/arc/Makefile
@@ -50,9 +50,6 @@ atleast_gcc44 := $(call cc-ifversion, -ge, 0404, y)
50 50
51cflags-$(atleast_gcc44) += -fsection-anchors 51cflags-$(atleast_gcc44) += -fsection-anchors
52 52
53cflags-$(CONFIG_ARC_HAS_LLSC) += -mlock
54cflags-$(CONFIG_ARC_HAS_SWAPE) += -mswape
55
56ifdef CONFIG_ISA_ARCV2 53ifdef CONFIG_ISA_ARCV2
57 54
58ifndef CONFIG_ARC_HAS_LL64 55ifndef CONFIG_ARC_HAS_LL64
diff --git a/arch/arc/boot/Makefile b/arch/arc/boot/Makefile
index e597cb34c16a..f94cf151e06a 100644
--- a/arch/arc/boot/Makefile
+++ b/arch/arc/boot/Makefile
@@ -14,9 +14,15 @@ UIMAGE_ENTRYADDR = $(LINUX_START_TEXT)
14 14
15suffix-y := bin 15suffix-y := bin
16suffix-$(CONFIG_KERNEL_GZIP) := gz 16suffix-$(CONFIG_KERNEL_GZIP) := gz
17suffix-$(CONFIG_KERNEL_LZMA) := lzma
17 18
18targets += uImage uImage.bin uImage.gz 19targets += uImage
19extra-y += vmlinux.bin vmlinux.bin.gz 20targets += uImage.bin
21targets += uImage.gz
22targets += uImage.lzma
23extra-y += vmlinux.bin
24extra-y += vmlinux.bin.gz
25extra-y += vmlinux.bin.lzma
20 26
21$(obj)/vmlinux.bin: vmlinux FORCE 27$(obj)/vmlinux.bin: vmlinux FORCE
22 $(call if_changed,objcopy) 28 $(call if_changed,objcopy)
@@ -24,12 +30,18 @@ $(obj)/vmlinux.bin: vmlinux FORCE
24$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE 30$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
25 $(call if_changed,gzip) 31 $(call if_changed,gzip)
26 32
33$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
34 $(call if_changed,lzma)
35
27$(obj)/uImage.bin: $(obj)/vmlinux.bin FORCE 36$(obj)/uImage.bin: $(obj)/vmlinux.bin FORCE
28 $(call if_changed,uimage,none) 37 $(call if_changed,uimage,none)
29 38
30$(obj)/uImage.gz: $(obj)/vmlinux.bin.gz FORCE 39$(obj)/uImage.gz: $(obj)/vmlinux.bin.gz FORCE
31 $(call if_changed,uimage,gzip) 40 $(call if_changed,uimage,gzip)
32 41
42$(obj)/uImage.lzma: $(obj)/vmlinux.bin.lzma FORCE
43 $(call if_changed,uimage,lzma)
44
33$(obj)/uImage: $(obj)/uImage.$(suffix-y) 45$(obj)/uImage: $(obj)/uImage.$(suffix-y)
34 @ln -sf $(notdir $<) $@ 46 @ln -sf $(notdir $<) $@
35 @echo ' Image $@ is ready' 47 @echo ' Image $@ is ready'
diff --git a/arch/arc/include/asm/arcregs.h b/arch/arc/include/asm/arcregs.h
index db25c65155cb..7f3f9f63708c 100644
--- a/arch/arc/include/asm/arcregs.h
+++ b/arch/arc/include/asm/arcregs.h
@@ -349,10 +349,11 @@ struct cpuinfo_arc {
349 struct cpuinfo_arc_bpu bpu; 349 struct cpuinfo_arc_bpu bpu;
350 struct bcr_identity core; 350 struct bcr_identity core;
351 struct bcr_isa isa; 351 struct bcr_isa isa;
352 const char *details, *name;
352 unsigned int vec_base; 353 unsigned int vec_base;
353 struct cpuinfo_arc_ccm iccm, dccm; 354 struct cpuinfo_arc_ccm iccm, dccm;
354 struct { 355 struct {
355 unsigned int swap:1, norm:1, minmax:1, barrel:1, crc:1, pad1:3, 356 unsigned int swap:1, norm:1, minmax:1, barrel:1, crc:1, swape:1, pad1:2,
356 fpu_sp:1, fpu_dp:1, pad2:6, 357 fpu_sp:1, fpu_dp:1, pad2:6,
357 debug:1, ap:1, smart:1, rtt:1, pad3:4, 358 debug:1, ap:1, smart:1, rtt:1, pad3:4,
358 timer0:1, timer1:1, rtc:1, gfrc:1, pad4:4; 359 timer0:1, timer1:1, rtc:1, gfrc:1, pad4:4;
diff --git a/arch/arc/include/asm/cache.h b/arch/arc/include/asm/cache.h
index fb781e34f322..b3410ff6a62d 100644
--- a/arch/arc/include/asm/cache.h
+++ b/arch/arc/include/asm/cache.h
@@ -53,7 +53,7 @@ extern void arc_cache_init(void);
53extern char *arc_cache_mumbojumbo(int cpu_id, char *buf, int len); 53extern char *arc_cache_mumbojumbo(int cpu_id, char *buf, int len);
54extern void read_decode_cache_bcr(void); 54extern void read_decode_cache_bcr(void);
55 55
56extern int ioc_exists; 56extern int ioc_enable;
57extern unsigned long perip_base, perip_end; 57extern unsigned long perip_base, perip_end;
58 58
59#endif /* !__ASSEMBLY__ */ 59#endif /* !__ASSEMBLY__ */
diff --git a/arch/arc/include/asm/elf.h b/arch/arc/include/asm/elf.h
index 7096f97a1434..aa2d6da9d187 100644
--- a/arch/arc/include/asm/elf.h
+++ b/arch/arc/include/asm/elf.h
@@ -54,7 +54,7 @@ extern int elf_check_arch(const struct elf32_hdr *);
54 * the loader. We need to make sure that it is out of the way of the program 54 * the loader. We need to make sure that it is out of the way of the program
55 * that it will "exec", and that there is sufficient room for the brk. 55 * that it will "exec", and that there is sufficient room for the brk.
56 */ 56 */
57#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3) 57#define ELF_ET_DYN_BASE (2UL * TASK_SIZE / 3)
58 58
59/* 59/*
60 * When the program starts, a1 contains a pointer to a function to be 60 * When the program starts, a1 contains a pointer to a function to be
diff --git a/arch/arc/include/asm/mcip.h b/arch/arc/include/asm/mcip.h
index 847e3bbe387f..c8fbe4114bad 100644
--- a/arch/arc/include/asm/mcip.h
+++ b/arch/arc/include/asm/mcip.h
@@ -55,6 +55,22 @@ struct mcip_cmd {
55#define IDU_M_DISTRI_DEST 0x2 55#define IDU_M_DISTRI_DEST 0x2
56}; 56};
57 57
58struct mcip_bcr {
59#ifdef CONFIG_CPU_BIG_ENDIAN
60 unsigned int pad3:8,
61 idu:1, llm:1, num_cores:6,
62 iocoh:1, gfrc:1, dbg:1, pad2:1,
63 msg:1, sem:1, ipi:1, pad:1,
64 ver:8;
65#else
66 unsigned int ver:8,
67 pad:1, ipi:1, sem:1, msg:1,
68 pad2:1, dbg:1, gfrc:1, iocoh:1,
69 num_cores:6, llm:1, idu:1,
70 pad3:8;
71#endif
72};
73
58/* 74/*
59 * MCIP programming model 75 * MCIP programming model
60 * 76 *
diff --git a/arch/arc/include/asm/module.h b/arch/arc/include/asm/module.h
index 518222bb3f8e..6e91d8b339c3 100644
--- a/arch/arc/include/asm/module.h
+++ b/arch/arc/include/asm/module.h
@@ -18,6 +18,7 @@
18struct mod_arch_specific { 18struct mod_arch_specific {
19 void *unw_info; 19 void *unw_info;
20 int unw_sec_idx; 20 int unw_sec_idx;
21 const char *secstr;
21}; 22};
22#endif 23#endif
23 24
diff --git a/arch/arc/include/asm/setup.h b/arch/arc/include/asm/setup.h
index 48b37c693db3..cb954cdab070 100644
--- a/arch/arc/include/asm/setup.h
+++ b/arch/arc/include/asm/setup.h
@@ -27,11 +27,6 @@ struct id_to_str {
27 const char *str; 27 const char *str;
28}; 28};
29 29
30struct cpuinfo_data {
31 struct id_to_str info;
32 int up_range;
33};
34
35extern int root_mountflags, end_mem; 30extern int root_mountflags, end_mem;
36 31
37void setup_processor(void); 32void setup_processor(void);
@@ -43,5 +38,6 @@ void __init setup_arch_memory(void);
43#define IS_USED_RUN(v) ((v) ? "" : "(not used) ") 38#define IS_USED_RUN(v) ((v) ? "" : "(not used) ")
44#define IS_USED_CFG(cfg) IS_USED_RUN(IS_ENABLED(cfg)) 39#define IS_USED_CFG(cfg) IS_USED_RUN(IS_ENABLED(cfg))
45#define IS_AVAIL2(v, s, cfg) IS_AVAIL1(v, s), IS_AVAIL1(v, IS_USED_CFG(cfg)) 40#define IS_AVAIL2(v, s, cfg) IS_AVAIL1(v, s), IS_AVAIL1(v, IS_USED_CFG(cfg))
41#define IS_AVAIL3(v, v2, s) IS_AVAIL1(v, s), IS_AVAIL1(v, IS_DISABLED_RUN(v2))
46 42
47#endif /* __ASMARC_SETUP_H */ 43#endif /* __ASMARC_SETUP_H */
diff --git a/arch/arc/include/asm/syscalls.h b/arch/arc/include/asm/syscalls.h
index e56f9fcc5581..772b67ca56e7 100644
--- a/arch/arc/include/asm/syscalls.h
+++ b/arch/arc/include/asm/syscalls.h
@@ -17,6 +17,7 @@ int sys_clone_wrapper(int, int, int, int, int);
17int sys_cacheflush(uint32_t, uint32_t uint32_t); 17int sys_cacheflush(uint32_t, uint32_t uint32_t);
18int sys_arc_settls(void *); 18int sys_arc_settls(void *);
19int sys_arc_gettls(void); 19int sys_arc_gettls(void);
20int sys_arc_usr_cmpxchg(int *, int, int);
20 21
21#include <asm-generic/syscalls.h> 22#include <asm-generic/syscalls.h>
22 23
diff --git a/arch/arc/include/uapi/asm/unistd.h b/arch/arc/include/uapi/asm/unistd.h
index 41fa2ec9e02c..9a34136d84b2 100644
--- a/arch/arc/include/uapi/asm/unistd.h
+++ b/arch/arc/include/uapi/asm/unistd.h
@@ -27,18 +27,19 @@
27 27
28#define NR_syscalls __NR_syscalls 28#define NR_syscalls __NR_syscalls
29 29
30/* Generic syscall (fs/filesystems.c - lost in asm-generic/unistd.h */
31#define __NR_sysfs (__NR_arch_specific_syscall + 3)
32
30/* ARC specific syscall */ 33/* ARC specific syscall */
31#define __NR_cacheflush (__NR_arch_specific_syscall + 0) 34#define __NR_cacheflush (__NR_arch_specific_syscall + 0)
32#define __NR_arc_settls (__NR_arch_specific_syscall + 1) 35#define __NR_arc_settls (__NR_arch_specific_syscall + 1)
33#define __NR_arc_gettls (__NR_arch_specific_syscall + 2) 36#define __NR_arc_gettls (__NR_arch_specific_syscall + 2)
37#define __NR_arc_usr_cmpxchg (__NR_arch_specific_syscall + 4)
34 38
35__SYSCALL(__NR_cacheflush, sys_cacheflush) 39__SYSCALL(__NR_cacheflush, sys_cacheflush)
36__SYSCALL(__NR_arc_settls, sys_arc_settls) 40__SYSCALL(__NR_arc_settls, sys_arc_settls)
37__SYSCALL(__NR_arc_gettls, sys_arc_gettls) 41__SYSCALL(__NR_arc_gettls, sys_arc_gettls)
38 42__SYSCALL(__NR_arc_usr_cmpxchg, sys_arc_usr_cmpxchg)
39
40/* Generic syscall (fs/filesystems.c - lost in asm-generic/unistd.h */
41#define __NR_sysfs (__NR_arch_specific_syscall + 3)
42__SYSCALL(__NR_sysfs, sys_sysfs) 43__SYSCALL(__NR_sysfs, sys_sysfs)
43 44
44#undef __SYSCALL 45#undef __SYSCALL
diff --git a/arch/arc/kernel/mcip.c b/arch/arc/kernel/mcip.c
index 72f9179b1a24..c424d5abc318 100644
--- a/arch/arc/kernel/mcip.c
+++ b/arch/arc/kernel/mcip.c
@@ -15,11 +15,12 @@
15#include <asm/mcip.h> 15#include <asm/mcip.h>
16#include <asm/setup.h> 16#include <asm/setup.h>
17 17
18static char smp_cpuinfo_buf[128];
19static int idu_detected;
20
21static DEFINE_RAW_SPINLOCK(mcip_lock); 18static DEFINE_RAW_SPINLOCK(mcip_lock);
22 19
20#ifdef CONFIG_SMP
21
22static char smp_cpuinfo_buf[128];
23
23static void mcip_setup_per_cpu(int cpu) 24static void mcip_setup_per_cpu(int cpu)
24{ 25{
25 smp_ipi_irq_setup(cpu, IPI_IRQ); 26 smp_ipi_irq_setup(cpu, IPI_IRQ);
@@ -86,21 +87,7 @@ static void mcip_ipi_clear(int irq)
86 87
87static void mcip_probe_n_setup(void) 88static void mcip_probe_n_setup(void)
88{ 89{
89 struct mcip_bcr { 90 struct mcip_bcr mp;
90#ifdef CONFIG_CPU_BIG_ENDIAN
91 unsigned int pad3:8,
92 idu:1, llm:1, num_cores:6,
93 iocoh:1, gfrc:1, dbg:1, pad2:1,
94 msg:1, sem:1, ipi:1, pad:1,
95 ver:8;
96#else
97 unsigned int ver:8,
98 pad:1, ipi:1, sem:1, msg:1,
99 pad2:1, dbg:1, gfrc:1, iocoh:1,
100 num_cores:6, llm:1, idu:1,
101 pad3:8;
102#endif
103 } mp;
104 91
105 READ_BCR(ARC_REG_MCIP_BCR, mp); 92 READ_BCR(ARC_REG_MCIP_BCR, mp);
106 93
@@ -114,7 +101,6 @@ static void mcip_probe_n_setup(void)
114 IS_AVAIL1(mp.gfrc, "GFRC")); 101 IS_AVAIL1(mp.gfrc, "GFRC"));
115 102
116 cpuinfo_arc700[0].extn.gfrc = mp.gfrc; 103 cpuinfo_arc700[0].extn.gfrc = mp.gfrc;
117 idu_detected = mp.idu;
118 104
119 if (mp.dbg) { 105 if (mp.dbg) {
120 __mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, 0xf); 106 __mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, 0xf);
@@ -130,6 +116,8 @@ struct plat_smp_ops plat_smp_ops = {
130 .ipi_clear = mcip_ipi_clear, 116 .ipi_clear = mcip_ipi_clear,
131}; 117};
132 118
119#endif
120
133/*************************************************************************** 121/***************************************************************************
134 * ARCv2 Interrupt Distribution Unit (IDU) 122 * ARCv2 Interrupt Distribution Unit (IDU)
135 * 123 *
@@ -295,8 +283,11 @@ idu_of_init(struct device_node *intc, struct device_node *parent)
295 /* Read IDU BCR to confirm nr_irqs */ 283 /* Read IDU BCR to confirm nr_irqs */
296 int nr_irqs = of_irq_count(intc); 284 int nr_irqs = of_irq_count(intc);
297 int i, irq; 285 int i, irq;
286 struct mcip_bcr mp;
287
288 READ_BCR(ARC_REG_MCIP_BCR, mp);
298 289
299 if (!idu_detected) 290 if (!mp.idu)
300 panic("IDU not detected, but DeviceTree using it"); 291 panic("IDU not detected, but DeviceTree using it");
301 292
302 pr_info("MCIP: IDU referenced from Devicetree %d irqs\n", nr_irqs); 293 pr_info("MCIP: IDU referenced from Devicetree %d irqs\n", nr_irqs);
diff --git a/arch/arc/kernel/module.c b/arch/arc/kernel/module.c
index 9a2849756022..42e964db2967 100644
--- a/arch/arc/kernel/module.c
+++ b/arch/arc/kernel/module.c
@@ -30,17 +30,9 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
30 char *secstr, struct module *mod) 30 char *secstr, struct module *mod)
31{ 31{
32#ifdef CONFIG_ARC_DW2_UNWIND 32#ifdef CONFIG_ARC_DW2_UNWIND
33 int i;
34
35 mod->arch.unw_sec_idx = 0; 33 mod->arch.unw_sec_idx = 0;
36 mod->arch.unw_info = NULL; 34 mod->arch.unw_info = NULL;
37 35 mod->arch.secstr = secstr;
38 for (i = 1; i < hdr->e_shnum; i++) {
39 if (strcmp(secstr+sechdrs[i].sh_name, ".eh_frame") == 0) {
40 mod->arch.unw_sec_idx = i;
41 break;
42 }
43 }
44#endif 36#endif
45 return 0; 37 return 0;
46} 38}
@@ -59,29 +51,33 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
59 unsigned int relsec, /* sec index for relo sec */ 51 unsigned int relsec, /* sec index for relo sec */
60 struct module *module) 52 struct module *module)
61{ 53{
62 int i, n; 54 int i, n, relo_type;
63 Elf32_Rela *rel_entry = (void *)sechdrs[relsec].sh_addr; 55 Elf32_Rela *rel_entry = (void *)sechdrs[relsec].sh_addr;
64 Elf32_Sym *sym_entry, *sym_sec; 56 Elf32_Sym *sym_entry, *sym_sec;
65 Elf32_Addr relocation; 57 Elf32_Addr relocation, location, tgt_addr;
66 Elf32_Addr location; 58 unsigned int tgtsec;
67 Elf32_Addr sec_to_patch; 59
68 int relo_type; 60 /*
69 61 * @relsec has relocations e.g. .rela.init.text
70 sec_to_patch = sechdrs[sechdrs[relsec].sh_info].sh_addr; 62 * @tgtsec is section to patch e.g. .init.text
63 */
64 tgtsec = sechdrs[relsec].sh_info;
65 tgt_addr = sechdrs[tgtsec].sh_addr;
71 sym_sec = (Elf32_Sym *) sechdrs[symindex].sh_addr; 66 sym_sec = (Elf32_Sym *) sechdrs[symindex].sh_addr;
72 n = sechdrs[relsec].sh_size / sizeof(*rel_entry); 67 n = sechdrs[relsec].sh_size / sizeof(*rel_entry);
73 68
74 pr_debug("\n========== Module Sym reloc ===========================\n"); 69 pr_debug("\nSection to fixup %s @%x\n",
75 pr_debug("Section to fixup %x\n", sec_to_patch); 70 module->arch.secstr + sechdrs[tgtsec].sh_name, tgt_addr);
76 pr_debug("=========================================================\n"); 71 pr_debug("=========================================================\n");
77 pr_debug("rela->r_off | rela->addend | sym->st_value | ADDR | VALUE\n"); 72 pr_debug("r_off\tr_add\tst_value ADDRESS VALUE\n");
78 pr_debug("=========================================================\n"); 73 pr_debug("=========================================================\n");
79 74
80 /* Loop thru entries in relocation section */ 75 /* Loop thru entries in relocation section */
81 for (i = 0; i < n; i++) { 76 for (i = 0; i < n; i++) {
77 const char *s;
82 78
83 /* This is where to make the change */ 79 /* This is where to make the change */
84 location = sec_to_patch + rel_entry[i].r_offset; 80 location = tgt_addr + rel_entry[i].r_offset;
85 81
86 /* This is the symbol it is referring to. Note that all 82 /* This is the symbol it is referring to. Note that all
87 undefined symbols have been resolved. */ 83 undefined symbols have been resolved. */
@@ -89,10 +85,15 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
89 85
90 relocation = sym_entry->st_value + rel_entry[i].r_addend; 86 relocation = sym_entry->st_value + rel_entry[i].r_addend;
91 87
92 pr_debug("\t%x\t\t%x\t\t%x %x %x [%s]\n", 88 if (sym_entry->st_name == 0 && ELF_ST_TYPE (sym_entry->st_info) == STT_SECTION) {
93 rel_entry[i].r_offset, rel_entry[i].r_addend, 89 s = module->arch.secstr + sechdrs[sym_entry->st_shndx].sh_name;
94 sym_entry->st_value, location, relocation, 90 } else {
95 strtab + sym_entry->st_name); 91 s = strtab + sym_entry->st_name;
92 }
93
94 pr_debug(" %x\t%x\t%x %x %x [%s]\n",
95 rel_entry[i].r_offset, rel_entry[i].r_addend,
96 sym_entry->st_value, location, relocation, s);
96 97
97 /* This assumes modules are built with -mlong-calls 98 /* This assumes modules are built with -mlong-calls
98 * so any branches/jumps are absolute 32 bit jmps 99 * so any branches/jumps are absolute 32 bit jmps
@@ -111,6 +112,10 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
111 goto relo_err; 112 goto relo_err;
112 113
113 } 114 }
115
116 if (strcmp(module->arch.secstr+sechdrs[tgtsec].sh_name, ".eh_frame") == 0)
117 module->arch.unw_sec_idx = tgtsec;
118
114 return 0; 119 return 0;
115 120
116relo_err: 121relo_err:
diff --git a/arch/arc/kernel/process.c b/arch/arc/kernel/process.c
index be1972bd2729..59aa43cb146e 100644
--- a/arch/arc/kernel/process.c
+++ b/arch/arc/kernel/process.c
@@ -41,6 +41,39 @@ SYSCALL_DEFINE0(arc_gettls)
41 return task_thread_info(current)->thr_ptr; 41 return task_thread_info(current)->thr_ptr;
42} 42}
43 43
44SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
45{
46 int uval;
47 int ret;
48
49 /*
50 * This is only for old cores lacking LLOCK/SCOND, which by defintion
51 * can't possibly be SMP. Thus doesn't need to be SMP safe.
52 * And this also helps reduce the overhead for serializing in
53 * the UP case
54 */
55 WARN_ON_ONCE(IS_ENABLED(CONFIG_SMP));
56
57 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
58 return -EFAULT;
59
60 preempt_disable();
61
62 ret = __get_user(uval, uaddr);
63 if (ret)
64 goto done;
65
66 if (uval != expected)
67 ret = -EAGAIN;
68 else
69 ret = __put_user(new, uaddr);
70
71done:
72 preempt_enable();
73
74 return ret;
75}
76
44void arch_cpu_idle(void) 77void arch_cpu_idle(void)
45{ 78{
46 /* sleep, but enable all interrupts before committing */ 79 /* sleep, but enable all interrupts before committing */
diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c
index 3df7f9c72f42..0385df77a697 100644
--- a/arch/arc/kernel/setup.c
+++ b/arch/arc/kernel/setup.c
@@ -40,6 +40,29 @@ struct task_struct *_current_task[NR_CPUS]; /* For stack switching */
40 40
41struct cpuinfo_arc cpuinfo_arc700[NR_CPUS]; 41struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
42 42
43static const struct id_to_str arc_cpu_rel[] = {
44#ifdef CONFIG_ISA_ARCOMPACT
45 { 0x34, "R4.10"},
46 { 0x35, "R4.11"},
47#else
48 { 0x51, "R2.0" },
49 { 0x52, "R2.1" },
50 { 0x53, "R3.0" },
51#endif
52 { 0x00, NULL }
53};
54
55static const struct id_to_str arc_cpu_nm[] = {
56#ifdef CONFIG_ISA_ARCOMPACT
57 { 0x20, "ARC 600" },
58 { 0x30, "ARC 770" }, /* 750 identified seperately */
59#else
60 { 0x40, "ARC EM" },
61 { 0x50, "ARC HS38" },
62#endif
63 { 0x00, "Unknown" }
64};
65
43static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu) 66static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu)
44{ 67{
45 if (is_isa_arcompact()) { 68 if (is_isa_arcompact()) {
@@ -92,11 +115,26 @@ static void read_arc_build_cfg_regs(void)
92 struct bcr_timer timer; 115 struct bcr_timer timer;
93 struct bcr_generic bcr; 116 struct bcr_generic bcr;
94 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()]; 117 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
118 const struct id_to_str *tbl;
119
95 FIX_PTR(cpu); 120 FIX_PTR(cpu);
96 121
97 READ_BCR(AUX_IDENTITY, cpu->core); 122 READ_BCR(AUX_IDENTITY, cpu->core);
98 READ_BCR(ARC_REG_ISA_CFG_BCR, cpu->isa); 123 READ_BCR(ARC_REG_ISA_CFG_BCR, cpu->isa);
99 124
125 for (tbl = &arc_cpu_rel[0]; tbl->id != 0; tbl++) {
126 if (cpu->core.family == tbl->id) {
127 cpu->details = tbl->str;
128 break;
129 }
130 }
131
132 for (tbl = &arc_cpu_nm[0]; tbl->id != 0; tbl++) {
133 if ((cpu->core.family & 0xF0) == tbl->id)
134 break;
135 }
136 cpu->name = tbl->str;
137
100 READ_BCR(ARC_REG_TIMERS_BCR, timer); 138 READ_BCR(ARC_REG_TIMERS_BCR, timer);
101 cpu->extn.timer0 = timer.t0; 139 cpu->extn.timer0 = timer.t0;
102 cpu->extn.timer1 = timer.t1; 140 cpu->extn.timer1 = timer.t1;
@@ -111,6 +149,9 @@ static void read_arc_build_cfg_regs(void)
111 cpu->extn.swap = read_aux_reg(ARC_REG_SWAP_BCR) ? 1 : 0; /* 1,3 */ 149 cpu->extn.swap = read_aux_reg(ARC_REG_SWAP_BCR) ? 1 : 0; /* 1,3 */
112 cpu->extn.crc = read_aux_reg(ARC_REG_CRC_BCR) ? 1 : 0; 150 cpu->extn.crc = read_aux_reg(ARC_REG_CRC_BCR) ? 1 : 0;
113 cpu->extn.minmax = read_aux_reg(ARC_REG_MIXMAX_BCR) > 1 ? 1 : 0; /* 2 */ 151 cpu->extn.minmax = read_aux_reg(ARC_REG_MIXMAX_BCR) > 1 ? 1 : 0; /* 2 */
152 cpu->extn.swape = (cpu->core.family >= 0x34) ? 1 :
153 IS_ENABLED(CONFIG_ARC_HAS_SWAPE);
154
114 READ_BCR(ARC_REG_XY_MEM_BCR, cpu->extn_xymem); 155 READ_BCR(ARC_REG_XY_MEM_BCR, cpu->extn_xymem);
115 156
116 /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */ 157 /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */
@@ -160,64 +201,38 @@ static void read_arc_build_cfg_regs(void)
160 cpu->extn.rtt = bcr.ver ? 1 : 0; 201 cpu->extn.rtt = bcr.ver ? 1 : 0;
161 202
162 cpu->extn.debug = cpu->extn.ap | cpu->extn.smart | cpu->extn.rtt; 203 cpu->extn.debug = cpu->extn.ap | cpu->extn.smart | cpu->extn.rtt;
163}
164 204
165static const struct cpuinfo_data arc_cpu_tbl[] = { 205 /* some hacks for lack of feature BCR info in old ARC700 cores */
166#ifdef CONFIG_ISA_ARCOMPACT 206 if (is_isa_arcompact()) {
167 { {0x20, "ARC 600" }, 0x2F}, 207 if (!cpu->isa.ver) /* ISA BCR absent, use Kconfig info */
168 { {0x30, "ARC 700" }, 0x33}, 208 cpu->isa.atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
169 { {0x34, "ARC 700 R4.10"}, 0x34}, 209 else
170 { {0x35, "ARC 700 R4.11"}, 0x35}, 210 cpu->isa.atomic = cpu->isa.atomic1;
171#else
172 { {0x50, "ARC HS38 R2.0"}, 0x51},
173 { {0x52, "ARC HS38 R2.1"}, 0x52},
174 { {0x53, "ARC HS38 R3.0"}, 0x53},
175#endif
176 { {0x00, NULL } }
177};
178 211
212 cpu->isa.be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
213
214 /* there's no direct way to distinguish 750 vs. 770 */
215 if (unlikely(cpu->core.family < 0x34 || cpu->mmu.ver < 3))
216 cpu->name = "ARC750";
217 }
218}
179 219
180static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len) 220static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
181{ 221{
182 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id]; 222 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
183 struct bcr_identity *core = &cpu->core; 223 struct bcr_identity *core = &cpu->core;
184 const struct cpuinfo_data *tbl; 224 int i, n = 0;
185 char *isa_nm;
186 int i, be, atomic;
187 int n = 0;
188 225
189 FIX_PTR(cpu); 226 FIX_PTR(cpu);
190 227
191 if (is_isa_arcompact()) {
192 isa_nm = "ARCompact";
193 be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
194
195 atomic = cpu->isa.atomic1;
196 if (!cpu->isa.ver) /* ISA BCR absent, use Kconfig info */
197 atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
198 } else {
199 isa_nm = "ARCv2";
200 be = cpu->isa.be;
201 atomic = cpu->isa.atomic;
202 }
203
204 n += scnprintf(buf + n, len - n, 228 n += scnprintf(buf + n, len - n,
205 "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n", 229 "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n",
206 core->family, core->cpu_id, core->chip_id); 230 core->family, core->cpu_id, core->chip_id);
207 231
208 for (tbl = &arc_cpu_tbl[0]; tbl->info.id != 0; tbl++) { 232 n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s\n",
209 if ((core->family >= tbl->info.id) && 233 cpu_id, cpu->name, cpu->details,
210 (core->family <= tbl->up_range)) { 234 is_isa_arcompact() ? "ARCompact" : "ARCv2",
211 n += scnprintf(buf + n, len - n, 235 IS_AVAIL1(cpu->isa.be, "[Big-Endian]"));
212 "processor [%d]\t: %s (%s ISA) %s\n",
213 cpu_id, tbl->info.str, isa_nm,
214 IS_AVAIL1(be, "[Big-Endian]"));
215 break;
216 }
217 }
218
219 if (tbl->info.id == 0)
220 n += scnprintf(buf + n, len - n, "UNKNOWN ARC Processor\n");
221 236
222 n += scnprintf(buf + n, len - n, "Timers\t\t: %s%s%s%s\nISA Extn\t: ", 237 n += scnprintf(buf + n, len - n, "Timers\t\t: %s%s%s%s\nISA Extn\t: ",
223 IS_AVAIL1(cpu->extn.timer0, "Timer0 "), 238 IS_AVAIL1(cpu->extn.timer0, "Timer0 "),
@@ -226,7 +241,7 @@ static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
226 CONFIG_ARC_HAS_RTC)); 241 CONFIG_ARC_HAS_RTC));
227 242
228 n += i = scnprintf(buf + n, len - n, "%s%s%s%s%s", 243 n += i = scnprintf(buf + n, len - n, "%s%s%s%s%s",
229 IS_AVAIL2(atomic, "atomic ", CONFIG_ARC_HAS_LLSC), 244 IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
230 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64), 245 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
231 IS_AVAIL1(cpu->isa.unalign, "unalign (not used)")); 246 IS_AVAIL1(cpu->isa.unalign, "unalign (not used)"));
232 247
@@ -253,7 +268,7 @@ static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
253 IS_AVAIL1(cpu->extn.swap, "swap "), 268 IS_AVAIL1(cpu->extn.swap, "swap "),
254 IS_AVAIL1(cpu->extn.minmax, "minmax "), 269 IS_AVAIL1(cpu->extn.minmax, "minmax "),
255 IS_AVAIL1(cpu->extn.crc, "crc "), 270 IS_AVAIL1(cpu->extn.crc, "crc "),
256 IS_AVAIL2(1, "swape", CONFIG_ARC_HAS_SWAPE)); 271 IS_AVAIL2(cpu->extn.swape, "swape", CONFIG_ARC_HAS_SWAPE));
257 272
258 if (cpu->bpu.ver) 273 if (cpu->bpu.ver)
259 n += scnprintf(buf + n, len - n, 274 n += scnprintf(buf + n, len - n,
@@ -272,9 +287,7 @@ static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
272 287
273 FIX_PTR(cpu); 288 FIX_PTR(cpu);
274 289
275 n += scnprintf(buf + n, len - n, 290 n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
276 "Vector Table\t: %#x\nPeripherals\t: %#lx:%#lx\n",
277 cpu->vec_base, perip_base, perip_end);
278 291
279 if (cpu->extn.fpu_sp || cpu->extn.fpu_dp) 292 if (cpu->extn.fpu_sp || cpu->extn.fpu_dp)
280 n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n", 293 n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n",
@@ -507,7 +520,7 @@ static void *c_start(struct seq_file *m, loff_t *pos)
507 * way to pass it w/o having to kmalloc/free a 2 byte string. 520 * way to pass it w/o having to kmalloc/free a 2 byte string.
508 * Encode cpu-id as 0xFFcccc, which is decoded by show routine. 521 * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
509 */ 522 */
510 return *pos < num_possible_cpus() ? cpu_to_ptr(*pos) : NULL; 523 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
511} 524}
512 525
513static void *c_next(struct seq_file *m, void *v, loff_t *pos) 526static void *c_next(struct seq_file *m, void *v, loff_t *pos)
diff --git a/arch/arc/kernel/troubleshoot.c b/arch/arc/kernel/troubleshoot.c
index 934150e7ac48..82f9bc819f4a 100644
--- a/arch/arc/kernel/troubleshoot.c
+++ b/arch/arc/kernel/troubleshoot.c
@@ -237,113 +237,3 @@ void show_kernel_fault_diag(const char *str, struct pt_regs *regs,
237 if (!user_mode(regs)) 237 if (!user_mode(regs))
238 show_stacktrace(current, regs); 238 show_stacktrace(current, regs);
239} 239}
240
241#ifdef CONFIG_DEBUG_FS
242
243#include <linux/module.h>
244#include <linux/fs.h>
245#include <linux/mount.h>
246#include <linux/pagemap.h>
247#include <linux/init.h>
248#include <linux/namei.h>
249#include <linux/debugfs.h>
250
251static struct dentry *test_dentry;
252static struct dentry *test_dir;
253static struct dentry *test_u32_dentry;
254
255static u32 clr_on_read = 1;
256
257#ifdef CONFIG_ARC_DBG_TLB_MISS_COUNT
258u32 numitlb, numdtlb, num_pte_not_present;
259
260static int fill_display_data(char *kbuf)
261{
262 size_t num = 0;
263 num += sprintf(kbuf + num, "I-TLB Miss %x\n", numitlb);
264 num += sprintf(kbuf + num, "D-TLB Miss %x\n", numdtlb);
265 num += sprintf(kbuf + num, "PTE not present %x\n", num_pte_not_present);
266
267 if (clr_on_read)
268 numitlb = numdtlb = num_pte_not_present = 0;
269
270 return num;
271}
272
273static int tlb_stats_open(struct inode *inode, struct file *file)
274{
275 file->private_data = (void *)__get_free_page(GFP_KERNEL);
276 return 0;
277}
278
279/* called on user read(): display the counters */
280static ssize_t tlb_stats_output(struct file *file, /* file descriptor */
281 char __user *user_buf, /* user buffer */
282 size_t len, /* length of buffer */
283 loff_t *offset) /* offset in the file */
284{
285 size_t num;
286 char *kbuf = (char *)file->private_data;
287
288 /* All of the data can he shoved in one iteration */
289 if (*offset != 0)
290 return 0;
291
292 num = fill_display_data(kbuf);
293
294 /* simple_read_from_buffer() is helper for copy to user space
295 It copies up to @2 (num) bytes from kernel buffer @4 (kbuf) at offset
296 @3 (offset) into the user space address starting at @1 (user_buf).
297 @5 (len) is max size of user buffer
298 */
299 return simple_read_from_buffer(user_buf, num, offset, kbuf, len);
300}
301
302/* called on user write : clears the counters */
303static ssize_t tlb_stats_clear(struct file *file, const char __user *user_buf,
304 size_t length, loff_t *offset)
305{
306 numitlb = numdtlb = num_pte_not_present = 0;
307 return length;
308}
309
310static int tlb_stats_close(struct inode *inode, struct file *file)
311{
312 free_page((unsigned long)(file->private_data));
313 return 0;
314}
315
316static const struct file_operations tlb_stats_file_ops = {
317 .read = tlb_stats_output,
318 .write = tlb_stats_clear,
319 .open = tlb_stats_open,
320 .release = tlb_stats_close
321};
322#endif
323
324static int __init arc_debugfs_init(void)
325{
326 test_dir = debugfs_create_dir("arc", NULL);
327
328#ifdef CONFIG_ARC_DBG_TLB_MISS_COUNT
329 test_dentry = debugfs_create_file("tlb_stats", 0444, test_dir, NULL,
330 &tlb_stats_file_ops);
331#endif
332
333 test_u32_dentry =
334 debugfs_create_u32("clr_on_read", 0444, test_dir, &clr_on_read);
335
336 return 0;
337}
338
339module_init(arc_debugfs_init);
340
341static void __exit arc_debugfs_exit(void)
342{
343 debugfs_remove(test_u32_dentry);
344 debugfs_remove(test_dentry);
345 debugfs_remove(test_dir);
346}
347module_exit(arc_debugfs_exit);
348
349#endif
diff --git a/arch/arc/mm/cache.c b/arch/arc/mm/cache.c
index 97dddbefb86a..2b96cfc3be75 100644
--- a/arch/arc/mm/cache.c
+++ b/arch/arc/mm/cache.c
@@ -22,8 +22,8 @@
22#include <asm/setup.h> 22#include <asm/setup.h>
23 23
24static int l2_line_sz; 24static int l2_line_sz;
25int ioc_exists; 25static int ioc_exists;
26volatile int slc_enable = 1, ioc_enable = 1; 26int slc_enable = 1, ioc_enable = 1;
27unsigned long perip_base = ARC_UNCACHED_ADDR_SPACE; /* legacy value for boot */ 27unsigned long perip_base = ARC_UNCACHED_ADDR_SPACE; /* legacy value for boot */
28unsigned long perip_end = 0xFFFFFFFF; /* legacy value */ 28unsigned long perip_end = 0xFFFFFFFF; /* legacy value */
29 29
@@ -53,18 +53,15 @@ char *arc_cache_mumbojumbo(int c, char *buf, int len)
53 PR_CACHE(&cpuinfo_arc700[c].icache, CONFIG_ARC_HAS_ICACHE, "I-Cache"); 53 PR_CACHE(&cpuinfo_arc700[c].icache, CONFIG_ARC_HAS_ICACHE, "I-Cache");
54 PR_CACHE(&cpuinfo_arc700[c].dcache, CONFIG_ARC_HAS_DCACHE, "D-Cache"); 54 PR_CACHE(&cpuinfo_arc700[c].dcache, CONFIG_ARC_HAS_DCACHE, "D-Cache");
55 55
56 if (!is_isa_arcv2())
57 return buf;
58
59 p = &cpuinfo_arc700[c].slc; 56 p = &cpuinfo_arc700[c].slc;
60 if (p->ver) 57 if (p->ver)
61 n += scnprintf(buf + n, len - n, 58 n += scnprintf(buf + n, len - n,
62 "SLC\t\t: %uK, %uB Line%s\n", 59 "SLC\t\t: %uK, %uB Line%s\n",
63 p->sz_k, p->line_len, IS_USED_RUN(slc_enable)); 60 p->sz_k, p->line_len, IS_USED_RUN(slc_enable));
64 61
65 if (ioc_exists) 62 n += scnprintf(buf + n, len - n, "Peripherals\t: %#lx%s%s\n",
66 n += scnprintf(buf + n, len - n, "IOC\t\t:%s\n", 63 perip_base,
67 IS_DISABLED_RUN(ioc_enable)); 64 IS_AVAIL3(ioc_exists, ioc_enable, ", IO-Coherency "));
68 65
69 return buf; 66 return buf;
70} 67}
@@ -113,8 +110,10 @@ static void read_decode_cache_bcr_arcv2(int cpu)
113 } 110 }
114 111
115 READ_BCR(ARC_REG_CLUSTER_BCR, cbcr); 112 READ_BCR(ARC_REG_CLUSTER_BCR, cbcr);
116 if (cbcr.c && ioc_enable) 113 if (cbcr.c)
117 ioc_exists = 1; 114 ioc_exists = 1;
115 else
116 ioc_enable = 0;
118 117
119 /* HS 2.0 didn't have AUX_VOL */ 118 /* HS 2.0 didn't have AUX_VOL */
120 if (cpuinfo_arc700[cpu].core.family > 0x51) { 119 if (cpuinfo_arc700[cpu].core.family > 0x51) {
@@ -1002,7 +1001,7 @@ void arc_cache_init(void)
1002 read_aux_reg(ARC_REG_SLC_CTRL) | SLC_CTRL_DISABLE); 1001 read_aux_reg(ARC_REG_SLC_CTRL) | SLC_CTRL_DISABLE);
1003 } 1002 }
1004 1003
1005 if (is_isa_arcv2() && ioc_exists) { 1004 if (is_isa_arcv2() && ioc_enable) {
1006 /* IO coherency base - 0x8z */ 1005 /* IO coherency base - 0x8z */
1007 write_aux_reg(ARC_REG_IO_COH_AP0_BASE, 0x80000); 1006 write_aux_reg(ARC_REG_IO_COH_AP0_BASE, 0x80000);
1008 /* IO coherency aperture size - 512Mb: 0x8z-0xAz */ 1007 /* IO coherency aperture size - 512Mb: 0x8z-0xAz */
diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c
index 20afc65e22dc..60aab5a7522b 100644
--- a/arch/arc/mm/dma.c
+++ b/arch/arc/mm/dma.c
@@ -45,7 +45,7 @@ static void *arc_dma_alloc(struct device *dev, size_t size,
45 * -For coherent data, Read/Write to buffers terminate early in cache 45 * -For coherent data, Read/Write to buffers terminate early in cache
46 * (vs. always going to memory - thus are faster) 46 * (vs. always going to memory - thus are faster)
47 */ 47 */
48 if ((is_isa_arcv2() && ioc_exists) || 48 if ((is_isa_arcv2() && ioc_enable) ||
49 (attrs & DMA_ATTR_NON_CONSISTENT)) 49 (attrs & DMA_ATTR_NON_CONSISTENT))
50 need_coh = 0; 50 need_coh = 0;
51 51
@@ -97,7 +97,7 @@ static void arc_dma_free(struct device *dev, size_t size, void *vaddr,
97 int is_non_coh = 1; 97 int is_non_coh = 1;
98 98
99 is_non_coh = (attrs & DMA_ATTR_NON_CONSISTENT) || 99 is_non_coh = (attrs & DMA_ATTR_NON_CONSISTENT) ||
100 (is_isa_arcv2() && ioc_exists); 100 (is_isa_arcv2() && ioc_enable);
101 101
102 if (PageHighMem(page) || !is_non_coh) 102 if (PageHighMem(page) || !is_non_coh)
103 iounmap((void __force __iomem *)vaddr); 103 iounmap((void __force __iomem *)vaddr);
diff --git a/arch/arc/mm/tlb.c b/arch/arc/mm/tlb.c
index ec868a9081a1..bdb295e09160 100644
--- a/arch/arc/mm/tlb.c
+++ b/arch/arc/mm/tlb.c
@@ -793,16 +793,16 @@ char *arc_mmu_mumbojumbo(int cpu_id, char *buf, int len)
793 char super_pg[64] = ""; 793 char super_pg[64] = "";
794 794
795 if (p_mmu->s_pg_sz_m) 795 if (p_mmu->s_pg_sz_m)
796 scnprintf(super_pg, 64, "%dM Super Page%s, ", 796 scnprintf(super_pg, 64, "%dM Super Page %s",
797 p_mmu->s_pg_sz_m, 797 p_mmu->s_pg_sz_m,
798 IS_USED_CFG(CONFIG_TRANSPARENT_HUGEPAGE)); 798 IS_USED_CFG(CONFIG_TRANSPARENT_HUGEPAGE));
799 799
800 n += scnprintf(buf + n, len - n, 800 n += scnprintf(buf + n, len - n,
801 "MMU [v%x]\t: %dk PAGE, %sJTLB %d (%dx%d), uDTLB %d, uITLB %d %s%s\n", 801 "MMU [v%x]\t: %dk PAGE, %sJTLB %d (%dx%d), uDTLB %d, uITLB %d%s%s\n",
802 p_mmu->ver, p_mmu->pg_sz_k, super_pg, 802 p_mmu->ver, p_mmu->pg_sz_k, super_pg,
803 p_mmu->sets * p_mmu->ways, p_mmu->sets, p_mmu->ways, 803 p_mmu->sets * p_mmu->ways, p_mmu->sets, p_mmu->ways,
804 p_mmu->u_dtlb, p_mmu->u_itlb, 804 p_mmu->u_dtlb, p_mmu->u_itlb,
805 IS_AVAIL2(p_mmu->pae, "PAE40 ", CONFIG_ARC_HAS_PAE40)); 805 IS_AVAIL2(p_mmu->pae, ", PAE40 ", CONFIG_ARC_HAS_PAE40));
806 806
807 return buf; 807 return buf;
808} 808}
diff --git a/arch/arc/mm/tlbex.S b/arch/arc/mm/tlbex.S
index f1967eeb32e7..b30e4e36bb00 100644
--- a/arch/arc/mm/tlbex.S
+++ b/arch/arc/mm/tlbex.S
@@ -237,15 +237,6 @@ ex_saved_reg1:
237 237
2382: 2382:
239 239
240#ifdef CONFIG_ARC_DBG_TLB_MISS_COUNT
241 and.f 0, r0, _PAGE_PRESENT
242 bz 1f
243 ld r3, [num_pte_not_present]
244 add r3, r3, 1
245 st r3, [num_pte_not_present]
2461:
247#endif
248
249.endm 240.endm
250 241
251;----------------------------------------------------------------- 242;-----------------------------------------------------------------
@@ -309,12 +300,6 @@ ENTRY(EV_TLBMissI)
309 300
310 TLBMISS_FREEUP_REGS 301 TLBMISS_FREEUP_REGS
311 302
312#ifdef CONFIG_ARC_DBG_TLB_MISS_COUNT
313 ld r0, [@numitlb]
314 add r0, r0, 1
315 st r0, [@numitlb]
316#endif
317
318 ;---------------------------------------------------------------- 303 ;----------------------------------------------------------------
319 ; Get the PTE corresponding to V-addr accessed, r2 is setup with EFA 304 ; Get the PTE corresponding to V-addr accessed, r2 is setup with EFA
320 LOAD_FAULT_PTE 305 LOAD_FAULT_PTE
@@ -349,12 +334,6 @@ ENTRY(EV_TLBMissD)
349 334
350 TLBMISS_FREEUP_REGS 335 TLBMISS_FREEUP_REGS
351 336
352#ifdef CONFIG_ARC_DBG_TLB_MISS_COUNT
353 ld r0, [@numdtlb]
354 add r0, r0, 1
355 st r0, [@numdtlb]
356#endif
357
358 ;---------------------------------------------------------------- 337 ;----------------------------------------------------------------
359 ; Get the PTE corresponding to V-addr accessed 338 ; Get the PTE corresponding to V-addr accessed
360 ; If PTE exists, it will setup, r0 = PTE, r1 = Ptr to PTE, r2 = EFA 339 ; If PTE exists, it will setup, r0 = PTE, r1 = Ptr to PTE, r2 = EFA
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index ba62df8c6e35..b71086d25195 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -217,7 +217,7 @@ static inline void *phys_to_virt(phys_addr_t x)
217#define _virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) 217#define _virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
218#else 218#else
219#define __virt_to_pgoff(kaddr) (((u64)(kaddr) & ~PAGE_OFFSET) / PAGE_SIZE * sizeof(struct page)) 219#define __virt_to_pgoff(kaddr) (((u64)(kaddr) & ~PAGE_OFFSET) / PAGE_SIZE * sizeof(struct page))
220#define __page_to_voff(kaddr) (((u64)(page) & ~VMEMMAP_START) * PAGE_SIZE / sizeof(struct page)) 220#define __page_to_voff(page) (((u64)(page) & ~VMEMMAP_START) * PAGE_SIZE / sizeof(struct page))
221 221
222#define page_to_virt(page) ((void *)((__page_to_voff(page)) | PAGE_OFFSET)) 222#define page_to_virt(page) ((void *)((__page_to_voff(page)) | PAGE_OFFSET))
223#define virt_to_page(vaddr) ((struct page *)((__virt_to_pgoff(vaddr)) | VMEMMAP_START)) 223#define virt_to_page(vaddr) ((struct page *)((__virt_to_pgoff(vaddr)) | VMEMMAP_START))
diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c
index 778a985c8a70..4b32168cf91a 100644
--- a/arch/arm64/mm/numa.c
+++ b/arch/arm64/mm/numa.c
@@ -147,7 +147,7 @@ static int __init early_cpu_to_node(int cpu)
147 147
148static int __init pcpu_cpu_distance(unsigned int from, unsigned int to) 148static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
149{ 149{
150 return node_distance(from, to); 150 return node_distance(early_cpu_to_node(from), early_cpu_to_node(to));
151} 151}
152 152
153static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, 153static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size,
@@ -223,8 +223,11 @@ static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn)
223 void *nd; 223 void *nd;
224 int tnid; 224 int tnid;
225 225
226 pr_info("Initmem setup node %d [mem %#010Lx-%#010Lx]\n", 226 if (start_pfn < end_pfn)
227 nid, start_pfn << PAGE_SHIFT, (end_pfn << PAGE_SHIFT) - 1); 227 pr_info("Initmem setup node %d [mem %#010Lx-%#010Lx]\n", nid,
228 start_pfn << PAGE_SHIFT, (end_pfn << PAGE_SHIFT) - 1);
229 else
230 pr_info("Initmem setup node %d [<memory-less node>]\n", nid);
228 231
229 nd_pa = memblock_alloc_try_nid(nd_size, SMP_CACHE_BYTES, nid); 232 nd_pa = memblock_alloc_try_nid(nd_size, SMP_CACHE_BYTES, nid);
230 nd = __va(nd_pa); 233 nd = __va(nd_pa);
diff --git a/arch/cris/arch-v32/drivers/cryptocop.c b/arch/cris/arch-v32/drivers/cryptocop.c
index 099e170a93ee..0068fd411a84 100644
--- a/arch/cris/arch-v32/drivers/cryptocop.c
+++ b/arch/cris/arch-v32/drivers/cryptocop.c
@@ -3149,7 +3149,7 @@ static void print_dma_descriptors(struct cryptocop_int_operation *iop)
3149 printk("print_dma_descriptors start\n"); 3149 printk("print_dma_descriptors start\n");
3150 3150
3151 printk("iop:\n"); 3151 printk("iop:\n");
3152 printk("\tsid: 0x%lld\n", iop->sid); 3152 printk("\tsid: 0x%llx\n", iop->sid);
3153 3153
3154 printk("\tcdesc_out: 0x%p\n", iop->cdesc_out); 3154 printk("\tcdesc_out: 0x%p\n", iop->cdesc_out);
3155 printk("\tcdesc_in: 0x%p\n", iop->cdesc_in); 3155 printk("\tcdesc_in: 0x%p\n", iop->cdesc_in);
diff --git a/arch/h8300/include/asm/thread_info.h b/arch/h8300/include/asm/thread_info.h
index b408fe660cf8..3cef06875f5c 100644
--- a/arch/h8300/include/asm/thread_info.h
+++ b/arch/h8300/include/asm/thread_info.h
@@ -31,7 +31,6 @@ struct thread_info {
31 int cpu; /* cpu we're on */ 31 int cpu; /* cpu we're on */
32 int preempt_count; /* 0 => preemptable, <0 => BUG */ 32 int preempt_count; /* 0 => preemptable, <0 => BUG */
33 mm_segment_t addr_limit; 33 mm_segment_t addr_limit;
34 struct restart_block restart_block;
35}; 34};
36 35
37/* 36/*
@@ -44,9 +43,6 @@ struct thread_info {
44 .cpu = 0, \ 43 .cpu = 0, \
45 .preempt_count = INIT_PREEMPT_COUNT, \ 44 .preempt_count = INIT_PREEMPT_COUNT, \
46 .addr_limit = KERNEL_DS, \ 45 .addr_limit = KERNEL_DS, \
47 .restart_block = { \
48 .fn = do_no_restart_syscall, \
49 }, \
50} 46}
51 47
52#define init_thread_info (init_thread_union.thread_info) 48#define init_thread_info (init_thread_union.thread_info)
diff --git a/arch/h8300/kernel/signal.c b/arch/h8300/kernel/signal.c
index ad1f81f574e5..7138303cbbf2 100644
--- a/arch/h8300/kernel/signal.c
+++ b/arch/h8300/kernel/signal.c
@@ -79,7 +79,7 @@ restore_sigcontext(struct sigcontext *usc, int *pd0)
79 unsigned int er0; 79 unsigned int er0;
80 80
81 /* Always make any pending restarted system calls return -EINTR */ 81 /* Always make any pending restarted system calls return -EINTR */
82 current_thread_info()->restart_block.fn = do_no_restart_syscall; 82 current->restart_block.fn = do_no_restart_syscall;
83 83
84 /* restore passed registers */ 84 /* restore passed registers */
85#define COPY(r) do { err |= get_user(regs->r, &usc->sc_##r); } while (0) 85#define COPY(r) do { err |= get_user(regs->r, &usc->sc_##r); } while (0)
diff --git a/arch/powerpc/include/asm/cpuidle.h b/arch/powerpc/include/asm/cpuidle.h
index 01b8a13f0224..3919332965af 100644
--- a/arch/powerpc/include/asm/cpuidle.h
+++ b/arch/powerpc/include/asm/cpuidle.h
@@ -26,7 +26,7 @@ extern u64 pnv_first_deep_stop_state;
26 std r0,0(r1); \ 26 std r0,0(r1); \
27 ptesync; \ 27 ptesync; \
28 ld r0,0(r1); \ 28 ld r0,0(r1); \
291: cmp cr0,r0,r0; \ 291: cmpd cr0,r0,r0; \
30 bne 1b; \ 30 bne 1b; \
31 IDLE_INST; \ 31 IDLE_INST; \
32 b . 32 b .
diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index 2e4e7d878c8e..84d49b197c32 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -93,6 +93,10 @@
93 ld reg,PACAKBASE(r13); /* get high part of &label */ \ 93 ld reg,PACAKBASE(r13); /* get high part of &label */ \
94 ori reg,reg,(FIXED_SYMBOL_ABS_ADDR(label))@l; 94 ori reg,reg,(FIXED_SYMBOL_ABS_ADDR(label))@l;
95 95
96#define __LOAD_HANDLER(reg, label) \
97 ld reg,PACAKBASE(r13); \
98 ori reg,reg,(ABS_ADDR(label))@l;
99
96/* Exception register prefixes */ 100/* Exception register prefixes */
97#define EXC_HV H 101#define EXC_HV H
98#define EXC_STD 102#define EXC_STD
@@ -208,6 +212,18 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
208#define kvmppc_interrupt kvmppc_interrupt_pr 212#define kvmppc_interrupt kvmppc_interrupt_pr
209#endif 213#endif
210 214
215#ifdef CONFIG_RELOCATABLE
216#define BRANCH_TO_COMMON(reg, label) \
217 __LOAD_HANDLER(reg, label); \
218 mtctr reg; \
219 bctr
220
221#else
222#define BRANCH_TO_COMMON(reg, label) \
223 b label
224
225#endif
226
211#define __KVM_HANDLER_PROLOG(area, n) \ 227#define __KVM_HANDLER_PROLOG(area, n) \
212 BEGIN_FTR_SECTION_NESTED(947) \ 228 BEGIN_FTR_SECTION_NESTED(947) \
213 ld r10,area+EX_CFAR(r13); \ 229 ld r10,area+EX_CFAR(r13); \
diff --git a/arch/powerpc/include/asm/tlb.h b/arch/powerpc/include/asm/tlb.h
index f6f68f73e858..99e1397b71da 100644
--- a/arch/powerpc/include/asm/tlb.h
+++ b/arch/powerpc/include/asm/tlb.h
@@ -52,11 +52,23 @@ static inline int mm_is_core_local(struct mm_struct *mm)
52 return cpumask_subset(mm_cpumask(mm), 52 return cpumask_subset(mm_cpumask(mm),
53 topology_sibling_cpumask(smp_processor_id())); 53 topology_sibling_cpumask(smp_processor_id()));
54} 54}
55
56static inline int mm_is_thread_local(struct mm_struct *mm)
57{
58 return cpumask_equal(mm_cpumask(mm),
59 cpumask_of(smp_processor_id()));
60}
61
55#else 62#else
56static inline int mm_is_core_local(struct mm_struct *mm) 63static inline int mm_is_core_local(struct mm_struct *mm)
57{ 64{
58 return 1; 65 return 1;
59} 66}
67
68static inline int mm_is_thread_local(struct mm_struct *mm)
69{
70 return 1;
71}
60#endif 72#endif
61 73
62#endif /* __KERNEL__ */ 74#endif /* __KERNEL__ */
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index f129408c6022..08ba447a4b3d 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -95,19 +95,35 @@ __start_interrupts:
95/* No virt vectors corresponding with 0x0..0x100 */ 95/* No virt vectors corresponding with 0x0..0x100 */
96EXC_VIRT_NONE(0x4000, 0x4100) 96EXC_VIRT_NONE(0x4000, 0x4100)
97 97
98EXC_REAL_BEGIN(system_reset, 0x100, 0x200) 98
99 SET_SCRATCH0(r13)
100#ifdef CONFIG_PPC_P7_NAP 99#ifdef CONFIG_PPC_P7_NAP
101BEGIN_FTR_SECTION 100 /*
102 /* Running native on arch 2.06 or later, check if we are 101 * If running native on arch 2.06 or later, check if we are waking up
103 * waking up from nap/sleep/winkle. 102 * from nap/sleep/winkle, and branch to idle handler.
104 */ 103 */
105 mfspr r13,SPRN_SRR1 104#define IDLETEST(n) \
106 rlwinm. r13,r13,47-31,30,31 105 BEGIN_FTR_SECTION ; \
107 beq 9f 106 mfspr r10,SPRN_SRR1 ; \
107 rlwinm. r10,r10,47-31,30,31 ; \
108 beq- 1f ; \
109 cmpwi cr3,r10,2 ; \
110 BRANCH_TO_COMMON(r10, system_reset_idle_common) ; \
1111: \
112 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
113#else
114#define IDLETEST NOTEST
115#endif
108 116
109 cmpwi cr3,r13,2 117EXC_REAL_BEGIN(system_reset, 0x100, 0x200)
110 GET_PACA(r13) 118 SET_SCRATCH0(r13)
119 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
120 IDLETEST, 0x100)
121
122EXC_REAL_END(system_reset, 0x100, 0x200)
123EXC_VIRT_NONE(0x4100, 0x4200)
124
125#ifdef CONFIG_PPC_P7_NAP
126EXC_COMMON_BEGIN(system_reset_idle_common)
111 bl pnv_restore_hyp_resource 127 bl pnv_restore_hyp_resource
112 128
113 li r0,PNV_THREAD_RUNNING 129 li r0,PNV_THREAD_RUNNING
@@ -130,14 +146,8 @@ BEGIN_FTR_SECTION
130 blt cr3,2f 146 blt cr3,2f
131 b pnv_wakeup_loss 147 b pnv_wakeup_loss
1322: b pnv_wakeup_noloss 1482: b pnv_wakeup_noloss
149#endif
133 150
1349:
135END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
136#endif /* CONFIG_PPC_P7_NAP */
137 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
138 NOTEST, 0x100)
139EXC_REAL_END(system_reset, 0x100, 0x200)
140EXC_VIRT_NONE(0x4100, 0x4200)
141EXC_COMMON(system_reset_common, 0x100, system_reset_exception) 151EXC_COMMON(system_reset_common, 0x100, system_reset_exception)
142 152
143#ifdef CONFIG_PPC_PSERIES 153#ifdef CONFIG_PPC_PSERIES
@@ -817,10 +827,8 @@ EXC_VIRT(trap_0b, 0x4b00, 0x4c00, 0xb00)
817TRAMP_KVM(PACA_EXGEN, 0xb00) 827TRAMP_KVM(PACA_EXGEN, 0xb00)
818EXC_COMMON(trap_0b_common, 0xb00, unknown_exception) 828EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
819 829
820 830#define LOAD_SYSCALL_HANDLER(reg) \
821#define LOAD_SYSCALL_HANDLER(reg) \ 831 __LOAD_HANDLER(reg, system_call_common)
822 ld reg,PACAKBASE(r13); \
823 ori reg,reg,(ABS_ADDR(system_call_common))@l;
824 832
825/* Syscall routine is used twice, in reloc-off and reloc-on paths */ 833/* Syscall routine is used twice, in reloc-off and reloc-on paths */
826#define SYSCALL_PSERIES_1 \ 834#define SYSCALL_PSERIES_1 \
diff --git a/arch/powerpc/kernel/hw_breakpoint.c b/arch/powerpc/kernel/hw_breakpoint.c
index 9781c69eae57..03d089b3ed72 100644
--- a/arch/powerpc/kernel/hw_breakpoint.c
+++ b/arch/powerpc/kernel/hw_breakpoint.c
@@ -275,7 +275,7 @@ int hw_breakpoint_handler(struct die_args *args)
275 if (!stepped) { 275 if (!stepped) {
276 WARN(1, "Unable to handle hardware breakpoint. Breakpoint at " 276 WARN(1, "Unable to handle hardware breakpoint. Breakpoint at "
277 "0x%lx will be disabled.", info->address); 277 "0x%lx will be disabled.", info->address);
278 perf_event_disable(bp); 278 perf_event_disable_inatomic(bp);
279 goto out; 279 goto out;
280 } 280 }
281 /* 281 /*
diff --git a/arch/powerpc/kernel/idle_book3s.S b/arch/powerpc/kernel/idle_book3s.S
index bd739fed26e3..72dac0b58061 100644
--- a/arch/powerpc/kernel/idle_book3s.S
+++ b/arch/powerpc/kernel/idle_book3s.S
@@ -90,6 +90,7 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_300)
90 * Threads will spin in HMT_LOW until the lock bit is cleared. 90 * Threads will spin in HMT_LOW until the lock bit is cleared.
91 * r14 - pointer to core_idle_state 91 * r14 - pointer to core_idle_state
92 * r15 - used to load contents of core_idle_state 92 * r15 - used to load contents of core_idle_state
93 * r9 - used as a temporary variable
93 */ 94 */
94 95
95core_idle_lock_held: 96core_idle_lock_held:
@@ -99,6 +100,8 @@ core_idle_lock_held:
99 bne 3b 100 bne 3b
100 HMT_MEDIUM 101 HMT_MEDIUM
101 lwarx r15,0,r14 102 lwarx r15,0,r14
103 andi. r9,r15,PNV_CORE_IDLE_LOCK_BIT
104 bne core_idle_lock_held
102 blr 105 blr
103 106
104/* 107/*
@@ -163,12 +166,6 @@ _GLOBAL(pnv_powersave_common)
163 std r9,_MSR(r1) 166 std r9,_MSR(r1)
164 std r1,PACAR1(r13) 167 std r1,PACAR1(r13)
165 168
166#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
167 /* Tell KVM we're entering idle */
168 li r4,KVM_HWTHREAD_IN_IDLE
169 stb r4,HSTATE_HWTHREAD_STATE(r13)
170#endif
171
172 /* 169 /*
173 * Go to real mode to do the nap, as required by the architecture. 170 * Go to real mode to do the nap, as required by the architecture.
174 * Also, we need to be in real mode before setting hwthread_state, 171 * Also, we need to be in real mode before setting hwthread_state,
@@ -185,6 +182,26 @@ _GLOBAL(pnv_powersave_common)
185 182
186 .globl pnv_enter_arch207_idle_mode 183 .globl pnv_enter_arch207_idle_mode
187pnv_enter_arch207_idle_mode: 184pnv_enter_arch207_idle_mode:
185#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
186 /* Tell KVM we're entering idle */
187 li r4,KVM_HWTHREAD_IN_IDLE
188 /******************************************************/
189 /* N O T E W E L L ! ! ! N O T E W E L L */
190 /* The following store to HSTATE_HWTHREAD_STATE(r13) */
191 /* MUST occur in real mode, i.e. with the MMU off, */
192 /* and the MMU must stay off until we clear this flag */
193 /* and test HSTATE_HWTHREAD_REQ(r13) in the system */
194 /* reset interrupt vector in exceptions-64s.S. */
195 /* The reason is that another thread can switch the */
196 /* MMU to a guest context whenever this flag is set */
197 /* to KVM_HWTHREAD_IN_IDLE, and if the MMU was on, */
198 /* that would potentially cause this thread to start */
199 /* executing instructions from guest memory in */
200 /* hypervisor mode, leading to a host crash or data */
201 /* corruption, or worse. */
202 /******************************************************/
203 stb r4,HSTATE_HWTHREAD_STATE(r13)
204#endif
188 stb r3,PACA_THREAD_IDLE_STATE(r13) 205 stb r3,PACA_THREAD_IDLE_STATE(r13)
189 cmpwi cr3,r3,PNV_THREAD_SLEEP 206 cmpwi cr3,r3,PNV_THREAD_SLEEP
190 bge cr3,2f 207 bge cr3,2f
@@ -250,6 +267,12 @@ enter_winkle:
250 * r3 - requested stop state 267 * r3 - requested stop state
251 */ 268 */
252power_enter_stop: 269power_enter_stop:
270#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
271 /* Tell KVM we're entering idle */
272 li r4,KVM_HWTHREAD_IN_IDLE
273 /* DO THIS IN REAL MODE! See comment above. */
274 stb r4,HSTATE_HWTHREAD_STATE(r13)
275#endif
253/* 276/*
254 * Check if the requested state is a deep idle state. 277 * Check if the requested state is a deep idle state.
255 */ 278 */
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 9e7c10fe205f..ce6dc61b15b2 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1012,7 +1012,7 @@ void restore_tm_state(struct pt_regs *regs)
1012 /* Ensure that restore_math() will restore */ 1012 /* Ensure that restore_math() will restore */
1013 if (msr_diff & MSR_FP) 1013 if (msr_diff & MSR_FP)
1014 current->thread.load_fp = 1; 1014 current->thread.load_fp = 1;
1015#ifdef CONFIG_ALIVEC 1015#ifdef CONFIG_ALTIVEC
1016 if (cpu_has_feature(CPU_FTR_ALTIVEC) && msr_diff & MSR_VEC) 1016 if (cpu_has_feature(CPU_FTR_ALTIVEC) && msr_diff & MSR_VEC)
1017 current->thread.load_vec = 1; 1017 current->thread.load_vec = 1;
1018#endif 1018#endif
diff --git a/arch/powerpc/kvm/book3s_hv_rm_xics.c b/arch/powerpc/kvm/book3s_hv_rm_xics.c
index 82ff5de8b1e7..a0ea63ac2b52 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_xics.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_xics.c
@@ -23,6 +23,7 @@
23#include <asm/ppc-opcode.h> 23#include <asm/ppc-opcode.h>
24#include <asm/pnv-pci.h> 24#include <asm/pnv-pci.h>
25#include <asm/opal.h> 25#include <asm/opal.h>
26#include <asm/smp.h>
26 27
27#include "book3s_xics.h" 28#include "book3s_xics.h"
28 29
diff --git a/arch/powerpc/mm/tlb-radix.c b/arch/powerpc/mm/tlb-radix.c
index 0e49ec541ab5..bda8c43be78a 100644
--- a/arch/powerpc/mm/tlb-radix.c
+++ b/arch/powerpc/mm/tlb-radix.c
@@ -175,7 +175,7 @@ void radix__flush_tlb_mm(struct mm_struct *mm)
175 if (unlikely(pid == MMU_NO_CONTEXT)) 175 if (unlikely(pid == MMU_NO_CONTEXT))
176 goto no_context; 176 goto no_context;
177 177
178 if (!mm_is_core_local(mm)) { 178 if (!mm_is_thread_local(mm)) {
179 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); 179 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
180 180
181 if (lock_tlbie) 181 if (lock_tlbie)
@@ -201,7 +201,7 @@ void radix__flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr)
201 if (unlikely(pid == MMU_NO_CONTEXT)) 201 if (unlikely(pid == MMU_NO_CONTEXT))
202 goto no_context; 202 goto no_context;
203 203
204 if (!mm_is_core_local(mm)) { 204 if (!mm_is_thread_local(mm)) {
205 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); 205 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
206 206
207 if (lock_tlbie) 207 if (lock_tlbie)
@@ -226,7 +226,7 @@ void radix__flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr,
226 pid = mm ? mm->context.id : 0; 226 pid = mm ? mm->context.id : 0;
227 if (unlikely(pid == MMU_NO_CONTEXT)) 227 if (unlikely(pid == MMU_NO_CONTEXT))
228 goto bail; 228 goto bail;
229 if (!mm_is_core_local(mm)) { 229 if (!mm_is_thread_local(mm)) {
230 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); 230 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
231 231
232 if (lock_tlbie) 232 if (lock_tlbie)
@@ -321,7 +321,7 @@ void radix__flush_tlb_range_psize(struct mm_struct *mm, unsigned long start,
321{ 321{
322 unsigned long pid; 322 unsigned long pid;
323 unsigned long addr; 323 unsigned long addr;
324 int local = mm_is_core_local(mm); 324 int local = mm_is_thread_local(mm);
325 unsigned long ap = mmu_get_ap(psize); 325 unsigned long ap = mmu_get_ap(psize);
326 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); 326 int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
327 unsigned long page_size = 1UL << mmu_psize_defs[psize].shift; 327 unsigned long page_size = 1UL << mmu_psize_defs[psize].shift;
diff --git a/arch/s390/include/asm/ftrace.h b/arch/s390/include/asm/ftrace.h
index 64053d9ac3f2..836c56290499 100644
--- a/arch/s390/include/asm/ftrace.h
+++ b/arch/s390/include/asm/ftrace.h
@@ -12,9 +12,7 @@
12 12
13#ifndef __ASSEMBLY__ 13#ifndef __ASSEMBLY__
14 14
15unsigned long return_address(int depth); 15#define ftrace_return_address(n) __builtin_return_address(n)
16
17#define ftrace_return_address(n) return_address(n)
18 16
19void _mcount(void); 17void _mcount(void);
20void ftrace_caller(void); 18void ftrace_caller(void);
diff --git a/arch/s390/include/asm/processor.h b/arch/s390/include/asm/processor.h
index 03323175de30..602af692efdc 100644
--- a/arch/s390/include/asm/processor.h
+++ b/arch/s390/include/asm/processor.h
@@ -192,7 +192,7 @@ struct task_struct;
192struct mm_struct; 192struct mm_struct;
193struct seq_file; 193struct seq_file;
194 194
195typedef int (*dump_trace_func_t)(void *data, unsigned long address); 195typedef int (*dump_trace_func_t)(void *data, unsigned long address, int reliable);
196void dump_trace(dump_trace_func_t func, void *data, 196void dump_trace(dump_trace_func_t func, void *data,
197 struct task_struct *task, unsigned long sp); 197 struct task_struct *task, unsigned long sp);
198 198
diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h
index 02613bad8bbb..3066031a73fe 100644
--- a/arch/s390/include/asm/unistd.h
+++ b/arch/s390/include/asm/unistd.h
@@ -9,6 +9,9 @@
9#include <uapi/asm/unistd.h> 9#include <uapi/asm/unistd.h>
10 10
11#define __IGNORE_time 11#define __IGNORE_time
12#define __IGNORE_pkey_mprotect
13#define __IGNORE_pkey_alloc
14#define __IGNORE_pkey_free
12 15
13#define __ARCH_WANT_OLD_READDIR 16#define __ARCH_WANT_OLD_READDIR
14#define __ARCH_WANT_SYS_ALARM 17#define __ARCH_WANT_SYS_ALARM
diff --git a/arch/s390/kernel/dis.c b/arch/s390/kernel/dis.c
index 43446fa2a4e5..c74c59236f44 100644
--- a/arch/s390/kernel/dis.c
+++ b/arch/s390/kernel/dis.c
@@ -2014,12 +2014,12 @@ void show_code(struct pt_regs *regs)
2014 *ptr++ = '\t'; 2014 *ptr++ = '\t';
2015 ptr += print_insn(ptr, code + start, addr); 2015 ptr += print_insn(ptr, code + start, addr);
2016 start += opsize; 2016 start += opsize;
2017 printk("%s", buffer); 2017 pr_cont("%s", buffer);
2018 ptr = buffer; 2018 ptr = buffer;
2019 ptr += sprintf(ptr, "\n "); 2019 ptr += sprintf(ptr, "\n ");
2020 hops++; 2020 hops++;
2021 } 2021 }
2022 printk("\n"); 2022 pr_cont("\n");
2023} 2023}
2024 2024
2025void print_fn_code(unsigned char *code, unsigned long len) 2025void print_fn_code(unsigned char *code, unsigned long len)
diff --git a/arch/s390/kernel/dumpstack.c b/arch/s390/kernel/dumpstack.c
index 6693383bc01b..55d4fe174fd9 100644
--- a/arch/s390/kernel/dumpstack.c
+++ b/arch/s390/kernel/dumpstack.c
@@ -38,10 +38,10 @@ __dump_trace(dump_trace_func_t func, void *data, unsigned long sp,
38 if (sp < low || sp > high - sizeof(*sf)) 38 if (sp < low || sp > high - sizeof(*sf))
39 return sp; 39 return sp;
40 sf = (struct stack_frame *) sp; 40 sf = (struct stack_frame *) sp;
41 if (func(data, sf->gprs[8], 0))
42 return sp;
41 /* Follow the backchain. */ 43 /* Follow the backchain. */
42 while (1) { 44 while (1) {
43 if (func(data, sf->gprs[8]))
44 return sp;
45 low = sp; 45 low = sp;
46 sp = sf->back_chain; 46 sp = sf->back_chain;
47 if (!sp) 47 if (!sp)
@@ -49,6 +49,8 @@ __dump_trace(dump_trace_func_t func, void *data, unsigned long sp,
49 if (sp <= low || sp > high - sizeof(*sf)) 49 if (sp <= low || sp > high - sizeof(*sf))
50 return sp; 50 return sp;
51 sf = (struct stack_frame *) sp; 51 sf = (struct stack_frame *) sp;
52 if (func(data, sf->gprs[8], 1))
53 return sp;
52 } 54 }
53 /* Zero backchain detected, check for interrupt frame. */ 55 /* Zero backchain detected, check for interrupt frame. */
54 sp = (unsigned long) (sf + 1); 56 sp = (unsigned long) (sf + 1);
@@ -56,7 +58,7 @@ __dump_trace(dump_trace_func_t func, void *data, unsigned long sp,
56 return sp; 58 return sp;
57 regs = (struct pt_regs *) sp; 59 regs = (struct pt_regs *) sp;
58 if (!user_mode(regs)) { 60 if (!user_mode(regs)) {
59 if (func(data, regs->psw.addr)) 61 if (func(data, regs->psw.addr, 1))
60 return sp; 62 return sp;
61 } 63 }
62 low = sp; 64 low = sp;
@@ -85,33 +87,12 @@ void dump_trace(dump_trace_func_t func, void *data, struct task_struct *task,
85} 87}
86EXPORT_SYMBOL_GPL(dump_trace); 88EXPORT_SYMBOL_GPL(dump_trace);
87 89
88struct return_address_data { 90static int show_address(void *data, unsigned long address, int reliable)
89 unsigned long address;
90 int depth;
91};
92
93static int __return_address(void *data, unsigned long address)
94{
95 struct return_address_data *rd = data;
96
97 if (rd->depth--)
98 return 0;
99 rd->address = address;
100 return 1;
101}
102
103unsigned long return_address(int depth)
104{
105 struct return_address_data rd = { .depth = depth + 2 };
106
107 dump_trace(__return_address, &rd, NULL, current_stack_pointer());
108 return rd.address;
109}
110EXPORT_SYMBOL_GPL(return_address);
111
112static int show_address(void *data, unsigned long address)
113{ 91{
114 printk("([<%016lx>] %pSR)\n", address, (void *)address); 92 if (reliable)
93 printk(" [<%016lx>] %pSR \n", address, (void *)address);
94 else
95 printk("([<%016lx>] %pSR)\n", address, (void *)address);
115 return 0; 96 return 0;
116} 97}
117 98
@@ -138,14 +119,14 @@ void show_stack(struct task_struct *task, unsigned long *sp)
138 else 119 else
139 stack = (unsigned long *)task->thread.ksp; 120 stack = (unsigned long *)task->thread.ksp;
140 } 121 }
122 printk(KERN_DEFAULT "Stack:\n");
141 for (i = 0; i < 20; i++) { 123 for (i = 0; i < 20; i++) {
142 if (((addr_t) stack & (THREAD_SIZE-1)) == 0) 124 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
143 break; 125 break;
144 if ((i * sizeof(long) % 32) == 0) 126 if (i % 4 == 0)
145 printk("%s ", i == 0 ? "" : "\n"); 127 printk(KERN_DEFAULT " ");
146 printk("%016lx ", *stack++); 128 pr_cont("%016lx%c", *stack++, i % 4 == 3 ? '\n' : ' ');
147 } 129 }
148 printk("\n");
149 show_trace(task, (unsigned long)sp); 130 show_trace(task, (unsigned long)sp);
150} 131}
151 132
@@ -163,13 +144,13 @@ void show_registers(struct pt_regs *regs)
163 mode = user_mode(regs) ? "User" : "Krnl"; 144 mode = user_mode(regs) ? "User" : "Krnl";
164 printk("%s PSW : %p %p", mode, (void *)regs->psw.mask, (void *)regs->psw.addr); 145 printk("%s PSW : %p %p", mode, (void *)regs->psw.mask, (void *)regs->psw.addr);
165 if (!user_mode(regs)) 146 if (!user_mode(regs))
166 printk(" (%pSR)", (void *)regs->psw.addr); 147 pr_cont(" (%pSR)", (void *)regs->psw.addr);
167 printk("\n"); 148 pr_cont("\n");
168 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x " 149 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
169 "P:%x AS:%x CC:%x PM:%x", psw->r, psw->t, psw->i, psw->e, 150 "P:%x AS:%x CC:%x PM:%x", psw->r, psw->t, psw->i, psw->e,
170 psw->key, psw->m, psw->w, psw->p, psw->as, psw->cc, psw->pm); 151 psw->key, psw->m, psw->w, psw->p, psw->as, psw->cc, psw->pm);
171 printk(" RI:%x EA:%x", psw->ri, psw->eaba); 152 pr_cont(" RI:%x EA:%x\n", psw->ri, psw->eaba);
172 printk("\n%s GPRS: %016lx %016lx %016lx %016lx\n", mode, 153 printk("%s GPRS: %016lx %016lx %016lx %016lx\n", mode,
173 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]); 154 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
174 printk(" %016lx %016lx %016lx %016lx\n", 155 printk(" %016lx %016lx %016lx %016lx\n",
175 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]); 156 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
@@ -205,14 +186,14 @@ void die(struct pt_regs *regs, const char *str)
205 printk("%s: %04x ilc:%d [#%d] ", str, regs->int_code & 0xffff, 186 printk("%s: %04x ilc:%d [#%d] ", str, regs->int_code & 0xffff,
206 regs->int_code >> 17, ++die_counter); 187 regs->int_code >> 17, ++die_counter);
207#ifdef CONFIG_PREEMPT 188#ifdef CONFIG_PREEMPT
208 printk("PREEMPT "); 189 pr_cont("PREEMPT ");
209#endif 190#endif
210#ifdef CONFIG_SMP 191#ifdef CONFIG_SMP
211 printk("SMP "); 192 pr_cont("SMP ");
212#endif 193#endif
213 if (debug_pagealloc_enabled()) 194 if (debug_pagealloc_enabled())
214 printk("DEBUG_PAGEALLOC"); 195 pr_cont("DEBUG_PAGEALLOC");
215 printk("\n"); 196 pr_cont("\n");
216 notify_die(DIE_OOPS, str, regs, 0, regs->int_code & 0xffff, SIGSEGV); 197 notify_die(DIE_OOPS, str, regs, 0, regs->int_code & 0xffff, SIGSEGV);
217 print_modules(); 198 print_modules();
218 show_regs(regs); 199 show_regs(regs);
diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c
index 17431f63de00..955a7b6fa0a4 100644
--- a/arch/s390/kernel/perf_event.c
+++ b/arch/s390/kernel/perf_event.c
@@ -222,7 +222,7 @@ static int __init service_level_perf_register(void)
222} 222}
223arch_initcall(service_level_perf_register); 223arch_initcall(service_level_perf_register);
224 224
225static int __perf_callchain_kernel(void *data, unsigned long address) 225static int __perf_callchain_kernel(void *data, unsigned long address, int reliable)
226{ 226{
227 struct perf_callchain_entry_ctx *entry = data; 227 struct perf_callchain_entry_ctx *entry = data;
228 228
diff --git a/arch/s390/kernel/stacktrace.c b/arch/s390/kernel/stacktrace.c
index 44f84b23d4e5..355db9db8210 100644
--- a/arch/s390/kernel/stacktrace.c
+++ b/arch/s390/kernel/stacktrace.c
@@ -27,12 +27,12 @@ static int __save_address(void *data, unsigned long address, int nosched)
27 return 1; 27 return 1;
28} 28}
29 29
30static int save_address(void *data, unsigned long address) 30static int save_address(void *data, unsigned long address, int reliable)
31{ 31{
32 return __save_address(data, address, 0); 32 return __save_address(data, address, 0);
33} 33}
34 34
35static int save_address_nosched(void *data, unsigned long address) 35static int save_address_nosched(void *data, unsigned long address, int reliable)
36{ 36{
37 return __save_address(data, address, 1); 37 return __save_address(data, address, 1);
38} 38}
diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c
index cd404aa3931c..4a0c5bce3552 100644
--- a/arch/s390/mm/hugetlbpage.c
+++ b/arch/s390/mm/hugetlbpage.c
@@ -217,6 +217,7 @@ static __init int setup_hugepagesz(char *opt)
217 } else if (MACHINE_HAS_EDAT2 && size == PUD_SIZE) { 217 } else if (MACHINE_HAS_EDAT2 && size == PUD_SIZE) {
218 hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT); 218 hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
219 } else { 219 } else {
220 hugetlb_bad_size();
220 pr_err("hugepagesz= specifies an unsupported page size %s\n", 221 pr_err("hugepagesz= specifies an unsupported page size %s\n",
221 string); 222 string);
222 return 0; 223 return 0;
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index f56a39bd8ba6..b3e9d18f2ec6 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -151,36 +151,40 @@ void __init free_initrd_mem(unsigned long start, unsigned long end)
151#ifdef CONFIG_MEMORY_HOTPLUG 151#ifdef CONFIG_MEMORY_HOTPLUG
152int arch_add_memory(int nid, u64 start, u64 size, bool for_device) 152int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
153{ 153{
154 unsigned long normal_end_pfn = PFN_DOWN(memblock_end_of_DRAM()); 154 unsigned long zone_start_pfn, zone_end_pfn, nr_pages;
155 unsigned long dma_end_pfn = PFN_DOWN(MAX_DMA_ADDRESS);
156 unsigned long start_pfn = PFN_DOWN(start); 155 unsigned long start_pfn = PFN_DOWN(start);
157 unsigned long size_pages = PFN_DOWN(size); 156 unsigned long size_pages = PFN_DOWN(size);
158 unsigned long nr_pages; 157 pg_data_t *pgdat = NODE_DATA(nid);
159 int rc, zone_enum; 158 struct zone *zone;
159 int rc, i;
160 160
161 rc = vmem_add_mapping(start, size); 161 rc = vmem_add_mapping(start, size);
162 if (rc) 162 if (rc)
163 return rc; 163 return rc;
164 164
165 while (size_pages > 0) { 165 for (i = 0; i < MAX_NR_ZONES; i++) {
166 if (start_pfn < dma_end_pfn) { 166 zone = pgdat->node_zones + i;
167 nr_pages = (start_pfn + size_pages > dma_end_pfn) ? 167 if (zone_idx(zone) != ZONE_MOVABLE) {
168 dma_end_pfn - start_pfn : size_pages; 168 /* Add range within existing zone limits, if possible */
169 zone_enum = ZONE_DMA; 169 zone_start_pfn = zone->zone_start_pfn;
170 } else if (start_pfn < normal_end_pfn) { 170 zone_end_pfn = zone->zone_start_pfn +
171 nr_pages = (start_pfn + size_pages > normal_end_pfn) ? 171 zone->spanned_pages;
172 normal_end_pfn - start_pfn : size_pages;
173 zone_enum = ZONE_NORMAL;
174 } else { 172 } else {
175 nr_pages = size_pages; 173 /* Add remaining range to ZONE_MOVABLE */
176 zone_enum = ZONE_MOVABLE; 174 zone_start_pfn = start_pfn;
175 zone_end_pfn = start_pfn + size_pages;
177 } 176 }
178 rc = __add_pages(nid, NODE_DATA(nid)->node_zones + zone_enum, 177 if (start_pfn < zone_start_pfn || start_pfn >= zone_end_pfn)
179 start_pfn, size_pages); 178 continue;
179 nr_pages = (start_pfn + size_pages > zone_end_pfn) ?
180 zone_end_pfn - start_pfn : size_pages;
181 rc = __add_pages(nid, zone, start_pfn, nr_pages);
180 if (rc) 182 if (rc)
181 break; 183 break;
182 start_pfn += nr_pages; 184 start_pfn += nr_pages;
183 size_pages -= nr_pages; 185 size_pages -= nr_pages;
186 if (!size_pages)
187 break;
184 } 188 }
185 if (rc) 189 if (rc)
186 vmem_remove_mapping(start, size); 190 vmem_remove_mapping(start, size);
diff --git a/arch/s390/oprofile/init.c b/arch/s390/oprofile/init.c
index 16f4c3960b87..9a4de4599c7b 100644
--- a/arch/s390/oprofile/init.c
+++ b/arch/s390/oprofile/init.c
@@ -13,7 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <asm/processor.h> 14#include <asm/processor.h>
15 15
16static int __s390_backtrace(void *data, unsigned long address) 16static int __s390_backtrace(void *data, unsigned long address, int reliable)
17{ 17{
18 unsigned int *depth = data; 18 unsigned int *depth = data;
19 19
diff --git a/arch/x86/entry/Makefile b/arch/x86/entry/Makefile
index 77f28ce9c646..9976fcecd17e 100644
--- a/arch/x86/entry/Makefile
+++ b/arch/x86/entry/Makefile
@@ -5,8 +5,8 @@
5OBJECT_FILES_NON_STANDARD_entry_$(BITS).o := y 5OBJECT_FILES_NON_STANDARD_entry_$(BITS).o := y
6OBJECT_FILES_NON_STANDARD_entry_64_compat.o := y 6OBJECT_FILES_NON_STANDARD_entry_64_compat.o := y
7 7
8CFLAGS_syscall_64.o += -Wno-override-init 8CFLAGS_syscall_64.o += $(call cc-option,-Wno-override-init,)
9CFLAGS_syscall_32.o += -Wno-override-init 9CFLAGS_syscall_32.o += $(call cc-option,-Wno-override-init,)
10obj-y := entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o 10obj-y := entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o
11obj-y += common.o 11obj-y += common.o
12 12
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index eab0915f5995..a74a2dbc0180 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3607,10 +3607,14 @@ __init int intel_pmu_init(void)
3607 3607
3608 /* 3608 /*
3609 * Quirk: v2 perfmon does not report fixed-purpose events, so 3609 * Quirk: v2 perfmon does not report fixed-purpose events, so
3610 * assume at least 3 events: 3610 * assume at least 3 events, when not running in a hypervisor:
3611 */ 3611 */
3612 if (version > 1) 3612 if (version > 1) {
3613 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3); 3613 int assume = 3 * !boot_cpu_has(X86_FEATURE_HYPERVISOR);
3614
3615 x86_pmu.num_counters_fixed =
3616 max((int)edx.split.num_counters_fixed, assume);
3617 }
3614 3618
3615 if (boot_cpu_has(X86_FEATURE_PDCM)) { 3619 if (boot_cpu_has(X86_FEATURE_PDCM)) {
3616 u64 capabilities; 3620 u64 capabilities;
diff --git a/arch/x86/events/intel/cstate.c b/arch/x86/events/intel/cstate.c
index 3ca87b5a8677..4f5ac726335f 100644
--- a/arch/x86/events/intel/cstate.c
+++ b/arch/x86/events/intel/cstate.c
@@ -48,7 +48,8 @@
48 * Scope: Core 48 * Scope: Core
49 * MSR_CORE_C6_RESIDENCY: CORE C6 Residency Counter 49 * MSR_CORE_C6_RESIDENCY: CORE C6 Residency Counter
50 * perf code: 0x02 50 * perf code: 0x02
51 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW,SKL 51 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW
52 * SKL,KNL
52 * Scope: Core 53 * Scope: Core
53 * MSR_CORE_C7_RESIDENCY: CORE C7 Residency Counter 54 * MSR_CORE_C7_RESIDENCY: CORE C7 Residency Counter
54 * perf code: 0x03 55 * perf code: 0x03
@@ -56,15 +57,16 @@
56 * Scope: Core 57 * Scope: Core
57 * MSR_PKG_C2_RESIDENCY: Package C2 Residency Counter. 58 * MSR_PKG_C2_RESIDENCY: Package C2 Residency Counter.
58 * perf code: 0x00 59 * perf code: 0x00
59 * Available model: SNB,IVB,HSW,BDW,SKL 60 * Available model: SNB,IVB,HSW,BDW,SKL,KNL
60 * Scope: Package (physical package) 61 * Scope: Package (physical package)
61 * MSR_PKG_C3_RESIDENCY: Package C3 Residency Counter. 62 * MSR_PKG_C3_RESIDENCY: Package C3 Residency Counter.
62 * perf code: 0x01 63 * perf code: 0x01
63 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL 64 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL,KNL
64 * Scope: Package (physical package) 65 * Scope: Package (physical package)
65 * MSR_PKG_C6_RESIDENCY: Package C6 Residency Counter. 66 * MSR_PKG_C6_RESIDENCY: Package C6 Residency Counter.
66 * perf code: 0x02 67 * perf code: 0x02
67 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW,SKL 68 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW
69 * SKL,KNL
68 * Scope: Package (physical package) 70 * Scope: Package (physical package)
69 * MSR_PKG_C7_RESIDENCY: Package C7 Residency Counter. 71 * MSR_PKG_C7_RESIDENCY: Package C7 Residency Counter.
70 * perf code: 0x03 72 * perf code: 0x03
@@ -118,6 +120,7 @@ struct cstate_model {
118 120
119/* Quirk flags */ 121/* Quirk flags */
120#define SLM_PKG_C6_USE_C7_MSR (1UL << 0) 122#define SLM_PKG_C6_USE_C7_MSR (1UL << 0)
123#define KNL_CORE_C6_MSR (1UL << 1)
121 124
122struct perf_cstate_msr { 125struct perf_cstate_msr {
123 u64 msr; 126 u64 msr;
@@ -488,6 +491,18 @@ static const struct cstate_model slm_cstates __initconst = {
488 .quirks = SLM_PKG_C6_USE_C7_MSR, 491 .quirks = SLM_PKG_C6_USE_C7_MSR,
489}; 492};
490 493
494
495static const struct cstate_model knl_cstates __initconst = {
496 .core_events = BIT(PERF_CSTATE_CORE_C6_RES),
497
498 .pkg_events = BIT(PERF_CSTATE_PKG_C2_RES) |
499 BIT(PERF_CSTATE_PKG_C3_RES) |
500 BIT(PERF_CSTATE_PKG_C6_RES),
501 .quirks = KNL_CORE_C6_MSR,
502};
503
504
505
491#define X86_CSTATES_MODEL(model, states) \ 506#define X86_CSTATES_MODEL(model, states) \
492 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long) &(states) } 507 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long) &(states) }
493 508
@@ -523,6 +538,8 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = {
523 538
524 X86_CSTATES_MODEL(INTEL_FAM6_SKYLAKE_MOBILE, snb_cstates), 539 X86_CSTATES_MODEL(INTEL_FAM6_SKYLAKE_MOBILE, snb_cstates),
525 X86_CSTATES_MODEL(INTEL_FAM6_SKYLAKE_DESKTOP, snb_cstates), 540 X86_CSTATES_MODEL(INTEL_FAM6_SKYLAKE_DESKTOP, snb_cstates),
541
542 X86_CSTATES_MODEL(INTEL_FAM6_XEON_PHI_KNL, knl_cstates),
526 { }, 543 { },
527}; 544};
528MODULE_DEVICE_TABLE(x86cpu, intel_cstates_match); 545MODULE_DEVICE_TABLE(x86cpu, intel_cstates_match);
@@ -558,6 +575,11 @@ static int __init cstate_probe(const struct cstate_model *cm)
558 if (cm->quirks & SLM_PKG_C6_USE_C7_MSR) 575 if (cm->quirks & SLM_PKG_C6_USE_C7_MSR)
559 pkg_msr[PERF_CSTATE_PKG_C6_RES].msr = MSR_PKG_C7_RESIDENCY; 576 pkg_msr[PERF_CSTATE_PKG_C6_RES].msr = MSR_PKG_C7_RESIDENCY;
560 577
578 /* KNL has different MSR for CORE C6 */
579 if (cm->quirks & KNL_CORE_C6_MSR)
580 pkg_msr[PERF_CSTATE_CORE_C6_RES].msr = MSR_KNL_CORE_C6_RESIDENCY;
581
582
561 has_cstate_core = cstate_probe_msr(cm->core_events, 583 has_cstate_core = cstate_probe_msr(cm->core_events,
562 PERF_CSTATE_CORE_EVENT_MAX, 584 PERF_CSTATE_CORE_EVENT_MAX,
563 core_msr, core_events_attrs); 585 core_msr, core_events_attrs);
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index de25aad07853..d34bd370074b 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -351,4 +351,10 @@ extern void arch_phys_wc_del(int handle);
351#define arch_phys_wc_add arch_phys_wc_add 351#define arch_phys_wc_add arch_phys_wc_add
352#endif 352#endif
353 353
354#ifdef CONFIG_X86_PAT
355extern int arch_io_reserve_memtype_wc(resource_size_t start, resource_size_t size);
356extern void arch_io_free_memtype_wc(resource_size_t start, resource_size_t size);
357#define arch_io_reserve_memtype_wc arch_io_reserve_memtype_wc
358#endif
359
354#endif /* _ASM_X86_IO_H */ 360#endif /* _ASM_X86_IO_H */
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 8a5abaa7d453..931ced8ca345 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -454,6 +454,7 @@ static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger,
454 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK; 454 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
455 455
456 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi); 456 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
457 acpi_penalize_sci_irq(bus_irq, trigger, polarity);
457 458
458 /* 459 /*
459 * stash over-ride to indicate we've been here 460 * stash over-ride to indicate we've been here
diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 620ab06bcf45..017bda12caae 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -429,7 +429,7 @@ int __init save_microcode_in_initrd_amd(void)
429 * We need the physical address of the container for both bitness since 429 * We need the physical address of the container for both bitness since
430 * boot_params.hdr.ramdisk_image is a physical address. 430 * boot_params.hdr.ramdisk_image is a physical address.
431 */ 431 */
432 cont = __pa(container); 432 cont = __pa_nodebug(container);
433 cont_va = container; 433 cont_va = container;
434#endif 434#endif
435 435
diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
index efe73aacf966..7b0d3da52fb4 100644
--- a/arch/x86/kernel/mcount_64.S
+++ b/arch/x86/kernel/mcount_64.S
@@ -18,8 +18,10 @@
18 18
19#ifdef CC_USING_FENTRY 19#ifdef CC_USING_FENTRY
20# define function_hook __fentry__ 20# define function_hook __fentry__
21EXPORT_SYMBOL(__fentry__)
21#else 22#else
22# define function_hook mcount 23# define function_hook mcount
24EXPORT_SYMBOL(mcount)
23#endif 25#endif
24 26
25/* All cases save the original rbp (8 bytes) */ 27/* All cases save the original rbp (8 bytes) */
@@ -295,7 +297,6 @@ trace:
295 jmp fgraph_trace 297 jmp fgraph_trace
296END(function_hook) 298END(function_hook)
297#endif /* CONFIG_DYNAMIC_FTRACE */ 299#endif /* CONFIG_DYNAMIC_FTRACE */
298EXPORT_SYMBOL(function_hook)
299#endif /* CONFIG_FUNCTION_TRACER */ 300#endif /* CONFIG_FUNCTION_TRACER */
300 301
301#ifdef CONFIG_FUNCTION_GRAPH_TRACER 302#ifdef CONFIG_FUNCTION_GRAPH_TRACER
diff --git a/arch/x86/kernel/quirks.c b/arch/x86/kernel/quirks.c
index 51402a7e4ca6..0bee04d41bed 100644
--- a/arch/x86/kernel/quirks.c
+++ b/arch/x86/kernel/quirks.c
@@ -625,8 +625,6 @@ static void amd_disable_seq_and_redirect_scrub(struct pci_dev *dev)
625DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3, 625DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3,
626 amd_disable_seq_and_redirect_scrub); 626 amd_disable_seq_and_redirect_scrub);
627 627
628#endif
629
630#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE) 628#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
631#include <linux/jump_label.h> 629#include <linux/jump_label.h>
632#include <asm/string_64.h> 630#include <asm/string_64.h>
@@ -657,3 +655,4 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2fc0, quirk_intel_brickland_xeon_
657DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fc0, quirk_intel_brickland_xeon_ras_cap); 655DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fc0, quirk_intel_brickland_xeon_ras_cap);
658DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_ras_cap); 656DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_ras_cap);
659#endif 657#endif
658#endif
diff --git a/arch/x86/kernel/unwind_guess.c b/arch/x86/kernel/unwind_guess.c
index 9298993dc8b7..2d721e533cf4 100644
--- a/arch/x86/kernel/unwind_guess.c
+++ b/arch/x86/kernel/unwind_guess.c
@@ -47,7 +47,14 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
47 get_stack_info(first_frame, state->task, &state->stack_info, 47 get_stack_info(first_frame, state->task, &state->stack_info,
48 &state->stack_mask); 48 &state->stack_mask);
49 49
50 if (!__kernel_text_address(*first_frame)) 50 /*
51 * The caller can provide the address of the first frame directly
52 * (first_frame) or indirectly (regs->sp) to indicate which stack frame
53 * to start unwinding at. Skip ahead until we reach it.
54 */
55 if (!unwind_done(state) &&
56 (!on_stack(&state->stack_info, first_frame, sizeof(long)) ||
57 !__kernel_text_address(*first_frame)))
51 unwind_next_frame(state); 58 unwind_next_frame(state);
52} 59}
53EXPORT_SYMBOL_GPL(__unwind_start); 60EXPORT_SYMBOL_GPL(__unwind_start);
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index ddd2661c4502..887e57182716 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -104,10 +104,10 @@ void __init kernel_randomize_memory(void)
104 * consistent with the vaddr_start/vaddr_end variables. 104 * consistent with the vaddr_start/vaddr_end variables.
105 */ 105 */
106 BUILD_BUG_ON(vaddr_start >= vaddr_end); 106 BUILD_BUG_ON(vaddr_start >= vaddr_end);
107 BUILD_BUG_ON(config_enabled(CONFIG_X86_ESPFIX64) && 107 BUILD_BUG_ON(IS_ENABLED(CONFIG_X86_ESPFIX64) &&
108 vaddr_end >= EFI_VA_START); 108 vaddr_end >= EFI_VA_START);
109 BUILD_BUG_ON((config_enabled(CONFIG_X86_ESPFIX64) || 109 BUILD_BUG_ON((IS_ENABLED(CONFIG_X86_ESPFIX64) ||
110 config_enabled(CONFIG_EFI)) && 110 IS_ENABLED(CONFIG_EFI)) &&
111 vaddr_end >= __START_KERNEL_map); 111 vaddr_end >= __START_KERNEL_map);
112 BUILD_BUG_ON(vaddr_end > __START_KERNEL_map); 112 BUILD_BUG_ON(vaddr_end > __START_KERNEL_map);
113 113
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
index 170cc4ff057b..83e701f160a9 100644
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -730,6 +730,20 @@ void io_free_memtype(resource_size_t start, resource_size_t end)
730 free_memtype(start, end); 730 free_memtype(start, end);
731} 731}
732 732
733int arch_io_reserve_memtype_wc(resource_size_t start, resource_size_t size)
734{
735 enum page_cache_mode type = _PAGE_CACHE_MODE_WC;
736
737 return io_reserve_memtype(start, start + size, &type);
738}
739EXPORT_SYMBOL(arch_io_reserve_memtype_wc);
740
741void arch_io_free_memtype_wc(resource_size_t start, resource_size_t size)
742{
743 io_free_memtype(start, start + size);
744}
745EXPORT_SYMBOL(arch_io_free_memtype_wc);
746
733pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, 747pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
734 unsigned long size, pgprot_t vma_prot) 748 unsigned long size, pgprot_t vma_prot)
735{ 749{
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index c0fdd57da7aa..bdd855685403 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1837,6 +1837,7 @@ static void __init init_hvm_pv_info(void)
1837 1837
1838 xen_domain_type = XEN_HVM_DOMAIN; 1838 xen_domain_type = XEN_HVM_DOMAIN;
1839} 1839}
1840#endif
1840 1841
1841static int xen_cpu_up_prepare(unsigned int cpu) 1842static int xen_cpu_up_prepare(unsigned int cpu)
1842{ 1843{
@@ -1887,6 +1888,7 @@ static int xen_cpu_up_online(unsigned int cpu)
1887 return 0; 1888 return 0;
1888} 1889}
1889 1890
1891#ifdef CONFIG_XEN_PVHVM
1890#ifdef CONFIG_KEXEC_CORE 1892#ifdef CONFIG_KEXEC_CORE
1891static void xen_hvm_shutdown(void) 1893static void xen_hvm_shutdown(void)
1892{ 1894{
diff --git a/block/badblocks.c b/block/badblocks.c
index 6610e282a03e..6ebcef282314 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -133,6 +133,26 @@ retry:
133} 133}
134EXPORT_SYMBOL_GPL(badblocks_check); 134EXPORT_SYMBOL_GPL(badblocks_check);
135 135
136static void badblocks_update_acked(struct badblocks *bb)
137{
138 u64 *p = bb->page;
139 int i;
140 bool unacked = false;
141
142 if (!bb->unacked_exist)
143 return;
144
145 for (i = 0; i < bb->count ; i++) {
146 if (!BB_ACK(p[i])) {
147 unacked = true;
148 break;
149 }
150 }
151
152 if (!unacked)
153 bb->unacked_exist = 0;
154}
155
136/** 156/**
137 * badblocks_set() - Add a range of bad blocks to the table. 157 * badblocks_set() - Add a range of bad blocks to the table.
138 * @bb: the badblocks structure that holds all badblock information 158 * @bb: the badblocks structure that holds all badblock information
@@ -294,6 +314,8 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
294 bb->changed = 1; 314 bb->changed = 1;
295 if (!acknowledged) 315 if (!acknowledged)
296 bb->unacked_exist = 1; 316 bb->unacked_exist = 1;
317 else
318 badblocks_update_acked(bb);
297 write_sequnlock_irqrestore(&bb->lock, flags); 319 write_sequnlock_irqrestore(&bb->lock, flags);
298 320
299 return rv; 321 return rv;
@@ -401,6 +423,7 @@ int badblocks_clear(struct badblocks *bb, sector_t s, int sectors)
401 } 423 }
402 } 424 }
403 425
426 badblocks_update_acked(bb);
404 bb->changed = 1; 427 bb->changed = 1;
405out: 428out:
406 write_sequnlock_irq(&bb->lock); 429 write_sequnlock_irq(&bb->lock);
diff --git a/block/blk-flush.c b/block/blk-flush.c
index 6a14b68b9135..3c882cbc7541 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -343,6 +343,34 @@ static void flush_data_end_io(struct request *rq, int error)
343 struct blk_flush_queue *fq = blk_get_flush_queue(q, NULL); 343 struct blk_flush_queue *fq = blk_get_flush_queue(q, NULL);
344 344
345 /* 345 /*
346 * Updating q->in_flight[] here for making this tag usable
347 * early. Because in blk_queue_start_tag(),
348 * q->in_flight[BLK_RW_ASYNC] is used to limit async I/O and
349 * reserve tags for sync I/O.
350 *
351 * More importantly this way can avoid the following I/O
352 * deadlock:
353 *
354 * - suppose there are 40 fua requests comming to flush queue
355 * and queue depth is 31
356 * - 30 rqs are scheduled then blk_queue_start_tag() can't alloc
357 * tag for async I/O any more
358 * - all the 30 rqs are completed before FLUSH_PENDING_TIMEOUT
359 * and flush_data_end_io() is called
360 * - the other rqs still can't go ahead if not updating
361 * q->in_flight[BLK_RW_ASYNC] here, meantime these rqs
362 * are held in flush data queue and make no progress of
363 * handling post flush rq
364 * - only after the post flush rq is handled, all these rqs
365 * can be completed
366 */
367
368 elv_completed_request(q, rq);
369
370 /* for avoiding double accounting */
371 rq->cmd_flags &= ~REQ_STARTED;
372
373 /*
346 * After populating an empty queue, kick it to avoid stall. Read 374 * After populating an empty queue, kick it to avoid stall. Read
347 * the comment in flush_end_io(). 375 * the comment in flush_end_io().
348 */ 376 */
diff --git a/block/blk-mq.c b/block/blk-mq.c
index ddc2eed64771..f3d27a6dee09 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1217,9 +1217,9 @@ static struct request *blk_mq_map_request(struct request_queue *q,
1217 blk_mq_set_alloc_data(&alloc_data, q, 0, ctx, hctx); 1217 blk_mq_set_alloc_data(&alloc_data, q, 0, ctx, hctx);
1218 rq = __blk_mq_alloc_request(&alloc_data, op, op_flags); 1218 rq = __blk_mq_alloc_request(&alloc_data, op, op_flags);
1219 1219
1220 hctx->queued++; 1220 data->hctx = alloc_data.hctx;
1221 data->hctx = hctx; 1221 data->ctx = alloc_data.ctx;
1222 data->ctx = ctx; 1222 data->hctx->queued++;
1223 return rq; 1223 return rq;
1224} 1224}
1225 1225
diff --git a/drivers/acpi/acpica/dsinit.c b/drivers/acpi/acpica/dsinit.c
index f1e6dcc7a827..54d48b90de2c 100644
--- a/drivers/acpi/acpica/dsinit.c
+++ b/drivers/acpi/acpica/dsinit.c
@@ -46,6 +46,7 @@
46#include "acdispat.h" 46#include "acdispat.h"
47#include "acnamesp.h" 47#include "acnamesp.h"
48#include "actables.h" 48#include "actables.h"
49#include "acinterp.h"
49 50
50#define _COMPONENT ACPI_DISPATCHER 51#define _COMPONENT ACPI_DISPATCHER
51ACPI_MODULE_NAME("dsinit") 52ACPI_MODULE_NAME("dsinit")
@@ -214,23 +215,17 @@ acpi_ds_initialize_objects(u32 table_index,
214 215
215 /* Walk entire namespace from the supplied root */ 216 /* Walk entire namespace from the supplied root */
216 217
217 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
218 if (ACPI_FAILURE(status)) {
219 return_ACPI_STATUS(status);
220 }
221
222 /* 218 /*
223 * We don't use acpi_walk_namespace since we do not want to acquire 219 * We don't use acpi_walk_namespace since we do not want to acquire
224 * the namespace reader lock. 220 * the namespace reader lock.
225 */ 221 */
226 status = 222 status =
227 acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX, 223 acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
228 ACPI_NS_WALK_UNLOCK, acpi_ds_init_one_object, 224 0, acpi_ds_init_one_object, NULL, &info,
229 NULL, &info, NULL); 225 NULL);
230 if (ACPI_FAILURE(status)) { 226 if (ACPI_FAILURE(status)) {
231 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); 227 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
232 } 228 }
233 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
234 229
235 status = acpi_get_table_by_index(table_index, &table); 230 status = acpi_get_table_by_index(table_index, &table);
236 if (ACPI_FAILURE(status)) { 231 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/acpica/dsmethod.c b/drivers/acpi/acpica/dsmethod.c
index 32e9ddc0cf2b..2b3210f42a46 100644
--- a/drivers/acpi/acpica/dsmethod.c
+++ b/drivers/acpi/acpica/dsmethod.c
@@ -99,14 +99,11 @@ acpi_ds_auto_serialize_method(struct acpi_namespace_node *node,
99 "Method auto-serialization parse [%4.4s] %p\n", 99 "Method auto-serialization parse [%4.4s] %p\n",
100 acpi_ut_get_node_name(node), node)); 100 acpi_ut_get_node_name(node), node));
101 101
102 acpi_ex_enter_interpreter();
103
104 /* Create/Init a root op for the method parse tree */ 102 /* Create/Init a root op for the method parse tree */
105 103
106 op = acpi_ps_alloc_op(AML_METHOD_OP, obj_desc->method.aml_start); 104 op = acpi_ps_alloc_op(AML_METHOD_OP, obj_desc->method.aml_start);
107 if (!op) { 105 if (!op) {
108 status = AE_NO_MEMORY; 106 return_ACPI_STATUS(AE_NO_MEMORY);
109 goto unlock;
110 } 107 }
111 108
112 acpi_ps_set_name(op, node->name.integer); 109 acpi_ps_set_name(op, node->name.integer);
@@ -118,8 +115,7 @@ acpi_ds_auto_serialize_method(struct acpi_namespace_node *node,
118 acpi_ds_create_walk_state(node->owner_id, NULL, NULL, NULL); 115 acpi_ds_create_walk_state(node->owner_id, NULL, NULL, NULL);
119 if (!walk_state) { 116 if (!walk_state) {
120 acpi_ps_free_op(op); 117 acpi_ps_free_op(op);
121 status = AE_NO_MEMORY; 118 return_ACPI_STATUS(AE_NO_MEMORY);
122 goto unlock;
123 } 119 }
124 120
125 status = acpi_ds_init_aml_walk(walk_state, op, node, 121 status = acpi_ds_init_aml_walk(walk_state, op, node,
@@ -138,8 +134,6 @@ acpi_ds_auto_serialize_method(struct acpi_namespace_node *node,
138 status = acpi_ps_parse_aml(walk_state); 134 status = acpi_ps_parse_aml(walk_state);
139 135
140 acpi_ps_delete_parse_tree(op); 136 acpi_ps_delete_parse_tree(op);
141unlock:
142 acpi_ex_exit_interpreter();
143 return_ACPI_STATUS(status); 137 return_ACPI_STATUS(status);
144} 138}
145 139
@@ -731,26 +725,6 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
731 acpi_ds_method_data_delete_all(walk_state); 725 acpi_ds_method_data_delete_all(walk_state);
732 726
733 /* 727 /*
734 * If method is serialized, release the mutex and restore the
735 * current sync level for this thread
736 */
737 if (method_desc->method.mutex) {
738
739 /* Acquisition Depth handles recursive calls */
740
741 method_desc->method.mutex->mutex.acquisition_depth--;
742 if (!method_desc->method.mutex->mutex.acquisition_depth) {
743 walk_state->thread->current_sync_level =
744 method_desc->method.mutex->mutex.
745 original_sync_level;
746
747 acpi_os_release_mutex(method_desc->method.
748 mutex->mutex.os_mutex);
749 method_desc->method.mutex->mutex.thread_id = 0;
750 }
751 }
752
753 /*
754 * Delete any namespace objects created anywhere within the 728 * Delete any namespace objects created anywhere within the
755 * namespace by the execution of this method. Unless: 729 * namespace by the execution of this method. Unless:
756 * 1) This method is a module-level executable code method, in which 730 * 1) This method is a module-level executable code method, in which
@@ -786,6 +760,26 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
786 ~ACPI_METHOD_MODIFIED_NAMESPACE; 760 ~ACPI_METHOD_MODIFIED_NAMESPACE;
787 } 761 }
788 } 762 }
763
764 /*
765 * If method is serialized, release the mutex and restore the
766 * current sync level for this thread
767 */
768 if (method_desc->method.mutex) {
769
770 /* Acquisition Depth handles recursive calls */
771
772 method_desc->method.mutex->mutex.acquisition_depth--;
773 if (!method_desc->method.mutex->mutex.acquisition_depth) {
774 walk_state->thread->current_sync_level =
775 method_desc->method.mutex->mutex.
776 original_sync_level;
777
778 acpi_os_release_mutex(method_desc->method.
779 mutex->mutex.os_mutex);
780 method_desc->method.mutex->mutex.thread_id = 0;
781 }
782 }
789 } 783 }
790 784
791 /* Decrement the thread count on the method */ 785 /* Decrement the thread count on the method */
diff --git a/drivers/acpi/acpica/dswload2.c b/drivers/acpi/acpica/dswload2.c
index 028b22a3154e..e36218206bb0 100644
--- a/drivers/acpi/acpica/dswload2.c
+++ b/drivers/acpi/acpica/dswload2.c
@@ -607,11 +607,9 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
607 } 607 }
608 } 608 }
609 609
610 acpi_ex_exit_interpreter();
611 status = 610 status =
612 acpi_ev_initialize_region 611 acpi_ev_initialize_region
613 (acpi_ns_get_attached_object(node), FALSE); 612 (acpi_ns_get_attached_object(node), FALSE);
614 acpi_ex_enter_interpreter();
615 613
616 if (ACPI_FAILURE(status)) { 614 if (ACPI_FAILURE(status)) {
617 /* 615 /*
diff --git a/drivers/acpi/acpica/evrgnini.c b/drivers/acpi/acpica/evrgnini.c
index 3843f1fc5dbb..75ddd160a716 100644
--- a/drivers/acpi/acpica/evrgnini.c
+++ b/drivers/acpi/acpica/evrgnini.c
@@ -45,6 +45,7 @@
45#include "accommon.h" 45#include "accommon.h"
46#include "acevents.h" 46#include "acevents.h"
47#include "acnamesp.h" 47#include "acnamesp.h"
48#include "acinterp.h"
48 49
49#define _COMPONENT ACPI_EVENTS 50#define _COMPONENT ACPI_EVENTS
50ACPI_MODULE_NAME("evrgnini") 51ACPI_MODULE_NAME("evrgnini")
@@ -597,9 +598,11 @@ acpi_ev_initialize_region(union acpi_operand_object *region_obj,
597 } 598 }
598 } 599 }
599 600
601 acpi_ex_exit_interpreter();
600 status = 602 status =
601 acpi_ev_execute_reg_method(region_obj, 603 acpi_ev_execute_reg_method(region_obj,
602 ACPI_REG_CONNECT); 604 ACPI_REG_CONNECT);
605 acpi_ex_enter_interpreter();
603 606
604 if (acpi_ns_locked) { 607 if (acpi_ns_locked) {
605 status = 608 status =
diff --git a/drivers/acpi/acpica/nsload.c b/drivers/acpi/acpica/nsload.c
index 334d3c5ba617..d1f20143bb11 100644
--- a/drivers/acpi/acpica/nsload.c
+++ b/drivers/acpi/acpica/nsload.c
@@ -137,7 +137,9 @@ unlock:
137 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 137 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
138 "**** Begin Table Object Initialization\n")); 138 "**** Begin Table Object Initialization\n"));
139 139
140 acpi_ex_enter_interpreter();
140 status = acpi_ds_initialize_objects(table_index, node); 141 status = acpi_ds_initialize_objects(table_index, node);
142 acpi_ex_exit_interpreter();
141 143
142 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 144 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
143 "**** Completed Table Object Initialization\n")); 145 "**** Completed Table Object Initialization\n"));
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index f0a029e68d3e..0d099a24f776 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -662,7 +662,7 @@ static int ghes_proc(struct ghes *ghes)
662 ghes_do_proc(ghes, ghes->estatus); 662 ghes_do_proc(ghes, ghes->estatus);
663out: 663out:
664 ghes_clear_estatus(ghes); 664 ghes_clear_estatus(ghes);
665 return 0; 665 return rc;
666} 666}
667 667
668static void ghes_add_timer(struct ghes *ghes) 668static void ghes_add_timer(struct ghes *ghes)
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index c983bf733ad3..bc3d914dfc3e 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -87,6 +87,7 @@ struct acpi_pci_link {
87 87
88static LIST_HEAD(acpi_link_list); 88static LIST_HEAD(acpi_link_list);
89static DEFINE_MUTEX(acpi_link_lock); 89static DEFINE_MUTEX(acpi_link_lock);
90static int sci_irq = -1, sci_penalty;
90 91
91/* -------------------------------------------------------------------------- 92/* --------------------------------------------------------------------------
92 PCI Link Device Management 93 PCI Link Device Management
@@ -496,25 +497,13 @@ static int acpi_irq_get_penalty(int irq)
496{ 497{
497 int penalty = 0; 498 int penalty = 0;
498 499
499 /* 500 if (irq == sci_irq)
500 * Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict 501 penalty += sci_penalty;
501 * with PCI IRQ attributes, mark ACPI SCI as ISA_ALWAYS so it won't be
502 * use for PCI IRQs.
503 */
504 if (irq == acpi_gbl_FADT.sci_interrupt) {
505 u32 type = irq_get_trigger_type(irq) & IRQ_TYPE_SENSE_MASK;
506
507 if (type != IRQ_TYPE_LEVEL_LOW)
508 penalty += PIRQ_PENALTY_ISA_ALWAYS;
509 else
510 penalty += PIRQ_PENALTY_PCI_USING;
511 }
512 502
513 if (irq < ACPI_MAX_ISA_IRQS) 503 if (irq < ACPI_MAX_ISA_IRQS)
514 return penalty + acpi_isa_irq_penalty[irq]; 504 return penalty + acpi_isa_irq_penalty[irq];
515 505
516 penalty += acpi_irq_pci_sharing_penalty(irq); 506 return penalty + acpi_irq_pci_sharing_penalty(irq);
517 return penalty;
518} 507}
519 508
520int __init acpi_irq_penalty_init(void) 509int __init acpi_irq_penalty_init(void)
@@ -619,6 +608,10 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
619 acpi_device_bid(link->device)); 608 acpi_device_bid(link->device));
620 return -ENODEV; 609 return -ENODEV;
621 } else { 610 } else {
611 if (link->irq.active < ACPI_MAX_ISA_IRQS)
612 acpi_isa_irq_penalty[link->irq.active] +=
613 PIRQ_PENALTY_PCI_USING;
614
622 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n", 615 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
623 acpi_device_name(link->device), 616 acpi_device_name(link->device),
624 acpi_device_bid(link->device), link->irq.active); 617 acpi_device_bid(link->device), link->irq.active);
@@ -849,7 +842,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
849 continue; 842 continue;
850 843
851 if (used) 844 if (used)
852 new_penalty = acpi_irq_get_penalty(irq) + 845 new_penalty = acpi_isa_irq_penalty[irq] +
853 PIRQ_PENALTY_ISA_USED; 846 PIRQ_PENALTY_ISA_USED;
854 else 847 else
855 new_penalty = 0; 848 new_penalty = 0;
@@ -871,7 +864,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
871void acpi_penalize_isa_irq(int irq, int active) 864void acpi_penalize_isa_irq(int irq, int active)
872{ 865{
873 if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty))) 866 if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty)))
874 acpi_isa_irq_penalty[irq] = acpi_irq_get_penalty(irq) + 867 acpi_isa_irq_penalty[irq] +=
875 (active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING); 868 (active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING);
876} 869}
877 870
@@ -881,6 +874,17 @@ bool acpi_isa_irq_available(int irq)
881 acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS); 874 acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS);
882} 875}
883 876
877void acpi_penalize_sci_irq(int irq, int trigger, int polarity)
878{
879 sci_irq = irq;
880
881 if (trigger == ACPI_MADT_TRIGGER_LEVEL &&
882 polarity == ACPI_MADT_POLARITY_ACTIVE_LOW)
883 sci_penalty = PIRQ_PENALTY_PCI_USING;
884 else
885 sci_penalty = PIRQ_PENALTY_ISA_ALWAYS;
886}
887
884/* 888/*
885 * Over-ride default table to reserve additional IRQs for use by ISA 889 * Over-ride default table to reserve additional IRQs for use by ISA
886 * e.g. acpi_irq_isa=5 890 * e.g. acpi_irq_isa=5
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index ba5f11cebee2..9669fc7c19df 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1418,31 +1418,34 @@ static int ahci_init_msi(struct pci_dev *pdev, unsigned int n_ports,
1418 * Message mode could be enforced. In this case assume that advantage 1418 * Message mode could be enforced. In this case assume that advantage
1419 * of multipe MSIs is negated and use single MSI mode instead. 1419 * of multipe MSIs is negated and use single MSI mode instead.
1420 */ 1420 */
1421 nvec = pci_alloc_irq_vectors(pdev, n_ports, INT_MAX, 1421 if (n_ports > 1) {
1422 PCI_IRQ_MSIX | PCI_IRQ_MSI); 1422 nvec = pci_alloc_irq_vectors(pdev, n_ports, INT_MAX,
1423 if (nvec > 0) { 1423 PCI_IRQ_MSIX | PCI_IRQ_MSI);
1424 if (!(readl(hpriv->mmio + HOST_CTL) & HOST_MRSM)) { 1424 if (nvec > 0) {
1425 hpriv->get_irq_vector = ahci_get_irq_vector; 1425 if (!(readl(hpriv->mmio + HOST_CTL) & HOST_MRSM)) {
1426 hpriv->flags |= AHCI_HFLAG_MULTI_MSI; 1426 hpriv->get_irq_vector = ahci_get_irq_vector;
1427 return nvec; 1427 hpriv->flags |= AHCI_HFLAG_MULTI_MSI;
1428 return nvec;
1429 }
1430
1431 /*
1432 * Fallback to single MSI mode if the controller
1433 * enforced MRSM mode.
1434 */
1435 printk(KERN_INFO
1436 "ahci: MRSM is on, fallback to single MSI\n");
1437 pci_free_irq_vectors(pdev);
1428 } 1438 }
1429 1439
1430 /* 1440 /*
1431 * Fallback to single MSI mode if the controller enforced MRSM 1441 * -ENOSPC indicated we don't have enough vectors. Don't bother
1432 * mode. 1442 * trying a single vectors for any other error:
1433 */ 1443 */
1434 printk(KERN_INFO "ahci: MRSM is on, fallback to single MSI\n"); 1444 if (nvec < 0 && nvec != -ENOSPC)
1435 pci_free_irq_vectors(pdev); 1445 return nvec;
1436 } 1446 }
1437 1447
1438 /* 1448 /*
1439 * -ENOSPC indicated we don't have enough vectors. Don't bother trying
1440 * a single vectors for any other error:
1441 */
1442 if (nvec < 0 && nvec != -ENOSPC)
1443 return nvec;
1444
1445 /*
1446 * If the host is not capable of supporting per-port vectors, fall 1449 * If the host is not capable of supporting per-port vectors, fall
1447 * back to single MSI before finally attempting single MSI-X. 1450 * back to single MSI before finally attempting single MSI-X.
1448 */ 1451 */
@@ -1617,7 +1620,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1617 /* legacy intx interrupts */ 1620 /* legacy intx interrupts */
1618 pci_intx(pdev, 1); 1621 pci_intx(pdev, 1);
1619 } 1622 }
1620 hpriv->irq = pdev->irq; 1623 hpriv->irq = pci_irq_vector(pdev, 0);
1621 1624
1622 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) 1625 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
1623 host->flags |= ATA_HOST_PARALLEL_SCAN; 1626 host->flags |= ATA_HOST_PARALLEL_SCAN;
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 811e11c82f32..0809cda93cc0 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -2954,7 +2954,7 @@ DAC960_DetectController(struct pci_dev *PCI_Device,
2954 case DAC960_PD_Controller: 2954 case DAC960_PD_Controller:
2955 if (!request_region(Controller->IO_Address, 0x80, 2955 if (!request_region(Controller->IO_Address, 0x80,
2956 Controller->FullModelName)) { 2956 Controller->FullModelName)) {
2957 DAC960_Error("IO port 0x%d busy for Controller at\n", 2957 DAC960_Error("IO port 0x%lx busy for Controller at\n",
2958 Controller, Controller->IO_Address); 2958 Controller, Controller->IO_Address);
2959 goto Failure; 2959 goto Failure;
2960 } 2960 }
@@ -2990,7 +2990,7 @@ DAC960_DetectController(struct pci_dev *PCI_Device,
2990 case DAC960_P_Controller: 2990 case DAC960_P_Controller:
2991 if (!request_region(Controller->IO_Address, 0x80, 2991 if (!request_region(Controller->IO_Address, 0x80,
2992 Controller->FullModelName)){ 2992 Controller->FullModelName)){
2993 DAC960_Error("IO port 0x%d busy for Controller at\n", 2993 DAC960_Error("IO port 0x%lx busy for Controller at\n",
2994 Controller, Controller->IO_Address); 2994 Controller, Controller->IO_Address);
2995 goto Failure; 2995 goto Failure;
2996 } 2996 }
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index ba405b55329f..19a16b2dbb91 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -164,7 +164,7 @@ static void sock_shutdown(struct nbd_device *nbd)
164 spin_lock(&nbd->sock_lock); 164 spin_lock(&nbd->sock_lock);
165 165
166 if (!nbd->sock) { 166 if (!nbd->sock) {
167 spin_unlock_irq(&nbd->sock_lock); 167 spin_unlock(&nbd->sock_lock);
168 return; 168 return;
169 } 169 }
170 170
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 482794526e8c..d2d2c89de5b4 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -84,14 +84,14 @@ static size_t rng_buffer_size(void)
84 84
85static void add_early_randomness(struct hwrng *rng) 85static void add_early_randomness(struct hwrng *rng)
86{ 86{
87 unsigned char bytes[16];
88 int bytes_read; 87 int bytes_read;
88 size_t size = min_t(size_t, 16, rng_buffer_size());
89 89
90 mutex_lock(&reading_mutex); 90 mutex_lock(&reading_mutex);
91 bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1); 91 bytes_read = rng_get_data(rng, rng_buffer, size, 1);
92 mutex_unlock(&reading_mutex); 92 mutex_unlock(&reading_mutex);
93 if (bytes_read > 0) 93 if (bytes_read > 0)
94 add_device_randomness(bytes, bytes_read); 94 add_device_randomness(rng_buffer, bytes_read);
95} 95}
96 96
97static inline void cleanup_rng(struct kref *kref) 97static inline void cleanup_rng(struct kref *kref)
diff --git a/drivers/clk/at91/clk-programmable.c b/drivers/clk/at91/clk-programmable.c
index 190122e64a3a..85a449cf61e3 100644
--- a/drivers/clk/at91/clk-programmable.c
+++ b/drivers/clk/at91/clk-programmable.c
@@ -203,7 +203,7 @@ at91_clk_register_programmable(struct regmap *regmap,
203 ret = clk_hw_register(NULL, &prog->hw); 203 ret = clk_hw_register(NULL, &prog->hw);
204 if (ret) { 204 if (ret) {
205 kfree(prog); 205 kfree(prog);
206 hw = &prog->hw; 206 hw = ERR_PTR(ret);
207 } 207 }
208 208
209 return hw; 209 return hw;
diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index b68bf573dcfb..8c7763fd9efc 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -502,8 +502,12 @@ static long bcm2835_pll_rate_from_divisors(unsigned long parent_rate,
502static long bcm2835_pll_round_rate(struct clk_hw *hw, unsigned long rate, 502static long bcm2835_pll_round_rate(struct clk_hw *hw, unsigned long rate,
503 unsigned long *parent_rate) 503 unsigned long *parent_rate)
504{ 504{
505 struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
506 const struct bcm2835_pll_data *data = pll->data;
505 u32 ndiv, fdiv; 507 u32 ndiv, fdiv;
506 508
509 rate = clamp(rate, data->min_rate, data->max_rate);
510
507 bcm2835_pll_choose_ndiv_and_fdiv(rate, *parent_rate, &ndiv, &fdiv); 511 bcm2835_pll_choose_ndiv_and_fdiv(rate, *parent_rate, &ndiv, &fdiv);
508 512
509 return bcm2835_pll_rate_from_divisors(*parent_rate, ndiv, fdiv, 1); 513 return bcm2835_pll_rate_from_divisors(*parent_rate, ndiv, fdiv, 1);
@@ -608,13 +612,6 @@ static int bcm2835_pll_set_rate(struct clk_hw *hw,
608 u32 ana[4]; 612 u32 ana[4];
609 int i; 613 int i;
610 614
611 if (rate < data->min_rate || rate > data->max_rate) {
612 dev_err(cprman->dev, "%s: rate out of spec: %lu vs (%lu, %lu)\n",
613 clk_hw_get_name(hw), rate,
614 data->min_rate, data->max_rate);
615 return -EINVAL;
616 }
617
618 if (rate > data->max_fb_rate) { 615 if (rate > data->max_fb_rate) {
619 use_fb_prediv = true; 616 use_fb_prediv = true;
620 rate /= 2; 617 rate /= 2;
diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c
index b637f5979023..eb953d3b0b69 100644
--- a/drivers/clk/clk-max77686.c
+++ b/drivers/clk/clk-max77686.c
@@ -216,6 +216,7 @@ static int max77686_clk_probe(struct platform_device *pdev)
216 return -EINVAL; 216 return -EINVAL;
217 } 217 }
218 218
219 drv_data->num_clks = num_clks;
219 drv_data->max_clk_data = devm_kcalloc(dev, num_clks, 220 drv_data->max_clk_data = devm_kcalloc(dev, num_clks,
220 sizeof(*drv_data->max_clk_data), 221 sizeof(*drv_data->max_clk_data),
221 GFP_KERNEL); 222 GFP_KERNEL);
diff --git a/drivers/clk/hisilicon/clk-hi6220.c b/drivers/clk/hisilicon/clk-hi6220.c
index fe364e63f8de..c0e8e1f196aa 100644
--- a/drivers/clk/hisilicon/clk-hi6220.c
+++ b/drivers/clk/hisilicon/clk-hi6220.c
@@ -195,7 +195,7 @@ static void __init hi6220_clk_sys_init(struct device_node *np)
195 hi6220_clk_register_divider(hi6220_div_clks_sys, 195 hi6220_clk_register_divider(hi6220_div_clks_sys,
196 ARRAY_SIZE(hi6220_div_clks_sys), clk_data); 196 ARRAY_SIZE(hi6220_div_clks_sys), clk_data);
197} 197}
198CLK_OF_DECLARE(hi6220_clk_sys, "hisilicon,hi6220-sysctrl", hi6220_clk_sys_init); 198CLK_OF_DECLARE_DRIVER(hi6220_clk_sys, "hisilicon,hi6220-sysctrl", hi6220_clk_sys_init);
199 199
200 200
201/* clocks in media controller */ 201/* clocks in media controller */
@@ -252,7 +252,7 @@ static void __init hi6220_clk_media_init(struct device_node *np)
252 hi6220_clk_register_divider(hi6220_div_clks_media, 252 hi6220_clk_register_divider(hi6220_div_clks_media,
253 ARRAY_SIZE(hi6220_div_clks_media), clk_data); 253 ARRAY_SIZE(hi6220_div_clks_media), clk_data);
254} 254}
255CLK_OF_DECLARE(hi6220_clk_media, "hisilicon,hi6220-mediactrl", hi6220_clk_media_init); 255CLK_OF_DECLARE_DRIVER(hi6220_clk_media, "hisilicon,hi6220-mediactrl", hi6220_clk_media_init);
256 256
257 257
258/* clocks in pmctrl */ 258/* clocks in pmctrl */
diff --git a/drivers/clk/mediatek/Kconfig b/drivers/clk/mediatek/Kconfig
index 380c372d528e..f042bd2a6a99 100644
--- a/drivers/clk/mediatek/Kconfig
+++ b/drivers/clk/mediatek/Kconfig
@@ -8,6 +8,7 @@ config COMMON_CLK_MEDIATEK
8 8
9config COMMON_CLK_MT8135 9config COMMON_CLK_MT8135
10 bool "Clock driver for Mediatek MT8135" 10 bool "Clock driver for Mediatek MT8135"
11 depends on ARCH_MEDIATEK || COMPILE_TEST
11 select COMMON_CLK_MEDIATEK 12 select COMMON_CLK_MEDIATEK
12 default ARCH_MEDIATEK 13 default ARCH_MEDIATEK
13 ---help--- 14 ---help---
@@ -15,6 +16,7 @@ config COMMON_CLK_MT8135
15 16
16config COMMON_CLK_MT8173 17config COMMON_CLK_MT8173
17 bool "Clock driver for Mediatek MT8173" 18 bool "Clock driver for Mediatek MT8173"
19 depends on ARCH_MEDIATEK || COMPILE_TEST
18 select COMMON_CLK_MEDIATEK 20 select COMMON_CLK_MEDIATEK
19 default ARCH_MEDIATEK 21 default ARCH_MEDIATEK
20 ---help--- 22 ---help---
diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c
index 45905fc0d75b..cecb0fdfaef6 100644
--- a/drivers/clk/mvebu/armada-37xx-periph.c
+++ b/drivers/clk/mvebu/armada-37xx-periph.c
@@ -305,7 +305,7 @@ static const struct of_device_id armada_3700_periph_clock_of_match[] = {
305}; 305};
306static int armada_3700_add_composite_clk(const struct clk_periph_data *data, 306static int armada_3700_add_composite_clk(const struct clk_periph_data *data,
307 void __iomem *reg, spinlock_t *lock, 307 void __iomem *reg, spinlock_t *lock,
308 struct device *dev, struct clk_hw *hw) 308 struct device *dev, struct clk_hw **hw)
309{ 309{
310 const struct clk_ops *mux_ops = NULL, *gate_ops = NULL, 310 const struct clk_ops *mux_ops = NULL, *gate_ops = NULL,
311 *rate_ops = NULL; 311 *rate_ops = NULL;
@@ -329,6 +329,7 @@ static int armada_3700_add_composite_clk(const struct clk_periph_data *data,
329 gate->lock = lock; 329 gate->lock = lock;
330 gate_ops = gate_hw->init->ops; 330 gate_ops = gate_hw->init->ops;
331 gate->reg = reg + (u64)gate->reg; 331 gate->reg = reg + (u64)gate->reg;
332 gate->flags = CLK_GATE_SET_TO_DISABLE;
332 } 333 }
333 334
334 if (data->rate_hw) { 335 if (data->rate_hw) {
@@ -353,13 +354,13 @@ static int armada_3700_add_composite_clk(const struct clk_periph_data *data,
353 } 354 }
354 } 355 }
355 356
356 hw = clk_hw_register_composite(dev, data->name, data->parent_names, 357 *hw = clk_hw_register_composite(dev, data->name, data->parent_names,
357 data->num_parents, mux_hw, 358 data->num_parents, mux_hw,
358 mux_ops, rate_hw, rate_ops, 359 mux_ops, rate_hw, rate_ops,
359 gate_hw, gate_ops, CLK_IGNORE_UNUSED); 360 gate_hw, gate_ops, CLK_IGNORE_UNUSED);
360 361
361 if (IS_ERR(hw)) 362 if (IS_ERR(*hw))
362 return PTR_ERR(hw); 363 return PTR_ERR(*hw);
363 364
364 return 0; 365 return 0;
365} 366}
@@ -400,7 +401,7 @@ static int armada_3700_periph_clock_probe(struct platform_device *pdev)
400 spin_lock_init(&driver_data->lock); 401 spin_lock_init(&driver_data->lock);
401 402
402 for (i = 0; i < num_periph; i++) { 403 for (i = 0; i < num_periph; i++) {
403 struct clk_hw *hw = driver_data->hw_data->hws[i]; 404 struct clk_hw **hw = &driver_data->hw_data->hws[i];
404 405
405 if (armada_3700_add_composite_clk(&data[i], reg, 406 if (armada_3700_add_composite_clk(&data[i], reg,
406 &driver_data->lock, dev, hw)) 407 &driver_data->lock, dev, hw))
diff --git a/drivers/clk/samsung/clk-exynos-audss.c b/drivers/clk/samsung/clk-exynos-audss.c
index 51d152f735cc..17e68a724945 100644
--- a/drivers/clk/samsung/clk-exynos-audss.c
+++ b/drivers/clk/samsung/clk-exynos-audss.c
@@ -106,6 +106,7 @@ static const struct of_device_id exynos_audss_clk_of_match[] = {
106 }, 106 },
107 { }, 107 { },
108}; 108};
109MODULE_DEVICE_TABLE(of, exynos_audss_clk_of_match);
109 110
110static void exynos_audss_clk_teardown(void) 111static void exynos_audss_clk_teardown(void)
111{ 112{
diff --git a/drivers/clk/uniphier/clk-uniphier-core.c b/drivers/clk/uniphier/clk-uniphier-core.c
index 5ffb898d0839..26c53f7963a4 100644
--- a/drivers/clk/uniphier/clk-uniphier-core.c
+++ b/drivers/clk/uniphier/clk-uniphier-core.c
@@ -79,7 +79,7 @@ static int uniphier_clk_probe(struct platform_device *pdev)
79 hw_data->num = clk_num; 79 hw_data->num = clk_num;
80 80
81 /* avoid returning NULL for unused idx */ 81 /* avoid returning NULL for unused idx */
82 for (; clk_num >= 0; clk_num--) 82 while (--clk_num >= 0)
83 hw_data->hws[clk_num] = ERR_PTR(-EINVAL); 83 hw_data->hws[clk_num] = ERR_PTR(-EINVAL);
84 84
85 for (p = data; p->name; p++) { 85 for (p = data; p->name; p++) {
@@ -111,6 +111,10 @@ static int uniphier_clk_remove(struct platform_device *pdev)
111static const struct of_device_id uniphier_clk_match[] = { 111static const struct of_device_id uniphier_clk_match[] = {
112 /* System clock */ 112 /* System clock */
113 { 113 {
114 .compatible = "socionext,uniphier-sld3-clock",
115 .data = uniphier_sld3_sys_clk_data,
116 },
117 {
114 .compatible = "socionext,uniphier-ld4-clock", 118 .compatible = "socionext,uniphier-ld4-clock",
115 .data = uniphier_ld4_sys_clk_data, 119 .data = uniphier_ld4_sys_clk_data,
116 }, 120 },
@@ -138,7 +142,7 @@ static const struct of_device_id uniphier_clk_match[] = {
138 .compatible = "socionext,uniphier-ld20-clock", 142 .compatible = "socionext,uniphier-ld20-clock",
139 .data = uniphier_ld20_sys_clk_data, 143 .data = uniphier_ld20_sys_clk_data,
140 }, 144 },
141 /* Media I/O clock */ 145 /* Media I/O clock, SD clock */
142 { 146 {
143 .compatible = "socionext,uniphier-sld3-mio-clock", 147 .compatible = "socionext,uniphier-sld3-mio-clock",
144 .data = uniphier_sld3_mio_clk_data, 148 .data = uniphier_sld3_mio_clk_data,
@@ -156,20 +160,20 @@ static const struct of_device_id uniphier_clk_match[] = {
156 .data = uniphier_sld3_mio_clk_data, 160 .data = uniphier_sld3_mio_clk_data,
157 }, 161 },
158 { 162 {
159 .compatible = "socionext,uniphier-pro5-mio-clock", 163 .compatible = "socionext,uniphier-pro5-sd-clock",
160 .data = uniphier_pro5_mio_clk_data, 164 .data = uniphier_pro5_sd_clk_data,
161 }, 165 },
162 { 166 {
163 .compatible = "socionext,uniphier-pxs2-mio-clock", 167 .compatible = "socionext,uniphier-pxs2-sd-clock",
164 .data = uniphier_pro5_mio_clk_data, 168 .data = uniphier_pro5_sd_clk_data,
165 }, 169 },
166 { 170 {
167 .compatible = "socionext,uniphier-ld11-mio-clock", 171 .compatible = "socionext,uniphier-ld11-mio-clock",
168 .data = uniphier_sld3_mio_clk_data, 172 .data = uniphier_sld3_mio_clk_data,
169 }, 173 },
170 { 174 {
171 .compatible = "socionext,uniphier-ld20-mio-clock", 175 .compatible = "socionext,uniphier-ld20-sd-clock",
172 .data = uniphier_pro5_mio_clk_data, 176 .data = uniphier_pro5_sd_clk_data,
173 }, 177 },
174 /* Peripheral clock */ 178 /* Peripheral clock */
175 { 179 {
diff --git a/drivers/clk/uniphier/clk-uniphier-mio.c b/drivers/clk/uniphier/clk-uniphier-mio.c
index 6aa7ec768d0b..218d20f099ce 100644
--- a/drivers/clk/uniphier/clk-uniphier-mio.c
+++ b/drivers/clk/uniphier/clk-uniphier-mio.c
@@ -93,7 +93,7 @@ const struct uniphier_clk_data uniphier_sld3_mio_clk_data[] = {
93 { /* sentinel */ } 93 { /* sentinel */ }
94}; 94};
95 95
96const struct uniphier_clk_data uniphier_pro5_mio_clk_data[] = { 96const struct uniphier_clk_data uniphier_pro5_sd_clk_data[] = {
97 UNIPHIER_MIO_CLK_SD_FIXED, 97 UNIPHIER_MIO_CLK_SD_FIXED,
98 UNIPHIER_MIO_CLK_SD(0, 0), 98 UNIPHIER_MIO_CLK_SD(0, 0),
99 UNIPHIER_MIO_CLK_SD(1, 1), 99 UNIPHIER_MIO_CLK_SD(1, 1),
diff --git a/drivers/clk/uniphier/clk-uniphier-mux.c b/drivers/clk/uniphier/clk-uniphier-mux.c
index 15a2f2cbe0d9..2c243a894f3b 100644
--- a/drivers/clk/uniphier/clk-uniphier-mux.c
+++ b/drivers/clk/uniphier/clk-uniphier-mux.c
@@ -42,7 +42,7 @@ static u8 uniphier_clk_mux_get_parent(struct clk_hw *hw)
42 struct uniphier_clk_mux *mux = to_uniphier_clk_mux(hw); 42 struct uniphier_clk_mux *mux = to_uniphier_clk_mux(hw);
43 int num_parents = clk_hw_get_num_parents(hw); 43 int num_parents = clk_hw_get_num_parents(hw);
44 int ret; 44 int ret;
45 u32 val; 45 unsigned int val;
46 u8 i; 46 u8 i;
47 47
48 ret = regmap_read(mux->regmap, mux->reg, &val); 48 ret = regmap_read(mux->regmap, mux->reg, &val);
diff --git a/drivers/clk/uniphier/clk-uniphier.h b/drivers/clk/uniphier/clk-uniphier.h
index 3ae184062388..0244dba1f4cf 100644
--- a/drivers/clk/uniphier/clk-uniphier.h
+++ b/drivers/clk/uniphier/clk-uniphier.h
@@ -115,7 +115,7 @@ extern const struct uniphier_clk_data uniphier_pxs2_sys_clk_data[];
115extern const struct uniphier_clk_data uniphier_ld11_sys_clk_data[]; 115extern const struct uniphier_clk_data uniphier_ld11_sys_clk_data[];
116extern const struct uniphier_clk_data uniphier_ld20_sys_clk_data[]; 116extern const struct uniphier_clk_data uniphier_ld20_sys_clk_data[];
117extern const struct uniphier_clk_data uniphier_sld3_mio_clk_data[]; 117extern const struct uniphier_clk_data uniphier_sld3_mio_clk_data[];
118extern const struct uniphier_clk_data uniphier_pro5_mio_clk_data[]; 118extern const struct uniphier_clk_data uniphier_pro5_sd_clk_data[];
119extern const struct uniphier_clk_data uniphier_ld4_peri_clk_data[]; 119extern const struct uniphier_clk_data uniphier_ld4_peri_clk_data[];
120extern const struct uniphier_clk_data uniphier_pro4_peri_clk_data[]; 120extern const struct uniphier_clk_data uniphier_pro4_peri_clk_data[];
121 121
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index f535f8123258..4737520ec823 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -179,6 +179,7 @@ struct _pid {
179/** 179/**
180 * struct cpudata - Per CPU instance data storage 180 * struct cpudata - Per CPU instance data storage
181 * @cpu: CPU number for this instance data 181 * @cpu: CPU number for this instance data
182 * @policy: CPUFreq policy value
182 * @update_util: CPUFreq utility callback information 183 * @update_util: CPUFreq utility callback information
183 * @update_util_set: CPUFreq utility callback is set 184 * @update_util_set: CPUFreq utility callback is set
184 * @iowait_boost: iowait-related boost fraction 185 * @iowait_boost: iowait-related boost fraction
@@ -201,6 +202,7 @@ struct _pid {
201struct cpudata { 202struct cpudata {
202 int cpu; 203 int cpu;
203 204
205 unsigned int policy;
204 struct update_util_data update_util; 206 struct update_util_data update_util;
205 bool update_util_set; 207 bool update_util_set;
206 208
@@ -1142,10 +1144,8 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
1142 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf); 1144 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf);
1143} 1145}
1144 1146
1145static void intel_pstate_set_min_pstate(struct cpudata *cpu) 1147static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
1146{ 1148{
1147 int pstate = cpu->pstate.min_pstate;
1148
1149 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); 1149 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu);
1150 cpu->pstate.current_pstate = pstate; 1150 cpu->pstate.current_pstate = pstate;
1151 /* 1151 /*
@@ -1157,6 +1157,20 @@ static void intel_pstate_set_min_pstate(struct cpudata *cpu)
1157 pstate_funcs.get_val(cpu, pstate)); 1157 pstate_funcs.get_val(cpu, pstate));
1158} 1158}
1159 1159
1160static void intel_pstate_set_min_pstate(struct cpudata *cpu)
1161{
1162 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
1163}
1164
1165static void intel_pstate_max_within_limits(struct cpudata *cpu)
1166{
1167 int min_pstate, max_pstate;
1168
1169 update_turbo_state();
1170 intel_pstate_get_min_max(cpu, &min_pstate, &max_pstate);
1171 intel_pstate_set_pstate(cpu, max_pstate);
1172}
1173
1160static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) 1174static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
1161{ 1175{
1162 cpu->pstate.min_pstate = pstate_funcs.get_min(); 1176 cpu->pstate.min_pstate = pstate_funcs.get_min();
@@ -1325,7 +1339,8 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
1325 1339
1326 from = cpu->pstate.current_pstate; 1340 from = cpu->pstate.current_pstate;
1327 1341
1328 target_pstate = pstate_funcs.get_target_pstate(cpu); 1342 target_pstate = cpu->policy == CPUFREQ_POLICY_PERFORMANCE ?
1343 cpu->pstate.turbo_pstate : pstate_funcs.get_target_pstate(cpu);
1329 1344
1330 intel_pstate_update_pstate(cpu, target_pstate); 1345 intel_pstate_update_pstate(cpu, target_pstate);
1331 1346
@@ -1491,7 +1506,9 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
1491 pr_debug("set_policy cpuinfo.max %u policy->max %u\n", 1506 pr_debug("set_policy cpuinfo.max %u policy->max %u\n",
1492 policy->cpuinfo.max_freq, policy->max); 1507 policy->cpuinfo.max_freq, policy->max);
1493 1508
1494 cpu = all_cpu_data[0]; 1509 cpu = all_cpu_data[policy->cpu];
1510 cpu->policy = policy->policy;
1511
1495 if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate && 1512 if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate &&
1496 policy->max < policy->cpuinfo.max_freq && 1513 policy->max < policy->cpuinfo.max_freq &&
1497 policy->max > cpu->pstate.max_pstate * cpu->pstate.scaling) { 1514 policy->max > cpu->pstate.max_pstate * cpu->pstate.scaling) {
@@ -1499,7 +1516,7 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
1499 policy->max = policy->cpuinfo.max_freq; 1516 policy->max = policy->cpuinfo.max_freq;
1500 } 1517 }
1501 1518
1502 if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) { 1519 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) {
1503 limits = &performance_limits; 1520 limits = &performance_limits;
1504 if (policy->max >= policy->cpuinfo.max_freq) { 1521 if (policy->max >= policy->cpuinfo.max_freq) {
1505 pr_debug("set performance\n"); 1522 pr_debug("set performance\n");
@@ -1535,6 +1552,15 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
1535 limits->max_perf = round_up(limits->max_perf, FRAC_BITS); 1552 limits->max_perf = round_up(limits->max_perf, FRAC_BITS);
1536 1553
1537 out: 1554 out:
1555 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) {
1556 /*
1557 * NOHZ_FULL CPUs need this as the governor callback may not
1558 * be invoked on them.
1559 */
1560 intel_pstate_clear_update_util_hook(policy->cpu);
1561 intel_pstate_max_within_limits(cpu);
1562 }
1563
1538 intel_pstate_set_update_util_hook(policy->cpu); 1564 intel_pstate_set_update_util_hook(policy->cpu);
1539 1565
1540 intel_pstate_hwp_set_policy(policy); 1566 intel_pstate_hwp_set_policy(policy);
diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
index daadd20aa936..3e2ab3b14eea 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -14,7 +14,7 @@ if DEV_DAX
14 14
15config DEV_DAX_PMEM 15config DEV_DAX_PMEM
16 tristate "PMEM DAX: direct access to persistent memory" 16 tristate "PMEM DAX: direct access to persistent memory"
17 depends on NVDIMM_DAX 17 depends on LIBNVDIMM && NVDIMM_DAX
18 default DEV_DAX 18 default DEV_DAX
19 help 19 help
20 Support raw access to persistent memory. Note that this 20 Support raw access to persistent memory. Note that this
diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index 9630d8837ba9..4a15fa5df98b 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -44,7 +44,6 @@ static void dax_pmem_percpu_exit(void *data)
44 44
45 dev_dbg(dax_pmem->dev, "%s\n", __func__); 45 dev_dbg(dax_pmem->dev, "%s\n", __func__);
46 percpu_ref_exit(ref); 46 percpu_ref_exit(ref);
47 wait_for_completion(&dax_pmem->cmp);
48} 47}
49 48
50static void dax_pmem_percpu_kill(void *data) 49static void dax_pmem_percpu_kill(void *data)
@@ -54,6 +53,7 @@ static void dax_pmem_percpu_kill(void *data)
54 53
55 dev_dbg(dax_pmem->dev, "%s\n", __func__); 54 dev_dbg(dax_pmem->dev, "%s\n", __func__);
56 percpu_ref_kill(ref); 55 percpu_ref_kill(ref);
56 wait_for_completion(&dax_pmem->cmp);
57} 57}
58 58
59static int dax_pmem_probe(struct device *dev) 59static int dax_pmem_probe(struct device *dev)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 26ee00f6bd58..d011cb89d25e 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -284,7 +284,7 @@ config GPIO_MM_LANTIQ
284 284
285config GPIO_MOCKUP 285config GPIO_MOCKUP
286 tristate "GPIO Testing Driver" 286 tristate "GPIO Testing Driver"
287 depends on GPIOLIB 287 depends on GPIOLIB && SYSFS
288 select GPIO_SYSFS 288 select GPIO_SYSFS
289 help 289 help
290 This enables GPIO Testing driver, which provides a way to test GPIO 290 This enables GPIO Testing driver, which provides a way to test GPIO
diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
index 9457e2022bf6..dc37dbe4b46d 100644
--- a/drivers/gpio/gpio-ath79.c
+++ b/drivers/gpio/gpio-ath79.c
@@ -219,6 +219,7 @@ static const struct of_device_id ath79_gpio_of_match[] = {
219 { .compatible = "qca,ar9340-gpio" }, 219 { .compatible = "qca,ar9340-gpio" },
220 {}, 220 {},
221}; 221};
222MODULE_DEVICE_TABLE(of, ath79_gpio_of_match);
222 223
223static int ath79_gpio_probe(struct platform_device *pdev) 224static int ath79_gpio_probe(struct platform_device *pdev)
224{ 225{
diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 425501c39527..793518a30afe 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -239,7 +239,7 @@ static int mpc8xxx_gpio_irq_map(struct irq_domain *h, unsigned int irq,
239 irq_hw_number_t hwirq) 239 irq_hw_number_t hwirq)
240{ 240{
241 irq_set_chip_data(irq, h->host_data); 241 irq_set_chip_data(irq, h->host_data);
242 irq_set_chip_and_handler(irq, &mpc8xxx_irq_chip, handle_level_irq); 242 irq_set_chip_and_handler(irq, &mpc8xxx_irq_chip, handle_edge_irq);
243 243
244 return 0; 244 return 0;
245} 245}
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index b9daa0bf32a4..ee1724806f46 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -308,8 +308,10 @@ static int mxs_gpio_probe(struct platform_device *pdev)
308 writel(~0U, port->base + PINCTRL_IRQSTAT(port) + MXS_CLR); 308 writel(~0U, port->base + PINCTRL_IRQSTAT(port) + MXS_CLR);
309 309
310 irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id()); 310 irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id());
311 if (irq_base < 0) 311 if (irq_base < 0) {
312 return irq_base; 312 err = irq_base;
313 goto out_iounmap;
314 }
313 315
314 port->domain = irq_domain_add_legacy(np, 32, irq_base, 0, 316 port->domain = irq_domain_add_legacy(np, 32, irq_base, 0,
315 &irq_domain_simple_ops, NULL); 317 &irq_domain_simple_ops, NULL);
@@ -349,6 +351,8 @@ out_irqdomain_remove:
349 irq_domain_remove(port->domain); 351 irq_domain_remove(port->domain);
350out_irqdesc_free: 352out_irqdesc_free:
351 irq_free_descs(irq_base, 32); 353 irq_free_descs(irq_base, 32);
354out_iounmap:
355 iounmap(port->base);
352 return err; 356 return err;
353} 357}
354 358
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index e7d422a6b90b..5b0042776ec7 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -409,7 +409,7 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
409 * 801/1801/1600, bits are cleared when read. 409 * 801/1801/1600, bits are cleared when read.
410 * Edge detect register is not present on 801/1600/1801 410 * Edge detect register is not present on 801/1600/1801
411 */ 411 */
412 if (stmpe->partnum != STMPE801 || stmpe->partnum != STMPE1600 || 412 if (stmpe->partnum != STMPE801 && stmpe->partnum != STMPE1600 &&
413 stmpe->partnum != STMPE1801) { 413 stmpe->partnum != STMPE1801) {
414 stmpe_reg_write(stmpe, statmsbreg + i, status[i]); 414 stmpe_reg_write(stmpe, statmsbreg + i, status[i]);
415 stmpe_reg_write(stmpe, 415 stmpe_reg_write(stmpe,
diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c
index 99256115bea5..c2a80b4cbf32 100644
--- a/drivers/gpio/gpio-ts4800.c
+++ b/drivers/gpio/gpio-ts4800.c
@@ -66,6 +66,7 @@ static const struct of_device_id ts4800_gpio_of_match[] = {
66 { .compatible = "technologic,ts4800-gpio", }, 66 { .compatible = "technologic,ts4800-gpio", },
67 {}, 67 {},
68}; 68};
69MODULE_DEVICE_TABLE(of, ts4800_gpio_of_match);
69 70
70static struct platform_driver ts4800_gpio_driver = { 71static struct platform_driver ts4800_gpio_driver = {
71 .driver = { 72 .driver = {
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 58ece201b8e6..72a4b326fd0d 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -653,14 +653,17 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
653{ 653{
654 int idx, i; 654 int idx, i;
655 unsigned int irq_flags; 655 unsigned int irq_flags;
656 int ret = -ENOENT;
656 657
657 for (i = 0, idx = 0; idx <= index; i++) { 658 for (i = 0, idx = 0; idx <= index; i++) {
658 struct acpi_gpio_info info; 659 struct acpi_gpio_info info;
659 struct gpio_desc *desc; 660 struct gpio_desc *desc;
660 661
661 desc = acpi_get_gpiod_by_index(adev, NULL, i, &info); 662 desc = acpi_get_gpiod_by_index(adev, NULL, i, &info);
662 if (IS_ERR(desc)) 663 if (IS_ERR(desc)) {
664 ret = PTR_ERR(desc);
663 break; 665 break;
666 }
664 if (info.gpioint && idx++ == index) { 667 if (info.gpioint && idx++ == index) {
665 int irq = gpiod_to_irq(desc); 668 int irq = gpiod_to_irq(desc);
666 669
@@ -679,7 +682,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
679 } 682 }
680 683
681 } 684 }
682 return -ENOENT; 685 return ret;
683} 686}
684EXPORT_SYMBOL_GPL(acpi_dev_gpio_irq_get); 687EXPORT_SYMBOL_GPL(acpi_dev_gpio_irq_get);
685 688
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f0fc3a0d37c8..20e09b7c2de3 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -333,6 +333,13 @@ struct linehandle_state {
333 u32 numdescs; 333 u32 numdescs;
334}; 334};
335 335
336#define GPIOHANDLE_REQUEST_VALID_FLAGS \
337 (GPIOHANDLE_REQUEST_INPUT | \
338 GPIOHANDLE_REQUEST_OUTPUT | \
339 GPIOHANDLE_REQUEST_ACTIVE_LOW | \
340 GPIOHANDLE_REQUEST_OPEN_DRAIN | \
341 GPIOHANDLE_REQUEST_OPEN_SOURCE)
342
336static long linehandle_ioctl(struct file *filep, unsigned int cmd, 343static long linehandle_ioctl(struct file *filep, unsigned int cmd,
337 unsigned long arg) 344 unsigned long arg)
338{ 345{
@@ -344,6 +351,8 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd,
344 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) { 351 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) {
345 int val; 352 int val;
346 353
354 memset(&ghd, 0, sizeof(ghd));
355
347 /* TODO: check if descriptors are really input */ 356 /* TODO: check if descriptors are really input */
348 for (i = 0; i < lh->numdescs; i++) { 357 for (i = 0; i < lh->numdescs; i++) {
349 val = gpiod_get_value_cansleep(lh->descs[i]); 358 val = gpiod_get_value_cansleep(lh->descs[i]);
@@ -444,6 +453,17 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
444 u32 lflags = handlereq.flags; 453 u32 lflags = handlereq.flags;
445 struct gpio_desc *desc; 454 struct gpio_desc *desc;
446 455
456 if (offset >= gdev->ngpio) {
457 ret = -EINVAL;
458 goto out_free_descs;
459 }
460
461 /* Return an error if a unknown flag is set */
462 if (lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) {
463 ret = -EINVAL;
464 goto out_free_descs;
465 }
466
447 desc = &gdev->descs[offset]; 467 desc = &gdev->descs[offset];
448 ret = gpiod_request(desc, lh->label); 468 ret = gpiod_request(desc, lh->label);
449 if (ret) 469 if (ret)
@@ -536,6 +556,10 @@ struct lineevent_state {
536 struct mutex read_lock; 556 struct mutex read_lock;
537}; 557};
538 558
559#define GPIOEVENT_REQUEST_VALID_FLAGS \
560 (GPIOEVENT_REQUEST_RISING_EDGE | \
561 GPIOEVENT_REQUEST_FALLING_EDGE)
562
539static unsigned int lineevent_poll(struct file *filep, 563static unsigned int lineevent_poll(struct file *filep,
540 struct poll_table_struct *wait) 564 struct poll_table_struct *wait)
541{ 565{
@@ -623,6 +647,8 @@ static long lineevent_ioctl(struct file *filep, unsigned int cmd,
623 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) { 647 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) {
624 int val; 648 int val;
625 649
650 memset(&ghd, 0, sizeof(ghd));
651
626 val = gpiod_get_value_cansleep(le->desc); 652 val = gpiod_get_value_cansleep(le->desc);
627 if (val < 0) 653 if (val < 0)
628 return val; 654 return val;
@@ -726,6 +752,18 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
726 lflags = eventreq.handleflags; 752 lflags = eventreq.handleflags;
727 eflags = eventreq.eventflags; 753 eflags = eventreq.eventflags;
728 754
755 if (offset >= gdev->ngpio) {
756 ret = -EINVAL;
757 goto out_free_label;
758 }
759
760 /* Return an error if a unknown flag is set */
761 if ((lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) ||
762 (eflags & ~GPIOEVENT_REQUEST_VALID_FLAGS)) {
763 ret = -EINVAL;
764 goto out_free_label;
765 }
766
729 /* This is just wrong: we don't look for events on output lines */ 767 /* This is just wrong: we don't look for events on output lines */
730 if (lflags & GPIOHANDLE_REQUEST_OUTPUT) { 768 if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
731 ret = -EINVAL; 769 ret = -EINVAL;
@@ -823,6 +861,8 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
823 if (cmd == GPIO_GET_CHIPINFO_IOCTL) { 861 if (cmd == GPIO_GET_CHIPINFO_IOCTL) {
824 struct gpiochip_info chipinfo; 862 struct gpiochip_info chipinfo;
825 863
864 memset(&chipinfo, 0, sizeof(chipinfo));
865
826 strncpy(chipinfo.name, dev_name(&gdev->dev), 866 strncpy(chipinfo.name, dev_name(&gdev->dev),
827 sizeof(chipinfo.name)); 867 sizeof(chipinfo.name));
828 chipinfo.name[sizeof(chipinfo.name)-1] = '\0'; 868 chipinfo.name[sizeof(chipinfo.name)-1] = '\0';
@@ -839,7 +879,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
839 879
840 if (copy_from_user(&lineinfo, ip, sizeof(lineinfo))) 880 if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
841 return -EFAULT; 881 return -EFAULT;
842 if (lineinfo.line_offset > gdev->ngpio) 882 if (lineinfo.line_offset >= gdev->ngpio)
843 return -EINVAL; 883 return -EINVAL;
844 884
845 desc = &gdev->descs[lineinfo.line_offset]; 885 desc = &gdev->descs[lineinfo.line_offset];
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index aa074fac0c7f..f3efb1c5dae9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -754,6 +754,10 @@ static const char *amdgpu_vram_names[] = {
754 754
755int amdgpu_bo_init(struct amdgpu_device *adev) 755int amdgpu_bo_init(struct amdgpu_device *adev)
756{ 756{
757 /* reserve PAT memory space to WC for VRAM */
758 arch_io_reserve_memtype_wc(adev->mc.aper_base,
759 adev->mc.aper_size);
760
757 /* Add an MTRR for the VRAM */ 761 /* Add an MTRR for the VRAM */
758 adev->mc.vram_mtrr = arch_phys_wc_add(adev->mc.aper_base, 762 adev->mc.vram_mtrr = arch_phys_wc_add(adev->mc.aper_base,
759 adev->mc.aper_size); 763 adev->mc.aper_size);
@@ -769,6 +773,7 @@ void amdgpu_bo_fini(struct amdgpu_device *adev)
769{ 773{
770 amdgpu_ttm_fini(adev); 774 amdgpu_ttm_fini(adev);
771 arch_phys_wc_del(adev->mc.vram_mtrr); 775 arch_phys_wc_del(adev->mc.vram_mtrr);
776 arch_io_free_memtype_wc(adev->mc.aper_base, adev->mc.aper_size);
772} 777}
773 778
774int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, 779int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c
index 608df4c90520..0743e65cb240 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -267,6 +267,8 @@ int ast_mm_init(struct ast_private *ast)
267 return ret; 267 return ret;
268 } 268 }
269 269
270 arch_io_reserve_memtype_wc(pci_resource_start(dev->pdev, 0),
271 pci_resource_len(dev->pdev, 0));
270 ast->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0), 272 ast->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0),
271 pci_resource_len(dev->pdev, 0)); 273 pci_resource_len(dev->pdev, 0));
272 274
@@ -275,11 +277,15 @@ int ast_mm_init(struct ast_private *ast)
275 277
276void ast_mm_fini(struct ast_private *ast) 278void ast_mm_fini(struct ast_private *ast)
277{ 279{
280 struct drm_device *dev = ast->dev;
281
278 ttm_bo_device_release(&ast->ttm.bdev); 282 ttm_bo_device_release(&ast->ttm.bdev);
279 283
280 ast_ttm_global_release(ast); 284 ast_ttm_global_release(ast);
281 285
282 arch_phys_wc_del(ast->fb_mtrr); 286 arch_phys_wc_del(ast->fb_mtrr);
287 arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
288 pci_resource_len(dev->pdev, 0));
283} 289}
284 290
285void ast_ttm_placement(struct ast_bo *bo, int domain) 291void ast_ttm_placement(struct ast_bo *bo, int domain)
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index bb2438dd8733..5e7e63ce7bce 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -267,6 +267,9 @@ int cirrus_mm_init(struct cirrus_device *cirrus)
267 return ret; 267 return ret;
268 } 268 }
269 269
270 arch_io_reserve_memtype_wc(pci_resource_start(dev->pdev, 0),
271 pci_resource_len(dev->pdev, 0));
272
270 cirrus->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0), 273 cirrus->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0),
271 pci_resource_len(dev->pdev, 0)); 274 pci_resource_len(dev->pdev, 0));
272 275
@@ -276,6 +279,8 @@ int cirrus_mm_init(struct cirrus_device *cirrus)
276 279
277void cirrus_mm_fini(struct cirrus_device *cirrus) 280void cirrus_mm_fini(struct cirrus_device *cirrus)
278{ 281{
282 struct drm_device *dev = cirrus->dev;
283
279 if (!cirrus->mm_inited) 284 if (!cirrus->mm_inited)
280 return; 285 return;
281 286
@@ -285,6 +290,8 @@ void cirrus_mm_fini(struct cirrus_device *cirrus)
285 290
286 arch_phys_wc_del(cirrus->fb_mtrr); 291 arch_phys_wc_del(cirrus->fb_mtrr);
287 cirrus->fb_mtrr = 0; 292 cirrus->fb_mtrr = 0;
293 arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
294 pci_resource_len(dev->pdev, 0));
288} 295}
289 296
290void cirrus_ttm_placement(struct cirrus_bo *bo, int domain) 297void cirrus_ttm_placement(struct cirrus_bo *bo, int domain)
diff --git a/drivers/gpu/drm/mgag200/mgag200_ttm.c b/drivers/gpu/drm/mgag200/mgag200_ttm.c
index 919b35f2ad24..dcf7d11ac380 100644
--- a/drivers/gpu/drm/mgag200/mgag200_ttm.c
+++ b/drivers/gpu/drm/mgag200/mgag200_ttm.c
@@ -266,6 +266,9 @@ int mgag200_mm_init(struct mga_device *mdev)
266 return ret; 266 return ret;
267 } 267 }
268 268
269 arch_io_reserve_memtype_wc(pci_resource_start(dev->pdev, 0),
270 pci_resource_len(dev->pdev, 0));
271
269 mdev->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0), 272 mdev->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0),
270 pci_resource_len(dev->pdev, 0)); 273 pci_resource_len(dev->pdev, 0));
271 274
@@ -274,10 +277,14 @@ int mgag200_mm_init(struct mga_device *mdev)
274 277
275void mgag200_mm_fini(struct mga_device *mdev) 278void mgag200_mm_fini(struct mga_device *mdev)
276{ 279{
280 struct drm_device *dev = mdev->dev;
281
277 ttm_bo_device_release(&mdev->ttm.bdev); 282 ttm_bo_device_release(&mdev->ttm.bdev);
278 283
279 mgag200_ttm_global_release(mdev); 284 mgag200_ttm_global_release(mdev);
280 285
286 arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
287 pci_resource_len(dev->pdev, 0));
281 arch_phys_wc_del(mdev->fb_mtrr); 288 arch_phys_wc_del(mdev->fb_mtrr);
282 mdev->fb_mtrr = 0; 289 mdev->fb_mtrr = 0;
283} 290}
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 1825dbc33192..a6dbe8258040 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -398,6 +398,9 @@ nouveau_ttm_init(struct nouveau_drm *drm)
398 /* VRAM init */ 398 /* VRAM init */
399 drm->gem.vram_available = drm->device.info.ram_user; 399 drm->gem.vram_available = drm->device.info.ram_user;
400 400
401 arch_io_reserve_memtype_wc(device->func->resource_addr(device, 1),
402 device->func->resource_size(device, 1));
403
401 ret = ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_VRAM, 404 ret = ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_VRAM,
402 drm->gem.vram_available >> PAGE_SHIFT); 405 drm->gem.vram_available >> PAGE_SHIFT);
403 if (ret) { 406 if (ret) {
@@ -430,6 +433,8 @@ nouveau_ttm_init(struct nouveau_drm *drm)
430void 433void
431nouveau_ttm_fini(struct nouveau_drm *drm) 434nouveau_ttm_fini(struct nouveau_drm *drm)
432{ 435{
436 struct nvkm_device *device = nvxx_device(&drm->device);
437
433 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_VRAM); 438 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_VRAM);
434 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_TT); 439 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_TT);
435 440
@@ -439,4 +444,7 @@ nouveau_ttm_fini(struct nouveau_drm *drm)
439 444
440 arch_phys_wc_del(drm->ttm.mtrr); 445 arch_phys_wc_del(drm->ttm.mtrr);
441 drm->ttm.mtrr = 0; 446 drm->ttm.mtrr = 0;
447 arch_io_free_memtype_wc(device->func->resource_addr(device, 1),
448 device->func->resource_size(device, 1));
449
442} 450}
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index be30861afae9..41b72ce6613f 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -446,6 +446,10 @@ void radeon_bo_force_delete(struct radeon_device *rdev)
446 446
447int radeon_bo_init(struct radeon_device *rdev) 447int radeon_bo_init(struct radeon_device *rdev)
448{ 448{
449 /* reserve PAT memory space to WC for VRAM */
450 arch_io_reserve_memtype_wc(rdev->mc.aper_base,
451 rdev->mc.aper_size);
452
449 /* Add an MTRR for the VRAM */ 453 /* Add an MTRR for the VRAM */
450 if (!rdev->fastfb_working) { 454 if (!rdev->fastfb_working) {
451 rdev->mc.vram_mtrr = arch_phys_wc_add(rdev->mc.aper_base, 455 rdev->mc.vram_mtrr = arch_phys_wc_add(rdev->mc.aper_base,
@@ -463,6 +467,7 @@ void radeon_bo_fini(struct radeon_device *rdev)
463{ 467{
464 radeon_ttm_fini(rdev); 468 radeon_ttm_fini(rdev);
465 arch_phys_wc_del(rdev->mc.vram_mtrr); 469 arch_phys_wc_del(rdev->mc.vram_mtrr);
470 arch_io_free_memtype_wc(rdev->mc.aper_base, rdev->mc.aper_size);
466} 471}
467 472
468/* Returns how many bytes TTM can move per IB. 473/* Returns how many bytes TTM can move per IB.
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 6d94e2ec5b4f..d252276feadf 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -79,12 +79,12 @@ config I2C_AMD8111
79 79
80config I2C_HIX5HD2 80config I2C_HIX5HD2
81 tristate "Hix5hd2 high-speed I2C driver" 81 tristate "Hix5hd2 high-speed I2C driver"
82 depends on ARCH_HIX5HD2 || COMPILE_TEST 82 depends on ARCH_HISI || ARCH_HIX5HD2 || COMPILE_TEST
83 help 83 help
84 Say Y here to include support for high-speed I2C controller in the 84 Say Y here to include support for the high-speed I2C controller
85 Hisilicon based hix5hd2 SoCs. 85 used in HiSilicon hix5hd2 SoCs.
86 86
87 This driver can also be built as a module. If so, the module 87 This driver can also be built as a module. If so, the module
88 will be called i2c-hix5hd2. 88 will be called i2c-hix5hd2.
89 89
90config I2C_I801 90config I2C_I801
@@ -589,10 +589,10 @@ config I2C_IMG
589 589
590config I2C_IMX 590config I2C_IMX
591 tristate "IMX I2C interface" 591 tristate "IMX I2C interface"
592 depends on ARCH_MXC || ARCH_LAYERSCAPE 592 depends on ARCH_MXC || ARCH_LAYERSCAPE || COLDFIRE
593 help 593 help
594 Say Y here if you want to use the IIC bus controller on 594 Say Y here if you want to use the IIC bus controller on
595 the Freescale i.MX/MXC or Layerscape processors. 595 the Freescale i.MX/MXC, Layerscape or ColdFire processors.
596 596
597 This driver can also be built as a module. If so, the module 597 This driver can also be built as a module. If so, the module
598 will be called i2c-imx. 598 will be called i2c-imx.
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 1fe93c43215c..11e866d05368 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -95,6 +95,9 @@
95#define DW_IC_STATUS_TFE BIT(2) 95#define DW_IC_STATUS_TFE BIT(2)
96#define DW_IC_STATUS_MST_ACTIVITY BIT(5) 96#define DW_IC_STATUS_MST_ACTIVITY BIT(5)
97 97
98#define DW_IC_SDA_HOLD_RX_SHIFT 16
99#define DW_IC_SDA_HOLD_RX_MASK GENMASK(23, DW_IC_SDA_HOLD_RX_SHIFT)
100
98#define DW_IC_ERR_TX_ABRT 0x1 101#define DW_IC_ERR_TX_ABRT 0x1
99 102
100#define DW_IC_TAR_10BITADDR_MASTER BIT(12) 103#define DW_IC_TAR_10BITADDR_MASTER BIT(12)
@@ -420,12 +423,20 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
420 /* Configure SDA Hold Time if required */ 423 /* Configure SDA Hold Time if required */
421 reg = dw_readl(dev, DW_IC_COMP_VERSION); 424 reg = dw_readl(dev, DW_IC_COMP_VERSION);
422 if (reg >= DW_IC_SDA_HOLD_MIN_VERS) { 425 if (reg >= DW_IC_SDA_HOLD_MIN_VERS) {
423 if (dev->sda_hold_time) { 426 if (!dev->sda_hold_time) {
424 dw_writel(dev, dev->sda_hold_time, DW_IC_SDA_HOLD);
425 } else {
426 /* Keep previous hold time setting if no one set it */ 427 /* Keep previous hold time setting if no one set it */
427 dev->sda_hold_time = dw_readl(dev, DW_IC_SDA_HOLD); 428 dev->sda_hold_time = dw_readl(dev, DW_IC_SDA_HOLD);
428 } 429 }
430 /*
431 * Workaround for avoiding TX arbitration lost in case I2C
432 * slave pulls SDA down "too quickly" after falling egde of
433 * SCL by enabling non-zero SDA RX hold. Specification says it
434 * extends incoming SDA low to high transition while SCL is
435 * high but it apprears to help also above issue.
436 */
437 if (!(dev->sda_hold_time & DW_IC_SDA_HOLD_RX_MASK))
438 dev->sda_hold_time |= 1 << DW_IC_SDA_HOLD_RX_SHIFT;
439 dw_writel(dev, dev->sda_hold_time, DW_IC_SDA_HOLD);
429 } else { 440 } else {
430 dev_warn(dev->dev, 441 dev_warn(dev->dev,
431 "Hardware too old to adjust SDA hold time.\n"); 442 "Hardware too old to adjust SDA hold time.\n");
diff --git a/drivers/i2c/busses/i2c-digicolor.c b/drivers/i2c/busses/i2c-digicolor.c
index 9604024e0eb0..49f2084f7bb5 100644
--- a/drivers/i2c/busses/i2c-digicolor.c
+++ b/drivers/i2c/busses/i2c-digicolor.c
@@ -368,6 +368,7 @@ static const struct of_device_id dc_i2c_match[] = {
368 { .compatible = "cnxt,cx92755-i2c" }, 368 { .compatible = "cnxt,cx92755-i2c" },
369 { }, 369 { },
370}; 370};
371MODULE_DEVICE_TABLE(of, dc_i2c_match);
371 372
372static struct platform_driver dc_i2c_driver = { 373static struct platform_driver dc_i2c_driver = {
373 .probe = dc_i2c_probe, 374 .probe = dc_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 08847e8b8998..eb3627f35d12 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -146,6 +146,7 @@
146#define SMBHSTCFG_HST_EN 1 146#define SMBHSTCFG_HST_EN 1
147#define SMBHSTCFG_SMB_SMI_EN 2 147#define SMBHSTCFG_SMB_SMI_EN 2
148#define SMBHSTCFG_I2C_EN 4 148#define SMBHSTCFG_I2C_EN 4
149#define SMBHSTCFG_SPD_WD 0x10
149 150
150/* TCO configuration bits for TCOCTL */ 151/* TCO configuration bits for TCOCTL */
151#define TCOCTL_EN 0x0100 152#define TCOCTL_EN 0x0100
@@ -865,9 +866,16 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
865 block = 1; 866 block = 1;
866 break; 867 break;
867 case I2C_SMBUS_I2C_BLOCK_DATA: 868 case I2C_SMBUS_I2C_BLOCK_DATA:
868 /* NB: page 240 of ICH5 datasheet shows that the R/#W 869 /*
869 * bit should be cleared here, even when reading */ 870 * NB: page 240 of ICH5 datasheet shows that the R/#W
870 outb_p((addr & 0x7f) << 1, SMBHSTADD(priv)); 871 * bit should be cleared here, even when reading.
872 * However if SPD Write Disable is set (Lynx Point and later),
873 * the read will fail if we don't set the R/#W bit.
874 */
875 outb_p(((addr & 0x7f) << 1) |
876 ((priv->original_hstcfg & SMBHSTCFG_SPD_WD) ?
877 (read_write & 0x01) : 0),
878 SMBHSTADD(priv));
871 if (read_write == I2C_SMBUS_READ) { 879 if (read_write == I2C_SMBUS_READ) {
872 /* NB: page 240 of ICH5 datasheet also shows 880 /* NB: page 240 of ICH5 datasheet also shows
873 * that DATA1 is the cmd field when reading */ 881 * that DATA1 is the cmd field when reading */
@@ -1573,6 +1581,8 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
1573 /* Disable SMBus interrupt feature if SMBus using SMI# */ 1581 /* Disable SMBus interrupt feature if SMBus using SMI# */
1574 priv->features &= ~FEATURE_IRQ; 1582 priv->features &= ~FEATURE_IRQ;
1575 } 1583 }
1584 if (temp & SMBHSTCFG_SPD_WD)
1585 dev_info(&dev->dev, "SPD Write Disable is set\n");
1576 1586
1577 /* Clear special mode bits */ 1587 /* Clear special mode bits */
1578 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER)) 1588 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 592a8f26a708..47fc1f1acff7 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1009,10 +1009,13 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
1009 rinfo->sda_gpio = of_get_named_gpio(pdev->dev.of_node, "sda-gpios", 0); 1009 rinfo->sda_gpio = of_get_named_gpio(pdev->dev.of_node, "sda-gpios", 0);
1010 rinfo->scl_gpio = of_get_named_gpio(pdev->dev.of_node, "scl-gpios", 0); 1010 rinfo->scl_gpio = of_get_named_gpio(pdev->dev.of_node, "scl-gpios", 0);
1011 1011
1012 if (!gpio_is_valid(rinfo->sda_gpio) || 1012 if (rinfo->sda_gpio == -EPROBE_DEFER ||
1013 !gpio_is_valid(rinfo->scl_gpio) || 1013 rinfo->scl_gpio == -EPROBE_DEFER) {
1014 IS_ERR(i2c_imx->pinctrl_pins_default) || 1014 return -EPROBE_DEFER;
1015 IS_ERR(i2c_imx->pinctrl_pins_gpio)) { 1015 } else if (!gpio_is_valid(rinfo->sda_gpio) ||
1016 !gpio_is_valid(rinfo->scl_gpio) ||
1017 IS_ERR(i2c_imx->pinctrl_pins_default) ||
1018 IS_ERR(i2c_imx->pinctrl_pins_gpio)) {
1016 dev_dbg(&pdev->dev, "recovery information incomplete\n"); 1019 dev_dbg(&pdev->dev, "recovery information incomplete\n");
1017 return 0; 1020 return 0;
1018 } 1021 }
diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
index b8ea62105f42..30132c3957cd 100644
--- a/drivers/i2c/busses/i2c-jz4780.c
+++ b/drivers/i2c/busses/i2c-jz4780.c
@@ -729,6 +729,7 @@ static const struct of_device_id jz4780_i2c_of_matches[] = {
729 { .compatible = "ingenic,jz4780-i2c", }, 729 { .compatible = "ingenic,jz4780-i2c", },
730 { /* sentinel */ } 730 { /* sentinel */ }
731}; 731};
732MODULE_DEVICE_TABLE(of, jz4780_i2c_of_matches);
732 733
733static int jz4780_i2c_probe(struct platform_device *pdev) 734static int jz4780_i2c_probe(struct platform_device *pdev)
734{ 735{
diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
index 50702c7bb244..df220666d627 100644
--- a/drivers/i2c/busses/i2c-rk3x.c
+++ b/drivers/i2c/busses/i2c-rk3x.c
@@ -694,6 +694,8 @@ static int rk3x_i2c_v0_calc_timings(unsigned long clk_rate,
694 t_calc->div_low--; 694 t_calc->div_low--;
695 t_calc->div_high--; 695 t_calc->div_high--;
696 696
697 /* Give the tuning value 0, that would not update con register */
698 t_calc->tuning = 0;
697 /* Maximum divider supported by hw is 0xffff */ 699 /* Maximum divider supported by hw is 0xffff */
698 if (t_calc->div_low > 0xffff) { 700 if (t_calc->div_low > 0xffff) {
699 t_calc->div_low = 0xffff; 701 t_calc->div_low = 0xffff;
diff --git a/drivers/i2c/busses/i2c-xgene-slimpro.c b/drivers/i2c/busses/i2c-xgene-slimpro.c
index 263685c7a512..05cf192ef1ac 100644
--- a/drivers/i2c/busses/i2c-xgene-slimpro.c
+++ b/drivers/i2c/busses/i2c-xgene-slimpro.c
@@ -105,7 +105,7 @@ struct slimpro_i2c_dev {
105 struct mbox_chan *mbox_chan; 105 struct mbox_chan *mbox_chan;
106 struct mbox_client mbox_client; 106 struct mbox_client mbox_client;
107 struct completion rd_complete; 107 struct completion rd_complete;
108 u8 dma_buffer[I2C_SMBUS_BLOCK_MAX]; 108 u8 dma_buffer[I2C_SMBUS_BLOCK_MAX + 1]; /* dma_buffer[0] is used for length */
109 u32 *resp_msg; 109 u32 *resp_msg;
110}; 110};
111 111
diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index 2a972ed7aa0d..e29ff37a43bd 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -426,6 +426,7 @@ static const struct of_device_id xlp9xx_i2c_of_match[] = {
426 { .compatible = "netlogic,xlp980-i2c", }, 426 { .compatible = "netlogic,xlp980-i2c", },
427 { /* sentinel */ }, 427 { /* sentinel */ },
428}; 428};
429MODULE_DEVICE_TABLE(of, xlp9xx_i2c_of_match);
429 430
430#ifdef CONFIG_ACPI 431#ifdef CONFIG_ACPI
431static const struct acpi_device_id xlp9xx_i2c_acpi_ids[] = { 432static const struct acpi_device_id xlp9xx_i2c_acpi_ids[] = {
diff --git a/drivers/i2c/busses/i2c-xlr.c b/drivers/i2c/busses/i2c-xlr.c
index 0968f59b6df5..ad17d88d8573 100644
--- a/drivers/i2c/busses/i2c-xlr.c
+++ b/drivers/i2c/busses/i2c-xlr.c
@@ -358,6 +358,7 @@ static const struct of_device_id xlr_i2c_dt_ids[] = {
358 }, 358 },
359 { } 359 { }
360}; 360};
361MODULE_DEVICE_TABLE(of, xlr_i2c_dt_ids);
361 362
362static int xlr_i2c_probe(struct platform_device *pdev) 363static int xlr_i2c_probe(struct platform_device *pdev)
363{ 364{
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 5ab67219f71e..1704fc84d647 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1681,6 +1681,7 @@ static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
1681static void of_i2c_register_devices(struct i2c_adapter *adap) 1681static void of_i2c_register_devices(struct i2c_adapter *adap)
1682{ 1682{
1683 struct device_node *bus, *node; 1683 struct device_node *bus, *node;
1684 struct i2c_client *client;
1684 1685
1685 /* Only register child devices if the adapter has a node pointer set */ 1686 /* Only register child devices if the adapter has a node pointer set */
1686 if (!adap->dev.of_node) 1687 if (!adap->dev.of_node)
@@ -1695,7 +1696,14 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
1695 for_each_available_child_of_node(bus, node) { 1696 for_each_available_child_of_node(bus, node) {
1696 if (of_node_test_and_set_flag(node, OF_POPULATED)) 1697 if (of_node_test_and_set_flag(node, OF_POPULATED))
1697 continue; 1698 continue;
1698 of_i2c_register_device(adap, node); 1699
1700 client = of_i2c_register_device(adap, node);
1701 if (IS_ERR(client)) {
1702 dev_warn(&adap->dev,
1703 "Failed to create I2C device for %s\n",
1704 node->full_name);
1705 of_node_clear_flag(node, OF_POPULATED);
1706 }
1699 } 1707 }
1700 1708
1701 of_node_put(bus); 1709 of_node_put(bus);
@@ -2299,6 +2307,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
2299 if (IS_ERR(client)) { 2307 if (IS_ERR(client)) {
2300 dev_err(&adap->dev, "failed to create client for '%s'\n", 2308 dev_err(&adap->dev, "failed to create client for '%s'\n",
2301 rd->dn->full_name); 2309 rd->dn->full_name);
2310 of_node_clear_flag(rd->dn, OF_POPULATED);
2302 return notifier_from_errno(PTR_ERR(client)); 2311 return notifier_from_errno(PTR_ERR(client));
2303 } 2312 }
2304 break; 2313 break;
diff --git a/drivers/ipack/ipack.c b/drivers/ipack/ipack.c
index c0e7b624ce54..12102448fddd 100644
--- a/drivers/ipack/ipack.c
+++ b/drivers/ipack/ipack.c
@@ -178,7 +178,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
178 idev->id_vendor, idev->id_device); 178 idev->id_vendor, idev->id_device);
179} 179}
180 180
181ipack_device_attr(id_format, "0x%hhu\n"); 181ipack_device_attr(id_format, "0x%hhx\n");
182 182
183static DEVICE_ATTR_RO(id); 183static DEVICE_ATTR_RO(id);
184static DEVICE_ATTR_RO(id_device); 184static DEVICE_ATTR_RO(id_device);
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 8abde6b8cedc..6d53810963f7 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -266,7 +266,7 @@ static struct raid_type {
266 {"raid10_offset", "raid10 offset (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_OFFSET}, 266 {"raid10_offset", "raid10 offset (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_OFFSET},
267 {"raid10_near", "raid10 near (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_NEAR}, 267 {"raid10_near", "raid10 near (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_NEAR},
268 {"raid10", "raid10 (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_DEFAULT}, 268 {"raid10", "raid10 (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_DEFAULT},
269 {"raid4", "raid4 (dedicated last parity disk)", 1, 2, 4, ALGORITHM_PARITY_N}, /* raid4 layout = raid5_n */ 269 {"raid4", "raid4 (dedicated first parity disk)", 1, 2, 5, ALGORITHM_PARITY_0}, /* raid4 layout = raid5_0 */
270 {"raid5_n", "raid5 (dedicated last parity disk)", 1, 2, 5, ALGORITHM_PARITY_N}, 270 {"raid5_n", "raid5 (dedicated last parity disk)", 1, 2, 5, ALGORITHM_PARITY_N},
271 {"raid5_ls", "raid5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC}, 271 {"raid5_ls", "raid5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC},
272 {"raid5_rs", "raid5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC}, 272 {"raid5_rs", "raid5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC},
@@ -2087,11 +2087,11 @@ static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev)
2087 /* 2087 /*
2088 * No takeover/reshaping, because we don't have the extended v1.9.0 metadata 2088 * No takeover/reshaping, because we don't have the extended v1.9.0 metadata
2089 */ 2089 */
2090 if (le32_to_cpu(sb->level) != mddev->level) { 2090 if (le32_to_cpu(sb->level) != mddev->new_level) {
2091 DMERR("Reshaping/takeover raid sets not yet supported. (raid level/stripes/size change)"); 2091 DMERR("Reshaping/takeover raid sets not yet supported. (raid level/stripes/size change)");
2092 return -EINVAL; 2092 return -EINVAL;
2093 } 2093 }
2094 if (le32_to_cpu(sb->layout) != mddev->layout) { 2094 if (le32_to_cpu(sb->layout) != mddev->new_layout) {
2095 DMERR("Reshaping raid sets not yet supported. (raid layout change)"); 2095 DMERR("Reshaping raid sets not yet supported. (raid layout change)");
2096 DMERR(" 0x%X vs 0x%X", le32_to_cpu(sb->layout), mddev->layout); 2096 DMERR(" 0x%X vs 0x%X", le32_to_cpu(sb->layout), mddev->layout);
2097 DMERR(" Old layout: %s w/ %d copies", 2097 DMERR(" Old layout: %s w/ %d copies",
@@ -2102,7 +2102,7 @@ static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev)
2102 raid10_md_layout_to_copies(mddev->layout)); 2102 raid10_md_layout_to_copies(mddev->layout));
2103 return -EINVAL; 2103 return -EINVAL;
2104 } 2104 }
2105 if (le32_to_cpu(sb->stripe_sectors) != mddev->chunk_sectors) { 2105 if (le32_to_cpu(sb->stripe_sectors) != mddev->new_chunk_sectors) {
2106 DMERR("Reshaping raid sets not yet supported. (stripe sectors change)"); 2106 DMERR("Reshaping raid sets not yet supported. (stripe sectors change)");
2107 return -EINVAL; 2107 return -EINVAL;
2108 } 2108 }
@@ -2115,6 +2115,8 @@ static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev)
2115 return -EINVAL; 2115 return -EINVAL;
2116 } 2116 }
2117 2117
2118 DMINFO("Discovered old metadata format; upgrading to extended metadata format");
2119
2118 /* Table line is checked vs. authoritative superblock */ 2120 /* Table line is checked vs. authoritative superblock */
2119 rs_set_new(rs); 2121 rs_set_new(rs);
2120 } 2122 }
@@ -2258,7 +2260,8 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev)
2258 if (!mddev->events && super_init_validation(rs, rdev)) 2260 if (!mddev->events && super_init_validation(rs, rdev))
2259 return -EINVAL; 2261 return -EINVAL;
2260 2262
2261 if (le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) { 2263 if (le32_to_cpu(sb->compat_features) &&
2264 le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) {
2262 rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags"; 2265 rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags";
2263 return -EINVAL; 2266 return -EINVAL;
2264 } 2267 }
@@ -3646,7 +3649,7 @@ static void raid_resume(struct dm_target *ti)
3646 3649
3647static struct target_type raid_target = { 3650static struct target_type raid_target = {
3648 .name = "raid", 3651 .name = "raid",
3649 .version = {1, 9, 0}, 3652 .version = {1, 9, 1},
3650 .module = THIS_MODULE, 3653 .module = THIS_MODULE,
3651 .ctr = raid_ctr, 3654 .ctr = raid_ctr,
3652 .dtr = raid_dtr, 3655 .dtr = raid_dtr,
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index bdf1606f67bc..9a8b71067c6e 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -145,7 +145,6 @@ static void dispatch_bios(void *context, struct bio_list *bio_list)
145 145
146struct dm_raid1_bio_record { 146struct dm_raid1_bio_record {
147 struct mirror *m; 147 struct mirror *m;
148 /* if details->bi_bdev == NULL, details were not saved */
149 struct dm_bio_details details; 148 struct dm_bio_details details;
150 region_t write_region; 149 region_t write_region;
151}; 150};
@@ -1200,8 +1199,6 @@ static int mirror_map(struct dm_target *ti, struct bio *bio)
1200 struct dm_raid1_bio_record *bio_record = 1199 struct dm_raid1_bio_record *bio_record =
1201 dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record)); 1200 dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record));
1202 1201
1203 bio_record->details.bi_bdev = NULL;
1204
1205 if (rw == WRITE) { 1202 if (rw == WRITE) {
1206 /* Save region for mirror_end_io() handler */ 1203 /* Save region for mirror_end_io() handler */
1207 bio_record->write_region = dm_rh_bio_to_region(ms->rh, bio); 1204 bio_record->write_region = dm_rh_bio_to_region(ms->rh, bio);
@@ -1260,22 +1257,12 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1260 } 1257 }
1261 1258
1262 if (error == -EOPNOTSUPP) 1259 if (error == -EOPNOTSUPP)
1263 goto out; 1260 return error;
1264 1261
1265 if ((error == -EWOULDBLOCK) && (bio->bi_opf & REQ_RAHEAD)) 1262 if ((error == -EWOULDBLOCK) && (bio->bi_opf & REQ_RAHEAD))
1266 goto out; 1263 return error;
1267 1264
1268 if (unlikely(error)) { 1265 if (unlikely(error)) {
1269 if (!bio_record->details.bi_bdev) {
1270 /*
1271 * There wasn't enough memory to record necessary
1272 * information for a retry or there was no other
1273 * mirror in-sync.
1274 */
1275 DMERR_LIMIT("Mirror read failed.");
1276 return -EIO;
1277 }
1278
1279 m = bio_record->m; 1266 m = bio_record->m;
1280 1267
1281 DMERR("Mirror read failed from %s. Trying alternative device.", 1268 DMERR("Mirror read failed from %s. Trying alternative device.",
@@ -1291,7 +1278,7 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1291 bd = &bio_record->details; 1278 bd = &bio_record->details;
1292 1279
1293 dm_bio_restore(bd, bio); 1280 dm_bio_restore(bd, bio);
1294 bio_record->details.bi_bdev = NULL; 1281 bio->bi_error = 0;
1295 1282
1296 queue_bio(ms, bio, rw); 1283 queue_bio(ms, bio, rw);
1297 return DM_ENDIO_INCOMPLETE; 1284 return DM_ENDIO_INCOMPLETE;
@@ -1299,9 +1286,6 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1299 DMERR("All replicated volumes dead, failing I/O"); 1286 DMERR("All replicated volumes dead, failing I/O");
1300 } 1287 }
1301 1288
1302out:
1303 bio_record->details.bi_bdev = NULL;
1304
1305 return error; 1289 return error;
1306} 1290}
1307 1291
diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index dc75bea0d541..1d0d2adc050a 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -856,8 +856,11 @@ int dm_old_init_request_queue(struct mapped_device *md)
856 kthread_init_worker(&md->kworker); 856 kthread_init_worker(&md->kworker);
857 md->kworker_task = kthread_run(kthread_worker_fn, &md->kworker, 857 md->kworker_task = kthread_run(kthread_worker_fn, &md->kworker,
858 "kdmwork-%s", dm_device_name(md)); 858 "kdmwork-%s", dm_device_name(md));
859 if (IS_ERR(md->kworker_task)) 859 if (IS_ERR(md->kworker_task)) {
860 return PTR_ERR(md->kworker_task); 860 int error = PTR_ERR(md->kworker_task);
861 md->kworker_task = NULL;
862 return error;
863 }
861 864
862 elv_register_queue(md->queue); 865 elv_register_queue(md->queue);
863 866
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 3e407a9cde1f..c4b53b332607 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -695,37 +695,32 @@ int dm_table_add_target(struct dm_table *t, const char *type,
695 695
696 tgt->type = dm_get_target_type(type); 696 tgt->type = dm_get_target_type(type);
697 if (!tgt->type) { 697 if (!tgt->type) {
698 DMERR("%s: %s: unknown target type", dm_device_name(t->md), 698 DMERR("%s: %s: unknown target type", dm_device_name(t->md), type);
699 type);
700 return -EINVAL; 699 return -EINVAL;
701 } 700 }
702 701
703 if (dm_target_needs_singleton(tgt->type)) { 702 if (dm_target_needs_singleton(tgt->type)) {
704 if (t->num_targets) { 703 if (t->num_targets) {
705 DMERR("%s: target type %s must appear alone in table", 704 tgt->error = "singleton target type must appear alone in table";
706 dm_device_name(t->md), type); 705 goto bad;
707 return -EINVAL;
708 } 706 }
709 t->singleton = true; 707 t->singleton = true;
710 } 708 }
711 709
712 if (dm_target_always_writeable(tgt->type) && !(t->mode & FMODE_WRITE)) { 710 if (dm_target_always_writeable(tgt->type) && !(t->mode & FMODE_WRITE)) {
713 DMERR("%s: target type %s may not be included in read-only tables", 711 tgt->error = "target type may not be included in a read-only table";
714 dm_device_name(t->md), type); 712 goto bad;
715 return -EINVAL;
716 } 713 }
717 714
718 if (t->immutable_target_type) { 715 if (t->immutable_target_type) {
719 if (t->immutable_target_type != tgt->type) { 716 if (t->immutable_target_type != tgt->type) {
720 DMERR("%s: immutable target type %s cannot be mixed with other target types", 717 tgt->error = "immutable target type cannot be mixed with other target types";
721 dm_device_name(t->md), t->immutable_target_type->name); 718 goto bad;
722 return -EINVAL;
723 } 719 }
724 } else if (dm_target_is_immutable(tgt->type)) { 720 } else if (dm_target_is_immutable(tgt->type)) {
725 if (t->num_targets) { 721 if (t->num_targets) {
726 DMERR("%s: immutable target type %s cannot be mixed with other target types", 722 tgt->error = "immutable target type cannot be mixed with other target types";
727 dm_device_name(t->md), tgt->type->name); 723 goto bad;
728 return -EINVAL;
729 } 724 }
730 t->immutable_target_type = tgt->type; 725 t->immutable_target_type = tgt->type;
731 } 726 }
@@ -740,7 +735,6 @@ int dm_table_add_target(struct dm_table *t, const char *type,
740 */ 735 */
741 if (!adjoin(t, tgt)) { 736 if (!adjoin(t, tgt)) {
742 tgt->error = "Gap in table"; 737 tgt->error = "Gap in table";
743 r = -EINVAL;
744 goto bad; 738 goto bad;
745 } 739 }
746 740
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 147af9536d0c..ef7bf1dd6900 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1423,8 +1423,6 @@ static void cleanup_mapped_device(struct mapped_device *md)
1423 if (md->bs) 1423 if (md->bs)
1424 bioset_free(md->bs); 1424 bioset_free(md->bs);
1425 1425
1426 cleanup_srcu_struct(&md->io_barrier);
1427
1428 if (md->disk) { 1426 if (md->disk) {
1429 spin_lock(&_minor_lock); 1427 spin_lock(&_minor_lock);
1430 md->disk->private_data = NULL; 1428 md->disk->private_data = NULL;
@@ -1436,6 +1434,8 @@ static void cleanup_mapped_device(struct mapped_device *md)
1436 if (md->queue) 1434 if (md->queue)
1437 blk_cleanup_queue(md->queue); 1435 blk_cleanup_queue(md->queue);
1438 1436
1437 cleanup_srcu_struct(&md->io_barrier);
1438
1439 if (md->bdev) { 1439 if (md->bdev) {
1440 bdput(md->bdev); 1440 bdput(md->bdev);
1441 md->bdev = NULL; 1441 md->bdev = NULL;
diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index af23d7dfe752..2e5233b60971 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -247,7 +247,9 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed,
247 cxl_ctx_get(); 247 cxl_ctx_get();
248 248
249 if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) { 249 if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) {
250 put_pid(ctx->glpid);
250 put_pid(ctx->pid); 251 put_pid(ctx->pid);
252 ctx->glpid = ctx->pid = NULL;
251 cxl_adapter_context_put(ctx->afu->adapter); 253 cxl_adapter_context_put(ctx->afu->adapter);
252 cxl_ctx_put(); 254 cxl_ctx_put();
253 goto out; 255 goto out;
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index d0b421f49b39..77080cc5fa0a 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -194,6 +194,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
194 ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF); 194 ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF);
195 195
196 /* 196 /*
197 * Increment the mapped context count for adapter. This also checks
198 * if adapter_context_lock is taken.
199 */
200 rc = cxl_adapter_context_get(ctx->afu->adapter);
201 if (rc) {
202 afu_release_irqs(ctx, ctx);
203 goto out;
204 }
205
206 /*
197 * We grab the PID here and not in the file open to allow for the case 207 * We grab the PID here and not in the file open to allow for the case
198 * where a process (master, some daemon, etc) has opened the chardev on 208 * where a process (master, some daemon, etc) has opened the chardev on
199 * behalf of another process, so the AFU's mm gets bound to the process 209 * behalf of another process, so the AFU's mm gets bound to the process
@@ -205,15 +215,6 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
205 ctx->pid = get_task_pid(current, PIDTYPE_PID); 215 ctx->pid = get_task_pid(current, PIDTYPE_PID);
206 ctx->glpid = get_task_pid(current->group_leader, PIDTYPE_PID); 216 ctx->glpid = get_task_pid(current->group_leader, PIDTYPE_PID);
207 217
208 /*
209 * Increment the mapped context count for adapter. This also checks
210 * if adapter_context_lock is taken.
211 */
212 rc = cxl_adapter_context_get(ctx->afu->adapter);
213 if (rc) {
214 afu_release_irqs(ctx, ctx);
215 goto out;
216 }
217 218
218 trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr); 219 trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr);
219 220
@@ -221,6 +222,9 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
221 amr))) { 222 amr))) {
222 afu_release_irqs(ctx, ctx); 223 afu_release_irqs(ctx, ctx);
223 cxl_adapter_context_put(ctx->afu->adapter); 224 cxl_adapter_context_put(ctx->afu->adapter);
225 put_pid(ctx->glpid);
226 put_pid(ctx->pid);
227 ctx->glpid = ctx->pid = NULL;
224 goto out; 228 goto out;
225 } 229 }
226 230
diff --git a/drivers/misc/sgi-gru/grumain.c b/drivers/misc/sgi-gru/grumain.c
index 1525870f460a..33741ad4a74a 100644
--- a/drivers/misc/sgi-gru/grumain.c
+++ b/drivers/misc/sgi-gru/grumain.c
@@ -283,7 +283,7 @@ static void gru_unload_mm_tracker(struct gru_state *gru,
283 spin_lock(&gru->gs_asid_lock); 283 spin_lock(&gru->gs_asid_lock);
284 BUG_ON((asids->mt_ctxbitmap & ctxbitmap) != ctxbitmap); 284 BUG_ON((asids->mt_ctxbitmap & ctxbitmap) != ctxbitmap);
285 asids->mt_ctxbitmap ^= ctxbitmap; 285 asids->mt_ctxbitmap ^= ctxbitmap;
286 gru_dbg(grudev, "gid %d, gts %p, gms %p, ctxnum 0x%d, asidmap 0x%lx\n", 286 gru_dbg(grudev, "gid %d, gts %p, gms %p, ctxnum %d, asidmap 0x%lx\n",
287 gru->gs_gid, gts, gms, gts->ts_ctxnum, gms->ms_asidmap[0]); 287 gru->gs_gid, gts, gms, gts->ts_ctxnum, gms->ms_asidmap[0]);
288 spin_unlock(&gru->gs_asid_lock); 288 spin_unlock(&gru->gs_asid_lock);
289 spin_unlock(&gms->ms_asid_lock); 289 spin_unlock(&gms->ms_asid_lock);
diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig
index 8b2b740d6679..124c2432ac9c 100644
--- a/drivers/nvdimm/Kconfig
+++ b/drivers/nvdimm/Kconfig
@@ -89,7 +89,7 @@ config NVDIMM_PFN
89 Select Y if unsure 89 Select Y if unsure
90 90
91config NVDIMM_DAX 91config NVDIMM_DAX
92 tristate "NVDIMM DAX: Raw access to persistent memory" 92 bool "NVDIMM DAX: Raw access to persistent memory"
93 default LIBNVDIMM 93 default LIBNVDIMM
94 depends on NVDIMM_PFN 94 depends on NVDIMM_PFN
95 help 95 help
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 3509cff68ef9..abe5c6bc756c 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2176,12 +2176,14 @@ static struct device **scan_labels(struct nd_region *nd_region)
2176 return devs; 2176 return devs;
2177 2177
2178 err: 2178 err:
2179 for (i = 0; devs[i]; i++) 2179 if (devs) {
2180 if (is_nd_blk(&nd_region->dev)) 2180 for (i = 0; devs[i]; i++)
2181 namespace_blk_release(devs[i]); 2181 if (is_nd_blk(&nd_region->dev))
2182 else 2182 namespace_blk_release(devs[i]);
2183 namespace_pmem_release(devs[i]); 2183 else
2184 kfree(devs); 2184 namespace_pmem_release(devs[i]);
2185 kfree(devs);
2186 }
2185 return NULL; 2187 return NULL;
2186} 2188}
2187 2189
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 42b3a8217073..24618431a14b 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -47,7 +47,7 @@ static struct nd_region *to_region(struct pmem_device *pmem)
47 return to_nd_region(to_dev(pmem)->parent); 47 return to_nd_region(to_dev(pmem)->parent);
48} 48}
49 49
50static void pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset, 50static int pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset,
51 unsigned int len) 51 unsigned int len)
52{ 52{
53 struct device *dev = to_dev(pmem); 53 struct device *dev = to_dev(pmem);
@@ -62,8 +62,12 @@ static void pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset,
62 __func__, (unsigned long long) sector, 62 __func__, (unsigned long long) sector,
63 cleared / 512, cleared / 512 > 1 ? "s" : ""); 63 cleared / 512, cleared / 512 > 1 ? "s" : "");
64 badblocks_clear(&pmem->bb, sector, cleared / 512); 64 badblocks_clear(&pmem->bb, sector, cleared / 512);
65 } else {
66 return -EIO;
65 } 67 }
68
66 invalidate_pmem(pmem->virt_addr + offset, len); 69 invalidate_pmem(pmem->virt_addr + offset, len);
70 return 0;
67} 71}
68 72
69static void write_pmem(void *pmem_addr, struct page *page, 73static void write_pmem(void *pmem_addr, struct page *page,
@@ -123,7 +127,7 @@ static int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
123 flush_dcache_page(page); 127 flush_dcache_page(page);
124 write_pmem(pmem_addr, page, off, len); 128 write_pmem(pmem_addr, page, off, len);
125 if (unlikely(bad_pmem)) { 129 if (unlikely(bad_pmem)) {
126 pmem_clear_poison(pmem, pmem_off, len); 130 rc = pmem_clear_poison(pmem, pmem_off, len);
127 write_pmem(pmem_addr, page, off, len); 131 write_pmem(pmem_addr, page, off, len);
128 } 132 }
129 } 133 }
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index bfdd0744b686..ad70507cfb56 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -610,6 +610,7 @@ static int msi_verify_entries(struct pci_dev *dev)
610 * msi_capability_init - configure device's MSI capability structure 610 * msi_capability_init - configure device's MSI capability structure
611 * @dev: pointer to the pci_dev data structure of MSI device function 611 * @dev: pointer to the pci_dev data structure of MSI device function
612 * @nvec: number of interrupts to allocate 612 * @nvec: number of interrupts to allocate
613 * @affinity: flag to indicate cpu irq affinity mask should be set
613 * 614 *
614 * Setup the MSI capability structure of the device with the requested 615 * Setup the MSI capability structure of the device with the requested
615 * number of interrupts. A return value of zero indicates the successful 616 * number of interrupts. A return value of zero indicates the successful
@@ -752,6 +753,7 @@ static void msix_program_entries(struct pci_dev *dev,
752 * @dev: pointer to the pci_dev data structure of MSI-X device function 753 * @dev: pointer to the pci_dev data structure of MSI-X device function
753 * @entries: pointer to an array of struct msix_entry entries 754 * @entries: pointer to an array of struct msix_entry entries
754 * @nvec: number of @entries 755 * @nvec: number of @entries
756 * @affinity: flag to indicate cpu irq affinity mask should be set
755 * 757 *
756 * Setup the MSI-X capability structure of device function with a 758 * Setup the MSI-X capability structure of device function with a
757 * single MSI-X irq. A return of zero indicates the successful setup of 759 * single MSI-X irq. A return of zero indicates the successful setup of
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index 831935af7389..a7a88476e215 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -1205,7 +1205,7 @@ static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1205 mdc, lpm); 1205 mdc, lpm);
1206 return mdc; 1206 return mdc;
1207 } 1207 }
1208 fcx_max_data = mdc * FCX_MAX_DATA_FACTOR; 1208 fcx_max_data = (u32)mdc * FCX_MAX_DATA_FACTOR;
1209 if (fcx_max_data < private->fcx_max_data) { 1209 if (fcx_max_data < private->fcx_max_data) {
1210 dev_warn(&device->cdev->dev, 1210 dev_warn(&device->cdev->dev,
1211 "The maximum data size for zHPF requests %u " 1211 "The maximum data size for zHPF requests %u "
@@ -1675,7 +1675,7 @@ static u32 get_fcx_max_data(struct dasd_device *device)
1675 " data size for zHPF requests failed\n"); 1675 " data size for zHPF requests failed\n");
1676 return 0; 1676 return 0;
1677 } else 1677 } else
1678 return mdc * FCX_MAX_DATA_FACTOR; 1678 return (u32)mdc * FCX_MAX_DATA_FACTOR;
1679} 1679}
1680 1680
1681/* 1681/*
diff --git a/drivers/s390/cio/chp.c b/drivers/s390/cio/chp.c
index 46be25c7461e..876c7e6e3a99 100644
--- a/drivers/s390/cio/chp.c
+++ b/drivers/s390/cio/chp.c
@@ -780,7 +780,7 @@ static int cfg_wait_idle(void)
780static int __init chp_init(void) 780static int __init chp_init(void)
781{ 781{
782 struct chp_id chpid; 782 struct chp_id chpid;
783 int ret; 783 int state, ret;
784 784
785 ret = crw_register_handler(CRW_RSC_CPATH, chp_process_crw); 785 ret = crw_register_handler(CRW_RSC_CPATH, chp_process_crw);
786 if (ret) 786 if (ret)
@@ -791,7 +791,9 @@ static int __init chp_init(void)
791 return 0; 791 return 0;
792 /* Register available channel-paths. */ 792 /* Register available channel-paths. */
793 chp_id_for_each(&chpid) { 793 chp_id_for_each(&chpid) {
794 if (chp_info_get_status(chpid) != CHP_STATUS_NOT_RECOGNIZED) 794 state = chp_info_get_status(chpid);
795 if (state == CHP_STATUS_CONFIGURED ||
796 state == CHP_STATUS_STANDBY)
795 chp_new(chpid); 797 chp_new(chpid);
796 } 798 }
797 799
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index db2739079cbb..790babc5ef66 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -353,7 +353,7 @@ static void NCR5380_print_phase(struct Scsi_Host *instance)
353#endif 353#endif
354 354
355 355
356static int probe_irq __initdata; 356static int probe_irq;
357 357
358/** 358/**
359 * probe_intr - helper for IRQ autoprobe 359 * probe_intr - helper for IRQ autoprobe
@@ -365,7 +365,7 @@ static int probe_irq __initdata;
365 * used by the IRQ probe code. 365 * used by the IRQ probe code.
366 */ 366 */
367 367
368static irqreturn_t __init probe_intr(int irq, void *dev_id) 368static irqreturn_t probe_intr(int irq, void *dev_id)
369{ 369{
370 probe_irq = irq; 370 probe_irq = irq;
371 return IRQ_HANDLED; 371 return IRQ_HANDLED;
@@ -380,7 +380,7 @@ static irqreturn_t __init probe_intr(int irq, void *dev_id)
380 * and then looking to see what interrupt actually turned up. 380 * and then looking to see what interrupt actually turned up.
381 */ 381 */
382 382
383static int __init __maybe_unused NCR5380_probe_irq(struct Scsi_Host *instance, 383static int __maybe_unused NCR5380_probe_irq(struct Scsi_Host *instance,
384 int possible) 384 int possible)
385{ 385{
386 struct NCR5380_hostdata *hostdata = shost_priv(instance); 386 struct NCR5380_hostdata *hostdata = shost_priv(instance);
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 68138a647dfc..d9239c2d49b1 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -900,8 +900,9 @@ void hwi_ring_cq_db(struct beiscsi_hba *phba,
900static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba) 900static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
901{ 901{
902 struct sgl_handle *psgl_handle; 902 struct sgl_handle *psgl_handle;
903 unsigned long flags;
903 904
904 spin_lock_bh(&phba->io_sgl_lock); 905 spin_lock_irqsave(&phba->io_sgl_lock, flags);
905 if (phba->io_sgl_hndl_avbl) { 906 if (phba->io_sgl_hndl_avbl) {
906 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, 907 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
907 "BM_%d : In alloc_io_sgl_handle," 908 "BM_%d : In alloc_io_sgl_handle,"
@@ -919,14 +920,16 @@ static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
919 phba->io_sgl_alloc_index++; 920 phba->io_sgl_alloc_index++;
920 } else 921 } else
921 psgl_handle = NULL; 922 psgl_handle = NULL;
922 spin_unlock_bh(&phba->io_sgl_lock); 923 spin_unlock_irqrestore(&phba->io_sgl_lock, flags);
923 return psgl_handle; 924 return psgl_handle;
924} 925}
925 926
926static void 927static void
927free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) 928free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
928{ 929{
929 spin_lock_bh(&phba->io_sgl_lock); 930 unsigned long flags;
931
932 spin_lock_irqsave(&phba->io_sgl_lock, flags);
930 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, 933 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
931 "BM_%d : In free_,io_sgl_free_index=%d\n", 934 "BM_%d : In free_,io_sgl_free_index=%d\n",
932 phba->io_sgl_free_index); 935 phba->io_sgl_free_index);
@@ -941,7 +944,7 @@ free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
941 "value there=%p\n", phba->io_sgl_free_index, 944 "value there=%p\n", phba->io_sgl_free_index,
942 phba->io_sgl_hndl_base 945 phba->io_sgl_hndl_base
943 [phba->io_sgl_free_index]); 946 [phba->io_sgl_free_index]);
944 spin_unlock_bh(&phba->io_sgl_lock); 947 spin_unlock_irqrestore(&phba->io_sgl_lock, flags);
945 return; 948 return;
946 } 949 }
947 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle; 950 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
@@ -950,7 +953,7 @@ free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
950 phba->io_sgl_free_index = 0; 953 phba->io_sgl_free_index = 0;
951 else 954 else
952 phba->io_sgl_free_index++; 955 phba->io_sgl_free_index++;
953 spin_unlock_bh(&phba->io_sgl_lock); 956 spin_unlock_irqrestore(&phba->io_sgl_lock, flags);
954} 957}
955 958
956static inline struct wrb_handle * 959static inline struct wrb_handle *
@@ -958,15 +961,16 @@ beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context,
958 unsigned int wrbs_per_cxn) 961 unsigned int wrbs_per_cxn)
959{ 962{
960 struct wrb_handle *pwrb_handle; 963 struct wrb_handle *pwrb_handle;
964 unsigned long flags;
961 965
962 spin_lock_bh(&pwrb_context->wrb_lock); 966 spin_lock_irqsave(&pwrb_context->wrb_lock, flags);
963 pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index]; 967 pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index];
964 pwrb_context->wrb_handles_available--; 968 pwrb_context->wrb_handles_available--;
965 if (pwrb_context->alloc_index == (wrbs_per_cxn - 1)) 969 if (pwrb_context->alloc_index == (wrbs_per_cxn - 1))
966 pwrb_context->alloc_index = 0; 970 pwrb_context->alloc_index = 0;
967 else 971 else
968 pwrb_context->alloc_index++; 972 pwrb_context->alloc_index++;
969 spin_unlock_bh(&pwrb_context->wrb_lock); 973 spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags);
970 974
971 if (pwrb_handle) 975 if (pwrb_handle)
972 memset(pwrb_handle->pwrb, 0, sizeof(*pwrb_handle->pwrb)); 976 memset(pwrb_handle->pwrb, 0, sizeof(*pwrb_handle->pwrb));
@@ -1001,14 +1005,16 @@ beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context,
1001 struct wrb_handle *pwrb_handle, 1005 struct wrb_handle *pwrb_handle,
1002 unsigned int wrbs_per_cxn) 1006 unsigned int wrbs_per_cxn)
1003{ 1007{
1004 spin_lock_bh(&pwrb_context->wrb_lock); 1008 unsigned long flags;
1009
1010 spin_lock_irqsave(&pwrb_context->wrb_lock, flags);
1005 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle; 1011 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
1006 pwrb_context->wrb_handles_available++; 1012 pwrb_context->wrb_handles_available++;
1007 if (pwrb_context->free_index == (wrbs_per_cxn - 1)) 1013 if (pwrb_context->free_index == (wrbs_per_cxn - 1))
1008 pwrb_context->free_index = 0; 1014 pwrb_context->free_index = 0;
1009 else 1015 else
1010 pwrb_context->free_index++; 1016 pwrb_context->free_index++;
1011 spin_unlock_bh(&pwrb_context->wrb_lock); 1017 spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags);
1012} 1018}
1013 1019
1014/** 1020/**
@@ -1037,8 +1043,9 @@ free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1037static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) 1043static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1038{ 1044{
1039 struct sgl_handle *psgl_handle; 1045 struct sgl_handle *psgl_handle;
1046 unsigned long flags;
1040 1047
1041 spin_lock_bh(&phba->mgmt_sgl_lock); 1048 spin_lock_irqsave(&phba->mgmt_sgl_lock, flags);
1042 if (phba->eh_sgl_hndl_avbl) { 1049 if (phba->eh_sgl_hndl_avbl) {
1043 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index]; 1050 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1044 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL; 1051 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
@@ -1056,14 +1063,16 @@ static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1056 phba->eh_sgl_alloc_index++; 1063 phba->eh_sgl_alloc_index++;
1057 } else 1064 } else
1058 psgl_handle = NULL; 1065 psgl_handle = NULL;
1059 spin_unlock_bh(&phba->mgmt_sgl_lock); 1066 spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags);
1060 return psgl_handle; 1067 return psgl_handle;
1061} 1068}
1062 1069
1063void 1070void
1064free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) 1071free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1065{ 1072{
1066 spin_lock_bh(&phba->mgmt_sgl_lock); 1073 unsigned long flags;
1074
1075 spin_lock_irqsave(&phba->mgmt_sgl_lock, flags);
1067 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, 1076 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1068 "BM_%d : In free_mgmt_sgl_handle," 1077 "BM_%d : In free_mgmt_sgl_handle,"
1069 "eh_sgl_free_index=%d\n", 1078 "eh_sgl_free_index=%d\n",
@@ -1078,7 +1087,7 @@ free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1078 "BM_%d : Double Free in eh SGL ," 1087 "BM_%d : Double Free in eh SGL ,"
1079 "eh_sgl_free_index=%d\n", 1088 "eh_sgl_free_index=%d\n",
1080 phba->eh_sgl_free_index); 1089 phba->eh_sgl_free_index);
1081 spin_unlock_bh(&phba->mgmt_sgl_lock); 1090 spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags);
1082 return; 1091 return;
1083 } 1092 }
1084 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle; 1093 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
@@ -1088,7 +1097,7 @@ free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1088 phba->eh_sgl_free_index = 0; 1097 phba->eh_sgl_free_index = 0;
1089 else 1098 else
1090 phba->eh_sgl_free_index++; 1099 phba->eh_sgl_free_index++;
1091 spin_unlock_bh(&phba->mgmt_sgl_lock); 1100 spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags);
1092} 1101}
1093 1102
1094static void 1103static void
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index c051694bfcb0..f9b6fba689ff 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -791,9 +791,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
791 791
792free_task: 792free_task:
793 /* regular RX path uses back_lock */ 793 /* regular RX path uses back_lock */
794 spin_lock_bh(&session->back_lock); 794 spin_lock(&session->back_lock);
795 __iscsi_put_task(task); 795 __iscsi_put_task(task);
796 spin_unlock_bh(&session->back_lock); 796 spin_unlock(&session->back_lock);
797 return NULL; 797 return NULL;
798} 798}
799 799
diff --git a/drivers/thermal/intel_pch_thermal.c b/drivers/thermal/intel_pch_thermal.c
index 9b4815e81b0d..19bf2028e508 100644
--- a/drivers/thermal/intel_pch_thermal.c
+++ b/drivers/thermal/intel_pch_thermal.c
@@ -20,10 +20,13 @@
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/acpi.h>
23#include <linux/thermal.h> 24#include <linux/thermal.h>
24#include <linux/pm.h> 25#include <linux/pm.h>
25 26
26/* Intel PCH thermal Device IDs */ 27/* Intel PCH thermal Device IDs */
28#define PCH_THERMAL_DID_HSW_1 0x9C24 /* Haswell PCH */
29#define PCH_THERMAL_DID_HSW_2 0x8C24 /* Haswell PCH */
27#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */ 30#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */
28#define PCH_THERMAL_DID_SKL 0x9D31 /* Skylake PCH */ 31#define PCH_THERMAL_DID_SKL 0x9D31 /* Skylake PCH */
29 32
@@ -66,9 +69,53 @@ struct pch_thermal_device {
66 unsigned long crt_temp; 69 unsigned long crt_temp;
67 int hot_trip_id; 70 int hot_trip_id;
68 unsigned long hot_temp; 71 unsigned long hot_temp;
72 int psv_trip_id;
73 unsigned long psv_temp;
69 bool bios_enabled; 74 bool bios_enabled;
70}; 75};
71 76
77#ifdef CONFIG_ACPI
78
79/*
80 * On some platforms, there is a companion ACPI device, which adds
81 * passive trip temperature using _PSV method. There is no specific
82 * passive temperature setting in MMIO interface of this PCI device.
83 */
84static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd,
85 int *nr_trips)
86{
87 struct acpi_device *adev;
88
89 ptd->psv_trip_id = -1;
90
91 adev = ACPI_COMPANION(&ptd->pdev->dev);
92 if (adev) {
93 unsigned long long r;
94 acpi_status status;
95
96 status = acpi_evaluate_integer(adev->handle, "_PSV", NULL,
97 &r);
98 if (ACPI_SUCCESS(status)) {
99 unsigned long trip_temp;
100
101 trip_temp = DECI_KELVIN_TO_MILLICELSIUS(r);
102 if (trip_temp) {
103 ptd->psv_temp = trip_temp;
104 ptd->psv_trip_id = *nr_trips;
105 ++(*nr_trips);
106 }
107 }
108 }
109}
110#else
111static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd,
112 int *nr_trips)
113{
114 ptd->psv_trip_id = -1;
115
116}
117#endif
118
72static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips) 119static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
73{ 120{
74 u8 tsel; 121 u8 tsel;
@@ -119,6 +166,8 @@ read_trips:
119 ++(*nr_trips); 166 ++(*nr_trips);
120 } 167 }
121 168
169 pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
170
122 return 0; 171 return 0;
123} 172}
124 173
@@ -194,6 +243,8 @@ static int pch_get_trip_type(struct thermal_zone_device *tzd, int trip,
194 *type = THERMAL_TRIP_CRITICAL; 243 *type = THERMAL_TRIP_CRITICAL;
195 else if (ptd->hot_trip_id == trip) 244 else if (ptd->hot_trip_id == trip)
196 *type = THERMAL_TRIP_HOT; 245 *type = THERMAL_TRIP_HOT;
246 else if (ptd->psv_trip_id == trip)
247 *type = THERMAL_TRIP_PASSIVE;
197 else 248 else
198 return -EINVAL; 249 return -EINVAL;
199 250
@@ -208,6 +259,8 @@ static int pch_get_trip_temp(struct thermal_zone_device *tzd, int trip, int *tem
208 *temp = ptd->crt_temp; 259 *temp = ptd->crt_temp;
209 else if (ptd->hot_trip_id == trip) 260 else if (ptd->hot_trip_id == trip)
210 *temp = ptd->hot_temp; 261 *temp = ptd->hot_temp;
262 else if (ptd->psv_trip_id == trip)
263 *temp = ptd->psv_temp;
211 else 264 else
212 return -EINVAL; 265 return -EINVAL;
213 266
@@ -242,6 +295,11 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
242 ptd->ops = &pch_dev_ops_wpt; 295 ptd->ops = &pch_dev_ops_wpt;
243 dev_name = "pch_skylake"; 296 dev_name = "pch_skylake";
244 break; 297 break;
298 case PCH_THERMAL_DID_HSW_1:
299 case PCH_THERMAL_DID_HSW_2:
300 ptd->ops = &pch_dev_ops_wpt;
301 dev_name = "pch_haswell";
302 break;
245 default: 303 default:
246 dev_err(&pdev->dev, "unknown pch thermal device\n"); 304 dev_err(&pdev->dev, "unknown pch thermal device\n");
247 return -ENODEV; 305 return -ENODEV;
@@ -324,6 +382,8 @@ static int intel_pch_thermal_resume(struct device *device)
324static struct pci_device_id intel_pch_thermal_id[] = { 382static struct pci_device_id intel_pch_thermal_id[] = {
325 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) }, 383 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) },
326 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) }, 384 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) },
385 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_1) },
386 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_2) },
327 { 0, }, 387 { 0, },
328}; 388};
329MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id); 389MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id);
diff --git a/drivers/thermal/intel_powerclamp.c b/drivers/thermal/intel_powerclamp.c
index 0e4dc0afcfd2..7a223074df3d 100644
--- a/drivers/thermal/intel_powerclamp.c
+++ b/drivers/thermal/intel_powerclamp.c
@@ -669,20 +669,10 @@ static struct thermal_cooling_device_ops powerclamp_cooling_ops = {
669 .set_cur_state = powerclamp_set_cur_state, 669 .set_cur_state = powerclamp_set_cur_state,
670}; 670};
671 671
672static const struct x86_cpu_id intel_powerclamp_ids[] __initconst = {
673 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_MWAIT },
674 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_ARAT },
675 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_NONSTOP_TSC },
676 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_CONSTANT_TSC},
677 {}
678};
679MODULE_DEVICE_TABLE(x86cpu, intel_powerclamp_ids);
680
681static int __init powerclamp_probe(void) 672static int __init powerclamp_probe(void)
682{ 673{
683 if (!x86_match_cpu(intel_powerclamp_ids)) { 674 if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
684 pr_err("Intel powerclamp does not run on family %d model %d\n", 675 pr_err("CPU does not support MWAIT");
685 boot_cpu_data.x86, boot_cpu_data.x86_model);
686 return -ENODEV; 676 return -ENODEV;
687 } 677 }
688 678
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 96ae69502c86..111b0e0b8698 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -188,6 +188,8 @@ static void host_stop(struct ci_hdrc *ci)
188 188
189 if (hcd) { 189 if (hcd) {
190 usb_remove_hcd(hcd); 190 usb_remove_hcd(hcd);
191 ci->role = CI_ROLE_END;
192 synchronize_irq(ci->irq);
191 usb_put_hcd(hcd); 193 usb_put_hcd(hcd);
192 if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) && 194 if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) &&
193 (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON)) 195 (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON))
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index fa9b26b91507..4c0fa0b17353 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -463,9 +463,18 @@ static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg)
463 */ 463 */
464void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg) 464void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg)
465{ 465{
466 bool ret;
467
466 switch (hsotg->dr_mode) { 468 switch (hsotg->dr_mode) {
467 case USB_DR_MODE_HOST: 469 case USB_DR_MODE_HOST:
468 dwc2_force_mode(hsotg, true); 470 ret = dwc2_force_mode(hsotg, true);
471 /*
472 * NOTE: This is required for some rockchip soc based
473 * platforms on their host-only dwc2.
474 */
475 if (!ret)
476 msleep(50);
477
469 break; 478 break;
470 case USB_DR_MODE_PERIPHERAL: 479 case USB_DR_MODE_PERIPHERAL:
471 dwc2_force_mode(hsotg, false); 480 dwc2_force_mode(hsotg, false);
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index aad4107ef927..2a21a0414b1d 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -259,6 +259,13 @@ enum dwc2_lx_state {
259 DWC2_L3, /* Off state */ 259 DWC2_L3, /* Off state */
260}; 260};
261 261
262/*
263 * Gadget periodic tx fifo sizes as used by legacy driver
264 * EP0 is not included
265 */
266#define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
267 768, 0, 0, 0, 0, 0, 0, 0}
268
262/* Gadget ep0 states */ 269/* Gadget ep0 states */
263enum dwc2_ep0_state { 270enum dwc2_ep0_state {
264 DWC2_EP0_SETUP, 271 DWC2_EP0_SETUP,
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 4cd6403a7566..24fbebc9b409 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -186,10 +186,9 @@ static void dwc2_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg,
186 */ 186 */
187static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg) 187static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
188{ 188{
189 unsigned int fifo; 189 unsigned int ep;
190 unsigned int addr; 190 unsigned int addr;
191 int timeout; 191 int timeout;
192 u32 dptxfsizn;
193 u32 val; 192 u32 val;
194 193
195 /* Reset fifo map if not correctly cleared during previous session */ 194 /* Reset fifo map if not correctly cleared during previous session */
@@ -217,16 +216,16 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
217 * them to endpoints dynamically according to maxpacket size value of 216 * them to endpoints dynamically according to maxpacket size value of
218 * given endpoint. 217 * given endpoint.
219 */ 218 */
220 for (fifo = 1; fifo < MAX_EPS_CHANNELS; fifo++) { 219 for (ep = 1; ep < MAX_EPS_CHANNELS; ep++) {
221 dptxfsizn = dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)); 220 if (!hsotg->g_tx_fifo_sz[ep])
222 221 continue;
223 val = (dptxfsizn & FIFOSIZE_DEPTH_MASK) | addr; 222 val = addr;
224 addr += dptxfsizn >> FIFOSIZE_DEPTH_SHIFT; 223 val |= hsotg->g_tx_fifo_sz[ep] << FIFOSIZE_DEPTH_SHIFT;
225 224 WARN_ONCE(addr + hsotg->g_tx_fifo_sz[ep] > hsotg->fifo_mem,
226 if (addr > hsotg->fifo_mem) 225 "insufficient fifo memory");
227 break; 226 addr += hsotg->g_tx_fifo_sz[ep];
228 227
229 dwc2_writel(val, hsotg->regs + DPTXFSIZN(fifo)); 228 dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep));
230 } 229 }
231 230
232 /* 231 /*
@@ -3807,10 +3806,36 @@ static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg)
3807static void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg) 3806static void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg)
3808{ 3807{
3809 struct device_node *np = hsotg->dev->of_node; 3808 struct device_node *np = hsotg->dev->of_node;
3809 u32 len = 0;
3810 u32 i = 0;
3810 3811
3811 /* Enable dma if requested in device tree */ 3812 /* Enable dma if requested in device tree */
3812 hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma"); 3813 hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma");
3813 3814
3815 /*
3816 * Register TX periodic fifo size per endpoint.
3817 * EP0 is excluded since it has no fifo configuration.
3818 */
3819 if (!of_find_property(np, "g-tx-fifo-size", &len))
3820 goto rx_fifo;
3821
3822 len /= sizeof(u32);
3823
3824 /* Read tx fifo sizes other than ep0 */
3825 if (of_property_read_u32_array(np, "g-tx-fifo-size",
3826 &hsotg->g_tx_fifo_sz[1], len))
3827 goto rx_fifo;
3828
3829 /* Add ep0 */
3830 len++;
3831
3832 /* Make remaining TX fifos unavailable */
3833 if (len < MAX_EPS_CHANNELS) {
3834 for (i = len; i < MAX_EPS_CHANNELS; i++)
3835 hsotg->g_tx_fifo_sz[i] = 0;
3836 }
3837
3838rx_fifo:
3814 /* Register RX fifo size */ 3839 /* Register RX fifo size */
3815 of_property_read_u32(np, "g-rx-fifo-size", &hsotg->g_rx_fifo_sz); 3840 of_property_read_u32(np, "g-rx-fifo-size", &hsotg->g_rx_fifo_sz);
3816 3841
@@ -3832,10 +3857,13 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
3832 struct device *dev = hsotg->dev; 3857 struct device *dev = hsotg->dev;
3833 int epnum; 3858 int epnum;
3834 int ret; 3859 int ret;
3860 int i;
3861 u32 p_tx_fifo[] = DWC2_G_P_LEGACY_TX_FIFO_SIZE;
3835 3862
3836 /* Initialize to legacy fifo configuration values */ 3863 /* Initialize to legacy fifo configuration values */
3837 hsotg->g_rx_fifo_sz = 2048; 3864 hsotg->g_rx_fifo_sz = 2048;
3838 hsotg->g_np_g_tx_fifo_sz = 1024; 3865 hsotg->g_np_g_tx_fifo_sz = 1024;
3866 memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo));
3839 /* Device tree specific probe */ 3867 /* Device tree specific probe */
3840 dwc2_hsotg_of_probe(hsotg); 3868 dwc2_hsotg_of_probe(hsotg);
3841 3869
@@ -3853,6 +3881,9 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
3853 dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n", 3881 dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n",
3854 hsotg->g_np_g_tx_fifo_sz); 3882 hsotg->g_np_g_tx_fifo_sz);
3855 dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz); 3883 dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz);
3884 for (i = 0; i < MAX_EPS_CHANNELS; i++)
3885 dev_dbg(dev, "Periodic TXFIFO%2d size: %d\n", i,
3886 hsotg->g_tx_fifo_sz[i]);
3856 3887
3857 hsotg->gadget.max_speed = USB_SPEED_HIGH; 3888 hsotg->gadget.max_speed = USB_SPEED_HIGH;
3858 hsotg->gadget.ops = &dwc2_hsotg_gadget_ops; 3889 hsotg->gadget.ops = &dwc2_hsotg_gadget_ops;
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 07cc8929f271..1dfa56a5f1c5 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -783,6 +783,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
783 req->trb = trb; 783 req->trb = trb;
784 req->trb_dma = dwc3_trb_dma_offset(dep, trb); 784 req->trb_dma = dwc3_trb_dma_offset(dep, trb);
785 req->first_trb_index = dep->trb_enqueue; 785 req->first_trb_index = dep->trb_enqueue;
786 dep->queued_requests++;
786 } 787 }
787 788
788 dwc3_ep_inc_enq(dep); 789 dwc3_ep_inc_enq(dep);
@@ -833,8 +834,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
833 834
834 trb->ctrl |= DWC3_TRB_CTRL_HWO; 835 trb->ctrl |= DWC3_TRB_CTRL_HWO;
835 836
836 dep->queued_requests++;
837
838 trace_dwc3_prepare_trb(dep, trb); 837 trace_dwc3_prepare_trb(dep, trb);
839} 838}
840 839
@@ -1074,9 +1073,17 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
1074 1073
1075 list_add_tail(&req->list, &dep->pending_list); 1074 list_add_tail(&req->list, &dep->pending_list);
1076 1075
1077 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1076 /*
1078 dep->flags & DWC3_EP_PENDING_REQUEST) { 1077 * NOTICE: Isochronous endpoints should NEVER be prestarted. We must
1079 if (list_empty(&dep->started_list)) { 1078 * wait for a XferNotReady event so we will know what's the current
1079 * (micro-)frame number.
1080 *
1081 * Without this trick, we are very, very likely gonna get Bus Expiry
1082 * errors which will force us issue EndTransfer command.
1083 */
1084 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
1085 if ((dep->flags & DWC3_EP_PENDING_REQUEST) &&
1086 list_empty(&dep->started_list)) {
1080 dwc3_stop_active_transfer(dwc, dep->number, true); 1087 dwc3_stop_active_transfer(dwc, dep->number, true);
1081 dep->flags = DWC3_EP_ENABLED; 1088 dep->flags = DWC3_EP_ENABLED;
1082 } 1089 }
@@ -1861,8 +1868,11 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
1861 unsigned int s_pkt = 0; 1868 unsigned int s_pkt = 0;
1862 unsigned int trb_status; 1869 unsigned int trb_status;
1863 1870
1864 dep->queued_requests--;
1865 dwc3_ep_inc_deq(dep); 1871 dwc3_ep_inc_deq(dep);
1872
1873 if (req->trb == trb)
1874 dep->queued_requests--;
1875
1866 trace_dwc3_complete_trb(dep, trb); 1876 trace_dwc3_complete_trb(dep, trb);
1867 1877
1868 /* 1878 /*
@@ -2980,7 +2990,7 @@ err3:
2980 kfree(dwc->setup_buf); 2990 kfree(dwc->setup_buf);
2981 2991
2982err2: 2992err2:
2983 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), 2993 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
2984 dwc->ep0_trb, dwc->ep0_trb_addr); 2994 dwc->ep0_trb, dwc->ep0_trb_addr);
2985 2995
2986err1: 2996err1:
@@ -3005,7 +3015,7 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
3005 kfree(dwc->setup_buf); 3015 kfree(dwc->setup_buf);
3006 kfree(dwc->zlp_buf); 3016 kfree(dwc->zlp_buf);
3007 3017
3008 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), 3018 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
3009 dwc->ep0_trb, dwc->ep0_trb_addr); 3019 dwc->ep0_trb, dwc->ep0_trb_addr);
3010 3020
3011 dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 3021 dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 54ad100af35b..e40d47d47d82 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -136,8 +136,60 @@ struct ffs_epfile {
136 /* 136 /*
137 * Buffer for holding data from partial reads which may happen since 137 * Buffer for holding data from partial reads which may happen since
138 * we’re rounding user read requests to a multiple of a max packet size. 138 * we’re rounding user read requests to a multiple of a max packet size.
139 *
140 * The pointer is initialised with NULL value and may be set by
141 * __ffs_epfile_read_data function to point to a temporary buffer.
142 *
143 * In normal operation, calls to __ffs_epfile_read_buffered will consume
144 * data from said buffer and eventually free it. Importantly, while the
145 * function is using the buffer, it sets the pointer to NULL. This is
146 * all right since __ffs_epfile_read_data and __ffs_epfile_read_buffered
147 * can never run concurrently (they are synchronised by epfile->mutex)
148 * so the latter will not assign a new value to the pointer.
149 *
150 * Meanwhile ffs_func_eps_disable frees the buffer (if the pointer is
151 * valid) and sets the pointer to READ_BUFFER_DROP value. This special
152 * value is crux of the synchronisation between ffs_func_eps_disable and
153 * __ffs_epfile_read_data.
154 *
155 * Once __ffs_epfile_read_data is about to finish it will try to set the
156 * pointer back to its old value (as described above), but seeing as the
157 * pointer is not-NULL (namely READ_BUFFER_DROP) it will instead free
158 * the buffer.
159 *
160 * == State transitions ==
161 *
162 * • ptr == NULL: (initial state)
163 * â—¦ __ffs_epfile_read_buffer_free: go to ptr == DROP
164 * â—¦ __ffs_epfile_read_buffered: nop
165 * â—¦ __ffs_epfile_read_data allocates temp buffer: go to ptr == buf
166 * ◦ reading finishes: n/a, not in ‘and reading’ state
167 * • ptr == DROP:
168 * â—¦ __ffs_epfile_read_buffer_free: nop
169 * â—¦ __ffs_epfile_read_buffered: go to ptr == NULL
170 * â—¦ __ffs_epfile_read_data allocates temp buffer: free buf, nop
171 * ◦ reading finishes: n/a, not in ‘and reading’ state
172 * • ptr == buf:
173 * â—¦ __ffs_epfile_read_buffer_free: free buf, go to ptr == DROP
174 * â—¦ __ffs_epfile_read_buffered: go to ptr == NULL and reading
175 * â—¦ __ffs_epfile_read_data: n/a, __ffs_epfile_read_buffered
176 * is always called first
177 * ◦ reading finishes: n/a, not in ‘and reading’ state
178 * • ptr == NULL and reading:
179 * â—¦ __ffs_epfile_read_buffer_free: go to ptr == DROP and reading
180 * â—¦ __ffs_epfile_read_buffered: n/a, mutex is held
181 * â—¦ __ffs_epfile_read_data: n/a, mutex is held
182 * ◦ reading finishes and …
183 * … all data read: free buf, go to ptr == NULL
184 * … otherwise: go to ptr == buf and reading
185 * • ptr == DROP and reading:
186 * â—¦ __ffs_epfile_read_buffer_free: nop
187 * â—¦ __ffs_epfile_read_buffered: n/a, mutex is held
188 * â—¦ __ffs_epfile_read_data: n/a, mutex is held
189 * â—¦ reading finishes: free buf, go to ptr == DROP
139 */ 190 */
140 struct ffs_buffer *read_buffer; /* P: epfile->mutex */ 191 struct ffs_buffer *read_buffer;
192#define READ_BUFFER_DROP ((struct ffs_buffer *)ERR_PTR(-ESHUTDOWN))
141 193
142 char name[5]; 194 char name[5];
143 195
@@ -736,25 +788,47 @@ static void ffs_epfile_async_io_complete(struct usb_ep *_ep,
736 schedule_work(&io_data->work); 788 schedule_work(&io_data->work);
737} 789}
738 790
791static void __ffs_epfile_read_buffer_free(struct ffs_epfile *epfile)
792{
793 /*
794 * See comment in struct ffs_epfile for full read_buffer pointer
795 * synchronisation story.
796 */
797 struct ffs_buffer *buf = xchg(&epfile->read_buffer, READ_BUFFER_DROP);
798 if (buf && buf != READ_BUFFER_DROP)
799 kfree(buf);
800}
801
739/* Assumes epfile->mutex is held. */ 802/* Assumes epfile->mutex is held. */
740static ssize_t __ffs_epfile_read_buffered(struct ffs_epfile *epfile, 803static ssize_t __ffs_epfile_read_buffered(struct ffs_epfile *epfile,
741 struct iov_iter *iter) 804 struct iov_iter *iter)
742{ 805{
743 struct ffs_buffer *buf = epfile->read_buffer; 806 /*
807 * Null out epfile->read_buffer so ffs_func_eps_disable does not free
808 * the buffer while we are using it. See comment in struct ffs_epfile
809 * for full read_buffer pointer synchronisation story.
810 */
811 struct ffs_buffer *buf = xchg(&epfile->read_buffer, NULL);
744 ssize_t ret; 812 ssize_t ret;
745 if (!buf) 813 if (!buf || buf == READ_BUFFER_DROP)
746 return 0; 814 return 0;
747 815
748 ret = copy_to_iter(buf->data, buf->length, iter); 816 ret = copy_to_iter(buf->data, buf->length, iter);
749 if (buf->length == ret) { 817 if (buf->length == ret) {
750 kfree(buf); 818 kfree(buf);
751 epfile->read_buffer = NULL; 819 return ret;
752 } else if (unlikely(iov_iter_count(iter))) { 820 }
821
822 if (unlikely(iov_iter_count(iter))) {
753 ret = -EFAULT; 823 ret = -EFAULT;
754 } else { 824 } else {
755 buf->length -= ret; 825 buf->length -= ret;
756 buf->data += ret; 826 buf->data += ret;
757 } 827 }
828
829 if (cmpxchg(&epfile->read_buffer, NULL, buf))
830 kfree(buf);
831
758 return ret; 832 return ret;
759} 833}
760 834
@@ -783,7 +857,15 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile,
783 buf->length = data_len; 857 buf->length = data_len;
784 buf->data = buf->storage; 858 buf->data = buf->storage;
785 memcpy(buf->storage, data + ret, data_len); 859 memcpy(buf->storage, data + ret, data_len);
786 epfile->read_buffer = buf; 860
861 /*
862 * At this point read_buffer is NULL or READ_BUFFER_DROP (if
863 * ffs_func_eps_disable has been called in the meanwhile). See comment
864 * in struct ffs_epfile for full read_buffer pointer synchronisation
865 * story.
866 */
867 if (unlikely(cmpxchg(&epfile->read_buffer, NULL, buf)))
868 kfree(buf);
787 869
788 return ret; 870 return ret;
789} 871}
@@ -1097,8 +1179,7 @@ ffs_epfile_release(struct inode *inode, struct file *file)
1097 1179
1098 ENTER(); 1180 ENTER();
1099 1181
1100 kfree(epfile->read_buffer); 1182 __ffs_epfile_read_buffer_free(epfile);
1101 epfile->read_buffer = NULL;
1102 ffs_data_closed(epfile->ffs); 1183 ffs_data_closed(epfile->ffs);
1103 1184
1104 return 0; 1185 return 0;
@@ -1724,24 +1805,20 @@ static void ffs_func_eps_disable(struct ffs_function *func)
1724 unsigned count = func->ffs->eps_count; 1805 unsigned count = func->ffs->eps_count;
1725 unsigned long flags; 1806 unsigned long flags;
1726 1807
1808 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1727 do { 1809 do {
1728 if (epfile)
1729 mutex_lock(&epfile->mutex);
1730 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1731 /* pending requests get nuked */ 1810 /* pending requests get nuked */
1732 if (likely(ep->ep)) 1811 if (likely(ep->ep))
1733 usb_ep_disable(ep->ep); 1812 usb_ep_disable(ep->ep);
1734 ++ep; 1813 ++ep;
1735 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
1736 1814
1737 if (epfile) { 1815 if (epfile) {
1738 epfile->ep = NULL; 1816 epfile->ep = NULL;
1739 kfree(epfile->read_buffer); 1817 __ffs_epfile_read_buffer_free(epfile);
1740 epfile->read_buffer = NULL;
1741 mutex_unlock(&epfile->mutex);
1742 ++epfile; 1818 ++epfile;
1743 } 1819 }
1744 } while (--count); 1820 } while (--count);
1821 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
1745} 1822}
1746 1823
1747static int ffs_func_eps_enable(struct ffs_function *func) 1824static int ffs_func_eps_enable(struct ffs_function *func)
diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 9c8c9ed1dc9e..fe1811650dbc 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -590,8 +590,9 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
590 590
591 /* throttle high/super speed IRQ rate back slightly */ 591 /* throttle high/super speed IRQ rate back slightly */
592 if (gadget_is_dualspeed(dev->gadget)) 592 if (gadget_is_dualspeed(dev->gadget))
593 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH || 593 req->no_interrupt = (((dev->gadget->speed == USB_SPEED_HIGH ||
594 dev->gadget->speed == USB_SPEED_SUPER) 594 dev->gadget->speed == USB_SPEED_SUPER)) &&
595 !list_empty(&dev->tx_reqs))
595 ? ((atomic_read(&dev->tx_qlen) % dev->qmult) != 0) 596 ? ((atomic_read(&dev->tx_qlen) % dev->qmult) != 0)
596 : 0; 597 : 0;
597 598
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c
index bb1f6c8f0f01..45bc997d0711 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1978,7 +1978,7 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
1978 dev_err(&pdev->dev, "of_probe: name error(%d)\n", ret); 1978 dev_err(&pdev->dev, "of_probe: name error(%d)\n", ret);
1979 goto err; 1979 goto err;
1980 } 1980 }
1981 ep->ep.name = name; 1981 ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", ep->index);
1982 1982
1983 ep->ep_regs = udc->regs + USBA_EPT_BASE(i); 1983 ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
1984 ep->dma_regs = udc->regs + USBA_DMA_BASE(i); 1984 ep->dma_regs = udc->regs + USBA_DMA_BASE(i);
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index 876dca4fc216..a268d9e8d6cf 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -39,7 +39,7 @@
39 39
40#define DRIVER_DESC "EHCI generic platform driver" 40#define DRIVER_DESC "EHCI generic platform driver"
41#define EHCI_MAX_CLKS 4 41#define EHCI_MAX_CLKS 4
42#define EHCI_MAX_RSTS 3 42#define EHCI_MAX_RSTS 4
43#define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv) 43#define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv)
44 44
45struct ehci_platform_priv { 45struct ehci_platform_priv {
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 5b5880c0ae19..b38a228134df 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -221,6 +221,12 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
221 ohci->num_ports = board->ports; 221 ohci->num_ports = board->ports;
222 at91_start_hc(pdev); 222 at91_start_hc(pdev);
223 223
224 /*
225 * The RemoteWakeupConnected bit has to be set explicitly
226 * before calling ohci_run. The reset value of this bit is 0.
227 */
228 ohci->hc_control = OHCI_CTRL_RWC;
229
224 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 230 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
225 if (retval == 0) { 231 if (retval == 0) {
226 device_wakeup_enable(hcd->self.controller); 232 device_wakeup_enable(hcd->self.controller);
@@ -677,9 +683,6 @@ ohci_hcd_at91_drv_suspend(struct device *dev)
677 * REVISIT: some boards will be able to turn VBUS off... 683 * REVISIT: some boards will be able to turn VBUS off...
678 */ 684 */
679 if (!ohci_at91->wakeup) { 685 if (!ohci_at91->wakeup) {
680 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
681 ohci->hc_control &= OHCI_CTRL_RWC;
682 ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
683 ohci->rh_state = OHCI_RH_HALTED; 686 ohci->rh_state = OHCI_RH_HALTED;
684 687
685 /* flush the writes */ 688 /* flush the writes */
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 1700908b84ef..86612ac3fda2 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -72,7 +72,7 @@
72static const char hcd_name [] = "ohci_hcd"; 72static const char hcd_name [] = "ohci_hcd";
73 73
74#define STATECHANGE_DELAY msecs_to_jiffies(300) 74#define STATECHANGE_DELAY msecs_to_jiffies(300)
75#define IO_WATCHDOG_DELAY msecs_to_jiffies(250) 75#define IO_WATCHDOG_DELAY msecs_to_jiffies(275)
76 76
77#include "ohci.h" 77#include "ohci.h"
78#include "pci-quirks.h" 78#include "pci-quirks.h"
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 730b9fd26685..0ef16900efed 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1166,7 +1166,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1166 xhci_set_link_state(xhci, port_array, wIndex, 1166 xhci_set_link_state(xhci, port_array, wIndex,
1167 XDEV_RESUME); 1167 XDEV_RESUME);
1168 spin_unlock_irqrestore(&xhci->lock, flags); 1168 spin_unlock_irqrestore(&xhci->lock, flags);
1169 msleep(20); 1169 msleep(USB_RESUME_TIMEOUT);
1170 spin_lock_irqsave(&xhci->lock, flags); 1170 spin_lock_irqsave(&xhci->lock, flags);
1171 xhci_set_link_state(xhci, port_array, wIndex, 1171 xhci_set_link_state(xhci, port_array, wIndex,
1172 XDEV_U0); 1172 XDEV_U0);
@@ -1355,6 +1355,35 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
1355 return 0; 1355 return 0;
1356} 1356}
1357 1357
1358/*
1359 * Workaround for missing Cold Attach Status (CAS) if device re-plugged in S3.
1360 * warm reset a USB3 device stuck in polling or compliance mode after resume.
1361 * See Intel 100/c230 series PCH specification update Doc #332692-006 Errata #8
1362 */
1363static bool xhci_port_missing_cas_quirk(int port_index,
1364 __le32 __iomem **port_array)
1365{
1366 u32 portsc;
1367
1368 portsc = readl(port_array[port_index]);
1369
1370 /* if any of these are set we are not stuck */
1371 if (portsc & (PORT_CONNECT | PORT_CAS))
1372 return false;
1373
1374 if (((portsc & PORT_PLS_MASK) != XDEV_POLLING) &&
1375 ((portsc & PORT_PLS_MASK) != XDEV_COMP_MODE))
1376 return false;
1377
1378 /* clear wakeup/change bits, and do a warm port reset */
1379 portsc &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
1380 portsc |= PORT_WR;
1381 writel(portsc, port_array[port_index]);
1382 /* flush write */
1383 readl(port_array[port_index]);
1384 return true;
1385}
1386
1358int xhci_bus_resume(struct usb_hcd *hcd) 1387int xhci_bus_resume(struct usb_hcd *hcd)
1359{ 1388{
1360 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1389 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
@@ -1392,6 +1421,14 @@ int xhci_bus_resume(struct usb_hcd *hcd)
1392 u32 temp; 1421 u32 temp;
1393 1422
1394 temp = readl(port_array[port_index]); 1423 temp = readl(port_array[port_index]);
1424
1425 /* warm reset CAS limited ports stuck in polling/compliance */
1426 if ((xhci->quirks & XHCI_MISSING_CAS) &&
1427 (hcd->speed >= HCD_USB3) &&
1428 xhci_port_missing_cas_quirk(port_index, port_array)) {
1429 xhci_dbg(xhci, "reset stuck port %d\n", port_index);
1430 continue;
1431 }
1395 if (DEV_SUPERSPEED_ANY(temp)) 1432 if (DEV_SUPERSPEED_ANY(temp))
1396 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); 1433 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
1397 else 1434 else
@@ -1410,7 +1447,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
1410 1447
1411 if (need_usb2_u3_exit) { 1448 if (need_usb2_u3_exit) {
1412 spin_unlock_irqrestore(&xhci->lock, flags); 1449 spin_unlock_irqrestore(&xhci->lock, flags);
1413 msleep(20); 1450 msleep(USB_RESUME_TIMEOUT);
1414 spin_lock_irqsave(&xhci->lock, flags); 1451 spin_lock_irqsave(&xhci->lock, flags);
1415 } 1452 }
1416 1453
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index d7b0f97abbad..e96ae80d107e 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -45,11 +45,13 @@
45 45
46#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31 46#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31
47#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 47#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
48#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI 0x9cb1
48#define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5 49#define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5
49#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f 50#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f
50#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI 0x9d2f 51#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI 0x9d2f
51#define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI 0x0aa8 52#define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI 0x0aa8
52#define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8 53#define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8
54#define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8
53 55
54static const char hcd_name[] = "xhci_hcd"; 56static const char hcd_name[] = "xhci_hcd";
55 57
@@ -153,7 +155,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
153 xhci->quirks |= XHCI_SPURIOUS_REBOOT; 155 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
154 } 156 }
155 if (pdev->vendor == PCI_VENDOR_ID_INTEL && 157 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
156 pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI) { 158 (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI ||
159 pdev->device == PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI)) {
157 xhci->quirks |= XHCI_SPURIOUS_REBOOT; 160 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
158 xhci->quirks |= XHCI_SPURIOUS_WAKEUP; 161 xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
159 } 162 }
@@ -169,6 +172,11 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
169 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI) { 172 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI) {
170 xhci->quirks |= XHCI_SSIC_PORT_UNUSED; 173 xhci->quirks |= XHCI_SSIC_PORT_UNUSED;
171 } 174 }
175 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
176 (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
177 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI))
178 xhci->quirks |= XHCI_MISSING_CAS;
179
172 if (pdev->vendor == PCI_VENDOR_ID_ETRON && 180 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
173 pdev->device == PCI_DEVICE_ID_EJ168) { 181 pdev->device == PCI_DEVICE_ID_EJ168) {
174 xhci->quirks |= XHCI_RESET_ON_RESUME; 182 xhci->quirks |= XHCI_RESET_ON_RESUME;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index b2c1dc5dc0f3..f945380035d0 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -314,6 +314,8 @@ struct xhci_op_regs {
314#define XDEV_U2 (0x2 << 5) 314#define XDEV_U2 (0x2 << 5)
315#define XDEV_U3 (0x3 << 5) 315#define XDEV_U3 (0x3 << 5)
316#define XDEV_INACTIVE (0x6 << 5) 316#define XDEV_INACTIVE (0x6 << 5)
317#define XDEV_POLLING (0x7 << 5)
318#define XDEV_COMP_MODE (0xa << 5)
317#define XDEV_RESUME (0xf << 5) 319#define XDEV_RESUME (0xf << 5)
318/* true: port has power (see HCC_PPC) */ 320/* true: port has power (see HCC_PPC) */
319#define PORT_POWER (1 << 9) 321#define PORT_POWER (1 << 9)
@@ -1653,6 +1655,7 @@ struct xhci_hcd {
1653#define XHCI_MTK_HOST (1 << 21) 1655#define XHCI_MTK_HOST (1 << 21)
1654#define XHCI_SSIC_PORT_UNUSED (1 << 22) 1656#define XHCI_SSIC_PORT_UNUSED (1 << 22)
1655#define XHCI_NO_64BIT_SUPPORT (1 << 23) 1657#define XHCI_NO_64BIT_SUPPORT (1 << 23)
1658#define XHCI_MISSING_CAS (1 << 24)
1656 unsigned int num_active_eps; 1659 unsigned int num_active_eps;
1657 unsigned int limit_active_eps; 1660 unsigned int limit_active_eps;
1658 /* There are two roothubs to keep track of bus suspend info for */ 1661 /* There are two roothubs to keep track of bus suspend info for */
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index bff4869a57cd..4042ea017985 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1255,6 +1255,7 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1255 1255
1256 map_dma_buffer(request, musb, musb_ep); 1256 map_dma_buffer(request, musb, musb_ep);
1257 1257
1258 pm_runtime_get_sync(musb->controller);
1258 spin_lock_irqsave(&musb->lock, lockflags); 1259 spin_lock_irqsave(&musb->lock, lockflags);
1259 1260
1260 /* don't queue if the ep is down */ 1261 /* don't queue if the ep is down */
@@ -1275,6 +1276,9 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1275 1276
1276unlock: 1277unlock:
1277 spin_unlock_irqrestore(&musb->lock, lockflags); 1278 spin_unlock_irqrestore(&musb->lock, lockflags);
1279 pm_runtime_mark_last_busy(musb->controller);
1280 pm_runtime_put_autosuspend(musb->controller);
1281
1278 return status; 1282 return status;
1279} 1283}
1280 1284
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 1ab6973d4f61..cc1225485509 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -287,6 +287,7 @@ static int omap2430_musb_init(struct musb *musb)
287 } 287 }
288 musb->isr = omap2430_musb_interrupt; 288 musb->isr = omap2430_musb_interrupt;
289 phy_init(musb->phy); 289 phy_init(musb->phy);
290 phy_power_on(musb->phy);
290 291
291 l = musb_readl(musb->mregs, OTG_INTERFSEL); 292 l = musb_readl(musb->mregs, OTG_INTERFSEL);
292 293
@@ -323,8 +324,6 @@ static void omap2430_musb_enable(struct musb *musb)
323 struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev); 324 struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
324 struct omap_musb_board_data *data = pdata->board_data; 325 struct omap_musb_board_data *data = pdata->board_data;
325 326
326 if (!WARN_ON(!musb->phy))
327 phy_power_on(musb->phy);
328 327
329 switch (glue->status) { 328 switch (glue->status) {
330 329
@@ -361,9 +360,6 @@ static void omap2430_musb_disable(struct musb *musb)
361 struct device *dev = musb->controller; 360 struct device *dev = musb->controller;
362 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 361 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
363 362
364 if (!WARN_ON(!musb->phy))
365 phy_power_off(musb->phy);
366
367 if (glue->status != MUSB_UNKNOWN) 363 if (glue->status != MUSB_UNKNOWN)
368 omap_control_usb_set_mode(glue->control_otghs, 364 omap_control_usb_set_mode(glue->control_otghs,
369 USB_MODE_DISCONNECT); 365 USB_MODE_DISCONNECT);
@@ -375,6 +371,7 @@ static int omap2430_musb_exit(struct musb *musb)
375 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 371 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
376 372
377 omap2430_low_level_exit(musb); 373 omap2430_low_level_exit(musb);
374 phy_power_off(musb->phy);
378 phy_exit(musb->phy); 375 phy_exit(musb->phy);
379 musb->phy = NULL; 376 musb->phy = NULL;
380 cancel_work_sync(&glue->omap_musb_mailbox_work); 377 cancel_work_sync(&glue->omap_musb_mailbox_work);
diff --git a/drivers/usb/renesas_usbhs/rcar3.c b/drivers/usb/renesas_usbhs/rcar3.c
index 1d70add926f0..d544b331c9f2 100644
--- a/drivers/usb/renesas_usbhs/rcar3.c
+++ b/drivers/usb/renesas_usbhs/rcar3.c
@@ -9,6 +9,7 @@
9 * 9 *
10 */ 10 */
11 11
12#include <linux/delay.h>
12#include <linux/io.h> 13#include <linux/io.h>
13#include "common.h" 14#include "common.h"
14#include "rcar3.h" 15#include "rcar3.h"
@@ -35,10 +36,13 @@ static int usbhs_rcar3_power_ctrl(struct platform_device *pdev,
35 36
36 usbhs_write32(priv, UGCTRL2, UGCTRL2_RESERVED_3 | UGCTRL2_USB0SEL_OTG); 37 usbhs_write32(priv, UGCTRL2, UGCTRL2_RESERVED_3 | UGCTRL2_USB0SEL_OTG);
37 38
38 if (enable) 39 if (enable) {
39 usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM); 40 usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM);
40 else 41 /* The controller on R-Car Gen3 needs to wait up to 45 usec */
42 udelay(45);
43 } else {
41 usbhs_bset(priv, LPSTS, LPSTS_SUSPM, 0); 44 usbhs_bset(priv, LPSTS, LPSTS_SUSPM, 0);
45 }
42 46
43 return 0; 47 return 0;
44} 48}
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 54a4de0efdba..f61477bed3a8 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1077,7 +1077,9 @@ static int cp210x_tiocmget(struct tty_struct *tty)
1077 u8 control; 1077 u8 control;
1078 int result; 1078 int result;
1079 1079
1080 cp210x_read_u8_reg(port, CP210X_GET_MDMSTS, &control); 1080 result = cp210x_read_u8_reg(port, CP210X_GET_MDMSTS, &control);
1081 if (result)
1082 return result;
1081 1083
1082 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) 1084 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
1083 |((control & CONTROL_RTS) ? TIOCM_RTS : 0) 1085 |((control & CONTROL_RTS) ? TIOCM_RTS : 0)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index b2d767e743fc..0ff7f38d7800 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -986,7 +986,8 @@ static const struct usb_device_id id_table_combined[] = {
986 /* ekey Devices */ 986 /* ekey Devices */
987 { USB_DEVICE(FTDI_VID, FTDI_EKEY_CONV_USB_PID) }, 987 { USB_DEVICE(FTDI_VID, FTDI_EKEY_CONV_USB_PID) },
988 /* Infineon Devices */ 988 /* Infineon Devices */
989 { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, INFINEON_TRIBOARD_PID, 1) }, 989 { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, INFINEON_TRIBOARD_TC1798_PID, 1) },
990 { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, INFINEON_TRIBOARD_TC2X7_PID, 1) },
990 /* GE Healthcare devices */ 991 /* GE Healthcare devices */
991 { USB_DEVICE(GE_HEALTHCARE_VID, GE_HEALTHCARE_NEMO_TRACKER_PID) }, 992 { USB_DEVICE(GE_HEALTHCARE_VID, GE_HEALTHCARE_NEMO_TRACKER_PID) },
992 /* Active Research (Actisense) devices */ 993 /* Active Research (Actisense) devices */
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index f87a938cf005..21011c0a4c64 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -626,8 +626,9 @@
626/* 626/*
627 * Infineon Technologies 627 * Infineon Technologies
628 */ 628 */
629#define INFINEON_VID 0x058b 629#define INFINEON_VID 0x058b
630#define INFINEON_TRIBOARD_PID 0x0028 /* DAS JTAG TriBoard TC1798 V1.0 */ 630#define INFINEON_TRIBOARD_TC1798_PID 0x0028 /* DAS JTAG TriBoard TC1798 V1.0 */
631#define INFINEON_TRIBOARD_TC2X7_PID 0x0043 /* DAS JTAG TriBoard TC2X7 V1.0 */
631 632
632/* 633/*
633 * Acton Research Corp. 634 * Acton Research Corp.
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index d213cf44a7e4..4a037b4a79cf 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1078,7 +1078,8 @@ static int usb_serial_probe(struct usb_interface *interface,
1078 1078
1079 serial->disconnected = 0; 1079 serial->disconnected = 0;
1080 1080
1081 usb_serial_console_init(serial->port[0]->minor); 1081 if (num_ports > 0)
1082 usb_serial_console_init(serial->port[0]->minor);
1082exit: 1083exit:
1083 module_put(type->driver.owner); 1084 module_put(type->driver.owner);
1084 return 0; 1085 return 0;
diff --git a/drivers/usb/wusbcore/crypto.c b/drivers/usb/wusbcore/crypto.c
index 79b2b628066d..79451f7ef1b7 100644
--- a/drivers/usb/wusbcore/crypto.c
+++ b/drivers/usb/wusbcore/crypto.c
@@ -133,6 +133,13 @@ static void bytewise_xor(void *_bo, const void *_bi1, const void *_bi2,
133 bo[itr] = bi1[itr] ^ bi2[itr]; 133 bo[itr] = bi1[itr] ^ bi2[itr];
134} 134}
135 135
136/* Scratch space for MAC calculations. */
137struct wusb_mac_scratch {
138 struct aes_ccm_b0 b0;
139 struct aes_ccm_b1 b1;
140 struct aes_ccm_a ax;
141};
142
136/* 143/*
137 * CC-MAC function WUSB1.0[6.5] 144 * CC-MAC function WUSB1.0[6.5]
138 * 145 *
@@ -197,16 +204,15 @@ static void bytewise_xor(void *_bo, const void *_bi1, const void *_bi2,
197 * what sg[4] is for. Maybe there is a smarter way to do this. 204 * what sg[4] is for. Maybe there is a smarter way to do this.
198 */ 205 */
199static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc, 206static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
200 struct crypto_cipher *tfm_aes, void *mic, 207 struct crypto_cipher *tfm_aes,
208 struct wusb_mac_scratch *scratch,
209 void *mic,
201 const struct aes_ccm_nonce *n, 210 const struct aes_ccm_nonce *n,
202 const struct aes_ccm_label *a, const void *b, 211 const struct aes_ccm_label *a, const void *b,
203 size_t blen) 212 size_t blen)
204{ 213{
205 int result = 0; 214 int result = 0;
206 SKCIPHER_REQUEST_ON_STACK(req, tfm_cbc); 215 SKCIPHER_REQUEST_ON_STACK(req, tfm_cbc);
207 struct aes_ccm_b0 b0;
208 struct aes_ccm_b1 b1;
209 struct aes_ccm_a ax;
210 struct scatterlist sg[4], sg_dst; 216 struct scatterlist sg[4], sg_dst;
211 void *dst_buf; 217 void *dst_buf;
212 size_t dst_size; 218 size_t dst_size;
@@ -218,16 +224,17 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
218 * These checks should be compile time optimized out 224 * These checks should be compile time optimized out
219 * ensure @a fills b1's mac_header and following fields 225 * ensure @a fills b1's mac_header and following fields
220 */ 226 */
221 WARN_ON(sizeof(*a) != sizeof(b1) - sizeof(b1.la)); 227 WARN_ON(sizeof(*a) != sizeof(scratch->b1) - sizeof(scratch->b1.la));
222 WARN_ON(sizeof(b0) != sizeof(struct aes_ccm_block)); 228 WARN_ON(sizeof(scratch->b0) != sizeof(struct aes_ccm_block));
223 WARN_ON(sizeof(b1) != sizeof(struct aes_ccm_block)); 229 WARN_ON(sizeof(scratch->b1) != sizeof(struct aes_ccm_block));
224 WARN_ON(sizeof(ax) != sizeof(struct aes_ccm_block)); 230 WARN_ON(sizeof(scratch->ax) != sizeof(struct aes_ccm_block));
225 231
226 result = -ENOMEM; 232 result = -ENOMEM;
227 zero_padding = blen % sizeof(struct aes_ccm_block); 233 zero_padding = blen % sizeof(struct aes_ccm_block);
228 if (zero_padding) 234 if (zero_padding)
229 zero_padding = sizeof(struct aes_ccm_block) - zero_padding; 235 zero_padding = sizeof(struct aes_ccm_block) - zero_padding;
230 dst_size = blen + sizeof(b0) + sizeof(b1) + zero_padding; 236 dst_size = blen + sizeof(scratch->b0) + sizeof(scratch->b1) +
237 zero_padding;
231 dst_buf = kzalloc(dst_size, GFP_KERNEL); 238 dst_buf = kzalloc(dst_size, GFP_KERNEL);
232 if (!dst_buf) 239 if (!dst_buf)
233 goto error_dst_buf; 240 goto error_dst_buf;
@@ -235,9 +242,9 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
235 memset(iv, 0, sizeof(iv)); 242 memset(iv, 0, sizeof(iv));
236 243
237 /* Setup B0 */ 244 /* Setup B0 */
238 b0.flags = 0x59; /* Format B0 */ 245 scratch->b0.flags = 0x59; /* Format B0 */
239 b0.ccm_nonce = *n; 246 scratch->b0.ccm_nonce = *n;
240 b0.lm = cpu_to_be16(0); /* WUSB1.0[6.5] sez l(m) is 0 */ 247 scratch->b0.lm = cpu_to_be16(0); /* WUSB1.0[6.5] sez l(m) is 0 */
241 248
242 /* Setup B1 249 /* Setup B1
243 * 250 *
@@ -246,12 +253,12 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
246 * 14'--after clarification, it means to use A's contents 253 * 14'--after clarification, it means to use A's contents
247 * for MAC Header, EO, sec reserved and padding. 254 * for MAC Header, EO, sec reserved and padding.
248 */ 255 */
249 b1.la = cpu_to_be16(blen + 14); 256 scratch->b1.la = cpu_to_be16(blen + 14);
250 memcpy(&b1.mac_header, a, sizeof(*a)); 257 memcpy(&scratch->b1.mac_header, a, sizeof(*a));
251 258
252 sg_init_table(sg, ARRAY_SIZE(sg)); 259 sg_init_table(sg, ARRAY_SIZE(sg));
253 sg_set_buf(&sg[0], &b0, sizeof(b0)); 260 sg_set_buf(&sg[0], &scratch->b0, sizeof(scratch->b0));
254 sg_set_buf(&sg[1], &b1, sizeof(b1)); 261 sg_set_buf(&sg[1], &scratch->b1, sizeof(scratch->b1));
255 sg_set_buf(&sg[2], b, blen); 262 sg_set_buf(&sg[2], b, blen);
256 /* 0 if well behaved :) */ 263 /* 0 if well behaved :) */
257 sg_set_buf(&sg[3], bzero, zero_padding); 264 sg_set_buf(&sg[3], bzero, zero_padding);
@@ -276,11 +283,12 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
276 * POS Crypto API: size is assumed to be AES's block size. 283 * POS Crypto API: size is assumed to be AES's block size.
277 * Thanks for documenting it -- tip taken from airo.c 284 * Thanks for documenting it -- tip taken from airo.c
278 */ 285 */
279 ax.flags = 0x01; /* as per WUSB 1.0 spec */ 286 scratch->ax.flags = 0x01; /* as per WUSB 1.0 spec */
280 ax.ccm_nonce = *n; 287 scratch->ax.ccm_nonce = *n;
281 ax.counter = 0; 288 scratch->ax.counter = 0;
282 crypto_cipher_encrypt_one(tfm_aes, (void *)&ax, (void *)&ax); 289 crypto_cipher_encrypt_one(tfm_aes, (void *)&scratch->ax,
283 bytewise_xor(mic, &ax, iv, 8); 290 (void *)&scratch->ax);
291 bytewise_xor(mic, &scratch->ax, iv, 8);
284 result = 8; 292 result = 8;
285error_cbc_crypt: 293error_cbc_crypt:
286 kfree(dst_buf); 294 kfree(dst_buf);
@@ -303,6 +311,7 @@ ssize_t wusb_prf(void *out, size_t out_size,
303 struct aes_ccm_nonce n = *_n; 311 struct aes_ccm_nonce n = *_n;
304 struct crypto_skcipher *tfm_cbc; 312 struct crypto_skcipher *tfm_cbc;
305 struct crypto_cipher *tfm_aes; 313 struct crypto_cipher *tfm_aes;
314 struct wusb_mac_scratch *scratch;
306 u64 sfn = 0; 315 u64 sfn = 0;
307 __le64 sfn_le; 316 __le64 sfn_le;
308 317
@@ -329,17 +338,25 @@ ssize_t wusb_prf(void *out, size_t out_size,
329 printk(KERN_ERR "E: can't set AES key: %d\n", (int)result); 338 printk(KERN_ERR "E: can't set AES key: %d\n", (int)result);
330 goto error_setkey_aes; 339 goto error_setkey_aes;
331 } 340 }
341 scratch = kmalloc(sizeof(*scratch), GFP_KERNEL);
342 if (!scratch) {
343 result = -ENOMEM;
344 goto error_alloc_scratch;
345 }
332 346
333 for (bitr = 0; bitr < (len + 63) / 64; bitr++) { 347 for (bitr = 0; bitr < (len + 63) / 64; bitr++) {
334 sfn_le = cpu_to_le64(sfn++); 348 sfn_le = cpu_to_le64(sfn++);
335 memcpy(&n.sfn, &sfn_le, sizeof(n.sfn)); /* n.sfn++... */ 349 memcpy(&n.sfn, &sfn_le, sizeof(n.sfn)); /* n.sfn++... */
336 result = wusb_ccm_mac(tfm_cbc, tfm_aes, out + bytes, 350 result = wusb_ccm_mac(tfm_cbc, tfm_aes, scratch, out + bytes,
337 &n, a, b, blen); 351 &n, a, b, blen);
338 if (result < 0) 352 if (result < 0)
339 goto error_ccm_mac; 353 goto error_ccm_mac;
340 bytes += result; 354 bytes += result;
341 } 355 }
342 result = bytes; 356 result = bytes;
357
358 kfree(scratch);
359error_alloc_scratch:
343error_ccm_mac: 360error_ccm_mac:
344error_setkey_aes: 361error_setkey_aes:
345 crypto_free_cipher(tfm_aes); 362 crypto_free_cipher(tfm_aes);
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index e12bd3635f83..26e5e8507f03 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -168,7 +168,9 @@ out:
168#endif /* CONFIG_HIBERNATE_CALLBACKS */ 168#endif /* CONFIG_HIBERNATE_CALLBACKS */
169 169
170struct shutdown_handler { 170struct shutdown_handler {
171 const char *command; 171#define SHUTDOWN_CMD_SIZE 11
172 const char command[SHUTDOWN_CMD_SIZE];
173 bool flag;
172 void (*cb)(void); 174 void (*cb)(void);
173}; 175};
174 176
@@ -206,22 +208,22 @@ static void do_reboot(void)
206 ctrl_alt_del(); 208 ctrl_alt_del();
207} 209}
208 210
211static struct shutdown_handler shutdown_handlers[] = {
212 { "poweroff", true, do_poweroff },
213 { "halt", false, do_poweroff },
214 { "reboot", true, do_reboot },
215#ifdef CONFIG_HIBERNATE_CALLBACKS
216 { "suspend", true, do_suspend },
217#endif
218};
219
209static void shutdown_handler(struct xenbus_watch *watch, 220static void shutdown_handler(struct xenbus_watch *watch,
210 const char **vec, unsigned int len) 221 const char **vec, unsigned int len)
211{ 222{
212 char *str; 223 char *str;
213 struct xenbus_transaction xbt; 224 struct xenbus_transaction xbt;
214 int err; 225 int err;
215 static struct shutdown_handler handlers[] = { 226 int idx;
216 { "poweroff", do_poweroff },
217 { "halt", do_poweroff },
218 { "reboot", do_reboot },
219#ifdef CONFIG_HIBERNATE_CALLBACKS
220 { "suspend", do_suspend },
221#endif
222 {NULL, NULL},
223 };
224 static struct shutdown_handler *handler;
225 227
226 if (shutting_down != SHUTDOWN_INVALID) 228 if (shutting_down != SHUTDOWN_INVALID)
227 return; 229 return;
@@ -238,13 +240,13 @@ static void shutdown_handler(struct xenbus_watch *watch,
238 return; 240 return;
239 } 241 }
240 242
241 for (handler = &handlers[0]; handler->command; handler++) { 243 for (idx = 0; idx < ARRAY_SIZE(shutdown_handlers); idx++) {
242 if (strcmp(str, handler->command) == 0) 244 if (strcmp(str, shutdown_handlers[idx].command) == 0)
243 break; 245 break;
244 } 246 }
245 247
246 /* Only acknowledge commands which we are prepared to handle. */ 248 /* Only acknowledge commands which we are prepared to handle. */
247 if (handler->cb) 249 if (idx < ARRAY_SIZE(shutdown_handlers))
248 xenbus_write(xbt, "control", "shutdown", ""); 250 xenbus_write(xbt, "control", "shutdown", "");
249 251
250 err = xenbus_transaction_end(xbt, 0); 252 err = xenbus_transaction_end(xbt, 0);
@@ -253,8 +255,8 @@ static void shutdown_handler(struct xenbus_watch *watch,
253 goto again; 255 goto again;
254 } 256 }
255 257
256 if (handler->cb) { 258 if (idx < ARRAY_SIZE(shutdown_handlers)) {
257 handler->cb(); 259 shutdown_handlers[idx].cb();
258 } else { 260 } else {
259 pr_info("Ignoring shutdown request: %s\n", str); 261 pr_info("Ignoring shutdown request: %s\n", str);
260 shutting_down = SHUTDOWN_INVALID; 262 shutting_down = SHUTDOWN_INVALID;
@@ -310,6 +312,9 @@ static struct notifier_block xen_reboot_nb = {
310static int setup_shutdown_watcher(void) 312static int setup_shutdown_watcher(void)
311{ 313{
312 int err; 314 int err;
315 int idx;
316#define FEATURE_PATH_SIZE (SHUTDOWN_CMD_SIZE + sizeof("feature-"))
317 char node[FEATURE_PATH_SIZE];
313 318
314 err = register_xenbus_watch(&shutdown_watch); 319 err = register_xenbus_watch(&shutdown_watch);
315 if (err) { 320 if (err) {
@@ -326,6 +331,14 @@ static int setup_shutdown_watcher(void)
326 } 331 }
327#endif 332#endif
328 333
334 for (idx = 0; idx < ARRAY_SIZE(shutdown_handlers); idx++) {
335 if (!shutdown_handlers[idx].flag)
336 continue;
337 snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
338 shutdown_handlers[idx].command);
339 xenbus_printf(XBT_NIL, "control", node, "%u", 1);
340 }
341
329 return 0; 342 return 0;
330} 343}
331 344
diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
index c1010f018bd8..1e8be12ebb55 100644
--- a/drivers/xen/xenbus/xenbus_dev_frontend.c
+++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
@@ -364,7 +364,7 @@ out:
364 364
365static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u) 365static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
366{ 366{
367 struct watch_adapter *watch, *tmp_watch; 367 struct watch_adapter *watch;
368 char *path, *token; 368 char *path, *token;
369 int err, rc; 369 int err, rc;
370 LIST_HEAD(staging_q); 370 LIST_HEAD(staging_q);
@@ -399,7 +399,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
399 } 399 }
400 list_add(&watch->list, &u->watches); 400 list_add(&watch->list, &u->watches);
401 } else { 401 } else {
402 list_for_each_entry_safe(watch, tmp_watch, &u->watches, list) { 402 list_for_each_entry(watch, &u->watches, list) {
403 if (!strcmp(watch->token, token) && 403 if (!strcmp(watch->token, token) &&
404 !strcmp(watch->watch.node, path)) { 404 !strcmp(watch->watch.node, path)) {
405 unregister_xenbus_watch(&watch->watch); 405 unregister_xenbus_watch(&watch->watch);
diff --git a/drivers/xen/xenbus/xenbus_probe_frontend.c b/drivers/xen/xenbus/xenbus_probe_frontend.c
index 611a23119675..6d40a972ffb2 100644
--- a/drivers/xen/xenbus/xenbus_probe_frontend.c
+++ b/drivers/xen/xenbus/xenbus_probe_frontend.c
@@ -335,7 +335,9 @@ static int backend_state;
335static void xenbus_reset_backend_state_changed(struct xenbus_watch *w, 335static void xenbus_reset_backend_state_changed(struct xenbus_watch *w,
336 const char **v, unsigned int l) 336 const char **v, unsigned int l)
337{ 337{
338 xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", &backend_state); 338 if (xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i",
339 &backend_state) != 1)
340 backend_state = XenbusStateUnknown;
339 printk(KERN_DEBUG "XENBUS: backend %s %s\n", 341 printk(KERN_DEBUG "XENBUS: backend %s %s\n",
340 v[XS_WATCH_PATH], xenbus_strstate(backend_state)); 342 v[XS_WATCH_PATH], xenbus_strstate(backend_state));
341 wake_up(&backend_state_wq); 343 wake_up(&backend_state_wq);
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 01bc36cec26e..71261b459863 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -5805,6 +5805,64 @@ static int changed_extent(struct send_ctx *sctx,
5805 int ret = 0; 5805 int ret = 0;
5806 5806
5807 if (sctx->cur_ino != sctx->cmp_key->objectid) { 5807 if (sctx->cur_ino != sctx->cmp_key->objectid) {
5808
5809 if (result == BTRFS_COMPARE_TREE_CHANGED) {
5810 struct extent_buffer *leaf_l;
5811 struct extent_buffer *leaf_r;
5812 struct btrfs_file_extent_item *ei_l;
5813 struct btrfs_file_extent_item *ei_r;
5814
5815 leaf_l = sctx->left_path->nodes[0];
5816 leaf_r = sctx->right_path->nodes[0];
5817 ei_l = btrfs_item_ptr(leaf_l,
5818 sctx->left_path->slots[0],
5819 struct btrfs_file_extent_item);
5820 ei_r = btrfs_item_ptr(leaf_r,
5821 sctx->right_path->slots[0],
5822 struct btrfs_file_extent_item);
5823
5824 /*
5825 * We may have found an extent item that has changed
5826 * only its disk_bytenr field and the corresponding
5827 * inode item was not updated. This case happens due to
5828 * very specific timings during relocation when a leaf
5829 * that contains file extent items is COWed while
5830 * relocation is ongoing and its in the stage where it
5831 * updates data pointers. So when this happens we can
5832 * safely ignore it since we know it's the same extent,
5833 * but just at different logical and physical locations
5834 * (when an extent is fully replaced with a new one, we
5835 * know the generation number must have changed too,
5836 * since snapshot creation implies committing the current
5837 * transaction, and the inode item must have been updated
5838 * as well).
5839 * This replacement of the disk_bytenr happens at
5840 * relocation.c:replace_file_extents() through
5841 * relocation.c:btrfs_reloc_cow_block().
5842 */
5843 if (btrfs_file_extent_generation(leaf_l, ei_l) ==
5844 btrfs_file_extent_generation(leaf_r, ei_r) &&
5845 btrfs_file_extent_ram_bytes(leaf_l, ei_l) ==
5846 btrfs_file_extent_ram_bytes(leaf_r, ei_r) &&
5847 btrfs_file_extent_compression(leaf_l, ei_l) ==
5848 btrfs_file_extent_compression(leaf_r, ei_r) &&
5849 btrfs_file_extent_encryption(leaf_l, ei_l) ==
5850 btrfs_file_extent_encryption(leaf_r, ei_r) &&
5851 btrfs_file_extent_other_encoding(leaf_l, ei_l) ==
5852 btrfs_file_extent_other_encoding(leaf_r, ei_r) &&
5853 btrfs_file_extent_type(leaf_l, ei_l) ==
5854 btrfs_file_extent_type(leaf_r, ei_r) &&
5855 btrfs_file_extent_disk_bytenr(leaf_l, ei_l) !=
5856 btrfs_file_extent_disk_bytenr(leaf_r, ei_r) &&
5857 btrfs_file_extent_disk_num_bytes(leaf_l, ei_l) ==
5858 btrfs_file_extent_disk_num_bytes(leaf_r, ei_r) &&
5859 btrfs_file_extent_offset(leaf_l, ei_l) ==
5860 btrfs_file_extent_offset(leaf_r, ei_r) &&
5861 btrfs_file_extent_num_bytes(leaf_l, ei_l) ==
5862 btrfs_file_extent_num_bytes(leaf_r, ei_r))
5863 return 0;
5864 }
5865
5808 inconsistent_snapshot_error(sctx, result, "extent"); 5866 inconsistent_snapshot_error(sctx, result, "extent");
5809 return -EIO; 5867 return -EIO;
5810 } 5868 }
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 528cae123dc9..3d33c4e41e5f 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2713,14 +2713,12 @@ static inline void btrfs_remove_all_log_ctxs(struct btrfs_root *root,
2713 int index, int error) 2713 int index, int error)
2714{ 2714{
2715 struct btrfs_log_ctx *ctx; 2715 struct btrfs_log_ctx *ctx;
2716 struct btrfs_log_ctx *safe;
2716 2717
2717 if (!error) { 2718 list_for_each_entry_safe(ctx, safe, &root->log_ctxs[index], list) {
2718 INIT_LIST_HEAD(&root->log_ctxs[index]); 2719 list_del_init(&ctx->list);
2719 return;
2720 }
2721
2722 list_for_each_entry(ctx, &root->log_ctxs[index], list)
2723 ctx->log_ret = error; 2720 ctx->log_ret = error;
2721 }
2724 2722
2725 INIT_LIST_HEAD(&root->log_ctxs[index]); 2723 INIT_LIST_HEAD(&root->log_ctxs[index]);
2726} 2724}
@@ -2961,13 +2959,9 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2961 mutex_unlock(&root->log_mutex); 2959 mutex_unlock(&root->log_mutex);
2962 2960
2963out_wake_log_root: 2961out_wake_log_root:
2964 /* 2962 mutex_lock(&log_root_tree->log_mutex);
2965 * We needn't get log_mutex here because we are sure all
2966 * the other tasks are blocked.
2967 */
2968 btrfs_remove_all_log_ctxs(log_root_tree, index2, ret); 2963 btrfs_remove_all_log_ctxs(log_root_tree, index2, ret);
2969 2964
2970 mutex_lock(&log_root_tree->log_mutex);
2971 log_root_tree->log_transid_committed++; 2965 log_root_tree->log_transid_committed++;
2972 atomic_set(&log_root_tree->log_commit[index2], 0); 2966 atomic_set(&log_root_tree->log_commit[index2], 0);
2973 mutex_unlock(&log_root_tree->log_mutex); 2967 mutex_unlock(&log_root_tree->log_mutex);
@@ -2978,10 +2972,8 @@ out_wake_log_root:
2978 if (waitqueue_active(&log_root_tree->log_commit_wait[index2])) 2972 if (waitqueue_active(&log_root_tree->log_commit_wait[index2]))
2979 wake_up(&log_root_tree->log_commit_wait[index2]); 2973 wake_up(&log_root_tree->log_commit_wait[index2]);
2980out: 2974out:
2981 /* See above. */
2982 btrfs_remove_all_log_ctxs(root, index1, ret);
2983
2984 mutex_lock(&root->log_mutex); 2975 mutex_lock(&root->log_mutex);
2976 btrfs_remove_all_log_ctxs(root, index1, ret);
2985 root->log_transid_committed++; 2977 root->log_transid_committed++;
2986 atomic_set(&root->log_commit[index1], 0); 2978 atomic_set(&root->log_commit[index1], 0);
2987 mutex_unlock(&root->log_mutex); 2979 mutex_unlock(&root->log_mutex);
diff --git a/fs/exofs/dir.c b/fs/exofs/dir.c
index 79101651fe9e..42f9a0a0c4ca 100644
--- a/fs/exofs/dir.c
+++ b/fs/exofs/dir.c
@@ -137,7 +137,7 @@ Espan:
137bad_entry: 137bad_entry:
138 EXOFS_ERR( 138 EXOFS_ERR(
139 "ERROR [exofs_check_page]: bad entry in directory(0x%lx): %s - " 139 "ERROR [exofs_check_page]: bad entry in directory(0x%lx): %s - "
140 "offset=%lu, inode=0x%llu, rec_len=%d, name_len=%d\n", 140 "offset=%lu, inode=0x%llx, rec_len=%d, name_len=%d\n",
141 dir->i_ino, error, (page->index<<PAGE_SHIFT)+offs, 141 dir->i_ino, error, (page->index<<PAGE_SHIFT)+offs,
142 _LLU(le64_to_cpu(p->inode_no)), 142 _LLU(le64_to_cpu(p->inode_no)),
143 rec_len, p->name_len); 143 rec_len, p->name_len);
diff --git a/fs/iomap.c b/fs/iomap.c
index 013d1d36fbbf..a8ee8c33ca78 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -433,8 +433,7 @@ iomap_page_mkwrite_actor(struct inode *inode, loff_t pos, loff_t length,
433 struct page *page = data; 433 struct page *page = data;
434 int ret; 434 int ret;
435 435
436 ret = __block_write_begin_int(page, pos & ~PAGE_MASK, length, 436 ret = __block_write_begin_int(page, pos, length, NULL, iomap);
437 NULL, iomap);
438 if (ret) 437 if (ret)
439 return ret; 438 return ret;
440 439
@@ -561,7 +560,7 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi,
561 } 560 }
562 561
563 while (len > 0) { 562 while (len > 0) {
564 ret = iomap_apply(inode, start, len, 0, ops, &ctx, 563 ret = iomap_apply(inode, start, len, IOMAP_REPORT, ops, &ctx,
565 iomap_fiemap_actor); 564 iomap_fiemap_actor);
566 /* inode with no (attribute) mapping will give ENOENT */ 565 /* inode with no (attribute) mapping will give ENOENT */
567 if (ret == -ENOENT) 566 if (ret == -ENOENT)
diff --git a/fs/orangefs/dcache.c b/fs/orangefs/dcache.c
index 1e8fe844e69f..5355efba4bc8 100644
--- a/fs/orangefs/dcache.c
+++ b/fs/orangefs/dcache.c
@@ -73,7 +73,7 @@ static int orangefs_revalidate_lookup(struct dentry *dentry)
73 } 73 }
74 } 74 }
75 75
76 dentry->d_time = jiffies + orangefs_dcache_timeout_msecs*HZ/1000; 76 orangefs_set_timeout(dentry);
77 ret = 1; 77 ret = 1;
78out_release_op: 78out_release_op:
79 op_release(new_op); 79 op_release(new_op);
@@ -94,8 +94,9 @@ out_drop:
94static int orangefs_d_revalidate(struct dentry *dentry, unsigned int flags) 94static int orangefs_d_revalidate(struct dentry *dentry, unsigned int flags)
95{ 95{
96 int ret; 96 int ret;
97 unsigned long time = (unsigned long) dentry->d_fsdata;
97 98
98 if (time_before(jiffies, dentry->d_time)) 99 if (time_before(jiffies, time))
99 return 1; 100 return 1;
100 101
101 if (flags & LOOKUP_RCU) 102 if (flags & LOOKUP_RCU)
diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c
index 66ea0cc37b18..02cc6139ec90 100644
--- a/fs/orangefs/file.c
+++ b/fs/orangefs/file.c
@@ -621,9 +621,9 @@ static int orangefs_file_release(struct inode *inode, struct file *file)
621 * readahead cache (if any); this forces an expensive refresh of 621 * readahead cache (if any); this forces an expensive refresh of
622 * data for the next caller of mmap (or 'get_block' accesses) 622 * data for the next caller of mmap (or 'get_block' accesses)
623 */ 623 */
624 if (file->f_path.dentry->d_inode && 624 if (file_inode(file) &&
625 file->f_path.dentry->d_inode->i_mapping && 625 file_inode(file)->i_mapping &&
626 mapping_nrpages(&file->f_path.dentry->d_inode->i_data)) { 626 mapping_nrpages(&file_inode(file)->i_data)) {
627 if (orangefs_features & ORANGEFS_FEATURE_READAHEAD) { 627 if (orangefs_features & ORANGEFS_FEATURE_READAHEAD) {
628 gossip_debug(GOSSIP_INODE_DEBUG, 628 gossip_debug(GOSSIP_INODE_DEBUG,
629 "calling flush_racache on %pU\n", 629 "calling flush_racache on %pU\n",
@@ -632,7 +632,7 @@ static int orangefs_file_release(struct inode *inode, struct file *file)
632 gossip_debug(GOSSIP_INODE_DEBUG, 632 gossip_debug(GOSSIP_INODE_DEBUG,
633 "flush_racache finished\n"); 633 "flush_racache finished\n");
634 } 634 }
635 truncate_inode_pages(file->f_path.dentry->d_inode->i_mapping, 635 truncate_inode_pages(file_inode(file)->i_mapping,
636 0); 636 0);
637 } 637 }
638 return 0; 638 return 0;
@@ -648,7 +648,7 @@ static int orangefs_fsync(struct file *file,
648{ 648{
649 int ret = -EINVAL; 649 int ret = -EINVAL;
650 struct orangefs_inode_s *orangefs_inode = 650 struct orangefs_inode_s *orangefs_inode =
651 ORANGEFS_I(file->f_path.dentry->d_inode); 651 ORANGEFS_I(file_inode(file));
652 struct orangefs_kernel_op_s *new_op = NULL; 652 struct orangefs_kernel_op_s *new_op = NULL;
653 653
654 /* required call */ 654 /* required call */
@@ -661,7 +661,7 @@ static int orangefs_fsync(struct file *file,
661 661
662 ret = service_operation(new_op, 662 ret = service_operation(new_op,
663 "orangefs_fsync", 663 "orangefs_fsync",
664 get_interruptible_flag(file->f_path.dentry->d_inode)); 664 get_interruptible_flag(file_inode(file)));
665 665
666 gossip_debug(GOSSIP_FILE_DEBUG, 666 gossip_debug(GOSSIP_FILE_DEBUG,
667 "orangefs_fsync got return value of %d\n", 667 "orangefs_fsync got return value of %d\n",
@@ -669,7 +669,7 @@ static int orangefs_fsync(struct file *file,
669 669
670 op_release(new_op); 670 op_release(new_op);
671 671
672 orangefs_flush_inode(file->f_path.dentry->d_inode); 672 orangefs_flush_inode(file_inode(file));
673 return ret; 673 return ret;
674} 674}
675 675
diff --git a/fs/orangefs/namei.c b/fs/orangefs/namei.c
index d15d3d2dba62..a290ff6ec756 100644
--- a/fs/orangefs/namei.c
+++ b/fs/orangefs/namei.c
@@ -72,7 +72,7 @@ static int orangefs_create(struct inode *dir,
72 72
73 d_instantiate(dentry, inode); 73 d_instantiate(dentry, inode);
74 unlock_new_inode(inode); 74 unlock_new_inode(inode);
75 dentry->d_time = jiffies + orangefs_dcache_timeout_msecs*HZ/1000; 75 orangefs_set_timeout(dentry);
76 ORANGEFS_I(inode)->getattr_time = jiffies - 1; 76 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
77 77
78 gossip_debug(GOSSIP_NAME_DEBUG, 78 gossip_debug(GOSSIP_NAME_DEBUG,
@@ -183,7 +183,7 @@ static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
183 goto out; 183 goto out;
184 } 184 }
185 185
186 dentry->d_time = jiffies + orangefs_dcache_timeout_msecs*HZ/1000; 186 orangefs_set_timeout(dentry);
187 187
188 inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn); 188 inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
189 if (IS_ERR(inode)) { 189 if (IS_ERR(inode)) {
@@ -322,7 +322,7 @@ static int orangefs_symlink(struct inode *dir,
322 322
323 d_instantiate(dentry, inode); 323 d_instantiate(dentry, inode);
324 unlock_new_inode(inode); 324 unlock_new_inode(inode);
325 dentry->d_time = jiffies + orangefs_dcache_timeout_msecs*HZ/1000; 325 orangefs_set_timeout(dentry);
326 ORANGEFS_I(inode)->getattr_time = jiffies - 1; 326 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
327 327
328 gossip_debug(GOSSIP_NAME_DEBUG, 328 gossip_debug(GOSSIP_NAME_DEBUG,
@@ -386,7 +386,7 @@ static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
386 386
387 d_instantiate(dentry, inode); 387 d_instantiate(dentry, inode);
388 unlock_new_inode(inode); 388 unlock_new_inode(inode);
389 dentry->d_time = jiffies + orangefs_dcache_timeout_msecs*HZ/1000; 389 orangefs_set_timeout(dentry);
390 ORANGEFS_I(inode)->getattr_time = jiffies - 1; 390 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
391 391
392 gossip_debug(GOSSIP_NAME_DEBUG, 392 gossip_debug(GOSSIP_NAME_DEBUG,
diff --git a/fs/orangefs/orangefs-kernel.h b/fs/orangefs/orangefs-kernel.h
index 0a82048f3aaf..3bf803d732c5 100644
--- a/fs/orangefs/orangefs-kernel.h
+++ b/fs/orangefs/orangefs-kernel.h
@@ -580,4 +580,11 @@ static inline void orangefs_i_size_write(struct inode *inode, loff_t i_size)
580#endif 580#endif
581} 581}
582 582
583static inline void orangefs_set_timeout(struct dentry *dentry)
584{
585 unsigned long time = jiffies + orangefs_dcache_timeout_msecs*HZ/1000;
586
587 dentry->d_fsdata = (void *) time;
588}
589
583#endif /* __ORANGEFSKERNEL_H */ 590#endif /* __ORANGEFSKERNEL_H */
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 8e654468ab67..ca651ac00660 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -252,7 +252,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
252 * Inherently racy -- command line shares address space 252 * Inherently racy -- command line shares address space
253 * with code and data. 253 * with code and data.
254 */ 254 */
255 rv = access_remote_vm(mm, arg_end - 1, &c, 1, FOLL_FORCE); 255 rv = access_remote_vm(mm, arg_end - 1, &c, 1, 0);
256 if (rv <= 0) 256 if (rv <= 0)
257 goto out_free_page; 257 goto out_free_page;
258 258
@@ -270,8 +270,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
270 int nr_read; 270 int nr_read;
271 271
272 _count = min3(count, len, PAGE_SIZE); 272 _count = min3(count, len, PAGE_SIZE);
273 nr_read = access_remote_vm(mm, p, page, _count, 273 nr_read = access_remote_vm(mm, p, page, _count, 0);
274 FOLL_FORCE);
275 if (nr_read < 0) 274 if (nr_read < 0)
276 rv = nr_read; 275 rv = nr_read;
277 if (nr_read <= 0) 276 if (nr_read <= 0)
@@ -306,8 +305,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
306 bool final; 305 bool final;
307 306
308 _count = min3(count, len, PAGE_SIZE); 307 _count = min3(count, len, PAGE_SIZE);
309 nr_read = access_remote_vm(mm, p, page, _count, 308 nr_read = access_remote_vm(mm, p, page, _count, 0);
310 FOLL_FORCE);
311 if (nr_read < 0) 309 if (nr_read < 0)
312 rv = nr_read; 310 rv = nr_read;
313 if (nr_read <= 0) 311 if (nr_read <= 0)
@@ -356,8 +354,7 @@ skip_argv:
356 bool final; 354 bool final;
357 355
358 _count = min3(count, len, PAGE_SIZE); 356 _count = min3(count, len, PAGE_SIZE);
359 nr_read = access_remote_vm(mm, p, page, _count, 357 nr_read = access_remote_vm(mm, p, page, _count, 0);
360 FOLL_FORCE);
361 if (nr_read < 0) 358 if (nr_read < 0)
362 rv = nr_read; 359 rv = nr_read;
363 if (nr_read <= 0) 360 if (nr_read <= 0)
@@ -835,7 +832,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
835 unsigned long addr = *ppos; 832 unsigned long addr = *ppos;
836 ssize_t copied; 833 ssize_t copied;
837 char *page; 834 char *page;
838 unsigned int flags = FOLL_FORCE; 835 unsigned int flags;
839 836
840 if (!mm) 837 if (!mm)
841 return 0; 838 return 0;
@@ -848,6 +845,8 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
848 if (!atomic_inc_not_zero(&mm->mm_users)) 845 if (!atomic_inc_not_zero(&mm->mm_users))
849 goto free; 846 goto free;
850 847
848 /* Maybe we should limit FOLL_FORCE to actual ptrace users? */
849 flags = FOLL_FORCE;
851 if (write) 850 if (write)
852 flags |= FOLL_WRITE; 851 flags |= FOLL_WRITE;
853 852
@@ -971,8 +970,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
971 max_len = min_t(size_t, PAGE_SIZE, count); 970 max_len = min_t(size_t, PAGE_SIZE, count);
972 this_len = min(max_len, this_len); 971 this_len = min(max_len, this_len);
973 972
974 retval = access_remote_vm(mm, (env_start + src), 973 retval = access_remote_vm(mm, (env_start + src), page, this_len, 0);
975 page, this_len, FOLL_FORCE);
976 974
977 if (retval <= 0) { 975 if (retval <= 0) {
978 ret = retval; 976 ret = retval;
@@ -1014,6 +1012,9 @@ static ssize_t auxv_read(struct file *file, char __user *buf,
1014{ 1012{
1015 struct mm_struct *mm = file->private_data; 1013 struct mm_struct *mm = file->private_data;
1016 unsigned int nwords = 0; 1014 unsigned int nwords = 0;
1015
1016 if (!mm)
1017 return 0;
1017 do { 1018 do {
1018 nwords += 2; 1019 nwords += 2;
1019 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */ 1020 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index c27344cf38e1..c6eb21940783 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3974,9 +3974,6 @@ xfs_bmap_remap_alloc(
3974 * allocating, so skip that check by pretending to be freeing. 3974 * allocating, so skip that check by pretending to be freeing.
3975 */ 3975 */
3976 error = xfs_alloc_fix_freelist(&args, XFS_ALLOC_FLAG_FREEING); 3976 error = xfs_alloc_fix_freelist(&args, XFS_ALLOC_FLAG_FREEING);
3977 if (error)
3978 goto error0;
3979error0:
3980 xfs_perag_put(args.pag); 3977 xfs_perag_put(args.pag);
3981 if (error) 3978 if (error)
3982 trace_xfs_bmap_remap_alloc_error(ap->ip, error, _RET_IP_); 3979 trace_xfs_bmap_remap_alloc_error(ap->ip, error, _RET_IP_);
@@ -3999,6 +3996,39 @@ xfs_bmap_alloc(
3999 return xfs_bmap_btalloc(ap); 3996 return xfs_bmap_btalloc(ap);
4000} 3997}
4001 3998
3999/* Trim extent to fit a logical block range. */
4000void
4001xfs_trim_extent(
4002 struct xfs_bmbt_irec *irec,
4003 xfs_fileoff_t bno,
4004 xfs_filblks_t len)
4005{
4006 xfs_fileoff_t distance;
4007 xfs_fileoff_t end = bno + len;
4008
4009 if (irec->br_startoff + irec->br_blockcount <= bno ||
4010 irec->br_startoff >= end) {
4011 irec->br_blockcount = 0;
4012 return;
4013 }
4014
4015 if (irec->br_startoff < bno) {
4016 distance = bno - irec->br_startoff;
4017 if (isnullstartblock(irec->br_startblock))
4018 irec->br_startblock = DELAYSTARTBLOCK;
4019 if (irec->br_startblock != DELAYSTARTBLOCK &&
4020 irec->br_startblock != HOLESTARTBLOCK)
4021 irec->br_startblock += distance;
4022 irec->br_startoff += distance;
4023 irec->br_blockcount -= distance;
4024 }
4025
4026 if (end < irec->br_startoff + irec->br_blockcount) {
4027 distance = irec->br_startoff + irec->br_blockcount - end;
4028 irec->br_blockcount -= distance;
4029 }
4030}
4031
4002/* 4032/*
4003 * Trim the returned map to the required bounds 4033 * Trim the returned map to the required bounds
4004 */ 4034 */
@@ -4829,6 +4859,219 @@ xfs_bmap_split_indlen(
4829 return stolen; 4859 return stolen;
4830} 4860}
4831 4861
4862int
4863xfs_bmap_del_extent_delay(
4864 struct xfs_inode *ip,
4865 int whichfork,
4866 xfs_extnum_t *idx,
4867 struct xfs_bmbt_irec *got,
4868 struct xfs_bmbt_irec *del)
4869{
4870 struct xfs_mount *mp = ip->i_mount;
4871 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
4872 struct xfs_bmbt_irec new;
4873 int64_t da_old, da_new, da_diff = 0;
4874 xfs_fileoff_t del_endoff, got_endoff;
4875 xfs_filblks_t got_indlen, new_indlen, stolen;
4876 int error = 0, state = 0;
4877 bool isrt;
4878
4879 XFS_STATS_INC(mp, xs_del_exlist);
4880
4881 isrt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip);
4882 del_endoff = del->br_startoff + del->br_blockcount;
4883 got_endoff = got->br_startoff + got->br_blockcount;
4884 da_old = startblockval(got->br_startblock);
4885 da_new = 0;
4886
4887 ASSERT(*idx >= 0);
4888 ASSERT(*idx < ifp->if_bytes / sizeof(struct xfs_bmbt_rec));
4889 ASSERT(del->br_blockcount > 0);
4890 ASSERT(got->br_startoff <= del->br_startoff);
4891 ASSERT(got_endoff >= del_endoff);
4892
4893 if (isrt) {
4894 int64_t rtexts = XFS_FSB_TO_B(mp, del->br_blockcount);
4895
4896 do_div(rtexts, mp->m_sb.sb_rextsize);
4897 xfs_mod_frextents(mp, rtexts);
4898 }
4899
4900 /*
4901 * Update the inode delalloc counter now and wait to update the
4902 * sb counters as we might have to borrow some blocks for the
4903 * indirect block accounting.
4904 */
4905 xfs_trans_reserve_quota_nblks(NULL, ip, -((long)del->br_blockcount), 0,
4906 isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
4907 ip->i_delayed_blks -= del->br_blockcount;
4908
4909 if (whichfork == XFS_COW_FORK)
4910 state |= BMAP_COWFORK;
4911
4912 if (got->br_startoff == del->br_startoff)
4913 state |= BMAP_LEFT_CONTIG;
4914 if (got_endoff == del_endoff)
4915 state |= BMAP_RIGHT_CONTIG;
4916
4917 switch (state & (BMAP_LEFT_CONTIG | BMAP_RIGHT_CONTIG)) {
4918 case BMAP_LEFT_CONTIG | BMAP_RIGHT_CONTIG:
4919 /*
4920 * Matches the whole extent. Delete the entry.
4921 */
4922 xfs_iext_remove(ip, *idx, 1, state);
4923 --*idx;
4924 break;
4925 case BMAP_LEFT_CONTIG:
4926 /*
4927 * Deleting the first part of the extent.
4928 */
4929 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
4930 got->br_startoff = del_endoff;
4931 got->br_blockcount -= del->br_blockcount;
4932 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip,
4933 got->br_blockcount), da_old);
4934 got->br_startblock = nullstartblock((int)da_new);
4935 xfs_bmbt_set_all(xfs_iext_get_ext(ifp, *idx), got);
4936 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
4937 break;
4938 case BMAP_RIGHT_CONTIG:
4939 /*
4940 * Deleting the last part of the extent.
4941 */
4942 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
4943 got->br_blockcount = got->br_blockcount - del->br_blockcount;
4944 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip,
4945 got->br_blockcount), da_old);
4946 got->br_startblock = nullstartblock((int)da_new);
4947 xfs_bmbt_set_all(xfs_iext_get_ext(ifp, *idx), got);
4948 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
4949 break;
4950 case 0:
4951 /*
4952 * Deleting the middle of the extent.
4953 *
4954 * Distribute the original indlen reservation across the two new
4955 * extents. Steal blocks from the deleted extent if necessary.
4956 * Stealing blocks simply fudges the fdblocks accounting below.
4957 * Warn if either of the new indlen reservations is zero as this
4958 * can lead to delalloc problems.
4959 */
4960 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
4961
4962 got->br_blockcount = del->br_startoff - got->br_startoff;
4963 got_indlen = xfs_bmap_worst_indlen(ip, got->br_blockcount);
4964
4965 new.br_blockcount = got_endoff - del_endoff;
4966 new_indlen = xfs_bmap_worst_indlen(ip, new.br_blockcount);
4967
4968 WARN_ON_ONCE(!got_indlen || !new_indlen);
4969 stolen = xfs_bmap_split_indlen(da_old, &got_indlen, &new_indlen,
4970 del->br_blockcount);
4971
4972 got->br_startblock = nullstartblock((int)got_indlen);
4973 xfs_bmbt_set_all(xfs_iext_get_ext(ifp, *idx), got);
4974 trace_xfs_bmap_post_update(ip, *idx, 0, _THIS_IP_);
4975
4976 new.br_startoff = del_endoff;
4977 new.br_state = got->br_state;
4978 new.br_startblock = nullstartblock((int)new_indlen);
4979
4980 ++*idx;
4981 xfs_iext_insert(ip, *idx, 1, &new, state);
4982
4983 da_new = got_indlen + new_indlen - stolen;
4984 del->br_blockcount -= stolen;
4985 break;
4986 }
4987
4988 ASSERT(da_old >= da_new);
4989 da_diff = da_old - da_new;
4990 if (!isrt)
4991 da_diff += del->br_blockcount;
4992 if (da_diff)
4993 xfs_mod_fdblocks(mp, da_diff, false);
4994 return error;
4995}
4996
4997void
4998xfs_bmap_del_extent_cow(
4999 struct xfs_inode *ip,
5000 xfs_extnum_t *idx,
5001 struct xfs_bmbt_irec *got,
5002 struct xfs_bmbt_irec *del)
5003{
5004 struct xfs_mount *mp = ip->i_mount;
5005 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
5006 struct xfs_bmbt_irec new;
5007 xfs_fileoff_t del_endoff, got_endoff;
5008 int state = BMAP_COWFORK;
5009
5010 XFS_STATS_INC(mp, xs_del_exlist);
5011
5012 del_endoff = del->br_startoff + del->br_blockcount;
5013 got_endoff = got->br_startoff + got->br_blockcount;
5014
5015 ASSERT(*idx >= 0);
5016 ASSERT(*idx < ifp->if_bytes / sizeof(struct xfs_bmbt_rec));
5017 ASSERT(del->br_blockcount > 0);
5018 ASSERT(got->br_startoff <= del->br_startoff);
5019 ASSERT(got_endoff >= del_endoff);
5020 ASSERT(!isnullstartblock(got->br_startblock));
5021
5022 if (got->br_startoff == del->br_startoff)
5023 state |= BMAP_LEFT_CONTIG;
5024 if (got_endoff == del_endoff)
5025 state |= BMAP_RIGHT_CONTIG;
5026
5027 switch (state & (BMAP_LEFT_CONTIG | BMAP_RIGHT_CONTIG)) {
5028 case BMAP_LEFT_CONTIG | BMAP_RIGHT_CONTIG:
5029 /*
5030 * Matches the whole extent. Delete the entry.
5031 */
5032 xfs_iext_remove(ip, *idx, 1, state);
5033 --*idx;
5034 break;
5035 case BMAP_LEFT_CONTIG:
5036 /*
5037 * Deleting the first part of the extent.
5038 */
5039 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
5040 got->br_startoff = del_endoff;
5041 got->br_blockcount -= del->br_blockcount;
5042 got->br_startblock = del->br_startblock + del->br_blockcount;
5043 xfs_bmbt_set_all(xfs_iext_get_ext(ifp, *idx), got);
5044 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
5045 break;
5046 case BMAP_RIGHT_CONTIG:
5047 /*
5048 * Deleting the last part of the extent.
5049 */
5050 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
5051 got->br_blockcount -= del->br_blockcount;
5052 xfs_bmbt_set_all(xfs_iext_get_ext(ifp, *idx), got);
5053 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
5054 break;
5055 case 0:
5056 /*
5057 * Deleting the middle of the extent.
5058 */
5059 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
5060 got->br_blockcount = del->br_startoff - got->br_startoff;
5061 xfs_bmbt_set_all(xfs_iext_get_ext(ifp, *idx), got);
5062 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
5063
5064 new.br_startoff = del_endoff;
5065 new.br_blockcount = got_endoff - del_endoff;
5066 new.br_state = got->br_state;
5067 new.br_startblock = del->br_startblock + del->br_blockcount;
5068
5069 ++*idx;
5070 xfs_iext_insert(ip, *idx, 1, &new, state);
5071 break;
5072 }
5073}
5074
4832/* 5075/*
4833 * Called by xfs_bmapi to update file extent records and the btree 5076 * Called by xfs_bmapi to update file extent records and the btree
4834 * after removing space (or undoing a delayed allocation). 5077 * after removing space (or undoing a delayed allocation).
@@ -5171,175 +5414,6 @@ done:
5171 return error; 5414 return error;
5172} 5415}
5173 5416
5174/* Remove an extent from the CoW fork. Similar to xfs_bmap_del_extent. */
5175int
5176xfs_bunmapi_cow(
5177 struct xfs_inode *ip,
5178 struct xfs_bmbt_irec *del)
5179{
5180 xfs_filblks_t da_new;
5181 xfs_filblks_t da_old;
5182 xfs_fsblock_t del_endblock = 0;
5183 xfs_fileoff_t del_endoff;
5184 int delay;
5185 struct xfs_bmbt_rec_host *ep;
5186 int error;
5187 struct xfs_bmbt_irec got;
5188 xfs_fileoff_t got_endoff;
5189 struct xfs_ifork *ifp;
5190 struct xfs_mount *mp;
5191 xfs_filblks_t nblks;
5192 struct xfs_bmbt_irec new;
5193 /* REFERENCED */
5194 uint qfield;
5195 xfs_filblks_t temp;
5196 xfs_filblks_t temp2;
5197 int state = BMAP_COWFORK;
5198 int eof;
5199 xfs_extnum_t eidx;
5200
5201 mp = ip->i_mount;
5202 XFS_STATS_INC(mp, xs_del_exlist);
5203
5204 ep = xfs_bmap_search_extents(ip, del->br_startoff, XFS_COW_FORK, &eof,
5205 &eidx, &got, &new);
5206
5207 ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK); ifp = ifp;
5208 ASSERT((eidx >= 0) && (eidx < ifp->if_bytes /
5209 (uint)sizeof(xfs_bmbt_rec_t)));
5210 ASSERT(del->br_blockcount > 0);
5211 ASSERT(got.br_startoff <= del->br_startoff);
5212 del_endoff = del->br_startoff + del->br_blockcount;
5213 got_endoff = got.br_startoff + got.br_blockcount;
5214 ASSERT(got_endoff >= del_endoff);
5215 delay = isnullstartblock(got.br_startblock);
5216 ASSERT(isnullstartblock(del->br_startblock) == delay);
5217 qfield = 0;
5218 error = 0;
5219 /*
5220 * If deleting a real allocation, must free up the disk space.
5221 */
5222 if (!delay) {
5223 nblks = del->br_blockcount;
5224 qfield = XFS_TRANS_DQ_BCOUNT;
5225 /*
5226 * Set up del_endblock and cur for later.
5227 */
5228 del_endblock = del->br_startblock + del->br_blockcount;
5229 da_old = da_new = 0;
5230 } else {
5231 da_old = startblockval(got.br_startblock);
5232 da_new = 0;
5233 nblks = 0;
5234 }
5235 qfield = qfield;
5236 nblks = nblks;
5237
5238 /*
5239 * Set flag value to use in switch statement.
5240 * Left-contig is 2, right-contig is 1.
5241 */
5242 switch (((got.br_startoff == del->br_startoff) << 1) |
5243 (got_endoff == del_endoff)) {
5244 case 3:
5245 /*
5246 * Matches the whole extent. Delete the entry.
5247 */
5248 xfs_iext_remove(ip, eidx, 1, BMAP_COWFORK);
5249 --eidx;
5250 break;
5251
5252 case 2:
5253 /*
5254 * Deleting the first part of the extent.
5255 */
5256 trace_xfs_bmap_pre_update(ip, eidx, state, _THIS_IP_);
5257 xfs_bmbt_set_startoff(ep, del_endoff);
5258 temp = got.br_blockcount - del->br_blockcount;
5259 xfs_bmbt_set_blockcount(ep, temp);
5260 if (delay) {
5261 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
5262 da_old);
5263 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
5264 trace_xfs_bmap_post_update(ip, eidx, state, _THIS_IP_);
5265 da_new = temp;
5266 break;
5267 }
5268 xfs_bmbt_set_startblock(ep, del_endblock);
5269 trace_xfs_bmap_post_update(ip, eidx, state, _THIS_IP_);
5270 break;
5271
5272 case 1:
5273 /*
5274 * Deleting the last part of the extent.
5275 */
5276 temp = got.br_blockcount - del->br_blockcount;
5277 trace_xfs_bmap_pre_update(ip, eidx, state, _THIS_IP_);
5278 xfs_bmbt_set_blockcount(ep, temp);
5279 if (delay) {
5280 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
5281 da_old);
5282 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
5283 trace_xfs_bmap_post_update(ip, eidx, state, _THIS_IP_);
5284 da_new = temp;
5285 break;
5286 }
5287 trace_xfs_bmap_post_update(ip, eidx, state, _THIS_IP_);
5288 break;
5289
5290 case 0:
5291 /*
5292 * Deleting the middle of the extent.
5293 */
5294 temp = del->br_startoff - got.br_startoff;
5295 trace_xfs_bmap_pre_update(ip, eidx, state, _THIS_IP_);
5296 xfs_bmbt_set_blockcount(ep, temp);
5297 new.br_startoff = del_endoff;
5298 temp2 = got_endoff - del_endoff;
5299 new.br_blockcount = temp2;
5300 new.br_state = got.br_state;
5301 if (!delay) {
5302 new.br_startblock = del_endblock;
5303 } else {
5304 temp = xfs_bmap_worst_indlen(ip, temp);
5305 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
5306 temp2 = xfs_bmap_worst_indlen(ip, temp2);
5307 new.br_startblock = nullstartblock((int)temp2);
5308 da_new = temp + temp2;
5309 while (da_new > da_old) {
5310 if (temp) {
5311 temp--;
5312 da_new--;
5313 xfs_bmbt_set_startblock(ep,
5314 nullstartblock((int)temp));
5315 }
5316 if (da_new == da_old)
5317 break;
5318 if (temp2) {
5319 temp2--;
5320 da_new--;
5321 new.br_startblock =
5322 nullstartblock((int)temp2);
5323 }
5324 }
5325 }
5326 trace_xfs_bmap_post_update(ip, eidx, state, _THIS_IP_);
5327 xfs_iext_insert(ip, eidx + 1, 1, &new, state);
5328 ++eidx;
5329 break;
5330 }
5331
5332 /*
5333 * Account for change in delayed indirect blocks.
5334 * Nothing to do for disk quota accounting here.
5335 */
5336 ASSERT(da_old >= da_new);
5337 if (da_old > da_new)
5338 xfs_mod_fdblocks(mp, (int64_t)(da_old - da_new), false);
5339
5340 return error;
5341}
5342
5343/* 5417/*
5344 * Unmap (remove) blocks from a file. 5418 * Unmap (remove) blocks from a file.
5345 * If nexts is nonzero then the number of extents to remove is limited to 5419 * If nexts is nonzero then the number of extents to remove is limited to
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index f97db7132564..7cae6ec27fa6 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -190,6 +190,8 @@ void xfs_bmap_trace_exlist(struct xfs_inode *ip, xfs_extnum_t cnt,
190#define XFS_BMAP_TRACE_EXLIST(ip,c,w) 190#define XFS_BMAP_TRACE_EXLIST(ip,c,w)
191#endif 191#endif
192 192
193void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno,
194 xfs_filblks_t len);
193int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd); 195int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);
194void xfs_bmap_local_to_extents_empty(struct xfs_inode *ip, int whichfork); 196void xfs_bmap_local_to_extents_empty(struct xfs_inode *ip, int whichfork);
195void xfs_bmap_add_free(struct xfs_mount *mp, struct xfs_defer_ops *dfops, 197void xfs_bmap_add_free(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
@@ -221,7 +223,11 @@ int xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip,
221 xfs_fileoff_t bno, xfs_filblks_t len, int flags, 223 xfs_fileoff_t bno, xfs_filblks_t len, int flags,
222 xfs_extnum_t nexts, xfs_fsblock_t *firstblock, 224 xfs_extnum_t nexts, xfs_fsblock_t *firstblock,
223 struct xfs_defer_ops *dfops, int *done); 225 struct xfs_defer_ops *dfops, int *done);
224int xfs_bunmapi_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *del); 226int xfs_bmap_del_extent_delay(struct xfs_inode *ip, int whichfork,
227 xfs_extnum_t *idx, struct xfs_bmbt_irec *got,
228 struct xfs_bmbt_irec *del);
229void xfs_bmap_del_extent_cow(struct xfs_inode *ip, xfs_extnum_t *idx,
230 struct xfs_bmbt_irec *got, struct xfs_bmbt_irec *del);
225int xfs_check_nostate_extents(struct xfs_ifork *ifp, xfs_extnum_t idx, 231int xfs_check_nostate_extents(struct xfs_ifork *ifp, xfs_extnum_t idx,
226 xfs_extnum_t num); 232 xfs_extnum_t num);
227uint xfs_default_attroffset(struct xfs_inode *ip); 233uint xfs_default_attroffset(struct xfs_inode *ip);
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
index 5c8e6f2ce44f..0e80993c8a59 100644
--- a/fs/xfs/libxfs/xfs_btree.c
+++ b/fs/xfs/libxfs/xfs_btree.c
@@ -4826,7 +4826,7 @@ xfs_btree_calc_size(
4826 return rval; 4826 return rval;
4827} 4827}
4828 4828
4829int 4829static int
4830xfs_btree_count_blocks_helper( 4830xfs_btree_count_blocks_helper(
4831 struct xfs_btree_cur *cur, 4831 struct xfs_btree_cur *cur,
4832 int level, 4832 int level,
diff --git a/fs/xfs/libxfs/xfs_dquot_buf.c b/fs/xfs/libxfs/xfs_dquot_buf.c
index 3cc3cf767474..ac9a003dd29a 100644
--- a/fs/xfs/libxfs/xfs_dquot_buf.c
+++ b/fs/xfs/libxfs/xfs_dquot_buf.c
@@ -191,8 +191,7 @@ xfs_dquot_buf_verify_crc(
191 if (mp->m_quotainfo) 191 if (mp->m_quotainfo)
192 ndquots = mp->m_quotainfo->qi_dqperchunk; 192 ndquots = mp->m_quotainfo->qi_dqperchunk;
193 else 193 else
194 ndquots = xfs_calc_dquots_per_chunk( 194 ndquots = xfs_calc_dquots_per_chunk(bp->b_length);
195 XFS_BB_TO_FSB(mp, bp->b_length));
196 195
197 for (i = 0; i < ndquots; i++, d++) { 196 for (i = 0; i < ndquots; i++, d++) {
198 if (!xfs_verify_cksum((char *)d, sizeof(struct xfs_dqblk), 197 if (!xfs_verify_cksum((char *)d, sizeof(struct xfs_dqblk),
diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index f6547fc5e016..6b7579e7b60a 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -865,7 +865,6 @@ typedef struct xfs_timestamp {
865 * padding field for v3 inodes. 865 * padding field for v3 inodes.
866 */ 866 */
867#define XFS_DINODE_MAGIC 0x494e /* 'IN' */ 867#define XFS_DINODE_MAGIC 0x494e /* 'IN' */
868#define XFS_DINODE_GOOD_VERSION(v) ((v) >= 1 && (v) <= 3)
869typedef struct xfs_dinode { 868typedef struct xfs_dinode {
870 __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */ 869 __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */
871 __be16 di_mode; /* mode and type of file */ 870 __be16 di_mode; /* mode and type of file */
diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
index 8de9a3a29589..134424fac434 100644
--- a/fs/xfs/libxfs/xfs_inode_buf.c
+++ b/fs/xfs/libxfs/xfs_inode_buf.c
@@ -57,6 +57,17 @@ xfs_inobp_check(
57} 57}
58#endif 58#endif
59 59
60bool
61xfs_dinode_good_version(
62 struct xfs_mount *mp,
63 __u8 version)
64{
65 if (xfs_sb_version_hascrc(&mp->m_sb))
66 return version == 3;
67
68 return version == 1 || version == 2;
69}
70
60/* 71/*
61 * If we are doing readahead on an inode buffer, we might be in log recovery 72 * If we are doing readahead on an inode buffer, we might be in log recovery
62 * reading an inode allocation buffer that hasn't yet been replayed, and hence 73 * reading an inode allocation buffer that hasn't yet been replayed, and hence
@@ -91,7 +102,7 @@ xfs_inode_buf_verify(
91 102
92 dip = xfs_buf_offset(bp, (i << mp->m_sb.sb_inodelog)); 103 dip = xfs_buf_offset(bp, (i << mp->m_sb.sb_inodelog));
93 di_ok = dip->di_magic == cpu_to_be16(XFS_DINODE_MAGIC) && 104 di_ok = dip->di_magic == cpu_to_be16(XFS_DINODE_MAGIC) &&
94 XFS_DINODE_GOOD_VERSION(dip->di_version); 105 xfs_dinode_good_version(mp, dip->di_version);
95 if (unlikely(XFS_TEST_ERROR(!di_ok, mp, 106 if (unlikely(XFS_TEST_ERROR(!di_ok, mp,
96 XFS_ERRTAG_ITOBP_INOTOBP, 107 XFS_ERRTAG_ITOBP_INOTOBP,
97 XFS_RANDOM_ITOBP_INOTOBP))) { 108 XFS_RANDOM_ITOBP_INOTOBP))) {
diff --git a/fs/xfs/libxfs/xfs_inode_buf.h b/fs/xfs/libxfs/xfs_inode_buf.h
index 62d9d4681c8c..3cfe12a4f58a 100644
--- a/fs/xfs/libxfs/xfs_inode_buf.h
+++ b/fs/xfs/libxfs/xfs_inode_buf.h
@@ -74,6 +74,8 @@ void xfs_inode_from_disk(struct xfs_inode *ip, struct xfs_dinode *from);
74void xfs_log_dinode_to_disk(struct xfs_log_dinode *from, 74void xfs_log_dinode_to_disk(struct xfs_log_dinode *from,
75 struct xfs_dinode *to); 75 struct xfs_dinode *to);
76 76
77bool xfs_dinode_good_version(struct xfs_mount *mp, __u8 version);
78
77#if defined(DEBUG) 79#if defined(DEBUG)
78void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *); 80void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);
79#else 81#else
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index a314fc7b56fa..6e4f7f900fea 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -249,6 +249,7 @@ xfs_file_dio_aio_read(
249 struct xfs_inode *ip = XFS_I(inode); 249 struct xfs_inode *ip = XFS_I(inode);
250 loff_t isize = i_size_read(inode); 250 loff_t isize = i_size_read(inode);
251 size_t count = iov_iter_count(to); 251 size_t count = iov_iter_count(to);
252 loff_t end = iocb->ki_pos + count - 1;
252 struct iov_iter data; 253 struct iov_iter data;
253 struct xfs_buftarg *target; 254 struct xfs_buftarg *target;
254 ssize_t ret = 0; 255 ssize_t ret = 0;
@@ -272,49 +273,21 @@ xfs_file_dio_aio_read(
272 273
273 file_accessed(iocb->ki_filp); 274 file_accessed(iocb->ki_filp);
274 275
275 /*
276 * Locking is a bit tricky here. If we take an exclusive lock for direct
277 * IO, we effectively serialise all new concurrent read IO to this file
278 * and block it behind IO that is currently in progress because IO in
279 * progress holds the IO lock shared. We only need to hold the lock
280 * exclusive to blow away the page cache, so only take lock exclusively
281 * if the page cache needs invalidation. This allows the normal direct
282 * IO case of no page cache pages to proceeed concurrently without
283 * serialisation.
284 */
285 xfs_rw_ilock(ip, XFS_IOLOCK_SHARED); 276 xfs_rw_ilock(ip, XFS_IOLOCK_SHARED);
286 if (mapping->nrpages) { 277 if (mapping->nrpages) {
287 xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED); 278 ret = filemap_write_and_wait_range(mapping, iocb->ki_pos, end);
288 xfs_rw_ilock(ip, XFS_IOLOCK_EXCL); 279 if (ret)
280 goto out_unlock;
289 281
290 /* 282 /*
291 * The generic dio code only flushes the range of the particular 283 * Invalidate whole pages. This can return an error if we fail
292 * I/O. Because we take an exclusive lock here, this whole 284 * to invalidate a page, but this should never happen on XFS.
293 * sequence is considerably more expensive for us. This has a 285 * Warn if it does fail.
294 * noticeable performance impact for any file with cached pages,
295 * even when outside of the range of the particular I/O.
296 *
297 * Hence, amortize the cost of the lock against a full file
298 * flush and reduce the chances of repeated iolock cycles going
299 * forward.
300 */ 286 */
301 if (mapping->nrpages) { 287 ret = invalidate_inode_pages2_range(mapping,
302 ret = filemap_write_and_wait(mapping); 288 iocb->ki_pos >> PAGE_SHIFT, end >> PAGE_SHIFT);
303 if (ret) { 289 WARN_ON_ONCE(ret);
304 xfs_rw_iunlock(ip, XFS_IOLOCK_EXCL); 290 ret = 0;
305 return ret;
306 }
307
308 /*
309 * Invalidate whole pages. This can return an error if
310 * we fail to invalidate a page, but this should never
311 * happen on XFS. Warn if it does fail.
312 */
313 ret = invalidate_inode_pages2(mapping);
314 WARN_ON_ONCE(ret);
315 ret = 0;
316 }
317 xfs_rw_ilock_demote(ip, XFS_IOLOCK_EXCL);
318 } 291 }
319 292
320 data = *to; 293 data = *to;
@@ -324,8 +297,9 @@ xfs_file_dio_aio_read(
324 iocb->ki_pos += ret; 297 iocb->ki_pos += ret;
325 iov_iter_advance(to, ret); 298 iov_iter_advance(to, ret);
326 } 299 }
327 xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED);
328 300
301out_unlock:
302 xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED);
329 return ret; 303 return ret;
330} 304}
331 305
@@ -570,61 +544,49 @@ xfs_file_dio_aio_write(
570 if ((iocb->ki_pos | count) & target->bt_logical_sectormask) 544 if ((iocb->ki_pos | count) & target->bt_logical_sectormask)
571 return -EINVAL; 545 return -EINVAL;
572 546
573 /* "unaligned" here means not aligned to a filesystem block */
574 if ((iocb->ki_pos & mp->m_blockmask) ||
575 ((iocb->ki_pos + count) & mp->m_blockmask))
576 unaligned_io = 1;
577
578 /* 547 /*
579 * We don't need to take an exclusive lock unless there page cache needs 548 * Don't take the exclusive iolock here unless the I/O is unaligned to
580 * to be invalidated or unaligned IO is being executed. We don't need to 549 * the file system block size. We don't need to consider the EOF
581 * consider the EOF extension case here because 550 * extension case here because xfs_file_aio_write_checks() will relock
582 * xfs_file_aio_write_checks() will relock the inode as necessary for 551 * the inode as necessary for EOF zeroing cases and fill out the new
583 * EOF zeroing cases and fill out the new inode size as appropriate. 552 * inode size as appropriate.
584 */ 553 */
585 if (unaligned_io || mapping->nrpages) 554 if ((iocb->ki_pos & mp->m_blockmask) ||
555 ((iocb->ki_pos + count) & mp->m_blockmask)) {
556 unaligned_io = 1;
586 iolock = XFS_IOLOCK_EXCL; 557 iolock = XFS_IOLOCK_EXCL;
587 else 558 } else {
588 iolock = XFS_IOLOCK_SHARED; 559 iolock = XFS_IOLOCK_SHARED;
589 xfs_rw_ilock(ip, iolock);
590
591 /*
592 * Recheck if there are cached pages that need invalidate after we got
593 * the iolock to protect against other threads adding new pages while
594 * we were waiting for the iolock.
595 */
596 if (mapping->nrpages && iolock == XFS_IOLOCK_SHARED) {
597 xfs_rw_iunlock(ip, iolock);
598 iolock = XFS_IOLOCK_EXCL;
599 xfs_rw_ilock(ip, iolock);
600 } 560 }
601 561
562 xfs_rw_ilock(ip, iolock);
563
602 ret = xfs_file_aio_write_checks(iocb, from, &iolock); 564 ret = xfs_file_aio_write_checks(iocb, from, &iolock);
603 if (ret) 565 if (ret)
604 goto out; 566 goto out;
605 count = iov_iter_count(from); 567 count = iov_iter_count(from);
606 end = iocb->ki_pos + count - 1; 568 end = iocb->ki_pos + count - 1;
607 569
608 /*
609 * See xfs_file_dio_aio_read() for why we do a full-file flush here.
610 */
611 if (mapping->nrpages) { 570 if (mapping->nrpages) {
612 ret = filemap_write_and_wait(VFS_I(ip)->i_mapping); 571 ret = filemap_write_and_wait_range(mapping, iocb->ki_pos, end);
613 if (ret) 572 if (ret)
614 goto out; 573 goto out;
574
615 /* 575 /*
616 * Invalidate whole pages. This can return an error if we fail 576 * Invalidate whole pages. This can return an error if we fail
617 * to invalidate a page, but this should never happen on XFS. 577 * to invalidate a page, but this should never happen on XFS.
618 * Warn if it does fail. 578 * Warn if it does fail.
619 */ 579 */
620 ret = invalidate_inode_pages2(VFS_I(ip)->i_mapping); 580 ret = invalidate_inode_pages2_range(mapping,
581 iocb->ki_pos >> PAGE_SHIFT, end >> PAGE_SHIFT);
621 WARN_ON_ONCE(ret); 582 WARN_ON_ONCE(ret);
622 ret = 0; 583 ret = 0;
623 } 584 }
624 585
625 /* 586 /*
626 * If we are doing unaligned IO, wait for all other IO to drain, 587 * If we are doing unaligned IO, wait for all other IO to drain,
627 * otherwise demote the lock if we had to flush cached pages 588 * otherwise demote the lock if we had to take the exclusive lock
589 * for other reasons in xfs_file_aio_write_checks.
628 */ 590 */
629 if (unaligned_io) 591 if (unaligned_io)
630 inode_dio_wait(inode); 592 inode_dio_wait(inode);
@@ -947,134 +909,6 @@ out_unlock:
947 return error; 909 return error;
948} 910}
949 911
950/*
951 * Flush all file writes out to disk.
952 */
953static int
954xfs_file_wait_for_io(
955 struct inode *inode,
956 loff_t offset,
957 size_t len)
958{
959 loff_t rounding;
960 loff_t ioffset;
961 loff_t iendoffset;
962 loff_t bs;
963 int ret;
964
965 bs = inode->i_sb->s_blocksize;
966 inode_dio_wait(inode);
967
968 rounding = max_t(xfs_off_t, bs, PAGE_SIZE);
969 ioffset = round_down(offset, rounding);
970 iendoffset = round_up(offset + len, rounding) - 1;
971 ret = filemap_write_and_wait_range(inode->i_mapping, ioffset,
972 iendoffset);
973 return ret;
974}
975
976/* Hook up to the VFS reflink function */
977STATIC int
978xfs_file_share_range(
979 struct file *file_in,
980 loff_t pos_in,
981 struct file *file_out,
982 loff_t pos_out,
983 u64 len,
984 bool is_dedupe)
985{
986 struct inode *inode_in;
987 struct inode *inode_out;
988 ssize_t ret;
989 loff_t bs;
990 loff_t isize;
991 int same_inode;
992 loff_t blen;
993 unsigned int flags = 0;
994
995 inode_in = file_inode(file_in);
996 inode_out = file_inode(file_out);
997 bs = inode_out->i_sb->s_blocksize;
998
999 /* Don't touch certain kinds of inodes */
1000 if (IS_IMMUTABLE(inode_out))
1001 return -EPERM;
1002 if (IS_SWAPFILE(inode_in) ||
1003 IS_SWAPFILE(inode_out))
1004 return -ETXTBSY;
1005
1006 /* Reflink only works within this filesystem. */
1007 if (inode_in->i_sb != inode_out->i_sb)
1008 return -EXDEV;
1009 same_inode = (inode_in->i_ino == inode_out->i_ino);
1010
1011 /* Don't reflink dirs, pipes, sockets... */
1012 if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
1013 return -EISDIR;
1014 if (S_ISFIFO(inode_in->i_mode) || S_ISFIFO(inode_out->i_mode))
1015 return -EINVAL;
1016 if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
1017 return -EINVAL;
1018
1019 /* Don't share DAX file data for now. */
1020 if (IS_DAX(inode_in) || IS_DAX(inode_out))
1021 return -EINVAL;
1022
1023 /* Are we going all the way to the end? */
1024 isize = i_size_read(inode_in);
1025 if (isize == 0)
1026 return 0;
1027 if (len == 0)
1028 len = isize - pos_in;
1029
1030 /* Ensure offsets don't wrap and the input is inside i_size */
1031 if (pos_in + len < pos_in || pos_out + len < pos_out ||
1032 pos_in + len > isize)
1033 return -EINVAL;
1034
1035 /* Don't allow dedupe past EOF in the dest file */
1036 if (is_dedupe) {
1037 loff_t disize;
1038
1039 disize = i_size_read(inode_out);
1040 if (pos_out >= disize || pos_out + len > disize)
1041 return -EINVAL;
1042 }
1043
1044 /* If we're linking to EOF, continue to the block boundary. */
1045 if (pos_in + len == isize)
1046 blen = ALIGN(isize, bs) - pos_in;
1047 else
1048 blen = len;
1049
1050 /* Only reflink if we're aligned to block boundaries */
1051 if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_in + blen, bs) ||
1052 !IS_ALIGNED(pos_out, bs) || !IS_ALIGNED(pos_out + blen, bs))
1053 return -EINVAL;
1054
1055 /* Don't allow overlapped reflink within the same file */
1056 if (same_inode && pos_out + blen > pos_in && pos_out < pos_in + blen)
1057 return -EINVAL;
1058
1059 /* Wait for the completion of any pending IOs on srcfile */
1060 ret = xfs_file_wait_for_io(inode_in, pos_in, len);
1061 if (ret)
1062 goto out;
1063 ret = xfs_file_wait_for_io(inode_out, pos_out, len);
1064 if (ret)
1065 goto out;
1066
1067 if (is_dedupe)
1068 flags |= XFS_REFLINK_DEDUPE;
1069 ret = xfs_reflink_remap_range(XFS_I(inode_in), pos_in, XFS_I(inode_out),
1070 pos_out, len, flags);
1071 if (ret < 0)
1072 goto out;
1073
1074out:
1075 return ret;
1076}
1077
1078STATIC ssize_t 912STATIC ssize_t
1079xfs_file_copy_range( 913xfs_file_copy_range(
1080 struct file *file_in, 914 struct file *file_in,
@@ -1086,7 +920,7 @@ xfs_file_copy_range(
1086{ 920{
1087 int error; 921 int error;
1088 922
1089 error = xfs_file_share_range(file_in, pos_in, file_out, pos_out, 923 error = xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out,
1090 len, false); 924 len, false);
1091 if (error) 925 if (error)
1092 return error; 926 return error;
@@ -1101,7 +935,7 @@ xfs_file_clone_range(
1101 loff_t pos_out, 935 loff_t pos_out,
1102 u64 len) 936 u64 len)
1103{ 937{
1104 return xfs_file_share_range(file_in, pos_in, file_out, pos_out, 938 return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out,
1105 len, false); 939 len, false);
1106} 940}
1107 941
@@ -1124,7 +958,7 @@ xfs_file_dedupe_range(
1124 if (len > XFS_MAX_DEDUPE_LEN) 958 if (len > XFS_MAX_DEDUPE_LEN)
1125 len = XFS_MAX_DEDUPE_LEN; 959 len = XFS_MAX_DEDUPE_LEN;
1126 960
1127 error = xfs_file_share_range(src_file, loff, dst_file, dst_loff, 961 error = xfs_reflink_remap_range(src_file, loff, dst_file, dst_loff,
1128 len, true); 962 len, true);
1129 if (error) 963 if (error)
1130 return error; 964 return error;
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index 14796b744e0a..f295049db681 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -1656,9 +1656,9 @@ void
1656xfs_inode_set_cowblocks_tag( 1656xfs_inode_set_cowblocks_tag(
1657 xfs_inode_t *ip) 1657 xfs_inode_t *ip)
1658{ 1658{
1659 trace_xfs_inode_set_eofblocks_tag(ip); 1659 trace_xfs_inode_set_cowblocks_tag(ip);
1660 return __xfs_inode_set_eofblocks_tag(ip, xfs_queue_cowblocks, 1660 return __xfs_inode_set_eofblocks_tag(ip, xfs_queue_cowblocks,
1661 trace_xfs_perag_set_eofblocks, 1661 trace_xfs_perag_set_cowblocks,
1662 XFS_ICI_COWBLOCKS_TAG); 1662 XFS_ICI_COWBLOCKS_TAG);
1663} 1663}
1664 1664
@@ -1666,7 +1666,7 @@ void
1666xfs_inode_clear_cowblocks_tag( 1666xfs_inode_clear_cowblocks_tag(
1667 xfs_inode_t *ip) 1667 xfs_inode_t *ip)
1668{ 1668{
1669 trace_xfs_inode_clear_eofblocks_tag(ip); 1669 trace_xfs_inode_clear_cowblocks_tag(ip);
1670 return __xfs_inode_clear_eofblocks_tag(ip, 1670 return __xfs_inode_clear_eofblocks_tag(ip,
1671 trace_xfs_perag_clear_eofblocks, XFS_ICI_COWBLOCKS_TAG); 1671 trace_xfs_perag_clear_cowblocks, XFS_ICI_COWBLOCKS_TAG);
1672} 1672}
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index d907eb9f8ef3..436e109bb01e 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -566,6 +566,17 @@ xfs_file_iomap_begin_delay(
566 xfs_bmap_search_extents(ip, offset_fsb, XFS_DATA_FORK, &eof, &idx, 566 xfs_bmap_search_extents(ip, offset_fsb, XFS_DATA_FORK, &eof, &idx,
567 &got, &prev); 567 &got, &prev);
568 if (!eof && got.br_startoff <= offset_fsb) { 568 if (!eof && got.br_startoff <= offset_fsb) {
569 if (xfs_is_reflink_inode(ip)) {
570 bool shared;
571
572 end_fsb = min(XFS_B_TO_FSB(mp, offset + count),
573 maxbytes_fsb);
574 xfs_trim_extent(&got, offset_fsb, end_fsb - offset_fsb);
575 error = xfs_reflink_reserve_cow(ip, &got, &shared);
576 if (error)
577 goto out_unlock;
578 }
579
569 trace_xfs_iomap_found(ip, offset, count, 0, &got); 580 trace_xfs_iomap_found(ip, offset, count, 0, &got);
570 goto done; 581 goto done;
571 } 582 }
@@ -961,19 +972,13 @@ xfs_file_iomap_begin(
961 struct xfs_mount *mp = ip->i_mount; 972 struct xfs_mount *mp = ip->i_mount;
962 struct xfs_bmbt_irec imap; 973 struct xfs_bmbt_irec imap;
963 xfs_fileoff_t offset_fsb, end_fsb; 974 xfs_fileoff_t offset_fsb, end_fsb;
964 bool shared, trimmed;
965 int nimaps = 1, error = 0; 975 int nimaps = 1, error = 0;
976 bool shared = false, trimmed = false;
966 unsigned lockmode; 977 unsigned lockmode;
967 978
968 if (XFS_FORCED_SHUTDOWN(mp)) 979 if (XFS_FORCED_SHUTDOWN(mp))
969 return -EIO; 980 return -EIO;
970 981
971 if ((flags & (IOMAP_WRITE | IOMAP_ZERO)) && xfs_is_reflink_inode(ip)) {
972 error = xfs_reflink_reserve_cow_range(ip, offset, length);
973 if (error < 0)
974 return error;
975 }
976
977 if ((flags & IOMAP_WRITE) && !IS_DAX(inode) && 982 if ((flags & IOMAP_WRITE) && !IS_DAX(inode) &&
978 !xfs_get_extsz_hint(ip)) { 983 !xfs_get_extsz_hint(ip)) {
979 /* Reserve delalloc blocks for regular writeback. */ 984 /* Reserve delalloc blocks for regular writeback. */
@@ -981,7 +986,16 @@ xfs_file_iomap_begin(
981 iomap); 986 iomap);
982 } 987 }
983 988
984 lockmode = xfs_ilock_data_map_shared(ip); 989 /*
990 * COW writes will allocate delalloc space, so we need to make sure
991 * to take the lock exclusively here.
992 */
993 if ((flags & (IOMAP_WRITE | IOMAP_ZERO)) && xfs_is_reflink_inode(ip)) {
994 lockmode = XFS_ILOCK_EXCL;
995 xfs_ilock(ip, XFS_ILOCK_EXCL);
996 } else {
997 lockmode = xfs_ilock_data_map_shared(ip);
998 }
985 999
986 ASSERT(offset <= mp->m_super->s_maxbytes); 1000 ASSERT(offset <= mp->m_super->s_maxbytes);
987 if ((xfs_fsize_t)offset + length > mp->m_super->s_maxbytes) 1001 if ((xfs_fsize_t)offset + length > mp->m_super->s_maxbytes)
@@ -991,16 +1005,24 @@ xfs_file_iomap_begin(
991 1005
992 error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap, 1006 error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
993 &nimaps, 0); 1007 &nimaps, 0);
994 if (error) { 1008 if (error)
995 xfs_iunlock(ip, lockmode); 1009 goto out_unlock;
996 return error; 1010
1011 if (flags & IOMAP_REPORT) {
1012 /* Trim the mapping to the nearest shared extent boundary. */
1013 error = xfs_reflink_trim_around_shared(ip, &imap, &shared,
1014 &trimmed);
1015 if (error)
1016 goto out_unlock;
997 } 1017 }
998 1018
999 /* Trim the mapping to the nearest shared extent boundary. */ 1019 if ((flags & (IOMAP_WRITE | IOMAP_ZERO)) && xfs_is_reflink_inode(ip)) {
1000 error = xfs_reflink_trim_around_shared(ip, &imap, &shared, &trimmed); 1020 error = xfs_reflink_reserve_cow(ip, &imap, &shared);
1001 if (error) { 1021 if (error)
1002 xfs_iunlock(ip, lockmode); 1022 goto out_unlock;
1003 return error; 1023
1024 end_fsb = imap.br_startoff + imap.br_blockcount;
1025 length = XFS_FSB_TO_B(mp, end_fsb) - offset;
1004 } 1026 }
1005 1027
1006 if ((flags & IOMAP_WRITE) && imap_needs_alloc(inode, &imap, nimaps)) { 1028 if ((flags & IOMAP_WRITE) && imap_needs_alloc(inode, &imap, nimaps)) {
@@ -1039,6 +1061,9 @@ xfs_file_iomap_begin(
1039 if (shared) 1061 if (shared)
1040 iomap->flags |= IOMAP_F_SHARED; 1062 iomap->flags |= IOMAP_F_SHARED;
1041 return 0; 1063 return 0;
1064out_unlock:
1065 xfs_iunlock(ip, lockmode);
1066 return error;
1042} 1067}
1043 1068
1044static int 1069static int
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index fc7873942bea..b341f10cf481 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -1009,6 +1009,7 @@ xfs_mountfs(
1009 out_quota: 1009 out_quota:
1010 xfs_qm_unmount_quotas(mp); 1010 xfs_qm_unmount_quotas(mp);
1011 out_rtunmount: 1011 out_rtunmount:
1012 mp->m_super->s_flags &= ~MS_ACTIVE;
1012 xfs_rtunmount_inodes(mp); 1013 xfs_rtunmount_inodes(mp);
1013 out_rele_rip: 1014 out_rele_rip:
1014 IRELE(rip); 1015 IRELE(rip);
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 5965e9455d91..a279b4e7f5fe 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -182,7 +182,8 @@ xfs_reflink_trim_around_shared(
182 if (!xfs_is_reflink_inode(ip) || 182 if (!xfs_is_reflink_inode(ip) ||
183 ISUNWRITTEN(irec) || 183 ISUNWRITTEN(irec) ||
184 irec->br_startblock == HOLESTARTBLOCK || 184 irec->br_startblock == HOLESTARTBLOCK ||
185 irec->br_startblock == DELAYSTARTBLOCK) { 185 irec->br_startblock == DELAYSTARTBLOCK ||
186 isnullstartblock(irec->br_startblock)) {
186 *shared = false; 187 *shared = false;
187 return 0; 188 return 0;
188 } 189 }
@@ -227,50 +228,54 @@ xfs_reflink_trim_around_shared(
227 } 228 }
228} 229}
229 230
230/* Create a CoW reservation for a range of blocks within a file. */ 231/*
231static int 232 * Trim the passed in imap to the next shared/unshared extent boundary, and
232__xfs_reflink_reserve_cow( 233 * if imap->br_startoff points to a shared extent reserve space for it in the
234 * COW fork. In this case *shared is set to true, else to false.
235 *
236 * Note that imap will always contain the block numbers for the existing blocks
237 * in the data fork, as the upper layers need them for read-modify-write
238 * operations.
239 */
240int
241xfs_reflink_reserve_cow(
233 struct xfs_inode *ip, 242 struct xfs_inode *ip,
234 xfs_fileoff_t *offset_fsb, 243 struct xfs_bmbt_irec *imap,
235 xfs_fileoff_t end_fsb, 244 bool *shared)
236 bool *skipped)
237{ 245{
238 struct xfs_bmbt_irec got, prev, imap; 246 struct xfs_bmbt_irec got, prev;
239 xfs_fileoff_t orig_end_fsb; 247 xfs_fileoff_t end_fsb, orig_end_fsb;
240 int nimaps, eof = 0, error = 0; 248 int eof = 0, error = 0;
241 bool shared = false, trimmed = false; 249 bool trimmed;
242 xfs_extnum_t idx; 250 xfs_extnum_t idx;
243 xfs_extlen_t align; 251 xfs_extlen_t align;
244 252
245 /* Already reserved? Skip the refcount btree access. */ 253 /*
246 xfs_bmap_search_extents(ip, *offset_fsb, XFS_COW_FORK, &eof, &idx, 254 * Search the COW fork extent list first. This serves two purposes:
255 * first this implement the speculative preallocation using cowextisze,
256 * so that we also unshared block adjacent to shared blocks instead
257 * of just the shared blocks themselves. Second the lookup in the
258 * extent list is generally faster than going out to the shared extent
259 * tree.
260 */
261 xfs_bmap_search_extents(ip, imap->br_startoff, XFS_COW_FORK, &eof, &idx,
247 &got, &prev); 262 &got, &prev);
248 if (!eof && got.br_startoff <= *offset_fsb) { 263 if (!eof && got.br_startoff <= imap->br_startoff) {
249 end_fsb = orig_end_fsb = got.br_startoff + got.br_blockcount; 264 trace_xfs_reflink_cow_found(ip, imap);
250 trace_xfs_reflink_cow_found(ip, &got); 265 xfs_trim_extent(imap, got.br_startoff, got.br_blockcount);
251 goto done;
252 }
253 266
254 /* Read extent from the source file. */ 267 *shared = true;
255 nimaps = 1; 268 return 0;
256 error = xfs_bmapi_read(ip, *offset_fsb, end_fsb - *offset_fsb, 269 }
257 &imap, &nimaps, 0);
258 if (error)
259 goto out_unlock;
260 ASSERT(nimaps == 1);
261 270
262 /* Trim the mapping to the nearest shared extent boundary. */ 271 /* Trim the mapping to the nearest shared extent boundary. */
263 error = xfs_reflink_trim_around_shared(ip, &imap, &shared, &trimmed); 272 error = xfs_reflink_trim_around_shared(ip, imap, shared, &trimmed);
264 if (error) 273 if (error)
265 goto out_unlock; 274 return error;
266
267 end_fsb = orig_end_fsb = imap.br_startoff + imap.br_blockcount;
268 275
269 /* Not shared? Just report the (potentially capped) extent. */ 276 /* Not shared? Just report the (potentially capped) extent. */
270 if (!shared) { 277 if (!*shared)
271 *skipped = true; 278 return 0;
272 goto done;
273 }
274 279
275 /* 280 /*
276 * Fork all the shared blocks from our write offset until the end of 281 * Fork all the shared blocks from our write offset until the end of
@@ -278,72 +283,38 @@ __xfs_reflink_reserve_cow(
278 */ 283 */
279 error = xfs_qm_dqattach_locked(ip, 0); 284 error = xfs_qm_dqattach_locked(ip, 0);
280 if (error) 285 if (error)
281 goto out_unlock; 286 return error;
287
288 end_fsb = orig_end_fsb = imap->br_startoff + imap->br_blockcount;
282 289
283 align = xfs_eof_alignment(ip, xfs_get_cowextsz_hint(ip)); 290 align = xfs_eof_alignment(ip, xfs_get_cowextsz_hint(ip));
284 if (align) 291 if (align)
285 end_fsb = roundup_64(end_fsb, align); 292 end_fsb = roundup_64(end_fsb, align);
286 293
287retry: 294retry:
288 error = xfs_bmapi_reserve_delalloc(ip, XFS_COW_FORK, *offset_fsb, 295 error = xfs_bmapi_reserve_delalloc(ip, XFS_COW_FORK, imap->br_startoff,
289 end_fsb - *offset_fsb, &got, 296 end_fsb - imap->br_startoff, &got, &prev, &idx, eof);
290 &prev, &idx, eof);
291 switch (error) { 297 switch (error) {
292 case 0: 298 case 0:
293 break; 299 break;
294 case -ENOSPC: 300 case -ENOSPC:
295 case -EDQUOT: 301 case -EDQUOT:
296 /* retry without any preallocation */ 302 /* retry without any preallocation */
297 trace_xfs_reflink_cow_enospc(ip, &imap); 303 trace_xfs_reflink_cow_enospc(ip, imap);
298 if (end_fsb != orig_end_fsb) { 304 if (end_fsb != orig_end_fsb) {
299 end_fsb = orig_end_fsb; 305 end_fsb = orig_end_fsb;
300 goto retry; 306 goto retry;
301 } 307 }
302 /*FALLTHRU*/ 308 /*FALLTHRU*/
303 default: 309 default:
304 goto out_unlock; 310 return error;
305 } 311 }
306 312
307 if (end_fsb != orig_end_fsb) 313 if (end_fsb != orig_end_fsb)
308 xfs_inode_set_cowblocks_tag(ip); 314 xfs_inode_set_cowblocks_tag(ip);
309 315
310 trace_xfs_reflink_cow_alloc(ip, &got); 316 trace_xfs_reflink_cow_alloc(ip, &got);
311done: 317 return 0;
312 *offset_fsb = end_fsb;
313out_unlock:
314 return error;
315}
316
317/* Create a CoW reservation for part of a file. */
318int
319xfs_reflink_reserve_cow_range(
320 struct xfs_inode *ip,
321 xfs_off_t offset,
322 xfs_off_t count)
323{
324 struct xfs_mount *mp = ip->i_mount;
325 xfs_fileoff_t offset_fsb, end_fsb;
326 bool skipped = false;
327 int error;
328
329 trace_xfs_reflink_reserve_cow_range(ip, offset, count);
330
331 offset_fsb = XFS_B_TO_FSBT(mp, offset);
332 end_fsb = XFS_B_TO_FSB(mp, offset + count);
333
334 xfs_ilock(ip, XFS_ILOCK_EXCL);
335 while (offset_fsb < end_fsb) {
336 error = __xfs_reflink_reserve_cow(ip, &offset_fsb, end_fsb,
337 &skipped);
338 if (error) {
339 trace_xfs_reflink_reserve_cow_range_error(ip, error,
340 _RET_IP_);
341 break;
342 }
343 }
344 xfs_iunlock(ip, XFS_ILOCK_EXCL);
345
346 return error;
347} 318}
348 319
349/* Allocate all CoW reservations covering a range of blocks in a file. */ 320/* Allocate all CoW reservations covering a range of blocks in a file. */
@@ -358,9 +329,8 @@ __xfs_reflink_allocate_cow(
358 struct xfs_defer_ops dfops; 329 struct xfs_defer_ops dfops;
359 struct xfs_trans *tp; 330 struct xfs_trans *tp;
360 xfs_fsblock_t first_block; 331 xfs_fsblock_t first_block;
361 xfs_fileoff_t next_fsb;
362 int nimaps = 1, error; 332 int nimaps = 1, error;
363 bool skipped = false; 333 bool shared;
364 334
365 xfs_defer_init(&dfops, &first_block); 335 xfs_defer_init(&dfops, &first_block);
366 336
@@ -371,33 +341,38 @@ __xfs_reflink_allocate_cow(
371 341
372 xfs_ilock(ip, XFS_ILOCK_EXCL); 342 xfs_ilock(ip, XFS_ILOCK_EXCL);
373 343
374 next_fsb = *offset_fsb; 344 /* Read extent from the source file. */
375 error = __xfs_reflink_reserve_cow(ip, &next_fsb, end_fsb, &skipped); 345 nimaps = 1;
346 error = xfs_bmapi_read(ip, *offset_fsb, end_fsb - *offset_fsb,
347 &imap, &nimaps, 0);
348 if (error)
349 goto out_unlock;
350 ASSERT(nimaps == 1);
351
352 error = xfs_reflink_reserve_cow(ip, &imap, &shared);
376 if (error) 353 if (error)
377 goto out_trans_cancel; 354 goto out_trans_cancel;
378 355
379 if (skipped) { 356 if (!shared) {
380 *offset_fsb = next_fsb; 357 *offset_fsb = imap.br_startoff + imap.br_blockcount;
381 goto out_trans_cancel; 358 goto out_trans_cancel;
382 } 359 }
383 360
384 xfs_trans_ijoin(tp, ip, 0); 361 xfs_trans_ijoin(tp, ip, 0);
385 error = xfs_bmapi_write(tp, ip, *offset_fsb, next_fsb - *offset_fsb, 362 error = xfs_bmapi_write(tp, ip, imap.br_startoff, imap.br_blockcount,
386 XFS_BMAPI_COWFORK, &first_block, 363 XFS_BMAPI_COWFORK, &first_block,
387 XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK), 364 XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK),
388 &imap, &nimaps, &dfops); 365 &imap, &nimaps, &dfops);
389 if (error) 366 if (error)
390 goto out_trans_cancel; 367 goto out_trans_cancel;
391 368
392 /* We might not have been able to map the whole delalloc extent */
393 *offset_fsb = min(*offset_fsb + imap.br_blockcount, next_fsb);
394
395 error = xfs_defer_finish(&tp, &dfops, NULL); 369 error = xfs_defer_finish(&tp, &dfops, NULL);
396 if (error) 370 if (error)
397 goto out_trans_cancel; 371 goto out_trans_cancel;
398 372
399 error = xfs_trans_commit(tp); 373 error = xfs_trans_commit(tp);
400 374
375 *offset_fsb = imap.br_startoff + imap.br_blockcount;
401out_unlock: 376out_unlock:
402 xfs_iunlock(ip, XFS_ILOCK_EXCL); 377 xfs_iunlock(ip, XFS_ILOCK_EXCL);
403 return error; 378 return error;
@@ -536,58 +511,49 @@ xfs_reflink_cancel_cow_blocks(
536 xfs_fileoff_t offset_fsb, 511 xfs_fileoff_t offset_fsb,
537 xfs_fileoff_t end_fsb) 512 xfs_fileoff_t end_fsb)
538{ 513{
539 struct xfs_bmbt_irec irec; 514 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
540 xfs_filblks_t count_fsb; 515 struct xfs_bmbt_irec got, prev, del;
516 xfs_extnum_t idx;
541 xfs_fsblock_t firstfsb; 517 xfs_fsblock_t firstfsb;
542 struct xfs_defer_ops dfops; 518 struct xfs_defer_ops dfops;
543 int error = 0; 519 int error = 0, eof = 0;
544 int nimaps;
545 520
546 if (!xfs_is_reflink_inode(ip)) 521 if (!xfs_is_reflink_inode(ip))
547 return 0; 522 return 0;
548 523
549 /* Go find the old extent in the CoW fork. */ 524 xfs_bmap_search_extents(ip, offset_fsb, XFS_COW_FORK, &eof, &idx,
550 while (offset_fsb < end_fsb) { 525 &got, &prev);
551 nimaps = 1; 526 if (eof)
552 count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb); 527 return 0;
553 error = xfs_bmapi_read(ip, offset_fsb, count_fsb, &irec,
554 &nimaps, XFS_BMAPI_COWFORK);
555 if (error)
556 break;
557 ASSERT(nimaps == 1);
558
559 trace_xfs_reflink_cancel_cow(ip, &irec);
560 528
561 if (irec.br_startblock == DELAYSTARTBLOCK) { 529 while (got.br_startoff < end_fsb) {
562 /* Free a delayed allocation. */ 530 del = got;
563 xfs_mod_fdblocks(ip->i_mount, irec.br_blockcount, 531 xfs_trim_extent(&del, offset_fsb, end_fsb - offset_fsb);
564 false); 532 trace_xfs_reflink_cancel_cow(ip, &del);
565 ip->i_delayed_blks -= irec.br_blockcount;
566 533
567 /* Remove the mapping from the CoW fork. */ 534 if (isnullstartblock(del.br_startblock)) {
568 error = xfs_bunmapi_cow(ip, &irec); 535 error = xfs_bmap_del_extent_delay(ip, XFS_COW_FORK,
536 &idx, &got, &del);
569 if (error) 537 if (error)
570 break; 538 break;
571 } else if (irec.br_startblock == HOLESTARTBLOCK) {
572 /* empty */
573 } else { 539 } else {
574 xfs_trans_ijoin(*tpp, ip, 0); 540 xfs_trans_ijoin(*tpp, ip, 0);
575 xfs_defer_init(&dfops, &firstfsb); 541 xfs_defer_init(&dfops, &firstfsb);
576 542
577 /* Free the CoW orphan record. */ 543 /* Free the CoW orphan record. */
578 error = xfs_refcount_free_cow_extent(ip->i_mount, 544 error = xfs_refcount_free_cow_extent(ip->i_mount,
579 &dfops, irec.br_startblock, 545 &dfops, del.br_startblock,
580 irec.br_blockcount); 546 del.br_blockcount);
581 if (error) 547 if (error)
582 break; 548 break;
583 549
584 xfs_bmap_add_free(ip->i_mount, &dfops, 550 xfs_bmap_add_free(ip->i_mount, &dfops,
585 irec.br_startblock, irec.br_blockcount, 551 del.br_startblock, del.br_blockcount,
586 NULL); 552 NULL);
587 553
588 /* Update quota accounting */ 554 /* Update quota accounting */
589 xfs_trans_mod_dquot_byino(*tpp, ip, XFS_TRANS_DQ_BCOUNT, 555 xfs_trans_mod_dquot_byino(*tpp, ip, XFS_TRANS_DQ_BCOUNT,
590 -(long)irec.br_blockcount); 556 -(long)del.br_blockcount);
591 557
592 /* Roll the transaction */ 558 /* Roll the transaction */
593 error = xfs_defer_finish(tpp, &dfops, ip); 559 error = xfs_defer_finish(tpp, &dfops, ip);
@@ -597,15 +563,18 @@ xfs_reflink_cancel_cow_blocks(
597 } 563 }
598 564
599 /* Remove the mapping from the CoW fork. */ 565 /* Remove the mapping from the CoW fork. */
600 error = xfs_bunmapi_cow(ip, &irec); 566 xfs_bmap_del_extent_cow(ip, &idx, &got, &del);
601 if (error)
602 break;
603 } 567 }
604 568
605 /* Roll on... */ 569 if (++idx >= ifp->if_bytes / sizeof(struct xfs_bmbt_rec))
606 offset_fsb = irec.br_startoff + irec.br_blockcount; 570 break;
571 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), &got);
607 } 572 }
608 573
574 /* clear tag if cow fork is emptied */
575 if (!ifp->if_bytes)
576 xfs_inode_clear_cowblocks_tag(ip);
577
609 return error; 578 return error;
610} 579}
611 580
@@ -668,25 +637,26 @@ xfs_reflink_end_cow(
668 xfs_off_t offset, 637 xfs_off_t offset,
669 xfs_off_t count) 638 xfs_off_t count)
670{ 639{
671 struct xfs_bmbt_irec irec; 640 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
672 struct xfs_bmbt_irec uirec; 641 struct xfs_bmbt_irec got, prev, del;
673 struct xfs_trans *tp; 642 struct xfs_trans *tp;
674 xfs_fileoff_t offset_fsb; 643 xfs_fileoff_t offset_fsb;
675 xfs_fileoff_t end_fsb; 644 xfs_fileoff_t end_fsb;
676 xfs_filblks_t count_fsb;
677 xfs_fsblock_t firstfsb; 645 xfs_fsblock_t firstfsb;
678 struct xfs_defer_ops dfops; 646 struct xfs_defer_ops dfops;
679 int error; 647 int error, eof = 0;
680 unsigned int resblks; 648 unsigned int resblks;
681 xfs_filblks_t ilen;
682 xfs_filblks_t rlen; 649 xfs_filblks_t rlen;
683 int nimaps; 650 xfs_extnum_t idx;
684 651
685 trace_xfs_reflink_end_cow(ip, offset, count); 652 trace_xfs_reflink_end_cow(ip, offset, count);
686 653
654 /* No COW extents? That's easy! */
655 if (ifp->if_bytes == 0)
656 return 0;
657
687 offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); 658 offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset);
688 end_fsb = XFS_B_TO_FSB(ip->i_mount, offset + count); 659 end_fsb = XFS_B_TO_FSB(ip->i_mount, offset + count);
689 count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb);
690 660
691 /* Start a rolling transaction to switch the mappings */ 661 /* Start a rolling transaction to switch the mappings */
692 resblks = XFS_EXTENTADD_SPACE_RES(ip->i_mount, XFS_DATA_FORK); 662 resblks = XFS_EXTENTADD_SPACE_RES(ip->i_mount, XFS_DATA_FORK);
@@ -698,72 +668,65 @@ xfs_reflink_end_cow(
698 xfs_ilock(ip, XFS_ILOCK_EXCL); 668 xfs_ilock(ip, XFS_ILOCK_EXCL);
699 xfs_trans_ijoin(tp, ip, 0); 669 xfs_trans_ijoin(tp, ip, 0);
700 670
701 /* Go find the old extent in the CoW fork. */ 671 xfs_bmap_search_extents(ip, end_fsb - 1, XFS_COW_FORK, &eof, &idx,
702 while (offset_fsb < end_fsb) { 672 &got, &prev);
703 /* Read extent from the source file */
704 nimaps = 1;
705 count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb);
706 error = xfs_bmapi_read(ip, offset_fsb, count_fsb, &irec,
707 &nimaps, XFS_BMAPI_COWFORK);
708 if (error)
709 goto out_cancel;
710 ASSERT(nimaps == 1);
711 673
712 ASSERT(irec.br_startblock != DELAYSTARTBLOCK); 674 /* If there is a hole at end_fsb - 1 go to the previous extent */
713 trace_xfs_reflink_cow_remap(ip, &irec); 675 if (eof || got.br_startoff > end_fsb) {
676 ASSERT(idx > 0);
677 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, --idx), &got);
678 }
714 679
715 /* 680 /* Walk backwards until we're out of the I/O range... */
716 * We can have a hole in the CoW fork if part of a directio 681 while (got.br_startoff + got.br_blockcount > offset_fsb) {
717 * write is CoW but part of it isn't. 682 del = got;
718 */ 683 xfs_trim_extent(&del, offset_fsb, end_fsb - offset_fsb);
719 rlen = ilen = irec.br_blockcount; 684
720 if (irec.br_startblock == HOLESTARTBLOCK) 685 /* Extent delete may have bumped idx forward */
686 if (!del.br_blockcount) {
687 idx--;
721 goto next_extent; 688 goto next_extent;
689 }
690
691 ASSERT(!isnullstartblock(got.br_startblock));
722 692
723 /* Unmap the old blocks in the data fork. */ 693 /* Unmap the old blocks in the data fork. */
724 while (rlen) { 694 xfs_defer_init(&dfops, &firstfsb);
725 xfs_defer_init(&dfops, &firstfsb); 695 rlen = del.br_blockcount;
726 error = __xfs_bunmapi(tp, ip, irec.br_startoff, 696 error = __xfs_bunmapi(tp, ip, del.br_startoff, &rlen, 0, 1,
727 &rlen, 0, 1, &firstfsb, &dfops); 697 &firstfsb, &dfops);
728 if (error) 698 if (error)
729 goto out_defer; 699 goto out_defer;
730
731 /*
732 * Trim the extent to whatever got unmapped.
733 * Remember, bunmapi works backwards.
734 */
735 uirec.br_startblock = irec.br_startblock + rlen;
736 uirec.br_startoff = irec.br_startoff + rlen;
737 uirec.br_blockcount = irec.br_blockcount - rlen;
738 irec.br_blockcount = rlen;
739 trace_xfs_reflink_cow_remap_piece(ip, &uirec);
740 700
741 /* Free the CoW orphan record. */ 701 /* Trim the extent to whatever got unmapped. */
742 error = xfs_refcount_free_cow_extent(tp->t_mountp, 702 if (rlen) {
743 &dfops, uirec.br_startblock, 703 xfs_trim_extent(&del, del.br_startoff + rlen,
744 uirec.br_blockcount); 704 del.br_blockcount - rlen);
745 if (error) 705 }
746 goto out_defer; 706 trace_xfs_reflink_cow_remap(ip, &del);
747 707
748 /* Map the new blocks into the data fork. */ 708 /* Free the CoW orphan record. */
749 error = xfs_bmap_map_extent(tp->t_mountp, &dfops, 709 error = xfs_refcount_free_cow_extent(tp->t_mountp, &dfops,
750 ip, &uirec); 710 del.br_startblock, del.br_blockcount);
751 if (error) 711 if (error)
752 goto out_defer; 712 goto out_defer;
753 713
754 /* Remove the mapping from the CoW fork. */ 714 /* Map the new blocks into the data fork. */
755 error = xfs_bunmapi_cow(ip, &uirec); 715 error = xfs_bmap_map_extent(tp->t_mountp, &dfops, ip, &del);
756 if (error) 716 if (error)
757 goto out_defer; 717 goto out_defer;
758 718
759 error = xfs_defer_finish(&tp, &dfops, ip); 719 /* Remove the mapping from the CoW fork. */
760 if (error) 720 xfs_bmap_del_extent_cow(ip, &idx, &got, &del);
761 goto out_defer; 721
762 } 722 error = xfs_defer_finish(&tp, &dfops, ip);
723 if (error)
724 goto out_defer;
763 725
764next_extent: 726next_extent:
765 /* Roll on... */ 727 if (idx < 0)
766 offset_fsb = irec.br_startoff + ilen; 728 break;
729 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), &got);
767 } 730 }
768 731
769 error = xfs_trans_commit(tp); 732 error = xfs_trans_commit(tp);
@@ -774,7 +737,6 @@ next_extent:
774 737
775out_defer: 738out_defer:
776 xfs_defer_cancel(&dfops); 739 xfs_defer_cancel(&dfops);
777out_cancel:
778 xfs_trans_cancel(tp); 740 xfs_trans_cancel(tp);
779 xfs_iunlock(ip, XFS_ILOCK_EXCL); 741 xfs_iunlock(ip, XFS_ILOCK_EXCL);
780out: 742out:
@@ -1312,19 +1274,26 @@ out_error:
1312 */ 1274 */
1313int 1275int
1314xfs_reflink_remap_range( 1276xfs_reflink_remap_range(
1315 struct xfs_inode *src, 1277 struct file *file_in,
1316 xfs_off_t srcoff, 1278 loff_t pos_in,
1317 struct xfs_inode *dest, 1279 struct file *file_out,
1318 xfs_off_t destoff, 1280 loff_t pos_out,
1319 xfs_off_t len, 1281 u64 len,
1320 unsigned int flags) 1282 bool is_dedupe)
1321{ 1283{
1284 struct inode *inode_in = file_inode(file_in);
1285 struct xfs_inode *src = XFS_I(inode_in);
1286 struct inode *inode_out = file_inode(file_out);
1287 struct xfs_inode *dest = XFS_I(inode_out);
1322 struct xfs_mount *mp = src->i_mount; 1288 struct xfs_mount *mp = src->i_mount;
1289 loff_t bs = inode_out->i_sb->s_blocksize;
1290 bool same_inode = (inode_in == inode_out);
1323 xfs_fileoff_t sfsbno, dfsbno; 1291 xfs_fileoff_t sfsbno, dfsbno;
1324 xfs_filblks_t fsblen; 1292 xfs_filblks_t fsblen;
1325 int error;
1326 xfs_extlen_t cowextsize; 1293 xfs_extlen_t cowextsize;
1327 bool is_same; 1294 loff_t isize;
1295 ssize_t ret;
1296 loff_t blen;
1328 1297
1329 if (!xfs_sb_version_hasreflink(&mp->m_sb)) 1298 if (!xfs_sb_version_hasreflink(&mp->m_sb))
1330 return -EOPNOTSUPP; 1299 return -EOPNOTSUPP;
@@ -1332,17 +1301,8 @@ xfs_reflink_remap_range(
1332 if (XFS_FORCED_SHUTDOWN(mp)) 1301 if (XFS_FORCED_SHUTDOWN(mp))
1333 return -EIO; 1302 return -EIO;
1334 1303
1335 /* Don't reflink realtime inodes */
1336 if (XFS_IS_REALTIME_INODE(src) || XFS_IS_REALTIME_INODE(dest))
1337 return -EINVAL;
1338
1339 if (flags & ~XFS_REFLINK_ALL)
1340 return -EINVAL;
1341
1342 trace_xfs_reflink_remap_range(src, srcoff, len, dest, destoff);
1343
1344 /* Lock both files against IO */ 1304 /* Lock both files against IO */
1345 if (src->i_ino == dest->i_ino) { 1305 if (same_inode) {
1346 xfs_ilock(src, XFS_IOLOCK_EXCL); 1306 xfs_ilock(src, XFS_IOLOCK_EXCL);
1347 xfs_ilock(src, XFS_MMAPLOCK_EXCL); 1307 xfs_ilock(src, XFS_MMAPLOCK_EXCL);
1348 } else { 1308 } else {
@@ -1350,39 +1310,126 @@ xfs_reflink_remap_range(
1350 xfs_lock_two_inodes(src, dest, XFS_MMAPLOCK_EXCL); 1310 xfs_lock_two_inodes(src, dest, XFS_MMAPLOCK_EXCL);
1351 } 1311 }
1352 1312
1313 /* Don't touch certain kinds of inodes */
1314 ret = -EPERM;
1315 if (IS_IMMUTABLE(inode_out))
1316 goto out_unlock;
1317
1318 ret = -ETXTBSY;
1319 if (IS_SWAPFILE(inode_in) || IS_SWAPFILE(inode_out))
1320 goto out_unlock;
1321
1322
1323 /* Don't reflink dirs, pipes, sockets... */
1324 ret = -EISDIR;
1325 if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
1326 goto out_unlock;
1327 ret = -EINVAL;
1328 if (S_ISFIFO(inode_in->i_mode) || S_ISFIFO(inode_out->i_mode))
1329 goto out_unlock;
1330 if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
1331 goto out_unlock;
1332
1333 /* Don't reflink realtime inodes */
1334 if (XFS_IS_REALTIME_INODE(src) || XFS_IS_REALTIME_INODE(dest))
1335 goto out_unlock;
1336
1337 /* Don't share DAX file data for now. */
1338 if (IS_DAX(inode_in) || IS_DAX(inode_out))
1339 goto out_unlock;
1340
1341 /* Are we going all the way to the end? */
1342 isize = i_size_read(inode_in);
1343 if (isize == 0) {
1344 ret = 0;
1345 goto out_unlock;
1346 }
1347
1348 if (len == 0)
1349 len = isize - pos_in;
1350
1351 /* Ensure offsets don't wrap and the input is inside i_size */
1352 if (pos_in + len < pos_in || pos_out + len < pos_out ||
1353 pos_in + len > isize)
1354 goto out_unlock;
1355
1356 /* Don't allow dedupe past EOF in the dest file */
1357 if (is_dedupe) {
1358 loff_t disize;
1359
1360 disize = i_size_read(inode_out);
1361 if (pos_out >= disize || pos_out + len > disize)
1362 goto out_unlock;
1363 }
1364
1365 /* If we're linking to EOF, continue to the block boundary. */
1366 if (pos_in + len == isize)
1367 blen = ALIGN(isize, bs) - pos_in;
1368 else
1369 blen = len;
1370
1371 /* Only reflink if we're aligned to block boundaries */
1372 if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_in + blen, bs) ||
1373 !IS_ALIGNED(pos_out, bs) || !IS_ALIGNED(pos_out + blen, bs))
1374 goto out_unlock;
1375
1376 /* Don't allow overlapped reflink within the same file */
1377 if (same_inode) {
1378 if (pos_out + blen > pos_in && pos_out < pos_in + blen)
1379 goto out_unlock;
1380 }
1381
1382 /* Wait for the completion of any pending IOs on both files */
1383 inode_dio_wait(inode_in);
1384 if (!same_inode)
1385 inode_dio_wait(inode_out);
1386
1387 ret = filemap_write_and_wait_range(inode_in->i_mapping,
1388 pos_in, pos_in + len - 1);
1389 if (ret)
1390 goto out_unlock;
1391
1392 ret = filemap_write_and_wait_range(inode_out->i_mapping,
1393 pos_out, pos_out + len - 1);
1394 if (ret)
1395 goto out_unlock;
1396
1397 trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out);
1398
1353 /* 1399 /*
1354 * Check that the extents are the same. 1400 * Check that the extents are the same.
1355 */ 1401 */
1356 if (flags & XFS_REFLINK_DEDUPE) { 1402 if (is_dedupe) {
1357 is_same = false; 1403 bool is_same = false;
1358 error = xfs_compare_extents(VFS_I(src), srcoff, VFS_I(dest), 1404
1359 destoff, len, &is_same); 1405 ret = xfs_compare_extents(inode_in, pos_in, inode_out, pos_out,
1360 if (error) 1406 len, &is_same);
1361 goto out_error; 1407 if (ret)
1408 goto out_unlock;
1362 if (!is_same) { 1409 if (!is_same) {
1363 error = -EBADE; 1410 ret = -EBADE;
1364 goto out_error; 1411 goto out_unlock;
1365 } 1412 }
1366 } 1413 }
1367 1414
1368 error = xfs_reflink_set_inode_flag(src, dest); 1415 ret = xfs_reflink_set_inode_flag(src, dest);
1369 if (error) 1416 if (ret)
1370 goto out_error; 1417 goto out_unlock;
1371 1418
1372 /* 1419 /*
1373 * Invalidate the page cache so that we can clear any CoW mappings 1420 * Invalidate the page cache so that we can clear any CoW mappings
1374 * in the destination file. 1421 * in the destination file.
1375 */ 1422 */
1376 truncate_inode_pages_range(&VFS_I(dest)->i_data, destoff, 1423 truncate_inode_pages_range(&inode_out->i_data, pos_out,
1377 PAGE_ALIGN(destoff + len) - 1); 1424 PAGE_ALIGN(pos_out + len) - 1);
1378 1425
1379 dfsbno = XFS_B_TO_FSBT(mp, destoff); 1426 dfsbno = XFS_B_TO_FSBT(mp, pos_out);
1380 sfsbno = XFS_B_TO_FSBT(mp, srcoff); 1427 sfsbno = XFS_B_TO_FSBT(mp, pos_in);
1381 fsblen = XFS_B_TO_FSB(mp, len); 1428 fsblen = XFS_B_TO_FSB(mp, len);
1382 error = xfs_reflink_remap_blocks(src, sfsbno, dest, dfsbno, fsblen, 1429 ret = xfs_reflink_remap_blocks(src, sfsbno, dest, dfsbno, fsblen,
1383 destoff + len); 1430 pos_out + len);
1384 if (error) 1431 if (ret)
1385 goto out_error; 1432 goto out_unlock;
1386 1433
1387 /* 1434 /*
1388 * Carry the cowextsize hint from src to dest if we're sharing the 1435 * Carry the cowextsize hint from src to dest if we're sharing the
@@ -1390,26 +1437,24 @@ xfs_reflink_remap_range(
1390 * has a cowextsize hint, and the destination file does not. 1437 * has a cowextsize hint, and the destination file does not.
1391 */ 1438 */
1392 cowextsize = 0; 1439 cowextsize = 0;
1393 if (srcoff == 0 && len == i_size_read(VFS_I(src)) && 1440 if (pos_in == 0 && len == i_size_read(inode_in) &&
1394 (src->i_d.di_flags2 & XFS_DIFLAG2_COWEXTSIZE) && 1441 (src->i_d.di_flags2 & XFS_DIFLAG2_COWEXTSIZE) &&
1395 destoff == 0 && len >= i_size_read(VFS_I(dest)) && 1442 pos_out == 0 && len >= i_size_read(inode_out) &&
1396 !(dest->i_d.di_flags2 & XFS_DIFLAG2_COWEXTSIZE)) 1443 !(dest->i_d.di_flags2 & XFS_DIFLAG2_COWEXTSIZE))
1397 cowextsize = src->i_d.di_cowextsize; 1444 cowextsize = src->i_d.di_cowextsize;
1398 1445
1399 error = xfs_reflink_update_dest(dest, destoff + len, cowextsize); 1446 ret = xfs_reflink_update_dest(dest, pos_out + len, cowextsize);
1400 if (error)
1401 goto out_error;
1402 1447
1403out_error: 1448out_unlock:
1404 xfs_iunlock(src, XFS_MMAPLOCK_EXCL); 1449 xfs_iunlock(src, XFS_MMAPLOCK_EXCL);
1405 xfs_iunlock(src, XFS_IOLOCK_EXCL); 1450 xfs_iunlock(src, XFS_IOLOCK_EXCL);
1406 if (src->i_ino != dest->i_ino) { 1451 if (src->i_ino != dest->i_ino) {
1407 xfs_iunlock(dest, XFS_MMAPLOCK_EXCL); 1452 xfs_iunlock(dest, XFS_MMAPLOCK_EXCL);
1408 xfs_iunlock(dest, XFS_IOLOCK_EXCL); 1453 xfs_iunlock(dest, XFS_IOLOCK_EXCL);
1409 } 1454 }
1410 if (error) 1455 if (ret)
1411 trace_xfs_reflink_remap_range_error(dest, error, _RET_IP_); 1456 trace_xfs_reflink_remap_range_error(dest, ret, _RET_IP_);
1412 return error; 1457 return ret;
1413} 1458}
1414 1459
1415/* 1460/*
diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h
index 5dc3c8ac12aa..fad11607c9ad 100644
--- a/fs/xfs/xfs_reflink.h
+++ b/fs/xfs/xfs_reflink.h
@@ -26,8 +26,8 @@ extern int xfs_reflink_find_shared(struct xfs_mount *mp, xfs_agnumber_t agno,
26extern int xfs_reflink_trim_around_shared(struct xfs_inode *ip, 26extern int xfs_reflink_trim_around_shared(struct xfs_inode *ip,
27 struct xfs_bmbt_irec *irec, bool *shared, bool *trimmed); 27 struct xfs_bmbt_irec *irec, bool *shared, bool *trimmed);
28 28
29extern int xfs_reflink_reserve_cow_range(struct xfs_inode *ip, 29extern int xfs_reflink_reserve_cow(struct xfs_inode *ip,
30 xfs_off_t offset, xfs_off_t count); 30 struct xfs_bmbt_irec *imap, bool *shared);
31extern int xfs_reflink_allocate_cow_range(struct xfs_inode *ip, 31extern int xfs_reflink_allocate_cow_range(struct xfs_inode *ip,
32 xfs_off_t offset, xfs_off_t count); 32 xfs_off_t offset, xfs_off_t count);
33extern bool xfs_reflink_find_cow_mapping(struct xfs_inode *ip, xfs_off_t offset, 33extern bool xfs_reflink_find_cow_mapping(struct xfs_inode *ip, xfs_off_t offset,
@@ -43,11 +43,8 @@ extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset,
43extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset, 43extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset,
44 xfs_off_t count); 44 xfs_off_t count);
45extern int xfs_reflink_recover_cow(struct xfs_mount *mp); 45extern int xfs_reflink_recover_cow(struct xfs_mount *mp);
46#define XFS_REFLINK_DEDUPE 1 /* only reflink if contents match */ 46extern int xfs_reflink_remap_range(struct file *file_in, loff_t pos_in,
47#define XFS_REFLINK_ALL (XFS_REFLINK_DEDUPE) 47 struct file *file_out, loff_t pos_out, u64 len, bool is_dedupe);
48extern int xfs_reflink_remap_range(struct xfs_inode *src, xfs_off_t srcoff,
49 struct xfs_inode *dest, xfs_off_t destoff, xfs_off_t len,
50 unsigned int flags);
51extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip, 48extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip,
52 struct xfs_trans **tpp); 49 struct xfs_trans **tpp);
53extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset, 50extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset,
diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c
index 5f8d55d29a11..276d3023d60f 100644
--- a/fs/xfs/xfs_sysfs.c
+++ b/fs/xfs/xfs_sysfs.c
@@ -512,13 +512,13 @@ static struct attribute *xfs_error_attrs[] = {
512}; 512};
513 513
514 514
515struct kobj_type xfs_error_cfg_ktype = { 515static struct kobj_type xfs_error_cfg_ktype = {
516 .release = xfs_sysfs_release, 516 .release = xfs_sysfs_release,
517 .sysfs_ops = &xfs_sysfs_ops, 517 .sysfs_ops = &xfs_sysfs_ops,
518 .default_attrs = xfs_error_attrs, 518 .default_attrs = xfs_error_attrs,
519}; 519};
520 520
521struct kobj_type xfs_error_ktype = { 521static struct kobj_type xfs_error_ktype = {
522 .release = xfs_sysfs_release, 522 .release = xfs_sysfs_release,
523 .sysfs_ops = &xfs_sysfs_ops, 523 .sysfs_ops = &xfs_sysfs_ops,
524}; 524};
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index ad188d3a83f3..0907752be62d 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -3346,7 +3346,7 @@ DEFINE_INODE_IREC_EVENT(xfs_reflink_cow_alloc);
3346DEFINE_INODE_IREC_EVENT(xfs_reflink_cow_found); 3346DEFINE_INODE_IREC_EVENT(xfs_reflink_cow_found);
3347DEFINE_INODE_IREC_EVENT(xfs_reflink_cow_enospc); 3347DEFINE_INODE_IREC_EVENT(xfs_reflink_cow_enospc);
3348 3348
3349DEFINE_RW_EVENT(xfs_reflink_reserve_cow_range); 3349DEFINE_RW_EVENT(xfs_reflink_reserve_cow);
3350DEFINE_RW_EVENT(xfs_reflink_allocate_cow_range); 3350DEFINE_RW_EVENT(xfs_reflink_allocate_cow_range);
3351 3351
3352DEFINE_INODE_IREC_EVENT(xfs_reflink_bounce_dio_write); 3352DEFINE_INODE_IREC_EVENT(xfs_reflink_bounce_dio_write);
@@ -3356,9 +3356,7 @@ DEFINE_INODE_IREC_EVENT(xfs_reflink_trim_irec);
3356DEFINE_SIMPLE_IO_EVENT(xfs_reflink_cancel_cow_range); 3356DEFINE_SIMPLE_IO_EVENT(xfs_reflink_cancel_cow_range);
3357DEFINE_SIMPLE_IO_EVENT(xfs_reflink_end_cow); 3357DEFINE_SIMPLE_IO_EVENT(xfs_reflink_end_cow);
3358DEFINE_INODE_IREC_EVENT(xfs_reflink_cow_remap); 3358DEFINE_INODE_IREC_EVENT(xfs_reflink_cow_remap);
3359DEFINE_INODE_IREC_EVENT(xfs_reflink_cow_remap_piece);
3360 3359
3361DEFINE_INODE_ERROR_EVENT(xfs_reflink_reserve_cow_range_error);
3362DEFINE_INODE_ERROR_EVENT(xfs_reflink_allocate_cow_range_error); 3360DEFINE_INODE_ERROR_EVENT(xfs_reflink_allocate_cow_range_error);
3363DEFINE_INODE_ERROR_EVENT(xfs_reflink_cancel_cow_range_error); 3361DEFINE_INODE_ERROR_EVENT(xfs_reflink_cancel_cow_range_error);
3364DEFINE_INODE_ERROR_EVENT(xfs_reflink_end_cow_error); 3362DEFINE_INODE_ERROR_EVENT(xfs_reflink_end_cow_error);
diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h
index 43199a049da5..63554e9f6e0c 100644
--- a/include/asm-generic/export.h
+++ b/include/asm-generic/export.h
@@ -70,7 +70,7 @@ KSYM(__kcrctab_\name):
70#include <generated/autoksyms.h> 70#include <generated/autoksyms.h>
71 71
72#define __EXPORT_SYMBOL(sym, val, sec) \ 72#define __EXPORT_SYMBOL(sym, val, sec) \
73 __cond_export_sym(sym, val, sec, config_enabled(__KSYM_##sym)) 73 __cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym))
74#define __cond_export_sym(sym, val, sec, conf) \ 74#define __cond_export_sym(sym, val, sec, conf) \
75 ___cond_export_sym(sym, val, sec, conf) 75 ___cond_export_sym(sym, val, sec, conf)
76#define ___cond_export_sym(sym, val, sec, enabled) \ 76#define ___cond_export_sym(sym, val, sec, enabled) \
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index ddbeda6dbdc8..689a8b9b9c8f 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -326,6 +326,7 @@ struct pci_dev;
326int acpi_pci_irq_enable (struct pci_dev *dev); 326int acpi_pci_irq_enable (struct pci_dev *dev);
327void acpi_penalize_isa_irq(int irq, int active); 327void acpi_penalize_isa_irq(int irq, int active);
328bool acpi_isa_irq_available(int irq); 328bool acpi_isa_irq_available(int irq);
329void acpi_penalize_sci_irq(int irq, int trigger, int polarity);
329void acpi_pci_irq_disable (struct pci_dev *dev); 330void acpi_pci_irq_disable (struct pci_dev *dev);
330 331
331extern int ec_read(u8 addr, u8 *val); 332extern int ec_read(u8 addr, u8 *val);
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index af596381fa0f..a428aec36ace 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -785,7 +785,7 @@ extern struct of_device_id __clk_of_table;
785 * routines, one at of_clk_init(), and one at platform device probe 785 * routines, one at of_clk_init(), and one at platform device probe
786 */ 786 */
787#define CLK_OF_DECLARE_DRIVER(name, compat, fn) \ 787#define CLK_OF_DECLARE_DRIVER(name, compat, fn) \
788 static void name##_of_clk_init_driver(struct device_node *np) \ 788 static void __init name##_of_clk_init_driver(struct device_node *np) \
789 { \ 789 { \
790 of_node_clear_flag(np, OF_POPULATED); \ 790 of_node_clear_flag(np, OF_POPULATED); \
791 fn(np); \ 791 fn(np); \
diff --git a/include/linux/io.h b/include/linux/io.h
index e2c8419278c1..82ef36eac8a1 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -141,4 +141,26 @@ enum {
141void *memremap(resource_size_t offset, size_t size, unsigned long flags); 141void *memremap(resource_size_t offset, size_t size, unsigned long flags);
142void memunmap(void *addr); 142void memunmap(void *addr);
143 143
144/*
145 * On x86 PAT systems we have memory tracking that keeps track of
146 * the allowed mappings on memory ranges. This tracking works for
147 * all the in-kernel mapping APIs (ioremap*), but where the user
148 * wishes to map a range from a physical device into user memory
149 * the tracking won't be updated. This API is to be used by
150 * drivers which remap physical device pages into userspace,
151 * and wants to make sure they are mapped WC and not UC.
152 */
153#ifndef arch_io_reserve_memtype_wc
154static inline int arch_io_reserve_memtype_wc(resource_size_t base,
155 resource_size_t size)
156{
157 return 0;
158}
159
160static inline void arch_io_free_memtype_wc(resource_size_t base,
161 resource_size_t size)
162{
163}
164#endif
165
144#endif /* _LINUX_IO_H */ 166#endif /* _LINUX_IO_H */
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index e63e288dee83..7892f55a1866 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -19,11 +19,15 @@ struct vm_fault;
19#define IOMAP_UNWRITTEN 0x04 /* blocks allocated @blkno in unwritten state */ 19#define IOMAP_UNWRITTEN 0x04 /* blocks allocated @blkno in unwritten state */
20 20
21/* 21/*
22 * Flags for iomap mappings: 22 * Flags for all iomap mappings:
23 */ 23 */
24#define IOMAP_F_MERGED 0x01 /* contains multiple blocks/extents */ 24#define IOMAP_F_NEW 0x01 /* blocks have been newly allocated */
25#define IOMAP_F_SHARED 0x02 /* block shared with another file */ 25
26#define IOMAP_F_NEW 0x04 /* blocks have been newly allocated */ 26/*
27 * Flags that only need to be reported for IOMAP_REPORT requests:
28 */
29#define IOMAP_F_MERGED 0x10 /* contains multiple blocks/extents */
30#define IOMAP_F_SHARED 0x20 /* block shared with another file */
27 31
28/* 32/*
29 * Magic value for blkno: 33 * Magic value for blkno:
@@ -42,8 +46,9 @@ struct iomap {
42/* 46/*
43 * Flags for iomap_begin / iomap_end. No flag implies a read. 47 * Flags for iomap_begin / iomap_end. No flag implies a read.
44 */ 48 */
45#define IOMAP_WRITE (1 << 0) 49#define IOMAP_WRITE (1 << 0) /* writing, must allocate blocks */
46#define IOMAP_ZERO (1 << 1) 50#define IOMAP_ZERO (1 << 1) /* zeroing operation, may skip holes */
51#define IOMAP_REPORT (1 << 2) /* report extent status, e.g. FIEMAP */
47 52
48struct iomap_ops { 53struct iomap_ops {
49 /* 54 /*
diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index 15ec117ec537..8f2e059e4d45 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -31,7 +31,6 @@
31 * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when 31 * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
32 * the last step cherry picks the 2nd arg, we get a zero. 32 * the last step cherry picks the 2nd arg, we get a zero.
33 */ 33 */
34#define config_enabled(cfg) ___is_defined(cfg)
35#define __is_defined(x) ___is_defined(x) 34#define __is_defined(x) ___is_defined(x)
36#define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val) 35#define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val)
37#define ____is_defined(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0) 36#define ____is_defined(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0)
@@ -41,13 +40,13 @@
41 * otherwise. For boolean options, this is equivalent to 40 * otherwise. For boolean options, this is equivalent to
42 * IS_ENABLED(CONFIG_FOO). 41 * IS_ENABLED(CONFIG_FOO).
43 */ 42 */
44#define IS_BUILTIN(option) config_enabled(option) 43#define IS_BUILTIN(option) __is_defined(option)
45 44
46/* 45/*
47 * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0 46 * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
48 * otherwise. 47 * otherwise.
49 */ 48 */
50#define IS_MODULE(option) config_enabled(option##_MODULE) 49#define IS_MODULE(option) __is_defined(option##_MODULE)
51 50
52/* 51/*
53 * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled 52 * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 3a191853faaa..a92c8d73aeaf 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1271,10 +1271,6 @@ extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *
1271extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, 1271extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
1272 void *buf, int len, unsigned int gup_flags); 1272 void *buf, int len, unsigned int gup_flags);
1273 1273
1274long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1275 unsigned long start, unsigned long nr_pages,
1276 unsigned int foll_flags, struct page **pages,
1277 struct vm_area_struct **vmas, int *nonblocking);
1278long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm, 1274long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
1279 unsigned long start, unsigned long nr_pages, 1275 unsigned long start, unsigned long nr_pages,
1280 unsigned int gup_flags, struct page **pages, 1276 unsigned int gup_flags, struct page **pages,
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 7f2ae99e5daf..0f088f3a2fed 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -440,33 +440,7 @@ struct zone {
440 seqlock_t span_seqlock; 440 seqlock_t span_seqlock;
441#endif 441#endif
442 442
443 /* 443 int initialized;
444 * wait_table -- the array holding the hash table
445 * wait_table_hash_nr_entries -- the size of the hash table array
446 * wait_table_bits -- wait_table_size == (1 << wait_table_bits)
447 *
448 * The purpose of all these is to keep track of the people
449 * waiting for a page to become available and make them
450 * runnable again when possible. The trouble is that this
451 * consumes a lot of space, especially when so few things
452 * wait on pages at a given time. So instead of using
453 * per-page waitqueues, we use a waitqueue hash table.
454 *
455 * The bucket discipline is to sleep on the same queue when
456 * colliding and wake all in that wait queue when removing.
457 * When something wakes, it must check to be sure its page is
458 * truly available, a la thundering herd. The cost of a
459 * collision is great, but given the expected load of the
460 * table, they should be so rare as to be outweighed by the
461 * benefits from the saved space.
462 *
463 * __wait_on_page_locked() and unlock_page() in mm/filemap.c, are the
464 * primary users of these fields, and in mm/page_alloc.c
465 * free_area_init_core() performs the initialization of them.
466 */
467 wait_queue_head_t *wait_table;
468 unsigned long wait_table_hash_nr_entries;
469 unsigned long wait_table_bits;
470 444
471 /* Write-intensive fields used from the page allocator */ 445 /* Write-intensive fields used from the page allocator */
472 ZONE_PADDING(_pad1_) 446 ZONE_PADDING(_pad1_)
@@ -546,7 +520,7 @@ static inline bool zone_spans_pfn(const struct zone *zone, unsigned long pfn)
546 520
547static inline bool zone_is_initialized(struct zone *zone) 521static inline bool zone_is_initialized(struct zone *zone)
548{ 522{
549 return !!zone->wait_table; 523 return zone->initialized;
550} 524}
551 525
552static inline bool zone_is_empty(struct zone *zone) 526static inline bool zone_is_empty(struct zone *zone)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 060d0ede88df..4741ecdb9817 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1257,6 +1257,7 @@ extern u64 perf_swevent_set_period(struct perf_event *event);
1257extern void perf_event_enable(struct perf_event *event); 1257extern void perf_event_enable(struct perf_event *event);
1258extern void perf_event_disable(struct perf_event *event); 1258extern void perf_event_disable(struct perf_event *event);
1259extern void perf_event_disable_local(struct perf_event *event); 1259extern void perf_event_disable_local(struct perf_event *event);
1260extern void perf_event_disable_inatomic(struct perf_event *event);
1260extern void perf_event_task_tick(void); 1261extern void perf_event_task_tick(void);
1261#else /* !CONFIG_PERF_EVENTS: */ 1262#else /* !CONFIG_PERF_EVENTS: */
1262static inline void * 1263static inline void *
diff --git a/ipc/msgutil.c b/ipc/msgutil.c
index a521999de4f1..bf74eaa5c39f 100644
--- a/ipc/msgutil.c
+++ b/ipc/msgutil.c
@@ -53,7 +53,7 @@ static struct msg_msg *alloc_msg(size_t len)
53 size_t alen; 53 size_t alen;
54 54
55 alen = min(len, DATALEN_MSG); 55 alen = min(len, DATALEN_MSG);
56 msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL); 56 msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL_ACCOUNT);
57 if (msg == NULL) 57 if (msg == NULL)
58 return NULL; 58 return NULL;
59 59
@@ -65,7 +65,7 @@ static struct msg_msg *alloc_msg(size_t len)
65 while (len > 0) { 65 while (len > 0) {
66 struct msg_msgseg *seg; 66 struct msg_msgseg *seg;
67 alen = min(len, DATALEN_SEG); 67 alen = min(len, DATALEN_SEG);
68 seg = kmalloc(sizeof(*seg) + alen, GFP_KERNEL); 68 seg = kmalloc(sizeof(*seg) + alen, GFP_KERNEL_ACCOUNT);
69 if (seg == NULL) 69 if (seg == NULL)
70 goto out_err; 70 goto out_err;
71 *pseg = seg; 71 *pseg = seg;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index c6e47e97b33f..0e292132efac 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1960,6 +1960,12 @@ void perf_event_disable(struct perf_event *event)
1960} 1960}
1961EXPORT_SYMBOL_GPL(perf_event_disable); 1961EXPORT_SYMBOL_GPL(perf_event_disable);
1962 1962
1963void perf_event_disable_inatomic(struct perf_event *event)
1964{
1965 event->pending_disable = 1;
1966 irq_work_queue(&event->pending);
1967}
1968
1963static void perf_set_shadow_time(struct perf_event *event, 1969static void perf_set_shadow_time(struct perf_event *event,
1964 struct perf_event_context *ctx, 1970 struct perf_event_context *ctx,
1965 u64 tstamp) 1971 u64 tstamp)
@@ -7075,8 +7081,8 @@ static int __perf_event_overflow(struct perf_event *event,
7075 if (events && atomic_dec_and_test(&event->event_limit)) { 7081 if (events && atomic_dec_and_test(&event->event_limit)) {
7076 ret = 1; 7082 ret = 1;
7077 event->pending_kill = POLL_HUP; 7083 event->pending_kill = POLL_HUP;
7078 event->pending_disable = 1; 7084
7079 irq_work_queue(&event->pending); 7085 perf_event_disable_inatomic(event);
7080 } 7086 }
7081 7087
7082 READ_ONCE(event->overflow_handler)(event, data, regs); 7088 READ_ONCE(event->overflow_handler)(event, data, regs);
@@ -8855,7 +8861,10 @@ EXPORT_SYMBOL_GPL(perf_pmu_register);
8855 8861
8856void perf_pmu_unregister(struct pmu *pmu) 8862void perf_pmu_unregister(struct pmu *pmu)
8857{ 8863{
8864 int remove_device;
8865
8858 mutex_lock(&pmus_lock); 8866 mutex_lock(&pmus_lock);
8867 remove_device = pmu_bus_running;
8859 list_del_rcu(&pmu->entry); 8868 list_del_rcu(&pmu->entry);
8860 mutex_unlock(&pmus_lock); 8869 mutex_unlock(&pmus_lock);
8861 8870
@@ -8869,10 +8878,12 @@ void perf_pmu_unregister(struct pmu *pmu)
8869 free_percpu(pmu->pmu_disable_count); 8878 free_percpu(pmu->pmu_disable_count);
8870 if (pmu->type >= PERF_TYPE_MAX) 8879 if (pmu->type >= PERF_TYPE_MAX)
8871 idr_remove(&pmu_idr, pmu->type); 8880 idr_remove(&pmu_idr, pmu->type);
8872 if (pmu->nr_addr_filters) 8881 if (remove_device) {
8873 device_remove_file(pmu->dev, &dev_attr_nr_addr_filters); 8882 if (pmu->nr_addr_filters)
8874 device_del(pmu->dev); 8883 device_remove_file(pmu->dev, &dev_attr_nr_addr_filters);
8875 put_device(pmu->dev); 8884 device_del(pmu->dev);
8885 put_device(pmu->dev);
8886 }
8876 free_pmu_context(pmu); 8887 free_pmu_context(pmu);
8877} 8888}
8878EXPORT_SYMBOL_GPL(perf_pmu_unregister); 8889EXPORT_SYMBOL_GPL(perf_pmu_unregister);
diff --git a/kernel/kcov.c b/kernel/kcov.c
index 8d44b3fea9d0..30e6d05aa5a9 100644
--- a/kernel/kcov.c
+++ b/kernel/kcov.c
@@ -53,8 +53,15 @@ void notrace __sanitizer_cov_trace_pc(void)
53 /* 53 /*
54 * We are interested in code coverage as a function of a syscall inputs, 54 * We are interested in code coverage as a function of a syscall inputs,
55 * so we ignore code executed in interrupts. 55 * so we ignore code executed in interrupts.
56 * The checks for whether we are in an interrupt are open-coded, because
57 * 1. We can't use in_interrupt() here, since it also returns true
58 * when we are inside local_bh_disable() section.
59 * 2. We don't want to use (in_irq() | in_serving_softirq() | in_nmi()),
60 * since that leads to slower generated code (three separate tests,
61 * one for each of the flags).
56 */ 62 */
57 if (!t || in_interrupt()) 63 if (!t || (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_OFFSET
64 | NMI_MASK)))
58 return; 65 return;
59 mode = READ_ONCE(t->kcov_mode); 66 mode = READ_ONCE(t->kcov_mode);
60 if (mode == KCOV_MODE_TRACE) { 67 if (mode == KCOV_MODE_TRACE) {
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 1e7f5da648d9..6ccb08f57fcb 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -498,9 +498,9 @@ static int enter_state(suspend_state_t state)
498 498
499#ifndef CONFIG_SUSPEND_SKIP_SYNC 499#ifndef CONFIG_SUSPEND_SKIP_SYNC
500 trace_suspend_resume(TPS("sync_filesystems"), 0, true); 500 trace_suspend_resume(TPS("sync_filesystems"), 0, true);
501 printk(KERN_INFO "PM: Syncing filesystems ... "); 501 pr_info("PM: Syncing filesystems ... ");
502 sys_sync(); 502 sys_sync();
503 printk("done.\n"); 503 pr_cont("done.\n");
504 trace_suspend_resume(TPS("sync_filesystems"), 0, false); 504 trace_suspend_resume(TPS("sync_filesystems"), 0, false);
505#endif 505#endif
506 506
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 94732d1ab00a..42d4027f9e26 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7515,11 +7515,27 @@ static struct kmem_cache *task_group_cache __read_mostly;
7515DECLARE_PER_CPU(cpumask_var_t, load_balance_mask); 7515DECLARE_PER_CPU(cpumask_var_t, load_balance_mask);
7516DECLARE_PER_CPU(cpumask_var_t, select_idle_mask); 7516DECLARE_PER_CPU(cpumask_var_t, select_idle_mask);
7517 7517
7518#define WAIT_TABLE_BITS 8
7519#define WAIT_TABLE_SIZE (1 << WAIT_TABLE_BITS)
7520static wait_queue_head_t bit_wait_table[WAIT_TABLE_SIZE] __cacheline_aligned;
7521
7522wait_queue_head_t *bit_waitqueue(void *word, int bit)
7523{
7524 const int shift = BITS_PER_LONG == 32 ? 5 : 6;
7525 unsigned long val = (unsigned long)word << shift | bit;
7526
7527 return bit_wait_table + hash_long(val, WAIT_TABLE_BITS);
7528}
7529EXPORT_SYMBOL(bit_waitqueue);
7530
7518void __init sched_init(void) 7531void __init sched_init(void)
7519{ 7532{
7520 int i, j; 7533 int i, j;
7521 unsigned long alloc_size = 0, ptr; 7534 unsigned long alloc_size = 0, ptr;
7522 7535
7536 for (i = 0; i < WAIT_TABLE_SIZE; i++)
7537 init_waitqueue_head(bit_wait_table + i);
7538
7523#ifdef CONFIG_FAIR_GROUP_SCHED 7539#ifdef CONFIG_FAIR_GROUP_SCHED
7524 alloc_size += 2 * nr_cpu_ids * sizeof(void **); 7540 alloc_size += 2 * nr_cpu_ids * sizeof(void **);
7525#endif 7541#endif
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index d941c97dfbc3..c242944f5cbd 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8839,7 +8839,6 @@ int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent)
8839{ 8839{
8840 struct sched_entity *se; 8840 struct sched_entity *se;
8841 struct cfs_rq *cfs_rq; 8841 struct cfs_rq *cfs_rq;
8842 struct rq *rq;
8843 int i; 8842 int i;
8844 8843
8845 tg->cfs_rq = kzalloc(sizeof(cfs_rq) * nr_cpu_ids, GFP_KERNEL); 8844 tg->cfs_rq = kzalloc(sizeof(cfs_rq) * nr_cpu_ids, GFP_KERNEL);
@@ -8854,8 +8853,6 @@ int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent)
8854 init_cfs_bandwidth(tg_cfs_bandwidth(tg)); 8853 init_cfs_bandwidth(tg_cfs_bandwidth(tg));
8855 8854
8856 for_each_possible_cpu(i) { 8855 for_each_possible_cpu(i) {
8857 rq = cpu_rq(i);
8858
8859 cfs_rq = kzalloc_node(sizeof(struct cfs_rq), 8856 cfs_rq = kzalloc_node(sizeof(struct cfs_rq),
8860 GFP_KERNEL, cpu_to_node(i)); 8857 GFP_KERNEL, cpu_to_node(i));
8861 if (!cfs_rq) 8858 if (!cfs_rq)
diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
index 4f7053579fe3..9453efe9b25a 100644
--- a/kernel/sched/wait.c
+++ b/kernel/sched/wait.c
@@ -480,16 +480,6 @@ void wake_up_bit(void *word, int bit)
480} 480}
481EXPORT_SYMBOL(wake_up_bit); 481EXPORT_SYMBOL(wake_up_bit);
482 482
483wait_queue_head_t *bit_waitqueue(void *word, int bit)
484{
485 const int shift = BITS_PER_LONG == 32 ? 5 : 6;
486 const struct zone *zone = page_zone(virt_to_page(word));
487 unsigned long val = (unsigned long)word << shift | bit;
488
489 return &zone->wait_table[hash_long(val, zone->wait_table_bits)];
490}
491EXPORT_SYMBOL(bit_waitqueue);
492
493/* 483/*
494 * Manipulate the atomic_t address to produce a better bit waitqueue table hash 484 * Manipulate the atomic_t address to produce a better bit waitqueue table hash
495 * index (we're keying off bit -1, but that would produce a horrible hash 485 * index (we're keying off bit -1, but that would produce a horrible hash
diff --git a/kernel/softirq.c b/kernel/softirq.c
index 1bf81ef91375..744fa611cae0 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -58,7 +58,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
58DEFINE_PER_CPU(struct task_struct *, ksoftirqd); 58DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
59 59
60const char * const softirq_to_name[NR_SOFTIRQS] = { 60const char * const softirq_to_name[NR_SOFTIRQS] = {
61 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL", 61 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "IRQ_POLL",
62 "TASKLET", "SCHED", "HRTIMER", "RCU" 62 "TASKLET", "SCHED", "HRTIMER", "RCU"
63}; 63};
64 64
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 2d47980a1bc4..c611c47de884 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -878,7 +878,7 @@ static inline struct timer_base *get_timer_base(u32 tflags)
878 878
879#ifdef CONFIG_NO_HZ_COMMON 879#ifdef CONFIG_NO_HZ_COMMON
880static inline struct timer_base * 880static inline struct timer_base *
881__get_target_base(struct timer_base *base, unsigned tflags) 881get_target_base(struct timer_base *base, unsigned tflags)
882{ 882{
883#ifdef CONFIG_SMP 883#ifdef CONFIG_SMP
884 if ((tflags & TIMER_PINNED) || !base->migration_enabled) 884 if ((tflags & TIMER_PINNED) || !base->migration_enabled)
@@ -891,25 +891,27 @@ __get_target_base(struct timer_base *base, unsigned tflags)
891 891
892static inline void forward_timer_base(struct timer_base *base) 892static inline void forward_timer_base(struct timer_base *base)
893{ 893{
894 unsigned long jnow = READ_ONCE(jiffies);
895
894 /* 896 /*
895 * We only forward the base when it's idle and we have a delta between 897 * We only forward the base when it's idle and we have a delta between
896 * base clock and jiffies. 898 * base clock and jiffies.
897 */ 899 */
898 if (!base->is_idle || (long) (jiffies - base->clk) < 2) 900 if (!base->is_idle || (long) (jnow - base->clk) < 2)
899 return; 901 return;
900 902
901 /* 903 /*
902 * If the next expiry value is > jiffies, then we fast forward to 904 * If the next expiry value is > jiffies, then we fast forward to
903 * jiffies otherwise we forward to the next expiry value. 905 * jiffies otherwise we forward to the next expiry value.
904 */ 906 */
905 if (time_after(base->next_expiry, jiffies)) 907 if (time_after(base->next_expiry, jnow))
906 base->clk = jiffies; 908 base->clk = jnow;
907 else 909 else
908 base->clk = base->next_expiry; 910 base->clk = base->next_expiry;
909} 911}
910#else 912#else
911static inline struct timer_base * 913static inline struct timer_base *
912__get_target_base(struct timer_base *base, unsigned tflags) 914get_target_base(struct timer_base *base, unsigned tflags)
913{ 915{
914 return get_timer_this_cpu_base(tflags); 916 return get_timer_this_cpu_base(tflags);
915} 917}
@@ -917,14 +919,6 @@ __get_target_base(struct timer_base *base, unsigned tflags)
917static inline void forward_timer_base(struct timer_base *base) { } 919static inline void forward_timer_base(struct timer_base *base) { }
918#endif 920#endif
919 921
920static inline struct timer_base *
921get_target_base(struct timer_base *base, unsigned tflags)
922{
923 struct timer_base *target = __get_target_base(base, tflags);
924
925 forward_timer_base(target);
926 return target;
927}
928 922
929/* 923/*
930 * We are using hashed locking: Holding per_cpu(timer_bases[x]).lock means 924 * We are using hashed locking: Holding per_cpu(timer_bases[x]).lock means
@@ -943,7 +937,14 @@ static struct timer_base *lock_timer_base(struct timer_list *timer,
943{ 937{
944 for (;;) { 938 for (;;) {
945 struct timer_base *base; 939 struct timer_base *base;
946 u32 tf = timer->flags; 940 u32 tf;
941
942 /*
943 * We need to use READ_ONCE() here, otherwise the compiler
944 * might re-read @tf between the check for TIMER_MIGRATING
945 * and spin_lock().
946 */
947 tf = READ_ONCE(timer->flags);
947 948
948 if (!(tf & TIMER_MIGRATING)) { 949 if (!(tf & TIMER_MIGRATING)) {
949 base = get_timer_base(tf); 950 base = get_timer_base(tf);
@@ -964,6 +965,8 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
964 unsigned long clk = 0, flags; 965 unsigned long clk = 0, flags;
965 int ret = 0; 966 int ret = 0;
966 967
968 BUG_ON(!timer->function);
969
967 /* 970 /*
968 * This is a common optimization triggered by the networking code - if 971 * This is a common optimization triggered by the networking code - if
969 * the timer is re-modified to have the same timeout or ends up in the 972 * the timer is re-modified to have the same timeout or ends up in the
@@ -972,13 +975,16 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
972 if (timer_pending(timer)) { 975 if (timer_pending(timer)) {
973 if (timer->expires == expires) 976 if (timer->expires == expires)
974 return 1; 977 return 1;
978
975 /* 979 /*
976 * Take the current timer_jiffies of base, but without holding 980 * We lock timer base and calculate the bucket index right
977 * the lock! 981 * here. If the timer ends up in the same bucket, then we
982 * just update the expiry time and avoid the whole
983 * dequeue/enqueue dance.
978 */ 984 */
979 base = get_timer_base(timer->flags); 985 base = lock_timer_base(timer, &flags);
980 clk = base->clk;
981 986
987 clk = base->clk;
982 idx = calc_wheel_index(expires, clk); 988 idx = calc_wheel_index(expires, clk);
983 989
984 /* 990 /*
@@ -988,14 +994,14 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
988 */ 994 */
989 if (idx == timer_get_idx(timer)) { 995 if (idx == timer_get_idx(timer)) {
990 timer->expires = expires; 996 timer->expires = expires;
991 return 1; 997 ret = 1;
998 goto out_unlock;
992 } 999 }
1000 } else {
1001 base = lock_timer_base(timer, &flags);
993 } 1002 }
994 1003
995 timer_stats_timer_set_start_info(timer); 1004 timer_stats_timer_set_start_info(timer);
996 BUG_ON(!timer->function);
997
998 base = lock_timer_base(timer, &flags);
999 1005
1000 ret = detach_if_pending(timer, base, false); 1006 ret = detach_if_pending(timer, base, false);
1001 if (!ret && pending_only) 1007 if (!ret && pending_only)
@@ -1025,12 +1031,16 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
1025 } 1031 }
1026 } 1032 }
1027 1033
1034 /* Try to forward a stale timer base clock */
1035 forward_timer_base(base);
1036
1028 timer->expires = expires; 1037 timer->expires = expires;
1029 /* 1038 /*
1030 * If 'idx' was calculated above and the base time did not advance 1039 * If 'idx' was calculated above and the base time did not advance
1031 * between calculating 'idx' and taking the lock, only enqueue_timer() 1040 * between calculating 'idx' and possibly switching the base, only
1032 * and trigger_dyntick_cpu() is required. Otherwise we need to 1041 * enqueue_timer() and trigger_dyntick_cpu() is required. Otherwise
1033 * (re)calculate the wheel index via internal_add_timer(). 1042 * we need to (re)calculate the wheel index via
1043 * internal_add_timer().
1034 */ 1044 */
1035 if (idx != UINT_MAX && clk == base->clk) { 1045 if (idx != UINT_MAX && clk == base->clk) {
1036 enqueue_timer(base, timer, idx); 1046 enqueue_timer(base, timer, idx);
@@ -1510,12 +1520,16 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
1510 is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA); 1520 is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA);
1511 base->next_expiry = nextevt; 1521 base->next_expiry = nextevt;
1512 /* 1522 /*
1513 * We have a fresh next event. Check whether we can forward the base: 1523 * We have a fresh next event. Check whether we can forward the
1524 * base. We can only do that when @basej is past base->clk
1525 * otherwise we might rewind base->clk.
1514 */ 1526 */
1515 if (time_after(nextevt, jiffies)) 1527 if (time_after(basej, base->clk)) {
1516 base->clk = jiffies; 1528 if (time_after(nextevt, basej))
1517 else if (time_after(nextevt, base->clk)) 1529 base->clk = basej;
1518 base->clk = nextevt; 1530 else if (time_after(nextevt, base->clk))
1531 base->clk = nextevt;
1532 }
1519 1533
1520 if (time_before_eq(nextevt, basej)) { 1534 if (time_before_eq(nextevt, basej)) {
1521 expires = basem; 1535 expires = basem;
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 33bc56cf60d7..b01e547d4d04 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -198,6 +198,7 @@ config FRAME_WARN
198 int "Warn for stack frames larger than (needs gcc 4.4)" 198 int "Warn for stack frames larger than (needs gcc 4.4)"
199 range 0 8192 199 range 0 8192
200 default 0 if KASAN 200 default 0 if KASAN
201 default 2048 if GCC_PLUGIN_LATENT_ENTROPY
201 default 1024 if !64BIT 202 default 1024 if !64BIT
202 default 2048 if 64BIT 203 default 2048 if 64BIT
203 help 204 help
diff --git a/lib/genalloc.c b/lib/genalloc.c
index 0a1139644d32..144fe6b1a03e 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -292,7 +292,7 @@ unsigned long gen_pool_alloc_algo(struct gen_pool *pool, size_t size,
292 struct gen_pool_chunk *chunk; 292 struct gen_pool_chunk *chunk;
293 unsigned long addr = 0; 293 unsigned long addr = 0;
294 int order = pool->min_alloc_order; 294 int order = pool->min_alloc_order;
295 int nbits, start_bit = 0, end_bit, remain; 295 int nbits, start_bit, end_bit, remain;
296 296
297#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG 297#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG
298 BUG_ON(in_nmi()); 298 BUG_ON(in_nmi());
@@ -307,6 +307,7 @@ unsigned long gen_pool_alloc_algo(struct gen_pool *pool, size_t size,
307 if (size > atomic_read(&chunk->avail)) 307 if (size > atomic_read(&chunk->avail))
308 continue; 308 continue;
309 309
310 start_bit = 0;
310 end_bit = chunk_size(chunk) >> order; 311 end_bit = chunk_size(chunk) >> order;
311retry: 312retry:
312 start_bit = algo(chunk->bits, end_bit, start_bit, 313 start_bit = algo(chunk->bits, end_bit, start_bit,
diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index 60f77f1d470a..4d830e299989 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -50,7 +50,7 @@
50 STACK_ALLOC_ALIGN) 50 STACK_ALLOC_ALIGN)
51#define STACK_ALLOC_INDEX_BITS (DEPOT_STACK_BITS - \ 51#define STACK_ALLOC_INDEX_BITS (DEPOT_STACK_BITS - \
52 STACK_ALLOC_NULL_PROTECTION_BITS - STACK_ALLOC_OFFSET_BITS) 52 STACK_ALLOC_NULL_PROTECTION_BITS - STACK_ALLOC_OFFSET_BITS)
53#define STACK_ALLOC_SLABS_CAP 1024 53#define STACK_ALLOC_SLABS_CAP 8192
54#define STACK_ALLOC_MAX_SLABS \ 54#define STACK_ALLOC_MAX_SLABS \
55 (((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_SLABS_CAP) ? \ 55 (((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_SLABS_CAP) ? \
56 (1LL << (STACK_ALLOC_INDEX_BITS)) : STACK_ALLOC_SLABS_CAP) 56 (1LL << (STACK_ALLOC_INDEX_BITS)) : STACK_ALLOC_SLABS_CAP)
diff --git a/mm/Kconfig b/mm/Kconfig
index be0ee11fa0d9..86e3e0e74d20 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -187,7 +187,7 @@ config MEMORY_HOTPLUG
187 bool "Allow for memory hot-add" 187 bool "Allow for memory hot-add"
188 depends on SPARSEMEM || X86_64_ACPI_NUMA 188 depends on SPARSEMEM || X86_64_ACPI_NUMA
189 depends on ARCH_ENABLE_MEMORY_HOTPLUG 189 depends on ARCH_ENABLE_MEMORY_HOTPLUG
190 depends on !KASAN 190 depends on COMPILE_TEST || !KASAN
191 191
192config MEMORY_HOTPLUG_SPARSE 192config MEMORY_HOTPLUG_SPARSE
193 def_bool y 193 def_bool y
diff --git a/mm/filemap.c b/mm/filemap.c
index 849f459ad078..c7fe2f16503f 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -790,9 +790,7 @@ EXPORT_SYMBOL(__page_cache_alloc);
790 */ 790 */
791wait_queue_head_t *page_waitqueue(struct page *page) 791wait_queue_head_t *page_waitqueue(struct page *page)
792{ 792{
793 const struct zone *zone = page_zone(page); 793 return bit_waitqueue(page, 0);
794
795 return &zone->wait_table[hash_ptr(page, zone->wait_table_bits)];
796} 794}
797EXPORT_SYMBOL(page_waitqueue); 795EXPORT_SYMBOL(page_waitqueue);
798 796
diff --git a/mm/gup.c b/mm/gup.c
index 7aa113c2d373..ec4f82704b6f 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -526,7 +526,7 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags)
526 * instead of __get_user_pages. __get_user_pages should be used only if 526 * instead of __get_user_pages. __get_user_pages should be used only if
527 * you need some special @gup_flags. 527 * you need some special @gup_flags.
528 */ 528 */
529long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 529static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
530 unsigned long start, unsigned long nr_pages, 530 unsigned long start, unsigned long nr_pages,
531 unsigned int gup_flags, struct page **pages, 531 unsigned int gup_flags, struct page **pages,
532 struct vm_area_struct **vmas, int *nonblocking) 532 struct vm_area_struct **vmas, int *nonblocking)
@@ -631,7 +631,6 @@ next_page:
631 } while (nr_pages); 631 } while (nr_pages);
632 return i; 632 return i;
633} 633}
634EXPORT_SYMBOL(__get_user_pages);
635 634
636bool vma_permits_fault(struct vm_area_struct *vma, unsigned int fault_flags) 635bool vma_permits_fault(struct vm_area_struct *vma, unsigned int fault_flags)
637{ 636{
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index a5e453cf05c4..e5355a5b423f 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1453,8 +1453,11 @@ static void kmemleak_scan(void)
1453 1453
1454 read_lock(&tasklist_lock); 1454 read_lock(&tasklist_lock);
1455 do_each_thread(g, p) { 1455 do_each_thread(g, p) {
1456 scan_block(task_stack_page(p), task_stack_page(p) + 1456 void *stack = try_get_task_stack(p);
1457 THREAD_SIZE, NULL); 1457 if (stack) {
1458 scan_block(stack, stack + THREAD_SIZE, NULL);
1459 put_task_stack(p);
1460 }
1458 } while_each_thread(g, p); 1461 } while_each_thread(g, p);
1459 read_unlock(&tasklist_lock); 1462 read_unlock(&tasklist_lock);
1460 } 1463 }
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 1d05cb9d363d..234676e31edd 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -554,6 +554,8 @@ int __list_lru_init(struct list_lru *lru, bool memcg_aware,
554 err = memcg_init_list_lru(lru, memcg_aware); 554 err = memcg_init_list_lru(lru, memcg_aware);
555 if (err) { 555 if (err) {
556 kfree(lru->node); 556 kfree(lru->node);
557 /* Do this so a list_lru_destroy() doesn't crash: */
558 lru->node = NULL;
557 goto out; 559 goto out;
558 } 560 }
559 561
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ae052b5e3315..0f870ba43942 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1917,6 +1917,15 @@ retry:
1917 current->flags & PF_EXITING)) 1917 current->flags & PF_EXITING))
1918 goto force; 1918 goto force;
1919 1919
1920 /*
1921 * Prevent unbounded recursion when reclaim operations need to
1922 * allocate memory. This might exceed the limits temporarily,
1923 * but we prefer facilitating memory reclaim and getting back
1924 * under the limit over triggering OOM kills in these cases.
1925 */
1926 if (unlikely(current->flags & PF_MEMALLOC))
1927 goto force;
1928
1920 if (unlikely(task_in_memcg_oom(current))) 1929 if (unlikely(task_in_memcg_oom(current)))
1921 goto nomem; 1930 goto nomem;
1922 1931
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 962927309b6e..cad4b9125695 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -268,7 +268,6 @@ void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
268 unsigned long i, pfn, end_pfn, nr_pages; 268 unsigned long i, pfn, end_pfn, nr_pages;
269 int node = pgdat->node_id; 269 int node = pgdat->node_id;
270 struct page *page; 270 struct page *page;
271 struct zone *zone;
272 271
273 nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT; 272 nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT;
274 page = virt_to_page(pgdat); 273 page = virt_to_page(pgdat);
@@ -276,19 +275,6 @@ void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
276 for (i = 0; i < nr_pages; i++, page++) 275 for (i = 0; i < nr_pages; i++, page++)
277 get_page_bootmem(node, page, NODE_INFO); 276 get_page_bootmem(node, page, NODE_INFO);
278 277
279 zone = &pgdat->node_zones[0];
280 for (; zone < pgdat->node_zones + MAX_NR_ZONES - 1; zone++) {
281 if (zone_is_initialized(zone)) {
282 nr_pages = zone->wait_table_hash_nr_entries
283 * sizeof(wait_queue_head_t);
284 nr_pages = PAGE_ALIGN(nr_pages) >> PAGE_SHIFT;
285 page = virt_to_page(zone->wait_table);
286
287 for (i = 0; i < nr_pages; i++, page++)
288 get_page_bootmem(node, page, NODE_INFO);
289 }
290 }
291
292 pfn = pgdat->node_start_pfn; 278 pfn = pgdat->node_start_pfn;
293 end_pfn = pgdat_end_pfn(pgdat); 279 end_pfn = pgdat_end_pfn(pgdat);
294 280
@@ -2131,7 +2117,6 @@ void try_offline_node(int nid)
2131 unsigned long start_pfn = pgdat->node_start_pfn; 2117 unsigned long start_pfn = pgdat->node_start_pfn;
2132 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages; 2118 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
2133 unsigned long pfn; 2119 unsigned long pfn;
2134 int i;
2135 2120
2136 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { 2121 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
2137 unsigned long section_nr = pfn_to_section_nr(pfn); 2122 unsigned long section_nr = pfn_to_section_nr(pfn);
@@ -2158,20 +2143,6 @@ void try_offline_node(int nid)
2158 */ 2143 */
2159 node_set_offline(nid); 2144 node_set_offline(nid);
2160 unregister_one_node(nid); 2145 unregister_one_node(nid);
2161
2162 /* free waittable in each zone */
2163 for (i = 0; i < MAX_NR_ZONES; i++) {
2164 struct zone *zone = pgdat->node_zones + i;
2165
2166 /*
2167 * wait_table may be allocated from boot memory,
2168 * here only free if it's allocated by vmalloc.
2169 */
2170 if (is_vmalloc_addr(zone->wait_table)) {
2171 vfree(zone->wait_table);
2172 zone->wait_table = NULL;
2173 }
2174 }
2175} 2146}
2176EXPORT_SYMBOL(try_offline_node); 2147EXPORT_SYMBOL(try_offline_node);
2177 2148
diff --git a/mm/nommu.c b/mm/nommu.c
index db5fd1795298..8b8faaf2a9e9 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -109,7 +109,7 @@ unsigned int kobjsize(const void *objp)
109 return PAGE_SIZE << compound_order(page); 109 return PAGE_SIZE << compound_order(page);
110} 110}
111 111
112long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 112static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
113 unsigned long start, unsigned long nr_pages, 113 unsigned long start, unsigned long nr_pages,
114 unsigned int foll_flags, struct page **pages, 114 unsigned int foll_flags, struct page **pages,
115 struct vm_area_struct **vmas, int *nonblocking) 115 struct vm_area_struct **vmas, int *nonblocking)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2b3bf6767d54..8fd42aa7c4bd 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4224,7 +4224,7 @@ static void show_migration_types(unsigned char type)
4224 } 4224 }
4225 4225
4226 *p = '\0'; 4226 *p = '\0';
4227 printk("(%s) ", tmp); 4227 printk(KERN_CONT "(%s) ", tmp);
4228} 4228}
4229 4229
4230/* 4230/*
@@ -4335,7 +4335,8 @@ void show_free_areas(unsigned int filter)
4335 free_pcp += per_cpu_ptr(zone->pageset, cpu)->pcp.count; 4335 free_pcp += per_cpu_ptr(zone->pageset, cpu)->pcp.count;
4336 4336
4337 show_node(zone); 4337 show_node(zone);
4338 printk("%s" 4338 printk(KERN_CONT
4339 "%s"
4339 " free:%lukB" 4340 " free:%lukB"
4340 " min:%lukB" 4341 " min:%lukB"
4341 " low:%lukB" 4342 " low:%lukB"
@@ -4382,8 +4383,8 @@ void show_free_areas(unsigned int filter)
4382 K(zone_page_state(zone, NR_FREE_CMA_PAGES))); 4383 K(zone_page_state(zone, NR_FREE_CMA_PAGES)));
4383 printk("lowmem_reserve[]:"); 4384 printk("lowmem_reserve[]:");
4384 for (i = 0; i < MAX_NR_ZONES; i++) 4385 for (i = 0; i < MAX_NR_ZONES; i++)
4385 printk(" %ld", zone->lowmem_reserve[i]); 4386 printk(KERN_CONT " %ld", zone->lowmem_reserve[i]);
4386 printk("\n"); 4387 printk(KERN_CONT "\n");
4387 } 4388 }
4388 4389
4389 for_each_populated_zone(zone) { 4390 for_each_populated_zone(zone) {
@@ -4394,7 +4395,7 @@ void show_free_areas(unsigned int filter)
4394 if (skip_free_areas_node(filter, zone_to_nid(zone))) 4395 if (skip_free_areas_node(filter, zone_to_nid(zone)))
4395 continue; 4396 continue;
4396 show_node(zone); 4397 show_node(zone);
4397 printk("%s: ", zone->name); 4398 printk(KERN_CONT "%s: ", zone->name);
4398 4399
4399 spin_lock_irqsave(&zone->lock, flags); 4400 spin_lock_irqsave(&zone->lock, flags);
4400 for (order = 0; order < MAX_ORDER; order++) { 4401 for (order = 0; order < MAX_ORDER; order++) {
@@ -4412,11 +4413,12 @@ void show_free_areas(unsigned int filter)
4412 } 4413 }
4413 spin_unlock_irqrestore(&zone->lock, flags); 4414 spin_unlock_irqrestore(&zone->lock, flags);
4414 for (order = 0; order < MAX_ORDER; order++) { 4415 for (order = 0; order < MAX_ORDER; order++) {
4415 printk("%lu*%lukB ", nr[order], K(1UL) << order); 4416 printk(KERN_CONT "%lu*%lukB ",
4417 nr[order], K(1UL) << order);
4416 if (nr[order]) 4418 if (nr[order])
4417 show_migration_types(types[order]); 4419 show_migration_types(types[order]);
4418 } 4420 }
4419 printk("= %lukB\n", K(total)); 4421 printk(KERN_CONT "= %lukB\n", K(total));
4420 } 4422 }
4421 4423
4422 hugetlb_show_meminfo(); 4424 hugetlb_show_meminfo();
@@ -4977,72 +4979,6 @@ void __ref build_all_zonelists(pg_data_t *pgdat, struct zone *zone)
4977} 4979}
4978 4980
4979/* 4981/*
4980 * Helper functions to size the waitqueue hash table.
4981 * Essentially these want to choose hash table sizes sufficiently
4982 * large so that collisions trying to wait on pages are rare.
4983 * But in fact, the number of active page waitqueues on typical
4984 * systems is ridiculously low, less than 200. So this is even
4985 * conservative, even though it seems large.
4986 *
4987 * The constant PAGES_PER_WAITQUEUE specifies the ratio of pages to
4988 * waitqueues, i.e. the size of the waitq table given the number of pages.
4989 */
4990#define PAGES_PER_WAITQUEUE 256
4991
4992#ifndef CONFIG_MEMORY_HOTPLUG
4993static inline unsigned long wait_table_hash_nr_entries(unsigned long pages)
4994{
4995 unsigned long size = 1;
4996
4997 pages /= PAGES_PER_WAITQUEUE;
4998
4999 while (size < pages)
5000 size <<= 1;
5001
5002 /*
5003 * Once we have dozens or even hundreds of threads sleeping
5004 * on IO we've got bigger problems than wait queue collision.
5005 * Limit the size of the wait table to a reasonable size.
5006 */
5007 size = min(size, 4096UL);
5008
5009 return max(size, 4UL);
5010}
5011#else
5012/*
5013 * A zone's size might be changed by hot-add, so it is not possible to determine
5014 * a suitable size for its wait_table. So we use the maximum size now.
5015 *
5016 * The max wait table size = 4096 x sizeof(wait_queue_head_t). ie:
5017 *
5018 * i386 (preemption config) : 4096 x 16 = 64Kbyte.
5019 * ia64, x86-64 (no preemption): 4096 x 20 = 80Kbyte.
5020 * ia64, x86-64 (preemption) : 4096 x 24 = 96Kbyte.
5021 *
5022 * The maximum entries are prepared when a zone's memory is (512K + 256) pages
5023 * or more by the traditional way. (See above). It equals:
5024 *
5025 * i386, x86-64, powerpc(4K page size) : = ( 2G + 1M)byte.
5026 * ia64(16K page size) : = ( 8G + 4M)byte.
5027 * powerpc (64K page size) : = (32G +16M)byte.
5028 */
5029static inline unsigned long wait_table_hash_nr_entries(unsigned long pages)
5030{
5031 return 4096UL;
5032}
5033#endif
5034
5035/*
5036 * This is an integer logarithm so that shifts can be used later
5037 * to extract the more random high bits from the multiplicative
5038 * hash function before the remainder is taken.
5039 */
5040static inline unsigned long wait_table_bits(unsigned long size)
5041{
5042 return ffz(~size);
5043}
5044
5045/*
5046 * Initially all pages are reserved - free ones are freed 4982 * Initially all pages are reserved - free ones are freed
5047 * up by free_all_bootmem() once the early boot process is 4983 * up by free_all_bootmem() once the early boot process is
5048 * done. Non-atomic initialization, single-pass. 4984 * done. Non-atomic initialization, single-pass.
@@ -5304,49 +5240,6 @@ void __init setup_per_cpu_pageset(void)
5304 alloc_percpu(struct per_cpu_nodestat); 5240 alloc_percpu(struct per_cpu_nodestat);
5305} 5241}
5306 5242
5307static noinline __ref
5308int zone_wait_table_init(struct zone *zone, unsigned long zone_size_pages)
5309{
5310 int i;
5311 size_t alloc_size;
5312
5313 /*
5314 * The per-page waitqueue mechanism uses hashed waitqueues
5315 * per zone.
5316 */
5317 zone->wait_table_hash_nr_entries =
5318 wait_table_hash_nr_entries(zone_size_pages);
5319 zone->wait_table_bits =
5320 wait_table_bits(zone->wait_table_hash_nr_entries);
5321 alloc_size = zone->wait_table_hash_nr_entries
5322 * sizeof(wait_queue_head_t);
5323
5324 if (!slab_is_available()) {
5325 zone->wait_table = (wait_queue_head_t *)
5326 memblock_virt_alloc_node_nopanic(
5327 alloc_size, zone->zone_pgdat->node_id);
5328 } else {
5329 /*
5330 * This case means that a zone whose size was 0 gets new memory
5331 * via memory hot-add.
5332 * But it may be the case that a new node was hot-added. In
5333 * this case vmalloc() will not be able to use this new node's
5334 * memory - this wait_table must be initialized to use this new
5335 * node itself as well.
5336 * To use this new node's memory, further consideration will be
5337 * necessary.
5338 */
5339 zone->wait_table = vmalloc(alloc_size);
5340 }
5341 if (!zone->wait_table)
5342 return -ENOMEM;
5343
5344 for (i = 0; i < zone->wait_table_hash_nr_entries; ++i)
5345 init_waitqueue_head(zone->wait_table + i);
5346
5347 return 0;
5348}
5349
5350static __meminit void zone_pcp_init(struct zone *zone) 5243static __meminit void zone_pcp_init(struct zone *zone)
5351{ 5244{
5352 /* 5245 /*
@@ -5367,10 +5260,7 @@ int __meminit init_currently_empty_zone(struct zone *zone,
5367 unsigned long size) 5260 unsigned long size)
5368{ 5261{
5369 struct pglist_data *pgdat = zone->zone_pgdat; 5262 struct pglist_data *pgdat = zone->zone_pgdat;
5370 int ret; 5263
5371 ret = zone_wait_table_init(zone, size);
5372 if (ret)
5373 return ret;
5374 pgdat->nr_zones = zone_idx(zone) + 1; 5264 pgdat->nr_zones = zone_idx(zone) + 1;
5375 5265
5376 zone->zone_start_pfn = zone_start_pfn; 5266 zone->zone_start_pfn = zone_start_pfn;
@@ -5382,6 +5272,7 @@ int __meminit init_currently_empty_zone(struct zone *zone,
5382 zone_start_pfn, (zone_start_pfn + size)); 5272 zone_start_pfn, (zone_start_pfn + size));
5383 5273
5384 zone_init_free_lists(zone); 5274 zone_init_free_lists(zone);
5275 zone->initialized = 1;
5385 5276
5386 return 0; 5277 return 0;
5387} 5278}
diff --git a/mm/slab.c b/mm/slab.c
index 090fb26b3a39..0b0550ca85b4 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -233,6 +233,7 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
233 spin_lock_init(&parent->list_lock); 233 spin_lock_init(&parent->list_lock);
234 parent->free_objects = 0; 234 parent->free_objects = 0;
235 parent->free_touched = 0; 235 parent->free_touched = 0;
236 parent->num_slabs = 0;
236} 237}
237 238
238#define MAKE_LIST(cachep, listp, slab, nodeid) \ 239#define MAKE_LIST(cachep, listp, slab, nodeid) \
@@ -966,7 +967,7 @@ static int setup_kmem_cache_node(struct kmem_cache *cachep,
966 * guaranteed to be valid until irq is re-enabled, because it will be 967 * guaranteed to be valid until irq is re-enabled, because it will be
967 * freed after synchronize_sched(). 968 * freed after synchronize_sched().
968 */ 969 */
969 if (force_change) 970 if (old_shared && force_change)
970 synchronize_sched(); 971 synchronize_sched();
971 972
972fail: 973fail:
@@ -1382,24 +1383,27 @@ slab_out_of_memory(struct kmem_cache *cachep, gfp_t gfpflags, int nodeid)
1382 for_each_kmem_cache_node(cachep, node, n) { 1383 for_each_kmem_cache_node(cachep, node, n) {
1383 unsigned long active_objs = 0, num_objs = 0, free_objects = 0; 1384 unsigned long active_objs = 0, num_objs = 0, free_objects = 0;
1384 unsigned long active_slabs = 0, num_slabs = 0; 1385 unsigned long active_slabs = 0, num_slabs = 0;
1386 unsigned long num_slabs_partial = 0, num_slabs_free = 0;
1387 unsigned long num_slabs_full;
1385 1388
1386 spin_lock_irqsave(&n->list_lock, flags); 1389 spin_lock_irqsave(&n->list_lock, flags);
1387 list_for_each_entry(page, &n->slabs_full, lru) { 1390 num_slabs = n->num_slabs;
1388 active_objs += cachep->num;
1389 active_slabs++;
1390 }
1391 list_for_each_entry(page, &n->slabs_partial, lru) { 1391 list_for_each_entry(page, &n->slabs_partial, lru) {
1392 active_objs += page->active; 1392 active_objs += page->active;
1393 active_slabs++; 1393 num_slabs_partial++;
1394 } 1394 }
1395 list_for_each_entry(page, &n->slabs_free, lru) 1395 list_for_each_entry(page, &n->slabs_free, lru)
1396 num_slabs++; 1396 num_slabs_free++;
1397 1397
1398 free_objects += n->free_objects; 1398 free_objects += n->free_objects;
1399 spin_unlock_irqrestore(&n->list_lock, flags); 1399 spin_unlock_irqrestore(&n->list_lock, flags);
1400 1400
1401 num_slabs += active_slabs;
1402 num_objs = num_slabs * cachep->num; 1401 num_objs = num_slabs * cachep->num;
1402 active_slabs = num_slabs - num_slabs_free;
1403 num_slabs_full = num_slabs -
1404 (num_slabs_partial + num_slabs_free);
1405 active_objs += (num_slabs_full * cachep->num);
1406
1403 pr_warn(" node %d: slabs: %ld/%ld, objs: %ld/%ld, free: %ld\n", 1407 pr_warn(" node %d: slabs: %ld/%ld, objs: %ld/%ld, free: %ld\n",
1404 node, active_slabs, num_slabs, active_objs, num_objs, 1408 node, active_slabs, num_slabs, active_objs, num_objs,
1405 free_objects); 1409 free_objects);
@@ -2314,6 +2318,7 @@ static int drain_freelist(struct kmem_cache *cache,
2314 2318
2315 page = list_entry(p, struct page, lru); 2319 page = list_entry(p, struct page, lru);
2316 list_del(&page->lru); 2320 list_del(&page->lru);
2321 n->num_slabs--;
2317 /* 2322 /*
2318 * Safe to drop the lock. The slab is no longer linked 2323 * Safe to drop the lock. The slab is no longer linked
2319 * to the cache. 2324 * to the cache.
@@ -2752,6 +2757,8 @@ static void cache_grow_end(struct kmem_cache *cachep, struct page *page)
2752 list_add_tail(&page->lru, &(n->slabs_free)); 2757 list_add_tail(&page->lru, &(n->slabs_free));
2753 else 2758 else
2754 fixup_slab_list(cachep, n, page, &list); 2759 fixup_slab_list(cachep, n, page, &list);
2760
2761 n->num_slabs++;
2755 STATS_INC_GROWN(cachep); 2762 STATS_INC_GROWN(cachep);
2756 n->free_objects += cachep->num - page->active; 2763 n->free_objects += cachep->num - page->active;
2757 spin_unlock(&n->list_lock); 2764 spin_unlock(&n->list_lock);
@@ -3443,6 +3450,7 @@ static void free_block(struct kmem_cache *cachep, void **objpp,
3443 3450
3444 page = list_last_entry(&n->slabs_free, struct page, lru); 3451 page = list_last_entry(&n->slabs_free, struct page, lru);
3445 list_move(&page->lru, list); 3452 list_move(&page->lru, list);
3453 n->num_slabs--;
3446 } 3454 }
3447} 3455}
3448 3456
@@ -4099,6 +4107,8 @@ void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)
4099 unsigned long num_objs; 4107 unsigned long num_objs;
4100 unsigned long active_slabs = 0; 4108 unsigned long active_slabs = 0;
4101 unsigned long num_slabs, free_objects = 0, shared_avail = 0; 4109 unsigned long num_slabs, free_objects = 0, shared_avail = 0;
4110 unsigned long num_slabs_partial = 0, num_slabs_free = 0;
4111 unsigned long num_slabs_full = 0;
4102 const char *name; 4112 const char *name;
4103 char *error = NULL; 4113 char *error = NULL;
4104 int node; 4114 int node;
@@ -4111,33 +4121,34 @@ void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)
4111 check_irq_on(); 4121 check_irq_on();
4112 spin_lock_irq(&n->list_lock); 4122 spin_lock_irq(&n->list_lock);
4113 4123
4114 list_for_each_entry(page, &n->slabs_full, lru) { 4124 num_slabs += n->num_slabs;
4115 if (page->active != cachep->num && !error) 4125
4116 error = "slabs_full accounting error";
4117 active_objs += cachep->num;
4118 active_slabs++;
4119 }
4120 list_for_each_entry(page, &n->slabs_partial, lru) { 4126 list_for_each_entry(page, &n->slabs_partial, lru) {
4121 if (page->active == cachep->num && !error) 4127 if (page->active == cachep->num && !error)
4122 error = "slabs_partial accounting error"; 4128 error = "slabs_partial accounting error";
4123 if (!page->active && !error) 4129 if (!page->active && !error)
4124 error = "slabs_partial accounting error"; 4130 error = "slabs_partial accounting error";
4125 active_objs += page->active; 4131 active_objs += page->active;
4126 active_slabs++; 4132 num_slabs_partial++;
4127 } 4133 }
4134
4128 list_for_each_entry(page, &n->slabs_free, lru) { 4135 list_for_each_entry(page, &n->slabs_free, lru) {
4129 if (page->active && !error) 4136 if (page->active && !error)
4130 error = "slabs_free accounting error"; 4137 error = "slabs_free accounting error";
4131 num_slabs++; 4138 num_slabs_free++;
4132 } 4139 }
4140
4133 free_objects += n->free_objects; 4141 free_objects += n->free_objects;
4134 if (n->shared) 4142 if (n->shared)
4135 shared_avail += n->shared->avail; 4143 shared_avail += n->shared->avail;
4136 4144
4137 spin_unlock_irq(&n->list_lock); 4145 spin_unlock_irq(&n->list_lock);
4138 } 4146 }
4139 num_slabs += active_slabs;
4140 num_objs = num_slabs * cachep->num; 4147 num_objs = num_slabs * cachep->num;
4148 active_slabs = num_slabs - num_slabs_free;
4149 num_slabs_full = num_slabs - (num_slabs_partial + num_slabs_free);
4150 active_objs += (num_slabs_full * cachep->num);
4151
4141 if (num_objs - active_objs != free_objects && !error) 4152 if (num_objs - active_objs != free_objects && !error)
4142 error = "free_objects accounting error"; 4153 error = "free_objects accounting error";
4143 4154
diff --git a/mm/slab.h b/mm/slab.h
index 9653f2e2591a..bc05fdc3edce 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -432,6 +432,7 @@ struct kmem_cache_node {
432 struct list_head slabs_partial; /* partial list first, better asm code */ 432 struct list_head slabs_partial; /* partial list first, better asm code */
433 struct list_head slabs_full; 433 struct list_head slabs_full;
434 struct list_head slabs_free; 434 struct list_head slabs_free;
435 unsigned long num_slabs;
435 unsigned long free_objects; 436 unsigned long free_objects;
436 unsigned int free_limit; 437 unsigned int free_limit;
437 unsigned int colour_next; /* Per-node cache coloring */ 438 unsigned int colour_next; /* Per-node cache coloring */
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 744f926af442..76fda2268148 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3043,7 +3043,9 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
3043 sc.gfp_mask, 3043 sc.gfp_mask,
3044 sc.reclaim_idx); 3044 sc.reclaim_idx);
3045 3045
3046 current->flags |= PF_MEMALLOC;
3046 nr_reclaimed = do_try_to_free_pages(zonelist, &sc); 3047 nr_reclaimed = do_try_to_free_pages(zonelist, &sc);
3048 current->flags &= ~PF_MEMALLOC;
3047 3049
3048 trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed); 3050 trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed);
3049 3051
diff --git a/security/keys/Kconfig b/security/keys/Kconfig
index f826e8739023..d942c7c2bc0a 100644
--- a/security/keys/Kconfig
+++ b/security/keys/Kconfig
@@ -41,7 +41,7 @@ config BIG_KEYS
41 bool "Large payload keys" 41 bool "Large payload keys"
42 depends on KEYS 42 depends on KEYS
43 depends on TMPFS 43 depends on TMPFS
44 select CRYPTO 44 depends on (CRYPTO_ANSI_CPRNG = y || CRYPTO_DRBG = y)
45 select CRYPTO_AES 45 select CRYPTO_AES
46 select CRYPTO_ECB 46 select CRYPTO_ECB
47 select CRYPTO_RNG 47 select CRYPTO_RNG
diff --git a/security/keys/big_key.c b/security/keys/big_key.c
index c0b3030b5634..835c1ab30d01 100644
--- a/security/keys/big_key.c
+++ b/security/keys/big_key.c
@@ -9,6 +9,7 @@
9 * 2 of the Licence, or (at your option) any later version. 9 * 2 of the Licence, or (at your option) any later version.
10 */ 10 */
11 11
12#define pr_fmt(fmt) "big_key: "fmt
12#include <linux/init.h> 13#include <linux/init.h>
13#include <linux/seq_file.h> 14#include <linux/seq_file.h>
14#include <linux/file.h> 15#include <linux/file.h>
@@ -341,44 +342,48 @@ error:
341 */ 342 */
342static int __init big_key_init(void) 343static int __init big_key_init(void)
343{ 344{
344 return register_key_type(&key_type_big_key); 345 struct crypto_skcipher *cipher;
345} 346 struct crypto_rng *rng;
346 347 int ret;
347/*
348 * Initialize big_key crypto and RNG algorithms
349 */
350static int __init big_key_crypto_init(void)
351{
352 int ret = -EINVAL;
353 348
354 /* init RNG */ 349 rng = crypto_alloc_rng(big_key_rng_name, 0, 0);
355 big_key_rng = crypto_alloc_rng(big_key_rng_name, 0, 0); 350 if (IS_ERR(rng)) {
356 if (IS_ERR(big_key_rng)) { 351 pr_err("Can't alloc rng: %ld\n", PTR_ERR(rng));
357 big_key_rng = NULL; 352 return PTR_ERR(rng);
358 return -EFAULT;
359 } 353 }
360 354
355 big_key_rng = rng;
356
361 /* seed RNG */ 357 /* seed RNG */
362 ret = crypto_rng_reset(big_key_rng, NULL, crypto_rng_seedsize(big_key_rng)); 358 ret = crypto_rng_reset(rng, NULL, crypto_rng_seedsize(rng));
363 if (ret) 359 if (ret) {
364 goto error; 360 pr_err("Can't reset rng: %d\n", ret);
361 goto error_rng;
362 }
365 363
366 /* init block cipher */ 364 /* init block cipher */
367 big_key_skcipher = crypto_alloc_skcipher(big_key_alg_name, 365 cipher = crypto_alloc_skcipher(big_key_alg_name, 0, CRYPTO_ALG_ASYNC);
368 0, CRYPTO_ALG_ASYNC); 366 if (IS_ERR(cipher)) {
369 if (IS_ERR(big_key_skcipher)) { 367 ret = PTR_ERR(cipher);
370 big_key_skcipher = NULL; 368 pr_err("Can't alloc crypto: %d\n", ret);
371 ret = -EFAULT; 369 goto error_rng;
372 goto error; 370 }
371
372 big_key_skcipher = cipher;
373
374 ret = register_key_type(&key_type_big_key);
375 if (ret < 0) {
376 pr_err("Can't register type: %d\n", ret);
377 goto error_cipher;
373 } 378 }
374 379
375 return 0; 380 return 0;
376 381
377error: 382error_cipher:
383 crypto_free_skcipher(big_key_skcipher);
384error_rng:
378 crypto_free_rng(big_key_rng); 385 crypto_free_rng(big_key_rng);
379 big_key_rng = NULL;
380 return ret; 386 return ret;
381} 387}
382 388
383device_initcall(big_key_init); 389late_initcall(big_key_init);
384late_initcall(big_key_crypto_init);
diff --git a/security/keys/proc.c b/security/keys/proc.c
index f0611a6368cd..b9f531c9e4fa 100644
--- a/security/keys/proc.c
+++ b/security/keys/proc.c
@@ -181,7 +181,7 @@ static int proc_keys_show(struct seq_file *m, void *v)
181 struct timespec now; 181 struct timespec now;
182 unsigned long timo; 182 unsigned long timo;
183 key_ref_t key_ref, skey_ref; 183 key_ref_t key_ref, skey_ref;
184 char xbuf[12]; 184 char xbuf[16];
185 int rc; 185 int rc;
186 186
187 struct keyring_search_context ctx = { 187 struct keyring_search_context ctx = {
diff --git a/sound/core/seq/seq_timer.c b/sound/core/seq/seq_timer.c
index dcc102813aef..37d9cfbc29f9 100644
--- a/sound/core/seq/seq_timer.c
+++ b/sound/core/seq/seq_timer.c
@@ -448,8 +448,8 @@ snd_seq_real_time_t snd_seq_timer_get_cur_time(struct snd_seq_timer *tmr)
448 448
449 ktime_get_ts64(&tm); 449 ktime_get_ts64(&tm);
450 tm = timespec64_sub(tm, tmr->last_update); 450 tm = timespec64_sub(tm, tmr->last_update);
451 cur_time.tv_nsec = tm.tv_nsec; 451 cur_time.tv_nsec += tm.tv_nsec;
452 cur_time.tv_sec = tm.tv_sec; 452 cur_time.tv_sec += tm.tv_sec;
453 snd_seq_sanity_real_time(&cur_time); 453 snd_seq_sanity_real_time(&cur_time);
454 } 454 }
455 spin_unlock_irqrestore(&tmr->lock, flags); 455 spin_unlock_irqrestore(&tmr->lock, flags);
diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
index d17937b92331..7e3aa50b21f9 100644
--- a/sound/pci/asihpi/hpioctl.c
+++ b/sound/pci/asihpi/hpioctl.c
@@ -111,7 +111,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
111 return -EINVAL; 111 return -EINVAL;
112 112
113 hm = kmalloc(sizeof(*hm), GFP_KERNEL); 113 hm = kmalloc(sizeof(*hm), GFP_KERNEL);
114 hr = kmalloc(sizeof(*hr), GFP_KERNEL); 114 hr = kzalloc(sizeof(*hr), GFP_KERNEL);
115 if (!hm || !hr) { 115 if (!hm || !hr) {
116 err = -ENOMEM; 116 err = -ENOMEM;
117 goto out; 117 goto out;
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index c3469f756ec2..c64d986009a9 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -341,8 +341,7 @@ enum {
341 341
342/* quirks for Nvidia */ 342/* quirks for Nvidia */
343#define AZX_DCAPS_PRESET_NVIDIA \ 343#define AZX_DCAPS_PRESET_NVIDIA \
344 (AZX_DCAPS_NO_MSI | /*AZX_DCAPS_ALIGN_BUFSIZE |*/ \ 344 (AZX_DCAPS_NO_MSI | AZX_DCAPS_CORBRP_SELF_CLEAR |\
345 AZX_DCAPS_NO_64BIT | AZX_DCAPS_CORBRP_SELF_CLEAR |\
346 AZX_DCAPS_SNOOP_TYPE(NVIDIA)) 345 AZX_DCAPS_SNOOP_TYPE(NVIDIA))
347 346
348#define AZX_DCAPS_PRESET_CTHDA \ 347#define AZX_DCAPS_PRESET_CTHDA \
@@ -1716,6 +1715,10 @@ static int azx_first_init(struct azx *chip)
1716 } 1715 }
1717 } 1716 }
1718 1717
1718 /* NVidia hardware normally only supports up to 40 bits of DMA */
1719 if (chip->pci->vendor == PCI_VENDOR_ID_NVIDIA)
1720 dma_bits = 40;
1721
1719 /* disable 64bit DMA address on some devices */ 1722 /* disable 64bit DMA address on some devices */
1720 if (chip->driver_caps & AZX_DCAPS_NO_64BIT) { 1723 if (chip->driver_caps & AZX_DCAPS_NO_64BIT) {
1721 dev_dbg(card->dev, "Disabling 64bit DMA\n"); 1724 dev_dbg(card->dev, "Disabling 64bit DMA\n");
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index b58e8c76346a..2f909dd8b7b8 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -5811,8 +5811,6 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
5811#define ALC295_STANDARD_PINS \ 5811#define ALC295_STANDARD_PINS \
5812 {0x12, 0xb7a60130}, \ 5812 {0x12, 0xb7a60130}, \
5813 {0x14, 0x90170110}, \ 5813 {0x14, 0x90170110}, \
5814 {0x17, 0x21014020}, \
5815 {0x18, 0x21a19030}, \
5816 {0x21, 0x04211020} 5814 {0x21, 0x04211020}
5817 5815
5818#define ALC298_STANDARD_PINS \ 5816#define ALC298_STANDARD_PINS \
@@ -5859,11 +5857,19 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
5859 {0x1b, 0x02011020}, 5857 {0x1b, 0x02011020},
5860 {0x21, 0x0221101f}), 5858 {0x21, 0x0221101f}),
5861 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, 5859 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5860 {0x14, 0x90170110},
5861 {0x1b, 0x01011020},
5862 {0x21, 0x0221101f}),
5863 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5862 {0x14, 0x90170130}, 5864 {0x14, 0x90170130},
5863 {0x1b, 0x01014020}, 5865 {0x1b, 0x01014020},
5864 {0x21, 0x0221103f}), 5866 {0x21, 0x0221103f}),
5865 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, 5867 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5866 {0x14, 0x90170130}, 5868 {0x14, 0x90170130},
5869 {0x1b, 0x01011020},
5870 {0x21, 0x0221103f}),
5871 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5872 {0x14, 0x90170130},
5867 {0x1b, 0x02011020}, 5873 {0x1b, 0x02011020},
5868 {0x21, 0x0221103f}), 5874 {0x21, 0x0221103f}),
5869 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, 5875 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
@@ -6039,7 +6045,13 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
6039 ALC292_STANDARD_PINS, 6045 ALC292_STANDARD_PINS,
6040 {0x13, 0x90a60140}), 6046 {0x13, 0x90a60140}),
6041 SND_HDA_PIN_QUIRK(0x10ec0295, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, 6047 SND_HDA_PIN_QUIRK(0x10ec0295, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
6042 ALC295_STANDARD_PINS), 6048 ALC295_STANDARD_PINS,
6049 {0x17, 0x21014020},
6050 {0x18, 0x21a19030}),
6051 SND_HDA_PIN_QUIRK(0x10ec0295, 0x1028, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
6052 ALC295_STANDARD_PINS,
6053 {0x17, 0x21014040},
6054 {0x18, 0x21a19050}),
6043 SND_HDA_PIN_QUIRK(0x10ec0298, 0x1028, "Dell", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE, 6055 SND_HDA_PIN_QUIRK(0x10ec0298, 0x1028, "Dell", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE,
6044 ALC298_STANDARD_PINS, 6056 ALC298_STANDARD_PINS,
6045 {0x17, 0x90170110}), 6057 {0x17, 0x90170110}),
@@ -6613,6 +6625,7 @@ enum {
6613 ALC891_FIXUP_HEADSET_MODE, 6625 ALC891_FIXUP_HEADSET_MODE,
6614 ALC891_FIXUP_DELL_MIC_NO_PRESENCE, 6626 ALC891_FIXUP_DELL_MIC_NO_PRESENCE,
6615 ALC662_FIXUP_ACER_VERITON, 6627 ALC662_FIXUP_ACER_VERITON,
6628 ALC892_FIXUP_ASROCK_MOBO,
6616}; 6629};
6617 6630
6618static const struct hda_fixup alc662_fixups[] = { 6631static const struct hda_fixup alc662_fixups[] = {
@@ -6889,6 +6902,16 @@ static const struct hda_fixup alc662_fixups[] = {
6889 { } 6902 { }
6890 } 6903 }
6891 }, 6904 },
6905 [ALC892_FIXUP_ASROCK_MOBO] = {
6906 .type = HDA_FIXUP_PINS,
6907 .v.pins = (const struct hda_pintbl[]) {
6908 { 0x15, 0x40f000f0 }, /* disabled */
6909 { 0x16, 0x40f000f0 }, /* disabled */
6910 { 0x18, 0x01014011 }, /* LO */
6911 { 0x1a, 0x01014012 }, /* LO */
6912 { }
6913 }
6914 },
6892}; 6915};
6893 6916
6894static const struct snd_pci_quirk alc662_fixup_tbl[] = { 6917static const struct snd_pci_quirk alc662_fixup_tbl[] = {
@@ -6926,6 +6949,7 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6926 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), 6949 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
6927 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), 6950 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
6928 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), 6951 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
6952 SND_PCI_QUIRK(0x1849, 0x5892, "ASRock B150M", ALC892_FIXUP_ASROCK_MOBO),
6929 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68), 6953 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
6930 SND_PCI_QUIRK(0x1b0a, 0x01b8, "ACER Veriton", ALC662_FIXUP_ACER_VERITON), 6954 SND_PCI_QUIRK(0x1b0a, 0x01b8, "ACER Veriton", ALC662_FIXUP_ACER_VERITON),
6931 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), 6955 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index c60a776e815d..8a59d4782a0f 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -2907,6 +2907,23 @@ AU0828_DEVICE(0x2040, 0x7260, "Hauppauge", "HVR-950Q"),
2907AU0828_DEVICE(0x2040, 0x7213, "Hauppauge", "HVR-950Q"), 2907AU0828_DEVICE(0x2040, 0x7213, "Hauppauge", "HVR-950Q"),
2908AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"), 2908AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
2909 2909
2910/* Syntek STK1160 */
2911{
2912 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
2913 USB_DEVICE_ID_MATCH_INT_CLASS |
2914 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
2915 .idVendor = 0x05e1,
2916 .idProduct = 0x0408,
2917 .bInterfaceClass = USB_CLASS_AUDIO,
2918 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
2919 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2920 .vendor_name = "Syntek",
2921 .product_name = "STK1160",
2922 .ifnum = QUIRK_ANY_INTERFACE,
2923 .type = QUIRK_AUDIO_ALIGN_TRANSFER
2924 }
2925},
2926
2910/* Digidesign Mbox */ 2927/* Digidesign Mbox */
2911{ 2928{
2912 /* Thanks to Clemens Ladisch <clemens@ladisch.de> */ 2929 /* Thanks to Clemens Ladisch <clemens@ladisch.de> */
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 4490601a9235..e8a1f699058a 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -754,7 +754,7 @@ static struct rela *find_switch_table(struct objtool_file *file,
754 if (insn->type == INSN_JUMP_UNCONDITIONAL && 754 if (insn->type == INSN_JUMP_UNCONDITIONAL &&
755 insn->jump_dest && 755 insn->jump_dest &&
756 (insn->jump_dest->offset <= insn->offset || 756 (insn->jump_dest->offset <= insn->offset ||
757 insn->jump_dest->offset >= orig_insn->offset)) 757 insn->jump_dest->offset > orig_insn->offset))
758 break; 758 break;
759 759
760 text_rela = find_rela_by_dest_range(insn->sec, insn->offset, 760 text_rela = find_rela_by_dest_range(insn->sec, insn->offset,
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 28510e72618a..2907b7b78654 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1346,21 +1346,19 @@ unsigned long kvm_vcpu_gfn_to_hva_prot(struct kvm_vcpu *vcpu, gfn_t gfn, bool *w
1346static int get_user_page_nowait(unsigned long start, int write, 1346static int get_user_page_nowait(unsigned long start, int write,
1347 struct page **page) 1347 struct page **page)
1348{ 1348{
1349 int flags = FOLL_TOUCH | FOLL_NOWAIT | FOLL_HWPOISON | FOLL_GET; 1349 int flags = FOLL_NOWAIT | FOLL_HWPOISON;
1350 1350
1351 if (write) 1351 if (write)
1352 flags |= FOLL_WRITE; 1352 flags |= FOLL_WRITE;
1353 1353
1354 return __get_user_pages(current, current->mm, start, 1, flags, page, 1354 return get_user_pages(start, 1, flags, page, NULL);
1355 NULL, NULL);
1356} 1355}
1357 1356
1358static inline int check_user_page_hwpoison(unsigned long addr) 1357static inline int check_user_page_hwpoison(unsigned long addr)
1359{ 1358{
1360 int rc, flags = FOLL_TOUCH | FOLL_HWPOISON | FOLL_WRITE; 1359 int rc, flags = FOLL_HWPOISON | FOLL_WRITE;
1361 1360
1362 rc = __get_user_pages(current, current->mm, addr, 1, 1361 rc = get_user_pages(addr, 1, flags, NULL, NULL);
1363 flags, NULL, NULL, NULL);
1364 return rc == -EHWPOISON; 1362 return rc == -EHWPOISON;
1365} 1363}
1366 1364